aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/3rdparty/GLee/GLee.c (renamed from src/libjin/3rdparty/GLee/GLee.c)0
-rw-r--r--src/3rdparty/GLee/GLee.h (renamed from src/libjin/3rdparty/GLee/GLee.h)0
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/.gitignore9
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/COPYRIGHT56
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/Makefile157
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/README16
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/doc/bluequad-print.css166
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/doc/bluequad.css325
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/doc/changes.html1019
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/doc/contact.html108
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/doc/ext_c_api.html186
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/doc/ext_ffi.html329
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/doc/ext_ffi_api.html565
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/doc/ext_ffi_semantics.html1244
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/doc/ext_ffi_tutorial.html600
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/doc/ext_jit.html198
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/doc/extensions.html407
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/doc/faq.html183
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/doc/img/contact.pngbin0 -> 1340 bytes
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/doc/install.html645
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/doc/luajit.html233
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/doc/running.html305
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/doc/status.html109
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_arm.h458
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_arm.lua1125
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_mips.h417
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_mips.lua953
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_ppc.h413
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_ppc.lua1249
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_proto.h83
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_x64.lua12
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_x86.h483
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_x86.lua1946
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/dynasm/dynasm.lua1094
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/etc/luajit.188
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/etc/luajit.pc25
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lauxlib.h167
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_alloc.h17
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_arch.h452
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm.h17
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm_arm.h2360
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm_mips.h1977
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm_ppc.h2168
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm_x86.h2900
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_bc.h261
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_bcdump.h66
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_carith.h28
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ccall.h171
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ccallback.h25
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_cconv.h70
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_cdata.h75
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_char.h42
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_clib.h29
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_cparse.h65
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_crecord.h31
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ctype.h461
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_debug.h61
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_def.h353
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_dispatch.h131
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_emit_arm.h356
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_emit_mips.h211
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_emit_ppc.h238
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_emit_x86.h468
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_err.h41
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_errmsg.h193
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ff.h18
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ffrecord.h24
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_frame.h187
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_func.h24
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_gc.h134
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_gdbjit.h22
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ir.h551
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ircall.h271
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_iropt.h161
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_jit.h423
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_lex.h85
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_lib.h112
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_mcode.h30
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_meta.h37
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_obj.h864
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_parse.h18
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_record.h44
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_snap.h34
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_state.h35
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_str.h50
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_strscan.h39
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_tab.h70
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target.h162
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target_arm.h274
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target_mips.h258
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target_ppc.h280
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target_x86.h342
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_trace.h53
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_traceerr.h61
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_udata.h14
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_vm.h116
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_vmevent.h59
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lua.h393
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lua.hpp9
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/luaconf.h156
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/luajit.h70
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lualib.h43
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/.gitignore7
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/Makefile690
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/Makefile.dep226
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/buildvm.libbin0 -> 33996 bytes
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/buildvm_arch.h2144
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/host/.gitignore3
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/host/README4
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/host/buildvm.c516
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/host/buildvm.h104
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/host/buildvm_asm.c314
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/host/buildvm_fold.c229
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/host/buildvm_lib.c398
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/host/buildvm_peobj.c368
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/host/genminilua.lua429
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/host/minilua.c7770
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/jit/.gitignore1
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/jit/bc.lua191
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/jit/bcsave.lua659
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/jit/dis_arm.lua689
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/jit/dis_mips.lua428
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/jit/dis_mipsel.lua20
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/jit/dis_ppc.lua591
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/jit/dis_x64.lua20
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/jit/dis_x86.lua836
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/jit/dump.lua701
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/jit/v.lua167
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lauxlib.h167
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lib_aux.c356
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lib_base.c683
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lib_bit.c74
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lib_debug.c405
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lib_ffi.c851
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lib_init.c55
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lib_io.c546
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lib_jit.c664
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lib_math.c233
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lib_os.c287
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lib_package.c602
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lib_string.c941
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lib_table.c300
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj.supp41
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_alloc.c1396
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_alloc.h17
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_api.c1200
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_arch.h452
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_asm.c1921
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_asm.h17
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_asm_arm.h2360
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_asm_mips.h1977
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_asm_ppc.h2168
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_asm_x86.h2900
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_bc.c14
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_bc.h261
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_bcdump.h66
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_bcread.c476
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_bcwrite.c396
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_carith.c362
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_carith.h28
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_ccall.c900
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_ccall.h171
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_ccallback.c644
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_ccallback.h25
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_cconv.c752
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_cconv.h70
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_cdata.c285
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_cdata.h75
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_char.c43
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_char.h42
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_clib.c409
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_clib.h29
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_cparse.c1891
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_cparse.h65
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_crecord.c1674
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_crecord.h31
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_ctype.c634
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_ctype.h461
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_debug.c605
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_debug.h61
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_def.h353
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_dispatch.c494
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_dispatch.h131
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_emit_arm.h356
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_emit_mips.h211
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_emit_ppc.h238
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_emit_x86.h468
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_err.c803
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_err.h41
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_errmsg.h193
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_ff.h18
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_ffrecord.c887
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_ffrecord.h24
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_frame.h187
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_func.c187
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_func.h24
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_gc.c856
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_gc.h134
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_gdbjit.c795
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_gdbjit.h22
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_ir.c501
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_ir.h551
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_ircall.h271
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_iropt.h161
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_jit.h423
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_lex.c482
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_lex.h85
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_lib.c258
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_lib.h112
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_load.c168
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_mcode.c381
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_mcode.h30
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_meta.c466
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_meta.h37
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_obj.c35
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_obj.h864
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_opt_dce.c78
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_opt_fold.c2304
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_opt_loop.c436
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_opt_mem.c916
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_opt_narrow.c654
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_opt_sink.c244
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_opt_split.c732
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_parse.c2757
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_parse.h18
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_record.c2263
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_record.h44
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_snap.c862
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_snap.h34
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_state.c287
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_state.h35
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_str.c339
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_str.h50
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_strscan.c498
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_strscan.h39
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_tab.c654
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_tab.h70
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_target.h162
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_target_arm.h274
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_target_mips.h258
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_target_ppc.h280
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_target_x86.h342
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_trace.c824
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_trace.h53
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_traceerr.h61
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_udata.c34
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_udata.h14
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_vm.h116
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_vmevent.c57
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_vmevent.h59
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lj_vmmath.c140
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/ljamalg.c93
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lua.h393
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lua.hpp9
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lua51.dllbin0 -> 364544 bytes
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lua51.libbin0 -> 59514 bytes
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/luaconf.h156
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/luajit.c573
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/luajit.h70
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/lualib.h43
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/minilua.libbin0 -> 33996 bytes
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/msvcbuild.bat115
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/ps4build.bat103
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/psvitabuild.bat93
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/vm_arm.dasc4486
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/vm_mips.dasc4248
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/vm_ppc.dasc5160
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/vm_ppcspe.dasc3691
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/vm_x86.dasc6401
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/vmdef.lua331
-rw-r--r--src/3rdparty/LuaJIT-2.0.5/src/xedkbuild.bat92
-rw-r--r--src/3rdparty/SDL2/include/SDL.h133
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL.h133
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_assert.h291
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_atomic.h277
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_audio.h825
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_bits.h112
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_blendmode.h120
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_clipboard.h71
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_config.h53
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_config_android.h171
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_config_iphoneos.h191
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_config_macosx.h234
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_config_minimal.h82
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_config_pandora.h130
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_config_psp.h159
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_config_windows.h248
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_config_winrt.h230
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_config_wiz.h142
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_copying.h20
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_cpuinfo.h181
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_egl.h1673
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_endian.h260
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_error.h76
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_events.h754
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_filesystem.h136
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_gamecontroller.h362
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_gesture.h87
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_haptic.h1227
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_hints.h1022
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_joystick.h382
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_keyboard.h217
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_keycode.h349
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_loadso.h81
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_log.h211
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_main.h168
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_messagebox.h144
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_mouse.h302
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_mutex.h251
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_name.h33
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_opengl.h2183
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_opengl_glext.h11177
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_opengles.h39
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_opengles2.h52
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_opengles2_gl2.h621
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_opengles2_gl2ext.h2050
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_opengles2_gl2platform.h30
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_opengles2_khrplatform.h282
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_pixels.h470
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_platform.h198
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_power.h75
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_quit.h58
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_rect.h148
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_render.h931
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_revision.h2
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_rwops.h254
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_scancode.h413
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_shape.h144
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_stdinc.h605
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_surface.h546
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_system.h247
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_syswm.h324
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_test.h69
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_test_assert.h105
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_test_common.h188
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_test_compare.h69
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_test_crc32.h124
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_test_font.h81
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_test_fuzzer.h384
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_test_harness.h134
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_test_images.h78
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_test_log.h67
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_test_md5.h129
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_test_memory.h63
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_test_random.h115
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_thread.h308
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_timer.h115
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_touch.h86
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_types.h29
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_version.h162
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_video.h1249
-rw-r--r--src/3rdparty/SDL2/include/SDL2/SDL_vulkan.h273
-rw-r--r--src/3rdparty/SDL2/include/SDL2/begin_code.h167
-rw-r--r--src/3rdparty/SDL2/include/SDL2/close_code.h37
-rw-r--r--src/3rdparty/SDL2/include/SDL_assert.h291
-rw-r--r--src/3rdparty/SDL2/include/SDL_atomic.h277
-rw-r--r--src/3rdparty/SDL2/include/SDL_audio.h825
-rw-r--r--src/3rdparty/SDL2/include/SDL_bits.h112
-rw-r--r--src/3rdparty/SDL2/include/SDL_blendmode.h120
-rw-r--r--src/3rdparty/SDL2/include/SDL_clipboard.h71
-rw-r--r--src/3rdparty/SDL2/include/SDL_config.h53
-rw-r--r--src/3rdparty/SDL2/include/SDL_config_android.h171
-rw-r--r--src/3rdparty/SDL2/include/SDL_config_iphoneos.h191
-rw-r--r--src/3rdparty/SDL2/include/SDL_config_macosx.h234
-rw-r--r--src/3rdparty/SDL2/include/SDL_config_minimal.h82
-rw-r--r--src/3rdparty/SDL2/include/SDL_config_pandora.h130
-rw-r--r--src/3rdparty/SDL2/include/SDL_config_psp.h159
-rw-r--r--src/3rdparty/SDL2/include/SDL_config_windows.h248
-rw-r--r--src/3rdparty/SDL2/include/SDL_config_winrt.h230
-rw-r--r--src/3rdparty/SDL2/include/SDL_config_wiz.h142
-rw-r--r--src/3rdparty/SDL2/include/SDL_copying.h20
-rw-r--r--src/3rdparty/SDL2/include/SDL_cpuinfo.h181
-rw-r--r--src/3rdparty/SDL2/include/SDL_egl.h1673
-rw-r--r--src/3rdparty/SDL2/include/SDL_endian.h260
-rw-r--r--src/3rdparty/SDL2/include/SDL_error.h76
-rw-r--r--src/3rdparty/SDL2/include/SDL_events.h754
-rw-r--r--src/3rdparty/SDL2/include/SDL_filesystem.h136
-rw-r--r--src/3rdparty/SDL2/include/SDL_gamecontroller.h362
-rw-r--r--src/3rdparty/SDL2/include/SDL_gesture.h87
-rw-r--r--src/3rdparty/SDL2/include/SDL_haptic.h1227
-rw-r--r--src/3rdparty/SDL2/include/SDL_hints.h1022
-rw-r--r--src/3rdparty/SDL2/include/SDL_joystick.h382
-rw-r--r--src/3rdparty/SDL2/include/SDL_keyboard.h217
-rw-r--r--src/3rdparty/SDL2/include/SDL_keycode.h349
-rw-r--r--src/3rdparty/SDL2/include/SDL_loadso.h81
-rw-r--r--src/3rdparty/SDL2/include/SDL_log.h211
-rw-r--r--src/3rdparty/SDL2/include/SDL_main.h168
-rw-r--r--src/3rdparty/SDL2/include/SDL_messagebox.h144
-rw-r--r--src/3rdparty/SDL2/include/SDL_mouse.h302
-rw-r--r--src/3rdparty/SDL2/include/SDL_mutex.h251
-rw-r--r--src/3rdparty/SDL2/include/SDL_name.h33
-rw-r--r--src/3rdparty/SDL2/include/SDL_opengl.h2183
-rw-r--r--src/3rdparty/SDL2/include/SDL_opengl_glext.h11177
-rw-r--r--src/3rdparty/SDL2/include/SDL_opengles.h39
-rw-r--r--src/3rdparty/SDL2/include/SDL_opengles2.h52
-rw-r--r--src/3rdparty/SDL2/include/SDL_opengles2_gl2.h621
-rw-r--r--src/3rdparty/SDL2/include/SDL_opengles2_gl2ext.h2050
-rw-r--r--src/3rdparty/SDL2/include/SDL_opengles2_gl2platform.h30
-rw-r--r--src/3rdparty/SDL2/include/SDL_opengles2_khrplatform.h282
-rw-r--r--src/3rdparty/SDL2/include/SDL_pixels.h470
-rw-r--r--src/3rdparty/SDL2/include/SDL_platform.h198
-rw-r--r--src/3rdparty/SDL2/include/SDL_power.h75
-rw-r--r--src/3rdparty/SDL2/include/SDL_quit.h58
-rw-r--r--src/3rdparty/SDL2/include/SDL_rect.h148
-rw-r--r--src/3rdparty/SDL2/include/SDL_render.h931
-rw-r--r--src/3rdparty/SDL2/include/SDL_revision.h2
-rw-r--r--src/3rdparty/SDL2/include/SDL_rwops.h254
-rw-r--r--src/3rdparty/SDL2/include/SDL_scancode.h413
-rw-r--r--src/3rdparty/SDL2/include/SDL_shape.h144
-rw-r--r--src/3rdparty/SDL2/include/SDL_stdinc.h605
-rw-r--r--src/3rdparty/SDL2/include/SDL_surface.h546
-rw-r--r--src/3rdparty/SDL2/include/SDL_system.h247
-rw-r--r--src/3rdparty/SDL2/include/SDL_syswm.h324
-rw-r--r--src/3rdparty/SDL2/include/SDL_test.h69
-rw-r--r--src/3rdparty/SDL2/include/SDL_test_assert.h105
-rw-r--r--src/3rdparty/SDL2/include/SDL_test_common.h188
-rw-r--r--src/3rdparty/SDL2/include/SDL_test_compare.h69
-rw-r--r--src/3rdparty/SDL2/include/SDL_test_crc32.h124
-rw-r--r--src/3rdparty/SDL2/include/SDL_test_font.h81
-rw-r--r--src/3rdparty/SDL2/include/SDL_test_fuzzer.h384
-rw-r--r--src/3rdparty/SDL2/include/SDL_test_harness.h134
-rw-r--r--src/3rdparty/SDL2/include/SDL_test_images.h78
-rw-r--r--src/3rdparty/SDL2/include/SDL_test_log.h67
-rw-r--r--src/3rdparty/SDL2/include/SDL_test_md5.h129
-rw-r--r--src/3rdparty/SDL2/include/SDL_test_memory.h63
-rw-r--r--src/3rdparty/SDL2/include/SDL_test_random.h115
-rw-r--r--src/3rdparty/SDL2/include/SDL_thread.h308
-rw-r--r--src/3rdparty/SDL2/include/SDL_timer.h115
-rw-r--r--src/3rdparty/SDL2/include/SDL_touch.h86
-rw-r--r--src/3rdparty/SDL2/include/SDL_types.h29
-rw-r--r--src/3rdparty/SDL2/include/SDL_version.h162
-rw-r--r--src/3rdparty/SDL2/include/SDL_video.h1249
-rw-r--r--src/3rdparty/SDL2/include/SDL_vulkan.h273
-rw-r--r--src/3rdparty/SDL2/include/begin_code.h167
-rw-r--r--src/3rdparty/SDL2/include/close_code.h37
-rw-r--r--src/3rdparty/SDL2/src/SDL.c476
-rw-r--r--src/3rdparty/SDL2/src/SDL_assert.c441
-rw-r--r--src/3rdparty/SDL2/src/SDL_assert_c.h24
-rw-r--r--src/3rdparty/SDL2/src/SDL_dataqueue.c339
-rw-r--r--src/3rdparty/SDL2/src/SDL_dataqueue.h55
-rw-r--r--src/3rdparty/SDL2/src/SDL_error.c319
-rw-r--r--src/3rdparty/SDL2/src/SDL_error_c.h65
-rw-r--r--src/3rdparty/SDL2/src/SDL_hints.c236
-rw-r--r--src/3rdparty/SDL2/src/SDL_internal.h52
-rw-r--r--src/3rdparty/SDL2/src/SDL_log.c450
-rw-r--r--src/3rdparty/SDL2/src/atomic/SDL_atomic.c303
-rw-r--r--src/3rdparty/SDL2/src/atomic/SDL_spinlock.c152
-rw-r--r--src/3rdparty/SDL2/src/audio/SDL_audio.c1635
-rw-r--r--src/3rdparty/SDL2/src/audio/SDL_audio_c.h79
-rw-r--r--src/3rdparty/SDL2/src/audio/SDL_audiocvt.c1673
-rw-r--r--src/3rdparty/SDL2/src/audio/SDL_audiodev.c124
-rw-r--r--src/3rdparty/SDL2/src/audio/SDL_audiodev_c.h38
-rw-r--r--src/3rdparty/SDL2/src/audio/SDL_audiotypecvt.c829
-rw-r--r--src/3rdparty/SDL2/src/audio/SDL_mixer.c369
-rw-r--r--src/3rdparty/SDL2/src/audio/SDL_sysaudio.h211
-rw-r--r--src/3rdparty/SDL2/src/audio/SDL_wave.c694
-rw-r--r--src/3rdparty/SDL2/src/audio/SDL_wave.h77
-rw-r--r--src/3rdparty/SDL2/src/audio/alsa/SDL_alsa_audio.c1030
-rw-r--r--src/3rdparty/SDL2/src/audio/alsa/SDL_alsa_audio.h48
-rw-r--r--src/3rdparty/SDL2/src/audio/android/SDL_androidaudio.c226
-rw-r--r--src/3rdparty/SDL2/src/audio/android/SDL_androidaudio.h42
-rw-r--r--src/3rdparty/SDL2/src/audio/arts/SDL_artsaudio.c365
-rw-r--r--src/3rdparty/SDL2/src/audio/arts/SDL_artsaudio.h53
-rw-r--r--src/3rdparty/SDL2/src/audio/coreaudio/SDL_coreaudio.h68
-rw-r--r--src/3rdparty/SDL2/src/audio/coreaudio/SDL_coreaudio.m891
-rw-r--r--src/3rdparty/SDL2/src/audio/directsound/SDL_directsound.c604
-rw-r--r--src/3rdparty/SDL2/src/audio/directsound/SDL_directsound.h47
-rw-r--r--src/3rdparty/SDL2/src/audio/disk/SDL_diskaudio.c207
-rw-r--r--src/3rdparty/SDL2/src/audio/disk/SDL_diskaudio.h41
-rw-r--r--src/3rdparty/SDL2/src/audio/dsp/SDL_dspaudio.c320
-rw-r--r--src/3rdparty/SDL2/src/audio/dsp/SDL_dspaudio.h43
-rw-r--r--src/3rdparty/SDL2/src/audio/dummy/SDL_dummyaudio.c65
-rw-r--r--src/3rdparty/SDL2/src/audio/dummy/SDL_dummyaudio.h41
-rw-r--r--src/3rdparty/SDL2/src/audio/emscripten/SDL_emscriptenaudio.c379
-rw-r--r--src/3rdparty/SDL2/src/audio/emscripten/SDL_emscriptenaudio.h38
-rw-r--r--src/3rdparty/SDL2/src/audio/esd/SDL_esdaudio.c335
-rw-r--r--src/3rdparty/SDL2/src/audio/esd/SDL_esdaudio.h51
-rw-r--r--src/3rdparty/SDL2/src/audio/fusionsound/SDL_fsaudio.c328
-rw-r--r--src/3rdparty/SDL2/src/audio/fusionsound/SDL_fsaudio.h50
-rw-r--r--src/3rdparty/SDL2/src/audio/haiku/SDL_haikuaudio.cc248
-rw-r--r--src/3rdparty/SDL2/src/audio/haiku/SDL_haikuaudio.h38
-rw-r--r--src/3rdparty/SDL2/src/audio/jack/SDL_jackaudio.c429
-rw-r--r--src/3rdparty/SDL2/src/audio/jack/SDL_jackaudio.h42
-rw-r--r--src/3rdparty/SDL2/src/audio/nacl/SDL_naclaudio.c165
-rw-r--r--src/3rdparty/SDL2/src/audio/nacl/SDL_naclaudio.h43
-rw-r--r--src/3rdparty/SDL2/src/audio/nas/SDL_nasaudio.c463
-rw-r--r--src/3rdparty/SDL2/src/audio/nas/SDL_nasaudio.h56
-rw-r--r--src/3rdparty/SDL2/src/audio/netbsd/SDL_netbsdaudio.c412
-rw-r--r--src/3rdparty/SDL2/src/audio/netbsd/SDL_netbsdaudio.h48
-rw-r--r--src/3rdparty/SDL2/src/audio/paudio/SDL_paudio.c516
-rw-r--r--src/3rdparty/SDL2/src/audio/paudio/SDL_paudio.h48
-rw-r--r--src/3rdparty/SDL2/src/audio/psp/SDL_pspaudio.c181
-rw-r--r--src/3rdparty/SDL2/src/audio/psp/SDL_pspaudio.h45
-rw-r--r--src/3rdparty/SDL2/src/audio/pulseaudio/SDL_pulseaudio.c782
-rw-r--r--src/3rdparty/SDL2/src/audio/pulseaudio/SDL_pulseaudio.h52
-rw-r--r--src/3rdparty/SDL2/src/audio/qsa/SDL_qsa_audio.c666
-rw-r--r--src/3rdparty/SDL2/src/audio/qsa/SDL_qsa_audio.h57
-rw-r--r--src/3rdparty/SDL2/src/audio/sndio/SDL_sndioaudio.c382
-rw-r--r--src/3rdparty/SDL2/src/audio/sndio/SDL_sndioaudio.h49
-rw-r--r--src/3rdparty/SDL2/src/audio/sun/SDL_sunaudio.c419
-rw-r--r--src/3rdparty/SDL2/src/audio/sun/SDL_sunaudio.h47
-rw-r--r--src/3rdparty/SDL2/src/audio/wasapi/SDL_wasapi.c779
-rw-r--r--src/3rdparty/SDL2/src/audio/wasapi/SDL_wasapi.h85
-rw-r--r--src/3rdparty/SDL2/src/audio/wasapi/SDL_wasapi_win32.c417
-rw-r--r--src/3rdparty/SDL2/src/audio/wasapi/SDL_wasapi_winrt.cpp276
-rw-r--r--src/3rdparty/SDL2/src/audio/winmm/SDL_winmm.c457
-rw-r--r--src/3rdparty/SDL2/src/audio/winmm/SDL_winmm.h45
-rw-r--r--src/3rdparty/SDL2/src/core/android/SDL_android.c2171
-rw-r--r--src/3rdparty/SDL2/src/core/android/SDL_android.h112
-rw-r--r--src/3rdparty/SDL2/src/core/android/keyinfotable.h175
-rw-r--r--src/3rdparty/SDL2/src/core/linux/SDL_dbus.c335
-rw-r--r--src/3rdparty/SDL2/src/core/linux/SDL_dbus.h97
-rw-r--r--src/3rdparty/SDL2/src/core/linux/SDL_evdev.c698
-rw-r--r--src/3rdparty/SDL2/src/core/linux/SDL_evdev.h39
-rw-r--r--src/3rdparty/SDL2/src/core/linux/SDL_evdev_kbd.c677
-rw-r--r--src/3rdparty/SDL2/src/core/linux/SDL_evdev_kbd.h29
-rw-r--r--src/3rdparty/SDL2/src/core/linux/SDL_evdev_kbd_default_accents.h284
-rw-r--r--src/3rdparty/SDL2/src/core/linux/SDL_evdev_kbd_default_keymap.h4763
-rw-r--r--src/3rdparty/SDL2/src/core/linux/SDL_fcitx.c373
-rw-r--r--src/3rdparty/SDL2/src/core/linux/SDL_fcitx.h40
-rw-r--r--src/3rdparty/SDL2/src/core/linux/SDL_ibus.c584
-rw-r--r--src/3rdparty/SDL2/src/core/linux/SDL_ibus.h58
-rw-r--r--src/3rdparty/SDL2/src/core/linux/SDL_ime.c152
-rw-r--r--src/3rdparty/SDL2/src/core/linux/SDL_ime.h40
-rw-r--r--src/3rdparty/SDL2/src/core/linux/SDL_udev.c553
-rw-r--r--src/3rdparty/SDL2/src/core/linux/SDL_udev.h121
-rw-r--r--src/3rdparty/SDL2/src/core/unix/SDL_poll.c87
-rw-r--r--src/3rdparty/SDL2/src/core/unix/SDL_poll.h34
-rw-r--r--src/3rdparty/SDL2/src/core/windows/SDL_directx.h111
-rw-r--r--src/3rdparty/SDL2/src/core/windows/SDL_windows.c230
-rw-r--r--src/3rdparty/SDL2/src/core/windows/SDL_windows.h75
-rw-r--r--src/3rdparty/SDL2/src/core/windows/SDL_xinput.c139
-rw-r--r--src/3rdparty/SDL2/src/core/windows/SDL_xinput.h177
-rw-r--r--src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_common.cpp66
-rw-r--r--src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_common.h31
-rw-r--r--src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_direct3d.cpp855
-rw-r--r--src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_direct3d.h92
-rw-r--r--src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_xaml.cpp160
-rw-r--r--src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_xaml.h33
-rw-r--r--src/3rdparty/SDL2/src/cpuinfo/SDL_cpuinfo.c777
-rw-r--r--src/3rdparty/SDL2/src/dynapi/SDL_dynapi.c325
-rw-r--r--src/3rdparty/SDL2/src/dynapi/SDL_dynapi.h67
-rw-r--r--src/3rdparty/SDL2/src/dynapi/SDL_dynapi_overrides.h671
-rw-r--r--src/3rdparty/SDL2/src/dynapi/SDL_dynapi_procs.h709
-rw-r--r--src/3rdparty/SDL2/src/dynapi/gendynapi.pl141
-rw-r--r--src/3rdparty/SDL2/src/events/SDL_clipboardevents.c46
-rw-r--r--src/3rdparty/SDL2/src/events/SDL_clipboardevents_c.h30
-rw-r--r--src/3rdparty/SDL2/src/events/SDL_dropevents.c98
-rw-r--r--src/3rdparty/SDL2/src/events/SDL_dropevents_c.h32
-rw-r--r--src/3rdparty/SDL2/src/events/SDL_events.c955
-rw-r--r--src/3rdparty/SDL2/src/events/SDL_events_c.h49
-rw-r--r--src/3rdparty/SDL2/src/events/SDL_gesture.c700
-rw-r--r--src/3rdparty/SDL2/src/events/SDL_gesture_c.h35
-rw-r--r--src/3rdparty/SDL2/src/events/SDL_keyboard.c1033
-rw-r--r--src/3rdparty/SDL2/src/events/SDL_keyboard_c.h70
-rw-r--r--src/3rdparty/SDL2/src/events/SDL_mouse.c1027
-rw-r--r--src/3rdparty/SDL2/src/events/SDL_mouse_c.h141
-rw-r--r--src/3rdparty/SDL2/src/events/SDL_quit.c152
-rw-r--r--src/3rdparty/SDL2/src/events/SDL_sysevents.h36
-rw-r--r--src/3rdparty/SDL2/src/events/SDL_touch.c375
-rw-r--r--src/3rdparty/SDL2/src/events/SDL_touch_c.h61
-rw-r--r--src/3rdparty/SDL2/src/events/SDL_windowevents.c228
-rw-r--r--src/3rdparty/SDL2/src/events/SDL_windowevents_c.h31
-rw-r--r--src/3rdparty/SDL2/src/events/blank_cursor.h33
-rw-r--r--src/3rdparty/SDL2/src/events/default_cursor.h114
-rw-r--r--src/3rdparty/SDL2/src/events/scancodes_darwin.h159
-rw-r--r--src/3rdparty/SDL2/src/events/scancodes_linux.h263
-rw-r--r--src/3rdparty/SDL2/src/events/scancodes_windows.h55
-rw-r--r--src/3rdparty/SDL2/src/events/scancodes_xfree86.h506
-rw-r--r--src/3rdparty/SDL2/src/file/SDL_rwops.c867
-rw-r--r--src/3rdparty/SDL2/src/file/cocoa/SDL_rwopsbundlesupport.h30
-rw-r--r--src/3rdparty/SDL2/src/file/cocoa/SDL_rwopsbundlesupport.m62
-rw-r--r--src/3rdparty/SDL2/src/filesystem/android/SDL_sysfilesystem.c62
-rw-r--r--src/3rdparty/SDL2/src/filesystem/cocoa/SDL_sysfilesystem.m117
-rw-r--r--src/3rdparty/SDL2/src/filesystem/dummy/SDL_sysfilesystem.c47
-rw-r--r--src/3rdparty/SDL2/src/filesystem/emscripten/SDL_sysfilesystem.c81
-rw-r--r--src/3rdparty/SDL2/src/filesystem/haiku/SDL_sysfilesystem.cc110
-rw-r--r--src/3rdparty/SDL2/src/filesystem/nacl/SDL_sysfilesystem.c43
-rw-r--r--src/3rdparty/SDL2/src/filesystem/unix/SDL_sysfilesystem.c250
-rw-r--r--src/3rdparty/SDL2/src/filesystem/windows/SDL_sysfilesystem.c192
-rw-r--r--src/3rdparty/SDL2/src/filesystem/winrt/SDL_sysfilesystem.cpp233
-rw-r--r--src/3rdparty/SDL2/src/haptic/SDL_haptic.c849
-rw-r--r--src/3rdparty/SDL2/src/haptic/SDL_haptic_c.h25
-rw-r--r--src/3rdparty/SDL2/src/haptic/SDL_syshaptic.h208
-rw-r--r--src/3rdparty/SDL2/src/haptic/android/SDL_syshaptic.c357
-rw-r--r--src/3rdparty/SDL2/src/haptic/android/SDL_syshaptic_c.h12
-rw-r--r--src/3rdparty/SDL2/src/haptic/darwin/SDL_syshaptic.c1417
-rw-r--r--src/3rdparty/SDL2/src/haptic/darwin/SDL_syshaptic_c.h26
-rw-r--r--src/3rdparty/SDL2/src/haptic/dummy/SDL_syshaptic.c186
-rw-r--r--src/3rdparty/SDL2/src/haptic/linux/SDL_syshaptic.c1162
-rw-r--r--src/3rdparty/SDL2/src/haptic/windows/SDL_dinputhaptic.c1305
-rw-r--r--src/3rdparty/SDL2/src/haptic/windows/SDL_dinputhaptic_c.h47
-rw-r--r--src/3rdparty/SDL2/src/haptic/windows/SDL_windowshaptic.c449
-rw-r--r--src/3rdparty/SDL2/src/haptic/windows/SDL_windowshaptic_c.h88
-rw-r--r--src/3rdparty/SDL2/src/haptic/windows/SDL_xinputhaptic.c487
-rw-r--r--src/3rdparty/SDL2/src/haptic/windows/SDL_xinputhaptic_c.h47
-rw-r--r--src/3rdparty/SDL2/src/joystick/SDL_gamecontroller.c1871
-rw-r--r--src/3rdparty/SDL2/src/joystick/SDL_gamecontrollerdb.h232
-rw-r--r--src/3rdparty/SDL2/src/joystick/SDL_joystick.c1276
-rw-r--r--src/3rdparty/SDL2/src/joystick/SDL_joystick_c.h62
-rw-r--r--src/3rdparty/SDL2/src/joystick/SDL_sysjoystick.h136
-rw-r--r--src/3rdparty/SDL2/src/joystick/android/SDL_sysjoystick.c687
-rw-r--r--src/3rdparty/SDL2/src/joystick/android/SDL_sysjoystick_c.h61
-rw-r--r--src/3rdparty/SDL2/src/joystick/bsd/SDL_sysjoystick.c691
-rw-r--r--src/3rdparty/SDL2/src/joystick/darwin/SDL_sysjoystick.c837
-rw-r--r--src/3rdparty/SDL2/src/joystick/darwin/SDL_sysjoystick_c.h73
-rw-r--r--src/3rdparty/SDL2/src/joystick/dummy/SDL_sysjoystick.c127
-rw-r--r--src/3rdparty/SDL2/src/joystick/emscripten/SDL_sysjoystick.c403
-rw-r--r--src/3rdparty/SDL2/src/joystick/emscripten/SDL_sysjoystick_c.h52
-rw-r--r--src/3rdparty/SDL2/src/joystick/haiku/SDL_haikujoystick.cc266
-rw-r--r--src/3rdparty/SDL2/src/joystick/iphoneos/SDL_sysjoystick.m795
-rw-r--r--src/3rdparty/SDL2/src/joystick/iphoneos/SDL_sysjoystick_c.h59
-rw-r--r--src/3rdparty/SDL2/src/joystick/linux/SDL_sysjoystick.c1049
-rw-r--r--src/3rdparty/SDL2/src/joystick/linux/SDL_sysjoystick_c.h60
-rw-r--r--src/3rdparty/SDL2/src/joystick/psp/SDL_sysjoystick.c270
-rw-r--r--src/3rdparty/SDL2/src/joystick/sort_controllers.py66
-rw-r--r--src/3rdparty/SDL2/src/joystick/steam/SDL_steamcontroller.c52
-rw-r--r--src/3rdparty/SDL2/src/joystick/steam/SDL_steamcontroller.h33
-rw-r--r--src/3rdparty/SDL2/src/joystick/windows/SDL_dinputjoystick.c992
-rw-r--r--src/3rdparty/SDL2/src/joystick/windows/SDL_dinputjoystick_c.h30
-rw-r--r--src/3rdparty/SDL2/src/joystick/windows/SDL_mmjoystick.c461
-rw-r--r--src/3rdparty/SDL2/src/joystick/windows/SDL_windowsjoystick.c548
-rw-r--r--src/3rdparty/SDL2/src/joystick/windows/SDL_windowsjoystick_c.h93
-rw-r--r--src/3rdparty/SDL2/src/joystick/windows/SDL_xinputjoystick.c522
-rw-r--r--src/3rdparty/SDL2/src/joystick/windows/SDL_xinputjoystick_c.h33
-rw-r--r--src/3rdparty/SDL2/src/libm/e_atan2.c134
-rw-r--r--src/3rdparty/SDL2/src/libm/e_fmod.c144
-rw-r--r--src/3rdparty/SDL2/src/libm/e_log.c152
-rw-r--r--src/3rdparty/SDL2/src/libm/e_log10.c106
-rw-r--r--src/3rdparty/SDL2/src/libm/e_pow.c343
-rw-r--r--src/3rdparty/SDL2/src/libm/e_rem_pio2.c161
-rw-r--r--src/3rdparty/SDL2/src/libm/e_sqrt.c457
-rw-r--r--src/3rdparty/SDL2/src/libm/k_cos.c82
-rw-r--r--src/3rdparty/SDL2/src/libm/k_rem_pio2.c299
-rw-r--r--src/3rdparty/SDL2/src/libm/k_sin.c65
-rw-r--r--src/3rdparty/SDL2/src/libm/k_tan.c118
-rw-r--r--src/3rdparty/SDL2/src/libm/math_libm.h40
-rw-r--r--src/3rdparty/SDL2/src/libm/math_private.h226
-rw-r--r--src/3rdparty/SDL2/src/libm/s_atan.c114
-rw-r--r--src/3rdparty/SDL2/src/libm/s_copysign.c29
-rw-r--r--src/3rdparty/SDL2/src/libm/s_cos.c73
-rw-r--r--src/3rdparty/SDL2/src/libm/s_fabs.c29
-rw-r--r--src/3rdparty/SDL2/src/libm/s_floor.c71
-rw-r--r--src/3rdparty/SDL2/src/libm/s_scalbn.c69
-rw-r--r--src/3rdparty/SDL2/src/libm/s_sin.c73
-rw-r--r--src/3rdparty/SDL2/src/libm/s_tan.c67
-rw-r--r--src/3rdparty/SDL2/src/loadso/dlopen/SDL_sysloadso.c88
-rw-r--r--src/3rdparty/SDL2/src/loadso/dummy/SDL_sysloadso.c54
-rw-r--r--src/3rdparty/SDL2/src/loadso/windows/SDL_sysloadso.c80
-rw-r--r--src/3rdparty/SDL2/src/main/android/SDL_android_main.c7
-rw-r--r--src/3rdparty/SDL2/src/main/dummy/SDL_dummy_main.c28
-rw-r--r--src/3rdparty/SDL2/src/main/haiku/SDL_BApp.h399
-rw-r--r--src/3rdparty/SDL2/src/main/haiku/SDL_BeApp.cc157
-rw-r--r--src/3rdparty/SDL2/src/main/haiku/SDL_BeApp.h38
-rw-r--r--src/3rdparty/SDL2/src/main/nacl/SDL_nacl_main.c93
-rw-r--r--src/3rdparty/SDL2/src/main/psp/SDL_psp_main.c70
-rw-r--r--src/3rdparty/SDL2/src/main/windows/SDL_windows_main.c207
-rw-r--r--src/3rdparty/SDL2/src/main/windows/version.rc38
-rw-r--r--src/3rdparty/SDL2/src/main/winrt/SDL2-WinRTResource_BlankCursor.curbin0 -> 326 bytes
-rw-r--r--src/3rdparty/SDL2/src/main/winrt/SDL2-WinRTResources.rc3
-rw-r--r--src/3rdparty/SDL2/src/main/winrt/SDL_winrt_main_NonXAML.cpp54
-rw-r--r--src/3rdparty/SDL2/src/power/SDL_power.c116
-rw-r--r--src/3rdparty/SDL2/src/power/SDL_syspower.h47
-rw-r--r--src/3rdparty/SDL2/src/power/android/SDL_syspower.c64
-rw-r--r--src/3rdparty/SDL2/src/power/emscripten/SDL_syspower.c62
-rw-r--r--src/3rdparty/SDL2/src/power/haiku/SDL_syspower.c128
-rw-r--r--src/3rdparty/SDL2/src/power/linux/SDL_syspower.c642
-rw-r--r--src/3rdparty/SDL2/src/power/macosx/SDL_syspower.c192
-rw-r--r--src/3rdparty/SDL2/src/power/psp/SDL_syspower.c68
-rw-r--r--src/3rdparty/SDL2/src/power/uikit/SDL_syspower.h32
-rw-r--r--src/3rdparty/SDL2/src/power/uikit/SDL_syspower.m113
-rw-r--r--src/3rdparty/SDL2/src/power/windows/SDL_syspower.c76
-rw-r--r--src/3rdparty/SDL2/src/power/winrt/SDL_syspower.cpp44
-rw-r--r--src/3rdparty/SDL2/src/render/SDL_d3dmath.c136
-rw-r--r--src/3rdparty/SDL2/src/render/SDL_d3dmath.h72
-rw-r--r--src/3rdparty/SDL2/src/render/SDL_render.c2234
-rw-r--r--src/3rdparty/SDL2/src/render/SDL_sysrender.h204
-rw-r--r--src/3rdparty/SDL2/src/render/SDL_yuv_sw.c414
-rw-r--r--src/3rdparty/SDL2/src/render/SDL_yuv_sw_c.h67
-rw-r--r--src/3rdparty/SDL2/src/render/direct3d/SDL_render_d3d.c1825
-rw-r--r--src/3rdparty/SDL2/src/render/direct3d/SDL_shaders_d3d.c274
-rw-r--r--src/3rdparty/SDL2/src/render/direct3d/SDL_shaders_d3d.h34
-rw-r--r--src/3rdparty/SDL2/src/render/direct3d11/SDL_render_d3d11.c2570
-rw-r--r--src/3rdparty/SDL2/src/render/direct3d11/SDL_render_winrt.cpp116
-rw-r--r--src/3rdparty/SDL2/src/render/direct3d11/SDL_render_winrt.h40
-rw-r--r--src/3rdparty/SDL2/src/render/direct3d11/SDL_shaders_d3d11.c1957
-rw-r--r--src/3rdparty/SDL2/src/render/direct3d11/SDL_shaders_d3d11.h43
-rw-r--r--src/3rdparty/SDL2/src/render/metal/SDL_render_metal.m1429
-rw-r--r--src/3rdparty/SDL2/src/render/metal/SDL_shaders_metal.metal109
-rw-r--r--src/3rdparty/SDL2/src/render/metal/SDL_shaders_metal_ios.h1899
-rw-r--r--src/3rdparty/SDL2/src/render/metal/SDL_shaders_metal_osx.h1903
-rw-r--r--src/3rdparty/SDL2/src/render/metal/build-metal-shaders.sh18
-rw-r--r--src/3rdparty/SDL2/src/render/opengl/SDL_glfuncs.h478
-rw-r--r--src/3rdparty/SDL2/src/render/opengl/SDL_render_gl.c1690
-rw-r--r--src/3rdparty/SDL2/src/render/opengl/SDL_shaders_gl.c524
-rw-r--r--src/3rdparty/SDL2/src/render/opengl/SDL_shaders_gl.h47
-rw-r--r--src/3rdparty/SDL2/src/render/opengles/SDL_glesfuncs.h65
-rw-r--r--src/3rdparty/SDL2/src/render/opengles/SDL_render_gles.c1290
-rw-r--r--src/3rdparty/SDL2/src/render/opengles2/SDL_gles2funcs.h80
-rw-r--r--src/3rdparty/SDL2/src/render/opengles2/SDL_render_gles2.c2258
-rw-r--r--src/3rdparty/SDL2/src/render/opengles2/SDL_shaders_gles2.c569
-rw-r--r--src/3rdparty/SDL2/src/render/opengles2/SDL_shaders_gles2.h70
-rw-r--r--src/3rdparty/SDL2/src/render/psp/SDL_render_psp.c1028
-rw-r--r--src/3rdparty/SDL2/src/render/software/SDL_blendfillrect.c336
-rw-r--r--src/3rdparty/SDL2/src/render/software/SDL_blendfillrect.h27
-rw-r--r--src/3rdparty/SDL2/src/render/software/SDL_blendline.c777
-rw-r--r--src/3rdparty/SDL2/src/render/software/SDL_blendline.h27
-rw-r--r--src/3rdparty/SDL2/src/render/software/SDL_blendpoint.c341
-rw-r--r--src/3rdparty/SDL2/src/render/software/SDL_blendpoint.h27
-rw-r--r--src/3rdparty/SDL2/src/render/software/SDL_draw.h576
-rw-r--r--src/3rdparty/SDL2/src/render/software/SDL_drawline.c209
-rw-r--r--src/3rdparty/SDL2/src/render/software/SDL_drawline.h27
-rw-r--r--src/3rdparty/SDL2/src/render/software/SDL_drawpoint.c114
-rw-r--r--src/3rdparty/SDL2/src/render/software/SDL_drawpoint.h27
-rw-r--r--src/3rdparty/SDL2/src/render/software/SDL_render_sw.c894
-rw-r--r--src/3rdparty/SDL2/src/render/software/SDL_render_sw_c.h24
-rw-r--r--src/3rdparty/SDL2/src/render/software/SDL_rotate.c530
-rw-r--r--src/3rdparty/SDL2/src/render/software/SDL_rotate.h28
-rw-r--r--src/3rdparty/SDL2/src/stdlib/SDL_getenv.c315
-rw-r--r--src/3rdparty/SDL2/src/stdlib/SDL_iconv.c934
-rw-r--r--src/3rdparty/SDL2/src/stdlib/SDL_malloc.c5376
-rw-r--r--src/3rdparty/SDL2/src/stdlib/SDL_qsort.c534
-rw-r--r--src/3rdparty/SDL2/src/stdlib/SDL_stdlib.c1131
-rw-r--r--src/3rdparty/SDL2/src/stdlib/SDL_string.c1715
-rw-r--r--src/3rdparty/SDL2/src/test/SDL_test_assert.c152
-rw-r--r--src/3rdparty/SDL2/src/test/SDL_test_common.c1783
-rw-r--r--src/3rdparty/SDL2/src/test/SDL_test_compare.c117
-rw-r--r--src/3rdparty/SDL2/src/test/SDL_test_crc32.c166
-rw-r--r--src/3rdparty/SDL2/src/test/SDL_test_font.c3250
-rw-r--r--src/3rdparty/SDL2/src/test/SDL_test_fuzzer.c534
-rw-r--r--src/3rdparty/SDL2/src/test/SDL_test_harness.c680
-rw-r--r--src/3rdparty/SDL2/src/test/SDL_test_imageBlit.c1559
-rw-r--r--src/3rdparty/SDL2/src/test/SDL_test_imageBlitBlend.c2845
-rw-r--r--src/3rdparty/SDL2/src/test/SDL_test_imageFace.c247
-rw-r--r--src/3rdparty/SDL2/src/test/SDL_test_imagePrimitives.c514
-rw-r--r--src/3rdparty/SDL2/src/test/SDL_test_imagePrimitivesBlend.c696
-rw-r--r--src/3rdparty/SDL2/src/test/SDL_test_log.c118
-rw-r--r--src/3rdparty/SDL2/src/test/SDL_test_md5.c338
-rw-r--r--src/3rdparty/SDL2/src/test/SDL_test_memory.c274
-rw-r--r--src/3rdparty/SDL2/src/test/SDL_test_random.c96
-rw-r--r--src/3rdparty/SDL2/src/thread/SDL_systhread.h70
-rw-r--r--src/3rdparty/SDL2/src/thread/SDL_thread.c503
-rw-r--r--src/3rdparty/SDL2/src/thread/SDL_thread_c.h95
-rw-r--r--src/3rdparty/SDL2/src/thread/generic/SDL_syscond.c220
-rw-r--r--src/3rdparty/SDL2/src/thread/generic/SDL_sysmutex.c165
-rw-r--r--src/3rdparty/SDL2/src/thread/generic/SDL_sysmutex_c.h22
-rw-r--r--src/3rdparty/SDL2/src/thread/generic/SDL_syssem.c217
-rw-r--r--src/3rdparty/SDL2/src/thread/generic/SDL_systhread.c71
-rw-r--r--src/3rdparty/SDL2/src/thread/generic/SDL_systhread_c.h26
-rw-r--r--src/3rdparty/SDL2/src/thread/generic/SDL_systls.c38
-rw-r--r--src/3rdparty/SDL2/src/thread/psp/SDL_syscond.c224
-rw-r--r--src/3rdparty/SDL2/src/thread/psp/SDL_sysmutex.c136
-rw-r--r--src/3rdparty/SDL2/src/thread/psp/SDL_sysmutex_c.h22
-rw-r--r--src/3rdparty/SDL2/src/thread/psp/SDL_syssem.c161
-rw-r--r--src/3rdparty/SDL2/src/thread/psp/SDL_systhread.c112
-rw-r--r--src/3rdparty/SDL2/src/thread/psp/SDL_systhread_c.h24
-rw-r--r--src/3rdparty/SDL2/src/thread/pthread/SDL_syscond.c158
-rw-r--r--src/3rdparty/SDL2/src/thread/pthread/SDL_sysmutex.c192
-rw-r--r--src/3rdparty/SDL2/src/thread/pthread/SDL_sysmutex_c.h32
-rw-r--r--src/3rdparty/SDL2/src/thread/pthread/SDL_syssem.c209
-rw-r--r--src/3rdparty/SDL2/src/thread/pthread/SDL_systhread.c246
-rw-r--r--src/3rdparty/SDL2/src/thread/pthread/SDL_systhread_c.h27
-rw-r--r--src/3rdparty/SDL2/src/thread/pthread/SDL_systls.c70
-rw-r--r--src/3rdparty/SDL2/src/thread/stdcpp/SDL_syscond.cpp164
-rw-r--r--src/3rdparty/SDL2/src/thread/stdcpp/SDL_sysmutex.cpp111
-rw-r--r--src/3rdparty/SDL2/src/thread/stdcpp/SDL_sysmutex_c.h30
-rw-r--r--src/3rdparty/SDL2/src/thread/stdcpp/SDL_systhread.cpp168
-rw-r--r--src/3rdparty/SDL2/src/thread/stdcpp/SDL_systhread_c.h26
-rw-r--r--src/3rdparty/SDL2/src/thread/windows/SDL_sysmutex.c110
-rw-r--r--src/3rdparty/SDL2/src/thread/windows/SDL_syssem.c152
-rw-r--r--src/3rdparty/SDL2/src/thread/windows/SDL_systhread.c258
-rw-r--r--src/3rdparty/SDL2/src/thread/windows/SDL_systhread_c.h32
-rw-r--r--src/3rdparty/SDL2/src/thread/windows/SDL_systls.c72
-rw-r--r--src/3rdparty/SDL2/src/timer/SDL_timer.c373
-rw-r--r--src/3rdparty/SDL2/src/timer/SDL_timer_c.h34
-rw-r--r--src/3rdparty/SDL2/src/timer/dummy/SDL_systimer.c75
-rw-r--r--src/3rdparty/SDL2/src/timer/haiku/SDL_systimer.c80
-rw-r--r--src/3rdparty/SDL2/src/timer/psp/SDL_systimer.c91
-rw-r--r--src/3rdparty/SDL2/src/timer/unix/SDL_systimer.c232
-rw-r--r--src/3rdparty/SDL2/src/timer/windows/SDL_systimer.c200
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_RLEaccel.c1581
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_RLEaccel_c.h31
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_blit.c296
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_blit.h553
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_blit_0.c483
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_blit_1.c552
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_blit_A.c1388
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_blit_N.c2647
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_blit_auto.c7419
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_blit_auto.h30
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_blit_copy.c162
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_blit_copy.h24
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_blit_slow.c164
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_blit_slow.h25
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_bmp.c702
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_clipboard.c90
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_egl.c838
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_egl_c.h149
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_fillrect.c343
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_pixels.c1125
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_pixels_c.h40
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_rect.c531
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_rect_c.h25
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_shape.c309
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_shape_internals.h69
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_stretch.c353
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_surface.c1232
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_sysvideo.h459
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_video.c4077
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_vulkan_internal.h91
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_vulkan_utils.c172
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_yuv.c1834
-rw-r--r--src/3rdparty/SDL2/src/video/SDL_yuv_c.h30
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidclipboard.c48
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidclipboard.h32
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidevents.c123
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidevents.h27
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidgl.c62
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidgl.h34
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidkeyboard.c391
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidkeyboard.h36
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidmessagebox.c37
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidmessagebox.h29
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidmouse.c117
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidmouse.h32
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidtouch.c151
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidtouch.h29
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidvideo.c254
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidvideo.h49
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidvulkan.c175
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidvulkan.h52
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidwindow.c152
-rw-r--r--src/3rdparty/SDL2/src/video/android/SDL_androidwindow.h45
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaclipboard.h36
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaclipboard.m103
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaevents.h32
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaevents.m483
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoakeyboard.h36
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoakeyboard.m720
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamessagebox.h29
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamessagebox.m145
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoametalview.h63
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoametalview.m135
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamodes.h46
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamodes.m490
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamouse.h52
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamouse.m467
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamousetap.h34
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamousetap.m279
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaopengl.h68
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaopengl.m428
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaopengles.h49
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaopengles.m132
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoashape.h45
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoashape.m113
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoavideo.h118
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoavideo.m253
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoavulkan.h55
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoavulkan.m231
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoawindow.h154
-rw-r--r--src/3rdparty/SDL2/src/video/cocoa/SDL_cocoawindow.m1877
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_WM.c413
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_WM.h56
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_dyn.c117
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_dyn.h41
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_events.c748
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_events.h34
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_modes.c414
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_modes.h59
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_mouse.c389
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_mouse.h44
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_opengl.c332
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_opengl.h64
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_render.c1335
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_render.h25
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_shape.c131
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_shape.h38
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_video.c418
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_video.h170
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_window.c565
-rw-r--r--src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_window.h82
-rw-r--r--src/3rdparty/SDL2/src/video/dummy/SDL_nullevents.c41
-rw-r--r--src/3rdparty/SDL2/src/video/dummy/SDL_nullevents_c.h27
-rw-r--r--src/3rdparty/SDL2/src/video/dummy/SDL_nullframebuffer.c89
-rw-r--r--src/3rdparty/SDL2/src/video/dummy/SDL_nullframebuffer_c.h27
-rw-r--r--src/3rdparty/SDL2/src/video/dummy/SDL_nullvideo.c144
-rw-r--r--src/3rdparty/SDL2/src/video/dummy/SDL_nullvideo.h30
-rw-r--r--src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenevents.c716
-rw-r--r--src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenevents.h40
-rw-r--r--src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenframebuffer.c178
-rw-r--r--src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenframebuffer.h32
-rw-r--r--src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenmouse.c274
-rw-r--r--src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenmouse.h42
-rw-r--r--src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenopengles.c119
-rw-r--r--src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenopengles.h49
-rw-r--r--src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenvideo.c354
-rw-r--r--src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenvideo.h58
-rw-r--r--src/3rdparty/SDL2/src/video/haiku/SDL_BWin.h679
-rw-r--r--src/3rdparty/SDL2/src/video/haiku/SDL_bclipboard.cc95
-rw-r--r--src/3rdparty/SDL2/src/video/haiku/SDL_bclipboard.h33
-rw-r--r--src/3rdparty/SDL2/src/video/haiku/SDL_bevents.cc41
-rw-r--r--src/3rdparty/SDL2/src/video/haiku/SDL_bevents.h39
-rw-r--r--src/3rdparty/SDL2/src/video/haiku/SDL_bframebuffer.cc259
-rw-r--r--src/3rdparty/SDL2/src/video/haiku/SDL_bframebuffer.h47
-rw-r--r--src/3rdparty/SDL2/src/video/haiku/SDL_bkeyboard.cc190
-rw-r--r--src/3rdparty/SDL2/src/video/haiku/SDL_bkeyboard.h44
-rw-r--r--src/3rdparty/SDL2/src/video/haiku/SDL_bmodes.cc333
-rw-r--r--src/3rdparty/SDL2/src/video/haiku/SDL_bmodes.h48
-rw-r--r--src/3rdparty/SDL2/src/video/haiku/SDL_bopengl.cc176
-rw-r--r--src/3rdparty/SDL2/src/video/haiku/SDL_bopengl.h55
-rw-r--r--src/3rdparty/SDL2/src/video/haiku/SDL_bvideo.cc178
-rw-r--r--src/3rdparty/SDL2/src/video/haiku/SDL_bvideo.h44
-rw-r--r--src/3rdparty/SDL2/src/video/haiku/SDL_bwindow.cc233
-rw-r--r--src/3rdparty/SDL2/src/video/haiku/SDL_bwindow.h55
-rw-r--r--src/3rdparty/SDL2/src/video/khronos/EGL/egl.h303
-rw-r--r--src/3rdparty/SDL2/src/video/khronos/EGL/eglext.h1241
-rw-r--r--src/3rdparty/SDL2/src/video/khronos/EGL/eglplatform.h132
-rw-r--r--src/3rdparty/SDL2/src/video/khronos/GLES2/gl2.h675
-rw-r--r--src/3rdparty/SDL2/src/video/khronos/GLES2/gl2ext.h3505
-rw-r--r--src/3rdparty/SDL2/src/video/khronos/GLES2/gl2platform.h38
-rw-r--r--src/3rdparty/SDL2/src/video/khronos/KHR/khrplatform.h284
-rw-r--r--src/3rdparty/SDL2/src/video/khronos/vulkan/vk_platform.h120
-rw-r--r--src/3rdparty/SDL2/src/video/khronos/vulkan/vulkan.h6458
-rw-r--r--src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmdyn.c171
-rw-r--r--src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmdyn.h53
-rw-r--r--src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmevents.c42
-rw-r--r--src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmevents.h31
-rw-r--r--src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmmouse.c501
-rw-r--r--src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmmouse.h45
-rw-r--r--src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmopengles.c189
-rw-r--r--src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmopengles.h48
-rw-r--r--src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmsym.h99
-rw-r--r--src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmvideo.c664
-rw-r--r--src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmvideo.h124
-rw-r--r--src/3rdparty/SDL2/src/video/mir/SDL_mirdyn.c170
-rw-r--r--src/3rdparty/SDL2/src/video/mir/SDL_mirdyn.h53
-rw-r--r--src/3rdparty/SDL2/src/video/mir/SDL_mirevents.c321
-rw-r--r--src/3rdparty/SDL2/src/video/mir/SDL_mirevents.h37
-rw-r--r--src/3rdparty/SDL2/src/video/mir/SDL_mirframebuffer.c134
-rw-r--r--src/3rdparty/SDL2/src/video/mir/SDL_mirframebuffer.h47
-rw-r--r--src/3rdparty/SDL2/src/video/mir/SDL_mirmouse.c292
-rw-r--r--src/3rdparty/SDL2/src/video/mir/SDL_mirmouse.h37
-rw-r--r--src/3rdparty/SDL2/src/video/mir/SDL_miropengl.c78
-rw-r--r--src/3rdparty/SDL2/src/video/mir/SDL_miropengl.h53
-rw-r--r--src/3rdparty/SDL2/src/video/mir/SDL_mirsym.h143
-rw-r--r--src/3rdparty/SDL2/src/video/mir/SDL_mirvideo.c423
-rw-r--r--src/3rdparty/SDL2/src/video/mir/SDL_mirvideo.h49
-rw-r--r--src/3rdparty/SDL2/src/video/mir/SDL_mirvulkan.c176
-rw-r--r--src/3rdparty/SDL2/src/video/mir/SDL_mirvulkan.h52
-rw-r--r--src/3rdparty/SDL2/src/video/mir/SDL_mirwindow.c374
-rw-r--r--src/3rdparty/SDL2/src/video/mir/SDL_mirwindow.h93
-rw-r--r--src/3rdparty/SDL2/src/video/nacl/SDL_naclevents.c438
-rw-r--r--src/3rdparty/SDL2/src/video/nacl/SDL_naclevents_c.h30
-rw-r--r--src/3rdparty/SDL2/src/video/nacl/SDL_naclglue.c24
-rw-r--r--src/3rdparty/SDL2/src/video/nacl/SDL_naclopengles.c174
-rw-r--r--src/3rdparty/SDL2/src/video/nacl/SDL_naclopengles.h38
-rw-r--r--src/3rdparty/SDL2/src/video/nacl/SDL_naclvideo.c183
-rw-r--r--src/3rdparty/SDL2/src/video/nacl/SDL_naclvideo.h67
-rw-r--r--src/3rdparty/SDL2/src/video/nacl/SDL_naclwindow.c79
-rw-r--r--src/3rdparty/SDL2/src/video/nacl/SDL_naclwindow.h32
-rw-r--r--src/3rdparty/SDL2/src/video/pandora/SDL_pandora.c838
-rw-r--r--src/3rdparty/SDL2/src/video/pandora/SDL_pandora.h101
-rw-r--r--src/3rdparty/SDL2/src/video/pandora/SDL_pandora_events.c38
-rw-r--r--src/3rdparty/SDL2/src/video/pandora/SDL_pandora_events.h25
-rw-r--r--src/3rdparty/SDL2/src/video/psp/SDL_pspevents.c290
-rw-r--r--src/3rdparty/SDL2/src/video/psp/SDL_pspevents_c.h31
-rw-r--r--src/3rdparty/SDL2/src/video/psp/SDL_pspgl.c210
-rw-r--r--src/3rdparty/SDL2/src/video/psp/SDL_pspgl_c.h54
-rw-r--r--src/3rdparty/SDL2/src/video/psp/SDL_pspmouse.c41
-rw-r--r--src/3rdparty/SDL2/src/video/psp/SDL_pspmouse_c.h24
-rw-r--r--src/3rdparty/SDL2/src/video/psp/SDL_pspvideo.c333
-rw-r--r--src/3rdparty/SDL2/src/video/psp/SDL_pspvideo.h102
-rw-r--r--src/3rdparty/SDL2/src/video/qnx/gl.c285
-rw-r--r--src/3rdparty/SDL2/src/video/qnx/keyboard.c133
-rw-r--r--src/3rdparty/SDL2/src/video/qnx/sdl_qnx.h48
-rw-r--r--src/3rdparty/SDL2/src/video/qnx/video.c364
-rw-r--r--src/3rdparty/SDL2/src/video/raspberry/SDL_rpievents.c45
-rw-r--r--src/3rdparty/SDL2/src/video/raspberry/SDL_rpievents_c.h31
-rw-r--r--src/3rdparty/SDL2/src/video/raspberry/SDL_rpimouse.c386
-rw-r--r--src/3rdparty/SDL2/src/video/raspberry/SDL_rpimouse.h43
-rw-r--r--src/3rdparty/SDL2/src/video/raspberry/SDL_rpiopengles.c71
-rw-r--r--src/3rdparty/SDL2/src/video/raspberry/SDL_rpiopengles.h49
-rw-r--r--src/3rdparty/SDL2/src/video/raspberry/SDL_rpivideo.c442
-rw-r--r--src/3rdparty/SDL2/src/video/raspberry/SDL_rpivideo.h104
-rw-r--r--src/3rdparty/SDL2/src/video/sdlgenblit.pl535
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitappdelegate.h47
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitappdelegate.m539
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitclipboard.h35
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitclipboard.m111
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitevents.h30
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitevents.m73
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitmessagebox.h31
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitmessagebox.m206
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitmetalview.h58
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitmetalview.m124
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitmodes.h50
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitmodes.m324
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitopengles.h40
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitopengles.m250
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitopenglview.h60
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitopenglview.m384
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitvideo.h46
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitvideo.m238
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitview.h41
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitview.m328
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitviewcontroller.h91
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitviewcontroller.m532
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitvulkan.h54
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitvulkan.m222
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitwindow.h56
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/SDL_uikitwindow.m465
-rw-r--r--src/3rdparty/SDL2/src/video/uikit/keyinfotable.h174
-rw-r--r--src/3rdparty/SDL2/src/video/vivante/SDL_vivanteopengles.c47
-rw-r--r--src/3rdparty/SDL2/src/video/vivante/SDL_vivanteopengles.h48
-rw-r--r--src/3rdparty/SDL2/src/video/vivante/SDL_vivanteplatform.c54
-rw-r--r--src/3rdparty/SDL2/src/video/vivante/SDL_vivanteplatform.h47
-rw-r--r--src/3rdparty/SDL2/src/video/vivante/SDL_vivantevideo.c409
-rw-r--r--src/3rdparty/SDL2/src/video/vivante/SDL_vivantevideo.h91
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylandclipboard.c123
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylandclipboard.h32
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylanddatamanager.c468
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylanddatamanager.h103
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylanddyn.c178
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylanddyn.h107
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylandevents.c1129
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylandevents_c.h51
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylandmouse.c396
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylandmouse.h31
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylandopengles.c93
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylandopengles.h49
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylandsym.h127
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylandtouch.c265
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylandtouch.h352
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylandvideo.c499
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylandvideo.h75
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylandvulkan.c176
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylandvulkan.h52
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylandwindow.c552
-rw-r--r--src/3rdparty/SDL2/src/video/wayland/SDL_waylandwindow.h78
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_msctf.h242
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_vkeys.h76
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsclipboard.c160
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsclipboard.h36
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsevents.c1204
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsevents.h36
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsframebuffer.c127
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsframebuffer.h27
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowskeyboard.c1579
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowskeyboard.h40
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsmessagebox.c496
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsmessagebox.h29
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsmodes.c407
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsmodes.h47
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsmouse.c322
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsmouse.h33
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsopengl.c895
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsopengl.h142
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsopengles.c131
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsopengles.h49
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsshape.c110
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsshape.h40
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsvideo.c441
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsvideo.h199
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsvulkan.c176
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowsvulkan.h52
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowswindow.c970
-rw-r--r--src/3rdparty/SDL2/src/video/windows/SDL_windowswindow.h84
-rw-r--r--src/3rdparty/SDL2/src/video/windows/wmmsg.h1052
-rw-r--r--src/3rdparty/SDL2/src/video/winrt/SDL_winrtevents.cpp154
-rw-r--r--src/3rdparty/SDL2/src/video/winrt/SDL_winrtevents_c.h82
-rw-r--r--src/3rdparty/SDL2/src/video/winrt/SDL_winrtgamebar.cpp196
-rw-r--r--src/3rdparty/SDL2/src/video/winrt/SDL_winrtgamebar_cpp.h35
-rw-r--r--src/3rdparty/SDL2/src/video/winrt/SDL_winrtkeyboard.cpp430
-rw-r--r--src/3rdparty/SDL2/src/video/winrt/SDL_winrtmessagebox.cpp112
-rw-r--r--src/3rdparty/SDL2/src/video/winrt/SDL_winrtmessagebox.h29
-rw-r--r--src/3rdparty/SDL2/src/video/winrt/SDL_winrtmouse.cpp224
-rw-r--r--src/3rdparty/SDL2/src/video/winrt/SDL_winrtmouse_c.h40
-rw-r--r--src/3rdparty/SDL2/src/video/winrt/SDL_winrtopengles.cpp203
-rw-r--r--src/3rdparty/SDL2/src/video/winrt/SDL_winrtopengles.h70
-rw-r--r--src/3rdparty/SDL2/src/video/winrt/SDL_winrtpointerinput.cpp415
-rw-r--r--src/3rdparty/SDL2/src/video/winrt/SDL_winrtvideo.cpp842
-rw-r--r--src/3rdparty/SDL2/src/video/winrt/SDL_winrtvideo_cpp.h106
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11clipboard.c199
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11clipboard.h33
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11dyn.c212
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11dyn.h111
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11events.c1500
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11events.h31
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11framebuffer.c257
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11framebuffer.h31
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11keyboard.c549
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11keyboard.h36
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11messagebox.c853
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11messagebox.h28
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11modes.c1112
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11modes.h85
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11mouse.c448
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11mouse.h31
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11opengl.c946
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11opengl.h84
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11opengles.c109
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11opengles.h56
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11shape.c115
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11shape.h39
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11sym.h337
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11touch.c54
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11touch.h32
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11video.c496
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11video.h156
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11vulkan.c243
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11vulkan.h48
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11window.c1609
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11window.h110
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11xinput2.c313
-rw-r--r--src/3rdparty/SDL2/src/video/x11/SDL_x11xinput2.h42
-rw-r--r--src/3rdparty/SDL2/src/video/x11/edid-parse.c754
-rw-r--r--src/3rdparty/SDL2/src/video/x11/edid.h167
-rw-r--r--src/3rdparty/SDL2/src/video/x11/imKStoUCS.c350
-rw-r--r--src/3rdparty/SDL2/src/video/x11/imKStoUCS.h32
-rw-r--r--src/3rdparty/SDL2/src/video/yuv2rgb/LICENSE27
-rw-r--r--src/3rdparty/SDL2/src/video/yuv2rgb/README.md63
-rw-r--r--src/3rdparty/SDL2/src/video/yuv2rgb/yuv_rgb.c687
-rw-r--r--src/3rdparty/SDL2/src/video/yuv2rgb/yuv_rgb.h381
-rw-r--r--src/3rdparty/SDL2/src/video/yuv2rgb/yuv_rgb_sse_func.h498
-rw-r--r--src/3rdparty/SDL2/src/video/yuv2rgb/yuv_rgb_std_func.h220
-rw-r--r--src/3rdparty/buildvm/buildvm-post.bat17
-rw-r--r--src/3rdparty/buildvm/buildvm.exebin0 -> 121856 bytes
-rw-r--r--src/3rdparty/minilua/minilua-post.bat6
-rw-r--r--src/3rdparty/minilua/minilua.exebin0 -> 209920 bytes
-rw-r--r--src/3rdparty/ogl/OpenGL.h184
-rw-r--r--src/3rdparty/smount/dirent.h (renamed from src/libjin/3rdparty/smount/dirent.h)0
-rw-r--r--src/3rdparty/smount/smount.c (renamed from src/libjin/3rdparty/smount/smount.c)0
-rw-r--r--src/3rdparty/smount/smount.h (renamed from src/libjin/3rdparty/smount/smount.h)0
-rw-r--r--src/3rdparty/stb/stb_image.h (renamed from src/libjin/3rdparty/stb/stb_image.h)0
-rw-r--r--src/3rdparty/stb/stb_truetype.h (renamed from src/libjin/3rdparty/stb/stb_truetype.h)0
-rw-r--r--src/3rdparty/stb/stb_vorbis.c (renamed from src/libjin/3rdparty/stb/stb_vorbis.c)0
-rw-r--r--src/3rdparty/tekcos/README (renamed from src/libjin/3rdparty/tekcos/README)0
-rw-r--r--src/3rdparty/tekcos/tekcos.c (renamed from src/libjin/3rdparty/tekcos/tekcos.c)0
-rw-r--r--src/3rdparty/tekcos/tekcos.h (renamed from src/libjin/3rdparty/tekcos/tekcos.h)0
-rw-r--r--src/3rdparty/wav/wav.c (renamed from src/libjin/3rdparty/wav/wav.c)0
-rw-r--r--src/3rdparty/wav/wav.h (renamed from src/libjin/3rdparty/wav/wav.h)0
-rw-r--r--src/jin/main.cpp107
-rw-r--r--src/libjin/3rdparty/base64/base64.h186
-rw-r--r--src/libjin/3rdparty/ogl/OpenGL.h520
-rw-r--r--src/libjin/Audio/SDL/je_sdl_audio.cpp251
-rw-r--r--src/libjin/Audio/SDL/je_sdl_audio.h237
-rw-r--r--src/libjin/Audio/SDL/je_sdl_source.cpp732
-rw-r--r--src/libjin/Audio/SDL/je_sdl_source.h487
-rw-r--r--src/libjin/Audio/je_audio_manager.h6
-rw-r--r--src/libjin/Audio/je_source.h6
-rw-r--r--src/libjin/Common/je_array.hpp4
-rw-r--r--src/libjin/Common/je_common.h5
-rw-r--r--src/libjin/Common/je_exception.cpp46
-rw-r--r--src/libjin/Common/je_exception.h35
-rw-r--r--src/libjin/Common/je_noncopyable.h4
-rw-r--r--src/libjin/Common/je_object.h6
-rw-r--r--src/libjin/Common/je_pool.hpp172
-rw-r--r--src/libjin/Common/je_singleton.hpp6
-rw-r--r--src/libjin/Common/je_stringmap.hpp4
-rw-r--r--src/libjin/Common/je_subsystem.hpp4
-rw-r--r--src/libjin/Common/je_temporary.h4
-rw-r--r--src/libjin/Common/je_types.h4
-rw-r--r--src/libjin/Common/je_utf8.h6
-rw-r--r--src/libjin/Filesystem/je_asset_database.cpp14
-rw-r--r--src/libjin/Filesystem/je_asset_database.h10
-rw-r--r--src/libjin/Filesystem/je_buffer.h4
-rw-r--r--src/libjin/Game/je_application.cpp (renamed from src/libjin/Game/je_game.cpp)14
-rw-r--r--src/libjin/Game/je_application.h (renamed from src/libjin/Game/je_game.h)16
-rw-r--r--src/libjin/Game/je_entity.cpp11
-rw-r--r--src/libjin/Game/je_entity.h64
-rw-r--r--src/libjin/Game/je_gameobject.cpp11
-rw-r--r--src/libjin/Game/je_gameobject.h86
-rw-r--r--src/libjin/Game/je_scene.h12
-rw-r--r--src/libjin/Graphics/Font/je_decoder.cpp93
-rw-r--r--src/libjin/Graphics/Font/je_decoder.h94
-rw-r--r--src/libjin/Graphics/Font/je_font.h100
-rw-r--r--src/libjin/Graphics/Font/je_page.h51
-rw-r--r--src/libjin/Graphics/Font/je_text.cpp154
-rw-r--r--src/libjin/Graphics/Font/je_text.h169
-rw-r--r--src/libjin/Graphics/Font/je_texture_font.cpp318
-rw-r--r--src/libjin/Graphics/Font/je_texture_font.h140
-rw-r--r--src/libjin/Graphics/Font/je_ttf.cpp463
-rw-r--r--src/libjin/Graphics/Font/je_ttf.h288
-rw-r--r--src/libjin/Graphics/Shader/je_jsl_compiler.cpp54
-rw-r--r--src/libjin/Graphics/Shader/je_jsl_compiler.h42
-rw-r--r--src/libjin/Graphics/Shader/je_shader.cpp278
-rw-r--r--src/libjin/Graphics/Shader/je_shader.h200
-rw-r--r--src/libjin/Graphics/animation/je_animation.h20
-rw-r--r--src/libjin/Graphics/animation/je_clip.h20
-rw-r--r--src/libjin/Graphics/animations/je_animation.cpp14
-rw-r--r--src/libjin/Graphics/animations/je_animation.h64
-rw-r--r--src/libjin/Graphics/animations/je_animator.cpp14
-rw-r--r--src/libjin/Graphics/animations/je_animator.h50
-rw-r--r--src/libjin/Graphics/fonts/je_decoder.cpp96
-rw-r--r--src/libjin/Graphics/fonts/je_decoder.h97
-rw-r--r--src/libjin/Graphics/fonts/je_font.h109
-rw-r--r--src/libjin/Graphics/fonts/je_page.h54
-rw-r--r--src/libjin/Graphics/fonts/je_text.cpp157
-rw-r--r--src/libjin/Graphics/fonts/je_text.h172
-rw-r--r--src/libjin/Graphics/fonts/je_texture_font.cpp322
-rw-r--r--src/libjin/Graphics/fonts/je_texture_font.h144
-rw-r--r--src/libjin/Graphics/fonts/je_ttf.cpp468
-rw-r--r--src/libjin/Graphics/fonts/je_ttf.h292
-rw-r--r--src/libjin/Graphics/je_bitmap.cpp42
-rw-r--r--src/libjin/Graphics/je_bitmap.h21
-rw-r--r--src/libjin/Graphics/je_canvas.cpp15
-rw-r--r--src/libjin/Graphics/je_canvas.h9
-rw-r--r--src/libjin/Graphics/je_color.cpp5
-rw-r--r--src/libjin/Graphics/je_color.h32
-rw-r--r--src/libjin/Graphics/je_gl.cpp80
-rw-r--r--src/libjin/Graphics/je_gl.h46
-rw-r--r--src/libjin/Graphics/je_graphic.cpp96
-rw-r--r--src/libjin/Graphics/je_graphic.h52
-rw-r--r--src/libjin/Graphics/je_graphics.h30
-rw-r--r--src/libjin/Graphics/je_image.cpp3
-rw-r--r--src/libjin/Graphics/je_image.h7
-rw-r--r--src/libjin/Graphics/je_mesh.h12
-rw-r--r--src/libjin/Graphics/je_shapes.cpp32
-rw-r--r--src/libjin/Graphics/je_shapes.h10
-rw-r--r--src/libjin/Graphics/je_sprite.cpp145
-rw-r--r--src/libjin/Graphics/je_sprite.h73
-rw-r--r--src/libjin/Graphics/je_sprite_batch.cpp11
-rw-r--r--src/libjin/Graphics/je_sprite_batch.h9
-rw-r--r--src/libjin/Graphics/je_sprite_sheet.cpp22
-rw-r--r--src/libjin/Graphics/je_sprite_sheet.h33
-rw-r--r--src/libjin/Graphics/je_texture.h11
-rw-r--r--src/libjin/Graphics/je_window.cpp43
-rw-r--r--src/libjin/Graphics/je_window.h14
-rw-r--r--src/libjin/Graphics/particle/je_particle.h21
-rw-r--r--src/libjin/Graphics/particle/je_particle_batch.h20
-rw-r--r--src/libjin/Graphics/particle/je_particle_emitter.h23
-rw-r--r--src/libjin/Graphics/particles/je_particle.cpp26
-rw-r--r--src/libjin/Graphics/particles/je_particle.h178
-rw-r--r--src/libjin/Graphics/particles/je_particle_emitter.cpp42
-rw-r--r--src/libjin/Graphics/particles/je_particle_emitter.h112
-rw-r--r--src/libjin/Graphics/particles/je_particle_pool.h24
-rw-r--r--src/libjin/Graphics/particles/je_particle_system.cpp (renamed from src/libjin/Graphics/particle/je_particle_emitter.cpp)2
-rw-r--r--src/libjin/Graphics/particles/je_particle_system.h103
-rw-r--r--src/libjin/Graphics/shaders/built-in/je_default.shader.h (renamed from src/libjin/Graphics/Shader/je_default.shader.h)0
-rw-r--r--src/libjin/Graphics/shaders/built-in/je_font.shader.h (renamed from src/libjin/Graphics/Shader/je_font.shader.h)0
-rw-r--r--src/libjin/Graphics/shaders/built-in/je_texture.shader.h (renamed from src/libjin/Graphics/Shader/je_texture.shader.h)0
-rw-r--r--src/libjin/Graphics/shaders/je_base.shader.h (renamed from src/libjin/Graphics/Shader/je_base.shader.h)9
-rw-r--r--src/libjin/Graphics/shaders/je_jsl_compiler.cpp57
-rw-r--r--src/libjin/Graphics/shaders/je_jsl_compiler.h45
-rw-r--r--src/libjin/Graphics/shaders/je_shader.cpp281
-rw-r--r--src/libjin/Graphics/shaders/je_shader.h201
-rw-r--r--src/libjin/Input/je_event.h6
-rw-r--r--src/libjin/Input/je_input.h4
-rw-r--r--src/libjin/Input/je_joypad.h6
-rw-r--r--src/libjin/Input/je_keyboard.h6
-rw-r--r--src/libjin/Input/je_mouse.h6
-rw-r--r--src/libjin/Math/je_bezier_curve.cpp (renamed from src/libjin/Graphics/animation/je_animation.cpp)0
-rw-r--r--src/libjin/Math/je_bezier_curve.h17
-rw-r--r--src/libjin/Math/je_constant.h4
-rw-r--r--src/libjin/Math/je_ellipse.cpp (renamed from src/libjin/Graphics/animation/je_clip.cpp)0
-rw-r--r--src/libjin/Math/je_ellipse.h (renamed from src/libjin/Graphics/particle/je_particle.cpp)0
-rw-r--r--src/libjin/Math/je_math.h12
-rw-r--r--src/libjin/Math/je_matrix.h6
-rw-r--r--src/libjin/Math/je_quad.h6
-rw-r--r--src/libjin/Math/je_random.cpp13
-rw-r--r--src/libjin/Math/je_random.h22
-rw-r--r--src/libjin/Math/je_vector2.hpp16
-rw-r--r--src/libjin/Math/je_vector3.hpp4
-rw-r--r--src/libjin/Math/je_vector4.hpp4
-rw-r--r--src/libjin/Net/je_net_manager.h6
-rw-r--r--src/libjin/Net/je_socket.h8
-rw-r--r--src/libjin/README.md4
-rw-r--r--src/libjin/Time/je_timer.cpp98
-rw-r--r--src/libjin/Time/je_timer.h88
-rw-r--r--src/libjin/Utils/je_log.cpp81
-rw-r--r--src/libjin/Utils/je_log.h106
-rw-r--r--src/libjin/Utils/je_macros.h4
-rw-r--r--src/libjin/Utils/je_utils.h4
-rw-r--r--src/libjin/ai/je_ai.h10
-rw-r--r--src/libjin/ai/je_behavior_tree.h45
-rw-r--r--src/libjin/ai/je_state_machine.cpp445
-rw-r--r--src/libjin/ai/je_state_machine.h401
-rw-r--r--src/libjin/core/je_configuration.h11
-rw-r--r--src/libjin/core/je_version.h6
-rw-r--r--src/libjin/jin.h11
-rw-r--r--src/libjin/threads/je_thread.cpp (renamed from src/libjin/multithread/je_thread.cpp)4
-rw-r--r--src/libjin/threads/je_thread.h (renamed from src/libjin/multithread/je_thread.h)10
-rw-r--r--src/lua/common/Proxy.h67
-rw-r--r--src/lua/common/Reference.hpp88
-rw-r--r--src/lua/common/common.h8
-rw-r--r--src/lua/common/constant.h1
-rw-r--r--src/lua/common/error.h28
-rw-r--r--src/lua/common/je_lua_callback.cpp43
-rw-r--r--src/lua/common/je_lua_callback.h67
-rw-r--r--src/lua/common/je_lua_common.h10
-rw-r--r--src/lua/common/je_lua_constant.h (renamed from src/libjin/Graphics/particle/je_particle_system.cpp)0
-rw-r--r--src/lua/common/je_lua_error.h28
-rw-r--r--src/lua/common/je_lua_function.cpp (renamed from src/libjin/Graphics/particle/je_particle_batch.cpp)0
-rw-r--r--src/lua/common/je_lua_function.h6
-rw-r--r--src/lua/common/je_lua_port.h8
-rw-r--r--src/lua/common/je_lua_proxy.h72
-rw-r--r--src/lua/common/je_lua_reference.cpp31
-rw-r--r--src/lua/common/je_lua_reference.h54
-rw-r--r--src/lua/common/je_lua_shared.hpp151
-rw-r--r--src/lua/embed/boot.lua.h175
-rw-r--r--src/lua/embed/embed.h46
-rw-r--r--src/lua/embed/graphics.lua.h46
-rw-r--r--src/lua/embed/scripts/ai.lua.h26
-rw-r--r--src/lua/embed/scripts/boot.lua.h139
-rw-r--r--src/lua/embed/scripts/graphics.lua.h73
-rw-r--r--src/lua/embed/scripts/keyboard.lua.h (renamed from src/lua/embed/keyboard.lua.h)2
-rw-r--r--src/lua/embed/scripts/mouse.lua.h (renamed from src/lua/embed/mouse.lua.h)2
-rw-r--r--src/lua/embed/scripts/net.lua.h (renamed from src/lua/embed/net.lua.h)3
-rw-r--r--src/lua/embed/scripts/path.lua.h (renamed from src/lua/embed/path.lua.h)2
-rw-r--r--src/lua/jin.cpp94
-rw-r--r--src/lua/jin.h5
-rw-r--r--src/lua/libraries/luax/luax.h26
-rw-r--r--src/lua/main.cpp44
-rw-r--r--src/lua/modules/ai/je_lua_ai.cpp13
-rw-r--r--src/lua/modules/ai/je_lua_ai.h7
-rw-r--r--src/lua/modules/ai/je_lua_behavior_tree.cpp11
-rw-r--r--src/lua/modules/ai/je_lua_behavior_tree.h14
-rw-r--r--src/lua/modules/ai/je_lua_state_machine.cpp25
-rw-r--r--src/lua/modules/ai/je_lua_state_machine.h14
-rw-r--r--src/lua/modules/audio/audio.cpp123
-rw-r--r--src/lua/modules/audio/je_lua_audio.cpp135
-rw-r--r--src/lua/modules/audio/je_lua_audio.h6
-rw-r--r--src/lua/modules/audio/je_lua_source.cpp117
-rw-r--r--src/lua/modules/audio/je_lua_source.h16
-rw-r--r--src/lua/modules/audio/source.cpp116
-rw-r--r--src/lua/modules/bit/je_lua_bit.cpp (renamed from src/lua/modules/bit/bit.cpp)41
-rw-r--r--src/lua/modules/bit/je_lua_bit.h (renamed from src/libjin/Graphics/particle/je_particle_system.h)0
-rw-r--r--src/lua/modules/core/core.cpp46
-rw-r--r--src/lua/modules/core/je_lua_core.cpp46
-rw-r--r--src/lua/modules/core/je_lua_core.h0
-rw-r--r--src/lua/modules/event/je_lua_event.cpp (renamed from src/lua/modules/event/event.cpp)26
-rw-r--r--src/lua/modules/event/je_lua_event.h0
-rw-r--r--src/lua/modules/filesystem/je_lua_filesystem.cpp (renamed from src/lua/modules/filesystem/filesystem.cpp)41
-rw-r--r--src/lua/modules/filesystem/je_lua_filesystem.h0
-rw-r--r--src/lua/modules/graphics/bitmap.cpp113
-rw-r--r--src/lua/modules/graphics/canvas.cpp65
-rw-r--r--src/lua/modules/graphics/je_lua_bitmap.cpp114
-rw-r--r--src/lua/modules/graphics/je_lua_bitmap.h16
-rw-r--r--src/lua/modules/graphics/je_lua_canvas.cpp66
-rw-r--r--src/lua/modules/graphics/je_lua_canvas.h16
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.cpp (renamed from src/lua/modules/graphics/graphics.cpp)561
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.h0
-rw-r--r--src/lua/modules/graphics/je_lua_page.cpp69
-rw-r--r--src/lua/modules/graphics/je_lua_page.h22
-rw-r--r--src/lua/modules/graphics/je_lua_particle_system.cpp11
-rw-r--r--src/lua/modules/graphics/je_lua_particle_system.h0
-rw-r--r--src/lua/modules/graphics/je_lua_shader.cpp137
-rw-r--r--src/lua/modules/graphics/je_lua_shader.h16
-rw-r--r--src/lua/modules/graphics/je_lua_sprite.cpp262
-rw-r--r--src/lua/modules/graphics/je_lua_sprite.h24
-rw-r--r--src/lua/modules/graphics/je_lua_spritesheet.cpp54
-rw-r--r--src/lua/modules/graphics/je_lua_spritesheet.h21
-rw-r--r--src/lua/modules/graphics/je_lua_text.cpp32
-rw-r--r--src/lua/modules/graphics/je_lua_text.h16
-rw-r--r--src/lua/modules/graphics/je_lua_texture.cpp66
-rw-r--r--src/lua/modules/graphics/je_lua_texture.h16
-rw-r--r--src/lua/modules/graphics/je_lua_texture_font.cpp66
-rw-r--r--src/lua/modules/graphics/je_lua_texture_font.h16
-rw-r--r--src/lua/modules/graphics/je_lua_ttf.cpp66
-rw-r--r--src/lua/modules/graphics/je_lua_ttf.h16
-rw-r--r--src/lua/modules/graphics/je_lua_ttf_data.cpp52
-rw-r--r--src/lua/modules/graphics/je_lua_ttf_data.h21
-rw-r--r--src/lua/modules/graphics/page.cpp73
-rw-r--r--src/lua/modules/graphics/shader.cpp135
-rw-r--r--src/lua/modules/graphics/text.cpp32
-rw-r--r--src/lua/modules/graphics/texture.cpp65
-rw-r--r--src/lua/modules/graphics/texture_font.cpp67
-rw-r--r--src/lua/modules/graphics/ttf.cpp73
-rw-r--r--src/lua/modules/graphics/ttfData.cpp51
-rw-r--r--src/lua/modules/joypad/je_lua_joypad.cpp (renamed from src/lua/modules/joypad/joypad.cpp)12
-rw-r--r--src/lua/modules/joypad/je_lua_joypad.h0
-rw-r--r--src/lua/modules/keyboard/je_lua_keyboard.cpp (renamed from src/lua/modules/keyboard/keyboard.cpp)3
-rw-r--r--src/lua/modules/keyboard/je_lua_keyboard.h0
-rw-r--r--src/lua/modules/math/je_lua_math.cpp (renamed from src/lua/modules/math/math.cpp)14
-rw-r--r--src/lua/modules/math/je_lua_math.h0
-rw-r--r--src/lua/modules/mouse/je_lua_mouse.cpp (renamed from src/lua/modules/mouse/mouse.cpp)22
-rw-r--r--src/lua/modules/mouse/je_lua_mouse.h0
-rw-r--r--src/lua/modules/net/Buffer.cpp142
-rw-r--r--src/lua/modules/net/je_lua_buffer.cpp137
-rw-r--r--src/lua/modules/net/je_lua_buffer.h (renamed from src/lua/modules/net/Buffer.h)7
-rw-r--r--src/lua/modules/net/je_lua_net.cpp (renamed from src/lua/modules/net/net.cpp)42
-rw-r--r--src/lua/modules/net/je_lua_net.h0
-rw-r--r--src/lua/modules/net/je_lua_socket.cpp129
-rw-r--r--src/lua/modules/net/je_lua_socket.h16
-rw-r--r--src/lua/modules/net/socket.cpp129
-rw-r--r--src/lua/modules/thread/Thread.cpp252
-rw-r--r--src/lua/modules/thread/Thread.h94
-rw-r--r--src/lua/modules/thread/je_lua_thread.cpp248
-rw-r--r--src/lua/modules/thread/je_lua_thread.h93
-rw-r--r--src/lua/modules/time/je_lua_time.cpp71
-rw-r--r--src/lua/modules/time/je_lua_time.h0
-rw-r--r--src/lua/modules/time/je_lua_timer.cpp146
-rw-r--r--src/lua/modules/time/je_lua_timer.h20
-rw-r--r--src/lua/modules/time/time.cpp38
-rw-r--r--src/lua/modules/types.h25
-rw-r--r--src/lua/resources/font.ttfbin84564 -> 0 bytes
-rw-r--r--src/lua/resources/font.ttf.h714
1397 files changed, 450582 insertions, 7519 deletions
diff --git a/src/libjin/3rdparty/GLee/GLee.c b/src/3rdparty/GLee/GLee.c
index 0f32273..0f32273 100644
--- a/src/libjin/3rdparty/GLee/GLee.c
+++ b/src/3rdparty/GLee/GLee.c
diff --git a/src/libjin/3rdparty/GLee/GLee.h b/src/3rdparty/GLee/GLee.h
index 1e9a297..1e9a297 100644
--- a/src/libjin/3rdparty/GLee/GLee.h
+++ b/src/3rdparty/GLee/GLee.h
diff --git a/src/3rdparty/LuaJIT-2.0.5/.gitignore b/src/3rdparty/LuaJIT-2.0.5/.gitignore
new file mode 100644
index 0000000..1a8e376
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/.gitignore
@@ -0,0 +1,9 @@
+*.[oa]
+*.so
+*.obj
+*.exp
+*.exe
+*.manifest
+*.dmp
+*.swp
+.tags
diff --git a/src/3rdparty/LuaJIT-2.0.5/COPYRIGHT b/src/3rdparty/LuaJIT-2.0.5/COPYRIGHT
new file mode 100644
index 0000000..6ed4002
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/COPYRIGHT
@@ -0,0 +1,56 @@
+===============================================================================
+LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/
+
+Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+[ MIT license: http://www.opensource.org/licenses/mit-license.php ]
+
+===============================================================================
+[ LuaJIT includes code from Lua 5.1/5.2, which has this license statement: ]
+
+Copyright (C) 1994-2012 Lua.org, PUC-Rio.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+===============================================================================
+[ LuaJIT includes code from dlmalloc, which has this license statement: ]
+
+This is a version (aka dlmalloc) of malloc/free/realloc written by
+Doug Lea and released to the public domain, as explained at
+http://creativecommons.org/licenses/publicdomain
+
+===============================================================================
diff --git a/src/3rdparty/LuaJIT-2.0.5/Makefile b/src/3rdparty/LuaJIT-2.0.5/Makefile
new file mode 100644
index 0000000..ecce9ec
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/Makefile
@@ -0,0 +1,157 @@
+##############################################################################
+# LuaJIT top level Makefile for installation. Requires GNU Make.
+#
+# Please read doc/install.html before changing any variables!
+#
+# Suitable for POSIX platforms (Linux, *BSD, OSX etc.).
+# Note: src/Makefile has many more configurable options.
+#
+# ##### This Makefile is NOT useful for Windows! #####
+# For MSVC, please follow the instructions given in src/msvcbuild.bat.
+# For MinGW and Cygwin, cd to src and run make with the Makefile there.
+#
+# Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+##############################################################################
+
+MAJVER= 2
+MINVER= 0
+RELVER= 5
+VERSION= $(MAJVER).$(MINVER).$(RELVER)
+ABIVER= 5.1
+
+##############################################################################
+#
+# Change the installation path as needed. This automatically adjusts
+# the paths in src/luaconf.h, too. Note: PREFIX must be an absolute path!
+#
+export PREFIX= /usr/local
+export MULTILIB= lib
+##############################################################################
+
+DPREFIX= $(DESTDIR)$(PREFIX)
+INSTALL_BIN= $(DPREFIX)/bin
+INSTALL_LIB= $(DPREFIX)/$(MULTILIB)
+INSTALL_SHARE= $(DPREFIX)/share
+INSTALL_INC= $(DPREFIX)/include/luajit-$(MAJVER).$(MINVER)
+
+INSTALL_LJLIBD= $(INSTALL_SHARE)/luajit-$(VERSION)
+INSTALL_JITLIB= $(INSTALL_LJLIBD)/jit
+INSTALL_LMODD= $(INSTALL_SHARE)/lua
+INSTALL_LMOD= $(INSTALL_LMODD)/$(ABIVER)
+INSTALL_CMODD= $(INSTALL_LIB)/lua
+INSTALL_CMOD= $(INSTALL_CMODD)/$(ABIVER)
+INSTALL_MAN= $(INSTALL_SHARE)/man/man1
+INSTALL_PKGCONFIG= $(INSTALL_LIB)/pkgconfig
+
+INSTALL_TNAME= luajit-$(VERSION)
+INSTALL_TSYMNAME= luajit
+INSTALL_ANAME= libluajit-$(ABIVER).a
+INSTALL_SOSHORT1= libluajit-$(ABIVER).so
+INSTALL_SOSHORT2= libluajit-$(ABIVER).so.$(MAJVER)
+INSTALL_SONAME= $(INSTALL_SOSHORT2).$(MINVER).$(RELVER)
+INSTALL_DYLIBSHORT1= libluajit-$(ABIVER).dylib
+INSTALL_DYLIBSHORT2= libluajit-$(ABIVER).$(MAJVER).dylib
+INSTALL_DYLIBNAME= libluajit-$(ABIVER).$(MAJVER).$(MINVER).$(RELVER).dylib
+INSTALL_PCNAME= luajit.pc
+
+INSTALL_STATIC= $(INSTALL_LIB)/$(INSTALL_ANAME)
+INSTALL_DYN= $(INSTALL_LIB)/$(INSTALL_SONAME)
+INSTALL_SHORT1= $(INSTALL_LIB)/$(INSTALL_SOSHORT1)
+INSTALL_SHORT2= $(INSTALL_LIB)/$(INSTALL_SOSHORT2)
+INSTALL_T= $(INSTALL_BIN)/$(INSTALL_TNAME)
+INSTALL_TSYM= $(INSTALL_BIN)/$(INSTALL_TSYMNAME)
+INSTALL_PC= $(INSTALL_PKGCONFIG)/$(INSTALL_PCNAME)
+
+INSTALL_DIRS= $(INSTALL_BIN) $(INSTALL_LIB) $(INSTALL_INC) $(INSTALL_MAN) \
+ $(INSTALL_PKGCONFIG) $(INSTALL_JITLIB) $(INSTALL_LMOD) $(INSTALL_CMOD)
+UNINSTALL_DIRS= $(INSTALL_JITLIB) $(INSTALL_LJLIBD) $(INSTALL_INC) \
+ $(INSTALL_LMOD) $(INSTALL_LMODD) $(INSTALL_CMOD) $(INSTALL_CMODD)
+
+RM= rm -f
+MKDIR= mkdir -p
+RMDIR= rmdir 2>/dev/null
+SYMLINK= ln -sf
+INSTALL_X= install -m 0755
+INSTALL_F= install -m 0644
+UNINSTALL= $(RM)
+LDCONFIG= ldconfig -n
+SED_PC= sed -e "s|^prefix=.*|prefix=$(PREFIX)|" \
+ -e "s|^multilib=.*|multilib=$(MULTILIB)|"
+
+FILE_T= luajit
+FILE_A= libluajit.a
+FILE_SO= libluajit.so
+FILE_MAN= luajit.1
+FILE_PC= luajit.pc
+FILES_INC= lua.h lualib.h lauxlib.h luaconf.h lua.hpp luajit.h
+FILES_JITLIB= bc.lua v.lua dump.lua dis_x86.lua dis_x64.lua dis_arm.lua \
+ dis_ppc.lua dis_mips.lua dis_mipsel.lua bcsave.lua vmdef.lua
+
+ifeq (,$(findstring Windows,$(OS)))
+ HOST_SYS:= $(shell uname -s)
+else
+ HOST_SYS= Windows
+endif
+TARGET_SYS?= $(HOST_SYS)
+
+ifeq (Darwin,$(TARGET_SYS))
+ INSTALL_SONAME= $(INSTALL_DYLIBNAME)
+ INSTALL_SOSHORT1= $(INSTALL_DYLIBSHORT1)
+ INSTALL_SOSHORT2= $(INSTALL_DYLIBSHORT2)
+ LDCONFIG= :
+endif
+
+##############################################################################
+
+INSTALL_DEP= src/luajit
+
+default all $(INSTALL_DEP):
+ @echo "==== Building LuaJIT $(VERSION) ===="
+ $(MAKE) -C src
+ @echo "==== Successfully built LuaJIT $(VERSION) ===="
+
+install: $(INSTALL_DEP)
+ @echo "==== Installing LuaJIT $(VERSION) to $(PREFIX) ===="
+ $(MKDIR) $(INSTALL_DIRS)
+ cd src && $(INSTALL_X) $(FILE_T) $(INSTALL_T)
+ cd src && test -f $(FILE_A) && $(INSTALL_F) $(FILE_A) $(INSTALL_STATIC) || :
+ $(RM) $(INSTALL_TSYM) $(INSTALL_DYN) $(INSTALL_SHORT1) $(INSTALL_SHORT2)
+ cd src && test -f $(FILE_SO) && \
+ $(INSTALL_X) $(FILE_SO) $(INSTALL_DYN) && \
+ $(LDCONFIG) $(INSTALL_LIB) && \
+ $(SYMLINK) $(INSTALL_SONAME) $(INSTALL_SHORT1) && \
+ $(SYMLINK) $(INSTALL_SONAME) $(INSTALL_SHORT2) || :
+ cd etc && $(INSTALL_F) $(FILE_MAN) $(INSTALL_MAN)
+ cd etc && $(SED_PC) $(FILE_PC) > $(FILE_PC).tmp && \
+ $(INSTALL_F) $(FILE_PC).tmp $(INSTALL_PC) && \
+ $(RM) $(FILE_PC).tmp
+ cd src && $(INSTALL_F) $(FILES_INC) $(INSTALL_INC)
+ cd src/jit && $(INSTALL_F) $(FILES_JITLIB) $(INSTALL_JITLIB)
+ $(SYMLINK) $(INSTALL_TNAME) $(INSTALL_TSYM)
+ @echo "==== Successfully installed LuaJIT $(VERSION) to $(PREFIX) ===="
+
+uninstall:
+ @echo "==== Uninstalling LuaJIT $(VERSION) from $(PREFIX) ===="
+ $(UNINSTALL) $(INSTALL_TSYM) $(INSTALL_T) $(INSTALL_STATIC) $(INSTALL_DYN) $(INSTALL_SHORT1) $(INSTALL_SHORT2) $(INSTALL_MAN)/$(FILE_MAN) $(INSTALL_PC)
+ for file in $(FILES_JITLIB); do \
+ $(UNINSTALL) $(INSTALL_JITLIB)/$$file; \
+ done
+ for file in $(FILES_INC); do \
+ $(UNINSTALL) $(INSTALL_INC)/$$file; \
+ done
+ $(LDCONFIG) $(INSTALL_LIB)
+ $(RMDIR) $(UNINSTALL_DIRS) || :
+ @echo "==== Successfully uninstalled LuaJIT $(VERSION) from $(PREFIX) ===="
+
+##############################################################################
+
+amalg:
+ @echo "Building LuaJIT $(VERSION)"
+ $(MAKE) -C src amalg
+
+clean:
+ $(MAKE) -C src clean
+
+.PHONY: all install amalg clean
+
+##############################################################################
diff --git a/src/3rdparty/LuaJIT-2.0.5/README b/src/3rdparty/LuaJIT-2.0.5/README
new file mode 100644
index 0000000..6cb7ceb
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/README
@@ -0,0 +1,16 @@
+README for LuaJIT 2.0.5
+-----------------------
+
+LuaJIT is a Just-In-Time (JIT) compiler for the Lua programming language.
+
+Project Homepage: http://luajit.org/
+
+LuaJIT is Copyright (C) 2005-2017 Mike Pall.
+LuaJIT is free software, released under the MIT license.
+See full Copyright Notice in the COPYRIGHT file or in luajit.h.
+
+Documentation for LuaJIT is available in HTML format.
+Please point your favorite browser to:
+
+ doc/luajit.html
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/doc/bluequad-print.css b/src/3rdparty/LuaJIT-2.0.5/doc/bluequad-print.css
new file mode 100644
index 0000000..d5a3ea3
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/doc/bluequad-print.css
@@ -0,0 +1,166 @@
+/* Copyright (C) 2004-2018 Mike Pall.
+ *
+ * You are welcome to use the general ideas of this design for your own sites.
+ * But please do not steal the stylesheet, the layout or the color scheme.
+ */
+body {
+ font-family: serif;
+ font-size: 11pt;
+ margin: 0 3em;
+ padding: 0;
+ border: none;
+}
+a:link, a:visited, a:hover, a:active {
+ text-decoration: none;
+ background: transparent;
+ color: #0000ff;
+}
+h1, h2, h3 {
+ font-family: sans-serif;
+ font-weight: bold;
+ text-align: left;
+ margin: 0.5em 0;
+ padding: 0;
+}
+h1 {
+ font-size: 200%;
+}
+h2 {
+ font-size: 150%;
+}
+h3 {
+ font-size: 125%;
+}
+p {
+ margin: 0 0 0.5em 0;
+ padding: 0;
+}
+ul, ol {
+ margin: 0.5em 0;
+ padding: 0 0 0 2em;
+}
+ul {
+ list-style: outside square;
+}
+ol {
+ list-style: outside decimal;
+}
+li {
+ margin: 0;
+ padding: 0;
+}
+dl {
+ margin: 1em 0;
+ padding: 1em;
+ border: 1px solid black;
+}
+dt {
+ font-weight: bold;
+ margin: 0;
+ padding: 0;
+}
+dt sup {
+ float: right;
+ margin-left: 1em;
+}
+dd {
+ margin: 0.5em 0 0 2em;
+ padding: 0;
+}
+table {
+ table-layout: fixed;
+ width: 100%;
+ margin: 1em 0;
+ padding: 0;
+ border: 1px solid black;
+ border-spacing: 0;
+ border-collapse: collapse;
+}
+tr {
+ margin: 0;
+ padding: 0;
+ border: none;
+}
+td {
+ text-align: left;
+ margin: 0;
+ padding: 0.2em 0.5em;
+ border-top: 1px solid black;
+ border-bottom: 1px solid black;
+}
+tr.separate td {
+ border-top: double;
+}
+tt, pre, code, kbd, samp {
+ font-family: monospace;
+ font-size: 75%;
+}
+kbd {
+ font-weight: bolder;
+}
+blockquote, pre {
+ margin: 1em 2em;
+ padding: 0;
+}
+img {
+ border: none;
+ vertical-align: baseline;
+ margin: 0;
+ padding: 0;
+}
+img.left {
+ float: left;
+ margin: 0.5em 1em 0.5em 0;
+}
+img.right {
+ float: right;
+ margin: 0.5em 0 0.5em 1em;
+}
+.flush {
+ clear: both;
+ visibility: hidden;
+}
+.hide, .noprint, #nav {
+ display: none !important;
+}
+.pagebreak {
+ page-break-before: always;
+}
+#site {
+ text-align: right;
+ font-family: sans-serif;
+ font-weight: bold;
+ margin: 0 1em;
+ border-bottom: 1pt solid black;
+}
+#site a {
+ font-size: 1.2em;
+}
+#site a:link, #site a:visited {
+ text-decoration: none;
+ font-weight: bold;
+ background: transparent;
+ color: #ffffff;
+}
+#logo {
+ color: #ff8000;
+}
+#head {
+ clear: both;
+ margin: 0 1em;
+}
+#main {
+ line-height: 1.3;
+ text-align: justify;
+ margin: 1em;
+}
+#foot {
+ clear: both;
+ font-size: 80%;
+ text-align: center;
+ margin: 0 1.25em;
+ padding: 0.5em 0 0 0;
+ border-top: 1pt solid black;
+ page-break-before: avoid;
+ page-break-after: avoid;
+}
diff --git a/src/3rdparty/LuaJIT-2.0.5/doc/bluequad.css b/src/3rdparty/LuaJIT-2.0.5/doc/bluequad.css
new file mode 100644
index 0000000..cfc889a
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/doc/bluequad.css
@@ -0,0 +1,325 @@
+/* Copyright (C) 2004-2018 Mike Pall.
+ *
+ * You are welcome to use the general ideas of this design for your own sites.
+ * But please do not steal the stylesheet, the layout or the color scheme.
+ */
+/* colorscheme:
+ *
+ * site | head #4162bf/white | #6078bf/#e6ecff
+ * ------+------ ----------------+-------------------
+ * nav | main #bfcfff | #e6ecff/black
+ *
+ * nav: hiback loback #c5d5ff #b9c9f9
+ * hiborder loborder #e6ecff #97a7d7
+ * link hover #2142bf #ff0000
+ *
+ * link: link visited hover #2142bf #8122bf #ff0000
+ *
+ * main: boxback boxborder #f0f4ff #bfcfff
+ */
+body {
+ font-family: Verdana, Arial, Helvetica, sans-serif;
+ font-size: 10pt;
+ margin: 0;
+ padding: 0;
+ border: none;
+ background: #e0e0e0;
+ color: #000000;
+}
+a:link {
+ text-decoration: none;
+ background: transparent;
+ color: #2142bf;
+}
+a:visited {
+ text-decoration: none;
+ background: transparent;
+ color: #8122bf;
+}
+a:hover, a:active {
+ text-decoration: underline;
+ background: transparent;
+ color: #ff0000;
+}
+h1, h2, h3 {
+ font-weight: bold;
+ text-align: left;
+ margin: 0.5em 0;
+ padding: 0;
+ background: transparent;
+}
+h1 {
+ font-size: 200%;
+ line-height: 3em; /* really 6em relative to body, match #site span */
+ margin: 0;
+}
+h2 {
+ font-size: 150%;
+ color: #606060;
+}
+h3 {
+ font-size: 125%;
+ color: #404040;
+}
+p {
+ max-width: 600px;
+ margin: 0 0 0.5em 0;
+ padding: 0;
+}
+b {
+ color: #404040;
+}
+ul, ol {
+ max-width: 600px;
+ margin: 0.5em 0;
+ padding: 0 0 0 2em;
+}
+ul {
+ list-style: outside square;
+}
+ol {
+ list-style: outside decimal;
+}
+li {
+ margin: 0;
+ padding: 0;
+}
+dl {
+ max-width: 600px;
+ margin: 1em 0;
+ padding: 1em;
+ border: 1px solid #bfcfff;
+ background: #f0f4ff;
+}
+dt {
+ font-weight: bold;
+ margin: 0;
+ padding: 0;
+}
+dt sup {
+ float: right;
+ margin-left: 1em;
+ color: #808080;
+}
+dt a:visited {
+ text-decoration: none;
+ color: #2142bf;
+}
+dt a:hover, dt a:active {
+ text-decoration: none;
+ color: #ff0000;
+}
+dd {
+ margin: 0.5em 0 0 2em;
+ padding: 0;
+}
+div.tablewrap { /* for IE *sigh* */
+ max-width: 600px;
+}
+table {
+ table-layout: fixed;
+ border-spacing: 0;
+ border-collapse: collapse;
+ max-width: 600px;
+ width: 100%;
+ margin: 1em 0;
+ padding: 0;
+ border: 1px solid #bfcfff;
+}
+tr {
+ margin: 0;
+ padding: 0;
+ border: none;
+}
+tr.odd {
+ background: #f0f4ff;
+}
+tr.separate td {
+ border-top: 1px solid #bfcfff;
+}
+td {
+ text-align: left;
+ margin: 0;
+ padding: 0.2em 0.5em;
+ border: none;
+}
+tt, code, kbd, samp {
+ font-family: Courier New, Courier, monospace;
+ line-height: 1.2;
+ font-size: 110%;
+}
+kbd {
+ font-weight: bolder;
+}
+blockquote, pre {
+ max-width: 600px;
+ margin: 1em 2em;
+ padding: 0;
+}
+pre {
+ line-height: 1.1;
+}
+pre.code {
+ line-height: 1.4;
+ margin: 0.5em 0 1em 0.5em;
+ padding: 0.5em 1em;
+ border: 1px solid #bfcfff;
+ background: #f0f4ff;
+}
+pre.mark {
+ padding-left: 2em;
+}
+span.codemark {
+ position:absolute;
+ left: 16em;
+ color: #4040c0;
+}
+span.mark {
+ color: #4040c0;
+ font-family: Courier New, Courier, monospace;
+ line-height: 1.1;
+}
+img {
+ border: none;
+ vertical-align: baseline;
+ margin: 0;
+ padding: 0;
+}
+img.left {
+ float: left;
+ margin: 0.5em 1em 0.5em 0;
+}
+img.right {
+ float: right;
+ margin: 0.5em 0 0.5em 1em;
+}
+.indent {
+ padding-left: 1em;
+}
+.flush {
+ clear: both;
+ visibility: hidden;
+}
+.hide, .noscreen {
+ display: none !important;
+}
+.ext {
+ color: #ff8000;
+}
+.new {
+ font-size: 6pt;
+ vertical-align: middle;
+ background: #ff8000;
+ color: #ffffff;
+}
+#site {
+ clear: both;
+ float: left;
+ width: 13em;
+ text-align: center;
+ font-weight: bold;
+ margin: 0;
+ padding: 0;
+ background: transparent;
+ color: #ffffff;
+}
+#site a {
+ font-size: 200%;
+}
+#site a:link, #site a:visited {
+ text-decoration: none;
+ font-weight: bold;
+ background: transparent;
+ color: #ffffff;
+}
+#site span {
+ line-height: 3em; /* really 6em relative to body, match h1 */
+}
+#logo {
+ color: #ffb380;
+}
+#head {
+ margin: 0;
+ padding: 0 0 0 2em;
+ border-left: solid 13em #4162bf;
+ border-right: solid 3em #6078bf;
+ background: #6078bf;
+ color: #e6ecff;
+}
+#nav {
+ clear: both;
+ float: left;
+ overflow: hidden;
+ text-align: left;
+ line-height: 1.5;
+ width: 13em;
+ padding-top: 1em;
+ background: transparent;
+}
+#nav ul {
+ list-style: none outside;
+ margin: 0;
+ padding: 0;
+}
+#nav li {
+ margin: 0;
+ padding: 0;
+}
+#nav a {
+ display: block;
+ text-decoration: none;
+ font-weight: bold;
+ margin: 0;
+ padding: 2px 1em;
+ border-top: 1px solid transparent;
+ border-bottom: 1px solid transparent;
+ background: transparent;
+ color: #2142bf;
+}
+#nav a:hover, #nav a:active {
+ text-decoration: none;
+ border-top: 1px solid #97a7d7;
+ border-bottom: 1px solid #e6ecff;
+ background: #b9c9f9;
+ color: #ff0000;
+}
+#nav a.current, #nav a.current:hover, #nav a.current:active {
+ border-top: 1px solid #e6ecff;
+ border-bottom: 1px solid #97a7d7;
+ background: #c5d5ff;
+ color: #2142bf;
+}
+#nav ul ul a {
+ padding: 0 1em 0 1.7em;
+}
+#nav ul ul ul a {
+ padding: 0 0.5em 0 2.4em;
+}
+#main {
+ line-height: 1.5;
+ text-align: left;
+ margin: 0;
+ padding: 1em 2em;
+ border-left: solid 13em #bfcfff;
+ border-right: solid 3em #e6ecff;
+ background: #e6ecff;
+}
+#foot {
+ clear: both;
+ font-size: 80%;
+ text-align: center;
+ margin: 0;
+ padding: 0.5em;
+ background: #6078bf;
+ color: #ffffff;
+}
+#foot a:link, #foot a:visited {
+ text-decoration: underline;
+ background: transparent;
+ color: #ffffff;
+}
+#foot a:hover, #foot a:active {
+ text-decoration: underline;
+ background: transparent;
+ color: #bfcfff;
+}
diff --git a/src/3rdparty/LuaJIT-2.0.5/doc/changes.html b/src/3rdparty/LuaJIT-2.0.5/doc/changes.html
new file mode 100644
index 0000000..c1848e8
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/doc/changes.html
@@ -0,0 +1,1019 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<title>LuaJIT Change History</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<meta name="Copyright" content="Copyright (C) 2005-2018">
+<meta name="Language" content="en">
+<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
+<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
+<style type="text/css">
+div.major { max-width: 600px; padding: 1em; margin: 1em 0 1em 0; }
+</style>
+</head>
+<body>
+<div id="site">
+<a href="http://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
+</div>
+<div id="head">
+<h1>LuaJIT Change History</h1>
+</div>
+<div id="nav">
+<ul><li>
+<a href="luajit.html">LuaJIT</a>
+<ul><li>
+<a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="install.html">Installation</a>
+</li><li>
+<a href="running.html">Running</a>
+</li></ul>
+</li><li>
+<a href="extensions.html">Extensions</a>
+<ul><li>
+<a href="ext_ffi.html">FFI Library</a>
+<ul><li>
+<a href="ext_ffi_tutorial.html">FFI Tutorial</a>
+</li><li>
+<a href="ext_ffi_api.html">ffi.* API</a>
+</li><li>
+<a href="ext_ffi_semantics.html">FFI Semantics</a>
+</li></ul>
+</li><li>
+<a href="ext_jit.html">jit.* Library</a>
+</li><li>
+<a href="ext_c_api.html">Lua/C API</a>
+</li></ul>
+</li><li>
+<a href="status.html">Status</a>
+<ul><li>
+<a class="current" href="changes.html">Changes</a>
+</li></ul>
+</li><li>
+<a href="faq.html">FAQ</a>
+</li><li>
+<a href="http://luajit.org/performance.html">Performance <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
+</li></ul>
+</div>
+<div id="main">
+<p>
+This is a list of changes between the released versions of LuaJIT.<br>
+The current <span style="color: #0000c0;">stable version</span> is <strong>LuaJIT&nbsp;2.0.5</strong>.<br>
+</p>
+<p>
+Please check the
+<a href="http://luajit.org/changes.html"><span class="ext">&raquo;</span>&nbsp;Online Change History</a>
+to see whether newer versions are available.
+</p>
+
+<div class="major" style="background: #d0d0ff;">
+<h2 id="LuaJIT-2.0.5">LuaJIT 2.0.5 &mdash; 2017-05-01</h2>
+<ul>
+<li>Add workaround for MSVC 2015 stdio changes.</li>
+<li>Limit mcode alloc probing, depending on the available pool size.</li>
+<li>Fix overly restrictive range calculation in mcode allocation.</li>
+<li>Fix out-of-scope goto handling in parser.</li>
+<li>Remove internal <tt>__mode = "K"</tt> and replace with safe check.</li>
+<li>Add "proto" field to <tt>jit.util.funcinfo()</tt>.</li>
+<li>Fix GC step size calculation.</li>
+<li>Initialize <tt>uv->immutable</tt> for upvalues of loaded chunks.</li>
+<li>Fix for cdata vs. non-cdata arithmetics/comparisons.</li>
+<li>Drop leftover regs in 'for' iterator assignment, too.</li>
+<li>Fix PHI remarking in SINK pass.</li>
+<li>Don't try to record outermost <tt>pcall()</tt> return to lower frame.</li>
+<li>Add guard for obscure aliasing between open upvalues and SSA slots.</li>
+<li>Remove assumption that <tt>lj_math_random_step()</tt> doesn't clobber FPRs.</li>
+<li>Fix handling of non-numeric strings in arithmetic coercions.</li>
+<li>Fix recording of <tt>select(n, ...)</tt> with off-trace varargs</li>
+<li>Fix install for cross-builds.</li>
+<li>Don't allocate unused 2nd result register in JIT compiler backend.</li>
+<li>Drop marks from replayed instructions when sinking.</li>
+<li>Fix unsinking check.</li>
+<li>Properly handle OOM in <tt>trace_save()</tt>.</li>
+<li>Limit number of arguments given to <tt>io.lines()</tt> and <tt>fp:lines()</tt>.</li>
+<li>Fix narrowing of <tt>TOBIT</tt>.</li>
+<li>OSX: Fix build with recent XCode.</li>
+<li>x86/x64: Don't spill an explicit <tt>REF_BASE</tt> in the IR.</li>
+<li>x86/x64: Fix instruction length decoder.</li>
+<li>x86/x64: Search for exit jumps with instruction length decoder.</li>
+<li>ARM: Fix <tt>BLX</tt> encoding for Thumb interworking calls.</li>
+<li>MIPS: Don't use <tt>RID_GP</tt> as a scratch register.</li>
+<li>MIPS: Fix emitted code for U32 to float conversion.</li>
+<li>MIPS: Backport workaround for compact unwind tables.</li>
+<li>MIPS: Fix cross-endian jit.bcsave.</li>
+<li>MIPS: Fix <tt>BC_ISNEXT</tt> fallback path.</li>
+<li>MIPS: Fix use of ffgccheck delay slots in interpreter.</li>
+<li>FFI: Fix FOLD rules for <tt>int64_t</tt> comparisons.</li>
+<li>FFI: Fix SPLIT pass for <tt>CONV i64.u64</tt>.</li>
+<li>FFI: Fix <tt>ipairs()</tt> recording.</li>
+<li>FFI: Don't propagate qualifiers into subtypes of complex.</li>
+</ul>
+
+<h2 id="LuaJIT-2.0.4">LuaJIT 2.0.4 &mdash; 2015-05-14</h2>
+<ul>
+<li>Fix stack check in narrowing optimization.</li>
+<li>Fix Lua/C API typecheck error for special indexes.</li>
+<li>Fix string to number conversion.</li>
+<li>Fix lexer error for chunks without tokens.</li>
+<li>Don't compile <tt>IR_RETF</tt> after <tt>CALLT</tt> to ff with-side effects.</li>
+<li>Fix <tt>BC_UCLO</tt>/<tt>BC_JMP</tt> join optimization in Lua parser.</li>
+<li>Fix corner case in string to number conversion.</li>
+<li>Gracefully handle <tt>lua_error()</tt> for a suspended coroutine.</li>
+<li>Avoid error messages when building with Clang.</li>
+<li>Fix snapshot #0 handling for traces with a stack check on entry.</li>
+<li>Fix fused constant loads under high register pressure.</li>
+<li>Invalidate backpropagation cache after DCE.</li>
+<li>Fix ABC elimination.</li>
+<li>Fix debug info for main chunk of stripped bytecode.</li>
+<li>Fix FOLD rule for <tt>string.sub(s, ...) == k</tt>.</li>
+<li>Fix FOLD rule for <tt>STRREF</tt> of <tt>SNEW</tt>.</li>
+<li>Fix frame traversal while searching for error function.</li>
+<li>Prevent GC estimate miscalculation due to buffer growth.</li>
+<li>Prevent adding side traces for stack checks.</li>
+<li>Fix top slot calculation for snapshots with continuations.</li>
+<li>Fix check for reuse of SCEV results in <tt>FORL</tt>.</li>
+<li>Add PS Vita port.</li>
+<li>Fix compatibility issues with Illumos.</li>
+<li>Fix DragonFly build (unsupported).</li>
+<li>OpenBSD/x86: Better executable memory allocation for W^X mode.</li>
+<li>x86: Fix argument checks for <tt>ipairs()</tt> iterator.</li>
+<li>x86: <tt>lj_math_random_step()</tt> clobbers XMM regs on OSX Clang.</li>
+<li>x86: Fix code generation for unused result of <tt>math.random()</tt>.</li>
+<li>x64: Allow building with <tt>LUAJIT_USE_SYSMALLOC</tt> and <tt>LUAJIT_USE_VALGRIND</tt>.</li>
+<li>x86/x64: Fix argument check for bit shifts.</li>
+<li>x86/x64: Fix code generation for fused test/arith ops.</li>
+<li>ARM: Fix write barrier check in <tt>BC_USETS</tt>.</li>
+<li>PPC: Fix red zone overflow in machine code generation.</li>
+<li>PPC: Don't use <tt>mcrxr</tt> on PPE.</li>
+<li>Various archs: Fix excess stack growth in interpreter.</li>
+<li>FFI: Fix FOLD rule for <tt>TOBIT</tt> + <tt>CONV num.u32</tt>.</li>
+<li>FFI: Prevent DSE across <tt>ffi.string()</tt>.</li>
+<li>FFI: No meta fallback when indexing pointer to incomplete struct.</li>
+<li>FFI: Fix initialization of unions of subtypes.</li>
+<li>FFI: Fix cdata vs. non-cdata arithmetic and comparisons.</li>
+<li>FFI: Fix <tt>__index</tt>/<tt>__newindex</tt> metamethod resolution for ctypes.</li>
+<li>FFI: Fix compilation of reference field access.</li>
+<li>FFI: Fix frame traversal for backtraces with FFI callbacks.</li>
+<li>FFI: Fix recording of indexing a struct pointer ctype object itself.</li>
+<li>FFI: Allow non-scalar cdata to be compared for equality by address.</li>
+<li>FFI: Fix pseudo type conversions for type punning.</li>
+</ul>
+
+<h2 id="LuaJIT-2.0.3">LuaJIT 2.0.3 &mdash; 2014-03-12</h2>
+<ul>
+<li>Add PS4 port.</li>
+<li>Add support for multilib distro builds.</li>
+<li>Fix OSX build.</li>
+<li>Fix MinGW build.</li>
+<li>Fix Xbox 360 build.</li>
+<li>Improve ULOAD forwarding for open upvalues.</li>
+<li>Fix GC steps threshold handling when called by JIT-compiled code.</li>
+<li>Fix argument checks for <tt>math.deg()</tt> and <tt>math.rad()</tt>.</li>
+<li>Fix <tt>jit.flush(func|true)</tt>.</li>
+<li>Respect <tt>jit.off(func)</tt> when returning to a function, too.</li>
+<li>Fix compilation of <tt>string.byte(s, nil, n)</tt>.</li>
+<li>Fix line number for relocated bytecode after closure fixup</li>
+<li>Fix frame traversal for backtraces.</li>
+<li>Fix ABC elimination.</li>
+<li>Fix handling of redundant PHIs.</li>
+<li>Fix snapshot restore for exit to function header.</li>
+<li>Fix type punning alias analysis for constified pointers</li>
+<li>Fix call unroll checks in the presence of metamethod frames.</li>
+<li>Fix initial maxslot for down-recursive traces.</li>
+<li>Prevent BASE register coalescing if parent uses <tt>IR_RETF</tt>.</li>
+<li>Don't purge modified function from stack slots in <tt>BC_RET</tt>.</li>
+<li>Fix recording of <tt>BC_VARG</tt>.</li>
+<li>Don't access dangling reference to reallocated IR.</li>
+<li>Fix frame depth display for bytecode dump in <tt>-jdump</tt>.</li>
+<li>ARM: Fix register allocation when rematerializing FPRs.</li>
+<li>x64: Fix store to upvalue for lightuserdata values.</li>
+<li>FFI: Add missing GC steps for callback argument conversions.</li>
+<li>FFI: Properly unload loaded DLLs.</li>
+<li>FFI: Fix argument checks for <tt>ffi.string()</tt>.</li>
+<li>FFI/x64: Fix passing of vector arguments to calls.</li>
+<li>FFI: Rehash finalizer table after GC cycle, if needed.</li>
+<li>FFI: Fix <tt>cts-&gt;L</tt> for cdata unsinking in snapshot restore.</li>
+</ul>
+
+<h2 id="LuaJIT-2.0.2">LuaJIT 2.0.2 &mdash; 2013-06-03</h2>
+<ul>
+<li>Fix memory access check for fast string interning.</li>
+<li>Fix MSVC intrinsics for older versions.</li>
+<li>Add missing GC steps for <tt>io.*</tt> functions.</li>
+<li>Fix spurious red zone overflows in machine code generation.</li>
+<li>Fix jump-range constrained mcode allocation.</li>
+<li>Inhibit DSE for implicit loads via calls.</li>
+<li>Fix builtin string to number conversion for overflow digits.</li>
+<li>Fix optional argument handling while recording builtins.</li>
+<li>Fix optional argument handling in <tt>table.concat()</tt>.</li>
+<li>Add partial support for building with MingW64 GCC 4.8-SEH.</li>
+<li>Add missing PHI barrier to <tt>string.sub(str, a, b) == kstr</tt> FOLD rule.</li>
+<li>Fix compatibility issues with Illumos.</li>
+<li>ARM: Fix cache flush/sync for exit stubs of JIT-compiled code.</li>
+<li>MIPS: Fix cache flush/sync for JIT-compiled code jump area.</li>
+<li>PPC: Add <tt>plt</tt> suffix for external calls from assembler code.</li>
+<li>FFI: Fix snapshot substitution in SPLIT pass.</li>
+<li>FFI/x86: Fix register allocation for 64 bit comparisons.</li>
+<li>FFI: Fix tailcall in lowest frame to C&nbsp;function with bool result.</li>
+<li>FFI: Ignore <tt>long</tt> type specifier in <tt>ffi.istype()</tt>.</li>
+<li>FFI: Fix calling conventions for 32 bit OSX and iOS simulator (struct returns).</li>
+<li>FFI: Fix calling conventions for ARM hard-float EABI (nested structs).</li>
+<li>FFI: Improve error messages for arithmetic and comparison operators.</li>
+<li>FFI: Insert no-op type conversion for pointer to integer cast.</li>
+<li>FFI: Fix unroll limit for <tt>ffi.fill()</tt>.</li>
+<li>FFI: Must sink <tt>XBAR</tt> together with <tt>XSTORE</tt>s.</li>
+<li>FFI: Preserve intermediate string for <tt>const&nbsp;char&nbsp;*</tt> conversion.</li>
+</ul>
+
+<h2 id="LuaJIT-2.0.1">LuaJIT 2.0.1 &mdash; 2013-02-19</h2>
+<ul>
+<li>Don't clear frame for out-of-memory error.</li>
+<li>Leave hook when resume catches error thrown from hook.</li>
+<li>Add missing GC steps for template table creation.</li>
+<li>Fix discharge order of comparisons in Lua parser.</li>
+<li>Improve buffer handling for <tt>io.read()</tt>.</li>
+<li>OSX: Add support for Mach-O object files to <tt>-b</tt> option.</li>
+<li>Fix PS3 port.</li>
+<li>Fix/enable Xbox 360 port.</li>
+<li>x86/x64: Always mark ref for shift count as non-weak.</li>
+<li>x64: Don't fuse implicitly 32-to-64 extended operands.</li>
+<li>ARM: Fix armhf call argument handling.</li>
+<li>ARM: Fix code generation for integer math.min/math.max.</li>
+<li>PPC/e500: Fix <tt>lj_vm_floor()</tt> for Inf/NaN.</li>
+<li>FFI: Change priority of table initializer variants for structs.</li>
+<li>FFI: Fix code generation for bool call result check on x86/x64.</li>
+<li>FFI: Load FFI library on-demand for bytecode with cdata literals.</li>
+<li>FFI: Fix handling of qualified transparent structs/unions.</li>
+</ul>
+
+<h2 id="LuaJIT-2.0.0">LuaJIT 2.0.0 &mdash; 2012-11-08</h2>
+<ul>
+<li>Correctness and completeness:
+<ul>
+ <li>Fix Android/x86 build.</li>
+ <li>Fix recording of equality comparisons with <tt>__eq</tt> metamethods.</li>
+ <li>Fix detection of immutable upvalues.</li>
+ <li>Replace error with PANIC for callbacks from JIT-compiled code.</li>
+ <li>Fix builtin string to number conversion for <tt>INT_MIN</tt>.</li>
+ <li>Don't create unneeded array part for template tables.</li>
+ <li>Fix <tt>CONV.num.int</tt> sinking.</li>
+ <li>Don't propagate implicitly widened number to index metamethods.</li>
+ <li>ARM: Fix ordered comparisons of number vs. non-number.</li>
+ <li>FFI: Fix code generation for replay of sunk float fields.</li>
+ <li>FFI: Fix signedness of bool.</li>
+ <li>FFI: Fix recording of bool call result check on x86/x64.</li>
+ <li>FFI: Fix stack-adjustment for <tt>__thiscall</tt> callbacks.</li>
+</ul></li>
+</ul>
+
+<h2 id="LuaJIT-2.0.0-beta11">LuaJIT 2.0.0-beta11 &mdash; 2012-10-16</h2>
+<ul>
+<li>New features:
+<ul>
+ <li>Use ARM VFP instructions, if available (build-time detection).</li>
+ <li>Add support for ARM hard-float EABI (<tt>armhf</tt>).</li>
+ <li>Add PS3 port.</li>
+ <li>Add many features from Lua&nbsp;5.2, e.g. <tt>goto</tt>/labels.
+ Refer to <a href="extensions.html#lua52">this list</a>.</li>
+ <li>FFI: Add parameterized C types.</li>
+ <li>FFI: Add support for copy constructors.</li>
+ <li>FFI: Equality comparisons never raise an error (treat as unequal instead).</li>
+ <li>FFI: Box all accessed or returned enums.</li>
+ <li>FFI: Check for <tt>__new</tt> metamethod when calling a constructor.</li>
+ <li>FFI: Handle <tt>__pairs</tt>/<tt>__ipairs</tt> metamethods for cdata objects.</li>
+ <li>FFI: Convert <tt>io.*</tt> file handle to <tt>FILE *</tt> pointer (but as a <tt>void *</tt>).</li>
+ <li>FFI: Detect and support type punning through unions.</li>
+ <li>FFI: Improve various error messages.</li>
+</ul></li>
+<li>Build-system reorganization:
+<ul>
+ <li>Reorganize directory layout:<br>
+ <tt>lib/*</tt> &rarr; <tt>src/jit/*</tt><br>
+ <tt>src/buildvm_*.dasc</tt> &rarr; <tt>src/vm_*.dasc</tt><br>
+ <tt>src/buildvm_*.h</tt> &rarr; removed<br>
+ <tt>src/buildvm*</tt> &rarr; <tt>src/host/*</tt></li>
+ <li>Add minified Lua interpreter plus Lua BitOp (<tt>minilua</tt>) to run DynASM.</li>
+ <li>Change DynASM bit operations to use Lua BitOp</li>
+ <li>Translate only <tt>vm_*.dasc</tt> for detected target architecture.</li>
+ <li>Improve target detection for <tt>msvcbuild.bat</tt>.</li>
+ <li>Fix build issues on Cygwin and MinGW with optional MSys.</li>
+ <li>Handle cross-compiles with FPU/no-FPU or hard-fp/soft-fp ABI mismatch.</li>
+ <li>Remove some library functions for no-JIT/no-FFI builds.</li>
+ <li>Add uninstall target to top-level Makefile.</li>
+</ul></li>
+<li>Correctness and completeness:
+<ul>
+ <li>Preserve snapshot #0 PC for all traces.</li>
+ <li>Fix argument checks for <tt>coroutine.create()</tt>.</li>
+ <li>Command line prints version and JIT status to <tt>stdout</tt>, not <tt>stderr</tt>.</li>
+ <li>Fix userdata <tt>__gc</tt> separations at Lua state close.</li>
+ <li>Fix <tt>TDUP</tt> to <tt>HLOAD</tt> forwarding for <tt>LJ_DUALNUM</tt> builds.</li>
+ <li>Fix buffer check in bytecode writer.</li>
+ <li>Make <tt>os.date()</tt> thread-safe.</li>
+ <li>Add missing declarations for MSVC intrinsics.</li>
+ <li>Fix dispatch table modifications for return hooks.</li>
+ <li>Workaround for MSVC conversion bug (<tt>double</tt> &rarr; <tt>uint32_t</tt> &rarr; <tt>int32_t</tt>).</li>
+ <li>Fix FOLD rule <tt>(i-j)-i => 0-j</tt>.</li>
+ <li>Never use DWARF unwinder on Windows.</li>
+ <li>Fix shrinking of direct mapped blocks in builtin allocator.</li>
+ <li>Limit recursion depth in <tt>string.match()</tt> et al.</li>
+ <li>Fix late despecialization of <tt>ITERN</tt> after loop has been entered.</li>
+ <li>Fix <tt>'f'</tt> and <tt>'L'</tt> options for <tt>debug.getinfo()</tt> and <tt>lua_getinfo()</tt>.</li>
+ <li>Fix <tt>package.searchpath()</tt>.</li>
+ <li>OSX: Change dylib names to be consistent with other platforms.</li>
+ <li>Android: Workaround for broken <tt>sprintf("%g",&nbsp;-0.0)</tt>.</li>
+ <li>x86: Remove support for ancient CPUs without <tt>CMOV</tt> (before Pentium Pro).</li>
+ <li>x86: Fix register allocation for calls returning register pair.</li>
+ <li>x86/x64: Fix fusion of unsigned byte comparisons with swapped operands.</li>
+ <li>ARM: Fix <tt>tonumber()</tt> argument check.</li>
+ <li>ARM: Fix modulo operator and <tt>math.floor()</tt>/<tt>math.ceil()</tt> for <tt>inf</tt>/<tt>nan</tt>.</li>
+ <li>ARM: Invoke SPLIT pass for leftover <tt>IR_TOBIT</tt>.</li>
+ <li>ARM: Fix BASE register coalescing.</li>
+ <li>PPC: Fix interpreter state setup in callbacks.</li>
+ <li>PPC: Fix <tt>string.sub()</tt> range check.</li>
+ <li>MIPS: Support generation of MIPS/MIPSEL bytecode object files.</li>
+ <li>MIPS: Fix calls to <tt>floor()</tt>/<tt>ceil()</tt><tt>/trunc()</tt>.</li>
+ <li>ARM/PPC: Detect more target architecture variants.</li>
+ <li>ARM/PPC/e500/MIPS: Fix tailcalls from fast functions, esp. <tt>tostring()</tt>.</li>
+ <li>ARM/PPC/MIPS: Fix rematerialization of FP constants.</li>
+ <li>FFI: Don't call <tt>FreeLibrary()</tt> on our own EXE/DLL.</li>
+ <li>FFI: Resolve metamethods for constructors, too.</li>
+ <li>FFI: Properly disable callbacks on iOS (would require executable memory).</li>
+ <li>FFI: Fix cdecl string parsing during recording.</li>
+ <li>FFI: Show address pointed to for <tt>tostring(ref)</tt>, too.</li>
+ <li>FFI: Fix alignment of C call argument/return structure.</li>
+ <li>FFI: Initialize all fields of standard types.</li>
+ <li>FFI: Fix callback handling when new C&nbsp;types are declared in callback.</li>
+ <li>FFI: Fix recording of constructors for pointers.</li>
+ <li>FFI: Always resolve metamethods for pointers to structs.</li>
+ <li>FFI: Correctly propagate alignment when interning nested types.</li>
+</ul></li>
+<li>Structural and performance enhancements:
+<ul>
+ <li>Add allocation sinking and store sinking optimization.</li>
+ <li>Constify immutable upvalues.</li>
+ <li>Add builtin string to integer or FP number conversion. Improves cross-platform consistency and correctness.</li>
+ <li>Create string hash slots in template tables for non-const values, too. Avoids later table resizes.</li>
+ <li>Eliminate <tt>HREFK</tt> guard for template table references.</li>
+ <li>Add various new FOLD rules.</li>
+ <li>Don't use stack unwinding for <tt>lua_yield()</tt> (slow on x64).</li>
+ <li>ARM, PPC, MIPS: Improve <tt>XLOAD</tt> operand fusion and register hinting.</li>
+ <li>PPC, MIPS: Compile <tt>math.sqrt()</tt> to sqrt instruction, if available.</li>
+ <li>FFI: Fold <tt>KPTR</tt> + constant offset in SPLIT pass.</li>
+ <li>FFI: Optimize/inline <tt>ffi.copy()</tt> and <tt>ffi.fill()</tt>.</li>
+ <li>FFI: Compile and optimize array/struct copies.</li>
+ <li>FFI: Compile <tt>ffi.typeof(cdata|ctype)</tt>, <tt>ffi.sizeof()</tt>, <tt>ffi.alignof()</tt>, <tt>ffi.offsetof()</tt> and <tt>ffi.gc()</tt>.</li>
+</ul></li>
+</ul>
+
+<h2 id="LuaJIT-2.0.0-beta10">LuaJIT 2.0.0-beta10 &mdash; 2012-05-09</h2>
+<ul>
+<li>New features:
+<ul>
+<li>The MIPS of LuaJIT is complete. It requires a CPU conforming to the
+MIPS32&nbsp;R1 architecture with hardware FPU. O32 hard-fp ABI,
+little-endian or big-endian.</li>
+<li>Auto-detect target arch via cross-compiler. No need for
+<tt>TARGET=arch</tt> anymore.</li>
+<li>Make DynASM compatible with Lua 5.2.</li>
+<li>From Lua 5.2: Try <tt>__tostring</tt> metamethod on non-string error
+messages..</li>
+</ul></li>
+<li>Correctness and completeness:
+<ul>
+<li>Fix parsing of hex literals with exponents.</li>
+<li>Fix bytecode dump for certain number constants.</li>
+<li>Fix argument type in error message for relative arguments.</li>
+<li>Fix argument error handling on Lua stacks without a frame.</li>
+<li>Add missing mcode limit check in assembler backend.</li>
+<li>Fix compilation on OpenBSD.</li>
+<li>Avoid recursive GC steps after GC-triggered trace exit.</li>
+<li>Replace <tt>&lt;unwind.h&gt;</tt> definitions with our own.</li>
+<li>Fix OSX build issues. Bump minimum required OSX version to 10.4.</li>
+<li>Fix discharge order of comparisons in Lua parser.</li>
+<li>Ensure running <tt>__gc</tt> of userdata created in <tt>__gc</tt>
+at state close.</li>
+<li>Limit number of userdata <tt>__gc</tt> separations at state close.</li>
+<li>Fix bytecode <tt>JMP</tt> slot range when optimizing
+<tt>and</tt>/<tt>or</tt> with constant LHS.</li>
+<li>Fix DSE of <tt>USTORE</tt>.</li>
+<li>Make <tt>lua_concat()</tt> work from C&nbsp;hook with partial frame.</li>
+<li>Add required PHIs for implicit conversions, e.g. via <tt>XREF</tt>
+forwarding.</li>
+<li>Add more comparison variants to Valgrind suppressions file.</li>
+<li>Disable loading bytecode with an extra header (BOM or <tt>#!</tt>).</li>
+<li>Fix PHI stack slot syncing.</li>
+<li>ARM: Reorder type/value tests to silence Valgrind.</li>
+<li>ARM: Fix register allocation for <tt>ldrd</tt>-optimized
+<tt>HREFK</tt>.</li>
+<li>ARM: Fix conditional branch fixup for <tt>OBAR</tt>.</li>
+<li>ARM: Invoke SPLIT pass for <tt>double</tt> args in FFI call.</li>
+<li>ARM: Handle all <tt>CALL*</tt> ops with <tt>double</tt> results in
+SPLIT pass.</li>
+<li>ARM: Fix rejoin of <tt>POW</tt> in SPLIT pass.</li>
+<li>ARM: Fix compilation of <tt>math.sinh</tt>, <tt>math.cosh</tt>,
+<tt>math.tanh</tt>.</li>
+<li>ARM, PPC: Avoid pointless arg clearing in <tt>BC_IFUNCF</tt>.</li>
+<li>PPC: Fix resume after yield from hook.</li>
+<li>PPC: Fix argument checking for <tt>rawget()</tt>.</li>
+<li>PPC: Fix fusion of floating-point <tt>XLOAD</tt>/<tt>XSTORE</tt>.</li>
+<li>PPC: Fix <tt>HREFK</tt> code generation for huge tables.</li>
+<li>PPC: Use builtin D-Cache/I-Cache sync code.</li>
+</ul></li>
+<li>FFI library:
+<ul>
+<li>Ignore empty statements in <tt>ffi.cdef()</tt>.</li>
+<li>Ignore number parsing errors while skipping definitions.</li>
+<li>Don't touch frame in callbacks with tailcalls to fast functions.</li>
+<li>Fix library unloading on POSIX systems.</li>
+<li>Finalize cdata before userdata when closing the state.</li>
+<li>Change <tt>ffi.load()</tt> library name resolution for Cygwin.</li>
+<li>Fix resolving of function name redirects on Windows/x86.</li>
+<li>Fix symbol resolving error messages on Windows.</li>
+<li>Fix blacklisting of C functions calling callbacks.</li>
+<li>Fix result type of pointer difference.</li>
+<li>Use correct PC in FFI metamethod error message.</li>
+<li>Allow <tt>'typedef _Bool int BOOL;'</tt> for the Windows API.</li>
+<li>Don't record test for bool result of call, if ignored.</li>
+</ul></li>
+</ul>
+
+<h2 id="LuaJIT-2.0.0-beta9">LuaJIT 2.0.0-beta9 &mdash; 2011-12-14</h2>
+<ul>
+<li>New features:
+<ul>
+<li>PPC port of LuaJIT is complete. Default is the dual-number port
+(usually faster). Single-number port selectable via <tt>src/Makefile</tt>
+at build time.</li>
+<li>Add FFI callback support.</li>
+<li>Extend <tt>-b</tt> to generate <tt>.c</tt>, <tt>.h</tt> or <tt>.obj/.o</tt>
+files with embedded bytecode.</li>
+<li>Allow loading embedded bytecode with <tt>require()</tt>.</li>
+<li>From Lua 5.2: Change to <tt>'\z'</tt> escape. Reject undefined escape
+sequences.</li>
+</ul></li>
+<li>Correctness and completeness:
+<ul>
+<li>Fix OSX 10.7 build. Fix <tt>install_name</tt> and versioning on OSX.</li>
+<li>Fix iOS build.</li>
+<li>Install <tt>dis_arm.lua</tt>, too.</li>
+<li>Mark installed shared library as executable.</li>
+<li>Add debug option to <tt>msvcbuild.bat</tt> and improve error handling.</li>
+<li>Fix data-flow analysis for iterators.</li>
+<li>Fix forced unwinding triggered by external unwinder.</li>
+<li>Record missing <tt>for</tt> loop slot loads (return to lower frame).</li>
+<li>Always use ANSI variants of Windows system functions.</li>
+<li>Fix GC barrier for multi-result table constructor (<tt>TSETM</tt>).</li>
+<li>Fix/add various FOLD rules.</li>
+<li>Add potential PHI for number conversions due to type instability.</li>
+<li>Do not eliminate PHIs only referenced from other PHIs.</li>
+<li>Correctly anchor implicit number to string conversions in Lua/C API.</li>
+<li>Fix various stack limit checks.</li>
+<li>x64: Use thread-safe exceptions for external unwinding (GCC platforms).</li>
+<li>x64: Fix result type of cdata index conversions.</li>
+<li>x64: Fix <tt>math.random()</tt> and <tt>bit.bswap()</tt> code generation.</li>
+<li>x64: Fix <tt>lightuserdata</tt> comparisons.</li>
+<li>x64: Always extend stack-passed arguments to pointer size.</li>
+<li>ARM: Many fixes to code generation backend.</li>
+<li>PPC/e500: Fix dispatch for binop metamethods.</li>
+<li>PPC/e500: Save/restore condition registers when entering/leaving the VM.</li>
+<li>PPC/e500: Fix write barrier in stores of strings to upvalues.</li>
+</ul></li>
+<li>FFI library:
+<ul>
+<li>Fix C comment parsing.</li>
+<li>Fix snapshot optimization for cdata comparisons.</li>
+<li>Fix recording of const/enum lookups in namespaces.</li>
+<li>Fix call argument and return handling for <tt>I8/U8/I16/U16</tt> types.</li>
+<li>Fix unfused loads of float fields.</li>
+<li>Fix <tt>ffi.string()</tt> recording.</li>
+<li>Save <tt>GetLastError()</tt> around <tt>ffi.load()</tt> and symbol
+resolving, too.</li>
+<li>Improve ld script detection in <tt>ffi.load()</tt>.</li>
+<li>Record loads/stores to external variables in namespaces.</li>
+<li>Compile calls to stdcall, fastcall and vararg functions.</li>
+<li>Treat function ctypes like pointers in comparisons.</li>
+<li>Resolve <tt>__call</tt> metamethod for pointers, too.</li>
+<li>Record C function calls with bool return values.</li>
+<li>Record <tt>ffi.errno()</tt>.</li>
+<li>x86: Fix number to <tt>uint32_t</tt> conversion rounding.</li>
+<li>x86: Fix 64 bit arithmetic in assembler backend.</li>
+<li>x64: Fix struct-by-value calling conventions.</li>
+<li>ARM: Ensure invocation of SPLIT pass for float conversions.</li>
+</ul></li>
+<li>Structural and performance enhancements:
+<ul>
+<li>Display trace types with <tt>-jv</tt> and <tt>-jdump</tt>.</li>
+<li>Record isolated calls. But prefer recording loops over calls.</li>
+<li>Specialize to prototype for non-monomorphic functions. Solves the
+trace-explosion problem for closure-heavy programming styles.</li>
+<li>Always generate a portable <tt>vmdef.lua</tt>. Easier for distros.</li>
+</ul></li>
+</ul>
+
+<h2 id="LuaJIT-2.0.0-beta8">LuaJIT 2.0.0-beta8 &mdash; 2011-06-23</h2>
+<ul>
+<li>New features:
+<ul>
+<li>Soft-float ARM port of LuaJIT is complete.</li>
+<li>Add support for bytecode loading/saving and <tt>-b</tt> command line
+option.</li>
+<li>From Lua 5.2: <tt>__len</tt> metamethod for tables
+(disabled by default).</li>
+</ul></li>
+<li>Correctness and completeness:
+<ul>
+<li>ARM: Misc. fixes for interpreter.</li>
+<li>x86/x64: Fix <tt>bit.*</tt> argument checking in interpreter.</li>
+<li>Catch early out-of-memory in memory allocator initialization.</li>
+<li>Fix data-flow analysis for paths leading to an upvalue close.</li>
+<li>Fix check for missing arguments in <tt>string.format()</tt>.</li>
+<li>Fix Solaris/x86 build (note: not a supported target).</li>
+<li>Fix recording of loops with instable directions in side traces.</li>
+<li>x86/x64: Fix fusion of comparisons with <tt>u8</tt>/<tt>u16</tt>
+<tt>XLOAD</tt>.</li>
+<li>x86/x64: Fix register allocation for variable shifts.</li>
+</ul></li>
+<li>FFI library:
+<ul>
+<li>Add <tt>ffi.errno()</tt>. Save <tt>errno</tt>/<tt>GetLastError()</tt>
+around allocations etc.</li>
+<li>Fix <tt>__gc</tt> for VLA/VLS cdata objects.</li>
+<li>Fix recording of casts from 32 bit cdata pointers to integers.</li>
+<li><tt>tonumber(cdata)</tt> returns <tt>nil</tt> for non-numbers.</li>
+<li>Show address pointed to for <tt>tostring(pointer)</tt>.</li>
+<li>Print <tt>NULL</tt> pointers as <tt>"cdata&lt;... *&gt;: NULL"</tt>.</li>
+<li>Support <tt>__tostring</tt> metamethod for pointers to structs, too.</li>
+</ul></li>
+<li>Structural and performance enhancements:
+<ul>
+<li>More tuning for loop unrolling heuristics.</li>
+<li>Flatten and compress in-memory debug info (saves ~70%).</li>
+</ul></li>
+</ul>
+
+<h2 id="LuaJIT-2.0.0-beta7">LuaJIT 2.0.0-beta7 &mdash; 2011-05-05</h2>
+<ul>
+<li>New features:
+<ul>
+<li>ARM port of the LuaJIT interpreter is complete.</li>
+<li>FFI library: Add <tt>ffi.gc()</tt>, <tt>ffi.metatype()</tt>,
+<tt>ffi.istype()</tt>.</li>
+<li>FFI library: Resolve ld script redirection in <tt>ffi.load()</tt>.</li>
+<li>From Lua 5.2: <tt>package.searchpath()</tt>, <tt>fp:read("*L")</tt>,
+<tt>load(string)</tt>.</li>
+<li>From Lua 5.2, disabled by default: empty statement,
+<tt>table.unpack()</tt>, modified <tt>coroutine.running()</tt>.</li>
+</ul></li>
+<li>Correctness and completeness:
+<ul>
+<li>FFI library: numerous fixes.</li>
+<li>Fix type mismatches in store-to-load forwarding.</li>
+<li>Fix error handling within metamethods.</li>
+<li>Fix <tt>table.maxn()</tt>.</li>
+<li>Improve accuracy of <tt>x^-k</tt> on x64.</li>
+<li>Fix code generation for Intel Atom in x64 mode.</li>
+<li>Fix narrowing of POW.</li>
+<li>Fix recording of retried fast functions.</li>
+<li>Fix code generation for <tt>bit.bnot()</tt> and multiplies.</li>
+<li>Fix error location within cpcall frames.</li>
+<li>Add workaround for old libgcc unwind bug.</li>
+<li>Fix <tt>lua_yield()</tt> and <tt>getmetatable(lightuserdata)</tt> on x64.</li>
+<li>Misc. fixes for PPC/e500 interpreter.</li>
+<li>Fix stack slot updates for down-recursion.</li>
+</ul></li>
+<li>Structural and performance enhancements:
+<ul>
+<li>Add dual-number mode (int/double) for the VM. Enabled for ARM.</li>
+<li>Improve narrowing of arithmetic operators and <tt>for</tt> loops.</li>
+<li>Tune loop unrolling heuristics and increase trace recorder limits.</li>
+<li>Eliminate dead slots in snapshots using bytecode data-flow analysis.</li>
+<li>Avoid phantom stores to proxy tables.</li>
+<li>Optimize lookups in empty proxy tables.</li>
+<li>Improve bytecode optimization of <tt>and</tt>/<tt>or</tt> operators.</li>
+</ul></li>
+</ul>
+
+<h2 id="LuaJIT-2.0.0-beta6">LuaJIT 2.0.0-beta6 &mdash; 2011-02-11</h2>
+<ul>
+<li>New features:
+<ul>
+<li>PowerPC/e500v2 port of the LuaJIT interpreter is complete.</li>
+<li>Various minor features from Lua 5.2: Hex escapes in literals,
+<tt>'\*'</tt> escape, reversible <tt>string.format("%q",s)</tt>,
+<tt>"%g"</tt> pattern, <tt>table.sort</tt> checks callbacks,
+<tt>os.exit(status|true|false[,close])</tt>.</li>
+<li>Lua 5.2 <tt>__pairs</tt> and <tt>__ipairs</tt> metamethods
+(disabled by default).</li>
+<li>Initial release of the FFI library.</li>
+</ul></li>
+<li>Correctness and completeness:
+<ul>
+<li>Fix <tt>string.format()</tt> for non-finite numbers.</li>
+<li>Fix memory leak when compiled to use the built-in allocator.</li>
+<li>x86/x64: Fix unnecessary resize in <tt>TSETM</tt> bytecode.</li>
+<li>Fix various GC issues with traces and <tt>jit.flush()</tt>.</li>
+<li>x64: Fix fusion of indexes for array references.</li>
+<li>x86/x64: Fix stack overflow handling for coroutine results.</li>
+<li>Enable low-2GB memory allocation on FreeBSD/x64.</li>
+<li>Fix <tt>collectgarbage("count")</tt> result if more than 2GB is in use.</li>
+<li>Fix parsing of hex floats.</li>
+<li>x86/x64: Fix loop branch inversion with trailing
+<tt>HREF+NE/EQ</tt>.</li>
+<li>Add <tt>jit.os</tt> string.</li>
+<li><tt>coroutine.create()</tt> permits running C functions, too.</li>
+<li>Fix OSX build to work with newer ld64 versions.</li>
+<li>Fix bytecode optimization of <tt>and</tt>/<tt>or</tt> operators.</li>
+</ul></li>
+<li>Structural and performance enhancements:
+<ul>
+<li>Emit specialized bytecode for <tt>pairs()</tt>/<tt>next()</tt>.</li>
+<li>Improve bytecode coalescing of <tt>nil</tt> constants.</li>
+<li>Compile calls to vararg functions.</li>
+<li>Compile <tt>select()</tt>.</li>
+<li>Improve alias analysis, esp. for loads from allocations.</li>
+<li>Tuning of various compiler heuristics.</li>
+<li>Refactor and extend IR conversion instructions.</li>
+<li>x86/x64: Various backend enhancements related to the FFI.</li>
+<li>Add SPLIT pass to split 64 bit IR instructions for 32 bit CPUs.</li>
+</ul></li>
+</ul>
+
+<h2 id="LuaJIT-2.0.0-beta5">LuaJIT 2.0.0-beta5 &mdash; 2010-08-24</h2>
+<ul>
+<li>Correctness and completeness:
+<ul>
+<li>Fix trace exit dispatch to function headers.</li>
+<li>Fix Windows and OSX builds with LUAJIT_DISABLE_JIT.</li>
+<li>Reorganize and fix placement of generated machine code on x64.</li>
+<li>Fix TNEW in x64 interpreter.</li>
+<li>Do not eliminate PHIs for values only referenced from side exits.</li>
+<li>OS-independent canonicalization of strings for non-finite numbers.</li>
+<li>Fix <tt>string.char()</tt> range check on x64.</li>
+<li>Fix <tt>tostring()</tt> resolving within <tt>print()</tt>.</li>
+<li>Fix error handling for <tt>next()</tt>.</li>
+<li>Fix passing of constant arguments to external calls on x64.</li>
+<li>Fix interpreter argument check for two-argument SSE math functions.</li>
+<li>Fix C frame chain corruption caused by <tt>lua_cpcall()</tt>.</li>
+<li>Fix return from <tt>pcall()</tt> within active hook.</li>
+</ul></li>
+<li>Structural and performance enhancements:
+<ul>
+<li>Replace on-trace GC frame syncing with interpreter exit.</li>
+<li>Improve hash lookup specialization by not removing dead keys during GC.</li>
+<li>Turn traces into true GC objects.</li>
+<li>Avoid starting a GC cycle immediately after library init.</li>
+<li>Add weak guards to improve dead-code elimination.</li>
+<li>Speed up string interning.</li>
+</ul></li>
+</ul>
+
+<h2 id="LuaJIT-2.0.0-beta4">LuaJIT 2.0.0-beta4 &mdash; 2010-03-28</h2>
+<ul>
+<li>Correctness and completeness:
+<ul>
+<li>Fix precondition for on-trace creation of table keys.</li>
+<li>Fix <tt>{f()}</tt> on x64 when table is resized.</li>
+<li>Fix folding of ordered comparisons with same references.</li>
+<li>Fix snapshot restores for multi-result bytecodes.</li>
+<li>Fix potential hang when recording bytecode with nested closures.</li>
+<li>Fix recording of <tt>getmetatable()</tt>, <tt>tonumber()</tt> and bad argument types.</li>
+<li>Fix SLOAD fusion across returns to lower frames.</li>
+</ul></li>
+<li>Structural and performance enhancements:
+<ul>
+<li>Add array bounds check elimination. <tt>-Oabc</tt> is enabled by default.</li>
+<li>More tuning for x64, e.g. smaller table objects.</li>
+</ul></li>
+</ul>
+
+<h2 id="LuaJIT-2.0.0-beta3">LuaJIT 2.0.0-beta3 &mdash; 2010-03-07</h2>
+<ul>
+<li>LuaJIT x64 port:
+<ul>
+<li>Port integrated memory allocator to Linux/x64, Windows/x64 and OSX/x64.</li>
+<li>Port interpreter and JIT compiler to x64.</li>
+<li>Port DynASM to x64.</li>
+<li>Many 32/64 bit cleanups in the VM.</li>
+<li>Allow building the interpreter with either x87 or SSE2 arithmetics.</li>
+<li>Add external unwinding and C++ exception interop (default on x64).</li>
+</ul></li>
+<li>Correctness and completeness:
+<ul>
+<li>Fix constructor bytecode generation for certain conditional values.</li>
+<li>Fix some cases of ordered string comparisons.</li>
+<li>Fix <tt>lua_tocfunction()</tt>.</li>
+<li>Fix cutoff register in JMP bytecode for some conditional expressions.</li>
+<li>Fix PHI marking algorithm for references from variant slots.</li>
+<li>Fix <tt>package.cpath</tt> for non-default PREFIX.</li>
+<li>Fix DWARF2 frame unwind information for interpreter on OSX.</li>
+<li>Drive the GC forward on string allocations in the parser.</li>
+<li>Implement call/return hooks (zero-cost if disabled).</li>
+<li>Implement yield from C hooks.</li>
+<li>Disable JIT compiler on older non-SSE2 CPUs instead of aborting.</li>
+</ul></li>
+<li>Structural and performance enhancements:
+<ul>
+<li>Compile recursive code (tail-, up- and down-recursion).</li>
+<li>Improve heuristics for bytecode penalties and blacklisting.</li>
+<li>Split CALL/FUNC recording and clean up fast function call semantics.</li>
+<li>Major redesign of internal function call handling.</li>
+<li>Improve FOR loop const specialization and integerness checks.</li>
+<li>Switch to pre-initialized stacks. Avoid frame-clearing.</li>
+<li>Colocation of prototypes and related data: bytecode, constants, debug info.</li>
+<li>Cleanup parser and streamline bytecode generation.</li>
+<li>Add support for weak IR references to register allocator.</li>
+<li>Switch to compressed, extensible snapshots.</li>
+<li>Compile returns to frames below the start frame.</li>
+<li>Improve alias analysis of upvalues using a disambiguation hash value.</li>
+<li>Compile floor/ceil/trunc to SSE2 helper calls or SSE4.1 instructions.</li>
+<li>Add generic C call handling to IR and backend.</li>
+<li>Improve KNUM fuse vs. load heuristics.</li>
+<li>Compile various <tt>io.*()</tt> functions.</li>
+<li>Compile <tt>math.sinh()</tt>, <tt>math.cosh()</tt>, <tt>math.tanh()</tt>
+and <tt>math.random()</tt>.</li>
+</ul></li>
+</ul>
+
+<h2 id="LuaJIT-2.0.0-beta2">LuaJIT 2.0.0-beta2 &mdash; 2009-11-09</h2>
+<ul>
+<li>Reorganize build system. Build static+shared library on POSIX.</li>
+<li>Allow C++ exception conversion on all platforms
+using a wrapper function.</li>
+<li>Automatically catch C++ exceptions and rethrow Lua error
+(DWARF2 only).</li>
+<li>Check for the correct x87 FPU precision at strategic points.</li>
+<li>Always use wrappers for libm functions.</li>
+<li>Resurrect metamethod name strings before copying them.</li>
+<li>Mark current trace, even if compiler is idle.</li>
+<li>Ensure FILE metatable is created only once.</li>
+<li>Fix type comparisons when different integer types are involved.</li>
+<li>Fix <tt>getmetatable()</tt> recording.</li>
+<li>Fix TDUP with dead keys in template table.</li>
+<li><tt>jit.flush(tr)</tt> returns status.
+Prevent manual flush of a trace that's still linked.</li>
+<li>Improve register allocation heuristics for invariant references.</li>
+<li>Compile the push/pop variants of <tt>table.insert()</tt> and
+<tt>table.remove()</tt>.</li>
+<li>Compatibility with MSVC <tt>link&nbsp/debug</tt>.</li>
+<li>Fix <tt>lua_iscfunction()</tt>.</li>
+<li>Fix <tt>math.random()</tt> when compiled with <tt>-fpic</tt> (OSX).</li>
+<li>Fix <tt>table.maxn()</tt>.</li>
+<li>Bump <tt>MACOSX_DEPLOYMENT_TARGET</tt> to <tt>10.4</tt></li>
+<li><tt>luaL_check*()</tt> and <tt>luaL_opt*()</tt> now support
+negative arguments, too.<br>
+This matches the behavior of Lua 5.1, but not the specification.</li>
+</ul>
+
+<h2 id="LuaJIT-2.0.0-beta1">LuaJIT 2.0.0-beta1 &mdash; 2009-10-31</h2>
+<ul>
+<li>This is the first public release of LuaJIT 2.0.</li>
+<li>The whole VM has been rewritten from the ground up, so there's
+no point in listing differences over earlier versions.</li>
+</ul>
+</div>
+
+<div class="major" style="background: #ffff80;">
+<h2 id="LuaJIT-1.1.8">LuaJIT 1.1.8 &mdash; 2012-04-16</h2>
+<ul>
+<li>Merged with Lua 5.1.5. Also integrated fixes for all
+<a href="http://www.lua.org/bugs.html#5.1.5"><span class="ext">&raquo;</span>&nbsp;<span class="ext">&raquo;</span>&nbsp;currently known bugs in Lua 5.1.5</a>.</li>
+</ul>
+
+<h2 id="LuaJIT-1.1.7">LuaJIT 1.1.7 &mdash; 2011-05-05</h2>
+<ul>
+<li>Added fixes for the
+<a href="http://www.lua.org/bugs.html#5.1.4"><span class="ext">&raquo;</span>&nbsp;currently known bugs in Lua 5.1.4</a>.</li>
+</ul>
+
+<h2 id="LuaJIT-1.1.6">LuaJIT 1.1.6 &mdash; 2010-03-28</h2>
+<ul>
+<li>Added fixes for the
+<a href="http://www.lua.org/bugs.html#5.1.4"><span class="ext">&raquo;</span>&nbsp;currently known bugs in Lua 5.1.4</a>.</li>
+<li>Removed wrong GC check in <tt>jit_createstate()</tt>.
+Thanks to Tim Mensch.</li>
+<li>Fixed bad assertions while compiling <tt>table.insert()</tt> and
+<tt>table.remove()</tt>.</li>
+</ul>
+
+<h2 id="LuaJIT-1.1.5">LuaJIT 1.1.5 &mdash; 2008-10-25</h2>
+<ul>
+<li>Merged with Lua 5.1.4. Fixes all
+<a href="http://www.lua.org/bugs.html#5.1.3"><span class="ext">&raquo;</span>&nbsp;known bugs in Lua 5.1.3</a>.</li>
+</ul>
+
+<h2 id="LuaJIT-1.1.4">LuaJIT 1.1.4 &mdash; 2008-02-05</h2>
+<ul>
+<li>Merged with Lua 5.1.3. Fixes all
+<a href="http://www.lua.org/bugs.html#5.1.2"><span class="ext">&raquo;</span>&nbsp;known bugs in Lua 5.1.2</a>.</li>
+<li>Fixed possible (but unlikely) stack corruption while compiling
+<tt>k^x</tt> expressions.</li>
+<li>Fixed DynASM template for cmpss instruction.</li>
+</ul>
+
+<h2 id="LuaJIT-1.1.3">LuaJIT 1.1.3 &mdash; 2007-05-24</h2>
+<ul>
+<li>Merged with Lua 5.1.2. Fixes all
+<a href="http://www.lua.org/bugs.html#5.1.1"><span class="ext">&raquo;</span>&nbsp;known bugs in Lua 5.1.1</a>.</li>
+<li>Merged pending Lua 5.1.x fixes: "return -nil" bug, spurious count hook call.</li>
+<li>Remove a (sometimes) wrong assertion in <tt>luaJIT_findpc()</tt>.</li>
+<li>DynASM now allows labels for displacements and <tt>.aword</tt>.</li>
+<li>Fix some compiler warnings for DynASM glue (internal API change).</li>
+<li>Correct naming for SSSE3 (temporarily known as SSE4) in DynASM and x86 disassembler.</li>
+<li>The loadable debug modules now handle redirection to stdout
+(e.g. <tt>-j&nbsp;trace=-</tt>).</li>
+</ul>
+
+<h2 id="LuaJIT-1.1.2">LuaJIT 1.1.2 &mdash; 2006-06-24</h2>
+<ul>
+<li>Fix MSVC inline assembly: use only local variables with
+<tt>lua_number2int()</tt>.</li>
+<li>Fix "attempt to call a thread value" bug on Mac OS X:
+make values of consts used as lightuserdata keys unique
+to avoid joining by the compiler/linker.</li>
+</ul>
+
+<h2 id="LuaJIT-1.1.1">LuaJIT 1.1.1 &mdash; 2006-06-20</h2>
+<ul>
+<li>Merged with Lua 5.1.1. Fixes all
+<a href="http://www.lua.org/bugs.html#5.1"><span class="ext">&raquo;</span>&nbsp;known bugs in Lua 5.1</a>.</li>
+<li>Enforce (dynamic) linker error for EXE/DLL version mismatches.</li>
+<li>Minor changes to DynASM: faster pre-processing, smaller encoding
+for some immediates.</li>
+</ul>
+<p>
+This release is in sync with Coco 1.1.1 (see the
+<a href="http://coco.luajit.org/changes.html"><span class="ext">&raquo;</span>&nbsp;Coco Change History</a>).
+</p>
+
+<h2 id="LuaJIT-1.1.0">LuaJIT 1.1.0 &mdash; 2006-03-13</h2>
+<ul>
+<li>Merged with Lua 5.1 (final).</li>
+
+<li>New JIT call frame setup:
+<ul>
+<li>The C stack is kept 16 byte aligned (faster).
+Mandatory for Mac OS X on Intel, too.</li>
+<li>Faster calling conventions for internal C helper functions.</li>
+<li>Better instruction scheduling for function prologue, OP_CALL and
+OP_RETURN.</li>
+</ul></li>
+
+<li>Miscellaneous optimizations:
+<ul>
+<li>Faster loads of FP constants. Remove narrow-to-wide store-to-load
+forwarding stalls.</li>
+<li>Use (scalar) SSE2 ops (if the CPU supports it) to speed up slot moves
+and FP to integer conversions.</li>
+<li>Optimized the two-argument form of <tt>OP_CONCAT</tt> (<tt>a..b</tt>).</li>
+<li>Inlined <tt>OP_MOD</tt> (<tt>a%b</tt>).
+With better accuracy than the C variant, too.</li>
+<li>Inlined <tt>OP_POW</tt> (<tt>a^b</tt>). Unroll <tt>x^k</tt> or
+use <tt>k^x = 2^(log2(k)*x)</tt> or call <tt>pow()</tt>.</li>
+</ul></li>
+
+<li>Changes in the optimizer:
+<ul>
+<li>Improved hinting for table keys derived from table values
+(<tt>t1[t2[x]]</tt>).</li>
+<li>Lookup hinting now works with arbitrary object types and
+supports index chains, too.</li>
+<li>Generate type hints for arithmetic and comparison operators,
+OP_LEN, OP_CONCAT and OP_FORPREP.</li>
+<li>Remove several hint definitions in favour of a generic COMBINE hint.</li>
+<li>Complete rewrite of <tt>jit.opt_inline</tt> module
+(ex <tt>jit.opt_lib</tt>).</li>
+</ul></li>
+
+<li>Use adaptive deoptimization:
+<ul>
+<li>If runtime verification of a contract fails, the affected
+instruction is recompiled and patched on-the-fly.
+Regular programs will trigger deoptimization only occasionally.</li>
+<li>This avoids generating code for uncommon fallback cases
+most of the time. Generated code is up to 30% smaller compared to
+LuaJIT&nbsp;1.0.3.</li>
+<li>Deoptimization is used for many opcodes and contracts:
+<ul>
+<li>OP_CALL, OP_TAILCALL: type mismatch for callable.</li>
+<li>Inlined calls: closure mismatch, parameter number and type mismatches.</li>
+<li>OP_GETTABLE, OP_SETTABLE: table or key type and range mismatches.</li>
+<li>All arithmetic and comparison operators, OP_LEN, OP_CONCAT,
+OP_FORPREP: operand type and range mismatches.</li>
+</ul></li>
+<li>Complete redesign of the debug and traceback info
+(bytecode &harr; mcode) to support deoptimization.
+Much more flexible and needs only 50% of the space.</li>
+<li>The modules <tt>jit.trace</tt>, <tt>jit.dumphints</tt> and
+<tt>jit.dump</tt> handle deoptimization.</li>
+</ul></li>
+
+<li>Inlined many popular library functions
+(for commonly used arguments only):
+<ul>
+<li>Most <tt>math.*</tt> functions (the 18 most used ones)
+[2x-10x faster].</li>
+<li><tt>string.len</tt>, <tt>string.sub</tt> and <tt>string.char</tt>
+[2x-10x faster].</li>
+<li><tt>table.insert</tt>, <tt>table.remove</tt> and <tt>table.getn</tt>
+[3x-5x faster].</li>
+<li><tt>coroutine.yield</tt> and <tt>coroutine.resume</tt>
+[3x-5x faster].</li>
+<li><tt>pairs</tt>, <tt>ipairs</tt> and the corresponding iterators
+[8x-15x faster].</li>
+</ul></li>
+
+<li>Changes in the core and loadable modules and the stand-alone executable:
+<ul>
+<li>Added <tt>jit.version</tt>, <tt>jit.version_num</tt>
+and <tt>jit.arch</tt>.</li>
+<li>Reorganized some internal API functions (<tt>jit.util.*mcode*</tt>).</li>
+<li>The <tt>-j dump</tt> output now shows JSUB names, too.</li>
+<li>New x86 disassembler module written in pure Lua. No dependency
+on ndisasm anymore. Flexible API, very compact (500 lines)
+and complete (x87, MMX, SSE, SSE2, SSE3, SSSE3, privileged instructions).</li>
+<li><tt>luajit -v</tt> prints the LuaJIT version and copyright
+on a separate line.</li>
+</ul></li>
+
+<li>Added SSE, SSE2, SSE3 and SSSE3 support to DynASM.</li>
+<li>Miscellaneous doc changes. Added a section about
+<a href="install.html#embedding">embedding LuaJIT</a>.</li>
+</ul>
+<p>
+This release is in sync with Coco 1.1.0 (see the
+<a href="http://coco.luajit.org/changes.html"><span class="ext">&raquo;</span>&nbsp;Coco Change History</a>).
+</p>
+</div>
+
+<div class="major" style="background: #ffffd0;">
+<h2 id="LuaJIT-1.0.3">LuaJIT 1.0.3 &mdash; 2005-09-08</h2>
+<ul>
+<li>Even more docs.</li>
+<li>Unified closure checks in <tt>jit.*</tt>.</li>
+<li>Fixed some range checks in <tt>jit.util.*</tt>.</li>
+<li>Fixed __newindex call originating from <tt>jit_settable_str()</tt>.</li>
+<li>Merged with Lua 5.1 alpha (including early bug fixes).</li>
+</ul>
+<p>
+This is the first public release of LuaJIT.
+</p>
+
+<h2 id="LuaJIT-1.0.2">LuaJIT 1.0.2 &mdash; 2005-09-02</h2>
+<ul>
+<li>Add support for flushing the Valgrind translation cache <br>
+(<tt>MYCFLAGS= -DUSE_VALGRIND</tt>).</li>
+<li>Add support for freeing executable mcode memory to the <tt>mmap()</tt>-based
+variant for POSIX systems.</li>
+<li>Reorganized the C&nbsp;function signature handling in
+<tt>jit.opt_lib</tt>.</li>
+<li>Changed to index-based hints for inlining C&nbsp;functions.
+Still no support in the backend for inlining.</li>
+<li>Hardcode <tt>HEAP_CREATE_ENABLE_EXECUTE</tt> value if undefined.</li>
+<li>Misc. changes to the <tt>jit.*</tt> modules.</li>
+<li>Misc. changes to the Makefiles.</li>
+<li>Lots of new docs.</li>
+<li>Complete doc reorg.</li>
+</ul>
+<p>
+Not released because Lua 5.1 alpha came out today.
+</p>
+
+<h2 id="LuaJIT-1.0.1">LuaJIT 1.0.1 &mdash; 2005-08-31</h2>
+<ul>
+<li>Missing GC step in <tt>OP_CONCAT</tt>.</li>
+<li>Fix result handling for C &ndash;> JIT calls.</li>
+<li>Detect CPU feature bits.</li>
+<li>Encode conditional moves (<tt>fucomip</tt>) only when supported.</li>
+<li>Add fallback instructions for FP compares.</li>
+<li>Add support for <tt>LUA_COMPAT_VARARG</tt>. Still disabled by default.</li>
+<li>MSVC needs a specific place for the <tt>CALLBACK</tt> attribute
+(David Burgess).</li>
+<li>Misc. doc updates.</li>
+</ul>
+<p>
+Interim non-public release.
+Special thanks to Adam D. Moss for reporting most of the bugs.
+</p>
+
+<h2 id="LuaJIT-1.0.0">LuaJIT 1.0.0 &mdash; 2005-08-29</h2>
+<p>
+This is the initial non-public release of LuaJIT.
+</p>
+</div>
+<br class="flush">
+</div>
+<div id="foot">
+<hr class="hide">
+Copyright &copy; 2005-2018
+<span class="noprint">
+&middot;
+<a href="contact.html">Contact</a>
+</span>
+</div>
+</body>
+</html>
diff --git a/src/3rdparty/LuaJIT-2.0.5/doc/contact.html b/src/3rdparty/LuaJIT-2.0.5/doc/contact.html
new file mode 100644
index 0000000..54ddf74
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/doc/contact.html
@@ -0,0 +1,108 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<title>Contact</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<meta name="Copyright" content="Copyright (C) 2005-2018">
+<meta name="Language" content="en">
+<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
+<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
+</head>
+<body>
+<div id="site">
+<a href="http://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
+</div>
+<div id="head">
+<h1>Contact</h1>
+</div>
+<div id="nav">
+<ul><li>
+<a href="luajit.html">LuaJIT</a>
+<ul><li>
+<a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="install.html">Installation</a>
+</li><li>
+<a href="running.html">Running</a>
+</li></ul>
+</li><li>
+<a href="extensions.html">Extensions</a>
+<ul><li>
+<a href="ext_ffi.html">FFI Library</a>
+<ul><li>
+<a href="ext_ffi_tutorial.html">FFI Tutorial</a>
+</li><li>
+<a href="ext_ffi_api.html">ffi.* API</a>
+</li><li>
+<a href="ext_ffi_semantics.html">FFI Semantics</a>
+</li></ul>
+</li><li>
+<a href="ext_jit.html">jit.* Library</a>
+</li><li>
+<a href="ext_c_api.html">Lua/C API</a>
+</li></ul>
+</li><li>
+<a href="status.html">Status</a>
+<ul><li>
+<a href="changes.html">Changes</a>
+</li></ul>
+</li><li>
+<a href="faq.html">FAQ</a>
+</li><li>
+<a href="http://luajit.org/performance.html">Performance <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
+</li></ul>
+</div>
+<div id="main">
+<p>
+If you want to report bugs, propose fixes or suggest enhancements,
+please use the
+<a href="https://github.com/LuaJIT/LuaJIT/issues">GitHub issue tracker</a>.
+</p>
+<p>
+Please send general questions to the
+<a href="http://luajit.org/list.html"><span class="ext">&raquo;</span>&nbsp;LuaJIT mailing list</a>.
+</p>
+<p>
+You can also send any questions you have directly to me:
+</p>
+
+<script type="text/javascript">
+<!--
+var xS="@-:\" .0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ<abc>defghijklmnopqrstuvwxyz";function xD(s)
+{var len=s.length;var r="";for(var i=0;i<len;i++)
+{var c=s.charAt(i);var n=xS.indexOf(c);if(n!=-1)c=xS.charAt(69-n);r+=c;}
+document.write("<"+"p>"+r+"<"+"/p>\n");}
+//-->
+</script>
+<script type="text/javascript">
+<!--
+xD("fyZKB8xv\"FJytmz8.KAB0u52D")
+//--></script>
+<noscript>
+<p><img src="img/contact.png" alt="Contact info in image" width="170" height="13">
+</p>
+</noscript>
+
+<h2>Copyright</h2>
+<p>
+All documentation is
+Copyright &copy; 2005-2018 Mike Pall.
+</p>
+
+
+<br class="flush">
+</div>
+<div id="foot">
+<hr class="hide">
+Copyright &copy; 2005-2018
+<span class="noprint">
+&middot;
+<a href="contact.html">Contact</a>
+</span>
+</div>
+</body>
+</html>
diff --git a/src/3rdparty/LuaJIT-2.0.5/doc/ext_c_api.html b/src/3rdparty/LuaJIT-2.0.5/doc/ext_c_api.html
new file mode 100644
index 0000000..3825956
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/doc/ext_c_api.html
@@ -0,0 +1,186 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<title>Lua/C API Extensions</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<meta name="Copyright" content="Copyright (C) 2005-2018">
+<meta name="Language" content="en">
+<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
+<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
+</head>
+<body>
+<div id="site">
+<a href="http://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
+</div>
+<div id="head">
+<h1>Lua/C API Extensions</h1>
+</div>
+<div id="nav">
+<ul><li>
+<a href="luajit.html">LuaJIT</a>
+<ul><li>
+<a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="install.html">Installation</a>
+</li><li>
+<a href="running.html">Running</a>
+</li></ul>
+</li><li>
+<a href="extensions.html">Extensions</a>
+<ul><li>
+<a href="ext_ffi.html">FFI Library</a>
+<ul><li>
+<a href="ext_ffi_tutorial.html">FFI Tutorial</a>
+</li><li>
+<a href="ext_ffi_api.html">ffi.* API</a>
+</li><li>
+<a href="ext_ffi_semantics.html">FFI Semantics</a>
+</li></ul>
+</li><li>
+<a href="ext_jit.html">jit.* Library</a>
+</li><li>
+<a class="current" href="ext_c_api.html">Lua/C API</a>
+</li></ul>
+</li><li>
+<a href="status.html">Status</a>
+<ul><li>
+<a href="changes.html">Changes</a>
+</li></ul>
+</li><li>
+<a href="faq.html">FAQ</a>
+</li><li>
+<a href="http://luajit.org/performance.html">Performance <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
+</li></ul>
+</div>
+<div id="main">
+<p>
+LuaJIT adds some extensions to the standard Lua/C API. The LuaJIT include
+directory must be in the compiler search path (<tt>-I<i>path</i></tt>)
+to be able to include the required header for C code:
+</p>
+<pre class="code">
+#include "luajit.h"
+</pre>
+<p>
+Or for C++ code:
+</p>
+<pre class="code">
+#include "lua.hpp"
+</pre>
+
+<h2 id="luaJIT_setmode"><tt>luaJIT_setmode(L, idx, mode)</tt>
+&mdash; Control VM</h2>
+<p>
+This is a C API extension to allow control of the VM from C code. The
+full prototype of <tt>LuaJIT_setmode</tt> is:
+</p>
+<pre class="code">
+LUA_API int luaJIT_setmode(lua_State *L, int idx, int mode);
+</pre>
+<p>
+The returned status is either success (<tt>1</tt>) or failure (<tt>0</tt>).
+The second argument is either <tt>0</tt> or a stack index (similar to the
+other Lua/C API functions).
+</p>
+<p>
+The third argument specifies the mode, which is 'or'ed with a flag.
+The flag can be <tt>LUAJIT_MODE_OFF</tt> to turn a feature off,
+<tt>LUAJIT_MODE_ON</tt> to turn a feature on, or
+<tt>LUAJIT_MODE_FLUSH</tt> to flush cached code.
+</p>
+<p>
+The following modes are defined:
+</p>
+
+<h3 id="mode_engine"><tt>luaJIT_setmode(L, 0, LUAJIT_MODE_ENGINE|flag)</tt></h3>
+<p>
+Turn the whole JIT compiler on or off or flush the whole cache of compiled code.
+</p>
+
+<h3 id="mode_func"><tt>luaJIT_setmode(L, idx, LUAJIT_MODE_FUNC|flag)</tt><br>
+<tt>luaJIT_setmode(L, idx, LUAJIT_MODE_ALLFUNC|flag)</tt><br>
+<tt>luaJIT_setmode(L, idx, LUAJIT_MODE_ALLSUBFUNC|flag)</tt></h3>
+<p>
+This sets the mode for the function at the stack index <tt>idx</tt> or
+the parent of the calling function (<tt>idx = 0</tt>). It either
+enables JIT compilation for a function, disables it and flushes any
+already compiled code or only flushes already compiled code. This
+applies recursively to all sub-functions of the function with
+<tt>LUAJIT_MODE_ALLFUNC</tt> or only to the sub-functions with
+<tt>LUAJIT_MODE_ALLSUBFUNC</tt>.
+</p>
+
+<h3 id="mode_trace"><tt>luaJIT_setmode(L, trace,<br>
+&nbsp;&nbsp;LUAJIT_MODE_TRACE|LUAJIT_MODE_FLUSH)</tt></h3>
+<p>
+Flushes the specified root trace and all of its side traces from the cache.
+The code for the trace will be retained as long as there are any other
+traces which link to it.
+</p>
+
+<h3 id="mode_wrapcfunc"><tt>luaJIT_setmode(L, idx, LUAJIT_MODE_WRAPCFUNC|flag)</tt></h3>
+<p>
+This mode defines a wrapper function for calls to C functions. If
+called with <tt>LUAJIT_MODE_ON</tt>, the stack index at <tt>idx</tt>
+must be a <tt>lightuserdata</tt> object holding a pointer to the wrapper
+function. From now on all C functions are called through the wrapper
+function. If called with <tt>LUAJIT_MODE_OFF</tt> this mode is turned
+off and all C functions are directly called.
+</p>
+<p>
+The wrapper function can be used for debugging purposes or to catch
+and convert foreign exceptions. But please read the section on
+<a href="extensions.html#exceptions">C++&nbsp;exception interoperability</a>
+first. Recommended usage can be seen in this C++ code excerpt:
+</p>
+<pre class="code">
+#include &lt;exception&gt;
+#include "lua.hpp"
+
+// Catch C++ exceptions and convert them to Lua error messages.
+// Customize as needed for your own exception classes.
+static int wrap_exceptions(lua_State *L, lua_CFunction f)
+{
+ try {
+ return f(L); // Call wrapped function and return result.
+ } catch (const char *s) { // Catch and convert exceptions.
+ lua_pushstring(L, s);
+ } catch (std::exception& e) {
+ lua_pushstring(L, e.what());
+ } catch (...) {
+ lua_pushliteral(L, "caught (...)");
+ }
+ return lua_error(L); // Rethrow as a Lua error.
+}
+
+static int myinit(lua_State *L)
+{
+ ...
+ // Define wrapper function and enable it.
+ lua_pushlightuserdata(L, (void *)wrap_exceptions);
+ luaJIT_setmode(L, -1, LUAJIT_MODE_WRAPCFUNC|LUAJIT_MODE_ON);
+ lua_pop(L, 1);
+ ...
+}
+</pre>
+<p>
+Note that you can only define <b>a single global wrapper function</b>,
+so be careful when using this mechanism from multiple C++ modules.
+Also note that this mechanism is not without overhead.
+</p>
+<br class="flush">
+</div>
+<div id="foot">
+<hr class="hide">
+Copyright &copy; 2005-2018
+<span class="noprint">
+&middot;
+<a href="contact.html">Contact</a>
+</span>
+</div>
+</body>
+</html>
diff --git a/src/3rdparty/LuaJIT-2.0.5/doc/ext_ffi.html b/src/3rdparty/LuaJIT-2.0.5/doc/ext_ffi.html
new file mode 100644
index 0000000..74ca294
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/doc/ext_ffi.html
@@ -0,0 +1,329 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<title>FFI Library</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<meta name="Copyright" content="Copyright (C) 2005-2018">
+<meta name="Language" content="en">
+<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
+<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
+</head>
+<body>
+<div id="site">
+<a href="http://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
+</div>
+<div id="head">
+<h1>FFI Library</h1>
+</div>
+<div id="nav">
+<ul><li>
+<a href="luajit.html">LuaJIT</a>
+<ul><li>
+<a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="install.html">Installation</a>
+</li><li>
+<a href="running.html">Running</a>
+</li></ul>
+</li><li>
+<a href="extensions.html">Extensions</a>
+<ul><li>
+<a class="current" href="ext_ffi.html">FFI Library</a>
+<ul><li>
+<a href="ext_ffi_tutorial.html">FFI Tutorial</a>
+</li><li>
+<a href="ext_ffi_api.html">ffi.* API</a>
+</li><li>
+<a href="ext_ffi_semantics.html">FFI Semantics</a>
+</li></ul>
+</li><li>
+<a href="ext_jit.html">jit.* Library</a>
+</li><li>
+<a href="ext_c_api.html">Lua/C API</a>
+</li></ul>
+</li><li>
+<a href="status.html">Status</a>
+<ul><li>
+<a href="changes.html">Changes</a>
+</li></ul>
+</li><li>
+<a href="faq.html">FAQ</a>
+</li><li>
+<a href="http://luajit.org/performance.html">Performance <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
+</li></ul>
+</div>
+<div id="main">
+<p>
+
+The FFI library allows <b>calling external C&nbsp;functions</b> and
+<b>using C&nbsp;data structures</b> from pure Lua code.
+
+</p>
+<p>
+
+The FFI library largely obviates the need to write tedious manual
+Lua/C bindings in C. No need to learn a separate binding language
+&mdash; <b>it parses plain C&nbsp;declarations!</b> These can be
+cut-n-pasted from C&nbsp;header files or reference manuals. It's up to
+the task of binding large libraries without the need for dealing with
+fragile binding generators.
+
+</p>
+<p>
+The FFI library is tightly integrated into LuaJIT (it's not available
+as a separate module). The code generated by the JIT-compiler for
+accesses to C&nbsp;data structures from Lua code is on par with the
+code a C&nbsp;compiler would generate. Calls to C&nbsp;functions can
+be inlined in JIT-compiled code, unlike calls to functions bound via
+the classic Lua/C API.
+</p>
+<p>
+This page gives a short introduction to the usage of the FFI library.
+<em>Please use the FFI sub-topics in the navigation bar to learn more.</em>
+</p>
+
+<h2 id="call">Motivating Example: Calling External C Functions</h2>
+<p>
+It's really easy to call an external C&nbsp;library function:
+</p>
+<pre class="code mark">
+<span class="codemark">&#9312;
+&#9313;
+
+
+&#9314;</span>local ffi = require("ffi")
+ffi.cdef[[
+<span style="color:#00a000;">int printf(const char *fmt, ...);</span>
+]]
+ffi.C.printf("Hello %s!", "world")
+</pre>
+<p>
+So, let's pick that apart:
+</p>
+<p>
+<span class="mark">&#9312;</span> Load the FFI library.
+</p>
+<p>
+<span class="mark">&#9313;</span> Add a C&nbsp;declaration
+for the function. The part inside the double-brackets (in green) is
+just standard C&nbsp;syntax.
+</p>
+<p>
+<span class="mark">&#9314;</span> Call the named
+C&nbsp;function &mdash; Yes, it's that simple!
+</p>
+<p style="font-size: 8pt;">
+Actually, what goes on behind the scenes is far from simple: <span
+style="color:#4040c0;">&#9314;</span> makes use of the standard
+C&nbsp;library namespace <tt>ffi.C</tt>. Indexing this namespace with
+a symbol name (<tt>"printf"</tt>) automatically binds it to the
+standard C&nbsp;library. The result is a special kind of object which,
+when called, runs the <tt>printf</tt> function. The arguments passed
+to this function are automatically converted from Lua objects to the
+corresponding C&nbsp;types.
+</p>
+<p>
+Ok, so maybe the use of <tt>printf()</tt> wasn't such a spectacular
+example. You could have done that with <tt>io.write()</tt> and
+<tt>string.format()</tt>, too. But you get the idea ...
+</p>
+<p>
+So here's something to pop up a message box on Windows:
+</p>
+<pre class="code">
+local ffi = require("ffi")
+ffi.cdef[[
+<span style="color:#00a000;">int MessageBoxA(void *w, const char *txt, const char *cap, int type);</span>
+]]
+ffi.C.MessageBoxA(nil, "Hello world!", "Test", 0)
+</pre>
+<p>
+Bing! Again, that was far too easy, no?
+</p>
+<p style="font-size: 8pt;">
+Compare this with the effort required to bind that function using the
+classic Lua/C API: create an extra C&nbsp;file, add a C&nbsp;function
+that retrieves and checks the argument types passed from Lua and calls
+the actual C&nbsp;function, add a list of module functions and their
+names, add a <tt>luaopen_*</tt> function and register all module
+functions, compile and link it into a shared library (DLL), move it to
+the proper path, add Lua code that loads the module aaaand ... finally
+call the binding function. Phew!
+</p>
+
+<h2 id="cdata">Motivating Example: Using C Data Structures</h2>
+<p>
+The FFI library allows you to create and access C&nbsp;data
+structures. Of course the main use for this is for interfacing with
+C&nbsp;functions. But they can be used stand-alone, too.
+</p>
+<p>
+Lua is built upon high-level data types. They are flexible, extensible
+and dynamic. That's why we all love Lua so much. Alas, this can be
+inefficient for certain tasks, where you'd really want a low-level
+data type. E.g. a large array of a fixed structure needs to be
+implemented with a big table holding lots of tiny tables. This imposes
+both a substantial memory overhead as well as a performance overhead.
+</p>
+<p>
+Here's a sketch of a library that operates on color images plus a
+simple benchmark. First, the plain Lua version:
+</p>
+<pre class="code">
+local floor = math.floor
+
+local function image_ramp_green(n)
+ local img = {}
+ local f = 255/(n-1)
+ for i=1,n do
+ img[i] = { red = 0, green = floor((i-1)*f), blue = 0, alpha = 255 }
+ end
+ return img
+end
+
+local function image_to_grey(img, n)
+ for i=1,n do
+ local y = floor(0.3*img[i].red + 0.59*img[i].green + 0.11*img[i].blue)
+ img[i].red = y; img[i].green = y; img[i].blue = y
+ end
+end
+
+local N = 400*400
+local img = image_ramp_green(N)
+for i=1,1000 do
+ image_to_grey(img, N)
+end
+</pre>
+<p>
+This creates a table with 160.000 pixels, each of which is a table
+holding four number values in the range of 0-255. First an image with
+a green ramp is created (1D for simplicity), then the image is
+converted to greyscale 1000 times. Yes, that's silly, but I was in
+need of a simple example ...
+</p>
+<p>
+And here's the FFI version. The modified parts have been marked in
+bold:
+</p>
+<pre class="code mark">
+<span class="codemark">&#9312;
+
+
+
+
+
+&#9313;
+
+&#9314;
+&#9315;
+
+
+
+
+
+
+&#9314;
+&#9316;</span><b>local ffi = require("ffi")
+ffi.cdef[[
+</b><span style="color:#00a000;">typedef struct { uint8_t red, green, blue, alpha; } rgba_pixel;</span><b>
+]]</b>
+
+local function image_ramp_green(n)
+ <b>local img = ffi.new("rgba_pixel[?]", n)</b>
+ local f = 255/(n-1)
+ for i=<b>0,n-1</b> do
+ <b>img[i].green = i*f</b>
+ <b>img[i].alpha = 255</b>
+ end
+ return img
+end
+
+local function image_to_grey(img, n)
+ for i=<b>0,n-1</b> do
+ local y = <b>0.3*img[i].red + 0.59*img[i].green + 0.11*img[i].blue</b>
+ img[i].red = y; img[i].green = y; img[i].blue = y
+ end
+end
+
+local N = 400*400
+local img = image_ramp_green(N)
+for i=1,1000 do
+ image_to_grey(img, N)
+end
+</pre>
+<p>
+Ok, so that wasn't too difficult:
+</p>
+<p>
+<span class="mark">&#9312;</span> First, load the FFI
+library and declare the low-level data type. Here we choose a
+<tt>struct</tt> which holds four byte fields, one for each component
+of a 4x8&nbsp;bit RGBA pixel.
+</p>
+<p>
+<span class="mark">&#9313;</span> Creating the data
+structure with <tt>ffi.new()</tt> is straightforward &mdash; the
+<tt>'?'</tt> is a placeholder for the number of elements of a
+variable-length array.
+</p>
+<p>
+<span class="mark">&#9314;</span> C&nbsp;arrays are
+zero-based, so the indexes have to run from <tt>0</tt> to
+<tt>n-1</tt>. One might want to allocate one more element instead to
+simplify converting legacy code.
+</p>
+<p>
+<span class="mark">&#9315;</span> Since <tt>ffi.new()</tt>
+zero-fills the array by default, we only need to set the green and the
+alpha fields.
+</p>
+<p>
+<span class="mark">&#9316;</span> The calls to
+<tt>math.floor()</tt> can be omitted here, because floating-point
+numbers are already truncated towards zero when converting them to an
+integer. This happens implicitly when the number is stored in the
+fields of each pixel.
+</p>
+<p>
+Now let's have a look at the impact of the changes: first, memory
+consumption for the image is down from 22&nbsp;Megabytes to
+640&nbsp;Kilobytes (400*400*4 bytes). That's a factor of 35x less! So,
+yes, tables do have a noticeable overhead. BTW: The original program
+would consume 40&nbsp;Megabytes in plain Lua (on x64).
+</p>
+<p>
+Next, performance: the pure Lua version runs in 9.57 seconds (52.9
+seconds with the Lua interpreter) and the FFI version runs in 0.48
+seconds on my machine (YMMV). That's a factor of 20x faster (110x
+faster than the Lua interpreter).
+</p>
+<p style="font-size: 8pt;">
+The avid reader may notice that converting the pure Lua version over
+to use array indexes for the colors (<tt>[1]</tt> instead of
+<tt>.red</tt>, <tt>[2]</tt> instead of <tt>.green</tt> etc.) ought to
+be more compact and faster. This is certainly true (by a factor of
+~1.7x). Switching to a struct-of-arrays would help, too.
+</p>
+<p style="font-size: 8pt;">
+However the resulting code would be less idiomatic and rather
+error-prone. And it still doesn't get even close to the performance of
+the FFI version of the code. Also, high-level data structures cannot
+be easily passed to other C&nbsp;functions, especially I/O functions,
+without undue conversion penalties.
+</p>
+<br class="flush">
+</div>
+<div id="foot">
+<hr class="hide">
+Copyright &copy; 2005-2018
+<span class="noprint">
+&middot;
+<a href="contact.html">Contact</a>
+</span>
+</div>
+</body>
+</html>
diff --git a/src/3rdparty/LuaJIT-2.0.5/doc/ext_ffi_api.html b/src/3rdparty/LuaJIT-2.0.5/doc/ext_ffi_api.html
new file mode 100644
index 0000000..10f2d02
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/doc/ext_ffi_api.html
@@ -0,0 +1,565 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<title>ffi.* API Functions</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<meta name="Copyright" content="Copyright (C) 2005-2018">
+<meta name="Language" content="en">
+<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
+<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
+<style type="text/css">
+table.abitable { width: 30em; line-height: 1.2; }
+tr.abihead td { font-weight: bold; }
+td.abiparam { font-weight: bold; width: 6em; }
+</style>
+</head>
+<body>
+<div id="site">
+<a href="http://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
+</div>
+<div id="head">
+<h1><tt>ffi.*</tt> API Functions</h1>
+</div>
+<div id="nav">
+<ul><li>
+<a href="luajit.html">LuaJIT</a>
+<ul><li>
+<a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="install.html">Installation</a>
+</li><li>
+<a href="running.html">Running</a>
+</li></ul>
+</li><li>
+<a href="extensions.html">Extensions</a>
+<ul><li>
+<a href="ext_ffi.html">FFI Library</a>
+<ul><li>
+<a href="ext_ffi_tutorial.html">FFI Tutorial</a>
+</li><li>
+<a class="current" href="ext_ffi_api.html">ffi.* API</a>
+</li><li>
+<a href="ext_ffi_semantics.html">FFI Semantics</a>
+</li></ul>
+</li><li>
+<a href="ext_jit.html">jit.* Library</a>
+</li><li>
+<a href="ext_c_api.html">Lua/C API</a>
+</li></ul>
+</li><li>
+<a href="status.html">Status</a>
+<ul><li>
+<a href="changes.html">Changes</a>
+</li></ul>
+</li><li>
+<a href="faq.html">FAQ</a>
+</li><li>
+<a href="http://luajit.org/performance.html">Performance <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
+</li></ul>
+</div>
+<div id="main">
+<p>
+This page describes the API functions provided by the FFI library in
+detail. It's recommended to read through the
+<a href="ext_ffi.html">introduction</a> and the
+<a href="ext_ffi_tutorial.html">FFI tutorial</a> first.
+</p>
+
+<h2 id="glossary">Glossary</h2>
+<ul>
+<li><b>cdecl</b> &mdash; An abstract C&nbsp;type declaration (a Lua
+string).</li>
+<li><b>ctype</b> &mdash; A C&nbsp;type object. This is a special kind of
+<b>cdata</b> returned by <tt>ffi.typeof()</tt>. It serves as a
+<b>cdata</b> <a href="#ffi_new">constructor</a> when called.</li>
+<li><b>cdata</b> &mdash; A C&nbsp;data object. It holds a value of the
+corresponding <b>ctype</b>.</li>
+<li><b>ct</b> &mdash; A C&nbsp;type specification which can be used for
+most of the API functions. Either a <b>cdecl</b>, a <b>ctype</b> or a
+<b>cdata</b> serving as a template type.</li>
+<li><b>cb</b> &mdash; A callback object. This is a C&nbsp;data object
+holding a special function pointer. Calling this function from
+C&nbsp;code runs an associated Lua function.</li>
+<li><b>VLA</b> &mdash; A variable-length array is declared with a
+<tt>?</tt> instead of the number of elements, e.g. <tt>"int[?]"</tt>.
+The number of elements (<tt>nelem</tt>) must be given when it's
+<a href="#ffi_new">created</a>.</li>
+<li><b>VLS</b> &mdash; A variable-length struct is a <tt>struct</tt> C
+type where the last element is a <b>VLA</b>. The same rules for
+declaration and creation apply.</li>
+</ul>
+
+<h2 id="decl">Declaring and Accessing External Symbols</h2>
+<p>
+External symbols must be declared first and can then be accessed by
+indexing a <a href="ext_ffi_semantics.html#clib">C&nbsp;library
+namespace</a>, which automatically binds the symbol to a specific
+library.
+</p>
+
+<h3 id="ffi_cdef"><tt>ffi.cdef(def)</tt></h3>
+<p>
+Adds multiple C&nbsp;declarations for types or external symbols (named
+variables or functions). <tt>def</tt> must be a Lua string. It's
+recommended to use the syntactic sugar for string arguments as
+follows:
+</p>
+<pre class="code">
+ffi.cdef[[
+<span style="color:#00a000;">typedef struct foo { int a, b; } foo_t; // Declare a struct and typedef.
+int dofoo(foo_t *f, int n); /* Declare an external C function. */</span>
+]]
+</pre>
+<p>
+The contents of the string (the part in green above) must be a
+sequence of
+<a href="ext_ffi_semantics.html#clang">C&nbsp;declarations</a>,
+separated by semicolons. The trailing semicolon for a single
+declaration may be omitted.
+</p>
+<p>
+Please note that external symbols are only <em>declared</em>, but they
+are <em>not bound</em> to any specific address, yet. Binding is
+achieved with C&nbsp;library namespaces (see below).
+</p>
+<p style="color: #c00000;">
+C&nbsp;declarations are not passed through a C&nbsp;pre-processor,
+yet. No pre-processor tokens are allowed, except for
+<tt>#pragma&nbsp;pack</tt>. Replace <tt>#define</tt> in existing
+C&nbsp;header files with <tt>enum</tt>, <tt>static&nbsp;const</tt>
+or <tt>typedef</tt> and/or pass the files through an external
+C&nbsp;pre-processor (once). Be careful not to include unneeded or
+redundant declarations from unrelated header files.
+</p>
+
+<h3 id="ffi_C"><tt>ffi.C</tt></h3>
+<p>
+This is the default C&nbsp;library namespace &mdash; note the
+uppercase <tt>'C'</tt>. It binds to the default set of symbols or
+libraries on the target system. These are more or less the same as a
+C&nbsp;compiler would offer by default, without specifying extra link
+libraries.
+</p>
+<p>
+On POSIX systems, this binds to symbols in the default or global
+namespace. This includes all exported symbols from the executable and
+any libraries loaded into the global namespace. This includes at least
+<tt>libc</tt>, <tt>libm</tt>, <tt>libdl</tt> (on Linux),
+<tt>libgcc</tt> (if compiled with GCC), as well as any exported
+symbols from the Lua/C&nbsp;API provided by LuaJIT itself.
+</p>
+<p>
+On Windows systems, this binds to symbols exported from the
+<tt>*.exe</tt>, the <tt>lua51.dll</tt> (i.e. the Lua/C&nbsp;API
+provided by LuaJIT itself), the C&nbsp;runtime library LuaJIT was linked
+with (<tt>msvcrt*.dll</tt>), <tt>kernel32.dll</tt>,
+<tt>user32.dll</tt> and <tt>gdi32.dll</tt>.
+</p>
+
+<h3 id="ffi_load"><tt>clib = ffi.load(name [,global])</tt></h3>
+<p>
+This loads the dynamic library given by <tt>name</tt> and returns
+a new C&nbsp;library namespace which binds to its symbols. On POSIX
+systems, if <tt>global</tt> is <tt>true</tt>, the library symbols are
+loaded into the global namespace, too.
+</p>
+<p>
+If <tt>name</tt> is a path, the library is loaded from this path.
+Otherwise <tt>name</tt> is canonicalized in a system-dependent way and
+searched in the default search path for dynamic libraries:
+</p>
+<p>
+On POSIX systems, if the name contains no dot, the extension
+<tt>.so</tt> is appended. Also, the <tt>lib</tt> prefix is prepended
+if necessary. So <tt>ffi.load("z")</tt> looks for <tt>"libz.so"</tt>
+in the default shared library search path.
+</p>
+<p>
+On Windows systems, if the name contains no dot, the extension
+<tt>.dll</tt> is appended. So <tt>ffi.load("ws2_32")</tt> looks for
+<tt>"ws2_32.dll"</tt> in the default DLL search path.
+</p>
+
+<h2 id="create">Creating cdata Objects</h2>
+<p>
+The following API functions create cdata objects (<tt>type()</tt>
+returns <tt>"cdata"</tt>). All created cdata objects are
+<a href="ext_ffi_semantics.html#gc">garbage collected</a>.
+</p>
+
+<h3 id="ffi_new"><tt>cdata = ffi.new(ct [,nelem] [,init...])<br>
+cdata = <em>ctype</em>([nelem,] [init...])</tt></h3>
+<p>
+Creates a cdata object for the given <tt>ct</tt>. VLA/VLS types
+require the <tt>nelem</tt> argument. The second syntax uses a ctype as
+a constructor and is otherwise fully equivalent.
+</p>
+<p>
+The cdata object is initialized according to the
+<a href="ext_ffi_semantics.html#init">rules for initializers</a>,
+using the optional <tt>init</tt> arguments. Excess initializers cause
+an error.
+</p>
+<p>
+Performance notice: if you want to create many objects of one kind,
+parse the cdecl only once and get its ctype with
+<tt>ffi.typeof()</tt>. Then use the ctype as a constructor repeatedly.
+</p>
+<p style="font-size: 8pt;">
+Please note that an anonymous <tt>struct</tt> declaration implicitly
+creates a new and distinguished ctype every time you use it for
+<tt>ffi.new()</tt>. This is probably <b>not</b> what you want,
+especially if you create more than one cdata object. Different anonymous
+<tt>structs</tt> are not considered assignment-compatible by the
+C&nbsp;standard, even though they may have the same fields! Also, they
+are considered different types by the JIT-compiler, which may cause an
+excessive number of traces. It's strongly suggested to either declare
+a named <tt>struct</tt> or <tt>typedef</tt> with <tt>ffi.cdef()</tt>
+or to create a single ctype object for an anonymous <tt>struct</tt>
+with <tt>ffi.typeof()</tt>.
+</p>
+
+<h3 id="ffi_typeof"><tt>ctype = ffi.typeof(ct)</tt></h3>
+<p>
+Creates a ctype object for the given <tt>ct</tt>.
+</p>
+<p>
+This function is especially useful to parse a cdecl only once and then
+use the resulting ctype object as a <a href="#ffi_new">constructor</a>.
+</p>
+
+<h3 id="ffi_cast"><tt>cdata = ffi.cast(ct, init)</tt></h3>
+<p>
+Creates a scalar cdata object for the given <tt>ct</tt>. The cdata
+object is initialized with <tt>init</tt> using the "cast" variant of
+the <a href="ext_ffi_semantics.html#convert">C&nbsp;type conversion
+rules</a>.
+</p>
+<p>
+This functions is mainly useful to override the pointer compatibility
+checks or to convert pointers to addresses or vice versa.
+</p>
+
+<h3 id="ffi_metatype"><tt>ctype = ffi.metatype(ct, metatable)</tt></h3>
+<p>
+Creates a ctype object for the given <tt>ct</tt> and associates it with
+a metatable. Only <tt>struct</tt>/<tt>union</tt> types, complex numbers
+and vectors are allowed. Other types may be wrapped in a
+<tt>struct</tt>, if needed.
+</p>
+<p>
+The association with a metatable is permanent and cannot be changed
+afterwards. Neither the contents of the <tt>metatable</tt> nor the
+contents of an <tt>__index</tt> table (if any) may be modified
+afterwards. The associated metatable automatically applies to all uses
+of this type, no matter how the objects are created or where they
+originate from. Note that pre-defined operations on types have
+precedence (e.g. declared field names cannot be overriden).
+</p>
+<p>
+All standard Lua metamethods are implemented. These are called directly,
+without shortcuts and on any mix of types. For binary operations, the
+left operand is checked first for a valid ctype metamethod. The
+<tt>__gc</tt> metamethod only applies to <tt>struct</tt>/<tt>union</tt>
+types and performs an implicit <a href="#ffi_gc"><tt>ffi.gc()</tt></a>
+call during creation of an instance.
+</p>
+
+<h3 id="ffi_gc"><tt>cdata = ffi.gc(cdata, finalizer)</tt></h3>
+<p>
+Associates a finalizer with a pointer or aggregate cdata object. The
+cdata object is returned unchanged.
+</p>
+<p>
+This function allows safe integration of unmanaged resources into the
+automatic memory management of the LuaJIT garbage collector. Typical
+usage:
+</p>
+<pre class="code">
+local p = ffi.gc(ffi.C.malloc(n), ffi.C.free)
+...
+p = nil -- Last reference to p is gone.
+-- GC will eventually run finalizer: ffi.C.free(p)
+</pre>
+<p>
+A cdata finalizer works like the <tt>__gc</tt> metamethod for userdata
+objects: when the last reference to a cdata object is gone, the
+associated finalizer is called with the cdata object as an argument. The
+finalizer can be a Lua function or a cdata function or cdata function
+pointer. An existing finalizer can be removed by setting a <tt>nil</tt>
+finalizer, e.g. right before explicitly deleting a resource:
+</p>
+<pre class="code">
+ffi.C.free(ffi.gc(p, nil)) -- Manually free the memory.
+</pre>
+
+<h2 id="info">C&nbsp;Type Information</h2>
+<p>
+The following API functions return information about C&nbsp;types.
+They are most useful for inspecting cdata objects.
+</p>
+
+<h3 id="ffi_sizeof"><tt>size = ffi.sizeof(ct [,nelem])</tt></h3>
+<p>
+Returns the size of <tt>ct</tt> in bytes. Returns <tt>nil</tt> if
+the size is not known (e.g. for <tt>"void"</tt> or function types).
+Requires <tt>nelem</tt> for VLA/VLS types, except for cdata objects.
+</p>
+
+<h3 id="ffi_alignof"><tt>align = ffi.alignof(ct)</tt></h3>
+<p>
+Returns the minimum required alignment for <tt>ct</tt> in bytes.
+</p>
+
+<h3 id="ffi_offsetof"><tt>ofs [,bpos,bsize] = ffi.offsetof(ct, field)</tt></h3>
+<p>
+Returns the offset (in bytes) of <tt>field</tt> relative to the start
+of <tt>ct</tt>, which must be a <tt>struct</tt>. Additionally returns
+the position and the field size (in bits) for bit fields.
+</p>
+
+<h3 id="ffi_istype"><tt>status = ffi.istype(ct, obj)</tt></h3>
+<p>
+Returns <tt>true</tt> if <tt>obj</tt> has the C&nbsp;type given by
+<tt>ct</tt>. Returns <tt>false</tt> otherwise.
+</p>
+<p>
+C&nbsp;type qualifiers (<tt>const</tt> etc.) are ignored. Pointers are
+checked with the standard pointer compatibility rules, but without any
+special treatment for <tt>void&nbsp;*</tt>. If <tt>ct</tt> specifies a
+<tt>struct</tt>/<tt>union</tt>, then a pointer to this type is accepted,
+too. Otherwise the types must match exactly.
+</p>
+<p>
+Note: this function accepts all kinds of Lua objects for the
+<tt>obj</tt> argument, but always returns <tt>false</tt> for non-cdata
+objects.
+</p>
+
+<h2 id="util">Utility Functions</h2>
+
+<h3 id="ffi_errno"><tt>err = ffi.errno([newerr])</tt></h3>
+<p>
+Returns the error number set by the last C&nbsp;function call which
+indicated an error condition. If the optional <tt>newerr</tt> argument
+is present, the error number is set to the new value and the previous
+value is returned.
+</p>
+<p>
+This function offers a portable and OS-independent way to get and set the
+error number. Note that only <em>some</em> C&nbsp;functions set the error
+number. And it's only significant if the function actually indicated an
+error condition (e.g. with a return value of <tt>-1</tt> or
+<tt>NULL</tt>). Otherwise, it may or may not contain any previously set
+value.
+</p>
+<p>
+You're advised to call this function only when needed and as close as
+possible after the return of the related C&nbsp;function. The
+<tt>errno</tt> value is preserved across hooks, memory allocations,
+invocations of the JIT compiler and other internal VM activity. The same
+applies to the value returned by <tt>GetLastError()</tt> on Windows, but
+you need to declare and call it yourself.
+</p>
+
+<h3 id="ffi_string"><tt>str = ffi.string(ptr [,len])</tt></h3>
+<p>
+Creates an interned Lua string from the data pointed to by
+<tt>ptr</tt>.
+</p>
+<p>
+If the optional argument <tt>len</tt> is missing, <tt>ptr</tt> is
+converted to a <tt>"char&nbsp;*"</tt> and the data is assumed to be
+zero-terminated. The length of the string is computed with
+<tt>strlen()</tt>.
+</p>
+<p>
+Otherwise <tt>ptr</tt> is converted to a <tt>"void&nbsp;*"</tt> and
+<tt>len</tt> gives the length of the data. The data may contain
+embedded zeros and need not be byte-oriented (though this may cause
+endianess issues).
+</p>
+<p>
+This function is mainly useful to convert (temporary)
+<tt>"const&nbsp;char&nbsp;*"</tt> pointers returned by
+C&nbsp;functions to Lua strings and store them or pass them to other
+functions expecting a Lua string. The Lua string is an (interned) copy
+of the data and bears no relation to the original data area anymore.
+Lua strings are 8&nbsp;bit clean and may be used to hold arbitrary,
+non-character data.
+</p>
+<p>
+Performance notice: it's faster to pass the length of the string, if
+it's known. E.g. when the length is returned by a C&nbsp;call like
+<tt>sprintf()</tt>.
+</p>
+
+<h3 id="ffi_copy"><tt>ffi.copy(dst, src, len)<br>
+ffi.copy(dst, str)</tt></h3>
+<p>
+Copies the data pointed to by <tt>src</tt> to <tt>dst</tt>.
+<tt>dst</tt> is converted to a <tt>"void&nbsp;*"</tt> and <tt>src</tt>
+is converted to a <tt>"const void&nbsp;*"</tt>.
+</p>
+<p>
+In the first syntax, <tt>len</tt> gives the number of bytes to copy.
+Caveat: if <tt>src</tt> is a Lua string, then <tt>len</tt> must not
+exceed <tt>#src+1</tt>.
+</p>
+<p>
+In the second syntax, the source of the copy must be a Lua string. All
+bytes of the string <em>plus a zero-terminator</em> are copied to
+<tt>dst</tt> (i.e. <tt>#src+1</tt> bytes).
+</p>
+<p>
+Performance notice: <tt>ffi.copy()</tt> may be used as a faster
+(inlinable) replacement for the C&nbsp;library functions
+<tt>memcpy()</tt>, <tt>strcpy()</tt> and <tt>strncpy()</tt>.
+</p>
+
+<h3 id="ffi_fill"><tt>ffi.fill(dst, len [,c])</tt></h3>
+<p>
+Fills the data pointed to by <tt>dst</tt> with <tt>len</tt> constant
+bytes, given by <tt>c</tt>. If <tt>c</tt> is omitted, the data is
+zero-filled.
+</p>
+<p>
+Performance notice: <tt>ffi.fill()</tt> may be used as a faster
+(inlinable) replacement for the C&nbsp;library function
+<tt>memset(dst,&nbsp;c,&nbsp;len)</tt>. Please note the different
+order of arguments!
+</p>
+
+<h2 id="target">Target-specific Information</h2>
+
+<h3 id="ffi_abi"><tt>status = ffi.abi(param)</tt></h3>
+<p>
+Returns <tt>true</tt> if <tt>param</tt> (a Lua string) applies for the
+target ABI (Application Binary Interface). Returns <tt>false</tt>
+otherwise. The following parameters are currently defined:
+</p>
+<table class="abitable">
+<tr class="abihead">
+<td class="abiparam">Parameter</td>
+<td class="abidesc">Description</td>
+</tr>
+<tr class="odd separate">
+<td class="abiparam">32bit</td><td class="abidesc">32 bit architecture</td></tr>
+<tr class="even">
+<td class="abiparam">64bit</td><td class="abidesc">64 bit architecture</td></tr>
+<tr class="odd separate">
+<td class="abiparam">le</td><td class="abidesc">Little-endian architecture</td></tr>
+<tr class="even">
+<td class="abiparam">be</td><td class="abidesc">Big-endian architecture</td></tr>
+<tr class="odd separate">
+<td class="abiparam">fpu</td><td class="abidesc">Target has a hardware FPU</td></tr>
+<tr class="even">
+<td class="abiparam">softfp</td><td class="abidesc">softfp calling conventions</td></tr>
+<tr class="odd">
+<td class="abiparam">hardfp</td><td class="abidesc">hardfp calling conventions</td></tr>
+<tr class="even separate">
+<td class="abiparam">eabi</td><td class="abidesc">EABI variant of the standard ABI</td></tr>
+<tr class="odd">
+<td class="abiparam">win</td><td class="abidesc">Windows variant of the standard ABI</td></tr>
+</table>
+
+<h3 id="ffi_os"><tt>ffi.os</tt></h3>
+<p>
+Contains the target OS name. Same contents as
+<a href="ext_jit.html#jit_os"><tt>jit.os</tt></a>.
+</p>
+
+<h3 id="ffi_arch"><tt>ffi.arch</tt></h3>
+<p>
+Contains the target architecture name. Same contents as
+<a href="ext_jit.html#jit_arch"><tt>jit.arch</tt></a>.
+</p>
+
+<h2 id="callback">Methods for Callbacks</h2>
+<p>
+The C&nbsp;types for <a href="ext_ffi_semantics.html#callback">callbacks</a>
+have some extra methods:
+</p>
+
+<h3 id="callback_free"><tt>cb:free()</tt></h3>
+<p>
+Free the resources associated with a callback. The associated Lua
+function is unanchored and may be garbage collected. The callback
+function pointer is no longer valid and must not be called anymore
+(it may be reused by a subsequently created callback).
+</p>
+
+<h3 id="callback_set"><tt>cb:set(func)</tt></h3>
+<p>
+Associate a new Lua function with a callback. The C&nbsp;type of the
+callback and the callback function pointer are unchanged.
+</p>
+<p>
+This method is useful to dynamically switch the receiver of callbacks
+without creating a new callback each time and registering it again (e.g.
+with a GUI library).
+</p>
+
+<h2 id="extended">Extended Standard Library Functions</h2>
+<p>
+The following standard library functions have been extended to work
+with cdata objects:
+</p>
+
+<h3 id="tonumber"><tt>n = tonumber(cdata)</tt></h3>
+<p>
+Converts a number cdata object to a <tt>double</tt> and returns it as
+a Lua number. This is particularly useful for boxed 64&nbsp;bit
+integer values. Caveat: this conversion may incur a precision loss.
+</p>
+
+<h3 id="tostring"><tt>s = tostring(cdata)</tt></h3>
+<p>
+Returns a string representation of the value of 64&nbsp;bit integers
+(<tt><b>"</b>nnn<b>LL"</b></tt> or <tt><b>"</b>nnn<b>ULL"</b></tt>) or
+complex numbers (<tt><b>"</b>re&plusmn;im<b>i"</b></tt>). Otherwise
+returns a string representation of the C&nbsp;type of a ctype object
+(<tt><b>"ctype&lt;</b>type<b>&gt;"</b></tt>) or a cdata object
+(<tt><b>"cdata&lt;</b>type<b>&gt;:&nbsp;</b>address"</tt>), unless you
+override it with a <tt>__tostring</tt> metamethod (see
+<a href="#ffi_metatype"><tt>ffi.metatype()</tt></a>).
+</p>
+
+<h3 id="pairs"><tt>iter, obj, start = pairs(cdata)<br>
+iter, obj, start = ipairs(cdata)<br></tt></h3>
+<p>
+Calls the <tt>__pairs</tt> or <tt>__ipairs</tt> metamethod of the
+corresponding ctype.
+</p>
+
+<h2 id="literals">Extensions to the Lua Parser</h2>
+<p>
+The parser for Lua source code treats numeric literals with the
+suffixes <tt>LL</tt> or <tt>ULL</tt> as signed or unsigned 64&nbsp;bit
+integers. Case doesn't matter, but uppercase is recommended for
+readability. It handles both decimal (<tt>42LL</tt>) and hexadecimal
+(<tt>0x2aLL</tt>) literals.
+</p>
+<p>
+The imaginary part of complex numbers can be specified by suffixing
+number literals with <tt>i</tt> or <tt>I</tt>, e.g. <tt>12.5i</tt>.
+Caveat: you'll need to use <tt>1i</tt> to get an imaginary part with
+the value one, since <tt>i</tt> itself still refers to a variable
+named <tt>i</tt>.
+</p>
+<br class="flush">
+</div>
+<div id="foot">
+<hr class="hide">
+Copyright &copy; 2005-2018
+<span class="noprint">
+&middot;
+<a href="contact.html">Contact</a>
+</span>
+</div>
+</body>
+</html>
diff --git a/src/3rdparty/LuaJIT-2.0.5/doc/ext_ffi_semantics.html b/src/3rdparty/LuaJIT-2.0.5/doc/ext_ffi_semantics.html
new file mode 100644
index 0000000..218049d
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/doc/ext_ffi_semantics.html
@@ -0,0 +1,1244 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<title>FFI Semantics</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<meta name="Copyright" content="Copyright (C) 2005-2018">
+<meta name="Language" content="en">
+<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
+<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
+<style type="text/css">
+table.convtable { line-height: 1.2; }
+tr.convhead td { font-weight: bold; }
+td.convop { font-style: italic; width: 40%; }
+</style>
+</head>
+<body>
+<div id="site">
+<a href="http://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
+</div>
+<div id="head">
+<h1>FFI Semantics</h1>
+</div>
+<div id="nav">
+<ul><li>
+<a href="luajit.html">LuaJIT</a>
+<ul><li>
+<a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="install.html">Installation</a>
+</li><li>
+<a href="running.html">Running</a>
+</li></ul>
+</li><li>
+<a href="extensions.html">Extensions</a>
+<ul><li>
+<a href="ext_ffi.html">FFI Library</a>
+<ul><li>
+<a href="ext_ffi_tutorial.html">FFI Tutorial</a>
+</li><li>
+<a href="ext_ffi_api.html">ffi.* API</a>
+</li><li>
+<a class="current" href="ext_ffi_semantics.html">FFI Semantics</a>
+</li></ul>
+</li><li>
+<a href="ext_jit.html">jit.* Library</a>
+</li><li>
+<a href="ext_c_api.html">Lua/C API</a>
+</li></ul>
+</li><li>
+<a href="status.html">Status</a>
+<ul><li>
+<a href="changes.html">Changes</a>
+</li></ul>
+</li><li>
+<a href="faq.html">FAQ</a>
+</li><li>
+<a href="http://luajit.org/performance.html">Performance <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
+</li></ul>
+</div>
+<div id="main">
+<p>
+This page describes the detailed semantics underlying the FFI library
+and its interaction with both Lua and C&nbsp;code.
+</p>
+<p>
+Given that the FFI library is designed to interface with C&nbsp;code
+and that declarations can be written in plain C&nbsp;syntax, <b>it
+closely follows the C&nbsp;language semantics</b>, wherever possible.
+Some minor concessions are needed for smoother interoperation with Lua
+language semantics.
+</p>
+<p>
+Please don't be overwhelmed by the contents of this page &mdash; this
+is a reference and you may need to consult it, if in doubt. It doesn't
+hurt to skim this page, but most of the semantics "just work" as you'd
+expect them to work. It should be straightforward to write
+applications using the LuaJIT FFI for developers with a C or C++
+background.
+</p>
+
+<h2 id="clang">C Language Support</h2>
+<p>
+The FFI library has a built-in C&nbsp;parser with a minimal memory
+footprint. It's used by the <a href="ext_ffi_api.html">ffi.* library
+functions</a> to declare C&nbsp;types or external symbols.
+</p>
+<p>
+It's only purpose is to parse C&nbsp;declarations, as found e.g. in
+C&nbsp;header files. Although it does evaluate constant expressions,
+it's <em>not</em> a C&nbsp;compiler. The body of <tt>inline</tt>
+C&nbsp;function definitions is simply ignored.
+</p>
+<p>
+Also, this is <em>not</em> a validating C&nbsp;parser. It expects and
+accepts correctly formed C&nbsp;declarations, but it may choose to
+ignore bad declarations or show rather generic error messages. If in
+doubt, please check the input against your favorite C&nbsp;compiler.
+</p>
+<p>
+The C&nbsp;parser complies to the <b>C99 language standard</b> plus
+the following extensions:
+</p>
+<ul>
+
+<li>The <tt>'\e'</tt> escape in character and string literals.</li>
+
+<li>The C99/C++ boolean type, declared with the keywords <tt>bool</tt>
+or <tt>_Bool</tt>.</li>
+
+<li>Complex numbers, declared with the keywords <tt>complex</tt> or
+<tt>_Complex</tt>.</li>
+
+<li>Two complex number types: <tt>complex</tt> (aka
+<tt>complex&nbsp;double</tt>) and <tt>complex&nbsp;float</tt>.</li>
+
+<li>Vector types, declared with the GCC <tt>mode</tt> or
+<tt>vector_size</tt> attribute.</li>
+
+<li>Unnamed ('transparent') <tt>struct</tt>/<tt>union</tt> fields
+inside a <tt>struct</tt>/<tt>union</tt>.</li>
+
+<li>Incomplete <tt>enum</tt> declarations, handled like incomplete
+<tt>struct</tt> declarations.</li>
+
+<li>Unnamed <tt>enum</tt> fields inside a
+<tt>struct</tt>/<tt>union</tt>. This is similar to a scoped C++
+<tt>enum</tt>, except that declared constants are visible in the
+global namespace, too.</li>
+
+<li>Scoped <tt>static&nbsp;const</tt> declarations inside a
+<tt>struct</tt>/<tt>union</tt> (from C++).</li>
+
+<li>Zero-length arrays (<tt>[0]</tt>), empty
+<tt>struct</tt>/<tt>union</tt>, variable-length arrays (VLA,
+<tt>[?]</tt>) and variable-length structs (VLS, with a trailing
+VLA).</li>
+
+<li>C++ reference types (<tt>int&nbsp;&amp;x</tt>).</li>
+
+<li>Alternate GCC keywords with '<tt>__</tt>', e.g.
+<tt>__const__</tt>.</li>
+
+<li>GCC <tt>__attribute__</tt> with the following attributes:
+<tt>aligned</tt>, <tt>packed</tt>, <tt>mode</tt>,
+<tt>vector_size</tt>, <tt>cdecl</tt>, <tt>fastcall</tt>,
+<tt>stdcall</tt>, <tt>thiscall</tt>.</li>
+
+<li>The GCC <tt>__extension__</tt> keyword and the GCC
+<tt>__alignof__</tt> operator.</li>
+
+<li>GCC <tt>__asm__("symname")</tt> symbol name redirection for
+function declarations.</li>
+
+<li>MSVC keywords for fixed-length types: <tt>__int8</tt>,
+<tt>__int16</tt>, <tt>__int32</tt> and <tt>__int64</tt>.</li>
+
+<li>MSVC <tt>__cdecl</tt>, <tt>__fastcall</tt>, <tt>__stdcall</tt>,
+<tt>__thiscall</tt>, <tt>__ptr32</tt>, <tt>__ptr64</tt>,
+<tt>__declspec(align(n))</tt> and <tt>#pragma&nbsp;pack</tt>.</li>
+
+<li>All other GCC/MSVC-specific attributes are ignored.</li>
+
+</ul>
+<p>
+The following C&nbsp;types are pre-defined by the C&nbsp;parser (like
+a <tt>typedef</tt>, except re-declarations will be ignored):
+</p>
+<ul>
+
+<li>Vararg handling: <tt>va_list</tt>, <tt>__builtin_va_list</tt>,
+<tt>__gnuc_va_list</tt>.</li>
+
+<li>From <tt>&lt;stddef.h&gt;</tt>: <tt>ptrdiff_t</tt>,
+<tt>size_t</tt>, <tt>wchar_t</tt>.</li>
+
+<li>From <tt>&lt;stdint.h&gt;</tt>: <tt>int8_t</tt>, <tt>int16_t</tt>,
+<tt>int32_t</tt>, <tt>int64_t</tt>, <tt>uint8_t</tt>,
+<tt>uint16_t</tt>, <tt>uint32_t</tt>, <tt>uint64_t</tt>,
+<tt>intptr_t</tt>, <tt>uintptr_t</tt>.</li>
+
+</ul>
+<p>
+You're encouraged to use these types in preference to
+compiler-specific extensions or target-dependent standard types.
+E.g. <tt>char</tt> differs in signedness and <tt>long</tt> differs in
+size, depending on the target architecture and platform ABI.
+</p>
+<p>
+The following C&nbsp;features are <b>not</b> supported:
+</p>
+<ul>
+
+<li>A declaration must always have a type specifier; it doesn't
+default to an <tt>int</tt> type.</li>
+
+<li>Old-style empty function declarations (K&amp;R) are not allowed.
+All C&nbsp;functions must have a proper prototype declaration. A
+function declared without parameters (<tt>int&nbsp;foo();</tt>) is
+treated as a function taking zero arguments, like in C++.</li>
+
+<li>The <tt>long double</tt> C&nbsp;type is parsed correctly, but
+there's no support for the related conversions, accesses or arithmetic
+operations.</li>
+
+<li>Wide character strings and character literals are not
+supported.</li>
+
+<li><a href="#status">See below</a> for features that are currently
+not implemented.</li>
+
+</ul>
+
+<h2 id="convert">C Type Conversion Rules</h2>
+
+<h3 id="convert_tolua">Conversions from C&nbsp;types to Lua objects</h3>
+<p>
+These conversion rules apply for <em>read accesses</em> to
+C&nbsp;types: indexing pointers, arrays or
+<tt>struct</tt>/<tt>union</tt> types; reading external variables or
+constant values; retrieving return values from C&nbsp;calls:
+</p>
+<table class="convtable">
+<tr class="convhead">
+<td class="convin">Input</td>
+<td class="convop">Conversion</td>
+<td class="convout">Output</td>
+</tr>
+<tr class="odd separate">
+<td class="convin"><tt>int8_t</tt>, <tt>int16_t</tt></td><td class="convop">&rarr;<sup>sign-ext</sup> <tt>int32_t</tt> &rarr; <tt>double</tt></td><td class="convout">number</td></tr>
+<tr class="even">
+<td class="convin"><tt>uint8_t</tt>, <tt>uint16_t</tt></td><td class="convop">&rarr;<sup>zero-ext</sup> <tt>int32_t</tt> &rarr; <tt>double</tt></td><td class="convout">number</td></tr>
+<tr class="odd">
+<td class="convin"><tt>int32_t</tt>, <tt>uint32_t</tt></td><td class="convop">&rarr; <tt>double</tt></td><td class="convout">number</td></tr>
+<tr class="even">
+<td class="convin"><tt>int64_t</tt>, <tt>uint64_t</tt></td><td class="convop">boxed value</td><td class="convout">64 bit int cdata</td></tr>
+<tr class="odd separate">
+<td class="convin"><tt>double</tt>, <tt>float</tt></td><td class="convop">&rarr; <tt>double</tt></td><td class="convout">number</td></tr>
+<tr class="even separate">
+<td class="convin"><tt>bool</tt></td><td class="convop">0 &rarr; <tt>false</tt>, otherwise <tt>true</tt></td><td class="convout">boolean</td></tr>
+<tr class="odd separate">
+<td class="convin"><tt>enum</tt></td><td class="convop">boxed value</td><td class="convout">enum cdata</td></tr>
+<tr class="even">
+<td class="convin">Complex number</td><td class="convop">boxed value</td><td class="convout">complex cdata</td></tr>
+<tr class="odd">
+<td class="convin">Vector</td><td class="convop">boxed value</td><td class="convout">vector cdata</td></tr>
+<tr class="even">
+<td class="convin">Pointer</td><td class="convop">boxed value</td><td class="convout">pointer cdata</td></tr>
+<tr class="odd separate">
+<td class="convin">Array</td><td class="convop">boxed reference</td><td class="convout">reference cdata</td></tr>
+<tr class="even">
+<td class="convin"><tt>struct</tt>/<tt>union</tt></td><td class="convop">boxed reference</td><td class="convout">reference cdata</td></tr>
+</table>
+<p>
+Bitfields are treated like their underlying type.
+</p>
+<p>
+Reference types are dereferenced <em>before</em> a conversion can take
+place &mdash; the conversion is applied to the C&nbsp;type pointed to
+by the reference.
+</p>
+
+<h3 id="convert_fromlua">Conversions from Lua objects to C&nbsp;types</h3>
+<p>
+These conversion rules apply for <em>write accesses</em> to
+C&nbsp;types: indexing pointers, arrays or
+<tt>struct</tt>/<tt>union</tt> types; initializing cdata objects;
+casts to C&nbsp;types; writing to external variables; passing
+arguments to C&nbsp;calls:
+</p>
+<table class="convtable">
+<tr class="convhead">
+<td class="convin">Input</td>
+<td class="convop">Conversion</td>
+<td class="convout">Output</td>
+</tr>
+<tr class="odd separate">
+<td class="convin">number</td><td class="convop">&rarr;</td><td class="convout"><tt>double</tt></td></tr>
+<tr class="even">
+<td class="convin">boolean</td><td class="convop"><tt>false</tt> &rarr; 0, <tt>true</tt> &rarr; 1</td><td class="convout"><tt>bool</tt></td></tr>
+<tr class="odd separate">
+<td class="convin">nil</td><td class="convop"><tt>NULL</tt> &rarr;</td><td class="convout"><tt>(void *)</tt></td></tr>
+<tr class="even">
+<td class="convin">lightuserdata</td><td class="convop">lightuserdata address &rarr;</td><td class="convout"><tt>(void *)</tt></td></tr>
+<tr class="odd">
+<td class="convin">userdata</td><td class="convop">userdata payload &rarr;</td><td class="convout"><tt>(void *)</tt></td></tr>
+<tr class="even">
+<td class="convin">io.* file</td><td class="convop">get FILE * handle &rarr;</td><td class="convout"><tt>(void *)</tt></td></tr>
+<tr class="odd separate">
+<td class="convin">string</td><td class="convop">match against <tt>enum</tt> constant</td><td class="convout"><tt>enum</tt></td></tr>
+<tr class="even">
+<td class="convin">string</td><td class="convop">copy string data + zero-byte</td><td class="convout"><tt>int8_t[]</tt>, <tt>uint8_t[]</tt></td></tr>
+<tr class="odd">
+<td class="convin">string</td><td class="convop">string data &rarr;</td><td class="convout"><tt>const char[]</tt></td></tr>
+<tr class="even separate">
+<td class="convin">function</td><td class="convop"><a href="#callback">create callback</a> &rarr;</td><td class="convout">C function type</td></tr>
+<tr class="odd separate">
+<td class="convin">table</td><td class="convop"><a href="#init_table">table initializer</a></td><td class="convout">Array</td></tr>
+<tr class="even">
+<td class="convin">table</td><td class="convop"><a href="#init_table">table initializer</a></td><td class="convout"><tt>struct</tt>/<tt>union</tt></td></tr>
+<tr class="odd separate">
+<td class="convin">cdata</td><td class="convop">cdata payload &rarr;</td><td class="convout">C type</td></tr>
+</table>
+<p>
+If the result type of this conversion doesn't match the
+C&nbsp;type of the destination, the
+<a href="#convert_between">conversion rules between C&nbsp;types</a>
+are applied.
+</p>
+<p>
+Reference types are immutable after initialization ("no re-seating of
+references"). For initialization purposes or when passing values to
+reference parameters, they are treated like pointers. Note that unlike
+in C++, there's no way to implement automatic reference generation of
+variables under the Lua language semantics. If you want to call a
+function with a reference parameter, you need to explicitly pass a
+one-element array.
+</p>
+
+<h3 id="convert_between">Conversions between C&nbsp;types</h3>
+<p>
+These conversion rules are more or less the same as the standard
+C&nbsp;conversion rules. Some rules only apply to casts, or require
+pointer or type compatibility:
+</p>
+<table class="convtable">
+<tr class="convhead">
+<td class="convin">Input</td>
+<td class="convop">Conversion</td>
+<td class="convout">Output</td>
+</tr>
+<tr class="odd separate">
+<td class="convin">Signed integer</td><td class="convop">&rarr;<sup>narrow or sign-extend</sup></td><td class="convout">Integer</td></tr>
+<tr class="even">
+<td class="convin">Unsigned integer</td><td class="convop">&rarr;<sup>narrow or zero-extend</sup></td><td class="convout">Integer</td></tr>
+<tr class="odd">
+<td class="convin">Integer</td><td class="convop">&rarr;<sup>round</sup></td><td class="convout"><tt>double</tt>, <tt>float</tt></td></tr>
+<tr class="even">
+<td class="convin"><tt>double</tt>, <tt>float</tt></td><td class="convop">&rarr;<sup>trunc</sup> <tt>int32_t</tt> &rarr;<sup>narrow</sup></td><td class="convout"><tt>(u)int8_t</tt>, <tt>(u)int16_t</tt></td></tr>
+<tr class="odd">
+<td class="convin"><tt>double</tt>, <tt>float</tt></td><td class="convop">&rarr;<sup>trunc</sup></td><td class="convout"><tt>(u)int32_t</tt>, <tt>(u)int64_t</tt></td></tr>
+<tr class="even">
+<td class="convin"><tt>double</tt>, <tt>float</tt></td><td class="convop">&rarr;<sup>round</sup></td><td class="convout"><tt>float</tt>, <tt>double</tt></td></tr>
+<tr class="odd separate">
+<td class="convin">Number</td><td class="convop">n == 0 &rarr; 0, otherwise 1</td><td class="convout"><tt>bool</tt></td></tr>
+<tr class="even">
+<td class="convin"><tt>bool</tt></td><td class="convop"><tt>false</tt> &rarr; 0, <tt>true</tt> &rarr; 1</td><td class="convout">Number</td></tr>
+<tr class="odd separate">
+<td class="convin">Complex number</td><td class="convop">convert real part</td><td class="convout">Number</td></tr>
+<tr class="even">
+<td class="convin">Number</td><td class="convop">convert real part, imag = 0</td><td class="convout">Complex number</td></tr>
+<tr class="odd">
+<td class="convin">Complex number</td><td class="convop">convert real and imag part</td><td class="convout">Complex number</td></tr>
+<tr class="even separate">
+<td class="convin">Number</td><td class="convop">convert scalar and replicate</td><td class="convout">Vector</td></tr>
+<tr class="odd">
+<td class="convin">Vector</td><td class="convop">copy (same size)</td><td class="convout">Vector</td></tr>
+<tr class="even separate">
+<td class="convin"><tt>struct</tt>/<tt>union</tt></td><td class="convop">take base address (compat)</td><td class="convout">Pointer</td></tr>
+<tr class="odd">
+<td class="convin">Array</td><td class="convop">take base address (compat)</td><td class="convout">Pointer</td></tr>
+<tr class="even">
+<td class="convin">Function</td><td class="convop">take function address</td><td class="convout">Function pointer</td></tr>
+<tr class="odd separate">
+<td class="convin">Number</td><td class="convop">convert via <tt>uintptr_t</tt> (cast)</td><td class="convout">Pointer</td></tr>
+<tr class="even">
+<td class="convin">Pointer</td><td class="convop">convert address (compat/cast)</td><td class="convout">Pointer</td></tr>
+<tr class="odd">
+<td class="convin">Pointer</td><td class="convop">convert address (cast)</td><td class="convout">Integer</td></tr>
+<tr class="even">
+<td class="convin">Array</td><td class="convop">convert base address (cast)</td><td class="convout">Integer</td></tr>
+<tr class="odd separate">
+<td class="convin">Array</td><td class="convop">copy (compat)</td><td class="convout">Array</td></tr>
+<tr class="even">
+<td class="convin"><tt>struct</tt>/<tt>union</tt></td><td class="convop">copy (identical type)</td><td class="convout"><tt>struct</tt>/<tt>union</tt></td></tr>
+</table>
+<p>
+Bitfields or <tt>enum</tt> types are treated like their underlying
+type.
+</p>
+<p>
+Conversions not listed above will raise an error. E.g. it's not
+possible to convert a pointer to a complex number or vice versa.
+</p>
+
+<h3 id="convert_vararg">Conversions for vararg C&nbsp;function arguments</h3>
+<p>
+The following default conversion rules apply when passing Lua objects
+to the variable argument part of vararg C&nbsp;functions:
+</p>
+<table class="convtable">
+<tr class="convhead">
+<td class="convin">Input</td>
+<td class="convop">Conversion</td>
+<td class="convout">Output</td>
+</tr>
+<tr class="odd separate">
+<td class="convin">number</td><td class="convop">&rarr;</td><td class="convout"><tt>double</tt></td></tr>
+<tr class="even">
+<td class="convin">boolean</td><td class="convop"><tt>false</tt> &rarr; 0, <tt>true</tt> &rarr; 1</td><td class="convout"><tt>bool</tt></td></tr>
+<tr class="odd separate">
+<td class="convin">nil</td><td class="convop"><tt>NULL</tt> &rarr;</td><td class="convout"><tt>(void *)</tt></td></tr>
+<tr class="even">
+<td class="convin">userdata</td><td class="convop">userdata payload &rarr;</td><td class="convout"><tt>(void *)</tt></td></tr>
+<tr class="odd">
+<td class="convin">lightuserdata</td><td class="convop">lightuserdata address &rarr;</td><td class="convout"><tt>(void *)</tt></td></tr>
+<tr class="even separate">
+<td class="convin">string</td><td class="convop">string data &rarr;</td><td class="convout"><tt>const char *</tt></td></tr>
+<tr class="odd separate">
+<td class="convin"><tt>float</tt> cdata</td><td class="convop">&rarr;</td><td class="convout"><tt>double</tt></td></tr>
+<tr class="even">
+<td class="convin">Array cdata</td><td class="convop">take base address</td><td class="convout">Element pointer</td></tr>
+<tr class="odd">
+<td class="convin"><tt>struct</tt>/<tt>union</tt> cdata</td><td class="convop">take base address</td><td class="convout"><tt>struct</tt>/<tt>union</tt> pointer</td></tr>
+<tr class="even">
+<td class="convin">Function cdata</td><td class="convop">take function address</td><td class="convout">Function pointer</td></tr>
+<tr class="odd">
+<td class="convin">Any other cdata</td><td class="convop">no conversion</td><td class="convout">C type</td></tr>
+</table>
+<p>
+To pass a Lua object, other than a cdata object, as a specific type,
+you need to override the conversion rules: create a temporary cdata
+object with a constructor or a cast and initialize it with the value
+to pass:
+</p>
+<p>
+Assuming <tt>x</tt> is a Lua number, here's how to pass it as an
+integer to a vararg function:
+</p>
+<pre class="code">
+ffi.cdef[[
+int printf(const char *fmt, ...);
+]]
+ffi.C.printf("integer value: %d\n", ffi.new("int", x))
+</pre>
+<p>
+If you don't do this, the default Lua number &rarr; <tt>double</tt>
+conversion rule applies. A vararg C&nbsp;function expecting an integer
+will see a garbled or uninitialized value.
+</p>
+
+<h2 id="init">Initializers</h2>
+<p>
+Creating a cdata object with
+<a href="ext_ffi_api.html#ffi_new"><tt>ffi.new()</tt></a> or the
+equivalent constructor syntax always initializes its contents, too.
+Different rules apply, depending on the number of optional
+initializers and the C&nbsp;types involved:
+</p>
+<ul>
+<li>If no initializers are given, the object is filled with zero bytes.</li>
+
+<li>Scalar types (numbers and pointers) accept a single initializer.
+The Lua object is <a href="#convert_fromlua">converted to the scalar
+C&nbsp;type</a>.</li>
+
+<li>Valarrays (complex numbers and vectors) are treated like scalars
+when a single initializer is given. Otherwise they are treated like
+regular arrays.</li>
+
+<li>Aggregate types (arrays and structs) accept either a single cdata
+initializer of the same type (copy constructor), a single
+<a href="#init_table">table initializer</a>, or a flat list of
+initializers.</li>
+
+<li>The elements of an array are initialized, starting at index zero.
+If a single initializer is given for an array, it's repeated for all
+remaining elements. This doesn't happen if two or more initializers
+are given: all remaining uninitialized elements are filled with zero
+bytes.</li>
+
+<li>Byte arrays may also be initialized with a Lua string. This copies
+the whole string plus a terminating zero-byte. The copy stops early only
+if the array has a known, fixed size.</li>
+
+<li>The fields of a <tt>struct</tt> are initialized in the order of
+their declaration. Uninitialized fields are filled with zero
+bytes.</li>
+
+<li>Only the first field of a <tt>union</tt> can be initialized with a
+flat initializer.</li>
+
+<li>Elements or fields which are aggregates themselves are initialized
+with a <em>single</em> initializer, but this may be a table
+initializer or a compatible aggregate.</li>
+
+<li>Excess initializers cause an error.</li>
+
+</ul>
+
+<h2 id="init_table">Table Initializers</h2>
+<p>
+The following rules apply if a Lua table is used to initialize an
+Array or a <tt>struct</tt>/<tt>union</tt>:
+</p>
+<ul>
+
+<li>If the table index <tt>[0]</tt> is non-<tt>nil</tt>, then the
+table is assumed to be zero-based. Otherwise it's assumed to be
+one-based.</li>
+
+<li>Array elements, starting at index zero, are initialized one-by-one
+with the consecutive table elements, starting at either index
+<tt>[0]</tt> or <tt>[1]</tt>. This process stops at the first
+<tt>nil</tt> table element.</li>
+
+<li>If exactly one array element was initialized, it's repeated for
+all the remaining elements. Otherwise all remaining uninitialized
+elements are filled with zero bytes.</li>
+
+<li>The above logic only applies to arrays with a known fixed size.
+A VLA is only initialized with the element(s) given in the table.
+Depending on the use case, you may need to explicitly add a
+<tt>NULL</tt> or <tt>0</tt> terminator to a VLA.</li>
+
+<li>A <tt>struct</tt>/<tt>union</tt> can be initialized in the
+order of the declaration of its fields. Each field is initialized with
+consecutive table elements, starting at either index <tt>[0]</tt>
+or <tt>[1]</tt>. This process stops at the first <tt>nil</tt> table
+element.</li>
+
+<li>Otherwise, if neither index <tt>[0]</tt> nor <tt>[1]</tt> is present,
+a <tt>struct</tt>/<tt>union</tt> is initialized by looking up each field
+name (as a string key) in the table. Each non-<tt>nil</tt> value is
+used to initialize the corresponding field.</li>
+
+<li>Uninitialized fields of a <tt>struct</tt> are filled with zero
+bytes, except for the trailing VLA of a VLS.</li>
+
+<li>Initialization of a <tt>union</tt> stops after one field has been
+initialized. If no field has been initialized, the <tt>union</tt> is
+filled with zero bytes.</li>
+
+<li>Elements or fields which are aggregates themselves are initialized
+with a <em>single</em> initializer, but this may be a nested table
+initializer (or a compatible aggregate).</li>
+
+<li>Excess initializers for an array cause an error. Excess
+initializers for a <tt>struct</tt>/<tt>union</tt> are ignored.
+Unrelated table entries are ignored, too.</li>
+
+</ul>
+<p>
+Example:
+</p>
+<pre class="code">
+local ffi = require("ffi")
+
+ffi.cdef[[
+struct foo { int a, b; };
+union bar { int i; double d; };
+struct nested { int x; struct foo y; };
+]]
+
+ffi.new("int[3]", {}) --> 0, 0, 0
+ffi.new("int[3]", {1}) --> 1, 1, 1
+ffi.new("int[3]", {1,2}) --> 1, 2, 0
+ffi.new("int[3]", {1,2,3}) --> 1, 2, 3
+ffi.new("int[3]", {[0]=1}) --> 1, 1, 1
+ffi.new("int[3]", {[0]=1,2}) --> 1, 2, 0
+ffi.new("int[3]", {[0]=1,2,3}) --> 1, 2, 3
+ffi.new("int[3]", {[0]=1,2,3,4}) --> error: too many initializers
+
+ffi.new("struct foo", {}) --> a = 0, b = 0
+ffi.new("struct foo", {1}) --> a = 1, b = 0
+ffi.new("struct foo", {1,2}) --> a = 1, b = 2
+ffi.new("struct foo", {[0]=1,2}) --> a = 1, b = 2
+ffi.new("struct foo", {b=2}) --> a = 0, b = 2
+ffi.new("struct foo", {a=1,b=2,c=3}) --> a = 1, b = 2 'c' is ignored
+
+ffi.new("union bar", {}) --> i = 0, d = 0.0
+ffi.new("union bar", {1}) --> i = 1, d = ?
+ffi.new("union bar", {[0]=1,2}) --> i = 1, d = ? '2' is ignored
+ffi.new("union bar", {d=2}) --> i = ?, d = 2.0
+
+ffi.new("struct nested", {1,{2,3}}) --> x = 1, y.a = 2, y.b = 3
+ffi.new("struct nested", {x=1,y={2,3}}) --> x = 1, y.a = 2, y.b = 3
+</pre>
+
+<h2 id="cdata_ops">Operations on cdata Objects</h2>
+<p>
+All of the standard Lua operators can be applied to cdata objects or a
+mix of a cdata object and another Lua object. The following list shows
+the pre-defined operations.
+</p>
+<p>
+Reference types are dereferenced <em>before</em> performing each of
+the operations below &mdash; the operation is applied to the
+C&nbsp;type pointed to by the reference.
+</p>
+<p>
+The pre-defined operations are always tried first before deferring to a
+metamethod or index table (if any) for the corresponding ctype (except
+for <tt>__new</tt>). An error is raised if the metamethod lookup or
+index table lookup fails.
+</p>
+
+<h3 id="cdata_array">Indexing a cdata object</h3>
+<ul>
+
+<li><b>Indexing a pointer/array</b>: a cdata pointer/array can be
+indexed by a cdata number or a Lua number. The element address is
+computed as the base address plus the number value multiplied by the
+element size in bytes. A read access loads the element value and
+<a href="#convert_tolua">converts it to a Lua object</a>. A write
+access <a href="#convert_fromlua">converts a Lua object to the element
+type</a> and stores the converted value to the element. An error is
+raised if the element size is undefined or a write access to a
+constant element is attempted.</li>
+
+<li><b>Dereferencing a <tt>struct</tt>/<tt>union</tt> field</b>: a
+cdata <tt>struct</tt>/<tt>union</tt> or a pointer to a
+<tt>struct</tt>/<tt>union</tt> can be dereferenced by a string key,
+giving the field name. The field address is computed as the base
+address plus the relative offset of the field. A read access loads the
+field value and <a href="#convert_tolua">converts it to a Lua
+object</a>. A write access <a href="#convert_fromlua">converts a Lua
+object to the field type</a> and stores the converted value to the
+field. An error is raised if a write access to a constant
+<tt>struct</tt>/<tt>union</tt> or a constant field is attempted.
+Scoped enum constants or static constants are treated like a constant
+field.</li>
+
+<li><b>Indexing a complex number</b>: a complex number can be indexed
+either by a cdata number or a Lua number with the values 0 or 1, or by
+the strings <tt>"re"</tt> or <tt>"im"</tt>. A read access loads the
+real part (<tt>[0]</tt>, <tt>.re</tt>) or the imaginary part
+(<tt>[1]</tt>, <tt>.im</tt>) part of a complex number and
+<a href="#convert_tolua">converts it to a Lua number</a>. The
+sub-parts of a complex number are immutable &mdash; assigning to an
+index of a complex number raises an error. Accessing out-of-bound
+indexes returns unspecified results, but is guaranteed not to trigger
+memory access violations.</li>
+
+<li><b>Indexing a vector</b>: a vector is treated like an array for
+indexing purposes, except the vector elements are immutable &mdash;
+assigning to an index of a vector raises an error.</li>
+
+</ul>
+<p>
+A ctype object can be indexed with a string key, too. The only
+pre-defined operation is reading scoped constants of
+<tt>struct</tt>/<tt>union</tt> types. All other accesses defer
+to the corresponding metamethods or index tables (if any).
+</p>
+<p>
+Note: since there's (deliberately) no address-of operator, a cdata
+object holding a value type is effectively immutable after
+initialization. The JIT compiler benefits from this fact when applying
+certain optimizations.
+</p>
+<p>
+As a consequence, the <em>elements</em> of complex numbers and
+vectors are immutable. But the elements of an aggregate holding these
+types <em>may</em> be modified of course. I.e. you cannot assign to
+<tt>foo.c.im</tt>, but you can assign a (newly created) complex number
+to <tt>foo.c</tt>.
+</p>
+<p>
+The JIT compiler implements strict aliasing rules: accesses to different
+types do <b>not</b> alias, except for differences in signedness (this
+applies even to <tt>char</tt> pointers, unlike C99). Type punning
+through unions is explicitly detected and allowed.
+</p>
+
+<h3 id="cdata_call">Calling a cdata object</h3>
+<ul>
+
+<li><b>Constructor</b>: a ctype object can be called and used as a
+<a href="ext_ffi_api.html#ffi_new">constructor</a>. This is equivalent
+to <tt>ffi.new(ct, ...)</tt>, unless a <tt>__new</tt> metamethod is
+defined. The <tt>__new</tt> metamethod is called with the ctype object
+plus any other arguments passed to the contructor. Note that you have to
+use <tt>ffi.new</tt> inside of it, since calling <tt>ct(...)</tt> would
+cause infinite recursion.</li>
+
+<li><b>C&nbsp;function call</b>: a cdata function or cdata function
+pointer can be called. The passed arguments are
+<a href="#convert_fromlua">converted to the C&nbsp;types</a> of the
+parameters given by the function declaration. Arguments passed to the
+variable argument part of vararg C&nbsp;function use
+<a href="#convert_vararg">special conversion rules</a>. This
+C&nbsp;function is called and the return value (if any) is
+<a href="#convert_tolua">converted to a Lua object</a>.<br>
+On Windows/x86 systems, <tt>__stdcall</tt> functions are automatically
+detected and a function declared as <tt>__cdecl</tt> (the default) is
+silently fixed up after the first call.</li>
+
+</ul>
+
+<h3 id="cdata_arith">Arithmetic on cdata objects</h3>
+<ul>
+
+<li><b>Pointer arithmetic</b>: a cdata pointer/array and a cdata
+number or a Lua number can be added or subtracted. The number must be
+on the right hand side for a subtraction. The result is a pointer of
+the same type with an address plus or minus the number value
+multiplied by the element size in bytes. An error is raised if the
+element size is undefined.</li>
+
+<li><b>Pointer difference</b>: two compatible cdata pointers/arrays
+can be subtracted. The result is the difference between their
+addresses, divided by the element size in bytes. An error is raised if
+the element size is undefined or zero.</li>
+
+<li><b>64&nbsp;bit integer arithmetic</b>: the standard arithmetic
+operators (<tt>+&nbsp;-&nbsp;*&nbsp;/&nbsp;%&nbsp;^</tt> and unary
+minus) can be applied to two cdata numbers, or a cdata number and a
+Lua number. If one of them is an <tt>uint64_t</tt>, the other side is
+converted to an <tt>uint64_t</tt> and an unsigned arithmetic operation
+is performed. Otherwise both sides are converted to an
+<tt>int64_t</tt> and a signed arithmetic operation is performed. The
+result is a boxed 64&nbsp;bit cdata object.<br>
+
+If one of the operands is an <tt>enum</tt> and the other operand is a
+string, the string is converted to the value of a matching <tt>enum</tt>
+constant before the above conversion.<br>
+
+These rules ensure that 64&nbsp;bit integers are "sticky". Any
+expression involving at least one 64&nbsp;bit integer operand results
+in another one. The undefined cases for the division, modulo and power
+operators return <tt>2LL&nbsp;^&nbsp;63</tt> or
+<tt>2ULL&nbsp;^&nbsp;63</tt>.<br>
+
+You'll have to explicitly convert a 64&nbsp;bit integer to a Lua
+number (e.g. for regular floating-point calculations) with
+<tt>tonumber()</tt>. But note this may incur a precision loss.</li>
+
+</ul>
+
+<h3 id="cdata_comp">Comparisons of cdata objects</h3>
+<ul>
+
+<li><b>Pointer comparison</b>: two compatible cdata pointers/arrays
+can be compared. The result is the same as an unsigned comparison of
+their addresses. <tt>nil</tt> is treated like a <tt>NULL</tt> pointer,
+which is compatible with any other pointer type.</li>
+
+<li><b>64&nbsp;bit integer comparison</b>: two cdata numbers, or a
+cdata number and a Lua number can be compared with each other. If one
+of them is an <tt>uint64_t</tt>, the other side is converted to an
+<tt>uint64_t</tt> and an unsigned comparison is performed. Otherwise
+both sides are converted to an <tt>int64_t</tt> and a signed
+comparison is performed.<br>
+
+If one of the operands is an <tt>enum</tt> and the other operand is a
+string, the string is converted to the value of a matching <tt>enum</tt>
+constant before the above conversion.<br>
+
+<li><b>Comparisons for equality/inequality</b> never raise an error.
+Even incompatible pointers can be compared for equality by address. Any
+other incompatible comparison (also with non-cdata objects) treats the
+two sides as unequal.</li>
+
+</ul>
+
+<h3 id="cdata_key">cdata objects as table keys</h3>
+<p>
+Lua tables may be indexed by cdata objects, but this doesn't provide
+any useful semantics &mdash; <b>cdata objects are unsuitable as table
+keys!</b>
+</p>
+<p>
+A cdata object is treated like any other garbage-collected object and
+is hashed and compared by its address for table indexing. Since
+there's no interning for cdata value types, the same value may be
+boxed in different cdata objects with different addresses. Thus
+<tt>t[1LL+1LL]</tt> and <tt>t[2LL]</tt> usually <b>do not</b> point to
+the same hash slot and they certainly <b>do not</b> point to the same
+hash slot as <tt>t[2]</tt>.
+</p>
+<p>
+It would seriously drive up implementation complexity and slow down
+the common case, if one were to add extra handling for by-value
+hashing and comparisons to Lua tables. Given the ubiquity of their use
+inside the VM, this is not acceptable.
+</p>
+<p>
+There are three viable alternatives, if you really need to use cdata
+objects as keys:
+</p>
+<ul>
+
+<li>If you can get by with the precision of Lua numbers
+(52&nbsp;bits), then use <tt>tonumber()</tt> on a cdata number or
+combine multiple fields of a cdata aggregate to a Lua number. Then use
+the resulting Lua number as a key when indexing tables.<br>
+One obvious benefit: <tt>t[tonumber(2LL)]</tt> <b>does</b> point to
+the same slot as <tt>t[2]</tt>.</li>
+
+<li>Otherwise use either <tt>tostring()</tt> on 64&nbsp;bit integers
+or complex numbers or combine multiple fields of a cdata aggregate to
+a Lua string (e.g. with
+<a href="ext_ffi_api.html#ffi_string"><tt>ffi.string()</tt></a>). Then
+use the resulting Lua string as a key when indexing tables.</li>
+
+<li>Create your own specialized hash table implementation using the
+C&nbsp;types provided by the FFI library, just like you would in
+C&nbsp;code. Ultimately this may give much better performance than the
+other alternatives or what a generic by-value hash table could
+possibly provide.</li>
+
+</ul>
+
+<h2 id="param">Parameterized Types</h2>
+<p>
+To facilitate some abstractions, the two functions
+<a href="ext_ffi_api.html#ffi_typeof"><tt>ffi.typeof</tt></a> and
+<a href="ext_ffi_api.html#ffi_cdef"><tt>ffi.cdef</tt></a> support
+parameterized types in C&nbsp;declarations. Note: none of the other API
+functions taking a cdecl allow this.
+</p>
+<p>
+Any place you can write a <b><tt>typedef</tt> name</b>, an
+<b>identifier</b> or a <b>number</b> in a declaration, you can write
+<tt>$</tt> (the dollar sign) instead. These placeholders are replaced in
+order of appearance with the arguments following the cdecl string:
+</p>
+<pre class="code">
+-- Declare a struct with a parameterized field type and name:
+ffi.cdef([[
+typedef struct { $ $; } foo_t;
+]], type1, name1)
+
+-- Anonymous struct with dynamic names:
+local bar_t = ffi.typeof("struct { int $, $; }", name1, name2)
+-- Derived pointer type:
+local bar_ptr_t = ffi.typeof("$ *", bar_t)
+
+-- Parameterized dimensions work even where a VLA won't work:
+local matrix_t = ffi.typeof("uint8_t[$][$]", width, height)
+</pre>
+<p>
+Caveat: this is <em>not</em> simple text substitution! A passed ctype or
+cdata object is treated like the underlying type, a passed string is
+considered an identifier and a number is considered a number. You must
+not mix this up: e.g. passing <tt>"int"</tt> as a string doesn't work in
+place of a type, you'd need to use <tt>ffi.typeof("int")</tt> instead.
+</p>
+<p>
+The main use for parameterized types are libraries implementing abstract
+data types
+(<a href="https://www.freelists.org/post/luajit/ffi-type-of-pointer-to,8">example</a>),
+similar to what can be achieved with C++ template metaprogramming.
+Another use case are derived types of anonymous structs, which avoids
+pollution of the global struct namespace.
+</p>
+<p>
+Please note that parameterized types are a nice tool and indispensable
+for certain use cases. But you'll want to use them sparingly in regular
+code, e.g. when all types are actually fixed.
+</p>
+
+<h2 id="gc">Garbage Collection of cdata Objects</h2>
+<p>
+All explicitly (<tt>ffi.new()</tt>, <tt>ffi.cast()</tt> etc.) or
+implicitly (accessors) created cdata objects are garbage collected.
+You need to ensure to retain valid references to cdata objects
+somewhere on a Lua stack, an upvalue or in a Lua table while they are
+still in use. Once the last reference to a cdata object is gone, the
+garbage collector will automatically free the memory used by it (at
+the end of the next GC cycle).
+</p>
+<p>
+Please note that pointers themselves are cdata objects, however they
+are <b>not</b> followed by the garbage collector. So e.g. if you
+assign a cdata array to a pointer, you must keep the cdata object
+holding the array alive as long as the pointer is still in use:
+</p>
+<pre class="code">
+ffi.cdef[[
+typedef struct { int *a; } foo_t;
+]]
+
+local s = ffi.new("foo_t", ffi.new("int[10]")) -- <span style="color:#c00000;">WRONG!</span>
+
+local a = ffi.new("int[10]") -- <span style="color:#00a000;">OK</span>
+local s = ffi.new("foo_t", a)
+-- Now do something with 's', but keep 'a' alive until you're done.
+</pre>
+<p>
+Similar rules apply for Lua strings which are implicitly converted to
+<tt>"const&nbsp;char&nbsp;*"</tt>: the string object itself must be
+referenced somewhere or it'll be garbage collected eventually. The
+pointer will then point to stale data, which may have already been
+overwritten. Note that <em>string literals</em> are automatically kept
+alive as long as the function containing it (actually its prototype)
+is not garbage collected.
+</p>
+<p>
+Objects which are passed as an argument to an external C&nbsp;function
+are kept alive until the call returns. So it's generally safe to
+create temporary cdata objects in argument lists. This is a common
+idiom for <a href="#convert_vararg">passing specific C&nbsp;types to
+vararg functions</a>.
+</p>
+<p>
+Memory areas returned by C functions (e.g. from <tt>malloc()</tt>)
+must be manually managed, of course (or use
+<a href="ext_ffi_api.html#ffi_gc"><tt>ffi.gc()</tt></a>). Pointers to
+cdata objects are indistinguishable from pointers returned by C
+functions (which is one of the reasons why the GC cannot follow them).
+</p>
+
+<h2 id="callback">Callbacks</h2>
+<p>
+The LuaJIT FFI automatically generates special callback functions
+whenever a Lua function is converted to a C&nbsp;function pointer. This
+associates the generated callback function pointer with the C&nbsp;type
+of the function pointer and the Lua function object (closure).
+</p>
+<p>
+This can happen implicitly due to the usual conversions, e.g. when
+passing a Lua function to a function pointer argument. Or you can use
+<tt>ffi.cast()</tt> to explicitly cast a Lua function to a
+C&nbsp;function pointer.
+</p>
+<p>
+Currently only certain C&nbsp;function types can be used as callback
+functions. Neither C&nbsp;vararg functions nor functions with
+pass-by-value aggregate argument or result types are supported. There
+are no restrictions for the kind of Lua functions that can be called
+from the callback &mdash; no checks for the proper number of arguments
+are made. The return value of the Lua function will be converted to the
+result type and an error will be thrown for invalid conversions.
+</p>
+<p>
+It's allowed to throw errors across a callback invocation, but it's not
+advisable in general. Do this only if you know the C&nbsp;function, that
+called the callback, copes with the forced stack unwinding and doesn't
+leak resources.
+</p>
+<p>
+One thing that's not allowed, is to let an FFI call into a C&nbsp;function
+get JIT-compiled, which in turn calls a callback, calling into Lua again.
+Usually this attempt is caught by the interpreter first and the
+C&nbsp;function is blacklisted for compilation.
+</p>
+<p>
+However, this heuristic may fail under specific circumstances: e.g. a
+message polling function might not run Lua callbacks right away and the call
+gets JIT-compiled. If it later happens to call back into Lua (e.g. a rarely
+invoked error callback), you'll get a VM PANIC with the message
+<tt>"bad callback"</tt>. Then you'll need to manually turn off
+JIT-compilation with
+<a href="ext_jit.html#jit_onoff_func"><tt>jit.off()</tt></a> for the
+surrounding Lua function that invokes such a message polling function (or
+similar).
+</p>
+
+<h3 id="callback_resources">Callback resource handling</h3>
+<p>
+Callbacks take up resources &mdash; you can only have a limited number
+of them at the same time (500&nbsp;-&nbsp;1000, depending on the
+architecture). The associated Lua functions are anchored to prevent
+garbage collection, too.
+</p>
+<p>
+<b>Callbacks due to implicit conversions are permanent!</b> There is no
+way to guess their lifetime, since the C&nbsp;side might store the
+function pointer for later use (typical for GUI toolkits). The associated
+resources cannot be reclaimed until termination:
+</p>
+<pre class="code">
+ffi.cdef[[
+typedef int (__stdcall *WNDENUMPROC)(void *hwnd, intptr_t l);
+int EnumWindows(WNDENUMPROC func, intptr_t l);
+]]
+
+-- Implicit conversion to a callback via function pointer argument.
+local count = 0
+ffi.C.EnumWindows(function(hwnd, l)
+ count = count + 1
+ return true
+end, 0)
+-- The callback is permanent and its resources cannot be reclaimed!
+-- Ok, so this may not be a problem, if you do this only once.
+</pre>
+<p>
+Note: this example shows that you <em>must</em> properly declare
+<tt>__stdcall</tt> callbacks on Windows/x86 systems. The calling
+convention cannot be automatically detected, unlike for
+<tt>__stdcall</tt> calls <em>to</em> Windows functions.
+</p>
+<p>
+For some use cases it's necessary to free up the resources or to
+dynamically redirect callbacks. Use an explicit cast to a
+C&nbsp;function pointer and keep the resulting cdata object. Then use
+the <a href="ext_ffi_api.html#callback_free"><tt>cb:free()</tt></a>
+or <a href="ext_ffi_api.html#callback_set"><tt>cb:set()</tt></a> methods
+on the cdata object:
+</p>
+<pre class="code">
+-- Explicitly convert to a callback via cast.
+local count = 0
+local cb = ffi.cast("WNDENUMPROC", function(hwnd, l)
+ count = count + 1
+ return true
+end)
+
+-- Pass it to a C function.
+ffi.C.EnumWindows(cb, 0)
+-- EnumWindows doesn't need the callback after it returns, so free it.
+
+cb:free()
+-- The callback function pointer is no longer valid and its resources
+-- will be reclaimed. The created Lua closure will be garbage collected.
+</pre>
+
+<h3 id="callback_performance">Callback performance</h3>
+<p>
+<b>Callbacks are slow!</b> First, the C&nbsp;to Lua transition itself
+has an unavoidable cost, similar to a <tt>lua_call()</tt> or
+<tt>lua_pcall()</tt>. Argument and result marshalling add to that cost.
+And finally, neither the C&nbsp;compiler nor LuaJIT can inline or
+optimize across the language barrier and hoist repeated computations out
+of a callback function.
+</p>
+<p>
+Do not use callbacks for performance-sensitive work: e.g. consider a
+numerical integration routine which takes a user-defined function to
+integrate over. It's a bad idea to call a user-defined Lua function from
+C&nbsp;code millions of times. The callback overhead will be absolutely
+detrimental for performance.
+</p>
+<p>
+It's considerably faster to write the numerical integration routine
+itself in Lua &mdash; the JIT compiler will be able to inline the
+user-defined function and optimize it together with its calling context,
+with very competitive performance.
+</p>
+<p>
+As a general guideline: <b>use callbacks only when you must</b>, because
+of existing C&nbsp;APIs. E.g. callback performance is irrelevant for a
+GUI application, which waits for user input most of the time, anyway.
+</p>
+<p>
+For new designs <b>avoid push-style APIs</b>: a C&nbsp;function repeatedly
+calling a callback for each result. Instead <b>use pull-style APIs</b>:
+call a C&nbsp;function repeatedly to get a new result. Calls from Lua
+to C via the FFI are much faster than the other way round. Most well-designed
+libraries already use pull-style APIs (read/write, get/put).
+</p>
+
+<h2 id="clib">C Library Namespaces</h2>
+<p>
+A C&nbsp;library namespace is a special kind of object which allows
+access to the symbols contained in shared libraries or the default
+symbol namespace. The default
+<a href="ext_ffi_api.html#ffi_C"><tt>ffi.C</tt></a> namespace is
+automatically created when the FFI library is loaded. C&nbsp;library
+namespaces for specific shared libraries may be created with the
+<a href="ext_ffi_api.html#ffi_load"><tt>ffi.load()</tt></a> API
+function.
+</p>
+<p>
+Indexing a C&nbsp;library namespace object with a symbol name (a Lua
+string) automatically binds it to the library. First the symbol type
+is resolved &mdash; it must have been declared with
+<a href="ext_ffi_api.html#ffi_cdef"><tt>ffi.cdef</tt></a>. Then the
+symbol address is resolved by searching for the symbol name in the
+associated shared libraries or the default symbol namespace. Finally,
+the resulting binding between the symbol name, the symbol type and its
+address is cached. Missing symbol declarations or nonexistent symbol
+names cause an error.
+</p>
+<p>
+This is what happens on a <b>read access</b> for the different kinds of
+symbols:
+</p>
+<ul>
+
+<li>External functions: a cdata object with the type of the function
+and its address is returned.</li>
+
+<li>External variables: the symbol address is dereferenced and the
+loaded value is <a href="#convert_tolua">converted to a Lua object</a>
+and returned.</li>
+
+<li>Constant values (<tt>static&nbsp;const</tt> or <tt>enum</tt>
+constants): the constant is <a href="#convert_tolua">converted to a
+Lua object</a> and returned.</li>
+
+</ul>
+<p>
+This is what happens on a <b>write access</b>:
+</p>
+<ul>
+
+<li>External variables: the value to be written is
+<a href="#convert_fromlua">converted to the C&nbsp;type</a> of the
+variable and then stored at the symbol address.</li>
+
+<li>Writing to constant variables or to any other symbol type causes
+an error, like any other attempted write to a constant location.</li>
+
+</ul>
+<p>
+C&nbsp;library namespaces themselves are garbage collected objects. If
+the last reference to the namespace object is gone, the garbage
+collector will eventually release the shared library reference and
+remove all memory associated with the namespace. Since this may
+trigger the removal of the shared library from the memory of the
+running process, it's generally <em>not safe</em> to use function
+cdata objects obtained from a library if the namespace object may be
+unreferenced.
+</p>
+<p>
+Performance notice: the JIT compiler specializes to the identity of
+namespace objects and to the strings used to index it. This
+effectively turns function cdata objects into constants. It's not
+useful and actually counter-productive to explicitly cache these
+function objects, e.g. <tt>local strlen = ffi.C.strlen</tt>. OTOH it
+<em>is</em> useful to cache the namespace itself, e.g. <tt>local C =
+ffi.C</tt>.
+</p>
+
+<h2 id="policy">No Hand-holding!</h2>
+<p>
+The FFI library has been designed as <b>a low-level library</b>. The
+goal is to interface with C&nbsp;code and C&nbsp;data types with a
+minimum of overhead. This means <b>you can do anything you can do
+from&nbsp;C</b>: access all memory, overwrite anything in memory, call
+machine code at any memory address and so on.
+</p>
+<p>
+The FFI library provides <b>no memory safety</b>, unlike regular Lua
+code. It will happily allow you to dereference a <tt>NULL</tt>
+pointer, to access arrays out of bounds or to misdeclare
+C&nbsp;functions. If you make a mistake, your application might crash,
+just like equivalent C&nbsp;code would.
+</p>
+<p>
+This behavior is inevitable, since the goal is to provide full
+interoperability with C&nbsp;code. Adding extra safety measures, like
+bounds checks, would be futile. There's no way to detect
+misdeclarations of C&nbsp;functions, since shared libraries only
+provide symbol names, but no type information. Likewise there's no way
+to infer the valid range of indexes for a returned pointer.
+</p>
+<p>
+Again: the FFI library is a low-level library. This implies it needs
+to be used with care, but it's flexibility and performance often
+outweigh this concern. If you're a C or C++ developer, it'll be easy
+to apply your existing knowledge. OTOH writing code for the FFI
+library is not for the faint of heart and probably shouldn't be the
+first exercise for someone with little experience in Lua, C or C++.
+</p>
+<p>
+As a corollary of the above, the FFI library is <b>not safe for use by
+untrusted Lua code</b>. If you're sandboxing untrusted Lua code, you
+definitely don't want to give this code access to the FFI library or
+to <em>any</em> cdata object (except 64&nbsp;bit integers or complex
+numbers). Any properly engineered Lua sandbox needs to provide safety
+wrappers for many of the standard Lua library functions &mdash;
+similar wrappers need to be written for high-level operations on FFI
+data types, too.
+</p>
+
+<h2 id="status">Current Status</h2>
+<p>
+The initial release of the FFI library has some limitations and is
+missing some features. Most of these will be fixed in future releases.
+</p>
+<p>
+<a href="#clang">C language support</a> is
+currently incomplete:
+</p>
+<ul>
+<li>C&nbsp;declarations are not passed through a C&nbsp;pre-processor,
+yet.</li>
+<li>The C&nbsp;parser is able to evaluate most constant expressions
+commonly found in C&nbsp;header files. However it doesn't handle the
+full range of C&nbsp;expression semantics and may fail for some
+obscure constructs.</li>
+<li><tt>static const</tt> declarations only work for integer types
+up to 32&nbsp;bits. Neither declaring string constants nor
+floating-point constants is supported.</li>
+<li>Packed <tt>struct</tt> bitfields that cross container boundaries
+are not implemented.</li>
+<li>Native vector types may be defined with the GCC <tt>mode</tt> or
+<tt>vector_size</tt> attribute. But no operations other than loading,
+storing and initializing them are supported, yet.</li>
+<li>The <tt>volatile</tt> type qualifier is currently ignored by
+compiled code.</li>
+<li><a href="ext_ffi_api.html#ffi_cdef"><tt>ffi.cdef</tt></a> silently
+ignores most re-declarations. Note: avoid re-declarations which do not
+conform to C99. The implementation will eventually be changed to
+perform strict checks.</li>
+</ul>
+<p>
+The JIT compiler already handles a large subset of all FFI operations.
+It automatically falls back to the interpreter for unimplemented
+operations (you can check for this with the
+<a href="running.html#opt_j"><tt>-jv</tt></a> command line option).
+The following operations are currently not compiled and may exhibit
+suboptimal performance, especially when used in inner loops:
+</p>
+<ul>
+<li>Bitfield accesses and initializations.</li>
+<li>Vector operations.</li>
+<li>Table initializers.</li>
+<li>Initialization of nested <tt>struct</tt>/<tt>union</tt> types.</li>
+<li>Allocations of variable-length arrays or structs.</li>
+<li>Allocations of C&nbsp;types with a size &gt; 128&nbsp;bytes or an
+alignment &gt; 8&nbsp;bytes.</li>
+<li>Conversions from lightuserdata to <tt>void&nbsp;*</tt>.</li>
+<li>Pointer differences for element sizes that are not a power of
+two.</li>
+<li>Calls to C&nbsp;functions with aggregates passed or returned by
+value.</li>
+<li>Calls to ctype metamethods which are not plain functions.</li>
+<li>ctype <tt>__newindex</tt> tables and non-string lookups in ctype
+<tt>__index</tt> tables.</li>
+<li><tt>tostring()</tt> for cdata types.</li>
+<li>Calls to <tt>ffi.cdef()</tt>, <tt>ffi.load()</tt> and
+<tt>ffi.metatype()</tt>.</li>
+</ul>
+<p>
+Other missing features:
+</p>
+<ul>
+<li>Bit operations for 64&nbsp;bit types.</li>
+<li>Arithmetic for <tt>complex</tt> numbers.</li>
+<li>Passing structs by value to vararg C&nbsp;functions.</li>
+<li><a href="extensions.html#exceptions">C++ exception interoperability</a>
+does not extend to C&nbsp;functions called via the FFI, if the call is
+compiled.</li>
+</ul>
+<br class="flush">
+</div>
+<div id="foot">
+<hr class="hide">
+Copyright &copy; 2005-2018
+<span class="noprint">
+&middot;
+<a href="contact.html">Contact</a>
+</span>
+</div>
+</body>
+</html>
diff --git a/src/3rdparty/LuaJIT-2.0.5/doc/ext_ffi_tutorial.html b/src/3rdparty/LuaJIT-2.0.5/doc/ext_ffi_tutorial.html
new file mode 100644
index 0000000..cd455cf
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/doc/ext_ffi_tutorial.html
@@ -0,0 +1,600 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<title>FFI Tutorial</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<meta name="Copyright" content="Copyright (C) 2005-2018">
+<meta name="Language" content="en">
+<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
+<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
+<style type="text/css">
+table.idiomtable { font-size: 90%; line-height: 1.2; }
+table.idiomtable tt { font-size: 100%; }
+table.idiomtable td { vertical-align: top; }
+tr.idiomhead td { font-weight: bold; }
+td.idiomlua b { font-weight: normal; color: #2142bf; }
+</style>
+</head>
+<body>
+<div id="site">
+<a href="http://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
+</div>
+<div id="head">
+<h1>FFI Tutorial</h1>
+</div>
+<div id="nav">
+<ul><li>
+<a href="luajit.html">LuaJIT</a>
+<ul><li>
+<a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="install.html">Installation</a>
+</li><li>
+<a href="running.html">Running</a>
+</li></ul>
+</li><li>
+<a href="extensions.html">Extensions</a>
+<ul><li>
+<a href="ext_ffi.html">FFI Library</a>
+<ul><li>
+<a class="current" href="ext_ffi_tutorial.html">FFI Tutorial</a>
+</li><li>
+<a href="ext_ffi_api.html">ffi.* API</a>
+</li><li>
+<a href="ext_ffi_semantics.html">FFI Semantics</a>
+</li></ul>
+</li><li>
+<a href="ext_jit.html">jit.* Library</a>
+</li><li>
+<a href="ext_c_api.html">Lua/C API</a>
+</li></ul>
+</li><li>
+<a href="status.html">Status</a>
+<ul><li>
+<a href="changes.html">Changes</a>
+</li></ul>
+</li><li>
+<a href="faq.html">FAQ</a>
+</li><li>
+<a href="http://luajit.org/performance.html">Performance <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
+</li></ul>
+</div>
+<div id="main">
+<p>
+This page is intended to give you an overview of the features of the FFI
+library by presenting a few use cases and guidelines.
+</p>
+<p>
+This page makes no attempt to explain all of the FFI library, though.
+You'll want to have a look at the <a href="ext_ffi_api.html">ffi.* API
+function reference</a> and the <a href="ext_ffi_semantics.html">FFI
+semantics</a> to learn more.
+</p>
+
+<h2 id="load">Loading the FFI Library</h2>
+<p>
+The FFI library is built into LuaJIT by default, but it's not loaded
+and initialized by default. The suggested way to use the FFI library
+is to add the following to the start of every Lua file that needs one
+of its functions:
+</p>
+<pre class="code">
+local ffi = require("ffi")
+</pre>
+<p>
+Please note this doesn't define an <tt>ffi</tt> variable in the table
+of globals &mdash; you really need to use the local variable. The
+<tt>require</tt> function ensures the library is only loaded once.
+</p>
+<p style="font-size: 8pt;">
+Note: If you want to experiment with the FFI from the interactive prompt
+of the command line executable, omit the <tt>local</tt>, as it doesn't
+preserve local variables across lines.
+</p>
+
+<h2 id="sleep">Accessing Standard System Functions</h2>
+<p>
+The following code explains how to access standard system functions.
+We slowly print two lines of dots by sleeping for 10&nbsp;milliseconds
+after each dot:
+</p>
+<pre class="code mark">
+<span class="codemark">&nbsp;
+&#9312;
+
+
+
+
+
+&#9313;
+&#9314;
+&#9315;
+
+
+
+&#9316;
+
+
+
+
+
+&#9317;</span>local ffi = require("ffi")
+ffi.cdef[[
+<span style="color:#00a000;">void Sleep(int ms);
+int poll(struct pollfd *fds, unsigned long nfds, int timeout);</span>
+]]
+
+local sleep
+if ffi.os == "Windows" then
+ function sleep(s)
+ ffi.C.Sleep(s*1000)
+ end
+else
+ function sleep(s)
+ ffi.C.poll(nil, 0, s*1000)
+ end
+end
+
+for i=1,160 do
+ io.write("."); io.flush()
+ sleep(0.01)
+end
+io.write("\n")
+</pre>
+<p>
+Here's the step-by-step explanation:
+</p>
+<p>
+<span class="mark">&#9312;</span> This defines the
+C&nbsp;library functions we're going to use. The part inside the
+double-brackets (in green) is just standard C&nbsp;syntax. You can
+usually get this info from the C&nbsp;header files or the
+documentation provided by each C&nbsp;library or C&nbsp;compiler.
+</p>
+<p>
+<span class="mark">&#9313;</span> The difficulty we're
+facing here, is that there are different standards to choose from.
+Windows has a simple <tt>Sleep()</tt> function. On other systems there
+are a variety of functions available to achieve sub-second sleeps, but
+with no clear consensus. Thankfully <tt>poll()</tt> can be used for
+this task, too, and it's present on most non-Windows systems. The
+check for <tt>ffi.os</tt> makes sure we use the Windows-specific
+function only on Windows systems.
+</p>
+<p>
+<span class="mark">&#9314;</span> Here we're wrapping the
+call to the C&nbsp;function in a Lua function. This isn't strictly
+necessary, but it's helpful to deal with system-specific issues only
+in one part of the code. The way we're wrapping it ensures the check
+for the OS is only done during initialization and not for every call.
+</p>
+<p>
+<span class="mark">&#9315;</span> A more subtle point is
+that we defined our <tt>sleep()</tt> function (for the sake of this
+example) as taking the number of seconds, but accepting fractional
+seconds. Multiplying this by 1000 gets us milliseconds, but that still
+leaves it a Lua number, which is a floating-point value. Alas, the
+<tt>Sleep()</tt> function only accepts an integer value. Luckily for
+us, the FFI library automatically performs the conversion when calling
+the function (truncating the FP value towards zero, like in C).
+</p>
+<p style="font-size: 8pt;">
+Some readers will notice that <tt>Sleep()</tt> is part of
+<tt>KERNEL32.DLL</tt> and is also a <tt>stdcall</tt> function. So how
+can this possibly work? The FFI library provides the <tt>ffi.C</tt>
+default C&nbsp;library namespace, which allows calling functions from
+the default set of libraries, like a C&nbsp;compiler would. Also, the
+FFI library automatically detects <tt>stdcall</tt> functions, so you
+don't need to declare them as such.
+</p>
+<p>
+<span class="mark">&#9316;</span> The <tt>poll()</tt>
+function takes a couple more arguments we're not going to use. You can
+simply use <tt>nil</tt> to pass a <tt>NULL</tt> pointer and <tt>0</tt>
+for the <tt>nfds</tt> parameter. Please note that the
+number&nbsp;<tt>0</tt> <em>does not convert to a pointer value</em>,
+unlike in C++. You really have to pass pointers to pointer arguments
+and numbers to number arguments.
+</p>
+<p style="font-size: 8pt;">
+The page on <a href="ext_ffi_semantics.html">FFI semantics</a> has all
+of the gory details about
+<a href="ext_ffi_semantics.html#convert">conversions between Lua
+objects and C&nbsp;types</a>. For the most part you don't have to deal
+with this, as it's performed automatically and it's carefully designed
+to bridge the semantic differences between Lua and C.
+</p>
+<p>
+<span class="mark">&#9317;</span> Now that we have defined
+our own <tt>sleep()</tt> function, we can just call it from plain Lua
+code. That wasn't so bad, huh? Turning these boring animated dots into
+a fascinating best-selling game is left as an exercise for the reader.
+:-)
+</p>
+
+<h2 id="zlib">Accessing the zlib Compression Library</h2>
+<p>
+The following code shows how to access the <a
+href="http://zlib.net/">zlib</a> compression library from Lua code.
+We'll define two convenience wrapper functions that take a string and
+compress or uncompress it to another string:
+</p>
+<pre class="code mark">
+<span class="codemark">&nbsp;
+&#9312;
+
+
+
+
+
+
+&#9313;
+
+
+&#9314;
+
+&#9315;
+
+
+&#9316;
+
+
+&#9317;
+
+
+
+
+
+
+
+&#9318;</span>local ffi = require("ffi")
+ffi.cdef[[
+<span style="color:#00a000;">unsigned long compressBound(unsigned long sourceLen);
+int compress2(uint8_t *dest, unsigned long *destLen,
+ const uint8_t *source, unsigned long sourceLen, int level);
+int uncompress(uint8_t *dest, unsigned long *destLen,
+ const uint8_t *source, unsigned long sourceLen);</span>
+]]
+local zlib = ffi.load(ffi.os == "Windows" and "zlib1" or "z")
+
+local function compress(txt)
+ local n = zlib.compressBound(#txt)
+ local buf = ffi.new("uint8_t[?]", n)
+ local buflen = ffi.new("unsigned long[1]", n)
+ local res = zlib.compress2(buf, buflen, txt, #txt, 9)
+ assert(res == 0)
+ return ffi.string(buf, buflen[0])
+end
+
+local function uncompress(comp, n)
+ local buf = ffi.new("uint8_t[?]", n)
+ local buflen = ffi.new("unsigned long[1]", n)
+ local res = zlib.uncompress(buf, buflen, comp, #comp)
+ assert(res == 0)
+ return ffi.string(buf, buflen[0])
+end
+
+-- Simple test code.
+local txt = string.rep("abcd", 1000)
+print("Uncompressed size: ", #txt)
+local c = compress(txt)
+print("Compressed size: ", #c)
+local txt2 = uncompress(c, #txt)
+assert(txt2 == txt)
+</pre>
+<p>
+Here's the step-by-step explanation:
+</p>
+<p>
+<span class="mark">&#9312;</span> This defines some of the
+C&nbsp;functions provided by zlib. For the sake of this example, some
+type indirections have been reduced and it uses the pre-defined
+fixed-size integer types, while still adhering to the zlib API/ABI.
+</p>
+<p>
+<span class="mark">&#9313;</span> This loads the zlib shared
+library. On POSIX systems it's named <tt>libz.so</tt> and usually
+comes pre-installed. Since <tt>ffi.load()</tt> automatically adds any
+missing standard prefixes/suffixes, we can simply load the
+<tt>"z"</tt> library. On Windows it's named <tt>zlib1.dll</tt> and
+you'll have to download it first from the
+<a href="http://zlib.net/"><span class="ext">&raquo;</span>&nbsp;zlib site</a>. The check for
+<tt>ffi.os</tt> makes sure we pass the right name to
+<tt>ffi.load()</tt>.
+</p>
+<p>
+<span class="mark">&#9314;</span> First, the maximum size of
+the compression buffer is obtained by calling the
+<tt>zlib.compressBound</tt> function with the length of the
+uncompressed string. The next line allocates a byte buffer of this
+size. The <tt>[?]</tt> in the type specification indicates a
+variable-length array (VLA). The actual number of elements of this
+array is given as the 2nd argument to <tt>ffi.new()</tt>.
+</p>
+<p>
+<span class="mark">&#9315;</span> This may look strange at
+first, but have a look at the declaration of the <tt>compress2</tt>
+function from zlib: the destination length is defined as a pointer!
+This is because you pass in the maximum buffer size and get back the
+actual length that was used.
+</p>
+<p>
+In C you'd pass in the address of a local variable
+(<tt>&amp;buflen</tt>). But since there's no address-of operator in
+Lua, we'll just pass in a one-element array. Conveniently it can be
+initialized with the maximum buffer size in one step. Calling the
+actual <tt>zlib.compress2</tt> function is then straightforward.
+</p>
+<p>
+<span class="mark">&#9316;</span> We want to return the
+compressed data as a Lua string, so we'll use <tt>ffi.string()</tt>.
+It needs a pointer to the start of the data and the actual length. The
+length has been returned in the <tt>buflen</tt> array, so we'll just
+get it from there.
+</p>
+<p style="font-size: 8pt;">
+Note that since the function returns now, the <tt>buf</tt> and
+<tt>buflen</tt> variables will eventually be garbage collected. This
+is fine, because <tt>ffi.string()</tt> has copied the contents to a
+newly created (interned) Lua string. If you plan to call this function
+lots of times, consider reusing the buffers and/or handing back the
+results in buffers instead of strings. This will reduce the overhead
+for garbage collection and string interning.
+</p>
+<p>
+<span class="mark">&#9317;</span> The <tt>uncompress</tt>
+functions does the exact opposite of the <tt>compress</tt> function.
+The compressed data doesn't include the size of the original string,
+so this needs to be passed in. Otherwise no surprises here.
+</p>
+<p>
+<span class="mark">&#9318;</span> The code, that makes use
+of the functions we just defined, is just plain Lua code. It doesn't
+need to know anything about the LuaJIT FFI &mdash; the convenience
+wrapper functions completely hide it.
+</p>
+<p>
+One major advantage of the LuaJIT FFI is that you are now able to
+write those wrappers <em>in Lua</em>. And at a fraction of the time it
+would cost you to create an extra C&nbsp;module using the Lua/C API.
+Many of the simpler C&nbsp;functions can probably be used directly
+from your Lua code, without any wrappers.
+</p>
+<p style="font-size: 8pt;">
+Side note: the zlib API uses the <tt>long</tt> type for passing
+lengths and sizes around. But all those zlib functions actually only
+deal with 32&nbsp;bit values. This is an unfortunate choice for a
+public API, but may be explained by zlib's history &mdash; we'll just
+have to deal with it.
+</p>
+<p style="font-size: 8pt;">
+First, you should know that a <tt>long</tt> is a 64&nbsp;bit type e.g.
+on POSIX/x64 systems, but a 32&nbsp;bit type on Windows/x64 and on
+32&nbsp;bit systems. Thus a <tt>long</tt> result can be either a plain
+Lua number or a boxed 64&nbsp;bit integer cdata object, depending on
+the target system.
+</p>
+<p style="font-size: 8pt;">
+Ok, so the <tt>ffi.*</tt> functions generally accept cdata objects
+wherever you'd want to use a number. That's why we get a away with
+passing <tt>n</tt> to <tt>ffi.string()</tt> above. But other Lua
+library functions or modules don't know how to deal with this. So for
+maximum portability one needs to use <tt>tonumber()</tt> on returned
+<tt>long</tt> results before passing them on. Otherwise the
+application might work on some systems, but would fail in a POSIX/x64
+environment.
+</p>
+
+<h2 id="metatype">Defining Metamethods for a C&nbsp;Type</h2>
+<p>
+The following code explains how to define metamethods for a C type.
+We define a simple point type and add some operations to it:
+</p>
+<pre class="code mark">
+<span class="codemark">&nbsp;
+&#9312;
+
+
+
+&#9313;
+
+&#9314;
+
+&#9315;
+
+
+
+&#9316;
+
+&#9317;</span>local ffi = require("ffi")
+ffi.cdef[[
+<span style="color:#00a000;">typedef struct { double x, y; } point_t;</span>
+]]
+
+local point
+local mt = {
+ __add = function(a, b) return point(a.x+b.x, a.y+b.y) end,
+ __len = function(a) return math.sqrt(a.x*a.x + a.y*a.y) end,
+ __index = {
+ area = function(a) return a.x*a.x + a.y*a.y end,
+ },
+}
+point = ffi.metatype("point_t", mt)
+
+local a = point(3, 4)
+print(a.x, a.y) --> 3 4
+print(#a) --> 5
+print(a:area()) --> 25
+local b = a + point(0.5, 8)
+print(#b) --> 12.5
+</pre>
+<p>
+Here's the step-by-step explanation:
+</p>
+<p>
+<span class="mark">&#9312;</span> This defines the C&nbsp;type for a
+two-dimensional point object.
+</p>
+<p>
+<span class="mark">&#9313;</span> We have to declare the variable
+holding the point constructor first, because it's used inside of a
+metamethod.
+</p>
+<p>
+<span class="mark">&#9314;</span> Let's define an <tt>__add</tt>
+metamethod which adds the coordinates of two points and creates a new
+point object. For simplicity, this function assumes that both arguments
+are points. But it could be any mix of objects, if at least one operand
+is of the required type (e.g. adding a point plus a number or vice
+versa). Our <tt>__len</tt> metamethod returns the distance of a point to
+the origin.
+</p>
+<p>
+<span class="mark">&#9315;</span> If we run out of operators, we can
+define named methods, too. Here the <tt>__index</tt> table defines an
+<tt>area</tt> function. For custom indexing needs, one might want to
+define <tt>__index</tt> and <tt>__newindex</tt> <em>functions</em> instead.
+</p>
+<p>
+<span class="mark">&#9316;</span> This associates the metamethods with
+our C&nbsp;type. This only needs to be done once. For convenience, a
+constructor is returned by
+<a href="ext_ffi_api.html#ffi_metatype"><tt>ffi.metatype()</tt></a>.
+We're not required to use it, though. The original C&nbsp;type can still
+be used e.g. to create an array of points. The metamethods automatically
+apply to any and all uses of this type.
+</p>
+<p>
+Please note that the association with a metatable is permanent and
+<b>the metatable must not be modified afterwards!</b> Ditto for the
+<tt>__index</tt> table.
+</p>
+<p>
+<span class="mark">&#9317;</span> Here are some simple usage examples
+for the point type and their expected results. The pre-defined
+operations (such as <tt>a.x</tt>) can be freely mixed with the newly
+defined metamethods. Note that <tt>area</tt> is a method and must be
+called with the Lua syntax for methods: <tt>a:area()</tt>, not
+<tt>a.area()</tt>.
+</p>
+<p>
+The C&nbsp;type metamethod mechanism is most useful when used in
+conjunction with C&nbsp;libraries that are written in an object-oriented
+style. Creators return a pointer to a new instance and methods take an
+instance pointer as the first argument. Sometimes you can just point
+<tt>__index</tt> to the library namespace and <tt>__gc</tt> to the
+destructor and you're done. But often enough you'll want to add
+convenience wrappers, e.g. to return actual Lua strings or when
+returning multiple values.
+</p>
+<p>
+Some C libraries only declare instance pointers as an opaque
+<tt>void&nbsp;*</tt> type. In this case you can use a fake type for all
+declarations, e.g. a pointer to a named (incomplete) struct will do:
+<tt>typedef struct foo_type *foo_handle</tt>. The C&nbsp;side doesn't
+know what you declare with the LuaJIT FFI, but as long as the underlying
+types are compatible, everything still works.
+</p>
+
+<h2 id="idioms">Translating C&nbsp;Idioms</h2>
+<p>
+Here's a list of common C&nbsp;idioms and their translation to the
+LuaJIT FFI:
+</p>
+<table class="idiomtable">
+<tr class="idiomhead">
+<td class="idiomdesc">Idiom</td>
+<td class="idiomc">C&nbsp;code</td>
+<td class="idiomlua">Lua code</td>
+</tr>
+<tr class="odd separate">
+<td class="idiomdesc">Pointer dereference<br><tt>int *p;</tt></td><td class="idiomc"><tt>x = *p;<br>*p = y;</tt></td><td class="idiomlua"><tt>x = <b>p[0]</b><br><b>p[0]</b> = y</tt></td></tr>
+<tr class="even">
+<td class="idiomdesc">Pointer indexing<br><tt>int i, *p;</tt></td><td class="idiomc"><tt>x = p[i];<br>p[i+1] = y;</tt></td><td class="idiomlua"><tt>x = p[i]<br>p[i+1] = y</tt></td></tr>
+<tr class="odd">
+<td class="idiomdesc">Array indexing<br><tt>int i, a[];</tt></td><td class="idiomc"><tt>x = a[i];<br>a[i+1] = y;</tt></td><td class="idiomlua"><tt>x = a[i]<br>a[i+1] = y</tt></td></tr>
+<tr class="even separate">
+<td class="idiomdesc"><tt>struct</tt>/<tt>union</tt> dereference<br><tt>struct foo s;</tt></td><td class="idiomc"><tt>x = s.field;<br>s.field = y;</tt></td><td class="idiomlua"><tt>x = s.field<br>s.field = y</tt></td></tr>
+<tr class="odd">
+<td class="idiomdesc"><tt>struct</tt>/<tt>union</tt> pointer deref.<br><tt>struct foo *sp;</tt></td><td class="idiomc"><tt>x = sp->field;<br>sp->field = y;</tt></td><td class="idiomlua"><tt>x = <b>s.field</b><br><b>s.field</b> = y</tt></td></tr>
+<tr class="even separate">
+<td class="idiomdesc">Pointer arithmetic<br><tt>int i, *p;</tt></td><td class="idiomc"><tt>x = p + i;<br>y = p - i;</tt></td><td class="idiomlua"><tt>x = p + i<br>y = p - i</tt></td></tr>
+<tr class="odd">
+<td class="idiomdesc">Pointer difference<br><tt>int *p1, *p2;</tt></td><td class="idiomc"><tt>x = p1 - p2;</tt></td><td class="idiomlua"><tt>x = p1 - p2</tt></td></tr>
+<tr class="even">
+<td class="idiomdesc">Array element pointer<br><tt>int i, a[];</tt></td><td class="idiomc"><tt>x = &amp;a[i];</tt></td><td class="idiomlua"><tt>x = <b>a+i</b></tt></td></tr>
+<tr class="odd">
+<td class="idiomdesc">Cast pointer to address<br><tt>int *p;</tt></td><td class="idiomc"><tt>x = (intptr_t)p;</tt></td><td class="idiomlua"><tt>x = <b>tonumber(<br>&nbsp;ffi.cast("intptr_t",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p))</b></tt></td></tr>
+<tr class="even separate">
+<td class="idiomdesc">Functions with outargs<br><tt>void foo(int *inoutlen);</tt></td><td class="idiomc"><tt>int len = x;<br>foo(&amp;len);<br>y = len;</tt></td><td class="idiomlua"><tt><b>local len =<br>&nbsp;&nbsp;ffi.new("int[1]", x)<br>foo(len)<br>y = len[0]</b></tt></td></tr>
+<tr class="odd">
+<td class="idiomdesc"><a href="ext_ffi_semantics.html#convert_vararg">Vararg conversions</a><br><tt>int printf(char *fmt, ...);</tt></td><td class="idiomc"><tt>printf("%g", 1.0);<br>printf("%d", 1);<br>&nbsp;</tt></td><td class="idiomlua"><tt>printf("%g", 1);<br>printf("%d",<br>&nbsp;&nbsp;<b>ffi.new("int", 1)</b>)</tt></td></tr>
+</table>
+
+<h2 id="cache">To Cache or Not to Cache</h2>
+<p>
+It's a common Lua idiom to cache library functions in local variables
+or upvalues, e.g.:
+</p>
+<pre class="code">
+local byte, char = string.byte, string.char
+local function foo(x)
+ return char(byte(x)+1)
+end
+</pre>
+<p>
+This replaces several hash-table lookups with a (faster) direct use of
+a local or an upvalue. This is less important with LuaJIT, since the
+JIT compiler optimizes hash-table lookups a lot and is even able to
+hoist most of them out of the inner loops. It can't eliminate
+<em>all</em> of them, though, and it saves some typing for often-used
+functions. So there's still a place for this, even with LuaJIT.
+</p>
+<p>
+The situation is a bit different with C&nbsp;function calls via the
+FFI library. The JIT compiler has special logic to eliminate <em>all
+of the lookup overhead</em> for functions resolved from a
+<a href="ext_ffi_semantics.html#clib">C&nbsp;library namespace</a>!
+Thus it's not helpful and actually counter-productive to cache
+individual C&nbsp;functions like this:
+</p>
+<pre class="code">
+local <b>funca</b>, <b>funcb</b> = ffi.C.funca, ffi.C.funcb -- <span style="color:#c00000;">Not helpful!</span>
+local function foo(x, n)
+ for i=1,n do <b>funcb</b>(<b>funca</b>(x, i), 1) end
+end
+</pre>
+<p>
+This turns them into indirect calls and generates bigger and slower
+machine code. Instead you'll want to cache the namespace itself and
+rely on the JIT compiler to eliminate the lookups:
+</p>
+<pre class="code">
+local <b>C</b> = ffi.C -- <span style="color:#00a000;">Instead use this!</span>
+local function foo(x, n)
+ for i=1,n do <b>C.funcb</b>(<b>C.funca</b>(x, i), 1) end
+end
+</pre>
+<p>
+This generates both shorter and faster code. So <b>don't cache
+C&nbsp;functions</b>, but <b>do</b> cache namespaces! Most often the
+namespace is already in a local variable at an outer scope, e.g. from
+<tt>local&nbsp;lib&nbsp;=&nbsp;ffi.load(...)</tt>. Note that copying
+it to a local variable in the function scope is unnecessary.
+</p>
+<br class="flush">
+</div>
+<div id="foot">
+<hr class="hide">
+Copyright &copy; 2005-2018
+<span class="noprint">
+&middot;
+<a href="contact.html">Contact</a>
+</span>
+</div>
+</body>
+</html>
diff --git a/src/3rdparty/LuaJIT-2.0.5/doc/ext_jit.html b/src/3rdparty/LuaJIT-2.0.5/doc/ext_jit.html
new file mode 100644
index 0000000..ce6dcd6
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/doc/ext_jit.html
@@ -0,0 +1,198 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<title>jit.* Library</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<meta name="Copyright" content="Copyright (C) 2005-2018">
+<meta name="Language" content="en">
+<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
+<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
+</head>
+<body>
+<div id="site">
+<a href="http://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
+</div>
+<div id="head">
+<h1><tt>jit.*</tt> Library</h1>
+</div>
+<div id="nav">
+<ul><li>
+<a href="luajit.html">LuaJIT</a>
+<ul><li>
+<a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="install.html">Installation</a>
+</li><li>
+<a href="running.html">Running</a>
+</li></ul>
+</li><li>
+<a href="extensions.html">Extensions</a>
+<ul><li>
+<a href="ext_ffi.html">FFI Library</a>
+<ul><li>
+<a href="ext_ffi_tutorial.html">FFI Tutorial</a>
+</li><li>
+<a href="ext_ffi_api.html">ffi.* API</a>
+</li><li>
+<a href="ext_ffi_semantics.html">FFI Semantics</a>
+</li></ul>
+</li><li>
+<a class="current" href="ext_jit.html">jit.* Library</a>
+</li><li>
+<a href="ext_c_api.html">Lua/C API</a>
+</li></ul>
+</li><li>
+<a href="status.html">Status</a>
+<ul><li>
+<a href="changes.html">Changes</a>
+</li></ul>
+</li><li>
+<a href="faq.html">FAQ</a>
+</li><li>
+<a href="http://luajit.org/performance.html">Performance <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
+</li></ul>
+</div>
+<div id="main">
+<p>
+The functions in this built-in module control the behavior of the JIT
+compiler engine. Note that JIT-compilation is fully automatic &mdash;
+you probably won't need to use any of the following functions unless
+you have special needs.
+</p>
+
+<h3 id="jit_onoff"><tt>jit.on()<br>
+jit.off()</tt></h3>
+<p>
+Turns the whole JIT compiler on (default) or off.
+</p>
+<p>
+These functions are typically used with the command line options
+<tt>-j on</tt> or <tt>-j off</tt>.
+</p>
+
+<h3 id="jit_flush"><tt>jit.flush()</tt></h3>
+<p>
+Flushes the whole cache of compiled code.
+</p>
+
+<h3 id="jit_onoff_func"><tt>jit.on(func|true [,true|false])<br>
+jit.off(func|true [,true|false])<br>
+jit.flush(func|true [,true|false])</tt></h3>
+<p>
+<tt>jit.on</tt> enables JIT compilation for a Lua function (this is
+the default).
+</p>
+<p>
+<tt>jit.off</tt> disables JIT compilation for a Lua function and
+flushes any already compiled code from the code cache.
+</p>
+<p>
+<tt>jit.flush</tt> flushes the code, but doesn't affect the
+enable/disable status.
+</p>
+<p>
+The current function, i.e. the Lua function calling this library
+function, can also be specified by passing <tt>true</tt> as the first
+argument.
+</p>
+<p>
+If the second argument is <tt>true</tt>, JIT compilation is also
+enabled, disabled or flushed recursively for all sub-functions of a
+function. With <tt>false</tt> only the sub-functions are affected.
+</p>
+<p>
+The <tt>jit.on</tt> and <tt>jit.off</tt> functions only set a flag
+which is checked when the function is about to be compiled. They do
+not trigger immediate compilation.
+</p>
+<p>
+Typical usage is <tt>jit.off(true, true)</tt> in the main chunk
+of a module to turn off JIT compilation for the whole module for
+debugging purposes.
+</p>
+
+<h3 id="jit_flush_tr"><tt>jit.flush(tr)</tt></h3>
+<p>
+Flushes the root trace, specified by its number, and all of its side
+traces from the cache. The code for the trace will be retained as long
+as there are any other traces which link to it.
+</p>
+
+<h3 id="jit_status"><tt>status, ... = jit.status()</tt></h3>
+<p>
+Returns the current status of the JIT compiler. The first result is
+either <tt>true</tt> or <tt>false</tt> if the JIT compiler is turned
+on or off. The remaining results are strings for CPU-specific features
+and enabled optimizations.
+</p>
+
+<h3 id="jit_version"><tt>jit.version</tt></h3>
+<p>
+Contains the LuaJIT version string.
+</p>
+
+<h3 id="jit_version_num"><tt>jit.version_num</tt></h3>
+<p>
+Contains the version number of the LuaJIT core. Version xx.yy.zz
+is represented by the decimal number xxyyzz.
+</p>
+
+<h3 id="jit_os"><tt>jit.os</tt></h3>
+<p>
+Contains the target OS name:
+"Windows", "Linux", "OSX", "BSD", "POSIX" or "Other".
+</p>
+
+<h3 id="jit_arch"><tt>jit.arch</tt></h3>
+<p>
+Contains the target architecture name:
+"x86", "x64", "arm", "ppc", "ppcspe", or "mips".
+</p>
+
+<h2 id="jit_opt"><tt>jit.opt.*</tt> &mdash; JIT compiler optimization control</h2>
+<p>
+This sub-module provides the backend for the <tt>-O</tt> command line
+option.
+</p>
+<p>
+You can also use it programmatically, e.g.:
+</p>
+<pre class="code">
+jit.opt.start(2) -- same as -O2
+jit.opt.start("-dce")
+jit.opt.start("hotloop=10", "hotexit=2")
+</pre>
+<p>
+Unlike in LuaJIT 1.x, the module is built-in and
+<b>optimization is turned on by default!</b>
+It's no longer necessary to run <tt>require("jit.opt").start()</tt>,
+which was one of the ways to enable optimization.
+</p>
+
+<h2 id="jit_util"><tt>jit.util.*</tt> &mdash; JIT compiler introspection</h2>
+<p>
+This sub-module holds functions to introspect the bytecode, generated
+traces, the IR and the generated machine code. The functionality
+provided by this module is still in flux and therefore undocumented.
+</p>
+<p>
+The debug modules <tt>-jbc</tt>, <tt>-jv</tt> and <tt>-jdump</tt> make
+extensive use of these functions. Please check out their source code,
+if you want to know more.
+</p>
+<br class="flush">
+</div>
+<div id="foot">
+<hr class="hide">
+Copyright &copy; 2005-2018
+<span class="noprint">
+&middot;
+<a href="contact.html">Contact</a>
+</span>
+</div>
+</body>
+</html>
diff --git a/src/3rdparty/LuaJIT-2.0.5/doc/extensions.html b/src/3rdparty/LuaJIT-2.0.5/doc/extensions.html
new file mode 100644
index 0000000..fa412e0
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/doc/extensions.html
@@ -0,0 +1,407 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<title>Extensions</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<meta name="Copyright" content="Copyright (C) 2005-2018">
+<meta name="Language" content="en">
+<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
+<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
+<style type="text/css">
+table.exc {
+ line-height: 1.2;
+}
+tr.exchead td {
+ font-weight: bold;
+}
+td.excplatform {
+ width: 48%;
+}
+td.exccompiler {
+ width: 29%;
+}
+td.excinterop {
+ width: 23%;
+}
+</style>
+</head>
+<body>
+<div id="site">
+<a href="http://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
+</div>
+<div id="head">
+<h1>Extensions</h1>
+</div>
+<div id="nav">
+<ul><li>
+<a href="luajit.html">LuaJIT</a>
+<ul><li>
+<a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="install.html">Installation</a>
+</li><li>
+<a href="running.html">Running</a>
+</li></ul>
+</li><li>
+<a class="current" href="extensions.html">Extensions</a>
+<ul><li>
+<a href="ext_ffi.html">FFI Library</a>
+<ul><li>
+<a href="ext_ffi_tutorial.html">FFI Tutorial</a>
+</li><li>
+<a href="ext_ffi_api.html">ffi.* API</a>
+</li><li>
+<a href="ext_ffi_semantics.html">FFI Semantics</a>
+</li></ul>
+</li><li>
+<a href="ext_jit.html">jit.* Library</a>
+</li><li>
+<a href="ext_c_api.html">Lua/C API</a>
+</li></ul>
+</li><li>
+<a href="status.html">Status</a>
+<ul><li>
+<a href="changes.html">Changes</a>
+</li></ul>
+</li><li>
+<a href="faq.html">FAQ</a>
+</li><li>
+<a href="http://luajit.org/performance.html">Performance <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
+</li></ul>
+</div>
+<div id="main">
+<p>
+LuaJIT is fully upwards-compatible with Lua 5.1. It supports all
+<a href="http://www.lua.org/manual/5.1/manual.html#5"><span class="ext">&raquo;</span>&nbsp;standard Lua
+library functions</a> and the full set of
+<a href="http://www.lua.org/manual/5.1/manual.html#3"><span class="ext">&raquo;</span>&nbsp;Lua/C API
+functions</a>.
+</p>
+<p>
+LuaJIT is also fully ABI-compatible to Lua 5.1 at the linker/dynamic
+loader level. This means you can compile a C&nbsp;module against the
+standard Lua headers and load the same shared library from either Lua
+or LuaJIT.
+</p>
+<p>
+LuaJIT extends the standard Lua VM with new functionality and adds
+several extension modules. Please note this page is only about
+<em>functional</em> enhancements and not about performance enhancements,
+such as the optimized VM, the faster interpreter or the JIT compiler.
+</p>
+
+<h2 id="modules">Extensions Modules</h2>
+<p>
+LuaJIT comes with several built-in extension modules:
+</p>
+
+<h3 id="bit"><tt>bit.*</tt> &mdash; Bitwise operations</h3>
+<p>
+LuaJIT supports all bitwise operations as defined by
+<a href="http://bitop.luajit.org"><span class="ext">&raquo;</span>&nbsp;Lua BitOp</a>:
+</p>
+<pre class="code">
+bit.tobit bit.tohex bit.bnot bit.band bit.bor bit.bxor
+bit.lshift bit.rshift bit.arshift bit.rol bit.ror bit.bswap
+</pre>
+<p>
+This module is a LuaJIT built-in &mdash; you don't need to download or
+install Lua BitOp. The Lua BitOp site has full documentation for all
+<a href="http://bitop.luajit.org/api.html"><span class="ext">&raquo;</span>&nbsp;Lua BitOp API functions</a>.
+</p>
+<p>
+Please make sure to <tt>require</tt> the module before using any of
+its functions:
+</p>
+<pre class="code">
+local bit = require("bit")
+</pre>
+<p>
+An already installed Lua BitOp module is ignored by LuaJIT.
+This way you can use bit operations from both Lua and LuaJIT on a
+shared installation.
+</p>
+
+<h3 id="ffi"><tt>ffi.*</tt> &mdash; FFI library</h3>
+<p>
+The <a href="ext_ffi.html">FFI library</a> allows calling external
+C&nbsp;functions and the use of C&nbsp;data structures from pure Lua
+code.
+</p>
+
+<h3 id="jit"><tt>jit.*</tt> &mdash; JIT compiler control</h3>
+<p>
+The functions in this module
+<a href="ext_jit.html">control the behavior of the JIT compiler engine</a>.
+</p>
+
+<h3 id="c_api">C API extensions</h3>
+<p>
+LuaJIT adds some
+<a href="ext_c_api.html">extra functions to the Lua/C API</a>.
+</p>
+
+<h2 id="library">Enhanced Standard Library Functions</h2>
+
+<h3 id="xpcall"><tt>xpcall(f, err [,args...])</tt> passes arguments</h3>
+<p>
+Unlike the standard implementation in Lua 5.1, <tt>xpcall()</tt>
+passes any arguments after the error function to the function
+which is called in a protected context.
+</p>
+
+<h3 id="load"><tt>loadfile()</tt> etc. handle UTF-8 source code</h3>
+<p>
+Non-ASCII characters are handled transparently by the Lua source code parser.
+This allows the use of UTF-8 characters in identifiers and strings.
+A UTF-8 BOM is skipped at the start of the source code.
+</p>
+
+<h3 id="tostring"><tt>tostring()</tt> etc. canonicalize NaN and &plusmn;Inf</h3>
+<p>
+All number-to-string conversions consistently convert non-finite numbers
+to the same strings on all platforms. NaN results in <tt>"nan"</tt>,
+positive infinity results in <tt>"inf"</tt> and negative infinity results
+in <tt>"-inf"</tt>.
+</p>
+
+<h3 id="tonumber"><tt>tonumber()</tt> etc. use builtin string to number conversion</h3>
+<p>
+All string-to-number conversions consistently convert integer and
+floating-point inputs in decimal and hexadecimal on all platforms.
+<tt>strtod()</tt> is <em>not</em> used anymore, which avoids numerous
+problems with poor C library implementations. The builtin conversion
+function provides full precision according to the IEEE-754 standard, it
+works independently of the current locale and it supports hex floating-point
+numbers (e.g. <tt>0x1.5p-3</tt>).
+</p>
+
+<h3 id="string_dump"><tt>string.dump(f [,strip])</tt> generates portable bytecode</h3>
+<p>
+An extra argument has been added to <tt>string.dump()</tt>. If set to
+<tt>true</tt>, 'stripped' bytecode without debug information is
+generated. This speeds up later bytecode loading and reduces memory
+usage. See also the
+<a href="running.html#opt_b"><tt>-b</tt> command line option</a>.
+</p>
+<p>
+The generated bytecode is portable and can be loaded on any architecture
+that LuaJIT supports, independent of word size or endianess. However the
+bytecode compatibility versions must match. Bytecode stays compatible
+for dot releases (x.y.0 &rarr; x.y.1), but may change with major or
+minor releases (2.0 &rarr; 2.1) or between any beta release. Foreign
+bytecode (e.g. from Lua 5.1) is incompatible and cannot be loaded.
+</p>
+
+<h3 id="math_random">Enhanced PRNG for <tt>math.random()</tt></h3>
+<p>
+LuaJIT uses a Tausworthe PRNG with period 2^223 to implement
+<tt>math.random()</tt> and <tt>math.randomseed()</tt>. The quality of
+the PRNG results is much superior compared to the standard Lua
+implementation which uses the platform-specific ANSI rand().
+</p>
+<p>
+The PRNG generates the same sequences from the same seeds on all
+platforms and makes use of all bits in the seed argument.
+<tt>math.random()</tt> without arguments generates 52 pseudo-random bits
+for every call. The result is uniformly distributed between 0.0 and 1.0.
+It's correctly scaled up and rounded for <tt>math.random(n&nbsp;[,m])</tt> to
+preserve uniformity.
+</p>
+
+<h3 id="io"><tt>io.*</tt> functions handle 64&nbsp;bit file offsets</h3>
+<p>
+The file I/O functions in the standard <tt>io.*</tt> library handle
+64&nbsp;bit file offsets. In particular this means it's possible
+to open files larger than 2&nbsp;Gigabytes and to reposition or obtain
+the current file position for offsets beyond 2&nbsp;GB
+(<tt>fp:seek()</tt> method).
+</p>
+
+<h3 id="debug_meta"><tt>debug.*</tt> functions identify metamethods</h3>
+<p>
+<tt>debug.getinfo()</tt> and <tt>lua_getinfo()</tt> also return information
+about invoked metamethods. The <tt>namewhat</tt> field is set to
+<tt>"metamethod"</tt> and the <tt>name</tt> field has the name of
+the corresponding metamethod (e.g. <tt>"__index"</tt>).
+</p>
+
+<h2 id="resumable">Fully Resumable VM</h2>
+<p>
+The LuaJIT VM is fully resumable. This means you can yield from a
+coroutine even across contexts, where this would not possible with
+the standard Lua&nbsp;5.1 VM: e.g. you can yield across <tt>pcall()</tt>
+and <tt>xpcall()</tt>, across iterators and across metamethods.
+</p>
+
+<h2 id="lua52">Extensions from Lua 5.2</h2>
+<p>
+LuaJIT supports some language and library extensions from Lua&nbsp;5.2.
+Features that are unlikely to break existing code are unconditionally
+enabled:
+</p>
+<ul>
+<li><tt>goto</tt> and <tt>::labels::</tt>.</li>
+<li>Hex escapes <tt>'\x3F'</tt> and <tt>'\*'</tt> escape in strings.</li>
+<li><tt>load(string|reader [, chunkname [,mode [,env]]])</tt>.</li>
+<li><tt>loadstring()</tt> is an alias for <tt>load()</tt>.</li>
+<li><tt>loadfile(filename [,mode [,env]])</tt>.</li>
+<li><tt>math.log(x [,base])</tt>.</li>
+<li><tt>string.rep(s, n [,sep])</tt>.</li>
+<li><tt>string.format()</tt>: <tt>%q</tt> reversible.
+<tt>%s</tt> checks <tt>__tostring</tt>.
+<tt>%a</tt> and <tt>"%A</tt> added.</li>
+<li>String matching pattern <tt>%g</tt> added.</li>
+<li><tt>io.read("*L")</tt>.</li>
+<li><tt>io.lines()</tt> and <tt>file:lines()</tt> process
+<tt>io.read()</tt> options.</li>
+<li><tt>os.exit(status|true|false [,close])</tt>.</li>
+<li><tt>package.searchpath(name, path [, sep [, rep]])</tt>.</li>
+<li><tt>package.loadlib(name, "*")</tt>.</li>
+<li><tt>debug.getinfo()</tt> returns <tt>nparams</tt> and <tt>isvararg</tt>
+for option <tt>"u"</tt>.</li>
+<li><tt>debug.getlocal()</tt> accepts function instead of level.</li>
+<li><tt>debug.getlocal()</tt> and <tt>debug.setlocal()</tt> accept negative
+indexes for varargs.</li>
+<li><tt>debug.getupvalue()</tt> and <tt>debug.setupvalue()</tt> handle
+C&nbsp;functions.</li>
+<li><tt>debug.upvalueid()</tt> and <tt>debug.upvaluejoin()</tt>.</li>
+<li>Command line option <tt>-E</tt>.</li>
+<li>Command line checks <tt>__tostring</tt> for errors.</li>
+</ul>
+<p>
+Other features are only enabled, if LuaJIT is built with
+<tt>-DLUAJIT_ENABLE_LUA52COMPAT</tt>:
+</p>
+<ul>
+<li><tt>goto</tt> is a keyword and not a valid variable name anymore.</li>
+<li><tt>break</tt> can be placed anywhere. Empty statements (<tt>;;</tt>)
+are allowed.</li>
+<li><tt>__lt</tt>, <tt>__le</tt> are invoked for mixed types.</li>
+<li><tt>__len</tt> for tables. <tt>rawlen()</tt> library function.</li>
+<li><tt>pairs()</tt> and <tt>ipairs()</tt> check for <tt>__pairs</tt> and
+<tt>__ipairs</tt>.</li>
+<li><tt>coroutine.running()</tt> returns two results.</li>
+<li><tt>table.pack()</tt> and <tt>table.unpack()</tt>
+(same as <tt>unpack()</tt>).</li>
+<li><tt>io.write()</tt> and <tt>file:write()</tt> return file handle
+instead of <tt>true</tt>.</li>
+<li><tt>os.execute()</tt> and <tt>pipe:close()</tt> return detailed
+exit status.</li>
+<li><tt>debug.setmetatable()</tt> returns object.</li>
+<li><tt>debug.getuservalue()</tt> and <tt>debug.setuservalue()</tt>.</li>
+<li>Remove <tt>math.mod()</tt>, <tt>string.gfind()</tt>.</li>
+</ul>
+<p>
+Note: this provides only partial compatibility with Lua 5.2 at the
+language and Lua library level. LuaJIT is API+ABI-compatible with
+Lua&nbsp;5.1, which prevents implementing features that would otherwise
+break the Lua/C API and ABI (e.g. <tt>_ENV</tt>).
+</p>
+
+<h2 id="exceptions">C++ Exception Interoperability</h2>
+<p>
+LuaJIT has built-in support for interoperating with C++&nbsp;exceptions.
+The available range of features depends on the target platform and
+the toolchain used to compile LuaJIT:
+</p>
+<table class="exc">
+<tr class="exchead">
+<td class="excplatform">Platform</td>
+<td class="exccompiler">Compiler</td>
+<td class="excinterop">Interoperability</td>
+</tr>
+<tr class="odd separate">
+<td class="excplatform">POSIX/x64, DWARF2 unwinding</td>
+<td class="exccompiler">GCC 4.3+</td>
+<td class="excinterop"><b style="color: #00a000;">Full</b></td>
+</tr>
+<tr class="even">
+<td class="excplatform">Other platforms, DWARF2 unwinding</td>
+<td class="exccompiler">GCC</td>
+<td class="excinterop"><b style="color: #c06000;">Limited</b></td>
+</tr>
+<tr class="odd">
+<td class="excplatform">Windows/x64</td>
+<td class="exccompiler">MSVC or WinSDK</td>
+<td class="excinterop"><b style="color: #00a000;">Full</b></td>
+</tr>
+<tr class="even">
+<td class="excplatform">Windows/x86</td>
+<td class="exccompiler">Any</td>
+<td class="excinterop"><b style="color: #a00000;">No</b></td>
+</tr>
+<tr class="odd">
+<td class="excplatform">Other platforms</td>
+<td class="exccompiler">Other compilers</td>
+<td class="excinterop"><b style="color: #a00000;">No</b></td>
+</tr>
+</table>
+<p>
+<b style="color: #00a000;">Full interoperability</b> means:
+</p>
+<ul>
+<li>C++&nbsp;exceptions can be caught on the Lua side with <tt>pcall()</tt>,
+<tt>lua_pcall()</tt> etc.</li>
+<li>C++&nbsp;exceptions will be converted to the generic Lua error
+<tt>"C++&nbsp;exception"</tt>, unless you use the
+<a href="ext_c_api.html#mode_wrapcfunc">C&nbsp;call wrapper</a> feature.</li>
+<li>It's safe to throw C++&nbsp;exceptions across non-protected Lua frames
+on the C&nbsp;stack. The contents of the C++&nbsp;exception object
+pass through unmodified.</li>
+<li>Lua errors can be caught on the C++ side with <tt>catch(...)</tt>.
+The corresponding Lua error message can be retrieved from the Lua stack.</li>
+<li>Throwing Lua errors across C++ frames is safe. C++ destructors
+will be called.</li>
+</ul>
+<p>
+<b style="color: #c06000;">Limited interoperability</b> means:
+</p>
+<ul>
+<li>C++&nbsp;exceptions can be caught on the Lua side with <tt>pcall()</tt>,
+<tt>lua_pcall()</tt> etc.</li>
+<li>C++&nbsp;exceptions will be converted to the generic Lua error
+<tt>"C++&nbsp;exception"</tt>, unless you use the
+<a href="ext_c_api.html#mode_wrapcfunc">C&nbsp;call wrapper</a> feature.</li>
+<li>C++&nbsp;exceptions will be caught by non-protected Lua frames and
+are rethrown as a generic Lua error. The C++&nbsp;exception object will
+be destroyed.</li>
+<li>Lua errors <b>cannot</b> be caught on the C++ side.</li>
+<li>Throwing Lua errors across C++ frames will <b>not</b> call
+C++ destructors.</li>
+</ul>
+
+<p>
+<b style="color: #a00000;">No interoperability</b> means:
+</p>
+<ul>
+<li>It's <b>not</b> safe to throw C++&nbsp;exceptions across Lua frames.</li>
+<li>C++&nbsp;exceptions <b>cannot</b> be caught on the Lua side.</li>
+<li>Lua errors <b>cannot</b> be caught on the C++ side.</li>
+<li>Throwing Lua errors across C++ frames will <b>not</b> call
+C++ destructors.</li>
+<li>Additionally, on Windows/x86 with SEH-based C++&nbsp;exceptions:
+it's <b>not</b> safe to throw a Lua error across any frames containing
+a C++ function with any try/catch construct or using variables with
+(implicit) destructors. This also applies to any functions which may be
+inlined in such a function. It doesn't matter whether <tt>lua_error()</tt>
+is called inside or outside of a try/catch or whether any object actually
+needs to be destroyed: the SEH chain is corrupted and this will eventually
+lead to the termination of the process.</li>
+</ul>
+<br class="flush">
+</div>
+<div id="foot">
+<hr class="hide">
+Copyright &copy; 2005-2018
+<span class="noprint">
+&middot;
+<a href="contact.html">Contact</a>
+</span>
+</div>
+</body>
+</html>
diff --git a/src/3rdparty/LuaJIT-2.0.5/doc/faq.html b/src/3rdparty/LuaJIT-2.0.5/doc/faq.html
new file mode 100644
index 0000000..9338be4
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/doc/faq.html
@@ -0,0 +1,183 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<title>Frequently Asked Questions (FAQ)</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<meta name="Copyright" content="Copyright (C) 2005-2018">
+<meta name="Language" content="en">
+<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
+<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
+<style type="text/css">
+dd { margin-left: 1.5em; }
+</style>
+</head>
+<body>
+<div id="site">
+<a href="http://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
+</div>
+<div id="head">
+<h1>Frequently Asked Questions (FAQ)</h1>
+</div>
+<div id="nav">
+<ul><li>
+<a href="luajit.html">LuaJIT</a>
+<ul><li>
+<a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="install.html">Installation</a>
+</li><li>
+<a href="running.html">Running</a>
+</li></ul>
+</li><li>
+<a href="extensions.html">Extensions</a>
+<ul><li>
+<a href="ext_ffi.html">FFI Library</a>
+<ul><li>
+<a href="ext_ffi_tutorial.html">FFI Tutorial</a>
+</li><li>
+<a href="ext_ffi_api.html">ffi.* API</a>
+</li><li>
+<a href="ext_ffi_semantics.html">FFI Semantics</a>
+</li></ul>
+</li><li>
+<a href="ext_jit.html">jit.* Library</a>
+</li><li>
+<a href="ext_c_api.html">Lua/C API</a>
+</li></ul>
+</li><li>
+<a href="status.html">Status</a>
+<ul><li>
+<a href="changes.html">Changes</a>
+</li></ul>
+</li><li>
+<a class="current" href="faq.html">FAQ</a>
+</li><li>
+<a href="http://luajit.org/performance.html">Performance <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
+</li></ul>
+</div>
+<div id="main">
+<dl>
+<dt>Q: Where can I learn more about LuaJIT and Lua?</dt>
+<dd>
+<ul style="padding: 0;">
+<li>The <a href="http://luajit.org/list.html"><span class="ext">&raquo;</span>&nbsp;LuaJIT mailing list</a> focuses on topics
+related to LuaJIT.</li>
+<li>The <a href="http://wiki.luajit.org/"><span class="ext">&raquo;</span>&nbsp;LuaJIT wiki</a> gathers community
+resources about LuaJIT.</li>
+<li>News about Lua itself can be found at the
+<a href="http://www.lua.org/lua-l.html"><span class="ext">&raquo;</span>&nbsp;Lua mailing list</a>.
+The mailing list archives are worth checking out for older postings
+about LuaJIT.</li>
+<li>The <a href="http://lua.org"><span class="ext">&raquo;</span>&nbsp;main Lua.org site</a> has complete
+<a href="http://www.lua.org/docs.html"><span class="ext">&raquo;</span>&nbsp;documentation</a> of the language
+and links to books and papers about Lua.</li>
+<li>The community-managed <a href="http://lua-users.org/wiki/"><span class="ext">&raquo;</span>&nbsp;Lua Wiki</a>
+has information about diverse topics.</li>
+</ul>
+</dl>
+
+<dl>
+<dt>Q: Where can I learn more about the compiler technology used by LuaJIT?</dt>
+<dd>
+I'm planning to write more documentation about the internals of LuaJIT.
+In the meantime, please use the following Google Scholar searches
+to find relevant papers:<br>
+Search for: <a href="http://scholar.google.com/scholar?q=Trace+Compiler"><span class="ext">&raquo;</span>&nbsp;Trace Compiler</a><br>
+Search for: <a href="http://scholar.google.com/scholar?q=JIT+Compiler"><span class="ext">&raquo;</span>&nbsp;JIT Compiler</a><br>
+Search for: <a href="http://scholar.google.com/scholar?q=Dynamic+Language+Optimizations"><span class="ext">&raquo;</span>&nbsp;Dynamic Language Optimizations</a><br>
+Search for: <a href="http://scholar.google.com/scholar?q=SSA+Form"><span class="ext">&raquo;</span>&nbsp;SSA Form</a><br>
+Search for: <a href="http://scholar.google.com/scholar?q=Linear+Scan+Register+Allocation"><span class="ext">&raquo;</span>&nbsp;Linear Scan Register Allocation</a><br>
+Here is a list of the <a href="http://article.gmane.org/gmane.comp.lang.lua.general/58908"><span class="ext">&raquo;</span>&nbsp;innovative features in LuaJIT</a>.<br>
+And, you know, reading the source is of course the only way to enlightenment. :-)
+</dd>
+</dl>
+
+<dl>
+<dt>Q: Why do I get this error: "attempt to index global 'arg' (a nil value)"?<br>
+Q: My vararg functions fail after switching to LuaJIT!</dt>
+<dd>LuaJIT is compatible to the Lua 5.1 language standard. It doesn't
+support the implicit <tt>arg</tt> parameter for old-style vararg
+functions from Lua 5.0.<br>Please convert your code to the
+<a href="http://www.lua.org/manual/5.1/manual.html#2.5.9"><span class="ext">&raquo;</span>&nbsp;Lua 5.1
+vararg syntax</a>.</dd>
+</dl>
+
+<dl>
+<dt>Q: Why do I get this error: "bad FPU precision"?<br>
+<dt>Q: I get weird behavior after initializing Direct3D.<br>
+<dt>Q: Some FPU operations crash after I load a Delphi DLL.<br>
+</dt>
+<dd>
+
+DirectX/Direct3D (up to version 9) sets the x87 FPU to single-precision
+mode by default. This violates the Windows ABI and interferes with the
+operation of many programs &mdash; LuaJIT is affected, too. Please make
+sure you always use the <tt>D3DCREATE_FPU_PRESERVE</tt> flag when
+initializing Direct3D.<br>
+
+Direct3D version 10 or higher do not show this behavior anymore.
+Consider testing your application with older versions, too.<br>
+
+Similarly, the Borland/Delphi runtime modifies the FPU control word and
+enables FP exceptions. Of course this violates the Windows ABI, too.
+Please check the Delphi docs for the Set8087CW method.
+
+</dl>
+
+<dl>
+<dt>Q: Sometimes Ctrl-C fails to stop my Lua program. Why?</dt>
+<dd>The interrupt signal handler sets a Lua debug hook. But this is
+currently ignored by compiled code (this will eventually be fixed). If
+your program is running in a tight loop and never falls back to the
+interpreter, the debug hook never runs and can't throw the
+"interrupted!" error.<br> In the meantime you have to press Ctrl-C
+twice to get stop your program. That's similar to when it's stuck
+running inside a C function under the Lua interpreter.</dd>
+</dl>
+
+<dl>
+<dt>Q: Why doesn't my favorite power-patch for Lua apply against LuaJIT?</dt>
+<dd>Because it's a completely redesigned VM and has very little code
+in common with Lua anymore. Also, if the patch introduces changes to
+the Lua semantics, these would need to be reflected everywhere in the
+VM, from the interpreter up to all stages of the compiler.<br> Please
+use only standard Lua language constructs. For many common needs you
+can use source transformations or use wrapper or proxy functions.
+The compiler will happily optimize away such indirections.</dd>
+</dl>
+
+<dl>
+<dt>Q: Lua runs everywhere. Why doesn't LuaJIT support my CPU?</dt>
+<dd>Because it's a compiler &mdash; it needs to generate native
+machine code. This means the code generator must be ported to each
+architecture. And the fast interpreter is written in assembler and
+must be ported, too. This is quite an undertaking.<br>
+The <a href="install.html">install documentation</a> shows the supported
+architectures. Other architectures will follow based on sufficient user
+demand and/or sponsoring.</dd>
+</dl>
+
+<dl>
+<dt>Q: When will feature X be added? When will the next version be released?</dt>
+<dd>When it's ready.<br>
+C'mon, it's open source &mdash; I'm doing it on my own time and you're
+getting it for free. You can either contribute a patch or sponsor
+the development of certain features, if they are important to you.
+</dd>
+</dl>
+<br class="flush">
+</div>
+<div id="foot">
+<hr class="hide">
+Copyright &copy; 2005-2018
+<span class="noprint">
+&middot;
+<a href="contact.html">Contact</a>
+</span>
+</div>
+</body>
+</html>
diff --git a/src/3rdparty/LuaJIT-2.0.5/doc/img/contact.png b/src/3rdparty/LuaJIT-2.0.5/doc/img/contact.png
new file mode 100644
index 0000000..9c73dc5
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/doc/img/contact.png
Binary files differ
diff --git a/src/3rdparty/LuaJIT-2.0.5/doc/install.html b/src/3rdparty/LuaJIT-2.0.5/doc/install.html
new file mode 100644
index 0000000..befffa7
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/doc/install.html
@@ -0,0 +1,645 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<title>Installation</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<meta name="Copyright" content="Copyright (C) 2005-2018">
+<meta name="Language" content="en">
+<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
+<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
+<style type="text/css">
+table.compat {
+ line-height: 1.2;
+ font-size: 80%;
+}
+table.compat td {
+ border: 1px solid #bfcfff;
+ height: 2.5em;
+}
+table.compat tr.compathead td {
+ font-weight: bold;
+ border-bottom: 2px solid #bfcfff;
+}
+tr.compathead td.compatos {
+ vertical-align: top;
+}
+table.compat td.compatcpu {
+ width: 18%;
+ border-right: 2px solid #bfcfff;
+}
+td.compatos {
+ width: 21%;
+ vertical-align: middle;
+}
+td.compatno {
+ background-color: #d0d0d0;
+}
+</style>
+</head>
+<body>
+<div id="site">
+<a href="http://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
+</div>
+<div id="head">
+<h1>Installation</h1>
+</div>
+<div id="nav">
+<ul><li>
+<a href="luajit.html">LuaJIT</a>
+<ul><li>
+<a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
+</li><li>
+<a class="current" href="install.html">Installation</a>
+</li><li>
+<a href="running.html">Running</a>
+</li></ul>
+</li><li>
+<a href="extensions.html">Extensions</a>
+<ul><li>
+<a href="ext_ffi.html">FFI Library</a>
+<ul><li>
+<a href="ext_ffi_tutorial.html">FFI Tutorial</a>
+</li><li>
+<a href="ext_ffi_api.html">ffi.* API</a>
+</li><li>
+<a href="ext_ffi_semantics.html">FFI Semantics</a>
+</li></ul>
+</li><li>
+<a href="ext_jit.html">jit.* Library</a>
+</li><li>
+<a href="ext_c_api.html">Lua/C API</a>
+</li></ul>
+</li><li>
+<a href="status.html">Status</a>
+<ul><li>
+<a href="changes.html">Changes</a>
+</li></ul>
+</li><li>
+<a href="faq.html">FAQ</a>
+</li><li>
+<a href="http://luajit.org/performance.html">Performance <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
+</li></ul>
+</div>
+<div id="main">
+<p>
+LuaJIT is only distributed as a source package. This page explains
+how to build and install LuaJIT with different operating systems
+and C&nbsp;compilers.
+</p>
+<p>
+For the impatient (on POSIX systems):
+</p>
+<pre class="code">
+make &amp;&amp; sudo make install
+</pre>
+<p>
+LuaJIT currently builds out-of-the box on most systems.
+Here's the compatibility matrix for the supported combinations of
+operating systems, CPUs and compilers:
+</p>
+<table class="compat">
+<tr class="compathead">
+<td class="compatcpu">CPU / OS</td>
+<td class="compatos"><a href="#posix">Linux</a> or<br><a href="#android">Android</a></td>
+<td class="compatos"><a href="#posix">*BSD, Other</a></td>
+<td class="compatos"><a href="#posix">OSX 10.4+</a> or<br><a href="#ios">iOS 3.0+</a></td>
+<td class="compatos"><a href="#windows">Windows<br>XP/Vista/7</a></td>
+</tr>
+<tr class="odd separate">
+<td class="compatcpu">x86 (32 bit)</td>
+<td class="compatos">GCC 4.x+<br>GCC 3.4</td>
+<td class="compatos">GCC 4.x+<br>GCC 3.4</td>
+<td class="compatos">XCode 5.0+<br>Clang</td>
+<td class="compatos">MSVC, MSVC/EE<br>WinSDK<br>MinGW, Cygwin</td>
+</tr>
+<tr class="even">
+<td class="compatcpu">x64 (64 bit)</td>
+<td class="compatos">GCC 4.x+</td>
+<td class="compatos">ORBIS (<a href="#ps4">PS4</a>)</td>
+<td class="compatos">XCode 5.0+<br>Clang</td>
+<td class="compatos">MSVC + SDK v7.0<br>WinSDK v7.0</td>
+</tr>
+<tr class="odd">
+<td class="compatcpu"><a href="#cross2">ARMv5+<br>ARM9E+</a></td>
+<td class="compatos">GCC 4.2+</td>
+<td class="compatos">GCC 4.2+<br>PSP2 (<a href="#psvita">PS VITA</a>)</td>
+<td class="compatos">XCode 5.0+<br>Clang</td>
+<td class="compatos compatno">&nbsp;</td>
+</tr>
+<tr class="even">
+<td class="compatcpu"><a href="#cross2">PPC</a></td>
+<td class="compatos">GCC 4.3+</td>
+<td class="compatos">GCC 4.3+<br>GCC 4.1 (<a href="#ps3">PS3</a>)</td>
+<td class="compatos compatno">&nbsp;</td>
+<td class="compatos">XEDK (<a href="#xbox360">Xbox 360</a>)</td>
+</tr>
+<tr class="odd">
+<td class="compatcpu"><a href="#cross2">PPC/e500v2</a></td>
+<td class="compatos">GCC 4.3+</td>
+<td class="compatos">GCC 4.3+</td>
+<td class="compatos compatno">&nbsp;</td>
+<td class="compatos compatno">&nbsp;</td>
+</tr>
+<tr class="even">
+<td class="compatcpu"><a href="#cross2">MIPS</a></td>
+<td class="compatos">GCC 4.3+</td>
+<td class="compatos">GCC 4.3+</td>
+<td class="compatos compatno">&nbsp;</td>
+<td class="compatos compatno">&nbsp;</td>
+</tr>
+</table>
+
+<h2>Configuring LuaJIT</h2>
+<p>
+The standard configuration should work fine for most installations.
+Usually there is no need to tweak the settings. The following files
+hold all user-configurable settings:
+</p>
+<ul>
+<li><tt>src/luaconf.h</tt> sets some configuration variables.</li>
+<li><tt>Makefile</tt> has settings for <b>installing</b> LuaJIT (POSIX
+only).</li>
+<li><tt>src/Makefile</tt> has settings for <b>compiling</b> LuaJIT
+under POSIX, MinGW or Cygwin.</li>
+<li><tt>src/msvcbuild.bat</tt> has settings for compiling LuaJIT with
+MSVC or WinSDK.</li>
+</ul>
+<p>
+Please read the instructions given in these files, before changing
+any settings.
+</p>
+
+<h2 id="posix">POSIX Systems (Linux, OSX, *BSD etc.)</h2>
+<h3>Prerequisites</h3>
+<p>
+Depending on your distribution, you may need to install a package for
+GCC, the development headers and/or a complete SDK. E.g. on a current
+Debian/Ubuntu, install <tt>libc6-dev</tt> with the package manager.
+</p>
+<p>
+Download the current source package of LuaJIT (pick the .tar.gz),
+if you haven't already done so. Move it to a directory of your choice,
+open a terminal window and change to this directory. Now unpack the archive
+and change to the newly created directory:
+</p>
+<pre class="code">
+tar zxf LuaJIT-2.0.5.tar.gz
+cd LuaJIT-2.0.5</pre>
+<h3>Building LuaJIT</h3>
+<p>
+The supplied Makefiles try to auto-detect the settings needed for your
+operating system and your compiler. They need to be run with GNU Make,
+which is probably the default on your system, anyway. Simply run:
+</p>
+<pre class="code">
+make
+</pre>
+<p>
+This always builds a native x86, x64 or PPC binary, depending on the host OS
+you're running this command on. Check the section on
+<a href="#cross">cross-compilation</a> for more options.
+</p>
+<p>
+By default, modules are only searched under the prefix <tt>/usr/local</tt>.
+You can add an extra prefix to the search paths by appending the
+<tt>PREFIX</tt> option, e.g.:
+</p>
+<pre class="code">
+make PREFIX=/home/myself/lj2
+</pre>
+<p>
+Note for OSX: if the <tt>MACOSX_DEPLOYMENT_TARGET</tt> environment
+variable is not set, then it's forced to <tt>10.4</tt>.
+</p>
+<h3>Installing LuaJIT</h3>
+<p>
+The top-level Makefile installs LuaJIT by default under
+<tt>/usr/local</tt>, i.e. the executable ends up in
+<tt>/usr/local/bin</tt> and so on. You need root privileges
+to write to this path. So, assuming sudo is installed on your system,
+run the following command and enter your sudo password:
+</p>
+<pre class="code">
+sudo make install
+</pre>
+<p>
+Otherwise specify the directory prefix as an absolute path, e.g.:
+</p>
+<pre class="code">
+make install PREFIX=/home/myself/lj2
+</pre>
+<p>
+Obviously the prefixes given during build and installation need to be the same.
+</p>
+
+<h2 id="windows">Windows Systems</h2>
+<h3>Prerequisites</h3>
+<p>
+Either install one of the open source SDKs
+(<a href="http://mingw.org/"><span class="ext">&raquo;</span>&nbsp;MinGW</a> or
+<a href="http://www.cygwin.com/"><span class="ext">&raquo;</span>&nbsp;Cygwin</a>), which come with a modified
+GCC plus the required development headers.
+</p>
+<p>
+Or install Microsoft's Visual C++ (MSVC). The freely downloadable
+<a href="http://www.microsoft.com/Express/VC/"><span class="ext">&raquo;</span>&nbsp;Express Edition</a>
+works just fine, but only contains an x86 compiler.
+</p>
+<p>
+The freely downloadable
+<a href="http://msdn.microsoft.com/en-us/windowsserver/bb980924.aspx"><span class="ext">&raquo;</span>&nbsp;Windows SDK</a>
+only comes with command line tools, but this is all you need to build LuaJIT.
+It contains x86 and x64 compilers.
+</p>
+<p>
+Next, download the source package and unpack it using an archive manager
+(e.g. the Windows Explorer) to a directory of your choice.
+</p>
+<h3>Building with MSVC</h3>
+<p>
+Open a "Visual Studio .NET Command Prompt", <tt>cd</tt> to the
+directory where you've unpacked the sources and run these commands:
+</p>
+<pre class="code">
+cd src
+msvcbuild
+</pre>
+<p>
+Then follow the installation instructions below.
+</p>
+<h3>Building with the Windows SDK</h3>
+<p>
+Open a "Windows SDK Command Shell" and select the x86 compiler:
+</p>
+<pre class="code">
+setenv /release /x86
+</pre>
+<p>
+Or select the x64 compiler:
+</p>
+<pre class="code">
+setenv /release /x64
+</pre>
+<p>
+Then <tt>cd</tt> to the directory where you've unpacked the sources
+and run these commands:
+</p>
+<pre class="code">
+cd src
+msvcbuild
+</pre>
+<p>
+Then follow the installation instructions below.
+</p>
+<h3>Building with MinGW or Cygwin</h3>
+<p>
+Open a command prompt window and make sure the MinGW or Cygwin programs
+are in your path. Then <tt>cd</tt> to the directory where
+you've unpacked the sources and run this command for MinGW:
+</p>
+<pre class="code">
+mingw32-make
+</pre>
+<p>
+Or this command for Cygwin:
+</p>
+<pre class="code">
+make
+</pre>
+<p>
+Then follow the installation instructions below.
+</p>
+<h3>Installing LuaJIT</h3>
+<p>
+Copy <tt>luajit.exe</tt> and <tt>lua51.dll</tt> (built in the <tt>src</tt>
+directory) to a newly created directory (any location is ok).
+Add <tt>lua</tt> and <tt>lua\jit</tt> directories below it and copy
+all Lua files from the <tt>src\jit</tt> directory of the distribution
+to the latter directory.
+</p>
+<p>
+There are no hardcoded
+absolute path names &mdash; all modules are loaded relative to the
+directory where <tt>luajit.exe</tt> is installed
+(see <tt>src/luaconf.h</tt>).
+</p>
+
+<h2 id="cross">Cross-compiling LuaJIT</h2>
+<p>
+The GNU Makefile-based build system allows cross-compiling on any host
+for any supported target, as long as both architectures have the same
+pointer size. If you want to cross-compile to any 32 bit target on an
+x64 OS, you need to install the multilib development package (e.g.
+<tt>libc6-dev-i386</tt> on Debian/Ubuntu) and build a 32 bit host part
+(<tt>HOST_CC="gcc -m32"</tt>).
+</p>
+<p>
+You need to specify <tt>TARGET_SYS</tt> whenever the host OS and the
+target OS differ, or you'll get assembler or linker errors. E.g. if
+you're compiling on a Windows or OSX host for embedded Linux or Android,
+you need to add <tt>TARGET_SYS=Linux</tt> to the examples below. For a
+minimal target OS, you may need to disable the built-in allocator in
+<tt>src/Makefile</tt> and use <tt>TARGET_SYS=Other</tt>. Don't forget to
+specify the same <tt>TARGET_SYS</tt> for the install step, too.
+</p>
+<p>
+The examples below only show some popular targets &mdash; please check
+the comments in <tt>src/Makefile</tt> for more details.
+</p>
+<pre class="code">
+# Cross-compile to a 32 bit binary on a multilib x64 OS
+make CC="gcc -m32"
+
+# Cross-compile on Debian/Ubuntu for Windows (mingw32 package)
+make HOST_CC="gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows
+</pre>
+<p id="cross2">
+The <tt>CROSS</tt> prefix allows specifying a standard GNU cross-compile
+toolchain (Binutils, GCC and a matching libc). The prefix may vary
+depending on the <tt>--target</tt> the toolchain was built for (note the
+<tt>CROSS</tt> prefix has a trailing <tt>"-"</tt>). The examples below
+use the canonical toolchain triplets for Linux.
+</p>
+<p>
+Since there's often no easy way to detect CPU features at runtime, it's
+important to compile with the proper CPU or architecture settings. You
+can specify these when building the toolchain yourself. Or add
+<tt>-mcpu=...</tt> or <tt>-march=...</tt> to <tt>TARGET_CFLAGS</tt>. For
+ARM it's important to have the correct <tt>-mfloat-abi=...</tt> setting,
+too. Otherwise LuaJIT may not run at the full performance of your target
+CPU.
+</p>
+<pre class="code">
+# ARM soft-float
+make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabi- \
+ TARGET_CFLAGS="-mfloat-abi=soft"
+
+# ARM soft-float ABI with VFP (example for Cortex-A8)
+make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabi- \
+ TARGET_CFLAGS="-mcpu=cortex-a8 -mfloat-abi=softfp"
+
+# ARM hard-float ABI with VFP (armhf, requires recent toolchain)
+make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabihf-
+
+# PPC
+make HOST_CC="gcc -m32" CROSS=powerpc-linux-gnu-
+# PPC/e500v2 (fast interpreter only)
+make HOST_CC="gcc -m32" CROSS=powerpc-e500v2-linux-gnuspe-
+
+# MIPS big-endian
+make HOST_CC="gcc -m32" CROSS=mips-linux-
+# MIPS little-endian
+make HOST_CC="gcc -m32" CROSS=mipsel-linux-
+</pre>
+<p>
+You can cross-compile for <b id="android">Android</b> using the <a href="http://developer.android.com/sdk/ndk/index.html"><span class="ext">&raquo;</span>&nbsp;Android NDK</a>.
+The environment variables need to match the install locations and the
+desired target platform. E.g. Android&nbsp;4.0 corresponds to ABI level&nbsp;14.
+For details check the folder <tt>docs</tt> in the NDK directory.
+</p>
+<p>
+Only a few common variations for the different CPUs, ABIs and platforms
+are listed. Please use your own judgement for which combination you want
+to build/deploy or which lowest common denominator you want to pick:
+</p>
+<pre class="code">
+# Android/ARM, armeabi (ARMv5TE soft-float), Android 2.2+ (Froyo)
+NDK=/opt/android/ndk
+NDKABI=8
+NDKVER=$NDK/toolchains/arm-linux-androideabi-4.6
+NDKP=$NDKVER/prebuilt/linux-x86/bin/arm-linux-androideabi-
+NDKF="--sysroot $NDK/platforms/android-$NDKABI/arch-arm"
+make HOST_CC="gcc -m32" CROSS=$NDKP TARGET_FLAGS="$NDKF"
+
+# Android/ARM, armeabi-v7a (ARMv7 VFP), Android 4.0+ (ICS)
+NDK=/opt/android/ndk
+NDKABI=14
+NDKVER=$NDK/toolchains/arm-linux-androideabi-4.6
+NDKP=$NDKVER/prebuilt/linux-x86/bin/arm-linux-androideabi-
+NDKF="--sysroot $NDK/platforms/android-$NDKABI/arch-arm"
+NDKARCH="-march=armv7-a -mfloat-abi=softfp -Wl,--fix-cortex-a8"
+make HOST_CC="gcc -m32" CROSS=$NDKP TARGET_FLAGS="$NDKF $NDKARCH"
+
+# Android/MIPS, mips (MIPS32R1 hard-float), Android 4.0+ (ICS)
+NDK=/opt/android/ndk
+NDKABI=14
+NDKVER=$NDK/toolchains/mipsel-linux-android-4.6
+NDKP=$NDKVER/prebuilt/linux-x86/bin/mipsel-linux-android-
+NDKF="--sysroot $NDK/platforms/android-$NDKABI/arch-mips"
+make HOST_CC="gcc -m32" CROSS=$NDKP TARGET_FLAGS="$NDKF"
+
+# Android/x86, x86 (i686 SSE3), Android 4.0+ (ICS)
+NDK=/opt/android/ndk
+NDKABI=14
+NDKVER=$NDK/toolchains/x86-4.6
+NDKP=$NDKVER/prebuilt/linux-x86/bin/i686-linux-android-
+NDKF="--sysroot $NDK/platforms/android-$NDKABI/arch-x86"
+make HOST_CC="gcc -m32" CROSS=$NDKP TARGET_FLAGS="$NDKF"
+</pre>
+<p>
+You can cross-compile for <b id="ios">iOS 3.0+</b> (iPhone/iPad) using the <a href="http://developer.apple.com/devcenter/ios/index.action"><span class="ext">&raquo;</span>&nbsp;iOS SDK</a>:
+</p>
+<p style="font-size: 8pt;">
+Note: <b>the JIT compiler is disabled for iOS</b>, because regular iOS Apps
+are not allowed to generate code at runtime. You'll only get the performance
+of the LuaJIT interpreter on iOS. This is still faster than plain Lua, but
+much slower than the JIT compiler. Please complain to Apple, not me.
+Or use Android. :-p
+</p>
+<pre class="code">
+ISDKP=$(xcrun --sdk iphoneos --show-sdk-path)
+ICC=$(xcrun --sdk iphoneos --find clang)
+ISDKF="-arch armv7 -isysroot $ISDKP"
+make DEFAULT_CC=clang HOST_CC="clang -m32 -arch i386" \
+ CROSS="$(dirname $ICC)/" TARGET_FLAGS="$ISDKF" TARGET_SYS=iOS
+</pre>
+
+<h3 id="consoles">Cross-compiling for consoles</h3>
+<p>
+Building LuaJIT for consoles requires both a supported host compiler
+(x86 or x64) and a cross-compiler (to PPC or ARM) from the official
+console SDK.
+</p>
+<p>
+Due to restrictions on consoles, the JIT compiler is disabled and only
+the fast interpreter is built. This is still faster than plain Lua,
+but much slower than the JIT compiler. The FFI is disabled, too, since
+it's not very useful in such an environment.
+</p>
+<p>
+The following commands build a static library <tt>libluajit.a</tt>,
+which can be linked against your game, just like the Lua library.
+</p>
+<p>
+To cross-compile for <b id="ps3">PS3</b> from a Linux host (requires
+32&nbsp;bit GCC, i.e. multilib Linux/x64) or a Windows host (requires
+32&nbsp;bit MinGW), run this command:
+</p>
+<pre class="code">
+make HOST_CC="gcc -m32" CROSS=ppu-lv2-
+</pre>
+<p>
+To cross-compile for <b id="ps4">PS4</b> from a Windows host,
+open a "Visual Studio .NET Command Prompt" (64&nbsp;bit host compiler),
+<tt>cd</tt> to the directory where you've unpacked the sources and
+run the following commands:
+</p>
+<pre class="code">
+cd src
+ps4build
+</pre>
+<p>
+To cross-compile for <b id="psvita">PS Vita</b> from a Windows host,
+open a "Visual Studio .NET Command Prompt" (32&nbsp;bit host compiler),
+<tt>cd</tt> to the directory where you've unpacked the sources and
+run the following commands:
+</p>
+<pre class="code">
+cd src
+psvitabuild
+</pre>
+<p>
+To cross-compile for <b id="xbox360">Xbox 360</b> from a Windows host,
+open a "Visual Studio .NET Command Prompt" (32&nbsp;bit host compiler),
+<tt>cd</tt> to the directory where you've unpacked the sources and run
+the following commands:
+</p>
+<pre class="code">
+cd src
+xedkbuild
+</pre>
+
+<h2 id="embed">Embedding LuaJIT</h2>
+<p>
+LuaJIT is API-compatible with Lua 5.1. If you've already embedded Lua
+into your application, you probably don't need to do anything to switch
+to LuaJIT, except link with a different library:
+</p>
+<ul>
+<li>It's strongly suggested to build LuaJIT separately using the supplied
+build system. Please do <em>not</em> attempt to integrate the individual
+source files into your build tree. You'll most likely get the internal build
+dependencies wrong or mess up the compiler flags. Treat LuaJIT like any
+other external library and link your application with either the dynamic
+or static library, depending on your needs.</li>
+<li>If you want to load C modules compiled for plain Lua
+with <tt>require()</tt>, you need to make sure the public symbols
+(e.g. <tt>lua_pushnumber</tt>) are exported, too:
+<ul><li>On POSIX systems you can either link to the shared library
+or link the static library into your application. In the latter case
+you'll need to export all public symbols from your main executable
+(e.g. <tt>-Wl,-E</tt> on Linux) and add the external dependencies
+(e.g. <tt>-lm -ldl</tt> on Linux).</li>
+<li>Since Windows symbols are bound to a specific DLL name, you need to
+link to the <tt>lua51.dll</tt> created by the LuaJIT build (do not rename
+the DLL). You may link LuaJIT statically on Windows only if you don't
+intend to load Lua/C modules at runtime.
+</li></ul>
+</li>
+<li>
+If you're building a 64 bit application on OSX which links directly or
+indirectly against LuaJIT, you need to link your main executable
+with these flags:
+<pre class="code">
+-pagezero_size 10000 -image_base 100000000
+</pre>
+Also, it's recommended to <tt>rebase</tt> all (self-compiled) shared libraries
+which are loaded at runtime on OSX/x64 (e.g. C extension modules for Lua).
+See: <tt>man rebase</tt>
+</li>
+</ul>
+<p>Additional hints for initializing LuaJIT using the C API functions:</p>
+<ul>
+<li>Here's a
+<a href="http://lua-users.org/wiki/SimpleLuaApiExample"><span class="ext">&raquo;</span>&nbsp;simple example</a>
+for embedding Lua or LuaJIT into your application.</li>
+<li>Make sure you use <tt>luaL_newstate</tt>. Avoid using
+<tt>lua_newstate</tt>, since this uses the (slower) default memory
+allocator from your system (no support for this on x64).</li>
+<li>Make sure you use <tt>luaL_openlibs</tt> and not the old Lua 5.0 style
+of calling <tt>luaopen_base</tt> etc. directly.</li>
+<li>To change or extend the list of standard libraries to load, copy
+<tt>src/lib_init.c</tt> to your project and modify it accordingly.
+Make sure the <tt>jit</tt> library is loaded or the JIT compiler
+will not be activated.</li>
+<li>The <tt>bit.*</tt> module for bitwise operations
+is already built-in. There's no need to statically link
+<a href="http://bitop.luajit.org/"><span class="ext">&raquo;</span>&nbsp;Lua BitOp</a> to your application.</li>
+</ul>
+
+<h2 id="distro">Hints for Distribution Maintainers</h2>
+<p>
+The LuaJIT build system has extra provisions for the needs of most
+POSIX-based distributions. If you're a package maintainer for
+a distribution, <em>please</em> make use of these features and
+avoid patching, subverting, autotoolizing or messing up the build system
+in unspeakable ways.
+</p>
+<p>
+There should be absolutely no need to patch <tt>luaconf.h</tt> or any
+of the Makefiles. And please do not hand-pick files for your packages &mdash;
+simply use whatever <tt>make install</tt> creates. There's a reason
+for all of the files <em>and</em> directories it creates.
+</p>
+<p>
+The build system uses GNU make and auto-detects most settings based on
+the host you're building it on. This should work fine for native builds,
+even when sandboxed. You may need to pass some of the following flags to
+<em>both</em> the <tt>make</tt> and the <tt>make install</tt> command lines
+for a regular distribution build:
+</p>
+<ul>
+<li><tt>PREFIX</tt> overrides the installation path and should usually
+be set to <tt>/usr</tt>. Setting this also changes the module paths and
+the paths needed to locate the shared library.</li>
+<li><tt>DESTDIR</tt> is an absolute path which allows you to install
+to a shadow tree instead of the root tree of the build system.</li>
+<li><tt>MULTILIB</tt> sets the architecture-specific library path component
+for multilib systems. The default is <tt>lib</tt>.</li>
+<li>Have a look at the top-level <tt>Makefile</tt> and <tt>src/Makefile</tt>
+for additional variables to tweak. The following variables <em>may</em> be
+overridden, but it's <em>not</em> recommended, except for special needs
+like cross-builds:
+<tt>BUILDMODE, CC, HOST_CC, STATIC_CC, DYNAMIC_CC, CFLAGS, HOST_CFLAGS,
+TARGET_CFLAGS, LDFLAGS, HOST_LDFLAGS, TARGET_LDFLAGS, TARGET_SHLDFLAGS,
+TARGET_FLAGS, LIBS, HOST_LIBS, TARGET_LIBS, CROSS, HOST_SYS, TARGET_SYS
+</tt></li>
+</ul>
+<p>
+The build system has a special target for an amalgamated build, i.e.
+<tt>make amalg</tt>. This compiles the LuaJIT core as one huge C file
+and allows GCC to generate faster and shorter code. Alas, this requires
+lots of memory during the build. This may be a problem for some users,
+that's why it's not enabled by default. But it shouldn't be a problem for
+most build farms. It's recommended that binary distributions use this
+target for their LuaJIT builds.
+</p>
+<p>
+The tl;dr version of the above:
+</p>
+<pre class="code">
+make amalg PREFIX=/usr && \
+make install PREFIX=/usr DESTDIR=/tmp/buildroot
+</pre>
+<p>
+Finally, if you encounter any difficulties, please
+<a href="contact.html">contact me</a> first, instead of releasing a broken
+package onto unsuspecting users. Because they'll usually gonna complain
+to me (the upstream) and not you (the package maintainer), anyway.
+</p>
+<br class="flush">
+</div>
+<div id="foot">
+<hr class="hide">
+Copyright &copy; 2005-2018
+<span class="noprint">
+&middot;
+<a href="contact.html">Contact</a>
+</span>
+</div>
+</body>
+</html>
diff --git a/src/3rdparty/LuaJIT-2.0.5/doc/luajit.html b/src/3rdparty/LuaJIT-2.0.5/doc/luajit.html
new file mode 100644
index 0000000..d8f531d
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/doc/luajit.html
@@ -0,0 +1,233 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<title>LuaJIT</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<meta name="Copyright" content="Copyright (C) 2005-2018">
+<meta name="Language" content="en">
+<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
+<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
+<meta name="description" content="LuaJIT is a Just-In-Time (JIT) compiler for the Lua language.">
+<style type="text/css">
+table.feature {
+ width: inherit;
+ line-height: 1.2;
+ margin: 0;
+}
+table.feature td {
+ width: 80px;
+ height: 40px;
+ vertical-align: middle;
+ text-align: center;
+ font-weight: bold;
+ border: 4px solid #e6ecff;
+ border-radius: 12px;
+}
+table.os td {
+ background: #7080d0;
+ background-image: linear-gradient(#4060c0 10%, #b0b0ff 95%);
+ background-image: -moz-linear-gradient(#4060c0 10%, #b0b0ff 95%);
+ background-image: -webkit-linear-gradient(#4060c0 10%, #b0b0ff 95%);
+ background-image: -o-linear-gradient(#4060c0 10%, #b0b0ff 95%);
+ background-image: -ms-linear-gradient(#4060c0 10%, #b0b0ff 95%);
+}
+table.os1 td {
+ color: #ffff80;
+}
+table.os2 td {
+ color: #ffa040;
+}
+table.os3 td {
+ color: #40ffff;
+}
+table.compiler td {
+ color: #2080ff;
+ background: #62bf41;
+ background-image: linear-gradient(#62bf41 10%, #b0ffb0 95%);
+ background-image: -moz-linear-gradient(#62bf41 10%, #b0ffb0 95%);
+ background-image: -webkit-linear-gradient(#62bf41 10%, #b0ffb0 95%);
+ background-image: -o-linear-gradient(#62bf41 10%, #b0ffb0 95%);
+ background-image: -ms-linear-gradient(#62bf41 10%, #b0ffb0 95%);
+}
+table.cpu td {
+ color: #ffff00;
+ background: #cf7251;
+ background-image: linear-gradient(#bf6241 10%, #ffb0b0 95%);
+ background-image: -moz-linear-gradient(#bf6241 10%, #ffb0b0 95%);
+ background-image: -webkit-linear-gradient(#bf6241 10%, #ffb0b0 95%);
+ background-image: -o-linear-gradient(#bf6241 10%, #ffb0b0 95%);
+ background-image: -ms-linear-gradient(#bf6241 10%, #ffb0b0 95%);
+}
+table.fcompat td {
+ color: #2060e0;
+ background: #61cfcf;
+ background-image: linear-gradient(#41bfbf 10%, #b0ffff 95%);
+ background-image: -moz-linear-gradient(#41bfbf 10%, #b0ffff 95%);
+ background-image: -webkit-linear-gradient(#41bfbf 10%, #b0ffff 95%);
+ background-image: -o-linear-gradient(#41bfbf 10%, #b0ffff 95%);
+ background-image: -ms-linear-gradient(#41bfbf 10%, #b0ffff 95%);
+}
+table.stats td {
+ color: #ffffff;
+ background: #a0a0a0;
+ background-image: linear-gradient(#808080 10%, #d0d0d0 95%);
+ background-image: -moz-linear-gradient(#808080 10%, #d0d0d0 95%);
+ background-image: -webkit-linear-gradient(#808080 10%, #d0d0d0 95%);
+ background-image: -o-linear-gradient(#808080 10%, #d0d0d0 95%);
+ background-image: -ms-linear-gradient(#808080 10%, #d0d0d0 95%);
+}
+table.stats td.speed {
+ color: #ff4020;
+}
+table.stats td.kb {
+ color: #ffff80;
+ background: #808080;
+ background-image: linear-gradient(#606060 10%, #c0c0c0 95%);
+ background-image: -moz-linear-gradient(#606060 10%, #c0c0c0 95%);
+ background-image: -webkit-linear-gradient(#606060 10%, #c0c0c0 95%);
+ background-image: -o-linear-gradient(#606060 10%, #c0c0c0 95%);
+ background-image: -ms-linear-gradient(#606060 10%, #c0c0c0 95%);
+}
+table.feature small {
+ font-size: 50%;
+}
+</style>
+</head>
+<body>
+<div id="site">
+<a href="http://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
+</div>
+<div id="head">
+<h1>LuaJIT</h1>
+</div>
+<div id="nav">
+<ul><li>
+<a class="current" href="luajit.html">LuaJIT</a>
+<ul><li>
+<a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="install.html">Installation</a>
+</li><li>
+<a href="running.html">Running</a>
+</li></ul>
+</li><li>
+<a href="extensions.html">Extensions</a>
+<ul><li>
+<a href="ext_ffi.html">FFI Library</a>
+<ul><li>
+<a href="ext_ffi_tutorial.html">FFI Tutorial</a>
+</li><li>
+<a href="ext_ffi_api.html">ffi.* API</a>
+</li><li>
+<a href="ext_ffi_semantics.html">FFI Semantics</a>
+</li></ul>
+</li><li>
+<a href="ext_jit.html">jit.* Library</a>
+</li><li>
+<a href="ext_c_api.html">Lua/C API</a>
+</li></ul>
+</li><li>
+<a href="status.html">Status</a>
+<ul><li>
+<a href="changes.html">Changes</a>
+</li></ul>
+</li><li>
+<a href="faq.html">FAQ</a>
+</li><li>
+<a href="http://luajit.org/performance.html">Performance <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
+</li></ul>
+</div>
+<div id="main">
+<p>
+LuaJIT is a <b>Just-In-Time Compiler</b> (JIT) for the
+<a href="http://www.lua.org/"><span class="ext">&raquo;</span>&nbsp;Lua</a> programming language.
+Lua is a powerful, dynamic and light-weight programming language.
+It may be embedded or used as a general-purpose, stand-alone language.
+</p>
+<p>
+LuaJIT is Copyright &copy; 2005-2018 Mike Pall, released under the
+<a href="http://www.opensource.org/licenses/mit-license.php"><span class="ext">&raquo;</span>&nbsp;MIT open source license</a>.
+</p>
+<p>
+</p>
+
+<h2>Compatibility</h2>
+<table class="feature os os1">
+<tr><td>Windows</td><td>Linux</td><td>BSD</td><td>OSX</td><td>POSIX</td></tr>
+</table>
+<table class="feature os os2">
+<tr><td><span style="font-size:90%;">Embedded</span></td><td>Android</td><td>iOS</td></tr>
+</table>
+<table class="feature os os3">
+<tr><td>PS3</td><td>PS4</td><td>PS Vita</td><td>Xbox 360</td></tr>
+</table>
+<table class="feature compiler">
+<tr><td>GCC</td><td>CLANG<br>LLVM</td><td>MSVC</td></tr>
+</table>
+<table class="feature cpu">
+<tr><td>x86</td><td>x64</td><td>ARM</td><td>PPC</td><td>e500</td><td>MIPS</td></tr>
+</table>
+<table class="feature fcompat">
+<tr><td>Lua&nbsp;5.1<br>API+ABI</td><td>+&nbsp;JIT</td><td>+&nbsp;BitOp</td><td>+&nbsp;FFI</td><td>Drop-in<br>DLL/.so</td></tr>
+</table>
+
+<h2>Overview</h2>
+<table class="feature stats">
+<tr>
+<td class="speed">3x<br>-&nbsp;&nbsp;100x</td>
+<td class="kb">115&nbsp;<small>KB</small><br>VM</td>
+<td class="kb">90&nbsp;<small>KB</small><br>JIT</td>
+<td class="kloc">63&nbsp;<small>KLOC</small><br>C</td>
+<td class="kloc">24&nbsp;<small>KLOC</small><br>ASM</td>
+<td class="kloc">11&nbsp;<small>KLOC</small><br>Lua</td>
+</tr>
+</table>
+<p style="margin-top: 1em;">
+LuaJIT has been successfully used as a <b>scripting middleware</b> in
+games, appliances, network and graphics apps, numerical simulations,
+trading platforms and many other specialty applications. It scales from
+embedded devices, smartphones, desktops up to server farms. It combines
+high flexibility with <a href="http://luajit.org/performance.html"><span class="ext">&raquo;</span>&nbsp;high performance</a>
+and an unmatched <b>low memory footprint</b>.
+</p>
+<p>
+LuaJIT has been in continuous development since 2005. It's widely
+considered to be <b>one of the fastest dynamic language
+implementations</b>. It has outperformed other dynamic languages on many
+cross-language benchmarks since its first release &mdash; often by a
+substantial margin.
+</p>
+<p>
+For <b>LuaJIT 2.0</b>, the whole VM has been rewritten from the ground up
+and relentlessly optimized for performance. It combines a <b>high-speed
+interpreter</b>, written in assembler, with a <b>state-of-the-art JIT
+compiler</b>.
+</p>
+<p>
+An innovative <b>trace compiler</b> is integrated with advanced,
+SSA-based optimizations and highly tuned code generation backends.
+A substantial reduction of the overhead associated with dynamic languages
+allows it to break into the performance range traditionally reserved for
+offline, static language compilers.
+</p>
+
+<h2>More ...</h2>
+<p>
+Please select a sub-topic in the navigation bar to learn more about LuaJIT.
+</p>
+<br class="flush">
+</div>
+<div id="foot">
+<hr class="hide">
+Copyright &copy; 2005-2018
+<span class="noprint">
+&middot;
+<a href="contact.html">Contact</a>
+</span>
+</div>
+</body>
+</html>
diff --git a/src/3rdparty/LuaJIT-2.0.5/doc/running.html b/src/3rdparty/LuaJIT-2.0.5/doc/running.html
new file mode 100644
index 0000000..08d7f71
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/doc/running.html
@@ -0,0 +1,305 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<title>Running LuaJIT</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<meta name="Copyright" content="Copyright (C) 2005-2018">
+<meta name="Language" content="en">
+<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
+<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
+<style type="text/css">
+table.opt {
+ line-height: 1.2;
+}
+tr.opthead td {
+ font-weight: bold;
+}
+td.flag_name {
+ width: 4em;
+}
+td.flag_level {
+ width: 2em;
+ text-align: center;
+}
+td.param_name {
+ width: 6em;
+}
+td.param_default {
+ width: 4em;
+ text-align: right;
+}
+</style>
+</head>
+<body>
+<div id="site">
+<a href="http://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
+</div>
+<div id="head">
+<h1>Running LuaJIT</h1>
+</div>
+<div id="nav">
+<ul><li>
+<a href="luajit.html">LuaJIT</a>
+<ul><li>
+<a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="install.html">Installation</a>
+</li><li>
+<a class="current" href="running.html">Running</a>
+</li></ul>
+</li><li>
+<a href="extensions.html">Extensions</a>
+<ul><li>
+<a href="ext_ffi.html">FFI Library</a>
+<ul><li>
+<a href="ext_ffi_tutorial.html">FFI Tutorial</a>
+</li><li>
+<a href="ext_ffi_api.html">ffi.* API</a>
+</li><li>
+<a href="ext_ffi_semantics.html">FFI Semantics</a>
+</li></ul>
+</li><li>
+<a href="ext_jit.html">jit.* Library</a>
+</li><li>
+<a href="ext_c_api.html">Lua/C API</a>
+</li></ul>
+</li><li>
+<a href="status.html">Status</a>
+<ul><li>
+<a href="changes.html">Changes</a>
+</li></ul>
+</li><li>
+<a href="faq.html">FAQ</a>
+</li><li>
+<a href="http://luajit.org/performance.html">Performance <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
+</li></ul>
+</div>
+<div id="main">
+<p>
+LuaJIT has only a single stand-alone executable, called <tt>luajit</tt> on
+POSIX systems or <tt>luajit.exe</tt> on Windows. It can be used to run simple
+Lua statements or whole Lua applications from the command line. It has an
+interactive mode, too.
+</p>
+
+<h2 id="options">Command Line Options</h2>
+<p>
+The <tt>luajit</tt> stand-alone executable is just a slightly modified
+version of the regular <tt>lua</tt> stand-alone executable.
+It supports the same basic options, too. <tt>luajit&nbsp;-h</tt>
+prints a short list of the available options. Please have a look at the
+<a href="http://www.lua.org/manual/5.1/manual.html#6"><span class="ext">&raquo;</span>&nbsp;Lua manual</a>
+for details.
+</p>
+<p>
+LuaJIT has some additional options:
+</p>
+
+<h3 id="opt_b"><tt>-b[options] input output</tt></h3>
+<p>
+This option saves or lists bytecode. The following additional options
+are accepted:
+</p>
+<ul>
+<li><tt>-l</tt> &mdash; Only list bytecode.</li>
+<li><tt>-s</tt> &mdash; Strip debug info (this is the default).</li>
+<li><tt>-g</tt> &mdash; Keep debug info.</li>
+<li><tt>-n name</tt> &mdash; Set module name (default: auto-detect from input name)</li>
+<li><tt>-t type</tt> &mdash; Set output file type (default: auto-detect from output name).</li>
+<li><tt>-a arch</tt> &mdash; Override architecture for object files (default: native).</li>
+<li><tt>-o os</tt> &mdash; Override OS for object files (default: native).</li>
+<li><tt>-e chunk</tt> &mdash; Use chunk string as input.</li>
+<li><tt>-</tt> (a single minus sign) &mdash; Use stdin as input and/or stdout as output.</li>
+</ul>
+<p>
+The output file type is auto-detected from the extension of the output
+file name:
+</p>
+<ul>
+<li><tt>c</tt> &mdash; C source file, exported bytecode data.</li>
+<li><tt>h</tt> &mdash; C header file, static bytecode data.</li>
+<li><tt>obj</tt> or <tt>o</tt> &mdash; Object file, exported bytecode data
+(OS- and architecture-specific).</li>
+<li><tt>raw</tt> or any other extension &mdash; Raw bytecode file (portable).
+</ul>
+<p>
+Notes:
+</p>
+<ul>
+<li>See also <a href="extensions.html#string_dump">string.dump()</a>
+for information on bytecode portability and compatibility.</li>
+<li>A file in raw bytecode format is auto-detected and can be loaded like
+any Lua source file. E.g. directly from the command line or with
+<tt>loadfile()</tt>, <tt>dofile()</tt> etc.</li>
+<li>To statically embed the bytecode of a module in your application,
+generate an object file and just link it with your application.</li>
+<li>On most ELF-based systems (e.g. Linux) you need to explicitly export the
+global symbols when linking your application, e.g. with: <tt>-Wl,-E</tt></li>
+<li><tt>require()</tt> tries to load embedded bytecode data from exported
+symbols (in <tt>*.exe</tt> or <tt>lua51.dll</tt> on Windows) and from
+shared libraries in <tt>package.cpath</tt>.</li>
+</ul>
+<p>
+Typical usage examples:
+</p>
+<pre class="code">
+luajit -b test.lua test.out # Save bytecode to test.out
+luajit -bg test.lua test.out # Keep debug info
+luajit -be "print('hello world')" test.out # Save cmdline script
+
+luajit -bl test.lua # List to stdout
+luajit -bl test.lua test.txt # List to test.txt
+luajit -ble "print('hello world')" # List cmdline script
+
+luajit -b test.lua test.obj # Generate object file
+# Link test.obj with your application and load it with require("test")
+</pre>
+
+<h3 id="opt_j"><tt>-j cmd[=arg[,arg...]]</tt></h3>
+<p>
+This option performs a LuaJIT control command or activates one of the
+loadable extension modules. The command is first looked up in the
+<tt>jit.*</tt> library. If no matching function is found, a module
+named <tt>jit.&lt;cmd&gt;</tt> is loaded and the <tt>start()</tt>
+function of the module is called with the specified arguments (if
+any). The space between <tt>-j</tt> and <tt>cmd</tt> is optional.
+</p>
+<p>
+Here are the available LuaJIT control commands:
+</p>
+<ul>
+<li id="j_on"><tt>-jon</tt> &mdash; Turns the JIT compiler on (default).</li>
+<li id="j_off"><tt>-joff</tt> &mdash; Turns the JIT compiler off (only use the interpreter).</li>
+<li id="j_flush"><tt>-jflush</tt> &mdash; Flushes the whole cache of compiled code.</li>
+<li id="j_v"><tt>-jv</tt> &mdash; Shows verbose information about the progress of the JIT compiler.</li>
+<li id="j_dump"><tt>-jdump</tt> &mdash; Dumps the code and structures used in various compiler stages.</li>
+</ul>
+<p>
+The <tt>-jv</tt> and <tt>-jdump</tt> commands are extension modules
+written in Lua. They are mainly used for debugging the JIT compiler
+itself. For a description of their options and output format, please
+read the comment block at the start of their source.
+They can be found in the <tt>lib</tt> directory of the source
+distribution or installed under the <tt>jit</tt> directory. By default
+this is <tt>/usr/local/share/luajit-2.0.5/jit</tt> on POSIX
+systems.
+</p>
+
+<h3 id="opt_O"><tt>-O[level]</tt><br>
+<tt>-O[+]flag</tt>&nbsp;&nbsp;&nbsp;<tt>-O-flag</tt><br>
+<tt>-Oparam=value</tt></h3>
+<p>
+This options allows fine-tuned control of the optimizations used by
+the JIT compiler. This is mainly intended for debugging LuaJIT itself.
+Please note that the JIT compiler is extremely fast (we are talking
+about the microsecond to millisecond range). Disabling optimizations
+doesn't have any visible impact on its overhead, but usually generates
+code that runs slower.
+</p>
+<p>
+The first form sets an optimization level &mdash; this enables a
+specific mix of optimization flags. <tt>-O0</tt> turns off all
+optimizations and higher numbers enable more optimizations. Omitting
+the level (i.e. just <tt>-O</tt>) sets the default optimization level,
+which is <tt>-O3</tt> in the current version.
+</p>
+<p>
+The second form adds or removes individual optimization flags.
+The third form sets a parameter for the VM or the JIT compiler
+to a specific value.
+</p>
+<p>
+You can either use this option multiple times (like <tt>-Ocse
+-O-dce -Ohotloop=10</tt>) or separate several settings with a comma
+(like <tt>-O+cse,-dce,hotloop=10</tt>). The settings are applied from
+left to right and later settings override earlier ones. You can freely
+mix the three forms, but note that setting an optimization level
+overrides all earlier flags.
+</p>
+<p>
+Here are the available flags and at what optimization levels they
+are enabled:
+</p>
+<table class="opt">
+<tr class="opthead">
+<td class="flag_name">Flag</td>
+<td class="flag_level">-O1</td>
+<td class="flag_level">-O2</td>
+<td class="flag_level">-O3</td>
+<td class="flag_desc">&nbsp;</td>
+</tr>
+<tr class="odd separate">
+<td class="flag_name">fold</td><td class="flag_level">&bull;</td><td class="flag_level">&bull;</td><td class="flag_level">&bull;</td><td class="flag_desc">Constant Folding, Simplifications and Reassociation</td></tr>
+<tr class="even">
+<td class="flag_name">cse</td><td class="flag_level">&bull;</td><td class="flag_level">&bull;</td><td class="flag_level">&bull;</td><td class="flag_desc">Common-Subexpression Elimination</td></tr>
+<tr class="odd">
+<td class="flag_name">dce</td><td class="flag_level">&bull;</td><td class="flag_level">&bull;</td><td class="flag_level">&bull;</td><td class="flag_desc">Dead-Code Elimination</td></tr>
+<tr class="even">
+<td class="flag_name">narrow</td><td class="flag_level">&nbsp;</td><td class="flag_level">&bull;</td><td class="flag_level">&bull;</td><td class="flag_desc">Narrowing of numbers to integers</td></tr>
+<tr class="odd">
+<td class="flag_name">loop</td><td class="flag_level">&nbsp;</td><td class="flag_level">&bull;</td><td class="flag_level">&bull;</td><td class="flag_desc">Loop Optimizations (code hoisting)</td></tr>
+<tr class="even">
+<td class="flag_name">fwd</td><td class="flag_level">&nbsp;</td><td class="flag_level">&nbsp;</td><td class="flag_level">&bull;</td><td class="flag_desc">Load Forwarding (L2L) and Store Forwarding (S2L)</td></tr>
+<tr class="odd">
+<td class="flag_name">dse</td><td class="flag_level">&nbsp;</td><td class="flag_level">&nbsp;</td><td class="flag_level">&bull;</td><td class="flag_desc">Dead-Store Elimination</td></tr>
+<tr class="even">
+<td class="flag_name">abc</td><td class="flag_level">&nbsp;</td><td class="flag_level">&nbsp;</td><td class="flag_level">&bull;</td><td class="flag_desc">Array Bounds Check Elimination</td></tr>
+<tr class="odd">
+<td class="flag_name">sink</td><td class="flag_level">&nbsp;</td><td class="flag_level">&nbsp;</td><td class="flag_level">&bull;</td><td class="flag_desc">Allocation/Store Sinking</td></tr>
+<tr class="even">
+<td class="flag_name">fuse</td><td class="flag_level">&nbsp;</td><td class="flag_level">&nbsp;</td><td class="flag_level">&bull;</td><td class="flag_desc">Fusion of operands into instructions</td></tr>
+</table>
+<p>
+Here are the parameters and their default settings:
+</p>
+<table class="opt">
+<tr class="opthead">
+<td class="param_name">Parameter</td>
+<td class="param_default">Default</td>
+<td class="param_desc">&nbsp;</td>
+</tr>
+<tr class="odd separate">
+<td class="param_name">maxtrace</td><td class="param_default">1000</td><td class="param_desc">Max. number of traces in the cache</td></tr>
+<tr class="even">
+<td class="param_name">maxrecord</td><td class="param_default">4000</td><td class="param_desc">Max. number of recorded IR instructions</td></tr>
+<tr class="odd">
+<td class="param_name">maxirconst</td><td class="param_default">500</td><td class="param_desc">Max. number of IR constants of a trace</td></tr>
+<tr class="even">
+<td class="param_name">maxside</td><td class="param_default">100</td><td class="param_desc">Max. number of side traces of a root trace</td></tr>
+<tr class="odd">
+<td class="param_name">maxsnap</td><td class="param_default">500</td><td class="param_desc">Max. number of snapshots for a trace</td></tr>
+<tr class="even separate">
+<td class="param_name">hotloop</td><td class="param_default">56</td><td class="param_desc">Number of iterations to detect a hot loop or hot call</td></tr>
+<tr class="odd">
+<td class="param_name">hotexit</td><td class="param_default">10</td><td class="param_desc">Number of taken exits to start a side trace</td></tr>
+<tr class="even">
+<td class="param_name">tryside</td><td class="param_default">4</td><td class="param_desc">Number of attempts to compile a side trace</td></tr>
+<tr class="odd separate">
+<td class="param_name">instunroll</td><td class="param_default">4</td><td class="param_desc">Max. unroll factor for instable loops</td></tr>
+<tr class="even">
+<td class="param_name">loopunroll</td><td class="param_default">15</td><td class="param_desc">Max. unroll factor for loop ops in side traces</td></tr>
+<tr class="odd">
+<td class="param_name">callunroll</td><td class="param_default">3</td><td class="param_desc">Max. unroll factor for pseudo-recursive calls</td></tr>
+<tr class="even">
+<td class="param_name">recunroll</td><td class="param_default">2</td><td class="param_desc">Min. unroll factor for true recursion</td></tr>
+<tr class="odd separate">
+<td class="param_name">sizemcode</td><td class="param_default">32</td><td class="param_desc">Size of each machine code area in KBytes (Windows: 64K)</td></tr>
+<tr class="even">
+<td class="param_name">maxmcode</td><td class="param_default">512</td><td class="param_desc">Max. total size of all machine code areas in KBytes</td></tr>
+</table>
+<br class="flush">
+</div>
+<div id="foot">
+<hr class="hide">
+Copyright &copy; 2005-2018
+<span class="noprint">
+&middot;
+<a href="contact.html">Contact</a>
+</span>
+</div>
+</body>
+</html>
diff --git a/src/3rdparty/LuaJIT-2.0.5/doc/status.html b/src/3rdparty/LuaJIT-2.0.5/doc/status.html
new file mode 100644
index 0000000..ea61db1
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/doc/status.html
@@ -0,0 +1,109 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<title>Status</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<meta name="Copyright" content="Copyright (C) 2005-2018">
+<meta name="Language" content="en">
+<link rel="stylesheet" type="text/css" href="bluequad.css" media="screen">
+<link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print">
+<style type="text/css">
+ul li { padding-bottom: 0.3em; }
+</style>
+</head>
+<body>
+<div id="site">
+<a href="http://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
+</div>
+<div id="head">
+<h1>Status</h1>
+</div>
+<div id="nav">
+<ul><li>
+<a href="luajit.html">LuaJIT</a>
+<ul><li>
+<a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="install.html">Installation</a>
+</li><li>
+<a href="running.html">Running</a>
+</li></ul>
+</li><li>
+<a href="extensions.html">Extensions</a>
+<ul><li>
+<a href="ext_ffi.html">FFI Library</a>
+<ul><li>
+<a href="ext_ffi_tutorial.html">FFI Tutorial</a>
+</li><li>
+<a href="ext_ffi_api.html">ffi.* API</a>
+</li><li>
+<a href="ext_ffi_semantics.html">FFI Semantics</a>
+</li></ul>
+</li><li>
+<a href="ext_jit.html">jit.* Library</a>
+</li><li>
+<a href="ext_c_api.html">Lua/C API</a>
+</li></ul>
+</li><li>
+<a class="current" href="status.html">Status</a>
+<ul><li>
+<a href="changes.html">Changes</a>
+</li></ul>
+</li><li>
+<a href="faq.html">FAQ</a>
+</li><li>
+<a href="http://luajit.org/performance.html">Performance <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://wiki.luajit.org/">Wiki <span class="ext">&raquo;</span></a>
+</li><li>
+<a href="http://luajit.org/list.html">Mailing List <span class="ext">&raquo;</span></a>
+</li></ul>
+</div>
+<div id="main">
+<p>
+<span style="color: #0000c0;">LuaJIT&nbsp;2.0</span> is the current
+<span style="color: #0000c0;">stable branch</span>. This branch is in
+feature-freeze &mdash; new features will only be added to LuaJIT&nbsp;2.1.
+</p>
+
+<h2>Current Status</h2>
+<p>
+LuaJIT ought to run all Lua&nbsp;5.1-compatible source code just fine.
+It's considered a serious bug if the VM crashes or produces unexpected
+results &mdash; please report this.
+</p>
+<p>
+Known incompatibilities and issues in LuaJIT&nbsp;2.0:
+</p>
+<ul>
+<li>
+There are some differences in <b>implementation-defined</b> behavior.
+These either have a good reason, are arbitrary design choices
+or are due to quirks in the VM. The latter cases may get fixed if a
+demonstrable need is shown.
+</li>
+<li>
+The Lua <b>debug API</b> is missing a couple of features (return
+hooks for non-Lua functions) and shows slightly different behavior
+in LuaJIT (no per-coroutine hooks, no tail call counting).
+</li>
+<li>
+Currently some <b>out-of-memory</b> errors from <b>on-trace code</b> are not
+handled correctly. The error may fall through an on-trace
+<tt>pcall</tt> or it may be passed on to the function set with
+<tt>lua_atpanic</tt> on x64. This issue will be fixed with the new
+garbage collector.
+</li>
+</ul>
+<br class="flush">
+</div>
+<div id="foot">
+<hr class="hide">
+Copyright &copy; 2005-2018
+<span class="noprint">
+&middot;
+<a href="contact.html">Contact</a>
+</span>
+</div>
+</body>
+</html>
diff --git a/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_arm.h b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_arm.h
new file mode 100644
index 0000000..1d404cc
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_arm.h
@@ -0,0 +1,458 @@
+/*
+** DynASM ARM encoding engine.
+** Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+** Released under the MIT license. See dynasm.lua for full copyright notice.
+*/
+
+#include <stddef.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+
+#define DASM_ARCH "arm"
+
+#ifndef DASM_EXTERN
+#define DASM_EXTERN(a,b,c,d) 0
+#endif
+
+/* Action definitions. */
+enum {
+ DASM_STOP, DASM_SECTION, DASM_ESC, DASM_REL_EXT,
+ /* The following actions need a buffer position. */
+ DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG,
+ /* The following actions also have an argument. */
+ DASM_REL_PC, DASM_LABEL_PC,
+ DASM_IMM, DASM_IMM12, DASM_IMM16, DASM_IMML8, DASM_IMML12, DASM_IMMV8,
+ DASM__MAX
+};
+
+/* Maximum number of section buffer positions for a single dasm_put() call. */
+#define DASM_MAXSECPOS 25
+
+/* DynASM encoder status codes. Action list offset or number are or'ed in. */
+#define DASM_S_OK 0x00000000
+#define DASM_S_NOMEM 0x01000000
+#define DASM_S_PHASE 0x02000000
+#define DASM_S_MATCH_SEC 0x03000000
+#define DASM_S_RANGE_I 0x11000000
+#define DASM_S_RANGE_SEC 0x12000000
+#define DASM_S_RANGE_LG 0x13000000
+#define DASM_S_RANGE_PC 0x14000000
+#define DASM_S_RANGE_REL 0x15000000
+#define DASM_S_UNDEF_LG 0x21000000
+#define DASM_S_UNDEF_PC 0x22000000
+
+/* Macros to convert positions (8 bit section + 24 bit index). */
+#define DASM_POS2IDX(pos) ((pos)&0x00ffffff)
+#define DASM_POS2BIAS(pos) ((pos)&0xff000000)
+#define DASM_SEC2POS(sec) ((sec)<<24)
+#define DASM_POS2SEC(pos) ((pos)>>24)
+#define DASM_POS2PTR(D, pos) (D->sections[DASM_POS2SEC(pos)].rbuf + (pos))
+
+/* Action list type. */
+typedef const unsigned int *dasm_ActList;
+
+/* Per-section structure. */
+typedef struct dasm_Section {
+ int *rbuf; /* Biased buffer pointer (negative section bias). */
+ int *buf; /* True buffer pointer. */
+ size_t bsize; /* Buffer size in bytes. */
+ int pos; /* Biased buffer position. */
+ int epos; /* End of biased buffer position - max single put. */
+ int ofs; /* Byte offset into section. */
+} dasm_Section;
+
+/* Core structure holding the DynASM encoding state. */
+struct dasm_State {
+ size_t psize; /* Allocated size of this structure. */
+ dasm_ActList actionlist; /* Current actionlist pointer. */
+ int *lglabels; /* Local/global chain/pos ptrs. */
+ size_t lgsize;
+ int *pclabels; /* PC label chains/pos ptrs. */
+ size_t pcsize;
+ void **globals; /* Array of globals (bias -10). */
+ dasm_Section *section; /* Pointer to active section. */
+ size_t codesize; /* Total size of all code sections. */
+ int maxsection; /* 0 <= sectionidx < maxsection. */
+ int status; /* Status code. */
+ dasm_Section sections[1]; /* All sections. Alloc-extended. */
+};
+
+/* The size of the core structure depends on the max. number of sections. */
+#define DASM_PSZ(ms) (sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section))
+
+
+/* Initialize DynASM state. */
+void dasm_init(Dst_DECL, int maxsection)
+{
+ dasm_State *D;
+ size_t psz = 0;
+ int i;
+ Dst_REF = NULL;
+ DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));
+ D = Dst_REF;
+ D->psize = psz;
+ D->lglabels = NULL;
+ D->lgsize = 0;
+ D->pclabels = NULL;
+ D->pcsize = 0;
+ D->globals = NULL;
+ D->maxsection = maxsection;
+ for (i = 0; i < maxsection; i++) {
+ D->sections[i].buf = NULL; /* Need this for pass3. */
+ D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);
+ D->sections[i].bsize = 0;
+ D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */
+ }
+}
+
+/* Free DynASM state. */
+void dasm_free(Dst_DECL)
+{
+ dasm_State *D = Dst_REF;
+ int i;
+ for (i = 0; i < D->maxsection; i++)
+ if (D->sections[i].buf)
+ DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize);
+ if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize);
+ if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize);
+ DASM_M_FREE(Dst, D, D->psize);
+}
+
+/* Setup global label array. Must be called before dasm_setup(). */
+void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)
+{
+ dasm_State *D = Dst_REF;
+ D->globals = gl - 10; /* Negative bias to compensate for locals. */
+ DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));
+}
+
+/* Grow PC label array. Can be called after dasm_setup(), too. */
+void dasm_growpc(Dst_DECL, unsigned int maxpc)
+{
+ dasm_State *D = Dst_REF;
+ size_t osz = D->pcsize;
+ DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int));
+ memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz);
+}
+
+/* Setup encoder. */
+void dasm_setup(Dst_DECL, const void *actionlist)
+{
+ dasm_State *D = Dst_REF;
+ int i;
+ D->actionlist = (dasm_ActList)actionlist;
+ D->status = DASM_S_OK;
+ D->section = &D->sections[0];
+ memset((void *)D->lglabels, 0, D->lgsize);
+ if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize);
+ for (i = 0; i < D->maxsection; i++) {
+ D->sections[i].pos = DASM_SEC2POS(i);
+ D->sections[i].ofs = 0;
+ }
+}
+
+
+#ifdef DASM_CHECKS
+#define CK(x, st) \
+ do { if (!(x)) { \
+ D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0)
+#define CKPL(kind, st) \
+ do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \
+ D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0)
+#else
+#define CK(x, st) ((void)0)
+#define CKPL(kind, st) ((void)0)
+#endif
+
+static int dasm_imm12(unsigned int n)
+{
+ int i;
+ for (i = 0; i < 16; i++, n = (n << 2) | (n >> 30))
+ if (n <= 255) return (int)(n + (i << 8));
+ return -1;
+}
+
+/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */
+void dasm_put(Dst_DECL, int start, ...)
+{
+ va_list ap;
+ dasm_State *D = Dst_REF;
+ dasm_ActList p = D->actionlist + start;
+ dasm_Section *sec = D->section;
+ int pos = sec->pos, ofs = sec->ofs;
+ int *b;
+
+ if (pos >= sec->epos) {
+ DASM_M_GROW(Dst, int, sec->buf, sec->bsize,
+ sec->bsize + 2*DASM_MAXSECPOS*sizeof(int));
+ sec->rbuf = sec->buf - DASM_POS2BIAS(pos);
+ sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos);
+ }
+
+ b = sec->rbuf;
+ b[pos++] = start;
+
+ va_start(ap, start);
+ while (1) {
+ unsigned int ins = *p++;
+ unsigned int action = (ins >> 16);
+ if (action >= DASM__MAX) {
+ ofs += 4;
+ } else {
+ int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0;
+ switch (action) {
+ case DASM_STOP: goto stop;
+ case DASM_SECTION:
+ n = (ins & 255); CK(n < D->maxsection, RANGE_SEC);
+ D->section = &D->sections[n]; goto stop;
+ case DASM_ESC: p++; ofs += 4; break;
+ case DASM_REL_EXT: break;
+ case DASM_ALIGN: ofs += (ins & 255); b[pos++] = ofs; break;
+ case DASM_REL_LG:
+ n = (ins & 2047) - 10; pl = D->lglabels + n;
+ /* Bkwd rel or global. */
+ if (n >= 0) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; }
+ pl += 10; n = *pl;
+ if (n < 0) n = 0; /* Start new chain for fwd rel if label exists. */
+ goto linkrel;
+ case DASM_REL_PC:
+ pl = D->pclabels + n; CKPL(pc, PC);
+ putrel:
+ n = *pl;
+ if (n < 0) { /* Label exists. Get label pos and store it. */
+ b[pos] = -n;
+ } else {
+ linkrel:
+ b[pos] = n; /* Else link to rel chain, anchored at label. */
+ *pl = pos;
+ }
+ pos++;
+ break;
+ case DASM_LABEL_LG:
+ pl = D->lglabels + (ins & 2047) - 10; CKPL(lg, LG); goto putlabel;
+ case DASM_LABEL_PC:
+ pl = D->pclabels + n; CKPL(pc, PC);
+ putlabel:
+ n = *pl; /* n > 0: Collapse rel chain and replace with label pos. */
+ while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos;
+ }
+ *pl = -pos; /* Label exists now. */
+ b[pos++] = ofs; /* Store pass1 offset estimate. */
+ break;
+ case DASM_IMM:
+ case DASM_IMM16:
+#ifdef DASM_CHECKS
+ CK((n & ((1<<((ins>>10)&31))-1)) == 0, RANGE_I);
+ if ((ins & 0x8000))
+ CK(((n + (1<<(((ins>>5)&31)-1)))>>((ins>>5)&31)) == 0, RANGE_I);
+ else
+ CK((n>>((ins>>5)&31)) == 0, RANGE_I);
+#endif
+ b[pos++] = n;
+ break;
+ case DASM_IMMV8:
+ CK((n & 3) == 0, RANGE_I);
+ n >>= 2;
+ /* fallthrough */
+ case DASM_IMML8:
+ case DASM_IMML12:
+ CK(n >= 0 ? ((n>>((ins>>5)&31)) == 0) :
+ (((-n)>>((ins>>5)&31)) == 0), RANGE_I);
+ b[pos++] = n;
+ break;
+ case DASM_IMM12:
+ CK(dasm_imm12((unsigned int)n) != -1, RANGE_I);
+ b[pos++] = n;
+ break;
+ }
+ }
+ }
+stop:
+ va_end(ap);
+ sec->pos = pos;
+ sec->ofs = ofs;
+}
+#undef CK
+
+/* Pass 2: Link sections, shrink aligns, fix label offsets. */
+int dasm_link(Dst_DECL, size_t *szp)
+{
+ dasm_State *D = Dst_REF;
+ int secnum;
+ int ofs = 0;
+
+#ifdef DASM_CHECKS
+ *szp = 0;
+ if (D->status != DASM_S_OK) return D->status;
+ {
+ int pc;
+ for (pc = 0; pc*sizeof(int) < D->pcsize; pc++)
+ if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc;
+ }
+#endif
+
+ { /* Handle globals not defined in this translation unit. */
+ int idx;
+ for (idx = 20; idx*sizeof(int) < D->lgsize; idx++) {
+ int n = D->lglabels[idx];
+ /* Undefined label: Collapse rel chain and replace with marker (< 0). */
+ while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }
+ }
+ }
+
+ /* Combine all code sections. No support for data sections (yet). */
+ for (secnum = 0; secnum < D->maxsection; secnum++) {
+ dasm_Section *sec = D->sections + secnum;
+ int *b = sec->rbuf;
+ int pos = DASM_SEC2POS(secnum);
+ int lastpos = sec->pos;
+
+ while (pos != lastpos) {
+ dasm_ActList p = D->actionlist + b[pos++];
+ while (1) {
+ unsigned int ins = *p++;
+ unsigned int action = (ins >> 16);
+ switch (action) {
+ case DASM_STOP: case DASM_SECTION: goto stop;
+ case DASM_ESC: p++; break;
+ case DASM_REL_EXT: break;
+ case DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break;
+ case DASM_REL_LG: case DASM_REL_PC: pos++; break;
+ case DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break;
+ case DASM_IMM: case DASM_IMM12: case DASM_IMM16:
+ case DASM_IMML8: case DASM_IMML12: case DASM_IMMV8: pos++; break;
+ }
+ }
+ stop: (void)0;
+ }
+ ofs += sec->ofs; /* Next section starts right after current section. */
+ }
+
+ D->codesize = ofs; /* Total size of all code sections */
+ *szp = ofs;
+ return DASM_S_OK;
+}
+
+#ifdef DASM_CHECKS
+#define CK(x, st) \
+ do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0)
+#else
+#define CK(x, st) ((void)0)
+#endif
+
+/* Pass 3: Encode sections. */
+int dasm_encode(Dst_DECL, void *buffer)
+{
+ dasm_State *D = Dst_REF;
+ char *base = (char *)buffer;
+ unsigned int *cp = (unsigned int *)buffer;
+ int secnum;
+
+ /* Encode all code sections. No support for data sections (yet). */
+ for (secnum = 0; secnum < D->maxsection; secnum++) {
+ dasm_Section *sec = D->sections + secnum;
+ int *b = sec->buf;
+ int *endb = sec->rbuf + sec->pos;
+
+ while (b != endb) {
+ dasm_ActList p = D->actionlist + *b++;
+ while (1) {
+ unsigned int ins = *p++;
+ unsigned int action = (ins >> 16);
+ int n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0;
+ switch (action) {
+ case DASM_STOP: case DASM_SECTION: goto stop;
+ case DASM_ESC: *cp++ = *p++; break;
+ case DASM_REL_EXT:
+ n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins&2047), !(ins&2048));
+ goto patchrel;
+ case DASM_ALIGN:
+ ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0xe1a00000;
+ break;
+ case DASM_REL_LG:
+ CK(n >= 0, UNDEF_LG);
+ /* fallthrough */
+ case DASM_REL_PC:
+ CK(n >= 0, UNDEF_PC);
+ n = *DASM_POS2PTR(D, n) - (int)((char *)cp - base) - 4;
+ patchrel:
+ if ((ins & 0x800) == 0) {
+ CK((n & 3) == 0 && ((n+0x02000000) >> 26) == 0, RANGE_REL);
+ cp[-1] |= ((n >> 2) & 0x00ffffff);
+ } else if ((ins & 0x1000)) {
+ CK((n & 3) == 0 && -256 <= n && n <= 256, RANGE_REL);
+ goto patchimml8;
+ } else if ((ins & 0x2000) == 0) {
+ CK((n & 3) == 0 && -4096 <= n && n <= 4096, RANGE_REL);
+ goto patchimml;
+ } else {
+ CK((n & 3) == 0 && -1020 <= n && n <= 1020, RANGE_REL);
+ n >>= 2;
+ goto patchimml;
+ }
+ break;
+ case DASM_LABEL_LG:
+ ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);
+ break;
+ case DASM_LABEL_PC: break;
+ case DASM_IMM:
+ cp[-1] |= ((n>>((ins>>10)&31)) & ((1<<((ins>>5)&31))-1)) << (ins&31);
+ break;
+ case DASM_IMM12:
+ cp[-1] |= dasm_imm12((unsigned int)n);
+ break;
+ case DASM_IMM16:
+ cp[-1] |= ((n & 0xf000) << 4) | (n & 0x0fff);
+ break;
+ case DASM_IMML8: patchimml8:
+ cp[-1] |= n >= 0 ? (0x00800000 | (n & 0x0f) | ((n & 0xf0) << 4)) :
+ ((-n & 0x0f) | ((-n & 0xf0) << 4));
+ break;
+ case DASM_IMML12: case DASM_IMMV8: patchimml:
+ cp[-1] |= n >= 0 ? (0x00800000 | n) : (-n);
+ break;
+ default: *cp++ = ins; break;
+ }
+ }
+ stop: (void)0;
+ }
+ }
+
+ if (base + D->codesize != (char *)cp) /* Check for phase errors. */
+ return DASM_S_PHASE;
+ return DASM_S_OK;
+}
+#undef CK
+
+/* Get PC label offset. */
+int dasm_getpclabel(Dst_DECL, unsigned int pc)
+{
+ dasm_State *D = Dst_REF;
+ if (pc*sizeof(int) < D->pcsize) {
+ int pos = D->pclabels[pc];
+ if (pos < 0) return *DASM_POS2PTR(D, -pos);
+ if (pos > 0) return -1; /* Undefined. */
+ }
+ return -2; /* Unused or out of range. */
+}
+
+#ifdef DASM_CHECKS
+/* Optional sanity checker to call between isolated encoding steps. */
+int dasm_checkstep(Dst_DECL, int secmatch)
+{
+ dasm_State *D = Dst_REF;
+ if (D->status == DASM_S_OK) {
+ int i;
+ for (i = 1; i <= 9; i++) {
+ if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_LG|i; break; }
+ D->lglabels[i] = 0;
+ }
+ }
+ if (D->status == DASM_S_OK && secmatch >= 0 &&
+ D->section != &D->sections[secmatch])
+ D->status = DASM_S_MATCH_SEC|(D->section-D->sections);
+ return D->status;
+}
+#endif
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_arm.lua b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_arm.lua
new file mode 100644
index 0000000..9ece1d7
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_arm.lua
@@ -0,0 +1,1125 @@
+------------------------------------------------------------------------------
+-- DynASM ARM module.
+--
+-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+-- See dynasm.lua for full copyright notice.
+------------------------------------------------------------------------------
+
+-- Module information:
+local _info = {
+ arch = "arm",
+ description = "DynASM ARM module",
+ version = "1.3.0",
+ vernum = 10300,
+ release = "2011-05-05",
+ author = "Mike Pall",
+ license = "MIT",
+}
+
+-- Exported glue functions for the arch-specific module.
+local _M = { _info = _info }
+
+-- Cache library functions.
+local type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs
+local assert, setmetatable, rawget = assert, setmetatable, rawget
+local _s = string
+local sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char
+local match, gmatch, gsub = _s.match, _s.gmatch, _s.gsub
+local concat, sort, insert = table.concat, table.sort, table.insert
+local bit = bit or require("bit")
+local band, shl, shr, sar = bit.band, bit.lshift, bit.rshift, bit.arshift
+local ror, tohex = bit.ror, bit.tohex
+
+-- Inherited tables and callbacks.
+local g_opt, g_arch
+local wline, werror, wfatal, wwarn
+
+-- Action name list.
+-- CHECK: Keep this in sync with the C code!
+local action_names = {
+ "STOP", "SECTION", "ESC", "REL_EXT",
+ "ALIGN", "REL_LG", "LABEL_LG",
+ "REL_PC", "LABEL_PC", "IMM", "IMM12", "IMM16", "IMML8", "IMML12", "IMMV8",
+}
+
+-- Maximum number of section buffer positions for dasm_put().
+-- CHECK: Keep this in sync with the C code!
+local maxsecpos = 25 -- Keep this low, to avoid excessively long C lines.
+
+-- Action name -> action number.
+local map_action = {}
+for n,name in ipairs(action_names) do
+ map_action[name] = n-1
+end
+
+-- Action list buffer.
+local actlist = {}
+
+-- Argument list for next dasm_put(). Start with offset 0 into action list.
+local actargs = { 0 }
+
+-- Current number of section buffer positions for dasm_put().
+local secpos = 1
+
+------------------------------------------------------------------------------
+
+-- Dump action names and numbers.
+local function dumpactions(out)
+ out:write("DynASM encoding engine action codes:\n")
+ for n,name in ipairs(action_names) do
+ local num = map_action[name]
+ out:write(format(" %-10s %02X %d\n", name, num, num))
+ end
+ out:write("\n")
+end
+
+-- Write action list buffer as a huge static C array.
+local function writeactions(out, name)
+ local nn = #actlist
+ if nn == 0 then nn = 1; actlist[0] = map_action.STOP end
+ out:write("static const unsigned int ", name, "[", nn, "] = {\n")
+ for i = 1,nn-1 do
+ assert(out:write("0x", tohex(actlist[i]), ",\n"))
+ end
+ assert(out:write("0x", tohex(actlist[nn]), "\n};\n\n"))
+end
+
+------------------------------------------------------------------------------
+
+-- Add word to action list.
+local function wputxw(n)
+ assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, "word out of range")
+ actlist[#actlist+1] = n
+end
+
+-- Add action to list with optional arg. Advance buffer pos, too.
+local function waction(action, val, a, num)
+ local w = assert(map_action[action], "bad action name `"..action.."'")
+ wputxw(w * 0x10000 + (val or 0))
+ if a then actargs[#actargs+1] = a end
+ if a or num then secpos = secpos + (num or 1) end
+end
+
+-- Flush action list (intervening C code or buffer pos overflow).
+local function wflush(term)
+ if #actlist == actargs[1] then return end -- Nothing to flush.
+ if not term then waction("STOP") end -- Terminate action list.
+ wline(format("dasm_put(Dst, %s);", concat(actargs, ", ")), true)
+ actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put().
+ secpos = 1 -- The actionlist offset occupies a buffer position, too.
+end
+
+-- Put escaped word.
+local function wputw(n)
+ if n <= 0x000fffff then waction("ESC") end
+ wputxw(n)
+end
+
+-- Reserve position for word.
+local function wpos()
+ local pos = #actlist+1
+ actlist[pos] = ""
+ return pos
+end
+
+-- Store word to reserved position.
+local function wputpos(pos, n)
+ assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, "word out of range")
+ if n <= 0x000fffff then
+ insert(actlist, pos+1, n)
+ n = map_action.ESC * 0x10000
+ end
+ actlist[pos] = n
+end
+
+------------------------------------------------------------------------------
+
+-- Global label name -> global label number. With auto assignment on 1st use.
+local next_global = 20
+local map_global = setmetatable({}, { __index = function(t, name)
+ if not match(name, "^[%a_][%w_]*$") then werror("bad global label") end
+ local n = next_global
+ if n > 2047 then werror("too many global labels") end
+ next_global = n + 1
+ t[name] = n
+ return n
+end})
+
+-- Dump global labels.
+local function dumpglobals(out, lvl)
+ local t = {}
+ for name, n in pairs(map_global) do t[n] = name end
+ out:write("Global labels:\n")
+ for i=20,next_global-1 do
+ out:write(format(" %s\n", t[i]))
+ end
+ out:write("\n")
+end
+
+-- Write global label enum.
+local function writeglobals(out, prefix)
+ local t = {}
+ for name, n in pairs(map_global) do t[n] = name end
+ out:write("enum {\n")
+ for i=20,next_global-1 do
+ out:write(" ", prefix, t[i], ",\n")
+ end
+ out:write(" ", prefix, "_MAX\n};\n")
+end
+
+-- Write global label names.
+local function writeglobalnames(out, name)
+ local t = {}
+ for name, n in pairs(map_global) do t[n] = name end
+ out:write("static const char *const ", name, "[] = {\n")
+ for i=20,next_global-1 do
+ out:write(" \"", t[i], "\",\n")
+ end
+ out:write(" (const char *)0\n};\n")
+end
+
+------------------------------------------------------------------------------
+
+-- Extern label name -> extern label number. With auto assignment on 1st use.
+local next_extern = 0
+local map_extern_ = {}
+local map_extern = setmetatable({}, { __index = function(t, name)
+ -- No restrictions on the name for now.
+ local n = next_extern
+ if n > 2047 then werror("too many extern labels") end
+ next_extern = n + 1
+ t[name] = n
+ map_extern_[n] = name
+ return n
+end})
+
+-- Dump extern labels.
+local function dumpexterns(out, lvl)
+ out:write("Extern labels:\n")
+ for i=0,next_extern-1 do
+ out:write(format(" %s\n", map_extern_[i]))
+ end
+ out:write("\n")
+end
+
+-- Write extern label names.
+local function writeexternnames(out, name)
+ out:write("static const char *const ", name, "[] = {\n")
+ for i=0,next_extern-1 do
+ out:write(" \"", map_extern_[i], "\",\n")
+ end
+ out:write(" (const char *)0\n};\n")
+end
+
+------------------------------------------------------------------------------
+
+-- Arch-specific maps.
+
+-- Ext. register name -> int. name.
+local map_archdef = { sp = "r13", lr = "r14", pc = "r15", }
+
+-- Int. register name -> ext. name.
+local map_reg_rev = { r13 = "sp", r14 = "lr", r15 = "pc", }
+
+local map_type = {} -- Type name -> { ctype, reg }
+local ctypenum = 0 -- Type number (for Dt... macros).
+
+-- Reverse defines for registers.
+function _M.revdef(s)
+ return map_reg_rev[s] or s
+end
+
+local map_shift = { lsl = 0, lsr = 1, asr = 2, ror = 3, }
+
+local map_cond = {
+ eq = 0, ne = 1, cs = 2, cc = 3, mi = 4, pl = 5, vs = 6, vc = 7,
+ hi = 8, ls = 9, ge = 10, lt = 11, gt = 12, le = 13, al = 14,
+ hs = 2, lo = 3,
+}
+
+------------------------------------------------------------------------------
+
+-- Template strings for ARM instructions.
+local map_op = {
+ -- Basic data processing instructions.
+ and_3 = "e0000000DNPs",
+ eor_3 = "e0200000DNPs",
+ sub_3 = "e0400000DNPs",
+ rsb_3 = "e0600000DNPs",
+ add_3 = "e0800000DNPs",
+ adc_3 = "e0a00000DNPs",
+ sbc_3 = "e0c00000DNPs",
+ rsc_3 = "e0e00000DNPs",
+ tst_2 = "e1100000NP",
+ teq_2 = "e1300000NP",
+ cmp_2 = "e1500000NP",
+ cmn_2 = "e1700000NP",
+ orr_3 = "e1800000DNPs",
+ mov_2 = "e1a00000DPs",
+ bic_3 = "e1c00000DNPs",
+ mvn_2 = "e1e00000DPs",
+
+ and_4 = "e0000000DNMps",
+ eor_4 = "e0200000DNMps",
+ sub_4 = "e0400000DNMps",
+ rsb_4 = "e0600000DNMps",
+ add_4 = "e0800000DNMps",
+ adc_4 = "e0a00000DNMps",
+ sbc_4 = "e0c00000DNMps",
+ rsc_4 = "e0e00000DNMps",
+ tst_3 = "e1100000NMp",
+ teq_3 = "e1300000NMp",
+ cmp_3 = "e1500000NMp",
+ cmn_3 = "e1700000NMp",
+ orr_4 = "e1800000DNMps",
+ mov_3 = "e1a00000DMps",
+ bic_4 = "e1c00000DNMps",
+ mvn_3 = "e1e00000DMps",
+
+ lsl_3 = "e1a00000DMws",
+ lsr_3 = "e1a00020DMws",
+ asr_3 = "e1a00040DMws",
+ ror_3 = "e1a00060DMws",
+ rrx_2 = "e1a00060DMs",
+
+ -- Multiply and multiply-accumulate.
+ mul_3 = "e0000090NMSs",
+ mla_4 = "e0200090NMSDs",
+ umaal_4 = "e0400090DNMSs", -- v6
+ mls_4 = "e0600090DNMSs", -- v6T2
+ umull_4 = "e0800090DNMSs",
+ umlal_4 = "e0a00090DNMSs",
+ smull_4 = "e0c00090DNMSs",
+ smlal_4 = "e0e00090DNMSs",
+
+ -- Halfword multiply and multiply-accumulate.
+ smlabb_4 = "e1000080NMSD", -- v5TE
+ smlatb_4 = "e10000a0NMSD", -- v5TE
+ smlabt_4 = "e10000c0NMSD", -- v5TE
+ smlatt_4 = "e10000e0NMSD", -- v5TE
+ smlawb_4 = "e1200080NMSD", -- v5TE
+ smulwb_3 = "e12000a0NMS", -- v5TE
+ smlawt_4 = "e12000c0NMSD", -- v5TE
+ smulwt_3 = "e12000e0NMS", -- v5TE
+ smlalbb_4 = "e1400080NMSD", -- v5TE
+ smlaltb_4 = "e14000a0NMSD", -- v5TE
+ smlalbt_4 = "e14000c0NMSD", -- v5TE
+ smlaltt_4 = "e14000e0NMSD", -- v5TE
+ smulbb_3 = "e1600080NMS", -- v5TE
+ smultb_3 = "e16000a0NMS", -- v5TE
+ smulbt_3 = "e16000c0NMS", -- v5TE
+ smultt_3 = "e16000e0NMS", -- v5TE
+
+ -- Miscellaneous data processing instructions.
+ clz_2 = "e16f0f10DM", -- v5T
+ rev_2 = "e6bf0f30DM", -- v6
+ rev16_2 = "e6bf0fb0DM", -- v6
+ revsh_2 = "e6ff0fb0DM", -- v6
+ sel_3 = "e6800fb0DNM", -- v6
+ usad8_3 = "e780f010NMS", -- v6
+ usada8_4 = "e7800010NMSD", -- v6
+ rbit_2 = "e6ff0f30DM", -- v6T2
+ movw_2 = "e3000000DW", -- v6T2
+ movt_2 = "e3400000DW", -- v6T2
+ -- Note: the X encodes width-1, not width.
+ sbfx_4 = "e7a00050DMvX", -- v6T2
+ ubfx_4 = "e7e00050DMvX", -- v6T2
+ -- Note: the X encodes the msb field, not the width.
+ bfc_3 = "e7c0001fDvX", -- v6T2
+ bfi_4 = "e7c00010DMvX", -- v6T2
+
+ -- Packing and unpacking instructions.
+ pkhbt_3 = "e6800010DNM", pkhbt_4 = "e6800010DNMv", -- v6
+ pkhtb_3 = "e6800050DNM", pkhtb_4 = "e6800050DNMv", -- v6
+ sxtab_3 = "e6a00070DNM", sxtab_4 = "e6a00070DNMv", -- v6
+ sxtab16_3 = "e6800070DNM", sxtab16_4 = "e6800070DNMv", -- v6
+ sxtah_3 = "e6b00070DNM", sxtah_4 = "e6b00070DNMv", -- v6
+ sxtb_2 = "e6af0070DM", sxtb_3 = "e6af0070DMv", -- v6
+ sxtb16_2 = "e68f0070DM", sxtb16_3 = "e68f0070DMv", -- v6
+ sxth_2 = "e6bf0070DM", sxth_3 = "e6bf0070DMv", -- v6
+ uxtab_3 = "e6e00070DNM", uxtab_4 = "e6e00070DNMv", -- v6
+ uxtab16_3 = "e6c00070DNM", uxtab16_4 = "e6c00070DNMv", -- v6
+ uxtah_3 = "e6f00070DNM", uxtah_4 = "e6f00070DNMv", -- v6
+ uxtb_2 = "e6ef0070DM", uxtb_3 = "e6ef0070DMv", -- v6
+ uxtb16_2 = "e6cf0070DM", uxtb16_3 = "e6cf0070DMv", -- v6
+ uxth_2 = "e6ff0070DM", uxth_3 = "e6ff0070DMv", -- v6
+
+ -- Saturating instructions.
+ qadd_3 = "e1000050DMN", -- v5TE
+ qsub_3 = "e1200050DMN", -- v5TE
+ qdadd_3 = "e1400050DMN", -- v5TE
+ qdsub_3 = "e1600050DMN", -- v5TE
+ -- Note: the X for ssat* encodes sat_imm-1, not sat_imm.
+ ssat_3 = "e6a00010DXM", ssat_4 = "e6a00010DXMp", -- v6
+ usat_3 = "e6e00010DXM", usat_4 = "e6e00010DXMp", -- v6
+ ssat16_3 = "e6a00f30DXM", -- v6
+ usat16_3 = "e6e00f30DXM", -- v6
+
+ -- Parallel addition and subtraction.
+ sadd16_3 = "e6100f10DNM", -- v6
+ sasx_3 = "e6100f30DNM", -- v6
+ ssax_3 = "e6100f50DNM", -- v6
+ ssub16_3 = "e6100f70DNM", -- v6
+ sadd8_3 = "e6100f90DNM", -- v6
+ ssub8_3 = "e6100ff0DNM", -- v6
+ qadd16_3 = "e6200f10DNM", -- v6
+ qasx_3 = "e6200f30DNM", -- v6
+ qsax_3 = "e6200f50DNM", -- v6
+ qsub16_3 = "e6200f70DNM", -- v6
+ qadd8_3 = "e6200f90DNM", -- v6
+ qsub8_3 = "e6200ff0DNM", -- v6
+ shadd16_3 = "e6300f10DNM", -- v6
+ shasx_3 = "e6300f30DNM", -- v6
+ shsax_3 = "e6300f50DNM", -- v6
+ shsub16_3 = "e6300f70DNM", -- v6
+ shadd8_3 = "e6300f90DNM", -- v6
+ shsub8_3 = "e6300ff0DNM", -- v6
+ uadd16_3 = "e6500f10DNM", -- v6
+ uasx_3 = "e6500f30DNM", -- v6
+ usax_3 = "e6500f50DNM", -- v6
+ usub16_3 = "e6500f70DNM", -- v6
+ uadd8_3 = "e6500f90DNM", -- v6
+ usub8_3 = "e6500ff0DNM", -- v6
+ uqadd16_3 = "e6600f10DNM", -- v6
+ uqasx_3 = "e6600f30DNM", -- v6
+ uqsax_3 = "e6600f50DNM", -- v6
+ uqsub16_3 = "e6600f70DNM", -- v6
+ uqadd8_3 = "e6600f90DNM", -- v6
+ uqsub8_3 = "e6600ff0DNM", -- v6
+ uhadd16_3 = "e6700f10DNM", -- v6
+ uhasx_3 = "e6700f30DNM", -- v6
+ uhsax_3 = "e6700f50DNM", -- v6
+ uhsub16_3 = "e6700f70DNM", -- v6
+ uhadd8_3 = "e6700f90DNM", -- v6
+ uhsub8_3 = "e6700ff0DNM", -- v6
+
+ -- Load/store instructions.
+ str_2 = "e4000000DL", str_3 = "e4000000DL", str_4 = "e4000000DL",
+ strb_2 = "e4400000DL", strb_3 = "e4400000DL", strb_4 = "e4400000DL",
+ ldr_2 = "e4100000DL", ldr_3 = "e4100000DL", ldr_4 = "e4100000DL",
+ ldrb_2 = "e4500000DL", ldrb_3 = "e4500000DL", ldrb_4 = "e4500000DL",
+ strh_2 = "e00000b0DL", strh_3 = "e00000b0DL",
+ ldrh_2 = "e01000b0DL", ldrh_3 = "e01000b0DL",
+ ldrd_2 = "e00000d0DL", ldrd_3 = "e00000d0DL", -- v5TE
+ ldrsb_2 = "e01000d0DL", ldrsb_3 = "e01000d0DL",
+ strd_2 = "e00000f0DL", strd_3 = "e00000f0DL", -- v5TE
+ ldrsh_2 = "e01000f0DL", ldrsh_3 = "e01000f0DL",
+
+ ldm_2 = "e8900000oR", ldmia_2 = "e8900000oR", ldmfd_2 = "e8900000oR",
+ ldmda_2 = "e8100000oR", ldmfa_2 = "e8100000oR",
+ ldmdb_2 = "e9100000oR", ldmea_2 = "e9100000oR",
+ ldmib_2 = "e9900000oR", ldmed_2 = "e9900000oR",
+ stm_2 = "e8800000oR", stmia_2 = "e8800000oR", stmfd_2 = "e8800000oR",
+ stmda_2 = "e8000000oR", stmfa_2 = "e8000000oR",
+ stmdb_2 = "e9000000oR", stmea_2 = "e9000000oR",
+ stmib_2 = "e9800000oR", stmed_2 = "e9800000oR",
+ pop_1 = "e8bd0000R", push_1 = "e92d0000R",
+
+ -- Branch instructions.
+ b_1 = "ea000000B",
+ bl_1 = "eb000000B",
+ blx_1 = "e12fff30C",
+ bx_1 = "e12fff10M",
+
+ -- Miscellaneous instructions.
+ nop_0 = "e1a00000",
+ mrs_1 = "e10f0000D",
+ bkpt_1 = "e1200070K", -- v5T
+ svc_1 = "ef000000T", swi_1 = "ef000000T",
+ ud_0 = "e7f001f0",
+
+ -- VFP instructions.
+ ["vadd.f32_3"] = "ee300a00dnm",
+ ["vadd.f64_3"] = "ee300b00Gdnm",
+ ["vsub.f32_3"] = "ee300a40dnm",
+ ["vsub.f64_3"] = "ee300b40Gdnm",
+ ["vmul.f32_3"] = "ee200a00dnm",
+ ["vmul.f64_3"] = "ee200b00Gdnm",
+ ["vnmul.f32_3"] = "ee200a40dnm",
+ ["vnmul.f64_3"] = "ee200b40Gdnm",
+ ["vmla.f32_3"] = "ee000a00dnm",
+ ["vmla.f64_3"] = "ee000b00Gdnm",
+ ["vmls.f32_3"] = "ee000a40dnm",
+ ["vmls.f64_3"] = "ee000b40Gdnm",
+ ["vnmla.f32_3"] = "ee100a40dnm",
+ ["vnmla.f64_3"] = "ee100b40Gdnm",
+ ["vnmls.f32_3"] = "ee100a00dnm",
+ ["vnmls.f64_3"] = "ee100b00Gdnm",
+ ["vdiv.f32_3"] = "ee800a00dnm",
+ ["vdiv.f64_3"] = "ee800b00Gdnm",
+
+ ["vabs.f32_2"] = "eeb00ac0dm",
+ ["vabs.f64_2"] = "eeb00bc0Gdm",
+ ["vneg.f32_2"] = "eeb10a40dm",
+ ["vneg.f64_2"] = "eeb10b40Gdm",
+ ["vsqrt.f32_2"] = "eeb10ac0dm",
+ ["vsqrt.f64_2"] = "eeb10bc0Gdm",
+ ["vcmp.f32_2"] = "eeb40a40dm",
+ ["vcmp.f64_2"] = "eeb40b40Gdm",
+ ["vcmpe.f32_2"] = "eeb40ac0dm",
+ ["vcmpe.f64_2"] = "eeb40bc0Gdm",
+ ["vcmpz.f32_1"] = "eeb50a40d",
+ ["vcmpz.f64_1"] = "eeb50b40Gd",
+ ["vcmpze.f32_1"] = "eeb50ac0d",
+ ["vcmpze.f64_1"] = "eeb50bc0Gd",
+
+ vldr_2 = "ed100a00dl|ed100b00Gdl",
+ vstr_2 = "ed000a00dl|ed000b00Gdl",
+ vldm_2 = "ec900a00or",
+ vldmia_2 = "ec900a00or",
+ vldmdb_2 = "ed100a00or",
+ vpop_1 = "ecbd0a00r",
+ vstm_2 = "ec800a00or",
+ vstmia_2 = "ec800a00or",
+ vstmdb_2 = "ed000a00or",
+ vpush_1 = "ed2d0a00r",
+
+ ["vmov.f32_2"] = "eeb00a40dm|eeb00a00dY", -- #imm is VFPv3 only
+ ["vmov.f64_2"] = "eeb00b40Gdm|eeb00b00GdY", -- #imm is VFPv3 only
+ vmov_2 = "ee100a10Dn|ee000a10nD",
+ vmov_3 = "ec500a10DNm|ec400a10mDN|ec500b10GDNm|ec400b10GmDN",
+
+ vmrs_0 = "eef1fa10",
+ vmrs_1 = "eef10a10D",
+ vmsr_1 = "eee10a10D",
+
+ ["vcvt.s32.f32_2"] = "eebd0ac0dm",
+ ["vcvt.s32.f64_2"] = "eebd0bc0dGm",
+ ["vcvt.u32.f32_2"] = "eebc0ac0dm",
+ ["vcvt.u32.f64_2"] = "eebc0bc0dGm",
+ ["vcvtr.s32.f32_2"] = "eebd0a40dm",
+ ["vcvtr.s32.f64_2"] = "eebd0b40dGm",
+ ["vcvtr.u32.f32_2"] = "eebc0a40dm",
+ ["vcvtr.u32.f64_2"] = "eebc0b40dGm",
+ ["vcvt.f32.s32_2"] = "eeb80ac0dm",
+ ["vcvt.f64.s32_2"] = "eeb80bc0GdFm",
+ ["vcvt.f32.u32_2"] = "eeb80a40dm",
+ ["vcvt.f64.u32_2"] = "eeb80b40GdFm",
+ ["vcvt.f32.f64_2"] = "eeb70bc0dGm",
+ ["vcvt.f64.f32_2"] = "eeb70ac0GdFm",
+
+ -- VFPv4 only:
+ ["vfma.f32_3"] = "eea00a00dnm",
+ ["vfma.f64_3"] = "eea00b00Gdnm",
+ ["vfms.f32_3"] = "eea00a40dnm",
+ ["vfms.f64_3"] = "eea00b40Gdnm",
+ ["vfnma.f32_3"] = "ee900a40dnm",
+ ["vfnma.f64_3"] = "ee900b40Gdnm",
+ ["vfnms.f32_3"] = "ee900a00dnm",
+ ["vfnms.f64_3"] = "ee900b00Gdnm",
+
+ -- NYI: Advanced SIMD instructions.
+
+ -- NYI: I have no need for these instructions right now:
+ -- swp, swpb, strex, ldrex, strexd, ldrexd, strexb, ldrexb, strexh, ldrexh
+ -- msr, nopv6, yield, wfe, wfi, sev, dbg, bxj, smc, srs, rfe
+ -- cps, setend, pli, pld, pldw, clrex, dsb, dmb, isb
+ -- stc, ldc, mcr, mcr2, mrc, mrc2, mcrr, mcrr2, mrrc, mrrc2, cdp, cdp2
+}
+
+-- Add mnemonics for "s" variants.
+do
+ local t = {}
+ for k,v in pairs(map_op) do
+ if sub(v, -1) == "s" then
+ local v2 = sub(v, 1, 2)..char(byte(v, 3)+1)..sub(v, 4, -2)
+ t[sub(k, 1, -3).."s"..sub(k, -2)] = v2
+ end
+ end
+ for k,v in pairs(t) do
+ map_op[k] = v
+ end
+end
+
+------------------------------------------------------------------------------
+
+local function parse_gpr(expr)
+ local tname, ovreg = match(expr, "^([%w_]+):(r1?[0-9])$")
+ local tp = map_type[tname or expr]
+ if tp then
+ local reg = ovreg or tp.reg
+ if not reg then
+ werror("type `"..(tname or expr).."' needs a register override")
+ end
+ expr = reg
+ end
+ local r = match(expr, "^r(1?[0-9])$")
+ if r then
+ r = tonumber(r)
+ if r <= 15 then return r, tp end
+ end
+ werror("bad register name `"..expr.."'")
+end
+
+local function parse_gpr_pm(expr)
+ local pm, expr2 = match(expr, "^([+-]?)(.*)$")
+ return parse_gpr(expr2), (pm == "-")
+end
+
+local function parse_vr(expr, tp)
+ local t, r = match(expr, "^([sd])([0-9]+)$")
+ if t == tp then
+ r = tonumber(r)
+ if r <= 31 then
+ if t == "s" then return shr(r, 1), band(r, 1) end
+ return band(r, 15), shr(r, 4)
+ end
+ end
+ werror("bad register name `"..expr.."'")
+end
+
+local function parse_reglist(reglist)
+ reglist = match(reglist, "^{%s*([^}]*)}$")
+ if not reglist then werror("register list expected") end
+ local rr = 0
+ for p in gmatch(reglist..",", "%s*([^,]*),") do
+ local rbit = shl(1, parse_gpr(gsub(p, "%s+$", "")))
+ if band(rr, rbit) ~= 0 then
+ werror("duplicate register `"..p.."'")
+ end
+ rr = rr + rbit
+ end
+ return rr
+end
+
+local function parse_vrlist(reglist)
+ local ta, ra, tb, rb = match(reglist,
+ "^{%s*([sd])([0-9]+)%s*%-%s*([sd])([0-9]+)%s*}$")
+ ra, rb = tonumber(ra), tonumber(rb)
+ if ta and ta == tb and ra and rb and ra <= 31 and rb <= 31 and ra <= rb then
+ local nr = rb+1 - ra
+ if ta == "s" then
+ return shl(shr(ra,1),12)+shl(band(ra,1),22) + nr
+ else
+ return shl(band(ra,15),12)+shl(shr(ra,4),22) + nr*2 + 0x100
+ end
+ end
+ werror("register list expected")
+end
+
+local function parse_imm(imm, bits, shift, scale, signed)
+ imm = match(imm, "^#(.*)$")
+ if not imm then werror("expected immediate operand") end
+ local n = tonumber(imm)
+ if n then
+ local m = sar(n, scale)
+ if shl(m, scale) == n then
+ if signed then
+ local s = sar(m, bits-1)
+ if s == 0 then return shl(m, shift)
+ elseif s == -1 then return shl(m + shl(1, bits), shift) end
+ else
+ if sar(m, bits) == 0 then return shl(m, shift) end
+ end
+ end
+ werror("out of range immediate `"..imm.."'")
+ else
+ waction("IMM", (signed and 32768 or 0)+scale*1024+bits*32+shift, imm)
+ return 0
+ end
+end
+
+local function parse_imm12(imm)
+ local n = tonumber(imm)
+ if n then
+ local m = band(n)
+ for i=0,-15,-1 do
+ if shr(m, 8) == 0 then return m + shl(band(i, 15), 8) end
+ m = ror(m, 2)
+ end
+ werror("out of range immediate `"..imm.."'")
+ else
+ waction("IMM12", 0, imm)
+ return 0
+ end
+end
+
+local function parse_imm16(imm)
+ imm = match(imm, "^#(.*)$")
+ if not imm then werror("expected immediate operand") end
+ local n = tonumber(imm)
+ if n then
+ if shr(n, 16) == 0 then return band(n, 0x0fff) + shl(band(n, 0xf000), 4) end
+ werror("out of range immediate `"..imm.."'")
+ else
+ waction("IMM16", 32*16, imm)
+ return 0
+ end
+end
+
+local function parse_imm_load(imm, ext)
+ local n = tonumber(imm)
+ if n then
+ if ext then
+ if n >= -255 and n <= 255 then
+ local up = 0x00800000
+ if n < 0 then n = -n; up = 0 end
+ return shl(band(n, 0xf0), 4) + band(n, 0x0f) + up
+ end
+ else
+ if n >= -4095 and n <= 4095 then
+ if n >= 0 then return n+0x00800000 end
+ return -n
+ end
+ end
+ werror("out of range immediate `"..imm.."'")
+ else
+ waction(ext and "IMML8" or "IMML12", 32768 + shl(ext and 8 or 12, 5), imm)
+ return 0
+ end
+end
+
+local function parse_shift(shift, gprok)
+ if shift == "rrx" then
+ return 3 * 32
+ else
+ local s, s2 = match(shift, "^(%S+)%s*(.*)$")
+ s = map_shift[s]
+ if not s then werror("expected shift operand") end
+ if sub(s2, 1, 1) == "#" then
+ return parse_imm(s2, 5, 7, 0, false) + shl(s, 5)
+ else
+ if not gprok then werror("expected immediate shift operand") end
+ return shl(parse_gpr(s2), 8) + shl(s, 5) + 16
+ end
+ end
+end
+
+local function parse_label(label, def)
+ local prefix = sub(label, 1, 2)
+ -- =>label (pc label reference)
+ if prefix == "=>" then
+ return "PC", 0, sub(label, 3)
+ end
+ -- ->name (global label reference)
+ if prefix == "->" then
+ return "LG", map_global[sub(label, 3)]
+ end
+ if def then
+ -- [1-9] (local label definition)
+ if match(label, "^[1-9]$") then
+ return "LG", 10+tonumber(label)
+ end
+ else
+ -- [<>][1-9] (local label reference)
+ local dir, lnum = match(label, "^([<>])([1-9])$")
+ if dir then -- Fwd: 1-9, Bkwd: 11-19.
+ return "LG", lnum + (dir == ">" and 0 or 10)
+ end
+ -- extern label (extern label reference)
+ local extname = match(label, "^extern%s+(%S+)$")
+ if extname then
+ return "EXT", map_extern[extname]
+ end
+ end
+ werror("bad label `"..label.."'")
+end
+
+local function parse_load(params, nparams, n, op)
+ local oplo = band(op, 255)
+ local ext, ldrd = (oplo ~= 0), (oplo == 208)
+ local d
+ if (ldrd or oplo == 240) then
+ d = band(shr(op, 12), 15)
+ if band(d, 1) ~= 0 then werror("odd destination register") end
+ end
+ local pn = params[n]
+ local p1, wb = match(pn, "^%[%s*(.-)%s*%](!?)$")
+ local p2 = params[n+1]
+ if not p1 then
+ if not p2 then
+ if match(pn, "^[<>=%-]") or match(pn, "^extern%s+") then
+ local mode, n, s = parse_label(pn, false)
+ waction("REL_"..mode, n + (ext and 0x1800 or 0x0800), s, 1)
+ return op + 15 * 65536 + 0x01000000 + (ext and 0x00400000 or 0)
+ end
+ local reg, tailr = match(pn, "^([%w_:]+)%s*(.*)$")
+ if reg and tailr ~= "" then
+ local d, tp = parse_gpr(reg)
+ if tp then
+ waction(ext and "IMML8" or "IMML12", 32768 + 32*(ext and 8 or 12),
+ format(tp.ctypefmt, tailr))
+ return op + shl(d, 16) + 0x01000000 + (ext and 0x00400000 or 0)
+ end
+ end
+ end
+ werror("expected address operand")
+ end
+ if wb == "!" then op = op + 0x00200000 end
+ if p2 then
+ if wb == "!" then werror("bad use of '!'") end
+ local p3 = params[n+2]
+ op = op + shl(parse_gpr(p1), 16)
+ local imm = match(p2, "^#(.*)$")
+ if imm then
+ local m = parse_imm_load(imm, ext)
+ if p3 then werror("too many parameters") end
+ op = op + m + (ext and 0x00400000 or 0)
+ else
+ local m, neg = parse_gpr_pm(p2)
+ if ldrd and (m == d or m-1 == d) then werror("register conflict") end
+ op = op + m + (neg and 0 or 0x00800000) + (ext and 0 or 0x02000000)
+ if p3 then op = op + parse_shift(p3) end
+ end
+ else
+ local p1a, p2 = match(p1, "^([^,%s]*)%s*(.*)$")
+ op = op + shl(parse_gpr(p1a), 16) + 0x01000000
+ if p2 ~= "" then
+ local imm = match(p2, "^,%s*#(.*)$")
+ if imm then
+ local m = parse_imm_load(imm, ext)
+ op = op + m + (ext and 0x00400000 or 0)
+ else
+ local p2a, p3 = match(p2, "^,%s*([^,%s]*)%s*,?%s*(.*)$")
+ local m, neg = parse_gpr_pm(p2a)
+ if ldrd and (m == d or m-1 == d) then werror("register conflict") end
+ op = op + m + (neg and 0 or 0x00800000) + (ext and 0 or 0x02000000)
+ if p3 ~= "" then
+ if ext then werror("too many parameters") end
+ op = op + parse_shift(p3)
+ end
+ end
+ else
+ if wb == "!" then werror("bad use of '!'") end
+ op = op + (ext and 0x00c00000 or 0x00800000)
+ end
+ end
+ return op
+end
+
+local function parse_vload(q)
+ local reg, imm = match(q, "^%[%s*([^,%s]*)%s*(.*)%]$")
+ if reg then
+ local d = shl(parse_gpr(reg), 16)
+ if imm == "" then return d end
+ imm = match(imm, "^,%s*#(.*)$")
+ if imm then
+ local n = tonumber(imm)
+ if n then
+ if n >= -1020 and n <= 1020 and n%4 == 0 then
+ return d + (n >= 0 and n/4+0x00800000 or -n/4)
+ end
+ werror("out of range immediate `"..imm.."'")
+ else
+ waction("IMMV8", 32768 + 32*8, imm)
+ return d
+ end
+ end
+ else
+ if match(q, "^[<>=%-]") or match(q, "^extern%s+") then
+ local mode, n, s = parse_label(q, false)
+ waction("REL_"..mode, n + 0x2800, s, 1)
+ return 15 * 65536
+ end
+ local reg, tailr = match(q, "^([%w_:]+)%s*(.*)$")
+ if reg and tailr ~= "" then
+ local d, tp = parse_gpr(reg)
+ if tp then
+ waction("IMMV8", 32768 + 32*8, format(tp.ctypefmt, tailr))
+ return shl(d, 16)
+ end
+ end
+ end
+ werror("expected address operand")
+end
+
+------------------------------------------------------------------------------
+
+-- Handle opcodes defined with template strings.
+local function parse_template(params, template, nparams, pos)
+ local op = tonumber(sub(template, 1, 8), 16)
+ local n = 1
+ local vr = "s"
+
+ -- Process each character.
+ for p in gmatch(sub(template, 9), ".") do
+ local q = params[n]
+ if p == "D" then
+ op = op + shl(parse_gpr(q), 12); n = n + 1
+ elseif p == "N" then
+ op = op + shl(parse_gpr(q), 16); n = n + 1
+ elseif p == "S" then
+ op = op + shl(parse_gpr(q), 8); n = n + 1
+ elseif p == "M" then
+ op = op + parse_gpr(q); n = n + 1
+ elseif p == "d" then
+ local r,h = parse_vr(q, vr); op = op+shl(r,12)+shl(h,22); n = n + 1
+ elseif p == "n" then
+ local r,h = parse_vr(q, vr); op = op+shl(r,16)+shl(h,7); n = n + 1
+ elseif p == "m" then
+ local r,h = parse_vr(q, vr); op = op+r+shl(h,5); n = n + 1
+ elseif p == "P" then
+ local imm = match(q, "^#(.*)$")
+ if imm then
+ op = op + parse_imm12(imm) + 0x02000000
+ else
+ op = op + parse_gpr(q)
+ end
+ n = n + 1
+ elseif p == "p" then
+ op = op + parse_shift(q, true); n = n + 1
+ elseif p == "L" then
+ op = parse_load(params, nparams, n, op)
+ elseif p == "l" then
+ op = op + parse_vload(q)
+ elseif p == "B" then
+ local mode, n, s = parse_label(q, false)
+ waction("REL_"..mode, n, s, 1)
+ elseif p == "C" then -- blx gpr vs. blx label.
+ if match(q, "^([%w_]+):(r1?[0-9])$") or match(q, "^r(1?[0-9])$") then
+ op = op + parse_gpr(q)
+ else
+ if op < 0xe0000000 then werror("unconditional instruction") end
+ local mode, n, s = parse_label(q, false)
+ waction("REL_"..mode, n, s, 1)
+ op = 0xfa000000
+ end
+ elseif p == "F" then
+ vr = "s"
+ elseif p == "G" then
+ vr = "d"
+ elseif p == "o" then
+ local r, wb = match(q, "^([^!]*)(!?)$")
+ op = op + shl(parse_gpr(r), 16) + (wb == "!" and 0x00200000 or 0)
+ n = n + 1
+ elseif p == "R" then
+ op = op + parse_reglist(q); n = n + 1
+ elseif p == "r" then
+ op = op + parse_vrlist(q); n = n + 1
+ elseif p == "W" then
+ op = op + parse_imm16(q); n = n + 1
+ elseif p == "v" then
+ op = op + parse_imm(q, 5, 7, 0, false); n = n + 1
+ elseif p == "w" then
+ local imm = match(q, "^#(.*)$")
+ if imm then
+ op = op + parse_imm(q, 5, 7, 0, false); n = n + 1
+ else
+ op = op + shl(parse_gpr(q), 8) + 16
+ end
+ elseif p == "X" then
+ op = op + parse_imm(q, 5, 16, 0, false); n = n + 1
+ elseif p == "Y" then
+ local imm = tonumber(match(q, "^#(.*)$")); n = n + 1
+ if not imm or shr(imm, 8) ~= 0 then
+ werror("bad immediate operand")
+ end
+ op = op + shl(band(imm, 0xf0), 12) + band(imm, 0x0f)
+ elseif p == "K" then
+ local imm = tonumber(match(q, "^#(.*)$")); n = n + 1
+ if not imm or shr(imm, 16) ~= 0 then
+ werror("bad immediate operand")
+ end
+ op = op + shl(band(imm, 0xfff0), 4) + band(imm, 0x000f)
+ elseif p == "T" then
+ op = op + parse_imm(q, 24, 0, 0, false); n = n + 1
+ elseif p == "s" then
+ -- Ignored.
+ else
+ assert(false)
+ end
+ end
+ wputpos(pos, op)
+end
+
+map_op[".template__"] = function(params, template, nparams)
+ if not params then return template:gsub("%x%x%x%x%x%x%x%x", "") end
+
+ -- Limit number of section buffer positions used by a single dasm_put().
+ -- A single opcode needs a maximum of 3 positions.
+ if secpos+3 > maxsecpos then wflush() end
+ local pos = wpos()
+ local lpos, apos, spos = #actlist, #actargs, secpos
+
+ local ok, err
+ for t in gmatch(template, "[^|]+") do
+ ok, err = pcall(parse_template, params, t, nparams, pos)
+ if ok then return end
+ secpos = spos
+ actlist[lpos+1] = nil
+ actlist[lpos+2] = nil
+ actlist[lpos+3] = nil
+ actargs[apos+1] = nil
+ actargs[apos+2] = nil
+ actargs[apos+3] = nil
+ end
+ error(err, 0)
+end
+
+------------------------------------------------------------------------------
+
+-- Pseudo-opcode to mark the position where the action list is to be emitted.
+map_op[".actionlist_1"] = function(params)
+ if not params then return "cvar" end
+ local name = params[1] -- No syntax check. You get to keep the pieces.
+ wline(function(out) writeactions(out, name) end)
+end
+
+-- Pseudo-opcode to mark the position where the global enum is to be emitted.
+map_op[".globals_1"] = function(params)
+ if not params then return "prefix" end
+ local prefix = params[1] -- No syntax check. You get to keep the pieces.
+ wline(function(out) writeglobals(out, prefix) end)
+end
+
+-- Pseudo-opcode to mark the position where the global names are to be emitted.
+map_op[".globalnames_1"] = function(params)
+ if not params then return "cvar" end
+ local name = params[1] -- No syntax check. You get to keep the pieces.
+ wline(function(out) writeglobalnames(out, name) end)
+end
+
+-- Pseudo-opcode to mark the position where the extern names are to be emitted.
+map_op[".externnames_1"] = function(params)
+ if not params then return "cvar" end
+ local name = params[1] -- No syntax check. You get to keep the pieces.
+ wline(function(out) writeexternnames(out, name) end)
+end
+
+------------------------------------------------------------------------------
+
+-- Label pseudo-opcode (converted from trailing colon form).
+map_op[".label_1"] = function(params)
+ if not params then return "[1-9] | ->global | =>pcexpr" end
+ if secpos+1 > maxsecpos then wflush() end
+ local mode, n, s = parse_label(params[1], true)
+ if mode == "EXT" then werror("bad label definition") end
+ waction("LABEL_"..mode, n, s, 1)
+end
+
+------------------------------------------------------------------------------
+
+-- Pseudo-opcodes for data storage.
+map_op[".long_*"] = function(params)
+ if not params then return "imm..." end
+ for _,p in ipairs(params) do
+ local n = tonumber(p)
+ if not n then werror("bad immediate `"..p.."'") end
+ if n < 0 then n = n + 2^32 end
+ wputw(n)
+ if secpos+2 > maxsecpos then wflush() end
+ end
+end
+
+-- Alignment pseudo-opcode.
+map_op[".align_1"] = function(params)
+ if not params then return "numpow2" end
+ if secpos+1 > maxsecpos then wflush() end
+ local align = tonumber(params[1])
+ if align then
+ local x = align
+ -- Must be a power of 2 in the range (2 ... 256).
+ for i=1,8 do
+ x = x / 2
+ if x == 1 then
+ waction("ALIGN", align-1, nil, 1) -- Action byte is 2**n-1.
+ return
+ end
+ end
+ end
+ werror("bad alignment")
+end
+
+------------------------------------------------------------------------------
+
+-- Pseudo-opcode for (primitive) type definitions (map to C types).
+map_op[".type_3"] = function(params, nparams)
+ if not params then
+ return nparams == 2 and "name, ctype" or "name, ctype, reg"
+ end
+ local name, ctype, reg = params[1], params[2], params[3]
+ if not match(name, "^[%a_][%w_]*$") then
+ werror("bad type name `"..name.."'")
+ end
+ local tp = map_type[name]
+ if tp then
+ werror("duplicate type `"..name.."'")
+ end
+ -- Add #type to defines. A bit unclean to put it in map_archdef.
+ map_archdef["#"..name] = "sizeof("..ctype..")"
+ -- Add new type and emit shortcut define.
+ local num = ctypenum + 1
+ map_type[name] = {
+ ctype = ctype,
+ ctypefmt = format("Dt%X(%%s)", num),
+ reg = reg,
+ }
+ wline(format("#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)", num, ctype))
+ ctypenum = num
+end
+map_op[".type_2"] = map_op[".type_3"]
+
+-- Dump type definitions.
+local function dumptypes(out, lvl)
+ local t = {}
+ for name in pairs(map_type) do t[#t+1] = name end
+ sort(t)
+ out:write("Type definitions:\n")
+ for _,name in ipairs(t) do
+ local tp = map_type[name]
+ local reg = tp.reg or ""
+ out:write(format(" %-20s %-20s %s\n", name, tp.ctype, reg))
+ end
+ out:write("\n")
+end
+
+------------------------------------------------------------------------------
+
+-- Set the current section.
+function _M.section(num)
+ waction("SECTION", num)
+ wflush(true) -- SECTION is a terminal action.
+end
+
+------------------------------------------------------------------------------
+
+-- Dump architecture description.
+function _M.dumparch(out)
+ out:write(format("DynASM %s version %s, released %s\n\n",
+ _info.arch, _info.version, _info.release))
+ dumpactions(out)
+end
+
+-- Dump all user defined elements.
+function _M.dumpdef(out, lvl)
+ dumptypes(out, lvl)
+ dumpglobals(out, lvl)
+ dumpexterns(out, lvl)
+end
+
+------------------------------------------------------------------------------
+
+-- Pass callbacks from/to the DynASM core.
+function _M.passcb(wl, we, wf, ww)
+ wline, werror, wfatal, wwarn = wl, we, wf, ww
+ return wflush
+end
+
+-- Setup the arch-specific module.
+function _M.setup(arch, opt)
+ g_arch, g_opt = arch, opt
+end
+
+-- Merge the core maps and the arch-specific maps.
+function _M.mergemaps(map_coreop, map_def)
+ setmetatable(map_op, { __index = function(t, k)
+ local v = map_coreop[k]
+ if v then return v end
+ local k1, cc, k2 = match(k, "^(.-)(..)([._].*)$")
+ local cv = map_cond[cc]
+ if cv then
+ local v = rawget(t, k1..k2)
+ if type(v) == "string" then
+ local scv = format("%x", cv)
+ return gsub(scv..sub(v, 2), "|e", "|"..scv)
+ end
+ end
+ end })
+ setmetatable(map_def, { __index = map_archdef })
+ return map_op, map_def
+end
+
+return _M
+
+------------------------------------------------------------------------------
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_mips.h b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_mips.h
new file mode 100644
index 0000000..46af034
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_mips.h
@@ -0,0 +1,417 @@
+/*
+** DynASM MIPS encoding engine.
+** Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+** Released under the MIT license. See dynasm.lua for full copyright notice.
+*/
+
+#include <stddef.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+
+#define DASM_ARCH "mips"
+
+#ifndef DASM_EXTERN
+#define DASM_EXTERN(a,b,c,d) 0
+#endif
+
+/* Action definitions. */
+enum {
+ DASM_STOP, DASM_SECTION, DASM_ESC, DASM_REL_EXT,
+ /* The following actions need a buffer position. */
+ DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG,
+ /* The following actions also have an argument. */
+ DASM_REL_PC, DASM_LABEL_PC, DASM_IMM,
+ DASM__MAX
+};
+
+/* Maximum number of section buffer positions for a single dasm_put() call. */
+#define DASM_MAXSECPOS 25
+
+/* DynASM encoder status codes. Action list offset or number are or'ed in. */
+#define DASM_S_OK 0x00000000
+#define DASM_S_NOMEM 0x01000000
+#define DASM_S_PHASE 0x02000000
+#define DASM_S_MATCH_SEC 0x03000000
+#define DASM_S_RANGE_I 0x11000000
+#define DASM_S_RANGE_SEC 0x12000000
+#define DASM_S_RANGE_LG 0x13000000
+#define DASM_S_RANGE_PC 0x14000000
+#define DASM_S_RANGE_REL 0x15000000
+#define DASM_S_UNDEF_LG 0x21000000
+#define DASM_S_UNDEF_PC 0x22000000
+
+/* Macros to convert positions (8 bit section + 24 bit index). */
+#define DASM_POS2IDX(pos) ((pos)&0x00ffffff)
+#define DASM_POS2BIAS(pos) ((pos)&0xff000000)
+#define DASM_SEC2POS(sec) ((sec)<<24)
+#define DASM_POS2SEC(pos) ((pos)>>24)
+#define DASM_POS2PTR(D, pos) (D->sections[DASM_POS2SEC(pos)].rbuf + (pos))
+
+/* Action list type. */
+typedef const unsigned int *dasm_ActList;
+
+/* Per-section structure. */
+typedef struct dasm_Section {
+ int *rbuf; /* Biased buffer pointer (negative section bias). */
+ int *buf; /* True buffer pointer. */
+ size_t bsize; /* Buffer size in bytes. */
+ int pos; /* Biased buffer position. */
+ int epos; /* End of biased buffer position - max single put. */
+ int ofs; /* Byte offset into section. */
+} dasm_Section;
+
+/* Core structure holding the DynASM encoding state. */
+struct dasm_State {
+ size_t psize; /* Allocated size of this structure. */
+ dasm_ActList actionlist; /* Current actionlist pointer. */
+ int *lglabels; /* Local/global chain/pos ptrs. */
+ size_t lgsize;
+ int *pclabels; /* PC label chains/pos ptrs. */
+ size_t pcsize;
+ void **globals; /* Array of globals (bias -10). */
+ dasm_Section *section; /* Pointer to active section. */
+ size_t codesize; /* Total size of all code sections. */
+ int maxsection; /* 0 <= sectionidx < maxsection. */
+ int status; /* Status code. */
+ dasm_Section sections[1]; /* All sections. Alloc-extended. */
+};
+
+/* The size of the core structure depends on the max. number of sections. */
+#define DASM_PSZ(ms) (sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section))
+
+
+/* Initialize DynASM state. */
+void dasm_init(Dst_DECL, int maxsection)
+{
+ dasm_State *D;
+ size_t psz = 0;
+ int i;
+ Dst_REF = NULL;
+ DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));
+ D = Dst_REF;
+ D->psize = psz;
+ D->lglabels = NULL;
+ D->lgsize = 0;
+ D->pclabels = NULL;
+ D->pcsize = 0;
+ D->globals = NULL;
+ D->maxsection = maxsection;
+ for (i = 0; i < maxsection; i++) {
+ D->sections[i].buf = NULL; /* Need this for pass3. */
+ D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);
+ D->sections[i].bsize = 0;
+ D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */
+ }
+}
+
+/* Free DynASM state. */
+void dasm_free(Dst_DECL)
+{
+ dasm_State *D = Dst_REF;
+ int i;
+ for (i = 0; i < D->maxsection; i++)
+ if (D->sections[i].buf)
+ DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize);
+ if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize);
+ if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize);
+ DASM_M_FREE(Dst, D, D->psize);
+}
+
+/* Setup global label array. Must be called before dasm_setup(). */
+void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)
+{
+ dasm_State *D = Dst_REF;
+ D->globals = gl - 10; /* Negative bias to compensate for locals. */
+ DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));
+}
+
+/* Grow PC label array. Can be called after dasm_setup(), too. */
+void dasm_growpc(Dst_DECL, unsigned int maxpc)
+{
+ dasm_State *D = Dst_REF;
+ size_t osz = D->pcsize;
+ DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int));
+ memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz);
+}
+
+/* Setup encoder. */
+void dasm_setup(Dst_DECL, const void *actionlist)
+{
+ dasm_State *D = Dst_REF;
+ int i;
+ D->actionlist = (dasm_ActList)actionlist;
+ D->status = DASM_S_OK;
+ D->section = &D->sections[0];
+ memset((void *)D->lglabels, 0, D->lgsize);
+ if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize);
+ for (i = 0; i < D->maxsection; i++) {
+ D->sections[i].pos = DASM_SEC2POS(i);
+ D->sections[i].ofs = 0;
+ }
+}
+
+
+#ifdef DASM_CHECKS
+#define CK(x, st) \
+ do { if (!(x)) { \
+ D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0)
+#define CKPL(kind, st) \
+ do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \
+ D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0)
+#else
+#define CK(x, st) ((void)0)
+#define CKPL(kind, st) ((void)0)
+#endif
+
+/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */
+void dasm_put(Dst_DECL, int start, ...)
+{
+ va_list ap;
+ dasm_State *D = Dst_REF;
+ dasm_ActList p = D->actionlist + start;
+ dasm_Section *sec = D->section;
+ int pos = sec->pos, ofs = sec->ofs;
+ int *b;
+
+ if (pos >= sec->epos) {
+ DASM_M_GROW(Dst, int, sec->buf, sec->bsize,
+ sec->bsize + 2*DASM_MAXSECPOS*sizeof(int));
+ sec->rbuf = sec->buf - DASM_POS2BIAS(pos);
+ sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos);
+ }
+
+ b = sec->rbuf;
+ b[pos++] = start;
+
+ va_start(ap, start);
+ while (1) {
+ unsigned int ins = *p++;
+ unsigned int action = (ins >> 16) - 0xff00;
+ if (action >= DASM__MAX) {
+ ofs += 4;
+ } else {
+ int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0;
+ switch (action) {
+ case DASM_STOP: goto stop;
+ case DASM_SECTION:
+ n = (ins & 255); CK(n < D->maxsection, RANGE_SEC);
+ D->section = &D->sections[n]; goto stop;
+ case DASM_ESC: p++; ofs += 4; break;
+ case DASM_REL_EXT: break;
+ case DASM_ALIGN: ofs += (ins & 255); b[pos++] = ofs; break;
+ case DASM_REL_LG:
+ n = (ins & 2047) - 10; pl = D->lglabels + n;
+ /* Bkwd rel or global. */
+ if (n >= 0) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; }
+ pl += 10; n = *pl;
+ if (n < 0) n = 0; /* Start new chain for fwd rel if label exists. */
+ goto linkrel;
+ case DASM_REL_PC:
+ pl = D->pclabels + n; CKPL(pc, PC);
+ putrel:
+ n = *pl;
+ if (n < 0) { /* Label exists. Get label pos and store it. */
+ b[pos] = -n;
+ } else {
+ linkrel:
+ b[pos] = n; /* Else link to rel chain, anchored at label. */
+ *pl = pos;
+ }
+ pos++;
+ break;
+ case DASM_LABEL_LG:
+ pl = D->lglabels + (ins & 2047) - 10; CKPL(lg, LG); goto putlabel;
+ case DASM_LABEL_PC:
+ pl = D->pclabels + n; CKPL(pc, PC);
+ putlabel:
+ n = *pl; /* n > 0: Collapse rel chain and replace with label pos. */
+ while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos;
+ }
+ *pl = -pos; /* Label exists now. */
+ b[pos++] = ofs; /* Store pass1 offset estimate. */
+ break;
+ case DASM_IMM:
+#ifdef DASM_CHECKS
+ CK((n & ((1<<((ins>>10)&31))-1)) == 0, RANGE_I);
+#endif
+ n >>= ((ins>>10)&31);
+#ifdef DASM_CHECKS
+ if (ins & 0x8000)
+ CK(((n + (1<<(((ins>>5)&31)-1)))>>((ins>>5)&31)) == 0, RANGE_I);
+ else
+ CK((n>>((ins>>5)&31)) == 0, RANGE_I);
+#endif
+ b[pos++] = n;
+ break;
+ }
+ }
+ }
+stop:
+ va_end(ap);
+ sec->pos = pos;
+ sec->ofs = ofs;
+}
+#undef CK
+
+/* Pass 2: Link sections, shrink aligns, fix label offsets. */
+int dasm_link(Dst_DECL, size_t *szp)
+{
+ dasm_State *D = Dst_REF;
+ int secnum;
+ int ofs = 0;
+
+#ifdef DASM_CHECKS
+ *szp = 0;
+ if (D->status != DASM_S_OK) return D->status;
+ {
+ int pc;
+ for (pc = 0; pc*sizeof(int) < D->pcsize; pc++)
+ if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc;
+ }
+#endif
+
+ { /* Handle globals not defined in this translation unit. */
+ int idx;
+ for (idx = 20; idx*sizeof(int) < D->lgsize; idx++) {
+ int n = D->lglabels[idx];
+ /* Undefined label: Collapse rel chain and replace with marker (< 0). */
+ while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }
+ }
+ }
+
+ /* Combine all code sections. No support for data sections (yet). */
+ for (secnum = 0; secnum < D->maxsection; secnum++) {
+ dasm_Section *sec = D->sections + secnum;
+ int *b = sec->rbuf;
+ int pos = DASM_SEC2POS(secnum);
+ int lastpos = sec->pos;
+
+ while (pos != lastpos) {
+ dasm_ActList p = D->actionlist + b[pos++];
+ while (1) {
+ unsigned int ins = *p++;
+ unsigned int action = (ins >> 16) - 0xff00;
+ switch (action) {
+ case DASM_STOP: case DASM_SECTION: goto stop;
+ case DASM_ESC: p++; break;
+ case DASM_REL_EXT: break;
+ case DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break;
+ case DASM_REL_LG: case DASM_REL_PC: pos++; break;
+ case DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break;
+ case DASM_IMM: pos++; break;
+ }
+ }
+ stop: (void)0;
+ }
+ ofs += sec->ofs; /* Next section starts right after current section. */
+ }
+
+ D->codesize = ofs; /* Total size of all code sections */
+ *szp = ofs;
+ return DASM_S_OK;
+}
+
+#ifdef DASM_CHECKS
+#define CK(x, st) \
+ do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0)
+#else
+#define CK(x, st) ((void)0)
+#endif
+
+/* Pass 3: Encode sections. */
+int dasm_encode(Dst_DECL, void *buffer)
+{
+ dasm_State *D = Dst_REF;
+ char *base = (char *)buffer;
+ unsigned int *cp = (unsigned int *)buffer;
+ int secnum;
+
+ /* Encode all code sections. No support for data sections (yet). */
+ for (secnum = 0; secnum < D->maxsection; secnum++) {
+ dasm_Section *sec = D->sections + secnum;
+ int *b = sec->buf;
+ int *endb = sec->rbuf + sec->pos;
+
+ while (b != endb) {
+ dasm_ActList p = D->actionlist + *b++;
+ while (1) {
+ unsigned int ins = *p++;
+ unsigned int action = (ins >> 16) - 0xff00;
+ int n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0;
+ switch (action) {
+ case DASM_STOP: case DASM_SECTION: goto stop;
+ case DASM_ESC: *cp++ = *p++; break;
+ case DASM_REL_EXT:
+ n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins & 2047), 1);
+ goto patchrel;
+ case DASM_ALIGN:
+ ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0x60000000;
+ break;
+ case DASM_REL_LG:
+ CK(n >= 0, UNDEF_LG);
+ /* fallthrough */
+ case DASM_REL_PC:
+ CK(n >= 0, UNDEF_PC);
+ n = *DASM_POS2PTR(D, n);
+ if (ins & 2048)
+ n = n - (int)((char *)cp - base);
+ else
+ n = (n + (int)base) & 0x0fffffff;
+ patchrel:
+ CK((n & 3) == 0 &&
+ ((n + ((ins & 2048) ? 0x00020000 : 0)) >>
+ ((ins & 2048) ? 18 : 28)) == 0, RANGE_REL);
+ cp[-1] |= ((n>>2) & ((ins & 2048) ? 0x0000ffff: 0x03ffffff));
+ break;
+ case DASM_LABEL_LG:
+ ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);
+ break;
+ case DASM_LABEL_PC: break;
+ case DASM_IMM:
+ cp[-1] |= (n & ((1<<((ins>>5)&31))-1)) << (ins&31);
+ break;
+ default: *cp++ = ins; break;
+ }
+ }
+ stop: (void)0;
+ }
+ }
+
+ if (base + D->codesize != (char *)cp) /* Check for phase errors. */
+ return DASM_S_PHASE;
+ return DASM_S_OK;
+}
+#undef CK
+
+/* Get PC label offset. */
+int dasm_getpclabel(Dst_DECL, unsigned int pc)
+{
+ dasm_State *D = Dst_REF;
+ if (pc*sizeof(int) < D->pcsize) {
+ int pos = D->pclabels[pc];
+ if (pos < 0) return *DASM_POS2PTR(D, -pos);
+ if (pos > 0) return -1; /* Undefined. */
+ }
+ return -2; /* Unused or out of range. */
+}
+
+#ifdef DASM_CHECKS
+/* Optional sanity checker to call between isolated encoding steps. */
+int dasm_checkstep(Dst_DECL, int secmatch)
+{
+ dasm_State *D = Dst_REF;
+ if (D->status == DASM_S_OK) {
+ int i;
+ for (i = 1; i <= 9; i++) {
+ if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_LG|i; break; }
+ D->lglabels[i] = 0;
+ }
+ }
+ if (D->status == DASM_S_OK && secmatch >= 0 &&
+ D->section != &D->sections[secmatch])
+ D->status = DASM_S_MATCH_SEC|(D->section-D->sections);
+ return D->status;
+}
+#endif
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_mips.lua b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_mips.lua
new file mode 100644
index 0000000..8e250ce
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_mips.lua
@@ -0,0 +1,953 @@
+------------------------------------------------------------------------------
+-- DynASM MIPS module.
+--
+-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+-- See dynasm.lua for full copyright notice.
+------------------------------------------------------------------------------
+
+-- Module information:
+local _info = {
+ arch = "mips",
+ description = "DynASM MIPS module",
+ version = "1.3.0",
+ vernum = 10300,
+ release = "2012-01-23",
+ author = "Mike Pall",
+ license = "MIT",
+}
+
+-- Exported glue functions for the arch-specific module.
+local _M = { _info = _info }
+
+-- Cache library functions.
+local type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs
+local assert, setmetatable = assert, setmetatable
+local _s = string
+local sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char
+local match, gmatch = _s.match, _s.gmatch
+local concat, sort = table.concat, table.sort
+local bit = bit or require("bit")
+local band, shl, sar, tohex = bit.band, bit.lshift, bit.arshift, bit.tohex
+
+-- Inherited tables and callbacks.
+local g_opt, g_arch
+local wline, werror, wfatal, wwarn
+
+-- Action name list.
+-- CHECK: Keep this in sync with the C code!
+local action_names = {
+ "STOP", "SECTION", "ESC", "REL_EXT",
+ "ALIGN", "REL_LG", "LABEL_LG",
+ "REL_PC", "LABEL_PC", "IMM",
+}
+
+-- Maximum number of section buffer positions for dasm_put().
+-- CHECK: Keep this in sync with the C code!
+local maxsecpos = 25 -- Keep this low, to avoid excessively long C lines.
+
+-- Action name -> action number.
+local map_action = {}
+for n,name in ipairs(action_names) do
+ map_action[name] = n-1
+end
+
+-- Action list buffer.
+local actlist = {}
+
+-- Argument list for next dasm_put(). Start with offset 0 into action list.
+local actargs = { 0 }
+
+-- Current number of section buffer positions for dasm_put().
+local secpos = 1
+
+------------------------------------------------------------------------------
+
+-- Dump action names and numbers.
+local function dumpactions(out)
+ out:write("DynASM encoding engine action codes:\n")
+ for n,name in ipairs(action_names) do
+ local num = map_action[name]
+ out:write(format(" %-10s %02X %d\n", name, num, num))
+ end
+ out:write("\n")
+end
+
+-- Write action list buffer as a huge static C array.
+local function writeactions(out, name)
+ local nn = #actlist
+ if nn == 0 then nn = 1; actlist[0] = map_action.STOP end
+ out:write("static const unsigned int ", name, "[", nn, "] = {\n")
+ for i = 1,nn-1 do
+ assert(out:write("0x", tohex(actlist[i]), ",\n"))
+ end
+ assert(out:write("0x", tohex(actlist[nn]), "\n};\n\n"))
+end
+
+------------------------------------------------------------------------------
+
+-- Add word to action list.
+local function wputxw(n)
+ assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, "word out of range")
+ actlist[#actlist+1] = n
+end
+
+-- Add action to list with optional arg. Advance buffer pos, too.
+local function waction(action, val, a, num)
+ local w = assert(map_action[action], "bad action name `"..action.."'")
+ wputxw(0xff000000 + w * 0x10000 + (val or 0))
+ if a then actargs[#actargs+1] = a end
+ if a or num then secpos = secpos + (num or 1) end
+end
+
+-- Flush action list (intervening C code or buffer pos overflow).
+local function wflush(term)
+ if #actlist == actargs[1] then return end -- Nothing to flush.
+ if not term then waction("STOP") end -- Terminate action list.
+ wline(format("dasm_put(Dst, %s);", concat(actargs, ", ")), true)
+ actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put().
+ secpos = 1 -- The actionlist offset occupies a buffer position, too.
+end
+
+-- Put escaped word.
+local function wputw(n)
+ if n >= 0xff000000 then waction("ESC") end
+ wputxw(n)
+end
+
+-- Reserve position for word.
+local function wpos()
+ local pos = #actlist+1
+ actlist[pos] = ""
+ return pos
+end
+
+-- Store word to reserved position.
+local function wputpos(pos, n)
+ assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, "word out of range")
+ actlist[pos] = n
+end
+
+------------------------------------------------------------------------------
+
+-- Global label name -> global label number. With auto assignment on 1st use.
+local next_global = 20
+local map_global = setmetatable({}, { __index = function(t, name)
+ if not match(name, "^[%a_][%w_]*$") then werror("bad global label") end
+ local n = next_global
+ if n > 2047 then werror("too many global labels") end
+ next_global = n + 1
+ t[name] = n
+ return n
+end})
+
+-- Dump global labels.
+local function dumpglobals(out, lvl)
+ local t = {}
+ for name, n in pairs(map_global) do t[n] = name end
+ out:write("Global labels:\n")
+ for i=20,next_global-1 do
+ out:write(format(" %s\n", t[i]))
+ end
+ out:write("\n")
+end
+
+-- Write global label enum.
+local function writeglobals(out, prefix)
+ local t = {}
+ for name, n in pairs(map_global) do t[n] = name end
+ out:write("enum {\n")
+ for i=20,next_global-1 do
+ out:write(" ", prefix, t[i], ",\n")
+ end
+ out:write(" ", prefix, "_MAX\n};\n")
+end
+
+-- Write global label names.
+local function writeglobalnames(out, name)
+ local t = {}
+ for name, n in pairs(map_global) do t[n] = name end
+ out:write("static const char *const ", name, "[] = {\n")
+ for i=20,next_global-1 do
+ out:write(" \"", t[i], "\",\n")
+ end
+ out:write(" (const char *)0\n};\n")
+end
+
+------------------------------------------------------------------------------
+
+-- Extern label name -> extern label number. With auto assignment on 1st use.
+local next_extern = 0
+local map_extern_ = {}
+local map_extern = setmetatable({}, { __index = function(t, name)
+ -- No restrictions on the name for now.
+ local n = next_extern
+ if n > 2047 then werror("too many extern labels") end
+ next_extern = n + 1
+ t[name] = n
+ map_extern_[n] = name
+ return n
+end})
+
+-- Dump extern labels.
+local function dumpexterns(out, lvl)
+ out:write("Extern labels:\n")
+ for i=0,next_extern-1 do
+ out:write(format(" %s\n", map_extern_[i]))
+ end
+ out:write("\n")
+end
+
+-- Write extern label names.
+local function writeexternnames(out, name)
+ out:write("static const char *const ", name, "[] = {\n")
+ for i=0,next_extern-1 do
+ out:write(" \"", map_extern_[i], "\",\n")
+ end
+ out:write(" (const char *)0\n};\n")
+end
+
+------------------------------------------------------------------------------
+
+-- Arch-specific maps.
+local map_archdef = { sp="r29", ra="r31" } -- Ext. register name -> int. name.
+
+local map_type = {} -- Type name -> { ctype, reg }
+local ctypenum = 0 -- Type number (for Dt... macros).
+
+-- Reverse defines for registers.
+function _M.revdef(s)
+ if s == "r29" then return "sp"
+ elseif s == "r31" then return "ra" end
+ return s
+end
+
+------------------------------------------------------------------------------
+
+-- Template strings for MIPS instructions.
+local map_op = {
+ -- First-level opcodes.
+ j_1 = "08000000J",
+ jal_1 = "0c000000J",
+ b_1 = "10000000B",
+ beqz_2 = "10000000SB",
+ beq_3 = "10000000STB",
+ bnez_2 = "14000000SB",
+ bne_3 = "14000000STB",
+ blez_2 = "18000000SB",
+ bgtz_2 = "1c000000SB",
+ addi_3 = "20000000TSI",
+ li_2 = "24000000TI",
+ addiu_3 = "24000000TSI",
+ slti_3 = "28000000TSI",
+ sltiu_3 = "2c000000TSI",
+ andi_3 = "30000000TSU",
+ lu_2 = "34000000TU",
+ ori_3 = "34000000TSU",
+ xori_3 = "38000000TSU",
+ lui_2 = "3c000000TU",
+ beqzl_2 = "50000000SB",
+ beql_3 = "50000000STB",
+ bnezl_2 = "54000000SB",
+ bnel_3 = "54000000STB",
+ blezl_2 = "58000000SB",
+ bgtzl_2 = "5c000000SB",
+ lb_2 = "80000000TO",
+ lh_2 = "84000000TO",
+ lwl_2 = "88000000TO",
+ lw_2 = "8c000000TO",
+ lbu_2 = "90000000TO",
+ lhu_2 = "94000000TO",
+ lwr_2 = "98000000TO",
+ sb_2 = "a0000000TO",
+ sh_2 = "a4000000TO",
+ swl_2 = "a8000000TO",
+ sw_2 = "ac000000TO",
+ swr_2 = "b8000000TO",
+ cache_2 = "bc000000NO",
+ ll_2 = "c0000000TO",
+ lwc1_2 = "c4000000HO",
+ pref_2 = "cc000000NO",
+ ldc1_2 = "d4000000HO",
+ sc_2 = "e0000000TO",
+ swc1_2 = "e4000000HO",
+ sdc1_2 = "f4000000HO",
+
+ -- Opcode SPECIAL.
+ nop_0 = "00000000",
+ sll_3 = "00000000DTA",
+ movf_2 = "00000001DS",
+ movf_3 = "00000001DSC",
+ movt_2 = "00010001DS",
+ movt_3 = "00010001DSC",
+ srl_3 = "00000002DTA",
+ rotr_3 = "00200002DTA",
+ sra_3 = "00000003DTA",
+ sllv_3 = "00000004DTS",
+ srlv_3 = "00000006DTS",
+ rotrv_3 = "00000046DTS",
+ srav_3 = "00000007DTS",
+ jr_1 = "00000008S",
+ jalr_1 = "0000f809S",
+ jalr_2 = "00000009DS",
+ movz_3 = "0000000aDST",
+ movn_3 = "0000000bDST",
+ syscall_0 = "0000000c",
+ syscall_1 = "0000000cY",
+ break_0 = "0000000d",
+ break_1 = "0000000dY",
+ sync_0 = "0000000f",
+ mfhi_1 = "00000010D",
+ mthi_1 = "00000011S",
+ mflo_1 = "00000012D",
+ mtlo_1 = "00000013S",
+ mult_2 = "00000018ST",
+ multu_2 = "00000019ST",
+ div_2 = "0000001aST",
+ divu_2 = "0000001bST",
+ add_3 = "00000020DST",
+ move_2 = "00000021DS",
+ addu_3 = "00000021DST",
+ sub_3 = "00000022DST",
+ negu_2 = "00000023DT",
+ subu_3 = "00000023DST",
+ and_3 = "00000024DST",
+ or_3 = "00000025DST",
+ xor_3 = "00000026DST",
+ not_2 = "00000027DS",
+ nor_3 = "00000027DST",
+ slt_3 = "0000002aDST",
+ sltu_3 = "0000002bDST",
+ tge_2 = "00000030ST",
+ tge_3 = "00000030STZ",
+ tgeu_2 = "00000031ST",
+ tgeu_3 = "00000031STZ",
+ tlt_2 = "00000032ST",
+ tlt_3 = "00000032STZ",
+ tltu_2 = "00000033ST",
+ tltu_3 = "00000033STZ",
+ teq_2 = "00000034ST",
+ teq_3 = "00000034STZ",
+ tne_2 = "00000036ST",
+ tne_3 = "00000036STZ",
+
+ -- Opcode REGIMM.
+ bltz_2 = "04000000SB",
+ bgez_2 = "04010000SB",
+ bltzl_2 = "04020000SB",
+ bgezl_2 = "04030000SB",
+ tgei_2 = "04080000SI",
+ tgeiu_2 = "04090000SI",
+ tlti_2 = "040a0000SI",
+ tltiu_2 = "040b0000SI",
+ teqi_2 = "040c0000SI",
+ tnei_2 = "040e0000SI",
+ bltzal_2 = "04100000SB",
+ bal_1 = "04110000B",
+ bgezal_2 = "04110000SB",
+ bltzall_2 = "04120000SB",
+ bgezall_2 = "04130000SB",
+ synci_1 = "041f0000O",
+
+ -- Opcode SPECIAL2.
+ madd_2 = "70000000ST",
+ maddu_2 = "70000001ST",
+ mul_3 = "70000002DST",
+ msub_2 = "70000004ST",
+ msubu_2 = "70000005ST",
+ clz_2 = "70000020DS=",
+ clo_2 = "70000021DS=",
+ sdbbp_0 = "7000003f",
+ sdbbp_1 = "7000003fY",
+
+ -- Opcode SPECIAL3.
+ ext_4 = "7c000000TSAM", -- Note: last arg is msbd = size-1
+ ins_4 = "7c000004TSAM", -- Note: last arg is msb = pos+size-1
+ wsbh_2 = "7c0000a0DT",
+ seb_2 = "7c000420DT",
+ seh_2 = "7c000620DT",
+ rdhwr_2 = "7c00003bTD",
+
+ -- Opcode COP0.
+ mfc0_2 = "40000000TD",
+ mfc0_3 = "40000000TDW",
+ mtc0_2 = "40800000TD",
+ mtc0_3 = "40800000TDW",
+ rdpgpr_2 = "41400000DT",
+ di_0 = "41606000",
+ di_1 = "41606000T",
+ ei_0 = "41606020",
+ ei_1 = "41606020T",
+ wrpgpr_2 = "41c00000DT",
+ tlbr_0 = "42000001",
+ tlbwi_0 = "42000002",
+ tlbwr_0 = "42000006",
+ tlbp_0 = "42000008",
+ eret_0 = "42000018",
+ deret_0 = "4200001f",
+ wait_0 = "42000020",
+
+ -- Opcode COP1.
+ mfc1_2 = "44000000TG",
+ cfc1_2 = "44400000TG",
+ mfhc1_2 = "44600000TG",
+ mtc1_2 = "44800000TG",
+ ctc1_2 = "44c00000TG",
+ mthc1_2 = "44e00000TG",
+
+ bc1f_1 = "45000000B",
+ bc1f_2 = "45000000CB",
+ bc1t_1 = "45010000B",
+ bc1t_2 = "45010000CB",
+ bc1fl_1 = "45020000B",
+ bc1fl_2 = "45020000CB",
+ bc1tl_1 = "45030000B",
+ bc1tl_2 = "45030000CB",
+
+ ["add.s_3"] = "46000000FGH",
+ ["sub.s_3"] = "46000001FGH",
+ ["mul.s_3"] = "46000002FGH",
+ ["div.s_3"] = "46000003FGH",
+ ["sqrt.s_2"] = "46000004FG",
+ ["abs.s_2"] = "46000005FG",
+ ["mov.s_2"] = "46000006FG",
+ ["neg.s_2"] = "46000007FG",
+ ["round.l.s_2"] = "46000008FG",
+ ["trunc.l.s_2"] = "46000009FG",
+ ["ceil.l.s_2"] = "4600000aFG",
+ ["floor.l.s_2"] = "4600000bFG",
+ ["round.w.s_2"] = "4600000cFG",
+ ["trunc.w.s_2"] = "4600000dFG",
+ ["ceil.w.s_2"] = "4600000eFG",
+ ["floor.w.s_2"] = "4600000fFG",
+ ["movf.s_2"] = "46000011FG",
+ ["movf.s_3"] = "46000011FGC",
+ ["movt.s_2"] = "46010011FG",
+ ["movt.s_3"] = "46010011FGC",
+ ["movz.s_3"] = "46000012FGT",
+ ["movn.s_3"] = "46000013FGT",
+ ["recip.s_2"] = "46000015FG",
+ ["rsqrt.s_2"] = "46000016FG",
+ ["cvt.d.s_2"] = "46000021FG",
+ ["cvt.w.s_2"] = "46000024FG",
+ ["cvt.l.s_2"] = "46000025FG",
+ ["cvt.ps.s_3"] = "46000026FGH",
+ ["c.f.s_2"] = "46000030GH",
+ ["c.f.s_3"] = "46000030VGH",
+ ["c.un.s_2"] = "46000031GH",
+ ["c.un.s_3"] = "46000031VGH",
+ ["c.eq.s_2"] = "46000032GH",
+ ["c.eq.s_3"] = "46000032VGH",
+ ["c.ueq.s_2"] = "46000033GH",
+ ["c.ueq.s_3"] = "46000033VGH",
+ ["c.olt.s_2"] = "46000034GH",
+ ["c.olt.s_3"] = "46000034VGH",
+ ["c.ult.s_2"] = "46000035GH",
+ ["c.ult.s_3"] = "46000035VGH",
+ ["c.ole.s_2"] = "46000036GH",
+ ["c.ole.s_3"] = "46000036VGH",
+ ["c.ule.s_2"] = "46000037GH",
+ ["c.ule.s_3"] = "46000037VGH",
+ ["c.sf.s_2"] = "46000038GH",
+ ["c.sf.s_3"] = "46000038VGH",
+ ["c.ngle.s_2"] = "46000039GH",
+ ["c.ngle.s_3"] = "46000039VGH",
+ ["c.seq.s_2"] = "4600003aGH",
+ ["c.seq.s_3"] = "4600003aVGH",
+ ["c.ngl.s_2"] = "4600003bGH",
+ ["c.ngl.s_3"] = "4600003bVGH",
+ ["c.lt.s_2"] = "4600003cGH",
+ ["c.lt.s_3"] = "4600003cVGH",
+ ["c.nge.s_2"] = "4600003dGH",
+ ["c.nge.s_3"] = "4600003dVGH",
+ ["c.le.s_2"] = "4600003eGH",
+ ["c.le.s_3"] = "4600003eVGH",
+ ["c.ngt.s_2"] = "4600003fGH",
+ ["c.ngt.s_3"] = "4600003fVGH",
+
+ ["add.d_3"] = "46200000FGH",
+ ["sub.d_3"] = "46200001FGH",
+ ["mul.d_3"] = "46200002FGH",
+ ["div.d_3"] = "46200003FGH",
+ ["sqrt.d_2"] = "46200004FG",
+ ["abs.d_2"] = "46200005FG",
+ ["mov.d_2"] = "46200006FG",
+ ["neg.d_2"] = "46200007FG",
+ ["round.l.d_2"] = "46200008FG",
+ ["trunc.l.d_2"] = "46200009FG",
+ ["ceil.l.d_2"] = "4620000aFG",
+ ["floor.l.d_2"] = "4620000bFG",
+ ["round.w.d_2"] = "4620000cFG",
+ ["trunc.w.d_2"] = "4620000dFG",
+ ["ceil.w.d_2"] = "4620000eFG",
+ ["floor.w.d_2"] = "4620000fFG",
+ ["movf.d_2"] = "46200011FG",
+ ["movf.d_3"] = "46200011FGC",
+ ["movt.d_2"] = "46210011FG",
+ ["movt.d_3"] = "46210011FGC",
+ ["movz.d_3"] = "46200012FGT",
+ ["movn.d_3"] = "46200013FGT",
+ ["recip.d_2"] = "46200015FG",
+ ["rsqrt.d_2"] = "46200016FG",
+ ["cvt.s.d_2"] = "46200020FG",
+ ["cvt.w.d_2"] = "46200024FG",
+ ["cvt.l.d_2"] = "46200025FG",
+ ["c.f.d_2"] = "46200030GH",
+ ["c.f.d_3"] = "46200030VGH",
+ ["c.un.d_2"] = "46200031GH",
+ ["c.un.d_3"] = "46200031VGH",
+ ["c.eq.d_2"] = "46200032GH",
+ ["c.eq.d_3"] = "46200032VGH",
+ ["c.ueq.d_2"] = "46200033GH",
+ ["c.ueq.d_3"] = "46200033VGH",
+ ["c.olt.d_2"] = "46200034GH",
+ ["c.olt.d_3"] = "46200034VGH",
+ ["c.ult.d_2"] = "46200035GH",
+ ["c.ult.d_3"] = "46200035VGH",
+ ["c.ole.d_2"] = "46200036GH",
+ ["c.ole.d_3"] = "46200036VGH",
+ ["c.ule.d_2"] = "46200037GH",
+ ["c.ule.d_3"] = "46200037VGH",
+ ["c.sf.d_2"] = "46200038GH",
+ ["c.sf.d_3"] = "46200038VGH",
+ ["c.ngle.d_2"] = "46200039GH",
+ ["c.ngle.d_3"] = "46200039VGH",
+ ["c.seq.d_2"] = "4620003aGH",
+ ["c.seq.d_3"] = "4620003aVGH",
+ ["c.ngl.d_2"] = "4620003bGH",
+ ["c.ngl.d_3"] = "4620003bVGH",
+ ["c.lt.d_2"] = "4620003cGH",
+ ["c.lt.d_3"] = "4620003cVGH",
+ ["c.nge.d_2"] = "4620003dGH",
+ ["c.nge.d_3"] = "4620003dVGH",
+ ["c.le.d_2"] = "4620003eGH",
+ ["c.le.d_3"] = "4620003eVGH",
+ ["c.ngt.d_2"] = "4620003fGH",
+ ["c.ngt.d_3"] = "4620003fVGH",
+
+ ["add.ps_3"] = "46c00000FGH",
+ ["sub.ps_3"] = "46c00001FGH",
+ ["mul.ps_3"] = "46c00002FGH",
+ ["abs.ps_2"] = "46c00005FG",
+ ["mov.ps_2"] = "46c00006FG",
+ ["neg.ps_2"] = "46c00007FG",
+ ["movf.ps_2"] = "46c00011FG",
+ ["movf.ps_3"] = "46c00011FGC",
+ ["movt.ps_2"] = "46c10011FG",
+ ["movt.ps_3"] = "46c10011FGC",
+ ["movz.ps_3"] = "46c00012FGT",
+ ["movn.ps_3"] = "46c00013FGT",
+ ["cvt.s.pu_2"] = "46c00020FG",
+ ["cvt.s.pl_2"] = "46c00028FG",
+ ["pll.ps_3"] = "46c0002cFGH",
+ ["plu.ps_3"] = "46c0002dFGH",
+ ["pul.ps_3"] = "46c0002eFGH",
+ ["puu.ps_3"] = "46c0002fFGH",
+ ["c.f.ps_2"] = "46c00030GH",
+ ["c.f.ps_3"] = "46c00030VGH",
+ ["c.un.ps_2"] = "46c00031GH",
+ ["c.un.ps_3"] = "46c00031VGH",
+ ["c.eq.ps_2"] = "46c00032GH",
+ ["c.eq.ps_3"] = "46c00032VGH",
+ ["c.ueq.ps_2"] = "46c00033GH",
+ ["c.ueq.ps_3"] = "46c00033VGH",
+ ["c.olt.ps_2"] = "46c00034GH",
+ ["c.olt.ps_3"] = "46c00034VGH",
+ ["c.ult.ps_2"] = "46c00035GH",
+ ["c.ult.ps_3"] = "46c00035VGH",
+ ["c.ole.ps_2"] = "46c00036GH",
+ ["c.ole.ps_3"] = "46c00036VGH",
+ ["c.ule.ps_2"] = "46c00037GH",
+ ["c.ule.ps_3"] = "46c00037VGH",
+ ["c.sf.ps_2"] = "46c00038GH",
+ ["c.sf.ps_3"] = "46c00038VGH",
+ ["c.ngle.ps_2"] = "46c00039GH",
+ ["c.ngle.ps_3"] = "46c00039VGH",
+ ["c.seq.ps_2"] = "46c0003aGH",
+ ["c.seq.ps_3"] = "46c0003aVGH",
+ ["c.ngl.ps_2"] = "46c0003bGH",
+ ["c.ngl.ps_3"] = "46c0003bVGH",
+ ["c.lt.ps_2"] = "46c0003cGH",
+ ["c.lt.ps_3"] = "46c0003cVGH",
+ ["c.nge.ps_2"] = "46c0003dGH",
+ ["c.nge.ps_3"] = "46c0003dVGH",
+ ["c.le.ps_2"] = "46c0003eGH",
+ ["c.le.ps_3"] = "46c0003eVGH",
+ ["c.ngt.ps_2"] = "46c0003fGH",
+ ["c.ngt.ps_3"] = "46c0003fVGH",
+
+ ["cvt.s.w_2"] = "46800020FG",
+ ["cvt.d.w_2"] = "46800021FG",
+
+ ["cvt.s.l_2"] = "46a00020FG",
+ ["cvt.d.l_2"] = "46a00021FG",
+
+ -- Opcode COP1X.
+ lwxc1_2 = "4c000000FX",
+ ldxc1_2 = "4c000001FX",
+ luxc1_2 = "4c000005FX",
+ swxc1_2 = "4c000008FX",
+ sdxc1_2 = "4c000009FX",
+ suxc1_2 = "4c00000dFX",
+ prefx_2 = "4c00000fMX",
+ ["alnv.ps_4"] = "4c00001eFGHS",
+ ["madd.s_4"] = "4c000020FRGH",
+ ["madd.d_4"] = "4c000021FRGH",
+ ["madd.ps_4"] = "4c000026FRGH",
+ ["msub.s_4"] = "4c000028FRGH",
+ ["msub.d_4"] = "4c000029FRGH",
+ ["msub.ps_4"] = "4c00002eFRGH",
+ ["nmadd.s_4"] = "4c000030FRGH",
+ ["nmadd.d_4"] = "4c000031FRGH",
+ ["nmadd.ps_4"] = "4c000036FRGH",
+ ["nmsub.s_4"] = "4c000038FRGH",
+ ["nmsub.d_4"] = "4c000039FRGH",
+ ["nmsub.ps_4"] = "4c00003eFRGH",
+}
+
+------------------------------------------------------------------------------
+
+local function parse_gpr(expr)
+ local tname, ovreg = match(expr, "^([%w_]+):(r[1-3]?[0-9])$")
+ local tp = map_type[tname or expr]
+ if tp then
+ local reg = ovreg or tp.reg
+ if not reg then
+ werror("type `"..(tname or expr).."' needs a register override")
+ end
+ expr = reg
+ end
+ local r = match(expr, "^r([1-3]?[0-9])$")
+ if r then
+ r = tonumber(r)
+ if r <= 31 then return r, tp end
+ end
+ werror("bad register name `"..expr.."'")
+end
+
+local function parse_fpr(expr)
+ local r = match(expr, "^f([1-3]?[0-9])$")
+ if r then
+ r = tonumber(r)
+ if r <= 31 then return r end
+ end
+ werror("bad register name `"..expr.."'")
+end
+
+local function parse_imm(imm, bits, shift, scale, signed)
+ local n = tonumber(imm)
+ if n then
+ local m = sar(n, scale)
+ if shl(m, scale) == n then
+ if signed then
+ local s = sar(m, bits-1)
+ if s == 0 then return shl(m, shift)
+ elseif s == -1 then return shl(m + shl(1, bits), shift) end
+ else
+ if sar(m, bits) == 0 then return shl(m, shift) end
+ end
+ end
+ werror("out of range immediate `"..imm.."'")
+ elseif match(imm, "^[rf]([1-3]?[0-9])$") or
+ match(imm, "^([%w_]+):([rf][1-3]?[0-9])$") then
+ werror("expected immediate operand, got register")
+ else
+ waction("IMM", (signed and 32768 or 0)+scale*1024+bits*32+shift, imm)
+ return 0
+ end
+end
+
+local function parse_disp(disp)
+ local imm, reg = match(disp, "^(.*)%(([%w_:]+)%)$")
+ if imm then
+ local r = shl(parse_gpr(reg), 21)
+ local extname = match(imm, "^extern%s+(%S+)$")
+ if extname then
+ waction("REL_EXT", map_extern[extname], nil, 1)
+ return r
+ else
+ return r + parse_imm(imm, 16, 0, 0, true)
+ end
+ end
+ local reg, tailr = match(disp, "^([%w_:]+)%s*(.*)$")
+ if reg and tailr ~= "" then
+ local r, tp = parse_gpr(reg)
+ if tp then
+ waction("IMM", 32768+16*32, format(tp.ctypefmt, tailr))
+ return shl(r, 21)
+ end
+ end
+ werror("bad displacement `"..disp.."'")
+end
+
+local function parse_index(idx)
+ local rt, rs = match(idx, "^(.*)%(([%w_:]+)%)$")
+ if rt then
+ rt = parse_gpr(rt)
+ rs = parse_gpr(rs)
+ return shl(rt, 16) + shl(rs, 21)
+ end
+ werror("bad index `"..idx.."'")
+end
+
+local function parse_label(label, def)
+ local prefix = sub(label, 1, 2)
+ -- =>label (pc label reference)
+ if prefix == "=>" then
+ return "PC", 0, sub(label, 3)
+ end
+ -- ->name (global label reference)
+ if prefix == "->" then
+ return "LG", map_global[sub(label, 3)]
+ end
+ if def then
+ -- [1-9] (local label definition)
+ if match(label, "^[1-9]$") then
+ return "LG", 10+tonumber(label)
+ end
+ else
+ -- [<>][1-9] (local label reference)
+ local dir, lnum = match(label, "^([<>])([1-9])$")
+ if dir then -- Fwd: 1-9, Bkwd: 11-19.
+ return "LG", lnum + (dir == ">" and 0 or 10)
+ end
+ -- extern label (extern label reference)
+ local extname = match(label, "^extern%s+(%S+)$")
+ if extname then
+ return "EXT", map_extern[extname]
+ end
+ end
+ werror("bad label `"..label.."'")
+end
+
+------------------------------------------------------------------------------
+
+-- Handle opcodes defined with template strings.
+map_op[".template__"] = function(params, template, nparams)
+ if not params then return sub(template, 9) end
+ local op = tonumber(sub(template, 1, 8), 16)
+ local n = 1
+
+ -- Limit number of section buffer positions used by a single dasm_put().
+ -- A single opcode needs a maximum of 2 positions (ins/ext).
+ if secpos+2 > maxsecpos then wflush() end
+ local pos = wpos()
+
+ -- Process each character.
+ for p in gmatch(sub(template, 9), ".") do
+ if p == "D" then
+ op = op + shl(parse_gpr(params[n]), 11); n = n + 1
+ elseif p == "T" then
+ op = op + shl(parse_gpr(params[n]), 16); n = n + 1
+ elseif p == "S" then
+ op = op + shl(parse_gpr(params[n]), 21); n = n + 1
+ elseif p == "F" then
+ op = op + shl(parse_fpr(params[n]), 6); n = n + 1
+ elseif p == "G" then
+ op = op + shl(parse_fpr(params[n]), 11); n = n + 1
+ elseif p == "H" then
+ op = op + shl(parse_fpr(params[n]), 16); n = n + 1
+ elseif p == "R" then
+ op = op + shl(parse_fpr(params[n]), 21); n = n + 1
+ elseif p == "I" then
+ op = op + parse_imm(params[n], 16, 0, 0, true); n = n + 1
+ elseif p == "U" then
+ op = op + parse_imm(params[n], 16, 0, 0, false); n = n + 1
+ elseif p == "O" then
+ op = op + parse_disp(params[n]); n = n + 1
+ elseif p == "X" then
+ op = op + parse_index(params[n]); n = n + 1
+ elseif p == "B" or p == "J" then
+ local mode, n, s = parse_label(params[n], false)
+ if p == "B" then n = n + 2048 end
+ waction("REL_"..mode, n, s, 1)
+ n = n + 1
+ elseif p == "A" then
+ op = op + parse_imm(params[n], 5, 6, 0, false); n = n + 1
+ elseif p == "M" then
+ op = op + parse_imm(params[n], 5, 11, 0, false); n = n + 1
+ elseif p == "N" then
+ op = op + parse_imm(params[n], 5, 16, 0, false); n = n + 1
+ elseif p == "C" then
+ op = op + parse_imm(params[n], 3, 18, 0, false); n = n + 1
+ elseif p == "V" then
+ op = op + parse_imm(params[n], 3, 8, 0, false); n = n + 1
+ elseif p == "W" then
+ op = op + parse_imm(params[n], 3, 0, 0, false); n = n + 1
+ elseif p == "Y" then
+ op = op + parse_imm(params[n], 20, 6, 0, false); n = n + 1
+ elseif p == "Z" then
+ op = op + parse_imm(params[n], 10, 6, 0, false); n = n + 1
+ elseif p == "=" then
+ op = op + shl(band(op, 0xf800), 5) -- Copy D to T for clz, clo.
+ else
+ assert(false)
+ end
+ end
+ wputpos(pos, op)
+end
+
+------------------------------------------------------------------------------
+
+-- Pseudo-opcode to mark the position where the action list is to be emitted.
+map_op[".actionlist_1"] = function(params)
+ if not params then return "cvar" end
+ local name = params[1] -- No syntax check. You get to keep the pieces.
+ wline(function(out) writeactions(out, name) end)
+end
+
+-- Pseudo-opcode to mark the position where the global enum is to be emitted.
+map_op[".globals_1"] = function(params)
+ if not params then return "prefix" end
+ local prefix = params[1] -- No syntax check. You get to keep the pieces.
+ wline(function(out) writeglobals(out, prefix) end)
+end
+
+-- Pseudo-opcode to mark the position where the global names are to be emitted.
+map_op[".globalnames_1"] = function(params)
+ if not params then return "cvar" end
+ local name = params[1] -- No syntax check. You get to keep the pieces.
+ wline(function(out) writeglobalnames(out, name) end)
+end
+
+-- Pseudo-opcode to mark the position where the extern names are to be emitted.
+map_op[".externnames_1"] = function(params)
+ if not params then return "cvar" end
+ local name = params[1] -- No syntax check. You get to keep the pieces.
+ wline(function(out) writeexternnames(out, name) end)
+end
+
+------------------------------------------------------------------------------
+
+-- Label pseudo-opcode (converted from trailing colon form).
+map_op[".label_1"] = function(params)
+ if not params then return "[1-9] | ->global | =>pcexpr" end
+ if secpos+1 > maxsecpos then wflush() end
+ local mode, n, s = parse_label(params[1], true)
+ if mode == "EXT" then werror("bad label definition") end
+ waction("LABEL_"..mode, n, s, 1)
+end
+
+------------------------------------------------------------------------------
+
+-- Pseudo-opcodes for data storage.
+map_op[".long_*"] = function(params)
+ if not params then return "imm..." end
+ for _,p in ipairs(params) do
+ local n = tonumber(p)
+ if not n then werror("bad immediate `"..p.."'") end
+ if n < 0 then n = n + 2^32 end
+ wputw(n)
+ if secpos+2 > maxsecpos then wflush() end
+ end
+end
+
+-- Alignment pseudo-opcode.
+map_op[".align_1"] = function(params)
+ if not params then return "numpow2" end
+ if secpos+1 > maxsecpos then wflush() end
+ local align = tonumber(params[1])
+ if align then
+ local x = align
+ -- Must be a power of 2 in the range (2 ... 256).
+ for i=1,8 do
+ x = x / 2
+ if x == 1 then
+ waction("ALIGN", align-1, nil, 1) -- Action byte is 2**n-1.
+ return
+ end
+ end
+ end
+ werror("bad alignment")
+end
+
+------------------------------------------------------------------------------
+
+-- Pseudo-opcode for (primitive) type definitions (map to C types).
+map_op[".type_3"] = function(params, nparams)
+ if not params then
+ return nparams == 2 and "name, ctype" or "name, ctype, reg"
+ end
+ local name, ctype, reg = params[1], params[2], params[3]
+ if not match(name, "^[%a_][%w_]*$") then
+ werror("bad type name `"..name.."'")
+ end
+ local tp = map_type[name]
+ if tp then
+ werror("duplicate type `"..name.."'")
+ end
+ -- Add #type to defines. A bit unclean to put it in map_archdef.
+ map_archdef["#"..name] = "sizeof("..ctype..")"
+ -- Add new type and emit shortcut define.
+ local num = ctypenum + 1
+ map_type[name] = {
+ ctype = ctype,
+ ctypefmt = format("Dt%X(%%s)", num),
+ reg = reg,
+ }
+ wline(format("#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)", num, ctype))
+ ctypenum = num
+end
+map_op[".type_2"] = map_op[".type_3"]
+
+-- Dump type definitions.
+local function dumptypes(out, lvl)
+ local t = {}
+ for name in pairs(map_type) do t[#t+1] = name end
+ sort(t)
+ out:write("Type definitions:\n")
+ for _,name in ipairs(t) do
+ local tp = map_type[name]
+ local reg = tp.reg or ""
+ out:write(format(" %-20s %-20s %s\n", name, tp.ctype, reg))
+ end
+ out:write("\n")
+end
+
+------------------------------------------------------------------------------
+
+-- Set the current section.
+function _M.section(num)
+ waction("SECTION", num)
+ wflush(true) -- SECTION is a terminal action.
+end
+
+------------------------------------------------------------------------------
+
+-- Dump architecture description.
+function _M.dumparch(out)
+ out:write(format("DynASM %s version %s, released %s\n\n",
+ _info.arch, _info.version, _info.release))
+ dumpactions(out)
+end
+
+-- Dump all user defined elements.
+function _M.dumpdef(out, lvl)
+ dumptypes(out, lvl)
+ dumpglobals(out, lvl)
+ dumpexterns(out, lvl)
+end
+
+------------------------------------------------------------------------------
+
+-- Pass callbacks from/to the DynASM core.
+function _M.passcb(wl, we, wf, ww)
+ wline, werror, wfatal, wwarn = wl, we, wf, ww
+ return wflush
+end
+
+-- Setup the arch-specific module.
+function _M.setup(arch, opt)
+ g_arch, g_opt = arch, opt
+end
+
+-- Merge the core maps and the arch-specific maps.
+function _M.mergemaps(map_coreop, map_def)
+ setmetatable(map_op, { __index = map_coreop })
+ setmetatable(map_def, { __index = map_archdef })
+ return map_op, map_def
+end
+
+return _M
+
+------------------------------------------------------------------------------
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_ppc.h b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_ppc.h
new file mode 100644
index 0000000..81b9a76
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_ppc.h
@@ -0,0 +1,413 @@
+/*
+** DynASM PPC encoding engine.
+** Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+** Released under the MIT license. See dynasm.lua for full copyright notice.
+*/
+
+#include <stddef.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+
+#define DASM_ARCH "ppc"
+
+#ifndef DASM_EXTERN
+#define DASM_EXTERN(a,b,c,d) 0
+#endif
+
+/* Action definitions. */
+enum {
+ DASM_STOP, DASM_SECTION, DASM_ESC, DASM_REL_EXT,
+ /* The following actions need a buffer position. */
+ DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG,
+ /* The following actions also have an argument. */
+ DASM_REL_PC, DASM_LABEL_PC, DASM_IMM,
+ DASM__MAX
+};
+
+/* Maximum number of section buffer positions for a single dasm_put() call. */
+#define DASM_MAXSECPOS 25
+
+/* DynASM encoder status codes. Action list offset or number are or'ed in. */
+#define DASM_S_OK 0x00000000
+#define DASM_S_NOMEM 0x01000000
+#define DASM_S_PHASE 0x02000000
+#define DASM_S_MATCH_SEC 0x03000000
+#define DASM_S_RANGE_I 0x11000000
+#define DASM_S_RANGE_SEC 0x12000000
+#define DASM_S_RANGE_LG 0x13000000
+#define DASM_S_RANGE_PC 0x14000000
+#define DASM_S_RANGE_REL 0x15000000
+#define DASM_S_UNDEF_LG 0x21000000
+#define DASM_S_UNDEF_PC 0x22000000
+
+/* Macros to convert positions (8 bit section + 24 bit index). */
+#define DASM_POS2IDX(pos) ((pos)&0x00ffffff)
+#define DASM_POS2BIAS(pos) ((pos)&0xff000000)
+#define DASM_SEC2POS(sec) ((sec)<<24)
+#define DASM_POS2SEC(pos) ((pos)>>24)
+#define DASM_POS2PTR(D, pos) (D->sections[DASM_POS2SEC(pos)].rbuf + (pos))
+
+/* Action list type. */
+typedef const unsigned int *dasm_ActList;
+
+/* Per-section structure. */
+typedef struct dasm_Section {
+ int *rbuf; /* Biased buffer pointer (negative section bias). */
+ int *buf; /* True buffer pointer. */
+ size_t bsize; /* Buffer size in bytes. */
+ int pos; /* Biased buffer position. */
+ int epos; /* End of biased buffer position - max single put. */
+ int ofs; /* Byte offset into section. */
+} dasm_Section;
+
+/* Core structure holding the DynASM encoding state. */
+struct dasm_State {
+ size_t psize; /* Allocated size of this structure. */
+ dasm_ActList actionlist; /* Current actionlist pointer. */
+ int *lglabels; /* Local/global chain/pos ptrs. */
+ size_t lgsize;
+ int *pclabels; /* PC label chains/pos ptrs. */
+ size_t pcsize;
+ void **globals; /* Array of globals (bias -10). */
+ dasm_Section *section; /* Pointer to active section. */
+ size_t codesize; /* Total size of all code sections. */
+ int maxsection; /* 0 <= sectionidx < maxsection. */
+ int status; /* Status code. */
+ dasm_Section sections[1]; /* All sections. Alloc-extended. */
+};
+
+/* The size of the core structure depends on the max. number of sections. */
+#define DASM_PSZ(ms) (sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section))
+
+
+/* Initialize DynASM state. */
+void dasm_init(Dst_DECL, int maxsection)
+{
+ dasm_State *D;
+ size_t psz = 0;
+ int i;
+ Dst_REF = NULL;
+ DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));
+ D = Dst_REF;
+ D->psize = psz;
+ D->lglabels = NULL;
+ D->lgsize = 0;
+ D->pclabels = NULL;
+ D->pcsize = 0;
+ D->globals = NULL;
+ D->maxsection = maxsection;
+ for (i = 0; i < maxsection; i++) {
+ D->sections[i].buf = NULL; /* Need this for pass3. */
+ D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);
+ D->sections[i].bsize = 0;
+ D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */
+ }
+}
+
+/* Free DynASM state. */
+void dasm_free(Dst_DECL)
+{
+ dasm_State *D = Dst_REF;
+ int i;
+ for (i = 0; i < D->maxsection; i++)
+ if (D->sections[i].buf)
+ DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize);
+ if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize);
+ if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize);
+ DASM_M_FREE(Dst, D, D->psize);
+}
+
+/* Setup global label array. Must be called before dasm_setup(). */
+void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)
+{
+ dasm_State *D = Dst_REF;
+ D->globals = gl - 10; /* Negative bias to compensate for locals. */
+ DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));
+}
+
+/* Grow PC label array. Can be called after dasm_setup(), too. */
+void dasm_growpc(Dst_DECL, unsigned int maxpc)
+{
+ dasm_State *D = Dst_REF;
+ size_t osz = D->pcsize;
+ DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int));
+ memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz);
+}
+
+/* Setup encoder. */
+void dasm_setup(Dst_DECL, const void *actionlist)
+{
+ dasm_State *D = Dst_REF;
+ int i;
+ D->actionlist = (dasm_ActList)actionlist;
+ D->status = DASM_S_OK;
+ D->section = &D->sections[0];
+ memset((void *)D->lglabels, 0, D->lgsize);
+ if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize);
+ for (i = 0; i < D->maxsection; i++) {
+ D->sections[i].pos = DASM_SEC2POS(i);
+ D->sections[i].ofs = 0;
+ }
+}
+
+
+#ifdef DASM_CHECKS
+#define CK(x, st) \
+ do { if (!(x)) { \
+ D->status = DASM_S_##st|(p-D->actionlist-1); return; } } while (0)
+#define CKPL(kind, st) \
+ do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \
+ D->status = DASM_S_RANGE_##st|(p-D->actionlist-1); return; } } while (0)
+#else
+#define CK(x, st) ((void)0)
+#define CKPL(kind, st) ((void)0)
+#endif
+
+/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */
+void dasm_put(Dst_DECL, int start, ...)
+{
+ va_list ap;
+ dasm_State *D = Dst_REF;
+ dasm_ActList p = D->actionlist + start;
+ dasm_Section *sec = D->section;
+ int pos = sec->pos, ofs = sec->ofs;
+ int *b;
+
+ if (pos >= sec->epos) {
+ DASM_M_GROW(Dst, int, sec->buf, sec->bsize,
+ sec->bsize + 2*DASM_MAXSECPOS*sizeof(int));
+ sec->rbuf = sec->buf - DASM_POS2BIAS(pos);
+ sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos);
+ }
+
+ b = sec->rbuf;
+ b[pos++] = start;
+
+ va_start(ap, start);
+ while (1) {
+ unsigned int ins = *p++;
+ unsigned int action = (ins >> 16);
+ if (action >= DASM__MAX) {
+ ofs += 4;
+ } else {
+ int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0;
+ switch (action) {
+ case DASM_STOP: goto stop;
+ case DASM_SECTION:
+ n = (ins & 255); CK(n < D->maxsection, RANGE_SEC);
+ D->section = &D->sections[n]; goto stop;
+ case DASM_ESC: p++; ofs += 4; break;
+ case DASM_REL_EXT: break;
+ case DASM_ALIGN: ofs += (ins & 255); b[pos++] = ofs; break;
+ case DASM_REL_LG:
+ n = (ins & 2047) - 10; pl = D->lglabels + n;
+ /* Bkwd rel or global. */
+ if (n >= 0) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; }
+ pl += 10; n = *pl;
+ if (n < 0) n = 0; /* Start new chain for fwd rel if label exists. */
+ goto linkrel;
+ case DASM_REL_PC:
+ pl = D->pclabels + n; CKPL(pc, PC);
+ putrel:
+ n = *pl;
+ if (n < 0) { /* Label exists. Get label pos and store it. */
+ b[pos] = -n;
+ } else {
+ linkrel:
+ b[pos] = n; /* Else link to rel chain, anchored at label. */
+ *pl = pos;
+ }
+ pos++;
+ break;
+ case DASM_LABEL_LG:
+ pl = D->lglabels + (ins & 2047) - 10; CKPL(lg, LG); goto putlabel;
+ case DASM_LABEL_PC:
+ pl = D->pclabels + n; CKPL(pc, PC);
+ putlabel:
+ n = *pl; /* n > 0: Collapse rel chain and replace with label pos. */
+ while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos;
+ }
+ *pl = -pos; /* Label exists now. */
+ b[pos++] = ofs; /* Store pass1 offset estimate. */
+ break;
+ case DASM_IMM:
+#ifdef DASM_CHECKS
+ CK((n & ((1<<((ins>>10)&31))-1)) == 0, RANGE_I);
+#endif
+ n >>= ((ins>>10)&31);
+#ifdef DASM_CHECKS
+ if (ins & 0x8000)
+ CK(((n + (1<<(((ins>>5)&31)-1)))>>((ins>>5)&31)) == 0, RANGE_I);
+ else
+ CK((n>>((ins>>5)&31)) == 0, RANGE_I);
+#endif
+ b[pos++] = n;
+ break;
+ }
+ }
+ }
+stop:
+ va_end(ap);
+ sec->pos = pos;
+ sec->ofs = ofs;
+}
+#undef CK
+
+/* Pass 2: Link sections, shrink aligns, fix label offsets. */
+int dasm_link(Dst_DECL, size_t *szp)
+{
+ dasm_State *D = Dst_REF;
+ int secnum;
+ int ofs = 0;
+
+#ifdef DASM_CHECKS
+ *szp = 0;
+ if (D->status != DASM_S_OK) return D->status;
+ {
+ int pc;
+ for (pc = 0; pc*sizeof(int) < D->pcsize; pc++)
+ if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc;
+ }
+#endif
+
+ { /* Handle globals not defined in this translation unit. */
+ int idx;
+ for (idx = 20; idx*sizeof(int) < D->lgsize; idx++) {
+ int n = D->lglabels[idx];
+ /* Undefined label: Collapse rel chain and replace with marker (< 0). */
+ while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }
+ }
+ }
+
+ /* Combine all code sections. No support for data sections (yet). */
+ for (secnum = 0; secnum < D->maxsection; secnum++) {
+ dasm_Section *sec = D->sections + secnum;
+ int *b = sec->rbuf;
+ int pos = DASM_SEC2POS(secnum);
+ int lastpos = sec->pos;
+
+ while (pos != lastpos) {
+ dasm_ActList p = D->actionlist + b[pos++];
+ while (1) {
+ unsigned int ins = *p++;
+ unsigned int action = (ins >> 16);
+ switch (action) {
+ case DASM_STOP: case DASM_SECTION: goto stop;
+ case DASM_ESC: p++; break;
+ case DASM_REL_EXT: break;
+ case DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break;
+ case DASM_REL_LG: case DASM_REL_PC: pos++; break;
+ case DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break;
+ case DASM_IMM: pos++; break;
+ }
+ }
+ stop: (void)0;
+ }
+ ofs += sec->ofs; /* Next section starts right after current section. */
+ }
+
+ D->codesize = ofs; /* Total size of all code sections */
+ *szp = ofs;
+ return DASM_S_OK;
+}
+
+#ifdef DASM_CHECKS
+#define CK(x, st) \
+ do { if (!(x)) return DASM_S_##st|(p-D->actionlist-1); } while (0)
+#else
+#define CK(x, st) ((void)0)
+#endif
+
+/* Pass 3: Encode sections. */
+int dasm_encode(Dst_DECL, void *buffer)
+{
+ dasm_State *D = Dst_REF;
+ char *base = (char *)buffer;
+ unsigned int *cp = (unsigned int *)buffer;
+ int secnum;
+
+ /* Encode all code sections. No support for data sections (yet). */
+ for (secnum = 0; secnum < D->maxsection; secnum++) {
+ dasm_Section *sec = D->sections + secnum;
+ int *b = sec->buf;
+ int *endb = sec->rbuf + sec->pos;
+
+ while (b != endb) {
+ dasm_ActList p = D->actionlist + *b++;
+ while (1) {
+ unsigned int ins = *p++;
+ unsigned int action = (ins >> 16);
+ int n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0;
+ switch (action) {
+ case DASM_STOP: case DASM_SECTION: goto stop;
+ case DASM_ESC: *cp++ = *p++; break;
+ case DASM_REL_EXT:
+ n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins & 2047), 1) - 4;
+ goto patchrel;
+ case DASM_ALIGN:
+ ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0x60000000;
+ break;
+ case DASM_REL_LG:
+ CK(n >= 0, UNDEF_LG);
+ /* fallthrough */
+ case DASM_REL_PC:
+ CK(n >= 0, UNDEF_PC);
+ n = *DASM_POS2PTR(D, n) - (int)((char *)cp - base);
+ patchrel:
+ CK((n & 3) == 0 &&
+ (((n+4) + ((ins & 2048) ? 0x00008000 : 0x02000000)) >>
+ ((ins & 2048) ? 16 : 26)) == 0, RANGE_REL);
+ cp[-1] |= ((n+4) & ((ins & 2048) ? 0x0000fffc: 0x03fffffc));
+ break;
+ case DASM_LABEL_LG:
+ ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n);
+ break;
+ case DASM_LABEL_PC: break;
+ case DASM_IMM:
+ cp[-1] |= (n & ((1<<((ins>>5)&31))-1)) << (ins&31);
+ break;
+ default: *cp++ = ins; break;
+ }
+ }
+ stop: (void)0;
+ }
+ }
+
+ if (base + D->codesize != (char *)cp) /* Check for phase errors. */
+ return DASM_S_PHASE;
+ return DASM_S_OK;
+}
+#undef CK
+
+/* Get PC label offset. */
+int dasm_getpclabel(Dst_DECL, unsigned int pc)
+{
+ dasm_State *D = Dst_REF;
+ if (pc*sizeof(int) < D->pcsize) {
+ int pos = D->pclabels[pc];
+ if (pos < 0) return *DASM_POS2PTR(D, -pos);
+ if (pos > 0) return -1; /* Undefined. */
+ }
+ return -2; /* Unused or out of range. */
+}
+
+#ifdef DASM_CHECKS
+/* Optional sanity checker to call between isolated encoding steps. */
+int dasm_checkstep(Dst_DECL, int secmatch)
+{
+ dasm_State *D = Dst_REF;
+ if (D->status == DASM_S_OK) {
+ int i;
+ for (i = 1; i <= 9; i++) {
+ if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_LG|i; break; }
+ D->lglabels[i] = 0;
+ }
+ }
+ if (D->status == DASM_S_OK && secmatch >= 0 &&
+ D->section != &D->sections[secmatch])
+ D->status = DASM_S_MATCH_SEC|(D->section-D->sections);
+ return D->status;
+}
+#endif
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_ppc.lua b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_ppc.lua
new file mode 100644
index 0000000..4e1656e
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_ppc.lua
@@ -0,0 +1,1249 @@
+------------------------------------------------------------------------------
+-- DynASM PPC module.
+--
+-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+-- See dynasm.lua for full copyright notice.
+------------------------------------------------------------------------------
+
+-- Module information:
+local _info = {
+ arch = "ppc",
+ description = "DynASM PPC module",
+ version = "1.3.0",
+ vernum = 10300,
+ release = "2011-05-05",
+ author = "Mike Pall",
+ license = "MIT",
+}
+
+-- Exported glue functions for the arch-specific module.
+local _M = { _info = _info }
+
+-- Cache library functions.
+local type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs
+local assert, setmetatable = assert, setmetatable
+local _s = string
+local sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char
+local match, gmatch = _s.match, _s.gmatch
+local concat, sort = table.concat, table.sort
+local bit = bit or require("bit")
+local band, shl, shr, sar = bit.band, bit.lshift, bit.rshift, bit.arshift
+local tohex = bit.tohex
+
+-- Inherited tables and callbacks.
+local g_opt, g_arch
+local wline, werror, wfatal, wwarn
+
+-- Action name list.
+-- CHECK: Keep this in sync with the C code!
+local action_names = {
+ "STOP", "SECTION", "ESC", "REL_EXT",
+ "ALIGN", "REL_LG", "LABEL_LG",
+ "REL_PC", "LABEL_PC", "IMM",
+}
+
+-- Maximum number of section buffer positions for dasm_put().
+-- CHECK: Keep this in sync with the C code!
+local maxsecpos = 25 -- Keep this low, to avoid excessively long C lines.
+
+-- Action name -> action number.
+local map_action = {}
+for n,name in ipairs(action_names) do
+ map_action[name] = n-1
+end
+
+-- Action list buffer.
+local actlist = {}
+
+-- Argument list for next dasm_put(). Start with offset 0 into action list.
+local actargs = { 0 }
+
+-- Current number of section buffer positions for dasm_put().
+local secpos = 1
+
+------------------------------------------------------------------------------
+
+-- Dump action names and numbers.
+local function dumpactions(out)
+ out:write("DynASM encoding engine action codes:\n")
+ for n,name in ipairs(action_names) do
+ local num = map_action[name]
+ out:write(format(" %-10s %02X %d\n", name, num, num))
+ end
+ out:write("\n")
+end
+
+-- Write action list buffer as a huge static C array.
+local function writeactions(out, name)
+ local nn = #actlist
+ if nn == 0 then nn = 1; actlist[0] = map_action.STOP end
+ out:write("static const unsigned int ", name, "[", nn, "] = {\n")
+ for i = 1,nn-1 do
+ assert(out:write("0x", tohex(actlist[i]), ",\n"))
+ end
+ assert(out:write("0x", tohex(actlist[nn]), "\n};\n\n"))
+end
+
+------------------------------------------------------------------------------
+
+-- Add word to action list.
+local function wputxw(n)
+ assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, "word out of range")
+ actlist[#actlist+1] = n
+end
+
+-- Add action to list with optional arg. Advance buffer pos, too.
+local function waction(action, val, a, num)
+ local w = assert(map_action[action], "bad action name `"..action.."'")
+ wputxw(w * 0x10000 + (val or 0))
+ if a then actargs[#actargs+1] = a end
+ if a or num then secpos = secpos + (num or 1) end
+end
+
+-- Flush action list (intervening C code or buffer pos overflow).
+local function wflush(term)
+ if #actlist == actargs[1] then return end -- Nothing to flush.
+ if not term then waction("STOP") end -- Terminate action list.
+ wline(format("dasm_put(Dst, %s);", concat(actargs, ", ")), true)
+ actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put().
+ secpos = 1 -- The actionlist offset occupies a buffer position, too.
+end
+
+-- Put escaped word.
+local function wputw(n)
+ if n <= 0xffffff then waction("ESC") end
+ wputxw(n)
+end
+
+-- Reserve position for word.
+local function wpos()
+ local pos = #actlist+1
+ actlist[pos] = ""
+ return pos
+end
+
+-- Store word to reserved position.
+local function wputpos(pos, n)
+ assert(n >= 0 and n <= 0xffffffff and n % 1 == 0, "word out of range")
+ actlist[pos] = n
+end
+
+------------------------------------------------------------------------------
+
+-- Global label name -> global label number. With auto assignment on 1st use.
+local next_global = 20
+local map_global = setmetatable({}, { __index = function(t, name)
+ if not match(name, "^[%a_][%w_]*$") then werror("bad global label") end
+ local n = next_global
+ if n > 2047 then werror("too many global labels") end
+ next_global = n + 1
+ t[name] = n
+ return n
+end})
+
+-- Dump global labels.
+local function dumpglobals(out, lvl)
+ local t = {}
+ for name, n in pairs(map_global) do t[n] = name end
+ out:write("Global labels:\n")
+ for i=20,next_global-1 do
+ out:write(format(" %s\n", t[i]))
+ end
+ out:write("\n")
+end
+
+-- Write global label enum.
+local function writeglobals(out, prefix)
+ local t = {}
+ for name, n in pairs(map_global) do t[n] = name end
+ out:write("enum {\n")
+ for i=20,next_global-1 do
+ out:write(" ", prefix, t[i], ",\n")
+ end
+ out:write(" ", prefix, "_MAX\n};\n")
+end
+
+-- Write global label names.
+local function writeglobalnames(out, name)
+ local t = {}
+ for name, n in pairs(map_global) do t[n] = name end
+ out:write("static const char *const ", name, "[] = {\n")
+ for i=20,next_global-1 do
+ out:write(" \"", t[i], "\",\n")
+ end
+ out:write(" (const char *)0\n};\n")
+end
+
+------------------------------------------------------------------------------
+
+-- Extern label name -> extern label number. With auto assignment on 1st use.
+local next_extern = 0
+local map_extern_ = {}
+local map_extern = setmetatable({}, { __index = function(t, name)
+ -- No restrictions on the name for now.
+ local n = next_extern
+ if n > 2047 then werror("too many extern labels") end
+ next_extern = n + 1
+ t[name] = n
+ map_extern_[n] = name
+ return n
+end})
+
+-- Dump extern labels.
+local function dumpexterns(out, lvl)
+ out:write("Extern labels:\n")
+ for i=0,next_extern-1 do
+ out:write(format(" %s\n", map_extern_[i]))
+ end
+ out:write("\n")
+end
+
+-- Write extern label names.
+local function writeexternnames(out, name)
+ out:write("static const char *const ", name, "[] = {\n")
+ for i=0,next_extern-1 do
+ out:write(" \"", map_extern_[i], "\",\n")
+ end
+ out:write(" (const char *)0\n};\n")
+end
+
+------------------------------------------------------------------------------
+
+-- Arch-specific maps.
+local map_archdef = { sp = "r1" } -- Ext. register name -> int. name.
+
+local map_type = {} -- Type name -> { ctype, reg }
+local ctypenum = 0 -- Type number (for Dt... macros).
+
+-- Reverse defines for registers.
+function _M.revdef(s)
+ if s == "r1" then return "sp" end
+ return s
+end
+
+local map_cond = {
+ lt = 0, gt = 1, eq = 2, so = 3,
+ ge = 4, le = 5, ne = 6, ns = 7,
+}
+
+------------------------------------------------------------------------------
+
+-- Template strings for PPC instructions.
+local map_op = {
+ tdi_3 = "08000000ARI",
+ twi_3 = "0c000000ARI",
+ mulli_3 = "1c000000RRI",
+ subfic_3 = "20000000RRI",
+ cmplwi_3 = "28000000XRU",
+ cmplwi_2 = "28000000-RU",
+ cmpldi_3 = "28200000XRU",
+ cmpldi_2 = "28200000-RU",
+ cmpwi_3 = "2c000000XRI",
+ cmpwi_2 = "2c000000-RI",
+ cmpdi_3 = "2c200000XRI",
+ cmpdi_2 = "2c200000-RI",
+ addic_3 = "30000000RRI",
+ ["addic._3"] = "34000000RRI",
+ addi_3 = "38000000RR0I",
+ li_2 = "38000000RI",
+ la_2 = "38000000RD",
+ addis_3 = "3c000000RR0I",
+ lis_2 = "3c000000RI",
+ lus_2 = "3c000000RU",
+ bc_3 = "40000000AAK",
+ bcl_3 = "40000001AAK",
+ bdnz_1 = "42000000K",
+ bdz_1 = "42400000K",
+ sc_0 = "44000000",
+ b_1 = "48000000J",
+ bl_1 = "48000001J",
+ rlwimi_5 = "50000000RR~AAA.",
+ rlwinm_5 = "54000000RR~AAA.",
+ rlwnm_5 = "5c000000RR~RAA.",
+ ori_3 = "60000000RR~U",
+ nop_0 = "60000000",
+ oris_3 = "64000000RR~U",
+ xori_3 = "68000000RR~U",
+ xoris_3 = "6c000000RR~U",
+ ["andi._3"] = "70000000RR~U",
+ ["andis._3"] = "74000000RR~U",
+ lwz_2 = "80000000RD",
+ lwzu_2 = "84000000RD",
+ lbz_2 = "88000000RD",
+ lbzu_2 = "8c000000RD",
+ stw_2 = "90000000RD",
+ stwu_2 = "94000000RD",
+ stb_2 = "98000000RD",
+ stbu_2 = "9c000000RD",
+ lhz_2 = "a0000000RD",
+ lhzu_2 = "a4000000RD",
+ lha_2 = "a8000000RD",
+ lhau_2 = "ac000000RD",
+ sth_2 = "b0000000RD",
+ sthu_2 = "b4000000RD",
+ lmw_2 = "b8000000RD",
+ stmw_2 = "bc000000RD",
+ lfs_2 = "c0000000FD",
+ lfsu_2 = "c4000000FD",
+ lfd_2 = "c8000000FD",
+ lfdu_2 = "cc000000FD",
+ stfs_2 = "d0000000FD",
+ stfsu_2 = "d4000000FD",
+ stfd_2 = "d8000000FD",
+ stfdu_2 = "dc000000FD",
+ ld_2 = "e8000000RD", -- NYI: displacement must be divisible by 4.
+ ldu_2 = "e8000001RD",
+ lwa_2 = "e8000002RD",
+ std_2 = "f8000000RD",
+ stdu_2 = "f8000001RD",
+
+ -- Primary opcode 19:
+ mcrf_2 = "4c000000XX",
+ isync_0 = "4c00012c",
+ crnor_3 = "4c000042CCC",
+ crnot_2 = "4c000042CC=",
+ crandc_3 = "4c000102CCC",
+ crxor_3 = "4c000182CCC",
+ crclr_1 = "4c000182C==",
+ crnand_3 = "4c0001c2CCC",
+ crand_3 = "4c000202CCC",
+ creqv_3 = "4c000242CCC",
+ crset_1 = "4c000242C==",
+ crorc_3 = "4c000342CCC",
+ cror_3 = "4c000382CCC",
+ crmove_2 = "4c000382CC=",
+ bclr_2 = "4c000020AA",
+ bclrl_2 = "4c000021AA",
+ bcctr_2 = "4c000420AA",
+ bcctrl_2 = "4c000421AA",
+ blr_0 = "4e800020",
+ blrl_0 = "4e800021",
+ bctr_0 = "4e800420",
+ bctrl_0 = "4e800421",
+
+ -- Primary opcode 31:
+ cmpw_3 = "7c000000XRR",
+ cmpw_2 = "7c000000-RR",
+ cmpd_3 = "7c200000XRR",
+ cmpd_2 = "7c200000-RR",
+ tw_3 = "7c000008ARR",
+ subfc_3 = "7c000010RRR.",
+ subc_3 = "7c000010RRR~.",
+ mulhdu_3 = "7c000012RRR.",
+ addc_3 = "7c000014RRR.",
+ mulhwu_3 = "7c000016RRR.",
+ isel_4 = "7c00001eRRRC",
+ isellt_3 = "7c00001eRRR",
+ iselgt_3 = "7c00005eRRR",
+ iseleq_3 = "7c00009eRRR",
+ mfcr_1 = "7c000026R",
+ mfocrf_2 = "7c100026RG",
+ mtcrf_2 = "7c000120GR",
+ mtocrf_2 = "7c100120GR",
+ lwarx_3 = "7c000028RR0R",
+ ldx_3 = "7c00002aRR0R",
+ lwzx_3 = "7c00002eRR0R",
+ slw_3 = "7c000030RR~R.",
+ cntlzw_2 = "7c000034RR~",
+ sld_3 = "7c000036RR~R.",
+ and_3 = "7c000038RR~R.",
+ cmplw_3 = "7c000040XRR",
+ cmplw_2 = "7c000040-RR",
+ cmpld_3 = "7c200040XRR",
+ cmpld_2 = "7c200040-RR",
+ subf_3 = "7c000050RRR.",
+ sub_3 = "7c000050RRR~.",
+ ldux_3 = "7c00006aRR0R",
+ dcbst_2 = "7c00006c-RR",
+ lwzux_3 = "7c00006eRR0R",
+ cntlzd_2 = "7c000074RR~",
+ andc_3 = "7c000078RR~R.",
+ td_3 = "7c000088ARR",
+ mulhd_3 = "7c000092RRR.",
+ mulhw_3 = "7c000096RRR.",
+ ldarx_3 = "7c0000a8RR0R",
+ dcbf_2 = "7c0000ac-RR",
+ lbzx_3 = "7c0000aeRR0R",
+ neg_2 = "7c0000d0RR.",
+ lbzux_3 = "7c0000eeRR0R",
+ popcntb_2 = "7c0000f4RR~",
+ not_2 = "7c0000f8RR~%.",
+ nor_3 = "7c0000f8RR~R.",
+ subfe_3 = "7c000110RRR.",
+ sube_3 = "7c000110RRR~.",
+ adde_3 = "7c000114RRR.",
+ stdx_3 = "7c00012aRR0R",
+ stwcx_3 = "7c00012cRR0R.",
+ stwx_3 = "7c00012eRR0R",
+ prtyw_2 = "7c000134RR~",
+ stdux_3 = "7c00016aRR0R",
+ stwux_3 = "7c00016eRR0R",
+ prtyd_2 = "7c000174RR~",
+ subfze_2 = "7c000190RR.",
+ addze_2 = "7c000194RR.",
+ stdcx_3 = "7c0001acRR0R.",
+ stbx_3 = "7c0001aeRR0R",
+ subfme_2 = "7c0001d0RR.",
+ mulld_3 = "7c0001d2RRR.",
+ addme_2 = "7c0001d4RR.",
+ mullw_3 = "7c0001d6RRR.",
+ dcbtst_2 = "7c0001ec-RR",
+ stbux_3 = "7c0001eeRR0R",
+ add_3 = "7c000214RRR.",
+ dcbt_2 = "7c00022c-RR",
+ lhzx_3 = "7c00022eRR0R",
+ eqv_3 = "7c000238RR~R.",
+ eciwx_3 = "7c00026cRR0R",
+ lhzux_3 = "7c00026eRR0R",
+ xor_3 = "7c000278RR~R.",
+ mfspefscr_1 = "7c0082a6R",
+ mfxer_1 = "7c0102a6R",
+ mflr_1 = "7c0802a6R",
+ mfctr_1 = "7c0902a6R",
+ lwax_3 = "7c0002aaRR0R",
+ lhax_3 = "7c0002aeRR0R",
+ mftb_1 = "7c0c42e6R",
+ mftbu_1 = "7c0d42e6R",
+ lwaux_3 = "7c0002eaRR0R",
+ lhaux_3 = "7c0002eeRR0R",
+ sthx_3 = "7c00032eRR0R",
+ orc_3 = "7c000338RR~R.",
+ ecowx_3 = "7c00036cRR0R",
+ sthux_3 = "7c00036eRR0R",
+ or_3 = "7c000378RR~R.",
+ mr_2 = "7c000378RR~%.",
+ divdu_3 = "7c000392RRR.",
+ divwu_3 = "7c000396RRR.",
+ mtspefscr_1 = "7c0083a6R",
+ mtxer_1 = "7c0103a6R",
+ mtlr_1 = "7c0803a6R",
+ mtctr_1 = "7c0903a6R",
+ dcbi_2 = "7c0003ac-RR",
+ nand_3 = "7c0003b8RR~R.",
+ divd_3 = "7c0003d2RRR.",
+ divw_3 = "7c0003d6RRR.",
+ cmpb_3 = "7c0003f8RR~R.",
+ mcrxr_1 = "7c000400X",
+ subfco_3 = "7c000410RRR.",
+ subco_3 = "7c000410RRR~.",
+ addco_3 = "7c000414RRR.",
+ ldbrx_3 = "7c000428RR0R",
+ lswx_3 = "7c00042aRR0R",
+ lwbrx_3 = "7c00042cRR0R",
+ lfsx_3 = "7c00042eFR0R",
+ srw_3 = "7c000430RR~R.",
+ srd_3 = "7c000436RR~R.",
+ subfo_3 = "7c000450RRR.",
+ subo_3 = "7c000450RRR~.",
+ lfsux_3 = "7c00046eFR0R",
+ lswi_3 = "7c0004aaRR0A",
+ sync_0 = "7c0004ac",
+ lwsync_0 = "7c2004ac",
+ ptesync_0 = "7c4004ac",
+ lfdx_3 = "7c0004aeFR0R",
+ nego_2 = "7c0004d0RR.",
+ lfdux_3 = "7c0004eeFR0R",
+ subfeo_3 = "7c000510RRR.",
+ subeo_3 = "7c000510RRR~.",
+ addeo_3 = "7c000514RRR.",
+ stdbrx_3 = "7c000528RR0R",
+ stswx_3 = "7c00052aRR0R",
+ stwbrx_3 = "7c00052cRR0R",
+ stfsx_3 = "7c00052eFR0R",
+ stfsux_3 = "7c00056eFR0R",
+ subfzeo_2 = "7c000590RR.",
+ addzeo_2 = "7c000594RR.",
+ stswi_3 = "7c0005aaRR0A",
+ stfdx_3 = "7c0005aeFR0R",
+ subfmeo_2 = "7c0005d0RR.",
+ mulldo_3 = "7c0005d2RRR.",
+ addmeo_2 = "7c0005d4RR.",
+ mullwo_3 = "7c0005d6RRR.",
+ dcba_2 = "7c0005ec-RR",
+ stfdux_3 = "7c0005eeFR0R",
+ addo_3 = "7c000614RRR.",
+ lhbrx_3 = "7c00062cRR0R",
+ sraw_3 = "7c000630RR~R.",
+ srad_3 = "7c000634RR~R.",
+ srawi_3 = "7c000670RR~A.",
+ sradi_3 = "7c000674RR~H.",
+ eieio_0 = "7c0006ac",
+ lfiwax_3 = "7c0006aeFR0R",
+ sthbrx_3 = "7c00072cRR0R",
+ extsh_2 = "7c000734RR~.",
+ extsb_2 = "7c000774RR~.",
+ divduo_3 = "7c000792RRR.",
+ divwou_3 = "7c000796RRR.",
+ icbi_2 = "7c0007ac-RR",
+ stfiwx_3 = "7c0007aeFR0R",
+ extsw_2 = "7c0007b4RR~.",
+ divdo_3 = "7c0007d2RRR.",
+ divwo_3 = "7c0007d6RRR.",
+ dcbz_2 = "7c0007ec-RR",
+
+ -- Primary opcode 30:
+ rldicl_4 = "78000000RR~HM.",
+ rldicr_4 = "78000004RR~HM.",
+ rldic_4 = "78000008RR~HM.",
+ rldimi_4 = "7800000cRR~HM.",
+ rldcl_4 = "78000010RR~RM.",
+ rldcr_4 = "78000012RR~RM.",
+
+ -- Primary opcode 59:
+ fdivs_3 = "ec000024FFF.",
+ fsubs_3 = "ec000028FFF.",
+ fadds_3 = "ec00002aFFF.",
+ fsqrts_2 = "ec00002cF-F.",
+ fres_2 = "ec000030F-F.",
+ fmuls_3 = "ec000032FF-F.",
+ frsqrtes_2 = "ec000034F-F.",
+ fmsubs_4 = "ec000038FFFF~.",
+ fmadds_4 = "ec00003aFFFF~.",
+ fnmsubs_4 = "ec00003cFFFF~.",
+ fnmadds_4 = "ec00003eFFFF~.",
+
+ -- Primary opcode 63:
+ fdiv_3 = "fc000024FFF.",
+ fsub_3 = "fc000028FFF.",
+ fadd_3 = "fc00002aFFF.",
+ fsqrt_2 = "fc00002cF-F.",
+ fsel_4 = "fc00002eFFFF~.",
+ fre_2 = "fc000030F-F.",
+ fmul_3 = "fc000032FF-F.",
+ frsqrte_2 = "fc000034F-F.",
+ fmsub_4 = "fc000038FFFF~.",
+ fmadd_4 = "fc00003aFFFF~.",
+ fnmsub_4 = "fc00003cFFFF~.",
+ fnmadd_4 = "fc00003eFFFF~.",
+ fcmpu_3 = "fc000000XFF",
+ fcpsgn_3 = "fc000010FFF.",
+ fcmpo_3 = "fc000040XFF",
+ mtfsb1_1 = "fc00004cA",
+ fneg_2 = "fc000050F-F.",
+ mcrfs_2 = "fc000080XX",
+ mtfsb0_1 = "fc00008cA",
+ fmr_2 = "fc000090F-F.",
+ frsp_2 = "fc000018F-F.",
+ fctiw_2 = "fc00001cF-F.",
+ fctiwz_2 = "fc00001eF-F.",
+ mtfsfi_2 = "fc00010cAA", -- NYI: upshift.
+ fnabs_2 = "fc000110F-F.",
+ fabs_2 = "fc000210F-F.",
+ frin_2 = "fc000310F-F.",
+ friz_2 = "fc000350F-F.",
+ frip_2 = "fc000390F-F.",
+ frim_2 = "fc0003d0F-F.",
+ mffs_1 = "fc00048eF.",
+ -- NYI: mtfsf, mtfsb0, mtfsb1.
+ fctid_2 = "fc00065cF-F.",
+ fctidz_2 = "fc00065eF-F.",
+ fcfid_2 = "fc00069cF-F.",
+
+ -- Primary opcode 4, SPE APU extension:
+ evaddw_3 = "10000200RRR",
+ evaddiw_3 = "10000202RAR~",
+ evsubw_3 = "10000204RRR~",
+ evsubiw_3 = "10000206RAR~",
+ evabs_2 = "10000208RR",
+ evneg_2 = "10000209RR",
+ evextsb_2 = "1000020aRR",
+ evextsh_2 = "1000020bRR",
+ evrndw_2 = "1000020cRR",
+ evcntlzw_2 = "1000020dRR",
+ evcntlsw_2 = "1000020eRR",
+ brinc_3 = "1000020fRRR",
+ evand_3 = "10000211RRR",
+ evandc_3 = "10000212RRR",
+ evxor_3 = "10000216RRR",
+ evor_3 = "10000217RRR",
+ evmr_2 = "10000217RR=",
+ evnor_3 = "10000218RRR",
+ evnot_2 = "10000218RR=",
+ eveqv_3 = "10000219RRR",
+ evorc_3 = "1000021bRRR",
+ evnand_3 = "1000021eRRR",
+ evsrwu_3 = "10000220RRR",
+ evsrws_3 = "10000221RRR",
+ evsrwiu_3 = "10000222RRA",
+ evsrwis_3 = "10000223RRA",
+ evslw_3 = "10000224RRR",
+ evslwi_3 = "10000226RRA",
+ evrlw_3 = "10000228RRR",
+ evsplati_2 = "10000229RS",
+ evrlwi_3 = "1000022aRRA",
+ evsplatfi_2 = "1000022bRS",
+ evmergehi_3 = "1000022cRRR",
+ evmergelo_3 = "1000022dRRR",
+ evcmpgtu_3 = "10000230XRR",
+ evcmpgtu_2 = "10000230-RR",
+ evcmpgts_3 = "10000231XRR",
+ evcmpgts_2 = "10000231-RR",
+ evcmpltu_3 = "10000232XRR",
+ evcmpltu_2 = "10000232-RR",
+ evcmplts_3 = "10000233XRR",
+ evcmplts_2 = "10000233-RR",
+ evcmpeq_3 = "10000234XRR",
+ evcmpeq_2 = "10000234-RR",
+ evsel_4 = "10000278RRRW",
+ evsel_3 = "10000278RRR",
+ evfsadd_3 = "10000280RRR",
+ evfssub_3 = "10000281RRR",
+ evfsabs_2 = "10000284RR",
+ evfsnabs_2 = "10000285RR",
+ evfsneg_2 = "10000286RR",
+ evfsmul_3 = "10000288RRR",
+ evfsdiv_3 = "10000289RRR",
+ evfscmpgt_3 = "1000028cXRR",
+ evfscmpgt_2 = "1000028c-RR",
+ evfscmplt_3 = "1000028dXRR",
+ evfscmplt_2 = "1000028d-RR",
+ evfscmpeq_3 = "1000028eXRR",
+ evfscmpeq_2 = "1000028e-RR",
+ evfscfui_2 = "10000290R-R",
+ evfscfsi_2 = "10000291R-R",
+ evfscfuf_2 = "10000292R-R",
+ evfscfsf_2 = "10000293R-R",
+ evfsctui_2 = "10000294R-R",
+ evfsctsi_2 = "10000295R-R",
+ evfsctuf_2 = "10000296R-R",
+ evfsctsf_2 = "10000297R-R",
+ evfsctuiz_2 = "10000298R-R",
+ evfsctsiz_2 = "1000029aR-R",
+ evfststgt_3 = "1000029cXRR",
+ evfststgt_2 = "1000029c-RR",
+ evfststlt_3 = "1000029dXRR",
+ evfststlt_2 = "1000029d-RR",
+ evfststeq_3 = "1000029eXRR",
+ evfststeq_2 = "1000029e-RR",
+ efsadd_3 = "100002c0RRR",
+ efssub_3 = "100002c1RRR",
+ efsabs_2 = "100002c4RR",
+ efsnabs_2 = "100002c5RR",
+ efsneg_2 = "100002c6RR",
+ efsmul_3 = "100002c8RRR",
+ efsdiv_3 = "100002c9RRR",
+ efscmpgt_3 = "100002ccXRR",
+ efscmpgt_2 = "100002cc-RR",
+ efscmplt_3 = "100002cdXRR",
+ efscmplt_2 = "100002cd-RR",
+ efscmpeq_3 = "100002ceXRR",
+ efscmpeq_2 = "100002ce-RR",
+ efscfd_2 = "100002cfR-R",
+ efscfui_2 = "100002d0R-R",
+ efscfsi_2 = "100002d1R-R",
+ efscfuf_2 = "100002d2R-R",
+ efscfsf_2 = "100002d3R-R",
+ efsctui_2 = "100002d4R-R",
+ efsctsi_2 = "100002d5R-R",
+ efsctuf_2 = "100002d6R-R",
+ efsctsf_2 = "100002d7R-R",
+ efsctuiz_2 = "100002d8R-R",
+ efsctsiz_2 = "100002daR-R",
+ efststgt_3 = "100002dcXRR",
+ efststgt_2 = "100002dc-RR",
+ efststlt_3 = "100002ddXRR",
+ efststlt_2 = "100002dd-RR",
+ efststeq_3 = "100002deXRR",
+ efststeq_2 = "100002de-RR",
+ efdadd_3 = "100002e0RRR",
+ efdsub_3 = "100002e1RRR",
+ efdcfuid_2 = "100002e2R-R",
+ efdcfsid_2 = "100002e3R-R",
+ efdabs_2 = "100002e4RR",
+ efdnabs_2 = "100002e5RR",
+ efdneg_2 = "100002e6RR",
+ efdmul_3 = "100002e8RRR",
+ efddiv_3 = "100002e9RRR",
+ efdctuidz_2 = "100002eaR-R",
+ efdctsidz_2 = "100002ebR-R",
+ efdcmpgt_3 = "100002ecXRR",
+ efdcmpgt_2 = "100002ec-RR",
+ efdcmplt_3 = "100002edXRR",
+ efdcmplt_2 = "100002ed-RR",
+ efdcmpeq_3 = "100002eeXRR",
+ efdcmpeq_2 = "100002ee-RR",
+ efdcfs_2 = "100002efR-R",
+ efdcfui_2 = "100002f0R-R",
+ efdcfsi_2 = "100002f1R-R",
+ efdcfuf_2 = "100002f2R-R",
+ efdcfsf_2 = "100002f3R-R",
+ efdctui_2 = "100002f4R-R",
+ efdctsi_2 = "100002f5R-R",
+ efdctuf_2 = "100002f6R-R",
+ efdctsf_2 = "100002f7R-R",
+ efdctuiz_2 = "100002f8R-R",
+ efdctsiz_2 = "100002faR-R",
+ efdtstgt_3 = "100002fcXRR",
+ efdtstgt_2 = "100002fc-RR",
+ efdtstlt_3 = "100002fdXRR",
+ efdtstlt_2 = "100002fd-RR",
+ efdtsteq_3 = "100002feXRR",
+ efdtsteq_2 = "100002fe-RR",
+ evlddx_3 = "10000300RR0R",
+ evldd_2 = "10000301R8",
+ evldwx_3 = "10000302RR0R",
+ evldw_2 = "10000303R8",
+ evldhx_3 = "10000304RR0R",
+ evldh_2 = "10000305R8",
+ evlwhex_3 = "10000310RR0R",
+ evlwhe_2 = "10000311R4",
+ evlwhoux_3 = "10000314RR0R",
+ evlwhou_2 = "10000315R4",
+ evlwhosx_3 = "10000316RR0R",
+ evlwhos_2 = "10000317R4",
+ evstddx_3 = "10000320RR0R",
+ evstdd_2 = "10000321R8",
+ evstdwx_3 = "10000322RR0R",
+ evstdw_2 = "10000323R8",
+ evstdhx_3 = "10000324RR0R",
+ evstdh_2 = "10000325R8",
+ evstwhex_3 = "10000330RR0R",
+ evstwhe_2 = "10000331R4",
+ evstwhox_3 = "10000334RR0R",
+ evstwho_2 = "10000335R4",
+ evstwwex_3 = "10000338RR0R",
+ evstwwe_2 = "10000339R4",
+ evstwwox_3 = "1000033cRR0R",
+ evstwwo_2 = "1000033dR4",
+ evmhessf_3 = "10000403RRR",
+ evmhossf_3 = "10000407RRR",
+ evmheumi_3 = "10000408RRR",
+ evmhesmi_3 = "10000409RRR",
+ evmhesmf_3 = "1000040bRRR",
+ evmhoumi_3 = "1000040cRRR",
+ evmhosmi_3 = "1000040dRRR",
+ evmhosmf_3 = "1000040fRRR",
+ evmhessfa_3 = "10000423RRR",
+ evmhossfa_3 = "10000427RRR",
+ evmheumia_3 = "10000428RRR",
+ evmhesmia_3 = "10000429RRR",
+ evmhesmfa_3 = "1000042bRRR",
+ evmhoumia_3 = "1000042cRRR",
+ evmhosmia_3 = "1000042dRRR",
+ evmhosmfa_3 = "1000042fRRR",
+ evmwhssf_3 = "10000447RRR",
+ evmwlumi_3 = "10000448RRR",
+ evmwhumi_3 = "1000044cRRR",
+ evmwhsmi_3 = "1000044dRRR",
+ evmwhsmf_3 = "1000044fRRR",
+ evmwssf_3 = "10000453RRR",
+ evmwumi_3 = "10000458RRR",
+ evmwsmi_3 = "10000459RRR",
+ evmwsmf_3 = "1000045bRRR",
+ evmwhssfa_3 = "10000467RRR",
+ evmwlumia_3 = "10000468RRR",
+ evmwhumia_3 = "1000046cRRR",
+ evmwhsmia_3 = "1000046dRRR",
+ evmwhsmfa_3 = "1000046fRRR",
+ evmwssfa_3 = "10000473RRR",
+ evmwumia_3 = "10000478RRR",
+ evmwsmia_3 = "10000479RRR",
+ evmwsmfa_3 = "1000047bRRR",
+ evmra_2 = "100004c4RR",
+ evdivws_3 = "100004c6RRR",
+ evdivwu_3 = "100004c7RRR",
+ evmwssfaa_3 = "10000553RRR",
+ evmwumiaa_3 = "10000558RRR",
+ evmwsmiaa_3 = "10000559RRR",
+ evmwsmfaa_3 = "1000055bRRR",
+ evmwssfan_3 = "100005d3RRR",
+ evmwumian_3 = "100005d8RRR",
+ evmwsmian_3 = "100005d9RRR",
+ evmwsmfan_3 = "100005dbRRR",
+ evmergehilo_3 = "1000022eRRR",
+ evmergelohi_3 = "1000022fRRR",
+ evlhhesplatx_3 = "10000308RR0R",
+ evlhhesplat_2 = "10000309R2",
+ evlhhousplatx_3 = "1000030cRR0R",
+ evlhhousplat_2 = "1000030dR2",
+ evlhhossplatx_3 = "1000030eRR0R",
+ evlhhossplat_2 = "1000030fR2",
+ evlwwsplatx_3 = "10000318RR0R",
+ evlwwsplat_2 = "10000319R4",
+ evlwhsplatx_3 = "1000031cRR0R",
+ evlwhsplat_2 = "1000031dR4",
+ evaddusiaaw_2 = "100004c0RR",
+ evaddssiaaw_2 = "100004c1RR",
+ evsubfusiaaw_2 = "100004c2RR",
+ evsubfssiaaw_2 = "100004c3RR",
+ evaddumiaaw_2 = "100004c8RR",
+ evaddsmiaaw_2 = "100004c9RR",
+ evsubfumiaaw_2 = "100004caRR",
+ evsubfsmiaaw_2 = "100004cbRR",
+ evmheusiaaw_3 = "10000500RRR",
+ evmhessiaaw_3 = "10000501RRR",
+ evmhessfaaw_3 = "10000503RRR",
+ evmhousiaaw_3 = "10000504RRR",
+ evmhossiaaw_3 = "10000505RRR",
+ evmhossfaaw_3 = "10000507RRR",
+ evmheumiaaw_3 = "10000508RRR",
+ evmhesmiaaw_3 = "10000509RRR",
+ evmhesmfaaw_3 = "1000050bRRR",
+ evmhoumiaaw_3 = "1000050cRRR",
+ evmhosmiaaw_3 = "1000050dRRR",
+ evmhosmfaaw_3 = "1000050fRRR",
+ evmhegumiaa_3 = "10000528RRR",
+ evmhegsmiaa_3 = "10000529RRR",
+ evmhegsmfaa_3 = "1000052bRRR",
+ evmhogumiaa_3 = "1000052cRRR",
+ evmhogsmiaa_3 = "1000052dRRR",
+ evmhogsmfaa_3 = "1000052fRRR",
+ evmwlusiaaw_3 = "10000540RRR",
+ evmwlssiaaw_3 = "10000541RRR",
+ evmwlumiaaw_3 = "10000548RRR",
+ evmwlsmiaaw_3 = "10000549RRR",
+ evmheusianw_3 = "10000580RRR",
+ evmhessianw_3 = "10000581RRR",
+ evmhessfanw_3 = "10000583RRR",
+ evmhousianw_3 = "10000584RRR",
+ evmhossianw_3 = "10000585RRR",
+ evmhossfanw_3 = "10000587RRR",
+ evmheumianw_3 = "10000588RRR",
+ evmhesmianw_3 = "10000589RRR",
+ evmhesmfanw_3 = "1000058bRRR",
+ evmhoumianw_3 = "1000058cRRR",
+ evmhosmianw_3 = "1000058dRRR",
+ evmhosmfanw_3 = "1000058fRRR",
+ evmhegumian_3 = "100005a8RRR",
+ evmhegsmian_3 = "100005a9RRR",
+ evmhegsmfan_3 = "100005abRRR",
+ evmhogumian_3 = "100005acRRR",
+ evmhogsmian_3 = "100005adRRR",
+ evmhogsmfan_3 = "100005afRRR",
+ evmwlusianw_3 = "100005c0RRR",
+ evmwlssianw_3 = "100005c1RRR",
+ evmwlumianw_3 = "100005c8RRR",
+ evmwlsmianw_3 = "100005c9RRR",
+
+ -- NYI: Book E instructions.
+}
+
+-- Add mnemonics for "." variants.
+do
+ local t = {}
+ for k,v in pairs(map_op) do
+ if sub(v, -1) == "." then
+ local v2 = sub(v, 1, 7)..char(byte(v, 8)+1)..sub(v, 9, -2)
+ t[sub(k, 1, -3).."."..sub(k, -2)] = v2
+ end
+ end
+ for k,v in pairs(t) do
+ map_op[k] = v
+ end
+end
+
+-- Add more branch mnemonics.
+for cond,c in pairs(map_cond) do
+ local b1 = "b"..cond
+ local c1 = shl(band(c, 3), 16) + (c < 4 and 0x01000000 or 0)
+ -- bX[l]
+ map_op[b1.."_1"] = tohex(0x40800000 + c1).."K"
+ map_op[b1.."y_1"] = tohex(0x40a00000 + c1).."K"
+ map_op[b1.."l_1"] = tohex(0x40800001 + c1).."K"
+ map_op[b1.."_2"] = tohex(0x40800000 + c1).."-XK"
+ map_op[b1.."y_2"] = tohex(0x40a00000 + c1).."-XK"
+ map_op[b1.."l_2"] = tohex(0x40800001 + c1).."-XK"
+ -- bXlr[l]
+ map_op[b1.."lr_0"] = tohex(0x4c800020 + c1)
+ map_op[b1.."lrl_0"] = tohex(0x4c800021 + c1)
+ map_op[b1.."ctr_0"] = tohex(0x4c800420 + c1)
+ map_op[b1.."ctrl_0"] = tohex(0x4c800421 + c1)
+ -- bXctr[l]
+ map_op[b1.."lr_1"] = tohex(0x4c800020 + c1).."-X"
+ map_op[b1.."lrl_1"] = tohex(0x4c800021 + c1).."-X"
+ map_op[b1.."ctr_1"] = tohex(0x4c800420 + c1).."-X"
+ map_op[b1.."ctrl_1"] = tohex(0x4c800421 + c1).."-X"
+end
+
+------------------------------------------------------------------------------
+
+local function parse_gpr(expr)
+ local tname, ovreg = match(expr, "^([%w_]+):(r[1-3]?[0-9])$")
+ local tp = map_type[tname or expr]
+ if tp then
+ local reg = ovreg or tp.reg
+ if not reg then
+ werror("type `"..(tname or expr).."' needs a register override")
+ end
+ expr = reg
+ end
+ local r = match(expr, "^r([1-3]?[0-9])$")
+ if r then
+ r = tonumber(r)
+ if r <= 31 then return r, tp end
+ end
+ werror("bad register name `"..expr.."'")
+end
+
+local function parse_fpr(expr)
+ local r = match(expr, "^f([1-3]?[0-9])$")
+ if r then
+ r = tonumber(r)
+ if r <= 31 then return r end
+ end
+ werror("bad register name `"..expr.."'")
+end
+
+local function parse_cr(expr)
+ local r = match(expr, "^cr([0-7])$")
+ if r then return tonumber(r) end
+ werror("bad condition register name `"..expr.."'")
+end
+
+local function parse_cond(expr)
+ local r, cond = match(expr, "^4%*cr([0-7])%+(%w%w)$")
+ if r then
+ r = tonumber(r)
+ local c = map_cond[cond]
+ if c and c < 4 then return r*4+c end
+ end
+ werror("bad condition bit name `"..expr.."'")
+end
+
+local function parse_imm(imm, bits, shift, scale, signed)
+ local n = tonumber(imm)
+ if n then
+ local m = sar(n, scale)
+ if shl(m, scale) == n then
+ if signed then
+ local s = sar(m, bits-1)
+ if s == 0 then return shl(m, shift)
+ elseif s == -1 then return shl(m + shl(1, bits), shift) end
+ else
+ if sar(m, bits) == 0 then return shl(m, shift) end
+ end
+ end
+ werror("out of range immediate `"..imm.."'")
+ elseif match(imm, "^r([1-3]?[0-9])$") or
+ match(imm, "^([%w_]+):(r[1-3]?[0-9])$") then
+ werror("expected immediate operand, got register")
+ else
+ waction("IMM", (signed and 32768 or 0)+scale*1024+bits*32+shift, imm)
+ return 0
+ end
+end
+
+local function parse_shiftmask(imm, isshift)
+ local n = tonumber(imm)
+ if n then
+ if shr(n, 6) == 0 then
+ local lsb = band(imm, 31)
+ local msb = imm - lsb
+ return isshift and (shl(lsb, 11)+shr(msb, 4)) or (shl(lsb, 6)+msb)
+ end
+ werror("out of range immediate `"..imm.."'")
+ elseif match(imm, "^r([1-3]?[0-9])$") or
+ match(imm, "^([%w_]+):(r[1-3]?[0-9])$") then
+ werror("expected immediate operand, got register")
+ else
+ werror("NYI: parameterized 64 bit shift/mask")
+ end
+end
+
+local function parse_disp(disp)
+ local imm, reg = match(disp, "^(.*)%(([%w_:]+)%)$")
+ if imm then
+ local r = parse_gpr(reg)
+ if r == 0 then werror("cannot use r0 in displacement") end
+ return shl(r, 16) + parse_imm(imm, 16, 0, 0, true)
+ end
+ local reg, tailr = match(disp, "^([%w_:]+)%s*(.*)$")
+ if reg and tailr ~= "" then
+ local r, tp = parse_gpr(reg)
+ if r == 0 then werror("cannot use r0 in displacement") end
+ if tp then
+ waction("IMM", 32768+16*32, format(tp.ctypefmt, tailr))
+ return shl(r, 16)
+ end
+ end
+ werror("bad displacement `"..disp.."'")
+end
+
+local function parse_u5disp(disp, scale)
+ local imm, reg = match(disp, "^(.*)%(([%w_:]+)%)$")
+ if imm then
+ local r = parse_gpr(reg)
+ if r == 0 then werror("cannot use r0 in displacement") end
+ return shl(r, 16) + parse_imm(imm, 5, 11, scale, false)
+ end
+ local reg, tailr = match(disp, "^([%w_:]+)%s*(.*)$")
+ if reg and tailr ~= "" then
+ local r, tp = parse_gpr(reg)
+ if r == 0 then werror("cannot use r0 in displacement") end
+ if tp then
+ waction("IMM", scale*1024+5*32+11, format(tp.ctypefmt, tailr))
+ return shl(r, 16)
+ end
+ end
+ werror("bad displacement `"..disp.."'")
+end
+
+local function parse_label(label, def)
+ local prefix = sub(label, 1, 2)
+ -- =>label (pc label reference)
+ if prefix == "=>" then
+ return "PC", 0, sub(label, 3)
+ end
+ -- ->name (global label reference)
+ if prefix == "->" then
+ return "LG", map_global[sub(label, 3)]
+ end
+ if def then
+ -- [1-9] (local label definition)
+ if match(label, "^[1-9]$") then
+ return "LG", 10+tonumber(label)
+ end
+ else
+ -- [<>][1-9] (local label reference)
+ local dir, lnum = match(label, "^([<>])([1-9])$")
+ if dir then -- Fwd: 1-9, Bkwd: 11-19.
+ return "LG", lnum + (dir == ">" and 0 or 10)
+ end
+ -- extern label (extern label reference)
+ local extname = match(label, "^extern%s+(%S+)$")
+ if extname then
+ return "EXT", map_extern[extname]
+ end
+ end
+ werror("bad label `"..label.."'")
+end
+
+------------------------------------------------------------------------------
+
+-- Handle opcodes defined with template strings.
+map_op[".template__"] = function(params, template, nparams)
+ if not params then return sub(template, 9) end
+ local op = tonumber(sub(template, 1, 8), 16)
+ local n, rs = 1, 26
+
+ -- Limit number of section buffer positions used by a single dasm_put().
+ -- A single opcode needs a maximum of 3 positions (rlwinm).
+ if secpos+3 > maxsecpos then wflush() end
+ local pos = wpos()
+
+ -- Process each character.
+ for p in gmatch(sub(template, 9), ".") do
+ if p == "R" then
+ rs = rs - 5; op = op + shl(parse_gpr(params[n]), rs); n = n + 1
+ elseif p == "F" then
+ rs = rs - 5; op = op + shl(parse_fpr(params[n]), rs); n = n + 1
+ elseif p == "A" then
+ rs = rs - 5; op = op + parse_imm(params[n], 5, rs, 0, false); n = n + 1
+ elseif p == "S" then
+ rs = rs - 5; op = op + parse_imm(params[n], 5, rs, 0, true); n = n + 1
+ elseif p == "I" then
+ op = op + parse_imm(params[n], 16, 0, 0, true); n = n + 1
+ elseif p == "U" then
+ op = op + parse_imm(params[n], 16, 0, 0, false); n = n + 1
+ elseif p == "D" then
+ op = op + parse_disp(params[n]); n = n + 1
+ elseif p == "2" then
+ op = op + parse_u5disp(params[n], 1); n = n + 1
+ elseif p == "4" then
+ op = op + parse_u5disp(params[n], 2); n = n + 1
+ elseif p == "8" then
+ op = op + parse_u5disp(params[n], 3); n = n + 1
+ elseif p == "C" then
+ rs = rs - 5; op = op + shl(parse_cond(params[n]), rs); n = n + 1
+ elseif p == "X" then
+ rs = rs - 5; op = op + shl(parse_cr(params[n]), rs+2); n = n + 1
+ elseif p == "W" then
+ op = op + parse_cr(params[n]); n = n + 1
+ elseif p == "G" then
+ op = op + parse_imm(params[n], 8, 12, 0, false); n = n + 1
+ elseif p == "H" then
+ op = op + parse_shiftmask(params[n], true); n = n + 1
+ elseif p == "M" then
+ op = op + parse_shiftmask(params[n], false); n = n + 1
+ elseif p == "J" or p == "K" then
+ local mode, n, s = parse_label(params[n], false)
+ if p == "K" then n = n + 2048 end
+ waction("REL_"..mode, n, s, 1)
+ n = n + 1
+ elseif p == "0" then
+ if band(shr(op, rs), 31) == 0 then werror("cannot use r0") end
+ elseif p == "=" or p == "%" then
+ local t = band(shr(op, p == "%" and rs+5 or rs), 31)
+ rs = rs - 5
+ op = op + shl(t, rs)
+ elseif p == "~" then
+ local mm = shl(31, rs)
+ local lo = band(op, mm)
+ local hi = band(op, shl(mm, 5))
+ op = op - lo - hi + shl(lo, 5) + shr(hi, 5)
+ elseif p == "-" then
+ rs = rs - 5
+ elseif p == "." then
+ -- Ignored.
+ else
+ assert(false)
+ end
+ end
+ wputpos(pos, op)
+end
+
+------------------------------------------------------------------------------
+
+-- Pseudo-opcode to mark the position where the action list is to be emitted.
+map_op[".actionlist_1"] = function(params)
+ if not params then return "cvar" end
+ local name = params[1] -- No syntax check. You get to keep the pieces.
+ wline(function(out) writeactions(out, name) end)
+end
+
+-- Pseudo-opcode to mark the position where the global enum is to be emitted.
+map_op[".globals_1"] = function(params)
+ if not params then return "prefix" end
+ local prefix = params[1] -- No syntax check. You get to keep the pieces.
+ wline(function(out) writeglobals(out, prefix) end)
+end
+
+-- Pseudo-opcode to mark the position where the global names are to be emitted.
+map_op[".globalnames_1"] = function(params)
+ if not params then return "cvar" end
+ local name = params[1] -- No syntax check. You get to keep the pieces.
+ wline(function(out) writeglobalnames(out, name) end)
+end
+
+-- Pseudo-opcode to mark the position where the extern names are to be emitted.
+map_op[".externnames_1"] = function(params)
+ if not params then return "cvar" end
+ local name = params[1] -- No syntax check. You get to keep the pieces.
+ wline(function(out) writeexternnames(out, name) end)
+end
+
+------------------------------------------------------------------------------
+
+-- Label pseudo-opcode (converted from trailing colon form).
+map_op[".label_1"] = function(params)
+ if not params then return "[1-9] | ->global | =>pcexpr" end
+ if secpos+1 > maxsecpos then wflush() end
+ local mode, n, s = parse_label(params[1], true)
+ if mode == "EXT" then werror("bad label definition") end
+ waction("LABEL_"..mode, n, s, 1)
+end
+
+------------------------------------------------------------------------------
+
+-- Pseudo-opcodes for data storage.
+map_op[".long_*"] = function(params)
+ if not params then return "imm..." end
+ for _,p in ipairs(params) do
+ local n = tonumber(p)
+ if not n then werror("bad immediate `"..p.."'") end
+ if n < 0 then n = n + 2^32 end
+ wputw(n)
+ if secpos+2 > maxsecpos then wflush() end
+ end
+end
+
+-- Alignment pseudo-opcode.
+map_op[".align_1"] = function(params)
+ if not params then return "numpow2" end
+ if secpos+1 > maxsecpos then wflush() end
+ local align = tonumber(params[1])
+ if align then
+ local x = align
+ -- Must be a power of 2 in the range (2 ... 256).
+ for i=1,8 do
+ x = x / 2
+ if x == 1 then
+ waction("ALIGN", align-1, nil, 1) -- Action byte is 2**n-1.
+ return
+ end
+ end
+ end
+ werror("bad alignment")
+end
+
+------------------------------------------------------------------------------
+
+-- Pseudo-opcode for (primitive) type definitions (map to C types).
+map_op[".type_3"] = function(params, nparams)
+ if not params then
+ return nparams == 2 and "name, ctype" or "name, ctype, reg"
+ end
+ local name, ctype, reg = params[1], params[2], params[3]
+ if not match(name, "^[%a_][%w_]*$") then
+ werror("bad type name `"..name.."'")
+ end
+ local tp = map_type[name]
+ if tp then
+ werror("duplicate type `"..name.."'")
+ end
+ -- Add #type to defines. A bit unclean to put it in map_archdef.
+ map_archdef["#"..name] = "sizeof("..ctype..")"
+ -- Add new type and emit shortcut define.
+ local num = ctypenum + 1
+ map_type[name] = {
+ ctype = ctype,
+ ctypefmt = format("Dt%X(%%s)", num),
+ reg = reg,
+ }
+ wline(format("#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)", num, ctype))
+ ctypenum = num
+end
+map_op[".type_2"] = map_op[".type_3"]
+
+-- Dump type definitions.
+local function dumptypes(out, lvl)
+ local t = {}
+ for name in pairs(map_type) do t[#t+1] = name end
+ sort(t)
+ out:write("Type definitions:\n")
+ for _,name in ipairs(t) do
+ local tp = map_type[name]
+ local reg = tp.reg or ""
+ out:write(format(" %-20s %-20s %s\n", name, tp.ctype, reg))
+ end
+ out:write("\n")
+end
+
+------------------------------------------------------------------------------
+
+-- Set the current section.
+function _M.section(num)
+ waction("SECTION", num)
+ wflush(true) -- SECTION is a terminal action.
+end
+
+------------------------------------------------------------------------------
+
+-- Dump architecture description.
+function _M.dumparch(out)
+ out:write(format("DynASM %s version %s, released %s\n\n",
+ _info.arch, _info.version, _info.release))
+ dumpactions(out)
+end
+
+-- Dump all user defined elements.
+function _M.dumpdef(out, lvl)
+ dumptypes(out, lvl)
+ dumpglobals(out, lvl)
+ dumpexterns(out, lvl)
+end
+
+------------------------------------------------------------------------------
+
+-- Pass callbacks from/to the DynASM core.
+function _M.passcb(wl, we, wf, ww)
+ wline, werror, wfatal, wwarn = wl, we, wf, ww
+ return wflush
+end
+
+-- Setup the arch-specific module.
+function _M.setup(arch, opt)
+ g_arch, g_opt = arch, opt
+end
+
+-- Merge the core maps and the arch-specific maps.
+function _M.mergemaps(map_coreop, map_def)
+ setmetatable(map_op, { __index = map_coreop })
+ setmetatable(map_def, { __index = map_archdef })
+ return map_op, map_def
+end
+
+return _M
+
+------------------------------------------------------------------------------
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_proto.h b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_proto.h
new file mode 100644
index 0000000..f5e79c7
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_proto.h
@@ -0,0 +1,83 @@
+/*
+** DynASM encoding engine prototypes.
+** Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+** Released under the MIT license. See dynasm.lua for full copyright notice.
+*/
+
+#ifndef _DASM_PROTO_H
+#define _DASM_PROTO_H
+
+#include <stddef.h>
+#include <stdarg.h>
+
+#define DASM_IDENT "DynASM 1.3.0"
+#define DASM_VERSION 10300 /* 1.3.0 */
+
+#ifndef Dst_DECL
+#define Dst_DECL dasm_State **Dst
+#endif
+
+#ifndef Dst_REF
+#define Dst_REF (*Dst)
+#endif
+
+#ifndef DASM_FDEF
+#define DASM_FDEF extern
+#endif
+
+#ifndef DASM_M_GROW
+#define DASM_M_GROW(ctx, t, p, sz, need) \
+ do { \
+ size_t _sz = (sz), _need = (need); \
+ if (_sz < _need) { \
+ if (_sz < 16) _sz = 16; \
+ while (_sz < _need) _sz += _sz; \
+ (p) = (t *)realloc((p), _sz); \
+ if ((p) == NULL) exit(1); \
+ (sz) = _sz; \
+ } \
+ } while(0)
+#endif
+
+#ifndef DASM_M_FREE
+#define DASM_M_FREE(ctx, p, sz) free(p)
+#endif
+
+/* Internal DynASM encoder state. */
+typedef struct dasm_State dasm_State;
+
+
+/* Initialize and free DynASM state. */
+DASM_FDEF void dasm_init(Dst_DECL, int maxsection);
+DASM_FDEF void dasm_free(Dst_DECL);
+
+/* Setup global array. Must be called before dasm_setup(). */
+DASM_FDEF void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl);
+
+/* Grow PC label array. Can be called after dasm_setup(), too. */
+DASM_FDEF void dasm_growpc(Dst_DECL, unsigned int maxpc);
+
+/* Setup encoder. */
+DASM_FDEF void dasm_setup(Dst_DECL, const void *actionlist);
+
+/* Feed encoder with actions. Calls are generated by pre-processor. */
+DASM_FDEF void dasm_put(Dst_DECL, int start, ...);
+
+/* Link sections and return the resulting size. */
+DASM_FDEF int dasm_link(Dst_DECL, size_t *szp);
+
+/* Encode sections into buffer. */
+DASM_FDEF int dasm_encode(Dst_DECL, void *buffer);
+
+/* Get PC label offset. */
+DASM_FDEF int dasm_getpclabel(Dst_DECL, unsigned int pc);
+
+#ifdef DASM_CHECKS
+/* Optional sanity checker to call between isolated encoding steps. */
+DASM_FDEF int dasm_checkstep(Dst_DECL, int secmatch);
+#else
+#define dasm_checkstep(a, b) 0
+#endif
+
+
+#endif /* _DASM_PROTO_H */
diff --git a/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_x64.lua b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_x64.lua
new file mode 100644
index 0000000..e8bdeb3
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_x64.lua
@@ -0,0 +1,12 @@
+------------------------------------------------------------------------------
+-- DynASM x64 module.
+--
+-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+-- See dynasm.lua for full copyright notice.
+------------------------------------------------------------------------------
+-- This module just sets 64 bit mode for the combined x86/x64 module.
+-- All the interesting stuff is there.
+------------------------------------------------------------------------------
+
+x64 = true -- Using a global is an ugly, but effective solution.
+return require("dasm_x86")
diff --git a/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_x86.h b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_x86.h
new file mode 100644
index 0000000..8ae911d
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_x86.h
@@ -0,0 +1,483 @@
+/*
+** DynASM x86 encoding engine.
+** Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+** Released under the MIT license. See dynasm.lua for full copyright notice.
+*/
+
+#include <stddef.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+
+#define DASM_ARCH "x86"
+
+#ifndef DASM_EXTERN
+#define DASM_EXTERN(a,b,c,d) 0
+#endif
+
+/* Action definitions. DASM_STOP must be 255. */
+enum {
+ DASM_DISP = 233,
+ DASM_IMM_S, DASM_IMM_B, DASM_IMM_W, DASM_IMM_D, DASM_IMM_WB, DASM_IMM_DB,
+ DASM_VREG, DASM_SPACE, DASM_SETLABEL, DASM_REL_A, DASM_REL_LG, DASM_REL_PC,
+ DASM_IMM_LG, DASM_IMM_PC, DASM_LABEL_LG, DASM_LABEL_PC, DASM_ALIGN,
+ DASM_EXTERN, DASM_ESC, DASM_MARK, DASM_SECTION, DASM_STOP
+};
+
+/* Maximum number of section buffer positions for a single dasm_put() call. */
+#define DASM_MAXSECPOS 25
+
+/* DynASM encoder status codes. Action list offset or number are or'ed in. */
+#define DASM_S_OK 0x00000000
+#define DASM_S_NOMEM 0x01000000
+#define DASM_S_PHASE 0x02000000
+#define DASM_S_MATCH_SEC 0x03000000
+#define DASM_S_RANGE_I 0x11000000
+#define DASM_S_RANGE_SEC 0x12000000
+#define DASM_S_RANGE_LG 0x13000000
+#define DASM_S_RANGE_PC 0x14000000
+#define DASM_S_RANGE_VREG 0x15000000
+#define DASM_S_UNDEF_L 0x21000000
+#define DASM_S_UNDEF_PC 0x22000000
+
+/* Macros to convert positions (8 bit section + 24 bit index). */
+#define DASM_POS2IDX(pos) ((pos)&0x00ffffff)
+#define DASM_POS2BIAS(pos) ((pos)&0xff000000)
+#define DASM_SEC2POS(sec) ((sec)<<24)
+#define DASM_POS2SEC(pos) ((pos)>>24)
+#define DASM_POS2PTR(D, pos) (D->sections[DASM_POS2SEC(pos)].rbuf + (pos))
+
+/* Action list type. */
+typedef const unsigned char *dasm_ActList;
+
+/* Per-section structure. */
+typedef struct dasm_Section {
+ int *rbuf; /* Biased buffer pointer (negative section bias). */
+ int *buf; /* True buffer pointer. */
+ size_t bsize; /* Buffer size in bytes. */
+ int pos; /* Biased buffer position. */
+ int epos; /* End of biased buffer position - max single put. */
+ int ofs; /* Byte offset into section. */
+} dasm_Section;
+
+/* Core structure holding the DynASM encoding state. */
+struct dasm_State {
+ size_t psize; /* Allocated size of this structure. */
+ dasm_ActList actionlist; /* Current actionlist pointer. */
+ int *lglabels; /* Local/global chain/pos ptrs. */
+ size_t lgsize;
+ int *pclabels; /* PC label chains/pos ptrs. */
+ size_t pcsize;
+ void **globals; /* Array of globals (bias -10). */
+ dasm_Section *section; /* Pointer to active section. */
+ size_t codesize; /* Total size of all code sections. */
+ int maxsection; /* 0 <= sectionidx < maxsection. */
+ int status; /* Status code. */
+ dasm_Section sections[1]; /* All sections. Alloc-extended. */
+};
+
+/* The size of the core structure depends on the max. number of sections. */
+#define DASM_PSZ(ms) (sizeof(dasm_State)+(ms-1)*sizeof(dasm_Section))
+
+
+/* Initialize DynASM state. */
+void dasm_init(Dst_DECL, int maxsection)
+{
+ dasm_State *D;
+ size_t psz = 0;
+ int i;
+ Dst_REF = NULL;
+ DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection));
+ D = Dst_REF;
+ D->psize = psz;
+ D->lglabels = NULL;
+ D->lgsize = 0;
+ D->pclabels = NULL;
+ D->pcsize = 0;
+ D->globals = NULL;
+ D->maxsection = maxsection;
+ for (i = 0; i < maxsection; i++) {
+ D->sections[i].buf = NULL; /* Need this for pass3. */
+ D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);
+ D->sections[i].bsize = 0;
+ D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */
+ }
+}
+
+/* Free DynASM state. */
+void dasm_free(Dst_DECL)
+{
+ dasm_State *D = Dst_REF;
+ int i;
+ for (i = 0; i < D->maxsection; i++)
+ if (D->sections[i].buf)
+ DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize);
+ if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize);
+ if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize);
+ DASM_M_FREE(Dst, D, D->psize);
+}
+
+/* Setup global label array. Must be called before dasm_setup(). */
+void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)
+{
+ dasm_State *D = Dst_REF;
+ D->globals = gl - 10; /* Negative bias to compensate for locals. */
+ DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));
+}
+
+/* Grow PC label array. Can be called after dasm_setup(), too. */
+void dasm_growpc(Dst_DECL, unsigned int maxpc)
+{
+ dasm_State *D = Dst_REF;
+ size_t osz = D->pcsize;
+ DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int));
+ memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz);
+}
+
+/* Setup encoder. */
+void dasm_setup(Dst_DECL, const void *actionlist)
+{
+ dasm_State *D = Dst_REF;
+ int i;
+ D->actionlist = (dasm_ActList)actionlist;
+ D->status = DASM_S_OK;
+ D->section = &D->sections[0];
+ memset((void *)D->lglabels, 0, D->lgsize);
+ if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize);
+ for (i = 0; i < D->maxsection; i++) {
+ D->sections[i].pos = DASM_SEC2POS(i);
+ D->sections[i].ofs = 0;
+ }
+}
+
+
+#ifdef DASM_CHECKS
+#define CK(x, st) \
+ do { if (!(x)) { \
+ D->status = DASM_S_##st|(int)(p-D->actionlist-1); return; } } while (0)
+#define CKPL(kind, st) \
+ do { if ((size_t)((char *)pl-(char *)D->kind##labels) >= D->kind##size) { \
+ D->status=DASM_S_RANGE_##st|(int)(p-D->actionlist-1); return; } } while (0)
+#else
+#define CK(x, st) ((void)0)
+#define CKPL(kind, st) ((void)0)
+#endif
+
+/* Pass 1: Store actions and args, link branches/labels, estimate offsets. */
+void dasm_put(Dst_DECL, int start, ...)
+{
+ va_list ap;
+ dasm_State *D = Dst_REF;
+ dasm_ActList p = D->actionlist + start;
+ dasm_Section *sec = D->section;
+ int pos = sec->pos, ofs = sec->ofs, mrm = 4;
+ int *b;
+
+ if (pos >= sec->epos) {
+ DASM_M_GROW(Dst, int, sec->buf, sec->bsize,
+ sec->bsize + 2*DASM_MAXSECPOS*sizeof(int));
+ sec->rbuf = sec->buf - DASM_POS2BIAS(pos);
+ sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos);
+ }
+
+ b = sec->rbuf;
+ b[pos++] = start;
+
+ va_start(ap, start);
+ while (1) {
+ int action = *p++;
+ if (action < DASM_DISP) {
+ ofs++;
+ } else if (action <= DASM_REL_A) {
+ int n = va_arg(ap, int);
+ b[pos++] = n;
+ switch (action) {
+ case DASM_DISP:
+ if (n == 0) { if ((mrm&7) == 4) mrm = p[-2]; if ((mrm&7) != 5) break; }
+ /* fallthrough */
+ case DASM_IMM_DB: if (((n+128)&-256) == 0) goto ob; /* fallthrough */
+ case DASM_REL_A: /* Assumes ptrdiff_t is int. !x64 */
+ case DASM_IMM_D: ofs += 4; break;
+ case DASM_IMM_S: CK(((n+128)&-256) == 0, RANGE_I); goto ob;
+ case DASM_IMM_B: CK((n&-256) == 0, RANGE_I); ob: ofs++; break;
+ case DASM_IMM_WB: if (((n+128)&-256) == 0) goto ob; /* fallthrough */
+ case DASM_IMM_W: CK((n&-65536) == 0, RANGE_I); ofs += 2; break;
+ case DASM_SPACE: p++; ofs += n; break;
+ case DASM_SETLABEL: b[pos-2] = -0x40000000; break; /* Neg. label ofs. */
+ case DASM_VREG: CK((n&-8) == 0 && (n != 4 || (*p&1) == 0), RANGE_VREG);
+ if (*p++ == 1 && *p == DASM_DISP) mrm = n;
+ continue;
+ }
+ mrm = 4;
+ } else {
+ int *pl, n;
+ switch (action) {
+ case DASM_REL_LG:
+ case DASM_IMM_LG:
+ n = *p++; pl = D->lglabels + n;
+ /* Bkwd rel or global. */
+ if (n <= 246) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; }
+ pl -= 246; n = *pl;
+ if (n < 0) n = 0; /* Start new chain for fwd rel if label exists. */
+ goto linkrel;
+ case DASM_REL_PC:
+ case DASM_IMM_PC: pl = D->pclabels + va_arg(ap, int); CKPL(pc, PC);
+ putrel:
+ n = *pl;
+ if (n < 0) { /* Label exists. Get label pos and store it. */
+ b[pos] = -n;
+ } else {
+ linkrel:
+ b[pos] = n; /* Else link to rel chain, anchored at label. */
+ *pl = pos;
+ }
+ pos++;
+ ofs += 4; /* Maximum offset needed. */
+ if (action == DASM_REL_LG || action == DASM_REL_PC)
+ b[pos++] = ofs; /* Store pass1 offset estimate. */
+ break;
+ case DASM_LABEL_LG: pl = D->lglabels + *p++; CKPL(lg, LG); goto putlabel;
+ case DASM_LABEL_PC: pl = D->pclabels + va_arg(ap, int); CKPL(pc, PC);
+ putlabel:
+ n = *pl; /* n > 0: Collapse rel chain and replace with label pos. */
+ while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos; }
+ *pl = -pos; /* Label exists now. */
+ b[pos++] = ofs; /* Store pass1 offset estimate. */
+ break;
+ case DASM_ALIGN:
+ ofs += *p++; /* Maximum alignment needed (arg is 2**n-1). */
+ b[pos++] = ofs; /* Store pass1 offset estimate. */
+ break;
+ case DASM_EXTERN: p += 2; ofs += 4; break;
+ case DASM_ESC: p++; ofs++; break;
+ case DASM_MARK: mrm = p[-2]; break;
+ case DASM_SECTION:
+ n = *p; CK(n < D->maxsection, RANGE_SEC); D->section = &D->sections[n];
+ case DASM_STOP: goto stop;
+ }
+ }
+ }
+stop:
+ va_end(ap);
+ sec->pos = pos;
+ sec->ofs = ofs;
+}
+#undef CK
+
+/* Pass 2: Link sections, shrink branches/aligns, fix label offsets. */
+int dasm_link(Dst_DECL, size_t *szp)
+{
+ dasm_State *D = Dst_REF;
+ int secnum;
+ int ofs = 0;
+
+#ifdef DASM_CHECKS
+ *szp = 0;
+ if (D->status != DASM_S_OK) return D->status;
+ {
+ int pc;
+ for (pc = 0; pc*sizeof(int) < D->pcsize; pc++)
+ if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc;
+ }
+#endif
+
+ { /* Handle globals not defined in this translation unit. */
+ int idx;
+ for (idx = 10; idx*sizeof(int) < D->lgsize; idx++) {
+ int n = D->lglabels[idx];
+ /* Undefined label: Collapse rel chain and replace with marker (< 0). */
+ while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }
+ }
+ }
+
+ /* Combine all code sections. No support for data sections (yet). */
+ for (secnum = 0; secnum < D->maxsection; secnum++) {
+ dasm_Section *sec = D->sections + secnum;
+ int *b = sec->rbuf;
+ int pos = DASM_SEC2POS(secnum);
+ int lastpos = sec->pos;
+
+ while (pos != lastpos) {
+ dasm_ActList p = D->actionlist + b[pos++];
+ while (1) {
+ int op, action = *p++;
+ switch (action) {
+ case DASM_REL_LG: p++; op = p[-3]; goto rel_pc;
+ case DASM_REL_PC: op = p[-2]; rel_pc: {
+ int shrink = op == 0xe9 ? 3 : ((op&0xf0) == 0x80 ? 4 : 0);
+ if (shrink) { /* Shrinkable branch opcode? */
+ int lofs, lpos = b[pos];
+ if (lpos < 0) goto noshrink; /* Ext global? */
+ lofs = *DASM_POS2PTR(D, lpos);
+ if (lpos > pos) { /* Fwd label: add cumulative section offsets. */
+ int i;
+ for (i = secnum; i < DASM_POS2SEC(lpos); i++)
+ lofs += D->sections[i].ofs;
+ } else {
+ lofs -= ofs; /* Bkwd label: unfix offset. */
+ }
+ lofs -= b[pos+1]; /* Short branch ok? */
+ if (lofs >= -128-shrink && lofs <= 127) ofs -= shrink; /* Yes. */
+ else { noshrink: shrink = 0; } /* No, cannot shrink op. */
+ }
+ b[pos+1] = shrink;
+ pos += 2;
+ break;
+ }
+ /* fallthrough */
+ case DASM_SPACE: case DASM_IMM_LG: case DASM_VREG: p++;
+ /* fallthrough */
+ case DASM_DISP: case DASM_IMM_S: case DASM_IMM_B: case DASM_IMM_W:
+ case DASM_IMM_D: case DASM_IMM_WB: case DASM_IMM_DB:
+ case DASM_SETLABEL: case DASM_REL_A: case DASM_IMM_PC: pos++; break;
+ case DASM_LABEL_LG: p++;
+ /* fallthrough */
+ case DASM_LABEL_PC: b[pos++] += ofs; break; /* Fix label offset. */
+ case DASM_ALIGN: ofs -= (b[pos++]+ofs)&*p++; break; /* Adjust ofs. */
+ case DASM_EXTERN: p += 2; break;
+ case DASM_ESC: p++; break;
+ case DASM_MARK: break;
+ case DASM_SECTION: case DASM_STOP: goto stop;
+ }
+ }
+ stop: (void)0;
+ }
+ ofs += sec->ofs; /* Next section starts right after current section. */
+ }
+
+ D->codesize = ofs; /* Total size of all code sections */
+ *szp = ofs;
+ return DASM_S_OK;
+}
+
+#define dasmb(x) *cp++ = (unsigned char)(x)
+#ifndef DASM_ALIGNED_WRITES
+#define dasmw(x) \
+ do { *((unsigned short *)cp) = (unsigned short)(x); cp+=2; } while (0)
+#define dasmd(x) \
+ do { *((unsigned int *)cp) = (unsigned int)(x); cp+=4; } while (0)
+#else
+#define dasmw(x) do { dasmb(x); dasmb((x)>>8); } while (0)
+#define dasmd(x) do { dasmw(x); dasmw((x)>>16); } while (0)
+#endif
+
+/* Pass 3: Encode sections. */
+int dasm_encode(Dst_DECL, void *buffer)
+{
+ dasm_State *D = Dst_REF;
+ unsigned char *base = (unsigned char *)buffer;
+ unsigned char *cp = base;
+ int secnum;
+
+ /* Encode all code sections. No support for data sections (yet). */
+ for (secnum = 0; secnum < D->maxsection; secnum++) {
+ dasm_Section *sec = D->sections + secnum;
+ int *b = sec->buf;
+ int *endb = sec->rbuf + sec->pos;
+
+ while (b != endb) {
+ dasm_ActList p = D->actionlist + *b++;
+ unsigned char *mark = NULL;
+ while (1) {
+ int action = *p++;
+ int n = (action >= DASM_DISP && action <= DASM_ALIGN) ? *b++ : 0;
+ switch (action) {
+ case DASM_DISP: if (!mark) mark = cp; {
+ unsigned char *mm = mark;
+ if (*p != DASM_IMM_DB && *p != DASM_IMM_WB) mark = NULL;
+ if (n == 0) { int mrm = mm[-1]&7; if (mrm == 4) mrm = mm[0]&7;
+ if (mrm != 5) { mm[-1] -= 0x80; break; } }
+ if (((n+128) & -256) != 0) goto wd; else mm[-1] -= 0x40;
+ }
+ /* fallthrough */
+ case DASM_IMM_S: case DASM_IMM_B: wb: dasmb(n); break;
+ case DASM_IMM_DB: if (((n+128)&-256) == 0) {
+ db: if (!mark) mark = cp; mark[-2] += 2; mark = NULL; goto wb;
+ } else mark = NULL;
+ /* fallthrough */
+ case DASM_IMM_D: wd: dasmd(n); break;
+ case DASM_IMM_WB: if (((n+128)&-256) == 0) goto db; else mark = NULL;
+ /* fallthrough */
+ case DASM_IMM_W: dasmw(n); break;
+ case DASM_VREG: { int t = *p++; if (t >= 2) n<<=3; cp[-1] |= n; break; }
+ case DASM_REL_LG: p++; if (n >= 0) goto rel_pc;
+ b++; n = (int)(ptrdiff_t)D->globals[-n];
+ /* fallthrough */
+ case DASM_REL_A: rel_a:
+ n -= (unsigned int)(ptrdiff_t)(cp+4); goto wd; /* !x64 */
+ case DASM_REL_PC: rel_pc: {
+ int shrink = *b++;
+ int *pb = DASM_POS2PTR(D, n); if (*pb < 0) { n = pb[1]; goto rel_a; }
+ n = *pb - ((int)(cp-base) + 4-shrink);
+ if (shrink == 0) goto wd;
+ if (shrink == 4) { cp--; cp[-1] = *cp-0x10; } else cp[-1] = 0xeb;
+ goto wb;
+ }
+ case DASM_IMM_LG:
+ p++; if (n < 0) { n = (int)(ptrdiff_t)D->globals[-n]; goto wd; }
+ /* fallthrough */
+ case DASM_IMM_PC: {
+ int *pb = DASM_POS2PTR(D, n);
+ n = *pb < 0 ? pb[1] : (*pb + (int)(ptrdiff_t)base);
+ goto wd;
+ }
+ case DASM_LABEL_LG: {
+ int idx = *p++;
+ if (idx >= 10)
+ D->globals[idx] = (void *)(base + (*p == DASM_SETLABEL ? *b : n));
+ break;
+ }
+ case DASM_LABEL_PC: case DASM_SETLABEL: break;
+ case DASM_SPACE: { int fill = *p++; while (n--) *cp++ = fill; break; }
+ case DASM_ALIGN:
+ n = *p++;
+ while (((cp-base) & n)) *cp++ = 0x90; /* nop */
+ break;
+ case DASM_EXTERN: n = DASM_EXTERN(Dst, cp, p[1], *p); p += 2; goto wd;
+ case DASM_MARK: mark = cp; break;
+ case DASM_ESC: action = *p++;
+ /* fallthrough */
+ default: *cp++ = action; break;
+ case DASM_SECTION: case DASM_STOP: goto stop;
+ }
+ }
+ stop: (void)0;
+ }
+ }
+
+ if (base + D->codesize != cp) /* Check for phase errors. */
+ return DASM_S_PHASE;
+ return DASM_S_OK;
+}
+
+/* Get PC label offset. */
+int dasm_getpclabel(Dst_DECL, unsigned int pc)
+{
+ dasm_State *D = Dst_REF;
+ if (pc*sizeof(int) < D->pcsize) {
+ int pos = D->pclabels[pc];
+ if (pos < 0) return *DASM_POS2PTR(D, -pos);
+ if (pos > 0) return -1; /* Undefined. */
+ }
+ return -2; /* Unused or out of range. */
+}
+
+#ifdef DASM_CHECKS
+/* Optional sanity checker to call between isolated encoding steps. */
+int dasm_checkstep(Dst_DECL, int secmatch)
+{
+ dasm_State *D = Dst_REF;
+ if (D->status == DASM_S_OK) {
+ int i;
+ for (i = 1; i <= 9; i++) {
+ if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_L|i; break; }
+ D->lglabels[i] = 0;
+ }
+ }
+ if (D->status == DASM_S_OK && secmatch >= 0 &&
+ D->section != &D->sections[secmatch])
+ D->status = DASM_S_MATCH_SEC|(int)(D->section-D->sections);
+ return D->status;
+}
+#endif
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_x86.lua b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_x86.lua
new file mode 100644
index 0000000..21c2086
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/dynasm/dasm_x86.lua
@@ -0,0 +1,1946 @@
+------------------------------------------------------------------------------
+-- DynASM x86/x64 module.
+--
+-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+-- See dynasm.lua for full copyright notice.
+------------------------------------------------------------------------------
+
+local x64 = x64
+
+-- Module information:
+local _info = {
+ arch = x64 and "x64" or "x86",
+ description = "DynASM x86/x64 module",
+ version = "1.3.0",
+ vernum = 10300,
+ release = "2011-05-05",
+ author = "Mike Pall",
+ license = "MIT",
+}
+
+-- Exported glue functions for the arch-specific module.
+local _M = { _info = _info }
+
+-- Cache library functions.
+local type, tonumber, pairs, ipairs = type, tonumber, pairs, ipairs
+local assert, unpack, setmetatable = assert, unpack or table.unpack, setmetatable
+local _s = string
+local sub, format, byte, char = _s.sub, _s.format, _s.byte, _s.char
+local find, match, gmatch, gsub = _s.find, _s.match, _s.gmatch, _s.gsub
+local concat, sort = table.concat, table.sort
+local bit = bit or require("bit")
+local band, shl, shr = bit.band, bit.lshift, bit.rshift
+
+-- Inherited tables and callbacks.
+local g_opt, g_arch
+local wline, werror, wfatal, wwarn
+
+-- Action name list.
+-- CHECK: Keep this in sync with the C code!
+local action_names = {
+ -- int arg, 1 buffer pos:
+ "DISP", "IMM_S", "IMM_B", "IMM_W", "IMM_D", "IMM_WB", "IMM_DB",
+ -- action arg (1 byte), int arg, 1 buffer pos (reg/num):
+ "VREG", "SPACE", -- !x64: VREG support NYI.
+ -- ptrdiff_t arg, 1 buffer pos (address): !x64
+ "SETLABEL", "REL_A",
+ -- action arg (1 byte) or int arg, 2 buffer pos (link, offset):
+ "REL_LG", "REL_PC",
+ -- action arg (1 byte) or int arg, 1 buffer pos (link):
+ "IMM_LG", "IMM_PC",
+ -- action arg (1 byte) or int arg, 1 buffer pos (offset):
+ "LABEL_LG", "LABEL_PC",
+ -- action arg (1 byte), 1 buffer pos (offset):
+ "ALIGN",
+ -- action args (2 bytes), no buffer pos.
+ "EXTERN",
+ -- action arg (1 byte), no buffer pos.
+ "ESC",
+ -- no action arg, no buffer pos.
+ "MARK",
+ -- action arg (1 byte), no buffer pos, terminal action:
+ "SECTION",
+ -- no args, no buffer pos, terminal action:
+ "STOP"
+}
+
+-- Maximum number of section buffer positions for dasm_put().
+-- CHECK: Keep this in sync with the C code!
+local maxsecpos = 25 -- Keep this low, to avoid excessively long C lines.
+
+-- Action name -> action number (dynamically generated below).
+local map_action = {}
+-- First action number. Everything below does not need to be escaped.
+local actfirst = 256-#action_names
+
+-- Action list buffer and string (only used to remove dupes).
+local actlist = {}
+local actstr = ""
+
+-- Argument list for next dasm_put(). Start with offset 0 into action list.
+local actargs = { 0 }
+
+-- Current number of section buffer positions for dasm_put().
+local secpos = 1
+
+------------------------------------------------------------------------------
+
+-- Compute action numbers for action names.
+for n,name in ipairs(action_names) do
+ local num = actfirst + n - 1
+ map_action[name] = num
+end
+
+-- Dump action names and numbers.
+local function dumpactions(out)
+ out:write("DynASM encoding engine action codes:\n")
+ for n,name in ipairs(action_names) do
+ local num = map_action[name]
+ out:write(format(" %-10s %02X %d\n", name, num, num))
+ end
+ out:write("\n")
+end
+
+-- Write action list buffer as a huge static C array.
+local function writeactions(out, name)
+ local nn = #actlist
+ local last = actlist[nn] or 255
+ actlist[nn] = nil -- Remove last byte.
+ if nn == 0 then nn = 1 end
+ out:write("static const unsigned char ", name, "[", nn, "] = {\n")
+ local s = " "
+ for n,b in ipairs(actlist) do
+ s = s..b..","
+ if #s >= 75 then
+ assert(out:write(s, "\n"))
+ s = " "
+ end
+ end
+ out:write(s, last, "\n};\n\n") -- Add last byte back.
+end
+
+------------------------------------------------------------------------------
+
+-- Add byte to action list.
+local function wputxb(n)
+ assert(n >= 0 and n <= 255 and n % 1 == 0, "byte out of range")
+ actlist[#actlist+1] = n
+end
+
+-- Add action to list with optional arg. Advance buffer pos, too.
+local function waction(action, a, num)
+ wputxb(assert(map_action[action], "bad action name `"..action.."'"))
+ if a then actargs[#actargs+1] = a end
+ if a or num then secpos = secpos + (num or 1) end
+end
+
+-- Add call to embedded DynASM C code.
+local function wcall(func, args)
+ wline(format("dasm_%s(Dst, %s);", func, concat(args, ", ")), true)
+end
+
+-- Delete duplicate action list chunks. A tad slow, but so what.
+local function dedupechunk(offset)
+ local al, as = actlist, actstr
+ local chunk = char(unpack(al, offset+1, #al))
+ local orig = find(as, chunk, 1, true)
+ if orig then
+ actargs[1] = orig-1 -- Replace with original offset.
+ for i=offset+1,#al do al[i] = nil end -- Kill dupe.
+ else
+ actstr = as..chunk
+ end
+end
+
+-- Flush action list (intervening C code or buffer pos overflow).
+local function wflush(term)
+ local offset = actargs[1]
+ if #actlist == offset then return end -- Nothing to flush.
+ if not term then waction("STOP") end -- Terminate action list.
+ dedupechunk(offset)
+ wcall("put", actargs) -- Add call to dasm_put().
+ actargs = { #actlist } -- Actionlist offset is 1st arg to next dasm_put().
+ secpos = 1 -- The actionlist offset occupies a buffer position, too.
+end
+
+-- Put escaped byte.
+local function wputb(n)
+ if n >= actfirst then waction("ESC") end -- Need to escape byte.
+ wputxb(n)
+end
+
+------------------------------------------------------------------------------
+
+-- Global label name -> global label number. With auto assignment on 1st use.
+local next_global = 10
+local map_global = setmetatable({}, { __index = function(t, name)
+ if not match(name, "^[%a_][%w_@]*$") then werror("bad global label") end
+ local n = next_global
+ if n > 246 then werror("too many global labels") end
+ next_global = n + 1
+ t[name] = n
+ return n
+end})
+
+-- Dump global labels.
+local function dumpglobals(out, lvl)
+ local t = {}
+ for name, n in pairs(map_global) do t[n] = name end
+ out:write("Global labels:\n")
+ for i=10,next_global-1 do
+ out:write(format(" %s\n", t[i]))
+ end
+ out:write("\n")
+end
+
+-- Write global label enum.
+local function writeglobals(out, prefix)
+ local t = {}
+ for name, n in pairs(map_global) do t[n] = name end
+ out:write("enum {\n")
+ for i=10,next_global-1 do
+ out:write(" ", prefix, gsub(t[i], "@.*", ""), ",\n")
+ end
+ out:write(" ", prefix, "_MAX\n};\n")
+end
+
+-- Write global label names.
+local function writeglobalnames(out, name)
+ local t = {}
+ for name, n in pairs(map_global) do t[n] = name end
+ out:write("static const char *const ", name, "[] = {\n")
+ for i=10,next_global-1 do
+ out:write(" \"", t[i], "\",\n")
+ end
+ out:write(" (const char *)0\n};\n")
+end
+
+------------------------------------------------------------------------------
+
+-- Extern label name -> extern label number. With auto assignment on 1st use.
+local next_extern = -1
+local map_extern = setmetatable({}, { __index = function(t, name)
+ -- No restrictions on the name for now.
+ local n = next_extern
+ if n < -256 then werror("too many extern labels") end
+ next_extern = n - 1
+ t[name] = n
+ return n
+end})
+
+-- Dump extern labels.
+local function dumpexterns(out, lvl)
+ local t = {}
+ for name, n in pairs(map_extern) do t[-n] = name end
+ out:write("Extern labels:\n")
+ for i=1,-next_extern-1 do
+ out:write(format(" %s\n", t[i]))
+ end
+ out:write("\n")
+end
+
+-- Write extern label names.
+local function writeexternnames(out, name)
+ local t = {}
+ for name, n in pairs(map_extern) do t[-n] = name end
+ out:write("static const char *const ", name, "[] = {\n")
+ for i=1,-next_extern-1 do
+ out:write(" \"", t[i], "\",\n")
+ end
+ out:write(" (const char *)0\n};\n")
+end
+
+------------------------------------------------------------------------------
+
+-- Arch-specific maps.
+local map_archdef = {} -- Ext. register name -> int. name.
+local map_reg_rev = {} -- Int. register name -> ext. name.
+local map_reg_num = {} -- Int. register name -> register number.
+local map_reg_opsize = {} -- Int. register name -> operand size.
+local map_reg_valid_base = {} -- Int. register name -> valid base register?
+local map_reg_valid_index = {} -- Int. register name -> valid index register?
+local map_reg_needrex = {} -- Int. register name -> need rex vs. no rex.
+local reg_list = {} -- Canonical list of int. register names.
+
+local map_type = {} -- Type name -> { ctype, reg }
+local ctypenum = 0 -- Type number (for _PTx macros).
+
+local addrsize = x64 and "q" or "d" -- Size for address operands.
+
+-- Helper functions to fill register maps.
+local function mkrmap(sz, cl, names)
+ local cname = format("@%s", sz)
+ reg_list[#reg_list+1] = cname
+ map_archdef[cl] = cname
+ map_reg_rev[cname] = cl
+ map_reg_num[cname] = -1
+ map_reg_opsize[cname] = sz
+ if sz == addrsize or sz == "d" then
+ map_reg_valid_base[cname] = true
+ map_reg_valid_index[cname] = true
+ end
+ if names then
+ for n,name in ipairs(names) do
+ local iname = format("@%s%x", sz, n-1)
+ reg_list[#reg_list+1] = iname
+ map_archdef[name] = iname
+ map_reg_rev[iname] = name
+ map_reg_num[iname] = n-1
+ map_reg_opsize[iname] = sz
+ if sz == "b" and n > 4 then map_reg_needrex[iname] = false end
+ if sz == addrsize or sz == "d" then
+ map_reg_valid_base[iname] = true
+ map_reg_valid_index[iname] = true
+ end
+ end
+ end
+ for i=0,(x64 and sz ~= "f") and 15 or 7 do
+ local needrex = sz == "b" and i > 3
+ local iname = format("@%s%x%s", sz, i, needrex and "R" or "")
+ if needrex then map_reg_needrex[iname] = true end
+ local name
+ if sz == "o" then name = format("xmm%d", i)
+ elseif sz == "f" then name = format("st%d", i)
+ else name = format("r%d%s", i, sz == addrsize and "" or sz) end
+ map_archdef[name] = iname
+ if not map_reg_rev[iname] then
+ reg_list[#reg_list+1] = iname
+ map_reg_rev[iname] = name
+ map_reg_num[iname] = i
+ map_reg_opsize[iname] = sz
+ if sz == addrsize or sz == "d" then
+ map_reg_valid_base[iname] = true
+ map_reg_valid_index[iname] = true
+ end
+ end
+ end
+ reg_list[#reg_list+1] = ""
+end
+
+-- Integer registers (qword, dword, word and byte sized).
+if x64 then
+ mkrmap("q", "Rq", {"rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi"})
+end
+mkrmap("d", "Rd", {"eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi"})
+mkrmap("w", "Rw", {"ax", "cx", "dx", "bx", "sp", "bp", "si", "di"})
+mkrmap("b", "Rb", {"al", "cl", "dl", "bl", "ah", "ch", "dh", "bh"})
+map_reg_valid_index[map_archdef.esp] = false
+if x64 then map_reg_valid_index[map_archdef.rsp] = false end
+map_archdef["Ra"] = "@"..addrsize
+
+-- FP registers (internally tword sized, but use "f" as operand size).
+mkrmap("f", "Rf")
+
+-- SSE registers (oword sized, but qword and dword accessible).
+mkrmap("o", "xmm")
+
+-- Operand size prefixes to codes.
+local map_opsize = {
+ byte = "b", word = "w", dword = "d", qword = "q", oword = "o", tword = "t",
+ aword = addrsize,
+}
+
+-- Operand size code to number.
+local map_opsizenum = {
+ b = 1, w = 2, d = 4, q = 8, o = 16, t = 10,
+}
+
+-- Operand size code to name.
+local map_opsizename = {
+ b = "byte", w = "word", d = "dword", q = "qword", o = "oword", t = "tword",
+ f = "fpword",
+}
+
+-- Valid index register scale factors.
+local map_xsc = {
+ ["1"] = 0, ["2"] = 1, ["4"] = 2, ["8"] = 3,
+}
+
+-- Condition codes.
+local map_cc = {
+ o = 0, no = 1, b = 2, nb = 3, e = 4, ne = 5, be = 6, nbe = 7,
+ s = 8, ns = 9, p = 10, np = 11, l = 12, nl = 13, le = 14, nle = 15,
+ c = 2, nae = 2, nc = 3, ae = 3, z = 4, nz = 5, na = 6, a = 7,
+ pe = 10, po = 11, nge = 12, ge = 13, ng = 14, g = 15,
+}
+
+
+-- Reverse defines for registers.
+function _M.revdef(s)
+ return gsub(s, "@%w+", map_reg_rev)
+end
+
+-- Dump register names and numbers
+local function dumpregs(out)
+ out:write("Register names, sizes and internal numbers:\n")
+ for _,reg in ipairs(reg_list) do
+ if reg == "" then
+ out:write("\n")
+ else
+ local name = map_reg_rev[reg]
+ local num = map_reg_num[reg]
+ local opsize = map_opsizename[map_reg_opsize[reg]]
+ out:write(format(" %-5s %-8s %s\n", name, opsize,
+ num < 0 and "(variable)" or num))
+ end
+ end
+end
+
+------------------------------------------------------------------------------
+
+-- Put action for label arg (IMM_LG, IMM_PC, REL_LG, REL_PC).
+local function wputlabel(aprefix, imm, num)
+ if type(imm) == "number" then
+ if imm < 0 then
+ waction("EXTERN")
+ wputxb(aprefix == "IMM_" and 0 or 1)
+ imm = -imm-1
+ else
+ waction(aprefix.."LG", nil, num);
+ end
+ wputxb(imm)
+ else
+ waction(aprefix.."PC", imm, num)
+ end
+end
+
+-- Put signed byte or arg.
+local function wputsbarg(n)
+ if type(n) == "number" then
+ if n < -128 or n > 127 then
+ werror("signed immediate byte out of range")
+ end
+ if n < 0 then n = n + 256 end
+ wputb(n)
+ else waction("IMM_S", n) end
+end
+
+-- Put unsigned byte or arg.
+local function wputbarg(n)
+ if type(n) == "number" then
+ if n < 0 or n > 255 then
+ werror("unsigned immediate byte out of range")
+ end
+ wputb(n)
+ else waction("IMM_B", n) end
+end
+
+-- Put unsigned word or arg.
+local function wputwarg(n)
+ if type(n) == "number" then
+ if shr(n, 16) ~= 0 then
+ werror("unsigned immediate word out of range")
+ end
+ wputb(band(n, 255)); wputb(shr(n, 8));
+ else waction("IMM_W", n) end
+end
+
+-- Put signed or unsigned dword or arg.
+local function wputdarg(n)
+ local tn = type(n)
+ if tn == "number" then
+ wputb(band(n, 255))
+ wputb(band(shr(n, 8), 255))
+ wputb(band(shr(n, 16), 255))
+ wputb(shr(n, 24))
+ elseif tn == "table" then
+ wputlabel("IMM_", n[1], 1)
+ else
+ waction("IMM_D", n)
+ end
+end
+
+-- Put operand-size dependent number or arg (defaults to dword).
+local function wputszarg(sz, n)
+ if not sz or sz == "d" or sz == "q" then wputdarg(n)
+ elseif sz == "w" then wputwarg(n)
+ elseif sz == "b" then wputbarg(n)
+ elseif sz == "s" then wputsbarg(n)
+ else werror("bad operand size") end
+end
+
+-- Put multi-byte opcode with operand-size dependent modifications.
+local function wputop(sz, op, rex)
+ local r
+ if rex ~= 0 and not x64 then werror("bad operand size") end
+ if sz == "w" then wputb(102) end
+ -- Needs >32 bit numbers, but only for crc32 eax, word [ebx]
+ if op >= 4294967296 then r = op%4294967296 wputb((op-r)/4294967296) op = r end
+ if op >= 16777216 then wputb(shr(op, 24)); op = band(op, 0xffffff) end
+ if op >= 65536 then
+ if rex ~= 0 then
+ local opc3 = band(op, 0xffff00)
+ if opc3 == 0x0f3a00 or opc3 == 0x0f3800 then
+ wputb(64 + band(rex, 15)); rex = 0
+ end
+ end
+ wputb(shr(op, 16)); op = band(op, 0xffff)
+ end
+ if op >= 256 then
+ local b = shr(op, 8)
+ if b == 15 and rex ~= 0 then wputb(64 + band(rex, 15)); rex = 0 end
+ wputb(b)
+ op = band(op, 255)
+ end
+ if rex ~= 0 then wputb(64 + band(rex, 15)) end
+ if sz == "b" then op = op - 1 end
+ wputb(op)
+end
+
+-- Put ModRM or SIB formatted byte.
+local function wputmodrm(m, s, rm, vs, vrm)
+ assert(m < 4 and s < 16 and rm < 16, "bad modrm operands")
+ wputb(shl(m, 6) + shl(band(s, 7), 3) + band(rm, 7))
+end
+
+-- Put ModRM/SIB plus optional displacement.
+local function wputmrmsib(t, imark, s, vsreg)
+ local vreg, vxreg
+ local reg, xreg = t.reg, t.xreg
+ if reg and reg < 0 then reg = 0; vreg = t.vreg end
+ if xreg and xreg < 0 then xreg = 0; vxreg = t.vxreg end
+ if s < 0 then s = 0 end
+
+ -- Register mode.
+ if sub(t.mode, 1, 1) == "r" then
+ wputmodrm(3, s, reg)
+ if vsreg then waction("VREG", vsreg); wputxb(2) end
+ if vreg then waction("VREG", vreg); wputxb(0) end
+ return
+ end
+
+ local disp = t.disp
+ local tdisp = type(disp)
+ -- No base register?
+ if not reg then
+ local riprel = false
+ if xreg then
+ -- Indexed mode with index register only.
+ -- [xreg*xsc+disp] -> (0, s, esp) (xsc, xreg, ebp)
+ wputmodrm(0, s, 4)
+ if imark == "I" then waction("MARK") end
+ if vsreg then waction("VREG", vsreg); wputxb(2) end
+ wputmodrm(t.xsc, xreg, 5)
+ if vxreg then waction("VREG", vxreg); wputxb(3) end
+ else
+ -- Pure 32 bit displacement.
+ if x64 and tdisp ~= "table" then
+ wputmodrm(0, s, 4) -- [disp] -> (0, s, esp) (0, esp, ebp)
+ if imark == "I" then waction("MARK") end
+ wputmodrm(0, 4, 5)
+ else
+ riprel = x64
+ wputmodrm(0, s, 5) -- [disp|rip-label] -> (0, s, ebp)
+ if imark == "I" then waction("MARK") end
+ end
+ if vsreg then waction("VREG", vsreg); wputxb(2) end
+ end
+ if riprel then -- Emit rip-relative displacement.
+ if match("UWSiI", imark) then
+ werror("NYI: rip-relative displacement followed by immediate")
+ end
+ -- The previous byte in the action buffer cannot be 0xe9 or 0x80-0x8f.
+ wputlabel("REL_", disp[1], 2)
+ else
+ wputdarg(disp)
+ end
+ return
+ end
+
+ local m
+ if tdisp == "number" then -- Check displacement size at assembly time.
+ if disp == 0 and band(reg, 7) ~= 5 then -- [ebp] -> [ebp+0] (in SIB, too)
+ if not vreg then m = 0 end -- Force DISP to allow [Rd(5)] -> [ebp+0]
+ elseif disp >= -128 and disp <= 127 then m = 1
+ else m = 2 end
+ elseif tdisp == "table" then
+ m = 2
+ end
+
+ -- Index register present or esp as base register: need SIB encoding.
+ if xreg or band(reg, 7) == 4 then
+ wputmodrm(m or 2, s, 4) -- ModRM.
+ if m == nil or imark == "I" then waction("MARK") end
+ if vsreg then waction("VREG", vsreg); wputxb(2) end
+ wputmodrm(t.xsc or 0, xreg or 4, reg) -- SIB.
+ if vxreg then waction("VREG", vxreg); wputxb(3) end
+ if vreg then waction("VREG", vreg); wputxb(1) end
+ else
+ wputmodrm(m or 2, s, reg) -- ModRM.
+ if (imark == "I" and (m == 1 or m == 2)) or
+ (m == nil and (vsreg or vreg)) then waction("MARK") end
+ if vsreg then waction("VREG", vsreg); wputxb(2) end
+ if vreg then waction("VREG", vreg); wputxb(1) end
+ end
+
+ -- Put displacement.
+ if m == 1 then wputsbarg(disp)
+ elseif m == 2 then wputdarg(disp)
+ elseif m == nil then waction("DISP", disp) end
+end
+
+------------------------------------------------------------------------------
+
+-- Return human-readable operand mode string.
+local function opmodestr(op, args)
+ local m = {}
+ for i=1,#args do
+ local a = args[i]
+ m[#m+1] = sub(a.mode, 1, 1)..(a.opsize or "?")
+ end
+ return op.." "..concat(m, ",")
+end
+
+-- Convert number to valid integer or nil.
+local function toint(expr)
+ local n = tonumber(expr)
+ if n then
+ if n % 1 ~= 0 or n < -2147483648 or n > 4294967295 then
+ werror("bad integer number `"..expr.."'")
+ end
+ return n
+ end
+end
+
+-- Parse immediate expression.
+local function immexpr(expr)
+ -- &expr (pointer)
+ if sub(expr, 1, 1) == "&" then
+ return "iPJ", format("(ptrdiff_t)(%s)", sub(expr,2))
+ end
+
+ local prefix = sub(expr, 1, 2)
+ -- =>expr (pc label reference)
+ if prefix == "=>" then
+ return "iJ", sub(expr, 3)
+ end
+ -- ->name (global label reference)
+ if prefix == "->" then
+ return "iJ", map_global[sub(expr, 3)]
+ end
+
+ -- [<>][1-9] (local label reference)
+ local dir, lnum = match(expr, "^([<>])([1-9])$")
+ if dir then -- Fwd: 247-255, Bkwd: 1-9.
+ return "iJ", lnum + (dir == ">" and 246 or 0)
+ end
+
+ local extname = match(expr, "^extern%s+(%S+)$")
+ if extname then
+ return "iJ", map_extern[extname]
+ end
+
+ -- expr (interpreted as immediate)
+ return "iI", expr
+end
+
+-- Parse displacement expression: +-num, +-expr, +-opsize*num
+local function dispexpr(expr)
+ local disp = expr == "" and 0 or toint(expr)
+ if disp then return disp end
+ local c, dispt = match(expr, "^([+-])%s*(.+)$")
+ if c == "+" then
+ expr = dispt
+ elseif not c then
+ werror("bad displacement expression `"..expr.."'")
+ end
+ local opsize, tailops = match(dispt, "^(%w+)%s*%*%s*(.+)$")
+ local ops, imm = map_opsize[opsize], toint(tailops)
+ if ops and imm then
+ if c == "-" then imm = -imm end
+ return imm*map_opsizenum[ops]
+ end
+ local mode, iexpr = immexpr(dispt)
+ if mode == "iJ" then
+ if c == "-" then werror("cannot invert label reference") end
+ return { iexpr }
+ end
+ return expr -- Need to return original signed expression.
+end
+
+-- Parse register or type expression.
+local function rtexpr(expr)
+ if not expr then return end
+ local tname, ovreg = match(expr, "^([%w_]+):(@[%w_]+)$")
+ local tp = map_type[tname or expr]
+ if tp then
+ local reg = ovreg or tp.reg
+ local rnum = map_reg_num[reg]
+ if not rnum then
+ werror("type `"..(tname or expr).."' needs a register override")
+ end
+ if not map_reg_valid_base[reg] then
+ werror("bad base register override `"..(map_reg_rev[reg] or reg).."'")
+ end
+ return reg, rnum, tp
+ end
+ return expr, map_reg_num[expr]
+end
+
+-- Parse operand and return { mode, opsize, reg, xreg, xsc, disp, imm }.
+local function parseoperand(param)
+ local t = {}
+
+ local expr = param
+ local opsize, tailops = match(param, "^(%w+)%s*(.+)$")
+ if opsize then
+ t.opsize = map_opsize[opsize]
+ if t.opsize then expr = tailops end
+ end
+
+ local br = match(expr, "^%[%s*(.-)%s*%]$")
+ repeat
+ if br then
+ t.mode = "xm"
+
+ -- [disp]
+ t.disp = toint(br)
+ if t.disp then
+ t.mode = x64 and "xm" or "xmO"
+ break
+ end
+
+ -- [reg...]
+ local tp
+ local reg, tailr = match(br, "^([@%w_:]+)%s*(.*)$")
+ reg, t.reg, tp = rtexpr(reg)
+ if not t.reg then
+ -- [expr]
+ t.mode = x64 and "xm" or "xmO"
+ t.disp = dispexpr("+"..br)
+ break
+ end
+
+ if t.reg == -1 then
+ t.vreg, tailr = match(tailr, "^(%b())(.*)$")
+ if not t.vreg then werror("bad variable register expression") end
+ end
+
+ -- [xreg*xsc] or [xreg*xsc+-disp] or [xreg*xsc+-expr]
+ local xsc, tailsc = match(tailr, "^%*%s*([1248])%s*(.*)$")
+ if xsc then
+ if not map_reg_valid_index[reg] then
+ werror("bad index register `"..map_reg_rev[reg].."'")
+ end
+ t.xsc = map_xsc[xsc]
+ t.xreg = t.reg
+ t.vxreg = t.vreg
+ t.reg = nil
+ t.vreg = nil
+ t.disp = dispexpr(tailsc)
+ break
+ end
+ if not map_reg_valid_base[reg] then
+ werror("bad base register `"..map_reg_rev[reg].."'")
+ end
+
+ -- [reg] or [reg+-disp]
+ t.disp = toint(tailr) or (tailr == "" and 0)
+ if t.disp then break end
+
+ -- [reg+xreg...]
+ local xreg, tailx = match(tailr, "^+%s*([@%w_:]+)%s*(.*)$")
+ xreg, t.xreg, tp = rtexpr(xreg)
+ if not t.xreg then
+ -- [reg+-expr]
+ t.disp = dispexpr(tailr)
+ break
+ end
+ if not map_reg_valid_index[xreg] then
+ werror("bad index register `"..map_reg_rev[xreg].."'")
+ end
+
+ if t.xreg == -1 then
+ t.vxreg, tailx = match(tailx, "^(%b())(.*)$")
+ if not t.vxreg then werror("bad variable register expression") end
+ end
+
+ -- [reg+xreg*xsc...]
+ local xsc, tailsc = match(tailx, "^%*%s*([1248])%s*(.*)$")
+ if xsc then
+ t.xsc = map_xsc[xsc]
+ tailx = tailsc
+ end
+
+ -- [...] or [...+-disp] or [...+-expr]
+ t.disp = dispexpr(tailx)
+ else
+ -- imm or opsize*imm
+ local imm = toint(expr)
+ if not imm and sub(expr, 1, 1) == "*" and t.opsize then
+ imm = toint(sub(expr, 2))
+ if imm then
+ imm = imm * map_opsizenum[t.opsize]
+ t.opsize = nil
+ end
+ end
+ if imm then
+ if t.opsize then werror("bad operand size override") end
+ local m = "i"
+ if imm == 1 then m = m.."1" end
+ if imm >= 4294967168 and imm <= 4294967295 then imm = imm-4294967296 end
+ if imm >= -128 and imm <= 127 then m = m.."S" end
+ t.imm = imm
+ t.mode = m
+ break
+ end
+
+ local tp
+ local reg, tailr = match(expr, "^([@%w_:]+)%s*(.*)$")
+ reg, t.reg, tp = rtexpr(reg)
+ if t.reg then
+ if t.reg == -1 then
+ t.vreg, tailr = match(tailr, "^(%b())(.*)$")
+ if not t.vreg then werror("bad variable register expression") end
+ end
+ -- reg
+ if tailr == "" then
+ if t.opsize then werror("bad operand size override") end
+ t.opsize = map_reg_opsize[reg]
+ if t.opsize == "f" then
+ t.mode = t.reg == 0 and "fF" or "f"
+ else
+ if reg == "@w4" or (x64 and reg == "@d4") then
+ wwarn("bad idea, try again with `"..(x64 and "rsp'" or "esp'"))
+ end
+ t.mode = t.reg == 0 and "rmR" or (reg == "@b1" and "rmC" or "rm")
+ end
+ t.needrex = map_reg_needrex[reg]
+ break
+ end
+
+ -- type[idx], type[idx].field, type->field -> [reg+offset_expr]
+ if not tp then werror("bad operand `"..param.."'") end
+ t.mode = "xm"
+ t.disp = format(tp.ctypefmt, tailr)
+ else
+ t.mode, t.imm = immexpr(expr)
+ if sub(t.mode, -1) == "J" then
+ if t.opsize and t.opsize ~= addrsize then
+ werror("bad operand size override")
+ end
+ t.opsize = addrsize
+ end
+ end
+ end
+ until true
+ return t
+end
+
+------------------------------------------------------------------------------
+-- x86 Template String Description
+-- ===============================
+--
+-- Each template string is a list of [match:]pattern pairs,
+-- separated by "|". The first match wins. No match means a
+-- bad or unsupported combination of operand modes or sizes.
+--
+-- The match part and the ":" is omitted if the operation has
+-- no operands. Otherwise the first N characters are matched
+-- against the mode strings of each of the N operands.
+--
+-- The mode string for each operand type is (see parseoperand()):
+-- Integer register: "rm", +"R" for eax, ax, al, +"C" for cl
+-- FP register: "f", +"F" for st0
+-- Index operand: "xm", +"O" for [disp] (pure offset)
+-- Immediate: "i", +"S" for signed 8 bit, +"1" for 1,
+-- +"I" for arg, +"P" for pointer
+-- Any: +"J" for valid jump targets
+--
+-- So a match character "m" (mixed) matches both an integer register
+-- and an index operand (to be encoded with the ModRM/SIB scheme).
+-- But "r" matches only a register and "x" only an index operand
+-- (e.g. for FP memory access operations).
+--
+-- The operand size match string starts right after the mode match
+-- characters and ends before the ":". "dwb" or "qdwb" is assumed, if empty.
+-- The effective data size of the operation is matched against this list.
+--
+-- If only the regular "b", "w", "d", "q", "t" operand sizes are
+-- present, then all operands must be the same size. Unspecified sizes
+-- are ignored, but at least one operand must have a size or the pattern
+-- won't match (use the "byte", "word", "dword", "qword", "tword"
+-- operand size overrides. E.g.: mov dword [eax], 1).
+--
+-- If the list has a "1" or "2" prefix, the operand size is taken
+-- from the respective operand and any other operand sizes are ignored.
+-- If the list contains only ".", all operand sizes are ignored.
+-- If the list has a "/" prefix, the concatenated (mixed) operand sizes
+-- are compared to the match.
+--
+-- E.g. "rrdw" matches for either two dword registers or two word
+-- registers. "Fx2dq" matches an st0 operand plus an index operand
+-- pointing to a dword (float) or qword (double).
+--
+-- Every character after the ":" is part of the pattern string:
+-- Hex chars are accumulated to form the opcode (left to right).
+-- "n" disables the standard opcode mods
+-- (otherwise: -1 for "b", o16 prefix for "w", rex.w for "q")
+-- "X" Force REX.W.
+-- "r"/"R" adds the reg. number from the 1st/2nd operand to the opcode.
+-- "m"/"M" generates ModRM/SIB from the 1st/2nd operand.
+-- The spare 3 bits are either filled with the last hex digit or
+-- the result from a previous "r"/"R". The opcode is restored.
+--
+-- All of the following characters force a flush of the opcode:
+-- "o"/"O" stores a pure 32 bit disp (offset) from the 1st/2nd operand.
+-- "S" stores a signed 8 bit immediate from the last operand.
+-- "U" stores an unsigned 8 bit immediate from the last operand.
+-- "W" stores an unsigned 16 bit immediate from the last operand.
+-- "i" stores an operand sized immediate from the last operand.
+-- "I" dito, but generates an action code to optionally modify
+-- the opcode (+2) for a signed 8 bit immediate.
+-- "J" generates one of the REL action codes from the last operand.
+--
+------------------------------------------------------------------------------
+
+-- Template strings for x86 instructions. Ordered by first opcode byte.
+-- Unimplemented opcodes (deliberate omissions) are marked with *.
+local map_op = {
+ -- 00-05: add...
+ -- 06: *push es
+ -- 07: *pop es
+ -- 08-0D: or...
+ -- 0E: *push cs
+ -- 0F: two byte opcode prefix
+ -- 10-15: adc...
+ -- 16: *push ss
+ -- 17: *pop ss
+ -- 18-1D: sbb...
+ -- 1E: *push ds
+ -- 1F: *pop ds
+ -- 20-25: and...
+ es_0 = "26",
+ -- 27: *daa
+ -- 28-2D: sub...
+ cs_0 = "2E",
+ -- 2F: *das
+ -- 30-35: xor...
+ ss_0 = "36",
+ -- 37: *aaa
+ -- 38-3D: cmp...
+ ds_0 = "3E",
+ -- 3F: *aas
+ inc_1 = x64 and "m:FF0m" or "rdw:40r|m:FF0m",
+ dec_1 = x64 and "m:FF1m" or "rdw:48r|m:FF1m",
+ push_1 = (x64 and "rq:n50r|rw:50r|mq:nFF6m|mw:FF6m" or
+ "rdw:50r|mdw:FF6m").."|S.:6AS|ib:n6Ai|i.:68i",
+ pop_1 = x64 and "rq:n58r|rw:58r|mq:n8F0m|mw:8F0m" or "rdw:58r|mdw:8F0m",
+ -- 60: *pusha, *pushad, *pushaw
+ -- 61: *popa, *popad, *popaw
+ -- 62: *bound rdw,x
+ -- 63: x86: *arpl mw,rw
+ movsxd_2 = x64 and "rm/qd:63rM",
+ fs_0 = "64",
+ gs_0 = "65",
+ o16_0 = "66",
+ a16_0 = not x64 and "67" or nil,
+ a32_0 = x64 and "67",
+ -- 68: push idw
+ -- 69: imul rdw,mdw,idw
+ -- 6A: push ib
+ -- 6B: imul rdw,mdw,S
+ -- 6C: *insb
+ -- 6D: *insd, *insw
+ -- 6E: *outsb
+ -- 6F: *outsd, *outsw
+ -- 70-7F: jcc lb
+ -- 80: add... mb,i
+ -- 81: add... mdw,i
+ -- 82: *undefined
+ -- 83: add... mdw,S
+ test_2 = "mr:85Rm|rm:85rM|Ri:A9ri|mi:F70mi",
+ -- 86: xchg rb,mb
+ -- 87: xchg rdw,mdw
+ -- 88: mov mb,r
+ -- 89: mov mdw,r
+ -- 8A: mov r,mb
+ -- 8B: mov r,mdw
+ -- 8C: *mov mdw,seg
+ lea_2 = "rx1dq:8DrM",
+ -- 8E: *mov seg,mdw
+ -- 8F: pop mdw
+ nop_0 = "90",
+ xchg_2 = "Rrqdw:90R|rRqdw:90r|rm:87rM|mr:87Rm",
+ cbw_0 = "6698",
+ cwde_0 = "98",
+ cdqe_0 = "4898",
+ cwd_0 = "6699",
+ cdq_0 = "99",
+ cqo_0 = "4899",
+ -- 9A: *call iw:idw
+ wait_0 = "9B",
+ fwait_0 = "9B",
+ pushf_0 = "9C",
+ pushfd_0 = not x64 and "9C",
+ pushfq_0 = x64 and "9C",
+ popf_0 = "9D",
+ popfd_0 = not x64 and "9D",
+ popfq_0 = x64 and "9D",
+ sahf_0 = "9E",
+ lahf_0 = "9F",
+ mov_2 = "OR:A3o|RO:A1O|mr:89Rm|rm:8BrM|rib:nB0ri|ridw:B8ri|mi:C70mi",
+ movsb_0 = "A4",
+ movsw_0 = "66A5",
+ movsd_0 = "A5",
+ cmpsb_0 = "A6",
+ cmpsw_0 = "66A7",
+ cmpsd_0 = "A7",
+ -- A8: test Rb,i
+ -- A9: test Rdw,i
+ stosb_0 = "AA",
+ stosw_0 = "66AB",
+ stosd_0 = "AB",
+ lodsb_0 = "AC",
+ lodsw_0 = "66AD",
+ lodsd_0 = "AD",
+ scasb_0 = "AE",
+ scasw_0 = "66AF",
+ scasd_0 = "AF",
+ -- B0-B7: mov rb,i
+ -- B8-BF: mov rdw,i
+ -- C0: rol... mb,i
+ -- C1: rol... mdw,i
+ ret_1 = "i.:nC2W",
+ ret_0 = "C3",
+ -- C4: *les rdw,mq
+ -- C5: *lds rdw,mq
+ -- C6: mov mb,i
+ -- C7: mov mdw,i
+ -- C8: *enter iw,ib
+ leave_0 = "C9",
+ -- CA: *retf iw
+ -- CB: *retf
+ int3_0 = "CC",
+ int_1 = "i.:nCDU",
+ into_0 = "CE",
+ -- CF: *iret
+ -- D0: rol... mb,1
+ -- D1: rol... mdw,1
+ -- D2: rol... mb,cl
+ -- D3: rol... mb,cl
+ -- D4: *aam ib
+ -- D5: *aad ib
+ -- D6: *salc
+ -- D7: *xlat
+ -- D8-DF: floating point ops
+ -- E0: *loopne
+ -- E1: *loope
+ -- E2: *loop
+ -- E3: *jcxz, *jecxz
+ -- E4: *in Rb,ib
+ -- E5: *in Rdw,ib
+ -- E6: *out ib,Rb
+ -- E7: *out ib,Rdw
+ call_1 = x64 and "mq:nFF2m|J.:E8nJ" or "md:FF2m|J.:E8J",
+ jmp_1 = x64 and "mq:nFF4m|J.:E9nJ" or "md:FF4m|J.:E9J", -- short: EB
+ -- EA: *jmp iw:idw
+ -- EB: jmp ib
+ -- EC: *in Rb,dx
+ -- ED: *in Rdw,dx
+ -- EE: *out dx,Rb
+ -- EF: *out dx,Rdw
+ lock_0 = "F0",
+ int1_0 = "F1",
+ repne_0 = "F2",
+ repnz_0 = "F2",
+ rep_0 = "F3",
+ repe_0 = "F3",
+ repz_0 = "F3",
+ -- F4: *hlt
+ cmc_0 = "F5",
+ -- F6: test... mb,i; div... mb
+ -- F7: test... mdw,i; div... mdw
+ clc_0 = "F8",
+ stc_0 = "F9",
+ -- FA: *cli
+ cld_0 = "FC",
+ std_0 = "FD",
+ -- FE: inc... mb
+ -- FF: inc... mdw
+
+ -- misc ops
+ not_1 = "m:F72m",
+ neg_1 = "m:F73m",
+ mul_1 = "m:F74m",
+ imul_1 = "m:F75m",
+ div_1 = "m:F76m",
+ idiv_1 = "m:F77m",
+
+ imul_2 = "rmqdw:0FAFrM|rIqdw:69rmI|rSqdw:6BrmS|riqdw:69rmi",
+ imul_3 = "rmIqdw:69rMI|rmSqdw:6BrMS|rmiqdw:69rMi",
+
+ movzx_2 = "rm/db:0FB6rM|rm/qb:|rm/wb:0FB6rM|rm/dw:0FB7rM|rm/qw:",
+ movsx_2 = "rm/db:0FBErM|rm/qb:|rm/wb:0FBErM|rm/dw:0FBFrM|rm/qw:",
+
+ bswap_1 = "rqd:0FC8r",
+ bsf_2 = "rmqdw:0FBCrM",
+ bsr_2 = "rmqdw:0FBDrM",
+ bt_2 = "mrqdw:0FA3Rm|miqdw:0FBA4mU",
+ btc_2 = "mrqdw:0FBBRm|miqdw:0FBA7mU",
+ btr_2 = "mrqdw:0FB3Rm|miqdw:0FBA6mU",
+ bts_2 = "mrqdw:0FABRm|miqdw:0FBA5mU",
+
+ shld_3 = "mriqdw:0FA4RmU|mrC/qq:0FA5Rm|mrC/dd:|mrC/ww:",
+ shrd_3 = "mriqdw:0FACRmU|mrC/qq:0FADRm|mrC/dd:|mrC/ww:",
+
+ rdtsc_0 = "0F31", -- P1+
+ rdpmc_0 = "0F33", -- P6+
+ cpuid_0 = "0FA2", -- P1+
+
+ -- floating point ops
+ fst_1 = "ff:DDD0r|xd:D92m|xq:nDD2m",
+ fstp_1 = "ff:DDD8r|xd:D93m|xq:nDD3m|xt:DB7m",
+ fld_1 = "ff:D9C0r|xd:D90m|xq:nDD0m|xt:DB5m",
+
+ fpop_0 = "DDD8", -- Alias for fstp st0.
+
+ fist_1 = "xw:nDF2m|xd:DB2m",
+ fistp_1 = "xw:nDF3m|xd:DB3m|xq:nDF7m",
+ fild_1 = "xw:nDF0m|xd:DB0m|xq:nDF5m",
+
+ fxch_0 = "D9C9",
+ fxch_1 = "ff:D9C8r",
+ fxch_2 = "fFf:D9C8r|Fff:D9C8R",
+
+ fucom_1 = "ff:DDE0r",
+ fucom_2 = "Fff:DDE0R",
+ fucomp_1 = "ff:DDE8r",
+ fucomp_2 = "Fff:DDE8R",
+ fucomi_1 = "ff:DBE8r", -- P6+
+ fucomi_2 = "Fff:DBE8R", -- P6+
+ fucomip_1 = "ff:DFE8r", -- P6+
+ fucomip_2 = "Fff:DFE8R", -- P6+
+ fcomi_1 = "ff:DBF0r", -- P6+
+ fcomi_2 = "Fff:DBF0R", -- P6+
+ fcomip_1 = "ff:DFF0r", -- P6+
+ fcomip_2 = "Fff:DFF0R", -- P6+
+ fucompp_0 = "DAE9",
+ fcompp_0 = "DED9",
+
+ fldenv_1 = "x.:D94m",
+ fnstenv_1 = "x.:D96m",
+ fstenv_1 = "x.:9BD96m",
+ fldcw_1 = "xw:nD95m",
+ fstcw_1 = "xw:n9BD97m",
+ fnstcw_1 = "xw:nD97m",
+ fstsw_1 = "Rw:n9BDFE0|xw:n9BDD7m",
+ fnstsw_1 = "Rw:nDFE0|xw:nDD7m",
+ fclex_0 = "9BDBE2",
+ fnclex_0 = "DBE2",
+
+ fnop_0 = "D9D0",
+ -- D9D1-D9DF: unassigned
+
+ fchs_0 = "D9E0",
+ fabs_0 = "D9E1",
+ -- D9E2: unassigned
+ -- D9E3: unassigned
+ ftst_0 = "D9E4",
+ fxam_0 = "D9E5",
+ -- D9E6: unassigned
+ -- D9E7: unassigned
+ fld1_0 = "D9E8",
+ fldl2t_0 = "D9E9",
+ fldl2e_0 = "D9EA",
+ fldpi_0 = "D9EB",
+ fldlg2_0 = "D9EC",
+ fldln2_0 = "D9ED",
+ fldz_0 = "D9EE",
+ -- D9EF: unassigned
+
+ f2xm1_0 = "D9F0",
+ fyl2x_0 = "D9F1",
+ fptan_0 = "D9F2",
+ fpatan_0 = "D9F3",
+ fxtract_0 = "D9F4",
+ fprem1_0 = "D9F5",
+ fdecstp_0 = "D9F6",
+ fincstp_0 = "D9F7",
+ fprem_0 = "D9F8",
+ fyl2xp1_0 = "D9F9",
+ fsqrt_0 = "D9FA",
+ fsincos_0 = "D9FB",
+ frndint_0 = "D9FC",
+ fscale_0 = "D9FD",
+ fsin_0 = "D9FE",
+ fcos_0 = "D9FF",
+
+ -- SSE, SSE2
+ andnpd_2 = "rmo:660F55rM",
+ andnps_2 = "rmo:0F55rM",
+ andpd_2 = "rmo:660F54rM",
+ andps_2 = "rmo:0F54rM",
+ clflush_1 = "x.:0FAE7m",
+ cmppd_3 = "rmio:660FC2rMU",
+ cmpps_3 = "rmio:0FC2rMU",
+ cmpsd_3 = "rrio:F20FC2rMU|rxi/oq:",
+ cmpss_3 = "rrio:F30FC2rMU|rxi/od:",
+ comisd_2 = "rro:660F2FrM|rx/oq:",
+ comiss_2 = "rro:0F2FrM|rx/od:",
+ cvtdq2pd_2 = "rro:F30FE6rM|rx/oq:",
+ cvtdq2ps_2 = "rmo:0F5BrM",
+ cvtpd2dq_2 = "rmo:F20FE6rM",
+ cvtpd2ps_2 = "rmo:660F5ArM",
+ cvtpi2pd_2 = "rx/oq:660F2ArM",
+ cvtpi2ps_2 = "rx/oq:0F2ArM",
+ cvtps2dq_2 = "rmo:660F5BrM",
+ cvtps2pd_2 = "rro:0F5ArM|rx/oq:",
+ cvtsd2si_2 = "rr/do:F20F2DrM|rr/qo:|rx/dq:|rxq:",
+ cvtsd2ss_2 = "rro:F20F5ArM|rx/oq:",
+ cvtsi2sd_2 = "rm/od:F20F2ArM|rm/oq:F20F2ArXM",
+ cvtsi2ss_2 = "rm/od:F30F2ArM|rm/oq:F30F2ArXM",
+ cvtss2sd_2 = "rro:F30F5ArM|rx/od:",
+ cvtss2si_2 = "rr/do:F30F2DrM|rr/qo:|rxd:|rx/qd:",
+ cvttpd2dq_2 = "rmo:660FE6rM",
+ cvttps2dq_2 = "rmo:F30F5BrM",
+ cvttsd2si_2 = "rr/do:F20F2CrM|rr/qo:|rx/dq:|rxq:",
+ cvttss2si_2 = "rr/do:F30F2CrM|rr/qo:|rxd:|rx/qd:",
+ fxsave_1 = "x.:0FAE0m",
+ fxrstor_1 = "x.:0FAE1m",
+ ldmxcsr_1 = "xd:0FAE2m",
+ lfence_0 = "0FAEE8",
+ maskmovdqu_2 = "rro:660FF7rM",
+ mfence_0 = "0FAEF0",
+ movapd_2 = "rmo:660F28rM|mro:660F29Rm",
+ movaps_2 = "rmo:0F28rM|mro:0F29Rm",
+ movd_2 = "rm/od:660F6ErM|rm/oq:660F6ErXM|mr/do:660F7ERm|mr/qo:",
+ movdqa_2 = "rmo:660F6FrM|mro:660F7FRm",
+ movdqu_2 = "rmo:F30F6FrM|mro:F30F7FRm",
+ movhlps_2 = "rro:0F12rM",
+ movhpd_2 = "rx/oq:660F16rM|xr/qo:n660F17Rm",
+ movhps_2 = "rx/oq:0F16rM|xr/qo:n0F17Rm",
+ movlhps_2 = "rro:0F16rM",
+ movlpd_2 = "rx/oq:660F12rM|xr/qo:n660F13Rm",
+ movlps_2 = "rx/oq:0F12rM|xr/qo:n0F13Rm",
+ movmskpd_2 = "rr/do:660F50rM",
+ movmskps_2 = "rr/do:0F50rM",
+ movntdq_2 = "xro:660FE7Rm",
+ movnti_2 = "xrqd:0FC3Rm",
+ movntpd_2 = "xro:660F2BRm",
+ movntps_2 = "xro:0F2BRm",
+ movq_2 = "rro:F30F7ErM|rx/oq:|xr/qo:n660FD6Rm",
+ movsd_2 = "rro:F20F10rM|rx/oq:|xr/qo:nF20F11Rm",
+ movss_2 = "rro:F30F10rM|rx/od:|xr/do:F30F11Rm",
+ movupd_2 = "rmo:660F10rM|mro:660F11Rm",
+ movups_2 = "rmo:0F10rM|mro:0F11Rm",
+ orpd_2 = "rmo:660F56rM",
+ orps_2 = "rmo:0F56rM",
+ packssdw_2 = "rmo:660F6BrM",
+ packsswb_2 = "rmo:660F63rM",
+ packuswb_2 = "rmo:660F67rM",
+ paddb_2 = "rmo:660FFCrM",
+ paddd_2 = "rmo:660FFErM",
+ paddq_2 = "rmo:660FD4rM",
+ paddsb_2 = "rmo:660FECrM",
+ paddsw_2 = "rmo:660FEDrM",
+ paddusb_2 = "rmo:660FDCrM",
+ paddusw_2 = "rmo:660FDDrM",
+ paddw_2 = "rmo:660FFDrM",
+ pand_2 = "rmo:660FDBrM",
+ pandn_2 = "rmo:660FDFrM",
+ pause_0 = "F390",
+ pavgb_2 = "rmo:660FE0rM",
+ pavgw_2 = "rmo:660FE3rM",
+ pcmpeqb_2 = "rmo:660F74rM",
+ pcmpeqd_2 = "rmo:660F76rM",
+ pcmpeqw_2 = "rmo:660F75rM",
+ pcmpgtb_2 = "rmo:660F64rM",
+ pcmpgtd_2 = "rmo:660F66rM",
+ pcmpgtw_2 = "rmo:660F65rM",
+ pextrw_3 = "rri/do:660FC5rMU|xri/wo:660F3A15nRmU", -- Mem op: SSE4.1 only.
+ pinsrw_3 = "rri/od:660FC4rMU|rxi/ow:",
+ pmaddwd_2 = "rmo:660FF5rM",
+ pmaxsw_2 = "rmo:660FEErM",
+ pmaxub_2 = "rmo:660FDErM",
+ pminsw_2 = "rmo:660FEArM",
+ pminub_2 = "rmo:660FDArM",
+ pmovmskb_2 = "rr/do:660FD7rM",
+ pmulhuw_2 = "rmo:660FE4rM",
+ pmulhw_2 = "rmo:660FE5rM",
+ pmullw_2 = "rmo:660FD5rM",
+ pmuludq_2 = "rmo:660FF4rM",
+ por_2 = "rmo:660FEBrM",
+ prefetchnta_1 = "xb:n0F180m",
+ prefetcht0_1 = "xb:n0F181m",
+ prefetcht1_1 = "xb:n0F182m",
+ prefetcht2_1 = "xb:n0F183m",
+ psadbw_2 = "rmo:660FF6rM",
+ pshufd_3 = "rmio:660F70rMU",
+ pshufhw_3 = "rmio:F30F70rMU",
+ pshuflw_3 = "rmio:F20F70rMU",
+ pslld_2 = "rmo:660FF2rM|rio:660F726mU",
+ pslldq_2 = "rio:660F737mU",
+ psllq_2 = "rmo:660FF3rM|rio:660F736mU",
+ psllw_2 = "rmo:660FF1rM|rio:660F716mU",
+ psrad_2 = "rmo:660FE2rM|rio:660F724mU",
+ psraw_2 = "rmo:660FE1rM|rio:660F714mU",
+ psrld_2 = "rmo:660FD2rM|rio:660F722mU",
+ psrldq_2 = "rio:660F733mU",
+ psrlq_2 = "rmo:660FD3rM|rio:660F732mU",
+ psrlw_2 = "rmo:660FD1rM|rio:660F712mU",
+ psubb_2 = "rmo:660FF8rM",
+ psubd_2 = "rmo:660FFArM",
+ psubq_2 = "rmo:660FFBrM",
+ psubsb_2 = "rmo:660FE8rM",
+ psubsw_2 = "rmo:660FE9rM",
+ psubusb_2 = "rmo:660FD8rM",
+ psubusw_2 = "rmo:660FD9rM",
+ psubw_2 = "rmo:660FF9rM",
+ punpckhbw_2 = "rmo:660F68rM",
+ punpckhdq_2 = "rmo:660F6ArM",
+ punpckhqdq_2 = "rmo:660F6DrM",
+ punpckhwd_2 = "rmo:660F69rM",
+ punpcklbw_2 = "rmo:660F60rM",
+ punpckldq_2 = "rmo:660F62rM",
+ punpcklqdq_2 = "rmo:660F6CrM",
+ punpcklwd_2 = "rmo:660F61rM",
+ pxor_2 = "rmo:660FEFrM",
+ rcpps_2 = "rmo:0F53rM",
+ rcpss_2 = "rro:F30F53rM|rx/od:",
+ rsqrtps_2 = "rmo:0F52rM",
+ rsqrtss_2 = "rmo:F30F52rM",
+ sfence_0 = "0FAEF8",
+ shufpd_3 = "rmio:660FC6rMU",
+ shufps_3 = "rmio:0FC6rMU",
+ stmxcsr_1 = "xd:0FAE3m",
+ ucomisd_2 = "rro:660F2ErM|rx/oq:",
+ ucomiss_2 = "rro:0F2ErM|rx/od:",
+ unpckhpd_2 = "rmo:660F15rM",
+ unpckhps_2 = "rmo:0F15rM",
+ unpcklpd_2 = "rmo:660F14rM",
+ unpcklps_2 = "rmo:0F14rM",
+ xorpd_2 = "rmo:660F57rM",
+ xorps_2 = "rmo:0F57rM",
+
+ -- SSE3 ops
+ fisttp_1 = "xw:nDF1m|xd:DB1m|xq:nDD1m",
+ addsubpd_2 = "rmo:660FD0rM",
+ addsubps_2 = "rmo:F20FD0rM",
+ haddpd_2 = "rmo:660F7CrM",
+ haddps_2 = "rmo:F20F7CrM",
+ hsubpd_2 = "rmo:660F7DrM",
+ hsubps_2 = "rmo:F20F7DrM",
+ lddqu_2 = "rxo:F20FF0rM",
+ movddup_2 = "rmo:F20F12rM",
+ movshdup_2 = "rmo:F30F16rM",
+ movsldup_2 = "rmo:F30F12rM",
+
+ -- SSSE3 ops
+ pabsb_2 = "rmo:660F381CrM",
+ pabsd_2 = "rmo:660F381ErM",
+ pabsw_2 = "rmo:660F381DrM",
+ palignr_3 = "rmio:660F3A0FrMU",
+ phaddd_2 = "rmo:660F3802rM",
+ phaddsw_2 = "rmo:660F3803rM",
+ phaddw_2 = "rmo:660F3801rM",
+ phsubd_2 = "rmo:660F3806rM",
+ phsubsw_2 = "rmo:660F3807rM",
+ phsubw_2 = "rmo:660F3805rM",
+ pmaddubsw_2 = "rmo:660F3804rM",
+ pmulhrsw_2 = "rmo:660F380BrM",
+ pshufb_2 = "rmo:660F3800rM",
+ psignb_2 = "rmo:660F3808rM",
+ psignd_2 = "rmo:660F380ArM",
+ psignw_2 = "rmo:660F3809rM",
+
+ -- SSE4.1 ops
+ blendpd_3 = "rmio:660F3A0DrMU",
+ blendps_3 = "rmio:660F3A0CrMU",
+ blendvpd_3 = "rmRo:660F3815rM",
+ blendvps_3 = "rmRo:660F3814rM",
+ dppd_3 = "rmio:660F3A41rMU",
+ dpps_3 = "rmio:660F3A40rMU",
+ extractps_3 = "mri/do:660F3A17RmU|rri/qo:660F3A17RXmU",
+ insertps_3 = "rrio:660F3A41rMU|rxi/od:",
+ movntdqa_2 = "rxo:660F382ArM",
+ mpsadbw_3 = "rmio:660F3A42rMU",
+ packusdw_2 = "rmo:660F382BrM",
+ pblendvb_3 = "rmRo:660F3810rM",
+ pblendw_3 = "rmio:660F3A0ErMU",
+ pcmpeqq_2 = "rmo:660F3829rM",
+ pextrb_3 = "rri/do:660F3A14nRmU|rri/qo:|xri/bo:",
+ pextrd_3 = "mri/do:660F3A16RmU",
+ pextrq_3 = "mri/qo:660F3A16RmU",
+ -- pextrw is SSE2, mem operand is SSE4.1 only
+ phminposuw_2 = "rmo:660F3841rM",
+ pinsrb_3 = "rri/od:660F3A20nrMU|rxi/ob:",
+ pinsrd_3 = "rmi/od:660F3A22rMU",
+ pinsrq_3 = "rmi/oq:660F3A22rXMU",
+ pmaxsb_2 = "rmo:660F383CrM",
+ pmaxsd_2 = "rmo:660F383DrM",
+ pmaxud_2 = "rmo:660F383FrM",
+ pmaxuw_2 = "rmo:660F383ErM",
+ pminsb_2 = "rmo:660F3838rM",
+ pminsd_2 = "rmo:660F3839rM",
+ pminud_2 = "rmo:660F383BrM",
+ pminuw_2 = "rmo:660F383ArM",
+ pmovsxbd_2 = "rro:660F3821rM|rx/od:",
+ pmovsxbq_2 = "rro:660F3822rM|rx/ow:",
+ pmovsxbw_2 = "rro:660F3820rM|rx/oq:",
+ pmovsxdq_2 = "rro:660F3825rM|rx/oq:",
+ pmovsxwd_2 = "rro:660F3823rM|rx/oq:",
+ pmovsxwq_2 = "rro:660F3824rM|rx/od:",
+ pmovzxbd_2 = "rro:660F3831rM|rx/od:",
+ pmovzxbq_2 = "rro:660F3832rM|rx/ow:",
+ pmovzxbw_2 = "rro:660F3830rM|rx/oq:",
+ pmovzxdq_2 = "rro:660F3835rM|rx/oq:",
+ pmovzxwd_2 = "rro:660F3833rM|rx/oq:",
+ pmovzxwq_2 = "rro:660F3834rM|rx/od:",
+ pmuldq_2 = "rmo:660F3828rM",
+ pmulld_2 = "rmo:660F3840rM",
+ ptest_2 = "rmo:660F3817rM",
+ roundpd_3 = "rmio:660F3A09rMU",
+ roundps_3 = "rmio:660F3A08rMU",
+ roundsd_3 = "rrio:660F3A0BrMU|rxi/oq:",
+ roundss_3 = "rrio:660F3A0ArMU|rxi/od:",
+
+ -- SSE4.2 ops
+ crc32_2 = "rmqd:F20F38F1rM|rm/dw:66F20F38F1rM|rm/db:F20F38F0rM|rm/qb:",
+ pcmpestri_3 = "rmio:660F3A61rMU",
+ pcmpestrm_3 = "rmio:660F3A60rMU",
+ pcmpgtq_2 = "rmo:660F3837rM",
+ pcmpistri_3 = "rmio:660F3A63rMU",
+ pcmpistrm_3 = "rmio:660F3A62rMU",
+ popcnt_2 = "rmqdw:F30FB8rM",
+
+ -- SSE4a
+ extrq_2 = "rro:660F79rM",
+ extrq_3 = "riio:660F780mUU",
+ insertq_2 = "rro:F20F79rM",
+ insertq_4 = "rriio:F20F78rMUU",
+ lzcnt_2 = "rmqdw:F30FBDrM",
+ movntsd_2 = "xr/qo:nF20F2BRm",
+ movntss_2 = "xr/do:F30F2BRm",
+ -- popcnt is also in SSE4.2
+}
+
+------------------------------------------------------------------------------
+
+-- Arithmetic ops.
+for name,n in pairs{ add = 0, ["or"] = 1, adc = 2, sbb = 3,
+ ["and"] = 4, sub = 5, xor = 6, cmp = 7 } do
+ local n8 = shl(n, 3)
+ map_op[name.."_2"] = format(
+ "mr:%02XRm|rm:%02XrM|mI1qdw:81%XmI|mS1qdw:83%XmS|Ri1qdwb:%02Xri|mi1qdwb:81%Xmi",
+ 1+n8, 3+n8, n, n, 5+n8, n)
+end
+
+-- Shift ops.
+for name,n in pairs{ rol = 0, ror = 1, rcl = 2, rcr = 3,
+ shl = 4, shr = 5, sar = 7, sal = 4 } do
+ map_op[name.."_2"] = format("m1:D1%Xm|mC1qdwb:D3%Xm|mi:C1%XmU", n, n, n)
+end
+
+-- Conditional ops.
+for cc,n in pairs(map_cc) do
+ map_op["j"..cc.."_1"] = format("J.:n0F8%XJ", n) -- short: 7%X
+ map_op["set"..cc.."_1"] = format("mb:n0F9%X2m", n)
+ map_op["cmov"..cc.."_2"] = format("rmqdw:0F4%XrM", n) -- P6+
+end
+
+-- FP arithmetic ops.
+for name,n in pairs{ add = 0, mul = 1, com = 2, comp = 3,
+ sub = 4, subr = 5, div = 6, divr = 7 } do
+ local nc = 0xc0 + shl(n, 3)
+ local nr = nc + (n < 4 and 0 or (n % 2 == 0 and 8 or -8))
+ local fn = "f"..name
+ map_op[fn.."_1"] = format("ff:D8%02Xr|xd:D8%Xm|xq:nDC%Xm", nc, n, n)
+ if n == 2 or n == 3 then
+ map_op[fn.."_2"] = format("Fff:D8%02XR|Fx2d:D8%XM|Fx2q:nDC%XM", nc, n, n)
+ else
+ map_op[fn.."_2"] = format("Fff:D8%02XR|fFf:DC%02Xr|Fx2d:D8%XM|Fx2q:nDC%XM", nc, nr, n, n)
+ map_op[fn.."p_1"] = format("ff:DE%02Xr", nr)
+ map_op[fn.."p_2"] = format("fFf:DE%02Xr", nr)
+ end
+ map_op["fi"..name.."_1"] = format("xd:DA%Xm|xw:nDE%Xm", n, n)
+end
+
+-- FP conditional moves.
+for cc,n in pairs{ b=0, e=1, be=2, u=3, nb=4, ne=5, nbe=6, nu=7 } do
+ local nc = 0xdac0 + shl(band(n, 3), 3) + shl(band(n, 4), 6)
+ map_op["fcmov"..cc.."_1"] = format("ff:%04Xr", nc) -- P6+
+ map_op["fcmov"..cc.."_2"] = format("Fff:%04XR", nc) -- P6+
+end
+
+-- SSE FP arithmetic ops.
+for name,n in pairs{ sqrt = 1, add = 8, mul = 9,
+ sub = 12, min = 13, div = 14, max = 15 } do
+ map_op[name.."ps_2"] = format("rmo:0F5%XrM", n)
+ map_op[name.."ss_2"] = format("rro:F30F5%XrM|rx/od:", n)
+ map_op[name.."pd_2"] = format("rmo:660F5%XrM", n)
+ map_op[name.."sd_2"] = format("rro:F20F5%XrM|rx/oq:", n)
+end
+
+------------------------------------------------------------------------------
+
+-- Process pattern string.
+local function dopattern(pat, args, sz, op, needrex)
+ local digit, addin
+ local opcode = 0
+ local szov = sz
+ local narg = 1
+ local rex = 0
+
+ -- Limit number of section buffer positions used by a single dasm_put().
+ -- A single opcode needs a maximum of 5 positions.
+ if secpos+5 > maxsecpos then wflush() end
+
+ -- Process each character.
+ for c in gmatch(pat.."|", ".") do
+ if match(c, "%x") then -- Hex digit.
+ digit = byte(c) - 48
+ if digit > 48 then digit = digit - 39
+ elseif digit > 16 then digit = digit - 7 end
+ opcode = opcode*16 + digit
+ addin = nil
+ elseif c == "n" then -- Disable operand size mods for opcode.
+ szov = nil
+ elseif c == "X" then -- Force REX.W.
+ rex = 8
+ elseif c == "r" then -- Merge 1st operand regno. into opcode.
+ addin = args[1]; opcode = opcode + (addin.reg % 8)
+ if narg < 2 then narg = 2 end
+ elseif c == "R" then -- Merge 2nd operand regno. into opcode.
+ addin = args[2]; opcode = opcode + (addin.reg % 8)
+ narg = 3
+ elseif c == "m" or c == "M" then -- Encode ModRM/SIB.
+ local s
+ if addin then
+ s = addin.reg
+ opcode = opcode - band(s, 7) -- Undo regno opcode merge.
+ else
+ s = band(opcode, 15) -- Undo last digit.
+ opcode = shr(opcode, 4)
+ end
+ local nn = c == "m" and 1 or 2
+ local t = args[nn]
+ if narg <= nn then narg = nn + 1 end
+ if szov == "q" and rex == 0 then rex = rex + 8 end
+ if t.reg and t.reg > 7 then rex = rex + 1 end
+ if t.xreg and t.xreg > 7 then rex = rex + 2 end
+ if s > 7 then rex = rex + 4 end
+ if needrex then rex = rex + 16 end
+ wputop(szov, opcode, rex); opcode = nil
+ local imark = sub(pat, -1) -- Force a mark (ugly).
+ -- Put ModRM/SIB with regno/last digit as spare.
+ wputmrmsib(t, imark, s, addin and addin.vreg)
+ addin = nil
+ else
+ if opcode then -- Flush opcode.
+ if szov == "q" and rex == 0 then rex = rex + 8 end
+ if needrex then rex = rex + 16 end
+ if addin and addin.reg == -1 then
+ wputop(szov, opcode - 7, rex)
+ waction("VREG", addin.vreg); wputxb(0)
+ else
+ if addin and addin.reg > 7 then rex = rex + 1 end
+ wputop(szov, opcode, rex)
+ end
+ opcode = nil
+ end
+ if c == "|" then break end
+ if c == "o" then -- Offset (pure 32 bit displacement).
+ wputdarg(args[1].disp); if narg < 2 then narg = 2 end
+ elseif c == "O" then
+ wputdarg(args[2].disp); narg = 3
+ else
+ -- Anything else is an immediate operand.
+ local a = args[narg]
+ narg = narg + 1
+ local mode, imm = a.mode, a.imm
+ if mode == "iJ" and not match("iIJ", c) then
+ werror("bad operand size for label")
+ end
+ if c == "S" then
+ wputsbarg(imm)
+ elseif c == "U" then
+ wputbarg(imm)
+ elseif c == "W" then
+ wputwarg(imm)
+ elseif c == "i" or c == "I" then
+ if mode == "iJ" then
+ wputlabel("IMM_", imm, 1)
+ elseif mode == "iI" and c == "I" then
+ waction(sz == "w" and "IMM_WB" or "IMM_DB", imm)
+ else
+ wputszarg(sz, imm)
+ end
+ elseif c == "J" then
+ if mode == "iPJ" then
+ waction("REL_A", imm) -- !x64 (secpos)
+ else
+ wputlabel("REL_", imm, 2)
+ end
+ else
+ werror("bad char `"..c.."' in pattern `"..pat.."' for `"..op.."'")
+ end
+ end
+ end
+ end
+end
+
+------------------------------------------------------------------------------
+
+-- Mapping of operand modes to short names. Suppress output with '#'.
+local map_modename = {
+ r = "reg", R = "eax", C = "cl", x = "mem", m = "mrm", i = "imm",
+ f = "stx", F = "st0", J = "lbl", ["1"] = "1",
+ I = "#", S = "#", O = "#",
+}
+
+-- Return a table/string showing all possible operand modes.
+local function templatehelp(template, nparams)
+ if nparams == 0 then return "" end
+ local t = {}
+ for tm in gmatch(template, "[^%|]+") do
+ local s = map_modename[sub(tm, 1, 1)]
+ s = s..gsub(sub(tm, 2, nparams), ".", function(c)
+ return ", "..map_modename[c]
+ end)
+ if not match(s, "#") then t[#t+1] = s end
+ end
+ return t
+end
+
+-- Match operand modes against mode match part of template.
+local function matchtm(tm, args)
+ for i=1,#args do
+ if not match(args[i].mode, sub(tm, i, i)) then return end
+ end
+ return true
+end
+
+-- Handle opcodes defined with template strings.
+map_op[".template__"] = function(params, template, nparams)
+ if not params then return templatehelp(template, nparams) end
+ local args = {}
+
+ -- Zero-operand opcodes have no match part.
+ if #params == 0 then
+ dopattern(template, args, "d", params.op, nil)
+ return
+ end
+
+ -- Determine common operand size (coerce undefined size) or flag as mixed.
+ local sz, szmix, needrex
+ for i,p in ipairs(params) do
+ args[i] = parseoperand(p)
+ local nsz = args[i].opsize
+ if nsz then
+ if sz and sz ~= nsz then szmix = true else sz = nsz end
+ end
+ local nrex = args[i].needrex
+ if nrex ~= nil then
+ if needrex == nil then
+ needrex = nrex
+ elseif needrex ~= nrex then
+ werror("bad mix of byte-addressable registers")
+ end
+ end
+ end
+
+ -- Try all match:pattern pairs (separated by '|').
+ local gotmatch, lastpat
+ for tm in gmatch(template, "[^%|]+") do
+ -- Split off size match (starts after mode match) and pattern string.
+ local szm, pat = match(tm, "^(.-):(.*)$", #args+1)
+ if pat == "" then pat = lastpat else lastpat = pat end
+ if matchtm(tm, args) then
+ local prefix = sub(szm, 1, 1)
+ if prefix == "/" then -- Match both operand sizes.
+ if args[1].opsize == sub(szm, 2, 2) and
+ args[2].opsize == sub(szm, 3, 3) then
+ dopattern(pat, args, sz, params.op, needrex) -- Process pattern.
+ return
+ end
+ else -- Match common operand size.
+ local szp = sz
+ if szm == "" then szm = x64 and "qdwb" or "dwb" end -- Default sizes.
+ if prefix == "1" then szp = args[1].opsize; szmix = nil
+ elseif prefix == "2" then szp = args[2].opsize; szmix = nil end
+ if not szmix and (prefix == "." or match(szm, szp or "#")) then
+ dopattern(pat, args, szp, params.op, needrex) -- Process pattern.
+ return
+ end
+ end
+ gotmatch = true
+ end
+ end
+
+ local msg = "bad operand mode"
+ if gotmatch then
+ if szmix then
+ msg = "mixed operand size"
+ else
+ msg = sz and "bad operand size" or "missing operand size"
+ end
+ end
+
+ werror(msg.." in `"..opmodestr(params.op, args).."'")
+end
+
+------------------------------------------------------------------------------
+
+-- x64-specific opcode for 64 bit immediates and displacements.
+if x64 then
+ function map_op.mov64_2(params)
+ if not params then return { "reg, imm", "reg, [disp]", "[disp], reg" } end
+ if secpos+2 > maxsecpos then wflush() end
+ local opcode, op64, sz, rex, vreg
+ local op64 = match(params[1], "^%[%s*(.-)%s*%]$")
+ if op64 then
+ local a = parseoperand(params[2])
+ if a.mode ~= "rmR" then werror("bad operand mode") end
+ sz = a.opsize
+ rex = sz == "q" and 8 or 0
+ opcode = 0xa3
+ else
+ op64 = match(params[2], "^%[%s*(.-)%s*%]$")
+ local a = parseoperand(params[1])
+ if op64 then
+ if a.mode ~= "rmR" then werror("bad operand mode") end
+ sz = a.opsize
+ rex = sz == "q" and 8 or 0
+ opcode = 0xa1
+ else
+ if sub(a.mode, 1, 1) ~= "r" or a.opsize ~= "q" then
+ werror("bad operand mode")
+ end
+ op64 = params[2]
+ if a.reg == -1 then
+ vreg = a.vreg
+ opcode = 0xb8
+ else
+ opcode = 0xb8 + band(a.reg, 7)
+ end
+ rex = a.reg > 7 and 9 or 8
+ end
+ end
+ wputop(sz, opcode, rex)
+ if vreg then waction("VREG", vreg); wputxb(0) end
+ waction("IMM_D", format("(unsigned int)(%s)", op64))
+ waction("IMM_D", format("(unsigned int)((%s)>>32)", op64))
+ end
+end
+
+------------------------------------------------------------------------------
+
+-- Pseudo-opcodes for data storage.
+local function op_data(params)
+ if not params then return "imm..." end
+ local sz = sub(params.op, 2, 2)
+ if sz == "a" then sz = addrsize end
+ for _,p in ipairs(params) do
+ local a = parseoperand(p)
+ if sub(a.mode, 1, 1) ~= "i" or (a.opsize and a.opsize ~= sz) then
+ werror("bad mode or size in `"..p.."'")
+ end
+ if a.mode == "iJ" then
+ wputlabel("IMM_", a.imm, 1)
+ else
+ wputszarg(sz, a.imm)
+ end
+ if secpos+2 > maxsecpos then wflush() end
+ end
+end
+
+map_op[".byte_*"] = op_data
+map_op[".sbyte_*"] = op_data
+map_op[".word_*"] = op_data
+map_op[".dword_*"] = op_data
+map_op[".aword_*"] = op_data
+
+------------------------------------------------------------------------------
+
+-- Pseudo-opcode to mark the position where the action list is to be emitted.
+map_op[".actionlist_1"] = function(params)
+ if not params then return "cvar" end
+ local name = params[1] -- No syntax check. You get to keep the pieces.
+ wline(function(out) writeactions(out, name) end)
+end
+
+-- Pseudo-opcode to mark the position where the global enum is to be emitted.
+map_op[".globals_1"] = function(params)
+ if not params then return "prefix" end
+ local prefix = params[1] -- No syntax check. You get to keep the pieces.
+ wline(function(out) writeglobals(out, prefix) end)
+end
+
+-- Pseudo-opcode to mark the position where the global names are to be emitted.
+map_op[".globalnames_1"] = function(params)
+ if not params then return "cvar" end
+ local name = params[1] -- No syntax check. You get to keep the pieces.
+ wline(function(out) writeglobalnames(out, name) end)
+end
+
+-- Pseudo-opcode to mark the position where the extern names are to be emitted.
+map_op[".externnames_1"] = function(params)
+ if not params then return "cvar" end
+ local name = params[1] -- No syntax check. You get to keep the pieces.
+ wline(function(out) writeexternnames(out, name) end)
+end
+
+------------------------------------------------------------------------------
+
+-- Label pseudo-opcode (converted from trailing colon form).
+map_op[".label_2"] = function(params)
+ if not params then return "[1-9] | ->global | =>pcexpr [, addr]" end
+ if secpos+2 > maxsecpos then wflush() end
+ local a = parseoperand(params[1])
+ local mode, imm = a.mode, a.imm
+ if type(imm) == "number" and (mode == "iJ" or (imm >= 1 and imm <= 9)) then
+ -- Local label (1: ... 9:) or global label (->global:).
+ waction("LABEL_LG", nil, 1)
+ wputxb(imm)
+ elseif mode == "iJ" then
+ -- PC label (=>pcexpr:).
+ waction("LABEL_PC", imm)
+ else
+ werror("bad label definition")
+ end
+ -- SETLABEL must immediately follow LABEL_LG/LABEL_PC.
+ local addr = params[2]
+ if addr then
+ local a = parseoperand(addr)
+ if a.mode == "iPJ" then
+ waction("SETLABEL", a.imm)
+ else
+ werror("bad label assignment")
+ end
+ end
+end
+map_op[".label_1"] = map_op[".label_2"]
+
+------------------------------------------------------------------------------
+
+-- Alignment pseudo-opcode.
+map_op[".align_1"] = function(params)
+ if not params then return "numpow2" end
+ if secpos+1 > maxsecpos then wflush() end
+ local align = tonumber(params[1]) or map_opsizenum[map_opsize[params[1]]]
+ if align then
+ local x = align
+ -- Must be a power of 2 in the range (2 ... 256).
+ for i=1,8 do
+ x = x / 2
+ if x == 1 then
+ waction("ALIGN", nil, 1)
+ wputxb(align-1) -- Action byte is 2**n-1.
+ return
+ end
+ end
+ end
+ werror("bad alignment")
+end
+
+-- Spacing pseudo-opcode.
+map_op[".space_2"] = function(params)
+ if not params then return "num [, filler]" end
+ if secpos+1 > maxsecpos then wflush() end
+ waction("SPACE", params[1])
+ local fill = params[2]
+ if fill then
+ fill = tonumber(fill)
+ if not fill or fill < 0 or fill > 255 then werror("bad filler") end
+ end
+ wputxb(fill or 0)
+end
+map_op[".space_1"] = map_op[".space_2"]
+
+------------------------------------------------------------------------------
+
+-- Pseudo-opcode for (primitive) type definitions (map to C types).
+map_op[".type_3"] = function(params, nparams)
+ if not params then
+ return nparams == 2 and "name, ctype" or "name, ctype, reg"
+ end
+ local name, ctype, reg = params[1], params[2], params[3]
+ if not match(name, "^[%a_][%w_]*$") then
+ werror("bad type name `"..name.."'")
+ end
+ local tp = map_type[name]
+ if tp then
+ werror("duplicate type `"..name.."'")
+ end
+ if reg and not map_reg_valid_base[reg] then
+ werror("bad base register `"..(map_reg_rev[reg] or reg).."'")
+ end
+ -- Add #type to defines. A bit unclean to put it in map_archdef.
+ map_archdef["#"..name] = "sizeof("..ctype..")"
+ -- Add new type and emit shortcut define.
+ local num = ctypenum + 1
+ map_type[name] = {
+ ctype = ctype,
+ ctypefmt = format("Dt%X(%%s)", num),
+ reg = reg,
+ }
+ wline(format("#define Dt%X(_V) (int)(ptrdiff_t)&(((%s *)0)_V)", num, ctype))
+ ctypenum = num
+end
+map_op[".type_2"] = map_op[".type_3"]
+
+-- Dump type definitions.
+local function dumptypes(out, lvl)
+ local t = {}
+ for name in pairs(map_type) do t[#t+1] = name end
+ sort(t)
+ out:write("Type definitions:\n")
+ for _,name in ipairs(t) do
+ local tp = map_type[name]
+ local reg = tp.reg and map_reg_rev[tp.reg] or ""
+ out:write(format(" %-20s %-20s %s\n", name, tp.ctype, reg))
+ end
+ out:write("\n")
+end
+
+------------------------------------------------------------------------------
+
+-- Set the current section.
+function _M.section(num)
+ waction("SECTION")
+ wputxb(num)
+ wflush(true) -- SECTION is a terminal action.
+end
+
+------------------------------------------------------------------------------
+
+-- Dump architecture description.
+function _M.dumparch(out)
+ out:write(format("DynASM %s version %s, released %s\n\n",
+ _info.arch, _info.version, _info.release))
+ dumpregs(out)
+ dumpactions(out)
+end
+
+-- Dump all user defined elements.
+function _M.dumpdef(out, lvl)
+ dumptypes(out, lvl)
+ dumpglobals(out, lvl)
+ dumpexterns(out, lvl)
+end
+
+------------------------------------------------------------------------------
+
+-- Pass callbacks from/to the DynASM core.
+function _M.passcb(wl, we, wf, ww)
+ wline, werror, wfatal, wwarn = wl, we, wf, ww
+ return wflush
+end
+
+-- Setup the arch-specific module.
+function _M.setup(arch, opt)
+ g_arch, g_opt = arch, opt
+end
+
+-- Merge the core maps and the arch-specific maps.
+function _M.mergemaps(map_coreop, map_def)
+ setmetatable(map_op, { __index = map_coreop })
+ setmetatable(map_def, { __index = map_archdef })
+ return map_op, map_def
+end
+
+return _M
+
+------------------------------------------------------------------------------
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/dynasm/dynasm.lua b/src/3rdparty/LuaJIT-2.0.5/dynasm/dynasm.lua
new file mode 100644
index 0000000..c46e956
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/dynasm/dynasm.lua
@@ -0,0 +1,1094 @@
+------------------------------------------------------------------------------
+-- DynASM. A dynamic assembler for code generation engines.
+-- Originally designed and implemented for LuaJIT.
+--
+-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+-- See below for full copyright notice.
+------------------------------------------------------------------------------
+
+-- Application information.
+local _info = {
+ name = "DynASM",
+ description = "A dynamic assembler for code generation engines",
+ version = "1.3.0",
+ vernum = 10300,
+ release = "2011-05-05",
+ author = "Mike Pall",
+ url = "http://luajit.org/dynasm.html",
+ license = "MIT",
+ copyright = [[
+Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+[ MIT license: http://www.opensource.org/licenses/mit-license.php ]
+]],
+}
+
+-- Cache library functions.
+local type, pairs, ipairs = type, pairs, ipairs
+local pcall, error, assert = pcall, error, assert
+local _s = string
+local sub, match, gmatch, gsub = _s.sub, _s.match, _s.gmatch, _s.gsub
+local format, rep, upper = _s.format, _s.rep, _s.upper
+local _t = table
+local insert, remove, concat, sort = _t.insert, _t.remove, _t.concat, _t.sort
+local exit = os.exit
+local io = io
+local stdin, stdout, stderr = io.stdin, io.stdout, io.stderr
+
+------------------------------------------------------------------------------
+
+-- Program options.
+local g_opt = {}
+
+-- Global state for current file.
+local g_fname, g_curline, g_indent, g_lineno, g_synclineno, g_arch
+local g_errcount = 0
+
+-- Write buffer for output file.
+local g_wbuffer, g_capbuffer
+
+------------------------------------------------------------------------------
+
+-- Write an output line (or callback function) to the buffer.
+local function wline(line, needindent)
+ local buf = g_capbuffer or g_wbuffer
+ buf[#buf+1] = needindent and g_indent..line or line
+ g_synclineno = g_synclineno + 1
+end
+
+-- Write assembler line as a comment, if requestd.
+local function wcomment(aline)
+ if g_opt.comment then
+ wline(g_opt.comment..aline..g_opt.endcomment, true)
+ end
+end
+
+-- Resync CPP line numbers.
+local function wsync()
+ if g_synclineno ~= g_lineno and g_opt.cpp then
+ wline("#line "..g_lineno..' "'..g_fname..'"')
+ g_synclineno = g_lineno
+ end
+end
+
+-- Dummy action flush function. Replaced with arch-specific function later.
+local function wflush(term)
+end
+
+-- Dump all buffered output lines.
+local function wdumplines(out, buf)
+ for _,line in ipairs(buf) do
+ if type(line) == "string" then
+ assert(out:write(line, "\n"))
+ else
+ -- Special callback to dynamically insert lines after end of processing.
+ line(out)
+ end
+ end
+end
+
+------------------------------------------------------------------------------
+
+-- Emit an error. Processing continues with next statement.
+local function werror(msg)
+ error(format("%s:%s: error: %s:\n%s", g_fname, g_lineno, msg, g_curline), 0)
+end
+
+-- Emit a fatal error. Processing stops.
+local function wfatal(msg)
+ g_errcount = "fatal"
+ werror(msg)
+end
+
+-- Print a warning. Processing continues.
+local function wwarn(msg)
+ stderr:write(format("%s:%s: warning: %s:\n%s\n",
+ g_fname, g_lineno, msg, g_curline))
+end
+
+-- Print caught error message. But suppress excessive errors.
+local function wprinterr(...)
+ if type(g_errcount) == "number" then
+ -- Regular error.
+ g_errcount = g_errcount + 1
+ if g_errcount < 21 then -- Seems to be a reasonable limit.
+ stderr:write(...)
+ elseif g_errcount == 21 then
+ stderr:write(g_fname,
+ ":*: warning: too many errors (suppressed further messages).\n")
+ end
+ else
+ -- Fatal error.
+ stderr:write(...)
+ return true -- Stop processing.
+ end
+end
+
+------------------------------------------------------------------------------
+
+-- Map holding all option handlers.
+local opt_map = {}
+local opt_current
+
+-- Print error and exit with error status.
+local function opterror(...)
+ stderr:write("dynasm.lua: ERROR: ", ...)
+ stderr:write("\n")
+ exit(1)
+end
+
+-- Get option parameter.
+local function optparam(args)
+ local argn = args.argn
+ local p = args[argn]
+ if not p then
+ opterror("missing parameter for option `", opt_current, "'.")
+ end
+ args.argn = argn + 1
+ return p
+end
+
+------------------------------------------------------------------------------
+
+-- Core pseudo-opcodes.
+local map_coreop = {}
+-- Dummy opcode map. Replaced by arch-specific map.
+local map_op = {}
+
+-- Forward declarations.
+local dostmt
+local readfile
+
+------------------------------------------------------------------------------
+
+-- Map for defines (initially empty, chains to arch-specific map).
+local map_def = {}
+
+-- Pseudo-opcode to define a substitution.
+map_coreop[".define_2"] = function(params, nparams)
+ if not params then return nparams == 1 and "name" or "name, subst" end
+ local name, def = params[1], params[2] or "1"
+ if not match(name, "^[%a_][%w_]*$") then werror("bad or duplicate define") end
+ map_def[name] = def
+end
+map_coreop[".define_1"] = map_coreop[".define_2"]
+
+-- Define a substitution on the command line.
+function opt_map.D(args)
+ local namesubst = optparam(args)
+ local name, subst = match(namesubst, "^([%a_][%w_]*)=(.*)$")
+ if name then
+ map_def[name] = subst
+ elseif match(namesubst, "^[%a_][%w_]*$") then
+ map_def[namesubst] = "1"
+ else
+ opterror("bad define")
+ end
+end
+
+-- Undefine a substitution on the command line.
+function opt_map.U(args)
+ local name = optparam(args)
+ if match(name, "^[%a_][%w_]*$") then
+ map_def[name] = nil
+ else
+ opterror("bad define")
+ end
+end
+
+-- Helper for definesubst.
+local gotsubst
+
+local function definesubst_one(word)
+ local subst = map_def[word]
+ if subst then gotsubst = word; return subst else return word end
+end
+
+-- Iteratively substitute defines.
+local function definesubst(stmt)
+ -- Limit number of iterations.
+ for i=1,100 do
+ gotsubst = false
+ stmt = gsub(stmt, "#?[%w_]+", definesubst_one)
+ if not gotsubst then break end
+ end
+ if gotsubst then wfatal("recursive define involving `"..gotsubst.."'") end
+ return stmt
+end
+
+-- Dump all defines.
+local function dumpdefines(out, lvl)
+ local t = {}
+ for name in pairs(map_def) do
+ t[#t+1] = name
+ end
+ sort(t)
+ out:write("Defines:\n")
+ for _,name in ipairs(t) do
+ local subst = map_def[name]
+ if g_arch then subst = g_arch.revdef(subst) end
+ out:write(format(" %-20s %s\n", name, subst))
+ end
+ out:write("\n")
+end
+
+------------------------------------------------------------------------------
+
+-- Support variables for conditional assembly.
+local condlevel = 0
+local condstack = {}
+
+-- Evaluate condition with a Lua expression. Substitutions already performed.
+local function cond_eval(cond)
+ local func, err
+ if setfenv then
+ func, err = loadstring("return "..cond, "=expr")
+ else
+ -- No globals. All unknown identifiers evaluate to nil.
+ func, err = load("return "..cond, "=expr", "t", {})
+ end
+ if func then
+ if setfenv then
+ setfenv(func, {}) -- No globals. All unknown identifiers evaluate to nil.
+ end
+ local ok, res = pcall(func)
+ if ok then
+ if res == 0 then return false end -- Oh well.
+ return not not res
+ end
+ err = res
+ end
+ wfatal("bad condition: "..err)
+end
+
+-- Skip statements until next conditional pseudo-opcode at the same level.
+local function stmtskip()
+ local dostmt_save = dostmt
+ local lvl = 0
+ dostmt = function(stmt)
+ local op = match(stmt, "^%s*(%S+)")
+ if op == ".if" then
+ lvl = lvl + 1
+ elseif lvl ~= 0 then
+ if op == ".endif" then lvl = lvl - 1 end
+ elseif op == ".elif" or op == ".else" or op == ".endif" then
+ dostmt = dostmt_save
+ dostmt(stmt)
+ end
+ end
+end
+
+-- Pseudo-opcodes for conditional assembly.
+map_coreop[".if_1"] = function(params)
+ if not params then return "condition" end
+ local lvl = condlevel + 1
+ local res = cond_eval(params[1])
+ condlevel = lvl
+ condstack[lvl] = res
+ if not res then stmtskip() end
+end
+
+map_coreop[".elif_1"] = function(params)
+ if not params then return "condition" end
+ if condlevel == 0 then wfatal(".elif without .if") end
+ local lvl = condlevel
+ local res = condstack[lvl]
+ if res then
+ if res == "else" then wfatal(".elif after .else") end
+ else
+ res = cond_eval(params[1])
+ if res then
+ condstack[lvl] = res
+ return
+ end
+ end
+ stmtskip()
+end
+
+map_coreop[".else_0"] = function(params)
+ if condlevel == 0 then wfatal(".else without .if") end
+ local lvl = condlevel
+ local res = condstack[lvl]
+ condstack[lvl] = "else"
+ if res then
+ if res == "else" then wfatal(".else after .else") end
+ stmtskip()
+ end
+end
+
+map_coreop[".endif_0"] = function(params)
+ local lvl = condlevel
+ if lvl == 0 then wfatal(".endif without .if") end
+ condlevel = lvl - 1
+end
+
+-- Check for unfinished conditionals.
+local function checkconds()
+ if g_errcount ~= "fatal" and condlevel ~= 0 then
+ wprinterr(g_fname, ":*: error: unbalanced conditional\n")
+ end
+end
+
+------------------------------------------------------------------------------
+
+-- Search for a file in the given path and open it for reading.
+local function pathopen(path, name)
+ local dirsep = package and match(package.path, "\\") and "\\" or "/"
+ for _,p in ipairs(path) do
+ local fullname = p == "" and name or p..dirsep..name
+ local fin = io.open(fullname, "r")
+ if fin then
+ g_fname = fullname
+ return fin
+ end
+ end
+end
+
+-- Include a file.
+map_coreop[".include_1"] = function(params)
+ if not params then return "filename" end
+ local name = params[1]
+ -- Save state. Ugly, I know. but upvalues are fast.
+ local gf, gl, gcl, gi = g_fname, g_lineno, g_curline, g_indent
+ -- Read the included file.
+ local fatal = readfile(pathopen(g_opt.include, name) or
+ wfatal("include file `"..name.."' not found"))
+ -- Restore state.
+ g_synclineno = -1
+ g_fname, g_lineno, g_curline, g_indent = gf, gl, gcl, gi
+ if fatal then wfatal("in include file") end
+end
+
+-- Make .include and conditionals initially available, too.
+map_op[".include_1"] = map_coreop[".include_1"]
+map_op[".if_1"] = map_coreop[".if_1"]
+map_op[".elif_1"] = map_coreop[".elif_1"]
+map_op[".else_0"] = map_coreop[".else_0"]
+map_op[".endif_0"] = map_coreop[".endif_0"]
+
+------------------------------------------------------------------------------
+
+-- Support variables for macros.
+local mac_capture, mac_lineno, mac_name
+local mac_active = {}
+local mac_list = {}
+
+-- Pseudo-opcode to define a macro.
+map_coreop[".macro_*"] = function(mparams)
+ if not mparams then return "name [, params...]" end
+ -- Split off and validate macro name.
+ local name = remove(mparams, 1)
+ if not name then werror("missing macro name") end
+ if not (match(name, "^[%a_][%w_%.]*$") or match(name, "^%.[%w_%.]*$")) then
+ wfatal("bad macro name `"..name.."'")
+ end
+ -- Validate macro parameter names.
+ local mdup = {}
+ for _,mp in ipairs(mparams) do
+ if not match(mp, "^[%a_][%w_]*$") then
+ wfatal("bad macro parameter name `"..mp.."'")
+ end
+ if mdup[mp] then wfatal("duplicate macro parameter name `"..mp.."'") end
+ mdup[mp] = true
+ end
+ -- Check for duplicate or recursive macro definitions.
+ local opname = name.."_"..#mparams
+ if map_op[opname] or map_op[name.."_*"] then
+ wfatal("duplicate macro `"..name.."' ("..#mparams.." parameters)")
+ end
+ if mac_capture then wfatal("recursive macro definition") end
+
+ -- Enable statement capture.
+ local lines = {}
+ mac_lineno = g_lineno
+ mac_name = name
+ mac_capture = function(stmt) -- Statement capture function.
+ -- Stop macro definition with .endmacro pseudo-opcode.
+ if not match(stmt, "^%s*.endmacro%s*$") then
+ lines[#lines+1] = stmt
+ return
+ end
+ mac_capture = nil
+ mac_lineno = nil
+ mac_name = nil
+ mac_list[#mac_list+1] = opname
+ -- Add macro-op definition.
+ map_op[opname] = function(params)
+ if not params then return mparams, lines end
+ -- Protect against recursive macro invocation.
+ if mac_active[opname] then wfatal("recursive macro invocation") end
+ mac_active[opname] = true
+ -- Setup substitution map.
+ local subst = {}
+ for i,mp in ipairs(mparams) do subst[mp] = params[i] end
+ local mcom
+ if g_opt.maccomment and g_opt.comment then
+ mcom = " MACRO "..name.." ("..#mparams..")"
+ wcomment("{"..mcom)
+ end
+ -- Loop through all captured statements
+ for _,stmt in ipairs(lines) do
+ -- Substitute macro parameters.
+ local st = gsub(stmt, "[%w_]+", subst)
+ st = definesubst(st)
+ st = gsub(st, "%s*%.%.%s*", "") -- Token paste a..b.
+ if mcom and sub(st, 1, 1) ~= "|" then wcomment(st) end
+ -- Emit statement. Use a protected call for better diagnostics.
+ local ok, err = pcall(dostmt, st)
+ if not ok then
+ -- Add the captured statement to the error.
+ wprinterr(err, "\n", g_indent, "| ", stmt,
+ "\t[MACRO ", name, " (", #mparams, ")]\n")
+ end
+ end
+ if mcom then wcomment("}"..mcom) end
+ mac_active[opname] = nil
+ end
+ end
+end
+
+-- An .endmacro pseudo-opcode outside of a macro definition is an error.
+map_coreop[".endmacro_0"] = function(params)
+ wfatal(".endmacro without .macro")
+end
+
+-- Dump all macros and their contents (with -PP only).
+local function dumpmacros(out, lvl)
+ sort(mac_list)
+ out:write("Macros:\n")
+ for _,opname in ipairs(mac_list) do
+ local name = sub(opname, 1, -3)
+ local params, lines = map_op[opname]()
+ out:write(format(" %-20s %s\n", name, concat(params, ", ")))
+ if lvl > 1 then
+ for _,line in ipairs(lines) do
+ out:write(" |", line, "\n")
+ end
+ out:write("\n")
+ end
+ end
+ out:write("\n")
+end
+
+-- Check for unfinished macro definitions.
+local function checkmacros()
+ if mac_capture then
+ wprinterr(g_fname, ":", mac_lineno,
+ ": error: unfinished .macro `", mac_name ,"'\n")
+ end
+end
+
+------------------------------------------------------------------------------
+
+-- Support variables for captures.
+local cap_lineno, cap_name
+local cap_buffers = {}
+local cap_used = {}
+
+-- Start a capture.
+map_coreop[".capture_1"] = function(params)
+ if not params then return "name" end
+ wflush()
+ local name = params[1]
+ if not match(name, "^[%a_][%w_]*$") then
+ wfatal("bad capture name `"..name.."'")
+ end
+ if cap_name then
+ wfatal("already capturing to `"..cap_name.."' since line "..cap_lineno)
+ end
+ cap_name = name
+ cap_lineno = g_lineno
+ -- Create or continue a capture buffer and start the output line capture.
+ local buf = cap_buffers[name]
+ if not buf then buf = {}; cap_buffers[name] = buf end
+ g_capbuffer = buf
+ g_synclineno = 0
+end
+
+-- Stop a capture.
+map_coreop[".endcapture_0"] = function(params)
+ wflush()
+ if not cap_name then wfatal(".endcapture without a valid .capture") end
+ cap_name = nil
+ cap_lineno = nil
+ g_capbuffer = nil
+ g_synclineno = 0
+end
+
+-- Dump a capture buffer.
+map_coreop[".dumpcapture_1"] = function(params)
+ if not params then return "name" end
+ wflush()
+ local name = params[1]
+ if not match(name, "^[%a_][%w_]*$") then
+ wfatal("bad capture name `"..name.."'")
+ end
+ cap_used[name] = true
+ wline(function(out)
+ local buf = cap_buffers[name]
+ if buf then wdumplines(out, buf) end
+ end)
+ g_synclineno = 0
+end
+
+-- Dump all captures and their buffers (with -PP only).
+local function dumpcaptures(out, lvl)
+ out:write("Captures:\n")
+ for name,buf in pairs(cap_buffers) do
+ out:write(format(" %-20s %4s)\n", name, "("..#buf))
+ if lvl > 1 then
+ local bar = rep("=", 76)
+ out:write(" ", bar, "\n")
+ for _,line in ipairs(buf) do
+ out:write(" ", line, "\n")
+ end
+ out:write(" ", bar, "\n\n")
+ end
+ end
+ out:write("\n")
+end
+
+-- Check for unfinished or unused captures.
+local function checkcaptures()
+ if cap_name then
+ wprinterr(g_fname, ":", cap_lineno,
+ ": error: unfinished .capture `", cap_name,"'\n")
+ return
+ end
+ for name in pairs(cap_buffers) do
+ if not cap_used[name] then
+ wprinterr(g_fname, ":*: error: missing .dumpcapture ", name ,"\n")
+ end
+ end
+end
+
+------------------------------------------------------------------------------
+
+-- Sections names.
+local map_sections = {}
+
+-- Pseudo-opcode to define code sections.
+-- TODO: Data sections, BSS sections. Needs extra C code and API.
+map_coreop[".section_*"] = function(params)
+ if not params then return "name..." end
+ if #map_sections > 0 then werror("duplicate section definition") end
+ wflush()
+ for sn,name in ipairs(params) do
+ local opname = "."..name.."_0"
+ if not match(name, "^[%a][%w_]*$") or
+ map_op[opname] or map_op["."..name.."_*"] then
+ werror("bad section name `"..name.."'")
+ end
+ map_sections[#map_sections+1] = name
+ wline(format("#define DASM_SECTION_%s\t%d", upper(name), sn-1))
+ map_op[opname] = function(params) g_arch.section(sn-1) end
+ end
+ wline(format("#define DASM_MAXSECTION\t\t%d", #map_sections))
+end
+
+-- Dump all sections.
+local function dumpsections(out, lvl)
+ out:write("Sections:\n")
+ for _,name in ipairs(map_sections) do
+ out:write(format(" %s\n", name))
+ end
+ out:write("\n")
+end
+
+------------------------------------------------------------------------------
+
+-- Replacement for customized Lua, which lacks the package library.
+local prefix = ""
+if not require then
+ function require(name)
+ local fp = assert(io.open(prefix..name..".lua"))
+ local s = fp:read("*a")
+ assert(fp:close())
+ return assert(loadstring(s, "@"..name..".lua"))()
+ end
+end
+
+-- Load architecture-specific module.
+local function loadarch(arch)
+ if not match(arch, "^[%w_]+$") then return "bad arch name" end
+ local ok, m_arch = pcall(require, "dasm_"..arch)
+ if not ok then return "cannot load module: "..m_arch end
+ g_arch = m_arch
+ wflush = m_arch.passcb(wline, werror, wfatal, wwarn)
+ m_arch.setup(arch, g_opt)
+ map_op, map_def = m_arch.mergemaps(map_coreop, map_def)
+end
+
+-- Dump architecture description.
+function opt_map.dumparch(args)
+ local name = optparam(args)
+ if not g_arch then
+ local err = loadarch(name)
+ if err then opterror(err) end
+ end
+
+ local t = {}
+ for name in pairs(map_coreop) do t[#t+1] = name end
+ for name in pairs(map_op) do t[#t+1] = name end
+ sort(t)
+
+ local out = stdout
+ local _arch = g_arch._info
+ out:write(format("%s version %s, released %s, %s\n",
+ _info.name, _info.version, _info.release, _info.url))
+ g_arch.dumparch(out)
+
+ local pseudo = true
+ out:write("Pseudo-Opcodes:\n")
+ for _,sname in ipairs(t) do
+ local name, nparam = match(sname, "^(.+)_([0-9%*])$")
+ if name then
+ if pseudo and sub(name, 1, 1) ~= "." then
+ out:write("\nOpcodes:\n")
+ pseudo = false
+ end
+ local f = map_op[sname]
+ local s
+ if nparam ~= "*" then nparam = nparam + 0 end
+ if nparam == 0 then
+ s = ""
+ elseif type(f) == "string" then
+ s = map_op[".template__"](nil, f, nparam)
+ else
+ s = f(nil, nparam)
+ end
+ if type(s) == "table" then
+ for _,s2 in ipairs(s) do
+ out:write(format(" %-12s %s\n", name, s2))
+ end
+ else
+ out:write(format(" %-12s %s\n", name, s))
+ end
+ end
+ end
+ out:write("\n")
+ exit(0)
+end
+
+-- Pseudo-opcode to set the architecture.
+-- Only initially available (map_op is replaced when called).
+map_op[".arch_1"] = function(params)
+ if not params then return "name" end
+ local err = loadarch(params[1])
+ if err then wfatal(err) end
+ wline(format("#if DASM_VERSION != %d", _info.vernum))
+ wline('#error "Version mismatch between DynASM and included encoding engine"')
+ wline("#endif")
+end
+
+-- Dummy .arch pseudo-opcode to improve the error report.
+map_coreop[".arch_1"] = function(params)
+ if not params then return "name" end
+ wfatal("duplicate .arch statement")
+end
+
+------------------------------------------------------------------------------
+
+-- Dummy pseudo-opcode. Don't confuse '.nop' with 'nop'.
+map_coreop[".nop_*"] = function(params)
+ if not params then return "[ignored...]" end
+end
+
+-- Pseudo-opcodes to raise errors.
+map_coreop[".error_1"] = function(params)
+ if not params then return "message" end
+ werror(params[1])
+end
+
+map_coreop[".fatal_1"] = function(params)
+ if not params then return "message" end
+ wfatal(params[1])
+end
+
+-- Dump all user defined elements.
+local function dumpdef(out)
+ local lvl = g_opt.dumpdef
+ if lvl == 0 then return end
+ dumpsections(out, lvl)
+ dumpdefines(out, lvl)
+ if g_arch then g_arch.dumpdef(out, lvl) end
+ dumpmacros(out, lvl)
+ dumpcaptures(out, lvl)
+end
+
+------------------------------------------------------------------------------
+
+-- Helper for splitstmt.
+local splitlvl
+
+local function splitstmt_one(c)
+ if c == "(" then
+ splitlvl = ")"..splitlvl
+ elseif c == "[" then
+ splitlvl = "]"..splitlvl
+ elseif c == "{" then
+ splitlvl = "}"..splitlvl
+ elseif c == ")" or c == "]" or c == "}" then
+ if sub(splitlvl, 1, 1) ~= c then werror("unbalanced (), [] or {}") end
+ splitlvl = sub(splitlvl, 2)
+ elseif splitlvl == "" then
+ return " \0 "
+ end
+ return c
+end
+
+-- Split statement into (pseudo-)opcode and params.
+local function splitstmt(stmt)
+ -- Convert label with trailing-colon into .label statement.
+ local label = match(stmt, "^%s*(.+):%s*$")
+ if label then return ".label", {label} end
+
+ -- Split at commas and equal signs, but obey parentheses and brackets.
+ splitlvl = ""
+ stmt = gsub(stmt, "[,%(%)%[%]{}]", splitstmt_one)
+ if splitlvl ~= "" then werror("unbalanced () or []") end
+
+ -- Split off opcode.
+ local op, other = match(stmt, "^%s*([^%s%z]+)%s*(.*)$")
+ if not op then werror("bad statement syntax") end
+
+ -- Split parameters.
+ local params = {}
+ for p in gmatch(other, "%s*(%Z+)%z?") do
+ params[#params+1] = gsub(p, "%s+$", "")
+ end
+ if #params > 16 then werror("too many parameters") end
+
+ params.op = op
+ return op, params
+end
+
+-- Process a single statement.
+dostmt = function(stmt)
+ -- Ignore empty statements.
+ if match(stmt, "^%s*$") then return end
+
+ -- Capture macro defs before substitution.
+ if mac_capture then return mac_capture(stmt) end
+ stmt = definesubst(stmt)
+
+ -- Emit C code without parsing the line.
+ if sub(stmt, 1, 1) == "|" then
+ local tail = sub(stmt, 2)
+ wflush()
+ if sub(tail, 1, 2) == "//" then wcomment(tail) else wline(tail, true) end
+ return
+ end
+
+ -- Split into (pseudo-)opcode and params.
+ local op, params = splitstmt(stmt)
+
+ -- Get opcode handler (matching # of parameters or generic handler).
+ local f = map_op[op.."_"..#params] or map_op[op.."_*"]
+ if not f then
+ if not g_arch then wfatal("first statement must be .arch") end
+ -- Improve error report.
+ for i=0,9 do
+ if map_op[op.."_"..i] then
+ werror("wrong number of parameters for `"..op.."'")
+ end
+ end
+ werror("unknown statement `"..op.."'")
+ end
+
+ -- Call opcode handler or special handler for template strings.
+ if type(f) == "string" then
+ map_op[".template__"](params, f)
+ else
+ f(params)
+ end
+end
+
+-- Process a single line.
+local function doline(line)
+ if g_opt.flushline then wflush() end
+
+ -- Assembler line?
+ local indent, aline = match(line, "^(%s*)%|(.*)$")
+ if not aline then
+ -- No, plain C code line, need to flush first.
+ wflush()
+ wsync()
+ wline(line, false)
+ return
+ end
+
+ g_indent = indent -- Remember current line indentation.
+
+ -- Emit C code (even from macros). Avoids echo and line parsing.
+ if sub(aline, 1, 1) == "|" then
+ if not mac_capture then
+ wsync()
+ elseif g_opt.comment then
+ wsync()
+ wcomment(aline)
+ end
+ dostmt(aline)
+ return
+ end
+
+ -- Echo assembler line as a comment.
+ if g_opt.comment then
+ wsync()
+ wcomment(aline)
+ end
+
+ -- Strip assembler comments.
+ aline = gsub(aline, "//.*$", "")
+
+ -- Split line into statements at semicolons.
+ if match(aline, ";") then
+ for stmt in gmatch(aline, "[^;]+") do dostmt(stmt) end
+ else
+ dostmt(aline)
+ end
+end
+
+------------------------------------------------------------------------------
+
+-- Write DynASM header.
+local function dasmhead(out)
+ out:write(format([[
+/*
+** This file has been pre-processed with DynASM.
+** %s
+** DynASM version %s, DynASM %s version %s
+** DO NOT EDIT! The original file is in "%s".
+*/
+
+]], _info.url,
+ _info.version, g_arch._info.arch, g_arch._info.version,
+ g_fname))
+end
+
+-- Read input file.
+readfile = function(fin)
+ g_indent = ""
+ g_lineno = 0
+ g_synclineno = -1
+
+ -- Process all lines.
+ for line in fin:lines() do
+ g_lineno = g_lineno + 1
+ g_curline = line
+ local ok, err = pcall(doline, line)
+ if not ok and wprinterr(err, "\n") then return true end
+ end
+ wflush()
+
+ -- Close input file.
+ assert(fin == stdin or fin:close())
+end
+
+-- Write output file.
+local function writefile(outfile)
+ local fout
+
+ -- Open output file.
+ if outfile == nil or outfile == "-" then
+ fout = stdout
+ else
+ fout = assert(io.open(outfile, "w"))
+ end
+
+ -- Write all buffered lines
+ wdumplines(fout, g_wbuffer)
+
+ -- Close output file.
+ assert(fout == stdout or fout:close())
+
+ -- Optionally dump definitions.
+ dumpdef(fout == stdout and stderr or stdout)
+end
+
+-- Translate an input file to an output file.
+local function translate(infile, outfile)
+ g_wbuffer = {}
+ g_indent = ""
+ g_lineno = 0
+ g_synclineno = -1
+
+ -- Put header.
+ wline(dasmhead)
+
+ -- Read input file.
+ local fin
+ if infile == "-" then
+ g_fname = "(stdin)"
+ fin = stdin
+ else
+ g_fname = infile
+ fin = assert(io.open(infile, "r"))
+ end
+ readfile(fin)
+
+ -- Check for errors.
+ if not g_arch then
+ wprinterr(g_fname, ":*: error: missing .arch directive\n")
+ end
+ checkconds()
+ checkmacros()
+ checkcaptures()
+
+ if g_errcount ~= 0 then
+ stderr:write(g_fname, ":*: info: ", g_errcount, " error",
+ (type(g_errcount) == "number" and g_errcount > 1) and "s" or "",
+ " in input file -- no output file generated.\n")
+ dumpdef(stderr)
+ exit(1)
+ end
+
+ -- Write output file.
+ writefile(outfile)
+end
+
+------------------------------------------------------------------------------
+
+-- Print help text.
+function opt_map.help()
+ stdout:write("DynASM -- ", _info.description, ".\n")
+ stdout:write("DynASM ", _info.version, " ", _info.release, " ", _info.url, "\n")
+ stdout:write[[
+
+Usage: dynasm [OPTION]... INFILE.dasc|-
+
+ -h, --help Display this help text.
+ -V, --version Display version and copyright information.
+
+ -o, --outfile FILE Output file name (default is stdout).
+ -I, --include DIR Add directory to the include search path.
+
+ -c, --ccomment Use /* */ comments for assembler lines.
+ -C, --cppcomment Use // comments for assembler lines (default).
+ -N, --nocomment Suppress assembler lines in output.
+ -M, --maccomment Show macro expansions as comments (default off).
+
+ -L, --nolineno Suppress CPP line number information in output.
+ -F, --flushline Flush action list for every line.
+
+ -D NAME[=SUBST] Define a substitution.
+ -U NAME Undefine a substitution.
+
+ -P, --dumpdef Dump defines, macros, etc. Repeat for more output.
+ -A, --dumparch ARCH Load architecture ARCH and dump description.
+]]
+ exit(0)
+end
+
+-- Print version information.
+function opt_map.version()
+ stdout:write(format("%s version %s, released %s\n%s\n\n%s",
+ _info.name, _info.version, _info.release, _info.url, _info.copyright))
+ exit(0)
+end
+
+-- Misc. options.
+function opt_map.outfile(args) g_opt.outfile = optparam(args) end
+function opt_map.include(args) insert(g_opt.include, 1, optparam(args)) end
+function opt_map.ccomment() g_opt.comment = "/*|"; g_opt.endcomment = " */" end
+function opt_map.cppcomment() g_opt.comment = "//|"; g_opt.endcomment = "" end
+function opt_map.nocomment() g_opt.comment = false end
+function opt_map.maccomment() g_opt.maccomment = true end
+function opt_map.nolineno() g_opt.cpp = false end
+function opt_map.flushline() g_opt.flushline = true end
+function opt_map.dumpdef() g_opt.dumpdef = g_opt.dumpdef + 1 end
+
+------------------------------------------------------------------------------
+
+-- Short aliases for long options.
+local opt_alias = {
+ h = "help", ["?"] = "help", V = "version",
+ o = "outfile", I = "include",
+ c = "ccomment", C = "cppcomment", N = "nocomment", M = "maccomment",
+ L = "nolineno", F = "flushline",
+ P = "dumpdef", A = "dumparch",
+}
+
+-- Parse single option.
+local function parseopt(opt, args)
+ opt_current = #opt == 1 and "-"..opt or "--"..opt
+ local f = opt_map[opt] or opt_map[opt_alias[opt]]
+ if not f then
+ opterror("unrecognized option `", opt_current, "'. Try `--help'.\n")
+ end
+ f(args)
+end
+
+-- Parse arguments.
+local function parseargs(args)
+ -- Default options.
+ g_opt.comment = "//|"
+ g_opt.endcomment = ""
+ g_opt.cpp = true
+ g_opt.dumpdef = 0
+ g_opt.include = { "" }
+
+ -- Process all option arguments.
+ args.argn = 1
+ repeat
+ local a = args[args.argn]
+ if not a then break end
+ local lopt, opt = match(a, "^%-(%-?)(.+)")
+ if not opt then break end
+ args.argn = args.argn + 1
+ if lopt == "" then
+ -- Loop through short options.
+ for o in gmatch(opt, ".") do parseopt(o, args) end
+ else
+ -- Long option.
+ parseopt(opt, args)
+ end
+ until false
+
+ -- Check for proper number of arguments.
+ local nargs = #args - args.argn + 1
+ if nargs ~= 1 then
+ if nargs == 0 then
+ if g_opt.dumpdef > 0 then return dumpdef(stdout) end
+ end
+ opt_map.help()
+ end
+
+ -- Translate a single input file to a single output file
+ -- TODO: Handle multiple files?
+ translate(args[args.argn], g_opt.outfile)
+end
+
+------------------------------------------------------------------------------
+
+-- Add the directory dynasm.lua resides in to the Lua module search path.
+local arg = arg
+if arg and arg[0] then
+ prefix = match(arg[0], "^(.*[/\\])")
+ if package and prefix then package.path = prefix.."?.lua;"..package.path end
+end
+
+-- Start DynASM.
+parseargs{...}
+
+------------------------------------------------------------------------------
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/etc/luajit.1 b/src/3rdparty/LuaJIT-2.0.5/etc/luajit.1
new file mode 100644
index 0000000..0d263db
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/etc/luajit.1
@@ -0,0 +1,88 @@
+.TH luajit 1 "" "" "LuaJIT documentation"
+.SH NAME
+luajit \- Just-In-Time Compiler for the Lua Language
+\fB
+.SH SYNOPSIS
+.B luajit
+[\fIoptions\fR]... [\fIscript\fR [\fIargs\fR]...]
+.SH "WEB SITE"
+.IR http://luajit.org
+.SH DESCRIPTION
+.PP
+This is the command-line program to run Lua programs with \fBLuaJIT\fR.
+.PP
+\fBLuaJIT\fR is a just-in-time (JIT) compiler for the Lua language.
+The virtual machine (VM) is based on a fast interpreter combined with
+a trace compiler. It can significantly improve the performance of Lua programs.
+.PP
+\fBLuaJIT\fR is API\- and ABI-compatible with the VM of the standard
+Lua\ 5.1 interpreter. When embedding the VM into an application,
+the built library can be used as a drop-in replacement.
+.SH OPTIONS
+.TP
+.BI "\-e " chunk
+Run the given chunk of Lua code.
+.TP
+.BI "\-l " library
+Load the named library, just like \fBrequire("\fR\fIlibrary\fR\fB")\fR.
+.TP
+.BI "\-b " ...
+Save or list bytecode. Run without arguments to get help on options.
+.TP
+.BI "\-j " command
+Perform LuaJIT control command (optional space after \fB\-j\fR).
+.TP
+.BI "\-O" [opt]
+Control LuaJIT optimizations.
+.TP
+.B "\-i"
+Run in interactive mode.
+.TP
+.B "\-v"
+Show \fBLuaJIT\fR version.
+.TP
+.B "\-E"
+Ignore environment variables.
+.TP
+.B "\-\-"
+Stop processing options.
+.TP
+.B "\-"
+Read script from stdin instead.
+.PP
+After all options are processed, the given \fIscript\fR is run.
+The arguments are passed in the global \fIarg\fR table.
+.PP
+Interactive mode is only entered, if no \fIscript\fR and no \fB\-e\fR
+option is given. Interactive mode can be left with EOF (\fICtrl\-Z\fB).
+.SH EXAMPLES
+.TP
+luajit hello.lua world
+
+Prints "Hello world", assuming \fIhello.lua\fR contains:
+.br
+ print("Hello", arg[1])
+.TP
+luajit \-e "local x=0; for i=1,1e9 do x=x+i end; print(x)"
+
+Calculates the sum of the numbers from 1 to 1000000000.
+.br
+And finishes in a reasonable amount of time, too.
+.TP
+luajit \-jv \-e "for i=1,10 do for j=1,10 do for k=1,100 do end end end"
+
+Runs some nested loops and shows the resulting traces.
+.SH COPYRIGHT
+.PP
+\fBLuaJIT\fR is Copyright \(co 2005-2017 Mike Pall.
+.br
+\fBLuaJIT\fR is open source software, released under the MIT license.
+.SH SEE ALSO
+.PP
+More details in the provided HTML docs or at:
+.IR http://luajit.org
+.br
+More about the Lua language can be found at:
+.IR http://lua.org/docs.html
+.PP
+lua(1)
diff --git a/src/3rdparty/LuaJIT-2.0.5/etc/luajit.pc b/src/3rdparty/LuaJIT-2.0.5/etc/luajit.pc
new file mode 100644
index 0000000..36840ab
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/etc/luajit.pc
@@ -0,0 +1,25 @@
+# Package information for LuaJIT to be used by pkg-config.
+majver=2
+minver=0
+relver=5
+version=${majver}.${minver}.${relver}
+abiver=5.1
+
+prefix=/usr/local
+multilib=lib
+exec_prefix=${prefix}
+libdir=${exec_prefix}/${multilib}
+libname=luajit-${abiver}
+includedir=${prefix}/include/luajit-${majver}.${minver}
+
+INSTALL_LMOD=${prefix}/share/lua/${abiver}
+INSTALL_CMOD=${prefix}/${multilib}/lua/${abiver}
+
+Name: LuaJIT
+Description: Just-in-time compiler for Lua
+URL: http://luajit.org
+Version: ${version}
+Requires:
+Libs: -L${libdir} -l${libname}
+Libs.private: -Wl,-E -lm -ldl
+Cflags: -I${includedir}
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lauxlib.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lauxlib.h
new file mode 100644
index 0000000..fed1491
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lauxlib.h
@@ -0,0 +1,167 @@
+/*
+** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $
+** Auxiliary functions for building Lua libraries
+** See Copyright Notice in lua.h
+*/
+
+
+#ifndef lauxlib_h
+#define lauxlib_h
+
+
+#include <stddef.h>
+#include <stdio.h>
+
+#include "lua.h"
+
+
+#define luaL_getn(L,i) ((int)lua_objlen(L, i))
+#define luaL_setn(L,i,j) ((void)0) /* no op! */
+
+/* extra error code for `luaL_load' */
+#define LUA_ERRFILE (LUA_ERRERR+1)
+
+typedef struct luaL_Reg {
+ const char *name;
+ lua_CFunction func;
+} luaL_Reg;
+
+LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
+ const luaL_Reg *l, int nup);
+LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
+ const luaL_Reg *l);
+LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
+LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
+LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);
+LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
+LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,
+ size_t *l);
+LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,
+ const char *def, size_t *l);
+LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg);
+LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def);
+
+LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);
+LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,
+ lua_Integer def);
+
+LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
+LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
+LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
+
+LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
+LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
+
+LUALIB_API void (luaL_where) (lua_State *L, int lvl);
+LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
+
+LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
+ const char *const lst[]);
+
+LUALIB_API int (luaL_ref) (lua_State *L, int t);
+LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
+
+LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);
+LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz,
+ const char *name);
+LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
+
+LUALIB_API lua_State *(luaL_newstate) (void);
+
+
+LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
+ const char *r);
+
+LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,
+ const char *fname, int szhint);
+
+/* From Lua 5.2. */
+LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname);
+LUALIB_API int luaL_execresult(lua_State *L, int stat);
+LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,
+ const char *mode);
+LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,
+ const char *name, const char *mode);
+LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,
+ int level);
+
+
+/*
+** ===============================================================
+** some useful macros
+** ===============================================================
+*/
+
+#define luaL_argcheck(L, cond,numarg,extramsg) \
+ ((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))
+#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
+#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
+#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
+#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
+#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
+#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
+
+#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
+
+#define luaL_dofile(L, fn) \
+ (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
+
+#define luaL_dostring(L, s) \
+ (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
+
+#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
+
+#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
+
+/*
+** {======================================================
+** Generic Buffer manipulation
+** =======================================================
+*/
+
+
+
+typedef struct luaL_Buffer {
+ char *p; /* current position in buffer */
+ int lvl; /* number of strings in the stack (level) */
+ lua_State *L;
+ char buffer[LUAL_BUFFERSIZE];
+} luaL_Buffer;
+
+#define luaL_addchar(B,c) \
+ ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \
+ (*(B)->p++ = (char)(c)))
+
+/* compatibility only */
+#define luaL_putchar(B,c) luaL_addchar(B,c)
+
+#define luaL_addsize(B,n) ((B)->p += (n))
+
+LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
+LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B);
+LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
+LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);
+LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);
+LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
+
+
+/* }====================================================== */
+
+
+/* compatibility with ref system */
+
+/* pre-defined references */
+#define LUA_NOREF (-2)
+#define LUA_REFNIL (-1)
+
+#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \
+ (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0))
+
+#define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref))
+
+#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))
+
+
+#define luaL_reg luaL_Reg
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_alloc.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_alloc.h
new file mode 100644
index 0000000..f87a7cf
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_alloc.h
@@ -0,0 +1,17 @@
+/*
+** Bundled memory allocator.
+** Donated to the public domain.
+*/
+
+#ifndef _LJ_ALLOC_H
+#define _LJ_ALLOC_H
+
+#include "lj_def.h"
+
+#ifndef LUAJIT_USE_SYSMALLOC
+LJ_FUNC void *lj_alloc_create(void);
+LJ_FUNC void lj_alloc_destroy(void *msp);
+LJ_FUNC void *lj_alloc_f(void *msp, void *ptr, size_t osize, size_t nsize);
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_arch.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_arch.h
new file mode 100644
index 0000000..5f7e445
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_arch.h
@@ -0,0 +1,452 @@
+/*
+** Target architecture selection.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_ARCH_H
+#define _LJ_ARCH_H
+
+#include "lua.h"
+
+/* Target endianess. */
+#define LUAJIT_LE 0
+#define LUAJIT_BE 1
+
+/* Target architectures. */
+#define LUAJIT_ARCH_X86 1
+#define LUAJIT_ARCH_x86 1
+#define LUAJIT_ARCH_X64 2
+#define LUAJIT_ARCH_x64 2
+#define LUAJIT_ARCH_ARM 3
+#define LUAJIT_ARCH_arm 3
+#define LUAJIT_ARCH_PPC 4
+#define LUAJIT_ARCH_ppc 4
+#define LUAJIT_ARCH_PPCSPE 5
+#define LUAJIT_ARCH_ppcspe 5
+#define LUAJIT_ARCH_MIPS 6
+#define LUAJIT_ARCH_mips 6
+
+/* Target OS. */
+#define LUAJIT_OS_OTHER 0
+#define LUAJIT_OS_WINDOWS 1
+#define LUAJIT_OS_LINUX 2
+#define LUAJIT_OS_OSX 3
+#define LUAJIT_OS_BSD 4
+#define LUAJIT_OS_POSIX 5
+
+/* Select native target if no target defined. */
+#ifndef LUAJIT_TARGET
+
+#if defined(__i386) || defined(__i386__) || defined(_M_IX86)
+#define LUAJIT_TARGET LUAJIT_ARCH_X86
+#elif defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
+#define LUAJIT_TARGET LUAJIT_ARCH_X64
+#elif defined(__arm__) || defined(__arm) || defined(__ARM__) || defined(__ARM)
+#define LUAJIT_TARGET LUAJIT_ARCH_ARM
+#elif defined(__ppc__) || defined(__ppc) || defined(__PPC__) || defined(__PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__POWERPC) || defined(_M_PPC)
+#ifdef __NO_FPRS__
+#define LUAJIT_TARGET LUAJIT_ARCH_PPCSPE
+#else
+#define LUAJIT_TARGET LUAJIT_ARCH_PPC
+#endif
+#elif defined(__mips__) || defined(__mips) || defined(__MIPS__) || defined(__MIPS)
+#define LUAJIT_TARGET LUAJIT_ARCH_MIPS
+#else
+#error "No support for this architecture (yet)"
+#endif
+
+#endif
+
+/* Select native OS if no target OS defined. */
+#ifndef LUAJIT_OS
+
+#if defined(_WIN32) && !defined(_XBOX_VER)
+#define LUAJIT_OS LUAJIT_OS_WINDOWS
+#elif defined(__linux__)
+#define LUAJIT_OS LUAJIT_OS_LINUX
+#elif defined(__MACH__) && defined(__APPLE__)
+#define LUAJIT_OS LUAJIT_OS_OSX
+#elif (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
+ defined(__NetBSD__) || defined(__OpenBSD__) || \
+ defined(__DragonFly__)) && !defined(__ORBIS__)
+#define LUAJIT_OS LUAJIT_OS_BSD
+#elif (defined(__sun__) && defined(__svr4__))
+#define LUAJIT_OS LUAJIT_OS_POSIX
+#elif defined(__CYGWIN__)
+#define LJ_TARGET_CYGWIN 1
+#define LUAJIT_OS LUAJIT_OS_POSIX
+#else
+#define LUAJIT_OS LUAJIT_OS_OTHER
+#endif
+
+#endif
+
+/* Set target OS properties. */
+#if LUAJIT_OS == LUAJIT_OS_WINDOWS
+#define LJ_OS_NAME "Windows"
+#elif LUAJIT_OS == LUAJIT_OS_LINUX
+#define LJ_OS_NAME "Linux"
+#elif LUAJIT_OS == LUAJIT_OS_OSX
+#define LJ_OS_NAME "OSX"
+#elif LUAJIT_OS == LUAJIT_OS_BSD
+#define LJ_OS_NAME "BSD"
+#elif LUAJIT_OS == LUAJIT_OS_POSIX
+#define LJ_OS_NAME "POSIX"
+#else
+#define LJ_OS_NAME "Other"
+#endif
+
+#define LJ_TARGET_WINDOWS (LUAJIT_OS == LUAJIT_OS_WINDOWS)
+#define LJ_TARGET_LINUX (LUAJIT_OS == LUAJIT_OS_LINUX)
+#define LJ_TARGET_OSX (LUAJIT_OS == LUAJIT_OS_OSX)
+#define LJ_TARGET_IOS (LJ_TARGET_OSX && LUAJIT_TARGET == LUAJIT_ARCH_ARM)
+#define LJ_TARGET_POSIX (LUAJIT_OS > LUAJIT_OS_WINDOWS)
+#define LJ_TARGET_DLOPEN LJ_TARGET_POSIX
+
+#ifdef __CELLOS_LV2__
+#define LJ_TARGET_PS3 1
+#define LJ_TARGET_CONSOLE 1
+#endif
+
+#ifdef __ORBIS__
+#define LJ_TARGET_PS4 1
+#define LJ_TARGET_CONSOLE 1
+#undef NULL
+#define NULL ((void*)0)
+#endif
+
+#ifdef __psp2__
+#define LJ_TARGET_PSVITA 1
+#define LJ_TARGET_CONSOLE 1
+#endif
+
+#if _XBOX_VER >= 200
+#define LJ_TARGET_XBOX360 1
+#define LJ_TARGET_CONSOLE 1
+#endif
+
+#define LJ_NUMMODE_SINGLE 0 /* Single-number mode only. */
+#define LJ_NUMMODE_SINGLE_DUAL 1 /* Default to single-number mode. */
+#define LJ_NUMMODE_DUAL 2 /* Dual-number mode only. */
+#define LJ_NUMMODE_DUAL_SINGLE 3 /* Default to dual-number mode. */
+
+/* Set target architecture properties. */
+#if LUAJIT_TARGET == LUAJIT_ARCH_X86
+
+#define LJ_ARCH_NAME "x86"
+#define LJ_ARCH_BITS 32
+#define LJ_ARCH_ENDIAN LUAJIT_LE
+#if LJ_TARGET_WINDOWS || LJ_TARGET_CYGWIN
+#define LJ_ABI_WIN 1
+#else
+#define LJ_ABI_WIN 0
+#endif
+#define LJ_TARGET_X86 1
+#define LJ_TARGET_X86ORX64 1
+#define LJ_TARGET_EHRETREG 0
+#define LJ_TARGET_MASKSHIFT 1
+#define LJ_TARGET_MASKROT 1
+#define LJ_TARGET_UNALIGNED 1
+#define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE_DUAL
+
+#elif LUAJIT_TARGET == LUAJIT_ARCH_X64
+
+#define LJ_ARCH_NAME "x64"
+#define LJ_ARCH_BITS 64
+#define LJ_ARCH_ENDIAN LUAJIT_LE
+#if LJ_TARGET_WINDOWS || LJ_TARGET_CYGWIN
+#define LJ_ABI_WIN 1
+#else
+#define LJ_ABI_WIN 0
+#endif
+#define LJ_TARGET_X64 1
+#define LJ_TARGET_X86ORX64 1
+#define LJ_TARGET_EHRETREG 0
+#define LJ_TARGET_JUMPRANGE 31 /* +-2^31 = +-2GB */
+#define LJ_TARGET_MASKSHIFT 1
+#define LJ_TARGET_MASKROT 1
+#define LJ_TARGET_UNALIGNED 1
+#define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE_DUAL
+
+#elif LUAJIT_TARGET == LUAJIT_ARCH_ARM
+
+#define LJ_ARCH_NAME "arm"
+#define LJ_ARCH_BITS 32
+#define LJ_ARCH_ENDIAN LUAJIT_LE
+#if !defined(LJ_ARCH_HASFPU) && __SOFTFP__
+#define LJ_ARCH_HASFPU 0
+#endif
+#if !defined(LJ_ABI_SOFTFP) && !__ARM_PCS_VFP
+#define LJ_ABI_SOFTFP 1
+#endif
+#define LJ_ABI_EABI 1
+#define LJ_TARGET_ARM 1
+#define LJ_TARGET_EHRETREG 0
+#define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */
+#define LJ_TARGET_MASKSHIFT 0
+#define LJ_TARGET_MASKROT 1
+#define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */
+#define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL
+
+#if __ARM_ARCH____ARM_ARCH_8__ || __ARM_ARCH_8A__
+#define LJ_ARCH_VERSION 80
+#elif __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH_7S__ || __ARM_ARCH_7VE__
+#define LJ_ARCH_VERSION 70
+#elif __ARM_ARCH_6T2__
+#define LJ_ARCH_VERSION 61
+#elif __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6K__ || __ARM_ARCH_6Z__ || __ARM_ARCH_6ZK__
+#define LJ_ARCH_VERSION 60
+#else
+#define LJ_ARCH_VERSION 50
+#endif
+
+#elif LUAJIT_TARGET == LUAJIT_ARCH_PPC
+
+#define LJ_ARCH_NAME "ppc"
+#if _LP64
+#define LJ_ARCH_BITS 64
+#else
+#define LJ_ARCH_BITS 32
+#endif
+#define LJ_ARCH_ENDIAN LUAJIT_BE
+#define LJ_TARGET_PPC 1
+#define LJ_TARGET_EHRETREG 3
+#define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */
+#define LJ_TARGET_MASKSHIFT 0
+#define LJ_TARGET_MASKROT 1
+#define LJ_TARGET_UNIFYROT 1 /* Want only IR_BROL. */
+#define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL_SINGLE
+
+#if _ARCH_PWR7
+#define LJ_ARCH_VERSION 70
+#elif _ARCH_PWR6
+#define LJ_ARCH_VERSION 60
+#elif _ARCH_PWR5X
+#define LJ_ARCH_VERSION 51
+#elif _ARCH_PWR5
+#define LJ_ARCH_VERSION 50
+#elif _ARCH_PWR4
+#define LJ_ARCH_VERSION 40
+#else
+#define LJ_ARCH_VERSION 0
+#endif
+#if __PPC64__ || __powerpc64__ || LJ_TARGET_CONSOLE
+#define LJ_ARCH_PPC64 1
+#define LJ_ARCH_NOFFI 1
+#endif
+#if _ARCH_PPCSQ
+#define LJ_ARCH_SQRT 1
+#endif
+#if _ARCH_PWR5X
+#define LJ_ARCH_ROUND 1
+#endif
+#if __PPU__
+#define LJ_ARCH_CELL 1
+#endif
+#if LJ_TARGET_XBOX360
+#define LJ_ARCH_XENON 1
+#endif
+
+#elif LUAJIT_TARGET == LUAJIT_ARCH_PPCSPE
+
+#define LJ_ARCH_NAME "ppcspe"
+#define LJ_ARCH_BITS 32
+#define LJ_ARCH_ENDIAN LUAJIT_BE
+#ifndef LJ_ABI_SOFTFP
+#define LJ_ABI_SOFTFP 1
+#endif
+#define LJ_ABI_EABI 1
+#define LJ_TARGET_PPCSPE 1
+#define LJ_TARGET_EHRETREG 3
+#define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */
+#define LJ_TARGET_MASKSHIFT 0
+#define LJ_TARGET_MASKROT 1
+#define LJ_TARGET_UNIFYROT 1 /* Want only IR_BROL. */
+#define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE
+#define LJ_ARCH_NOFFI 1 /* NYI: comparisons, calls. */
+#define LJ_ARCH_NOJIT 1
+
+#elif LUAJIT_TARGET == LUAJIT_ARCH_MIPS
+
+#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL)
+#define LJ_ARCH_NAME "mipsel"
+#define LJ_ARCH_ENDIAN LUAJIT_LE
+#else
+#define LJ_ARCH_NAME "mips"
+#define LJ_ARCH_ENDIAN LUAJIT_BE
+#endif
+#define LJ_ARCH_BITS 32
+#define LJ_TARGET_MIPS 1
+#define LJ_TARGET_EHRETREG 4
+#define LJ_TARGET_JUMPRANGE 27 /* 2*2^27 = 256MB-aligned region */
+#define LJ_TARGET_MASKSHIFT 1
+#define LJ_TARGET_MASKROT 1
+#define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */
+#define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE
+
+#if _MIPS_ARCH_MIPS32R2
+#define LJ_ARCH_VERSION 20
+#else
+#define LJ_ARCH_VERSION 10
+#endif
+
+#else
+#error "No target architecture defined"
+#endif
+
+#ifndef LJ_PAGESIZE
+#define LJ_PAGESIZE 4096
+#endif
+
+/* Check for minimum required compiler versions. */
+#if defined(__GNUC__)
+#if LJ_TARGET_X86
+#if (__GNUC__ < 3) || ((__GNUC__ == 3) && __GNUC_MINOR__ < 4)
+#error "Need at least GCC 3.4 or newer"
+#endif
+#elif LJ_TARGET_X64
+#if __GNUC__ < 4
+#error "Need at least GCC 4.0 or newer"
+#endif
+#elif LJ_TARGET_ARM
+#if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 2)
+#error "Need at least GCC 4.2 or newer"
+#endif
+#elif !LJ_TARGET_PS3
+#if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 3)
+#error "Need at least GCC 4.3 or newer"
+#endif
+#endif
+#endif
+
+/* Check target-specific constraints. */
+#ifndef _BUILDVM_H
+#if LJ_TARGET_X64
+#if __USING_SJLJ_EXCEPTIONS__
+#error "Need a C compiler with native exception handling on x64"
+#endif
+#elif LJ_TARGET_ARM
+#if defined(__ARMEB__)
+#error "No support for big-endian ARM"
+#endif
+#if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__
+#error "No support for Cortex-M CPUs"
+#endif
+#if !(__ARM_EABI__ || LJ_TARGET_IOS)
+#error "Only ARM EABI or iOS 3.0+ ABI is supported"
+#endif
+#elif LJ_TARGET_PPC || LJ_TARGET_PPCSPE
+#if defined(_SOFT_FLOAT) || defined(_SOFT_DOUBLE)
+#error "No support for PowerPC CPUs without double-precision FPU"
+#endif
+#if defined(_LITTLE_ENDIAN) && (!defined(_BYTE_ORDER) || (_BYTE_ORDER == _LITTLE_ENDIAN))
+#error "No support for little-endian PowerPC"
+#endif
+#if defined(_LP64)
+#error "No support for PowerPC 64 bit mode"
+#endif
+#elif LJ_TARGET_MIPS
+#if defined(__mips_soft_float)
+#error "No support for MIPS CPUs without FPU"
+#endif
+#if defined(_LP64)
+#error "No support for MIPS64"
+#endif
+#endif
+#endif
+
+/* Enable or disable the dual-number mode for the VM. */
+#if (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE && LUAJIT_NUMMODE == 2) || \
+ (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL && LUAJIT_NUMMODE == 1)
+#error "No support for this number mode on this architecture"
+#endif
+#if LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL || \
+ (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL_SINGLE && LUAJIT_NUMMODE != 1) || \
+ (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE_DUAL && LUAJIT_NUMMODE == 2)
+#define LJ_DUALNUM 1
+#else
+#define LJ_DUALNUM 0
+#endif
+
+#if LJ_TARGET_IOS || LJ_TARGET_CONSOLE
+/* Runtime code generation is restricted on iOS. Complain to Apple, not me. */
+/* Ditto for the consoles. Complain to Sony or MS, not me. */
+#ifndef LUAJIT_ENABLE_JIT
+#define LJ_OS_NOJIT 1
+#endif
+#endif
+
+/* Disable or enable the JIT compiler. */
+#if defined(LUAJIT_DISABLE_JIT) || defined(LJ_ARCH_NOJIT) || defined(LJ_OS_NOJIT)
+#define LJ_HASJIT 0
+#else
+#define LJ_HASJIT 1
+#endif
+
+/* Disable or enable the FFI extension. */
+#if defined(LUAJIT_DISABLE_FFI) || defined(LJ_ARCH_NOFFI)
+#define LJ_HASFFI 0
+#else
+#define LJ_HASFFI 1
+#endif
+
+#ifndef LJ_ARCH_HASFPU
+#define LJ_ARCH_HASFPU 1
+#endif
+#ifndef LJ_ABI_SOFTFP
+#define LJ_ABI_SOFTFP 0
+#endif
+#define LJ_SOFTFP (!LJ_ARCH_HASFPU)
+
+#if LJ_ARCH_ENDIAN == LUAJIT_BE
+#define LJ_LE 0
+#define LJ_BE 1
+#define LJ_ENDIAN_SELECT(le, be) be
+#define LJ_ENDIAN_LOHI(lo, hi) hi lo
+#else
+#define LJ_LE 1
+#define LJ_BE 0
+#define LJ_ENDIAN_SELECT(le, be) le
+#define LJ_ENDIAN_LOHI(lo, hi) lo hi
+#endif
+
+#if LJ_ARCH_BITS == 32
+#define LJ_32 1
+#define LJ_64 0
+#else
+#define LJ_32 0
+#define LJ_64 1
+#endif
+
+#ifndef LJ_TARGET_UNALIGNED
+#define LJ_TARGET_UNALIGNED 0
+#endif
+
+/* Various workarounds for embedded operating systems. */
+#if (defined(__ANDROID__) && !defined(LJ_TARGET_X86ORX64)) || defined(__symbian__) || LJ_TARGET_XBOX360
+#define LUAJIT_NO_LOG2
+#endif
+#if defined(__symbian__)
+#define LUAJIT_NO_EXP2
+#endif
+#if LJ_TARGET_CONSOLE || (LJ_TARGET_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_8_0)
+#define LJ_NO_SYSTEM 1
+#endif
+
+#if !defined(LUAJIT_NO_UNWIND) && __GNU_COMPACT_EH__
+/* NYI: no support for compact unwind specification, yet. */
+#define LUAJIT_NO_UNWIND 1
+#endif
+
+#if defined(LUAJIT_NO_UNWIND) || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 || LJ_TARGET_PS4
+#define LJ_NO_UNWIND 1
+#endif
+
+/* Compatibility with Lua 5.1 vs. 5.2. */
+#ifdef LUAJIT_ENABLE_LUA52COMPAT
+#define LJ_52 1
+#else
+#define LJ_52 0
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm.h
new file mode 100644
index 0000000..2819481
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm.h
@@ -0,0 +1,17 @@
+/*
+** IR assembler (SSA IR -> machine code).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_ASM_H
+#define _LJ_ASM_H
+
+#include "lj_jit.h"
+
+#if LJ_HASJIT
+LJ_FUNC void lj_asm_trace(jit_State *J, GCtrace *T);
+LJ_FUNC void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno,
+ MCode *target);
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm_arm.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm_arm.h
new file mode 100644
index 0000000..961f7e3
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm_arm.h
@@ -0,0 +1,2360 @@
+/*
+** ARM IR assembler (SSA IR -> machine code).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* -- Register allocator extensions --------------------------------------- */
+
+/* Allocate a register with a hint. */
+static Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow)
+{
+ Reg r = IR(ref)->r;
+ if (ra_noreg(r)) {
+ if (!ra_hashint(r) && !iscrossref(as, ref))
+ ra_sethint(IR(ref)->r, hint); /* Propagate register hint. */
+ r = ra_allocref(as, ref, allow);
+ }
+ ra_noweak(as, r);
+ return r;
+}
+
+/* Allocate a scratch register pair. */
+static Reg ra_scratchpair(ASMState *as, RegSet allow)
+{
+ RegSet pick1 = as->freeset & allow;
+ RegSet pick2 = pick1 & (pick1 >> 1) & RSET_GPREVEN;
+ Reg r;
+ if (pick2) {
+ r = rset_picktop(pick2);
+ } else {
+ RegSet pick = pick1 & (allow >> 1) & RSET_GPREVEN;
+ if (pick) {
+ r = rset_picktop(pick);
+ ra_restore(as, regcost_ref(as->cost[r+1]));
+ } else {
+ pick = pick1 & (allow << 1) & RSET_GPRODD;
+ if (pick) {
+ r = ra_restore(as, regcost_ref(as->cost[rset_picktop(pick)-1]));
+ } else {
+ r = ra_evict(as, allow & (allow >> 1) & RSET_GPREVEN);
+ ra_restore(as, regcost_ref(as->cost[r+1]));
+ }
+ }
+ }
+ lua_assert(rset_test(RSET_GPREVEN, r));
+ ra_modified(as, r);
+ ra_modified(as, r+1);
+ RA_DBGX((as, "scratchpair $r $r", r, r+1));
+ return r;
+}
+
+#if !LJ_SOFTFP
+/* Allocate two source registers for three-operand instructions. */
+static Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow)
+{
+ IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);
+ Reg left = irl->r, right = irr->r;
+ if (ra_hasreg(left)) {
+ ra_noweak(as, left);
+ if (ra_noreg(right))
+ right = ra_allocref(as, ir->op2, rset_exclude(allow, left));
+ else
+ ra_noweak(as, right);
+ } else if (ra_hasreg(right)) {
+ ra_noweak(as, right);
+ left = ra_allocref(as, ir->op1, rset_exclude(allow, right));
+ } else if (ra_hashint(right)) {
+ right = ra_allocref(as, ir->op2, allow);
+ left = ra_alloc1(as, ir->op1, rset_exclude(allow, right));
+ } else {
+ left = ra_allocref(as, ir->op1, allow);
+ right = ra_alloc1(as, ir->op2, rset_exclude(allow, left));
+ }
+ return left | (right << 8);
+}
+#endif
+
+/* -- Guard handling ------------------------------------------------------ */
+
+/* Generate an exit stub group at the bottom of the reserved MCode memory. */
+static MCode *asm_exitstub_gen(ASMState *as, ExitNo group)
+{
+ MCode *mxp = as->mcbot;
+ int i;
+ if (mxp + 4*4+4*EXITSTUBS_PER_GROUP >= as->mctop)
+ asm_mclimit(as);
+ /* str lr, [sp]; bl ->vm_exit_handler; .long DISPATCH_address, group. */
+ *mxp++ = ARMI_STR|ARMI_LS_P|ARMI_LS_U|ARMF_D(RID_LR)|ARMF_N(RID_SP);
+ *mxp = ARMI_BL|((((MCode *)(void *)lj_vm_exit_handler-mxp)-2)&0x00ffffffu);
+ mxp++;
+ *mxp++ = (MCode)i32ptr(J2GG(as->J)->dispatch); /* DISPATCH address */
+ *mxp++ = group*EXITSTUBS_PER_GROUP;
+ for (i = 0; i < EXITSTUBS_PER_GROUP; i++)
+ *mxp++ = ARMI_B|((-6-i)&0x00ffffffu);
+ lj_mcode_sync(as->mcbot, mxp);
+ lj_mcode_commitbot(as->J, mxp);
+ as->mcbot = mxp;
+ as->mclim = as->mcbot + MCLIM_REDZONE;
+ return mxp - EXITSTUBS_PER_GROUP;
+}
+
+/* Setup all needed exit stubs. */
+static void asm_exitstub_setup(ASMState *as, ExitNo nexits)
+{
+ ExitNo i;
+ if (nexits >= EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR)
+ lj_trace_err(as->J, LJ_TRERR_SNAPOV);
+ for (i = 0; i < (nexits+EXITSTUBS_PER_GROUP-1)/EXITSTUBS_PER_GROUP; i++)
+ if (as->J->exitstubgroup[i] == NULL)
+ as->J->exitstubgroup[i] = asm_exitstub_gen(as, i);
+}
+
+/* Emit conditional branch to exit for guard. */
+static void asm_guardcc(ASMState *as, ARMCC cc)
+{
+ MCode *target = exitstub_addr(as->J, as->snapno);
+ MCode *p = as->mcp;
+ if (LJ_UNLIKELY(p == as->invmcp)) {
+ as->loopinv = 1;
+ *p = ARMI_BL | ((target-p-2) & 0x00ffffffu);
+ emit_branch(as, ARMF_CC(ARMI_B, cc^1), p+1);
+ return;
+ }
+ emit_branch(as, ARMF_CC(ARMI_BL, cc), target);
+}
+
+/* -- Operand fusion ------------------------------------------------------ */
+
+/* Limit linear search to this distance. Avoids O(n^2) behavior. */
+#define CONFLICT_SEARCH_LIM 31
+
+/* Check if there's no conflicting instruction between curins and ref. */
+static int noconflict(ASMState *as, IRRef ref, IROp conflict)
+{
+ IRIns *ir = as->ir;
+ IRRef i = as->curins;
+ if (i > ref + CONFLICT_SEARCH_LIM)
+ return 0; /* Give up, ref is too far away. */
+ while (--i > ref)
+ if (ir[i].o == conflict)
+ return 0; /* Conflict found. */
+ return 1; /* Ok, no conflict. */
+}
+
+/* Fuse the array base of colocated arrays. */
+static int32_t asm_fuseabase(ASMState *as, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE &&
+ !neverfuse(as) && noconflict(as, ref, IR_NEWREF))
+ return (int32_t)sizeof(GCtab);
+ return 0;
+}
+
+/* Fuse array/hash/upvalue reference into register+offset operand. */
+static Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow,
+ int lim)
+{
+ IRIns *ir = IR(ref);
+ if (ra_noreg(ir->r)) {
+ if (ir->o == IR_AREF) {
+ if (mayfuse(as, ref)) {
+ if (irref_isk(ir->op2)) {
+ IRRef tab = IR(ir->op1)->op1;
+ int32_t ofs = asm_fuseabase(as, tab);
+ IRRef refa = ofs ? tab : ir->op1;
+ ofs += 8*IR(ir->op2)->i;
+ if (ofs > -lim && ofs < lim) {
+ *ofsp = ofs;
+ return ra_alloc1(as, refa, allow);
+ }
+ }
+ }
+ } else if (ir->o == IR_HREFK) {
+ if (mayfuse(as, ref)) {
+ int32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node));
+ if (ofs < lim) {
+ *ofsp = ofs;
+ return ra_alloc1(as, ir->op1, allow);
+ }
+ }
+ } else if (ir->o == IR_UREFC) {
+ if (irref_isk(ir->op1)) {
+ GCfunc *fn = ir_kfunc(IR(ir->op1));
+ int32_t ofs = i32ptr(&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv);
+ *ofsp = (ofs & 255); /* Mask out less bits to allow LDRD. */
+ return ra_allock(as, (ofs & ~255), allow);
+ }
+ }
+ }
+ *ofsp = 0;
+ return ra_alloc1(as, ref, allow);
+}
+
+/* Fuse m operand into arithmetic/logic instructions. */
+static uint32_t asm_fuseopm(ASMState *as, ARMIns ai, IRRef ref, RegSet allow)
+{
+ IRIns *ir = IR(ref);
+ if (ra_hasreg(ir->r)) {
+ ra_noweak(as, ir->r);
+ return ARMF_M(ir->r);
+ } else if (irref_isk(ref)) {
+ uint32_t k = emit_isk12(ai, ir->i);
+ if (k)
+ return k;
+ } else if (mayfuse(as, ref)) {
+ if (ir->o >= IR_BSHL && ir->o <= IR_BROR) {
+ Reg m = ra_alloc1(as, ir->op1, allow);
+ ARMShift sh = ir->o == IR_BSHL ? ARMSH_LSL :
+ ir->o == IR_BSHR ? ARMSH_LSR :
+ ir->o == IR_BSAR ? ARMSH_ASR : ARMSH_ROR;
+ if (irref_isk(ir->op2)) {
+ return m | ARMF_SH(sh, (IR(ir->op2)->i & 31));
+ } else {
+ Reg s = ra_alloc1(as, ir->op2, rset_exclude(allow, m));
+ return m | ARMF_RSH(sh, s);
+ }
+ } else if (ir->o == IR_ADD && ir->op1 == ir->op2) {
+ Reg m = ra_alloc1(as, ir->op1, allow);
+ return m | ARMF_SH(ARMSH_LSL, 1);
+ }
+ }
+ return ra_allocref(as, ref, allow);
+}
+
+/* Fuse shifts into loads/stores. Only bother with BSHL 2 => lsl #2. */
+static IRRef asm_fuselsl2(ASMState *as, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ if (ra_noreg(ir->r) && mayfuse(as, ref) && ir->o == IR_BSHL &&
+ irref_isk(ir->op2) && IR(ir->op2)->i == 2)
+ return ir->op1;
+ return 0; /* No fusion. */
+}
+
+/* Fuse XLOAD/XSTORE reference into load/store operand. */
+static void asm_fusexref(ASMState *as, ARMIns ai, Reg rd, IRRef ref,
+ RegSet allow, int32_t ofs)
+{
+ IRIns *ir = IR(ref);
+ Reg base;
+ if (ra_noreg(ir->r) && canfuse(as, ir)) {
+ int32_t lim = (!LJ_SOFTFP && (ai & 0x08000000)) ? 1024 :
+ (ai & 0x04000000) ? 4096 : 256;
+ if (ir->o == IR_ADD) {
+ int32_t ofs2;
+ if (irref_isk(ir->op2) &&
+ (ofs2 = ofs + IR(ir->op2)->i) > -lim && ofs2 < lim &&
+ (!(!LJ_SOFTFP && (ai & 0x08000000)) || !(ofs2 & 3))) {
+ ofs = ofs2;
+ ref = ir->op1;
+ } else if (ofs == 0 && !(!LJ_SOFTFP && (ai & 0x08000000))) {
+ IRRef lref = ir->op1, rref = ir->op2;
+ Reg rn, rm;
+ if ((ai & 0x04000000)) {
+ IRRef sref = asm_fuselsl2(as, rref);
+ if (sref) {
+ rref = sref;
+ ai |= ARMF_SH(ARMSH_LSL, 2);
+ } else if ((sref = asm_fuselsl2(as, lref)) != 0) {
+ lref = rref;
+ rref = sref;
+ ai |= ARMF_SH(ARMSH_LSL, 2);
+ }
+ }
+ rn = ra_alloc1(as, lref, allow);
+ rm = ra_alloc1(as, rref, rset_exclude(allow, rn));
+ if ((ai & 0x04000000)) ai |= ARMI_LS_R;
+ emit_dnm(as, ai|ARMI_LS_P|ARMI_LS_U, rd, rn, rm);
+ return;
+ }
+ } else if (ir->o == IR_STRREF && !(!LJ_SOFTFP && (ai & 0x08000000))) {
+ lua_assert(ofs == 0);
+ ofs = (int32_t)sizeof(GCstr);
+ if (irref_isk(ir->op2)) {
+ ofs += IR(ir->op2)->i;
+ ref = ir->op1;
+ } else if (irref_isk(ir->op1)) {
+ ofs += IR(ir->op1)->i;
+ ref = ir->op2;
+ } else {
+ /* NYI: Fuse ADD with constant. */
+ Reg rn = ra_alloc1(as, ir->op1, allow);
+ uint32_t m = asm_fuseopm(as, 0, ir->op2, rset_exclude(allow, rn));
+ if ((ai & 0x04000000))
+ emit_lso(as, ai, rd, rd, ofs);
+ else
+ emit_lsox(as, ai, rd, rd, ofs);
+ emit_dn(as, ARMI_ADD^m, rd, rn);
+ return;
+ }
+ if (ofs <= -lim || ofs >= lim) {
+ Reg rn = ra_alloc1(as, ref, allow);
+ Reg rm = ra_allock(as, ofs, rset_exclude(allow, rn));
+ if ((ai & 0x04000000)) ai |= ARMI_LS_R;
+ emit_dnm(as, ai|ARMI_LS_P|ARMI_LS_U, rd, rn, rm);
+ return;
+ }
+ }
+ }
+ base = ra_alloc1(as, ref, allow);
+#if !LJ_SOFTFP
+ if ((ai & 0x08000000))
+ emit_vlso(as, ai, rd, base, ofs);
+ else
+#endif
+ if ((ai & 0x04000000))
+ emit_lso(as, ai, rd, base, ofs);
+ else
+ emit_lsox(as, ai, rd, base, ofs);
+}
+
+#if !LJ_SOFTFP
+/* Fuse to multiply-add/sub instruction. */
+static int asm_fusemadd(ASMState *as, IRIns *ir, ARMIns ai, ARMIns air)
+{
+ IRRef lref = ir->op1, rref = ir->op2;
+ IRIns *irm;
+ if (lref != rref &&
+ ((mayfuse(as, lref) && (irm = IR(lref), irm->o == IR_MUL) &&
+ ra_noreg(irm->r)) ||
+ (mayfuse(as, rref) && (irm = IR(rref), irm->o == IR_MUL) &&
+ (rref = lref, ai = air, ra_noreg(irm->r))))) {
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg add = ra_hintalloc(as, rref, dest, RSET_FPR);
+ Reg right, left = ra_alloc2(as, irm,
+ rset_exclude(rset_exclude(RSET_FPR, dest), add));
+ right = (left >> 8); left &= 255;
+ emit_dnm(as, ai, (dest & 15), (left & 15), (right & 15));
+ if (dest != add) emit_dm(as, ARMI_VMOV_D, (dest & 15), (add & 15));
+ return 1;
+ }
+ return 0;
+}
+#endif
+
+/* -- Calls --------------------------------------------------------------- */
+
+/* Generate a call to a C function. */
+static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)
+{
+ uint32_t n, nargs = CCI_NARGS(ci);
+ int32_t ofs = 0;
+#if LJ_SOFTFP
+ Reg gpr = REGARG_FIRSTGPR;
+#else
+ Reg gpr, fpr = REGARG_FIRSTFPR, fprodd = 0;
+#endif
+ if ((void *)ci->func)
+ emit_call(as, (void *)ci->func);
+#if !LJ_SOFTFP
+ for (gpr = REGARG_FIRSTGPR; gpr <= REGARG_LASTGPR; gpr++)
+ as->cost[gpr] = REGCOST(~0u, ASMREF_L);
+ gpr = REGARG_FIRSTGPR;
+#endif
+ for (n = 0; n < nargs; n++) { /* Setup args. */
+ IRRef ref = args[n];
+ IRIns *ir = IR(ref);
+#if !LJ_SOFTFP
+ if (ref && irt_isfp(ir->t)) {
+ RegSet of = as->freeset;
+ Reg src;
+ if (!LJ_ABI_SOFTFP && !(ci->flags & CCI_VARARG)) {
+ if (irt_isnum(ir->t)) {
+ if (fpr <= REGARG_LASTFPR) {
+ ra_leftov(as, fpr, ref);
+ fpr++;
+ continue;
+ }
+ } else if (fprodd) { /* Ick. */
+ src = ra_alloc1(as, ref, RSET_FPR);
+ emit_dm(as, ARMI_VMOV_S, (fprodd & 15), (src & 15) | 0x00400000);
+ fprodd = 0;
+ continue;
+ } else if (fpr <= REGARG_LASTFPR) {
+ ra_leftov(as, fpr, ref);
+ fprodd = fpr++;
+ continue;
+ }
+ /* Workaround to protect argument GPRs from being used for remat. */
+ as->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1);
+ src = ra_alloc1(as, ref, RSET_FPR); /* May alloc GPR to remat FPR. */
+ as->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1));
+ fprodd = 0;
+ goto stackfp;
+ }
+ /* Workaround to protect argument GPRs from being used for remat. */
+ as->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1);
+ src = ra_alloc1(as, ref, RSET_FPR); /* May alloc GPR to remat FPR. */
+ as->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1));
+ if (irt_isnum(ir->t)) gpr = (gpr+1) & ~1u;
+ if (gpr <= REGARG_LASTGPR) {
+ lua_assert(rset_test(as->freeset, gpr)); /* Must have been evicted. */
+ if (irt_isnum(ir->t)) {
+ lua_assert(rset_test(as->freeset, gpr+1)); /* Ditto. */
+ emit_dnm(as, ARMI_VMOV_RR_D, gpr, gpr+1, (src & 15));
+ gpr += 2;
+ } else {
+ emit_dn(as, ARMI_VMOV_R_S, gpr, (src & 15));
+ gpr++;
+ }
+ } else {
+ stackfp:
+ if (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4;
+ emit_spstore(as, ir, src, ofs);
+ ofs += irt_isnum(ir->t) ? 8 : 4;
+ }
+ } else
+#endif
+ {
+ if (gpr <= REGARG_LASTGPR) {
+ lua_assert(rset_test(as->freeset, gpr)); /* Must have been evicted. */
+ if (ref) ra_leftov(as, gpr, ref);
+ gpr++;
+ } else {
+ if (ref) {
+ Reg r = ra_alloc1(as, ref, RSET_GPR);
+ emit_spstore(as, ir, r, ofs);
+ }
+ ofs += 4;
+ }
+ }
+ }
+}
+
+/* Setup result reg/sp for call. Evict scratch regs. */
+static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci)
+{
+ RegSet drop = RSET_SCRATCH;
+ int hiop = ((ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t));
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ if (hiop && ra_hasreg((ir+1)->r))
+ rset_clear(drop, (ir+1)->r); /* Dest reg handled below. */
+ ra_evictset(as, drop); /* Evictions must be performed first. */
+ if (ra_used(ir)) {
+ lua_assert(!irt_ispri(ir->t));
+ if (!LJ_SOFTFP && irt_isfp(ir->t)) {
+ if (LJ_ABI_SOFTFP || (ci->flags & (CCI_CASTU64|CCI_VARARG))) {
+ Reg dest = (ra_dest(as, ir, RSET_FPR) & 15);
+ if (irt_isnum(ir->t))
+ emit_dnm(as, ARMI_VMOV_D_RR, RID_RETLO, RID_RETHI, dest);
+ else
+ emit_dn(as, ARMI_VMOV_S_R, RID_RET, dest);
+ } else {
+ ra_destreg(as, ir, RID_FPRET);
+ }
+ } else if (hiop) {
+ ra_destpair(as, ir);
+ } else {
+ ra_destreg(as, ir, RID_RET);
+ }
+ }
+ UNUSED(ci);
+}
+
+static void asm_call(ASMState *as, IRIns *ir)
+{
+ IRRef args[CCI_NARGS_MAX];
+ const CCallInfo *ci = &lj_ir_callinfo[ir->op2];
+ asm_collectargs(as, ir, ci, args);
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+
+static void asm_callx(ASMState *as, IRIns *ir)
+{
+ IRRef args[CCI_NARGS_MAX*2];
+ CCallInfo ci;
+ IRRef func;
+ IRIns *irf;
+ ci.flags = asm_callx_flags(as, ir);
+ asm_collectargs(as, ir, &ci, args);
+ asm_setupresult(as, ir, &ci);
+ func = ir->op2; irf = IR(func);
+ if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }
+ if (irref_isk(func)) { /* Call to constant address. */
+ ci.func = (ASMFunction)(void *)(irf->i);
+ } else { /* Need a non-argument register for indirect calls. */
+ Reg freg = ra_alloc1(as, func, RSET_RANGE(RID_R4, RID_R12+1));
+ emit_m(as, ARMI_BLXr, freg);
+ ci.func = (ASMFunction)(void *)0;
+ }
+ asm_gencall(as, &ci, args);
+}
+
+/* -- Returns ------------------------------------------------------------- */
+
+/* Return to lower frame. Guard that it goes to the right spot. */
+static void asm_retf(ASMState *as, IRIns *ir)
+{
+ Reg base = ra_alloc1(as, REF_BASE, RSET_GPR);
+ void *pc = ir_kptr(IR(ir->op2));
+ int32_t delta = 1+bc_a(*((const BCIns *)pc - 1));
+ as->topslot -= (BCReg)delta;
+ if ((int32_t)as->topslot < 0) as->topslot = 0;
+ irt_setmark(IR(REF_BASE)->t); /* Children must not coalesce with BASE reg. */
+ /* Need to force a spill on REF_BASE now to update the stack slot. */
+ emit_lso(as, ARMI_STR, base, RID_SP, ra_spill(as, IR(REF_BASE)));
+ emit_setgl(as, base, jit_base);
+ emit_addptr(as, base, -8*delta);
+ asm_guardcc(as, CC_NE);
+ emit_nm(as, ARMI_CMP, RID_TMP,
+ ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base)));
+ emit_lso(as, ARMI_LDR, RID_TMP, base, -4);
+}
+
+/* -- Type conversions ---------------------------------------------------- */
+
+#if !LJ_SOFTFP
+static void asm_tointg(ASMState *as, IRIns *ir, Reg left)
+{
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ asm_guardcc(as, CC_NE);
+ emit_d(as, ARMI_VMRS, 0);
+ emit_dm(as, ARMI_VCMP_D, (tmp & 15), (left & 15));
+ emit_dm(as, ARMI_VCVT_F64_S32, (tmp & 15), (tmp & 15));
+ emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15));
+ emit_dm(as, ARMI_VCVT_S32_F64, (tmp & 15), (left & 15));
+}
+
+static void asm_tobit(ASMState *as, IRIns *ir)
+{
+ RegSet allow = RSET_FPR;
+ Reg left = ra_alloc1(as, ir->op1, allow);
+ Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left));
+ Reg tmp = ra_scratch(as, rset_clear(allow, right));
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15));
+ emit_dnm(as, ARMI_VADD_D, (tmp & 15), (left & 15), (right & 15));
+}
+#endif
+
+static void asm_conv(ASMState *as, IRIns *ir)
+{
+ IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);
+#if !LJ_SOFTFP
+ int stfp = (st == IRT_NUM || st == IRT_FLOAT);
+#endif
+ IRRef lref = ir->op1;
+ /* 64 bit integer conversions are handled by SPLIT. */
+ lua_assert(!irt_isint64(ir->t) && !(st == IRT_I64 || st == IRT_U64));
+#if LJ_SOFTFP
+ /* FP conversions are handled by SPLIT. */
+ lua_assert(!irt_isfp(ir->t) && !(st == IRT_NUM || st == IRT_FLOAT));
+ /* Can't check for same types: SPLIT uses CONV int.int + BXOR for sfp NEG. */
+#else
+ lua_assert(irt_type(ir->t) != st);
+ if (irt_isfp(ir->t)) {
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ if (stfp) { /* FP to FP conversion. */
+ emit_dm(as, st == IRT_NUM ? ARMI_VCVT_F32_F64 : ARMI_VCVT_F64_F32,
+ (dest & 15), (ra_alloc1(as, lref, RSET_FPR) & 15));
+ } else { /* Integer to FP conversion. */
+ Reg left = ra_alloc1(as, lref, RSET_GPR);
+ ARMIns ai = irt_isfloat(ir->t) ?
+ (st == IRT_INT ? ARMI_VCVT_F32_S32 : ARMI_VCVT_F32_U32) :
+ (st == IRT_INT ? ARMI_VCVT_F64_S32 : ARMI_VCVT_F64_U32);
+ emit_dm(as, ai, (dest & 15), (dest & 15));
+ emit_dn(as, ARMI_VMOV_S_R, left, (dest & 15));
+ }
+ } else if (stfp) { /* FP to integer conversion. */
+ if (irt_isguard(ir->t)) {
+ /* Checked conversions are only supported from number to int. */
+ lua_assert(irt_isint(ir->t) && st == IRT_NUM);
+ asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR));
+ } else {
+ Reg left = ra_alloc1(as, lref, RSET_FPR);
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ ARMIns ai;
+ emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15));
+ ai = irt_isint(ir->t) ?
+ (st == IRT_NUM ? ARMI_VCVT_S32_F64 : ARMI_VCVT_S32_F32) :
+ (st == IRT_NUM ? ARMI_VCVT_U32_F64 : ARMI_VCVT_U32_F32);
+ emit_dm(as, ai, (tmp & 15), (left & 15));
+ }
+ } else
+#endif
+ {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */
+ Reg left = ra_alloc1(as, lref, RSET_GPR);
+ lua_assert(irt_isint(ir->t) || irt_isu32(ir->t));
+ if ((as->flags & JIT_F_ARMV6)) {
+ ARMIns ai = st == IRT_I8 ? ARMI_SXTB :
+ st == IRT_U8 ? ARMI_UXTB :
+ st == IRT_I16 ? ARMI_SXTH : ARMI_UXTH;
+ emit_dm(as, ai, dest, left);
+ } else if (st == IRT_U8) {
+ emit_dn(as, ARMI_AND|ARMI_K12|255, dest, left);
+ } else {
+ uint32_t shift = st == IRT_I8 ? 24 : 16;
+ ARMShift sh = st == IRT_U16 ? ARMSH_LSR : ARMSH_ASR;
+ emit_dm(as, ARMI_MOV|ARMF_SH(sh, shift), dest, RID_TMP);
+ emit_dm(as, ARMI_MOV|ARMF_SH(ARMSH_LSL, shift), RID_TMP, left);
+ }
+ } else { /* Handle 32/32 bit no-op (cast). */
+ ra_leftov(as, dest, lref); /* Do nothing, but may need to move regs. */
+ }
+ }
+}
+
+#if !LJ_SOFTFP && LJ_HASFFI
+static void asm_conv64(ASMState *as, IRIns *ir)
+{
+ IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK);
+ IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH);
+ IRCallID id;
+ CCallInfo ci;
+ IRRef args[2];
+ args[0] = (ir-1)->op1;
+ args[1] = ir->op1;
+ if (st == IRT_NUM || st == IRT_FLOAT) {
+ id = IRCALL_fp64_d2l + ((st == IRT_FLOAT) ? 2 : 0) + (dt - IRT_I64);
+ ir--;
+ } else {
+ id = IRCALL_fp64_l2d + ((dt == IRT_FLOAT) ? 2 : 0) + (st - IRT_I64);
+ }
+ ci = lj_ir_callinfo[id];
+#if !LJ_ABI_SOFTFP
+ ci.flags |= CCI_VARARG; /* These calls don't use the hard-float ABI! */
+#endif
+ asm_setupresult(as, ir, &ci);
+ asm_gencall(as, &ci, args);
+}
+#endif
+
+static void asm_strto(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num];
+ IRRef args[2];
+ Reg rlo = 0, rhi = 0, tmp;
+ int destused = ra_used(ir);
+ int32_t ofs = 0;
+ ra_evictset(as, RSET_SCRATCH);
+#if LJ_SOFTFP
+ if (destused) {
+ if (ra_hasspill(ir->s) && ra_hasspill((ir+1)->s) &&
+ (ir->s & 1) == 0 && ir->s + 1 == (ir+1)->s) {
+ int i;
+ for (i = 0; i < 2; i++) {
+ Reg r = (ir+i)->r;
+ if (ra_hasreg(r)) {
+ ra_free(as, r);
+ ra_modified(as, r);
+ emit_spload(as, ir+i, r, sps_scale((ir+i)->s));
+ }
+ }
+ ofs = sps_scale(ir->s);
+ destused = 0;
+ } else {
+ rhi = ra_dest(as, ir+1, RSET_GPR);
+ rlo = ra_dest(as, ir, rset_exclude(RSET_GPR, rhi));
+ }
+ }
+ asm_guardcc(as, CC_EQ);
+ if (destused) {
+ emit_lso(as, ARMI_LDR, rhi, RID_SP, 4);
+ emit_lso(as, ARMI_LDR, rlo, RID_SP, 0);
+ }
+#else
+ UNUSED(rhi);
+ if (destused) {
+ if (ra_hasspill(ir->s)) {
+ ofs = sps_scale(ir->s);
+ destused = 0;
+ if (ra_hasreg(ir->r)) {
+ ra_free(as, ir->r);
+ ra_modified(as, ir->r);
+ emit_spload(as, ir, ir->r, ofs);
+ }
+ } else {
+ rlo = ra_dest(as, ir, RSET_FPR);
+ }
+ }
+ asm_guardcc(as, CC_EQ);
+ if (destused)
+ emit_vlso(as, ARMI_VLDR_D, rlo, RID_SP, 0);
+#endif
+ emit_n(as, ARMI_CMP|ARMI_K12|0, RID_RET); /* Test return status. */
+ args[0] = ir->op1; /* GCstr *str */
+ args[1] = ASMREF_TMP1; /* TValue *n */
+ asm_gencall(as, ci, args);
+ tmp = ra_releasetmp(as, ASMREF_TMP1);
+ if (ofs == 0)
+ emit_dm(as, ARMI_MOV, tmp, RID_SP);
+ else
+ emit_opk(as, ARMI_ADD, tmp, RID_SP, ofs, RSET_GPR);
+}
+
+/* Get pointer to TValue. */
+static void asm_tvptr(ASMState *as, Reg dest, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ if (irt_isnum(ir->t)) {
+ if (irref_isk(ref)) {
+ /* Use the number constant itself as a TValue. */
+ ra_allockreg(as, i32ptr(ir_knum(ir)), dest);
+ } else {
+#if LJ_SOFTFP
+ lua_assert(0);
+#else
+ /* Otherwise force a spill and use the spill slot. */
+ emit_opk(as, ARMI_ADD, dest, RID_SP, ra_spill(as, ir), RSET_GPR);
+#endif
+ }
+ } else {
+ /* Otherwise use [sp] and [sp+4] to hold the TValue. */
+ RegSet allow = rset_exclude(RSET_GPR, dest);
+ Reg type;
+ emit_dm(as, ARMI_MOV, dest, RID_SP);
+ if (!irt_ispri(ir->t)) {
+ Reg src = ra_alloc1(as, ref, allow);
+ emit_lso(as, ARMI_STR, src, RID_SP, 0);
+ }
+ if ((ir+1)->o == IR_HIOP)
+ type = ra_alloc1(as, ref+1, allow);
+ else
+ type = ra_allock(as, irt_toitype(ir->t), allow);
+ emit_lso(as, ARMI_STR, type, RID_SP, 4);
+ }
+}
+
+static void asm_tostr(ASMState *as, IRIns *ir)
+{
+ IRRef args[2];
+ args[0] = ASMREF_L;
+ as->gcsteps++;
+ if (irt_isnum(IR(ir->op1)->t) || (ir+1)->o == IR_HIOP) {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromnum];
+ args[1] = ASMREF_TMP1; /* const lua_Number * */
+ asm_setupresult(as, ir, ci); /* GCstr * */
+ asm_gencall(as, ci, args);
+ asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op1);
+ } else {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromint];
+ args[1] = ir->op1; /* int32_t k */
+ asm_setupresult(as, ir, ci); /* GCstr * */
+ asm_gencall(as, ci, args);
+ }
+}
+
+/* -- Memory references --------------------------------------------------- */
+
+static void asm_aref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg idx, base;
+ if (irref_isk(ir->op2)) {
+ IRRef tab = IR(ir->op1)->op1;
+ int32_t ofs = asm_fuseabase(as, tab);
+ IRRef refa = ofs ? tab : ir->op1;
+ uint32_t k = emit_isk12(ARMI_ADD, ofs + 8*IR(ir->op2)->i);
+ if (k) {
+ base = ra_alloc1(as, refa, RSET_GPR);
+ emit_dn(as, ARMI_ADD^k, dest, base);
+ return;
+ }
+ }
+ base = ra_alloc1(as, ir->op1, RSET_GPR);
+ idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base));
+ emit_dnm(as, ARMI_ADD|ARMF_SH(ARMSH_LSL, 3), dest, base, idx);
+}
+
+/* Inlined hash lookup. Specialized for key type and for const keys.
+** The equivalent C code is:
+** Node *n = hashkey(t, key);
+** do {
+** if (lj_obj_equal(&n->key, key)) return &n->val;
+** } while ((n = nextnode(n)));
+** return niltv(L);
+*/
+static void asm_href(ASMState *as, IRIns *ir, IROp merge)
+{
+ RegSet allow = RSET_GPR;
+ int destused = ra_used(ir);
+ Reg dest = ra_dest(as, ir, allow);
+ Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest));
+ Reg key = 0, keyhi = 0, keynumhi = RID_NONE, tmp = RID_TMP;
+ IRRef refkey = ir->op2;
+ IRIns *irkey = IR(refkey);
+ IRType1 kt = irkey->t;
+ int32_t k = 0, khi = emit_isk12(ARMI_CMP, irt_toitype(kt));
+ uint32_t khash;
+ MCLabel l_end, l_loop;
+ rset_clear(allow, tab);
+ if (!irref_isk(refkey) || irt_isstr(kt)) {
+#if LJ_SOFTFP
+ key = ra_alloc1(as, refkey, allow);
+ rset_clear(allow, key);
+ if (irkey[1].o == IR_HIOP) {
+ if (ra_hasreg((irkey+1)->r)) {
+ keynumhi = (irkey+1)->r;
+ keyhi = RID_TMP;
+ ra_noweak(as, keynumhi);
+ } else {
+ keyhi = keynumhi = ra_allocref(as, refkey+1, allow);
+ }
+ rset_clear(allow, keynumhi);
+ khi = 0;
+ }
+#else
+ if (irt_isnum(kt)) {
+ key = ra_scratch(as, allow);
+ rset_clear(allow, key);
+ keyhi = keynumhi = ra_scratch(as, allow);
+ rset_clear(allow, keyhi);
+ khi = 0;
+ } else {
+ key = ra_alloc1(as, refkey, allow);
+ rset_clear(allow, key);
+ }
+#endif
+ } else if (irt_isnum(kt)) {
+ int32_t val = (int32_t)ir_knum(irkey)->u32.lo;
+ k = emit_isk12(ARMI_CMP, val);
+ if (!k) {
+ key = ra_allock(as, val, allow);
+ rset_clear(allow, key);
+ }
+ val = (int32_t)ir_knum(irkey)->u32.hi;
+ khi = emit_isk12(ARMI_CMP, val);
+ if (!khi) {
+ keyhi = ra_allock(as, val, allow);
+ rset_clear(allow, keyhi);
+ }
+ } else if (!irt_ispri(kt)) {
+ k = emit_isk12(ARMI_CMP, irkey->i);
+ if (!k) {
+ key = ra_alloc1(as, refkey, allow);
+ rset_clear(allow, key);
+ }
+ }
+ if (!irt_ispri(kt))
+ tmp = ra_scratchpair(as, allow);
+
+ /* Key not found in chain: jump to exit (if merged) or load niltv. */
+ l_end = emit_label(as);
+ as->invmcp = NULL;
+ if (merge == IR_NE)
+ asm_guardcc(as, CC_AL);
+ else if (destused)
+ emit_loada(as, dest, niltvg(J2G(as->J)));
+
+ /* Follow hash chain until the end. */
+ l_loop = --as->mcp;
+ emit_n(as, ARMI_CMP|ARMI_K12|0, dest);
+ emit_lso(as, ARMI_LDR, dest, dest, (int32_t)offsetof(Node, next));
+
+ /* Type and value comparison. */
+ if (merge == IR_EQ)
+ asm_guardcc(as, CC_EQ);
+ else
+ emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end);
+ if (!irt_ispri(kt)) {
+ emit_nm(as, ARMF_CC(ARMI_CMP, CC_EQ)^k, tmp, key);
+ emit_nm(as, ARMI_CMP^khi, tmp+1, keyhi);
+ emit_lsox(as, ARMI_LDRD, tmp, dest, (int32_t)offsetof(Node, key));
+ } else {
+ emit_n(as, ARMI_CMP^khi, tmp);
+ emit_lso(as, ARMI_LDR, tmp, dest, (int32_t)offsetof(Node, key.it));
+ }
+ *l_loop = ARMF_CC(ARMI_B, CC_NE) | ((as->mcp-l_loop-2) & 0x00ffffffu);
+
+ /* Load main position relative to tab->node into dest. */
+ khash = irref_isk(refkey) ? ir_khash(irkey) : 1;
+ if (khash == 0) {
+ emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node));
+ } else {
+ emit_dnm(as, ARMI_ADD|ARMF_SH(ARMSH_LSL, 3), dest, dest, tmp);
+ emit_dnm(as, ARMI_ADD|ARMF_SH(ARMSH_LSL, 1), tmp, tmp, tmp);
+ if (irt_isstr(kt)) { /* Fetch of str->hash is cheaper than ra_allock. */
+ emit_dnm(as, ARMI_AND, tmp, tmp+1, RID_TMP);
+ emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node));
+ emit_lso(as, ARMI_LDR, tmp+1, key, (int32_t)offsetof(GCstr, hash));
+ emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask));
+ } else if (irref_isk(refkey)) {
+ emit_opk(as, ARMI_AND, tmp, RID_TMP, (int32_t)khash,
+ rset_exclude(rset_exclude(RSET_GPR, tab), dest));
+ emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node));
+ emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask));
+ } else { /* Must match with hash*() in lj_tab.c. */
+ if (ra_hasreg(keynumhi)) { /* Canonicalize +-0.0 to 0.0. */
+ if (keyhi == RID_TMP)
+ emit_dm(as, ARMF_CC(ARMI_MOV, CC_NE), keyhi, keynumhi);
+ emit_d(as, ARMF_CC(ARMI_MOV, CC_EQ)|ARMI_K12|0, keyhi);
+ }
+ emit_dnm(as, ARMI_AND, tmp, tmp, RID_TMP);
+ emit_dnm(as, ARMI_SUB|ARMF_SH(ARMSH_ROR, 32-HASH_ROT3), tmp, tmp, tmp+1);
+ emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node));
+ emit_dnm(as, ARMI_EOR|ARMF_SH(ARMSH_ROR, 32-((HASH_ROT2+HASH_ROT1)&31)),
+ tmp, tmp+1, tmp);
+ emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask));
+ emit_dnm(as, ARMI_SUB|ARMF_SH(ARMSH_ROR, 32-HASH_ROT1), tmp+1, tmp+1, tmp);
+ if (ra_hasreg(keynumhi)) {
+ emit_dnm(as, ARMI_EOR, tmp+1, tmp, key);
+ emit_dnm(as, ARMI_ORR|ARMI_S, RID_TMP, tmp, key); /* Test for +-0.0. */
+ emit_dnm(as, ARMI_ADD, tmp, keynumhi, keynumhi);
+#if !LJ_SOFTFP
+ emit_dnm(as, ARMI_VMOV_RR_D, key, keynumhi,
+ (ra_alloc1(as, refkey, RSET_FPR) & 15));
+#endif
+ } else {
+ emit_dnm(as, ARMI_EOR, tmp+1, tmp, key);
+ emit_opk(as, ARMI_ADD, tmp, key, (int32_t)HASH_BIAS,
+ rset_exclude(rset_exclude(RSET_GPR, tab), key));
+ }
+ }
+ }
+}
+
+static void asm_hrefk(ASMState *as, IRIns *ir)
+{
+ IRIns *kslot = IR(ir->op2);
+ IRIns *irkey = IR(kslot->op1);
+ int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node));
+ int32_t kofs = ofs + (int32_t)offsetof(Node, key);
+ Reg dest = (ra_used(ir) || ofs > 4095) ? ra_dest(as, ir, RSET_GPR) : RID_NONE;
+ Reg node = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg key = RID_NONE, type = RID_TMP, idx = node;
+ RegSet allow = rset_exclude(RSET_GPR, node);
+ lua_assert(ofs % sizeof(Node) == 0);
+ if (ofs > 4095) {
+ idx = dest;
+ rset_clear(allow, dest);
+ kofs = (int32_t)offsetof(Node, key);
+ } else if (ra_hasreg(dest)) {
+ emit_opk(as, ARMI_ADD, dest, node, ofs, allow);
+ }
+ asm_guardcc(as, CC_NE);
+ if (!irt_ispri(irkey->t)) {
+ RegSet even = (as->freeset & allow);
+ even = even & (even >> 1) & RSET_GPREVEN;
+ if (even) {
+ key = ra_scratch(as, even);
+ if (rset_test(as->freeset, key+1)) {
+ type = key+1;
+ ra_modified(as, type);
+ }
+ } else {
+ key = ra_scratch(as, allow);
+ }
+ rset_clear(allow, key);
+ }
+ rset_clear(allow, type);
+ if (irt_isnum(irkey->t)) {
+ emit_opk(as, ARMF_CC(ARMI_CMP, CC_EQ), 0, type,
+ (int32_t)ir_knum(irkey)->u32.hi, allow);
+ emit_opk(as, ARMI_CMP, 0, key,
+ (int32_t)ir_knum(irkey)->u32.lo, allow);
+ } else {
+ if (ra_hasreg(key))
+ emit_opk(as, ARMF_CC(ARMI_CMP, CC_EQ), 0, key, irkey->i, allow);
+ emit_n(as, ARMI_CMN|ARMI_K12|-irt_toitype(irkey->t), type);
+ }
+ emit_lso(as, ARMI_LDR, type, idx, kofs+4);
+ if (ra_hasreg(key)) emit_lso(as, ARMI_LDR, key, idx, kofs);
+ if (ofs > 4095)
+ emit_opk(as, ARMI_ADD, dest, node, ofs, RSET_GPR);
+}
+
+static void asm_newref(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_newkey];
+ IRRef args[3];
+ if (ir->r == RID_SINK)
+ return;
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ir->op1; /* GCtab *t */
+ args[2] = ASMREF_TMP1; /* cTValue *key */
+ asm_setupresult(as, ir, ci); /* TValue * */
+ asm_gencall(as, ci, args);
+ asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op2);
+}
+
+static void asm_uref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (irref_isk(ir->op1)) {
+ GCfunc *fn = ir_kfunc(IR(ir->op1));
+ MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v;
+ emit_lsptr(as, ARMI_LDR, dest, v);
+ } else {
+ Reg uv = ra_scratch(as, RSET_GPR);
+ Reg func = ra_alloc1(as, ir->op1, RSET_GPR);
+ if (ir->o == IR_UREFC) {
+ asm_guardcc(as, CC_NE);
+ emit_n(as, ARMI_CMP|ARMI_K12|1, RID_TMP);
+ emit_opk(as, ARMI_ADD, dest, uv,
+ (int32_t)offsetof(GCupval, tv), RSET_GPR);
+ emit_lso(as, ARMI_LDRB, RID_TMP, uv, (int32_t)offsetof(GCupval, closed));
+ } else {
+ emit_lso(as, ARMI_LDR, dest, uv, (int32_t)offsetof(GCupval, v));
+ }
+ emit_lso(as, ARMI_LDR, uv, func,
+ (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8));
+ }
+}
+
+static void asm_fref(ASMState *as, IRIns *ir)
+{
+ UNUSED(as); UNUSED(ir);
+ lua_assert(!ra_used(ir));
+}
+
+static void asm_strref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ IRRef ref = ir->op2, refk = ir->op1;
+ Reg r;
+ if (irref_isk(ref)) {
+ IRRef tmp = refk; refk = ref; ref = tmp;
+ } else if (!irref_isk(refk)) {
+ uint32_t k, m = ARMI_K12|sizeof(GCstr);
+ Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);
+ IRIns *irr = IR(ir->op2);
+ if (ra_hasreg(irr->r)) {
+ ra_noweak(as, irr->r);
+ right = irr->r;
+ } else if (mayfuse(as, irr->op2) &&
+ irr->o == IR_ADD && irref_isk(irr->op2) &&
+ (k = emit_isk12(ARMI_ADD,
+ (int32_t)sizeof(GCstr) + IR(irr->op2)->i))) {
+ m = k;
+ right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left));
+ } else {
+ right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left));
+ }
+ emit_dn(as, ARMI_ADD^m, dest, dest);
+ emit_dnm(as, ARMI_ADD, dest, left, right);
+ return;
+ }
+ r = ra_alloc1(as, ref, RSET_GPR);
+ emit_opk(as, ARMI_ADD, dest, r,
+ sizeof(GCstr) + IR(refk)->i, rset_exclude(RSET_GPR, r));
+}
+
+/* -- Loads and stores ---------------------------------------------------- */
+
+static ARMIns asm_fxloadins(IRIns *ir)
+{
+ switch (irt_type(ir->t)) {
+ case IRT_I8: return ARMI_LDRSB;
+ case IRT_U8: return ARMI_LDRB;
+ case IRT_I16: return ARMI_LDRSH;
+ case IRT_U16: return ARMI_LDRH;
+ case IRT_NUM: lua_assert(!LJ_SOFTFP); return ARMI_VLDR_D;
+ case IRT_FLOAT: if (!LJ_SOFTFP) return ARMI_VLDR_S;
+ default: return ARMI_LDR;
+ }
+}
+
+static ARMIns asm_fxstoreins(IRIns *ir)
+{
+ switch (irt_type(ir->t)) {
+ case IRT_I8: case IRT_U8: return ARMI_STRB;
+ case IRT_I16: case IRT_U16: return ARMI_STRH;
+ case IRT_NUM: lua_assert(!LJ_SOFTFP); return ARMI_VSTR_D;
+ case IRT_FLOAT: if (!LJ_SOFTFP) return ARMI_VSTR_S;
+ default: return ARMI_STR;
+ }
+}
+
+static void asm_fload(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg idx = ra_alloc1(as, ir->op1, RSET_GPR);
+ ARMIns ai = asm_fxloadins(ir);
+ int32_t ofs;
+ if (ir->op2 == IRFL_TAB_ARRAY) {
+ ofs = asm_fuseabase(as, ir->op1);
+ if (ofs) { /* Turn the t->array load into an add for colocated arrays. */
+ emit_dn(as, ARMI_ADD|ARMI_K12|ofs, dest, idx);
+ return;
+ }
+ }
+ ofs = field_ofs[ir->op2];
+ if ((ai & 0x04000000))
+ emit_lso(as, ai, dest, idx, ofs);
+ else
+ emit_lsox(as, ai, dest, idx, ofs);
+}
+
+static void asm_fstore(ASMState *as, IRIns *ir)
+{
+ if (ir->r != RID_SINK) {
+ Reg src = ra_alloc1(as, ir->op2, RSET_GPR);
+ IRIns *irf = IR(ir->op1);
+ Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src));
+ int32_t ofs = field_ofs[irf->op2];
+ ARMIns ai = asm_fxstoreins(ir);
+ if ((ai & 0x04000000))
+ emit_lso(as, ai, src, idx, ofs);
+ else
+ emit_lsox(as, ai, src, idx, ofs);
+ }
+}
+
+static void asm_xload(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir,
+ (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR);
+ lua_assert(!(ir->op2 & IRXLOAD_UNALIGNED));
+ asm_fusexref(as, asm_fxloadins(ir), dest, ir->op1, RSET_GPR, 0);
+}
+
+static void asm_xstore(ASMState *as, IRIns *ir, int32_t ofs)
+{
+ if (ir->r != RID_SINK) {
+ Reg src = ra_alloc1(as, ir->op2,
+ (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR);
+ asm_fusexref(as, asm_fxstoreins(ir), src, ir->op1,
+ rset_exclude(RSET_GPR, src), ofs);
+ }
+}
+
+static void asm_ahuvload(ASMState *as, IRIns *ir)
+{
+ int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP);
+ IRType t = hiop ? IRT_NUM : irt_type(ir->t);
+ Reg dest = RID_NONE, type = RID_NONE, idx;
+ RegSet allow = RSET_GPR;
+ int32_t ofs = 0;
+ if (hiop && ra_used(ir+1)) {
+ type = ra_dest(as, ir+1, allow);
+ rset_clear(allow, type);
+ }
+ if (ra_used(ir)) {
+ lua_assert((LJ_SOFTFP ? 0 : irt_isnum(ir->t)) ||
+ irt_isint(ir->t) || irt_isaddr(ir->t));
+ dest = ra_dest(as, ir, (!LJ_SOFTFP && t == IRT_NUM) ? RSET_FPR : allow);
+ rset_clear(allow, dest);
+ }
+ idx = asm_fuseahuref(as, ir->op1, &ofs, allow,
+ (!LJ_SOFTFP && t == IRT_NUM) ? 1024 : 4096);
+ if (!hiop || type == RID_NONE) {
+ rset_clear(allow, idx);
+ if (ofs < 256 && ra_hasreg(dest) && (dest & 1) == 0 &&
+ rset_test((as->freeset & allow), dest+1)) {
+ type = dest+1;
+ ra_modified(as, type);
+ } else {
+ type = RID_TMP;
+ }
+ }
+ asm_guardcc(as, t == IRT_NUM ? CC_HS : CC_NE);
+ emit_n(as, ARMI_CMN|ARMI_K12|-irt_toitype_(t), type);
+ if (ra_hasreg(dest)) {
+#if !LJ_SOFTFP
+ if (t == IRT_NUM)
+ emit_vlso(as, ARMI_VLDR_D, dest, idx, ofs);
+ else
+#endif
+ emit_lso(as, ARMI_LDR, dest, idx, ofs);
+ }
+ emit_lso(as, ARMI_LDR, type, idx, ofs+4);
+}
+
+static void asm_ahustore(ASMState *as, IRIns *ir)
+{
+ if (ir->r != RID_SINK) {
+ RegSet allow = RSET_GPR;
+ Reg idx, src = RID_NONE, type = RID_NONE;
+ int32_t ofs = 0;
+#if !LJ_SOFTFP
+ if (irt_isnum(ir->t)) {
+ src = ra_alloc1(as, ir->op2, RSET_FPR);
+ idx = asm_fuseahuref(as, ir->op1, &ofs, allow, 1024);
+ emit_vlso(as, ARMI_VSTR_D, src, idx, ofs);
+ } else
+#endif
+ {
+ int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP);
+ if (!irt_ispri(ir->t)) {
+ src = ra_alloc1(as, ir->op2, allow);
+ rset_clear(allow, src);
+ }
+ if (hiop)
+ type = ra_alloc1(as, (ir+1)->op2, allow);
+ else
+ type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);
+ idx = asm_fuseahuref(as, ir->op1, &ofs, rset_exclude(allow, type), 4096);
+ if (ra_hasreg(src)) emit_lso(as, ARMI_STR, src, idx, ofs);
+ emit_lso(as, ARMI_STR, type, idx, ofs+4);
+ }
+ }
+}
+
+static void asm_sload(ASMState *as, IRIns *ir)
+{
+ int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 4 : 0);
+ int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP);
+ IRType t = hiop ? IRT_NUM : irt_type(ir->t);
+ Reg dest = RID_NONE, type = RID_NONE, base;
+ RegSet allow = RSET_GPR;
+ lua_assert(!(ir->op2 & IRSLOAD_PARENT)); /* Handled by asm_head_side(). */
+ lua_assert(irt_isguard(ir->t) || !(ir->op2 & IRSLOAD_TYPECHECK));
+#if LJ_SOFTFP
+ lua_assert(!(ir->op2 & IRSLOAD_CONVERT)); /* Handled by LJ_SOFTFP SPLIT. */
+ if (hiop && ra_used(ir+1)) {
+ type = ra_dest(as, ir+1, allow);
+ rset_clear(allow, type);
+ }
+#else
+ if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(ir->t) && t == IRT_INT) {
+ dest = ra_scratch(as, RSET_FPR);
+ asm_tointg(as, ir, dest);
+ t = IRT_NUM; /* Continue with a regular number type check. */
+ } else
+#endif
+ if (ra_used(ir)) {
+ Reg tmp = RID_NONE;
+ if ((ir->op2 & IRSLOAD_CONVERT))
+ tmp = ra_scratch(as, t == IRT_INT ? RSET_FPR : RSET_GPR);
+ lua_assert((LJ_SOFTFP ? 0 : irt_isnum(ir->t)) ||
+ irt_isint(ir->t) || irt_isaddr(ir->t));
+ dest = ra_dest(as, ir, (!LJ_SOFTFP && t == IRT_NUM) ? RSET_FPR : allow);
+ rset_clear(allow, dest);
+ base = ra_alloc1(as, REF_BASE, allow);
+ if ((ir->op2 & IRSLOAD_CONVERT)) {
+ if (t == IRT_INT) {
+ emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15));
+ emit_dm(as, ARMI_VCVT_S32_F64, (tmp & 15), (tmp & 15));
+ t = IRT_NUM; /* Check for original type. */
+ } else {
+ emit_dm(as, ARMI_VCVT_F64_S32, (dest & 15), (dest & 15));
+ emit_dn(as, ARMI_VMOV_S_R, tmp, (dest & 15));
+ t = IRT_INT; /* Check for original type. */
+ }
+ dest = tmp;
+ }
+ goto dotypecheck;
+ }
+ base = ra_alloc1(as, REF_BASE, allow);
+dotypecheck:
+ rset_clear(allow, base);
+ if ((ir->op2 & IRSLOAD_TYPECHECK)) {
+ if (ra_noreg(type)) {
+ if (ofs < 256 && ra_hasreg(dest) && (dest & 1) == 0 &&
+ rset_test((as->freeset & allow), dest+1)) {
+ type = dest+1;
+ ra_modified(as, type);
+ } else {
+ type = RID_TMP;
+ }
+ }
+ asm_guardcc(as, t == IRT_NUM ? CC_HS : CC_NE);
+ emit_n(as, ARMI_CMN|ARMI_K12|-irt_toitype_(t), type);
+ }
+ if (ra_hasreg(dest)) {
+#if !LJ_SOFTFP
+ if (t == IRT_NUM) {
+ if (ofs < 1024) {
+ emit_vlso(as, ARMI_VLDR_D, dest, base, ofs);
+ } else {
+ if (ra_hasreg(type)) emit_lso(as, ARMI_LDR, type, base, ofs+4);
+ emit_vlso(as, ARMI_VLDR_D, dest, RID_TMP, 0);
+ emit_opk(as, ARMI_ADD, RID_TMP, base, ofs, allow);
+ return;
+ }
+ } else
+#endif
+ emit_lso(as, ARMI_LDR, dest, base, ofs);
+ }
+ if (ra_hasreg(type)) emit_lso(as, ARMI_LDR, type, base, ofs+4);
+}
+
+/* -- Allocations --------------------------------------------------------- */
+
+#if LJ_HASFFI
+static void asm_cnew(ASMState *as, IRIns *ir)
+{
+ CTState *cts = ctype_ctsG(J2G(as->J));
+ CTypeID ctypeid = (CTypeID)IR(ir->op1)->i;
+ CTSize sz = (ir->o == IR_CNEWI || ir->op2 == REF_NIL) ?
+ lj_ctype_size(cts, ctypeid) : (CTSize)IR(ir->op2)->i;
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];
+ IRRef args[2];
+ RegSet allow = (RSET_GPR & ~RSET_SCRATCH);
+ RegSet drop = RSET_SCRATCH;
+ lua_assert(sz != CTSIZE_INVALID);
+
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ASMREF_TMP1; /* MSize size */
+ as->gcsteps++;
+
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ ra_evictset(as, drop);
+ if (ra_used(ir))
+ ra_destreg(as, ir, RID_RET); /* GCcdata * */
+
+ /* Initialize immutable cdata object. */
+ if (ir->o == IR_CNEWI) {
+ int32_t ofs = sizeof(GCcdata);
+ lua_assert(sz == 4 || sz == 8);
+ if (sz == 8) {
+ ofs += 4; ir++;
+ lua_assert(ir->o == IR_HIOP);
+ }
+ for (;;) {
+ Reg r = ra_alloc1(as, ir->op2, allow);
+ emit_lso(as, ARMI_STR, r, RID_RET, ofs);
+ rset_clear(allow, r);
+ if (ofs == sizeof(GCcdata)) break;
+ ofs -= 4; ir--;
+ }
+ }
+ /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */
+ {
+ uint32_t k = emit_isk12(ARMI_MOV, ctypeid);
+ Reg r = k ? RID_R1 : ra_allock(as, ctypeid, allow);
+ emit_lso(as, ARMI_STRB, RID_TMP, RID_RET, offsetof(GCcdata, gct));
+ emit_lsox(as, ARMI_STRH, r, RID_RET, offsetof(GCcdata, ctypeid));
+ emit_d(as, ARMI_MOV|ARMI_K12|~LJ_TCDATA, RID_TMP);
+ if (k) emit_d(as, ARMI_MOV^k, RID_R1);
+ }
+ asm_gencall(as, ci, args);
+ ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)),
+ ra_releasetmp(as, ASMREF_TMP1));
+}
+#else
+#define asm_cnew(as, ir) ((void)0)
+#endif
+
+/* -- Write barriers ------------------------------------------------------ */
+
+static void asm_tbar(ASMState *as, IRIns *ir)
+{
+ Reg tab = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg link = ra_scratch(as, rset_exclude(RSET_GPR, tab));
+ Reg gr = ra_allock(as, i32ptr(J2G(as->J)),
+ rset_exclude(rset_exclude(RSET_GPR, tab), link));
+ Reg mark = RID_TMP;
+ MCLabel l_end = emit_label(as);
+ emit_lso(as, ARMI_STR, link, tab, (int32_t)offsetof(GCtab, gclist));
+ emit_lso(as, ARMI_STRB, mark, tab, (int32_t)offsetof(GCtab, marked));
+ emit_lso(as, ARMI_STR, tab, gr,
+ (int32_t)offsetof(global_State, gc.grayagain));
+ emit_dn(as, ARMI_BIC|ARMI_K12|LJ_GC_BLACK, mark, mark);
+ emit_lso(as, ARMI_LDR, link, gr,
+ (int32_t)offsetof(global_State, gc.grayagain));
+ emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end);
+ emit_n(as, ARMI_TST|ARMI_K12|LJ_GC_BLACK, mark);
+ emit_lso(as, ARMI_LDRB, mark, tab, (int32_t)offsetof(GCtab, marked));
+}
+
+static void asm_obar(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv];
+ IRRef args[2];
+ MCLabel l_end;
+ Reg obj, val, tmp;
+ /* No need for other object barriers (yet). */
+ lua_assert(IR(ir->op1)->o == IR_UREFC);
+ ra_evictset(as, RSET_SCRATCH);
+ l_end = emit_label(as);
+ args[0] = ASMREF_TMP1; /* global_State *g */
+ args[1] = ir->op1; /* TValue *tv */
+ asm_gencall(as, ci, args);
+ if ((l_end[-1] >> 28) == CC_AL)
+ l_end[-1] = ARMF_CC(l_end[-1], CC_NE);
+ else
+ emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end);
+ ra_allockreg(as, i32ptr(J2G(as->J)), ra_releasetmp(as, ASMREF_TMP1));
+ obj = IR(ir->op1)->r;
+ tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj));
+ emit_n(as, ARMF_CC(ARMI_TST, CC_NE)|ARMI_K12|LJ_GC_BLACK, tmp);
+ emit_n(as, ARMI_TST|ARMI_K12|LJ_GC_WHITES, RID_TMP);
+ val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj));
+ emit_lso(as, ARMI_LDRB, tmp, obj,
+ (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv));
+ emit_lso(as, ARMI_LDRB, RID_TMP, val, (int32_t)offsetof(GChead, marked));
+}
+
+/* -- Arithmetic and logic operations ------------------------------------- */
+
+#if !LJ_SOFTFP
+static void asm_fparith(ASMState *as, IRIns *ir, ARMIns ai)
+{
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg right, left = ra_alloc2(as, ir, RSET_FPR);
+ right = (left >> 8); left &= 255;
+ emit_dnm(as, ai, (dest & 15), (left & 15), (right & 15));
+}
+
+static void asm_fpunary(ASMState *as, IRIns *ir, ARMIns ai)
+{
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR);
+ emit_dm(as, ai, (dest & 15), (left & 15));
+}
+
+static int asm_fpjoin_pow(ASMState *as, IRIns *ir)
+{
+ IRIns *irp = IR(ir->op1);
+ if (irp == ir-1 && irp->o == IR_MUL && !ra_used(irp)) {
+ IRIns *irpp = IR(irp->op1);
+ if (irpp == ir-2 && irpp->o == IR_FPMATH &&
+ irpp->op2 == IRFPM_LOG2 && !ra_used(irpp)) {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_pow];
+ IRRef args[2];
+ args[0] = irpp->op1;
+ args[1] = irp->op2;
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+ return 1;
+ }
+ }
+ return 0;
+}
+#endif
+
+static int asm_swapops(ASMState *as, IRRef lref, IRRef rref)
+{
+ IRIns *ir;
+ if (irref_isk(rref))
+ return 0; /* Don't swap constants to the left. */
+ if (irref_isk(lref))
+ return 1; /* But swap constants to the right. */
+ ir = IR(rref);
+ if ((ir->o >= IR_BSHL && ir->o <= IR_BROR) ||
+ (ir->o == IR_ADD && ir->op1 == ir->op2))
+ return 0; /* Don't swap fusable operands to the left. */
+ ir = IR(lref);
+ if ((ir->o >= IR_BSHL && ir->o <= IR_BROR) ||
+ (ir->o == IR_ADD && ir->op1 == ir->op2))
+ return 1; /* But swap fusable operands to the right. */
+ return 0; /* Otherwise don't swap. */
+}
+
+static void asm_intop(ASMState *as, IRIns *ir, ARMIns ai)
+{
+ IRRef lref = ir->op1, rref = ir->op2;
+ Reg left, dest = ra_dest(as, ir, RSET_GPR);
+ uint32_t m;
+ if (asm_swapops(as, lref, rref)) {
+ IRRef tmp = lref; lref = rref; rref = tmp;
+ if ((ai & ~ARMI_S) == ARMI_SUB || (ai & ~ARMI_S) == ARMI_SBC)
+ ai ^= (ARMI_SUB^ARMI_RSB);
+ }
+ left = ra_hintalloc(as, lref, dest, RSET_GPR);
+ m = asm_fuseopm(as, ai, rref, rset_exclude(RSET_GPR, left));
+ if (irt_isguard(ir->t)) { /* For IR_ADDOV etc. */
+ asm_guardcc(as, CC_VS);
+ ai |= ARMI_S;
+ }
+ emit_dn(as, ai^m, dest, left);
+}
+
+static void asm_intop_s(ASMState *as, IRIns *ir, ARMIns ai)
+{
+ if (as->flagmcp == as->mcp) { /* Drop cmp r, #0. */
+ as->flagmcp = NULL;
+ as->mcp++;
+ ai |= ARMI_S;
+ }
+ asm_intop(as, ir, ai);
+}
+
+static void asm_bitop(ASMState *as, IRIns *ir, ARMIns ai)
+{
+ if (as->flagmcp == as->mcp) { /* Try to drop cmp r, #0. */
+ uint32_t cc = (as->mcp[1] >> 28);
+ as->flagmcp = NULL;
+ if (cc <= CC_NE) {
+ as->mcp++;
+ ai |= ARMI_S;
+ } else if (cc == CC_GE) {
+ *++as->mcp ^= ((CC_GE^CC_PL) << 28);
+ ai |= ARMI_S;
+ } else if (cc == CC_LT) {
+ *++as->mcp ^= ((CC_LT^CC_MI) << 28);
+ ai |= ARMI_S;
+ } /* else: other conds don't work with bit ops. */
+ }
+ if (ir->op2 == 0) {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ uint32_t m = asm_fuseopm(as, ai, ir->op1, RSET_GPR);
+ emit_d(as, ai^m, dest);
+ } else {
+ /* NYI: Turn BAND !k12 into uxtb, uxth or bfc or shl+shr. */
+ asm_intop(as, ir, ai);
+ }
+}
+
+static void asm_intneg(ASMState *as, IRIns *ir, ARMIns ai)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ emit_dn(as, ai|ARMI_K12|0, dest, left);
+}
+
+/* NYI: use add/shift for MUL(OV) with constants. FOLD only does 2^k. */
+static void asm_intmul(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, dest));
+ Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ Reg tmp = RID_NONE;
+ /* ARMv5 restriction: dest != left and dest_hi != left. */
+ if (dest == left && left != right) { left = right; right = dest; }
+ if (irt_isguard(ir->t)) { /* IR_MULOV */
+ if (!(as->flags & JIT_F_ARMV6) && dest == left)
+ tmp = left = ra_scratch(as, rset_exclude(RSET_GPR, left));
+ asm_guardcc(as, CC_NE);
+ emit_nm(as, ARMI_TEQ|ARMF_SH(ARMSH_ASR, 31), RID_TMP, dest);
+ emit_dnm(as, ARMI_SMULL|ARMF_S(right), dest, RID_TMP, left);
+ } else {
+ if (!(as->flags & JIT_F_ARMV6) && dest == left) tmp = left = RID_TMP;
+ emit_nm(as, ARMI_MUL|ARMF_S(right), dest, left);
+ }
+ /* Only need this for the dest == left == right case. */
+ if (ra_hasreg(tmp)) emit_dm(as, ARMI_MOV, tmp, right);
+}
+
+static void asm_add(ASMState *as, IRIns *ir)
+{
+#if !LJ_SOFTFP
+ if (irt_isnum(ir->t)) {
+ if (!asm_fusemadd(as, ir, ARMI_VMLA_D, ARMI_VMLA_D))
+ asm_fparith(as, ir, ARMI_VADD_D);
+ return;
+ }
+#endif
+ asm_intop_s(as, ir, ARMI_ADD);
+}
+
+static void asm_sub(ASMState *as, IRIns *ir)
+{
+#if !LJ_SOFTFP
+ if (irt_isnum(ir->t)) {
+ if (!asm_fusemadd(as, ir, ARMI_VNMLS_D, ARMI_VMLS_D))
+ asm_fparith(as, ir, ARMI_VSUB_D);
+ return;
+ }
+#endif
+ asm_intop_s(as, ir, ARMI_SUB);
+}
+
+static void asm_mul(ASMState *as, IRIns *ir)
+{
+#if !LJ_SOFTFP
+ if (irt_isnum(ir->t)) {
+ asm_fparith(as, ir, ARMI_VMUL_D);
+ return;
+ }
+#endif
+ asm_intmul(as, ir);
+}
+
+static void asm_neg(ASMState *as, IRIns *ir)
+{
+#if !LJ_SOFTFP
+ if (irt_isnum(ir->t)) {
+ asm_fpunary(as, ir, ARMI_VNEG_D);
+ return;
+ }
+#endif
+ asm_intneg(as, ir, ARMI_RSB);
+}
+
+static void asm_callid(ASMState *as, IRIns *ir, IRCallID id)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[id];
+ IRRef args[2];
+ args[0] = ir->op1;
+ args[1] = ir->op2;
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+
+#if !LJ_SOFTFP
+static void asm_callround(ASMState *as, IRIns *ir, int id)
+{
+ /* The modified regs must match with the *.dasc implementation. */
+ RegSet drop = RID2RSET(RID_R0)|RID2RSET(RID_R1)|RID2RSET(RID_R2)|
+ RID2RSET(RID_R3)|RID2RSET(RID_R12);
+ RegSet of;
+ Reg dest, src;
+ ra_evictset(as, drop);
+ dest = ra_dest(as, ir, RSET_FPR);
+ emit_dnm(as, ARMI_VMOV_D_RR, RID_RETLO, RID_RETHI, (dest & 15));
+ emit_call(as, id == IRFPM_FLOOR ? (void *)lj_vm_floor_sf :
+ id == IRFPM_CEIL ? (void *)lj_vm_ceil_sf :
+ (void *)lj_vm_trunc_sf);
+ /* Workaround to protect argument GPRs from being used for remat. */
+ of = as->freeset;
+ as->freeset &= ~RSET_RANGE(RID_R0, RID_R1+1);
+ as->cost[RID_R0] = as->cost[RID_R1] = REGCOST(~0u, ASMREF_L);
+ src = ra_alloc1(as, ir->op1, RSET_FPR); /* May alloc GPR to remat FPR. */
+ as->freeset |= (of & RSET_RANGE(RID_R0, RID_R1+1));
+ emit_dnm(as, ARMI_VMOV_RR_D, RID_R0, RID_R1, (src & 15));
+}
+#endif
+
+static void asm_bitswap(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
+ if ((as->flags & JIT_F_ARMV6)) {
+ emit_dm(as, ARMI_REV, dest, left);
+ } else {
+ Reg tmp2 = dest;
+ if (tmp2 == left)
+ tmp2 = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, dest), left));
+ emit_dnm(as, ARMI_EOR|ARMF_SH(ARMSH_LSR, 8), dest, tmp2, RID_TMP);
+ emit_dm(as, ARMI_MOV|ARMF_SH(ARMSH_ROR, 8), tmp2, left);
+ emit_dn(as, ARMI_BIC|ARMI_K12|256*8|255, RID_TMP, RID_TMP);
+ emit_dnm(as, ARMI_EOR|ARMF_SH(ARMSH_ROR, 16), RID_TMP, left, left);
+ }
+}
+
+static void asm_bitshift(ASMState *as, IRIns *ir, ARMShift sh)
+{
+ if (irref_isk(ir->op2)) { /* Constant shifts. */
+ /* NYI: Turn SHL+SHR or BAND+SHR into uxtb, uxth or ubfx. */
+ /* NYI: Turn SHL+ASR into sxtb, sxth or sbfx. */
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
+ int32_t shift = (IR(ir->op2)->i & 31);
+ emit_dm(as, ARMI_MOV|ARMF_SH(sh, shift), dest, left);
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_dm(as, ARMI_MOV|ARMF_RSH(sh, right), dest, left);
+ }
+}
+
+static void asm_intmin_max(ASMState *as, IRIns *ir, int cc)
+{
+ uint32_t kcmp = 0, kmov = 0;
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ Reg right = 0;
+ if (irref_isk(ir->op2)) {
+ kcmp = emit_isk12(ARMI_CMP, IR(ir->op2)->i);
+ if (kcmp) kmov = emit_isk12(ARMI_MOV, IR(ir->op2)->i);
+ }
+ if (!kmov) {
+ kcmp = 0;
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ }
+ if (kmov || dest != right) {
+ emit_dm(as, ARMF_CC(ARMI_MOV, cc)^kmov, dest, right);
+ cc ^= 1; /* Must use opposite conditions for paired moves. */
+ } else {
+ cc ^= (CC_LT^CC_GT); /* Otherwise may swap CC_LT <-> CC_GT. */
+ }
+ if (dest != left) emit_dm(as, ARMF_CC(ARMI_MOV, cc), dest, left);
+ emit_nm(as, ARMI_CMP^kcmp, left, right);
+}
+
+#if LJ_SOFTFP
+static void asm_sfpmin_max(ASMState *as, IRIns *ir, int cc)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_softfp_cmp];
+ RegSet drop = RSET_SCRATCH;
+ Reg r;
+ IRRef args[4];
+ args[0] = ir->op1; args[1] = (ir+1)->op1;
+ args[2] = ir->op2; args[3] = (ir+1)->op2;
+ /* __aeabi_cdcmple preserves r0-r3. */
+ if (ra_hasreg(ir->r)) rset_clear(drop, ir->r);
+ if (ra_hasreg((ir+1)->r)) rset_clear(drop, (ir+1)->r);
+ if (!rset_test(as->freeset, RID_R2) &&
+ regcost_ref(as->cost[RID_R2]) == args[2]) rset_clear(drop, RID_R2);
+ if (!rset_test(as->freeset, RID_R3) &&
+ regcost_ref(as->cost[RID_R3]) == args[3]) rset_clear(drop, RID_R3);
+ ra_evictset(as, drop);
+ ra_destpair(as, ir);
+ emit_dm(as, ARMF_CC(ARMI_MOV, cc), RID_RETHI, RID_R3);
+ emit_dm(as, ARMF_CC(ARMI_MOV, cc), RID_RETLO, RID_R2);
+ emit_call(as, (void *)ci->func);
+ for (r = RID_R0; r <= RID_R3; r++)
+ ra_leftov(as, r, args[r-RID_R0]);
+}
+#else
+static void asm_fpmin_max(ASMState *as, IRIns *ir, int cc)
+{
+ Reg dest = (ra_dest(as, ir, RSET_FPR) & 15);
+ Reg right, left = ra_alloc2(as, ir, RSET_FPR);
+ right = ((left >> 8) & 15); left &= 15;
+ if (dest != left) emit_dm(as, ARMF_CC(ARMI_VMOV_D, cc^1), dest, left);
+ if (dest != right) emit_dm(as, ARMF_CC(ARMI_VMOV_D, cc), dest, right);
+ emit_d(as, ARMI_VMRS, 0);
+ emit_dm(as, ARMI_VCMP_D, left, right);
+}
+#endif
+
+static void asm_min_max(ASMState *as, IRIns *ir, int cc, int fcc)
+{
+#if LJ_SOFTFP
+ UNUSED(fcc);
+#else
+ if (irt_isnum(ir->t))
+ asm_fpmin_max(as, ir, fcc);
+ else
+#endif
+ asm_intmin_max(as, ir, cc);
+}
+
+/* -- Comparisons --------------------------------------------------------- */
+
+/* Map of comparisons to flags. ORDER IR. */
+static const uint8_t asm_compmap[IR_ABC+1] = {
+ /* op FP swp int cc FP cc */
+ /* LT */ CC_GE + (CC_HS << 4),
+ /* GE x */ CC_LT + (CC_HI << 4),
+ /* LE */ CC_GT + (CC_HI << 4),
+ /* GT x */ CC_LE + (CC_HS << 4),
+ /* ULT x */ CC_HS + (CC_LS << 4),
+ /* UGE */ CC_LO + (CC_LO << 4),
+ /* ULE x */ CC_HI + (CC_LO << 4),
+ /* UGT */ CC_LS + (CC_LS << 4),
+ /* EQ */ CC_NE + (CC_NE << 4),
+ /* NE */ CC_EQ + (CC_EQ << 4),
+ /* ABC */ CC_LS + (CC_LS << 4) /* Same as UGT. */
+};
+
+#if LJ_SOFTFP
+/* FP comparisons. */
+static void asm_sfpcomp(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_softfp_cmp];
+ RegSet drop = RSET_SCRATCH;
+ Reg r;
+ IRRef args[4];
+ int swp = (((ir->o ^ (ir->o >> 2)) & ~(ir->o >> 3) & 1) << 1);
+ args[swp^0] = ir->op1; args[swp^1] = (ir+1)->op1;
+ args[swp^2] = ir->op2; args[swp^3] = (ir+1)->op2;
+ /* __aeabi_cdcmple preserves r0-r3. This helps to reduce spills. */
+ for (r = RID_R0; r <= RID_R3; r++)
+ if (!rset_test(as->freeset, r) &&
+ regcost_ref(as->cost[r]) == args[r-RID_R0]) rset_clear(drop, r);
+ ra_evictset(as, drop);
+ asm_guardcc(as, (asm_compmap[ir->o] >> 4));
+ emit_call(as, (void *)ci->func);
+ for (r = RID_R0; r <= RID_R3; r++)
+ ra_leftov(as, r, args[r-RID_R0]);
+}
+#else
+/* FP comparisons. */
+static void asm_fpcomp(ASMState *as, IRIns *ir)
+{
+ Reg left, right;
+ ARMIns ai;
+ int swp = ((ir->o ^ (ir->o >> 2)) & ~(ir->o >> 3) & 1);
+ if (!swp && irref_isk(ir->op2) && ir_knum(IR(ir->op2))->u64 == 0) {
+ left = (ra_alloc1(as, ir->op1, RSET_FPR) & 15);
+ right = 0;
+ ai = ARMI_VCMPZ_D;
+ } else {
+ left = ra_alloc2(as, ir, RSET_FPR);
+ if (swp) {
+ right = (left & 15); left = ((left >> 8) & 15);
+ } else {
+ right = ((left >> 8) & 15); left &= 15;
+ }
+ ai = ARMI_VCMP_D;
+ }
+ asm_guardcc(as, (asm_compmap[ir->o] >> 4));
+ emit_d(as, ARMI_VMRS, 0);
+ emit_dm(as, ai, left, right);
+}
+#endif
+
+/* Integer comparisons. */
+static void asm_intcomp(ASMState *as, IRIns *ir)
+{
+ ARMCC cc = (asm_compmap[ir->o] & 15);
+ IRRef lref = ir->op1, rref = ir->op2;
+ Reg left;
+ uint32_t m;
+ int cmpprev0 = 0;
+ lua_assert(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t));
+ if (asm_swapops(as, lref, rref)) {
+ Reg tmp = lref; lref = rref; rref = tmp;
+ if (cc >= CC_GE) cc ^= 7; /* LT <-> GT, LE <-> GE */
+ else if (cc > CC_NE) cc ^= 11; /* LO <-> HI, LS <-> HS */
+ }
+ if (irref_isk(rref) && IR(rref)->i == 0) {
+ IRIns *irl = IR(lref);
+ cmpprev0 = (irl+1 == ir);
+ /* Combine comp(BAND(left, right), 0) into tst left, right. */
+ if (cmpprev0 && irl->o == IR_BAND && !ra_used(irl)) {
+ IRRef blref = irl->op1, brref = irl->op2;
+ uint32_t m2 = 0;
+ Reg bleft;
+ if (asm_swapops(as, blref, brref)) {
+ Reg tmp = blref; blref = brref; brref = tmp;
+ }
+ if (irref_isk(brref)) {
+ m2 = emit_isk12(ARMI_AND, IR(brref)->i);
+ if ((m2 & (ARMI_AND^ARMI_BIC)))
+ goto notst; /* Not beneficial if we miss a constant operand. */
+ }
+ if (cc == CC_GE) cc = CC_PL;
+ else if (cc == CC_LT) cc = CC_MI;
+ else if (cc > CC_NE) goto notst; /* Other conds don't work with tst. */
+ bleft = ra_alloc1(as, blref, RSET_GPR);
+ if (!m2) m2 = asm_fuseopm(as, 0, brref, rset_exclude(RSET_GPR, bleft));
+ asm_guardcc(as, cc);
+ emit_n(as, ARMI_TST^m2, bleft);
+ return;
+ }
+ }
+notst:
+ left = ra_alloc1(as, lref, RSET_GPR);
+ m = asm_fuseopm(as, ARMI_CMP, rref, rset_exclude(RSET_GPR, left));
+ asm_guardcc(as, cc);
+ emit_n(as, ARMI_CMP^m, left);
+ /* Signed comparison with zero and referencing previous ins? */
+ if (cmpprev0 && (cc <= CC_NE || cc >= CC_GE))
+ as->flagmcp = as->mcp; /* Allow elimination of the compare. */
+}
+
+#if LJ_HASFFI
+/* 64 bit integer comparisons. */
+static void asm_int64comp(ASMState *as, IRIns *ir)
+{
+ int signedcomp = (ir->o <= IR_GT);
+ ARMCC cclo, cchi;
+ Reg leftlo, lefthi;
+ uint32_t mlo, mhi;
+ RegSet allow = RSET_GPR, oldfree;
+
+ /* Always use unsigned comparison for loword. */
+ cclo = asm_compmap[ir->o + (signedcomp ? 4 : 0)] & 15;
+ leftlo = ra_alloc1(as, ir->op1, allow);
+ oldfree = as->freeset;
+ mlo = asm_fuseopm(as, ARMI_CMP, ir->op2, rset_clear(allow, leftlo));
+ allow &= ~(oldfree & ~as->freeset); /* Update for allocs of asm_fuseopm. */
+
+ /* Use signed or unsigned comparison for hiword. */
+ cchi = asm_compmap[ir->o] & 15;
+ lefthi = ra_alloc1(as, (ir+1)->op1, allow);
+ mhi = asm_fuseopm(as, ARMI_CMP, (ir+1)->op2, rset_clear(allow, lefthi));
+
+ /* All register allocations must be performed _before_ this point. */
+ if (signedcomp) {
+ MCLabel l_around = emit_label(as);
+ asm_guardcc(as, cclo);
+ emit_n(as, ARMI_CMP^mlo, leftlo);
+ emit_branch(as, ARMF_CC(ARMI_B, CC_NE), l_around);
+ if (cchi == CC_GE || cchi == CC_LE) cchi ^= 6; /* GE -> GT, LE -> LT */
+ asm_guardcc(as, cchi);
+ } else {
+ asm_guardcc(as, cclo);
+ emit_n(as, ARMF_CC(ARMI_CMP, CC_EQ)^mlo, leftlo);
+ }
+ emit_n(as, ARMI_CMP^mhi, lefthi);
+}
+#endif
+
+/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */
+
+/* Hiword op of a split 64 bit op. Previous op must be the loword op. */
+static void asm_hiop(ASMState *as, IRIns *ir)
+{
+#if LJ_HASFFI || LJ_SOFTFP
+ /* HIOP is marked as a store because it needs its own DCE logic. */
+ int uselo = ra_used(ir-1), usehi = ra_used(ir); /* Loword/hiword used? */
+ if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1;
+ if ((ir-1)->o <= IR_NE) { /* 64 bit integer or FP comparisons. ORDER IR. */
+ as->curins--; /* Always skip the loword comparison. */
+#if LJ_SOFTFP
+ if (!irt_isint(ir->t)) {
+ asm_sfpcomp(as, ir-1);
+ return;
+ }
+#endif
+#if LJ_HASFFI
+ asm_int64comp(as, ir-1);
+#endif
+ return;
+#if LJ_SOFTFP
+ } else if ((ir-1)->o == IR_MIN || (ir-1)->o == IR_MAX) {
+ as->curins--; /* Always skip the loword min/max. */
+ if (uselo || usehi)
+ asm_sfpmin_max(as, ir-1, (ir-1)->o == IR_MIN ? CC_HI : CC_LO);
+ return;
+#elif LJ_HASFFI
+ } else if ((ir-1)->o == IR_CONV) {
+ as->curins--; /* Always skip the CONV. */
+ if (usehi || uselo)
+ asm_conv64(as, ir);
+ return;
+#endif
+ } else if ((ir-1)->o == IR_XSTORE) {
+ if ((ir-1)->r != RID_SINK)
+ asm_xstore(as, ir, 4);
+ return;
+ }
+ if (!usehi) return; /* Skip unused hiword op for all remaining ops. */
+ switch ((ir-1)->o) {
+#if LJ_HASFFI
+ case IR_ADD:
+ as->curins--;
+ asm_intop(as, ir, ARMI_ADC);
+ asm_intop(as, ir-1, ARMI_ADD|ARMI_S);
+ break;
+ case IR_SUB:
+ as->curins--;
+ asm_intop(as, ir, ARMI_SBC);
+ asm_intop(as, ir-1, ARMI_SUB|ARMI_S);
+ break;
+ case IR_NEG:
+ as->curins--;
+ asm_intneg(as, ir, ARMI_RSC);
+ asm_intneg(as, ir-1, ARMI_RSB|ARMI_S);
+ break;
+#endif
+#if LJ_SOFTFP
+ case IR_SLOAD: case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:
+ case IR_STRTO:
+ if (!uselo)
+ ra_allocref(as, ir->op1, RSET_GPR); /* Mark lo op as used. */
+ break;
+#endif
+ case IR_CALLN:
+ case IR_CALLS:
+ case IR_CALLXS:
+ if (!uselo)
+ ra_allocref(as, ir->op1, RID2RSET(RID_RETLO)); /* Mark lo op as used. */
+ break;
+#if LJ_SOFTFP
+ case IR_ASTORE: case IR_HSTORE: case IR_USTORE: case IR_TOSTR:
+#endif
+ case IR_CNEWI:
+ /* Nothing to do here. Handled by lo op itself. */
+ break;
+ default: lua_assert(0); break;
+ }
+#else
+ UNUSED(as); UNUSED(ir); lua_assert(0);
+#endif
+}
+
+/* -- Stack handling ------------------------------------------------------ */
+
+/* Check Lua stack size for overflow. Use exit handler as fallback. */
+static void asm_stack_check(ASMState *as, BCReg topslot,
+ IRIns *irp, RegSet allow, ExitNo exitno)
+{
+ Reg pbase;
+ uint32_t k;
+ if (irp) {
+ if (!ra_hasspill(irp->s)) {
+ pbase = irp->r;
+ lua_assert(ra_hasreg(pbase));
+ } else if (allow) {
+ pbase = rset_pickbot(allow);
+ } else {
+ pbase = RID_RET;
+ emit_lso(as, ARMI_LDR, RID_RET, RID_SP, 0); /* Restore temp. register. */
+ }
+ } else {
+ pbase = RID_BASE;
+ }
+ emit_branch(as, ARMF_CC(ARMI_BL, CC_LS), exitstub_addr(as->J, exitno));
+ k = emit_isk12(0, (int32_t)(8*topslot));
+ lua_assert(k);
+ emit_n(as, ARMI_CMP^k, RID_TMP);
+ emit_dnm(as, ARMI_SUB, RID_TMP, RID_TMP, pbase);
+ emit_lso(as, ARMI_LDR, RID_TMP, RID_TMP,
+ (int32_t)offsetof(lua_State, maxstack));
+ if (irp) { /* Must not spill arbitrary registers in head of side trace. */
+ int32_t i = i32ptr(&J2G(as->J)->jit_L);
+ if (ra_hasspill(irp->s))
+ emit_lso(as, ARMI_LDR, pbase, RID_SP, sps_scale(irp->s));
+ emit_lso(as, ARMI_LDR, RID_TMP, RID_TMP, (i & 4095));
+ if (ra_hasspill(irp->s) && !allow)
+ emit_lso(as, ARMI_STR, RID_RET, RID_SP, 0); /* Save temp. register. */
+ emit_loadi(as, RID_TMP, (i & ~4095));
+ } else {
+ emit_getgl(as, RID_TMP, jit_L);
+ }
+}
+
+/* Restore Lua stack from on-trace state. */
+static void asm_stack_restore(ASMState *as, SnapShot *snap)
+{
+ SnapEntry *map = &as->T->snapmap[snap->mapofs];
+ SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1];
+ MSize n, nent = snap->nent;
+ /* Store the value of all modified slots to the Lua stack. */
+ for (n = 0; n < nent; n++) {
+ SnapEntry sn = map[n];
+ BCReg s = snap_slot(sn);
+ int32_t ofs = 8*((int32_t)s-1);
+ IRRef ref = snap_ref(sn);
+ IRIns *ir = IR(ref);
+ if ((sn & SNAP_NORESTORE))
+ continue;
+ if (irt_isnum(ir->t)) {
+#if LJ_SOFTFP
+ RegSet odd = rset_exclude(RSET_GPRODD, RID_BASE);
+ Reg tmp;
+ lua_assert(irref_isk(ref)); /* LJ_SOFTFP: must be a number constant. */
+ tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.lo,
+ rset_exclude(RSET_GPREVEN, RID_BASE));
+ emit_lso(as, ARMI_STR, tmp, RID_BASE, ofs);
+ if (rset_test(as->freeset, tmp+1)) odd = RID2RSET(tmp+1);
+ tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.hi, odd);
+ emit_lso(as, ARMI_STR, tmp, RID_BASE, ofs+4);
+#else
+ Reg src = ra_alloc1(as, ref, RSET_FPR);
+ emit_vlso(as, ARMI_VSTR_D, src, RID_BASE, ofs);
+#endif
+ } else {
+ RegSet odd = rset_exclude(RSET_GPRODD, RID_BASE);
+ Reg type;
+ lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t));
+ if (!irt_ispri(ir->t)) {
+ Reg src = ra_alloc1(as, ref, rset_exclude(RSET_GPREVEN, RID_BASE));
+ emit_lso(as, ARMI_STR, src, RID_BASE, ofs);
+ if (rset_test(as->freeset, src+1)) odd = RID2RSET(src+1);
+ }
+ if ((sn & (SNAP_CONT|SNAP_FRAME))) {
+ if (s == 0) continue; /* Do not overwrite link to previous frame. */
+ type = ra_allock(as, (int32_t)(*flinks--), odd);
+#if LJ_SOFTFP
+ } else if ((sn & SNAP_SOFTFPNUM)) {
+ type = ra_alloc1(as, ref+1, rset_exclude(RSET_GPRODD, RID_BASE));
+#endif
+ } else {
+ type = ra_allock(as, (int32_t)irt_toitype(ir->t), odd);
+ }
+ emit_lso(as, ARMI_STR, type, RID_BASE, ofs+4);
+ }
+ checkmclim(as);
+ }
+ lua_assert(map + nent == flinks);
+}
+
+/* -- GC handling --------------------------------------------------------- */
+
+/* Check GC threshold and do one or more GC steps. */
+static void asm_gc_check(ASMState *as)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit];
+ IRRef args[2];
+ MCLabel l_end;
+ Reg tmp1, tmp2;
+ ra_evictset(as, RSET_SCRATCH);
+ l_end = emit_label(as);
+ /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */
+ asm_guardcc(as, CC_NE); /* Assumes asm_snap_prep() already done. */
+ emit_n(as, ARMI_CMP|ARMI_K12|0, RID_RET);
+ args[0] = ASMREF_TMP1; /* global_State *g */
+ args[1] = ASMREF_TMP2; /* MSize steps */
+ asm_gencall(as, ci, args);
+ tmp1 = ra_releasetmp(as, ASMREF_TMP1);
+ tmp2 = ra_releasetmp(as, ASMREF_TMP2);
+ emit_loadi(as, tmp2, as->gcsteps);
+ /* Jump around GC step if GC total < GC threshold. */
+ emit_branch(as, ARMF_CC(ARMI_B, CC_LS), l_end);
+ emit_nm(as, ARMI_CMP, RID_TMP, tmp2);
+ emit_lso(as, ARMI_LDR, tmp2, tmp1,
+ (int32_t)offsetof(global_State, gc.threshold));
+ emit_lso(as, ARMI_LDR, RID_TMP, tmp1,
+ (int32_t)offsetof(global_State, gc.total));
+ ra_allockreg(as, i32ptr(J2G(as->J)), tmp1);
+ as->gcsteps = 0;
+ checkmclim(as);
+}
+
+/* -- Loop handling ------------------------------------------------------- */
+
+/* Fixup the loop branch. */
+static void asm_loop_fixup(ASMState *as)
+{
+ MCode *p = as->mctop;
+ MCode *target = as->mcp;
+ if (as->loopinv) { /* Inverted loop branch? */
+ /* asm_guardcc already inverted the bcc and patched the final bl. */
+ p[-2] |= ((uint32_t)(target-p) & 0x00ffffffu);
+ } else {
+ p[-1] = ARMI_B | ((uint32_t)((target-p)-1) & 0x00ffffffu);
+ }
+}
+
+/* -- Head of trace ------------------------------------------------------- */
+
+/* Reload L register from g->jit_L. */
+static void asm_head_lreg(ASMState *as)
+{
+ IRIns *ir = IR(ASMREF_L);
+ if (ra_used(ir)) {
+ Reg r = ra_dest(as, ir, RSET_GPR);
+ emit_getgl(as, r, jit_L);
+ ra_evictk(as);
+ }
+}
+
+/* Coalesce BASE register for a root trace. */
+static void asm_head_root_base(ASMState *as)
+{
+ IRIns *ir;
+ asm_head_lreg(as);
+ ir = IR(REF_BASE);
+ if (ra_hasreg(ir->r) && (rset_test(as->modset, ir->r) || irt_ismarked(ir->t)))
+ ra_spill(as, ir);
+ ra_destreg(as, ir, RID_BASE);
+}
+
+/* Coalesce BASE register for a side trace. */
+static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow)
+{
+ IRIns *ir;
+ asm_head_lreg(as);
+ ir = IR(REF_BASE);
+ if (ra_hasreg(ir->r) && (rset_test(as->modset, ir->r) || irt_ismarked(ir->t)))
+ ra_spill(as, ir);
+ if (ra_hasspill(irp->s)) {
+ rset_clear(allow, ra_dest(as, ir, allow));
+ } else {
+ Reg r = irp->r;
+ lua_assert(ra_hasreg(r));
+ rset_clear(allow, r);
+ if (r != ir->r && !rset_test(as->freeset, r))
+ ra_restore(as, regcost_ref(as->cost[r]));
+ ra_destreg(as, ir, r);
+ }
+ return allow;
+}
+
+/* -- Tail of trace ------------------------------------------------------- */
+
+/* Fixup the tail code. */
+static void asm_tail_fixup(ASMState *as, TraceNo lnk)
+{
+ MCode *p = as->mctop;
+ MCode *target;
+ int32_t spadj = as->T->spadjust;
+ if (spadj == 0) {
+ as->mctop = --p;
+ } else {
+ /* Patch stack adjustment. */
+ uint32_t k = emit_isk12(ARMI_ADD, spadj);
+ lua_assert(k);
+ p[-2] = (ARMI_ADD^k) | ARMF_D(RID_SP) | ARMF_N(RID_SP);
+ }
+ /* Patch exit branch. */
+ target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp;
+ p[-1] = ARMI_B|(((target-p)-1)&0x00ffffffu);
+}
+
+/* Prepare tail of code. */
+static void asm_tail_prep(ASMState *as)
+{
+ MCode *p = as->mctop - 1; /* Leave room for exit branch. */
+ if (as->loopref) {
+ as->invmcp = as->mcp = p;
+ } else {
+ as->mcp = p-1; /* Leave room for stack pointer adjustment. */
+ as->invmcp = NULL;
+ }
+ *p = 0; /* Prevent load/store merging. */
+}
+
+/* -- Instruction dispatch ------------------------------------------------ */
+
+/* Assemble a single instruction. */
+static void asm_ir(ASMState *as, IRIns *ir)
+{
+ switch ((IROp)ir->o) {
+ /* Miscellaneous ops. */
+ case IR_LOOP: asm_loop(as); break;
+ case IR_NOP: case IR_XBAR: lua_assert(!ra_used(ir)); break;
+ case IR_USE:
+ ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break;
+ case IR_PHI: asm_phi(as, ir); break;
+ case IR_HIOP: asm_hiop(as, ir); break;
+ case IR_GCSTEP: asm_gcstep(as, ir); break;
+
+ /* Guarded assertions. */
+ case IR_EQ: case IR_NE:
+ if ((ir-1)->o == IR_HREF && ir->op1 == as->curins-1) {
+ as->curins--;
+ asm_href(as, ir-1, (IROp)ir->o);
+ break;
+ }
+ /* fallthrough */
+ case IR_LT: case IR_GE: case IR_LE: case IR_GT:
+ case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT:
+ case IR_ABC:
+#if !LJ_SOFTFP
+ if (irt_isnum(ir->t)) { asm_fpcomp(as, ir); break; }
+#endif
+ asm_intcomp(as, ir);
+ break;
+
+ case IR_RETF: asm_retf(as, ir); break;
+
+ /* Bit ops. */
+ case IR_BNOT: asm_bitop(as, ir, ARMI_MVN); break;
+ case IR_BSWAP: asm_bitswap(as, ir); break;
+
+ case IR_BAND: asm_bitop(as, ir, ARMI_AND); break;
+ case IR_BOR: asm_bitop(as, ir, ARMI_ORR); break;
+ case IR_BXOR: asm_bitop(as, ir, ARMI_EOR); break;
+
+ case IR_BSHL: asm_bitshift(as, ir, ARMSH_LSL); break;
+ case IR_BSHR: asm_bitshift(as, ir, ARMSH_LSR); break;
+ case IR_BSAR: asm_bitshift(as, ir, ARMSH_ASR); break;
+ case IR_BROR: asm_bitshift(as, ir, ARMSH_ROR); break;
+ case IR_BROL: lua_assert(0); break;
+
+ /* Arithmetic ops. */
+ case IR_ADD: case IR_ADDOV: asm_add(as, ir); break;
+ case IR_SUB: case IR_SUBOV: asm_sub(as, ir); break;
+ case IR_MUL: case IR_MULOV: asm_mul(as, ir); break;
+ case IR_MOD: asm_callid(as, ir, IRCALL_lj_vm_modi); break;
+ case IR_NEG: asm_neg(as, ir); break;
+
+#if LJ_SOFTFP
+ case IR_DIV: case IR_POW: case IR_ABS:
+ case IR_ATAN2: case IR_LDEXP: case IR_FPMATH: case IR_TOBIT:
+ lua_assert(0); /* Unused for LJ_SOFTFP. */
+ break;
+#else
+ case IR_DIV: asm_fparith(as, ir, ARMI_VDIV_D); break;
+ case IR_POW: asm_callid(as, ir, IRCALL_lj_vm_powi); break;
+ case IR_ABS: asm_fpunary(as, ir, ARMI_VABS_D); break;
+ case IR_ATAN2: asm_callid(as, ir, IRCALL_atan2); break;
+ case IR_LDEXP: asm_callid(as, ir, IRCALL_ldexp); break;
+ case IR_FPMATH:
+ if (ir->op2 == IRFPM_EXP2 && asm_fpjoin_pow(as, ir))
+ break;
+ if (ir->op2 <= IRFPM_TRUNC)
+ asm_callround(as, ir, ir->op2);
+ else if (ir->op2 == IRFPM_SQRT)
+ asm_fpunary(as, ir, ARMI_VSQRT_D);
+ else
+ asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2);
+ break;
+ case IR_TOBIT: asm_tobit(as, ir); break;
+#endif
+
+ case IR_MIN: asm_min_max(as, ir, CC_GT, CC_HI); break;
+ case IR_MAX: asm_min_max(as, ir, CC_LT, CC_LO); break;
+
+ /* Memory references. */
+ case IR_AREF: asm_aref(as, ir); break;
+ case IR_HREF: asm_href(as, ir, 0); break;
+ case IR_HREFK: asm_hrefk(as, ir); break;
+ case IR_NEWREF: asm_newref(as, ir); break;
+ case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break;
+ case IR_FREF: asm_fref(as, ir); break;
+ case IR_STRREF: asm_strref(as, ir); break;
+
+ /* Loads and stores. */
+ case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:
+ asm_ahuvload(as, ir);
+ break;
+ case IR_FLOAD: asm_fload(as, ir); break;
+ case IR_XLOAD: asm_xload(as, ir); break;
+ case IR_SLOAD: asm_sload(as, ir); break;
+
+ case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break;
+ case IR_FSTORE: asm_fstore(as, ir); break;
+ case IR_XSTORE: asm_xstore(as, ir, 0); break;
+
+ /* Allocations. */
+ case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break;
+ case IR_TNEW: asm_tnew(as, ir); break;
+ case IR_TDUP: asm_tdup(as, ir); break;
+ case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break;
+
+ /* Write barriers. */
+ case IR_TBAR: asm_tbar(as, ir); break;
+ case IR_OBAR: asm_obar(as, ir); break;
+
+ /* Type conversions. */
+ case IR_CONV: asm_conv(as, ir); break;
+ case IR_TOSTR: asm_tostr(as, ir); break;
+ case IR_STRTO: asm_strto(as, ir); break;
+
+ /* Calls. */
+ case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break;
+ case IR_CALLXS: asm_callx(as, ir); break;
+ case IR_CARG: break;
+
+ default:
+ setintV(&as->J->errinfo, ir->o);
+ lj_trace_err_info(as->J, LJ_TRERR_NYIIR);
+ break;
+ }
+}
+
+/* -- Trace setup --------------------------------------------------------- */
+
+/* Ensure there are enough stack slots for call arguments. */
+static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)
+{
+ IRRef args[CCI_NARGS_MAX*2];
+ uint32_t i, nargs = (int)CCI_NARGS(ci);
+ int nslots = 0, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR, fprodd = 0;
+ asm_collectargs(as, ir, ci, args);
+ for (i = 0; i < nargs; i++) {
+ if (!LJ_SOFTFP && args[i] && irt_isfp(IR(args[i])->t)) {
+ if (!LJ_ABI_SOFTFP && !(ci->flags & CCI_VARARG)) {
+ if (irt_isnum(IR(args[i])->t)) {
+ if (nfpr > 0) nfpr--;
+ else fprodd = 0, nslots = (nslots + 3) & ~1;
+ } else {
+ if (fprodd) fprodd--;
+ else if (nfpr > 0) fprodd = 1, nfpr--;
+ else nslots++;
+ }
+ } else if (irt_isnum(IR(args[i])->t)) {
+ ngpr &= ~1;
+ if (ngpr > 0) ngpr -= 2; else nslots += 2;
+ } else {
+ if (ngpr > 0) ngpr--; else nslots++;
+ }
+ } else {
+ if (ngpr > 0) ngpr--; else nslots++;
+ }
+ }
+ if (nslots > as->evenspill) /* Leave room for args in stack slots. */
+ as->evenspill = nslots;
+ return REGSP_HINT(RID_RET);
+}
+
+static void asm_setup_target(ASMState *as)
+{
+ /* May need extra exit for asm_stack_check on side traces. */
+ asm_exitstub_setup(as, as->T->nsnap + (as->parent ? 1 : 0));
+}
+
+/* -- Trace patching ------------------------------------------------------ */
+
+/* Patch exit jumps of existing machine code to a new target. */
+void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target)
+{
+ MCode *p = T->mcode;
+ MCode *pe = (MCode *)((char *)p + T->szmcode);
+ MCode *cstart = NULL, *cend = p;
+ MCode *mcarea = lj_mcode_patch(J, p, 0);
+ MCode *px = exitstub_addr(J, exitno) - 2;
+ for (; p < pe; p++) {
+ /* Look for bl_cc exitstub, replace with b_cc target. */
+ uint32_t ins = *p;
+ if ((ins & 0x0f000000u) == 0x0b000000u && ins < 0xf0000000u &&
+ ((ins ^ (px-p)) & 0x00ffffffu) == 0) {
+ *p = (ins & 0xfe000000u) | (((target-p)-2) & 0x00ffffffu);
+ cend = p+1;
+ if (!cstart) cstart = p;
+ }
+ }
+ lua_assert(cstart != NULL);
+ lj_mcode_sync(cstart, cend);
+ lj_mcode_patch(J, mcarea, 1);
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm_mips.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm_mips.h
new file mode 100644
index 0000000..7631190
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm_mips.h
@@ -0,0 +1,1977 @@
+/*
+** MIPS IR assembler (SSA IR -> machine code).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* -- Register allocator extensions --------------------------------------- */
+
+/* Allocate a register with a hint. */
+static Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow)
+{
+ Reg r = IR(ref)->r;
+ if (ra_noreg(r)) {
+ if (!ra_hashint(r) && !iscrossref(as, ref))
+ ra_sethint(IR(ref)->r, hint); /* Propagate register hint. */
+ r = ra_allocref(as, ref, allow);
+ }
+ ra_noweak(as, r);
+ return r;
+}
+
+/* Allocate a register or RID_ZERO. */
+static Reg ra_alloc1z(ASMState *as, IRRef ref, RegSet allow)
+{
+ Reg r = IR(ref)->r;
+ if (ra_noreg(r)) {
+ if (!(allow & RSET_FPR) && irref_isk(ref) && IR(ref)->i == 0)
+ return RID_ZERO;
+ r = ra_allocref(as, ref, allow);
+ } else {
+ ra_noweak(as, r);
+ }
+ return r;
+}
+
+/* Allocate two source registers for three-operand instructions. */
+static Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow)
+{
+ IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);
+ Reg left = irl->r, right = irr->r;
+ if (ra_hasreg(left)) {
+ ra_noweak(as, left);
+ if (ra_noreg(right))
+ right = ra_alloc1z(as, ir->op2, rset_exclude(allow, left));
+ else
+ ra_noweak(as, right);
+ } else if (ra_hasreg(right)) {
+ ra_noweak(as, right);
+ left = ra_alloc1z(as, ir->op1, rset_exclude(allow, right));
+ } else if (ra_hashint(right)) {
+ right = ra_alloc1z(as, ir->op2, allow);
+ left = ra_alloc1z(as, ir->op1, rset_exclude(allow, right));
+ } else {
+ left = ra_alloc1z(as, ir->op1, allow);
+ right = ra_alloc1z(as, ir->op2, rset_exclude(allow, left));
+ }
+ return left | (right << 8);
+}
+
+/* -- Guard handling ------------------------------------------------------ */
+
+/* Need some spare long-range jump slots, for out-of-range branches. */
+#define MIPS_SPAREJUMP 4
+
+/* Setup spare long-range jump slots per mcarea. */
+static void asm_sparejump_setup(ASMState *as)
+{
+ MCode *mxp = as->mcbot;
+ if (((uintptr_t)mxp & (LJ_PAGESIZE-1)) == sizeof(MCLink)) {
+ lua_assert(MIPSI_NOP == 0);
+ memset(mxp, 0, MIPS_SPAREJUMP*2*sizeof(MCode));
+ mxp += MIPS_SPAREJUMP*2;
+ lua_assert(mxp < as->mctop);
+ lj_mcode_sync(as->mcbot, mxp);
+ lj_mcode_commitbot(as->J, mxp);
+ as->mcbot = mxp;
+ as->mclim = as->mcbot + MCLIM_REDZONE;
+ }
+}
+
+/* Setup exit stub after the end of each trace. */
+static void asm_exitstub_setup(ASMState *as)
+{
+ MCode *mxp = as->mctop;
+ /* sw TMP, 0(sp); j ->vm_exit_handler; li TMP, traceno */
+ *--mxp = MIPSI_LI|MIPSF_T(RID_TMP)|as->T->traceno;
+ *--mxp = MIPSI_J|((((uintptr_t)(void *)lj_vm_exit_handler)>>2)&0x03ffffffu);
+ lua_assert(((uintptr_t)mxp ^ (uintptr_t)(void *)lj_vm_exit_handler)>>28 == 0);
+ *--mxp = MIPSI_SW|MIPSF_T(RID_TMP)|MIPSF_S(RID_SP)|0;
+ as->mctop = mxp;
+}
+
+/* Keep this in-sync with exitstub_trace_addr(). */
+#define asm_exitstub_addr(as) ((as)->mctop)
+
+/* Emit conditional branch to exit for guard. */
+static void asm_guard(ASMState *as, MIPSIns mi, Reg rs, Reg rt)
+{
+ MCode *target = asm_exitstub_addr(as);
+ MCode *p = as->mcp;
+ if (LJ_UNLIKELY(p == as->invmcp)) {
+ as->invmcp = NULL;
+ as->loopinv = 1;
+ as->mcp = p+1;
+ mi = mi ^ ((mi>>28) == 1 ? 0x04000000u : 0x00010000u); /* Invert cond. */
+ target = p; /* Patch target later in asm_loop_fixup. */
+ }
+ emit_ti(as, MIPSI_LI, RID_TMP, as->snapno);
+ emit_branch(as, mi, rs, rt, target);
+}
+
+/* -- Operand fusion ------------------------------------------------------ */
+
+/* Limit linear search to this distance. Avoids O(n^2) behavior. */
+#define CONFLICT_SEARCH_LIM 31
+
+/* Check if there's no conflicting instruction between curins and ref. */
+static int noconflict(ASMState *as, IRRef ref, IROp conflict)
+{
+ IRIns *ir = as->ir;
+ IRRef i = as->curins;
+ if (i > ref + CONFLICT_SEARCH_LIM)
+ return 0; /* Give up, ref is too far away. */
+ while (--i > ref)
+ if (ir[i].o == conflict)
+ return 0; /* Conflict found. */
+ return 1; /* Ok, no conflict. */
+}
+
+/* Fuse the array base of colocated arrays. */
+static int32_t asm_fuseabase(ASMState *as, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE &&
+ !neverfuse(as) && noconflict(as, ref, IR_NEWREF))
+ return (int32_t)sizeof(GCtab);
+ return 0;
+}
+
+/* Fuse array/hash/upvalue reference into register+offset operand. */
+static Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow)
+{
+ IRIns *ir = IR(ref);
+ if (ra_noreg(ir->r)) {
+ if (ir->o == IR_AREF) {
+ if (mayfuse(as, ref)) {
+ if (irref_isk(ir->op2)) {
+ IRRef tab = IR(ir->op1)->op1;
+ int32_t ofs = asm_fuseabase(as, tab);
+ IRRef refa = ofs ? tab : ir->op1;
+ ofs += 8*IR(ir->op2)->i;
+ if (checki16(ofs)) {
+ *ofsp = ofs;
+ return ra_alloc1(as, refa, allow);
+ }
+ }
+ }
+ } else if (ir->o == IR_HREFK) {
+ if (mayfuse(as, ref)) {
+ int32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node));
+ if (checki16(ofs)) {
+ *ofsp = ofs;
+ return ra_alloc1(as, ir->op1, allow);
+ }
+ }
+ } else if (ir->o == IR_UREFC) {
+ if (irref_isk(ir->op1)) {
+ GCfunc *fn = ir_kfunc(IR(ir->op1));
+ int32_t ofs = i32ptr(&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv);
+ int32_t jgl = (intptr_t)J2G(as->J);
+ if ((uint32_t)(ofs-jgl) < 65536) {
+ *ofsp = ofs-jgl-32768;
+ return RID_JGL;
+ } else {
+ *ofsp = (int16_t)ofs;
+ return ra_allock(as, ofs-(int16_t)ofs, allow);
+ }
+ }
+ }
+ }
+ *ofsp = 0;
+ return ra_alloc1(as, ref, allow);
+}
+
+/* Fuse XLOAD/XSTORE reference into load/store operand. */
+static void asm_fusexref(ASMState *as, MIPSIns mi, Reg rt, IRRef ref,
+ RegSet allow, int32_t ofs)
+{
+ IRIns *ir = IR(ref);
+ Reg base;
+ if (ra_noreg(ir->r) && canfuse(as, ir)) {
+ if (ir->o == IR_ADD) {
+ int32_t ofs2;
+ if (irref_isk(ir->op2) && (ofs2 = ofs + IR(ir->op2)->i, checki16(ofs2))) {
+ ref = ir->op1;
+ ofs = ofs2;
+ }
+ } else if (ir->o == IR_STRREF) {
+ int32_t ofs2 = 65536;
+ lua_assert(ofs == 0);
+ ofs = (int32_t)sizeof(GCstr);
+ if (irref_isk(ir->op2)) {
+ ofs2 = ofs + IR(ir->op2)->i;
+ ref = ir->op1;
+ } else if (irref_isk(ir->op1)) {
+ ofs2 = ofs + IR(ir->op1)->i;
+ ref = ir->op2;
+ }
+ if (!checki16(ofs2)) {
+ /* NYI: Fuse ADD with constant. */
+ Reg right, left = ra_alloc2(as, ir, allow);
+ right = (left >> 8); left &= 255;
+ emit_hsi(as, mi, rt, RID_TMP, ofs);
+ emit_dst(as, MIPSI_ADDU, RID_TMP, left, right);
+ return;
+ }
+ ofs = ofs2;
+ }
+ }
+ base = ra_alloc1(as, ref, allow);
+ emit_hsi(as, mi, rt, base, ofs);
+}
+
+/* -- Calls --------------------------------------------------------------- */
+
+/* Generate a call to a C function. */
+static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)
+{
+ uint32_t n, nargs = CCI_NARGS(ci);
+ int32_t ofs = 16;
+ Reg gpr, fpr = REGARG_FIRSTFPR;
+ if ((void *)ci->func)
+ emit_call(as, (void *)ci->func);
+ for (gpr = REGARG_FIRSTGPR; gpr <= REGARG_LASTGPR; gpr++)
+ as->cost[gpr] = REGCOST(~0u, ASMREF_L);
+ gpr = REGARG_FIRSTGPR;
+ for (n = 0; n < nargs; n++) { /* Setup args. */
+ IRRef ref = args[n];
+ if (ref) {
+ IRIns *ir = IR(ref);
+ if (irt_isfp(ir->t) && fpr <= REGARG_LASTFPR &&
+ !(ci->flags & CCI_VARARG)) {
+ lua_assert(rset_test(as->freeset, fpr)); /* Already evicted. */
+ ra_leftov(as, fpr, ref);
+ fpr += 2;
+ gpr += irt_isnum(ir->t) ? 2 : 1;
+ } else {
+ fpr = REGARG_LASTFPR+1;
+ if (irt_isnum(ir->t)) gpr = (gpr+1) & ~1;
+ if (gpr <= REGARG_LASTGPR) {
+ lua_assert(rset_test(as->freeset, gpr)); /* Already evicted. */
+ if (irt_isfp(ir->t)) {
+ RegSet of = as->freeset;
+ Reg r;
+ /* Workaround to protect argument GPRs from being used for remat. */
+ as->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1);
+ r = ra_alloc1(as, ref, RSET_FPR);
+ as->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1));
+ if (irt_isnum(ir->t)) {
+ emit_tg(as, MIPSI_MFC1, gpr+(LJ_BE?0:1), r+1);
+ emit_tg(as, MIPSI_MFC1, gpr+(LJ_BE?1:0), r);
+ lua_assert(rset_test(as->freeset, gpr+1)); /* Already evicted. */
+ gpr += 2;
+ } else if (irt_isfloat(ir->t)) {
+ emit_tg(as, MIPSI_MFC1, gpr, r);
+ gpr++;
+ }
+ } else {
+ ra_leftov(as, gpr, ref);
+ gpr++;
+ }
+ } else {
+ Reg r = ra_alloc1z(as, ref, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);
+ if (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4;
+ emit_spstore(as, ir, r, ofs);
+ ofs += irt_isnum(ir->t) ? 8 : 4;
+ }
+ }
+ } else {
+ fpr = REGARG_LASTFPR+1;
+ if (gpr <= REGARG_LASTGPR)
+ gpr++;
+ else
+ ofs += 4;
+ }
+ checkmclim(as);
+ }
+}
+
+/* Setup result reg/sp for call. Evict scratch regs. */
+static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci)
+{
+ RegSet drop = RSET_SCRATCH;
+ int hiop = ((ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t));
+ if ((ci->flags & CCI_NOFPRCLOBBER))
+ drop &= ~RSET_FPR;
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ if (hiop && ra_hasreg((ir+1)->r))
+ rset_clear(drop, (ir+1)->r); /* Dest reg handled below. */
+ ra_evictset(as, drop); /* Evictions must be performed first. */
+ if (ra_used(ir)) {
+ lua_assert(!irt_ispri(ir->t));
+ if (irt_isfp(ir->t)) {
+ if ((ci->flags & CCI_CASTU64)) {
+ int32_t ofs = sps_scale(ir->s);
+ Reg dest = ir->r;
+ if (ra_hasreg(dest)) {
+ ra_free(as, dest);
+ ra_modified(as, dest);
+ emit_tg(as, MIPSI_MTC1, RID_RETHI, dest+1);
+ emit_tg(as, MIPSI_MTC1, RID_RETLO, dest);
+ }
+ if (ofs) {
+ emit_tsi(as, MIPSI_SW, RID_RETLO, RID_SP, ofs+(LJ_BE?4:0));
+ emit_tsi(as, MIPSI_SW, RID_RETHI, RID_SP, ofs+(LJ_BE?0:4));
+ }
+ } else {
+ ra_destreg(as, ir, RID_FPRET);
+ }
+ } else if (hiop) {
+ ra_destpair(as, ir);
+ } else {
+ ra_destreg(as, ir, RID_RET);
+ }
+ }
+}
+
+static void asm_call(ASMState *as, IRIns *ir)
+{
+ IRRef args[CCI_NARGS_MAX];
+ const CCallInfo *ci = &lj_ir_callinfo[ir->op2];
+ asm_collectargs(as, ir, ci, args);
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+
+static void asm_callx(ASMState *as, IRIns *ir)
+{
+ IRRef args[CCI_NARGS_MAX*2];
+ CCallInfo ci;
+ IRRef func;
+ IRIns *irf;
+ ci.flags = asm_callx_flags(as, ir);
+ asm_collectargs(as, ir, &ci, args);
+ asm_setupresult(as, ir, &ci);
+ func = ir->op2; irf = IR(func);
+ if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }
+ if (irref_isk(func)) { /* Call to constant address. */
+ ci.func = (ASMFunction)(void *)(irf->i);
+ } else { /* Need specific register for indirect calls. */
+ Reg r = ra_alloc1(as, func, RID2RSET(RID_CFUNCADDR));
+ MCode *p = as->mcp;
+ if (r == RID_CFUNCADDR)
+ *--p = MIPSI_NOP;
+ else
+ *--p = MIPSI_MOVE | MIPSF_D(RID_CFUNCADDR) | MIPSF_S(r);
+ *--p = MIPSI_JALR | MIPSF_S(r);
+ as->mcp = p;
+ ci.func = (ASMFunction)(void *)0;
+ }
+ asm_gencall(as, &ci, args);
+}
+
+static void asm_callid(ASMState *as, IRIns *ir, IRCallID id)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[id];
+ IRRef args[2];
+ args[0] = ir->op1;
+ args[1] = ir->op2;
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+
+static void asm_callround(ASMState *as, IRIns *ir, IRCallID id)
+{
+ /* The modified regs must match with the *.dasc implementation. */
+ RegSet drop = RID2RSET(RID_R1)|RID2RSET(RID_R12)|RID2RSET(RID_FPRET)|
+ RID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(REGARG_FIRSTFPR);
+ if (ra_hasreg(ir->r)) rset_clear(drop, ir->r);
+ ra_evictset(as, drop);
+ ra_destreg(as, ir, RID_FPRET);
+ emit_call(as, (void *)lj_ir_callinfo[id].func);
+ ra_leftov(as, REGARG_FIRSTFPR, ir->op1);
+}
+
+/* -- Returns ------------------------------------------------------------- */
+
+/* Return to lower frame. Guard that it goes to the right spot. */
+static void asm_retf(ASMState *as, IRIns *ir)
+{
+ Reg base = ra_alloc1(as, REF_BASE, RSET_GPR);
+ void *pc = ir_kptr(IR(ir->op2));
+ int32_t delta = 1+bc_a(*((const BCIns *)pc - 1));
+ as->topslot -= (BCReg)delta;
+ if ((int32_t)as->topslot < 0) as->topslot = 0;
+ irt_setmark(IR(REF_BASE)->t); /* Children must not coalesce with BASE reg. */
+ emit_setgl(as, base, jit_base);
+ emit_addptr(as, base, -8*delta);
+ asm_guard(as, MIPSI_BNE, RID_TMP,
+ ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base)));
+ emit_tsi(as, MIPSI_LW, RID_TMP, base, -8);
+}
+
+/* -- Type conversions ---------------------------------------------------- */
+
+static void asm_tointg(ASMState *as, IRIns *ir, Reg left)
+{
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ asm_guard(as, MIPSI_BC1F, 0, 0);
+ emit_fgh(as, MIPSI_C_EQ_D, 0, tmp, left);
+ emit_fg(as, MIPSI_CVT_D_W, tmp, tmp);
+ emit_tg(as, MIPSI_MFC1, dest, tmp);
+ emit_fg(as, MIPSI_CVT_W_D, tmp, left);
+}
+
+static void asm_tobit(ASMState *as, IRIns *ir)
+{
+ RegSet allow = RSET_FPR;
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, ir->op1, allow);
+ Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left));
+ Reg tmp = ra_scratch(as, rset_clear(allow, right));
+ emit_tg(as, MIPSI_MFC1, dest, tmp);
+ emit_fgh(as, MIPSI_ADD_D, tmp, left, right);
+}
+
+static void asm_conv(ASMState *as, IRIns *ir)
+{
+ IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);
+ int stfp = (st == IRT_NUM || st == IRT_FLOAT);
+ IRRef lref = ir->op1;
+ lua_assert(irt_type(ir->t) != st);
+ lua_assert(!(irt_isint64(ir->t) ||
+ (st == IRT_I64 || st == IRT_U64))); /* Handled by SPLIT. */
+ if (irt_isfp(ir->t)) {
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ if (stfp) { /* FP to FP conversion. */
+ emit_fg(as, st == IRT_NUM ? MIPSI_CVT_S_D : MIPSI_CVT_D_S,
+ dest, ra_alloc1(as, lref, RSET_FPR));
+ } else if (st == IRT_U32) { /* U32 to FP conversion. */
+ /* y = (x ^ 0x8000000) + 2147483648.0 */
+ Reg left = ra_alloc1(as, lref, RSET_GPR);
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, dest));
+ if (irt_isfloat(ir->t))
+ emit_fg(as, MIPSI_CVT_S_D, dest, dest);
+ /* Must perform arithmetic with doubles to keep the precision. */
+ emit_fgh(as, MIPSI_ADD_D, dest, dest, tmp);
+ emit_fg(as, MIPSI_CVT_D_W, dest, dest);
+ emit_lsptr(as, MIPSI_LDC1, (tmp & 31),
+ (void *)lj_ir_k64_find(as->J, U64x(41e00000,00000000)),
+ RSET_GPR);
+ emit_tg(as, MIPSI_MTC1, RID_TMP, dest);
+ emit_dst(as, MIPSI_XOR, RID_TMP, RID_TMP, left);
+ emit_ti(as, MIPSI_LUI, RID_TMP, 0x8000);
+ } else { /* Integer to FP conversion. */
+ Reg left = ra_alloc1(as, lref, RSET_GPR);
+ emit_fg(as, irt_isfloat(ir->t) ? MIPSI_CVT_S_W : MIPSI_CVT_D_W,
+ dest, dest);
+ emit_tg(as, MIPSI_MTC1, left, dest);
+ }
+ } else if (stfp) { /* FP to integer conversion. */
+ if (irt_isguard(ir->t)) {
+ /* Checked conversions are only supported from number to int. */
+ lua_assert(irt_isint(ir->t) && st == IRT_NUM);
+ asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR));
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, lref, RSET_FPR);
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));
+ if (irt_isu32(ir->t)) {
+ /* y = (int)floor(x - 2147483648.0) ^ 0x80000000 */
+ emit_dst(as, MIPSI_XOR, dest, dest, RID_TMP);
+ emit_ti(as, MIPSI_LUI, RID_TMP, 0x8000);
+ emit_tg(as, MIPSI_MFC1, dest, tmp);
+ emit_fg(as, st == IRT_FLOAT ? MIPSI_FLOOR_W_S : MIPSI_FLOOR_W_D,
+ tmp, tmp);
+ emit_fgh(as, st == IRT_FLOAT ? MIPSI_SUB_S : MIPSI_SUB_D,
+ tmp, left, tmp);
+ if (st == IRT_FLOAT)
+ emit_lsptr(as, MIPSI_LWC1, (tmp & 31),
+ (void *)lj_ir_k64_find(as->J, U64x(4f000000,4f000000)),
+ RSET_GPR);
+ else
+ emit_lsptr(as, MIPSI_LDC1, (tmp & 31),
+ (void *)lj_ir_k64_find(as->J, U64x(41e00000,00000000)),
+ RSET_GPR);
+ } else {
+ emit_tg(as, MIPSI_MFC1, dest, tmp);
+ emit_fg(as, st == IRT_FLOAT ? MIPSI_TRUNC_W_S : MIPSI_TRUNC_W_D,
+ tmp, left);
+ }
+ }
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */
+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
+ lua_assert(irt_isint(ir->t) || irt_isu32(ir->t));
+ if ((ir->op2 & IRCONV_SEXT)) {
+ if ((as->flags & JIT_F_MIPS32R2)) {
+ emit_dst(as, st == IRT_I8 ? MIPSI_SEB : MIPSI_SEH, dest, 0, left);
+ } else {
+ uint32_t shift = st == IRT_I8 ? 24 : 16;
+ emit_dta(as, MIPSI_SRA, dest, dest, shift);
+ emit_dta(as, MIPSI_SLL, dest, left, shift);
+ }
+ } else {
+ emit_tsi(as, MIPSI_ANDI, dest, left,
+ (int32_t)(st == IRT_U8 ? 0xff : 0xffff));
+ }
+ } else { /* 32/64 bit integer conversions. */
+ /* Only need to handle 32/32 bit no-op (cast) on 32 bit archs. */
+ ra_leftov(as, dest, lref); /* Do nothing, but may need to move regs. */
+ }
+ }
+}
+
+#if LJ_HASFFI
+static void asm_conv64(ASMState *as, IRIns *ir)
+{
+ IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK);
+ IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH);
+ IRCallID id;
+ const CCallInfo *ci;
+ IRRef args[2];
+ args[LJ_BE?0:1] = ir->op1;
+ args[LJ_BE?1:0] = (ir-1)->op1;
+ if (st == IRT_NUM || st == IRT_FLOAT) {
+ id = IRCALL_fp64_d2l + ((st == IRT_FLOAT) ? 2 : 0) + (dt - IRT_I64);
+ ir--;
+ } else {
+ id = IRCALL_fp64_l2d + ((dt == IRT_FLOAT) ? 2 : 0) + (st - IRT_I64);
+ }
+ ci = &lj_ir_callinfo[id];
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+#endif
+
+static void asm_strto(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num];
+ IRRef args[2];
+ RegSet drop = RSET_SCRATCH;
+ if (ra_hasreg(ir->r)) rset_set(drop, ir->r); /* Spill dest reg (if any). */
+ ra_evictset(as, drop);
+ asm_guard(as, MIPSI_BEQ, RID_RET, RID_ZERO); /* Test return status. */
+ args[0] = ir->op1; /* GCstr *str */
+ args[1] = ASMREF_TMP1; /* TValue *n */
+ asm_gencall(as, ci, args);
+ /* Store the result to the spill slot or temp slots. */
+ emit_tsi(as, MIPSI_ADDIU, ra_releasetmp(as, ASMREF_TMP1),
+ RID_SP, sps_scale(ir->s));
+}
+
+/* Get pointer to TValue. */
+static void asm_tvptr(ASMState *as, Reg dest, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ if (irt_isnum(ir->t)) {
+ if (irref_isk(ref)) /* Use the number constant itself as a TValue. */
+ ra_allockreg(as, i32ptr(ir_knum(ir)), dest);
+ else /* Otherwise force a spill and use the spill slot. */
+ emit_tsi(as, MIPSI_ADDIU, dest, RID_SP, ra_spill(as, ir));
+ } else {
+ /* Otherwise use g->tmptv to hold the TValue. */
+ RegSet allow = rset_exclude(RSET_GPR, dest);
+ Reg type;
+ emit_tsi(as, MIPSI_ADDIU, dest, RID_JGL, offsetof(global_State, tmptv)-32768);
+ if (!irt_ispri(ir->t)) {
+ Reg src = ra_alloc1(as, ref, allow);
+ emit_setgl(as, src, tmptv.gcr);
+ }
+ type = ra_allock(as, irt_toitype(ir->t), allow);
+ emit_setgl(as, type, tmptv.it);
+ }
+}
+
+static void asm_tostr(ASMState *as, IRIns *ir)
+{
+ IRRef args[2];
+ args[0] = ASMREF_L;
+ as->gcsteps++;
+ if (irt_isnum(IR(ir->op1)->t) || (ir+1)->o == IR_HIOP) {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromnum];
+ args[1] = ASMREF_TMP1; /* const lua_Number * */
+ asm_setupresult(as, ir, ci); /* GCstr * */
+ asm_gencall(as, ci, args);
+ asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op1);
+ } else {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromint];
+ args[1] = ir->op1; /* int32_t k */
+ asm_setupresult(as, ir, ci); /* GCstr * */
+ asm_gencall(as, ci, args);
+ }
+}
+
+/* -- Memory references --------------------------------------------------- */
+
+static void asm_aref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg idx, base;
+ if (irref_isk(ir->op2)) {
+ IRRef tab = IR(ir->op1)->op1;
+ int32_t ofs = asm_fuseabase(as, tab);
+ IRRef refa = ofs ? tab : ir->op1;
+ ofs += 8*IR(ir->op2)->i;
+ if (checki16(ofs)) {
+ base = ra_alloc1(as, refa, RSET_GPR);
+ emit_tsi(as, MIPSI_ADDIU, dest, base, ofs);
+ return;
+ }
+ }
+ base = ra_alloc1(as, ir->op1, RSET_GPR);
+ idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base));
+ emit_dst(as, MIPSI_ADDU, dest, RID_TMP, base);
+ emit_dta(as, MIPSI_SLL, RID_TMP, idx, 3);
+}
+
+/* Inlined hash lookup. Specialized for key type and for const keys.
+** The equivalent C code is:
+** Node *n = hashkey(t, key);
+** do {
+** if (lj_obj_equal(&n->key, key)) return &n->val;
+** } while ((n = nextnode(n)));
+** return niltv(L);
+*/
+static void asm_href(ASMState *as, IRIns *ir)
+{
+ RegSet allow = RSET_GPR;
+ int destused = ra_used(ir);
+ Reg dest = ra_dest(as, ir, allow);
+ Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest));
+ Reg key = RID_NONE, type = RID_NONE, tmpnum = RID_NONE, tmp1 = RID_TMP, tmp2;
+ IRRef refkey = ir->op2;
+ IRIns *irkey = IR(refkey);
+ IRType1 kt = irkey->t;
+ uint32_t khash;
+ MCLabel l_end, l_loop, l_next;
+
+ rset_clear(allow, tab);
+ if (irt_isnum(kt)) {
+ key = ra_alloc1(as, refkey, RSET_FPR);
+ tmpnum = ra_scratch(as, rset_exclude(RSET_FPR, key));
+ } else if (!irt_ispri(kt)) {
+ key = ra_alloc1(as, refkey, allow);
+ rset_clear(allow, key);
+ type = ra_allock(as, irt_toitype(irkey->t), allow);
+ rset_clear(allow, type);
+ }
+ tmp2 = ra_scratch(as, allow);
+ rset_clear(allow, tmp2);
+
+ /* Key not found in chain: load niltv. */
+ l_end = emit_label(as);
+ if (destused)
+ emit_loada(as, dest, niltvg(J2G(as->J)));
+ else
+ *--as->mcp = MIPSI_NOP;
+ /* Follow hash chain until the end. */
+ emit_move(as, dest, tmp1);
+ l_loop = --as->mcp;
+ emit_tsi(as, MIPSI_LW, tmp1, dest, (int32_t)offsetof(Node, next));
+ l_next = emit_label(as);
+
+ /* Type and value comparison. */
+ if (irt_isnum(kt)) {
+ emit_branch(as, MIPSI_BC1T, 0, 0, l_end);
+ emit_fgh(as, MIPSI_C_EQ_D, 0, tmpnum, key);
+ emit_tg(as, MIPSI_MFC1, tmp1, key+1);
+ emit_branch(as, MIPSI_BEQ, tmp1, RID_ZERO, l_next);
+ emit_tsi(as, MIPSI_SLTIU, tmp1, tmp1, (int32_t)LJ_TISNUM);
+ emit_hsi(as, MIPSI_LDC1, tmpnum, dest, (int32_t)offsetof(Node, key.n));
+ } else {
+ if (irt_ispri(kt)) {
+ emit_branch(as, MIPSI_BEQ, tmp1, type, l_end);
+ } else {
+ emit_branch(as, MIPSI_BEQ, tmp2, key, l_end);
+ emit_tsi(as, MIPSI_LW, tmp2, dest, (int32_t)offsetof(Node, key.gcr));
+ emit_branch(as, MIPSI_BNE, tmp1, type, l_next);
+ }
+ }
+ emit_tsi(as, MIPSI_LW, tmp1, dest, (int32_t)offsetof(Node, key.it));
+ *l_loop = MIPSI_BNE | MIPSF_S(tmp1) | ((as->mcp-l_loop-1) & 0xffffu);
+
+ /* Load main position relative to tab->node into dest. */
+ khash = irref_isk(refkey) ? ir_khash(irkey) : 1;
+ if (khash == 0) {
+ emit_tsi(as, MIPSI_LW, dest, tab, (int32_t)offsetof(GCtab, node));
+ } else {
+ Reg tmphash = tmp1;
+ if (irref_isk(refkey))
+ tmphash = ra_allock(as, khash, allow);
+ emit_dst(as, MIPSI_ADDU, dest, dest, tmp1);
+ lua_assert(sizeof(Node) == 24);
+ emit_dst(as, MIPSI_SUBU, tmp1, tmp2, tmp1);
+ emit_dta(as, MIPSI_SLL, tmp1, tmp1, 3);
+ emit_dta(as, MIPSI_SLL, tmp2, tmp1, 5);
+ emit_dst(as, MIPSI_AND, tmp1, tmp2, tmphash);
+ emit_tsi(as, MIPSI_LW, dest, tab, (int32_t)offsetof(GCtab, node));
+ emit_tsi(as, MIPSI_LW, tmp2, tab, (int32_t)offsetof(GCtab, hmask));
+ if (irref_isk(refkey)) {
+ /* Nothing to do. */
+ } else if (irt_isstr(kt)) {
+ emit_tsi(as, MIPSI_LW, tmp1, key, (int32_t)offsetof(GCstr, hash));
+ } else { /* Must match with hash*() in lj_tab.c. */
+ emit_dst(as, MIPSI_SUBU, tmp1, tmp1, tmp2);
+ emit_rotr(as, tmp2, tmp2, dest, (-HASH_ROT3)&31);
+ emit_dst(as, MIPSI_XOR, tmp1, tmp1, tmp2);
+ emit_rotr(as, tmp1, tmp1, dest, (-HASH_ROT2-HASH_ROT1)&31);
+ emit_dst(as, MIPSI_SUBU, tmp2, tmp2, dest);
+ if (irt_isnum(kt)) {
+ emit_dst(as, MIPSI_XOR, tmp2, tmp2, tmp1);
+ if ((as->flags & JIT_F_MIPS32R2)) {
+ emit_dta(as, MIPSI_ROTR, dest, tmp1, (-HASH_ROT1)&31);
+ } else {
+ emit_dst(as, MIPSI_OR, dest, dest, tmp1);
+ emit_dta(as, MIPSI_SLL, tmp1, tmp1, HASH_ROT1);
+ emit_dta(as, MIPSI_SRL, dest, tmp1, (-HASH_ROT1)&31);
+ }
+ emit_dst(as, MIPSI_ADDU, tmp1, tmp1, tmp1);
+ emit_tg(as, MIPSI_MFC1, tmp2, key);
+ emit_tg(as, MIPSI_MFC1, tmp1, key+1);
+ } else {
+ emit_dst(as, MIPSI_XOR, tmp2, key, tmp1);
+ emit_rotr(as, dest, tmp1, tmp2, (-HASH_ROT1)&31);
+ emit_dst(as, MIPSI_ADDU, tmp1, key, ra_allock(as, HASH_BIAS, allow));
+ }
+ }
+ }
+}
+
+static void asm_hrefk(ASMState *as, IRIns *ir)
+{
+ IRIns *kslot = IR(ir->op2);
+ IRIns *irkey = IR(kslot->op1);
+ int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node));
+ int32_t kofs = ofs + (int32_t)offsetof(Node, key);
+ Reg dest = (ra_used(ir)||ofs > 32736) ? ra_dest(as, ir, RSET_GPR) : RID_NONE;
+ Reg node = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg key = RID_NONE, type = RID_TMP, idx = node;
+ RegSet allow = rset_exclude(RSET_GPR, node);
+ int32_t lo, hi;
+ lua_assert(ofs % sizeof(Node) == 0);
+ if (ofs > 32736) {
+ idx = dest;
+ rset_clear(allow, dest);
+ kofs = (int32_t)offsetof(Node, key);
+ } else if (ra_hasreg(dest)) {
+ emit_tsi(as, MIPSI_ADDIU, dest, node, ofs);
+ }
+ if (!irt_ispri(irkey->t)) {
+ key = ra_scratch(as, allow);
+ rset_clear(allow, key);
+ }
+ if (irt_isnum(irkey->t)) {
+ lo = (int32_t)ir_knum(irkey)->u32.lo;
+ hi = (int32_t)ir_knum(irkey)->u32.hi;
+ } else {
+ lo = irkey->i;
+ hi = irt_toitype(irkey->t);
+ if (!ra_hasreg(key))
+ goto nolo;
+ }
+ asm_guard(as, MIPSI_BNE, key, lo ? ra_allock(as, lo, allow) : RID_ZERO);
+nolo:
+ asm_guard(as, MIPSI_BNE, type, hi ? ra_allock(as, hi, allow) : RID_ZERO);
+ if (ra_hasreg(key)) emit_tsi(as, MIPSI_LW, key, idx, kofs+(LJ_BE?4:0));
+ emit_tsi(as, MIPSI_LW, type, idx, kofs+(LJ_BE?0:4));
+ if (ofs > 32736)
+ emit_tsi(as, MIPSI_ADDU, dest, node, ra_allock(as, ofs, allow));
+}
+
+static void asm_newref(ASMState *as, IRIns *ir)
+{
+ if (ir->r != RID_SINK) {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_newkey];
+ IRRef args[3];
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ir->op1; /* GCtab *t */
+ args[2] = ASMREF_TMP1; /* cTValue *key */
+ asm_setupresult(as, ir, ci); /* TValue * */
+ asm_gencall(as, ci, args);
+ asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op2);
+ }
+}
+
+static void asm_uref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (irref_isk(ir->op1)) {
+ GCfunc *fn = ir_kfunc(IR(ir->op1));
+ MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v;
+ emit_lsptr(as, MIPSI_LW, dest, v, RSET_GPR);
+ } else {
+ Reg uv = ra_scratch(as, RSET_GPR);
+ Reg func = ra_alloc1(as, ir->op1, RSET_GPR);
+ if (ir->o == IR_UREFC) {
+ asm_guard(as, MIPSI_BEQ, RID_TMP, RID_ZERO);
+ emit_tsi(as, MIPSI_ADDIU, dest, uv, (int32_t)offsetof(GCupval, tv));
+ emit_tsi(as, MIPSI_LBU, RID_TMP, uv, (int32_t)offsetof(GCupval, closed));
+ } else {
+ emit_tsi(as, MIPSI_LW, dest, uv, (int32_t)offsetof(GCupval, v));
+ }
+ emit_tsi(as, MIPSI_LW, uv, func,
+ (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8));
+ }
+}
+
+static void asm_fref(ASMState *as, IRIns *ir)
+{
+ UNUSED(as); UNUSED(ir);
+ lua_assert(!ra_used(ir));
+}
+
+static void asm_strref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ IRRef ref = ir->op2, refk = ir->op1;
+ int32_t ofs = (int32_t)sizeof(GCstr);
+ Reg r;
+ if (irref_isk(ref)) {
+ IRRef tmp = refk; refk = ref; ref = tmp;
+ } else if (!irref_isk(refk)) {
+ Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);
+ IRIns *irr = IR(ir->op2);
+ if (ra_hasreg(irr->r)) {
+ ra_noweak(as, irr->r);
+ right = irr->r;
+ } else if (mayfuse(as, irr->op2) &&
+ irr->o == IR_ADD && irref_isk(irr->op2) &&
+ checki16(ofs + IR(irr->op2)->i)) {
+ ofs += IR(irr->op2)->i;
+ right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left));
+ } else {
+ right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left));
+ }
+ emit_tsi(as, MIPSI_ADDIU, dest, dest, ofs);
+ emit_dst(as, MIPSI_ADDU, dest, left, right);
+ return;
+ }
+ r = ra_alloc1(as, ref, RSET_GPR);
+ ofs += IR(refk)->i;
+ if (checki16(ofs))
+ emit_tsi(as, MIPSI_ADDIU, dest, r, ofs);
+ else
+ emit_dst(as, MIPSI_ADDU, dest, r,
+ ra_allock(as, ofs, rset_exclude(RSET_GPR, r)));
+}
+
+/* -- Loads and stores ---------------------------------------------------- */
+
+static MIPSIns asm_fxloadins(IRIns *ir)
+{
+ switch (irt_type(ir->t)) {
+ case IRT_I8: return MIPSI_LB;
+ case IRT_U8: return MIPSI_LBU;
+ case IRT_I16: return MIPSI_LH;
+ case IRT_U16: return MIPSI_LHU;
+ case IRT_NUM: return MIPSI_LDC1;
+ case IRT_FLOAT: return MIPSI_LWC1;
+ default: return MIPSI_LW;
+ }
+}
+
+static MIPSIns asm_fxstoreins(IRIns *ir)
+{
+ switch (irt_type(ir->t)) {
+ case IRT_I8: case IRT_U8: return MIPSI_SB;
+ case IRT_I16: case IRT_U16: return MIPSI_SH;
+ case IRT_NUM: return MIPSI_SDC1;
+ case IRT_FLOAT: return MIPSI_SWC1;
+ default: return MIPSI_SW;
+ }
+}
+
+static void asm_fload(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg idx = ra_alloc1(as, ir->op1, RSET_GPR);
+ MIPSIns mi = asm_fxloadins(ir);
+ int32_t ofs;
+ if (ir->op2 == IRFL_TAB_ARRAY) {
+ ofs = asm_fuseabase(as, ir->op1);
+ if (ofs) { /* Turn the t->array load into an add for colocated arrays. */
+ emit_tsi(as, MIPSI_ADDIU, dest, idx, ofs);
+ return;
+ }
+ }
+ ofs = field_ofs[ir->op2];
+ lua_assert(!irt_isfp(ir->t));
+ emit_tsi(as, mi, dest, idx, ofs);
+}
+
+static void asm_fstore(ASMState *as, IRIns *ir)
+{
+ if (ir->r != RID_SINK) {
+ Reg src = ra_alloc1z(as, ir->op2, RSET_GPR);
+ IRIns *irf = IR(ir->op1);
+ Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src));
+ int32_t ofs = field_ofs[irf->op2];
+ MIPSIns mi = asm_fxstoreins(ir);
+ lua_assert(!irt_isfp(ir->t));
+ emit_tsi(as, mi, src, idx, ofs);
+ }
+}
+
+static void asm_xload(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);
+ lua_assert(!(ir->op2 & IRXLOAD_UNALIGNED));
+ asm_fusexref(as, asm_fxloadins(ir), dest, ir->op1, RSET_GPR, 0);
+}
+
+static void asm_xstore(ASMState *as, IRIns *ir, int32_t ofs)
+{
+ if (ir->r != RID_SINK) {
+ Reg src = ra_alloc1z(as, ir->op2, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);
+ asm_fusexref(as, asm_fxstoreins(ir), src, ir->op1,
+ rset_exclude(RSET_GPR, src), ofs);
+ }
+}
+
+static void asm_ahuvload(ASMState *as, IRIns *ir)
+{
+ IRType1 t = ir->t;
+ Reg dest = RID_NONE, type = RID_TMP, idx;
+ RegSet allow = RSET_GPR;
+ int32_t ofs = 0;
+ if (ra_used(ir)) {
+ lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t));
+ dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : RSET_GPR);
+ rset_clear(allow, dest);
+ }
+ idx = asm_fuseahuref(as, ir->op1, &ofs, allow);
+ rset_clear(allow, idx);
+ if (irt_isnum(t)) {
+ asm_guard(as, MIPSI_BEQ, type, RID_ZERO);
+ emit_tsi(as, MIPSI_SLTIU, type, type, (int32_t)LJ_TISNUM);
+ if (ra_hasreg(dest))
+ emit_hsi(as, MIPSI_LDC1, dest, idx, ofs);
+ } else {
+ asm_guard(as, MIPSI_BNE, type, ra_allock(as, irt_toitype(t), allow));
+ if (ra_hasreg(dest)) emit_tsi(as, MIPSI_LW, dest, idx, ofs+(LJ_BE?4:0));
+ }
+ emit_tsi(as, MIPSI_LW, type, idx, ofs+(LJ_BE?0:4));
+}
+
+static void asm_ahustore(ASMState *as, IRIns *ir)
+{
+ RegSet allow = RSET_GPR;
+ Reg idx, src = RID_NONE, type = RID_NONE;
+ int32_t ofs = 0;
+ if (ir->r == RID_SINK)
+ return;
+ if (irt_isnum(ir->t)) {
+ src = ra_alloc1(as, ir->op2, RSET_FPR);
+ } else {
+ if (!irt_ispri(ir->t)) {
+ src = ra_alloc1(as, ir->op2, allow);
+ rset_clear(allow, src);
+ }
+ type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);
+ rset_clear(allow, type);
+ }
+ idx = asm_fuseahuref(as, ir->op1, &ofs, allow);
+ if (irt_isnum(ir->t)) {
+ emit_hsi(as, MIPSI_SDC1, src, idx, ofs);
+ } else {
+ if (ra_hasreg(src))
+ emit_tsi(as, MIPSI_SW, src, idx, ofs+(LJ_BE?4:0));
+ emit_tsi(as, MIPSI_SW, type, idx, ofs+(LJ_BE?0:4));
+ }
+}
+
+static void asm_sload(ASMState *as, IRIns *ir)
+{
+ int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 4 : 0);
+ IRType1 t = ir->t;
+ Reg dest = RID_NONE, type = RID_NONE, base;
+ RegSet allow = RSET_GPR;
+ lua_assert(!(ir->op2 & IRSLOAD_PARENT)); /* Handled by asm_head_side(). */
+ lua_assert(irt_isguard(t) || !(ir->op2 & IRSLOAD_TYPECHECK));
+ lua_assert(!irt_isint(t) || (ir->op2 & (IRSLOAD_CONVERT|IRSLOAD_FRAME)));
+ if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(t) && irt_isint(t)) {
+ dest = ra_scratch(as, RSET_FPR);
+ asm_tointg(as, ir, dest);
+ t.irt = IRT_NUM; /* Continue with a regular number type check. */
+ } else if (ra_used(ir)) {
+ lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t));
+ dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : RSET_GPR);
+ rset_clear(allow, dest);
+ base = ra_alloc1(as, REF_BASE, allow);
+ rset_clear(allow, base);
+ if ((ir->op2 & IRSLOAD_CONVERT)) {
+ if (irt_isint(t)) {
+ Reg tmp = ra_scratch(as, RSET_FPR);
+ emit_tg(as, MIPSI_MFC1, dest, tmp);
+ emit_fg(as, MIPSI_CVT_W_D, tmp, tmp);
+ dest = tmp;
+ t.irt = IRT_NUM; /* Check for original type. */
+ } else {
+ Reg tmp = ra_scratch(as, RSET_GPR);
+ emit_fg(as, MIPSI_CVT_D_W, dest, dest);
+ emit_tg(as, MIPSI_MTC1, tmp, dest);
+ dest = tmp;
+ t.irt = IRT_INT; /* Check for original type. */
+ }
+ }
+ goto dotypecheck;
+ }
+ base = ra_alloc1(as, REF_BASE, allow);
+ rset_clear(allow, base);
+dotypecheck:
+ if (irt_isnum(t)) {
+ if ((ir->op2 & IRSLOAD_TYPECHECK)) {
+ asm_guard(as, MIPSI_BEQ, RID_TMP, RID_ZERO);
+ emit_tsi(as, MIPSI_SLTIU, RID_TMP, RID_TMP, (int32_t)LJ_TISNUM);
+ type = RID_TMP;
+ }
+ if (ra_hasreg(dest)) emit_hsi(as, MIPSI_LDC1, dest, base, ofs);
+ } else {
+ if ((ir->op2 & IRSLOAD_TYPECHECK)) {
+ Reg ktype = ra_allock(as, irt_toitype(t), allow);
+ asm_guard(as, MIPSI_BNE, RID_TMP, ktype);
+ type = RID_TMP;
+ }
+ if (ra_hasreg(dest)) emit_tsi(as, MIPSI_LW, dest, base, ofs ^ (LJ_BE?4:0));
+ }
+ if (ra_hasreg(type)) emit_tsi(as, MIPSI_LW, type, base, ofs ^ (LJ_BE?0:4));
+}
+
+/* -- Allocations --------------------------------------------------------- */
+
+#if LJ_HASFFI
+static void asm_cnew(ASMState *as, IRIns *ir)
+{
+ CTState *cts = ctype_ctsG(J2G(as->J));
+ CTypeID ctypeid = (CTypeID)IR(ir->op1)->i;
+ CTSize sz = (ir->o == IR_CNEWI || ir->op2 == REF_NIL) ?
+ lj_ctype_size(cts, ctypeid) : (CTSize)IR(ir->op2)->i;
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];
+ IRRef args[2];
+ RegSet allow = (RSET_GPR & ~RSET_SCRATCH);
+ RegSet drop = RSET_SCRATCH;
+ lua_assert(sz != CTSIZE_INVALID);
+
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ASMREF_TMP1; /* MSize size */
+ as->gcsteps++;
+
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ ra_evictset(as, drop);
+ if (ra_used(ir))
+ ra_destreg(as, ir, RID_RET); /* GCcdata * */
+
+ /* Initialize immutable cdata object. */
+ if (ir->o == IR_CNEWI) {
+ int32_t ofs = sizeof(GCcdata);
+ lua_assert(sz == 4 || sz == 8);
+ if (sz == 8) {
+ ofs += 4;
+ lua_assert((ir+1)->o == IR_HIOP);
+ if (LJ_LE) ir++;
+ }
+ for (;;) {
+ Reg r = ra_alloc1z(as, ir->op2, allow);
+ emit_tsi(as, MIPSI_SW, r, RID_RET, ofs);
+ rset_clear(allow, r);
+ if (ofs == sizeof(GCcdata)) break;
+ ofs -= 4; if (LJ_BE) ir++; else ir--;
+ }
+ }
+ /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */
+ emit_tsi(as, MIPSI_SB, RID_RET+1, RID_RET, offsetof(GCcdata, gct));
+ emit_tsi(as, MIPSI_SH, RID_TMP, RID_RET, offsetof(GCcdata, ctypeid));
+ emit_ti(as, MIPSI_LI, RID_RET+1, ~LJ_TCDATA);
+ emit_ti(as, MIPSI_LI, RID_TMP, ctypeid); /* Lower 16 bit used. Sign-ext ok. */
+ asm_gencall(as, ci, args);
+ ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)),
+ ra_releasetmp(as, ASMREF_TMP1));
+}
+#else
+#define asm_cnew(as, ir) ((void)0)
+#endif
+
+/* -- Write barriers ------------------------------------------------------ */
+
+static void asm_tbar(ASMState *as, IRIns *ir)
+{
+ Reg tab = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg mark = ra_scratch(as, rset_exclude(RSET_GPR, tab));
+ Reg link = RID_TMP;
+ MCLabel l_end = emit_label(as);
+ emit_tsi(as, MIPSI_SW, link, tab, (int32_t)offsetof(GCtab, gclist));
+ emit_tsi(as, MIPSI_SB, mark, tab, (int32_t)offsetof(GCtab, marked));
+ emit_setgl(as, tab, gc.grayagain);
+ emit_getgl(as, link, gc.grayagain);
+ emit_dst(as, MIPSI_XOR, mark, mark, RID_TMP); /* Clear black bit. */
+ emit_branch(as, MIPSI_BEQ, RID_TMP, RID_ZERO, l_end);
+ emit_tsi(as, MIPSI_ANDI, RID_TMP, mark, LJ_GC_BLACK);
+ emit_tsi(as, MIPSI_LBU, mark, tab, (int32_t)offsetof(GCtab, marked));
+}
+
+static void asm_obar(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv];
+ IRRef args[2];
+ MCLabel l_end;
+ Reg obj, val, tmp;
+ /* No need for other object barriers (yet). */
+ lua_assert(IR(ir->op1)->o == IR_UREFC);
+ ra_evictset(as, RSET_SCRATCH);
+ l_end = emit_label(as);
+ args[0] = ASMREF_TMP1; /* global_State *g */
+ args[1] = ir->op1; /* TValue *tv */
+ asm_gencall(as, ci, args);
+ emit_tsi(as, MIPSI_ADDIU, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768);
+ obj = IR(ir->op1)->r;
+ tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj));
+ emit_branch(as, MIPSI_BEQ, RID_TMP, RID_ZERO, l_end);
+ emit_tsi(as, MIPSI_ANDI, tmp, tmp, LJ_GC_BLACK);
+ emit_branch(as, MIPSI_BEQ, RID_TMP, RID_ZERO, l_end);
+ emit_tsi(as, MIPSI_ANDI, RID_TMP, RID_TMP, LJ_GC_WHITES);
+ val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj));
+ emit_tsi(as, MIPSI_LBU, tmp, obj,
+ (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv));
+ emit_tsi(as, MIPSI_LBU, RID_TMP, val, (int32_t)offsetof(GChead, marked));
+}
+
+/* -- Arithmetic and logic operations ------------------------------------- */
+
+static void asm_fparith(ASMState *as, IRIns *ir, MIPSIns mi)
+{
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg right, left = ra_alloc2(as, ir, RSET_FPR);
+ right = (left >> 8); left &= 255;
+ emit_fgh(as, mi, dest, left, right);
+}
+
+static void asm_fpunary(ASMState *as, IRIns *ir, MIPSIns mi)
+{
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR);
+ emit_fg(as, mi, dest, left);
+}
+
+static int asm_fpjoin_pow(ASMState *as, IRIns *ir)
+{
+ IRIns *irp = IR(ir->op1);
+ if (irp == ir-1 && irp->o == IR_MUL && !ra_used(irp)) {
+ IRIns *irpp = IR(irp->op1);
+ if (irpp == ir-2 && irpp->o == IR_FPMATH &&
+ irpp->op2 == IRFPM_LOG2 && !ra_used(irpp)) {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_pow];
+ IRRef args[2];
+ args[0] = irpp->op1;
+ args[1] = irp->op2;
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static void asm_add(ASMState *as, IRIns *ir)
+{
+ if (irt_isnum(ir->t)) {
+ asm_fparith(as, ir, MIPSI_ADD_D);
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (checki16(k)) {
+ emit_tsi(as, MIPSI_ADDIU, dest, left, k);
+ return;
+ }
+ }
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_dst(as, MIPSI_ADDU, dest, left, right);
+ }
+}
+
+static void asm_sub(ASMState *as, IRIns *ir)
+{
+ if (irt_isnum(ir->t)) {
+ asm_fparith(as, ir, MIPSI_SUB_D);
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ emit_dst(as, MIPSI_SUBU, dest, left, right);
+ }
+}
+
+static void asm_mul(ASMState *as, IRIns *ir)
+{
+ if (irt_isnum(ir->t)) {
+ asm_fparith(as, ir, MIPSI_MUL_D);
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ emit_dst(as, MIPSI_MUL, dest, left, right);
+ }
+}
+
+static void asm_neg(ASMState *as, IRIns *ir)
+{
+ if (irt_isnum(ir->t)) {
+ asm_fpunary(as, ir, MIPSI_NEG_D);
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ emit_dst(as, MIPSI_SUBU, dest, RID_ZERO, left);
+ }
+}
+
+static void asm_arithov(ASMState *as, IRIns *ir)
+{
+ Reg right, left, tmp, dest = ra_dest(as, ir, RSET_GPR);
+ if (irref_isk(ir->op2)) {
+ int k = IR(ir->op2)->i;
+ if (ir->o == IR_SUBOV) k = -k;
+ if (checki16(k)) { /* (dest < left) == (k >= 0 ? 1 : 0) */
+ left = ra_alloc1(as, ir->op1, RSET_GPR);
+ asm_guard(as, k >= 0 ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO);
+ emit_dst(as, MIPSI_SLT, RID_TMP, dest, dest == left ? RID_TMP : left);
+ emit_tsi(as, MIPSI_ADDIU, dest, left, k);
+ if (dest == left) emit_move(as, RID_TMP, left);
+ return;
+ }
+ }
+ left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ tmp = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_GPR, left),
+ right), dest));
+ asm_guard(as, MIPSI_BLTZ, RID_TMP, 0);
+ emit_dst(as, MIPSI_AND, RID_TMP, RID_TMP, tmp);
+ if (ir->o == IR_ADDOV) { /* ((dest^left) & (dest^right)) < 0 */
+ emit_dst(as, MIPSI_XOR, RID_TMP, dest, dest == right ? RID_TMP : right);
+ } else { /* ((dest^left) & (dest^~right)) < 0 */
+ emit_dst(as, MIPSI_XOR, RID_TMP, RID_TMP, dest);
+ emit_dst(as, MIPSI_NOR, RID_TMP, dest == right ? RID_TMP : right, RID_ZERO);
+ }
+ emit_dst(as, MIPSI_XOR, tmp, dest, dest == left ? RID_TMP : left);
+ emit_dst(as, ir->o == IR_ADDOV ? MIPSI_ADDU : MIPSI_SUBU, dest, left, right);
+ if (dest == left || dest == right)
+ emit_move(as, RID_TMP, dest == left ? left : right);
+}
+
+static void asm_mulov(ASMState *as, IRIns *ir)
+{
+#if LJ_DUALNUM
+#error "NYI: MULOV"
+#else
+ UNUSED(as); UNUSED(ir); lua_assert(0); /* Unused in single-number mode. */
+#endif
+}
+
+#if LJ_HASFFI
+static void asm_add64(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (k == 0) {
+ emit_dst(as, MIPSI_ADDU, dest, left, RID_TMP);
+ goto loarith;
+ } else if (checki16(k)) {
+ emit_dst(as, MIPSI_ADDU, dest, dest, RID_TMP);
+ emit_tsi(as, MIPSI_ADDIU, dest, left, k);
+ goto loarith;
+ }
+ }
+ emit_dst(as, MIPSI_ADDU, dest, dest, RID_TMP);
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_dst(as, MIPSI_ADDU, dest, left, right);
+loarith:
+ ir--;
+ dest = ra_dest(as, ir, RSET_GPR);
+ left = ra_alloc1(as, ir->op1, RSET_GPR);
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (k == 0) {
+ if (dest != left)
+ emit_move(as, dest, left);
+ return;
+ } else if (checki16(k)) {
+ if (dest == left) {
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, left));
+ emit_move(as, dest, tmp);
+ dest = tmp;
+ }
+ emit_dst(as, MIPSI_SLTU, RID_TMP, dest, left);
+ emit_tsi(as, MIPSI_ADDIU, dest, left, k);
+ return;
+ }
+ }
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ if (dest == left && dest == right) {
+ Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), right));
+ emit_move(as, dest, tmp);
+ dest = tmp;
+ }
+ emit_dst(as, MIPSI_SLTU, RID_TMP, dest, dest == left ? right : left);
+ emit_dst(as, MIPSI_ADDU, dest, left, right);
+}
+
+static void asm_sub64(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ emit_dst(as, MIPSI_SUBU, dest, dest, RID_TMP);
+ emit_dst(as, MIPSI_SUBU, dest, left, right);
+ ir--;
+ dest = ra_dest(as, ir, RSET_GPR);
+ left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ if (dest == left) {
+ Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), right));
+ emit_move(as, dest, tmp);
+ dest = tmp;
+ }
+ emit_dst(as, MIPSI_SLTU, RID_TMP, left, dest);
+ emit_dst(as, MIPSI_SUBU, dest, left, right);
+}
+
+static void asm_neg64(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
+ emit_dst(as, MIPSI_SUBU, dest, dest, RID_TMP);
+ emit_dst(as, MIPSI_SUBU, dest, RID_ZERO, left);
+ ir--;
+ dest = ra_dest(as, ir, RSET_GPR);
+ left = ra_alloc1(as, ir->op1, RSET_GPR);
+ emit_dst(as, MIPSI_SLTU, RID_TMP, RID_ZERO, dest);
+ emit_dst(as, MIPSI_SUBU, dest, RID_ZERO, left);
+}
+#endif
+
+static void asm_bitnot(ASMState *as, IRIns *ir)
+{
+ Reg left, right, dest = ra_dest(as, ir, RSET_GPR);
+ IRIns *irl = IR(ir->op1);
+ if (mayfuse(as, ir->op1) && irl->o == IR_BOR) {
+ left = ra_alloc2(as, irl, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ } else {
+ left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ right = RID_ZERO;
+ }
+ emit_dst(as, MIPSI_NOR, dest, left, right);
+}
+
+static void asm_bitswap(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
+ if ((as->flags & JIT_F_MIPS32R2)) {
+ emit_dta(as, MIPSI_ROTR, dest, RID_TMP, 16);
+ emit_dst(as, MIPSI_WSBH, RID_TMP, 0, left);
+ } else {
+ Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), dest));
+ emit_dst(as, MIPSI_OR, dest, dest, tmp);
+ emit_dst(as, MIPSI_OR, dest, dest, RID_TMP);
+ emit_tsi(as, MIPSI_ANDI, dest, dest, 0xff00);
+ emit_dta(as, MIPSI_SLL, RID_TMP, RID_TMP, 8);
+ emit_dta(as, MIPSI_SRL, dest, left, 8);
+ emit_tsi(as, MIPSI_ANDI, RID_TMP, left, 0xff00);
+ emit_dst(as, MIPSI_OR, tmp, tmp, RID_TMP);
+ emit_dta(as, MIPSI_SRL, tmp, left, 24);
+ emit_dta(as, MIPSI_SLL, RID_TMP, left, 24);
+ }
+}
+
+static void asm_bitop(ASMState *as, IRIns *ir, MIPSIns mi, MIPSIns mik)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (checku16(k)) {
+ emit_tsi(as, mik, dest, left, k);
+ return;
+ }
+ }
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_dst(as, mi, dest, left, right);
+}
+
+static void asm_bitshift(ASMState *as, IRIns *ir, MIPSIns mi, MIPSIns mik)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (irref_isk(ir->op2)) { /* Constant shifts. */
+ uint32_t shift = (uint32_t)(IR(ir->op2)->i & 31);
+ emit_dta(as, mik, dest, ra_hintalloc(as, ir->op1, dest, RSET_GPR), shift);
+ } else {
+ Reg right, left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ emit_dst(as, mi, dest, right, left); /* Shift amount is in rs. */
+ }
+}
+
+static void asm_bitror(ASMState *as, IRIns *ir)
+{
+ if ((as->flags & JIT_F_MIPS32R2)) {
+ asm_bitshift(as, ir, MIPSI_ROTRV, MIPSI_ROTR);
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (irref_isk(ir->op2)) { /* Constant shifts. */
+ uint32_t shift = (uint32_t)(IR(ir->op2)->i & 31);
+ Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ emit_rotr(as, dest, left, RID_TMP, shift);
+ } else {
+ Reg right, left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ emit_dst(as, MIPSI_OR, dest, dest, RID_TMP);
+ emit_dst(as, MIPSI_SRLV, dest, right, left);
+ emit_dst(as, MIPSI_SLLV, RID_TMP, RID_TMP, left);
+ emit_dst(as, MIPSI_SUBU, RID_TMP, ra_allock(as, 32, RSET_GPR), right);
+ }
+ }
+}
+
+static void asm_min_max(ASMState *as, IRIns *ir, int ismax)
+{
+ if (irt_isnum(ir->t)) {
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg right, left = ra_alloc2(as, ir, RSET_FPR);
+ right = (left >> 8); left &= 255;
+ if (dest == left) {
+ emit_fg(as, MIPSI_MOVT_D, dest, right);
+ } else {
+ emit_fg(as, MIPSI_MOVF_D, dest, left);
+ if (dest != right) emit_fg(as, MIPSI_MOV_D, dest, right);
+ }
+ emit_fgh(as, MIPSI_C_OLT_D, 0, ismax ? left : right, ismax ? right : left);
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ if (dest == left) {
+ emit_dst(as, MIPSI_MOVN, dest, right, RID_TMP);
+ } else {
+ emit_dst(as, MIPSI_MOVZ, dest, left, RID_TMP);
+ if (dest != right) emit_move(as, dest, right);
+ }
+ emit_dst(as, MIPSI_SLT, RID_TMP,
+ ismax ? left : right, ismax ? right : left);
+ }
+}
+
+/* -- Comparisons --------------------------------------------------------- */
+
+static void asm_comp(ASMState *as, IRIns *ir)
+{
+ /* ORDER IR: LT GE LE GT ULT UGE ULE UGT. */
+ IROp op = ir->o;
+ if (irt_isnum(ir->t)) {
+ Reg right, left = ra_alloc2(as, ir, RSET_FPR);
+ right = (left >> 8); left &= 255;
+ asm_guard(as, (op&1) ? MIPSI_BC1T : MIPSI_BC1F, 0, 0);
+ emit_fgh(as, MIPSI_C_OLT_D + ((op&3) ^ ((op>>2)&1)), 0, left, right);
+ } else {
+ Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);
+ if (op == IR_ABC) op = IR_UGT;
+ if ((op&4) == 0 && irref_isk(ir->op2) && IR(ir->op2)->i == 0) {
+ MIPSIns mi = (op&2) ? ((op&1) ? MIPSI_BLEZ : MIPSI_BGTZ) :
+ ((op&1) ? MIPSI_BLTZ : MIPSI_BGEZ);
+ asm_guard(as, mi, left, 0);
+ } else {
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if ((op&2)) k++;
+ if (checki16(k)) {
+ asm_guard(as, (op&1) ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO);
+ emit_tsi(as, (op&4) ? MIPSI_SLTIU : MIPSI_SLTI,
+ RID_TMP, left, k);
+ return;
+ }
+ }
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ asm_guard(as, ((op^(op>>1))&1) ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO);
+ emit_dst(as, (op&4) ? MIPSI_SLTU : MIPSI_SLT,
+ RID_TMP, (op&2) ? right : left, (op&2) ? left : right);
+ }
+ }
+}
+
+static void asm_compeq(ASMState *as, IRIns *ir)
+{
+ Reg right, left = ra_alloc2(as, ir, irt_isnum(ir->t) ? RSET_FPR : RSET_GPR);
+ right = (left >> 8); left &= 255;
+ if (irt_isnum(ir->t)) {
+ asm_guard(as, (ir->o & 1) ? MIPSI_BC1T : MIPSI_BC1F, 0, 0);
+ emit_fgh(as, MIPSI_C_EQ_D, 0, left, right);
+ } else {
+ asm_guard(as, (ir->o & 1) ? MIPSI_BEQ : MIPSI_BNE, left, right);
+ }
+}
+
+#if LJ_HASFFI
+/* 64 bit integer comparisons. */
+static void asm_comp64(ASMState *as, IRIns *ir)
+{
+ /* ORDER IR: LT GE LE GT ULT UGE ULE UGT. */
+ IROp op = (ir-1)->o;
+ MCLabel l_end;
+ Reg rightlo, leftlo, righthi, lefthi = ra_alloc2(as, ir, RSET_GPR);
+ righthi = (lefthi >> 8); lefthi &= 255;
+ leftlo = ra_alloc2(as, ir-1,
+ rset_exclude(rset_exclude(RSET_GPR, lefthi), righthi));
+ rightlo = (leftlo >> 8); leftlo &= 255;
+ asm_guard(as, ((op^(op>>1))&1) ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO);
+ l_end = emit_label(as);
+ if (lefthi != righthi)
+ emit_dst(as, (op&4) ? MIPSI_SLTU : MIPSI_SLT, RID_TMP,
+ (op&2) ? righthi : lefthi, (op&2) ? lefthi : righthi);
+ emit_dst(as, MIPSI_SLTU, RID_TMP,
+ (op&2) ? rightlo : leftlo, (op&2) ? leftlo : rightlo);
+ if (lefthi != righthi)
+ emit_branch(as, MIPSI_BEQ, lefthi, righthi, l_end);
+}
+
+static void asm_comp64eq(ASMState *as, IRIns *ir)
+{
+ Reg tmp, right, left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ asm_guard(as, ((ir-1)->o & 1) ? MIPSI_BEQ : MIPSI_BNE, RID_TMP, RID_ZERO);
+ tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), right));
+ emit_dst(as, MIPSI_OR, RID_TMP, RID_TMP, tmp);
+ emit_dst(as, MIPSI_XOR, tmp, left, right);
+ left = ra_alloc2(as, ir-1, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ emit_dst(as, MIPSI_XOR, RID_TMP, left, right);
+}
+#endif
+
+/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */
+
+/* Hiword op of a split 64 bit op. Previous op must be the loword op. */
+static void asm_hiop(ASMState *as, IRIns *ir)
+{
+#if LJ_HASFFI
+ /* HIOP is marked as a store because it needs its own DCE logic. */
+ int uselo = ra_used(ir-1), usehi = ra_used(ir); /* Loword/hiword used? */
+ if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1;
+ if ((ir-1)->o == IR_CONV) { /* Conversions to/from 64 bit. */
+ as->curins--; /* Always skip the CONV. */
+ if (usehi || uselo)
+ asm_conv64(as, ir);
+ return;
+ } else if ((ir-1)->o < IR_EQ) { /* 64 bit integer comparisons. ORDER IR. */
+ as->curins--; /* Always skip the loword comparison. */
+ asm_comp64(as, ir);
+ return;
+ } else if ((ir-1)->o <= IR_NE) { /* 64 bit integer comparisons. ORDER IR. */
+ as->curins--; /* Always skip the loword comparison. */
+ asm_comp64eq(as, ir);
+ return;
+ } else if ((ir-1)->o == IR_XSTORE) {
+ as->curins--; /* Handle both stores here. */
+ if ((ir-1)->r != RID_SINK) {
+ asm_xstore(as, ir, LJ_LE ? 4 : 0);
+ asm_xstore(as, ir-1, LJ_LE ? 0 : 4);
+ }
+ return;
+ }
+ if (!usehi) return; /* Skip unused hiword op for all remaining ops. */
+ switch ((ir-1)->o) {
+ case IR_ADD: as->curins--; asm_add64(as, ir); break;
+ case IR_SUB: as->curins--; asm_sub64(as, ir); break;
+ case IR_NEG: as->curins--; asm_neg64(as, ir); break;
+ case IR_CALLN:
+ case IR_CALLXS:
+ if (!uselo)
+ ra_allocref(as, ir->op1, RID2RSET(RID_RETLO)); /* Mark lo op as used. */
+ break;
+ case IR_CNEWI:
+ /* Nothing to do here. Handled by lo op itself. */
+ break;
+ default: lua_assert(0); break;
+ }
+#else
+ UNUSED(as); UNUSED(ir); lua_assert(0); /* Unused without FFI. */
+#endif
+}
+
+/* -- Stack handling ------------------------------------------------------ */
+
+/* Check Lua stack size for overflow. Use exit handler as fallback. */
+static void asm_stack_check(ASMState *as, BCReg topslot,
+ IRIns *irp, RegSet allow, ExitNo exitno)
+{
+ /* Try to get an unused temp. register, otherwise spill/restore RID_RET*. */
+ Reg tmp, pbase = irp ? (ra_hasreg(irp->r) ? irp->r : RID_TMP) : RID_BASE;
+ ExitNo oldsnap = as->snapno;
+ rset_clear(allow, pbase);
+ tmp = allow ? rset_pickbot(allow) :
+ (pbase == RID_RETHI ? RID_RETLO : RID_RETHI);
+ as->snapno = exitno;
+ asm_guard(as, MIPSI_BNE, RID_TMP, RID_ZERO);
+ as->snapno = oldsnap;
+ if (allow == RSET_EMPTY) /* Restore temp. register. */
+ emit_tsi(as, MIPSI_LW, tmp, RID_SP, 0);
+ else
+ ra_modified(as, tmp);
+ emit_tsi(as, MIPSI_SLTIU, RID_TMP, RID_TMP, (int32_t)(8*topslot));
+ emit_dst(as, MIPSI_SUBU, RID_TMP, tmp, pbase);
+ emit_tsi(as, MIPSI_LW, tmp, tmp, offsetof(lua_State, maxstack));
+ if (pbase == RID_TMP)
+ emit_getgl(as, RID_TMP, jit_base);
+ emit_getgl(as, tmp, jit_L);
+ if (allow == RSET_EMPTY) /* Spill temp. register. */
+ emit_tsi(as, MIPSI_SW, tmp, RID_SP, 0);
+}
+
+/* Restore Lua stack from on-trace state. */
+static void asm_stack_restore(ASMState *as, SnapShot *snap)
+{
+ SnapEntry *map = &as->T->snapmap[snap->mapofs];
+ SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1];
+ MSize n, nent = snap->nent;
+ /* Store the value of all modified slots to the Lua stack. */
+ for (n = 0; n < nent; n++) {
+ SnapEntry sn = map[n];
+ BCReg s = snap_slot(sn);
+ int32_t ofs = 8*((int32_t)s-1);
+ IRRef ref = snap_ref(sn);
+ IRIns *ir = IR(ref);
+ if ((sn & SNAP_NORESTORE))
+ continue;
+ if (irt_isnum(ir->t)) {
+ Reg src = ra_alloc1(as, ref, RSET_FPR);
+ emit_hsi(as, MIPSI_SDC1, src, RID_BASE, ofs);
+ } else {
+ Reg type;
+ RegSet allow = rset_exclude(RSET_GPR, RID_BASE);
+ lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t));
+ if (!irt_ispri(ir->t)) {
+ Reg src = ra_alloc1(as, ref, allow);
+ rset_clear(allow, src);
+ emit_tsi(as, MIPSI_SW, src, RID_BASE, ofs+(LJ_BE?4:0));
+ }
+ if ((sn & (SNAP_CONT|SNAP_FRAME))) {
+ if (s == 0) continue; /* Do not overwrite link to previous frame. */
+ type = ra_allock(as, (int32_t)(*flinks--), allow);
+ } else {
+ type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);
+ }
+ emit_tsi(as, MIPSI_SW, type, RID_BASE, ofs+(LJ_BE?0:4));
+ }
+ checkmclim(as);
+ }
+ lua_assert(map + nent == flinks);
+}
+
+/* -- GC handling --------------------------------------------------------- */
+
+/* Check GC threshold and do one or more GC steps. */
+static void asm_gc_check(ASMState *as)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit];
+ IRRef args[2];
+ MCLabel l_end;
+ Reg tmp;
+ ra_evictset(as, RSET_SCRATCH);
+ l_end = emit_label(as);
+ /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */
+ /* Assumes asm_snap_prep() already done. */
+ asm_guard(as, MIPSI_BNE, RID_RET, RID_ZERO);
+ args[0] = ASMREF_TMP1; /* global_State *g */
+ args[1] = ASMREF_TMP2; /* MSize steps */
+ asm_gencall(as, ci, args);
+ emit_tsi(as, MIPSI_ADDIU, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768);
+ tmp = ra_releasetmp(as, ASMREF_TMP2);
+ emit_loadi(as, tmp, as->gcsteps);
+ /* Jump around GC step if GC total < GC threshold. */
+ emit_branch(as, MIPSI_BNE, RID_TMP, RID_ZERO, l_end);
+ emit_dst(as, MIPSI_SLTU, RID_TMP, RID_TMP, tmp);
+ emit_getgl(as, tmp, gc.threshold);
+ emit_getgl(as, RID_TMP, gc.total);
+ as->gcsteps = 0;
+ checkmclim(as);
+}
+
+/* -- Loop handling ------------------------------------------------------- */
+
+/* Fixup the loop branch. */
+static void asm_loop_fixup(ASMState *as)
+{
+ MCode *p = as->mctop;
+ MCode *target = as->mcp;
+ p[-1] = MIPSI_NOP;
+ if (as->loopinv) { /* Inverted loop branch? */
+ /* asm_guard already inverted the cond branch. Only patch the target. */
+ p[-3] |= ((target-p+2) & 0x0000ffffu);
+ } else {
+ p[-2] = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu);
+ }
+}
+
+/* -- Head of trace ------------------------------------------------------- */
+
+/* Coalesce BASE register for a root trace. */
+static void asm_head_root_base(ASMState *as)
+{
+ IRIns *ir = IR(REF_BASE);
+ Reg r = ir->r;
+ if (as->loopinv) as->mctop--;
+ if (ra_hasreg(r)) {
+ ra_free(as, r);
+ if (rset_test(as->modset, r) || irt_ismarked(ir->t))
+ ir->r = RID_INIT; /* No inheritance for modified BASE register. */
+ if (r != RID_BASE)
+ emit_move(as, r, RID_BASE);
+ }
+}
+
+/* Coalesce BASE register for a side trace. */
+static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow)
+{
+ IRIns *ir = IR(REF_BASE);
+ Reg r = ir->r;
+ if (as->loopinv) as->mctop--;
+ if (ra_hasreg(r)) {
+ ra_free(as, r);
+ if (rset_test(as->modset, r) || irt_ismarked(ir->t))
+ ir->r = RID_INIT; /* No inheritance for modified BASE register. */
+ if (irp->r == r) {
+ rset_clear(allow, r); /* Mark same BASE register as coalesced. */
+ } else if (ra_hasreg(irp->r) && rset_test(as->freeset, irp->r)) {
+ rset_clear(allow, irp->r);
+ emit_move(as, r, irp->r); /* Move from coalesced parent reg. */
+ } else {
+ emit_getgl(as, r, jit_base); /* Otherwise reload BASE. */
+ }
+ }
+ return allow;
+}
+
+/* -- Tail of trace ------------------------------------------------------- */
+
+/* Fixup the tail code. */
+static void asm_tail_fixup(ASMState *as, TraceNo lnk)
+{
+ MCode *target = lnk ? traceref(as->J,lnk)->mcode : (MCode *)lj_vm_exit_interp;
+ int32_t spadj = as->T->spadjust;
+ MCode *p = as->mctop-1;
+ *p = spadj ? (MIPSI_ADDIU|MIPSF_T(RID_SP)|MIPSF_S(RID_SP)|spadj) : MIPSI_NOP;
+ p[-1] = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu);
+}
+
+/* Prepare tail of code. */
+static void asm_tail_prep(ASMState *as)
+{
+ as->mcp = as->mctop-2; /* Leave room for branch plus nop or stack adj. */
+ as->invmcp = as->loopref ? as->mcp : NULL;
+}
+
+/* -- Instruction dispatch ------------------------------------------------ */
+
+/* Assemble a single instruction. */
+static void asm_ir(ASMState *as, IRIns *ir)
+{
+ switch ((IROp)ir->o) {
+ /* Miscellaneous ops. */
+ case IR_LOOP: asm_loop(as); break;
+ case IR_NOP: case IR_XBAR: lua_assert(!ra_used(ir)); break;
+ case IR_USE:
+ ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break;
+ case IR_PHI: asm_phi(as, ir); break;
+ case IR_HIOP: asm_hiop(as, ir); break;
+ case IR_GCSTEP: asm_gcstep(as, ir); break;
+
+ /* Guarded assertions. */
+ case IR_EQ: case IR_NE: asm_compeq(as, ir); break;
+ case IR_LT: case IR_GE: case IR_LE: case IR_GT:
+ case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT:
+ case IR_ABC:
+ asm_comp(as, ir);
+ break;
+
+ case IR_RETF: asm_retf(as, ir); break;
+
+ /* Bit ops. */
+ case IR_BNOT: asm_bitnot(as, ir); break;
+ case IR_BSWAP: asm_bitswap(as, ir); break;
+
+ case IR_BAND: asm_bitop(as, ir, MIPSI_AND, MIPSI_ANDI); break;
+ case IR_BOR: asm_bitop(as, ir, MIPSI_OR, MIPSI_ORI); break;
+ case IR_BXOR: asm_bitop(as, ir, MIPSI_XOR, MIPSI_XORI); break;
+
+ case IR_BSHL: asm_bitshift(as, ir, MIPSI_SLLV, MIPSI_SLL); break;
+ case IR_BSHR: asm_bitshift(as, ir, MIPSI_SRLV, MIPSI_SRL); break;
+ case IR_BSAR: asm_bitshift(as, ir, MIPSI_SRAV, MIPSI_SRA); break;
+ case IR_BROL: lua_assert(0); break;
+ case IR_BROR: asm_bitror(as, ir); break;
+
+ /* Arithmetic ops. */
+ case IR_ADD: asm_add(as, ir); break;
+ case IR_SUB: asm_sub(as, ir); break;
+ case IR_MUL: asm_mul(as, ir); break;
+ case IR_DIV: asm_fparith(as, ir, MIPSI_DIV_D); break;
+ case IR_MOD: asm_callid(as, ir, IRCALL_lj_vm_modi); break;
+ case IR_POW: asm_callid(as, ir, IRCALL_lj_vm_powi); break;
+ case IR_NEG: asm_neg(as, ir); break;
+
+ case IR_ABS: asm_fpunary(as, ir, MIPSI_ABS_D); break;
+ case IR_ATAN2: asm_callid(as, ir, IRCALL_atan2); break;
+ case IR_LDEXP: asm_callid(as, ir, IRCALL_ldexp); break;
+ case IR_MIN: asm_min_max(as, ir, 0); break;
+ case IR_MAX: asm_min_max(as, ir, 1); break;
+ case IR_FPMATH:
+ if (ir->op2 == IRFPM_EXP2 && asm_fpjoin_pow(as, ir))
+ break;
+ if (ir->op2 <= IRFPM_TRUNC)
+ asm_callround(as, ir, IRCALL_lj_vm_floor + ir->op2);
+ else if (ir->op2 == IRFPM_SQRT)
+ asm_fpunary(as, ir, MIPSI_SQRT_D);
+ else
+ asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2);
+ break;
+
+ /* Overflow-checking arithmetic ops. */
+ case IR_ADDOV: asm_arithov(as, ir); break;
+ case IR_SUBOV: asm_arithov(as, ir); break;
+ case IR_MULOV: asm_mulov(as, ir); break;
+
+ /* Memory references. */
+ case IR_AREF: asm_aref(as, ir); break;
+ case IR_HREF: asm_href(as, ir); break;
+ case IR_HREFK: asm_hrefk(as, ir); break;
+ case IR_NEWREF: asm_newref(as, ir); break;
+ case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break;
+ case IR_FREF: asm_fref(as, ir); break;
+ case IR_STRREF: asm_strref(as, ir); break;
+
+ /* Loads and stores. */
+ case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:
+ asm_ahuvload(as, ir);
+ break;
+ case IR_FLOAD: asm_fload(as, ir); break;
+ case IR_XLOAD: asm_xload(as, ir); break;
+ case IR_SLOAD: asm_sload(as, ir); break;
+
+ case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break;
+ case IR_FSTORE: asm_fstore(as, ir); break;
+ case IR_XSTORE: asm_xstore(as, ir, 0); break;
+
+ /* Allocations. */
+ case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break;
+ case IR_TNEW: asm_tnew(as, ir); break;
+ case IR_TDUP: asm_tdup(as, ir); break;
+ case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break;
+
+ /* Write barriers. */
+ case IR_TBAR: asm_tbar(as, ir); break;
+ case IR_OBAR: asm_obar(as, ir); break;
+
+ /* Type conversions. */
+ case IR_CONV: asm_conv(as, ir); break;
+ case IR_TOBIT: asm_tobit(as, ir); break;
+ case IR_TOSTR: asm_tostr(as, ir); break;
+ case IR_STRTO: asm_strto(as, ir); break;
+
+ /* Calls. */
+ case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break;
+ case IR_CALLXS: asm_callx(as, ir); break;
+ case IR_CARG: break;
+
+ default:
+ setintV(&as->J->errinfo, ir->o);
+ lj_trace_err_info(as->J, LJ_TRERR_NYIIR);
+ break;
+ }
+}
+
+/* -- Trace setup --------------------------------------------------------- */
+
+/* Ensure there are enough stack slots for call arguments. */
+static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)
+{
+ IRRef args[CCI_NARGS_MAX*2];
+ uint32_t i, nargs = (int)CCI_NARGS(ci);
+ int nslots = 4, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR;
+ asm_collectargs(as, ir, ci, args);
+ for (i = 0; i < nargs; i++) {
+ if (args[i] && irt_isfp(IR(args[i])->t) &&
+ nfpr > 0 && !(ci->flags & CCI_VARARG)) {
+ nfpr--;
+ ngpr -= irt_isnum(IR(args[i])->t) ? 2 : 1;
+ } else if (args[i] && irt_isnum(IR(args[i])->t)) {
+ nfpr = 0;
+ ngpr = ngpr & ~1;
+ if (ngpr > 0) ngpr -= 2; else nslots = (nslots+3) & ~1;
+ } else {
+ nfpr = 0;
+ if (ngpr > 0) ngpr--; else nslots++;
+ }
+ }
+ if (nslots > as->evenspill) /* Leave room for args in stack slots. */
+ as->evenspill = nslots;
+ return irt_isfp(ir->t) ? REGSP_HINT(RID_FPRET) : REGSP_HINT(RID_RET);
+}
+
+static void asm_setup_target(ASMState *as)
+{
+ asm_sparejump_setup(as);
+ asm_exitstub_setup(as);
+}
+
+/* -- Trace patching ------------------------------------------------------ */
+
+/* Patch exit jumps of existing machine code to a new target. */
+void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target)
+{
+ MCode *p = T->mcode;
+ MCode *pe = (MCode *)((char *)p + T->szmcode);
+ MCode *px = exitstub_trace_addr(T, exitno);
+ MCode *cstart = NULL, *cstop = NULL;
+ MCode *mcarea = lj_mcode_patch(J, p, 0);
+ MCode exitload = MIPSI_LI | MIPSF_T(RID_TMP) | exitno;
+ MCode tjump = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu);
+ for (p++; p < pe; p++) {
+ if (*p == exitload) { /* Look for load of exit number. */
+ /* Look for exitstub branch. Yes, this covers all used branch variants. */
+ if (((p[-1] ^ (px-p)) & 0xffffu) == 0 &&
+ ((p[-1] & 0xf0000000u) == MIPSI_BEQ ||
+ (p[-1] & 0xfc1e0000u) == MIPSI_BLTZ ||
+ (p[-1] & 0xffe00000u) == MIPSI_BC1F)) {
+ ptrdiff_t delta = target - p;
+ if (((delta + 0x8000) >> 16) == 0) { /* Patch in-range branch. */
+ patchbranch:
+ p[-1] = (p[-1] & 0xffff0000u) | (delta & 0xffffu);
+ *p = MIPSI_NOP; /* Replace the load of the exit number. */
+ cstop = p;
+ if (!cstart) cstart = p-1;
+ } else { /* Branch out of range. Use spare jump slot in mcarea. */
+ int i;
+ for (i = (int)(sizeof(MCLink)/sizeof(MCode));
+ i < (int)(sizeof(MCLink)/sizeof(MCode)+MIPS_SPAREJUMP*2);
+ i += 2) {
+ if (mcarea[i] == tjump) {
+ delta = mcarea+i - p;
+ goto patchbranch;
+ } else if (mcarea[i] == MIPSI_NOP) {
+ mcarea[i] = tjump;
+ cstart = mcarea+i;
+ delta = mcarea+i - p;
+ goto patchbranch;
+ }
+ }
+ /* Ignore jump slot overflow. Child trace is simply not attached. */
+ }
+ } else if (p+1 == pe) {
+ /* Patch NOP after code for inverted loop branch. Use of J is ok. */
+ lua_assert(p[1] == MIPSI_NOP);
+ p[1] = tjump;
+ *p = MIPSI_NOP; /* Replace the load of the exit number. */
+ cstop = p+2;
+ if (!cstart) cstart = p+1;
+ }
+ }
+ }
+ if (cstart) lj_mcode_sync(cstart, cstop);
+ lj_mcode_patch(J, mcarea, 1);
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm_ppc.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm_ppc.h
new file mode 100644
index 0000000..d8a14c8
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm_ppc.h
@@ -0,0 +1,2168 @@
+/*
+** PPC IR assembler (SSA IR -> machine code).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* -- Register allocator extensions --------------------------------------- */
+
+/* Allocate a register with a hint. */
+static Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow)
+{
+ Reg r = IR(ref)->r;
+ if (ra_noreg(r)) {
+ if (!ra_hashint(r) && !iscrossref(as, ref))
+ ra_sethint(IR(ref)->r, hint); /* Propagate register hint. */
+ r = ra_allocref(as, ref, allow);
+ }
+ ra_noweak(as, r);
+ return r;
+}
+
+/* Allocate two source registers for three-operand instructions. */
+static Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow)
+{
+ IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);
+ Reg left = irl->r, right = irr->r;
+ if (ra_hasreg(left)) {
+ ra_noweak(as, left);
+ if (ra_noreg(right))
+ right = ra_allocref(as, ir->op2, rset_exclude(allow, left));
+ else
+ ra_noweak(as, right);
+ } else if (ra_hasreg(right)) {
+ ra_noweak(as, right);
+ left = ra_allocref(as, ir->op1, rset_exclude(allow, right));
+ } else if (ra_hashint(right)) {
+ right = ra_allocref(as, ir->op2, allow);
+ left = ra_alloc1(as, ir->op1, rset_exclude(allow, right));
+ } else {
+ left = ra_allocref(as, ir->op1, allow);
+ right = ra_alloc1(as, ir->op2, rset_exclude(allow, left));
+ }
+ return left | (right << 8);
+}
+
+/* -- Guard handling ------------------------------------------------------ */
+
+/* Setup exit stubs after the end of each trace. */
+static void asm_exitstub_setup(ASMState *as, ExitNo nexits)
+{
+ ExitNo i;
+ MCode *mxp = as->mctop;
+ if (mxp - (nexits + 3 + MCLIM_REDZONE) < as->mclim)
+ asm_mclimit(as);
+ /* 1: mflr r0; bl ->vm_exit_handler; li r0, traceno; bl <1; bl <1; ... */
+ for (i = nexits-1; (int32_t)i >= 0; i--)
+ *--mxp = PPCI_BL|(((-3-i)&0x00ffffffu)<<2);
+ *--mxp = PPCI_LI|PPCF_T(RID_TMP)|as->T->traceno; /* Read by exit handler. */
+ mxp--;
+ *mxp = PPCI_BL|((((MCode *)(void *)lj_vm_exit_handler-mxp)&0x00ffffffu)<<2);
+ *--mxp = PPCI_MFLR|PPCF_T(RID_TMP);
+ as->mctop = mxp;
+}
+
+static MCode *asm_exitstub_addr(ASMState *as, ExitNo exitno)
+{
+ /* Keep this in-sync with exitstub_trace_addr(). */
+ return as->mctop + exitno + 3;
+}
+
+/* Emit conditional branch to exit for guard. */
+static void asm_guardcc(ASMState *as, PPCCC cc)
+{
+ MCode *target = asm_exitstub_addr(as, as->snapno);
+ MCode *p = as->mcp;
+ if (LJ_UNLIKELY(p == as->invmcp)) {
+ as->loopinv = 1;
+ *p = PPCI_B | (((target-p) & 0x00ffffffu) << 2);
+ emit_condbranch(as, PPCI_BC, cc^4, p);
+ return;
+ }
+ emit_condbranch(as, PPCI_BC, cc, target);
+}
+
+/* -- Operand fusion ------------------------------------------------------ */
+
+/* Limit linear search to this distance. Avoids O(n^2) behavior. */
+#define CONFLICT_SEARCH_LIM 31
+
+/* Check if there's no conflicting instruction between curins and ref. */
+static int noconflict(ASMState *as, IRRef ref, IROp conflict)
+{
+ IRIns *ir = as->ir;
+ IRRef i = as->curins;
+ if (i > ref + CONFLICT_SEARCH_LIM)
+ return 0; /* Give up, ref is too far away. */
+ while (--i > ref)
+ if (ir[i].o == conflict)
+ return 0; /* Conflict found. */
+ return 1; /* Ok, no conflict. */
+}
+
+/* Fuse the array base of colocated arrays. */
+static int32_t asm_fuseabase(ASMState *as, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE &&
+ !neverfuse(as) && noconflict(as, ref, IR_NEWREF))
+ return (int32_t)sizeof(GCtab);
+ return 0;
+}
+
+/* Indicates load/store indexed is ok. */
+#define AHUREF_LSX ((int32_t)0x80000000)
+
+/* Fuse array/hash/upvalue reference into register+offset operand. */
+static Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow)
+{
+ IRIns *ir = IR(ref);
+ if (ra_noreg(ir->r)) {
+ if (ir->o == IR_AREF) {
+ if (mayfuse(as, ref)) {
+ if (irref_isk(ir->op2)) {
+ IRRef tab = IR(ir->op1)->op1;
+ int32_t ofs = asm_fuseabase(as, tab);
+ IRRef refa = ofs ? tab : ir->op1;
+ ofs += 8*IR(ir->op2)->i;
+ if (checki16(ofs)) {
+ *ofsp = ofs;
+ return ra_alloc1(as, refa, allow);
+ }
+ }
+ if (*ofsp == AHUREF_LSX) {
+ Reg base = ra_alloc1(as, ir->op1, allow);
+ Reg idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base));
+ return base | (idx << 8);
+ }
+ }
+ } else if (ir->o == IR_HREFK) {
+ if (mayfuse(as, ref)) {
+ int32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node));
+ if (checki16(ofs)) {
+ *ofsp = ofs;
+ return ra_alloc1(as, ir->op1, allow);
+ }
+ }
+ } else if (ir->o == IR_UREFC) {
+ if (irref_isk(ir->op1)) {
+ GCfunc *fn = ir_kfunc(IR(ir->op1));
+ int32_t ofs = i32ptr(&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv);
+ int32_t jgl = (intptr_t)J2G(as->J);
+ if ((uint32_t)(ofs-jgl) < 65536) {
+ *ofsp = ofs-jgl-32768;
+ return RID_JGL;
+ } else {
+ *ofsp = (int16_t)ofs;
+ return ra_allock(as, ofs-(int16_t)ofs, allow);
+ }
+ }
+ }
+ }
+ *ofsp = 0;
+ return ra_alloc1(as, ref, allow);
+}
+
+/* Fuse XLOAD/XSTORE reference into load/store operand. */
+static void asm_fusexref(ASMState *as, PPCIns pi, Reg rt, IRRef ref,
+ RegSet allow, int32_t ofs)
+{
+ IRIns *ir = IR(ref);
+ Reg base;
+ if (ra_noreg(ir->r) && canfuse(as, ir)) {
+ if (ir->o == IR_ADD) {
+ int32_t ofs2;
+ if (irref_isk(ir->op2) && (ofs2 = ofs + IR(ir->op2)->i, checki16(ofs2))) {
+ ofs = ofs2;
+ ref = ir->op1;
+ } else if (ofs == 0) {
+ Reg right, left = ra_alloc2(as, ir, allow);
+ right = (left >> 8); left &= 255;
+ emit_fab(as, PPCI_LWZX | ((pi >> 20) & 0x780), rt, left, right);
+ return;
+ }
+ } else if (ir->o == IR_STRREF) {
+ lua_assert(ofs == 0);
+ ofs = (int32_t)sizeof(GCstr);
+ if (irref_isk(ir->op2)) {
+ ofs += IR(ir->op2)->i;
+ ref = ir->op1;
+ } else if (irref_isk(ir->op1)) {
+ ofs += IR(ir->op1)->i;
+ ref = ir->op2;
+ } else {
+ /* NYI: Fuse ADD with constant. */
+ Reg tmp, right, left = ra_alloc2(as, ir, allow);
+ right = (left >> 8); left &= 255;
+ tmp = ra_scratch(as, rset_exclude(rset_exclude(allow, left), right));
+ emit_fai(as, pi, rt, tmp, ofs);
+ emit_tab(as, PPCI_ADD, tmp, left, right);
+ return;
+ }
+ if (!checki16(ofs)) {
+ Reg left = ra_alloc1(as, ref, allow);
+ Reg right = ra_allock(as, ofs, rset_exclude(allow, left));
+ emit_fab(as, PPCI_LWZX | ((pi >> 20) & 0x780), rt, left, right);
+ return;
+ }
+ }
+ }
+ base = ra_alloc1(as, ref, allow);
+ emit_fai(as, pi, rt, base, ofs);
+}
+
+/* Fuse XLOAD/XSTORE reference into indexed-only load/store operand. */
+static void asm_fusexrefx(ASMState *as, PPCIns pi, Reg rt, IRRef ref,
+ RegSet allow)
+{
+ IRIns *ira = IR(ref);
+ Reg right, left;
+ if (canfuse(as, ira) && ira->o == IR_ADD && ra_noreg(ira->r)) {
+ left = ra_alloc2(as, ira, allow);
+ right = (left >> 8); left &= 255;
+ } else {
+ right = ra_alloc1(as, ref, allow);
+ left = RID_R0;
+ }
+ emit_tab(as, pi, rt, left, right);
+}
+
+/* Fuse to multiply-add/sub instruction. */
+static int asm_fusemadd(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pir)
+{
+ IRRef lref = ir->op1, rref = ir->op2;
+ IRIns *irm;
+ if (lref != rref &&
+ ((mayfuse(as, lref) && (irm = IR(lref), irm->o == IR_MUL) &&
+ ra_noreg(irm->r)) ||
+ (mayfuse(as, rref) && (irm = IR(rref), irm->o == IR_MUL) &&
+ (rref = lref, pi = pir, ra_noreg(irm->r))))) {
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg add = ra_alloc1(as, rref, RSET_FPR);
+ Reg right, left = ra_alloc2(as, irm, rset_exclude(RSET_FPR, add));
+ right = (left >> 8); left &= 255;
+ emit_facb(as, pi, dest, left, right, add);
+ return 1;
+ }
+ return 0;
+}
+
+/* -- Calls --------------------------------------------------------------- */
+
+/* Generate a call to a C function. */
+static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)
+{
+ uint32_t n, nargs = CCI_NARGS(ci);
+ int32_t ofs = 8;
+ Reg gpr = REGARG_FIRSTGPR, fpr = REGARG_FIRSTFPR;
+ if ((void *)ci->func)
+ emit_call(as, (void *)ci->func);
+ for (n = 0; n < nargs; n++) { /* Setup args. */
+ IRRef ref = args[n];
+ if (ref) {
+ IRIns *ir = IR(ref);
+ if (irt_isfp(ir->t)) {
+ if (fpr <= REGARG_LASTFPR) {
+ lua_assert(rset_test(as->freeset, fpr)); /* Already evicted. */
+ ra_leftov(as, fpr, ref);
+ fpr++;
+ } else {
+ Reg r = ra_alloc1(as, ref, RSET_FPR);
+ if (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4;
+ emit_spstore(as, ir, r, ofs);
+ ofs += irt_isnum(ir->t) ? 8 : 4;
+ }
+ } else {
+ if (gpr <= REGARG_LASTGPR) {
+ lua_assert(rset_test(as->freeset, gpr)); /* Already evicted. */
+ ra_leftov(as, gpr, ref);
+ gpr++;
+ } else {
+ Reg r = ra_alloc1(as, ref, RSET_GPR);
+ emit_spstore(as, ir, r, ofs);
+ ofs += 4;
+ }
+ }
+ } else {
+ if (gpr <= REGARG_LASTGPR)
+ gpr++;
+ else
+ ofs += 4;
+ }
+ checkmclim(as);
+ }
+ if ((ci->flags & CCI_VARARG)) /* Vararg calls need to know about FPR use. */
+ emit_tab(as, fpr == REGARG_FIRSTFPR ? PPCI_CRXOR : PPCI_CREQV, 6, 6, 6);
+}
+
+/* Setup result reg/sp for call. Evict scratch regs. */
+static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci)
+{
+ RegSet drop = RSET_SCRATCH;
+ int hiop = ((ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t));
+ if ((ci->flags & CCI_NOFPRCLOBBER))
+ drop &= ~RSET_FPR;
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ if (hiop && ra_hasreg((ir+1)->r))
+ rset_clear(drop, (ir+1)->r); /* Dest reg handled below. */
+ ra_evictset(as, drop); /* Evictions must be performed first. */
+ if (ra_used(ir)) {
+ lua_assert(!irt_ispri(ir->t));
+ if (irt_isfp(ir->t)) {
+ if ((ci->flags & CCI_CASTU64)) {
+ /* Use spill slot or temp slots. */
+ int32_t ofs = ir->s ? sps_scale(ir->s) : SPOFS_TMP;
+ Reg dest = ir->r;
+ if (ra_hasreg(dest)) {
+ ra_free(as, dest);
+ ra_modified(as, dest);
+ emit_fai(as, PPCI_LFD, dest, RID_SP, ofs);
+ }
+ emit_tai(as, PPCI_STW, RID_RETHI, RID_SP, ofs);
+ emit_tai(as, PPCI_STW, RID_RETLO, RID_SP, ofs+4);
+ } else {
+ ra_destreg(as, ir, RID_FPRET);
+ }
+ } else if (hiop) {
+ ra_destpair(as, ir);
+ } else {
+ ra_destreg(as, ir, RID_RET);
+ }
+ }
+}
+
+static void asm_call(ASMState *as, IRIns *ir)
+{
+ IRRef args[CCI_NARGS_MAX];
+ const CCallInfo *ci = &lj_ir_callinfo[ir->op2];
+ asm_collectargs(as, ir, ci, args);
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+
+static void asm_callx(ASMState *as, IRIns *ir)
+{
+ IRRef args[CCI_NARGS_MAX*2];
+ CCallInfo ci;
+ IRRef func;
+ IRIns *irf;
+ ci.flags = asm_callx_flags(as, ir);
+ asm_collectargs(as, ir, &ci, args);
+ asm_setupresult(as, ir, &ci);
+ func = ir->op2; irf = IR(func);
+ if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }
+ if (irref_isk(func)) { /* Call to constant address. */
+ ci.func = (ASMFunction)(void *)(irf->i);
+ } else { /* Need a non-argument register for indirect calls. */
+ RegSet allow = RSET_GPR & ~RSET_RANGE(RID_R0, REGARG_LASTGPR+1);
+ Reg freg = ra_alloc1(as, func, allow);
+ *--as->mcp = PPCI_BCTRL;
+ *--as->mcp = PPCI_MTCTR | PPCF_T(freg);
+ ci.func = (ASMFunction)(void *)0;
+ }
+ asm_gencall(as, &ci, args);
+}
+
+static void asm_callid(ASMState *as, IRIns *ir, IRCallID id)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[id];
+ IRRef args[2];
+ args[0] = ir->op1;
+ args[1] = ir->op2;
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+
+/* -- Returns ------------------------------------------------------------- */
+
+/* Return to lower frame. Guard that it goes to the right spot. */
+static void asm_retf(ASMState *as, IRIns *ir)
+{
+ Reg base = ra_alloc1(as, REF_BASE, RSET_GPR);
+ void *pc = ir_kptr(IR(ir->op2));
+ int32_t delta = 1+bc_a(*((const BCIns *)pc - 1));
+ as->topslot -= (BCReg)delta;
+ if ((int32_t)as->topslot < 0) as->topslot = 0;
+ irt_setmark(IR(REF_BASE)->t); /* Children must not coalesce with BASE reg. */
+ emit_setgl(as, base, jit_base);
+ emit_addptr(as, base, -8*delta);
+ asm_guardcc(as, CC_NE);
+ emit_ab(as, PPCI_CMPW, RID_TMP,
+ ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base)));
+ emit_tai(as, PPCI_LWZ, RID_TMP, base, -8);
+}
+
+/* -- Type conversions ---------------------------------------------------- */
+
+static void asm_tointg(ASMState *as, IRIns *ir, Reg left)
+{
+ RegSet allow = RSET_FPR;
+ Reg tmp = ra_scratch(as, rset_clear(allow, left));
+ Reg fbias = ra_scratch(as, rset_clear(allow, tmp));
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg hibias = ra_allock(as, 0x43300000, rset_exclude(RSET_GPR, dest));
+ asm_guardcc(as, CC_NE);
+ emit_fab(as, PPCI_FCMPU, 0, tmp, left);
+ emit_fab(as, PPCI_FSUB, tmp, tmp, fbias);
+ emit_fai(as, PPCI_LFD, tmp, RID_SP, SPOFS_TMP);
+ emit_tai(as, PPCI_STW, RID_TMP, RID_SP, SPOFS_TMPLO);
+ emit_tai(as, PPCI_STW, hibias, RID_SP, SPOFS_TMPHI);
+ emit_asi(as, PPCI_XORIS, RID_TMP, dest, 0x8000);
+ emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO);
+ emit_lsptr(as, PPCI_LFS, (fbias & 31),
+ (void *)lj_ir_k64_find(as->J, U64x(59800004,59800000)),
+ RSET_GPR);
+ emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);
+ emit_fb(as, PPCI_FCTIWZ, tmp, left);
+}
+
+static void asm_tobit(ASMState *as, IRIns *ir)
+{
+ RegSet allow = RSET_FPR;
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, ir->op1, allow);
+ Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left));
+ Reg tmp = ra_scratch(as, rset_clear(allow, right));
+ emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO);
+ emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);
+ emit_fab(as, PPCI_FADD, tmp, left, right);
+}
+
+static void asm_conv(ASMState *as, IRIns *ir)
+{
+ IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);
+ int stfp = (st == IRT_NUM || st == IRT_FLOAT);
+ IRRef lref = ir->op1;
+ lua_assert(irt_type(ir->t) != st);
+ lua_assert(!(irt_isint64(ir->t) ||
+ (st == IRT_I64 || st == IRT_U64))); /* Handled by SPLIT. */
+ if (irt_isfp(ir->t)) {
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ if (stfp) { /* FP to FP conversion. */
+ if (st == IRT_NUM) /* double -> float conversion. */
+ emit_fb(as, PPCI_FRSP, dest, ra_alloc1(as, lref, RSET_FPR));
+ else /* float -> double conversion is a no-op on PPC. */
+ ra_leftov(as, dest, lref); /* Do nothing, but may need to move regs. */
+ } else { /* Integer to FP conversion. */
+ /* IRT_INT: Flip hibit, bias with 2^52, subtract 2^52+2^31. */
+ /* IRT_U32: Bias with 2^52, subtract 2^52. */
+ RegSet allow = RSET_GPR;
+ Reg left = ra_alloc1(as, lref, allow);
+ Reg hibias = ra_allock(as, 0x43300000, rset_clear(allow, left));
+ Reg fbias = ra_scratch(as, rset_exclude(RSET_FPR, dest));
+ const float *kbias;
+ if (irt_isfloat(ir->t)) emit_fb(as, PPCI_FRSP, dest, dest);
+ emit_fab(as, PPCI_FSUB, dest, dest, fbias);
+ emit_fai(as, PPCI_LFD, dest, RID_SP, SPOFS_TMP);
+ kbias = (const float *)lj_ir_k64_find(as->J, U64x(59800004,59800000));
+ if (st == IRT_U32) kbias++;
+ emit_lsptr(as, PPCI_LFS, (fbias & 31), (void *)kbias,
+ rset_clear(allow, hibias));
+ emit_tai(as, PPCI_STW, st == IRT_U32 ? left : RID_TMP,
+ RID_SP, SPOFS_TMPLO);
+ emit_tai(as, PPCI_STW, hibias, RID_SP, SPOFS_TMPHI);
+ if (st != IRT_U32) emit_asi(as, PPCI_XORIS, RID_TMP, left, 0x8000);
+ }
+ } else if (stfp) { /* FP to integer conversion. */
+ if (irt_isguard(ir->t)) {
+ /* Checked conversions are only supported from number to int. */
+ lua_assert(irt_isint(ir->t) && st == IRT_NUM);
+ asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR));
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, lref, RSET_FPR);
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));
+ if (irt_isu32(ir->t)) {
+ /* Convert both x and x-2^31 to int and merge results. */
+ Reg tmpi = ra_scratch(as, rset_exclude(RSET_GPR, dest));
+ emit_asb(as, PPCI_OR, dest, dest, tmpi); /* Select with mask idiom. */
+ emit_asb(as, PPCI_AND, tmpi, tmpi, RID_TMP);
+ emit_asb(as, PPCI_ANDC, dest, dest, RID_TMP);
+ emit_tai(as, PPCI_LWZ, tmpi, RID_SP, SPOFS_TMPLO); /* tmp = (int)(x) */
+ emit_tai(as, PPCI_ADDIS, dest, dest, 0x8000); /* dest += 2^31 */
+ emit_asb(as, PPCI_SRAWI, RID_TMP, dest, 31); /* mask = -(dest < 0) */
+ emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);
+ emit_tai(as, PPCI_LWZ, dest,
+ RID_SP, SPOFS_TMPLO); /* dest = (int)(x-2^31) */
+ emit_fb(as, PPCI_FCTIWZ, tmp, left);
+ emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);
+ emit_fb(as, PPCI_FCTIWZ, tmp, tmp);
+ emit_fab(as, PPCI_FSUB, tmp, left, tmp);
+ emit_lsptr(as, PPCI_LFS, (tmp & 31),
+ (void *)lj_ir_k64_find(as->J, U64x(4f000000,00000000)),
+ RSET_GPR);
+ } else {
+ emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO);
+ emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);
+ emit_fb(as, PPCI_FCTIWZ, tmp, left);
+ }
+ }
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */
+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
+ lua_assert(irt_isint(ir->t) || irt_isu32(ir->t));
+ if ((ir->op2 & IRCONV_SEXT))
+ emit_as(as, st == IRT_I8 ? PPCI_EXTSB : PPCI_EXTSH, dest, left);
+ else
+ emit_rot(as, PPCI_RLWINM, dest, left, 0, st == IRT_U8 ? 24 : 16, 31);
+ } else { /* 32/64 bit integer conversions. */
+ /* Only need to handle 32/32 bit no-op (cast) on 32 bit archs. */
+ ra_leftov(as, dest, lref); /* Do nothing, but may need to move regs. */
+ }
+ }
+}
+
+#if LJ_HASFFI
+static void asm_conv64(ASMState *as, IRIns *ir)
+{
+ IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK);
+ IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH);
+ IRCallID id;
+ const CCallInfo *ci;
+ IRRef args[2];
+ args[0] = ir->op1;
+ args[1] = (ir-1)->op1;
+ if (st == IRT_NUM || st == IRT_FLOAT) {
+ id = IRCALL_fp64_d2l + ((st == IRT_FLOAT) ? 2 : 0) + (dt - IRT_I64);
+ ir--;
+ } else {
+ id = IRCALL_fp64_l2d + ((dt == IRT_FLOAT) ? 2 : 0) + (st - IRT_I64);
+ }
+ ci = &lj_ir_callinfo[id];
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+#endif
+
+static void asm_strto(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num];
+ IRRef args[2];
+ int32_t ofs;
+ RegSet drop = RSET_SCRATCH;
+ if (ra_hasreg(ir->r)) rset_set(drop, ir->r); /* Spill dest reg (if any). */
+ ra_evictset(as, drop);
+ asm_guardcc(as, CC_EQ);
+ emit_ai(as, PPCI_CMPWI, RID_RET, 0); /* Test return status. */
+ args[0] = ir->op1; /* GCstr *str */
+ args[1] = ASMREF_TMP1; /* TValue *n */
+ asm_gencall(as, ci, args);
+ /* Store the result to the spill slot or temp slots. */
+ ofs = ir->s ? sps_scale(ir->s) : SPOFS_TMP;
+ emit_tai(as, PPCI_ADDI, ra_releasetmp(as, ASMREF_TMP1), RID_SP, ofs);
+}
+
+/* Get pointer to TValue. */
+static void asm_tvptr(ASMState *as, Reg dest, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ if (irt_isnum(ir->t)) {
+ if (irref_isk(ref)) /* Use the number constant itself as a TValue. */
+ ra_allockreg(as, i32ptr(ir_knum(ir)), dest);
+ else /* Otherwise force a spill and use the spill slot. */
+ emit_tai(as, PPCI_ADDI, dest, RID_SP, ra_spill(as, ir));
+ } else {
+ /* Otherwise use g->tmptv to hold the TValue. */
+ RegSet allow = rset_exclude(RSET_GPR, dest);
+ Reg type;
+ emit_tai(as, PPCI_ADDI, dest, RID_JGL, offsetof(global_State, tmptv)-32768);
+ if (!irt_ispri(ir->t)) {
+ Reg src = ra_alloc1(as, ref, allow);
+ emit_setgl(as, src, tmptv.gcr);
+ }
+ type = ra_allock(as, irt_toitype(ir->t), allow);
+ emit_setgl(as, type, tmptv.it);
+ }
+}
+
+static void asm_tostr(ASMState *as, IRIns *ir)
+{
+ IRRef args[2];
+ args[0] = ASMREF_L;
+ as->gcsteps++;
+ if (irt_isnum(IR(ir->op1)->t) || (ir+1)->o == IR_HIOP) {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromnum];
+ args[1] = ASMREF_TMP1; /* const lua_Number * */
+ asm_setupresult(as, ir, ci); /* GCstr * */
+ asm_gencall(as, ci, args);
+ asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op1);
+ } else {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromint];
+ args[1] = ir->op1; /* int32_t k */
+ asm_setupresult(as, ir, ci); /* GCstr * */
+ asm_gencall(as, ci, args);
+ }
+}
+
+/* -- Memory references --------------------------------------------------- */
+
+static void asm_aref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg idx, base;
+ if (irref_isk(ir->op2)) {
+ IRRef tab = IR(ir->op1)->op1;
+ int32_t ofs = asm_fuseabase(as, tab);
+ IRRef refa = ofs ? tab : ir->op1;
+ ofs += 8*IR(ir->op2)->i;
+ if (checki16(ofs)) {
+ base = ra_alloc1(as, refa, RSET_GPR);
+ emit_tai(as, PPCI_ADDI, dest, base, ofs);
+ return;
+ }
+ }
+ base = ra_alloc1(as, ir->op1, RSET_GPR);
+ idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base));
+ emit_tab(as, PPCI_ADD, dest, RID_TMP, base);
+ emit_slwi(as, RID_TMP, idx, 3);
+}
+
+/* Inlined hash lookup. Specialized for key type and for const keys.
+** The equivalent C code is:
+** Node *n = hashkey(t, key);
+** do {
+** if (lj_obj_equal(&n->key, key)) return &n->val;
+** } while ((n = nextnode(n)));
+** return niltv(L);
+*/
+static void asm_href(ASMState *as, IRIns *ir, IROp merge)
+{
+ RegSet allow = RSET_GPR;
+ int destused = ra_used(ir);
+ Reg dest = ra_dest(as, ir, allow);
+ Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest));
+ Reg key = RID_NONE, tmp1 = RID_TMP, tmp2;
+ Reg tisnum = RID_NONE, tmpnum = RID_NONE;
+ IRRef refkey = ir->op2;
+ IRIns *irkey = IR(refkey);
+ IRType1 kt = irkey->t;
+ uint32_t khash;
+ MCLabel l_end, l_loop, l_next;
+
+ rset_clear(allow, tab);
+ if (irt_isnum(kt)) {
+ key = ra_alloc1(as, refkey, RSET_FPR);
+ tmpnum = ra_scratch(as, rset_exclude(RSET_FPR, key));
+ tisnum = ra_allock(as, (int32_t)LJ_TISNUM, allow);
+ rset_clear(allow, tisnum);
+ } else if (!irt_ispri(kt)) {
+ key = ra_alloc1(as, refkey, allow);
+ rset_clear(allow, key);
+ }
+ tmp2 = ra_scratch(as, allow);
+ rset_clear(allow, tmp2);
+
+ /* Key not found in chain: jump to exit (if merged) or load niltv. */
+ l_end = emit_label(as);
+ as->invmcp = NULL;
+ if (merge == IR_NE)
+ asm_guardcc(as, CC_EQ);
+ else if (destused)
+ emit_loada(as, dest, niltvg(J2G(as->J)));
+
+ /* Follow hash chain until the end. */
+ l_loop = --as->mcp;
+ emit_ai(as, PPCI_CMPWI, dest, 0);
+ emit_tai(as, PPCI_LWZ, dest, dest, (int32_t)offsetof(Node, next));
+ l_next = emit_label(as);
+
+ /* Type and value comparison. */
+ if (merge == IR_EQ)
+ asm_guardcc(as, CC_EQ);
+ else
+ emit_condbranch(as, PPCI_BC|PPCF_Y, CC_EQ, l_end);
+ if (irt_isnum(kt)) {
+ emit_fab(as, PPCI_FCMPU, 0, tmpnum, key);
+ emit_condbranch(as, PPCI_BC, CC_GE, l_next);
+ emit_ab(as, PPCI_CMPLW, tmp1, tisnum);
+ emit_fai(as, PPCI_LFD, tmpnum, dest, (int32_t)offsetof(Node, key.n));
+ } else {
+ if (!irt_ispri(kt)) {
+ emit_ab(as, PPCI_CMPW, tmp2, key);
+ emit_condbranch(as, PPCI_BC, CC_NE, l_next);
+ }
+ emit_ai(as, PPCI_CMPWI, tmp1, irt_toitype(irkey->t));
+ if (!irt_ispri(kt))
+ emit_tai(as, PPCI_LWZ, tmp2, dest, (int32_t)offsetof(Node, key.gcr));
+ }
+ emit_tai(as, PPCI_LWZ, tmp1, dest, (int32_t)offsetof(Node, key.it));
+ *l_loop = PPCI_BC | PPCF_Y | PPCF_CC(CC_NE) |
+ (((char *)as->mcp-(char *)l_loop) & 0xffffu);
+
+ /* Load main position relative to tab->node into dest. */
+ khash = irref_isk(refkey) ? ir_khash(irkey) : 1;
+ if (khash == 0) {
+ emit_tai(as, PPCI_LWZ, dest, tab, (int32_t)offsetof(GCtab, node));
+ } else {
+ Reg tmphash = tmp1;
+ if (irref_isk(refkey))
+ tmphash = ra_allock(as, khash, allow);
+ emit_tab(as, PPCI_ADD, dest, dest, tmp1);
+ emit_tai(as, PPCI_MULLI, tmp1, tmp1, sizeof(Node));
+ emit_asb(as, PPCI_AND, tmp1, tmp2, tmphash);
+ emit_tai(as, PPCI_LWZ, dest, tab, (int32_t)offsetof(GCtab, node));
+ emit_tai(as, PPCI_LWZ, tmp2, tab, (int32_t)offsetof(GCtab, hmask));
+ if (irref_isk(refkey)) {
+ /* Nothing to do. */
+ } else if (irt_isstr(kt)) {
+ emit_tai(as, PPCI_LWZ, tmp1, key, (int32_t)offsetof(GCstr, hash));
+ } else { /* Must match with hash*() in lj_tab.c. */
+ emit_tab(as, PPCI_SUBF, tmp1, tmp2, tmp1);
+ emit_rotlwi(as, tmp2, tmp2, HASH_ROT3);
+ emit_asb(as, PPCI_XOR, tmp1, tmp1, tmp2);
+ emit_rotlwi(as, tmp1, tmp1, (HASH_ROT2+HASH_ROT1)&31);
+ emit_tab(as, PPCI_SUBF, tmp2, dest, tmp2);
+ if (irt_isnum(kt)) {
+ int32_t ofs = ra_spill(as, irkey);
+ emit_asb(as, PPCI_XOR, tmp2, tmp2, tmp1);
+ emit_rotlwi(as, dest, tmp1, HASH_ROT1);
+ emit_tab(as, PPCI_ADD, tmp1, tmp1, tmp1);
+ emit_tai(as, PPCI_LWZ, tmp2, RID_SP, ofs+4);
+ emit_tai(as, PPCI_LWZ, tmp1, RID_SP, ofs);
+ } else {
+ emit_asb(as, PPCI_XOR, tmp2, key, tmp1);
+ emit_rotlwi(as, dest, tmp1, HASH_ROT1);
+ emit_tai(as, PPCI_ADDI, tmp1, tmp2, HASH_BIAS);
+ emit_tai(as, PPCI_ADDIS, tmp2, key, (HASH_BIAS + 32768)>>16);
+ }
+ }
+ }
+}
+
+static void asm_hrefk(ASMState *as, IRIns *ir)
+{
+ IRIns *kslot = IR(ir->op2);
+ IRIns *irkey = IR(kslot->op1);
+ int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node));
+ int32_t kofs = ofs + (int32_t)offsetof(Node, key);
+ Reg dest = (ra_used(ir)||ofs > 32736) ? ra_dest(as, ir, RSET_GPR) : RID_NONE;
+ Reg node = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg key = RID_NONE, type = RID_TMP, idx = node;
+ RegSet allow = rset_exclude(RSET_GPR, node);
+ lua_assert(ofs % sizeof(Node) == 0);
+ if (ofs > 32736) {
+ idx = dest;
+ rset_clear(allow, dest);
+ kofs = (int32_t)offsetof(Node, key);
+ } else if (ra_hasreg(dest)) {
+ emit_tai(as, PPCI_ADDI, dest, node, ofs);
+ }
+ asm_guardcc(as, CC_NE);
+ if (!irt_ispri(irkey->t)) {
+ key = ra_scratch(as, allow);
+ rset_clear(allow, key);
+ }
+ rset_clear(allow, type);
+ if (irt_isnum(irkey->t)) {
+ emit_cmpi(as, key, (int32_t)ir_knum(irkey)->u32.lo);
+ asm_guardcc(as, CC_NE);
+ emit_cmpi(as, type, (int32_t)ir_knum(irkey)->u32.hi);
+ } else {
+ if (ra_hasreg(key)) {
+ emit_cmpi(as, key, irkey->i); /* May use RID_TMP, i.e. type. */
+ asm_guardcc(as, CC_NE);
+ }
+ emit_ai(as, PPCI_CMPWI, type, irt_toitype(irkey->t));
+ }
+ if (ra_hasreg(key)) emit_tai(as, PPCI_LWZ, key, idx, kofs+4);
+ emit_tai(as, PPCI_LWZ, type, idx, kofs);
+ if (ofs > 32736) {
+ emit_tai(as, PPCI_ADDIS, dest, dest, (ofs + 32768) >> 16);
+ emit_tai(as, PPCI_ADDI, dest, node, ofs);
+ }
+}
+
+static void asm_newref(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_newkey];
+ IRRef args[3];
+ if (ir->r == RID_SINK)
+ return;
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ir->op1; /* GCtab *t */
+ args[2] = ASMREF_TMP1; /* cTValue *key */
+ asm_setupresult(as, ir, ci); /* TValue * */
+ asm_gencall(as, ci, args);
+ asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op2);
+}
+
+static void asm_uref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (irref_isk(ir->op1)) {
+ GCfunc *fn = ir_kfunc(IR(ir->op1));
+ MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v;
+ emit_lsptr(as, PPCI_LWZ, dest, v, RSET_GPR);
+ } else {
+ Reg uv = ra_scratch(as, RSET_GPR);
+ Reg func = ra_alloc1(as, ir->op1, RSET_GPR);
+ if (ir->o == IR_UREFC) {
+ asm_guardcc(as, CC_NE);
+ emit_ai(as, PPCI_CMPWI, RID_TMP, 1);
+ emit_tai(as, PPCI_ADDI, dest, uv, (int32_t)offsetof(GCupval, tv));
+ emit_tai(as, PPCI_LBZ, RID_TMP, uv, (int32_t)offsetof(GCupval, closed));
+ } else {
+ emit_tai(as, PPCI_LWZ, dest, uv, (int32_t)offsetof(GCupval, v));
+ }
+ emit_tai(as, PPCI_LWZ, uv, func,
+ (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8));
+ }
+}
+
+static void asm_fref(ASMState *as, IRIns *ir)
+{
+ UNUSED(as); UNUSED(ir);
+ lua_assert(!ra_used(ir));
+}
+
+static void asm_strref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ IRRef ref = ir->op2, refk = ir->op1;
+ int32_t ofs = (int32_t)sizeof(GCstr);
+ Reg r;
+ if (irref_isk(ref)) {
+ IRRef tmp = refk; refk = ref; ref = tmp;
+ } else if (!irref_isk(refk)) {
+ Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);
+ IRIns *irr = IR(ir->op2);
+ if (ra_hasreg(irr->r)) {
+ ra_noweak(as, irr->r);
+ right = irr->r;
+ } else if (mayfuse(as, irr->op2) &&
+ irr->o == IR_ADD && irref_isk(irr->op2) &&
+ checki16(ofs + IR(irr->op2)->i)) {
+ ofs += IR(irr->op2)->i;
+ right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left));
+ } else {
+ right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left));
+ }
+ emit_tai(as, PPCI_ADDI, dest, dest, ofs);
+ emit_tab(as, PPCI_ADD, dest, left, right);
+ return;
+ }
+ r = ra_alloc1(as, ref, RSET_GPR);
+ ofs += IR(refk)->i;
+ if (checki16(ofs))
+ emit_tai(as, PPCI_ADDI, dest, r, ofs);
+ else
+ emit_tab(as, PPCI_ADD, dest, r,
+ ra_allock(as, ofs, rset_exclude(RSET_GPR, r)));
+}
+
+/* -- Loads and stores ---------------------------------------------------- */
+
+static PPCIns asm_fxloadins(IRIns *ir)
+{
+ switch (irt_type(ir->t)) {
+ case IRT_I8: return PPCI_LBZ; /* Needs sign-extension. */
+ case IRT_U8: return PPCI_LBZ;
+ case IRT_I16: return PPCI_LHA;
+ case IRT_U16: return PPCI_LHZ;
+ case IRT_NUM: return PPCI_LFD;
+ case IRT_FLOAT: return PPCI_LFS;
+ default: return PPCI_LWZ;
+ }
+}
+
+static PPCIns asm_fxstoreins(IRIns *ir)
+{
+ switch (irt_type(ir->t)) {
+ case IRT_I8: case IRT_U8: return PPCI_STB;
+ case IRT_I16: case IRT_U16: return PPCI_STH;
+ case IRT_NUM: return PPCI_STFD;
+ case IRT_FLOAT: return PPCI_STFS;
+ default: return PPCI_STW;
+ }
+}
+
+static void asm_fload(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg idx = ra_alloc1(as, ir->op1, RSET_GPR);
+ PPCIns pi = asm_fxloadins(ir);
+ int32_t ofs;
+ if (ir->op2 == IRFL_TAB_ARRAY) {
+ ofs = asm_fuseabase(as, ir->op1);
+ if (ofs) { /* Turn the t->array load into an add for colocated arrays. */
+ emit_tai(as, PPCI_ADDI, dest, idx, ofs);
+ return;
+ }
+ }
+ ofs = field_ofs[ir->op2];
+ lua_assert(!irt_isi8(ir->t));
+ emit_tai(as, pi, dest, idx, ofs);
+}
+
+static void asm_fstore(ASMState *as, IRIns *ir)
+{
+ if (ir->r != RID_SINK) {
+ Reg src = ra_alloc1(as, ir->op2, RSET_GPR);
+ IRIns *irf = IR(ir->op1);
+ Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src));
+ int32_t ofs = field_ofs[irf->op2];
+ PPCIns pi = asm_fxstoreins(ir);
+ emit_tai(as, pi, src, idx, ofs);
+ }
+}
+
+static void asm_xload(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);
+ lua_assert(!(ir->op2 & IRXLOAD_UNALIGNED));
+ if (irt_isi8(ir->t))
+ emit_as(as, PPCI_EXTSB, dest, dest);
+ asm_fusexref(as, asm_fxloadins(ir), dest, ir->op1, RSET_GPR, 0);
+}
+
+static void asm_xstore(ASMState *as, IRIns *ir, int32_t ofs)
+{
+ IRIns *irb;
+ if (ir->r == RID_SINK)
+ return;
+ if (ofs == 0 && mayfuse(as, ir->op2) && (irb = IR(ir->op2))->o == IR_BSWAP &&
+ ra_noreg(irb->r) && (irt_isint(ir->t) || irt_isu32(ir->t))) {
+ /* Fuse BSWAP with XSTORE to stwbrx. */
+ Reg src = ra_alloc1(as, irb->op1, RSET_GPR);
+ asm_fusexrefx(as, PPCI_STWBRX, src, ir->op1, rset_exclude(RSET_GPR, src));
+ } else {
+ Reg src = ra_alloc1(as, ir->op2, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);
+ asm_fusexref(as, asm_fxstoreins(ir), src, ir->op1,
+ rset_exclude(RSET_GPR, src), ofs);
+ }
+}
+
+static void asm_ahuvload(ASMState *as, IRIns *ir)
+{
+ IRType1 t = ir->t;
+ Reg dest = RID_NONE, type = RID_TMP, tmp = RID_TMP, idx;
+ RegSet allow = RSET_GPR;
+ int32_t ofs = AHUREF_LSX;
+ if (ra_used(ir)) {
+ lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t));
+ if (!irt_isnum(t)) ofs = 0;
+ dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : RSET_GPR);
+ rset_clear(allow, dest);
+ }
+ idx = asm_fuseahuref(as, ir->op1, &ofs, allow);
+ if (irt_isnum(t)) {
+ Reg tisnum = ra_allock(as, (int32_t)LJ_TISNUM, rset_exclude(allow, idx));
+ asm_guardcc(as, CC_GE);
+ emit_ab(as, PPCI_CMPLW, type, tisnum);
+ if (ra_hasreg(dest)) {
+ if (ofs == AHUREF_LSX) {
+ tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR,
+ (idx&255)), (idx>>8)));
+ emit_fab(as, PPCI_LFDX, dest, (idx&255), tmp);
+ } else {
+ emit_fai(as, PPCI_LFD, dest, idx, ofs);
+ }
+ }
+ } else {
+ asm_guardcc(as, CC_NE);
+ emit_ai(as, PPCI_CMPWI, type, irt_toitype(t));
+ if (ra_hasreg(dest)) emit_tai(as, PPCI_LWZ, dest, idx, ofs+4);
+ }
+ if (ofs == AHUREF_LSX) {
+ emit_tab(as, PPCI_LWZX, type, (idx&255), tmp);
+ emit_slwi(as, tmp, (idx>>8), 3);
+ } else {
+ emit_tai(as, PPCI_LWZ, type, idx, ofs);
+ }
+}
+
+static void asm_ahustore(ASMState *as, IRIns *ir)
+{
+ RegSet allow = RSET_GPR;
+ Reg idx, src = RID_NONE, type = RID_NONE;
+ int32_t ofs = AHUREF_LSX;
+ if (ir->r == RID_SINK)
+ return;
+ if (irt_isnum(ir->t)) {
+ src = ra_alloc1(as, ir->op2, RSET_FPR);
+ } else {
+ if (!irt_ispri(ir->t)) {
+ src = ra_alloc1(as, ir->op2, allow);
+ rset_clear(allow, src);
+ ofs = 0;
+ }
+ type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);
+ rset_clear(allow, type);
+ }
+ idx = asm_fuseahuref(as, ir->op1, &ofs, allow);
+ if (irt_isnum(ir->t)) {
+ if (ofs == AHUREF_LSX) {
+ emit_fab(as, PPCI_STFDX, src, (idx&255), RID_TMP);
+ emit_slwi(as, RID_TMP, (idx>>8), 3);
+ } else {
+ emit_fai(as, PPCI_STFD, src, idx, ofs);
+ }
+ } else {
+ if (ra_hasreg(src))
+ emit_tai(as, PPCI_STW, src, idx, ofs+4);
+ if (ofs == AHUREF_LSX) {
+ emit_tab(as, PPCI_STWX, type, (idx&255), RID_TMP);
+ emit_slwi(as, RID_TMP, (idx>>8), 3);
+ } else {
+ emit_tai(as, PPCI_STW, type, idx, ofs);
+ }
+ }
+}
+
+static void asm_sload(ASMState *as, IRIns *ir)
+{
+ int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 0 : 4);
+ IRType1 t = ir->t;
+ Reg dest = RID_NONE, type = RID_NONE, base;
+ RegSet allow = RSET_GPR;
+ lua_assert(!(ir->op2 & IRSLOAD_PARENT)); /* Handled by asm_head_side(). */
+ lua_assert(irt_isguard(t) || !(ir->op2 & IRSLOAD_TYPECHECK));
+ lua_assert(LJ_DUALNUM ||
+ !irt_isint(t) || (ir->op2 & (IRSLOAD_CONVERT|IRSLOAD_FRAME)));
+ if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(t) && irt_isint(t)) {
+ dest = ra_scratch(as, RSET_FPR);
+ asm_tointg(as, ir, dest);
+ t.irt = IRT_NUM; /* Continue with a regular number type check. */
+ } else if (ra_used(ir)) {
+ lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t));
+ dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : RSET_GPR);
+ rset_clear(allow, dest);
+ base = ra_alloc1(as, REF_BASE, allow);
+ rset_clear(allow, base);
+ if ((ir->op2 & IRSLOAD_CONVERT)) {
+ if (irt_isint(t)) {
+ emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO);
+ dest = ra_scratch(as, RSET_FPR);
+ emit_fai(as, PPCI_STFD, dest, RID_SP, SPOFS_TMP);
+ emit_fb(as, PPCI_FCTIWZ, dest, dest);
+ t.irt = IRT_NUM; /* Check for original type. */
+ } else {
+ Reg tmp = ra_scratch(as, allow);
+ Reg hibias = ra_allock(as, 0x43300000, rset_clear(allow, tmp));
+ Reg fbias = ra_scratch(as, rset_exclude(RSET_FPR, dest));
+ emit_fab(as, PPCI_FSUB, dest, dest, fbias);
+ emit_fai(as, PPCI_LFD, dest, RID_SP, SPOFS_TMP);
+ emit_lsptr(as, PPCI_LFS, (fbias & 31),
+ (void *)lj_ir_k64_find(as->J, U64x(59800004,59800000)),
+ rset_clear(allow, hibias));
+ emit_tai(as, PPCI_STW, tmp, RID_SP, SPOFS_TMPLO);
+ emit_tai(as, PPCI_STW, hibias, RID_SP, SPOFS_TMPHI);
+ emit_asi(as, PPCI_XORIS, tmp, tmp, 0x8000);
+ dest = tmp;
+ t.irt = IRT_INT; /* Check for original type. */
+ }
+ }
+ goto dotypecheck;
+ }
+ base = ra_alloc1(as, REF_BASE, allow);
+ rset_clear(allow, base);
+dotypecheck:
+ if (irt_isnum(t)) {
+ if ((ir->op2 & IRSLOAD_TYPECHECK)) {
+ Reg tisnum = ra_allock(as, (int32_t)LJ_TISNUM, allow);
+ asm_guardcc(as, CC_GE);
+ emit_ab(as, PPCI_CMPLW, RID_TMP, tisnum);
+ type = RID_TMP;
+ }
+ if (ra_hasreg(dest)) emit_fai(as, PPCI_LFD, dest, base, ofs-4);
+ } else {
+ if ((ir->op2 & IRSLOAD_TYPECHECK)) {
+ asm_guardcc(as, CC_NE);
+ emit_ai(as, PPCI_CMPWI, RID_TMP, irt_toitype(t));
+ type = RID_TMP;
+ }
+ if (ra_hasreg(dest)) emit_tai(as, PPCI_LWZ, dest, base, ofs);
+ }
+ if (ra_hasreg(type)) emit_tai(as, PPCI_LWZ, type, base, ofs-4);
+}
+
+/* -- Allocations --------------------------------------------------------- */
+
+#if LJ_HASFFI
+static void asm_cnew(ASMState *as, IRIns *ir)
+{
+ CTState *cts = ctype_ctsG(J2G(as->J));
+ CTypeID ctypeid = (CTypeID)IR(ir->op1)->i;
+ CTSize sz = (ir->o == IR_CNEWI || ir->op2 == REF_NIL) ?
+ lj_ctype_size(cts, ctypeid) : (CTSize)IR(ir->op2)->i;
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];
+ IRRef args[2];
+ RegSet allow = (RSET_GPR & ~RSET_SCRATCH);
+ RegSet drop = RSET_SCRATCH;
+ lua_assert(sz != CTSIZE_INVALID);
+
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ASMREF_TMP1; /* MSize size */
+ as->gcsteps++;
+
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ ra_evictset(as, drop);
+ if (ra_used(ir))
+ ra_destreg(as, ir, RID_RET); /* GCcdata * */
+
+ /* Initialize immutable cdata object. */
+ if (ir->o == IR_CNEWI) {
+ int32_t ofs = sizeof(GCcdata);
+ lua_assert(sz == 4 || sz == 8);
+ if (sz == 8) {
+ ofs += 4;
+ lua_assert((ir+1)->o == IR_HIOP);
+ }
+ for (;;) {
+ Reg r = ra_alloc1(as, ir->op2, allow);
+ emit_tai(as, PPCI_STW, r, RID_RET, ofs);
+ rset_clear(allow, r);
+ if (ofs == sizeof(GCcdata)) break;
+ ofs -= 4; ir++;
+ }
+ }
+ /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */
+ emit_tai(as, PPCI_STB, RID_RET+1, RID_RET, offsetof(GCcdata, gct));
+ emit_tai(as, PPCI_STH, RID_TMP, RID_RET, offsetof(GCcdata, ctypeid));
+ emit_ti(as, PPCI_LI, RID_RET+1, ~LJ_TCDATA);
+ emit_ti(as, PPCI_LI, RID_TMP, ctypeid); /* Lower 16 bit used. Sign-ext ok. */
+ asm_gencall(as, ci, args);
+ ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)),
+ ra_releasetmp(as, ASMREF_TMP1));
+}
+#else
+#define asm_cnew(as, ir) ((void)0)
+#endif
+
+/* -- Write barriers ------------------------------------------------------ */
+
+static void asm_tbar(ASMState *as, IRIns *ir)
+{
+ Reg tab = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg mark = ra_scratch(as, rset_exclude(RSET_GPR, tab));
+ Reg link = RID_TMP;
+ MCLabel l_end = emit_label(as);
+ emit_tai(as, PPCI_STW, link, tab, (int32_t)offsetof(GCtab, gclist));
+ emit_tai(as, PPCI_STB, mark, tab, (int32_t)offsetof(GCtab, marked));
+ emit_setgl(as, tab, gc.grayagain);
+ lua_assert(LJ_GC_BLACK == 0x04);
+ emit_rot(as, PPCI_RLWINM, mark, mark, 0, 30, 28); /* Clear black bit. */
+ emit_getgl(as, link, gc.grayagain);
+ emit_condbranch(as, PPCI_BC|PPCF_Y, CC_EQ, l_end);
+ emit_asi(as, PPCI_ANDIDOT, RID_TMP, mark, LJ_GC_BLACK);
+ emit_tai(as, PPCI_LBZ, mark, tab, (int32_t)offsetof(GCtab, marked));
+}
+
+static void asm_obar(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv];
+ IRRef args[2];
+ MCLabel l_end;
+ Reg obj, val, tmp;
+ /* No need for other object barriers (yet). */
+ lua_assert(IR(ir->op1)->o == IR_UREFC);
+ ra_evictset(as, RSET_SCRATCH);
+ l_end = emit_label(as);
+ args[0] = ASMREF_TMP1; /* global_State *g */
+ args[1] = ir->op1; /* TValue *tv */
+ asm_gencall(as, ci, args);
+ emit_tai(as, PPCI_ADDI, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768);
+ obj = IR(ir->op1)->r;
+ tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj));
+ emit_condbranch(as, PPCI_BC|PPCF_Y, CC_EQ, l_end);
+ emit_asi(as, PPCI_ANDIDOT, tmp, tmp, LJ_GC_BLACK);
+ emit_condbranch(as, PPCI_BC, CC_EQ, l_end);
+ emit_asi(as, PPCI_ANDIDOT, RID_TMP, RID_TMP, LJ_GC_WHITES);
+ val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj));
+ emit_tai(as, PPCI_LBZ, tmp, obj,
+ (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv));
+ emit_tai(as, PPCI_LBZ, RID_TMP, val, (int32_t)offsetof(GChead, marked));
+}
+
+/* -- Arithmetic and logic operations ------------------------------------- */
+
+static void asm_fparith(ASMState *as, IRIns *ir, PPCIns pi)
+{
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg right, left = ra_alloc2(as, ir, RSET_FPR);
+ right = (left >> 8); left &= 255;
+ if (pi == PPCI_FMUL)
+ emit_fac(as, pi, dest, left, right);
+ else
+ emit_fab(as, pi, dest, left, right);
+}
+
+static void asm_fpunary(ASMState *as, IRIns *ir, PPCIns pi)
+{
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR);
+ emit_fb(as, pi, dest, left);
+}
+
+static int asm_fpjoin_pow(ASMState *as, IRIns *ir)
+{
+ IRIns *irp = IR(ir->op1);
+ if (irp == ir-1 && irp->o == IR_MUL && !ra_used(irp)) {
+ IRIns *irpp = IR(irp->op1);
+ if (irpp == ir-2 && irpp->o == IR_FPMATH &&
+ irpp->op2 == IRFPM_LOG2 && !ra_used(irpp)) {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_pow];
+ IRRef args[2];
+ args[0] = irpp->op1;
+ args[1] = irp->op2;
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static void asm_add(ASMState *as, IRIns *ir)
+{
+ if (irt_isnum(ir->t)) {
+ if (!asm_fusemadd(as, ir, PPCI_FMADD, PPCI_FMADD))
+ asm_fparith(as, ir, PPCI_FADD);
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ PPCIns pi;
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (checki16(k)) {
+ pi = PPCI_ADDI;
+ /* May fail due to spills/restores above, but simplifies the logic. */
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ pi = PPCI_ADDICDOT;
+ }
+ emit_tai(as, pi, dest, left, k);
+ return;
+ } else if ((k & 0xffff) == 0) {
+ emit_tai(as, PPCI_ADDIS, dest, left, (k >> 16));
+ return;
+ } else if (!as->sectref) {
+ emit_tai(as, PPCI_ADDIS, dest, dest, (k + 32768) >> 16);
+ emit_tai(as, PPCI_ADDI, dest, left, k);
+ return;
+ }
+ }
+ pi = PPCI_ADD;
+ /* May fail due to spills/restores above, but simplifies the logic. */
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ pi |= PPCF_DOT;
+ }
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_tab(as, pi, dest, left, right);
+ }
+}
+
+static void asm_sub(ASMState *as, IRIns *ir)
+{
+ if (irt_isnum(ir->t)) {
+ if (!asm_fusemadd(as, ir, PPCI_FMSUB, PPCI_FNMSUB))
+ asm_fparith(as, ir, PPCI_FSUB);
+ } else {
+ PPCIns pi = PPCI_SUBF;
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left, right;
+ if (irref_isk(ir->op1)) {
+ int32_t k = IR(ir->op1)->i;
+ if (checki16(k)) {
+ right = ra_alloc1(as, ir->op2, RSET_GPR);
+ emit_tai(as, PPCI_SUBFIC, dest, right, k);
+ return;
+ }
+ }
+ /* May fail due to spills/restores above, but simplifies the logic. */
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ pi |= PPCF_DOT;
+ }
+ left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_tab(as, pi, dest, right, left); /* Subtract right _from_ left. */
+ }
+}
+
+static void asm_mul(ASMState *as, IRIns *ir)
+{
+ if (irt_isnum(ir->t)) {
+ asm_fparith(as, ir, PPCI_FMUL);
+ } else {
+ PPCIns pi = PPCI_MULLW;
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (checki16(k)) {
+ emit_tai(as, PPCI_MULLI, dest, left, k);
+ return;
+ }
+ }
+ /* May fail due to spills/restores above, but simplifies the logic. */
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ pi |= PPCF_DOT;
+ }
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_tab(as, pi, dest, left, right);
+ }
+}
+
+static void asm_neg(ASMState *as, IRIns *ir)
+{
+ if (irt_isnum(ir->t)) {
+ asm_fpunary(as, ir, PPCI_FNEG);
+ } else {
+ Reg dest, left;
+ PPCIns pi = PPCI_NEG;
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ pi |= PPCF_DOT;
+ }
+ dest = ra_dest(as, ir, RSET_GPR);
+ left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ emit_tab(as, pi, dest, left, 0);
+ }
+}
+
+static void asm_arithov(ASMState *as, IRIns *ir, PPCIns pi)
+{
+ Reg dest, left, right;
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ }
+ asm_guardcc(as, CC_SO);
+ dest = ra_dest(as, ir, RSET_GPR);
+ left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ if (pi == PPCI_SUBFO) { Reg tmp = left; left = right; right = tmp; }
+ emit_tab(as, pi|PPCF_DOT, dest, left, right);
+}
+
+#if LJ_HASFFI
+static void asm_add64(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);
+ PPCIns pi = PPCI_ADDE;
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (k == 0)
+ pi = PPCI_ADDZE;
+ else if (k == -1)
+ pi = PPCI_ADDME;
+ else
+ goto needright;
+ right = 0;
+ } else {
+ needright:
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ }
+ emit_tab(as, pi, dest, left, right);
+ ir--;
+ dest = ra_dest(as, ir, RSET_GPR);
+ left = ra_alloc1(as, ir->op1, RSET_GPR);
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (checki16(k)) {
+ emit_tai(as, PPCI_ADDIC, dest, left, k);
+ return;
+ }
+ }
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_tab(as, PPCI_ADDC, dest, left, right);
+}
+
+static void asm_sub64(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left, right = ra_alloc1(as, ir->op2, RSET_GPR);
+ PPCIns pi = PPCI_SUBFE;
+ if (irref_isk(ir->op1)) {
+ int32_t k = IR(ir->op1)->i;
+ if (k == 0)
+ pi = PPCI_SUBFZE;
+ else if (k == -1)
+ pi = PPCI_SUBFME;
+ else
+ goto needleft;
+ left = 0;
+ } else {
+ needleft:
+ left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, right));
+ }
+ emit_tab(as, pi, dest, right, left); /* Subtract right _from_ left. */
+ ir--;
+ dest = ra_dest(as, ir, RSET_GPR);
+ right = ra_alloc1(as, ir->op2, RSET_GPR);
+ if (irref_isk(ir->op1)) {
+ int32_t k = IR(ir->op1)->i;
+ if (checki16(k)) {
+ emit_tai(as, PPCI_SUBFIC, dest, right, k);
+ return;
+ }
+ }
+ left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, right));
+ emit_tab(as, PPCI_SUBFC, dest, right, left);
+}
+
+static void asm_neg64(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
+ emit_tab(as, PPCI_SUBFZE, dest, left, 0);
+ ir--;
+ dest = ra_dest(as, ir, RSET_GPR);
+ left = ra_alloc1(as, ir->op1, RSET_GPR);
+ emit_tai(as, PPCI_SUBFIC, dest, left, 0);
+}
+#endif
+
+static void asm_bitnot(ASMState *as, IRIns *ir)
+{
+ Reg dest, left, right;
+ PPCIns pi = PPCI_NOR;
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ pi |= PPCF_DOT;
+ }
+ dest = ra_dest(as, ir, RSET_GPR);
+ if (mayfuse(as, ir->op1)) {
+ IRIns *irl = IR(ir->op1);
+ if (irl->o == IR_BAND)
+ pi ^= (PPCI_NOR ^ PPCI_NAND);
+ else if (irl->o == IR_BXOR)
+ pi ^= (PPCI_NOR ^ PPCI_EQV);
+ else if (irl->o != IR_BOR)
+ goto nofuse;
+ left = ra_hintalloc(as, irl->op1, dest, RSET_GPR);
+ right = ra_alloc1(as, irl->op2, rset_exclude(RSET_GPR, left));
+ } else {
+nofuse:
+ left = right = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ }
+ emit_asb(as, pi, dest, left, right);
+}
+
+static void asm_bitswap(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ IRIns *irx;
+ if (mayfuse(as, ir->op1) && (irx = IR(ir->op1))->o == IR_XLOAD &&
+ ra_noreg(irx->r) && (irt_isint(irx->t) || irt_isu32(irx->t))) {
+ /* Fuse BSWAP with XLOAD to lwbrx. */
+ asm_fusexrefx(as, PPCI_LWBRX, dest, irx->op1, RSET_GPR);
+ } else {
+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg tmp = dest;
+ if (tmp == left) {
+ tmp = RID_TMP;
+ emit_mr(as, dest, RID_TMP);
+ }
+ emit_rot(as, PPCI_RLWIMI, tmp, left, 24, 16, 23);
+ emit_rot(as, PPCI_RLWIMI, tmp, left, 24, 0, 7);
+ emit_rotlwi(as, tmp, left, 8);
+ }
+}
+
+static void asm_bitop(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pik)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ Reg tmp = left;
+ if ((checku16(k) || (k & 0xffff) == 0) || (tmp = dest, !as->sectref)) {
+ if (!checku16(k)) {
+ emit_asi(as, pik ^ (PPCI_ORI ^ PPCI_ORIS), dest, tmp, (k >> 16));
+ if ((k & 0xffff) == 0) return;
+ }
+ emit_asi(as, pik, dest, left, k);
+ return;
+ }
+ }
+ /* May fail due to spills/restores above, but simplifies the logic. */
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ pi |= PPCF_DOT;
+ }
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_asb(as, pi, dest, left, right);
+}
+
+/* Fuse BAND with contiguous bitmask and a shift to rlwinm. */
+static void asm_fuseandsh(ASMState *as, PPCIns pi, int32_t mask, IRRef ref)
+{
+ IRIns *ir;
+ Reg left;
+ if (mayfuse(as, ref) && (ir = IR(ref), ra_noreg(ir->r)) &&
+ irref_isk(ir->op2) && ir->o >= IR_BSHL && ir->o <= IR_BROR) {
+ int32_t sh = (IR(ir->op2)->i & 31);
+ switch (ir->o) {
+ case IR_BSHL:
+ if ((mask & ((1u<<sh)-1))) goto nofuse;
+ break;
+ case IR_BSHR:
+ if ((mask & ~((~0u)>>sh))) goto nofuse;
+ sh = ((32-sh)&31);
+ break;
+ case IR_BROL:
+ break;
+ default:
+ goto nofuse;
+ }
+ left = ra_alloc1(as, ir->op1, RSET_GPR);
+ *--as->mcp = pi | PPCF_T(left) | PPCF_B(sh);
+ return;
+ }
+nofuse:
+ left = ra_alloc1(as, ref, RSET_GPR);
+ *--as->mcp = pi | PPCF_T(left);
+}
+
+static void asm_bitand(ASMState *as, IRIns *ir)
+{
+ Reg dest, left, right;
+ IRRef lref = ir->op1;
+ PPCIns dot = 0;
+ IRRef op2;
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ dot = PPCF_DOT;
+ }
+ dest = ra_dest(as, ir, RSET_GPR);
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (k) {
+ /* First check for a contiguous bitmask as used by rlwinm. */
+ uint32_t s1 = lj_ffs((uint32_t)k);
+ uint32_t k1 = ((uint32_t)k >> s1);
+ if ((k1 & (k1+1)) == 0) {
+ asm_fuseandsh(as, PPCI_RLWINM|dot | PPCF_A(dest) |
+ PPCF_MB(31-lj_fls((uint32_t)k)) | PPCF_ME(31-s1),
+ k, lref);
+ return;
+ }
+ if (~(uint32_t)k) {
+ uint32_t s2 = lj_ffs(~(uint32_t)k);
+ uint32_t k2 = (~(uint32_t)k >> s2);
+ if ((k2 & (k2+1)) == 0) {
+ asm_fuseandsh(as, PPCI_RLWINM|dot | PPCF_A(dest) |
+ PPCF_MB(32-s2) | PPCF_ME(30-lj_fls(~(uint32_t)k)),
+ k, lref);
+ return;
+ }
+ }
+ }
+ if (checku16(k)) {
+ left = ra_alloc1(as, lref, RSET_GPR);
+ emit_asi(as, PPCI_ANDIDOT, dest, left, k);
+ return;
+ } else if ((k & 0xffff) == 0) {
+ left = ra_alloc1(as, lref, RSET_GPR);
+ emit_asi(as, PPCI_ANDISDOT, dest, left, (k >> 16));
+ return;
+ }
+ }
+ op2 = ir->op2;
+ if (mayfuse(as, op2) && IR(op2)->o == IR_BNOT && ra_noreg(IR(op2)->r)) {
+ dot ^= (PPCI_AND ^ PPCI_ANDC);
+ op2 = IR(op2)->op1;
+ }
+ left = ra_hintalloc(as, lref, dest, RSET_GPR);
+ right = ra_alloc1(as, op2, rset_exclude(RSET_GPR, left));
+ emit_asb(as, PPCI_AND ^ dot, dest, left, right);
+}
+
+static void asm_bitshift(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pik)
+{
+ Reg dest, left;
+ Reg dot = 0;
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ dot = PPCF_DOT;
+ }
+ dest = ra_dest(as, ir, RSET_GPR);
+ left = ra_alloc1(as, ir->op1, RSET_GPR);
+ if (irref_isk(ir->op2)) { /* Constant shifts. */
+ int32_t shift = (IR(ir->op2)->i & 31);
+ if (pik == 0) /* SLWI */
+ emit_rot(as, PPCI_RLWINM|dot, dest, left, shift, 0, 31-shift);
+ else if (pik == 1) /* SRWI */
+ emit_rot(as, PPCI_RLWINM|dot, dest, left, (32-shift)&31, shift, 31);
+ else
+ emit_asb(as, pik|dot, dest, left, shift);
+ } else {
+ Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_asb(as, pi|dot, dest, left, right);
+ }
+}
+
+static void asm_min_max(ASMState *as, IRIns *ir, int ismax)
+{
+ if (irt_isnum(ir->t)) {
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg tmp = dest;
+ Reg right, left = ra_alloc2(as, ir, RSET_FPR);
+ right = (left >> 8); left &= 255;
+ if (tmp == left || tmp == right)
+ tmp = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_FPR,
+ dest), left), right));
+ emit_facb(as, PPCI_FSEL, dest, tmp,
+ ismax ? left : right, ismax ? right : left);
+ emit_fab(as, PPCI_FSUB, tmp, left, right);
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg tmp1 = RID_TMP, tmp2 = dest;
+ Reg right, left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ if (tmp2 == left || tmp2 == right)
+ tmp2 = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_GPR,
+ dest), left), right));
+ emit_tab(as, PPCI_ADD, dest, tmp2, right);
+ emit_asb(as, ismax ? PPCI_ANDC : PPCI_AND, tmp2, tmp2, tmp1);
+ emit_tab(as, PPCI_SUBFE, tmp1, tmp1, tmp1);
+ emit_tab(as, PPCI_SUBFC, tmp2, tmp2, tmp1);
+ emit_asi(as, PPCI_XORIS, tmp2, right, 0x8000);
+ emit_asi(as, PPCI_XORIS, tmp1, left, 0x8000);
+ }
+}
+
+/* -- Comparisons --------------------------------------------------------- */
+
+#define CC_UNSIGNED 0x08 /* Unsigned integer comparison. */
+#define CC_TWO 0x80 /* Check two flags for FP comparison. */
+
+/* Map of comparisons to flags. ORDER IR. */
+static const uint8_t asm_compmap[IR_ABC+1] = {
+ /* op int cc FP cc */
+ /* LT */ CC_GE + (CC_GE<<4),
+ /* GE */ CC_LT + (CC_LE<<4) + CC_TWO,
+ /* LE */ CC_GT + (CC_GE<<4) + CC_TWO,
+ /* GT */ CC_LE + (CC_LE<<4),
+ /* ULT */ CC_GE + CC_UNSIGNED + (CC_GT<<4) + CC_TWO,
+ /* UGE */ CC_LT + CC_UNSIGNED + (CC_LT<<4),
+ /* ULE */ CC_GT + CC_UNSIGNED + (CC_GT<<4),
+ /* UGT */ CC_LE + CC_UNSIGNED + (CC_LT<<4) + CC_TWO,
+ /* EQ */ CC_NE + (CC_NE<<4),
+ /* NE */ CC_EQ + (CC_EQ<<4),
+ /* ABC */ CC_LE + CC_UNSIGNED + (CC_LT<<4) + CC_TWO /* Same as UGT. */
+};
+
+static void asm_intcomp_(ASMState *as, IRRef lref, IRRef rref, Reg cr, PPCCC cc)
+{
+ Reg right, left = ra_alloc1(as, lref, RSET_GPR);
+ if (irref_isk(rref)) {
+ int32_t k = IR(rref)->i;
+ if ((cc & CC_UNSIGNED) == 0) { /* Signed comparison with constant. */
+ if (checki16(k)) {
+ emit_tai(as, PPCI_CMPWI, cr, left, k);
+ /* Signed comparison with zero and referencing previous ins? */
+ if (k == 0 && lref == as->curins-1)
+ as->flagmcp = as->mcp; /* Allow elimination of the compare. */
+ return;
+ } else if ((cc & 3) == (CC_EQ & 3)) { /* Use CMPLWI for EQ or NE. */
+ if (checku16(k)) {
+ emit_tai(as, PPCI_CMPLWI, cr, left, k);
+ return;
+ } else if (!as->sectref && ra_noreg(IR(rref)->r)) {
+ emit_tai(as, PPCI_CMPLWI, cr, RID_TMP, k);
+ emit_asi(as, PPCI_XORIS, RID_TMP, left, (k >> 16));
+ return;
+ }
+ }
+ } else { /* Unsigned comparison with constant. */
+ if (checku16(k)) {
+ emit_tai(as, PPCI_CMPLWI, cr, left, k);
+ return;
+ }
+ }
+ }
+ right = ra_alloc1(as, rref, rset_exclude(RSET_GPR, left));
+ emit_tab(as, (cc & CC_UNSIGNED) ? PPCI_CMPLW : PPCI_CMPW, cr, left, right);
+}
+
+static void asm_comp(ASMState *as, IRIns *ir)
+{
+ PPCCC cc = asm_compmap[ir->o];
+ if (irt_isnum(ir->t)) {
+ Reg right, left = ra_alloc2(as, ir, RSET_FPR);
+ right = (left >> 8); left &= 255;
+ asm_guardcc(as, (cc >> 4));
+ if ((cc & CC_TWO))
+ emit_tab(as, PPCI_CROR, ((cc>>4)&3), ((cc>>4)&3), (CC_EQ&3));
+ emit_fab(as, PPCI_FCMPU, 0, left, right);
+ } else {
+ IRRef lref = ir->op1, rref = ir->op2;
+ if (irref_isk(lref) && !irref_isk(rref)) {
+ /* Swap constants to the right (only for ABC). */
+ IRRef tmp = lref; lref = rref; rref = tmp;
+ if ((cc & 2) == 0) cc ^= 1; /* LT <-> GT, LE <-> GE */
+ }
+ asm_guardcc(as, cc);
+ asm_intcomp_(as, lref, rref, 0, cc);
+ }
+}
+
+#if LJ_HASFFI
+/* 64 bit integer comparisons. */
+static void asm_comp64(ASMState *as, IRIns *ir)
+{
+ PPCCC cc = asm_compmap[(ir-1)->o];
+ if ((cc&3) == (CC_EQ&3)) {
+ asm_guardcc(as, cc);
+ emit_tab(as, (cc&4) ? PPCI_CRAND : PPCI_CROR,
+ (CC_EQ&3), (CC_EQ&3), 4+(CC_EQ&3));
+ } else {
+ asm_guardcc(as, CC_EQ);
+ emit_tab(as, PPCI_CROR, (CC_EQ&3), (CC_EQ&3), ((cc^~(cc>>2))&1));
+ emit_tab(as, (cc&4) ? PPCI_CRAND : PPCI_CRANDC,
+ (CC_EQ&3), (CC_EQ&3), 4+(cc&3));
+ }
+ /* Loword comparison sets cr1 and is unsigned, except for equality. */
+ asm_intcomp_(as, (ir-1)->op1, (ir-1)->op2, 4,
+ cc | ((cc&3) == (CC_EQ&3) ? 0 : CC_UNSIGNED));
+ /* Hiword comparison sets cr0. */
+ asm_intcomp_(as, ir->op1, ir->op2, 0, cc);
+ as->flagmcp = NULL; /* Doesn't work here. */
+}
+#endif
+
+/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */
+
+/* Hiword op of a split 64 bit op. Previous op must be the loword op. */
+static void asm_hiop(ASMState *as, IRIns *ir)
+{
+#if LJ_HASFFI
+ /* HIOP is marked as a store because it needs its own DCE logic. */
+ int uselo = ra_used(ir-1), usehi = ra_used(ir); /* Loword/hiword used? */
+ if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1;
+ if ((ir-1)->o == IR_CONV) { /* Conversions to/from 64 bit. */
+ as->curins--; /* Always skip the CONV. */
+ if (usehi || uselo)
+ asm_conv64(as, ir);
+ return;
+ } else if ((ir-1)->o <= IR_NE) { /* 64 bit integer comparisons. ORDER IR. */
+ as->curins--; /* Always skip the loword comparison. */
+ asm_comp64(as, ir);
+ return;
+ } else if ((ir-1)->o == IR_XSTORE) {
+ as->curins--; /* Handle both stores here. */
+ if ((ir-1)->r != RID_SINK) {
+ asm_xstore(as, ir, 0);
+ asm_xstore(as, ir-1, 4);
+ }
+ return;
+ }
+ if (!usehi) return; /* Skip unused hiword op for all remaining ops. */
+ switch ((ir-1)->o) {
+ case IR_ADD: as->curins--; asm_add64(as, ir); break;
+ case IR_SUB: as->curins--; asm_sub64(as, ir); break;
+ case IR_NEG: as->curins--; asm_neg64(as, ir); break;
+ case IR_CALLN:
+ case IR_CALLXS:
+ if (!uselo)
+ ra_allocref(as, ir->op1, RID2RSET(RID_RETLO)); /* Mark lo op as used. */
+ break;
+ case IR_CNEWI:
+ /* Nothing to do here. Handled by lo op itself. */
+ break;
+ default: lua_assert(0); break;
+ }
+#else
+ UNUSED(as); UNUSED(ir); lua_assert(0); /* Unused without FFI. */
+#endif
+}
+
+/* -- Stack handling ------------------------------------------------------ */
+
+/* Check Lua stack size for overflow. Use exit handler as fallback. */
+static void asm_stack_check(ASMState *as, BCReg topslot,
+ IRIns *irp, RegSet allow, ExitNo exitno)
+{
+ /* Try to get an unused temp. register, otherwise spill/restore RID_RET*. */
+ Reg tmp, pbase = irp ? (ra_hasreg(irp->r) ? irp->r : RID_TMP) : RID_BASE;
+ rset_clear(allow, pbase);
+ tmp = allow ? rset_pickbot(allow) :
+ (pbase == RID_RETHI ? RID_RETLO : RID_RETHI);
+ emit_condbranch(as, PPCI_BC, CC_LT, asm_exitstub_addr(as, exitno));
+ if (allow == RSET_EMPTY) /* Restore temp. register. */
+ emit_tai(as, PPCI_LWZ, tmp, RID_SP, SPOFS_TMPW);
+ else
+ ra_modified(as, tmp);
+ emit_ai(as, PPCI_CMPLWI, RID_TMP, (int32_t)(8*topslot));
+ emit_tab(as, PPCI_SUBF, RID_TMP, pbase, tmp);
+ emit_tai(as, PPCI_LWZ, tmp, tmp, offsetof(lua_State, maxstack));
+ if (pbase == RID_TMP)
+ emit_getgl(as, RID_TMP, jit_base);
+ emit_getgl(as, tmp, jit_L);
+ if (allow == RSET_EMPTY) /* Spill temp. register. */
+ emit_tai(as, PPCI_STW, tmp, RID_SP, SPOFS_TMPW);
+}
+
+/* Restore Lua stack from on-trace state. */
+static void asm_stack_restore(ASMState *as, SnapShot *snap)
+{
+ SnapEntry *map = &as->T->snapmap[snap->mapofs];
+ SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1];
+ MSize n, nent = snap->nent;
+ /* Store the value of all modified slots to the Lua stack. */
+ for (n = 0; n < nent; n++) {
+ SnapEntry sn = map[n];
+ BCReg s = snap_slot(sn);
+ int32_t ofs = 8*((int32_t)s-1);
+ IRRef ref = snap_ref(sn);
+ IRIns *ir = IR(ref);
+ if ((sn & SNAP_NORESTORE))
+ continue;
+ if (irt_isnum(ir->t)) {
+ Reg src = ra_alloc1(as, ref, RSET_FPR);
+ emit_fai(as, PPCI_STFD, src, RID_BASE, ofs);
+ } else {
+ Reg type;
+ RegSet allow = rset_exclude(RSET_GPR, RID_BASE);
+ lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t));
+ if (!irt_ispri(ir->t)) {
+ Reg src = ra_alloc1(as, ref, allow);
+ rset_clear(allow, src);
+ emit_tai(as, PPCI_STW, src, RID_BASE, ofs+4);
+ }
+ if ((sn & (SNAP_CONT|SNAP_FRAME))) {
+ if (s == 0) continue; /* Do not overwrite link to previous frame. */
+ type = ra_allock(as, (int32_t)(*flinks--), allow);
+ } else {
+ type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);
+ }
+ emit_tai(as, PPCI_STW, type, RID_BASE, ofs);
+ }
+ checkmclim(as);
+ }
+ lua_assert(map + nent == flinks);
+}
+
+/* -- GC handling --------------------------------------------------------- */
+
+/* Check GC threshold and do one or more GC steps. */
+static void asm_gc_check(ASMState *as)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit];
+ IRRef args[2];
+ MCLabel l_end;
+ Reg tmp;
+ ra_evictset(as, RSET_SCRATCH);
+ l_end = emit_label(as);
+ /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */
+ asm_guardcc(as, CC_NE); /* Assumes asm_snap_prep() already done. */
+ emit_ai(as, PPCI_CMPWI, RID_RET, 0);
+ args[0] = ASMREF_TMP1; /* global_State *g */
+ args[1] = ASMREF_TMP2; /* MSize steps */
+ asm_gencall(as, ci, args);
+ emit_tai(as, PPCI_ADDI, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768);
+ tmp = ra_releasetmp(as, ASMREF_TMP2);
+ emit_loadi(as, tmp, as->gcsteps);
+ /* Jump around GC step if GC total < GC threshold. */
+ emit_condbranch(as, PPCI_BC|PPCF_Y, CC_LT, l_end);
+ emit_ab(as, PPCI_CMPLW, RID_TMP, tmp);
+ emit_getgl(as, tmp, gc.threshold);
+ emit_getgl(as, RID_TMP, gc.total);
+ as->gcsteps = 0;
+ checkmclim(as);
+}
+
+/* -- Loop handling ------------------------------------------------------- */
+
+/* Fixup the loop branch. */
+static void asm_loop_fixup(ASMState *as)
+{
+ MCode *p = as->mctop;
+ MCode *target = as->mcp;
+ if (as->loopinv) { /* Inverted loop branch? */
+ /* asm_guardcc already inverted the cond branch and patched the final b. */
+ p[-2] = (p[-2] & (0xffff0000u & ~PPCF_Y)) | (((target-p+2) & 0x3fffu) << 2);
+ } else {
+ p[-1] = PPCI_B|(((target-p+1)&0x00ffffffu)<<2);
+ }
+}
+
+/* -- Head of trace ------------------------------------------------------- */
+
+/* Coalesce BASE register for a root trace. */
+static void asm_head_root_base(ASMState *as)
+{
+ IRIns *ir = IR(REF_BASE);
+ Reg r = ir->r;
+ if (ra_hasreg(r)) {
+ ra_free(as, r);
+ if (rset_test(as->modset, r) || irt_ismarked(ir->t))
+ ir->r = RID_INIT; /* No inheritance for modified BASE register. */
+ if (r != RID_BASE)
+ emit_mr(as, r, RID_BASE);
+ }
+}
+
+/* Coalesce BASE register for a side trace. */
+static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow)
+{
+ IRIns *ir = IR(REF_BASE);
+ Reg r = ir->r;
+ if (ra_hasreg(r)) {
+ ra_free(as, r);
+ if (rset_test(as->modset, r) || irt_ismarked(ir->t))
+ ir->r = RID_INIT; /* No inheritance for modified BASE register. */
+ if (irp->r == r) {
+ rset_clear(allow, r); /* Mark same BASE register as coalesced. */
+ } else if (ra_hasreg(irp->r) && rset_test(as->freeset, irp->r)) {
+ rset_clear(allow, irp->r);
+ emit_mr(as, r, irp->r); /* Move from coalesced parent reg. */
+ } else {
+ emit_getgl(as, r, jit_base); /* Otherwise reload BASE. */
+ }
+ }
+ return allow;
+}
+
+/* -- Tail of trace ------------------------------------------------------- */
+
+/* Fixup the tail code. */
+static void asm_tail_fixup(ASMState *as, TraceNo lnk)
+{
+ MCode *p = as->mctop;
+ MCode *target;
+ int32_t spadj = as->T->spadjust;
+ if (spadj == 0) {
+ *--p = PPCI_NOP;
+ *--p = PPCI_NOP;
+ as->mctop = p;
+ } else {
+ /* Patch stack adjustment. */
+ lua_assert(checki16(CFRAME_SIZE+spadj));
+ p[-3] = PPCI_ADDI | PPCF_T(RID_TMP) | PPCF_A(RID_SP) | (CFRAME_SIZE+spadj);
+ p[-2] = PPCI_STWU | PPCF_T(RID_TMP) | PPCF_A(RID_SP) | spadj;
+ }
+ /* Patch exit branch. */
+ target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp;
+ p[-1] = PPCI_B|(((target-p+1)&0x00ffffffu)<<2);
+}
+
+/* Prepare tail of code. */
+static void asm_tail_prep(ASMState *as)
+{
+ MCode *p = as->mctop - 1; /* Leave room for exit branch. */
+ if (as->loopref) {
+ as->invmcp = as->mcp = p;
+ } else {
+ as->mcp = p-2; /* Leave room for stack pointer adjustment. */
+ as->invmcp = NULL;
+ }
+}
+
+/* -- Instruction dispatch ------------------------------------------------ */
+
+/* Assemble a single instruction. */
+static void asm_ir(ASMState *as, IRIns *ir)
+{
+ switch ((IROp)ir->o) {
+ /* Miscellaneous ops. */
+ case IR_LOOP: asm_loop(as); break;
+ case IR_NOP: case IR_XBAR: lua_assert(!ra_used(ir)); break;
+ case IR_USE:
+ ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break;
+ case IR_PHI: asm_phi(as, ir); break;
+ case IR_HIOP: asm_hiop(as, ir); break;
+ case IR_GCSTEP: asm_gcstep(as, ir); break;
+
+ /* Guarded assertions. */
+ case IR_EQ: case IR_NE:
+ if ((ir-1)->o == IR_HREF && ir->op1 == as->curins-1) {
+ as->curins--;
+ asm_href(as, ir-1, (IROp)ir->o);
+ break;
+ }
+ /* fallthrough */
+ case IR_LT: case IR_GE: case IR_LE: case IR_GT:
+ case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT:
+ case IR_ABC:
+ asm_comp(as, ir);
+ break;
+
+ case IR_RETF: asm_retf(as, ir); break;
+
+ /* Bit ops. */
+ case IR_BNOT: asm_bitnot(as, ir); break;
+ case IR_BSWAP: asm_bitswap(as, ir); break;
+
+ case IR_BAND: asm_bitand(as, ir); break;
+ case IR_BOR: asm_bitop(as, ir, PPCI_OR, PPCI_ORI); break;
+ case IR_BXOR: asm_bitop(as, ir, PPCI_XOR, PPCI_XORI); break;
+
+ case IR_BSHL: asm_bitshift(as, ir, PPCI_SLW, 0); break;
+ case IR_BSHR: asm_bitshift(as, ir, PPCI_SRW, 1); break;
+ case IR_BSAR: asm_bitshift(as, ir, PPCI_SRAW, PPCI_SRAWI); break;
+ case IR_BROL: asm_bitshift(as, ir, PPCI_RLWNM|PPCF_MB(0)|PPCF_ME(31),
+ PPCI_RLWINM|PPCF_MB(0)|PPCF_ME(31)); break;
+ case IR_BROR: lua_assert(0); break;
+
+ /* Arithmetic ops. */
+ case IR_ADD: asm_add(as, ir); break;
+ case IR_SUB: asm_sub(as, ir); break;
+ case IR_MUL: asm_mul(as, ir); break;
+ case IR_DIV: asm_fparith(as, ir, PPCI_FDIV); break;
+ case IR_MOD: asm_callid(as, ir, IRCALL_lj_vm_modi); break;
+ case IR_POW: asm_callid(as, ir, IRCALL_lj_vm_powi); break;
+ case IR_NEG: asm_neg(as, ir); break;
+
+ case IR_ABS: asm_fpunary(as, ir, PPCI_FABS); break;
+ case IR_ATAN2: asm_callid(as, ir, IRCALL_atan2); break;
+ case IR_LDEXP: asm_callid(as, ir, IRCALL_ldexp); break;
+ case IR_MIN: asm_min_max(as, ir, 0); break;
+ case IR_MAX: asm_min_max(as, ir, 1); break;
+ case IR_FPMATH:
+ if (ir->op2 == IRFPM_EXP2 && asm_fpjoin_pow(as, ir))
+ break;
+ if (ir->op2 == IRFPM_SQRT && (as->flags & JIT_F_SQRT))
+ asm_fpunary(as, ir, PPCI_FSQRT);
+ else
+ asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2);
+ break;
+
+ /* Overflow-checking arithmetic ops. */
+ case IR_ADDOV: asm_arithov(as, ir, PPCI_ADDO); break;
+ case IR_SUBOV: asm_arithov(as, ir, PPCI_SUBFO); break;
+ case IR_MULOV: asm_arithov(as, ir, PPCI_MULLWO); break;
+
+ /* Memory references. */
+ case IR_AREF: asm_aref(as, ir); break;
+ case IR_HREF: asm_href(as, ir, 0); break;
+ case IR_HREFK: asm_hrefk(as, ir); break;
+ case IR_NEWREF: asm_newref(as, ir); break;
+ case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break;
+ case IR_FREF: asm_fref(as, ir); break;
+ case IR_STRREF: asm_strref(as, ir); break;
+
+ /* Loads and stores. */
+ case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:
+ asm_ahuvload(as, ir);
+ break;
+ case IR_FLOAD: asm_fload(as, ir); break;
+ case IR_XLOAD: asm_xload(as, ir); break;
+ case IR_SLOAD: asm_sload(as, ir); break;
+
+ case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break;
+ case IR_FSTORE: asm_fstore(as, ir); break;
+ case IR_XSTORE: asm_xstore(as, ir, 0); break;
+
+ /* Allocations. */
+ case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break;
+ case IR_TNEW: asm_tnew(as, ir); break;
+ case IR_TDUP: asm_tdup(as, ir); break;
+ case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break;
+
+ /* Write barriers. */
+ case IR_TBAR: asm_tbar(as, ir); break;
+ case IR_OBAR: asm_obar(as, ir); break;
+
+ /* Type conversions. */
+ case IR_CONV: asm_conv(as, ir); break;
+ case IR_TOBIT: asm_tobit(as, ir); break;
+ case IR_TOSTR: asm_tostr(as, ir); break;
+ case IR_STRTO: asm_strto(as, ir); break;
+
+ /* Calls. */
+ case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break;
+ case IR_CALLXS: asm_callx(as, ir); break;
+ case IR_CARG: break;
+
+ default:
+ setintV(&as->J->errinfo, ir->o);
+ lj_trace_err_info(as->J, LJ_TRERR_NYIIR);
+ break;
+ }
+}
+
+/* -- Trace setup --------------------------------------------------------- */
+
+/* Ensure there are enough stack slots for call arguments. */
+static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)
+{
+ IRRef args[CCI_NARGS_MAX*2];
+ uint32_t i, nargs = (int)CCI_NARGS(ci);
+ int nslots = 2, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR;
+ asm_collectargs(as, ir, ci, args);
+ for (i = 0; i < nargs; i++)
+ if (args[i] && irt_isfp(IR(args[i])->t)) {
+ if (nfpr > 0) nfpr--; else nslots = (nslots+3) & ~1;
+ } else {
+ if (ngpr > 0) ngpr--; else nslots++;
+ }
+ if (nslots > as->evenspill) /* Leave room for args in stack slots. */
+ as->evenspill = nslots;
+ return irt_isfp(ir->t) ? REGSP_HINT(RID_FPRET) : REGSP_HINT(RID_RET);
+}
+
+static void asm_setup_target(ASMState *as)
+{
+ asm_exitstub_setup(as, as->T->nsnap + (as->parent ? 1 : 0));
+}
+
+/* -- Trace patching ------------------------------------------------------ */
+
+/* Patch exit jumps of existing machine code to a new target. */
+void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target)
+{
+ MCode *p = T->mcode;
+ MCode *pe = (MCode *)((char *)p + T->szmcode);
+ MCode *px = exitstub_trace_addr(T, exitno);
+ MCode *cstart = NULL;
+ MCode *mcarea = lj_mcode_patch(J, p, 0);
+ int clearso = 0;
+ for (; p < pe; p++) {
+ /* Look for exitstub branch, try to replace with branch to target. */
+ uint32_t ins = *p;
+ if ((ins & 0xfc000000u) == 0x40000000u &&
+ ((ins ^ ((char *)px-(char *)p)) & 0xffffu) == 0) {
+ ptrdiff_t delta = (char *)target - (char *)p;
+ if (((ins >> 16) & 3) == (CC_SO&3)) {
+ clearso = sizeof(MCode);
+ delta -= sizeof(MCode);
+ }
+ /* Many, but not all short-range branches can be patched directly. */
+ if (((delta + 0x8000) >> 16) == 0) {
+ *p = (ins & 0xffdf0000u) | ((uint32_t)delta & 0xffffu) |
+ ((delta & 0x8000) * (PPCF_Y/0x8000));
+ if (!cstart) cstart = p;
+ }
+ } else if ((ins & 0xfc000000u) == PPCI_B &&
+ ((ins ^ ((char *)px-(char *)p)) & 0x03ffffffu) == 0) {
+ ptrdiff_t delta = (char *)target - (char *)p;
+ lua_assert(((delta + 0x02000000) >> 26) == 0);
+ *p = PPCI_B | ((uint32_t)delta & 0x03ffffffu);
+ if (!cstart) cstart = p;
+ }
+ }
+ { /* Always patch long-range branch in exit stub itself. */
+ ptrdiff_t delta = (char *)target - (char *)px - clearso;
+ lua_assert(((delta + 0x02000000) >> 26) == 0);
+ *px = PPCI_B | ((uint32_t)delta & 0x03ffffffu);
+ }
+ if (!cstart) cstart = px;
+ lj_mcode_sync(cstart, px+1);
+ if (clearso) { /* Extend the current trace. Ugly workaround. */
+ MCode *pp = J->cur.mcode;
+ J->cur.szmcode += sizeof(MCode);
+ *--pp = PPCI_MCRXR; /* Clear SO flag. */
+ J->cur.mcode = pp;
+ lj_mcode_sync(pp, pp+1);
+ }
+ lj_mcode_patch(J, mcarea, 1);
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm_x86.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm_x86.h
new file mode 100644
index 0000000..10468bb
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_asm_x86.h
@@ -0,0 +1,2900 @@
+/*
+** x86/x64 IR assembler (SSA IR -> machine code).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* -- Guard handling ------------------------------------------------------ */
+
+/* Generate an exit stub group at the bottom of the reserved MCode memory. */
+static MCode *asm_exitstub_gen(ASMState *as, ExitNo group)
+{
+ ExitNo i, groupofs = (group*EXITSTUBS_PER_GROUP) & 0xff;
+ MCode *mxp = as->mcbot;
+ MCode *mxpstart = mxp;
+ if (mxp + (2+2)*EXITSTUBS_PER_GROUP+8+5 >= as->mctop)
+ asm_mclimit(as);
+ /* Push low byte of exitno for each exit stub. */
+ *mxp++ = XI_PUSHi8; *mxp++ = (MCode)groupofs;
+ for (i = 1; i < EXITSTUBS_PER_GROUP; i++) {
+ *mxp++ = XI_JMPs; *mxp++ = (MCode)((2+2)*(EXITSTUBS_PER_GROUP - i) - 2);
+ *mxp++ = XI_PUSHi8; *mxp++ = (MCode)(groupofs + i);
+ }
+ /* Push the high byte of the exitno for each exit stub group. */
+ *mxp++ = XI_PUSHi8; *mxp++ = (MCode)((group*EXITSTUBS_PER_GROUP)>>8);
+ /* Store DISPATCH at original stack slot 0. Account for the two push ops. */
+ *mxp++ = XI_MOVmi;
+ *mxp++ = MODRM(XM_OFS8, 0, RID_ESP);
+ *mxp++ = MODRM(XM_SCALE1, RID_ESP, RID_ESP);
+ *mxp++ = 2*sizeof(void *);
+ *(int32_t *)mxp = ptr2addr(J2GG(as->J)->dispatch); mxp += 4;
+ /* Jump to exit handler which fills in the ExitState. */
+ *mxp++ = XI_JMP; mxp += 4;
+ *((int32_t *)(mxp-4)) = jmprel(mxp, (MCode *)(void *)lj_vm_exit_handler);
+ /* Commit the code for this group (even if assembly fails later on). */
+ lj_mcode_commitbot(as->J, mxp);
+ as->mcbot = mxp;
+ as->mclim = as->mcbot + MCLIM_REDZONE;
+ return mxpstart;
+}
+
+/* Setup all needed exit stubs. */
+static void asm_exitstub_setup(ASMState *as, ExitNo nexits)
+{
+ ExitNo i;
+ if (nexits >= EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR)
+ lj_trace_err(as->J, LJ_TRERR_SNAPOV);
+ for (i = 0; i < (nexits+EXITSTUBS_PER_GROUP-1)/EXITSTUBS_PER_GROUP; i++)
+ if (as->J->exitstubgroup[i] == NULL)
+ as->J->exitstubgroup[i] = asm_exitstub_gen(as, i);
+}
+
+/* Emit conditional branch to exit for guard.
+** It's important to emit this *after* all registers have been allocated,
+** because rematerializations may invalidate the flags.
+*/
+static void asm_guardcc(ASMState *as, int cc)
+{
+ MCode *target = exitstub_addr(as->J, as->snapno);
+ MCode *p = as->mcp;
+ if (LJ_UNLIKELY(p == as->invmcp)) {
+ as->loopinv = 1;
+ *(int32_t *)(p+1) = jmprel(p+5, target);
+ target = p;
+ cc ^= 1;
+ if (as->realign) {
+ emit_sjcc(as, cc, target);
+ return;
+ }
+ }
+ emit_jcc(as, cc, target);
+}
+
+/* -- Memory operand fusion ----------------------------------------------- */
+
+/* Limit linear search to this distance. Avoids O(n^2) behavior. */
+#define CONFLICT_SEARCH_LIM 31
+
+/* Check if a reference is a signed 32 bit constant. */
+static int asm_isk32(ASMState *as, IRRef ref, int32_t *k)
+{
+ if (irref_isk(ref)) {
+ IRIns *ir = IR(ref);
+ if (ir->o != IR_KINT64) {
+ *k = ir->i;
+ return 1;
+ } else if (checki32((int64_t)ir_kint64(ir)->u64)) {
+ *k = (int32_t)ir_kint64(ir)->u64;
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/* Check if there's no conflicting instruction between curins and ref.
+** Also avoid fusing loads if there are multiple references.
+*/
+static int noconflict(ASMState *as, IRRef ref, IROp conflict, int noload)
+{
+ IRIns *ir = as->ir;
+ IRRef i = as->curins;
+ if (i > ref + CONFLICT_SEARCH_LIM)
+ return 0; /* Give up, ref is too far away. */
+ while (--i > ref) {
+ if (ir[i].o == conflict)
+ return 0; /* Conflict found. */
+ else if (!noload && (ir[i].op1 == ref || ir[i].op2 == ref))
+ return 0;
+ }
+ return 1; /* Ok, no conflict. */
+}
+
+/* Fuse array base into memory operand. */
+static IRRef asm_fuseabase(ASMState *as, IRRef ref)
+{
+ IRIns *irb = IR(ref);
+ as->mrm.ofs = 0;
+ if (irb->o == IR_FLOAD) {
+ IRIns *ira = IR(irb->op1);
+ lua_assert(irb->op2 == IRFL_TAB_ARRAY);
+ /* We can avoid the FLOAD of t->array for colocated arrays. */
+ if (ira->o == IR_TNEW && ira->op1 <= LJ_MAX_COLOSIZE &&
+ !neverfuse(as) && noconflict(as, irb->op1, IR_NEWREF, 1)) {
+ as->mrm.ofs = (int32_t)sizeof(GCtab); /* Ofs to colocated array. */
+ return irb->op1; /* Table obj. */
+ }
+ } else if (irb->o == IR_ADD && irref_isk(irb->op2)) {
+ /* Fuse base offset (vararg load). */
+ as->mrm.ofs = IR(irb->op2)->i;
+ return irb->op1;
+ }
+ return ref; /* Otherwise use the given array base. */
+}
+
+/* Fuse array reference into memory operand. */
+static void asm_fusearef(ASMState *as, IRIns *ir, RegSet allow)
+{
+ IRIns *irx;
+ lua_assert(ir->o == IR_AREF);
+ as->mrm.base = (uint8_t)ra_alloc1(as, asm_fuseabase(as, ir->op1), allow);
+ irx = IR(ir->op2);
+ if (irref_isk(ir->op2)) {
+ as->mrm.ofs += 8*irx->i;
+ as->mrm.idx = RID_NONE;
+ } else {
+ rset_clear(allow, as->mrm.base);
+ as->mrm.scale = XM_SCALE8;
+ /* Fuse a constant ADD (e.g. t[i+1]) into the offset.
+ ** Doesn't help much without ABCelim, but reduces register pressure.
+ */
+ if (!LJ_64 && /* Has bad effects with negative index on x64. */
+ mayfuse(as, ir->op2) && ra_noreg(irx->r) &&
+ irx->o == IR_ADD && irref_isk(irx->op2)) {
+ as->mrm.ofs += 8*IR(irx->op2)->i;
+ as->mrm.idx = (uint8_t)ra_alloc1(as, irx->op1, allow);
+ } else {
+ as->mrm.idx = (uint8_t)ra_alloc1(as, ir->op2, allow);
+ }
+ }
+}
+
+/* Fuse array/hash/upvalue reference into memory operand.
+** Caveat: this may allocate GPRs for the base/idx registers. Be sure to
+** pass the final allow mask, excluding any GPRs used for other inputs.
+** In particular: 2-operand GPR instructions need to call ra_dest() first!
+*/
+static void asm_fuseahuref(ASMState *as, IRRef ref, RegSet allow)
+{
+ IRIns *ir = IR(ref);
+ if (ra_noreg(ir->r)) {
+ switch ((IROp)ir->o) {
+ case IR_AREF:
+ if (mayfuse(as, ref)) {
+ asm_fusearef(as, ir, allow);
+ return;
+ }
+ break;
+ case IR_HREFK:
+ if (mayfuse(as, ref)) {
+ as->mrm.base = (uint8_t)ra_alloc1(as, ir->op1, allow);
+ as->mrm.ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node));
+ as->mrm.idx = RID_NONE;
+ return;
+ }
+ break;
+ case IR_UREFC:
+ if (irref_isk(ir->op1)) {
+ GCfunc *fn = ir_kfunc(IR(ir->op1));
+ GCupval *uv = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv;
+ as->mrm.ofs = ptr2addr(&uv->tv);
+ as->mrm.base = as->mrm.idx = RID_NONE;
+ return;
+ }
+ break;
+ default:
+ lua_assert(ir->o == IR_HREF || ir->o == IR_NEWREF || ir->o == IR_UREFO ||
+ ir->o == IR_KKPTR);
+ break;
+ }
+ }
+ as->mrm.base = (uint8_t)ra_alloc1(as, ref, allow);
+ as->mrm.ofs = 0;
+ as->mrm.idx = RID_NONE;
+}
+
+/* Fuse FLOAD/FREF reference into memory operand. */
+static void asm_fusefref(ASMState *as, IRIns *ir, RegSet allow)
+{
+ lua_assert(ir->o == IR_FLOAD || ir->o == IR_FREF);
+ as->mrm.ofs = field_ofs[ir->op2];
+ as->mrm.idx = RID_NONE;
+ if (irref_isk(ir->op1)) {
+ as->mrm.ofs += IR(ir->op1)->i;
+ as->mrm.base = RID_NONE;
+ } else {
+ as->mrm.base = (uint8_t)ra_alloc1(as, ir->op1, allow);
+ }
+}
+
+/* Fuse string reference into memory operand. */
+static void asm_fusestrref(ASMState *as, IRIns *ir, RegSet allow)
+{
+ IRIns *irr;
+ lua_assert(ir->o == IR_STRREF);
+ as->mrm.base = as->mrm.idx = RID_NONE;
+ as->mrm.scale = XM_SCALE1;
+ as->mrm.ofs = sizeof(GCstr);
+ if (irref_isk(ir->op1)) {
+ as->mrm.ofs += IR(ir->op1)->i;
+ } else {
+ Reg r = ra_alloc1(as, ir->op1, allow);
+ rset_clear(allow, r);
+ as->mrm.base = (uint8_t)r;
+ }
+ irr = IR(ir->op2);
+ if (irref_isk(ir->op2)) {
+ as->mrm.ofs += irr->i;
+ } else {
+ Reg r;
+ /* Fuse a constant add into the offset, e.g. string.sub(s, i+10). */
+ if (!LJ_64 && /* Has bad effects with negative index on x64. */
+ mayfuse(as, ir->op2) && irr->o == IR_ADD && irref_isk(irr->op2)) {
+ as->mrm.ofs += IR(irr->op2)->i;
+ r = ra_alloc1(as, irr->op1, allow);
+ } else {
+ r = ra_alloc1(as, ir->op2, allow);
+ }
+ if (as->mrm.base == RID_NONE)
+ as->mrm.base = (uint8_t)r;
+ else
+ as->mrm.idx = (uint8_t)r;
+ }
+}
+
+static void asm_fusexref(ASMState *as, IRRef ref, RegSet allow)
+{
+ IRIns *ir = IR(ref);
+ as->mrm.idx = RID_NONE;
+ if (ir->o == IR_KPTR || ir->o == IR_KKPTR) {
+ as->mrm.ofs = ir->i;
+ as->mrm.base = RID_NONE;
+ } else if (ir->o == IR_STRREF) {
+ asm_fusestrref(as, ir, allow);
+ } else {
+ as->mrm.ofs = 0;
+ if (canfuse(as, ir) && ir->o == IR_ADD && ra_noreg(ir->r)) {
+ /* Gather (base+idx*sz)+ofs as emitted by cdata ptr/array indexing. */
+ IRIns *irx;
+ IRRef idx;
+ Reg r;
+ if (asm_isk32(as, ir->op2, &as->mrm.ofs)) { /* Recognize x+ofs. */
+ ref = ir->op1;
+ ir = IR(ref);
+ if (!(ir->o == IR_ADD && canfuse(as, ir) && ra_noreg(ir->r)))
+ goto noadd;
+ }
+ as->mrm.scale = XM_SCALE1;
+ idx = ir->op1;
+ ref = ir->op2;
+ irx = IR(idx);
+ if (!(irx->o == IR_BSHL || irx->o == IR_ADD)) { /* Try other operand. */
+ idx = ir->op2;
+ ref = ir->op1;
+ irx = IR(idx);
+ }
+ if (canfuse(as, irx) && ra_noreg(irx->r)) {
+ if (irx->o == IR_BSHL && irref_isk(irx->op2) && IR(irx->op2)->i <= 3) {
+ /* Recognize idx<<b with b = 0-3, corresponding to sz = (1),2,4,8. */
+ idx = irx->op1;
+ as->mrm.scale = (uint8_t)(IR(irx->op2)->i << 6);
+ } else if (irx->o == IR_ADD && irx->op1 == irx->op2) {
+ /* FOLD does idx*2 ==> idx<<1 ==> idx+idx. */
+ idx = irx->op1;
+ as->mrm.scale = XM_SCALE2;
+ }
+ }
+ r = ra_alloc1(as, idx, allow);
+ rset_clear(allow, r);
+ as->mrm.idx = (uint8_t)r;
+ }
+ noadd:
+ as->mrm.base = (uint8_t)ra_alloc1(as, ref, allow);
+ }
+}
+
+/* Fuse load into memory operand. */
+static Reg asm_fuseload(ASMState *as, IRRef ref, RegSet allow)
+{
+ IRIns *ir = IR(ref);
+ if (ra_hasreg(ir->r)) {
+ if (allow != RSET_EMPTY) { /* Fast path. */
+ ra_noweak(as, ir->r);
+ return ir->r;
+ }
+ fusespill:
+ /* Force a spill if only memory operands are allowed (asm_x87load). */
+ as->mrm.base = RID_ESP;
+ as->mrm.ofs = ra_spill(as, ir);
+ as->mrm.idx = RID_NONE;
+ return RID_MRM;
+ }
+ if (ir->o == IR_KNUM) {
+ RegSet avail = as->freeset & ~as->modset & RSET_FPR;
+ lua_assert(allow != RSET_EMPTY);
+ if (!(avail & (avail-1))) { /* Fuse if less than two regs available. */
+ as->mrm.ofs = ptr2addr(ir_knum(ir));
+ as->mrm.base = as->mrm.idx = RID_NONE;
+ return RID_MRM;
+ }
+ } else if (ref == REF_BASE || ir->o == IR_KINT64) {
+ RegSet avail = as->freeset & ~as->modset & RSET_GPR;
+ lua_assert(allow != RSET_EMPTY);
+ if (!(avail & (avail-1))) { /* Fuse if less than two regs available. */
+ as->mrm.ofs = ptr2addr(ref == REF_BASE ? (void *)&J2G(as->J)->jit_base : (void *)ir_kint64(ir));
+ as->mrm.base = as->mrm.idx = RID_NONE;
+ return RID_MRM;
+ }
+ } else if (mayfuse(as, ref)) {
+ RegSet xallow = (allow & RSET_GPR) ? allow : RSET_GPR;
+ if (ir->o == IR_SLOAD) {
+ if (!(ir->op2 & (IRSLOAD_PARENT|IRSLOAD_CONVERT)) &&
+ noconflict(as, ref, IR_RETF, 0)) {
+ as->mrm.base = (uint8_t)ra_alloc1(as, REF_BASE, xallow);
+ as->mrm.ofs = 8*((int32_t)ir->op1-1) + ((ir->op2&IRSLOAD_FRAME)?4:0);
+ as->mrm.idx = RID_NONE;
+ return RID_MRM;
+ }
+ } else if (ir->o == IR_FLOAD) {
+ /* Generic fusion is only ok for 32 bit operand (but see asm_comp). */
+ if ((irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t)) &&
+ noconflict(as, ref, IR_FSTORE, 0)) {
+ asm_fusefref(as, ir, xallow);
+ return RID_MRM;
+ }
+ } else if (ir->o == IR_ALOAD || ir->o == IR_HLOAD || ir->o == IR_ULOAD) {
+ if (noconflict(as, ref, ir->o + IRDELTA_L2S, 0)) {
+ asm_fuseahuref(as, ir->op1, xallow);
+ return RID_MRM;
+ }
+ } else if (ir->o == IR_XLOAD) {
+ /* Generic fusion is not ok for 8/16 bit operands (but see asm_comp).
+ ** Fusing unaligned memory operands is ok on x86 (except for SIMD types).
+ */
+ if ((!irt_typerange(ir->t, IRT_I8, IRT_U16)) &&
+ noconflict(as, ref, IR_XSTORE, 0)) {
+ asm_fusexref(as, ir->op1, xallow);
+ return RID_MRM;
+ }
+ } else if (ir->o == IR_VLOAD) {
+ asm_fuseahuref(as, ir->op1, xallow);
+ return RID_MRM;
+ }
+ }
+ if (!(as->freeset & allow) && !emit_canremat(ref) &&
+ (allow == RSET_EMPTY || ra_hasspill(ir->s) || iscrossref(as, ref)))
+ goto fusespill;
+ return ra_allocref(as, ref, allow);
+}
+
+#if LJ_64
+/* Don't fuse a 32 bit load into a 64 bit operation. */
+static Reg asm_fuseloadm(ASMState *as, IRRef ref, RegSet allow, int is64)
+{
+ if (is64 && !irt_is64(IR(ref)->t))
+ return ra_alloc1(as, ref, allow);
+ return asm_fuseload(as, ref, allow);
+}
+#else
+#define asm_fuseloadm(as, ref, allow, is64) asm_fuseload(as, (ref), (allow))
+#endif
+
+/* -- Calls --------------------------------------------------------------- */
+
+/* Count the required number of stack slots for a call. */
+static int asm_count_call_slots(ASMState *as, const CCallInfo *ci, IRRef *args)
+{
+ uint32_t i, nargs = CCI_NARGS(ci);
+ int nslots = 0;
+#if LJ_64
+ if (LJ_ABI_WIN) {
+ nslots = (int)(nargs*2); /* Only matters for more than four args. */
+ } else {
+ int ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR;
+ for (i = 0; i < nargs; i++)
+ if (args[i] && irt_isfp(IR(args[i])->t)) {
+ if (nfpr > 0) nfpr--; else nslots += 2;
+ } else {
+ if (ngpr > 0) ngpr--; else nslots += 2;
+ }
+ }
+#else
+ int ngpr = 0;
+ if ((ci->flags & CCI_CC_MASK) == CCI_CC_FASTCALL)
+ ngpr = 2;
+ else if ((ci->flags & CCI_CC_MASK) == CCI_CC_THISCALL)
+ ngpr = 1;
+ for (i = 0; i < nargs; i++)
+ if (args[i] && irt_isfp(IR(args[i])->t)) {
+ nslots += irt_isnum(IR(args[i])->t) ? 2 : 1;
+ } else {
+ if (ngpr > 0) ngpr--; else nslots++;
+ }
+#endif
+ return nslots;
+}
+
+/* Generate a call to a C function. */
+static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)
+{
+ uint32_t n, nargs = CCI_NARGS(ci);
+ int32_t ofs = STACKARG_OFS;
+#if LJ_64
+ uint32_t gprs = REGARG_GPRS;
+ Reg fpr = REGARG_FIRSTFPR;
+#if !LJ_ABI_WIN
+ MCode *patchnfpr = NULL;
+#endif
+#else
+ uint32_t gprs = 0;
+ if ((ci->flags & CCI_CC_MASK) != CCI_CC_CDECL) {
+ if ((ci->flags & CCI_CC_MASK) == CCI_CC_THISCALL)
+ gprs = (REGARG_GPRS & 31);
+ else if ((ci->flags & CCI_CC_MASK) == CCI_CC_FASTCALL)
+ gprs = REGARG_GPRS;
+ }
+#endif
+ if ((void *)ci->func)
+ emit_call(as, ci->func);
+#if LJ_64
+ if ((ci->flags & CCI_VARARG)) { /* Special handling for vararg calls. */
+#if LJ_ABI_WIN
+ for (n = 0; n < 4 && n < nargs; n++) {
+ IRIns *ir = IR(args[n]);
+ if (irt_isfp(ir->t)) /* Duplicate FPRs in GPRs. */
+ emit_rr(as, XO_MOVDto, (irt_isnum(ir->t) ? REX_64 : 0) | (fpr+n),
+ ((gprs >> (n*5)) & 31)); /* Either MOVD or MOVQ. */
+ }
+#else
+ patchnfpr = --as->mcp; /* Indicate number of used FPRs in register al. */
+ *--as->mcp = XI_MOVrib | RID_EAX;
+#endif
+ }
+#endif
+ for (n = 0; n < nargs; n++) { /* Setup args. */
+ IRRef ref = args[n];
+ IRIns *ir = IR(ref);
+ Reg r;
+#if LJ_64 && LJ_ABI_WIN
+ /* Windows/x64 argument registers are strictly positional. */
+ r = irt_isfp(ir->t) ? (fpr <= REGARG_LASTFPR ? fpr : 0) : (gprs & 31);
+ fpr++; gprs >>= 5;
+#elif LJ_64
+ /* POSIX/x64 argument registers are used in order of appearance. */
+ if (irt_isfp(ir->t)) {
+ r = fpr <= REGARG_LASTFPR ? fpr++ : 0;
+ } else {
+ r = gprs & 31; gprs >>= 5;
+ }
+#else
+ if (ref && irt_isfp(ir->t)) {
+ r = 0;
+ } else {
+ r = gprs & 31; gprs >>= 5;
+ if (!ref) continue;
+ }
+#endif
+ if (r) { /* Argument is in a register. */
+ if (r < RID_MAX_GPR && ref < ASMREF_TMP1) {
+#if LJ_64
+ if (ir->o == IR_KINT64)
+ emit_loadu64(as, r, ir_kint64(ir)->u64);
+ else
+#endif
+ emit_loadi(as, r, ir->i);
+ } else {
+ lua_assert(rset_test(as->freeset, r)); /* Must have been evicted. */
+ if (ra_hasreg(ir->r)) {
+ ra_noweak(as, ir->r);
+ emit_movrr(as, ir, r, ir->r);
+ } else {
+ ra_allocref(as, ref, RID2RSET(r));
+ }
+ }
+ } else if (irt_isfp(ir->t)) { /* FP argument is on stack. */
+ lua_assert(!(irt_isfloat(ir->t) && irref_isk(ref))); /* No float k. */
+ if (LJ_32 && (ofs & 4) && irref_isk(ref)) {
+ /* Split stores for unaligned FP consts. */
+ emit_movmroi(as, RID_ESP, ofs, (int32_t)ir_knum(ir)->u32.lo);
+ emit_movmroi(as, RID_ESP, ofs+4, (int32_t)ir_knum(ir)->u32.hi);
+ } else {
+ r = ra_alloc1(as, ref, RSET_FPR);
+ emit_rmro(as, irt_isnum(ir->t) ? XO_MOVSDto : XO_MOVSSto,
+ r, RID_ESP, ofs);
+ }
+ ofs += (LJ_32 && irt_isfloat(ir->t)) ? 4 : 8;
+ } else { /* Non-FP argument is on stack. */
+ if (LJ_32 && ref < ASMREF_TMP1) {
+ emit_movmroi(as, RID_ESP, ofs, ir->i);
+ } else {
+ r = ra_alloc1(as, ref, RSET_GPR);
+ emit_movtomro(as, REX_64 + r, RID_ESP, ofs);
+ }
+ ofs += sizeof(intptr_t);
+ }
+ checkmclim(as);
+ }
+#if LJ_64 && !LJ_ABI_WIN
+ if (patchnfpr) *patchnfpr = fpr - REGARG_FIRSTFPR;
+#endif
+}
+
+/* Setup result reg/sp for call. Evict scratch regs. */
+static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci)
+{
+ RegSet drop = RSET_SCRATCH;
+ int hiop = (LJ_32 && (ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t));
+ if ((ci->flags & CCI_NOFPRCLOBBER))
+ drop &= ~RSET_FPR;
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ if (hiop && ra_hasreg((ir+1)->r))
+ rset_clear(drop, (ir+1)->r); /* Dest reg handled below. */
+ ra_evictset(as, drop); /* Evictions must be performed first. */
+ if (ra_used(ir)) {
+ if (irt_isfp(ir->t)) {
+ int32_t ofs = sps_scale(ir->s); /* Use spill slot or temp slots. */
+#if LJ_64
+ if ((ci->flags & CCI_CASTU64)) {
+ Reg dest = ir->r;
+ if (ra_hasreg(dest)) {
+ ra_free(as, dest);
+ ra_modified(as, dest);
+ emit_rr(as, XO_MOVD, dest|REX_64, RID_RET); /* Really MOVQ. */
+ }
+ if (ofs) emit_movtomro(as, RID_RET|REX_64, RID_ESP, ofs);
+ } else {
+ ra_destreg(as, ir, RID_FPRET);
+ }
+#else
+ /* Number result is in x87 st0 for x86 calling convention. */
+ Reg dest = ir->r;
+ if (ra_hasreg(dest)) {
+ ra_free(as, dest);
+ ra_modified(as, dest);
+ emit_rmro(as, irt_isnum(ir->t) ? XMM_MOVRM(as) : XO_MOVSS,
+ dest, RID_ESP, ofs);
+ }
+ if ((ci->flags & CCI_CASTU64)) {
+ emit_movtomro(as, RID_RETLO, RID_ESP, ofs);
+ emit_movtomro(as, RID_RETHI, RID_ESP, ofs+4);
+ } else {
+ emit_rmro(as, irt_isnum(ir->t) ? XO_FSTPq : XO_FSTPd,
+ irt_isnum(ir->t) ? XOg_FSTPq : XOg_FSTPd, RID_ESP, ofs);
+ }
+#endif
+#if LJ_32
+ } else if (hiop) {
+ ra_destpair(as, ir);
+#endif
+ } else {
+ lua_assert(!irt_ispri(ir->t));
+ ra_destreg(as, ir, RID_RET);
+ }
+ } else if (LJ_32 && irt_isfp(ir->t) && !(ci->flags & CCI_CASTU64)) {
+ emit_x87op(as, XI_FPOP); /* Pop unused result from x87 st0. */
+ }
+}
+
+static void asm_call(ASMState *as, IRIns *ir)
+{
+ IRRef args[CCI_NARGS_MAX];
+ const CCallInfo *ci = &lj_ir_callinfo[ir->op2];
+ asm_collectargs(as, ir, ci, args);
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+
+/* Return a constant function pointer or NULL for indirect calls. */
+static void *asm_callx_func(ASMState *as, IRIns *irf, IRRef func)
+{
+#if LJ_32
+ UNUSED(as);
+ if (irref_isk(func))
+ return (void *)irf->i;
+#else
+ if (irref_isk(func)) {
+ MCode *p;
+ if (irf->o == IR_KINT64)
+ p = (MCode *)(void *)ir_k64(irf)->u64;
+ else
+ p = (MCode *)(void *)(uintptr_t)(uint32_t)irf->i;
+ if (p - as->mcp == (int32_t)(p - as->mcp))
+ return p; /* Call target is still in +-2GB range. */
+ /* Avoid the indirect case of emit_call(). Try to hoist func addr. */
+ }
+#endif
+ return NULL;
+}
+
+static void asm_callx(ASMState *as, IRIns *ir)
+{
+ IRRef args[CCI_NARGS_MAX*2];
+ CCallInfo ci;
+ IRRef func;
+ IRIns *irf;
+ int32_t spadj = 0;
+ ci.flags = asm_callx_flags(as, ir);
+ asm_collectargs(as, ir, &ci, args);
+ asm_setupresult(as, ir, &ci);
+#if LJ_32
+ /* Have to readjust stack after non-cdecl calls due to callee cleanup. */
+ if ((ci.flags & CCI_CC_MASK) != CCI_CC_CDECL)
+ spadj = 4 * asm_count_call_slots(as, &ci, args);
+#endif
+ func = ir->op2; irf = IR(func);
+ if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }
+ ci.func = (ASMFunction)asm_callx_func(as, irf, func);
+ if (!(void *)ci.func) {
+ /* Use a (hoistable) non-scratch register for indirect calls. */
+ RegSet allow = (RSET_GPR & ~RSET_SCRATCH);
+ Reg r = ra_alloc1(as, func, allow);
+ if (LJ_32) emit_spsub(as, spadj); /* Above code may cause restores! */
+ emit_rr(as, XO_GROUP5, XOg_CALL, r);
+ } else if (LJ_32) {
+ emit_spsub(as, spadj);
+ }
+ asm_gencall(as, &ci, args);
+}
+
+/* -- Returns ------------------------------------------------------------- */
+
+/* Return to lower frame. Guard that it goes to the right spot. */
+static void asm_retf(ASMState *as, IRIns *ir)
+{
+ Reg base = ra_alloc1(as, REF_BASE, RSET_GPR);
+ void *pc = ir_kptr(IR(ir->op2));
+ int32_t delta = 1+bc_a(*((const BCIns *)pc - 1));
+ as->topslot -= (BCReg)delta;
+ if ((int32_t)as->topslot < 0) as->topslot = 0;
+ irt_setmark(IR(REF_BASE)->t); /* Children must not coalesce with BASE reg. */
+ emit_setgl(as, base, jit_base);
+ emit_addptr(as, base, -8*delta);
+ asm_guardcc(as, CC_NE);
+ emit_gmroi(as, XG_ARITHi(XOg_CMP), base, -4, ptr2addr(pc));
+}
+
+/* -- Type conversions ---------------------------------------------------- */
+
+static void asm_tointg(ASMState *as, IRIns *ir, Reg left)
+{
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ asm_guardcc(as, CC_P);
+ asm_guardcc(as, CC_NE);
+ emit_rr(as, XO_UCOMISD, left, tmp);
+ emit_rr(as, XO_CVTSI2SD, tmp, dest);
+ if (!(as->flags & JIT_F_SPLIT_XMM))
+ emit_rr(as, XO_XORPS, tmp, tmp); /* Avoid partial register stall. */
+ emit_rr(as, XO_CVTTSD2SI, dest, left);
+ /* Can't fuse since left is needed twice. */
+}
+
+static void asm_tobit(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg tmp = ra_noreg(IR(ir->op1)->r) ?
+ ra_alloc1(as, ir->op1, RSET_FPR) :
+ ra_scratch(as, RSET_FPR);
+ Reg right = asm_fuseload(as, ir->op2, rset_exclude(RSET_FPR, tmp));
+ emit_rr(as, XO_MOVDto, tmp, dest);
+ emit_mrm(as, XO_ADDSD, tmp, right);
+ ra_left(as, tmp, ir->op1);
+}
+
+static void asm_conv(ASMState *as, IRIns *ir)
+{
+ IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);
+ int st64 = (st == IRT_I64 || st == IRT_U64 || (LJ_64 && st == IRT_P64));
+ int stfp = (st == IRT_NUM || st == IRT_FLOAT);
+ IRRef lref = ir->op1;
+ lua_assert(irt_type(ir->t) != st);
+ lua_assert(!(LJ_32 && (irt_isint64(ir->t) || st64))); /* Handled by SPLIT. */
+ if (irt_isfp(ir->t)) {
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ if (stfp) { /* FP to FP conversion. */
+ Reg left = asm_fuseload(as, lref, RSET_FPR);
+ emit_mrm(as, st == IRT_NUM ? XO_CVTSD2SS : XO_CVTSS2SD, dest, left);
+ if (left == dest) return; /* Avoid the XO_XORPS. */
+ } else if (LJ_32 && st == IRT_U32) { /* U32 to FP conversion on x86. */
+ /* number = (2^52+2^51 .. u32) - (2^52+2^51) */
+ cTValue *k = lj_ir_k64_find(as->J, U64x(43380000,00000000));
+ Reg bias = ra_scratch(as, rset_exclude(RSET_FPR, dest));
+ if (irt_isfloat(ir->t))
+ emit_rr(as, XO_CVTSD2SS, dest, dest);
+ emit_rr(as, XO_SUBSD, dest, bias); /* Subtract 2^52+2^51 bias. */
+ emit_rr(as, XO_XORPS, dest, bias); /* Merge bias and integer. */
+ emit_loadn(as, bias, k);
+ emit_mrm(as, XO_MOVD, dest, asm_fuseload(as, lref, RSET_GPR));
+ return;
+ } else { /* Integer to FP conversion. */
+ Reg left = (LJ_64 && (st == IRT_U32 || st == IRT_U64)) ?
+ ra_alloc1(as, lref, RSET_GPR) :
+ asm_fuseloadm(as, lref, RSET_GPR, st64);
+ if (LJ_64 && st == IRT_U64) {
+ MCLabel l_end = emit_label(as);
+ const void *k = lj_ir_k64_find(as->J, U64x(43f00000,00000000));
+ emit_rma(as, XO_ADDSD, dest, k); /* Add 2^64 to compensate. */
+ emit_sjcc(as, CC_NS, l_end);
+ emit_rr(as, XO_TEST, left|REX_64, left); /* Check if u64 >= 2^63. */
+ }
+ emit_mrm(as, irt_isnum(ir->t) ? XO_CVTSI2SD : XO_CVTSI2SS,
+ dest|((LJ_64 && (st64 || st == IRT_U32)) ? REX_64 : 0), left);
+ }
+ if (!(as->flags & JIT_F_SPLIT_XMM))
+ emit_rr(as, XO_XORPS, dest, dest); /* Avoid partial register stall. */
+ } else if (stfp) { /* FP to integer conversion. */
+ if (irt_isguard(ir->t)) {
+ /* Checked conversions are only supported from number to int. */
+ lua_assert(irt_isint(ir->t) && st == IRT_NUM);
+ asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR));
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ x86Op op = st == IRT_NUM ?
+ ((ir->op2 & IRCONV_TRUNC) ? XO_CVTTSD2SI : XO_CVTSD2SI) :
+ ((ir->op2 & IRCONV_TRUNC) ? XO_CVTTSS2SI : XO_CVTSS2SI);
+ if (LJ_64 ? irt_isu64(ir->t) : irt_isu32(ir->t)) {
+ /* LJ_64: For inputs >= 2^63 add -2^64, convert again. */
+ /* LJ_32: For inputs >= 2^31 add -2^31, convert again and add 2^31. */
+ Reg tmp = ra_noreg(IR(lref)->r) ? ra_alloc1(as, lref, RSET_FPR) :
+ ra_scratch(as, RSET_FPR);
+ MCLabel l_end = emit_label(as);
+ if (LJ_32)
+ emit_gri(as, XG_ARITHi(XOg_ADD), dest, (int32_t)0x80000000);
+ emit_rr(as, op, dest|REX_64, tmp);
+ if (st == IRT_NUM)
+ emit_rma(as, XO_ADDSD, tmp, lj_ir_k64_find(as->J,
+ LJ_64 ? U64x(c3f00000,00000000) : U64x(c1e00000,00000000)));
+ else
+ emit_rma(as, XO_ADDSS, tmp, lj_ir_k64_find(as->J,
+ LJ_64 ? U64x(00000000,df800000) : U64x(00000000,cf000000)));
+ emit_sjcc(as, CC_NS, l_end);
+ emit_rr(as, XO_TEST, dest|REX_64, dest); /* Check if dest negative. */
+ emit_rr(as, op, dest|REX_64, tmp);
+ ra_left(as, tmp, lref);
+ } else {
+ Reg left = asm_fuseload(as, lref, RSET_FPR);
+ if (LJ_64 && irt_isu32(ir->t))
+ emit_rr(as, XO_MOV, dest, dest); /* Zero hiword. */
+ emit_mrm(as, op,
+ dest|((LJ_64 &&
+ (irt_is64(ir->t) || irt_isu32(ir->t))) ? REX_64 : 0),
+ left);
+ }
+ }
+ } else if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */
+ Reg left, dest = ra_dest(as, ir, RSET_GPR);
+ RegSet allow = RSET_GPR;
+ x86Op op;
+ lua_assert(irt_isint(ir->t) || irt_isu32(ir->t));
+ if (st == IRT_I8) {
+ op = XO_MOVSXb; allow = RSET_GPR8; dest |= FORCE_REX;
+ } else if (st == IRT_U8) {
+ op = XO_MOVZXb; allow = RSET_GPR8; dest |= FORCE_REX;
+ } else if (st == IRT_I16) {
+ op = XO_MOVSXw;
+ } else {
+ op = XO_MOVZXw;
+ }
+ left = asm_fuseload(as, lref, allow);
+ /* Add extra MOV if source is already in wrong register. */
+ if (!LJ_64 && left != RID_MRM && !rset_test(allow, left)) {
+ Reg tmp = ra_scratch(as, allow);
+ emit_rr(as, op, dest, tmp);
+ emit_rr(as, XO_MOV, tmp, left);
+ } else {
+ emit_mrm(as, op, dest, left);
+ }
+ } else { /* 32/64 bit integer conversions. */
+ if (LJ_32) { /* Only need to handle 32/32 bit no-op (cast) on x86. */
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ ra_left(as, dest, lref); /* Do nothing, but may need to move regs. */
+ } else if (irt_is64(ir->t)) {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (st64 || !(ir->op2 & IRCONV_SEXT)) {
+ /* 64/64 bit no-op (cast) or 32 to 64 bit zero extension. */
+ ra_left(as, dest, lref); /* Do nothing, but may need to move regs. */
+ } else { /* 32 to 64 bit sign extension. */
+ Reg left = asm_fuseload(as, lref, RSET_GPR);
+ emit_mrm(as, XO_MOVSXd, dest|REX_64, left);
+ }
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (st64) {
+ Reg left = asm_fuseload(as, lref, RSET_GPR);
+ /* This is either a 32 bit reg/reg mov which zeroes the hiword
+ ** or a load of the loword from a 64 bit address.
+ */
+ emit_mrm(as, XO_MOV, dest, left);
+ } else { /* 32/32 bit no-op (cast). */
+ ra_left(as, dest, lref); /* Do nothing, but may need to move regs. */
+ }
+ }
+ }
+}
+
+#if LJ_32 && LJ_HASFFI
+/* No SSE conversions to/from 64 bit on x86, so resort to ugly x87 code. */
+
+/* 64 bit integer to FP conversion in 32 bit mode. */
+static void asm_conv_fp_int64(ASMState *as, IRIns *ir)
+{
+ Reg hi = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg lo = ra_alloc1(as, (ir-1)->op1, rset_exclude(RSET_GPR, hi));
+ int32_t ofs = sps_scale(ir->s); /* Use spill slot or temp slots. */
+ Reg dest = ir->r;
+ if (ra_hasreg(dest)) {
+ ra_free(as, dest);
+ ra_modified(as, dest);
+ emit_rmro(as, irt_isnum(ir->t) ? XMM_MOVRM(as) : XO_MOVSS,
+ dest, RID_ESP, ofs);
+ }
+ emit_rmro(as, irt_isnum(ir->t) ? XO_FSTPq : XO_FSTPd,
+ irt_isnum(ir->t) ? XOg_FSTPq : XOg_FSTPd, RID_ESP, ofs);
+ if (((ir-1)->op2 & IRCONV_SRCMASK) == IRT_U64) {
+ /* For inputs in [2^63,2^64-1] add 2^64 to compensate. */
+ MCLabel l_end = emit_label(as);
+ emit_rma(as, XO_FADDq, XOg_FADDq,
+ lj_ir_k64_find(as->J, U64x(43f00000,00000000)));
+ emit_sjcc(as, CC_NS, l_end);
+ emit_rr(as, XO_TEST, hi, hi); /* Check if u64 >= 2^63. */
+ } else {
+ lua_assert(((ir-1)->op2 & IRCONV_SRCMASK) == IRT_I64);
+ }
+ emit_rmro(as, XO_FILDq, XOg_FILDq, RID_ESP, 0);
+ /* NYI: Avoid narrow-to-wide store-to-load forwarding stall. */
+ emit_rmro(as, XO_MOVto, hi, RID_ESP, 4);
+ emit_rmro(as, XO_MOVto, lo, RID_ESP, 0);
+}
+
+/* FP to 64 bit integer conversion in 32 bit mode. */
+static void asm_conv_int64_fp(ASMState *as, IRIns *ir)
+{
+ IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK);
+ IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH);
+ Reg lo, hi;
+ lua_assert(st == IRT_NUM || st == IRT_FLOAT);
+ lua_assert(dt == IRT_I64 || dt == IRT_U64);
+ lua_assert(((ir-1)->op2 & IRCONV_TRUNC));
+ hi = ra_dest(as, ir, RSET_GPR);
+ lo = ra_dest(as, ir-1, rset_exclude(RSET_GPR, hi));
+ if (ra_used(ir-1)) emit_rmro(as, XO_MOV, lo, RID_ESP, 0);
+ /* NYI: Avoid wide-to-narrow store-to-load forwarding stall. */
+ if (!(as->flags & JIT_F_SSE3)) { /* Set FPU rounding mode to default. */
+ emit_rmro(as, XO_FLDCW, XOg_FLDCW, RID_ESP, 4);
+ emit_rmro(as, XO_MOVto, lo, RID_ESP, 4);
+ emit_gri(as, XG_ARITHi(XOg_AND), lo, 0xf3ff);
+ }
+ if (dt == IRT_U64) {
+ /* For inputs in [2^63,2^64-1] add -2^64 and convert again. */
+ MCLabel l_pop, l_end = emit_label(as);
+ emit_x87op(as, XI_FPOP);
+ l_pop = emit_label(as);
+ emit_sjmp(as, l_end);
+ emit_rmro(as, XO_MOV, hi, RID_ESP, 4);
+ if ((as->flags & JIT_F_SSE3))
+ emit_rmro(as, XO_FISTTPq, XOg_FISTTPq, RID_ESP, 0);
+ else
+ emit_rmro(as, XO_FISTPq, XOg_FISTPq, RID_ESP, 0);
+ emit_rma(as, XO_FADDq, XOg_FADDq,
+ lj_ir_k64_find(as->J, U64x(c3f00000,00000000)));
+ emit_sjcc(as, CC_NS, l_pop);
+ emit_rr(as, XO_TEST, hi, hi); /* Check if out-of-range (2^63). */
+ }
+ emit_rmro(as, XO_MOV, hi, RID_ESP, 4);
+ if ((as->flags & JIT_F_SSE3)) { /* Truncation is easy with SSE3. */
+ emit_rmro(as, XO_FISTTPq, XOg_FISTTPq, RID_ESP, 0);
+ } else { /* Otherwise set FPU rounding mode to truncate before the store. */
+ emit_rmro(as, XO_FISTPq, XOg_FISTPq, RID_ESP, 0);
+ emit_rmro(as, XO_FLDCW, XOg_FLDCW, RID_ESP, 0);
+ emit_rmro(as, XO_MOVtow, lo, RID_ESP, 0);
+ emit_rmro(as, XO_ARITHw(XOg_OR), lo, RID_ESP, 0);
+ emit_loadi(as, lo, 0xc00);
+ emit_rmro(as, XO_FNSTCW, XOg_FNSTCW, RID_ESP, 0);
+ }
+ if (dt == IRT_U64)
+ emit_x87op(as, XI_FDUP);
+ emit_mrm(as, st == IRT_NUM ? XO_FLDq : XO_FLDd,
+ st == IRT_NUM ? XOg_FLDq: XOg_FLDd,
+ asm_fuseload(as, ir->op1, RSET_EMPTY));
+}
+#endif
+
+static void asm_strto(ASMState *as, IRIns *ir)
+{
+ /* Force a spill slot for the destination register (if any). */
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num];
+ IRRef args[2];
+ RegSet drop = RSET_SCRATCH;
+ if ((drop & RSET_FPR) != RSET_FPR && ra_hasreg(ir->r))
+ rset_set(drop, ir->r); /* WIN64 doesn't spill all FPRs. */
+ ra_evictset(as, drop);
+ asm_guardcc(as, CC_E);
+ emit_rr(as, XO_TEST, RID_RET, RID_RET); /* Test return status. */
+ args[0] = ir->op1; /* GCstr *str */
+ args[1] = ASMREF_TMP1; /* TValue *n */
+ asm_gencall(as, ci, args);
+ /* Store the result to the spill slot or temp slots. */
+ emit_rmro(as, XO_LEA, ra_releasetmp(as, ASMREF_TMP1)|REX_64,
+ RID_ESP, sps_scale(ir->s));
+}
+
+static void asm_tostr(ASMState *as, IRIns *ir)
+{
+ IRIns *irl = IR(ir->op1);
+ IRRef args[2];
+ args[0] = ASMREF_L;
+ as->gcsteps++;
+ if (irt_isnum(irl->t)) {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromnum];
+ args[1] = ASMREF_TMP1; /* const lua_Number * */
+ asm_setupresult(as, ir, ci); /* GCstr * */
+ asm_gencall(as, ci, args);
+ emit_rmro(as, XO_LEA, ra_releasetmp(as, ASMREF_TMP1)|REX_64,
+ RID_ESP, ra_spill(as, irl));
+ } else {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromint];
+ args[1] = ir->op1; /* int32_t k */
+ asm_setupresult(as, ir, ci); /* GCstr * */
+ asm_gencall(as, ci, args);
+ }
+}
+
+/* -- Memory references --------------------------------------------------- */
+
+static void asm_aref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ asm_fusearef(as, ir, RSET_GPR);
+ if (!(as->mrm.idx == RID_NONE && as->mrm.ofs == 0))
+ emit_mrm(as, XO_LEA, dest, RID_MRM);
+ else if (as->mrm.base != dest)
+ emit_rr(as, XO_MOV, dest, as->mrm.base);
+}
+
+/* Merge NE(HREF, niltv) check. */
+static MCode *merge_href_niltv(ASMState *as, IRIns *ir)
+{
+ /* Assumes nothing else generates NE of HREF. */
+ if ((ir[1].o == IR_NE || ir[1].o == IR_EQ) && ir[1].op1 == as->curins &&
+ ra_hasreg(ir->r)) {
+ MCode *p = as->mcp;
+ p += (LJ_64 && *p != XI_ARITHi) ? 7+6 : 6+6;
+ /* Ensure no loop branch inversion happened. */
+ if (p[-6] == 0x0f && p[-5] == XI_JCCn+(CC_NE^(ir[1].o & 1))) {
+ as->mcp = p; /* Kill cmp reg, imm32 + jz exit. */
+ return p + *(int32_t *)(p-4); /* Return exit address. */
+ }
+ }
+ return NULL;
+}
+
+/* Inlined hash lookup. Specialized for key type and for const keys.
+** The equivalent C code is:
+** Node *n = hashkey(t, key);
+** do {
+** if (lj_obj_equal(&n->key, key)) return &n->val;
+** } while ((n = nextnode(n)));
+** return niltv(L);
+*/
+static void asm_href(ASMState *as, IRIns *ir)
+{
+ MCode *nilexit = merge_href_niltv(as, ir); /* Do this before any restores. */
+ RegSet allow = RSET_GPR;
+ Reg dest = ra_dest(as, ir, allow);
+ Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest));
+ Reg key = RID_NONE, tmp = RID_NONE;
+ IRIns *irkey = IR(ir->op2);
+ int isk = irref_isk(ir->op2);
+ IRType1 kt = irkey->t;
+ uint32_t khash;
+ MCLabel l_end, l_loop, l_next;
+
+ if (!isk) {
+ rset_clear(allow, tab);
+ key = ra_alloc1(as, ir->op2, irt_isnum(kt) ? RSET_FPR : allow);
+ if (!irt_isstr(kt))
+ tmp = ra_scratch(as, rset_exclude(allow, key));
+ }
+
+ /* Key not found in chain: jump to exit (if merged with NE) or load niltv. */
+ l_end = emit_label(as);
+ if (nilexit && ir[1].o == IR_NE) {
+ emit_jcc(as, CC_E, nilexit); /* XI_JMP is not found by lj_asm_patchexit. */
+ nilexit = NULL;
+ } else {
+ emit_loada(as, dest, niltvg(J2G(as->J)));
+ }
+
+ /* Follow hash chain until the end. */
+ l_loop = emit_sjcc_label(as, CC_NZ);
+ emit_rr(as, XO_TEST, dest, dest);
+ emit_rmro(as, XO_MOV, dest, dest, offsetof(Node, next));
+ l_next = emit_label(as);
+
+ /* Type and value comparison. */
+ if (nilexit)
+ emit_jcc(as, CC_E, nilexit);
+ else
+ emit_sjcc(as, CC_E, l_end);
+ if (irt_isnum(kt)) {
+ if (isk) {
+ /* Assumes -0.0 is already canonicalized to +0.0. */
+ emit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.u32.lo),
+ (int32_t)ir_knum(irkey)->u32.lo);
+ emit_sjcc(as, CC_NE, l_next);
+ emit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.u32.hi),
+ (int32_t)ir_knum(irkey)->u32.hi);
+ } else {
+ emit_sjcc(as, CC_P, l_next);
+ emit_rmro(as, XO_UCOMISD, key, dest, offsetof(Node, key.n));
+ emit_sjcc(as, CC_AE, l_next);
+ /* The type check avoids NaN penalties and complaints from Valgrind. */
+#if LJ_64
+ emit_u32(as, LJ_TISNUM);
+ emit_rmro(as, XO_ARITHi, XOg_CMP, dest, offsetof(Node, key.it));
+#else
+ emit_i8(as, LJ_TISNUM);
+ emit_rmro(as, XO_ARITHi8, XOg_CMP, dest, offsetof(Node, key.it));
+#endif
+ }
+#if LJ_64
+ } else if (irt_islightud(kt)) {
+ emit_rmro(as, XO_CMP, key|REX_64, dest, offsetof(Node, key.u64));
+#endif
+ } else {
+ if (!irt_ispri(kt)) {
+ lua_assert(irt_isaddr(kt));
+ if (isk)
+ emit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.gcr),
+ ptr2addr(ir_kgc(irkey)));
+ else
+ emit_rmro(as, XO_CMP, key, dest, offsetof(Node, key.gcr));
+ emit_sjcc(as, CC_NE, l_next);
+ }
+ lua_assert(!irt_isnil(kt));
+ emit_i8(as, irt_toitype(kt));
+ emit_rmro(as, XO_ARITHi8, XOg_CMP, dest, offsetof(Node, key.it));
+ }
+ emit_sfixup(as, l_loop);
+ checkmclim(as);
+
+ /* Load main position relative to tab->node into dest. */
+ khash = isk ? ir_khash(irkey) : 1;
+ if (khash == 0) {
+ emit_rmro(as, XO_MOV, dest, tab, offsetof(GCtab, node));
+ } else {
+ emit_rmro(as, XO_ARITH(XOg_ADD), dest, tab, offsetof(GCtab, node));
+ if ((as->flags & JIT_F_PREFER_IMUL)) {
+ emit_i8(as, sizeof(Node));
+ emit_rr(as, XO_IMULi8, dest, dest);
+ } else {
+ emit_shifti(as, XOg_SHL, dest, 3);
+ emit_rmrxo(as, XO_LEA, dest, dest, dest, XM_SCALE2, 0);
+ }
+ if (isk) {
+ emit_gri(as, XG_ARITHi(XOg_AND), dest, (int32_t)khash);
+ emit_rmro(as, XO_MOV, dest, tab, offsetof(GCtab, hmask));
+ } else if (irt_isstr(kt)) {
+ emit_rmro(as, XO_ARITH(XOg_AND), dest, key, offsetof(GCstr, hash));
+ emit_rmro(as, XO_MOV, dest, tab, offsetof(GCtab, hmask));
+ } else { /* Must match with hashrot() in lj_tab.c. */
+ emit_rmro(as, XO_ARITH(XOg_AND), dest, tab, offsetof(GCtab, hmask));
+ emit_rr(as, XO_ARITH(XOg_SUB), dest, tmp);
+ emit_shifti(as, XOg_ROL, tmp, HASH_ROT3);
+ emit_rr(as, XO_ARITH(XOg_XOR), dest, tmp);
+ emit_shifti(as, XOg_ROL, dest, HASH_ROT2);
+ emit_rr(as, XO_ARITH(XOg_SUB), tmp, dest);
+ emit_shifti(as, XOg_ROL, dest, HASH_ROT1);
+ emit_rr(as, XO_ARITH(XOg_XOR), tmp, dest);
+ if (irt_isnum(kt)) {
+ emit_rr(as, XO_ARITH(XOg_ADD), dest, dest);
+#if LJ_64
+ emit_shifti(as, XOg_SHR|REX_64, dest, 32);
+ emit_rr(as, XO_MOV, tmp, dest);
+ emit_rr(as, XO_MOVDto, key|REX_64, dest);
+#else
+ emit_rmro(as, XO_MOV, dest, RID_ESP, ra_spill(as, irkey)+4);
+ emit_rr(as, XO_MOVDto, key, tmp);
+#endif
+ } else {
+ emit_rr(as, XO_MOV, tmp, key);
+ emit_rmro(as, XO_LEA, dest, key, HASH_BIAS);
+ }
+ }
+ }
+}
+
+static void asm_hrefk(ASMState *as, IRIns *ir)
+{
+ IRIns *kslot = IR(ir->op2);
+ IRIns *irkey = IR(kslot->op1);
+ int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node));
+ Reg dest = ra_used(ir) ? ra_dest(as, ir, RSET_GPR) : RID_NONE;
+ Reg node = ra_alloc1(as, ir->op1, RSET_GPR);
+#if !LJ_64
+ MCLabel l_exit;
+#endif
+ lua_assert(ofs % sizeof(Node) == 0);
+ if (ra_hasreg(dest)) {
+ if (ofs != 0) {
+ if (dest == node && !(as->flags & JIT_F_LEA_AGU))
+ emit_gri(as, XG_ARITHi(XOg_ADD), dest, ofs);
+ else
+ emit_rmro(as, XO_LEA, dest, node, ofs);
+ } else if (dest != node) {
+ emit_rr(as, XO_MOV, dest, node);
+ }
+ }
+ asm_guardcc(as, CC_NE);
+#if LJ_64
+ if (!irt_ispri(irkey->t)) {
+ Reg key = ra_scratch(as, rset_exclude(RSET_GPR, node));
+ emit_rmro(as, XO_CMP, key|REX_64, node,
+ ofs + (int32_t)offsetof(Node, key.u64));
+ lua_assert(irt_isnum(irkey->t) || irt_isgcv(irkey->t));
+ /* Assumes -0.0 is already canonicalized to +0.0. */
+ emit_loadu64(as, key, irt_isnum(irkey->t) ? ir_knum(irkey)->u64 :
+ ((uint64_t)irt_toitype(irkey->t) << 32) |
+ (uint64_t)(uint32_t)ptr2addr(ir_kgc(irkey)));
+ } else {
+ lua_assert(!irt_isnil(irkey->t));
+ emit_i8(as, irt_toitype(irkey->t));
+ emit_rmro(as, XO_ARITHi8, XOg_CMP, node,
+ ofs + (int32_t)offsetof(Node, key.it));
+ }
+#else
+ l_exit = emit_label(as);
+ if (irt_isnum(irkey->t)) {
+ /* Assumes -0.0 is already canonicalized to +0.0. */
+ emit_gmroi(as, XG_ARITHi(XOg_CMP), node,
+ ofs + (int32_t)offsetof(Node, key.u32.lo),
+ (int32_t)ir_knum(irkey)->u32.lo);
+ emit_sjcc(as, CC_NE, l_exit);
+ emit_gmroi(as, XG_ARITHi(XOg_CMP), node,
+ ofs + (int32_t)offsetof(Node, key.u32.hi),
+ (int32_t)ir_knum(irkey)->u32.hi);
+ } else {
+ if (!irt_ispri(irkey->t)) {
+ lua_assert(irt_isgcv(irkey->t));
+ emit_gmroi(as, XG_ARITHi(XOg_CMP), node,
+ ofs + (int32_t)offsetof(Node, key.gcr),
+ ptr2addr(ir_kgc(irkey)));
+ emit_sjcc(as, CC_NE, l_exit);
+ }
+ lua_assert(!irt_isnil(irkey->t));
+ emit_i8(as, irt_toitype(irkey->t));
+ emit_rmro(as, XO_ARITHi8, XOg_CMP, node,
+ ofs + (int32_t)offsetof(Node, key.it));
+ }
+#endif
+}
+
+static void asm_newref(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_newkey];
+ IRRef args[3];
+ IRIns *irkey;
+ Reg tmp;
+ if (ir->r == RID_SINK)
+ return;
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ir->op1; /* GCtab *t */
+ args[2] = ASMREF_TMP1; /* cTValue *key */
+ asm_setupresult(as, ir, ci); /* TValue * */
+ asm_gencall(as, ci, args);
+ tmp = ra_releasetmp(as, ASMREF_TMP1);
+ irkey = IR(ir->op2);
+ if (irt_isnum(irkey->t)) {
+ /* For numbers use the constant itself or a spill slot as a TValue. */
+ if (irref_isk(ir->op2))
+ emit_loada(as, tmp, ir_knum(irkey));
+ else
+ emit_rmro(as, XO_LEA, tmp|REX_64, RID_ESP, ra_spill(as, irkey));
+ } else {
+ /* Otherwise use g->tmptv to hold the TValue. */
+ if (!irref_isk(ir->op2)) {
+ Reg src = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, tmp));
+ emit_movtomro(as, REX_64IR(irkey, src), tmp, 0);
+ } else if (!irt_ispri(irkey->t)) {
+ emit_movmroi(as, tmp, 0, irkey->i);
+ }
+ if (!(LJ_64 && irt_islightud(irkey->t)))
+ emit_movmroi(as, tmp, 4, irt_toitype(irkey->t));
+ emit_loada(as, tmp, &J2G(as->J)->tmptv);
+ }
+}
+
+static void asm_uref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (irref_isk(ir->op1)) {
+ GCfunc *fn = ir_kfunc(IR(ir->op1));
+ MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v;
+ emit_rma(as, XO_MOV, dest, v);
+ } else {
+ Reg uv = ra_scratch(as, RSET_GPR);
+ Reg func = ra_alloc1(as, ir->op1, RSET_GPR);
+ if (ir->o == IR_UREFC) {
+ emit_rmro(as, XO_LEA, dest, uv, offsetof(GCupval, tv));
+ asm_guardcc(as, CC_NE);
+ emit_i8(as, 1);
+ emit_rmro(as, XO_ARITHib, XOg_CMP, uv, offsetof(GCupval, closed));
+ } else {
+ emit_rmro(as, XO_MOV, dest, uv, offsetof(GCupval, v));
+ }
+ emit_rmro(as, XO_MOV, uv, func,
+ (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8));
+ }
+}
+
+static void asm_fref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ asm_fusefref(as, ir, RSET_GPR);
+ emit_mrm(as, XO_LEA, dest, RID_MRM);
+}
+
+static void asm_strref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ asm_fusestrref(as, ir, RSET_GPR);
+ if (as->mrm.base == RID_NONE)
+ emit_loadi(as, dest, as->mrm.ofs);
+ else if (as->mrm.base == dest && as->mrm.idx == RID_NONE)
+ emit_gri(as, XG_ARITHi(XOg_ADD), dest, as->mrm.ofs);
+ else
+ emit_mrm(as, XO_LEA, dest, RID_MRM);
+}
+
+/* -- Loads and stores ---------------------------------------------------- */
+
+static void asm_fxload(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);
+ x86Op xo;
+ if (ir->o == IR_FLOAD)
+ asm_fusefref(as, ir, RSET_GPR);
+ else
+ asm_fusexref(as, ir->op1, RSET_GPR);
+ /* ir->op2 is ignored -- unaligned loads are ok on x86. */
+ switch (irt_type(ir->t)) {
+ case IRT_I8: xo = XO_MOVSXb; break;
+ case IRT_U8: xo = XO_MOVZXb; break;
+ case IRT_I16: xo = XO_MOVSXw; break;
+ case IRT_U16: xo = XO_MOVZXw; break;
+ case IRT_NUM: xo = XMM_MOVRM(as); break;
+ case IRT_FLOAT: xo = XO_MOVSS; break;
+ default:
+ if (LJ_64 && irt_is64(ir->t))
+ dest |= REX_64;
+ else
+ lua_assert(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t));
+ xo = XO_MOV;
+ break;
+ }
+ emit_mrm(as, xo, dest, RID_MRM);
+}
+
+static void asm_fxstore(ASMState *as, IRIns *ir)
+{
+ RegSet allow = RSET_GPR;
+ Reg src = RID_NONE, osrc = RID_NONE;
+ int32_t k = 0;
+ if (ir->r == RID_SINK)
+ return;
+ /* The IRT_I16/IRT_U16 stores should never be simplified for constant
+ ** values since mov word [mem], imm16 has a length-changing prefix.
+ */
+ if (irt_isi16(ir->t) || irt_isu16(ir->t) || irt_isfp(ir->t) ||
+ !asm_isk32(as, ir->op2, &k)) {
+ RegSet allow8 = irt_isfp(ir->t) ? RSET_FPR :
+ (irt_isi8(ir->t) || irt_isu8(ir->t)) ? RSET_GPR8 : RSET_GPR;
+ src = osrc = ra_alloc1(as, ir->op2, allow8);
+ if (!LJ_64 && !rset_test(allow8, src)) { /* Already in wrong register. */
+ rset_clear(allow, osrc);
+ src = ra_scratch(as, allow8);
+ }
+ rset_clear(allow, src);
+ }
+ if (ir->o == IR_FSTORE) {
+ asm_fusefref(as, IR(ir->op1), allow);
+ } else {
+ asm_fusexref(as, ir->op1, allow);
+ if (LJ_32 && ir->o == IR_HIOP) as->mrm.ofs += 4;
+ }
+ if (ra_hasreg(src)) {
+ x86Op xo;
+ switch (irt_type(ir->t)) {
+ case IRT_I8: case IRT_U8: xo = XO_MOVtob; src |= FORCE_REX; break;
+ case IRT_I16: case IRT_U16: xo = XO_MOVtow; break;
+ case IRT_NUM: xo = XO_MOVSDto; break;
+ case IRT_FLOAT: xo = XO_MOVSSto; break;
+#if LJ_64
+ case IRT_LIGHTUD: lua_assert(0); /* NYI: mask 64 bit lightuserdata. */
+#endif
+ default:
+ if (LJ_64 && irt_is64(ir->t))
+ src |= REX_64;
+ else
+ lua_assert(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t));
+ xo = XO_MOVto;
+ break;
+ }
+ emit_mrm(as, xo, src, RID_MRM);
+ if (!LJ_64 && src != osrc) {
+ ra_noweak(as, osrc);
+ emit_rr(as, XO_MOV, src, osrc);
+ }
+ } else {
+ if (irt_isi8(ir->t) || irt_isu8(ir->t)) {
+ emit_i8(as, k);
+ emit_mrm(as, XO_MOVmib, 0, RID_MRM);
+ } else {
+ lua_assert(irt_is64(ir->t) || irt_isint(ir->t) || irt_isu32(ir->t) ||
+ irt_isaddr(ir->t));
+ emit_i32(as, k);
+ emit_mrm(as, XO_MOVmi, REX_64IR(ir, 0), RID_MRM);
+ }
+ }
+}
+
+#if LJ_64
+static Reg asm_load_lightud64(ASMState *as, IRIns *ir, int typecheck)
+{
+ if (ra_used(ir) || typecheck) {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (typecheck) {
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, dest));
+ asm_guardcc(as, CC_NE);
+ emit_i8(as, -2);
+ emit_rr(as, XO_ARITHi8, XOg_CMP, tmp);
+ emit_shifti(as, XOg_SAR|REX_64, tmp, 47);
+ emit_rr(as, XO_MOV, tmp|REX_64, dest);
+ }
+ return dest;
+ } else {
+ return RID_NONE;
+ }
+}
+#endif
+
+static void asm_ahuvload(ASMState *as, IRIns *ir)
+{
+ lua_assert(irt_isnum(ir->t) || irt_ispri(ir->t) || irt_isaddr(ir->t) ||
+ (LJ_DUALNUM && irt_isint(ir->t)));
+#if LJ_64
+ if (irt_islightud(ir->t)) {
+ Reg dest = asm_load_lightud64(as, ir, 1);
+ if (ra_hasreg(dest)) {
+ asm_fuseahuref(as, ir->op1, RSET_GPR);
+ emit_mrm(as, XO_MOV, dest|REX_64, RID_MRM);
+ }
+ return;
+ } else
+#endif
+ if (ra_used(ir)) {
+ RegSet allow = irt_isnum(ir->t) ? RSET_FPR : RSET_GPR;
+ Reg dest = ra_dest(as, ir, allow);
+ asm_fuseahuref(as, ir->op1, RSET_GPR);
+ emit_mrm(as, dest < RID_MAX_GPR ? XO_MOV : XMM_MOVRM(as), dest, RID_MRM);
+ } else {
+ asm_fuseahuref(as, ir->op1, RSET_GPR);
+ }
+ /* Always do the type check, even if the load result is unused. */
+ as->mrm.ofs += 4;
+ asm_guardcc(as, irt_isnum(ir->t) ? CC_AE : CC_NE);
+ if (LJ_64 && irt_type(ir->t) >= IRT_NUM) {
+ lua_assert(irt_isinteger(ir->t) || irt_isnum(ir->t));
+ emit_u32(as, LJ_TISNUM);
+ emit_mrm(as, XO_ARITHi, XOg_CMP, RID_MRM);
+ } else {
+ emit_i8(as, irt_toitype(ir->t));
+ emit_mrm(as, XO_ARITHi8, XOg_CMP, RID_MRM);
+ }
+}
+
+static void asm_ahustore(ASMState *as, IRIns *ir)
+{
+ if (ir->r == RID_SINK)
+ return;
+ if (irt_isnum(ir->t)) {
+ Reg src = ra_alloc1(as, ir->op2, RSET_FPR);
+ asm_fuseahuref(as, ir->op1, RSET_GPR);
+ emit_mrm(as, XO_MOVSDto, src, RID_MRM);
+#if LJ_64
+ } else if (irt_islightud(ir->t)) {
+ Reg src = ra_alloc1(as, ir->op2, RSET_GPR);
+ asm_fuseahuref(as, ir->op1, rset_exclude(RSET_GPR, src));
+ emit_mrm(as, XO_MOVto, src|REX_64, RID_MRM);
+#endif
+ } else {
+ IRIns *irr = IR(ir->op2);
+ RegSet allow = RSET_GPR;
+ Reg src = RID_NONE;
+ if (!irref_isk(ir->op2)) {
+ src = ra_alloc1(as, ir->op2, allow);
+ rset_clear(allow, src);
+ }
+ asm_fuseahuref(as, ir->op1, allow);
+ if (ra_hasreg(src)) {
+ emit_mrm(as, XO_MOVto, src, RID_MRM);
+ } else if (!irt_ispri(irr->t)) {
+ lua_assert(irt_isaddr(ir->t) || (LJ_DUALNUM && irt_isinteger(ir->t)));
+ emit_i32(as, irr->i);
+ emit_mrm(as, XO_MOVmi, 0, RID_MRM);
+ }
+ as->mrm.ofs += 4;
+ emit_i32(as, (int32_t)irt_toitype(ir->t));
+ emit_mrm(as, XO_MOVmi, 0, RID_MRM);
+ }
+}
+
+static void asm_sload(ASMState *as, IRIns *ir)
+{
+ int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 4 : 0);
+ IRType1 t = ir->t;
+ Reg base;
+ lua_assert(!(ir->op2 & IRSLOAD_PARENT)); /* Handled by asm_head_side(). */
+ lua_assert(irt_isguard(t) || !(ir->op2 & IRSLOAD_TYPECHECK));
+ lua_assert(LJ_DUALNUM ||
+ !irt_isint(t) || (ir->op2 & (IRSLOAD_CONVERT|IRSLOAD_FRAME)));
+ if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(t) && irt_isint(t)) {
+ Reg left = ra_scratch(as, RSET_FPR);
+ asm_tointg(as, ir, left); /* Frees dest reg. Do this before base alloc. */
+ base = ra_alloc1(as, REF_BASE, RSET_GPR);
+ emit_rmro(as, XMM_MOVRM(as), left, base, ofs);
+ t.irt = IRT_NUM; /* Continue with a regular number type check. */
+#if LJ_64
+ } else if (irt_islightud(t)) {
+ Reg dest = asm_load_lightud64(as, ir, (ir->op2 & IRSLOAD_TYPECHECK));
+ if (ra_hasreg(dest)) {
+ base = ra_alloc1(as, REF_BASE, RSET_GPR);
+ emit_rmro(as, XO_MOV, dest|REX_64, base, ofs);
+ }
+ return;
+#endif
+ } else if (ra_used(ir)) {
+ RegSet allow = irt_isnum(t) ? RSET_FPR : RSET_GPR;
+ Reg dest = ra_dest(as, ir, allow);
+ base = ra_alloc1(as, REF_BASE, RSET_GPR);
+ lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t));
+ if ((ir->op2 & IRSLOAD_CONVERT)) {
+ t.irt = irt_isint(t) ? IRT_NUM : IRT_INT; /* Check for original type. */
+ emit_rmro(as, irt_isint(t) ? XO_CVTSI2SD : XO_CVTSD2SI, dest, base, ofs);
+ } else if (irt_isnum(t)) {
+ emit_rmro(as, XMM_MOVRM(as), dest, base, ofs);
+ } else {
+ emit_rmro(as, XO_MOV, dest, base, ofs);
+ }
+ } else {
+ if (!(ir->op2 & IRSLOAD_TYPECHECK))
+ return; /* No type check: avoid base alloc. */
+ base = ra_alloc1(as, REF_BASE, RSET_GPR);
+ }
+ if ((ir->op2 & IRSLOAD_TYPECHECK)) {
+ /* Need type check, even if the load result is unused. */
+ asm_guardcc(as, irt_isnum(t) ? CC_AE : CC_NE);
+ if (LJ_64 && irt_type(t) >= IRT_NUM) {
+ lua_assert(irt_isinteger(t) || irt_isnum(t));
+ emit_u32(as, LJ_TISNUM);
+ emit_rmro(as, XO_ARITHi, XOg_CMP, base, ofs+4);
+ } else {
+ emit_i8(as, irt_toitype(t));
+ emit_rmro(as, XO_ARITHi8, XOg_CMP, base, ofs+4);
+ }
+ }
+}
+
+/* -- Allocations --------------------------------------------------------- */
+
+#if LJ_HASFFI
+static void asm_cnew(ASMState *as, IRIns *ir)
+{
+ CTState *cts = ctype_ctsG(J2G(as->J));
+ CTypeID ctypeid = (CTypeID)IR(ir->op1)->i;
+ CTSize sz = (ir->o == IR_CNEWI || ir->op2 == REF_NIL) ?
+ lj_ctype_size(cts, ctypeid) : (CTSize)IR(ir->op2)->i;
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];
+ IRRef args[2];
+ lua_assert(sz != CTSIZE_INVALID);
+
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ASMREF_TMP1; /* MSize size */
+ as->gcsteps++;
+ asm_setupresult(as, ir, ci); /* GCcdata * */
+
+ /* Initialize immutable cdata object. */
+ if (ir->o == IR_CNEWI) {
+ RegSet allow = (RSET_GPR & ~RSET_SCRATCH);
+#if LJ_64
+ Reg r64 = sz == 8 ? REX_64 : 0;
+ if (irref_isk(ir->op2)) {
+ IRIns *irk = IR(ir->op2);
+ uint64_t k = irk->o == IR_KINT64 ? ir_k64(irk)->u64 :
+ (uint64_t)(uint32_t)irk->i;
+ if (sz == 4 || checki32((int64_t)k)) {
+ emit_i32(as, (int32_t)k);
+ emit_rmro(as, XO_MOVmi, r64, RID_RET, sizeof(GCcdata));
+ } else {
+ emit_movtomro(as, RID_ECX + r64, RID_RET, sizeof(GCcdata));
+ emit_loadu64(as, RID_ECX, k);
+ }
+ } else {
+ Reg r = ra_alloc1(as, ir->op2, allow);
+ emit_movtomro(as, r + r64, RID_RET, sizeof(GCcdata));
+ }
+#else
+ int32_t ofs = sizeof(GCcdata);
+ if (sz == 8) {
+ ofs += 4; ir++;
+ lua_assert(ir->o == IR_HIOP);
+ }
+ do {
+ if (irref_isk(ir->op2)) {
+ emit_movmroi(as, RID_RET, ofs, IR(ir->op2)->i);
+ } else {
+ Reg r = ra_alloc1(as, ir->op2, allow);
+ emit_movtomro(as, r, RID_RET, ofs);
+ rset_clear(allow, r);
+ }
+ if (ofs == sizeof(GCcdata)) break;
+ ofs -= 4; ir--;
+ } while (1);
+#endif
+ lua_assert(sz == 4 || sz == 8);
+ }
+
+ /* Combine initialization of marked, gct and ctypeid. */
+ emit_movtomro(as, RID_ECX, RID_RET, offsetof(GCcdata, marked));
+ emit_gri(as, XG_ARITHi(XOg_OR), RID_ECX,
+ (int32_t)((~LJ_TCDATA<<8)+(ctypeid<<16)));
+ emit_gri(as, XG_ARITHi(XOg_AND), RID_ECX, LJ_GC_WHITES);
+ emit_opgl(as, XO_MOVZXb, RID_ECX, gc.currentwhite);
+
+ asm_gencall(as, ci, args);
+ emit_loadi(as, ra_releasetmp(as, ASMREF_TMP1), (int32_t)(sz+sizeof(GCcdata)));
+}
+#else
+#define asm_cnew(as, ir) ((void)0)
+#endif
+
+/* -- Write barriers ------------------------------------------------------ */
+
+static void asm_tbar(ASMState *as, IRIns *ir)
+{
+ Reg tab = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, tab));
+ MCLabel l_end = emit_label(as);
+ emit_movtomro(as, tmp, tab, offsetof(GCtab, gclist));
+ emit_setgl(as, tab, gc.grayagain);
+ emit_getgl(as, tmp, gc.grayagain);
+ emit_i8(as, ~LJ_GC_BLACK);
+ emit_rmro(as, XO_ARITHib, XOg_AND, tab, offsetof(GCtab, marked));
+ emit_sjcc(as, CC_Z, l_end);
+ emit_i8(as, LJ_GC_BLACK);
+ emit_rmro(as, XO_GROUP3b, XOg_TEST, tab, offsetof(GCtab, marked));
+}
+
+static void asm_obar(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv];
+ IRRef args[2];
+ MCLabel l_end;
+ Reg obj;
+ /* No need for other object barriers (yet). */
+ lua_assert(IR(ir->op1)->o == IR_UREFC);
+ ra_evictset(as, RSET_SCRATCH);
+ l_end = emit_label(as);
+ args[0] = ASMREF_TMP1; /* global_State *g */
+ args[1] = ir->op1; /* TValue *tv */
+ asm_gencall(as, ci, args);
+ emit_loada(as, ra_releasetmp(as, ASMREF_TMP1), J2G(as->J));
+ obj = IR(ir->op1)->r;
+ emit_sjcc(as, CC_Z, l_end);
+ emit_i8(as, LJ_GC_WHITES);
+ if (irref_isk(ir->op2)) {
+ GCobj *vp = ir_kgc(IR(ir->op2));
+ emit_rma(as, XO_GROUP3b, XOg_TEST, &vp->gch.marked);
+ } else {
+ Reg val = ra_alloc1(as, ir->op2, rset_exclude(RSET_SCRATCH&RSET_GPR, obj));
+ emit_rmro(as, XO_GROUP3b, XOg_TEST, val, (int32_t)offsetof(GChead, marked));
+ }
+ emit_sjcc(as, CC_Z, l_end);
+ emit_i8(as, LJ_GC_BLACK);
+ emit_rmro(as, XO_GROUP3b, XOg_TEST, obj,
+ (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv));
+}
+
+/* -- FP/int arithmetic and logic operations ------------------------------ */
+
+/* Load reference onto x87 stack. Force a spill to memory if needed. */
+static void asm_x87load(ASMState *as, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ if (ir->o == IR_KNUM) {
+ cTValue *tv = ir_knum(ir);
+ if (tvispzero(tv)) /* Use fldz only for +0. */
+ emit_x87op(as, XI_FLDZ);
+ else if (tvispone(tv))
+ emit_x87op(as, XI_FLD1);
+ else
+ emit_rma(as, XO_FLDq, XOg_FLDq, tv);
+ } else if (ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT && !ra_used(ir) &&
+ !irref_isk(ir->op1) && mayfuse(as, ir->op1)) {
+ IRIns *iri = IR(ir->op1);
+ emit_rmro(as, XO_FILDd, XOg_FILDd, RID_ESP, ra_spill(as, iri));
+ } else {
+ emit_mrm(as, XO_FLDq, XOg_FLDq, asm_fuseload(as, ref, RSET_EMPTY));
+ }
+}
+
+/* Try to rejoin pow from EXP2, MUL and LOG2 (if still unsplit). */
+static int fpmjoin_pow(ASMState *as, IRIns *ir)
+{
+ IRIns *irp = IR(ir->op1);
+ if (irp == ir-1 && irp->o == IR_MUL && !ra_used(irp)) {
+ IRIns *irpp = IR(irp->op1);
+ if (irpp == ir-2 && irpp->o == IR_FPMATH &&
+ irpp->op2 == IRFPM_LOG2 && !ra_used(irpp)) {
+ /* The modified regs must match with the *.dasc implementation. */
+ RegSet drop = RSET_RANGE(RID_XMM0, RID_XMM2+1)|RID2RSET(RID_EAX);
+ IRIns *irx;
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ ra_evictset(as, drop);
+ ra_destreg(as, ir, RID_XMM0);
+ emit_call(as, lj_vm_pow_sse);
+ irx = IR(irpp->op1);
+ if (ra_noreg(irx->r) && ra_gethint(irx->r) == RID_XMM1)
+ irx->r = RID_INIT; /* Avoid allocating xmm1 for x. */
+ ra_left(as, RID_XMM0, irpp->op1);
+ ra_left(as, RID_XMM1, irp->op2);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static void asm_fpmath(ASMState *as, IRIns *ir)
+{
+ IRFPMathOp fpm = ir->o == IR_FPMATH ? (IRFPMathOp)ir->op2 : IRFPM_OTHER;
+ if (fpm == IRFPM_SQRT) {
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg left = asm_fuseload(as, ir->op1, RSET_FPR);
+ emit_mrm(as, XO_SQRTSD, dest, left);
+ } else if (fpm <= IRFPM_TRUNC) {
+ if (as->flags & JIT_F_SSE4_1) { /* SSE4.1 has a rounding instruction. */
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg left = asm_fuseload(as, ir->op1, RSET_FPR);
+ /* ROUNDSD has a 4-byte opcode which doesn't fit in x86Op.
+ ** Let's pretend it's a 3-byte opcode, and compensate afterwards.
+ ** This is atrocious, but the alternatives are much worse.
+ */
+ /* Round down/up/trunc == 1001/1010/1011. */
+ emit_i8(as, 0x09 + fpm);
+ emit_mrm(as, XO_ROUNDSD, dest, left);
+ if (LJ_64 && as->mcp[1] != (MCode)(XO_ROUNDSD >> 16)) {
+ as->mcp[0] = as->mcp[1]; as->mcp[1] = 0x0f; /* Swap 0F and REX. */
+ }
+ *--as->mcp = 0x66; /* 1st byte of ROUNDSD opcode. */
+ } else { /* Call helper functions for SSE2 variant. */
+ /* The modified regs must match with the *.dasc implementation. */
+ RegSet drop = RSET_RANGE(RID_XMM0, RID_XMM3+1)|RID2RSET(RID_EAX);
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ ra_evictset(as, drop);
+ ra_destreg(as, ir, RID_XMM0);
+ emit_call(as, fpm == IRFPM_FLOOR ? lj_vm_floor_sse :
+ fpm == IRFPM_CEIL ? lj_vm_ceil_sse : lj_vm_trunc_sse);
+ ra_left(as, RID_XMM0, ir->op1);
+ }
+ } else if (fpm == IRFPM_EXP2 && fpmjoin_pow(as, ir)) {
+ /* Rejoined to pow(). */
+ } else { /* Handle x87 ops. */
+ int32_t ofs = sps_scale(ir->s); /* Use spill slot or temp slots. */
+ Reg dest = ir->r;
+ if (ra_hasreg(dest)) {
+ ra_free(as, dest);
+ ra_modified(as, dest);
+ emit_rmro(as, XMM_MOVRM(as), dest, RID_ESP, ofs);
+ }
+ emit_rmro(as, XO_FSTPq, XOg_FSTPq, RID_ESP, ofs);
+ switch (fpm) { /* st0 = lj_vm_*(st0) */
+ case IRFPM_EXP: emit_call(as, lj_vm_exp_x87); break;
+ case IRFPM_EXP2: emit_call(as, lj_vm_exp2_x87); break;
+ case IRFPM_SIN: emit_x87op(as, XI_FSIN); break;
+ case IRFPM_COS: emit_x87op(as, XI_FCOS); break;
+ case IRFPM_TAN: emit_x87op(as, XI_FPOP); emit_x87op(as, XI_FPTAN); break;
+ case IRFPM_LOG: case IRFPM_LOG2: case IRFPM_LOG10:
+ /* Note: the use of fyl2xp1 would be pointless here. When computing
+ ** log(1.0+eps) the precision is already lost after 1.0 is added.
+ ** Subtracting 1.0 won't recover it. OTOH math.log1p would make sense.
+ */
+ emit_x87op(as, XI_FYL2X); break;
+ case IRFPM_OTHER:
+ switch (ir->o) {
+ case IR_ATAN2:
+ emit_x87op(as, XI_FPATAN); asm_x87load(as, ir->op2); break;
+ case IR_LDEXP:
+ emit_x87op(as, XI_FPOP1); emit_x87op(as, XI_FSCALE); break;
+ default: lua_assert(0); break;
+ }
+ break;
+ default: lua_assert(0); break;
+ }
+ asm_x87load(as, ir->op1);
+ switch (fpm) {
+ case IRFPM_LOG: emit_x87op(as, XI_FLDLN2); break;
+ case IRFPM_LOG2: emit_x87op(as, XI_FLD1); break;
+ case IRFPM_LOG10: emit_x87op(as, XI_FLDLG2); break;
+ case IRFPM_OTHER:
+ if (ir->o == IR_LDEXP) asm_x87load(as, ir->op2);
+ break;
+ default: break;
+ }
+ }
+}
+
+static void asm_fppowi(ASMState *as, IRIns *ir)
+{
+ /* The modified regs must match with the *.dasc implementation. */
+ RegSet drop = RSET_RANGE(RID_XMM0, RID_XMM1+1)|RID2RSET(RID_EAX);
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ ra_evictset(as, drop);
+ ra_destreg(as, ir, RID_XMM0);
+ emit_call(as, lj_vm_powi_sse);
+ ra_left(as, RID_XMM0, ir->op1);
+ ra_left(as, RID_EAX, ir->op2);
+}
+
+#if LJ_64 && LJ_HASFFI
+static void asm_arith64(ASMState *as, IRIns *ir, IRCallID id)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[id];
+ IRRef args[2];
+ args[0] = ir->op1;
+ args[1] = ir->op2;
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+#endif
+
+static void asm_intmod(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_vm_modi];
+ IRRef args[2];
+ args[0] = ir->op1;
+ args[1] = ir->op2;
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+
+static int asm_swapops(ASMState *as, IRIns *ir)
+{
+ IRIns *irl = IR(ir->op1);
+ IRIns *irr = IR(ir->op2);
+ lua_assert(ra_noreg(irr->r));
+ if (!irm_iscomm(lj_ir_mode[ir->o]))
+ return 0; /* Can't swap non-commutative operations. */
+ if (irref_isk(ir->op2))
+ return 0; /* Don't swap constants to the left. */
+ if (ra_hasreg(irl->r))
+ return 1; /* Swap if left already has a register. */
+ if (ra_samehint(ir->r, irr->r))
+ return 1; /* Swap if dest and right have matching hints. */
+ if (as->curins > as->loopref) { /* In variant part? */
+ if (ir->op2 < as->loopref && !irt_isphi(irr->t))
+ return 0; /* Keep invariants on the right. */
+ if (ir->op1 < as->loopref && !irt_isphi(irl->t))
+ return 1; /* Swap invariants to the right. */
+ }
+ if (opisfusableload(irl->o))
+ return 1; /* Swap fusable loads to the right. */
+ return 0; /* Otherwise don't swap. */
+}
+
+static void asm_fparith(ASMState *as, IRIns *ir, x86Op xo)
+{
+ IRRef lref = ir->op1;
+ IRRef rref = ir->op2;
+ RegSet allow = RSET_FPR;
+ Reg dest;
+ Reg right = IR(rref)->r;
+ if (ra_hasreg(right)) {
+ rset_clear(allow, right);
+ ra_noweak(as, right);
+ }
+ dest = ra_dest(as, ir, allow);
+ if (lref == rref) {
+ right = dest;
+ } else if (ra_noreg(right)) {
+ if (asm_swapops(as, ir)) {
+ IRRef tmp = lref; lref = rref; rref = tmp;
+ }
+ right = asm_fuseload(as, rref, rset_clear(allow, dest));
+ }
+ emit_mrm(as, xo, dest, right);
+ ra_left(as, dest, lref);
+}
+
+static void asm_intarith(ASMState *as, IRIns *ir, x86Arith xa)
+{
+ IRRef lref = ir->op1;
+ IRRef rref = ir->op2;
+ RegSet allow = RSET_GPR;
+ Reg dest, right;
+ int32_t k = 0;
+ if (as->flagmcp == as->mcp) { /* Drop test r,r instruction. */
+ MCode *p = as->mcp + ((LJ_64 && *as->mcp < XI_TESTb) ? 3 : 2);
+ if ((p[1] & 15) < 14) {
+ if ((p[1] & 15) >= 12) p[1] -= 4; /* L <->S, NL <-> NS */
+ as->flagmcp = NULL;
+ as->mcp = p;
+ } /* else: cannot transform LE/NLE to cc without use of OF. */
+ }
+ right = IR(rref)->r;
+ if (ra_hasreg(right)) {
+ rset_clear(allow, right);
+ ra_noweak(as, right);
+ }
+ dest = ra_dest(as, ir, allow);
+ if (lref == rref) {
+ right = dest;
+ } else if (ra_noreg(right) && !asm_isk32(as, rref, &k)) {
+ if (asm_swapops(as, ir)) {
+ IRRef tmp = lref; lref = rref; rref = tmp;
+ }
+ right = asm_fuseloadm(as, rref, rset_clear(allow, dest), irt_is64(ir->t));
+ }
+ if (irt_isguard(ir->t)) /* For IR_ADDOV etc. */
+ asm_guardcc(as, CC_O);
+ if (xa != XOg_X_IMUL) {
+ if (ra_hasreg(right))
+ emit_mrm(as, XO_ARITH(xa), REX_64IR(ir, dest), right);
+ else
+ emit_gri(as, XG_ARITHi(xa), REX_64IR(ir, dest), k);
+ } else if (ra_hasreg(right)) { /* IMUL r, mrm. */
+ emit_mrm(as, XO_IMUL, REX_64IR(ir, dest), right);
+ } else { /* IMUL r, r, k. */
+ /* NYI: use lea/shl/add/sub (FOLD only does 2^k) depending on CPU. */
+ Reg left = asm_fuseloadm(as, lref, RSET_GPR, irt_is64(ir->t));
+ x86Op xo;
+ if (checki8(k)) { emit_i8(as, k); xo = XO_IMULi8;
+ } else { emit_i32(as, k); xo = XO_IMULi; }
+ emit_mrm(as, xo, REX_64IR(ir, dest), left);
+ return;
+ }
+ ra_left(as, dest, lref);
+}
+
+/* LEA is really a 4-operand ADD with an independent destination register,
+** up to two source registers and an immediate. One register can be scaled
+** by 1, 2, 4 or 8. This can be used to avoid moves or to fuse several
+** instructions.
+**
+** Currently only a few common cases are supported:
+** - 3-operand ADD: y = a+b; y = a+k with a and b already allocated
+** - Left ADD fusion: y = (a+b)+k; y = (a+k)+b
+** - Right ADD fusion: y = a+(b+k)
+** The ommited variants have already been reduced by FOLD.
+**
+** There are more fusion opportunities, like gathering shifts or joining
+** common references. But these are probably not worth the trouble, since
+** array indexing is not decomposed and already makes use of all fields
+** of the ModRM operand.
+*/
+static int asm_lea(ASMState *as, IRIns *ir)
+{
+ IRIns *irl = IR(ir->op1);
+ IRIns *irr = IR(ir->op2);
+ RegSet allow = RSET_GPR;
+ Reg dest;
+ as->mrm.base = as->mrm.idx = RID_NONE;
+ as->mrm.scale = XM_SCALE1;
+ as->mrm.ofs = 0;
+ if (ra_hasreg(irl->r)) {
+ rset_clear(allow, irl->r);
+ ra_noweak(as, irl->r);
+ as->mrm.base = irl->r;
+ if (irref_isk(ir->op2) || ra_hasreg(irr->r)) {
+ /* The PHI renaming logic does a better job in some cases. */
+ if (ra_hasreg(ir->r) &&
+ ((irt_isphi(irl->t) && as->phireg[ir->r] == ir->op1) ||
+ (irt_isphi(irr->t) && as->phireg[ir->r] == ir->op2)))
+ return 0;
+ if (irref_isk(ir->op2)) {
+ as->mrm.ofs = irr->i;
+ } else {
+ rset_clear(allow, irr->r);
+ ra_noweak(as, irr->r);
+ as->mrm.idx = irr->r;
+ }
+ } else if (irr->o == IR_ADD && mayfuse(as, ir->op2) &&
+ irref_isk(irr->op2)) {
+ Reg idx = ra_alloc1(as, irr->op1, allow);
+ rset_clear(allow, idx);
+ as->mrm.idx = (uint8_t)idx;
+ as->mrm.ofs = IR(irr->op2)->i;
+ } else {
+ return 0;
+ }
+ } else if (ir->op1 != ir->op2 && irl->o == IR_ADD && mayfuse(as, ir->op1) &&
+ (irref_isk(ir->op2) || irref_isk(irl->op2))) {
+ Reg idx, base = ra_alloc1(as, irl->op1, allow);
+ rset_clear(allow, base);
+ as->mrm.base = (uint8_t)base;
+ if (irref_isk(ir->op2)) {
+ as->mrm.ofs = irr->i;
+ idx = ra_alloc1(as, irl->op2, allow);
+ } else {
+ as->mrm.ofs = IR(irl->op2)->i;
+ idx = ra_alloc1(as, ir->op2, allow);
+ }
+ rset_clear(allow, idx);
+ as->mrm.idx = (uint8_t)idx;
+ } else {
+ return 0;
+ }
+ dest = ra_dest(as, ir, allow);
+ emit_mrm(as, XO_LEA, dest, RID_MRM);
+ return 1; /* Success. */
+}
+
+static void asm_add(ASMState *as, IRIns *ir)
+{
+ if (irt_isnum(ir->t))
+ asm_fparith(as, ir, XO_ADDSD);
+ else if ((as->flags & JIT_F_LEA_AGU) || as->flagmcp == as->mcp ||
+ irt_is64(ir->t) || !asm_lea(as, ir))
+ asm_intarith(as, ir, XOg_ADD);
+}
+
+static void asm_neg_not(ASMState *as, IRIns *ir, x86Group3 xg)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ emit_rr(as, XO_GROUP3, REX_64IR(ir, xg), dest);
+ ra_left(as, dest, ir->op1);
+}
+
+static void asm_min_max(ASMState *as, IRIns *ir, int cc)
+{
+ Reg right, dest = ra_dest(as, ir, RSET_GPR);
+ IRRef lref = ir->op1, rref = ir->op2;
+ if (irref_isk(rref)) { lref = rref; rref = ir->op1; }
+ right = ra_alloc1(as, rref, rset_exclude(RSET_GPR, dest));
+ emit_rr(as, XO_CMOV + (cc<<24), REX_64IR(ir, dest), right);
+ emit_rr(as, XO_CMP, REX_64IR(ir, dest), right);
+ ra_left(as, dest, lref);
+}
+
+static void asm_bitswap(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ as->mcp = emit_op(XO_BSWAP + ((dest&7) << 24),
+ REX_64IR(ir, 0), dest, 0, as->mcp, 1);
+ ra_left(as, dest, ir->op1);
+}
+
+static void asm_bitshift(ASMState *as, IRIns *ir, x86Shift xs)
+{
+ IRRef rref = ir->op2;
+ IRIns *irr = IR(rref);
+ Reg dest;
+ if (irref_isk(rref)) { /* Constant shifts. */
+ int shift;
+ dest = ra_dest(as, ir, RSET_GPR);
+ shift = irr->i & (irt_is64(ir->t) ? 63 : 31);
+ switch (shift) {
+ case 0: break;
+ case 1: emit_rr(as, XO_SHIFT1, REX_64IR(ir, xs), dest); break;
+ default: emit_shifti(as, REX_64IR(ir, xs), dest, shift); break;
+ }
+ } else { /* Variable shifts implicitly use register cl (i.e. ecx). */
+ Reg right;
+ dest = ra_dest(as, ir, rset_exclude(RSET_GPR, RID_ECX));
+ if (dest == RID_ECX) {
+ dest = ra_scratch(as, rset_exclude(RSET_GPR, RID_ECX));
+ emit_rr(as, XO_MOV, RID_ECX, dest);
+ }
+ right = irr->r;
+ if (ra_noreg(right))
+ right = ra_allocref(as, rref, RID2RSET(RID_ECX));
+ else if (right != RID_ECX)
+ ra_scratch(as, RID2RSET(RID_ECX));
+ emit_rr(as, XO_SHIFTcl, REX_64IR(ir, xs), dest);
+ ra_noweak(as, right);
+ if (right != RID_ECX)
+ emit_rr(as, XO_MOV, RID_ECX, right);
+ }
+ ra_left(as, dest, ir->op1);
+ /*
+ ** Note: avoid using the flags resulting from a shift or rotate!
+ ** All of them cause a partial flag stall, except for r,1 shifts
+ ** (but not rotates). And a shift count of 0 leaves the flags unmodified.
+ */
+}
+
+/* -- Comparisons --------------------------------------------------------- */
+
+/* Virtual flags for unordered FP comparisons. */
+#define VCC_U 0x1000 /* Unordered. */
+#define VCC_P 0x2000 /* Needs extra CC_P branch. */
+#define VCC_S 0x4000 /* Swap avoids CC_P branch. */
+#define VCC_PS (VCC_P|VCC_S)
+
+/* Map of comparisons to flags. ORDER IR. */
+#define COMPFLAGS(ci, cin, cu, cf) ((ci)+((cu)<<4)+((cin)<<8)+(cf))
+static const uint16_t asm_compmap[IR_ABC+1] = {
+ /* signed non-eq unsigned flags */
+ /* LT */ COMPFLAGS(CC_GE, CC_G, CC_AE, VCC_PS),
+ /* GE */ COMPFLAGS(CC_L, CC_L, CC_B, 0),
+ /* LE */ COMPFLAGS(CC_G, CC_G, CC_A, VCC_PS),
+ /* GT */ COMPFLAGS(CC_LE, CC_L, CC_BE, 0),
+ /* ULT */ COMPFLAGS(CC_AE, CC_A, CC_AE, VCC_U),
+ /* UGE */ COMPFLAGS(CC_B, CC_B, CC_B, VCC_U|VCC_PS),
+ /* ULE */ COMPFLAGS(CC_A, CC_A, CC_A, VCC_U),
+ /* UGT */ COMPFLAGS(CC_BE, CC_B, CC_BE, VCC_U|VCC_PS),
+ /* EQ */ COMPFLAGS(CC_NE, CC_NE, CC_NE, VCC_P),
+ /* NE */ COMPFLAGS(CC_E, CC_E, CC_E, VCC_U|VCC_P),
+ /* ABC */ COMPFLAGS(CC_BE, CC_B, CC_BE, VCC_U|VCC_PS) /* Same as UGT. */
+};
+
+/* FP and integer comparisons. */
+static void asm_comp(ASMState *as, IRIns *ir, uint32_t cc)
+{
+ if (irt_isnum(ir->t)) {
+ IRRef lref = ir->op1;
+ IRRef rref = ir->op2;
+ Reg left, right;
+ MCLabel l_around;
+ /*
+ ** An extra CC_P branch is required to preserve ordered/unordered
+ ** semantics for FP comparisons. This can be avoided by swapping
+ ** the operands and inverting the condition (except for EQ and UNE).
+ ** So always try to swap if possible.
+ **
+ ** Another option would be to swap operands to achieve better memory
+ ** operand fusion. But it's unlikely that this outweighs the cost
+ ** of the extra branches.
+ */
+ if (cc & VCC_S) { /* Swap? */
+ IRRef tmp = lref; lref = rref; rref = tmp;
+ cc ^= (VCC_PS|(5<<4)); /* A <-> B, AE <-> BE, PS <-> none */
+ }
+ left = ra_alloc1(as, lref, RSET_FPR);
+ right = asm_fuseload(as, rref, rset_exclude(RSET_FPR, left));
+ l_around = emit_label(as);
+ asm_guardcc(as, cc >> 4);
+ if (cc & VCC_P) { /* Extra CC_P branch required? */
+ if (!(cc & VCC_U)) {
+ asm_guardcc(as, CC_P); /* Branch to exit for ordered comparisons. */
+ } else if (l_around != as->invmcp) {
+ emit_sjcc(as, CC_P, l_around); /* Branch around for unordered. */
+ } else {
+ /* Patched to mcloop by asm_loop_fixup. */
+ as->loopinv = 2;
+ if (as->realign)
+ emit_sjcc(as, CC_P, as->mcp);
+ else
+ emit_jcc(as, CC_P, as->mcp);
+ }
+ }
+ emit_mrm(as, XO_UCOMISD, left, right);
+ } else {
+ IRRef lref = ir->op1, rref = ir->op2;
+ IROp leftop = (IROp)(IR(lref)->o);
+ Reg r64 = REX_64IR(ir, 0);
+ int32_t imm = 0;
+ lua_assert(irt_is64(ir->t) || irt_isint(ir->t) ||
+ irt_isu32(ir->t) || irt_isaddr(ir->t) || irt_isu8(ir->t));
+ /* Swap constants (only for ABC) and fusable loads to the right. */
+ if (irref_isk(lref) || (!irref_isk(rref) && opisfusableload(leftop))) {
+ if ((cc & 0xc) == 0xc) cc ^= 0x53; /* L <-> G, LE <-> GE */
+ else if ((cc & 0xa) == 0x2) cc ^= 0x55; /* A <-> B, AE <-> BE */
+ lref = ir->op2; rref = ir->op1;
+ }
+ if (asm_isk32(as, rref, &imm)) {
+ IRIns *irl = IR(lref);
+ /* Check wether we can use test ins. Not for unsigned, since CF=0. */
+ int usetest = (imm == 0 && (cc & 0xa) != 0x2);
+ if (usetest && irl->o == IR_BAND && irl+1 == ir && !ra_used(irl)) {
+ /* Combine comp(BAND(ref, r/imm), 0) into test mrm, r/imm. */
+ Reg right, left = RID_NONE;
+ RegSet allow = RSET_GPR;
+ if (!asm_isk32(as, irl->op2, &imm)) {
+ left = ra_alloc1(as, irl->op2, allow);
+ rset_clear(allow, left);
+ } else { /* Try to Fuse IRT_I8/IRT_U8 loads, too. See below. */
+ IRIns *irll = IR(irl->op1);
+ if (opisfusableload((IROp)irll->o) &&
+ (irt_isi8(irll->t) || irt_isu8(irll->t))) {
+ IRType1 origt = irll->t; /* Temporarily flip types. */
+ irll->t.irt = (irll->t.irt & ~IRT_TYPE) | IRT_INT;
+ as->curins--; /* Skip to BAND to avoid failing in noconflict(). */
+ right = asm_fuseload(as, irl->op1, RSET_GPR);
+ as->curins++;
+ irll->t = origt;
+ if (right != RID_MRM) goto test_nofuse;
+ /* Fusion succeeded, emit test byte mrm, imm8. */
+ asm_guardcc(as, cc);
+ emit_i8(as, (imm & 0xff));
+ emit_mrm(as, XO_GROUP3b, XOg_TEST, RID_MRM);
+ return;
+ }
+ }
+ as->curins--; /* Skip to BAND to avoid failing in noconflict(). */
+ right = asm_fuseloadm(as, irl->op1, allow, r64);
+ as->curins++; /* Undo the above. */
+ test_nofuse:
+ asm_guardcc(as, cc);
+ if (ra_noreg(left)) {
+ emit_i32(as, imm);
+ emit_mrm(as, XO_GROUP3, r64 + XOg_TEST, right);
+ } else {
+ emit_mrm(as, XO_TEST, r64 + left, right);
+ }
+ } else {
+ Reg left;
+ if (opisfusableload((IROp)irl->o) &&
+ ((irt_isu8(irl->t) && checku8(imm)) ||
+ ((irt_isi8(irl->t) || irt_isi16(irl->t)) && checki8(imm)) ||
+ (irt_isu16(irl->t) && checku16(imm) && checki8((int16_t)imm)))) {
+ /* Only the IRT_INT case is fused by asm_fuseload.
+ ** The IRT_I8/IRT_U8 loads and some IRT_I16/IRT_U16 loads
+ ** are handled here.
+ ** Note that cmp word [mem], imm16 should not be generated,
+ ** since it has a length-changing prefix. Compares of a word
+ ** against a sign-extended imm8 are ok, however.
+ */
+ IRType1 origt = irl->t; /* Temporarily flip types. */
+ irl->t.irt = (irl->t.irt & ~IRT_TYPE) | IRT_INT;
+ left = asm_fuseload(as, lref, RSET_GPR);
+ irl->t = origt;
+ if (left == RID_MRM) { /* Fusion succeeded? */
+ if (irt_isu8(irl->t) || irt_isu16(irl->t))
+ cc >>= 4; /* Need unsigned compare. */
+ asm_guardcc(as, cc);
+ emit_i8(as, imm);
+ emit_mrm(as, (irt_isi8(origt) || irt_isu8(origt)) ?
+ XO_ARITHib : XO_ARITHiw8, r64 + XOg_CMP, RID_MRM);
+ return;
+ } /* Otherwise handle register case as usual. */
+ } else {
+ left = asm_fuseloadm(as, lref,
+ irt_isu8(ir->t) ? RSET_GPR8 : RSET_GPR, r64);
+ }
+ asm_guardcc(as, cc);
+ if (usetest && left != RID_MRM) {
+ /* Use test r,r instead of cmp r,0. */
+ x86Op xo = XO_TEST;
+ if (irt_isu8(ir->t)) {
+ lua_assert(ir->o == IR_EQ || ir->o == IR_NE);
+ xo = XO_TESTb;
+ if (!rset_test(RSET_RANGE(RID_EAX, RID_EBX+1), left)) {
+ if (LJ_64) {
+ left |= FORCE_REX;
+ } else {
+ emit_i32(as, 0xff);
+ emit_mrm(as, XO_GROUP3, XOg_TEST, left);
+ return;
+ }
+ }
+ }
+ emit_rr(as, xo, r64 + left, left);
+ if (irl+1 == ir) /* Referencing previous ins? */
+ as->flagmcp = as->mcp; /* Set flag to drop test r,r if possible. */
+ } else {
+ emit_gmrmi(as, XG_ARITHi(XOg_CMP), r64 + left, imm);
+ }
+ }
+ } else {
+ Reg left = ra_alloc1(as, lref, RSET_GPR);
+ Reg right = asm_fuseloadm(as, rref, rset_exclude(RSET_GPR, left), r64);
+ asm_guardcc(as, cc);
+ emit_mrm(as, XO_CMP, r64 + left, right);
+ }
+ }
+}
+
+#if LJ_32 && LJ_HASFFI
+/* 64 bit integer comparisons in 32 bit mode. */
+static void asm_comp_int64(ASMState *as, IRIns *ir)
+{
+ uint32_t cc = asm_compmap[(ir-1)->o];
+ RegSet allow = RSET_GPR;
+ Reg lefthi = RID_NONE, leftlo = RID_NONE;
+ Reg righthi = RID_NONE, rightlo = RID_NONE;
+ MCLabel l_around;
+ x86ModRM mrm;
+
+ as->curins--; /* Skip loword ins. Avoids failing in noconflict(), too. */
+
+ /* Allocate/fuse hiword operands. */
+ if (irref_isk(ir->op2)) {
+ lefthi = asm_fuseload(as, ir->op1, allow);
+ } else {
+ lefthi = ra_alloc1(as, ir->op1, allow);
+ rset_clear(allow, lefthi);
+ righthi = asm_fuseload(as, ir->op2, allow);
+ if (righthi == RID_MRM) {
+ if (as->mrm.base != RID_NONE) rset_clear(allow, as->mrm.base);
+ if (as->mrm.idx != RID_NONE) rset_clear(allow, as->mrm.idx);
+ } else {
+ rset_clear(allow, righthi);
+ }
+ }
+ mrm = as->mrm; /* Save state for hiword instruction. */
+
+ /* Allocate/fuse loword operands. */
+ if (irref_isk((ir-1)->op2)) {
+ leftlo = asm_fuseload(as, (ir-1)->op1, allow);
+ } else {
+ leftlo = ra_alloc1(as, (ir-1)->op1, allow);
+ rset_clear(allow, leftlo);
+ rightlo = asm_fuseload(as, (ir-1)->op2, allow);
+ }
+
+ /* All register allocations must be performed _before_ this point. */
+ l_around = emit_label(as);
+ as->invmcp = as->flagmcp = NULL; /* Cannot use these optimizations. */
+
+ /* Loword comparison and branch. */
+ asm_guardcc(as, cc >> 4); /* Always use unsigned compare for loword. */
+ if (ra_noreg(rightlo)) {
+ int32_t imm = IR((ir-1)->op2)->i;
+ if (imm == 0 && ((cc >> 4) & 0xa) != 0x2 && leftlo != RID_MRM)
+ emit_rr(as, XO_TEST, leftlo, leftlo);
+ else
+ emit_gmrmi(as, XG_ARITHi(XOg_CMP), leftlo, imm);
+ } else {
+ emit_mrm(as, XO_CMP, leftlo, rightlo);
+ }
+
+ /* Hiword comparison and branches. */
+ if ((cc & 15) != CC_NE)
+ emit_sjcc(as, CC_NE, l_around); /* Hiword unequal: skip loword compare. */
+ if ((cc & 15) != CC_E)
+ asm_guardcc(as, cc >> 8); /* Hiword compare without equality check. */
+ as->mrm = mrm; /* Restore state. */
+ if (ra_noreg(righthi)) {
+ int32_t imm = IR(ir->op2)->i;
+ if (imm == 0 && (cc & 0xa) != 0x2 && lefthi != RID_MRM)
+ emit_rr(as, XO_TEST, lefthi, lefthi);
+ else
+ emit_gmrmi(as, XG_ARITHi(XOg_CMP), lefthi, imm);
+ } else {
+ emit_mrm(as, XO_CMP, lefthi, righthi);
+ }
+}
+#endif
+
+/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */
+
+/* Hiword op of a split 64 bit op. Previous op must be the loword op. */
+static void asm_hiop(ASMState *as, IRIns *ir)
+{
+#if LJ_32 && LJ_HASFFI
+ /* HIOP is marked as a store because it needs its own DCE logic. */
+ int uselo = ra_used(ir-1), usehi = ra_used(ir); /* Loword/hiword used? */
+ if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1;
+ if ((ir-1)->o == IR_CONV) { /* Conversions to/from 64 bit. */
+ if (usehi || uselo) {
+ if (irt_isfp(ir->t))
+ asm_conv_fp_int64(as, ir);
+ else
+ asm_conv_int64_fp(as, ir);
+ }
+ as->curins--; /* Always skip the CONV. */
+ return;
+ } else if ((ir-1)->o <= IR_NE) { /* 64 bit integer comparisons. ORDER IR. */
+ asm_comp_int64(as, ir);
+ return;
+ } else if ((ir-1)->o == IR_XSTORE) {
+ if ((ir-1)->r != RID_SINK)
+ asm_fxstore(as, ir);
+ return;
+ }
+ if (!usehi) return; /* Skip unused hiword op for all remaining ops. */
+ switch ((ir-1)->o) {
+ case IR_ADD:
+ as->flagmcp = NULL;
+ as->curins--;
+ asm_intarith(as, ir, XOg_ADC);
+ asm_intarith(as, ir-1, XOg_ADD);
+ break;
+ case IR_SUB:
+ as->flagmcp = NULL;
+ as->curins--;
+ asm_intarith(as, ir, XOg_SBB);
+ asm_intarith(as, ir-1, XOg_SUB);
+ break;
+ case IR_NEG: {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ emit_rr(as, XO_GROUP3, XOg_NEG, dest);
+ emit_i8(as, 0);
+ emit_rr(as, XO_ARITHi8, XOg_ADC, dest);
+ ra_left(as, dest, ir->op1);
+ as->curins--;
+ asm_neg_not(as, ir-1, XOg_NEG);
+ break;
+ }
+ case IR_CALLN:
+ case IR_CALLXS:
+ if (!uselo)
+ ra_allocref(as, ir->op1, RID2RSET(RID_RETLO)); /* Mark lo op as used. */
+ break;
+ case IR_CNEWI:
+ /* Nothing to do here. Handled by CNEWI itself. */
+ break;
+ default: lua_assert(0); break;
+ }
+#else
+ UNUSED(as); UNUSED(ir); lua_assert(0); /* Unused on x64 or without FFI. */
+#endif
+}
+
+/* -- Stack handling ------------------------------------------------------ */
+
+/* Check Lua stack size for overflow. Use exit handler as fallback. */
+static void asm_stack_check(ASMState *as, BCReg topslot,
+ IRIns *irp, RegSet allow, ExitNo exitno)
+{
+ /* Try to get an unused temp. register, otherwise spill/restore eax. */
+ Reg pbase = irp ? irp->r : RID_BASE;
+ Reg r = allow ? rset_pickbot(allow) : RID_EAX;
+ emit_jcc(as, CC_B, exitstub_addr(as->J, exitno));
+ if (allow == RSET_EMPTY) /* Restore temp. register. */
+ emit_rmro(as, XO_MOV, r|REX_64, RID_ESP, 0);
+ else
+ ra_modified(as, r);
+ emit_gri(as, XG_ARITHi(XOg_CMP), r, (int32_t)(8*topslot));
+ if (ra_hasreg(pbase) && pbase != r)
+ emit_rr(as, XO_ARITH(XOg_SUB), r, pbase);
+ else
+ emit_rmro(as, XO_ARITH(XOg_SUB), r, RID_NONE,
+ ptr2addr(&J2G(as->J)->jit_base));
+ emit_rmro(as, XO_MOV, r, r, offsetof(lua_State, maxstack));
+ emit_getgl(as, r, jit_L);
+ if (allow == RSET_EMPTY) /* Spill temp. register. */
+ emit_rmro(as, XO_MOVto, r|REX_64, RID_ESP, 0);
+}
+
+/* Restore Lua stack from on-trace state. */
+static void asm_stack_restore(ASMState *as, SnapShot *snap)
+{
+ SnapEntry *map = &as->T->snapmap[snap->mapofs];
+ SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1];
+ MSize n, nent = snap->nent;
+ /* Store the value of all modified slots to the Lua stack. */
+ for (n = 0; n < nent; n++) {
+ SnapEntry sn = map[n];
+ BCReg s = snap_slot(sn);
+ int32_t ofs = 8*((int32_t)s-1);
+ IRRef ref = snap_ref(sn);
+ IRIns *ir = IR(ref);
+ if ((sn & SNAP_NORESTORE))
+ continue;
+ if (irt_isnum(ir->t)) {
+ Reg src = ra_alloc1(as, ref, RSET_FPR);
+ emit_rmro(as, XO_MOVSDto, src, RID_BASE, ofs);
+ } else {
+ lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) ||
+ (LJ_DUALNUM && irt_isinteger(ir->t)));
+ if (!irref_isk(ref)) {
+ Reg src = ra_alloc1(as, ref, rset_exclude(RSET_GPR, RID_BASE));
+ emit_movtomro(as, REX_64IR(ir, src), RID_BASE, ofs);
+ } else if (!irt_ispri(ir->t)) {
+ emit_movmroi(as, RID_BASE, ofs, ir->i);
+ }
+ if ((sn & (SNAP_CONT|SNAP_FRAME))) {
+ if (s != 0) /* Do not overwrite link to previous frame. */
+ emit_movmroi(as, RID_BASE, ofs+4, (int32_t)(*flinks--));
+ } else {
+ if (!(LJ_64 && irt_islightud(ir->t)))
+ emit_movmroi(as, RID_BASE, ofs+4, irt_toitype(ir->t));
+ }
+ }
+ checkmclim(as);
+ }
+ lua_assert(map + nent == flinks);
+}
+
+/* -- GC handling --------------------------------------------------------- */
+
+/* Check GC threshold and do one or more GC steps. */
+static void asm_gc_check(ASMState *as)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit];
+ IRRef args[2];
+ MCLabel l_end;
+ Reg tmp;
+ ra_evictset(as, RSET_SCRATCH);
+ l_end = emit_label(as);
+ /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */
+ asm_guardcc(as, CC_NE); /* Assumes asm_snap_prep() already done. */
+ emit_rr(as, XO_TEST, RID_RET, RID_RET);
+ args[0] = ASMREF_TMP1; /* global_State *g */
+ args[1] = ASMREF_TMP2; /* MSize steps */
+ asm_gencall(as, ci, args);
+ tmp = ra_releasetmp(as, ASMREF_TMP1);
+ emit_loada(as, tmp, J2G(as->J));
+ emit_loadi(as, ra_releasetmp(as, ASMREF_TMP2), as->gcsteps);
+ /* Jump around GC step if GC total < GC threshold. */
+ emit_sjcc(as, CC_B, l_end);
+ emit_opgl(as, XO_ARITH(XOg_CMP), tmp, gc.threshold);
+ emit_getgl(as, tmp, gc.total);
+ as->gcsteps = 0;
+ checkmclim(as);
+}
+
+/* -- Loop handling ------------------------------------------------------- */
+
+/* Fixup the loop branch. */
+static void asm_loop_fixup(ASMState *as)
+{
+ MCode *p = as->mctop;
+ MCode *target = as->mcp;
+ if (as->realign) { /* Realigned loops use short jumps. */
+ as->realign = NULL; /* Stop another retry. */
+ lua_assert(((intptr_t)target & 15) == 0);
+ if (as->loopinv) { /* Inverted loop branch? */
+ p -= 5;
+ p[0] = XI_JMP;
+ lua_assert(target - p >= -128);
+ p[-1] = (MCode)(target - p); /* Patch sjcc. */
+ if (as->loopinv == 2)
+ p[-3] = (MCode)(target - p + 2); /* Patch opt. short jp. */
+ } else {
+ lua_assert(target - p >= -128);
+ p[-1] = (MCode)(int8_t)(target - p); /* Patch short jmp. */
+ p[-2] = XI_JMPs;
+ }
+ } else {
+ MCode *newloop;
+ p[-5] = XI_JMP;
+ if (as->loopinv) { /* Inverted loop branch? */
+ /* asm_guardcc already inverted the jcc and patched the jmp. */
+ p -= 5;
+ newloop = target+4;
+ *(int32_t *)(p-4) = (int32_t)(target - p); /* Patch jcc. */
+ if (as->loopinv == 2) {
+ *(int32_t *)(p-10) = (int32_t)(target - p + 6); /* Patch opt. jp. */
+ newloop = target+8;
+ }
+ } else { /* Otherwise just patch jmp. */
+ *(int32_t *)(p-4) = (int32_t)(target - p);
+ newloop = target+3;
+ }
+ /* Realign small loops and shorten the loop branch. */
+ if (newloop >= p - 128) {
+ as->realign = newloop; /* Force a retry and remember alignment. */
+ as->curins = as->stopins; /* Abort asm_trace now. */
+ as->T->nins = as->orignins; /* Remove any added renames. */
+ }
+ }
+}
+
+/* -- Head of trace ------------------------------------------------------- */
+
+/* Coalesce BASE register for a root trace. */
+static void asm_head_root_base(ASMState *as)
+{
+ IRIns *ir = IR(REF_BASE);
+ Reg r = ir->r;
+ if (ra_hasreg(r)) {
+ ra_free(as, r);
+ if (rset_test(as->modset, r) || irt_ismarked(ir->t))
+ ir->r = RID_INIT; /* No inheritance for modified BASE register. */
+ if (r != RID_BASE)
+ emit_rr(as, XO_MOV, r, RID_BASE);
+ }
+}
+
+/* Coalesce or reload BASE register for a side trace. */
+static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow)
+{
+ IRIns *ir = IR(REF_BASE);
+ Reg r = ir->r;
+ if (ra_hasreg(r)) {
+ ra_free(as, r);
+ if (rset_test(as->modset, r) || irt_ismarked(ir->t))
+ ir->r = RID_INIT; /* No inheritance for modified BASE register. */
+ if (irp->r == r) {
+ rset_clear(allow, r); /* Mark same BASE register as coalesced. */
+ } else if (ra_hasreg(irp->r) && rset_test(as->freeset, irp->r)) {
+ rset_clear(allow, irp->r);
+ emit_rr(as, XO_MOV, r, irp->r); /* Move from coalesced parent reg. */
+ } else {
+ emit_getgl(as, r, jit_base); /* Otherwise reload BASE. */
+ }
+ }
+ return allow;
+}
+
+/* -- Tail of trace ------------------------------------------------------- */
+
+/* Fixup the tail code. */
+static void asm_tail_fixup(ASMState *as, TraceNo lnk)
+{
+ /* Note: don't use as->mcp swap + emit_*: emit_op overwrites more bytes. */
+ MCode *p = as->mctop;
+ MCode *target, *q;
+ int32_t spadj = as->T->spadjust;
+ if (spadj == 0) {
+ p -= ((as->flags & JIT_F_LEA_AGU) ? 7 : 6) + (LJ_64 ? 1 : 0);
+ } else {
+ MCode *p1;
+ /* Patch stack adjustment. */
+ if (checki8(spadj)) {
+ p -= 3;
+ p1 = p-6;
+ *p1 = (MCode)spadj;
+ } else {
+ p1 = p-9;
+ *(int32_t *)p1 = spadj;
+ }
+ if ((as->flags & JIT_F_LEA_AGU)) {
+#if LJ_64
+ p1[-4] = 0x48;
+#endif
+ p1[-3] = (MCode)XI_LEA;
+ p1[-2] = MODRM(checki8(spadj) ? XM_OFS8 : XM_OFS32, RID_ESP, RID_ESP);
+ p1[-1] = MODRM(XM_SCALE1, RID_ESP, RID_ESP);
+ } else {
+#if LJ_64
+ p1[-3] = 0x48;
+#endif
+ p1[-2] = (MCode)(checki8(spadj) ? XI_ARITHi8 : XI_ARITHi);
+ p1[-1] = MODRM(XM_REG, XOg_ADD, RID_ESP);
+ }
+ }
+ /* Patch exit branch. */
+ target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp;
+ *(int32_t *)(p-4) = jmprel(p, target);
+ p[-5] = XI_JMP;
+ /* Drop unused mcode tail. Fill with NOPs to make the prefetcher happy. */
+ for (q = as->mctop-1; q >= p; q--)
+ *q = XI_NOP;
+ as->mctop = p;
+}
+
+/* Prepare tail of code. */
+static void asm_tail_prep(ASMState *as)
+{
+ MCode *p = as->mctop;
+ /* Realign and leave room for backwards loop branch or exit branch. */
+ if (as->realign) {
+ int i = ((int)(intptr_t)as->realign) & 15;
+ /* Fill unused mcode tail with NOPs to make the prefetcher happy. */
+ while (i-- > 0)
+ *--p = XI_NOP;
+ as->mctop = p;
+ p -= (as->loopinv ? 5 : 2); /* Space for short/near jmp. */
+ } else {
+ p -= 5; /* Space for exit branch (near jmp). */
+ }
+ if (as->loopref) {
+ as->invmcp = as->mcp = p;
+ } else {
+ /* Leave room for ESP adjustment: add esp, imm or lea esp, [esp+imm] */
+ as->mcp = p - (((as->flags & JIT_F_LEA_AGU) ? 7 : 6) + (LJ_64 ? 1 : 0));
+ as->invmcp = NULL;
+ }
+}
+
+/* -- Instruction dispatch ------------------------------------------------ */
+
+/* Assemble a single instruction. */
+static void asm_ir(ASMState *as, IRIns *ir)
+{
+ switch ((IROp)ir->o) {
+ /* Miscellaneous ops. */
+ case IR_LOOP: asm_loop(as); break;
+ case IR_NOP: case IR_XBAR: lua_assert(!ra_used(ir)); break;
+ case IR_USE:
+ ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break;
+ case IR_PHI: asm_phi(as, ir); break;
+ case IR_HIOP: asm_hiop(as, ir); break;
+ case IR_GCSTEP: asm_gcstep(as, ir); break;
+
+ /* Guarded assertions. */
+ case IR_LT: case IR_GE: case IR_LE: case IR_GT:
+ case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT:
+ case IR_EQ: case IR_NE: case IR_ABC:
+ asm_comp(as, ir, asm_compmap[ir->o]);
+ break;
+
+ case IR_RETF: asm_retf(as, ir); break;
+
+ /* Bit ops. */
+ case IR_BNOT: asm_neg_not(as, ir, XOg_NOT); break;
+ case IR_BSWAP: asm_bitswap(as, ir); break;
+
+ case IR_BAND: asm_intarith(as, ir, XOg_AND); break;
+ case IR_BOR: asm_intarith(as, ir, XOg_OR); break;
+ case IR_BXOR: asm_intarith(as, ir, XOg_XOR); break;
+
+ case IR_BSHL: asm_bitshift(as, ir, XOg_SHL); break;
+ case IR_BSHR: asm_bitshift(as, ir, XOg_SHR); break;
+ case IR_BSAR: asm_bitshift(as, ir, XOg_SAR); break;
+ case IR_BROL: asm_bitshift(as, ir, XOg_ROL); break;
+ case IR_BROR: asm_bitshift(as, ir, XOg_ROR); break;
+
+ /* Arithmetic ops. */
+ case IR_ADD: asm_add(as, ir); break;
+ case IR_SUB:
+ if (irt_isnum(ir->t))
+ asm_fparith(as, ir, XO_SUBSD);
+ else /* Note: no need for LEA trick here. i-k is encoded as i+(-k). */
+ asm_intarith(as, ir, XOg_SUB);
+ break;
+ case IR_MUL:
+ if (irt_isnum(ir->t))
+ asm_fparith(as, ir, XO_MULSD);
+ else
+ asm_intarith(as, ir, XOg_X_IMUL);
+ break;
+ case IR_DIV:
+#if LJ_64 && LJ_HASFFI
+ if (!irt_isnum(ir->t))
+ asm_arith64(as, ir, irt_isi64(ir->t) ? IRCALL_lj_carith_divi64 :
+ IRCALL_lj_carith_divu64);
+ else
+#endif
+ asm_fparith(as, ir, XO_DIVSD);
+ break;
+ case IR_MOD:
+#if LJ_64 && LJ_HASFFI
+ if (!irt_isint(ir->t))
+ asm_arith64(as, ir, irt_isi64(ir->t) ? IRCALL_lj_carith_modi64 :
+ IRCALL_lj_carith_modu64);
+ else
+#endif
+ asm_intmod(as, ir);
+ break;
+
+ case IR_NEG:
+ if (irt_isnum(ir->t))
+ asm_fparith(as, ir, XO_XORPS);
+ else
+ asm_neg_not(as, ir, XOg_NEG);
+ break;
+ case IR_ABS: asm_fparith(as, ir, XO_ANDPS); break;
+
+ case IR_MIN:
+ if (irt_isnum(ir->t))
+ asm_fparith(as, ir, XO_MINSD);
+ else
+ asm_min_max(as, ir, CC_G);
+ break;
+ case IR_MAX:
+ if (irt_isnum(ir->t))
+ asm_fparith(as, ir, XO_MAXSD);
+ else
+ asm_min_max(as, ir, CC_L);
+ break;
+
+ case IR_FPMATH: case IR_ATAN2: case IR_LDEXP:
+ asm_fpmath(as, ir);
+ break;
+ case IR_POW:
+#if LJ_64 && LJ_HASFFI
+ if (!irt_isnum(ir->t))
+ asm_arith64(as, ir, irt_isi64(ir->t) ? IRCALL_lj_carith_powi64 :
+ IRCALL_lj_carith_powu64);
+ else
+#endif
+ asm_fppowi(as, ir);
+ break;
+
+ /* Overflow-checking arithmetic ops. Note: don't use LEA here! */
+ case IR_ADDOV: asm_intarith(as, ir, XOg_ADD); break;
+ case IR_SUBOV: asm_intarith(as, ir, XOg_SUB); break;
+ case IR_MULOV: asm_intarith(as, ir, XOg_X_IMUL); break;
+
+ /* Memory references. */
+ case IR_AREF: asm_aref(as, ir); break;
+ case IR_HREF: asm_href(as, ir); break;
+ case IR_HREFK: asm_hrefk(as, ir); break;
+ case IR_NEWREF: asm_newref(as, ir); break;
+ case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break;
+ case IR_FREF: asm_fref(as, ir); break;
+ case IR_STRREF: asm_strref(as, ir); break;
+
+ /* Loads and stores. */
+ case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:
+ asm_ahuvload(as, ir);
+ break;
+ case IR_FLOAD: case IR_XLOAD: asm_fxload(as, ir); break;
+ case IR_SLOAD: asm_sload(as, ir); break;
+
+ case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break;
+ case IR_FSTORE: case IR_XSTORE: asm_fxstore(as, ir); break;
+
+ /* Allocations. */
+ case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break;
+ case IR_TNEW: asm_tnew(as, ir); break;
+ case IR_TDUP: asm_tdup(as, ir); break;
+ case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break;
+
+ /* Write barriers. */
+ case IR_TBAR: asm_tbar(as, ir); break;
+ case IR_OBAR: asm_obar(as, ir); break;
+
+ /* Type conversions. */
+ case IR_TOBIT: asm_tobit(as, ir); break;
+ case IR_CONV: asm_conv(as, ir); break;
+ case IR_TOSTR: asm_tostr(as, ir); break;
+ case IR_STRTO: asm_strto(as, ir); break;
+
+ /* Calls. */
+ case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break;
+ case IR_CALLXS: asm_callx(as, ir); break;
+ case IR_CARG: break;
+
+ default:
+ setintV(&as->J->errinfo, ir->o);
+ lj_trace_err_info(as->J, LJ_TRERR_NYIIR);
+ break;
+ }
+}
+
+/* -- Trace setup --------------------------------------------------------- */
+
+/* Ensure there are enough stack slots for call arguments. */
+static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)
+{
+ IRRef args[CCI_NARGS_MAX*2];
+ int nslots;
+ asm_collectargs(as, ir, ci, args);
+ nslots = asm_count_call_slots(as, ci, args);
+ if (nslots > as->evenspill) /* Leave room for args in stack slots. */
+ as->evenspill = nslots;
+#if LJ_64
+ return irt_isfp(ir->t) ? REGSP_HINT(RID_FPRET) : REGSP_HINT(RID_RET);
+#else
+ return irt_isfp(ir->t) ? REGSP_INIT : REGSP_HINT(RID_RET);
+#endif
+}
+
+/* Target-specific setup. */
+static void asm_setup_target(ASMState *as)
+{
+ asm_exitstub_setup(as, as->T->nsnap);
+}
+
+/* -- Trace patching ------------------------------------------------------ */
+
+static const uint8_t map_op1[256] = {
+0x92,0x92,0x92,0x92,0x52,0x45,0x51,0x51,0x92,0x92,0x92,0x92,0x52,0x45,0x51,0x20,
+0x92,0x92,0x92,0x92,0x52,0x45,0x51,0x51,0x92,0x92,0x92,0x92,0x52,0x45,0x51,0x51,
+0x92,0x92,0x92,0x92,0x52,0x45,0x10,0x51,0x92,0x92,0x92,0x92,0x52,0x45,0x10,0x51,
+0x92,0x92,0x92,0x92,0x52,0x45,0x10,0x51,0x92,0x92,0x92,0x92,0x52,0x45,0x10,0x51,
+#if LJ_64
+0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,
+#else
+0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,
+#endif
+0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,
+0x51,0x51,0x92,0x92,0x10,0x10,0x12,0x11,0x45,0x86,0x52,0x93,0x51,0x51,0x51,0x51,
+0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,
+0x93,0x86,0x93,0x93,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,
+0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x47,0x51,0x51,0x51,0x51,0x51,
+#if LJ_64
+0x59,0x59,0x59,0x59,0x51,0x51,0x51,0x51,0x52,0x45,0x51,0x51,0x51,0x51,0x51,0x51,
+#else
+0x55,0x55,0x55,0x55,0x51,0x51,0x51,0x51,0x52,0x45,0x51,0x51,0x51,0x51,0x51,0x51,
+#endif
+0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,
+0x93,0x93,0x53,0x51,0x70,0x71,0x93,0x86,0x54,0x51,0x53,0x51,0x51,0x52,0x51,0x51,
+0x92,0x92,0x92,0x92,0x52,0x52,0x51,0x51,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,
+0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x45,0x45,0x47,0x52,0x51,0x51,0x51,0x51,
+0x10,0x51,0x10,0x10,0x51,0x51,0x63,0x66,0x51,0x51,0x51,0x51,0x51,0x51,0x92,0x92
+};
+
+static const uint8_t map_op2[256] = {
+0x93,0x93,0x93,0x93,0x52,0x52,0x52,0x52,0x52,0x52,0x51,0x52,0x51,0x93,0x52,0x94,
+0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+0x53,0x53,0x53,0x53,0x53,0x53,0x53,0x53,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x34,0x51,0x35,0x51,0x51,0x51,0x51,0x51,
+0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+0x53,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+0x94,0x54,0x54,0x54,0x93,0x93,0x93,0x52,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,
+0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+0x52,0x52,0x52,0x93,0x94,0x93,0x51,0x51,0x52,0x52,0x52,0x93,0x94,0x93,0x93,0x93,
+0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x94,0x93,0x93,0x93,0x93,0x93,
+0x93,0x93,0x94,0x93,0x94,0x94,0x94,0x93,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,
+0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x52
+};
+
+static uint32_t asm_x86_inslen(const uint8_t* p)
+{
+ uint32_t result = 0;
+ uint32_t prefixes = 0;
+ uint32_t x = map_op1[*p];
+ for (;;) {
+ switch (x >> 4) {
+ case 0: return result + x + (prefixes & 4);
+ case 1: prefixes |= x; x = map_op1[*++p]; result++; break;
+ case 2: x = map_op2[*++p]; break;
+ case 3: p++; goto mrm;
+ case 4: result -= (prefixes & 2); /* fallthrough */
+ case 5: return result + (x & 15);
+ case 6: /* Group 3. */
+ if (p[1] & 0x38) x = 2;
+ else if ((prefixes & 2) && (x == 0x66)) x = 4;
+ goto mrm;
+ case 7: /* VEX c4/c5. */
+ if (LJ_32 && p[1] < 0xc0) {
+ x = 2;
+ goto mrm;
+ }
+ if (x == 0x70) {
+ x = *++p & 0x1f;
+ result++;
+ if (x >= 2) {
+ p += 2;
+ result += 2;
+ goto mrm;
+ }
+ }
+ p++;
+ result++;
+ x = map_op2[*++p];
+ break;
+ case 8: result -= (prefixes & 2); /* fallthrough */
+ case 9: mrm: /* ModR/M and possibly SIB. */
+ result += (x & 15);
+ x = *++p;
+ switch (x >> 6) {
+ case 0: if ((x & 7) == 5) return result + 4; break;
+ case 1: result++; break;
+ case 2: result += 4; break;
+ case 3: return result;
+ }
+ if ((x & 7) == 4) {
+ result++;
+ if (x < 0x40 && (p[1] & 7) == 5) result += 4;
+ }
+ return result;
+ }
+ }
+}
+
+/* Patch exit jumps of existing machine code to a new target. */
+void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target)
+{
+ MCode *p = T->mcode;
+ MCode *mcarea = lj_mcode_patch(J, p, 0);
+ MSize len = T->szmcode;
+ MCode *px = exitstub_addr(J, exitno) - 6;
+ MCode *pe = p+len-6;
+ uint32_t stateaddr = u32ptr(&J2G(J)->vmstate);
+ if (len > 5 && p[len-5] == XI_JMP && p+len-6 + *(int32_t *)(p+len-4) == px)
+ *(int32_t *)(p+len-4) = jmprel(p+len, target);
+ /* Do not patch parent exit for a stack check. Skip beyond vmstate update. */
+ for (; p < pe; p += asm_x86_inslen(p))
+ if (*(uint32_t *)(p+(LJ_64 ? 3 : 2)) == stateaddr && p[0] == XI_MOVmi)
+ break;
+ lua_assert(p < pe);
+ for (; p < pe; p += asm_x86_inslen(p))
+ if ((*(uint16_t *)p & 0xf0ff) == 0x800f && p + *(int32_t *)(p+2) == px)
+ *(int32_t *)(p+2) = jmprel(p+6, target);
+ lj_mcode_sync(T->mcode, T->mcode + T->szmcode);
+ lj_mcode_patch(J, mcarea, 1);
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_bc.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_bc.h
new file mode 100644
index 0000000..108c10f
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_bc.h
@@ -0,0 +1,261 @@
+/*
+** Bytecode instruction format.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_BC_H
+#define _LJ_BC_H
+
+#include "lj_def.h"
+#include "lj_arch.h"
+
+/* Bytecode instruction format, 32 bit wide, fields of 8 or 16 bit:
+**
+** +----+----+----+----+
+** | B | C | A | OP | Format ABC
+** +----+----+----+----+
+** | D | A | OP | Format AD
+** +--------------------
+** MSB LSB
+**
+** In-memory instructions are always stored in host byte order.
+*/
+
+/* Operand ranges and related constants. */
+#define BCMAX_A 0xff
+#define BCMAX_B 0xff
+#define BCMAX_C 0xff
+#define BCMAX_D 0xffff
+#define BCBIAS_J 0x8000
+#define NO_REG BCMAX_A
+#define NO_JMP (~(BCPos)0)
+
+/* Macros to get instruction fields. */
+#define bc_op(i) ((BCOp)((i)&0xff))
+#define bc_a(i) ((BCReg)(((i)>>8)&0xff))
+#define bc_b(i) ((BCReg)((i)>>24))
+#define bc_c(i) ((BCReg)(((i)>>16)&0xff))
+#define bc_d(i) ((BCReg)((i)>>16))
+#define bc_j(i) ((ptrdiff_t)bc_d(i)-BCBIAS_J)
+
+/* Macros to set instruction fields. */
+#define setbc_byte(p, x, ofs) \
+ ((uint8_t *)(p))[LJ_ENDIAN_SELECT(ofs, 3-ofs)] = (uint8_t)(x)
+#define setbc_op(p, x) setbc_byte(p, (x), 0)
+#define setbc_a(p, x) setbc_byte(p, (x), 1)
+#define setbc_b(p, x) setbc_byte(p, (x), 3)
+#define setbc_c(p, x) setbc_byte(p, (x), 2)
+#define setbc_d(p, x) \
+ ((uint16_t *)(p))[LJ_ENDIAN_SELECT(1, 0)] = (uint16_t)(x)
+#define setbc_j(p, x) setbc_d(p, (BCPos)((int32_t)(x)+BCBIAS_J))
+
+/* Macros to compose instructions. */
+#define BCINS_ABC(o, a, b, c) \
+ (((BCIns)(o))|((BCIns)(a)<<8)|((BCIns)(b)<<24)|((BCIns)(c)<<16))
+#define BCINS_AD(o, a, d) \
+ (((BCIns)(o))|((BCIns)(a)<<8)|((BCIns)(d)<<16))
+#define BCINS_AJ(o, a, j) BCINS_AD(o, a, (BCPos)((int32_t)(j)+BCBIAS_J))
+
+/* Bytecode instruction definition. Order matters, see below.
+**
+** (name, filler, Amode, Bmode, Cmode or Dmode, metamethod)
+**
+** The opcode name suffixes specify the type for RB/RC or RD:
+** V = variable slot
+** S = string const
+** N = number const
+** P = primitive type (~itype)
+** B = unsigned byte literal
+** M = multiple args/results
+*/
+#define BCDEF(_) \
+ /* Comparison ops. ORDER OPR. */ \
+ _(ISLT, var, ___, var, lt) \
+ _(ISGE, var, ___, var, lt) \
+ _(ISLE, var, ___, var, le) \
+ _(ISGT, var, ___, var, le) \
+ \
+ _(ISEQV, var, ___, var, eq) \
+ _(ISNEV, var, ___, var, eq) \
+ _(ISEQS, var, ___, str, eq) \
+ _(ISNES, var, ___, str, eq) \
+ _(ISEQN, var, ___, num, eq) \
+ _(ISNEN, var, ___, num, eq) \
+ _(ISEQP, var, ___, pri, eq) \
+ _(ISNEP, var, ___, pri, eq) \
+ \
+ /* Unary test and copy ops. */ \
+ _(ISTC, dst, ___, var, ___) \
+ _(ISFC, dst, ___, var, ___) \
+ _(IST, ___, ___, var, ___) \
+ _(ISF, ___, ___, var, ___) \
+ \
+ /* Unary ops. */ \
+ _(MOV, dst, ___, var, ___) \
+ _(NOT, dst, ___, var, ___) \
+ _(UNM, dst, ___, var, unm) \
+ _(LEN, dst, ___, var, len) \
+ \
+ /* Binary ops. ORDER OPR. VV last, POW must be next. */ \
+ _(ADDVN, dst, var, num, add) \
+ _(SUBVN, dst, var, num, sub) \
+ _(MULVN, dst, var, num, mul) \
+ _(DIVVN, dst, var, num, div) \
+ _(MODVN, dst, var, num, mod) \
+ \
+ _(ADDNV, dst, var, num, add) \
+ _(SUBNV, dst, var, num, sub) \
+ _(MULNV, dst, var, num, mul) \
+ _(DIVNV, dst, var, num, div) \
+ _(MODNV, dst, var, num, mod) \
+ \
+ _(ADDVV, dst, var, var, add) \
+ _(SUBVV, dst, var, var, sub) \
+ _(MULVV, dst, var, var, mul) \
+ _(DIVVV, dst, var, var, div) \
+ _(MODVV, dst, var, var, mod) \
+ \
+ _(POW, dst, var, var, pow) \
+ _(CAT, dst, rbase, rbase, concat) \
+ \
+ /* Constant ops. */ \
+ _(KSTR, dst, ___, str, ___) \
+ _(KCDATA, dst, ___, cdata, ___) \
+ _(KSHORT, dst, ___, lits, ___) \
+ _(KNUM, dst, ___, num, ___) \
+ _(KPRI, dst, ___, pri, ___) \
+ _(KNIL, base, ___, base, ___) \
+ \
+ /* Upvalue and function ops. */ \
+ _(UGET, dst, ___, uv, ___) \
+ _(USETV, uv, ___, var, ___) \
+ _(USETS, uv, ___, str, ___) \
+ _(USETN, uv, ___, num, ___) \
+ _(USETP, uv, ___, pri, ___) \
+ _(UCLO, rbase, ___, jump, ___) \
+ _(FNEW, dst, ___, func, gc) \
+ \
+ /* Table ops. */ \
+ _(TNEW, dst, ___, lit, gc) \
+ _(TDUP, dst, ___, tab, gc) \
+ _(GGET, dst, ___, str, index) \
+ _(GSET, var, ___, str, newindex) \
+ _(TGETV, dst, var, var, index) \
+ _(TGETS, dst, var, str, index) \
+ _(TGETB, dst, var, lit, index) \
+ _(TSETV, var, var, var, newindex) \
+ _(TSETS, var, var, str, newindex) \
+ _(TSETB, var, var, lit, newindex) \
+ _(TSETM, base, ___, num, newindex) \
+ \
+ /* Calls and vararg handling. T = tail call. */ \
+ _(CALLM, base, lit, lit, call) \
+ _(CALL, base, lit, lit, call) \
+ _(CALLMT, base, ___, lit, call) \
+ _(CALLT, base, ___, lit, call) \
+ _(ITERC, base, lit, lit, call) \
+ _(ITERN, base, lit, lit, call) \
+ _(VARG, base, lit, lit, ___) \
+ _(ISNEXT, base, ___, jump, ___) \
+ \
+ /* Returns. */ \
+ _(RETM, base, ___, lit, ___) \
+ _(RET, rbase, ___, lit, ___) \
+ _(RET0, rbase, ___, lit, ___) \
+ _(RET1, rbase, ___, lit, ___) \
+ \
+ /* Loops and branches. I/J = interp/JIT, I/C/L = init/call/loop. */ \
+ _(FORI, base, ___, jump, ___) \
+ _(JFORI, base, ___, jump, ___) \
+ \
+ _(FORL, base, ___, jump, ___) \
+ _(IFORL, base, ___, jump, ___) \
+ _(JFORL, base, ___, lit, ___) \
+ \
+ _(ITERL, base, ___, jump, ___) \
+ _(IITERL, base, ___, jump, ___) \
+ _(JITERL, base, ___, lit, ___) \
+ \
+ _(LOOP, rbase, ___, jump, ___) \
+ _(ILOOP, rbase, ___, jump, ___) \
+ _(JLOOP, rbase, ___, lit, ___) \
+ \
+ _(JMP, rbase, ___, jump, ___) \
+ \
+ /* Function headers. I/J = interp/JIT, F/V/C = fixarg/vararg/C func. */ \
+ _(FUNCF, rbase, ___, ___, ___) \
+ _(IFUNCF, rbase, ___, ___, ___) \
+ _(JFUNCF, rbase, ___, lit, ___) \
+ _(FUNCV, rbase, ___, ___, ___) \
+ _(IFUNCV, rbase, ___, ___, ___) \
+ _(JFUNCV, rbase, ___, lit, ___) \
+ _(FUNCC, rbase, ___, ___, ___) \
+ _(FUNCCW, rbase, ___, ___, ___)
+
+/* Bytecode opcode numbers. */
+typedef enum {
+#define BCENUM(name, ma, mb, mc, mt) BC_##name,
+BCDEF(BCENUM)
+#undef BCENUM
+ BC__MAX
+} BCOp;
+
+LJ_STATIC_ASSERT((int)BC_ISEQV+1 == (int)BC_ISNEV);
+LJ_STATIC_ASSERT(((int)BC_ISEQV^1) == (int)BC_ISNEV);
+LJ_STATIC_ASSERT(((int)BC_ISEQS^1) == (int)BC_ISNES);
+LJ_STATIC_ASSERT(((int)BC_ISEQN^1) == (int)BC_ISNEN);
+LJ_STATIC_ASSERT(((int)BC_ISEQP^1) == (int)BC_ISNEP);
+LJ_STATIC_ASSERT(((int)BC_ISLT^1) == (int)BC_ISGE);
+LJ_STATIC_ASSERT(((int)BC_ISLE^1) == (int)BC_ISGT);
+LJ_STATIC_ASSERT(((int)BC_ISLT^3) == (int)BC_ISGT);
+LJ_STATIC_ASSERT((int)BC_IST-(int)BC_ISTC == (int)BC_ISF-(int)BC_ISFC);
+LJ_STATIC_ASSERT((int)BC_CALLT-(int)BC_CALL == (int)BC_CALLMT-(int)BC_CALLM);
+LJ_STATIC_ASSERT((int)BC_CALLMT + 1 == (int)BC_CALLT);
+LJ_STATIC_ASSERT((int)BC_RETM + 1 == (int)BC_RET);
+LJ_STATIC_ASSERT((int)BC_FORL + 1 == (int)BC_IFORL);
+LJ_STATIC_ASSERT((int)BC_FORL + 2 == (int)BC_JFORL);
+LJ_STATIC_ASSERT((int)BC_ITERL + 1 == (int)BC_IITERL);
+LJ_STATIC_ASSERT((int)BC_ITERL + 2 == (int)BC_JITERL);
+LJ_STATIC_ASSERT((int)BC_LOOP + 1 == (int)BC_ILOOP);
+LJ_STATIC_ASSERT((int)BC_LOOP + 2 == (int)BC_JLOOP);
+LJ_STATIC_ASSERT((int)BC_FUNCF + 1 == (int)BC_IFUNCF);
+LJ_STATIC_ASSERT((int)BC_FUNCF + 2 == (int)BC_JFUNCF);
+LJ_STATIC_ASSERT((int)BC_FUNCV + 1 == (int)BC_IFUNCV);
+LJ_STATIC_ASSERT((int)BC_FUNCV + 2 == (int)BC_JFUNCV);
+
+/* This solves a circular dependency problem, change as needed. */
+#define FF_next_N 4
+
+/* Stack slots used by FORI/FORL, relative to operand A. */
+enum {
+ FORL_IDX, FORL_STOP, FORL_STEP, FORL_EXT
+};
+
+/* Bytecode operand modes. ORDER BCMode */
+typedef enum {
+ BCMnone, BCMdst, BCMbase, BCMvar, BCMrbase, BCMuv, /* Mode A must be <= 7 */
+ BCMlit, BCMlits, BCMpri, BCMnum, BCMstr, BCMtab, BCMfunc, BCMjump, BCMcdata,
+ BCM_max
+} BCMode;
+#define BCM___ BCMnone
+
+#define bcmode_a(op) ((BCMode)(lj_bc_mode[op] & 7))
+#define bcmode_b(op) ((BCMode)((lj_bc_mode[op]>>3) & 15))
+#define bcmode_c(op) ((BCMode)((lj_bc_mode[op]>>7) & 15))
+#define bcmode_d(op) bcmode_c(op)
+#define bcmode_hasd(op) ((lj_bc_mode[op] & (15<<3)) == (BCMnone<<3))
+#define bcmode_mm(op) ((MMS)(lj_bc_mode[op]>>11))
+
+#define BCMODE(name, ma, mb, mc, mm) \
+ (BCM##ma|(BCM##mb<<3)|(BCM##mc<<7)|(MM_##mm<<11)),
+#define BCMODE_FF 0
+
+static LJ_AINLINE int bc_isret(BCOp op)
+{
+ return (op == BC_RETM || op == BC_RET || op == BC_RET0 || op == BC_RET1);
+}
+
+LJ_DATA const uint16_t lj_bc_mode[];
+LJ_DATA const uint16_t lj_bc_ofs[];
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_bcdump.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_bcdump.h
new file mode 100644
index 0000000..ba53c0a
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_bcdump.h
@@ -0,0 +1,66 @@
+/*
+** Bytecode dump definitions.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_BCDUMP_H
+#define _LJ_BCDUMP_H
+
+#include "lj_obj.h"
+#include "lj_lex.h"
+
+/* -- Bytecode dump format ------------------------------------------------ */
+
+/*
+** dump = header proto+ 0U
+** header = ESC 'L' 'J' versionB flagsU [namelenU nameB*]
+** proto = lengthU pdata
+** pdata = phead bcinsW* uvdataH* kgc* knum* [debugB*]
+** phead = flagsB numparamsB framesizeB numuvB numkgcU numknU numbcU
+** [debuglenU [firstlineU numlineU]]
+** kgc = kgctypeU { ktab | (loU hiU) | (rloU rhiU iloU ihiU) | strB* }
+** knum = intU0 | (loU1 hiU)
+** ktab = narrayU nhashU karray* khash*
+** karray = ktabk
+** khash = ktabk ktabk
+** ktabk = ktabtypeU { intU | (loU hiU) | strB* }
+**
+** B = 8 bit, H = 16 bit, W = 32 bit, U = ULEB128 of W, U0/U1 = ULEB128 of W+1
+*/
+
+/* Bytecode dump header. */
+#define BCDUMP_HEAD1 0x1b
+#define BCDUMP_HEAD2 0x4c
+#define BCDUMP_HEAD3 0x4a
+
+/* If you perform *any* kind of private modifications to the bytecode itself
+** or to the dump format, you *must* set BCDUMP_VERSION to 0x80 or higher.
+*/
+#define BCDUMP_VERSION 1
+
+/* Compatibility flags. */
+#define BCDUMP_F_BE 0x01
+#define BCDUMP_F_STRIP 0x02
+#define BCDUMP_F_FFI 0x04
+
+#define BCDUMP_F_KNOWN (BCDUMP_F_FFI*2-1)
+
+/* Type codes for the GC constants of a prototype. Plus length for strings. */
+enum {
+ BCDUMP_KGC_CHILD, BCDUMP_KGC_TAB, BCDUMP_KGC_I64, BCDUMP_KGC_U64,
+ BCDUMP_KGC_COMPLEX, BCDUMP_KGC_STR
+};
+
+/* Type codes for the keys/values of a constant table. */
+enum {
+ BCDUMP_KTAB_NIL, BCDUMP_KTAB_FALSE, BCDUMP_KTAB_TRUE,
+ BCDUMP_KTAB_INT, BCDUMP_KTAB_NUM, BCDUMP_KTAB_STR
+};
+
+/* -- Bytecode reader/writer ---------------------------------------------- */
+
+LJ_FUNC int lj_bcwrite(lua_State *L, GCproto *pt, lua_Writer writer,
+ void *data, int strip);
+LJ_FUNC GCproto *lj_bcread(LexState *ls);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_carith.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_carith.h
new file mode 100644
index 0000000..82fc824
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_carith.h
@@ -0,0 +1,28 @@
+/*
+** C data arithmetic.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_CARITH_H
+#define _LJ_CARITH_H
+
+#include "lj_obj.h"
+
+#if LJ_HASFFI
+
+LJ_FUNC int lj_carith_op(lua_State *L, MMS mm);
+LJ_FUNC int lj_carith_len(lua_State *L);
+
+#if LJ_32 && LJ_HASJIT
+LJ_FUNC int64_t lj_carith_mul64(int64_t x, int64_t k);
+#endif
+LJ_FUNC uint64_t lj_carith_divu64(uint64_t a, uint64_t b);
+LJ_FUNC int64_t lj_carith_divi64(int64_t a, int64_t b);
+LJ_FUNC uint64_t lj_carith_modu64(uint64_t a, uint64_t b);
+LJ_FUNC int64_t lj_carith_modi64(int64_t a, int64_t b);
+LJ_FUNC uint64_t lj_carith_powu64(uint64_t x, uint64_t k);
+LJ_FUNC int64_t lj_carith_powi64(int64_t x, int64_t k);
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ccall.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ccall.h
new file mode 100644
index 0000000..9089e6c
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ccall.h
@@ -0,0 +1,171 @@
+/*
+** FFI C call handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_CCALL_H
+#define _LJ_CCALL_H
+
+#include "lj_obj.h"
+#include "lj_ctype.h"
+
+#if LJ_HASFFI
+
+/* -- C calling conventions ----------------------------------------------- */
+
+#if LJ_TARGET_X86ORX64
+
+#if LJ_TARGET_X86
+#define CCALL_NARG_GPR 2 /* For fastcall arguments. */
+#define CCALL_NARG_FPR 0
+#define CCALL_NRET_GPR 2
+#define CCALL_NRET_FPR 1 /* For FP results on x87 stack. */
+#define CCALL_ALIGN_STACKARG 0 /* Don't align argument on stack. */
+#elif LJ_ABI_WIN
+#define CCALL_NARG_GPR 4
+#define CCALL_NARG_FPR 4
+#define CCALL_NRET_GPR 1
+#define CCALL_NRET_FPR 1
+#define CCALL_SPS_EXTRA 4
+#else
+#define CCALL_NARG_GPR 6
+#define CCALL_NARG_FPR 8
+#define CCALL_NRET_GPR 2
+#define CCALL_NRET_FPR 2
+#define CCALL_VECTOR_REG 1 /* Pass vectors in registers. */
+#endif
+
+#define CCALL_SPS_FREE 1
+#define CCALL_ALIGN_CALLSTATE 16
+
+typedef LJ_ALIGN(16) union FPRArg {
+ double d[2];
+ float f[4];
+ uint8_t b[16];
+ uint16_t s[8];
+ int i[4];
+ int64_t l[2];
+} FPRArg;
+
+typedef intptr_t GPRArg;
+
+#elif LJ_TARGET_ARM
+
+#define CCALL_NARG_GPR 4
+#define CCALL_NRET_GPR 2 /* For softfp double. */
+#if LJ_ABI_SOFTFP
+#define CCALL_NARG_FPR 0
+#define CCALL_NRET_FPR 0
+#else
+#define CCALL_NARG_FPR 8
+#define CCALL_NRET_FPR 4
+#endif
+#define CCALL_SPS_FREE 0
+
+typedef intptr_t GPRArg;
+typedef union FPRArg {
+ double d;
+ float f[2];
+} FPRArg;
+
+#elif LJ_TARGET_PPC
+
+#define CCALL_NARG_GPR 8
+#define CCALL_NARG_FPR 8
+#define CCALL_NRET_GPR 4 /* For complex double. */
+#define CCALL_NRET_FPR 1
+#define CCALL_SPS_EXTRA 4
+#define CCALL_SPS_FREE 0
+
+typedef intptr_t GPRArg;
+typedef double FPRArg;
+
+#elif LJ_TARGET_PPCSPE
+
+#define CCALL_NARG_GPR 8
+#define CCALL_NARG_FPR 0
+#define CCALL_NRET_GPR 4 /* For softfp complex double. */
+#define CCALL_NRET_FPR 0
+#define CCALL_SPS_FREE 0 /* NYI */
+
+typedef intptr_t GPRArg;
+
+#elif LJ_TARGET_MIPS
+
+#define CCALL_NARG_GPR 4
+#define CCALL_NARG_FPR 2
+#define CCALL_NRET_GPR 2
+#define CCALL_NRET_FPR 2
+#define CCALL_SPS_EXTRA 7
+#define CCALL_SPS_FREE 1
+
+typedef intptr_t GPRArg;
+typedef union FPRArg {
+ double d;
+ struct { LJ_ENDIAN_LOHI(float f; , float g;) };
+} FPRArg;
+
+#else
+#error "Missing calling convention definitions for this architecture"
+#endif
+
+#ifndef CCALL_SPS_EXTRA
+#define CCALL_SPS_EXTRA 0
+#endif
+#ifndef CCALL_VECTOR_REG
+#define CCALL_VECTOR_REG 0
+#endif
+#ifndef CCALL_ALIGN_STACKARG
+#define CCALL_ALIGN_STACKARG 1
+#endif
+#ifndef CCALL_ALIGN_CALLSTATE
+#define CCALL_ALIGN_CALLSTATE 8
+#endif
+
+#define CCALL_NUM_GPR \
+ (CCALL_NARG_GPR > CCALL_NRET_GPR ? CCALL_NARG_GPR : CCALL_NRET_GPR)
+#define CCALL_NUM_FPR \
+ (CCALL_NARG_FPR > CCALL_NRET_FPR ? CCALL_NARG_FPR : CCALL_NRET_FPR)
+
+/* Check against constants in lj_ctype.h. */
+LJ_STATIC_ASSERT(CCALL_NUM_GPR <= CCALL_MAX_GPR);
+LJ_STATIC_ASSERT(CCALL_NUM_FPR <= CCALL_MAX_FPR);
+
+#define CCALL_MAXSTACK 32
+
+/* -- C call state -------------------------------------------------------- */
+
+typedef LJ_ALIGN(CCALL_ALIGN_CALLSTATE) struct CCallState {
+ void (*func)(void); /* Pointer to called function. */
+ uint32_t spadj; /* Stack pointer adjustment. */
+ uint8_t nsp; /* Number of stack slots. */
+ uint8_t retref; /* Return value by reference. */
+#if LJ_TARGET_X64
+ uint8_t ngpr; /* Number of arguments in GPRs. */
+ uint8_t nfpr; /* Number of arguments in FPRs. */
+#elif LJ_TARGET_X86
+ uint8_t resx87; /* Result on x87 stack: 1:float, 2:double. */
+#elif LJ_TARGET_PPC
+ uint8_t nfpr; /* Number of arguments in FPRs. */
+#endif
+#if LJ_32
+ int32_t align1;
+#endif
+#if CCALL_NUM_FPR
+ FPRArg fpr[CCALL_NUM_FPR]; /* Arguments/results in FPRs. */
+#endif
+ GPRArg gpr[CCALL_NUM_GPR]; /* Arguments/results in GPRs. */
+ GPRArg stack[CCALL_MAXSTACK]; /* Stack slots. */
+} CCallState;
+
+/* -- C call handling ----------------------------------------------------- */
+
+/* Really belongs to lj_vm.h. */
+LJ_ASMF void LJ_FASTCALL lj_vm_ffi_call(CCallState *cc);
+
+LJ_FUNC CTypeID lj_ccall_ctid_vararg(CTState *cts, cTValue *o);
+LJ_FUNC int lj_ccall_func(lua_State *L, GCcdata *cd);
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ccallback.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ccallback.h
new file mode 100644
index 0000000..a8cdad3
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ccallback.h
@@ -0,0 +1,25 @@
+/*
+** FFI C callback handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_CCALLBACK_H
+#define _LJ_CCALLBACK_H
+
+#include "lj_obj.h"
+#include "lj_ctype.h"
+
+#if LJ_HASFFI
+
+/* Really belongs to lj_vm.h. */
+LJ_ASMF void lj_vm_ffi_callback(void);
+
+LJ_FUNC MSize lj_ccallback_ptr2slot(CTState *cts, void *p);
+LJ_FUNCA lua_State * LJ_FASTCALL lj_ccallback_enter(CTState *cts, void *cf);
+LJ_FUNCA void LJ_FASTCALL lj_ccallback_leave(CTState *cts, TValue *o);
+LJ_FUNC void *lj_ccallback_new(CTState *cts, CType *ct, GCfunc *fn);
+LJ_FUNC void lj_ccallback_mcode_free(CTState *cts);
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_cconv.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_cconv.h
new file mode 100644
index 0000000..0a0b66c
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_cconv.h
@@ -0,0 +1,70 @@
+/*
+** C type conversions.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_CCONV_H
+#define _LJ_CCONV_H
+
+#include "lj_obj.h"
+#include "lj_ctype.h"
+
+#if LJ_HASFFI
+
+/* Compressed C type index. ORDER CCX. */
+enum {
+ CCX_B, /* Bool. */
+ CCX_I, /* Integer. */
+ CCX_F, /* Floating-point number. */
+ CCX_C, /* Complex. */
+ CCX_V, /* Vector. */
+ CCX_P, /* Pointer. */
+ CCX_A, /* Refarray. */
+ CCX_S /* Struct/union. */
+};
+
+/* Convert C type info to compressed C type index. ORDER CT. ORDER CCX. */
+static LJ_AINLINE uint32_t cconv_idx(CTInfo info)
+{
+ uint32_t idx = ((info >> 26) & 15u); /* Dispatch bits. */
+ lua_assert(ctype_type(info) <= CT_MAYCONVERT);
+#if LJ_64
+ idx = ((uint32_t)(U64x(f436fff5,fff7f021) >> 4*idx) & 15u);
+#else
+ idx = (((idx < 8 ? 0xfff7f021u : 0xf436fff5) >> 4*(idx & 7u)) & 15u);
+#endif
+ lua_assert(idx < 8);
+ return idx;
+}
+
+#define cconv_idx2(dinfo, sinfo) \
+ ((cconv_idx((dinfo)) << 3) + cconv_idx((sinfo)))
+
+#define CCX(dst, src) ((CCX_##dst << 3) + CCX_##src)
+
+/* Conversion flags. */
+#define CCF_CAST 0x00000001u
+#define CCF_FROMTV 0x00000002u
+#define CCF_SAME 0x00000004u
+#define CCF_IGNQUAL 0x00000008u
+
+#define CCF_ARG_SHIFT 8
+#define CCF_ARG(n) ((n) << CCF_ARG_SHIFT)
+#define CCF_GETARG(f) ((f) >> CCF_ARG_SHIFT)
+
+LJ_FUNC int lj_cconv_compatptr(CTState *cts, CType *d, CType *s, CTInfo flags);
+LJ_FUNC void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s,
+ uint8_t *dp, uint8_t *sp, CTInfo flags);
+LJ_FUNC int lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid,
+ TValue *o, uint8_t *sp);
+LJ_FUNC int lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp);
+LJ_FUNC void lj_cconv_ct_tv(CTState *cts, CType *d,
+ uint8_t *dp, TValue *o, CTInfo flags);
+LJ_FUNC void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o);
+LJ_FUNC int lj_cconv_multi_init(CTState *cts, CType *d, TValue *o);
+LJ_FUNC void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz,
+ uint8_t *dp, TValue *o, MSize len);
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_cdata.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_cdata.h
new file mode 100644
index 0000000..4bb65db
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_cdata.h
@@ -0,0 +1,75 @@
+/*
+** C data management.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_CDATA_H
+#define _LJ_CDATA_H
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_ctype.h"
+
+#if LJ_HASFFI
+
+/* Get C data pointer. */
+static LJ_AINLINE void *cdata_getptr(void *p, CTSize sz)
+{
+ if (LJ_64 && sz == 4) { /* Support 32 bit pointers on 64 bit targets. */
+ return ((void *)(uintptr_t)*(uint32_t *)p);
+ } else {
+ lua_assert(sz == CTSIZE_PTR);
+ return *(void **)p;
+ }
+}
+
+/* Set C data pointer. */
+static LJ_AINLINE void cdata_setptr(void *p, CTSize sz, const void *v)
+{
+ if (LJ_64 && sz == 4) { /* Support 32 bit pointers on 64 bit targets. */
+ *(uint32_t *)p = (uint32_t)(uintptr_t)v;
+ } else {
+ lua_assert(sz == CTSIZE_PTR);
+ *(void **)p = (void *)v;
+ }
+}
+
+/* Allocate fixed-size C data object. */
+static LJ_AINLINE GCcdata *lj_cdata_new(CTState *cts, CTypeID id, CTSize sz)
+{
+ GCcdata *cd;
+#ifdef LUA_USE_ASSERT
+ CType *ct = ctype_raw(cts, id);
+ lua_assert((ctype_hassize(ct->info) ? ct->size : CTSIZE_PTR) == sz);
+#endif
+ cd = (GCcdata *)lj_mem_newgco(cts->L, sizeof(GCcdata) + sz);
+ cd->gct = ~LJ_TCDATA;
+ cd->ctypeid = ctype_check(cts, id);
+ return cd;
+}
+
+/* Variant which works without a valid CTState. */
+static LJ_AINLINE GCcdata *lj_cdata_new_(lua_State *L, CTypeID id, CTSize sz)
+{
+ GCcdata *cd = (GCcdata *)lj_mem_newgco(L, sizeof(GCcdata) + sz);
+ cd->gct = ~LJ_TCDATA;
+ cd->ctypeid = id;
+ return cd;
+}
+
+LJ_FUNC GCcdata *lj_cdata_newref(CTState *cts, const void *pp, CTypeID id);
+LJ_FUNC GCcdata *lj_cdata_newv(CTState *cts, CTypeID id, CTSize sz,
+ CTSize align);
+
+LJ_FUNC void LJ_FASTCALL lj_cdata_free(global_State *g, GCcdata *cd);
+LJ_FUNCA TValue * LJ_FASTCALL lj_cdata_setfin(lua_State *L, GCcdata *cd);
+
+LJ_FUNC CType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key,
+ uint8_t **pp, CTInfo *qual);
+LJ_FUNC int lj_cdata_get(CTState *cts, CType *s, TValue *o, uint8_t *sp);
+LJ_FUNC void lj_cdata_set(CTState *cts, CType *d, uint8_t *dp, TValue *o,
+ CTInfo qual);
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_char.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_char.h
new file mode 100644
index 0000000..c3c86d3
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_char.h
@@ -0,0 +1,42 @@
+/*
+** Character types.
+** Donated to the public domain.
+*/
+
+#ifndef _LJ_CHAR_H
+#define _LJ_CHAR_H
+
+#include "lj_def.h"
+
+#define LJ_CHAR_CNTRL 0x01
+#define LJ_CHAR_SPACE 0x02
+#define LJ_CHAR_PUNCT 0x04
+#define LJ_CHAR_DIGIT 0x08
+#define LJ_CHAR_XDIGIT 0x10
+#define LJ_CHAR_UPPER 0x20
+#define LJ_CHAR_LOWER 0x40
+#define LJ_CHAR_IDENT 0x80
+#define LJ_CHAR_ALPHA (LJ_CHAR_LOWER|LJ_CHAR_UPPER)
+#define LJ_CHAR_ALNUM (LJ_CHAR_ALPHA|LJ_CHAR_DIGIT)
+#define LJ_CHAR_GRAPH (LJ_CHAR_ALNUM|LJ_CHAR_PUNCT)
+
+/* Only pass -1 or 0..255 to these macros. Never pass a signed char! */
+#define lj_char_isa(c, t) ((lj_char_bits+1)[(c)] & t)
+#define lj_char_iscntrl(c) lj_char_isa((c), LJ_CHAR_CNTRL)
+#define lj_char_isspace(c) lj_char_isa((c), LJ_CHAR_SPACE)
+#define lj_char_ispunct(c) lj_char_isa((c), LJ_CHAR_PUNCT)
+#define lj_char_isdigit(c) lj_char_isa((c), LJ_CHAR_DIGIT)
+#define lj_char_isxdigit(c) lj_char_isa((c), LJ_CHAR_XDIGIT)
+#define lj_char_isupper(c) lj_char_isa((c), LJ_CHAR_UPPER)
+#define lj_char_islower(c) lj_char_isa((c), LJ_CHAR_LOWER)
+#define lj_char_isident(c) lj_char_isa((c), LJ_CHAR_IDENT)
+#define lj_char_isalpha(c) lj_char_isa((c), LJ_CHAR_ALPHA)
+#define lj_char_isalnum(c) lj_char_isa((c), LJ_CHAR_ALNUM)
+#define lj_char_isgraph(c) lj_char_isa((c), LJ_CHAR_GRAPH)
+
+#define lj_char_toupper(c) ((c) - (lj_char_islower(c) >> 1))
+#define lj_char_tolower(c) ((c) + lj_char_isupper(c))
+
+LJ_DATA const uint8_t lj_char_bits[257];
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_clib.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_clib.h
new file mode 100644
index 0000000..fcc9dac
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_clib.h
@@ -0,0 +1,29 @@
+/*
+** FFI C library loader.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_CLIB_H
+#define _LJ_CLIB_H
+
+#include "lj_obj.h"
+
+#if LJ_HASFFI
+
+/* Namespace for C library indexing. */
+#define CLNS_INDEX ((1u<<CT_FUNC)|(1u<<CT_EXTERN)|(1u<<CT_CONSTVAL))
+
+/* C library namespace. */
+typedef struct CLibrary {
+ void *handle; /* Opaque handle for dynamic library loader. */
+ GCtab *cache; /* Cache for resolved symbols. Anchored in ud->env. */
+} CLibrary;
+
+LJ_FUNC TValue *lj_clib_index(lua_State *L, CLibrary *cl, GCstr *name);
+LJ_FUNC void lj_clib_load(lua_State *L, GCtab *mt, GCstr *name, int global);
+LJ_FUNC void lj_clib_unload(CLibrary *cl);
+LJ_FUNC void lj_clib_default(lua_State *L, GCtab *mt);
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_cparse.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_cparse.h
new file mode 100644
index 0000000..bad1060
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_cparse.h
@@ -0,0 +1,65 @@
+/*
+** C declaration parser.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_CPARSE_H
+#define _LJ_CPARSE_H
+
+#include "lj_obj.h"
+#include "lj_ctype.h"
+
+#if LJ_HASFFI
+
+/* C parser limits. */
+#define CPARSE_MAX_BUF 32768 /* Max. token buffer size. */
+#define CPARSE_MAX_DECLSTACK 100 /* Max. declaration stack depth. */
+#define CPARSE_MAX_DECLDEPTH 20 /* Max. recursive declaration depth. */
+#define CPARSE_MAX_PACKSTACK 7 /* Max. pack pragma stack depth. */
+
+/* Flags for C parser mode. */
+#define CPARSE_MODE_MULTI 1 /* Process multiple declarations. */
+#define CPARSE_MODE_ABSTRACT 2 /* Accept abstract declarators. */
+#define CPARSE_MODE_DIRECT 4 /* Accept direct declarators. */
+#define CPARSE_MODE_FIELD 8 /* Accept field width in bits, too. */
+#define CPARSE_MODE_NOIMPLICIT 16 /* Reject implicit declarations. */
+#define CPARSE_MODE_SKIP 32 /* Skip definitions, ignore errors. */
+
+typedef int CPChar; /* C parser character. Unsigned ext. from char. */
+typedef int CPToken; /* C parser token. */
+
+/* C parser internal value representation. */
+typedef struct CPValue {
+ union {
+ int32_t i32; /* Value for CTID_INT32. */
+ uint32_t u32; /* Value for CTID_UINT32. */
+ };
+ CTypeID id; /* C Type ID of the value. */
+} CPValue;
+
+/* C parser state. */
+typedef struct CPState {
+ CPChar c; /* Current character. */
+ CPToken tok; /* Current token. */
+ CPValue val; /* Token value. */
+ GCstr *str; /* Interned string of identifier/keyword. */
+ CType *ct; /* C type table entry. */
+ const char *p; /* Current position in input buffer. */
+ SBuf sb; /* String buffer for tokens. */
+ lua_State *L; /* Lua state. */
+ CTState *cts; /* C type state. */
+ TValue *param; /* C type parameters. */
+ const char *srcname; /* Current source name. */
+ BCLine linenumber; /* Input line counter. */
+ int depth; /* Recursive declaration depth. */
+ uint32_t tmask; /* Type mask for next identifier. */
+ uint32_t mode; /* C parser mode. */
+ uint8_t packstack[CPARSE_MAX_PACKSTACK]; /* Stack for pack pragmas. */
+ uint8_t curpack; /* Current position in pack pragma stack. */
+} CPState;
+
+LJ_FUNC int lj_cparse(CPState *cp);
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_crecord.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_crecord.h
new file mode 100644
index 0000000..8e0afd1
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_crecord.h
@@ -0,0 +1,31 @@
+/*
+** Trace recorder for C data operations.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_CRECORD_H
+#define _LJ_CRECORD_H
+
+#include "lj_obj.h"
+#include "lj_jit.h"
+#include "lj_ffrecord.h"
+
+#if LJ_HASJIT && LJ_HASFFI
+LJ_FUNC void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_cdata_call(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_clib_index(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_errno(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_copy(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_fill(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_typeof(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_istype(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_abi(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_gc(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd);
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ctype.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ctype.h
new file mode 100644
index 0000000..2aefd3b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ctype.h
@@ -0,0 +1,461 @@
+/*
+** C type management.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_CTYPE_H
+#define _LJ_CTYPE_H
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+
+#if LJ_HASFFI
+
+/* -- C type definitions -------------------------------------------------- */
+
+/* C type numbers. Highest 4 bits of C type info. ORDER CT. */
+enum {
+ /* Externally visible types. */
+ CT_NUM, /* Integer or floating-point numbers. */
+ CT_STRUCT, /* Struct or union. */
+ CT_PTR, /* Pointer or reference. */
+ CT_ARRAY, /* Array or complex type. */
+ CT_MAYCONVERT = CT_ARRAY,
+ CT_VOID, /* Void type. */
+ CT_ENUM, /* Enumeration. */
+ CT_HASSIZE = CT_ENUM, /* Last type where ct->size holds the actual size. */
+ CT_FUNC, /* Function. */
+ CT_TYPEDEF, /* Typedef. */
+ CT_ATTRIB, /* Miscellaneous attributes. */
+ /* Internal element types. */
+ CT_FIELD, /* Struct/union field or function parameter. */
+ CT_BITFIELD, /* Struct/union bitfield. */
+ CT_CONSTVAL, /* Constant value. */
+ CT_EXTERN, /* External reference. */
+ CT_KW /* Keyword. */
+};
+
+LJ_STATIC_ASSERT(((int)CT_PTR & (int)CT_ARRAY) == CT_PTR);
+LJ_STATIC_ASSERT(((int)CT_STRUCT & (int)CT_ARRAY) == CT_STRUCT);
+
+/*
+** ---------- info ------------
+** |type flags... A cid | size | sib | next | name |
+** +----------------------------+--------+-------+-------+-------+--
+** |NUM BFcvUL.. A | size | | type | |
+** |STRUCT ..cvU..V A | size | field | name? | name? |
+** |PTR ..cvR... A cid | size | | type | |
+** |ARRAY VCcv...V A cid | size | | type | |
+** |VOID ..cv.... A | size | | type | |
+** |ENUM A cid | size | const | name? | name? |
+** |FUNC ....VS.. cc cid | nargs | field | name? | name? |
+** |TYPEDEF cid | | | name | name |
+** |ATTRIB attrnum cid | attr | sib? | type? | |
+** |FIELD cid | offset | field | | name? |
+** |BITFIELD B.cvU csz bsz pos | offset | field | | name? |
+** |CONSTVAL c cid | value | const | name | name |
+** |EXTERN cid | | sib? | name | name |
+** |KW tok | size | | name | name |
+** +----------------------------+--------+-------+-------+-------+--
+** ^^ ^^--- bits used for C type conversion dispatch
+*/
+
+/* C type info flags. TFFArrrr */
+#define CTF_BOOL 0x08000000u /* Boolean: NUM, BITFIELD. */
+#define CTF_FP 0x04000000u /* Floating-point: NUM. */
+#define CTF_CONST 0x02000000u /* Const qualifier. */
+#define CTF_VOLATILE 0x01000000u /* Volatile qualifier. */
+#define CTF_UNSIGNED 0x00800000u /* Unsigned: NUM, BITFIELD. */
+#define CTF_LONG 0x00400000u /* Long: NUM. */
+#define CTF_VLA 0x00100000u /* Variable-length: ARRAY, STRUCT. */
+#define CTF_REF 0x00800000u /* Reference: PTR. */
+#define CTF_VECTOR 0x08000000u /* Vector: ARRAY. */
+#define CTF_COMPLEX 0x04000000u /* Complex: ARRAY. */
+#define CTF_UNION 0x00800000u /* Union: STRUCT. */
+#define CTF_VARARG 0x00800000u /* Vararg: FUNC. */
+#define CTF_SSEREGPARM 0x00400000u /* SSE register parameters: FUNC. */
+
+#define CTF_QUAL (CTF_CONST|CTF_VOLATILE)
+#define CTF_ALIGN (CTMASK_ALIGN<<CTSHIFT_ALIGN)
+#define CTF_UCHAR ((char)-1 > 0 ? CTF_UNSIGNED : 0)
+
+/* Flags used in parser. .F.Ammvf cp->attr */
+#define CTFP_ALIGNED 0x00000001u /* cp->attr + ALIGN */
+#define CTFP_PACKED 0x00000002u /* cp->attr */
+/* ...C...f cp->fattr */
+#define CTFP_CCONV 0x00000001u /* cp->fattr + CCONV/[SSE]REGPARM */
+
+/* C type info bitfields. */
+#define CTMASK_CID 0x0000ffffu /* Max. 65536 type IDs. */
+#define CTMASK_NUM 0xf0000000u /* Max. 16 type numbers. */
+#define CTSHIFT_NUM 28
+#define CTMASK_ALIGN 15 /* Max. alignment is 2^15. */
+#define CTSHIFT_ALIGN 16
+#define CTMASK_ATTRIB 255 /* Max. 256 attributes. */
+#define CTSHIFT_ATTRIB 16
+#define CTMASK_CCONV 3 /* Max. 4 calling conventions. */
+#define CTSHIFT_CCONV 16
+#define CTMASK_REGPARM 3 /* Max. 0-3 regparms. */
+#define CTSHIFT_REGPARM 18
+/* Bitfields only used in parser. */
+#define CTMASK_VSIZEP 15 /* Max. vector size is 2^15. */
+#define CTSHIFT_VSIZEP 4
+#define CTMASK_MSIZEP 255 /* Max. type size (via mode) is 128. */
+#define CTSHIFT_MSIZEP 8
+
+/* Info bits for BITFIELD. Max. size of bitfield is 64 bits. */
+#define CTBSZ_MAX 32 /* Max. size of bitfield is 32 bit. */
+#define CTBSZ_FIELD 127 /* Temp. marker for regular field. */
+#define CTMASK_BITPOS 127
+#define CTMASK_BITBSZ 127
+#define CTMASK_BITCSZ 127
+#define CTSHIFT_BITPOS 0
+#define CTSHIFT_BITBSZ 8
+#define CTSHIFT_BITCSZ 16
+
+#define CTF_INSERT(info, field, val) \
+ info = (info & ~(CTMASK_##field<<CTSHIFT_##field)) | \
+ (((CTSize)(val) & CTMASK_##field) << CTSHIFT_##field)
+
+/* Calling conventions. ORDER CC */
+enum { CTCC_CDECL, CTCC_THISCALL, CTCC_FASTCALL, CTCC_STDCALL };
+
+/* Attribute numbers. */
+enum {
+ CTA_NONE, /* Ignored attribute. Must be zero. */
+ CTA_QUAL, /* Unmerged qualifiers. */
+ CTA_ALIGN, /* Alignment override. */
+ CTA_SUBTYPE, /* Transparent sub-type. */
+ CTA_REDIR, /* Redirected symbol name. */
+ CTA_BAD, /* To catch bad IDs. */
+ CTA__MAX
+};
+
+/* Special sizes. */
+#define CTSIZE_INVALID 0xffffffffu
+
+typedef uint32_t CTInfo; /* Type info. */
+typedef uint32_t CTSize; /* Type size. */
+typedef uint32_t CTypeID; /* Type ID. */
+typedef uint16_t CTypeID1; /* Minimum-sized type ID. */
+
+/* C type table element. */
+typedef struct CType {
+ CTInfo info; /* Type info. */
+ CTSize size; /* Type size or other info. */
+ CTypeID1 sib; /* Sibling element. */
+ CTypeID1 next; /* Next element in hash chain. */
+ GCRef name; /* Element name (GCstr). */
+} CType;
+
+#define CTHASH_SIZE 128 /* Number of hash anchors. */
+#define CTHASH_MASK (CTHASH_SIZE-1)
+
+/* Simplify target-specific configuration. Checked in lj_ccall.h. */
+#define CCALL_MAX_GPR 8
+#define CCALL_MAX_FPR 8
+
+typedef LJ_ALIGN(8) union FPRCBArg { double d; float f[2]; } FPRCBArg;
+
+/* C callback state. Defined here, to avoid dragging in lj_ccall.h. */
+
+typedef LJ_ALIGN(8) struct CCallback {
+ FPRCBArg fpr[CCALL_MAX_FPR]; /* Arguments/results in FPRs. */
+ intptr_t gpr[CCALL_MAX_GPR]; /* Arguments/results in GPRs. */
+ intptr_t *stack; /* Pointer to arguments on stack. */
+ void *mcode; /* Machine code for callback func. pointers. */
+ CTypeID1 *cbid; /* Callback type table. */
+ MSize sizeid; /* Size of callback type table. */
+ MSize topid; /* Highest unused callback type table slot. */
+ MSize slot; /* Current callback slot. */
+} CCallback;
+
+/* C type state. */
+typedef struct CTState {
+ CType *tab; /* C type table. */
+ CTypeID top; /* Current top of C type table. */
+ MSize sizetab; /* Size of C type table. */
+ lua_State *L; /* Lua state (needed for errors and allocations). */
+ global_State *g; /* Global state. */
+ GCtab *finalizer; /* Map of cdata to finalizer. */
+ GCtab *miscmap; /* Map of -CTypeID to metatable and cb slot to func. */
+ CCallback cb; /* Temporary callback state. */
+ CTypeID1 hash[CTHASH_SIZE]; /* Hash anchors for C type table. */
+} CTState;
+
+#define CTINFO(ct, flags) (((CTInfo)(ct) << CTSHIFT_NUM) + (flags))
+#define CTALIGN(al) ((CTSize)(al) << CTSHIFT_ALIGN)
+#define CTATTRIB(at) ((CTInfo)(at) << CTSHIFT_ATTRIB)
+
+#define ctype_type(info) ((info) >> CTSHIFT_NUM)
+#define ctype_cid(info) ((CTypeID)((info) & CTMASK_CID))
+#define ctype_align(info) (((info) >> CTSHIFT_ALIGN) & CTMASK_ALIGN)
+#define ctype_attrib(info) (((info) >> CTSHIFT_ATTRIB) & CTMASK_ATTRIB)
+#define ctype_bitpos(info) (((info) >> CTSHIFT_BITPOS) & CTMASK_BITPOS)
+#define ctype_bitbsz(info) (((info) >> CTSHIFT_BITBSZ) & CTMASK_BITBSZ)
+#define ctype_bitcsz(info) (((info) >> CTSHIFT_BITCSZ) & CTMASK_BITCSZ)
+#define ctype_vsizeP(info) (((info) >> CTSHIFT_VSIZEP) & CTMASK_VSIZEP)
+#define ctype_msizeP(info) (((info) >> CTSHIFT_MSIZEP) & CTMASK_MSIZEP)
+#define ctype_cconv(info) (((info) >> CTSHIFT_CCONV) & CTMASK_CCONV)
+
+/* Simple type checks. */
+#define ctype_isnum(info) (ctype_type((info)) == CT_NUM)
+#define ctype_isvoid(info) (ctype_type((info)) == CT_VOID)
+#define ctype_isptr(info) (ctype_type((info)) == CT_PTR)
+#define ctype_isarray(info) (ctype_type((info)) == CT_ARRAY)
+#define ctype_isstruct(info) (ctype_type((info)) == CT_STRUCT)
+#define ctype_isfunc(info) (ctype_type((info)) == CT_FUNC)
+#define ctype_isenum(info) (ctype_type((info)) == CT_ENUM)
+#define ctype_istypedef(info) (ctype_type((info)) == CT_TYPEDEF)
+#define ctype_isattrib(info) (ctype_type((info)) == CT_ATTRIB)
+#define ctype_isfield(info) (ctype_type((info)) == CT_FIELD)
+#define ctype_isbitfield(info) (ctype_type((info)) == CT_BITFIELD)
+#define ctype_isconstval(info) (ctype_type((info)) == CT_CONSTVAL)
+#define ctype_isextern(info) (ctype_type((info)) == CT_EXTERN)
+#define ctype_hassize(info) (ctype_type((info)) <= CT_HASSIZE)
+
+/* Combined type and flag checks. */
+#define ctype_isinteger(info) \
+ (((info) & (CTMASK_NUM|CTF_BOOL|CTF_FP)) == CTINFO(CT_NUM, 0))
+#define ctype_isinteger_or_bool(info) \
+ (((info) & (CTMASK_NUM|CTF_FP)) == CTINFO(CT_NUM, 0))
+#define ctype_isbool(info) \
+ (((info) & (CTMASK_NUM|CTF_BOOL)) == CTINFO(CT_NUM, CTF_BOOL))
+#define ctype_isfp(info) \
+ (((info) & (CTMASK_NUM|CTF_FP)) == CTINFO(CT_NUM, CTF_FP))
+
+#define ctype_ispointer(info) \
+ ((ctype_type(info) >> 1) == (CT_PTR >> 1)) /* Pointer or array. */
+#define ctype_isref(info) \
+ (((info) & (CTMASK_NUM|CTF_REF)) == CTINFO(CT_PTR, CTF_REF))
+
+#define ctype_isrefarray(info) \
+ (((info) & (CTMASK_NUM|CTF_VECTOR|CTF_COMPLEX)) == CTINFO(CT_ARRAY, 0))
+#define ctype_isvector(info) \
+ (((info) & (CTMASK_NUM|CTF_VECTOR)) == CTINFO(CT_ARRAY, CTF_VECTOR))
+#define ctype_iscomplex(info) \
+ (((info) & (CTMASK_NUM|CTF_COMPLEX)) == CTINFO(CT_ARRAY, CTF_COMPLEX))
+
+#define ctype_isvltype(info) \
+ (((info) & ((CTMASK_NUM|CTF_VLA) - (2u<<CTSHIFT_NUM))) == \
+ CTINFO(CT_STRUCT, CTF_VLA)) /* VL array or VL struct. */
+#define ctype_isvlarray(info) \
+ (((info) & (CTMASK_NUM|CTF_VLA)) == CTINFO(CT_ARRAY, CTF_VLA))
+
+#define ctype_isxattrib(info, at) \
+ (((info) & (CTMASK_NUM|CTATTRIB(CTMASK_ATTRIB))) == \
+ CTINFO(CT_ATTRIB, CTATTRIB(at)))
+
+/* Target-dependent sizes and alignments. */
+#if LJ_64
+#define CTSIZE_PTR 8
+#define CTALIGN_PTR CTALIGN(3)
+#else
+#define CTSIZE_PTR 4
+#define CTALIGN_PTR CTALIGN(2)
+#endif
+
+#define CTINFO_REF(ref) \
+ CTINFO(CT_PTR, (CTF_CONST|CTF_REF|CTALIGN_PTR) + (ref))
+
+#define CT_MEMALIGN 3 /* Alignment guaranteed by memory allocator. */
+
+/* -- Predefined types ---------------------------------------------------- */
+
+/* Target-dependent types. */
+#if LJ_TARGET_PPC || LJ_TARGET_PPCSPE
+#define CTTYDEFP(_) \
+ _(LINT32, 4, CT_NUM, CTF_LONG|CTALIGN(2))
+#else
+#define CTTYDEFP(_)
+#endif
+
+/* Common types. */
+#define CTTYDEF(_) \
+ _(NONE, 0, CT_ATTRIB, CTATTRIB(CTA_BAD)) \
+ _(VOID, -1, CT_VOID, CTALIGN(0)) \
+ _(CVOID, -1, CT_VOID, CTF_CONST|CTALIGN(0)) \
+ _(BOOL, 1, CT_NUM, CTF_BOOL|CTF_UNSIGNED|CTALIGN(0)) \
+ _(CCHAR, 1, CT_NUM, CTF_CONST|CTF_UCHAR|CTALIGN(0)) \
+ _(INT8, 1, CT_NUM, CTALIGN(0)) \
+ _(UINT8, 1, CT_NUM, CTF_UNSIGNED|CTALIGN(0)) \
+ _(INT16, 2, CT_NUM, CTALIGN(1)) \
+ _(UINT16, 2, CT_NUM, CTF_UNSIGNED|CTALIGN(1)) \
+ _(INT32, 4, CT_NUM, CTALIGN(2)) \
+ _(UINT32, 4, CT_NUM, CTF_UNSIGNED|CTALIGN(2)) \
+ _(INT64, 8, CT_NUM, CTF_LONG|CTALIGN(3)) \
+ _(UINT64, 8, CT_NUM, CTF_UNSIGNED|CTF_LONG|CTALIGN(3)) \
+ _(FLOAT, 4, CT_NUM, CTF_FP|CTALIGN(2)) \
+ _(DOUBLE, 8, CT_NUM, CTF_FP|CTALIGN(3)) \
+ _(COMPLEX_FLOAT, 8, CT_ARRAY, CTF_COMPLEX|CTALIGN(2)|CTID_FLOAT) \
+ _(COMPLEX_DOUBLE, 16, CT_ARRAY, CTF_COMPLEX|CTALIGN(3)|CTID_DOUBLE) \
+ _(P_VOID, CTSIZE_PTR, CT_PTR, CTALIGN_PTR|CTID_VOID) \
+ _(P_CVOID, CTSIZE_PTR, CT_PTR, CTALIGN_PTR|CTID_CVOID) \
+ _(P_CCHAR, CTSIZE_PTR, CT_PTR, CTALIGN_PTR|CTID_CCHAR) \
+ _(A_CCHAR, -1, CT_ARRAY, CTF_CONST|CTALIGN(0)|CTID_CCHAR) \
+ _(CTYPEID, 4, CT_ENUM, CTALIGN(2)|CTID_INT32) \
+ CTTYDEFP(_) \
+ /* End of type list. */
+
+/* Public predefined type IDs. */
+enum {
+#define CTTYIDDEF(id, sz, ct, info) CTID_##id,
+CTTYDEF(CTTYIDDEF)
+#undef CTTYIDDEF
+ /* Predefined typedefs and keywords follow. */
+ CTID_MAX = 65536
+};
+
+/* Target-dependent type IDs. */
+#if LJ_64
+#define CTID_INT_PSZ CTID_INT64
+#define CTID_UINT_PSZ CTID_UINT64
+#else
+#define CTID_INT_PSZ CTID_INT32
+#define CTID_UINT_PSZ CTID_UINT32
+#endif
+
+#if LJ_ABI_WIN
+#define CTID_WCHAR CTID_UINT16
+#elif LJ_TARGET_PPC
+#define CTID_WCHAR CTID_LINT32
+#else
+#define CTID_WCHAR CTID_INT32
+#endif
+
+/* -- C tokens and keywords ----------------------------------------------- */
+
+/* C lexer keywords. */
+#define CTOKDEF(_) \
+ _(IDENT, "<identifier>") _(STRING, "<string>") \
+ _(INTEGER, "<integer>") _(EOF, "<eof>") \
+ _(OROR, "||") _(ANDAND, "&&") _(EQ, "==") _(NE, "!=") \
+ _(LE, "<=") _(GE, ">=") _(SHL, "<<") _(SHR, ">>") _(DEREF, "->")
+
+/* Simple declaration specifiers. */
+#define CDSDEF(_) \
+ _(VOID) _(BOOL) _(CHAR) _(INT) _(FP) \
+ _(LONG) _(LONGLONG) _(SHORT) _(COMPLEX) _(SIGNED) _(UNSIGNED) \
+ _(CONST) _(VOLATILE) _(RESTRICT) _(INLINE) \
+ _(TYPEDEF) _(EXTERN) _(STATIC) _(AUTO) _(REGISTER)
+
+/* C keywords. */
+#define CKWDEF(_) \
+ CDSDEF(_) _(EXTENSION) _(ASM) _(ATTRIBUTE) \
+ _(DECLSPEC) _(CCDECL) _(PTRSZ) \
+ _(STRUCT) _(UNION) _(ENUM) \
+ _(SIZEOF) _(ALIGNOF)
+
+/* C token numbers. */
+enum {
+ CTOK_OFS = 255,
+#define CTOKNUM(name, sym) CTOK_##name,
+#define CKWNUM(name) CTOK_##name,
+CTOKDEF(CTOKNUM)
+CKWDEF(CKWNUM)
+#undef CTOKNUM
+#undef CKWNUM
+ CTOK_FIRSTDECL = CTOK_VOID,
+ CTOK_FIRSTSCL = CTOK_TYPEDEF,
+ CTOK_LASTDECLFLAG = CTOK_REGISTER,
+ CTOK_LASTDECL = CTOK_ENUM
+};
+
+/* Declaration specifier flags. */
+enum {
+#define CDSFLAG(name) CDF_##name = (1u << (CTOK_##name - CTOK_FIRSTDECL)),
+CDSDEF(CDSFLAG)
+#undef CDSFLAG
+ CDF__END
+};
+
+#define CDF_SCL (CDF_TYPEDEF|CDF_EXTERN|CDF_STATIC|CDF_AUTO|CDF_REGISTER)
+
+/* -- C type management --------------------------------------------------- */
+
+#define ctype_ctsG(g) (mref((g)->ctype_state, CTState))
+
+/* Get C type state. */
+static LJ_AINLINE CTState *ctype_cts(lua_State *L)
+{
+ CTState *cts = ctype_ctsG(G(L));
+ cts->L = L; /* Save L for errors and allocations. */
+ return cts;
+}
+
+/* Save and restore state of C type table. */
+#define LJ_CTYPE_SAVE(cts) CTState savects_ = *(cts)
+#define LJ_CTYPE_RESTORE(cts) \
+ ((cts)->top = savects_.top, \
+ memcpy((cts)->hash, savects_.hash, sizeof(savects_.hash)))
+
+/* Check C type ID for validity when assertions are enabled. */
+static LJ_AINLINE CTypeID ctype_check(CTState *cts, CTypeID id)
+{
+ lua_assert(id > 0 && id < cts->top); UNUSED(cts);
+ return id;
+}
+
+/* Get C type for C type ID. */
+static LJ_AINLINE CType *ctype_get(CTState *cts, CTypeID id)
+{
+ return &cts->tab[ctype_check(cts, id)];
+}
+
+/* Get C type ID for a C type. */
+#define ctype_typeid(cts, ct) ((CTypeID)((ct) - (cts)->tab))
+
+/* Get child C type. */
+static LJ_AINLINE CType *ctype_child(CTState *cts, CType *ct)
+{
+ lua_assert(!(ctype_isvoid(ct->info) || ctype_isstruct(ct->info) ||
+ ctype_isbitfield(ct->info))); /* These don't have children. */
+ return ctype_get(cts, ctype_cid(ct->info));
+}
+
+/* Get raw type for a C type ID. */
+static LJ_AINLINE CType *ctype_raw(CTState *cts, CTypeID id)
+{
+ CType *ct = ctype_get(cts, id);
+ while (ctype_isattrib(ct->info)) ct = ctype_child(cts, ct);
+ return ct;
+}
+
+/* Get raw type of the child of a C type. */
+static LJ_AINLINE CType *ctype_rawchild(CTState *cts, CType *ct)
+{
+ do { ct = ctype_child(cts, ct); } while (ctype_isattrib(ct->info));
+ return ct;
+}
+
+/* Set the name of a C type table element. */
+static LJ_AINLINE void ctype_setname(CType *ct, GCstr *s)
+{
+ /* NOBARRIER: mark string as fixed -- the C type table is never collected. */
+ fixstring(s);
+ setgcref(ct->name, obj2gco(s));
+}
+
+LJ_FUNC CTypeID lj_ctype_new(CTState *cts, CType **ctp);
+LJ_FUNC CTypeID lj_ctype_intern(CTState *cts, CTInfo info, CTSize size);
+LJ_FUNC void lj_ctype_addname(CTState *cts, CType *ct, CTypeID id);
+LJ_FUNC CTypeID lj_ctype_getname(CTState *cts, CType **ctp, GCstr *name,
+ uint32_t tmask);
+LJ_FUNC CType *lj_ctype_getfieldq(CTState *cts, CType *ct, GCstr *name,
+ CTSize *ofs, CTInfo *qual);
+#define lj_ctype_getfield(cts, ct, name, ofs) \
+ lj_ctype_getfieldq((cts), (ct), (name), (ofs), NULL)
+LJ_FUNC CType *lj_ctype_rawref(CTState *cts, CTypeID id);
+LJ_FUNC CTSize lj_ctype_size(CTState *cts, CTypeID id);
+LJ_FUNC CTSize lj_ctype_vlsize(CTState *cts, CType *ct, CTSize nelem);
+LJ_FUNC CTInfo lj_ctype_info(CTState *cts, CTypeID id, CTSize *szp);
+LJ_FUNC cTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm);
+LJ_FUNC GCstr *lj_ctype_repr(lua_State *L, CTypeID id, GCstr *name);
+LJ_FUNC GCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned);
+LJ_FUNC GCstr *lj_ctype_repr_complex(lua_State *L, void *sp, CTSize size);
+LJ_FUNC CTState *lj_ctype_init(lua_State *L);
+LJ_FUNC void lj_ctype_freestate(global_State *g);
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_debug.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_debug.h
new file mode 100644
index 0000000..d10d0da
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_debug.h
@@ -0,0 +1,61 @@
+/*
+** Debugging and introspection.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_DEBUG_H
+#define _LJ_DEBUG_H
+
+#include "lj_obj.h"
+
+typedef struct lj_Debug {
+ /* Common fields. Must be in the same order as in lua.h. */
+ int event;
+ const char *name;
+ const char *namewhat;
+ const char *what;
+ const char *source;
+ int currentline;
+ int nups;
+ int linedefined;
+ int lastlinedefined;
+ char short_src[LUA_IDSIZE];
+ int i_ci;
+ /* Extended fields. Only valid if lj_debug_getinfo() is called with ext = 1.*/
+ int nparams;
+ int isvararg;
+} lj_Debug;
+
+LJ_FUNC cTValue *lj_debug_frame(lua_State *L, int level, int *size);
+LJ_FUNC BCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc);
+LJ_FUNC const char *lj_debug_uvname(GCproto *pt, uint32_t idx);
+LJ_FUNC const char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp);
+LJ_FUNC const char *lj_debug_slotname(GCproto *pt, const BCIns *pc,
+ BCReg slot, const char **name);
+LJ_FUNC const char *lj_debug_funcname(lua_State *L, TValue *frame,
+ const char **name);
+LJ_FUNC void lj_debug_shortname(char *out, GCstr *str);
+LJ_FUNC void lj_debug_addloc(lua_State *L, const char *msg,
+ cTValue *frame, cTValue *nextframe);
+LJ_FUNC void lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc);
+LJ_FUNC int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar,
+ int ext);
+
+/* Fixed internal variable names. */
+#define VARNAMEDEF(_) \
+ _(FOR_IDX, "(for index)") \
+ _(FOR_STOP, "(for limit)") \
+ _(FOR_STEP, "(for step)") \
+ _(FOR_GEN, "(for generator)") \
+ _(FOR_STATE, "(for state)") \
+ _(FOR_CTL, "(for control)")
+
+enum {
+ VARNAME_END,
+#define VARNAMEENUM(name, str) VARNAME_##name,
+ VARNAMEDEF(VARNAMEENUM)
+#undef VARNAMEENUM
+ VARNAME__MAX
+};
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_def.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_def.h
new file mode 100644
index 0000000..21cc59a
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_def.h
@@ -0,0 +1,353 @@
+/*
+** LuaJIT common internal definitions.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_DEF_H
+#define _LJ_DEF_H
+
+#include "lua.h"
+
+#if defined(_MSC_VER)
+/* MSVC is stuck in the last century and doesn't have C99's stdint.h. */
+typedef __int8 int8_t;
+typedef __int16 int16_t;
+typedef __int32 int32_t;
+typedef __int64 int64_t;
+typedef unsigned __int8 uint8_t;
+typedef unsigned __int16 uint16_t;
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int64 uint64_t;
+#ifdef _WIN64
+typedef __int64 intptr_t;
+typedef unsigned __int64 uintptr_t;
+#else
+typedef __int32 intptr_t;
+typedef unsigned __int32 uintptr_t;
+#endif
+#elif defined(__symbian__)
+/* Cough. */
+typedef signed char int8_t;
+typedef short int int16_t;
+typedef int int32_t;
+typedef long long int64_t;
+typedef unsigned char uint8_t;
+typedef unsigned short int uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
+typedef int intptr_t;
+typedef unsigned int uintptr_t;
+#else
+#include <stdint.h>
+#endif
+
+/* Needed everywhere. */
+#include <string.h>
+#include <stdlib.h>
+
+/* Various VM limits. */
+#define LJ_MAX_MEM 0x7fffff00 /* Max. total memory allocation. */
+#define LJ_MAX_ALLOC LJ_MAX_MEM /* Max. individual allocation length. */
+#define LJ_MAX_STR LJ_MAX_MEM /* Max. string length. */
+#define LJ_MAX_UDATA LJ_MAX_MEM /* Max. userdata length. */
+
+#define LJ_MAX_STRTAB (1<<26) /* Max. string table size. */
+#define LJ_MAX_HBITS 26 /* Max. hash bits. */
+#define LJ_MAX_ABITS 28 /* Max. bits of array key. */
+#define LJ_MAX_ASIZE ((1<<(LJ_MAX_ABITS-1))+1) /* Max. array part size. */
+#define LJ_MAX_COLOSIZE 16 /* Max. elems for colocated array. */
+
+#define LJ_MAX_LINE LJ_MAX_MEM /* Max. source code line number. */
+#define LJ_MAX_XLEVEL 200 /* Max. syntactic nesting level. */
+#define LJ_MAX_BCINS (1<<26) /* Max. # of bytecode instructions. */
+#define LJ_MAX_SLOTS 250 /* Max. # of slots in a Lua func. */
+#define LJ_MAX_LOCVAR 200 /* Max. # of local variables. */
+#define LJ_MAX_UPVAL 60 /* Max. # of upvalues. */
+
+#define LJ_MAX_IDXCHAIN 100 /* __index/__newindex chain limit. */
+#define LJ_STACK_EXTRA 5 /* Extra stack space (metamethods). */
+
+#define LJ_NUM_CBPAGE 1 /* Number of FFI callback pages. */
+
+/* Minimum table/buffer sizes. */
+#define LJ_MIN_GLOBAL 6 /* Min. global table size (hbits). */
+#define LJ_MIN_REGISTRY 2 /* Min. registry size (hbits). */
+#define LJ_MIN_STRTAB 256 /* Min. string table size (pow2). */
+#define LJ_MIN_SBUF 32 /* Min. string buffer length. */
+#define LJ_MIN_VECSZ 8 /* Min. size for growable vectors. */
+#define LJ_MIN_IRSZ 32 /* Min. size for growable IR. */
+#define LJ_MIN_K64SZ 16 /* Min. size for chained K64Array. */
+
+/* JIT compiler limits. */
+#define LJ_MAX_JSLOTS 250 /* Max. # of stack slots for a trace. */
+#define LJ_MAX_PHI 64 /* Max. # of PHIs for a loop. */
+#define LJ_MAX_EXITSTUBGR 16 /* Max. # of exit stub groups. */
+
+/* Various macros. */
+#ifndef UNUSED
+#define UNUSED(x) ((void)(x)) /* to avoid warnings */
+#endif
+
+#define U64x(hi, lo) (((uint64_t)0x##hi << 32) + (uint64_t)0x##lo)
+#define i32ptr(p) ((int32_t)(intptr_t)(void *)(p))
+#define u32ptr(p) ((uint32_t)(intptr_t)(void *)(p))
+
+#define checki8(x) ((x) == (int32_t)(int8_t)(x))
+#define checku8(x) ((x) == (int32_t)(uint8_t)(x))
+#define checki16(x) ((x) == (int32_t)(int16_t)(x))
+#define checku16(x) ((x) == (int32_t)(uint16_t)(x))
+#define checki32(x) ((x) == (int32_t)(x))
+#define checku32(x) ((x) == (uint32_t)(x))
+#define checkptr32(x) ((uintptr_t)(x) == (uint32_t)(uintptr_t)(x))
+
+/* Every half-decent C compiler transforms this into a rotate instruction. */
+#define lj_rol(x, n) (((x)<<(n)) | ((x)>>(-(int)(n)&(8*sizeof(x)-1))))
+#define lj_ror(x, n) (((x)<<(-(int)(n)&(8*sizeof(x)-1))) | ((x)>>(n)))
+
+/* A really naive Bloom filter. But sufficient for our needs. */
+typedef uintptr_t BloomFilter;
+#define BLOOM_MASK (8*sizeof(BloomFilter) - 1)
+#define bloombit(x) ((uintptr_t)1 << ((x) & BLOOM_MASK))
+#define bloomset(b, x) ((b) |= bloombit((x)))
+#define bloomtest(b, x) ((b) & bloombit((x)))
+
+#if defined(__GNUC__) || defined(__psp2__)
+
+#define LJ_NORET __attribute__((noreturn))
+#define LJ_ALIGN(n) __attribute__((aligned(n)))
+#define LJ_INLINE inline
+#define LJ_AINLINE inline __attribute__((always_inline))
+#define LJ_NOINLINE __attribute__((noinline))
+
+#if defined(__ELF__) || defined(__MACH__) || defined(__psp2__)
+#if !((defined(__sun__) && defined(__svr4__)) || defined(__CELLOS_LV2__))
+#define LJ_NOAPI extern __attribute__((visibility("hidden")))
+#endif
+#endif
+
+/* Note: it's only beneficial to use fastcall on x86 and then only for up to
+** two non-FP args. The amalgamated compile covers all LJ_FUNC cases. Only
+** indirect calls and related tail-called C functions are marked as fastcall.
+*/
+#if defined(__i386__)
+#define LJ_FASTCALL __attribute__((fastcall))
+#endif
+
+#define LJ_LIKELY(x) __builtin_expect(!!(x), 1)
+#define LJ_UNLIKELY(x) __builtin_expect(!!(x), 0)
+
+#define lj_ffs(x) ((uint32_t)__builtin_ctz(x))
+/* Don't ask ... */
+#if defined(__INTEL_COMPILER) && (defined(__i386__) || defined(__x86_64__))
+static LJ_AINLINE uint32_t lj_fls(uint32_t x)
+{
+ uint32_t r; __asm__("bsrl %1, %0" : "=r" (r) : "rm" (x) : "cc"); return r;
+}
+#else
+#define lj_fls(x) ((uint32_t)(__builtin_clz(x)^31))
+#endif
+
+#if defined(__arm__)
+static LJ_AINLINE uint32_t lj_bswap(uint32_t x)
+{
+#if defined(__psp2__)
+ return __builtin_rev(x);
+#else
+ uint32_t r;
+#if __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6T2__ || __ARM_ARCH_6Z__ ||\
+ __ARM_ARCH_6ZK__ || __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__
+ __asm__("rev %0, %1" : "=r" (r) : "r" (x));
+ return r;
+#else
+#ifdef __thumb__
+ r = x ^ lj_ror(x, 16);
+#else
+ __asm__("eor %0, %1, %1, ror #16" : "=r" (r) : "r" (x));
+#endif
+ return ((r & 0xff00ffffu) >> 8) ^ lj_ror(x, 8);
+#endif
+#endif
+}
+
+static LJ_AINLINE uint64_t lj_bswap64(uint64_t x)
+{
+ return ((uint64_t)lj_bswap((uint32_t)x)<<32) | lj_bswap((uint32_t)(x>>32));
+}
+#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+static LJ_AINLINE uint32_t lj_bswap(uint32_t x)
+{
+ return (uint32_t)__builtin_bswap32((int32_t)x);
+}
+
+static LJ_AINLINE uint64_t lj_bswap64(uint64_t x)
+{
+ return (uint64_t)__builtin_bswap64((int64_t)x);
+}
+#elif defined(__i386__) || defined(__x86_64__)
+static LJ_AINLINE uint32_t lj_bswap(uint32_t x)
+{
+ uint32_t r; __asm__("bswap %0" : "=r" (r) : "0" (x)); return r;
+}
+
+#if defined(__i386__)
+static LJ_AINLINE uint64_t lj_bswap64(uint64_t x)
+{
+ return ((uint64_t)lj_bswap((uint32_t)x)<<32) | lj_bswap((uint32_t)(x>>32));
+}
+#else
+static LJ_AINLINE uint64_t lj_bswap64(uint64_t x)
+{
+ uint64_t r; __asm__("bswap %0" : "=r" (r) : "0" (x)); return r;
+}
+#endif
+#else
+static LJ_AINLINE uint32_t lj_bswap(uint32_t x)
+{
+ return (x << 24) | ((x & 0xff00) << 8) | ((x >> 8) & 0xff00) | (x >> 24);
+}
+
+static LJ_AINLINE uint64_t lj_bswap64(uint64_t x)
+{
+ return (uint64_t)lj_bswap((uint32_t)(x >> 32)) |
+ ((uint64_t)lj_bswap((uint32_t)x) << 32);
+}
+#endif
+
+typedef union __attribute__((packed)) Unaligned16 {
+ uint16_t u;
+ uint8_t b[2];
+} Unaligned16;
+
+typedef union __attribute__((packed)) Unaligned32 {
+ uint32_t u;
+ uint8_t b[4];
+} Unaligned32;
+
+/* Unaligned load of uint16_t. */
+static LJ_AINLINE uint16_t lj_getu16(const void *p)
+{
+ return ((const Unaligned16 *)p)->u;
+}
+
+/* Unaligned load of uint32_t. */
+static LJ_AINLINE uint32_t lj_getu32(const void *p)
+{
+ return ((const Unaligned32 *)p)->u;
+}
+
+#elif defined(_MSC_VER)
+
+#define LJ_NORET __declspec(noreturn)
+#define LJ_ALIGN(n) __declspec(align(n))
+#define LJ_INLINE __inline
+#define LJ_AINLINE __forceinline
+#define LJ_NOINLINE __declspec(noinline)
+#if defined(_M_IX86)
+#define LJ_FASTCALL __fastcall
+#endif
+
+#ifdef _M_PPC
+unsigned int _CountLeadingZeros(long);
+#pragma intrinsic(_CountLeadingZeros)
+static LJ_AINLINE uint32_t lj_fls(uint32_t x)
+{
+ return _CountLeadingZeros(x) ^ 31;
+}
+#else
+unsigned char _BitScanForward(uint32_t *, unsigned long);
+unsigned char _BitScanReverse(uint32_t *, unsigned long);
+#pragma intrinsic(_BitScanForward)
+#pragma intrinsic(_BitScanReverse)
+
+static LJ_AINLINE uint32_t lj_ffs(uint32_t x)
+{
+ uint32_t r; _BitScanForward(&r, x); return r;
+}
+
+static LJ_AINLINE uint32_t lj_fls(uint32_t x)
+{
+ uint32_t r; _BitScanReverse(&r, x); return r;
+}
+#endif
+
+unsigned long _byteswap_ulong(unsigned long);
+uint64_t _byteswap_uint64(uint64_t);
+#define lj_bswap(x) (_byteswap_ulong((x)))
+#define lj_bswap64(x) (_byteswap_uint64((x)))
+
+#if defined(_M_PPC) && defined(LUAJIT_NO_UNALIGNED)
+/*
+** Replacement for unaligned loads on Xbox 360. Disabled by default since it's
+** usually more costly than the occasional stall when crossing a cache-line.
+*/
+static LJ_AINLINE uint16_t lj_getu16(const void *v)
+{
+ const uint8_t *p = (const uint8_t *)v;
+ return (uint16_t)((p[0]<<8) | p[1]);
+}
+static LJ_AINLINE uint32_t lj_getu32(const void *v)
+{
+ const uint8_t *p = (const uint8_t *)v;
+ return (uint32_t)((p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]);
+}
+#else
+/* Unaligned loads are generally ok on x86/x64. */
+#define lj_getu16(p) (*(uint16_t *)(p))
+#define lj_getu32(p) (*(uint32_t *)(p))
+#endif
+
+#else
+#error "missing defines for your compiler"
+#endif
+
+/* Optional defines. */
+#ifndef LJ_FASTCALL
+#define LJ_FASTCALL
+#endif
+#ifndef LJ_NORET
+#define LJ_NORET
+#endif
+#ifndef LJ_NOAPI
+#define LJ_NOAPI extern
+#endif
+#ifndef LJ_LIKELY
+#define LJ_LIKELY(x) (x)
+#define LJ_UNLIKELY(x) (x)
+#endif
+
+/* Attributes for internal functions. */
+#define LJ_DATA LJ_NOAPI
+#define LJ_DATADEF
+#define LJ_ASMF LJ_NOAPI
+#define LJ_FUNCA LJ_NOAPI
+#if defined(ljamalg_c)
+#define LJ_FUNC static
+#else
+#define LJ_FUNC LJ_NOAPI
+#endif
+#define LJ_FUNC_NORET LJ_FUNC LJ_NORET
+#define LJ_FUNCA_NORET LJ_FUNCA LJ_NORET
+#define LJ_ASMF_NORET LJ_ASMF LJ_NORET
+
+/* Runtime assertions. */
+#ifdef lua_assert
+#define check_exp(c, e) (lua_assert(c), (e))
+#define api_check(l, e) lua_assert(e)
+#else
+#define lua_assert(c) ((void)0)
+#define check_exp(c, e) (e)
+#define api_check luai_apicheck
+#endif
+
+/* Static assertions. */
+#define LJ_ASSERT_NAME2(name, line) name ## line
+#define LJ_ASSERT_NAME(line) LJ_ASSERT_NAME2(lj_assert_, line)
+#ifdef __COUNTER__
+#define LJ_STATIC_ASSERT(cond) \
+ extern void LJ_ASSERT_NAME(__COUNTER__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
+#else
+#define LJ_STATIC_ASSERT(cond) \
+ extern void LJ_ASSERT_NAME(__LINE__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_dispatch.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_dispatch.h
new file mode 100644
index 0000000..e46a0ee
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_dispatch.h
@@ -0,0 +1,131 @@
+/*
+** Instruction dispatch handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_DISPATCH_H
+#define _LJ_DISPATCH_H
+
+#include "lj_obj.h"
+#include "lj_bc.h"
+#if LJ_HASJIT
+#include "lj_jit.h"
+#endif
+
+#if LJ_TARGET_MIPS
+/* Need our own global offset table for the dreaded MIPS calling conventions. */
+#if LJ_HASJIT
+#define JITGOTDEF(_) _(lj_trace_exit) _(lj_trace_hot)
+#else
+#define JITGOTDEF(_)
+#endif
+#if LJ_HASFFI
+#define FFIGOTDEF(_) \
+ _(lj_meta_equal_cd) _(lj_ccallback_enter) _(lj_ccallback_leave)
+#else
+#define FFIGOTDEF(_)
+#endif
+#define GOTDEF(_) \
+ _(floor) _(ceil) _(trunc) _(log) _(log10) _(exp) _(sin) _(cos) _(tan) \
+ _(asin) _(acos) _(atan) _(sinh) _(cosh) _(tanh) _(frexp) _(modf) _(atan2) \
+ _(pow) _(fmod) _(ldexp) \
+ _(lj_dispatch_call) _(lj_dispatch_ins) _(lj_err_throw) \
+ _(lj_ffh_coroutine_wrap_err) _(lj_func_closeuv) _(lj_func_newL_gc) \
+ _(lj_gc_barrieruv) _(lj_gc_step) _(lj_gc_step_fixtop) _(lj_meta_arith) \
+ _(lj_meta_call) _(lj_meta_cat) _(lj_meta_comp) _(lj_meta_equal) \
+ _(lj_meta_for) _(lj_meta_len) _(lj_meta_tget) _(lj_meta_tset) \
+ _(lj_state_growstack) _(lj_str_fromnum) _(lj_str_fromnumber) _(lj_str_new) \
+ _(lj_tab_dup) _(lj_tab_get) _(lj_tab_getinth) _(lj_tab_len) _(lj_tab_new) \
+ _(lj_tab_newkey) _(lj_tab_next) _(lj_tab_reasize) \
+ JITGOTDEF(_) FFIGOTDEF(_)
+
+enum {
+#define GOTENUM(name) LJ_GOT_##name,
+GOTDEF(GOTENUM)
+#undef GOTENUM
+ LJ_GOT__MAX
+};
+#endif
+
+/* Type of hot counter. Must match the code in the assembler VM. */
+/* 16 bits are sufficient. Only 0.0015% overhead with maximum slot penalty. */
+typedef uint16_t HotCount;
+
+/* Number of hot counter hash table entries (must be a power of two). */
+#define HOTCOUNT_SIZE 64
+#define HOTCOUNT_PCMASK ((HOTCOUNT_SIZE-1)*sizeof(HotCount))
+
+/* Hotcount decrements. */
+#define HOTCOUNT_LOOP 2
+#define HOTCOUNT_CALL 1
+
+/* This solves a circular dependency problem -- bump as needed. Sigh. */
+#define GG_NUM_ASMFF 62
+
+#define GG_LEN_DDISP (BC__MAX + GG_NUM_ASMFF)
+#define GG_LEN_SDISP BC_FUNCF
+#define GG_LEN_DISP (GG_LEN_DDISP + GG_LEN_SDISP)
+
+/* Global state, main thread and extra fields are allocated together. */
+typedef struct GG_State {
+ lua_State L; /* Main thread. */
+ global_State g; /* Global state. */
+#if LJ_TARGET_MIPS
+ ASMFunction got[LJ_GOT__MAX]; /* Global offset table. */
+#endif
+#if LJ_HASJIT
+ jit_State J; /* JIT state. */
+ HotCount hotcount[HOTCOUNT_SIZE]; /* Hot counters. */
+#endif
+ ASMFunction dispatch[GG_LEN_DISP]; /* Instruction dispatch tables. */
+ BCIns bcff[GG_NUM_ASMFF]; /* Bytecode for ASM fast functions. */
+} GG_State;
+
+#define GG_OFS(field) ((int)offsetof(GG_State, field))
+#define G2GG(gl) ((GG_State *)((char *)(gl) - GG_OFS(g)))
+#define J2GG(j) ((GG_State *)((char *)(j) - GG_OFS(J)))
+#define L2GG(L) (G2GG(G(L)))
+#define J2G(J) (&J2GG(J)->g)
+#define G2J(gl) (&G2GG(gl)->J)
+#define L2J(L) (&L2GG(L)->J)
+#define GG_G2DISP (GG_OFS(dispatch) - GG_OFS(g))
+#define GG_DISP2G (GG_OFS(g) - GG_OFS(dispatch))
+#define GG_DISP2J (GG_OFS(J) - GG_OFS(dispatch))
+#define GG_DISP2HOT (GG_OFS(hotcount) - GG_OFS(dispatch))
+#define GG_DISP2STATIC (GG_LEN_DDISP*(int)sizeof(ASMFunction))
+
+#define hotcount_get(gg, pc) \
+ (gg)->hotcount[(u32ptr(pc)>>2) & (HOTCOUNT_SIZE-1)]
+#define hotcount_set(gg, pc, val) \
+ (hotcount_get((gg), (pc)) = (HotCount)(val))
+
+/* Dispatch table management. */
+LJ_FUNC void lj_dispatch_init(GG_State *GG);
+#if LJ_HASJIT
+LJ_FUNC void lj_dispatch_init_hotcount(global_State *g);
+#endif
+LJ_FUNC void lj_dispatch_update(global_State *g);
+
+/* Instruction dispatch callback for hooks or when recording. */
+LJ_FUNCA void LJ_FASTCALL lj_dispatch_ins(lua_State *L, const BCIns *pc);
+LJ_FUNCA ASMFunction LJ_FASTCALL lj_dispatch_call(lua_State *L, const BCIns*pc);
+LJ_FUNCA void LJ_FASTCALL lj_dispatch_return(lua_State *L, const BCIns *pc);
+
+#if LJ_HASFFI && !defined(_BUILDVM_H)
+/* Save/restore errno and GetLastError() around hooks, exits and recording. */
+#include <errno.h>
+#if LJ_TARGET_WINDOWS
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#define ERRNO_SAVE int olderr = errno; DWORD oldwerr = GetLastError();
+#define ERRNO_RESTORE errno = olderr; SetLastError(oldwerr);
+#else
+#define ERRNO_SAVE int olderr = errno;
+#define ERRNO_RESTORE errno = olderr;
+#endif
+#else
+#define ERRNO_SAVE
+#define ERRNO_RESTORE
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_emit_arm.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_emit_arm.h
new file mode 100644
index 0000000..285c98d
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_emit_arm.h
@@ -0,0 +1,356 @@
+/*
+** ARM instruction emitter.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* -- Constant encoding --------------------------------------------------- */
+
+static uint8_t emit_invai[16] = {
+ /* AND */ (ARMI_AND^ARMI_BIC) >> 21,
+ /* EOR */ 0,
+ /* SUB */ (ARMI_SUB^ARMI_ADD) >> 21,
+ /* RSB */ 0,
+ /* ADD */ (ARMI_ADD^ARMI_SUB) >> 21,
+ /* ADC */ (ARMI_ADC^ARMI_SBC) >> 21,
+ /* SBC */ (ARMI_SBC^ARMI_ADC) >> 21,
+ /* RSC */ 0,
+ /* TST */ 0,
+ /* TEQ */ 0,
+ /* CMP */ (ARMI_CMP^ARMI_CMN) >> 21,
+ /* CMN */ (ARMI_CMN^ARMI_CMP) >> 21,
+ /* ORR */ 0,
+ /* MOV */ (ARMI_MOV^ARMI_MVN) >> 21,
+ /* BIC */ (ARMI_BIC^ARMI_AND) >> 21,
+ /* MVN */ (ARMI_MVN^ARMI_MOV) >> 21
+};
+
+/* Encode constant in K12 format for data processing instructions. */
+static uint32_t emit_isk12(ARMIns ai, int32_t n)
+{
+ uint32_t invai, i, m = (uint32_t)n;
+ /* K12: unsigned 8 bit value, rotated in steps of two bits. */
+ for (i = 0; i < 4096; i += 256, m = lj_rol(m, 2))
+ if (m <= 255) return ARMI_K12|m|i;
+ /* Otherwise try negation/complement with the inverse instruction. */
+ invai = emit_invai[((ai >> 21) & 15)];
+ if (!invai) return 0; /* Failed. No inverse instruction. */
+ m = ~(uint32_t)n;
+ if (invai == ((ARMI_SUB^ARMI_ADD) >> 21) ||
+ invai == (ARMI_CMP^ARMI_CMN) >> 21) m++;
+ for (i = 0; i < 4096; i += 256, m = lj_rol(m, 2))
+ if (m <= 255) return ARMI_K12|(invai<<21)|m|i;
+ return 0; /* Failed. */
+}
+
+/* -- Emit basic instructions --------------------------------------------- */
+
+static void emit_dnm(ASMState *as, ARMIns ai, Reg rd, Reg rn, Reg rm)
+{
+ *--as->mcp = ai | ARMF_D(rd) | ARMF_N(rn) | ARMF_M(rm);
+}
+
+static void emit_dm(ASMState *as, ARMIns ai, Reg rd, Reg rm)
+{
+ *--as->mcp = ai | ARMF_D(rd) | ARMF_M(rm);
+}
+
+static void emit_dn(ASMState *as, ARMIns ai, Reg rd, Reg rn)
+{
+ *--as->mcp = ai | ARMF_D(rd) | ARMF_N(rn);
+}
+
+static void emit_nm(ASMState *as, ARMIns ai, Reg rn, Reg rm)
+{
+ *--as->mcp = ai | ARMF_N(rn) | ARMF_M(rm);
+}
+
+static void emit_d(ASMState *as, ARMIns ai, Reg rd)
+{
+ *--as->mcp = ai | ARMF_D(rd);
+}
+
+static void emit_n(ASMState *as, ARMIns ai, Reg rn)
+{
+ *--as->mcp = ai | ARMF_N(rn);
+}
+
+static void emit_m(ASMState *as, ARMIns ai, Reg rm)
+{
+ *--as->mcp = ai | ARMF_M(rm);
+}
+
+static void emit_lsox(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs)
+{
+ lua_assert(ofs >= -255 && ofs <= 255);
+ if (ofs < 0) ofs = -ofs; else ai |= ARMI_LS_U;
+ *--as->mcp = ai | ARMI_LS_P | ARMI_LSX_I | ARMF_D(rd) | ARMF_N(rn) |
+ ((ofs & 0xf0) << 4) | (ofs & 0x0f);
+}
+
+static void emit_lso(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs)
+{
+ lua_assert(ofs >= -4095 && ofs <= 4095);
+ /* Combine LDR/STR pairs to LDRD/STRD. */
+ if (*as->mcp == (ai|ARMI_LS_P|ARMI_LS_U|ARMF_D(rd^1)|ARMF_N(rn)|(ofs^4)) &&
+ (ai & ~(ARMI_LDR^ARMI_STR)) == ARMI_STR && rd != rn &&
+ (uint32_t)ofs <= 252 && !(ofs & 3) && !((rd ^ (ofs >>2)) & 1) &&
+ as->mcp != as->mcloop) {
+ as->mcp++;
+ emit_lsox(as, ai == ARMI_LDR ? ARMI_LDRD : ARMI_STRD, rd&~1, rn, ofs&~4);
+ return;
+ }
+ if (ofs < 0) ofs = -ofs; else ai |= ARMI_LS_U;
+ *--as->mcp = ai | ARMI_LS_P | ARMF_D(rd) | ARMF_N(rn) | ofs;
+}
+
+#if !LJ_SOFTFP
+static void emit_vlso(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs)
+{
+ lua_assert(ofs >= -1020 && ofs <= 1020 && (ofs&3) == 0);
+ if (ofs < 0) ofs = -ofs; else ai |= ARMI_LS_U;
+ *--as->mcp = ai | ARMI_LS_P | ARMF_D(rd & 15) | ARMF_N(rn) | (ofs >> 2);
+}
+#endif
+
+/* -- Emit loads/stores --------------------------------------------------- */
+
+/* Prefer spills of BASE/L. */
+#define emit_canremat(ref) ((ref) < ASMREF_L)
+
+/* Try to find a one step delta relative to another constant. */
+static int emit_kdelta1(ASMState *as, Reg d, int32_t i)
+{
+ RegSet work = ~as->freeset & RSET_GPR;
+ while (work) {
+ Reg r = rset_picktop(work);
+ IRRef ref = regcost_ref(as->cost[r]);
+ lua_assert(r != d);
+ if (emit_canremat(ref)) {
+ int32_t delta = i - (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i);
+ uint32_t k = emit_isk12(ARMI_ADD, delta);
+ if (k) {
+ if (k == ARMI_K12)
+ emit_dm(as, ARMI_MOV, d, r);
+ else
+ emit_dn(as, ARMI_ADD^k, d, r);
+ return 1;
+ }
+ }
+ rset_clear(work, r);
+ }
+ return 0; /* Failed. */
+}
+
+/* Try to find a two step delta relative to another constant. */
+static int emit_kdelta2(ASMState *as, Reg d, int32_t i)
+{
+ RegSet work = ~as->freeset & RSET_GPR;
+ while (work) {
+ Reg r = rset_picktop(work);
+ IRRef ref = regcost_ref(as->cost[r]);
+ lua_assert(r != d);
+ if (emit_canremat(ref)) {
+ int32_t other = ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i;
+ if (other) {
+ int32_t delta = i - other;
+ uint32_t sh, inv = 0, k2, k;
+ if (delta < 0) { delta = -delta; inv = ARMI_ADD^ARMI_SUB; }
+ sh = lj_ffs(delta) & ~1;
+ k2 = emit_isk12(0, delta & (255 << sh));
+ k = emit_isk12(0, delta & ~(255 << sh));
+ if (k) {
+ emit_dn(as, ARMI_ADD^k2^inv, d, d);
+ emit_dn(as, ARMI_ADD^k^inv, d, r);
+ return 1;
+ }
+ }
+ }
+ rset_clear(work, r);
+ }
+ return 0; /* Failed. */
+}
+
+/* Load a 32 bit constant into a GPR. */
+static void emit_loadi(ASMState *as, Reg r, int32_t i)
+{
+ uint32_t k = emit_isk12(ARMI_MOV, i);
+ lua_assert(rset_test(as->freeset, r) || r == RID_TMP);
+ if (k) {
+ /* Standard K12 constant. */
+ emit_d(as, ARMI_MOV^k, r);
+ } else if ((as->flags & JIT_F_ARMV6T2) && (uint32_t)i < 0x00010000u) {
+ /* 16 bit loword constant for ARMv6T2. */
+ emit_d(as, ARMI_MOVW|(i & 0x0fff)|((i & 0xf000)<<4), r);
+ } else if (emit_kdelta1(as, r, i)) {
+ /* One step delta relative to another constant. */
+ } else if ((as->flags & JIT_F_ARMV6T2)) {
+ /* 32 bit hiword/loword constant for ARMv6T2. */
+ emit_d(as, ARMI_MOVT|((i>>16) & 0x0fff)|(((i>>16) & 0xf000)<<4), r);
+ emit_d(as, ARMI_MOVW|(i & 0x0fff)|((i & 0xf000)<<4), r);
+ } else if (emit_kdelta2(as, r, i)) {
+ /* Two step delta relative to another constant. */
+ } else {
+ /* Otherwise construct the constant with up to 4 instructions. */
+ /* NYI: use mvn+bic, use pc-relative loads. */
+ for (;;) {
+ uint32_t sh = lj_ffs(i) & ~1;
+ int32_t m = i & (255 << sh);
+ i &= ~(255 << sh);
+ if (i == 0) {
+ emit_d(as, ARMI_MOV ^ emit_isk12(0, m), r);
+ break;
+ }
+ emit_dn(as, ARMI_ORR ^ emit_isk12(0, m), r, r);
+ }
+ }
+}
+
+#define emit_loada(as, r, addr) emit_loadi(as, (r), i32ptr((addr)))
+
+static Reg ra_allock(ASMState *as, int32_t k, RegSet allow);
+
+/* Get/set from constant pointer. */
+static void emit_lsptr(ASMState *as, ARMIns ai, Reg r, void *p)
+{
+ int32_t i = i32ptr(p);
+ emit_lso(as, ai, r, ra_allock(as, (i & ~4095), rset_exclude(RSET_GPR, r)),
+ (i & 4095));
+}
+
+#if !LJ_SOFTFP
+/* Load a number constant into an FPR. */
+static void emit_loadn(ASMState *as, Reg r, cTValue *tv)
+{
+ int32_t i;
+ if ((as->flags & JIT_F_VFPV3) && !tv->u32.lo) {
+ uint32_t hi = tv->u32.hi;
+ uint32_t b = ((hi >> 22) & 0x1ff);
+ if (!(hi & 0xffff) && (b == 0x100 || b == 0x0ff)) {
+ *--as->mcp = ARMI_VMOVI_D | ARMF_D(r & 15) |
+ ((tv->u32.hi >> 12) & 0x00080000) |
+ ((tv->u32.hi >> 4) & 0x00070000) |
+ ((tv->u32.hi >> 16) & 0x0000000f);
+ return;
+ }
+ }
+ i = i32ptr(tv);
+ emit_vlso(as, ARMI_VLDR_D, r,
+ ra_allock(as, (i & ~1020), RSET_GPR), (i & 1020));
+}
+#endif
+
+/* Get/set global_State fields. */
+#define emit_getgl(as, r, field) \
+ emit_lsptr(as, ARMI_LDR, (r), (void *)&J2G(as->J)->field)
+#define emit_setgl(as, r, field) \
+ emit_lsptr(as, ARMI_STR, (r), (void *)&J2G(as->J)->field)
+
+/* Trace number is determined from pc of exit instruction. */
+#define emit_setvmstate(as, i) UNUSED(i)
+
+/* -- Emit control-flow instructions -------------------------------------- */
+
+/* Label for internal jumps. */
+typedef MCode *MCLabel;
+
+/* Return label pointing to current PC. */
+#define emit_label(as) ((as)->mcp)
+
+static void emit_branch(ASMState *as, ARMIns ai, MCode *target)
+{
+ MCode *p = as->mcp;
+ ptrdiff_t delta = (target - p) - 1;
+ lua_assert(((delta + 0x00800000) >> 24) == 0);
+ *--p = ai | ((uint32_t)delta & 0x00ffffffu);
+ as->mcp = p;
+}
+
+#define emit_jmp(as, target) emit_branch(as, ARMI_B, (target))
+
+static void emit_call(ASMState *as, void *target)
+{
+ MCode *p = --as->mcp;
+ ptrdiff_t delta = ((char *)target - (char *)p) - 8;
+ if ((((delta>>2) + 0x00800000) >> 24) == 0) {
+ if ((delta & 1))
+ *p = ARMI_BLX | ((uint32_t)(delta>>2) & 0x00ffffffu) | ((delta&2) << 23);
+ else
+ *p = ARMI_BL | ((uint32_t)(delta>>2) & 0x00ffffffu);
+ } else { /* Target out of range: need indirect call. But don't use R0-R3. */
+ Reg r = ra_allock(as, i32ptr(target), RSET_RANGE(RID_R4, RID_R12+1));
+ *p = ARMI_BLXr | ARMF_M(r);
+ }
+}
+
+/* -- Emit generic operations --------------------------------------------- */
+
+/* Generic move between two regs. */
+static void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src)
+{
+#if LJ_SOFTFP
+ lua_assert(!irt_isnum(ir->t)); UNUSED(ir);
+#else
+ if (dst >= RID_MAX_GPR) {
+ emit_dm(as, irt_isnum(ir->t) ? ARMI_VMOV_D : ARMI_VMOV_S,
+ (dst & 15), (src & 15));
+ return;
+ }
+#endif
+ if (as->mcp != as->mcloop) { /* Swap early registers for loads/stores. */
+ MCode ins = *as->mcp, swp = (src^dst);
+ if ((ins & 0x0c000000) == 0x04000000 && (ins & 0x02000010) != 0x02000010) {
+ if (!((ins ^ (dst << 16)) & 0x000f0000))
+ *as->mcp = ins ^ (swp << 16); /* Swap N in load/store. */
+ if (!(ins & 0x00100000) && !((ins ^ (dst << 12)) & 0x0000f000))
+ *as->mcp = ins ^ (swp << 12); /* Swap D in store. */
+ }
+ }
+ emit_dm(as, ARMI_MOV, dst, src);
+}
+
+/* Generic load of register from stack slot. */
+static void emit_spload(ASMState *as, IRIns *ir, Reg r, int32_t ofs)
+{
+#if LJ_SOFTFP
+ lua_assert(!irt_isnum(ir->t)); UNUSED(ir);
+#else
+ if (r >= RID_MAX_GPR)
+ emit_vlso(as, irt_isnum(ir->t) ? ARMI_VLDR_D : ARMI_VLDR_S, r, RID_SP, ofs);
+ else
+#endif
+ emit_lso(as, ARMI_LDR, r, RID_SP, ofs);
+}
+
+/* Generic store of register to stack slot. */
+static void emit_spstore(ASMState *as, IRIns *ir, Reg r, int32_t ofs)
+{
+#if LJ_SOFTFP
+ lua_assert(!irt_isnum(ir->t)); UNUSED(ir);
+#else
+ if (r >= RID_MAX_GPR)
+ emit_vlso(as, irt_isnum(ir->t) ? ARMI_VSTR_D : ARMI_VSTR_S, r, RID_SP, ofs);
+ else
+#endif
+ emit_lso(as, ARMI_STR, r, RID_SP, ofs);
+}
+
+/* Emit an arithmetic/logic operation with a constant operand. */
+static void emit_opk(ASMState *as, ARMIns ai, Reg dest, Reg src,
+ int32_t i, RegSet allow)
+{
+ uint32_t k = emit_isk12(ai, i);
+ if (k)
+ emit_dn(as, ai^k, dest, src);
+ else
+ emit_dnm(as, ai, dest, src, ra_allock(as, i, allow));
+}
+
+/* Add offset to pointer. */
+static void emit_addptr(ASMState *as, Reg r, int32_t ofs)
+{
+ if (ofs)
+ emit_opk(as, ARMI_ADD, r, r, ofs, rset_exclude(RSET_GPR, r));
+}
+
+#define emit_spsub(as, ofs) emit_addptr(as, RID_SP, -(ofs))
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_emit_mips.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_emit_mips.h
new file mode 100644
index 0000000..ed62608
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_emit_mips.h
@@ -0,0 +1,211 @@
+/*
+** MIPS instruction emitter.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* -- Emit basic instructions --------------------------------------------- */
+
+static void emit_dst(ASMState *as, MIPSIns mi, Reg rd, Reg rs, Reg rt)
+{
+ *--as->mcp = mi | MIPSF_D(rd) | MIPSF_S(rs) | MIPSF_T(rt);
+}
+
+static void emit_dta(ASMState *as, MIPSIns mi, Reg rd, Reg rt, uint32_t a)
+{
+ *--as->mcp = mi | MIPSF_D(rd) | MIPSF_T(rt) | MIPSF_A(a);
+}
+
+#define emit_ds(as, mi, rd, rs) emit_dst(as, (mi), (rd), (rs), 0)
+#define emit_tg(as, mi, rt, rg) emit_dst(as, (mi), (rg)&31, 0, (rt))
+
+static void emit_tsi(ASMState *as, MIPSIns mi, Reg rt, Reg rs, int32_t i)
+{
+ *--as->mcp = mi | MIPSF_T(rt) | MIPSF_S(rs) | (i & 0xffff);
+}
+
+#define emit_ti(as, mi, rt, i) emit_tsi(as, (mi), (rt), 0, (i))
+#define emit_hsi(as, mi, rh, rs, i) emit_tsi(as, (mi), (rh) & 31, (rs), (i))
+
+static void emit_fgh(ASMState *as, MIPSIns mi, Reg rf, Reg rg, Reg rh)
+{
+ *--as->mcp = mi | MIPSF_F(rf&31) | MIPSF_G(rg&31) | MIPSF_H(rh&31);
+}
+
+#define emit_fg(as, mi, rf, rg) emit_fgh(as, (mi), (rf), (rg), 0)
+
+static void emit_rotr(ASMState *as, Reg dest, Reg src, Reg tmp, uint32_t shift)
+{
+ if ((as->flags & JIT_F_MIPS32R2)) {
+ emit_dta(as, MIPSI_ROTR, dest, src, shift);
+ } else {
+ emit_dst(as, MIPSI_OR, dest, dest, tmp);
+ emit_dta(as, MIPSI_SLL, dest, src, (-shift)&31);
+ emit_dta(as, MIPSI_SRL, tmp, src, shift);
+ }
+}
+
+/* -- Emit loads/stores --------------------------------------------------- */
+
+/* Prefer rematerialization of BASE/L from global_State over spills. */
+#define emit_canremat(ref) ((ref) <= REF_BASE)
+
+/* Try to find a one step delta relative to another constant. */
+static int emit_kdelta1(ASMState *as, Reg t, int32_t i)
+{
+ RegSet work = ~as->freeset & RSET_GPR;
+ while (work) {
+ Reg r = rset_picktop(work);
+ IRRef ref = regcost_ref(as->cost[r]);
+ lua_assert(r != t);
+ if (ref < ASMREF_L) {
+ int32_t delta = i - (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i);
+ if (checki16(delta)) {
+ emit_tsi(as, MIPSI_ADDIU, t, r, delta);
+ return 1;
+ }
+ }
+ rset_clear(work, r);
+ }
+ return 0; /* Failed. */
+}
+
+/* Load a 32 bit constant into a GPR. */
+static void emit_loadi(ASMState *as, Reg r, int32_t i)
+{
+ if (checki16(i)) {
+ emit_ti(as, MIPSI_LI, r, i);
+ } else {
+ if ((i & 0xffff)) {
+ int32_t jgl = i32ptr(J2G(as->J));
+ if ((uint32_t)(i-jgl) < 65536) {
+ emit_tsi(as, MIPSI_ADDIU, r, RID_JGL, i-jgl-32768);
+ return;
+ } else if (emit_kdelta1(as, r, i)) {
+ return;
+ } else if ((i >> 16) == 0) {
+ emit_tsi(as, MIPSI_ORI, r, RID_ZERO, i);
+ return;
+ }
+ emit_tsi(as, MIPSI_ORI, r, r, i);
+ }
+ emit_ti(as, MIPSI_LUI, r, (i >> 16));
+ }
+}
+
+#define emit_loada(as, r, addr) emit_loadi(as, (r), i32ptr((addr)))
+
+static Reg ra_allock(ASMState *as, int32_t k, RegSet allow);
+static void ra_allockreg(ASMState *as, int32_t k, Reg r);
+
+/* Get/set from constant pointer. */
+static void emit_lsptr(ASMState *as, MIPSIns mi, Reg r, void *p, RegSet allow)
+{
+ int32_t jgl = i32ptr(J2G(as->J));
+ int32_t i = i32ptr(p);
+ Reg base;
+ if ((uint32_t)(i-jgl) < 65536) {
+ i = i-jgl-32768;
+ base = RID_JGL;
+ } else {
+ base = ra_allock(as, i-(int16_t)i, allow);
+ }
+ emit_tsi(as, mi, r, base, i);
+}
+
+#define emit_loadn(as, r, tv) \
+ emit_lsptr(as, MIPSI_LDC1, ((r) & 31), (void *)(tv), RSET_GPR)
+
+/* Get/set global_State fields. */
+static void emit_lsglptr(ASMState *as, MIPSIns mi, Reg r, int32_t ofs)
+{
+ emit_tsi(as, mi, r, RID_JGL, ofs-32768);
+}
+
+#define emit_getgl(as, r, field) \
+ emit_lsglptr(as, MIPSI_LW, (r), (int32_t)offsetof(global_State, field))
+#define emit_setgl(as, r, field) \
+ emit_lsglptr(as, MIPSI_SW, (r), (int32_t)offsetof(global_State, field))
+
+/* Trace number is determined from per-trace exit stubs. */
+#define emit_setvmstate(as, i) UNUSED(i)
+
+/* -- Emit control-flow instructions -------------------------------------- */
+
+/* Label for internal jumps. */
+typedef MCode *MCLabel;
+
+/* Return label pointing to current PC. */
+#define emit_label(as) ((as)->mcp)
+
+static void emit_branch(ASMState *as, MIPSIns mi, Reg rs, Reg rt, MCode *target)
+{
+ MCode *p = as->mcp;
+ ptrdiff_t delta = target - p;
+ lua_assert(((delta + 0x8000) >> 16) == 0);
+ *--p = mi | MIPSF_S(rs) | MIPSF_T(rt) | ((uint32_t)delta & 0xffffu);
+ as->mcp = p;
+}
+
+static void emit_jmp(ASMState *as, MCode *target)
+{
+ *--as->mcp = MIPSI_NOP;
+ emit_branch(as, MIPSI_B, RID_ZERO, RID_ZERO, (target));
+}
+
+static void emit_call(ASMState *as, void *target)
+{
+ MCode *p = as->mcp;
+ *--p = MIPSI_NOP;
+ if ((((uintptr_t)target ^ (uintptr_t)p) >> 28) == 0)
+ *--p = MIPSI_JAL | (((uintptr_t)target >>2) & 0x03ffffffu);
+ else /* Target out of range: need indirect call. */
+ *--p = MIPSI_JALR | MIPSF_S(RID_CFUNCADDR);
+ as->mcp = p;
+ ra_allockreg(as, i32ptr(target), RID_CFUNCADDR);
+}
+
+/* -- Emit generic operations --------------------------------------------- */
+
+#define emit_move(as, dst, src) \
+ emit_ds(as, MIPSI_MOVE, (dst), (src))
+
+/* Generic move between two regs. */
+static void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src)
+{
+ if (dst < RID_MAX_GPR)
+ emit_move(as, dst, src);
+ else
+ emit_fg(as, irt_isnum(ir->t) ? MIPSI_MOV_D : MIPSI_MOV_S, dst, src);
+}
+
+/* Generic load of register from stack slot. */
+static void emit_spload(ASMState *as, IRIns *ir, Reg r, int32_t ofs)
+{
+ if (r < RID_MAX_GPR)
+ emit_tsi(as, MIPSI_LW, r, RID_SP, ofs);
+ else
+ emit_tsi(as, irt_isnum(ir->t) ? MIPSI_LDC1 : MIPSI_LWC1,
+ (r & 31), RID_SP, ofs);
+}
+
+/* Generic store of register to stack slot. */
+static void emit_spstore(ASMState *as, IRIns *ir, Reg r, int32_t ofs)
+{
+ if (r < RID_MAX_GPR)
+ emit_tsi(as, MIPSI_SW, r, RID_SP, ofs);
+ else
+ emit_tsi(as, irt_isnum(ir->t) ? MIPSI_SDC1 : MIPSI_SWC1,
+ (r&31), RID_SP, ofs);
+}
+
+/* Add offset to pointer. */
+static void emit_addptr(ASMState *as, Reg r, int32_t ofs)
+{
+ if (ofs) {
+ lua_assert(checki16(ofs));
+ emit_tsi(as, MIPSI_ADDIU, r, r, ofs);
+ }
+}
+
+#define emit_spsub(as, ofs) emit_addptr(as, RID_SP, -(ofs))
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_emit_ppc.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_emit_ppc.h
new file mode 100644
index 0000000..1409930
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_emit_ppc.h
@@ -0,0 +1,238 @@
+/*
+** PPC instruction emitter.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* -- Emit basic instructions --------------------------------------------- */
+
+static void emit_tab(ASMState *as, PPCIns pi, Reg rt, Reg ra, Reg rb)
+{
+ *--as->mcp = pi | PPCF_T(rt) | PPCF_A(ra) | PPCF_B(rb);
+}
+
+#define emit_asb(as, pi, ra, rs, rb) emit_tab(as, (pi), (rs), (ra), (rb))
+#define emit_as(as, pi, ra, rs) emit_tab(as, (pi), (rs), (ra), 0)
+#define emit_ab(as, pi, ra, rb) emit_tab(as, (pi), 0, (ra), (rb))
+
+static void emit_tai(ASMState *as, PPCIns pi, Reg rt, Reg ra, int32_t i)
+{
+ *--as->mcp = pi | PPCF_T(rt) | PPCF_A(ra) | (i & 0xffff);
+}
+
+#define emit_ti(as, pi, rt, i) emit_tai(as, (pi), (rt), 0, (i))
+#define emit_ai(as, pi, ra, i) emit_tai(as, (pi), 0, (ra), (i))
+#define emit_asi(as, pi, ra, rs, i) emit_tai(as, (pi), (rs), (ra), (i))
+
+#define emit_fab(as, pi, rf, ra, rb) \
+ emit_tab(as, (pi), (rf)&31, (ra)&31, (rb)&31)
+#define emit_fb(as, pi, rf, rb) emit_tab(as, (pi), (rf)&31, 0, (rb)&31)
+#define emit_fac(as, pi, rf, ra, rc) \
+ emit_tab(as, (pi) | PPCF_C((rc) & 31), (rf)&31, (ra)&31, 0)
+#define emit_facb(as, pi, rf, ra, rc, rb) \
+ emit_tab(as, (pi) | PPCF_C((rc) & 31), (rf)&31, (ra)&31, (rb)&31)
+#define emit_fai(as, pi, rf, ra, i) emit_tai(as, (pi), (rf)&31, (ra), (i))
+
+static void emit_rot(ASMState *as, PPCIns pi, Reg ra, Reg rs,
+ int32_t n, int32_t b, int32_t e)
+{
+ *--as->mcp = pi | PPCF_T(rs) | PPCF_A(ra) | PPCF_B(n) |
+ PPCF_MB(b) | PPCF_ME(e);
+}
+
+static void emit_slwi(ASMState *as, Reg ra, Reg rs, int32_t n)
+{
+ lua_assert(n >= 0 && n < 32);
+ emit_rot(as, PPCI_RLWINM, ra, rs, n, 0, 31-n);
+}
+
+static void emit_rotlwi(ASMState *as, Reg ra, Reg rs, int32_t n)
+{
+ lua_assert(n >= 0 && n < 32);
+ emit_rot(as, PPCI_RLWINM, ra, rs, n, 0, 31);
+}
+
+/* -- Emit loads/stores --------------------------------------------------- */
+
+/* Prefer rematerialization of BASE/L from global_State over spills. */
+#define emit_canremat(ref) ((ref) <= REF_BASE)
+
+/* Try to find a one step delta relative to another constant. */
+static int emit_kdelta1(ASMState *as, Reg t, int32_t i)
+{
+ RegSet work = ~as->freeset & RSET_GPR;
+ while (work) {
+ Reg r = rset_picktop(work);
+ IRRef ref = regcost_ref(as->cost[r]);
+ lua_assert(r != t);
+ if (ref < ASMREF_L) {
+ int32_t delta = i - (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i);
+ if (checki16(delta)) {
+ emit_tai(as, PPCI_ADDI, t, r, delta);
+ return 1;
+ }
+ }
+ rset_clear(work, r);
+ }
+ return 0; /* Failed. */
+}
+
+/* Load a 32 bit constant into a GPR. */
+static void emit_loadi(ASMState *as, Reg r, int32_t i)
+{
+ if (checki16(i)) {
+ emit_ti(as, PPCI_LI, r, i);
+ } else {
+ if ((i & 0xffff)) {
+ int32_t jgl = i32ptr(J2G(as->J));
+ if ((uint32_t)(i-jgl) < 65536) {
+ emit_tai(as, PPCI_ADDI, r, RID_JGL, i-jgl-32768);
+ return;
+ } else if (emit_kdelta1(as, r, i)) {
+ return;
+ }
+ emit_asi(as, PPCI_ORI, r, r, i);
+ }
+ emit_ti(as, PPCI_LIS, r, (i >> 16));
+ }
+}
+
+#define emit_loada(as, r, addr) emit_loadi(as, (r), i32ptr((addr)))
+
+static Reg ra_allock(ASMState *as, int32_t k, RegSet allow);
+
+/* Get/set from constant pointer. */
+static void emit_lsptr(ASMState *as, PPCIns pi, Reg r, void *p, RegSet allow)
+{
+ int32_t jgl = i32ptr(J2G(as->J));
+ int32_t i = i32ptr(p);
+ Reg base;
+ if ((uint32_t)(i-jgl) < 65536) {
+ i = i-jgl-32768;
+ base = RID_JGL;
+ } else {
+ base = ra_allock(as, i-(int16_t)i, allow);
+ }
+ emit_tai(as, pi, r, base, i);
+}
+
+#define emit_loadn(as, r, tv) \
+ emit_lsptr(as, PPCI_LFD, ((r) & 31), (void *)(tv), RSET_GPR)
+
+/* Get/set global_State fields. */
+static void emit_lsglptr(ASMState *as, PPCIns pi, Reg r, int32_t ofs)
+{
+ emit_tai(as, pi, r, RID_JGL, ofs-32768);
+}
+
+#define emit_getgl(as, r, field) \
+ emit_lsglptr(as, PPCI_LWZ, (r), (int32_t)offsetof(global_State, field))
+#define emit_setgl(as, r, field) \
+ emit_lsglptr(as, PPCI_STW, (r), (int32_t)offsetof(global_State, field))
+
+/* Trace number is determined from per-trace exit stubs. */
+#define emit_setvmstate(as, i) UNUSED(i)
+
+/* -- Emit control-flow instructions -------------------------------------- */
+
+/* Label for internal jumps. */
+typedef MCode *MCLabel;
+
+/* Return label pointing to current PC. */
+#define emit_label(as) ((as)->mcp)
+
+static void emit_condbranch(ASMState *as, PPCIns pi, PPCCC cc, MCode *target)
+{
+ MCode *p = --as->mcp;
+ ptrdiff_t delta = (char *)target - (char *)p;
+ lua_assert(((delta + 0x8000) >> 16) == 0);
+ pi ^= (delta & 0x8000) * (PPCF_Y/0x8000);
+ *p = pi | PPCF_CC(cc) | ((uint32_t)delta & 0xffffu);
+}
+
+static void emit_jmp(ASMState *as, MCode *target)
+{
+ MCode *p = --as->mcp;
+ ptrdiff_t delta = (char *)target - (char *)p;
+ *p = PPCI_B | (delta & 0x03fffffcu);
+}
+
+static void emit_call(ASMState *as, void *target)
+{
+ MCode *p = --as->mcp;
+ ptrdiff_t delta = (char *)target - (char *)p;
+ if ((((delta>>2) + 0x00800000) >> 24) == 0) {
+ *p = PPCI_BL | (delta & 0x03fffffcu);
+ } else { /* Target out of range: need indirect call. Don't use arg reg. */
+ RegSet allow = RSET_GPR & ~RSET_RANGE(RID_R0, REGARG_LASTGPR+1);
+ Reg r = ra_allock(as, i32ptr(target), allow);
+ *p = PPCI_BCTRL;
+ p[-1] = PPCI_MTCTR | PPCF_T(r);
+ as->mcp = p-1;
+ }
+}
+
+/* -- Emit generic operations --------------------------------------------- */
+
+#define emit_mr(as, dst, src) \
+ emit_asb(as, PPCI_MR, (dst), (src), (src))
+
+/* Generic move between two regs. */
+static void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src)
+{
+ UNUSED(ir);
+ if (dst < RID_MAX_GPR)
+ emit_mr(as, dst, src);
+ else
+ emit_fb(as, PPCI_FMR, dst, src);
+}
+
+/* Generic load of register from stack slot. */
+static void emit_spload(ASMState *as, IRIns *ir, Reg r, int32_t ofs)
+{
+ if (r < RID_MAX_GPR)
+ emit_tai(as, PPCI_LWZ, r, RID_SP, ofs);
+ else
+ emit_fai(as, irt_isnum(ir->t) ? PPCI_LFD : PPCI_LFS, r, RID_SP, ofs);
+}
+
+/* Generic store of register to stack slot. */
+static void emit_spstore(ASMState *as, IRIns *ir, Reg r, int32_t ofs)
+{
+ if (r < RID_MAX_GPR)
+ emit_tai(as, PPCI_STW, r, RID_SP, ofs);
+ else
+ emit_fai(as, irt_isnum(ir->t) ? PPCI_STFD : PPCI_STFS, r, RID_SP, ofs);
+}
+
+/* Emit a compare (for equality) with a constant operand. */
+static void emit_cmpi(ASMState *as, Reg r, int32_t k)
+{
+ if (checki16(k)) {
+ emit_ai(as, PPCI_CMPWI, r, k);
+ } else if (checku16(k)) {
+ emit_ai(as, PPCI_CMPLWI, r, k);
+ } else {
+ emit_ai(as, PPCI_CMPLWI, RID_TMP, k);
+ emit_asi(as, PPCI_XORIS, RID_TMP, r, (k >> 16));
+ }
+}
+
+/* Add offset to pointer. */
+static void emit_addptr(ASMState *as, Reg r, int32_t ofs)
+{
+ if (ofs) {
+ emit_tai(as, PPCI_ADDI, r, r, ofs);
+ if (!checki16(ofs))
+ emit_tai(as, PPCI_ADDIS, r, r, (ofs + 32768) >> 16);
+ }
+}
+
+static void emit_spsub(ASMState *as, int32_t ofs)
+{
+ if (ofs) {
+ emit_tai(as, PPCI_STWU, RID_TMP, RID_SP, -ofs);
+ emit_tai(as, PPCI_ADDI, RID_TMP, RID_SP,
+ CFRAME_SIZE + (as->parent ? as->parent->spadjust : 0));
+ }
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_emit_x86.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_emit_x86.h
new file mode 100644
index 0000000..9c371a9
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_emit_x86.h
@@ -0,0 +1,468 @@
+/*
+** x86/x64 instruction emitter.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* -- Emit basic instructions --------------------------------------------- */
+
+#define MODRM(mode, r1, r2) ((MCode)((mode)+(((r1)&7)<<3)+((r2)&7)))
+
+#if LJ_64
+#define REXRB(p, rr, rb) \
+ { MCode rex = 0x40 + (((rr)>>1)&4) + (((rb)>>3)&1); \
+ if (rex != 0x40) *--(p) = rex; }
+#define FORCE_REX 0x200
+#define REX_64 (FORCE_REX|0x080000)
+#else
+#define REXRB(p, rr, rb) ((void)0)
+#define FORCE_REX 0
+#define REX_64 0
+#endif
+
+#define emit_i8(as, i) (*--as->mcp = (MCode)(i))
+#define emit_i32(as, i) (*(int32_t *)(as->mcp-4) = (i), as->mcp -= 4)
+#define emit_u32(as, u) (*(uint32_t *)(as->mcp-4) = (u), as->mcp -= 4)
+
+#define emit_x87op(as, xo) \
+ (*(uint16_t *)(as->mcp-2) = (uint16_t)(xo), as->mcp -= 2)
+
+/* op */
+static LJ_AINLINE MCode *emit_op(x86Op xo, Reg rr, Reg rb, Reg rx,
+ MCode *p, int delta)
+{
+ int n = (int8_t)xo;
+#if defined(__GNUC__)
+ if (__builtin_constant_p(xo) && n == -2)
+ p[delta-2] = (MCode)(xo >> 24);
+ else if (__builtin_constant_p(xo) && n == -3)
+ *(uint16_t *)(p+delta-3) = (uint16_t)(xo >> 16);
+ else
+#endif
+ *(uint32_t *)(p+delta-5) = (uint32_t)xo;
+ p += n + delta;
+#if LJ_64
+ {
+ uint32_t rex = 0x40 + ((rr>>1)&(4+(FORCE_REX>>1)))+((rx>>2)&2)+((rb>>3)&1);
+ if (rex != 0x40) {
+ rex |= (rr >> 16);
+ if (n == -4) { *p = (MCode)rex; rex = (MCode)(xo >> 8); }
+ else if ((xo & 0xffffff) == 0x6600fd) { *p = (MCode)rex; rex = 0x66; }
+ *--p = (MCode)rex;
+ }
+ }
+#else
+ UNUSED(rr); UNUSED(rb); UNUSED(rx);
+#endif
+ return p;
+}
+
+/* op + modrm */
+#define emit_opm(xo, mode, rr, rb, p, delta) \
+ (p[(delta)-1] = MODRM((mode), (rr), (rb)), \
+ emit_op((xo), (rr), (rb), 0, (p), (delta)))
+
+/* op + modrm + sib */
+#define emit_opmx(xo, mode, scale, rr, rb, rx, p) \
+ (p[-1] = MODRM((scale), (rx), (rb)), \
+ p[-2] = MODRM((mode), (rr), RID_ESP), \
+ emit_op((xo), (rr), (rb), (rx), (p), -1))
+
+/* op r1, r2 */
+static void emit_rr(ASMState *as, x86Op xo, Reg r1, Reg r2)
+{
+ MCode *p = as->mcp;
+ as->mcp = emit_opm(xo, XM_REG, r1, r2, p, 0);
+}
+
+#if LJ_64 && defined(LUA_USE_ASSERT)
+/* [addr] is sign-extended in x64 and must be in lower 2G (not 4G). */
+static int32_t ptr2addr(const void *p)
+{
+ lua_assert((uintptr_t)p < (uintptr_t)0x80000000);
+ return i32ptr(p);
+}
+#else
+#define ptr2addr(p) (i32ptr((p)))
+#endif
+
+/* op r, [addr] */
+static void emit_rma(ASMState *as, x86Op xo, Reg rr, const void *addr)
+{
+ MCode *p = as->mcp;
+ *(int32_t *)(p-4) = ptr2addr(addr);
+#if LJ_64
+ p[-5] = MODRM(XM_SCALE1, RID_ESP, RID_EBP);
+ as->mcp = emit_opm(xo, XM_OFS0, rr, RID_ESP, p, -5);
+#else
+ as->mcp = emit_opm(xo, XM_OFS0, rr, RID_EBP, p, -4);
+#endif
+}
+
+/* op r, [base+ofs] */
+static void emit_rmro(ASMState *as, x86Op xo, Reg rr, Reg rb, int32_t ofs)
+{
+ MCode *p = as->mcp;
+ x86Mode mode;
+ if (ra_hasreg(rb)) {
+ if (ofs == 0 && (rb&7) != RID_EBP) {
+ mode = XM_OFS0;
+ } else if (checki8(ofs)) {
+ *--p = (MCode)ofs;
+ mode = XM_OFS8;
+ } else {
+ p -= 4;
+ *(int32_t *)p = ofs;
+ mode = XM_OFS32;
+ }
+ if ((rb&7) == RID_ESP)
+ *--p = MODRM(XM_SCALE1, RID_ESP, RID_ESP);
+ } else {
+ *(int32_t *)(p-4) = ofs;
+#if LJ_64
+ p[-5] = MODRM(XM_SCALE1, RID_ESP, RID_EBP);
+ p -= 5;
+ rb = RID_ESP;
+#else
+ p -= 4;
+ rb = RID_EBP;
+#endif
+ mode = XM_OFS0;
+ }
+ as->mcp = emit_opm(xo, mode, rr, rb, p, 0);
+}
+
+/* op r, [base+idx*scale+ofs] */
+static void emit_rmrxo(ASMState *as, x86Op xo, Reg rr, Reg rb, Reg rx,
+ x86Mode scale, int32_t ofs)
+{
+ MCode *p = as->mcp;
+ x86Mode mode;
+ if (ofs == 0 && (rb&7) != RID_EBP) {
+ mode = XM_OFS0;
+ } else if (checki8(ofs)) {
+ mode = XM_OFS8;
+ *--p = (MCode)ofs;
+ } else {
+ mode = XM_OFS32;
+ p -= 4;
+ *(int32_t *)p = ofs;
+ }
+ as->mcp = emit_opmx(xo, mode, scale, rr, rb, rx, p);
+}
+
+/* op r, i */
+static void emit_gri(ASMState *as, x86Group xg, Reg rb, int32_t i)
+{
+ MCode *p = as->mcp;
+ x86Op xo;
+ if (checki8(i)) {
+ *--p = (MCode)i;
+ xo = XG_TOXOi8(xg);
+ } else {
+ p -= 4;
+ *(int32_t *)p = i;
+ xo = XG_TOXOi(xg);
+ }
+ as->mcp = emit_opm(xo, XM_REG, (Reg)(xg & 7) | (rb & REX_64), rb, p, 0);
+}
+
+/* op [base+ofs], i */
+static void emit_gmroi(ASMState *as, x86Group xg, Reg rb, int32_t ofs,
+ int32_t i)
+{
+ x86Op xo;
+ if (checki8(i)) {
+ emit_i8(as, i);
+ xo = XG_TOXOi8(xg);
+ } else {
+ emit_i32(as, i);
+ xo = XG_TOXOi(xg);
+ }
+ emit_rmro(as, xo, (Reg)(xg & 7), rb, ofs);
+}
+
+#define emit_shifti(as, xg, r, i) \
+ (emit_i8(as, (i)), emit_rr(as, XO_SHIFTi, (Reg)(xg), (r)))
+
+/* op r, rm/mrm */
+static void emit_mrm(ASMState *as, x86Op xo, Reg rr, Reg rb)
+{
+ MCode *p = as->mcp;
+ x86Mode mode = XM_REG;
+ if (rb == RID_MRM) {
+ rb = as->mrm.base;
+ if (rb == RID_NONE) {
+ rb = RID_EBP;
+ mode = XM_OFS0;
+ p -= 4;
+ *(int32_t *)p = as->mrm.ofs;
+ if (as->mrm.idx != RID_NONE)
+ goto mrmidx;
+#if LJ_64
+ *--p = MODRM(XM_SCALE1, RID_ESP, RID_EBP);
+ rb = RID_ESP;
+#endif
+ } else {
+ if (as->mrm.ofs == 0 && (rb&7) != RID_EBP) {
+ mode = XM_OFS0;
+ } else if (checki8(as->mrm.ofs)) {
+ *--p = (MCode)as->mrm.ofs;
+ mode = XM_OFS8;
+ } else {
+ p -= 4;
+ *(int32_t *)p = as->mrm.ofs;
+ mode = XM_OFS32;
+ }
+ if (as->mrm.idx != RID_NONE) {
+ mrmidx:
+ as->mcp = emit_opmx(xo, mode, as->mrm.scale, rr, rb, as->mrm.idx, p);
+ return;
+ }
+ if ((rb&7) == RID_ESP)
+ *--p = MODRM(XM_SCALE1, RID_ESP, RID_ESP);
+ }
+ }
+ as->mcp = emit_opm(xo, mode, rr, rb, p, 0);
+}
+
+/* op rm/mrm, i */
+static void emit_gmrmi(ASMState *as, x86Group xg, Reg rb, int32_t i)
+{
+ x86Op xo;
+ if (checki8(i)) {
+ emit_i8(as, i);
+ xo = XG_TOXOi8(xg);
+ } else {
+ emit_i32(as, i);
+ xo = XG_TOXOi(xg);
+ }
+ emit_mrm(as, xo, (Reg)(xg & 7) | (rb & REX_64), (rb & ~REX_64));
+}
+
+/* -- Emit loads/stores --------------------------------------------------- */
+
+/* Instruction selection for XMM moves. */
+#define XMM_MOVRR(as) ((as->flags & JIT_F_SPLIT_XMM) ? XO_MOVSD : XO_MOVAPS)
+#define XMM_MOVRM(as) ((as->flags & JIT_F_SPLIT_XMM) ? XO_MOVLPD : XO_MOVSD)
+
+/* mov [base+ofs], i */
+static void emit_movmroi(ASMState *as, Reg base, int32_t ofs, int32_t i)
+{
+ emit_i32(as, i);
+ emit_rmro(as, XO_MOVmi, 0, base, ofs);
+}
+
+/* mov [base+ofs], r */
+#define emit_movtomro(as, r, base, ofs) \
+ emit_rmro(as, XO_MOVto, (r), (base), (ofs))
+
+/* Get/set global_State fields. */
+#define emit_opgl(as, xo, r, field) \
+ emit_rma(as, (xo), (r), (void *)&J2G(as->J)->field)
+#define emit_getgl(as, r, field) emit_opgl(as, XO_MOV, (r), field)
+#define emit_setgl(as, r, field) emit_opgl(as, XO_MOVto, (r), field)
+
+#define emit_setvmstate(as, i) \
+ (emit_i32(as, i), emit_opgl(as, XO_MOVmi, 0, vmstate))
+
+/* mov r, i / xor r, r */
+static void emit_loadi(ASMState *as, Reg r, int32_t i)
+{
+ /* XOR r,r is shorter, but modifies the flags. This is bad for HIOP/jcc. */
+ if (i == 0 && !(LJ_32 && (IR(as->curins)->o == IR_HIOP ||
+ (as->curins+1 < as->T->nins &&
+ IR(as->curins+1)->o == IR_HIOP))) &&
+ !((*as->mcp == 0x0f && (as->mcp[1] & 0xf0) == XI_JCCn) ||
+ (*as->mcp & 0xf0) == XI_JCCs)) {
+ emit_rr(as, XO_ARITH(XOg_XOR), r, r);
+ } else {
+ MCode *p = as->mcp;
+ *(int32_t *)(p-4) = i;
+ p[-5] = (MCode)(XI_MOVri+(r&7));
+ p -= 5;
+ REXRB(p, 0, r);
+ as->mcp = p;
+ }
+}
+
+/* mov r, addr */
+#define emit_loada(as, r, addr) \
+ emit_loadi(as, (r), ptr2addr((addr)))
+
+#if LJ_64
+/* mov r, imm64 or shorter 32 bit extended load. */
+static void emit_loadu64(ASMState *as, Reg r, uint64_t u64)
+{
+ if (checku32(u64)) { /* 32 bit load clears upper 32 bits. */
+ emit_loadi(as, r, (int32_t)u64);
+ } else if (checki32((int64_t)u64)) { /* Sign-extended 32 bit load. */
+ MCode *p = as->mcp;
+ *(int32_t *)(p-4) = (int32_t)u64;
+ as->mcp = emit_opm(XO_MOVmi, XM_REG, REX_64, r, p, -4);
+ } else { /* Full-size 64 bit load. */
+ MCode *p = as->mcp;
+ *(uint64_t *)(p-8) = u64;
+ p[-9] = (MCode)(XI_MOVri+(r&7));
+ p[-10] = 0x48 + ((r>>3)&1);
+ p -= 10;
+ as->mcp = p;
+ }
+}
+#endif
+
+/* movsd r, [&tv->n] / xorps r, r */
+static void emit_loadn(ASMState *as, Reg r, cTValue *tv)
+{
+ if (tvispzero(tv)) /* Use xor only for +0. */
+ emit_rr(as, XO_XORPS, r, r);
+ else
+ emit_rma(as, XMM_MOVRM(as), r, &tv->n);
+}
+
+/* -- Emit control-flow instructions -------------------------------------- */
+
+/* Label for short jumps. */
+typedef MCode *MCLabel;
+
+#if LJ_32 && LJ_HASFFI
+/* jmp short target */
+static void emit_sjmp(ASMState *as, MCLabel target)
+{
+ MCode *p = as->mcp;
+ ptrdiff_t delta = target - p;
+ lua_assert(delta == (int8_t)delta);
+ p[-1] = (MCode)(int8_t)delta;
+ p[-2] = XI_JMPs;
+ as->mcp = p - 2;
+}
+#endif
+
+/* jcc short target */
+static void emit_sjcc(ASMState *as, int cc, MCLabel target)
+{
+ MCode *p = as->mcp;
+ ptrdiff_t delta = target - p;
+ lua_assert(delta == (int8_t)delta);
+ p[-1] = (MCode)(int8_t)delta;
+ p[-2] = (MCode)(XI_JCCs+(cc&15));
+ as->mcp = p - 2;
+}
+
+/* jcc short (pending target) */
+static MCLabel emit_sjcc_label(ASMState *as, int cc)
+{
+ MCode *p = as->mcp;
+ p[-1] = 0;
+ p[-2] = (MCode)(XI_JCCs+(cc&15));
+ as->mcp = p - 2;
+ return p;
+}
+
+/* Fixup jcc short target. */
+static void emit_sfixup(ASMState *as, MCLabel source)
+{
+ source[-1] = (MCode)(as->mcp-source);
+}
+
+/* Return label pointing to current PC. */
+#define emit_label(as) ((as)->mcp)
+
+/* Compute relative 32 bit offset for jump and call instructions. */
+static LJ_AINLINE int32_t jmprel(MCode *p, MCode *target)
+{
+ ptrdiff_t delta = target - p;
+ lua_assert(delta == (int32_t)delta);
+ return (int32_t)delta;
+}
+
+/* jcc target */
+static void emit_jcc(ASMState *as, int cc, MCode *target)
+{
+ MCode *p = as->mcp;
+ *(int32_t *)(p-4) = jmprel(p, target);
+ p[-5] = (MCode)(XI_JCCn+(cc&15));
+ p[-6] = 0x0f;
+ as->mcp = p - 6;
+}
+
+/* jmp target */
+static void emit_jmp(ASMState *as, MCode *target)
+{
+ MCode *p = as->mcp;
+ *(int32_t *)(p-4) = jmprel(p, target);
+ p[-5] = XI_JMP;
+ as->mcp = p - 5;
+}
+
+/* call target */
+static void emit_call_(ASMState *as, MCode *target)
+{
+ MCode *p = as->mcp;
+#if LJ_64
+ if (target-p != (int32_t)(target-p)) {
+ /* Assumes RID_RET is never an argument to calls and always clobbered. */
+ emit_rr(as, XO_GROUP5, XOg_CALL, RID_RET);
+ emit_loadu64(as, RID_RET, (uint64_t)target);
+ return;
+ }
+#endif
+ *(int32_t *)(p-4) = jmprel(p, target);
+ p[-5] = XI_CALL;
+ as->mcp = p - 5;
+}
+
+#define emit_call(as, f) emit_call_(as, (MCode *)(void *)(f))
+
+/* -- Emit generic operations --------------------------------------------- */
+
+/* Use 64 bit operations to handle 64 bit IR types. */
+#if LJ_64
+#define REX_64IR(ir, r) ((r) + (irt_is64((ir)->t) ? REX_64 : 0))
+#else
+#define REX_64IR(ir, r) (r)
+#endif
+
+/* Generic move between two regs. */
+static void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src)
+{
+ UNUSED(ir);
+ if (dst < RID_MAX_GPR)
+ emit_rr(as, XO_MOV, REX_64IR(ir, dst), src);
+ else
+ emit_rr(as, XMM_MOVRR(as), dst, src);
+}
+
+/* Generic load of register from stack slot. */
+static void emit_spload(ASMState *as, IRIns *ir, Reg r, int32_t ofs)
+{
+ if (r < RID_MAX_GPR)
+ emit_rmro(as, XO_MOV, REX_64IR(ir, r), RID_ESP, ofs);
+ else
+ emit_rmro(as, irt_isnum(ir->t) ? XMM_MOVRM(as) : XO_MOVSS, r, RID_ESP, ofs);
+}
+
+/* Generic store of register to stack slot. */
+static void emit_spstore(ASMState *as, IRIns *ir, Reg r, int32_t ofs)
+{
+ if (r < RID_MAX_GPR)
+ emit_rmro(as, XO_MOVto, REX_64IR(ir, r), RID_ESP, ofs);
+ else
+ emit_rmro(as, irt_isnum(ir->t) ? XO_MOVSDto : XO_MOVSSto, r, RID_ESP, ofs);
+}
+
+/* Add offset to pointer. */
+static void emit_addptr(ASMState *as, Reg r, int32_t ofs)
+{
+ if (ofs) {
+ if ((as->flags & JIT_F_LEA_AGU))
+ emit_rmro(as, XO_LEA, r, r, ofs);
+ else
+ emit_gri(as, XG_ARITHi(XOg_ADD), r, ofs);
+ }
+}
+
+#define emit_spsub(as, ofs) emit_addptr(as, RID_ESP|REX_64, -(ofs))
+
+/* Prefer rematerialization of BASE/L from global_State over spills. */
+#define emit_canremat(ref) ((ref) <= REF_BASE)
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_err.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_err.h
new file mode 100644
index 0000000..cba5fb7
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_err.h
@@ -0,0 +1,41 @@
+/*
+** Error handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_ERR_H
+#define _LJ_ERR_H
+
+#include <stdarg.h>
+
+#include "lj_obj.h"
+
+typedef enum {
+#define ERRDEF(name, msg) \
+ LJ_ERR_##name, LJ_ERR_##name##_ = LJ_ERR_##name + sizeof(msg)-1,
+#include "lj_errmsg.h"
+ LJ_ERR__MAX
+} ErrMsg;
+
+LJ_DATA const char *lj_err_allmsg;
+#define err2msg(em) (lj_err_allmsg+(int)(em))
+
+LJ_FUNC GCstr *lj_err_str(lua_State *L, ErrMsg em);
+LJ_FUNCA_NORET void LJ_FASTCALL lj_err_throw(lua_State *L, int errcode);
+LJ_FUNC_NORET void lj_err_mem(lua_State *L);
+LJ_FUNC_NORET void lj_err_run(lua_State *L);
+LJ_FUNC_NORET void lj_err_msg(lua_State *L, ErrMsg em);
+LJ_FUNC_NORET void lj_err_lex(lua_State *L, GCstr *src, const char *tok,
+ BCLine line, ErrMsg em, va_list argp);
+LJ_FUNC_NORET void lj_err_optype(lua_State *L, cTValue *o, ErrMsg opm);
+LJ_FUNC_NORET void lj_err_comp(lua_State *L, cTValue *o1, cTValue *o2);
+LJ_FUNC_NORET void lj_err_optype_call(lua_State *L, TValue *o);
+LJ_FUNC_NORET void lj_err_callermsg(lua_State *L, const char *msg);
+LJ_FUNC_NORET void lj_err_callerv(lua_State *L, ErrMsg em, ...);
+LJ_FUNC_NORET void lj_err_caller(lua_State *L, ErrMsg em);
+LJ_FUNC_NORET void lj_err_arg(lua_State *L, int narg, ErrMsg em);
+LJ_FUNC_NORET void lj_err_argv(lua_State *L, int narg, ErrMsg em, ...);
+LJ_FUNC_NORET void lj_err_argtype(lua_State *L, int narg, const char *xname);
+LJ_FUNC_NORET void lj_err_argt(lua_State *L, int narg, int tt);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_errmsg.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_errmsg.h
new file mode 100644
index 0000000..ac552f4
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_errmsg.h
@@ -0,0 +1,193 @@
+/*
+** VM error messages.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* This file may be included multiple times with different ERRDEF macros. */
+
+/* Basic error handling. */
+ERRDEF(ERRMEM, "not enough memory")
+ERRDEF(ERRERR, "error in error handling")
+ERRDEF(ERRCPP, "C++ exception")
+
+/* Allocations. */
+ERRDEF(STROV, "string length overflow")
+ERRDEF(UDATAOV, "userdata length overflow")
+ERRDEF(STKOV, "stack overflow")
+ERRDEF(STKOVM, "stack overflow (%s)")
+ERRDEF(TABOV, "table overflow")
+
+/* Table indexing. */
+ERRDEF(NANIDX, "table index is NaN")
+ERRDEF(NILIDX, "table index is nil")
+ERRDEF(NEXTIDX, "invalid key to " LUA_QL("next"))
+
+/* Metamethod resolving. */
+ERRDEF(BADCALL, "attempt to call a %s value")
+ERRDEF(BADOPRT, "attempt to %s %s " LUA_QS " (a %s value)")
+ERRDEF(BADOPRV, "attempt to %s a %s value")
+ERRDEF(BADCMPT, "attempt to compare %s with %s")
+ERRDEF(BADCMPV, "attempt to compare two %s values")
+ERRDEF(GETLOOP, "loop in gettable")
+ERRDEF(SETLOOP, "loop in settable")
+ERRDEF(OPCALL, "call")
+ERRDEF(OPINDEX, "index")
+ERRDEF(OPARITH, "perform arithmetic on")
+ERRDEF(OPCAT, "concatenate")
+ERRDEF(OPLEN, "get length of")
+
+/* Type checks. */
+ERRDEF(BADSELF, "calling " LUA_QS " on bad self (%s)")
+ERRDEF(BADARG, "bad argument #%d to " LUA_QS " (%s)")
+ERRDEF(BADTYPE, "%s expected, got %s")
+ERRDEF(BADVAL, "invalid value")
+ERRDEF(NOVAL, "value expected")
+ERRDEF(NOCORO, "coroutine expected")
+ERRDEF(NOTABN, "nil or table expected")
+ERRDEF(NOLFUNC, "Lua function expected")
+ERRDEF(NOFUNCL, "function or level expected")
+ERRDEF(NOSFT, "string/function/table expected")
+ERRDEF(NOPROXY, "boolean or proxy expected")
+ERRDEF(FORINIT, LUA_QL("for") " initial value must be a number")
+ERRDEF(FORLIM, LUA_QL("for") " limit must be a number")
+ERRDEF(FORSTEP, LUA_QL("for") " step must be a number")
+
+/* C API checks. */
+ERRDEF(NOENV, "no calling environment")
+ERRDEF(CYIELD, "attempt to yield across C-call boundary")
+ERRDEF(BADLU, "bad light userdata pointer")
+ERRDEF(NOGCMM, "bad action while in __gc metamethod")
+#if LJ_TARGET_WINDOWS
+ERRDEF(BADFPU, "bad FPU precision (use D3DCREATE_FPU_PRESERVE with DirectX)")
+#endif
+
+/* Standard library function errors. */
+ERRDEF(ASSERT, "assertion failed!")
+ERRDEF(PROTMT, "cannot change a protected metatable")
+ERRDEF(UNPACK, "too many results to unpack")
+ERRDEF(RDRSTR, "reader function must return a string")
+ERRDEF(PRTOSTR, LUA_QL("tostring") " must return a string to " LUA_QL("print"))
+ERRDEF(IDXRNG, "index out of range")
+ERRDEF(BASERNG, "base out of range")
+ERRDEF(LVLRNG, "level out of range")
+ERRDEF(INVLVL, "invalid level")
+ERRDEF(INVOPT, "invalid option")
+ERRDEF(INVOPTM, "invalid option " LUA_QS)
+ERRDEF(INVFMT, "invalid format")
+ERRDEF(SETFENV, LUA_QL("setfenv") " cannot change environment of given object")
+ERRDEF(CORUN, "cannot resume running coroutine")
+ERRDEF(CODEAD, "cannot resume dead coroutine")
+ERRDEF(COSUSP, "cannot resume non-suspended coroutine")
+ERRDEF(TABINS, "wrong number of arguments to " LUA_QL("insert"))
+ERRDEF(TABCAT, "invalid value (%s) at index %d in table for " LUA_QL("concat"))
+ERRDEF(TABSORT, "invalid order function for sorting")
+ERRDEF(IOCLFL, "attempt to use a closed file")
+ERRDEF(IOSTDCL, "standard file is closed")
+ERRDEF(OSUNIQF, "unable to generate a unique filename")
+ERRDEF(OSDATEF, "field " LUA_QS " missing in date table")
+ERRDEF(STRDUMP, "unable to dump given function")
+ERRDEF(STRSLC, "string slice too long")
+ERRDEF(STRPATB, "missing " LUA_QL("[") " after " LUA_QL("%f") " in pattern")
+ERRDEF(STRPATC, "invalid pattern capture")
+ERRDEF(STRPATE, "malformed pattern (ends with " LUA_QL("%") ")")
+ERRDEF(STRPATM, "malformed pattern (missing " LUA_QL("]") ")")
+ERRDEF(STRPATU, "unbalanced pattern")
+ERRDEF(STRPATX, "pattern too complex")
+ERRDEF(STRCAPI, "invalid capture index")
+ERRDEF(STRCAPN, "too many captures")
+ERRDEF(STRCAPU, "unfinished capture")
+ERRDEF(STRFMTO, "invalid option " LUA_QL("%%%c") " to " LUA_QL("format"))
+ERRDEF(STRFMTR, "invalid format (repeated flags)")
+ERRDEF(STRFMTW, "invalid format (width or precision too long)")
+ERRDEF(STRGSRV, "invalid replacement value (a %s)")
+ERRDEF(BADMODN, "name conflict for module " LUA_QS)
+#if LJ_HASJIT
+ERRDEF(JITPROT, "runtime code generation failed, restricted kernel?")
+#if LJ_TARGET_X86ORX64
+ERRDEF(NOJIT, "JIT compiler disabled, CPU does not support SSE2")
+#else
+ERRDEF(NOJIT, "JIT compiler disabled")
+#endif
+#elif defined(LJ_ARCH_NOJIT)
+ERRDEF(NOJIT, "no JIT compiler for this architecture (yet)")
+#else
+ERRDEF(NOJIT, "JIT compiler permanently disabled by build option")
+#endif
+ERRDEF(JITOPT, "unknown or malformed optimization flag " LUA_QS)
+
+/* Lexer/parser errors. */
+ERRDEF(XMODE, "attempt to load chunk with wrong mode")
+ERRDEF(XNEAR, "%s near " LUA_QS)
+ERRDEF(XELEM, "lexical element too long")
+ERRDEF(XLINES, "chunk has too many lines")
+ERRDEF(XLEVELS, "chunk has too many syntax levels")
+ERRDEF(XNUMBER, "malformed number")
+ERRDEF(XLSTR, "unfinished long string")
+ERRDEF(XLCOM, "unfinished long comment")
+ERRDEF(XSTR, "unfinished string")
+ERRDEF(XESC, "invalid escape sequence")
+ERRDEF(XLDELIM, "invalid long string delimiter")
+ERRDEF(XTOKEN, LUA_QS " expected")
+ERRDEF(XJUMP, "control structure too long")
+ERRDEF(XSLOTS, "function or expression too complex")
+ERRDEF(XLIMC, "chunk has more than %d local variables")
+ERRDEF(XLIMM, "main function has more than %d %s")
+ERRDEF(XLIMF, "function at line %d has more than %d %s")
+ERRDEF(XMATCH, LUA_QS " expected (to close " LUA_QS " at line %d)")
+ERRDEF(XFIXUP, "function too long for return fixup")
+ERRDEF(XPARAM, "<name> or " LUA_QL("...") " expected")
+#if !LJ_52
+ERRDEF(XAMBIG, "ambiguous syntax (function call x new statement)")
+#endif
+ERRDEF(XFUNARG, "function arguments expected")
+ERRDEF(XSYMBOL, "unexpected symbol")
+ERRDEF(XDOTS, "cannot use " LUA_QL("...") " outside a vararg function")
+ERRDEF(XSYNTAX, "syntax error")
+ERRDEF(XFOR, LUA_QL("=") " or " LUA_QL("in") " expected")
+ERRDEF(XBREAK, "no loop to break")
+ERRDEF(XLUNDEF, "undefined label " LUA_QS)
+ERRDEF(XLDUP, "duplicate label " LUA_QS)
+ERRDEF(XGSCOPE, "<goto %s> jumps into the scope of local " LUA_QS)
+
+/* Bytecode reader errors. */
+ERRDEF(BCFMT, "cannot load incompatible bytecode")
+ERRDEF(BCBAD, "cannot load malformed bytecode")
+
+#if LJ_HASFFI
+/* FFI errors. */
+ERRDEF(FFI_INVTYPE, "invalid C type")
+ERRDEF(FFI_INVSIZE, "size of C type is unknown or too large")
+ERRDEF(FFI_BADSCL, "bad storage class")
+ERRDEF(FFI_DECLSPEC, "declaration specifier expected")
+ERRDEF(FFI_BADTAG, "undeclared or implicit tag " LUA_QS)
+ERRDEF(FFI_REDEF, "attempt to redefine " LUA_QS)
+ERRDEF(FFI_NUMPARAM, "wrong number of type parameters")
+ERRDEF(FFI_INITOV, "too many initializers for " LUA_QS)
+ERRDEF(FFI_BADCONV, "cannot convert " LUA_QS " to " LUA_QS)
+ERRDEF(FFI_BADLEN, "attempt to get length of " LUA_QS)
+ERRDEF(FFI_BADCONCAT, "attempt to concatenate " LUA_QS " and " LUA_QS)
+ERRDEF(FFI_BADARITH, "attempt to perform arithmetic on " LUA_QS " and " LUA_QS)
+ERRDEF(FFI_BADCOMP, "attempt to compare " LUA_QS " with " LUA_QS)
+ERRDEF(FFI_BADCALL, LUA_QS " is not callable")
+ERRDEF(FFI_NUMARG, "wrong number of arguments for function call")
+ERRDEF(FFI_BADMEMBER, LUA_QS " has no member named " LUA_QS)
+ERRDEF(FFI_BADIDX, LUA_QS " cannot be indexed")
+ERRDEF(FFI_BADIDXW, LUA_QS " cannot be indexed with " LUA_QS)
+ERRDEF(FFI_BADMM, LUA_QS " has no " LUA_QS " metamethod")
+ERRDEF(FFI_WRCONST, "attempt to write to constant location")
+ERRDEF(FFI_NODECL, "missing declaration for symbol " LUA_QS)
+ERRDEF(FFI_BADCBACK, "bad callback")
+#if LJ_OS_NOJIT
+ERRDEF(FFI_CBACKOV, "no support for callbacks on this OS")
+#else
+ERRDEF(FFI_CBACKOV, "too many callbacks")
+#endif
+ERRDEF(FFI_NYIPACKBIT, "NYI: packed bit fields")
+ERRDEF(FFI_NYICALL, "NYI: cannot call this C function (yet)")
+#endif
+
+#undef ERRDEF
+
+/* Detecting unused error messages:
+ awk -F, '/^ERRDEF/ { gsub(/ERRDEF./, ""); printf "grep -q LJ_ERR_%s *.[ch] || echo %s\n", $1, $1}' lj_errmsg.h | sh
+*/
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ff.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ff.h
new file mode 100644
index 0000000..31d65a0
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ff.h
@@ -0,0 +1,18 @@
+/*
+** Fast function IDs.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_FF_H
+#define _LJ_FF_H
+
+/* Fast function ID. */
+typedef enum {
+ FF_LUA_ = FF_LUA, /* Lua function (must be 0). */
+ FF_C_ = FF_C, /* Regular C function (must be 1). */
+#define FFDEF(name) FF_##name,
+#include "lj_ffdef.h"
+ FF__MAX
+} FastFunc;
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ffrecord.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ffrecord.h
new file mode 100644
index 0000000..3b40745
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ffrecord.h
@@ -0,0 +1,24 @@
+/*
+** Fast function call recorder.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_FFRECORD_H
+#define _LJ_FFRECORD_H
+
+#include "lj_obj.h"
+#include "lj_jit.h"
+
+#if LJ_HASJIT
+/* Data used by handlers to record a fast function. */
+typedef struct RecordFFData {
+ TValue *argv; /* Runtime argument values. */
+ ptrdiff_t nres; /* Number of returned results (defaults to 1). */
+ uint32_t data; /* Per-ffid auxiliary data (opcode, literal etc.). */
+} RecordFFData;
+
+LJ_FUNC int32_t lj_ffrecord_select_mode(jit_State *J, TRef tr, TValue *tv);
+LJ_FUNC void lj_ffrecord_func(jit_State *J);
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_frame.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_frame.h
new file mode 100644
index 0000000..eb5df30
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_frame.h
@@ -0,0 +1,187 @@
+/*
+** Stack frames.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_FRAME_H
+#define _LJ_FRAME_H
+
+#include "lj_obj.h"
+#include "lj_bc.h"
+
+/* -- Lua stack frame ----------------------------------------------------- */
+
+/* Frame type markers in callee function slot (callee base-1). */
+enum {
+ FRAME_LUA, FRAME_C, FRAME_CONT, FRAME_VARG,
+ FRAME_LUAP, FRAME_CP, FRAME_PCALL, FRAME_PCALLH
+};
+#define FRAME_TYPE 3
+#define FRAME_P 4
+#define FRAME_TYPEP (FRAME_TYPE|FRAME_P)
+
+/* Macros to access and modify Lua frames. */
+#define frame_gc(f) (gcref((f)->fr.func))
+#define frame_func(f) (&frame_gc(f)->fn)
+#define frame_ftsz(f) ((f)->fr.tp.ftsz)
+
+#define frame_type(f) (frame_ftsz(f) & FRAME_TYPE)
+#define frame_typep(f) (frame_ftsz(f) & FRAME_TYPEP)
+#define frame_islua(f) (frame_type(f) == FRAME_LUA)
+#define frame_isc(f) (frame_type(f) == FRAME_C)
+#define frame_iscont(f) (frame_typep(f) == FRAME_CONT)
+#define frame_isvarg(f) (frame_typep(f) == FRAME_VARG)
+#define frame_ispcall(f) ((frame_ftsz(f) & 6) == FRAME_PCALL)
+
+#define frame_pc(f) (mref((f)->fr.tp.pcr, const BCIns))
+#define frame_contpc(f) (frame_pc((f)-1))
+#if LJ_64
+#define frame_contf(f) \
+ ((ASMFunction)(void *)((intptr_t)lj_vm_asm_begin + \
+ (intptr_t)(int32_t)((f)-1)->u32.lo))
+#else
+#define frame_contf(f) ((ASMFunction)gcrefp(((f)-1)->gcr, void))
+#endif
+#define frame_delta(f) (frame_ftsz(f) >> 3)
+#define frame_sized(f) (frame_ftsz(f) & ~FRAME_TYPEP)
+
+#define frame_prevl(f) ((f) - (1+bc_a(frame_pc(f)[-1])))
+#define frame_prevd(f) ((TValue *)((char *)(f) - frame_sized(f)))
+#define frame_prev(f) (frame_islua(f)?frame_prevl(f):frame_prevd(f))
+/* Note: this macro does not skip over FRAME_VARG. */
+
+#define setframe_pc(f, pc) (setmref((f)->fr.tp.pcr, (pc)))
+#define setframe_ftsz(f, sz) ((f)->fr.tp.ftsz = (sz))
+#define setframe_gc(f, p) (setgcref((f)->fr.func, (p)))
+
+/* -- C stack frame ------------------------------------------------------- */
+
+/* Macros to access and modify the C stack frame chain. */
+
+/* These definitions must match with the arch-specific *.dasc files. */
+#if LJ_TARGET_X86
+#define CFRAME_OFS_ERRF (15*4)
+#define CFRAME_OFS_NRES (14*4)
+#define CFRAME_OFS_PREV (13*4)
+#define CFRAME_OFS_L (12*4)
+#define CFRAME_OFS_PC (6*4)
+#define CFRAME_OFS_MULTRES (5*4)
+#define CFRAME_SIZE (12*4)
+#define CFRAME_SHIFT_MULTRES 0
+#elif LJ_TARGET_X64
+#if LJ_ABI_WIN
+#define CFRAME_OFS_PREV (13*8)
+#define CFRAME_OFS_PC (25*4)
+#define CFRAME_OFS_L (24*4)
+#define CFRAME_OFS_ERRF (23*4)
+#define CFRAME_OFS_NRES (22*4)
+#define CFRAME_OFS_MULTRES (21*4)
+#define CFRAME_SIZE (10*8)
+#define CFRAME_SIZE_JIT (CFRAME_SIZE + 9*16 + 4*8)
+#define CFRAME_SHIFT_MULTRES 0
+#else
+#define CFRAME_OFS_PREV (4*8)
+#define CFRAME_OFS_PC (7*4)
+#define CFRAME_OFS_L (6*4)
+#define CFRAME_OFS_ERRF (5*4)
+#define CFRAME_OFS_NRES (4*4)
+#define CFRAME_OFS_MULTRES (1*4)
+#if LJ_NO_UNWIND
+#define CFRAME_SIZE (12*8)
+#else
+#define CFRAME_SIZE (10*8)
+#endif
+#define CFRAME_SIZE_JIT (CFRAME_SIZE + 16)
+#define CFRAME_SHIFT_MULTRES 0
+#endif
+#elif LJ_TARGET_ARM
+#define CFRAME_OFS_ERRF 24
+#define CFRAME_OFS_NRES 20
+#define CFRAME_OFS_PREV 16
+#define CFRAME_OFS_L 12
+#define CFRAME_OFS_PC 8
+#define CFRAME_OFS_MULTRES 4
+#if LJ_ARCH_HASFPU
+#define CFRAME_SIZE 128
+#else
+#define CFRAME_SIZE 64
+#endif
+#define CFRAME_SHIFT_MULTRES 3
+#elif LJ_TARGET_PPC
+#if LJ_TARGET_XBOX360
+#define CFRAME_OFS_ERRF 424
+#define CFRAME_OFS_NRES 420
+#define CFRAME_OFS_PREV 400
+#define CFRAME_OFS_L 416
+#define CFRAME_OFS_PC 412
+#define CFRAME_OFS_MULTRES 408
+#define CFRAME_SIZE 384
+#define CFRAME_SHIFT_MULTRES 3
+#elif LJ_ARCH_PPC64
+#define CFRAME_OFS_ERRF 472
+#define CFRAME_OFS_NRES 468
+#define CFRAME_OFS_PREV 448
+#define CFRAME_OFS_L 464
+#define CFRAME_OFS_PC 460
+#define CFRAME_OFS_MULTRES 456
+#define CFRAME_SIZE 400
+#define CFRAME_SHIFT_MULTRES 3
+#else
+#define CFRAME_OFS_ERRF 48
+#define CFRAME_OFS_NRES 44
+#define CFRAME_OFS_PREV 40
+#define CFRAME_OFS_L 36
+#define CFRAME_OFS_PC 32
+#define CFRAME_OFS_MULTRES 28
+#define CFRAME_SIZE 272
+#define CFRAME_SHIFT_MULTRES 3
+#endif
+#elif LJ_TARGET_PPCSPE
+#define CFRAME_OFS_ERRF 28
+#define CFRAME_OFS_NRES 24
+#define CFRAME_OFS_PREV 20
+#define CFRAME_OFS_L 16
+#define CFRAME_OFS_PC 12
+#define CFRAME_OFS_MULTRES 8
+#define CFRAME_SIZE 184
+#define CFRAME_SHIFT_MULTRES 3
+#elif LJ_TARGET_MIPS
+#define CFRAME_OFS_ERRF 124
+#define CFRAME_OFS_NRES 120
+#define CFRAME_OFS_PREV 116
+#define CFRAME_OFS_L 112
+#define CFRAME_OFS_PC 20
+#define CFRAME_OFS_MULTRES 16
+#define CFRAME_SIZE 112
+#define CFRAME_SHIFT_MULTRES 3
+#else
+#error "Missing CFRAME_* definitions for this architecture"
+#endif
+
+#ifndef CFRAME_SIZE_JIT
+#define CFRAME_SIZE_JIT CFRAME_SIZE
+#endif
+
+#define CFRAME_RESUME 1
+#define CFRAME_UNWIND_FF 2 /* Only used in unwinder. */
+#define CFRAME_RAWMASK (~(intptr_t)(CFRAME_RESUME|CFRAME_UNWIND_FF))
+
+#define cframe_errfunc(cf) (*(int32_t *)(((char *)(cf))+CFRAME_OFS_ERRF))
+#define cframe_nres(cf) (*(int32_t *)(((char *)(cf))+CFRAME_OFS_NRES))
+#define cframe_prev(cf) (*(void **)(((char *)(cf))+CFRAME_OFS_PREV))
+#define cframe_multres(cf) (*(uint32_t *)(((char *)(cf))+CFRAME_OFS_MULTRES))
+#define cframe_multres_n(cf) (cframe_multres((cf)) >> CFRAME_SHIFT_MULTRES)
+#define cframe_L(cf) \
+ (&gcref(*(GCRef *)(((char *)(cf))+CFRAME_OFS_L))->th)
+#define cframe_pc(cf) \
+ (mref(*(MRef *)(((char *)(cf))+CFRAME_OFS_PC), const BCIns))
+#define setcframe_L(cf, L) \
+ (setmref(*(MRef *)(((char *)(cf))+CFRAME_OFS_L), (L)))
+#define setcframe_pc(cf, pc) \
+ (setmref(*(MRef *)(((char *)(cf))+CFRAME_OFS_PC), (pc)))
+#define cframe_canyield(cf) ((intptr_t)(cf) & CFRAME_RESUME)
+#define cframe_unwind_ff(cf) ((intptr_t)(cf) & CFRAME_UNWIND_FF)
+#define cframe_raw(cf) ((void *)((intptr_t)(cf) & CFRAME_RAWMASK))
+#define cframe_Lpc(L) cframe_pc(cframe_raw(L->cframe))
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_func.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_func.h
new file mode 100644
index 0000000..901751b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_func.h
@@ -0,0 +1,24 @@
+/*
+** Function handling (prototypes, functions and upvalues).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_FUNC_H
+#define _LJ_FUNC_H
+
+#include "lj_obj.h"
+
+/* Prototypes. */
+LJ_FUNC void LJ_FASTCALL lj_func_freeproto(global_State *g, GCproto *pt);
+
+/* Upvalues. */
+LJ_FUNCA void LJ_FASTCALL lj_func_closeuv(lua_State *L, TValue *level);
+LJ_FUNC void LJ_FASTCALL lj_func_freeuv(global_State *g, GCupval *uv);
+
+/* Functions (closures). */
+LJ_FUNC GCfunc *lj_func_newC(lua_State *L, MSize nelems, GCtab *env);
+LJ_FUNC GCfunc *lj_func_newL_empty(lua_State *L, GCproto *pt, GCtab *env);
+LJ_FUNCA GCfunc *lj_func_newL_gc(lua_State *L, GCproto *pt, GCfuncL *parent);
+LJ_FUNC void LJ_FASTCALL lj_func_free(global_State *g, GCfunc *c);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_gc.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_gc.h
new file mode 100644
index 0000000..57ac714
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_gc.h
@@ -0,0 +1,134 @@
+/*
+** Garbage collector.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_GC_H
+#define _LJ_GC_H
+
+#include "lj_obj.h"
+
+/* Garbage collector states. Order matters. */
+enum {
+ GCSpause, GCSpropagate, GCSatomic, GCSsweepstring, GCSsweep, GCSfinalize
+};
+
+/* Bitmasks for marked field of GCobj. */
+#define LJ_GC_WHITE0 0x01
+#define LJ_GC_WHITE1 0x02
+#define LJ_GC_BLACK 0x04
+#define LJ_GC_FINALIZED 0x08
+#define LJ_GC_WEAKKEY 0x08
+#define LJ_GC_WEAKVAL 0x10
+#define LJ_GC_CDATA_FIN 0x10
+#define LJ_GC_FIXED 0x20
+#define LJ_GC_SFIXED 0x40
+
+#define LJ_GC_WHITES (LJ_GC_WHITE0 | LJ_GC_WHITE1)
+#define LJ_GC_COLORS (LJ_GC_WHITES | LJ_GC_BLACK)
+#define LJ_GC_WEAK (LJ_GC_WEAKKEY | LJ_GC_WEAKVAL)
+
+/* Macros to test and set GCobj colors. */
+#define iswhite(x) ((x)->gch.marked & LJ_GC_WHITES)
+#define isblack(x) ((x)->gch.marked & LJ_GC_BLACK)
+#define isgray(x) (!((x)->gch.marked & (LJ_GC_BLACK|LJ_GC_WHITES)))
+#define tviswhite(x) (tvisgcv(x) && iswhite(gcV(x)))
+#define otherwhite(g) (g->gc.currentwhite ^ LJ_GC_WHITES)
+#define isdead(g, v) ((v)->gch.marked & otherwhite(g) & LJ_GC_WHITES)
+
+#define curwhite(g) ((g)->gc.currentwhite & LJ_GC_WHITES)
+#define newwhite(g, x) (obj2gco(x)->gch.marked = (uint8_t)curwhite(g))
+#define makewhite(g, x) \
+ ((x)->gch.marked = ((x)->gch.marked & (uint8_t)~LJ_GC_COLORS) | curwhite(g))
+#define flipwhite(x) ((x)->gch.marked ^= LJ_GC_WHITES)
+#define black2gray(x) ((x)->gch.marked &= (uint8_t)~LJ_GC_BLACK)
+#define fixstring(s) ((s)->marked |= LJ_GC_FIXED)
+#define markfinalized(x) ((x)->gch.marked |= LJ_GC_FINALIZED)
+
+/* Collector. */
+LJ_FUNC size_t lj_gc_separateudata(global_State *g, int all);
+LJ_FUNC void lj_gc_finalize_udata(lua_State *L);
+#if LJ_HASFFI
+LJ_FUNC void lj_gc_finalize_cdata(lua_State *L);
+#else
+#define lj_gc_finalize_cdata(L) UNUSED(L)
+#endif
+LJ_FUNC void lj_gc_freeall(global_State *g);
+LJ_FUNCA int LJ_FASTCALL lj_gc_step(lua_State *L);
+LJ_FUNCA void LJ_FASTCALL lj_gc_step_fixtop(lua_State *L);
+#if LJ_HASJIT
+LJ_FUNC int LJ_FASTCALL lj_gc_step_jit(global_State *g, MSize steps);
+#endif
+LJ_FUNC void lj_gc_fullgc(lua_State *L);
+
+/* GC check: drive collector forward if the GC threshold has been reached. */
+#define lj_gc_check(L) \
+ { if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) \
+ lj_gc_step(L); }
+#define lj_gc_check_fixtop(L) \
+ { if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) \
+ lj_gc_step_fixtop(L); }
+
+/* Write barriers. */
+LJ_FUNC void lj_gc_barrierf(global_State *g, GCobj *o, GCobj *v);
+LJ_FUNCA void LJ_FASTCALL lj_gc_barrieruv(global_State *g, TValue *tv);
+LJ_FUNC void lj_gc_closeuv(global_State *g, GCupval *uv);
+#if LJ_HASJIT
+LJ_FUNC void lj_gc_barriertrace(global_State *g, uint32_t traceno);
+#endif
+
+/* Move the GC propagation frontier back for tables (make it gray again). */
+static LJ_AINLINE void lj_gc_barrierback(global_State *g, GCtab *t)
+{
+ GCobj *o = obj2gco(t);
+ lua_assert(isblack(o) && !isdead(g, o));
+ lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause);
+ black2gray(o);
+ setgcrefr(t->gclist, g->gc.grayagain);
+ setgcref(g->gc.grayagain, o);
+}
+
+/* Barrier for stores to table objects. TValue and GCobj variant. */
+#define lj_gc_anybarriert(L, t) \
+ { if (LJ_UNLIKELY(isblack(obj2gco(t)))) lj_gc_barrierback(G(L), (t)); }
+#define lj_gc_barriert(L, t, tv) \
+ { if (tviswhite(tv) && isblack(obj2gco(t))) \
+ lj_gc_barrierback(G(L), (t)); }
+#define lj_gc_objbarriert(L, t, o) \
+ { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) \
+ lj_gc_barrierback(G(L), (t)); }
+
+/* Barrier for stores to any other object. TValue and GCobj variant. */
+#define lj_gc_barrier(L, p, tv) \
+ { if (tviswhite(tv) && isblack(obj2gco(p))) \
+ lj_gc_barrierf(G(L), obj2gco(p), gcV(tv)); }
+#define lj_gc_objbarrier(L, p, o) \
+ { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
+ lj_gc_barrierf(G(L), obj2gco(p), obj2gco(o)); }
+
+/* Allocator. */
+LJ_FUNC void *lj_mem_realloc(lua_State *L, void *p, MSize osz, MSize nsz);
+LJ_FUNC void * LJ_FASTCALL lj_mem_newgco(lua_State *L, MSize size);
+LJ_FUNC void *lj_mem_grow(lua_State *L, void *p,
+ MSize *szp, MSize lim, MSize esz);
+
+#define lj_mem_new(L, s) lj_mem_realloc(L, NULL, 0, (s))
+
+static LJ_AINLINE void lj_mem_free(global_State *g, void *p, size_t osize)
+{
+ g->gc.total -= (MSize)osize;
+ g->allocf(g->allocd, p, osize, 0);
+}
+
+#define lj_mem_newvec(L, n, t) ((t *)lj_mem_new(L, (MSize)((n)*sizeof(t))))
+#define lj_mem_reallocvec(L, p, on, n, t) \
+ ((p) = (t *)lj_mem_realloc(L, p, (on)*sizeof(t), (MSize)((n)*sizeof(t))))
+#define lj_mem_growvec(L, p, n, m, t) \
+ ((p) = (t *)lj_mem_grow(L, (p), &(n), (m), (MSize)sizeof(t)))
+#define lj_mem_freevec(g, p, n, t) lj_mem_free(g, (p), (n)*sizeof(t))
+
+#define lj_mem_newobj(L, t) ((t *)lj_mem_newgco(L, sizeof(t)))
+#define lj_mem_newt(L, s, t) ((t *)lj_mem_new(L, (s)))
+#define lj_mem_freet(g, p) lj_mem_free(g, (p), sizeof(*(p)))
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_gdbjit.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_gdbjit.h
new file mode 100644
index 0000000..bbaa156
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_gdbjit.h
@@ -0,0 +1,22 @@
+/*
+** Client for the GDB JIT API.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_GDBJIT_H
+#define _LJ_GDBJIT_H
+
+#include "lj_obj.h"
+#include "lj_jit.h"
+
+#if LJ_HASJIT && defined(LUAJIT_USE_GDBJIT)
+
+LJ_FUNC void lj_gdbjit_addtrace(jit_State *J, GCtrace *T);
+LJ_FUNC void lj_gdbjit_deltrace(jit_State *J, GCtrace *T);
+
+#else
+#define lj_gdbjit_addtrace(J, T) UNUSED(T)
+#define lj_gdbjit_deltrace(J, T) UNUSED(T)
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ir.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ir.h
new file mode 100644
index 0000000..ded3e0e
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ir.h
@@ -0,0 +1,551 @@
+/*
+** SSA IR (Intermediate Representation) format.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_IR_H
+#define _LJ_IR_H
+
+#include "lj_obj.h"
+
+/* -- IR instructions ----------------------------------------------------- */
+
+/* IR instruction definition. Order matters, see below. ORDER IR */
+#define IRDEF(_) \
+ /* Guarded assertions. */ \
+ /* Must be properly aligned to flip opposites (^1) and (un)ordered (^4). */ \
+ _(LT, N , ref, ref) \
+ _(GE, N , ref, ref) \
+ _(LE, N , ref, ref) \
+ _(GT, N , ref, ref) \
+ \
+ _(ULT, N , ref, ref) \
+ _(UGE, N , ref, ref) \
+ _(ULE, N , ref, ref) \
+ _(UGT, N , ref, ref) \
+ \
+ _(EQ, C , ref, ref) \
+ _(NE, C , ref, ref) \
+ \
+ _(ABC, N , ref, ref) \
+ _(RETF, S , ref, ref) \
+ \
+ /* Miscellaneous ops. */ \
+ _(NOP, N , ___, ___) \
+ _(BASE, N , lit, lit) \
+ _(PVAL, N , lit, ___) \
+ _(GCSTEP, S , ___, ___) \
+ _(HIOP, S , ref, ref) \
+ _(LOOP, S , ___, ___) \
+ _(USE, S , ref, ___) \
+ _(PHI, S , ref, ref) \
+ _(RENAME, S , ref, lit) \
+ \
+ /* Constants. */ \
+ _(KPRI, N , ___, ___) \
+ _(KINT, N , cst, ___) \
+ _(KGC, N , cst, ___) \
+ _(KPTR, N , cst, ___) \
+ _(KKPTR, N , cst, ___) \
+ _(KNULL, N , cst, ___) \
+ _(KNUM, N , cst, ___) \
+ _(KINT64, N , cst, ___) \
+ _(KSLOT, N , ref, lit) \
+ \
+ /* Bit ops. */ \
+ _(BNOT, N , ref, ___) \
+ _(BSWAP, N , ref, ___) \
+ _(BAND, C , ref, ref) \
+ _(BOR, C , ref, ref) \
+ _(BXOR, C , ref, ref) \
+ _(BSHL, N , ref, ref) \
+ _(BSHR, N , ref, ref) \
+ _(BSAR, N , ref, ref) \
+ _(BROL, N , ref, ref) \
+ _(BROR, N , ref, ref) \
+ \
+ /* Arithmetic ops. ORDER ARITH */ \
+ _(ADD, C , ref, ref) \
+ _(SUB, N , ref, ref) \
+ _(MUL, C , ref, ref) \
+ _(DIV, N , ref, ref) \
+ _(MOD, N , ref, ref) \
+ _(POW, N , ref, ref) \
+ _(NEG, N , ref, ref) \
+ \
+ _(ABS, N , ref, ref) \
+ _(ATAN2, N , ref, ref) \
+ _(LDEXP, N , ref, ref) \
+ _(MIN, C , ref, ref) \
+ _(MAX, C , ref, ref) \
+ _(FPMATH, N , ref, lit) \
+ \
+ /* Overflow-checking arithmetic ops. */ \
+ _(ADDOV, CW, ref, ref) \
+ _(SUBOV, NW, ref, ref) \
+ _(MULOV, CW, ref, ref) \
+ \
+ /* Memory ops. A = array, H = hash, U = upvalue, F = field, S = stack. */ \
+ \
+ /* Memory references. */ \
+ _(AREF, R , ref, ref) \
+ _(HREFK, R , ref, ref) \
+ _(HREF, L , ref, ref) \
+ _(NEWREF, S , ref, ref) \
+ _(UREFO, LW, ref, lit) \
+ _(UREFC, LW, ref, lit) \
+ _(FREF, R , ref, lit) \
+ _(STRREF, N , ref, ref) \
+ \
+ /* Loads and Stores. These must be in the same order. */ \
+ _(ALOAD, L , ref, ___) \
+ _(HLOAD, L , ref, ___) \
+ _(ULOAD, L , ref, ___) \
+ _(FLOAD, L , ref, lit) \
+ _(XLOAD, L , ref, lit) \
+ _(SLOAD, L , lit, lit) \
+ _(VLOAD, L , ref, ___) \
+ \
+ _(ASTORE, S , ref, ref) \
+ _(HSTORE, S , ref, ref) \
+ _(USTORE, S , ref, ref) \
+ _(FSTORE, S , ref, ref) \
+ _(XSTORE, S , ref, ref) \
+ \
+ /* Allocations. */ \
+ _(SNEW, N , ref, ref) /* CSE is ok, not marked as A. */ \
+ _(XSNEW, A , ref, ref) \
+ _(TNEW, AW, lit, lit) \
+ _(TDUP, AW, ref, ___) \
+ _(CNEW, AW, ref, ref) \
+ _(CNEWI, NW, ref, ref) /* CSE is ok, not marked as A. */ \
+ \
+ /* Barriers. */ \
+ _(TBAR, S , ref, ___) \
+ _(OBAR, S , ref, ref) \
+ _(XBAR, S , ___, ___) \
+ \
+ /* Type conversions. */ \
+ _(CONV, NW, ref, lit) \
+ _(TOBIT, N , ref, ref) \
+ _(TOSTR, N , ref, ___) \
+ _(STRTO, N , ref, ___) \
+ \
+ /* Calls. */ \
+ _(CALLN, N , ref, lit) \
+ _(CALLL, L , ref, lit) \
+ _(CALLS, S , ref, lit) \
+ _(CALLXS, S , ref, ref) \
+ _(CARG, N , ref, ref) \
+ \
+ /* End of list. */
+
+/* IR opcodes (max. 256). */
+typedef enum {
+#define IRENUM(name, m, m1, m2) IR_##name,
+IRDEF(IRENUM)
+#undef IRENUM
+ IR__MAX
+} IROp;
+
+/* Stored opcode. */
+typedef uint8_t IROp1;
+
+LJ_STATIC_ASSERT(((int)IR_EQ^1) == (int)IR_NE);
+LJ_STATIC_ASSERT(((int)IR_LT^1) == (int)IR_GE);
+LJ_STATIC_ASSERT(((int)IR_LE^1) == (int)IR_GT);
+LJ_STATIC_ASSERT(((int)IR_LT^3) == (int)IR_GT);
+LJ_STATIC_ASSERT(((int)IR_LT^4) == (int)IR_ULT);
+
+/* Delta between xLOAD and xSTORE. */
+#define IRDELTA_L2S ((int)IR_ASTORE - (int)IR_ALOAD)
+
+LJ_STATIC_ASSERT((int)IR_HLOAD + IRDELTA_L2S == (int)IR_HSTORE);
+LJ_STATIC_ASSERT((int)IR_ULOAD + IRDELTA_L2S == (int)IR_USTORE);
+LJ_STATIC_ASSERT((int)IR_FLOAD + IRDELTA_L2S == (int)IR_FSTORE);
+LJ_STATIC_ASSERT((int)IR_XLOAD + IRDELTA_L2S == (int)IR_XSTORE);
+
+/* -- Named IR literals --------------------------------------------------- */
+
+/* FPMATH sub-functions. ORDER FPM. */
+#define IRFPMDEF(_) \
+ _(FLOOR) _(CEIL) _(TRUNC) /* Must be first and in this order. */ \
+ _(SQRT) _(EXP) _(EXP2) _(LOG) _(LOG2) _(LOG10) \
+ _(SIN) _(COS) _(TAN) \
+ _(OTHER)
+
+typedef enum {
+#define FPMENUM(name) IRFPM_##name,
+IRFPMDEF(FPMENUM)
+#undef FPMENUM
+ IRFPM__MAX
+} IRFPMathOp;
+
+/* FLOAD fields. */
+#define IRFLDEF(_) \
+ _(STR_LEN, offsetof(GCstr, len)) \
+ _(FUNC_ENV, offsetof(GCfunc, l.env)) \
+ _(FUNC_PC, offsetof(GCfunc, l.pc)) \
+ _(TAB_META, offsetof(GCtab, metatable)) \
+ _(TAB_ARRAY, offsetof(GCtab, array)) \
+ _(TAB_NODE, offsetof(GCtab, node)) \
+ _(TAB_ASIZE, offsetof(GCtab, asize)) \
+ _(TAB_HMASK, offsetof(GCtab, hmask)) \
+ _(TAB_NOMM, offsetof(GCtab, nomm)) \
+ _(UDATA_META, offsetof(GCudata, metatable)) \
+ _(UDATA_UDTYPE, offsetof(GCudata, udtype)) \
+ _(UDATA_FILE, sizeof(GCudata)) \
+ _(CDATA_CTYPEID, offsetof(GCcdata, ctypeid)) \
+ _(CDATA_PTR, sizeof(GCcdata)) \
+ _(CDATA_INT, sizeof(GCcdata)) \
+ _(CDATA_INT64, sizeof(GCcdata)) \
+ _(CDATA_INT64_4, sizeof(GCcdata) + 4)
+
+typedef enum {
+#define FLENUM(name, ofs) IRFL_##name,
+IRFLDEF(FLENUM)
+#undef FLENUM
+ IRFL__MAX
+} IRFieldID;
+
+/* SLOAD mode bits, stored in op2. */
+#define IRSLOAD_PARENT 0x01 /* Coalesce with parent trace. */
+#define IRSLOAD_FRAME 0x02 /* Load hiword of frame. */
+#define IRSLOAD_TYPECHECK 0x04 /* Needs type check. */
+#define IRSLOAD_CONVERT 0x08 /* Number to integer conversion. */
+#define IRSLOAD_READONLY 0x10 /* Read-only, omit slot store. */
+#define IRSLOAD_INHERIT 0x20 /* Inherited by exits/side traces. */
+
+/* XLOAD mode, stored in op2. */
+#define IRXLOAD_READONLY 1 /* Load from read-only data. */
+#define IRXLOAD_VOLATILE 2 /* Load from volatile data. */
+#define IRXLOAD_UNALIGNED 4 /* Unaligned load. */
+
+/* CONV mode, stored in op2. */
+#define IRCONV_SRCMASK 0x001f /* Source IRType. */
+#define IRCONV_DSTMASK 0x03e0 /* Dest. IRType (also in ir->t). */
+#define IRCONV_DSH 5
+#define IRCONV_NUM_INT ((IRT_NUM<<IRCONV_DSH)|IRT_INT)
+#define IRCONV_INT_NUM ((IRT_INT<<IRCONV_DSH)|IRT_NUM)
+#define IRCONV_TRUNC 0x0400 /* Truncate number to integer. */
+#define IRCONV_SEXT 0x0800 /* Sign-extend integer to integer. */
+#define IRCONV_MODEMASK 0x0fff
+#define IRCONV_CONVMASK 0xf000
+#define IRCONV_CSH 12
+/* Number to integer conversion mode. Ordered by strength of the checks. */
+#define IRCONV_TOBIT (0<<IRCONV_CSH) /* None. Cache only: TOBIT conv. */
+#define IRCONV_ANY (1<<IRCONV_CSH) /* Any FP number is ok. */
+#define IRCONV_INDEX (2<<IRCONV_CSH) /* Check + special backprop rules. */
+#define IRCONV_CHECK (3<<IRCONV_CSH) /* Number checked for integerness. */
+
+/* -- IR operands --------------------------------------------------------- */
+
+/* IR operand mode (2 bit). */
+typedef enum {
+ IRMref, /* IR reference. */
+ IRMlit, /* 16 bit unsigned literal. */
+ IRMcst, /* Constant literal: i, gcr or ptr. */
+ IRMnone /* Unused operand. */
+} IRMode;
+#define IRM___ IRMnone
+
+/* Mode bits: Commutative, {Normal/Ref, Alloc, Load, Store}, Non-weak guard. */
+#define IRM_C 0x10
+
+#define IRM_N 0x00
+#define IRM_R IRM_N
+#define IRM_A 0x20
+#define IRM_L 0x40
+#define IRM_S 0x60
+
+#define IRM_W 0x80
+
+#define IRM_NW (IRM_N|IRM_W)
+#define IRM_CW (IRM_C|IRM_W)
+#define IRM_AW (IRM_A|IRM_W)
+#define IRM_LW (IRM_L|IRM_W)
+
+#define irm_op1(m) ((IRMode)((m)&3))
+#define irm_op2(m) ((IRMode)(((m)>>2)&3))
+#define irm_iscomm(m) ((m) & IRM_C)
+#define irm_kind(m) ((m) & IRM_S)
+
+#define IRMODE(name, m, m1, m2) (((IRM##m1)|((IRM##m2)<<2)|(IRM_##m))^IRM_W),
+
+LJ_DATA const uint8_t lj_ir_mode[IR__MAX+1];
+
+/* -- IR instruction types ------------------------------------------------ */
+
+/* Map of itypes to non-negative numbers. ORDER LJ_T.
+** LJ_TUPVAL/LJ_TTRACE never appear in a TValue. Use these itypes for
+** IRT_P32 and IRT_P64, which never escape the IR.
+** The various integers are only used in the IR and can only escape to
+** a TValue after implicit or explicit conversion. Their types must be
+** contiguous and next to IRT_NUM (see the typerange macros below).
+*/
+#define IRTDEF(_) \
+ _(NIL, 4) _(FALSE, 4) _(TRUE, 4) _(LIGHTUD, LJ_64 ? 8 : 4) _(STR, 4) \
+ _(P32, 4) _(THREAD, 4) _(PROTO, 4) _(FUNC, 4) _(P64, 8) _(CDATA, 4) \
+ _(TAB, 4) _(UDATA, 4) \
+ _(FLOAT, 4) _(NUM, 8) _(I8, 1) _(U8, 1) _(I16, 2) _(U16, 2) \
+ _(INT, 4) _(U32, 4) _(I64, 8) _(U64, 8) \
+ _(SOFTFP, 4) /* There is room for 9 more types. */
+
+/* IR result type and flags (8 bit). */
+typedef enum {
+#define IRTENUM(name, size) IRT_##name,
+IRTDEF(IRTENUM)
+#undef IRTENUM
+ IRT__MAX,
+
+ /* Native pointer type and the corresponding integer type. */
+ IRT_PTR = LJ_64 ? IRT_P64 : IRT_P32,
+ IRT_INTP = LJ_64 ? IRT_I64 : IRT_INT,
+ IRT_UINTP = LJ_64 ? IRT_U64 : IRT_U32,
+
+ /* Additional flags. */
+ IRT_MARK = 0x20, /* Marker for misc. purposes. */
+ IRT_ISPHI = 0x40, /* Instruction is left or right PHI operand. */
+ IRT_GUARD = 0x80, /* Instruction is a guard. */
+
+ /* Masks. */
+ IRT_TYPE = 0x1f,
+ IRT_T = 0xff
+} IRType;
+
+#define irtype_ispri(irt) ((uint32_t)(irt) <= IRT_TRUE)
+
+/* Stored IRType. */
+typedef struct IRType1 { uint8_t irt; } IRType1;
+
+#define IRT(o, t) ((uint32_t)(((o)<<8) | (t)))
+#define IRTI(o) (IRT((o), IRT_INT))
+#define IRTN(o) (IRT((o), IRT_NUM))
+#define IRTG(o, t) (IRT((o), IRT_GUARD|(t)))
+#define IRTGI(o) (IRT((o), IRT_GUARD|IRT_INT))
+
+#define irt_t(t) ((IRType)(t).irt)
+#define irt_type(t) ((IRType)((t).irt & IRT_TYPE))
+#define irt_sametype(t1, t2) ((((t1).irt ^ (t2).irt) & IRT_TYPE) == 0)
+#define irt_typerange(t, first, last) \
+ ((uint32_t)((t).irt & IRT_TYPE) - (uint32_t)(first) <= (uint32_t)(last-first))
+
+#define irt_isnil(t) (irt_type(t) == IRT_NIL)
+#define irt_ispri(t) ((uint32_t)irt_type(t) <= IRT_TRUE)
+#define irt_islightud(t) (irt_type(t) == IRT_LIGHTUD)
+#define irt_isstr(t) (irt_type(t) == IRT_STR)
+#define irt_istab(t) (irt_type(t) == IRT_TAB)
+#define irt_iscdata(t) (irt_type(t) == IRT_CDATA)
+#define irt_isfloat(t) (irt_type(t) == IRT_FLOAT)
+#define irt_isnum(t) (irt_type(t) == IRT_NUM)
+#define irt_isint(t) (irt_type(t) == IRT_INT)
+#define irt_isi8(t) (irt_type(t) == IRT_I8)
+#define irt_isu8(t) (irt_type(t) == IRT_U8)
+#define irt_isi16(t) (irt_type(t) == IRT_I16)
+#define irt_isu16(t) (irt_type(t) == IRT_U16)
+#define irt_isu32(t) (irt_type(t) == IRT_U32)
+#define irt_isi64(t) (irt_type(t) == IRT_I64)
+#define irt_isu64(t) (irt_type(t) == IRT_U64)
+
+#define irt_isfp(t) (irt_isnum(t) || irt_isfloat(t))
+#define irt_isinteger(t) (irt_typerange((t), IRT_I8, IRT_INT))
+#define irt_isgcv(t) (irt_typerange((t), IRT_STR, IRT_UDATA))
+#define irt_isaddr(t) (irt_typerange((t), IRT_LIGHTUD, IRT_UDATA))
+#define irt_isint64(t) (irt_typerange((t), IRT_I64, IRT_U64))
+
+#if LJ_64
+#define IRT_IS64 \
+ ((1u<<IRT_NUM)|(1u<<IRT_I64)|(1u<<IRT_U64)|(1u<<IRT_P64)|(1u<<IRT_LIGHTUD))
+#else
+#define IRT_IS64 \
+ ((1u<<IRT_NUM)|(1u<<IRT_I64)|(1u<<IRT_U64))
+#endif
+
+#define irt_is64(t) ((IRT_IS64 >> irt_type(t)) & 1)
+#define irt_is64orfp(t) (((IRT_IS64|(1u<<IRT_FLOAT))>>irt_type(t)) & 1)
+
+#define irt_size(t) (lj_ir_type_size[irt_t((t))])
+
+LJ_DATA const uint8_t lj_ir_type_size[];
+
+static LJ_AINLINE IRType itype2irt(const TValue *tv)
+{
+ if (tvisint(tv))
+ return IRT_INT;
+ else if (tvisnum(tv))
+ return IRT_NUM;
+#if LJ_64
+ else if (tvislightud(tv))
+ return IRT_LIGHTUD;
+#endif
+ else
+ return (IRType)~itype(tv);
+}
+
+static LJ_AINLINE uint32_t irt_toitype_(IRType t)
+{
+ lua_assert(!LJ_64 || t != IRT_LIGHTUD);
+ if (LJ_DUALNUM && t > IRT_NUM) {
+ return LJ_TISNUM;
+ } else {
+ lua_assert(t <= IRT_NUM);
+ return ~(uint32_t)t;
+ }
+}
+
+#define irt_toitype(t) irt_toitype_(irt_type((t)))
+
+#define irt_isguard(t) ((t).irt & IRT_GUARD)
+#define irt_ismarked(t) ((t).irt & IRT_MARK)
+#define irt_setmark(t) ((t).irt |= IRT_MARK)
+#define irt_clearmark(t) ((t).irt &= ~IRT_MARK)
+#define irt_isphi(t) ((t).irt & IRT_ISPHI)
+#define irt_setphi(t) ((t).irt |= IRT_ISPHI)
+#define irt_clearphi(t) ((t).irt &= ~IRT_ISPHI)
+
+/* Stored combined IR opcode and type. */
+typedef uint16_t IROpT;
+
+/* -- IR references ------------------------------------------------------- */
+
+/* IR references. */
+typedef uint16_t IRRef1; /* One stored reference. */
+typedef uint32_t IRRef2; /* Two stored references. */
+typedef uint32_t IRRef; /* Used to pass around references. */
+
+/* Fixed references. */
+enum {
+ REF_BIAS = 0x8000,
+ REF_TRUE = REF_BIAS-3,
+ REF_FALSE = REF_BIAS-2,
+ REF_NIL = REF_BIAS-1, /* \--- Constants grow downwards. */
+ REF_BASE = REF_BIAS, /* /--- IR grows upwards. */
+ REF_FIRST = REF_BIAS+1,
+ REF_DROP = 0xffff
+};
+
+/* Note: IRMlit operands must be < REF_BIAS, too!
+** This allows for fast and uniform manipulation of all operands
+** without looking up the operand mode in lj_ir_mode:
+** - CSE calculates the maximum reference of two operands.
+** This must work with mixed reference/literal operands, too.
+** - DCE marking only checks for operand >= REF_BIAS.
+** - LOOP needs to substitute reference operands.
+** Constant references and literals must not be modified.
+*/
+
+#define IRREF2(lo, hi) ((IRRef2)(lo) | ((IRRef2)(hi) << 16))
+
+#define irref_isk(ref) ((ref) < REF_BIAS)
+
+/* Tagged IR references (32 bit).
+**
+** +-------+-------+---------------+
+** | irt | flags | ref |
+** +-------+-------+---------------+
+**
+** The tag holds a copy of the IRType and speeds up IR type checks.
+*/
+typedef uint32_t TRef;
+
+#define TREF_REFMASK 0x0000ffff
+#define TREF_FRAME 0x00010000
+#define TREF_CONT 0x00020000
+
+#define TREF(ref, t) ((TRef)((ref) + ((t)<<24)))
+
+#define tref_ref(tr) ((IRRef1)(tr))
+#define tref_t(tr) ((IRType)((tr)>>24))
+#define tref_type(tr) ((IRType)(((tr)>>24) & IRT_TYPE))
+#define tref_typerange(tr, first, last) \
+ ((((tr)>>24) & IRT_TYPE) - (TRef)(first) <= (TRef)(last-first))
+
+#define tref_istype(tr, t) (((tr) & (IRT_TYPE<<24)) == ((t)<<24))
+#define tref_isnil(tr) (tref_istype((tr), IRT_NIL))
+#define tref_isfalse(tr) (tref_istype((tr), IRT_FALSE))
+#define tref_istrue(tr) (tref_istype((tr), IRT_TRUE))
+#define tref_isstr(tr) (tref_istype((tr), IRT_STR))
+#define tref_isfunc(tr) (tref_istype((tr), IRT_FUNC))
+#define tref_iscdata(tr) (tref_istype((tr), IRT_CDATA))
+#define tref_istab(tr) (tref_istype((tr), IRT_TAB))
+#define tref_isudata(tr) (tref_istype((tr), IRT_UDATA))
+#define tref_isnum(tr) (tref_istype((tr), IRT_NUM))
+#define tref_isint(tr) (tref_istype((tr), IRT_INT))
+
+#define tref_isbool(tr) (tref_typerange((tr), IRT_FALSE, IRT_TRUE))
+#define tref_ispri(tr) (tref_typerange((tr), IRT_NIL, IRT_TRUE))
+#define tref_istruecond(tr) (!tref_typerange((tr), IRT_NIL, IRT_FALSE))
+#define tref_isinteger(tr) (tref_typerange((tr), IRT_I8, IRT_INT))
+#define tref_isnumber(tr) (tref_typerange((tr), IRT_NUM, IRT_INT))
+#define tref_isnumber_str(tr) (tref_isnumber((tr)) || tref_isstr((tr)))
+#define tref_isgcv(tr) (tref_typerange((tr), IRT_STR, IRT_UDATA))
+
+#define tref_isk(tr) (irref_isk(tref_ref((tr))))
+#define tref_isk2(tr1, tr2) (irref_isk(tref_ref((tr1) | (tr2))))
+
+#define TREF_PRI(t) (TREF(REF_NIL-(t), (t)))
+#define TREF_NIL (TREF_PRI(IRT_NIL))
+#define TREF_FALSE (TREF_PRI(IRT_FALSE))
+#define TREF_TRUE (TREF_PRI(IRT_TRUE))
+
+/* -- IR format ----------------------------------------------------------- */
+
+/* IR instruction format (64 bit).
+**
+** 16 16 8 8 8 8
+** +-------+-------+---+---+---+---+
+** | op1 | op2 | t | o | r | s |
+** +-------+-------+---+---+---+---+
+** | op12/i/gco | ot | prev | (alternative fields in union)
+** +---------------+-------+-------+
+** 32 16 16
+**
+** prev is only valid prior to register allocation and then reused for r + s.
+*/
+
+typedef union IRIns {
+ struct {
+ LJ_ENDIAN_LOHI(
+ IRRef1 op1; /* IR operand 1. */
+ , IRRef1 op2; /* IR operand 2. */
+ )
+ IROpT ot; /* IR opcode and type (overlaps t and o). */
+ IRRef1 prev; /* Previous ins in same chain (overlaps r and s). */
+ };
+ struct {
+ IRRef2 op12; /* IR operand 1 and 2 (overlaps op1 and op2). */
+ LJ_ENDIAN_LOHI(
+ IRType1 t; /* IR type. */
+ , IROp1 o; /* IR opcode. */
+ )
+ LJ_ENDIAN_LOHI(
+ uint8_t r; /* Register allocation (overlaps prev). */
+ , uint8_t s; /* Spill slot allocation (overlaps prev). */
+ )
+ };
+ int32_t i; /* 32 bit signed integer literal (overlaps op12). */
+ GCRef gcr; /* GCobj constant (overlaps op12). */
+ MRef ptr; /* Pointer constant (overlaps op12). */
+} IRIns;
+
+#define ir_kgc(ir) check_exp((ir)->o == IR_KGC, gcref((ir)->gcr))
+#define ir_kstr(ir) (gco2str(ir_kgc((ir))))
+#define ir_ktab(ir) (gco2tab(ir_kgc((ir))))
+#define ir_kfunc(ir) (gco2func(ir_kgc((ir))))
+#define ir_kcdata(ir) (gco2cd(ir_kgc((ir))))
+#define ir_knum(ir) check_exp((ir)->o == IR_KNUM, mref((ir)->ptr, cTValue))
+#define ir_kint64(ir) check_exp((ir)->o == IR_KINT64, mref((ir)->ptr,cTValue))
+#define ir_k64(ir) \
+ check_exp((ir)->o == IR_KNUM || (ir)->o == IR_KINT64, mref((ir)->ptr,cTValue))
+#define ir_kptr(ir) \
+ check_exp((ir)->o == IR_KPTR || (ir)->o == IR_KKPTR, mref((ir)->ptr, void))
+
+/* A store or any other op with a non-weak guard has a side-effect. */
+static LJ_AINLINE int ir_sideeff(IRIns *ir)
+{
+ return (((ir->t.irt | ~IRT_GUARD) & lj_ir_mode[ir->o]) >= IRM_S);
+}
+
+LJ_STATIC_ASSERT((int)IRT_GUARD == (int)IRM_W);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ircall.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ircall.h
new file mode 100644
index 0000000..44afde3
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_ircall.h
@@ -0,0 +1,271 @@
+/*
+** IR CALL* instruction definitions.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_IRCALL_H
+#define _LJ_IRCALL_H
+
+#include "lj_obj.h"
+#include "lj_ir.h"
+#include "lj_jit.h"
+
+/* C call info for CALL* instructions. */
+typedef struct CCallInfo {
+ ASMFunction func; /* Function pointer. */
+ uint32_t flags; /* Number of arguments and flags. */
+} CCallInfo;
+
+#define CCI_NARGS(ci) ((ci)->flags & 0xff) /* Extract # of args. */
+#define CCI_NARGS_MAX 32 /* Max. # of args. */
+
+#define CCI_OTSHIFT 16
+#define CCI_OPTYPE(ci) ((ci)->flags >> CCI_OTSHIFT) /* Get op/type. */
+#define CCI_OPSHIFT 24
+#define CCI_OP(ci) ((ci)->flags >> CCI_OPSHIFT) /* Get op. */
+
+#define CCI_CALL_N (IR_CALLN << CCI_OPSHIFT)
+#define CCI_CALL_L (IR_CALLL << CCI_OPSHIFT)
+#define CCI_CALL_S (IR_CALLS << CCI_OPSHIFT)
+#define CCI_CALL_FN (CCI_CALL_N|CCI_CC_FASTCALL)
+#define CCI_CALL_FL (CCI_CALL_L|CCI_CC_FASTCALL)
+#define CCI_CALL_FS (CCI_CALL_S|CCI_CC_FASTCALL)
+
+/* C call info flags. */
+#define CCI_L 0x0100 /* Implicit L arg. */
+#define CCI_CASTU64 0x0200 /* Cast u64 result to number. */
+#define CCI_NOFPRCLOBBER 0x0400 /* Does not clobber any FPRs. */
+#define CCI_VARARG 0x0800 /* Vararg function. */
+
+#define CCI_CC_MASK 0x3000 /* Calling convention mask. */
+#define CCI_CC_SHIFT 12
+/* ORDER CC */
+#define CCI_CC_CDECL 0x0000 /* Default cdecl calling convention. */
+#define CCI_CC_THISCALL 0x1000 /* Thiscall calling convention. */
+#define CCI_CC_FASTCALL 0x2000 /* Fastcall calling convention. */
+#define CCI_CC_STDCALL 0x3000 /* Stdcall calling convention. */
+
+/* Helpers for conditional function definitions. */
+#define IRCALLCOND_ANY(x) x
+
+#if LJ_TARGET_X86ORX64
+#define IRCALLCOND_FPMATH(x) NULL
+#else
+#define IRCALLCOND_FPMATH(x) x
+#endif
+
+#if LJ_SOFTFP
+#define IRCALLCOND_SOFTFP(x) x
+#if LJ_HASFFI
+#define IRCALLCOND_SOFTFP_FFI(x) x
+#else
+#define IRCALLCOND_SOFTFP_FFI(x) NULL
+#endif
+#else
+#define IRCALLCOND_SOFTFP(x) NULL
+#define IRCALLCOND_SOFTFP_FFI(x) NULL
+#endif
+
+#define LJ_NEED_FP64 (LJ_TARGET_ARM || LJ_TARGET_PPC || LJ_TARGET_MIPS)
+
+#if LJ_HASFFI && (LJ_SOFTFP || LJ_NEED_FP64)
+#define IRCALLCOND_FP64_FFI(x) x
+#else
+#define IRCALLCOND_FP64_FFI(x) NULL
+#endif
+
+#if LJ_HASFFI
+#define IRCALLCOND_FFI(x) x
+#if LJ_32
+#define IRCALLCOND_FFI32(x) x
+#else
+#define IRCALLCOND_FFI32(x) NULL
+#endif
+#else
+#define IRCALLCOND_FFI(x) NULL
+#define IRCALLCOND_FFI32(x) NULL
+#endif
+
+#if LJ_SOFTFP
+#define ARG1_FP 2 /* Treat as 2 32 bit arguments. */
+#else
+#define ARG1_FP 1
+#endif
+
+#if LJ_32
+#define ARG2_64 4 /* Treat as 4 32 bit arguments. */
+#else
+#define ARG2_64 2
+#endif
+
+/* Function definitions for CALL* instructions. */
+#define IRCALLDEF(_) \
+ _(ANY, lj_str_cmp, 2, FN, INT, CCI_NOFPRCLOBBER) \
+ _(ANY, lj_str_new, 3, S, STR, CCI_L) \
+ _(ANY, lj_strscan_num, 2, FN, INT, 0) \
+ _(ANY, lj_str_fromint, 2, FN, STR, CCI_L) \
+ _(ANY, lj_str_fromnum, 2, FN, STR, CCI_L) \
+ _(ANY, lj_tab_new1, 2, FS, TAB, CCI_L) \
+ _(ANY, lj_tab_dup, 2, FS, TAB, CCI_L) \
+ _(ANY, lj_tab_newkey, 3, S, P32, CCI_L) \
+ _(ANY, lj_tab_len, 1, FL, INT, 0) \
+ _(ANY, lj_gc_step_jit, 2, FS, NIL, CCI_L) \
+ _(ANY, lj_gc_barrieruv, 2, FS, NIL, 0) \
+ _(ANY, lj_mem_newgco, 2, FS, P32, CCI_L) \
+ _(ANY, lj_math_random_step, 1, FS, NUM, CCI_CASTU64) \
+ _(ANY, lj_vm_modi, 2, FN, INT, 0) \
+ _(ANY, sinh, ARG1_FP, N, NUM, 0) \
+ _(ANY, cosh, ARG1_FP, N, NUM, 0) \
+ _(ANY, tanh, ARG1_FP, N, NUM, 0) \
+ _(ANY, fputc, 2, S, INT, 0) \
+ _(ANY, fwrite, 4, S, INT, 0) \
+ _(ANY, fflush, 1, S, INT, 0) \
+ /* ORDER FPM */ \
+ _(FPMATH, lj_vm_floor, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, lj_vm_ceil, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, lj_vm_trunc, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, sqrt, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, exp, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, lj_vm_exp2, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, log, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, lj_vm_log2, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, log10, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, sin, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, cos, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, tan, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, lj_vm_powi, ARG1_FP+1, N, NUM, 0) \
+ _(FPMATH, pow, ARG1_FP*2, N, NUM, 0) \
+ _(FPMATH, atan2, ARG1_FP*2, N, NUM, 0) \
+ _(FPMATH, ldexp, ARG1_FP+1, N, NUM, 0) \
+ _(SOFTFP, lj_vm_tobit, 2, N, INT, 0) \
+ _(SOFTFP, softfp_add, 4, N, NUM, 0) \
+ _(SOFTFP, softfp_sub, 4, N, NUM, 0) \
+ _(SOFTFP, softfp_mul, 4, N, NUM, 0) \
+ _(SOFTFP, softfp_div, 4, N, NUM, 0) \
+ _(SOFTFP, softfp_cmp, 4, N, NIL, 0) \
+ _(SOFTFP, softfp_i2d, 1, N, NUM, 0) \
+ _(SOFTFP, softfp_d2i, 2, N, INT, 0) \
+ _(SOFTFP_FFI, softfp_ui2d, 1, N, NUM, 0) \
+ _(SOFTFP_FFI, softfp_f2d, 1, N, NUM, 0) \
+ _(SOFTFP_FFI, softfp_d2ui, 2, N, INT, 0) \
+ _(SOFTFP_FFI, softfp_d2f, 2, N, FLOAT, 0) \
+ _(SOFTFP_FFI, softfp_i2f, 1, N, FLOAT, 0) \
+ _(SOFTFP_FFI, softfp_ui2f, 1, N, FLOAT, 0) \
+ _(SOFTFP_FFI, softfp_f2i, 1, N, INT, 0) \
+ _(SOFTFP_FFI, softfp_f2ui, 1, N, INT, 0) \
+ _(FP64_FFI, fp64_l2d, 2, N, NUM, 0) \
+ _(FP64_FFI, fp64_ul2d, 2, N, NUM, 0) \
+ _(FP64_FFI, fp64_l2f, 2, N, FLOAT, 0) \
+ _(FP64_FFI, fp64_ul2f, 2, N, FLOAT, 0) \
+ _(FP64_FFI, fp64_d2l, ARG1_FP, N, I64, 0) \
+ _(FP64_FFI, fp64_d2ul, ARG1_FP, N, U64, 0) \
+ _(FP64_FFI, fp64_f2l, 1, N, I64, 0) \
+ _(FP64_FFI, fp64_f2ul, 1, N, U64, 0) \
+ _(FFI, lj_carith_divi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \
+ _(FFI, lj_carith_divu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \
+ _(FFI, lj_carith_modi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \
+ _(FFI, lj_carith_modu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \
+ _(FFI, lj_carith_powi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \
+ _(FFI, lj_carith_powu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \
+ _(FFI, lj_cdata_setfin, 2, FN, P32, CCI_L) \
+ _(FFI, strlen, 1, L, INTP, 0) \
+ _(FFI, memcpy, 3, S, PTR, 0) \
+ _(FFI, memset, 3, S, PTR, 0) \
+ _(FFI, lj_vm_errno, 0, S, INT, CCI_NOFPRCLOBBER) \
+ _(FFI32, lj_carith_mul64, ARG2_64, N, I64, CCI_NOFPRCLOBBER)
+ \
+ /* End of list. */
+
+typedef enum {
+#define IRCALLENUM(cond, name, nargs, kind, type, flags) IRCALL_##name,
+IRCALLDEF(IRCALLENUM)
+#undef IRCALLENUM
+ IRCALL__MAX
+} IRCallID;
+
+LJ_FUNC TRef lj_ir_call(jit_State *J, IRCallID id, ...);
+
+LJ_DATA const CCallInfo lj_ir_callinfo[IRCALL__MAX+1];
+
+/* Soft-float declarations. */
+#if LJ_SOFTFP
+#if LJ_TARGET_ARM
+#define softfp_add __aeabi_dadd
+#define softfp_sub __aeabi_dsub
+#define softfp_mul __aeabi_dmul
+#define softfp_div __aeabi_ddiv
+#define softfp_cmp __aeabi_cdcmple
+#define softfp_i2d __aeabi_i2d
+#define softfp_d2i __aeabi_d2iz
+#define softfp_ui2d __aeabi_ui2d
+#define softfp_f2d __aeabi_f2d
+#define softfp_d2ui __aeabi_d2uiz
+#define softfp_d2f __aeabi_d2f
+#define softfp_i2f __aeabi_i2f
+#define softfp_ui2f __aeabi_ui2f
+#define softfp_f2i __aeabi_f2iz
+#define softfp_f2ui __aeabi_f2uiz
+#define fp64_l2d __aeabi_l2d
+#define fp64_ul2d __aeabi_ul2d
+#define fp64_l2f __aeabi_l2f
+#define fp64_ul2f __aeabi_ul2f
+#if LJ_TARGET_IOS
+#define fp64_d2l __fixdfdi
+#define fp64_d2ul __fixunsdfdi
+#define fp64_f2l __fixsfdi
+#define fp64_f2ul __fixunssfdi
+#else
+#define fp64_d2l __aeabi_d2lz
+#define fp64_d2ul __aeabi_d2ulz
+#define fp64_f2l __aeabi_f2lz
+#define fp64_f2ul __aeabi_f2ulz
+#endif
+#else
+#error "Missing soft-float definitions for target architecture"
+#endif
+extern double softfp_add(double a, double b);
+extern double softfp_sub(double a, double b);
+extern double softfp_mul(double a, double b);
+extern double softfp_div(double a, double b);
+extern void softfp_cmp(double a, double b);
+extern double softfp_i2d(int32_t a);
+extern int32_t softfp_d2i(double a);
+#if LJ_HASFFI
+extern double softfp_ui2d(uint32_t a);
+extern double softfp_f2d(float a);
+extern uint32_t softfp_d2ui(double a);
+extern float softfp_d2f(double a);
+extern float softfp_i2f(int32_t a);
+extern float softfp_ui2f(uint32_t a);
+extern int32_t softfp_f2i(float a);
+extern uint32_t softfp_f2ui(float a);
+#endif
+#endif
+
+#if LJ_HASFFI && LJ_NEED_FP64 && !(LJ_TARGET_ARM && LJ_SOFTFP)
+#ifdef __GNUC__
+#define fp64_l2d __floatdidf
+#define fp64_ul2d __floatundidf
+#define fp64_l2f __floatdisf
+#define fp64_ul2f __floatundisf
+#define fp64_d2l __fixdfdi
+#define fp64_d2ul __fixunsdfdi
+#define fp64_f2l __fixsfdi
+#define fp64_f2ul __fixunssfdi
+#else
+#error "Missing fp64 helper definitions for this compiler"
+#endif
+#endif
+
+#if LJ_HASFFI && (LJ_SOFTFP || LJ_NEED_FP64)
+extern double fp64_l2d(int64_t a);
+extern double fp64_ul2d(uint64_t a);
+extern float fp64_l2f(int64_t a);
+extern float fp64_ul2f(uint64_t a);
+extern int64_t fp64_d2l(double a);
+extern uint64_t fp64_d2ul(double a);
+extern int64_t fp64_f2l(float a);
+extern uint64_t fp64_f2ul(float a);
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_iropt.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_iropt.h
new file mode 100644
index 0000000..b5081e0
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_iropt.h
@@ -0,0 +1,161 @@
+/*
+** Common header for IR emitter and optimizations.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_IROPT_H
+#define _LJ_IROPT_H
+
+#include <stdarg.h>
+
+#include "lj_obj.h"
+#include "lj_jit.h"
+
+#if LJ_HASJIT
+/* IR emitter. */
+LJ_FUNC void LJ_FASTCALL lj_ir_growtop(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_ir_emit(jit_State *J);
+
+/* Save current IR in J->fold.ins, but do not emit it (yet). */
+static LJ_AINLINE void lj_ir_set_(jit_State *J, uint16_t ot, IRRef1 a, IRRef1 b)
+{
+ J->fold.ins.ot = ot; J->fold.ins.op1 = a; J->fold.ins.op2 = b;
+}
+
+#define lj_ir_set(J, ot, a, b) \
+ lj_ir_set_(J, (uint16_t)(ot), (IRRef1)(a), (IRRef1)(b))
+
+/* Get ref of next IR instruction and optionally grow IR.
+** Note: this may invalidate all IRIns*!
+*/
+static LJ_AINLINE IRRef lj_ir_nextins(jit_State *J)
+{
+ IRRef ref = J->cur.nins;
+ if (LJ_UNLIKELY(ref >= J->irtoplim)) lj_ir_growtop(J);
+ J->cur.nins = ref + 1;
+ return ref;
+}
+
+/* Interning of constants. */
+LJ_FUNC TRef LJ_FASTCALL lj_ir_kint(jit_State *J, int32_t k);
+LJ_FUNC void lj_ir_k64_freeall(jit_State *J);
+LJ_FUNC TRef lj_ir_k64(jit_State *J, IROp op, cTValue *tv);
+LJ_FUNC cTValue *lj_ir_k64_find(jit_State *J, uint64_t u64);
+LJ_FUNC TRef lj_ir_knum_u64(jit_State *J, uint64_t u64);
+LJ_FUNC TRef lj_ir_knumint(jit_State *J, lua_Number n);
+LJ_FUNC TRef lj_ir_kint64(jit_State *J, uint64_t u64);
+LJ_FUNC TRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t);
+LJ_FUNC TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr);
+LJ_FUNC TRef lj_ir_knull(jit_State *J, IRType t);
+LJ_FUNC TRef lj_ir_kslot(jit_State *J, TRef key, IRRef slot);
+
+#if LJ_64
+#define lj_ir_kintp(J, k) lj_ir_kint64(J, (uint64_t)(k))
+#else
+#define lj_ir_kintp(J, k) lj_ir_kint(J, (int32_t)(k))
+#endif
+
+static LJ_AINLINE TRef lj_ir_knum(jit_State *J, lua_Number n)
+{
+ TValue tv;
+ tv.n = n;
+ return lj_ir_knum_u64(J, tv.u64);
+}
+
+#define lj_ir_kstr(J, str) lj_ir_kgc(J, obj2gco((str)), IRT_STR)
+#define lj_ir_ktab(J, tab) lj_ir_kgc(J, obj2gco((tab)), IRT_TAB)
+#define lj_ir_kfunc(J, func) lj_ir_kgc(J, obj2gco((func)), IRT_FUNC)
+#define lj_ir_kptr(J, ptr) lj_ir_kptr_(J, IR_KPTR, (ptr))
+#define lj_ir_kkptr(J, ptr) lj_ir_kptr_(J, IR_KKPTR, (ptr))
+
+/* Special FP constants. */
+#define lj_ir_knum_zero(J) lj_ir_knum_u64(J, U64x(00000000,00000000))
+#define lj_ir_knum_one(J) lj_ir_knum_u64(J, U64x(3ff00000,00000000))
+#define lj_ir_knum_tobit(J) lj_ir_knum_u64(J, U64x(43380000,00000000))
+
+/* Special 128 bit SIMD constants. */
+#define lj_ir_knum_abs(J) lj_ir_k64(J, IR_KNUM, LJ_KSIMD(J, LJ_KSIMD_ABS))
+#define lj_ir_knum_neg(J) lj_ir_k64(J, IR_KNUM, LJ_KSIMD(J, LJ_KSIMD_NEG))
+
+/* Access to constants. */
+LJ_FUNC void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir);
+
+/* Convert IR operand types. */
+LJ_FUNC TRef LJ_FASTCALL lj_ir_tonumber(jit_State *J, TRef tr);
+LJ_FUNC TRef LJ_FASTCALL lj_ir_tonum(jit_State *J, TRef tr);
+LJ_FUNC TRef LJ_FASTCALL lj_ir_tostr(jit_State *J, TRef tr);
+
+/* Miscellaneous IR ops. */
+LJ_FUNC int lj_ir_numcmp(lua_Number a, lua_Number b, IROp op);
+LJ_FUNC int lj_ir_strcmp(GCstr *a, GCstr *b, IROp op);
+LJ_FUNC void lj_ir_rollback(jit_State *J, IRRef ref);
+
+/* Emit IR instructions with on-the-fly optimizations. */
+LJ_FUNC TRef LJ_FASTCALL lj_opt_fold(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_cse(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_cselim(jit_State *J, IRRef lim);
+
+/* Special return values for the fold functions. */
+enum {
+ NEXTFOLD, /* Couldn't fold, pass on. */
+ RETRYFOLD, /* Retry fold with modified fins. */
+ KINTFOLD, /* Return ref for int constant in fins->i. */
+ FAILFOLD, /* Guard would always fail. */
+ DROPFOLD, /* Guard eliminated. */
+ MAX_FOLD
+};
+
+#define INTFOLD(k) ((J->fold.ins.i = (k)), (TRef)KINTFOLD)
+#define INT64FOLD(k) (lj_ir_kint64(J, (k)))
+#define CONDFOLD(cond) ((TRef)FAILFOLD + (TRef)(cond))
+#define LEFTFOLD (J->fold.ins.op1)
+#define RIGHTFOLD (J->fold.ins.op2)
+#define CSEFOLD (lj_opt_cse(J))
+#define EMITFOLD (lj_ir_emit(J))
+
+/* Load/store forwarding. */
+LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_aload(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_hload(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_uload(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_fload(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_xload(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_tab_len(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_hrefk(jit_State *J);
+LJ_FUNC int LJ_FASTCALL lj_opt_fwd_href_nokey(jit_State *J);
+LJ_FUNC int LJ_FASTCALL lj_opt_fwd_tptr(jit_State *J, IRRef lim);
+LJ_FUNC int lj_opt_fwd_wasnonnil(jit_State *J, IROpT loadop, IRRef xref);
+
+/* Dead-store elimination. */
+LJ_FUNC TRef LJ_FASTCALL lj_opt_dse_ahstore(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_dse_ustore(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_dse_fstore(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_dse_xstore(jit_State *J);
+
+/* Narrowing. */
+LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_convert(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_index(jit_State *J, TRef key);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_toint(jit_State *J, TRef tr);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_tobit(jit_State *J, TRef tr);
+#if LJ_HASFFI
+LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_cindex(jit_State *J, TRef key);
+#endif
+LJ_FUNC TRef lj_opt_narrow_arith(jit_State *J, TRef rb, TRef rc,
+ TValue *vb, TValue *vc, IROp op);
+LJ_FUNC TRef lj_opt_narrow_unm(jit_State *J, TRef rc, TValue *vc);
+LJ_FUNC TRef lj_opt_narrow_mod(jit_State *J, TRef rb, TRef rc, TValue *vb, TValue *vc);
+LJ_FUNC TRef lj_opt_narrow_pow(jit_State *J, TRef rb, TRef rc, TValue *vb, TValue *vc);
+LJ_FUNC IRType lj_opt_narrow_forl(jit_State *J, cTValue *forbase);
+
+/* Optimization passes. */
+LJ_FUNC void lj_opt_dce(jit_State *J);
+LJ_FUNC int lj_opt_loop(jit_State *J);
+#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI)
+LJ_FUNC void lj_opt_split(jit_State *J);
+#else
+#define lj_opt_split(J) UNUSED(J)
+#endif
+LJ_FUNC void lj_opt_sink(jit_State *J);
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_jit.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_jit.h
new file mode 100644
index 0000000..3f38d28
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_jit.h
@@ -0,0 +1,423 @@
+/*
+** Common definitions for the JIT compiler.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_JIT_H
+#define _LJ_JIT_H
+
+#include "lj_obj.h"
+#include "lj_ir.h"
+
+/* JIT engine flags. */
+#define JIT_F_ON 0x00000001
+
+/* CPU-specific JIT engine flags. */
+#if LJ_TARGET_X86ORX64
+#define JIT_F_CMOV 0x00000010
+#define JIT_F_SSE2 0x00000020
+#define JIT_F_SSE3 0x00000040
+#define JIT_F_SSE4_1 0x00000080
+#define JIT_F_P4 0x00000100
+#define JIT_F_PREFER_IMUL 0x00000200
+#define JIT_F_SPLIT_XMM 0x00000400
+#define JIT_F_LEA_AGU 0x00000800
+
+/* Names for the CPU-specific flags. Must match the order above. */
+#define JIT_F_CPU_FIRST JIT_F_CMOV
+#define JIT_F_CPUSTRING "\4CMOV\4SSE2\4SSE3\6SSE4.1\2P4\3AMD\2K8\4ATOM"
+#elif LJ_TARGET_ARM
+#define JIT_F_ARMV6_ 0x00000010
+#define JIT_F_ARMV6T2_ 0x00000020
+#define JIT_F_ARMV7 0x00000040
+#define JIT_F_VFPV2 0x00000080
+#define JIT_F_VFPV3 0x00000100
+
+#define JIT_F_ARMV6 (JIT_F_ARMV6_|JIT_F_ARMV6T2_|JIT_F_ARMV7)
+#define JIT_F_ARMV6T2 (JIT_F_ARMV6T2_|JIT_F_ARMV7)
+#define JIT_F_VFP (JIT_F_VFPV2|JIT_F_VFPV3)
+
+/* Names for the CPU-specific flags. Must match the order above. */
+#define JIT_F_CPU_FIRST JIT_F_ARMV6_
+#define JIT_F_CPUSTRING "\5ARMv6\7ARMv6T2\5ARMv7\5VFPv2\5VFPv3"
+#elif LJ_TARGET_PPC
+#define JIT_F_SQRT 0x00000010
+#define JIT_F_ROUND 0x00000020
+
+/* Names for the CPU-specific flags. Must match the order above. */
+#define JIT_F_CPU_FIRST JIT_F_SQRT
+#define JIT_F_CPUSTRING "\4SQRT\5ROUND"
+#elif LJ_TARGET_MIPS
+#define JIT_F_MIPS32R2 0x00000010
+
+/* Names for the CPU-specific flags. Must match the order above. */
+#define JIT_F_CPU_FIRST JIT_F_MIPS32R2
+#define JIT_F_CPUSTRING "\010MIPS32R2"
+#else
+#define JIT_F_CPU_FIRST 0
+#define JIT_F_CPUSTRING ""
+#endif
+
+/* Optimization flags. */
+#define JIT_F_OPT_MASK 0x0fff0000
+
+#define JIT_F_OPT_FOLD 0x00010000
+#define JIT_F_OPT_CSE 0x00020000
+#define JIT_F_OPT_DCE 0x00040000
+#define JIT_F_OPT_FWD 0x00080000
+#define JIT_F_OPT_DSE 0x00100000
+#define JIT_F_OPT_NARROW 0x00200000
+#define JIT_F_OPT_LOOP 0x00400000
+#define JIT_F_OPT_ABC 0x00800000
+#define JIT_F_OPT_SINK 0x01000000
+#define JIT_F_OPT_FUSE 0x02000000
+
+/* Optimizations names for -O. Must match the order above. */
+#define JIT_F_OPT_FIRST JIT_F_OPT_FOLD
+#define JIT_F_OPTSTRING \
+ "\4fold\3cse\3dce\3fwd\3dse\6narrow\4loop\3abc\4sink\4fuse"
+
+/* Optimization levels set a fixed combination of flags. */
+#define JIT_F_OPT_0 0
+#define JIT_F_OPT_1 (JIT_F_OPT_FOLD|JIT_F_OPT_CSE|JIT_F_OPT_DCE)
+#define JIT_F_OPT_2 (JIT_F_OPT_1|JIT_F_OPT_NARROW|JIT_F_OPT_LOOP)
+#define JIT_F_OPT_3 (JIT_F_OPT_2|\
+ JIT_F_OPT_FWD|JIT_F_OPT_DSE|JIT_F_OPT_ABC|JIT_F_OPT_SINK|JIT_F_OPT_FUSE)
+#define JIT_F_OPT_DEFAULT JIT_F_OPT_3
+
+#if LJ_TARGET_WINDOWS || LJ_64
+/* See: http://blogs.msdn.com/oldnewthing/archive/2003/10/08/55239.aspx */
+#define JIT_P_sizemcode_DEFAULT 64
+#else
+/* Could go as low as 4K, but the mmap() overhead would be rather high. */
+#define JIT_P_sizemcode_DEFAULT 32
+#endif
+
+/* Optimization parameters and their defaults. Length is a char in octal! */
+#define JIT_PARAMDEF(_) \
+ _(\010, maxtrace, 1000) /* Max. # of traces in cache. */ \
+ _(\011, maxrecord, 4000) /* Max. # of recorded IR instructions. */ \
+ _(\012, maxirconst, 500) /* Max. # of IR constants of a trace. */ \
+ _(\007, maxside, 100) /* Max. # of side traces of a root trace. */ \
+ _(\007, maxsnap, 500) /* Max. # of snapshots for a trace. */ \
+ \
+ _(\007, hotloop, 56) /* # of iter. to detect a hot loop/call. */ \
+ _(\007, hotexit, 10) /* # of taken exits to start a side trace. */ \
+ _(\007, tryside, 4) /* # of attempts to compile a side trace. */ \
+ \
+ _(\012, instunroll, 4) /* Max. unroll for instable loops. */ \
+ _(\012, loopunroll, 15) /* Max. unroll for loop ops in side traces. */ \
+ _(\012, callunroll, 3) /* Max. unroll for recursive calls. */ \
+ _(\011, recunroll, 2) /* Min. unroll for true recursion. */ \
+ \
+ /* Size of each machine code area (in KBytes). */ \
+ _(\011, sizemcode, JIT_P_sizemcode_DEFAULT) \
+ /* Max. total size of all machine code areas (in KBytes). */ \
+ _(\010, maxmcode, 512) \
+ /* End of list. */
+
+enum {
+#define JIT_PARAMENUM(len, name, value) JIT_P_##name,
+JIT_PARAMDEF(JIT_PARAMENUM)
+#undef JIT_PARAMENUM
+ JIT_P__MAX
+};
+
+#define JIT_PARAMSTR(len, name, value) #len #name
+#define JIT_P_STRING JIT_PARAMDEF(JIT_PARAMSTR)
+
+/* Trace compiler state. */
+typedef enum {
+ LJ_TRACE_IDLE, /* Trace compiler idle. */
+ LJ_TRACE_ACTIVE = 0x10,
+ LJ_TRACE_RECORD, /* Bytecode recording active. */
+ LJ_TRACE_START, /* New trace started. */
+ LJ_TRACE_END, /* End of trace. */
+ LJ_TRACE_ASM, /* Assemble trace. */
+ LJ_TRACE_ERR /* Trace aborted with error. */
+} TraceState;
+
+/* Post-processing action. */
+typedef enum {
+ LJ_POST_NONE, /* No action. */
+ LJ_POST_FIXCOMP, /* Fixup comparison and emit pending guard. */
+ LJ_POST_FIXGUARD, /* Fixup and emit pending guard. */
+ LJ_POST_FIXGUARDSNAP, /* Fixup and emit pending guard and snapshot. */
+ LJ_POST_FIXBOOL, /* Fixup boolean result. */
+ LJ_POST_FIXCONST, /* Fixup constant results. */
+ LJ_POST_FFRETRY /* Suppress recording of retried fast functions. */
+} PostProc;
+
+/* Machine code type. */
+#if LJ_TARGET_X86ORX64
+typedef uint8_t MCode;
+#else
+typedef uint32_t MCode;
+#endif
+
+/* Linked list of MCode areas. */
+typedef struct MCLink {
+ MCode *next; /* Next area. */
+ size_t size; /* Size of current area. */
+} MCLink;
+
+/* Stack snapshot header. */
+typedef struct SnapShot {
+ uint16_t mapofs; /* Offset into snapshot map. */
+ IRRef1 ref; /* First IR ref for this snapshot. */
+ uint8_t nslots; /* Number of valid slots. */
+ uint8_t topslot; /* Maximum frame extent. */
+ uint8_t nent; /* Number of compressed entries. */
+ uint8_t count; /* Count of taken exits for this snapshot. */
+} SnapShot;
+
+#define SNAPCOUNT_DONE 255 /* Already compiled and linked a side trace. */
+
+/* Compressed snapshot entry. */
+typedef uint32_t SnapEntry;
+
+#define SNAP_FRAME 0x010000 /* Frame slot. */
+#define SNAP_CONT 0x020000 /* Continuation slot. */
+#define SNAP_NORESTORE 0x040000 /* No need to restore slot. */
+#define SNAP_SOFTFPNUM 0x080000 /* Soft-float number. */
+LJ_STATIC_ASSERT(SNAP_FRAME == TREF_FRAME);
+LJ_STATIC_ASSERT(SNAP_CONT == TREF_CONT);
+
+#define SNAP(slot, flags, ref) (((SnapEntry)(slot) << 24) + (flags) + (ref))
+#define SNAP_TR(slot, tr) \
+ (((SnapEntry)(slot) << 24) + ((tr) & (TREF_CONT|TREF_FRAME|TREF_REFMASK)))
+#define SNAP_MKPC(pc) ((SnapEntry)u32ptr(pc))
+#define SNAP_MKFTSZ(ftsz) ((SnapEntry)(ftsz))
+#define snap_ref(sn) ((sn) & 0xffff)
+#define snap_slot(sn) ((BCReg)((sn) >> 24))
+#define snap_isframe(sn) ((sn) & SNAP_FRAME)
+#define snap_pc(sn) ((const BCIns *)(uintptr_t)(sn))
+#define snap_setref(sn, ref) (((sn) & (0xffff0000&~SNAP_NORESTORE)) | (ref))
+
+/* Snapshot and exit numbers. */
+typedef uint32_t SnapNo;
+typedef uint32_t ExitNo;
+
+/* Trace number. */
+typedef uint32_t TraceNo; /* Used to pass around trace numbers. */
+typedef uint16_t TraceNo1; /* Stored trace number. */
+
+/* Type of link. ORDER LJ_TRLINK */
+typedef enum {
+ LJ_TRLINK_NONE, /* Incomplete trace. No link, yet. */
+ LJ_TRLINK_ROOT, /* Link to other root trace. */
+ LJ_TRLINK_LOOP, /* Loop to same trace. */
+ LJ_TRLINK_TAILREC, /* Tail-recursion. */
+ LJ_TRLINK_UPREC, /* Up-recursion. */
+ LJ_TRLINK_DOWNREC, /* Down-recursion. */
+ LJ_TRLINK_INTERP, /* Fallback to interpreter. */
+ LJ_TRLINK_RETURN /* Return to interpreter. */
+} TraceLink;
+
+/* Trace object. */
+typedef struct GCtrace {
+ GCHeader;
+ uint8_t topslot; /* Top stack slot already checked to be allocated. */
+ uint8_t linktype; /* Type of link. */
+ IRRef nins; /* Next IR instruction. Biased with REF_BIAS. */
+ GCRef gclist;
+ IRIns *ir; /* IR instructions/constants. Biased with REF_BIAS. */
+ IRRef nk; /* Lowest IR constant. Biased with REF_BIAS. */
+ uint16_t nsnap; /* Number of snapshots. */
+ uint16_t nsnapmap; /* Number of snapshot map elements. */
+ SnapShot *snap; /* Snapshot array. */
+ SnapEntry *snapmap; /* Snapshot map. */
+ GCRef startpt; /* Starting prototype. */
+ MRef startpc; /* Bytecode PC of starting instruction. */
+ BCIns startins; /* Original bytecode of starting instruction. */
+ MSize szmcode; /* Size of machine code. */
+ MCode *mcode; /* Start of machine code. */
+ MSize mcloop; /* Offset of loop start in machine code. */
+ uint16_t nchild; /* Number of child traces (root trace only). */
+ uint16_t spadjust; /* Stack pointer adjustment (offset in bytes). */
+ TraceNo1 traceno; /* Trace number. */
+ TraceNo1 link; /* Linked trace (or self for loops). */
+ TraceNo1 root; /* Root trace of side trace (or 0 for root traces). */
+ TraceNo1 nextroot; /* Next root trace for same prototype. */
+ TraceNo1 nextside; /* Next side trace of same root trace. */
+ uint8_t sinktags; /* Trace has SINK tags. */
+ uint8_t unused1;
+#ifdef LUAJIT_USE_GDBJIT
+ void *gdbjit_entry; /* GDB JIT entry. */
+#endif
+} GCtrace;
+
+#define gco2trace(o) check_exp((o)->gch.gct == ~LJ_TTRACE, (GCtrace *)(o))
+#define traceref(J, n) \
+ check_exp((n)>0 && (MSize)(n)<J->sizetrace, (GCtrace *)gcref(J->trace[(n)]))
+
+LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCtrace, gclist));
+
+static LJ_AINLINE MSize snap_nextofs(GCtrace *T, SnapShot *snap)
+{
+ if (snap+1 == &T->snap[T->nsnap])
+ return T->nsnapmap;
+ else
+ return (snap+1)->mapofs;
+}
+
+/* Round-robin penalty cache for bytecodes leading to aborted traces. */
+typedef struct HotPenalty {
+ MRef pc; /* Starting bytecode PC. */
+ uint16_t val; /* Penalty value, i.e. hotcount start. */
+ uint16_t reason; /* Abort reason (really TraceErr). */
+} HotPenalty;
+
+#define PENALTY_SLOTS 64 /* Penalty cache slot. Must be a power of 2. */
+#define PENALTY_MIN (36*2) /* Minimum penalty value. */
+#define PENALTY_MAX 60000 /* Maximum penalty value. */
+#define PENALTY_RNDBITS 4 /* # of random bits to add to penalty value. */
+
+/* Round-robin backpropagation cache for narrowing conversions. */
+typedef struct BPropEntry {
+ IRRef1 key; /* Key: original reference. */
+ IRRef1 val; /* Value: reference after conversion. */
+ IRRef mode; /* Mode for this entry (currently IRCONV_*). */
+} BPropEntry;
+
+/* Number of slots for the backpropagation cache. Must be a power of 2. */
+#define BPROP_SLOTS 16
+
+/* Scalar evolution analysis cache. */
+typedef struct ScEvEntry {
+ MRef pc; /* Bytecode PC of FORI. */
+ IRRef1 idx; /* Index reference. */
+ IRRef1 start; /* Constant start reference. */
+ IRRef1 stop; /* Constant stop reference. */
+ IRRef1 step; /* Constant step reference. */
+ IRType1 t; /* Scalar type. */
+ uint8_t dir; /* Direction. 1: +, 0: -. */
+} ScEvEntry;
+
+/* 128 bit SIMD constants. */
+enum {
+ LJ_KSIMD_ABS,
+ LJ_KSIMD_NEG,
+ LJ_KSIMD__MAX
+};
+
+/* Get 16 byte aligned pointer to SIMD constant. */
+#define LJ_KSIMD(J, n) \
+ ((TValue *)(((intptr_t)&J->ksimd[2*(n)] + 15) & ~(intptr_t)15))
+
+/* Set/reset flag to activate the SPLIT pass for the current trace. */
+#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI)
+#define lj_needsplit(J) (J->needsplit = 1)
+#define lj_resetsplit(J) (J->needsplit = 0)
+#else
+#define lj_needsplit(J) UNUSED(J)
+#define lj_resetsplit(J) UNUSED(J)
+#endif
+
+/* Fold state is used to fold instructions on-the-fly. */
+typedef struct FoldState {
+ IRIns ins; /* Currently emitted instruction. */
+ IRIns left; /* Instruction referenced by left operand. */
+ IRIns right; /* Instruction referenced by right operand. */
+} FoldState;
+
+/* JIT compiler state. */
+typedef struct jit_State {
+ GCtrace cur; /* Current trace. */
+
+ lua_State *L; /* Current Lua state. */
+ const BCIns *pc; /* Current PC. */
+ GCfunc *fn; /* Current function. */
+ GCproto *pt; /* Current prototype. */
+ TRef *base; /* Current frame base, points into J->slots. */
+
+ uint32_t flags; /* JIT engine flags. */
+ BCReg maxslot; /* Relative to baseslot. */
+ BCReg baseslot; /* Current frame base, offset into J->slots. */
+
+ uint8_t mergesnap; /* Allowed to merge with next snapshot. */
+ uint8_t needsnap; /* Need snapshot before recording next bytecode. */
+ IRType1 guardemit; /* Accumulated IRT_GUARD for emitted instructions. */
+ uint8_t bcskip; /* Number of bytecode instructions to skip. */
+
+ FoldState fold; /* Fold state. */
+
+ const BCIns *bc_min; /* Start of allowed bytecode range for root trace. */
+ MSize bc_extent; /* Extent of the range. */
+
+ TraceState state; /* Trace compiler state. */
+
+ int32_t instunroll; /* Unroll counter for instable loops. */
+ int32_t loopunroll; /* Unroll counter for loop ops in side traces. */
+ int32_t tailcalled; /* Number of successive tailcalls. */
+ int32_t framedepth; /* Current frame depth. */
+ int32_t retdepth; /* Return frame depth (count of RETF). */
+
+ MRef k64; /* Pointer to chained array of 64 bit constants. */
+ TValue ksimd[LJ_KSIMD__MAX*2+1]; /* 16 byte aligned SIMD constants. */
+
+ IRIns *irbuf; /* Temp. IR instruction buffer. Biased with REF_BIAS. */
+ IRRef irtoplim; /* Upper limit of instuction buffer (biased). */
+ IRRef irbotlim; /* Lower limit of instuction buffer (biased). */
+ IRRef loopref; /* Last loop reference or ref of final LOOP (or 0). */
+
+ MSize sizesnap; /* Size of temp. snapshot buffer. */
+ SnapShot *snapbuf; /* Temp. snapshot buffer. */
+ SnapEntry *snapmapbuf; /* Temp. snapshot map buffer. */
+ MSize sizesnapmap; /* Size of temp. snapshot map buffer. */
+
+ PostProc postproc; /* Required post-processing after execution. */
+#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI)
+ int needsplit; /* Need SPLIT pass. */
+#endif
+
+ GCRef *trace; /* Array of traces. */
+ TraceNo freetrace; /* Start of scan for next free trace. */
+ MSize sizetrace; /* Size of trace array. */
+
+ IRRef1 chain[IR__MAX]; /* IR instruction skip-list chain anchors. */
+ TRef slot[LJ_MAX_JSLOTS+LJ_STACK_EXTRA]; /* Stack slot map. */
+
+ int32_t param[JIT_P__MAX]; /* JIT engine parameters. */
+
+ MCode *exitstubgroup[LJ_MAX_EXITSTUBGR]; /* Exit stub group addresses. */
+
+ HotPenalty penalty[PENALTY_SLOTS]; /* Penalty slots. */
+ uint32_t penaltyslot; /* Round-robin index into penalty slots. */
+ uint32_t prngstate; /* PRNG state. */
+
+ BPropEntry bpropcache[BPROP_SLOTS]; /* Backpropagation cache slots. */
+ uint32_t bpropslot; /* Round-robin index into bpropcache slots. */
+
+ ScEvEntry scev; /* Scalar evolution analysis cache slots. */
+
+ const BCIns *startpc; /* Bytecode PC of starting instruction. */
+ TraceNo parent; /* Parent of current side trace (0 for root traces). */
+ ExitNo exitno; /* Exit number in parent of current side trace. */
+
+ BCIns *patchpc; /* PC for pending re-patch. */
+ BCIns patchins; /* Instruction for pending re-patch. */
+
+ int mcprot; /* Protection of current mcode area. */
+ MCode *mcarea; /* Base of current mcode area. */
+ MCode *mctop; /* Top of current mcode area. */
+ MCode *mcbot; /* Bottom of current mcode area. */
+ size_t szmcarea; /* Size of current mcode area. */
+ size_t szallmcarea; /* Total size of all allocated mcode areas. */
+
+ TValue errinfo; /* Additional info element for trace errors. */
+}
+#if LJ_TARGET_ARM
+LJ_ALIGN(16) /* For DISPATCH-relative addresses in assembler part. */
+#endif
+jit_State;
+
+/* Trivial PRNG e.g. used for penalty randomization. */
+static LJ_AINLINE uint32_t LJ_PRNG_BITS(jit_State *J, int bits)
+{
+ /* Yes, this LCG is very weak, but that doesn't matter for our use case. */
+ J->prngstate = J->prngstate * 1103515245 + 12345;
+ return J->prngstate >> (32-bits);
+}
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_lex.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_lex.h
new file mode 100644
index 0000000..41c03f9
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_lex.h
@@ -0,0 +1,85 @@
+/*
+** Lexical analyzer.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_LEX_H
+#define _LJ_LEX_H
+
+#include <stdarg.h>
+
+#include "lj_obj.h"
+#include "lj_err.h"
+
+/* Lua lexer tokens. */
+#define TKDEF(_, __) \
+ _(and) _(break) _(do) _(else) _(elseif) _(end) _(false) \
+ _(for) _(function) _(goto) _(if) _(in) _(local) _(nil) _(not) _(or) \
+ _(repeat) _(return) _(then) _(true) _(until) _(while) \
+ __(concat, ..) __(dots, ...) __(eq, ==) __(ge, >=) __(le, <=) __(ne, ~=) \
+ __(label, ::) __(number, <number>) __(name, <name>) __(string, <string>) \
+ __(eof, <eof>)
+
+enum {
+ TK_OFS = 256,
+#define TKENUM1(name) TK_##name,
+#define TKENUM2(name, sym) TK_##name,
+TKDEF(TKENUM1, TKENUM2)
+#undef TKENUM1
+#undef TKENUM2
+ TK_RESERVED = TK_while - TK_OFS
+};
+
+typedef int LexToken;
+
+/* Combined bytecode ins/line. Only used during bytecode generation. */
+typedef struct BCInsLine {
+ BCIns ins; /* Bytecode instruction. */
+ BCLine line; /* Line number for this bytecode. */
+} BCInsLine;
+
+/* Info for local variables. Only used during bytecode generation. */
+typedef struct VarInfo {
+ GCRef name; /* Local variable name or goto/label name. */
+ BCPos startpc; /* First point where the local variable is active. */
+ BCPos endpc; /* First point where the local variable is dead. */
+ uint8_t slot; /* Variable slot. */
+ uint8_t info; /* Variable/goto/label info. */
+} VarInfo;
+
+/* Lua lexer state. */
+typedef struct LexState {
+ struct FuncState *fs; /* Current FuncState. Defined in lj_parse.c. */
+ struct lua_State *L; /* Lua state. */
+ TValue tokenval; /* Current token value. */
+ TValue lookaheadval; /* Lookahead token value. */
+ int current; /* Current character (charint). */
+ LexToken token; /* Current token. */
+ LexToken lookahead; /* Lookahead token. */
+ MSize n; /* Bytes left in input buffer. */
+ const char *p; /* Current position in input buffer. */
+ SBuf sb; /* String buffer for tokens. */
+ lua_Reader rfunc; /* Reader callback. */
+ void *rdata; /* Reader callback data. */
+ BCLine linenumber; /* Input line counter. */
+ BCLine lastline; /* Line of last token. */
+ GCstr *chunkname; /* Current chunk name (interned string). */
+ const char *chunkarg; /* Chunk name argument. */
+ const char *mode; /* Allow loading bytecode (b) and/or source text (t). */
+ VarInfo *vstack; /* Stack for names and extents of local variables. */
+ MSize sizevstack; /* Size of variable stack. */
+ MSize vtop; /* Top of variable stack. */
+ BCInsLine *bcstack; /* Stack for bytecode instructions/line numbers. */
+ MSize sizebcstack; /* Size of bytecode stack. */
+ uint32_t level; /* Syntactical nesting level. */
+} LexState;
+
+LJ_FUNC int lj_lex_setup(lua_State *L, LexState *ls);
+LJ_FUNC void lj_lex_cleanup(lua_State *L, LexState *ls);
+LJ_FUNC void lj_lex_next(LexState *ls);
+LJ_FUNC LexToken lj_lex_lookahead(LexState *ls);
+LJ_FUNC const char *lj_lex_token2str(LexState *ls, LexToken token);
+LJ_FUNC_NORET void lj_lex_error(LexState *ls, LexToken token, ErrMsg em, ...);
+LJ_FUNC void lj_lex_init(lua_State *L);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_lib.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_lib.h
new file mode 100644
index 0000000..aa87407
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_lib.h
@@ -0,0 +1,112 @@
+/*
+** Library function support.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_LIB_H
+#define _LJ_LIB_H
+
+#include "lj_obj.h"
+
+/*
+** A fallback handler is called by the assembler VM if the fast path fails:
+**
+** - too few arguments: unrecoverable.
+** - wrong argument type: recoverable, if coercion succeeds.
+** - bad argument value: unrecoverable.
+** - stack overflow: recoverable, if stack reallocation succeeds.
+** - extra handling: recoverable.
+**
+** The unrecoverable cases throw an error with lj_err_arg(), lj_err_argtype(),
+** lj_err_caller() or lj_err_callermsg().
+** The recoverable cases return 0 or the number of results + 1.
+** The assembler VM retries the fast path only if 0 is returned.
+** This time the fallback must not be called again or it gets stuck in a loop.
+*/
+
+/* Return values from fallback handler. */
+#define FFH_RETRY 0
+#define FFH_UNREACHABLE FFH_RETRY
+#define FFH_RES(n) ((n)+1)
+#define FFH_TAILCALL (-1)
+
+LJ_FUNC TValue *lj_lib_checkany(lua_State *L, int narg);
+LJ_FUNC GCstr *lj_lib_checkstr(lua_State *L, int narg);
+LJ_FUNC GCstr *lj_lib_optstr(lua_State *L, int narg);
+#if LJ_DUALNUM
+LJ_FUNC void lj_lib_checknumber(lua_State *L, int narg);
+#else
+#define lj_lib_checknumber(L, narg) lj_lib_checknum((L), (narg))
+#endif
+LJ_FUNC lua_Number lj_lib_checknum(lua_State *L, int narg);
+LJ_FUNC int32_t lj_lib_checkint(lua_State *L, int narg);
+LJ_FUNC int32_t lj_lib_optint(lua_State *L, int narg, int32_t def);
+LJ_FUNC int32_t lj_lib_checkbit(lua_State *L, int narg);
+LJ_FUNC GCfunc *lj_lib_checkfunc(lua_State *L, int narg);
+LJ_FUNC GCtab *lj_lib_checktab(lua_State *L, int narg);
+LJ_FUNC GCtab *lj_lib_checktabornil(lua_State *L, int narg);
+LJ_FUNC int lj_lib_checkopt(lua_State *L, int narg, int def, const char *lst);
+
+/* Avoid including lj_frame.h. */
+#define lj_lib_upvalue(L, n) \
+ (&gcref((L->base-1)->fr.func)->fn.c.upvalue[(n)-1])
+
+#if LJ_TARGET_WINDOWS
+#define lj_lib_checkfpu(L) \
+ do { setnumV(L->top++, (lua_Number)1437217655); \
+ if (lua_tointeger(L, -1) != 1437217655) lj_err_caller(L, LJ_ERR_BADFPU); \
+ L->top--; } while (0)
+#else
+#define lj_lib_checkfpu(L) UNUSED(L)
+#endif
+
+/* Push internal function on the stack. */
+static LJ_AINLINE void lj_lib_pushcc(lua_State *L, lua_CFunction f,
+ int id, int n)
+{
+ GCfunc *fn;
+ lua_pushcclosure(L, f, n);
+ fn = funcV(L->top-1);
+ fn->c.ffid = (uint8_t)id;
+ setmref(fn->c.pc, &G(L)->bc_cfunc_int);
+}
+
+#define lj_lib_pushcf(L, fn, id) (lj_lib_pushcc(L, (fn), (id), 0))
+
+/* Library function declarations. Scanned by buildvm. */
+#define LJLIB_CF(name) static int lj_cf_##name(lua_State *L)
+#define LJLIB_ASM(name) static int lj_ffh_##name(lua_State *L)
+#define LJLIB_ASM_(name)
+#define LJLIB_SET(name)
+#define LJLIB_PUSH(arg)
+#define LJLIB_REC(handler)
+#define LJLIB_NOREGUV
+#define LJLIB_NOREG
+
+#define LJ_LIB_REG(L, regname, name) \
+ lj_lib_register(L, regname, lj_lib_init_##name, lj_lib_cf_##name)
+
+LJ_FUNC void lj_lib_register(lua_State *L, const char *libname,
+ const uint8_t *init, const lua_CFunction *cf);
+
+/* Library init data tags. */
+#define LIBINIT_LENMASK 0x3f
+#define LIBINIT_TAGMASK 0xc0
+#define LIBINIT_CF 0x00
+#define LIBINIT_ASM 0x40
+#define LIBINIT_ASM_ 0x80
+#define LIBINIT_STRING 0xc0
+#define LIBINIT_MAXSTR 0x39
+#define LIBINIT_SET 0xfa
+#define LIBINIT_NUMBER 0xfb
+#define LIBINIT_COPY 0xfc
+#define LIBINIT_LASTCL 0xfd
+#define LIBINIT_FFID 0xfe
+#define LIBINIT_END 0xff
+
+/* Exported library functions. */
+
+typedef struct RandomState RandomState;
+LJ_FUNC uint64_t LJ_FASTCALL lj_math_random_step(RandomState *rs);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_mcode.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_mcode.h
new file mode 100644
index 0000000..f0847e9
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_mcode.h
@@ -0,0 +1,30 @@
+/*
+** Machine code management.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_MCODE_H
+#define _LJ_MCODE_H
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT || LJ_HASFFI
+LJ_FUNC void lj_mcode_sync(void *start, void *end);
+#endif
+
+#if LJ_HASJIT
+
+#include "lj_jit.h"
+
+LJ_FUNC void lj_mcode_free(jit_State *J);
+LJ_FUNC MCode *lj_mcode_reserve(jit_State *J, MCode **lim);
+LJ_FUNC void lj_mcode_commit(jit_State *J, MCode *m);
+LJ_FUNC void lj_mcode_abort(jit_State *J);
+LJ_FUNC MCode *lj_mcode_patch(jit_State *J, MCode *ptr, int finish);
+LJ_FUNC_NORET void lj_mcode_limiterr(jit_State *J, size_t need);
+
+#define lj_mcode_commitbot(J, m) (J->mcbot = (m))
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_meta.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_meta.h
new file mode 100644
index 0000000..e061d99
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_meta.h
@@ -0,0 +1,37 @@
+/*
+** Metamethod handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_META_H
+#define _LJ_META_H
+
+#include "lj_obj.h"
+
+/* Metamethod handling */
+LJ_FUNC void lj_meta_init(lua_State *L);
+LJ_FUNC cTValue *lj_meta_cache(GCtab *mt, MMS mm, GCstr *name);
+LJ_FUNC cTValue *lj_meta_lookup(lua_State *L, cTValue *o, MMS mm);
+#if LJ_HASFFI
+LJ_FUNC int lj_meta_tailcall(lua_State *L, cTValue *tv);
+#endif
+
+#define lj_meta_fastg(g, mt, mm) \
+ ((mt) == NULL ? NULL : ((mt)->nomm & (1u<<(mm))) ? NULL : \
+ lj_meta_cache(mt, mm, mmname_str(g, mm)))
+#define lj_meta_fast(L, mt, mm) lj_meta_fastg(G(L), mt, mm)
+
+/* C helpers for some instructions, called from assembler VM. */
+LJ_FUNCA cTValue *lj_meta_tget(lua_State *L, cTValue *o, cTValue *k);
+LJ_FUNCA TValue *lj_meta_tset(lua_State *L, cTValue *o, cTValue *k);
+LJ_FUNCA TValue *lj_meta_arith(lua_State *L, TValue *ra, cTValue *rb,
+ cTValue *rc, BCReg op);
+LJ_FUNCA TValue *lj_meta_cat(lua_State *L, TValue *top, int left);
+LJ_FUNCA TValue * LJ_FASTCALL lj_meta_len(lua_State *L, cTValue *o);
+LJ_FUNCA TValue *lj_meta_equal(lua_State *L, GCobj *o1, GCobj *o2, int ne);
+LJ_FUNCA TValue * LJ_FASTCALL lj_meta_equal_cd(lua_State *L, BCIns ins);
+LJ_FUNCA TValue *lj_meta_comp(lua_State *L, cTValue *o1, cTValue *o2, int op);
+LJ_FUNCA void lj_meta_call(lua_State *L, TValue *func, TValue *top);
+LJ_FUNCA void LJ_FASTCALL lj_meta_for(lua_State *L, TValue *o);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_obj.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_obj.h
new file mode 100644
index 0000000..2ee526c
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_obj.h
@@ -0,0 +1,864 @@
+/*
+** LuaJIT VM tags, values and objects.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#ifndef _LJ_OBJ_H
+#define _LJ_OBJ_H
+
+#include "lua.h"
+#include "lj_def.h"
+#include "lj_arch.h"
+
+/* -- Memory references (32 bit address space) ---------------------------- */
+
+/* Memory size. */
+typedef uint32_t MSize;
+
+/* Memory reference */
+typedef struct MRef {
+ uint32_t ptr32; /* Pseudo 32 bit pointer. */
+} MRef;
+
+#define mref(r, t) ((t *)(void *)(uintptr_t)(r).ptr32)
+
+#define setmref(r, p) ((r).ptr32 = (uint32_t)(uintptr_t)(void *)(p))
+#define setmrefr(r, v) ((r).ptr32 = (v).ptr32)
+
+/* -- GC object references (32 bit address space) ------------------------- */
+
+/* GCobj reference */
+typedef struct GCRef {
+ uint32_t gcptr32; /* Pseudo 32 bit pointer. */
+} GCRef;
+
+/* Common GC header for all collectable objects. */
+#define GCHeader GCRef nextgc; uint8_t marked; uint8_t gct
+/* This occupies 6 bytes, so use the next 2 bytes for non-32 bit fields. */
+
+#define gcref(r) ((GCobj *)(uintptr_t)(r).gcptr32)
+#define gcrefp(r, t) ((t *)(void *)(uintptr_t)(r).gcptr32)
+#define gcrefu(r) ((r).gcptr32)
+#define gcrefi(r) ((int32_t)(r).gcptr32)
+#define gcrefeq(r1, r2) ((r1).gcptr32 == (r2).gcptr32)
+#define gcnext(gc) (gcref((gc)->gch.nextgc))
+
+#define setgcref(r, gc) ((r).gcptr32 = (uint32_t)(uintptr_t)&(gc)->gch)
+#define setgcrefi(r, i) ((r).gcptr32 = (uint32_t)(i))
+#define setgcrefp(r, p) ((r).gcptr32 = (uint32_t)(uintptr_t)(p))
+#define setgcrefnull(r) ((r).gcptr32 = 0)
+#define setgcrefr(r, v) ((r).gcptr32 = (v).gcptr32)
+
+/* IMPORTANT NOTE:
+**
+** All uses of the setgcref* macros MUST be accompanied with a write barrier.
+**
+** This is to ensure the integrity of the incremental GC. The invariant
+** to preserve is that a black object never points to a white object.
+** I.e. never store a white object into a field of a black object.
+**
+** It's ok to LEAVE OUT the write barrier ONLY in the following cases:
+** - The source is not a GC object (NULL).
+** - The target is a GC root. I.e. everything in global_State.
+** - The target is a lua_State field (threads are never black).
+** - The target is a stack slot, see setgcV et al.
+** - The target is an open upvalue, i.e. pointing to a stack slot.
+** - The target is a newly created object (i.e. marked white). But make
+** sure nothing invokes the GC inbetween.
+** - The target and the source are the same object (self-reference).
+** - The target already contains the object (e.g. moving elements around).
+**
+** The most common case is a store to a stack slot. All other cases where
+** a barrier has been omitted are annotated with a NOBARRIER comment.
+**
+** The same logic applies for stores to table slots (array part or hash
+** part). ALL uses of lj_tab_set* require a barrier for the stored value
+** *and* the stored key, based on the above rules. In practice this means
+** a barrier is needed if *either* of the key or value are a GC object.
+**
+** It's ok to LEAVE OUT the write barrier in the following special cases:
+** - The stored value is nil. The key doesn't matter because it's either
+** not resurrected or lj_tab_newkey() will take care of the key barrier.
+** - The key doesn't matter if the *previously* stored value is guaranteed
+** to be non-nil (because the key is kept alive in the table).
+** - The key doesn't matter if it's guaranteed not to be part of the table,
+** since lj_tab_newkey() takes care of the key barrier. This applies
+** trivially to new tables, but watch out for resurrected keys. Storing
+** a nil value leaves the key in the table!
+**
+** In case of doubt use lj_gc_anybarriert() as it's rather cheap. It's used
+** by the interpreter for all table stores.
+**
+** Note: In contrast to Lua's GC, LuaJIT's GC does *not* specially mark
+** dead keys in tables. The reference is left in, but it's guaranteed to
+** be never dereferenced as long as the value is nil. It's ok if the key is
+** freed or if any object subsequently gets the same address.
+**
+** Not destroying dead keys helps to keep key hash slots stable. This avoids
+** specialization back-off for HREFK when a value flips between nil and
+** non-nil and the GC gets in the way. It also allows safely hoisting
+** HREF/HREFK across GC steps. Dead keys are only removed if a table is
+** resized (i.e. by NEWREF) and xREF must not be CSEd across a resize.
+**
+** The trade-off is that a write barrier for tables must take the key into
+** account, too. Implicitly resurrecting the key by storing a non-nil value
+** may invalidate the incremental GC invariant.
+*/
+
+/* -- Common type definitions --------------------------------------------- */
+
+/* Types for handling bytecodes. Need this here, details in lj_bc.h. */
+typedef uint32_t BCIns; /* Bytecode instruction. */
+typedef uint32_t BCPos; /* Bytecode position. */
+typedef uint32_t BCReg; /* Bytecode register. */
+typedef int32_t BCLine; /* Bytecode line number. */
+
+/* Internal assembler functions. Never call these directly from C. */
+typedef void (*ASMFunction)(void);
+
+/* Resizable string buffer. Need this here, details in lj_str.h. */
+typedef struct SBuf {
+ char *buf; /* String buffer base. */
+ MSize n; /* String buffer length. */
+ MSize sz; /* String buffer size. */
+} SBuf;
+
+/* -- Tags and values ----------------------------------------------------- */
+
+/* Frame link. */
+typedef union {
+ int32_t ftsz; /* Frame type and size of previous frame. */
+ MRef pcr; /* Overlaps PC for Lua frames. */
+} FrameLink;
+
+/* Tagged value. */
+typedef LJ_ALIGN(8) union TValue {
+ uint64_t u64; /* 64 bit pattern overlaps number. */
+ lua_Number n; /* Number object overlaps split tag/value object. */
+ struct {
+ LJ_ENDIAN_LOHI(
+ union {
+ GCRef gcr; /* GCobj reference (if any). */
+ int32_t i; /* Integer value. */
+ };
+ , uint32_t it; /* Internal object tag. Must overlap MSW of number. */
+ )
+ };
+ struct {
+ LJ_ENDIAN_LOHI(
+ GCRef func; /* Function for next frame (or dummy L). */
+ , FrameLink tp; /* Link to previous frame. */
+ )
+ } fr;
+ struct {
+ LJ_ENDIAN_LOHI(
+ uint32_t lo; /* Lower 32 bits of number. */
+ , uint32_t hi; /* Upper 32 bits of number. */
+ )
+ } u32;
+} TValue;
+
+typedef const TValue cTValue;
+
+#define tvref(r) (mref(r, TValue))
+
+/* More external and GCobj tags for internal objects. */
+#define LAST_TT LUA_TTHREAD
+#define LUA_TPROTO (LAST_TT+1)
+#define LUA_TCDATA (LAST_TT+2)
+
+/* Internal object tags.
+**
+** Internal tags overlap the MSW of a number object (must be a double).
+** Interpreted as a double these are special NaNs. The FPU only generates
+** one type of NaN (0xfff8_0000_0000_0000). So MSWs > 0xfff80000 are available
+** for use as internal tags. Small negative numbers are used to shorten the
+** encoding of type comparisons (reg/mem against sign-ext. 8 bit immediate).
+**
+** ---MSW---.---LSW---
+** primitive types | itype | |
+** lightuserdata | itype | void * | (32 bit platforms)
+** lightuserdata |ffff| void * | (64 bit platforms, 47 bit pointers)
+** GC objects | itype | GCRef |
+** int (LJ_DUALNUM)| itype | int |
+** number -------double------
+**
+** ORDER LJ_T
+** Primitive types nil/false/true must be first, lightuserdata next.
+** GC objects are at the end, table/userdata must be lowest.
+** Also check lj_ir.h for similar ordering constraints.
+*/
+#define LJ_TNIL (~0u)
+#define LJ_TFALSE (~1u)
+#define LJ_TTRUE (~2u)
+#define LJ_TLIGHTUD (~3u)
+#define LJ_TSTR (~4u)
+#define LJ_TUPVAL (~5u)
+#define LJ_TTHREAD (~6u)
+#define LJ_TPROTO (~7u)
+#define LJ_TFUNC (~8u)
+#define LJ_TTRACE (~9u)
+#define LJ_TCDATA (~10u)
+#define LJ_TTAB (~11u)
+#define LJ_TUDATA (~12u)
+/* This is just the canonical number type used in some places. */
+#define LJ_TNUMX (~13u)
+
+/* Integers have itype == LJ_TISNUM doubles have itype < LJ_TISNUM */
+#if LJ_64
+#define LJ_TISNUM 0xfffeffffu
+#else
+#define LJ_TISNUM LJ_TNUMX
+#endif
+#define LJ_TISTRUECOND LJ_TFALSE
+#define LJ_TISPRI LJ_TTRUE
+#define LJ_TISGCV (LJ_TSTR+1)
+#define LJ_TISTABUD LJ_TTAB
+
+/* -- String object ------------------------------------------------------- */
+
+/* String object header. String payload follows. */
+typedef struct GCstr {
+ GCHeader;
+ uint8_t reserved; /* Used by lexer for fast lookup of reserved words. */
+ uint8_t unused;
+ MSize hash; /* Hash of string. */
+ MSize len; /* Size of string. */
+} GCstr;
+
+#define strref(r) (&gcref((r))->str)
+#define strdata(s) ((const char *)((s)+1))
+#define strdatawr(s) ((char *)((s)+1))
+#define strVdata(o) strdata(strV(o))
+#define sizestring(s) (sizeof(struct GCstr)+(s)->len+1)
+
+/* -- Userdata object ----------------------------------------------------- */
+
+/* Userdata object. Payload follows. */
+typedef struct GCudata {
+ GCHeader;
+ uint8_t udtype; /* Userdata type. */
+ uint8_t unused2;
+ GCRef env; /* Should be at same offset in GCfunc. */
+ MSize len; /* Size of payload. */
+ GCRef metatable; /* Must be at same offset in GCtab. */
+ uint32_t align1; /* To force 8 byte alignment of the payload. */
+} GCudata;
+
+/* Userdata types. */
+enum {
+ UDTYPE_USERDATA, /* Regular userdata. */
+ UDTYPE_IO_FILE, /* I/O library FILE. */
+ UDTYPE_FFI_CLIB, /* FFI C library namespace. */
+ UDTYPE__MAX
+};
+
+#define uddata(u) ((void *)((u)+1))
+#define sizeudata(u) (sizeof(struct GCudata)+(u)->len)
+
+/* -- C data object ------------------------------------------------------- */
+
+/* C data object. Payload follows. */
+typedef struct GCcdata {
+ GCHeader;
+ uint16_t ctypeid; /* C type ID. */
+} GCcdata;
+
+/* Prepended to variable-sized or realigned C data objects. */
+typedef struct GCcdataVar {
+ uint16_t offset; /* Offset to allocated memory (relative to GCcdata). */
+ uint16_t extra; /* Extra space allocated (incl. GCcdata + GCcdatav). */
+ MSize len; /* Size of payload. */
+} GCcdataVar;
+
+#define cdataptr(cd) ((void *)((cd)+1))
+#define cdataisv(cd) ((cd)->marked & 0x80)
+#define cdatav(cd) ((GCcdataVar *)((char *)(cd) - sizeof(GCcdataVar)))
+#define cdatavlen(cd) check_exp(cdataisv(cd), cdatav(cd)->len)
+#define sizecdatav(cd) (cdatavlen(cd) + cdatav(cd)->extra)
+#define memcdatav(cd) ((void *)((char *)(cd) - cdatav(cd)->offset))
+
+/* -- Prototype object ---------------------------------------------------- */
+
+#define SCALE_NUM_GCO ((int32_t)sizeof(lua_Number)/sizeof(GCRef))
+#define round_nkgc(n) (((n) + SCALE_NUM_GCO-1) & ~(SCALE_NUM_GCO-1))
+
+typedef struct GCproto {
+ GCHeader;
+ uint8_t numparams; /* Number of parameters. */
+ uint8_t framesize; /* Fixed frame size. */
+ MSize sizebc; /* Number of bytecode instructions. */
+ GCRef gclist;
+ MRef k; /* Split constant array (points to the middle). */
+ MRef uv; /* Upvalue list. local slot|0x8000 or parent uv idx. */
+ MSize sizekgc; /* Number of collectable constants. */
+ MSize sizekn; /* Number of lua_Number constants. */
+ MSize sizept; /* Total size including colocated arrays. */
+ uint8_t sizeuv; /* Number of upvalues. */
+ uint8_t flags; /* Miscellaneous flags (see below). */
+ uint16_t trace; /* Anchor for chain of root traces. */
+ /* ------ The following fields are for debugging/tracebacks only ------ */
+ GCRef chunkname; /* Name of the chunk this function was defined in. */
+ BCLine firstline; /* First line of the function definition. */
+ BCLine numline; /* Number of lines for the function definition. */
+ MRef lineinfo; /* Compressed map from bytecode ins. to source line. */
+ MRef uvinfo; /* Upvalue names. */
+ MRef varinfo; /* Names and compressed extents of local variables. */
+} GCproto;
+
+/* Flags for prototype. */
+#define PROTO_CHILD 0x01 /* Has child prototypes. */
+#define PROTO_VARARG 0x02 /* Vararg function. */
+#define PROTO_FFI 0x04 /* Uses BC_KCDATA for FFI datatypes. */
+#define PROTO_NOJIT 0x08 /* JIT disabled for this function. */
+#define PROTO_ILOOP 0x10 /* Patched bytecode with ILOOP etc. */
+/* Only used during parsing. */
+#define PROTO_HAS_RETURN 0x20 /* Already emitted a return. */
+#define PROTO_FIXUP_RETURN 0x40 /* Need to fixup emitted returns. */
+/* Top bits used for counting created closures. */
+#define PROTO_CLCOUNT 0x20 /* Base of saturating 3 bit counter. */
+#define PROTO_CLC_BITS 3
+#define PROTO_CLC_POLY (3*PROTO_CLCOUNT) /* Polymorphic threshold. */
+
+#define PROTO_UV_LOCAL 0x8000 /* Upvalue for local slot. */
+#define PROTO_UV_IMMUTABLE 0x4000 /* Immutable upvalue. */
+
+#define proto_kgc(pt, idx) \
+ check_exp((uintptr_t)(intptr_t)(idx) >= (uintptr_t)-(intptr_t)(pt)->sizekgc, \
+ gcref(mref((pt)->k, GCRef)[(idx)]))
+#define proto_knumtv(pt, idx) \
+ check_exp((uintptr_t)(idx) < (pt)->sizekn, &mref((pt)->k, TValue)[(idx)])
+#define proto_bc(pt) ((BCIns *)((char *)(pt) + sizeof(GCproto)))
+#define proto_bcpos(pt, pc) ((BCPos)((pc) - proto_bc(pt)))
+#define proto_uv(pt) (mref((pt)->uv, uint16_t))
+
+#define proto_chunkname(pt) (strref((pt)->chunkname))
+#define proto_chunknamestr(pt) (strdata(proto_chunkname((pt))))
+#define proto_lineinfo(pt) (mref((pt)->lineinfo, const void))
+#define proto_uvinfo(pt) (mref((pt)->uvinfo, const uint8_t))
+#define proto_varinfo(pt) (mref((pt)->varinfo, const uint8_t))
+
+/* -- Upvalue object ------------------------------------------------------ */
+
+typedef struct GCupval {
+ GCHeader;
+ uint8_t closed; /* Set if closed (i.e. uv->v == &uv->u.value). */
+ uint8_t immutable; /* Immutable value. */
+ union {
+ TValue tv; /* If closed: the value itself. */
+ struct { /* If open: double linked list, anchored at thread. */
+ GCRef prev;
+ GCRef next;
+ };
+ };
+ MRef v; /* Points to stack slot (open) or above (closed). */
+ uint32_t dhash; /* Disambiguation hash: dh1 != dh2 => cannot alias. */
+} GCupval;
+
+#define uvprev(uv_) (&gcref((uv_)->prev)->uv)
+#define uvnext(uv_) (&gcref((uv_)->next)->uv)
+#define uvval(uv_) (mref((uv_)->v, TValue))
+
+/* -- Function object (closures) ------------------------------------------ */
+
+/* Common header for functions. env should be at same offset in GCudata. */
+#define GCfuncHeader \
+ GCHeader; uint8_t ffid; uint8_t nupvalues; \
+ GCRef env; GCRef gclist; MRef pc
+
+typedef struct GCfuncC {
+ GCfuncHeader;
+ lua_CFunction f; /* C function to be called. */
+ TValue upvalue[1]; /* Array of upvalues (TValue). */
+} GCfuncC;
+
+typedef struct GCfuncL {
+ GCfuncHeader;
+ GCRef uvptr[1]; /* Array of _pointers_ to upvalue objects (GCupval). */
+} GCfuncL;
+
+typedef union GCfunc {
+ GCfuncC c;
+ GCfuncL l;
+} GCfunc;
+
+#define FF_LUA 0
+#define FF_C 1
+#define isluafunc(fn) ((fn)->c.ffid == FF_LUA)
+#define iscfunc(fn) ((fn)->c.ffid == FF_C)
+#define isffunc(fn) ((fn)->c.ffid > FF_C)
+#define funcproto(fn) \
+ check_exp(isluafunc(fn), (GCproto *)(mref((fn)->l.pc, char)-sizeof(GCproto)))
+#define sizeCfunc(n) (sizeof(GCfuncC)-sizeof(TValue)+sizeof(TValue)*(n))
+#define sizeLfunc(n) (sizeof(GCfuncL)-sizeof(GCRef)+sizeof(GCRef)*(n))
+
+/* -- Table object -------------------------------------------------------- */
+
+/* Hash node. */
+typedef struct Node {
+ TValue val; /* Value object. Must be first field. */
+ TValue key; /* Key object. */
+ MRef next; /* Hash chain. */
+ MRef freetop; /* Top of free elements (stored in t->node[0]). */
+} Node;
+
+LJ_STATIC_ASSERT(offsetof(Node, val) == 0);
+
+typedef struct GCtab {
+ GCHeader;
+ uint8_t nomm; /* Negative cache for fast metamethods. */
+ int8_t colo; /* Array colocation. */
+ MRef array; /* Array part. */
+ GCRef gclist;
+ GCRef metatable; /* Must be at same offset in GCudata. */
+ MRef node; /* Hash part. */
+ uint32_t asize; /* Size of array part (keys [0, asize-1]). */
+ uint32_t hmask; /* Hash part mask (size of hash part - 1). */
+} GCtab;
+
+#define sizetabcolo(n) ((n)*sizeof(TValue) + sizeof(GCtab))
+#define tabref(r) (&gcref((r))->tab)
+#define noderef(r) (mref((r), Node))
+#define nextnode(n) (mref((n)->next, Node))
+
+/* -- State objects ------------------------------------------------------- */
+
+/* VM states. */
+enum {
+ LJ_VMST_INTERP, /* Interpreter. */
+ LJ_VMST_C, /* C function. */
+ LJ_VMST_GC, /* Garbage collector. */
+ LJ_VMST_EXIT, /* Trace exit handler. */
+ LJ_VMST_RECORD, /* Trace recorder. */
+ LJ_VMST_OPT, /* Optimizer. */
+ LJ_VMST_ASM, /* Assembler. */
+ LJ_VMST__MAX
+};
+
+#define setvmstate(g, st) ((g)->vmstate = ~LJ_VMST_##st)
+
+/* Metamethods. ORDER MM */
+#ifdef LJ_HASFFI
+#define MMDEF_FFI(_) _(new)
+#else
+#define MMDEF_FFI(_)
+#endif
+
+#if LJ_52 || LJ_HASFFI
+#define MMDEF_PAIRS(_) _(pairs) _(ipairs)
+#else
+#define MMDEF_PAIRS(_)
+#define MM_pairs 255
+#define MM_ipairs 255
+#endif
+
+#define MMDEF(_) \
+ _(index) _(newindex) _(gc) _(mode) _(eq) _(len) \
+ /* Only the above (fast) metamethods are negative cached (max. 8). */ \
+ _(lt) _(le) _(concat) _(call) \
+ /* The following must be in ORDER ARITH. */ \
+ _(add) _(sub) _(mul) _(div) _(mod) _(pow) _(unm) \
+ /* The following are used in the standard libraries. */ \
+ _(metatable) _(tostring) MMDEF_FFI(_) MMDEF_PAIRS(_)
+
+typedef enum {
+#define MMENUM(name) MM_##name,
+MMDEF(MMENUM)
+#undef MMENUM
+ MM__MAX,
+ MM____ = MM__MAX,
+ MM_FAST = MM_len
+} MMS;
+
+/* GC root IDs. */
+typedef enum {
+ GCROOT_MMNAME, /* Metamethod names. */
+ GCROOT_MMNAME_LAST = GCROOT_MMNAME + MM__MAX-1,
+ GCROOT_BASEMT, /* Metatables for base types. */
+ GCROOT_BASEMT_NUM = GCROOT_BASEMT + ~LJ_TNUMX,
+ GCROOT_IO_INPUT, /* Userdata for default I/O input file. */
+ GCROOT_IO_OUTPUT, /* Userdata for default I/O output file. */
+ GCROOT_MAX
+} GCRootID;
+
+#define basemt_it(g, it) ((g)->gcroot[GCROOT_BASEMT+~(it)])
+#define basemt_obj(g, o) ((g)->gcroot[GCROOT_BASEMT+itypemap(o)])
+#define mmname_str(g, mm) (strref((g)->gcroot[GCROOT_MMNAME+(mm)]))
+
+typedef struct GCState {
+ MSize total; /* Memory currently allocated. */
+ MSize threshold; /* Memory threshold. */
+ uint8_t currentwhite; /* Current white color. */
+ uint8_t state; /* GC state. */
+ uint8_t nocdatafin; /* No cdata finalizer called. */
+ uint8_t unused2;
+ MSize sweepstr; /* Sweep position in string table. */
+ GCRef root; /* List of all collectable objects. */
+ MRef sweep; /* Sweep position in root list. */
+ GCRef gray; /* List of gray objects. */
+ GCRef grayagain; /* List of objects for atomic traversal. */
+ GCRef weak; /* List of weak tables (to be cleared). */
+ GCRef mmudata; /* List of userdata (to be finalized). */
+ MSize stepmul; /* Incremental GC step granularity. */
+ MSize debt; /* Debt (how much GC is behind schedule). */
+ MSize estimate; /* Estimate of memory actually in use. */
+ MSize pause; /* Pause between successive GC cycles. */
+} GCState;
+
+/* Global state, shared by all threads of a Lua universe. */
+typedef struct global_State {
+ GCRef *strhash; /* String hash table (hash chain anchors). */
+ MSize strmask; /* String hash mask (size of hash table - 1). */
+ MSize strnum; /* Number of strings in hash table. */
+ lua_Alloc allocf; /* Memory allocator. */
+ void *allocd; /* Memory allocator data. */
+ GCState gc; /* Garbage collector. */
+ SBuf tmpbuf; /* Temporary buffer for string concatenation. */
+ Node nilnode; /* Fallback 1-element hash part (nil key and value). */
+ GCstr strempty; /* Empty string. */
+ uint8_t stremptyz; /* Zero terminator of empty string. */
+ uint8_t hookmask; /* Hook mask. */
+ uint8_t dispatchmode; /* Dispatch mode. */
+ uint8_t vmevmask; /* VM event mask. */
+ GCRef mainthref; /* Link to main thread. */
+ TValue registrytv; /* Anchor for registry. */
+ TValue tmptv, tmptv2; /* Temporary TValues. */
+ GCupval uvhead; /* Head of double-linked list of all open upvalues. */
+ int32_t hookcount; /* Instruction hook countdown. */
+ int32_t hookcstart; /* Start count for instruction hook counter. */
+ lua_Hook hookf; /* Hook function. */
+ lua_CFunction wrapf; /* Wrapper for C function calls. */
+ lua_CFunction panic; /* Called as a last resort for errors. */
+ volatile int32_t vmstate; /* VM state or current JIT code trace number. */
+ BCIns bc_cfunc_int; /* Bytecode for internal C function calls. */
+ BCIns bc_cfunc_ext; /* Bytecode for external C function calls. */
+ GCRef jit_L; /* Current JIT code lua_State or NULL. */
+ MRef jit_base; /* Current JIT code L->base. */
+ MRef ctype_state; /* Pointer to C type state. */
+ GCRef gcroot[GCROOT_MAX]; /* GC roots. */
+} global_State;
+
+#define mainthread(g) (&gcref(g->mainthref)->th)
+#define niltv(L) \
+ check_exp(tvisnil(&G(L)->nilnode.val), &G(L)->nilnode.val)
+#define niltvg(g) \
+ check_exp(tvisnil(&(g)->nilnode.val), &(g)->nilnode.val)
+
+/* Hook management. Hook event masks are defined in lua.h. */
+#define HOOK_EVENTMASK 0x0f
+#define HOOK_ACTIVE 0x10
+#define HOOK_ACTIVE_SHIFT 4
+#define HOOK_VMEVENT 0x20
+#define HOOK_GC 0x40
+#define hook_active(g) ((g)->hookmask & HOOK_ACTIVE)
+#define hook_enter(g) ((g)->hookmask |= HOOK_ACTIVE)
+#define hook_entergc(g) ((g)->hookmask |= (HOOK_ACTIVE|HOOK_GC))
+#define hook_vmevent(g) ((g)->hookmask |= (HOOK_ACTIVE|HOOK_VMEVENT))
+#define hook_leave(g) ((g)->hookmask &= ~HOOK_ACTIVE)
+#define hook_save(g) ((g)->hookmask & ~HOOK_EVENTMASK)
+#define hook_restore(g, h) \
+ ((g)->hookmask = ((g)->hookmask & HOOK_EVENTMASK) | (h))
+
+/* Per-thread state object. */
+struct lua_State {
+ GCHeader;
+ uint8_t dummy_ffid; /* Fake FF_C for curr_funcisL() on dummy frames. */
+ uint8_t status; /* Thread status. */
+ MRef glref; /* Link to global state. */
+ GCRef gclist; /* GC chain. */
+ TValue *base; /* Base of currently executing function. */
+ TValue *top; /* First free slot in the stack. */
+ MRef maxstack; /* Last free slot in the stack. */
+ MRef stack; /* Stack base. */
+ GCRef openupval; /* List of open upvalues in the stack. */
+ GCRef env; /* Thread environment (table of globals). */
+ void *cframe; /* End of C stack frame chain. */
+ MSize stacksize; /* True stack size (incl. LJ_STACK_EXTRA). */
+};
+
+#define G(L) (mref(L->glref, global_State))
+#define registry(L) (&G(L)->registrytv)
+
+/* Macros to access the currently executing (Lua) function. */
+#define curr_func(L) (&gcref((L->base-1)->fr.func)->fn)
+#define curr_funcisL(L) (isluafunc(curr_func(L)))
+#define curr_proto(L) (funcproto(curr_func(L)))
+#define curr_topL(L) (L->base + curr_proto(L)->framesize)
+#define curr_top(L) (curr_funcisL(L) ? curr_topL(L) : L->top)
+
+/* -- GC object definition and conversions -------------------------------- */
+
+/* GC header for generic access to common fields of GC objects. */
+typedef struct GChead {
+ GCHeader;
+ uint8_t unused1;
+ uint8_t unused2;
+ GCRef env;
+ GCRef gclist;
+ GCRef metatable;
+} GChead;
+
+/* The env field SHOULD be at the same offset for all GC objects. */
+LJ_STATIC_ASSERT(offsetof(GChead, env) == offsetof(GCfuncL, env));
+LJ_STATIC_ASSERT(offsetof(GChead, env) == offsetof(GCudata, env));
+
+/* The metatable field MUST be at the same offset for all GC objects. */
+LJ_STATIC_ASSERT(offsetof(GChead, metatable) == offsetof(GCtab, metatable));
+LJ_STATIC_ASSERT(offsetof(GChead, metatable) == offsetof(GCudata, metatable));
+
+/* The gclist field MUST be at the same offset for all GC objects. */
+LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(lua_State, gclist));
+LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCproto, gclist));
+LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCfuncL, gclist));
+LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCtab, gclist));
+
+typedef union GCobj {
+ GChead gch;
+ GCstr str;
+ GCupval uv;
+ lua_State th;
+ GCproto pt;
+ GCfunc fn;
+ GCcdata cd;
+ GCtab tab;
+ GCudata ud;
+} GCobj;
+
+/* Macros to convert a GCobj pointer into a specific value. */
+#define gco2str(o) check_exp((o)->gch.gct == ~LJ_TSTR, &(o)->str)
+#define gco2uv(o) check_exp((o)->gch.gct == ~LJ_TUPVAL, &(o)->uv)
+#define gco2th(o) check_exp((o)->gch.gct == ~LJ_TTHREAD, &(o)->th)
+#define gco2pt(o) check_exp((o)->gch.gct == ~LJ_TPROTO, &(o)->pt)
+#define gco2func(o) check_exp((o)->gch.gct == ~LJ_TFUNC, &(o)->fn)
+#define gco2cd(o) check_exp((o)->gch.gct == ~LJ_TCDATA, &(o)->cd)
+#define gco2tab(o) check_exp((o)->gch.gct == ~LJ_TTAB, &(o)->tab)
+#define gco2ud(o) check_exp((o)->gch.gct == ~LJ_TUDATA, &(o)->ud)
+
+/* Macro to convert any collectable object into a GCobj pointer. */
+#define obj2gco(v) ((GCobj *)(v))
+
+/* -- TValue getters/setters ---------------------------------------------- */
+
+#ifdef LUA_USE_ASSERT
+#include "lj_gc.h"
+#endif
+
+/* Macros to test types. */
+#define itype(o) ((o)->it)
+#define tvisnil(o) (itype(o) == LJ_TNIL)
+#define tvisfalse(o) (itype(o) == LJ_TFALSE)
+#define tvistrue(o) (itype(o) == LJ_TTRUE)
+#define tvisbool(o) (tvisfalse(o) || tvistrue(o))
+#if LJ_64
+#define tvislightud(o) (((int32_t)itype(o) >> 15) == -2)
+#else
+#define tvislightud(o) (itype(o) == LJ_TLIGHTUD)
+#endif
+#define tvisstr(o) (itype(o) == LJ_TSTR)
+#define tvisfunc(o) (itype(o) == LJ_TFUNC)
+#define tvisthread(o) (itype(o) == LJ_TTHREAD)
+#define tvisproto(o) (itype(o) == LJ_TPROTO)
+#define tviscdata(o) (itype(o) == LJ_TCDATA)
+#define tvistab(o) (itype(o) == LJ_TTAB)
+#define tvisudata(o) (itype(o) == LJ_TUDATA)
+#define tvisnumber(o) (itype(o) <= LJ_TISNUM)
+#define tvisint(o) (LJ_DUALNUM && itype(o) == LJ_TISNUM)
+#define tvisnum(o) (itype(o) < LJ_TISNUM)
+
+#define tvistruecond(o) (itype(o) < LJ_TISTRUECOND)
+#define tvispri(o) (itype(o) >= LJ_TISPRI)
+#define tvistabud(o) (itype(o) <= LJ_TISTABUD) /* && !tvisnum() */
+#define tvisgcv(o) ((itype(o) - LJ_TISGCV) > (LJ_TNUMX - LJ_TISGCV))
+
+/* Special macros to test numbers for NaN, +0, -0, +1 and raw equality. */
+#define tvisnan(o) ((o)->n != (o)->n)
+#if LJ_64
+#define tviszero(o) (((o)->u64 << 1) == 0)
+#else
+#define tviszero(o) (((o)->u32.lo | ((o)->u32.hi << 1)) == 0)
+#endif
+#define tvispzero(o) ((o)->u64 == 0)
+#define tvismzero(o) ((o)->u64 == U64x(80000000,00000000))
+#define tvispone(o) ((o)->u64 == U64x(3ff00000,00000000))
+#define rawnumequal(o1, o2) ((o1)->u64 == (o2)->u64)
+
+/* Macros to convert type ids. */
+#if LJ_64
+#define itypemap(o) \
+ (tvisnumber(o) ? ~LJ_TNUMX : tvislightud(o) ? ~LJ_TLIGHTUD : ~itype(o))
+#else
+#define itypemap(o) (tvisnumber(o) ? ~LJ_TNUMX : ~itype(o))
+#endif
+
+/* Macros to get tagged values. */
+#define gcval(o) (gcref((o)->gcr))
+#define boolV(o) check_exp(tvisbool(o), (LJ_TFALSE - (o)->it))
+#if LJ_64
+#define lightudV(o) \
+ check_exp(tvislightud(o), (void *)((o)->u64 & U64x(00007fff,ffffffff)))
+#else
+#define lightudV(o) check_exp(tvislightud(o), gcrefp((o)->gcr, void))
+#endif
+#define gcV(o) check_exp(tvisgcv(o), gcval(o))
+#define strV(o) check_exp(tvisstr(o), &gcval(o)->str)
+#define funcV(o) check_exp(tvisfunc(o), &gcval(o)->fn)
+#define threadV(o) check_exp(tvisthread(o), &gcval(o)->th)
+#define protoV(o) check_exp(tvisproto(o), &gcval(o)->pt)
+#define cdataV(o) check_exp(tviscdata(o), &gcval(o)->cd)
+#define tabV(o) check_exp(tvistab(o), &gcval(o)->tab)
+#define udataV(o) check_exp(tvisudata(o), &gcval(o)->ud)
+#define numV(o) check_exp(tvisnum(o), (o)->n)
+#define intV(o) check_exp(tvisint(o), (int32_t)(o)->i)
+
+/* Macros to set tagged values. */
+#define setitype(o, i) ((o)->it = (i))
+#define setnilV(o) ((o)->it = LJ_TNIL)
+#define setboolV(o, x) ((o)->it = LJ_TFALSE-(uint32_t)(x))
+
+static LJ_AINLINE void setlightudV(TValue *o, void *p)
+{
+#if LJ_64
+ o->u64 = (uint64_t)p | (((uint64_t)0xffff) << 48);
+#else
+ setgcrefp(o->gcr, p); setitype(o, LJ_TLIGHTUD);
+#endif
+}
+
+#if LJ_64
+#define checklightudptr(L, p) \
+ (((uint64_t)(p) >> 47) ? (lj_err_msg(L, LJ_ERR_BADLU), NULL) : (p))
+#define setcont(o, f) \
+ ((o)->u64 = (uint64_t)(void *)(f) - (uint64_t)lj_vm_asm_begin)
+#else
+#define checklightudptr(L, p) (p)
+#define setcont(o, f) setlightudV((o), (void *)(f))
+#endif
+
+#define tvchecklive(L, o) \
+ UNUSED(L), lua_assert(!tvisgcv(o) || \
+ ((~itype(o) == gcval(o)->gch.gct) && !isdead(G(L), gcval(o))))
+
+static LJ_AINLINE void setgcV(lua_State *L, TValue *o, GCobj *v, uint32_t itype)
+{
+ setgcref(o->gcr, v); setitype(o, itype); tvchecklive(L, o);
+}
+
+#define define_setV(name, type, tag) \
+static LJ_AINLINE void name(lua_State *L, TValue *o, type *v) \
+{ \
+ setgcV(L, o, obj2gco(v), tag); \
+}
+define_setV(setstrV, GCstr, LJ_TSTR)
+define_setV(setthreadV, lua_State, LJ_TTHREAD)
+define_setV(setprotoV, GCproto, LJ_TPROTO)
+define_setV(setfuncV, GCfunc, LJ_TFUNC)
+define_setV(setcdataV, GCcdata, LJ_TCDATA)
+define_setV(settabV, GCtab, LJ_TTAB)
+define_setV(setudataV, GCudata, LJ_TUDATA)
+
+#define setnumV(o, x) ((o)->n = (x))
+#define setnanV(o) ((o)->u64 = U64x(fff80000,00000000))
+#define setpinfV(o) ((o)->u64 = U64x(7ff00000,00000000))
+#define setminfV(o) ((o)->u64 = U64x(fff00000,00000000))
+
+static LJ_AINLINE void setintV(TValue *o, int32_t i)
+{
+#if LJ_DUALNUM
+ o->i = (uint32_t)i; setitype(o, LJ_TISNUM);
+#else
+ o->n = (lua_Number)i;
+#endif
+}
+
+static LJ_AINLINE void setint64V(TValue *o, int64_t i)
+{
+ if (LJ_DUALNUM && LJ_LIKELY(i == (int64_t)(int32_t)i))
+ setintV(o, (int32_t)i);
+ else
+ setnumV(o, (lua_Number)i);
+}
+
+#if LJ_64
+#define setintptrV(o, i) setint64V((o), (i))
+#else
+#define setintptrV(o, i) setintV((o), (i))
+#endif
+
+/* Copy tagged values. */
+static LJ_AINLINE void copyTV(lua_State *L, TValue *o1, const TValue *o2)
+{
+ *o1 = *o2; tvchecklive(L, o1);
+}
+
+/* -- Number to integer conversion ---------------------------------------- */
+
+#if LJ_SOFTFP
+LJ_ASMF int32_t lj_vm_tobit(double x);
+#endif
+
+static LJ_AINLINE int32_t lj_num2bit(lua_Number n)
+{
+#if LJ_SOFTFP
+ return lj_vm_tobit(n);
+#else
+ TValue o;
+ o.n = n + 6755399441055744.0; /* 2^52 + 2^51 */
+ return (int32_t)o.u32.lo;
+#endif
+}
+
+#if LJ_TARGET_X86 && !defined(__SSE2__)
+#define lj_num2int(n) lj_num2bit((n))
+#else
+#define lj_num2int(n) ((int32_t)(n))
+#endif
+
+/*
+** This must match the JIT backend behavior. In particular for archs
+** that don't have a common hardware instruction for this conversion.
+** Note that signed FP to unsigned int conversions have an undefined
+** result and should never be relied upon in portable FFI code.
+** See also: C99 or C11 standard, 6.3.1.4, footnote of (1).
+*/
+static LJ_AINLINE uint64_t lj_num2u64(lua_Number n)
+{
+#if LJ_TARGET_X86ORX64 || LJ_TARGET_MIPS
+ int64_t i = (int64_t)n;
+ if (i < 0) i = (int64_t)(n - 18446744073709551616.0);
+ return (uint64_t)i;
+#else
+ return (uint64_t)n;
+#endif
+}
+
+static LJ_AINLINE int32_t numberVint(cTValue *o)
+{
+ if (LJ_LIKELY(tvisint(o)))
+ return intV(o);
+ else
+ return lj_num2int(numV(o));
+}
+
+static LJ_AINLINE lua_Number numberVnum(cTValue *o)
+{
+ if (LJ_UNLIKELY(tvisint(o)))
+ return (lua_Number)intV(o);
+ else
+ return numV(o);
+}
+
+/* -- Miscellaneous object handling --------------------------------------- */
+
+/* Names and maps for internal and external object tags. */
+LJ_DATA const char *const lj_obj_typename[1+LUA_TCDATA+1];
+LJ_DATA const char *const lj_obj_itypename[~LJ_TNUMX+1];
+
+#define lj_typename(o) (lj_obj_itypename[itypemap(o)])
+
+/* Compare two objects without calling metamethods. */
+LJ_FUNC int lj_obj_equal(cTValue *o1, cTValue *o2);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_parse.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_parse.h
new file mode 100644
index 0000000..ceeab69
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_parse.h
@@ -0,0 +1,18 @@
+/*
+** Lua parser (source code -> bytecode).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_PARSE_H
+#define _LJ_PARSE_H
+
+#include "lj_obj.h"
+#include "lj_lex.h"
+
+LJ_FUNC GCproto *lj_parse(LexState *ls);
+LJ_FUNC GCstr *lj_parse_keepstr(LexState *ls, const char *str, size_t l);
+#if LJ_HASFFI
+LJ_FUNC void lj_parse_keepcdata(LexState *ls, TValue *tv, GCcdata *cd);
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_record.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_record.h
new file mode 100644
index 0000000..2bbbde5
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_record.h
@@ -0,0 +1,44 @@
+/*
+** Trace recorder (bytecode -> SSA IR).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_RECORD_H
+#define _LJ_RECORD_H
+
+#include "lj_obj.h"
+#include "lj_jit.h"
+
+#if LJ_HASJIT
+/* Context for recording an indexed load/store. */
+typedef struct RecordIndex {
+ TValue tabv; /* Runtime value of table (or indexed object). */
+ TValue keyv; /* Runtime value of key. */
+ TValue valv; /* Runtime value of stored value. */
+ TValue mobjv; /* Runtime value of metamethod object. */
+ GCtab *mtv; /* Runtime value of metatable object. */
+ cTValue *oldv; /* Runtime value of previously stored value. */
+ TRef tab; /* Table (or indexed object) reference. */
+ TRef key; /* Key reference. */
+ TRef val; /* Value reference for a store or 0 for a load. */
+ TRef mt; /* Metatable reference. */
+ TRef mobj; /* Metamethod object reference. */
+ int idxchain; /* Index indirections left or 0 for raw lookup. */
+} RecordIndex;
+
+LJ_FUNC int lj_record_objcmp(jit_State *J, TRef a, TRef b,
+ cTValue *av, cTValue *bv);
+LJ_FUNC TRef lj_record_constify(jit_State *J, cTValue *o);
+
+LJ_FUNC void lj_record_call(jit_State *J, BCReg func, ptrdiff_t nargs);
+LJ_FUNC void lj_record_tailcall(jit_State *J, BCReg func, ptrdiff_t nargs);
+LJ_FUNC void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults);
+
+LJ_FUNC int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm);
+LJ_FUNC TRef lj_record_idx(jit_State *J, RecordIndex *ix);
+
+LJ_FUNC void lj_record_ins(jit_State *J);
+LJ_FUNC void lj_record_setup(jit_State *J);
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_snap.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_snap.h
new file mode 100644
index 0000000..2c9ae3d
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_snap.h
@@ -0,0 +1,34 @@
+/*
+** Snapshot handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_SNAP_H
+#define _LJ_SNAP_H
+
+#include "lj_obj.h"
+#include "lj_jit.h"
+
+#if LJ_HASJIT
+LJ_FUNC void lj_snap_add(jit_State *J);
+LJ_FUNC void lj_snap_purge(jit_State *J);
+LJ_FUNC void lj_snap_shrink(jit_State *J);
+LJ_FUNC IRIns *lj_snap_regspmap(GCtrace *T, SnapNo snapno, IRIns *ir);
+LJ_FUNC void lj_snap_replay(jit_State *J, GCtrace *T);
+LJ_FUNC const BCIns *lj_snap_restore(jit_State *J, void *exptr);
+LJ_FUNC void lj_snap_grow_buf_(jit_State *J, MSize need);
+LJ_FUNC void lj_snap_grow_map_(jit_State *J, MSize need);
+
+static LJ_AINLINE void lj_snap_grow_buf(jit_State *J, MSize need)
+{
+ if (LJ_UNLIKELY(need > J->sizesnap)) lj_snap_grow_buf_(J, need);
+}
+
+static LJ_AINLINE void lj_snap_grow_map(jit_State *J, MSize need)
+{
+ if (LJ_UNLIKELY(need > J->sizesnapmap)) lj_snap_grow_map_(J, need);
+}
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_state.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_state.h
new file mode 100644
index 0000000..d5b476b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_state.h
@@ -0,0 +1,35 @@
+/*
+** State and stack handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_STATE_H
+#define _LJ_STATE_H
+
+#include "lj_obj.h"
+
+#define incr_top(L) \
+ (++L->top >= tvref(L->maxstack) && (lj_state_growstack1(L), 0))
+
+#define savestack(L, p) ((char *)(p) - mref(L->stack, char))
+#define restorestack(L, n) ((TValue *)(mref(L->stack, char) + (n)))
+
+LJ_FUNC void lj_state_relimitstack(lua_State *L);
+LJ_FUNC void lj_state_shrinkstack(lua_State *L, MSize used);
+LJ_FUNCA void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need);
+LJ_FUNC void LJ_FASTCALL lj_state_growstack1(lua_State *L);
+
+static LJ_AINLINE void lj_state_checkstack(lua_State *L, MSize need)
+{
+ if ((mref(L->maxstack, char) - (char *)L->top) <=
+ (ptrdiff_t)need*(ptrdiff_t)sizeof(TValue))
+ lj_state_growstack(L, need);
+}
+
+LJ_FUNC lua_State *lj_state_new(lua_State *L);
+LJ_FUNC void LJ_FASTCALL lj_state_free(global_State *g, lua_State *L);
+#if LJ_64
+LJ_FUNC lua_State *lj_state_newstate(lua_Alloc f, void *ud);
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_str.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_str.h
new file mode 100644
index 0000000..be04a97
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_str.h
@@ -0,0 +1,50 @@
+/*
+** String handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_STR_H
+#define _LJ_STR_H
+
+#include <stdarg.h>
+
+#include "lj_obj.h"
+
+/* String interning. */
+LJ_FUNC int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b);
+LJ_FUNC void lj_str_resize(lua_State *L, MSize newmask);
+LJ_FUNCA GCstr *lj_str_new(lua_State *L, const char *str, size_t len);
+LJ_FUNC void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s);
+
+#define lj_str_newz(L, s) (lj_str_new(L, s, strlen(s)))
+#define lj_str_newlit(L, s) (lj_str_new(L, "" s, sizeof(s)-1))
+
+/* Type conversions. */
+LJ_FUNC size_t LJ_FASTCALL lj_str_bufnum(char *s, cTValue *o);
+LJ_FUNC char * LJ_FASTCALL lj_str_bufint(char *p, int32_t k);
+LJ_FUNCA GCstr * LJ_FASTCALL lj_str_fromnum(lua_State *L, const lua_Number *np);
+LJ_FUNC GCstr * LJ_FASTCALL lj_str_fromint(lua_State *L, int32_t k);
+LJ_FUNCA GCstr * LJ_FASTCALL lj_str_fromnumber(lua_State *L, cTValue *o);
+
+#define LJ_STR_INTBUF (1+10)
+#define LJ_STR_NUMBUF LUAI_MAXNUMBER2STR
+
+/* String formatting. */
+LJ_FUNC const char *lj_str_pushvf(lua_State *L, const char *fmt, va_list argp);
+LJ_FUNC const char *lj_str_pushf(lua_State *L, const char *fmt, ...)
+#if defined(__GNUC__)
+ __attribute__ ((format (printf, 2, 3)))
+#endif
+ ;
+
+/* Resizable string buffers. Struct definition in lj_obj.h. */
+LJ_FUNC char *lj_str_needbuf(lua_State *L, SBuf *sb, MSize sz);
+
+#define lj_str_initbuf(sb) ((sb)->buf = NULL, (sb)->sz = 0)
+#define lj_str_resetbuf(sb) ((sb)->n = 0)
+#define lj_str_resizebuf(L, sb, size) \
+ ((sb)->buf = (char *)lj_mem_realloc(L, (sb)->buf, (sb)->sz, (size)), \
+ (sb)->sz = (size))
+#define lj_str_freebuf(g, sb) lj_mem_free(g, (void *)(sb)->buf, (sb)->sz)
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_strscan.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_strscan.h
new file mode 100644
index 0000000..6fb0dda
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_strscan.h
@@ -0,0 +1,39 @@
+/*
+** String scanning.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_STRSCAN_H
+#define _LJ_STRSCAN_H
+
+#include "lj_obj.h"
+
+/* Options for accepted/returned formats. */
+#define STRSCAN_OPT_TOINT 0x01 /* Convert to int32_t, if possible. */
+#define STRSCAN_OPT_TONUM 0x02 /* Always convert to double. */
+#define STRSCAN_OPT_IMAG 0x04
+#define STRSCAN_OPT_LL 0x08
+#define STRSCAN_OPT_C 0x10
+
+/* Returned format. */
+typedef enum {
+ STRSCAN_ERROR,
+ STRSCAN_NUM, STRSCAN_IMAG,
+ STRSCAN_INT, STRSCAN_U32, STRSCAN_I64, STRSCAN_U64,
+} StrScanFmt;
+
+LJ_FUNC StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt);
+LJ_FUNC int LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o);
+#if LJ_DUALNUM
+LJ_FUNC int LJ_FASTCALL lj_strscan_number(GCstr *str, TValue *o);
+#else
+#define lj_strscan_number(s, o) lj_strscan_num((s), (o))
+#endif
+
+/* Check for number or convert string to number/int in-place (!). */
+static LJ_AINLINE int lj_strscan_numberobj(TValue *o)
+{
+ return tvisnumber(o) || (tvisstr(o) && lj_strscan_number(strV(o), o));
+}
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_tab.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_tab.h
new file mode 100644
index 0000000..36ce7cd
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_tab.h
@@ -0,0 +1,70 @@
+/*
+** Table handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_TAB_H
+#define _LJ_TAB_H
+
+#include "lj_obj.h"
+
+/* Hash constants. Tuned using a brute force search. */
+#define HASH_BIAS (-0x04c11db7)
+#define HASH_ROT1 14
+#define HASH_ROT2 5
+#define HASH_ROT3 13
+
+/* Scramble the bits of numbers and pointers. */
+static LJ_AINLINE uint32_t hashrot(uint32_t lo, uint32_t hi)
+{
+#if LJ_TARGET_X86ORX64
+ /* Prefer variant that compiles well for a 2-operand CPU. */
+ lo ^= hi; hi = lj_rol(hi, HASH_ROT1);
+ lo -= hi; hi = lj_rol(hi, HASH_ROT2);
+ hi ^= lo; hi -= lj_rol(lo, HASH_ROT3);
+#else
+ lo ^= hi;
+ lo = lo - lj_rol(hi, HASH_ROT1);
+ hi = lo ^ lj_rol(hi, HASH_ROT1 + HASH_ROT2);
+ hi = hi - lj_rol(lo, HASH_ROT3);
+#endif
+ return hi;
+}
+
+#define hsize2hbits(s) ((s) ? ((s)==1 ? 1 : 1+lj_fls((uint32_t)((s)-1))) : 0)
+
+LJ_FUNCA GCtab *lj_tab_new(lua_State *L, uint32_t asize, uint32_t hbits);
+#if LJ_HASJIT
+LJ_FUNC GCtab * LJ_FASTCALL lj_tab_new1(lua_State *L, uint32_t ahsize);
+#endif
+LJ_FUNCA GCtab * LJ_FASTCALL lj_tab_dup(lua_State *L, const GCtab *kt);
+LJ_FUNC void LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t);
+#if LJ_HASFFI
+LJ_FUNC void lj_tab_rehash(lua_State *L, GCtab *t);
+#endif
+LJ_FUNCA void lj_tab_reasize(lua_State *L, GCtab *t, uint32_t nasize);
+
+/* Caveat: all getters except lj_tab_get() can return NULL! */
+
+LJ_FUNCA cTValue * LJ_FASTCALL lj_tab_getinth(GCtab *t, int32_t key);
+LJ_FUNC cTValue *lj_tab_getstr(GCtab *t, GCstr *key);
+LJ_FUNCA cTValue *lj_tab_get(lua_State *L, GCtab *t, cTValue *key);
+
+/* Caveat: all setters require a write barrier for the stored value. */
+
+LJ_FUNCA TValue *lj_tab_newkey(lua_State *L, GCtab *t, cTValue *key);
+LJ_FUNC TValue *lj_tab_setinth(lua_State *L, GCtab *t, int32_t key);
+LJ_FUNC TValue *lj_tab_setstr(lua_State *L, GCtab *t, GCstr *key);
+LJ_FUNC TValue *lj_tab_set(lua_State *L, GCtab *t, cTValue *key);
+
+#define inarray(t, key) ((MSize)(key) < (MSize)(t)->asize)
+#define arrayslot(t, i) (&tvref((t)->array)[(i)])
+#define lj_tab_getint(t, key) \
+ (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_getinth((t), (key)))
+#define lj_tab_setint(L, t, key) \
+ (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_setinth(L, (t), (key)))
+
+LJ_FUNCA int lj_tab_next(lua_State *L, GCtab *t, TValue *key);
+LJ_FUNCA MSize LJ_FASTCALL lj_tab_len(GCtab *t);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target.h
new file mode 100644
index 0000000..53bfa6b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target.h
@@ -0,0 +1,162 @@
+/*
+** Definitions for target CPU.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_TARGET_H
+#define _LJ_TARGET_H
+
+#include "lj_def.h"
+#include "lj_arch.h"
+
+/* -- Registers and spill slots ------------------------------------------- */
+
+/* Register type (uint8_t in ir->r). */
+typedef uint32_t Reg;
+
+/* The hi-bit is NOT set for an allocated register. This means the value
+** can be directly used without masking. The hi-bit is set for a register
+** allocation hint or for RID_INIT, RID_SINK or RID_SUNK.
+*/
+#define RID_NONE 0x80
+#define RID_MASK 0x7f
+#define RID_INIT (RID_NONE|RID_MASK)
+#define RID_SINK (RID_INIT-1)
+#define RID_SUNK (RID_INIT-2)
+
+#define ra_noreg(r) ((r) & RID_NONE)
+#define ra_hasreg(r) (!((r) & RID_NONE))
+
+/* The ra_hashint() macro assumes a previous test for ra_noreg(). */
+#define ra_hashint(r) ((r) < RID_SUNK)
+#define ra_gethint(r) ((Reg)((r) & RID_MASK))
+#define ra_sethint(rr, r) rr = (uint8_t)((r)|RID_NONE)
+#define ra_samehint(r1, r2) (ra_gethint((r1)^(r2)) == 0)
+
+/* Spill slot 0 means no spill slot has been allocated. */
+#define SPS_NONE 0
+
+#define ra_hasspill(s) ((s) != SPS_NONE)
+
+/* Combined register and spill slot (uint16_t in ir->prev). */
+typedef uint32_t RegSP;
+
+#define REGSP(r, s) ((r) + ((s) << 8))
+#define REGSP_HINT(r) ((r)|RID_NONE)
+#define REGSP_INIT REGSP(RID_INIT, 0)
+
+#define regsp_reg(rs) ((rs) & 255)
+#define regsp_spill(rs) ((rs) >> 8)
+#define regsp_used(rs) \
+ (((rs) & ~REGSP(RID_MASK, 0)) != REGSP(RID_NONE, 0))
+
+/* -- Register sets ------------------------------------------------------- */
+
+/* Bitset for registers. 32 registers suffice for most architectures.
+** Note that one set holds bits for both GPRs and FPRs.
+*/
+#if LJ_TARGET_PPC || LJ_TARGET_MIPS
+typedef uint64_t RegSet;
+#else
+typedef uint32_t RegSet;
+#endif
+
+#define RID2RSET(r) (((RegSet)1) << (r))
+#define RSET_EMPTY ((RegSet)0)
+#define RSET_RANGE(lo, hi) ((RID2RSET((hi)-(lo))-1) << (lo))
+
+#define rset_test(rs, r) ((int)((rs) >> (r)) & 1)
+#define rset_set(rs, r) (rs |= RID2RSET(r))
+#define rset_clear(rs, r) (rs &= ~RID2RSET(r))
+#define rset_exclude(rs, r) (rs & ~RID2RSET(r))
+#if LJ_TARGET_PPC || LJ_TARGET_MIPS
+#define rset_picktop(rs) ((Reg)(__builtin_clzll(rs)^63))
+#define rset_pickbot(rs) ((Reg)__builtin_ctzll(rs))
+#else
+#define rset_picktop(rs) ((Reg)lj_fls(rs))
+#define rset_pickbot(rs) ((Reg)lj_ffs(rs))
+#endif
+
+/* -- Register allocation cost -------------------------------------------- */
+
+/* The register allocation heuristic keeps track of the cost for allocating
+** a specific register:
+**
+** A free register (obviously) has a cost of 0 and a 1-bit in the free mask.
+**
+** An already allocated register has the (non-zero) IR reference in the lowest
+** bits and the result of a blended cost-model in the higher bits.
+**
+** The allocator first checks the free mask for a hit. Otherwise an (unrolled)
+** linear search for the minimum cost is used. The search doesn't need to
+** keep track of the position of the minimum, which makes it very fast.
+** The lowest bits of the minimum cost show the desired IR reference whose
+** register is the one to evict.
+**
+** Without the cost-model this degenerates to the standard heuristics for
+** (reverse) linear-scan register allocation. Since code generation is done
+** in reverse, a live interval extends from the last use to the first def.
+** For an SSA IR the IR reference is the first (and only) def and thus
+** trivially marks the end of the interval. The LSRA heuristics says to pick
+** the register whose live interval has the furthest extent, i.e. the lowest
+** IR reference in our case.
+**
+** A cost-model should take into account other factors, like spill-cost and
+** restore- or rematerialization-cost, which depend on the kind of instruction.
+** E.g. constants have zero spill costs, variant instructions have higher
+** costs than invariants and PHIs should preferably never be spilled.
+**
+** Here's a first cut at simple, but effective blended cost-model for R-LSRA:
+** - Due to careful design of the IR, constants already have lower IR
+** references than invariants and invariants have lower IR references
+** than variants.
+** - The cost in the upper 16 bits is the sum of the IR reference and a
+** weighted score. The score currently only takes into account whether
+** the IRT_ISPHI bit is set in the instruction type.
+** - The PHI weight is the minimum distance (in IR instructions) a PHI
+** reference has to be further apart from a non-PHI reference to be spilled.
+** - It should be a power of two (for speed) and must be between 2 and 32768.
+** Good values for the PHI weight seem to be between 40 and 150.
+** - Further study is required.
+*/
+#define REGCOST_PHI_WEIGHT 64
+
+/* Cost for allocating a specific register. */
+typedef uint32_t RegCost;
+
+/* Note: assumes 16 bit IRRef1. */
+#define REGCOST(cost, ref) ((RegCost)(ref) + ((RegCost)(cost) << 16))
+#define regcost_ref(rc) ((IRRef1)(rc))
+
+#define REGCOST_T(t) \
+ ((RegCost)((t)&IRT_ISPHI) * (((RegCost)(REGCOST_PHI_WEIGHT)<<16)/IRT_ISPHI))
+#define REGCOST_REF_T(ref, t) (REGCOST((ref), (ref)) + REGCOST_T((t)))
+
+/* -- Target-specific definitions ----------------------------------------- */
+
+#if LJ_TARGET_X86ORX64
+#include "lj_target_x86.h"
+#elif LJ_TARGET_ARM
+#include "lj_target_arm.h"
+#elif LJ_TARGET_PPC
+#include "lj_target_ppc.h"
+#elif LJ_TARGET_MIPS
+#include "lj_target_mips.h"
+#else
+#error "Missing include for target CPU"
+#endif
+
+#ifdef EXITSTUBS_PER_GROUP
+/* Return the address of an exit stub. */
+static LJ_AINLINE char *exitstub_addr_(char **group, uint32_t exitno)
+{
+ lua_assert(group[exitno / EXITSTUBS_PER_GROUP] != NULL);
+ return (char *)group[exitno / EXITSTUBS_PER_GROUP] +
+ EXITSTUB_SPACING*(exitno % EXITSTUBS_PER_GROUP);
+}
+/* Avoid dependence on lj_jit.h if only including lj_target.h. */
+#define exitstub_addr(J, exitno) \
+ ((MCode *)exitstub_addr_((char **)((J)->exitstubgroup), (exitno)))
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target_arm.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target_arm.h
new file mode 100644
index 0000000..d02cbf8
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target_arm.h
@@ -0,0 +1,274 @@
+/*
+** Definitions for ARM CPUs.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_TARGET_ARM_H
+#define _LJ_TARGET_ARM_H
+
+/* -- Registers IDs ------------------------------------------------------- */
+
+#define GPRDEF(_) \
+ _(R0) _(R1) _(R2) _(R3) _(R4) _(R5) _(R6) _(R7) \
+ _(R8) _(R9) _(R10) _(R11) _(R12) _(SP) _(LR) _(PC)
+#if LJ_SOFTFP
+#define FPRDEF(_)
+#else
+#define FPRDEF(_) \
+ _(D0) _(D1) _(D2) _(D3) _(D4) _(D5) _(D6) _(D7) \
+ _(D8) _(D9) _(D10) _(D11) _(D12) _(D13) _(D14) _(D15)
+#endif
+#define VRIDDEF(_)
+
+#define RIDENUM(name) RID_##name,
+
+enum {
+ GPRDEF(RIDENUM) /* General-purpose registers (GPRs). */
+ FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */
+ RID_MAX,
+ RID_TMP = RID_LR,
+
+ /* Calling conventions. */
+ RID_RET = RID_R0,
+ RID_RETLO = RID_R0,
+ RID_RETHI = RID_R1,
+#if LJ_SOFTFP
+ RID_FPRET = RID_R0,
+#else
+ RID_FPRET = RID_D0,
+#endif
+
+ /* These definitions must match with the *.dasc file(s): */
+ RID_BASE = RID_R9, /* Interpreter BASE. */
+ RID_LPC = RID_R6, /* Interpreter PC. */
+ RID_DISPATCH = RID_R7, /* Interpreter DISPATCH table. */
+ RID_LREG = RID_R8, /* Interpreter L. */
+
+ /* Register ranges [min, max) and number of registers. */
+ RID_MIN_GPR = RID_R0,
+ RID_MAX_GPR = RID_PC+1,
+ RID_MIN_FPR = RID_MAX_GPR,
+#if LJ_SOFTFP
+ RID_MAX_FPR = RID_MIN_FPR,
+#else
+ RID_MAX_FPR = RID_D15+1,
+#endif
+ RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,
+ RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR
+};
+
+#define RID_NUM_KREF RID_NUM_GPR
+#define RID_MIN_KREF RID_R0
+
+/* -- Register sets ------------------------------------------------------- */
+
+/* Make use of all registers, except sp, lr and pc. */
+#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_R12+1))
+#define RSET_GPREVEN \
+ (RID2RSET(RID_R0)|RID2RSET(RID_R2)|RID2RSET(RID_R4)|RID2RSET(RID_R6)| \
+ RID2RSET(RID_R8)|RID2RSET(RID_R10))
+#define RSET_GPRODD \
+ (RID2RSET(RID_R1)|RID2RSET(RID_R3)|RID2RSET(RID_R5)|RID2RSET(RID_R7)| \
+ RID2RSET(RID_R9)|RID2RSET(RID_R11))
+#if LJ_SOFTFP
+#define RSET_FPR 0
+#else
+#define RSET_FPR (RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR))
+#endif
+#define RSET_ALL (RSET_GPR|RSET_FPR)
+#define RSET_INIT RSET_ALL
+
+/* ABI-specific register sets. lr is an implicit scratch register. */
+#define RSET_SCRATCH_GPR_ (RSET_RANGE(RID_R0, RID_R3+1)|RID2RSET(RID_R12))
+#ifdef __APPLE__
+#define RSET_SCRATCH_GPR (RSET_SCRATCH_GPR_|RID2RSET(RID_R9))
+#else
+#define RSET_SCRATCH_GPR RSET_SCRATCH_GPR_
+#endif
+#if LJ_SOFTFP
+#define RSET_SCRATCH_FPR 0
+#else
+#define RSET_SCRATCH_FPR (RSET_RANGE(RID_D0, RID_D7+1))
+#endif
+#define RSET_SCRATCH (RSET_SCRATCH_GPR|RSET_SCRATCH_FPR)
+#define REGARG_FIRSTGPR RID_R0
+#define REGARG_LASTGPR RID_R3
+#define REGARG_NUMGPR 4
+#if LJ_ABI_SOFTFP
+#define REGARG_FIRSTFPR 0
+#define REGARG_LASTFPR 0
+#define REGARG_NUMFPR 0
+#else
+#define REGARG_FIRSTFPR RID_D0
+#define REGARG_LASTFPR RID_D7
+#define REGARG_NUMFPR 8
+#endif
+
+/* -- Spill slots --------------------------------------------------------- */
+
+/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.
+**
+** SPS_FIXED: Available fixed spill slots in interpreter frame.
+** This definition must match with the *.dasc file(s).
+**
+** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots.
+*/
+#define SPS_FIXED 2
+#define SPS_FIRST 2
+
+#define SPOFS_TMP 0
+
+#define sps_scale(slot) (4 * (int32_t)(slot))
+#define sps_align(slot) (((slot) - SPS_FIXED + 1) & ~1)
+
+/* -- Exit state ---------------------------------------------------------- */
+
+/* This definition must match with the *.dasc file(s). */
+typedef struct {
+#if !LJ_SOFTFP
+ lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */
+#endif
+ int32_t gpr[RID_NUM_GPR]; /* General-purpose registers. */
+ int32_t spill[256]; /* Spill slots. */
+} ExitState;
+
+/* PC after instruction that caused an exit. Used to find the trace number. */
+#define EXITSTATE_PCREG RID_PC
+/* Highest exit + 1 indicates stack check. */
+#define EXITSTATE_CHECKEXIT 1
+
+#define EXITSTUB_SPACING 4
+#define EXITSTUBS_PER_GROUP 32
+
+/* -- Instructions -------------------------------------------------------- */
+
+/* Instruction fields. */
+#define ARMF_CC(ai, cc) (((ai) ^ ARMI_CCAL) | ((cc) << 28))
+#define ARMF_N(r) ((r) << 16)
+#define ARMF_D(r) ((r) << 12)
+#define ARMF_S(r) ((r) << 8)
+#define ARMF_M(r) (r)
+#define ARMF_SH(sh, n) (((sh) << 5) | ((n) << 7))
+#define ARMF_RSH(sh, r) (0x10 | ((sh) << 5) | ARMF_S(r))
+
+typedef enum ARMIns {
+ ARMI_CCAL = 0xe0000000,
+ ARMI_S = 0x000100000,
+ ARMI_K12 = 0x02000000,
+ ARMI_KNEG = 0x00200000,
+ ARMI_LS_W = 0x00200000,
+ ARMI_LS_U = 0x00800000,
+ ARMI_LS_P = 0x01000000,
+ ARMI_LS_R = 0x02000000,
+ ARMI_LSX_I = 0x00400000,
+
+ ARMI_AND = 0xe0000000,
+ ARMI_EOR = 0xe0200000,
+ ARMI_SUB = 0xe0400000,
+ ARMI_RSB = 0xe0600000,
+ ARMI_ADD = 0xe0800000,
+ ARMI_ADC = 0xe0a00000,
+ ARMI_SBC = 0xe0c00000,
+ ARMI_RSC = 0xe0e00000,
+ ARMI_TST = 0xe1100000,
+ ARMI_TEQ = 0xe1300000,
+ ARMI_CMP = 0xe1500000,
+ ARMI_CMN = 0xe1700000,
+ ARMI_ORR = 0xe1800000,
+ ARMI_MOV = 0xe1a00000,
+ ARMI_BIC = 0xe1c00000,
+ ARMI_MVN = 0xe1e00000,
+
+ ARMI_NOP = 0xe1a00000,
+
+ ARMI_MUL = 0xe0000090,
+ ARMI_SMULL = 0xe0c00090,
+
+ ARMI_LDR = 0xe4100000,
+ ARMI_LDRB = 0xe4500000,
+ ARMI_LDRH = 0xe01000b0,
+ ARMI_LDRSB = 0xe01000d0,
+ ARMI_LDRSH = 0xe01000f0,
+ ARMI_LDRD = 0xe00000d0,
+ ARMI_STR = 0xe4000000,
+ ARMI_STRB = 0xe4400000,
+ ARMI_STRH = 0xe00000b0,
+ ARMI_STRD = 0xe00000f0,
+ ARMI_PUSH = 0xe92d0000,
+
+ ARMI_B = 0xea000000,
+ ARMI_BL = 0xeb000000,
+ ARMI_BLX = 0xfa000000,
+ ARMI_BLXr = 0xe12fff30,
+
+ /* ARMv6 */
+ ARMI_REV = 0xe6bf0f30,
+ ARMI_SXTB = 0xe6af0070,
+ ARMI_SXTH = 0xe6bf0070,
+ ARMI_UXTB = 0xe6ef0070,
+ ARMI_UXTH = 0xe6ff0070,
+
+ /* ARMv6T2 */
+ ARMI_MOVW = 0xe3000000,
+ ARMI_MOVT = 0xe3400000,
+
+ /* VFP */
+ ARMI_VMOV_D = 0xeeb00b40,
+ ARMI_VMOV_S = 0xeeb00a40,
+ ARMI_VMOVI_D = 0xeeb00b00,
+
+ ARMI_VMOV_R_S = 0xee100a10,
+ ARMI_VMOV_S_R = 0xee000a10,
+ ARMI_VMOV_RR_D = 0xec500b10,
+ ARMI_VMOV_D_RR = 0xec400b10,
+
+ ARMI_VADD_D = 0xee300b00,
+ ARMI_VSUB_D = 0xee300b40,
+ ARMI_VMUL_D = 0xee200b00,
+ ARMI_VMLA_D = 0xee000b00,
+ ARMI_VMLS_D = 0xee000b40,
+ ARMI_VNMLS_D = 0xee100b00,
+ ARMI_VDIV_D = 0xee800b00,
+
+ ARMI_VABS_D = 0xeeb00bc0,
+ ARMI_VNEG_D = 0xeeb10b40,
+ ARMI_VSQRT_D = 0xeeb10bc0,
+
+ ARMI_VCMP_D = 0xeeb40b40,
+ ARMI_VCMPZ_D = 0xeeb50b40,
+
+ ARMI_VMRS = 0xeef1fa10,
+
+ ARMI_VCVT_S32_F32 = 0xeebd0ac0,
+ ARMI_VCVT_S32_F64 = 0xeebd0bc0,
+ ARMI_VCVT_U32_F32 = 0xeebc0ac0,
+ ARMI_VCVT_U32_F64 = 0xeebc0bc0,
+ ARMI_VCVTR_S32_F32 = 0xeebd0a40,
+ ARMI_VCVTR_S32_F64 = 0xeebd0b40,
+ ARMI_VCVTR_U32_F32 = 0xeebc0a40,
+ ARMI_VCVTR_U32_F64 = 0xeebc0b40,
+ ARMI_VCVT_F32_S32 = 0xeeb80ac0,
+ ARMI_VCVT_F64_S32 = 0xeeb80bc0,
+ ARMI_VCVT_F32_U32 = 0xeeb80a40,
+ ARMI_VCVT_F64_U32 = 0xeeb80b40,
+ ARMI_VCVT_F32_F64 = 0xeeb70bc0,
+ ARMI_VCVT_F64_F32 = 0xeeb70ac0,
+
+ ARMI_VLDR_S = 0xed100a00,
+ ARMI_VLDR_D = 0xed100b00,
+ ARMI_VSTR_S = 0xed000a00,
+ ARMI_VSTR_D = 0xed000b00,
+} ARMIns;
+
+typedef enum ARMShift {
+ ARMSH_LSL, ARMSH_LSR, ARMSH_ASR, ARMSH_ROR
+} ARMShift;
+
+/* ARM condition codes. */
+typedef enum ARMCC {
+ CC_EQ, CC_NE, CC_CS, CC_CC, CC_MI, CC_PL, CC_VS, CC_VC,
+ CC_HI, CC_LS, CC_GE, CC_LT, CC_GT, CC_LE, CC_AL,
+ CC_HS = CC_CS, CC_LO = CC_CC
+} ARMCC;
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target_mips.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target_mips.h
new file mode 100644
index 0000000..bed174b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target_mips.h
@@ -0,0 +1,258 @@
+/*
+** Definitions for MIPS CPUs.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_TARGET_MIPS_H
+#define _LJ_TARGET_MIPS_H
+
+/* -- Registers IDs ------------------------------------------------------- */
+
+#define GPRDEF(_) \
+ _(R0) _(R1) _(R2) _(R3) _(R4) _(R5) _(R6) _(R7) \
+ _(R8) _(R9) _(R10) _(R11) _(R12) _(R13) _(R14) _(R15) \
+ _(R16) _(R17) _(R18) _(R19) _(R20) _(R21) _(R22) _(R23) \
+ _(R24) _(R25) _(SYS1) _(SYS2) _(R28) _(SP) _(R30) _(RA)
+#define FPRDEF(_) \
+ _(F0) _(F1) _(F2) _(F3) _(F4) _(F5) _(F6) _(F7) \
+ _(F8) _(F9) _(F10) _(F11) _(F12) _(F13) _(F14) _(F15) \
+ _(F16) _(F17) _(F18) _(F19) _(F20) _(F21) _(F22) _(F23) \
+ _(F24) _(F25) _(F26) _(F27) _(F28) _(F29) _(F30) _(F31)
+#define VRIDDEF(_)
+
+#define RIDENUM(name) RID_##name,
+
+enum {
+ GPRDEF(RIDENUM) /* General-purpose registers (GPRs). */
+ FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */
+ RID_MAX,
+ RID_ZERO = RID_R0,
+ RID_TMP = RID_RA,
+ RID_GP = RID_R28,
+
+ /* Calling conventions. */
+ RID_RET = RID_R2,
+#if LJ_LE
+ RID_RETHI = RID_R3,
+ RID_RETLO = RID_R2,
+#else
+ RID_RETHI = RID_R2,
+ RID_RETLO = RID_R3,
+#endif
+ RID_FPRET = RID_F0,
+ RID_CFUNCADDR = RID_R25,
+
+ /* These definitions must match with the *.dasc file(s): */
+ RID_BASE = RID_R16, /* Interpreter BASE. */
+ RID_LPC = RID_R18, /* Interpreter PC. */
+ RID_DISPATCH = RID_R19, /* Interpreter DISPATCH table. */
+ RID_LREG = RID_R20, /* Interpreter L. */
+ RID_JGL = RID_R30, /* On-trace: global_State + 32768. */
+
+ /* Register ranges [min, max) and number of registers. */
+ RID_MIN_GPR = RID_R0,
+ RID_MAX_GPR = RID_RA+1,
+ RID_MIN_FPR = RID_F0,
+ RID_MAX_FPR = RID_F31+1,
+ RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,
+ RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR /* Only even regs are used. */
+};
+
+#define RID_NUM_KREF RID_NUM_GPR
+#define RID_MIN_KREF RID_R0
+
+/* -- Register sets ------------------------------------------------------- */
+
+/* Make use of all registers, except ZERO, TMP, SP, SYS1, SYS2, JGL and GP. */
+#define RSET_FIXED \
+ (RID2RSET(RID_ZERO)|RID2RSET(RID_TMP)|RID2RSET(RID_SP)|\
+ RID2RSET(RID_SYS1)|RID2RSET(RID_SYS2)|RID2RSET(RID_JGL)|RID2RSET(RID_GP))
+#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) - RSET_FIXED)
+#define RSET_FPR \
+ (RID2RSET(RID_F0)|RID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(RID_F6)|\
+ RID2RSET(RID_F8)|RID2RSET(RID_F10)|RID2RSET(RID_F12)|RID2RSET(RID_F14)|\
+ RID2RSET(RID_F16)|RID2RSET(RID_F18)|RID2RSET(RID_F20)|RID2RSET(RID_F22)|\
+ RID2RSET(RID_F24)|RID2RSET(RID_F26)|RID2RSET(RID_F28)|RID2RSET(RID_F30))
+#define RSET_ALL (RSET_GPR|RSET_FPR)
+#define RSET_INIT RSET_ALL
+
+#define RSET_SCRATCH_GPR \
+ (RSET_RANGE(RID_R1, RID_R15+1)|\
+ RID2RSET(RID_R24)|RID2RSET(RID_R25))
+#define RSET_SCRATCH_FPR \
+ (RID2RSET(RID_F0)|RID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(RID_F6)|\
+ RID2RSET(RID_F8)|RID2RSET(RID_F10)|RID2RSET(RID_F12)|RID2RSET(RID_F14)|\
+ RID2RSET(RID_F16)|RID2RSET(RID_F18))
+#define RSET_SCRATCH (RSET_SCRATCH_GPR|RSET_SCRATCH_FPR)
+#define REGARG_FIRSTGPR RID_R4
+#define REGARG_LASTGPR RID_R7
+#define REGARG_NUMGPR 4
+#define REGARG_FIRSTFPR RID_F12
+#define REGARG_LASTFPR RID_F14
+#define REGARG_NUMFPR 2
+
+/* -- Spill slots --------------------------------------------------------- */
+
+/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.
+**
+** SPS_FIXED: Available fixed spill slots in interpreter frame.
+** This definition must match with the *.dasc file(s).
+**
+** SPS_FIRST: First spill slot for general use.
+*/
+#define SPS_FIXED 5
+#define SPS_FIRST 4
+
+#define SPOFS_TMP 0
+
+#define sps_scale(slot) (4 * (int32_t)(slot))
+#define sps_align(slot) (((slot) - SPS_FIXED + 1) & ~1)
+
+/* -- Exit state ---------------------------------------------------------- */
+
+/* This definition must match with the *.dasc file(s). */
+typedef struct {
+ lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */
+ int32_t gpr[RID_NUM_GPR]; /* General-purpose registers. */
+ int32_t spill[256]; /* Spill slots. */
+} ExitState;
+
+/* Highest exit + 1 indicates stack check. */
+#define EXITSTATE_CHECKEXIT 1
+
+/* Return the address of a per-trace exit stub. */
+static LJ_AINLINE uint32_t *exitstub_trace_addr_(uint32_t *p)
+{
+ while (*p == 0x00000000) p++; /* Skip MIPSI_NOP. */
+ return p;
+}
+/* Avoid dependence on lj_jit.h if only including lj_target.h. */
+#define exitstub_trace_addr(T, exitno) \
+ exitstub_trace_addr_((MCode *)((char *)(T)->mcode + (T)->szmcode))
+
+/* -- Instructions -------------------------------------------------------- */
+
+/* Instruction fields. */
+#define MIPSF_S(r) ((r) << 21)
+#define MIPSF_T(r) ((r) << 16)
+#define MIPSF_D(r) ((r) << 11)
+#define MIPSF_R(r) ((r) << 21)
+#define MIPSF_H(r) ((r) << 16)
+#define MIPSF_G(r) ((r) << 11)
+#define MIPSF_F(r) ((r) << 6)
+#define MIPSF_A(n) ((n) << 6)
+#define MIPSF_M(n) ((n) << 11)
+
+typedef enum MIPSIns {
+ /* Integer instructions. */
+ MIPSI_MOVE = 0x00000021,
+ MIPSI_NOP = 0x00000000,
+
+ MIPSI_LI = 0x24000000,
+ MIPSI_LU = 0x34000000,
+ MIPSI_LUI = 0x3c000000,
+
+ MIPSI_ADDIU = 0x24000000,
+ MIPSI_ANDI = 0x30000000,
+ MIPSI_ORI = 0x34000000,
+ MIPSI_XORI = 0x38000000,
+ MIPSI_SLTI = 0x28000000,
+ MIPSI_SLTIU = 0x2c000000,
+
+ MIPSI_ADDU = 0x00000021,
+ MIPSI_SUBU = 0x00000023,
+ MIPSI_MUL = 0x70000002,
+ MIPSI_AND = 0x00000024,
+ MIPSI_OR = 0x00000025,
+ MIPSI_XOR = 0x00000026,
+ MIPSI_NOR = 0x00000027,
+ MIPSI_SLT = 0x0000002a,
+ MIPSI_SLTU = 0x0000002b,
+ MIPSI_MOVZ = 0x0000000a,
+ MIPSI_MOVN = 0x0000000b,
+
+ MIPSI_SLL = 0x00000000,
+ MIPSI_SRL = 0x00000002,
+ MIPSI_SRA = 0x00000003,
+ MIPSI_ROTR = 0x00200002, /* MIPS32R2 */
+ MIPSI_SLLV = 0x00000004,
+ MIPSI_SRLV = 0x00000006,
+ MIPSI_SRAV = 0x00000007,
+ MIPSI_ROTRV = 0x00000046, /* MIPS32R2 */
+
+ MIPSI_SEB = 0x7c000420, /* MIPS32R2 */
+ MIPSI_SEH = 0x7c000620, /* MIPS32R2 */
+ MIPSI_WSBH = 0x7c0000a0, /* MIPS32R2 */
+
+ MIPSI_B = 0x10000000,
+ MIPSI_J = 0x08000000,
+ MIPSI_JAL = 0x0c000000,
+ MIPSI_JR = 0x00000008,
+ MIPSI_JALR = 0x0000f809,
+
+ MIPSI_BEQ = 0x10000000,
+ MIPSI_BNE = 0x14000000,
+ MIPSI_BLEZ = 0x18000000,
+ MIPSI_BGTZ = 0x1c000000,
+ MIPSI_BLTZ = 0x04000000,
+ MIPSI_BGEZ = 0x04010000,
+
+ /* Load/store instructions. */
+ MIPSI_LW = 0x8c000000,
+ MIPSI_SW = 0xac000000,
+ MIPSI_LB = 0x80000000,
+ MIPSI_SB = 0xa0000000,
+ MIPSI_LH = 0x84000000,
+ MIPSI_SH = 0xa4000000,
+ MIPSI_LBU = 0x90000000,
+ MIPSI_LHU = 0x94000000,
+ MIPSI_LWC1 = 0xc4000000,
+ MIPSI_SWC1 = 0xe4000000,
+ MIPSI_LDC1 = 0xd4000000,
+ MIPSI_SDC1 = 0xf4000000,
+
+ /* FP instructions. */
+ MIPSI_MOV_S = 0x46000006,
+ MIPSI_MOV_D = 0x46200006,
+ MIPSI_MOVT_D = 0x46210011,
+ MIPSI_MOVF_D = 0x46200011,
+
+ MIPSI_ABS_D = 0x46200005,
+ MIPSI_NEG_D = 0x46200007,
+
+ MIPSI_ADD_D = 0x46200000,
+ MIPSI_SUB_D = 0x46200001,
+ MIPSI_MUL_D = 0x46200002,
+ MIPSI_DIV_D = 0x46200003,
+ MIPSI_SQRT_D = 0x46200004,
+
+ MIPSI_ADD_S = 0x46000000,
+ MIPSI_SUB_S = 0x46000001,
+
+ MIPSI_CVT_D_S = 0x46000021,
+ MIPSI_CVT_W_S = 0x46000024,
+ MIPSI_CVT_S_D = 0x46200020,
+ MIPSI_CVT_W_D = 0x46200024,
+ MIPSI_CVT_S_W = 0x46800020,
+ MIPSI_CVT_D_W = 0x46800021,
+
+ MIPSI_TRUNC_W_S = 0x4600000d,
+ MIPSI_TRUNC_W_D = 0x4620000d,
+ MIPSI_FLOOR_W_S = 0x4600000f,
+ MIPSI_FLOOR_W_D = 0x4620000f,
+
+ MIPSI_MFC1 = 0x44000000,
+ MIPSI_MTC1 = 0x44800000,
+
+ MIPSI_BC1F = 0x45000000,
+ MIPSI_BC1T = 0x45010000,
+
+ MIPSI_C_EQ_D = 0x46200032,
+ MIPSI_C_OLT_D = 0x46200034,
+ MIPSI_C_ULT_D = 0x46200035,
+ MIPSI_C_OLE_D = 0x46200036,
+ MIPSI_C_ULE_D = 0x46200037,
+
+} MIPSIns;
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target_ppc.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target_ppc.h
new file mode 100644
index 0000000..e57e27d
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target_ppc.h
@@ -0,0 +1,280 @@
+/*
+** Definitions for PPC CPUs.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_TARGET_PPC_H
+#define _LJ_TARGET_PPC_H
+
+/* -- Registers IDs ------------------------------------------------------- */
+
+#define GPRDEF(_) \
+ _(R0) _(SP) _(SYS1) _(R3) _(R4) _(R5) _(R6) _(R7) \
+ _(R8) _(R9) _(R10) _(R11) _(R12) _(SYS2) _(R14) _(R15) \
+ _(R16) _(R17) _(R18) _(R19) _(R20) _(R21) _(R22) _(R23) \
+ _(R24) _(R25) _(R26) _(R27) _(R28) _(R29) _(R30) _(R31)
+#define FPRDEF(_) \
+ _(F0) _(F1) _(F2) _(F3) _(F4) _(F5) _(F6) _(F7) \
+ _(F8) _(F9) _(F10) _(F11) _(F12) _(F13) _(F14) _(F15) \
+ _(F16) _(F17) _(F18) _(F19) _(F20) _(F21) _(F22) _(F23) \
+ _(F24) _(F25) _(F26) _(F27) _(F28) _(F29) _(F30) _(F31)
+#define VRIDDEF(_)
+
+#define RIDENUM(name) RID_##name,
+
+enum {
+ GPRDEF(RIDENUM) /* General-purpose registers (GPRs). */
+ FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */
+ RID_MAX,
+ RID_TMP = RID_R0,
+
+ /* Calling conventions. */
+ RID_RET = RID_R3,
+ RID_RETHI = RID_R3,
+ RID_RETLO = RID_R4,
+ RID_FPRET = RID_F1,
+
+ /* These definitions must match with the *.dasc file(s): */
+ RID_BASE = RID_R14, /* Interpreter BASE. */
+ RID_LPC = RID_R16, /* Interpreter PC. */
+ RID_DISPATCH = RID_R17, /* Interpreter DISPATCH table. */
+ RID_LREG = RID_R18, /* Interpreter L. */
+ RID_JGL = RID_R31, /* On-trace: global_State + 32768. */
+
+ /* Register ranges [min, max) and number of registers. */
+ RID_MIN_GPR = RID_R0,
+ RID_MAX_GPR = RID_R31+1,
+ RID_MIN_FPR = RID_F0,
+ RID_MAX_FPR = RID_F31+1,
+ RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,
+ RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR
+};
+
+#define RID_NUM_KREF RID_NUM_GPR
+#define RID_MIN_KREF RID_R0
+
+/* -- Register sets ------------------------------------------------------- */
+
+/* Make use of all registers, except TMP, SP, SYS1, SYS2 and JGL. */
+#define RSET_FIXED \
+ (RID2RSET(RID_TMP)|RID2RSET(RID_SP)|RID2RSET(RID_SYS1)|\
+ RID2RSET(RID_SYS2)|RID2RSET(RID_JGL))
+#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) - RSET_FIXED)
+#define RSET_FPR RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR)
+#define RSET_ALL (RSET_GPR|RSET_FPR)
+#define RSET_INIT RSET_ALL
+
+#define RSET_SCRATCH_GPR (RSET_RANGE(RID_R3, RID_R12+1))
+#define RSET_SCRATCH_FPR (RSET_RANGE(RID_F0, RID_F13+1))
+#define RSET_SCRATCH (RSET_SCRATCH_GPR|RSET_SCRATCH_FPR)
+#define REGARG_FIRSTGPR RID_R3
+#define REGARG_LASTGPR RID_R10
+#define REGARG_NUMGPR 8
+#define REGARG_FIRSTFPR RID_F1
+#define REGARG_LASTFPR RID_F8
+#define REGARG_NUMFPR 8
+
+/* -- Spill slots --------------------------------------------------------- */
+
+/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.
+**
+** SPS_FIXED: Available fixed spill slots in interpreter frame.
+** This definition must match with the *.dasc file(s).
+**
+** SPS_FIRST: First spill slot for general use.
+** [sp+12] tmplo word \
+** [sp+ 8] tmphi word / tmp dword, parameter area for callee
+** [sp+ 4] tmpw, LR of callee
+** [sp+ 0] stack chain
+*/
+#define SPS_FIXED 7
+#define SPS_FIRST 4
+
+/* Stack offsets for temporary slots. Used for FP<->int conversions etc. */
+#define SPOFS_TMPW 4
+#define SPOFS_TMP 8
+#define SPOFS_TMPHI 8
+#define SPOFS_TMPLO 12
+
+#define sps_scale(slot) (4 * (int32_t)(slot))
+#define sps_align(slot) (((slot) - SPS_FIXED + 3) & ~3)
+
+/* -- Exit state ---------------------------------------------------------- */
+
+/* This definition must match with the *.dasc file(s). */
+typedef struct {
+ lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */
+ int32_t gpr[RID_NUM_GPR]; /* General-purpose registers. */
+ int32_t spill[256]; /* Spill slots. */
+} ExitState;
+
+/* Highest exit + 1 indicates stack check. */
+#define EXITSTATE_CHECKEXIT 1
+
+/* Return the address of a per-trace exit stub. */
+static LJ_AINLINE uint32_t *exitstub_trace_addr_(uint32_t *p, uint32_t exitno)
+{
+ while (*p == 0x60000000) p++; /* Skip PPCI_NOP. */
+ return p + 3 + exitno;
+}
+/* Avoid dependence on lj_jit.h if only including lj_target.h. */
+#define exitstub_trace_addr(T, exitno) \
+ exitstub_trace_addr_((MCode *)((char *)(T)->mcode + (T)->szmcode), (exitno))
+
+/* -- Instructions -------------------------------------------------------- */
+
+/* Instruction fields. */
+#define PPCF_CC(cc) ((((cc) & 3) << 16) | (((cc) & 4) << 22))
+#define PPCF_T(r) ((r) << 21)
+#define PPCF_A(r) ((r) << 16)
+#define PPCF_B(r) ((r) << 11)
+#define PPCF_C(r) ((r) << 6)
+#define PPCF_MB(n) ((n) << 6)
+#define PPCF_ME(n) ((n) << 1)
+#define PPCF_Y 0x00200000
+#define PPCF_DOT 0x00000001
+
+typedef enum PPCIns {
+ /* Integer instructions. */
+ PPCI_MR = 0x7c000378,
+ PPCI_NOP = 0x60000000,
+
+ PPCI_LI = 0x38000000,
+ PPCI_LIS = 0x3c000000,
+
+ PPCI_ADD = 0x7c000214,
+ PPCI_ADDC = 0x7c000014,
+ PPCI_ADDO = 0x7c000614,
+ PPCI_ADDE = 0x7c000114,
+ PPCI_ADDZE = 0x7c000194,
+ PPCI_ADDME = 0x7c0001d4,
+ PPCI_ADDI = 0x38000000,
+ PPCI_ADDIS = 0x3c000000,
+ PPCI_ADDIC = 0x30000000,
+ PPCI_ADDICDOT = 0x34000000,
+
+ PPCI_SUBF = 0x7c000050,
+ PPCI_SUBFC = 0x7c000010,
+ PPCI_SUBFO = 0x7c000450,
+ PPCI_SUBFE = 0x7c000110,
+ PPCI_SUBFZE = 0x7c000190,
+ PPCI_SUBFME = 0x7c0001d0,
+ PPCI_SUBFIC = 0x20000000,
+
+ PPCI_NEG = 0x7c0000d0,
+
+ PPCI_AND = 0x7c000038,
+ PPCI_ANDC = 0x7c000078,
+ PPCI_NAND = 0x7c0003b8,
+ PPCI_ANDIDOT = 0x70000000,
+ PPCI_ANDISDOT = 0x74000000,
+
+ PPCI_OR = 0x7c000378,
+ PPCI_NOR = 0x7c0000f8,
+ PPCI_ORI = 0x60000000,
+ PPCI_ORIS = 0x64000000,
+
+ PPCI_XOR = 0x7c000278,
+ PPCI_EQV = 0x7c000238,
+ PPCI_XORI = 0x68000000,
+ PPCI_XORIS = 0x6c000000,
+
+ PPCI_CMPW = 0x7c000000,
+ PPCI_CMPLW = 0x7c000040,
+ PPCI_CMPWI = 0x2c000000,
+ PPCI_CMPLWI = 0x28000000,
+
+ PPCI_MULLW = 0x7c0001d6,
+ PPCI_MULLI = 0x1c000000,
+ PPCI_MULLWO = 0x7c0005d6,
+
+ PPCI_EXTSB = 0x7c000774,
+ PPCI_EXTSH = 0x7c000734,
+
+ PPCI_SLW = 0x7c000030,
+ PPCI_SRW = 0x7c000430,
+ PPCI_SRAW = 0x7c000630,
+ PPCI_SRAWI = 0x7c000670,
+
+ PPCI_RLWNM = 0x5c000000,
+ PPCI_RLWINM = 0x54000000,
+ PPCI_RLWIMI = 0x50000000,
+
+ PPCI_B = 0x48000000,
+ PPCI_BL = 0x48000001,
+ PPCI_BC = 0x40800000,
+ PPCI_BCL = 0x40800001,
+ PPCI_BCTR = 0x4e800420,
+ PPCI_BCTRL = 0x4e800421,
+
+ PPCI_CRANDC = 0x4c000102,
+ PPCI_CRXOR = 0x4c000182,
+ PPCI_CRAND = 0x4c000202,
+ PPCI_CREQV = 0x4c000242,
+ PPCI_CRORC = 0x4c000342,
+ PPCI_CROR = 0x4c000382,
+
+ PPCI_MFLR = 0x7c0802a6,
+ PPCI_MTCTR = 0x7c0903a6,
+
+ PPCI_MCRXR = 0x7c000400,
+
+ /* Load/store instructions. */
+ PPCI_LWZ = 0x80000000,
+ PPCI_LBZ = 0x88000000,
+ PPCI_STW = 0x90000000,
+ PPCI_STB = 0x98000000,
+ PPCI_LHZ = 0xa0000000,
+ PPCI_LHA = 0xa8000000,
+ PPCI_STH = 0xb0000000,
+
+ PPCI_STWU = 0x94000000,
+
+ PPCI_LFS = 0xc0000000,
+ PPCI_LFD = 0xc8000000,
+ PPCI_STFS = 0xd0000000,
+ PPCI_STFD = 0xd8000000,
+
+ PPCI_LWZX = 0x7c00002e,
+ PPCI_LBZX = 0x7c0000ae,
+ PPCI_STWX = 0x7c00012e,
+ PPCI_STBX = 0x7c0001ae,
+ PPCI_LHZX = 0x7c00022e,
+ PPCI_LHAX = 0x7c0002ae,
+ PPCI_STHX = 0x7c00032e,
+
+ PPCI_LWBRX = 0x7c00042c,
+ PPCI_STWBRX = 0x7c00052c,
+
+ PPCI_LFSX = 0x7c00042e,
+ PPCI_LFDX = 0x7c0004ae,
+ PPCI_STFSX = 0x7c00052e,
+ PPCI_STFDX = 0x7c0005ae,
+
+ /* FP instructions. */
+ PPCI_FMR = 0xfc000090,
+ PPCI_FNEG = 0xfc000050,
+ PPCI_FABS = 0xfc000210,
+
+ PPCI_FRSP = 0xfc000018,
+ PPCI_FCTIWZ = 0xfc00001e,
+
+ PPCI_FADD = 0xfc00002a,
+ PPCI_FSUB = 0xfc000028,
+ PPCI_FMUL = 0xfc000032,
+ PPCI_FDIV = 0xfc000024,
+ PPCI_FSQRT = 0xfc00002c,
+
+ PPCI_FMADD = 0xfc00003a,
+ PPCI_FMSUB = 0xfc000038,
+ PPCI_FNMSUB = 0xfc00003c,
+
+ PPCI_FCMPU = 0xfc000000,
+ PPCI_FSEL = 0xfc00002e,
+} PPCIns;
+
+typedef enum PPCCC {
+ CC_GE, CC_LE, CC_NE, CC_NS, CC_LT, CC_GT, CC_EQ, CC_SO
+} PPCCC;
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target_x86.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target_x86.h
new file mode 100644
index 0000000..4426cc8
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_target_x86.h
@@ -0,0 +1,342 @@
+/*
+** Definitions for x86 and x64 CPUs.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_TARGET_X86_H
+#define _LJ_TARGET_X86_H
+
+/* -- Registers IDs ------------------------------------------------------- */
+
+#if LJ_64
+#define GPRDEF(_) \
+ _(EAX) _(ECX) _(EDX) _(EBX) _(ESP) _(EBP) _(ESI) _(EDI) \
+ _(R8D) _(R9D) _(R10D) _(R11D) _(R12D) _(R13D) _(R14D) _(R15D)
+#define FPRDEF(_) \
+ _(XMM0) _(XMM1) _(XMM2) _(XMM3) _(XMM4) _(XMM5) _(XMM6) _(XMM7) \
+ _(XMM8) _(XMM9) _(XMM10) _(XMM11) _(XMM12) _(XMM13) _(XMM14) _(XMM15)
+#else
+#define GPRDEF(_) \
+ _(EAX) _(ECX) _(EDX) _(EBX) _(ESP) _(EBP) _(ESI) _(EDI)
+#define FPRDEF(_) \
+ _(XMM0) _(XMM1) _(XMM2) _(XMM3) _(XMM4) _(XMM5) _(XMM6) _(XMM7)
+#endif
+#define VRIDDEF(_) \
+ _(MRM)
+
+#define RIDENUM(name) RID_##name,
+
+enum {
+ GPRDEF(RIDENUM) /* General-purpose registers (GPRs). */
+ FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */
+ RID_MAX,
+ RID_MRM = RID_MAX, /* Pseudo-id for ModRM operand. */
+
+ /* Calling conventions. */
+ RID_RET = RID_EAX,
+#if LJ_64
+ RID_FPRET = RID_XMM0,
+#else
+ RID_RETLO = RID_EAX,
+ RID_RETHI = RID_EDX,
+#endif
+
+ /* These definitions must match with the *.dasc file(s): */
+ RID_BASE = RID_EDX, /* Interpreter BASE. */
+#if LJ_64 && !LJ_ABI_WIN
+ RID_LPC = RID_EBX, /* Interpreter PC. */
+ RID_DISPATCH = RID_R14D, /* Interpreter DISPATCH table. */
+#else
+ RID_LPC = RID_ESI, /* Interpreter PC. */
+ RID_DISPATCH = RID_EBX, /* Interpreter DISPATCH table. */
+#endif
+
+ /* Register ranges [min, max) and number of registers. */
+ RID_MIN_GPR = RID_EAX,
+ RID_MIN_FPR = RID_XMM0,
+ RID_MAX_GPR = RID_MIN_FPR,
+ RID_MAX_FPR = RID_MAX,
+ RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,
+ RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR,
+};
+
+/* -- Register sets ------------------------------------------------------- */
+
+/* Make use of all registers, except the stack pointer. */
+#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR)-RID2RSET(RID_ESP))
+#define RSET_FPR (RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR))
+#define RSET_ALL (RSET_GPR|RSET_FPR)
+#define RSET_INIT RSET_ALL
+
+#if LJ_64
+/* Note: this requires the use of FORCE_REX! */
+#define RSET_GPR8 RSET_GPR
+#else
+#define RSET_GPR8 (RSET_RANGE(RID_EAX, RID_EBX+1))
+#endif
+
+/* ABI-specific register sets. */
+#define RSET_ACD (RID2RSET(RID_EAX)|RID2RSET(RID_ECX)|RID2RSET(RID_EDX))
+#if LJ_64
+#if LJ_ABI_WIN
+/* Windows x64 ABI. */
+#define RSET_SCRATCH \
+ (RSET_ACD|RSET_RANGE(RID_R8D, RID_R11D+1)|RSET_RANGE(RID_XMM0, RID_XMM5+1))
+#define REGARG_GPRS \
+ (RID_ECX|((RID_EDX|((RID_R8D|(RID_R9D<<5))<<5))<<5))
+#define REGARG_NUMGPR 4
+#define REGARG_NUMFPR 4
+#define REGARG_FIRSTFPR RID_XMM0
+#define REGARG_LASTFPR RID_XMM3
+#define STACKARG_OFS (4*8)
+#else
+/* The rest of the civilized x64 world has a common ABI. */
+#define RSET_SCRATCH \
+ (RSET_ACD|RSET_RANGE(RID_ESI, RID_R11D+1)|RSET_FPR)
+#define REGARG_GPRS \
+ (RID_EDI|((RID_ESI|((RID_EDX|((RID_ECX|((RID_R8D|(RID_R9D \
+ <<5))<<5))<<5))<<5))<<5))
+#define REGARG_NUMGPR 6
+#define REGARG_NUMFPR 8
+#define REGARG_FIRSTFPR RID_XMM0
+#define REGARG_LASTFPR RID_XMM7
+#define STACKARG_OFS 0
+#endif
+#else
+/* Common x86 ABI. */
+#define RSET_SCRATCH (RSET_ACD|RSET_FPR)
+#define REGARG_GPRS (RID_ECX|(RID_EDX<<5)) /* Fastcall only. */
+#define REGARG_NUMGPR 2 /* Fastcall only. */
+#define REGARG_NUMFPR 0
+#define STACKARG_OFS 0
+#endif
+
+#if LJ_64
+/* Prefer the low 8 regs of each type to reduce REX prefixes. */
+#undef rset_picktop
+#define rset_picktop(rs) (lj_fls(lj_bswap(rs)) ^ 0x18)
+#endif
+
+/* -- Spill slots --------------------------------------------------------- */
+
+/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.
+**
+** SPS_FIXED: Available fixed spill slots in interpreter frame.
+** This definition must match with the *.dasc file(s).
+**
+** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots.
+*/
+#if LJ_64
+#if LJ_ABI_WIN
+#define SPS_FIXED (4*2)
+#define SPS_FIRST (4*2) /* Don't use callee register save area. */
+#else
+#define SPS_FIXED 4
+#define SPS_FIRST 2
+#endif
+#else
+#define SPS_FIXED 6
+#define SPS_FIRST 2
+#endif
+
+#define SPOFS_TMP 0
+
+#define sps_scale(slot) (4 * (int32_t)(slot))
+#define sps_align(slot) (((slot) - SPS_FIXED + 3) & ~3)
+
+/* -- Exit state ---------------------------------------------------------- */
+
+/* This definition must match with the *.dasc file(s). */
+typedef struct {
+ lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */
+ intptr_t gpr[RID_NUM_GPR]; /* General-purpose registers. */
+ int32_t spill[256]; /* Spill slots. */
+} ExitState;
+
+/* Limited by the range of a short fwd jump (127): (2+2)*(32-1)-2 = 122. */
+#define EXITSTUB_SPACING (2+2)
+#define EXITSTUBS_PER_GROUP 32
+
+/* -- x86 ModRM operand encoding ------------------------------------------ */
+
+typedef enum {
+ XM_OFS0 = 0x00, XM_OFS8 = 0x40, XM_OFS32 = 0x80, XM_REG = 0xc0,
+ XM_SCALE1 = 0x00, XM_SCALE2 = 0x40, XM_SCALE4 = 0x80, XM_SCALE8 = 0xc0,
+ XM_MASK = 0xc0
+} x86Mode;
+
+/* Structure to hold variable ModRM operand. */
+typedef struct {
+ int32_t ofs; /* Offset. */
+ uint8_t base; /* Base register or RID_NONE. */
+ uint8_t idx; /* Index register or RID_NONE. */
+ uint8_t scale; /* Index scale (XM_SCALE1 .. XM_SCALE8). */
+} x86ModRM;
+
+/* -- Opcodes ------------------------------------------------------------- */
+
+/* Macros to construct variable-length x86 opcodes. -(len+1) is in LSB. */
+#define XO_(o) ((uint32_t)(0x0000fe + (0x##o<<24)))
+#define XO_FPU(a,b) ((uint32_t)(0x00fd + (0x##a<<16)+(0x##b<<24)))
+#define XO_0f(o) ((uint32_t)(0x0f00fd + (0x##o<<24)))
+#define XO_66(o) ((uint32_t)(0x6600fd + (0x##o<<24)))
+#define XO_660f(o) ((uint32_t)(0x0f66fc + (0x##o<<24)))
+#define XO_f20f(o) ((uint32_t)(0x0ff2fc + (0x##o<<24)))
+#define XO_f30f(o) ((uint32_t)(0x0ff3fc + (0x##o<<24)))
+
+/* This list of x86 opcodes is not intended to be complete. Opcodes are only
+** included when needed. Take a look at DynASM or jit.dis_x86 to see the
+** whole mess.
+*/
+typedef enum {
+ /* Fixed length opcodes. XI_* prefix. */
+ XI_NOP = 0x90,
+ XI_XCHGa = 0x90,
+ XI_CALL = 0xe8,
+ XI_JMP = 0xe9,
+ XI_JMPs = 0xeb,
+ XI_PUSH = 0x50, /* Really 50+r. */
+ XI_JCCs = 0x70, /* Really 7x. */
+ XI_JCCn = 0x80, /* Really 0f8x. */
+ XI_LEA = 0x8d,
+ XI_MOVrib = 0xb0, /* Really b0+r. */
+ XI_MOVri = 0xb8, /* Really b8+r. */
+ XI_ARITHib = 0x80,
+ XI_ARITHi = 0x81,
+ XI_ARITHi8 = 0x83,
+ XI_PUSHi8 = 0x6a,
+ XI_TESTb = 0x84,
+ XI_TEST = 0x85,
+ XI_MOVmi = 0xc7,
+ XI_GROUP5 = 0xff,
+
+ /* Note: little-endian byte-order! */
+ XI_FLDZ = 0xeed9,
+ XI_FLD1 = 0xe8d9,
+ XI_FLDLG2 = 0xecd9,
+ XI_FLDLN2 = 0xedd9,
+ XI_FDUP = 0xc0d9, /* Really fld st0. */
+ XI_FPOP = 0xd8dd, /* Really fstp st0. */
+ XI_FPOP1 = 0xd9dd, /* Really fstp st1. */
+ XI_FRNDINT = 0xfcd9,
+ XI_FSIN = 0xfed9,
+ XI_FCOS = 0xffd9,
+ XI_FPTAN = 0xf2d9,
+ XI_FPATAN = 0xf3d9,
+ XI_FSCALE = 0xfdd9,
+ XI_FYL2X = 0xf1d9,
+
+ /* Variable-length opcodes. XO_* prefix. */
+ XO_MOV = XO_(8b),
+ XO_MOVto = XO_(89),
+ XO_MOVtow = XO_66(89),
+ XO_MOVtob = XO_(88),
+ XO_MOVmi = XO_(c7),
+ XO_MOVmib = XO_(c6),
+ XO_LEA = XO_(8d),
+ XO_ARITHib = XO_(80),
+ XO_ARITHi = XO_(81),
+ XO_ARITHi8 = XO_(83),
+ XO_ARITHiw8 = XO_66(83),
+ XO_SHIFTi = XO_(c1),
+ XO_SHIFT1 = XO_(d1),
+ XO_SHIFTcl = XO_(d3),
+ XO_IMUL = XO_0f(af),
+ XO_IMULi = XO_(69),
+ XO_IMULi8 = XO_(6b),
+ XO_CMP = XO_(3b),
+ XO_TESTb = XO_(84),
+ XO_TEST = XO_(85),
+ XO_GROUP3b = XO_(f6),
+ XO_GROUP3 = XO_(f7),
+ XO_GROUP5b = XO_(fe),
+ XO_GROUP5 = XO_(ff),
+ XO_MOVZXb = XO_0f(b6),
+ XO_MOVZXw = XO_0f(b7),
+ XO_MOVSXb = XO_0f(be),
+ XO_MOVSXw = XO_0f(bf),
+ XO_MOVSXd = XO_(63),
+ XO_BSWAP = XO_0f(c8),
+ XO_CMOV = XO_0f(40),
+
+ XO_MOVSD = XO_f20f(10),
+ XO_MOVSDto = XO_f20f(11),
+ XO_MOVSS = XO_f30f(10),
+ XO_MOVSSto = XO_f30f(11),
+ XO_MOVLPD = XO_660f(12),
+ XO_MOVAPS = XO_0f(28),
+ XO_XORPS = XO_0f(57),
+ XO_ANDPS = XO_0f(54),
+ XO_ADDSD = XO_f20f(58),
+ XO_SUBSD = XO_f20f(5c),
+ XO_MULSD = XO_f20f(59),
+ XO_DIVSD = XO_f20f(5e),
+ XO_SQRTSD = XO_f20f(51),
+ XO_MINSD = XO_f20f(5d),
+ XO_MAXSD = XO_f20f(5f),
+ XO_ROUNDSD = 0x0b3a0ffc, /* Really 66 0f 3a 0b. See asm_fpmath. */
+ XO_UCOMISD = XO_660f(2e),
+ XO_CVTSI2SD = XO_f20f(2a),
+ XO_CVTSD2SI = XO_f20f(2d),
+ XO_CVTTSD2SI= XO_f20f(2c),
+ XO_CVTSI2SS = XO_f30f(2a),
+ XO_CVTSS2SI = XO_f30f(2d),
+ XO_CVTTSS2SI= XO_f30f(2c),
+ XO_CVTSS2SD = XO_f30f(5a),
+ XO_CVTSD2SS = XO_f20f(5a),
+ XO_ADDSS = XO_f30f(58),
+ XO_MOVD = XO_660f(6e),
+ XO_MOVDto = XO_660f(7e),
+
+ XO_FLDd = XO_(d9), XOg_FLDd = 0,
+ XO_FLDq = XO_(dd), XOg_FLDq = 0,
+ XO_FILDd = XO_(db), XOg_FILDd = 0,
+ XO_FILDq = XO_(df), XOg_FILDq = 5,
+ XO_FSTPd = XO_(d9), XOg_FSTPd = 3,
+ XO_FSTPq = XO_(dd), XOg_FSTPq = 3,
+ XO_FISTPq = XO_(df), XOg_FISTPq = 7,
+ XO_FISTTPq = XO_(dd), XOg_FISTTPq = 1,
+ XO_FADDq = XO_(dc), XOg_FADDq = 0,
+ XO_FLDCW = XO_(d9), XOg_FLDCW = 5,
+ XO_FNSTCW = XO_(d9), XOg_FNSTCW = 7
+} x86Op;
+
+/* x86 opcode groups. */
+typedef uint32_t x86Group;
+
+#define XG_(i8, i, g) ((x86Group)(((i8) << 16) + ((i) << 8) + (g)))
+#define XG_ARITHi(g) XG_(XI_ARITHi8, XI_ARITHi, g)
+#define XG_TOXOi(xg) ((x86Op)(0x000000fe + (((xg)<<16) & 0xff000000)))
+#define XG_TOXOi8(xg) ((x86Op)(0x000000fe + (((xg)<<8) & 0xff000000)))
+
+#define XO_ARITH(a) ((x86Op)(0x030000fe + ((a)<<27)))
+#define XO_ARITHw(a) ((x86Op)(0x036600fd + ((a)<<27)))
+
+typedef enum {
+ XOg_ADD, XOg_OR, XOg_ADC, XOg_SBB, XOg_AND, XOg_SUB, XOg_XOR, XOg_CMP,
+ XOg_X_IMUL
+} x86Arith;
+
+typedef enum {
+ XOg_ROL, XOg_ROR, XOg_RCL, XOg_RCR, XOg_SHL, XOg_SHR, XOg_SAL, XOg_SAR
+} x86Shift;
+
+typedef enum {
+ XOg_TEST, XOg_TEST_, XOg_NOT, XOg_NEG, XOg_MUL, XOg_IMUL, XOg_DIV, XOg_IDIV
+} x86Group3;
+
+typedef enum {
+ XOg_INC, XOg_DEC, XOg_CALL, XOg_CALLfar, XOg_JMP, XOg_JMPfar, XOg_PUSH
+} x86Group5;
+
+/* x86 condition codes. */
+typedef enum {
+ CC_O, CC_NO, CC_B, CC_NB, CC_E, CC_NE, CC_BE, CC_NBE,
+ CC_S, CC_NS, CC_P, CC_NP, CC_L, CC_NL, CC_LE, CC_NLE,
+ CC_C = CC_B, CC_NAE = CC_C, CC_NC = CC_NB, CC_AE = CC_NB,
+ CC_Z = CC_E, CC_NZ = CC_NE, CC_NA = CC_BE, CC_A = CC_NBE,
+ CC_PE = CC_P, CC_PO = CC_NP, CC_NGE = CC_L, CC_GE = CC_NL,
+ CC_NG = CC_LE, CC_G = CC_NLE
+} x86CC;
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_trace.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_trace.h
new file mode 100644
index 0000000..edc7af0
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_trace.h
@@ -0,0 +1,53 @@
+/*
+** Trace management.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_TRACE_H
+#define _LJ_TRACE_H
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT
+#include "lj_jit.h"
+#include "lj_dispatch.h"
+
+/* Trace errors. */
+typedef enum {
+#define TREDEF(name, msg) LJ_TRERR_##name,
+#include "lj_traceerr.h"
+ LJ_TRERR__MAX
+} TraceError;
+
+LJ_FUNC_NORET void lj_trace_err(jit_State *J, TraceError e);
+LJ_FUNC_NORET void lj_trace_err_info(jit_State *J, TraceError e);
+
+/* Trace management. */
+LJ_FUNC void LJ_FASTCALL lj_trace_free(global_State *g, GCtrace *T);
+LJ_FUNC void lj_trace_reenableproto(GCproto *pt);
+LJ_FUNC void lj_trace_flushproto(global_State *g, GCproto *pt);
+LJ_FUNC void lj_trace_flush(jit_State *J, TraceNo traceno);
+LJ_FUNC int lj_trace_flushall(lua_State *L);
+LJ_FUNC void lj_trace_initstate(global_State *g);
+LJ_FUNC void lj_trace_freestate(global_State *g);
+
+/* Event handling. */
+LJ_FUNC void lj_trace_ins(jit_State *J, const BCIns *pc);
+LJ_FUNCA void LJ_FASTCALL lj_trace_hot(jit_State *J, const BCIns *pc);
+LJ_FUNCA int LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr);
+
+/* Signal asynchronous abort of trace or end of trace. */
+#define lj_trace_abort(g) (G2J(g)->state &= ~LJ_TRACE_ACTIVE)
+#define lj_trace_end(J) (J->state = LJ_TRACE_END)
+
+#else
+
+#define lj_trace_flushall(L) (UNUSED(L), 0)
+#define lj_trace_initstate(g) UNUSED(g)
+#define lj_trace_freestate(g) UNUSED(g)
+#define lj_trace_abort(g) UNUSED(g)
+#define lj_trace_end(J) UNUSED(J)
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_traceerr.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_traceerr.h
new file mode 100644
index 0000000..f920e5e
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_traceerr.h
@@ -0,0 +1,61 @@
+/*
+** Trace compiler error messages.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* This file may be included multiple times with different TREDEF macros. */
+
+/* Recording. */
+TREDEF(RECERR, "error thrown or hook called during recording")
+TREDEF(TRACEOV, "trace too long")
+TREDEF(STACKOV, "trace too deep")
+TREDEF(SNAPOV, "too many snapshots")
+TREDEF(BLACKL, "blacklisted")
+TREDEF(NYIBC, "NYI: bytecode %d")
+
+/* Recording loop ops. */
+TREDEF(LLEAVE, "leaving loop in root trace")
+TREDEF(LINNER, "inner loop in root trace")
+TREDEF(LUNROLL, "loop unroll limit reached")
+
+/* Recording calls/returns. */
+TREDEF(BADTYPE, "bad argument type")
+TREDEF(CJITOFF, "JIT compilation disabled for function")
+TREDEF(CUNROLL, "call unroll limit reached")
+TREDEF(DOWNREC, "down-recursion, restarting")
+TREDEF(NYICF, "NYI: C function %s")
+TREDEF(NYIFF, "NYI: FastFunc %s")
+TREDEF(NYIFFU, "NYI: unsupported variant of FastFunc %s")
+TREDEF(NYIRETL, "NYI: return to lower frame")
+
+/* Recording indexed load/store. */
+TREDEF(STORENN, "store with nil or NaN key")
+TREDEF(NOMM, "missing metamethod")
+TREDEF(IDXLOOP, "looping index lookup")
+TREDEF(NYITMIX, "NYI: mixed sparse/dense table")
+
+/* Recording C data operations. */
+TREDEF(NOCACHE, "symbol not in cache")
+TREDEF(NYICONV, "NYI: unsupported C type conversion")
+TREDEF(NYICALL, "NYI: unsupported C function type")
+
+/* Optimizations. */
+TREDEF(GFAIL, "guard would always fail")
+TREDEF(PHIOV, "too many PHIs")
+TREDEF(TYPEINS, "persistent type instability")
+
+/* Assembler. */
+TREDEF(MCODEAL, "failed to allocate mcode memory")
+TREDEF(MCODEOV, "machine code too long")
+TREDEF(MCODELM, "hit mcode limit (retrying)")
+TREDEF(SPILLOV, "too many spill slots")
+TREDEF(BADRA, "inconsistent register allocation")
+TREDEF(NYIIR, "NYI: cannot assemble IR instruction %d")
+TREDEF(NYIPHI, "NYI: PHI shuffling too complex")
+TREDEF(NYICOAL, "NYI: register coalescing too complex")
+
+#undef TREDEF
+
+/* Detecting unused error messages:
+ awk -F, '/^TREDEF/ { gsub(/TREDEF./, ""); printf "grep -q LJ_TRERR_%s *.[ch] || echo %s\n", $1, $1}' lj_traceerr.h | sh
+*/
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_udata.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_udata.h
new file mode 100644
index 0000000..f271a42
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_udata.h
@@ -0,0 +1,14 @@
+/*
+** Userdata handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_UDATA_H
+#define _LJ_UDATA_H
+
+#include "lj_obj.h"
+
+LJ_FUNC GCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env);
+LJ_FUNC void LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_vm.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_vm.h
new file mode 100644
index 0000000..3ffa76b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_vm.h
@@ -0,0 +1,116 @@
+/*
+** Assembler VM interface definitions.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_VM_H
+#define _LJ_VM_H
+
+#include "lj_obj.h"
+
+/* Entry points for ASM parts of VM. */
+LJ_ASMF void lj_vm_call(lua_State *L, TValue *base, int nres1);
+LJ_ASMF int lj_vm_pcall(lua_State *L, TValue *base, int nres1, ptrdiff_t ef);
+typedef TValue *(*lua_CPFunction)(lua_State *L, lua_CFunction func, void *ud);
+LJ_ASMF int lj_vm_cpcall(lua_State *L, lua_CFunction func, void *ud,
+ lua_CPFunction cp);
+LJ_ASMF int lj_vm_resume(lua_State *L, TValue *base, int nres1, ptrdiff_t ef);
+LJ_ASMF_NORET void LJ_FASTCALL lj_vm_unwind_c(void *cframe, int errcode);
+LJ_ASMF_NORET void LJ_FASTCALL lj_vm_unwind_ff(void *cframe);
+LJ_ASMF void lj_vm_unwind_c_eh(void);
+LJ_ASMF void lj_vm_unwind_ff_eh(void);
+#if LJ_TARGET_X86ORX64
+LJ_ASMF void lj_vm_unwind_rethrow(void);
+#endif
+
+/* Miscellaneous functions. */
+#if LJ_TARGET_X86ORX64
+LJ_ASMF int lj_vm_cpuid(uint32_t f, uint32_t res[4]);
+#endif
+#if LJ_TARGET_PPC
+void lj_vm_cachesync(void *start, void *end);
+#endif
+LJ_ASMF double lj_vm_foldarith(double x, double y, int op);
+#if LJ_HASJIT
+LJ_ASMF double lj_vm_foldfpm(double x, int op);
+#endif
+#if !LJ_ARCH_HASFPU
+/* Declared in lj_obj.h: LJ_ASMF int32_t lj_vm_tobit(double x); */
+#endif
+
+/* Dispatch targets for recording and hooks. */
+LJ_ASMF void lj_vm_record(void);
+LJ_ASMF void lj_vm_inshook(void);
+LJ_ASMF void lj_vm_rethook(void);
+LJ_ASMF void lj_vm_callhook(void);
+
+/* Trace exit handling. */
+LJ_ASMF void lj_vm_exit_handler(void);
+LJ_ASMF void lj_vm_exit_interp(void);
+
+/* Internal math helper functions. */
+#if LJ_TARGET_X86ORX64 || LJ_TARGET_PPC
+#define lj_vm_floor floor
+#define lj_vm_ceil ceil
+#else
+LJ_ASMF double lj_vm_floor(double);
+LJ_ASMF double lj_vm_ceil(double);
+#if LJ_TARGET_ARM
+LJ_ASMF double lj_vm_floor_sf(double);
+LJ_ASMF double lj_vm_ceil_sf(double);
+#endif
+#endif
+#if defined(LUAJIT_NO_LOG2) || LJ_TARGET_X86ORX64
+LJ_ASMF double lj_vm_log2(double);
+#else
+#define lj_vm_log2 log2
+#endif
+
+#if LJ_HASJIT
+#if LJ_TARGET_X86ORX64
+LJ_ASMF void lj_vm_floor_sse(void);
+LJ_ASMF void lj_vm_ceil_sse(void);
+LJ_ASMF void lj_vm_trunc_sse(void);
+LJ_ASMF void lj_vm_exp_x87(void);
+LJ_ASMF void lj_vm_exp2_x87(void);
+LJ_ASMF void lj_vm_pow_sse(void);
+LJ_ASMF void lj_vm_powi_sse(void);
+#else
+#if LJ_TARGET_PPC
+#define lj_vm_trunc trunc
+#else
+LJ_ASMF double lj_vm_trunc(double);
+#if LJ_TARGET_ARM
+LJ_ASMF double lj_vm_trunc_sf(double);
+#endif
+#endif
+LJ_ASMF double lj_vm_powi(double, int32_t);
+#ifdef LUAJIT_NO_EXP2
+LJ_ASMF double lj_vm_exp2(double);
+#else
+#define lj_vm_exp2 exp2
+#endif
+#endif
+LJ_ASMF int32_t LJ_FASTCALL lj_vm_modi(int32_t, int32_t);
+#if LJ_HASFFI
+LJ_ASMF int lj_vm_errno(void);
+#endif
+#endif
+
+/* Continuations for metamethods. */
+LJ_ASMF void lj_cont_cat(void); /* Continue with concatenation. */
+LJ_ASMF void lj_cont_ra(void); /* Store result in RA from instruction. */
+LJ_ASMF void lj_cont_nop(void); /* Do nothing, just continue execution. */
+LJ_ASMF void lj_cont_condt(void); /* Branch if result is true. */
+LJ_ASMF void lj_cont_condf(void); /* Branch if result is false. */
+LJ_ASMF void lj_cont_hook(void); /* Continue from hook yield. */
+
+enum { LJ_CONT_TAILCALL, LJ_CONT_FFI_CALLBACK }; /* Special continuations. */
+
+/* Start of the ASM code. */
+LJ_ASMF char lj_vm_asm_begin[];
+
+/* Bytecode offsets are relative to lj_vm_asm_begin. */
+#define makeasmfunc(ofs) ((ASMFunction)(lj_vm_asm_begin + (ofs)))
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_vmevent.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_vmevent.h
new file mode 100644
index 0000000..050fb4d
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lj_vmevent.h
@@ -0,0 +1,59 @@
+/*
+** VM event handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_VMEVENT_H
+#define _LJ_VMEVENT_H
+
+#include "lj_obj.h"
+
+/* Registry key for VM event handler table. */
+#define LJ_VMEVENTS_REGKEY "_VMEVENTS"
+#define LJ_VMEVENTS_HSIZE 4
+
+#define VMEVENT_MASK(ev) ((uint8_t)1 << ((int)(ev) & 7))
+#define VMEVENT_HASH(ev) ((int)(ev) & ~7)
+#define VMEVENT_HASHIDX(h) ((int)(h) << 3)
+#define VMEVENT_NOCACHE 255
+
+#define VMEVENT_DEF(name, hash) \
+ LJ_VMEVENT_##name##_, \
+ LJ_VMEVENT_##name = ((LJ_VMEVENT_##name##_) & 7)|((hash) << 3)
+
+/* VM event IDs. */
+typedef enum {
+ VMEVENT_DEF(BC, 0x00003883),
+ VMEVENT_DEF(TRACE, 0xb2d91467),
+ VMEVENT_DEF(RECORD, 0x9284bf4f),
+ VMEVENT_DEF(TEXIT, 0xb29df2b0),
+ LJ_VMEVENT__MAX
+} VMEvent;
+
+#ifdef LUAJIT_DISABLE_VMEVENT
+#define lj_vmevent_send(L, ev, args) UNUSED(L)
+#define lj_vmevent_send_(L, ev, args, post) UNUSED(L)
+#else
+#define lj_vmevent_send(L, ev, args) \
+ if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \
+ ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \
+ if (argbase) { \
+ args \
+ lj_vmevent_call(L, argbase); \
+ } \
+ }
+#define lj_vmevent_send_(L, ev, args, post) \
+ if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \
+ ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \
+ if (argbase) { \
+ args \
+ lj_vmevent_call(L, argbase); \
+ post \
+ } \
+ }
+
+LJ_FUNC ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev);
+LJ_FUNC void lj_vmevent_call(lua_State *L, ptrdiff_t argbase);
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lua.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lua.h
new file mode 100644
index 0000000..c83fd3b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lua.h
@@ -0,0 +1,393 @@
+/*
+** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $
+** Lua - An Extensible Extension Language
+** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
+** See Copyright Notice at the end of this file
+*/
+
+
+#ifndef lua_h
+#define lua_h
+
+#include <stdarg.h>
+#include <stddef.h>
+
+
+#include "luaconf.h"
+
+
+#define LUA_VERSION "Lua 5.1"
+#define LUA_RELEASE "Lua 5.1.4"
+#define LUA_VERSION_NUM 501
+#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio"
+#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
+
+
+/* mark for precompiled code (`<esc>Lua') */
+#define LUA_SIGNATURE "\033Lua"
+
+/* option for multiple returns in `lua_pcall' and `lua_call' */
+#define LUA_MULTRET (-1)
+
+
+/*
+** pseudo-indices
+*/
+#define LUA_REGISTRYINDEX (-10000)
+#define LUA_ENVIRONINDEX (-10001)
+#define LUA_GLOBALSINDEX (-10002)
+#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i))
+
+
+/* thread status; 0 is OK */
+#define LUA_YIELD 1
+#define LUA_ERRRUN 2
+#define LUA_ERRSYNTAX 3
+#define LUA_ERRMEM 4
+#define LUA_ERRERR 5
+
+
+typedef struct lua_State lua_State;
+
+typedef int (*lua_CFunction) (lua_State *L);
+
+
+/*
+** functions that read/write blocks when loading/dumping Lua chunks
+*/
+typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
+
+typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);
+
+
+/*
+** prototype for memory-allocation functions
+*/
+typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
+
+
+/*
+** basic types
+*/
+#define LUA_TNONE (-1)
+
+#define LUA_TNIL 0
+#define LUA_TBOOLEAN 1
+#define LUA_TLIGHTUSERDATA 2
+#define LUA_TNUMBER 3
+#define LUA_TSTRING 4
+#define LUA_TTABLE 5
+#define LUA_TFUNCTION 6
+#define LUA_TUSERDATA 7
+#define LUA_TTHREAD 8
+
+
+
+/* minimum Lua stack available to a C function */
+#define LUA_MINSTACK 20
+
+
+/*
+** generic extra include file
+*/
+#if defined(LUA_USER_H)
+#include LUA_USER_H
+#endif
+
+
+/* type of numbers in Lua */
+typedef LUA_NUMBER lua_Number;
+
+
+/* type for integer functions */
+typedef LUA_INTEGER lua_Integer;
+
+
+
+/*
+** state manipulation
+*/
+LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
+LUA_API void (lua_close) (lua_State *L);
+LUA_API lua_State *(lua_newthread) (lua_State *L);
+
+LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
+
+
+/*
+** basic stack manipulation
+*/
+LUA_API int (lua_gettop) (lua_State *L);
+LUA_API void (lua_settop) (lua_State *L, int idx);
+LUA_API void (lua_pushvalue) (lua_State *L, int idx);
+LUA_API void (lua_remove) (lua_State *L, int idx);
+LUA_API void (lua_insert) (lua_State *L, int idx);
+LUA_API void (lua_replace) (lua_State *L, int idx);
+LUA_API int (lua_checkstack) (lua_State *L, int sz);
+
+LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
+
+
+/*
+** access functions (stack -> C)
+*/
+
+LUA_API int (lua_isnumber) (lua_State *L, int idx);
+LUA_API int (lua_isstring) (lua_State *L, int idx);
+LUA_API int (lua_iscfunction) (lua_State *L, int idx);
+LUA_API int (lua_isuserdata) (lua_State *L, int idx);
+LUA_API int (lua_type) (lua_State *L, int idx);
+LUA_API const char *(lua_typename) (lua_State *L, int tp);
+
+LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2);
+LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
+LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2);
+
+LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx);
+LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx);
+LUA_API int (lua_toboolean) (lua_State *L, int idx);
+LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
+LUA_API size_t (lua_objlen) (lua_State *L, int idx);
+LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
+LUA_API void *(lua_touserdata) (lua_State *L, int idx);
+LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
+LUA_API const void *(lua_topointer) (lua_State *L, int idx);
+
+
+/*
+** push functions (C -> stack)
+*/
+LUA_API void (lua_pushnil) (lua_State *L);
+LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
+LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
+LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l);
+LUA_API void (lua_pushstring) (lua_State *L, const char *s);
+LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
+ va_list argp);
+LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
+LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
+LUA_API void (lua_pushboolean) (lua_State *L, int b);
+LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
+LUA_API int (lua_pushthread) (lua_State *L);
+
+
+/*
+** get functions (Lua -> stack)
+*/
+LUA_API void (lua_gettable) (lua_State *L, int idx);
+LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k);
+LUA_API void (lua_rawget) (lua_State *L, int idx);
+LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n);
+LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
+LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
+LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
+LUA_API void (lua_getfenv) (lua_State *L, int idx);
+
+
+/*
+** set functions (stack -> Lua)
+*/
+LUA_API void (lua_settable) (lua_State *L, int idx);
+LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
+LUA_API void (lua_rawset) (lua_State *L, int idx);
+LUA_API void (lua_rawseti) (lua_State *L, int idx, int n);
+LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
+LUA_API int (lua_setfenv) (lua_State *L, int idx);
+
+
+/*
+** `load' and `call' functions (load and run Lua code)
+*/
+LUA_API void (lua_call) (lua_State *L, int nargs, int nresults);
+LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
+LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);
+LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
+ const char *chunkname);
+
+LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
+
+
+/*
+** coroutine functions
+*/
+LUA_API int (lua_yield) (lua_State *L, int nresults);
+LUA_API int (lua_resume) (lua_State *L, int narg);
+LUA_API int (lua_status) (lua_State *L);
+
+/*
+** garbage-collection function and options
+*/
+
+#define LUA_GCSTOP 0
+#define LUA_GCRESTART 1
+#define LUA_GCCOLLECT 2
+#define LUA_GCCOUNT 3
+#define LUA_GCCOUNTB 4
+#define LUA_GCSTEP 5
+#define LUA_GCSETPAUSE 6
+#define LUA_GCSETSTEPMUL 7
+
+LUA_API int (lua_gc) (lua_State *L, int what, int data);
+
+
+/*
+** miscellaneous functions
+*/
+
+LUA_API int (lua_error) (lua_State *L);
+
+LUA_API int (lua_next) (lua_State *L, int idx);
+
+LUA_API void (lua_concat) (lua_State *L, int n);
+
+LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
+LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
+
+
+
+/*
+** ===============================================================
+** some useful macros
+** ===============================================================
+*/
+
+#define lua_pop(L,n) lua_settop(L, -(n)-1)
+
+#define lua_newtable(L) lua_createtable(L, 0, 0)
+
+#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
+
+#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
+
+#define lua_strlen(L,i) lua_objlen(L, (i))
+
+#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
+#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
+#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
+#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
+#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
+#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
+#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
+#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
+
+#define lua_pushliteral(L, s) \
+ lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
+
+#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s))
+#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s))
+
+#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
+
+
+
+/*
+** compatibility macros and functions
+*/
+
+#define lua_open() luaL_newstate()
+
+#define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX)
+
+#define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0)
+
+#define lua_Chunkreader lua_Reader
+#define lua_Chunkwriter lua_Writer
+
+
+/* hack */
+LUA_API void lua_setlevel (lua_State *from, lua_State *to);
+
+
+/*
+** {======================================================================
+** Debug API
+** =======================================================================
+*/
+
+
+/*
+** Event codes
+*/
+#define LUA_HOOKCALL 0
+#define LUA_HOOKRET 1
+#define LUA_HOOKLINE 2
+#define LUA_HOOKCOUNT 3
+#define LUA_HOOKTAILRET 4
+
+
+/*
+** Event masks
+*/
+#define LUA_MASKCALL (1 << LUA_HOOKCALL)
+#define LUA_MASKRET (1 << LUA_HOOKRET)
+#define LUA_MASKLINE (1 << LUA_HOOKLINE)
+#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
+
+typedef struct lua_Debug lua_Debug; /* activation record */
+
+
+/* Functions to be called by the debuger in specific events */
+typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
+
+
+LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);
+LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
+LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
+LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
+LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);
+LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);
+LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
+LUA_API lua_Hook lua_gethook (lua_State *L);
+LUA_API int lua_gethookmask (lua_State *L);
+LUA_API int lua_gethookcount (lua_State *L);
+
+/* From Lua 5.2. */
+LUA_API void *lua_upvalueid (lua_State *L, int idx, int n);
+LUA_API void lua_upvaluejoin (lua_State *L, int idx1, int n1, int idx2, int n2);
+LUA_API int lua_loadx (lua_State *L, lua_Reader reader, void *dt,
+ const char *chunkname, const char *mode);
+
+
+struct lua_Debug {
+ int event;
+ const char *name; /* (n) */
+ const char *namewhat; /* (n) `global', `local', `field', `method' */
+ const char *what; /* (S) `Lua', `C', `main', `tail' */
+ const char *source; /* (S) */
+ int currentline; /* (l) */
+ int nups; /* (u) number of upvalues */
+ int linedefined; /* (S) */
+ int lastlinedefined; /* (S) */
+ char short_src[LUA_IDSIZE]; /* (S) */
+ /* private part */
+ int i_ci; /* active function */
+};
+
+/* }====================================================================== */
+
+
+/******************************************************************************
+* Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining
+* a copy of this software and associated documentation files (the
+* "Software"), to deal in the Software without restriction, including
+* without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to
+* permit persons to whom the Software is furnished to do so, subject to
+* the following conditions:
+*
+* The above copyright notice and this permission notice shall be
+* included in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+******************************************************************************/
+
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lua.hpp b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lua.hpp
new file mode 100644
index 0000000..07e9002
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lua.hpp
@@ -0,0 +1,9 @@
+// C++ wrapper for LuaJIT header files.
+
+extern "C" {
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+#include "luajit.h"
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/luaconf.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/luaconf.h
new file mode 100644
index 0000000..b33e91b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/luaconf.h
@@ -0,0 +1,156 @@
+/*
+** Configuration header.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef luaconf_h
+#define luaconf_h
+
+#ifndef WINVER
+#define WINVER 0x0501
+#endif
+#include <limits.h>
+#include <stddef.h>
+
+/* Default path for loading Lua and C modules with require(). */
+#if defined(_WIN32)
+/*
+** In Windows, any exclamation mark ('!') in the path is replaced by the
+** path of the directory of the executable file of the current process.
+*/
+#define LUA_LDIR "!\\lua\\"
+#define LUA_CDIR "!\\"
+#define LUA_PATH_DEFAULT \
+ ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;"
+#define LUA_CPATH_DEFAULT \
+ ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
+#else
+/*
+** Note to distribution maintainers: do NOT patch the following lines!
+** Please read ../doc/install.html#distro and pass PREFIX=/usr instead.
+*/
+#ifndef LUA_MULTILIB
+#define LUA_MULTILIB "lib"
+#endif
+#ifndef LUA_LMULTILIB
+#define LUA_LMULTILIB "lib"
+#endif
+#define LUA_LROOT "/usr/local"
+#define LUA_LUADIR "/lua/5.1/"
+#define LUA_LJDIR "/luajit-2.0.5/"
+
+#ifdef LUA_ROOT
+#define LUA_JROOT LUA_ROOT
+#define LUA_RLDIR LUA_ROOT "/share" LUA_LUADIR
+#define LUA_RCDIR LUA_ROOT "/" LUA_MULTILIB LUA_LUADIR
+#define LUA_RLPATH ";" LUA_RLDIR "?.lua;" LUA_RLDIR "?/init.lua"
+#define LUA_RCPATH ";" LUA_RCDIR "?.so"
+#else
+#define LUA_JROOT LUA_LROOT
+#define LUA_RLPATH
+#define LUA_RCPATH
+#endif
+
+#define LUA_JPATH ";" LUA_JROOT "/share" LUA_LJDIR "?.lua"
+#define LUA_LLDIR LUA_LROOT "/share" LUA_LUADIR
+#define LUA_LCDIR LUA_LROOT "/" LUA_LMULTILIB LUA_LUADIR
+#define LUA_LLPATH ";" LUA_LLDIR "?.lua;" LUA_LLDIR "?/init.lua"
+#define LUA_LCPATH1 ";" LUA_LCDIR "?.so"
+#define LUA_LCPATH2 ";" LUA_LCDIR "loadall.so"
+
+#define LUA_PATH_DEFAULT "./?.lua" LUA_JPATH LUA_LLPATH LUA_RLPATH
+#define LUA_CPATH_DEFAULT "./?.so" LUA_LCPATH1 LUA_RCPATH LUA_LCPATH2
+#endif
+
+/* Environment variable names for path overrides and initialization code. */
+#define LUA_PATH "LUA_PATH"
+#define LUA_CPATH "LUA_CPATH"
+#define LUA_INIT "LUA_INIT"
+
+/* Special file system characters. */
+#if defined(_WIN32)
+#define LUA_DIRSEP "\\"
+#else
+#define LUA_DIRSEP "/"
+#endif
+#define LUA_PATHSEP ";"
+#define LUA_PATH_MARK "?"
+#define LUA_EXECDIR "!"
+#define LUA_IGMARK "-"
+#define LUA_PATH_CONFIG \
+ LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" \
+ LUA_EXECDIR "\n" LUA_IGMARK
+
+/* Quoting in error messages. */
+#define LUA_QL(x) "'" x "'"
+#define LUA_QS LUA_QL("%s")
+
+/* Various tunables. */
+#define LUAI_MAXSTACK 65500 /* Max. # of stack slots for a thread (<64K). */
+#define LUAI_MAXCSTACK 8000 /* Max. # of stack slots for a C func (<10K). */
+#define LUAI_GCPAUSE 200 /* Pause GC until memory is at 200%. */
+#define LUAI_GCMUL 200 /* Run GC at 200% of allocation speed. */
+#define LUA_MAXCAPTURES 32 /* Max. pattern captures. */
+
+/* Compatibility with older library function names. */
+#define LUA_COMPAT_MOD /* OLD: math.mod, NEW: math.fmod */
+#define LUA_COMPAT_GFIND /* OLD: string.gfind, NEW: string.gmatch */
+
+/* Configuration for the frontend (the luajit executable). */
+#if defined(luajit_c)
+#define LUA_PROGNAME "luajit" /* Fallback frontend name. */
+#define LUA_PROMPT "> " /* Interactive prompt. */
+#define LUA_PROMPT2 ">> " /* Continuation prompt. */
+#define LUA_MAXINPUT 512 /* Max. input line length. */
+#endif
+
+/* Note: changing the following defines breaks the Lua 5.1 ABI. */
+#define LUA_INTEGER ptrdiff_t
+#define LUA_IDSIZE 60 /* Size of lua_Debug.short_src. */
+/*
+** Size of lauxlib and io.* on-stack buffers. Weird workaround to avoid using
+** unreasonable amounts of stack space, but still retain ABI compatibility.
+** Blame Lua for depending on BUFSIZ in the ABI, blame **** for wrecking it.
+*/
+#define LUAL_BUFFERSIZE (BUFSIZ > 16384 ? 8192 : BUFSIZ)
+
+/* The following defines are here only for compatibility with luaconf.h
+** from the standard Lua distribution. They must not be changed for LuaJIT.
+*/
+#define LUA_NUMBER_DOUBLE
+#define LUA_NUMBER double
+#define LUAI_UACNUMBER double
+#define LUA_NUMBER_SCAN "%lf"
+#define LUA_NUMBER_FMT "%.14g"
+#define lua_number2str(s, n) sprintf((s), LUA_NUMBER_FMT, (n))
+#define LUAI_MAXNUMBER2STR 32
+#define LUA_INTFRMLEN "l"
+#define LUA_INTFRM_T long
+
+/* Linkage of public API functions. */
+#if defined(LUA_BUILD_AS_DLL)
+#if defined(LUA_CORE) || defined(LUA_LIB)
+#define LUA_API __declspec(dllexport)
+#else
+#define LUA_API __declspec(dllimport)
+#endif
+#else
+#define LUA_API extern
+#endif
+
+#define LUALIB_API LUA_API
+
+/* Support for internal assertions. */
+#if defined(LUA_USE_ASSERT) || defined(LUA_USE_APICHECK)
+#include <assert.h>
+#endif
+#ifdef LUA_USE_ASSERT
+#define lua_assert(x) assert(x)
+#endif
+#ifdef LUA_USE_APICHECK
+#define luai_apicheck(L, o) { (void)L; assert(o); }
+#else
+#define luai_apicheck(L, o) { (void)L; }
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/luajit.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/luajit.h
new file mode 100644
index 0000000..c5ff3ac
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/luajit.h
@@ -0,0 +1,70 @@
+/*
+** LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/
+**
+** Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+**
+** Permission is hereby granted, free of charge, to any person obtaining
+** a copy of this software and associated documentation files (the
+** "Software"), to deal in the Software without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Software, and to
+** permit persons to whom the Software is furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be
+** included in all copies or substantial portions of the Software.
+**
+** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**
+** [ MIT license: http://www.opensource.org/licenses/mit-license.php ]
+*/
+
+#ifndef _LUAJIT_H
+#define _LUAJIT_H
+
+#include "lua.h"
+
+#define LUAJIT_VERSION "LuaJIT 2.0.5"
+#define LUAJIT_VERSION_NUM 20005 /* Version 2.0.5 = 02.00.05. */
+#define LUAJIT_VERSION_SYM luaJIT_version_2_0_5
+#define LUAJIT_COPYRIGHT "Copyright (C) 2005-2017 Mike Pall"
+#define LUAJIT_URL "http://luajit.org/"
+
+/* Modes for luaJIT_setmode. */
+#define LUAJIT_MODE_MASK 0x00ff
+
+enum {
+ LUAJIT_MODE_ENGINE, /* Set mode for whole JIT engine. */
+ LUAJIT_MODE_DEBUG, /* Set debug mode (idx = level). */
+
+ LUAJIT_MODE_FUNC, /* Change mode for a function. */
+ LUAJIT_MODE_ALLFUNC, /* Recurse into subroutine protos. */
+ LUAJIT_MODE_ALLSUBFUNC, /* Change only the subroutines. */
+
+ LUAJIT_MODE_TRACE, /* Flush a compiled trace. */
+
+ LUAJIT_MODE_WRAPCFUNC = 0x10, /* Set wrapper mode for C function calls. */
+
+ LUAJIT_MODE_MAX
+};
+
+/* Flags or'ed in to the mode. */
+#define LUAJIT_MODE_OFF 0x0000 /* Turn feature off. */
+#define LUAJIT_MODE_ON 0x0100 /* Turn feature on. */
+#define LUAJIT_MODE_FLUSH 0x0200 /* Flush JIT-compiled code. */
+
+/* LuaJIT public C API. */
+
+/* Control the JIT engine. */
+LUA_API int luaJIT_setmode(lua_State *L, int idx, int mode);
+
+/* Enforce (dynamic) linker error for version mismatches. Call from main. */
+LUA_API void LUAJIT_VERSION_SYM(void);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lualib.h b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lualib.h
new file mode 100644
index 0000000..bfc130a
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/include/LuaJIT/lualib.h
@@ -0,0 +1,43 @@
+/*
+** Standard library header.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LUALIB_H
+#define _LUALIB_H
+
+#include "lua.h"
+
+#define LUA_FILEHANDLE "FILE*"
+
+#define LUA_COLIBNAME "coroutine"
+#define LUA_MATHLIBNAME "math"
+#define LUA_STRLIBNAME "string"
+#define LUA_TABLIBNAME "table"
+#define LUA_IOLIBNAME "io"
+#define LUA_OSLIBNAME "os"
+#define LUA_LOADLIBNAME "package"
+#define LUA_DBLIBNAME "debug"
+#define LUA_BITLIBNAME "bit"
+#define LUA_JITLIBNAME "jit"
+#define LUA_FFILIBNAME "ffi"
+
+LUALIB_API int luaopen_base(lua_State *L);
+LUALIB_API int luaopen_math(lua_State *L);
+LUALIB_API int luaopen_string(lua_State *L);
+LUALIB_API int luaopen_table(lua_State *L);
+LUALIB_API int luaopen_io(lua_State *L);
+LUALIB_API int luaopen_os(lua_State *L);
+LUALIB_API int luaopen_package(lua_State *L);
+LUALIB_API int luaopen_debug(lua_State *L);
+LUALIB_API int luaopen_bit(lua_State *L);
+LUALIB_API int luaopen_jit(lua_State *L);
+LUALIB_API int luaopen_ffi(lua_State *L);
+
+LUALIB_API void luaL_openlibs(lua_State *L);
+
+#ifndef lua_assert
+#define lua_assert(x) ((void)0)
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/.gitignore b/src/3rdparty/LuaJIT-2.0.5/src/.gitignore
new file mode 100644
index 0000000..fc94e82
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/.gitignore
@@ -0,0 +1,7 @@
+luajit
+lj_bcdef.h
+lj_ffdef.h
+lj_libdef.h
+lj_recdef.h
+lj_folddef.h
+lj_vm.s
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/Makefile b/src/3rdparty/LuaJIT-2.0.5/src/Makefile
new file mode 100644
index 0000000..24e8c0e
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/Makefile
@@ -0,0 +1,690 @@
+##############################################################################
+# LuaJIT Makefile. Requires GNU Make.
+#
+# Please read doc/install.html before changing any variables!
+#
+# Suitable for POSIX platforms (Linux, *BSD, OSX etc.).
+# Also works with MinGW and Cygwin on Windows.
+# Please check msvcbuild.bat for building with MSVC on Windows.
+#
+# Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+##############################################################################
+
+MAJVER= 2
+MINVER= 0
+RELVER= 5
+ABIVER= 5.1
+NODOTABIVER= 51
+
+##############################################################################
+############################# COMPILER OPTIONS #############################
+##############################################################################
+# These options mainly affect the speed of the JIT compiler itself, not the
+# speed of the JIT-compiled code. Turn any of the optional settings on by
+# removing the '#' in front of them. Make sure you force a full recompile
+# with "make clean", followed by "make" if you change any options.
+#
+DEFAULT_CC = gcc
+#
+# LuaJIT builds as a native 32 or 64 bit binary by default.
+CC= $(DEFAULT_CC)
+#
+# Use this if you want to force a 32 bit build on a 64 bit multilib OS.
+#CC= $(DEFAULT_CC) -m32
+#
+# Since the assembler part does NOT maintain a frame pointer, it's pointless
+# to slow down the C part by not omitting it. Debugging, tracebacks and
+# unwinding are not affected -- the assembler part has frame unwind
+# information and GCC emits it where needed (x64) or with -g (see CCDEBUG).
+CCOPT= -O2 -fomit-frame-pointer
+# Use this if you want to generate a smaller binary (but it's slower):
+#CCOPT= -Os -fomit-frame-pointer
+# Note: it's no longer recommended to use -O3 with GCC 4.x.
+# The I-Cache bloat usually outweighs the benefits from aggressive inlining.
+#
+# Target-specific compiler options:
+#
+# x86 only: it's recommended to compile at least for i686. Better yet,
+# compile for an architecture that has SSE2, too (-msse -msse2).
+#
+# x86/x64 only: For GCC 4.2 or higher and if you don't intend to distribute
+# the binaries to a different machine you could also use: -march=native
+#
+CCOPT_x86= -march=i686
+CCOPT_x64=
+CCOPT_arm=
+CCOPT_ppc=
+CCOPT_ppcspe=
+CCOPT_mips=
+#
+CCDEBUG=
+# Uncomment the next line to generate debug information:
+#CCDEBUG= -g
+#
+CCWARN= -Wall
+# Uncomment the next line to enable more warnings:
+#CCWARN+= -Wextra -Wdeclaration-after-statement -Wredundant-decls -Wshadow -Wpointer-arith
+#
+##############################################################################
+
+##############################################################################
+################################ BUILD MODE ################################
+##############################################################################
+# The default build mode is mixed mode on POSIX. On Windows this is the same
+# as dynamic mode.
+#
+# Mixed mode creates a static + dynamic library and a statically linked luajit.
+BUILDMODE= mixed
+#
+# Static mode creates a static library and a statically linked luajit.
+#BUILDMODE= static
+#
+# Dynamic mode creates a dynamic library and a dynamically linked luajit.
+# Note: this executable will only run when the library is installed!
+#BUILDMODE= dynamic
+#
+##############################################################################
+
+##############################################################################
+################################# FEATURES #################################
+##############################################################################
+# Enable/disable these features as needed, but make sure you force a full
+# recompile with "make clean", followed by "make".
+XCFLAGS=
+#
+# Permanently disable the FFI extension to reduce the size of the LuaJIT
+# executable. But please consider that the FFI library is compiled-in,
+# but NOT loaded by default. It only allocates any memory, if you actually
+# make use of it.
+#XCFLAGS+= -DLUAJIT_DISABLE_FFI
+#
+# Features from Lua 5.2 that are unlikely to break existing code are
+# enabled by default. Some other features that *might* break some existing
+# code (e.g. __pairs or os.execute() return values) can be enabled here.
+# Note: this does not provide full compatibility with Lua 5.2 at this time.
+#XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT
+#
+# Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter.
+#XCFLAGS+= -DLUAJIT_DISABLE_JIT
+#
+# Some architectures (e.g. PPC) can use either single-number (1) or
+# dual-number (2) mode. Uncomment one of these lines to override the
+# default mode. Please see LJ_ARCH_NUMMODE in lj_arch.h for details.
+#XCFLAGS+= -DLUAJIT_NUMMODE=1
+#XCFLAGS+= -DLUAJIT_NUMMODE=2
+#
+##############################################################################
+
+##############################################################################
+############################ DEBUGGING SUPPORT #############################
+##############################################################################
+# Enable these options as needed, but make sure you force a full recompile
+# with "make clean", followed by "make".
+# Note that most of these are NOT suitable for benchmarking or release mode!
+#
+# Use the system provided memory allocator (realloc) instead of the
+# bundled memory allocator. This is slower, but sometimes helpful for
+# debugging. This option cannot be enabled on x64, since realloc usually
+# doesn't return addresses in the right address range.
+# OTOH this option is mandatory for Valgrind's memcheck tool on x64 and
+# the only way to get useful results from it for all other architectures.
+#XCFLAGS+= -DLUAJIT_USE_SYSMALLOC
+#
+# This define is required to run LuaJIT under Valgrind. The Valgrind
+# header files must be installed. You should enable debug information, too.
+# Use --suppressions=lj.supp to avoid some false positives.
+#XCFLAGS+= -DLUAJIT_USE_VALGRIND
+#
+# This is the client for the GDB JIT API. GDB 7.0 or higher is required
+# to make use of it. See lj_gdbjit.c for details. Enabling this causes
+# a non-negligible overhead, even when not running under GDB.
+#XCFLAGS+= -DLUAJIT_USE_GDBJIT
+#
+# Turn on assertions for the Lua/C API to debug problems with lua_* calls.
+# This is rather slow -- use only while developing C libraries/embeddings.
+#XCFLAGS+= -DLUA_USE_APICHECK
+#
+# Turn on assertions for the whole LuaJIT VM. This significantly slows down
+# everything. Use only if you suspect a problem with LuaJIT itself.
+#XCFLAGS+= -DLUA_USE_ASSERT
+#
+##############################################################################
+# You probably don't need to change anything below this line!
+##############################################################################
+
+##############################################################################
+# Host system detection.
+##############################################################################
+
+ifeq (Windows,$(findstring Windows,$(OS))$(MSYSTEM)$(TERM))
+ HOST_SYS= Windows
+ HOST_RM= del
+else
+ HOST_SYS:= $(shell uname -s)
+ ifneq (,$(findstring MINGW,$(HOST_SYS)))
+ HOST_SYS= Windows
+ HOST_MSYS= mingw
+ endif
+ ifneq (,$(findstring CYGWIN,$(HOST_SYS)))
+ HOST_SYS= Windows
+ HOST_MSYS= cygwin
+ endif
+endif
+
+##############################################################################
+# Flags and options for host and target.
+##############################################################################
+
+# You can override the following variables at the make command line:
+# CC HOST_CC STATIC_CC DYNAMIC_CC
+# CFLAGS HOST_CFLAGS TARGET_CFLAGS
+# LDFLAGS HOST_LDFLAGS TARGET_LDFLAGS TARGET_SHLDFLAGS
+# LIBS HOST_LIBS TARGET_LIBS
+# CROSS HOST_SYS TARGET_SYS TARGET_FLAGS
+#
+# Cross-compilation examples:
+# make HOST_CC="gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows
+# make HOST_CC="gcc -m32" CROSS=powerpc-linux-gnu-
+
+CCOPTIONS= $(CCDEBUG) $(CCOPT) $(CCWARN) $(XCFLAGS) $(CFLAGS)
+LDOPTIONS= $(CCDEBUG) $(LDFLAGS)
+
+HOST_CC= $(CC)
+HOST_RM= rm -f
+# If left blank, minilua is built and used. You can supply an installed
+# copy of (plain) Lua 5.1 or 5.2, plus Lua BitOp. E.g. with: HOST_LUA=lua
+HOST_LUA=
+
+HOST_XCFLAGS= -I.
+HOST_XLDFLAGS=
+HOST_XLIBS=
+HOST_ACFLAGS= $(CCOPTIONS) $(HOST_XCFLAGS) $(TARGET_ARCH) $(HOST_CFLAGS)
+HOST_ALDFLAGS= $(LDOPTIONS) $(HOST_XLDFLAGS) $(HOST_LDFLAGS)
+HOST_ALIBS= $(HOST_XLIBS) $(LIBS) $(HOST_LIBS)
+
+STATIC_CC = $(CROSS)$(CC)
+DYNAMIC_CC = $(CROSS)$(CC) -fPIC
+TARGET_CC= $(STATIC_CC)
+TARGET_STCC= $(STATIC_CC)
+TARGET_DYNCC= $(DYNAMIC_CC)
+TARGET_LD= $(CROSS)$(CC)
+TARGET_AR= $(CROSS)ar rcus
+TARGET_STRIP= $(CROSS)strip
+
+TARGET_LIBPATH= $(or $(PREFIX),/usr/local)/$(or $(MULTILIB),lib)
+TARGET_SONAME= libluajit-$(ABIVER).so.$(MAJVER)
+TARGET_DYLIBNAME= libluajit-$(ABIVER).$(MAJVER).dylib
+TARGET_DYLIBPATH= $(TARGET_LIBPATH)/$(TARGET_DYLIBNAME)
+TARGET_DLLNAME= lua$(NODOTABIVER).dll
+TARGET_XSHLDFLAGS= -shared -fPIC -Wl,-soname,$(TARGET_SONAME)
+TARGET_DYNXLDOPTS=
+
+TARGET_LFSFLAGS= -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
+TARGET_XCFLAGS= $(TARGET_LFSFLAGS) -U_FORTIFY_SOURCE
+TARGET_XLDFLAGS=
+TARGET_XLIBS= -lm
+TARGET_TCFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)
+TARGET_ACFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)
+TARGET_ALDFLAGS= $(LDOPTIONS) $(TARGET_XLDFLAGS) $(TARGET_FLAGS) $(TARGET_LDFLAGS)
+TARGET_ASHLDFLAGS= $(LDOPTIONS) $(TARGET_XSHLDFLAGS) $(TARGET_FLAGS) $(TARGET_SHLDFLAGS)
+TARGET_ALIBS= $(TARGET_XLIBS) $(LIBS) $(TARGET_LIBS)
+
+TARGET_TESTARCH=$(shell $(TARGET_CC) $(TARGET_TCFLAGS) -E lj_arch.h -dM)
+ifneq (,$(findstring LJ_TARGET_X64 ,$(TARGET_TESTARCH)))
+ TARGET_LJARCH= x64
+else
+ifneq (,$(findstring LJ_TARGET_X86 ,$(TARGET_TESTARCH)))
+ TARGET_LJARCH= x86
+else
+ifneq (,$(findstring LJ_TARGET_ARM ,$(TARGET_TESTARCH)))
+ TARGET_LJARCH= arm
+else
+ifneq (,$(findstring LJ_TARGET_PPC ,$(TARGET_TESTARCH)))
+ TARGET_LJARCH= ppc
+else
+ifneq (,$(findstring LJ_TARGET_PPCSPE ,$(TARGET_TESTARCH)))
+ TARGET_LJARCH= ppcspe
+else
+ifneq (,$(findstring LJ_TARGET_MIPS ,$(TARGET_TESTARCH)))
+ ifneq (,$(findstring MIPSEL ,$(TARGET_TESTARCH)))
+ TARGET_ARCH= -D__MIPSEL__=1
+ endif
+ TARGET_LJARCH= mips
+else
+ $(error Unsupported target architecture)
+endif
+endif
+endif
+endif
+endif
+endif
+
+ifneq (,$(findstring LJ_TARGET_PS3 1,$(TARGET_TESTARCH)))
+ TARGET_SYS= PS3
+ TARGET_ARCH+= -D__CELLOS_LV2__
+ TARGET_XCFLAGS+= -DLUAJIT_USE_SYSMALLOC
+endif
+
+TARGET_XCFLAGS+= $(CCOPT_$(TARGET_LJARCH))
+TARGET_ARCH+= $(patsubst %,-DLUAJIT_TARGET=LUAJIT_ARCH_%,$(TARGET_LJARCH))
+
+ifneq (,$(PREFIX))
+ifneq (/usr/local,$(PREFIX))
+ TARGET_XCFLAGS+= -DLUA_ROOT=\"$(PREFIX)\"
+ ifneq (/usr,$(PREFIX))
+ TARGET_DYNXLDOPTS= -Wl,-rpath,$(TARGET_LIBPATH)
+ endif
+endif
+endif
+ifneq (,$(MULTILIB))
+ TARGET_XCFLAGS+= -DLUA_MULTILIB=\"$(MULTILIB)\"
+endif
+ifneq (,$(LMULTILIB))
+ TARGET_XCFLAGS+= -DLUA_LMULTILIB=\"$(LMULTILIB)\"
+endif
+
+##############################################################################
+# Target system detection.
+##############################################################################
+
+TARGET_SYS?= $(HOST_SYS)
+ifeq (Windows,$(TARGET_SYS))
+ TARGET_STRIP+= --strip-unneeded
+ TARGET_XSHLDFLAGS= -shared
+ TARGET_DYNXLDOPTS=
+else
+ TARGET_AR+= 2>/dev/null
+ifeq (,$(shell $(TARGET_CC) -o /dev/null -c -x c /dev/null -fno-stack-protector 2>/dev/null || echo 1))
+ TARGET_XCFLAGS+= -fno-stack-protector
+endif
+ifeq (Darwin,$(TARGET_SYS))
+ ifeq (,$(MACOSX_DEPLOYMENT_TARGET))
+ export MACOSX_DEPLOYMENT_TARGET=10.4
+ endif
+ TARGET_STRIP+= -x
+ TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
+ TARGET_DYNXLDOPTS=
+ TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)
+ ifeq (x64,$(TARGET_LJARCH))
+ TARGET_XLDFLAGS+= -pagezero_size 10000 -image_base 100000000
+ TARGET_XSHLDFLAGS+= -image_base 7fff04c4a000
+ endif
+else
+ifeq (iOS,$(TARGET_SYS))
+ TARGET_STRIP+= -x
+ TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
+ TARGET_DYNXLDOPTS=
+ TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)
+else
+ ifneq (SunOS,$(TARGET_SYS))
+ ifneq (PS3,$(TARGET_SYS))
+ TARGET_XLDFLAGS+= -Wl,-E
+ endif
+ endif
+ ifeq (Linux,$(TARGET_SYS))
+ TARGET_XLIBS+= -ldl
+ endif
+ ifeq (GNU/kFreeBSD,$(TARGET_SYS))
+ TARGET_XLIBS+= -ldl
+ endif
+endif
+endif
+endif
+
+ifneq ($(HOST_SYS),$(TARGET_SYS))
+ ifeq (Windows,$(TARGET_SYS))
+ HOST_XCFLAGS+= -malign-double -DLUAJIT_OS=LUAJIT_OS_WINDOWS
+ else
+ ifeq (Linux,$(TARGET_SYS))
+ HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_LINUX
+ else
+ ifeq (Darwin,$(TARGET_SYS))
+ HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX
+ else
+ ifeq (iOS,$(TARGET_SYS))
+ HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX
+ else
+ HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OTHER
+ endif
+ endif
+ endif
+ endif
+endif
+
+ifneq (,$(CCDEBUG))
+ TARGET_STRIP= @:
+endif
+
+##############################################################################
+# Files and pathnames.
+##############################################################################
+
+MINILUA_O= host/minilua.o
+MINILUA_LIBS= -lm
+MINILUA_T= host/minilua
+MINILUA_X= $(MINILUA_T)
+
+ifeq (,$(HOST_LUA))
+ HOST_LUA= $(MINILUA_X)
+ DASM_DEP= $(MINILUA_T)
+endif
+
+DASM_DIR= ../dynasm
+DASM= $(HOST_LUA) $(DASM_DIR)/dynasm.lua
+DASM_XFLAGS=
+DASM_AFLAGS=
+DASM_ARCH= $(TARGET_LJARCH)
+
+ifneq (,$(findstring LJ_ARCH_BITS 64,$(TARGET_TESTARCH)))
+ DASM_AFLAGS+= -D P64
+endif
+ifneq (,$(findstring LJ_HASJIT 1,$(TARGET_TESTARCH)))
+ DASM_AFLAGS+= -D JIT
+endif
+ifneq (,$(findstring LJ_HASFFI 1,$(TARGET_TESTARCH)))
+ DASM_AFLAGS+= -D FFI
+endif
+ifneq (,$(findstring LJ_DUALNUM 1,$(TARGET_TESTARCH)))
+ DASM_AFLAGS+= -D DUALNUM
+endif
+ifneq (,$(findstring LJ_ARCH_HASFPU 1,$(TARGET_TESTARCH)))
+ DASM_AFLAGS+= -D FPU
+ TARGET_ARCH+= -DLJ_ARCH_HASFPU=1
+else
+ TARGET_ARCH+= -DLJ_ARCH_HASFPU=0
+endif
+ifeq (,$(findstring LJ_ABI_SOFTFP 1,$(TARGET_TESTARCH)))
+ DASM_AFLAGS+= -D HFABI
+ TARGET_ARCH+= -DLJ_ABI_SOFTFP=0
+else
+ TARGET_ARCH+= -DLJ_ABI_SOFTFP=1
+endif
+ifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH)))
+ DASM_AFLAGS+= -D NO_UNWIND
+ TARGET_ARCH+= -DLUAJIT_NO_UNWIND
+endif
+DASM_AFLAGS+= -D VER=$(subst LJ_ARCH_VERSION_,,$(filter LJ_ARCH_VERSION_%,$(subst LJ_ARCH_VERSION ,LJ_ARCH_VERSION_,$(TARGET_TESTARCH))))
+ifeq (Windows,$(TARGET_SYS))
+ DASM_AFLAGS+= -D WIN
+endif
+ifeq (x86,$(TARGET_LJARCH))
+ ifneq (,$(findstring __SSE2__ 1,$(TARGET_TESTARCH)))
+ DASM_AFLAGS+= -D SSE
+ endif
+else
+ifeq (x64,$(TARGET_LJARCH))
+ DASM_ARCH= x86
+else
+ifeq (arm,$(TARGET_LJARCH))
+ ifeq (iOS,$(TARGET_SYS))
+ DASM_AFLAGS+= -D IOS
+ endif
+else
+ifeq (ppc,$(TARGET_LJARCH))
+ ifneq (,$(findstring LJ_ARCH_SQRT 1,$(TARGET_TESTARCH)))
+ DASM_AFLAGS+= -D SQRT
+ endif
+ ifneq (,$(findstring LJ_ARCH_ROUND 1,$(TARGET_TESTARCH)))
+ DASM_AFLAGS+= -D ROUND
+ endif
+ ifneq (,$(findstring LJ_ARCH_PPC64 1,$(TARGET_TESTARCH)))
+ DASM_AFLAGS+= -D GPR64
+ endif
+ ifeq (PS3,$(TARGET_SYS))
+ DASM_AFLAGS+= -D PPE -D TOC
+ endif
+endif
+endif
+endif
+endif
+
+DASM_FLAGS= $(DASM_XFLAGS) $(DASM_AFLAGS)
+DASM_DASC= vm_$(DASM_ARCH).dasc
+
+BUILDVM_O= host/buildvm.o host/buildvm_asm.o host/buildvm_peobj.o \
+ host/buildvm_lib.o host/buildvm_fold.o
+BUILDVM_T= host/buildvm
+BUILDVM_X= $(BUILDVM_T)
+
+HOST_O= $(MINILUA_O) $(BUILDVM_O)
+HOST_T= $(MINILUA_T) $(BUILDVM_T)
+
+LJVM_S= lj_vm.s
+LJVM_O= lj_vm.o
+LJVM_BOUT= $(LJVM_S)
+LJVM_MODE= elfasm
+
+LJLIB_O= lib_base.o lib_math.o lib_bit.o lib_string.o lib_table.o \
+ lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o lib_ffi.o
+LJLIB_C= $(LJLIB_O:.o=.c)
+
+LJCORE_O= lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o \
+ lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o lj_debug.o \
+ lj_state.o lj_dispatch.o lj_vmevent.o lj_vmmath.o lj_strscan.o \
+ lj_api.o lj_lex.o lj_parse.o lj_bcread.o lj_bcwrite.o lj_load.o \
+ lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \
+ lj_opt_dce.o lj_opt_loop.o lj_opt_split.o lj_opt_sink.o \
+ lj_mcode.o lj_snap.o lj_record.o lj_crecord.o lj_ffrecord.o \
+ lj_asm.o lj_trace.o lj_gdbjit.o \
+ lj_ctype.o lj_cdata.o lj_cconv.o lj_ccall.o lj_ccallback.o \
+ lj_carith.o lj_clib.o lj_cparse.o \
+ lj_lib.o lj_alloc.o lib_aux.o \
+ $(LJLIB_O) lib_init.o
+
+LJVMCORE_O= $(LJVM_O) $(LJCORE_O)
+LJVMCORE_DYNO= $(LJVMCORE_O:.o=_dyn.o)
+
+LIB_VMDEF= jit/vmdef.lua
+LIB_VMDEFP= $(LIB_VMDEF)
+
+LUAJIT_O= luajit.o
+LUAJIT_A= libluajit.a
+LUAJIT_SO= libluajit.so
+LUAJIT_T= luajit
+
+ALL_T= $(LUAJIT_T) $(LUAJIT_A) $(LUAJIT_SO) $(HOST_T)
+ALL_HDRGEN= lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h \
+ host/buildvm_arch.h
+ALL_GEN= $(LJVM_S) $(ALL_HDRGEN) $(LIB_VMDEFP)
+WIN_RM= *.obj *.lib *.exp *.dll *.exe *.manifest *.pdb *.ilk
+ALL_RM= $(ALL_T) $(ALL_GEN) *.o host/*.o $(WIN_RM)
+
+##############################################################################
+# Build mode handling.
+##############################################################################
+
+# Mixed mode defaults.
+TARGET_O= $(LUAJIT_A)
+TARGET_T= $(LUAJIT_T) $(LUAJIT_SO)
+TARGET_DEP= $(LIB_VMDEF) $(LUAJIT_SO)
+
+ifeq (Windows,$(TARGET_SYS))
+ TARGET_DYNCC= $(STATIC_CC)
+ LJVM_MODE= peobj
+ LJVM_BOUT= $(LJVM_O)
+ LUAJIT_T= luajit.exe
+ ifeq (cygwin,$(HOST_MSYS))
+ LUAJIT_SO= cyg$(TARGET_DLLNAME)
+ else
+ LUAJIT_SO= $(TARGET_DLLNAME)
+ endif
+ # Mixed mode is not supported on Windows. And static mode doesn't work well.
+ # C modules cannot be loaded, because they bind to lua51.dll.
+ ifneq (static,$(BUILDMODE))
+ BUILDMODE= dynamic
+ TARGET_XCFLAGS+= -DLUA_BUILD_AS_DLL
+ endif
+endif
+ifeq (Darwin,$(TARGET_SYS))
+ LJVM_MODE= machasm
+endif
+ifeq (iOS,$(TARGET_SYS))
+ LJVM_MODE= machasm
+endif
+ifeq (SunOS,$(TARGET_SYS))
+ BUILDMODE= static
+endif
+ifeq (PS3,$(TARGET_SYS))
+ BUILDMODE= static
+endif
+
+ifeq (Windows,$(HOST_SYS))
+ MINILUA_T= host/minilua.exe
+ BUILDVM_T= host/buildvm.exe
+ ifeq (,$(HOST_MSYS))
+ MINILUA_X= host\minilua
+ BUILDVM_X= host\buildvm
+ ALL_RM:= $(subst /,\,$(ALL_RM))
+ endif
+endif
+
+ifeq (static,$(BUILDMODE))
+ TARGET_DYNCC= @:
+ TARGET_T= $(LUAJIT_T)
+ TARGET_DEP= $(LIB_VMDEF)
+else
+ifeq (dynamic,$(BUILDMODE))
+ ifneq (Windows,$(TARGET_SYS))
+ TARGET_CC= $(DYNAMIC_CC)
+ endif
+ TARGET_DYNCC= @:
+ LJVMCORE_DYNO= $(LJVMCORE_O)
+ TARGET_O= $(LUAJIT_SO)
+ TARGET_XLDFLAGS+= $(TARGET_DYNXLDOPTS)
+else
+ifeq (Darwin,$(TARGET_SYS))
+ TARGET_DYNCC= @:
+ LJVMCORE_DYNO= $(LJVMCORE_O)
+endif
+ifeq (iOS,$(TARGET_SYS))
+ TARGET_DYNCC= @:
+ LJVMCORE_DYNO= $(LJVMCORE_O)
+endif
+endif
+endif
+
+Q= @
+E= @echo
+#Q=
+#E= @:
+
+##############################################################################
+# Make targets.
+##############################################################################
+
+default all: $(TARGET_T)
+
+amalg:
+ @grep "^[+|]" ljamalg.c
+ $(MAKE) all "LJCORE_O=ljamalg.o"
+
+clean:
+ $(HOST_RM) $(ALL_RM)
+
+depend:
+ @for file in $(ALL_HDRGEN); do \
+ test -f $$file || touch $$file; \
+ done
+ @$(HOST_CC) $(HOST_ACFLAGS) -MM *.c host/*.c | \
+ sed -e "s| [^ ]*/dasm_\S*\.h||g" \
+ -e "s|^\([^l ]\)|host/\1|" \
+ -e "s| lj_target_\S*\.h| lj_target_*.h|g" \
+ -e "s| lj_emit_\S*\.h| lj_emit_*.h|g" \
+ -e "s| lj_asm_\S*\.h| lj_asm_*.h|g" >Makefile.dep
+ @for file in $(ALL_HDRGEN); do \
+ test -s $$file || $(HOST_RM) $$file; \
+ done
+
+.PHONY: default all amalg clean depend
+
+##############################################################################
+# Rules for generated files.
+##############################################################################
+
+$(MINILUA_T): $(MINILUA_O)
+ $(E) "HOSTLINK $@"
+ $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(MINILUA_O) $(MINILUA_LIBS) $(HOST_ALIBS)
+
+host/buildvm_arch.h: $(DASM_DASC) $(DASM_DEP)
+ $(E) "DYNASM $@"
+ $(Q)$(DASM) $(DASM_FLAGS) -o $@ $(DASM_DASC)
+
+host/buildvm.o: $(DASM_DIR)/dasm_*.h
+
+$(BUILDVM_T): $(BUILDVM_O)
+ $(E) "HOSTLINK $@"
+ $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(BUILDVM_O) $(HOST_ALIBS)
+
+$(LJVM_BOUT): $(BUILDVM_T)
+ $(E) "BUILDVM $@"
+ $(Q)$(BUILDVM_X) -m $(LJVM_MODE) -o $@
+
+lj_bcdef.h: $(BUILDVM_T) $(LJLIB_C)
+ $(E) "BUILDVM $@"
+ $(Q)$(BUILDVM_X) -m bcdef -o $@ $(LJLIB_C)
+
+lj_ffdef.h: $(BUILDVM_T) $(LJLIB_C)
+ $(E) "BUILDVM $@"
+ $(Q)$(BUILDVM_X) -m ffdef -o $@ $(LJLIB_C)
+
+lj_libdef.h: $(BUILDVM_T) $(LJLIB_C)
+ $(E) "BUILDVM $@"
+ $(Q)$(BUILDVM_X) -m libdef -o $@ $(LJLIB_C)
+
+lj_recdef.h: $(BUILDVM_T) $(LJLIB_C)
+ $(E) "BUILDVM $@"
+ $(Q)$(BUILDVM_X) -m recdef -o $@ $(LJLIB_C)
+
+$(LIB_VMDEF): $(BUILDVM_T) $(LJLIB_C)
+ $(E) "BUILDVM $@"
+ $(Q)$(BUILDVM_X) -m vmdef -o $(LIB_VMDEFP) $(LJLIB_C)
+
+lj_folddef.h: $(BUILDVM_T) lj_opt_fold.c
+ $(E) "BUILDVM $@"
+ $(Q)$(BUILDVM_X) -m folddef -o $@ lj_opt_fold.c
+
+##############################################################################
+# Object file rules.
+##############################################################################
+
+%.o: %.c
+ $(E) "CC $@"
+ $(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $<
+ $(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $<
+
+%.o: %.s
+ $(E) "ASM $@"
+ $(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $<
+ $(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $<
+
+$(LUAJIT_O):
+ $(E) "CC $@"
+ $(Q)$(TARGET_STCC) $(TARGET_ACFLAGS) -c -o $@ $<
+
+$(HOST_O): %.o: %.c
+ $(E) "HOSTCC $@"
+ $(Q)$(HOST_CC) $(HOST_ACFLAGS) -c -o $@ $<
+
+include Makefile.dep
+
+##############################################################################
+# Target file rules.
+##############################################################################
+
+$(LUAJIT_A): $(LJVMCORE_O)
+ $(E) "AR $@"
+ $(Q)$(TARGET_AR) $@ $(LJVMCORE_O)
+
+# The dependency on _O, but linking with _DYNO is intentional.
+$(LUAJIT_SO): $(LJVMCORE_O)
+ $(E) "DYNLINK $@"
+ $(Q)$(TARGET_LD) $(TARGET_ASHLDFLAGS) -o $@ $(LJVMCORE_DYNO) $(TARGET_ALIBS)
+ $(Q)$(TARGET_STRIP) $@
+
+$(LUAJIT_T): $(TARGET_O) $(LUAJIT_O) $(TARGET_DEP)
+ $(E) "LINK $@"
+ $(Q)$(TARGET_LD) $(TARGET_ALDFLAGS) -o $@ $(LUAJIT_O) $(TARGET_O) $(TARGET_ALIBS)
+ $(Q)$(TARGET_STRIP) $@
+ $(E) "OK Successfully built LuaJIT"
+
+##############################################################################
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/Makefile.dep b/src/3rdparty/LuaJIT-2.0.5/src/Makefile.dep
new file mode 100644
index 0000000..9e14d61
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/Makefile.dep
@@ -0,0 +1,226 @@
+lib_aux.o: lib_aux.c lua.h luaconf.h lauxlib.h lj_obj.h lj_def.h \
+ lj_arch.h lj_err.h lj_errmsg.h lj_state.h lj_trace.h lj_jit.h lj_ir.h \
+ lj_dispatch.h lj_bc.h lj_traceerr.h lj_lib.h lj_alloc.h
+lib_base.o: lib_base.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \
+ lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h \
+ lj_tab.h lj_meta.h lj_state.h lj_ctype.h lj_cconv.h lj_bc.h lj_ff.h \
+ lj_ffdef.h lj_dispatch.h lj_jit.h lj_ir.h lj_char.h lj_strscan.h \
+ lj_lib.h lj_libdef.h
+lib_bit.o: lib_bit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \
+ lj_arch.h lj_err.h lj_errmsg.h lj_str.h lj_lib.h lj_libdef.h
+lib_debug.o: lib_debug.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \
+ lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_lib.h \
+ lj_libdef.h
+lib_ffi.o: lib_ffi.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \
+ lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_meta.h \
+ lj_ctype.h lj_cparse.h lj_cdata.h lj_cconv.h lj_carith.h lj_ccall.h \
+ lj_ccallback.h lj_clib.h lj_ff.h lj_ffdef.h lj_lib.h lj_libdef.h
+lib_init.o: lib_init.c lua.h luaconf.h lauxlib.h lualib.h lj_arch.h
+lib_io.o: lib_io.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \
+ lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_state.h lj_ff.h \
+ lj_ffdef.h lj_lib.h lj_libdef.h
+lib_jit.o: lib_jit.c lua.h luaconf.h lauxlib.h lualib.h lj_arch.h \
+ lj_obj.h lj_def.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h \
+ lj_bc.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_target.h \
+ lj_target_*.h lj_dispatch.h lj_vm.h lj_vmevent.h lj_lib.h luajit.h \
+ lj_libdef.h
+lib_math.o: lib_math.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \
+ lj_def.h lj_arch.h lj_lib.h lj_vm.h lj_libdef.h
+lib_os.o: lib_os.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \
+ lj_arch.h lj_err.h lj_errmsg.h lj_lib.h lj_libdef.h
+lib_package.o: lib_package.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \
+ lj_def.h lj_arch.h lj_err.h lj_errmsg.h lj_lib.h
+lib_string.o: lib_string.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \
+ lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h \
+ lj_meta.h lj_state.h lj_ff.h lj_ffdef.h lj_bcdump.h lj_lex.h lj_char.h \
+ lj_lib.h lj_libdef.h
+lib_table.o: lib_table.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \
+ lj_def.h lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_lib.h \
+ lj_libdef.h
+lj_alloc.o: lj_alloc.c lj_def.h lua.h luaconf.h lj_arch.h lj_alloc.h
+lj_api.o: lj_api.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
+ lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h lj_func.h lj_udata.h \
+ lj_meta.h lj_state.h lj_bc.h lj_frame.h lj_trace.h lj_jit.h lj_ir.h \
+ lj_dispatch.h lj_traceerr.h lj_vm.h lj_strscan.h
+lj_asm.o: lj_asm.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
+ lj_str.h lj_tab.h lj_frame.h lj_bc.h lj_ctype.h lj_ir.h lj_jit.h \
+ lj_ircall.h lj_iropt.h lj_mcode.h lj_trace.h lj_dispatch.h lj_traceerr.h \
+ lj_snap.h lj_asm.h lj_vm.h lj_target.h lj_target_*.h lj_emit_*.h \
+ lj_asm_*.h
+lj_bc.o: lj_bc.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_bc.h \
+ lj_bcdef.h
+lj_bcread.o: lj_bcread.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_bc.h lj_ctype.h \
+ lj_cdata.h lualib.h lj_lex.h lj_bcdump.h lj_state.h
+lj_bcwrite.o: lj_bcwrite.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_gc.h lj_str.h lj_bc.h lj_ctype.h lj_dispatch.h lj_jit.h lj_ir.h \
+ lj_bcdump.h lj_lex.h lj_err.h lj_errmsg.h lj_vm.h
+lj_carith.o: lj_carith.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_meta.h lj_ctype.h lj_cconv.h \
+ lj_cdata.h lj_carith.h
+lj_ccall.o: lj_ccall.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_cconv.h \
+ lj_cdata.h lj_ccall.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h lj_bc.h \
+ lj_traceerr.h
+lj_ccallback.o: lj_ccallback.c lj_obj.h lua.h luaconf.h lj_def.h \
+ lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_tab.h lj_state.h lj_frame.h \
+ lj_bc.h lj_ctype.h lj_cconv.h lj_ccall.h lj_ccallback.h lj_target.h \
+ lj_target_*.h lj_mcode.h lj_jit.h lj_ir.h lj_trace.h lj_dispatch.h \
+ lj_traceerr.h lj_vm.h
+lj_cconv.o: lj_cconv.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_err.h lj_errmsg.h lj_tab.h lj_ctype.h lj_gc.h lj_cdata.h lj_cconv.h \
+ lj_ccallback.h
+lj_cdata.o: lj_cdata.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_cconv.h \
+ lj_cdata.h
+lj_char.o: lj_char.c lj_char.h lj_def.h lua.h luaconf.h
+lj_clib.o: lj_clib.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
+ lj_err.h lj_errmsg.h lj_tab.h lj_str.h lj_udata.h lj_ctype.h lj_cconv.h \
+ lj_cdata.h lj_clib.h
+lj_cparse.o: lj_cparse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_ctype.h lj_cparse.h lj_frame.h \
+ lj_bc.h lj_vm.h lj_char.h lj_strscan.h
+lj_crecord.o: lj_crecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_frame.h lj_bc.h lj_ctype.h \
+ lj_gc.h lj_cdata.h lj_cparse.h lj_cconv.h lj_clib.h lj_ccall.h lj_ff.h \
+ lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \
+ lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h lj_snap.h \
+ lj_crecord.h
+lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_ccallback.h
+lj_debug.o: lj_debug.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h lj_state.h lj_frame.h \
+ lj_bc.h lj_vm.h lj_jit.h lj_ir.h
+lj_dispatch.o: lj_dispatch.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_err.h lj_errmsg.h lj_func.h lj_str.h lj_tab.h lj_meta.h lj_debug.h \
+ lj_state.h lj_frame.h lj_bc.h lj_ff.h lj_ffdef.h lj_jit.h lj_ir.h \
+ lj_ccallback.h lj_ctype.h lj_gc.h lj_trace.h lj_dispatch.h lj_traceerr.h \
+ lj_vm.h luajit.h
+lj_err.o: lj_err.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_err.h \
+ lj_errmsg.h lj_debug.h lj_str.h lj_func.h lj_state.h lj_frame.h lj_bc.h \
+ lj_ff.h lj_ffdef.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h \
+ lj_traceerr.h lj_vm.h
+lj_ffrecord.o: lj_ffrecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_frame.h lj_bc.h lj_ff.h \
+ lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \
+ lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h lj_crecord.h \
+ lj_vm.h lj_strscan.h lj_recdef.h
+lj_func.o: lj_func.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
+ lj_func.h lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h lj_bc.h \
+ lj_traceerr.h lj_vm.h
+lj_gc.o: lj_gc.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
+ lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_udata.h lj_meta.h \
+ lj_state.h lj_frame.h lj_bc.h lj_ctype.h lj_cdata.h lj_trace.h lj_jit.h \
+ lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h
+lj_gdbjit.o: lj_gdbjit.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_frame.h lj_bc.h lj_jit.h \
+ lj_ir.h lj_dispatch.h
+lj_ir.o: lj_ir.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
+ lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \
+ lj_dispatch.h lj_bc.h lj_traceerr.h lj_ctype.h lj_cdata.h lj_carith.h \
+ lj_vm.h lj_strscan.h lj_lib.h
+lj_lex.o: lj_lex.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
+ lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_ctype.h lj_cdata.h lualib.h \
+ lj_state.h lj_lex.h lj_parse.h lj_char.h lj_strscan.h
+lj_lib.o: lj_lib.c lauxlib.h lua.h luaconf.h lj_obj.h lj_def.h lj_arch.h \
+ lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_bc.h \
+ lj_dispatch.h lj_jit.h lj_ir.h lj_vm.h lj_strscan.h lj_lib.h
+lj_load.o: lj_load.c lua.h luaconf.h lauxlib.h lj_obj.h lj_def.h \
+ lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_func.h lj_frame.h \
+ lj_bc.h lj_vm.h lj_lex.h lj_bcdump.h lj_parse.h
+lj_mcode.o: lj_mcode.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_gc.h lj_err.h lj_errmsg.h lj_jit.h lj_ir.h lj_mcode.h lj_trace.h \
+ lj_dispatch.h lj_bc.h lj_traceerr.h lj_vm.h
+lj_meta.o: lj_meta.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
+ lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_meta.h lj_frame.h lj_bc.h \
+ lj_vm.h lj_strscan.h
+lj_obj.o: lj_obj.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h
+lj_opt_dce.o: lj_opt_dce.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_ir.h lj_jit.h lj_iropt.h
+lj_opt_fold.o: lj_opt_fold.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \
+ lj_bc.h lj_traceerr.h lj_ctype.h lj_gc.h lj_carith.h lj_vm.h \
+ lj_strscan.h lj_folddef.h
+lj_opt_loop.o: lj_opt_loop.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_err.h lj_errmsg.h lj_str.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h \
+ lj_dispatch.h lj_bc.h lj_traceerr.h lj_snap.h lj_vm.h
+lj_opt_mem.o: lj_opt_mem.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_tab.h lj_ir.h lj_jit.h lj_iropt.h
+lj_opt_narrow.o: lj_opt_narrow.c lj_obj.h lua.h luaconf.h lj_def.h \
+ lj_arch.h lj_bc.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \
+ lj_traceerr.h lj_vm.h lj_strscan.h
+lj_opt_sink.o: lj_opt_sink.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_ir.h lj_jit.h lj_iropt.h lj_target.h lj_target_*.h
+lj_opt_split.o: lj_opt_split.c lj_obj.h lua.h luaconf.h lj_def.h \
+ lj_arch.h lj_err.h lj_errmsg.h lj_str.h lj_ir.h lj_jit.h lj_ircall.h \
+ lj_iropt.h lj_vm.h
+lj_parse.o: lj_parse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h lj_func.h \
+ lj_state.h lj_bc.h lj_ctype.h lj_lex.h lj_parse.h lj_vm.h lj_vmevent.h
+lj_record.o: lj_record.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_meta.h lj_frame.h lj_bc.h \
+ lj_ctype.h lj_gc.h lj_ff.h lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h \
+ lj_iropt.h lj_trace.h lj_dispatch.h lj_traceerr.h lj_record.h \
+ lj_ffrecord.h lj_snap.h lj_vm.h
+lj_snap.o: lj_snap.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
+ lj_tab.h lj_state.h lj_frame.h lj_bc.h lj_ir.h lj_jit.h lj_iropt.h \
+ lj_trace.h lj_dispatch.h lj_traceerr.h lj_snap.h lj_target.h \
+ lj_target_*.h lj_ctype.h lj_cdata.h
+lj_state.o: lj_state.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h lj_meta.h \
+ lj_state.h lj_frame.h lj_bc.h lj_ctype.h lj_trace.h lj_jit.h lj_ir.h \
+ lj_dispatch.h lj_traceerr.h lj_vm.h lj_lex.h lj_alloc.h
+lj_str.o: lj_str.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
+ lj_err.h lj_errmsg.h lj_str.h lj_state.h lj_char.h
+lj_strscan.o: lj_strscan.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_char.h lj_strscan.h
+lj_tab.o: lj_tab.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
+ lj_err.h lj_errmsg.h lj_tab.h
+lj_trace.o: lj_trace.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_frame.h lj_bc.h \
+ lj_state.h lj_ir.h lj_jit.h lj_iropt.h lj_mcode.h lj_trace.h \
+ lj_dispatch.h lj_traceerr.h lj_snap.h lj_gdbjit.h lj_record.h lj_asm.h \
+ lj_vm.h lj_vmevent.h lj_target.h lj_target_*.h
+lj_udata.o: lj_udata.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_gc.h lj_udata.h
+lj_vmevent.o: lj_vmevent.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_str.h lj_tab.h lj_state.h lj_dispatch.h lj_bc.h lj_jit.h lj_ir.h \
+ lj_vm.h lj_vmevent.h
+lj_vmmath.o: lj_vmmath.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
+ lj_ir.h lj_vm.h
+ljamalg.o: ljamalg.c lua.h luaconf.h lauxlib.h lj_gc.c lj_obj.h lj_def.h \
+ lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_func.h \
+ lj_udata.h lj_meta.h lj_state.h lj_frame.h lj_bc.h lj_ctype.h lj_cdata.h \
+ lj_trace.h lj_jit.h lj_ir.h lj_dispatch.h lj_traceerr.h lj_vm.h lj_err.c \
+ lj_debug.h lj_ff.h lj_ffdef.h lj_char.c lj_char.h lj_bc.c lj_bcdef.h \
+ lj_obj.c lj_str.c lj_tab.c lj_func.c lj_udata.c lj_meta.c lj_strscan.h \
+ lj_debug.c lj_state.c lj_lex.h lj_alloc.h lj_dispatch.c lj_ccallback.h \
+ luajit.h lj_vmevent.c lj_vmevent.h lj_vmmath.c lj_strscan.c lj_api.c \
+ lj_lex.c lualib.h lj_parse.h lj_parse.c lj_bcread.c lj_bcdump.h \
+ lj_bcwrite.c lj_load.c lj_ctype.c lj_cdata.c lj_cconv.h lj_cconv.c \
+ lj_ccall.c lj_ccall.h lj_ccallback.c lj_target.h lj_target_*.h \
+ lj_mcode.h lj_carith.c lj_carith.h lj_clib.c lj_clib.h lj_cparse.c \
+ lj_cparse.h lj_lib.c lj_lib.h lj_ir.c lj_ircall.h lj_iropt.h \
+ lj_opt_mem.c lj_opt_fold.c lj_folddef.h lj_opt_narrow.c lj_opt_dce.c \
+ lj_opt_loop.c lj_snap.h lj_opt_split.c lj_opt_sink.c lj_mcode.c \
+ lj_snap.c lj_record.c lj_record.h lj_ffrecord.h lj_crecord.c \
+ lj_crecord.h lj_ffrecord.c lj_recdef.h lj_asm.c lj_asm.h lj_emit_*.h \
+ lj_asm_*.h lj_trace.c lj_gdbjit.h lj_gdbjit.c lj_alloc.c lib_aux.c \
+ lib_base.c lj_libdef.h lib_math.c lib_string.c lib_table.c lib_io.c \
+ lib_os.c lib_package.c lib_debug.c lib_bit.c lib_jit.c lib_ffi.c \
+ lib_init.c
+luajit.o: luajit.c lua.h luaconf.h lauxlib.h lualib.h luajit.h lj_arch.h
+host/buildvm.o: host/buildvm.c host/buildvm.h lj_def.h lua.h luaconf.h \
+ lj_arch.h lj_obj.h lj_def.h lj_arch.h lj_gc.h lj_obj.h lj_bc.h lj_ir.h \
+ lj_ircall.h lj_ir.h lj_jit.h lj_frame.h lj_bc.h lj_dispatch.h lj_ctype.h \
+ lj_gc.h lj_ccall.h lj_ctype.h luajit.h \
+ host/buildvm_arch.h lj_traceerr.h
+host/buildvm_asm.o: host/buildvm_asm.c host/buildvm.h lj_def.h lua.h luaconf.h \
+ lj_arch.h lj_bc.h lj_def.h lj_arch.h
+host/buildvm_fold.o: host/buildvm_fold.c host/buildvm.h lj_def.h lua.h \
+ luaconf.h lj_arch.h lj_obj.h lj_def.h lj_arch.h lj_ir.h lj_obj.h
+host/buildvm_lib.o: host/buildvm_lib.c host/buildvm.h lj_def.h lua.h luaconf.h \
+ lj_arch.h lj_obj.h lj_def.h lj_arch.h lj_lib.h lj_obj.h
+host/buildvm_peobj.o: host/buildvm_peobj.c host/buildvm.h lj_def.h lua.h \
+ luaconf.h lj_arch.h lj_bc.h lj_def.h lj_arch.h
+host/minilua.o: host/minilua.c
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/buildvm.lib b/src/3rdparty/LuaJIT-2.0.5/src/buildvm.lib
new file mode 100644
index 0000000..c7be727
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/buildvm.lib
Binary files differ
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/buildvm_arch.h b/src/3rdparty/LuaJIT-2.0.5/src/buildvm_arch.h
new file mode 100644
index 0000000..47a4ac9
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/buildvm_arch.h
@@ -0,0 +1,2144 @@
+/*
+** This file has been pre-processed with DynASM.
+** http://luajit.org/dynasm.html
+** DynASM version 1.3.0, DynASM x86 version 1.3.0
+** DO NOT EDIT! The original file is in "..\..\..\..\src\3rdparty\LuaJIT-2.0.5\src\vm_x86.dasc".
+*/
+
+#if DASM_VERSION != 10300
+#error "Version mismatch between DynASM and included encoding engine"
+#endif
+#define DASM_SECTION_CODE_OP 0
+#define DASM_SECTION_CODE_SUB 1
+#define DASM_MAXSECTION 2
+static const unsigned char build_actionlist[14067] = {
+ 254,1,248,10,252,247,198,237,15,132,244,11,131,230,252,248,41,252,242,141,
+ 76,49,252,248,139,114,252,252,199,68,10,4,237,248,12,131,192,1,15,132,244,
+ 13,137,68,36,20,252,247,198,237,15,132,244,14,248,15,129,252,246,239,252,
+ 247,198,237,15,133,244,10,199,131,233,237,131,230,252,248,41,214,252,247,
+ 222,131,232,1,15,132,244,248,248,1,255,139,44,10,137,106,252,248,139,108,
+ 10,4,137,106,252,252,131,194,8,131,232,1,15,133,244,1,248,2,139,108,36,48,
+ 137,181,233,248,3,139,68,36,20,139,76,36,56,248,4,57,193,15,133,244,252,248,
+ 5,131,252,234,8,137,149,233,248,16,139,76,36,52,137,141,233,49,192,248,17,
+ 131,196,28,91,94,95,93,195,248,6,15,130,244,253,59,149,233,15,135,244,254,
+ 199,66,252,252,237,255,131,194,8,131,192,1,252,233,244,4,248,7,133,201,15,
+ 132,244,5,41,193,141,20,202,252,233,244,5,248,8,137,149,233,137,68,36,20,
+ 137,202,137,252,233,232,251,1,0,139,149,233,252,233,244,3,248,13,176,235,
+ 252,233,244,18,248,19,137,208,137,204,248,18,139,108,36,48,139,173,233,199,
+ 133,233,237,255,252,233,244,17,248,20,248,21,129,225,239,137,204,248,22,139,
+ 108,36,48,185,252,248,252,255,252,255,252,255,184,237,139,149,233,139,157,
+ 233,129,195,239,139,114,252,252,199,66,252,252,237,199,131,233,237,252,233,
+ 244,12,248,23,186,237,252,233,244,248,248,24,255,131,232,8,252,233,244,247,
+ 248,25,141,68,194,252,248,248,1,15,182,142,233,131,198,4,137,149,233,137,
+ 133,233,137,116,36,24,137,202,248,2,137,252,233,232,251,1,0,139,149,233,139,
+ 133,233,139,106,252,248,41,208,193,232,3,131,192,1,139,181,233,139,14,15,
+ 182,252,233,15,182,205,131,198,4,252,255,36,171,248,26,85,87,86,83,131,252,
+ 236,28,139,108,36,48,139,76,36,52,190,237,49,192,141,188,253,36,233,139,157,
+ 233,129,195,239,137,189,233,137,68,36,24,137,68,36,52,56,133,233,15,132,244,
+ 249,255,199,131,233,237,136,133,233,139,149,233,139,133,233,41,200,193,232,
+ 3,131,192,1,41,209,139,114,252,252,137,68,36,20,252,247,198,237,15,132,244,
+ 14,252,233,244,15,248,27,85,87,86,83,131,252,236,28,190,237,252,233,244,247,
+ 248,28,85,87,86,83,131,252,236,28,190,237,248,1,139,108,36,48,139,76,36,52,
+ 139,189,233,137,124,36,52,137,108,36,24,137,165,233,248,2,255,139,157,233,
+ 129,195,239,248,3,199,131,233,237,139,149,233,1,206,41,214,139,133,233,41,
+ 200,193,232,3,131,192,1,248,29,139,105,252,248,129,121,253,252,252,239,15,
+ 133,244,30,248,31,137,202,137,114,252,252,139,181,233,139,14,15,182,252,233,
+ 15,182,205,131,198,4,252,255,36,171,248,32,85,87,86,83,131,252,236,28,139,
+ 108,36,48,139,68,36,56,139,76,36,52,139,84,36,60,137,108,36,24,139,189,233,
+ 43,189,233,199,68,36,60,0,0,0,0,137,124,36,56,137,68,36,8,137,76,36,4,137,
+ 44,36,139,189,233,137,124,36,52,137,165,233,252,255,210,133,192,15,132,244,
+ 16,255,137,193,190,237,252,233,244,2,248,11,1,209,131,230,252,248,137,213,
+ 41,252,242,199,68,193,252,252,237,137,200,139,117,252,244,139,77,252,240,
+ 131,252,249,1,15,134,244,247,139,122,252,248,139,191,233,139,191,233,252,
+ 255,225,248,1,15,132,244,33,41,213,193,252,237,3,141,69,252,255,252,233,244,
+ 34,248,35,15,182,78,252,255,131,252,237,16,141,12,202,41,252,233,15,132,244,
+ 36,252,247,217,193,252,233,3,137,76,36,8,139,72,4,139,0,137,77,4,137,69,0,
+ 137,108,36,4,252,233,244,37,248,38,255,137,68,36,16,199,68,36,20,237,141,
+ 68,36,16,128,126,252,252,235,15,133,244,247,141,139,233,137,41,199,65,4,237,
+ 137,205,252,233,244,248,248,39,15,182,70,252,254,137,68,36,12,219,68,36,12,
+ 221,92,36,16,141,68,36,16,252,233,244,247,248,40,15,182,70,252,254,141,4,
+ 194,248,1,15,182,110,252,255,141,44,252,234,248,2,137,108,36,4,139,108,36,
+ 48,137,68,36,8,137,44,36,137,149,233,137,116,36,24,232,251,1,1,139,149,233,
+ 133,192,15,132,244,249,248,36,15,182,78,252,253,139,104,4,139,0,137,108,202,
+ 4,137,4,202,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,
+ 248,3,255,139,141,233,137,113,252,244,141,177,233,41,214,139,105,252,248,
+ 184,237,252,233,244,31,248,41,137,68,36,16,199,68,36,20,237,141,68,36,16,
+ 128,126,252,252,235,15,133,244,247,141,139,233,137,41,199,65,4,237,137,205,
+ 252,233,244,248,248,42,15,182,70,252,254,137,68,36,12,219,68,36,12,221,92,
+ 36,16,141,68,36,16,252,233,244,247,248,43,15,182,70,252,254,141,4,194,248,
+ 1,15,182,110,252,255,141,44,252,234,248,2,255,137,108,36,4,139,108,36,48,
+ 137,68,36,8,137,44,36,137,149,233,137,116,36,24,232,251,1,2,139,149,233,133,
+ 192,15,132,244,249,15,182,78,252,253,139,108,202,4,139,12,202,137,104,4,137,
+ 8,248,44,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,
+ 248,3,139,141,233,137,113,252,244,15,182,70,252,253,139,108,194,4,139,4,194,
+ 137,105,20,137,65,16,141,177,233,41,214,139,105,252,248,184,237,252,233,244,
+ 31,248,45,15,182,110,252,252,141,4,194,141,12,202,137,108,36,12,139,108,36,
+ 48,137,68,36,8,137,76,36,4,137,44,36,137,149,233,137,116,36,24,232,251,1,
+ 3,248,3,139,149,233,131,252,248,1,15,135,244,46,248,4,141,118,4,15,130,244,
+ 252,248,5,255,15,183,70,252,254,141,180,253,134,233,248,6,139,6,15,182,204,
+ 15,182,232,131,198,4,193,232,16,252,255,36,171,248,47,131,198,4,129,120,253,
+ 4,239,15,130,244,5,252,233,244,6,248,48,129,120,253,4,239,252,233,244,4,248,
+ 49,131,252,238,4,137,108,36,12,139,108,36,48,137,68,36,8,137,76,36,4,137,
+ 44,36,137,149,233,137,116,36,24,232,251,1,4,252,233,244,3,248,50,131,252,
+ 238,4,139,108,36,48,137,149,233,137,252,233,139,86,252,252,137,116,36,24,
+ 232,251,1,5,252,233,244,3,248,51,248,52,255,141,4,199,252,233,244,247,248,
+ 53,248,54,141,4,199,141,44,252,234,149,252,233,244,248,248,55,141,4,194,137,
+ 197,252,233,244,248,248,56,248,57,141,4,194,248,1,141,44,252,234,248,2,141,
+ 12,202,137,108,36,8,139,108,36,48,137,68,36,12,15,182,70,252,252,137,76,36,
+ 4,137,68,36,16,137,44,36,137,149,233,137,116,36,24,232,251,1,6,139,149,233,
+ 133,192,15,132,244,44,248,46,137,193,41,208,137,113,252,244,141,176,233,184,
+ 237,255,252,233,244,29,248,58,139,108,36,48,137,149,233,141,20,194,137,252,
+ 233,137,116,36,24,232,251,1,7,139,149,233,255,133,192,15,133,244,46,15,183,
+ 70,252,254,139,12,194,252,233,244,59,255,252,233,244,46,255,248,60,141,76,
+ 202,8,248,30,137,76,36,20,137,68,36,16,131,252,233,8,141,4,193,139,108,36,
+ 48,137,76,36,4,137,68,36,8,137,44,36,137,149,233,137,116,36,24,232,251,1,
+ 8,139,149,233,139,76,36,20,139,68,36,16,139,105,252,248,131,192,1,57,215,
+ 15,132,244,61,137,202,137,114,252,252,139,181,233,139,14,15,182,252,233,15,
+ 182,205,131,198,4,252,255,36,171,248,62,139,108,36,48,137,149,233,137,202,
+ 137,252,233,137,116,36,24,232,251,1,9,139,149,233,139,70,252,252,15,182,204,
+ 15,182,232,193,232,16,252,255,164,253,171,233,248,63,129,252,248,239,15,130,
+ 244,64,139,106,4,129,252,253,239,15,131,244,64,139,114,252,252,137,68,36,
+ 20,137,106,252,252,139,42,137,106,252,248,131,232,2,15,132,244,248,255,137,
+ 209,248,1,131,193,8,139,105,4,137,105,252,252,139,41,137,105,252,248,131,
+ 232,1,15,133,244,1,248,2,139,68,36,20,252,233,244,65,248,66,129,252,248,239,
+ 15,130,244,64,139,106,4,184,237,252,247,213,57,232,15,71,197,248,2,139,106,
+ 252,248,139,132,253,197,233,139,114,252,252,199,66,252,252,237,137,66,252,
+ 248,252,233,244,67,248,68,129,252,248,239,15,130,244,64,255,139,106,4,139,
+ 114,252,252,129,252,253,239,15,133,244,252,248,1,139,42,139,173,233,248,2,
+ 133,252,237,199,66,252,252,237,15,132,244,67,139,131,233,199,66,252,252,237,
+ 137,106,252,248,139,141,233,35,136,233,105,201,239,3,141,233,248,3,129,185,
+ 233,239,15,133,244,250,255,57,129,233,15,132,244,251,248,4,139,137,233,133,
+ 201,15,133,244,3,252,233,244,67,248,5,139,105,4,129,252,253,239,15,132,244,
+ 67,139,1,137,106,252,252,137,66,252,248,252,233,244,67,248,6,129,252,253,
+ 239,15,132,244,1,129,252,253,239,255,15,135,244,254,189,237,248,8,252,247,
+ 213,139,172,253,171,233,252,233,244,2,248,69,129,252,248,239,15,130,244,64,
+ 129,122,253,4,239,15,133,244,64,139,42,131,189,233,0,15,133,244,64,129,122,
+ 253,12,239,15,133,244,64,255,139,66,8,137,133,233,139,114,252,252,199,66,
+ 252,252,237,137,106,252,248,252,246,133,233,235,15,132,244,247,128,165,233,
+ 235,139,131,233,137,171,233,137,133,233,248,1,252,233,244,67,248,70,129,252,
+ 248,239,15,130,244,64,129,122,253,4,239,15,133,244,64,255,139,2,139,108,36,
+ 48,137,68,36,4,137,44,36,137,213,131,194,8,137,84,36,8,232,251,1,10,137,252,
+ 234,139,40,139,64,4,139,114,252,252,137,106,252,248,137,66,252,252,252,233,
+ 244,67,248,71,129,252,248,239,15,133,244,64,129,122,253,4,239,15,131,244,
+ 64,221,2,252,233,244,72,248,73,129,252,248,239,15,130,244,64,139,114,252,
+ 252,129,122,253,4,239,15,133,244,249,139,2,248,2,199,66,252,252,237,255,137,
+ 66,252,248,252,233,244,67,248,3,129,122,253,4,239,15,135,244,64,131,187,233,
+ 0,15,133,244,64,139,171,233,59,171,233,15,130,244,247,232,244,74,248,1,139,
+ 108,36,48,137,149,233,137,116,36,24,137,252,233,232,251,1,11,139,149,233,
+ 252,233,244,2,248,75,255,129,252,248,239,15,130,244,64,15,132,244,248,248,
+ 1,129,122,253,4,239,15,133,244,64,139,108,36,48,137,149,233,137,149,233,139,
+ 114,252,252,139,2,137,68,36,4,137,44,36,131,194,8,137,84,36,8,137,116,36,
+ 24,232,251,1,12,139,149,233,133,192,15,132,244,249,139,106,8,139,66,12,137,
+ 106,252,248,137,66,252,252,139,106,16,139,66,20,137,42,137,66,4,248,76,184,
+ 237,252,233,244,77,248,2,199,66,12,237,255,252,233,244,1,248,3,199,66,252,
+ 252,237,252,233,244,67,248,78,129,252,248,239,15,130,244,64,139,42,129,122,
+ 253,4,239,15,133,244,64,255,131,189,233,0,15,133,244,64,255,139,106,252,248,
+ 139,133,233,139,114,252,252,199,66,252,252,237,137,66,252,248,199,66,12,237,
+ 184,237,252,233,244,77,248,79,129,252,248,239,15,130,244,64,129,122,253,4,
+ 239,15,133,244,64,129,122,253,12,239,15,131,244,64,139,114,252,252,221,66,
+ 8,217,232,222,193,219,20,36,221,90,252,248,139,4,36,139,42,59,133,233,15,
+ 131,244,248,193,224,3,3,133,233,248,1,255,129,120,253,4,239,15,132,244,80,
+ 139,40,139,64,4,137,42,137,66,4,252,233,244,76,248,2,131,189,233,0,15,132,
+ 244,80,137,252,233,137,213,137,194,232,251,1,13,137,252,234,133,192,15,133,
+ 244,1,248,80,184,237,252,233,244,77,248,81,129,252,248,239,15,130,244,64,
+ 139,42,129,122,253,4,239,255,139,106,252,248,139,133,233,139,114,252,252,
+ 199,66,252,252,237,137,66,252,248,217,252,238,221,90,8,184,237,252,233,244,
+ 77,248,82,129,252,248,239,15,130,244,64,141,74,8,131,232,1,190,237,248,1,
+ 15,182,171,233,193,252,237,235,131,229,1,1,252,238,252,233,244,29,248,83,
+ 129,252,248,239,15,130,244,64,129,122,253,12,239,255,15,133,244,64,139,106,
+ 4,137,106,12,199,66,4,237,139,42,139,114,8,137,106,8,137,50,141,74,16,131,
+ 232,2,190,237,252,233,244,1,248,84,129,252,248,239,15,130,244,64,139,42,139,
+ 114,252,252,137,116,36,24,137,44,36,129,122,253,4,239,15,133,244,64,131,189,
+ 233,0,15,133,244,64,128,189,233,235,15,135,244,64,255,139,141,233,15,132,
+ 244,247,59,141,233,15,132,244,64,248,1,141,116,193,252,240,59,181,233,15,
+ 135,244,64,137,181,233,139,108,36,48,137,149,233,131,194,8,137,149,233,141,
+ 108,194,232,41,252,245,57,206,15,132,244,249,248,2,139,68,46,4,137,70,252,
+ 252,139,4,46,137,70,252,248,131,252,238,8,57,206,15,133,244,2,248,3,137,76,
+ 36,4,49,201,137,76,36,12,137,76,36,8,232,244,26,255,199,131,233,237,139,108,
+ 36,48,139,52,36,139,149,233,129,252,248,239,15,135,244,254,248,4,139,142,
+ 233,139,190,233,137,142,233,137,252,254,41,206,15,132,244,252,141,4,50,193,
+ 252,238,3,59,133,233,15,135,244,255,137,213,41,205,248,5,139,1,137,4,41,139,
+ 65,4,137,68,41,4,131,193,8,57,252,249,15,133,244,5,248,6,141,70,2,199,66,
+ 252,252,237,248,7,255,139,116,36,24,137,68,36,20,185,252,248,252,255,252,
+ 255,252,255,252,247,198,237,15,132,244,14,252,233,244,15,248,8,199,66,252,
+ 252,237,139,142,233,131,252,233,8,137,142,233,139,1,137,2,139,65,4,137,66,
+ 4,184,237,252,233,244,7,248,9,139,12,36,137,185,233,137,252,242,137,252,233,
+ 232,251,1,0,139,52,36,139,149,233,252,233,244,4,248,85,139,106,252,248,139,
+ 173,233,139,114,252,252,137,116,36,24,137,44,36,131,189,233,0,255,15,133,
+ 244,64,128,189,233,235,15,135,244,64,139,141,233,15,132,244,247,59,141,233,
+ 15,132,244,64,248,1,141,116,193,252,248,59,181,233,15,135,244,64,137,181,
+ 233,139,108,36,48,137,149,233,137,149,233,141,108,194,252,240,41,252,245,
+ 57,206,15,132,244,249,248,2,255,139,68,46,4,137,70,252,252,139,4,46,137,70,
+ 252,248,131,252,238,8,57,206,15,133,244,2,248,3,137,76,36,4,49,201,137,76,
+ 36,12,137,76,36,8,232,244,26,199,131,233,237,139,108,36,48,139,52,36,139,
+ 149,233,129,252,248,239,15,135,244,254,248,4,139,142,233,139,190,233,137,
+ 142,233,137,252,254,41,206,15,132,244,252,141,4,50,193,252,238,3,59,133,233,
+ 15,135,244,255,255,137,213,41,205,248,5,139,1,137,4,41,139,65,4,137,68,41,
+ 4,131,193,8,57,252,249,15,133,244,5,248,6,141,70,1,248,7,139,116,36,24,137,
+ 68,36,20,49,201,252,247,198,237,15,132,244,14,252,233,244,15,248,8,137,252,
+ 242,137,252,233,232,251,1,14,248,9,139,12,36,137,185,233,137,252,242,137,
+ 252,233,232,251,1,0,139,52,36,139,149,233,252,233,244,4,248,86,139,108,36,
+ 48,252,247,133,233,237,15,132,244,64,255,137,149,233,141,68,194,252,248,137,
+ 133,233,49,192,137,133,233,176,235,136,133,233,252,233,244,17,248,87,248,
+ 88,129,252,248,239,15,130,244,64,129,122,253,4,239,15,131,244,64,221,2,217,
+ 225,248,89,248,72,139,114,252,252,221,90,252,248,248,67,184,237,248,77,255,
+ 137,68,36,20,248,65,252,247,198,237,15,133,244,253,248,5,56,70,252,255,15,
+ 135,244,252,15,182,78,252,253,252,247,209,141,20,202,139,6,15,182,204,15,
+ 182,232,131,198,4,193,232,16,252,255,36,171,248,6,199,68,194,252,244,237,
+ 131,192,1,252,233,244,5,248,7,185,252,248,252,255,252,255,252,255,252,233,
+ 244,15,248,90,129,122,253,4,239,15,131,244,64,221,2,232,244,91,255,252,233,
+ 244,72,248,92,129,122,253,4,239,15,131,244,64,221,2,232,244,93,252,233,244,
+ 72,248,94,129,252,248,239,15,130,244,64,129,122,253,4,239,15,131,244,64,221,
+ 2,217,252,250,252,233,244,72,248,95,255,129,252,248,239,15,133,244,64,129,
+ 122,253,4,239,15,131,244,64,217,252,237,221,2,217,252,241,252,233,244,72,
+ 248,96,129,252,248,239,15,130,244,64,129,122,253,4,239,15,131,244,64,217,
+ 252,236,221,2,217,252,241,252,233,244,72,248,97,129,252,248,239,15,130,244,
+ 64,255,129,122,253,4,239,15,131,244,64,221,2,232,244,98,252,233,244,72,248,
+ 99,129,252,248,239,15,130,244,64,129,122,253,4,239,15,131,244,64,221,2,217,
+ 252,254,252,233,244,72,248,100,129,252,248,239,15,130,244,64,255,129,122,
+ 253,4,239,15,131,244,64,221,2,217,252,255,252,233,244,72,248,101,129,252,
+ 248,239,15,130,244,64,129,122,253,4,239,15,131,244,64,221,2,217,252,242,221,
+ 216,252,233,244,72,248,102,129,252,248,239,15,130,244,64,129,122,253,4,239,
+ 15,131,244,64,255,221,2,217,192,216,200,217,232,222,225,217,252,250,217,252,
+ 243,252,233,244,72,248,103,129,252,248,239,15,130,244,64,129,122,253,4,239,
+ 15,131,244,64,221,2,217,192,216,200,217,232,222,225,217,252,250,217,201,217,
+ 252,243,252,233,244,72,248,104,129,252,248,239,15,130,244,64,129,122,253,
+ 4,239,15,131,244,64,221,2,217,232,217,252,243,252,233,244,72,248,105,255,
+ 129,252,248,239,15,130,244,64,129,122,253,4,239,15,131,244,64,221,2,221,28,
+ 36,137,213,232,251,1,15,137,252,234,252,233,244,72,248,106,129,252,248,239,
+ 15,130,244,64,129,122,253,4,239,15,131,244,64,221,2,221,28,36,137,213,232,
+ 251,1,16,137,252,234,252,233,244,72,248,107,129,252,248,239,15,130,244,64,
+ 255,129,122,253,4,239,15,131,244,64,221,2,221,28,36,137,213,232,251,1,17,
+ 137,252,234,252,233,244,72,248,108,248,109,129,252,248,239,15,130,244,64,
+ 129,122,253,4,239,15,131,244,64,221,2,139,106,252,248,220,141,233,252,233,
+ 244,72,248,110,129,252,248,239,15,130,244,64,255,129,122,253,4,239,15,131,
+ 244,64,129,122,253,12,239,15,131,244,64,221,2,221,66,8,217,252,243,252,233,
+ 244,72,248,111,129,252,248,239,15,130,244,64,129,122,253,4,239,15,131,244,
+ 64,129,122,253,12,239,15,131,244,64,221,66,8,221,2,217,252,253,221,217,252,
+ 233,244,72,248,112,255,129,252,248,239,15,130,244,64,139,106,4,129,252,253,
+ 239,15,131,244,64,139,114,252,252,139,2,137,106,252,252,137,66,252,248,209,
+ 229,129,252,253,0,0,224,252,255,15,131,244,249,9,232,15,132,244,249,184,252,
+ 254,3,0,0,129,252,253,0,0,32,0,15,130,244,250,248,1,193,252,237,21,41,197,
+ 137,108,36,16,219,68,36,16,139,106,252,252,129,229,252,255,252,255,15,128,
+ 129,205,0,0,224,63,137,106,252,252,248,2,221,26,184,237,252,233,244,77,248,
+ 3,217,252,238,252,233,244,2,248,4,255,221,2,199,68,36,16,0,0,128,90,216,76,
+ 36,16,221,90,252,248,139,106,252,252,184,52,4,0,0,209,229,252,233,244,1,248,
+ 113,129,252,248,239,15,130,244,64,129,122,253,4,239,15,131,244,64,221,2,139,
+ 106,4,139,114,252,252,209,229,129,252,253,0,0,224,252,255,15,132,244,250,
+ 217,192,232,244,114,220,252,233,248,1,221,90,252,248,221,26,139,66,252,252,
+ 139,106,4,49,232,15,136,244,249,248,2,184,237,252,233,244,77,248,3,255,129,
+ 252,245,0,0,0,128,137,106,4,252,233,244,2,248,4,217,252,238,217,201,252,233,
+ 244,1,248,115,129,252,248,239,15,130,244,64,129,122,253,4,239,15,131,244,
+ 64,129,122,253,12,239,15,131,244,64,221,66,8,221,2,248,1,217,252,248,223,
+ 224,102,37,0,4,15,133,244,1,221,217,252,233,244,72,248,116,255,129,252,248,
+ 239,15,130,244,64,129,122,253,4,239,15,131,244,64,129,122,253,12,239,15,131,
+ 244,64,221,2,221,66,8,232,244,117,252,233,244,72,248,118,185,2,0,0,0,129,
+ 122,253,4,239,15,131,244,64,221,2,248,5,57,193,15,131,244,72,255,129,124,
+ 253,202,252,252,239,15,131,244,255,248,6,221,68,202,252,248,248,7,219,252,
+ 233,219,209,221,217,131,193,1,252,233,244,5,248,119,185,2,0,0,0,129,122,253,
+ 4,239,15,131,244,64,221,2,248,5,57,193,15,131,244,72,129,124,253,202,252,
+ 252,239,15,131,244,255,248,6,221,68,202,252,248,248,7,219,252,233,218,209,
+ 221,217,131,193,1,252,233,244,5,248,9,255,221,216,252,233,244,64,248,120,
+ 129,252,248,239,15,130,244,64,129,122,253,4,239,15,133,244,64,139,42,219,
+ 133,233,252,233,244,72,248,121,129,252,248,239,15,133,244,64,129,122,253,
+ 4,239,15,133,244,64,139,42,139,114,252,252,131,189,233,1,255,15,130,244,80,
+ 15,182,173,233,137,108,36,16,219,68,36,16,252,233,244,72,248,122,139,171,
+ 233,59,171,233,15,130,244,247,232,244,74,248,1,129,252,248,239,15,133,244,
+ 64,129,122,253,4,239,15,131,244,64,221,2,219,92,36,20,129,124,36,20,252,255,
+ 0,0,0,15,135,244,64,255,199,68,36,8,1,0,0,0,141,68,36,20,248,123,139,108,
+ 36,48,137,149,233,137,68,36,4,137,44,36,137,116,36,24,232,251,1,18,139,149,
+ 233,139,114,252,252,199,66,252,252,237,137,66,252,248,252,233,244,67,248,
+ 124,139,171,233,59,171,233,15,130,244,247,232,244,74,248,1,199,68,36,20,252,
+ 255,252,255,252,255,252,255,129,252,248,239,15,130,244,64,15,134,244,247,
+ 129,122,253,20,239,255,15,131,244,64,221,66,16,219,92,36,20,248,1,129,122,
+ 253,4,239,15,133,244,64,129,122,253,12,239,15,131,244,64,139,42,137,108,36,
+ 12,139,173,233,221,66,8,219,92,36,8,139,76,36,8,139,68,36,20,57,197,15,130,
+ 244,251,248,2,133,201,15,142,244,253,248,3,139,108,36,12,41,200,15,140,244,
+ 125,141,172,253,13,233,131,192,1,248,4,255,137,68,36,8,137,232,252,233,244,
+ 123,248,5,15,140,244,252,141,68,40,1,252,233,244,2,248,6,137,232,252,233,
+ 244,2,248,7,15,132,244,254,1,252,233,131,193,1,15,143,244,3,248,8,185,1,0,
+ 0,0,252,233,244,3,248,125,49,192,252,233,244,4,248,126,255,139,171,233,59,
+ 171,233,15,130,244,247,232,244,74,248,1,129,252,248,239,15,133,244,64,129,
+ 122,253,4,239,15,133,244,64,129,122,253,12,239,139,42,15,131,244,64,221,66,
+ 8,219,92,36,20,139,68,36,20,133,192,15,142,244,125,131,189,233,1,15,130,244,
+ 125,255,15,133,244,127,57,131,233,15,130,244,127,15,182,141,233,139,171,233,
+ 137,68,36,8,248,1,136,77,0,131,197,1,131,232,1,15,133,244,1,139,131,233,252,
+ 233,244,123,248,128,129,252,248,239,15,130,244,64,139,171,233,59,171,233,
+ 15,130,244,247,255,232,244,74,248,1,129,122,253,4,239,15,133,244,64,139,42,
+ 139,133,233,133,192,15,132,244,125,57,131,233,15,130,244,129,129,197,239,
+ 137,116,36,20,137,68,36,8,139,179,233,248,1,15,182,77,0,131,197,1,131,232,
+ 1,136,12,6,15,133,244,1,137,252,240,139,116,36,20,252,233,244,123,248,130,
+ 255,129,252,248,239,15,130,244,64,139,171,233,59,171,233,15,130,244,247,232,
+ 244,74,248,1,129,122,253,4,239,15,133,244,64,139,42,139,133,233,57,131,233,
+ 15,130,244,129,129,197,239,137,116,36,20,137,68,36,8,139,179,233,252,233,
+ 244,249,248,1,255,15,182,76,5,0,131,252,249,65,15,130,244,248,131,252,249,
+ 90,15,135,244,248,131,252,241,32,248,2,136,12,6,248,3,131,232,1,15,137,244,
+ 1,137,252,240,139,116,36,20,252,233,244,123,248,131,129,252,248,239,15,130,
+ 244,64,139,171,233,59,171,233,15,130,244,247,232,244,74,248,1,255,129,122,
+ 253,4,239,15,133,244,64,139,42,139,133,233,57,131,233,15,130,244,129,129,
+ 197,239,137,116,36,20,137,68,36,8,139,179,233,252,233,244,249,248,1,15,182,
+ 76,5,0,131,252,249,97,15,130,244,248,131,252,249,122,15,135,244,248,131,252,
+ 241,32,248,2,136,12,6,248,3,131,232,1,15,137,244,1,255,137,252,240,139,116,
+ 36,20,252,233,244,123,248,132,129,252,248,239,15,130,244,64,129,122,253,4,
+ 239,15,133,244,64,137,213,139,10,232,251,1,19,137,252,234,137,4,36,219,4,
+ 36,252,233,244,72,248,133,129,252,248,239,15,130,244,64,129,122,253,4,239,
+ 15,131,244,64,221,2,199,68,36,16,0,0,192,89,216,68,36,16,221,28,36,248,2,
+ 219,4,36,252,233,244,72,248,134,255,129,252,248,239,15,130,244,64,199,68,
+ 36,16,0,0,192,89,129,122,253,4,239,15,131,244,64,221,2,216,68,36,16,221,28,
+ 36,139,44,36,248,2,137,68,36,20,141,68,194,252,240,248,1,57,208,15,134,244,
+ 135,129,120,253,4,239,15,131,244,136,221,0,216,68,36,16,221,28,36,35,44,36,
+ 131,232,8,252,233,244,1,248,137,129,252,248,239,15,130,244,64,199,68,36,16,
+ 0,0,192,89,129,122,253,4,239,255,15,131,244,64,221,2,216,68,36,16,221,28,
+ 36,139,44,36,248,2,137,68,36,20,141,68,194,252,240,248,1,57,208,15,134,244,
+ 135,129,120,253,4,239,15,131,244,136,221,0,216,68,36,16,221,28,36,11,44,36,
+ 131,232,8,252,233,244,1,248,138,129,252,248,239,15,130,244,64,199,68,36,16,
+ 0,0,192,89,129,122,253,4,239,15,131,244,64,221,2,216,68,36,16,221,28,36,139,
+ 44,36,248,2,137,68,36,20,141,68,194,252,240,248,1,255,57,208,15,134,244,135,
+ 129,120,253,4,239,15,131,244,136,221,0,216,68,36,16,221,28,36,51,44,36,131,
+ 232,8,252,233,244,1,248,139,129,252,248,239,15,130,244,64,129,122,253,4,239,
+ 15,131,244,64,221,2,199,68,36,16,0,0,192,89,216,68,36,16,221,28,36,139,44,
+ 36,248,2,15,205,252,233,244,135,248,140,129,252,248,239,15,130,244,64,255,
+ 129,122,253,4,239,15,131,244,64,221,2,199,68,36,16,0,0,192,89,216,68,36,16,
+ 221,28,36,139,44,36,248,2,252,247,213,248,135,137,44,36,219,4,36,252,233,
+ 244,72,248,136,139,68,36,20,252,233,244,64,248,141,129,252,248,239,15,130,
+ 244,64,129,122,253,4,239,15,131,244,64,129,122,253,12,239,15,131,244,64,255,
+ 221,2,221,66,8,199,68,36,16,0,0,192,89,216,68,36,16,221,92,36,8,216,68,36,
+ 16,221,28,36,139,76,36,8,139,44,36,211,229,252,233,244,135,248,142,129,252,
+ 248,239,15,130,244,64,129,122,253,4,239,15,131,244,64,129,122,253,12,239,
+ 15,131,244,64,221,2,221,66,8,199,68,36,16,0,0,192,89,216,68,36,16,221,92,
+ 36,8,216,68,36,16,221,28,36,139,76,36,8,139,44,36,211,252,237,252,233,244,
+ 135,248,143,129,252,248,239,15,130,244,64,129,122,253,4,239,15,131,244,64,
+ 255,129,122,253,12,239,15,131,244,64,221,2,221,66,8,199,68,36,16,0,0,192,
+ 89,216,68,36,16,221,92,36,8,216,68,36,16,221,28,36,139,76,36,8,139,44,36,
+ 211,252,253,252,233,244,135,248,144,129,252,248,239,15,130,244,64,129,122,
+ 253,4,239,15,131,244,64,129,122,253,12,239,15,131,244,64,221,2,221,66,8,199,
+ 68,36,16,0,0,192,89,216,68,36,16,221,92,36,8,216,68,36,16,221,28,36,139,76,
+ 36,8,139,44,36,211,197,252,233,244,135,248,145,129,252,248,239,15,130,244,
+ 64,255,129,122,253,4,239,15,131,244,64,129,122,253,12,239,15,131,244,64,221,
+ 2,221,66,8,199,68,36,16,0,0,192,89,216,68,36,16,221,92,36,8,216,68,36,16,
+ 221,28,36,139,76,36,8,139,44,36,211,205,252,233,244,135,248,127,184,237,252,
+ 233,244,64,248,129,184,237,248,64,139,108,36,48,139,114,252,252,137,116,36,
+ 24,137,149,233,141,68,194,252,248,141,136,233,137,133,233,139,66,252,248,
+ 59,141,233,15,135,244,251,255,137,44,36,252,255,144,233,139,149,233,133,192,
+ 15,143,244,77,248,1,139,141,233,41,209,193,252,233,3,133,192,141,65,1,139,
+ 106,252,248,15,133,244,34,139,181,233,139,14,15,182,252,233,15,182,205,131,
+ 198,4,252,255,36,171,248,34,137,209,252,247,198,237,15,133,244,249,15,182,
+ 110,252,253,252,247,213,141,20,252,234,252,233,244,29,248,3,137,252,245,131,
+ 229,252,248,41,252,234,252,233,244,29,248,5,186,237,255,137,252,233,232,251,
+ 1,0,139,149,233,49,192,252,233,244,1,248,74,93,137,108,36,16,139,108,36,48,
+ 137,116,36,24,137,149,233,141,68,194,252,248,137,252,233,137,133,233,232,
+ 251,1,20,139,149,233,139,133,233,41,208,193,232,3,131,192,1,139,108,36,16,
+ 85,195,248,146,15,182,131,233,168,235,15,133,244,251,168,235,15,133,244,247,
+ 168,235,15,132,244,247,252,255,139,233,255,252,233,244,247,248,147,15,182,
+ 131,233,168,235,15,133,244,251,252,233,244,247,248,148,15,182,131,233,168,
+ 235,15,133,244,251,168,235,15,132,244,251,252,255,139,233,15,132,244,247,
+ 255,168,235,15,132,244,251,248,1,139,108,36,48,137,149,233,137,252,242,137,
+ 252,233,232,251,1,21,248,3,139,149,233,248,4,15,182,78,252,253,248,5,15,182,
+ 110,252,252,15,183,70,252,254,252,255,164,253,171,233,248,149,131,198,4,139,
+ 77,232,137,76,36,20,252,233,244,4,248,150,139,106,252,248,139,173,233,15,
+ 182,133,233,141,4,194,139,108,36,48,137,149,233,137,133,233,137,252,242,141,
+ 139,233,137,171,233,255,137,116,36,24,232,251,1,22,252,233,244,3,248,151,
+ 137,116,36,24,252,233,244,247,248,152,137,116,36,24,131,206,1,248,1,141,68,
+ 194,252,248,139,108,36,48,137,149,233,137,133,233,137,252,242,137,252,233,
+ 232,251,1,23,199,68,36,24,0,0,0,0,131,230,252,254,139,149,233,137,193,139,
+ 133,233,41,208,137,205,15,182,78,252,253,193,232,3,131,192,1,252,255,229,
+ 248,153,85,141,108,36,12,85,83,82,81,80,15,182,69,252,252,138,101,252,248,
+ 137,125,252,252,137,117,252,248,139,93,0,139,139,233,199,131,233,237,137,
+ 131,233,137,139,233,129,252,236,239,252,242,15,17,125,216,252,242,15,17,117,
+ 208,252,242,15,17,109,200,252,242,15,17,101,192,252,242,15,17,93,184,252,
+ 242,15,17,85,176,252,242,15,17,77,168,252,242,15,17,69,160,139,171,233,139,
+ 147,233,255,137,171,233,199,131,233,0,0,0,0,137,149,233,141,84,36,16,141,
+ 139,233,232,251,1,24,139,141,233,129,225,239,137,204,137,169,233,139,149,
+ 233,139,177,233,248,154,133,192,15,136,244,249,137,68,36,20,139,122,252,248,
+ 139,191,233,139,191,233,199,131,233,0,0,0,0,199,131,233,237,139,6,15,182,
+ 204,15,182,232,131,198,4,193,232,16,129,252,253,239,15,130,244,248,255,139,
+ 68,36,20,248,2,252,255,36,171,248,3,252,247,216,137,252,233,137,194,232,251,
+ 1,25,248,91,217,124,36,4,137,68,36,8,102,184,0,4,102,11,68,36,4,102,37,252,
+ 255,252,247,102,137,68,36,6,217,108,36,6,217,252,252,217,108,36,4,139,68,
+ 36,8,195,248,155,102,15,252,239,210,102,15,118,210,102,15,115,210,1,184,0,
+ 0,48,67,102,15,110,216,102,15,112,219,81,15,40,200,102,15,84,202,102,15,46,
+ 217,15,134,244,247,102,15,85,208,252,242,15,88,203,252,242,15,92,203,102,
+ 15,86,202,184,0,0,252,240,63,102,15,110,208,102,15,112,210,81,252,242,15,
+ 194,193,1,102,15,84,194,252,242,15,92,200,15,40,193,248,1,195,248,93,217,
+ 124,36,4,137,68,36,8,102,184,0,8,102,11,68,36,4,102,37,252,255,252,251,102,
+ 137,68,36,6,217,108,36,6,217,252,252,217,108,36,4,139,68,36,8,195,248,156,
+ 102,15,252,239,210,102,15,118,210,102,15,115,210,1,184,0,0,48,67,102,15,110,
+ 216,102,15,112,219,81,15,40,200,102,15,84,202,102,15,46,217,15,134,244,247,
+ 102,15,85,208,252,242,15,88,203,252,242,15,92,203,102,15,86,202,184,0,0,252,
+ 240,191,102,15,110,208,102,15,112,210,81,252,242,15,194,193,6,102,15,84,194,
+ 252,242,15,92,200,15,40,193,248,1,195,248,114,217,124,36,4,137,68,36,8,102,
+ 184,0,12,102,11,68,36,4,102,137,68,36,6,217,108,36,6,217,252,252,217,108,
+ 36,4,139,68,36,8,195,248,157,102,15,252,239,210,102,15,118,210,102,15,115,
+ 210,1,184,0,0,48,67,102,15,110,216,102,15,112,219,81,15,40,200,102,15,84,
+ 202,102,15,46,217,15,134,244,247,102,15,85,208,15,40,193,252,242,15,88,203,
+ 252,242,15,92,203,184,0,0,252,240,63,102,15,110,216,102,15,112,219,81,252,
+ 242,15,194,193,1,102,15,84,195,252,242,15,92,200,102,15,86,202,15,40,193,
+ 248,1,195,248,158,217,193,216,252,241,217,124,36,4,102,184,0,4,102,11,68,
+ 36,4,102,37,252,255,252,247,102,137,68,36,6,217,108,36,6,217,252,252,217,
+ 108,36,4,222,201,222,252,233,195,248,159,217,232,221,68,36,4,217,252,241,
+ 195,248,98,255,217,252,234,222,201,248,160,217,84,36,4,129,124,36,4,0,0,128,
+ 127,15,132,244,247,129,124,36,4,0,0,128,252,255,15,132,244,248,248,161,217,
+ 192,217,252,252,220,252,233,217,201,217,252,240,217,232,222,193,217,252,253,
+ 221,217,248,1,195,248,2,221,216,217,252,238,195,248,117,219,84,36,4,219,68,
+ 36,4,223,252,233,15,133,244,254,15,138,244,255,221,216,139,68,36,4,131,252,
+ 248,1,15,142,244,252,248,1,169,1,0,0,0,15,133,244,248,216,200,209,232,252,
+ 233,244,1,248,2,255,209,232,15,132,244,251,217,192,248,3,216,200,209,232,
+ 15,132,244,250,15,131,244,3,220,201,252,233,244,3,248,4,222,201,248,5,195,
+ 248,6,15,132,244,5,15,130,244,253,217,232,222,252,241,252,247,216,131,252,
+ 248,1,15,132,244,5,252,233,244,1,248,7,255,221,216,217,232,195,248,8,217,
+ 84,36,4,217,201,217,84,36,8,139,68,36,4,209,224,61,0,0,0,252,255,15,132,244,
+ 248,139,68,36,8,209,224,15,132,244,250,61,0,0,0,252,255,15,132,244,250,217,
+ 252,241,252,233,244,161,248,9,217,232,223,252,234,15,132,244,247,217,201,
+ 248,1,221,216,195,248,2,217,225,217,232,223,252,233,15,132,244,249,221,216,
+ 217,225,217,252,238,184,0,0,0,0,15,146,208,209,200,51,68,36,4,15,137,244,
+ 249,217,201,248,3,221,217,217,225,195,248,4,255,131,124,36,4,0,15,141,244,
+ 3,221,216,221,216,133,192,15,132,244,251,217,252,238,195,248,5,199,68,36,
+ 4,0,0,128,127,217,68,36,4,195,248,162,252,242,15,45,193,252,242,15,42,208,
+ 102,15,46,202,15,133,244,254,15,138,244,255,248,163,131,252,248,1,15,142,
+ 244,252,248,1,169,1,0,0,0,15,133,244,248,252,242,15,89,192,209,232,252,233,
+ 244,1,248,2,209,232,15,132,244,251,255,15,40,200,248,3,252,242,15,89,192,
+ 209,232,15,132,244,250,15,131,244,3,252,242,15,89,200,252,233,244,3,248,4,
+ 252,242,15,89,193,248,5,195,248,6,15,132,244,5,15,130,244,253,252,247,216,
+ 232,244,1,184,0,0,252,240,63,102,15,110,200,102,15,112,201,81,252,242,15,
+ 94,200,15,40,193,195,248,7,184,0,0,252,240,63,102,15,110,192,102,15,112,192,
+ 81,195,248,8,252,242,15,17,76,36,12,252,242,15,17,68,36,4,131,124,36,12,0,
+ 15,133,244,247,255,139,68,36,16,209,224,61,0,0,224,252,255,15,132,244,248,
+ 248,1,131,124,36,4,0,15,133,244,247,139,68,36,8,209,224,15,132,244,250,61,
+ 0,0,224,252,255,15,132,244,251,248,1,221,68,36,12,221,68,36,4,217,252,241,
+ 217,192,217,252,252,220,252,233,217,201,217,252,240,217,232,222,193,217,252,
+ 253,221,217,221,92,36,4,252,242,15,16,68,36,4,195,248,9,184,0,0,252,240,63,
+ 102,15,110,208,102,15,112,210,81,102,15,46,194,15,132,244,247,15,40,193,248,
+ 1,195,248,2,102,15,252,239,210,102,15,118,210,102,15,115,210,1,102,15,84,
+ 194,184,0,0,252,240,63,102,15,110,208,102,15,112,210,81,102,15,46,194,15,
+ 132,244,1,102,15,80,193,15,87,192,136,196,15,146,208,48,224,15,133,244,1,
+ 248,3,255,184,0,0,252,240,127,102,15,110,192,102,15,112,192,81,195,248,4,
+ 102,15,80,193,133,192,15,133,244,3,15,87,192,195,248,5,102,15,80,193,133,
+ 192,15,132,244,3,15,87,192,195,248,164,139,68,36,12,221,68,36,4,131,252,248,
+ 1,15,130,244,91,15,132,244,93,131,252,248,3,15,130,244,114,15,135,244,248,
+ 217,252,250,195,248,2,131,252,248,5,15,130,244,98,15,132,244,160,255,131,
+ 252,248,7,15,132,244,247,15,135,244,248,217,252,237,217,201,217,252,241,195,
+ 248,1,217,232,217,201,217,252,241,195,248,2,131,252,248,9,15,132,244,247,
+ 15,135,244,248,217,252,236,217,201,217,252,241,195,248,1,217,252,254,195,
+ 248,2,131,252,248,11,15,132,244,247,15,135,244,255,217,252,255,195,248,1,
+ 217,252,242,221,216,195,248,9,204,248,165,139,68,36,20,221,68,36,4,221,68,
+ 36,12,131,252,248,1,15,132,244,247,255,15,135,244,248,222,193,195,248,1,222,
+ 252,233,195,248,2,131,252,248,3,15,132,244,247,15,135,244,248,222,201,195,
+ 248,1,222,252,249,195,248,2,131,252,248,5,15,130,244,158,15,132,244,117,131,
+ 252,248,7,15,132,244,247,15,135,244,248,221,216,217,224,195,248,1,221,216,
+ 217,225,195,248,2,255,131,252,248,9,15,132,244,247,15,135,244,248,217,252,
+ 243,195,248,1,217,201,217,252,253,221,217,195,248,2,131,252,248,11,15,132,
+ 244,247,15,135,244,255,219,252,233,219,209,221,217,195,248,1,219,252,233,
+ 218,209,221,217,195,248,9,204,248,166,156,90,137,209,129,252,242,0,0,32,0,
+ 82,157,156,90,49,192,57,209,15,132,244,247,139,68,36,4,87,83,15,162,139,124,
+ 36,16,137,7,137,95,4,137,79,8,137,87,12,91,95,248,1,195,248,167,255,204,255,
+ 204,248,168,131,252,236,16,87,86,83,131,252,236,28,141,157,233,139,181,233,
+ 15,183,192,137,134,233,141,132,253,36,233,137,142,233,137,150,233,137,134,
+ 233,139,140,253,36,233,139,148,253,36,233,137,76,36,44,137,84,36,40,137,226,
+ 137,116,36,24,137,252,241,232,251,1,26,199,131,233,237,139,144,233,139,128,
+ 233,41,208,139,106,252,248,193,232,3,131,192,1,139,181,233,139,14,15,182,
+ 252,233,15,182,205,131,198,4,252,255,36,171,248,33,139,76,36,48,139,179,233,
+ 137,142,233,137,145,233,137,169,233,255,137,252,241,137,194,232,251,1,27,
+ 139,108,36,48,139,134,233,139,150,233,131,190,233,1,15,130,244,253,15,132,
+ 244,252,221,134,233,252,233,244,253,248,6,217,134,233,248,7,139,141,233,15,
+ 183,73,6,137,76,36,48,131,196,28,91,94,95,93,89,3,36,36,131,196,16,81,195,
+ 248,169,85,137,229,83,137,203,43,163,233,137,163,233,15,182,139,233,131,252,
+ 233,1,15,136,244,248,248,1,255,139,132,253,139,233,137,4,140,131,252,233,
+ 1,15,137,244,1,248,2,139,139,233,139,147,233,252,255,147,233,137,131,233,
+ 137,147,233,128,187,233,1,15,130,244,253,15,132,244,252,221,155,233,252,233,
+ 244,253,248,6,217,155,233,248,7,255,41,163,233,139,93,252,252,201,195,255,
+ 129,124,253,202,4,239,15,131,244,45,129,124,253,194,4,239,15,131,244,45,248,
+ 1,221,4,202,248,2,221,4,194,248,3,131,198,4,223,252,233,221,216,255,15,134,
+ 244,247,255,15,135,244,247,255,15,131,244,247,255,15,183,70,252,254,141,180,
+ 253,134,233,248,1,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,
+ 36,171,255,139,108,194,4,131,198,4,255,129,252,253,239,15,131,244,251,129,
+ 124,253,202,4,239,15,131,244,251,248,1,221,4,202,248,2,221,4,194,248,4,223,
+ 252,233,221,216,255,15,138,244,248,15,133,244,248,255,15,138,244,248,15,132,
+ 244,247,255,248,1,15,183,70,252,254,141,180,253,134,233,248,2,255,248,2,15,
+ 183,70,252,254,141,180,253,134,233,248,1,255,252,233,244,9,255,248,5,129,
+ 252,253,239,15,132,244,50,129,124,253,202,4,239,15,132,244,50,57,108,202,
+ 4,15,133,244,2,129,252,253,239,15,131,244,1,139,12,202,139,4,194,57,193,15,
+ 132,244,1,129,252,253,239,15,135,244,2,139,169,233,133,252,237,15,132,244,
+ 2,255,252,246,133,233,235,15,133,244,2,255,49,252,237,255,189,1,0,0,0,255,
+ 252,233,244,49,255,248,3,129,252,253,239,255,15,133,244,9,255,252,233,244,
+ 50,255,252,247,208,139,108,202,4,131,198,4,129,252,253,239,15,133,244,249,
+ 139,12,202,59,12,135,255,139,108,202,4,131,198,4,255,129,252,253,239,15,131,
+ 244,249,248,1,221,4,199,248,2,221,4,202,248,4,223,252,233,221,216,255,252,
+ 247,208,139,108,202,4,131,198,4,57,197,255,15,133,244,249,15,183,70,252,254,
+ 141,180,253,134,233,248,2,139,6,15,182,204,15,182,232,131,198,4,193,232,16,
+ 252,255,36,171,248,3,129,252,253,239,15,133,244,2,252,233,244,50,255,15,132,
+ 244,248,129,252,253,239,15,132,244,50,15,183,70,252,254,141,180,253,134,233,
+ 248,2,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,255,
+ 139,108,194,4,131,198,4,129,252,253,239,255,137,108,202,4,139,44,194,137,
+ 44,202,255,139,108,194,4,139,4,194,137,108,202,4,137,4,202,139,6,15,182,204,
+ 15,182,232,131,198,4,193,232,16,252,255,36,171,255,49,252,237,129,124,253,
+ 194,4,239,129,213,239,137,108,202,4,139,6,15,182,204,15,182,232,131,198,4,
+ 193,232,16,252,255,36,171,255,129,124,253,194,4,239,15,131,244,55,221,4,194,
+ 217,224,221,28,202,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,
+ 36,171,255,129,124,253,194,4,239,15,133,244,248,139,4,194,219,128,233,248,
+ 1,221,28,202,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,
+ 171,248,2,129,124,253,194,4,239,15,133,244,58,139,12,194,255,139,169,233,
+ 131,252,253,0,15,133,244,255,248,3,255,248,59,137,213,232,251,1,19,137,4,
+ 36,219,4,36,137,252,234,15,182,78,252,253,252,233,244,1,255,248,9,252,246,
+ 133,233,235,15,133,244,3,252,233,244,58,255,15,182,252,236,15,182,192,255,
+ 129,124,253,252,234,4,239,15,131,244,52,221,4,252,234,220,4,199,255,129,124,
+ 253,252,234,4,239,15,131,244,54,221,4,199,220,4,252,234,255,129,124,253,252,
+ 234,4,239,15,131,244,57,129,124,253,194,4,239,15,131,244,57,221,4,252,234,
+ 220,4,194,255,129,124,253,252,234,4,239,15,131,244,52,221,4,252,234,220,36,
+ 199,255,129,124,253,252,234,4,239,15,131,244,54,221,4,199,220,36,252,234,
+ 255,129,124,253,252,234,4,239,15,131,244,57,129,124,253,194,4,239,15,131,
+ 244,57,221,4,252,234,220,36,194,255,129,124,253,252,234,4,239,15,131,244,
+ 52,221,4,252,234,220,12,199,255,129,124,253,252,234,4,239,15,131,244,54,221,
+ 4,199,220,12,252,234,255,129,124,253,252,234,4,239,15,131,244,57,129,124,
+ 253,194,4,239,15,131,244,57,221,4,252,234,220,12,194,255,129,124,253,252,
+ 234,4,239,15,131,244,52,221,4,252,234,220,52,199,255,129,124,253,252,234,
+ 4,239,15,131,244,54,221,4,199,220,52,252,234,255,129,124,253,252,234,4,239,
+ 15,131,244,57,129,124,253,194,4,239,15,131,244,57,221,4,252,234,220,52,194,
+ 255,129,124,253,252,234,4,239,15,131,244,52,221,4,252,234,221,4,199,255,129,
+ 124,253,252,234,4,239,15,131,244,54,221,4,199,221,4,252,234,255,129,124,253,
+ 252,234,4,239,15,131,244,57,129,124,253,194,4,239,15,131,244,57,221,4,252,
+ 234,221,4,194,255,248,170,232,244,158,221,28,202,139,6,15,182,204,15,182,
+ 232,131,198,4,193,232,16,252,255,36,171,255,252,233,244,170,255,232,244,117,
+ 221,28,202,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,
+ 255,15,182,252,236,15,182,192,141,12,194,41,232,137,76,36,4,137,68,36,8,248,
+ 37,139,108,36,48,137,44,36,137,149,233,137,116,36,24,232,251,1,28,139,149,
+ 233,133,192,15,133,244,46,15,182,110,252,255,15,182,78,252,253,139,68,252,
+ 234,4,139,44,252,234,137,68,202,4,137,44,202,139,6,15,182,204,15,182,232,
+ 131,198,4,193,232,16,252,255,36,171,255,252,247,208,139,4,135,199,68,202,
+ 4,237,137,4,202,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,
+ 36,171,255,223,70,252,254,221,28,202,139,6,15,182,204,15,182,232,131,198,
+ 4,193,232,16,252,255,36,171,255,221,4,199,221,28,202,139,6,15,182,204,15,
+ 182,232,131,198,4,193,232,16,252,255,36,171,255,252,247,208,137,68,202,4,
+ 139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,255,141,76,
+ 202,12,141,68,194,4,189,237,137,105,252,248,248,1,137,41,131,193,8,57,193,
+ 15,134,244,1,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,
+ 171,255,139,106,252,248,139,172,253,133,233,139,173,233,139,69,4,139,109,
+ 0,137,68,202,4,137,44,202,139,6,15,182,204,15,182,232,131,198,4,193,232,16,
+ 252,255,36,171,255,139,106,252,248,139,172,253,141,233,128,189,233,0,139,
+ 173,233,139,12,194,139,68,194,4,137,77,0,137,69,4,15,132,244,247,252,246,
+ 133,233,235,15,133,244,248,248,1,139,6,15,182,204,15,182,232,131,198,4,193,
+ 232,16,252,255,36,171,248,2,129,232,239,129,252,248,239,15,134,244,1,252,
+ 246,129,233,235,15,132,244,1,135,213,141,139,233,255,232,251,1,29,137,252,
+ 234,252,233,244,1,255,252,247,208,139,106,252,248,139,172,253,141,233,139,
+ 12,135,139,133,233,137,8,199,64,4,237,252,246,133,233,235,15,133,244,248,
+ 248,1,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,248,
+ 2,252,246,129,233,235,15,132,244,1,128,189,233,0,15,132,244,1,137,213,137,
+ 194,141,139,233,232,251,1,29,137,252,234,252,233,244,1,255,139,106,252,248,
+ 221,4,199,139,172,253,141,233,139,141,233,221,25,139,6,15,182,204,15,182,
+ 232,131,198,4,193,232,16,252,255,36,171,255,252,247,208,139,106,252,248,139,
+ 172,253,141,233,139,141,233,137,65,4,139,6,15,182,204,15,182,232,131,198,
+ 4,193,232,16,252,255,36,171,255,141,180,253,134,233,139,108,36,48,131,189,
+ 233,0,15,132,244,247,137,149,233,141,20,202,137,252,233,232,251,1,30,139,
+ 149,233,248,1,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,
+ 171,255,252,247,208,139,74,252,248,139,4,135,139,108,36,48,137,76,36,8,137,
+ 68,36,4,137,44,36,137,149,233,137,116,36,24,232,251,1,31,139,149,233,15,182,
+ 78,252,253,137,4,202,199,68,202,4,237,139,6,15,182,204,15,182,232,131,198,
+ 4,193,232,16,252,255,36,171,255,139,108,36,48,137,149,233,139,139,233,59,
+ 139,233,137,116,36,24,15,131,244,251,248,1,137,193,37,252,255,7,0,0,193,252,
+ 233,11,137,76,36,8,61,252,255,7,0,0,15,132,244,249,248,2,137,44,36,137,68,
+ 36,4,232,251,1,32,139,149,233,15,182,78,252,253,137,4,202,199,68,202,4,237,
+ 139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,248,3,184,
+ 1,8,0,0,252,233,244,2,248,5,137,252,233,232,251,1,33,15,183,70,252,254,252,
+ 233,244,1,255,252,247,208,139,108,36,48,139,139,233,137,116,36,24,59,139,
+ 233,137,149,233,15,131,244,249,248,2,139,20,135,137,252,233,232,251,1,34,
+ 139,149,233,15,182,78,252,253,137,4,202,199,68,202,4,237,139,6,15,182,204,
+ 15,182,232,131,198,4,193,232,16,252,255,36,171,248,3,137,252,233,232,251,
+ 1,33,15,183,70,252,254,252,247,208,252,233,244,2,255,252,247,208,139,106,
+ 252,248,139,173,233,139,4,135,252,233,244,171,255,252,247,208,139,106,252,
+ 248,139,173,233,139,4,135,252,233,244,172,255,15,182,252,236,15,182,192,129,
+ 124,253,252,234,4,239,15,133,244,40,139,44,252,234,129,124,253,194,4,239,
+ 15,131,244,251,221,4,194,219,20,36,219,4,36,223,252,233,221,216,139,4,36,
+ 15,133,244,40,59,133,233,15,131,244,40,193,224,3,3,133,233,129,120,253,4,
+ 239,15,132,244,248,139,40,139,64,4,137,44,202,137,68,202,4,248,1,139,6,15,
+ 182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,248,2,131,189,233,
+ 0,15,132,244,249,255,139,141,233,252,246,129,233,235,15,132,244,40,15,182,
+ 78,252,253,248,3,199,68,202,4,237,252,233,244,1,248,5,129,124,253,194,4,239,
+ 15,133,244,40,139,4,194,252,233,244,171,255,15,182,252,236,15,182,192,252,
+ 247,208,139,4,135,129,124,253,252,234,4,239,15,133,244,38,139,44,252,234,
+ 248,171,139,141,233,35,136,233,105,201,239,3,141,233,248,1,129,185,233,239,
+ 15,133,244,250,57,129,233,15,133,244,250,129,121,253,4,239,15,132,244,251,
+ 15,182,70,252,253,139,41,139,73,4,137,44,194,137,76,194,4,248,2,255,139,6,
+ 15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,248,3,15,182,70,
+ 252,253,199,68,194,4,237,252,233,244,2,248,4,139,137,233,133,201,15,133,244,
+ 1,248,5,139,141,233,133,201,15,132,244,3,252,246,129,233,235,15,133,244,3,
+ 252,233,244,38,255,15,182,252,236,15,182,192,129,124,253,252,234,4,239,15,
+ 133,244,39,139,44,252,234,59,133,233,15,131,244,39,193,224,3,3,133,233,129,
+ 120,253,4,239,15,132,244,248,139,40,139,64,4,137,44,202,137,68,202,4,248,
+ 1,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,248,2,131,
+ 189,233,0,15,132,244,249,139,141,233,252,246,129,233,235,15,132,244,39,255,
+ 15,182,78,252,253,248,3,199,68,202,4,237,252,233,244,1,255,15,182,252,236,
+ 15,182,192,129,124,253,252,234,4,239,15,133,244,43,139,44,252,234,129,124,
+ 253,194,4,239,15,131,244,251,221,4,194,219,20,36,219,4,36,223,252,233,221,
+ 216,139,4,36,15,133,244,43,59,133,233,15,131,244,43,193,224,3,3,133,233,129,
+ 120,253,4,239,15,132,244,249,248,1,252,246,133,233,235,15,133,244,253,248,
+ 2,255,139,108,202,4,139,12,202,137,104,4,137,8,139,6,15,182,204,15,182,232,
+ 131,198,4,193,232,16,252,255,36,171,248,3,131,189,233,0,15,132,244,1,139,
+ 141,233,252,246,129,233,235,15,132,244,43,15,182,78,252,253,252,233,244,1,
+ 248,5,129,124,253,194,4,239,15,133,244,43,139,4,194,252,233,244,172,248,7,
+ 128,165,233,235,255,139,139,233,137,171,233,137,141,233,15,182,78,252,253,
+ 252,233,244,2,255,15,182,252,236,15,182,192,252,247,208,139,4,135,129,124,
+ 253,252,234,4,239,15,133,244,41,139,44,252,234,248,172,139,141,233,35,136,
+ 233,105,201,239,198,133,233,0,3,141,233,248,1,129,185,233,239,15,133,244,
+ 251,57,129,233,15,133,244,251,129,121,253,4,239,15,132,244,250,248,2,255,
+ 252,246,133,233,235,15,133,244,253,248,3,15,182,70,252,253,139,108,194,4,
+ 139,4,194,137,105,4,137,1,139,6,15,182,204,15,182,232,131,198,4,193,232,16,
+ 252,255,36,171,248,4,131,189,233,0,15,132,244,2,137,76,36,16,139,141,233,
+ 252,246,129,233,235,15,132,244,41,139,76,36,16,252,233,244,2,248,5,139,137,
+ 233,133,201,15,133,244,1,255,139,141,233,133,201,15,132,244,252,252,246,129,
+ 233,235,15,132,244,41,248,6,137,68,36,16,199,68,36,20,237,137,108,36,12,141,
+ 68,36,16,137,108,36,4,139,108,36,48,137,68,36,8,137,44,36,137,149,233,137,
+ 116,36,24,232,251,1,35,139,149,233,139,108,36,12,137,193,252,233,244,2,248,
+ 7,128,165,233,235,139,131,233,137,171,233,137,133,233,252,233,244,3,255,15,
+ 182,252,236,15,182,192,129,124,253,252,234,4,239,15,133,244,42,139,44,252,
+ 234,59,133,233,15,131,244,42,193,224,3,3,133,233,129,120,253,4,239,15,132,
+ 244,249,248,1,252,246,133,233,235,15,133,244,253,248,2,139,108,202,4,139,
+ 12,202,137,104,4,137,8,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,
+ 255,36,171,248,3,131,189,233,0,15,132,244,1,255,139,141,233,252,246,129,233,
+ 235,15,132,244,42,15,182,78,252,253,252,233,244,1,248,7,128,165,233,235,139,
+ 139,233,137,171,233,137,141,233,15,182,78,252,253,252,233,244,2,255,137,124,
+ 36,16,139,60,199,248,1,141,12,202,139,105,252,248,252,246,133,233,235,15,
+ 133,244,253,248,2,139,68,36,20,131,232,1,15,132,244,250,1,252,248,59,133,
+ 233,15,135,244,251,41,252,248,193,231,3,3,189,233,248,3,139,41,137,47,139,
+ 105,4,131,193,8,137,111,4,131,199,8,131,232,1,15,133,244,3,248,4,139,124,
+ 36,16,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,248,
+ 5,137,108,36,4,139,108,36,48,137,149,233,137,68,36,8,137,44,36,137,116,36,
+ 24,232,251,1,36,139,149,233,15,182,78,252,253,252,233,244,1,248,7,255,128,
+ 165,233,235,139,131,233,137,171,233,137,133,233,252,233,244,2,255,3,68,36,
+ 20,255,129,124,253,202,4,239,139,44,202,15,133,244,60,141,84,202,8,137,114,
+ 252,252,139,181,233,139,14,15,182,252,233,15,182,205,131,198,4,252,255,36,
+ 171,255,141,76,202,8,137,215,139,105,252,248,129,121,253,252,252,239,15,133,
+ 244,30,248,61,139,114,252,252,252,247,198,237,15,133,244,253,248,1,137,106,
+ 252,248,137,68,36,20,131,232,1,15,132,244,249,248,2,139,41,137,47,139,105,
+ 4,131,193,8,137,111,4,131,199,8,131,232,1,15,133,244,2,139,106,252,248,248,
+ 3,139,68,36,20,128,189,233,1,15,135,244,251,248,4,139,181,233,139,14,15,182,
+ 252,233,15,182,205,131,198,4,252,255,36,171,248,5,255,252,247,198,237,15,
+ 133,244,4,15,182,78,252,253,252,247,209,139,124,202,252,248,139,191,233,139,
+ 191,233,252,233,244,4,248,7,129,252,238,239,252,247,198,237,15,133,244,254,
+ 41,252,242,137,215,139,114,252,252,252,233,244,1,248,8,129,198,239,252,233,
+ 244,1,255,141,76,202,8,139,105,232,139,65,252,236,137,41,137,65,4,139,105,
+ 252,240,139,65,252,244,137,105,8,137,65,12,139,105,224,139,65,228,137,105,
+ 252,248,137,65,252,252,129,252,248,239,184,237,15,133,244,30,137,202,137,
+ 114,252,252,139,181,233,139,14,15,182,252,233,15,182,205,131,198,4,252,255,
+ 36,171,255,137,124,36,16,137,92,36,20,139,108,202,252,240,139,68,202,252,
+ 248,139,157,233,131,198,4,139,189,233,248,1,57,216,15,131,244,251,129,124,
+ 253,199,4,239,15,132,244,250,219,68,202,252,248,139,108,199,4,137,108,202,
+ 12,139,44,199,137,108,202,8,131,192,1,221,28,202,137,68,202,252,248,248,2,
+ 15,183,70,252,254,141,180,253,134,233,248,3,139,92,36,20,139,124,36,16,139,
+ 6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,248,4,131,192,
+ 1,137,68,202,252,248,252,233,244,1,248,5,41,216,248,6,59,133,233,15,135,244,
+ 3,105,252,248,239,255,3,189,233,129,191,233,239,15,132,244,253,141,92,24,
+ 1,139,175,233,139,135,233,137,44,202,137,68,202,4,139,175,233,139,135,233,
+ 137,108,202,8,137,68,202,12,137,92,202,252,248,252,233,244,2,248,7,131,192,
+ 1,252,233,244,6,255,129,124,253,202,252,236,239,15,133,244,251,139,108,202,
+ 232,129,124,253,202,252,244,239,15,133,244,251,129,124,253,202,252,252,239,
+ 15,133,244,251,128,189,233,235,15,133,244,251,141,180,253,134,233,199,68,
+ 202,252,248,0,0,0,0,199,68,202,252,252,252,255,127,252,254,252,255,248,1,
+ 139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,248,5,198,
+ 70,252,252,235,141,180,253,134,233,198,6,235,252,233,244,1,255,15,182,252,
+ 236,15,182,192,137,124,36,16,141,188,253,194,233,141,12,202,43,122,252,252,
+ 133,252,237,15,132,244,251,141,108,252,233,252,248,57,215,15,131,244,248,
+ 248,1,139,71,252,248,137,1,139,71,252,252,131,199,8,137,65,4,131,193,8,57,
+ 252,233,15,131,244,249,57,215,15,130,244,1,248,2,199,65,4,237,131,193,8,57,
+ 252,233,15,130,244,2,248,3,139,124,36,16,139,6,15,182,204,15,182,232,131,
+ 198,4,193,232,16,252,255,36,171,248,5,199,68,36,20,1,0,0,0,137,208,41,252,
+ 248,15,134,244,3,137,197,193,252,237,3,131,197,1,137,108,36,20,139,108,36,
+ 48,1,200,59,133,233,15,135,244,253,248,6,255,139,71,252,248,137,1,139,71,
+ 252,252,131,199,8,137,65,4,131,193,8,57,215,15,130,244,6,252,233,244,3,248,
+ 7,137,149,233,137,141,233,137,116,36,24,41,215,139,84,36,20,131,252,234,1,
+ 137,252,233,232,251,1,0,139,149,233,139,141,233,1,215,252,233,244,6,255,193,
+ 225,3,255,248,1,139,114,252,252,137,68,36,20,252,247,198,237,15,133,244,253,
+ 255,248,14,137,215,131,232,1,15,132,244,249,248,2,139,44,15,137,111,252,248,
+ 139,108,15,4,137,111,252,252,131,199,8,131,232,1,15,133,244,2,248,3,139,68,
+ 36,20,15,182,110,252,255,248,5,57,197,15,135,244,252,255,139,108,10,4,137,
+ 106,252,252,139,44,10,137,106,252,248,255,248,5,56,70,252,255,15,135,244,
+ 252,255,15,182,78,252,253,252,247,209,141,20,202,139,122,252,248,139,191,
+ 233,139,191,233,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,
+ 36,171,248,6,255,199,71,252,252,237,131,199,8,255,199,68,194,252,244,237,
+ 255,131,192,1,252,233,244,5,248,7,141,174,233,252,247,197,237,15,133,244,
+ 15,41,252,234,255,1,252,233,255,137,252,245,209,252,237,129,229,239,102,129,
+ 172,253,43,233,238,15,130,244,150,255,141,12,202,255,129,121,253,4,239,15,
+ 133,244,255,255,129,121,253,12,239,15,133,244,62,129,121,253,20,239,15,133,
+ 244,62,139,41,131,121,16,0,15,140,244,251,255,129,121,253,12,239,15,133,244,
+ 167,129,121,253,20,239,15,133,244,167,255,139,105,16,133,252,237,15,136,244,
+ 251,3,41,15,128,244,247,137,41,255,59,105,8,199,65,28,237,137,105,24,255,
+ 15,142,244,253,248,1,248,6,141,180,253,134,233,255,141,180,253,134,233,15,
+ 183,70,252,254,15,142,245,248,1,248,6,255,15,143,244,253,248,6,141,180,253,
+ 134,233,248,1,255,248,7,139,6,15,182,204,15,182,232,131,198,4,193,232,16,
+ 252,255,36,171,248,5,255,3,41,15,128,244,1,137,41,255,15,141,244,7,255,141,
+ 180,253,134,233,15,183,70,252,254,15,141,245,255,15,140,244,7,255,252,233,
+ 244,6,248,9,255,129,121,253,4,239,255,15,131,244,62,129,121,253,12,239,15,
+ 131,244,62,255,129,121,253,12,239,15,131,244,167,129,121,253,20,239,15,131,
+ 244,167,255,139,105,20,255,129,252,253,239,15,131,244,62,255,221,65,8,221,
+ 1,255,220,65,16,221,17,221,81,24,133,252,237,15,136,244,247,255,221,81,24,
+ 15,140,244,247,255,217,201,248,1,223,252,233,221,216,255,15,131,244,248,141,
+ 180,253,134,233,255,141,180,253,134,233,15,183,70,252,254,15,131,245,255,
+ 15,130,244,248,141,180,253,134,233,255,141,12,202,139,105,4,129,252,253,239,
+ 15,132,244,247,255,137,105,252,252,139,41,137,105,252,248,252,233,245,255,
+ 141,180,253,134,233,139,1,137,105,252,252,137,65,252,248,255,139,139,233,
+ 139,4,129,139,128,233,139,108,36,48,137,147,233,137,171,233,252,255,224,255,
+ 141,180,253,134,233,139,6,15,182,204,15,182,232,131,198,4,193,232,16,252,
+ 255,36,171,255,137,252,245,209,252,237,129,229,239,102,129,172,253,43,233,
+ 238,15,130,244,152,255,139,190,233,139,108,36,48,141,12,202,59,141,233,15,
+ 135,244,25,15,182,142,233,57,200,15,134,244,249,248,2,255,15,183,70,252,254,
+ 252,233,245,255,248,3,199,68,194,252,252,237,131,192,1,57,200,15,134,244,
+ 3,252,233,244,2,255,141,44,197,237,141,4,194,139,122,252,248,137,104,252,
+ 252,137,120,252,248,139,108,36,48,141,12,200,59,141,233,15,135,244,24,137,
+ 209,137,194,15,182,174,233,133,252,237,15,132,244,248,248,1,131,193,8,57,
+ 209,15,131,244,249,139,121,252,248,137,56,139,121,252,252,137,120,4,131,192,
+ 8,199,65,252,252,237,131,252,237,1,15,133,244,1,248,2,255,139,190,233,139,
+ 6,15,182,204,15,182,232,131,198,4,193,232,16,252,255,36,171,255,248,3,199,
+ 64,4,237,131,192,8,131,252,237,1,15,133,244,3,252,233,244,2,255,139,106,252,
+ 248,139,189,233,139,108,36,48,141,68,194,252,248,137,149,233,141,136,233,
+ 59,141,233,137,133,233,255,137,44,36,255,137,124,36,4,137,44,36,255,15,135,
+ 244,23,199,131,233,237,255,252,255,215,255,252,255,147,233,255,199,131,233,
+ 237,139,149,233,141,12,194,252,247,217,3,141,233,139,114,252,252,252,233,
+ 244,12,255,254,0
+};
+
+enum {
+ GLOB_vm_returnp,
+ GLOB_cont_dispatch,
+ GLOB_vm_returnc,
+ GLOB_vm_unwind_yield,
+ GLOB_BC_RET_Z,
+ GLOB_vm_return,
+ GLOB_vm_leave_cp,
+ GLOB_vm_leave_unw,
+ GLOB_vm_unwind_c_eh,
+ GLOB_vm_unwind_c,
+ GLOB_vm_unwind_rethrow,
+ GLOB_vm_unwind_ff,
+ GLOB_vm_unwind_ff_eh,
+ GLOB_vm_growstack_c,
+ GLOB_vm_growstack_v,
+ GLOB_vm_growstack_f,
+ GLOB_vm_resume,
+ GLOB_vm_pcall,
+ GLOB_vm_call,
+ GLOB_vm_call_dispatch,
+ GLOB_vmeta_call,
+ GLOB_vm_call_dispatch_f,
+ GLOB_vm_cpcall,
+ GLOB_cont_ffi_callback,
+ GLOB_vm_call_tail,
+ GLOB_cont_cat,
+ GLOB_cont_ra,
+ GLOB_BC_CAT_Z,
+ GLOB_vmeta_tgets,
+ GLOB_vmeta_tgetb,
+ GLOB_vmeta_tgetv,
+ GLOB_vmeta_tsets,
+ GLOB_vmeta_tsetb,
+ GLOB_vmeta_tsetv,
+ GLOB_cont_nop,
+ GLOB_vmeta_comp,
+ GLOB_vmeta_binop,
+ GLOB_cont_condt,
+ GLOB_cont_condf,
+ GLOB_vmeta_equal,
+ GLOB_vmeta_equal_cd,
+ GLOB_vmeta_arith_vno,
+ GLOB_vmeta_arith_vn,
+ GLOB_vmeta_arith_nvo,
+ GLOB_vmeta_arith_nv,
+ GLOB_vmeta_unm,
+ GLOB_vmeta_arith_vvo,
+ GLOB_vmeta_arith_vv,
+ GLOB_vmeta_len,
+ GLOB_BC_LEN_Z,
+ GLOB_vmeta_call_ra,
+ GLOB_BC_CALLT_Z,
+ GLOB_vmeta_for,
+ GLOB_ff_assert,
+ GLOB_fff_fallback,
+ GLOB_fff_res_,
+ GLOB_ff_type,
+ GLOB_fff_res1,
+ GLOB_ff_getmetatable,
+ GLOB_ff_setmetatable,
+ GLOB_ff_rawget,
+ GLOB_ff_tonumber,
+ GLOB_fff_resn,
+ GLOB_ff_tostring,
+ GLOB_fff_gcstep,
+ GLOB_ff_next,
+ GLOB_fff_res2,
+ GLOB_fff_res,
+ GLOB_ff_pairs,
+ GLOB_ff_ipairs_aux,
+ GLOB_fff_res0,
+ GLOB_ff_ipairs,
+ GLOB_ff_pcall,
+ GLOB_ff_xpcall,
+ GLOB_ff_coroutine_resume,
+ GLOB_ff_coroutine_wrap_aux,
+ GLOB_ff_coroutine_yield,
+ GLOB_fff_resi,
+ GLOB_ff_math_abs,
+ GLOB_fff_resxmm0,
+ GLOB_ff_math_floor,
+ GLOB_vm_floor,
+ GLOB_ff_math_ceil,
+ GLOB_vm_ceil,
+ GLOB_ff_math_sqrt,
+ GLOB_ff_math_log,
+ GLOB_ff_math_log10,
+ GLOB_ff_math_exp,
+ GLOB_vm_exp_x87,
+ GLOB_ff_math_sin,
+ GLOB_ff_math_cos,
+ GLOB_ff_math_tan,
+ GLOB_ff_math_asin,
+ GLOB_ff_math_acos,
+ GLOB_ff_math_atan,
+ GLOB_ff_math_sinh,
+ GLOB_ff_math_cosh,
+ GLOB_ff_math_tanh,
+ GLOB_ff_math_deg,
+ GLOB_ff_math_rad,
+ GLOB_ff_math_atan2,
+ GLOB_ff_math_ldexp,
+ GLOB_ff_math_frexp,
+ GLOB_ff_math_modf,
+ GLOB_vm_trunc,
+ GLOB_ff_math_fmod,
+ GLOB_ff_math_pow,
+ GLOB_vm_pow,
+ GLOB_ff_math_min,
+ GLOB_ff_math_max,
+ GLOB_ff_string_len,
+ GLOB_ff_string_byte,
+ GLOB_ff_string_char,
+ GLOB_fff_newstr,
+ GLOB_ff_string_sub,
+ GLOB_fff_emptystr,
+ GLOB_ff_string_rep,
+ GLOB_fff_fallback_2,
+ GLOB_ff_string_reverse,
+ GLOB_fff_fallback_1,
+ GLOB_ff_string_lower,
+ GLOB_ff_string_upper,
+ GLOB_ff_table_getn,
+ GLOB_ff_bit_tobit,
+ GLOB_ff_bit_band,
+ GLOB_fff_resbit,
+ GLOB_fff_fallback_bit_op,
+ GLOB_ff_bit_bor,
+ GLOB_ff_bit_bxor,
+ GLOB_ff_bit_bswap,
+ GLOB_ff_bit_bnot,
+ GLOB_ff_bit_lshift,
+ GLOB_ff_bit_rshift,
+ GLOB_ff_bit_arshift,
+ GLOB_ff_bit_rol,
+ GLOB_ff_bit_ror,
+ GLOB_vm_record,
+ GLOB_vm_rethook,
+ GLOB_vm_inshook,
+ GLOB_cont_hook,
+ GLOB_vm_hotloop,
+ GLOB_vm_callhook,
+ GLOB_vm_hotcall,
+ GLOB_vm_exit_handler,
+ GLOB_vm_exit_interp,
+ GLOB_vm_floor_sse,
+ GLOB_vm_ceil_sse,
+ GLOB_vm_trunc_sse,
+ GLOB_vm_mod,
+ GLOB_vm_log2,
+ GLOB_vm_exp2_x87,
+ GLOB_vm_exp2raw,
+ GLOB_vm_pow_sse,
+ GLOB_vm_powi_sse,
+ GLOB_vm_foldfpm,
+ GLOB_vm_foldarith,
+ GLOB_vm_cpuid,
+ GLOB_assert_bad_for_arg_type,
+ GLOB_vm_ffi_callback,
+ GLOB_vm_ffi_call,
+ GLOB_BC_MODVN_Z,
+ GLOB_BC_TGETS_Z,
+ GLOB_BC_TSETS_Z,
+ GLOB__MAX
+};
+static const char *const globnames[] = {
+ "vm_returnp",
+ "cont_dispatch",
+ "vm_returnc",
+ "vm_unwind_yield",
+ "BC_RET_Z",
+ "vm_return",
+ "vm_leave_cp",
+ "vm_leave_unw",
+ "vm_unwind_c_eh",
+ "vm_unwind_c@8",
+ "vm_unwind_rethrow",
+ "vm_unwind_ff@4",
+ "vm_unwind_ff_eh",
+ "vm_growstack_c",
+ "vm_growstack_v",
+ "vm_growstack_f",
+ "vm_resume",
+ "vm_pcall",
+ "vm_call",
+ "vm_call_dispatch",
+ "vmeta_call",
+ "vm_call_dispatch_f",
+ "vm_cpcall",
+ "cont_ffi_callback",
+ "vm_call_tail",
+ "cont_cat",
+ "cont_ra",
+ "BC_CAT_Z",
+ "vmeta_tgets",
+ "vmeta_tgetb",
+ "vmeta_tgetv",
+ "vmeta_tsets",
+ "vmeta_tsetb",
+ "vmeta_tsetv",
+ "cont_nop",
+ "vmeta_comp",
+ "vmeta_binop",
+ "cont_condt",
+ "cont_condf",
+ "vmeta_equal",
+ "vmeta_equal_cd",
+ "vmeta_arith_vno",
+ "vmeta_arith_vn",
+ "vmeta_arith_nvo",
+ "vmeta_arith_nv",
+ "vmeta_unm",
+ "vmeta_arith_vvo",
+ "vmeta_arith_vv",
+ "vmeta_len",
+ "BC_LEN_Z",
+ "vmeta_call_ra",
+ "BC_CALLT_Z",
+ "vmeta_for",
+ "ff_assert",
+ "fff_fallback",
+ "fff_res_",
+ "ff_type",
+ "fff_res1",
+ "ff_getmetatable",
+ "ff_setmetatable",
+ "ff_rawget",
+ "ff_tonumber",
+ "fff_resn",
+ "ff_tostring",
+ "fff_gcstep",
+ "ff_next",
+ "fff_res2",
+ "fff_res",
+ "ff_pairs",
+ "ff_ipairs_aux",
+ "fff_res0",
+ "ff_ipairs",
+ "ff_pcall",
+ "ff_xpcall",
+ "ff_coroutine_resume",
+ "ff_coroutine_wrap_aux",
+ "ff_coroutine_yield",
+ "fff_resi",
+ "ff_math_abs",
+ "fff_resxmm0",
+ "ff_math_floor",
+ "vm_floor",
+ "ff_math_ceil",
+ "vm_ceil",
+ "ff_math_sqrt",
+ "ff_math_log",
+ "ff_math_log10",
+ "ff_math_exp",
+ "vm_exp_x87",
+ "ff_math_sin",
+ "ff_math_cos",
+ "ff_math_tan",
+ "ff_math_asin",
+ "ff_math_acos",
+ "ff_math_atan",
+ "ff_math_sinh",
+ "ff_math_cosh",
+ "ff_math_tanh",
+ "ff_math_deg",
+ "ff_math_rad",
+ "ff_math_atan2",
+ "ff_math_ldexp",
+ "ff_math_frexp",
+ "ff_math_modf",
+ "vm_trunc",
+ "ff_math_fmod",
+ "ff_math_pow",
+ "vm_pow",
+ "ff_math_min",
+ "ff_math_max",
+ "ff_string_len",
+ "ff_string_byte",
+ "ff_string_char",
+ "fff_newstr",
+ "ff_string_sub",
+ "fff_emptystr",
+ "ff_string_rep",
+ "fff_fallback_2",
+ "ff_string_reverse",
+ "fff_fallback_1",
+ "ff_string_lower",
+ "ff_string_upper",
+ "ff_table_getn",
+ "ff_bit_tobit",
+ "ff_bit_band",
+ "fff_resbit",
+ "fff_fallback_bit_op",
+ "ff_bit_bor",
+ "ff_bit_bxor",
+ "ff_bit_bswap",
+ "ff_bit_bnot",
+ "ff_bit_lshift",
+ "ff_bit_rshift",
+ "ff_bit_arshift",
+ "ff_bit_rol",
+ "ff_bit_ror",
+ "vm_record",
+ "vm_rethook",
+ "vm_inshook",
+ "cont_hook",
+ "vm_hotloop",
+ "vm_callhook",
+ "vm_hotcall",
+ "vm_exit_handler",
+ "vm_exit_interp",
+ "vm_floor_sse",
+ "vm_ceil_sse",
+ "vm_trunc_sse",
+ "vm_mod",
+ "vm_log2",
+ "vm_exp2_x87",
+ "vm_exp2raw",
+ "vm_pow_sse",
+ "vm_powi_sse",
+ "vm_foldfpm",
+ "vm_foldarith",
+ "vm_cpuid",
+ "assert_bad_for_arg_type",
+ "vm_ffi_callback",
+ "vm_ffi_call@4",
+ "BC_MODVN_Z",
+ "BC_TGETS_Z",
+ "BC_TSETS_Z",
+ (const char *)0
+};
+static const char *const extnames[] = {
+ "lj_state_growstack@8",
+ "lj_meta_tget",
+ "lj_meta_tset",
+ "lj_meta_comp",
+ "lj_meta_equal",
+ "lj_meta_equal_cd@8",
+ "lj_meta_arith",
+ "lj_meta_len@8",
+ "lj_meta_call",
+ "lj_meta_for@8",
+ "lj_tab_get",
+ "lj_str_fromnum@8",
+ "lj_tab_next",
+ "lj_tab_getinth@8",
+ "lj_ffh_coroutine_wrap_err@8",
+ "lj_vm_sinh",
+ "lj_vm_cosh",
+ "lj_vm_tanh",
+ "lj_str_new",
+ "lj_tab_len@4",
+ "lj_gc_step@4",
+ "lj_dispatch_ins@8",
+ "lj_trace_hot@8",
+ "lj_dispatch_call@8",
+ "lj_trace_exit@8",
+ "lj_err_throw@8",
+ "lj_ccallback_enter@8",
+ "lj_ccallback_leave@8",
+ "lj_meta_cat",
+ "lj_gc_barrieruv@8",
+ "lj_func_closeuv@8",
+ "lj_func_newL_gc",
+ "lj_tab_new",
+ "lj_gc_step_fixtop@4",
+ "lj_tab_dup@8",
+ "lj_tab_newkey",
+ "lj_tab_reasize",
+ (const char *)0
+};
+#define Dt1(_V) (int)(ptrdiff_t)&(((lua_State *)0)_V)
+#define Dt2(_V) (int)(ptrdiff_t)&(((global_State *)0)_V)
+#define Dt3(_V) (int)(ptrdiff_t)&(((TValue *)0)_V)
+#define Dt4(_V) (int)(ptrdiff_t)&(((GCobj *)0)_V)
+#define Dt5(_V) (int)(ptrdiff_t)&(((GCstr *)0)_V)
+#define Dt6(_V) (int)(ptrdiff_t)&(((GCtab *)0)_V)
+#define Dt7(_V) (int)(ptrdiff_t)&(((GCfuncL *)0)_V)
+#define Dt8(_V) (int)(ptrdiff_t)&(((GCfuncC *)0)_V)
+#define Dt9(_V) (int)(ptrdiff_t)&(((GCproto *)0)_V)
+#define DtA(_V) (int)(ptrdiff_t)&(((GCupval *)0)_V)
+#define DtB(_V) (int)(ptrdiff_t)&(((Node *)0)_V)
+#define DtC(_V) (int)(ptrdiff_t)&(((int *)0)_V)
+#define DtD(_V) (int)(ptrdiff_t)&(((GCtrace *)0)_V)
+#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field))
+#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field))
+#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
+
+/* Generate subroutines used by opcodes and other parts of the VM. */
+/* The .code_sub section should be last to help static branch prediction. */
+static void build_subroutines(BuildCtx *ctx)
+{
+ dasm_put(Dst, 0);
+ dasm_put(Dst, 2, FRAME_P, LJ_TTRUE, FRAME_TYPE, FRAME_C, FRAME_TYPE, DISPATCH_GL(vmstate), ~LJ_VMST_C);
+ dasm_put(Dst, 91, Dt1(->base), Dt1(->top), Dt1(->cframe), Dt1(->maxstack), LJ_TNIL);
+ dasm_put(Dst, 192, Dt1(->top), Dt1(->top), LUA_YIELD, Dt1(->glref), Dt2(->vmstate), ~LJ_VMST_C);
+ dasm_put(Dst, 272, CFRAME_RAWMASK, 1+1, Dt1(->base), Dt1(->glref), GG_G2DISP, LJ_TFALSE, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, LUA_MINSTACK);
+ dasm_put(Dst, 339, -4+PC2PROTO(framesize), Dt1(->base), Dt1(->top), Dt1(->base), Dt1(->top), Dt7(->pc), FRAME_CP, CFRAME_RESUME, Dt1(->glref), GG_G2DISP, Dt1(->cframe), Dt1(->status));
+ dasm_put(Dst, 472, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->status), Dt1(->base), Dt1(->top), FRAME_TYPE, FRAME_CP, FRAME_C, Dt1(->cframe), Dt1(->cframe));
+ dasm_put(Dst, 570, Dt1(->glref), GG_G2DISP, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), Dt1(->top), LJ_TFUNC, Dt7(->pc), Dt1(->stack), Dt1(->top), Dt1(->cframe), Dt1(->cframe));
+ dasm_put(Dst, 722, FRAME_CP, LJ_TNIL, Dt7(->pc), PC2PROTO(k));
+ dasm_put(Dst, 854, LJ_TSTR, BC_GGET, DISPATCH_GL(tmptv), LJ_TTAB, Dt1(->base), Dt1(->base));
+ dasm_put(Dst, 1016, Dt1(->top), FRAME_CONT, 2+1, LJ_TSTR, BC_GSET, DISPATCH_GL(tmptv), LJ_TTAB);
+ dasm_put(Dst, 1128, Dt1(->base), Dt1(->base), Dt1(->top), FRAME_CONT, 3+1, Dt1(->base), Dt1(->base));
+ dasm_put(Dst, 1310, -BCBIAS_J*4, LJ_TISTRUECOND, LJ_TISTRUECOND, Dt1(->base), Dt1(->base));
+ dasm_put(Dst, 1446, Dt1(->base), Dt1(->base), FRAME_CONT, 2+1);
+ dasm_put(Dst, 1562, Dt1(->base), Dt1(->base));
+#if LJ_52
+ dasm_put(Dst, 1593);
+#else
+ dasm_put(Dst, 1612);
+#endif
+ dasm_put(Dst, 1617, Dt1(->base), Dt1(->base), Dt7(->pc), Dt1(->base), Dt1(->base), GG_DISP2STATIC, 1+1, LJ_TISTRUECOND);
+ dasm_put(Dst, 1806, 1+1, ~LJ_TNUMX, ((char *)(&((GCfuncC *)0)->upvalue)), LJ_TSTR, 1+1);
+ dasm_put(Dst, 1905, LJ_TTAB, Dt6(->metatable), LJ_TNIL, DISPATCH_GL(gcroot)+4*(GCROOT_MMNAME+MM_metatable), LJ_TTAB, Dt6(->hmask), Dt5(->hash), sizeof(Node), Dt6(->node), DtB(->key.it), LJ_TSTR);
+ dasm_put(Dst, 1976, DtB(->key.gcr), DtB(->next), LJ_TNIL, LJ_TUDATA, LJ_TISNUM);
+ dasm_put(Dst, 2040, LJ_TNUMX, DISPATCH_GL(gcroot[GCROOT_BASEMT]), 2+1, LJ_TTAB, Dt6(->metatable), LJ_TTAB);
+ dasm_put(Dst, 2099, Dt6(->metatable), LJ_TTAB, Dt6(->marked), LJ_GC_BLACK, Dt6(->marked), (uint8_t)~LJ_GC_BLACK, DISPATCH_GL(gc.grayagain), DISPATCH_GL(gc.grayagain), Dt6(->gclist), 2+1, LJ_TTAB);
+ dasm_put(Dst, 2166, 1+1, LJ_TISNUM, 1+1, LJ_TSTR, LJ_TSTR);
+ dasm_put(Dst, 2274, LJ_TISNUM, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM]), DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold), Dt1(->base), Dt1(->base));
+ dasm_put(Dst, 2344, 1+1, LJ_TTAB, Dt1(->base), Dt1(->top), Dt1(->base), 1+2, LJ_TNIL);
+ dasm_put(Dst, 2454, LJ_TNIL, 1+1, LJ_TTAB);
+#if LJ_52
+ dasm_put(Dst, 2491, Dt6(->metatable));
+#endif
+ dasm_put(Dst, 2500, Dt8(->upvalue[0]), LJ_TFUNC, LJ_TNIL, 1+3, 2+1, LJ_TTAB, LJ_TISNUM, Dt6(->asize), Dt6(->array));
+ dasm_put(Dst, 2597, LJ_TNIL, Dt6(->hmask), 1+0, 1+1, LJ_TTAB);
+ dasm_put(Dst, 2094);
+#if LJ_52
+ dasm_put(Dst, 2491, Dt6(->metatable));
+#endif
+ dasm_put(Dst, 2676, Dt8(->upvalue[0]), LJ_TFUNC, 1+3, 1+1, 8+FRAME_PCALL, DISPATCH_GL(hookmask), HOOK_ACTIVE_SHIFT, 2+1, LJ_TFUNC);
+ dasm_put(Dst, 2762, LJ_TFUNC, 16+FRAME_PCALL, 1+1, LJ_TTHREAD, Dt1(->cframe), Dt1(->status), LUA_YIELD);
+ dasm_put(Dst, 2847, Dt1(->top), Dt1(->base), Dt1(->maxstack), Dt1(->top), Dt1(->base), Dt1(->top));
+ dasm_put(Dst, 2951, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), LUA_YIELD, Dt1(->base), Dt1(->top), Dt1(->top), Dt1(->maxstack), LJ_TTRUE);
+ dasm_put(Dst, 3048, FRAME_TYPE, LJ_TFALSE, Dt1(->top), Dt1(->top), 1+2, Dt1(->top), Dt1(->base), Dt8(->upvalue[0].gcr), Dt1(->cframe));
+ dasm_put(Dst, 3163, Dt1(->status), LUA_YIELD, Dt1(->top), Dt1(->base), Dt1(->maxstack), Dt1(->top), Dt1(->base), Dt1(->top));
+ dasm_put(Dst, 3233, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), LUA_YIELD, Dt1(->base), Dt1(->top), Dt1(->top), Dt1(->maxstack));
+ dasm_put(Dst, 3334, FRAME_TYPE, Dt1(->top), Dt1(->base), Dt1(->cframe), CFRAME_RESUME);
+ dasm_put(Dst, 3447, Dt1(->base), Dt1(->top), Dt1(->cframe), LUA_YIELD, Dt1(->status), 1+1, LJ_TISNUM, 1+1);
+ dasm_put(Dst, 3516, FRAME_TYPE, LJ_TNIL, LJ_TISNUM);
+ dasm_put(Dst, 3616, LJ_TISNUM, 1+1, LJ_TISNUM);
+ dasm_put(Dst, 3671, 1+1, LJ_TISNUM, 1+1, LJ_TISNUM, 1+1);
+ dasm_put(Dst, 3742, LJ_TISNUM, 1+1, LJ_TISNUM, 1+1);
+ dasm_put(Dst, 3799, LJ_TISNUM, 1+1, LJ_TISNUM, 1+1, LJ_TISNUM);
+ dasm_put(Dst, 3867, 1+1, LJ_TISNUM, 1+1, LJ_TISNUM);
+ dasm_put(Dst, 3961, 1+1, LJ_TISNUM, 1+1, LJ_TISNUM, 1+1);
+ dasm_put(Dst, 4044, LJ_TISNUM, 1+1, LJ_TISNUM, Dt8(->upvalue[0]), 2+1);
+ dasm_put(Dst, 4116, LJ_TISNUM, LJ_TISNUM, 2+1, LJ_TISNUM, LJ_TISNUM);
+ dasm_put(Dst, 4191, 1+1, LJ_TISNUM, 1+2);
+ dasm_put(Dst, 4321, 1+1, LJ_TISNUM, 1+2);
+ dasm_put(Dst, 4436, 2+1, LJ_TISNUM, LJ_TISNUM);
+ dasm_put(Dst, 4518, 2+1, LJ_TISNUM, LJ_TISNUM, LJ_TISNUM);
+ dasm_put(Dst, 4583, LJ_TISNUM, LJ_TISNUM, LJ_TISNUM);
+ dasm_put(Dst, 4680, 1+1, LJ_TSTR, Dt5(->len), 1+1, LJ_TSTR, Dt5(->len));
+ dasm_put(Dst, 4744, Dt5([1]), DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold), 1+1, LJ_TISNUM);
+ dasm_put(Dst, 4818, Dt1(->base), Dt1(->base), LJ_TSTR, DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold), 1+2, LJ_TISNUM);
+ dasm_put(Dst, 4921, LJ_TSTR, LJ_TISNUM, Dt5(->len), sizeof(GCstr)-1);
+ dasm_put(Dst, 5013);
+ dasm_put(Dst, 5083, DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold), 2+1, LJ_TSTR, LJ_TISNUM, Dt5(->len));
+ dasm_put(Dst, 5152, DISPATCH_GL(tmpbuf.sz), Dt5([1]), DISPATCH_GL(tmpbuf.buf), DISPATCH_GL(tmpbuf.buf), 1+1, DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold));
+ dasm_put(Dst, 5217, LJ_TSTR, Dt5(->len), DISPATCH_GL(tmpbuf.sz), sizeof(GCstr), DISPATCH_GL(tmpbuf.buf));
+ dasm_put(Dst, 5296, 1+1, DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold), LJ_TSTR, Dt5(->len), DISPATCH_GL(tmpbuf.sz), sizeof(GCstr), DISPATCH_GL(tmpbuf.buf));
+ dasm_put(Dst, 5361, 1+1, DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold));
+ dasm_put(Dst, 5437, LJ_TSTR, Dt5(->len), DISPATCH_GL(tmpbuf.sz), sizeof(GCstr), DISPATCH_GL(tmpbuf.buf));
+ dasm_put(Dst, 5518, 1+1, LJ_TTAB, 1+1, LJ_TISNUM);
+ dasm_put(Dst, 5617, 1+1, LJ_TISNUM, LJ_TISNUM, 1+1, LJ_TISNUM);
+ dasm_put(Dst, 5725, LJ_TISNUM, 1+1, LJ_TISNUM);
+ dasm_put(Dst, 5841, LJ_TISNUM, 1+1, LJ_TISNUM, 1+1);
+ dasm_put(Dst, 5933, LJ_TISNUM, 2+1, LJ_TISNUM, LJ_TISNUM);
+ dasm_put(Dst, 6018, 2+1, LJ_TISNUM, LJ_TISNUM, 2+1, LJ_TISNUM);
+ dasm_put(Dst, 6149, LJ_TISNUM, 2+1, LJ_TISNUM, LJ_TISNUM, 2+1);
+ dasm_put(Dst, 6280, LJ_TISNUM, LJ_TISNUM, 1+2, 1+1, Dt1(->base), 8*LUA_MINSTACK, Dt1(->top), Dt1(->maxstack));
+ dasm_put(Dst, 6391, Dt8(->f), Dt1(->base), Dt1(->top), Dt7(->pc), FRAME_TYPE, LUA_MINSTACK);
+ dasm_put(Dst, 6499, Dt1(->base), Dt1(->base), Dt1(->top), Dt1(->base), Dt1(->top), DISPATCH_GL(hookmask), HOOK_VMEVENT, HOOK_ACTIVE, LUA_MASKLINE|LUA_MASKCOUNT, DISPATCH_GL(hookcount));
+ dasm_put(Dst, 6597, DISPATCH_GL(hookmask), HOOK_ACTIVE, DISPATCH_GL(hookmask), HOOK_ACTIVE, LUA_MASKLINE|LUA_MASKCOUNT, DISPATCH_GL(hookcount));
+ dasm_put(Dst, 6644, LUA_MASKLINE, Dt1(->base), Dt1(->base), GG_DISP2STATIC, Dt7(->pc), PC2PROTO(framesize), Dt1(->base), Dt1(->top), GG_DISP2J, DISPATCH_J(L));
+ dasm_put(Dst, 6751, Dt1(->base), Dt1(->top), Dt1(->base), Dt1(->top), DISPATCH_GL(vmstate), DISPATCH_GL(vmstate), ~LJ_VMST_EXIT, DISPATCH_J(exitno), DISPATCH_J(parent), 8*8+16, DISPATCH_GL(jit_L), DISPATCH_GL(jit_base));
+ dasm_put(Dst, 6951, DISPATCH_J(L), DISPATCH_GL(jit_L), Dt1(->base), GG_DISP2J, Dt1(->cframe), CFRAME_RAWMASK, CFRAME_OFS_L, Dt1(->base), CFRAME_OFS_PC, Dt7(->pc), PC2PROTO(k), DISPATCH_GL(jit_L), DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, BC_FUNCF);
+ dasm_put(Dst, 7048);
+ dasm_put(Dst, 7567);
+ dasm_put(Dst, 7695);
+ dasm_put(Dst, 7763);
+ dasm_put(Dst, 7891);
+ dasm_put(Dst, 7994);
+ dasm_put(Dst, 8117);
+ dasm_put(Dst, 8306);
+ dasm_put(Dst, 8407);
+ dasm_put(Dst, 8519);
+ dasm_put(Dst, 8596);
+#ifdef LUA_USE_ASSERT
+ dasm_put(Dst, 8713);
+#endif
+#define DtE(_V) (int)(ptrdiff_t)&(((CTState *)0)_V)
+ dasm_put(Dst, 8715, GG_G2DISP, Dt2(->ctype_state), DtE(->cb.slot), CFRAME_SIZE+16, DtE(->cb.gpr[0]), DtE(->cb.gpr[1]), DtE(->cb.stack), CFRAME_SIZE+12, CFRAME_SIZE+8, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), Dt1(->top), Dt7(->pc), DISPATCH_GL(ctype_state), DtE(->L), Dt1(->base), Dt1(->top));
+#define DtF(_V) (int)(ptrdiff_t)&(((CCallState *)0)_V)
+ dasm_put(Dst, 8846, DtE(->cb.gpr[0]), DtE(->cb.gpr[1]), DtE(->cb.gpr[2]), DtE(->cb.fpr[0].d), DtE(->cb.fpr[0].f), Dt1(->top), DtF(->spadj), DtF(->spadj), DtF(->nsp));
+ dasm_put(Dst, 8947, offsetof(CCallState, stack), DtF(->gpr[0]), DtF(->gpr[1]), DtF(->func), DtF(->gpr[0]), DtF(->gpr[1]), DtF(->resx87), DtF(->fpr[0].d[0]), DtF(->fpr[0].f[0]));
+ dasm_put(Dst, 9008, DtF(->spadj));
+}
+
+/* Generate the code for a single instruction. */
+static void build_ins(BuildCtx *ctx, BCOp op, int defop)
+{
+ int vk = 0;
+ dasm_put(Dst, 470, defop);
+
+ switch (op) {
+
+ /* -- Comparison ops ---------------------------------------------------- */
+
+ /* Remember: all ops branch for a true comparison, fall through otherwise. */
+
+
+ case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:
+ dasm_put(Dst, 9018, LJ_TISNUM, LJ_TISNUM);
+ switch (op) {
+ case BC_ISLT:
+ dasm_put(Dst, 9059);
+ break;
+ case BC_ISGE:
+ dasm_put(Dst, 9064);
+ break;
+ case BC_ISLE:
+ dasm_put(Dst, 5212);
+ break;
+ case BC_ISGT:
+ dasm_put(Dst, 9069);
+ break;
+ default: break; /* Shut up GCC. */
+ }
+ dasm_put(Dst, 9074, -BCBIAS_J*4);
+ break;
+
+ case BC_ISEQV: case BC_ISNEV:
+ vk = op == BC_ISEQV;
+ dasm_put(Dst, 9105);
+ if (vk) {
+ } else {
+ }
+ dasm_put(Dst, 9113, LJ_TISNUM, LJ_TISNUM);
+ iseqne_fp:
+ if (vk) {
+ dasm_put(Dst, 9149);
+ } else {
+ dasm_put(Dst, 9158);
+ }
+ iseqne_end:
+ if (vk) {
+ dasm_put(Dst, 9167, -BCBIAS_J*4);
+ } else {
+ dasm_put(Dst, 9182, -BCBIAS_J*4);
+ }
+ if (LJ_DUALNUM && (op == BC_ISEQV || op == BC_ISNEV ||
+ op == BC_ISEQN || op == BC_ISNEN)) {
+ dasm_put(Dst, 9197);
+ } else {
+ dasm_put(Dst, 9086);
+ }
+ if (op == BC_ISEQV || op == BC_ISNEV) {
+ dasm_put(Dst, 9202, LJ_TCDATA, LJ_TCDATA, LJ_TISPRI, LJ_TISTABUD, Dt6(->metatable));
+ dasm_put(Dst, 9269, Dt6(->nomm), 1<<MM_eq);
+ if (vk) {
+ dasm_put(Dst, 9279);
+ } else {
+ dasm_put(Dst, 9283);
+ }
+ dasm_put(Dst, 9289);
+ } else {
+ dasm_put(Dst, 9294, LJ_TCDATA);
+ if (LJ_DUALNUM && vk) {
+ dasm_put(Dst, 9301);
+ } else {
+ dasm_put(Dst, 9274);
+ }
+ dasm_put(Dst, 9306);
+ }
+ break;
+ case BC_ISEQS: case BC_ISNES:
+ vk = op == BC_ISEQS;
+ dasm_put(Dst, 9311, LJ_TSTR);
+ iseqne_test:
+ if (vk) {
+ dasm_put(Dst, 9153);
+ } else {
+ dasm_put(Dst, 6639);
+ }
+ goto iseqne_end;
+ case BC_ISEQN: case BC_ISNEN:
+ vk = op == BC_ISEQN;
+ dasm_put(Dst, 9336);
+ if (vk) {
+ } else {
+ }
+ dasm_put(Dst, 9344, LJ_TISNUM);
+ goto iseqne_fp;
+ case BC_ISEQP: case BC_ISNEP:
+ vk = op == BC_ISEQP;
+ dasm_put(Dst, 9370);
+ if (!LJ_HASFFI) goto iseqne_test;
+ if (vk) {
+ dasm_put(Dst, 9383, -BCBIAS_J*4, LJ_TCDATA);
+ } else {
+ dasm_put(Dst, 9432, LJ_TCDATA, -BCBIAS_J*4);
+ }
+ break;
+
+ /* -- Unary test and copy ops ------------------------------------------- */
+
+ case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:
+ dasm_put(Dst, 9475, LJ_TISTRUECOND);
+ if (op == BC_IST || op == BC_ISTC) {
+ dasm_put(Dst, 9069);
+ } else {
+ dasm_put(Dst, 5212);
+ }
+ if (op == BC_ISTC || op == BC_ISFC) {
+ dasm_put(Dst, 9487);
+ }
+ dasm_put(Dst, 9074, -BCBIAS_J*4);
+ break;
+
+ /* -- Unary ops --------------------------------------------------------- */
+
+ case BC_MOV:
+ dasm_put(Dst, 9498);
+ break;
+ case BC_NOT:
+ dasm_put(Dst, 9531, LJ_TISTRUECOND, LJ_TTRUE);
+ break;
+ case BC_UNM:
+ dasm_put(Dst, 9566, LJ_TISNUM);
+ break;
+ case BC_LEN:
+ dasm_put(Dst, 9603, LJ_TSTR, Dt5(->len), LJ_TTAB);
+#if LJ_52
+ dasm_put(Dst, 9658, Dt6(->metatable));
+#endif
+ dasm_put(Dst, 9672);
+#if LJ_52
+ dasm_put(Dst, 9699, Dt6(->nomm), 1<<MM_len);
+#endif
+ break;
+
+ /* -- Binary ops -------------------------------------------------------- */
+
+
+ case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:
+ dasm_put(Dst, 9715);
+ vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
+ switch (vk) {
+ case 0:
+ dasm_put(Dst, 9723, LJ_TISNUM);
+ break;
+ case 1:
+ dasm_put(Dst, 9742, LJ_TISNUM);
+ break;
+ default:
+ dasm_put(Dst, 9761, LJ_TISNUM, LJ_TISNUM);
+ break;
+ }
+ dasm_put(Dst, 9581);
+ break;
+ case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:
+ dasm_put(Dst, 9715);
+ vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
+ switch (vk) {
+ case 0:
+ dasm_put(Dst, 9790, LJ_TISNUM);
+ break;
+ case 1:
+ dasm_put(Dst, 9809, LJ_TISNUM);
+ break;
+ default:
+ dasm_put(Dst, 9828, LJ_TISNUM, LJ_TISNUM);
+ break;
+ }
+ dasm_put(Dst, 9581);
+ break;
+ case BC_MULVN: case BC_MULNV: case BC_MULVV:
+ dasm_put(Dst, 9715);
+ vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
+ switch (vk) {
+ case 0:
+ dasm_put(Dst, 9857, LJ_TISNUM);
+ break;
+ case 1:
+ dasm_put(Dst, 9876, LJ_TISNUM);
+ break;
+ default:
+ dasm_put(Dst, 9895, LJ_TISNUM, LJ_TISNUM);
+ break;
+ }
+ dasm_put(Dst, 9581);
+ break;
+ case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:
+ dasm_put(Dst, 9715);
+ vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
+ switch (vk) {
+ case 0:
+ dasm_put(Dst, 9924, LJ_TISNUM);
+ break;
+ case 1:
+ dasm_put(Dst, 9943, LJ_TISNUM);
+ break;
+ default:
+ dasm_put(Dst, 9962, LJ_TISNUM, LJ_TISNUM);
+ break;
+ }
+ dasm_put(Dst, 9581);
+ break;
+ case BC_MODVN:
+ dasm_put(Dst, 9715);
+ vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
+ switch (vk) {
+ case 0:
+ dasm_put(Dst, 9991, LJ_TISNUM);
+ break;
+ case 1:
+ dasm_put(Dst, 10010, LJ_TISNUM);
+ break;
+ default:
+ dasm_put(Dst, 10029, LJ_TISNUM, LJ_TISNUM);
+ break;
+ }
+ dasm_put(Dst, 10058);
+ break;
+ case BC_MODNV: case BC_MODVV:
+ dasm_put(Dst, 9715);
+ vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
+ switch (vk) {
+ case 0:
+ dasm_put(Dst, 9991, LJ_TISNUM);
+ break;
+ case 1:
+ dasm_put(Dst, 10010, LJ_TISNUM);
+ break;
+ default:
+ dasm_put(Dst, 10029, LJ_TISNUM, LJ_TISNUM);
+ break;
+ }
+ dasm_put(Dst, 10085);
+ break;
+ case BC_POW:
+ dasm_put(Dst, 9715);
+ vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
+ switch (vk) {
+ case 0:
+ dasm_put(Dst, 9991, LJ_TISNUM);
+ break;
+ case 1:
+ dasm_put(Dst, 10010, LJ_TISNUM);
+ break;
+ default:
+ dasm_put(Dst, 10029, LJ_TISNUM, LJ_TISNUM);
+ break;
+ }
+ dasm_put(Dst, 10090);
+ break;
+
+ case BC_CAT:
+ dasm_put(Dst, 10115, Dt1(->base), Dt1(->base));
+ break;
+
+ /* -- Constant ops ------------------------------------------------------ */
+
+ case BC_KSTR:
+ dasm_put(Dst, 10209, LJ_TSTR);
+ break;
+ case BC_KCDATA:
+ dasm_put(Dst, 10209, LJ_TCDATA);
+ break;
+ case BC_KSHORT:
+ dasm_put(Dst, 10242);
+ break;
+ case BC_KNUM:
+ dasm_put(Dst, 10268);
+ break;
+ case BC_KPRI:
+ dasm_put(Dst, 10293);
+ break;
+ case BC_KNIL:
+ dasm_put(Dst, 10319, LJ_TNIL);
+ break;
+
+ /* -- Upvalue and function ops ------------------------------------------ */
+
+ case BC_UGET:
+ dasm_put(Dst, 10365, offsetof(GCfuncL, uvptr), DtA(->v));
+ break;
+ case BC_USETV:
+#define TV2MARKOFS \
+ ((int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv))
+ dasm_put(Dst, 10409, offsetof(GCfuncL, uvptr), DtA(->closed), DtA(->v), TV2MARKOFS, LJ_GC_BLACK, LJ_TISGCV, LJ_TNUMX - LJ_TISGCV, Dt4(->gch.marked), LJ_GC_WHITES, GG_DISP2G);
+ dasm_put(Dst, 10499);
+ break;
+#undef TV2MARKOFS
+ case BC_USETS:
+ dasm_put(Dst, 10511, offsetof(GCfuncL, uvptr), DtA(->v), LJ_TSTR, DtA(->marked), LJ_GC_BLACK, Dt4(->gch.marked), LJ_GC_WHITES, DtA(->closed), GG_DISP2G);
+ break;
+ case BC_USETN:
+ dasm_put(Dst, 10602, offsetof(GCfuncL, uvptr), DtA(->v));
+ break;
+ case BC_USETP:
+ dasm_put(Dst, 10638, offsetof(GCfuncL, uvptr), DtA(->v));
+ break;
+ case BC_UCLO:
+ dasm_put(Dst, 10675, -BCBIAS_J*4, Dt1(->openupval), Dt1(->base), Dt1(->base));
+ break;
+
+ case BC_FNEW:
+ dasm_put(Dst, 10729, Dt1(->base), Dt1(->base), LJ_TFUNC);
+ break;
+
+ /* -- Table ops --------------------------------------------------------- */
+
+ case BC_TNEW:
+ dasm_put(Dst, 10800, Dt1(->base), DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold), Dt1(->base), LJ_TTAB);
+ break;
+ case BC_TDUP:
+ dasm_put(Dst, 10926, DISPATCH_GL(gc.total), DISPATCH_GL(gc.threshold), Dt1(->base), Dt1(->base), LJ_TTAB);
+ break;
+
+ case BC_GGET:
+ dasm_put(Dst, 11018, Dt7(->env));
+ break;
+ case BC_GSET:
+ dasm_put(Dst, 11036, Dt7(->env));
+ break;
+
+ case BC_TGETV:
+ dasm_put(Dst, 11054, LJ_TTAB, LJ_TISNUM, Dt6(->asize), Dt6(->array), LJ_TNIL, Dt6(->metatable));
+ dasm_put(Dst, 11172, Dt6(->metatable), Dt6(->nomm), 1<<MM_index, LJ_TNIL, LJ_TSTR);
+ break;
+ case BC_TGETS:
+ dasm_put(Dst, 11220, LJ_TTAB, Dt6(->hmask), Dt5(->hash), sizeof(Node), Dt6(->node), DtB(->key.it), LJ_TSTR, DtB(->key.gcr), LJ_TNIL);
+ dasm_put(Dst, 11308, LJ_TNIL, DtB(->next), Dt6(->metatable), Dt6(->nomm), 1<<MM_index);
+ break;
+ case BC_TGETB:
+ dasm_put(Dst, 11378, LJ_TTAB, Dt6(->asize), Dt6(->array), LJ_TNIL, Dt6(->metatable), Dt6(->metatable), Dt6(->nomm), 1<<MM_index);
+ dasm_put(Dst, 11477, LJ_TNIL);
+ break;
+
+ case BC_TSETV:
+ dasm_put(Dst, 11494, LJ_TTAB, LJ_TISNUM, Dt6(->asize), Dt6(->array), LJ_TNIL, Dt6(->marked), LJ_GC_BLACK);
+ dasm_put(Dst, 11583, Dt6(->metatable), Dt6(->metatable), Dt6(->nomm), 1<<MM_newindex, LJ_TSTR, Dt6(->marked), (uint8_t)~LJ_GC_BLACK);
+ dasm_put(Dst, 11670, DISPATCH_GL(gc.grayagain), DISPATCH_GL(gc.grayagain), Dt6(->gclist));
+ break;
+ case BC_TSETS:
+ dasm_put(Dst, 11689, LJ_TTAB, Dt6(->hmask), Dt5(->hash), sizeof(Node), Dt6(->nomm), Dt6(->node), DtB(->key.it), LJ_TSTR, DtB(->key.gcr), LJ_TNIL);
+ dasm_put(Dst, 11764, Dt6(->marked), LJ_GC_BLACK, Dt6(->metatable), Dt6(->metatable), Dt6(->nomm), 1<<MM_newindex, DtB(->next));
+ dasm_put(Dst, 11856, Dt6(->metatable), Dt6(->nomm), 1<<MM_newindex, LJ_TSTR, Dt1(->base), Dt1(->base), Dt6(->marked), (uint8_t)~LJ_GC_BLACK, DISPATCH_GL(gc.grayagain), DISPATCH_GL(gc.grayagain), Dt6(->gclist));
+ break;
+ case BC_TSETB:
+ dasm_put(Dst, 11952, LJ_TTAB, Dt6(->asize), Dt6(->array), LJ_TNIL, Dt6(->marked), LJ_GC_BLACK, Dt6(->metatable));
+ dasm_put(Dst, 12050, Dt6(->metatable), Dt6(->nomm), 1<<MM_newindex, Dt6(->marked), (uint8_t)~LJ_GC_BLACK, DISPATCH_GL(gc.grayagain), DISPATCH_GL(gc.grayagain), Dt6(->gclist));
+ break;
+
+ case BC_TSETM:
+ dasm_put(Dst, 12096, Dt6(->marked), LJ_GC_BLACK, Dt6(->asize), Dt6(->array), Dt1(->base), Dt1(->base));
+ dasm_put(Dst, 12245, Dt6(->marked), (uint8_t)~LJ_GC_BLACK, DISPATCH_GL(gc.grayagain), DISPATCH_GL(gc.grayagain), Dt6(->gclist));
+ break;
+
+ /* -- Calls and vararg handling ----------------------------------------- */
+
+ case BC_CALL: case BC_CALLM:
+ dasm_put(Dst, 9719);
+ if (op == BC_CALLM) {
+ dasm_put(Dst, 12263);
+ }
+ dasm_put(Dst, 12268, LJ_TFUNC, Dt7(->pc));
+ break;
+
+ case BC_CALLMT:
+ dasm_put(Dst, 12263);
+ break;
+ case BC_CALLT:
+ dasm_put(Dst, 12309, LJ_TFUNC, FRAME_TYPE, Dt7(->ffid), Dt7(->pc));
+ dasm_put(Dst, 12427, FRAME_TYPE, Dt7(->pc), PC2PROTO(k), FRAME_VARG, FRAME_TYPEP, FRAME_VARG);
+ break;
+
+ case BC_ITERC:
+ dasm_put(Dst, 12495, LJ_TFUNC, 2+1, Dt7(->pc));
+ break;
+
+ case BC_ITERN:
+ dasm_put(Dst, 12575, Dt6(->asize), Dt6(->array), LJ_TNIL, -BCBIAS_J*4, Dt6(->hmask), sizeof(Node));
+ dasm_put(Dst, 12723, Dt6(->node), DtB(->val.it), LJ_TNIL, DtB(->key.gcr), DtB(->key.it), DtB(->val.gcr), DtB(->val.it));
+ break;
+
+ case BC_ISNEXT:
+ dasm_put(Dst, 12784, LJ_TFUNC, LJ_TTAB, LJ_TNIL, Dt8(->ffid), FF_next_N, -BCBIAS_J*4, BC_JMP, -BCBIAS_J*4, BC_ITERC);
+ break;
+
+ case BC_VARG:
+ dasm_put(Dst, 12895, (8+FRAME_VARG), LJ_TNIL, Dt1(->maxstack));
+ dasm_put(Dst, 13059, Dt1(->base), Dt1(->top), Dt1(->base), Dt1(->top));
+ break;
+
+ /* -- Returns ----------------------------------------------------------- */
+
+ case BC_RETM:
+ dasm_put(Dst, 12263);
+ break;
+
+ case BC_RET: case BC_RET0: case BC_RET1:
+ if (op != BC_RET0) {
+ dasm_put(Dst, 13130);
+ }
+ dasm_put(Dst, 13134, FRAME_TYPE);
+ switch (op) {
+ case BC_RET:
+ dasm_put(Dst, 13153);
+ break;
+ case BC_RET1:
+ dasm_put(Dst, 13211);
+ /* fallthrough */
+ case BC_RET0:
+ dasm_put(Dst, 13227);
+ default:
+ break;
+ }
+ dasm_put(Dst, 13238, Dt7(->pc), PC2PROTO(k));
+ if (op == BC_RET) {
+ dasm_put(Dst, 13280, LJ_TNIL);
+ } else {
+ dasm_put(Dst, 13289, LJ_TNIL);
+ }
+ dasm_put(Dst, 13296, -FRAME_VARG, FRAME_TYPEP);
+ if (op != BC_RET0) {
+ dasm_put(Dst, 13320);
+ }
+ dasm_put(Dst, 9694);
+ break;
+
+ /* -- Loops and branches ------------------------------------------------ */
+
+
+ case BC_FORL:
+ dasm_put(Dst, 13324, HOTCOUNT_PCMASK, GG_DISP2HOT, HOTCOUNT_LOOP);
+ break;
+
+ case BC_JFORI:
+ case BC_JFORL:
+#if !LJ_HASJIT
+ break;
+#endif
+ case BC_FORI:
+ case BC_IFORL:
+ vk = (op == BC_IFORL || op == BC_JFORL);
+ dasm_put(Dst, 13345);
+ if (LJ_DUALNUM) {
+ dasm_put(Dst, 13349, LJ_TISNUM);
+ if (!vk) {
+ dasm_put(Dst, 13359, LJ_TISNUM, LJ_TISNUM);
+ } else {
+#ifdef LUA_USE_ASSERT
+ dasm_put(Dst, 13388, LJ_TISNUM, LJ_TISNUM);
+#endif
+ dasm_put(Dst, 13407);
+ }
+ dasm_put(Dst, 13426, LJ_TISNUM);
+ if (op == BC_FORI) {
+ dasm_put(Dst, 13437, -BCBIAS_J*4);
+ } else if (op == BC_JFORI) {
+ dasm_put(Dst, 13451, -BCBIAS_J*4, BC_JLOOP);
+ } else if (op == BC_IFORL) {
+ dasm_put(Dst, 13469, -BCBIAS_J*4);
+ } else {
+ dasm_put(Dst, 13461, BC_JLOOP);
+ }
+ dasm_put(Dst, 13483);
+ if (vk) {
+ dasm_put(Dst, 13506);
+ }
+ dasm_put(Dst, 13426, LJ_TISNUM);
+ if (op == BC_FORI) {
+ dasm_put(Dst, 13515);
+ } else if (op == BC_JFORI) {
+ dasm_put(Dst, 13520, -BCBIAS_J*4, BC_JLOOP);
+ } else if (op == BC_IFORL) {
+ dasm_put(Dst, 13534);
+ } else {
+ dasm_put(Dst, 13530, BC_JLOOP);
+ }
+ dasm_put(Dst, 13539);
+ } else if (!vk) {
+ dasm_put(Dst, 13546, LJ_TISNUM);
+ }
+ if (!vk) {
+ dasm_put(Dst, 13552, LJ_TISNUM);
+ } else {
+#ifdef LUA_USE_ASSERT
+ dasm_put(Dst, 13566, LJ_TISNUM, LJ_TISNUM);
+#endif
+ }
+ dasm_put(Dst, 13585);
+ if (!vk) {
+ dasm_put(Dst, 13589, LJ_TISNUM);
+ }
+ if (vk) {
+ } else {
+ }
+ dasm_put(Dst, 13598);
+ if (vk) {
+ dasm_put(Dst, 13604);
+ } else {
+ dasm_put(Dst, 13620);
+ }
+ dasm_put(Dst, 13628);
+ if (op == BC_FORI) {
+ dasm_put(Dst, 13638, -BCBIAS_J*4);
+ } else if (op == BC_JFORI) {
+ dasm_put(Dst, 13648, -BCBIAS_J*4, BC_JLOOP);
+ } else if (op == BC_IFORL) {
+ dasm_put(Dst, 13662, -BCBIAS_J*4);
+ } else {
+ dasm_put(Dst, 13658, BC_JLOOP);
+ }
+ dasm_put(Dst, 9454);
+ break;
+
+ case BC_ITERL:
+ dasm_put(Dst, 13324, HOTCOUNT_PCMASK, GG_DISP2HOT, HOTCOUNT_LOOP);
+ break;
+
+ case BC_JITERL:
+#if !LJ_HASJIT
+ break;
+#endif
+ case BC_IITERL:
+ dasm_put(Dst, 13672, LJ_TNIL);
+ if (op == BC_JITERL) {
+ dasm_put(Dst, 13687, BC_JLOOP);
+ } else {
+ dasm_put(Dst, 13701, -BCBIAS_J*4);
+ }
+ dasm_put(Dst, 9084);
+ break;
+
+ case BC_LOOP:
+ dasm_put(Dst, 13324, HOTCOUNT_PCMASK, GG_DISP2HOT, HOTCOUNT_LOOP);
+ break;
+
+ case BC_ILOOP:
+ dasm_put(Dst, 9086);
+ break;
+
+ case BC_JLOOP:
+ dasm_put(Dst, 13717, DISPATCH_J(trace), DtD(->mcode), DISPATCH_GL(jit_base), DISPATCH_GL(jit_L));
+ break;
+
+ case BC_JMP:
+ dasm_put(Dst, 13740, -BCBIAS_J*4);
+ break;
+
+ /* -- Function headers -------------------------------------------------- */
+
+ /*
+ ** Reminder: A function may be called with func/args above L->maxstack,
+ ** i.e. occupying EXTRA_STACK slots. And vmeta_call may add one extra slot,
+ ** too. This means all FUNC* ops (including fast functions) must check
+ ** for stack overflow _before_ adding more slots!
+ */
+
+ case BC_FUNCF:
+ dasm_put(Dst, 13764, HOTCOUNT_PCMASK, GG_DISP2HOT, HOTCOUNT_CALL);
+ case BC_FUNCV: /* NYI: compiled vararg functions. */
+ break;
+
+ case BC_JFUNCF:
+#if !LJ_HASJIT
+ break;
+#endif
+ case BC_IFUNCF:
+ dasm_put(Dst, 13785, -4+PC2PROTO(k), Dt1(->maxstack), -4+PC2PROTO(numparams));
+ if (op == BC_JFUNCF) {
+ dasm_put(Dst, 13815, BC_JLOOP);
+ } else {
+ dasm_put(Dst, 9086);
+ }
+ dasm_put(Dst, 13824, LJ_TNIL);
+ break;
+
+ case BC_JFUNCV:
+#if !LJ_HASJIT
+ break;
+#endif
+ dasm_put(Dst, 8713);
+ break; /* NYI: compiled vararg functions. */
+
+ case BC_IFUNCV:
+ dasm_put(Dst, 13846, FRAME_VARG, Dt1(->maxstack), -4+PC2PROTO(numparams), LJ_TNIL);
+ if (op == BC_JFUNCV) {
+ dasm_put(Dst, 13815, BC_JLOOP);
+ } else {
+ dasm_put(Dst, 13937, -4+PC2PROTO(k));
+ }
+ dasm_put(Dst, 13959, LJ_TNIL);
+ break;
+
+ case BC_FUNCC:
+ case BC_FUNCCW:
+ dasm_put(Dst, 13981, Dt8(->f), Dt1(->base), 8*LUA_MINSTACK, Dt1(->maxstack), Dt1(->top));
+ if (op == BC_FUNCC) {
+ dasm_put(Dst, 14010);
+ } else {
+ dasm_put(Dst, 14014);
+ }
+ dasm_put(Dst, 14022, DISPATCH_GL(vmstate), ~LJ_VMST_C);
+ if (op == BC_FUNCC) {
+ dasm_put(Dst, 14031);
+ } else {
+ dasm_put(Dst, 14035, DISPATCH_GL(wrapf));
+ }
+ dasm_put(Dst, 14040, DISPATCH_GL(vmstate), ~LJ_VMST_INTERP, Dt1(->base), Dt1(->top));
+ break;
+
+ /* ---------------------------------------------------------------------- */
+
+ default:
+ fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]);
+ exit(2);
+ break;
+ }
+}
+
+static int build_backend(BuildCtx *ctx)
+{
+ int op;
+ dasm_growpc(Dst, BC__MAX);
+ build_subroutines(ctx);
+ dasm_put(Dst, 14065);
+ for (op = 0; op < BC__MAX; op++)
+ build_ins(ctx, (BCOp)op, op);
+ return BC__MAX;
+}
+
+/* Emit pseudo frame-info for all assembler functions. */
+static void emit_asm_debug(BuildCtx *ctx)
+{
+ int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);
+#if LJ_64
+#define SZPTR "8"
+#define BSZPTR "3"
+#define REG_SP "0x7"
+#define REG_RA "0x10"
+#else
+#define SZPTR "4"
+#define BSZPTR "2"
+#define REG_SP "0x4"
+#define REG_RA "0x8"
+#endif
+ switch (ctx->mode) {
+ case BUILD_elfasm:
+ fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n");
+ fprintf(ctx->fp,
+ ".Lframe0:\n"
+ "\t.long .LECIE0-.LSCIE0\n"
+ ".LSCIE0:\n"
+ "\t.long 0xffffffff\n"
+ "\t.byte 0x1\n"
+ "\t.string \"\"\n"
+ "\t.uleb128 0x1\n"
+ "\t.sleb128 -" SZPTR "\n"
+ "\t.byte " REG_RA "\n"
+ "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n"
+ "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n"
+ "\t.align " SZPTR "\n"
+ ".LECIE0:\n\n");
+ fprintf(ctx->fp,
+ ".LSFDE0:\n"
+ "\t.long .LEFDE0-.LASFDE0\n"
+ ".LASFDE0:\n"
+ "\t.long .Lframe0\n"
+#if LJ_64
+ "\t.quad .Lbegin\n"
+ "\t.quad %d\n"
+ "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
+ "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
+ "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
+ "\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */
+ "\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */
+#if LJ_NO_UNWIND
+ "\t.byte 0x8d\n\t.uleb128 0x6\n" /* offset r13 */
+ "\t.byte 0x8c\n\t.uleb128 0x7\n" /* offset r12 */
+#endif
+#else
+ "\t.long .Lbegin\n"
+ "\t.long %d\n"
+ "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
+ "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
+ "\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */
+ "\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */
+ "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */
+#endif
+ "\t.align " SZPTR "\n"
+ ".LEFDE0:\n\n", fcofs, CFRAME_SIZE);
+#if LJ_HASFFI
+ fprintf(ctx->fp,
+ ".LSFDE1:\n"
+ "\t.long .LEFDE1-.LASFDE1\n"
+ ".LASFDE1:\n"
+ "\t.long .Lframe0\n"
+#if LJ_64
+ "\t.quad lj_vm_ffi_call\n"
+ "\t.quad %d\n"
+ "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */
+ "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
+ "\t.byte 0xd\n\t.uleb128 0x6\n" /* def_cfa_register rbp */
+ "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
+#else
+ "\t.long lj_vm_ffi_call\n"
+ "\t.long %d\n"
+ "\t.byte 0xe\n\t.uleb128 8\n" /* def_cfa_offset */
+ "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
+ "\t.byte 0xd\n\t.uleb128 0x5\n" /* def_cfa_register ebp */
+ "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset ebx */
+#endif
+ "\t.align " SZPTR "\n"
+ ".LEFDE1:\n\n", (int)ctx->codesz - fcofs);
+#endif
+#if !LJ_NO_UNWIND
+#if (defined(__sun__) && defined(__svr4__))
+#if LJ_64
+ fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@unwind\n");
+#else
+ fprintf(ctx->fp, "\t.section .eh_frame,\"aw\",@progbits\n");
+#endif
+#else
+ fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@progbits\n");
+#endif
+ fprintf(ctx->fp,
+ ".Lframe1:\n"
+ "\t.long .LECIE1-.LSCIE1\n"
+ ".LSCIE1:\n"
+ "\t.long 0\n"
+ "\t.byte 0x1\n"
+ "\t.string \"zPR\"\n"
+ "\t.uleb128 0x1\n"
+ "\t.sleb128 -" SZPTR "\n"
+ "\t.byte " REG_RA "\n"
+ "\t.uleb128 6\n" /* augmentation length */
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.long lj_err_unwind_dwarf-.\n"
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n"
+ "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n"
+ "\t.align " SZPTR "\n"
+ ".LECIE1:\n\n");
+ fprintf(ctx->fp,
+ ".LSFDE2:\n"
+ "\t.long .LEFDE2-.LASFDE2\n"
+ ".LASFDE2:\n"
+ "\t.long .LASFDE2-.Lframe1\n"
+ "\t.long .Lbegin-.\n"
+ "\t.long %d\n"
+ "\t.uleb128 0\n" /* augmentation length */
+ "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
+#if LJ_64
+ "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
+ "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
+ "\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */
+ "\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */
+#else
+ "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
+ "\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */
+ "\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */
+ "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */
+#endif
+ "\t.align " SZPTR "\n"
+ ".LEFDE2:\n\n", fcofs, CFRAME_SIZE);
+#if LJ_HASFFI
+ fprintf(ctx->fp,
+ ".Lframe2:\n"
+ "\t.long .LECIE2-.LSCIE2\n"
+ ".LSCIE2:\n"
+ "\t.long 0\n"
+ "\t.byte 0x1\n"
+ "\t.string \"zR\"\n"
+ "\t.uleb128 0x1\n"
+ "\t.sleb128 -" SZPTR "\n"
+ "\t.byte " REG_RA "\n"
+ "\t.uleb128 1\n" /* augmentation length */
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n"
+ "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n"
+ "\t.align " SZPTR "\n"
+ ".LECIE2:\n\n");
+ fprintf(ctx->fp,
+ ".LSFDE3:\n"
+ "\t.long .LEFDE3-.LASFDE3\n"
+ ".LASFDE3:\n"
+ "\t.long .LASFDE3-.Lframe2\n"
+ "\t.long lj_vm_ffi_call-.\n"
+ "\t.long %d\n"
+ "\t.uleb128 0\n" /* augmentation length */
+#if LJ_64
+ "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */
+ "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
+ "\t.byte 0xd\n\t.uleb128 0x6\n" /* def_cfa_register rbp */
+ "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
+#else
+ "\t.byte 0xe\n\t.uleb128 8\n" /* def_cfa_offset */
+ "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
+ "\t.byte 0xd\n\t.uleb128 0x5\n" /* def_cfa_register ebp */
+ "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset ebx */
+#endif
+ "\t.align " SZPTR "\n"
+ ".LEFDE3:\n\n", (int)ctx->codesz - fcofs);
+#endif
+#endif
+ break;
+#if !LJ_NO_UNWIND
+ /* Mental note: never let Apple design an assembler.
+ ** Or a linker. Or a plastic case. But I digress.
+ */
+ case BUILD_machasm: {
+#if LJ_HASFFI
+ int fcsize = 0;
+#endif
+ int i;
+ fprintf(ctx->fp, "\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\n");
+ fprintf(ctx->fp,
+ "EH_frame1:\n"
+ "\t.set L$set$x,LECIEX-LSCIEX\n"
+ "\t.long L$set$x\n"
+ "LSCIEX:\n"
+ "\t.long 0\n"
+ "\t.byte 0x1\n"
+ "\t.ascii \"zPR\\0\"\n"
+ "\t.byte 0x1\n"
+ "\t.byte 128-" SZPTR "\n"
+ "\t.byte " REG_RA "\n"
+ "\t.byte 6\n" /* augmentation length */
+ "\t.byte 0x9b\n" /* indirect|pcrel|sdata4 */
+#if LJ_64
+ "\t.long _lj_err_unwind_dwarf+4@GOTPCREL\n"
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.byte 0xc\n\t.byte " REG_SP "\n\t.byte " SZPTR "\n"
+#else
+ "\t.long L_lj_err_unwind_dwarf$non_lazy_ptr-.\n"
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.byte 0xc\n\t.byte 0x5\n\t.byte 0x4\n" /* esp=5 on 32 bit MACH-O. */
+#endif
+ "\t.byte 0x80+" REG_RA "\n\t.byte 0x1\n"
+ "\t.align " BSZPTR "\n"
+ "LECIEX:\n\n");
+ for (i = 0; i < ctx->nsym; i++) {
+ const char *name = ctx->sym[i].name;
+ int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs;
+ if (size == 0) continue;
+#if LJ_HASFFI
+ if (!strcmp(name, "_lj_vm_ffi_call")) { fcsize = size; continue; }
+#endif
+ fprintf(ctx->fp,
+ "%s.eh:\n"
+ "LSFDE%d:\n"
+ "\t.set L$set$%d,LEFDE%d-LASFDE%d\n"
+ "\t.long L$set$%d\n"
+ "LASFDE%d:\n"
+ "\t.long LASFDE%d-EH_frame1\n"
+ "\t.long %s-.\n"
+ "\t.long %d\n"
+ "\t.byte 0\n" /* augmentation length */
+ "\t.byte 0xe\n\t.byte %d\n" /* def_cfa_offset */
+#if LJ_64
+ "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */
+ "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */
+ "\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */
+ "\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */
+#else
+ "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/
+ "\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */
+ "\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */
+ "\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */
+#endif
+ "\t.align " BSZPTR "\n"
+ "LEFDE%d:\n\n",
+ name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);
+ }
+#if LJ_HASFFI
+ if (fcsize) {
+ fprintf(ctx->fp,
+ "EH_frame2:\n"
+ "\t.set L$set$y,LECIEY-LSCIEY\n"
+ "\t.long L$set$y\n"
+ "LSCIEY:\n"
+ "\t.long 0\n"
+ "\t.byte 0x1\n"
+ "\t.ascii \"zR\\0\"\n"
+ "\t.byte 0x1\n"
+ "\t.byte 128-" SZPTR "\n"
+ "\t.byte " REG_RA "\n"
+ "\t.byte 1\n" /* augmentation length */
+#if LJ_64
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.byte 0xc\n\t.byte " REG_SP "\n\t.byte " SZPTR "\n"
+#else
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.byte 0xc\n\t.byte 0x5\n\t.byte 0x4\n" /* esp=5 on 32 bit MACH. */
+#endif
+ "\t.byte 0x80+" REG_RA "\n\t.byte 0x1\n"
+ "\t.align " BSZPTR "\n"
+ "LECIEY:\n\n");
+ fprintf(ctx->fp,
+ "_lj_vm_ffi_call.eh:\n"
+ "LSFDEY:\n"
+ "\t.set L$set$yy,LEFDEY-LASFDEY\n"
+ "\t.long L$set$yy\n"
+ "LASFDEY:\n"
+ "\t.long LASFDEY-EH_frame2\n"
+ "\t.long _lj_vm_ffi_call-.\n"
+ "\t.long %d\n"
+ "\t.byte 0\n" /* augmentation length */
+#if LJ_64
+ "\t.byte 0xe\n\t.byte 16\n" /* def_cfa_offset */
+ "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */
+ "\t.byte 0xd\n\t.byte 0x6\n" /* def_cfa_register rbp */
+ "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */
+#else
+ "\t.byte 0xe\n\t.byte 8\n" /* def_cfa_offset */
+ "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/
+ "\t.byte 0xd\n\t.byte 0x4\n" /* def_cfa_register ebp */
+ "\t.byte 0x83\n\t.byte 0x3\n" /* offset ebx */
+#endif
+ "\t.align " BSZPTR "\n"
+ "LEFDEY:\n\n", fcsize);
+ }
+#endif
+#if LJ_64
+ fprintf(ctx->fp, "\t.subsections_via_symbols\n");
+#else
+ fprintf(ctx->fp,
+ "\t.non_lazy_symbol_pointer\n"
+ "L_lj_err_unwind_dwarf$non_lazy_ptr:\n"
+ ".indirect_symbol _lj_err_unwind_dwarf\n"
+ ".long 0\n");
+#endif
+ }
+ break;
+#endif
+ default: /* Difficult for other modes. */
+ break;
+ }
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/host/.gitignore b/src/3rdparty/LuaJIT-2.0.5/src/host/.gitignore
new file mode 100644
index 0000000..762ac2a
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/host/.gitignore
@@ -0,0 +1,3 @@
+minilua
+buildvm
+buildvm_arch.h
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/host/README b/src/3rdparty/LuaJIT-2.0.5/src/host/README
new file mode 100644
index 0000000..abfcdaa
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/host/README
@@ -0,0 +1,4 @@
+The files in this directory are only used during the build process of LuaJIT.
+For cross-compilation, they must be executed on the host, not on the target.
+
+These files should NOT be installed!
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/host/buildvm.c b/src/3rdparty/LuaJIT-2.0.5/src/host/buildvm.c
new file mode 100644
index 0000000..b9560f3
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/host/buildvm.c
@@ -0,0 +1,516 @@
+/*
+** LuaJIT VM builder.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** This is a tool to build the hand-tuned assembler code required for
+** LuaJIT's bytecode interpreter. It supports a variety of output formats
+** to feed different toolchains (see usage() below).
+**
+** This tool is not particularly optimized because it's only used while
+** _building_ LuaJIT. There's no point in distributing or installing it.
+** Only the object code generated by this tool is linked into LuaJIT.
+**
+** Caveat: some memory is not free'd, error handling is lazy.
+** It's a one-shot tool -- any effort fixing this would be wasted.
+*/
+
+#include "buildvm.h"
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_bc.h"
+#include "lj_ir.h"
+#include "lj_ircall.h"
+#include "lj_frame.h"
+#include "lj_dispatch.h"
+#if LJ_HASFFI
+#include "lj_ctype.h"
+#include "lj_ccall.h"
+#endif
+#include "luajit.h"
+
+#if defined(_WIN32)
+#include <fcntl.h>
+#include <io.h>
+#endif
+
+/* ------------------------------------------------------------------------ */
+
+/* DynASM glue definitions. */
+#define Dst ctx
+#define Dst_DECL BuildCtx *ctx
+#define Dst_REF (ctx->D)
+#define DASM_CHECKS 1
+
+#include "../dynasm/dasm_proto.h"
+
+/* Glue macros for DynASM. */
+static int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type);
+
+#define DASM_EXTERN(ctx, addr, idx, type) \
+ collect_reloc(ctx, addr, idx, type)
+
+/* ------------------------------------------------------------------------ */
+
+/* Avoid trouble if cross-compiling for an x86 target. Speed doesn't matter. */
+#define DASM_ALIGNED_WRITES 1
+
+/* Embed architecture-specific DynASM encoder. */
+#if LJ_TARGET_X86ORX64
+#include "../dynasm/dasm_x86.h"
+#elif LJ_TARGET_ARM
+#include "../dynasm/dasm_arm.h"
+#elif LJ_TARGET_PPC
+#include "../dynasm/dasm_ppc.h"
+#elif LJ_TARGET_PPCSPE
+#include "../dynasm/dasm_ppc.h"
+#elif LJ_TARGET_MIPS
+#include "../dynasm/dasm_mips.h"
+#else
+#error "No support for this architecture (yet)"
+#endif
+
+/* Embed generated architecture-specific backend. */
+#include "buildvm_arch.h"
+
+/* ------------------------------------------------------------------------ */
+
+void owrite(BuildCtx *ctx, const void *ptr, size_t sz)
+{
+ if (fwrite(ptr, 1, sz, ctx->fp) != sz) {
+ fprintf(stderr, "Error: cannot write to output file: %s\n",
+ strerror(errno));
+ exit(1);
+ }
+}
+
+/* ------------------------------------------------------------------------ */
+
+/* Emit code as raw bytes. Only used for DynASM debugging. */
+static void emit_raw(BuildCtx *ctx)
+{
+ owrite(ctx, ctx->code, ctx->codesz);
+}
+
+/* -- Build machine code -------------------------------------------------- */
+
+static const char *sym_decorate(BuildCtx *ctx,
+ const char *prefix, const char *suffix)
+{
+ char name[256];
+ char *p;
+#if LJ_64
+ const char *symprefix = ctx->mode == BUILD_machasm ? "_" : "";
+#elif LJ_TARGET_XBOX360
+ const char *symprefix = "";
+#else
+ const char *symprefix = ctx->mode != BUILD_elfasm ? "_" : "";
+#endif
+ sprintf(name, "%s%s%s", symprefix, prefix, suffix);
+ p = strchr(name, '@');
+ if (p) {
+#if LJ_TARGET_X86ORX64
+ if (!LJ_64 && (ctx->mode == BUILD_coffasm || ctx->mode == BUILD_peobj))
+ name[0] = '@';
+ else
+ *p = '\0';
+#elif (LJ_TARGET_PPC || LJ_TARGET_PPCSPE) && !LJ_TARGET_CONSOLE
+ /* Keep @plt. */
+#else
+ *p = '\0';
+#endif
+ }
+ p = (char *)malloc(strlen(name)+1); /* MSVC doesn't like strdup. */
+ strcpy(p, name);
+ return p;
+}
+
+#define NRELOCSYM (sizeof(extnames)/sizeof(extnames[0])-1)
+
+static int relocmap[NRELOCSYM];
+
+/* Collect external relocations. */
+static int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type)
+{
+ if (ctx->nreloc >= BUILD_MAX_RELOC) {
+ fprintf(stderr, "Error: too many relocations, increase BUILD_MAX_RELOC.\n");
+ exit(1);
+ }
+ if (relocmap[idx] < 0) {
+ relocmap[idx] = ctx->nrelocsym;
+ ctx->relocsym[ctx->nrelocsym] = sym_decorate(ctx, "", extnames[idx]);
+ ctx->nrelocsym++;
+ }
+ ctx->reloc[ctx->nreloc].ofs = (int32_t)(addr - ctx->code);
+ ctx->reloc[ctx->nreloc].sym = relocmap[idx];
+ ctx->reloc[ctx->nreloc].type = type;
+ ctx->nreloc++;
+#if LJ_TARGET_XBOX360
+ return (int)(ctx->code - addr) + 4; /* Encode symbol offset of .text. */
+#else
+ return 0; /* Encode symbol offset of 0. */
+#endif
+}
+
+/* Naive insertion sort. Performance doesn't matter here. */
+static void sym_insert(BuildCtx *ctx, int32_t ofs,
+ const char *prefix, const char *suffix)
+{
+ ptrdiff_t i = ctx->nsym++;
+ while (i > 0) {
+ if (ctx->sym[i-1].ofs <= ofs)
+ break;
+ ctx->sym[i] = ctx->sym[i-1];
+ i--;
+ }
+ ctx->sym[i].ofs = ofs;
+ ctx->sym[i].name = sym_decorate(ctx, prefix, suffix);
+}
+
+/* Build the machine code. */
+static int build_code(BuildCtx *ctx)
+{
+ int status;
+ int i;
+
+ /* Initialize DynASM structures. */
+ ctx->nglob = GLOB__MAX;
+ ctx->glob = (void **)malloc(ctx->nglob*sizeof(void *));
+ memset(ctx->glob, 0, ctx->nglob*sizeof(void *));
+ ctx->nreloc = 0;
+
+ ctx->globnames = globnames;
+ ctx->relocsym = (const char **)malloc(NRELOCSYM*sizeof(const char *));
+ ctx->nrelocsym = 0;
+ for (i = 0; i < (int)NRELOCSYM; i++) relocmap[i] = -1;
+
+ ctx->dasm_ident = DASM_IDENT;
+ ctx->dasm_arch = DASM_ARCH;
+
+ dasm_init(Dst, DASM_MAXSECTION);
+ dasm_setupglobal(Dst, ctx->glob, ctx->nglob);
+ dasm_setup(Dst, build_actionlist);
+
+ /* Call arch-specific backend to emit the code. */
+ ctx->npc = build_backend(ctx);
+
+ /* Finalize the code. */
+ (void)dasm_checkstep(Dst, -1);
+ if ((status = dasm_link(Dst, &ctx->codesz))) return status;
+ ctx->code = (uint8_t *)malloc(ctx->codesz);
+ if ((status = dasm_encode(Dst, (void *)ctx->code))) return status;
+
+ /* Allocate symbol table and bytecode offsets. */
+ ctx->beginsym = sym_decorate(ctx, "", LABEL_PREFIX "vm_asm_begin");
+ ctx->sym = (BuildSym *)malloc((ctx->npc+ctx->nglob+1)*sizeof(BuildSym));
+ ctx->nsym = 0;
+ ctx->bc_ofs = (int32_t *)malloc(ctx->npc*sizeof(int32_t));
+
+ /* Collect the opcodes (PC labels). */
+ for (i = 0; i < ctx->npc; i++) {
+ int32_t ofs = dasm_getpclabel(Dst, i);
+ if (ofs < 0) return 0x22000000|i;
+ ctx->bc_ofs[i] = ofs;
+ if ((LJ_HASJIT ||
+ !(i == BC_JFORI || i == BC_JFORL || i == BC_JITERL || i == BC_JLOOP ||
+ i == BC_IFORL || i == BC_IITERL || i == BC_ILOOP)) &&
+ (LJ_HASFFI || i != BC_KCDATA))
+ sym_insert(ctx, ofs, LABEL_PREFIX_BC, bc_names[i]);
+ }
+
+ /* Collect the globals (named labels). */
+ for (i = 0; i < ctx->nglob; i++) {
+ const char *gl = globnames[i];
+ int len = (int)strlen(gl);
+ if (!ctx->glob[i]) {
+ fprintf(stderr, "Error: undefined global %s\n", gl);
+ exit(2);
+ }
+ /* Skip the _Z symbols. */
+ if (!(len >= 2 && gl[len-2] == '_' && gl[len-1] == 'Z'))
+ sym_insert(ctx, (int32_t)((uint8_t *)(ctx->glob[i]) - ctx->code),
+ LABEL_PREFIX, globnames[i]);
+ }
+
+ /* Close the address range. */
+ sym_insert(ctx, (int32_t)ctx->codesz, "", "");
+ ctx->nsym--;
+
+ dasm_free(Dst);
+
+ return 0;
+}
+
+/* -- Generate VM enums --------------------------------------------------- */
+
+const char *const bc_names[] = {
+#define BCNAME(name, ma, mb, mc, mt) #name,
+BCDEF(BCNAME)
+#undef BCNAME
+ NULL
+};
+
+const char *const ir_names[] = {
+#define IRNAME(name, m, m1, m2) #name,
+IRDEF(IRNAME)
+#undef IRNAME
+ NULL
+};
+
+const char *const irt_names[] = {
+#define IRTNAME(name, size) #name,
+IRTDEF(IRTNAME)
+#undef IRTNAME
+ NULL
+};
+
+const char *const irfpm_names[] = {
+#define FPMNAME(name) #name,
+IRFPMDEF(FPMNAME)
+#undef FPMNAME
+ NULL
+};
+
+const char *const irfield_names[] = {
+#define FLNAME(name, ofs) #name,
+IRFLDEF(FLNAME)
+#undef FLNAME
+ NULL
+};
+
+const char *const ircall_names[] = {
+#define IRCALLNAME(cond, name, nargs, kind, type, flags) #name,
+IRCALLDEF(IRCALLNAME)
+#undef IRCALLNAME
+ NULL
+};
+
+static const char *const trace_errors[] = {
+#define TREDEF(name, msg) msg,
+#include "lj_traceerr.h"
+ NULL
+};
+
+static const char *lower(char *buf, const char *s)
+{
+ char *p = buf;
+ while (*s) {
+ *p++ = (*s >= 'A' && *s <= 'Z') ? *s+0x20 : *s;
+ s++;
+ }
+ *p = '\0';
+ return buf;
+}
+
+/* Emit C source code for bytecode-related definitions. */
+static void emit_bcdef(BuildCtx *ctx)
+{
+ int i;
+ fprintf(ctx->fp, "/* This is a generated file. DO NOT EDIT! */\n\n");
+ fprintf(ctx->fp, "LJ_DATADEF const uint16_t lj_bc_ofs[] = {\n");
+ for (i = 0; i < ctx->npc; i++) {
+ if (i != 0)
+ fprintf(ctx->fp, ",\n");
+ fprintf(ctx->fp, "%d", ctx->bc_ofs[i]);
+ }
+}
+
+/* Emit VM definitions as Lua code for debug modules. */
+static void emit_vmdef(BuildCtx *ctx)
+{
+ char buf[80];
+ int i;
+ fprintf(ctx->fp, "-- This is a generated file. DO NOT EDIT!\n\n");
+ fprintf(ctx->fp, "module(...)\n\n");
+
+ fprintf(ctx->fp, "bcnames = \"");
+ for (i = 0; bc_names[i]; i++) fprintf(ctx->fp, "%-6s", bc_names[i]);
+ fprintf(ctx->fp, "\"\n\n");
+
+ fprintf(ctx->fp, "irnames = \"");
+ for (i = 0; ir_names[i]; i++) fprintf(ctx->fp, "%-6s", ir_names[i]);
+ fprintf(ctx->fp, "\"\n\n");
+
+ fprintf(ctx->fp, "irfpm = { [0]=");
+ for (i = 0; irfpm_names[i]; i++)
+ fprintf(ctx->fp, "\"%s\", ", lower(buf, irfpm_names[i]));
+ fprintf(ctx->fp, "}\n\n");
+
+ fprintf(ctx->fp, "irfield = { [0]=");
+ for (i = 0; irfield_names[i]; i++) {
+ char *p;
+ lower(buf, irfield_names[i]);
+ p = strchr(buf, '_');
+ if (p) *p = '.';
+ fprintf(ctx->fp, "\"%s\", ", buf);
+ }
+ fprintf(ctx->fp, "}\n\n");
+
+ fprintf(ctx->fp, "ircall = {\n[0]=");
+ for (i = 0; ircall_names[i]; i++)
+ fprintf(ctx->fp, "\"%s\",\n", ircall_names[i]);
+ fprintf(ctx->fp, "}\n\n");
+
+ fprintf(ctx->fp, "traceerr = {\n[0]=");
+ for (i = 0; trace_errors[i]; i++)
+ fprintf(ctx->fp, "\"%s\",\n", trace_errors[i]);
+ fprintf(ctx->fp, "}\n\n");
+}
+
+/* -- Argument parsing ---------------------------------------------------- */
+
+/* Build mode names. */
+static const char *const modenames[] = {
+#define BUILDNAME(name) #name,
+BUILDDEF(BUILDNAME)
+#undef BUILDNAME
+ NULL
+};
+
+/* Print usage information and exit. */
+static void usage(void)
+{
+ int i;
+ fprintf(stderr, LUAJIT_VERSION " VM builder.\n");
+ fprintf(stderr, LUAJIT_COPYRIGHT ", " LUAJIT_URL "\n");
+ fprintf(stderr, "Target architecture: " LJ_ARCH_NAME "\n\n");
+ fprintf(stderr, "Usage: buildvm -m mode [-o outfile] [infiles...]\n\n");
+ fprintf(stderr, "Available modes:\n");
+ for (i = 0; i < BUILD__MAX; i++)
+ fprintf(stderr, " %s\n", modenames[i]);
+ exit(1);
+}
+
+/* Parse the output mode name. */
+static BuildMode parsemode(const char *mode)
+{
+ int i;
+ for (i = 0; modenames[i]; i++)
+ if (!strcmp(mode, modenames[i]))
+ return (BuildMode)i;
+ usage();
+ return (BuildMode)-1;
+}
+
+/* Parse arguments. */
+static void parseargs(BuildCtx *ctx, char **argv)
+{
+ const char *a;
+ int i;
+ ctx->mode = (BuildMode)-1;
+ ctx->outname = "-";
+ for (i = 1; (a = argv[i]) != NULL; i++) {
+ if (a[0] != '-')
+ break;
+ switch (a[1]) {
+ case '-':
+ if (a[2]) goto err;
+ i++;
+ goto ok;
+ case '\0':
+ goto ok;
+ case 'm':
+ i++;
+ if (a[2] || argv[i] == NULL) goto err;
+ ctx->mode = parsemode(argv[i]);
+ break;
+ case 'o':
+ i++;
+ if (a[2] || argv[i] == NULL) goto err;
+ ctx->outname = argv[i];
+ break;
+ default: err:
+ usage();
+ break;
+ }
+ }
+ok:
+ ctx->args = argv+i;
+ if (ctx->mode == (BuildMode)-1) goto err;
+}
+
+int main(int argc, char **argv)
+{
+ BuildCtx ctx_;
+ BuildCtx *ctx = &ctx_;
+ int status, binmode;
+
+ if (sizeof(void *) != 4*LJ_32+8*LJ_64) {
+ fprintf(stderr,"Error: pointer size mismatch in cross-build.\n");
+ fprintf(stderr,"Try: make HOST_CC=\"gcc -m32\" CROSS=...\n\n");
+ return 1;
+ }
+
+ UNUSED(argc);
+ parseargs(ctx, argv);
+
+ if ((status = build_code(ctx))) {
+ fprintf(stderr,"Error: DASM error %08x\n", status);
+ return 1;
+ }
+
+ switch (ctx->mode) {
+ case BUILD_peobj:
+ case BUILD_raw:
+ binmode = 1;
+ break;
+ default:
+ binmode = 0;
+ break;
+ }
+
+ if (ctx->outname[0] == '-' && ctx->outname[1] == '\0') {
+ ctx->fp = stdout;
+#if defined(_WIN32)
+ if (binmode)
+ _setmode(_fileno(stdout), _O_BINARY); /* Yuck. */
+#endif
+ } else if (!(ctx->fp = fopen(ctx->outname, binmode ? "wb" : "w"))) {
+ fprintf(stderr, "Error: cannot open output file '%s': %s\n",
+ ctx->outname, strerror(errno));
+ exit(1);
+ }
+
+ switch (ctx->mode) {
+ case BUILD_elfasm:
+ case BUILD_coffasm:
+ case BUILD_machasm:
+ emit_asm(ctx);
+ emit_asm_debug(ctx);
+ break;
+ case BUILD_peobj:
+ emit_peobj(ctx);
+ break;
+ case BUILD_raw:
+ emit_raw(ctx);
+ break;
+ case BUILD_bcdef:
+ emit_bcdef(ctx);
+ emit_lib(ctx);
+ break;
+ case BUILD_vmdef:
+ emit_vmdef(ctx);
+ emit_lib(ctx);
+ break;
+ case BUILD_ffdef:
+ case BUILD_libdef:
+ case BUILD_recdef:
+ emit_lib(ctx);
+ break;
+ case BUILD_folddef:
+ emit_fold(ctx);
+ break;
+ default:
+ break;
+ }
+
+ fflush(ctx->fp);
+ if (ferror(ctx->fp)) {
+ fprintf(stderr, "Error: cannot write to output file: %s\n",
+ strerror(errno));
+ exit(1);
+ }
+ fclose(ctx->fp);
+
+ return 0;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/host/buildvm.h b/src/3rdparty/LuaJIT-2.0.5/src/host/buildvm.h
new file mode 100644
index 0000000..e6dd3dc
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/host/buildvm.h
@@ -0,0 +1,104 @@
+/*
+** LuaJIT VM builder.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _BUILDVM_H
+#define _BUILDVM_H
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "lj_def.h"
+#include "lj_arch.h"
+
+/* Hardcoded limits. Increase as needed. */
+#define BUILD_MAX_RELOC 200 /* Max. number of relocations. */
+#define BUILD_MAX_FOLD 4096 /* Max. number of fold rules. */
+
+/* Prefix for scanned library definitions. */
+#define LIBDEF_PREFIX "LJLIB_"
+
+/* Prefix for scanned fold definitions. */
+#define FOLDDEF_PREFIX "LJFOLD"
+
+/* Prefixes for generated labels. */
+#define LABEL_PREFIX "lj_"
+#define LABEL_PREFIX_BC LABEL_PREFIX "BC_"
+#define LABEL_PREFIX_FF LABEL_PREFIX "ff_"
+#define LABEL_PREFIX_CF LABEL_PREFIX "cf_"
+#define LABEL_PREFIX_FFH LABEL_PREFIX "ffh_"
+#define LABEL_PREFIX_LIBCF LABEL_PREFIX "lib_cf_"
+#define LABEL_PREFIX_LIBINIT LABEL_PREFIX "lib_init_"
+
+/* Forward declaration. */
+struct dasm_State;
+
+/* Build modes. */
+#define BUILDDEF(_) \
+ _(elfasm) _(coffasm) _(machasm) _(peobj) _(raw) \
+ _(bcdef) _(ffdef) _(libdef) _(recdef) _(vmdef) \
+ _(folddef)
+
+typedef enum {
+#define BUILDENUM(name) BUILD_##name,
+BUILDDEF(BUILDENUM)
+#undef BUILDENUM
+ BUILD__MAX
+} BuildMode;
+
+/* Code relocation. */
+typedef struct BuildReloc {
+ int32_t ofs;
+ int sym;
+ int type;
+} BuildReloc;
+
+typedef struct BuildSym {
+ const char *name;
+ int32_t ofs;
+} BuildSym;
+
+/* Build context structure. */
+typedef struct BuildCtx {
+ /* DynASM state pointer. Should be first member. */
+ struct dasm_State *D;
+ /* Parsed command line. */
+ BuildMode mode;
+ FILE *fp;
+ const char *outname;
+ char **args;
+ /* Code and symbols generated by DynASM. */
+ uint8_t *code;
+ size_t codesz;
+ int npc, nglob, nsym, nreloc, nrelocsym;
+ void **glob;
+ BuildSym *sym;
+ const char **relocsym;
+ int32_t *bc_ofs;
+ const char *beginsym;
+ /* Strings generated by DynASM. */
+ const char *const *globnames;
+ const char *dasm_ident;
+ const char *dasm_arch;
+ /* Relocations. */
+ BuildReloc reloc[BUILD_MAX_RELOC];
+} BuildCtx;
+
+extern void owrite(BuildCtx *ctx, const void *ptr, size_t sz);
+extern void emit_asm(BuildCtx *ctx);
+extern void emit_peobj(BuildCtx *ctx);
+extern void emit_lib(BuildCtx *ctx);
+extern void emit_fold(BuildCtx *ctx);
+
+extern const char *const bc_names[];
+extern const char *const ir_names[];
+extern const char *const irt_names[];
+extern const char *const irfpm_names[];
+extern const char *const irfield_names[];
+extern const char *const ircall_names[];
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/host/buildvm_asm.c b/src/3rdparty/LuaJIT-2.0.5/src/host/buildvm_asm.c
new file mode 100644
index 0000000..81a3969
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/host/buildvm_asm.c
@@ -0,0 +1,314 @@
+/*
+** LuaJIT VM builder: Assembler source code emitter.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#include "buildvm.h"
+#include "lj_bc.h"
+
+/* ------------------------------------------------------------------------ */
+
+#if LJ_TARGET_X86ORX64
+/* Emit bytes piecewise as assembler text. */
+static void emit_asm_bytes(BuildCtx *ctx, uint8_t *p, int n)
+{
+ int i;
+ for (i = 0; i < n; i++) {
+ if ((i & 15) == 0)
+ fprintf(ctx->fp, "\t.byte %d", p[i]);
+ else
+ fprintf(ctx->fp, ",%d", p[i]);
+ if ((i & 15) == 15) putc('\n', ctx->fp);
+ }
+ if ((n & 15) != 0) putc('\n', ctx->fp);
+}
+
+/* Emit relocation */
+static void emit_asm_reloc(BuildCtx *ctx, int type, const char *sym)
+{
+ switch (ctx->mode) {
+ case BUILD_elfasm:
+ if (type)
+ fprintf(ctx->fp, "\t.long %s-.-4\n", sym);
+ else
+ fprintf(ctx->fp, "\t.long %s\n", sym);
+ break;
+ case BUILD_coffasm:
+ fprintf(ctx->fp, "\t.def %s; .scl 3; .type 32; .endef\n", sym);
+ if (type)
+ fprintf(ctx->fp, "\t.long %s-.-4\n", sym);
+ else
+ fprintf(ctx->fp, "\t.long %s\n", sym);
+ break;
+ default: /* BUILD_machasm for relative relocations handled below. */
+ fprintf(ctx->fp, "\t.long %s\n", sym);
+ break;
+ }
+}
+
+static const char *const jccnames[] = {
+ "jo", "jno", "jb", "jnb", "jz", "jnz", "jbe", "ja",
+ "js", "jns", "jpe", "jpo", "jl", "jge", "jle", "jg"
+};
+
+/* Emit relocation for the incredibly stupid OSX assembler. */
+static void emit_asm_reloc_mach(BuildCtx *ctx, uint8_t *cp, int n,
+ const char *sym)
+{
+ const char *opname = NULL;
+ if (--n < 0) goto err;
+ if (cp[n] == 0xe8) {
+ opname = "call";
+ } else if (cp[n] == 0xe9) {
+ opname = "jmp";
+ } else if (cp[n] >= 0x80 && cp[n] <= 0x8f && n > 0 && cp[n-1] == 0x0f) {
+ opname = jccnames[cp[n]-0x80];
+ n--;
+ } else {
+err:
+ fprintf(stderr, "Error: unsupported opcode for %s symbol relocation.\n",
+ sym);
+ exit(1);
+ }
+ emit_asm_bytes(ctx, cp, n);
+ fprintf(ctx->fp, "\t%s %s\n", opname, sym);
+}
+#else
+/* Emit words piecewise as assembler text. */
+static void emit_asm_words(BuildCtx *ctx, uint8_t *p, int n)
+{
+ int i;
+ for (i = 0; i < n; i += 4) {
+ if ((i & 15) == 0)
+ fprintf(ctx->fp, "\t.long 0x%08x", *(uint32_t *)(p+i));
+ else
+ fprintf(ctx->fp, ",0x%08x", *(uint32_t *)(p+i));
+ if ((i & 15) == 12) putc('\n', ctx->fp);
+ }
+ if ((n & 15) != 0) putc('\n', ctx->fp);
+}
+
+/* Emit relocation as part of an instruction. */
+static void emit_asm_wordreloc(BuildCtx *ctx, uint8_t *p, int n,
+ const char *sym)
+{
+ uint32_t ins;
+ emit_asm_words(ctx, p, n-4);
+ ins = *(uint32_t *)(p+n-4);
+#if LJ_TARGET_ARM
+ if ((ins & 0xff000000u) == 0xfa000000u) {
+ fprintf(ctx->fp, "\tblx %s\n", sym);
+ } else if ((ins & 0x0e000000u) == 0x0a000000u) {
+ fprintf(ctx->fp, "\t%s%.2s %s\n", (ins & 0x01000000u) ? "bl" : "b",
+ &"eqnecsccmiplvsvchilsgeltgtle"[2*(ins >> 28)], sym);
+ } else {
+ fprintf(stderr,
+ "Error: unsupported opcode %08x for %s symbol relocation.\n",
+ ins, sym);
+ exit(1);
+ }
+#elif LJ_TARGET_PPC || LJ_TARGET_PPCSPE
+#if LJ_TARGET_PS3
+#define TOCPREFIX "."
+#else
+#define TOCPREFIX ""
+#endif
+ if ((ins >> 26) == 16) {
+ fprintf(ctx->fp, "\t%s %d, %d, " TOCPREFIX "%s\n",
+ (ins & 1) ? "bcl" : "bc", (ins >> 21) & 31, (ins >> 16) & 31, sym);
+ } else if ((ins >> 26) == 18) {
+ fprintf(ctx->fp, "\t%s " TOCPREFIX "%s\n", (ins & 1) ? "bl" : "b", sym);
+ } else {
+ fprintf(stderr,
+ "Error: unsupported opcode %08x for %s symbol relocation.\n",
+ ins, sym);
+ exit(1);
+ }
+#elif LJ_TARGET_MIPS
+ fprintf(stderr,
+ "Error: unsupported opcode %08x for %s symbol relocation.\n",
+ ins, sym);
+ exit(1);
+#else
+#error "missing relocation support for this architecture"
+#endif
+}
+#endif
+
+#if LJ_TARGET_ARM
+#define ELFASM_PX "%%"
+#else
+#define ELFASM_PX "@"
+#endif
+
+/* Emit an assembler label. */
+static void emit_asm_label(BuildCtx *ctx, const char *name, int size, int isfunc)
+{
+ switch (ctx->mode) {
+ case BUILD_elfasm:
+#if LJ_TARGET_PS3
+ if (!strncmp(name, "lj_vm_", 6) &&
+ strcmp(name, ctx->beginsym) &&
+ !strstr(name, "hook")) {
+ fprintf(ctx->fp,
+ "\n\t.globl %s\n"
+ "\t.section \".opd\",\"aw\"\n"
+ "%s:\n"
+ "\t.long .%s,.TOC.@tocbase32\n"
+ "\t.size %s,8\n"
+ "\t.previous\n"
+ "\t.globl .%s\n"
+ "\t.hidden .%s\n"
+ "\t.type .%s, " ELFASM_PX "function\n"
+ "\t.size .%s, %d\n"
+ ".%s:\n",
+ name, name, name, name, name, name, name, name, size, name);
+ break;
+ }
+#endif
+ fprintf(ctx->fp,
+ "\n\t.globl %s\n"
+ "\t.hidden %s\n"
+ "\t.type %s, " ELFASM_PX "%s\n"
+ "\t.size %s, %d\n"
+ "%s:\n",
+ name, name, name, isfunc ? "function" : "object", name, size, name);
+ break;
+ case BUILD_coffasm:
+ fprintf(ctx->fp, "\n\t.globl %s\n", name);
+ if (isfunc)
+ fprintf(ctx->fp, "\t.def %s; .scl 3; .type 32; .endef\n", name);
+ fprintf(ctx->fp, "%s:\n", name);
+ break;
+ case BUILD_machasm:
+ fprintf(ctx->fp,
+ "\n\t.private_extern %s\n"
+ "\t.no_dead_strip %s\n"
+ "%s:\n", name, name, name);
+ break;
+ default:
+ break;
+ }
+}
+
+/* Emit alignment. */
+static void emit_asm_align(BuildCtx *ctx, int bits)
+{
+ switch (ctx->mode) {
+ case BUILD_elfasm:
+ case BUILD_coffasm:
+ fprintf(ctx->fp, "\t.p2align %d\n", bits);
+ break;
+ case BUILD_machasm:
+ fprintf(ctx->fp, "\t.align %d\n", bits);
+ break;
+ default:
+ break;
+ }
+}
+
+/* ------------------------------------------------------------------------ */
+
+/* Emit assembler source code. */
+void emit_asm(BuildCtx *ctx)
+{
+ int i, rel;
+
+ fprintf(ctx->fp, "\t.file \"buildvm_%s.dasc\"\n", ctx->dasm_arch);
+ fprintf(ctx->fp, "\t.text\n");
+ emit_asm_align(ctx, 4);
+
+#if LJ_TARGET_PS3
+ emit_asm_label(ctx, ctx->beginsym, ctx->codesz, 0);
+#else
+ emit_asm_label(ctx, ctx->beginsym, 0, 0);
+#endif
+ if (ctx->mode != BUILD_machasm)
+ fprintf(ctx->fp, ".Lbegin:\n");
+
+#if LJ_TARGET_ARM && defined(__GNUC__) && !LJ_NO_UNWIND
+ /* This should really be moved into buildvm_arm.dasc. */
+ fprintf(ctx->fp,
+ ".fnstart\n"
+ ".save {r4, r5, r6, r7, r8, r9, r10, r11, lr}\n"
+ ".pad #28\n");
+#endif
+#if LJ_TARGET_MIPS
+ fprintf(ctx->fp, ".set nomips16\n.abicalls\n.set noreorder\n.set nomacro\n");
+#endif
+
+ for (i = rel = 0; i < ctx->nsym; i++) {
+ int32_t ofs = ctx->sym[i].ofs;
+ int32_t next = ctx->sym[i+1].ofs;
+#if LJ_TARGET_ARM && defined(__GNUC__) && !LJ_NO_UNWIND && LJ_HASFFI
+ if (!strcmp(ctx->sym[i].name, "lj_vm_ffi_call"))
+ fprintf(ctx->fp,
+ ".globl lj_err_unwind_arm\n"
+ ".personality lj_err_unwind_arm\n"
+ ".fnend\n"
+ ".fnstart\n"
+ ".save {r4, r5, r11, lr}\n"
+ ".setfp r11, sp\n");
+#endif
+ emit_asm_label(ctx, ctx->sym[i].name, next - ofs, 1);
+ while (rel < ctx->nreloc && ctx->reloc[rel].ofs <= next) {
+ BuildReloc *r = &ctx->reloc[rel];
+ int n = r->ofs - ofs;
+#if LJ_TARGET_X86ORX64
+ if (ctx->mode == BUILD_machasm && r->type != 0) {
+ emit_asm_reloc_mach(ctx, ctx->code+ofs, n, ctx->relocsym[r->sym]);
+ } else {
+ emit_asm_bytes(ctx, ctx->code+ofs, n);
+ emit_asm_reloc(ctx, r->type, ctx->relocsym[r->sym]);
+ }
+ ofs += n+4;
+#else
+ emit_asm_wordreloc(ctx, ctx->code+ofs, n, ctx->relocsym[r->sym]);
+ ofs += n;
+#endif
+ rel++;
+ }
+#if LJ_TARGET_X86ORX64
+ emit_asm_bytes(ctx, ctx->code+ofs, next-ofs);
+#else
+ emit_asm_words(ctx, ctx->code+ofs, next-ofs);
+#endif
+ }
+
+#if LJ_TARGET_ARM && defined(__GNUC__) && !LJ_NO_UNWIND
+ fprintf(ctx->fp,
+#if !LJ_HASFFI
+ ".globl lj_err_unwind_arm\n"
+ ".personality lj_err_unwind_arm\n"
+#endif
+ ".fnend\n");
+#endif
+
+ fprintf(ctx->fp, "\n");
+ switch (ctx->mode) {
+ case BUILD_elfasm:
+#if !(LJ_TARGET_PS3 || LJ_TARGET_PSVITA)
+ fprintf(ctx->fp, "\t.section .note.GNU-stack,\"\"," ELFASM_PX "progbits\n");
+#endif
+#if LJ_TARGET_PPCSPE
+ /* Soft-float ABI + SPE. */
+ fprintf(ctx->fp, "\t.gnu_attribute 4, 2\n\t.gnu_attribute 8, 3\n");
+#elif LJ_TARGET_PPC && !LJ_TARGET_PS3
+ /* Hard-float ABI. */
+ fprintf(ctx->fp, "\t.gnu_attribute 4, 1\n");
+#endif
+ /* fallthrough */
+ case BUILD_coffasm:
+ fprintf(ctx->fp, "\t.ident \"%s\"\n", ctx->dasm_ident);
+ break;
+ case BUILD_machasm:
+ fprintf(ctx->fp,
+ "\t.cstring\n"
+ "\t.ascii \"%s\\0\"\n", ctx->dasm_ident);
+ break;
+ default:
+ break;
+ }
+ fprintf(ctx->fp, "\n");
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/host/buildvm_fold.c b/src/3rdparty/LuaJIT-2.0.5/src/host/buildvm_fold.c
new file mode 100644
index 0000000..d579f4d
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/host/buildvm_fold.c
@@ -0,0 +1,229 @@
+/*
+** LuaJIT VM builder: IR folding hash table generator.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#include "buildvm.h"
+#include "lj_obj.h"
+#include "lj_ir.h"
+
+/* Context for the folding hash table generator. */
+static int lineno;
+static uint32_t funcidx;
+static uint32_t foldkeys[BUILD_MAX_FOLD];
+static uint32_t nkeys;
+
+/* Try to fill the hash table with keys using the hash parameters. */
+static int tryhash(uint32_t *htab, uint32_t sz, uint32_t r, int dorol)
+{
+ uint32_t i;
+ if (dorol && ((r & 31) == 0 || (r>>5) == 0))
+ return 0; /* Avoid zero rotates. */
+ memset(htab, 0xff, (sz+1)*sizeof(uint32_t));
+ for (i = 0; i < nkeys; i++) {
+ uint32_t key = foldkeys[i];
+ uint32_t k = key & 0xffffff;
+ uint32_t h = (dorol ? lj_rol(lj_rol(k, r>>5) - k, r&31) :
+ (((k << (r>>5)) - k) << (r&31))) % sz;
+ if (htab[h] != 0xffffffff) { /* Collision on primary slot. */
+ if (htab[h+1] != 0xffffffff) { /* Collision on secondary slot. */
+ /* Try to move the colliding key, if possible. */
+ if (h < sz-1 && htab[h+2] == 0xffffffff) {
+ uint32_t k2 = htab[h+1] & 0xffffff;
+ uint32_t h2 = (dorol ? lj_rol(lj_rol(k2, r>>5) - k2, r&31) :
+ (((k2 << (r>>5)) - k2) << (r&31))) % sz;
+ if (h2 != h+1) return 0; /* Cannot resolve collision. */
+ htab[h+2] = htab[h+1]; /* Move colliding key to secondary slot. */
+ } else {
+ return 0; /* Collision. */
+ }
+ }
+ htab[h+1] = key;
+ } else {
+ htab[h] = key;
+ }
+ }
+ return 1; /* Success, all keys could be stored. */
+}
+
+/* Print the generated hash table. */
+static void printhash(BuildCtx *ctx, uint32_t *htab, uint32_t sz)
+{
+ uint32_t i;
+ fprintf(ctx->fp, "static const uint32_t fold_hash[%d] = {\n0x%08x",
+ sz+1, htab[0]);
+ for (i = 1; i < sz+1; i++)
+ fprintf(ctx->fp, ",\n0x%08x", htab[i]);
+ fprintf(ctx->fp, "\n};\n\n");
+}
+
+/* Exhaustive search for the shortest semi-perfect hash table. */
+static void makehash(BuildCtx *ctx)
+{
+ uint32_t htab[BUILD_MAX_FOLD*2+1];
+ uint32_t sz, r;
+ /* Search for the smallest hash table with an odd size. */
+ for (sz = (nkeys|1); sz < BUILD_MAX_FOLD*2; sz += 2) {
+ /* First try all shift hash combinations. */
+ for (r = 0; r < 32*32; r++) {
+ if (tryhash(htab, sz, r, 0)) {
+ printhash(ctx, htab, sz);
+ fprintf(ctx->fp,
+ "#define fold_hashkey(k)\t(((((k)<<%u)-(k))<<%u)%%%u)\n\n",
+ r>>5, r&31, sz);
+ return;
+ }
+ }
+ /* Then try all rotate hash combinations. */
+ for (r = 0; r < 32*32; r++) {
+ if (tryhash(htab, sz, r, 1)) {
+ printhash(ctx, htab, sz);
+ fprintf(ctx->fp,
+ "#define fold_hashkey(k)\t(lj_rol(lj_rol((k),%u)-(k),%u)%%%u)\n\n",
+ r>>5, r&31, sz);
+ return;
+ }
+ }
+ }
+ fprintf(stderr, "Error: search for perfect hash failed\n");
+ exit(1);
+}
+
+/* Parse one token of a fold rule. */
+static uint32_t nexttoken(char **pp, int allowlit, int allowany)
+{
+ char *p = *pp;
+ if (p) {
+ uint32_t i;
+ char *q = strchr(p, ' ');
+ if (q) *q++ = '\0';
+ *pp = q;
+ if (allowlit && !strncmp(p, "IRFPM_", 6)) {
+ for (i = 0; irfpm_names[i]; i++)
+ if (!strcmp(irfpm_names[i], p+6))
+ return i;
+ } else if (allowlit && !strncmp(p, "IRFL_", 5)) {
+ for (i = 0; irfield_names[i]; i++)
+ if (!strcmp(irfield_names[i], p+5))
+ return i;
+ } else if (allowlit && !strncmp(p, "IRCALL_", 7)) {
+ for (i = 0; ircall_names[i]; i++)
+ if (!strcmp(ircall_names[i], p+7))
+ return i;
+ } else if (allowlit && !strncmp(p, "IRCONV_", 7)) {
+ for (i = 0; irt_names[i]; i++) {
+ const char *r = strchr(p+7, '_');
+ if (r && !strncmp(irt_names[i], p+7, r-(p+7))) {
+ uint32_t j;
+ for (j = 0; irt_names[j]; j++)
+ if (!strcmp(irt_names[j], r+1))
+ return (i << 5) + j;
+ }
+ }
+ } else if (allowlit && *p >= '0' && *p <= '9') {
+ for (i = 0; *p >= '0' && *p <= '9'; p++)
+ i = i*10 + (*p - '0');
+ if (*p == '\0')
+ return i;
+ } else if (allowany && !strcmp("any", p)) {
+ return allowany;
+ } else {
+ for (i = 0; ir_names[i]; i++)
+ if (!strcmp(ir_names[i], p))
+ return i;
+ }
+ fprintf(stderr, "Error: bad fold definition token \"%s\" at line %d\n", p, lineno);
+ exit(1);
+ }
+ return 0;
+}
+
+/* Parse a fold rule. */
+static void foldrule(char *p)
+{
+ uint32_t op = nexttoken(&p, 0, 0);
+ uint32_t left = nexttoken(&p, 0, 0x7f);
+ uint32_t right = nexttoken(&p, 1, 0x3ff);
+ uint32_t key = (funcidx << 24) | (op << 17) | (left << 10) | right;
+ uint32_t i;
+ if (nkeys >= BUILD_MAX_FOLD) {
+ fprintf(stderr, "Error: too many fold rules, increase BUILD_MAX_FOLD.\n");
+ exit(1);
+ }
+ /* Simple insertion sort to detect duplicates. */
+ for (i = nkeys; i > 0; i--) {
+ if ((foldkeys[i-1]&0xffffff) < (key & 0xffffff))
+ break;
+ if ((foldkeys[i-1]&0xffffff) == (key & 0xffffff)) {
+ fprintf(stderr, "Error: duplicate fold definition at line %d\n", lineno);
+ exit(1);
+ }
+ foldkeys[i] = foldkeys[i-1];
+ }
+ foldkeys[i] = key;
+ nkeys++;
+}
+
+/* Emit C source code for IR folding hash table. */
+void emit_fold(BuildCtx *ctx)
+{
+ char buf[256]; /* We don't care about analyzing lines longer than that. */
+ const char *fname = ctx->args[0];
+ FILE *fp;
+
+ if (fname == NULL) {
+ fprintf(stderr, "Error: missing input filename\n");
+ exit(1);
+ }
+
+ if (fname[0] == '-' && fname[1] == '\0') {
+ fp = stdin;
+ } else {
+ fp = fopen(fname, "r");
+ if (!fp) {
+ fprintf(stderr, "Error: cannot open input file '%s': %s\n",
+ fname, strerror(errno));
+ exit(1);
+ }
+ }
+
+ fprintf(ctx->fp, "/* This is a generated file. DO NOT EDIT! */\n\n");
+ fprintf(ctx->fp, "static const FoldFunc fold_func[] = {\n");
+
+ lineno = 0;
+ funcidx = 0;
+ nkeys = 0;
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ lineno++;
+ /* The prefix must be at the start of a line, otherwise it's ignored. */
+ if (!strncmp(buf, FOLDDEF_PREFIX, sizeof(FOLDDEF_PREFIX)-1)) {
+ char *p = buf+sizeof(FOLDDEF_PREFIX)-1;
+ char *q = strchr(p, ')');
+ if (p[0] == '(' && q) {
+ p++;
+ *q = '\0';
+ foldrule(p);
+ } else if ((p[0] == 'F' || p[0] == 'X') && p[1] == '(' && q) {
+ p += 2;
+ *q = '\0';
+ if (funcidx)
+ fprintf(ctx->fp, ",\n");
+ if (p[-2] == 'X')
+ fprintf(ctx->fp, " %s", p);
+ else
+ fprintf(ctx->fp, " fold_%s", p);
+ funcidx++;
+ } else {
+ buf[strlen(buf)-1] = '\0';
+ fprintf(stderr, "Error: unknown fold definition tag %s%s at line %d\n",
+ FOLDDEF_PREFIX, p, lineno);
+ exit(1);
+ }
+ }
+ }
+ fclose(fp);
+ fprintf(ctx->fp, "\n};\n\n");
+
+ makehash(ctx);
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/host/buildvm_lib.c b/src/3rdparty/LuaJIT-2.0.5/src/host/buildvm_lib.c
new file mode 100644
index 0000000..569e2ca
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/host/buildvm_lib.c
@@ -0,0 +1,398 @@
+/*
+** LuaJIT VM builder: library definition compiler.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#include "buildvm.h"
+#include "lj_obj.h"
+#include "lj_lib.h"
+
+/* Context for library definitions. */
+static uint8_t obuf[8192];
+static uint8_t *optr;
+static char modname[80];
+static size_t modnamelen;
+static char funcname[80];
+static int modstate, regfunc;
+static int ffid, recffid, ffasmfunc;
+
+enum {
+ REGFUNC_OK,
+ REGFUNC_NOREG,
+ REGFUNC_NOREGUV
+};
+
+static void libdef_name(const char *p, int kind)
+{
+ size_t n = strlen(p);
+ if (kind != LIBINIT_STRING) {
+ if (n > modnamelen && p[modnamelen] == '_' &&
+ !strncmp(p, modname, modnamelen)) {
+ p += modnamelen+1;
+ n -= modnamelen+1;
+ }
+ }
+ if (n > LIBINIT_MAXSTR) {
+ fprintf(stderr, "Error: string too long: '%s'\n", p);
+ exit(1);
+ }
+ if (optr+1+n+2 > obuf+sizeof(obuf)) { /* +2 for caller. */
+ fprintf(stderr, "Error: output buffer overflow\n");
+ exit(1);
+ }
+ *optr++ = (uint8_t)(n | kind);
+ memcpy(optr, p, n);
+ optr += n;
+}
+
+static void libdef_endmodule(BuildCtx *ctx)
+{
+ if (modstate != 0) {
+ char line[80];
+ const uint8_t *p;
+ int n;
+ if (modstate == 1)
+ fprintf(ctx->fp, " (lua_CFunction)0");
+ fprintf(ctx->fp, "\n};\n");
+ fprintf(ctx->fp, "static const uint8_t %s%s[] = {\n",
+ LABEL_PREFIX_LIBINIT, modname);
+ line[0] = '\0';
+ for (n = 0, p = obuf; p < optr; p++) {
+ n += sprintf(line+n, "%d,", *p);
+ if (n >= 75) {
+ fprintf(ctx->fp, "%s\n", line);
+ n = 0;
+ line[0] = '\0';
+ }
+ }
+ fprintf(ctx->fp, "%s%d\n};\n#endif\n\n", line, LIBINIT_END);
+ }
+}
+
+static void libdef_module(BuildCtx *ctx, char *p, int arg)
+{
+ UNUSED(arg);
+ if (ctx->mode == BUILD_libdef) {
+ libdef_endmodule(ctx);
+ optr = obuf;
+ *optr++ = (uint8_t)ffid;
+ *optr++ = (uint8_t)ffasmfunc;
+ *optr++ = 0; /* Hash table size. */
+ modstate = 1;
+ fprintf(ctx->fp, "#ifdef %sMODULE_%s\n", LIBDEF_PREFIX, p);
+ fprintf(ctx->fp, "#undef %sMODULE_%s\n", LIBDEF_PREFIX, p);
+ fprintf(ctx->fp, "static const lua_CFunction %s%s[] = {\n",
+ LABEL_PREFIX_LIBCF, p);
+ }
+ modnamelen = strlen(p);
+ if (modnamelen > sizeof(modname)-1) {
+ fprintf(stderr, "Error: module name too long: '%s'\n", p);
+ exit(1);
+ }
+ strcpy(modname, p);
+}
+
+static int find_ffofs(BuildCtx *ctx, const char *name)
+{
+ int i;
+ for (i = 0; i < ctx->nglob; i++) {
+ const char *gl = ctx->globnames[i];
+ if (gl[0] == 'f' && gl[1] == 'f' && gl[2] == '_' && !strcmp(gl+3, name)) {
+ return (int)((uint8_t *)ctx->glob[i] - ctx->code);
+ }
+ }
+ fprintf(stderr, "Error: undefined fast function %s%s\n",
+ LABEL_PREFIX_FF, name);
+ exit(1);
+}
+
+static void libdef_func(BuildCtx *ctx, char *p, int arg)
+{
+ if (arg != LIBINIT_CF)
+ ffasmfunc++;
+ if (ctx->mode == BUILD_libdef) {
+ if (modstate == 0) {
+ fprintf(stderr, "Error: no module for function definition %s\n", p);
+ exit(1);
+ }
+ if (regfunc == REGFUNC_NOREG) {
+ if (optr+1 > obuf+sizeof(obuf)) {
+ fprintf(stderr, "Error: output buffer overflow\n");
+ exit(1);
+ }
+ *optr++ = LIBINIT_FFID;
+ } else {
+ if (arg != LIBINIT_ASM_) {
+ if (modstate != 1) fprintf(ctx->fp, ",\n");
+ modstate = 2;
+ fprintf(ctx->fp, " %s%s", arg ? LABEL_PREFIX_FFH : LABEL_PREFIX_CF, p);
+ }
+ if (regfunc != REGFUNC_NOREGUV) obuf[2]++; /* Bump hash table size. */
+ libdef_name(regfunc == REGFUNC_NOREGUV ? "" : p, arg);
+ }
+ } else if (ctx->mode == BUILD_ffdef) {
+ fprintf(ctx->fp, "FFDEF(%s)\n", p);
+ } else if (ctx->mode == BUILD_recdef) {
+ if (strlen(p) > sizeof(funcname)-1) {
+ fprintf(stderr, "Error: function name too long: '%s'\n", p);
+ exit(1);
+ }
+ strcpy(funcname, p);
+ } else if (ctx->mode == BUILD_vmdef) {
+ int i;
+ for (i = 1; p[i] && modname[i-1]; i++)
+ if (p[i] == '_') p[i] = '.';
+ fprintf(ctx->fp, "\"%s\",\n", p);
+ } else if (ctx->mode == BUILD_bcdef) {
+ if (arg != LIBINIT_CF)
+ fprintf(ctx->fp, ",\n%d", find_ffofs(ctx, p));
+ }
+ ffid++;
+ regfunc = REGFUNC_OK;
+}
+
+static uint32_t find_rec(char *name)
+{
+ char *p = (char *)obuf;
+ uint32_t n;
+ for (n = 2; *p; n++) {
+ if (strcmp(p, name) == 0)
+ return n;
+ p += strlen(p)+1;
+ }
+ if (p+strlen(name)+1 >= (char *)obuf+sizeof(obuf)) {
+ fprintf(stderr, "Error: output buffer overflow\n");
+ exit(1);
+ }
+ strcpy(p, name);
+ return n;
+}
+
+static void libdef_rec(BuildCtx *ctx, char *p, int arg)
+{
+ UNUSED(arg);
+ if (ctx->mode == BUILD_recdef) {
+ char *q;
+ uint32_t n;
+ for (; recffid+1 < ffid; recffid++)
+ fprintf(ctx->fp, ",\n0");
+ recffid = ffid;
+ if (*p == '.') p = funcname;
+ q = strchr(p, ' ');
+ if (q) *q++ = '\0';
+ n = find_rec(p);
+ if (q)
+ fprintf(ctx->fp, ",\n0x%02x00+(%s)", n, q);
+ else
+ fprintf(ctx->fp, ",\n0x%02x00", n);
+ }
+}
+
+static void memcpy_endian(void *dst, void *src, size_t n)
+{
+ union { uint8_t b; uint32_t u; } host_endian;
+ host_endian.u = 1;
+ if (host_endian.b == LJ_ENDIAN_SELECT(1, 0)) {
+ memcpy(dst, src, n);
+ } else {
+ size_t i;
+ for (i = 0; i < n; i++)
+ ((uint8_t *)dst)[i] = ((uint8_t *)src)[n-i-1];
+ }
+}
+
+static void libdef_push(BuildCtx *ctx, char *p, int arg)
+{
+ UNUSED(arg);
+ if (ctx->mode == BUILD_libdef) {
+ int len = (int)strlen(p);
+ if (*p == '"') {
+ if (len > 1 && p[len-1] == '"') {
+ p[len-1] = '\0';
+ libdef_name(p+1, LIBINIT_STRING);
+ return;
+ }
+ } else if (*p >= '0' && *p <= '9') {
+ char *ep;
+ double d = strtod(p, &ep);
+ if (*ep == '\0') {
+ if (optr+1+sizeof(double) > obuf+sizeof(obuf)) {
+ fprintf(stderr, "Error: output buffer overflow\n");
+ exit(1);
+ }
+ *optr++ = LIBINIT_NUMBER;
+ memcpy_endian(optr, &d, sizeof(double));
+ optr += sizeof(double);
+ return;
+ }
+ } else if (!strcmp(p, "lastcl")) {
+ if (optr+1 > obuf+sizeof(obuf)) {
+ fprintf(stderr, "Error: output buffer overflow\n");
+ exit(1);
+ }
+ *optr++ = LIBINIT_LASTCL;
+ return;
+ } else if (len > 4 && !strncmp(p, "top-", 4)) {
+ if (optr+2 > obuf+sizeof(obuf)) {
+ fprintf(stderr, "Error: output buffer overflow\n");
+ exit(1);
+ }
+ *optr++ = LIBINIT_COPY;
+ *optr++ = (uint8_t)atoi(p+4);
+ return;
+ }
+ fprintf(stderr, "Error: bad value for %sPUSH(%s)\n", LIBDEF_PREFIX, p);
+ exit(1);
+ }
+}
+
+static void libdef_set(BuildCtx *ctx, char *p, int arg)
+{
+ UNUSED(arg);
+ if (ctx->mode == BUILD_libdef) {
+ if (p[0] == '!' && p[1] == '\0') p[0] = '\0'; /* Set env. */
+ libdef_name(p, LIBINIT_STRING);
+ *optr++ = LIBINIT_SET;
+ obuf[2]++; /* Bump hash table size. */
+ }
+}
+
+static void libdef_regfunc(BuildCtx *ctx, char *p, int arg)
+{
+ UNUSED(ctx); UNUSED(p);
+ regfunc = arg;
+}
+
+typedef void (*LibDefFunc)(BuildCtx *ctx, char *p, int arg);
+
+typedef struct LibDefHandler {
+ const char *suffix;
+ const char *stop;
+ const LibDefFunc func;
+ const int arg;
+} LibDefHandler;
+
+static const LibDefHandler libdef_handlers[] = {
+ { "MODULE_", " \t\r\n", libdef_module, 0 },
+ { "CF(", ")", libdef_func, LIBINIT_CF },
+ { "ASM(", ")", libdef_func, LIBINIT_ASM },
+ { "ASM_(", ")", libdef_func, LIBINIT_ASM_ },
+ { "REC(", ")", libdef_rec, 0 },
+ { "PUSH(", ")", libdef_push, 0 },
+ { "SET(", ")", libdef_set, 0 },
+ { "NOREGUV", NULL, libdef_regfunc, REGFUNC_NOREGUV },
+ { "NOREG", NULL, libdef_regfunc, REGFUNC_NOREG },
+ { NULL, NULL, (LibDefFunc)0, 0 }
+};
+
+/* Emit C source code for library function definitions. */
+void emit_lib(BuildCtx *ctx)
+{
+ const char *fname;
+
+ if (ctx->mode == BUILD_ffdef || ctx->mode == BUILD_libdef ||
+ ctx->mode == BUILD_recdef)
+ fprintf(ctx->fp, "/* This is a generated file. DO NOT EDIT! */\n\n");
+ else if (ctx->mode == BUILD_vmdef)
+ fprintf(ctx->fp, "ffnames = {\n[0]=\"Lua\",\n\"C\",\n");
+ if (ctx->mode == BUILD_recdef)
+ fprintf(ctx->fp, "static const uint16_t recff_idmap[] = {\n0,\n0x0100");
+ recffid = ffid = FF_C+1;
+ ffasmfunc = 0;
+
+ while ((fname = *ctx->args++)) {
+ char buf[256]; /* We don't care about analyzing lines longer than that. */
+ FILE *fp;
+ if (fname[0] == '-' && fname[1] == '\0') {
+ fp = stdin;
+ } else {
+ fp = fopen(fname, "r");
+ if (!fp) {
+ fprintf(stderr, "Error: cannot open input file '%s': %s\n",
+ fname, strerror(errno));
+ exit(1);
+ }
+ }
+ modstate = 0;
+ regfunc = REGFUNC_OK;
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ char *p;
+ /* Simplistic pre-processor. Only handles top-level #if/#endif. */
+ if (buf[0] == '#' && buf[1] == 'i' && buf[2] == 'f') {
+ int ok = 1;
+ if (!strcmp(buf, "#if LJ_52\n"))
+ ok = LJ_52;
+ else if (!strcmp(buf, "#if LJ_HASJIT\n"))
+ ok = LJ_HASJIT;
+ else if (!strcmp(buf, "#if LJ_HASFFI\n"))
+ ok = LJ_HASFFI;
+ if (!ok) {
+ int lvl = 1;
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ if (buf[0] == '#' && buf[1] == 'e' && buf[2] == 'n') {
+ if (--lvl == 0) break;
+ } else if (buf[0] == '#' && buf[1] == 'i' && buf[2] == 'f') {
+ lvl++;
+ }
+ }
+ continue;
+ }
+ }
+ for (p = buf; (p = strstr(p, LIBDEF_PREFIX)) != NULL; ) {
+ const LibDefHandler *ldh;
+ p += sizeof(LIBDEF_PREFIX)-1;
+ for (ldh = libdef_handlers; ldh->suffix != NULL; ldh++) {
+ size_t n, len = strlen(ldh->suffix);
+ if (!strncmp(p, ldh->suffix, len)) {
+ p += len;
+ n = ldh->stop ? strcspn(p, ldh->stop) : 0;
+ if (!p[n]) break;
+ p[n] = '\0';
+ ldh->func(ctx, p, ldh->arg);
+ p += n+1;
+ break;
+ }
+ }
+ if (ldh->suffix == NULL) {
+ buf[strlen(buf)-1] = '\0';
+ fprintf(stderr, "Error: unknown library definition tag %s%s\n",
+ LIBDEF_PREFIX, p);
+ exit(1);
+ }
+ }
+ }
+ fclose(fp);
+ if (ctx->mode == BUILD_libdef) {
+ libdef_endmodule(ctx);
+ }
+ }
+
+ if (ctx->mode == BUILD_ffdef) {
+ fprintf(ctx->fp, "\n#undef FFDEF\n\n");
+ fprintf(ctx->fp,
+ "#ifndef FF_NUM_ASMFUNC\n#define FF_NUM_ASMFUNC %d\n#endif\n\n",
+ ffasmfunc);
+ } else if (ctx->mode == BUILD_vmdef) {
+ fprintf(ctx->fp, "}\n\n");
+ } else if (ctx->mode == BUILD_bcdef) {
+ int i;
+ fprintf(ctx->fp, "\n};\n\n");
+ fprintf(ctx->fp, "LJ_DATADEF const uint16_t lj_bc_mode[] = {\n");
+ fprintf(ctx->fp, "BCDEF(BCMODE)\n");
+ for (i = ffasmfunc-1; i > 0; i--)
+ fprintf(ctx->fp, "BCMODE_FF,\n");
+ fprintf(ctx->fp, "BCMODE_FF\n};\n\n");
+ } else if (ctx->mode == BUILD_recdef) {
+ char *p = (char *)obuf;
+ fprintf(ctx->fp, "\n};\n\n");
+ fprintf(ctx->fp, "static const RecordFunc recff_func[] = {\n"
+ "recff_nyi,\n"
+ "recff_c");
+ while (*p) {
+ fprintf(ctx->fp, ",\nrecff_%s", p);
+ p += strlen(p)+1;
+ }
+ fprintf(ctx->fp, "\n};\n\n");
+ }
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/host/buildvm_peobj.c b/src/3rdparty/LuaJIT-2.0.5/src/host/buildvm_peobj.c
new file mode 100644
index 0000000..aab00d6
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/host/buildvm_peobj.c
@@ -0,0 +1,368 @@
+/*
+** LuaJIT VM builder: PE object emitter.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Only used for building on Windows, since we cannot assume the presence
+** of a suitable assembler. The host and target byte order must match.
+*/
+
+#include "buildvm.h"
+#include "lj_bc.h"
+
+#if LJ_TARGET_X86ORX64 || LJ_TARGET_PPC
+
+/* Context for PE object emitter. */
+static char *strtab;
+static size_t strtabofs;
+
+/* -- PE object definitions ----------------------------------------------- */
+
+/* PE header. */
+typedef struct PEheader {
+ uint16_t arch;
+ uint16_t nsects;
+ uint32_t time;
+ uint32_t symtabofs;
+ uint32_t nsyms;
+ uint16_t opthdrsz;
+ uint16_t flags;
+} PEheader;
+
+/* PE section. */
+typedef struct PEsection {
+ char name[8];
+ uint32_t vsize;
+ uint32_t vaddr;
+ uint32_t size;
+ uint32_t ofs;
+ uint32_t relocofs;
+ uint32_t lineofs;
+ uint16_t nreloc;
+ uint16_t nline;
+ uint32_t flags;
+} PEsection;
+
+/* PE relocation. */
+typedef struct PEreloc {
+ uint32_t vaddr;
+ uint32_t symidx;
+ uint16_t type;
+} PEreloc;
+
+/* Cannot use sizeof, because it pads up to the max. alignment. */
+#define PEOBJ_RELOC_SIZE (4+4+2)
+
+/* PE symbol table entry. */
+typedef struct PEsym {
+ union {
+ char name[8];
+ uint32_t nameref[2];
+ } n;
+ uint32_t value;
+ int16_t sect;
+ uint16_t type;
+ uint8_t scl;
+ uint8_t naux;
+} PEsym;
+
+/* PE symbol table auxiliary entry for a section. */
+typedef struct PEsymaux {
+ uint32_t size;
+ uint16_t nreloc;
+ uint16_t nline;
+ uint32_t cksum;
+ uint16_t assoc;
+ uint8_t comdatsel;
+ uint8_t unused[3];
+} PEsymaux;
+
+/* Cannot use sizeof, because it pads up to the max. alignment. */
+#define PEOBJ_SYM_SIZE (8+4+2+2+1+1)
+
+/* PE object CPU specific defines. */
+#if LJ_TARGET_X86
+#define PEOBJ_ARCH_TARGET 0x014c
+#define PEOBJ_RELOC_REL32 0x14 /* MS: REL32, GNU: DISP32. */
+#define PEOBJ_RELOC_DIR32 0x06
+#define PEOBJ_RELOC_OFS 0
+#define PEOBJ_TEXT_FLAGS 0x60500020 /* 60=r+x, 50=align16, 20=code. */
+#elif LJ_TARGET_X64
+#define PEOBJ_ARCH_TARGET 0x8664
+#define PEOBJ_RELOC_REL32 0x04 /* MS: REL32, GNU: DISP32. */
+#define PEOBJ_RELOC_DIR32 0x02
+#define PEOBJ_RELOC_ADDR32NB 0x03
+#define PEOBJ_RELOC_OFS 0
+#define PEOBJ_TEXT_FLAGS 0x60500020 /* 60=r+x, 50=align16, 20=code. */
+#elif LJ_TARGET_PPC
+#define PEOBJ_ARCH_TARGET 0x01f2
+#define PEOBJ_RELOC_REL32 0x06
+#define PEOBJ_RELOC_DIR32 0x02
+#define PEOBJ_RELOC_OFS (-4)
+#define PEOBJ_TEXT_FLAGS 0x60400020 /* 60=r+x, 40=align8, 20=code. */
+#endif
+
+/* Section numbers (0-based). */
+enum {
+ PEOBJ_SECT_ABS = -2,
+ PEOBJ_SECT_UNDEF = -1,
+ PEOBJ_SECT_TEXT,
+#if LJ_TARGET_X64
+ PEOBJ_SECT_PDATA,
+ PEOBJ_SECT_XDATA,
+#endif
+ PEOBJ_SECT_RDATA_Z,
+ PEOBJ_NSECTIONS
+};
+
+/* Symbol types. */
+#define PEOBJ_TYPE_NULL 0
+#define PEOBJ_TYPE_FUNC 0x20
+
+/* Symbol storage class. */
+#define PEOBJ_SCL_EXTERN 2
+#define PEOBJ_SCL_STATIC 3
+
+/* -- PE object emitter --------------------------------------------------- */
+
+/* Emit PE object symbol. */
+static void emit_peobj_sym(BuildCtx *ctx, const char *name, uint32_t value,
+ int sect, int type, int scl)
+{
+ PEsym sym;
+ size_t len = strlen(name);
+ if (!strtab) { /* Pass 1: only calculate string table length. */
+ if (len > 8) strtabofs += len+1;
+ return;
+ }
+ if (len <= 8) {
+ memcpy(sym.n.name, name, len);
+ memset(sym.n.name+len, 0, 8-len);
+ } else {
+ sym.n.nameref[0] = 0;
+ sym.n.nameref[1] = (uint32_t)strtabofs;
+ memcpy(strtab + strtabofs, name, len);
+ strtab[strtabofs+len] = 0;
+ strtabofs += len+1;
+ }
+ sym.value = value;
+ sym.sect = (int16_t)(sect+1); /* 1-based section number. */
+ sym.type = (uint16_t)type;
+ sym.scl = (uint8_t)scl;
+ sym.naux = 0;
+ owrite(ctx, &sym, PEOBJ_SYM_SIZE);
+}
+
+/* Emit PE object section symbol. */
+static void emit_peobj_sym_sect(BuildCtx *ctx, PEsection *pesect, int sect)
+{
+ PEsym sym;
+ PEsymaux aux;
+ if (!strtab) return; /* Pass 1: no output. */
+ memcpy(sym.n.name, pesect[sect].name, 8);
+ sym.value = 0;
+ sym.sect = (int16_t)(sect+1); /* 1-based section number. */
+ sym.type = PEOBJ_TYPE_NULL;
+ sym.scl = PEOBJ_SCL_STATIC;
+ sym.naux = 1;
+ owrite(ctx, &sym, PEOBJ_SYM_SIZE);
+ memset(&aux, 0, sizeof(PEsymaux));
+ aux.size = pesect[sect].size;
+ aux.nreloc = pesect[sect].nreloc;
+ owrite(ctx, &aux, PEOBJ_SYM_SIZE);
+}
+
+/* Emit Windows PE object file. */
+void emit_peobj(BuildCtx *ctx)
+{
+ PEheader pehdr;
+ PEsection pesect[PEOBJ_NSECTIONS];
+ uint32_t sofs;
+ int i, nrsym;
+ union { uint8_t b; uint32_t u; } host_endian;
+
+ sofs = sizeof(PEheader) + PEOBJ_NSECTIONS*sizeof(PEsection);
+
+ /* Fill in PE sections. */
+ memset(&pesect, 0, PEOBJ_NSECTIONS*sizeof(PEsection));
+ memcpy(pesect[PEOBJ_SECT_TEXT].name, ".text", sizeof(".text")-1);
+ pesect[PEOBJ_SECT_TEXT].ofs = sofs;
+ sofs += (pesect[PEOBJ_SECT_TEXT].size = (uint32_t)ctx->codesz);
+ pesect[PEOBJ_SECT_TEXT].relocofs = sofs;
+ sofs += (pesect[PEOBJ_SECT_TEXT].nreloc = (uint16_t)ctx->nreloc) * PEOBJ_RELOC_SIZE;
+ /* Flags: 60 = read+execute, 50 = align16, 20 = code. */
+ pesect[PEOBJ_SECT_TEXT].flags = PEOBJ_TEXT_FLAGS;
+
+#if LJ_TARGET_X64
+ memcpy(pesect[PEOBJ_SECT_PDATA].name, ".pdata", sizeof(".pdata")-1);
+ pesect[PEOBJ_SECT_PDATA].ofs = sofs;
+ sofs += (pesect[PEOBJ_SECT_PDATA].size = 6*4);
+ pesect[PEOBJ_SECT_PDATA].relocofs = sofs;
+ sofs += (pesect[PEOBJ_SECT_PDATA].nreloc = 6) * PEOBJ_RELOC_SIZE;
+ /* Flags: 40 = read, 30 = align4, 40 = initialized data. */
+ pesect[PEOBJ_SECT_PDATA].flags = 0x40300040;
+
+ memcpy(pesect[PEOBJ_SECT_XDATA].name, ".xdata", sizeof(".xdata")-1);
+ pesect[PEOBJ_SECT_XDATA].ofs = sofs;
+ sofs += (pesect[PEOBJ_SECT_XDATA].size = 8*2+4+6*2); /* See below. */
+ pesect[PEOBJ_SECT_XDATA].relocofs = sofs;
+ sofs += (pesect[PEOBJ_SECT_XDATA].nreloc = 1) * PEOBJ_RELOC_SIZE;
+ /* Flags: 40 = read, 30 = align4, 40 = initialized data. */
+ pesect[PEOBJ_SECT_XDATA].flags = 0x40300040;
+#endif
+
+ memcpy(pesect[PEOBJ_SECT_RDATA_Z].name, ".rdata$Z", sizeof(".rdata$Z")-1);
+ pesect[PEOBJ_SECT_RDATA_Z].ofs = sofs;
+ sofs += (pesect[PEOBJ_SECT_RDATA_Z].size = (uint32_t)strlen(ctx->dasm_ident)+1);
+ /* Flags: 40 = read, 30 = align4, 40 = initialized data. */
+ pesect[PEOBJ_SECT_RDATA_Z].flags = 0x40300040;
+
+ /* Fill in PE header. */
+ pehdr.arch = PEOBJ_ARCH_TARGET;
+ pehdr.nsects = PEOBJ_NSECTIONS;
+ pehdr.time = 0; /* Timestamp is optional. */
+ pehdr.symtabofs = sofs;
+ pehdr.opthdrsz = 0;
+ pehdr.flags = 0;
+
+ /* Compute the size of the symbol table:
+ ** @feat.00 + nsections*2
+ ** + asm_start + nsym
+ ** + nrsym
+ */
+ nrsym = ctx->nrelocsym;
+ pehdr.nsyms = 1+PEOBJ_NSECTIONS*2 + 1+ctx->nsym + nrsym;
+#if LJ_TARGET_X64
+ pehdr.nsyms += 1; /* Symbol for lj_err_unwind_win64. */
+#endif
+
+ /* Write PE object header and all sections. */
+ owrite(ctx, &pehdr, sizeof(PEheader));
+ owrite(ctx, &pesect, sizeof(PEsection)*PEOBJ_NSECTIONS);
+
+ /* Write .text section. */
+ host_endian.u = 1;
+ if (host_endian.b != LJ_ENDIAN_SELECT(1, 0)) {
+#if LJ_TARGET_PPC
+ uint32_t *p = (uint32_t *)ctx->code;
+ int n = (int)(ctx->codesz >> 2);
+ for (i = 0; i < n; i++, p++)
+ *p = lj_bswap(*p); /* Byteswap .text section. */
+#else
+ fprintf(stderr, "Error: different byte order for host and target\n");
+ exit(1);
+#endif
+ }
+ owrite(ctx, ctx->code, ctx->codesz);
+ for (i = 0; i < ctx->nreloc; i++) {
+ PEreloc reloc;
+ reloc.vaddr = (uint32_t)ctx->reloc[i].ofs + PEOBJ_RELOC_OFS;
+ reloc.symidx = 1+2+ctx->reloc[i].sym; /* Reloc syms are after .text sym. */
+ reloc.type = ctx->reloc[i].type ? PEOBJ_RELOC_REL32 : PEOBJ_RELOC_DIR32;
+ owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);
+ }
+
+#if LJ_TARGET_X64
+ { /* Write .pdata section. */
+ uint32_t fcofs = (uint32_t)ctx->sym[ctx->nsym-1].ofs;
+ uint32_t pdata[3]; /* Start of .text, end of .text and .xdata. */
+ PEreloc reloc;
+ pdata[0] = 0; pdata[1] = fcofs; pdata[2] = 0;
+ owrite(ctx, &pdata, sizeof(pdata));
+ pdata[0] = fcofs; pdata[1] = (uint32_t)ctx->codesz; pdata[2] = 20;
+ owrite(ctx, &pdata, sizeof(pdata));
+ reloc.vaddr = 0; reloc.symidx = 1+2+nrsym+2+2+1;
+ reloc.type = PEOBJ_RELOC_ADDR32NB;
+ owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);
+ reloc.vaddr = 4; reloc.symidx = 1+2+nrsym+2+2+1;
+ reloc.type = PEOBJ_RELOC_ADDR32NB;
+ owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);
+ reloc.vaddr = 8; reloc.symidx = 1+2+nrsym+2;
+ reloc.type = PEOBJ_RELOC_ADDR32NB;
+ owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);
+ reloc.vaddr = 12; reloc.symidx = 1+2+nrsym+2+2+1;
+ reloc.type = PEOBJ_RELOC_ADDR32NB;
+ owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);
+ reloc.vaddr = 16; reloc.symidx = 1+2+nrsym+2+2+1;
+ reloc.type = PEOBJ_RELOC_ADDR32NB;
+ owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);
+ reloc.vaddr = 20; reloc.symidx = 1+2+nrsym+2;
+ reloc.type = PEOBJ_RELOC_ADDR32NB;
+ owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);
+ }
+ { /* Write .xdata section. */
+ uint16_t xdata[8+2+6];
+ PEreloc reloc;
+ xdata[0] = 0x01|0x08|0x10; /* Ver. 1, uhandler/ehandler, prolog size 0. */
+ xdata[1] = 0x0005; /* Number of unwind codes, no frame pointer. */
+ xdata[2] = 0x4200; /* Stack offset 4*8+8 = aword*5. */
+ xdata[3] = 0x3000; /* Push rbx. */
+ xdata[4] = 0x6000; /* Push rsi. */
+ xdata[5] = 0x7000; /* Push rdi. */
+ xdata[6] = 0x5000; /* Push rbp. */
+ xdata[7] = 0; /* Alignment. */
+ xdata[8] = xdata[9] = 0; /* Relocated address of exception handler. */
+ xdata[10] = 0x01; /* Ver. 1, no handler, prolog size 0. */
+ xdata[11] = 0x1504; /* Number of unwind codes, fp = rbp, fpofs = 16. */
+ xdata[12] = 0x0300; /* set_fpreg. */
+ xdata[13] = 0x0200; /* stack offset 0*8+8 = aword*1. */
+ xdata[14] = 0x3000; /* Push rbx. */
+ xdata[15] = 0x5000; /* Push rbp. */
+ owrite(ctx, &xdata, sizeof(xdata));
+ reloc.vaddr = 2*8; reloc.symidx = 1+2+nrsym+2+2;
+ reloc.type = PEOBJ_RELOC_ADDR32NB;
+ owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);
+ }
+#endif
+
+ /* Write .rdata$Z section. */
+ owrite(ctx, ctx->dasm_ident, strlen(ctx->dasm_ident)+1);
+
+ /* Write symbol table. */
+ strtab = NULL; /* 1st pass: collect string sizes. */
+ for (;;) {
+ strtabofs = 4;
+ /* Mark as SafeSEH compliant. */
+ emit_peobj_sym(ctx, "@feat.00", 1,
+ PEOBJ_SECT_ABS, PEOBJ_TYPE_NULL, PEOBJ_SCL_STATIC);
+
+ emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_TEXT);
+ for (i = 0; i < nrsym; i++)
+ emit_peobj_sym(ctx, ctx->relocsym[i], 0,
+ PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN);
+
+#if LJ_TARGET_X64
+ emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_PDATA);
+ emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_XDATA);
+ emit_peobj_sym(ctx, "lj_err_unwind_win64", 0,
+ PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN);
+#endif
+
+ emit_peobj_sym(ctx, ctx->beginsym, 0,
+ PEOBJ_SECT_TEXT, PEOBJ_TYPE_NULL, PEOBJ_SCL_EXTERN);
+ for (i = 0; i < ctx->nsym; i++)
+ emit_peobj_sym(ctx, ctx->sym[i].name, (uint32_t)ctx->sym[i].ofs,
+ PEOBJ_SECT_TEXT, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN);
+
+ emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_RDATA_Z);
+
+ if (strtab)
+ break;
+ /* 2nd pass: alloc strtab, write syms and copy strings. */
+ strtab = (char *)malloc(strtabofs);
+ *(uint32_t *)strtab = (uint32_t)strtabofs;
+ }
+
+ /* Write string table. */
+ owrite(ctx, strtab, strtabofs);
+}
+
+#else
+
+void emit_peobj(BuildCtx *ctx)
+{
+ UNUSED(ctx);
+ fprintf(stderr, "Error: no PE object support for this target\n");
+ exit(1);
+}
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/host/genminilua.lua b/src/3rdparty/LuaJIT-2.0.5/src/host/genminilua.lua
new file mode 100644
index 0000000..50feff0
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/host/genminilua.lua
@@ -0,0 +1,429 @@
+----------------------------------------------------------------------------
+-- Lua script to generate a customized, minified version of Lua.
+-- The resulting 'minilua' is used for the build process of LuaJIT.
+----------------------------------------------------------------------------
+-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+-- Released under the MIT license. See Copyright Notice in luajit.h
+----------------------------------------------------------------------------
+
+local sub, match, gsub = string.sub, string.match, string.gsub
+
+local LUA_VERSION = "5.1.5"
+local LUA_SOURCE
+
+local function usage()
+ io.stderr:write("Usage: ", arg and arg[0] or "genminilua",
+ " lua-", LUA_VERSION, "-source-dir\n")
+ os.exit(1)
+end
+
+local function find_sources()
+ LUA_SOURCE = arg and arg[1]
+ if not LUA_SOURCE then usage() end
+ if sub(LUA_SOURCE, -1) ~= "/" then LUA_SOURCE = LUA_SOURCE.."/" end
+ local fp = io.open(LUA_SOURCE .. "lua.h")
+ if not fp then
+ LUA_SOURCE = LUA_SOURCE.."src/"
+ fp = io.open(LUA_SOURCE .. "lua.h")
+ if not fp then usage() end
+ end
+ local all = fp:read("*a")
+ fp:close()
+ if not match(all, 'LUA_RELEASE%s*"Lua '..LUA_VERSION..'"') then
+ io.stderr:write("Error: version mismatch\n")
+ usage()
+ end
+end
+
+local LUA_FILES = {
+"lmem.c", "lobject.c", "ltm.c", "lfunc.c", "ldo.c", "lstring.c", "ltable.c",
+"lgc.c", "lstate.c", "ldebug.c", "lzio.c", "lopcodes.c",
+"llex.c", "lcode.c", "lparser.c", "lvm.c", "lapi.c", "lauxlib.c",
+"lbaselib.c", "ltablib.c", "liolib.c", "loslib.c", "lstrlib.c", "linit.c",
+}
+
+local REMOVE_LIB = {}
+gsub([[
+collectgarbage dofile gcinfo getfenv getmetatable load print rawequal rawset
+select tostring xpcall
+foreach foreachi getn maxn setn
+popen tmpfile seek setvbuf __tostring
+clock date difftime execute getenv rename setlocale time tmpname
+dump gfind len reverse
+LUA_LOADLIBNAME LUA_MATHLIBNAME LUA_DBLIBNAME
+]], "%S+", function(name)
+ REMOVE_LIB[name] = true
+end)
+
+local REMOVE_EXTINC = { ["<assert.h>"] = true, ["<locale.h>"] = true, }
+
+local CUSTOM_MAIN = [[
+typedef unsigned int UB;
+static UB barg(lua_State *L,int idx){
+union{lua_Number n;U64 b;}bn;
+bn.n=lua_tonumber(L,idx)+6755399441055744.0;
+if (bn.n==0.0&&!lua_isnumber(L,idx))luaL_typerror(L,idx,"number");
+return(UB)bn.b;
+}
+#define BRET(b) lua_pushnumber(L,(lua_Number)(int)(b));return 1;
+static int tobit(lua_State *L){
+BRET(barg(L,1))}
+static int bnot(lua_State *L){
+BRET(~barg(L,1))}
+static int band(lua_State *L){
+int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b&=barg(L,i);BRET(b)}
+static int bor(lua_State *L){
+int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b|=barg(L,i);BRET(b)}
+static int bxor(lua_State *L){
+int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b^=barg(L,i);BRET(b)}
+static int lshift(lua_State *L){
+UB b=barg(L,1),n=barg(L,2)&31;BRET(b<<n)}
+static int rshift(lua_State *L){
+UB b=barg(L,1),n=barg(L,2)&31;BRET(b>>n)}
+static int arshift(lua_State *L){
+UB b=barg(L,1),n=barg(L,2)&31;BRET((int)b>>n)}
+static int rol(lua_State *L){
+UB b=barg(L,1),n=barg(L,2)&31;BRET((b<<n)|(b>>(32-n)))}
+static int ror(lua_State *L){
+UB b=barg(L,1),n=barg(L,2)&31;BRET((b>>n)|(b<<(32-n)))}
+static int bswap(lua_State *L){
+UB b=barg(L,1);b=(b>>24)|((b>>8)&0xff00)|((b&0xff00)<<8)|(b<<24);BRET(b)}
+static int tohex(lua_State *L){
+UB b=barg(L,1);
+int n=lua_isnone(L,2)?8:(int)barg(L,2);
+const char *hexdigits="0123456789abcdef";
+char buf[8];
+int i;
+if(n<0){n=-n;hexdigits="0123456789ABCDEF";}
+if(n>8)n=8;
+for(i=(int)n;--i>=0;){buf[i]=hexdigits[b&15];b>>=4;}
+lua_pushlstring(L,buf,(size_t)n);
+return 1;
+}
+static const struct luaL_Reg bitlib[] = {
+{"tobit",tobit},
+{"bnot",bnot},
+{"band",band},
+{"bor",bor},
+{"bxor",bxor},
+{"lshift",lshift},
+{"rshift",rshift},
+{"arshift",arshift},
+{"rol",rol},
+{"ror",ror},
+{"bswap",bswap},
+{"tohex",tohex},
+{NULL,NULL}
+};
+int main(int argc, char **argv){
+ lua_State *L = luaL_newstate();
+ int i;
+ luaL_openlibs(L);
+ luaL_register(L, "bit", bitlib);
+ if (argc < 2) return sizeof(void *);
+ lua_createtable(L, 0, 1);
+ lua_pushstring(L, argv[1]);
+ lua_rawseti(L, -2, 0);
+ lua_setglobal(L, "arg");
+ if (luaL_loadfile(L, argv[1]))
+ goto err;
+ for (i = 2; i < argc; i++)
+ lua_pushstring(L, argv[i]);
+ if (lua_pcall(L, argc - 2, 0, 0)) {
+ err:
+ fprintf(stderr, "Error: %s\n", lua_tostring(L, -1));
+ return 1;
+ }
+ lua_close(L);
+ return 0;
+}
+]]
+
+local function read_sources()
+ local t = {}
+ for i, name in ipairs(LUA_FILES) do
+ local fp = assert(io.open(LUA_SOURCE..name, "r"))
+ t[i] = fp:read("*a")
+ assert(fp:close())
+ end
+ t[#t+1] = CUSTOM_MAIN
+ return table.concat(t)
+end
+
+local includes = {}
+
+local function merge_includes(src)
+ return gsub(src, '#include%s*"([^"]*)"%s*\n', function(name)
+ if includes[name] then return "" end
+ includes[name] = true
+ local fp = assert(io.open(LUA_SOURCE..name, "r"))
+ local inc = fp:read("*a")
+ assert(fp:close())
+ inc = gsub(inc, "#ifndef%s+%w+_h\n#define%s+%w+_h\n", "")
+ inc = gsub(inc, "#endif%s*$", "")
+ return merge_includes(inc)
+ end)
+end
+
+local function get_license(src)
+ return match(src, "/%*+\n%* Copyright %(.-%*/\n")
+end
+
+local function fold_lines(src)
+ return gsub(src, "\\\n", " ")
+end
+
+local strings = {}
+
+local function save_str(str)
+ local n = #strings+1
+ strings[n] = str
+ return "\1"..n.."\2"
+end
+
+local function save_strings(src)
+ src = gsub(src, '"[^"\n]*"', save_str)
+ return gsub(src, "'[^'\n]*'", save_str)
+end
+
+local function restore_strings(src)
+ return gsub(src, "\1(%d+)\2", function(numstr)
+ return strings[tonumber(numstr)]
+ end)
+end
+
+local function def_istrue(def)
+ return def == "INT_MAX > 2147483640L" or
+ def == "LUAI_BITSINT >= 32" or
+ def == "SIZE_Bx < LUAI_BITSINT-1" or
+ def == "cast" or
+ def == "defined(LUA_CORE)" or
+ def == "MINSTRTABSIZE" or
+ def == "LUA_MINBUFFER" or
+ def == "HARDSTACKTESTS" or
+ def == "UNUSED"
+end
+
+local head, defs = {[[
+#ifdef _MSC_VER
+typedef unsigned __int64 U64;
+#else
+typedef unsigned long long U64;
+#endif
+int _CRT_glob = 0;
+]]}, {}
+
+local function preprocess(src)
+ local t = { match(src, "^(.-)#") }
+ local lvl, on, oldon = 0, true, {}
+ for pp, def, txt in string.gmatch(src, "#(%w+) *([^\n]*)\n([^#]*)") do
+ if pp == "if" or pp == "ifdef" or pp == "ifndef" then
+ lvl = lvl + 1
+ oldon[lvl] = on
+ on = def_istrue(def)
+ elseif pp == "else" then
+ if oldon[lvl] then
+ if on == false then on = true else on = false end
+ end
+ elseif pp == "elif" then
+ if oldon[lvl] then
+ on = def_istrue(def)
+ end
+ elseif pp == "endif" then
+ on = oldon[lvl]
+ lvl = lvl - 1
+ elseif on then
+ if pp == "include" then
+ if not head[def] and not REMOVE_EXTINC[def] then
+ head[def] = true
+ head[#head+1] = "#include "..def.."\n"
+ end
+ elseif pp == "define" then
+ local k, sp, v = match(def, "([%w_]+)(%s*)(.*)")
+ if k and not (sp == "" and sub(v, 1, 1) == "(") then
+ defs[k] = gsub(v, "%a[%w_]*", function(tok)
+ return defs[tok] or tok
+ end)
+ else
+ t[#t+1] = "#define "..def.."\n"
+ end
+ elseif pp ~= "undef" then
+ error("unexpected directive: "..pp.." "..def)
+ end
+ end
+ if on then t[#t+1] = txt end
+ end
+ return gsub(table.concat(t), "%a[%w_]*", function(tok)
+ return defs[tok] or tok
+ end)
+end
+
+local function merge_header(src, license)
+ local hdr = string.format([[
+/* This is a heavily customized and minimized copy of Lua %s. */
+/* It's only used to build LuaJIT. It does NOT have all standard functions! */
+]], LUA_VERSION)
+ return hdr..license..table.concat(head)..src
+end
+
+local function strip_unused1(src)
+ return gsub(src, '( {"?([%w_]+)"?,%s+%a[%w_]*},\n)', function(line, func)
+ return REMOVE_LIB[func] and "" or line
+ end)
+end
+
+local function strip_unused2(src)
+ return gsub(src, "Symbolic Execution.-}=", "")
+end
+
+local function strip_unused3(src)
+ src = gsub(src, "extern", "static")
+ src = gsub(src, "\nstatic([^\n]-)%(([^)]*)%)%(", "\nstatic%1 %2(")
+ src = gsub(src, "#define lua_assert[^\n]*\n", "")
+ src = gsub(src, "lua_assert%b();?", "")
+ src = gsub(src, "default:\n}", "default:;\n}")
+ src = gsub(src, "lua_lock%b();", "")
+ src = gsub(src, "lua_unlock%b();", "")
+ src = gsub(src, "luai_threadyield%b();", "")
+ src = gsub(src, "luai_userstateopen%b();", "{}")
+ src = gsub(src, "luai_userstate%w+%b();", "")
+ src = gsub(src, "%(%(c==.*luaY_parser%)", "luaY_parser")
+ src = gsub(src, "trydecpoint%(ls,seminfo%)",
+ "luaX_lexerror(ls,\"malformed number\",TK_NUMBER)")
+ src = gsub(src, "int c=luaZ_lookahead%b();", "")
+ src = gsub(src, "luaL_register%(L,[^,]*,co_funcs%);\nreturn 2;",
+ "return 1;")
+ src = gsub(src, "getfuncname%b():", "NULL:")
+ src = gsub(src, "getobjname%b():", "NULL:")
+ src = gsub(src, "if%([^\n]*hookmask[^\n]*%)\n[^\n]*\n", "")
+ src = gsub(src, "if%([^\n]*hookmask[^\n]*%)%b{}\n", "")
+ src = gsub(src, "if%([^\n]*hookmask[^\n]*&&\n[^\n]*%b{}\n", "")
+ src = gsub(src, "(twoto%b()%()", "%1(size_t)")
+ src = gsub(src, "i<sizenode", "i<(int)sizenode")
+ src = gsub(src, "cast%(unsigned int,key%-1%)", "cast(unsigned int,key)-1")
+ return gsub(src, "\n\n+", "\n")
+end
+
+local function strip_comments(src)
+ return gsub(src, "/%*.-%*/", " ")
+end
+
+local function strip_whitespace(src)
+ src = gsub(src, "^%s+", "")
+ src = gsub(src, "%s*\n%s*", "\n")
+ src = gsub(src, "[ \t]+", " ")
+ src = gsub(src, "(%W) ", "%1")
+ return gsub(src, " (%W)", "%1")
+end
+
+local function rename_tokens1(src)
+ src = gsub(src, "getline", "getline_")
+ src = gsub(src, "struct ([%w_]+)", "ZX%1")
+ return gsub(src, "union ([%w_]+)", "ZY%1")
+end
+
+local function rename_tokens2(src)
+ src = gsub(src, "ZX([%w_]+)", "struct %1")
+ return gsub(src, "ZY([%w_]+)", "union %1")
+end
+
+local function func_gather(src)
+ local nodes, list = {}, {}
+ local pos, len = 1, #src
+ while pos < len do
+ local d, w = match(src, "^(#define ([%w_]+)[^\n]*\n)", pos)
+ if d then
+ local n = #list+1
+ list[n] = d
+ nodes[w] = n
+ else
+ local s
+ d, w, s = match(src, "^(([%w_]+)[^\n]*([{;])\n)", pos)
+ if not d then
+ d, w, s = match(src, "^(([%w_]+)[^(]*%b()([{;])\n)", pos)
+ if not d then d = match(src, "^[^\n]*\n", pos) end
+ end
+ if s == "{" then
+ d = d..sub(match(src, "^%b{}[^;\n]*;?\n", pos+#d-2), 3)
+ if sub(d, -2) == "{\n" then
+ d = d..sub(match(src, "^%b{}[^;\n]*;?\n", pos+#d-2), 3)
+ end
+ end
+ local k, v = nil, d
+ if w == "typedef" then
+ if match(d, "^typedef enum") then
+ head[#head+1] = d
+ else
+ k = match(d, "([%w_]+);\n$")
+ if not k then k = match(d, "^.-%(.-([%w_]+)%)%(") end
+ end
+ elseif w == "enum" then
+ head[#head+1] = v
+ elseif w ~= nil then
+ k = match(d, "^[^\n]-([%w_]+)[(%[=]")
+ if k then
+ if w ~= "static" and k ~= "main" then v = "static "..d end
+ else
+ k = w
+ end
+ end
+ if w and k then
+ local o = nodes[k]
+ if o then nodes["*"..k] = o end
+ local n = #list+1
+ list[n] = v
+ nodes[k] = n
+ end
+ end
+ pos = pos + #d
+ end
+ return nodes, list
+end
+
+local function func_visit(nodes, list, used, n)
+ local i = nodes[n]
+ for m in string.gmatch(list[i], "[%w_]+") do
+ if nodes[m] then
+ local j = used[m]
+ if not j then
+ used[m] = i
+ func_visit(nodes, list, used, m)
+ elseif i < j then
+ used[m] = i
+ end
+ end
+ end
+end
+
+local function func_collect(src)
+ local nodes, list = func_gather(src)
+ local used = {}
+ func_visit(nodes, list, used, "main")
+ for n,i in pairs(nodes) do
+ local j = used[n]
+ if j and j < i then used["*"..n] = j end
+ end
+ for n,i in pairs(nodes) do
+ if not used[n] then list[i] = "" end
+ end
+ return table.concat(list)
+end
+
+find_sources()
+local src = read_sources()
+src = merge_includes(src)
+local license = get_license(src)
+src = fold_lines(src)
+src = strip_unused1(src)
+src = save_strings(src)
+src = strip_unused2(src)
+src = strip_comments(src)
+src = preprocess(src)
+src = strip_whitespace(src)
+src = strip_unused3(src)
+src = rename_tokens1(src)
+src = func_collect(src)
+src = rename_tokens2(src)
+src = restore_strings(src)
+src = merge_header(src, license)
+io.write(src)
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/host/minilua.c b/src/3rdparty/LuaJIT-2.0.5/src/host/minilua.c
new file mode 100644
index 0000000..7915028
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/host/minilua.c
@@ -0,0 +1,7770 @@
+/* This is a heavily customized and minimized copy of Lua 5.1.5. */
+/* It's only used to build LuaJIT. It does NOT have all standard functions! */
+/******************************************************************************
+* Copyright (C) 1994-2012 Lua.org, PUC-Rio. All rights reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining
+* a copy of this software and associated documentation files (the
+* "Software"), to deal in the Software without restriction, including
+* without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to
+* permit persons to whom the Software is furnished to do so, subject to
+* the following conditions:
+*
+* The above copyright notice and this permission notice shall be
+* included in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+******************************************************************************/
+#ifdef _MSC_VER
+typedef unsigned __int64 U64;
+#else
+typedef unsigned long long U64;
+#endif
+int _CRT_glob = 0;
+#include <stddef.h>
+#include <stdarg.h>
+#include <limits.h>
+#include <math.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <setjmp.h>
+#include <errno.h>
+#include <time.h>
+typedef enum{
+TM_INDEX,
+TM_NEWINDEX,
+TM_GC,
+TM_MODE,
+TM_EQ,
+TM_ADD,
+TM_SUB,
+TM_MUL,
+TM_DIV,
+TM_MOD,
+TM_POW,
+TM_UNM,
+TM_LEN,
+TM_LT,
+TM_LE,
+TM_CONCAT,
+TM_CALL,
+TM_N
+}TMS;
+enum OpMode{iABC,iABx,iAsBx};
+typedef enum{
+OP_MOVE,
+OP_LOADK,
+OP_LOADBOOL,
+OP_LOADNIL,
+OP_GETUPVAL,
+OP_GETGLOBAL,
+OP_GETTABLE,
+OP_SETGLOBAL,
+OP_SETUPVAL,
+OP_SETTABLE,
+OP_NEWTABLE,
+OP_SELF,
+OP_ADD,
+OP_SUB,
+OP_MUL,
+OP_DIV,
+OP_MOD,
+OP_POW,
+OP_UNM,
+OP_NOT,
+OP_LEN,
+OP_CONCAT,
+OP_JMP,
+OP_EQ,
+OP_LT,
+OP_LE,
+OP_TEST,
+OP_TESTSET,
+OP_CALL,
+OP_TAILCALL,
+OP_RETURN,
+OP_FORLOOP,
+OP_FORPREP,
+OP_TFORLOOP,
+OP_SETLIST,
+OP_CLOSE,
+OP_CLOSURE,
+OP_VARARG
+}OpCode;
+enum OpArgMask{
+OpArgN,
+OpArgU,
+OpArgR,
+OpArgK
+};
+typedef enum{
+VVOID,
+VNIL,
+VTRUE,
+VFALSE,
+VK,
+VKNUM,
+VLOCAL,
+VUPVAL,
+VGLOBAL,
+VINDEXED,
+VJMP,
+VRELOCABLE,
+VNONRELOC,
+VCALL,
+VVARARG
+}expkind;
+enum RESERVED{
+TK_AND=257,TK_BREAK,
+TK_DO,TK_ELSE,TK_ELSEIF,TK_END,TK_FALSE,TK_FOR,TK_FUNCTION,
+TK_IF,TK_IN,TK_LOCAL,TK_NIL,TK_NOT,TK_OR,TK_REPEAT,
+TK_RETURN,TK_THEN,TK_TRUE,TK_UNTIL,TK_WHILE,
+TK_CONCAT,TK_DOTS,TK_EQ,TK_GE,TK_LE,TK_NE,TK_NUMBER,
+TK_NAME,TK_STRING,TK_EOS
+};
+typedef enum BinOpr{
+OPR_ADD,OPR_SUB,OPR_MUL,OPR_DIV,OPR_MOD,OPR_POW,
+OPR_CONCAT,
+OPR_NE,OPR_EQ,
+OPR_LT,OPR_LE,OPR_GT,OPR_GE,
+OPR_AND,OPR_OR,
+OPR_NOBINOPR
+}BinOpr;
+typedef enum UnOpr{OPR_MINUS,OPR_NOT,OPR_LEN,OPR_NOUNOPR}UnOpr;
+#define LUA_QL(x)"'"x"'"
+#define luai_apicheck(L,o){(void)L;}
+#define lua_number2str(s,n)sprintf((s),"%.14g",(n))
+#define lua_str2number(s,p)strtod((s),(p))
+#define luai_numadd(a,b)((a)+(b))
+#define luai_numsub(a,b)((a)-(b))
+#define luai_nummul(a,b)((a)*(b))
+#define luai_numdiv(a,b)((a)/(b))
+#define luai_nummod(a,b)((a)-floor((a)/(b))*(b))
+#define luai_numpow(a,b)(pow(a,b))
+#define luai_numunm(a)(-(a))
+#define luai_numeq(a,b)((a)==(b))
+#define luai_numlt(a,b)((a)<(b))
+#define luai_numle(a,b)((a)<=(b))
+#define luai_numisnan(a)(!luai_numeq((a),(a)))
+#define lua_number2int(i,d)((i)=(int)(d))
+#define lua_number2integer(i,d)((i)=(lua_Integer)(d))
+#define LUAI_THROW(L,c)longjmp((c)->b,1)
+#define LUAI_TRY(L,c,a)if(setjmp((c)->b)==0){a}
+#define lua_pclose(L,file)((void)((void)L,file),0)
+#define lua_upvalueindex(i)((-10002)-(i))
+typedef struct lua_State lua_State;
+typedef int(*lua_CFunction)(lua_State*L);
+typedef const char*(*lua_Reader)(lua_State*L,void*ud,size_t*sz);
+typedef void*(*lua_Alloc)(void*ud,void*ptr,size_t osize,size_t nsize);
+typedef double lua_Number;
+typedef ptrdiff_t lua_Integer;
+static void lua_settop(lua_State*L,int idx);
+static int lua_type(lua_State*L,int idx);
+static const char* lua_tolstring(lua_State*L,int idx,size_t*len);
+static size_t lua_objlen(lua_State*L,int idx);
+static void lua_pushlstring(lua_State*L,const char*s,size_t l);
+static void lua_pushcclosure(lua_State*L,lua_CFunction fn,int n);
+static void lua_createtable(lua_State*L,int narr,int nrec);
+static void lua_setfield(lua_State*L,int idx,const char*k);
+#define lua_pop(L,n)lua_settop(L,-(n)-1)
+#define lua_newtable(L)lua_createtable(L,0,0)
+#define lua_pushcfunction(L,f)lua_pushcclosure(L,(f),0)
+#define lua_strlen(L,i)lua_objlen(L,(i))
+#define lua_isfunction(L,n)(lua_type(L,(n))==6)
+#define lua_istable(L,n)(lua_type(L,(n))==5)
+#define lua_isnil(L,n)(lua_type(L,(n))==0)
+#define lua_isboolean(L,n)(lua_type(L,(n))==1)
+#define lua_isnone(L,n)(lua_type(L,(n))==(-1))
+#define lua_isnoneornil(L,n)(lua_type(L,(n))<=0)
+#define lua_pushliteral(L,s)lua_pushlstring(L,""s,(sizeof(s)/sizeof(char))-1)
+#define lua_setglobal(L,s)lua_setfield(L,(-10002),(s))
+#define lua_tostring(L,i)lua_tolstring(L,(i),NULL)
+typedef struct lua_Debug lua_Debug;
+typedef void(*lua_Hook)(lua_State*L,lua_Debug*ar);
+struct lua_Debug{
+int event;
+const char*name;
+const char*namewhat;
+const char*what;
+const char*source;
+int currentline;
+int nups;
+int linedefined;
+int lastlinedefined;
+char short_src[60];
+int i_ci;
+};
+typedef unsigned int lu_int32;
+typedef size_t lu_mem;
+typedef ptrdiff_t l_mem;
+typedef unsigned char lu_byte;
+#define IntPoint(p)((unsigned int)(lu_mem)(p))
+typedef union{double u;void*s;long l;}L_Umaxalign;
+typedef double l_uacNumber;
+#define check_exp(c,e)(e)
+#define UNUSED(x)((void)(x))
+#define cast(t,exp)((t)(exp))
+#define cast_byte(i)cast(lu_byte,(i))
+#define cast_num(i)cast(lua_Number,(i))
+#define cast_int(i)cast(int,(i))
+typedef lu_int32 Instruction;
+#define condhardstacktests(x)((void)0)
+typedef union GCObject GCObject;
+typedef struct GCheader{
+GCObject*next;lu_byte tt;lu_byte marked;
+}GCheader;
+typedef union{
+GCObject*gc;
+void*p;
+lua_Number n;
+int b;
+}Value;
+typedef struct lua_TValue{
+Value value;int tt;
+}TValue;
+#define ttisnil(o)(ttype(o)==0)
+#define ttisnumber(o)(ttype(o)==3)
+#define ttisstring(o)(ttype(o)==4)
+#define ttistable(o)(ttype(o)==5)
+#define ttisfunction(o)(ttype(o)==6)
+#define ttisboolean(o)(ttype(o)==1)
+#define ttisuserdata(o)(ttype(o)==7)
+#define ttisthread(o)(ttype(o)==8)
+#define ttislightuserdata(o)(ttype(o)==2)
+#define ttype(o)((o)->tt)
+#define gcvalue(o)check_exp(iscollectable(o),(o)->value.gc)
+#define pvalue(o)check_exp(ttislightuserdata(o),(o)->value.p)
+#define nvalue(o)check_exp(ttisnumber(o),(o)->value.n)
+#define rawtsvalue(o)check_exp(ttisstring(o),&(o)->value.gc->ts)
+#define tsvalue(o)(&rawtsvalue(o)->tsv)
+#define rawuvalue(o)check_exp(ttisuserdata(o),&(o)->value.gc->u)
+#define uvalue(o)(&rawuvalue(o)->uv)
+#define clvalue(o)check_exp(ttisfunction(o),&(o)->value.gc->cl)
+#define hvalue(o)check_exp(ttistable(o),&(o)->value.gc->h)
+#define bvalue(o)check_exp(ttisboolean(o),(o)->value.b)
+#define thvalue(o)check_exp(ttisthread(o),&(o)->value.gc->th)
+#define l_isfalse(o)(ttisnil(o)||(ttisboolean(o)&&bvalue(o)==0))
+#define checkconsistency(obj)
+#define checkliveness(g,obj)
+#define setnilvalue(obj)((obj)->tt=0)
+#define setnvalue(obj,x){TValue*i_o=(obj);i_o->value.n=(x);i_o->tt=3;}
+#define setbvalue(obj,x){TValue*i_o=(obj);i_o->value.b=(x);i_o->tt=1;}
+#define setsvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=4;checkliveness(G(L),i_o);}
+#define setuvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=7;checkliveness(G(L),i_o);}
+#define setthvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=8;checkliveness(G(L),i_o);}
+#define setclvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=6;checkliveness(G(L),i_o);}
+#define sethvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=5;checkliveness(G(L),i_o);}
+#define setptvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=(8+1);checkliveness(G(L),i_o);}
+#define setobj(L,obj1,obj2){const TValue*o2=(obj2);TValue*o1=(obj1);o1->value=o2->value;o1->tt=o2->tt;checkliveness(G(L),o1);}
+#define setttype(obj,tt)(ttype(obj)=(tt))
+#define iscollectable(o)(ttype(o)>=4)
+typedef TValue*StkId;
+typedef union TString{
+L_Umaxalign dummy;
+struct{
+GCObject*next;lu_byte tt;lu_byte marked;
+lu_byte reserved;
+unsigned int hash;
+size_t len;
+}tsv;
+}TString;
+#define getstr(ts)cast(const char*,(ts)+1)
+#define svalue(o)getstr(rawtsvalue(o))
+typedef union Udata{
+L_Umaxalign dummy;
+struct{
+GCObject*next;lu_byte tt;lu_byte marked;
+struct Table*metatable;
+struct Table*env;
+size_t len;
+}uv;
+}Udata;
+typedef struct Proto{
+GCObject*next;lu_byte tt;lu_byte marked;
+TValue*k;
+Instruction*code;
+struct Proto**p;
+int*lineinfo;
+struct LocVar*locvars;
+TString**upvalues;
+TString*source;
+int sizeupvalues;
+int sizek;
+int sizecode;
+int sizelineinfo;
+int sizep;
+int sizelocvars;
+int linedefined;
+int lastlinedefined;
+GCObject*gclist;
+lu_byte nups;
+lu_byte numparams;
+lu_byte is_vararg;
+lu_byte maxstacksize;
+}Proto;
+typedef struct LocVar{
+TString*varname;
+int startpc;
+int endpc;
+}LocVar;
+typedef struct UpVal{
+GCObject*next;lu_byte tt;lu_byte marked;
+TValue*v;
+union{
+TValue value;
+struct{
+struct UpVal*prev;
+struct UpVal*next;
+}l;
+}u;
+}UpVal;
+typedef struct CClosure{
+GCObject*next;lu_byte tt;lu_byte marked;lu_byte isC;lu_byte nupvalues;GCObject*gclist;struct Table*env;
+lua_CFunction f;
+TValue upvalue[1];
+}CClosure;
+typedef struct LClosure{
+GCObject*next;lu_byte tt;lu_byte marked;lu_byte isC;lu_byte nupvalues;GCObject*gclist;struct Table*env;
+struct Proto*p;
+UpVal*upvals[1];
+}LClosure;
+typedef union Closure{
+CClosure c;
+LClosure l;
+}Closure;
+#define iscfunction(o)(ttype(o)==6&&clvalue(o)->c.isC)
+typedef union TKey{
+struct{
+Value value;int tt;
+struct Node*next;
+}nk;
+TValue tvk;
+}TKey;
+typedef struct Node{
+TValue i_val;
+TKey i_key;
+}Node;
+typedef struct Table{
+GCObject*next;lu_byte tt;lu_byte marked;
+lu_byte flags;
+lu_byte lsizenode;
+struct Table*metatable;
+TValue*array;
+Node*node;
+Node*lastfree;
+GCObject*gclist;
+int sizearray;
+}Table;
+#define lmod(s,size)(check_exp((size&(size-1))==0,(cast(int,(s)&((size)-1)))))
+#define twoto(x)((size_t)1<<(x))
+#define sizenode(t)(twoto((t)->lsizenode))
+static const TValue luaO_nilobject_;
+#define ceillog2(x)(luaO_log2((x)-1)+1)
+static int luaO_log2(unsigned int x);
+#define gfasttm(g,et,e)((et)==NULL?NULL:((et)->flags&(1u<<(e)))?NULL:luaT_gettm(et,e,(g)->tmname[e]))
+#define fasttm(l,et,e)gfasttm(G(l),et,e)
+static const TValue*luaT_gettm(Table*events,TMS event,TString*ename);
+#define luaM_reallocv(L,b,on,n,e)((cast(size_t,(n)+1)<=((size_t)(~(size_t)0)-2)/(e))?luaM_realloc_(L,(b),(on)*(e),(n)*(e)):luaM_toobig(L))
+#define luaM_freemem(L,b,s)luaM_realloc_(L,(b),(s),0)
+#define luaM_free(L,b)luaM_realloc_(L,(b),sizeof(*(b)),0)
+#define luaM_freearray(L,b,n,t)luaM_reallocv(L,(b),n,0,sizeof(t))
+#define luaM_malloc(L,t)luaM_realloc_(L,NULL,0,(t))
+#define luaM_new(L,t)cast(t*,luaM_malloc(L,sizeof(t)))
+#define luaM_newvector(L,n,t)cast(t*,luaM_reallocv(L,NULL,0,n,sizeof(t)))
+#define luaM_growvector(L,v,nelems,size,t,limit,e)if((nelems)+1>(size))((v)=cast(t*,luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))
+#define luaM_reallocvector(L,v,oldn,n,t)((v)=cast(t*,luaM_reallocv(L,v,oldn,n,sizeof(t))))
+static void*luaM_realloc_(lua_State*L,void*block,size_t oldsize,
+size_t size);
+static void*luaM_toobig(lua_State*L);
+static void*luaM_growaux_(lua_State*L,void*block,int*size,
+size_t size_elem,int limit,
+const char*errormsg);
+typedef struct Zio ZIO;
+#define char2int(c)cast(int,cast(unsigned char,(c)))
+#define zgetc(z)(((z)->n--)>0?char2int(*(z)->p++):luaZ_fill(z))
+typedef struct Mbuffer{
+char*buffer;
+size_t n;
+size_t buffsize;
+}Mbuffer;
+#define luaZ_initbuffer(L,buff)((buff)->buffer=NULL,(buff)->buffsize=0)
+#define luaZ_buffer(buff)((buff)->buffer)
+#define luaZ_sizebuffer(buff)((buff)->buffsize)
+#define luaZ_bufflen(buff)((buff)->n)
+#define luaZ_resetbuffer(buff)((buff)->n=0)
+#define luaZ_resizebuffer(L,buff,size)(luaM_reallocvector(L,(buff)->buffer,(buff)->buffsize,size,char),(buff)->buffsize=size)
+#define luaZ_freebuffer(L,buff)luaZ_resizebuffer(L,buff,0)
+struct Zio{
+size_t n;
+const char*p;
+lua_Reader reader;
+void*data;
+lua_State*L;
+};
+static int luaZ_fill(ZIO*z);
+struct lua_longjmp;
+#define gt(L)(&L->l_gt)
+#define registry(L)(&G(L)->l_registry)
+typedef struct stringtable{
+GCObject**hash;
+lu_int32 nuse;
+int size;
+}stringtable;
+typedef struct CallInfo{
+StkId base;
+StkId func;
+StkId top;
+const Instruction*savedpc;
+int nresults;
+int tailcalls;
+}CallInfo;
+#define curr_func(L)(clvalue(L->ci->func))
+#define ci_func(ci)(clvalue((ci)->func))
+#define f_isLua(ci)(!ci_func(ci)->c.isC)
+#define isLua(ci)(ttisfunction((ci)->func)&&f_isLua(ci))
+typedef struct global_State{
+stringtable strt;
+lua_Alloc frealloc;
+void*ud;
+lu_byte currentwhite;
+lu_byte gcstate;
+int sweepstrgc;
+GCObject*rootgc;
+GCObject**sweepgc;
+GCObject*gray;
+GCObject*grayagain;
+GCObject*weak;
+GCObject*tmudata;
+Mbuffer buff;
+lu_mem GCthreshold;
+lu_mem totalbytes;
+lu_mem estimate;
+lu_mem gcdept;
+int gcpause;
+int gcstepmul;
+lua_CFunction panic;
+TValue l_registry;
+struct lua_State*mainthread;
+UpVal uvhead;
+struct Table*mt[(8+1)];
+TString*tmname[TM_N];
+}global_State;
+struct lua_State{
+GCObject*next;lu_byte tt;lu_byte marked;
+lu_byte status;
+StkId top;
+StkId base;
+global_State*l_G;
+CallInfo*ci;
+const Instruction*savedpc;
+StkId stack_last;
+StkId stack;
+CallInfo*end_ci;
+CallInfo*base_ci;
+int stacksize;
+int size_ci;
+unsigned short nCcalls;
+unsigned short baseCcalls;
+lu_byte hookmask;
+lu_byte allowhook;
+int basehookcount;
+int hookcount;
+lua_Hook hook;
+TValue l_gt;
+TValue env;
+GCObject*openupval;
+GCObject*gclist;
+struct lua_longjmp*errorJmp;
+ptrdiff_t errfunc;
+};
+#define G(L)(L->l_G)
+union GCObject{
+GCheader gch;
+union TString ts;
+union Udata u;
+union Closure cl;
+struct Table h;
+struct Proto p;
+struct UpVal uv;
+struct lua_State th;
+};
+#define rawgco2ts(o)check_exp((o)->gch.tt==4,&((o)->ts))
+#define gco2ts(o)(&rawgco2ts(o)->tsv)
+#define rawgco2u(o)check_exp((o)->gch.tt==7,&((o)->u))
+#define gco2u(o)(&rawgco2u(o)->uv)
+#define gco2cl(o)check_exp((o)->gch.tt==6,&((o)->cl))
+#define gco2h(o)check_exp((o)->gch.tt==5,&((o)->h))
+#define gco2p(o)check_exp((o)->gch.tt==(8+1),&((o)->p))
+#define gco2uv(o)check_exp((o)->gch.tt==(8+2),&((o)->uv))
+#define ngcotouv(o)check_exp((o)==NULL||(o)->gch.tt==(8+2),&((o)->uv))
+#define gco2th(o)check_exp((o)->gch.tt==8,&((o)->th))
+#define obj2gco(v)(cast(GCObject*,(v)))
+static void luaE_freethread(lua_State*L,lua_State*L1);
+#define pcRel(pc,p)(cast(int,(pc)-(p)->code)-1)
+#define getline_(f,pc)(((f)->lineinfo)?(f)->lineinfo[pc]:0)
+#define resethookcount(L)(L->hookcount=L->basehookcount)
+static void luaG_typeerror(lua_State*L,const TValue*o,
+const char*opname);
+static void luaG_runerror(lua_State*L,const char*fmt,...);
+#define luaD_checkstack(L,n)if((char*)L->stack_last-(char*)L->top<=(n)*(int)sizeof(TValue))luaD_growstack(L,n);else condhardstacktests(luaD_reallocstack(L,L->stacksize-5-1));
+#define incr_top(L){luaD_checkstack(L,1);L->top++;}
+#define savestack(L,p)((char*)(p)-(char*)L->stack)
+#define restorestack(L,n)((TValue*)((char*)L->stack+(n)))
+#define saveci(L,p)((char*)(p)-(char*)L->base_ci)
+#define restoreci(L,n)((CallInfo*)((char*)L->base_ci+(n)))
+typedef void(*Pfunc)(lua_State*L,void*ud);
+static int luaD_poscall(lua_State*L,StkId firstResult);
+static void luaD_reallocCI(lua_State*L,int newsize);
+static void luaD_reallocstack(lua_State*L,int newsize);
+static void luaD_growstack(lua_State*L,int n);
+static void luaD_throw(lua_State*L,int errcode);
+static void*luaM_growaux_(lua_State*L,void*block,int*size,size_t size_elems,
+int limit,const char*errormsg){
+void*newblock;
+int newsize;
+if(*size>=limit/2){
+if(*size>=limit)
+luaG_runerror(L,errormsg);
+newsize=limit;
+}
+else{
+newsize=(*size)*2;
+if(newsize<4)
+newsize=4;
+}
+newblock=luaM_reallocv(L,block,*size,newsize,size_elems);
+*size=newsize;
+return newblock;
+}
+static void*luaM_toobig(lua_State*L){
+luaG_runerror(L,"memory allocation error: block too big");
+return NULL;
+}
+static void*luaM_realloc_(lua_State*L,void*block,size_t osize,size_t nsize){
+global_State*g=G(L);
+block=(*g->frealloc)(g->ud,block,osize,nsize);
+if(block==NULL&&nsize>0)
+luaD_throw(L,4);
+g->totalbytes=(g->totalbytes-osize)+nsize;
+return block;
+}
+#define resetbits(x,m)((x)&=cast(lu_byte,~(m)))
+#define setbits(x,m)((x)|=(m))
+#define testbits(x,m)((x)&(m))
+#define bitmask(b)(1<<(b))
+#define bit2mask(b1,b2)(bitmask(b1)|bitmask(b2))
+#define l_setbit(x,b)setbits(x,bitmask(b))
+#define resetbit(x,b)resetbits(x,bitmask(b))
+#define testbit(x,b)testbits(x,bitmask(b))
+#define set2bits(x,b1,b2)setbits(x,(bit2mask(b1,b2)))
+#define reset2bits(x,b1,b2)resetbits(x,(bit2mask(b1,b2)))
+#define test2bits(x,b1,b2)testbits(x,(bit2mask(b1,b2)))
+#define iswhite(x)test2bits((x)->gch.marked,0,1)
+#define isblack(x)testbit((x)->gch.marked,2)
+#define isgray(x)(!isblack(x)&&!iswhite(x))
+#define otherwhite(g)(g->currentwhite^bit2mask(0,1))
+#define isdead(g,v)((v)->gch.marked&otherwhite(g)&bit2mask(0,1))
+#define changewhite(x)((x)->gch.marked^=bit2mask(0,1))
+#define gray2black(x)l_setbit((x)->gch.marked,2)
+#define valiswhite(x)(iscollectable(x)&&iswhite(gcvalue(x)))
+#define luaC_white(g)cast(lu_byte,(g)->currentwhite&bit2mask(0,1))
+#define luaC_checkGC(L){condhardstacktests(luaD_reallocstack(L,L->stacksize-5-1));if(G(L)->totalbytes>=G(L)->GCthreshold)luaC_step(L);}
+#define luaC_barrier(L,p,v){if(valiswhite(v)&&isblack(obj2gco(p)))luaC_barrierf(L,obj2gco(p),gcvalue(v));}
+#define luaC_barriert(L,t,v){if(valiswhite(v)&&isblack(obj2gco(t)))luaC_barrierback(L,t);}
+#define luaC_objbarrier(L,p,o){if(iswhite(obj2gco(o))&&isblack(obj2gco(p)))luaC_barrierf(L,obj2gco(p),obj2gco(o));}
+#define luaC_objbarriert(L,t,o){if(iswhite(obj2gco(o))&&isblack(obj2gco(t)))luaC_barrierback(L,t);}
+static void luaC_step(lua_State*L);
+static void luaC_link(lua_State*L,GCObject*o,lu_byte tt);
+static void luaC_linkupval(lua_State*L,UpVal*uv);
+static void luaC_barrierf(lua_State*L,GCObject*o,GCObject*v);
+static void luaC_barrierback(lua_State*L,Table*t);
+#define sizestring(s)(sizeof(union TString)+((s)->len+1)*sizeof(char))
+#define sizeudata(u)(sizeof(union Udata)+(u)->len)
+#define luaS_new(L,s)(luaS_newlstr(L,s,strlen(s)))
+#define luaS_newliteral(L,s)(luaS_newlstr(L,""s,(sizeof(s)/sizeof(char))-1))
+#define luaS_fix(s)l_setbit((s)->tsv.marked,5)
+static TString*luaS_newlstr(lua_State*L,const char*str,size_t l);
+#define tostring(L,o)((ttype(o)==4)||(luaV_tostring(L,o)))
+#define tonumber(o,n)(ttype(o)==3||(((o)=luaV_tonumber(o,n))!=NULL))
+#define equalobj(L,o1,o2)(ttype(o1)==ttype(o2)&&luaV_equalval(L,o1,o2))
+static int luaV_equalval(lua_State*L,const TValue*t1,const TValue*t2);
+static const TValue*luaV_tonumber(const TValue*obj,TValue*n);
+static int luaV_tostring(lua_State*L,StkId obj);
+static void luaV_execute(lua_State*L,int nexeccalls);
+static void luaV_concat(lua_State*L,int total,int last);
+static const TValue luaO_nilobject_={{NULL},0};
+static int luaO_int2fb(unsigned int x){
+int e=0;
+while(x>=16){
+x=(x+1)>>1;
+e++;
+}
+if(x<8)return x;
+else return((e+1)<<3)|(cast_int(x)-8);
+}
+static int luaO_fb2int(int x){
+int e=(x>>3)&31;
+if(e==0)return x;
+else return((x&7)+8)<<(e-1);
+}
+static int luaO_log2(unsigned int x){
+static const lu_byte log_2[256]={
+0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
+7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
+7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
+8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
+8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
+8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
+8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
+};
+int l=-1;
+while(x>=256){l+=8;x>>=8;}
+return l+log_2[x];
+}
+static int luaO_rawequalObj(const TValue*t1,const TValue*t2){
+if(ttype(t1)!=ttype(t2))return 0;
+else switch(ttype(t1)){
+case 0:
+return 1;
+case 3:
+return luai_numeq(nvalue(t1),nvalue(t2));
+case 1:
+return bvalue(t1)==bvalue(t2);
+case 2:
+return pvalue(t1)==pvalue(t2);
+default:
+return gcvalue(t1)==gcvalue(t2);
+}
+}
+static int luaO_str2d(const char*s,lua_Number*result){
+char*endptr;
+*result=lua_str2number(s,&endptr);
+if(endptr==s)return 0;
+if(*endptr=='x'||*endptr=='X')
+*result=cast_num(strtoul(s,&endptr,16));
+if(*endptr=='\0')return 1;
+while(isspace(cast(unsigned char,*endptr)))endptr++;
+if(*endptr!='\0')return 0;
+return 1;
+}
+static void pushstr(lua_State*L,const char*str){
+setsvalue(L,L->top,luaS_new(L,str));
+incr_top(L);
+}
+static const char*luaO_pushvfstring(lua_State*L,const char*fmt,va_list argp){
+int n=1;
+pushstr(L,"");
+for(;;){
+const char*e=strchr(fmt,'%');
+if(e==NULL)break;
+setsvalue(L,L->top,luaS_newlstr(L,fmt,e-fmt));
+incr_top(L);
+switch(*(e+1)){
+case's':{
+const char*s=va_arg(argp,char*);
+if(s==NULL)s="(null)";
+pushstr(L,s);
+break;
+}
+case'c':{
+char buff[2];
+buff[0]=cast(char,va_arg(argp,int));
+buff[1]='\0';
+pushstr(L,buff);
+break;
+}
+case'd':{
+setnvalue(L->top,cast_num(va_arg(argp,int)));
+incr_top(L);
+break;
+}
+case'f':{
+setnvalue(L->top,cast_num(va_arg(argp,l_uacNumber)));
+incr_top(L);
+break;
+}
+case'p':{
+char buff[4*sizeof(void*)+8];
+sprintf(buff,"%p",va_arg(argp,void*));
+pushstr(L,buff);
+break;
+}
+case'%':{
+pushstr(L,"%");
+break;
+}
+default:{
+char buff[3];
+buff[0]='%';
+buff[1]=*(e+1);
+buff[2]='\0';
+pushstr(L,buff);
+break;
+}
+}
+n+=2;
+fmt=e+2;
+}
+pushstr(L,fmt);
+luaV_concat(L,n+1,cast_int(L->top-L->base)-1);
+L->top-=n;
+return svalue(L->top-1);
+}
+static const char*luaO_pushfstring(lua_State*L,const char*fmt,...){
+const char*msg;
+va_list argp;
+va_start(argp,fmt);
+msg=luaO_pushvfstring(L,fmt,argp);
+va_end(argp);
+return msg;
+}
+static void luaO_chunkid(char*out,const char*source,size_t bufflen){
+if(*source=='='){
+strncpy(out,source+1,bufflen);
+out[bufflen-1]='\0';
+}
+else{
+if(*source=='@'){
+size_t l;
+source++;
+bufflen-=sizeof(" '...' ");
+l=strlen(source);
+strcpy(out,"");
+if(l>bufflen){
+source+=(l-bufflen);
+strcat(out,"...");
+}
+strcat(out,source);
+}
+else{
+size_t len=strcspn(source,"\n\r");
+bufflen-=sizeof(" [string \"...\"] ");
+if(len>bufflen)len=bufflen;
+strcpy(out,"[string \"");
+if(source[len]!='\0'){
+strncat(out,source,len);
+strcat(out,"...");
+}
+else
+strcat(out,source);
+strcat(out,"\"]");
+}
+}
+}
+#define gnode(t,i)(&(t)->node[i])
+#define gkey(n)(&(n)->i_key.nk)
+#define gval(n)(&(n)->i_val)
+#define gnext(n)((n)->i_key.nk.next)
+#define key2tval(n)(&(n)->i_key.tvk)
+static TValue*luaH_setnum(lua_State*L,Table*t,int key);
+static const TValue*luaH_getstr(Table*t,TString*key);
+static TValue*luaH_set(lua_State*L,Table*t,const TValue*key);
+static const char*const luaT_typenames[]={
+"nil","boolean","userdata","number",
+"string","table","function","userdata","thread",
+"proto","upval"
+};
+static void luaT_init(lua_State*L){
+static const char*const luaT_eventname[]={
+"__index","__newindex",
+"__gc","__mode","__eq",
+"__add","__sub","__mul","__div","__mod",
+"__pow","__unm","__len","__lt","__le",
+"__concat","__call"
+};
+int i;
+for(i=0;i<TM_N;i++){
+G(L)->tmname[i]=luaS_new(L,luaT_eventname[i]);
+luaS_fix(G(L)->tmname[i]);
+}
+}
+static const TValue*luaT_gettm(Table*events,TMS event,TString*ename){
+const TValue*tm=luaH_getstr(events,ename);
+if(ttisnil(tm)){
+events->flags|=cast_byte(1u<<event);
+return NULL;
+}
+else return tm;
+}
+static const TValue*luaT_gettmbyobj(lua_State*L,const TValue*o,TMS event){
+Table*mt;
+switch(ttype(o)){
+case 5:
+mt=hvalue(o)->metatable;
+break;
+case 7:
+mt=uvalue(o)->metatable;
+break;
+default:
+mt=G(L)->mt[ttype(o)];
+}
+return(mt?luaH_getstr(mt,G(L)->tmname[event]):(&luaO_nilobject_));
+}
+#define sizeCclosure(n)(cast(int,sizeof(CClosure))+cast(int,sizeof(TValue)*((n)-1)))
+#define sizeLclosure(n)(cast(int,sizeof(LClosure))+cast(int,sizeof(TValue*)*((n)-1)))
+static Closure*luaF_newCclosure(lua_State*L,int nelems,Table*e){
+Closure*c=cast(Closure*,luaM_malloc(L,sizeCclosure(nelems)));
+luaC_link(L,obj2gco(c),6);
+c->c.isC=1;
+c->c.env=e;
+c->c.nupvalues=cast_byte(nelems);
+return c;
+}
+static Closure*luaF_newLclosure(lua_State*L,int nelems,Table*e){
+Closure*c=cast(Closure*,luaM_malloc(L,sizeLclosure(nelems)));
+luaC_link(L,obj2gco(c),6);
+c->l.isC=0;
+c->l.env=e;
+c->l.nupvalues=cast_byte(nelems);
+while(nelems--)c->l.upvals[nelems]=NULL;
+return c;
+}
+static UpVal*luaF_newupval(lua_State*L){
+UpVal*uv=luaM_new(L,UpVal);
+luaC_link(L,obj2gco(uv),(8+2));
+uv->v=&uv->u.value;
+setnilvalue(uv->v);
+return uv;
+}
+static UpVal*luaF_findupval(lua_State*L,StkId level){
+global_State*g=G(L);
+GCObject**pp=&L->openupval;
+UpVal*p;
+UpVal*uv;
+while(*pp!=NULL&&(p=ngcotouv(*pp))->v>=level){
+if(p->v==level){
+if(isdead(g,obj2gco(p)))
+changewhite(obj2gco(p));
+return p;
+}
+pp=&p->next;
+}
+uv=luaM_new(L,UpVal);
+uv->tt=(8+2);
+uv->marked=luaC_white(g);
+uv->v=level;
+uv->next=*pp;
+*pp=obj2gco(uv);
+uv->u.l.prev=&g->uvhead;
+uv->u.l.next=g->uvhead.u.l.next;
+uv->u.l.next->u.l.prev=uv;
+g->uvhead.u.l.next=uv;
+return uv;
+}
+static void unlinkupval(UpVal*uv){
+uv->u.l.next->u.l.prev=uv->u.l.prev;
+uv->u.l.prev->u.l.next=uv->u.l.next;
+}
+static void luaF_freeupval(lua_State*L,UpVal*uv){
+if(uv->v!=&uv->u.value)
+unlinkupval(uv);
+luaM_free(L,uv);
+}
+static void luaF_close(lua_State*L,StkId level){
+UpVal*uv;
+global_State*g=G(L);
+while(L->openupval!=NULL&&(uv=ngcotouv(L->openupval))->v>=level){
+GCObject*o=obj2gco(uv);
+L->openupval=uv->next;
+if(isdead(g,o))
+luaF_freeupval(L,uv);
+else{
+unlinkupval(uv);
+setobj(L,&uv->u.value,uv->v);
+uv->v=&uv->u.value;
+luaC_linkupval(L,uv);
+}
+}
+}
+static Proto*luaF_newproto(lua_State*L){
+Proto*f=luaM_new(L,Proto);
+luaC_link(L,obj2gco(f),(8+1));
+f->k=NULL;
+f->sizek=0;
+f->p=NULL;
+f->sizep=0;
+f->code=NULL;
+f->sizecode=0;
+f->sizelineinfo=0;
+f->sizeupvalues=0;
+f->nups=0;
+f->upvalues=NULL;
+f->numparams=0;
+f->is_vararg=0;
+f->maxstacksize=0;
+f->lineinfo=NULL;
+f->sizelocvars=0;
+f->locvars=NULL;
+f->linedefined=0;
+f->lastlinedefined=0;
+f->source=NULL;
+return f;
+}
+static void luaF_freeproto(lua_State*L,Proto*f){
+luaM_freearray(L,f->code,f->sizecode,Instruction);
+luaM_freearray(L,f->p,f->sizep,Proto*);
+luaM_freearray(L,f->k,f->sizek,TValue);
+luaM_freearray(L,f->lineinfo,f->sizelineinfo,int);
+luaM_freearray(L,f->locvars,f->sizelocvars,struct LocVar);
+luaM_freearray(L,f->upvalues,f->sizeupvalues,TString*);
+luaM_free(L,f);
+}
+static void luaF_freeclosure(lua_State*L,Closure*c){
+int size=(c->c.isC)?sizeCclosure(c->c.nupvalues):
+sizeLclosure(c->l.nupvalues);
+luaM_freemem(L,c,size);
+}
+#define MASK1(n,p)((~((~(Instruction)0)<<n))<<p)
+#define MASK0(n,p)(~MASK1(n,p))
+#define GET_OPCODE(i)(cast(OpCode,((i)>>0)&MASK1(6,0)))
+#define SET_OPCODE(i,o)((i)=(((i)&MASK0(6,0))|((cast(Instruction,o)<<0)&MASK1(6,0))))
+#define GETARG_A(i)(cast(int,((i)>>(0+6))&MASK1(8,0)))
+#define SETARG_A(i,u)((i)=(((i)&MASK0(8,(0+6)))|((cast(Instruction,u)<<(0+6))&MASK1(8,(0+6)))))
+#define GETARG_B(i)(cast(int,((i)>>(((0+6)+8)+9))&MASK1(9,0)))
+#define SETARG_B(i,b)((i)=(((i)&MASK0(9,(((0+6)+8)+9)))|((cast(Instruction,b)<<(((0+6)+8)+9))&MASK1(9,(((0+6)+8)+9)))))
+#define GETARG_C(i)(cast(int,((i)>>((0+6)+8))&MASK1(9,0)))
+#define SETARG_C(i,b)((i)=(((i)&MASK0(9,((0+6)+8)))|((cast(Instruction,b)<<((0+6)+8))&MASK1(9,((0+6)+8)))))
+#define GETARG_Bx(i)(cast(int,((i)>>((0+6)+8))&MASK1((9+9),0)))
+#define SETARG_Bx(i,b)((i)=(((i)&MASK0((9+9),((0+6)+8)))|((cast(Instruction,b)<<((0+6)+8))&MASK1((9+9),((0+6)+8)))))
+#define GETARG_sBx(i)(GETARG_Bx(i)-(((1<<(9+9))-1)>>1))
+#define SETARG_sBx(i,b)SETARG_Bx((i),cast(unsigned int,(b)+(((1<<(9+9))-1)>>1)))
+#define CREATE_ABC(o,a,b,c)((cast(Instruction,o)<<0)|(cast(Instruction,a)<<(0+6))|(cast(Instruction,b)<<(((0+6)+8)+9))|(cast(Instruction,c)<<((0+6)+8)))
+#define CREATE_ABx(o,a,bc)((cast(Instruction,o)<<0)|(cast(Instruction,a)<<(0+6))|(cast(Instruction,bc)<<((0+6)+8)))
+#define ISK(x)((x)&(1<<(9-1)))
+#define INDEXK(r)((int)(r)&~(1<<(9-1)))
+#define RKASK(x)((x)|(1<<(9-1)))
+static const lu_byte luaP_opmodes[(cast(int,OP_VARARG)+1)];
+#define getBMode(m)(cast(enum OpArgMask,(luaP_opmodes[m]>>4)&3))
+#define getCMode(m)(cast(enum OpArgMask,(luaP_opmodes[m]>>2)&3))
+#define testTMode(m)(luaP_opmodes[m]&(1<<7))
+typedef struct expdesc{
+expkind k;
+union{
+struct{int info,aux;}s;
+lua_Number nval;
+}u;
+int t;
+int f;
+}expdesc;
+typedef struct upvaldesc{
+lu_byte k;
+lu_byte info;
+}upvaldesc;
+struct BlockCnt;
+typedef struct FuncState{
+Proto*f;
+Table*h;
+struct FuncState*prev;
+struct LexState*ls;
+struct lua_State*L;
+struct BlockCnt*bl;
+int pc;
+int lasttarget;
+int jpc;
+int freereg;
+int nk;
+int np;
+short nlocvars;
+lu_byte nactvar;
+upvaldesc upvalues[60];
+unsigned short actvar[200];
+}FuncState;
+static Proto*luaY_parser(lua_State*L,ZIO*z,Mbuffer*buff,
+const char*name);
+struct lua_longjmp{
+struct lua_longjmp*previous;
+jmp_buf b;
+volatile int status;
+};
+static void luaD_seterrorobj(lua_State*L,int errcode,StkId oldtop){
+switch(errcode){
+case 4:{
+setsvalue(L,oldtop,luaS_newliteral(L,"not enough memory"));
+break;
+}
+case 5:{
+setsvalue(L,oldtop,luaS_newliteral(L,"error in error handling"));
+break;
+}
+case 3:
+case 2:{
+setobj(L,oldtop,L->top-1);
+break;
+}
+}
+L->top=oldtop+1;
+}
+static void restore_stack_limit(lua_State*L){
+if(L->size_ci>20000){
+int inuse=cast_int(L->ci-L->base_ci);
+if(inuse+1<20000)
+luaD_reallocCI(L,20000);
+}
+}
+static void resetstack(lua_State*L,int status){
+L->ci=L->base_ci;
+L->base=L->ci->base;
+luaF_close(L,L->base);
+luaD_seterrorobj(L,status,L->base);
+L->nCcalls=L->baseCcalls;
+L->allowhook=1;
+restore_stack_limit(L);
+L->errfunc=0;
+L->errorJmp=NULL;
+}
+static void luaD_throw(lua_State*L,int errcode){
+if(L->errorJmp){
+L->errorJmp->status=errcode;
+LUAI_THROW(L,L->errorJmp);
+}
+else{
+L->status=cast_byte(errcode);
+if(G(L)->panic){
+resetstack(L,errcode);
+G(L)->panic(L);
+}
+exit(EXIT_FAILURE);
+}
+}
+static int luaD_rawrunprotected(lua_State*L,Pfunc f,void*ud){
+struct lua_longjmp lj;
+lj.status=0;
+lj.previous=L->errorJmp;
+L->errorJmp=&lj;
+LUAI_TRY(L,&lj,
+(*f)(L,ud);
+);
+L->errorJmp=lj.previous;
+return lj.status;
+}
+static void correctstack(lua_State*L,TValue*oldstack){
+CallInfo*ci;
+GCObject*up;
+L->top=(L->top-oldstack)+L->stack;
+for(up=L->openupval;up!=NULL;up=up->gch.next)
+gco2uv(up)->v=(gco2uv(up)->v-oldstack)+L->stack;
+for(ci=L->base_ci;ci<=L->ci;ci++){
+ci->top=(ci->top-oldstack)+L->stack;
+ci->base=(ci->base-oldstack)+L->stack;
+ci->func=(ci->func-oldstack)+L->stack;
+}
+L->base=(L->base-oldstack)+L->stack;
+}
+static void luaD_reallocstack(lua_State*L,int newsize){
+TValue*oldstack=L->stack;
+int realsize=newsize+1+5;
+luaM_reallocvector(L,L->stack,L->stacksize,realsize,TValue);
+L->stacksize=realsize;
+L->stack_last=L->stack+newsize;
+correctstack(L,oldstack);
+}
+static void luaD_reallocCI(lua_State*L,int newsize){
+CallInfo*oldci=L->base_ci;
+luaM_reallocvector(L,L->base_ci,L->size_ci,newsize,CallInfo);
+L->size_ci=newsize;
+L->ci=(L->ci-oldci)+L->base_ci;
+L->end_ci=L->base_ci+L->size_ci-1;
+}
+static void luaD_growstack(lua_State*L,int n){
+if(n<=L->stacksize)
+luaD_reallocstack(L,2*L->stacksize);
+else
+luaD_reallocstack(L,L->stacksize+n);
+}
+static CallInfo*growCI(lua_State*L){
+if(L->size_ci>20000)
+luaD_throw(L,5);
+else{
+luaD_reallocCI(L,2*L->size_ci);
+if(L->size_ci>20000)
+luaG_runerror(L,"stack overflow");
+}
+return++L->ci;
+}
+static StkId adjust_varargs(lua_State*L,Proto*p,int actual){
+int i;
+int nfixargs=p->numparams;
+Table*htab=NULL;
+StkId base,fixed;
+for(;actual<nfixargs;++actual)
+setnilvalue(L->top++);
+fixed=L->top-actual;
+base=L->top;
+for(i=0;i<nfixargs;i++){
+setobj(L,L->top++,fixed+i);
+setnilvalue(fixed+i);
+}
+if(htab){
+sethvalue(L,L->top++,htab);
+}
+return base;
+}
+static StkId tryfuncTM(lua_State*L,StkId func){
+const TValue*tm=luaT_gettmbyobj(L,func,TM_CALL);
+StkId p;
+ptrdiff_t funcr=savestack(L,func);
+if(!ttisfunction(tm))
+luaG_typeerror(L,func,"call");
+for(p=L->top;p>func;p--)setobj(L,p,p-1);
+incr_top(L);
+func=restorestack(L,funcr);
+setobj(L,func,tm);
+return func;
+}
+#define inc_ci(L)((L->ci==L->end_ci)?growCI(L):(condhardstacktests(luaD_reallocCI(L,L->size_ci)),++L->ci))
+static int luaD_precall(lua_State*L,StkId func,int nresults){
+LClosure*cl;
+ptrdiff_t funcr;
+if(!ttisfunction(func))
+func=tryfuncTM(L,func);
+funcr=savestack(L,func);
+cl=&clvalue(func)->l;
+L->ci->savedpc=L->savedpc;
+if(!cl->isC){
+CallInfo*ci;
+StkId st,base;
+Proto*p=cl->p;
+luaD_checkstack(L,p->maxstacksize);
+func=restorestack(L,funcr);
+if(!p->is_vararg){
+base=func+1;
+if(L->top>base+p->numparams)
+L->top=base+p->numparams;
+}
+else{
+int nargs=cast_int(L->top-func)-1;
+base=adjust_varargs(L,p,nargs);
+func=restorestack(L,funcr);
+}
+ci=inc_ci(L);
+ci->func=func;
+L->base=ci->base=base;
+ci->top=L->base+p->maxstacksize;
+L->savedpc=p->code;
+ci->tailcalls=0;
+ci->nresults=nresults;
+for(st=L->top;st<ci->top;st++)
+setnilvalue(st);
+L->top=ci->top;
+return 0;
+}
+else{
+CallInfo*ci;
+int n;
+luaD_checkstack(L,20);
+ci=inc_ci(L);
+ci->func=restorestack(L,funcr);
+L->base=ci->base=ci->func+1;
+ci->top=L->top+20;
+ci->nresults=nresults;
+n=(*curr_func(L)->c.f)(L);
+if(n<0)
+return 2;
+else{
+luaD_poscall(L,L->top-n);
+return 1;
+}
+}
+}
+static int luaD_poscall(lua_State*L,StkId firstResult){
+StkId res;
+int wanted,i;
+CallInfo*ci;
+ci=L->ci--;
+res=ci->func;
+wanted=ci->nresults;
+L->base=(ci-1)->base;
+L->savedpc=(ci-1)->savedpc;
+for(i=wanted;i!=0&&firstResult<L->top;i--)
+setobj(L,res++,firstResult++);
+while(i-->0)
+setnilvalue(res++);
+L->top=res;
+return(wanted-(-1));
+}
+static void luaD_call(lua_State*L,StkId func,int nResults){
+if(++L->nCcalls>=200){
+if(L->nCcalls==200)
+luaG_runerror(L,"C stack overflow");
+else if(L->nCcalls>=(200+(200>>3)))
+luaD_throw(L,5);
+}
+if(luaD_precall(L,func,nResults)==0)
+luaV_execute(L,1);
+L->nCcalls--;
+luaC_checkGC(L);
+}
+static int luaD_pcall(lua_State*L,Pfunc func,void*u,
+ptrdiff_t old_top,ptrdiff_t ef){
+int status;
+unsigned short oldnCcalls=L->nCcalls;
+ptrdiff_t old_ci=saveci(L,L->ci);
+lu_byte old_allowhooks=L->allowhook;
+ptrdiff_t old_errfunc=L->errfunc;
+L->errfunc=ef;
+status=luaD_rawrunprotected(L,func,u);
+if(status!=0){
+StkId oldtop=restorestack(L,old_top);
+luaF_close(L,oldtop);
+luaD_seterrorobj(L,status,oldtop);
+L->nCcalls=oldnCcalls;
+L->ci=restoreci(L,old_ci);
+L->base=L->ci->base;
+L->savedpc=L->ci->savedpc;
+L->allowhook=old_allowhooks;
+restore_stack_limit(L);
+}
+L->errfunc=old_errfunc;
+return status;
+}
+struct SParser{
+ZIO*z;
+Mbuffer buff;
+const char*name;
+};
+static void f_parser(lua_State*L,void*ud){
+int i;
+Proto*tf;
+Closure*cl;
+struct SParser*p=cast(struct SParser*,ud);
+luaC_checkGC(L);
+tf=luaY_parser(L,p->z,
+&p->buff,p->name);
+cl=luaF_newLclosure(L,tf->nups,hvalue(gt(L)));
+cl->l.p=tf;
+for(i=0;i<tf->nups;i++)
+cl->l.upvals[i]=luaF_newupval(L);
+setclvalue(L,L->top,cl);
+incr_top(L);
+}
+static int luaD_protectedparser(lua_State*L,ZIO*z,const char*name){
+struct SParser p;
+int status;
+p.z=z;p.name=name;
+luaZ_initbuffer(L,&p.buff);
+status=luaD_pcall(L,f_parser,&p,savestack(L,L->top),L->errfunc);
+luaZ_freebuffer(L,&p.buff);
+return status;
+}
+static void luaS_resize(lua_State*L,int newsize){
+GCObject**newhash;
+stringtable*tb;
+int i;
+if(G(L)->gcstate==2)
+return;
+newhash=luaM_newvector(L,newsize,GCObject*);
+tb=&G(L)->strt;
+for(i=0;i<newsize;i++)newhash[i]=NULL;
+for(i=0;i<tb->size;i++){
+GCObject*p=tb->hash[i];
+while(p){
+GCObject*next=p->gch.next;
+unsigned int h=gco2ts(p)->hash;
+int h1=lmod(h,newsize);
+p->gch.next=newhash[h1];
+newhash[h1]=p;
+p=next;
+}
+}
+luaM_freearray(L,tb->hash,tb->size,TString*);
+tb->size=newsize;
+tb->hash=newhash;
+}
+static TString*newlstr(lua_State*L,const char*str,size_t l,
+unsigned int h){
+TString*ts;
+stringtable*tb;
+if(l+1>(((size_t)(~(size_t)0)-2)-sizeof(TString))/sizeof(char))
+luaM_toobig(L);
+ts=cast(TString*,luaM_malloc(L,(l+1)*sizeof(char)+sizeof(TString)));
+ts->tsv.len=l;
+ts->tsv.hash=h;
+ts->tsv.marked=luaC_white(G(L));
+ts->tsv.tt=4;
+ts->tsv.reserved=0;
+memcpy(ts+1,str,l*sizeof(char));
+((char*)(ts+1))[l]='\0';
+tb=&G(L)->strt;
+h=lmod(h,tb->size);
+ts->tsv.next=tb->hash[h];
+tb->hash[h]=obj2gco(ts);
+tb->nuse++;
+if(tb->nuse>cast(lu_int32,tb->size)&&tb->size<=(INT_MAX-2)/2)
+luaS_resize(L,tb->size*2);
+return ts;
+}
+static TString*luaS_newlstr(lua_State*L,const char*str,size_t l){
+GCObject*o;
+unsigned int h=cast(unsigned int,l);
+size_t step=(l>>5)+1;
+size_t l1;
+for(l1=l;l1>=step;l1-=step)
+h=h^((h<<5)+(h>>2)+cast(unsigned char,str[l1-1]));
+for(o=G(L)->strt.hash[lmod(h,G(L)->strt.size)];
+o!=NULL;
+o=o->gch.next){
+TString*ts=rawgco2ts(o);
+if(ts->tsv.len==l&&(memcmp(str,getstr(ts),l)==0)){
+if(isdead(G(L),o))changewhite(o);
+return ts;
+}
+}
+return newlstr(L,str,l,h);
+}
+static Udata*luaS_newudata(lua_State*L,size_t s,Table*e){
+Udata*u;
+if(s>((size_t)(~(size_t)0)-2)-sizeof(Udata))
+luaM_toobig(L);
+u=cast(Udata*,luaM_malloc(L,s+sizeof(Udata)));
+u->uv.marked=luaC_white(G(L));
+u->uv.tt=7;
+u->uv.len=s;
+u->uv.metatable=NULL;
+u->uv.env=e;
+u->uv.next=G(L)->mainthread->next;
+G(L)->mainthread->next=obj2gco(u);
+return u;
+}
+#define hashpow2(t,n)(gnode(t,lmod((n),sizenode(t))))
+#define hashstr(t,str)hashpow2(t,(str)->tsv.hash)
+#define hashboolean(t,p)hashpow2(t,p)
+#define hashmod(t,n)(gnode(t,((n)%((sizenode(t)-1)|1))))
+#define hashpointer(t,p)hashmod(t,IntPoint(p))
+static const Node dummynode_={
+{{NULL},0},
+{{{NULL},0,NULL}}
+};
+static Node*hashnum(const Table*t,lua_Number n){
+unsigned int a[cast_int(sizeof(lua_Number)/sizeof(int))];
+int i;
+if(luai_numeq(n,0))
+return gnode(t,0);
+memcpy(a,&n,sizeof(a));
+for(i=1;i<cast_int(sizeof(lua_Number)/sizeof(int));i++)a[0]+=a[i];
+return hashmod(t,a[0]);
+}
+static Node*mainposition(const Table*t,const TValue*key){
+switch(ttype(key)){
+case 3:
+return hashnum(t,nvalue(key));
+case 4:
+return hashstr(t,rawtsvalue(key));
+case 1:
+return hashboolean(t,bvalue(key));
+case 2:
+return hashpointer(t,pvalue(key));
+default:
+return hashpointer(t,gcvalue(key));
+}
+}
+static int arrayindex(const TValue*key){
+if(ttisnumber(key)){
+lua_Number n=nvalue(key);
+int k;
+lua_number2int(k,n);
+if(luai_numeq(cast_num(k),n))
+return k;
+}
+return-1;
+}
+static int findindex(lua_State*L,Table*t,StkId key){
+int i;
+if(ttisnil(key))return-1;
+i=arrayindex(key);
+if(0<i&&i<=t->sizearray)
+return i-1;
+else{
+Node*n=mainposition(t,key);
+do{
+if(luaO_rawequalObj(key2tval(n),key)||
+(ttype(gkey(n))==(8+3)&&iscollectable(key)&&
+gcvalue(gkey(n))==gcvalue(key))){
+i=cast_int(n-gnode(t,0));
+return i+t->sizearray;
+}
+else n=gnext(n);
+}while(n);
+luaG_runerror(L,"invalid key to "LUA_QL("next"));
+return 0;
+}
+}
+static int luaH_next(lua_State*L,Table*t,StkId key){
+int i=findindex(L,t,key);
+for(i++;i<t->sizearray;i++){
+if(!ttisnil(&t->array[i])){
+setnvalue(key,cast_num(i+1));
+setobj(L,key+1,&t->array[i]);
+return 1;
+}
+}
+for(i-=t->sizearray;i<(int)sizenode(t);i++){
+if(!ttisnil(gval(gnode(t,i)))){
+setobj(L,key,key2tval(gnode(t,i)));
+setobj(L,key+1,gval(gnode(t,i)));
+return 1;
+}
+}
+return 0;
+}
+static int computesizes(int nums[],int*narray){
+int i;
+int twotoi;
+int a=0;
+int na=0;
+int n=0;
+for(i=0,twotoi=1;twotoi/2<*narray;i++,twotoi*=2){
+if(nums[i]>0){
+a+=nums[i];
+if(a>twotoi/2){
+n=twotoi;
+na=a;
+}
+}
+if(a==*narray)break;
+}
+*narray=n;
+return na;
+}
+static int countint(const TValue*key,int*nums){
+int k=arrayindex(key);
+if(0<k&&k<=(1<<(32-2))){
+nums[ceillog2(k)]++;
+return 1;
+}
+else
+return 0;
+}
+static int numusearray(const Table*t,int*nums){
+int lg;
+int ttlg;
+int ause=0;
+int i=1;
+for(lg=0,ttlg=1;lg<=(32-2);lg++,ttlg*=2){
+int lc=0;
+int lim=ttlg;
+if(lim>t->sizearray){
+lim=t->sizearray;
+if(i>lim)
+break;
+}
+for(;i<=lim;i++){
+if(!ttisnil(&t->array[i-1]))
+lc++;
+}
+nums[lg]+=lc;
+ause+=lc;
+}
+return ause;
+}
+static int numusehash(const Table*t,int*nums,int*pnasize){
+int totaluse=0;
+int ause=0;
+int i=sizenode(t);
+while(i--){
+Node*n=&t->node[i];
+if(!ttisnil(gval(n))){
+ause+=countint(key2tval(n),nums);
+totaluse++;
+}
+}
+*pnasize+=ause;
+return totaluse;
+}
+static void setarrayvector(lua_State*L,Table*t,int size){
+int i;
+luaM_reallocvector(L,t->array,t->sizearray,size,TValue);
+for(i=t->sizearray;i<size;i++)
+setnilvalue(&t->array[i]);
+t->sizearray=size;
+}
+static void setnodevector(lua_State*L,Table*t,int size){
+int lsize;
+if(size==0){
+t->node=cast(Node*,(&dummynode_));
+lsize=0;
+}
+else{
+int i;
+lsize=ceillog2(size);
+if(lsize>(32-2))
+luaG_runerror(L,"table overflow");
+size=twoto(lsize);
+t->node=luaM_newvector(L,size,Node);
+for(i=0;i<size;i++){
+Node*n=gnode(t,i);
+gnext(n)=NULL;
+setnilvalue(gkey(n));
+setnilvalue(gval(n));
+}
+}
+t->lsizenode=cast_byte(lsize);
+t->lastfree=gnode(t,size);
+}
+static void resize(lua_State*L,Table*t,int nasize,int nhsize){
+int i;
+int oldasize=t->sizearray;
+int oldhsize=t->lsizenode;
+Node*nold=t->node;
+if(nasize>oldasize)
+setarrayvector(L,t,nasize);
+setnodevector(L,t,nhsize);
+if(nasize<oldasize){
+t->sizearray=nasize;
+for(i=nasize;i<oldasize;i++){
+if(!ttisnil(&t->array[i]))
+setobj(L,luaH_setnum(L,t,i+1),&t->array[i]);
+}
+luaM_reallocvector(L,t->array,oldasize,nasize,TValue);
+}
+for(i=twoto(oldhsize)-1;i>=0;i--){
+Node*old=nold+i;
+if(!ttisnil(gval(old)))
+setobj(L,luaH_set(L,t,key2tval(old)),gval(old));
+}
+if(nold!=(&dummynode_))
+luaM_freearray(L,nold,twoto(oldhsize),Node);
+}
+static void luaH_resizearray(lua_State*L,Table*t,int nasize){
+int nsize=(t->node==(&dummynode_))?0:sizenode(t);
+resize(L,t,nasize,nsize);
+}
+static void rehash(lua_State*L,Table*t,const TValue*ek){
+int nasize,na;
+int nums[(32-2)+1];
+int i;
+int totaluse;
+for(i=0;i<=(32-2);i++)nums[i]=0;
+nasize=numusearray(t,nums);
+totaluse=nasize;
+totaluse+=numusehash(t,nums,&nasize);
+nasize+=countint(ek,nums);
+totaluse++;
+na=computesizes(nums,&nasize);
+resize(L,t,nasize,totaluse-na);
+}
+static Table*luaH_new(lua_State*L,int narray,int nhash){
+Table*t=luaM_new(L,Table);
+luaC_link(L,obj2gco(t),5);
+t->metatable=NULL;
+t->flags=cast_byte(~0);
+t->array=NULL;
+t->sizearray=0;
+t->lsizenode=0;
+t->node=cast(Node*,(&dummynode_));
+setarrayvector(L,t,narray);
+setnodevector(L,t,nhash);
+return t;
+}
+static void luaH_free(lua_State*L,Table*t){
+if(t->node!=(&dummynode_))
+luaM_freearray(L,t->node,sizenode(t),Node);
+luaM_freearray(L,t->array,t->sizearray,TValue);
+luaM_free(L,t);
+}
+static Node*getfreepos(Table*t){
+while(t->lastfree-->t->node){
+if(ttisnil(gkey(t->lastfree)))
+return t->lastfree;
+}
+return NULL;
+}
+static TValue*newkey(lua_State*L,Table*t,const TValue*key){
+Node*mp=mainposition(t,key);
+if(!ttisnil(gval(mp))||mp==(&dummynode_)){
+Node*othern;
+Node*n=getfreepos(t);
+if(n==NULL){
+rehash(L,t,key);
+return luaH_set(L,t,key);
+}
+othern=mainposition(t,key2tval(mp));
+if(othern!=mp){
+while(gnext(othern)!=mp)othern=gnext(othern);
+gnext(othern)=n;
+*n=*mp;
+gnext(mp)=NULL;
+setnilvalue(gval(mp));
+}
+else{
+gnext(n)=gnext(mp);
+gnext(mp)=n;
+mp=n;
+}
+}
+gkey(mp)->value=key->value;gkey(mp)->tt=key->tt;
+luaC_barriert(L,t,key);
+return gval(mp);
+}
+static const TValue*luaH_getnum(Table*t,int key){
+if(cast(unsigned int,key)-1<cast(unsigned int,t->sizearray))
+return&t->array[key-1];
+else{
+lua_Number nk=cast_num(key);
+Node*n=hashnum(t,nk);
+do{
+if(ttisnumber(gkey(n))&&luai_numeq(nvalue(gkey(n)),nk))
+return gval(n);
+else n=gnext(n);
+}while(n);
+return(&luaO_nilobject_);
+}
+}
+static const TValue*luaH_getstr(Table*t,TString*key){
+Node*n=hashstr(t,key);
+do{
+if(ttisstring(gkey(n))&&rawtsvalue(gkey(n))==key)
+return gval(n);
+else n=gnext(n);
+}while(n);
+return(&luaO_nilobject_);
+}
+static const TValue*luaH_get(Table*t,const TValue*key){
+switch(ttype(key)){
+case 0:return(&luaO_nilobject_);
+case 4:return luaH_getstr(t,rawtsvalue(key));
+case 3:{
+int k;
+lua_Number n=nvalue(key);
+lua_number2int(k,n);
+if(luai_numeq(cast_num(k),nvalue(key)))
+return luaH_getnum(t,k);
+}
+default:{
+Node*n=mainposition(t,key);
+do{
+if(luaO_rawequalObj(key2tval(n),key))
+return gval(n);
+else n=gnext(n);
+}while(n);
+return(&luaO_nilobject_);
+}
+}
+}
+static TValue*luaH_set(lua_State*L,Table*t,const TValue*key){
+const TValue*p=luaH_get(t,key);
+t->flags=0;
+if(p!=(&luaO_nilobject_))
+return cast(TValue*,p);
+else{
+if(ttisnil(key))luaG_runerror(L,"table index is nil");
+else if(ttisnumber(key)&&luai_numisnan(nvalue(key)))
+luaG_runerror(L,"table index is NaN");
+return newkey(L,t,key);
+}
+}
+static TValue*luaH_setnum(lua_State*L,Table*t,int key){
+const TValue*p=luaH_getnum(t,key);
+if(p!=(&luaO_nilobject_))
+return cast(TValue*,p);
+else{
+TValue k;
+setnvalue(&k,cast_num(key));
+return newkey(L,t,&k);
+}
+}
+static TValue*luaH_setstr(lua_State*L,Table*t,TString*key){
+const TValue*p=luaH_getstr(t,key);
+if(p!=(&luaO_nilobject_))
+return cast(TValue*,p);
+else{
+TValue k;
+setsvalue(L,&k,key);
+return newkey(L,t,&k);
+}
+}
+static int unbound_search(Table*t,unsigned int j){
+unsigned int i=j;
+j++;
+while(!ttisnil(luaH_getnum(t,j))){
+i=j;
+j*=2;
+if(j>cast(unsigned int,(INT_MAX-2))){
+i=1;
+while(!ttisnil(luaH_getnum(t,i)))i++;
+return i-1;
+}
+}
+while(j-i>1){
+unsigned int m=(i+j)/2;
+if(ttisnil(luaH_getnum(t,m)))j=m;
+else i=m;
+}
+return i;
+}
+static int luaH_getn(Table*t){
+unsigned int j=t->sizearray;
+if(j>0&&ttisnil(&t->array[j-1])){
+unsigned int i=0;
+while(j-i>1){
+unsigned int m=(i+j)/2;
+if(ttisnil(&t->array[m-1]))j=m;
+else i=m;
+}
+return i;
+}
+else if(t->node==(&dummynode_))
+return j;
+else return unbound_search(t,j);
+}
+#define makewhite(g,x)((x)->gch.marked=cast_byte(((x)->gch.marked&cast_byte(~(bitmask(2)|bit2mask(0,1))))|luaC_white(g)))
+#define white2gray(x)reset2bits((x)->gch.marked,0,1)
+#define black2gray(x)resetbit((x)->gch.marked,2)
+#define stringmark(s)reset2bits((s)->tsv.marked,0,1)
+#define isfinalized(u)testbit((u)->marked,3)
+#define markfinalized(u)l_setbit((u)->marked,3)
+#define markvalue(g,o){checkconsistency(o);if(iscollectable(o)&&iswhite(gcvalue(o)))reallymarkobject(g,gcvalue(o));}
+#define markobject(g,t){if(iswhite(obj2gco(t)))reallymarkobject(g,obj2gco(t));}
+#define setthreshold(g)(g->GCthreshold=(g->estimate/100)*g->gcpause)
+static void removeentry(Node*n){
+if(iscollectable(gkey(n)))
+setttype(gkey(n),(8+3));
+}
+static void reallymarkobject(global_State*g,GCObject*o){
+white2gray(o);
+switch(o->gch.tt){
+case 4:{
+return;
+}
+case 7:{
+Table*mt=gco2u(o)->metatable;
+gray2black(o);
+if(mt)markobject(g,mt);
+markobject(g,gco2u(o)->env);
+return;
+}
+case(8+2):{
+UpVal*uv=gco2uv(o);
+markvalue(g,uv->v);
+if(uv->v==&uv->u.value)
+gray2black(o);
+return;
+}
+case 6:{
+gco2cl(o)->c.gclist=g->gray;
+g->gray=o;
+break;
+}
+case 5:{
+gco2h(o)->gclist=g->gray;
+g->gray=o;
+break;
+}
+case 8:{
+gco2th(o)->gclist=g->gray;
+g->gray=o;
+break;
+}
+case(8+1):{
+gco2p(o)->gclist=g->gray;
+g->gray=o;
+break;
+}
+default:;
+}
+}
+static void marktmu(global_State*g){
+GCObject*u=g->tmudata;
+if(u){
+do{
+u=u->gch.next;
+makewhite(g,u);
+reallymarkobject(g,u);
+}while(u!=g->tmudata);
+}
+}
+static size_t luaC_separateudata(lua_State*L,int all){
+global_State*g=G(L);
+size_t deadmem=0;
+GCObject**p=&g->mainthread->next;
+GCObject*curr;
+while((curr=*p)!=NULL){
+if(!(iswhite(curr)||all)||isfinalized(gco2u(curr)))
+p=&curr->gch.next;
+else if(fasttm(L,gco2u(curr)->metatable,TM_GC)==NULL){
+markfinalized(gco2u(curr));
+p=&curr->gch.next;
+}
+else{
+deadmem+=sizeudata(gco2u(curr));
+markfinalized(gco2u(curr));
+*p=curr->gch.next;
+if(g->tmudata==NULL)
+g->tmudata=curr->gch.next=curr;
+else{
+curr->gch.next=g->tmudata->gch.next;
+g->tmudata->gch.next=curr;
+g->tmudata=curr;
+}
+}
+}
+return deadmem;
+}
+static int traversetable(global_State*g,Table*h){
+int i;
+int weakkey=0;
+int weakvalue=0;
+const TValue*mode;
+if(h->metatable)
+markobject(g,h->metatable);
+mode=gfasttm(g,h->metatable,TM_MODE);
+if(mode&&ttisstring(mode)){
+weakkey=(strchr(svalue(mode),'k')!=NULL);
+weakvalue=(strchr(svalue(mode),'v')!=NULL);
+if(weakkey||weakvalue){
+h->marked&=~(bitmask(3)|bitmask(4));
+h->marked|=cast_byte((weakkey<<3)|
+(weakvalue<<4));
+h->gclist=g->weak;
+g->weak=obj2gco(h);
+}
+}
+if(weakkey&&weakvalue)return 1;
+if(!weakvalue){
+i=h->sizearray;
+while(i--)
+markvalue(g,&h->array[i]);
+}
+i=sizenode(h);
+while(i--){
+Node*n=gnode(h,i);
+if(ttisnil(gval(n)))
+removeentry(n);
+else{
+if(!weakkey)markvalue(g,gkey(n));
+if(!weakvalue)markvalue(g,gval(n));
+}
+}
+return weakkey||weakvalue;
+}
+static void traverseproto(global_State*g,Proto*f){
+int i;
+if(f->source)stringmark(f->source);
+for(i=0;i<f->sizek;i++)
+markvalue(g,&f->k[i]);
+for(i=0;i<f->sizeupvalues;i++){
+if(f->upvalues[i])
+stringmark(f->upvalues[i]);
+}
+for(i=0;i<f->sizep;i++){
+if(f->p[i])
+markobject(g,f->p[i]);
+}
+for(i=0;i<f->sizelocvars;i++){
+if(f->locvars[i].varname)
+stringmark(f->locvars[i].varname);
+}
+}
+static void traverseclosure(global_State*g,Closure*cl){
+markobject(g,cl->c.env);
+if(cl->c.isC){
+int i;
+for(i=0;i<cl->c.nupvalues;i++)
+markvalue(g,&cl->c.upvalue[i]);
+}
+else{
+int i;
+markobject(g,cl->l.p);
+for(i=0;i<cl->l.nupvalues;i++)
+markobject(g,cl->l.upvals[i]);
+}
+}
+static void checkstacksizes(lua_State*L,StkId max){
+int ci_used=cast_int(L->ci-L->base_ci);
+int s_used=cast_int(max-L->stack);
+if(L->size_ci>20000)
+return;
+if(4*ci_used<L->size_ci&&2*8<L->size_ci)
+luaD_reallocCI(L,L->size_ci/2);
+condhardstacktests(luaD_reallocCI(L,ci_used+1));
+if(4*s_used<L->stacksize&&
+2*((2*20)+5)<L->stacksize)
+luaD_reallocstack(L,L->stacksize/2);
+condhardstacktests(luaD_reallocstack(L,s_used));
+}
+static void traversestack(global_State*g,lua_State*l){
+StkId o,lim;
+CallInfo*ci;
+markvalue(g,gt(l));
+lim=l->top;
+for(ci=l->base_ci;ci<=l->ci;ci++){
+if(lim<ci->top)lim=ci->top;
+}
+for(o=l->stack;o<l->top;o++)
+markvalue(g,o);
+for(;o<=lim;o++)
+setnilvalue(o);
+checkstacksizes(l,lim);
+}
+static l_mem propagatemark(global_State*g){
+GCObject*o=g->gray;
+gray2black(o);
+switch(o->gch.tt){
+case 5:{
+Table*h=gco2h(o);
+g->gray=h->gclist;
+if(traversetable(g,h))
+black2gray(o);
+return sizeof(Table)+sizeof(TValue)*h->sizearray+
+sizeof(Node)*sizenode(h);
+}
+case 6:{
+Closure*cl=gco2cl(o);
+g->gray=cl->c.gclist;
+traverseclosure(g,cl);
+return(cl->c.isC)?sizeCclosure(cl->c.nupvalues):
+sizeLclosure(cl->l.nupvalues);
+}
+case 8:{
+lua_State*th=gco2th(o);
+g->gray=th->gclist;
+th->gclist=g->grayagain;
+g->grayagain=o;
+black2gray(o);
+traversestack(g,th);
+return sizeof(lua_State)+sizeof(TValue)*th->stacksize+
+sizeof(CallInfo)*th->size_ci;
+}
+case(8+1):{
+Proto*p=gco2p(o);
+g->gray=p->gclist;
+traverseproto(g,p);
+return sizeof(Proto)+sizeof(Instruction)*p->sizecode+
+sizeof(Proto*)*p->sizep+
+sizeof(TValue)*p->sizek+
+sizeof(int)*p->sizelineinfo+
+sizeof(LocVar)*p->sizelocvars+
+sizeof(TString*)*p->sizeupvalues;
+}
+default:return 0;
+}
+}
+static size_t propagateall(global_State*g){
+size_t m=0;
+while(g->gray)m+=propagatemark(g);
+return m;
+}
+static int iscleared(const TValue*o,int iskey){
+if(!iscollectable(o))return 0;
+if(ttisstring(o)){
+stringmark(rawtsvalue(o));
+return 0;
+}
+return iswhite(gcvalue(o))||
+(ttisuserdata(o)&&(!iskey&&isfinalized(uvalue(o))));
+}
+static void cleartable(GCObject*l){
+while(l){
+Table*h=gco2h(l);
+int i=h->sizearray;
+if(testbit(h->marked,4)){
+while(i--){
+TValue*o=&h->array[i];
+if(iscleared(o,0))
+setnilvalue(o);
+}
+}
+i=sizenode(h);
+while(i--){
+Node*n=gnode(h,i);
+if(!ttisnil(gval(n))&&
+(iscleared(key2tval(n),1)||iscleared(gval(n),0))){
+setnilvalue(gval(n));
+removeentry(n);
+}
+}
+l=h->gclist;
+}
+}
+static void freeobj(lua_State*L,GCObject*o){
+switch(o->gch.tt){
+case(8+1):luaF_freeproto(L,gco2p(o));break;
+case 6:luaF_freeclosure(L,gco2cl(o));break;
+case(8+2):luaF_freeupval(L,gco2uv(o));break;
+case 5:luaH_free(L,gco2h(o));break;
+case 8:{
+luaE_freethread(L,gco2th(o));
+break;
+}
+case 4:{
+G(L)->strt.nuse--;
+luaM_freemem(L,o,sizestring(gco2ts(o)));
+break;
+}
+case 7:{
+luaM_freemem(L,o,sizeudata(gco2u(o)));
+break;
+}
+default:;
+}
+}
+#define sweepwholelist(L,p)sweeplist(L,p,((lu_mem)(~(lu_mem)0)-2))
+static GCObject**sweeplist(lua_State*L,GCObject**p,lu_mem count){
+GCObject*curr;
+global_State*g=G(L);
+int deadmask=otherwhite(g);
+while((curr=*p)!=NULL&&count-->0){
+if(curr->gch.tt==8)
+sweepwholelist(L,&gco2th(curr)->openupval);
+if((curr->gch.marked^bit2mask(0,1))&deadmask){
+makewhite(g,curr);
+p=&curr->gch.next;
+}
+else{
+*p=curr->gch.next;
+if(curr==g->rootgc)
+g->rootgc=curr->gch.next;
+freeobj(L,curr);
+}
+}
+return p;
+}
+static void checkSizes(lua_State*L){
+global_State*g=G(L);
+if(g->strt.nuse<cast(lu_int32,g->strt.size/4)&&
+g->strt.size>32*2)
+luaS_resize(L,g->strt.size/2);
+if(luaZ_sizebuffer(&g->buff)>32*2){
+size_t newsize=luaZ_sizebuffer(&g->buff)/2;
+luaZ_resizebuffer(L,&g->buff,newsize);
+}
+}
+static void GCTM(lua_State*L){
+global_State*g=G(L);
+GCObject*o=g->tmudata->gch.next;
+Udata*udata=rawgco2u(o);
+const TValue*tm;
+if(o==g->tmudata)
+g->tmudata=NULL;
+else
+g->tmudata->gch.next=udata->uv.next;
+udata->uv.next=g->mainthread->next;
+g->mainthread->next=o;
+makewhite(g,o);
+tm=fasttm(L,udata->uv.metatable,TM_GC);
+if(tm!=NULL){
+lu_byte oldah=L->allowhook;
+lu_mem oldt=g->GCthreshold;
+L->allowhook=0;
+g->GCthreshold=2*g->totalbytes;
+setobj(L,L->top,tm);
+setuvalue(L,L->top+1,udata);
+L->top+=2;
+luaD_call(L,L->top-2,0);
+L->allowhook=oldah;
+g->GCthreshold=oldt;
+}
+}
+static void luaC_callGCTM(lua_State*L){
+while(G(L)->tmudata)
+GCTM(L);
+}
+static void luaC_freeall(lua_State*L){
+global_State*g=G(L);
+int i;
+g->currentwhite=bit2mask(0,1)|bitmask(6);
+sweepwholelist(L,&g->rootgc);
+for(i=0;i<g->strt.size;i++)
+sweepwholelist(L,&g->strt.hash[i]);
+}
+static void markmt(global_State*g){
+int i;
+for(i=0;i<(8+1);i++)
+if(g->mt[i])markobject(g,g->mt[i]);
+}
+static void markroot(lua_State*L){
+global_State*g=G(L);
+g->gray=NULL;
+g->grayagain=NULL;
+g->weak=NULL;
+markobject(g,g->mainthread);
+markvalue(g,gt(g->mainthread));
+markvalue(g,registry(L));
+markmt(g);
+g->gcstate=1;
+}
+static void remarkupvals(global_State*g){
+UpVal*uv;
+for(uv=g->uvhead.u.l.next;uv!=&g->uvhead;uv=uv->u.l.next){
+if(isgray(obj2gco(uv)))
+markvalue(g,uv->v);
+}
+}
+static void atomic(lua_State*L){
+global_State*g=G(L);
+size_t udsize;
+remarkupvals(g);
+propagateall(g);
+g->gray=g->weak;
+g->weak=NULL;
+markobject(g,L);
+markmt(g);
+propagateall(g);
+g->gray=g->grayagain;
+g->grayagain=NULL;
+propagateall(g);
+udsize=luaC_separateudata(L,0);
+marktmu(g);
+udsize+=propagateall(g);
+cleartable(g->weak);
+g->currentwhite=cast_byte(otherwhite(g));
+g->sweepstrgc=0;
+g->sweepgc=&g->rootgc;
+g->gcstate=2;
+g->estimate=g->totalbytes-udsize;
+}
+static l_mem singlestep(lua_State*L){
+global_State*g=G(L);
+switch(g->gcstate){
+case 0:{
+markroot(L);
+return 0;
+}
+case 1:{
+if(g->gray)
+return propagatemark(g);
+else{
+atomic(L);
+return 0;
+}
+}
+case 2:{
+lu_mem old=g->totalbytes;
+sweepwholelist(L,&g->strt.hash[g->sweepstrgc++]);
+if(g->sweepstrgc>=g->strt.size)
+g->gcstate=3;
+g->estimate-=old-g->totalbytes;
+return 10;
+}
+case 3:{
+lu_mem old=g->totalbytes;
+g->sweepgc=sweeplist(L,g->sweepgc,40);
+if(*g->sweepgc==NULL){
+checkSizes(L);
+g->gcstate=4;
+}
+g->estimate-=old-g->totalbytes;
+return 40*10;
+}
+case 4:{
+if(g->tmudata){
+GCTM(L);
+if(g->estimate>100)
+g->estimate-=100;
+return 100;
+}
+else{
+g->gcstate=0;
+g->gcdept=0;
+return 0;
+}
+}
+default:return 0;
+}
+}
+static void luaC_step(lua_State*L){
+global_State*g=G(L);
+l_mem lim=(1024u/100)*g->gcstepmul;
+if(lim==0)
+lim=(((lu_mem)(~(lu_mem)0)-2)-1)/2;
+g->gcdept+=g->totalbytes-g->GCthreshold;
+do{
+lim-=singlestep(L);
+if(g->gcstate==0)
+break;
+}while(lim>0);
+if(g->gcstate!=0){
+if(g->gcdept<1024u)
+g->GCthreshold=g->totalbytes+1024u;
+else{
+g->gcdept-=1024u;
+g->GCthreshold=g->totalbytes;
+}
+}
+else{
+setthreshold(g);
+}
+}
+static void luaC_barrierf(lua_State*L,GCObject*o,GCObject*v){
+global_State*g=G(L);
+if(g->gcstate==1)
+reallymarkobject(g,v);
+else
+makewhite(g,o);
+}
+static void luaC_barrierback(lua_State*L,Table*t){
+global_State*g=G(L);
+GCObject*o=obj2gco(t);
+black2gray(o);
+t->gclist=g->grayagain;
+g->grayagain=o;
+}
+static void luaC_link(lua_State*L,GCObject*o,lu_byte tt){
+global_State*g=G(L);
+o->gch.next=g->rootgc;
+g->rootgc=o;
+o->gch.marked=luaC_white(g);
+o->gch.tt=tt;
+}
+static void luaC_linkupval(lua_State*L,UpVal*uv){
+global_State*g=G(L);
+GCObject*o=obj2gco(uv);
+o->gch.next=g->rootgc;
+g->rootgc=o;
+if(isgray(o)){
+if(g->gcstate==1){
+gray2black(o);
+luaC_barrier(L,uv,uv->v);
+}
+else{
+makewhite(g,o);
+}
+}
+}
+typedef union{
+lua_Number r;
+TString*ts;
+}SemInfo;
+typedef struct Token{
+int token;
+SemInfo seminfo;
+}Token;
+typedef struct LexState{
+int current;
+int linenumber;
+int lastline;
+Token t;
+Token lookahead;
+struct FuncState*fs;
+struct lua_State*L;
+ZIO*z;
+Mbuffer*buff;
+TString*source;
+char decpoint;
+}LexState;
+static void luaX_init(lua_State*L);
+static void luaX_lexerror(LexState*ls,const char*msg,int token);
+#define state_size(x)(sizeof(x)+0)
+#define fromstate(l)(cast(lu_byte*,(l))-0)
+#define tostate(l)(cast(lua_State*,cast(lu_byte*,l)+0))
+typedef struct LG{
+lua_State l;
+global_State g;
+}LG;
+static void stack_init(lua_State*L1,lua_State*L){
+L1->base_ci=luaM_newvector(L,8,CallInfo);
+L1->ci=L1->base_ci;
+L1->size_ci=8;
+L1->end_ci=L1->base_ci+L1->size_ci-1;
+L1->stack=luaM_newvector(L,(2*20)+5,TValue);
+L1->stacksize=(2*20)+5;
+L1->top=L1->stack;
+L1->stack_last=L1->stack+(L1->stacksize-5)-1;
+L1->ci->func=L1->top;
+setnilvalue(L1->top++);
+L1->base=L1->ci->base=L1->top;
+L1->ci->top=L1->top+20;
+}
+static void freestack(lua_State*L,lua_State*L1){
+luaM_freearray(L,L1->base_ci,L1->size_ci,CallInfo);
+luaM_freearray(L,L1->stack,L1->stacksize,TValue);
+}
+static void f_luaopen(lua_State*L,void*ud){
+global_State*g=G(L);
+UNUSED(ud);
+stack_init(L,L);
+sethvalue(L,gt(L),luaH_new(L,0,2));
+sethvalue(L,registry(L),luaH_new(L,0,2));
+luaS_resize(L,32);
+luaT_init(L);
+luaX_init(L);
+luaS_fix(luaS_newliteral(L,"not enough memory"));
+g->GCthreshold=4*g->totalbytes;
+}
+static void preinit_state(lua_State*L,global_State*g){
+G(L)=g;
+L->stack=NULL;
+L->stacksize=0;
+L->errorJmp=NULL;
+L->hook=NULL;
+L->hookmask=0;
+L->basehookcount=0;
+L->allowhook=1;
+resethookcount(L);
+L->openupval=NULL;
+L->size_ci=0;
+L->nCcalls=L->baseCcalls=0;
+L->status=0;
+L->base_ci=L->ci=NULL;
+L->savedpc=NULL;
+L->errfunc=0;
+setnilvalue(gt(L));
+}
+static void close_state(lua_State*L){
+global_State*g=G(L);
+luaF_close(L,L->stack);
+luaC_freeall(L);
+luaM_freearray(L,G(L)->strt.hash,G(L)->strt.size,TString*);
+luaZ_freebuffer(L,&g->buff);
+freestack(L,L);
+(*g->frealloc)(g->ud,fromstate(L),state_size(LG),0);
+}
+static void luaE_freethread(lua_State*L,lua_State*L1){
+luaF_close(L1,L1->stack);
+freestack(L,L1);
+luaM_freemem(L,fromstate(L1),state_size(lua_State));
+}
+static lua_State*lua_newstate(lua_Alloc f,void*ud){
+int i;
+lua_State*L;
+global_State*g;
+void*l=(*f)(ud,NULL,0,state_size(LG));
+if(l==NULL)return NULL;
+L=tostate(l);
+g=&((LG*)L)->g;
+L->next=NULL;
+L->tt=8;
+g->currentwhite=bit2mask(0,5);
+L->marked=luaC_white(g);
+set2bits(L->marked,5,6);
+preinit_state(L,g);
+g->frealloc=f;
+g->ud=ud;
+g->mainthread=L;
+g->uvhead.u.l.prev=&g->uvhead;
+g->uvhead.u.l.next=&g->uvhead;
+g->GCthreshold=0;
+g->strt.size=0;
+g->strt.nuse=0;
+g->strt.hash=NULL;
+setnilvalue(registry(L));
+luaZ_initbuffer(L,&g->buff);
+g->panic=NULL;
+g->gcstate=0;
+g->rootgc=obj2gco(L);
+g->sweepstrgc=0;
+g->sweepgc=&g->rootgc;
+g->gray=NULL;
+g->grayagain=NULL;
+g->weak=NULL;
+g->tmudata=NULL;
+g->totalbytes=sizeof(LG);
+g->gcpause=200;
+g->gcstepmul=200;
+g->gcdept=0;
+for(i=0;i<(8+1);i++)g->mt[i]=NULL;
+if(luaD_rawrunprotected(L,f_luaopen,NULL)!=0){
+close_state(L);
+L=NULL;
+}
+else
+{}
+return L;
+}
+static void callallgcTM(lua_State*L,void*ud){
+UNUSED(ud);
+luaC_callGCTM(L);
+}
+static void lua_close(lua_State*L){
+L=G(L)->mainthread;
+luaF_close(L,L->stack);
+luaC_separateudata(L,1);
+L->errfunc=0;
+do{
+L->ci=L->base_ci;
+L->base=L->top=L->ci->base;
+L->nCcalls=L->baseCcalls=0;
+}while(luaD_rawrunprotected(L,callallgcTM,NULL)!=0);
+close_state(L);
+}
+#define getcode(fs,e)((fs)->f->code[(e)->u.s.info])
+#define luaK_codeAsBx(fs,o,A,sBx)luaK_codeABx(fs,o,A,(sBx)+(((1<<(9+9))-1)>>1))
+#define luaK_setmultret(fs,e)luaK_setreturns(fs,e,(-1))
+static int luaK_codeABx(FuncState*fs,OpCode o,int A,unsigned int Bx);
+static int luaK_codeABC(FuncState*fs,OpCode o,int A,int B,int C);
+static void luaK_setreturns(FuncState*fs,expdesc*e,int nresults);
+static void luaK_patchtohere(FuncState*fs,int list);
+static void luaK_concat(FuncState*fs,int*l1,int l2);
+static int currentpc(lua_State*L,CallInfo*ci){
+if(!isLua(ci))return-1;
+if(ci==L->ci)
+ci->savedpc=L->savedpc;
+return pcRel(ci->savedpc,ci_func(ci)->l.p);
+}
+static int currentline(lua_State*L,CallInfo*ci){
+int pc=currentpc(L,ci);
+if(pc<0)
+return-1;
+else
+return getline_(ci_func(ci)->l.p,pc);
+}
+static int lua_getstack(lua_State*L,int level,lua_Debug*ar){
+int status;
+CallInfo*ci;
+for(ci=L->ci;level>0&&ci>L->base_ci;ci--){
+level--;
+if(f_isLua(ci))
+level-=ci->tailcalls;
+}
+if(level==0&&ci>L->base_ci){
+status=1;
+ar->i_ci=cast_int(ci-L->base_ci);
+}
+else if(level<0){
+status=1;
+ar->i_ci=0;
+}
+else status=0;
+return status;
+}
+static Proto*getluaproto(CallInfo*ci){
+return(isLua(ci)?ci_func(ci)->l.p:NULL);
+}
+static void funcinfo(lua_Debug*ar,Closure*cl){
+if(cl->c.isC){
+ar->source="=[C]";
+ar->linedefined=-1;
+ar->lastlinedefined=-1;
+ar->what="C";
+}
+else{
+ar->source=getstr(cl->l.p->source);
+ar->linedefined=cl->l.p->linedefined;
+ar->lastlinedefined=cl->l.p->lastlinedefined;
+ar->what=(ar->linedefined==0)?"main":"Lua";
+}
+luaO_chunkid(ar->short_src,ar->source,60);
+}
+static void info_tailcall(lua_Debug*ar){
+ar->name=ar->namewhat="";
+ar->what="tail";
+ar->lastlinedefined=ar->linedefined=ar->currentline=-1;
+ar->source="=(tail call)";
+luaO_chunkid(ar->short_src,ar->source,60);
+ar->nups=0;
+}
+static void collectvalidlines(lua_State*L,Closure*f){
+if(f==NULL||f->c.isC){
+setnilvalue(L->top);
+}
+else{
+Table*t=luaH_new(L,0,0);
+int*lineinfo=f->l.p->lineinfo;
+int i;
+for(i=0;i<f->l.p->sizelineinfo;i++)
+setbvalue(luaH_setnum(L,t,lineinfo[i]),1);
+sethvalue(L,L->top,t);
+}
+incr_top(L);
+}
+static int auxgetinfo(lua_State*L,const char*what,lua_Debug*ar,
+Closure*f,CallInfo*ci){
+int status=1;
+if(f==NULL){
+info_tailcall(ar);
+return status;
+}
+for(;*what;what++){
+switch(*what){
+case'S':{
+funcinfo(ar,f);
+break;
+}
+case'l':{
+ar->currentline=(ci)?currentline(L,ci):-1;
+break;
+}
+case'u':{
+ar->nups=f->c.nupvalues;
+break;
+}
+case'n':{
+ar->namewhat=(ci)?NULL:NULL;
+if(ar->namewhat==NULL){
+ar->namewhat="";
+ar->name=NULL;
+}
+break;
+}
+case'L':
+case'f':
+break;
+default:status=0;
+}
+}
+return status;
+}
+static int lua_getinfo(lua_State*L,const char*what,lua_Debug*ar){
+int status;
+Closure*f=NULL;
+CallInfo*ci=NULL;
+if(*what=='>'){
+StkId func=L->top-1;
+luai_apicheck(L,ttisfunction(func));
+what++;
+f=clvalue(func);
+L->top--;
+}
+else if(ar->i_ci!=0){
+ci=L->base_ci+ar->i_ci;
+f=clvalue(ci->func);
+}
+status=auxgetinfo(L,what,ar,f,ci);
+if(strchr(what,'f')){
+if(f==NULL)setnilvalue(L->top);
+else setclvalue(L,L->top,f);
+incr_top(L);
+}
+if(strchr(what,'L'))
+collectvalidlines(L,f);
+return status;
+}
+static int isinstack(CallInfo*ci,const TValue*o){
+StkId p;
+for(p=ci->base;p<ci->top;p++)
+if(o==p)return 1;
+return 0;
+}
+static void luaG_typeerror(lua_State*L,const TValue*o,const char*op){
+const char*name=NULL;
+const char*t=luaT_typenames[ttype(o)];
+const char*kind=(isinstack(L->ci,o))?
+NULL:
+NULL;
+if(kind)
+luaG_runerror(L,"attempt to %s %s "LUA_QL("%s")" (a %s value)",
+op,kind,name,t);
+else
+luaG_runerror(L,"attempt to %s a %s value",op,t);
+}
+static void luaG_concaterror(lua_State*L,StkId p1,StkId p2){
+if(ttisstring(p1)||ttisnumber(p1))p1=p2;
+luaG_typeerror(L,p1,"concatenate");
+}
+static void luaG_aritherror(lua_State*L,const TValue*p1,const TValue*p2){
+TValue temp;
+if(luaV_tonumber(p1,&temp)==NULL)
+p2=p1;
+luaG_typeerror(L,p2,"perform arithmetic on");
+}
+static int luaG_ordererror(lua_State*L,const TValue*p1,const TValue*p2){
+const char*t1=luaT_typenames[ttype(p1)];
+const char*t2=luaT_typenames[ttype(p2)];
+if(t1[2]==t2[2])
+luaG_runerror(L,"attempt to compare two %s values",t1);
+else
+luaG_runerror(L,"attempt to compare %s with %s",t1,t2);
+return 0;
+}
+static void addinfo(lua_State*L,const char*msg){
+CallInfo*ci=L->ci;
+if(isLua(ci)){
+char buff[60];
+int line=currentline(L,ci);
+luaO_chunkid(buff,getstr(getluaproto(ci)->source),60);
+luaO_pushfstring(L,"%s:%d: %s",buff,line,msg);
+}
+}
+static void luaG_errormsg(lua_State*L){
+if(L->errfunc!=0){
+StkId errfunc=restorestack(L,L->errfunc);
+if(!ttisfunction(errfunc))luaD_throw(L,5);
+setobj(L,L->top,L->top-1);
+setobj(L,L->top-1,errfunc);
+incr_top(L);
+luaD_call(L,L->top-2,1);
+}
+luaD_throw(L,2);
+}
+static void luaG_runerror(lua_State*L,const char*fmt,...){
+va_list argp;
+va_start(argp,fmt);
+addinfo(L,luaO_pushvfstring(L,fmt,argp));
+va_end(argp);
+luaG_errormsg(L);
+}
+static int luaZ_fill(ZIO*z){
+size_t size;
+lua_State*L=z->L;
+const char*buff;
+buff=z->reader(L,z->data,&size);
+if(buff==NULL||size==0)return(-1);
+z->n=size-1;
+z->p=buff;
+return char2int(*(z->p++));
+}
+static void luaZ_init(lua_State*L,ZIO*z,lua_Reader reader,void*data){
+z->L=L;
+z->reader=reader;
+z->data=data;
+z->n=0;
+z->p=NULL;
+}
+static char*luaZ_openspace(lua_State*L,Mbuffer*buff,size_t n){
+if(n>buff->buffsize){
+if(n<32)n=32;
+luaZ_resizebuffer(L,buff,n);
+}
+return buff->buffer;
+}
+#define opmode(t,a,b,c,m)(((t)<<7)|((a)<<6)|((b)<<4)|((c)<<2)|(m))
+static const lu_byte luaP_opmodes[(cast(int,OP_VARARG)+1)]={
+opmode(0,1,OpArgR,OpArgN,iABC)
+,opmode(0,1,OpArgK,OpArgN,iABx)
+,opmode(0,1,OpArgU,OpArgU,iABC)
+,opmode(0,1,OpArgR,OpArgN,iABC)
+,opmode(0,1,OpArgU,OpArgN,iABC)
+,opmode(0,1,OpArgK,OpArgN,iABx)
+,opmode(0,1,OpArgR,OpArgK,iABC)
+,opmode(0,0,OpArgK,OpArgN,iABx)
+,opmode(0,0,OpArgU,OpArgN,iABC)
+,opmode(0,0,OpArgK,OpArgK,iABC)
+,opmode(0,1,OpArgU,OpArgU,iABC)
+,opmode(0,1,OpArgR,OpArgK,iABC)
+,opmode(0,1,OpArgK,OpArgK,iABC)
+,opmode(0,1,OpArgK,OpArgK,iABC)
+,opmode(0,1,OpArgK,OpArgK,iABC)
+,opmode(0,1,OpArgK,OpArgK,iABC)
+,opmode(0,1,OpArgK,OpArgK,iABC)
+,opmode(0,1,OpArgK,OpArgK,iABC)
+,opmode(0,1,OpArgR,OpArgN,iABC)
+,opmode(0,1,OpArgR,OpArgN,iABC)
+,opmode(0,1,OpArgR,OpArgN,iABC)
+,opmode(0,1,OpArgR,OpArgR,iABC)
+,opmode(0,0,OpArgR,OpArgN,iAsBx)
+,opmode(1,0,OpArgK,OpArgK,iABC)
+,opmode(1,0,OpArgK,OpArgK,iABC)
+,opmode(1,0,OpArgK,OpArgK,iABC)
+,opmode(1,1,OpArgR,OpArgU,iABC)
+,opmode(1,1,OpArgR,OpArgU,iABC)
+,opmode(0,1,OpArgU,OpArgU,iABC)
+,opmode(0,1,OpArgU,OpArgU,iABC)
+,opmode(0,0,OpArgU,OpArgN,iABC)
+,opmode(0,1,OpArgR,OpArgN,iAsBx)
+,opmode(0,1,OpArgR,OpArgN,iAsBx)
+,opmode(1,0,OpArgN,OpArgU,iABC)
+,opmode(0,0,OpArgU,OpArgU,iABC)
+,opmode(0,0,OpArgN,OpArgN,iABC)
+,opmode(0,1,OpArgU,OpArgN,iABx)
+,opmode(0,1,OpArgU,OpArgN,iABC)
+};
+#define next(ls)(ls->current=zgetc(ls->z))
+#define currIsNewline(ls)(ls->current=='\n'||ls->current=='\r')
+static const char*const luaX_tokens[]={
+"and","break","do","else","elseif",
+"end","false","for","function","if",
+"in","local","nil","not","or","repeat",
+"return","then","true","until","while",
+"..","...","==",">=","<=","~=",
+"<number>","<name>","<string>","<eof>",
+NULL
+};
+#define save_and_next(ls)(save(ls,ls->current),next(ls))
+static void save(LexState*ls,int c){
+Mbuffer*b=ls->buff;
+if(b->n+1>b->buffsize){
+size_t newsize;
+if(b->buffsize>=((size_t)(~(size_t)0)-2)/2)
+luaX_lexerror(ls,"lexical element too long",0);
+newsize=b->buffsize*2;
+luaZ_resizebuffer(ls->L,b,newsize);
+}
+b->buffer[b->n++]=cast(char,c);
+}
+static void luaX_init(lua_State*L){
+int i;
+for(i=0;i<(cast(int,TK_WHILE-257+1));i++){
+TString*ts=luaS_new(L,luaX_tokens[i]);
+luaS_fix(ts);
+ts->tsv.reserved=cast_byte(i+1);
+}
+}
+static const char*luaX_token2str(LexState*ls,int token){
+if(token<257){
+return(iscntrl(token))?luaO_pushfstring(ls->L,"char(%d)",token):
+luaO_pushfstring(ls->L,"%c",token);
+}
+else
+return luaX_tokens[token-257];
+}
+static const char*txtToken(LexState*ls,int token){
+switch(token){
+case TK_NAME:
+case TK_STRING:
+case TK_NUMBER:
+save(ls,'\0');
+return luaZ_buffer(ls->buff);
+default:
+return luaX_token2str(ls,token);
+}
+}
+static void luaX_lexerror(LexState*ls,const char*msg,int token){
+char buff[80];
+luaO_chunkid(buff,getstr(ls->source),80);
+msg=luaO_pushfstring(ls->L,"%s:%d: %s",buff,ls->linenumber,msg);
+if(token)
+luaO_pushfstring(ls->L,"%s near "LUA_QL("%s"),msg,txtToken(ls,token));
+luaD_throw(ls->L,3);
+}
+static void luaX_syntaxerror(LexState*ls,const char*msg){
+luaX_lexerror(ls,msg,ls->t.token);
+}
+static TString*luaX_newstring(LexState*ls,const char*str,size_t l){
+lua_State*L=ls->L;
+TString*ts=luaS_newlstr(L,str,l);
+TValue*o=luaH_setstr(L,ls->fs->h,ts);
+if(ttisnil(o)){
+setbvalue(o,1);
+luaC_checkGC(L);
+}
+return ts;
+}
+static void inclinenumber(LexState*ls){
+int old=ls->current;
+next(ls);
+if(currIsNewline(ls)&&ls->current!=old)
+next(ls);
+if(++ls->linenumber>=(INT_MAX-2))
+luaX_syntaxerror(ls,"chunk has too many lines");
+}
+static void luaX_setinput(lua_State*L,LexState*ls,ZIO*z,TString*source){
+ls->decpoint='.';
+ls->L=L;
+ls->lookahead.token=TK_EOS;
+ls->z=z;
+ls->fs=NULL;
+ls->linenumber=1;
+ls->lastline=1;
+ls->source=source;
+luaZ_resizebuffer(ls->L,ls->buff,32);
+next(ls);
+}
+static int check_next(LexState*ls,const char*set){
+if(!strchr(set,ls->current))
+return 0;
+save_and_next(ls);
+return 1;
+}
+static void buffreplace(LexState*ls,char from,char to){
+size_t n=luaZ_bufflen(ls->buff);
+char*p=luaZ_buffer(ls->buff);
+while(n--)
+if(p[n]==from)p[n]=to;
+}
+static void read_numeral(LexState*ls,SemInfo*seminfo){
+do{
+save_and_next(ls);
+}while(isdigit(ls->current)||ls->current=='.');
+if(check_next(ls,"Ee"))
+check_next(ls,"+-");
+while(isalnum(ls->current)||ls->current=='_')
+save_and_next(ls);
+save(ls,'\0');
+buffreplace(ls,'.',ls->decpoint);
+if(!luaO_str2d(luaZ_buffer(ls->buff),&seminfo->r))
+luaX_lexerror(ls,"malformed number",TK_NUMBER);
+}
+static int skip_sep(LexState*ls){
+int count=0;
+int s=ls->current;
+save_and_next(ls);
+while(ls->current=='='){
+save_and_next(ls);
+count++;
+}
+return(ls->current==s)?count:(-count)-1;
+}
+static void read_long_string(LexState*ls,SemInfo*seminfo,int sep){
+int cont=0;
+(void)(cont);
+save_and_next(ls);
+if(currIsNewline(ls))
+inclinenumber(ls);
+for(;;){
+switch(ls->current){
+case(-1):
+luaX_lexerror(ls,(seminfo)?"unfinished long string":
+"unfinished long comment",TK_EOS);
+break;
+case']':{
+if(skip_sep(ls)==sep){
+save_and_next(ls);
+goto endloop;
+}
+break;
+}
+case'\n':
+case'\r':{
+save(ls,'\n');
+inclinenumber(ls);
+if(!seminfo)luaZ_resetbuffer(ls->buff);
+break;
+}
+default:{
+if(seminfo)save_and_next(ls);
+else next(ls);
+}
+}
+}endloop:
+if(seminfo)
+seminfo->ts=luaX_newstring(ls,luaZ_buffer(ls->buff)+(2+sep),
+luaZ_bufflen(ls->buff)-2*(2+sep));
+}
+static void read_string(LexState*ls,int del,SemInfo*seminfo){
+save_and_next(ls);
+while(ls->current!=del){
+switch(ls->current){
+case(-1):
+luaX_lexerror(ls,"unfinished string",TK_EOS);
+continue;
+case'\n':
+case'\r':
+luaX_lexerror(ls,"unfinished string",TK_STRING);
+continue;
+case'\\':{
+int c;
+next(ls);
+switch(ls->current){
+case'a':c='\a';break;
+case'b':c='\b';break;
+case'f':c='\f';break;
+case'n':c='\n';break;
+case'r':c='\r';break;
+case't':c='\t';break;
+case'v':c='\v';break;
+case'\n':
+case'\r':save(ls,'\n');inclinenumber(ls);continue;
+case(-1):continue;
+default:{
+if(!isdigit(ls->current))
+save_and_next(ls);
+else{
+int i=0;
+c=0;
+do{
+c=10*c+(ls->current-'0');
+next(ls);
+}while(++i<3&&isdigit(ls->current));
+if(c>UCHAR_MAX)
+luaX_lexerror(ls,"escape sequence too large",TK_STRING);
+save(ls,c);
+}
+continue;
+}
+}
+save(ls,c);
+next(ls);
+continue;
+}
+default:
+save_and_next(ls);
+}
+}
+save_and_next(ls);
+seminfo->ts=luaX_newstring(ls,luaZ_buffer(ls->buff)+1,
+luaZ_bufflen(ls->buff)-2);
+}
+static int llex(LexState*ls,SemInfo*seminfo){
+luaZ_resetbuffer(ls->buff);
+for(;;){
+switch(ls->current){
+case'\n':
+case'\r':{
+inclinenumber(ls);
+continue;
+}
+case'-':{
+next(ls);
+if(ls->current!='-')return'-';
+next(ls);
+if(ls->current=='['){
+int sep=skip_sep(ls);
+luaZ_resetbuffer(ls->buff);
+if(sep>=0){
+read_long_string(ls,NULL,sep);
+luaZ_resetbuffer(ls->buff);
+continue;
+}
+}
+while(!currIsNewline(ls)&&ls->current!=(-1))
+next(ls);
+continue;
+}
+case'[':{
+int sep=skip_sep(ls);
+if(sep>=0){
+read_long_string(ls,seminfo,sep);
+return TK_STRING;
+}
+else if(sep==-1)return'[';
+else luaX_lexerror(ls,"invalid long string delimiter",TK_STRING);
+}
+case'=':{
+next(ls);
+if(ls->current!='=')return'=';
+else{next(ls);return TK_EQ;}
+}
+case'<':{
+next(ls);
+if(ls->current!='=')return'<';
+else{next(ls);return TK_LE;}
+}
+case'>':{
+next(ls);
+if(ls->current!='=')return'>';
+else{next(ls);return TK_GE;}
+}
+case'~':{
+next(ls);
+if(ls->current!='=')return'~';
+else{next(ls);return TK_NE;}
+}
+case'"':
+case'\'':{
+read_string(ls,ls->current,seminfo);
+return TK_STRING;
+}
+case'.':{
+save_and_next(ls);
+if(check_next(ls,".")){
+if(check_next(ls,"."))
+return TK_DOTS;
+else return TK_CONCAT;
+}
+else if(!isdigit(ls->current))return'.';
+else{
+read_numeral(ls,seminfo);
+return TK_NUMBER;
+}
+}
+case(-1):{
+return TK_EOS;
+}
+default:{
+if(isspace(ls->current)){
+next(ls);
+continue;
+}
+else if(isdigit(ls->current)){
+read_numeral(ls,seminfo);
+return TK_NUMBER;
+}
+else if(isalpha(ls->current)||ls->current=='_'){
+TString*ts;
+do{
+save_and_next(ls);
+}while(isalnum(ls->current)||ls->current=='_');
+ts=luaX_newstring(ls,luaZ_buffer(ls->buff),
+luaZ_bufflen(ls->buff));
+if(ts->tsv.reserved>0)
+return ts->tsv.reserved-1+257;
+else{
+seminfo->ts=ts;
+return TK_NAME;
+}
+}
+else{
+int c=ls->current;
+next(ls);
+return c;
+}
+}
+}
+}
+}
+static void luaX_next(LexState*ls){
+ls->lastline=ls->linenumber;
+if(ls->lookahead.token!=TK_EOS){
+ls->t=ls->lookahead;
+ls->lookahead.token=TK_EOS;
+}
+else
+ls->t.token=llex(ls,&ls->t.seminfo);
+}
+static void luaX_lookahead(LexState*ls){
+ls->lookahead.token=llex(ls,&ls->lookahead.seminfo);
+}
+#define hasjumps(e)((e)->t!=(e)->f)
+static int isnumeral(expdesc*e){
+return(e->k==VKNUM&&e->t==(-1)&&e->f==(-1));
+}
+static void luaK_nil(FuncState*fs,int from,int n){
+Instruction*previous;
+if(fs->pc>fs->lasttarget){
+if(fs->pc==0){
+if(from>=fs->nactvar)
+return;
+}
+else{
+previous=&fs->f->code[fs->pc-1];
+if(GET_OPCODE(*previous)==OP_LOADNIL){
+int pfrom=GETARG_A(*previous);
+int pto=GETARG_B(*previous);
+if(pfrom<=from&&from<=pto+1){
+if(from+n-1>pto)
+SETARG_B(*previous,from+n-1);
+return;
+}
+}
+}
+}
+luaK_codeABC(fs,OP_LOADNIL,from,from+n-1,0);
+}
+static int luaK_jump(FuncState*fs){
+int jpc=fs->jpc;
+int j;
+fs->jpc=(-1);
+j=luaK_codeAsBx(fs,OP_JMP,0,(-1));
+luaK_concat(fs,&j,jpc);
+return j;
+}
+static void luaK_ret(FuncState*fs,int first,int nret){
+luaK_codeABC(fs,OP_RETURN,first,nret+1,0);
+}
+static int condjump(FuncState*fs,OpCode op,int A,int B,int C){
+luaK_codeABC(fs,op,A,B,C);
+return luaK_jump(fs);
+}
+static void fixjump(FuncState*fs,int pc,int dest){
+Instruction*jmp=&fs->f->code[pc];
+int offset=dest-(pc+1);
+if(abs(offset)>(((1<<(9+9))-1)>>1))
+luaX_syntaxerror(fs->ls,"control structure too long");
+SETARG_sBx(*jmp,offset);
+}
+static int luaK_getlabel(FuncState*fs){
+fs->lasttarget=fs->pc;
+return fs->pc;
+}
+static int getjump(FuncState*fs,int pc){
+int offset=GETARG_sBx(fs->f->code[pc]);
+if(offset==(-1))
+return(-1);
+else
+return(pc+1)+offset;
+}
+static Instruction*getjumpcontrol(FuncState*fs,int pc){
+Instruction*pi=&fs->f->code[pc];
+if(pc>=1&&testTMode(GET_OPCODE(*(pi-1))))
+return pi-1;
+else
+return pi;
+}
+static int need_value(FuncState*fs,int list){
+for(;list!=(-1);list=getjump(fs,list)){
+Instruction i=*getjumpcontrol(fs,list);
+if(GET_OPCODE(i)!=OP_TESTSET)return 1;
+}
+return 0;
+}
+static int patchtestreg(FuncState*fs,int node,int reg){
+Instruction*i=getjumpcontrol(fs,node);
+if(GET_OPCODE(*i)!=OP_TESTSET)
+return 0;
+if(reg!=((1<<8)-1)&&reg!=GETARG_B(*i))
+SETARG_A(*i,reg);
+else
+*i=CREATE_ABC(OP_TEST,GETARG_B(*i),0,GETARG_C(*i));
+return 1;
+}
+static void removevalues(FuncState*fs,int list){
+for(;list!=(-1);list=getjump(fs,list))
+patchtestreg(fs,list,((1<<8)-1));
+}
+static void patchlistaux(FuncState*fs,int list,int vtarget,int reg,
+int dtarget){
+while(list!=(-1)){
+int next=getjump(fs,list);
+if(patchtestreg(fs,list,reg))
+fixjump(fs,list,vtarget);
+else
+fixjump(fs,list,dtarget);
+list=next;
+}
+}
+static void dischargejpc(FuncState*fs){
+patchlistaux(fs,fs->jpc,fs->pc,((1<<8)-1),fs->pc);
+fs->jpc=(-1);
+}
+static void luaK_patchlist(FuncState*fs,int list,int target){
+if(target==fs->pc)
+luaK_patchtohere(fs,list);
+else{
+patchlistaux(fs,list,target,((1<<8)-1),target);
+}
+}
+static void luaK_patchtohere(FuncState*fs,int list){
+luaK_getlabel(fs);
+luaK_concat(fs,&fs->jpc,list);
+}
+static void luaK_concat(FuncState*fs,int*l1,int l2){
+if(l2==(-1))return;
+else if(*l1==(-1))
+*l1=l2;
+else{
+int list=*l1;
+int next;
+while((next=getjump(fs,list))!=(-1))
+list=next;
+fixjump(fs,list,l2);
+}
+}
+static void luaK_checkstack(FuncState*fs,int n){
+int newstack=fs->freereg+n;
+if(newstack>fs->f->maxstacksize){
+if(newstack>=250)
+luaX_syntaxerror(fs->ls,"function or expression too complex");
+fs->f->maxstacksize=cast_byte(newstack);
+}
+}
+static void luaK_reserveregs(FuncState*fs,int n){
+luaK_checkstack(fs,n);
+fs->freereg+=n;
+}
+static void freereg(FuncState*fs,int reg){
+if(!ISK(reg)&&reg>=fs->nactvar){
+fs->freereg--;
+}
+}
+static void freeexp(FuncState*fs,expdesc*e){
+if(e->k==VNONRELOC)
+freereg(fs,e->u.s.info);
+}
+static int addk(FuncState*fs,TValue*k,TValue*v){
+lua_State*L=fs->L;
+TValue*idx=luaH_set(L,fs->h,k);
+Proto*f=fs->f;
+int oldsize=f->sizek;
+if(ttisnumber(idx)){
+return cast_int(nvalue(idx));
+}
+else{
+setnvalue(idx,cast_num(fs->nk));
+luaM_growvector(L,f->k,fs->nk,f->sizek,TValue,
+((1<<(9+9))-1),"constant table overflow");
+while(oldsize<f->sizek)setnilvalue(&f->k[oldsize++]);
+setobj(L,&f->k[fs->nk],v);
+luaC_barrier(L,f,v);
+return fs->nk++;
+}
+}
+static int luaK_stringK(FuncState*fs,TString*s){
+TValue o;
+setsvalue(fs->L,&o,s);
+return addk(fs,&o,&o);
+}
+static int luaK_numberK(FuncState*fs,lua_Number r){
+TValue o;
+setnvalue(&o,r);
+return addk(fs,&o,&o);
+}
+static int boolK(FuncState*fs,int b){
+TValue o;
+setbvalue(&o,b);
+return addk(fs,&o,&o);
+}
+static int nilK(FuncState*fs){
+TValue k,v;
+setnilvalue(&v);
+sethvalue(fs->L,&k,fs->h);
+return addk(fs,&k,&v);
+}
+static void luaK_setreturns(FuncState*fs,expdesc*e,int nresults){
+if(e->k==VCALL){
+SETARG_C(getcode(fs,e),nresults+1);
+}
+else if(e->k==VVARARG){
+SETARG_B(getcode(fs,e),nresults+1);
+SETARG_A(getcode(fs,e),fs->freereg);
+luaK_reserveregs(fs,1);
+}
+}
+static void luaK_setoneret(FuncState*fs,expdesc*e){
+if(e->k==VCALL){
+e->k=VNONRELOC;
+e->u.s.info=GETARG_A(getcode(fs,e));
+}
+else if(e->k==VVARARG){
+SETARG_B(getcode(fs,e),2);
+e->k=VRELOCABLE;
+}
+}
+static void luaK_dischargevars(FuncState*fs,expdesc*e){
+switch(e->k){
+case VLOCAL:{
+e->k=VNONRELOC;
+break;
+}
+case VUPVAL:{
+e->u.s.info=luaK_codeABC(fs,OP_GETUPVAL,0,e->u.s.info,0);
+e->k=VRELOCABLE;
+break;
+}
+case VGLOBAL:{
+e->u.s.info=luaK_codeABx(fs,OP_GETGLOBAL,0,e->u.s.info);
+e->k=VRELOCABLE;
+break;
+}
+case VINDEXED:{
+freereg(fs,e->u.s.aux);
+freereg(fs,e->u.s.info);
+e->u.s.info=luaK_codeABC(fs,OP_GETTABLE,0,e->u.s.info,e->u.s.aux);
+e->k=VRELOCABLE;
+break;
+}
+case VVARARG:
+case VCALL:{
+luaK_setoneret(fs,e);
+break;
+}
+default:break;
+}
+}
+static int code_label(FuncState*fs,int A,int b,int jump){
+luaK_getlabel(fs);
+return luaK_codeABC(fs,OP_LOADBOOL,A,b,jump);
+}
+static void discharge2reg(FuncState*fs,expdesc*e,int reg){
+luaK_dischargevars(fs,e);
+switch(e->k){
+case VNIL:{
+luaK_nil(fs,reg,1);
+break;
+}
+case VFALSE:case VTRUE:{
+luaK_codeABC(fs,OP_LOADBOOL,reg,e->k==VTRUE,0);
+break;
+}
+case VK:{
+luaK_codeABx(fs,OP_LOADK,reg,e->u.s.info);
+break;
+}
+case VKNUM:{
+luaK_codeABx(fs,OP_LOADK,reg,luaK_numberK(fs,e->u.nval));
+break;
+}
+case VRELOCABLE:{
+Instruction*pc=&getcode(fs,e);
+SETARG_A(*pc,reg);
+break;
+}
+case VNONRELOC:{
+if(reg!=e->u.s.info)
+luaK_codeABC(fs,OP_MOVE,reg,e->u.s.info,0);
+break;
+}
+default:{
+return;
+}
+}
+e->u.s.info=reg;
+e->k=VNONRELOC;
+}
+static void discharge2anyreg(FuncState*fs,expdesc*e){
+if(e->k!=VNONRELOC){
+luaK_reserveregs(fs,1);
+discharge2reg(fs,e,fs->freereg-1);
+}
+}
+static void exp2reg(FuncState*fs,expdesc*e,int reg){
+discharge2reg(fs,e,reg);
+if(e->k==VJMP)
+luaK_concat(fs,&e->t,e->u.s.info);
+if(hasjumps(e)){
+int final;
+int p_f=(-1);
+int p_t=(-1);
+if(need_value(fs,e->t)||need_value(fs,e->f)){
+int fj=(e->k==VJMP)?(-1):luaK_jump(fs);
+p_f=code_label(fs,reg,0,1);
+p_t=code_label(fs,reg,1,0);
+luaK_patchtohere(fs,fj);
+}
+final=luaK_getlabel(fs);
+patchlistaux(fs,e->f,final,reg,p_f);
+patchlistaux(fs,e->t,final,reg,p_t);
+}
+e->f=e->t=(-1);
+e->u.s.info=reg;
+e->k=VNONRELOC;
+}
+static void luaK_exp2nextreg(FuncState*fs,expdesc*e){
+luaK_dischargevars(fs,e);
+freeexp(fs,e);
+luaK_reserveregs(fs,1);
+exp2reg(fs,e,fs->freereg-1);
+}
+static int luaK_exp2anyreg(FuncState*fs,expdesc*e){
+luaK_dischargevars(fs,e);
+if(e->k==VNONRELOC){
+if(!hasjumps(e))return e->u.s.info;
+if(e->u.s.info>=fs->nactvar){
+exp2reg(fs,e,e->u.s.info);
+return e->u.s.info;
+}
+}
+luaK_exp2nextreg(fs,e);
+return e->u.s.info;
+}
+static void luaK_exp2val(FuncState*fs,expdesc*e){
+if(hasjumps(e))
+luaK_exp2anyreg(fs,e);
+else
+luaK_dischargevars(fs,e);
+}
+static int luaK_exp2RK(FuncState*fs,expdesc*e){
+luaK_exp2val(fs,e);
+switch(e->k){
+case VKNUM:
+case VTRUE:
+case VFALSE:
+case VNIL:{
+if(fs->nk<=((1<<(9-1))-1)){
+e->u.s.info=(e->k==VNIL)?nilK(fs):
+(e->k==VKNUM)?luaK_numberK(fs,e->u.nval):
+boolK(fs,(e->k==VTRUE));
+e->k=VK;
+return RKASK(e->u.s.info);
+}
+else break;
+}
+case VK:{
+if(e->u.s.info<=((1<<(9-1))-1))
+return RKASK(e->u.s.info);
+else break;
+}
+default:break;
+}
+return luaK_exp2anyreg(fs,e);
+}
+static void luaK_storevar(FuncState*fs,expdesc*var,expdesc*ex){
+switch(var->k){
+case VLOCAL:{
+freeexp(fs,ex);
+exp2reg(fs,ex,var->u.s.info);
+return;
+}
+case VUPVAL:{
+int e=luaK_exp2anyreg(fs,ex);
+luaK_codeABC(fs,OP_SETUPVAL,e,var->u.s.info,0);
+break;
+}
+case VGLOBAL:{
+int e=luaK_exp2anyreg(fs,ex);
+luaK_codeABx(fs,OP_SETGLOBAL,e,var->u.s.info);
+break;
+}
+case VINDEXED:{
+int e=luaK_exp2RK(fs,ex);
+luaK_codeABC(fs,OP_SETTABLE,var->u.s.info,var->u.s.aux,e);
+break;
+}
+default:{
+break;
+}
+}
+freeexp(fs,ex);
+}
+static void luaK_self(FuncState*fs,expdesc*e,expdesc*key){
+int func;
+luaK_exp2anyreg(fs,e);
+freeexp(fs,e);
+func=fs->freereg;
+luaK_reserveregs(fs,2);
+luaK_codeABC(fs,OP_SELF,func,e->u.s.info,luaK_exp2RK(fs,key));
+freeexp(fs,key);
+e->u.s.info=func;
+e->k=VNONRELOC;
+}
+static void invertjump(FuncState*fs,expdesc*e){
+Instruction*pc=getjumpcontrol(fs,e->u.s.info);
+SETARG_A(*pc,!(GETARG_A(*pc)));
+}
+static int jumponcond(FuncState*fs,expdesc*e,int cond){
+if(e->k==VRELOCABLE){
+Instruction ie=getcode(fs,e);
+if(GET_OPCODE(ie)==OP_NOT){
+fs->pc--;
+return condjump(fs,OP_TEST,GETARG_B(ie),0,!cond);
+}
+}
+discharge2anyreg(fs,e);
+freeexp(fs,e);
+return condjump(fs,OP_TESTSET,((1<<8)-1),e->u.s.info,cond);
+}
+static void luaK_goiftrue(FuncState*fs,expdesc*e){
+int pc;
+luaK_dischargevars(fs,e);
+switch(e->k){
+case VK:case VKNUM:case VTRUE:{
+pc=(-1);
+break;
+}
+case VJMP:{
+invertjump(fs,e);
+pc=e->u.s.info;
+break;
+}
+default:{
+pc=jumponcond(fs,e,0);
+break;
+}
+}
+luaK_concat(fs,&e->f,pc);
+luaK_patchtohere(fs,e->t);
+e->t=(-1);
+}
+static void luaK_goiffalse(FuncState*fs,expdesc*e){
+int pc;
+luaK_dischargevars(fs,e);
+switch(e->k){
+case VNIL:case VFALSE:{
+pc=(-1);
+break;
+}
+case VJMP:{
+pc=e->u.s.info;
+break;
+}
+default:{
+pc=jumponcond(fs,e,1);
+break;
+}
+}
+luaK_concat(fs,&e->t,pc);
+luaK_patchtohere(fs,e->f);
+e->f=(-1);
+}
+static void codenot(FuncState*fs,expdesc*e){
+luaK_dischargevars(fs,e);
+switch(e->k){
+case VNIL:case VFALSE:{
+e->k=VTRUE;
+break;
+}
+case VK:case VKNUM:case VTRUE:{
+e->k=VFALSE;
+break;
+}
+case VJMP:{
+invertjump(fs,e);
+break;
+}
+case VRELOCABLE:
+case VNONRELOC:{
+discharge2anyreg(fs,e);
+freeexp(fs,e);
+e->u.s.info=luaK_codeABC(fs,OP_NOT,0,e->u.s.info,0);
+e->k=VRELOCABLE;
+break;
+}
+default:{
+break;
+}
+}
+{int temp=e->f;e->f=e->t;e->t=temp;}
+removevalues(fs,e->f);
+removevalues(fs,e->t);
+}
+static void luaK_indexed(FuncState*fs,expdesc*t,expdesc*k){
+t->u.s.aux=luaK_exp2RK(fs,k);
+t->k=VINDEXED;
+}
+static int constfolding(OpCode op,expdesc*e1,expdesc*e2){
+lua_Number v1,v2,r;
+if(!isnumeral(e1)||!isnumeral(e2))return 0;
+v1=e1->u.nval;
+v2=e2->u.nval;
+switch(op){
+case OP_ADD:r=luai_numadd(v1,v2);break;
+case OP_SUB:r=luai_numsub(v1,v2);break;
+case OP_MUL:r=luai_nummul(v1,v2);break;
+case OP_DIV:
+if(v2==0)return 0;
+r=luai_numdiv(v1,v2);break;
+case OP_MOD:
+if(v2==0)return 0;
+r=luai_nummod(v1,v2);break;
+case OP_POW:r=luai_numpow(v1,v2);break;
+case OP_UNM:r=luai_numunm(v1);break;
+case OP_LEN:return 0;
+default:r=0;break;
+}
+if(luai_numisnan(r))return 0;
+e1->u.nval=r;
+return 1;
+}
+static void codearith(FuncState*fs,OpCode op,expdesc*e1,expdesc*e2){
+if(constfolding(op,e1,e2))
+return;
+else{
+int o2=(op!=OP_UNM&&op!=OP_LEN)?luaK_exp2RK(fs,e2):0;
+int o1=luaK_exp2RK(fs,e1);
+if(o1>o2){
+freeexp(fs,e1);
+freeexp(fs,e2);
+}
+else{
+freeexp(fs,e2);
+freeexp(fs,e1);
+}
+e1->u.s.info=luaK_codeABC(fs,op,0,o1,o2);
+e1->k=VRELOCABLE;
+}
+}
+static void codecomp(FuncState*fs,OpCode op,int cond,expdesc*e1,
+expdesc*e2){
+int o1=luaK_exp2RK(fs,e1);
+int o2=luaK_exp2RK(fs,e2);
+freeexp(fs,e2);
+freeexp(fs,e1);
+if(cond==0&&op!=OP_EQ){
+int temp;
+temp=o1;o1=o2;o2=temp;
+cond=1;
+}
+e1->u.s.info=condjump(fs,op,cond,o1,o2);
+e1->k=VJMP;
+}
+static void luaK_prefix(FuncState*fs,UnOpr op,expdesc*e){
+expdesc e2;
+e2.t=e2.f=(-1);e2.k=VKNUM;e2.u.nval=0;
+switch(op){
+case OPR_MINUS:{
+if(!isnumeral(e))
+luaK_exp2anyreg(fs,e);
+codearith(fs,OP_UNM,e,&e2);
+break;
+}
+case OPR_NOT:codenot(fs,e);break;
+case OPR_LEN:{
+luaK_exp2anyreg(fs,e);
+codearith(fs,OP_LEN,e,&e2);
+break;
+}
+default:;
+}
+}
+static void luaK_infix(FuncState*fs,BinOpr op,expdesc*v){
+switch(op){
+case OPR_AND:{
+luaK_goiftrue(fs,v);
+break;
+}
+case OPR_OR:{
+luaK_goiffalse(fs,v);
+break;
+}
+case OPR_CONCAT:{
+luaK_exp2nextreg(fs,v);
+break;
+}
+case OPR_ADD:case OPR_SUB:case OPR_MUL:case OPR_DIV:
+case OPR_MOD:case OPR_POW:{
+if(!isnumeral(v))luaK_exp2RK(fs,v);
+break;
+}
+default:{
+luaK_exp2RK(fs,v);
+break;
+}
+}
+}
+static void luaK_posfix(FuncState*fs,BinOpr op,expdesc*e1,expdesc*e2){
+switch(op){
+case OPR_AND:{
+luaK_dischargevars(fs,e2);
+luaK_concat(fs,&e2->f,e1->f);
+*e1=*e2;
+break;
+}
+case OPR_OR:{
+luaK_dischargevars(fs,e2);
+luaK_concat(fs,&e2->t,e1->t);
+*e1=*e2;
+break;
+}
+case OPR_CONCAT:{
+luaK_exp2val(fs,e2);
+if(e2->k==VRELOCABLE&&GET_OPCODE(getcode(fs,e2))==OP_CONCAT){
+freeexp(fs,e1);
+SETARG_B(getcode(fs,e2),e1->u.s.info);
+e1->k=VRELOCABLE;e1->u.s.info=e2->u.s.info;
+}
+else{
+luaK_exp2nextreg(fs,e2);
+codearith(fs,OP_CONCAT,e1,e2);
+}
+break;
+}
+case OPR_ADD:codearith(fs,OP_ADD,e1,e2);break;
+case OPR_SUB:codearith(fs,OP_SUB,e1,e2);break;
+case OPR_MUL:codearith(fs,OP_MUL,e1,e2);break;
+case OPR_DIV:codearith(fs,OP_DIV,e1,e2);break;
+case OPR_MOD:codearith(fs,OP_MOD,e1,e2);break;
+case OPR_POW:codearith(fs,OP_POW,e1,e2);break;
+case OPR_EQ:codecomp(fs,OP_EQ,1,e1,e2);break;
+case OPR_NE:codecomp(fs,OP_EQ,0,e1,e2);break;
+case OPR_LT:codecomp(fs,OP_LT,1,e1,e2);break;
+case OPR_LE:codecomp(fs,OP_LE,1,e1,e2);break;
+case OPR_GT:codecomp(fs,OP_LT,0,e1,e2);break;
+case OPR_GE:codecomp(fs,OP_LE,0,e1,e2);break;
+default:;
+}
+}
+static void luaK_fixline(FuncState*fs,int line){
+fs->f->lineinfo[fs->pc-1]=line;
+}
+static int luaK_code(FuncState*fs,Instruction i,int line){
+Proto*f=fs->f;
+dischargejpc(fs);
+luaM_growvector(fs->L,f->code,fs->pc,f->sizecode,Instruction,
+(INT_MAX-2),"code size overflow");
+f->code[fs->pc]=i;
+luaM_growvector(fs->L,f->lineinfo,fs->pc,f->sizelineinfo,int,
+(INT_MAX-2),"code size overflow");
+f->lineinfo[fs->pc]=line;
+return fs->pc++;
+}
+static int luaK_codeABC(FuncState*fs,OpCode o,int a,int b,int c){
+return luaK_code(fs,CREATE_ABC(o,a,b,c),fs->ls->lastline);
+}
+static int luaK_codeABx(FuncState*fs,OpCode o,int a,unsigned int bc){
+return luaK_code(fs,CREATE_ABx(o,a,bc),fs->ls->lastline);
+}
+static void luaK_setlist(FuncState*fs,int base,int nelems,int tostore){
+int c=(nelems-1)/50+1;
+int b=(tostore==(-1))?0:tostore;
+if(c<=((1<<9)-1))
+luaK_codeABC(fs,OP_SETLIST,base,b,c);
+else{
+luaK_codeABC(fs,OP_SETLIST,base,b,0);
+luaK_code(fs,cast(Instruction,c),fs->ls->lastline);
+}
+fs->freereg=base+1;
+}
+#define hasmultret(k)((k)==VCALL||(k)==VVARARG)
+#define getlocvar(fs,i)((fs)->f->locvars[(fs)->actvar[i]])
+#define luaY_checklimit(fs,v,l,m)if((v)>(l))errorlimit(fs,l,m)
+typedef struct BlockCnt{
+struct BlockCnt*previous;
+int breaklist;
+lu_byte nactvar;
+lu_byte upval;
+lu_byte isbreakable;
+}BlockCnt;
+static void chunk(LexState*ls);
+static void expr(LexState*ls,expdesc*v);
+static void anchor_token(LexState*ls){
+if(ls->t.token==TK_NAME||ls->t.token==TK_STRING){
+TString*ts=ls->t.seminfo.ts;
+luaX_newstring(ls,getstr(ts),ts->tsv.len);
+}
+}
+static void error_expected(LexState*ls,int token){
+luaX_syntaxerror(ls,
+luaO_pushfstring(ls->L,LUA_QL("%s")" expected",luaX_token2str(ls,token)));
+}
+static void errorlimit(FuncState*fs,int limit,const char*what){
+const char*msg=(fs->f->linedefined==0)?
+luaO_pushfstring(fs->L,"main function has more than %d %s",limit,what):
+luaO_pushfstring(fs->L,"function at line %d has more than %d %s",
+fs->f->linedefined,limit,what);
+luaX_lexerror(fs->ls,msg,0);
+}
+static int testnext(LexState*ls,int c){
+if(ls->t.token==c){
+luaX_next(ls);
+return 1;
+}
+else return 0;
+}
+static void check(LexState*ls,int c){
+if(ls->t.token!=c)
+error_expected(ls,c);
+}
+static void checknext(LexState*ls,int c){
+check(ls,c);
+luaX_next(ls);
+}
+#define check_condition(ls,c,msg){if(!(c))luaX_syntaxerror(ls,msg);}
+static void check_match(LexState*ls,int what,int who,int where){
+if(!testnext(ls,what)){
+if(where==ls->linenumber)
+error_expected(ls,what);
+else{
+luaX_syntaxerror(ls,luaO_pushfstring(ls->L,
+LUA_QL("%s")" expected (to close "LUA_QL("%s")" at line %d)",
+luaX_token2str(ls,what),luaX_token2str(ls,who),where));
+}
+}
+}
+static TString*str_checkname(LexState*ls){
+TString*ts;
+check(ls,TK_NAME);
+ts=ls->t.seminfo.ts;
+luaX_next(ls);
+return ts;
+}
+static void init_exp(expdesc*e,expkind k,int i){
+e->f=e->t=(-1);
+e->k=k;
+e->u.s.info=i;
+}
+static void codestring(LexState*ls,expdesc*e,TString*s){
+init_exp(e,VK,luaK_stringK(ls->fs,s));
+}
+static void checkname(LexState*ls,expdesc*e){
+codestring(ls,e,str_checkname(ls));
+}
+static int registerlocalvar(LexState*ls,TString*varname){
+FuncState*fs=ls->fs;
+Proto*f=fs->f;
+int oldsize=f->sizelocvars;
+luaM_growvector(ls->L,f->locvars,fs->nlocvars,f->sizelocvars,
+LocVar,SHRT_MAX,"too many local variables");
+while(oldsize<f->sizelocvars)f->locvars[oldsize++].varname=NULL;
+f->locvars[fs->nlocvars].varname=varname;
+luaC_objbarrier(ls->L,f,varname);
+return fs->nlocvars++;
+}
+#define new_localvarliteral(ls,v,n)new_localvar(ls,luaX_newstring(ls,""v,(sizeof(v)/sizeof(char))-1),n)
+static void new_localvar(LexState*ls,TString*name,int n){
+FuncState*fs=ls->fs;
+luaY_checklimit(fs,fs->nactvar+n+1,200,"local variables");
+fs->actvar[fs->nactvar+n]=cast(unsigned short,registerlocalvar(ls,name));
+}
+static void adjustlocalvars(LexState*ls,int nvars){
+FuncState*fs=ls->fs;
+fs->nactvar=cast_byte(fs->nactvar+nvars);
+for(;nvars;nvars--){
+getlocvar(fs,fs->nactvar-nvars).startpc=fs->pc;
+}
+}
+static void removevars(LexState*ls,int tolevel){
+FuncState*fs=ls->fs;
+while(fs->nactvar>tolevel)
+getlocvar(fs,--fs->nactvar).endpc=fs->pc;
+}
+static int indexupvalue(FuncState*fs,TString*name,expdesc*v){
+int i;
+Proto*f=fs->f;
+int oldsize=f->sizeupvalues;
+for(i=0;i<f->nups;i++){
+if(fs->upvalues[i].k==v->k&&fs->upvalues[i].info==v->u.s.info){
+return i;
+}
+}
+luaY_checklimit(fs,f->nups+1,60,"upvalues");
+luaM_growvector(fs->L,f->upvalues,f->nups,f->sizeupvalues,
+TString*,(INT_MAX-2),"");
+while(oldsize<f->sizeupvalues)f->upvalues[oldsize++]=NULL;
+f->upvalues[f->nups]=name;
+luaC_objbarrier(fs->L,f,name);
+fs->upvalues[f->nups].k=cast_byte(v->k);
+fs->upvalues[f->nups].info=cast_byte(v->u.s.info);
+return f->nups++;
+}
+static int searchvar(FuncState*fs,TString*n){
+int i;
+for(i=fs->nactvar-1;i>=0;i--){
+if(n==getlocvar(fs,i).varname)
+return i;
+}
+return-1;
+}
+static void markupval(FuncState*fs,int level){
+BlockCnt*bl=fs->bl;
+while(bl&&bl->nactvar>level)bl=bl->previous;
+if(bl)bl->upval=1;
+}
+static int singlevaraux(FuncState*fs,TString*n,expdesc*var,int base){
+if(fs==NULL){
+init_exp(var,VGLOBAL,((1<<8)-1));
+return VGLOBAL;
+}
+else{
+int v=searchvar(fs,n);
+if(v>=0){
+init_exp(var,VLOCAL,v);
+if(!base)
+markupval(fs,v);
+return VLOCAL;
+}
+else{
+if(singlevaraux(fs->prev,n,var,0)==VGLOBAL)
+return VGLOBAL;
+var->u.s.info=indexupvalue(fs,n,var);
+var->k=VUPVAL;
+return VUPVAL;
+}
+}
+}
+static void singlevar(LexState*ls,expdesc*var){
+TString*varname=str_checkname(ls);
+FuncState*fs=ls->fs;
+if(singlevaraux(fs,varname,var,1)==VGLOBAL)
+var->u.s.info=luaK_stringK(fs,varname);
+}
+static void adjust_assign(LexState*ls,int nvars,int nexps,expdesc*e){
+FuncState*fs=ls->fs;
+int extra=nvars-nexps;
+if(hasmultret(e->k)){
+extra++;
+if(extra<0)extra=0;
+luaK_setreturns(fs,e,extra);
+if(extra>1)luaK_reserveregs(fs,extra-1);
+}
+else{
+if(e->k!=VVOID)luaK_exp2nextreg(fs,e);
+if(extra>0){
+int reg=fs->freereg;
+luaK_reserveregs(fs,extra);
+luaK_nil(fs,reg,extra);
+}
+}
+}
+static void enterlevel(LexState*ls){
+if(++ls->L->nCcalls>200)
+luaX_lexerror(ls,"chunk has too many syntax levels",0);
+}
+#define leavelevel(ls)((ls)->L->nCcalls--)
+static void enterblock(FuncState*fs,BlockCnt*bl,lu_byte isbreakable){
+bl->breaklist=(-1);
+bl->isbreakable=isbreakable;
+bl->nactvar=fs->nactvar;
+bl->upval=0;
+bl->previous=fs->bl;
+fs->bl=bl;
+}
+static void leaveblock(FuncState*fs){
+BlockCnt*bl=fs->bl;
+fs->bl=bl->previous;
+removevars(fs->ls,bl->nactvar);
+if(bl->upval)
+luaK_codeABC(fs,OP_CLOSE,bl->nactvar,0,0);
+fs->freereg=fs->nactvar;
+luaK_patchtohere(fs,bl->breaklist);
+}
+static void pushclosure(LexState*ls,FuncState*func,expdesc*v){
+FuncState*fs=ls->fs;
+Proto*f=fs->f;
+int oldsize=f->sizep;
+int i;
+luaM_growvector(ls->L,f->p,fs->np,f->sizep,Proto*,
+((1<<(9+9))-1),"constant table overflow");
+while(oldsize<f->sizep)f->p[oldsize++]=NULL;
+f->p[fs->np++]=func->f;
+luaC_objbarrier(ls->L,f,func->f);
+init_exp(v,VRELOCABLE,luaK_codeABx(fs,OP_CLOSURE,0,fs->np-1));
+for(i=0;i<func->f->nups;i++){
+OpCode o=(func->upvalues[i].k==VLOCAL)?OP_MOVE:OP_GETUPVAL;
+luaK_codeABC(fs,o,0,func->upvalues[i].info,0);
+}
+}
+static void open_func(LexState*ls,FuncState*fs){
+lua_State*L=ls->L;
+Proto*f=luaF_newproto(L);
+fs->f=f;
+fs->prev=ls->fs;
+fs->ls=ls;
+fs->L=L;
+ls->fs=fs;
+fs->pc=0;
+fs->lasttarget=-1;
+fs->jpc=(-1);
+fs->freereg=0;
+fs->nk=0;
+fs->np=0;
+fs->nlocvars=0;
+fs->nactvar=0;
+fs->bl=NULL;
+f->source=ls->source;
+f->maxstacksize=2;
+fs->h=luaH_new(L,0,0);
+sethvalue(L,L->top,fs->h);
+incr_top(L);
+setptvalue(L,L->top,f);
+incr_top(L);
+}
+static void close_func(LexState*ls){
+lua_State*L=ls->L;
+FuncState*fs=ls->fs;
+Proto*f=fs->f;
+removevars(ls,0);
+luaK_ret(fs,0,0);
+luaM_reallocvector(L,f->code,f->sizecode,fs->pc,Instruction);
+f->sizecode=fs->pc;
+luaM_reallocvector(L,f->lineinfo,f->sizelineinfo,fs->pc,int);
+f->sizelineinfo=fs->pc;
+luaM_reallocvector(L,f->k,f->sizek,fs->nk,TValue);
+f->sizek=fs->nk;
+luaM_reallocvector(L,f->p,f->sizep,fs->np,Proto*);
+f->sizep=fs->np;
+luaM_reallocvector(L,f->locvars,f->sizelocvars,fs->nlocvars,LocVar);
+f->sizelocvars=fs->nlocvars;
+luaM_reallocvector(L,f->upvalues,f->sizeupvalues,f->nups,TString*);
+f->sizeupvalues=f->nups;
+ls->fs=fs->prev;
+if(fs)anchor_token(ls);
+L->top-=2;
+}
+static Proto*luaY_parser(lua_State*L,ZIO*z,Mbuffer*buff,const char*name){
+struct LexState lexstate;
+struct FuncState funcstate;
+lexstate.buff=buff;
+luaX_setinput(L,&lexstate,z,luaS_new(L,name));
+open_func(&lexstate,&funcstate);
+funcstate.f->is_vararg=2;
+luaX_next(&lexstate);
+chunk(&lexstate);
+check(&lexstate,TK_EOS);
+close_func(&lexstate);
+return funcstate.f;
+}
+static void field(LexState*ls,expdesc*v){
+FuncState*fs=ls->fs;
+expdesc key;
+luaK_exp2anyreg(fs,v);
+luaX_next(ls);
+checkname(ls,&key);
+luaK_indexed(fs,v,&key);
+}
+static void yindex(LexState*ls,expdesc*v){
+luaX_next(ls);
+expr(ls,v);
+luaK_exp2val(ls->fs,v);
+checknext(ls,']');
+}
+struct ConsControl{
+expdesc v;
+expdesc*t;
+int nh;
+int na;
+int tostore;
+};
+static void recfield(LexState*ls,struct ConsControl*cc){
+FuncState*fs=ls->fs;
+int reg=ls->fs->freereg;
+expdesc key,val;
+int rkkey;
+if(ls->t.token==TK_NAME){
+luaY_checklimit(fs,cc->nh,(INT_MAX-2),"items in a constructor");
+checkname(ls,&key);
+}
+else
+yindex(ls,&key);
+cc->nh++;
+checknext(ls,'=');
+rkkey=luaK_exp2RK(fs,&key);
+expr(ls,&val);
+luaK_codeABC(fs,OP_SETTABLE,cc->t->u.s.info,rkkey,luaK_exp2RK(fs,&val));
+fs->freereg=reg;
+}
+static void closelistfield(FuncState*fs,struct ConsControl*cc){
+if(cc->v.k==VVOID)return;
+luaK_exp2nextreg(fs,&cc->v);
+cc->v.k=VVOID;
+if(cc->tostore==50){
+luaK_setlist(fs,cc->t->u.s.info,cc->na,cc->tostore);
+cc->tostore=0;
+}
+}
+static void lastlistfield(FuncState*fs,struct ConsControl*cc){
+if(cc->tostore==0)return;
+if(hasmultret(cc->v.k)){
+luaK_setmultret(fs,&cc->v);
+luaK_setlist(fs,cc->t->u.s.info,cc->na,(-1));
+cc->na--;
+}
+else{
+if(cc->v.k!=VVOID)
+luaK_exp2nextreg(fs,&cc->v);
+luaK_setlist(fs,cc->t->u.s.info,cc->na,cc->tostore);
+}
+}
+static void listfield(LexState*ls,struct ConsControl*cc){
+expr(ls,&cc->v);
+luaY_checklimit(ls->fs,cc->na,(INT_MAX-2),"items in a constructor");
+cc->na++;
+cc->tostore++;
+}
+static void constructor(LexState*ls,expdesc*t){
+FuncState*fs=ls->fs;
+int line=ls->linenumber;
+int pc=luaK_codeABC(fs,OP_NEWTABLE,0,0,0);
+struct ConsControl cc;
+cc.na=cc.nh=cc.tostore=0;
+cc.t=t;
+init_exp(t,VRELOCABLE,pc);
+init_exp(&cc.v,VVOID,0);
+luaK_exp2nextreg(ls->fs,t);
+checknext(ls,'{');
+do{
+if(ls->t.token=='}')break;
+closelistfield(fs,&cc);
+switch(ls->t.token){
+case TK_NAME:{
+luaX_lookahead(ls);
+if(ls->lookahead.token!='=')
+listfield(ls,&cc);
+else
+recfield(ls,&cc);
+break;
+}
+case'[':{
+recfield(ls,&cc);
+break;
+}
+default:{
+listfield(ls,&cc);
+break;
+}
+}
+}while(testnext(ls,',')||testnext(ls,';'));
+check_match(ls,'}','{',line);
+lastlistfield(fs,&cc);
+SETARG_B(fs->f->code[pc],luaO_int2fb(cc.na));
+SETARG_C(fs->f->code[pc],luaO_int2fb(cc.nh));
+}
+static void parlist(LexState*ls){
+FuncState*fs=ls->fs;
+Proto*f=fs->f;
+int nparams=0;
+f->is_vararg=0;
+if(ls->t.token!=')'){
+do{
+switch(ls->t.token){
+case TK_NAME:{
+new_localvar(ls,str_checkname(ls),nparams++);
+break;
+}
+case TK_DOTS:{
+luaX_next(ls);
+f->is_vararg|=2;
+break;
+}
+default:luaX_syntaxerror(ls,"<name> or "LUA_QL("...")" expected");
+}
+}while(!f->is_vararg&&testnext(ls,','));
+}
+adjustlocalvars(ls,nparams);
+f->numparams=cast_byte(fs->nactvar-(f->is_vararg&1));
+luaK_reserveregs(fs,fs->nactvar);
+}
+static void body(LexState*ls,expdesc*e,int needself,int line){
+FuncState new_fs;
+open_func(ls,&new_fs);
+new_fs.f->linedefined=line;
+checknext(ls,'(');
+if(needself){
+new_localvarliteral(ls,"self",0);
+adjustlocalvars(ls,1);
+}
+parlist(ls);
+checknext(ls,')');
+chunk(ls);
+new_fs.f->lastlinedefined=ls->linenumber;
+check_match(ls,TK_END,TK_FUNCTION,line);
+close_func(ls);
+pushclosure(ls,&new_fs,e);
+}
+static int explist1(LexState*ls,expdesc*v){
+int n=1;
+expr(ls,v);
+while(testnext(ls,',')){
+luaK_exp2nextreg(ls->fs,v);
+expr(ls,v);
+n++;
+}
+return n;
+}
+static void funcargs(LexState*ls,expdesc*f){
+FuncState*fs=ls->fs;
+expdesc args;
+int base,nparams;
+int line=ls->linenumber;
+switch(ls->t.token){
+case'(':{
+if(line!=ls->lastline)
+luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)");
+luaX_next(ls);
+if(ls->t.token==')')
+args.k=VVOID;
+else{
+explist1(ls,&args);
+luaK_setmultret(fs,&args);
+}
+check_match(ls,')','(',line);
+break;
+}
+case'{':{
+constructor(ls,&args);
+break;
+}
+case TK_STRING:{
+codestring(ls,&args,ls->t.seminfo.ts);
+luaX_next(ls);
+break;
+}
+default:{
+luaX_syntaxerror(ls,"function arguments expected");
+return;
+}
+}
+base=f->u.s.info;
+if(hasmultret(args.k))
+nparams=(-1);
+else{
+if(args.k!=VVOID)
+luaK_exp2nextreg(fs,&args);
+nparams=fs->freereg-(base+1);
+}
+init_exp(f,VCALL,luaK_codeABC(fs,OP_CALL,base,nparams+1,2));
+luaK_fixline(fs,line);
+fs->freereg=base+1;
+}
+static void prefixexp(LexState*ls,expdesc*v){
+switch(ls->t.token){
+case'(':{
+int line=ls->linenumber;
+luaX_next(ls);
+expr(ls,v);
+check_match(ls,')','(',line);
+luaK_dischargevars(ls->fs,v);
+return;
+}
+case TK_NAME:{
+singlevar(ls,v);
+return;
+}
+default:{
+luaX_syntaxerror(ls,"unexpected symbol");
+return;
+}
+}
+}
+static void primaryexp(LexState*ls,expdesc*v){
+FuncState*fs=ls->fs;
+prefixexp(ls,v);
+for(;;){
+switch(ls->t.token){
+case'.':{
+field(ls,v);
+break;
+}
+case'[':{
+expdesc key;
+luaK_exp2anyreg(fs,v);
+yindex(ls,&key);
+luaK_indexed(fs,v,&key);
+break;
+}
+case':':{
+expdesc key;
+luaX_next(ls);
+checkname(ls,&key);
+luaK_self(fs,v,&key);
+funcargs(ls,v);
+break;
+}
+case'(':case TK_STRING:case'{':{
+luaK_exp2nextreg(fs,v);
+funcargs(ls,v);
+break;
+}
+default:return;
+}
+}
+}
+static void simpleexp(LexState*ls,expdesc*v){
+switch(ls->t.token){
+case TK_NUMBER:{
+init_exp(v,VKNUM,0);
+v->u.nval=ls->t.seminfo.r;
+break;
+}
+case TK_STRING:{
+codestring(ls,v,ls->t.seminfo.ts);
+break;
+}
+case TK_NIL:{
+init_exp(v,VNIL,0);
+break;
+}
+case TK_TRUE:{
+init_exp(v,VTRUE,0);
+break;
+}
+case TK_FALSE:{
+init_exp(v,VFALSE,0);
+break;
+}
+case TK_DOTS:{
+FuncState*fs=ls->fs;
+check_condition(ls,fs->f->is_vararg,
+"cannot use "LUA_QL("...")" outside a vararg function");
+fs->f->is_vararg&=~4;
+init_exp(v,VVARARG,luaK_codeABC(fs,OP_VARARG,0,1,0));
+break;
+}
+case'{':{
+constructor(ls,v);
+return;
+}
+case TK_FUNCTION:{
+luaX_next(ls);
+body(ls,v,0,ls->linenumber);
+return;
+}
+default:{
+primaryexp(ls,v);
+return;
+}
+}
+luaX_next(ls);
+}
+static UnOpr getunopr(int op){
+switch(op){
+case TK_NOT:return OPR_NOT;
+case'-':return OPR_MINUS;
+case'#':return OPR_LEN;
+default:return OPR_NOUNOPR;
+}
+}
+static BinOpr getbinopr(int op){
+switch(op){
+case'+':return OPR_ADD;
+case'-':return OPR_SUB;
+case'*':return OPR_MUL;
+case'/':return OPR_DIV;
+case'%':return OPR_MOD;
+case'^':return OPR_POW;
+case TK_CONCAT:return OPR_CONCAT;
+case TK_NE:return OPR_NE;
+case TK_EQ:return OPR_EQ;
+case'<':return OPR_LT;
+case TK_LE:return OPR_LE;
+case'>':return OPR_GT;
+case TK_GE:return OPR_GE;
+case TK_AND:return OPR_AND;
+case TK_OR:return OPR_OR;
+default:return OPR_NOBINOPR;
+}
+}
+static const struct{
+lu_byte left;
+lu_byte right;
+}priority[]={
+{6,6},{6,6},{7,7},{7,7},{7,7},
+{10,9},{5,4},
+{3,3},{3,3},
+{3,3},{3,3},{3,3},{3,3},
+{2,2},{1,1}
+};
+static BinOpr subexpr(LexState*ls,expdesc*v,unsigned int limit){
+BinOpr op;
+UnOpr uop;
+enterlevel(ls);
+uop=getunopr(ls->t.token);
+if(uop!=OPR_NOUNOPR){
+luaX_next(ls);
+subexpr(ls,v,8);
+luaK_prefix(ls->fs,uop,v);
+}
+else simpleexp(ls,v);
+op=getbinopr(ls->t.token);
+while(op!=OPR_NOBINOPR&&priority[op].left>limit){
+expdesc v2;
+BinOpr nextop;
+luaX_next(ls);
+luaK_infix(ls->fs,op,v);
+nextop=subexpr(ls,&v2,priority[op].right);
+luaK_posfix(ls->fs,op,v,&v2);
+op=nextop;
+}
+leavelevel(ls);
+return op;
+}
+static void expr(LexState*ls,expdesc*v){
+subexpr(ls,v,0);
+}
+static int block_follow(int token){
+switch(token){
+case TK_ELSE:case TK_ELSEIF:case TK_END:
+case TK_UNTIL:case TK_EOS:
+return 1;
+default:return 0;
+}
+}
+static void block(LexState*ls){
+FuncState*fs=ls->fs;
+BlockCnt bl;
+enterblock(fs,&bl,0);
+chunk(ls);
+leaveblock(fs);
+}
+struct LHS_assign{
+struct LHS_assign*prev;
+expdesc v;
+};
+static void check_conflict(LexState*ls,struct LHS_assign*lh,expdesc*v){
+FuncState*fs=ls->fs;
+int extra=fs->freereg;
+int conflict=0;
+for(;lh;lh=lh->prev){
+if(lh->v.k==VINDEXED){
+if(lh->v.u.s.info==v->u.s.info){
+conflict=1;
+lh->v.u.s.info=extra;
+}
+if(lh->v.u.s.aux==v->u.s.info){
+conflict=1;
+lh->v.u.s.aux=extra;
+}
+}
+}
+if(conflict){
+luaK_codeABC(fs,OP_MOVE,fs->freereg,v->u.s.info,0);
+luaK_reserveregs(fs,1);
+}
+}
+static void assignment(LexState*ls,struct LHS_assign*lh,int nvars){
+expdesc e;
+check_condition(ls,VLOCAL<=lh->v.k&&lh->v.k<=VINDEXED,
+"syntax error");
+if(testnext(ls,',')){
+struct LHS_assign nv;
+nv.prev=lh;
+primaryexp(ls,&nv.v);
+if(nv.v.k==VLOCAL)
+check_conflict(ls,lh,&nv.v);
+luaY_checklimit(ls->fs,nvars,200-ls->L->nCcalls,
+"variables in assignment");
+assignment(ls,&nv,nvars+1);
+}
+else{
+int nexps;
+checknext(ls,'=');
+nexps=explist1(ls,&e);
+if(nexps!=nvars){
+adjust_assign(ls,nvars,nexps,&e);
+if(nexps>nvars)
+ls->fs->freereg-=nexps-nvars;
+}
+else{
+luaK_setoneret(ls->fs,&e);
+luaK_storevar(ls->fs,&lh->v,&e);
+return;
+}
+}
+init_exp(&e,VNONRELOC,ls->fs->freereg-1);
+luaK_storevar(ls->fs,&lh->v,&e);
+}
+static int cond(LexState*ls){
+expdesc v;
+expr(ls,&v);
+if(v.k==VNIL)v.k=VFALSE;
+luaK_goiftrue(ls->fs,&v);
+return v.f;
+}
+static void breakstat(LexState*ls){
+FuncState*fs=ls->fs;
+BlockCnt*bl=fs->bl;
+int upval=0;
+while(bl&&!bl->isbreakable){
+upval|=bl->upval;
+bl=bl->previous;
+}
+if(!bl)
+luaX_syntaxerror(ls,"no loop to break");
+if(upval)
+luaK_codeABC(fs,OP_CLOSE,bl->nactvar,0,0);
+luaK_concat(fs,&bl->breaklist,luaK_jump(fs));
+}
+static void whilestat(LexState*ls,int line){
+FuncState*fs=ls->fs;
+int whileinit;
+int condexit;
+BlockCnt bl;
+luaX_next(ls);
+whileinit=luaK_getlabel(fs);
+condexit=cond(ls);
+enterblock(fs,&bl,1);
+checknext(ls,TK_DO);
+block(ls);
+luaK_patchlist(fs,luaK_jump(fs),whileinit);
+check_match(ls,TK_END,TK_WHILE,line);
+leaveblock(fs);
+luaK_patchtohere(fs,condexit);
+}
+static void repeatstat(LexState*ls,int line){
+int condexit;
+FuncState*fs=ls->fs;
+int repeat_init=luaK_getlabel(fs);
+BlockCnt bl1,bl2;
+enterblock(fs,&bl1,1);
+enterblock(fs,&bl2,0);
+luaX_next(ls);
+chunk(ls);
+check_match(ls,TK_UNTIL,TK_REPEAT,line);
+condexit=cond(ls);
+if(!bl2.upval){
+leaveblock(fs);
+luaK_patchlist(ls->fs,condexit,repeat_init);
+}
+else{
+breakstat(ls);
+luaK_patchtohere(ls->fs,condexit);
+leaveblock(fs);
+luaK_patchlist(ls->fs,luaK_jump(fs),repeat_init);
+}
+leaveblock(fs);
+}
+static int exp1(LexState*ls){
+expdesc e;
+int k;
+expr(ls,&e);
+k=e.k;
+luaK_exp2nextreg(ls->fs,&e);
+return k;
+}
+static void forbody(LexState*ls,int base,int line,int nvars,int isnum){
+BlockCnt bl;
+FuncState*fs=ls->fs;
+int prep,endfor;
+adjustlocalvars(ls,3);
+checknext(ls,TK_DO);
+prep=isnum?luaK_codeAsBx(fs,OP_FORPREP,base,(-1)):luaK_jump(fs);
+enterblock(fs,&bl,0);
+adjustlocalvars(ls,nvars);
+luaK_reserveregs(fs,nvars);
+block(ls);
+leaveblock(fs);
+luaK_patchtohere(fs,prep);
+endfor=(isnum)?luaK_codeAsBx(fs,OP_FORLOOP,base,(-1)):
+luaK_codeABC(fs,OP_TFORLOOP,base,0,nvars);
+luaK_fixline(fs,line);
+luaK_patchlist(fs,(isnum?endfor:luaK_jump(fs)),prep+1);
+}
+static void fornum(LexState*ls,TString*varname,int line){
+FuncState*fs=ls->fs;
+int base=fs->freereg;
+new_localvarliteral(ls,"(for index)",0);
+new_localvarliteral(ls,"(for limit)",1);
+new_localvarliteral(ls,"(for step)",2);
+new_localvar(ls,varname,3);
+checknext(ls,'=');
+exp1(ls);
+checknext(ls,',');
+exp1(ls);
+if(testnext(ls,','))
+exp1(ls);
+else{
+luaK_codeABx(fs,OP_LOADK,fs->freereg,luaK_numberK(fs,1));
+luaK_reserveregs(fs,1);
+}
+forbody(ls,base,line,1,1);
+}
+static void forlist(LexState*ls,TString*indexname){
+FuncState*fs=ls->fs;
+expdesc e;
+int nvars=0;
+int line;
+int base=fs->freereg;
+new_localvarliteral(ls,"(for generator)",nvars++);
+new_localvarliteral(ls,"(for state)",nvars++);
+new_localvarliteral(ls,"(for control)",nvars++);
+new_localvar(ls,indexname,nvars++);
+while(testnext(ls,','))
+new_localvar(ls,str_checkname(ls),nvars++);
+checknext(ls,TK_IN);
+line=ls->linenumber;
+adjust_assign(ls,3,explist1(ls,&e),&e);
+luaK_checkstack(fs,3);
+forbody(ls,base,line,nvars-3,0);
+}
+static void forstat(LexState*ls,int line){
+FuncState*fs=ls->fs;
+TString*varname;
+BlockCnt bl;
+enterblock(fs,&bl,1);
+luaX_next(ls);
+varname=str_checkname(ls);
+switch(ls->t.token){
+case'=':fornum(ls,varname,line);break;
+case',':case TK_IN:forlist(ls,varname);break;
+default:luaX_syntaxerror(ls,LUA_QL("=")" or "LUA_QL("in")" expected");
+}
+check_match(ls,TK_END,TK_FOR,line);
+leaveblock(fs);
+}
+static int test_then_block(LexState*ls){
+int condexit;
+luaX_next(ls);
+condexit=cond(ls);
+checknext(ls,TK_THEN);
+block(ls);
+return condexit;
+}
+static void ifstat(LexState*ls,int line){
+FuncState*fs=ls->fs;
+int flist;
+int escapelist=(-1);
+flist=test_then_block(ls);
+while(ls->t.token==TK_ELSEIF){
+luaK_concat(fs,&escapelist,luaK_jump(fs));
+luaK_patchtohere(fs,flist);
+flist=test_then_block(ls);
+}
+if(ls->t.token==TK_ELSE){
+luaK_concat(fs,&escapelist,luaK_jump(fs));
+luaK_patchtohere(fs,flist);
+luaX_next(ls);
+block(ls);
+}
+else
+luaK_concat(fs,&escapelist,flist);
+luaK_patchtohere(fs,escapelist);
+check_match(ls,TK_END,TK_IF,line);
+}
+static void localfunc(LexState*ls){
+expdesc v,b;
+FuncState*fs=ls->fs;
+new_localvar(ls,str_checkname(ls),0);
+init_exp(&v,VLOCAL,fs->freereg);
+luaK_reserveregs(fs,1);
+adjustlocalvars(ls,1);
+body(ls,&b,0,ls->linenumber);
+luaK_storevar(fs,&v,&b);
+getlocvar(fs,fs->nactvar-1).startpc=fs->pc;
+}
+static void localstat(LexState*ls){
+int nvars=0;
+int nexps;
+expdesc e;
+do{
+new_localvar(ls,str_checkname(ls),nvars++);
+}while(testnext(ls,','));
+if(testnext(ls,'='))
+nexps=explist1(ls,&e);
+else{
+e.k=VVOID;
+nexps=0;
+}
+adjust_assign(ls,nvars,nexps,&e);
+adjustlocalvars(ls,nvars);
+}
+static int funcname(LexState*ls,expdesc*v){
+int needself=0;
+singlevar(ls,v);
+while(ls->t.token=='.')
+field(ls,v);
+if(ls->t.token==':'){
+needself=1;
+field(ls,v);
+}
+return needself;
+}
+static void funcstat(LexState*ls,int line){
+int needself;
+expdesc v,b;
+luaX_next(ls);
+needself=funcname(ls,&v);
+body(ls,&b,needself,line);
+luaK_storevar(ls->fs,&v,&b);
+luaK_fixline(ls->fs,line);
+}
+static void exprstat(LexState*ls){
+FuncState*fs=ls->fs;
+struct LHS_assign v;
+primaryexp(ls,&v.v);
+if(v.v.k==VCALL)
+SETARG_C(getcode(fs,&v.v),1);
+else{
+v.prev=NULL;
+assignment(ls,&v,1);
+}
+}
+static void retstat(LexState*ls){
+FuncState*fs=ls->fs;
+expdesc e;
+int first,nret;
+luaX_next(ls);
+if(block_follow(ls->t.token)||ls->t.token==';')
+first=nret=0;
+else{
+nret=explist1(ls,&e);
+if(hasmultret(e.k)){
+luaK_setmultret(fs,&e);
+if(e.k==VCALL&&nret==1){
+SET_OPCODE(getcode(fs,&e),OP_TAILCALL);
+}
+first=fs->nactvar;
+nret=(-1);
+}
+else{
+if(nret==1)
+first=luaK_exp2anyreg(fs,&e);
+else{
+luaK_exp2nextreg(fs,&e);
+first=fs->nactvar;
+}
+}
+}
+luaK_ret(fs,first,nret);
+}
+static int statement(LexState*ls){
+int line=ls->linenumber;
+switch(ls->t.token){
+case TK_IF:{
+ifstat(ls,line);
+return 0;
+}
+case TK_WHILE:{
+whilestat(ls,line);
+return 0;
+}
+case TK_DO:{
+luaX_next(ls);
+block(ls);
+check_match(ls,TK_END,TK_DO,line);
+return 0;
+}
+case TK_FOR:{
+forstat(ls,line);
+return 0;
+}
+case TK_REPEAT:{
+repeatstat(ls,line);
+return 0;
+}
+case TK_FUNCTION:{
+funcstat(ls,line);
+return 0;
+}
+case TK_LOCAL:{
+luaX_next(ls);
+if(testnext(ls,TK_FUNCTION))
+localfunc(ls);
+else
+localstat(ls);
+return 0;
+}
+case TK_RETURN:{
+retstat(ls);
+return 1;
+}
+case TK_BREAK:{
+luaX_next(ls);
+breakstat(ls);
+return 1;
+}
+default:{
+exprstat(ls);
+return 0;
+}
+}
+}
+static void chunk(LexState*ls){
+int islast=0;
+enterlevel(ls);
+while(!islast&&!block_follow(ls->t.token)){
+islast=statement(ls);
+testnext(ls,';');
+ls->fs->freereg=ls->fs->nactvar;
+}
+leavelevel(ls);
+}
+static const TValue*luaV_tonumber(const TValue*obj,TValue*n){
+lua_Number num;
+if(ttisnumber(obj))return obj;
+if(ttisstring(obj)&&luaO_str2d(svalue(obj),&num)){
+setnvalue(n,num);
+return n;
+}
+else
+return NULL;
+}
+static int luaV_tostring(lua_State*L,StkId obj){
+if(!ttisnumber(obj))
+return 0;
+else{
+char s[32];
+lua_Number n=nvalue(obj);
+lua_number2str(s,n);
+setsvalue(L,obj,luaS_new(L,s));
+return 1;
+}
+}
+static void callTMres(lua_State*L,StkId res,const TValue*f,
+const TValue*p1,const TValue*p2){
+ptrdiff_t result=savestack(L,res);
+setobj(L,L->top,f);
+setobj(L,L->top+1,p1);
+setobj(L,L->top+2,p2);
+luaD_checkstack(L,3);
+L->top+=3;
+luaD_call(L,L->top-3,1);
+res=restorestack(L,result);
+L->top--;
+setobj(L,res,L->top);
+}
+static void callTM(lua_State*L,const TValue*f,const TValue*p1,
+const TValue*p2,const TValue*p3){
+setobj(L,L->top,f);
+setobj(L,L->top+1,p1);
+setobj(L,L->top+2,p2);
+setobj(L,L->top+3,p3);
+luaD_checkstack(L,4);
+L->top+=4;
+luaD_call(L,L->top-4,0);
+}
+static void luaV_gettable(lua_State*L,const TValue*t,TValue*key,StkId val){
+int loop;
+for(loop=0;loop<100;loop++){
+const TValue*tm;
+if(ttistable(t)){
+Table*h=hvalue(t);
+const TValue*res=luaH_get(h,key);
+if(!ttisnil(res)||
+(tm=fasttm(L,h->metatable,TM_INDEX))==NULL){
+setobj(L,val,res);
+return;
+}
+}
+else if(ttisnil(tm=luaT_gettmbyobj(L,t,TM_INDEX)))
+luaG_typeerror(L,t,"index");
+if(ttisfunction(tm)){
+callTMres(L,val,tm,t,key);
+return;
+}
+t=tm;
+}
+luaG_runerror(L,"loop in gettable");
+}
+static void luaV_settable(lua_State*L,const TValue*t,TValue*key,StkId val){
+int loop;
+TValue temp;
+for(loop=0;loop<100;loop++){
+const TValue*tm;
+if(ttistable(t)){
+Table*h=hvalue(t);
+TValue*oldval=luaH_set(L,h,key);
+if(!ttisnil(oldval)||
+(tm=fasttm(L,h->metatable,TM_NEWINDEX))==NULL){
+setobj(L,oldval,val);
+h->flags=0;
+luaC_barriert(L,h,val);
+return;
+}
+}
+else if(ttisnil(tm=luaT_gettmbyobj(L,t,TM_NEWINDEX)))
+luaG_typeerror(L,t,"index");
+if(ttisfunction(tm)){
+callTM(L,tm,t,key,val);
+return;
+}
+setobj(L,&temp,tm);
+t=&temp;
+}
+luaG_runerror(L,"loop in settable");
+}
+static int call_binTM(lua_State*L,const TValue*p1,const TValue*p2,
+StkId res,TMS event){
+const TValue*tm=luaT_gettmbyobj(L,p1,event);
+if(ttisnil(tm))
+tm=luaT_gettmbyobj(L,p2,event);
+if(ttisnil(tm))return 0;
+callTMres(L,res,tm,p1,p2);
+return 1;
+}
+static const TValue*get_compTM(lua_State*L,Table*mt1,Table*mt2,
+TMS event){
+const TValue*tm1=fasttm(L,mt1,event);
+const TValue*tm2;
+if(tm1==NULL)return NULL;
+if(mt1==mt2)return tm1;
+tm2=fasttm(L,mt2,event);
+if(tm2==NULL)return NULL;
+if(luaO_rawequalObj(tm1,tm2))
+return tm1;
+return NULL;
+}
+static int call_orderTM(lua_State*L,const TValue*p1,const TValue*p2,
+TMS event){
+const TValue*tm1=luaT_gettmbyobj(L,p1,event);
+const TValue*tm2;
+if(ttisnil(tm1))return-1;
+tm2=luaT_gettmbyobj(L,p2,event);
+if(!luaO_rawequalObj(tm1,tm2))
+return-1;
+callTMres(L,L->top,tm1,p1,p2);
+return!l_isfalse(L->top);
+}
+static int l_strcmp(const TString*ls,const TString*rs){
+const char*l=getstr(ls);
+size_t ll=ls->tsv.len;
+const char*r=getstr(rs);
+size_t lr=rs->tsv.len;
+for(;;){
+int temp=strcoll(l,r);
+if(temp!=0)return temp;
+else{
+size_t len=strlen(l);
+if(len==lr)
+return(len==ll)?0:1;
+else if(len==ll)
+return-1;
+len++;
+l+=len;ll-=len;r+=len;lr-=len;
+}
+}
+}
+static int luaV_lessthan(lua_State*L,const TValue*l,const TValue*r){
+int res;
+if(ttype(l)!=ttype(r))
+return luaG_ordererror(L,l,r);
+else if(ttisnumber(l))
+return luai_numlt(nvalue(l),nvalue(r));
+else if(ttisstring(l))
+return l_strcmp(rawtsvalue(l),rawtsvalue(r))<0;
+else if((res=call_orderTM(L,l,r,TM_LT))!=-1)
+return res;
+return luaG_ordererror(L,l,r);
+}
+static int lessequal(lua_State*L,const TValue*l,const TValue*r){
+int res;
+if(ttype(l)!=ttype(r))
+return luaG_ordererror(L,l,r);
+else if(ttisnumber(l))
+return luai_numle(nvalue(l),nvalue(r));
+else if(ttisstring(l))
+return l_strcmp(rawtsvalue(l),rawtsvalue(r))<=0;
+else if((res=call_orderTM(L,l,r,TM_LE))!=-1)
+return res;
+else if((res=call_orderTM(L,r,l,TM_LT))!=-1)
+return!res;
+return luaG_ordererror(L,l,r);
+}
+static int luaV_equalval(lua_State*L,const TValue*t1,const TValue*t2){
+const TValue*tm;
+switch(ttype(t1)){
+case 0:return 1;
+case 3:return luai_numeq(nvalue(t1),nvalue(t2));
+case 1:return bvalue(t1)==bvalue(t2);
+case 2:return pvalue(t1)==pvalue(t2);
+case 7:{
+if(uvalue(t1)==uvalue(t2))return 1;
+tm=get_compTM(L,uvalue(t1)->metatable,uvalue(t2)->metatable,
+TM_EQ);
+break;
+}
+case 5:{
+if(hvalue(t1)==hvalue(t2))return 1;
+tm=get_compTM(L,hvalue(t1)->metatable,hvalue(t2)->metatable,TM_EQ);
+break;
+}
+default:return gcvalue(t1)==gcvalue(t2);
+}
+if(tm==NULL)return 0;
+callTMres(L,L->top,tm,t1,t2);
+return!l_isfalse(L->top);
+}
+static void luaV_concat(lua_State*L,int total,int last){
+do{
+StkId top=L->base+last+1;
+int n=2;
+if(!(ttisstring(top-2)||ttisnumber(top-2))||!tostring(L,top-1)){
+if(!call_binTM(L,top-2,top-1,top-2,TM_CONCAT))
+luaG_concaterror(L,top-2,top-1);
+}else if(tsvalue(top-1)->len==0)
+(void)tostring(L,top-2);
+else{
+size_t tl=tsvalue(top-1)->len;
+char*buffer;
+int i;
+for(n=1;n<total&&tostring(L,top-n-1);n++){
+size_t l=tsvalue(top-n-1)->len;
+if(l>=((size_t)(~(size_t)0)-2)-tl)luaG_runerror(L,"string length overflow");
+tl+=l;
+}
+buffer=luaZ_openspace(L,&G(L)->buff,tl);
+tl=0;
+for(i=n;i>0;i--){
+size_t l=tsvalue(top-i)->len;
+memcpy(buffer+tl,svalue(top-i),l);
+tl+=l;
+}
+setsvalue(L,top-n,luaS_newlstr(L,buffer,tl));
+}
+total-=n-1;
+last-=n-1;
+}while(total>1);
+}
+static void Arith(lua_State*L,StkId ra,const TValue*rb,
+const TValue*rc,TMS op){
+TValue tempb,tempc;
+const TValue*b,*c;
+if((b=luaV_tonumber(rb,&tempb))!=NULL&&
+(c=luaV_tonumber(rc,&tempc))!=NULL){
+lua_Number nb=nvalue(b),nc=nvalue(c);
+switch(op){
+case TM_ADD:setnvalue(ra,luai_numadd(nb,nc));break;
+case TM_SUB:setnvalue(ra,luai_numsub(nb,nc));break;
+case TM_MUL:setnvalue(ra,luai_nummul(nb,nc));break;
+case TM_DIV:setnvalue(ra,luai_numdiv(nb,nc));break;
+case TM_MOD:setnvalue(ra,luai_nummod(nb,nc));break;
+case TM_POW:setnvalue(ra,luai_numpow(nb,nc));break;
+case TM_UNM:setnvalue(ra,luai_numunm(nb));break;
+default:break;
+}
+}
+else if(!call_binTM(L,rb,rc,ra,op))
+luaG_aritherror(L,rb,rc);
+}
+#define runtime_check(L,c){if(!(c))break;}
+#define RA(i)(base+GETARG_A(i))
+#define RB(i)check_exp(getBMode(GET_OPCODE(i))==OpArgR,base+GETARG_B(i))
+#define RKB(i)check_exp(getBMode(GET_OPCODE(i))==OpArgK,ISK(GETARG_B(i))?k+INDEXK(GETARG_B(i)):base+GETARG_B(i))
+#define RKC(i)check_exp(getCMode(GET_OPCODE(i))==OpArgK,ISK(GETARG_C(i))?k+INDEXK(GETARG_C(i)):base+GETARG_C(i))
+#define KBx(i)check_exp(getBMode(GET_OPCODE(i))==OpArgK,k+GETARG_Bx(i))
+#define dojump(L,pc,i){(pc)+=(i);}
+#define Protect(x){L->savedpc=pc;{x;};base=L->base;}
+#define arith_op(op,tm){TValue*rb=RKB(i);TValue*rc=RKC(i);if(ttisnumber(rb)&&ttisnumber(rc)){lua_Number nb=nvalue(rb),nc=nvalue(rc);setnvalue(ra,op(nb,nc));}else Protect(Arith(L,ra,rb,rc,tm));}
+static void luaV_execute(lua_State*L,int nexeccalls){
+LClosure*cl;
+StkId base;
+TValue*k;
+const Instruction*pc;
+reentry:
+pc=L->savedpc;
+cl=&clvalue(L->ci->func)->l;
+base=L->base;
+k=cl->p->k;
+for(;;){
+const Instruction i=*pc++;
+StkId ra;
+ra=RA(i);
+switch(GET_OPCODE(i)){
+case OP_MOVE:{
+setobj(L,ra,RB(i));
+continue;
+}
+case OP_LOADK:{
+setobj(L,ra,KBx(i));
+continue;
+}
+case OP_LOADBOOL:{
+setbvalue(ra,GETARG_B(i));
+if(GETARG_C(i))pc++;
+continue;
+}
+case OP_LOADNIL:{
+TValue*rb=RB(i);
+do{
+setnilvalue(rb--);
+}while(rb>=ra);
+continue;
+}
+case OP_GETUPVAL:{
+int b=GETARG_B(i);
+setobj(L,ra,cl->upvals[b]->v);
+continue;
+}
+case OP_GETGLOBAL:{
+TValue g;
+TValue*rb=KBx(i);
+sethvalue(L,&g,cl->env);
+Protect(luaV_gettable(L,&g,rb,ra));
+continue;
+}
+case OP_GETTABLE:{
+Protect(luaV_gettable(L,RB(i),RKC(i),ra));
+continue;
+}
+case OP_SETGLOBAL:{
+TValue g;
+sethvalue(L,&g,cl->env);
+Protect(luaV_settable(L,&g,KBx(i),ra));
+continue;
+}
+case OP_SETUPVAL:{
+UpVal*uv=cl->upvals[GETARG_B(i)];
+setobj(L,uv->v,ra);
+luaC_barrier(L,uv,ra);
+continue;
+}
+case OP_SETTABLE:{
+Protect(luaV_settable(L,ra,RKB(i),RKC(i)));
+continue;
+}
+case OP_NEWTABLE:{
+int b=GETARG_B(i);
+int c=GETARG_C(i);
+sethvalue(L,ra,luaH_new(L,luaO_fb2int(b),luaO_fb2int(c)));
+Protect(luaC_checkGC(L));
+continue;
+}
+case OP_SELF:{
+StkId rb=RB(i);
+setobj(L,ra+1,rb);
+Protect(luaV_gettable(L,rb,RKC(i),ra));
+continue;
+}
+case OP_ADD:{
+arith_op(luai_numadd,TM_ADD);
+continue;
+}
+case OP_SUB:{
+arith_op(luai_numsub,TM_SUB);
+continue;
+}
+case OP_MUL:{
+arith_op(luai_nummul,TM_MUL);
+continue;
+}
+case OP_DIV:{
+arith_op(luai_numdiv,TM_DIV);
+continue;
+}
+case OP_MOD:{
+arith_op(luai_nummod,TM_MOD);
+continue;
+}
+case OP_POW:{
+arith_op(luai_numpow,TM_POW);
+continue;
+}
+case OP_UNM:{
+TValue*rb=RB(i);
+if(ttisnumber(rb)){
+lua_Number nb=nvalue(rb);
+setnvalue(ra,luai_numunm(nb));
+}
+else{
+Protect(Arith(L,ra,rb,rb,TM_UNM));
+}
+continue;
+}
+case OP_NOT:{
+int res=l_isfalse(RB(i));
+setbvalue(ra,res);
+continue;
+}
+case OP_LEN:{
+const TValue*rb=RB(i);
+switch(ttype(rb)){
+case 5:{
+setnvalue(ra,cast_num(luaH_getn(hvalue(rb))));
+break;
+}
+case 4:{
+setnvalue(ra,cast_num(tsvalue(rb)->len));
+break;
+}
+default:{
+Protect(
+if(!call_binTM(L,rb,(&luaO_nilobject_),ra,TM_LEN))
+luaG_typeerror(L,rb,"get length of");
+)
+}
+}
+continue;
+}
+case OP_CONCAT:{
+int b=GETARG_B(i);
+int c=GETARG_C(i);
+Protect(luaV_concat(L,c-b+1,c);luaC_checkGC(L));
+setobj(L,RA(i),base+b);
+continue;
+}
+case OP_JMP:{
+dojump(L,pc,GETARG_sBx(i));
+continue;
+}
+case OP_EQ:{
+TValue*rb=RKB(i);
+TValue*rc=RKC(i);
+Protect(
+if(equalobj(L,rb,rc)==GETARG_A(i))
+dojump(L,pc,GETARG_sBx(*pc));
+)
+pc++;
+continue;
+}
+case OP_LT:{
+Protect(
+if(luaV_lessthan(L,RKB(i),RKC(i))==GETARG_A(i))
+dojump(L,pc,GETARG_sBx(*pc));
+)
+pc++;
+continue;
+}
+case OP_LE:{
+Protect(
+if(lessequal(L,RKB(i),RKC(i))==GETARG_A(i))
+dojump(L,pc,GETARG_sBx(*pc));
+)
+pc++;
+continue;
+}
+case OP_TEST:{
+if(l_isfalse(ra)!=GETARG_C(i))
+dojump(L,pc,GETARG_sBx(*pc));
+pc++;
+continue;
+}
+case OP_TESTSET:{
+TValue*rb=RB(i);
+if(l_isfalse(rb)!=GETARG_C(i)){
+setobj(L,ra,rb);
+dojump(L,pc,GETARG_sBx(*pc));
+}
+pc++;
+continue;
+}
+case OP_CALL:{
+int b=GETARG_B(i);
+int nresults=GETARG_C(i)-1;
+if(b!=0)L->top=ra+b;
+L->savedpc=pc;
+switch(luaD_precall(L,ra,nresults)){
+case 0:{
+nexeccalls++;
+goto reentry;
+}
+case 1:{
+if(nresults>=0)L->top=L->ci->top;
+base=L->base;
+continue;
+}
+default:{
+return;
+}
+}
+}
+case OP_TAILCALL:{
+int b=GETARG_B(i);
+if(b!=0)L->top=ra+b;
+L->savedpc=pc;
+switch(luaD_precall(L,ra,(-1))){
+case 0:{
+CallInfo*ci=L->ci-1;
+int aux;
+StkId func=ci->func;
+StkId pfunc=(ci+1)->func;
+if(L->openupval)luaF_close(L,ci->base);
+L->base=ci->base=ci->func+((ci+1)->base-pfunc);
+for(aux=0;pfunc+aux<L->top;aux++)
+setobj(L,func+aux,pfunc+aux);
+ci->top=L->top=func+aux;
+ci->savedpc=L->savedpc;
+ci->tailcalls++;
+L->ci--;
+goto reentry;
+}
+case 1:{
+base=L->base;
+continue;
+}
+default:{
+return;
+}
+}
+}
+case OP_RETURN:{
+int b=GETARG_B(i);
+if(b!=0)L->top=ra+b-1;
+if(L->openupval)luaF_close(L,base);
+L->savedpc=pc;
+b=luaD_poscall(L,ra);
+if(--nexeccalls==0)
+return;
+else{
+if(b)L->top=L->ci->top;
+goto reentry;
+}
+}
+case OP_FORLOOP:{
+lua_Number step=nvalue(ra+2);
+lua_Number idx=luai_numadd(nvalue(ra),step);
+lua_Number limit=nvalue(ra+1);
+if(luai_numlt(0,step)?luai_numle(idx,limit)
+:luai_numle(limit,idx)){
+dojump(L,pc,GETARG_sBx(i));
+setnvalue(ra,idx);
+setnvalue(ra+3,idx);
+}
+continue;
+}
+case OP_FORPREP:{
+const TValue*init=ra;
+const TValue*plimit=ra+1;
+const TValue*pstep=ra+2;
+L->savedpc=pc;
+if(!tonumber(init,ra))
+luaG_runerror(L,LUA_QL("for")" initial value must be a number");
+else if(!tonumber(plimit,ra+1))
+luaG_runerror(L,LUA_QL("for")" limit must be a number");
+else if(!tonumber(pstep,ra+2))
+luaG_runerror(L,LUA_QL("for")" step must be a number");
+setnvalue(ra,luai_numsub(nvalue(ra),nvalue(pstep)));
+dojump(L,pc,GETARG_sBx(i));
+continue;
+}
+case OP_TFORLOOP:{
+StkId cb=ra+3;
+setobj(L,cb+2,ra+2);
+setobj(L,cb+1,ra+1);
+setobj(L,cb,ra);
+L->top=cb+3;
+Protect(luaD_call(L,cb,GETARG_C(i)));
+L->top=L->ci->top;
+cb=RA(i)+3;
+if(!ttisnil(cb)){
+setobj(L,cb-1,cb);
+dojump(L,pc,GETARG_sBx(*pc));
+}
+pc++;
+continue;
+}
+case OP_SETLIST:{
+int n=GETARG_B(i);
+int c=GETARG_C(i);
+int last;
+Table*h;
+if(n==0){
+n=cast_int(L->top-ra)-1;
+L->top=L->ci->top;
+}
+if(c==0)c=cast_int(*pc++);
+runtime_check(L,ttistable(ra));
+h=hvalue(ra);
+last=((c-1)*50)+n;
+if(last>h->sizearray)
+luaH_resizearray(L,h,last);
+for(;n>0;n--){
+TValue*val=ra+n;
+setobj(L,luaH_setnum(L,h,last--),val);
+luaC_barriert(L,h,val);
+}
+continue;
+}
+case OP_CLOSE:{
+luaF_close(L,ra);
+continue;
+}
+case OP_CLOSURE:{
+Proto*p;
+Closure*ncl;
+int nup,j;
+p=cl->p->p[GETARG_Bx(i)];
+nup=p->nups;
+ncl=luaF_newLclosure(L,nup,cl->env);
+ncl->l.p=p;
+for(j=0;j<nup;j++,pc++){
+if(GET_OPCODE(*pc)==OP_GETUPVAL)
+ncl->l.upvals[j]=cl->upvals[GETARG_B(*pc)];
+else{
+ncl->l.upvals[j]=luaF_findupval(L,base+GETARG_B(*pc));
+}
+}
+setclvalue(L,ra,ncl);
+Protect(luaC_checkGC(L));
+continue;
+}
+case OP_VARARG:{
+int b=GETARG_B(i)-1;
+int j;
+CallInfo*ci=L->ci;
+int n=cast_int(ci->base-ci->func)-cl->p->numparams-1;
+if(b==(-1)){
+Protect(luaD_checkstack(L,n));
+ra=RA(i);
+b=n;
+L->top=ra+n;
+}
+for(j=0;j<b;j++){
+if(j<n){
+setobj(L,ra+j,ci->base-n+j);
+}
+else{
+setnilvalue(ra+j);
+}
+}
+continue;
+}
+}
+}
+}
+#define api_checknelems(L,n)luai_apicheck(L,(n)<=(L->top-L->base))
+#define api_checkvalidindex(L,i)luai_apicheck(L,(i)!=(&luaO_nilobject_))
+#define api_incr_top(L){luai_apicheck(L,L->top<L->ci->top);L->top++;}
+static TValue*index2adr(lua_State*L,int idx){
+if(idx>0){
+TValue*o=L->base+(idx-1);
+luai_apicheck(L,idx<=L->ci->top-L->base);
+if(o>=L->top)return cast(TValue*,(&luaO_nilobject_));
+else return o;
+}
+else if(idx>(-10000)){
+luai_apicheck(L,idx!=0&&-idx<=L->top-L->base);
+return L->top+idx;
+}
+else switch(idx){
+case(-10000):return registry(L);
+case(-10001):{
+Closure*func=curr_func(L);
+sethvalue(L,&L->env,func->c.env);
+return&L->env;
+}
+case(-10002):return gt(L);
+default:{
+Closure*func=curr_func(L);
+idx=(-10002)-idx;
+return(idx<=func->c.nupvalues)
+?&func->c.upvalue[idx-1]
+:cast(TValue*,(&luaO_nilobject_));
+}
+}
+}
+static Table*getcurrenv(lua_State*L){
+if(L->ci==L->base_ci)
+return hvalue(gt(L));
+else{
+Closure*func=curr_func(L);
+return func->c.env;
+}
+}
+static int lua_checkstack(lua_State*L,int size){
+int res=1;
+if(size>8000||(L->top-L->base+size)>8000)
+res=0;
+else if(size>0){
+luaD_checkstack(L,size);
+if(L->ci->top<L->top+size)
+L->ci->top=L->top+size;
+}
+return res;
+}
+static lua_CFunction lua_atpanic(lua_State*L,lua_CFunction panicf){
+lua_CFunction old;
+old=G(L)->panic;
+G(L)->panic=panicf;
+return old;
+}
+static int lua_gettop(lua_State*L){
+return cast_int(L->top-L->base);
+}
+static void lua_settop(lua_State*L,int idx){
+if(idx>=0){
+luai_apicheck(L,idx<=L->stack_last-L->base);
+while(L->top<L->base+idx)
+setnilvalue(L->top++);
+L->top=L->base+idx;
+}
+else{
+luai_apicheck(L,-(idx+1)<=(L->top-L->base));
+L->top+=idx+1;
+}
+}
+static void lua_remove(lua_State*L,int idx){
+StkId p;
+p=index2adr(L,idx);
+api_checkvalidindex(L,p);
+while(++p<L->top)setobj(L,p-1,p);
+L->top--;
+}
+static void lua_insert(lua_State*L,int idx){
+StkId p;
+StkId q;
+p=index2adr(L,idx);
+api_checkvalidindex(L,p);
+for(q=L->top;q>p;q--)setobj(L,q,q-1);
+setobj(L,p,L->top);
+}
+static void lua_replace(lua_State*L,int idx){
+StkId o;
+if(idx==(-10001)&&L->ci==L->base_ci)
+luaG_runerror(L,"no calling environment");
+api_checknelems(L,1);
+o=index2adr(L,idx);
+api_checkvalidindex(L,o);
+if(idx==(-10001)){
+Closure*func=curr_func(L);
+luai_apicheck(L,ttistable(L->top-1));
+func->c.env=hvalue(L->top-1);
+luaC_barrier(L,func,L->top-1);
+}
+else{
+setobj(L,o,L->top-1);
+if(idx<(-10002))
+luaC_barrier(L,curr_func(L),L->top-1);
+}
+L->top--;
+}
+static void lua_pushvalue(lua_State*L,int idx){
+setobj(L,L->top,index2adr(L,idx));
+api_incr_top(L);
+}
+static int lua_type(lua_State*L,int idx){
+StkId o=index2adr(L,idx);
+return(o==(&luaO_nilobject_))?(-1):ttype(o);
+}
+static const char*lua_typename(lua_State*L,int t){
+UNUSED(L);
+return(t==(-1))?"no value":luaT_typenames[t];
+}
+static int lua_iscfunction(lua_State*L,int idx){
+StkId o=index2adr(L,idx);
+return iscfunction(o);
+}
+static int lua_isnumber(lua_State*L,int idx){
+TValue n;
+const TValue*o=index2adr(L,idx);
+return tonumber(o,&n);
+}
+static int lua_isstring(lua_State*L,int idx){
+int t=lua_type(L,idx);
+return(t==4||t==3);
+}
+static int lua_rawequal(lua_State*L,int index1,int index2){
+StkId o1=index2adr(L,index1);
+StkId o2=index2adr(L,index2);
+return(o1==(&luaO_nilobject_)||o2==(&luaO_nilobject_))?0
+:luaO_rawequalObj(o1,o2);
+}
+static int lua_lessthan(lua_State*L,int index1,int index2){
+StkId o1,o2;
+int i;
+o1=index2adr(L,index1);
+o2=index2adr(L,index2);
+i=(o1==(&luaO_nilobject_)||o2==(&luaO_nilobject_))?0
+:luaV_lessthan(L,o1,o2);
+return i;
+}
+static lua_Number lua_tonumber(lua_State*L,int idx){
+TValue n;
+const TValue*o=index2adr(L,idx);
+if(tonumber(o,&n))
+return nvalue(o);
+else
+return 0;
+}
+static lua_Integer lua_tointeger(lua_State*L,int idx){
+TValue n;
+const TValue*o=index2adr(L,idx);
+if(tonumber(o,&n)){
+lua_Integer res;
+lua_Number num=nvalue(o);
+lua_number2integer(res,num);
+return res;
+}
+else
+return 0;
+}
+static int lua_toboolean(lua_State*L,int idx){
+const TValue*o=index2adr(L,idx);
+return!l_isfalse(o);
+}
+static const char*lua_tolstring(lua_State*L,int idx,size_t*len){
+StkId o=index2adr(L,idx);
+if(!ttisstring(o)){
+if(!luaV_tostring(L,o)){
+if(len!=NULL)*len=0;
+return NULL;
+}
+luaC_checkGC(L);
+o=index2adr(L,idx);
+}
+if(len!=NULL)*len=tsvalue(o)->len;
+return svalue(o);
+}
+static size_t lua_objlen(lua_State*L,int idx){
+StkId o=index2adr(L,idx);
+switch(ttype(o)){
+case 4:return tsvalue(o)->len;
+case 7:return uvalue(o)->len;
+case 5:return luaH_getn(hvalue(o));
+case 3:{
+size_t l;
+l=(luaV_tostring(L,o)?tsvalue(o)->len:0);
+return l;
+}
+default:return 0;
+}
+}
+static lua_CFunction lua_tocfunction(lua_State*L,int idx){
+StkId o=index2adr(L,idx);
+return(!iscfunction(o))?NULL:clvalue(o)->c.f;
+}
+static void*lua_touserdata(lua_State*L,int idx){
+StkId o=index2adr(L,idx);
+switch(ttype(o)){
+case 7:return(rawuvalue(o)+1);
+case 2:return pvalue(o);
+default:return NULL;
+}
+}
+static void lua_pushnil(lua_State*L){
+setnilvalue(L->top);
+api_incr_top(L);
+}
+static void lua_pushnumber(lua_State*L,lua_Number n){
+setnvalue(L->top,n);
+api_incr_top(L);
+}
+static void lua_pushinteger(lua_State*L,lua_Integer n){
+setnvalue(L->top,cast_num(n));
+api_incr_top(L);
+}
+static void lua_pushlstring(lua_State*L,const char*s,size_t len){
+luaC_checkGC(L);
+setsvalue(L,L->top,luaS_newlstr(L,s,len));
+api_incr_top(L);
+}
+static void lua_pushstring(lua_State*L,const char*s){
+if(s==NULL)
+lua_pushnil(L);
+else
+lua_pushlstring(L,s,strlen(s));
+}
+static const char*lua_pushvfstring(lua_State*L,const char*fmt,
+va_list argp){
+const char*ret;
+luaC_checkGC(L);
+ret=luaO_pushvfstring(L,fmt,argp);
+return ret;
+}
+static const char*lua_pushfstring(lua_State*L,const char*fmt,...){
+const char*ret;
+va_list argp;
+luaC_checkGC(L);
+va_start(argp,fmt);
+ret=luaO_pushvfstring(L,fmt,argp);
+va_end(argp);
+return ret;
+}
+static void lua_pushcclosure(lua_State*L,lua_CFunction fn,int n){
+Closure*cl;
+luaC_checkGC(L);
+api_checknelems(L,n);
+cl=luaF_newCclosure(L,n,getcurrenv(L));
+cl->c.f=fn;
+L->top-=n;
+while(n--)
+setobj(L,&cl->c.upvalue[n],L->top+n);
+setclvalue(L,L->top,cl);
+api_incr_top(L);
+}
+static void lua_pushboolean(lua_State*L,int b){
+setbvalue(L->top,(b!=0));
+api_incr_top(L);
+}
+static int lua_pushthread(lua_State*L){
+setthvalue(L,L->top,L);
+api_incr_top(L);
+return(G(L)->mainthread==L);
+}
+static void lua_gettable(lua_State*L,int idx){
+StkId t;
+t=index2adr(L,idx);
+api_checkvalidindex(L,t);
+luaV_gettable(L,t,L->top-1,L->top-1);
+}
+static void lua_getfield(lua_State*L,int idx,const char*k){
+StkId t;
+TValue key;
+t=index2adr(L,idx);
+api_checkvalidindex(L,t);
+setsvalue(L,&key,luaS_new(L,k));
+luaV_gettable(L,t,&key,L->top);
+api_incr_top(L);
+}
+static void lua_rawget(lua_State*L,int idx){
+StkId t;
+t=index2adr(L,idx);
+luai_apicheck(L,ttistable(t));
+setobj(L,L->top-1,luaH_get(hvalue(t),L->top-1));
+}
+static void lua_rawgeti(lua_State*L,int idx,int n){
+StkId o;
+o=index2adr(L,idx);
+luai_apicheck(L,ttistable(o));
+setobj(L,L->top,luaH_getnum(hvalue(o),n));
+api_incr_top(L);
+}
+static void lua_createtable(lua_State*L,int narray,int nrec){
+luaC_checkGC(L);
+sethvalue(L,L->top,luaH_new(L,narray,nrec));
+api_incr_top(L);
+}
+static int lua_getmetatable(lua_State*L,int objindex){
+const TValue*obj;
+Table*mt=NULL;
+int res;
+obj=index2adr(L,objindex);
+switch(ttype(obj)){
+case 5:
+mt=hvalue(obj)->metatable;
+break;
+case 7:
+mt=uvalue(obj)->metatable;
+break;
+default:
+mt=G(L)->mt[ttype(obj)];
+break;
+}
+if(mt==NULL)
+res=0;
+else{
+sethvalue(L,L->top,mt);
+api_incr_top(L);
+res=1;
+}
+return res;
+}
+static void lua_getfenv(lua_State*L,int idx){
+StkId o;
+o=index2adr(L,idx);
+api_checkvalidindex(L,o);
+switch(ttype(o)){
+case 6:
+sethvalue(L,L->top,clvalue(o)->c.env);
+break;
+case 7:
+sethvalue(L,L->top,uvalue(o)->env);
+break;
+case 8:
+setobj(L,L->top,gt(thvalue(o)));
+break;
+default:
+setnilvalue(L->top);
+break;
+}
+api_incr_top(L);
+}
+static void lua_settable(lua_State*L,int idx){
+StkId t;
+api_checknelems(L,2);
+t=index2adr(L,idx);
+api_checkvalidindex(L,t);
+luaV_settable(L,t,L->top-2,L->top-1);
+L->top-=2;
+}
+static void lua_setfield(lua_State*L,int idx,const char*k){
+StkId t;
+TValue key;
+api_checknelems(L,1);
+t=index2adr(L,idx);
+api_checkvalidindex(L,t);
+setsvalue(L,&key,luaS_new(L,k));
+luaV_settable(L,t,&key,L->top-1);
+L->top--;
+}
+static void lua_rawset(lua_State*L,int idx){
+StkId t;
+api_checknelems(L,2);
+t=index2adr(L,idx);
+luai_apicheck(L,ttistable(t));
+setobj(L,luaH_set(L,hvalue(t),L->top-2),L->top-1);
+luaC_barriert(L,hvalue(t),L->top-1);
+L->top-=2;
+}
+static void lua_rawseti(lua_State*L,int idx,int n){
+StkId o;
+api_checknelems(L,1);
+o=index2adr(L,idx);
+luai_apicheck(L,ttistable(o));
+setobj(L,luaH_setnum(L,hvalue(o),n),L->top-1);
+luaC_barriert(L,hvalue(o),L->top-1);
+L->top--;
+}
+static int lua_setmetatable(lua_State*L,int objindex){
+TValue*obj;
+Table*mt;
+api_checknelems(L,1);
+obj=index2adr(L,objindex);
+api_checkvalidindex(L,obj);
+if(ttisnil(L->top-1))
+mt=NULL;
+else{
+luai_apicheck(L,ttistable(L->top-1));
+mt=hvalue(L->top-1);
+}
+switch(ttype(obj)){
+case 5:{
+hvalue(obj)->metatable=mt;
+if(mt)
+luaC_objbarriert(L,hvalue(obj),mt);
+break;
+}
+case 7:{
+uvalue(obj)->metatable=mt;
+if(mt)
+luaC_objbarrier(L,rawuvalue(obj),mt);
+break;
+}
+default:{
+G(L)->mt[ttype(obj)]=mt;
+break;
+}
+}
+L->top--;
+return 1;
+}
+static int lua_setfenv(lua_State*L,int idx){
+StkId o;
+int res=1;
+api_checknelems(L,1);
+o=index2adr(L,idx);
+api_checkvalidindex(L,o);
+luai_apicheck(L,ttistable(L->top-1));
+switch(ttype(o)){
+case 6:
+clvalue(o)->c.env=hvalue(L->top-1);
+break;
+case 7:
+uvalue(o)->env=hvalue(L->top-1);
+break;
+case 8:
+sethvalue(L,gt(thvalue(o)),hvalue(L->top-1));
+break;
+default:
+res=0;
+break;
+}
+if(res)luaC_objbarrier(L,gcvalue(o),hvalue(L->top-1));
+L->top--;
+return res;
+}
+#define adjustresults(L,nres){if(nres==(-1)&&L->top>=L->ci->top)L->ci->top=L->top;}
+#define checkresults(L,na,nr)luai_apicheck(L,(nr)==(-1)||(L->ci->top-L->top>=(nr)-(na)))
+static void lua_call(lua_State*L,int nargs,int nresults){
+StkId func;
+api_checknelems(L,nargs+1);
+checkresults(L,nargs,nresults);
+func=L->top-(nargs+1);
+luaD_call(L,func,nresults);
+adjustresults(L,nresults);
+}
+struct CallS{
+StkId func;
+int nresults;
+};
+static void f_call(lua_State*L,void*ud){
+struct CallS*c=cast(struct CallS*,ud);
+luaD_call(L,c->func,c->nresults);
+}
+static int lua_pcall(lua_State*L,int nargs,int nresults,int errfunc){
+struct CallS c;
+int status;
+ptrdiff_t func;
+api_checknelems(L,nargs+1);
+checkresults(L,nargs,nresults);
+if(errfunc==0)
+func=0;
+else{
+StkId o=index2adr(L,errfunc);
+api_checkvalidindex(L,o);
+func=savestack(L,o);
+}
+c.func=L->top-(nargs+1);
+c.nresults=nresults;
+status=luaD_pcall(L,f_call,&c,savestack(L,c.func),func);
+adjustresults(L,nresults);
+return status;
+}
+static int lua_load(lua_State*L,lua_Reader reader,void*data,
+const char*chunkname){
+ZIO z;
+int status;
+if(!chunkname)chunkname="?";
+luaZ_init(L,&z,reader,data);
+status=luaD_protectedparser(L,&z,chunkname);
+return status;
+}
+static int lua_error(lua_State*L){
+api_checknelems(L,1);
+luaG_errormsg(L);
+return 0;
+}
+static int lua_next(lua_State*L,int idx){
+StkId t;
+int more;
+t=index2adr(L,idx);
+luai_apicheck(L,ttistable(t));
+more=luaH_next(L,hvalue(t),L->top-1);
+if(more){
+api_incr_top(L);
+}
+else
+L->top-=1;
+return more;
+}
+static void lua_concat(lua_State*L,int n){
+api_checknelems(L,n);
+if(n>=2){
+luaC_checkGC(L);
+luaV_concat(L,n,cast_int(L->top-L->base)-1);
+L->top-=(n-1);
+}
+else if(n==0){
+setsvalue(L,L->top,luaS_newlstr(L,"",0));
+api_incr_top(L);
+}
+}
+static void*lua_newuserdata(lua_State*L,size_t size){
+Udata*u;
+luaC_checkGC(L);
+u=luaS_newudata(L,size,getcurrenv(L));
+setuvalue(L,L->top,u);
+api_incr_top(L);
+return u+1;
+}
+#define luaL_getn(L,i)((int)lua_objlen(L,i))
+#define luaL_setn(L,i,j)((void)0)
+typedef struct luaL_Reg{
+const char*name;
+lua_CFunction func;
+}luaL_Reg;
+static void luaI_openlib(lua_State*L,const char*libname,
+const luaL_Reg*l,int nup);
+static int luaL_argerror(lua_State*L,int numarg,const char*extramsg);
+static const char* luaL_checklstring(lua_State*L,int numArg,
+size_t*l);
+static const char* luaL_optlstring(lua_State*L,int numArg,
+const char*def,size_t*l);
+static lua_Integer luaL_checkinteger(lua_State*L,int numArg);
+static lua_Integer luaL_optinteger(lua_State*L,int nArg,
+lua_Integer def);
+static int luaL_error(lua_State*L,const char*fmt,...);
+static const char* luaL_findtable(lua_State*L,int idx,
+const char*fname,int szhint);
+#define luaL_argcheck(L,cond,numarg,extramsg)((void)((cond)||luaL_argerror(L,(numarg),(extramsg))))
+#define luaL_checkstring(L,n)(luaL_checklstring(L,(n),NULL))
+#define luaL_optstring(L,n,d)(luaL_optlstring(L,(n),(d),NULL))
+#define luaL_checkint(L,n)((int)luaL_checkinteger(L,(n)))
+#define luaL_optint(L,n,d)((int)luaL_optinteger(L,(n),(d)))
+#define luaL_typename(L,i)lua_typename(L,lua_type(L,(i)))
+#define luaL_getmetatable(L,n)(lua_getfield(L,(-10000),(n)))
+#define luaL_opt(L,f,n,d)(lua_isnoneornil(L,(n))?(d):f(L,(n)))
+typedef struct luaL_Buffer{
+char*p;
+int lvl;
+lua_State*L;
+char buffer[BUFSIZ];
+}luaL_Buffer;
+#define luaL_addchar(B,c)((void)((B)->p<((B)->buffer+BUFSIZ)||luaL_prepbuffer(B)),(*(B)->p++=(char)(c)))
+#define luaL_addsize(B,n)((B)->p+=(n))
+static char* luaL_prepbuffer(luaL_Buffer*B);
+static int luaL_argerror(lua_State*L,int narg,const char*extramsg){
+lua_Debug ar;
+if(!lua_getstack(L,0,&ar))
+return luaL_error(L,"bad argument #%d (%s)",narg,extramsg);
+lua_getinfo(L,"n",&ar);
+if(strcmp(ar.namewhat,"method")==0){
+narg--;
+if(narg==0)
+return luaL_error(L,"calling "LUA_QL("%s")" on bad self (%s)",
+ar.name,extramsg);
+}
+if(ar.name==NULL)
+ar.name="?";
+return luaL_error(L,"bad argument #%d to "LUA_QL("%s")" (%s)",
+narg,ar.name,extramsg);
+}
+static int luaL_typerror(lua_State*L,int narg,const char*tname){
+const char*msg=lua_pushfstring(L,"%s expected, got %s",
+tname,luaL_typename(L,narg));
+return luaL_argerror(L,narg,msg);
+}
+static void tag_error(lua_State*L,int narg,int tag){
+luaL_typerror(L,narg,lua_typename(L,tag));
+}
+static void luaL_where(lua_State*L,int level){
+lua_Debug ar;
+if(lua_getstack(L,level,&ar)){
+lua_getinfo(L,"Sl",&ar);
+if(ar.currentline>0){
+lua_pushfstring(L,"%s:%d: ",ar.short_src,ar.currentline);
+return;
+}
+}
+lua_pushliteral(L,"");
+}
+static int luaL_error(lua_State*L,const char*fmt,...){
+va_list argp;
+va_start(argp,fmt);
+luaL_where(L,1);
+lua_pushvfstring(L,fmt,argp);
+va_end(argp);
+lua_concat(L,2);
+return lua_error(L);
+}
+static int luaL_newmetatable(lua_State*L,const char*tname){
+lua_getfield(L,(-10000),tname);
+if(!lua_isnil(L,-1))
+return 0;
+lua_pop(L,1);
+lua_newtable(L);
+lua_pushvalue(L,-1);
+lua_setfield(L,(-10000),tname);
+return 1;
+}
+static void*luaL_checkudata(lua_State*L,int ud,const char*tname){
+void*p=lua_touserdata(L,ud);
+if(p!=NULL){
+if(lua_getmetatable(L,ud)){
+lua_getfield(L,(-10000),tname);
+if(lua_rawequal(L,-1,-2)){
+lua_pop(L,2);
+return p;
+}
+}
+}
+luaL_typerror(L,ud,tname);
+return NULL;
+}
+static void luaL_checkstack(lua_State*L,int space,const char*mes){
+if(!lua_checkstack(L,space))
+luaL_error(L,"stack overflow (%s)",mes);
+}
+static void luaL_checktype(lua_State*L,int narg,int t){
+if(lua_type(L,narg)!=t)
+tag_error(L,narg,t);
+}
+static void luaL_checkany(lua_State*L,int narg){
+if(lua_type(L,narg)==(-1))
+luaL_argerror(L,narg,"value expected");
+}
+static const char*luaL_checklstring(lua_State*L,int narg,size_t*len){
+const char*s=lua_tolstring(L,narg,len);
+if(!s)tag_error(L,narg,4);
+return s;
+}
+static const char*luaL_optlstring(lua_State*L,int narg,
+const char*def,size_t*len){
+if(lua_isnoneornil(L,narg)){
+if(len)
+*len=(def?strlen(def):0);
+return def;
+}
+else return luaL_checklstring(L,narg,len);
+}
+static lua_Number luaL_checknumber(lua_State*L,int narg){
+lua_Number d=lua_tonumber(L,narg);
+if(d==0&&!lua_isnumber(L,narg))
+tag_error(L,narg,3);
+return d;
+}
+static lua_Integer luaL_checkinteger(lua_State*L,int narg){
+lua_Integer d=lua_tointeger(L,narg);
+if(d==0&&!lua_isnumber(L,narg))
+tag_error(L,narg,3);
+return d;
+}
+static lua_Integer luaL_optinteger(lua_State*L,int narg,
+lua_Integer def){
+return luaL_opt(L,luaL_checkinteger,narg,def);
+}
+static int luaL_getmetafield(lua_State*L,int obj,const char*event){
+if(!lua_getmetatable(L,obj))
+return 0;
+lua_pushstring(L,event);
+lua_rawget(L,-2);
+if(lua_isnil(L,-1)){
+lua_pop(L,2);
+return 0;
+}
+else{
+lua_remove(L,-2);
+return 1;
+}
+}
+static void luaL_register(lua_State*L,const char*libname,
+const luaL_Reg*l){
+luaI_openlib(L,libname,l,0);
+}
+static int libsize(const luaL_Reg*l){
+int size=0;
+for(;l->name;l++)size++;
+return size;
+}
+static void luaI_openlib(lua_State*L,const char*libname,
+const luaL_Reg*l,int nup){
+if(libname){
+int size=libsize(l);
+luaL_findtable(L,(-10000),"_LOADED",1);
+lua_getfield(L,-1,libname);
+if(!lua_istable(L,-1)){
+lua_pop(L,1);
+if(luaL_findtable(L,(-10002),libname,size)!=NULL)
+luaL_error(L,"name conflict for module "LUA_QL("%s"),libname);
+lua_pushvalue(L,-1);
+lua_setfield(L,-3,libname);
+}
+lua_remove(L,-2);
+lua_insert(L,-(nup+1));
+}
+for(;l->name;l++){
+int i;
+for(i=0;i<nup;i++)
+lua_pushvalue(L,-nup);
+lua_pushcclosure(L,l->func,nup);
+lua_setfield(L,-(nup+2),l->name);
+}
+lua_pop(L,nup);
+}
+static const char*luaL_findtable(lua_State*L,int idx,
+const char*fname,int szhint){
+const char*e;
+lua_pushvalue(L,idx);
+do{
+e=strchr(fname,'.');
+if(e==NULL)e=fname+strlen(fname);
+lua_pushlstring(L,fname,e-fname);
+lua_rawget(L,-2);
+if(lua_isnil(L,-1)){
+lua_pop(L,1);
+lua_createtable(L,0,(*e=='.'?1:szhint));
+lua_pushlstring(L,fname,e-fname);
+lua_pushvalue(L,-2);
+lua_settable(L,-4);
+}
+else if(!lua_istable(L,-1)){
+lua_pop(L,2);
+return fname;
+}
+lua_remove(L,-2);
+fname=e+1;
+}while(*e=='.');
+return NULL;
+}
+#define bufflen(B)((B)->p-(B)->buffer)
+#define bufffree(B)((size_t)(BUFSIZ-bufflen(B)))
+static int emptybuffer(luaL_Buffer*B){
+size_t l=bufflen(B);
+if(l==0)return 0;
+else{
+lua_pushlstring(B->L,B->buffer,l);
+B->p=B->buffer;
+B->lvl++;
+return 1;
+}
+}
+static void adjuststack(luaL_Buffer*B){
+if(B->lvl>1){
+lua_State*L=B->L;
+int toget=1;
+size_t toplen=lua_strlen(L,-1);
+do{
+size_t l=lua_strlen(L,-(toget+1));
+if(B->lvl-toget+1>=(20/2)||toplen>l){
+toplen+=l;
+toget++;
+}
+else break;
+}while(toget<B->lvl);
+lua_concat(L,toget);
+B->lvl=B->lvl-toget+1;
+}
+}
+static char*luaL_prepbuffer(luaL_Buffer*B){
+if(emptybuffer(B))
+adjuststack(B);
+return B->buffer;
+}
+static void luaL_addlstring(luaL_Buffer*B,const char*s,size_t l){
+while(l--)
+luaL_addchar(B,*s++);
+}
+static void luaL_pushresult(luaL_Buffer*B){
+emptybuffer(B);
+lua_concat(B->L,B->lvl);
+B->lvl=1;
+}
+static void luaL_addvalue(luaL_Buffer*B){
+lua_State*L=B->L;
+size_t vl;
+const char*s=lua_tolstring(L,-1,&vl);
+if(vl<=bufffree(B)){
+memcpy(B->p,s,vl);
+B->p+=vl;
+lua_pop(L,1);
+}
+else{
+if(emptybuffer(B))
+lua_insert(L,-2);
+B->lvl++;
+adjuststack(B);
+}
+}
+static void luaL_buffinit(lua_State*L,luaL_Buffer*B){
+B->L=L;
+B->p=B->buffer;
+B->lvl=0;
+}
+typedef struct LoadF{
+int extraline;
+FILE*f;
+char buff[BUFSIZ];
+}LoadF;
+static const char*getF(lua_State*L,void*ud,size_t*size){
+LoadF*lf=(LoadF*)ud;
+(void)L;
+if(lf->extraline){
+lf->extraline=0;
+*size=1;
+return"\n";
+}
+if(feof(lf->f))return NULL;
+*size=fread(lf->buff,1,sizeof(lf->buff),lf->f);
+return(*size>0)?lf->buff:NULL;
+}
+static int errfile(lua_State*L,const char*what,int fnameindex){
+const char*serr=strerror(errno);
+const char*filename=lua_tostring(L,fnameindex)+1;
+lua_pushfstring(L,"cannot %s %s: %s",what,filename,serr);
+lua_remove(L,fnameindex);
+return(5+1);
+}
+static int luaL_loadfile(lua_State*L,const char*filename){
+LoadF lf;
+int status,readstatus;
+int c;
+int fnameindex=lua_gettop(L)+1;
+lf.extraline=0;
+if(filename==NULL){
+lua_pushliteral(L,"=stdin");
+lf.f=stdin;
+}
+else{
+lua_pushfstring(L,"@%s",filename);
+lf.f=fopen(filename,"r");
+if(lf.f==NULL)return errfile(L,"open",fnameindex);
+}
+c=getc(lf.f);
+if(c=='#'){
+lf.extraline=1;
+while((c=getc(lf.f))!=EOF&&c!='\n');
+if(c=='\n')c=getc(lf.f);
+}
+if(c=="\033Lua"[0]&&filename){
+lf.f=freopen(filename,"rb",lf.f);
+if(lf.f==NULL)return errfile(L,"reopen",fnameindex);
+while((c=getc(lf.f))!=EOF&&c!="\033Lua"[0]);
+lf.extraline=0;
+}
+ungetc(c,lf.f);
+status=lua_load(L,getF,&lf,lua_tostring(L,-1));
+readstatus=ferror(lf.f);
+if(filename)fclose(lf.f);
+if(readstatus){
+lua_settop(L,fnameindex);
+return errfile(L,"read",fnameindex);
+}
+lua_remove(L,fnameindex);
+return status;
+}
+typedef struct LoadS{
+const char*s;
+size_t size;
+}LoadS;
+static const char*getS(lua_State*L,void*ud,size_t*size){
+LoadS*ls=(LoadS*)ud;
+(void)L;
+if(ls->size==0)return NULL;
+*size=ls->size;
+ls->size=0;
+return ls->s;
+}
+static int luaL_loadbuffer(lua_State*L,const char*buff,size_t size,
+const char*name){
+LoadS ls;
+ls.s=buff;
+ls.size=size;
+return lua_load(L,getS,&ls,name);
+}
+static void*l_alloc(void*ud,void*ptr,size_t osize,size_t nsize){
+(void)ud;
+(void)osize;
+if(nsize==0){
+free(ptr);
+return NULL;
+}
+else
+return realloc(ptr,nsize);
+}
+static int panic(lua_State*L){
+(void)L;
+fprintf(stderr,"PANIC: unprotected error in call to Lua API (%s)\n",
+lua_tostring(L,-1));
+return 0;
+}
+static lua_State*luaL_newstate(void){
+lua_State*L=lua_newstate(l_alloc,NULL);
+if(L)lua_atpanic(L,&panic);
+return L;
+}
+static int luaB_tonumber(lua_State*L){
+int base=luaL_optint(L,2,10);
+if(base==10){
+luaL_checkany(L,1);
+if(lua_isnumber(L,1)){
+lua_pushnumber(L,lua_tonumber(L,1));
+return 1;
+}
+}
+else{
+const char*s1=luaL_checkstring(L,1);
+char*s2;
+unsigned long n;
+luaL_argcheck(L,2<=base&&base<=36,2,"base out of range");
+n=strtoul(s1,&s2,base);
+if(s1!=s2){
+while(isspace((unsigned char)(*s2)))s2++;
+if(*s2=='\0'){
+lua_pushnumber(L,(lua_Number)n);
+return 1;
+}
+}
+}
+lua_pushnil(L);
+return 1;
+}
+static int luaB_error(lua_State*L){
+int level=luaL_optint(L,2,1);
+lua_settop(L,1);
+if(lua_isstring(L,1)&&level>0){
+luaL_where(L,level);
+lua_pushvalue(L,1);
+lua_concat(L,2);
+}
+return lua_error(L);
+}
+static int luaB_setmetatable(lua_State*L){
+int t=lua_type(L,2);
+luaL_checktype(L,1,5);
+luaL_argcheck(L,t==0||t==5,2,
+"nil or table expected");
+if(luaL_getmetafield(L,1,"__metatable"))
+luaL_error(L,"cannot change a protected metatable");
+lua_settop(L,2);
+lua_setmetatable(L,1);
+return 1;
+}
+static void getfunc(lua_State*L,int opt){
+if(lua_isfunction(L,1))lua_pushvalue(L,1);
+else{
+lua_Debug ar;
+int level=opt?luaL_optint(L,1,1):luaL_checkint(L,1);
+luaL_argcheck(L,level>=0,1,"level must be non-negative");
+if(lua_getstack(L,level,&ar)==0)
+luaL_argerror(L,1,"invalid level");
+lua_getinfo(L,"f",&ar);
+if(lua_isnil(L,-1))
+luaL_error(L,"no function environment for tail call at level %d",
+level);
+}
+}
+static int luaB_setfenv(lua_State*L){
+luaL_checktype(L,2,5);
+getfunc(L,0);
+lua_pushvalue(L,2);
+if(lua_isnumber(L,1)&&lua_tonumber(L,1)==0){
+lua_pushthread(L);
+lua_insert(L,-2);
+lua_setfenv(L,-2);
+return 0;
+}
+else if(lua_iscfunction(L,-2)||lua_setfenv(L,-2)==0)
+luaL_error(L,
+LUA_QL("setfenv")" cannot change environment of given object");
+return 1;
+}
+static int luaB_rawget(lua_State*L){
+luaL_checktype(L,1,5);
+luaL_checkany(L,2);
+lua_settop(L,2);
+lua_rawget(L,1);
+return 1;
+}
+static int luaB_type(lua_State*L){
+luaL_checkany(L,1);
+lua_pushstring(L,luaL_typename(L,1));
+return 1;
+}
+static int luaB_next(lua_State*L){
+luaL_checktype(L,1,5);
+lua_settop(L,2);
+if(lua_next(L,1))
+return 2;
+else{
+lua_pushnil(L);
+return 1;
+}
+}
+static int luaB_pairs(lua_State*L){
+luaL_checktype(L,1,5);
+lua_pushvalue(L,lua_upvalueindex(1));
+lua_pushvalue(L,1);
+lua_pushnil(L);
+return 3;
+}
+static int ipairsaux(lua_State*L){
+int i=luaL_checkint(L,2);
+luaL_checktype(L,1,5);
+i++;
+lua_pushinteger(L,i);
+lua_rawgeti(L,1,i);
+return(lua_isnil(L,-1))?0:2;
+}
+static int luaB_ipairs(lua_State*L){
+luaL_checktype(L,1,5);
+lua_pushvalue(L,lua_upvalueindex(1));
+lua_pushvalue(L,1);
+lua_pushinteger(L,0);
+return 3;
+}
+static int load_aux(lua_State*L,int status){
+if(status==0)
+return 1;
+else{
+lua_pushnil(L);
+lua_insert(L,-2);
+return 2;
+}
+}
+static int luaB_loadstring(lua_State*L){
+size_t l;
+const char*s=luaL_checklstring(L,1,&l);
+const char*chunkname=luaL_optstring(L,2,s);
+return load_aux(L,luaL_loadbuffer(L,s,l,chunkname));
+}
+static int luaB_loadfile(lua_State*L){
+const char*fname=luaL_optstring(L,1,NULL);
+return load_aux(L,luaL_loadfile(L,fname));
+}
+static int luaB_assert(lua_State*L){
+luaL_checkany(L,1);
+if(!lua_toboolean(L,1))
+return luaL_error(L,"%s",luaL_optstring(L,2,"assertion failed!"));
+return lua_gettop(L);
+}
+static int luaB_unpack(lua_State*L){
+int i,e,n;
+luaL_checktype(L,1,5);
+i=luaL_optint(L,2,1);
+e=luaL_opt(L,luaL_checkint,3,luaL_getn(L,1));
+if(i>e)return 0;
+n=e-i+1;
+if(n<=0||!lua_checkstack(L,n))
+return luaL_error(L,"too many results to unpack");
+lua_rawgeti(L,1,i);
+while(i++<e)
+lua_rawgeti(L,1,i);
+return n;
+}
+static int luaB_pcall(lua_State*L){
+int status;
+luaL_checkany(L,1);
+status=lua_pcall(L,lua_gettop(L)-1,(-1),0);
+lua_pushboolean(L,(status==0));
+lua_insert(L,1);
+return lua_gettop(L);
+}
+static int luaB_newproxy(lua_State*L){
+lua_settop(L,1);
+lua_newuserdata(L,0);
+if(lua_toboolean(L,1)==0)
+return 1;
+else if(lua_isboolean(L,1)){
+lua_newtable(L);
+lua_pushvalue(L,-1);
+lua_pushboolean(L,1);
+lua_rawset(L,lua_upvalueindex(1));
+}
+else{
+int validproxy=0;
+if(lua_getmetatable(L,1)){
+lua_rawget(L,lua_upvalueindex(1));
+validproxy=lua_toboolean(L,-1);
+lua_pop(L,1);
+}
+luaL_argcheck(L,validproxy,1,"boolean or proxy expected");
+lua_getmetatable(L,1);
+}
+lua_setmetatable(L,2);
+return 1;
+}
+static const luaL_Reg base_funcs[]={
+{"assert",luaB_assert},
+{"error",luaB_error},
+{"loadfile",luaB_loadfile},
+{"loadstring",luaB_loadstring},
+{"next",luaB_next},
+{"pcall",luaB_pcall},
+{"rawget",luaB_rawget},
+{"setfenv",luaB_setfenv},
+{"setmetatable",luaB_setmetatable},
+{"tonumber",luaB_tonumber},
+{"type",luaB_type},
+{"unpack",luaB_unpack},
+{NULL,NULL}
+};
+static void auxopen(lua_State*L,const char*name,
+lua_CFunction f,lua_CFunction u){
+lua_pushcfunction(L,u);
+lua_pushcclosure(L,f,1);
+lua_setfield(L,-2,name);
+}
+static void base_open(lua_State*L){
+lua_pushvalue(L,(-10002));
+lua_setglobal(L,"_G");
+luaL_register(L,"_G",base_funcs);
+lua_pushliteral(L,"Lua 5.1");
+lua_setglobal(L,"_VERSION");
+auxopen(L,"ipairs",luaB_ipairs,ipairsaux);
+auxopen(L,"pairs",luaB_pairs,luaB_next);
+lua_createtable(L,0,1);
+lua_pushvalue(L,-1);
+lua_setmetatable(L,-2);
+lua_pushliteral(L,"kv");
+lua_setfield(L,-2,"__mode");
+lua_pushcclosure(L,luaB_newproxy,1);
+lua_setglobal(L,"newproxy");
+}
+static int luaopen_base(lua_State*L){
+base_open(L);
+return 1;
+}
+#define aux_getn(L,n)(luaL_checktype(L,n,5),luaL_getn(L,n))
+static int tinsert(lua_State*L){
+int e=aux_getn(L,1)+1;
+int pos;
+switch(lua_gettop(L)){
+case 2:{
+pos=e;
+break;
+}
+case 3:{
+int i;
+pos=luaL_checkint(L,2);
+if(pos>e)e=pos;
+for(i=e;i>pos;i--){
+lua_rawgeti(L,1,i-1);
+lua_rawseti(L,1,i);
+}
+break;
+}
+default:{
+return luaL_error(L,"wrong number of arguments to "LUA_QL("insert"));
+}
+}
+luaL_setn(L,1,e);
+lua_rawseti(L,1,pos);
+return 0;
+}
+static int tremove(lua_State*L){
+int e=aux_getn(L,1);
+int pos=luaL_optint(L,2,e);
+if(!(1<=pos&&pos<=e))
+return 0;
+luaL_setn(L,1,e-1);
+lua_rawgeti(L,1,pos);
+for(;pos<e;pos++){
+lua_rawgeti(L,1,pos+1);
+lua_rawseti(L,1,pos);
+}
+lua_pushnil(L);
+lua_rawseti(L,1,e);
+return 1;
+}
+static void addfield(lua_State*L,luaL_Buffer*b,int i){
+lua_rawgeti(L,1,i);
+if(!lua_isstring(L,-1))
+luaL_error(L,"invalid value (%s) at index %d in table for "
+LUA_QL("concat"),luaL_typename(L,-1),i);
+luaL_addvalue(b);
+}
+static int tconcat(lua_State*L){
+luaL_Buffer b;
+size_t lsep;
+int i,last;
+const char*sep=luaL_optlstring(L,2,"",&lsep);
+luaL_checktype(L,1,5);
+i=luaL_optint(L,3,1);
+last=luaL_opt(L,luaL_checkint,4,luaL_getn(L,1));
+luaL_buffinit(L,&b);
+for(;i<last;i++){
+addfield(L,&b,i);
+luaL_addlstring(&b,sep,lsep);
+}
+if(i==last)
+addfield(L,&b,i);
+luaL_pushresult(&b);
+return 1;
+}
+static void set2(lua_State*L,int i,int j){
+lua_rawseti(L,1,i);
+lua_rawseti(L,1,j);
+}
+static int sort_comp(lua_State*L,int a,int b){
+if(!lua_isnil(L,2)){
+int res;
+lua_pushvalue(L,2);
+lua_pushvalue(L,a-1);
+lua_pushvalue(L,b-2);
+lua_call(L,2,1);
+res=lua_toboolean(L,-1);
+lua_pop(L,1);
+return res;
+}
+else
+return lua_lessthan(L,a,b);
+}
+static void auxsort(lua_State*L,int l,int u){
+while(l<u){
+int i,j;
+lua_rawgeti(L,1,l);
+lua_rawgeti(L,1,u);
+if(sort_comp(L,-1,-2))
+set2(L,l,u);
+else
+lua_pop(L,2);
+if(u-l==1)break;
+i=(l+u)/2;
+lua_rawgeti(L,1,i);
+lua_rawgeti(L,1,l);
+if(sort_comp(L,-2,-1))
+set2(L,i,l);
+else{
+lua_pop(L,1);
+lua_rawgeti(L,1,u);
+if(sort_comp(L,-1,-2))
+set2(L,i,u);
+else
+lua_pop(L,2);
+}
+if(u-l==2)break;
+lua_rawgeti(L,1,i);
+lua_pushvalue(L,-1);
+lua_rawgeti(L,1,u-1);
+set2(L,i,u-1);
+i=l;j=u-1;
+for(;;){
+while(lua_rawgeti(L,1,++i),sort_comp(L,-1,-2)){
+if(i>u)luaL_error(L,"invalid order function for sorting");
+lua_pop(L,1);
+}
+while(lua_rawgeti(L,1,--j),sort_comp(L,-3,-1)){
+if(j<l)luaL_error(L,"invalid order function for sorting");
+lua_pop(L,1);
+}
+if(j<i){
+lua_pop(L,3);
+break;
+}
+set2(L,i,j);
+}
+lua_rawgeti(L,1,u-1);
+lua_rawgeti(L,1,i);
+set2(L,u-1,i);
+if(i-l<u-i){
+j=l;i=i-1;l=i+2;
+}
+else{
+j=i+1;i=u;u=j-2;
+}
+auxsort(L,j,i);
+}
+}
+static int sort(lua_State*L){
+int n=aux_getn(L,1);
+luaL_checkstack(L,40,"");
+if(!lua_isnoneornil(L,2))
+luaL_checktype(L,2,6);
+lua_settop(L,2);
+auxsort(L,1,n);
+return 0;
+}
+static const luaL_Reg tab_funcs[]={
+{"concat",tconcat},
+{"insert",tinsert},
+{"remove",tremove},
+{"sort",sort},
+{NULL,NULL}
+};
+static int luaopen_table(lua_State*L){
+luaL_register(L,"table",tab_funcs);
+return 1;
+}
+static const char*const fnames[]={"input","output"};
+static int pushresult(lua_State*L,int i,const char*filename){
+int en=errno;
+if(i){
+lua_pushboolean(L,1);
+return 1;
+}
+else{
+lua_pushnil(L);
+if(filename)
+lua_pushfstring(L,"%s: %s",filename,strerror(en));
+else
+lua_pushfstring(L,"%s",strerror(en));
+lua_pushinteger(L,en);
+return 3;
+}
+}
+static void fileerror(lua_State*L,int arg,const char*filename){
+lua_pushfstring(L,"%s: %s",filename,strerror(errno));
+luaL_argerror(L,arg,lua_tostring(L,-1));
+}
+#define tofilep(L)((FILE**)luaL_checkudata(L,1,"FILE*"))
+static int io_type(lua_State*L){
+void*ud;
+luaL_checkany(L,1);
+ud=lua_touserdata(L,1);
+lua_getfield(L,(-10000),"FILE*");
+if(ud==NULL||!lua_getmetatable(L,1)||!lua_rawequal(L,-2,-1))
+lua_pushnil(L);
+else if(*((FILE**)ud)==NULL)
+lua_pushliteral(L,"closed file");
+else
+lua_pushliteral(L,"file");
+return 1;
+}
+static FILE*tofile(lua_State*L){
+FILE**f=tofilep(L);
+if(*f==NULL)
+luaL_error(L,"attempt to use a closed file");
+return*f;
+}
+static FILE**newfile(lua_State*L){
+FILE**pf=(FILE**)lua_newuserdata(L,sizeof(FILE*));
+*pf=NULL;
+luaL_getmetatable(L,"FILE*");
+lua_setmetatable(L,-2);
+return pf;
+}
+static int io_noclose(lua_State*L){
+lua_pushnil(L);
+lua_pushliteral(L,"cannot close standard file");
+return 2;
+}
+static int io_pclose(lua_State*L){
+FILE**p=tofilep(L);
+int ok=lua_pclose(L,*p);
+*p=NULL;
+return pushresult(L,ok,NULL);
+}
+static int io_fclose(lua_State*L){
+FILE**p=tofilep(L);
+int ok=(fclose(*p)==0);
+*p=NULL;
+return pushresult(L,ok,NULL);
+}
+static int aux_close(lua_State*L){
+lua_getfenv(L,1);
+lua_getfield(L,-1,"__close");
+return(lua_tocfunction(L,-1))(L);
+}
+static int io_close(lua_State*L){
+if(lua_isnone(L,1))
+lua_rawgeti(L,(-10001),2);
+tofile(L);
+return aux_close(L);
+}
+static int io_gc(lua_State*L){
+FILE*f=*tofilep(L);
+if(f!=NULL)
+aux_close(L);
+return 0;
+}
+static int io_open(lua_State*L){
+const char*filename=luaL_checkstring(L,1);
+const char*mode=luaL_optstring(L,2,"r");
+FILE**pf=newfile(L);
+*pf=fopen(filename,mode);
+return(*pf==NULL)?pushresult(L,0,filename):1;
+}
+static FILE*getiofile(lua_State*L,int findex){
+FILE*f;
+lua_rawgeti(L,(-10001),findex);
+f=*(FILE**)lua_touserdata(L,-1);
+if(f==NULL)
+luaL_error(L,"standard %s file is closed",fnames[findex-1]);
+return f;
+}
+static int g_iofile(lua_State*L,int f,const char*mode){
+if(!lua_isnoneornil(L,1)){
+const char*filename=lua_tostring(L,1);
+if(filename){
+FILE**pf=newfile(L);
+*pf=fopen(filename,mode);
+if(*pf==NULL)
+fileerror(L,1,filename);
+}
+else{
+tofile(L);
+lua_pushvalue(L,1);
+}
+lua_rawseti(L,(-10001),f);
+}
+lua_rawgeti(L,(-10001),f);
+return 1;
+}
+static int io_input(lua_State*L){
+return g_iofile(L,1,"r");
+}
+static int io_output(lua_State*L){
+return g_iofile(L,2,"w");
+}
+static int io_readline(lua_State*L);
+static void aux_lines(lua_State*L,int idx,int toclose){
+lua_pushvalue(L,idx);
+lua_pushboolean(L,toclose);
+lua_pushcclosure(L,io_readline,2);
+}
+static int f_lines(lua_State*L){
+tofile(L);
+aux_lines(L,1,0);
+return 1;
+}
+static int io_lines(lua_State*L){
+if(lua_isnoneornil(L,1)){
+lua_rawgeti(L,(-10001),1);
+return f_lines(L);
+}
+else{
+const char*filename=luaL_checkstring(L,1);
+FILE**pf=newfile(L);
+*pf=fopen(filename,"r");
+if(*pf==NULL)
+fileerror(L,1,filename);
+aux_lines(L,lua_gettop(L),1);
+return 1;
+}
+}
+static int read_number(lua_State*L,FILE*f){
+lua_Number d;
+if(fscanf(f,"%lf",&d)==1){
+lua_pushnumber(L,d);
+return 1;
+}
+else{
+lua_pushnil(L);
+return 0;
+}
+}
+static int test_eof(lua_State*L,FILE*f){
+int c=getc(f);
+ungetc(c,f);
+lua_pushlstring(L,NULL,0);
+return(c!=EOF);
+}
+static int read_line(lua_State*L,FILE*f){
+luaL_Buffer b;
+luaL_buffinit(L,&b);
+for(;;){
+size_t l;
+char*p=luaL_prepbuffer(&b);
+if(fgets(p,BUFSIZ,f)==NULL){
+luaL_pushresult(&b);
+return(lua_objlen(L,-1)>0);
+}
+l=strlen(p);
+if(l==0||p[l-1]!='\n')
+luaL_addsize(&b,l);
+else{
+luaL_addsize(&b,l-1);
+luaL_pushresult(&b);
+return 1;
+}
+}
+}
+static int read_chars(lua_State*L,FILE*f,size_t n){
+size_t rlen;
+size_t nr;
+luaL_Buffer b;
+luaL_buffinit(L,&b);
+rlen=BUFSIZ;
+do{
+char*p=luaL_prepbuffer(&b);
+if(rlen>n)rlen=n;
+nr=fread(p,sizeof(char),rlen,f);
+luaL_addsize(&b,nr);
+n-=nr;
+}while(n>0&&nr==rlen);
+luaL_pushresult(&b);
+return(n==0||lua_objlen(L,-1)>0);
+}
+static int g_read(lua_State*L,FILE*f,int first){
+int nargs=lua_gettop(L)-1;
+int success;
+int n;
+clearerr(f);
+if(nargs==0){
+success=read_line(L,f);
+n=first+1;
+}
+else{
+luaL_checkstack(L,nargs+20,"too many arguments");
+success=1;
+for(n=first;nargs--&&success;n++){
+if(lua_type(L,n)==3){
+size_t l=(size_t)lua_tointeger(L,n);
+success=(l==0)?test_eof(L,f):read_chars(L,f,l);
+}
+else{
+const char*p=lua_tostring(L,n);
+luaL_argcheck(L,p&&p[0]=='*',n,"invalid option");
+switch(p[1]){
+case'n':
+success=read_number(L,f);
+break;
+case'l':
+success=read_line(L,f);
+break;
+case'a':
+read_chars(L,f,~((size_t)0));
+success=1;
+break;
+default:
+return luaL_argerror(L,n,"invalid format");
+}
+}
+}
+}
+if(ferror(f))
+return pushresult(L,0,NULL);
+if(!success){
+lua_pop(L,1);
+lua_pushnil(L);
+}
+return n-first;
+}
+static int io_read(lua_State*L){
+return g_read(L,getiofile(L,1),1);
+}
+static int f_read(lua_State*L){
+return g_read(L,tofile(L),2);
+}
+static int io_readline(lua_State*L){
+FILE*f=*(FILE**)lua_touserdata(L,lua_upvalueindex(1));
+int sucess;
+if(f==NULL)
+luaL_error(L,"file is already closed");
+sucess=read_line(L,f);
+if(ferror(f))
+return luaL_error(L,"%s",strerror(errno));
+if(sucess)return 1;
+else{
+if(lua_toboolean(L,lua_upvalueindex(2))){
+lua_settop(L,0);
+lua_pushvalue(L,lua_upvalueindex(1));
+aux_close(L);
+}
+return 0;
+}
+}
+static int g_write(lua_State*L,FILE*f,int arg){
+int nargs=lua_gettop(L)-1;
+int status=1;
+for(;nargs--;arg++){
+if(lua_type(L,arg)==3){
+status=status&&
+fprintf(f,"%.14g",lua_tonumber(L,arg))>0;
+}
+else{
+size_t l;
+const char*s=luaL_checklstring(L,arg,&l);
+status=status&&(fwrite(s,sizeof(char),l,f)==l);
+}
+}
+return pushresult(L,status,NULL);
+}
+static int io_write(lua_State*L){
+return g_write(L,getiofile(L,2),1);
+}
+static int f_write(lua_State*L){
+return g_write(L,tofile(L),2);
+}
+static int io_flush(lua_State*L){
+return pushresult(L,fflush(getiofile(L,2))==0,NULL);
+}
+static int f_flush(lua_State*L){
+return pushresult(L,fflush(tofile(L))==0,NULL);
+}
+static const luaL_Reg iolib[]={
+{"close",io_close},
+{"flush",io_flush},
+{"input",io_input},
+{"lines",io_lines},
+{"open",io_open},
+{"output",io_output},
+{"read",io_read},
+{"type",io_type},
+{"write",io_write},
+{NULL,NULL}
+};
+static const luaL_Reg flib[]={
+{"close",io_close},
+{"flush",f_flush},
+{"lines",f_lines},
+{"read",f_read},
+{"write",f_write},
+{"__gc",io_gc},
+{NULL,NULL}
+};
+static void createmeta(lua_State*L){
+luaL_newmetatable(L,"FILE*");
+lua_pushvalue(L,-1);
+lua_setfield(L,-2,"__index");
+luaL_register(L,NULL,flib);
+}
+static void createstdfile(lua_State*L,FILE*f,int k,const char*fname){
+*newfile(L)=f;
+if(k>0){
+lua_pushvalue(L,-1);
+lua_rawseti(L,(-10001),k);
+}
+lua_pushvalue(L,-2);
+lua_setfenv(L,-2);
+lua_setfield(L,-3,fname);
+}
+static void newfenv(lua_State*L,lua_CFunction cls){
+lua_createtable(L,0,1);
+lua_pushcfunction(L,cls);
+lua_setfield(L,-2,"__close");
+}
+static int luaopen_io(lua_State*L){
+createmeta(L);
+newfenv(L,io_fclose);
+lua_replace(L,(-10001));
+luaL_register(L,"io",iolib);
+newfenv(L,io_noclose);
+createstdfile(L,stdin,1,"stdin");
+createstdfile(L,stdout,2,"stdout");
+createstdfile(L,stderr,0,"stderr");
+lua_pop(L,1);
+lua_getfield(L,-1,"popen");
+newfenv(L,io_pclose);
+lua_setfenv(L,-2);
+lua_pop(L,1);
+return 1;
+}
+static int os_pushresult(lua_State*L,int i,const char*filename){
+int en=errno;
+if(i){
+lua_pushboolean(L,1);
+return 1;
+}
+else{
+lua_pushnil(L);
+lua_pushfstring(L,"%s: %s",filename,strerror(en));
+lua_pushinteger(L,en);
+return 3;
+}
+}
+static int os_remove(lua_State*L){
+const char*filename=luaL_checkstring(L,1);
+return os_pushresult(L,remove(filename)==0,filename);
+}
+static int os_exit(lua_State*L){
+exit(luaL_optint(L,1,EXIT_SUCCESS));
+}
+static const luaL_Reg syslib[]={
+{"exit",os_exit},
+{"remove",os_remove},
+{NULL,NULL}
+};
+static int luaopen_os(lua_State*L){
+luaL_register(L,"os",syslib);
+return 1;
+}
+#define uchar(c)((unsigned char)(c))
+static ptrdiff_t posrelat(ptrdiff_t pos,size_t len){
+if(pos<0)pos+=(ptrdiff_t)len+1;
+return(pos>=0)?pos:0;
+}
+static int str_sub(lua_State*L){
+size_t l;
+const char*s=luaL_checklstring(L,1,&l);
+ptrdiff_t start=posrelat(luaL_checkinteger(L,2),l);
+ptrdiff_t end=posrelat(luaL_optinteger(L,3,-1),l);
+if(start<1)start=1;
+if(end>(ptrdiff_t)l)end=(ptrdiff_t)l;
+if(start<=end)
+lua_pushlstring(L,s+start-1,end-start+1);
+else lua_pushliteral(L,"");
+return 1;
+}
+static int str_lower(lua_State*L){
+size_t l;
+size_t i;
+luaL_Buffer b;
+const char*s=luaL_checklstring(L,1,&l);
+luaL_buffinit(L,&b);
+for(i=0;i<l;i++)
+luaL_addchar(&b,tolower(uchar(s[i])));
+luaL_pushresult(&b);
+return 1;
+}
+static int str_upper(lua_State*L){
+size_t l;
+size_t i;
+luaL_Buffer b;
+const char*s=luaL_checklstring(L,1,&l);
+luaL_buffinit(L,&b);
+for(i=0;i<l;i++)
+luaL_addchar(&b,toupper(uchar(s[i])));
+luaL_pushresult(&b);
+return 1;
+}
+static int str_rep(lua_State*L){
+size_t l;
+luaL_Buffer b;
+const char*s=luaL_checklstring(L,1,&l);
+int n=luaL_checkint(L,2);
+luaL_buffinit(L,&b);
+while(n-->0)
+luaL_addlstring(&b,s,l);
+luaL_pushresult(&b);
+return 1;
+}
+static int str_byte(lua_State*L){
+size_t l;
+const char*s=luaL_checklstring(L,1,&l);
+ptrdiff_t posi=posrelat(luaL_optinteger(L,2,1),l);
+ptrdiff_t pose=posrelat(luaL_optinteger(L,3,posi),l);
+int n,i;
+if(posi<=0)posi=1;
+if((size_t)pose>l)pose=l;
+if(posi>pose)return 0;
+n=(int)(pose-posi+1);
+if(posi+n<=pose)
+luaL_error(L,"string slice too long");
+luaL_checkstack(L,n,"string slice too long");
+for(i=0;i<n;i++)
+lua_pushinteger(L,uchar(s[posi+i-1]));
+return n;
+}
+static int str_char(lua_State*L){
+int n=lua_gettop(L);
+int i;
+luaL_Buffer b;
+luaL_buffinit(L,&b);
+for(i=1;i<=n;i++){
+int c=luaL_checkint(L,i);
+luaL_argcheck(L,uchar(c)==c,i,"invalid value");
+luaL_addchar(&b,uchar(c));
+}
+luaL_pushresult(&b);
+return 1;
+}
+typedef struct MatchState{
+const char*src_init;
+const char*src_end;
+lua_State*L;
+int level;
+struct{
+const char*init;
+ptrdiff_t len;
+}capture[32];
+}MatchState;
+static int check_capture(MatchState*ms,int l){
+l-='1';
+if(l<0||l>=ms->level||ms->capture[l].len==(-1))
+return luaL_error(ms->L,"invalid capture index");
+return l;
+}
+static int capture_to_close(MatchState*ms){
+int level=ms->level;
+for(level--;level>=0;level--)
+if(ms->capture[level].len==(-1))return level;
+return luaL_error(ms->L,"invalid pattern capture");
+}
+static const char*classend(MatchState*ms,const char*p){
+switch(*p++){
+case'%':{
+if(*p=='\0')
+luaL_error(ms->L,"malformed pattern (ends with "LUA_QL("%%")")");
+return p+1;
+}
+case'[':{
+if(*p=='^')p++;
+do{
+if(*p=='\0')
+luaL_error(ms->L,"malformed pattern (missing "LUA_QL("]")")");
+if(*(p++)=='%'&&*p!='\0')
+p++;
+}while(*p!=']');
+return p+1;
+}
+default:{
+return p;
+}
+}
+}
+static int match_class(int c,int cl){
+int res;
+switch(tolower(cl)){
+case'a':res=isalpha(c);break;
+case'c':res=iscntrl(c);break;
+case'd':res=isdigit(c);break;
+case'l':res=islower(c);break;
+case'p':res=ispunct(c);break;
+case's':res=isspace(c);break;
+case'u':res=isupper(c);break;
+case'w':res=isalnum(c);break;
+case'x':res=isxdigit(c);break;
+case'z':res=(c==0);break;
+default:return(cl==c);
+}
+return(islower(cl)?res:!res);
+}
+static int matchbracketclass(int c,const char*p,const char*ec){
+int sig=1;
+if(*(p+1)=='^'){
+sig=0;
+p++;
+}
+while(++p<ec){
+if(*p=='%'){
+p++;
+if(match_class(c,uchar(*p)))
+return sig;
+}
+else if((*(p+1)=='-')&&(p+2<ec)){
+p+=2;
+if(uchar(*(p-2))<=c&&c<=uchar(*p))
+return sig;
+}
+else if(uchar(*p)==c)return sig;
+}
+return!sig;
+}
+static int singlematch(int c,const char*p,const char*ep){
+switch(*p){
+case'.':return 1;
+case'%':return match_class(c,uchar(*(p+1)));
+case'[':return matchbracketclass(c,p,ep-1);
+default:return(uchar(*p)==c);
+}
+}
+static const char*match(MatchState*ms,const char*s,const char*p);
+static const char*matchbalance(MatchState*ms,const char*s,
+const char*p){
+if(*p==0||*(p+1)==0)
+luaL_error(ms->L,"unbalanced pattern");
+if(*s!=*p)return NULL;
+else{
+int b=*p;
+int e=*(p+1);
+int cont=1;
+while(++s<ms->src_end){
+if(*s==e){
+if(--cont==0)return s+1;
+}
+else if(*s==b)cont++;
+}
+}
+return NULL;
+}
+static const char*max_expand(MatchState*ms,const char*s,
+const char*p,const char*ep){
+ptrdiff_t i=0;
+while((s+i)<ms->src_end&&singlematch(uchar(*(s+i)),p,ep))
+i++;
+while(i>=0){
+const char*res=match(ms,(s+i),ep+1);
+if(res)return res;
+i--;
+}
+return NULL;
+}
+static const char*min_expand(MatchState*ms,const char*s,
+const char*p,const char*ep){
+for(;;){
+const char*res=match(ms,s,ep+1);
+if(res!=NULL)
+return res;
+else if(s<ms->src_end&&singlematch(uchar(*s),p,ep))
+s++;
+else return NULL;
+}
+}
+static const char*start_capture(MatchState*ms,const char*s,
+const char*p,int what){
+const char*res;
+int level=ms->level;
+if(level>=32)luaL_error(ms->L,"too many captures");
+ms->capture[level].init=s;
+ms->capture[level].len=what;
+ms->level=level+1;
+if((res=match(ms,s,p))==NULL)
+ms->level--;
+return res;
+}
+static const char*end_capture(MatchState*ms,const char*s,
+const char*p){
+int l=capture_to_close(ms);
+const char*res;
+ms->capture[l].len=s-ms->capture[l].init;
+if((res=match(ms,s,p))==NULL)
+ms->capture[l].len=(-1);
+return res;
+}
+static const char*match_capture(MatchState*ms,const char*s,int l){
+size_t len;
+l=check_capture(ms,l);
+len=ms->capture[l].len;
+if((size_t)(ms->src_end-s)>=len&&
+memcmp(ms->capture[l].init,s,len)==0)
+return s+len;
+else return NULL;
+}
+static const char*match(MatchState*ms,const char*s,const char*p){
+init:
+switch(*p){
+case'(':{
+if(*(p+1)==')')
+return start_capture(ms,s,p+2,(-2));
+else
+return start_capture(ms,s,p+1,(-1));
+}
+case')':{
+return end_capture(ms,s,p+1);
+}
+case'%':{
+switch(*(p+1)){
+case'b':{
+s=matchbalance(ms,s,p+2);
+if(s==NULL)return NULL;
+p+=4;goto init;
+}
+case'f':{
+const char*ep;char previous;
+p+=2;
+if(*p!='[')
+luaL_error(ms->L,"missing "LUA_QL("[")" after "
+LUA_QL("%%f")" in pattern");
+ep=classend(ms,p);
+previous=(s==ms->src_init)?'\0':*(s-1);
+if(matchbracketclass(uchar(previous),p,ep-1)||
+!matchbracketclass(uchar(*s),p,ep-1))return NULL;
+p=ep;goto init;
+}
+default:{
+if(isdigit(uchar(*(p+1)))){
+s=match_capture(ms,s,uchar(*(p+1)));
+if(s==NULL)return NULL;
+p+=2;goto init;
+}
+goto dflt;
+}
+}
+}
+case'\0':{
+return s;
+}
+case'$':{
+if(*(p+1)=='\0')
+return(s==ms->src_end)?s:NULL;
+else goto dflt;
+}
+default:dflt:{
+const char*ep=classend(ms,p);
+int m=s<ms->src_end&&singlematch(uchar(*s),p,ep);
+switch(*ep){
+case'?':{
+const char*res;
+if(m&&((res=match(ms,s+1,ep+1))!=NULL))
+return res;
+p=ep+1;goto init;
+}
+case'*':{
+return max_expand(ms,s,p,ep);
+}
+case'+':{
+return(m?max_expand(ms,s+1,p,ep):NULL);
+}
+case'-':{
+return min_expand(ms,s,p,ep);
+}
+default:{
+if(!m)return NULL;
+s++;p=ep;goto init;
+}
+}
+}
+}
+}
+static const char*lmemfind(const char*s1,size_t l1,
+const char*s2,size_t l2){
+if(l2==0)return s1;
+else if(l2>l1)return NULL;
+else{
+const char*init;
+l2--;
+l1=l1-l2;
+while(l1>0&&(init=(const char*)memchr(s1,*s2,l1))!=NULL){
+init++;
+if(memcmp(init,s2+1,l2)==0)
+return init-1;
+else{
+l1-=init-s1;
+s1=init;
+}
+}
+return NULL;
+}
+}
+static void push_onecapture(MatchState*ms,int i,const char*s,
+const char*e){
+if(i>=ms->level){
+if(i==0)
+lua_pushlstring(ms->L,s,e-s);
+else
+luaL_error(ms->L,"invalid capture index");
+}
+else{
+ptrdiff_t l=ms->capture[i].len;
+if(l==(-1))luaL_error(ms->L,"unfinished capture");
+if(l==(-2))
+lua_pushinteger(ms->L,ms->capture[i].init-ms->src_init+1);
+else
+lua_pushlstring(ms->L,ms->capture[i].init,l);
+}
+}
+static int push_captures(MatchState*ms,const char*s,const char*e){
+int i;
+int nlevels=(ms->level==0&&s)?1:ms->level;
+luaL_checkstack(ms->L,nlevels,"too many captures");
+for(i=0;i<nlevels;i++)
+push_onecapture(ms,i,s,e);
+return nlevels;
+}
+static int str_find_aux(lua_State*L,int find){
+size_t l1,l2;
+const char*s=luaL_checklstring(L,1,&l1);
+const char*p=luaL_checklstring(L,2,&l2);
+ptrdiff_t init=posrelat(luaL_optinteger(L,3,1),l1)-1;
+if(init<0)init=0;
+else if((size_t)(init)>l1)init=(ptrdiff_t)l1;
+if(find&&(lua_toboolean(L,4)||
+strpbrk(p,"^$*+?.([%-")==NULL)){
+const char*s2=lmemfind(s+init,l1-init,p,l2);
+if(s2){
+lua_pushinteger(L,s2-s+1);
+lua_pushinteger(L,s2-s+l2);
+return 2;
+}
+}
+else{
+MatchState ms;
+int anchor=(*p=='^')?(p++,1):0;
+const char*s1=s+init;
+ms.L=L;
+ms.src_init=s;
+ms.src_end=s+l1;
+do{
+const char*res;
+ms.level=0;
+if((res=match(&ms,s1,p))!=NULL){
+if(find){
+lua_pushinteger(L,s1-s+1);
+lua_pushinteger(L,res-s);
+return push_captures(&ms,NULL,0)+2;
+}
+else
+return push_captures(&ms,s1,res);
+}
+}while(s1++<ms.src_end&&!anchor);
+}
+lua_pushnil(L);
+return 1;
+}
+static int str_find(lua_State*L){
+return str_find_aux(L,1);
+}
+static int str_match(lua_State*L){
+return str_find_aux(L,0);
+}
+static int gmatch_aux(lua_State*L){
+MatchState ms;
+size_t ls;
+const char*s=lua_tolstring(L,lua_upvalueindex(1),&ls);
+const char*p=lua_tostring(L,lua_upvalueindex(2));
+const char*src;
+ms.L=L;
+ms.src_init=s;
+ms.src_end=s+ls;
+for(src=s+(size_t)lua_tointeger(L,lua_upvalueindex(3));
+src<=ms.src_end;
+src++){
+const char*e;
+ms.level=0;
+if((e=match(&ms,src,p))!=NULL){
+lua_Integer newstart=e-s;
+if(e==src)newstart++;
+lua_pushinteger(L,newstart);
+lua_replace(L,lua_upvalueindex(3));
+return push_captures(&ms,src,e);
+}
+}
+return 0;
+}
+static int gmatch(lua_State*L){
+luaL_checkstring(L,1);
+luaL_checkstring(L,2);
+lua_settop(L,2);
+lua_pushinteger(L,0);
+lua_pushcclosure(L,gmatch_aux,3);
+return 1;
+}
+static void add_s(MatchState*ms,luaL_Buffer*b,const char*s,
+const char*e){
+size_t l,i;
+const char*news=lua_tolstring(ms->L,3,&l);
+for(i=0;i<l;i++){
+if(news[i]!='%')
+luaL_addchar(b,news[i]);
+else{
+i++;
+if(!isdigit(uchar(news[i])))
+luaL_addchar(b,news[i]);
+else if(news[i]=='0')
+luaL_addlstring(b,s,e-s);
+else{
+push_onecapture(ms,news[i]-'1',s,e);
+luaL_addvalue(b);
+}
+}
+}
+}
+static void add_value(MatchState*ms,luaL_Buffer*b,const char*s,
+const char*e){
+lua_State*L=ms->L;
+switch(lua_type(L,3)){
+case 3:
+case 4:{
+add_s(ms,b,s,e);
+return;
+}
+case 6:{
+int n;
+lua_pushvalue(L,3);
+n=push_captures(ms,s,e);
+lua_call(L,n,1);
+break;
+}
+case 5:{
+push_onecapture(ms,0,s,e);
+lua_gettable(L,3);
+break;
+}
+}
+if(!lua_toboolean(L,-1)){
+lua_pop(L,1);
+lua_pushlstring(L,s,e-s);
+}
+else if(!lua_isstring(L,-1))
+luaL_error(L,"invalid replacement value (a %s)",luaL_typename(L,-1));
+luaL_addvalue(b);
+}
+static int str_gsub(lua_State*L){
+size_t srcl;
+const char*src=luaL_checklstring(L,1,&srcl);
+const char*p=luaL_checkstring(L,2);
+int tr=lua_type(L,3);
+int max_s=luaL_optint(L,4,srcl+1);
+int anchor=(*p=='^')?(p++,1):0;
+int n=0;
+MatchState ms;
+luaL_Buffer b;
+luaL_argcheck(L,tr==3||tr==4||
+tr==6||tr==5,3,
+"string/function/table expected");
+luaL_buffinit(L,&b);
+ms.L=L;
+ms.src_init=src;
+ms.src_end=src+srcl;
+while(n<max_s){
+const char*e;
+ms.level=0;
+e=match(&ms,src,p);
+if(e){
+n++;
+add_value(&ms,&b,src,e);
+}
+if(e&&e>src)
+src=e;
+else if(src<ms.src_end)
+luaL_addchar(&b,*src++);
+else break;
+if(anchor)break;
+}
+luaL_addlstring(&b,src,ms.src_end-src);
+luaL_pushresult(&b);
+lua_pushinteger(L,n);
+return 2;
+}
+static void addquoted(lua_State*L,luaL_Buffer*b,int arg){
+size_t l;
+const char*s=luaL_checklstring(L,arg,&l);
+luaL_addchar(b,'"');
+while(l--){
+switch(*s){
+case'"':case'\\':case'\n':{
+luaL_addchar(b,'\\');
+luaL_addchar(b,*s);
+break;
+}
+case'\r':{
+luaL_addlstring(b,"\\r",2);
+break;
+}
+case'\0':{
+luaL_addlstring(b,"\\000",4);
+break;
+}
+default:{
+luaL_addchar(b,*s);
+break;
+}
+}
+s++;
+}
+luaL_addchar(b,'"');
+}
+static const char*scanformat(lua_State*L,const char*strfrmt,char*form){
+const char*p=strfrmt;
+while(*p!='\0'&&strchr("-+ #0",*p)!=NULL)p++;
+if((size_t)(p-strfrmt)>=sizeof("-+ #0"))
+luaL_error(L,"invalid format (repeated flags)");
+if(isdigit(uchar(*p)))p++;
+if(isdigit(uchar(*p)))p++;
+if(*p=='.'){
+p++;
+if(isdigit(uchar(*p)))p++;
+if(isdigit(uchar(*p)))p++;
+}
+if(isdigit(uchar(*p)))
+luaL_error(L,"invalid format (width or precision too long)");
+*(form++)='%';
+strncpy(form,strfrmt,p-strfrmt+1);
+form+=p-strfrmt+1;
+*form='\0';
+return p;
+}
+static void addintlen(char*form){
+size_t l=strlen(form);
+char spec=form[l-1];
+strcpy(form+l-1,"l");
+form[l+sizeof("l")-2]=spec;
+form[l+sizeof("l")-1]='\0';
+}
+static int str_format(lua_State*L){
+int top=lua_gettop(L);
+int arg=1;
+size_t sfl;
+const char*strfrmt=luaL_checklstring(L,arg,&sfl);
+const char*strfrmt_end=strfrmt+sfl;
+luaL_Buffer b;
+luaL_buffinit(L,&b);
+while(strfrmt<strfrmt_end){
+if(*strfrmt!='%')
+luaL_addchar(&b,*strfrmt++);
+else if(*++strfrmt=='%')
+luaL_addchar(&b,*strfrmt++);
+else{
+char form[(sizeof("-+ #0")+sizeof("l")+10)];
+char buff[512];
+if(++arg>top)
+luaL_argerror(L,arg,"no value");
+strfrmt=scanformat(L,strfrmt,form);
+switch(*strfrmt++){
+case'c':{
+sprintf(buff,form,(int)luaL_checknumber(L,arg));
+break;
+}
+case'd':case'i':{
+addintlen(form);
+sprintf(buff,form,(long)luaL_checknumber(L,arg));
+break;
+}
+case'o':case'u':case'x':case'X':{
+addintlen(form);
+sprintf(buff,form,(unsigned long)luaL_checknumber(L,arg));
+break;
+}
+case'e':case'E':case'f':
+case'g':case'G':{
+sprintf(buff,form,(double)luaL_checknumber(L,arg));
+break;
+}
+case'q':{
+addquoted(L,&b,arg);
+continue;
+}
+case's':{
+size_t l;
+const char*s=luaL_checklstring(L,arg,&l);
+if(!strchr(form,'.')&&l>=100){
+lua_pushvalue(L,arg);
+luaL_addvalue(&b);
+continue;
+}
+else{
+sprintf(buff,form,s);
+break;
+}
+}
+default:{
+return luaL_error(L,"invalid option "LUA_QL("%%%c")" to "
+LUA_QL("format"),*(strfrmt-1));
+}
+}
+luaL_addlstring(&b,buff,strlen(buff));
+}
+}
+luaL_pushresult(&b);
+return 1;
+}
+static const luaL_Reg strlib[]={
+{"byte",str_byte},
+{"char",str_char},
+{"find",str_find},
+{"format",str_format},
+{"gmatch",gmatch},
+{"gsub",str_gsub},
+{"lower",str_lower},
+{"match",str_match},
+{"rep",str_rep},
+{"sub",str_sub},
+{"upper",str_upper},
+{NULL,NULL}
+};
+static void createmetatable(lua_State*L){
+lua_createtable(L,0,1);
+lua_pushliteral(L,"");
+lua_pushvalue(L,-2);
+lua_setmetatable(L,-2);
+lua_pop(L,1);
+lua_pushvalue(L,-2);
+lua_setfield(L,-2,"__index");
+lua_pop(L,1);
+}
+static int luaopen_string(lua_State*L){
+luaL_register(L,"string",strlib);
+createmetatable(L);
+return 1;
+}
+static const luaL_Reg lualibs[]={
+{"",luaopen_base},
+{"table",luaopen_table},
+{"io",luaopen_io},
+{"os",luaopen_os},
+{"string",luaopen_string},
+{NULL,NULL}
+};
+static void luaL_openlibs(lua_State*L){
+const luaL_Reg*lib=lualibs;
+for(;lib->func;lib++){
+lua_pushcfunction(L,lib->func);
+lua_pushstring(L,lib->name);
+lua_call(L,1,0);
+}
+}
+typedef unsigned int UB;
+static UB barg(lua_State*L,int idx){
+union{lua_Number n;U64 b;}bn;
+bn.n=lua_tonumber(L,idx)+6755399441055744.0;
+if(bn.n==0.0&&!lua_isnumber(L,idx))luaL_typerror(L,idx,"number");
+return(UB)bn.b;
+}
+#define BRET(b)lua_pushnumber(L,(lua_Number)(int)(b));return 1;
+static int tobit(lua_State*L){
+BRET(barg(L,1))}
+static int bnot(lua_State*L){
+BRET(~barg(L,1))}
+static int band(lua_State*L){
+int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b&=barg(L,i);BRET(b)}
+static int bor(lua_State*L){
+int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b|=barg(L,i);BRET(b)}
+static int bxor(lua_State*L){
+int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b^=barg(L,i);BRET(b)}
+static int lshift(lua_State*L){
+UB b=barg(L,1),n=barg(L,2)&31;BRET(b<<n)}
+static int rshift(lua_State*L){
+UB b=barg(L,1),n=barg(L,2)&31;BRET(b>>n)}
+static int arshift(lua_State*L){
+UB b=barg(L,1),n=barg(L,2)&31;BRET((int)b>>n)}
+static int rol(lua_State*L){
+UB b=barg(L,1),n=barg(L,2)&31;BRET((b<<n)|(b>>(32-n)))}
+static int ror(lua_State*L){
+UB b=barg(L,1),n=barg(L,2)&31;BRET((b>>n)|(b<<(32-n)))}
+static int bswap(lua_State*L){
+UB b=barg(L,1);b=(b>>24)|((b>>8)&0xff00)|((b&0xff00)<<8)|(b<<24);BRET(b)}
+static int tohex(lua_State*L){
+UB b=barg(L,1);
+int n=lua_isnone(L,2)?8:(int)barg(L,2);
+const char*hexdigits="0123456789abcdef";
+char buf[8];
+int i;
+if(n<0){n=-n;hexdigits="0123456789ABCDEF";}
+if(n>8)n=8;
+for(i=(int)n;--i>=0;){buf[i]=hexdigits[b&15];b>>=4;}
+lua_pushlstring(L,buf,(size_t)n);
+return 1;
+}
+static const struct luaL_Reg bitlib[]={
+{"tobit",tobit},
+{"bnot",bnot},
+{"band",band},
+{"bor",bor},
+{"bxor",bxor},
+{"lshift",lshift},
+{"rshift",rshift},
+{"arshift",arshift},
+{"rol",rol},
+{"ror",ror},
+{"bswap",bswap},
+{"tohex",tohex},
+{NULL,NULL}
+};
+int main(int argc,char**argv){
+lua_State*L=luaL_newstate();
+int i;
+luaL_openlibs(L);
+luaL_register(L,"bit",bitlib);
+if(argc<2)return sizeof(void*);
+lua_createtable(L,0,1);
+lua_pushstring(L,argv[1]);
+lua_rawseti(L,-2,0);
+lua_setglobal(L,"arg");
+if(luaL_loadfile(L,argv[1]))
+goto err;
+for(i=2;i<argc;i++)
+lua_pushstring(L,argv[i]);
+if(lua_pcall(L,argc-2,0,0)){
+err:
+fprintf(stderr,"Error: %s\n",lua_tostring(L,-1));
+return 1;
+}
+lua_close(L);
+return 0;
+}
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/jit/.gitignore b/src/3rdparty/LuaJIT-2.0.5/src/jit/.gitignore
new file mode 100644
index 0000000..500e285
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/jit/.gitignore
@@ -0,0 +1 @@
+vmdef.lua
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/jit/bc.lua b/src/3rdparty/LuaJIT-2.0.5/src/jit/bc.lua
new file mode 100644
index 0000000..a2f84aa
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/jit/bc.lua
@@ -0,0 +1,191 @@
+----------------------------------------------------------------------------
+-- LuaJIT bytecode listing module.
+--
+-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+-- Released under the MIT license. See Copyright Notice in luajit.h
+----------------------------------------------------------------------------
+--
+-- This module lists the bytecode of a Lua function. If it's loaded by -jbc
+-- it hooks into the parser and lists all functions of a chunk as they
+-- are parsed.
+--
+-- Example usage:
+--
+-- luajit -jbc -e 'local x=0; for i=1,1e6 do x=x+i end; print(x)'
+-- luajit -jbc=- foo.lua
+-- luajit -jbc=foo.list foo.lua
+--
+-- Default output is to stderr. To redirect the output to a file, pass a
+-- filename as an argument (use '-' for stdout) or set the environment
+-- variable LUAJIT_LISTFILE. The file is overwritten every time the module
+-- is started.
+--
+-- This module can also be used programmatically:
+--
+-- local bc = require("jit.bc")
+--
+-- local function foo() print("hello") end
+--
+-- bc.dump(foo) --> -- BYTECODE -- [...]
+-- print(bc.line(foo, 2)) --> 0002 KSTR 1 1 ; "hello"
+--
+-- local out = {
+-- -- Do something with each line:
+-- write = function(t, ...) io.write(...) end,
+-- close = function(t) end,
+-- flush = function(t) end,
+-- }
+-- bc.dump(foo, out)
+--
+------------------------------------------------------------------------------
+
+-- Cache some library functions and objects.
+local jit = require("jit")
+assert(jit.version_num == 20005, "LuaJIT core/library version mismatch")
+local jutil = require("jit.util")
+local vmdef = require("jit.vmdef")
+local bit = require("bit")
+local sub, gsub, format = string.sub, string.gsub, string.format
+local byte, band, shr = string.byte, bit.band, bit.rshift
+local funcinfo, funcbc, funck = jutil.funcinfo, jutil.funcbc, jutil.funck
+local funcuvname = jutil.funcuvname
+local bcnames = vmdef.bcnames
+local stdout, stderr = io.stdout, io.stderr
+
+------------------------------------------------------------------------------
+
+local function ctlsub(c)
+ if c == "\n" then return "\\n"
+ elseif c == "\r" then return "\\r"
+ elseif c == "\t" then return "\\t"
+ else return format("\\%03d", byte(c))
+ end
+end
+
+-- Return one bytecode line.
+local function bcline(func, pc, prefix)
+ local ins, m = funcbc(func, pc)
+ if not ins then return end
+ local ma, mb, mc = band(m, 7), band(m, 15*8), band(m, 15*128)
+ local a = band(shr(ins, 8), 0xff)
+ local oidx = 6*band(ins, 0xff)
+ local op = sub(bcnames, oidx+1, oidx+6)
+ local s = format("%04d %s %-6s %3s ",
+ pc, prefix or " ", op, ma == 0 and "" or a)
+ local d = shr(ins, 16)
+ if mc == 13*128 then -- BCMjump
+ return format("%s=> %04d\n", s, pc+d-0x7fff)
+ end
+ if mb ~= 0 then
+ d = band(d, 0xff)
+ elseif mc == 0 then
+ return s.."\n"
+ end
+ local kc
+ if mc == 10*128 then -- BCMstr
+ kc = funck(func, -d-1)
+ kc = format(#kc > 40 and '"%.40s"~' or '"%s"', gsub(kc, "%c", ctlsub))
+ elseif mc == 9*128 then -- BCMnum
+ kc = funck(func, d)
+ if op == "TSETM " then kc = kc - 2^52 end
+ elseif mc == 12*128 then -- BCMfunc
+ local fi = funcinfo(funck(func, -d-1))
+ if fi.ffid then
+ kc = vmdef.ffnames[fi.ffid]
+ else
+ kc = fi.loc
+ end
+ elseif mc == 5*128 then -- BCMuv
+ kc = funcuvname(func, d)
+ end
+ if ma == 5 then -- BCMuv
+ local ka = funcuvname(func, a)
+ if kc then kc = ka.." ; "..kc else kc = ka end
+ end
+ if mb ~= 0 then
+ local b = shr(ins, 24)
+ if kc then return format("%s%3d %3d ; %s\n", s, b, d, kc) end
+ return format("%s%3d %3d\n", s, b, d)
+ end
+ if kc then return format("%s%3d ; %s\n", s, d, kc) end
+ if mc == 7*128 and d > 32767 then d = d - 65536 end -- BCMlits
+ return format("%s%3d\n", s, d)
+end
+
+-- Collect branch targets of a function.
+local function bctargets(func)
+ local target = {}
+ for pc=1,1000000000 do
+ local ins, m = funcbc(func, pc)
+ if not ins then break end
+ if band(m, 15*128) == 13*128 then target[pc+shr(ins, 16)-0x7fff] = true end
+ end
+ return target
+end
+
+-- Dump bytecode instructions of a function.
+local function bcdump(func, out, all)
+ if not out then out = stdout end
+ local fi = funcinfo(func)
+ if all and fi.children then
+ for n=-1,-1000000000,-1 do
+ local k = funck(func, n)
+ if not k then break end
+ if type(k) == "proto" then bcdump(k, out, true) end
+ end
+ end
+ out:write(format("-- BYTECODE -- %s-%d\n", fi.loc, fi.lastlinedefined))
+ local target = bctargets(func)
+ for pc=1,1000000000 do
+ local s = bcline(func, pc, target[pc] and "=>")
+ if not s then break end
+ out:write(s)
+ end
+ out:write("\n")
+ out:flush()
+end
+
+------------------------------------------------------------------------------
+
+-- Active flag and output file handle.
+local active, out
+
+-- List handler.
+local function h_list(func)
+ return bcdump(func, out)
+end
+
+-- Detach list handler.
+local function bclistoff()
+ if active then
+ active = false
+ jit.attach(h_list)
+ if out and out ~= stdout and out ~= stderr then out:close() end
+ out = nil
+ end
+end
+
+-- Open the output file and attach list handler.
+local function bcliston(outfile)
+ if active then bclistoff() end
+ if not outfile then outfile = os.getenv("LUAJIT_LISTFILE") end
+ if outfile then
+ out = outfile == "-" and stdout or assert(io.open(outfile, "w"))
+ else
+ out = stderr
+ end
+ jit.attach(h_list, "bc")
+ active = true
+end
+
+-- Public module functions.
+module(...)
+
+line = bcline
+dump = bcdump
+targets = bctargets
+
+on = bcliston
+off = bclistoff
+start = bcliston -- For -j command line option.
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/jit/bcsave.lua b/src/3rdparty/LuaJIT-2.0.5/src/jit/bcsave.lua
new file mode 100644
index 0000000..c94064e
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/jit/bcsave.lua
@@ -0,0 +1,659 @@
+----------------------------------------------------------------------------
+-- LuaJIT module to save/list bytecode.
+--
+-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+-- Released under the MIT license. See Copyright Notice in luajit.h
+----------------------------------------------------------------------------
+--
+-- This module saves or lists the bytecode for an input file.
+-- It's run by the -b command line option.
+--
+------------------------------------------------------------------------------
+
+local jit = require("jit")
+assert(jit.version_num == 20005, "LuaJIT core/library version mismatch")
+local bit = require("bit")
+
+-- Symbol name prefix for LuaJIT bytecode.
+local LJBC_PREFIX = "luaJIT_BC_"
+
+------------------------------------------------------------------------------
+
+local function usage()
+ io.stderr:write[[
+Save LuaJIT bytecode: luajit -b[options] input output
+ -l Only list bytecode.
+ -s Strip debug info (default).
+ -g Keep debug info.
+ -n name Set module name (default: auto-detect from input name).
+ -t type Set output file type (default: auto-detect from output name).
+ -a arch Override architecture for object files (default: native).
+ -o os Override OS for object files (default: native).
+ -e chunk Use chunk string as input.
+ -- Stop handling options.
+ - Use stdin as input and/or stdout as output.
+
+File types: c h obj o raw (default)
+]]
+ os.exit(1)
+end
+
+local function check(ok, ...)
+ if ok then return ok, ... end
+ io.stderr:write("luajit: ", ...)
+ io.stderr:write("\n")
+ os.exit(1)
+end
+
+local function readfile(input)
+ if type(input) == "function" then return input end
+ if input == "-" then input = nil end
+ return check(loadfile(input))
+end
+
+local function savefile(name, mode)
+ if name == "-" then return io.stdout end
+ return check(io.open(name, mode))
+end
+
+------------------------------------------------------------------------------
+
+local map_type = {
+ raw = "raw", c = "c", h = "h", o = "obj", obj = "obj",
+}
+
+local map_arch = {
+ x86 = true, x64 = true, arm = true, ppc = true, ppcspe = true,
+ mips = true, mipsel = true,
+}
+
+local map_os = {
+ linux = true, windows = true, osx = true, freebsd = true, netbsd = true,
+ openbsd = true, dragonfly = true, solaris = true,
+}
+
+local function checkarg(str, map, err)
+ str = string.lower(str)
+ local s = check(map[str], "unknown ", err)
+ return s == true and str or s
+end
+
+local function detecttype(str)
+ local ext = string.match(string.lower(str), "%.(%a+)$")
+ return map_type[ext] or "raw"
+end
+
+local function checkmodname(str)
+ check(string.match(str, "^[%w_.%-]+$"), "bad module name")
+ return string.gsub(str, "[%.%-]", "_")
+end
+
+local function detectmodname(str)
+ if type(str) == "string" then
+ local tail = string.match(str, "[^/\\]+$")
+ if tail then str = tail end
+ local head = string.match(str, "^(.*)%.[^.]*$")
+ if head then str = head end
+ str = string.match(str, "^[%w_.%-]+")
+ else
+ str = nil
+ end
+ check(str, "cannot derive module name, use -n name")
+ return string.gsub(str, "[%.%-]", "_")
+end
+
+------------------------------------------------------------------------------
+
+local function bcsave_tail(fp, output, s)
+ local ok, err = fp:write(s)
+ if ok and output ~= "-" then ok, err = fp:close() end
+ check(ok, "cannot write ", output, ": ", err)
+end
+
+local function bcsave_raw(output, s)
+ local fp = savefile(output, "wb")
+ bcsave_tail(fp, output, s)
+end
+
+local function bcsave_c(ctx, output, s)
+ local fp = savefile(output, "w")
+ if ctx.type == "c" then
+ fp:write(string.format([[
+#ifdef _cplusplus
+extern "C"
+#endif
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+const char %s%s[] = {
+]], LJBC_PREFIX, ctx.modname))
+ else
+ fp:write(string.format([[
+#define %s%s_SIZE %d
+static const char %s%s[] = {
+]], LJBC_PREFIX, ctx.modname, #s, LJBC_PREFIX, ctx.modname))
+ end
+ local t, n, m = {}, 0, 0
+ for i=1,#s do
+ local b = tostring(string.byte(s, i))
+ m = m + #b + 1
+ if m > 78 then
+ fp:write(table.concat(t, ",", 1, n), ",\n")
+ n, m = 0, #b + 1
+ end
+ n = n + 1
+ t[n] = b
+ end
+ bcsave_tail(fp, output, table.concat(t, ",", 1, n).."\n};\n")
+end
+
+local function bcsave_elfobj(ctx, output, s, ffi)
+ ffi.cdef[[
+typedef struct {
+ uint8_t emagic[4], eclass, eendian, eversion, eosabi, eabiversion, epad[7];
+ uint16_t type, machine;
+ uint32_t version;
+ uint32_t entry, phofs, shofs;
+ uint32_t flags;
+ uint16_t ehsize, phentsize, phnum, shentsize, shnum, shstridx;
+} ELF32header;
+typedef struct {
+ uint8_t emagic[4], eclass, eendian, eversion, eosabi, eabiversion, epad[7];
+ uint16_t type, machine;
+ uint32_t version;
+ uint64_t entry, phofs, shofs;
+ uint32_t flags;
+ uint16_t ehsize, phentsize, phnum, shentsize, shnum, shstridx;
+} ELF64header;
+typedef struct {
+ uint32_t name, type, flags, addr, ofs, size, link, info, align, entsize;
+} ELF32sectheader;
+typedef struct {
+ uint32_t name, type;
+ uint64_t flags, addr, ofs, size;
+ uint32_t link, info;
+ uint64_t align, entsize;
+} ELF64sectheader;
+typedef struct {
+ uint32_t name, value, size;
+ uint8_t info, other;
+ uint16_t sectidx;
+} ELF32symbol;
+typedef struct {
+ uint32_t name;
+ uint8_t info, other;
+ uint16_t sectidx;
+ uint64_t value, size;
+} ELF64symbol;
+typedef struct {
+ ELF32header hdr;
+ ELF32sectheader sect[6];
+ ELF32symbol sym[2];
+ uint8_t space[4096];
+} ELF32obj;
+typedef struct {
+ ELF64header hdr;
+ ELF64sectheader sect[6];
+ ELF64symbol sym[2];
+ uint8_t space[4096];
+} ELF64obj;
+]]
+ local symname = LJBC_PREFIX..ctx.modname
+ local is64, isbe = false, false
+ if ctx.arch == "x64" then
+ is64 = true
+ elseif ctx.arch == "ppc" or ctx.arch == "ppcspe" or ctx.arch == "mips" then
+ isbe = true
+ end
+
+ -- Handle different host/target endianess.
+ local function f32(x) return x end
+ local f16, fofs = f32, f32
+ if ffi.abi("be") ~= isbe then
+ f32 = bit.bswap
+ function f16(x) return bit.rshift(bit.bswap(x), 16) end
+ if is64 then
+ local two32 = ffi.cast("int64_t", 2^32)
+ function fofs(x) return bit.bswap(x)*two32 end
+ else
+ fofs = f32
+ end
+ end
+
+ -- Create ELF object and fill in header.
+ local o = ffi.new(is64 and "ELF64obj" or "ELF32obj")
+ local hdr = o.hdr
+ if ctx.os == "bsd" or ctx.os == "other" then -- Determine native hdr.eosabi.
+ local bf = assert(io.open("/bin/ls", "rb"))
+ local bs = bf:read(9)
+ bf:close()
+ ffi.copy(o, bs, 9)
+ check(hdr.emagic[0] == 127, "no support for writing native object files")
+ else
+ hdr.emagic = "\127ELF"
+ hdr.eosabi = ({ freebsd=9, netbsd=2, openbsd=12, solaris=6 })[ctx.os] or 0
+ end
+ hdr.eclass = is64 and 2 or 1
+ hdr.eendian = isbe and 2 or 1
+ hdr.eversion = 1
+ hdr.type = f16(1)
+ hdr.machine = f16(({ x86=3, x64=62, arm=40, ppc=20, ppcspe=20, mips=8, mipsel=8 })[ctx.arch])
+ if ctx.arch == "mips" or ctx.arch == "mipsel" then
+ hdr.flags = f32(0x50001006)
+ end
+ hdr.version = f32(1)
+ hdr.shofs = fofs(ffi.offsetof(o, "sect"))
+ hdr.ehsize = f16(ffi.sizeof(hdr))
+ hdr.shentsize = f16(ffi.sizeof(o.sect[0]))
+ hdr.shnum = f16(6)
+ hdr.shstridx = f16(2)
+
+ -- Fill in sections and symbols.
+ local sofs, ofs = ffi.offsetof(o, "space"), 1
+ for i,name in ipairs{
+ ".symtab", ".shstrtab", ".strtab", ".rodata", ".note.GNU-stack",
+ } do
+ local sect = o.sect[i]
+ sect.align = fofs(1)
+ sect.name = f32(ofs)
+ ffi.copy(o.space+ofs, name)
+ ofs = ofs + #name+1
+ end
+ o.sect[1].type = f32(2) -- .symtab
+ o.sect[1].link = f32(3)
+ o.sect[1].info = f32(1)
+ o.sect[1].align = fofs(8)
+ o.sect[1].ofs = fofs(ffi.offsetof(o, "sym"))
+ o.sect[1].entsize = fofs(ffi.sizeof(o.sym[0]))
+ o.sect[1].size = fofs(ffi.sizeof(o.sym))
+ o.sym[1].name = f32(1)
+ o.sym[1].sectidx = f16(4)
+ o.sym[1].size = fofs(#s)
+ o.sym[1].info = 17
+ o.sect[2].type = f32(3) -- .shstrtab
+ o.sect[2].ofs = fofs(sofs)
+ o.sect[2].size = fofs(ofs)
+ o.sect[3].type = f32(3) -- .strtab
+ o.sect[3].ofs = fofs(sofs + ofs)
+ o.sect[3].size = fofs(#symname+2)
+ ffi.copy(o.space+ofs+1, symname)
+ ofs = ofs + #symname + 2
+ o.sect[4].type = f32(1) -- .rodata
+ o.sect[4].flags = fofs(2)
+ o.sect[4].ofs = fofs(sofs + ofs)
+ o.sect[4].size = fofs(#s)
+ o.sect[5].type = f32(1) -- .note.GNU-stack
+ o.sect[5].ofs = fofs(sofs + ofs + #s)
+
+ -- Write ELF object file.
+ local fp = savefile(output, "wb")
+ fp:write(ffi.string(o, ffi.sizeof(o)-4096+ofs))
+ bcsave_tail(fp, output, s)
+end
+
+local function bcsave_peobj(ctx, output, s, ffi)
+ ffi.cdef[[
+typedef struct {
+ uint16_t arch, nsects;
+ uint32_t time, symtabofs, nsyms;
+ uint16_t opthdrsz, flags;
+} PEheader;
+typedef struct {
+ char name[8];
+ uint32_t vsize, vaddr, size, ofs, relocofs, lineofs;
+ uint16_t nreloc, nline;
+ uint32_t flags;
+} PEsection;
+typedef struct __attribute((packed)) {
+ union {
+ char name[8];
+ uint32_t nameref[2];
+ };
+ uint32_t value;
+ int16_t sect;
+ uint16_t type;
+ uint8_t scl, naux;
+} PEsym;
+typedef struct __attribute((packed)) {
+ uint32_t size;
+ uint16_t nreloc, nline;
+ uint32_t cksum;
+ uint16_t assoc;
+ uint8_t comdatsel, unused[3];
+} PEsymaux;
+typedef struct {
+ PEheader hdr;
+ PEsection sect[2];
+ // Must be an even number of symbol structs.
+ PEsym sym0;
+ PEsymaux sym0aux;
+ PEsym sym1;
+ PEsymaux sym1aux;
+ PEsym sym2;
+ PEsym sym3;
+ uint32_t strtabsize;
+ uint8_t space[4096];
+} PEobj;
+]]
+ local symname = LJBC_PREFIX..ctx.modname
+ local is64 = false
+ if ctx.arch == "x86" then
+ symname = "_"..symname
+ elseif ctx.arch == "x64" then
+ is64 = true
+ end
+ local symexport = " /EXPORT:"..symname..",DATA "
+
+ -- The file format is always little-endian. Swap if the host is big-endian.
+ local function f32(x) return x end
+ local f16 = f32
+ if ffi.abi("be") then
+ f32 = bit.bswap
+ function f16(x) return bit.rshift(bit.bswap(x), 16) end
+ end
+
+ -- Create PE object and fill in header.
+ local o = ffi.new("PEobj")
+ local hdr = o.hdr
+ hdr.arch = f16(({ x86=0x14c, x64=0x8664, arm=0x1c0, ppc=0x1f2, mips=0x366, mipsel=0x366 })[ctx.arch])
+ hdr.nsects = f16(2)
+ hdr.symtabofs = f32(ffi.offsetof(o, "sym0"))
+ hdr.nsyms = f32(6)
+
+ -- Fill in sections and symbols.
+ o.sect[0].name = ".drectve"
+ o.sect[0].size = f32(#symexport)
+ o.sect[0].flags = f32(0x00100a00)
+ o.sym0.sect = f16(1)
+ o.sym0.scl = 3
+ o.sym0.name = ".drectve"
+ o.sym0.naux = 1
+ o.sym0aux.size = f32(#symexport)
+ o.sect[1].name = ".rdata"
+ o.sect[1].size = f32(#s)
+ o.sect[1].flags = f32(0x40300040)
+ o.sym1.sect = f16(2)
+ o.sym1.scl = 3
+ o.sym1.name = ".rdata"
+ o.sym1.naux = 1
+ o.sym1aux.size = f32(#s)
+ o.sym2.sect = f16(2)
+ o.sym2.scl = 2
+ o.sym2.nameref[1] = f32(4)
+ o.sym3.sect = f16(-1)
+ o.sym3.scl = 2
+ o.sym3.value = f32(1)
+ o.sym3.name = "@feat.00" -- Mark as SafeSEH compliant.
+ ffi.copy(o.space, symname)
+ local ofs = #symname + 1
+ o.strtabsize = f32(ofs + 4)
+ o.sect[0].ofs = f32(ffi.offsetof(o, "space") + ofs)
+ ffi.copy(o.space + ofs, symexport)
+ ofs = ofs + #symexport
+ o.sect[1].ofs = f32(ffi.offsetof(o, "space") + ofs)
+
+ -- Write PE object file.
+ local fp = savefile(output, "wb")
+ fp:write(ffi.string(o, ffi.sizeof(o)-4096+ofs))
+ bcsave_tail(fp, output, s)
+end
+
+local function bcsave_machobj(ctx, output, s, ffi)
+ ffi.cdef[[
+typedef struct
+{
+ uint32_t magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags;
+} mach_header;
+typedef struct
+{
+ mach_header; uint32_t reserved;
+} mach_header_64;
+typedef struct {
+ uint32_t cmd, cmdsize;
+ char segname[16];
+ uint32_t vmaddr, vmsize, fileoff, filesize;
+ uint32_t maxprot, initprot, nsects, flags;
+} mach_segment_command;
+typedef struct {
+ uint32_t cmd, cmdsize;
+ char segname[16];
+ uint64_t vmaddr, vmsize, fileoff, filesize;
+ uint32_t maxprot, initprot, nsects, flags;
+} mach_segment_command_64;
+typedef struct {
+ char sectname[16], segname[16];
+ uint32_t addr, size;
+ uint32_t offset, align, reloff, nreloc, flags;
+ uint32_t reserved1, reserved2;
+} mach_section;
+typedef struct {
+ char sectname[16], segname[16];
+ uint64_t addr, size;
+ uint32_t offset, align, reloff, nreloc, flags;
+ uint32_t reserved1, reserved2, reserved3;
+} mach_section_64;
+typedef struct {
+ uint32_t cmd, cmdsize, symoff, nsyms, stroff, strsize;
+} mach_symtab_command;
+typedef struct {
+ int32_t strx;
+ uint8_t type, sect;
+ int16_t desc;
+ uint32_t value;
+} mach_nlist;
+typedef struct {
+ uint32_t strx;
+ uint8_t type, sect;
+ uint16_t desc;
+ uint64_t value;
+} mach_nlist_64;
+typedef struct
+{
+ uint32_t magic, nfat_arch;
+} mach_fat_header;
+typedef struct
+{
+ uint32_t cputype, cpusubtype, offset, size, align;
+} mach_fat_arch;
+typedef struct {
+ struct {
+ mach_header hdr;
+ mach_segment_command seg;
+ mach_section sec;
+ mach_symtab_command sym;
+ } arch[1];
+ mach_nlist sym_entry;
+ uint8_t space[4096];
+} mach_obj;
+typedef struct {
+ struct {
+ mach_header_64 hdr;
+ mach_segment_command_64 seg;
+ mach_section_64 sec;
+ mach_symtab_command sym;
+ } arch[1];
+ mach_nlist_64 sym_entry;
+ uint8_t space[4096];
+} mach_obj_64;
+typedef struct {
+ mach_fat_header fat;
+ mach_fat_arch fat_arch[4];
+ struct {
+ mach_header hdr;
+ mach_segment_command seg;
+ mach_section sec;
+ mach_symtab_command sym;
+ } arch[4];
+ mach_nlist sym_entry;
+ uint8_t space[4096];
+} mach_fat_obj;
+]]
+ local symname = '_'..LJBC_PREFIX..ctx.modname
+ local isfat, is64, align, mobj = false, false, 4, "mach_obj"
+ if ctx.arch == "x64" then
+ is64, align, mobj = true, 8, "mach_obj_64"
+ elseif ctx.arch == "arm" then
+ isfat, mobj = true, "mach_fat_obj"
+ else
+ check(ctx.arch == "x86", "unsupported architecture for OSX")
+ end
+ local function aligned(v, a) return bit.band(v+a-1, -a) end
+ local be32 = bit.bswap -- Mach-O FAT is BE, supported archs are LE.
+
+ -- Create Mach-O object and fill in header.
+ local o = ffi.new(mobj)
+ local mach_size = aligned(ffi.offsetof(o, "space")+#symname+2, align)
+ local cputype = ({ x86={7}, x64={0x01000007}, arm={7,12,12,12} })[ctx.arch]
+ local cpusubtype = ({ x86={3}, x64={3}, arm={3,6,9,11} })[ctx.arch]
+ if isfat then
+ o.fat.magic = be32(0xcafebabe)
+ o.fat.nfat_arch = be32(#cpusubtype)
+ end
+
+ -- Fill in sections and symbols.
+ for i=0,#cpusubtype-1 do
+ local ofs = 0
+ if isfat then
+ local a = o.fat_arch[i]
+ a.cputype = be32(cputype[i+1])
+ a.cpusubtype = be32(cpusubtype[i+1])
+ -- Subsequent slices overlap each other to share data.
+ ofs = ffi.offsetof(o, "arch") + i*ffi.sizeof(o.arch[0])
+ a.offset = be32(ofs)
+ a.size = be32(mach_size-ofs+#s)
+ end
+ local a = o.arch[i]
+ a.hdr.magic = is64 and 0xfeedfacf or 0xfeedface
+ a.hdr.cputype = cputype[i+1]
+ a.hdr.cpusubtype = cpusubtype[i+1]
+ a.hdr.filetype = 1
+ a.hdr.ncmds = 2
+ a.hdr.sizeofcmds = ffi.sizeof(a.seg)+ffi.sizeof(a.sec)+ffi.sizeof(a.sym)
+ a.seg.cmd = is64 and 0x19 or 0x1
+ a.seg.cmdsize = ffi.sizeof(a.seg)+ffi.sizeof(a.sec)
+ a.seg.vmsize = #s
+ a.seg.fileoff = mach_size-ofs
+ a.seg.filesize = #s
+ a.seg.maxprot = 1
+ a.seg.initprot = 1
+ a.seg.nsects = 1
+ ffi.copy(a.sec.sectname, "__data")
+ ffi.copy(a.sec.segname, "__DATA")
+ a.sec.size = #s
+ a.sec.offset = mach_size-ofs
+ a.sym.cmd = 2
+ a.sym.cmdsize = ffi.sizeof(a.sym)
+ a.sym.symoff = ffi.offsetof(o, "sym_entry")-ofs
+ a.sym.nsyms = 1
+ a.sym.stroff = ffi.offsetof(o, "sym_entry")+ffi.sizeof(o.sym_entry)-ofs
+ a.sym.strsize = aligned(#symname+2, align)
+ end
+ o.sym_entry.type = 0xf
+ o.sym_entry.sect = 1
+ o.sym_entry.strx = 1
+ ffi.copy(o.space+1, symname)
+
+ -- Write Macho-O object file.
+ local fp = savefile(output, "wb")
+ fp:write(ffi.string(o, mach_size))
+ bcsave_tail(fp, output, s)
+end
+
+local function bcsave_obj(ctx, output, s)
+ local ok, ffi = pcall(require, "ffi")
+ check(ok, "FFI library required to write this file type")
+ if ctx.os == "windows" then
+ return bcsave_peobj(ctx, output, s, ffi)
+ elseif ctx.os == "osx" then
+ return bcsave_machobj(ctx, output, s, ffi)
+ else
+ return bcsave_elfobj(ctx, output, s, ffi)
+ end
+end
+
+------------------------------------------------------------------------------
+
+local function bclist(input, output)
+ local f = readfile(input)
+ require("jit.bc").dump(f, savefile(output, "w"), true)
+end
+
+local function bcsave(ctx, input, output)
+ local f = readfile(input)
+ local s = string.dump(f, ctx.strip)
+ local t = ctx.type
+ if not t then
+ t = detecttype(output)
+ ctx.type = t
+ end
+ if t == "raw" then
+ bcsave_raw(output, s)
+ else
+ if not ctx.modname then ctx.modname = detectmodname(input) end
+ if t == "obj" then
+ bcsave_obj(ctx, output, s)
+ else
+ bcsave_c(ctx, output, s)
+ end
+ end
+end
+
+local function docmd(...)
+ local arg = {...}
+ local n = 1
+ local list = false
+ local ctx = {
+ strip = true, arch = jit.arch, os = string.lower(jit.os),
+ type = false, modname = false,
+ }
+ while n <= #arg do
+ local a = arg[n]
+ if type(a) == "string" and string.sub(a, 1, 1) == "-" and a ~= "-" then
+ table.remove(arg, n)
+ if a == "--" then break end
+ for m=2,#a do
+ local opt = string.sub(a, m, m)
+ if opt == "l" then
+ list = true
+ elseif opt == "s" then
+ ctx.strip = true
+ elseif opt == "g" then
+ ctx.strip = false
+ else
+ if arg[n] == nil or m ~= #a then usage() end
+ if opt == "e" then
+ if n ~= 1 then usage() end
+ arg[1] = check(loadstring(arg[1]))
+ elseif opt == "n" then
+ ctx.modname = checkmodname(table.remove(arg, n))
+ elseif opt == "t" then
+ ctx.type = checkarg(table.remove(arg, n), map_type, "file type")
+ elseif opt == "a" then
+ ctx.arch = checkarg(table.remove(arg, n), map_arch, "architecture")
+ elseif opt == "o" then
+ ctx.os = checkarg(table.remove(arg, n), map_os, "OS name")
+ else
+ usage()
+ end
+ end
+ end
+ else
+ n = n + 1
+ end
+ end
+ if list then
+ if #arg == 0 or #arg > 2 then usage() end
+ bclist(arg[1], arg[2] or "-")
+ else
+ if #arg ~= 2 then usage() end
+ bcsave(ctx, arg[1], arg[2])
+ end
+end
+
+------------------------------------------------------------------------------
+
+-- Public module functions.
+module(...)
+
+start = docmd -- Process -b command line option.
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/jit/dis_arm.lua b/src/3rdparty/LuaJIT-2.0.5/src/jit/dis_arm.lua
new file mode 100644
index 0000000..91ebb7d
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/jit/dis_arm.lua
@@ -0,0 +1,689 @@
+----------------------------------------------------------------------------
+-- LuaJIT ARM disassembler module.
+--
+-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+-- Released under the MIT license. See Copyright Notice in luajit.h
+----------------------------------------------------------------------------
+-- This is a helper module used by the LuaJIT machine code dumper module.
+--
+-- It disassembles most user-mode ARMv7 instructions
+-- NYI: Advanced SIMD and VFP instructions.
+------------------------------------------------------------------------------
+
+local type = type
+local sub, byte, format = string.sub, string.byte, string.format
+local match, gmatch = string.match, string.gmatch
+local concat = table.concat
+local bit = require("bit")
+local band, bor, ror, tohex = bit.band, bit.bor, bit.ror, bit.tohex
+local lshift, rshift, arshift = bit.lshift, bit.rshift, bit.arshift
+
+------------------------------------------------------------------------------
+-- Opcode maps
+------------------------------------------------------------------------------
+
+local map_loadc = {
+ shift = 8, mask = 15,
+ [10] = {
+ shift = 20, mask = 1,
+ [0] = {
+ shift = 23, mask = 3,
+ [0] = "vmovFmDN", "vstmFNdr",
+ _ = {
+ shift = 21, mask = 1,
+ [0] = "vstrFdl",
+ { shift = 16, mask = 15, [13] = "vpushFdr", _ = "vstmdbFNdr", }
+ },
+ },
+ {
+ shift = 23, mask = 3,
+ [0] = "vmovFDNm",
+ { shift = 16, mask = 15, [13] = "vpopFdr", _ = "vldmFNdr", },
+ _ = {
+ shift = 21, mask = 1,
+ [0] = "vldrFdl", "vldmdbFNdr",
+ },
+ },
+ },
+ [11] = {
+ shift = 20, mask = 1,
+ [0] = {
+ shift = 23, mask = 3,
+ [0] = "vmovGmDN", "vstmGNdr",
+ _ = {
+ shift = 21, mask = 1,
+ [0] = "vstrGdl",
+ { shift = 16, mask = 15, [13] = "vpushGdr", _ = "vstmdbGNdr", }
+ },
+ },
+ {
+ shift = 23, mask = 3,
+ [0] = "vmovGDNm",
+ { shift = 16, mask = 15, [13] = "vpopGdr", _ = "vldmGNdr", },
+ _ = {
+ shift = 21, mask = 1,
+ [0] = "vldrGdl", "vldmdbGNdr",
+ },
+ },
+ },
+ _ = {
+ shift = 0, mask = 0 -- NYI ldc, mcrr, mrrc.
+ },
+}
+
+local map_vfps = {
+ shift = 6, mask = 0x2c001,
+ [0] = "vmlaF.dnm", "vmlsF.dnm",
+ [0x04000] = "vnmlsF.dnm", [0x04001] = "vnmlaF.dnm",
+ [0x08000] = "vmulF.dnm", [0x08001] = "vnmulF.dnm",
+ [0x0c000] = "vaddF.dnm", [0x0c001] = "vsubF.dnm",
+ [0x20000] = "vdivF.dnm",
+ [0x24000] = "vfnmsF.dnm", [0x24001] = "vfnmaF.dnm",
+ [0x28000] = "vfmaF.dnm", [0x28001] = "vfmsF.dnm",
+ [0x2c000] = "vmovF.dY",
+ [0x2c001] = {
+ shift = 7, mask = 0x1e01,
+ [0] = "vmovF.dm", "vabsF.dm",
+ [0x0200] = "vnegF.dm", [0x0201] = "vsqrtF.dm",
+ [0x0800] = "vcmpF.dm", [0x0801] = "vcmpeF.dm",
+ [0x0a00] = "vcmpzF.d", [0x0a01] = "vcmpzeF.d",
+ [0x0e01] = "vcvtG.dF.m",
+ [0x1000] = "vcvt.f32.u32Fdm", [0x1001] = "vcvt.f32.s32Fdm",
+ [0x1800] = "vcvtr.u32F.dm", [0x1801] = "vcvt.u32F.dm",
+ [0x1a00] = "vcvtr.s32F.dm", [0x1a01] = "vcvt.s32F.dm",
+ },
+}
+
+local map_vfpd = {
+ shift = 6, mask = 0x2c001,
+ [0] = "vmlaG.dnm", "vmlsG.dnm",
+ [0x04000] = "vnmlsG.dnm", [0x04001] = "vnmlaG.dnm",
+ [0x08000] = "vmulG.dnm", [0x08001] = "vnmulG.dnm",
+ [0x0c000] = "vaddG.dnm", [0x0c001] = "vsubG.dnm",
+ [0x20000] = "vdivG.dnm",
+ [0x24000] = "vfnmsG.dnm", [0x24001] = "vfnmaG.dnm",
+ [0x28000] = "vfmaG.dnm", [0x28001] = "vfmsG.dnm",
+ [0x2c000] = "vmovG.dY",
+ [0x2c001] = {
+ shift = 7, mask = 0x1e01,
+ [0] = "vmovG.dm", "vabsG.dm",
+ [0x0200] = "vnegG.dm", [0x0201] = "vsqrtG.dm",
+ [0x0800] = "vcmpG.dm", [0x0801] = "vcmpeG.dm",
+ [0x0a00] = "vcmpzG.d", [0x0a01] = "vcmpzeG.d",
+ [0x0e01] = "vcvtF.dG.m",
+ [0x1000] = "vcvt.f64.u32GdFm", [0x1001] = "vcvt.f64.s32GdFm",
+ [0x1800] = "vcvtr.u32FdG.m", [0x1801] = "vcvt.u32FdG.m",
+ [0x1a00] = "vcvtr.s32FdG.m", [0x1a01] = "vcvt.s32FdG.m",
+ },
+}
+
+local map_datac = {
+ shift = 24, mask = 1,
+ [0] = {
+ shift = 4, mask = 1,
+ [0] = {
+ shift = 8, mask = 15,
+ [10] = map_vfps,
+ [11] = map_vfpd,
+ -- NYI cdp, mcr, mrc.
+ },
+ {
+ shift = 8, mask = 15,
+ [10] = {
+ shift = 20, mask = 15,
+ [0] = "vmovFnD", "vmovFDn",
+ [14] = "vmsrD",
+ [15] = { shift = 12, mask = 15, [15] = "vmrs", _ = "vmrsD", },
+ },
+ },
+ },
+ "svcT",
+}
+
+local map_loadcu = {
+ shift = 0, mask = 0, -- NYI unconditional CP load/store.
+}
+
+local map_datacu = {
+ shift = 0, mask = 0, -- NYI unconditional CP data.
+}
+
+local map_simddata = {
+ shift = 0, mask = 0, -- NYI SIMD data.
+}
+
+local map_simdload = {
+ shift = 0, mask = 0, -- NYI SIMD load/store, preload.
+}
+
+local map_preload = {
+ shift = 0, mask = 0, -- NYI preload.
+}
+
+local map_media = {
+ shift = 20, mask = 31,
+ [0] = false,
+ { --01
+ shift = 5, mask = 7,
+ [0] = "sadd16DNM", "sasxDNM", "ssaxDNM", "ssub16DNM",
+ "sadd8DNM", false, false, "ssub8DNM",
+ },
+ { --02
+ shift = 5, mask = 7,
+ [0] = "qadd16DNM", "qasxDNM", "qsaxDNM", "qsub16DNM",
+ "qadd8DNM", false, false, "qsub8DNM",
+ },
+ { --03
+ shift = 5, mask = 7,
+ [0] = "shadd16DNM", "shasxDNM", "shsaxDNM", "shsub16DNM",
+ "shadd8DNM", false, false, "shsub8DNM",
+ },
+ false,
+ { --05
+ shift = 5, mask = 7,
+ [0] = "uadd16DNM", "uasxDNM", "usaxDNM", "usub16DNM",
+ "uadd8DNM", false, false, "usub8DNM",
+ },
+ { --06
+ shift = 5, mask = 7,
+ [0] = "uqadd16DNM", "uqasxDNM", "uqsaxDNM", "uqsub16DNM",
+ "uqadd8DNM", false, false, "uqsub8DNM",
+ },
+ { --07
+ shift = 5, mask = 7,
+ [0] = "uhadd16DNM", "uhasxDNM", "uhsaxDNM", "uhsub16DNM",
+ "uhadd8DNM", false, false, "uhsub8DNM",
+ },
+ { --08
+ shift = 5, mask = 7,
+ [0] = "pkhbtDNMU", false, "pkhtbDNMU",
+ { shift = 16, mask = 15, [15] = "sxtb16DMU", _ = "sxtab16DNMU", },
+ "pkhbtDNMU", "selDNM", "pkhtbDNMU",
+ },
+ false,
+ { --0a
+ shift = 5, mask = 7,
+ [0] = "ssatDxMu", "ssat16DxM", "ssatDxMu",
+ { shift = 16, mask = 15, [15] = "sxtbDMU", _ = "sxtabDNMU", },
+ "ssatDxMu", false, "ssatDxMu",
+ },
+ { --0b
+ shift = 5, mask = 7,
+ [0] = "ssatDxMu", "revDM", "ssatDxMu",
+ { shift = 16, mask = 15, [15] = "sxthDMU", _ = "sxtahDNMU", },
+ "ssatDxMu", "rev16DM", "ssatDxMu",
+ },
+ { --0c
+ shift = 5, mask = 7,
+ [3] = { shift = 16, mask = 15, [15] = "uxtb16DMU", _ = "uxtab16DNMU", },
+ },
+ false,
+ { --0e
+ shift = 5, mask = 7,
+ [0] = "usatDwMu", "usat16DwM", "usatDwMu",
+ { shift = 16, mask = 15, [15] = "uxtbDMU", _ = "uxtabDNMU", },
+ "usatDwMu", false, "usatDwMu",
+ },
+ { --0f
+ shift = 5, mask = 7,
+ [0] = "usatDwMu", "rbitDM", "usatDwMu",
+ { shift = 16, mask = 15, [15] = "uxthDMU", _ = "uxtahDNMU", },
+ "usatDwMu", "revshDM", "usatDwMu",
+ },
+ { --10
+ shift = 12, mask = 15,
+ [15] = {
+ shift = 5, mask = 7,
+ "smuadNMS", "smuadxNMS", "smusdNMS", "smusdxNMS",
+ },
+ _ = {
+ shift = 5, mask = 7,
+ [0] = "smladNMSD", "smladxNMSD", "smlsdNMSD", "smlsdxNMSD",
+ },
+ },
+ false, false, false,
+ { --14
+ shift = 5, mask = 7,
+ [0] = "smlaldDNMS", "smlaldxDNMS", "smlsldDNMS", "smlsldxDNMS",
+ },
+ { --15
+ shift = 5, mask = 7,
+ [0] = { shift = 12, mask = 15, [15] = "smmulNMS", _ = "smmlaNMSD", },
+ { shift = 12, mask = 15, [15] = "smmulrNMS", _ = "smmlarNMSD", },
+ false, false, false, false,
+ "smmlsNMSD", "smmlsrNMSD",
+ },
+ false, false,
+ { --18
+ shift = 5, mask = 7,
+ [0] = { shift = 12, mask = 15, [15] = "usad8NMS", _ = "usada8NMSD", },
+ },
+ false,
+ { --1a
+ shift = 5, mask = 3, [2] = "sbfxDMvw",
+ },
+ { --1b
+ shift = 5, mask = 3, [2] = "sbfxDMvw",
+ },
+ { --1c
+ shift = 5, mask = 3,
+ [0] = { shift = 0, mask = 15, [15] = "bfcDvX", _ = "bfiDMvX", },
+ },
+ { --1d
+ shift = 5, mask = 3,
+ [0] = { shift = 0, mask = 15, [15] = "bfcDvX", _ = "bfiDMvX", },
+ },
+ { --1e
+ shift = 5, mask = 3, [2] = "ubfxDMvw",
+ },
+ { --1f
+ shift = 5, mask = 3, [2] = "ubfxDMvw",
+ },
+}
+
+local map_load = {
+ shift = 21, mask = 9,
+ {
+ shift = 20, mask = 5,
+ [0] = "strtDL", "ldrtDL", [4] = "strbtDL", [5] = "ldrbtDL",
+ },
+ _ = {
+ shift = 20, mask = 5,
+ [0] = "strDL", "ldrDL", [4] = "strbDL", [5] = "ldrbDL",
+ }
+}
+
+local map_load1 = {
+ shift = 4, mask = 1,
+ [0] = map_load, map_media,
+}
+
+local map_loadm = {
+ shift = 20, mask = 1,
+ [0] = {
+ shift = 23, mask = 3,
+ [0] = "stmdaNR", "stmNR",
+ { shift = 16, mask = 63, [45] = "pushR", _ = "stmdbNR", }, "stmibNR",
+ },
+ {
+ shift = 23, mask = 3,
+ [0] = "ldmdaNR", { shift = 16, mask = 63, [61] = "popR", _ = "ldmNR", },
+ "ldmdbNR", "ldmibNR",
+ },
+}
+
+local map_data = {
+ shift = 21, mask = 15,
+ [0] = "andDNPs", "eorDNPs", "subDNPs", "rsbDNPs",
+ "addDNPs", "adcDNPs", "sbcDNPs", "rscDNPs",
+ "tstNP", "teqNP", "cmpNP", "cmnNP",
+ "orrDNPs", "movDPs", "bicDNPs", "mvnDPs",
+}
+
+local map_mul = {
+ shift = 21, mask = 7,
+ [0] = "mulNMSs", "mlaNMSDs", "umaalDNMS", "mlsDNMS",
+ "umullDNMSs", "umlalDNMSs", "smullDNMSs", "smlalDNMSs",
+}
+
+local map_sync = {
+ shift = 20, mask = 15, -- NYI: brackets around N. R(D+1) for ldrexd/strexd.
+ [0] = "swpDMN", false, false, false,
+ "swpbDMN", false, false, false,
+ "strexDMN", "ldrexDN", "strexdDN", "ldrexdDN",
+ "strexbDMN", "ldrexbDN", "strexhDN", "ldrexhDN",
+}
+
+local map_mulh = {
+ shift = 21, mask = 3,
+ [0] = { shift = 5, mask = 3,
+ [0] = "smlabbNMSD", "smlatbNMSD", "smlabtNMSD", "smlattNMSD", },
+ { shift = 5, mask = 3,
+ [0] = "smlawbNMSD", "smulwbNMS", "smlawtNMSD", "smulwtNMS", },
+ { shift = 5, mask = 3,
+ [0] = "smlalbbDNMS", "smlaltbDNMS", "smlalbtDNMS", "smlalttDNMS", },
+ { shift = 5, mask = 3,
+ [0] = "smulbbNMS", "smultbNMS", "smulbtNMS", "smulttNMS", },
+}
+
+local map_misc = {
+ shift = 4, mask = 7,
+ -- NYI: decode PSR bits of msr.
+ [0] = { shift = 21, mask = 1, [0] = "mrsD", "msrM", },
+ { shift = 21, mask = 3, "bxM", false, "clzDM", },
+ { shift = 21, mask = 3, "bxjM", },
+ { shift = 21, mask = 3, "blxM", },
+ false,
+ { shift = 21, mask = 3, [0] = "qaddDMN", "qsubDMN", "qdaddDMN", "qdsubDMN", },
+ false,
+ { shift = 21, mask = 3, "bkptK", },
+}
+
+local map_datar = {
+ shift = 4, mask = 9,
+ [9] = {
+ shift = 5, mask = 3,
+ [0] = { shift = 24, mask = 1, [0] = map_mul, map_sync, },
+ { shift = 20, mask = 1, [0] = "strhDL", "ldrhDL", },
+ { shift = 20, mask = 1, [0] = "ldrdDL", "ldrsbDL", },
+ { shift = 20, mask = 1, [0] = "strdDL", "ldrshDL", },
+ },
+ _ = {
+ shift = 20, mask = 25,
+ [16] = { shift = 7, mask = 1, [0] = map_misc, map_mulh, },
+ _ = {
+ shift = 0, mask = 0xffffffff,
+ [bor(0xe1a00000)] = "nop",
+ _ = map_data,
+ }
+ },
+}
+
+local map_datai = {
+ shift = 20, mask = 31, -- NYI: decode PSR bits of msr. Decode imm12.
+ [16] = "movwDW", [20] = "movtDW",
+ [18] = { shift = 0, mask = 0xf00ff, [0] = "nopv6", _ = "msrNW", },
+ [22] = "msrNW",
+ _ = map_data,
+}
+
+local map_branch = {
+ shift = 24, mask = 1,
+ [0] = "bB", "blB"
+}
+
+local map_condins = {
+ [0] = map_datar, map_datai, map_load, map_load1,
+ map_loadm, map_branch, map_loadc, map_datac
+}
+
+-- NYI: setend.
+local map_uncondins = {
+ [0] = false, map_simddata, map_simdload, map_preload,
+ false, "blxB", map_loadcu, map_datacu,
+}
+
+------------------------------------------------------------------------------
+
+local map_gpr = {
+ [0] = "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
+ "r8", "r9", "r10", "r11", "r12", "sp", "lr", "pc",
+}
+
+local map_cond = {
+ [0] = "eq", "ne", "hs", "lo", "mi", "pl", "vs", "vc",
+ "hi", "ls", "ge", "lt", "gt", "le", "al",
+}
+
+local map_shift = { [0] = "lsl", "lsr", "asr", "ror", }
+
+------------------------------------------------------------------------------
+
+-- Output a nicely formatted line with an opcode and operands.
+local function putop(ctx, text, operands)
+ local pos = ctx.pos
+ local extra = ""
+ if ctx.rel then
+ local sym = ctx.symtab[ctx.rel]
+ if sym then
+ extra = "\t->"..sym
+ elseif band(ctx.op, 0x0e000000) ~= 0x0a000000 then
+ extra = "\t; 0x"..tohex(ctx.rel)
+ end
+ end
+ if ctx.hexdump > 0 then
+ ctx.out(format("%08x %s %-5s %s%s\n",
+ ctx.addr+pos, tohex(ctx.op), text, concat(operands, ", "), extra))
+ else
+ ctx.out(format("%08x %-5s %s%s\n",
+ ctx.addr+pos, text, concat(operands, ", "), extra))
+ end
+ ctx.pos = pos + 4
+end
+
+-- Fallback for unknown opcodes.
+local function unknown(ctx)
+ return putop(ctx, ".long", { "0x"..tohex(ctx.op) })
+end
+
+-- Format operand 2 of load/store opcodes.
+local function fmtload(ctx, op, pos)
+ local base = map_gpr[band(rshift(op, 16), 15)]
+ local x, ofs
+ local ext = (band(op, 0x04000000) == 0)
+ if not ext and band(op, 0x02000000) == 0 then
+ ofs = band(op, 4095)
+ if band(op, 0x00800000) == 0 then ofs = -ofs end
+ if base == "pc" then ctx.rel = ctx.addr + pos + 8 + ofs end
+ ofs = "#"..ofs
+ elseif ext and band(op, 0x00400000) ~= 0 then
+ ofs = band(op, 15) + band(rshift(op, 4), 0xf0)
+ if band(op, 0x00800000) == 0 then ofs = -ofs end
+ if base == "pc" then ctx.rel = ctx.addr + pos + 8 + ofs end
+ ofs = "#"..ofs
+ else
+ ofs = map_gpr[band(op, 15)]
+ if ext or band(op, 0xfe0) == 0 then
+ elseif band(op, 0xfe0) == 0x60 then
+ ofs = format("%s, rrx", ofs)
+ else
+ local sh = band(rshift(op, 7), 31)
+ if sh == 0 then sh = 32 end
+ ofs = format("%s, %s #%d", ofs, map_shift[band(rshift(op, 5), 3)], sh)
+ end
+ if band(op, 0x00800000) == 0 then ofs = "-"..ofs end
+ end
+ if ofs == "#0" then
+ x = format("[%s]", base)
+ elseif band(op, 0x01000000) == 0 then
+ x = format("[%s], %s", base, ofs)
+ else
+ x = format("[%s, %s]", base, ofs)
+ end
+ if band(op, 0x01200000) == 0x01200000 then x = x.."!" end
+ return x
+end
+
+-- Format operand 2 of vector load/store opcodes.
+local function fmtvload(ctx, op, pos)
+ local base = map_gpr[band(rshift(op, 16), 15)]
+ local ofs = band(op, 255)*4
+ if band(op, 0x00800000) == 0 then ofs = -ofs end
+ if base == "pc" then ctx.rel = ctx.addr + pos + 8 + ofs end
+ if ofs == 0 then
+ return format("[%s]", base)
+ else
+ return format("[%s, #%d]", base, ofs)
+ end
+end
+
+local function fmtvr(op, vr, sh0, sh1)
+ if vr == "s" then
+ return format("s%d", 2*band(rshift(op, sh0), 15)+band(rshift(op, sh1), 1))
+ else
+ return format("d%d", band(rshift(op, sh0), 15)+band(rshift(op, sh1-4), 16))
+ end
+end
+
+-- Disassemble a single instruction.
+local function disass_ins(ctx)
+ local pos = ctx.pos
+ local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4)
+ local op = bor(lshift(b3, 24), lshift(b2, 16), lshift(b1, 8), b0)
+ local operands = {}
+ local suffix = ""
+ local last, name, pat
+ local vr
+ ctx.op = op
+ ctx.rel = nil
+
+ local cond = rshift(op, 28)
+ local opat
+ if cond == 15 then
+ opat = map_uncondins[band(rshift(op, 25), 7)]
+ else
+ if cond ~= 14 then suffix = map_cond[cond] end
+ opat = map_condins[band(rshift(op, 25), 7)]
+ end
+ while type(opat) ~= "string" do
+ if not opat then return unknown(ctx) end
+ opat = opat[band(rshift(op, opat.shift), opat.mask)] or opat._
+ end
+ name, pat = match(opat, "^([a-z0-9]*)(.*)")
+ if sub(pat, 1, 1) == "." then
+ local s2, p2 = match(pat, "^([a-z0-9.]*)(.*)")
+ suffix = suffix..s2
+ pat = p2
+ end
+
+ for p in gmatch(pat, ".") do
+ local x = nil
+ if p == "D" then
+ x = map_gpr[band(rshift(op, 12), 15)]
+ elseif p == "N" then
+ x = map_gpr[band(rshift(op, 16), 15)]
+ elseif p == "S" then
+ x = map_gpr[band(rshift(op, 8), 15)]
+ elseif p == "M" then
+ x = map_gpr[band(op, 15)]
+ elseif p == "d" then
+ x = fmtvr(op, vr, 12, 22)
+ elseif p == "n" then
+ x = fmtvr(op, vr, 16, 7)
+ elseif p == "m" then
+ x = fmtvr(op, vr, 0, 5)
+ elseif p == "P" then
+ if band(op, 0x02000000) ~= 0 then
+ x = ror(band(op, 255), 2*band(rshift(op, 8), 15))
+ else
+ x = map_gpr[band(op, 15)]
+ if band(op, 0xff0) ~= 0 then
+ operands[#operands+1] = x
+ local s = map_shift[band(rshift(op, 5), 3)]
+ local r = nil
+ if band(op, 0xf90) == 0 then
+ if s == "ror" then s = "rrx" else r = "#32" end
+ elseif band(op, 0x10) == 0 then
+ r = "#"..band(rshift(op, 7), 31)
+ else
+ r = map_gpr[band(rshift(op, 8), 15)]
+ end
+ if name == "mov" then name = s; x = r
+ elseif r then x = format("%s %s", s, r)
+ else x = s end
+ end
+ end
+ elseif p == "L" then
+ x = fmtload(ctx, op, pos)
+ elseif p == "l" then
+ x = fmtvload(ctx, op, pos)
+ elseif p == "B" then
+ local addr = ctx.addr + pos + 8 + arshift(lshift(op, 8), 6)
+ if cond == 15 then addr = addr + band(rshift(op, 23), 2) end
+ ctx.rel = addr
+ x = "0x"..tohex(addr)
+ elseif p == "F" then
+ vr = "s"
+ elseif p == "G" then
+ vr = "d"
+ elseif p == "." then
+ suffix = suffix..(vr == "s" and ".f32" or ".f64")
+ elseif p == "R" then
+ if band(op, 0x00200000) ~= 0 and #operands == 1 then
+ operands[1] = operands[1].."!"
+ end
+ local t = {}
+ for i=0,15 do
+ if band(rshift(op, i), 1) == 1 then t[#t+1] = map_gpr[i] end
+ end
+ x = "{"..concat(t, ", ").."}"
+ elseif p == "r" then
+ if band(op, 0x00200000) ~= 0 and #operands == 2 then
+ operands[1] = operands[1].."!"
+ end
+ local s = tonumber(sub(last, 2))
+ local n = band(op, 255)
+ if vr == "d" then n = rshift(n, 1) end
+ operands[#operands] = format("{%s-%s%d}", last, vr, s+n-1)
+ elseif p == "W" then
+ x = band(op, 0x0fff) + band(rshift(op, 4), 0xf000)
+ elseif p == "T" then
+ x = "#0x"..tohex(band(op, 0x00ffffff), 6)
+ elseif p == "U" then
+ x = band(rshift(op, 7), 31)
+ if x == 0 then x = nil end
+ elseif p == "u" then
+ x = band(rshift(op, 7), 31)
+ if band(op, 0x40) == 0 then
+ if x == 0 then x = nil else x = "lsl #"..x end
+ else
+ if x == 0 then x = "asr #32" else x = "asr #"..x end
+ end
+ elseif p == "v" then
+ x = band(rshift(op, 7), 31)
+ elseif p == "w" then
+ x = band(rshift(op, 16), 31)
+ elseif p == "x" then
+ x = band(rshift(op, 16), 31) + 1
+ elseif p == "X" then
+ x = band(rshift(op, 16), 31) - last + 1
+ elseif p == "Y" then
+ x = band(rshift(op, 12), 0xf0) + band(op, 0x0f)
+ elseif p == "K" then
+ x = "#0x"..tohex(band(rshift(op, 4), 0x0000fff0) + band(op, 15), 4)
+ elseif p == "s" then
+ if band(op, 0x00100000) ~= 0 then suffix = "s"..suffix end
+ else
+ assert(false)
+ end
+ if x then
+ last = x
+ if type(x) == "number" then x = "#"..x end
+ operands[#operands+1] = x
+ end
+ end
+
+ return putop(ctx, name..suffix, operands)
+end
+
+------------------------------------------------------------------------------
+
+-- Disassemble a block of code.
+local function disass_block(ctx, ofs, len)
+ if not ofs then ofs = 0 end
+ local stop = len and ofs+len or #ctx.code
+ ctx.pos = ofs
+ ctx.rel = nil
+ while ctx.pos < stop do disass_ins(ctx) end
+end
+
+-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len).
+local function create_(code, addr, out)
+ local ctx = {}
+ ctx.code = code
+ ctx.addr = addr or 0
+ ctx.out = out or io.write
+ ctx.symtab = {}
+ ctx.disass = disass_block
+ ctx.hexdump = 8
+ return ctx
+end
+
+-- Simple API: disassemble code (a string) at address and output via out.
+local function disass_(code, addr, out)
+ create_(code, addr, out):disass()
+end
+
+-- Return register name for RID.
+local function regname_(r)
+ if r < 16 then return map_gpr[r] end
+ return "d"..(r-16)
+end
+
+-- Public module functions.
+module(...)
+
+create = create_
+disass = disass_
+regname = regname_
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/jit/dis_mips.lua b/src/3rdparty/LuaJIT-2.0.5/src/jit/dis_mips.lua
new file mode 100644
index 0000000..02dfc17
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/jit/dis_mips.lua
@@ -0,0 +1,428 @@
+----------------------------------------------------------------------------
+-- LuaJIT MIPS disassembler module.
+--
+-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+-- Released under the MIT/X license. See Copyright Notice in luajit.h
+----------------------------------------------------------------------------
+-- This is a helper module used by the LuaJIT machine code dumper module.
+--
+-- It disassembles all standard MIPS32R1/R2 instructions.
+-- Default mode is big-endian, but see: dis_mipsel.lua
+------------------------------------------------------------------------------
+
+local type = type
+local byte, format = string.byte, string.format
+local match, gmatch = string.match, string.gmatch
+local concat = table.concat
+local bit = require("bit")
+local band, bor, tohex = bit.band, bit.bor, bit.tohex
+local lshift, rshift, arshift = bit.lshift, bit.rshift, bit.arshift
+
+------------------------------------------------------------------------------
+-- Primary and extended opcode maps
+------------------------------------------------------------------------------
+
+local map_movci = { shift = 16, mask = 1, [0] = "movfDSC", "movtDSC", }
+local map_srl = { shift = 21, mask = 1, [0] = "srlDTA", "rotrDTA", }
+local map_srlv = { shift = 6, mask = 1, [0] = "srlvDTS", "rotrvDTS", }
+
+local map_special = {
+ shift = 0, mask = 63,
+ [0] = { shift = 0, mask = -1, [0] = "nop", _ = "sllDTA" },
+ map_movci, map_srl, "sraDTA",
+ "sllvDTS", false, map_srlv, "sravDTS",
+ "jrS", "jalrD1S", "movzDST", "movnDST",
+ "syscallY", "breakY", false, "sync",
+ "mfhiD", "mthiS", "mfloD", "mtloS",
+ false, false, false, false,
+ "multST", "multuST", "divST", "divuST",
+ false, false, false, false,
+ "addDST", "addu|moveDST0", "subDST", "subu|neguDS0T",
+ "andDST", "orDST", "xorDST", "nor|notDST0",
+ false, false, "sltDST", "sltuDST",
+ false, false, false, false,
+ "tgeSTZ", "tgeuSTZ", "tltSTZ", "tltuSTZ",
+ "teqSTZ", false, "tneSTZ",
+}
+
+local map_special2 = {
+ shift = 0, mask = 63,
+ [0] = "maddST", "madduST", "mulDST", false,
+ "msubST", "msubuST",
+ [32] = "clzDS", [33] = "cloDS",
+ [63] = "sdbbpY",
+}
+
+local map_bshfl = {
+ shift = 6, mask = 31,
+ [2] = "wsbhDT",
+ [16] = "sebDT",
+ [24] = "sehDT",
+}
+
+local map_special3 = {
+ shift = 0, mask = 63,
+ [0] = "extTSAK", [4] = "insTSAL",
+ [32] = map_bshfl,
+ [59] = "rdhwrTD",
+}
+
+local map_regimm = {
+ shift = 16, mask = 31,
+ [0] = "bltzSB", "bgezSB", "bltzlSB", "bgezlSB",
+ false, false, false, false,
+ "tgeiSI", "tgeiuSI", "tltiSI", "tltiuSI",
+ "teqiSI", false, "tneiSI", false,
+ "bltzalSB", "bgezalSB", "bltzallSB", "bgezallSB",
+ false, false, false, false,
+ false, false, false, false,
+ false, false, false, "synciSO",
+}
+
+local map_cop0 = {
+ shift = 25, mask = 1,
+ [0] = {
+ shift = 21, mask = 15,
+ [0] = "mfc0TDW", [4] = "mtc0TDW",
+ [10] = "rdpgprDT",
+ [11] = { shift = 5, mask = 1, [0] = "diT0", "eiT0", },
+ [14] = "wrpgprDT",
+ }, {
+ shift = 0, mask = 63,
+ [1] = "tlbr", [2] = "tlbwi", [6] = "tlbwr", [8] = "tlbp",
+ [24] = "eret", [31] = "deret",
+ [32] = "wait",
+ },
+}
+
+local map_cop1s = {
+ shift = 0, mask = 63,
+ [0] = "add.sFGH", "sub.sFGH", "mul.sFGH", "div.sFGH",
+ "sqrt.sFG", "abs.sFG", "mov.sFG", "neg.sFG",
+ "round.l.sFG", "trunc.l.sFG", "ceil.l.sFG", "floor.l.sFG",
+ "round.w.sFG", "trunc.w.sFG", "ceil.w.sFG", "floor.w.sFG",
+ false,
+ { shift = 16, mask = 1, [0] = "movf.sFGC", "movt.sFGC" },
+ "movz.sFGT", "movn.sFGT",
+ false, "recip.sFG", "rsqrt.sFG", false,
+ false, false, false, false,
+ false, false, false, false,
+ false, "cvt.d.sFG", false, false,
+ "cvt.w.sFG", "cvt.l.sFG", "cvt.ps.sFGH", false,
+ false, false, false, false,
+ false, false, false, false,
+ "c.f.sVGH", "c.un.sVGH", "c.eq.sVGH", "c.ueq.sVGH",
+ "c.olt.sVGH", "c.ult.sVGH", "c.ole.sVGH", "c.ule.sVGH",
+ "c.sf.sVGH", "c.ngle.sVGH", "c.seq.sVGH", "c.ngl.sVGH",
+ "c.lt.sVGH", "c.nge.sVGH", "c.le.sVGH", "c.ngt.sVGH",
+}
+
+local map_cop1d = {
+ shift = 0, mask = 63,
+ [0] = "add.dFGH", "sub.dFGH", "mul.dFGH", "div.dFGH",
+ "sqrt.dFG", "abs.dFG", "mov.dFG", "neg.dFG",
+ "round.l.dFG", "trunc.l.dFG", "ceil.l.dFG", "floor.l.dFG",
+ "round.w.dFG", "trunc.w.dFG", "ceil.w.dFG", "floor.w.dFG",
+ false,
+ { shift = 16, mask = 1, [0] = "movf.dFGC", "movt.dFGC" },
+ "movz.dFGT", "movn.dFGT",
+ false, "recip.dFG", "rsqrt.dFG", false,
+ false, false, false, false,
+ false, false, false, false,
+ "cvt.s.dFG", false, false, false,
+ "cvt.w.dFG", "cvt.l.dFG", false, false,
+ false, false, false, false,
+ false, false, false, false,
+ "c.f.dVGH", "c.un.dVGH", "c.eq.dVGH", "c.ueq.dVGH",
+ "c.olt.dVGH", "c.ult.dVGH", "c.ole.dVGH", "c.ule.dVGH",
+ "c.df.dVGH", "c.ngle.dVGH", "c.deq.dVGH", "c.ngl.dVGH",
+ "c.lt.dVGH", "c.nge.dVGH", "c.le.dVGH", "c.ngt.dVGH",
+}
+
+local map_cop1ps = {
+ shift = 0, mask = 63,
+ [0] = "add.psFGH", "sub.psFGH", "mul.psFGH", false,
+ false, "abs.psFG", "mov.psFG", "neg.psFG",
+ false, false, false, false,
+ false, false, false, false,
+ false,
+ { shift = 16, mask = 1, [0] = "movf.psFGC", "movt.psFGC" },
+ "movz.psFGT", "movn.psFGT",
+ false, false, false, false,
+ false, false, false, false,
+ false, false, false, false,
+ "cvt.s.puFG", false, false, false,
+ false, false, false, false,
+ "cvt.s.plFG", false, false, false,
+ "pll.psFGH", "plu.psFGH", "pul.psFGH", "puu.psFGH",
+ "c.f.psVGH", "c.un.psVGH", "c.eq.psVGH", "c.ueq.psVGH",
+ "c.olt.psVGH", "c.ult.psVGH", "c.ole.psVGH", "c.ule.psVGH",
+ "c.psf.psVGH", "c.ngle.psVGH", "c.pseq.psVGH", "c.ngl.psVGH",
+ "c.lt.psVGH", "c.nge.psVGH", "c.le.psVGH", "c.ngt.psVGH",
+}
+
+local map_cop1w = {
+ shift = 0, mask = 63,
+ [32] = "cvt.s.wFG", [33] = "cvt.d.wFG",
+}
+
+local map_cop1l = {
+ shift = 0, mask = 63,
+ [32] = "cvt.s.lFG", [33] = "cvt.d.lFG",
+}
+
+local map_cop1bc = {
+ shift = 16, mask = 3,
+ [0] = "bc1fCB", "bc1tCB", "bc1flCB", "bc1tlCB",
+}
+
+local map_cop1 = {
+ shift = 21, mask = 31,
+ [0] = "mfc1TG", false, "cfc1TG", "mfhc1TG",
+ "mtc1TG", false, "ctc1TG", "mthc1TG",
+ map_cop1bc, false, false, false,
+ false, false, false, false,
+ map_cop1s, map_cop1d, false, false,
+ map_cop1w, map_cop1l, map_cop1ps,
+}
+
+local map_cop1x = {
+ shift = 0, mask = 63,
+ [0] = "lwxc1FSX", "ldxc1FSX", false, false,
+ false, "luxc1FSX", false, false,
+ "swxc1FSX", "sdxc1FSX", false, false,
+ false, "suxc1FSX", false, "prefxMSX",
+ false, false, false, false,
+ false, false, false, false,
+ false, false, false, false,
+ false, false, "alnv.psFGHS", false,
+ "madd.sFRGH", "madd.dFRGH", false, false,
+ false, false, "madd.psFRGH", false,
+ "msub.sFRGH", "msub.dFRGH", false, false,
+ false, false, "msub.psFRGH", false,
+ "nmadd.sFRGH", "nmadd.dFRGH", false, false,
+ false, false, "nmadd.psFRGH", false,
+ "nmsub.sFRGH", "nmsub.dFRGH", false, false,
+ false, false, "nmsub.psFRGH", false,
+}
+
+local map_pri = {
+ [0] = map_special, map_regimm, "jJ", "jalJ",
+ "beq|beqz|bST00B", "bne|bnezST0B", "blezSB", "bgtzSB",
+ "addiTSI", "addiu|liTS0I", "sltiTSI", "sltiuTSI",
+ "andiTSU", "ori|liTS0U", "xoriTSU", "luiTU",
+ map_cop0, map_cop1, false, map_cop1x,
+ "beql|beqzlST0B", "bnel|bnezlST0B", "blezlSB", "bgtzlSB",
+ false, false, false, false,
+ map_special2, false, false, map_special3,
+ "lbTSO", "lhTSO", "lwlTSO", "lwTSO",
+ "lbuTSO", "lhuTSO", "lwrTSO", false,
+ "sbTSO", "shTSO", "swlTSO", "swTSO",
+ false, false, "swrTSO", "cacheNSO",
+ "llTSO", "lwc1HSO", "lwc2TSO", "prefNSO",
+ false, "ldc1HSO", "ldc2TSO", false,
+ "scTSO", "swc1HSO", "swc2TSO", false,
+ false, "sdc1HSO", "sdc2TSO", false,
+}
+
+------------------------------------------------------------------------------
+
+local map_gpr = {
+ [0] = "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
+ "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
+ "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
+ "r24", "r25", "r26", "r27", "r28", "sp", "r30", "ra",
+}
+
+------------------------------------------------------------------------------
+
+-- Output a nicely formatted line with an opcode and operands.
+local function putop(ctx, text, operands)
+ local pos = ctx.pos
+ local extra = ""
+ if ctx.rel then
+ local sym = ctx.symtab[ctx.rel]
+ if sym then extra = "\t->"..sym end
+ end
+ if ctx.hexdump > 0 then
+ ctx.out(format("%08x %s %-7s %s%s\n",
+ ctx.addr+pos, tohex(ctx.op), text, concat(operands, ", "), extra))
+ else
+ ctx.out(format("%08x %-7s %s%s\n",
+ ctx.addr+pos, text, concat(operands, ", "), extra))
+ end
+ ctx.pos = pos + 4
+end
+
+-- Fallback for unknown opcodes.
+local function unknown(ctx)
+ return putop(ctx, ".long", { "0x"..tohex(ctx.op) })
+end
+
+local function get_be(ctx)
+ local pos = ctx.pos
+ local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4)
+ return bor(lshift(b0, 24), lshift(b1, 16), lshift(b2, 8), b3)
+end
+
+local function get_le(ctx)
+ local pos = ctx.pos
+ local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4)
+ return bor(lshift(b3, 24), lshift(b2, 16), lshift(b1, 8), b0)
+end
+
+-- Disassemble a single instruction.
+local function disass_ins(ctx)
+ local op = ctx:get()
+ local operands = {}
+ local last = nil
+ ctx.op = op
+ ctx.rel = nil
+
+ local opat = map_pri[rshift(op, 26)]
+ while type(opat) ~= "string" do
+ if not opat then return unknown(ctx) end
+ opat = opat[band(rshift(op, opat.shift), opat.mask)] or opat._
+ end
+ local name, pat = match(opat, "^([a-z0-9_.]*)(.*)")
+ local altname, pat2 = match(pat, "|([a-z0-9_.|]*)(.*)")
+ if altname then pat = pat2 end
+
+ for p in gmatch(pat, ".") do
+ local x = nil
+ if p == "S" then
+ x = map_gpr[band(rshift(op, 21), 31)]
+ elseif p == "T" then
+ x = map_gpr[band(rshift(op, 16), 31)]
+ elseif p == "D" then
+ x = map_gpr[band(rshift(op, 11), 31)]
+ elseif p == "F" then
+ x = "f"..band(rshift(op, 6), 31)
+ elseif p == "G" then
+ x = "f"..band(rshift(op, 11), 31)
+ elseif p == "H" then
+ x = "f"..band(rshift(op, 16), 31)
+ elseif p == "R" then
+ x = "f"..band(rshift(op, 21), 31)
+ elseif p == "A" then
+ x = band(rshift(op, 6), 31)
+ elseif p == "M" then
+ x = band(rshift(op, 11), 31)
+ elseif p == "N" then
+ x = band(rshift(op, 16), 31)
+ elseif p == "C" then
+ x = band(rshift(op, 18), 7)
+ if x == 0 then x = nil end
+ elseif p == "K" then
+ x = band(rshift(op, 11), 31) + 1
+ elseif p == "L" then
+ x = band(rshift(op, 11), 31) - last + 1
+ elseif p == "I" then
+ x = arshift(lshift(op, 16), 16)
+ elseif p == "U" then
+ x = band(op, 0xffff)
+ elseif p == "O" then
+ local disp = arshift(lshift(op, 16), 16)
+ operands[#operands] = format("%d(%s)", disp, last)
+ elseif p == "X" then
+ local index = map_gpr[band(rshift(op, 16), 31)]
+ operands[#operands] = format("%s(%s)", index, last)
+ elseif p == "B" then
+ x = ctx.addr + ctx.pos + arshift(lshift(op, 16), 16)*4 + 4
+ ctx.rel = x
+ x = "0x"..tohex(x)
+ elseif p == "J" then
+ x = band(ctx.addr + ctx.pos, 0xf0000000) + band(op, 0x03ffffff)*4
+ ctx.rel = x
+ x = "0x"..tohex(x)
+ elseif p == "V" then
+ x = band(rshift(op, 8), 7)
+ if x == 0 then x = nil end
+ elseif p == "W" then
+ x = band(op, 7)
+ if x == 0 then x = nil end
+ elseif p == "Y" then
+ x = band(rshift(op, 6), 0x000fffff)
+ if x == 0 then x = nil end
+ elseif p == "Z" then
+ x = band(rshift(op, 6), 1023)
+ if x == 0 then x = nil end
+ elseif p == "0" then
+ if last == "r0" or last == 0 then
+ local n = #operands
+ operands[n] = nil
+ last = operands[n-1]
+ if altname then
+ local a1, a2 = match(altname, "([^|]*)|(.*)")
+ if a1 then name, altname = a1, a2
+ else name = altname end
+ end
+ end
+ elseif p == "1" then
+ if last == "ra" then
+ operands[#operands] = nil
+ end
+ else
+ assert(false)
+ end
+ if x then operands[#operands+1] = x; last = x end
+ end
+
+ return putop(ctx, name, operands)
+end
+
+------------------------------------------------------------------------------
+
+-- Disassemble a block of code.
+local function disass_block(ctx, ofs, len)
+ if not ofs then ofs = 0 end
+ local stop = len and ofs+len or #ctx.code
+ stop = stop - stop % 4
+ ctx.pos = ofs - ofs % 4
+ ctx.rel = nil
+ while ctx.pos < stop do disass_ins(ctx) end
+end
+
+-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len).
+local function create_(code, addr, out)
+ local ctx = {}
+ ctx.code = code
+ ctx.addr = addr or 0
+ ctx.out = out or io.write
+ ctx.symtab = {}
+ ctx.disass = disass_block
+ ctx.hexdump = 8
+ ctx.get = get_be
+ return ctx
+end
+
+local function create_el_(code, addr, out)
+ local ctx = create_(code, addr, out)
+ ctx.get = get_le
+ return ctx
+end
+
+-- Simple API: disassemble code (a string) at address and output via out.
+local function disass_(code, addr, out)
+ create_(code, addr, out):disass()
+end
+
+local function disass_el_(code, addr, out)
+ create_el_(code, addr, out):disass()
+end
+
+-- Return register name for RID.
+local function regname_(r)
+ if r < 32 then return map_gpr[r] end
+ return "f"..(r-32)
+end
+
+-- Public module functions.
+module(...)
+
+create = create_
+create_el = create_el_
+disass = disass_
+disass_el = disass_el_
+regname = regname_
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/jit/dis_mipsel.lua b/src/3rdparty/LuaJIT-2.0.5/src/jit/dis_mipsel.lua
new file mode 100644
index 0000000..c9c2e24
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/jit/dis_mipsel.lua
@@ -0,0 +1,20 @@
+----------------------------------------------------------------------------
+-- LuaJIT MIPSEL disassembler wrapper module.
+--
+-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+-- Released under the MIT license. See Copyright Notice in luajit.h
+----------------------------------------------------------------------------
+-- This module just exports the little-endian functions from the
+-- MIPS disassembler module. All the interesting stuff is there.
+------------------------------------------------------------------------------
+
+local require = require
+
+module(...)
+
+local dis_mips = require(_PACKAGE.."dis_mips")
+
+create = dis_mips.create_el
+disass = dis_mips.disass_el
+regname = dis_mips.regname
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/jit/dis_ppc.lua b/src/3rdparty/LuaJIT-2.0.5/src/jit/dis_ppc.lua
new file mode 100644
index 0000000..4043aeb
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/jit/dis_ppc.lua
@@ -0,0 +1,591 @@
+----------------------------------------------------------------------------
+-- LuaJIT PPC disassembler module.
+--
+-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+-- Released under the MIT/X license. See Copyright Notice in luajit.h
+----------------------------------------------------------------------------
+-- This is a helper module used by the LuaJIT machine code dumper module.
+--
+-- It disassembles all common, non-privileged 32/64 bit PowerPC instructions
+-- plus the e500 SPE instructions and some Cell/Xenon extensions.
+--
+-- NYI: VMX, VMX128
+------------------------------------------------------------------------------
+
+local type = type
+local byte, format = string.byte, string.format
+local match, gmatch, gsub = string.match, string.gmatch, string.gsub
+local concat = table.concat
+local bit = require("bit")
+local band, bor, tohex = bit.band, bit.bor, bit.tohex
+local lshift, rshift, arshift = bit.lshift, bit.rshift, bit.arshift
+
+------------------------------------------------------------------------------
+-- Primary and extended opcode maps
+------------------------------------------------------------------------------
+
+local map_crops = {
+ shift = 1, mask = 1023,
+ [0] = "mcrfXX",
+ [33] = "crnor|crnotCCC=", [129] = "crandcCCC",
+ [193] = "crxor|crclrCCC%", [225] = "crnandCCC",
+ [257] = "crandCCC", [289] = "creqv|crsetCCC%",
+ [417] = "crorcCCC", [449] = "cror|crmoveCCC=",
+ [16] = "b_lrKB", [528] = "b_ctrKB",
+ [150] = "isync",
+}
+
+local map_rlwinm = setmetatable({
+ shift = 0, mask = -1,
+},
+{ __index = function(t, x)
+ local rot = band(rshift(x, 11), 31)
+ local mb = band(rshift(x, 6), 31)
+ local me = band(rshift(x, 1), 31)
+ if mb == 0 and me == 31-rot then
+ return "slwiRR~A."
+ elseif me == 31 and mb == 32-rot then
+ return "srwiRR~-A."
+ else
+ return "rlwinmRR~AAA."
+ end
+ end
+})
+
+local map_rld = {
+ shift = 2, mask = 7,
+ [0] = "rldiclRR~HM.", "rldicrRR~HM.", "rldicRR~HM.", "rldimiRR~HM.",
+ {
+ shift = 1, mask = 1,
+ [0] = "rldclRR~RM.", "rldcrRR~RM.",
+ },
+}
+
+local map_ext = setmetatable({
+ shift = 1, mask = 1023,
+
+ [0] = "cmp_YLRR", [32] = "cmpl_YLRR",
+ [4] = "twARR", [68] = "tdARR",
+
+ [8] = "subfcRRR.", [40] = "subfRRR.",
+ [104] = "negRR.", [136] = "subfeRRR.",
+ [200] = "subfzeRR.", [232] = "subfmeRR.",
+ [520] = "subfcoRRR.", [552] = "subfoRRR.",
+ [616] = "negoRR.", [648] = "subfeoRRR.",
+ [712] = "subfzeoRR.", [744] = "subfmeoRR.",
+
+ [9] = "mulhduRRR.", [73] = "mulhdRRR.", [233] = "mulldRRR.",
+ [457] = "divduRRR.", [489] = "divdRRR.",
+ [745] = "mulldoRRR.",
+ [969] = "divduoRRR.", [1001] = "divdoRRR.",
+
+ [10] = "addcRRR.", [138] = "addeRRR.",
+ [202] = "addzeRR.", [234] = "addmeRR.", [266] = "addRRR.",
+ [522] = "addcoRRR.", [650] = "addeoRRR.",
+ [714] = "addzeoRR.", [746] = "addmeoRR.", [778] = "addoRRR.",
+
+ [11] = "mulhwuRRR.", [75] = "mulhwRRR.", [235] = "mullwRRR.",
+ [459] = "divwuRRR.", [491] = "divwRRR.",
+ [747] = "mullwoRRR.",
+ [971] = "divwouRRR.", [1003] = "divwoRRR.",
+
+ [15] = "iselltRRR", [47] = "iselgtRRR", [79] = "iseleqRRR",
+
+ [144] = { shift = 20, mask = 1, [0] = "mtcrfRZ~", "mtocrfRZ~", },
+ [19] = { shift = 20, mask = 1, [0] = "mfcrR", "mfocrfRZ", },
+ [371] = { shift = 11, mask = 1023, [392] = "mftbR", [424] = "mftbuR", },
+ [339] = {
+ shift = 11, mask = 1023,
+ [32] = "mferR", [256] = "mflrR", [288] = "mfctrR", [16] = "mfspefscrR",
+ },
+ [467] = {
+ shift = 11, mask = 1023,
+ [32] = "mtxerR", [256] = "mtlrR", [288] = "mtctrR", [16] = "mtspefscrR",
+ },
+
+ [20] = "lwarxRR0R", [84] = "ldarxRR0R",
+
+ [21] = "ldxRR0R", [53] = "lduxRRR",
+ [149] = "stdxRR0R", [181] = "stduxRRR",
+ [341] = "lwaxRR0R", [373] = "lwauxRRR",
+
+ [23] = "lwzxRR0R", [55] = "lwzuxRRR",
+ [87] = "lbzxRR0R", [119] = "lbzuxRRR",
+ [151] = "stwxRR0R", [183] = "stwuxRRR",
+ [215] = "stbxRR0R", [247] = "stbuxRRR",
+ [279] = "lhzxRR0R", [311] = "lhzuxRRR",
+ [343] = "lhaxRR0R", [375] = "lhauxRRR",
+ [407] = "sthxRR0R", [439] = "sthuxRRR",
+
+ [54] = "dcbst-R0R", [86] = "dcbf-R0R",
+ [150] = "stwcxRR0R.", [214] = "stdcxRR0R.",
+ [246] = "dcbtst-R0R", [278] = "dcbt-R0R",
+ [310] = "eciwxRR0R", [438] = "ecowxRR0R",
+ [470] = "dcbi-RR",
+
+ [598] = {
+ shift = 21, mask = 3,
+ [0] = "sync", "lwsync", "ptesync",
+ },
+ [758] = "dcba-RR",
+ [854] = "eieio", [982] = "icbi-R0R", [1014] = "dcbz-R0R",
+
+ [26] = "cntlzwRR~", [58] = "cntlzdRR~",
+ [122] = "popcntbRR~",
+ [154] = "prtywRR~", [186] = "prtydRR~",
+
+ [28] = "andRR~R.", [60] = "andcRR~R.", [124] = "nor|notRR~R=.",
+ [284] = "eqvRR~R.", [316] = "xorRR~R.",
+ [412] = "orcRR~R.", [444] = "or|mrRR~R=.", [476] = "nandRR~R.",
+ [508] = "cmpbRR~R",
+
+ [512] = "mcrxrX",
+
+ [532] = "ldbrxRR0R", [660] = "stdbrxRR0R",
+
+ [533] = "lswxRR0R", [597] = "lswiRR0A",
+ [661] = "stswxRR0R", [725] = "stswiRR0A",
+
+ [534] = "lwbrxRR0R", [662] = "stwbrxRR0R",
+ [790] = "lhbrxRR0R", [918] = "sthbrxRR0R",
+
+ [535] = "lfsxFR0R", [567] = "lfsuxFRR",
+ [599] = "lfdxFR0R", [631] = "lfduxFRR",
+ [663] = "stfsxFR0R", [695] = "stfsuxFRR",
+ [727] = "stfdxFR0R", [759] = "stfduxFR0R",
+ [855] = "lfiwaxFR0R",
+ [983] = "stfiwxFR0R",
+
+ [24] = "slwRR~R.",
+
+ [27] = "sldRR~R.", [536] = "srwRR~R.",
+ [792] = "srawRR~R.", [824] = "srawiRR~A.",
+
+ [794] = "sradRR~R.", [826] = "sradiRR~H.", [827] = "sradiRR~H.",
+ [922] = "extshRR~.", [954] = "extsbRR~.", [986] = "extswRR~.",
+
+ [539] = "srdRR~R.",
+},
+{ __index = function(t, x)
+ if band(x, 31) == 15 then return "iselRRRC" end
+ end
+})
+
+local map_ld = {
+ shift = 0, mask = 3,
+ [0] = "ldRRE", "lduRRE", "lwaRRE",
+}
+
+local map_std = {
+ shift = 0, mask = 3,
+ [0] = "stdRRE", "stduRRE",
+}
+
+local map_fps = {
+ shift = 5, mask = 1,
+ {
+ shift = 1, mask = 15,
+ [0] = false, false, "fdivsFFF.", false,
+ "fsubsFFF.", "faddsFFF.", "fsqrtsF-F.", false,
+ "fresF-F.", "fmulsFF-F.", "frsqrtesF-F.", false,
+ "fmsubsFFFF~.", "fmaddsFFFF~.", "fnmsubsFFFF~.", "fnmaddsFFFF~.",
+ }
+}
+
+local map_fpd = {
+ shift = 5, mask = 1,
+ [0] = {
+ shift = 1, mask = 1023,
+ [0] = "fcmpuXFF", [32] = "fcmpoXFF", [64] = "mcrfsXX",
+ [38] = "mtfsb1A.", [70] = "mtfsb0A.", [134] = "mtfsfiA>>-A>",
+ [8] = "fcpsgnFFF.", [40] = "fnegF-F.", [72] = "fmrF-F.",
+ [136] = "fnabsF-F.", [264] = "fabsF-F.",
+ [12] = "frspF-F.",
+ [14] = "fctiwF-F.", [15] = "fctiwzF-F.",
+ [583] = "mffsF.", [711] = "mtfsfZF.",
+ [392] = "frinF-F.", [424] = "frizF-F.",
+ [456] = "fripF-F.", [488] = "frimF-F.",
+ [814] = "fctidF-F.", [815] = "fctidzF-F.", [846] = "fcfidF-F.",
+ },
+ {
+ shift = 1, mask = 15,
+ [0] = false, false, "fdivFFF.", false,
+ "fsubFFF.", "faddFFF.", "fsqrtF-F.", "fselFFFF~.",
+ "freF-F.", "fmulFF-F.", "frsqrteF-F.", false,
+ "fmsubFFFF~.", "fmaddFFFF~.", "fnmsubFFFF~.", "fnmaddFFFF~.",
+ }
+}
+
+local map_spe = {
+ shift = 0, mask = 2047,
+
+ [512] = "evaddwRRR", [514] = "evaddiwRAR~",
+ [516] = "evsubwRRR~", [518] = "evsubiwRAR~",
+ [520] = "evabsRR", [521] = "evnegRR",
+ [522] = "evextsbRR", [523] = "evextshRR", [524] = "evrndwRR",
+ [525] = "evcntlzwRR", [526] = "evcntlswRR",
+
+ [527] = "brincRRR",
+
+ [529] = "evandRRR", [530] = "evandcRRR", [534] = "evxorRRR",
+ [535] = "evor|evmrRRR=", [536] = "evnor|evnotRRR=",
+ [537] = "eveqvRRR", [539] = "evorcRRR", [542] = "evnandRRR",
+
+ [544] = "evsrwuRRR", [545] = "evsrwsRRR",
+ [546] = "evsrwiuRRA", [547] = "evsrwisRRA",
+ [548] = "evslwRRR", [550] = "evslwiRRA",
+ [552] = "evrlwRRR", [553] = "evsplatiRS",
+ [554] = "evrlwiRRA", [555] = "evsplatfiRS",
+ [556] = "evmergehiRRR", [557] = "evmergeloRRR",
+ [558] = "evmergehiloRRR", [559] = "evmergelohiRRR",
+
+ [560] = "evcmpgtuYRR", [561] = "evcmpgtsYRR",
+ [562] = "evcmpltuYRR", [563] = "evcmpltsYRR",
+ [564] = "evcmpeqYRR",
+
+ [632] = "evselRRR", [633] = "evselRRRW",
+ [634] = "evselRRRW", [635] = "evselRRRW",
+ [636] = "evselRRRW", [637] = "evselRRRW",
+ [638] = "evselRRRW", [639] = "evselRRRW",
+
+ [640] = "evfsaddRRR", [641] = "evfssubRRR",
+ [644] = "evfsabsRR", [645] = "evfsnabsRR", [646] = "evfsnegRR",
+ [648] = "evfsmulRRR", [649] = "evfsdivRRR",
+ [652] = "evfscmpgtYRR", [653] = "evfscmpltYRR", [654] = "evfscmpeqYRR",
+ [656] = "evfscfuiR-R", [657] = "evfscfsiR-R",
+ [658] = "evfscfufR-R", [659] = "evfscfsfR-R",
+ [660] = "evfsctuiR-R", [661] = "evfsctsiR-R",
+ [662] = "evfsctufR-R", [663] = "evfsctsfR-R",
+ [664] = "evfsctuizR-R", [666] = "evfsctsizR-R",
+ [668] = "evfststgtYRR", [669] = "evfststltYRR", [670] = "evfststeqYRR",
+
+ [704] = "efsaddRRR", [705] = "efssubRRR",
+ [708] = "efsabsRR", [709] = "efsnabsRR", [710] = "efsnegRR",
+ [712] = "efsmulRRR", [713] = "efsdivRRR",
+ [716] = "efscmpgtYRR", [717] = "efscmpltYRR", [718] = "efscmpeqYRR",
+ [719] = "efscfdR-R",
+ [720] = "efscfuiR-R", [721] = "efscfsiR-R",
+ [722] = "efscfufR-R", [723] = "efscfsfR-R",
+ [724] = "efsctuiR-R", [725] = "efsctsiR-R",
+ [726] = "efsctufR-R", [727] = "efsctsfR-R",
+ [728] = "efsctuizR-R", [730] = "efsctsizR-R",
+ [732] = "efststgtYRR", [733] = "efststltYRR", [734] = "efststeqYRR",
+
+ [736] = "efdaddRRR", [737] = "efdsubRRR",
+ [738] = "efdcfuidR-R", [739] = "efdcfsidR-R",
+ [740] = "efdabsRR", [741] = "efdnabsRR", [742] = "efdnegRR",
+ [744] = "efdmulRRR", [745] = "efddivRRR",
+ [746] = "efdctuidzR-R", [747] = "efdctsidzR-R",
+ [748] = "efdcmpgtYRR", [749] = "efdcmpltYRR", [750] = "efdcmpeqYRR",
+ [751] = "efdcfsR-R",
+ [752] = "efdcfuiR-R", [753] = "efdcfsiR-R",
+ [754] = "efdcfufR-R", [755] = "efdcfsfR-R",
+ [756] = "efdctuiR-R", [757] = "efdctsiR-R",
+ [758] = "efdctufR-R", [759] = "efdctsfR-R",
+ [760] = "efdctuizR-R", [762] = "efdctsizR-R",
+ [764] = "efdtstgtYRR", [765] = "efdtstltYRR", [766] = "efdtsteqYRR",
+
+ [768] = "evlddxRR0R", [769] = "evlddRR8",
+ [770] = "evldwxRR0R", [771] = "evldwRR8",
+ [772] = "evldhxRR0R", [773] = "evldhRR8",
+ [776] = "evlhhesplatxRR0R", [777] = "evlhhesplatRR2",
+ [780] = "evlhhousplatxRR0R", [781] = "evlhhousplatRR2",
+ [782] = "evlhhossplatxRR0R", [783] = "evlhhossplatRR2",
+ [784] = "evlwhexRR0R", [785] = "evlwheRR4",
+ [788] = "evlwhouxRR0R", [789] = "evlwhouRR4",
+ [790] = "evlwhosxRR0R", [791] = "evlwhosRR4",
+ [792] = "evlwwsplatxRR0R", [793] = "evlwwsplatRR4",
+ [796] = "evlwhsplatxRR0R", [797] = "evlwhsplatRR4",
+
+ [800] = "evstddxRR0R", [801] = "evstddRR8",
+ [802] = "evstdwxRR0R", [803] = "evstdwRR8",
+ [804] = "evstdhxRR0R", [805] = "evstdhRR8",
+ [816] = "evstwhexRR0R", [817] = "evstwheRR4",
+ [820] = "evstwhoxRR0R", [821] = "evstwhoRR4",
+ [824] = "evstwwexRR0R", [825] = "evstwweRR4",
+ [828] = "evstwwoxRR0R", [829] = "evstwwoRR4",
+
+ [1027] = "evmhessfRRR", [1031] = "evmhossfRRR", [1032] = "evmheumiRRR",
+ [1033] = "evmhesmiRRR", [1035] = "evmhesmfRRR", [1036] = "evmhoumiRRR",
+ [1037] = "evmhosmiRRR", [1039] = "evmhosmfRRR", [1059] = "evmhessfaRRR",
+ [1063] = "evmhossfaRRR", [1064] = "evmheumiaRRR", [1065] = "evmhesmiaRRR",
+ [1067] = "evmhesmfaRRR", [1068] = "evmhoumiaRRR", [1069] = "evmhosmiaRRR",
+ [1071] = "evmhosmfaRRR", [1095] = "evmwhssfRRR", [1096] = "evmwlumiRRR",
+ [1100] = "evmwhumiRRR", [1101] = "evmwhsmiRRR", [1103] = "evmwhsmfRRR",
+ [1107] = "evmwssfRRR", [1112] = "evmwumiRRR", [1113] = "evmwsmiRRR",
+ [1115] = "evmwsmfRRR", [1127] = "evmwhssfaRRR", [1128] = "evmwlumiaRRR",
+ [1132] = "evmwhumiaRRR", [1133] = "evmwhsmiaRRR", [1135] = "evmwhsmfaRRR",
+ [1139] = "evmwssfaRRR", [1144] = "evmwumiaRRR", [1145] = "evmwsmiaRRR",
+ [1147] = "evmwsmfaRRR",
+
+ [1216] = "evaddusiaawRR", [1217] = "evaddssiaawRR",
+ [1218] = "evsubfusiaawRR", [1219] = "evsubfssiaawRR",
+ [1220] = "evmraRR",
+ [1222] = "evdivwsRRR", [1223] = "evdivwuRRR",
+ [1224] = "evaddumiaawRR", [1225] = "evaddsmiaawRR",
+ [1226] = "evsubfumiaawRR", [1227] = "evsubfsmiaawRR",
+
+ [1280] = "evmheusiaawRRR", [1281] = "evmhessiaawRRR",
+ [1283] = "evmhessfaawRRR", [1284] = "evmhousiaawRRR",
+ [1285] = "evmhossiaawRRR", [1287] = "evmhossfaawRRR",
+ [1288] = "evmheumiaawRRR", [1289] = "evmhesmiaawRRR",
+ [1291] = "evmhesmfaawRRR", [1292] = "evmhoumiaawRRR",
+ [1293] = "evmhosmiaawRRR", [1295] = "evmhosmfaawRRR",
+ [1320] = "evmhegumiaaRRR", [1321] = "evmhegsmiaaRRR",
+ [1323] = "evmhegsmfaaRRR", [1324] = "evmhogumiaaRRR",
+ [1325] = "evmhogsmiaaRRR", [1327] = "evmhogsmfaaRRR",
+ [1344] = "evmwlusiaawRRR", [1345] = "evmwlssiaawRRR",
+ [1352] = "evmwlumiaawRRR", [1353] = "evmwlsmiaawRRR",
+ [1363] = "evmwssfaaRRR", [1368] = "evmwumiaaRRR",
+ [1369] = "evmwsmiaaRRR", [1371] = "evmwsmfaaRRR",
+ [1408] = "evmheusianwRRR", [1409] = "evmhessianwRRR",
+ [1411] = "evmhessfanwRRR", [1412] = "evmhousianwRRR",
+ [1413] = "evmhossianwRRR", [1415] = "evmhossfanwRRR",
+ [1416] = "evmheumianwRRR", [1417] = "evmhesmianwRRR",
+ [1419] = "evmhesmfanwRRR", [1420] = "evmhoumianwRRR",
+ [1421] = "evmhosmianwRRR", [1423] = "evmhosmfanwRRR",
+ [1448] = "evmhegumianRRR", [1449] = "evmhegsmianRRR",
+ [1451] = "evmhegsmfanRRR", [1452] = "evmhogumianRRR",
+ [1453] = "evmhogsmianRRR", [1455] = "evmhogsmfanRRR",
+ [1472] = "evmwlusianwRRR", [1473] = "evmwlssianwRRR",
+ [1480] = "evmwlumianwRRR", [1481] = "evmwlsmianwRRR",
+ [1491] = "evmwssfanRRR", [1496] = "evmwumianRRR",
+ [1497] = "evmwsmianRRR", [1499] = "evmwsmfanRRR",
+}
+
+local map_pri = {
+ [0] = false, false, "tdiARI", "twiARI",
+ map_spe, false, false, "mulliRRI",
+ "subficRRI", false, "cmpl_iYLRU", "cmp_iYLRI",
+ "addicRRI", "addic.RRI", "addi|liRR0I", "addis|lisRR0I",
+ "b_KBJ", "sc", "bKJ", map_crops,
+ "rlwimiRR~AAA.", map_rlwinm, false, "rlwnmRR~RAA.",
+ "oriNRR~U", "orisRR~U", "xoriRR~U", "xorisRR~U",
+ "andi.RR~U", "andis.RR~U", map_rld, map_ext,
+ "lwzRRD", "lwzuRRD", "lbzRRD", "lbzuRRD",
+ "stwRRD", "stwuRRD", "stbRRD", "stbuRRD",
+ "lhzRRD", "lhzuRRD", "lhaRRD", "lhauRRD",
+ "sthRRD", "sthuRRD", "lmwRRD", "stmwRRD",
+ "lfsFRD", "lfsuFRD", "lfdFRD", "lfduFRD",
+ "stfsFRD", "stfsuFRD", "stfdFRD", "stfduFRD",
+ false, false, map_ld, map_fps,
+ false, false, map_std, map_fpd,
+}
+
+------------------------------------------------------------------------------
+
+local map_gpr = {
+ [0] = "r0", "sp", "r2", "r3", "r4", "r5", "r6", "r7",
+ "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
+ "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
+ "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
+}
+
+local map_cond = { [0] = "lt", "gt", "eq", "so", "ge", "le", "ne", "ns", }
+
+-- Format a condition bit.
+local function condfmt(cond)
+ if cond <= 3 then
+ return map_cond[band(cond, 3)]
+ else
+ return format("4*cr%d+%s", rshift(cond, 2), map_cond[band(cond, 3)])
+ end
+end
+
+------------------------------------------------------------------------------
+
+-- Output a nicely formatted line with an opcode and operands.
+local function putop(ctx, text, operands)
+ local pos = ctx.pos
+ local extra = ""
+ if ctx.rel then
+ local sym = ctx.symtab[ctx.rel]
+ if sym then extra = "\t->"..sym end
+ end
+ if ctx.hexdump > 0 then
+ ctx.out(format("%08x %s %-7s %s%s\n",
+ ctx.addr+pos, tohex(ctx.op), text, concat(operands, ", "), extra))
+ else
+ ctx.out(format("%08x %-7s %s%s\n",
+ ctx.addr+pos, text, concat(operands, ", "), extra))
+ end
+ ctx.pos = pos + 4
+end
+
+-- Fallback for unknown opcodes.
+local function unknown(ctx)
+ return putop(ctx, ".long", { "0x"..tohex(ctx.op) })
+end
+
+-- Disassemble a single instruction.
+local function disass_ins(ctx)
+ local pos = ctx.pos
+ local b0, b1, b2, b3 = byte(ctx.code, pos+1, pos+4)
+ local op = bor(lshift(b0, 24), lshift(b1, 16), lshift(b2, 8), b3)
+ local operands = {}
+ local last = nil
+ local rs = 21
+ ctx.op = op
+ ctx.rel = nil
+
+ local opat = map_pri[rshift(b0, 2)]
+ while type(opat) ~= "string" do
+ if not opat then return unknown(ctx) end
+ opat = opat[band(rshift(op, opat.shift), opat.mask)]
+ end
+ local name, pat = match(opat, "^([a-z0-9_.]*)(.*)")
+ local altname, pat2 = match(pat, "|([a-z0-9_.]*)(.*)")
+ if altname then pat = pat2 end
+
+ for p in gmatch(pat, ".") do
+ local x = nil
+ if p == "R" then
+ x = map_gpr[band(rshift(op, rs), 31)]
+ rs = rs - 5
+ elseif p == "F" then
+ x = "f"..band(rshift(op, rs), 31)
+ rs = rs - 5
+ elseif p == "A" then
+ x = band(rshift(op, rs), 31)
+ rs = rs - 5
+ elseif p == "S" then
+ x = arshift(lshift(op, 27-rs), 27)
+ rs = rs - 5
+ elseif p == "I" then
+ x = arshift(lshift(op, 16), 16)
+ elseif p == "U" then
+ x = band(op, 0xffff)
+ elseif p == "D" or p == "E" then
+ local disp = arshift(lshift(op, 16), 16)
+ if p == "E" then disp = band(disp, -4) end
+ if last == "r0" then last = "0" end
+ operands[#operands] = format("%d(%s)", disp, last)
+ elseif p >= "2" and p <= "8" then
+ local disp = band(rshift(op, rs), 31) * p
+ if last == "r0" then last = "0" end
+ operands[#operands] = format("%d(%s)", disp, last)
+ elseif p == "H" then
+ x = band(rshift(op, rs), 31) + lshift(band(op, 2), 4)
+ rs = rs - 5
+ elseif p == "M" then
+ x = band(rshift(op, rs), 31) + band(op, 0x20)
+ elseif p == "C" then
+ x = condfmt(band(rshift(op, rs), 31))
+ rs = rs - 5
+ elseif p == "B" then
+ local bo = rshift(op, 21)
+ local cond = band(rshift(op, 16), 31)
+ local cn = ""
+ rs = rs - 10
+ if band(bo, 4) == 0 then
+ cn = band(bo, 2) == 0 and "dnz" or "dz"
+ if band(bo, 0x10) == 0 then
+ cn = cn..(band(bo, 8) == 0 and "f" or "t")
+ end
+ if band(bo, 0x10) == 0 then x = condfmt(cond) end
+ name = name..(band(bo, 1) == band(rshift(op, 15), 1) and "-" or "+")
+ elseif band(bo, 0x10) == 0 then
+ cn = map_cond[band(cond, 3) + (band(bo, 8) == 0 and 4 or 0)]
+ if cond > 3 then x = "cr"..rshift(cond, 2) end
+ name = name..(band(bo, 1) == band(rshift(op, 15), 1) and "-" or "+")
+ end
+ name = gsub(name, "_", cn)
+ elseif p == "J" then
+ x = arshift(lshift(op, 27-rs), 29-rs)*4
+ if band(op, 2) == 0 then x = ctx.addr + pos + x end
+ ctx.rel = x
+ x = "0x"..tohex(x)
+ elseif p == "K" then
+ if band(op, 1) ~= 0 then name = name.."l" end
+ if band(op, 2) ~= 0 then name = name.."a" end
+ elseif p == "X" or p == "Y" then
+ x = band(rshift(op, rs+2), 7)
+ if x == 0 and p == "Y" then x = nil else x = "cr"..x end
+ rs = rs - 5
+ elseif p == "W" then
+ x = "cr"..band(op, 7)
+ elseif p == "Z" then
+ x = band(rshift(op, rs-4), 255)
+ rs = rs - 10
+ elseif p == ">" then
+ operands[#operands] = rshift(operands[#operands], 1)
+ elseif p == "0" then
+ if last == "r0" then
+ operands[#operands] = nil
+ if altname then name = altname end
+ end
+ elseif p == "L" then
+ name = gsub(name, "_", band(op, 0x00200000) ~= 0 and "d" or "w")
+ elseif p == "." then
+ if band(op, 1) == 1 then name = name.."." end
+ elseif p == "N" then
+ if op == 0x60000000 then name = "nop"; break end
+ elseif p == "~" then
+ local n = #operands
+ operands[n-1], operands[n] = operands[n], operands[n-1]
+ elseif p == "=" then
+ local n = #operands
+ if last == operands[n-1] then
+ operands[n] = nil
+ name = altname
+ end
+ elseif p == "%" then
+ local n = #operands
+ if last == operands[n-1] and last == operands[n-2] then
+ operands[n] = nil
+ operands[n-1] = nil
+ name = altname
+ end
+ elseif p == "-" then
+ rs = rs - 5
+ else
+ assert(false)
+ end
+ if x then operands[#operands+1] = x; last = x end
+ end
+
+ return putop(ctx, name, operands)
+end
+
+------------------------------------------------------------------------------
+
+-- Disassemble a block of code.
+local function disass_block(ctx, ofs, len)
+ if not ofs then ofs = 0 end
+ local stop = len and ofs+len or #ctx.code
+ stop = stop - stop % 4
+ ctx.pos = ofs - ofs % 4
+ ctx.rel = nil
+ while ctx.pos < stop do disass_ins(ctx) end
+end
+
+-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len).
+local function create_(code, addr, out)
+ local ctx = {}
+ ctx.code = code
+ ctx.addr = addr or 0
+ ctx.out = out or io.write
+ ctx.symtab = {}
+ ctx.disass = disass_block
+ ctx.hexdump = 8
+ return ctx
+end
+
+-- Simple API: disassemble code (a string) at address and output via out.
+local function disass_(code, addr, out)
+ create_(code, addr, out):disass()
+end
+
+-- Return register name for RID.
+local function regname_(r)
+ if r < 32 then return map_gpr[r] end
+ return "f"..(r-32)
+end
+
+-- Public module functions.
+module(...)
+
+create = create_
+disass = disass_
+regname = regname_
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/jit/dis_x64.lua b/src/3rdparty/LuaJIT-2.0.5/src/jit/dis_x64.lua
new file mode 100644
index 0000000..0891803
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/jit/dis_x64.lua
@@ -0,0 +1,20 @@
+----------------------------------------------------------------------------
+-- LuaJIT x64 disassembler wrapper module.
+--
+-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+-- Released under the MIT license. See Copyright Notice in luajit.h
+----------------------------------------------------------------------------
+-- This module just exports the 64 bit functions from the combined
+-- x86/x64 disassembler module. All the interesting stuff is there.
+------------------------------------------------------------------------------
+
+local require = require
+
+module(...)
+
+local dis_x86 = require(_PACKAGE.."dis_x86")
+
+create = dis_x86.create64
+disass = dis_x86.disass64
+regname = dis_x86.regname64
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/jit/dis_x86.lua b/src/3rdparty/LuaJIT-2.0.5/src/jit/dis_x86.lua
new file mode 100644
index 0000000..74d0f52
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/jit/dis_x86.lua
@@ -0,0 +1,836 @@
+----------------------------------------------------------------------------
+-- LuaJIT x86/x64 disassembler module.
+--
+-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+-- Released under the MIT license. See Copyright Notice in luajit.h
+----------------------------------------------------------------------------
+-- This is a helper module used by the LuaJIT machine code dumper module.
+--
+-- Sending small code snippets to an external disassembler and mixing the
+-- output with our own stuff was too fragile. So I had to bite the bullet
+-- and write yet another x86 disassembler. Oh well ...
+--
+-- The output format is very similar to what ndisasm generates. But it has
+-- been developed independently by looking at the opcode tables from the
+-- Intel and AMD manuals. The supported instruction set is quite extensive
+-- and reflects what a current generation Intel or AMD CPU implements in
+-- 32 bit and 64 bit mode. Yes, this includes MMX, SSE, SSE2, SSE3, SSSE3,
+-- SSE4.1, SSE4.2, SSE4a and even privileged and hypervisor (VMX/SVM)
+-- instructions.
+--
+-- Notes:
+-- * The (useless) a16 prefix, 3DNow and pre-586 opcodes are unsupported.
+-- * No attempt at optimization has been made -- it's fast enough for my needs.
+-- * The public API may change when more architectures are added.
+------------------------------------------------------------------------------
+
+local type = type
+local sub, byte, format = string.sub, string.byte, string.format
+local match, gmatch, gsub = string.match, string.gmatch, string.gsub
+local lower, rep = string.lower, string.rep
+
+-- Map for 1st opcode byte in 32 bit mode. Ugly? Well ... read on.
+local map_opc1_32 = {
+--0x
+[0]="addBmr","addVmr","addBrm","addVrm","addBai","addVai","push es","pop es",
+"orBmr","orVmr","orBrm","orVrm","orBai","orVai","push cs","opc2*",
+--1x
+"adcBmr","adcVmr","adcBrm","adcVrm","adcBai","adcVai","push ss","pop ss",
+"sbbBmr","sbbVmr","sbbBrm","sbbVrm","sbbBai","sbbVai","push ds","pop ds",
+--2x
+"andBmr","andVmr","andBrm","andVrm","andBai","andVai","es:seg","daa",
+"subBmr","subVmr","subBrm","subVrm","subBai","subVai","cs:seg","das",
+--3x
+"xorBmr","xorVmr","xorBrm","xorVrm","xorBai","xorVai","ss:seg","aaa",
+"cmpBmr","cmpVmr","cmpBrm","cmpVrm","cmpBai","cmpVai","ds:seg","aas",
+--4x
+"incVR","incVR","incVR","incVR","incVR","incVR","incVR","incVR",
+"decVR","decVR","decVR","decVR","decVR","decVR","decVR","decVR",
+--5x
+"pushUR","pushUR","pushUR","pushUR","pushUR","pushUR","pushUR","pushUR",
+"popUR","popUR","popUR","popUR","popUR","popUR","popUR","popUR",
+--6x
+"sz*pushaw,pusha","sz*popaw,popa","boundVrm","arplWmr",
+"fs:seg","gs:seg","o16:","a16",
+"pushUi","imulVrmi","pushBs","imulVrms",
+"insb","insVS","outsb","outsVS",
+--7x
+"joBj","jnoBj","jbBj","jnbBj","jzBj","jnzBj","jbeBj","jaBj",
+"jsBj","jnsBj","jpeBj","jpoBj","jlBj","jgeBj","jleBj","jgBj",
+--8x
+"arith!Bmi","arith!Vmi","arith!Bmi","arith!Vms",
+"testBmr","testVmr","xchgBrm","xchgVrm",
+"movBmr","movVmr","movBrm","movVrm",
+"movVmg","leaVrm","movWgm","popUm",
+--9x
+"nop*xchgVaR|pause|xchgWaR|repne nop","xchgVaR","xchgVaR","xchgVaR",
+"xchgVaR","xchgVaR","xchgVaR","xchgVaR",
+"sz*cbw,cwde,cdqe","sz*cwd,cdq,cqo","call farViw","wait",
+"sz*pushfw,pushf","sz*popfw,popf","sahf","lahf",
+--Ax
+"movBao","movVao","movBoa","movVoa",
+"movsb","movsVS","cmpsb","cmpsVS",
+"testBai","testVai","stosb","stosVS",
+"lodsb","lodsVS","scasb","scasVS",
+--Bx
+"movBRi","movBRi","movBRi","movBRi","movBRi","movBRi","movBRi","movBRi",
+"movVRI","movVRI","movVRI","movVRI","movVRI","movVRI","movVRI","movVRI",
+--Cx
+"shift!Bmu","shift!Vmu","retBw","ret","$lesVrm","$ldsVrm","movBmi","movVmi",
+"enterBwu","leave","retfBw","retf","int3","intBu","into","iretVS",
+--Dx
+"shift!Bm1","shift!Vm1","shift!Bmc","shift!Vmc","aamBu","aadBu","salc","xlatb",
+"fp*0","fp*1","fp*2","fp*3","fp*4","fp*5","fp*6","fp*7",
+--Ex
+"loopneBj","loopeBj","loopBj","sz*jcxzBj,jecxzBj,jrcxzBj",
+"inBau","inVau","outBua","outVua",
+"callVj","jmpVj","jmp farViw","jmpBj","inBad","inVad","outBda","outVda",
+--Fx
+"lock:","int1","repne:rep","rep:","hlt","cmc","testb!Bm","testv!Vm",
+"clc","stc","cli","sti","cld","std","incb!Bm","incd!Vm",
+}
+assert(#map_opc1_32 == 255)
+
+-- Map for 1st opcode byte in 64 bit mode (overrides only).
+local map_opc1_64 = setmetatable({
+ [0x06]=false, [0x07]=false, [0x0e]=false,
+ [0x16]=false, [0x17]=false, [0x1e]=false, [0x1f]=false,
+ [0x27]=false, [0x2f]=false, [0x37]=false, [0x3f]=false,
+ [0x60]=false, [0x61]=false, [0x62]=false, [0x63]="movsxdVrDmt", [0x67]="a32:",
+ [0x40]="rex*", [0x41]="rex*b", [0x42]="rex*x", [0x43]="rex*xb",
+ [0x44]="rex*r", [0x45]="rex*rb", [0x46]="rex*rx", [0x47]="rex*rxb",
+ [0x48]="rex*w", [0x49]="rex*wb", [0x4a]="rex*wx", [0x4b]="rex*wxb",
+ [0x4c]="rex*wr", [0x4d]="rex*wrb", [0x4e]="rex*wrx", [0x4f]="rex*wrxb",
+ [0x82]=false, [0x9a]=false, [0xc4]=false, [0xc5]=false, [0xce]=false,
+ [0xd4]=false, [0xd5]=false, [0xd6]=false, [0xea]=false,
+}, { __index = map_opc1_32 })
+
+-- Map for 2nd opcode byte (0F xx). True CISC hell. Hey, I told you.
+-- Prefix dependent MMX/SSE opcodes: (none)|rep|o16|repne, -|F3|66|F2
+local map_opc2 = {
+--0x
+[0]="sldt!Dmp","sgdt!Ump","larVrm","lslVrm",nil,"syscall","clts","sysret",
+"invd","wbinvd",nil,"ud1",nil,"$prefetch!Bm","femms","3dnowMrmu",
+--1x
+"movupsXrm|movssXrm|movupdXrm|movsdXrm",
+"movupsXmr|movssXmr|movupdXmr|movsdXmr",
+"movhlpsXrm$movlpsXrm|movsldupXrm|movlpdXrm|movddupXrm",
+"movlpsXmr||movlpdXmr",
+"unpcklpsXrm||unpcklpdXrm",
+"unpckhpsXrm||unpckhpdXrm",
+"movlhpsXrm$movhpsXrm|movshdupXrm|movhpdXrm",
+"movhpsXmr||movhpdXmr",
+"$prefetcht!Bm","hintnopVm","hintnopVm","hintnopVm",
+"hintnopVm","hintnopVm","hintnopVm","hintnopVm",
+--2x
+"movUmx$","movUmy$","movUxm$","movUym$","movUmz$",nil,"movUzm$",nil,
+"movapsXrm||movapdXrm",
+"movapsXmr||movapdXmr",
+"cvtpi2psXrMm|cvtsi2ssXrVmt|cvtpi2pdXrMm|cvtsi2sdXrVmt",
+"movntpsXmr|movntssXmr|movntpdXmr|movntsdXmr",
+"cvttps2piMrXm|cvttss2siVrXm|cvttpd2piMrXm|cvttsd2siVrXm",
+"cvtps2piMrXm|cvtss2siVrXm|cvtpd2piMrXm|cvtsd2siVrXm",
+"ucomissXrm||ucomisdXrm",
+"comissXrm||comisdXrm",
+--3x
+"wrmsr","rdtsc","rdmsr","rdpmc","sysenter","sysexit",nil,"getsec",
+"opc3*38",nil,"opc3*3a",nil,nil,nil,nil,nil,
+--4x
+"cmovoVrm","cmovnoVrm","cmovbVrm","cmovnbVrm",
+"cmovzVrm","cmovnzVrm","cmovbeVrm","cmovaVrm",
+"cmovsVrm","cmovnsVrm","cmovpeVrm","cmovpoVrm",
+"cmovlVrm","cmovgeVrm","cmovleVrm","cmovgVrm",
+--5x
+"movmskpsVrXm$||movmskpdVrXm$","sqrtpsXrm|sqrtssXrm|sqrtpdXrm|sqrtsdXrm",
+"rsqrtpsXrm|rsqrtssXrm","rcppsXrm|rcpssXrm",
+"andpsXrm||andpdXrm","andnpsXrm||andnpdXrm",
+"orpsXrm||orpdXrm","xorpsXrm||xorpdXrm",
+"addpsXrm|addssXrm|addpdXrm|addsdXrm","mulpsXrm|mulssXrm|mulpdXrm|mulsdXrm",
+"cvtps2pdXrm|cvtss2sdXrm|cvtpd2psXrm|cvtsd2ssXrm",
+"cvtdq2psXrm|cvttps2dqXrm|cvtps2dqXrm",
+"subpsXrm|subssXrm|subpdXrm|subsdXrm","minpsXrm|minssXrm|minpdXrm|minsdXrm",
+"divpsXrm|divssXrm|divpdXrm|divsdXrm","maxpsXrm|maxssXrm|maxpdXrm|maxsdXrm",
+--6x
+"punpcklbwPrm","punpcklwdPrm","punpckldqPrm","packsswbPrm",
+"pcmpgtbPrm","pcmpgtwPrm","pcmpgtdPrm","packuswbPrm",
+"punpckhbwPrm","punpckhwdPrm","punpckhdqPrm","packssdwPrm",
+"||punpcklqdqXrm","||punpckhqdqXrm",
+"movPrVSm","movqMrm|movdquXrm|movdqaXrm",
+--7x
+"pshufwMrmu|pshufhwXrmu|pshufdXrmu|pshuflwXrmu","pshiftw!Pmu",
+"pshiftd!Pmu","pshiftq!Mmu||pshiftdq!Xmu",
+"pcmpeqbPrm","pcmpeqwPrm","pcmpeqdPrm","emms|",
+"vmreadUmr||extrqXmuu$|insertqXrmuu$","vmwriteUrm||extrqXrm$|insertqXrm$",
+nil,nil,
+"||haddpdXrm|haddpsXrm","||hsubpdXrm|hsubpsXrm",
+"movVSmMr|movqXrm|movVSmXr","movqMmr|movdquXmr|movdqaXmr",
+--8x
+"joVj","jnoVj","jbVj","jnbVj","jzVj","jnzVj","jbeVj","jaVj",
+"jsVj","jnsVj","jpeVj","jpoVj","jlVj","jgeVj","jleVj","jgVj",
+--9x
+"setoBm","setnoBm","setbBm","setnbBm","setzBm","setnzBm","setbeBm","setaBm",
+"setsBm","setnsBm","setpeBm","setpoBm","setlBm","setgeBm","setleBm","setgBm",
+--Ax
+"push fs","pop fs","cpuid","btVmr","shldVmru","shldVmrc",nil,nil,
+"push gs","pop gs","rsm","btsVmr","shrdVmru","shrdVmrc","fxsave!Dmp","imulVrm",
+--Bx
+"cmpxchgBmr","cmpxchgVmr","$lssVrm","btrVmr",
+"$lfsVrm","$lgsVrm","movzxVrBmt","movzxVrWmt",
+"|popcntVrm","ud2Dp","bt!Vmu","btcVmr",
+"bsfVrm","bsrVrm|lzcntVrm|bsrWrm","movsxVrBmt","movsxVrWmt",
+--Cx
+"xaddBmr","xaddVmr",
+"cmppsXrmu|cmpssXrmu|cmppdXrmu|cmpsdXrmu","$movntiVmr|",
+"pinsrwPrWmu","pextrwDrPmu",
+"shufpsXrmu||shufpdXrmu","$cmpxchg!Qmp",
+"bswapVR","bswapVR","bswapVR","bswapVR","bswapVR","bswapVR","bswapVR","bswapVR",
+--Dx
+"||addsubpdXrm|addsubpsXrm","psrlwPrm","psrldPrm","psrlqPrm",
+"paddqPrm","pmullwPrm",
+"|movq2dqXrMm|movqXmr|movdq2qMrXm$","pmovmskbVrMm||pmovmskbVrXm",
+"psubusbPrm","psubuswPrm","pminubPrm","pandPrm",
+"paddusbPrm","padduswPrm","pmaxubPrm","pandnPrm",
+--Ex
+"pavgbPrm","psrawPrm","psradPrm","pavgwPrm",
+"pmulhuwPrm","pmulhwPrm",
+"|cvtdq2pdXrm|cvttpd2dqXrm|cvtpd2dqXrm","$movntqMmr||$movntdqXmr",
+"psubsbPrm","psubswPrm","pminswPrm","porPrm",
+"paddsbPrm","paddswPrm","pmaxswPrm","pxorPrm",
+--Fx
+"|||lddquXrm","psllwPrm","pslldPrm","psllqPrm",
+"pmuludqPrm","pmaddwdPrm","psadbwPrm","maskmovqMrm||maskmovdquXrm$",
+"psubbPrm","psubwPrm","psubdPrm","psubqPrm",
+"paddbPrm","paddwPrm","padddPrm","ud",
+}
+assert(map_opc2[255] == "ud")
+
+-- Map for three-byte opcodes. Can't wait for their next invention.
+local map_opc3 = {
+["38"] = { -- [66] 0f 38 xx
+--0x
+[0]="pshufbPrm","phaddwPrm","phadddPrm","phaddswPrm",
+"pmaddubswPrm","phsubwPrm","phsubdPrm","phsubswPrm",
+"psignbPrm","psignwPrm","psigndPrm","pmulhrswPrm",
+nil,nil,nil,nil,
+--1x
+"||pblendvbXrma",nil,nil,nil,
+"||blendvpsXrma","||blendvpdXrma",nil,"||ptestXrm",
+nil,nil,nil,nil,
+"pabsbPrm","pabswPrm","pabsdPrm",nil,
+--2x
+"||pmovsxbwXrm","||pmovsxbdXrm","||pmovsxbqXrm","||pmovsxwdXrm",
+"||pmovsxwqXrm","||pmovsxdqXrm",nil,nil,
+"||pmuldqXrm","||pcmpeqqXrm","||$movntdqaXrm","||packusdwXrm",
+nil,nil,nil,nil,
+--3x
+"||pmovzxbwXrm","||pmovzxbdXrm","||pmovzxbqXrm","||pmovzxwdXrm",
+"||pmovzxwqXrm","||pmovzxdqXrm",nil,"||pcmpgtqXrm",
+"||pminsbXrm","||pminsdXrm","||pminuwXrm","||pminudXrm",
+"||pmaxsbXrm","||pmaxsdXrm","||pmaxuwXrm","||pmaxudXrm",
+--4x
+"||pmulddXrm","||phminposuwXrm",
+--Fx
+[0xf0] = "|||crc32TrBmt",[0xf1] = "|||crc32TrVmt",
+},
+
+["3a"] = { -- [66] 0f 3a xx
+--0x
+[0x00]=nil,nil,nil,nil,nil,nil,nil,nil,
+"||roundpsXrmu","||roundpdXrmu","||roundssXrmu","||roundsdXrmu",
+"||blendpsXrmu","||blendpdXrmu","||pblendwXrmu","palignrPrmu",
+--1x
+nil,nil,nil,nil,
+"||pextrbVmXru","||pextrwVmXru","||pextrVmSXru","||extractpsVmXru",
+nil,nil,nil,nil,nil,nil,nil,nil,
+--2x
+"||pinsrbXrVmu","||insertpsXrmu","||pinsrXrVmuS",nil,
+--4x
+[0x40] = "||dppsXrmu",
+[0x41] = "||dppdXrmu",
+[0x42] = "||mpsadbwXrmu",
+--6x
+[0x60] = "||pcmpestrmXrmu",[0x61] = "||pcmpestriXrmu",
+[0x62] = "||pcmpistrmXrmu",[0x63] = "||pcmpistriXrmu",
+},
+}
+
+-- Map for VMX/SVM opcodes 0F 01 C0-FF (sgdt group with register operands).
+local map_opcvm = {
+[0xc1]="vmcall",[0xc2]="vmlaunch",[0xc3]="vmresume",[0xc4]="vmxoff",
+[0xc8]="monitor",[0xc9]="mwait",
+[0xd8]="vmrun",[0xd9]="vmmcall",[0xda]="vmload",[0xdb]="vmsave",
+[0xdc]="stgi",[0xdd]="clgi",[0xde]="skinit",[0xdf]="invlpga",
+[0xf8]="swapgs",[0xf9]="rdtscp",
+}
+
+-- Map for FP opcodes. And you thought stack machines are simple?
+local map_opcfp = {
+-- D8-DF 00-BF: opcodes with a memory operand.
+-- D8
+[0]="faddFm","fmulFm","fcomFm","fcompFm","fsubFm","fsubrFm","fdivFm","fdivrFm",
+"fldFm",nil,"fstFm","fstpFm","fldenvVm","fldcwWm","fnstenvVm","fnstcwWm",
+-- DA
+"fiaddDm","fimulDm","ficomDm","ficompDm",
+"fisubDm","fisubrDm","fidivDm","fidivrDm",
+-- DB
+"fildDm","fisttpDm","fistDm","fistpDm",nil,"fld twordFmp",nil,"fstp twordFmp",
+-- DC
+"faddGm","fmulGm","fcomGm","fcompGm","fsubGm","fsubrGm","fdivGm","fdivrGm",
+-- DD
+"fldGm","fisttpQm","fstGm","fstpGm","frstorDmp",nil,"fnsaveDmp","fnstswWm",
+-- DE
+"fiaddWm","fimulWm","ficomWm","ficompWm",
+"fisubWm","fisubrWm","fidivWm","fidivrWm",
+-- DF
+"fildWm","fisttpWm","fistWm","fistpWm",
+"fbld twordFmp","fildQm","fbstp twordFmp","fistpQm",
+-- xx C0-FF: opcodes with a pseudo-register operand.
+-- D8
+"faddFf","fmulFf","fcomFf","fcompFf","fsubFf","fsubrFf","fdivFf","fdivrFf",
+-- D9
+"fldFf","fxchFf",{"fnop"},nil,
+{"fchs","fabs",nil,nil,"ftst","fxam"},
+{"fld1","fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz"},
+{"f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp","fincstp"},
+{"fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos"},
+-- DA
+"fcmovbFf","fcmoveFf","fcmovbeFf","fcmovuFf",nil,{nil,"fucompp"},nil,nil,
+-- DB
+"fcmovnbFf","fcmovneFf","fcmovnbeFf","fcmovnuFf",
+{nil,nil,"fnclex","fninit"},"fucomiFf","fcomiFf",nil,
+-- DC
+"fadd toFf","fmul toFf",nil,nil,
+"fsub toFf","fsubr toFf","fdivr toFf","fdiv toFf",
+-- DD
+"ffreeFf",nil,"fstFf","fstpFf","fucomFf","fucompFf",nil,nil,
+-- DE
+"faddpFf","fmulpFf",nil,{nil,"fcompp"},
+"fsubrpFf","fsubpFf","fdivrpFf","fdivpFf",
+-- DF
+nil,nil,nil,nil,{"fnstsw ax"},"fucomipFf","fcomipFf",nil,
+}
+assert(map_opcfp[126] == "fcomipFf")
+
+-- Map for opcode groups. The subkey is sp from the ModRM byte.
+local map_opcgroup = {
+ arith = { "add", "or", "adc", "sbb", "and", "sub", "xor", "cmp" },
+ shift = { "rol", "ror", "rcl", "rcr", "shl", "shr", "sal", "sar" },
+ testb = { "testBmi", "testBmi", "not", "neg", "mul", "imul", "div", "idiv" },
+ testv = { "testVmi", "testVmi", "not", "neg", "mul", "imul", "div", "idiv" },
+ incb = { "inc", "dec" },
+ incd = { "inc", "dec", "callUmp", "$call farDmp",
+ "jmpUmp", "$jmp farDmp", "pushUm" },
+ sldt = { "sldt", "str", "lldt", "ltr", "verr", "verw" },
+ sgdt = { "vm*$sgdt", "vm*$sidt", "$lgdt", "vm*$lidt",
+ "smsw", nil, "lmsw", "vm*$invlpg" },
+ bt = { nil, nil, nil, nil, "bt", "bts", "btr", "btc" },
+ cmpxchg = { nil, "sz*,cmpxchg8bQmp,cmpxchg16bXmp", nil, nil,
+ nil, nil, "vmptrld|vmxon|vmclear", "vmptrst" },
+ pshiftw = { nil, nil, "psrlw", nil, "psraw", nil, "psllw" },
+ pshiftd = { nil, nil, "psrld", nil, "psrad", nil, "pslld" },
+ pshiftq = { nil, nil, "psrlq", nil, nil, nil, "psllq" },
+ pshiftdq = { nil, nil, "psrlq", "psrldq", nil, nil, "psllq", "pslldq" },
+ fxsave = { "$fxsave", "$fxrstor", "$ldmxcsr", "$stmxcsr",
+ nil, "lfenceDp$", "mfenceDp$", "sfenceDp$clflush" },
+ prefetch = { "prefetch", "prefetchw" },
+ prefetcht = { "prefetchnta", "prefetcht0", "prefetcht1", "prefetcht2" },
+}
+
+------------------------------------------------------------------------------
+
+-- Maps for register names.
+local map_regs = {
+ B = { "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh",
+ "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b" },
+ B64 = { "al", "cl", "dl", "bl", "spl", "bpl", "sil", "dil",
+ "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b" },
+ W = { "ax", "cx", "dx", "bx", "sp", "bp", "si", "di",
+ "r8w", "r9w", "r10w", "r11w", "r12w", "r13w", "r14w", "r15w" },
+ D = { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
+ "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d" },
+ Q = { "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
+ "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" },
+ M = { "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7",
+ "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7" }, -- No x64 ext!
+ X = { "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
+ "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15" },
+}
+local map_segregs = { "es", "cs", "ss", "ds", "fs", "gs", "segr6", "segr7" }
+
+-- Maps for size names.
+local map_sz2n = {
+ B = 1, W = 2, D = 4, Q = 8, M = 8, X = 16,
+}
+local map_sz2prefix = {
+ B = "byte", W = "word", D = "dword",
+ Q = "qword",
+ M = "qword", X = "xword",
+ F = "dword", G = "qword", -- No need for sizes/register names for these two.
+}
+
+------------------------------------------------------------------------------
+
+-- Output a nicely formatted line with an opcode and operands.
+local function putop(ctx, text, operands)
+ local code, pos, hex = ctx.code, ctx.pos, ""
+ local hmax = ctx.hexdump
+ if hmax > 0 then
+ for i=ctx.start,pos-1 do
+ hex = hex..format("%02X", byte(code, i, i))
+ end
+ if #hex > hmax then hex = sub(hex, 1, hmax)..". "
+ else hex = hex..rep(" ", hmax-#hex+2) end
+ end
+ if operands then text = text.." "..operands end
+ if ctx.o16 then text = "o16 "..text; ctx.o16 = false end
+ if ctx.a32 then text = "a32 "..text; ctx.a32 = false end
+ if ctx.rep then text = ctx.rep.." "..text; ctx.rep = false end
+ if ctx.rex then
+ local t = (ctx.rexw and "w" or "")..(ctx.rexr and "r" or "")..
+ (ctx.rexx and "x" or "")..(ctx.rexb and "b" or "")
+ if t ~= "" then text = "rex."..t.." "..text end
+ ctx.rexw = false; ctx.rexr = false; ctx.rexx = false; ctx.rexb = false
+ ctx.rex = false
+ end
+ if ctx.seg then
+ local text2, n = gsub(text, "%[", "["..ctx.seg..":")
+ if n == 0 then text = ctx.seg.." "..text else text = text2 end
+ ctx.seg = false
+ end
+ if ctx.lock then text = "lock "..text; ctx.lock = false end
+ local imm = ctx.imm
+ if imm then
+ local sym = ctx.symtab[imm]
+ if sym then text = text.."\t->"..sym end
+ end
+ ctx.out(format("%08x %s%s\n", ctx.addr+ctx.start, hex, text))
+ ctx.mrm = false
+ ctx.start = pos
+ ctx.imm = nil
+end
+
+-- Clear all prefix flags.
+local function clearprefixes(ctx)
+ ctx.o16 = false; ctx.seg = false; ctx.lock = false; ctx.rep = false
+ ctx.rexw = false; ctx.rexr = false; ctx.rexx = false; ctx.rexb = false
+ ctx.rex = false; ctx.a32 = false
+end
+
+-- Fallback for incomplete opcodes at the end.
+local function incomplete(ctx)
+ ctx.pos = ctx.stop+1
+ clearprefixes(ctx)
+ return putop(ctx, "(incomplete)")
+end
+
+-- Fallback for unknown opcodes.
+local function unknown(ctx)
+ clearprefixes(ctx)
+ return putop(ctx, "(unknown)")
+end
+
+-- Return an immediate of the specified size.
+local function getimm(ctx, pos, n)
+ if pos+n-1 > ctx.stop then return incomplete(ctx) end
+ local code = ctx.code
+ if n == 1 then
+ local b1 = byte(code, pos, pos)
+ return b1
+ elseif n == 2 then
+ local b1, b2 = byte(code, pos, pos+1)
+ return b1+b2*256
+ else
+ local b1, b2, b3, b4 = byte(code, pos, pos+3)
+ local imm = b1+b2*256+b3*65536+b4*16777216
+ ctx.imm = imm
+ return imm
+ end
+end
+
+-- Process pattern string and generate the operands.
+local function putpat(ctx, name, pat)
+ local operands, regs, sz, mode, sp, rm, sc, rx, sdisp
+ local code, pos, stop = ctx.code, ctx.pos, ctx.stop
+
+ -- Chars used: 1DFGIMPQRSTUVWXacdfgijmoprstuwxyz
+ for p in gmatch(pat, ".") do
+ local x = nil
+ if p == "V" or p == "U" then
+ if ctx.rexw then sz = "Q"; ctx.rexw = false
+ elseif ctx.o16 then sz = "W"; ctx.o16 = false
+ elseif p == "U" and ctx.x64 then sz = "Q"
+ else sz = "D" end
+ regs = map_regs[sz]
+ elseif p == "T" then
+ if ctx.rexw then sz = "Q"; ctx.rexw = false else sz = "D" end
+ regs = map_regs[sz]
+ elseif p == "B" then
+ sz = "B"
+ regs = ctx.rex and map_regs.B64 or map_regs.B
+ elseif match(p, "[WDQMXFG]") then
+ sz = p
+ regs = map_regs[sz]
+ elseif p == "P" then
+ sz = ctx.o16 and "X" or "M"; ctx.o16 = false
+ regs = map_regs[sz]
+ elseif p == "S" then
+ name = name..lower(sz)
+ elseif p == "s" then
+ local imm = getimm(ctx, pos, 1); if not imm then return end
+ x = imm <= 127 and format("+0x%02x", imm)
+ or format("-0x%02x", 256-imm)
+ pos = pos+1
+ elseif p == "u" then
+ local imm = getimm(ctx, pos, 1); if not imm then return end
+ x = format("0x%02x", imm)
+ pos = pos+1
+ elseif p == "w" then
+ local imm = getimm(ctx, pos, 2); if not imm then return end
+ x = format("0x%x", imm)
+ pos = pos+2
+ elseif p == "o" then -- [offset]
+ if ctx.x64 then
+ local imm1 = getimm(ctx, pos, 4); if not imm1 then return end
+ local imm2 = getimm(ctx, pos+4, 4); if not imm2 then return end
+ x = format("[0x%08x%08x]", imm2, imm1)
+ pos = pos+8
+ else
+ local imm = getimm(ctx, pos, 4); if not imm then return end
+ x = format("[0x%08x]", imm)
+ pos = pos+4
+ end
+ elseif p == "i" or p == "I" then
+ local n = map_sz2n[sz]
+ if n == 8 and ctx.x64 and p == "I" then
+ local imm1 = getimm(ctx, pos, 4); if not imm1 then return end
+ local imm2 = getimm(ctx, pos+4, 4); if not imm2 then return end
+ x = format("0x%08x%08x", imm2, imm1)
+ else
+ if n == 8 then n = 4 end
+ local imm = getimm(ctx, pos, n); if not imm then return end
+ if sz == "Q" and (imm < 0 or imm > 0x7fffffff) then
+ imm = (0xffffffff+1)-imm
+ x = format(imm > 65535 and "-0x%08x" or "-0x%x", imm)
+ else
+ x = format(imm > 65535 and "0x%08x" or "0x%x", imm)
+ end
+ end
+ pos = pos+n
+ elseif p == "j" then
+ local n = map_sz2n[sz]
+ if n == 8 then n = 4 end
+ local imm = getimm(ctx, pos, n); if not imm then return end
+ if sz == "B" and imm > 127 then imm = imm-256
+ elseif imm > 2147483647 then imm = imm-4294967296 end
+ pos = pos+n
+ imm = imm + pos + ctx.addr
+ if imm > 4294967295 and not ctx.x64 then imm = imm-4294967296 end
+ ctx.imm = imm
+ if sz == "W" then
+ x = format("word 0x%04x", imm%65536)
+ elseif ctx.x64 then
+ local lo = imm % 0x1000000
+ x = format("0x%02x%06x", (imm-lo) / 0x1000000, lo)
+ else
+ x = format("0x%08x", imm)
+ end
+ elseif p == "R" then
+ local r = byte(code, pos-1, pos-1)%8
+ if ctx.rexb then r = r + 8; ctx.rexb = false end
+ x = regs[r+1]
+ elseif p == "a" then x = regs[1]
+ elseif p == "c" then x = "cl"
+ elseif p == "d" then x = "dx"
+ elseif p == "1" then x = "1"
+ else
+ if not mode then
+ mode = ctx.mrm
+ if not mode then
+ if pos > stop then return incomplete(ctx) end
+ mode = byte(code, pos, pos)
+ pos = pos+1
+ end
+ rm = mode%8; mode = (mode-rm)/8
+ sp = mode%8; mode = (mode-sp)/8
+ sdisp = ""
+ if mode < 3 then
+ if rm == 4 then
+ if pos > stop then return incomplete(ctx) end
+ sc = byte(code, pos, pos)
+ pos = pos+1
+ rm = sc%8; sc = (sc-rm)/8
+ rx = sc%8; sc = (sc-rx)/8
+ if ctx.rexx then rx = rx + 8; ctx.rexx = false end
+ if rx == 4 then rx = nil end
+ end
+ if mode > 0 or rm == 5 then
+ local dsz = mode
+ if dsz ~= 1 then dsz = 4 end
+ local disp = getimm(ctx, pos, dsz); if not disp then return end
+ if mode == 0 then rm = nil end
+ if rm or rx or (not sc and ctx.x64 and not ctx.a32) then
+ if dsz == 1 and disp > 127 then
+ sdisp = format("-0x%x", 256-disp)
+ elseif disp >= 0 and disp <= 0x7fffffff then
+ sdisp = format("+0x%x", disp)
+ else
+ sdisp = format("-0x%x", (0xffffffff+1)-disp)
+ end
+ else
+ sdisp = format(ctx.x64 and not ctx.a32 and
+ not (disp >= 0 and disp <= 0x7fffffff)
+ and "0xffffffff%08x" or "0x%08x", disp)
+ end
+ pos = pos+dsz
+ end
+ end
+ if rm and ctx.rexb then rm = rm + 8; ctx.rexb = false end
+ if ctx.rexr then sp = sp + 8; ctx.rexr = false end
+ end
+ if p == "m" then
+ if mode == 3 then x = regs[rm+1]
+ else
+ local aregs = ctx.a32 and map_regs.D or ctx.aregs
+ local srm, srx = "", ""
+ if rm then srm = aregs[rm+1]
+ elseif not sc and ctx.x64 and not ctx.a32 then srm = "rip" end
+ ctx.a32 = false
+ if rx then
+ if rm then srm = srm.."+" end
+ srx = aregs[rx+1]
+ if sc > 0 then srx = srx.."*"..(2^sc) end
+ end
+ x = format("[%s%s%s]", srm, srx, sdisp)
+ end
+ if mode < 3 and
+ (not match(pat, "[aRrgp]") or match(pat, "t")) then -- Yuck.
+ x = map_sz2prefix[sz].." "..x
+ end
+ elseif p == "r" then x = regs[sp+1]
+ elseif p == "g" then x = map_segregs[sp+1]
+ elseif p == "p" then -- Suppress prefix.
+ elseif p == "f" then x = "st"..rm
+ elseif p == "x" then
+ if sp == 0 and ctx.lock and not ctx.x64 then
+ x = "CR8"; ctx.lock = false
+ else
+ x = "CR"..sp
+ end
+ elseif p == "y" then x = "DR"..sp
+ elseif p == "z" then x = "TR"..sp
+ elseif p == "t" then
+ else
+ error("bad pattern `"..pat.."'")
+ end
+ end
+ if x then operands = operands and operands..", "..x or x end
+ end
+ ctx.pos = pos
+ return putop(ctx, name, operands)
+end
+
+-- Forward declaration.
+local map_act
+
+-- Fetch and cache MRM byte.
+local function getmrm(ctx)
+ local mrm = ctx.mrm
+ if not mrm then
+ local pos = ctx.pos
+ if pos > ctx.stop then return nil end
+ mrm = byte(ctx.code, pos, pos)
+ ctx.pos = pos+1
+ ctx.mrm = mrm
+ end
+ return mrm
+end
+
+-- Dispatch to handler depending on pattern.
+local function dispatch(ctx, opat, patgrp)
+ if not opat then return unknown(ctx) end
+ if match(opat, "%|") then -- MMX/SSE variants depending on prefix.
+ local p
+ if ctx.rep then
+ p = ctx.rep=="rep" and "%|([^%|]*)" or "%|[^%|]*%|[^%|]*%|([^%|]*)"
+ ctx.rep = false
+ elseif ctx.o16 then p = "%|[^%|]*%|([^%|]*)"; ctx.o16 = false
+ else p = "^[^%|]*" end
+ opat = match(opat, p)
+ if not opat then return unknown(ctx) end
+-- ctx.rep = false; ctx.o16 = false
+ --XXX fails for 66 f2 0f 38 f1 06 crc32 eax,WORD PTR [esi]
+ --XXX remove in branches?
+ end
+ if match(opat, "%$") then -- reg$mem variants.
+ local mrm = getmrm(ctx); if not mrm then return incomplete(ctx) end
+ opat = match(opat, mrm >= 192 and "^[^%$]*" or "%$(.*)")
+ if opat == "" then return unknown(ctx) end
+ end
+ if opat == "" then return unknown(ctx) end
+ local name, pat = match(opat, "^([a-z0-9 ]*)(.*)")
+ if pat == "" and patgrp then pat = patgrp end
+ return map_act[sub(pat, 1, 1)](ctx, name, pat)
+end
+
+-- Get a pattern from an opcode map and dispatch to handler.
+local function dispatchmap(ctx, opcmap)
+ local pos = ctx.pos
+ local opat = opcmap[byte(ctx.code, pos, pos)]
+ pos = pos + 1
+ ctx.pos = pos
+ return dispatch(ctx, opat)
+end
+
+-- Map for action codes. The key is the first char after the name.
+map_act = {
+ -- Simple opcodes without operands.
+ [""] = function(ctx, name, pat)
+ return putop(ctx, name)
+ end,
+
+ -- Operand size chars fall right through.
+ B = putpat, W = putpat, D = putpat, Q = putpat,
+ V = putpat, U = putpat, T = putpat,
+ M = putpat, X = putpat, P = putpat,
+ F = putpat, G = putpat,
+
+ -- Collect prefixes.
+ [":"] = function(ctx, name, pat)
+ ctx[pat == ":" and name or sub(pat, 2)] = name
+ if ctx.pos - ctx.start > 5 then return unknown(ctx) end -- Limit #prefixes.
+ end,
+
+ -- Chain to special handler specified by name.
+ ["*"] = function(ctx, name, pat)
+ return map_act[name](ctx, name, sub(pat, 2))
+ end,
+
+ -- Use named subtable for opcode group.
+ ["!"] = function(ctx, name, pat)
+ local mrm = getmrm(ctx); if not mrm then return incomplete(ctx) end
+ return dispatch(ctx, map_opcgroup[name][((mrm-(mrm%8))/8)%8+1], sub(pat, 2))
+ end,
+
+ -- o16,o32[,o64] variants.
+ sz = function(ctx, name, pat)
+ if ctx.o16 then ctx.o16 = false
+ else
+ pat = match(pat, ",(.*)")
+ if ctx.rexw then
+ local p = match(pat, ",(.*)")
+ if p then pat = p; ctx.rexw = false end
+ end
+ end
+ pat = match(pat, "^[^,]*")
+ return dispatch(ctx, pat)
+ end,
+
+ -- Two-byte opcode dispatch.
+ opc2 = function(ctx, name, pat)
+ return dispatchmap(ctx, map_opc2)
+ end,
+
+ -- Three-byte opcode dispatch.
+ opc3 = function(ctx, name, pat)
+ return dispatchmap(ctx, map_opc3[pat])
+ end,
+
+ -- VMX/SVM dispatch.
+ vm = function(ctx, name, pat)
+ return dispatch(ctx, map_opcvm[ctx.mrm])
+ end,
+
+ -- Floating point opcode dispatch.
+ fp = function(ctx, name, pat)
+ local mrm = getmrm(ctx); if not mrm then return incomplete(ctx) end
+ local rm = mrm%8
+ local idx = pat*8 + ((mrm-rm)/8)%8
+ if mrm >= 192 then idx = idx + 64 end
+ local opat = map_opcfp[idx]
+ if type(opat) == "table" then opat = opat[rm+1] end
+ return dispatch(ctx, opat)
+ end,
+
+ -- REX prefix.
+ rex = function(ctx, name, pat)
+ if ctx.rex then return unknown(ctx) end -- Only 1 REX prefix allowed.
+ for p in gmatch(pat, ".") do ctx["rex"..p] = true end
+ ctx.rex = true
+ end,
+
+ -- Special case for nop with REX prefix.
+ nop = function(ctx, name, pat)
+ return dispatch(ctx, ctx.rex and pat or "nop")
+ end,
+}
+
+------------------------------------------------------------------------------
+
+-- Disassemble a block of code.
+local function disass_block(ctx, ofs, len)
+ if not ofs then ofs = 0 end
+ local stop = len and ofs+len or #ctx.code
+ ofs = ofs + 1
+ ctx.start = ofs
+ ctx.pos = ofs
+ ctx.stop = stop
+ ctx.imm = nil
+ ctx.mrm = false
+ clearprefixes(ctx)
+ while ctx.pos <= stop do dispatchmap(ctx, ctx.map1) end
+ if ctx.pos ~= ctx.start then incomplete(ctx) end
+end
+
+-- Extended API: create a disassembler context. Then call ctx:disass(ofs, len).
+local function create_(code, addr, out)
+ local ctx = {}
+ ctx.code = code
+ ctx.addr = (addr or 0) - 1
+ ctx.out = out or io.write
+ ctx.symtab = {}
+ ctx.disass = disass_block
+ ctx.hexdump = 16
+ ctx.x64 = false
+ ctx.map1 = map_opc1_32
+ ctx.aregs = map_regs.D
+ return ctx
+end
+
+local function create64_(code, addr, out)
+ local ctx = create_(code, addr, out)
+ ctx.x64 = true
+ ctx.map1 = map_opc1_64
+ ctx.aregs = map_regs.Q
+ return ctx
+end
+
+-- Simple API: disassemble code (a string) at address and output via out.
+local function disass_(code, addr, out)
+ create_(code, addr, out):disass()
+end
+
+local function disass64_(code, addr, out)
+ create64_(code, addr, out):disass()
+end
+
+-- Return register name for RID.
+local function regname_(r)
+ if r < 8 then return map_regs.D[r+1] end
+ return map_regs.X[r-7]
+end
+
+local function regname64_(r)
+ if r < 16 then return map_regs.Q[r+1] end
+ return map_regs.X[r-15]
+end
+
+-- Public module functions.
+module(...)
+
+create = create_
+create64 = create64_
+disass = disass_
+disass64 = disass64_
+regname = regname_
+regname64 = regname64_
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/jit/dump.lua b/src/3rdparty/LuaJIT-2.0.5/src/jit/dump.lua
new file mode 100644
index 0000000..666ba43
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/jit/dump.lua
@@ -0,0 +1,701 @@
+----------------------------------------------------------------------------
+-- LuaJIT compiler dump module.
+--
+-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+-- Released under the MIT license. See Copyright Notice in luajit.h
+----------------------------------------------------------------------------
+--
+-- This module can be used to debug the JIT compiler itself. It dumps the
+-- code representations and structures used in various compiler stages.
+--
+-- Example usage:
+--
+-- luajit -jdump -e "local x=0; for i=1,1e6 do x=x+i end; print(x)"
+-- luajit -jdump=im -e "for i=1,1000 do for j=1,1000 do end end" | less -R
+-- luajit -jdump=is myapp.lua | less -R
+-- luajit -jdump=-b myapp.lua
+-- luajit -jdump=+aH,myapp.html myapp.lua
+-- luajit -jdump=ixT,myapp.dump myapp.lua
+--
+-- The first argument specifies the dump mode. The second argument gives
+-- the output file name. Default output is to stdout, unless the environment
+-- variable LUAJIT_DUMPFILE is set. The file is overwritten every time the
+-- module is started.
+--
+-- Different features can be turned on or off with the dump mode. If the
+-- mode starts with a '+', the following features are added to the default
+-- set of features; a '-' removes them. Otherwise the features are replaced.
+--
+-- The following dump features are available (* marks the default):
+--
+-- * t Print a line for each started, ended or aborted trace (see also -jv).
+-- * b Dump the traced bytecode.
+-- * i Dump the IR (intermediate representation).
+-- r Augment the IR with register/stack slots.
+-- s Dump the snapshot map.
+-- * m Dump the generated machine code.
+-- x Print each taken trace exit.
+-- X Print each taken trace exit and the contents of all registers.
+-- a Print the IR of aborted traces, too.
+--
+-- The output format can be set with the following characters:
+--
+-- T Plain text output.
+-- A ANSI-colored text output
+-- H Colorized HTML + CSS output.
+--
+-- The default output format is plain text. It's set to ANSI-colored text
+-- if the COLORTERM variable is set. Note: this is independent of any output
+-- redirection, which is actually considered a feature.
+--
+-- You probably want to use less -R to enjoy viewing ANSI-colored text from
+-- a pipe or a file. Add this to your ~/.bashrc: export LESS="-R"
+--
+------------------------------------------------------------------------------
+
+-- Cache some library functions and objects.
+local jit = require("jit")
+assert(jit.version_num == 20005, "LuaJIT core/library version mismatch")
+local jutil = require("jit.util")
+local vmdef = require("jit.vmdef")
+local funcinfo, funcbc = jutil.funcinfo, jutil.funcbc
+local traceinfo, traceir, tracek = jutil.traceinfo, jutil.traceir, jutil.tracek
+local tracemc, tracesnap = jutil.tracemc, jutil.tracesnap
+local traceexitstub, ircalladdr = jutil.traceexitstub, jutil.ircalladdr
+local bit = require("bit")
+local band, shr = bit.band, bit.rshift
+local sub, gsub, format = string.sub, string.gsub, string.format
+local byte, rep = string.byte, string.rep
+local type, tostring = type, tostring
+local stdout, stderr = io.stdout, io.stderr
+
+-- Load other modules on-demand.
+local bcline, disass
+
+-- Active flag, output file handle and dump mode.
+local active, out, dumpmode
+
+------------------------------------------------------------------------------
+
+local symtabmt = { __index = false }
+local symtab = {}
+local nexitsym = 0
+
+-- Fill nested symbol table with per-trace exit stub addresses.
+local function fillsymtab_tr(tr, nexit)
+ local t = {}
+ symtabmt.__index = t
+ if jit.arch == "mips" or jit.arch == "mipsel" then
+ t[traceexitstub(tr, 0)] = "exit"
+ return
+ end
+ for i=0,nexit-1 do
+ local addr = traceexitstub(tr, i)
+ t[addr] = tostring(i)
+ end
+ local addr = traceexitstub(tr, nexit)
+ if addr then t[addr] = "stack_check" end
+end
+
+-- Fill symbol table with trace exit stub addresses.
+local function fillsymtab(tr, nexit)
+ local t = symtab
+ if nexitsym == 0 then
+ local ircall = vmdef.ircall
+ for i=0,#ircall do
+ local addr = ircalladdr(i)
+ if addr ~= 0 then t[addr] = ircall[i] end
+ end
+ end
+ if nexitsym == 1000000 then -- Per-trace exit stubs.
+ fillsymtab_tr(tr, nexit)
+ elseif nexit > nexitsym then -- Shared exit stubs.
+ for i=nexitsym,nexit-1 do
+ local addr = traceexitstub(i)
+ if addr == nil then -- Fall back to per-trace exit stubs.
+ fillsymtab_tr(tr, nexit)
+ setmetatable(symtab, symtabmt)
+ nexit = 1000000
+ break
+ end
+ t[addr] = tostring(i)
+ end
+ nexitsym = nexit
+ end
+ return t
+end
+
+local function dumpwrite(s)
+ out:write(s)
+end
+
+-- Disassemble machine code.
+local function dump_mcode(tr)
+ local info = traceinfo(tr)
+ if not info then return end
+ local mcode, addr, loop = tracemc(tr)
+ if not mcode then return end
+ if not disass then disass = require("jit.dis_"..jit.arch) end
+ out:write("---- TRACE ", tr, " mcode ", #mcode, "\n")
+ local ctx = disass.create(mcode, addr, dumpwrite)
+ ctx.hexdump = 0
+ ctx.symtab = fillsymtab(tr, info.nexit)
+ if loop ~= 0 then
+ symtab[addr+loop] = "LOOP"
+ ctx:disass(0, loop)
+ out:write("->LOOP:\n")
+ ctx:disass(loop, #mcode-loop)
+ symtab[addr+loop] = nil
+ else
+ ctx:disass(0, #mcode)
+ end
+end
+
+------------------------------------------------------------------------------
+
+local irtype_text = {
+ [0] = "nil",
+ "fal",
+ "tru",
+ "lud",
+ "str",
+ "p32",
+ "thr",
+ "pro",
+ "fun",
+ "p64",
+ "cdt",
+ "tab",
+ "udt",
+ "flt",
+ "num",
+ "i8 ",
+ "u8 ",
+ "i16",
+ "u16",
+ "int",
+ "u32",
+ "i64",
+ "u64",
+ "sfp",
+}
+
+local colortype_ansi = {
+ [0] = "%s",
+ "%s",
+ "%s",
+ "\027[36m%s\027[m",
+ "\027[32m%s\027[m",
+ "%s",
+ "\027[1m%s\027[m",
+ "%s",
+ "\027[1m%s\027[m",
+ "%s",
+ "\027[33m%s\027[m",
+ "\027[31m%s\027[m",
+ "\027[36m%s\027[m",
+ "\027[34m%s\027[m",
+ "\027[34m%s\027[m",
+ "\027[35m%s\027[m",
+ "\027[35m%s\027[m",
+ "\027[35m%s\027[m",
+ "\027[35m%s\027[m",
+ "\027[35m%s\027[m",
+ "\027[35m%s\027[m",
+ "\027[35m%s\027[m",
+ "\027[35m%s\027[m",
+ "\027[35m%s\027[m",
+}
+
+local function colorize_text(s)
+ return s
+end
+
+local function colorize_ansi(s, t)
+ return format(colortype_ansi[t], s)
+end
+
+local irtype_ansi = setmetatable({},
+ { __index = function(tab, t)
+ local s = colorize_ansi(irtype_text[t], t); tab[t] = s; return s; end })
+
+local html_escape = { ["<"] = "&lt;", [">"] = "&gt;", ["&"] = "&amp;", }
+
+local function colorize_html(s, t)
+ s = gsub(s, "[<>&]", html_escape)
+ return format('<span class="irt_%s">%s</span>', irtype_text[t], s)
+end
+
+local irtype_html = setmetatable({},
+ { __index = function(tab, t)
+ local s = colorize_html(irtype_text[t], t); tab[t] = s; return s; end })
+
+local header_html = [[
+<style type="text/css">
+background { background: #ffffff; color: #000000; }
+pre.ljdump {
+font-size: 10pt;
+background: #f0f4ff;
+color: #000000;
+border: 1px solid #bfcfff;
+padding: 0.5em;
+margin-left: 2em;
+margin-right: 2em;
+}
+span.irt_str { color: #00a000; }
+span.irt_thr, span.irt_fun { color: #404040; font-weight: bold; }
+span.irt_tab { color: #c00000; }
+span.irt_udt, span.irt_lud { color: #00c0c0; }
+span.irt_num { color: #4040c0; }
+span.irt_int, span.irt_i8, span.irt_u8, span.irt_i16, span.irt_u16 { color: #b040b0; }
+</style>
+]]
+
+local colorize, irtype
+
+-- Lookup tables to convert some literals into names.
+local litname = {
+ ["SLOAD "] = setmetatable({}, { __index = function(t, mode)
+ local s = ""
+ if band(mode, 1) ~= 0 then s = s.."P" end
+ if band(mode, 2) ~= 0 then s = s.."F" end
+ if band(mode, 4) ~= 0 then s = s.."T" end
+ if band(mode, 8) ~= 0 then s = s.."C" end
+ if band(mode, 16) ~= 0 then s = s.."R" end
+ if band(mode, 32) ~= 0 then s = s.."I" end
+ t[mode] = s
+ return s
+ end}),
+ ["XLOAD "] = { [0] = "", "R", "V", "RV", "U", "RU", "VU", "RVU", },
+ ["CONV "] = setmetatable({}, { __index = function(t, mode)
+ local s = irtype[band(mode, 31)]
+ s = irtype[band(shr(mode, 5), 31)].."."..s
+ if band(mode, 0x400) ~= 0 then s = s.." trunc"
+ elseif band(mode, 0x800) ~= 0 then s = s.." sext" end
+ local c = shr(mode, 14)
+ if c == 2 then s = s.." index" elseif c == 3 then s = s.." check" end
+ t[mode] = s
+ return s
+ end}),
+ ["FLOAD "] = vmdef.irfield,
+ ["FREF "] = vmdef.irfield,
+ ["FPMATH"] = vmdef.irfpm,
+}
+
+local function ctlsub(c)
+ if c == "\n" then return "\\n"
+ elseif c == "\r" then return "\\r"
+ elseif c == "\t" then return "\\t"
+ else return format("\\%03d", byte(c))
+ end
+end
+
+local function fmtfunc(func, pc)
+ local fi = funcinfo(func, pc)
+ if fi.loc then
+ return fi.loc
+ elseif fi.ffid then
+ return vmdef.ffnames[fi.ffid]
+ elseif fi.addr then
+ return format("C:%x", fi.addr)
+ else
+ return "(?)"
+ end
+end
+
+local function formatk(tr, idx)
+ local k, t, slot = tracek(tr, idx)
+ local tn = type(k)
+ local s
+ if tn == "number" then
+ if k == 2^52+2^51 then
+ s = "bias"
+ else
+ s = format("%+.14g", k)
+ end
+ elseif tn == "string" then
+ s = format(#k > 20 and '"%.20s"~' or '"%s"', gsub(k, "%c", ctlsub))
+ elseif tn == "function" then
+ s = fmtfunc(k)
+ elseif tn == "table" then
+ s = format("{%p}", k)
+ elseif tn == "userdata" then
+ if t == 12 then
+ s = format("userdata:%p", k)
+ else
+ s = format("[%p]", k)
+ if s == "[NULL]" then s = "NULL" end
+ end
+ elseif t == 21 then -- int64_t
+ s = sub(tostring(k), 1, -3)
+ if sub(s, 1, 1) ~= "-" then s = "+"..s end
+ else
+ s = tostring(k) -- For primitives.
+ end
+ s = colorize(format("%-4s", s), t)
+ if slot then
+ s = format("%s @%d", s, slot)
+ end
+ return s
+end
+
+local function printsnap(tr, snap)
+ local n = 2
+ for s=0,snap[1]-1 do
+ local sn = snap[n]
+ if shr(sn, 24) == s then
+ n = n + 1
+ local ref = band(sn, 0xffff) - 0x8000 -- REF_BIAS
+ if ref < 0 then
+ out:write(formatk(tr, ref))
+ elseif band(sn, 0x80000) ~= 0 then -- SNAP_SOFTFPNUM
+ out:write(colorize(format("%04d/%04d", ref, ref+1), 14))
+ else
+ local m, ot, op1, op2 = traceir(tr, ref)
+ out:write(colorize(format("%04d", ref), band(ot, 31)))
+ end
+ out:write(band(sn, 0x10000) == 0 and " " or "|") -- SNAP_FRAME
+ else
+ out:write("---- ")
+ end
+ end
+ out:write("]\n")
+end
+
+-- Dump snapshots (not interleaved with IR).
+local function dump_snap(tr)
+ out:write("---- TRACE ", tr, " snapshots\n")
+ for i=0,1000000000 do
+ local snap = tracesnap(tr, i)
+ if not snap then break end
+ out:write(format("#%-3d %04d [ ", i, snap[0]))
+ printsnap(tr, snap)
+ end
+end
+
+-- Return a register name or stack slot for a rid/sp location.
+local function ridsp_name(ridsp, ins)
+ if not disass then disass = require("jit.dis_"..jit.arch) end
+ local rid, slot = band(ridsp, 0xff), shr(ridsp, 8)
+ if rid == 253 or rid == 254 then
+ return (slot == 0 or slot == 255) and " {sink" or format(" {%04d", ins-slot)
+ end
+ if ridsp > 255 then return format("[%x]", slot*4) end
+ if rid < 128 then return disass.regname(rid) end
+ return ""
+end
+
+-- Dump CALL* function ref and return optional ctype.
+local function dumpcallfunc(tr, ins)
+ local ctype
+ if ins > 0 then
+ local m, ot, op1, op2 = traceir(tr, ins)
+ if band(ot, 31) == 0 then -- nil type means CARG(func, ctype).
+ ins = op1
+ ctype = formatk(tr, op2)
+ end
+ end
+ if ins < 0 then
+ out:write(format("[0x%x](", tonumber((tracek(tr, ins)))))
+ else
+ out:write(format("%04d (", ins))
+ end
+ return ctype
+end
+
+-- Recursively gather CALL* args and dump them.
+local function dumpcallargs(tr, ins)
+ if ins < 0 then
+ out:write(formatk(tr, ins))
+ else
+ local m, ot, op1, op2 = traceir(tr, ins)
+ local oidx = 6*shr(ot, 8)
+ local op = sub(vmdef.irnames, oidx+1, oidx+6)
+ if op == "CARG " then
+ dumpcallargs(tr, op1)
+ if op2 < 0 then
+ out:write(" ", formatk(tr, op2))
+ else
+ out:write(" ", format("%04d", op2))
+ end
+ else
+ out:write(format("%04d", ins))
+ end
+ end
+end
+
+-- Dump IR and interleaved snapshots.
+local function dump_ir(tr, dumpsnap, dumpreg)
+ local info = traceinfo(tr)
+ if not info then return end
+ local nins = info.nins
+ out:write("---- TRACE ", tr, " IR\n")
+ local irnames = vmdef.irnames
+ local snapref = 65536
+ local snap, snapno
+ if dumpsnap then
+ snap = tracesnap(tr, 0)
+ snapref = snap[0]
+ snapno = 0
+ end
+ for ins=1,nins do
+ if ins >= snapref then
+ if dumpreg then
+ out:write(format(".... SNAP #%-3d [ ", snapno))
+ else
+ out:write(format(".... SNAP #%-3d [ ", snapno))
+ end
+ printsnap(tr, snap)
+ snapno = snapno + 1
+ snap = tracesnap(tr, snapno)
+ snapref = snap and snap[0] or 65536
+ end
+ local m, ot, op1, op2, ridsp = traceir(tr, ins)
+ local oidx, t = 6*shr(ot, 8), band(ot, 31)
+ local op = sub(irnames, oidx+1, oidx+6)
+ if op == "LOOP " then
+ if dumpreg then
+ out:write(format("%04d ------------ LOOP ------------\n", ins))
+ else
+ out:write(format("%04d ------ LOOP ------------\n", ins))
+ end
+ elseif op ~= "NOP " and op ~= "CARG " and
+ (dumpreg or op ~= "RENAME") then
+ local rid = band(ridsp, 255)
+ if dumpreg then
+ out:write(format("%04d %-6s", ins, ridsp_name(ridsp, ins)))
+ else
+ out:write(format("%04d ", ins))
+ end
+ out:write(format("%s%s %s %s ",
+ (rid == 254 or rid == 253) and "}" or
+ (band(ot, 128) == 0 and " " or ">"),
+ band(ot, 64) == 0 and " " or "+",
+ irtype[t], op))
+ local m1, m2 = band(m, 3), band(m, 3*4)
+ if sub(op, 1, 4) == "CALL" then
+ local ctype
+ if m2 == 1*4 then -- op2 == IRMlit
+ out:write(format("%-10s (", vmdef.ircall[op2]))
+ else
+ ctype = dumpcallfunc(tr, op2)
+ end
+ if op1 ~= -1 then dumpcallargs(tr, op1) end
+ out:write(")")
+ if ctype then out:write(" ctype ", ctype) end
+ elseif op == "CNEW " and op2 == -1 then
+ out:write(formatk(tr, op1))
+ elseif m1 ~= 3 then -- op1 != IRMnone
+ if op1 < 0 then
+ out:write(formatk(tr, op1))
+ else
+ out:write(format(m1 == 0 and "%04d" or "#%-3d", op1))
+ end
+ if m2 ~= 3*4 then -- op2 != IRMnone
+ if m2 == 1*4 then -- op2 == IRMlit
+ local litn = litname[op]
+ if litn and litn[op2] then
+ out:write(" ", litn[op2])
+ elseif op == "UREFO " or op == "UREFC " then
+ out:write(format(" #%-3d", shr(op2, 8)))
+ else
+ out:write(format(" #%-3d", op2))
+ end
+ elseif op2 < 0 then
+ out:write(" ", formatk(tr, op2))
+ else
+ out:write(format(" %04d", op2))
+ end
+ end
+ end
+ out:write("\n")
+ end
+ end
+ if snap then
+ if dumpreg then
+ out:write(format(".... SNAP #%-3d [ ", snapno))
+ else
+ out:write(format(".... SNAP #%-3d [ ", snapno))
+ end
+ printsnap(tr, snap)
+ end
+end
+
+------------------------------------------------------------------------------
+
+local recprefix = ""
+local recdepth = 0
+
+-- Format trace error message.
+local function fmterr(err, info)
+ if type(err) == "number" then
+ if type(info) == "function" then info = fmtfunc(info) end
+ err = format(vmdef.traceerr[err], info)
+ end
+ return err
+end
+
+-- Dump trace states.
+local function dump_trace(what, tr, func, pc, otr, oex)
+ if what == "stop" or (what == "abort" and dumpmode.a) then
+ if dumpmode.i then dump_ir(tr, dumpmode.s, dumpmode.r and what == "stop")
+ elseif dumpmode.s then dump_snap(tr) end
+ if dumpmode.m then dump_mcode(tr) end
+ end
+ if what == "start" then
+ if dumpmode.H then out:write('<pre class="ljdump">\n') end
+ out:write("---- TRACE ", tr, " ", what)
+ if otr then out:write(" ", otr, "/", oex) end
+ out:write(" ", fmtfunc(func, pc), "\n")
+ elseif what == "stop" or what == "abort" then
+ out:write("---- TRACE ", tr, " ", what)
+ if what == "abort" then
+ out:write(" ", fmtfunc(func, pc), " -- ", fmterr(otr, oex), "\n")
+ else
+ local info = traceinfo(tr)
+ local link, ltype = info.link, info.linktype
+ if link == tr or link == 0 then
+ out:write(" -> ", ltype, "\n")
+ elseif ltype == "root" then
+ out:write(" -> ", link, "\n")
+ else
+ out:write(" -> ", link, " ", ltype, "\n")
+ end
+ end
+ if dumpmode.H then out:write("</pre>\n\n") else out:write("\n") end
+ else
+ if what == "flush" then symtab, nexitsym = {}, 0 end
+ out:write("---- TRACE ", what, "\n\n")
+ end
+ out:flush()
+end
+
+-- Dump recorded bytecode.
+local function dump_record(tr, func, pc, depth, callee)
+ if depth ~= recdepth then
+ recdepth = depth
+ recprefix = rep(" .", depth)
+ end
+ local line
+ if pc >= 0 then
+ line = bcline(func, pc, recprefix)
+ if dumpmode.H then line = gsub(line, "[<>&]", html_escape) end
+ else
+ line = "0000 "..recprefix.." FUNCC \n"
+ callee = func
+ end
+ if pc <= 0 then
+ out:write(sub(line, 1, -2), " ; ", fmtfunc(func), "\n")
+ else
+ out:write(line)
+ end
+ if pc >= 0 and band(funcbc(func, pc), 0xff) < 16 then -- ORDER BC
+ out:write(bcline(func, pc+1, recprefix)) -- Write JMP for cond.
+ end
+end
+
+------------------------------------------------------------------------------
+
+-- Dump taken trace exits.
+local function dump_texit(tr, ex, ngpr, nfpr, ...)
+ out:write("---- TRACE ", tr, " exit ", ex, "\n")
+ if dumpmode.X then
+ local regs = {...}
+ if jit.arch == "x64" then
+ for i=1,ngpr do
+ out:write(format(" %016x", regs[i]))
+ if i % 4 == 0 then out:write("\n") end
+ end
+ else
+ for i=1,ngpr do
+ out:write(format(" %08x", regs[i]))
+ if i % 8 == 0 then out:write("\n") end
+ end
+ end
+ if jit.arch == "mips" or jit.arch == "mipsel" then
+ for i=1,nfpr,2 do
+ out:write(format(" %+17.14g", regs[ngpr+i]))
+ if i % 8 == 7 then out:write("\n") end
+ end
+ else
+ for i=1,nfpr do
+ out:write(format(" %+17.14g", regs[ngpr+i]))
+ if i % 4 == 0 then out:write("\n") end
+ end
+ end
+ end
+end
+
+------------------------------------------------------------------------------
+
+-- Detach dump handlers.
+local function dumpoff()
+ if active then
+ active = false
+ jit.attach(dump_texit)
+ jit.attach(dump_record)
+ jit.attach(dump_trace)
+ if out and out ~= stdout and out ~= stderr then out:close() end
+ out = nil
+ end
+end
+
+-- Open the output file and attach dump handlers.
+local function dumpon(opt, outfile)
+ if active then dumpoff() end
+
+ local term = os.getenv("TERM")
+ local colormode = (term and term:match("color") or os.getenv("COLORTERM")) and "A" or "T"
+ if opt then
+ opt = gsub(opt, "[TAH]", function(mode) colormode = mode; return ""; end)
+ end
+
+ local m = { t=true, b=true, i=true, m=true, }
+ if opt and opt ~= "" then
+ local o = sub(opt, 1, 1)
+ if o ~= "+" and o ~= "-" then m = {} end
+ for i=1,#opt do m[sub(opt, i, i)] = (o ~= "-") end
+ end
+ dumpmode = m
+
+ if m.t or m.b or m.i or m.s or m.m then
+ jit.attach(dump_trace, "trace")
+ end
+ if m.b then
+ jit.attach(dump_record, "record")
+ if not bcline then bcline = require("jit.bc").line end
+ end
+ if m.x or m.X then
+ jit.attach(dump_texit, "texit")
+ end
+
+ if not outfile then outfile = os.getenv("LUAJIT_DUMPFILE") end
+ if outfile then
+ out = outfile == "-" and stdout or assert(io.open(outfile, "w"))
+ else
+ out = stdout
+ end
+
+ m[colormode] = true
+ if colormode == "A" then
+ colorize = colorize_ansi
+ irtype = irtype_ansi
+ elseif colormode == "H" then
+ colorize = colorize_html
+ irtype = irtype_html
+ out:write(header_html)
+ else
+ colorize = colorize_text
+ irtype = irtype_text
+ end
+
+ active = true
+end
+
+-- Public module functions.
+module(...)
+
+on = dumpon
+off = dumpoff
+start = dumpon -- For -j command line option.
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/jit/v.lua b/src/3rdparty/LuaJIT-2.0.5/src/jit/v.lua
new file mode 100644
index 0000000..47ee394
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/jit/v.lua
@@ -0,0 +1,167 @@
+----------------------------------------------------------------------------
+-- Verbose mode of the LuaJIT compiler.
+--
+-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+-- Released under the MIT license. See Copyright Notice in luajit.h
+----------------------------------------------------------------------------
+--
+-- This module shows verbose information about the progress of the
+-- JIT compiler. It prints one line for each generated trace. This module
+-- is useful to see which code has been compiled or where the compiler
+-- punts and falls back to the interpreter.
+--
+-- Example usage:
+--
+-- luajit -jv -e "for i=1,1000 do for j=1,1000 do end end"
+-- luajit -jv=myapp.out myapp.lua
+--
+-- Default output is to stderr. To redirect the output to a file, pass a
+-- filename as an argument (use '-' for stdout) or set the environment
+-- variable LUAJIT_VERBOSEFILE. The file is overwritten every time the
+-- module is started.
+--
+-- The output from the first example should look like this:
+--
+-- [TRACE 1 (command line):1 loop]
+-- [TRACE 2 (1/3) (command line):1 -> 1]
+--
+-- The first number in each line is the internal trace number. Next are
+-- the file name ('(command line)') and the line number (':1') where the
+-- trace has started. Side traces also show the parent trace number and
+-- the exit number where they are attached to in parentheses ('(1/3)').
+-- An arrow at the end shows where the trace links to ('-> 1'), unless
+-- it loops to itself.
+--
+-- In this case the inner loop gets hot and is traced first, generating
+-- a root trace. Then the last exit from the 1st trace gets hot, too,
+-- and triggers generation of the 2nd trace. The side trace follows the
+-- path along the outer loop and *around* the inner loop, back to its
+-- start, and then links to the 1st trace. Yes, this may seem unusual,
+-- if you know how traditional compilers work. Trace compilers are full
+-- of surprises like this -- have fun! :-)
+--
+-- Aborted traces are shown like this:
+--
+-- [TRACE --- foo.lua:44 -- leaving loop in root trace at foo:lua:50]
+--
+-- Don't worry -- trace aborts are quite common, even in programs which
+-- can be fully compiled. The compiler may retry several times until it
+-- finds a suitable trace.
+--
+-- Of course this doesn't work with features that are not-yet-implemented
+-- (NYI error messages). The VM simply falls back to the interpreter. This
+-- may not matter at all if the particular trace is not very high up in
+-- the CPU usage profile. Oh, and the interpreter is quite fast, too.
+--
+-- Also check out the -jdump module, which prints all the gory details.
+--
+------------------------------------------------------------------------------
+
+-- Cache some library functions and objects.
+local jit = require("jit")
+assert(jit.version_num == 20005, "LuaJIT core/library version mismatch")
+local jutil = require("jit.util")
+local vmdef = require("jit.vmdef")
+local funcinfo, traceinfo = jutil.funcinfo, jutil.traceinfo
+local type, format = type, string.format
+local stdout, stderr = io.stdout, io.stderr
+
+-- Active flag and output file handle.
+local active, out
+
+------------------------------------------------------------------------------
+
+local startloc, startex
+
+local function fmtfunc(func, pc)
+ local fi = funcinfo(func, pc)
+ if fi.loc then
+ return fi.loc
+ elseif fi.ffid then
+ return vmdef.ffnames[fi.ffid]
+ elseif fi.addr then
+ return format("C:%x", fi.addr)
+ else
+ return "(?)"
+ end
+end
+
+-- Format trace error message.
+local function fmterr(err, info)
+ if type(err) == "number" then
+ if type(info) == "function" then info = fmtfunc(info) end
+ err = format(vmdef.traceerr[err], info)
+ end
+ return err
+end
+
+-- Dump trace states.
+local function dump_trace(what, tr, func, pc, otr, oex)
+ if what == "start" then
+ startloc = fmtfunc(func, pc)
+ startex = otr and "("..otr.."/"..oex..") " or ""
+ else
+ if what == "abort" then
+ local loc = fmtfunc(func, pc)
+ if loc ~= startloc then
+ out:write(format("[TRACE --- %s%s -- %s at %s]\n",
+ startex, startloc, fmterr(otr, oex), loc))
+ else
+ out:write(format("[TRACE --- %s%s -- %s]\n",
+ startex, startloc, fmterr(otr, oex)))
+ end
+ elseif what == "stop" then
+ local info = traceinfo(tr)
+ local link, ltype = info.link, info.linktype
+ if ltype == "interpreter" then
+ out:write(format("[TRACE %3s %s%s -- fallback to interpreter]\n",
+ tr, startex, startloc))
+ elseif link == tr or link == 0 then
+ out:write(format("[TRACE %3s %s%s %s]\n",
+ tr, startex, startloc, ltype))
+ elseif ltype == "root" then
+ out:write(format("[TRACE %3s %s%s -> %d]\n",
+ tr, startex, startloc, link))
+ else
+ out:write(format("[TRACE %3s %s%s -> %d %s]\n",
+ tr, startex, startloc, link, ltype))
+ end
+ else
+ out:write(format("[TRACE %s]\n", what))
+ end
+ out:flush()
+ end
+end
+
+------------------------------------------------------------------------------
+
+-- Detach dump handlers.
+local function dumpoff()
+ if active then
+ active = false
+ jit.attach(dump_trace)
+ if out and out ~= stdout and out ~= stderr then out:close() end
+ out = nil
+ end
+end
+
+-- Open the output file and attach dump handlers.
+local function dumpon(outfile)
+ if active then dumpoff() end
+ if not outfile then outfile = os.getenv("LUAJIT_VERBOSEFILE") end
+ if outfile then
+ out = outfile == "-" and stdout or assert(io.open(outfile, "w"))
+ else
+ out = stderr
+ end
+ jit.attach(dump_trace, "trace")
+ active = true
+end
+
+-- Public module functions.
+module(...)
+
+on = dumpon
+off = dumpoff
+start = dumpon -- For -j command line option.
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lauxlib.h b/src/3rdparty/LuaJIT-2.0.5/src/lauxlib.h
new file mode 100644
index 0000000..fed1491
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lauxlib.h
@@ -0,0 +1,167 @@
+/*
+** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $
+** Auxiliary functions for building Lua libraries
+** See Copyright Notice in lua.h
+*/
+
+
+#ifndef lauxlib_h
+#define lauxlib_h
+
+
+#include <stddef.h>
+#include <stdio.h>
+
+#include "lua.h"
+
+
+#define luaL_getn(L,i) ((int)lua_objlen(L, i))
+#define luaL_setn(L,i,j) ((void)0) /* no op! */
+
+/* extra error code for `luaL_load' */
+#define LUA_ERRFILE (LUA_ERRERR+1)
+
+typedef struct luaL_Reg {
+ const char *name;
+ lua_CFunction func;
+} luaL_Reg;
+
+LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
+ const luaL_Reg *l, int nup);
+LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
+ const luaL_Reg *l);
+LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
+LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
+LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);
+LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
+LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,
+ size_t *l);
+LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,
+ const char *def, size_t *l);
+LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg);
+LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def);
+
+LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);
+LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,
+ lua_Integer def);
+
+LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
+LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
+LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
+
+LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
+LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
+
+LUALIB_API void (luaL_where) (lua_State *L, int lvl);
+LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
+
+LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
+ const char *const lst[]);
+
+LUALIB_API int (luaL_ref) (lua_State *L, int t);
+LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
+
+LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);
+LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz,
+ const char *name);
+LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
+
+LUALIB_API lua_State *(luaL_newstate) (void);
+
+
+LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
+ const char *r);
+
+LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,
+ const char *fname, int szhint);
+
+/* From Lua 5.2. */
+LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname);
+LUALIB_API int luaL_execresult(lua_State *L, int stat);
+LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,
+ const char *mode);
+LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,
+ const char *name, const char *mode);
+LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,
+ int level);
+
+
+/*
+** ===============================================================
+** some useful macros
+** ===============================================================
+*/
+
+#define luaL_argcheck(L, cond,numarg,extramsg) \
+ ((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))
+#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
+#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
+#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
+#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
+#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
+#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
+
+#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
+
+#define luaL_dofile(L, fn) \
+ (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
+
+#define luaL_dostring(L, s) \
+ (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
+
+#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
+
+#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
+
+/*
+** {======================================================
+** Generic Buffer manipulation
+** =======================================================
+*/
+
+
+
+typedef struct luaL_Buffer {
+ char *p; /* current position in buffer */
+ int lvl; /* number of strings in the stack (level) */
+ lua_State *L;
+ char buffer[LUAL_BUFFERSIZE];
+} luaL_Buffer;
+
+#define luaL_addchar(B,c) \
+ ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \
+ (*(B)->p++ = (char)(c)))
+
+/* compatibility only */
+#define luaL_putchar(B,c) luaL_addchar(B,c)
+
+#define luaL_addsize(B,n) ((B)->p += (n))
+
+LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
+LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B);
+LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
+LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);
+LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);
+LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
+
+
+/* }====================================================== */
+
+
+/* compatibility with ref system */
+
+/* pre-defined references */
+#define LUA_NOREF (-2)
+#define LUA_REFNIL (-1)
+
+#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \
+ (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0))
+
+#define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref))
+
+#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))
+
+
+#define luaL_reg luaL_Reg
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lib_aux.c b/src/3rdparty/LuaJIT-2.0.5/src/lib_aux.c
new file mode 100644
index 0000000..7af1cd4
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lib_aux.c
@@ -0,0 +1,356 @@
+/*
+** Auxiliary library for the Lua/C API.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Major parts taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#define lib_aux_c
+#define LUA_LIB
+
+#include "lua.h"
+#include "lauxlib.h"
+
+#include "lj_obj.h"
+#include "lj_err.h"
+#include "lj_state.h"
+#include "lj_trace.h"
+#include "lj_lib.h"
+
+#if LJ_TARGET_POSIX
+#include <sys/wait.h>
+#endif
+
+/* -- I/O error handling -------------------------------------------------- */
+
+LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname)
+{
+ if (stat) {
+ setboolV(L->top++, 1);
+ return 1;
+ } else {
+ int en = errno; /* Lua API calls may change this value. */
+ setnilV(L->top++);
+ if (fname)
+ lua_pushfstring(L, "%s: %s", fname, strerror(en));
+ else
+ lua_pushfstring(L, "%s", strerror(en));
+ setintV(L->top++, en);
+ lj_trace_abort(G(L));
+ return 3;
+ }
+}
+
+LUALIB_API int luaL_execresult(lua_State *L, int stat)
+{
+ if (stat != -1) {
+#if LJ_TARGET_POSIX
+ if (WIFSIGNALED(stat)) {
+ stat = WTERMSIG(stat);
+ setnilV(L->top++);
+ lua_pushliteral(L, "signal");
+ } else {
+ if (WIFEXITED(stat))
+ stat = WEXITSTATUS(stat);
+ if (stat == 0)
+ setboolV(L->top++, 1);
+ else
+ setnilV(L->top++);
+ lua_pushliteral(L, "exit");
+ }
+#else
+ if (stat == 0)
+ setboolV(L->top++, 1);
+ else
+ setnilV(L->top++);
+ lua_pushliteral(L, "exit");
+#endif
+ setintV(L->top++, stat);
+ return 3;
+ }
+ return luaL_fileresult(L, 0, NULL);
+}
+
+/* -- Module registration ------------------------------------------------- */
+
+LUALIB_API const char *luaL_findtable(lua_State *L, int idx,
+ const char *fname, int szhint)
+{
+ const char *e;
+ lua_pushvalue(L, idx);
+ do {
+ e = strchr(fname, '.');
+ if (e == NULL) e = fname + strlen(fname);
+ lua_pushlstring(L, fname, (size_t)(e - fname));
+ lua_rawget(L, -2);
+ if (lua_isnil(L, -1)) { /* no such field? */
+ lua_pop(L, 1); /* remove this nil */
+ lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */
+ lua_pushlstring(L, fname, (size_t)(e - fname));
+ lua_pushvalue(L, -2);
+ lua_settable(L, -4); /* set new table into field */
+ } else if (!lua_istable(L, -1)) { /* field has a non-table value? */
+ lua_pop(L, 2); /* remove table and value */
+ return fname; /* return problematic part of the name */
+ }
+ lua_remove(L, -2); /* remove previous table */
+ fname = e + 1;
+ } while (*e == '.');
+ return NULL;
+}
+
+static int libsize(const luaL_Reg *l)
+{
+ int size = 0;
+ for (; l->name; l++) size++;
+ return size;
+}
+
+LUALIB_API void luaL_openlib(lua_State *L, const char *libname,
+ const luaL_Reg *l, int nup)
+{
+ lj_lib_checkfpu(L);
+ if (libname) {
+ int size = libsize(l);
+ /* check whether lib already exists */
+ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16);
+ lua_getfield(L, -1, libname); /* get _LOADED[libname] */
+ if (!lua_istable(L, -1)) { /* not found? */
+ lua_pop(L, 1); /* remove previous result */
+ /* try global variable (and create one if it does not exist) */
+ if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, size) != NULL)
+ lj_err_callerv(L, LJ_ERR_BADMODN, libname);
+ lua_pushvalue(L, -1);
+ lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */
+ }
+ lua_remove(L, -2); /* remove _LOADED table */
+ lua_insert(L, -(nup+1)); /* move library table to below upvalues */
+ }
+ for (; l->name; l++) {
+ int i;
+ for (i = 0; i < nup; i++) /* copy upvalues to the top */
+ lua_pushvalue(L, -nup);
+ lua_pushcclosure(L, l->func, nup);
+ lua_setfield(L, -(nup+2), l->name);
+ }
+ lua_pop(L, nup); /* remove upvalues */
+}
+
+LUALIB_API void luaL_register(lua_State *L, const char *libname,
+ const luaL_Reg *l)
+{
+ luaL_openlib(L, libname, l, 0);
+}
+
+LUALIB_API const char *luaL_gsub(lua_State *L, const char *s,
+ const char *p, const char *r)
+{
+ const char *wild;
+ size_t l = strlen(p);
+ luaL_Buffer b;
+ luaL_buffinit(L, &b);
+ while ((wild = strstr(s, p)) != NULL) {
+ luaL_addlstring(&b, s, (size_t)(wild - s)); /* push prefix */
+ luaL_addstring(&b, r); /* push replacement in place of pattern */
+ s = wild + l; /* continue after `p' */
+ }
+ luaL_addstring(&b, s); /* push last suffix */
+ luaL_pushresult(&b);
+ return lua_tostring(L, -1);
+}
+
+/* -- Buffer handling ----------------------------------------------------- */
+
+#define bufflen(B) ((size_t)((B)->p - (B)->buffer))
+#define bufffree(B) ((size_t)(LUAL_BUFFERSIZE - bufflen(B)))
+
+static int emptybuffer(luaL_Buffer *B)
+{
+ size_t l = bufflen(B);
+ if (l == 0)
+ return 0; /* put nothing on stack */
+ lua_pushlstring(B->L, B->buffer, l);
+ B->p = B->buffer;
+ B->lvl++;
+ return 1;
+}
+
+static void adjuststack(luaL_Buffer *B)
+{
+ if (B->lvl > 1) {
+ lua_State *L = B->L;
+ int toget = 1; /* number of levels to concat */
+ size_t toplen = lua_strlen(L, -1);
+ do {
+ size_t l = lua_strlen(L, -(toget+1));
+ if (!(B->lvl - toget + 1 >= LUA_MINSTACK/2 || toplen > l))
+ break;
+ toplen += l;
+ toget++;
+ } while (toget < B->lvl);
+ lua_concat(L, toget);
+ B->lvl = B->lvl - toget + 1;
+ }
+}
+
+LUALIB_API char *luaL_prepbuffer(luaL_Buffer *B)
+{
+ if (emptybuffer(B))
+ adjuststack(B);
+ return B->buffer;
+}
+
+LUALIB_API void luaL_addlstring(luaL_Buffer *B, const char *s, size_t l)
+{
+ while (l--)
+ luaL_addchar(B, *s++);
+}
+
+LUALIB_API void luaL_addstring(luaL_Buffer *B, const char *s)
+{
+ luaL_addlstring(B, s, strlen(s));
+}
+
+LUALIB_API void luaL_pushresult(luaL_Buffer *B)
+{
+ emptybuffer(B);
+ lua_concat(B->L, B->lvl);
+ B->lvl = 1;
+}
+
+LUALIB_API void luaL_addvalue(luaL_Buffer *B)
+{
+ lua_State *L = B->L;
+ size_t vl;
+ const char *s = lua_tolstring(L, -1, &vl);
+ if (vl <= bufffree(B)) { /* fit into buffer? */
+ memcpy(B->p, s, vl); /* put it there */
+ B->p += vl;
+ lua_pop(L, 1); /* remove from stack */
+ } else {
+ if (emptybuffer(B))
+ lua_insert(L, -2); /* put buffer before new value */
+ B->lvl++; /* add new value into B stack */
+ adjuststack(B);
+ }
+}
+
+LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)
+{
+ B->L = L;
+ B->p = B->buffer;
+ B->lvl = 0;
+}
+
+/* -- Reference management ------------------------------------------------ */
+
+#define FREELIST_REF 0
+
+/* Convert a stack index to an absolute index. */
+#define abs_index(L, i) \
+ ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : lua_gettop(L) + (i) + 1)
+
+LUALIB_API int luaL_ref(lua_State *L, int t)
+{
+ int ref;
+ t = abs_index(L, t);
+ if (lua_isnil(L, -1)) {
+ lua_pop(L, 1); /* remove from stack */
+ return LUA_REFNIL; /* `nil' has a unique fixed reference */
+ }
+ lua_rawgeti(L, t, FREELIST_REF); /* get first free element */
+ ref = (int)lua_tointeger(L, -1); /* ref = t[FREELIST_REF] */
+ lua_pop(L, 1); /* remove it from stack */
+ if (ref != 0) { /* any free element? */
+ lua_rawgeti(L, t, ref); /* remove it from list */
+ lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */
+ } else { /* no free elements */
+ ref = (int)lua_objlen(L, t);
+ ref++; /* create new reference */
+ }
+ lua_rawseti(L, t, ref);
+ return ref;
+}
+
+LUALIB_API void luaL_unref(lua_State *L, int t, int ref)
+{
+ if (ref >= 0) {
+ t = abs_index(L, t);
+ lua_rawgeti(L, t, FREELIST_REF);
+ lua_rawseti(L, t, ref); /* t[ref] = t[FREELIST_REF] */
+ lua_pushinteger(L, ref);
+ lua_rawseti(L, t, FREELIST_REF); /* t[FREELIST_REF] = ref */
+ }
+}
+
+/* -- Default allocator and panic function -------------------------------- */
+
+static int panic(lua_State *L)
+{
+ const char *s = lua_tostring(L, -1);
+ fputs("PANIC: unprotected error in call to Lua API (", stderr);
+ fputs(s ? s : "?", stderr);
+ fputc(')', stderr); fputc('\n', stderr);
+ fflush(stderr);
+ return 0;
+}
+
+#ifdef LUAJIT_USE_SYSMALLOC
+
+#if LJ_64 && !defined(LUAJIT_USE_VALGRIND)
+#error "Must use builtin allocator for 64 bit target"
+#endif
+
+static void *mem_alloc(void *ud, void *ptr, size_t osize, size_t nsize)
+{
+ (void)ud;
+ (void)osize;
+ if (nsize == 0) {
+ free(ptr);
+ return NULL;
+ } else {
+ return realloc(ptr, nsize);
+ }
+}
+
+LUALIB_API lua_State *luaL_newstate(void)
+{
+ lua_State *L = lua_newstate(mem_alloc, NULL);
+ if (L) G(L)->panic = panic;
+ return L;
+}
+
+#else
+
+#include "lj_alloc.h"
+
+LUALIB_API lua_State *luaL_newstate(void)
+{
+ lua_State *L;
+ void *ud = lj_alloc_create();
+ if (ud == NULL) return NULL;
+#if LJ_64
+ L = lj_state_newstate(lj_alloc_f, ud);
+#else
+ L = lua_newstate(lj_alloc_f, ud);
+#endif
+ if (L) G(L)->panic = panic;
+ return L;
+}
+
+#if LJ_64
+LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud)
+{
+ UNUSED(f); UNUSED(ud);
+ fputs("Must use luaL_newstate() for 64 bit target\n", stderr);
+ return NULL;
+}
+#endif
+
+#endif
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lib_base.c b/src/3rdparty/LuaJIT-2.0.5/src/lib_base.c
new file mode 100644
index 0000000..162bbbb
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lib_base.c
@@ -0,0 +1,683 @@
+/*
+** Base and coroutine library.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Major portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2011 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#include <stdio.h>
+
+#define lib_base_c
+#define LUA_LIB
+
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_debug.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_meta.h"
+#include "lj_state.h"
+#if LJ_HASFFI
+#include "lj_ctype.h"
+#include "lj_cconv.h"
+#endif
+#include "lj_bc.h"
+#include "lj_ff.h"
+#include "lj_dispatch.h"
+#include "lj_char.h"
+#include "lj_strscan.h"
+#include "lj_lib.h"
+
+/* -- Base library: checks ------------------------------------------------ */
+
+#define LJLIB_MODULE_base
+
+LJLIB_ASM(assert) LJLIB_REC(.)
+{
+ GCstr *s;
+ lj_lib_checkany(L, 1);
+ s = lj_lib_optstr(L, 2);
+ if (s)
+ lj_err_callermsg(L, strdata(s));
+ else
+ lj_err_caller(L, LJ_ERR_ASSERT);
+ return FFH_UNREACHABLE;
+}
+
+/* ORDER LJ_T */
+LJLIB_PUSH("nil")
+LJLIB_PUSH("boolean")
+LJLIB_PUSH(top-1) /* boolean */
+LJLIB_PUSH("userdata")
+LJLIB_PUSH("string")
+LJLIB_PUSH("upval")
+LJLIB_PUSH("thread")
+LJLIB_PUSH("proto")
+LJLIB_PUSH("function")
+LJLIB_PUSH("trace")
+LJLIB_PUSH("cdata")
+LJLIB_PUSH("table")
+LJLIB_PUSH(top-9) /* userdata */
+LJLIB_PUSH("number")
+LJLIB_ASM_(type) LJLIB_REC(.)
+/* Recycle the lj_lib_checkany(L, 1) from assert. */
+
+/* -- Base library: iterators --------------------------------------------- */
+
+/* This solves a circular dependency problem -- change FF_next_N as needed. */
+LJ_STATIC_ASSERT((int)FF_next == FF_next_N);
+
+LJLIB_ASM(next)
+{
+ lj_lib_checktab(L, 1);
+ return FFH_UNREACHABLE;
+}
+
+#if LJ_52 || LJ_HASFFI
+static int ffh_pairs(lua_State *L, MMS mm)
+{
+ TValue *o = lj_lib_checkany(L, 1);
+ cTValue *mo = lj_meta_lookup(L, o, mm);
+ if ((LJ_52 || tviscdata(o)) && !tvisnil(mo)) {
+ L->top = o+1; /* Only keep one argument. */
+ copyTV(L, L->base-1, mo); /* Replace callable. */
+ return FFH_TAILCALL;
+ } else {
+ if (!tvistab(o)) lj_err_argt(L, 1, LUA_TTABLE);
+ setfuncV(L, o-1, funcV(lj_lib_upvalue(L, 1)));
+ if (mm == MM_pairs) setnilV(o+1); else setintV(o+1, 0);
+ return FFH_RES(3);
+ }
+}
+#else
+#define ffh_pairs(L, mm) (lj_lib_checktab(L, 1), FFH_UNREACHABLE)
+#endif
+
+LJLIB_PUSH(lastcl)
+LJLIB_ASM(pairs)
+{
+ return ffh_pairs(L, MM_pairs);
+}
+
+LJLIB_NOREGUV LJLIB_ASM(ipairs_aux) LJLIB_REC(.)
+{
+ lj_lib_checktab(L, 1);
+ lj_lib_checkint(L, 2);
+ return FFH_UNREACHABLE;
+}
+
+LJLIB_PUSH(lastcl)
+LJLIB_ASM(ipairs) LJLIB_REC(.)
+{
+ return ffh_pairs(L, MM_ipairs);
+}
+
+/* -- Base library: getters and setters ----------------------------------- */
+
+LJLIB_ASM_(getmetatable) LJLIB_REC(.)
+/* Recycle the lj_lib_checkany(L, 1) from assert. */
+
+LJLIB_ASM(setmetatable) LJLIB_REC(.)
+{
+ GCtab *t = lj_lib_checktab(L, 1);
+ GCtab *mt = lj_lib_checktabornil(L, 2);
+ if (!tvisnil(lj_meta_lookup(L, L->base, MM_metatable)))
+ lj_err_caller(L, LJ_ERR_PROTMT);
+ setgcref(t->metatable, obj2gco(mt));
+ if (mt) { lj_gc_objbarriert(L, t, mt); }
+ settabV(L, L->base-1, t);
+ return FFH_RES(1);
+}
+
+LJLIB_CF(getfenv)
+{
+ GCfunc *fn;
+ cTValue *o = L->base;
+ if (!(o < L->top && tvisfunc(o))) {
+ int level = lj_lib_optint(L, 1, 1);
+ o = lj_debug_frame(L, level, &level);
+ if (o == NULL)
+ lj_err_arg(L, 1, LJ_ERR_INVLVL);
+ }
+ fn = &gcval(o)->fn;
+ settabV(L, L->top++, isluafunc(fn) ? tabref(fn->l.env) : tabref(L->env));
+ return 1;
+}
+
+LJLIB_CF(setfenv)
+{
+ GCfunc *fn;
+ GCtab *t = lj_lib_checktab(L, 2);
+ cTValue *o = L->base;
+ if (!(o < L->top && tvisfunc(o))) {
+ int level = lj_lib_checkint(L, 1);
+ if (level == 0) {
+ /* NOBARRIER: A thread (i.e. L) is never black. */
+ setgcref(L->env, obj2gco(t));
+ return 0;
+ }
+ o = lj_debug_frame(L, level, &level);
+ if (o == NULL)
+ lj_err_arg(L, 1, LJ_ERR_INVLVL);
+ }
+ fn = &gcval(o)->fn;
+ if (!isluafunc(fn))
+ lj_err_caller(L, LJ_ERR_SETFENV);
+ setgcref(fn->l.env, obj2gco(t));
+ lj_gc_objbarrier(L, obj2gco(fn), t);
+ setfuncV(L, L->top++, fn);
+ return 1;
+}
+
+LJLIB_ASM(rawget) LJLIB_REC(.)
+{
+ lj_lib_checktab(L, 1);
+ lj_lib_checkany(L, 2);
+ return FFH_UNREACHABLE;
+}
+
+LJLIB_CF(rawset) LJLIB_REC(.)
+{
+ lj_lib_checktab(L, 1);
+ lj_lib_checkany(L, 2);
+ L->top = 1+lj_lib_checkany(L, 3);
+ lua_rawset(L, 1);
+ return 1;
+}
+
+LJLIB_CF(rawequal) LJLIB_REC(.)
+{
+ cTValue *o1 = lj_lib_checkany(L, 1);
+ cTValue *o2 = lj_lib_checkany(L, 2);
+ setboolV(L->top-1, lj_obj_equal(o1, o2));
+ return 1;
+}
+
+#if LJ_52
+LJLIB_CF(rawlen) LJLIB_REC(.)
+{
+ cTValue *o = L->base;
+ int32_t len;
+ if (L->top > o && tvisstr(o))
+ len = (int32_t)strV(o)->len;
+ else
+ len = (int32_t)lj_tab_len(lj_lib_checktab(L, 1));
+ setintV(L->top-1, len);
+ return 1;
+}
+#endif
+
+LJLIB_CF(unpack)
+{
+ GCtab *t = lj_lib_checktab(L, 1);
+ int32_t n, i = lj_lib_optint(L, 2, 1);
+ int32_t e = (L->base+3-1 < L->top && !tvisnil(L->base+3-1)) ?
+ lj_lib_checkint(L, 3) : (int32_t)lj_tab_len(t);
+ if (i > e) return 0;
+ n = e - i + 1;
+ if (n <= 0 || !lua_checkstack(L, n))
+ lj_err_caller(L, LJ_ERR_UNPACK);
+ do {
+ cTValue *tv = lj_tab_getint(t, i);
+ if (tv) {
+ copyTV(L, L->top++, tv);
+ } else {
+ setnilV(L->top++);
+ }
+ } while (i++ < e);
+ return n;
+}
+
+LJLIB_CF(select) LJLIB_REC(.)
+{
+ int32_t n = (int32_t)(L->top - L->base);
+ if (n >= 1 && tvisstr(L->base) && *strVdata(L->base) == '#') {
+ setintV(L->top-1, n-1);
+ return 1;
+ } else {
+ int32_t i = lj_lib_checkint(L, 1);
+ if (i < 0) i = n + i; else if (i > n) i = n;
+ if (i < 1)
+ lj_err_arg(L, 1, LJ_ERR_IDXRNG);
+ return n - i;
+ }
+}
+
+/* -- Base library: conversions ------------------------------------------- */
+
+LJLIB_ASM(tonumber) LJLIB_REC(.)
+{
+ int32_t base = lj_lib_optint(L, 2, 10);
+ if (base == 10) {
+ TValue *o = lj_lib_checkany(L, 1);
+ if (lj_strscan_numberobj(o)) {
+ copyTV(L, L->base-1, o);
+ return FFH_RES(1);
+ }
+#if LJ_HASFFI
+ if (tviscdata(o)) {
+ CTState *cts = ctype_cts(L);
+ CType *ct = lj_ctype_rawref(cts, cdataV(o)->ctypeid);
+ if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);
+ if (ctype_isnum(ct->info) || ctype_iscomplex(ct->info)) {
+ if (LJ_DUALNUM && ctype_isinteger_or_bool(ct->info) &&
+ ct->size <= 4 && !(ct->size == 4 && (ct->info & CTF_UNSIGNED))) {
+ int32_t i;
+ lj_cconv_ct_tv(cts, ctype_get(cts, CTID_INT32), (uint8_t *)&i, o, 0);
+ setintV(L->base-1, i);
+ return FFH_RES(1);
+ }
+ lj_cconv_ct_tv(cts, ctype_get(cts, CTID_DOUBLE),
+ (uint8_t *)&(L->base-1)->n, o, 0);
+ return FFH_RES(1);
+ }
+ }
+#endif
+ } else {
+ const char *p = strdata(lj_lib_checkstr(L, 1));
+ char *ep;
+ unsigned long ul;
+ if (base < 2 || base > 36)
+ lj_err_arg(L, 2, LJ_ERR_BASERNG);
+ ul = strtoul(p, &ep, base);
+ if (p != ep) {
+ while (lj_char_isspace((unsigned char)(*ep))) ep++;
+ if (*ep == '\0') {
+ if (LJ_DUALNUM && LJ_LIKELY(ul < 0x80000000u))
+ setintV(L->base-1, (int32_t)ul);
+ else
+ setnumV(L->base-1, (lua_Number)ul);
+ return FFH_RES(1);
+ }
+ }
+ }
+ setnilV(L->base-1);
+ return FFH_RES(1);
+}
+
+LJLIB_PUSH("nil")
+LJLIB_PUSH("false")
+LJLIB_PUSH("true")
+LJLIB_ASM(tostring) LJLIB_REC(.)
+{
+ TValue *o = lj_lib_checkany(L, 1);
+ cTValue *mo;
+ L->top = o+1; /* Only keep one argument. */
+ if (!tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) {
+ copyTV(L, L->base-1, mo); /* Replace callable. */
+ return FFH_TAILCALL;
+ } else {
+ GCstr *s;
+ if (tvisnumber(o)) {
+ s = lj_str_fromnumber(L, o);
+ } else if (tvispri(o)) {
+ s = strV(lj_lib_upvalue(L, -(int32_t)itype(o)));
+ } else {
+ if (tvisfunc(o) && isffunc(funcV(o)))
+ lua_pushfstring(L, "function: builtin#%d", funcV(o)->c.ffid);
+ else
+ lua_pushfstring(L, "%s: %p", lj_typename(o), lua_topointer(L, 1));
+ /* Note: lua_pushfstring calls the GC which may invalidate o. */
+ s = strV(L->top-1);
+ }
+ setstrV(L, L->base-1, s);
+ return FFH_RES(1);
+ }
+}
+
+/* -- Base library: throw and catch errors -------------------------------- */
+
+LJLIB_CF(error)
+{
+ int32_t level = lj_lib_optint(L, 2, 1);
+ lua_settop(L, 1);
+ if (lua_isstring(L, 1) && level > 0) {
+ luaL_where(L, level);
+ lua_pushvalue(L, 1);
+ lua_concat(L, 2);
+ }
+ return lua_error(L);
+}
+
+LJLIB_ASM(pcall) LJLIB_REC(.)
+{
+ lj_lib_checkany(L, 1);
+ lj_lib_checkfunc(L, 2); /* For xpcall only. */
+ return FFH_UNREACHABLE;
+}
+LJLIB_ASM_(xpcall) LJLIB_REC(.)
+
+/* -- Base library: load Lua code ----------------------------------------- */
+
+static int load_aux(lua_State *L, int status, int envarg)
+{
+ if (status == 0) {
+ if (tvistab(L->base+envarg-1)) {
+ GCfunc *fn = funcV(L->top-1);
+ GCtab *t = tabV(L->base+envarg-1);
+ setgcref(fn->c.env, obj2gco(t));
+ lj_gc_objbarrier(L, fn, t);
+ }
+ return 1;
+ } else {
+ setnilV(L->top-2);
+ return 2;
+ }
+}
+
+LJLIB_CF(loadfile)
+{
+ GCstr *fname = lj_lib_optstr(L, 1);
+ GCstr *mode = lj_lib_optstr(L, 2);
+ int status;
+ lua_settop(L, 3); /* Ensure env arg exists. */
+ status = luaL_loadfilex(L, fname ? strdata(fname) : NULL,
+ mode ? strdata(mode) : NULL);
+ return load_aux(L, status, 3);
+}
+
+static const char *reader_func(lua_State *L, void *ud, size_t *size)
+{
+ UNUSED(ud);
+ luaL_checkstack(L, 2, "too many nested functions");
+ copyTV(L, L->top++, L->base);
+ lua_call(L, 0, 1); /* Call user-supplied function. */
+ L->top--;
+ if (tvisnil(L->top)) {
+ *size = 0;
+ return NULL;
+ } else if (tvisstr(L->top) || tvisnumber(L->top)) {
+ copyTV(L, L->base+4, L->top); /* Anchor string in reserved stack slot. */
+ return lua_tolstring(L, 5, size);
+ } else {
+ lj_err_caller(L, LJ_ERR_RDRSTR);
+ return NULL;
+ }
+}
+
+LJLIB_CF(load)
+{
+ GCstr *name = lj_lib_optstr(L, 2);
+ GCstr *mode = lj_lib_optstr(L, 3);
+ int status;
+ if (L->base < L->top && (tvisstr(L->base) || tvisnumber(L->base))) {
+ GCstr *s = lj_lib_checkstr(L, 1);
+ lua_settop(L, 4); /* Ensure env arg exists. */
+ status = luaL_loadbufferx(L, strdata(s), s->len, strdata(name ? name : s),
+ mode ? strdata(mode) : NULL);
+ } else {
+ lj_lib_checkfunc(L, 1);
+ lua_settop(L, 5); /* Reserve a slot for the string from the reader. */
+ status = lua_loadx(L, reader_func, NULL, name ? strdata(name) : "=(load)",
+ mode ? strdata(mode) : NULL);
+ }
+ return load_aux(L, status, 4);
+}
+
+LJLIB_CF(loadstring)
+{
+ return lj_cf_load(L);
+}
+
+LJLIB_CF(dofile)
+{
+ GCstr *fname = lj_lib_optstr(L, 1);
+ setnilV(L->top);
+ L->top = L->base+1;
+ if (luaL_loadfile(L, fname ? strdata(fname) : NULL) != 0)
+ lua_error(L);
+ lua_call(L, 0, LUA_MULTRET);
+ return (int)(L->top - L->base) - 1;
+}
+
+/* -- Base library: GC control -------------------------------------------- */
+
+LJLIB_CF(gcinfo)
+{
+ setintV(L->top++, (G(L)->gc.total >> 10));
+ return 1;
+}
+
+LJLIB_CF(collectgarbage)
+{
+ int opt = lj_lib_checkopt(L, 1, LUA_GCCOLLECT, /* ORDER LUA_GC* */
+ "\4stop\7restart\7collect\5count\1\377\4step\10setpause\12setstepmul");
+ int32_t data = lj_lib_optint(L, 2, 0);
+ if (opt == LUA_GCCOUNT) {
+ setnumV(L->top, (lua_Number)G(L)->gc.total/1024.0);
+ } else {
+ int res = lua_gc(L, opt, data);
+ if (opt == LUA_GCSTEP)
+ setboolV(L->top, res);
+ else
+ setintV(L->top, res);
+ }
+ L->top++;
+ return 1;
+}
+
+/* -- Base library: miscellaneous functions ------------------------------- */
+
+LJLIB_PUSH(top-2) /* Upvalue holds weak table. */
+LJLIB_CF(newproxy)
+{
+ lua_settop(L, 1);
+ lua_newuserdata(L, 0);
+ if (lua_toboolean(L, 1) == 0) { /* newproxy(): without metatable. */
+ return 1;
+ } else if (lua_isboolean(L, 1)) { /* newproxy(true): with metatable. */
+ lua_newtable(L);
+ lua_pushvalue(L, -1);
+ lua_pushboolean(L, 1);
+ lua_rawset(L, lua_upvalueindex(1)); /* Remember mt in weak table. */
+ } else { /* newproxy(proxy): inherit metatable. */
+ int validproxy = 0;
+ if (lua_getmetatable(L, 1)) {
+ lua_rawget(L, lua_upvalueindex(1));
+ validproxy = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+ }
+ if (!validproxy)
+ lj_err_arg(L, 1, LJ_ERR_NOPROXY);
+ lua_getmetatable(L, 1);
+ }
+ lua_setmetatable(L, 2);
+ return 1;
+}
+
+LJLIB_PUSH("tostring")
+LJLIB_CF(print)
+{
+ ptrdiff_t i, nargs = L->top - L->base;
+ cTValue *tv = lj_tab_getstr(tabref(L->env), strV(lj_lib_upvalue(L, 1)));
+ int shortcut;
+ if (tv && !tvisnil(tv)) {
+ copyTV(L, L->top++, tv);
+ } else {
+ setstrV(L, L->top++, strV(lj_lib_upvalue(L, 1)));
+ lua_gettable(L, LUA_GLOBALSINDEX);
+ tv = L->top-1;
+ }
+ shortcut = (tvisfunc(tv) && funcV(tv)->c.ffid == FF_tostring);
+ for (i = 0; i < nargs; i++) {
+ const char *str;
+ size_t size;
+ cTValue *o = &L->base[i];
+ if (shortcut && tvisstr(o)) {
+ str = strVdata(o);
+ size = strV(o)->len;
+ } else if (shortcut && tvisint(o)) {
+ char buf[LJ_STR_INTBUF];
+ char *p = lj_str_bufint(buf, intV(o));
+ size = (size_t)(buf+LJ_STR_INTBUF-p);
+ str = p;
+ } else if (shortcut && tvisnum(o)) {
+ char buf[LJ_STR_NUMBUF];
+ size = lj_str_bufnum(buf, o);
+ str = buf;
+ } else {
+ copyTV(L, L->top+1, o);
+ copyTV(L, L->top, L->top-1);
+ L->top += 2;
+ lua_call(L, 1, 1);
+ str = lua_tolstring(L, -1, &size);
+ if (!str)
+ lj_err_caller(L, LJ_ERR_PRTOSTR);
+ L->top--;
+ }
+ if (i)
+ putchar('\t');
+ fwrite(str, 1, size, stdout);
+ }
+ putchar('\n');
+ return 0;
+}
+
+LJLIB_PUSH(top-3)
+LJLIB_SET(_VERSION)
+
+#include "lj_libdef.h"
+
+/* -- Coroutine library --------------------------------------------------- */
+
+#define LJLIB_MODULE_coroutine
+
+LJLIB_CF(coroutine_status)
+{
+ const char *s;
+ lua_State *co;
+ if (!(L->top > L->base && tvisthread(L->base)))
+ lj_err_arg(L, 1, LJ_ERR_NOCORO);
+ co = threadV(L->base);
+ if (co == L) s = "running";
+ else if (co->status == LUA_YIELD) s = "suspended";
+ else if (co->status != 0) s = "dead";
+ else if (co->base > tvref(co->stack)+1) s = "normal";
+ else if (co->top == co->base) s = "dead";
+ else s = "suspended";
+ lua_pushstring(L, s);
+ return 1;
+}
+
+LJLIB_CF(coroutine_running)
+{
+#if LJ_52
+ int ismain = lua_pushthread(L);
+ setboolV(L->top++, ismain);
+ return 2;
+#else
+ if (lua_pushthread(L))
+ setnilV(L->top++);
+ return 1;
+#endif
+}
+
+LJLIB_CF(coroutine_create)
+{
+ lua_State *L1;
+ if (!(L->base < L->top && tvisfunc(L->base)))
+ lj_err_argt(L, 1, LUA_TFUNCTION);
+ L1 = lua_newthread(L);
+ setfuncV(L, L1->top++, funcV(L->base));
+ return 1;
+}
+
+LJLIB_ASM(coroutine_yield)
+{
+ lj_err_caller(L, LJ_ERR_CYIELD);
+ return FFH_UNREACHABLE;
+}
+
+static int ffh_resume(lua_State *L, lua_State *co, int wrap)
+{
+ if (co->cframe != NULL || co->status > LUA_YIELD ||
+ (co->status == 0 && co->top == co->base)) {
+ ErrMsg em = co->cframe ? LJ_ERR_CORUN : LJ_ERR_CODEAD;
+ if (wrap) lj_err_caller(L, em);
+ setboolV(L->base-1, 0);
+ setstrV(L, L->base, lj_err_str(L, em));
+ return FFH_RES(2);
+ }
+ lj_state_growstack(co, (MSize)(L->top - L->base));
+ return FFH_RETRY;
+}
+
+LJLIB_ASM(coroutine_resume)
+{
+ if (!(L->top > L->base && tvisthread(L->base)))
+ lj_err_arg(L, 1, LJ_ERR_NOCORO);
+ return ffh_resume(L, threadV(L->base), 0);
+}
+
+LJLIB_NOREG LJLIB_ASM(coroutine_wrap_aux)
+{
+ return ffh_resume(L, threadV(lj_lib_upvalue(L, 1)), 1);
+}
+
+/* Inline declarations. */
+LJ_ASMF void lj_ff_coroutine_wrap_aux(void);
+#if !(LJ_TARGET_MIPS && defined(ljamalg_c))
+LJ_FUNCA_NORET void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L,
+ lua_State *co);
+#endif
+
+/* Error handler, called from assembler VM. */
+void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L, lua_State *co)
+{
+ co->top--; copyTV(L, L->top, co->top); L->top++;
+ if (tvisstr(L->top-1))
+ lj_err_callermsg(L, strVdata(L->top-1));
+ else
+ lj_err_run(L);
+}
+
+/* Forward declaration. */
+static void setpc_wrap_aux(lua_State *L, GCfunc *fn);
+
+LJLIB_CF(coroutine_wrap)
+{
+ lj_cf_coroutine_create(L);
+ lj_lib_pushcc(L, lj_ffh_coroutine_wrap_aux, FF_coroutine_wrap_aux, 1);
+ setpc_wrap_aux(L, funcV(L->top-1));
+ return 1;
+}
+
+#include "lj_libdef.h"
+
+/* Fix the PC of wrap_aux. Really ugly workaround. */
+static void setpc_wrap_aux(lua_State *L, GCfunc *fn)
+{
+ setmref(fn->c.pc, &L2GG(L)->bcff[lj_lib_init_coroutine[1]+2]);
+}
+
+/* ------------------------------------------------------------------------ */
+
+static void newproxy_weaktable(lua_State *L)
+{
+ /* NOBARRIER: The table is new (marked white). */
+ GCtab *t = lj_tab_new(L, 0, 1);
+ settabV(L, L->top++, t);
+ setgcref(t->metatable, obj2gco(t));
+ setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "__mode")),
+ lj_str_newlit(L, "kv"));
+ t->nomm = (uint8_t)(~(1u<<MM_mode));
+}
+
+LUALIB_API int luaopen_base(lua_State *L)
+{
+ /* NOBARRIER: Table and value are the same. */
+ GCtab *env = tabref(L->env);
+ settabV(L, lj_tab_setstr(L, env, lj_str_newlit(L, "_G")), env);
+ lua_pushliteral(L, LUA_VERSION); /* top-3. */
+ newproxy_weaktable(L); /* top-2. */
+ LJ_LIB_REG(L, "_G", base);
+ LJ_LIB_REG(L, LUA_COLIBNAME, coroutine);
+ return 2;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lib_bit.c b/src/3rdparty/LuaJIT-2.0.5/src/lib_bit.c
new file mode 100644
index 0000000..6dffdfa
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lib_bit.c
@@ -0,0 +1,74 @@
+/*
+** Bit manipulation library.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lib_bit_c
+#define LUA_LIB
+
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+
+#include "lj_obj.h"
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_lib.h"
+
+/* ------------------------------------------------------------------------ */
+
+#define LJLIB_MODULE_bit
+
+LJLIB_ASM(bit_tobit) LJLIB_REC(bit_unary IR_TOBIT)
+{
+ lj_lib_checknumber(L, 1);
+ return FFH_RETRY;
+}
+LJLIB_ASM_(bit_bnot) LJLIB_REC(bit_unary IR_BNOT)
+LJLIB_ASM_(bit_bswap) LJLIB_REC(bit_unary IR_BSWAP)
+
+LJLIB_ASM(bit_lshift) LJLIB_REC(bit_shift IR_BSHL)
+{
+ lj_lib_checknumber(L, 1);
+ lj_lib_checkbit(L, 2);
+ return FFH_RETRY;
+}
+LJLIB_ASM_(bit_rshift) LJLIB_REC(bit_shift IR_BSHR)
+LJLIB_ASM_(bit_arshift) LJLIB_REC(bit_shift IR_BSAR)
+LJLIB_ASM_(bit_rol) LJLIB_REC(bit_shift IR_BROL)
+LJLIB_ASM_(bit_ror) LJLIB_REC(bit_shift IR_BROR)
+
+LJLIB_ASM(bit_band) LJLIB_REC(bit_nary IR_BAND)
+{
+ int i = 0;
+ do { lj_lib_checknumber(L, ++i); } while (L->base+i < L->top);
+ return FFH_RETRY;
+}
+LJLIB_ASM_(bit_bor) LJLIB_REC(bit_nary IR_BOR)
+LJLIB_ASM_(bit_bxor) LJLIB_REC(bit_nary IR_BXOR)
+
+/* ------------------------------------------------------------------------ */
+
+LJLIB_CF(bit_tohex)
+{
+ uint32_t b = (uint32_t)lj_lib_checkbit(L, 1);
+ int32_t i, n = L->base+1 >= L->top ? 8 : lj_lib_checkbit(L, 2);
+ const char *hexdigits = "0123456789abcdef";
+ char buf[8];
+ if (n < 0) { n = -n; hexdigits = "0123456789ABCDEF"; }
+ if (n > 8) n = 8;
+ for (i = n; --i >= 0; ) { buf[i] = hexdigits[b & 15]; b >>= 4; }
+ lua_pushlstring(L, buf, (size_t)n);
+ return 1;
+}
+
+/* ------------------------------------------------------------------------ */
+
+#include "lj_libdef.h"
+
+LUALIB_API int luaopen_bit(lua_State *L)
+{
+ LJ_LIB_REG(L, LUA_BITLIBNAME, bit);
+ return 1;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lib_debug.c b/src/3rdparty/LuaJIT-2.0.5/src/lib_debug.c
new file mode 100644
index 0000000..54c3b7e
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lib_debug.c
@@ -0,0 +1,405 @@
+/*
+** Debug library.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Major portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#define lib_debug_c
+#define LUA_LIB
+
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_debug.h"
+#include "lj_lib.h"
+
+/* ------------------------------------------------------------------------ */
+
+#define LJLIB_MODULE_debug
+
+LJLIB_CF(debug_getregistry)
+{
+ copyTV(L, L->top++, registry(L));
+ return 1;
+}
+
+LJLIB_CF(debug_getmetatable)
+{
+ lj_lib_checkany(L, 1);
+ if (!lua_getmetatable(L, 1)) {
+ setnilV(L->top-1);
+ }
+ return 1;
+}
+
+LJLIB_CF(debug_setmetatable)
+{
+ lj_lib_checktabornil(L, 2);
+ L->top = L->base+2;
+ lua_setmetatable(L, 1);
+#if !LJ_52
+ setboolV(L->top-1, 1);
+#endif
+ return 1;
+}
+
+LJLIB_CF(debug_getfenv)
+{
+ lj_lib_checkany(L, 1);
+ lua_getfenv(L, 1);
+ return 1;
+}
+
+LJLIB_CF(debug_setfenv)
+{
+ lj_lib_checktab(L, 2);
+ L->top = L->base+2;
+ if (!lua_setfenv(L, 1))
+ lj_err_caller(L, LJ_ERR_SETFENV);
+ return 1;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static void settabss(lua_State *L, const char *i, const char *v)
+{
+ lua_pushstring(L, v);
+ lua_setfield(L, -2, i);
+}
+
+static void settabsi(lua_State *L, const char *i, int v)
+{
+ lua_pushinteger(L, v);
+ lua_setfield(L, -2, i);
+}
+
+static void settabsb(lua_State *L, const char *i, int v)
+{
+ lua_pushboolean(L, v);
+ lua_setfield(L, -2, i);
+}
+
+static lua_State *getthread(lua_State *L, int *arg)
+{
+ if (L->base < L->top && tvisthread(L->base)) {
+ *arg = 1;
+ return threadV(L->base);
+ } else {
+ *arg = 0;
+ return L;
+ }
+}
+
+static void treatstackoption(lua_State *L, lua_State *L1, const char *fname)
+{
+ if (L == L1) {
+ lua_pushvalue(L, -2);
+ lua_remove(L, -3);
+ }
+ else
+ lua_xmove(L1, L, 1);
+ lua_setfield(L, -2, fname);
+}
+
+LJLIB_CF(debug_getinfo)
+{
+ lj_Debug ar;
+ int arg, opt_f = 0, opt_L = 0;
+ lua_State *L1 = getthread(L, &arg);
+ const char *options = luaL_optstring(L, arg+2, "flnSu");
+ if (lua_isnumber(L, arg+1)) {
+ if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), (lua_Debug *)&ar)) {
+ setnilV(L->top-1);
+ return 1;
+ }
+ } else if (L->base+arg < L->top && tvisfunc(L->base+arg)) {
+ options = lua_pushfstring(L, ">%s", options);
+ setfuncV(L1, L1->top++, funcV(L->base+arg));
+ } else {
+ lj_err_arg(L, arg+1, LJ_ERR_NOFUNCL);
+ }
+ if (!lj_debug_getinfo(L1, options, &ar, 1))
+ lj_err_arg(L, arg+2, LJ_ERR_INVOPT);
+ lua_createtable(L, 0, 16); /* Create result table. */
+ for (; *options; options++) {
+ switch (*options) {
+ case 'S':
+ settabss(L, "source", ar.source);
+ settabss(L, "short_src", ar.short_src);
+ settabsi(L, "linedefined", ar.linedefined);
+ settabsi(L, "lastlinedefined", ar.lastlinedefined);
+ settabss(L, "what", ar.what);
+ break;
+ case 'l':
+ settabsi(L, "currentline", ar.currentline);
+ break;
+ case 'u':
+ settabsi(L, "nups", ar.nups);
+ settabsi(L, "nparams", ar.nparams);
+ settabsb(L, "isvararg", ar.isvararg);
+ break;
+ case 'n':
+ settabss(L, "name", ar.name);
+ settabss(L, "namewhat", ar.namewhat);
+ break;
+ case 'f': opt_f = 1; break;
+ case 'L': opt_L = 1; break;
+ default: break;
+ }
+ }
+ if (opt_L) treatstackoption(L, L1, "activelines");
+ if (opt_f) treatstackoption(L, L1, "func");
+ return 1; /* Return result table. */
+}
+
+LJLIB_CF(debug_getlocal)
+{
+ int arg;
+ lua_State *L1 = getthread(L, &arg);
+ lua_Debug ar;
+ const char *name;
+ int slot = lj_lib_checkint(L, arg+2);
+ if (tvisfunc(L->base+arg)) {
+ L->top = L->base+arg+1;
+ lua_pushstring(L, lua_getlocal(L, NULL, slot));
+ return 1;
+ }
+ if (!lua_getstack(L1, lj_lib_checkint(L, arg+1), &ar))
+ lj_err_arg(L, arg+1, LJ_ERR_LVLRNG);
+ name = lua_getlocal(L1, &ar, slot);
+ if (name) {
+ lua_xmove(L1, L, 1);
+ lua_pushstring(L, name);
+ lua_pushvalue(L, -2);
+ return 2;
+ } else {
+ setnilV(L->top-1);
+ return 1;
+ }
+}
+
+LJLIB_CF(debug_setlocal)
+{
+ int arg;
+ lua_State *L1 = getthread(L, &arg);
+ lua_Debug ar;
+ TValue *tv;
+ if (!lua_getstack(L1, lj_lib_checkint(L, arg+1), &ar))
+ lj_err_arg(L, arg+1, LJ_ERR_LVLRNG);
+ tv = lj_lib_checkany(L, arg+3);
+ copyTV(L1, L1->top++, tv);
+ lua_pushstring(L, lua_setlocal(L1, &ar, lj_lib_checkint(L, arg+2)));
+ return 1;
+}
+
+static int debug_getupvalue(lua_State *L, int get)
+{
+ int32_t n = lj_lib_checkint(L, 2);
+ const char *name;
+ lj_lib_checkfunc(L, 1);
+ name = get ? lua_getupvalue(L, 1, n) : lua_setupvalue(L, 1, n);
+ if (name) {
+ lua_pushstring(L, name);
+ if (!get) return 1;
+ copyTV(L, L->top, L->top-2);
+ L->top++;
+ return 2;
+ }
+ return 0;
+}
+
+LJLIB_CF(debug_getupvalue)
+{
+ return debug_getupvalue(L, 1);
+}
+
+LJLIB_CF(debug_setupvalue)
+{
+ lj_lib_checkany(L, 3);
+ return debug_getupvalue(L, 0);
+}
+
+LJLIB_CF(debug_upvalueid)
+{
+ GCfunc *fn = lj_lib_checkfunc(L, 1);
+ int32_t n = lj_lib_checkint(L, 2) - 1;
+ if ((uint32_t)n >= fn->l.nupvalues)
+ lj_err_arg(L, 2, LJ_ERR_IDXRNG);
+ setlightudV(L->top-1, isluafunc(fn) ? (void *)gcref(fn->l.uvptr[n]) :
+ (void *)&fn->c.upvalue[n]);
+ return 1;
+}
+
+LJLIB_CF(debug_upvaluejoin)
+{
+ GCfunc *fn[2];
+ GCRef *p[2];
+ int i;
+ for (i = 0; i < 2; i++) {
+ int32_t n;
+ fn[i] = lj_lib_checkfunc(L, 2*i+1);
+ if (!isluafunc(fn[i]))
+ lj_err_arg(L, 2*i+1, LJ_ERR_NOLFUNC);
+ n = lj_lib_checkint(L, 2*i+2) - 1;
+ if ((uint32_t)n >= fn[i]->l.nupvalues)
+ lj_err_arg(L, 2*i+2, LJ_ERR_IDXRNG);
+ p[i] = &fn[i]->l.uvptr[n];
+ }
+ setgcrefr(*p[0], *p[1]);
+ lj_gc_objbarrier(L, fn[0], gcref(*p[1]));
+ return 0;
+}
+
+#if LJ_52
+LJLIB_CF(debug_getuservalue)
+{
+ TValue *o = L->base;
+ if (o < L->top && tvisudata(o))
+ settabV(L, o, tabref(udataV(o)->env));
+ else
+ setnilV(o);
+ L->top = o+1;
+ return 1;
+}
+
+LJLIB_CF(debug_setuservalue)
+{
+ TValue *o = L->base;
+ if (!(o < L->top && tvisudata(o)))
+ lj_err_argt(L, 1, LUA_TUSERDATA);
+ if (!(o+1 < L->top && tvistab(o+1)))
+ lj_err_argt(L, 2, LUA_TTABLE);
+ L->top = o+2;
+ lua_setfenv(L, 1);
+ return 1;
+}
+#endif
+
+/* ------------------------------------------------------------------------ */
+
+static const char KEY_HOOK = 'h';
+
+static void hookf(lua_State *L, lua_Debug *ar)
+{
+ static const char *const hooknames[] =
+ {"call", "return", "line", "count", "tail return"};
+ lua_pushlightuserdata(L, (void *)&KEY_HOOK);
+ lua_rawget(L, LUA_REGISTRYINDEX);
+ if (lua_isfunction(L, -1)) {
+ lua_pushstring(L, hooknames[(int)ar->event]);
+ if (ar->currentline >= 0)
+ lua_pushinteger(L, ar->currentline);
+ else lua_pushnil(L);
+ lua_call(L, 2, 0);
+ }
+}
+
+static int makemask(const char *smask, int count)
+{
+ int mask = 0;
+ if (strchr(smask, 'c')) mask |= LUA_MASKCALL;
+ if (strchr(smask, 'r')) mask |= LUA_MASKRET;
+ if (strchr(smask, 'l')) mask |= LUA_MASKLINE;
+ if (count > 0) mask |= LUA_MASKCOUNT;
+ return mask;
+}
+
+static char *unmakemask(int mask, char *smask)
+{
+ int i = 0;
+ if (mask & LUA_MASKCALL) smask[i++] = 'c';
+ if (mask & LUA_MASKRET) smask[i++] = 'r';
+ if (mask & LUA_MASKLINE) smask[i++] = 'l';
+ smask[i] = '\0';
+ return smask;
+}
+
+LJLIB_CF(debug_sethook)
+{
+ int arg, mask, count;
+ lua_Hook func;
+ (void)getthread(L, &arg);
+ if (lua_isnoneornil(L, arg+1)) {
+ lua_settop(L, arg+1);
+ func = NULL; mask = 0; count = 0; /* turn off hooks */
+ } else {
+ const char *smask = luaL_checkstring(L, arg+2);
+ luaL_checktype(L, arg+1, LUA_TFUNCTION);
+ count = luaL_optint(L, arg+3, 0);
+ func = hookf; mask = makemask(smask, count);
+ }
+ lua_pushlightuserdata(L, (void *)&KEY_HOOK);
+ lua_pushvalue(L, arg+1);
+ lua_rawset(L, LUA_REGISTRYINDEX);
+ lua_sethook(L, func, mask, count);
+ return 0;
+}
+
+LJLIB_CF(debug_gethook)
+{
+ char buff[5];
+ int mask = lua_gethookmask(L);
+ lua_Hook hook = lua_gethook(L);
+ if (hook != NULL && hook != hookf) { /* external hook? */
+ lua_pushliteral(L, "external hook");
+ } else {
+ lua_pushlightuserdata(L, (void *)&KEY_HOOK);
+ lua_rawget(L, LUA_REGISTRYINDEX); /* get hook */
+ }
+ lua_pushstring(L, unmakemask(mask, buff));
+ lua_pushinteger(L, lua_gethookcount(L));
+ return 3;
+}
+
+/* ------------------------------------------------------------------------ */
+
+LJLIB_CF(debug_debug)
+{
+ for (;;) {
+ char buffer[250];
+ fputs("lua_debug> ", stderr);
+ if (fgets(buffer, sizeof(buffer), stdin) == 0 ||
+ strcmp(buffer, "cont\n") == 0)
+ return 0;
+ if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||
+ lua_pcall(L, 0, 0, 0)) {
+ fputs(lua_tostring(L, -1), stderr);
+ fputs("\n", stderr);
+ }
+ lua_settop(L, 0); /* remove eventual returns */
+ }
+}
+
+/* ------------------------------------------------------------------------ */
+
+#define LEVELS1 12 /* size of the first part of the stack */
+#define LEVELS2 10 /* size of the second part of the stack */
+
+LJLIB_CF(debug_traceback)
+{
+ int arg;
+ lua_State *L1 = getthread(L, &arg);
+ const char *msg = lua_tostring(L, arg+1);
+ if (msg == NULL && L->top > L->base+arg)
+ L->top = L->base+arg+1;
+ else
+ luaL_traceback(L, L1, msg, lj_lib_optint(L, arg+2, (L == L1)));
+ return 1;
+}
+
+/* ------------------------------------------------------------------------ */
+
+#include "lj_libdef.h"
+
+LUALIB_API int luaopen_debug(lua_State *L)
+{
+ LJ_LIB_REG(L, LUA_DBLIBNAME, debug);
+ return 1;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lib_ffi.c b/src/3rdparty/LuaJIT-2.0.5/src/lib_ffi.c
new file mode 100644
index 0000000..83483d9
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lib_ffi.c
@@ -0,0 +1,851 @@
+/*
+** FFI library.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lib_ffi_c
+#define LUA_LIB
+
+#include <errno.h>
+
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+
+#include "lj_obj.h"
+
+#if LJ_HASFFI
+
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_meta.h"
+#include "lj_ctype.h"
+#include "lj_cparse.h"
+#include "lj_cdata.h"
+#include "lj_cconv.h"
+#include "lj_carith.h"
+#include "lj_ccall.h"
+#include "lj_ccallback.h"
+#include "lj_clib.h"
+#include "lj_ff.h"
+#include "lj_lib.h"
+
+/* -- C type checks ------------------------------------------------------- */
+
+/* Check first argument for a C type and returns its ID. */
+static CTypeID ffi_checkctype(lua_State *L, CTState *cts, TValue *param)
+{
+ TValue *o = L->base;
+ if (!(o < L->top)) {
+ err_argtype:
+ lj_err_argtype(L, 1, "C type");
+ }
+ if (tvisstr(o)) { /* Parse an abstract C type declaration. */
+ GCstr *s = strV(o);
+ CPState cp;
+ int errcode;
+ cp.L = L;
+ cp.cts = cts;
+ cp.srcname = strdata(s);
+ cp.p = strdata(s);
+ cp.param = param;
+ cp.mode = CPARSE_MODE_ABSTRACT|CPARSE_MODE_NOIMPLICIT;
+ errcode = lj_cparse(&cp);
+ if (errcode) lj_err_throw(L, errcode); /* Propagate errors. */
+ return cp.val.id;
+ } else {
+ GCcdata *cd;
+ if (!tviscdata(o)) goto err_argtype;
+ if (param && param < L->top) lj_err_arg(L, 1, LJ_ERR_FFI_NUMPARAM);
+ cd = cdataV(o);
+ return cd->ctypeid == CTID_CTYPEID ? *(CTypeID *)cdataptr(cd) : cd->ctypeid;
+ }
+}
+
+/* Check argument for C data and return it. */
+static GCcdata *ffi_checkcdata(lua_State *L, int narg)
+{
+ TValue *o = L->base + narg-1;
+ if (!(o < L->top && tviscdata(o)))
+ lj_err_argt(L, narg, LUA_TCDATA);
+ return cdataV(o);
+}
+
+/* Convert argument to C pointer. */
+static void *ffi_checkptr(lua_State *L, int narg, CTypeID id)
+{
+ CTState *cts = ctype_cts(L);
+ TValue *o = L->base + narg-1;
+ void *p;
+ if (o >= L->top)
+ lj_err_arg(L, narg, LJ_ERR_NOVAL);
+ lj_cconv_ct_tv(cts, ctype_get(cts, id), (uint8_t *)&p, o, CCF_ARG(narg));
+ return p;
+}
+
+/* Convert argument to int32_t. */
+static int32_t ffi_checkint(lua_State *L, int narg)
+{
+ CTState *cts = ctype_cts(L);
+ TValue *o = L->base + narg-1;
+ int32_t i;
+ if (o >= L->top)
+ lj_err_arg(L, narg, LJ_ERR_NOVAL);
+ lj_cconv_ct_tv(cts, ctype_get(cts, CTID_INT32), (uint8_t *)&i, o,
+ CCF_ARG(narg));
+ return i;
+}
+
+/* -- C type metamethods -------------------------------------------------- */
+
+#define LJLIB_MODULE_ffi_meta
+
+/* Handle ctype __index/__newindex metamethods. */
+static int ffi_index_meta(lua_State *L, CTState *cts, CType *ct, MMS mm)
+{
+ CTypeID id = ctype_typeid(cts, ct);
+ cTValue *tv = lj_ctype_meta(cts, id, mm);
+ TValue *base = L->base;
+ if (!tv) {
+ const char *s;
+ err_index:
+ s = strdata(lj_ctype_repr(L, id, NULL));
+ if (tvisstr(L->base+1)) {
+ lj_err_callerv(L, LJ_ERR_FFI_BADMEMBER, s, strVdata(L->base+1));
+ } else {
+ const char *key = tviscdata(L->base+1) ?
+ strdata(lj_ctype_repr(L, cdataV(L->base+1)->ctypeid, NULL)) :
+ lj_typename(L->base+1);
+ lj_err_callerv(L, LJ_ERR_FFI_BADIDXW, s, key);
+ }
+ }
+ if (!tvisfunc(tv)) {
+ if (mm == MM_index) {
+ cTValue *o = lj_meta_tget(L, tv, base+1);
+ if (o) {
+ if (tvisnil(o)) goto err_index;
+ copyTV(L, L->top-1, o);
+ return 1;
+ }
+ } else {
+ TValue *o = lj_meta_tset(L, tv, base+1);
+ if (o) {
+ copyTV(L, o, base+2);
+ return 0;
+ }
+ }
+ copyTV(L, base, L->top);
+ tv = L->top-1;
+ }
+ return lj_meta_tailcall(L, tv);
+}
+
+LJLIB_CF(ffi_meta___index) LJLIB_REC(cdata_index 0)
+{
+ CTState *cts = ctype_cts(L);
+ CTInfo qual = 0;
+ CType *ct;
+ uint8_t *p;
+ TValue *o = L->base;
+ if (!(o+1 < L->top && tviscdata(o))) /* Also checks for presence of key. */
+ lj_err_argt(L, 1, LUA_TCDATA);
+ ct = lj_cdata_index(cts, cdataV(o), o+1, &p, &qual);
+ if ((qual & 1))
+ return ffi_index_meta(L, cts, ct, MM_index);
+ if (lj_cdata_get(cts, ct, L->top-1, p))
+ lj_gc_check(L);
+ return 1;
+}
+
+LJLIB_CF(ffi_meta___newindex) LJLIB_REC(cdata_index 1)
+{
+ CTState *cts = ctype_cts(L);
+ CTInfo qual = 0;
+ CType *ct;
+ uint8_t *p;
+ TValue *o = L->base;
+ if (!(o+2 < L->top && tviscdata(o))) /* Also checks for key and value. */
+ lj_err_argt(L, 1, LUA_TCDATA);
+ ct = lj_cdata_index(cts, cdataV(o), o+1, &p, &qual);
+ if ((qual & 1)) {
+ if ((qual & CTF_CONST))
+ lj_err_caller(L, LJ_ERR_FFI_WRCONST);
+ return ffi_index_meta(L, cts, ct, MM_newindex);
+ }
+ lj_cdata_set(cts, ct, p, o+2, qual);
+ return 0;
+}
+
+/* Common handler for cdata arithmetic. */
+static int ffi_arith(lua_State *L)
+{
+ MMS mm = (MMS)(curr_func(L)->c.ffid - (int)FF_ffi_meta___eq + (int)MM_eq);
+ return lj_carith_op(L, mm);
+}
+
+/* The following functions must be in contiguous ORDER MM. */
+LJLIB_CF(ffi_meta___eq) LJLIB_REC(cdata_arith MM_eq)
+{
+ return ffi_arith(L);
+}
+
+LJLIB_CF(ffi_meta___len) LJLIB_REC(cdata_arith MM_len)
+{
+ return lj_carith_len(L);
+}
+
+LJLIB_CF(ffi_meta___lt) LJLIB_REC(cdata_arith MM_lt)
+{
+ return ffi_arith(L);
+}
+
+LJLIB_CF(ffi_meta___le) LJLIB_REC(cdata_arith MM_le)
+{
+ return ffi_arith(L);
+}
+
+LJLIB_CF(ffi_meta___concat) LJLIB_REC(cdata_arith MM_concat)
+{
+ return ffi_arith(L);
+}
+
+/* Forward declaration. */
+static int lj_cf_ffi_new(lua_State *L);
+
+LJLIB_CF(ffi_meta___call) LJLIB_REC(cdata_call)
+{
+ CTState *cts = ctype_cts(L);
+ GCcdata *cd = ffi_checkcdata(L, 1);
+ CTypeID id = cd->ctypeid;
+ CType *ct;
+ cTValue *tv;
+ MMS mm = MM_call;
+ if (cd->ctypeid == CTID_CTYPEID) {
+ id = *(CTypeID *)cdataptr(cd);
+ mm = MM_new;
+ } else {
+ int ret = lj_ccall_func(L, cd);
+ if (ret >= 0)
+ return ret;
+ }
+ /* Handle ctype __call/__new metamethod. */
+ ct = ctype_raw(cts, id);
+ if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);
+ tv = lj_ctype_meta(cts, id, mm);
+ if (tv)
+ return lj_meta_tailcall(L, tv);
+ else if (mm == MM_call)
+ lj_err_callerv(L, LJ_ERR_FFI_BADCALL, strdata(lj_ctype_repr(L, id, NULL)));
+ return lj_cf_ffi_new(L);
+}
+
+LJLIB_CF(ffi_meta___add) LJLIB_REC(cdata_arith MM_add)
+{
+ return ffi_arith(L);
+}
+
+LJLIB_CF(ffi_meta___sub) LJLIB_REC(cdata_arith MM_sub)
+{
+ return ffi_arith(L);
+}
+
+LJLIB_CF(ffi_meta___mul) LJLIB_REC(cdata_arith MM_mul)
+{
+ return ffi_arith(L);
+}
+
+LJLIB_CF(ffi_meta___div) LJLIB_REC(cdata_arith MM_div)
+{
+ return ffi_arith(L);
+}
+
+LJLIB_CF(ffi_meta___mod) LJLIB_REC(cdata_arith MM_mod)
+{
+ return ffi_arith(L);
+}
+
+LJLIB_CF(ffi_meta___pow) LJLIB_REC(cdata_arith MM_pow)
+{
+ return ffi_arith(L);
+}
+
+LJLIB_CF(ffi_meta___unm) LJLIB_REC(cdata_arith MM_unm)
+{
+ return ffi_arith(L);
+}
+/* End of contiguous ORDER MM. */
+
+LJLIB_CF(ffi_meta___tostring)
+{
+ GCcdata *cd = ffi_checkcdata(L, 1);
+ const char *msg = "cdata<%s>: %p";
+ CTypeID id = cd->ctypeid;
+ void *p = cdataptr(cd);
+ if (id == CTID_CTYPEID) {
+ msg = "ctype<%s>";
+ id = *(CTypeID *)p;
+ } else {
+ CTState *cts = ctype_cts(L);
+ CType *ct = ctype_raw(cts, id);
+ if (ctype_isref(ct->info)) {
+ p = *(void **)p;
+ ct = ctype_rawchild(cts, ct);
+ }
+ if (ctype_iscomplex(ct->info)) {
+ setstrV(L, L->top-1, lj_ctype_repr_complex(L, cdataptr(cd), ct->size));
+ goto checkgc;
+ } else if (ct->size == 8 && ctype_isinteger(ct->info)) {
+ setstrV(L, L->top-1, lj_ctype_repr_int64(L, *(uint64_t *)cdataptr(cd),
+ (ct->info & CTF_UNSIGNED)));
+ goto checkgc;
+ } else if (ctype_isfunc(ct->info)) {
+ p = *(void **)p;
+ } else if (ctype_isenum(ct->info)) {
+ msg = "cdata<%s>: %d";
+ p = (void *)(uintptr_t)*(uint32_t **)p;
+ } else {
+ if (ctype_isptr(ct->info)) {
+ p = cdata_getptr(p, ct->size);
+ ct = ctype_rawchild(cts, ct);
+ }
+ if (ctype_isstruct(ct->info) || ctype_isvector(ct->info)) {
+ /* Handle ctype __tostring metamethod. */
+ cTValue *tv = lj_ctype_meta(cts, ctype_typeid(cts, ct), MM_tostring);
+ if (tv)
+ return lj_meta_tailcall(L, tv);
+ }
+ }
+ }
+ lj_str_pushf(L, msg, strdata(lj_ctype_repr(L, id, NULL)), p);
+checkgc:
+ lj_gc_check(L);
+ return 1;
+}
+
+static int ffi_pairs(lua_State *L, MMS mm)
+{
+ CTState *cts = ctype_cts(L);
+ CTypeID id = ffi_checkcdata(L, 1)->ctypeid;
+ CType *ct = ctype_raw(cts, id);
+ cTValue *tv;
+ if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);
+ tv = lj_ctype_meta(cts, id, mm);
+ if (!tv)
+ lj_err_callerv(L, LJ_ERR_FFI_BADMM, strdata(lj_ctype_repr(L, id, NULL)),
+ strdata(mmname_str(G(L), mm)));
+ return lj_meta_tailcall(L, tv);
+}
+
+LJLIB_CF(ffi_meta___pairs)
+{
+ return ffi_pairs(L, MM_pairs);
+}
+
+LJLIB_CF(ffi_meta___ipairs)
+{
+ return ffi_pairs(L, MM_ipairs);
+}
+
+LJLIB_PUSH("ffi") LJLIB_SET(__metatable)
+
+#include "lj_libdef.h"
+
+/* -- C library metamethods ----------------------------------------------- */
+
+#define LJLIB_MODULE_ffi_clib
+
+/* Index C library by a name. */
+static TValue *ffi_clib_index(lua_State *L)
+{
+ TValue *o = L->base;
+ CLibrary *cl;
+ if (!(o < L->top && tvisudata(o) && udataV(o)->udtype == UDTYPE_FFI_CLIB))
+ lj_err_argt(L, 1, LUA_TUSERDATA);
+ cl = (CLibrary *)uddata(udataV(o));
+ if (!(o+1 < L->top && tvisstr(o+1)))
+ lj_err_argt(L, 2, LUA_TSTRING);
+ return lj_clib_index(L, cl, strV(o+1));
+}
+
+LJLIB_CF(ffi_clib___index) LJLIB_REC(clib_index 1)
+{
+ TValue *tv = ffi_clib_index(L);
+ if (tviscdata(tv)) {
+ CTState *cts = ctype_cts(L);
+ GCcdata *cd = cdataV(tv);
+ CType *s = ctype_get(cts, cd->ctypeid);
+ if (ctype_isextern(s->info)) {
+ CTypeID sid = ctype_cid(s->info);
+ void *sp = *(void **)cdataptr(cd);
+ CType *ct = ctype_raw(cts, sid);
+ if (lj_cconv_tv_ct(cts, ct, sid, L->top-1, sp))
+ lj_gc_check(L);
+ return 1;
+ }
+ }
+ copyTV(L, L->top-1, tv);
+ return 1;
+}
+
+LJLIB_CF(ffi_clib___newindex) LJLIB_REC(clib_index 0)
+{
+ TValue *tv = ffi_clib_index(L);
+ TValue *o = L->base+2;
+ if (o < L->top && tviscdata(tv)) {
+ CTState *cts = ctype_cts(L);
+ GCcdata *cd = cdataV(tv);
+ CType *d = ctype_get(cts, cd->ctypeid);
+ if (ctype_isextern(d->info)) {
+ CTInfo qual = 0;
+ for (;;) { /* Skip attributes and collect qualifiers. */
+ d = ctype_child(cts, d);
+ if (!ctype_isattrib(d->info)) break;
+ if (ctype_attrib(d->info) == CTA_QUAL) qual |= d->size;
+ }
+ if (!((d->info|qual) & CTF_CONST)) {
+ lj_cconv_ct_tv(cts, d, *(void **)cdataptr(cd), o, 0);
+ return 0;
+ }
+ }
+ }
+ lj_err_caller(L, LJ_ERR_FFI_WRCONST);
+ return 0; /* unreachable */
+}
+
+LJLIB_CF(ffi_clib___gc)
+{
+ TValue *o = L->base;
+ if (o < L->top && tvisudata(o) && udataV(o)->udtype == UDTYPE_FFI_CLIB)
+ lj_clib_unload((CLibrary *)uddata(udataV(o)));
+ return 0;
+}
+
+#include "lj_libdef.h"
+
+/* -- Callback function metamethods --------------------------------------- */
+
+#define LJLIB_MODULE_ffi_callback
+
+static int ffi_callback_set(lua_State *L, GCfunc *fn)
+{
+ GCcdata *cd = ffi_checkcdata(L, 1);
+ CTState *cts = ctype_cts(L);
+ CType *ct = ctype_raw(cts, cd->ctypeid);
+ if (ctype_isptr(ct->info) && (LJ_32 || ct->size == 8)) {
+ MSize slot = lj_ccallback_ptr2slot(cts, *(void **)cdataptr(cd));
+ if (slot < cts->cb.sizeid && cts->cb.cbid[slot] != 0) {
+ GCtab *t = cts->miscmap;
+ TValue *tv = lj_tab_setint(L, t, (int32_t)slot);
+ if (fn) {
+ setfuncV(L, tv, fn);
+ lj_gc_anybarriert(L, t);
+ } else {
+ setnilV(tv);
+ cts->cb.cbid[slot] = 0;
+ cts->cb.topid = slot < cts->cb.topid ? slot : cts->cb.topid;
+ }
+ return 0;
+ }
+ }
+ lj_err_caller(L, LJ_ERR_FFI_BADCBACK);
+ return 0;
+}
+
+LJLIB_CF(ffi_callback_free)
+{
+ return ffi_callback_set(L, NULL);
+}
+
+LJLIB_CF(ffi_callback_set)
+{
+ GCfunc *fn = lj_lib_checkfunc(L, 2);
+ return ffi_callback_set(L, fn);
+}
+
+LJLIB_PUSH(top-1) LJLIB_SET(__index)
+
+#include "lj_libdef.h"
+
+/* -- FFI library functions ----------------------------------------------- */
+
+#define LJLIB_MODULE_ffi
+
+LJLIB_CF(ffi_cdef)
+{
+ GCstr *s = lj_lib_checkstr(L, 1);
+ CPState cp;
+ int errcode;
+ cp.L = L;
+ cp.cts = ctype_cts(L);
+ cp.srcname = strdata(s);
+ cp.p = strdata(s);
+ cp.param = L->base+1;
+ cp.mode = CPARSE_MODE_MULTI|CPARSE_MODE_DIRECT;
+ errcode = lj_cparse(&cp);
+ if (errcode) lj_err_throw(L, errcode); /* Propagate errors. */
+ lj_gc_check(L);
+ return 0;
+}
+
+LJLIB_CF(ffi_new) LJLIB_REC(.)
+{
+ CTState *cts = ctype_cts(L);
+ CTypeID id = ffi_checkctype(L, cts, NULL);
+ CType *ct = ctype_raw(cts, id);
+ CTSize sz;
+ CTInfo info = lj_ctype_info(cts, id, &sz);
+ TValue *o = L->base+1;
+ GCcdata *cd;
+ if ((info & CTF_VLA)) {
+ o++;
+ sz = lj_ctype_vlsize(cts, ct, (CTSize)ffi_checkint(L, 2));
+ }
+ if (sz == CTSIZE_INVALID)
+ lj_err_arg(L, 1, LJ_ERR_FFI_INVSIZE);
+ if (!(info & CTF_VLA) && ctype_align(info) <= CT_MEMALIGN)
+ cd = lj_cdata_new(cts, id, sz);
+ else
+ cd = lj_cdata_newv(cts, id, sz, ctype_align(info));
+ setcdataV(L, o-1, cd); /* Anchor the uninitialized cdata. */
+ lj_cconv_ct_init(cts, ct, sz, cdataptr(cd),
+ o, (MSize)(L->top - o)); /* Initialize cdata. */
+ if (ctype_isstruct(ct->info)) {
+ /* Handle ctype __gc metamethod. Use the fast lookup here. */
+ cTValue *tv = lj_tab_getinth(cts->miscmap, -(int32_t)id);
+ if (tv && tvistab(tv) && (tv = lj_meta_fast(L, tabV(tv), MM_gc))) {
+ GCtab *t = cts->finalizer;
+ if (gcref(t->metatable)) {
+ /* Add to finalizer table, if still enabled. */
+ copyTV(L, lj_tab_set(L, t, o-1), tv);
+ lj_gc_anybarriert(L, t);
+ cd->marked |= LJ_GC_CDATA_FIN;
+ }
+ }
+ }
+ L->top = o; /* Only return the cdata itself. */
+ lj_gc_check(L);
+ return 1;
+}
+
+LJLIB_CF(ffi_cast) LJLIB_REC(ffi_new)
+{
+ CTState *cts = ctype_cts(L);
+ CTypeID id = ffi_checkctype(L, cts, NULL);
+ CType *d = ctype_raw(cts, id);
+ TValue *o = lj_lib_checkany(L, 2);
+ L->top = o+1; /* Make sure this is the last item on the stack. */
+ if (!(ctype_isnum(d->info) || ctype_isptr(d->info) || ctype_isenum(d->info)))
+ lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE);
+ if (!(tviscdata(o) && cdataV(o)->ctypeid == id)) {
+ GCcdata *cd = lj_cdata_new(cts, id, d->size);
+ lj_cconv_ct_tv(cts, d, cdataptr(cd), o, CCF_CAST);
+ setcdataV(L, o, cd);
+ lj_gc_check(L);
+ }
+ return 1;
+}
+
+LJLIB_CF(ffi_typeof) LJLIB_REC(.)
+{
+ CTState *cts = ctype_cts(L);
+ CTypeID id = ffi_checkctype(L, cts, L->base+1);
+ GCcdata *cd = lj_cdata_new(cts, CTID_CTYPEID, 4);
+ *(CTypeID *)cdataptr(cd) = id;
+ setcdataV(L, L->top-1, cd);
+ lj_gc_check(L);
+ return 1;
+}
+
+LJLIB_CF(ffi_istype) LJLIB_REC(.)
+{
+ CTState *cts = ctype_cts(L);
+ CTypeID id1 = ffi_checkctype(L, cts, NULL);
+ TValue *o = lj_lib_checkany(L, 2);
+ int b = 0;
+ if (tviscdata(o)) {
+ GCcdata *cd = cdataV(o);
+ CTypeID id2 = cd->ctypeid == CTID_CTYPEID ? *(CTypeID *)cdataptr(cd) :
+ cd->ctypeid;
+ CType *ct1 = lj_ctype_rawref(cts, id1);
+ CType *ct2 = lj_ctype_rawref(cts, id2);
+ if (ct1 == ct2) {
+ b = 1;
+ } else if (ctype_type(ct1->info) == ctype_type(ct2->info) &&
+ ct1->size == ct2->size) {
+ if (ctype_ispointer(ct1->info))
+ b = lj_cconv_compatptr(cts, ct1, ct2, CCF_IGNQUAL);
+ else if (ctype_isnum(ct1->info) || ctype_isvoid(ct1->info))
+ b = (((ct1->info ^ ct2->info) & ~(CTF_QUAL|CTF_LONG)) == 0);
+ } else if (ctype_isstruct(ct1->info) && ctype_isptr(ct2->info) &&
+ ct1 == ctype_rawchild(cts, ct2)) {
+ b = 1;
+ }
+ }
+ setboolV(L->top-1, b);
+ setboolV(&G(L)->tmptv2, b); /* Remember for trace recorder. */
+ return 1;
+}
+
+LJLIB_CF(ffi_sizeof) LJLIB_REC(ffi_xof FF_ffi_sizeof)
+{
+ CTState *cts = ctype_cts(L);
+ CTypeID id = ffi_checkctype(L, cts, NULL);
+ CTSize sz;
+ if (LJ_UNLIKELY(tviscdata(L->base) && cdataisv(cdataV(L->base)))) {
+ sz = cdatavlen(cdataV(L->base));
+ } else {
+ CType *ct = lj_ctype_rawref(cts, id);
+ if (ctype_isvltype(ct->info))
+ sz = lj_ctype_vlsize(cts, ct, (CTSize)ffi_checkint(L, 2));
+ else
+ sz = ctype_hassize(ct->info) ? ct->size : CTSIZE_INVALID;
+ if (LJ_UNLIKELY(sz == CTSIZE_INVALID)) {
+ setnilV(L->top-1);
+ return 1;
+ }
+ }
+ setintV(L->top-1, (int32_t)sz);
+ return 1;
+}
+
+LJLIB_CF(ffi_alignof) LJLIB_REC(ffi_xof FF_ffi_alignof)
+{
+ CTState *cts = ctype_cts(L);
+ CTypeID id = ffi_checkctype(L, cts, NULL);
+ CTSize sz = 0;
+ CTInfo info = lj_ctype_info(cts, id, &sz);
+ setintV(L->top-1, 1 << ctype_align(info));
+ return 1;
+}
+
+LJLIB_CF(ffi_offsetof) LJLIB_REC(ffi_xof FF_ffi_offsetof)
+{
+ CTState *cts = ctype_cts(L);
+ CTypeID id = ffi_checkctype(L, cts, NULL);
+ GCstr *name = lj_lib_checkstr(L, 2);
+ CType *ct = lj_ctype_rawref(cts, id);
+ CTSize ofs;
+ if (ctype_isstruct(ct->info) && ct->size != CTSIZE_INVALID) {
+ CType *fct = lj_ctype_getfield(cts, ct, name, &ofs);
+ if (fct) {
+ setintV(L->top-1, ofs);
+ if (ctype_isfield(fct->info)) {
+ return 1;
+ } else if (ctype_isbitfield(fct->info)) {
+ setintV(L->top++, ctype_bitpos(fct->info));
+ setintV(L->top++, ctype_bitbsz(fct->info));
+ return 3;
+ }
+ }
+ }
+ return 0;
+}
+
+LJLIB_CF(ffi_errno) LJLIB_REC(.)
+{
+ int err = errno;
+ if (L->top > L->base)
+ errno = ffi_checkint(L, 1);
+ setintV(L->top++, err);
+ return 1;
+}
+
+LJLIB_CF(ffi_string) LJLIB_REC(.)
+{
+ CTState *cts = ctype_cts(L);
+ TValue *o = lj_lib_checkany(L, 1);
+ const char *p;
+ size_t len;
+ if (o+1 < L->top && !tvisnil(o+1)) {
+ len = (size_t)ffi_checkint(L, 2);
+ lj_cconv_ct_tv(cts, ctype_get(cts, CTID_P_CVOID), (uint8_t *)&p, o,
+ CCF_ARG(1));
+ } else {
+ lj_cconv_ct_tv(cts, ctype_get(cts, CTID_P_CCHAR), (uint8_t *)&p, o,
+ CCF_ARG(1));
+ len = strlen(p);
+ }
+ L->top = o+1; /* Make sure this is the last item on the stack. */
+ setstrV(L, o, lj_str_new(L, p, len));
+ lj_gc_check(L);
+ return 1;
+}
+
+LJLIB_CF(ffi_copy) LJLIB_REC(.)
+{
+ void *dp = ffi_checkptr(L, 1, CTID_P_VOID);
+ void *sp = ffi_checkptr(L, 2, CTID_P_CVOID);
+ TValue *o = L->base+1;
+ CTSize len;
+ if (tvisstr(o) && o+1 >= L->top)
+ len = strV(o)->len+1; /* Copy Lua string including trailing '\0'. */
+ else
+ len = (CTSize)ffi_checkint(L, 3);
+ memcpy(dp, sp, len);
+ return 0;
+}
+
+LJLIB_CF(ffi_fill) LJLIB_REC(.)
+{
+ void *dp = ffi_checkptr(L, 1, CTID_P_VOID);
+ CTSize len = (CTSize)ffi_checkint(L, 2);
+ int32_t fill = 0;
+ if (L->base+2 < L->top && !tvisnil(L->base+2)) fill = ffi_checkint(L, 3);
+ memset(dp, fill, len);
+ return 0;
+}
+
+#define H_(le, be) LJ_ENDIAN_SELECT(0x##le, 0x##be)
+
+/* Test ABI string. */
+LJLIB_CF(ffi_abi) LJLIB_REC(.)
+{
+ GCstr *s = lj_lib_checkstr(L, 1);
+ int b = 0;
+ switch (s->hash) {
+#if LJ_64
+ case H_(849858eb,ad35fd06): b = 1; break; /* 64bit */
+#else
+ case H_(662d3c79,d0e22477): b = 1; break; /* 32bit */
+#endif
+#if LJ_ARCH_HASFPU
+ case H_(e33ee463,e33ee463): b = 1; break; /* fpu */
+#endif
+#if LJ_ABI_SOFTFP
+ case H_(61211a23,c2e8c81c): b = 1; break; /* softfp */
+#else
+ case H_(539417a8,8ce0812f): b = 1; break; /* hardfp */
+#endif
+#if LJ_ABI_EABI
+ case H_(2182df8f,f2ed1152): b = 1; break; /* eabi */
+#endif
+#if LJ_ABI_WIN
+ case H_(4ab624a8,4ab624a8): b = 1; break; /* win */
+#endif
+ case H_(3af93066,1f001464): b = 1; break; /* le/be */
+ default:
+ break;
+ }
+ setboolV(L->top-1, b);
+ setboolV(&G(L)->tmptv2, b); /* Remember for trace recorder. */
+ return 1;
+}
+
+#undef H_
+
+LJLIB_PUSH(top-8) LJLIB_SET(!) /* Store reference to miscmap table. */
+
+LJLIB_CF(ffi_metatype)
+{
+ CTState *cts = ctype_cts(L);
+ CTypeID id = ffi_checkctype(L, cts, NULL);
+ GCtab *mt = lj_lib_checktab(L, 2);
+ GCtab *t = cts->miscmap;
+ CType *ct = ctype_get(cts, id); /* Only allow raw types. */
+ TValue *tv;
+ GCcdata *cd;
+ if (!(ctype_isstruct(ct->info) || ctype_iscomplex(ct->info) ||
+ ctype_isvector(ct->info)))
+ lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE);
+ tv = lj_tab_setinth(L, t, -(int32_t)id);
+ if (!tvisnil(tv))
+ lj_err_caller(L, LJ_ERR_PROTMT);
+ settabV(L, tv, mt);
+ lj_gc_anybarriert(L, t);
+ cd = lj_cdata_new(cts, CTID_CTYPEID, 4);
+ *(CTypeID *)cdataptr(cd) = id;
+ setcdataV(L, L->top-1, cd);
+ lj_gc_check(L);
+ return 1;
+}
+
+LJLIB_PUSH(top-7) LJLIB_SET(!) /* Store reference to finalizer table. */
+
+LJLIB_CF(ffi_gc) LJLIB_REC(.)
+{
+ GCcdata *cd = ffi_checkcdata(L, 1);
+ TValue *fin = lj_lib_checkany(L, 2);
+ CTState *cts = ctype_cts(L);
+ GCtab *t = cts->finalizer;
+ CType *ct = ctype_raw(cts, cd->ctypeid);
+ if (!(ctype_isptr(ct->info) || ctype_isstruct(ct->info) ||
+ ctype_isrefarray(ct->info)))
+ lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE);
+ if (gcref(t->metatable)) { /* Update finalizer table, if still enabled. */
+ copyTV(L, lj_tab_set(L, t, L->base), fin);
+ lj_gc_anybarriert(L, t);
+ if (!tvisnil(fin))
+ cd->marked |= LJ_GC_CDATA_FIN;
+ else
+ cd->marked &= ~LJ_GC_CDATA_FIN;
+ }
+ L->top = L->base+1; /* Pass through the cdata object. */
+ return 1;
+}
+
+LJLIB_PUSH(top-5) LJLIB_SET(!) /* Store clib metatable in func environment. */
+
+LJLIB_CF(ffi_load)
+{
+ GCstr *name = lj_lib_checkstr(L, 1);
+ int global = (L->base+1 < L->top && tvistruecond(L->base+1));
+ lj_clib_load(L, tabref(curr_func(L)->c.env), name, global);
+ return 1;
+}
+
+LJLIB_PUSH(top-4) LJLIB_SET(C)
+LJLIB_PUSH(top-3) LJLIB_SET(os)
+LJLIB_PUSH(top-2) LJLIB_SET(arch)
+
+#include "lj_libdef.h"
+
+/* ------------------------------------------------------------------------ */
+
+/* Create special weak-keyed finalizer table. */
+static GCtab *ffi_finalizer(lua_State *L)
+{
+ /* NOBARRIER: The table is new (marked white). */
+ GCtab *t = lj_tab_new(L, 0, 1);
+ settabV(L, L->top++, t);
+ setgcref(t->metatable, obj2gco(t));
+ setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "__mode")),
+ lj_str_newlit(L, "k"));
+ t->nomm = (uint8_t)(~(1u<<MM_mode));
+ return t;
+}
+
+/* Register FFI module as loaded. */
+static void ffi_register_module(lua_State *L)
+{
+ cTValue *tmp = lj_tab_getstr(tabV(registry(L)), lj_str_newlit(L, "_LOADED"));
+ if (tmp && tvistab(tmp)) {
+ GCtab *t = tabV(tmp);
+ copyTV(L, lj_tab_setstr(L, t, lj_str_newlit(L, LUA_FFILIBNAME)), L->top-1);
+ lj_gc_anybarriert(L, t);
+ }
+}
+
+LUALIB_API int luaopen_ffi(lua_State *L)
+{
+ CTState *cts = lj_ctype_init(L);
+ settabV(L, L->top++, (cts->miscmap = lj_tab_new(L, 0, 1)));
+ cts->finalizer = ffi_finalizer(L);
+ LJ_LIB_REG(L, NULL, ffi_meta);
+ /* NOBARRIER: basemt is a GC root. */
+ setgcref(basemt_it(G(L), LJ_TCDATA), obj2gco(tabV(L->top-1)));
+ LJ_LIB_REG(L, NULL, ffi_clib);
+ LJ_LIB_REG(L, NULL, ffi_callback);
+ /* NOBARRIER: the key is new and lj_tab_newkey() handles the barrier. */
+ settabV(L, lj_tab_setstr(L, cts->miscmap, &cts->g->strempty), tabV(L->top-1));
+ L->top--;
+ lj_clib_default(L, tabV(L->top-1)); /* Create ffi.C default namespace. */
+ lua_pushliteral(L, LJ_OS_NAME);
+ lua_pushliteral(L, LJ_ARCH_NAME);
+ LJ_LIB_REG(L, NULL, ffi); /* Note: no global "ffi" created! */
+ ffi_register_module(L);
+ return 1;
+}
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lib_init.c b/src/3rdparty/LuaJIT-2.0.5/src/lib_init.c
new file mode 100644
index 0000000..2ed370e
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lib_init.c
@@ -0,0 +1,55 @@
+/*
+** Library initialization.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Major parts taken verbatim from the Lua interpreter.
+** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#define lib_init_c
+#define LUA_LIB
+
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+
+#include "lj_arch.h"
+
+static const luaL_Reg lj_lib_load[] = {
+ { "", luaopen_base },
+ { LUA_LOADLIBNAME, luaopen_package },
+ { LUA_TABLIBNAME, luaopen_table },
+ { LUA_IOLIBNAME, luaopen_io },
+ { LUA_OSLIBNAME, luaopen_os },
+ { LUA_STRLIBNAME, luaopen_string },
+ { LUA_MATHLIBNAME, luaopen_math },
+ { LUA_DBLIBNAME, luaopen_debug },
+ { LUA_BITLIBNAME, luaopen_bit },
+ { LUA_JITLIBNAME, luaopen_jit },
+ { NULL, NULL }
+};
+
+static const luaL_Reg lj_lib_preload[] = {
+#if LJ_HASFFI
+ { LUA_FFILIBNAME, luaopen_ffi },
+#endif
+ { NULL, NULL }
+};
+
+LUALIB_API void luaL_openlibs(lua_State *L)
+{
+ const luaL_Reg *lib;
+ for (lib = lj_lib_load; lib->func; lib++) {
+ lua_pushcfunction(L, lib->func);
+ lua_pushstring(L, lib->name);
+ lua_call(L, 1, 0);
+ }
+ luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD",
+ sizeof(lj_lib_preload)/sizeof(lj_lib_preload[0])-1);
+ for (lib = lj_lib_preload; lib->func; lib++) {
+ lua_pushcfunction(L, lib->func);
+ lua_setfield(L, -2, lib->name);
+ }
+ lua_pop(L, 1);
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lib_io.c b/src/3rdparty/LuaJIT-2.0.5/src/lib_io.c
new file mode 100644
index 0000000..9cdcfcf
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lib_io.c
@@ -0,0 +1,546 @@
+/*
+** I/O library.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Major portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2011 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#include <errno.h>
+#include <stdio.h>
+
+#define lib_io_c
+#define LUA_LIB
+
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_state.h"
+#include "lj_ff.h"
+#include "lj_lib.h"
+
+/* Userdata payload for I/O file. */
+typedef struct IOFileUD {
+ FILE *fp; /* File handle. */
+ uint32_t type; /* File type. */
+} IOFileUD;
+
+#define IOFILE_TYPE_FILE 0 /* Regular file. */
+#define IOFILE_TYPE_PIPE 1 /* Pipe. */
+#define IOFILE_TYPE_STDF 2 /* Standard file handle. */
+#define IOFILE_TYPE_MASK 3
+
+#define IOFILE_FLAG_CLOSE 4 /* Close after io.lines() iterator. */
+
+#define IOSTDF_UD(L, id) (&gcref(G(L)->gcroot[(id)])->ud)
+#define IOSTDF_IOF(L, id) ((IOFileUD *)uddata(IOSTDF_UD(L, (id))))
+
+/* -- Open/close helpers -------------------------------------------------- */
+
+static IOFileUD *io_tofilep(lua_State *L)
+{
+ if (!(L->base < L->top && tvisudata(L->base) &&
+ udataV(L->base)->udtype == UDTYPE_IO_FILE))
+ lj_err_argtype(L, 1, "FILE*");
+ return (IOFileUD *)uddata(udataV(L->base));
+}
+
+static IOFileUD *io_tofile(lua_State *L)
+{
+ IOFileUD *iof = io_tofilep(L);
+ if (iof->fp == NULL)
+ lj_err_caller(L, LJ_ERR_IOCLFL);
+ return iof;
+}
+
+static FILE *io_stdfile(lua_State *L, ptrdiff_t id)
+{
+ IOFileUD *iof = IOSTDF_IOF(L, id);
+ if (iof->fp == NULL)
+ lj_err_caller(L, LJ_ERR_IOSTDCL);
+ return iof->fp;
+}
+
+static IOFileUD *io_file_new(lua_State *L)
+{
+ IOFileUD *iof = (IOFileUD *)lua_newuserdata(L, sizeof(IOFileUD));
+ GCudata *ud = udataV(L->top-1);
+ ud->udtype = UDTYPE_IO_FILE;
+ /* NOBARRIER: The GCudata is new (marked white). */
+ setgcrefr(ud->metatable, curr_func(L)->c.env);
+ iof->fp = NULL;
+ iof->type = IOFILE_TYPE_FILE;
+ return iof;
+}
+
+static IOFileUD *io_file_open(lua_State *L, const char *mode)
+{
+ const char *fname = strdata(lj_lib_checkstr(L, 1));
+ IOFileUD *iof = io_file_new(L);
+ iof->fp = fopen(fname, mode);
+ if (iof->fp == NULL)
+ luaL_argerror(L, 1, lj_str_pushf(L, "%s: %s", fname, strerror(errno)));
+ return iof;
+}
+
+static int io_file_close(lua_State *L, IOFileUD *iof)
+{
+ int ok;
+ if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_FILE) {
+ ok = (fclose(iof->fp) == 0);
+ } else if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_PIPE) {
+ int stat = -1;
+#if LJ_TARGET_POSIX
+ stat = pclose(iof->fp);
+#elif LJ_TARGET_WINDOWS
+ stat = _pclose(iof->fp);
+#else
+ lua_assert(0);
+ return 0;
+#endif
+#if LJ_52
+ iof->fp = NULL;
+ return luaL_execresult(L, stat);
+#else
+ ok = (stat != -1);
+#endif
+ } else {
+ lua_assert((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_STDF);
+ setnilV(L->top++);
+ lua_pushliteral(L, "cannot close standard file");
+ return 2;
+ }
+ iof->fp = NULL;
+ return luaL_fileresult(L, ok, NULL);
+}
+
+/* -- Read/write helpers -------------------------------------------------- */
+
+static int io_file_readnum(lua_State *L, FILE *fp)
+{
+ lua_Number d;
+ if (fscanf(fp, LUA_NUMBER_SCAN, &d) == 1) {
+ if (LJ_DUALNUM) {
+ int32_t i = lj_num2int(d);
+ if (d == (lua_Number)i && !tvismzero((cTValue *)&d)) {
+ setintV(L->top++, i);
+ return 1;
+ }
+ }
+ setnumV(L->top++, d);
+ return 1;
+ } else {
+ setnilV(L->top++);
+ return 0;
+ }
+}
+
+static int io_file_readline(lua_State *L, FILE *fp, MSize chop)
+{
+ MSize m = LUAL_BUFFERSIZE, n = 0, ok = 0;
+ char *buf;
+ for (;;) {
+ buf = lj_str_needbuf(L, &G(L)->tmpbuf, m);
+ if (fgets(buf+n, m-n, fp) == NULL) break;
+ n += (MSize)strlen(buf+n);
+ ok |= n;
+ if (n && buf[n-1] == '\n') { n -= chop; break; }
+ if (n >= m - 64) m += m;
+ }
+ setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n));
+ lj_gc_check(L);
+ return (int)ok;
+}
+
+static void io_file_readall(lua_State *L, FILE *fp)
+{
+ MSize m, n;
+ for (m = LUAL_BUFFERSIZE, n = 0; ; m += m) {
+ char *buf = lj_str_needbuf(L, &G(L)->tmpbuf, m);
+ n += (MSize)fread(buf+n, 1, m-n, fp);
+ if (n != m) {
+ setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n));
+ lj_gc_check(L);
+ return;
+ }
+ }
+}
+
+static int io_file_readlen(lua_State *L, FILE *fp, MSize m)
+{
+ if (m) {
+ char *buf = lj_str_needbuf(L, &G(L)->tmpbuf, m);
+ MSize n = (MSize)fread(buf, 1, m, fp);
+ setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n));
+ lj_gc_check(L);
+ return (n > 0 || m == 0);
+ } else {
+ int c = getc(fp);
+ ungetc(c, fp);
+ setstrV(L, L->top++, &G(L)->strempty);
+ return (c != EOF);
+ }
+}
+
+static int io_file_read(lua_State *L, FILE *fp, int start)
+{
+ int ok, n, nargs = (int)(L->top - L->base) - start;
+ clearerr(fp);
+ if (nargs == 0) {
+ ok = io_file_readline(L, fp, 1);
+ n = start+1; /* Return 1 result. */
+ } else {
+ /* The results plus the buffers go on top of the args. */
+ luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
+ ok = 1;
+ for (n = start; nargs-- && ok; n++) {
+ if (tvisstr(L->base+n)) {
+ const char *p = strVdata(L->base+n);
+ if (p[0] != '*')
+ lj_err_arg(L, n+1, LJ_ERR_INVOPT);
+ if (p[1] == 'n')
+ ok = io_file_readnum(L, fp);
+ else if ((p[1] & ~0x20) == 'L')
+ ok = io_file_readline(L, fp, (p[1] == 'l'));
+ else if (p[1] == 'a')
+ io_file_readall(L, fp);
+ else
+ lj_err_arg(L, n+1, LJ_ERR_INVFMT);
+ } else if (tvisnumber(L->base+n)) {
+ ok = io_file_readlen(L, fp, (MSize)lj_lib_checkint(L, n+1));
+ } else {
+ lj_err_arg(L, n+1, LJ_ERR_INVOPT);
+ }
+ }
+ }
+ if (ferror(fp))
+ return luaL_fileresult(L, 0, NULL);
+ if (!ok)
+ setnilV(L->top-1); /* Replace last result with nil. */
+ return n - start;
+}
+
+static int io_file_write(lua_State *L, FILE *fp, int start)
+{
+ cTValue *tv;
+ int status = 1;
+ for (tv = L->base+start; tv < L->top; tv++) {
+ if (tvisstr(tv)) {
+ MSize len = strV(tv)->len;
+ status = status && (fwrite(strVdata(tv), 1, len, fp) == len);
+ } else if (tvisint(tv)) {
+ char buf[LJ_STR_INTBUF];
+ char *p = lj_str_bufint(buf, intV(tv));
+ size_t len = (size_t)(buf+LJ_STR_INTBUF-p);
+ status = status && (fwrite(p, 1, len, fp) == len);
+ } else if (tvisnum(tv)) {
+ status = status && (fprintf(fp, LUA_NUMBER_FMT, numV(tv)) > 0);
+ } else {
+ lj_err_argt(L, (int)(tv - L->base) + 1, LUA_TSTRING);
+ }
+ }
+ if (LJ_52 && status) {
+ L->top = L->base+1;
+ if (start == 0)
+ setudataV(L, L->base, IOSTDF_UD(L, GCROOT_IO_OUTPUT));
+ return 1;
+ }
+ return luaL_fileresult(L, status, NULL);
+}
+
+static int io_file_iter(lua_State *L)
+{
+ GCfunc *fn = curr_func(L);
+ IOFileUD *iof = uddata(udataV(&fn->c.upvalue[0]));
+ int n = fn->c.nupvalues - 1;
+ if (iof->fp == NULL)
+ lj_err_caller(L, LJ_ERR_IOCLFL);
+ L->top = L->base;
+ if (n) { /* Copy upvalues with options to stack. */
+ if (n > LUAI_MAXCSTACK)
+ lj_err_caller(L, LJ_ERR_STKOV);
+ lj_state_checkstack(L, (MSize)n);
+ memcpy(L->top, &fn->c.upvalue[1], n*sizeof(TValue));
+ L->top += n;
+ }
+ n = io_file_read(L, iof->fp, 0);
+ if (ferror(iof->fp))
+ lj_err_callermsg(L, strVdata(L->top-2));
+ if (tvisnil(L->base) && (iof->type & IOFILE_FLAG_CLOSE)) {
+ io_file_close(L, iof); /* Return values are ignored. */
+ return 0;
+ }
+ return n;
+}
+
+static int io_file_lines(lua_State *L)
+{
+ int n = (int)(L->top - L->base);
+ if (n > LJ_MAX_UPVAL)
+ lj_err_caller(L, LJ_ERR_UNPACK);
+ lua_pushcclosure(L, io_file_iter, n);
+ return 1;
+}
+
+/* -- I/O file methods ---------------------------------------------------- */
+
+#define LJLIB_MODULE_io_method
+
+LJLIB_CF(io_method_close)
+{
+ IOFileUD *iof = L->base < L->top ? io_tofile(L) :
+ IOSTDF_IOF(L, GCROOT_IO_OUTPUT);
+ return io_file_close(L, iof);
+}
+
+LJLIB_CF(io_method_read)
+{
+ return io_file_read(L, io_tofile(L)->fp, 1);
+}
+
+LJLIB_CF(io_method_write) LJLIB_REC(io_write 0)
+{
+ return io_file_write(L, io_tofile(L)->fp, 1);
+}
+
+LJLIB_CF(io_method_flush) LJLIB_REC(io_flush 0)
+{
+ return luaL_fileresult(L, fflush(io_tofile(L)->fp) == 0, NULL);
+}
+
+LJLIB_CF(io_method_seek)
+{
+ FILE *fp = io_tofile(L)->fp;
+ int opt = lj_lib_checkopt(L, 2, 1, "\3set\3cur\3end");
+ int64_t ofs = 0;
+ cTValue *o;
+ int res;
+ if (opt == 0) opt = SEEK_SET;
+ else if (opt == 1) opt = SEEK_CUR;
+ else if (opt == 2) opt = SEEK_END;
+ o = L->base+2;
+ if (o < L->top) {
+ if (tvisint(o))
+ ofs = (int64_t)intV(o);
+ else if (tvisnum(o))
+ ofs = (int64_t)numV(o);
+ else if (!tvisnil(o))
+ lj_err_argt(L, 3, LUA_TNUMBER);
+ }
+#if LJ_TARGET_POSIX
+ res = fseeko(fp, ofs, opt);
+#elif _MSC_VER >= 1400
+ res = _fseeki64(fp, ofs, opt);
+#elif defined(__MINGW32__)
+ res = fseeko64(fp, ofs, opt);
+#else
+ res = fseek(fp, (long)ofs, opt);
+#endif
+ if (res)
+ return luaL_fileresult(L, 0, NULL);
+#if LJ_TARGET_POSIX
+ ofs = ftello(fp);
+#elif _MSC_VER >= 1400
+ ofs = _ftelli64(fp);
+#elif defined(__MINGW32__)
+ ofs = ftello64(fp);
+#else
+ ofs = (int64_t)ftell(fp);
+#endif
+ setint64V(L->top-1, ofs);
+ return 1;
+}
+
+LJLIB_CF(io_method_setvbuf)
+{
+ FILE *fp = io_tofile(L)->fp;
+ int opt = lj_lib_checkopt(L, 2, -1, "\4full\4line\2no");
+ size_t sz = (size_t)lj_lib_optint(L, 3, LUAL_BUFFERSIZE);
+ if (opt == 0) opt = _IOFBF;
+ else if (opt == 1) opt = _IOLBF;
+ else if (opt == 2) opt = _IONBF;
+ return luaL_fileresult(L, setvbuf(fp, NULL, opt, sz) == 0, NULL);
+}
+
+LJLIB_CF(io_method_lines)
+{
+ io_tofile(L);
+ return io_file_lines(L);
+}
+
+LJLIB_CF(io_method___gc)
+{
+ IOFileUD *iof = io_tofilep(L);
+ if (iof->fp != NULL && (iof->type & IOFILE_TYPE_MASK) != IOFILE_TYPE_STDF)
+ io_file_close(L, iof);
+ return 0;
+}
+
+LJLIB_CF(io_method___tostring)
+{
+ IOFileUD *iof = io_tofilep(L);
+ if (iof->fp != NULL)
+ lua_pushfstring(L, "file (%p)", iof->fp);
+ else
+ lua_pushliteral(L, "file (closed)");
+ return 1;
+}
+
+LJLIB_PUSH(top-1) LJLIB_SET(__index)
+
+#include "lj_libdef.h"
+
+/* -- I/O library functions ----------------------------------------------- */
+
+#define LJLIB_MODULE_io
+
+LJLIB_PUSH(top-2) LJLIB_SET(!) /* Set environment. */
+
+LJLIB_CF(io_open)
+{
+ const char *fname = strdata(lj_lib_checkstr(L, 1));
+ GCstr *s = lj_lib_optstr(L, 2);
+ const char *mode = s ? strdata(s) : "r";
+ IOFileUD *iof = io_file_new(L);
+ iof->fp = fopen(fname, mode);
+ return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, fname);
+}
+
+LJLIB_CF(io_popen)
+{
+#if LJ_TARGET_POSIX || LJ_TARGET_WINDOWS
+ const char *fname = strdata(lj_lib_checkstr(L, 1));
+ GCstr *s = lj_lib_optstr(L, 2);
+ const char *mode = s ? strdata(s) : "r";
+ IOFileUD *iof = io_file_new(L);
+ iof->type = IOFILE_TYPE_PIPE;
+#if LJ_TARGET_POSIX
+ fflush(NULL);
+ iof->fp = popen(fname, mode);
+#else
+ iof->fp = _popen(fname, mode);
+#endif
+ return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, fname);
+#else
+ return luaL_error(L, LUA_QL("popen") " not supported");
+#endif
+}
+
+LJLIB_CF(io_tmpfile)
+{
+ IOFileUD *iof = io_file_new(L);
+#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PSVITA
+ iof->fp = NULL; errno = ENOSYS;
+#else
+ iof->fp = tmpfile();
+#endif
+ return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, NULL);
+}
+
+LJLIB_CF(io_close)
+{
+ return lj_cf_io_method_close(L);
+}
+
+LJLIB_CF(io_read)
+{
+ return io_file_read(L, io_stdfile(L, GCROOT_IO_INPUT), 0);
+}
+
+LJLIB_CF(io_write) LJLIB_REC(io_write GCROOT_IO_OUTPUT)
+{
+ return io_file_write(L, io_stdfile(L, GCROOT_IO_OUTPUT), 0);
+}
+
+LJLIB_CF(io_flush) LJLIB_REC(io_flush GCROOT_IO_OUTPUT)
+{
+ return luaL_fileresult(L, fflush(io_stdfile(L, GCROOT_IO_OUTPUT)) == 0, NULL);
+}
+
+static int io_std_getset(lua_State *L, ptrdiff_t id, const char *mode)
+{
+ if (L->base < L->top && !tvisnil(L->base)) {
+ if (tvisudata(L->base)) {
+ io_tofile(L);
+ L->top = L->base+1;
+ } else {
+ io_file_open(L, mode);
+ }
+ /* NOBARRIER: The standard I/O handles are GC roots. */
+ setgcref(G(L)->gcroot[id], gcV(L->top-1));
+ } else {
+ setudataV(L, L->top++, IOSTDF_UD(L, id));
+ }
+ return 1;
+}
+
+LJLIB_CF(io_input)
+{
+ return io_std_getset(L, GCROOT_IO_INPUT, "r");
+}
+
+LJLIB_CF(io_output)
+{
+ return io_std_getset(L, GCROOT_IO_OUTPUT, "w");
+}
+
+LJLIB_CF(io_lines)
+{
+ if (L->base == L->top) setnilV(L->top++);
+ if (!tvisnil(L->base)) { /* io.lines(fname) */
+ IOFileUD *iof = io_file_open(L, "r");
+ iof->type = IOFILE_TYPE_FILE|IOFILE_FLAG_CLOSE;
+ L->top--;
+ setudataV(L, L->base, udataV(L->top));
+ } else { /* io.lines() iterates over stdin. */
+ setudataV(L, L->base, IOSTDF_UD(L, GCROOT_IO_INPUT));
+ }
+ return io_file_lines(L);
+}
+
+LJLIB_CF(io_type)
+{
+ cTValue *o = lj_lib_checkany(L, 1);
+ if (!(tvisudata(o) && udataV(o)->udtype == UDTYPE_IO_FILE))
+ setnilV(L->top++);
+ else if (((IOFileUD *)uddata(udataV(o)))->fp != NULL)
+ lua_pushliteral(L, "file");
+ else
+ lua_pushliteral(L, "closed file");
+ return 1;
+}
+
+#include "lj_libdef.h"
+
+/* ------------------------------------------------------------------------ */
+
+static GCobj *io_std_new(lua_State *L, FILE *fp, const char *name)
+{
+ IOFileUD *iof = (IOFileUD *)lua_newuserdata(L, sizeof(IOFileUD));
+ GCudata *ud = udataV(L->top-1);
+ ud->udtype = UDTYPE_IO_FILE;
+ /* NOBARRIER: The GCudata is new (marked white). */
+ setgcref(ud->metatable, gcV(L->top-3));
+ iof->fp = fp;
+ iof->type = IOFILE_TYPE_STDF;
+ lua_setfield(L, -2, name);
+ return obj2gco(ud);
+}
+
+LUALIB_API int luaopen_io(lua_State *L)
+{
+ LJ_LIB_REG(L, NULL, io_method);
+ copyTV(L, L->top, L->top-1); L->top++;
+ lua_setfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE);
+ LJ_LIB_REG(L, LUA_IOLIBNAME, io);
+ setgcref(G(L)->gcroot[GCROOT_IO_INPUT], io_std_new(L, stdin, "stdin"));
+ setgcref(G(L)->gcroot[GCROOT_IO_OUTPUT], io_std_new(L, stdout, "stdout"));
+ io_std_new(L, stderr, "stderr");
+ return 1;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lib_jit.c b/src/3rdparty/LuaJIT-2.0.5/src/lib_jit.c
new file mode 100644
index 0000000..d2fcf21
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lib_jit.c
@@ -0,0 +1,664 @@
+/*
+** JIT library.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lib_jit_c
+#define LUA_LIB
+
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+
+#include "lj_arch.h"
+#include "lj_obj.h"
+#include "lj_err.h"
+#include "lj_debug.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_bc.h"
+#if LJ_HASJIT
+#include "lj_ir.h"
+#include "lj_jit.h"
+#include "lj_ircall.h"
+#include "lj_iropt.h"
+#include "lj_target.h"
+#endif
+#include "lj_dispatch.h"
+#include "lj_vm.h"
+#include "lj_vmevent.h"
+#include "lj_lib.h"
+
+#include "luajit.h"
+
+/* -- jit.* functions ----------------------------------------------------- */
+
+#define LJLIB_MODULE_jit
+
+static int setjitmode(lua_State *L, int mode)
+{
+ int idx = 0;
+ if (L->base == L->top || tvisnil(L->base)) { /* jit.on/off/flush([nil]) */
+ mode |= LUAJIT_MODE_ENGINE;
+ } else {
+ /* jit.on/off/flush(func|proto, nil|true|false) */
+ if (tvisfunc(L->base) || tvisproto(L->base))
+ idx = 1;
+ else if (!tvistrue(L->base)) /* jit.on/off/flush(true, nil|true|false) */
+ goto err;
+ if (L->base+1 < L->top && tvisbool(L->base+1))
+ mode |= boolV(L->base+1) ? LUAJIT_MODE_ALLFUNC : LUAJIT_MODE_ALLSUBFUNC;
+ else
+ mode |= LUAJIT_MODE_FUNC;
+ }
+ if (luaJIT_setmode(L, idx, mode) != 1) {
+ if ((mode & LUAJIT_MODE_MASK) == LUAJIT_MODE_ENGINE)
+ lj_err_caller(L, LJ_ERR_NOJIT);
+ err:
+ lj_err_argt(L, 1, LUA_TFUNCTION);
+ }
+ return 0;
+}
+
+LJLIB_CF(jit_on)
+{
+ return setjitmode(L, LUAJIT_MODE_ON);
+}
+
+LJLIB_CF(jit_off)
+{
+ return setjitmode(L, LUAJIT_MODE_OFF);
+}
+
+LJLIB_CF(jit_flush)
+{
+#if LJ_HASJIT
+ if (L->base < L->top && tvisnumber(L->base)) {
+ int traceno = lj_lib_checkint(L, 1);
+ luaJIT_setmode(L, traceno, LUAJIT_MODE_FLUSH|LUAJIT_MODE_TRACE);
+ return 0;
+ }
+#endif
+ return setjitmode(L, LUAJIT_MODE_FLUSH);
+}
+
+#if LJ_HASJIT
+/* Push a string for every flag bit that is set. */
+static void flagbits_to_strings(lua_State *L, uint32_t flags, uint32_t base,
+ const char *str)
+{
+ for (; *str; base <<= 1, str += 1+*str)
+ if (flags & base)
+ setstrV(L, L->top++, lj_str_new(L, str+1, *(uint8_t *)str));
+}
+#endif
+
+LJLIB_CF(jit_status)
+{
+#if LJ_HASJIT
+ jit_State *J = L2J(L);
+ L->top = L->base;
+ setboolV(L->top++, (J->flags & JIT_F_ON) ? 1 : 0);
+ flagbits_to_strings(L, J->flags, JIT_F_CPU_FIRST, JIT_F_CPUSTRING);
+ flagbits_to_strings(L, J->flags, JIT_F_OPT_FIRST, JIT_F_OPTSTRING);
+ return (int)(L->top - L->base);
+#else
+ setboolV(L->top++, 0);
+ return 1;
+#endif
+}
+
+LJLIB_CF(jit_attach)
+{
+#ifdef LUAJIT_DISABLE_VMEVENT
+ luaL_error(L, "vmevent API disabled");
+#else
+ GCfunc *fn = lj_lib_checkfunc(L, 1);
+ GCstr *s = lj_lib_optstr(L, 2);
+ luaL_findtable(L, LUA_REGISTRYINDEX, LJ_VMEVENTS_REGKEY, LJ_VMEVENTS_HSIZE);
+ if (s) { /* Attach to given event. */
+ const uint8_t *p = (const uint8_t *)strdata(s);
+ uint32_t h = s->len;
+ while (*p) h = h ^ (lj_rol(h, 6) + *p++);
+ lua_pushvalue(L, 1);
+ lua_rawseti(L, -2, VMEVENT_HASHIDX(h));
+ G(L)->vmevmask = VMEVENT_NOCACHE; /* Invalidate cache. */
+ } else { /* Detach if no event given. */
+ setnilV(L->top++);
+ while (lua_next(L, -2)) {
+ L->top--;
+ if (tvisfunc(L->top) && funcV(L->top) == fn) {
+ setnilV(lj_tab_set(L, tabV(L->top-2), L->top-1));
+ }
+ }
+ }
+#endif
+ return 0;
+}
+
+LJLIB_PUSH(top-5) LJLIB_SET(os)
+LJLIB_PUSH(top-4) LJLIB_SET(arch)
+LJLIB_PUSH(top-3) LJLIB_SET(version_num)
+LJLIB_PUSH(top-2) LJLIB_SET(version)
+
+#include "lj_libdef.h"
+
+/* -- jit.util.* functions ------------------------------------------------ */
+
+#define LJLIB_MODULE_jit_util
+
+/* -- Reflection API for Lua functions ------------------------------------ */
+
+/* Return prototype of first argument (Lua function or prototype object) */
+static GCproto *check_Lproto(lua_State *L, int nolua)
+{
+ TValue *o = L->base;
+ if (L->top > o) {
+ if (tvisproto(o)) {
+ return protoV(o);
+ } else if (tvisfunc(o)) {
+ if (isluafunc(funcV(o)))
+ return funcproto(funcV(o));
+ else if (nolua)
+ return NULL;
+ }
+ }
+ lj_err_argt(L, 1, LUA_TFUNCTION);
+ return NULL; /* unreachable */
+}
+
+static void setintfield(lua_State *L, GCtab *t, const char *name, int32_t val)
+{
+ setintV(lj_tab_setstr(L, t, lj_str_newz(L, name)), val);
+}
+
+/* local info = jit.util.funcinfo(func [,pc]) */
+LJLIB_CF(jit_util_funcinfo)
+{
+ GCproto *pt = check_Lproto(L, 1);
+ if (pt) {
+ BCPos pc = (BCPos)lj_lib_optint(L, 2, 0);
+ GCtab *t;
+ lua_createtable(L, 0, 16); /* Increment hash size if fields are added. */
+ t = tabV(L->top-1);
+ setintfield(L, t, "linedefined", pt->firstline);
+ setintfield(L, t, "lastlinedefined", pt->firstline + pt->numline);
+ setintfield(L, t, "stackslots", pt->framesize);
+ setintfield(L, t, "params", pt->numparams);
+ setintfield(L, t, "bytecodes", (int32_t)pt->sizebc);
+ setintfield(L, t, "gcconsts", (int32_t)pt->sizekgc);
+ setintfield(L, t, "nconsts", (int32_t)pt->sizekn);
+ setintfield(L, t, "upvalues", (int32_t)pt->sizeuv);
+ if (pc < pt->sizebc)
+ setintfield(L, t, "currentline", lj_debug_line(pt, pc));
+ lua_pushboolean(L, (pt->flags & PROTO_VARARG));
+ lua_setfield(L, -2, "isvararg");
+ lua_pushboolean(L, (pt->flags & PROTO_CHILD));
+ lua_setfield(L, -2, "children");
+ setstrV(L, L->top++, proto_chunkname(pt));
+ lua_setfield(L, -2, "source");
+ lj_debug_pushloc(L, pt, pc);
+ lua_setfield(L, -2, "loc");
+ setprotoV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "proto")), pt);
+ } else {
+ GCfunc *fn = funcV(L->base);
+ GCtab *t;
+ lua_createtable(L, 0, 4); /* Increment hash size if fields are added. */
+ t = tabV(L->top-1);
+ if (!iscfunc(fn))
+ setintfield(L, t, "ffid", fn->c.ffid);
+ setintptrV(lj_tab_setstr(L, t, lj_str_newlit(L, "addr")),
+ (intptr_t)(void *)fn->c.f);
+ setintfield(L, t, "upvalues", fn->c.nupvalues);
+ }
+ return 1;
+}
+
+/* local ins, m = jit.util.funcbc(func, pc) */
+LJLIB_CF(jit_util_funcbc)
+{
+ GCproto *pt = check_Lproto(L, 0);
+ BCPos pc = (BCPos)lj_lib_checkint(L, 2);
+ if (pc < pt->sizebc) {
+ BCIns ins = proto_bc(pt)[pc];
+ BCOp op = bc_op(ins);
+ lua_assert(op < BC__MAX);
+ setintV(L->top, ins);
+ setintV(L->top+1, lj_bc_mode[op]);
+ L->top += 2;
+ return 2;
+ }
+ return 0;
+}
+
+/* local k = jit.util.funck(func, idx) */
+LJLIB_CF(jit_util_funck)
+{
+ GCproto *pt = check_Lproto(L, 0);
+ ptrdiff_t idx = (ptrdiff_t)lj_lib_checkint(L, 2);
+ if (idx >= 0) {
+ if (idx < (ptrdiff_t)pt->sizekn) {
+ copyTV(L, L->top-1, proto_knumtv(pt, idx));
+ return 1;
+ }
+ } else {
+ if (~idx < (ptrdiff_t)pt->sizekgc) {
+ GCobj *gc = proto_kgc(pt, idx);
+ setgcV(L, L->top-1, gc, ~gc->gch.gct);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/* local name = jit.util.funcuvname(func, idx) */
+LJLIB_CF(jit_util_funcuvname)
+{
+ GCproto *pt = check_Lproto(L, 0);
+ uint32_t idx = (uint32_t)lj_lib_checkint(L, 2);
+ if (idx < pt->sizeuv) {
+ setstrV(L, L->top-1, lj_str_newz(L, lj_debug_uvname(pt, idx)));
+ return 1;
+ }
+ return 0;
+}
+
+/* -- Reflection API for traces ------------------------------------------- */
+
+#if LJ_HASJIT
+
+/* Check trace argument. Must not throw for non-existent trace numbers. */
+static GCtrace *jit_checktrace(lua_State *L)
+{
+ TraceNo tr = (TraceNo)lj_lib_checkint(L, 1);
+ jit_State *J = L2J(L);
+ if (tr > 0 && tr < J->sizetrace)
+ return traceref(J, tr);
+ return NULL;
+}
+
+/* Names of link types. ORDER LJ_TRLINK */
+static const char *const jit_trlinkname[] = {
+ "none", "root", "loop", "tail-recursion", "up-recursion", "down-recursion",
+ "interpreter", "return"
+};
+
+/* local info = jit.util.traceinfo(tr) */
+LJLIB_CF(jit_util_traceinfo)
+{
+ GCtrace *T = jit_checktrace(L);
+ if (T) {
+ GCtab *t;
+ lua_createtable(L, 0, 8); /* Increment hash size if fields are added. */
+ t = tabV(L->top-1);
+ setintfield(L, t, "nins", (int32_t)T->nins - REF_BIAS - 1);
+ setintfield(L, t, "nk", REF_BIAS - (int32_t)T->nk);
+ setintfield(L, t, "link", T->link);
+ setintfield(L, t, "nexit", T->nsnap);
+ setstrV(L, L->top++, lj_str_newz(L, jit_trlinkname[T->linktype]));
+ lua_setfield(L, -2, "linktype");
+ /* There are many more fields. Add them only when needed. */
+ return 1;
+ }
+ return 0;
+}
+
+/* local m, ot, op1, op2, prev = jit.util.traceir(tr, idx) */
+LJLIB_CF(jit_util_traceir)
+{
+ GCtrace *T = jit_checktrace(L);
+ IRRef ref = (IRRef)lj_lib_checkint(L, 2) + REF_BIAS;
+ if (T && ref >= REF_BIAS && ref < T->nins) {
+ IRIns *ir = &T->ir[ref];
+ int32_t m = lj_ir_mode[ir->o];
+ setintV(L->top-2, m);
+ setintV(L->top-1, ir->ot);
+ setintV(L->top++, (int32_t)ir->op1 - (irm_op1(m)==IRMref ? REF_BIAS : 0));
+ setintV(L->top++, (int32_t)ir->op2 - (irm_op2(m)==IRMref ? REF_BIAS : 0));
+ setintV(L->top++, ir->prev);
+ return 5;
+ }
+ return 0;
+}
+
+/* local k, t [, slot] = jit.util.tracek(tr, idx) */
+LJLIB_CF(jit_util_tracek)
+{
+ GCtrace *T = jit_checktrace(L);
+ IRRef ref = (IRRef)lj_lib_checkint(L, 2) + REF_BIAS;
+ if (T && ref >= T->nk && ref < REF_BIAS) {
+ IRIns *ir = &T->ir[ref];
+ int32_t slot = -1;
+ if (ir->o == IR_KSLOT) {
+ slot = ir->op2;
+ ir = &T->ir[ir->op1];
+ }
+ lj_ir_kvalue(L, L->top-2, ir);
+ setintV(L->top-1, (int32_t)irt_type(ir->t));
+ if (slot == -1)
+ return 2;
+ setintV(L->top++, slot);
+ return 3;
+ }
+ return 0;
+}
+
+/* local snap = jit.util.tracesnap(tr, sn) */
+LJLIB_CF(jit_util_tracesnap)
+{
+ GCtrace *T = jit_checktrace(L);
+ SnapNo sn = (SnapNo)lj_lib_checkint(L, 2);
+ if (T && sn < T->nsnap) {
+ SnapShot *snap = &T->snap[sn];
+ SnapEntry *map = &T->snapmap[snap->mapofs];
+ MSize n, nent = snap->nent;
+ GCtab *t;
+ lua_createtable(L, nent+2, 0);
+ t = tabV(L->top-1);
+ setintV(lj_tab_setint(L, t, 0), (int32_t)snap->ref - REF_BIAS);
+ setintV(lj_tab_setint(L, t, 1), (int32_t)snap->nslots);
+ for (n = 0; n < nent; n++)
+ setintV(lj_tab_setint(L, t, (int32_t)(n+2)), (int32_t)map[n]);
+ setintV(lj_tab_setint(L, t, (int32_t)(nent+2)), (int32_t)SNAP(255, 0, 0));
+ return 1;
+ }
+ return 0;
+}
+
+/* local mcode, addr, loop = jit.util.tracemc(tr) */
+LJLIB_CF(jit_util_tracemc)
+{
+ GCtrace *T = jit_checktrace(L);
+ if (T && T->mcode != NULL) {
+ setstrV(L, L->top-1, lj_str_new(L, (const char *)T->mcode, T->szmcode));
+ setintptrV(L->top++, (intptr_t)(void *)T->mcode);
+ setintV(L->top++, T->mcloop);
+ return 3;
+ }
+ return 0;
+}
+
+/* local addr = jit.util.traceexitstub([tr,] exitno) */
+LJLIB_CF(jit_util_traceexitstub)
+{
+#ifdef EXITSTUBS_PER_GROUP
+ ExitNo exitno = (ExitNo)lj_lib_checkint(L, 1);
+ jit_State *J = L2J(L);
+ if (exitno < EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR) {
+ setintptrV(L->top-1, (intptr_t)(void *)exitstub_addr(J, exitno));
+ return 1;
+ }
+#else
+ if (L->top > L->base+1) { /* Don't throw for one-argument variant. */
+ GCtrace *T = jit_checktrace(L);
+ ExitNo exitno = (ExitNo)lj_lib_checkint(L, 2);
+ ExitNo maxexit = T->root ? T->nsnap+1 : T->nsnap;
+ if (T && T->mcode != NULL && exitno < maxexit) {
+ setintptrV(L->top-1, (intptr_t)(void *)exitstub_trace_addr(T, exitno));
+ return 1;
+ }
+ }
+#endif
+ return 0;
+}
+
+/* local addr = jit.util.ircalladdr(idx) */
+LJLIB_CF(jit_util_ircalladdr)
+{
+ uint32_t idx = (uint32_t)lj_lib_checkint(L, 1);
+ if (idx < IRCALL__MAX) {
+ setintptrV(L->top-1, (intptr_t)(void *)lj_ir_callinfo[idx].func);
+ return 1;
+ }
+ return 0;
+}
+
+#endif
+
+#include "lj_libdef.h"
+
+/* -- jit.opt module ------------------------------------------------------ */
+
+#if LJ_HASJIT
+
+#define LJLIB_MODULE_jit_opt
+
+/* Parse optimization level. */
+static int jitopt_level(jit_State *J, const char *str)
+{
+ if (str[0] >= '0' && str[0] <= '9' && str[1] == '\0') {
+ uint32_t flags;
+ if (str[0] == '0') flags = JIT_F_OPT_0;
+ else if (str[0] == '1') flags = JIT_F_OPT_1;
+ else if (str[0] == '2') flags = JIT_F_OPT_2;
+ else flags = JIT_F_OPT_3;
+ J->flags = (J->flags & ~JIT_F_OPT_MASK) | flags;
+ return 1; /* Ok. */
+ }
+ return 0; /* No match. */
+}
+
+/* Parse optimization flag. */
+static int jitopt_flag(jit_State *J, const char *str)
+{
+ const char *lst = JIT_F_OPTSTRING;
+ uint32_t opt;
+ int set = 1;
+ if (str[0] == '+') {
+ str++;
+ } else if (str[0] == '-') {
+ str++;
+ set = 0;
+ } else if (str[0] == 'n' && str[1] == 'o') {
+ str += str[2] == '-' ? 3 : 2;
+ set = 0;
+ }
+ for (opt = JIT_F_OPT_FIRST; ; opt <<= 1) {
+ size_t len = *(const uint8_t *)lst;
+ if (len == 0)
+ break;
+ if (strncmp(str, lst+1, len) == 0 && str[len] == '\0') {
+ if (set) J->flags |= opt; else J->flags &= ~opt;
+ return 1; /* Ok. */
+ }
+ lst += 1+len;
+ }
+ return 0; /* No match. */
+}
+
+/* Parse optimization parameter. */
+static int jitopt_param(jit_State *J, const char *str)
+{
+ const char *lst = JIT_P_STRING;
+ int i;
+ for (i = 0; i < JIT_P__MAX; i++) {
+ size_t len = *(const uint8_t *)lst;
+ lua_assert(len != 0);
+ if (strncmp(str, lst+1, len) == 0 && str[len] == '=') {
+ int32_t n = 0;
+ const char *p = &str[len+1];
+ while (*p >= '0' && *p <= '9')
+ n = n*10 + (*p++ - '0');
+ if (*p) return 0; /* Malformed number. */
+ J->param[i] = n;
+ if (i == JIT_P_hotloop)
+ lj_dispatch_init_hotcount(J2G(J));
+ return 1; /* Ok. */
+ }
+ lst += 1+len;
+ }
+ return 0; /* No match. */
+}
+
+/* jit.opt.start(flags...) */
+LJLIB_CF(jit_opt_start)
+{
+ jit_State *J = L2J(L);
+ int nargs = (int)(L->top - L->base);
+ if (nargs == 0) {
+ J->flags = (J->flags & ~JIT_F_OPT_MASK) | JIT_F_OPT_DEFAULT;
+ } else {
+ int i;
+ for (i = 1; i <= nargs; i++) {
+ const char *str = strdata(lj_lib_checkstr(L, i));
+ if (!jitopt_level(J, str) &&
+ !jitopt_flag(J, str) &&
+ !jitopt_param(J, str))
+ lj_err_callerv(L, LJ_ERR_JITOPT, str);
+ }
+ }
+ return 0;
+}
+
+#include "lj_libdef.h"
+
+#endif
+
+/* -- JIT compiler initialization ----------------------------------------- */
+
+#if LJ_HASJIT
+/* Default values for JIT parameters. */
+static const int32_t jit_param_default[JIT_P__MAX+1] = {
+#define JIT_PARAMINIT(len, name, value) (value),
+JIT_PARAMDEF(JIT_PARAMINIT)
+#undef JIT_PARAMINIT
+ 0
+};
+#endif
+
+#if LJ_TARGET_ARM && LJ_TARGET_LINUX
+#include <sys/utsname.h>
+#endif
+
+/* Arch-dependent CPU detection. */
+static uint32_t jit_cpudetect(lua_State *L)
+{
+ uint32_t flags = 0;
+#if LJ_TARGET_X86ORX64
+ uint32_t vendor[4];
+ uint32_t features[4];
+ if (lj_vm_cpuid(0, vendor) && lj_vm_cpuid(1, features)) {
+#if !LJ_HASJIT
+#define JIT_F_CMOV 1
+#define JIT_F_SSE2 2
+#endif
+ flags |= ((features[3] >> 15)&1) * JIT_F_CMOV;
+ flags |= ((features[3] >> 26)&1) * JIT_F_SSE2;
+#if LJ_HASJIT
+ flags |= ((features[2] >> 0)&1) * JIT_F_SSE3;
+ flags |= ((features[2] >> 19)&1) * JIT_F_SSE4_1;
+ if (vendor[2] == 0x6c65746e) { /* Intel. */
+ if ((features[0] & 0x0ff00f00) == 0x00000f00) /* P4. */
+ flags |= JIT_F_P4; /* Currently unused. */
+ else if ((features[0] & 0x0fff0ff0) == 0x000106c0) /* Atom. */
+ flags |= JIT_F_LEA_AGU;
+ } else if (vendor[2] == 0x444d4163) { /* AMD. */
+ uint32_t fam = (features[0] & 0x0ff00f00);
+ if (fam == 0x00000f00) /* K8. */
+ flags |= JIT_F_SPLIT_XMM;
+ if (fam >= 0x00000f00) /* K8, K10. */
+ flags |= JIT_F_PREFER_IMUL;
+ }
+#endif
+ }
+ /* Check for required instruction set support on x86 (unnecessary on x64). */
+#if LJ_TARGET_X86
+#if !defined(LUAJIT_CPU_NOCMOV)
+ if (!(flags & JIT_F_CMOV))
+ luaL_error(L, "CPU not supported");
+#endif
+#if defined(LUAJIT_CPU_SSE2)
+ if (!(flags & JIT_F_SSE2))
+ luaL_error(L, "CPU does not support SSE2 (recompile without -DLUAJIT_CPU_SSE2)");
+#endif
+#endif
+#elif LJ_TARGET_ARM
+#if LJ_HASJIT
+ int ver = LJ_ARCH_VERSION; /* Compile-time ARM CPU detection. */
+#if LJ_TARGET_LINUX
+ if (ver < 70) { /* Runtime ARM CPU detection. */
+ struct utsname ut;
+ uname(&ut);
+ if (strncmp(ut.machine, "armv", 4) == 0) {
+ if (ut.machine[4] >= '7')
+ ver = 70;
+ else if (ut.machine[4] == '6')
+ ver = 60;
+ }
+ }
+#endif
+ flags |= ver >= 70 ? JIT_F_ARMV7 :
+ ver >= 61 ? JIT_F_ARMV6T2_ :
+ ver >= 60 ? JIT_F_ARMV6_ : 0;
+ flags |= LJ_ARCH_HASFPU == 0 ? 0 : ver >= 70 ? JIT_F_VFPV3 : JIT_F_VFPV2;
+#endif
+#elif LJ_TARGET_PPC
+#if LJ_HASJIT
+#if LJ_ARCH_SQRT
+ flags |= JIT_F_SQRT;
+#endif
+#if LJ_ARCH_ROUND
+ flags |= JIT_F_ROUND;
+#endif
+#endif
+#elif LJ_TARGET_PPCSPE
+ /* Nothing to do. */
+#elif LJ_TARGET_MIPS
+#if LJ_HASJIT
+ /* Compile-time MIPS CPU detection. */
+#if LJ_ARCH_VERSION >= 20
+ flags |= JIT_F_MIPS32R2;
+#endif
+ /* Runtime MIPS CPU detection. */
+#if defined(__GNUC__)
+ if (!(flags & JIT_F_MIPS32R2)) {
+ int x;
+ /* On MIPS32R1 rotr is treated as srl. rotr r2,r2,1 -> srl r2,r2,1. */
+ __asm__("li $2, 1\n\t.long 0x00221042\n\tmove %0, $2" : "=r"(x) : : "$2");
+ if (x) flags |= JIT_F_MIPS32R2; /* Either 0x80000000 (R2) or 0 (R1). */
+ }
+#endif
+#endif
+#else
+#error "Missing CPU detection for this architecture"
+#endif
+ UNUSED(L);
+ return flags;
+}
+
+/* Initialize JIT compiler. */
+static void jit_init(lua_State *L)
+{
+ uint32_t flags = jit_cpudetect(L);
+#if LJ_HASJIT
+ jit_State *J = L2J(L);
+#if LJ_TARGET_X86
+ /* Silently turn off the JIT compiler on CPUs without SSE2. */
+ if ((flags & JIT_F_SSE2))
+#endif
+ J->flags = flags | JIT_F_ON | JIT_F_OPT_DEFAULT;
+ memcpy(J->param, jit_param_default, sizeof(J->param));
+ lj_dispatch_update(G(L));
+#else
+ UNUSED(flags);
+#endif
+}
+
+LUALIB_API int luaopen_jit(lua_State *L)
+{
+ lua_pushliteral(L, LJ_OS_NAME);
+ lua_pushliteral(L, LJ_ARCH_NAME);
+ lua_pushinteger(L, LUAJIT_VERSION_NUM);
+ lua_pushliteral(L, LUAJIT_VERSION);
+ LJ_LIB_REG(L, LUA_JITLIBNAME, jit);
+#ifndef LUAJIT_DISABLE_JITUTIL
+ LJ_LIB_REG(L, "jit.util", jit_util);
+#endif
+#if LJ_HASJIT
+ LJ_LIB_REG(L, "jit.opt", jit_opt);
+#endif
+ L->top -= 2;
+ jit_init(L);
+ return 1;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lib_math.c b/src/3rdparty/LuaJIT-2.0.5/src/lib_math.c
new file mode 100644
index 0000000..4c708a4
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lib_math.c
@@ -0,0 +1,233 @@
+/*
+** Math library.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#include <math.h>
+
+#define lib_math_c
+#define LUA_LIB
+
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+
+#include "lj_obj.h"
+#include "lj_lib.h"
+#include "lj_vm.h"
+
+/* ------------------------------------------------------------------------ */
+
+#define LJLIB_MODULE_math
+
+LJLIB_ASM(math_abs) LJLIB_REC(.)
+{
+ lj_lib_checknumber(L, 1);
+ return FFH_RETRY;
+}
+LJLIB_ASM_(math_floor) LJLIB_REC(math_round IRFPM_FLOOR)
+LJLIB_ASM_(math_ceil) LJLIB_REC(math_round IRFPM_CEIL)
+
+LJLIB_ASM(math_sqrt) LJLIB_REC(math_unary IRFPM_SQRT)
+{
+ lj_lib_checknum(L, 1);
+ return FFH_RETRY;
+}
+LJLIB_ASM_(math_log10) LJLIB_REC(math_unary IRFPM_LOG10)
+LJLIB_ASM_(math_exp) LJLIB_REC(math_unary IRFPM_EXP)
+LJLIB_ASM_(math_sin) LJLIB_REC(math_unary IRFPM_SIN)
+LJLIB_ASM_(math_cos) LJLIB_REC(math_unary IRFPM_COS)
+LJLIB_ASM_(math_tan) LJLIB_REC(math_unary IRFPM_TAN)
+LJLIB_ASM_(math_asin) LJLIB_REC(math_atrig FF_math_asin)
+LJLIB_ASM_(math_acos) LJLIB_REC(math_atrig FF_math_acos)
+LJLIB_ASM_(math_atan) LJLIB_REC(math_atrig FF_math_atan)
+LJLIB_ASM_(math_sinh) LJLIB_REC(math_htrig IRCALL_sinh)
+LJLIB_ASM_(math_cosh) LJLIB_REC(math_htrig IRCALL_cosh)
+LJLIB_ASM_(math_tanh) LJLIB_REC(math_htrig IRCALL_tanh)
+LJLIB_ASM_(math_frexp)
+LJLIB_ASM_(math_modf) LJLIB_REC(.)
+
+LJLIB_PUSH(57.29577951308232)
+LJLIB_ASM_(math_deg) LJLIB_REC(math_degrad)
+
+LJLIB_PUSH(0.017453292519943295)
+LJLIB_ASM_(math_rad) LJLIB_REC(math_degrad)
+
+LJLIB_ASM(math_log) LJLIB_REC(math_log)
+{
+ double x = lj_lib_checknum(L, 1);
+ if (L->base+1 < L->top) {
+ double y = lj_lib_checknum(L, 2);
+#ifdef LUAJIT_NO_LOG2
+ x = log(x); y = 1.0 / log(y);
+#else
+ x = lj_vm_log2(x); y = 1.0 / lj_vm_log2(y);
+#endif
+ setnumV(L->base-1, x*y); /* Do NOT join the expression to x / y. */
+ return FFH_RES(1);
+ }
+ return FFH_RETRY;
+}
+
+LJLIB_ASM(math_atan2) LJLIB_REC(.)
+{
+ lj_lib_checknum(L, 1);
+ lj_lib_checknum(L, 2);
+ return FFH_RETRY;
+}
+LJLIB_ASM_(math_pow) LJLIB_REC(.)
+LJLIB_ASM_(math_fmod)
+
+LJLIB_ASM(math_ldexp) LJLIB_REC(.)
+{
+ lj_lib_checknum(L, 1);
+#if LJ_DUALNUM && !LJ_TARGET_X86ORX64
+ lj_lib_checkint(L, 2);
+#else
+ lj_lib_checknum(L, 2);
+#endif
+ return FFH_RETRY;
+}
+
+LJLIB_ASM(math_min) LJLIB_REC(math_minmax IR_MIN)
+{
+ int i = 0;
+ do { lj_lib_checknumber(L, ++i); } while (L->base+i < L->top);
+ return FFH_RETRY;
+}
+LJLIB_ASM_(math_max) LJLIB_REC(math_minmax IR_MAX)
+
+LJLIB_PUSH(3.14159265358979323846) LJLIB_SET(pi)
+LJLIB_PUSH(1e310) LJLIB_SET(huge)
+
+/* ------------------------------------------------------------------------ */
+
+/* This implements a Tausworthe PRNG with period 2^223. Based on:
+** Tables of maximally-equidistributed combined LFSR generators,
+** Pierre L'Ecuyer, 1991, table 3, 1st entry.
+** Full-period ME-CF generator with L=64, J=4, k=223, N1=49.
+*/
+
+/* PRNG state. */
+struct RandomState {
+ uint64_t gen[4]; /* State of the 4 LFSR generators. */
+ int valid; /* State is valid. */
+};
+
+/* Union needed for bit-pattern conversion between uint64_t and double. */
+typedef union { uint64_t u64; double d; } U64double;
+
+/* Update generator i and compute a running xor of all states. */
+#define TW223_GEN(i, k, q, s) \
+ z = rs->gen[i]; \
+ z = (((z<<q)^z) >> (k-s)) ^ ((z&((uint64_t)(int64_t)-1 << (64-k)))<<s); \
+ r ^= z; rs->gen[i] = z;
+
+/* PRNG step function. Returns a double in the range 1.0 <= d < 2.0. */
+LJ_NOINLINE uint64_t LJ_FASTCALL lj_math_random_step(RandomState *rs)
+{
+ uint64_t z, r = 0;
+ TW223_GEN(0, 63, 31, 18)
+ TW223_GEN(1, 58, 19, 28)
+ TW223_GEN(2, 55, 24, 7)
+ TW223_GEN(3, 47, 21, 8)
+ return (r & U64x(000fffff,ffffffff)) | U64x(3ff00000,00000000);
+}
+
+/* PRNG initialization function. */
+static void random_init(RandomState *rs, double d)
+{
+ uint32_t r = 0x11090601; /* 64-k[i] as four 8 bit constants. */
+ int i;
+ for (i = 0; i < 4; i++) {
+ U64double u;
+ uint32_t m = 1u << (r&255);
+ r >>= 8;
+ u.d = d = d * 3.14159265358979323846 + 2.7182818284590452354;
+ if (u.u64 < m) u.u64 += m; /* Ensure k[i] MSB of gen[i] are non-zero. */
+ rs->gen[i] = u.u64;
+ }
+ rs->valid = 1;
+ for (i = 0; i < 10; i++)
+ lj_math_random_step(rs);
+}
+
+/* PRNG extract function. */
+LJLIB_PUSH(top-2) /* Upvalue holds userdata with RandomState. */
+LJLIB_CF(math_random) LJLIB_REC(.)
+{
+ int n = (int)(L->top - L->base);
+ RandomState *rs = (RandomState *)(uddata(udataV(lj_lib_upvalue(L, 1))));
+ U64double u;
+ double d;
+ if (LJ_UNLIKELY(!rs->valid)) random_init(rs, 0.0);
+ u.u64 = lj_math_random_step(rs);
+ d = u.d - 1.0;
+ if (n > 0) {
+#if LJ_DUALNUM
+ int isint = 1;
+ double r1;
+ lj_lib_checknumber(L, 1);
+ if (tvisint(L->base)) {
+ r1 = (lua_Number)intV(L->base);
+ } else {
+ isint = 0;
+ r1 = numV(L->base);
+ }
+#else
+ double r1 = lj_lib_checknum(L, 1);
+#endif
+ if (n == 1) {
+ d = lj_vm_floor(d*r1) + 1.0; /* d is an int in range [1, r1] */
+ } else {
+#if LJ_DUALNUM
+ double r2;
+ lj_lib_checknumber(L, 2);
+ if (tvisint(L->base+1)) {
+ r2 = (lua_Number)intV(L->base+1);
+ } else {
+ isint = 0;
+ r2 = numV(L->base+1);
+ }
+#else
+ double r2 = lj_lib_checknum(L, 2);
+#endif
+ d = lj_vm_floor(d*(r2-r1+1.0)) + r1; /* d is an int in range [r1, r2] */
+ }
+#if LJ_DUALNUM
+ if (isint) {
+ setintV(L->top-1, lj_num2int(d));
+ return 1;
+ }
+#endif
+ } /* else: d is a double in range [0, 1] */
+ setnumV(L->top++, d);
+ return 1;
+}
+
+/* PRNG seed function. */
+LJLIB_PUSH(top-2) /* Upvalue holds userdata with RandomState. */
+LJLIB_CF(math_randomseed)
+{
+ RandomState *rs = (RandomState *)(uddata(udataV(lj_lib_upvalue(L, 1))));
+ random_init(rs, lj_lib_checknum(L, 1));
+ return 0;
+}
+
+/* ------------------------------------------------------------------------ */
+
+#include "lj_libdef.h"
+
+LUALIB_API int luaopen_math(lua_State *L)
+{
+ RandomState *rs;
+ rs = (RandomState *)lua_newuserdata(L, sizeof(RandomState));
+ rs->valid = 0; /* Use lazy initialization to save some time on startup. */
+ LJ_LIB_REG(L, LUA_MATHLIBNAME, math);
+#if defined(LUA_COMPAT_MOD) && !LJ_52
+ lua_getfield(L, -1, "fmod");
+ lua_setfield(L, -2, "mod");
+#endif
+ return 1;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lib_os.c b/src/3rdparty/LuaJIT-2.0.5/src/lib_os.c
new file mode 100644
index 0000000..8c96b86
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lib_os.c
@@ -0,0 +1,287 @@
+/*
+** OS library.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Major portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#include <errno.h>
+#include <time.h>
+
+#define lib_os_c
+#define LUA_LIB
+
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+
+#include "lj_obj.h"
+#include "lj_err.h"
+#include "lj_lib.h"
+
+#if LJ_TARGET_POSIX
+#include <unistd.h>
+#else
+#include <stdio.h>
+#endif
+
+#if !LJ_TARGET_PSVITA
+#include <locale.h>
+#endif
+
+/* ------------------------------------------------------------------------ */
+
+#define LJLIB_MODULE_os
+
+LJLIB_CF(os_execute)
+{
+#if LJ_NO_SYSTEM
+#if LJ_52
+ errno = ENOSYS;
+ return luaL_fileresult(L, 0, NULL);
+#else
+ lua_pushinteger(L, -1);
+ return 1;
+#endif
+#else
+ const char *cmd = luaL_optstring(L, 1, NULL);
+ int stat = system(cmd);
+#if LJ_52
+ if (cmd)
+ return luaL_execresult(L, stat);
+ setboolV(L->top++, 1);
+#else
+ setintV(L->top++, stat);
+#endif
+ return 1;
+#endif
+}
+
+LJLIB_CF(os_remove)
+{
+ const char *filename = luaL_checkstring(L, 1);
+ return luaL_fileresult(L, remove(filename) == 0, filename);
+}
+
+LJLIB_CF(os_rename)
+{
+ const char *fromname = luaL_checkstring(L, 1);
+ const char *toname = luaL_checkstring(L, 2);
+ return luaL_fileresult(L, rename(fromname, toname) == 0, fromname);
+}
+
+LJLIB_CF(os_tmpname)
+{
+#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PSVITA
+ lj_err_caller(L, LJ_ERR_OSUNIQF);
+ return 0;
+#else
+#if LJ_TARGET_POSIX
+ char buf[15+1];
+ int fp;
+ strcpy(buf, "/tmp/lua_XXXXXX");
+ fp = mkstemp(buf);
+ if (fp != -1)
+ close(fp);
+ else
+ lj_err_caller(L, LJ_ERR_OSUNIQF);
+#else
+ char buf[L_tmpnam];
+ if (tmpnam(buf) == NULL)
+ lj_err_caller(L, LJ_ERR_OSUNIQF);
+#endif
+ lua_pushstring(L, buf);
+ return 1;
+#endif
+}
+
+LJLIB_CF(os_getenv)
+{
+#if LJ_TARGET_CONSOLE
+ lua_pushnil(L);
+#else
+ lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */
+#endif
+ return 1;
+}
+
+LJLIB_CF(os_exit)
+{
+ int status;
+ if (L->base < L->top && tvisbool(L->base))
+ status = boolV(L->base) ? EXIT_SUCCESS : EXIT_FAILURE;
+ else
+ status = lj_lib_optint(L, 1, EXIT_SUCCESS);
+ if (L->base+1 < L->top && tvistruecond(L->base+1))
+ lua_close(L);
+ exit(status);
+ return 0; /* Unreachable. */
+}
+
+LJLIB_CF(os_clock)
+{
+ setnumV(L->top++, ((lua_Number)clock())*(1.0/(lua_Number)CLOCKS_PER_SEC));
+ return 1;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static void setfield(lua_State *L, const char *key, int value)
+{
+ lua_pushinteger(L, value);
+ lua_setfield(L, -2, key);
+}
+
+static void setboolfield(lua_State *L, const char *key, int value)
+{
+ if (value < 0) /* undefined? */
+ return; /* does not set field */
+ lua_pushboolean(L, value);
+ lua_setfield(L, -2, key);
+}
+
+static int getboolfield(lua_State *L, const char *key)
+{
+ int res;
+ lua_getfield(L, -1, key);
+ res = lua_isnil(L, -1) ? -1 : lua_toboolean(L, -1);
+ lua_pop(L, 1);
+ return res;
+}
+
+static int getfield(lua_State *L, const char *key, int d)
+{
+ int res;
+ lua_getfield(L, -1, key);
+ if (lua_isnumber(L, -1)) {
+ res = (int)lua_tointeger(L, -1);
+ } else {
+ if (d < 0)
+ lj_err_callerv(L, LJ_ERR_OSDATEF, key);
+ res = d;
+ }
+ lua_pop(L, 1);
+ return res;
+}
+
+LJLIB_CF(os_date)
+{
+ const char *s = luaL_optstring(L, 1, "%c");
+ time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL));
+ struct tm *stm;
+#if LJ_TARGET_POSIX
+ struct tm rtm;
+#endif
+ if (*s == '!') { /* UTC? */
+ s++; /* Skip '!' */
+#if LJ_TARGET_POSIX
+ stm = gmtime_r(&t, &rtm);
+#else
+ stm = gmtime(&t);
+#endif
+ } else {
+#if LJ_TARGET_POSIX
+ stm = localtime_r(&t, &rtm);
+#else
+ stm = localtime(&t);
+#endif
+ }
+ if (stm == NULL) { /* Invalid date? */
+ setnilV(L->top-1);
+ } else if (strcmp(s, "*t") == 0) {
+ lua_createtable(L, 0, 9); /* 9 = number of fields */
+ setfield(L, "sec", stm->tm_sec);
+ setfield(L, "min", stm->tm_min);
+ setfield(L, "hour", stm->tm_hour);
+ setfield(L, "day", stm->tm_mday);
+ setfield(L, "month", stm->tm_mon+1);
+ setfield(L, "year", stm->tm_year+1900);
+ setfield(L, "wday", stm->tm_wday+1);
+ setfield(L, "yday", stm->tm_yday+1);
+ setboolfield(L, "isdst", stm->tm_isdst);
+ } else {
+ char cc[3];
+ luaL_Buffer b;
+ cc[0] = '%'; cc[2] = '\0';
+ luaL_buffinit(L, &b);
+ for (; *s; s++) {
+ if (*s != '%' || *(s + 1) == '\0') { /* No conversion specifier? */
+ luaL_addchar(&b, *s);
+ } else {
+ size_t reslen;
+ char buff[200]; /* Should be big enough for any conversion result. */
+ cc[1] = *(++s);
+ reslen = strftime(buff, sizeof(buff), cc, stm);
+ luaL_addlstring(&b, buff, reslen);
+ }
+ }
+ luaL_pushresult(&b);
+ }
+ return 1;
+}
+
+LJLIB_CF(os_time)
+{
+ time_t t;
+ if (lua_isnoneornil(L, 1)) { /* called without args? */
+ t = time(NULL); /* get current time */
+ } else {
+ struct tm ts;
+ luaL_checktype(L, 1, LUA_TTABLE);
+ lua_settop(L, 1); /* make sure table is at the top */
+ ts.tm_sec = getfield(L, "sec", 0);
+ ts.tm_min = getfield(L, "min", 0);
+ ts.tm_hour = getfield(L, "hour", 12);
+ ts.tm_mday = getfield(L, "day", -1);
+ ts.tm_mon = getfield(L, "month", -1) - 1;
+ ts.tm_year = getfield(L, "year", -1) - 1900;
+ ts.tm_isdst = getboolfield(L, "isdst");
+ t = mktime(&ts);
+ }
+ if (t == (time_t)(-1))
+ lua_pushnil(L);
+ else
+ lua_pushnumber(L, (lua_Number)t);
+ return 1;
+}
+
+LJLIB_CF(os_difftime)
+{
+ lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)),
+ (time_t)(luaL_optnumber(L, 2, (lua_Number)0))));
+ return 1;
+}
+
+/* ------------------------------------------------------------------------ */
+
+LJLIB_CF(os_setlocale)
+{
+#if LJ_TARGET_PSVITA
+ lua_pushliteral(L, "C");
+#else
+ GCstr *s = lj_lib_optstr(L, 1);
+ const char *str = s ? strdata(s) : NULL;
+ int opt = lj_lib_checkopt(L, 2, 6,
+ "\5ctype\7numeric\4time\7collate\10monetary\1\377\3all");
+ if (opt == 0) opt = LC_CTYPE;
+ else if (opt == 1) opt = LC_NUMERIC;
+ else if (opt == 2) opt = LC_TIME;
+ else if (opt == 3) opt = LC_COLLATE;
+ else if (opt == 4) opt = LC_MONETARY;
+ else if (opt == 6) opt = LC_ALL;
+ lua_pushstring(L, setlocale(opt, str));
+#endif
+ return 1;
+}
+
+/* ------------------------------------------------------------------------ */
+
+#include "lj_libdef.h"
+
+LUALIB_API int luaopen_os(lua_State *L)
+{
+ LJ_LIB_REG(L, LUA_OSLIBNAME, os);
+ return 1;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lib_package.c b/src/3rdparty/LuaJIT-2.0.5/src/lib_package.c
new file mode 100644
index 0000000..01b63d6
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lib_package.c
@@ -0,0 +1,602 @@
+/*
+** Package library.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Major portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2012 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#define lib_package_c
+#define LUA_LIB
+
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+
+#include "lj_obj.h"
+#include "lj_err.h"
+#include "lj_lib.h"
+
+/* ------------------------------------------------------------------------ */
+
+/* Error codes for ll_loadfunc. */
+#define PACKAGE_ERR_LIB 1
+#define PACKAGE_ERR_FUNC 2
+#define PACKAGE_ERR_LOAD 3
+
+/* Redefined in platform specific part. */
+#define PACKAGE_LIB_FAIL "open"
+#define setprogdir(L) ((void)0)
+
+/* Symbol name prefixes. */
+#define SYMPREFIX_CF "luaopen_%s"
+#define SYMPREFIX_BC "luaJIT_BC_%s"
+
+#if LJ_TARGET_DLOPEN
+
+#include <dlfcn.h>
+
+static void ll_unloadlib(void *lib)
+{
+ dlclose(lib);
+}
+
+static void *ll_load(lua_State *L, const char *path, int gl)
+{
+ void *lib = dlopen(path, RTLD_NOW | (gl ? RTLD_GLOBAL : RTLD_LOCAL));
+ if (lib == NULL) lua_pushstring(L, dlerror());
+ return lib;
+}
+
+static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)
+{
+ lua_CFunction f = (lua_CFunction)dlsym(lib, sym);
+ if (f == NULL) lua_pushstring(L, dlerror());
+ return f;
+}
+
+static const char *ll_bcsym(void *lib, const char *sym)
+{
+#if defined(RTLD_DEFAULT)
+ if (lib == NULL) lib = RTLD_DEFAULT;
+#elif LJ_TARGET_OSX || LJ_TARGET_BSD
+ if (lib == NULL) lib = (void *)(intptr_t)-2;
+#endif
+ return (const char *)dlsym(lib, sym);
+}
+
+#elif LJ_TARGET_WINDOWS
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#ifndef GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
+#define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS 4
+#define GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT 2
+BOOL WINAPI GetModuleHandleExA(DWORD, LPCSTR, HMODULE*);
+#endif
+
+#undef setprogdir
+
+static void setprogdir(lua_State *L)
+{
+ char buff[MAX_PATH + 1];
+ char *lb;
+ DWORD nsize = sizeof(buff);
+ DWORD n = GetModuleFileNameA(NULL, buff, nsize);
+ if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) {
+ luaL_error(L, "unable to get ModuleFileName");
+ } else {
+ *lb = '\0';
+ luaL_gsub(L, lua_tostring(L, -1), LUA_EXECDIR, buff);
+ lua_remove(L, -2); /* remove original string */
+ }
+}
+
+static void pusherror(lua_State *L)
+{
+ DWORD error = GetLastError();
+ char buffer[128];
+ if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL, error, 0, buffer, sizeof(buffer), NULL))
+ lua_pushstring(L, buffer);
+ else
+ lua_pushfstring(L, "system error %d\n", error);
+}
+
+static void ll_unloadlib(void *lib)
+{
+ FreeLibrary((HINSTANCE)lib);
+}
+
+static void *ll_load(lua_State *L, const char *path, int gl)
+{
+ HINSTANCE lib = LoadLibraryA(path);
+ if (lib == NULL) pusherror(L);
+ UNUSED(gl);
+ return lib;
+}
+
+static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)
+{
+ lua_CFunction f = (lua_CFunction)GetProcAddress((HINSTANCE)lib, sym);
+ if (f == NULL) pusherror(L);
+ return f;
+}
+
+static const char *ll_bcsym(void *lib, const char *sym)
+{
+ if (lib) {
+ return (const char *)GetProcAddress((HINSTANCE)lib, sym);
+ } else {
+ HINSTANCE h = GetModuleHandleA(NULL);
+ const char *p = (const char *)GetProcAddress(h, sym);
+ if (p == NULL && GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ (const char *)ll_bcsym, &h))
+ p = (const char *)GetProcAddress(h, sym);
+ return p;
+ }
+}
+
+#else
+
+#undef PACKAGE_LIB_FAIL
+#define PACKAGE_LIB_FAIL "absent"
+
+#define DLMSG "dynamic libraries not enabled; no support for target OS"
+
+static void ll_unloadlib(void *lib)
+{
+ UNUSED(lib);
+}
+
+static void *ll_load(lua_State *L, const char *path, int gl)
+{
+ UNUSED(path); UNUSED(gl);
+ lua_pushliteral(L, DLMSG);
+ return NULL;
+}
+
+static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)
+{
+ UNUSED(lib); UNUSED(sym);
+ lua_pushliteral(L, DLMSG);
+ return NULL;
+}
+
+static const char *ll_bcsym(void *lib, const char *sym)
+{
+ UNUSED(lib); UNUSED(sym);
+ return NULL;
+}
+
+#endif
+
+/* ------------------------------------------------------------------------ */
+
+static void **ll_register(lua_State *L, const char *path)
+{
+ void **plib;
+ lua_pushfstring(L, "LOADLIB: %s", path);
+ lua_gettable(L, LUA_REGISTRYINDEX); /* check library in registry? */
+ if (!lua_isnil(L, -1)) { /* is there an entry? */
+ plib = (void **)lua_touserdata(L, -1);
+ } else { /* no entry yet; create one */
+ lua_pop(L, 1);
+ plib = (void **)lua_newuserdata(L, sizeof(void *));
+ *plib = NULL;
+ luaL_getmetatable(L, "_LOADLIB");
+ lua_setmetatable(L, -2);
+ lua_pushfstring(L, "LOADLIB: %s", path);
+ lua_pushvalue(L, -2);
+ lua_settable(L, LUA_REGISTRYINDEX);
+ }
+ return plib;
+}
+
+static const char *mksymname(lua_State *L, const char *modname,
+ const char *prefix)
+{
+ const char *funcname;
+ const char *mark = strchr(modname, *LUA_IGMARK);
+ if (mark) modname = mark + 1;
+ funcname = luaL_gsub(L, modname, ".", "_");
+ funcname = lua_pushfstring(L, prefix, funcname);
+ lua_remove(L, -2); /* remove 'gsub' result */
+ return funcname;
+}
+
+static int ll_loadfunc(lua_State *L, const char *path, const char *name, int r)
+{
+ void **reg = ll_register(L, path);
+ if (*reg == NULL) *reg = ll_load(L, path, (*name == '*'));
+ if (*reg == NULL) {
+ return PACKAGE_ERR_LIB; /* Unable to load library. */
+ } else if (*name == '*') { /* Only load library into global namespace. */
+ lua_pushboolean(L, 1);
+ return 0;
+ } else {
+ const char *sym = r ? name : mksymname(L, name, SYMPREFIX_CF);
+ lua_CFunction f = ll_sym(L, *reg, sym);
+ if (f) {
+ lua_pushcfunction(L, f);
+ return 0;
+ }
+ if (!r) {
+ const char *bcdata = ll_bcsym(*reg, mksymname(L, name, SYMPREFIX_BC));
+ lua_pop(L, 1);
+ if (bcdata) {
+ if (luaL_loadbuffer(L, bcdata, ~(size_t)0, name) != 0)
+ return PACKAGE_ERR_LOAD;
+ return 0;
+ }
+ }
+ return PACKAGE_ERR_FUNC; /* Unable to find function. */
+ }
+}
+
+static int lj_cf_package_loadlib(lua_State *L)
+{
+ const char *path = luaL_checkstring(L, 1);
+ const char *init = luaL_checkstring(L, 2);
+ int st = ll_loadfunc(L, path, init, 1);
+ if (st == 0) { /* no errors? */
+ return 1; /* return the loaded function */
+ } else { /* error; error message is on stack top */
+ lua_pushnil(L);
+ lua_insert(L, -2);
+ lua_pushstring(L, (st == PACKAGE_ERR_LIB) ? PACKAGE_LIB_FAIL : "init");
+ return 3; /* return nil, error message, and where */
+ }
+}
+
+static int lj_cf_package_unloadlib(lua_State *L)
+{
+ void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB");
+ if (*lib) ll_unloadlib(*lib);
+ *lib = NULL; /* mark library as closed */
+ return 0;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static int readable(const char *filename)
+{
+ FILE *f = fopen(filename, "r"); /* try to open file */
+ if (f == NULL) return 0; /* open failed */
+ fclose(f);
+ return 1;
+}
+
+static const char *pushnexttemplate(lua_State *L, const char *path)
+{
+ const char *l;
+ while (*path == *LUA_PATHSEP) path++; /* skip separators */
+ if (*path == '\0') return NULL; /* no more templates */
+ l = strchr(path, *LUA_PATHSEP); /* find next separator */
+ if (l == NULL) l = path + strlen(path);
+ lua_pushlstring(L, path, (size_t)(l - path)); /* template */
+ return l;
+}
+
+static const char *searchpath (lua_State *L, const char *name,
+ const char *path, const char *sep,
+ const char *dirsep)
+{
+ luaL_Buffer msg; /* to build error message */
+ luaL_buffinit(L, &msg);
+ if (*sep != '\0') /* non-empty separator? */
+ name = luaL_gsub(L, name, sep, dirsep); /* replace it by 'dirsep' */
+ while ((path = pushnexttemplate(L, path)) != NULL) {
+ const char *filename = luaL_gsub(L, lua_tostring(L, -1),
+ LUA_PATH_MARK, name);
+ lua_remove(L, -2); /* remove path template */
+ if (readable(filename)) /* does file exist and is readable? */
+ return filename; /* return that file name */
+ lua_pushfstring(L, "\n\tno file " LUA_QS, filename);
+ lua_remove(L, -2); /* remove file name */
+ luaL_addvalue(&msg); /* concatenate error msg. entry */
+ }
+ luaL_pushresult(&msg); /* create error message */
+ return NULL; /* not found */
+}
+
+static int lj_cf_package_searchpath(lua_State *L)
+{
+ const char *f = searchpath(L, luaL_checkstring(L, 1),
+ luaL_checkstring(L, 2),
+ luaL_optstring(L, 3, "."),
+ luaL_optstring(L, 4, LUA_DIRSEP));
+ if (f != NULL) {
+ return 1;
+ } else { /* error message is on top of the stack */
+ lua_pushnil(L);
+ lua_insert(L, -2);
+ return 2; /* return nil + error message */
+ }
+}
+
+static const char *findfile(lua_State *L, const char *name,
+ const char *pname)
+{
+ const char *path;
+ lua_getfield(L, LUA_ENVIRONINDEX, pname);
+ path = lua_tostring(L, -1);
+ if (path == NULL)
+ luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
+ return searchpath(L, name, path, ".", LUA_DIRSEP);
+}
+
+static void loaderror(lua_State *L, const char *filename)
+{
+ luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s",
+ lua_tostring(L, 1), filename, lua_tostring(L, -1));
+}
+
+static int lj_cf_package_loader_lua(lua_State *L)
+{
+ const char *filename;
+ const char *name = luaL_checkstring(L, 1);
+ filename = findfile(L, name, "path");
+ if (filename == NULL) return 1; /* library not found in this path */
+ if (luaL_loadfile(L, filename) != 0)
+ loaderror(L, filename);
+ return 1; /* library loaded successfully */
+}
+
+static int lj_cf_package_loader_c(lua_State *L)
+{
+ const char *name = luaL_checkstring(L, 1);
+ const char *filename = findfile(L, name, "cpath");
+ if (filename == NULL) return 1; /* library not found in this path */
+ if (ll_loadfunc(L, filename, name, 0) != 0)
+ loaderror(L, filename);
+ return 1; /* library loaded successfully */
+}
+
+static int lj_cf_package_loader_croot(lua_State *L)
+{
+ const char *filename;
+ const char *name = luaL_checkstring(L, 1);
+ const char *p = strchr(name, '.');
+ int st;
+ if (p == NULL) return 0; /* is root */
+ lua_pushlstring(L, name, (size_t)(p - name));
+ filename = findfile(L, lua_tostring(L, -1), "cpath");
+ if (filename == NULL) return 1; /* root not found */
+ if ((st = ll_loadfunc(L, filename, name, 0)) != 0) {
+ if (st != PACKAGE_ERR_FUNC) loaderror(L, filename); /* real error */
+ lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS,
+ name, filename);
+ return 1; /* function not found */
+ }
+ return 1;
+}
+
+static int lj_cf_package_loader_preload(lua_State *L)
+{
+ const char *name = luaL_checkstring(L, 1);
+ lua_getfield(L, LUA_ENVIRONINDEX, "preload");
+ if (!lua_istable(L, -1))
+ luaL_error(L, LUA_QL("package.preload") " must be a table");
+ lua_getfield(L, -1, name);
+ if (lua_isnil(L, -1)) { /* Not found? */
+ const char *bcname = mksymname(L, name, SYMPREFIX_BC);
+ const char *bcdata = ll_bcsym(NULL, bcname);
+ if (bcdata == NULL || luaL_loadbuffer(L, bcdata, ~(size_t)0, name) != 0)
+ lua_pushfstring(L, "\n\tno field package.preload['%s']", name);
+ }
+ return 1;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static const int sentinel_ = 0;
+#define sentinel ((void *)&sentinel_)
+
+static int lj_cf_package_require(lua_State *L)
+{
+ const char *name = luaL_checkstring(L, 1);
+ int i;
+ lua_settop(L, 1); /* _LOADED table will be at index 2 */
+ lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
+ lua_getfield(L, 2, name);
+ if (lua_toboolean(L, -1)) { /* is it there? */
+ if (lua_touserdata(L, -1) == sentinel) /* check loops */
+ luaL_error(L, "loop or previous error loading module " LUA_QS, name);
+ return 1; /* package is already loaded */
+ }
+ /* else must load it; iterate over available loaders */
+ lua_getfield(L, LUA_ENVIRONINDEX, "loaders");
+ if (!lua_istable(L, -1))
+ luaL_error(L, LUA_QL("package.loaders") " must be a table");
+ lua_pushliteral(L, ""); /* error message accumulator */
+ for (i = 1; ; i++) {
+ lua_rawgeti(L, -2, i); /* get a loader */
+ if (lua_isnil(L, -1))
+ luaL_error(L, "module " LUA_QS " not found:%s",
+ name, lua_tostring(L, -2));
+ lua_pushstring(L, name);
+ lua_call(L, 1, 1); /* call it */
+ if (lua_isfunction(L, -1)) /* did it find module? */
+ break; /* module loaded successfully */
+ else if (lua_isstring(L, -1)) /* loader returned error message? */
+ lua_concat(L, 2); /* accumulate it */
+ else
+ lua_pop(L, 1);
+ }
+ lua_pushlightuserdata(L, sentinel);
+ lua_setfield(L, 2, name); /* _LOADED[name] = sentinel */
+ lua_pushstring(L, name); /* pass name as argument to module */
+ lua_call(L, 1, 1); /* run loaded module */
+ if (!lua_isnil(L, -1)) /* non-nil return? */
+ lua_setfield(L, 2, name); /* _LOADED[name] = returned value */
+ lua_getfield(L, 2, name);
+ if (lua_touserdata(L, -1) == sentinel) { /* module did not set a value? */
+ lua_pushboolean(L, 1); /* use true as result */
+ lua_pushvalue(L, -1); /* extra copy to be returned */
+ lua_setfield(L, 2, name); /* _LOADED[name] = true */
+ }
+ lj_lib_checkfpu(L);
+ return 1;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static void setfenv(lua_State *L)
+{
+ lua_Debug ar;
+ if (lua_getstack(L, 1, &ar) == 0 ||
+ lua_getinfo(L, "f", &ar) == 0 || /* get calling function */
+ lua_iscfunction(L, -1))
+ luaL_error(L, LUA_QL("module") " not called from a Lua function");
+ lua_pushvalue(L, -2);
+ lua_setfenv(L, -2);
+ lua_pop(L, 1);
+}
+
+static void dooptions(lua_State *L, int n)
+{
+ int i;
+ for (i = 2; i <= n; i++) {
+ lua_pushvalue(L, i); /* get option (a function) */
+ lua_pushvalue(L, -2); /* module */
+ lua_call(L, 1, 0);
+ }
+}
+
+static void modinit(lua_State *L, const char *modname)
+{
+ const char *dot;
+ lua_pushvalue(L, -1);
+ lua_setfield(L, -2, "_M"); /* module._M = module */
+ lua_pushstring(L, modname);
+ lua_setfield(L, -2, "_NAME");
+ dot = strrchr(modname, '.'); /* look for last dot in module name */
+ if (dot == NULL) dot = modname; else dot++;
+ /* set _PACKAGE as package name (full module name minus last part) */
+ lua_pushlstring(L, modname, (size_t)(dot - modname));
+ lua_setfield(L, -2, "_PACKAGE");
+}
+
+static int lj_cf_package_module(lua_State *L)
+{
+ const char *modname = luaL_checkstring(L, 1);
+ int loaded = lua_gettop(L) + 1; /* index of _LOADED table */
+ lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
+ lua_getfield(L, loaded, modname); /* get _LOADED[modname] */
+ if (!lua_istable(L, -1)) { /* not found? */
+ lua_pop(L, 1); /* remove previous result */
+ /* try global variable (and create one if it does not exist) */
+ if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL)
+ lj_err_callerv(L, LJ_ERR_BADMODN, modname);
+ lua_pushvalue(L, -1);
+ lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */
+ }
+ /* check whether table already has a _NAME field */
+ lua_getfield(L, -1, "_NAME");
+ if (!lua_isnil(L, -1)) { /* is table an initialized module? */
+ lua_pop(L, 1);
+ } else { /* no; initialize it */
+ lua_pop(L, 1);
+ modinit(L, modname);
+ }
+ lua_pushvalue(L, -1);
+ setfenv(L);
+ dooptions(L, loaded - 1);
+ return 0;
+}
+
+static int lj_cf_package_seeall(lua_State *L)
+{
+ luaL_checktype(L, 1, LUA_TTABLE);
+ if (!lua_getmetatable(L, 1)) {
+ lua_createtable(L, 0, 1); /* create new metatable */
+ lua_pushvalue(L, -1);
+ lua_setmetatable(L, 1);
+ }
+ lua_pushvalue(L, LUA_GLOBALSINDEX);
+ lua_setfield(L, -2, "__index"); /* mt.__index = _G */
+ return 0;
+}
+
+/* ------------------------------------------------------------------------ */
+
+#define AUXMARK "\1"
+
+static void setpath(lua_State *L, const char *fieldname, const char *envname,
+ const char *def, int noenv)
+{
+#if LJ_TARGET_CONSOLE
+ const char *path = NULL;
+ UNUSED(envname);
+#else
+ const char *path = getenv(envname);
+#endif
+ if (path == NULL || noenv) {
+ lua_pushstring(L, def);
+ } else {
+ path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP,
+ LUA_PATHSEP AUXMARK LUA_PATHSEP);
+ luaL_gsub(L, path, AUXMARK, def);
+ lua_remove(L, -2);
+ }
+ setprogdir(L);
+ lua_setfield(L, -2, fieldname);
+}
+
+static const luaL_Reg package_lib[] = {
+ { "loadlib", lj_cf_package_loadlib },
+ { "searchpath", lj_cf_package_searchpath },
+ { "seeall", lj_cf_package_seeall },
+ { NULL, NULL }
+};
+
+static const luaL_Reg package_global[] = {
+ { "module", lj_cf_package_module },
+ { "require", lj_cf_package_require },
+ { NULL, NULL }
+};
+
+static const lua_CFunction package_loaders[] =
+{
+ lj_cf_package_loader_preload,
+ lj_cf_package_loader_lua,
+ lj_cf_package_loader_c,
+ lj_cf_package_loader_croot,
+ NULL
+};
+
+LUALIB_API int luaopen_package(lua_State *L)
+{
+ int i;
+ int noenv;
+ luaL_newmetatable(L, "_LOADLIB");
+ lj_lib_pushcf(L, lj_cf_package_unloadlib, 1);
+ lua_setfield(L, -2, "__gc");
+ luaL_register(L, LUA_LOADLIBNAME, package_lib);
+ lua_pushvalue(L, -1);
+ lua_replace(L, LUA_ENVIRONINDEX);
+ lua_createtable(L, sizeof(package_loaders)/sizeof(package_loaders[0])-1, 0);
+ for (i = 0; package_loaders[i] != NULL; i++) {
+ lj_lib_pushcf(L, package_loaders[i], 1);
+ lua_rawseti(L, -2, i+1);
+ }
+ lua_setfield(L, -2, "loaders");
+ lua_getfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
+ noenv = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+ setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT, noenv);
+ setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT, noenv);
+ lua_pushliteral(L, LUA_PATH_CONFIG);
+ lua_setfield(L, -2, "config");
+ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16);
+ lua_setfield(L, -2, "loaded");
+ luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD", 4);
+ lua_setfield(L, -2, "preload");
+ lua_pushvalue(L, LUA_GLOBALSINDEX);
+ luaL_register(L, NULL, package_global);
+ lua_pop(L, 1);
+ return 1;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lib_string.c b/src/3rdparty/LuaJIT-2.0.5/src/lib_string.c
new file mode 100644
index 0000000..c1e595c
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lib_string.c
@@ -0,0 +1,941 @@
+/*
+** String library.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Major portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#include <stdio.h>
+
+#define lib_string_c
+#define LUA_LIB
+
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_meta.h"
+#include "lj_state.h"
+#include "lj_ff.h"
+#include "lj_bcdump.h"
+#include "lj_char.h"
+#include "lj_lib.h"
+
+/* ------------------------------------------------------------------------ */
+
+#define LJLIB_MODULE_string
+
+LJLIB_ASM(string_len) LJLIB_REC(.)
+{
+ lj_lib_checkstr(L, 1);
+ return FFH_RETRY;
+}
+
+LJLIB_ASM(string_byte) LJLIB_REC(string_range 0)
+{
+ GCstr *s = lj_lib_checkstr(L, 1);
+ int32_t len = (int32_t)s->len;
+ int32_t start = lj_lib_optint(L, 2, 1);
+ int32_t stop = lj_lib_optint(L, 3, start);
+ int32_t n, i;
+ const unsigned char *p;
+ if (stop < 0) stop += len+1;
+ if (start < 0) start += len+1;
+ if (start <= 0) start = 1;
+ if (stop > len) stop = len;
+ if (start > stop) return FFH_RES(0); /* Empty interval: return no results. */
+ start--;
+ n = stop - start;
+ if ((uint32_t)n > LUAI_MAXCSTACK)
+ lj_err_caller(L, LJ_ERR_STRSLC);
+ lj_state_checkstack(L, (MSize)n);
+ p = (const unsigned char *)strdata(s) + start;
+ for (i = 0; i < n; i++)
+ setintV(L->base + i-1, p[i]);
+ return FFH_RES(n);
+}
+
+LJLIB_ASM(string_char)
+{
+ int i, nargs = (int)(L->top - L->base);
+ char *buf = lj_str_needbuf(L, &G(L)->tmpbuf, (MSize)nargs);
+ for (i = 1; i <= nargs; i++) {
+ int32_t k = lj_lib_checkint(L, i);
+ if (!checku8(k))
+ lj_err_arg(L, i, LJ_ERR_BADVAL);
+ buf[i-1] = (char)k;
+ }
+ setstrV(L, L->base-1, lj_str_new(L, buf, (size_t)nargs));
+ return FFH_RES(1);
+}
+
+LJLIB_ASM(string_sub) LJLIB_REC(string_range 1)
+{
+ lj_lib_checkstr(L, 1);
+ lj_lib_checkint(L, 2);
+ setintV(L->base+2, lj_lib_optint(L, 3, -1));
+ return FFH_RETRY;
+}
+
+LJLIB_ASM(string_rep)
+{
+ GCstr *s = lj_lib_checkstr(L, 1);
+ int32_t k = lj_lib_checkint(L, 2);
+ GCstr *sep = lj_lib_optstr(L, 3);
+ int32_t len = (int32_t)s->len;
+ global_State *g = G(L);
+ int64_t tlen;
+ const char *src;
+ char *buf;
+ if (k <= 0) {
+ empty:
+ setstrV(L, L->base-1, &g->strempty);
+ return FFH_RES(1);
+ }
+ if (sep) {
+ tlen = (int64_t)len + sep->len;
+ if (tlen > LJ_MAX_STR)
+ lj_err_caller(L, LJ_ERR_STROV);
+ tlen *= k;
+ if (tlen > LJ_MAX_STR)
+ lj_err_caller(L, LJ_ERR_STROV);
+ } else {
+ tlen = (int64_t)k * len;
+ if (tlen > LJ_MAX_STR)
+ lj_err_caller(L, LJ_ERR_STROV);
+ }
+ if (tlen == 0) goto empty;
+ buf = lj_str_needbuf(L, &g->tmpbuf, (MSize)tlen);
+ src = strdata(s);
+ if (sep) {
+ tlen -= sep->len; /* Ignore trailing separator. */
+ if (k > 1) { /* Paste one string and one separator. */
+ int32_t i;
+ i = 0; while (i < len) *buf++ = src[i++];
+ src = strdata(sep); len = sep->len;
+ i = 0; while (i < len) *buf++ = src[i++];
+ src = g->tmpbuf.buf; len += s->len; k--; /* Now copy that k-1 times. */
+ }
+ }
+ do {
+ int32_t i = 0;
+ do { *buf++ = src[i++]; } while (i < len);
+ } while (--k > 0);
+ setstrV(L, L->base-1, lj_str_new(L, g->tmpbuf.buf, (size_t)tlen));
+ return FFH_RES(1);
+}
+
+LJLIB_ASM(string_reverse)
+{
+ GCstr *s = lj_lib_checkstr(L, 1);
+ lj_str_needbuf(L, &G(L)->tmpbuf, s->len);
+ return FFH_RETRY;
+}
+LJLIB_ASM_(string_lower)
+LJLIB_ASM_(string_upper)
+
+/* ------------------------------------------------------------------------ */
+
+static int writer_buf(lua_State *L, const void *p, size_t size, void *b)
+{
+ luaL_addlstring((luaL_Buffer *)b, (const char *)p, size);
+ UNUSED(L);
+ return 0;
+}
+
+LJLIB_CF(string_dump)
+{
+ GCfunc *fn = lj_lib_checkfunc(L, 1);
+ int strip = L->base+1 < L->top && tvistruecond(L->base+1);
+ luaL_Buffer b;
+ L->top = L->base+1;
+ luaL_buffinit(L, &b);
+ if (!isluafunc(fn) || lj_bcwrite(L, funcproto(fn), writer_buf, &b, strip))
+ lj_err_caller(L, LJ_ERR_STRDUMP);
+ luaL_pushresult(&b);
+ return 1;
+}
+
+/* ------------------------------------------------------------------------ */
+
+/* macro to `unsign' a character */
+#define uchar(c) ((unsigned char)(c))
+
+#define CAP_UNFINISHED (-1)
+#define CAP_POSITION (-2)
+
+typedef struct MatchState {
+ const char *src_init; /* init of source string */
+ const char *src_end; /* end (`\0') of source string */
+ lua_State *L;
+ int level; /* total number of captures (finished or unfinished) */
+ int depth;
+ struct {
+ const char *init;
+ ptrdiff_t len;
+ } capture[LUA_MAXCAPTURES];
+} MatchState;
+
+#define L_ESC '%'
+#define SPECIALS "^$*+?.([%-"
+
+static int check_capture(MatchState *ms, int l)
+{
+ l -= '1';
+ if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)
+ lj_err_caller(ms->L, LJ_ERR_STRCAPI);
+ return l;
+}
+
+static int capture_to_close(MatchState *ms)
+{
+ int level = ms->level;
+ for (level--; level>=0; level--)
+ if (ms->capture[level].len == CAP_UNFINISHED) return level;
+ lj_err_caller(ms->L, LJ_ERR_STRPATC);
+ return 0; /* unreachable */
+}
+
+static const char *classend(MatchState *ms, const char *p)
+{
+ switch (*p++) {
+ case L_ESC:
+ if (*p == '\0')
+ lj_err_caller(ms->L, LJ_ERR_STRPATE);
+ return p+1;
+ case '[':
+ if (*p == '^') p++;
+ do { /* look for a `]' */
+ if (*p == '\0')
+ lj_err_caller(ms->L, LJ_ERR_STRPATM);
+ if (*(p++) == L_ESC && *p != '\0')
+ p++; /* skip escapes (e.g. `%]') */
+ } while (*p != ']');
+ return p+1;
+ default:
+ return p;
+ }
+}
+
+static const unsigned char match_class_map[32] = {
+ 0,LJ_CHAR_ALPHA,0,LJ_CHAR_CNTRL,LJ_CHAR_DIGIT,0,0,LJ_CHAR_GRAPH,0,0,0,0,
+ LJ_CHAR_LOWER,0,0,0,LJ_CHAR_PUNCT,0,0,LJ_CHAR_SPACE,0,
+ LJ_CHAR_UPPER,0,LJ_CHAR_ALNUM,LJ_CHAR_XDIGIT,0,0,0,0,0,0,0
+};
+
+static int match_class(int c, int cl)
+{
+ if ((cl & 0xc0) == 0x40) {
+ int t = match_class_map[(cl&0x1f)];
+ if (t) {
+ t = lj_char_isa(c, t);
+ return (cl & 0x20) ? t : !t;
+ }
+ if (cl == 'z') return c == 0;
+ if (cl == 'Z') return c != 0;
+ }
+ return (cl == c);
+}
+
+static int matchbracketclass(int c, const char *p, const char *ec)
+{
+ int sig = 1;
+ if (*(p+1) == '^') {
+ sig = 0;
+ p++; /* skip the `^' */
+ }
+ while (++p < ec) {
+ if (*p == L_ESC) {
+ p++;
+ if (match_class(c, uchar(*p)))
+ return sig;
+ }
+ else if ((*(p+1) == '-') && (p+2 < ec)) {
+ p+=2;
+ if (uchar(*(p-2)) <= c && c <= uchar(*p))
+ return sig;
+ }
+ else if (uchar(*p) == c) return sig;
+ }
+ return !sig;
+}
+
+static int singlematch(int c, const char *p, const char *ep)
+{
+ switch (*p) {
+ case '.': return 1; /* matches any char */
+ case L_ESC: return match_class(c, uchar(*(p+1)));
+ case '[': return matchbracketclass(c, p, ep-1);
+ default: return (uchar(*p) == c);
+ }
+}
+
+static const char *match(MatchState *ms, const char *s, const char *p);
+
+static const char *matchbalance(MatchState *ms, const char *s, const char *p)
+{
+ if (*p == 0 || *(p+1) == 0)
+ lj_err_caller(ms->L, LJ_ERR_STRPATU);
+ if (*s != *p) {
+ return NULL;
+ } else {
+ int b = *p;
+ int e = *(p+1);
+ int cont = 1;
+ while (++s < ms->src_end) {
+ if (*s == e) {
+ if (--cont == 0) return s+1;
+ } else if (*s == b) {
+ cont++;
+ }
+ }
+ }
+ return NULL; /* string ends out of balance */
+}
+
+static const char *max_expand(MatchState *ms, const char *s,
+ const char *p, const char *ep)
+{
+ ptrdiff_t i = 0; /* counts maximum expand for item */
+ while ((s+i)<ms->src_end && singlematch(uchar(*(s+i)), p, ep))
+ i++;
+ /* keeps trying to match with the maximum repetitions */
+ while (i>=0) {
+ const char *res = match(ms, (s+i), ep+1);
+ if (res) return res;
+ i--; /* else didn't match; reduce 1 repetition to try again */
+ }
+ return NULL;
+}
+
+static const char *min_expand(MatchState *ms, const char *s,
+ const char *p, const char *ep)
+{
+ for (;;) {
+ const char *res = match(ms, s, ep+1);
+ if (res != NULL)
+ return res;
+ else if (s<ms->src_end && singlematch(uchar(*s), p, ep))
+ s++; /* try with one more repetition */
+ else
+ return NULL;
+ }
+}
+
+static const char *start_capture(MatchState *ms, const char *s,
+ const char *p, int what)
+{
+ const char *res;
+ int level = ms->level;
+ if (level >= LUA_MAXCAPTURES) lj_err_caller(ms->L, LJ_ERR_STRCAPN);
+ ms->capture[level].init = s;
+ ms->capture[level].len = what;
+ ms->level = level+1;
+ if ((res=match(ms, s, p)) == NULL) /* match failed? */
+ ms->level--; /* undo capture */
+ return res;
+}
+
+static const char *end_capture(MatchState *ms, const char *s,
+ const char *p)
+{
+ int l = capture_to_close(ms);
+ const char *res;
+ ms->capture[l].len = s - ms->capture[l].init; /* close capture */
+ if ((res = match(ms, s, p)) == NULL) /* match failed? */
+ ms->capture[l].len = CAP_UNFINISHED; /* undo capture */
+ return res;
+}
+
+static const char *match_capture(MatchState *ms, const char *s, int l)
+{
+ size_t len;
+ l = check_capture(ms, l);
+ len = (size_t)ms->capture[l].len;
+ if ((size_t)(ms->src_end-s) >= len &&
+ memcmp(ms->capture[l].init, s, len) == 0)
+ return s+len;
+ else
+ return NULL;
+}
+
+static const char *match(MatchState *ms, const char *s, const char *p)
+{
+ if (++ms->depth > LJ_MAX_XLEVEL)
+ lj_err_caller(ms->L, LJ_ERR_STRPATX);
+ init: /* using goto's to optimize tail recursion */
+ switch (*p) {
+ case '(': /* start capture */
+ if (*(p+1) == ')') /* position capture? */
+ s = start_capture(ms, s, p+2, CAP_POSITION);
+ else
+ s = start_capture(ms, s, p+1, CAP_UNFINISHED);
+ break;
+ case ')': /* end capture */
+ s = end_capture(ms, s, p+1);
+ break;
+ case L_ESC:
+ switch (*(p+1)) {
+ case 'b': /* balanced string? */
+ s = matchbalance(ms, s, p+2);
+ if (s == NULL) break;
+ p+=4;
+ goto init; /* else s = match(ms, s, p+4); */
+ case 'f': { /* frontier? */
+ const char *ep; char previous;
+ p += 2;
+ if (*p != '[')
+ lj_err_caller(ms->L, LJ_ERR_STRPATB);
+ ep = classend(ms, p); /* points to what is next */
+ previous = (s == ms->src_init) ? '\0' : *(s-1);
+ if (matchbracketclass(uchar(previous), p, ep-1) ||
+ !matchbracketclass(uchar(*s), p, ep-1)) { s = NULL; break; }
+ p=ep;
+ goto init; /* else s = match(ms, s, ep); */
+ }
+ default:
+ if (lj_char_isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */
+ s = match_capture(ms, s, uchar(*(p+1)));
+ if (s == NULL) break;
+ p+=2;
+ goto init; /* else s = match(ms, s, p+2) */
+ }
+ goto dflt; /* case default */
+ }
+ break;
+ case '\0': /* end of pattern */
+ break; /* match succeeded */
+ case '$':
+ /* is the `$' the last char in pattern? */
+ if (*(p+1) != '\0') goto dflt;
+ if (s != ms->src_end) s = NULL; /* check end of string */
+ break;
+ default: dflt: { /* it is a pattern item */
+ const char *ep = classend(ms, p); /* points to what is next */
+ int m = s<ms->src_end && singlematch(uchar(*s), p, ep);
+ switch (*ep) {
+ case '?': { /* optional */
+ const char *res;
+ if (m && ((res=match(ms, s+1, ep+1)) != NULL)) {
+ s = res;
+ break;
+ }
+ p=ep+1;
+ goto init; /* else s = match(ms, s, ep+1); */
+ }
+ case '*': /* 0 or more repetitions */
+ s = max_expand(ms, s, p, ep);
+ break;
+ case '+': /* 1 or more repetitions */
+ s = (m ? max_expand(ms, s+1, p, ep) : NULL);
+ break;
+ case '-': /* 0 or more repetitions (minimum) */
+ s = min_expand(ms, s, p, ep);
+ break;
+ default:
+ if (m) { s++; p=ep; goto init; } /* else s = match(ms, s+1, ep); */
+ s = NULL;
+ break;
+ }
+ break;
+ }
+ }
+ ms->depth--;
+ return s;
+}
+
+static const char *lmemfind(const char *s1, size_t l1,
+ const char *s2, size_t l2)
+{
+ if (l2 == 0) {
+ return s1; /* empty strings are everywhere */
+ } else if (l2 > l1) {
+ return NULL; /* avoids a negative `l1' */
+ } else {
+ const char *init; /* to search for a `*s2' inside `s1' */
+ l2--; /* 1st char will be checked by `memchr' */
+ l1 = l1-l2; /* `s2' cannot be found after that */
+ while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) {
+ init++; /* 1st char is already checked */
+ if (memcmp(init, s2+1, l2) == 0) {
+ return init-1;
+ } else { /* correct `l1' and `s1' to try again */
+ l1 -= (size_t)(init-s1);
+ s1 = init;
+ }
+ }
+ return NULL; /* not found */
+ }
+}
+
+static void push_onecapture(MatchState *ms, int i, const char *s, const char *e)
+{
+ if (i >= ms->level) {
+ if (i == 0) /* ms->level == 0, too */
+ lua_pushlstring(ms->L, s, (size_t)(e - s)); /* add whole match */
+ else
+ lj_err_caller(ms->L, LJ_ERR_STRCAPI);
+ } else {
+ ptrdiff_t l = ms->capture[i].len;
+ if (l == CAP_UNFINISHED) lj_err_caller(ms->L, LJ_ERR_STRCAPU);
+ if (l == CAP_POSITION)
+ lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1);
+ else
+ lua_pushlstring(ms->L, ms->capture[i].init, (size_t)l);
+ }
+}
+
+static int push_captures(MatchState *ms, const char *s, const char *e)
+{
+ int i;
+ int nlevels = (ms->level == 0 && s) ? 1 : ms->level;
+ luaL_checkstack(ms->L, nlevels, "too many captures");
+ for (i = 0; i < nlevels; i++)
+ push_onecapture(ms, i, s, e);
+ return nlevels; /* number of strings pushed */
+}
+
+static ptrdiff_t posrelat(ptrdiff_t pos, size_t len)
+{
+ /* relative string position: negative means back from end */
+ if (pos < 0) pos += (ptrdiff_t)len + 1;
+ return (pos >= 0) ? pos : 0;
+}
+
+static int str_find_aux(lua_State *L, int find)
+{
+ size_t l1, l2;
+ const char *s = luaL_checklstring(L, 1, &l1);
+ const char *p = luaL_checklstring(L, 2, &l2);
+ ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1;
+ if (init < 0) {
+ init = 0;
+ } else if ((size_t)(init) > l1) {
+#if LJ_52
+ setnilV(L->top-1);
+ return 1;
+#else
+ init = (ptrdiff_t)l1;
+#endif
+ }
+ if (find && (lua_toboolean(L, 4) || /* explicit request? */
+ strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */
+ /* do a plain search */
+ const char *s2 = lmemfind(s+init, l1-(size_t)init, p, l2);
+ if (s2) {
+ lua_pushinteger(L, s2-s+1);
+ lua_pushinteger(L, s2-s+(ptrdiff_t)l2);
+ return 2;
+ }
+ } else {
+ MatchState ms;
+ int anchor = (*p == '^') ? (p++, 1) : 0;
+ const char *s1=s+init;
+ ms.L = L;
+ ms.src_init = s;
+ ms.src_end = s+l1;
+ do {
+ const char *res;
+ ms.level = ms.depth = 0;
+ if ((res=match(&ms, s1, p)) != NULL) {
+ if (find) {
+ lua_pushinteger(L, s1-s+1); /* start */
+ lua_pushinteger(L, res-s); /* end */
+ return push_captures(&ms, NULL, 0) + 2;
+ } else {
+ return push_captures(&ms, s1, res);
+ }
+ }
+ } while (s1++ < ms.src_end && !anchor);
+ }
+ lua_pushnil(L); /* not found */
+ return 1;
+}
+
+LJLIB_CF(string_find)
+{
+ return str_find_aux(L, 1);
+}
+
+LJLIB_CF(string_match)
+{
+ return str_find_aux(L, 0);
+}
+
+LJLIB_NOREG LJLIB_CF(string_gmatch_aux)
+{
+ const char *p = strVdata(lj_lib_upvalue(L, 2));
+ GCstr *str = strV(lj_lib_upvalue(L, 1));
+ const char *s = strdata(str);
+ TValue *tvpos = lj_lib_upvalue(L, 3);
+ const char *src = s + tvpos->u32.lo;
+ MatchState ms;
+ ms.L = L;
+ ms.src_init = s;
+ ms.src_end = s + str->len;
+ for (; src <= ms.src_end; src++) {
+ const char *e;
+ ms.level = ms.depth = 0;
+ if ((e = match(&ms, src, p)) != NULL) {
+ int32_t pos = (int32_t)(e - s);
+ if (e == src) pos++; /* Ensure progress for empty match. */
+ tvpos->u32.lo = (uint32_t)pos;
+ return push_captures(&ms, src, e);
+ }
+ }
+ return 0; /* not found */
+}
+
+LJLIB_CF(string_gmatch)
+{
+ lj_lib_checkstr(L, 1);
+ lj_lib_checkstr(L, 2);
+ L->top = L->base+3;
+ (L->top-1)->u64 = 0;
+ lj_lib_pushcc(L, lj_cf_string_gmatch_aux, FF_string_gmatch_aux, 3);
+ return 1;
+}
+
+static void add_s(MatchState *ms, luaL_Buffer *b, const char *s, const char *e)
+{
+ size_t l, i;
+ const char *news = lua_tolstring(ms->L, 3, &l);
+ for (i = 0; i < l; i++) {
+ if (news[i] != L_ESC) {
+ luaL_addchar(b, news[i]);
+ } else {
+ i++; /* skip ESC */
+ if (!lj_char_isdigit(uchar(news[i]))) {
+ luaL_addchar(b, news[i]);
+ } else if (news[i] == '0') {
+ luaL_addlstring(b, s, (size_t)(e - s));
+ } else {
+ push_onecapture(ms, news[i] - '1', s, e);
+ luaL_addvalue(b); /* add capture to accumulated result */
+ }
+ }
+ }
+}
+
+static void add_value(MatchState *ms, luaL_Buffer *b,
+ const char *s, const char *e)
+{
+ lua_State *L = ms->L;
+ switch (lua_type(L, 3)) {
+ case LUA_TNUMBER:
+ case LUA_TSTRING: {
+ add_s(ms, b, s, e);
+ return;
+ }
+ case LUA_TFUNCTION: {
+ int n;
+ lua_pushvalue(L, 3);
+ n = push_captures(ms, s, e);
+ lua_call(L, n, 1);
+ break;
+ }
+ case LUA_TTABLE: {
+ push_onecapture(ms, 0, s, e);
+ lua_gettable(L, 3);
+ break;
+ }
+ }
+ if (!lua_toboolean(L, -1)) { /* nil or false? */
+ lua_pop(L, 1);
+ lua_pushlstring(L, s, (size_t)(e - s)); /* keep original text */
+ } else if (!lua_isstring(L, -1)) {
+ lj_err_callerv(L, LJ_ERR_STRGSRV, luaL_typename(L, -1));
+ }
+ luaL_addvalue(b); /* add result to accumulator */
+}
+
+LJLIB_CF(string_gsub)
+{
+ size_t srcl;
+ const char *src = luaL_checklstring(L, 1, &srcl);
+ const char *p = luaL_checkstring(L, 2);
+ int tr = lua_type(L, 3);
+ int max_s = luaL_optint(L, 4, (int)(srcl+1));
+ int anchor = (*p == '^') ? (p++, 1) : 0;
+ int n = 0;
+ MatchState ms;
+ luaL_Buffer b;
+ if (!(tr == LUA_TNUMBER || tr == LUA_TSTRING ||
+ tr == LUA_TFUNCTION || tr == LUA_TTABLE))
+ lj_err_arg(L, 3, LJ_ERR_NOSFT);
+ luaL_buffinit(L, &b);
+ ms.L = L;
+ ms.src_init = src;
+ ms.src_end = src+srcl;
+ while (n < max_s) {
+ const char *e;
+ ms.level = ms.depth = 0;
+ e = match(&ms, src, p);
+ if (e) {
+ n++;
+ add_value(&ms, &b, src, e);
+ }
+ if (e && e>src) /* non empty match? */
+ src = e; /* skip it */
+ else if (src < ms.src_end)
+ luaL_addchar(&b, *src++);
+ else
+ break;
+ if (anchor)
+ break;
+ }
+ luaL_addlstring(&b, src, (size_t)(ms.src_end-src));
+ luaL_pushresult(&b);
+ lua_pushinteger(L, n); /* number of substitutions */
+ return 2;
+}
+
+/* ------------------------------------------------------------------------ */
+
+/* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */
+#define MAX_FMTITEM 512
+/* valid flags in a format specification */
+#define FMT_FLAGS "-+ #0"
+/*
+** maximum size of each format specification (such as '%-099.99d')
+** (+10 accounts for %99.99x plus margin of error)
+*/
+#define MAX_FMTSPEC (sizeof(FMT_FLAGS) + sizeof(LUA_INTFRMLEN) + 10)
+
+static void addquoted(lua_State *L, luaL_Buffer *b, int arg)
+{
+ GCstr *str = lj_lib_checkstr(L, arg);
+ int32_t len = (int32_t)str->len;
+ const char *s = strdata(str);
+ luaL_addchar(b, '"');
+ while (len--) {
+ uint32_t c = uchar(*s);
+ if (c == '"' || c == '\\' || c == '\n') {
+ luaL_addchar(b, '\\');
+ } else if (lj_char_iscntrl(c)) { /* This can only be 0-31 or 127. */
+ uint32_t d;
+ luaL_addchar(b, '\\');
+ if (c >= 100 || lj_char_isdigit(uchar(s[1]))) {
+ luaL_addchar(b, '0'+(c >= 100)); if (c >= 100) c -= 100;
+ goto tens;
+ } else if (c >= 10) {
+ tens:
+ d = (c * 205) >> 11; c -= d * 10; luaL_addchar(b, '0'+d);
+ }
+ c += '0';
+ }
+ luaL_addchar(b, c);
+ s++;
+ }
+ luaL_addchar(b, '"');
+}
+
+static const char *scanformat(lua_State *L, const char *strfrmt, char *form)
+{
+ const char *p = strfrmt;
+ while (*p != '\0' && strchr(FMT_FLAGS, *p) != NULL) p++; /* skip flags */
+ if ((size_t)(p - strfrmt) >= sizeof(FMT_FLAGS))
+ lj_err_caller(L, LJ_ERR_STRFMTR);
+ if (lj_char_isdigit(uchar(*p))) p++; /* skip width */
+ if (lj_char_isdigit(uchar(*p))) p++; /* (2 digits at most) */
+ if (*p == '.') {
+ p++;
+ if (lj_char_isdigit(uchar(*p))) p++; /* skip precision */
+ if (lj_char_isdigit(uchar(*p))) p++; /* (2 digits at most) */
+ }
+ if (lj_char_isdigit(uchar(*p)))
+ lj_err_caller(L, LJ_ERR_STRFMTW);
+ *(form++) = '%';
+ strncpy(form, strfrmt, (size_t)(p - strfrmt + 1));
+ form += p - strfrmt + 1;
+ *form = '\0';
+ return p;
+}
+
+static void addintlen(char *form)
+{
+ size_t l = strlen(form);
+ char spec = form[l - 1];
+ strcpy(form + l - 1, LUA_INTFRMLEN);
+ form[l + sizeof(LUA_INTFRMLEN) - 2] = spec;
+ form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0';
+}
+
+static unsigned LUA_INTFRM_T num2intfrm(lua_State *L, int arg)
+{
+ if (sizeof(LUA_INTFRM_T) == 4) {
+ return (LUA_INTFRM_T)lj_lib_checkbit(L, arg);
+ } else {
+ cTValue *o;
+ lj_lib_checknumber(L, arg);
+ o = L->base+arg-1;
+ if (tvisint(o))
+ return (LUA_INTFRM_T)intV(o);
+ else
+ return (LUA_INTFRM_T)numV(o);
+ }
+}
+
+static unsigned LUA_INTFRM_T num2uintfrm(lua_State *L, int arg)
+{
+ if (sizeof(LUA_INTFRM_T) == 4) {
+ return (unsigned LUA_INTFRM_T)lj_lib_checkbit(L, arg);
+ } else {
+ cTValue *o;
+ lj_lib_checknumber(L, arg);
+ o = L->base+arg-1;
+ if (tvisint(o))
+ return (unsigned LUA_INTFRM_T)intV(o);
+ else if ((int32_t)o->u32.hi < 0)
+ return (unsigned LUA_INTFRM_T)(LUA_INTFRM_T)numV(o);
+ else
+ return (unsigned LUA_INTFRM_T)numV(o);
+ }
+}
+
+static GCstr *meta_tostring(lua_State *L, int arg)
+{
+ TValue *o = L->base+arg-1;
+ cTValue *mo;
+ lua_assert(o < L->top); /* Caller already checks for existence. */
+ if (LJ_LIKELY(tvisstr(o)))
+ return strV(o);
+ if (!tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) {
+ copyTV(L, L->top++, mo);
+ copyTV(L, L->top++, o);
+ lua_call(L, 1, 1);
+ L->top--;
+ if (tvisstr(L->top))
+ return strV(L->top);
+ o = L->base+arg-1;
+ copyTV(L, o, L->top);
+ }
+ if (tvisnumber(o)) {
+ return lj_str_fromnumber(L, o);
+ } else if (tvisnil(o)) {
+ return lj_str_newlit(L, "nil");
+ } else if (tvisfalse(o)) {
+ return lj_str_newlit(L, "false");
+ } else if (tvistrue(o)) {
+ return lj_str_newlit(L, "true");
+ } else {
+ if (tvisfunc(o) && isffunc(funcV(o)))
+ lj_str_pushf(L, "function: builtin#%d", funcV(o)->c.ffid);
+ else
+ lj_str_pushf(L, "%s: %p", lj_typename(o), lua_topointer(L, arg));
+ L->top--;
+ return strV(L->top);
+ }
+}
+
+LJLIB_CF(string_format)
+{
+ int arg = 1, top = (int)(L->top - L->base);
+ GCstr *fmt = lj_lib_checkstr(L, arg);
+ const char *strfrmt = strdata(fmt);
+ const char *strfrmt_end = strfrmt + fmt->len;
+ luaL_Buffer b;
+ luaL_buffinit(L, &b);
+ while (strfrmt < strfrmt_end) {
+ if (*strfrmt != L_ESC) {
+ luaL_addchar(&b, *strfrmt++);
+ } else if (*++strfrmt == L_ESC) {
+ luaL_addchar(&b, *strfrmt++); /* %% */
+ } else { /* format item */
+ char form[MAX_FMTSPEC]; /* to store the format (`%...') */
+ char buff[MAX_FMTITEM]; /* to store the formatted item */
+ int n = 0;
+ if (++arg > top)
+ luaL_argerror(L, arg, lj_obj_typename[0]);
+ strfrmt = scanformat(L, strfrmt, form);
+ switch (*strfrmt++) {
+ case 'c':
+ n = sprintf(buff, form, lj_lib_checkint(L, arg));
+ break;
+ case 'd': case 'i':
+ addintlen(form);
+ n = sprintf(buff, form, num2intfrm(L, arg));
+ break;
+ case 'o': case 'u': case 'x': case 'X':
+ addintlen(form);
+ n = sprintf(buff, form, num2uintfrm(L, arg));
+ break;
+ case 'e': case 'E': case 'f': case 'g': case 'G': case 'a': case 'A': {
+ TValue tv;
+ tv.n = lj_lib_checknum(L, arg);
+ if (LJ_UNLIKELY((tv.u32.hi << 1) >= 0xffe00000)) {
+ /* Canonicalize output of non-finite values. */
+ char *p, nbuf[LJ_STR_NUMBUF];
+ size_t len = lj_str_bufnum(nbuf, &tv);
+ if (strfrmt[-1] < 'a') {
+ nbuf[len-3] = nbuf[len-3] - 0x20;
+ nbuf[len-2] = nbuf[len-2] - 0x20;
+ nbuf[len-1] = nbuf[len-1] - 0x20;
+ }
+ nbuf[len] = '\0';
+ for (p = form; *p < 'A' && *p != '.'; p++) ;
+ *p++ = 's'; *p = '\0';
+ n = sprintf(buff, form, nbuf);
+ break;
+ }
+ n = sprintf(buff, form, (double)tv.n);
+ break;
+ }
+ case 'q':
+ addquoted(L, &b, arg);
+ continue;
+ case 'p':
+ lj_str_pushf(L, "%p", lua_topointer(L, arg));
+ luaL_addvalue(&b);
+ continue;
+ case 's': {
+ GCstr *str = meta_tostring(L, arg);
+ if (!strchr(form, '.') && str->len >= 100) {
+ /* no precision and string is too long to be formatted;
+ keep original string */
+ setstrV(L, L->top++, str);
+ luaL_addvalue(&b);
+ continue;
+ }
+ n = sprintf(buff, form, strdata(str));
+ break;
+ }
+ default:
+ lj_err_callerv(L, LJ_ERR_STRFMTO, *(strfrmt -1));
+ break;
+ }
+ luaL_addlstring(&b, buff, n);
+ }
+ }
+ luaL_pushresult(&b);
+ return 1;
+}
+
+/* ------------------------------------------------------------------------ */
+
+#include "lj_libdef.h"
+
+LUALIB_API int luaopen_string(lua_State *L)
+{
+ GCtab *mt;
+ global_State *g;
+ LJ_LIB_REG(L, LUA_STRLIBNAME, string);
+#if defined(LUA_COMPAT_GFIND) && !LJ_52
+ lua_getfield(L, -1, "gmatch");
+ lua_setfield(L, -2, "gfind");
+#endif
+ mt = lj_tab_new(L, 0, 1);
+ /* NOBARRIER: basemt is a GC root. */
+ g = G(L);
+ setgcref(basemt_it(g, LJ_TSTR), obj2gco(mt));
+ settabV(L, lj_tab_setstr(L, mt, mmname_str(g, MM_index)), tabV(L->top-1));
+ mt->nomm = (uint8_t)(~(1u<<MM_index));
+ return 1;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lib_table.c b/src/3rdparty/LuaJIT-2.0.5/src/lib_table.c
new file mode 100644
index 0000000..b2856ee
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lib_table.c
@@ -0,0 +1,300 @@
+/*
+** Table library.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Major portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#define lib_table_c
+#define LUA_LIB
+
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_tab.h"
+#include "lj_lib.h"
+
+/* ------------------------------------------------------------------------ */
+
+#define LJLIB_MODULE_table
+
+LJLIB_CF(table_foreachi)
+{
+ GCtab *t = lj_lib_checktab(L, 1);
+ GCfunc *func = lj_lib_checkfunc(L, 2);
+ MSize i, n = lj_tab_len(t);
+ for (i = 1; i <= n; i++) {
+ cTValue *val;
+ setfuncV(L, L->top, func);
+ setintV(L->top+1, i);
+ val = lj_tab_getint(t, (int32_t)i);
+ if (val) { copyTV(L, L->top+2, val); } else { setnilV(L->top+2); }
+ L->top += 3;
+ lua_call(L, 2, 1);
+ if (!tvisnil(L->top-1))
+ return 1;
+ L->top--;
+ }
+ return 0;
+}
+
+LJLIB_CF(table_foreach)
+{
+ GCtab *t = lj_lib_checktab(L, 1);
+ GCfunc *func = lj_lib_checkfunc(L, 2);
+ L->top = L->base+3;
+ setnilV(L->top-1);
+ while (lj_tab_next(L, t, L->top-1)) {
+ copyTV(L, L->top+2, L->top);
+ copyTV(L, L->top+1, L->top-1);
+ setfuncV(L, L->top, func);
+ L->top += 3;
+ lua_call(L, 2, 1);
+ if (!tvisnil(L->top-1))
+ return 1;
+ L->top--;
+ }
+ return 0;
+}
+
+LJLIB_ASM(table_getn) LJLIB_REC(.)
+{
+ lj_lib_checktab(L, 1);
+ return FFH_UNREACHABLE;
+}
+
+LJLIB_CF(table_maxn)
+{
+ GCtab *t = lj_lib_checktab(L, 1);
+ TValue *array = tvref(t->array);
+ Node *node;
+ lua_Number m = 0;
+ ptrdiff_t i;
+ for (i = (ptrdiff_t)t->asize - 1; i >= 0; i--)
+ if (!tvisnil(&array[i])) {
+ m = (lua_Number)(int32_t)i;
+ break;
+ }
+ node = noderef(t->node);
+ for (i = (ptrdiff_t)t->hmask; i >= 0; i--)
+ if (!tvisnil(&node[i].val) && tvisnumber(&node[i].key)) {
+ lua_Number n = numberVnum(&node[i].key);
+ if (n > m) m = n;
+ }
+ setnumV(L->top-1, m);
+ return 1;
+}
+
+LJLIB_CF(table_insert) LJLIB_REC(.)
+{
+ GCtab *t = lj_lib_checktab(L, 1);
+ int32_t n, i = (int32_t)lj_tab_len(t) + 1;
+ int nargs = (int)((char *)L->top - (char *)L->base);
+ if (nargs != 2*sizeof(TValue)) {
+ if (nargs != 3*sizeof(TValue))
+ lj_err_caller(L, LJ_ERR_TABINS);
+ /* NOBARRIER: This just moves existing elements around. */
+ for (n = lj_lib_checkint(L, 2); i > n; i--) {
+ /* The set may invalidate the get pointer, so need to do it first! */
+ TValue *dst = lj_tab_setint(L, t, i);
+ cTValue *src = lj_tab_getint(t, i-1);
+ if (src) {
+ copyTV(L, dst, src);
+ } else {
+ setnilV(dst);
+ }
+ }
+ i = n;
+ }
+ {
+ TValue *dst = lj_tab_setint(L, t, i);
+ copyTV(L, dst, L->top-1); /* Set new value. */
+ lj_gc_barriert(L, t, dst);
+ }
+ return 0;
+}
+
+LJLIB_CF(table_remove) LJLIB_REC(.)
+{
+ GCtab *t = lj_lib_checktab(L, 1);
+ int32_t e = (int32_t)lj_tab_len(t);
+ int32_t pos = lj_lib_optint(L, 2, e);
+ if (!(1 <= pos && pos <= e)) /* Nothing to remove? */
+ return 0;
+ lua_rawgeti(L, 1, pos); /* Get previous value. */
+ /* NOBARRIER: This just moves existing elements around. */
+ for (; pos < e; pos++) {
+ cTValue *src = lj_tab_getint(t, pos+1);
+ TValue *dst = lj_tab_setint(L, t, pos);
+ if (src) {
+ copyTV(L, dst, src);
+ } else {
+ setnilV(dst);
+ }
+ }
+ setnilV(lj_tab_setint(L, t, e)); /* Remove (last) value. */
+ return 1; /* Return previous value. */
+}
+
+LJLIB_CF(table_concat)
+{
+ luaL_Buffer b;
+ GCtab *t = lj_lib_checktab(L, 1);
+ GCstr *sep = lj_lib_optstr(L, 2);
+ MSize seplen = sep ? sep->len : 0;
+ int32_t i = lj_lib_optint(L, 3, 1);
+ int32_t e = (L->base+3 < L->top && !tvisnil(L->base+3)) ?
+ lj_lib_checkint(L, 4) : (int32_t)lj_tab_len(t);
+ luaL_buffinit(L, &b);
+ if (i <= e) {
+ for (;;) {
+ cTValue *o;
+ lua_rawgeti(L, 1, i);
+ o = L->top-1;
+ if (!(tvisstr(o) || tvisnumber(o)))
+ lj_err_callerv(L, LJ_ERR_TABCAT, lj_typename(o), i);
+ luaL_addvalue(&b);
+ if (i++ == e) break;
+ if (seplen)
+ luaL_addlstring(&b, strdata(sep), seplen);
+ }
+ }
+ luaL_pushresult(&b);
+ return 1;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static void set2(lua_State *L, int i, int j)
+{
+ lua_rawseti(L, 1, i);
+ lua_rawseti(L, 1, j);
+}
+
+static int sort_comp(lua_State *L, int a, int b)
+{
+ if (!lua_isnil(L, 2)) { /* function? */
+ int res;
+ lua_pushvalue(L, 2);
+ lua_pushvalue(L, a-1); /* -1 to compensate function */
+ lua_pushvalue(L, b-2); /* -2 to compensate function and `a' */
+ lua_call(L, 2, 1);
+ res = lua_toboolean(L, -1);
+ lua_pop(L, 1);
+ return res;
+ } else { /* a < b? */
+ return lua_lessthan(L, a, b);
+ }
+}
+
+static void auxsort(lua_State *L, int l, int u)
+{
+ while (l < u) { /* for tail recursion */
+ int i, j;
+ /* sort elements a[l], a[(l+u)/2] and a[u] */
+ lua_rawgeti(L, 1, l);
+ lua_rawgeti(L, 1, u);
+ if (sort_comp(L, -1, -2)) /* a[u] < a[l]? */
+ set2(L, l, u); /* swap a[l] - a[u] */
+ else
+ lua_pop(L, 2);
+ if (u-l == 1) break; /* only 2 elements */
+ i = (l+u)/2;
+ lua_rawgeti(L, 1, i);
+ lua_rawgeti(L, 1, l);
+ if (sort_comp(L, -2, -1)) { /* a[i]<a[l]? */
+ set2(L, i, l);
+ } else {
+ lua_pop(L, 1); /* remove a[l] */
+ lua_rawgeti(L, 1, u);
+ if (sort_comp(L, -1, -2)) /* a[u]<a[i]? */
+ set2(L, i, u);
+ else
+ lua_pop(L, 2);
+ }
+ if (u-l == 2) break; /* only 3 elements */
+ lua_rawgeti(L, 1, i); /* Pivot */
+ lua_pushvalue(L, -1);
+ lua_rawgeti(L, 1, u-1);
+ set2(L, i, u-1);
+ /* a[l] <= P == a[u-1] <= a[u], only need to sort from l+1 to u-2 */
+ i = l; j = u-1;
+ for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */
+ /* repeat ++i until a[i] >= P */
+ while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) {
+ if (i>=u) lj_err_caller(L, LJ_ERR_TABSORT);
+ lua_pop(L, 1); /* remove a[i] */
+ }
+ /* repeat --j until a[j] <= P */
+ while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) {
+ if (j<=l) lj_err_caller(L, LJ_ERR_TABSORT);
+ lua_pop(L, 1); /* remove a[j] */
+ }
+ if (j<i) {
+ lua_pop(L, 3); /* pop pivot, a[i], a[j] */
+ break;
+ }
+ set2(L, i, j);
+ }
+ lua_rawgeti(L, 1, u-1);
+ lua_rawgeti(L, 1, i);
+ set2(L, u-1, i); /* swap pivot (a[u-1]) with a[i] */
+ /* a[l..i-1] <= a[i] == P <= a[i+1..u] */
+ /* adjust so that smaller half is in [j..i] and larger one in [l..u] */
+ if (i-l < u-i) {
+ j=l; i=i-1; l=i+2;
+ } else {
+ j=i+1; i=u; u=j-2;
+ }
+ auxsort(L, j, i); /* call recursively the smaller one */
+ } /* repeat the routine for the larger one */
+}
+
+LJLIB_CF(table_sort)
+{
+ GCtab *t = lj_lib_checktab(L, 1);
+ int32_t n = (int32_t)lj_tab_len(t);
+ lua_settop(L, 2);
+ if (!tvisnil(L->base+1))
+ lj_lib_checkfunc(L, 2);
+ auxsort(L, 1, n);
+ return 0;
+}
+
+#if LJ_52
+LJLIB_PUSH("n")
+LJLIB_CF(table_pack)
+{
+ TValue *array, *base = L->base;
+ MSize i, n = (uint32_t)(L->top - base);
+ GCtab *t = lj_tab_new(L, n ? n+1 : 0, 1);
+ /* NOBARRIER: The table is new (marked white). */
+ setintV(lj_tab_setstr(L, t, strV(lj_lib_upvalue(L, 1))), (int32_t)n);
+ for (array = tvref(t->array) + 1, i = 0; i < n; i++)
+ copyTV(L, &array[i], &base[i]);
+ settabV(L, base, t);
+ L->top = base+1;
+ lj_gc_check(L);
+ return 1;
+}
+#endif
+
+/* ------------------------------------------------------------------------ */
+
+#include "lj_libdef.h"
+
+LUALIB_API int luaopen_table(lua_State *L)
+{
+ LJ_LIB_REG(L, LUA_TABLIBNAME, table);
+#if LJ_52
+ lua_getglobal(L, "unpack");
+ lua_setfield(L, -2, "unpack");
+#endif
+ return 1;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj.supp b/src/3rdparty/LuaJIT-2.0.5/src/lj.supp
new file mode 100644
index 0000000..217f7c8
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj.supp
@@ -0,0 +1,41 @@
+# Valgrind suppression file for LuaJIT 2.0.
+{
+ Optimized string compare
+ Memcheck:Addr4
+ fun:lj_str_cmp
+}
+{
+ Optimized string compare
+ Memcheck:Addr1
+ fun:lj_str_cmp
+}
+{
+ Optimized string compare
+ Memcheck:Addr4
+ fun:lj_str_new
+}
+{
+ Optimized string compare
+ Memcheck:Addr1
+ fun:lj_str_new
+}
+{
+ Optimized string compare
+ Memcheck:Cond
+ fun:lj_str_new
+}
+{
+ Optimized string compare
+ Memcheck:Addr4
+ fun:str_fastcmp
+}
+{
+ Optimized string compare
+ Memcheck:Addr1
+ fun:str_fastcmp
+}
+{
+ Optimized string compare
+ Memcheck:Cond
+ fun:str_fastcmp
+}
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_alloc.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_alloc.c
new file mode 100644
index 0000000..dc64dca
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_alloc.c
@@ -0,0 +1,1396 @@
+/*
+** Bundled memory allocator.
+**
+** Beware: this is a HEAVILY CUSTOMIZED version of dlmalloc.
+** The original bears the following remark:
+**
+** This is a version (aka dlmalloc) of malloc/free/realloc written by
+** Doug Lea and released to the public domain, as explained at
+** http://creativecommons.org/licenses/publicdomain.
+**
+** * Version pre-2.8.4 Wed Mar 29 19:46:29 2006 (dl at gee)
+**
+** No additional copyright is claimed over the customizations.
+** Please do NOT bother the original author about this version here!
+**
+** If you want to use dlmalloc in another project, you should get
+** the original from: ftp://gee.cs.oswego.edu/pub/misc/
+** For thread-safe derivatives, take a look at:
+** - ptmalloc: http://www.malloc.de/
+** - nedmalloc: http://www.nedprod.com/programs/portable/nedmalloc/
+*/
+
+#define lj_alloc_c
+#define LUA_CORE
+
+/* To get the mremap prototype. Must be defined before any system includes. */
+#if defined(__linux__) && !defined(_GNU_SOURCE)
+#define _GNU_SOURCE
+#endif
+
+#include "lj_def.h"
+#include "lj_arch.h"
+#include "lj_alloc.h"
+
+#ifndef LUAJIT_USE_SYSMALLOC
+
+#define MAX_SIZE_T (~(size_t)0)
+#define MALLOC_ALIGNMENT ((size_t)8U)
+
+#define DEFAULT_GRANULARITY ((size_t)128U * (size_t)1024U)
+#define DEFAULT_TRIM_THRESHOLD ((size_t)2U * (size_t)1024U * (size_t)1024U)
+#define DEFAULT_MMAP_THRESHOLD ((size_t)128U * (size_t)1024U)
+#define MAX_RELEASE_CHECK_RATE 255
+
+/* ------------------- size_t and alignment properties -------------------- */
+
+/* The byte and bit size of a size_t */
+#define SIZE_T_SIZE (sizeof(size_t))
+#define SIZE_T_BITSIZE (sizeof(size_t) << 3)
+
+/* Some constants coerced to size_t */
+/* Annoying but necessary to avoid errors on some platforms */
+#define SIZE_T_ZERO ((size_t)0)
+#define SIZE_T_ONE ((size_t)1)
+#define SIZE_T_TWO ((size_t)2)
+#define TWO_SIZE_T_SIZES (SIZE_T_SIZE<<1)
+#define FOUR_SIZE_T_SIZES (SIZE_T_SIZE<<2)
+#define SIX_SIZE_T_SIZES (FOUR_SIZE_T_SIZES+TWO_SIZE_T_SIZES)
+
+/* The bit mask value corresponding to MALLOC_ALIGNMENT */
+#define CHUNK_ALIGN_MASK (MALLOC_ALIGNMENT - SIZE_T_ONE)
+
+/* the number of bytes to offset an address to align it */
+#define align_offset(A)\
+ ((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :\
+ ((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))
+
+/* -------------------------- MMAP support ------------------------------- */
+
+#define MFAIL ((void *)(MAX_SIZE_T))
+#define CMFAIL ((char *)(MFAIL)) /* defined for convenience */
+
+#define IS_DIRECT_BIT (SIZE_T_ONE)
+
+#if LJ_TARGET_WINDOWS
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#if LJ_64
+
+/* Undocumented, but hey, that's what we all love so much about Windows. */
+typedef long (*PNTAVM)(HANDLE handle, void **addr, ULONG zbits,
+ size_t *size, ULONG alloctype, ULONG prot);
+static PNTAVM ntavm;
+
+/* Number of top bits of the lower 32 bits of an address that must be zero.
+** Apparently 0 gives us full 64 bit addresses and 1 gives us the lower 2GB.
+*/
+#define NTAVM_ZEROBITS 1
+
+static void INIT_MMAP(void)
+{
+ ntavm = (PNTAVM)GetProcAddress(GetModuleHandleA("ntdll.dll"),
+ "NtAllocateVirtualMemory");
+}
+
+/* Win64 32 bit MMAP via NtAllocateVirtualMemory. */
+static LJ_AINLINE void *CALL_MMAP(size_t size)
+{
+ DWORD olderr = GetLastError();
+ void *ptr = NULL;
+ long st = ntavm(INVALID_HANDLE_VALUE, &ptr, NTAVM_ZEROBITS, &size,
+ MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
+ SetLastError(olderr);
+ return st == 0 ? ptr : MFAIL;
+}
+
+/* For direct MMAP, use MEM_TOP_DOWN to minimize interference */
+static LJ_AINLINE void *DIRECT_MMAP(size_t size)
+{
+ DWORD olderr = GetLastError();
+ void *ptr = NULL;
+ long st = ntavm(INVALID_HANDLE_VALUE, &ptr, NTAVM_ZEROBITS, &size,
+ MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN, PAGE_READWRITE);
+ SetLastError(olderr);
+ return st == 0 ? ptr : MFAIL;
+}
+
+#else
+
+#define INIT_MMAP() ((void)0)
+
+/* Win32 MMAP via VirtualAlloc */
+static LJ_AINLINE void *CALL_MMAP(size_t size)
+{
+ DWORD olderr = GetLastError();
+ void *ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
+ SetLastError(olderr);
+ return ptr ? ptr : MFAIL;
+}
+
+/* For direct MMAP, use MEM_TOP_DOWN to minimize interference */
+static LJ_AINLINE void *DIRECT_MMAP(size_t size)
+{
+ DWORD olderr = GetLastError();
+ void *ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN,
+ PAGE_READWRITE);
+ SetLastError(olderr);
+ return ptr ? ptr : MFAIL;
+}
+
+#endif
+
+/* This function supports releasing coalesed segments */
+static LJ_AINLINE int CALL_MUNMAP(void *ptr, size_t size)
+{
+ DWORD olderr = GetLastError();
+ MEMORY_BASIC_INFORMATION minfo;
+ char *cptr = (char *)ptr;
+ while (size) {
+ if (VirtualQuery(cptr, &minfo, sizeof(minfo)) == 0)
+ return -1;
+ if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr ||
+ minfo.State != MEM_COMMIT || minfo.RegionSize > size)
+ return -1;
+ if (VirtualFree(cptr, 0, MEM_RELEASE) == 0)
+ return -1;
+ cptr += minfo.RegionSize;
+ size -= minfo.RegionSize;
+ }
+ SetLastError(olderr);
+ return 0;
+}
+
+#else
+
+#include <errno.h>
+#include <sys/mman.h>
+
+#define MMAP_PROT (PROT_READ|PROT_WRITE)
+#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
+#define MAP_ANONYMOUS MAP_ANON
+#endif
+#define MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS)
+
+#if LJ_64
+/* 64 bit mode needs special support for allocating memory in the lower 2GB. */
+
+#if defined(MAP_32BIT)
+
+#if defined(__sun__)
+#define MMAP_REGION_START ((uintptr_t)0x1000)
+#else
+/* Actually this only gives us max. 1GB in current Linux kernels. */
+#define MMAP_REGION_START ((uintptr_t)0)
+#endif
+
+static LJ_AINLINE void *CALL_MMAP(size_t size)
+{
+ int olderr = errno;
+ void *ptr = mmap((void *)MMAP_REGION_START, size, MMAP_PROT, MAP_32BIT|MMAP_FLAGS, -1, 0);
+ errno = olderr;
+ return ptr;
+}
+
+#elif LJ_TARGET_OSX || LJ_TARGET_PS4 || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__sun__) || LJ_TARGET_CYGWIN
+
+/* OSX and FreeBSD mmap() use a naive first-fit linear search.
+** That's perfect for us. Except that -pagezero_size must be set for OSX,
+** otherwise the lower 4GB are blocked. And the 32GB RLIMIT_DATA needs
+** to be reduced to 250MB on FreeBSD.
+*/
+#if LJ_TARGET_OSX || defined(__DragonFly__)
+#define MMAP_REGION_START ((uintptr_t)0x10000)
+#elif LJ_TARGET_PS4
+#define MMAP_REGION_START ((uintptr_t)0x4000)
+#else
+#define MMAP_REGION_START ((uintptr_t)0x10000000)
+#endif
+#define MMAP_REGION_END ((uintptr_t)0x80000000)
+
+#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4
+#include <sys/resource.h>
+#endif
+
+static LJ_AINLINE void *CALL_MMAP(size_t size)
+{
+ int olderr = errno;
+ /* Hint for next allocation. Doesn't need to be thread-safe. */
+ static uintptr_t alloc_hint = MMAP_REGION_START;
+ int retry = 0;
+#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4
+ static int rlimit_modified = 0;
+ if (LJ_UNLIKELY(rlimit_modified == 0)) {
+ struct rlimit rlim;
+ rlim.rlim_cur = rlim.rlim_max = MMAP_REGION_START;
+ setrlimit(RLIMIT_DATA, &rlim); /* Ignore result. May fail below. */
+ rlimit_modified = 1;
+ }
+#endif
+ for (;;) {
+ void *p = mmap((void *)alloc_hint, size, MMAP_PROT, MMAP_FLAGS, -1, 0);
+ if ((uintptr_t)p >= MMAP_REGION_START &&
+ (uintptr_t)p + size < MMAP_REGION_END) {
+ alloc_hint = (uintptr_t)p + size;
+ errno = olderr;
+ return p;
+ }
+ if (p != CMFAIL) munmap(p, size);
+#if defined(__sun__) || defined(__DragonFly__)
+ alloc_hint += 0x1000000; /* Need near-exhaustive linear scan. */
+ if (alloc_hint + size < MMAP_REGION_END) continue;
+#endif
+ if (retry) break;
+ retry = 1;
+ alloc_hint = MMAP_REGION_START;
+ }
+ errno = olderr;
+ return CMFAIL;
+}
+
+#else
+
+#error "NYI: need an equivalent of MAP_32BIT for this 64 bit OS"
+
+#endif
+
+#else
+
+/* 32 bit mode is easy. */
+static LJ_AINLINE void *CALL_MMAP(size_t size)
+{
+ int olderr = errno;
+ void *ptr = mmap(NULL, size, MMAP_PROT, MMAP_FLAGS, -1, 0);
+ errno = olderr;
+ return ptr;
+}
+
+#endif
+
+#define INIT_MMAP() ((void)0)
+#define DIRECT_MMAP(s) CALL_MMAP(s)
+
+static LJ_AINLINE int CALL_MUNMAP(void *ptr, size_t size)
+{
+ int olderr = errno;
+ int ret = munmap(ptr, size);
+ errno = olderr;
+ return ret;
+}
+
+#if LJ_TARGET_LINUX
+/* Need to define _GNU_SOURCE to get the mremap prototype. */
+static LJ_AINLINE void *CALL_MREMAP_(void *ptr, size_t osz, size_t nsz,
+ int flags)
+{
+ int olderr = errno;
+ ptr = mremap(ptr, osz, nsz, flags);
+ errno = olderr;
+ return ptr;
+}
+
+#define CALL_MREMAP(addr, osz, nsz, mv) CALL_MREMAP_((addr), (osz), (nsz), (mv))
+#define CALL_MREMAP_NOMOVE 0
+#define CALL_MREMAP_MAYMOVE 1
+#if LJ_64
+#define CALL_MREMAP_MV CALL_MREMAP_NOMOVE
+#else
+#define CALL_MREMAP_MV CALL_MREMAP_MAYMOVE
+#endif
+#endif
+
+#endif
+
+#ifndef CALL_MREMAP
+#define CALL_MREMAP(addr, osz, nsz, mv) ((void)osz, MFAIL)
+#endif
+
+/* ----------------------- Chunk representations ------------------------ */
+
+struct malloc_chunk {
+ size_t prev_foot; /* Size of previous chunk (if free). */
+ size_t head; /* Size and inuse bits. */
+ struct malloc_chunk *fd; /* double links -- used only if free. */
+ struct malloc_chunk *bk;
+};
+
+typedef struct malloc_chunk mchunk;
+typedef struct malloc_chunk *mchunkptr;
+typedef struct malloc_chunk *sbinptr; /* The type of bins of chunks */
+typedef size_t bindex_t; /* Described below */
+typedef unsigned int binmap_t; /* Described below */
+typedef unsigned int flag_t; /* The type of various bit flag sets */
+
+/* ------------------- Chunks sizes and alignments ----------------------- */
+
+#define MCHUNK_SIZE (sizeof(mchunk))
+
+#define CHUNK_OVERHEAD (SIZE_T_SIZE)
+
+/* Direct chunks need a second word of overhead ... */
+#define DIRECT_CHUNK_OVERHEAD (TWO_SIZE_T_SIZES)
+/* ... and additional padding for fake next-chunk at foot */
+#define DIRECT_FOOT_PAD (FOUR_SIZE_T_SIZES)
+
+/* The smallest size we can malloc is an aligned minimal chunk */
+#define MIN_CHUNK_SIZE\
+ ((MCHUNK_SIZE + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK)
+
+/* conversion from malloc headers to user pointers, and back */
+#define chunk2mem(p) ((void *)((char *)(p) + TWO_SIZE_T_SIZES))
+#define mem2chunk(mem) ((mchunkptr)((char *)(mem) - TWO_SIZE_T_SIZES))
+/* chunk associated with aligned address A */
+#define align_as_chunk(A) (mchunkptr)((A) + align_offset(chunk2mem(A)))
+
+/* Bounds on request (not chunk) sizes. */
+#define MAX_REQUEST ((~MIN_CHUNK_SIZE+1) << 2)
+#define MIN_REQUEST (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE)
+
+/* pad request bytes into a usable size */
+#define pad_request(req) \
+ (((req) + CHUNK_OVERHEAD + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK)
+
+/* pad request, checking for minimum (but not maximum) */
+#define request2size(req) \
+ (((req) < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(req))
+
+/* ------------------ Operations on head and foot fields ----------------- */
+
+#define PINUSE_BIT (SIZE_T_ONE)
+#define CINUSE_BIT (SIZE_T_TWO)
+#define INUSE_BITS (PINUSE_BIT|CINUSE_BIT)
+
+/* Head value for fenceposts */
+#define FENCEPOST_HEAD (INUSE_BITS|SIZE_T_SIZE)
+
+/* extraction of fields from head words */
+#define cinuse(p) ((p)->head & CINUSE_BIT)
+#define pinuse(p) ((p)->head & PINUSE_BIT)
+#define chunksize(p) ((p)->head & ~(INUSE_BITS))
+
+#define clear_pinuse(p) ((p)->head &= ~PINUSE_BIT)
+#define clear_cinuse(p) ((p)->head &= ~CINUSE_BIT)
+
+/* Treat space at ptr +/- offset as a chunk */
+#define chunk_plus_offset(p, s) ((mchunkptr)(((char *)(p)) + (s)))
+#define chunk_minus_offset(p, s) ((mchunkptr)(((char *)(p)) - (s)))
+
+/* Ptr to next or previous physical malloc_chunk. */
+#define next_chunk(p) ((mchunkptr)(((char *)(p)) + ((p)->head & ~INUSE_BITS)))
+#define prev_chunk(p) ((mchunkptr)(((char *)(p)) - ((p)->prev_foot) ))
+
+/* extract next chunk's pinuse bit */
+#define next_pinuse(p) ((next_chunk(p)->head) & PINUSE_BIT)
+
+/* Get/set size at footer */
+#define get_foot(p, s) (((mchunkptr)((char *)(p) + (s)))->prev_foot)
+#define set_foot(p, s) (((mchunkptr)((char *)(p) + (s)))->prev_foot = (s))
+
+/* Set size, pinuse bit, and foot */
+#define set_size_and_pinuse_of_free_chunk(p, s)\
+ ((p)->head = (s|PINUSE_BIT), set_foot(p, s))
+
+/* Set size, pinuse bit, foot, and clear next pinuse */
+#define set_free_with_pinuse(p, s, n)\
+ (clear_pinuse(n), set_size_and_pinuse_of_free_chunk(p, s))
+
+#define is_direct(p)\
+ (!((p)->head & PINUSE_BIT) && ((p)->prev_foot & IS_DIRECT_BIT))
+
+/* Get the internal overhead associated with chunk p */
+#define overhead_for(p)\
+ (is_direct(p)? DIRECT_CHUNK_OVERHEAD : CHUNK_OVERHEAD)
+
+/* ---------------------- Overlaid data structures ----------------------- */
+
+struct malloc_tree_chunk {
+ /* The first four fields must be compatible with malloc_chunk */
+ size_t prev_foot;
+ size_t head;
+ struct malloc_tree_chunk *fd;
+ struct malloc_tree_chunk *bk;
+
+ struct malloc_tree_chunk *child[2];
+ struct malloc_tree_chunk *parent;
+ bindex_t index;
+};
+
+typedef struct malloc_tree_chunk tchunk;
+typedef struct malloc_tree_chunk *tchunkptr;
+typedef struct malloc_tree_chunk *tbinptr; /* The type of bins of trees */
+
+/* A little helper macro for trees */
+#define leftmost_child(t) ((t)->child[0] != 0? (t)->child[0] : (t)->child[1])
+
+/* ----------------------------- Segments -------------------------------- */
+
+struct malloc_segment {
+ char *base; /* base address */
+ size_t size; /* allocated size */
+ struct malloc_segment *next; /* ptr to next segment */
+};
+
+typedef struct malloc_segment msegment;
+typedef struct malloc_segment *msegmentptr;
+
+/* ---------------------------- malloc_state ----------------------------- */
+
+/* Bin types, widths and sizes */
+#define NSMALLBINS (32U)
+#define NTREEBINS (32U)
+#define SMALLBIN_SHIFT (3U)
+#define SMALLBIN_WIDTH (SIZE_T_ONE << SMALLBIN_SHIFT)
+#define TREEBIN_SHIFT (8U)
+#define MIN_LARGE_SIZE (SIZE_T_ONE << TREEBIN_SHIFT)
+#define MAX_SMALL_SIZE (MIN_LARGE_SIZE - SIZE_T_ONE)
+#define MAX_SMALL_REQUEST (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD)
+
+struct malloc_state {
+ binmap_t smallmap;
+ binmap_t treemap;
+ size_t dvsize;
+ size_t topsize;
+ mchunkptr dv;
+ mchunkptr top;
+ size_t trim_check;
+ size_t release_checks;
+ mchunkptr smallbins[(NSMALLBINS+1)*2];
+ tbinptr treebins[NTREEBINS];
+ msegment seg;
+};
+
+typedef struct malloc_state *mstate;
+
+#define is_initialized(M) ((M)->top != 0)
+
+/* -------------------------- system alloc setup ------------------------- */
+
+/* page-align a size */
+#define page_align(S)\
+ (((S) + (LJ_PAGESIZE - SIZE_T_ONE)) & ~(LJ_PAGESIZE - SIZE_T_ONE))
+
+/* granularity-align a size */
+#define granularity_align(S)\
+ (((S) + (DEFAULT_GRANULARITY - SIZE_T_ONE))\
+ & ~(DEFAULT_GRANULARITY - SIZE_T_ONE))
+
+#if LJ_TARGET_WINDOWS
+#define mmap_align(S) granularity_align(S)
+#else
+#define mmap_align(S) page_align(S)
+#endif
+
+/* True if segment S holds address A */
+#define segment_holds(S, A)\
+ ((char *)(A) >= S->base && (char *)(A) < S->base + S->size)
+
+/* Return segment holding given address */
+static msegmentptr segment_holding(mstate m, char *addr)
+{
+ msegmentptr sp = &m->seg;
+ for (;;) {
+ if (addr >= sp->base && addr < sp->base + sp->size)
+ return sp;
+ if ((sp = sp->next) == 0)
+ return 0;
+ }
+}
+
+/* Return true if segment contains a segment link */
+static int has_segment_link(mstate m, msegmentptr ss)
+{
+ msegmentptr sp = &m->seg;
+ for (;;) {
+ if ((char *)sp >= ss->base && (char *)sp < ss->base + ss->size)
+ return 1;
+ if ((sp = sp->next) == 0)
+ return 0;
+ }
+}
+
+/*
+ TOP_FOOT_SIZE is padding at the end of a segment, including space
+ that may be needed to place segment records and fenceposts when new
+ noncontiguous segments are added.
+*/
+#define TOP_FOOT_SIZE\
+ (align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
+
+/* ---------------------------- Indexing Bins ---------------------------- */
+
+#define is_small(s) (((s) >> SMALLBIN_SHIFT) < NSMALLBINS)
+#define small_index(s) ((s) >> SMALLBIN_SHIFT)
+#define small_index2size(i) ((i) << SMALLBIN_SHIFT)
+#define MIN_SMALL_INDEX (small_index(MIN_CHUNK_SIZE))
+
+/* addressing by index. See above about smallbin repositioning */
+#define smallbin_at(M, i) ((sbinptr)((char *)&((M)->smallbins[(i)<<1])))
+#define treebin_at(M,i) (&((M)->treebins[i]))
+
+/* assign tree index for size S to variable I */
+#define compute_tree_index(S, I)\
+{\
+ unsigned int X = (unsigned int)(S >> TREEBIN_SHIFT);\
+ if (X == 0) {\
+ I = 0;\
+ } else if (X > 0xFFFF) {\
+ I = NTREEBINS-1;\
+ } else {\
+ unsigned int K = lj_fls(X);\
+ I = (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\
+ }\
+}
+
+/* Bit representing maximum resolved size in a treebin at i */
+#define bit_for_tree_index(i) \
+ (i == NTREEBINS-1)? (SIZE_T_BITSIZE-1) : (((i) >> 1) + TREEBIN_SHIFT - 2)
+
+/* Shift placing maximum resolved bit in a treebin at i as sign bit */
+#define leftshift_for_tree_index(i) \
+ ((i == NTREEBINS-1)? 0 : \
+ ((SIZE_T_BITSIZE-SIZE_T_ONE) - (((i) >> 1) + TREEBIN_SHIFT - 2)))
+
+/* The size of the smallest chunk held in bin with index i */
+#define minsize_for_tree_index(i) \
+ ((SIZE_T_ONE << (((i) >> 1) + TREEBIN_SHIFT)) | \
+ (((size_t)((i) & SIZE_T_ONE)) << (((i) >> 1) + TREEBIN_SHIFT - 1)))
+
+/* ------------------------ Operations on bin maps ----------------------- */
+
+/* bit corresponding to given index */
+#define idx2bit(i) ((binmap_t)(1) << (i))
+
+/* Mark/Clear bits with given index */
+#define mark_smallmap(M,i) ((M)->smallmap |= idx2bit(i))
+#define clear_smallmap(M,i) ((M)->smallmap &= ~idx2bit(i))
+#define smallmap_is_marked(M,i) ((M)->smallmap & idx2bit(i))
+
+#define mark_treemap(M,i) ((M)->treemap |= idx2bit(i))
+#define clear_treemap(M,i) ((M)->treemap &= ~idx2bit(i))
+#define treemap_is_marked(M,i) ((M)->treemap & idx2bit(i))
+
+/* mask with all bits to left of least bit of x on */
+#define left_bits(x) ((x<<1) | (~(x<<1)+1))
+
+/* Set cinuse bit and pinuse bit of next chunk */
+#define set_inuse(M,p,s)\
+ ((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\
+ ((mchunkptr)(((char *)(p)) + (s)))->head |= PINUSE_BIT)
+
+/* Set cinuse and pinuse of this chunk and pinuse of next chunk */
+#define set_inuse_and_pinuse(M,p,s)\
+ ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\
+ ((mchunkptr)(((char *)(p)) + (s)))->head |= PINUSE_BIT)
+
+/* Set size, cinuse and pinuse bit of this chunk */
+#define set_size_and_pinuse_of_inuse_chunk(M, p, s)\
+ ((p)->head = (s|PINUSE_BIT|CINUSE_BIT))
+
+/* ----------------------- Operations on smallbins ----------------------- */
+
+/* Link a free chunk into a smallbin */
+#define insert_small_chunk(M, P, S) {\
+ bindex_t I = small_index(S);\
+ mchunkptr B = smallbin_at(M, I);\
+ mchunkptr F = B;\
+ if (!smallmap_is_marked(M, I))\
+ mark_smallmap(M, I);\
+ else\
+ F = B->fd;\
+ B->fd = P;\
+ F->bk = P;\
+ P->fd = F;\
+ P->bk = B;\
+}
+
+/* Unlink a chunk from a smallbin */
+#define unlink_small_chunk(M, P, S) {\
+ mchunkptr F = P->fd;\
+ mchunkptr B = P->bk;\
+ bindex_t I = small_index(S);\
+ if (F == B) {\
+ clear_smallmap(M, I);\
+ } else {\
+ F->bk = B;\
+ B->fd = F;\
+ }\
+}
+
+/* Unlink the first chunk from a smallbin */
+#define unlink_first_small_chunk(M, B, P, I) {\
+ mchunkptr F = P->fd;\
+ if (B == F) {\
+ clear_smallmap(M, I);\
+ } else {\
+ B->fd = F;\
+ F->bk = B;\
+ }\
+}
+
+/* Replace dv node, binning the old one */
+/* Used only when dvsize known to be small */
+#define replace_dv(M, P, S) {\
+ size_t DVS = M->dvsize;\
+ if (DVS != 0) {\
+ mchunkptr DV = M->dv;\
+ insert_small_chunk(M, DV, DVS);\
+ }\
+ M->dvsize = S;\
+ M->dv = P;\
+}
+
+/* ------------------------- Operations on trees ------------------------- */
+
+/* Insert chunk into tree */
+#define insert_large_chunk(M, X, S) {\
+ tbinptr *H;\
+ bindex_t I;\
+ compute_tree_index(S, I);\
+ H = treebin_at(M, I);\
+ X->index = I;\
+ X->child[0] = X->child[1] = 0;\
+ if (!treemap_is_marked(M, I)) {\
+ mark_treemap(M, I);\
+ *H = X;\
+ X->parent = (tchunkptr)H;\
+ X->fd = X->bk = X;\
+ } else {\
+ tchunkptr T = *H;\
+ size_t K = S << leftshift_for_tree_index(I);\
+ for (;;) {\
+ if (chunksize(T) != S) {\
+ tchunkptr *C = &(T->child[(K >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]);\
+ K <<= 1;\
+ if (*C != 0) {\
+ T = *C;\
+ } else {\
+ *C = X;\
+ X->parent = T;\
+ X->fd = X->bk = X;\
+ break;\
+ }\
+ } else {\
+ tchunkptr F = T->fd;\
+ T->fd = F->bk = X;\
+ X->fd = F;\
+ X->bk = T;\
+ X->parent = 0;\
+ break;\
+ }\
+ }\
+ }\
+}
+
+#define unlink_large_chunk(M, X) {\
+ tchunkptr XP = X->parent;\
+ tchunkptr R;\
+ if (X->bk != X) {\
+ tchunkptr F = X->fd;\
+ R = X->bk;\
+ F->bk = R;\
+ R->fd = F;\
+ } else {\
+ tchunkptr *RP;\
+ if (((R = *(RP = &(X->child[1]))) != 0) ||\
+ ((R = *(RP = &(X->child[0]))) != 0)) {\
+ tchunkptr *CP;\
+ while ((*(CP = &(R->child[1])) != 0) ||\
+ (*(CP = &(R->child[0])) != 0)) {\
+ R = *(RP = CP);\
+ }\
+ *RP = 0;\
+ }\
+ }\
+ if (XP != 0) {\
+ tbinptr *H = treebin_at(M, X->index);\
+ if (X == *H) {\
+ if ((*H = R) == 0) \
+ clear_treemap(M, X->index);\
+ } else {\
+ if (XP->child[0] == X) \
+ XP->child[0] = R;\
+ else \
+ XP->child[1] = R;\
+ }\
+ if (R != 0) {\
+ tchunkptr C0, C1;\
+ R->parent = XP;\
+ if ((C0 = X->child[0]) != 0) {\
+ R->child[0] = C0;\
+ C0->parent = R;\
+ }\
+ if ((C1 = X->child[1]) != 0) {\
+ R->child[1] = C1;\
+ C1->parent = R;\
+ }\
+ }\
+ }\
+}
+
+/* Relays to large vs small bin operations */
+
+#define insert_chunk(M, P, S)\
+ if (is_small(S)) { insert_small_chunk(M, P, S)\
+ } else { tchunkptr TP = (tchunkptr)(P); insert_large_chunk(M, TP, S); }
+
+#define unlink_chunk(M, P, S)\
+ if (is_small(S)) { unlink_small_chunk(M, P, S)\
+ } else { tchunkptr TP = (tchunkptr)(P); unlink_large_chunk(M, TP); }
+
+/* ----------------------- Direct-mmapping chunks ----------------------- */
+
+static void *direct_alloc(size_t nb)
+{
+ size_t mmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
+ if (LJ_LIKELY(mmsize > nb)) { /* Check for wrap around 0 */
+ char *mm = (char *)(DIRECT_MMAP(mmsize));
+ if (mm != CMFAIL) {
+ size_t offset = align_offset(chunk2mem(mm));
+ size_t psize = mmsize - offset - DIRECT_FOOT_PAD;
+ mchunkptr p = (mchunkptr)(mm + offset);
+ p->prev_foot = offset | IS_DIRECT_BIT;
+ p->head = psize|CINUSE_BIT;
+ chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD;
+ chunk_plus_offset(p, psize+SIZE_T_SIZE)->head = 0;
+ return chunk2mem(p);
+ }
+ }
+ return NULL;
+}
+
+static mchunkptr direct_resize(mchunkptr oldp, size_t nb)
+{
+ size_t oldsize = chunksize(oldp);
+ if (is_small(nb)) /* Can't shrink direct regions below small size */
+ return NULL;
+ /* Keep old chunk if big enough but not too big */
+ if (oldsize >= nb + SIZE_T_SIZE &&
+ (oldsize - nb) <= (DEFAULT_GRANULARITY >> 1)) {
+ return oldp;
+ } else {
+ size_t offset = oldp->prev_foot & ~IS_DIRECT_BIT;
+ size_t oldmmsize = oldsize + offset + DIRECT_FOOT_PAD;
+ size_t newmmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
+ char *cp = (char *)CALL_MREMAP((char *)oldp - offset,
+ oldmmsize, newmmsize, CALL_MREMAP_MV);
+ if (cp != CMFAIL) {
+ mchunkptr newp = (mchunkptr)(cp + offset);
+ size_t psize = newmmsize - offset - DIRECT_FOOT_PAD;
+ newp->head = psize|CINUSE_BIT;
+ chunk_plus_offset(newp, psize)->head = FENCEPOST_HEAD;
+ chunk_plus_offset(newp, psize+SIZE_T_SIZE)->head = 0;
+ return newp;
+ }
+ }
+ return NULL;
+}
+
+/* -------------------------- mspace management -------------------------- */
+
+/* Initialize top chunk and its size */
+static void init_top(mstate m, mchunkptr p, size_t psize)
+{
+ /* Ensure alignment */
+ size_t offset = align_offset(chunk2mem(p));
+ p = (mchunkptr)((char *)p + offset);
+ psize -= offset;
+
+ m->top = p;
+ m->topsize = psize;
+ p->head = psize | PINUSE_BIT;
+ /* set size of fake trailing chunk holding overhead space only once */
+ chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE;
+ m->trim_check = DEFAULT_TRIM_THRESHOLD; /* reset on each update */
+}
+
+/* Initialize bins for a new mstate that is otherwise zeroed out */
+static void init_bins(mstate m)
+{
+ /* Establish circular links for smallbins */
+ bindex_t i;
+ for (i = 0; i < NSMALLBINS; i++) {
+ sbinptr bin = smallbin_at(m,i);
+ bin->fd = bin->bk = bin;
+ }
+}
+
+/* Allocate chunk and prepend remainder with chunk in successor base. */
+static void *prepend_alloc(mstate m, char *newbase, char *oldbase, size_t nb)
+{
+ mchunkptr p = align_as_chunk(newbase);
+ mchunkptr oldfirst = align_as_chunk(oldbase);
+ size_t psize = (size_t)((char *)oldfirst - (char *)p);
+ mchunkptr q = chunk_plus_offset(p, nb);
+ size_t qsize = psize - nb;
+ set_size_and_pinuse_of_inuse_chunk(m, p, nb);
+
+ /* consolidate remainder with first chunk of old base */
+ if (oldfirst == m->top) {
+ size_t tsize = m->topsize += qsize;
+ m->top = q;
+ q->head = tsize | PINUSE_BIT;
+ } else if (oldfirst == m->dv) {
+ size_t dsize = m->dvsize += qsize;
+ m->dv = q;
+ set_size_and_pinuse_of_free_chunk(q, dsize);
+ } else {
+ if (!cinuse(oldfirst)) {
+ size_t nsize = chunksize(oldfirst);
+ unlink_chunk(m, oldfirst, nsize);
+ oldfirst = chunk_plus_offset(oldfirst, nsize);
+ qsize += nsize;
+ }
+ set_free_with_pinuse(q, qsize, oldfirst);
+ insert_chunk(m, q, qsize);
+ }
+
+ return chunk2mem(p);
+}
+
+/* Add a segment to hold a new noncontiguous region */
+static void add_segment(mstate m, char *tbase, size_t tsize)
+{
+ /* Determine locations and sizes of segment, fenceposts, old top */
+ char *old_top = (char *)m->top;
+ msegmentptr oldsp = segment_holding(m, old_top);
+ char *old_end = oldsp->base + oldsp->size;
+ size_t ssize = pad_request(sizeof(struct malloc_segment));
+ char *rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
+ size_t offset = align_offset(chunk2mem(rawsp));
+ char *asp = rawsp + offset;
+ char *csp = (asp < (old_top + MIN_CHUNK_SIZE))? old_top : asp;
+ mchunkptr sp = (mchunkptr)csp;
+ msegmentptr ss = (msegmentptr)(chunk2mem(sp));
+ mchunkptr tnext = chunk_plus_offset(sp, ssize);
+ mchunkptr p = tnext;
+
+ /* reset top to new space */
+ init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE);
+
+ /* Set up segment record */
+ set_size_and_pinuse_of_inuse_chunk(m, sp, ssize);
+ *ss = m->seg; /* Push current record */
+ m->seg.base = tbase;
+ m->seg.size = tsize;
+ m->seg.next = ss;
+
+ /* Insert trailing fenceposts */
+ for (;;) {
+ mchunkptr nextp = chunk_plus_offset(p, SIZE_T_SIZE);
+ p->head = FENCEPOST_HEAD;
+ if ((char *)(&(nextp->head)) < old_end)
+ p = nextp;
+ else
+ break;
+ }
+
+ /* Insert the rest of old top into a bin as an ordinary free chunk */
+ if (csp != old_top) {
+ mchunkptr q = (mchunkptr)old_top;
+ size_t psize = (size_t)(csp - old_top);
+ mchunkptr tn = chunk_plus_offset(q, psize);
+ set_free_with_pinuse(q, psize, tn);
+ insert_chunk(m, q, psize);
+ }
+}
+
+/* -------------------------- System allocation -------------------------- */
+
+static void *alloc_sys(mstate m, size_t nb)
+{
+ char *tbase = CMFAIL;
+ size_t tsize = 0;
+
+ /* Directly map large chunks */
+ if (LJ_UNLIKELY(nb >= DEFAULT_MMAP_THRESHOLD)) {
+ void *mem = direct_alloc(nb);
+ if (mem != 0)
+ return mem;
+ }
+
+ {
+ size_t req = nb + TOP_FOOT_SIZE + SIZE_T_ONE;
+ size_t rsize = granularity_align(req);
+ if (LJ_LIKELY(rsize > nb)) { /* Fail if wraps around zero */
+ char *mp = (char *)(CALL_MMAP(rsize));
+ if (mp != CMFAIL) {
+ tbase = mp;
+ tsize = rsize;
+ }
+ }
+ }
+
+ if (tbase != CMFAIL) {
+ msegmentptr sp = &m->seg;
+ /* Try to merge with an existing segment */
+ while (sp != 0 && tbase != sp->base + sp->size)
+ sp = sp->next;
+ if (sp != 0 && segment_holds(sp, m->top)) { /* append */
+ sp->size += tsize;
+ init_top(m, m->top, m->topsize + tsize);
+ } else {
+ sp = &m->seg;
+ while (sp != 0 && sp->base != tbase + tsize)
+ sp = sp->next;
+ if (sp != 0) {
+ char *oldbase = sp->base;
+ sp->base = tbase;
+ sp->size += tsize;
+ return prepend_alloc(m, tbase, oldbase, nb);
+ } else {
+ add_segment(m, tbase, tsize);
+ }
+ }
+
+ if (nb < m->topsize) { /* Allocate from new or extended top space */
+ size_t rsize = m->topsize -= nb;
+ mchunkptr p = m->top;
+ mchunkptr r = m->top = chunk_plus_offset(p, nb);
+ r->head = rsize | PINUSE_BIT;
+ set_size_and_pinuse_of_inuse_chunk(m, p, nb);
+ return chunk2mem(p);
+ }
+ }
+
+ return NULL;
+}
+
+/* ----------------------- system deallocation -------------------------- */
+
+/* Unmap and unlink any mmapped segments that don't contain used chunks */
+static size_t release_unused_segments(mstate m)
+{
+ size_t released = 0;
+ size_t nsegs = 0;
+ msegmentptr pred = &m->seg;
+ msegmentptr sp = pred->next;
+ while (sp != 0) {
+ char *base = sp->base;
+ size_t size = sp->size;
+ msegmentptr next = sp->next;
+ nsegs++;
+ {
+ mchunkptr p = align_as_chunk(base);
+ size_t psize = chunksize(p);
+ /* Can unmap if first chunk holds entire segment and not pinned */
+ if (!cinuse(p) && (char *)p + psize >= base + size - TOP_FOOT_SIZE) {
+ tchunkptr tp = (tchunkptr)p;
+ if (p == m->dv) {
+ m->dv = 0;
+ m->dvsize = 0;
+ } else {
+ unlink_large_chunk(m, tp);
+ }
+ if (CALL_MUNMAP(base, size) == 0) {
+ released += size;
+ /* unlink obsoleted record */
+ sp = pred;
+ sp->next = next;
+ } else { /* back out if cannot unmap */
+ insert_large_chunk(m, tp, psize);
+ }
+ }
+ }
+ pred = sp;
+ sp = next;
+ }
+ /* Reset check counter */
+ m->release_checks = nsegs > MAX_RELEASE_CHECK_RATE ?
+ nsegs : MAX_RELEASE_CHECK_RATE;
+ return released;
+}
+
+static int alloc_trim(mstate m, size_t pad)
+{
+ size_t released = 0;
+ if (pad < MAX_REQUEST && is_initialized(m)) {
+ pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead */
+
+ if (m->topsize > pad) {
+ /* Shrink top space in granularity-size units, keeping at least one */
+ size_t unit = DEFAULT_GRANULARITY;
+ size_t extra = ((m->topsize - pad + (unit - SIZE_T_ONE)) / unit -
+ SIZE_T_ONE) * unit;
+ msegmentptr sp = segment_holding(m, (char *)m->top);
+
+ if (sp->size >= extra &&
+ !has_segment_link(m, sp)) { /* can't shrink if pinned */
+ size_t newsize = sp->size - extra;
+ /* Prefer mremap, fall back to munmap */
+ if ((CALL_MREMAP(sp->base, sp->size, newsize, CALL_MREMAP_NOMOVE) != MFAIL) ||
+ (CALL_MUNMAP(sp->base + newsize, extra) == 0)) {
+ released = extra;
+ }
+ }
+
+ if (released != 0) {
+ sp->size -= released;
+ init_top(m, m->top, m->topsize - released);
+ }
+ }
+
+ /* Unmap any unused mmapped segments */
+ released += release_unused_segments(m);
+
+ /* On failure, disable autotrim to avoid repeated failed future calls */
+ if (released == 0 && m->topsize > m->trim_check)
+ m->trim_check = MAX_SIZE_T;
+ }
+
+ return (released != 0)? 1 : 0;
+}
+
+/* ---------------------------- malloc support --------------------------- */
+
+/* allocate a large request from the best fitting chunk in a treebin */
+static void *tmalloc_large(mstate m, size_t nb)
+{
+ tchunkptr v = 0;
+ size_t rsize = ~nb+1; /* Unsigned negation */
+ tchunkptr t;
+ bindex_t idx;
+ compute_tree_index(nb, idx);
+
+ if ((t = *treebin_at(m, idx)) != 0) {
+ /* Traverse tree for this bin looking for node with size == nb */
+ size_t sizebits = nb << leftshift_for_tree_index(idx);
+ tchunkptr rst = 0; /* The deepest untaken right subtree */
+ for (;;) {
+ tchunkptr rt;
+ size_t trem = chunksize(t) - nb;
+ if (trem < rsize) {
+ v = t;
+ if ((rsize = trem) == 0)
+ break;
+ }
+ rt = t->child[1];
+ t = t->child[(sizebits >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1];
+ if (rt != 0 && rt != t)
+ rst = rt;
+ if (t == 0) {
+ t = rst; /* set t to least subtree holding sizes > nb */
+ break;
+ }
+ sizebits <<= 1;
+ }
+ }
+
+ if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */
+ binmap_t leftbits = left_bits(idx2bit(idx)) & m->treemap;
+ if (leftbits != 0)
+ t = *treebin_at(m, lj_ffs(leftbits));
+ }
+
+ while (t != 0) { /* find smallest of tree or subtree */
+ size_t trem = chunksize(t) - nb;
+ if (trem < rsize) {
+ rsize = trem;
+ v = t;
+ }
+ t = leftmost_child(t);
+ }
+
+ /* If dv is a better fit, return NULL so malloc will use it */
+ if (v != 0 && rsize < (size_t)(m->dvsize - nb)) {
+ mchunkptr r = chunk_plus_offset(v, nb);
+ unlink_large_chunk(m, v);
+ if (rsize < MIN_CHUNK_SIZE) {
+ set_inuse_and_pinuse(m, v, (rsize + nb));
+ } else {
+ set_size_and_pinuse_of_inuse_chunk(m, v, nb);
+ set_size_and_pinuse_of_free_chunk(r, rsize);
+ insert_chunk(m, r, rsize);
+ }
+ return chunk2mem(v);
+ }
+ return NULL;
+}
+
+/* allocate a small request from the best fitting chunk in a treebin */
+static void *tmalloc_small(mstate m, size_t nb)
+{
+ tchunkptr t, v;
+ mchunkptr r;
+ size_t rsize;
+ bindex_t i = lj_ffs(m->treemap);
+
+ v = t = *treebin_at(m, i);
+ rsize = chunksize(t) - nb;
+
+ while ((t = leftmost_child(t)) != 0) {
+ size_t trem = chunksize(t) - nb;
+ if (trem < rsize) {
+ rsize = trem;
+ v = t;
+ }
+ }
+
+ r = chunk_plus_offset(v, nb);
+ unlink_large_chunk(m, v);
+ if (rsize < MIN_CHUNK_SIZE) {
+ set_inuse_and_pinuse(m, v, (rsize + nb));
+ } else {
+ set_size_and_pinuse_of_inuse_chunk(m, v, nb);
+ set_size_and_pinuse_of_free_chunk(r, rsize);
+ replace_dv(m, r, rsize);
+ }
+ return chunk2mem(v);
+}
+
+/* ----------------------------------------------------------------------- */
+
+void *lj_alloc_create(void)
+{
+ size_t tsize = DEFAULT_GRANULARITY;
+ char *tbase;
+ INIT_MMAP();
+ tbase = (char *)(CALL_MMAP(tsize));
+ if (tbase != CMFAIL) {
+ size_t msize = pad_request(sizeof(struct malloc_state));
+ mchunkptr mn;
+ mchunkptr msp = align_as_chunk(tbase);
+ mstate m = (mstate)(chunk2mem(msp));
+ memset(m, 0, msize);
+ msp->head = (msize|PINUSE_BIT|CINUSE_BIT);
+ m->seg.base = tbase;
+ m->seg.size = tsize;
+ m->release_checks = MAX_RELEASE_CHECK_RATE;
+ init_bins(m);
+ mn = next_chunk(mem2chunk(m));
+ init_top(m, mn, (size_t)((tbase + tsize) - (char *)mn) - TOP_FOOT_SIZE);
+ return m;
+ }
+ return NULL;
+}
+
+void lj_alloc_destroy(void *msp)
+{
+ mstate ms = (mstate)msp;
+ msegmentptr sp = &ms->seg;
+ while (sp != 0) {
+ char *base = sp->base;
+ size_t size = sp->size;
+ sp = sp->next;
+ CALL_MUNMAP(base, size);
+ }
+}
+
+static LJ_NOINLINE void *lj_alloc_malloc(void *msp, size_t nsize)
+{
+ mstate ms = (mstate)msp;
+ void *mem;
+ size_t nb;
+ if (nsize <= MAX_SMALL_REQUEST) {
+ bindex_t idx;
+ binmap_t smallbits;
+ nb = (nsize < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(nsize);
+ idx = small_index(nb);
+ smallbits = ms->smallmap >> idx;
+
+ if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */
+ mchunkptr b, p;
+ idx += ~smallbits & 1; /* Uses next bin if idx empty */
+ b = smallbin_at(ms, idx);
+ p = b->fd;
+ unlink_first_small_chunk(ms, b, p, idx);
+ set_inuse_and_pinuse(ms, p, small_index2size(idx));
+ mem = chunk2mem(p);
+ return mem;
+ } else if (nb > ms->dvsize) {
+ if (smallbits != 0) { /* Use chunk in next nonempty smallbin */
+ mchunkptr b, p, r;
+ size_t rsize;
+ binmap_t leftbits = (smallbits << idx) & left_bits(idx2bit(idx));
+ bindex_t i = lj_ffs(leftbits);
+ b = smallbin_at(ms, i);
+ p = b->fd;
+ unlink_first_small_chunk(ms, b, p, i);
+ rsize = small_index2size(i) - nb;
+ /* Fit here cannot be remainderless if 4byte sizes */
+ if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) {
+ set_inuse_and_pinuse(ms, p, small_index2size(i));
+ } else {
+ set_size_and_pinuse_of_inuse_chunk(ms, p, nb);
+ r = chunk_plus_offset(p, nb);
+ set_size_and_pinuse_of_free_chunk(r, rsize);
+ replace_dv(ms, r, rsize);
+ }
+ mem = chunk2mem(p);
+ return mem;
+ } else if (ms->treemap != 0 && (mem = tmalloc_small(ms, nb)) != 0) {
+ return mem;
+ }
+ }
+ } else if (nsize >= MAX_REQUEST) {
+ nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */
+ } else {
+ nb = pad_request(nsize);
+ if (ms->treemap != 0 && (mem = tmalloc_large(ms, nb)) != 0) {
+ return mem;
+ }
+ }
+
+ if (nb <= ms->dvsize) {
+ size_t rsize = ms->dvsize - nb;
+ mchunkptr p = ms->dv;
+ if (rsize >= MIN_CHUNK_SIZE) { /* split dv */
+ mchunkptr r = ms->dv = chunk_plus_offset(p, nb);
+ ms->dvsize = rsize;
+ set_size_and_pinuse_of_free_chunk(r, rsize);
+ set_size_and_pinuse_of_inuse_chunk(ms, p, nb);
+ } else { /* exhaust dv */
+ size_t dvs = ms->dvsize;
+ ms->dvsize = 0;
+ ms->dv = 0;
+ set_inuse_and_pinuse(ms, p, dvs);
+ }
+ mem = chunk2mem(p);
+ return mem;
+ } else if (nb < ms->topsize) { /* Split top */
+ size_t rsize = ms->topsize -= nb;
+ mchunkptr p = ms->top;
+ mchunkptr r = ms->top = chunk_plus_offset(p, nb);
+ r->head = rsize | PINUSE_BIT;
+ set_size_and_pinuse_of_inuse_chunk(ms, p, nb);
+ mem = chunk2mem(p);
+ return mem;
+ }
+ return alloc_sys(ms, nb);
+}
+
+static LJ_NOINLINE void *lj_alloc_free(void *msp, void *ptr)
+{
+ if (ptr != 0) {
+ mchunkptr p = mem2chunk(ptr);
+ mstate fm = (mstate)msp;
+ size_t psize = chunksize(p);
+ mchunkptr next = chunk_plus_offset(p, psize);
+ if (!pinuse(p)) {
+ size_t prevsize = p->prev_foot;
+ if ((prevsize & IS_DIRECT_BIT) != 0) {
+ prevsize &= ~IS_DIRECT_BIT;
+ psize += prevsize + DIRECT_FOOT_PAD;
+ CALL_MUNMAP((char *)p - prevsize, psize);
+ return NULL;
+ } else {
+ mchunkptr prev = chunk_minus_offset(p, prevsize);
+ psize += prevsize;
+ p = prev;
+ /* consolidate backward */
+ if (p != fm->dv) {
+ unlink_chunk(fm, p, prevsize);
+ } else if ((next->head & INUSE_BITS) == INUSE_BITS) {
+ fm->dvsize = psize;
+ set_free_with_pinuse(p, psize, next);
+ return NULL;
+ }
+ }
+ }
+ if (!cinuse(next)) { /* consolidate forward */
+ if (next == fm->top) {
+ size_t tsize = fm->topsize += psize;
+ fm->top = p;
+ p->head = tsize | PINUSE_BIT;
+ if (p == fm->dv) {
+ fm->dv = 0;
+ fm->dvsize = 0;
+ }
+ if (tsize > fm->trim_check)
+ alloc_trim(fm, 0);
+ return NULL;
+ } else if (next == fm->dv) {
+ size_t dsize = fm->dvsize += psize;
+ fm->dv = p;
+ set_size_and_pinuse_of_free_chunk(p, dsize);
+ return NULL;
+ } else {
+ size_t nsize = chunksize(next);
+ psize += nsize;
+ unlink_chunk(fm, next, nsize);
+ set_size_and_pinuse_of_free_chunk(p, psize);
+ if (p == fm->dv) {
+ fm->dvsize = psize;
+ return NULL;
+ }
+ }
+ } else {
+ set_free_with_pinuse(p, psize, next);
+ }
+
+ if (is_small(psize)) {
+ insert_small_chunk(fm, p, psize);
+ } else {
+ tchunkptr tp = (tchunkptr)p;
+ insert_large_chunk(fm, tp, psize);
+ if (--fm->release_checks == 0)
+ release_unused_segments(fm);
+ }
+ }
+ return NULL;
+}
+
+static LJ_NOINLINE void *lj_alloc_realloc(void *msp, void *ptr, size_t nsize)
+{
+ if (nsize >= MAX_REQUEST) {
+ return NULL;
+ } else {
+ mstate m = (mstate)msp;
+ mchunkptr oldp = mem2chunk(ptr);
+ size_t oldsize = chunksize(oldp);
+ mchunkptr next = chunk_plus_offset(oldp, oldsize);
+ mchunkptr newp = 0;
+ size_t nb = request2size(nsize);
+
+ /* Try to either shrink or extend into top. Else malloc-copy-free */
+ if (is_direct(oldp)) {
+ newp = direct_resize(oldp, nb); /* this may return NULL. */
+ } else if (oldsize >= nb) { /* already big enough */
+ size_t rsize = oldsize - nb;
+ newp = oldp;
+ if (rsize >= MIN_CHUNK_SIZE) {
+ mchunkptr rem = chunk_plus_offset(newp, nb);
+ set_inuse(m, newp, nb);
+ set_inuse(m, rem, rsize);
+ lj_alloc_free(m, chunk2mem(rem));
+ }
+ } else if (next == m->top && oldsize + m->topsize > nb) {
+ /* Expand into top */
+ size_t newsize = oldsize + m->topsize;
+ size_t newtopsize = newsize - nb;
+ mchunkptr newtop = chunk_plus_offset(oldp, nb);
+ set_inuse(m, oldp, nb);
+ newtop->head = newtopsize |PINUSE_BIT;
+ m->top = newtop;
+ m->topsize = newtopsize;
+ newp = oldp;
+ }
+
+ if (newp != 0) {
+ return chunk2mem(newp);
+ } else {
+ void *newmem = lj_alloc_malloc(m, nsize);
+ if (newmem != 0) {
+ size_t oc = oldsize - overhead_for(oldp);
+ memcpy(newmem, ptr, oc < nsize ? oc : nsize);
+ lj_alloc_free(m, ptr);
+ }
+ return newmem;
+ }
+ }
+}
+
+void *lj_alloc_f(void *msp, void *ptr, size_t osize, size_t nsize)
+{
+ (void)osize;
+ if (nsize == 0) {
+ return lj_alloc_free(msp, ptr);
+ } else if (ptr == NULL) {
+ return lj_alloc_malloc(msp, nsize);
+ } else {
+ return lj_alloc_realloc(msp, ptr, nsize);
+ }
+}
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_alloc.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_alloc.h
new file mode 100644
index 0000000..f87a7cf
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_alloc.h
@@ -0,0 +1,17 @@
+/*
+** Bundled memory allocator.
+** Donated to the public domain.
+*/
+
+#ifndef _LJ_ALLOC_H
+#define _LJ_ALLOC_H
+
+#include "lj_def.h"
+
+#ifndef LUAJIT_USE_SYSMALLOC
+LJ_FUNC void *lj_alloc_create(void);
+LJ_FUNC void lj_alloc_destroy(void *msp);
+LJ_FUNC void *lj_alloc_f(void *msp, void *ptr, size_t osize, size_t nsize);
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_api.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_api.c
new file mode 100644
index 0000000..7b0b3f9
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_api.c
@@ -0,0 +1,1200 @@
+/*
+** Public Lua/C API.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Major portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#define lj_api_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_debug.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_func.h"
+#include "lj_udata.h"
+#include "lj_meta.h"
+#include "lj_state.h"
+#include "lj_bc.h"
+#include "lj_frame.h"
+#include "lj_trace.h"
+#include "lj_vm.h"
+#include "lj_strscan.h"
+
+/* -- Common helper functions --------------------------------------------- */
+
+#define api_checknelems(L, n) api_check(L, (n) <= (L->top - L->base))
+#define api_checkvalidindex(L, i) api_check(L, (i) != niltv(L))
+
+static TValue *index2adr(lua_State *L, int idx)
+{
+ if (idx > 0) {
+ TValue *o = L->base + (idx - 1);
+ return o < L->top ? o : niltv(L);
+ } else if (idx > LUA_REGISTRYINDEX) {
+ api_check(L, idx != 0 && -idx <= L->top - L->base);
+ return L->top + idx;
+ } else if (idx == LUA_GLOBALSINDEX) {
+ TValue *o = &G(L)->tmptv;
+ settabV(L, o, tabref(L->env));
+ return o;
+ } else if (idx == LUA_REGISTRYINDEX) {
+ return registry(L);
+ } else {
+ GCfunc *fn = curr_func(L);
+ api_check(L, fn->c.gct == ~LJ_TFUNC && !isluafunc(fn));
+ if (idx == LUA_ENVIRONINDEX) {
+ TValue *o = &G(L)->tmptv;
+ settabV(L, o, tabref(fn->c.env));
+ return o;
+ } else {
+ idx = LUA_GLOBALSINDEX - idx;
+ return idx <= fn->c.nupvalues ? &fn->c.upvalue[idx-1] : niltv(L);
+ }
+ }
+}
+
+static TValue *stkindex2adr(lua_State *L, int idx)
+{
+ if (idx > 0) {
+ TValue *o = L->base + (idx - 1);
+ return o < L->top ? o : niltv(L);
+ } else {
+ api_check(L, idx != 0 && -idx <= L->top - L->base);
+ return L->top + idx;
+ }
+}
+
+static GCtab *getcurrenv(lua_State *L)
+{
+ GCfunc *fn = curr_func(L);
+ return fn->c.gct == ~LJ_TFUNC ? tabref(fn->c.env) : tabref(L->env);
+}
+
+/* -- Miscellaneous API functions ----------------------------------------- */
+
+LUA_API int lua_status(lua_State *L)
+{
+ return L->status;
+}
+
+LUA_API int lua_checkstack(lua_State *L, int size)
+{
+ if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK) {
+ return 0; /* Stack overflow. */
+ } else if (size > 0) {
+ lj_state_checkstack(L, (MSize)size);
+ }
+ return 1;
+}
+
+LUALIB_API void luaL_checkstack(lua_State *L, int size, const char *msg)
+{
+ if (!lua_checkstack(L, size))
+ lj_err_callerv(L, LJ_ERR_STKOVM, msg);
+}
+
+LUA_API void lua_xmove(lua_State *from, lua_State *to, int n)
+{
+ TValue *f, *t;
+ if (from == to) return;
+ api_checknelems(from, n);
+ api_check(from, G(from) == G(to));
+ lj_state_checkstack(to, (MSize)n);
+ f = from->top;
+ t = to->top = to->top + n;
+ while (--n >= 0) copyTV(to, --t, --f);
+ from->top = f;
+}
+
+/* -- Stack manipulation -------------------------------------------------- */
+
+LUA_API int lua_gettop(lua_State *L)
+{
+ return (int)(L->top - L->base);
+}
+
+LUA_API void lua_settop(lua_State *L, int idx)
+{
+ if (idx >= 0) {
+ api_check(L, idx <= tvref(L->maxstack) - L->base);
+ if (L->base + idx > L->top) {
+ if (L->base + idx >= tvref(L->maxstack))
+ lj_state_growstack(L, (MSize)idx - (MSize)(L->top - L->base));
+ do { setnilV(L->top++); } while (L->top < L->base + idx);
+ } else {
+ L->top = L->base + idx;
+ }
+ } else {
+ api_check(L, -(idx+1) <= (L->top - L->base));
+ L->top += idx+1; /* Shrinks top (idx < 0). */
+ }
+}
+
+LUA_API void lua_remove(lua_State *L, int idx)
+{
+ TValue *p = stkindex2adr(L, idx);
+ api_checkvalidindex(L, p);
+ while (++p < L->top) copyTV(L, p-1, p);
+ L->top--;
+}
+
+LUA_API void lua_insert(lua_State *L, int idx)
+{
+ TValue *q, *p = stkindex2adr(L, idx);
+ api_checkvalidindex(L, p);
+ for (q = L->top; q > p; q--) copyTV(L, q, q-1);
+ copyTV(L, p, L->top);
+}
+
+LUA_API void lua_replace(lua_State *L, int idx)
+{
+ api_checknelems(L, 1);
+ if (idx == LUA_GLOBALSINDEX) {
+ api_check(L, tvistab(L->top-1));
+ /* NOBARRIER: A thread (i.e. L) is never black. */
+ setgcref(L->env, obj2gco(tabV(L->top-1)));
+ } else if (idx == LUA_ENVIRONINDEX) {
+ GCfunc *fn = curr_func(L);
+ if (fn->c.gct != ~LJ_TFUNC)
+ lj_err_msg(L, LJ_ERR_NOENV);
+ api_check(L, tvistab(L->top-1));
+ setgcref(fn->c.env, obj2gco(tabV(L->top-1)));
+ lj_gc_barrier(L, fn, L->top-1);
+ } else {
+ TValue *o = index2adr(L, idx);
+ api_checkvalidindex(L, o);
+ copyTV(L, o, L->top-1);
+ if (idx < LUA_GLOBALSINDEX) /* Need a barrier for upvalues. */
+ lj_gc_barrier(L, curr_func(L), L->top-1);
+ }
+ L->top--;
+}
+
+LUA_API void lua_pushvalue(lua_State *L, int idx)
+{
+ copyTV(L, L->top, index2adr(L, idx));
+ incr_top(L);
+}
+
+/* -- Stack getters ------------------------------------------------------- */
+
+LUA_API int lua_type(lua_State *L, int idx)
+{
+ cTValue *o = index2adr(L, idx);
+ if (tvisnumber(o)) {
+ return LUA_TNUMBER;
+#if LJ_64
+ } else if (tvislightud(o)) {
+ return LUA_TLIGHTUSERDATA;
+#endif
+ } else if (o == niltv(L)) {
+ return LUA_TNONE;
+ } else { /* Magic internal/external tag conversion. ORDER LJ_T */
+ uint32_t t = ~itype(o);
+#if LJ_64
+ int tt = (int)((U64x(75a06,98042110) >> 4*t) & 15u);
+#else
+ int tt = (int)(((t < 8 ? 0x98042110u : 0x75a06u) >> 4*(t&7)) & 15u);
+#endif
+ lua_assert(tt != LUA_TNIL || tvisnil(o));
+ return tt;
+ }
+}
+
+LUALIB_API void luaL_checktype(lua_State *L, int idx, int tt)
+{
+ if (lua_type(L, idx) != tt)
+ lj_err_argt(L, idx, tt);
+}
+
+LUALIB_API void luaL_checkany(lua_State *L, int idx)
+{
+ if (index2adr(L, idx) == niltv(L))
+ lj_err_arg(L, idx, LJ_ERR_NOVAL);
+}
+
+LUA_API const char *lua_typename(lua_State *L, int t)
+{
+ UNUSED(L);
+ return lj_obj_typename[t+1];
+}
+
+LUA_API int lua_iscfunction(lua_State *L, int idx)
+{
+ cTValue *o = index2adr(L, idx);
+ return tvisfunc(o) && !isluafunc(funcV(o));
+}
+
+LUA_API int lua_isnumber(lua_State *L, int idx)
+{
+ cTValue *o = index2adr(L, idx);
+ TValue tmp;
+ return (tvisnumber(o) || (tvisstr(o) && lj_strscan_number(strV(o), &tmp)));
+}
+
+LUA_API int lua_isstring(lua_State *L, int idx)
+{
+ cTValue *o = index2adr(L, idx);
+ return (tvisstr(o) || tvisnumber(o));
+}
+
+LUA_API int lua_isuserdata(lua_State *L, int idx)
+{
+ cTValue *o = index2adr(L, idx);
+ return (tvisudata(o) || tvislightud(o));
+}
+
+LUA_API int lua_rawequal(lua_State *L, int idx1, int idx2)
+{
+ cTValue *o1 = index2adr(L, idx1);
+ cTValue *o2 = index2adr(L, idx2);
+ return (o1 == niltv(L) || o2 == niltv(L)) ? 0 : lj_obj_equal(o1, o2);
+}
+
+LUA_API int lua_equal(lua_State *L, int idx1, int idx2)
+{
+ cTValue *o1 = index2adr(L, idx1);
+ cTValue *o2 = index2adr(L, idx2);
+ if (tvisint(o1) && tvisint(o2)) {
+ return intV(o1) == intV(o2);
+ } else if (tvisnumber(o1) && tvisnumber(o2)) {
+ return numberVnum(o1) == numberVnum(o2);
+ } else if (itype(o1) != itype(o2)) {
+ return 0;
+ } else if (tvispri(o1)) {
+ return o1 != niltv(L) && o2 != niltv(L);
+#if LJ_64
+ } else if (tvislightud(o1)) {
+ return o1->u64 == o2->u64;
+#endif
+ } else if (gcrefeq(o1->gcr, o2->gcr)) {
+ return 1;
+ } else if (!tvistabud(o1)) {
+ return 0;
+ } else {
+ TValue *base = lj_meta_equal(L, gcV(o1), gcV(o2), 0);
+ if ((uintptr_t)base <= 1) {
+ return (int)(uintptr_t)base;
+ } else {
+ L->top = base+2;
+ lj_vm_call(L, base, 1+1);
+ L->top -= 2;
+ return tvistruecond(L->top+1);
+ }
+ }
+}
+
+LUA_API int lua_lessthan(lua_State *L, int idx1, int idx2)
+{
+ cTValue *o1 = index2adr(L, idx1);
+ cTValue *o2 = index2adr(L, idx2);
+ if (o1 == niltv(L) || o2 == niltv(L)) {
+ return 0;
+ } else if (tvisint(o1) && tvisint(o2)) {
+ return intV(o1) < intV(o2);
+ } else if (tvisnumber(o1) && tvisnumber(o2)) {
+ return numberVnum(o1) < numberVnum(o2);
+ } else {
+ TValue *base = lj_meta_comp(L, o1, o2, 0);
+ if ((uintptr_t)base <= 1) {
+ return (int)(uintptr_t)base;
+ } else {
+ L->top = base+2;
+ lj_vm_call(L, base, 1+1);
+ L->top -= 2;
+ return tvistruecond(L->top+1);
+ }
+ }
+}
+
+LUA_API lua_Number lua_tonumber(lua_State *L, int idx)
+{
+ cTValue *o = index2adr(L, idx);
+ TValue tmp;
+ if (LJ_LIKELY(tvisnumber(o)))
+ return numberVnum(o);
+ else if (tvisstr(o) && lj_strscan_num(strV(o), &tmp))
+ return numV(&tmp);
+ else
+ return 0;
+}
+
+LUALIB_API lua_Number luaL_checknumber(lua_State *L, int idx)
+{
+ cTValue *o = index2adr(L, idx);
+ TValue tmp;
+ if (LJ_LIKELY(tvisnumber(o)))
+ return numberVnum(o);
+ else if (!(tvisstr(o) && lj_strscan_num(strV(o), &tmp)))
+ lj_err_argt(L, idx, LUA_TNUMBER);
+ return numV(&tmp);
+}
+
+LUALIB_API lua_Number luaL_optnumber(lua_State *L, int idx, lua_Number def)
+{
+ cTValue *o = index2adr(L, idx);
+ TValue tmp;
+ if (LJ_LIKELY(tvisnumber(o)))
+ return numberVnum(o);
+ else if (tvisnil(o))
+ return def;
+ else if (!(tvisstr(o) && lj_strscan_num(strV(o), &tmp)))
+ lj_err_argt(L, idx, LUA_TNUMBER);
+ return numV(&tmp);
+}
+
+LUA_API lua_Integer lua_tointeger(lua_State *L, int idx)
+{
+ cTValue *o = index2adr(L, idx);
+ TValue tmp;
+ lua_Number n;
+ if (LJ_LIKELY(tvisint(o))) {
+ return intV(o);
+ } else if (LJ_LIKELY(tvisnum(o))) {
+ n = numV(o);
+ } else {
+ if (!(tvisstr(o) && lj_strscan_number(strV(o), &tmp)))
+ return 0;
+ if (tvisint(&tmp))
+ return (lua_Integer)intV(&tmp);
+ n = numV(&tmp);
+ }
+#if LJ_64
+ return (lua_Integer)n;
+#else
+ return lj_num2int(n);
+#endif
+}
+
+LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int idx)
+{
+ cTValue *o = index2adr(L, idx);
+ TValue tmp;
+ lua_Number n;
+ if (LJ_LIKELY(tvisint(o))) {
+ return intV(o);
+ } else if (LJ_LIKELY(tvisnum(o))) {
+ n = numV(o);
+ } else {
+ if (!(tvisstr(o) && lj_strscan_number(strV(o), &tmp)))
+ lj_err_argt(L, idx, LUA_TNUMBER);
+ if (tvisint(&tmp))
+ return (lua_Integer)intV(&tmp);
+ n = numV(&tmp);
+ }
+#if LJ_64
+ return (lua_Integer)n;
+#else
+ return lj_num2int(n);
+#endif
+}
+
+LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int idx, lua_Integer def)
+{
+ cTValue *o = index2adr(L, idx);
+ TValue tmp;
+ lua_Number n;
+ if (LJ_LIKELY(tvisint(o))) {
+ return intV(o);
+ } else if (LJ_LIKELY(tvisnum(o))) {
+ n = numV(o);
+ } else if (tvisnil(o)) {
+ return def;
+ } else {
+ if (!(tvisstr(o) && lj_strscan_number(strV(o), &tmp)))
+ lj_err_argt(L, idx, LUA_TNUMBER);
+ if (tvisint(&tmp))
+ return (lua_Integer)intV(&tmp);
+ n = numV(&tmp);
+ }
+#if LJ_64
+ return (lua_Integer)n;
+#else
+ return lj_num2int(n);
+#endif
+}
+
+LUA_API int lua_toboolean(lua_State *L, int idx)
+{
+ cTValue *o = index2adr(L, idx);
+ return tvistruecond(o);
+}
+
+LUA_API const char *lua_tolstring(lua_State *L, int idx, size_t *len)
+{
+ TValue *o = index2adr(L, idx);
+ GCstr *s;
+ if (LJ_LIKELY(tvisstr(o))) {
+ s = strV(o);
+ } else if (tvisnumber(o)) {
+ lj_gc_check(L);
+ o = index2adr(L, idx); /* GC may move the stack. */
+ s = lj_str_fromnumber(L, o);
+ setstrV(L, o, s);
+ } else {
+ if (len != NULL) *len = 0;
+ return NULL;
+ }
+ if (len != NULL) *len = s->len;
+ return strdata(s);
+}
+
+LUALIB_API const char *luaL_checklstring(lua_State *L, int idx, size_t *len)
+{
+ TValue *o = index2adr(L, idx);
+ GCstr *s;
+ if (LJ_LIKELY(tvisstr(o))) {
+ s = strV(o);
+ } else if (tvisnumber(o)) {
+ lj_gc_check(L);
+ o = index2adr(L, idx); /* GC may move the stack. */
+ s = lj_str_fromnumber(L, o);
+ setstrV(L, o, s);
+ } else {
+ lj_err_argt(L, idx, LUA_TSTRING);
+ }
+ if (len != NULL) *len = s->len;
+ return strdata(s);
+}
+
+LUALIB_API const char *luaL_optlstring(lua_State *L, int idx,
+ const char *def, size_t *len)
+{
+ TValue *o = index2adr(L, idx);
+ GCstr *s;
+ if (LJ_LIKELY(tvisstr(o))) {
+ s = strV(o);
+ } else if (tvisnil(o)) {
+ if (len != NULL) *len = def ? strlen(def) : 0;
+ return def;
+ } else if (tvisnumber(o)) {
+ lj_gc_check(L);
+ o = index2adr(L, idx); /* GC may move the stack. */
+ s = lj_str_fromnumber(L, o);
+ setstrV(L, o, s);
+ } else {
+ lj_err_argt(L, idx, LUA_TSTRING);
+ }
+ if (len != NULL) *len = s->len;
+ return strdata(s);
+}
+
+LUALIB_API int luaL_checkoption(lua_State *L, int idx, const char *def,
+ const char *const lst[])
+{
+ ptrdiff_t i;
+ const char *s = lua_tolstring(L, idx, NULL);
+ if (s == NULL && (s = def) == NULL)
+ lj_err_argt(L, idx, LUA_TSTRING);
+ for (i = 0; lst[i]; i++)
+ if (strcmp(lst[i], s) == 0)
+ return (int)i;
+ lj_err_argv(L, idx, LJ_ERR_INVOPTM, s);
+}
+
+LUA_API size_t lua_objlen(lua_State *L, int idx)
+{
+ TValue *o = index2adr(L, idx);
+ if (tvisstr(o)) {
+ return strV(o)->len;
+ } else if (tvistab(o)) {
+ return (size_t)lj_tab_len(tabV(o));
+ } else if (tvisudata(o)) {
+ return udataV(o)->len;
+ } else if (tvisnumber(o)) {
+ GCstr *s = lj_str_fromnumber(L, o);
+ setstrV(L, o, s);
+ return s->len;
+ } else {
+ return 0;
+ }
+}
+
+LUA_API lua_CFunction lua_tocfunction(lua_State *L, int idx)
+{
+ cTValue *o = index2adr(L, idx);
+ if (tvisfunc(o)) {
+ BCOp op = bc_op(*mref(funcV(o)->c.pc, BCIns));
+ if (op == BC_FUNCC || op == BC_FUNCCW)
+ return funcV(o)->c.f;
+ }
+ return NULL;
+}
+
+LUA_API void *lua_touserdata(lua_State *L, int idx)
+{
+ cTValue *o = index2adr(L, idx);
+ if (tvisudata(o))
+ return uddata(udataV(o));
+ else if (tvislightud(o))
+ return lightudV(o);
+ else
+ return NULL;
+}
+
+LUA_API lua_State *lua_tothread(lua_State *L, int idx)
+{
+ cTValue *o = index2adr(L, idx);
+ return (!tvisthread(o)) ? NULL : threadV(o);
+}
+
+LUA_API const void *lua_topointer(lua_State *L, int idx)
+{
+ cTValue *o = index2adr(L, idx);
+ if (tvisudata(o))
+ return uddata(udataV(o));
+ else if (tvislightud(o))
+ return lightudV(o);
+ else if (tviscdata(o))
+ return cdataptr(cdataV(o));
+ else if (tvisgcv(o))
+ return gcV(o);
+ else
+ return NULL;
+}
+
+/* -- Stack setters (object creation) ------------------------------------- */
+
+LUA_API void lua_pushnil(lua_State *L)
+{
+ setnilV(L->top);
+ incr_top(L);
+}
+
+LUA_API void lua_pushnumber(lua_State *L, lua_Number n)
+{
+ setnumV(L->top, n);
+ if (LJ_UNLIKELY(tvisnan(L->top)))
+ setnanV(L->top); /* Canonicalize injected NaNs. */
+ incr_top(L);
+}
+
+LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
+{
+ setintptrV(L->top, n);
+ incr_top(L);
+}
+
+LUA_API void lua_pushlstring(lua_State *L, const char *str, size_t len)
+{
+ GCstr *s;
+ lj_gc_check(L);
+ s = lj_str_new(L, str, len);
+ setstrV(L, L->top, s);
+ incr_top(L);
+}
+
+LUA_API void lua_pushstring(lua_State *L, const char *str)
+{
+ if (str == NULL) {
+ setnilV(L->top);
+ } else {
+ GCstr *s;
+ lj_gc_check(L);
+ s = lj_str_newz(L, str);
+ setstrV(L, L->top, s);
+ }
+ incr_top(L);
+}
+
+LUA_API const char *lua_pushvfstring(lua_State *L, const char *fmt,
+ va_list argp)
+{
+ lj_gc_check(L);
+ return lj_str_pushvf(L, fmt, argp);
+}
+
+LUA_API const char *lua_pushfstring(lua_State *L, const char *fmt, ...)
+{
+ const char *ret;
+ va_list argp;
+ lj_gc_check(L);
+ va_start(argp, fmt);
+ ret = lj_str_pushvf(L, fmt, argp);
+ va_end(argp);
+ return ret;
+}
+
+LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction f, int n)
+{
+ GCfunc *fn;
+ lj_gc_check(L);
+ api_checknelems(L, n);
+ fn = lj_func_newC(L, (MSize)n, getcurrenv(L));
+ fn->c.f = f;
+ L->top -= n;
+ while (n--)
+ copyTV(L, &fn->c.upvalue[n], L->top+n);
+ setfuncV(L, L->top, fn);
+ lua_assert(iswhite(obj2gco(fn)));
+ incr_top(L);
+}
+
+LUA_API void lua_pushboolean(lua_State *L, int b)
+{
+ setboolV(L->top, (b != 0));
+ incr_top(L);
+}
+
+LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
+{
+ setlightudV(L->top, checklightudptr(L, p));
+ incr_top(L);
+}
+
+LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
+{
+ GCtab *t;
+ lj_gc_check(L);
+ t = lj_tab_new(L, (uint32_t)(narray > 0 ? narray+1 : 0), hsize2hbits(nrec));
+ settabV(L, L->top, t);
+ incr_top(L);
+}
+
+LUALIB_API int luaL_newmetatable(lua_State *L, const char *tname)
+{
+ GCtab *regt = tabV(registry(L));
+ TValue *tv = lj_tab_setstr(L, regt, lj_str_newz(L, tname));
+ if (tvisnil(tv)) {
+ GCtab *mt = lj_tab_new(L, 0, 1);
+ settabV(L, tv, mt);
+ settabV(L, L->top++, mt);
+ lj_gc_anybarriert(L, regt);
+ return 1;
+ } else {
+ copyTV(L, L->top++, tv);
+ return 0;
+ }
+}
+
+LUA_API int lua_pushthread(lua_State *L)
+{
+ setthreadV(L, L->top, L);
+ incr_top(L);
+ return (mainthread(G(L)) == L);
+}
+
+LUA_API lua_State *lua_newthread(lua_State *L)
+{
+ lua_State *L1;
+ lj_gc_check(L);
+ L1 = lj_state_new(L);
+ setthreadV(L, L->top, L1);
+ incr_top(L);
+ return L1;
+}
+
+LUA_API void *lua_newuserdata(lua_State *L, size_t size)
+{
+ GCudata *ud;
+ lj_gc_check(L);
+ if (size > LJ_MAX_UDATA)
+ lj_err_msg(L, LJ_ERR_UDATAOV);
+ ud = lj_udata_new(L, (MSize)size, getcurrenv(L));
+ setudataV(L, L->top, ud);
+ incr_top(L);
+ return uddata(ud);
+}
+
+LUA_API void lua_concat(lua_State *L, int n)
+{
+ api_checknelems(L, n);
+ if (n >= 2) {
+ n--;
+ do {
+ TValue *top = lj_meta_cat(L, L->top-1, -n);
+ if (top == NULL) {
+ L->top -= n;
+ break;
+ }
+ n -= (int)(L->top - top);
+ L->top = top+2;
+ lj_vm_call(L, top, 1+1);
+ L->top--;
+ copyTV(L, L->top-1, L->top);
+ } while (--n > 0);
+ } else if (n == 0) { /* Push empty string. */
+ setstrV(L, L->top, &G(L)->strempty);
+ incr_top(L);
+ }
+ /* else n == 1: nothing to do. */
+}
+
+/* -- Object getters ------------------------------------------------------ */
+
+LUA_API void lua_gettable(lua_State *L, int idx)
+{
+ cTValue *v, *t = index2adr(L, idx);
+ api_checkvalidindex(L, t);
+ v = lj_meta_tget(L, t, L->top-1);
+ if (v == NULL) {
+ L->top += 2;
+ lj_vm_call(L, L->top-2, 1+1);
+ L->top -= 2;
+ v = L->top+1;
+ }
+ copyTV(L, L->top-1, v);
+}
+
+LUA_API void lua_getfield(lua_State *L, int idx, const char *k)
+{
+ cTValue *v, *t = index2adr(L, idx);
+ TValue key;
+ api_checkvalidindex(L, t);
+ setstrV(L, &key, lj_str_newz(L, k));
+ v = lj_meta_tget(L, t, &key);
+ if (v == NULL) {
+ L->top += 2;
+ lj_vm_call(L, L->top-2, 1+1);
+ L->top -= 2;
+ v = L->top+1;
+ }
+ copyTV(L, L->top, v);
+ incr_top(L);
+}
+
+LUA_API void lua_rawget(lua_State *L, int idx)
+{
+ cTValue *t = index2adr(L, idx);
+ api_check(L, tvistab(t));
+ copyTV(L, L->top-1, lj_tab_get(L, tabV(t), L->top-1));
+}
+
+LUA_API void lua_rawgeti(lua_State *L, int idx, int n)
+{
+ cTValue *v, *t = index2adr(L, idx);
+ api_check(L, tvistab(t));
+ v = lj_tab_getint(tabV(t), n);
+ if (v) {
+ copyTV(L, L->top, v);
+ } else {
+ setnilV(L->top);
+ }
+ incr_top(L);
+}
+
+LUA_API int lua_getmetatable(lua_State *L, int idx)
+{
+ cTValue *o = index2adr(L, idx);
+ GCtab *mt = NULL;
+ if (tvistab(o))
+ mt = tabref(tabV(o)->metatable);
+ else if (tvisudata(o))
+ mt = tabref(udataV(o)->metatable);
+ else
+ mt = tabref(basemt_obj(G(L), o));
+ if (mt == NULL)
+ return 0;
+ settabV(L, L->top, mt);
+ incr_top(L);
+ return 1;
+}
+
+LUALIB_API int luaL_getmetafield(lua_State *L, int idx, const char *field)
+{
+ if (lua_getmetatable(L, idx)) {
+ cTValue *tv = lj_tab_getstr(tabV(L->top-1), lj_str_newz(L, field));
+ if (tv && !tvisnil(tv)) {
+ copyTV(L, L->top-1, tv);
+ return 1;
+ }
+ L->top--;
+ }
+ return 0;
+}
+
+LUA_API void lua_getfenv(lua_State *L, int idx)
+{
+ cTValue *o = index2adr(L, idx);
+ api_checkvalidindex(L, o);
+ if (tvisfunc(o)) {
+ settabV(L, L->top, tabref(funcV(o)->c.env));
+ } else if (tvisudata(o)) {
+ settabV(L, L->top, tabref(udataV(o)->env));
+ } else if (tvisthread(o)) {
+ settabV(L, L->top, tabref(threadV(o)->env));
+ } else {
+ setnilV(L->top);
+ }
+ incr_top(L);
+}
+
+LUA_API int lua_next(lua_State *L, int idx)
+{
+ cTValue *t = index2adr(L, idx);
+ int more;
+ api_check(L, tvistab(t));
+ more = lj_tab_next(L, tabV(t), L->top-1);
+ if (more) {
+ incr_top(L); /* Return new key and value slot. */
+ } else { /* End of traversal. */
+ L->top--; /* Remove key slot. */
+ }
+ return more;
+}
+
+LUA_API const char *lua_getupvalue(lua_State *L, int idx, int n)
+{
+ TValue *val;
+ const char *name = lj_debug_uvnamev(index2adr(L, idx), (uint32_t)(n-1), &val);
+ if (name) {
+ copyTV(L, L->top, val);
+ incr_top(L);
+ }
+ return name;
+}
+
+LUA_API void *lua_upvalueid(lua_State *L, int idx, int n)
+{
+ GCfunc *fn = funcV(index2adr(L, idx));
+ n--;
+ api_check(L, (uint32_t)n < fn->l.nupvalues);
+ return isluafunc(fn) ? (void *)gcref(fn->l.uvptr[n]) :
+ (void *)&fn->c.upvalue[n];
+}
+
+LUA_API void lua_upvaluejoin(lua_State *L, int idx1, int n1, int idx2, int n2)
+{
+ GCfunc *fn1 = funcV(index2adr(L, idx1));
+ GCfunc *fn2 = funcV(index2adr(L, idx2));
+ n1--; n2--;
+ api_check(L, isluafunc(fn1) && (uint32_t)n1 < fn1->l.nupvalues);
+ api_check(L, isluafunc(fn2) && (uint32_t)n2 < fn2->l.nupvalues);
+ setgcrefr(fn1->l.uvptr[n1], fn2->l.uvptr[n2]);
+ lj_gc_objbarrier(L, fn1, gcref(fn1->l.uvptr[n1]));
+}
+
+LUALIB_API void *luaL_checkudata(lua_State *L, int idx, const char *tname)
+{
+ cTValue *o = index2adr(L, idx);
+ if (tvisudata(o)) {
+ GCudata *ud = udataV(o);
+ cTValue *tv = lj_tab_getstr(tabV(registry(L)), lj_str_newz(L, tname));
+ if (tv && tvistab(tv) && tabV(tv) == tabref(ud->metatable))
+ return uddata(ud);
+ }
+ lj_err_argtype(L, idx, tname);
+ return NULL; /* unreachable */
+}
+
+/* -- Object setters ------------------------------------------------------ */
+
+LUA_API void lua_settable(lua_State *L, int idx)
+{
+ TValue *o;
+ cTValue *t = index2adr(L, idx);
+ api_checknelems(L, 2);
+ api_checkvalidindex(L, t);
+ o = lj_meta_tset(L, t, L->top-2);
+ if (o) {
+ /* NOBARRIER: lj_meta_tset ensures the table is not black. */
+ copyTV(L, o, L->top-1);
+ L->top -= 2;
+ } else {
+ L->top += 3;
+ copyTV(L, L->top-1, L->top-6);
+ lj_vm_call(L, L->top-3, 0+1);
+ L->top -= 3;
+ }
+}
+
+LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
+{
+ TValue *o;
+ TValue key;
+ cTValue *t = index2adr(L, idx);
+ api_checknelems(L, 1);
+ api_checkvalidindex(L, t);
+ setstrV(L, &key, lj_str_newz(L, k));
+ o = lj_meta_tset(L, t, &key);
+ if (o) {
+ L->top--;
+ /* NOBARRIER: lj_meta_tset ensures the table is not black. */
+ copyTV(L, o, L->top);
+ } else {
+ L->top += 3;
+ copyTV(L, L->top-1, L->top-6);
+ lj_vm_call(L, L->top-3, 0+1);
+ L->top -= 2;
+ }
+}
+
+LUA_API void lua_rawset(lua_State *L, int idx)
+{
+ GCtab *t = tabV(index2adr(L, idx));
+ TValue *dst, *key;
+ api_checknelems(L, 2);
+ key = L->top-2;
+ dst = lj_tab_set(L, t, key);
+ copyTV(L, dst, key+1);
+ lj_gc_anybarriert(L, t);
+ L->top = key;
+}
+
+LUA_API void lua_rawseti(lua_State *L, int idx, int n)
+{
+ GCtab *t = tabV(index2adr(L, idx));
+ TValue *dst, *src;
+ api_checknelems(L, 1);
+ dst = lj_tab_setint(L, t, n);
+ src = L->top-1;
+ copyTV(L, dst, src);
+ lj_gc_barriert(L, t, dst);
+ L->top = src;
+}
+
+LUA_API int lua_setmetatable(lua_State *L, int idx)
+{
+ global_State *g;
+ GCtab *mt;
+ cTValue *o = index2adr(L, idx);
+ api_checknelems(L, 1);
+ api_checkvalidindex(L, o);
+ if (tvisnil(L->top-1)) {
+ mt = NULL;
+ } else {
+ api_check(L, tvistab(L->top-1));
+ mt = tabV(L->top-1);
+ }
+ g = G(L);
+ if (tvistab(o)) {
+ setgcref(tabV(o)->metatable, obj2gco(mt));
+ if (mt)
+ lj_gc_objbarriert(L, tabV(o), mt);
+ } else if (tvisudata(o)) {
+ setgcref(udataV(o)->metatable, obj2gco(mt));
+ if (mt)
+ lj_gc_objbarrier(L, udataV(o), mt);
+ } else {
+ /* Flush cache, since traces specialize to basemt. But not during __gc. */
+ if (lj_trace_flushall(L))
+ lj_err_caller(L, LJ_ERR_NOGCMM);
+ if (tvisbool(o)) {
+ /* NOBARRIER: basemt is a GC root. */
+ setgcref(basemt_it(g, LJ_TTRUE), obj2gco(mt));
+ setgcref(basemt_it(g, LJ_TFALSE), obj2gco(mt));
+ } else {
+ /* NOBARRIER: basemt is a GC root. */
+ setgcref(basemt_obj(g, o), obj2gco(mt));
+ }
+ }
+ L->top--;
+ return 1;
+}
+
+LUA_API int lua_setfenv(lua_State *L, int idx)
+{
+ cTValue *o = index2adr(L, idx);
+ GCtab *t;
+ api_checknelems(L, 1);
+ api_checkvalidindex(L, o);
+ api_check(L, tvistab(L->top-1));
+ t = tabV(L->top-1);
+ if (tvisfunc(o)) {
+ setgcref(funcV(o)->c.env, obj2gco(t));
+ } else if (tvisudata(o)) {
+ setgcref(udataV(o)->env, obj2gco(t));
+ } else if (tvisthread(o)) {
+ setgcref(threadV(o)->env, obj2gco(t));
+ } else {
+ L->top--;
+ return 0;
+ }
+ lj_gc_objbarrier(L, gcV(o), t);
+ L->top--;
+ return 1;
+}
+
+LUA_API const char *lua_setupvalue(lua_State *L, int idx, int n)
+{
+ cTValue *f = index2adr(L, idx);
+ TValue *val;
+ const char *name;
+ api_checknelems(L, 1);
+ name = lj_debug_uvnamev(f, (uint32_t)(n-1), &val);
+ if (name) {
+ L->top--;
+ copyTV(L, val, L->top);
+ lj_gc_barrier(L, funcV(f), L->top);
+ }
+ return name;
+}
+
+/* -- Calls --------------------------------------------------------------- */
+
+LUA_API void lua_call(lua_State *L, int nargs, int nresults)
+{
+ api_check(L, L->status == 0 || L->status == LUA_ERRERR);
+ api_checknelems(L, nargs+1);
+ lj_vm_call(L, L->top - nargs, nresults+1);
+}
+
+LUA_API int lua_pcall(lua_State *L, int nargs, int nresults, int errfunc)
+{
+ global_State *g = G(L);
+ uint8_t oldh = hook_save(g);
+ ptrdiff_t ef;
+ int status;
+ api_check(L, L->status == 0 || L->status == LUA_ERRERR);
+ api_checknelems(L, nargs+1);
+ if (errfunc == 0) {
+ ef = 0;
+ } else {
+ cTValue *o = stkindex2adr(L, errfunc);
+ api_checkvalidindex(L, o);
+ ef = savestack(L, o);
+ }
+ status = lj_vm_pcall(L, L->top - nargs, nresults+1, ef);
+ if (status) hook_restore(g, oldh);
+ return status;
+}
+
+static TValue *cpcall(lua_State *L, lua_CFunction func, void *ud)
+{
+ GCfunc *fn = lj_func_newC(L, 0, getcurrenv(L));
+ fn->c.f = func;
+ setfuncV(L, L->top, fn);
+ setlightudV(L->top+1, checklightudptr(L, ud));
+ cframe_nres(L->cframe) = 1+0; /* Zero results. */
+ L->top += 2;
+ return L->top-1; /* Now call the newly allocated C function. */
+}
+
+LUA_API int lua_cpcall(lua_State *L, lua_CFunction func, void *ud)
+{
+ global_State *g = G(L);
+ uint8_t oldh = hook_save(g);
+ int status;
+ api_check(L, L->status == 0 || L->status == LUA_ERRERR);
+ status = lj_vm_cpcall(L, func, ud, cpcall);
+ if (status) hook_restore(g, oldh);
+ return status;
+}
+
+LUALIB_API int luaL_callmeta(lua_State *L, int idx, const char *field)
+{
+ if (luaL_getmetafield(L, idx, field)) {
+ TValue *base = L->top--;
+ copyTV(L, base, index2adr(L, idx));
+ L->top = base+1;
+ lj_vm_call(L, base, 1+1);
+ return 1;
+ }
+ return 0;
+}
+
+/* -- Coroutine yield and resume ------------------------------------------ */
+
+LUA_API int lua_yield(lua_State *L, int nresults)
+{
+ void *cf = L->cframe;
+ global_State *g = G(L);
+ if (cframe_canyield(cf)) {
+ cf = cframe_raw(cf);
+ if (!hook_active(g)) { /* Regular yield: move results down if needed. */
+ cTValue *f = L->top - nresults;
+ if (f > L->base) {
+ TValue *t = L->base;
+ while (--nresults >= 0) copyTV(L, t++, f++);
+ L->top = t;
+ }
+ L->cframe = NULL;
+ L->status = LUA_YIELD;
+ return -1;
+ } else { /* Yield from hook: add a pseudo-frame. */
+ TValue *top = L->top;
+ hook_leave(g);
+ top->u64 = cframe_multres(cf);
+ setcont(top+1, lj_cont_hook);
+ setframe_pc(top+1, cframe_pc(cf)-1);
+ setframe_gc(top+2, obj2gco(L));
+ setframe_ftsz(top+2, (int)((char *)(top+3)-(char *)L->base)+FRAME_CONT);
+ L->top = L->base = top+3;
+#if LJ_TARGET_X64
+ lj_err_throw(L, LUA_YIELD);
+#else
+ L->cframe = NULL;
+ L->status = LUA_YIELD;
+ lj_vm_unwind_c(cf, LUA_YIELD);
+#endif
+ }
+ }
+ lj_err_msg(L, LJ_ERR_CYIELD);
+ return 0; /* unreachable */
+}
+
+LUA_API int lua_resume(lua_State *L, int nargs)
+{
+ if (L->cframe == NULL && L->status <= LUA_YIELD)
+ return lj_vm_resume(L, L->top - nargs, 0, 0);
+ L->top = L->base;
+ setstrV(L, L->top, lj_err_str(L, LJ_ERR_COSUSP));
+ incr_top(L);
+ return LUA_ERRRUN;
+}
+
+/* -- GC and memory management -------------------------------------------- */
+
+LUA_API int lua_gc(lua_State *L, int what, int data)
+{
+ global_State *g = G(L);
+ int res = 0;
+ switch (what) {
+ case LUA_GCSTOP:
+ g->gc.threshold = LJ_MAX_MEM;
+ break;
+ case LUA_GCRESTART:
+ g->gc.threshold = data == -1 ? (g->gc.total/100)*g->gc.pause : g->gc.total;
+ break;
+ case LUA_GCCOLLECT:
+ lj_gc_fullgc(L);
+ break;
+ case LUA_GCCOUNT:
+ res = (int)(g->gc.total >> 10);
+ break;
+ case LUA_GCCOUNTB:
+ res = (int)(g->gc.total & 0x3ff);
+ break;
+ case LUA_GCSTEP: {
+ MSize a = (MSize)data << 10;
+ g->gc.threshold = (a <= g->gc.total) ? (g->gc.total - a) : 0;
+ while (g->gc.total >= g->gc.threshold)
+ if (lj_gc_step(L) > 0) {
+ res = 1;
+ break;
+ }
+ break;
+ }
+ case LUA_GCSETPAUSE:
+ res = (int)(g->gc.pause);
+ g->gc.pause = (MSize)data;
+ break;
+ case LUA_GCSETSTEPMUL:
+ res = (int)(g->gc.stepmul);
+ g->gc.stepmul = (MSize)data;
+ break;
+ default:
+ res = -1; /* Invalid option. */
+ }
+ return res;
+}
+
+LUA_API lua_Alloc lua_getallocf(lua_State *L, void **ud)
+{
+ global_State *g = G(L);
+ if (ud) *ud = g->allocd;
+ return g->allocf;
+}
+
+LUA_API void lua_setallocf(lua_State *L, lua_Alloc f, void *ud)
+{
+ global_State *g = G(L);
+ g->allocd = ud;
+ g->allocf = f;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_arch.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_arch.h
new file mode 100644
index 0000000..5f7e445
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_arch.h
@@ -0,0 +1,452 @@
+/*
+** Target architecture selection.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_ARCH_H
+#define _LJ_ARCH_H
+
+#include "lua.h"
+
+/* Target endianess. */
+#define LUAJIT_LE 0
+#define LUAJIT_BE 1
+
+/* Target architectures. */
+#define LUAJIT_ARCH_X86 1
+#define LUAJIT_ARCH_x86 1
+#define LUAJIT_ARCH_X64 2
+#define LUAJIT_ARCH_x64 2
+#define LUAJIT_ARCH_ARM 3
+#define LUAJIT_ARCH_arm 3
+#define LUAJIT_ARCH_PPC 4
+#define LUAJIT_ARCH_ppc 4
+#define LUAJIT_ARCH_PPCSPE 5
+#define LUAJIT_ARCH_ppcspe 5
+#define LUAJIT_ARCH_MIPS 6
+#define LUAJIT_ARCH_mips 6
+
+/* Target OS. */
+#define LUAJIT_OS_OTHER 0
+#define LUAJIT_OS_WINDOWS 1
+#define LUAJIT_OS_LINUX 2
+#define LUAJIT_OS_OSX 3
+#define LUAJIT_OS_BSD 4
+#define LUAJIT_OS_POSIX 5
+
+/* Select native target if no target defined. */
+#ifndef LUAJIT_TARGET
+
+#if defined(__i386) || defined(__i386__) || defined(_M_IX86)
+#define LUAJIT_TARGET LUAJIT_ARCH_X86
+#elif defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
+#define LUAJIT_TARGET LUAJIT_ARCH_X64
+#elif defined(__arm__) || defined(__arm) || defined(__ARM__) || defined(__ARM)
+#define LUAJIT_TARGET LUAJIT_ARCH_ARM
+#elif defined(__ppc__) || defined(__ppc) || defined(__PPC__) || defined(__PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__POWERPC) || defined(_M_PPC)
+#ifdef __NO_FPRS__
+#define LUAJIT_TARGET LUAJIT_ARCH_PPCSPE
+#else
+#define LUAJIT_TARGET LUAJIT_ARCH_PPC
+#endif
+#elif defined(__mips__) || defined(__mips) || defined(__MIPS__) || defined(__MIPS)
+#define LUAJIT_TARGET LUAJIT_ARCH_MIPS
+#else
+#error "No support for this architecture (yet)"
+#endif
+
+#endif
+
+/* Select native OS if no target OS defined. */
+#ifndef LUAJIT_OS
+
+#if defined(_WIN32) && !defined(_XBOX_VER)
+#define LUAJIT_OS LUAJIT_OS_WINDOWS
+#elif defined(__linux__)
+#define LUAJIT_OS LUAJIT_OS_LINUX
+#elif defined(__MACH__) && defined(__APPLE__)
+#define LUAJIT_OS LUAJIT_OS_OSX
+#elif (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
+ defined(__NetBSD__) || defined(__OpenBSD__) || \
+ defined(__DragonFly__)) && !defined(__ORBIS__)
+#define LUAJIT_OS LUAJIT_OS_BSD
+#elif (defined(__sun__) && defined(__svr4__))
+#define LUAJIT_OS LUAJIT_OS_POSIX
+#elif defined(__CYGWIN__)
+#define LJ_TARGET_CYGWIN 1
+#define LUAJIT_OS LUAJIT_OS_POSIX
+#else
+#define LUAJIT_OS LUAJIT_OS_OTHER
+#endif
+
+#endif
+
+/* Set target OS properties. */
+#if LUAJIT_OS == LUAJIT_OS_WINDOWS
+#define LJ_OS_NAME "Windows"
+#elif LUAJIT_OS == LUAJIT_OS_LINUX
+#define LJ_OS_NAME "Linux"
+#elif LUAJIT_OS == LUAJIT_OS_OSX
+#define LJ_OS_NAME "OSX"
+#elif LUAJIT_OS == LUAJIT_OS_BSD
+#define LJ_OS_NAME "BSD"
+#elif LUAJIT_OS == LUAJIT_OS_POSIX
+#define LJ_OS_NAME "POSIX"
+#else
+#define LJ_OS_NAME "Other"
+#endif
+
+#define LJ_TARGET_WINDOWS (LUAJIT_OS == LUAJIT_OS_WINDOWS)
+#define LJ_TARGET_LINUX (LUAJIT_OS == LUAJIT_OS_LINUX)
+#define LJ_TARGET_OSX (LUAJIT_OS == LUAJIT_OS_OSX)
+#define LJ_TARGET_IOS (LJ_TARGET_OSX && LUAJIT_TARGET == LUAJIT_ARCH_ARM)
+#define LJ_TARGET_POSIX (LUAJIT_OS > LUAJIT_OS_WINDOWS)
+#define LJ_TARGET_DLOPEN LJ_TARGET_POSIX
+
+#ifdef __CELLOS_LV2__
+#define LJ_TARGET_PS3 1
+#define LJ_TARGET_CONSOLE 1
+#endif
+
+#ifdef __ORBIS__
+#define LJ_TARGET_PS4 1
+#define LJ_TARGET_CONSOLE 1
+#undef NULL
+#define NULL ((void*)0)
+#endif
+
+#ifdef __psp2__
+#define LJ_TARGET_PSVITA 1
+#define LJ_TARGET_CONSOLE 1
+#endif
+
+#if _XBOX_VER >= 200
+#define LJ_TARGET_XBOX360 1
+#define LJ_TARGET_CONSOLE 1
+#endif
+
+#define LJ_NUMMODE_SINGLE 0 /* Single-number mode only. */
+#define LJ_NUMMODE_SINGLE_DUAL 1 /* Default to single-number mode. */
+#define LJ_NUMMODE_DUAL 2 /* Dual-number mode only. */
+#define LJ_NUMMODE_DUAL_SINGLE 3 /* Default to dual-number mode. */
+
+/* Set target architecture properties. */
+#if LUAJIT_TARGET == LUAJIT_ARCH_X86
+
+#define LJ_ARCH_NAME "x86"
+#define LJ_ARCH_BITS 32
+#define LJ_ARCH_ENDIAN LUAJIT_LE
+#if LJ_TARGET_WINDOWS || LJ_TARGET_CYGWIN
+#define LJ_ABI_WIN 1
+#else
+#define LJ_ABI_WIN 0
+#endif
+#define LJ_TARGET_X86 1
+#define LJ_TARGET_X86ORX64 1
+#define LJ_TARGET_EHRETREG 0
+#define LJ_TARGET_MASKSHIFT 1
+#define LJ_TARGET_MASKROT 1
+#define LJ_TARGET_UNALIGNED 1
+#define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE_DUAL
+
+#elif LUAJIT_TARGET == LUAJIT_ARCH_X64
+
+#define LJ_ARCH_NAME "x64"
+#define LJ_ARCH_BITS 64
+#define LJ_ARCH_ENDIAN LUAJIT_LE
+#if LJ_TARGET_WINDOWS || LJ_TARGET_CYGWIN
+#define LJ_ABI_WIN 1
+#else
+#define LJ_ABI_WIN 0
+#endif
+#define LJ_TARGET_X64 1
+#define LJ_TARGET_X86ORX64 1
+#define LJ_TARGET_EHRETREG 0
+#define LJ_TARGET_JUMPRANGE 31 /* +-2^31 = +-2GB */
+#define LJ_TARGET_MASKSHIFT 1
+#define LJ_TARGET_MASKROT 1
+#define LJ_TARGET_UNALIGNED 1
+#define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE_DUAL
+
+#elif LUAJIT_TARGET == LUAJIT_ARCH_ARM
+
+#define LJ_ARCH_NAME "arm"
+#define LJ_ARCH_BITS 32
+#define LJ_ARCH_ENDIAN LUAJIT_LE
+#if !defined(LJ_ARCH_HASFPU) && __SOFTFP__
+#define LJ_ARCH_HASFPU 0
+#endif
+#if !defined(LJ_ABI_SOFTFP) && !__ARM_PCS_VFP
+#define LJ_ABI_SOFTFP 1
+#endif
+#define LJ_ABI_EABI 1
+#define LJ_TARGET_ARM 1
+#define LJ_TARGET_EHRETREG 0
+#define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */
+#define LJ_TARGET_MASKSHIFT 0
+#define LJ_TARGET_MASKROT 1
+#define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */
+#define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL
+
+#if __ARM_ARCH____ARM_ARCH_8__ || __ARM_ARCH_8A__
+#define LJ_ARCH_VERSION 80
+#elif __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH_7S__ || __ARM_ARCH_7VE__
+#define LJ_ARCH_VERSION 70
+#elif __ARM_ARCH_6T2__
+#define LJ_ARCH_VERSION 61
+#elif __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6K__ || __ARM_ARCH_6Z__ || __ARM_ARCH_6ZK__
+#define LJ_ARCH_VERSION 60
+#else
+#define LJ_ARCH_VERSION 50
+#endif
+
+#elif LUAJIT_TARGET == LUAJIT_ARCH_PPC
+
+#define LJ_ARCH_NAME "ppc"
+#if _LP64
+#define LJ_ARCH_BITS 64
+#else
+#define LJ_ARCH_BITS 32
+#endif
+#define LJ_ARCH_ENDIAN LUAJIT_BE
+#define LJ_TARGET_PPC 1
+#define LJ_TARGET_EHRETREG 3
+#define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */
+#define LJ_TARGET_MASKSHIFT 0
+#define LJ_TARGET_MASKROT 1
+#define LJ_TARGET_UNIFYROT 1 /* Want only IR_BROL. */
+#define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL_SINGLE
+
+#if _ARCH_PWR7
+#define LJ_ARCH_VERSION 70
+#elif _ARCH_PWR6
+#define LJ_ARCH_VERSION 60
+#elif _ARCH_PWR5X
+#define LJ_ARCH_VERSION 51
+#elif _ARCH_PWR5
+#define LJ_ARCH_VERSION 50
+#elif _ARCH_PWR4
+#define LJ_ARCH_VERSION 40
+#else
+#define LJ_ARCH_VERSION 0
+#endif
+#if __PPC64__ || __powerpc64__ || LJ_TARGET_CONSOLE
+#define LJ_ARCH_PPC64 1
+#define LJ_ARCH_NOFFI 1
+#endif
+#if _ARCH_PPCSQ
+#define LJ_ARCH_SQRT 1
+#endif
+#if _ARCH_PWR5X
+#define LJ_ARCH_ROUND 1
+#endif
+#if __PPU__
+#define LJ_ARCH_CELL 1
+#endif
+#if LJ_TARGET_XBOX360
+#define LJ_ARCH_XENON 1
+#endif
+
+#elif LUAJIT_TARGET == LUAJIT_ARCH_PPCSPE
+
+#define LJ_ARCH_NAME "ppcspe"
+#define LJ_ARCH_BITS 32
+#define LJ_ARCH_ENDIAN LUAJIT_BE
+#ifndef LJ_ABI_SOFTFP
+#define LJ_ABI_SOFTFP 1
+#endif
+#define LJ_ABI_EABI 1
+#define LJ_TARGET_PPCSPE 1
+#define LJ_TARGET_EHRETREG 3
+#define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */
+#define LJ_TARGET_MASKSHIFT 0
+#define LJ_TARGET_MASKROT 1
+#define LJ_TARGET_UNIFYROT 1 /* Want only IR_BROL. */
+#define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE
+#define LJ_ARCH_NOFFI 1 /* NYI: comparisons, calls. */
+#define LJ_ARCH_NOJIT 1
+
+#elif LUAJIT_TARGET == LUAJIT_ARCH_MIPS
+
+#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL)
+#define LJ_ARCH_NAME "mipsel"
+#define LJ_ARCH_ENDIAN LUAJIT_LE
+#else
+#define LJ_ARCH_NAME "mips"
+#define LJ_ARCH_ENDIAN LUAJIT_BE
+#endif
+#define LJ_ARCH_BITS 32
+#define LJ_TARGET_MIPS 1
+#define LJ_TARGET_EHRETREG 4
+#define LJ_TARGET_JUMPRANGE 27 /* 2*2^27 = 256MB-aligned region */
+#define LJ_TARGET_MASKSHIFT 1
+#define LJ_TARGET_MASKROT 1
+#define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */
+#define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE
+
+#if _MIPS_ARCH_MIPS32R2
+#define LJ_ARCH_VERSION 20
+#else
+#define LJ_ARCH_VERSION 10
+#endif
+
+#else
+#error "No target architecture defined"
+#endif
+
+#ifndef LJ_PAGESIZE
+#define LJ_PAGESIZE 4096
+#endif
+
+/* Check for minimum required compiler versions. */
+#if defined(__GNUC__)
+#if LJ_TARGET_X86
+#if (__GNUC__ < 3) || ((__GNUC__ == 3) && __GNUC_MINOR__ < 4)
+#error "Need at least GCC 3.4 or newer"
+#endif
+#elif LJ_TARGET_X64
+#if __GNUC__ < 4
+#error "Need at least GCC 4.0 or newer"
+#endif
+#elif LJ_TARGET_ARM
+#if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 2)
+#error "Need at least GCC 4.2 or newer"
+#endif
+#elif !LJ_TARGET_PS3
+#if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 3)
+#error "Need at least GCC 4.3 or newer"
+#endif
+#endif
+#endif
+
+/* Check target-specific constraints. */
+#ifndef _BUILDVM_H
+#if LJ_TARGET_X64
+#if __USING_SJLJ_EXCEPTIONS__
+#error "Need a C compiler with native exception handling on x64"
+#endif
+#elif LJ_TARGET_ARM
+#if defined(__ARMEB__)
+#error "No support for big-endian ARM"
+#endif
+#if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__
+#error "No support for Cortex-M CPUs"
+#endif
+#if !(__ARM_EABI__ || LJ_TARGET_IOS)
+#error "Only ARM EABI or iOS 3.0+ ABI is supported"
+#endif
+#elif LJ_TARGET_PPC || LJ_TARGET_PPCSPE
+#if defined(_SOFT_FLOAT) || defined(_SOFT_DOUBLE)
+#error "No support for PowerPC CPUs without double-precision FPU"
+#endif
+#if defined(_LITTLE_ENDIAN) && (!defined(_BYTE_ORDER) || (_BYTE_ORDER == _LITTLE_ENDIAN))
+#error "No support for little-endian PowerPC"
+#endif
+#if defined(_LP64)
+#error "No support for PowerPC 64 bit mode"
+#endif
+#elif LJ_TARGET_MIPS
+#if defined(__mips_soft_float)
+#error "No support for MIPS CPUs without FPU"
+#endif
+#if defined(_LP64)
+#error "No support for MIPS64"
+#endif
+#endif
+#endif
+
+/* Enable or disable the dual-number mode for the VM. */
+#if (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE && LUAJIT_NUMMODE == 2) || \
+ (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL && LUAJIT_NUMMODE == 1)
+#error "No support for this number mode on this architecture"
+#endif
+#if LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL || \
+ (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL_SINGLE && LUAJIT_NUMMODE != 1) || \
+ (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE_DUAL && LUAJIT_NUMMODE == 2)
+#define LJ_DUALNUM 1
+#else
+#define LJ_DUALNUM 0
+#endif
+
+#if LJ_TARGET_IOS || LJ_TARGET_CONSOLE
+/* Runtime code generation is restricted on iOS. Complain to Apple, not me. */
+/* Ditto for the consoles. Complain to Sony or MS, not me. */
+#ifndef LUAJIT_ENABLE_JIT
+#define LJ_OS_NOJIT 1
+#endif
+#endif
+
+/* Disable or enable the JIT compiler. */
+#if defined(LUAJIT_DISABLE_JIT) || defined(LJ_ARCH_NOJIT) || defined(LJ_OS_NOJIT)
+#define LJ_HASJIT 0
+#else
+#define LJ_HASJIT 1
+#endif
+
+/* Disable or enable the FFI extension. */
+#if defined(LUAJIT_DISABLE_FFI) || defined(LJ_ARCH_NOFFI)
+#define LJ_HASFFI 0
+#else
+#define LJ_HASFFI 1
+#endif
+
+#ifndef LJ_ARCH_HASFPU
+#define LJ_ARCH_HASFPU 1
+#endif
+#ifndef LJ_ABI_SOFTFP
+#define LJ_ABI_SOFTFP 0
+#endif
+#define LJ_SOFTFP (!LJ_ARCH_HASFPU)
+
+#if LJ_ARCH_ENDIAN == LUAJIT_BE
+#define LJ_LE 0
+#define LJ_BE 1
+#define LJ_ENDIAN_SELECT(le, be) be
+#define LJ_ENDIAN_LOHI(lo, hi) hi lo
+#else
+#define LJ_LE 1
+#define LJ_BE 0
+#define LJ_ENDIAN_SELECT(le, be) le
+#define LJ_ENDIAN_LOHI(lo, hi) lo hi
+#endif
+
+#if LJ_ARCH_BITS == 32
+#define LJ_32 1
+#define LJ_64 0
+#else
+#define LJ_32 0
+#define LJ_64 1
+#endif
+
+#ifndef LJ_TARGET_UNALIGNED
+#define LJ_TARGET_UNALIGNED 0
+#endif
+
+/* Various workarounds for embedded operating systems. */
+#if (defined(__ANDROID__) && !defined(LJ_TARGET_X86ORX64)) || defined(__symbian__) || LJ_TARGET_XBOX360
+#define LUAJIT_NO_LOG2
+#endif
+#if defined(__symbian__)
+#define LUAJIT_NO_EXP2
+#endif
+#if LJ_TARGET_CONSOLE || (LJ_TARGET_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_8_0)
+#define LJ_NO_SYSTEM 1
+#endif
+
+#if !defined(LUAJIT_NO_UNWIND) && __GNU_COMPACT_EH__
+/* NYI: no support for compact unwind specification, yet. */
+#define LUAJIT_NO_UNWIND 1
+#endif
+
+#if defined(LUAJIT_NO_UNWIND) || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 || LJ_TARGET_PS4
+#define LJ_NO_UNWIND 1
+#endif
+
+/* Compatibility with Lua 5.1 vs. 5.2. */
+#ifdef LUAJIT_ENABLE_LUA52COMPAT
+#define LJ_52 1
+#else
+#define LJ_52 0
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_asm.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_asm.c
new file mode 100644
index 0000000..dd7186f
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_asm.c
@@ -0,0 +1,1921 @@
+/*
+** IR assembler (SSA IR -> machine code).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_asm_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT
+
+#include "lj_gc.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_frame.h"
+#if LJ_HASFFI
+#include "lj_ctype.h"
+#endif
+#include "lj_ir.h"
+#include "lj_jit.h"
+#include "lj_ircall.h"
+#include "lj_iropt.h"
+#include "lj_mcode.h"
+#include "lj_iropt.h"
+#include "lj_trace.h"
+#include "lj_snap.h"
+#include "lj_asm.h"
+#include "lj_dispatch.h"
+#include "lj_vm.h"
+#include "lj_target.h"
+
+#ifdef LUA_USE_ASSERT
+#include <stdio.h>
+#endif
+
+/* -- Assembler state and common macros ----------------------------------- */
+
+/* Assembler state. */
+typedef struct ASMState {
+ RegCost cost[RID_MAX]; /* Reference and blended allocation cost for regs. */
+
+ MCode *mcp; /* Current MCode pointer (grows down). */
+ MCode *mclim; /* Lower limit for MCode memory + red zone. */
+#ifdef LUA_USE_ASSERT
+ MCode *mcp_prev; /* Red zone overflow check. */
+#endif
+
+ IRIns *ir; /* Copy of pointer to IR instructions/constants. */
+ jit_State *J; /* JIT compiler state. */
+
+#if LJ_TARGET_X86ORX64
+ x86ModRM mrm; /* Fused x86 address operand. */
+#endif
+
+ RegSet freeset; /* Set of free registers. */
+ RegSet modset; /* Set of registers modified inside the loop. */
+ RegSet weakset; /* Set of weakly referenced registers. */
+ RegSet phiset; /* Set of PHI registers. */
+
+ uint32_t flags; /* Copy of JIT compiler flags. */
+ int loopinv; /* Loop branch inversion (0:no, 1:yes, 2:yes+CC_P). */
+
+ int32_t evenspill; /* Next even spill slot. */
+ int32_t oddspill; /* Next odd spill slot (or 0). */
+
+ IRRef curins; /* Reference of current instruction. */
+ IRRef stopins; /* Stop assembly before hitting this instruction. */
+ IRRef orignins; /* Original T->nins. */
+
+ IRRef snapref; /* Current snapshot is active after this reference. */
+ IRRef snaprename; /* Rename highwater mark for snapshot check. */
+ SnapNo snapno; /* Current snapshot number. */
+ SnapNo loopsnapno; /* Loop snapshot number. */
+
+ IRRef fuseref; /* Fusion limit (loopref, 0 or FUSE_DISABLED). */
+ IRRef sectref; /* Section base reference (loopref or 0). */
+ IRRef loopref; /* Reference of LOOP instruction (or 0). */
+
+ BCReg topslot; /* Number of slots for stack check (unless 0). */
+ int32_t gcsteps; /* Accumulated number of GC steps (per section). */
+
+ GCtrace *T; /* Trace to assemble. */
+ GCtrace *parent; /* Parent trace (or NULL). */
+
+ MCode *mcbot; /* Bottom of reserved MCode. */
+ MCode *mctop; /* Top of generated MCode. */
+ MCode *mcloop; /* Pointer to loop MCode (or NULL). */
+ MCode *invmcp; /* Points to invertible loop branch (or NULL). */
+ MCode *flagmcp; /* Pending opportunity to merge flag setting ins. */
+ MCode *realign; /* Realign loop if not NULL. */
+
+#ifdef RID_NUM_KREF
+ int32_t krefk[RID_NUM_KREF];
+#endif
+ IRRef1 phireg[RID_MAX]; /* PHI register references. */
+ uint16_t parentmap[LJ_MAX_JSLOTS]; /* Parent instruction to RegSP map. */
+} ASMState;
+
+#define IR(ref) (&as->ir[(ref)])
+
+#define ASMREF_TMP1 REF_TRUE /* Temp. register. */
+#define ASMREF_TMP2 REF_FALSE /* Temp. register. */
+#define ASMREF_L REF_NIL /* Stores register for L. */
+
+/* Check for variant to invariant references. */
+#define iscrossref(as, ref) ((ref) < as->sectref)
+
+/* Inhibit memory op fusion from variant to invariant references. */
+#define FUSE_DISABLED (~(IRRef)0)
+#define mayfuse(as, ref) ((ref) > as->fuseref)
+#define neverfuse(as) (as->fuseref == FUSE_DISABLED)
+#define canfuse(as, ir) (!neverfuse(as) && !irt_isphi((ir)->t))
+#define opisfusableload(o) \
+ ((o) == IR_ALOAD || (o) == IR_HLOAD || (o) == IR_ULOAD || \
+ (o) == IR_FLOAD || (o) == IR_XLOAD || (o) == IR_SLOAD || (o) == IR_VLOAD)
+
+/* Sparse limit checks using a red zone before the actual limit. */
+#define MCLIM_REDZONE 64
+
+static LJ_NORET LJ_NOINLINE void asm_mclimit(ASMState *as)
+{
+ lj_mcode_limiterr(as->J, (size_t)(as->mctop - as->mcp + 4*MCLIM_REDZONE));
+}
+
+static LJ_AINLINE void checkmclim(ASMState *as)
+{
+#ifdef LUA_USE_ASSERT
+ if (as->mcp + MCLIM_REDZONE < as->mcp_prev) {
+ IRIns *ir = IR(as->curins+1);
+ fprintf(stderr, "RED ZONE OVERFLOW: %p IR %04d %02d %04d %04d\n", as->mcp,
+ as->curins+1-REF_BIAS, ir->o, ir->op1-REF_BIAS, ir->op2-REF_BIAS);
+ lua_assert(0);
+ }
+#endif
+ if (LJ_UNLIKELY(as->mcp < as->mclim)) asm_mclimit(as);
+#ifdef LUA_USE_ASSERT
+ as->mcp_prev = as->mcp;
+#endif
+}
+
+#ifdef RID_NUM_KREF
+#define ra_iskref(ref) ((ref) < RID_NUM_KREF)
+#define ra_krefreg(ref) ((Reg)(RID_MIN_KREF + (Reg)(ref)))
+#define ra_krefk(as, ref) (as->krefk[(ref)])
+
+static LJ_AINLINE void ra_setkref(ASMState *as, Reg r, int32_t k)
+{
+ IRRef ref = (IRRef)(r - RID_MIN_KREF);
+ as->krefk[ref] = k;
+ as->cost[r] = REGCOST(ref, ref);
+}
+
+#else
+#define ra_iskref(ref) 0
+#define ra_krefreg(ref) RID_MIN_GPR
+#define ra_krefk(as, ref) 0
+#endif
+
+/* Arch-specific field offsets. */
+static const uint8_t field_ofs[IRFL__MAX+1] = {
+#define FLOFS(name, ofs) (uint8_t)(ofs),
+IRFLDEF(FLOFS)
+#undef FLOFS
+ 0
+};
+
+/* -- Target-specific instruction emitter --------------------------------- */
+
+#if LJ_TARGET_X86ORX64
+#include "lj_emit_x86.h"
+#elif LJ_TARGET_ARM
+#include "lj_emit_arm.h"
+#elif LJ_TARGET_PPC
+#include "lj_emit_ppc.h"
+#elif LJ_TARGET_MIPS
+#include "lj_emit_mips.h"
+#else
+#error "Missing instruction emitter for target CPU"
+#endif
+
+/* -- Register allocator debugging ---------------------------------------- */
+
+/* #define LUAJIT_DEBUG_RA */
+
+#ifdef LUAJIT_DEBUG_RA
+
+#include <stdio.h>
+#include <stdarg.h>
+
+#define RIDNAME(name) #name,
+static const char *const ra_regname[] = {
+ GPRDEF(RIDNAME)
+ FPRDEF(RIDNAME)
+ VRIDDEF(RIDNAME)
+ NULL
+};
+#undef RIDNAME
+
+static char ra_dbg_buf[65536];
+static char *ra_dbg_p;
+static char *ra_dbg_merge;
+static MCode *ra_dbg_mcp;
+
+static void ra_dstart(void)
+{
+ ra_dbg_p = ra_dbg_buf;
+ ra_dbg_merge = NULL;
+ ra_dbg_mcp = NULL;
+}
+
+static void ra_dflush(void)
+{
+ fwrite(ra_dbg_buf, 1, (size_t)(ra_dbg_p-ra_dbg_buf), stdout);
+ ra_dstart();
+}
+
+static void ra_dprintf(ASMState *as, const char *fmt, ...)
+{
+ char *p;
+ va_list argp;
+ va_start(argp, fmt);
+ p = ra_dbg_mcp == as->mcp ? ra_dbg_merge : ra_dbg_p;
+ ra_dbg_mcp = NULL;
+ p += sprintf(p, "%08x \e[36m%04d ", (uintptr_t)as->mcp, as->curins-REF_BIAS);
+ for (;;) {
+ const char *e = strchr(fmt, '$');
+ if (e == NULL) break;
+ memcpy(p, fmt, (size_t)(e-fmt));
+ p += e-fmt;
+ if (e[1] == 'r') {
+ Reg r = va_arg(argp, Reg) & RID_MASK;
+ if (r <= RID_MAX) {
+ const char *q;
+ for (q = ra_regname[r]; *q; q++)
+ *p++ = *q >= 'A' && *q <= 'Z' ? *q + 0x20 : *q;
+ } else {
+ *p++ = '?';
+ lua_assert(0);
+ }
+ } else if (e[1] == 'f' || e[1] == 'i') {
+ IRRef ref;
+ if (e[1] == 'f')
+ ref = va_arg(argp, IRRef);
+ else
+ ref = va_arg(argp, IRIns *) - as->ir;
+ if (ref >= REF_BIAS)
+ p += sprintf(p, "%04d", ref - REF_BIAS);
+ else
+ p += sprintf(p, "K%03d", REF_BIAS - ref);
+ } else if (e[1] == 's') {
+ uint32_t slot = va_arg(argp, uint32_t);
+ p += sprintf(p, "[sp+0x%x]", sps_scale(slot));
+ } else if (e[1] == 'x') {
+ p += sprintf(p, "%08x", va_arg(argp, int32_t));
+ } else {
+ lua_assert(0);
+ }
+ fmt = e+2;
+ }
+ va_end(argp);
+ while (*fmt)
+ *p++ = *fmt++;
+ *p++ = '\e'; *p++ = '['; *p++ = 'm'; *p++ = '\n';
+ if (p > ra_dbg_buf+sizeof(ra_dbg_buf)-256) {
+ fwrite(ra_dbg_buf, 1, (size_t)(p-ra_dbg_buf), stdout);
+ p = ra_dbg_buf;
+ }
+ ra_dbg_p = p;
+}
+
+#define RA_DBG_START() ra_dstart()
+#define RA_DBG_FLUSH() ra_dflush()
+#define RA_DBG_REF() \
+ do { char *_p = ra_dbg_p; ra_dprintf(as, ""); \
+ ra_dbg_merge = _p; ra_dbg_mcp = as->mcp; } while (0)
+#define RA_DBGX(x) ra_dprintf x
+
+#else
+#define RA_DBG_START() ((void)0)
+#define RA_DBG_FLUSH() ((void)0)
+#define RA_DBG_REF() ((void)0)
+#define RA_DBGX(x) ((void)0)
+#endif
+
+/* -- Register allocator -------------------------------------------------- */
+
+#define ra_free(as, r) rset_set(as->freeset, (r))
+#define ra_modified(as, r) rset_set(as->modset, (r))
+#define ra_weak(as, r) rset_set(as->weakset, (r))
+#define ra_noweak(as, r) rset_clear(as->weakset, (r))
+
+#define ra_used(ir) (ra_hasreg((ir)->r) || ra_hasspill((ir)->s))
+
+/* Setup register allocator. */
+static void ra_setup(ASMState *as)
+{
+ Reg r;
+ /* Initially all regs (except the stack pointer) are free for use. */
+ as->freeset = RSET_INIT;
+ as->modset = RSET_EMPTY;
+ as->weakset = RSET_EMPTY;
+ as->phiset = RSET_EMPTY;
+ memset(as->phireg, 0, sizeof(as->phireg));
+ for (r = RID_MIN_GPR; r < RID_MAX; r++)
+ as->cost[r] = REGCOST(~0u, 0u);
+}
+
+/* Rematerialize constants. */
+static Reg ra_rematk(ASMState *as, IRRef ref)
+{
+ IRIns *ir;
+ Reg r;
+ if (ra_iskref(ref)) {
+ r = ra_krefreg(ref);
+ lua_assert(!rset_test(as->freeset, r));
+ ra_free(as, r);
+ ra_modified(as, r);
+ emit_loadi(as, r, ra_krefk(as, ref));
+ return r;
+ }
+ ir = IR(ref);
+ r = ir->r;
+ lua_assert(ra_hasreg(r) && !ra_hasspill(ir->s));
+ ra_free(as, r);
+ ra_modified(as, r);
+ ir->r = RID_INIT; /* Do not keep any hint. */
+ RA_DBGX((as, "remat $i $r", ir, r));
+#if !LJ_SOFTFP
+ if (ir->o == IR_KNUM) {
+ emit_loadn(as, r, ir_knum(ir));
+ } else
+#endif
+ if (emit_canremat(REF_BASE) && ir->o == IR_BASE) {
+ ra_sethint(ir->r, RID_BASE); /* Restore BASE register hint. */
+ emit_getgl(as, r, jit_base);
+ } else if (emit_canremat(ASMREF_L) && ir->o == IR_KPRI) {
+ lua_assert(irt_isnil(ir->t)); /* REF_NIL stores ASMREF_L register. */
+ emit_getgl(as, r, jit_L);
+#if LJ_64
+ } else if (ir->o == IR_KINT64) {
+ emit_loadu64(as, r, ir_kint64(ir)->u64);
+#endif
+ } else {
+ lua_assert(ir->o == IR_KINT || ir->o == IR_KGC ||
+ ir->o == IR_KPTR || ir->o == IR_KKPTR || ir->o == IR_KNULL);
+ emit_loadi(as, r, ir->i);
+ }
+ return r;
+}
+
+/* Force a spill. Allocate a new spill slot if needed. */
+static int32_t ra_spill(ASMState *as, IRIns *ir)
+{
+ int32_t slot = ir->s;
+ lua_assert(ir >= as->ir + REF_TRUE);
+ if (!ra_hasspill(slot)) {
+ if (irt_is64(ir->t)) {
+ slot = as->evenspill;
+ as->evenspill += 2;
+ } else if (as->oddspill) {
+ slot = as->oddspill;
+ as->oddspill = 0;
+ } else {
+ slot = as->evenspill;
+ as->oddspill = slot+1;
+ as->evenspill += 2;
+ }
+ if (as->evenspill > 256)
+ lj_trace_err(as->J, LJ_TRERR_SPILLOV);
+ ir->s = (uint8_t)slot;
+ }
+ return sps_scale(slot);
+}
+
+/* Release the temporarily allocated register in ASMREF_TMP1/ASMREF_TMP2. */
+static Reg ra_releasetmp(ASMState *as, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ Reg r = ir->r;
+ lua_assert(ra_hasreg(r) && !ra_hasspill(ir->s));
+ ra_free(as, r);
+ ra_modified(as, r);
+ ir->r = RID_INIT;
+ return r;
+}
+
+/* Restore a register (marked as free). Rematerialize or force a spill. */
+static Reg ra_restore(ASMState *as, IRRef ref)
+{
+ if (emit_canremat(ref)) {
+ return ra_rematk(as, ref);
+ } else {
+ IRIns *ir = IR(ref);
+ int32_t ofs = ra_spill(as, ir); /* Force a spill slot. */
+ Reg r = ir->r;
+ lua_assert(ra_hasreg(r));
+ ra_sethint(ir->r, r); /* Keep hint. */
+ ra_free(as, r);
+ if (!rset_test(as->weakset, r)) { /* Only restore non-weak references. */
+ ra_modified(as, r);
+ RA_DBGX((as, "restore $i $r", ir, r));
+ emit_spload(as, ir, r, ofs);
+ }
+ return r;
+ }
+}
+
+/* Save a register to a spill slot. */
+static void ra_save(ASMState *as, IRIns *ir, Reg r)
+{
+ RA_DBGX((as, "save $i $r", ir, r));
+ emit_spstore(as, ir, r, sps_scale(ir->s));
+}
+
+#define MINCOST(name) \
+ if (rset_test(RSET_ALL, RID_##name) && \
+ LJ_LIKELY(allow&RID2RSET(RID_##name)) && as->cost[RID_##name] < cost) \
+ cost = as->cost[RID_##name];
+
+/* Evict the register with the lowest cost, forcing a restore. */
+static Reg ra_evict(ASMState *as, RegSet allow)
+{
+ IRRef ref;
+ RegCost cost = ~(RegCost)0;
+ lua_assert(allow != RSET_EMPTY);
+ if (RID_NUM_FPR == 0 || allow < RID2RSET(RID_MAX_GPR)) {
+ GPRDEF(MINCOST)
+ } else {
+ FPRDEF(MINCOST)
+ }
+ ref = regcost_ref(cost);
+ lua_assert(ra_iskref(ref) || (ref >= as->T->nk && ref < as->T->nins));
+ /* Preferably pick any weak ref instead of a non-weak, non-const ref. */
+ if (!irref_isk(ref) && (as->weakset & allow)) {
+ IRIns *ir = IR(ref);
+ if (!rset_test(as->weakset, ir->r))
+ ref = regcost_ref(as->cost[rset_pickbot((as->weakset & allow))]);
+ }
+ return ra_restore(as, ref);
+}
+
+/* Pick any register (marked as free). Evict on-demand. */
+static Reg ra_pick(ASMState *as, RegSet allow)
+{
+ RegSet pick = as->freeset & allow;
+ if (!pick)
+ return ra_evict(as, allow);
+ else
+ return rset_picktop(pick);
+}
+
+/* Get a scratch register (marked as free). */
+static Reg ra_scratch(ASMState *as, RegSet allow)
+{
+ Reg r = ra_pick(as, allow);
+ ra_modified(as, r);
+ RA_DBGX((as, "scratch $r", r));
+ return r;
+}
+
+/* Evict all registers from a set (if not free). */
+static void ra_evictset(ASMState *as, RegSet drop)
+{
+ RegSet work;
+ as->modset |= drop;
+#if !LJ_SOFTFP
+ work = (drop & ~as->freeset) & RSET_FPR;
+ while (work) {
+ Reg r = rset_pickbot(work);
+ ra_restore(as, regcost_ref(as->cost[r]));
+ rset_clear(work, r);
+ checkmclim(as);
+ }
+#endif
+ work = (drop & ~as->freeset);
+ while (work) {
+ Reg r = rset_pickbot(work);
+ ra_restore(as, regcost_ref(as->cost[r]));
+ rset_clear(work, r);
+ checkmclim(as);
+ }
+}
+
+/* Evict (rematerialize) all registers allocated to constants. */
+static void ra_evictk(ASMState *as)
+{
+ RegSet work;
+#if !LJ_SOFTFP
+ work = ~as->freeset & RSET_FPR;
+ while (work) {
+ Reg r = rset_pickbot(work);
+ IRRef ref = regcost_ref(as->cost[r]);
+ if (emit_canremat(ref) && irref_isk(ref)) {
+ ra_rematk(as, ref);
+ checkmclim(as);
+ }
+ rset_clear(work, r);
+ }
+#endif
+ work = ~as->freeset & RSET_GPR;
+ while (work) {
+ Reg r = rset_pickbot(work);
+ IRRef ref = regcost_ref(as->cost[r]);
+ if (emit_canremat(ref) && irref_isk(ref)) {
+ ra_rematk(as, ref);
+ checkmclim(as);
+ }
+ rset_clear(work, r);
+ }
+}
+
+#ifdef RID_NUM_KREF
+/* Allocate a register for a constant. */
+static Reg ra_allock(ASMState *as, int32_t k, RegSet allow)
+{
+ /* First try to find a register which already holds the same constant. */
+ RegSet pick, work = ~as->freeset & RSET_GPR;
+ Reg r;
+ while (work) {
+ IRRef ref;
+ r = rset_pickbot(work);
+ ref = regcost_ref(as->cost[r]);
+ if (ref < ASMREF_L &&
+ k == (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i))
+ return r;
+ rset_clear(work, r);
+ }
+ pick = as->freeset & allow;
+ if (pick) {
+ /* Constants should preferably get unmodified registers. */
+ if ((pick & ~as->modset))
+ pick &= ~as->modset;
+ r = rset_pickbot(pick); /* Reduce conflicts with inverse allocation. */
+ } else {
+ r = ra_evict(as, allow);
+ }
+ RA_DBGX((as, "allock $x $r", k, r));
+ ra_setkref(as, r, k);
+ rset_clear(as->freeset, r);
+ ra_noweak(as, r);
+ return r;
+}
+
+/* Allocate a specific register for a constant. */
+static void ra_allockreg(ASMState *as, int32_t k, Reg r)
+{
+ Reg kr = ra_allock(as, k, RID2RSET(r));
+ if (kr != r) {
+ IRIns irdummy;
+ irdummy.t.irt = IRT_INT;
+ ra_scratch(as, RID2RSET(r));
+ emit_movrr(as, &irdummy, r, kr);
+ }
+}
+#else
+#define ra_allockreg(as, k, r) emit_loadi(as, (r), (k))
+#endif
+
+/* Allocate a register for ref from the allowed set of registers.
+** Note: this function assumes the ref does NOT have a register yet!
+** Picks an optimal register, sets the cost and marks the register as non-free.
+*/
+static Reg ra_allocref(ASMState *as, IRRef ref, RegSet allow)
+{
+ IRIns *ir = IR(ref);
+ RegSet pick = as->freeset & allow;
+ Reg r;
+ lua_assert(ra_noreg(ir->r));
+ if (pick) {
+ /* First check register hint from propagation or PHI. */
+ if (ra_hashint(ir->r)) {
+ r = ra_gethint(ir->r);
+ if (rset_test(pick, r)) /* Use hint register if possible. */
+ goto found;
+ /* Rematerialization is cheaper than missing a hint. */
+ if (rset_test(allow, r) && emit_canremat(regcost_ref(as->cost[r]))) {
+ ra_rematk(as, regcost_ref(as->cost[r]));
+ goto found;
+ }
+ RA_DBGX((as, "hintmiss $f $r", ref, r));
+ }
+ /* Invariants should preferably get unmodified registers. */
+ if (ref < as->loopref && !irt_isphi(ir->t)) {
+ if ((pick & ~as->modset))
+ pick &= ~as->modset;
+ r = rset_pickbot(pick); /* Reduce conflicts with inverse allocation. */
+ } else {
+ /* We've got plenty of regs, so get callee-save regs if possible. */
+ if (RID_NUM_GPR > 8 && (pick & ~RSET_SCRATCH))
+ pick &= ~RSET_SCRATCH;
+ r = rset_picktop(pick);
+ }
+ } else {
+ r = ra_evict(as, allow);
+ }
+found:
+ RA_DBGX((as, "alloc $f $r", ref, r));
+ ir->r = (uint8_t)r;
+ rset_clear(as->freeset, r);
+ ra_noweak(as, r);
+ as->cost[r] = REGCOST_REF_T(ref, irt_t(ir->t));
+ return r;
+}
+
+/* Allocate a register on-demand. */
+static Reg ra_alloc1(ASMState *as, IRRef ref, RegSet allow)
+{
+ Reg r = IR(ref)->r;
+ /* Note: allow is ignored if the register is already allocated. */
+ if (ra_noreg(r)) r = ra_allocref(as, ref, allow);
+ ra_noweak(as, r);
+ return r;
+}
+
+/* Rename register allocation and emit move. */
+static void ra_rename(ASMState *as, Reg down, Reg up)
+{
+ IRRef ren, ref = regcost_ref(as->cost[up] = as->cost[down]);
+ IRIns *ir = IR(ref);
+ ir->r = (uint8_t)up;
+ as->cost[down] = 0;
+ lua_assert((down < RID_MAX_GPR) == (up < RID_MAX_GPR));
+ lua_assert(!rset_test(as->freeset, down) && rset_test(as->freeset, up));
+ ra_free(as, down); /* 'down' is free ... */
+ ra_modified(as, down);
+ rset_clear(as->freeset, up); /* ... and 'up' is now allocated. */
+ ra_noweak(as, up);
+ RA_DBGX((as, "rename $f $r $r", regcost_ref(as->cost[up]), down, up));
+ emit_movrr(as, ir, down, up); /* Backwards codegen needs inverse move. */
+ if (!ra_hasspill(IR(ref)->s)) { /* Add the rename to the IR. */
+ lj_ir_set(as->J, IRT(IR_RENAME, IRT_NIL), ref, as->snapno);
+ ren = tref_ref(lj_ir_emit(as->J));
+ as->ir = as->T->ir; /* The IR may have been reallocated. */
+ IR(ren)->r = (uint8_t)down;
+ IR(ren)->s = SPS_NONE;
+ }
+}
+
+/* Pick a destination register (marked as free).
+** Caveat: allow is ignored if there's already a destination register.
+** Use ra_destreg() to get a specific register.
+*/
+static Reg ra_dest(ASMState *as, IRIns *ir, RegSet allow)
+{
+ Reg dest = ir->r;
+ if (ra_hasreg(dest)) {
+ ra_free(as, dest);
+ ra_modified(as, dest);
+ } else {
+ if (ra_hashint(dest) && rset_test((as->freeset&allow), ra_gethint(dest))) {
+ dest = ra_gethint(dest);
+ ra_modified(as, dest);
+ RA_DBGX((as, "dest $r", dest));
+ } else {
+ dest = ra_scratch(as, allow);
+ }
+ ir->r = dest;
+ }
+ if (LJ_UNLIKELY(ra_hasspill(ir->s))) ra_save(as, ir, dest);
+ return dest;
+}
+
+/* Force a specific destination register (marked as free). */
+static void ra_destreg(ASMState *as, IRIns *ir, Reg r)
+{
+ Reg dest = ra_dest(as, ir, RID2RSET(r));
+ if (dest != r) {
+ lua_assert(rset_test(as->freeset, r));
+ ra_modified(as, r);
+ emit_movrr(as, ir, dest, r);
+ }
+}
+
+#if LJ_TARGET_X86ORX64
+/* Propagate dest register to left reference. Emit moves as needed.
+** This is a required fixup step for all 2-operand machine instructions.
+*/
+static void ra_left(ASMState *as, Reg dest, IRRef lref)
+{
+ IRIns *ir = IR(lref);
+ Reg left = ir->r;
+ if (ra_noreg(left)) {
+ if (irref_isk(lref)) {
+ if (ir->o == IR_KNUM) {
+ cTValue *tv = ir_knum(ir);
+ /* FP remat needs a load except for +0. Still better than eviction. */
+ if (tvispzero(tv) || !(as->freeset & RSET_FPR)) {
+ emit_loadn(as, dest, tv);
+ return;
+ }
+#if LJ_64
+ } else if (ir->o == IR_KINT64) {
+ emit_loadu64(as, dest, ir_kint64(ir)->u64);
+ return;
+#endif
+ } else {
+ lua_assert(ir->o == IR_KINT || ir->o == IR_KGC ||
+ ir->o == IR_KPTR || ir->o == IR_KKPTR || ir->o == IR_KNULL);
+ emit_loadi(as, dest, ir->i);
+ return;
+ }
+ }
+ if (!ra_hashint(left) && !iscrossref(as, lref))
+ ra_sethint(ir->r, dest); /* Propagate register hint. */
+ left = ra_allocref(as, lref, dest < RID_MAX_GPR ? RSET_GPR : RSET_FPR);
+ }
+ ra_noweak(as, left);
+ /* Move needed for true 3-operand instruction: y=a+b ==> y=a; y+=b. */
+ if (dest != left) {
+ /* Use register renaming if dest is the PHI reg. */
+ if (irt_isphi(ir->t) && as->phireg[dest] == lref) {
+ ra_modified(as, left);
+ ra_rename(as, left, dest);
+ } else {
+ emit_movrr(as, ir, dest, left);
+ }
+ }
+}
+#else
+/* Similar to ra_left, except we override any hints. */
+static void ra_leftov(ASMState *as, Reg dest, IRRef lref)
+{
+ IRIns *ir = IR(lref);
+ Reg left = ir->r;
+ if (ra_noreg(left)) {
+ ra_sethint(ir->r, dest); /* Propagate register hint. */
+ left = ra_allocref(as, lref,
+ (LJ_SOFTFP || dest < RID_MAX_GPR) ? RSET_GPR : RSET_FPR);
+ }
+ ra_noweak(as, left);
+ if (dest != left) {
+ /* Use register renaming if dest is the PHI reg. */
+ if (irt_isphi(ir->t) && as->phireg[dest] == lref) {
+ ra_modified(as, left);
+ ra_rename(as, left, dest);
+ } else {
+ emit_movrr(as, ir, dest, left);
+ }
+ }
+}
+#endif
+
+#if !LJ_64
+/* Force a RID_RETLO/RID_RETHI destination register pair (marked as free). */
+static void ra_destpair(ASMState *as, IRIns *ir)
+{
+ Reg destlo = ir->r, desthi = (ir+1)->r;
+ /* First spill unrelated refs blocking the destination registers. */
+ if (!rset_test(as->freeset, RID_RETLO) &&
+ destlo != RID_RETLO && desthi != RID_RETLO)
+ ra_restore(as, regcost_ref(as->cost[RID_RETLO]));
+ if (!rset_test(as->freeset, RID_RETHI) &&
+ destlo != RID_RETHI && desthi != RID_RETHI)
+ ra_restore(as, regcost_ref(as->cost[RID_RETHI]));
+ /* Next free the destination registers (if any). */
+ if (ra_hasreg(destlo)) {
+ ra_free(as, destlo);
+ ra_modified(as, destlo);
+ } else {
+ destlo = RID_RETLO;
+ }
+ if (ra_hasreg(desthi)) {
+ ra_free(as, desthi);
+ ra_modified(as, desthi);
+ } else {
+ desthi = RID_RETHI;
+ }
+ /* Check for conflicts and shuffle the registers as needed. */
+ if (destlo == RID_RETHI) {
+ if (desthi == RID_RETLO) {
+#if LJ_TARGET_X86
+ *--as->mcp = XI_XCHGa + RID_RETHI;
+#else
+ emit_movrr(as, ir, RID_RETHI, RID_TMP);
+ emit_movrr(as, ir, RID_RETLO, RID_RETHI);
+ emit_movrr(as, ir, RID_TMP, RID_RETLO);
+#endif
+ } else {
+ emit_movrr(as, ir, RID_RETHI, RID_RETLO);
+ if (desthi != RID_RETHI) emit_movrr(as, ir, desthi, RID_RETHI);
+ }
+ } else if (desthi == RID_RETLO) {
+ emit_movrr(as, ir, RID_RETLO, RID_RETHI);
+ if (destlo != RID_RETLO) emit_movrr(as, ir, destlo, RID_RETLO);
+ } else {
+ if (desthi != RID_RETHI) emit_movrr(as, ir, desthi, RID_RETHI);
+ if (destlo != RID_RETLO) emit_movrr(as, ir, destlo, RID_RETLO);
+ }
+ /* Restore spill slots (if any). */
+ if (ra_hasspill((ir+1)->s)) ra_save(as, ir+1, RID_RETHI);
+ if (ra_hasspill(ir->s)) ra_save(as, ir, RID_RETLO);
+}
+#endif
+
+/* -- Snapshot handling --------- ----------------------------------------- */
+
+/* Can we rematerialize a KNUM instead of forcing a spill? */
+static int asm_snap_canremat(ASMState *as)
+{
+ Reg r;
+ for (r = RID_MIN_FPR; r < RID_MAX_FPR; r++)
+ if (irref_isk(regcost_ref(as->cost[r])))
+ return 1;
+ return 0;
+}
+
+/* Check whether a sunk store corresponds to an allocation. */
+static int asm_sunk_store(ASMState *as, IRIns *ira, IRIns *irs)
+{
+ if (irs->s == 255) {
+ if (irs->o == IR_ASTORE || irs->o == IR_HSTORE ||
+ irs->o == IR_FSTORE || irs->o == IR_XSTORE) {
+ IRIns *irk = IR(irs->op1);
+ if (irk->o == IR_AREF || irk->o == IR_HREFK)
+ irk = IR(irk->op1);
+ return (IR(irk->op1) == ira);
+ }
+ return 0;
+ } else {
+ return (ira + irs->s == irs); /* Quick check. */
+ }
+}
+
+/* Allocate register or spill slot for a ref that escapes to a snapshot. */
+static void asm_snap_alloc1(ASMState *as, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ if (!irref_isk(ref) && (!(ra_used(ir) || ir->r == RID_SUNK))) {
+ if (ir->r == RID_SINK) {
+ ir->r = RID_SUNK;
+#if LJ_HASFFI
+ if (ir->o == IR_CNEWI) { /* Allocate CNEWI value. */
+ asm_snap_alloc1(as, ir->op2);
+ if (LJ_32 && (ir+1)->o == IR_HIOP)
+ asm_snap_alloc1(as, (ir+1)->op2);
+ } else
+#endif
+ { /* Allocate stored values for TNEW, TDUP and CNEW. */
+ IRIns *irs;
+ lua_assert(ir->o == IR_TNEW || ir->o == IR_TDUP || ir->o == IR_CNEW);
+ for (irs = IR(as->snapref-1); irs > ir; irs--)
+ if (irs->r == RID_SINK && asm_sunk_store(as, ir, irs)) {
+ lua_assert(irs->o == IR_ASTORE || irs->o == IR_HSTORE ||
+ irs->o == IR_FSTORE || irs->o == IR_XSTORE);
+ asm_snap_alloc1(as, irs->op2);
+ if (LJ_32 && (irs+1)->o == IR_HIOP)
+ asm_snap_alloc1(as, (irs+1)->op2);
+ }
+ }
+ } else {
+ RegSet allow;
+ if (ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT) {
+ IRIns *irc;
+ for (irc = IR(as->curins); irc > ir; irc--)
+ if ((irc->op1 == ref || irc->op2 == ref) &&
+ !(irc->r == RID_SINK || irc->r == RID_SUNK))
+ goto nosink; /* Don't sink conversion if result is used. */
+ asm_snap_alloc1(as, ir->op1);
+ return;
+ }
+ nosink:
+ allow = (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR;
+ if ((as->freeset & allow) ||
+ (allow == RSET_FPR && asm_snap_canremat(as))) {
+ /* Get a weak register if we have a free one or can rematerialize. */
+ Reg r = ra_allocref(as, ref, allow); /* Allocate a register. */
+ if (!irt_isphi(ir->t))
+ ra_weak(as, r); /* But mark it as weakly referenced. */
+ checkmclim(as);
+ RA_DBGX((as, "snapreg $f $r", ref, ir->r));
+ } else {
+ ra_spill(as, ir); /* Otherwise force a spill slot. */
+ RA_DBGX((as, "snapspill $f $s", ref, ir->s));
+ }
+ }
+ }
+}
+
+/* Allocate refs escaping to a snapshot. */
+static void asm_snap_alloc(ASMState *as)
+{
+ SnapShot *snap = &as->T->snap[as->snapno];
+ SnapEntry *map = &as->T->snapmap[snap->mapofs];
+ MSize n, nent = snap->nent;
+ for (n = 0; n < nent; n++) {
+ SnapEntry sn = map[n];
+ IRRef ref = snap_ref(sn);
+ if (!irref_isk(ref)) {
+ asm_snap_alloc1(as, ref);
+ if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM)) {
+ lua_assert(irt_type(IR(ref+1)->t) == IRT_SOFTFP);
+ asm_snap_alloc1(as, ref+1);
+ }
+ }
+ }
+}
+
+/* All guards for a snapshot use the same exitno. This is currently the
+** same as the snapshot number. Since the exact origin of the exit cannot
+** be determined, all guards for the same snapshot must exit with the same
+** RegSP mapping.
+** A renamed ref which has been used in a prior guard for the same snapshot
+** would cause an inconsistency. The easy way out is to force a spill slot.
+*/
+static int asm_snap_checkrename(ASMState *as, IRRef ren)
+{
+ SnapShot *snap = &as->T->snap[as->snapno];
+ SnapEntry *map = &as->T->snapmap[snap->mapofs];
+ MSize n, nent = snap->nent;
+ for (n = 0; n < nent; n++) {
+ SnapEntry sn = map[n];
+ IRRef ref = snap_ref(sn);
+ if (ref == ren || (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM) && ++ref == ren)) {
+ IRIns *ir = IR(ref);
+ ra_spill(as, ir); /* Register renamed, so force a spill slot. */
+ RA_DBGX((as, "snaprensp $f $s", ref, ir->s));
+ return 1; /* Found. */
+ }
+ }
+ return 0; /* Not found. */
+}
+
+/* Prepare snapshot for next guard instruction. */
+static void asm_snap_prep(ASMState *as)
+{
+ if (as->curins < as->snapref) {
+ do {
+ if (as->snapno == 0) return; /* Called by sunk stores before snap #0. */
+ as->snapno--;
+ as->snapref = as->T->snap[as->snapno].ref;
+ } while (as->curins < as->snapref);
+ asm_snap_alloc(as);
+ as->snaprename = as->T->nins;
+ } else {
+ /* Process any renames above the highwater mark. */
+ for (; as->snaprename < as->T->nins; as->snaprename++) {
+ IRIns *ir = IR(as->snaprename);
+ if (asm_snap_checkrename(as, ir->op1))
+ ir->op2 = REF_BIAS-1; /* Kill rename. */
+ }
+ }
+}
+
+/* -- Miscellaneous helpers ----------------------------------------------- */
+
+/* Collect arguments from CALL* and CARG instructions. */
+static void asm_collectargs(ASMState *as, IRIns *ir,
+ const CCallInfo *ci, IRRef *args)
+{
+ uint32_t n = CCI_NARGS(ci);
+ lua_assert(n <= CCI_NARGS_MAX*2); /* Account for split args. */
+ if ((ci->flags & CCI_L)) { *args++ = ASMREF_L; n--; }
+ while (n-- > 1) {
+ ir = IR(ir->op1);
+ lua_assert(ir->o == IR_CARG);
+ args[n] = ir->op2 == REF_NIL ? 0 : ir->op2;
+ }
+ args[0] = ir->op1 == REF_NIL ? 0 : ir->op1;
+ lua_assert(IR(ir->op1)->o != IR_CARG);
+}
+
+/* Reconstruct CCallInfo flags for CALLX*. */
+static uint32_t asm_callx_flags(ASMState *as, IRIns *ir)
+{
+ uint32_t nargs = 0;
+ if (ir->op1 != REF_NIL) { /* Count number of arguments first. */
+ IRIns *ira = IR(ir->op1);
+ nargs++;
+ while (ira->o == IR_CARG) { nargs++; ira = IR(ira->op1); }
+ }
+#if LJ_HASFFI
+ if (IR(ir->op2)->o == IR_CARG) { /* Copy calling convention info. */
+ CTypeID id = (CTypeID)IR(IR(ir->op2)->op2)->i;
+ CType *ct = ctype_get(ctype_ctsG(J2G(as->J)), id);
+ nargs |= ((ct->info & CTF_VARARG) ? CCI_VARARG : 0);
+#if LJ_TARGET_X86
+ nargs |= (ctype_cconv(ct->info) << CCI_CC_SHIFT);
+#endif
+ }
+#endif
+ return (nargs | (ir->t.irt << CCI_OTSHIFT));
+}
+
+/* Calculate stack adjustment. */
+static int32_t asm_stack_adjust(ASMState *as)
+{
+ if (as->evenspill <= SPS_FIXED)
+ return 0;
+ return sps_scale(sps_align(as->evenspill));
+}
+
+/* Must match with hash*() in lj_tab.c. */
+static uint32_t ir_khash(IRIns *ir)
+{
+ uint32_t lo, hi;
+ if (irt_isstr(ir->t)) {
+ return ir_kstr(ir)->hash;
+ } else if (irt_isnum(ir->t)) {
+ lo = ir_knum(ir)->u32.lo;
+ hi = ir_knum(ir)->u32.hi << 1;
+ } else if (irt_ispri(ir->t)) {
+ lua_assert(!irt_isnil(ir->t));
+ return irt_type(ir->t)-IRT_FALSE;
+ } else {
+ lua_assert(irt_isgcv(ir->t));
+ lo = u32ptr(ir_kgc(ir));
+ hi = lo + HASH_BIAS;
+ }
+ return hashrot(lo, hi);
+}
+
+/* -- Allocations --------------------------------------------------------- */
+
+static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args);
+static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci);
+
+static void asm_snew(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_new];
+ IRRef args[3];
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ir->op1; /* const char *str */
+ args[2] = ir->op2; /* size_t len */
+ as->gcsteps++;
+ asm_setupresult(as, ir, ci); /* GCstr * */
+ asm_gencall(as, ci, args);
+}
+
+static void asm_tnew(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_new1];
+ IRRef args[2];
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ASMREF_TMP1; /* uint32_t ahsize */
+ as->gcsteps++;
+ asm_setupresult(as, ir, ci); /* GCtab * */
+ asm_gencall(as, ci, args);
+ ra_allockreg(as, ir->op1 | (ir->op2 << 24), ra_releasetmp(as, ASMREF_TMP1));
+}
+
+static void asm_tdup(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_dup];
+ IRRef args[2];
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ir->op1; /* const GCtab *kt */
+ as->gcsteps++;
+ asm_setupresult(as, ir, ci); /* GCtab * */
+ asm_gencall(as, ci, args);
+}
+
+static void asm_gc_check(ASMState *as);
+
+/* Explicit GC step. */
+static void asm_gcstep(ASMState *as, IRIns *ir)
+{
+ IRIns *ira;
+ for (ira = IR(as->stopins+1); ira < ir; ira++)
+ if ((ira->o == IR_TNEW || ira->o == IR_TDUP ||
+ (LJ_HASFFI && (ira->o == IR_CNEW || ira->o == IR_CNEWI))) &&
+ ra_used(ira))
+ as->gcsteps++;
+ if (as->gcsteps)
+ asm_gc_check(as);
+ as->gcsteps = 0x80000000; /* Prevent implicit GC check further up. */
+}
+
+/* -- PHI and loop handling ----------------------------------------------- */
+
+/* Break a PHI cycle by renaming to a free register (evict if needed). */
+static void asm_phi_break(ASMState *as, RegSet blocked, RegSet blockedby,
+ RegSet allow)
+{
+ RegSet candidates = blocked & allow;
+ if (candidates) { /* If this register file has candidates. */
+ /* Note: the set for ra_pick cannot be empty, since each register file
+ ** has some registers never allocated to PHIs.
+ */
+ Reg down, up = ra_pick(as, ~blocked & allow); /* Get a free register. */
+ if (candidates & ~blockedby) /* Optimize shifts, else it's a cycle. */
+ candidates = candidates & ~blockedby;
+ down = rset_picktop(candidates); /* Pick candidate PHI register. */
+ ra_rename(as, down, up); /* And rename it to the free register. */
+ }
+}
+
+/* PHI register shuffling.
+**
+** The allocator tries hard to preserve PHI register assignments across
+** the loop body. Most of the time this loop does nothing, since there
+** are no register mismatches.
+**
+** If a register mismatch is detected and ...
+** - the register is currently free: rename it.
+** - the register is blocked by an invariant: restore/remat and rename it.
+** - Otherwise the register is used by another PHI, so mark it as blocked.
+**
+** The renames are order-sensitive, so just retry the loop if a register
+** is marked as blocked, but has been freed in the meantime. A cycle is
+** detected if all of the blocked registers are allocated. To break the
+** cycle rename one of them to a free register and retry.
+**
+** Note that PHI spill slots are kept in sync and don't need to be shuffled.
+*/
+static void asm_phi_shuffle(ASMState *as)
+{
+ RegSet work;
+
+ /* Find and resolve PHI register mismatches. */
+ for (;;) {
+ RegSet blocked = RSET_EMPTY;
+ RegSet blockedby = RSET_EMPTY;
+ RegSet phiset = as->phiset;
+ while (phiset) { /* Check all left PHI operand registers. */
+ Reg r = rset_pickbot(phiset);
+ IRIns *irl = IR(as->phireg[r]);
+ Reg left = irl->r;
+ if (r != left) { /* Mismatch? */
+ if (!rset_test(as->freeset, r)) { /* PHI register blocked? */
+ IRRef ref = regcost_ref(as->cost[r]);
+ /* Blocked by other PHI (w/reg)? */
+ if (!ra_iskref(ref) && irt_ismarked(IR(ref)->t)) {
+ rset_set(blocked, r);
+ if (ra_hasreg(left))
+ rset_set(blockedby, left);
+ left = RID_NONE;
+ } else { /* Otherwise grab register from invariant. */
+ ra_restore(as, ref);
+ checkmclim(as);
+ }
+ }
+ if (ra_hasreg(left)) {
+ ra_rename(as, left, r);
+ checkmclim(as);
+ }
+ }
+ rset_clear(phiset, r);
+ }
+ if (!blocked) break; /* Finished. */
+ if (!(as->freeset & blocked)) { /* Break cycles if none are free. */
+ asm_phi_break(as, blocked, blockedby, RSET_GPR);
+ if (!LJ_SOFTFP) asm_phi_break(as, blocked, blockedby, RSET_FPR);
+ checkmclim(as);
+ } /* Else retry some more renames. */
+ }
+
+ /* Restore/remat invariants whose registers are modified inside the loop. */
+#if !LJ_SOFTFP
+ work = as->modset & ~(as->freeset | as->phiset) & RSET_FPR;
+ while (work) {
+ Reg r = rset_pickbot(work);
+ ra_restore(as, regcost_ref(as->cost[r]));
+ rset_clear(work, r);
+ checkmclim(as);
+ }
+#endif
+ work = as->modset & ~(as->freeset | as->phiset);
+ while (work) {
+ Reg r = rset_pickbot(work);
+ ra_restore(as, regcost_ref(as->cost[r]));
+ rset_clear(work, r);
+ checkmclim(as);
+ }
+
+ /* Allocate and save all unsaved PHI regs and clear marks. */
+ work = as->phiset;
+ while (work) {
+ Reg r = rset_picktop(work);
+ IRRef lref = as->phireg[r];
+ IRIns *ir = IR(lref);
+ if (ra_hasspill(ir->s)) { /* Left PHI gained a spill slot? */
+ irt_clearmark(ir->t); /* Handled here, so clear marker now. */
+ ra_alloc1(as, lref, RID2RSET(r));
+ ra_save(as, ir, r); /* Save to spill slot inside the loop. */
+ checkmclim(as);
+ }
+ rset_clear(work, r);
+ }
+}
+
+/* Copy unsynced left/right PHI spill slots. Rarely needed. */
+static void asm_phi_copyspill(ASMState *as)
+{
+ int need = 0;
+ IRIns *ir;
+ for (ir = IR(as->orignins-1); ir->o == IR_PHI; ir--)
+ if (ra_hasspill(ir->s) && ra_hasspill(IR(ir->op1)->s))
+ need |= irt_isfp(ir->t) ? 2 : 1; /* Unsynced spill slot? */
+ if ((need & 1)) { /* Copy integer spill slots. */
+#if !LJ_TARGET_X86ORX64
+ Reg r = RID_TMP;
+#else
+ Reg r = RID_RET;
+ if ((as->freeset & RSET_GPR))
+ r = rset_pickbot((as->freeset & RSET_GPR));
+ else
+ emit_spload(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP);
+#endif
+ for (ir = IR(as->orignins-1); ir->o == IR_PHI; ir--) {
+ if (ra_hasspill(ir->s)) {
+ IRIns *irl = IR(ir->op1);
+ if (ra_hasspill(irl->s) && !irt_isfp(ir->t)) {
+ emit_spstore(as, irl, r, sps_scale(irl->s));
+ emit_spload(as, ir, r, sps_scale(ir->s));
+ checkmclim(as);
+ }
+ }
+ }
+#if LJ_TARGET_X86ORX64
+ if (!rset_test(as->freeset, r))
+ emit_spstore(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP);
+#endif
+ }
+#if !LJ_SOFTFP
+ if ((need & 2)) { /* Copy FP spill slots. */
+#if LJ_TARGET_X86
+ Reg r = RID_XMM0;
+#else
+ Reg r = RID_FPRET;
+#endif
+ if ((as->freeset & RSET_FPR))
+ r = rset_pickbot((as->freeset & RSET_FPR));
+ if (!rset_test(as->freeset, r))
+ emit_spload(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP);
+ for (ir = IR(as->orignins-1); ir->o == IR_PHI; ir--) {
+ if (ra_hasspill(ir->s)) {
+ IRIns *irl = IR(ir->op1);
+ if (ra_hasspill(irl->s) && irt_isfp(ir->t)) {
+ emit_spstore(as, irl, r, sps_scale(irl->s));
+ emit_spload(as, ir, r, sps_scale(ir->s));
+ checkmclim(as);
+ }
+ }
+ }
+ if (!rset_test(as->freeset, r))
+ emit_spstore(as, IR(regcost_ref(as->cost[r])), r, SPOFS_TMP);
+ }
+#endif
+}
+
+/* Emit renames for left PHIs which are only spilled outside the loop. */
+static void asm_phi_fixup(ASMState *as)
+{
+ RegSet work = as->phiset;
+ while (work) {
+ Reg r = rset_picktop(work);
+ IRRef lref = as->phireg[r];
+ IRIns *ir = IR(lref);
+ if (irt_ismarked(ir->t)) {
+ irt_clearmark(ir->t);
+ /* Left PHI gained a spill slot before the loop? */
+ if (ra_hasspill(ir->s)) {
+ IRRef ren;
+ lj_ir_set(as->J, IRT(IR_RENAME, IRT_NIL), lref, as->loopsnapno);
+ ren = tref_ref(lj_ir_emit(as->J));
+ as->ir = as->T->ir; /* The IR may have been reallocated. */
+ IR(ren)->r = (uint8_t)r;
+ IR(ren)->s = SPS_NONE;
+ }
+ }
+ rset_clear(work, r);
+ }
+}
+
+/* Setup right PHI reference. */
+static void asm_phi(ASMState *as, IRIns *ir)
+{
+ RegSet allow = ((!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR) &
+ ~as->phiset;
+ RegSet afree = (as->freeset & allow);
+ IRIns *irl = IR(ir->op1);
+ IRIns *irr = IR(ir->op2);
+ if (ir->r == RID_SINK) /* Sink PHI. */
+ return;
+ /* Spill slot shuffling is not implemented yet (but rarely needed). */
+ if (ra_hasspill(irl->s) || ra_hasspill(irr->s))
+ lj_trace_err(as->J, LJ_TRERR_NYIPHI);
+ /* Leave at least one register free for non-PHIs (and PHI cycle breaking). */
+ if ((afree & (afree-1))) { /* Two or more free registers? */
+ Reg r;
+ if (ra_noreg(irr->r)) { /* Get a register for the right PHI. */
+ r = ra_allocref(as, ir->op2, allow);
+ } else { /* Duplicate right PHI, need a copy (rare). */
+ r = ra_scratch(as, allow);
+ emit_movrr(as, irr, r, irr->r);
+ }
+ ir->r = (uint8_t)r;
+ rset_set(as->phiset, r);
+ as->phireg[r] = (IRRef1)ir->op1;
+ irt_setmark(irl->t); /* Marks left PHIs _with_ register. */
+ if (ra_noreg(irl->r))
+ ra_sethint(irl->r, r); /* Set register hint for left PHI. */
+ } else { /* Otherwise allocate a spill slot. */
+ /* This is overly restrictive, but it triggers only on synthetic code. */
+ if (ra_hasreg(irl->r) || ra_hasreg(irr->r))
+ lj_trace_err(as->J, LJ_TRERR_NYIPHI);
+ ra_spill(as, ir);
+ irr->s = ir->s; /* Set right PHI spill slot. Sync left slot later. */
+ }
+}
+
+static void asm_loop_fixup(ASMState *as);
+
+/* Middle part of a loop. */
+static void asm_loop(ASMState *as)
+{
+ MCode *mcspill;
+ /* LOOP is a guard, so the snapno is up to date. */
+ as->loopsnapno = as->snapno;
+ if (as->gcsteps)
+ asm_gc_check(as);
+ /* LOOP marks the transition from the variant to the invariant part. */
+ as->flagmcp = as->invmcp = NULL;
+ as->sectref = 0;
+ if (!neverfuse(as)) as->fuseref = 0;
+ asm_phi_shuffle(as);
+ mcspill = as->mcp;
+ asm_phi_copyspill(as);
+ asm_loop_fixup(as);
+ as->mcloop = as->mcp;
+ RA_DBGX((as, "===== LOOP ====="));
+ if (!as->realign) RA_DBG_FLUSH();
+ if (as->mcp != mcspill)
+ emit_jmp(as, mcspill);
+}
+
+/* -- Target-specific assembler ------------------------------------------- */
+
+#if LJ_TARGET_X86ORX64
+#include "lj_asm_x86.h"
+#elif LJ_TARGET_ARM
+#include "lj_asm_arm.h"
+#elif LJ_TARGET_PPC
+#include "lj_asm_ppc.h"
+#elif LJ_TARGET_MIPS
+#include "lj_asm_mips.h"
+#else
+#error "Missing assembler for target CPU"
+#endif
+
+/* -- Head of trace ------------------------------------------------------- */
+
+/* Head of a root trace. */
+static void asm_head_root(ASMState *as)
+{
+ int32_t spadj;
+ asm_head_root_base(as);
+ emit_setvmstate(as, (int32_t)as->T->traceno);
+ spadj = asm_stack_adjust(as);
+ as->T->spadjust = (uint16_t)spadj;
+ emit_spsub(as, spadj);
+ /* Root traces assume a checked stack for the starting proto. */
+ as->T->topslot = gcref(as->T->startpt)->pt.framesize;
+}
+
+/* Head of a side trace.
+**
+** The current simplistic algorithm requires that all slots inherited
+** from the parent are live in a register between pass 2 and pass 3. This
+** avoids the complexity of stack slot shuffling. But of course this may
+** overflow the register set in some cases and cause the dreaded error:
+** "NYI: register coalescing too complex". A refined algorithm is needed.
+*/
+static void asm_head_side(ASMState *as)
+{
+ IRRef1 sloadins[RID_MAX];
+ RegSet allow = RSET_ALL; /* Inverse of all coalesced registers. */
+ RegSet live = RSET_EMPTY; /* Live parent registers. */
+ IRIns *irp = &as->parent->ir[REF_BASE]; /* Parent base. */
+ int32_t spadj, spdelta;
+ int pass2 = 0;
+ int pass3 = 0;
+ IRRef i;
+
+ if (as->snapno && as->topslot > as->parent->topslot) {
+ /* Force snap #0 alloc to prevent register overwrite in stack check. */
+ as->snapno = 0;
+ asm_snap_alloc(as);
+ }
+ allow = asm_head_side_base(as, irp, allow);
+
+ /* Scan all parent SLOADs and collect register dependencies. */
+ for (i = as->stopins; i > REF_BASE; i--) {
+ IRIns *ir = IR(i);
+ RegSP rs;
+ lua_assert((ir->o == IR_SLOAD && (ir->op2 & IRSLOAD_PARENT)) ||
+ (LJ_SOFTFP && ir->o == IR_HIOP) || ir->o == IR_PVAL);
+ rs = as->parentmap[i - REF_FIRST];
+ if (ra_hasreg(ir->r)) {
+ rset_clear(allow, ir->r);
+ if (ra_hasspill(ir->s)) {
+ ra_save(as, ir, ir->r);
+ checkmclim(as);
+ }
+ } else if (ra_hasspill(ir->s)) {
+ irt_setmark(ir->t);
+ pass2 = 1;
+ }
+ if (ir->r == rs) { /* Coalesce matching registers right now. */
+ ra_free(as, ir->r);
+ } else if (ra_hasspill(regsp_spill(rs))) {
+ if (ra_hasreg(ir->r))
+ pass3 = 1;
+ } else if (ra_used(ir)) {
+ sloadins[rs] = (IRRef1)i;
+ rset_set(live, rs); /* Block live parent register. */
+ }
+ }
+
+ /* Calculate stack frame adjustment. */
+ spadj = asm_stack_adjust(as);
+ spdelta = spadj - (int32_t)as->parent->spadjust;
+ if (spdelta < 0) { /* Don't shrink the stack frame. */
+ spadj = (int32_t)as->parent->spadjust;
+ spdelta = 0;
+ }
+ as->T->spadjust = (uint16_t)spadj;
+
+ /* Reload spilled target registers. */
+ if (pass2) {
+ for (i = as->stopins; i > REF_BASE; i--) {
+ IRIns *ir = IR(i);
+ if (irt_ismarked(ir->t)) {
+ RegSet mask;
+ Reg r;
+ RegSP rs;
+ irt_clearmark(ir->t);
+ rs = as->parentmap[i - REF_FIRST];
+ if (!ra_hasspill(regsp_spill(rs)))
+ ra_sethint(ir->r, rs); /* Hint may be gone, set it again. */
+ else if (sps_scale(regsp_spill(rs))+spdelta == sps_scale(ir->s))
+ continue; /* Same spill slot, do nothing. */
+ mask = ((!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR) & allow;
+ if (mask == RSET_EMPTY)
+ lj_trace_err(as->J, LJ_TRERR_NYICOAL);
+ r = ra_allocref(as, i, mask);
+ ra_save(as, ir, r);
+ rset_clear(allow, r);
+ if (r == rs) { /* Coalesce matching registers right now. */
+ ra_free(as, r);
+ rset_clear(live, r);
+ } else if (ra_hasspill(regsp_spill(rs))) {
+ pass3 = 1;
+ }
+ checkmclim(as);
+ }
+ }
+ }
+
+ /* Store trace number and adjust stack frame relative to the parent. */
+ emit_setvmstate(as, (int32_t)as->T->traceno);
+ emit_spsub(as, spdelta);
+
+#if !LJ_TARGET_X86ORX64
+ /* Restore BASE register from parent spill slot. */
+ if (ra_hasspill(irp->s))
+ emit_spload(as, IR(REF_BASE), IR(REF_BASE)->r, sps_scale(irp->s));
+#endif
+
+ /* Restore target registers from parent spill slots. */
+ if (pass3) {
+ RegSet work = ~as->freeset & RSET_ALL;
+ while (work) {
+ Reg r = rset_pickbot(work);
+ IRRef ref = regcost_ref(as->cost[r]);
+ RegSP rs = as->parentmap[ref - REF_FIRST];
+ rset_clear(work, r);
+ if (ra_hasspill(regsp_spill(rs))) {
+ int32_t ofs = sps_scale(regsp_spill(rs));
+ ra_free(as, r);
+ emit_spload(as, IR(ref), r, ofs);
+ checkmclim(as);
+ }
+ }
+ }
+
+ /* Shuffle registers to match up target regs with parent regs. */
+ for (;;) {
+ RegSet work;
+
+ /* Repeatedly coalesce free live registers by moving to their target. */
+ while ((work = as->freeset & live) != RSET_EMPTY) {
+ Reg rp = rset_pickbot(work);
+ IRIns *ir = IR(sloadins[rp]);
+ rset_clear(live, rp);
+ rset_clear(allow, rp);
+ ra_free(as, ir->r);
+ emit_movrr(as, ir, ir->r, rp);
+ checkmclim(as);
+ }
+
+ /* We're done if no live registers remain. */
+ if (live == RSET_EMPTY)
+ break;
+
+ /* Break cycles by renaming one target to a temp. register. */
+ if (live & RSET_GPR) {
+ RegSet tmpset = as->freeset & ~live & allow & RSET_GPR;
+ if (tmpset == RSET_EMPTY)
+ lj_trace_err(as->J, LJ_TRERR_NYICOAL);
+ ra_rename(as, rset_pickbot(live & RSET_GPR), rset_pickbot(tmpset));
+ }
+ if (!LJ_SOFTFP && (live & RSET_FPR)) {
+ RegSet tmpset = as->freeset & ~live & allow & RSET_FPR;
+ if (tmpset == RSET_EMPTY)
+ lj_trace_err(as->J, LJ_TRERR_NYICOAL);
+ ra_rename(as, rset_pickbot(live & RSET_FPR), rset_pickbot(tmpset));
+ }
+ checkmclim(as);
+ /* Continue with coalescing to fix up the broken cycle(s). */
+ }
+
+ /* Inherit top stack slot already checked by parent trace. */
+ as->T->topslot = as->parent->topslot;
+ if (as->topslot > as->T->topslot) { /* Need to check for higher slot? */
+#ifdef EXITSTATE_CHECKEXIT
+ /* Highest exit + 1 indicates stack check. */
+ ExitNo exitno = as->T->nsnap;
+#else
+ /* Reuse the parent exit in the context of the parent trace. */
+ ExitNo exitno = as->J->exitno;
+#endif
+ as->T->topslot = (uint8_t)as->topslot; /* Remember for child traces. */
+ asm_stack_check(as, as->topslot, irp, allow & RSET_GPR, exitno);
+ }
+}
+
+/* -- Tail of trace ------------------------------------------------------- */
+
+/* Get base slot for a snapshot. */
+static BCReg asm_baseslot(ASMState *as, SnapShot *snap, int *gotframe)
+{
+ SnapEntry *map = &as->T->snapmap[snap->mapofs];
+ MSize n;
+ for (n = snap->nent; n > 0; n--) {
+ SnapEntry sn = map[n-1];
+ if ((sn & SNAP_FRAME)) {
+ *gotframe = 1;
+ return snap_slot(sn);
+ }
+ }
+ return 0;
+}
+
+/* Link to another trace. */
+static void asm_tail_link(ASMState *as)
+{
+ SnapNo snapno = as->T->nsnap-1; /* Last snapshot. */
+ SnapShot *snap = &as->T->snap[snapno];
+ int gotframe = 0;
+ BCReg baseslot = asm_baseslot(as, snap, &gotframe);
+
+ as->topslot = snap->topslot;
+ checkmclim(as);
+ ra_allocref(as, REF_BASE, RID2RSET(RID_BASE));
+
+ if (as->T->link == 0) {
+ /* Setup fixed registers for exit to interpreter. */
+ const BCIns *pc = snap_pc(as->T->snapmap[snap->mapofs + snap->nent]);
+ int32_t mres;
+ if (bc_op(*pc) == BC_JLOOP) { /* NYI: find a better way to do this. */
+ BCIns *retpc = &traceref(as->J, bc_d(*pc))->startins;
+ if (bc_isret(bc_op(*retpc)))
+ pc = retpc;
+ }
+ ra_allockreg(as, i32ptr(J2GG(as->J)->dispatch), RID_DISPATCH);
+ ra_allockreg(as, i32ptr(pc), RID_LPC);
+ mres = (int32_t)(snap->nslots - baseslot);
+ switch (bc_op(*pc)) {
+ case BC_CALLM: case BC_CALLMT:
+ mres -= (int32_t)(1 + bc_a(*pc) + bc_c(*pc)); break;
+ case BC_RETM: mres -= (int32_t)(bc_a(*pc) + bc_d(*pc)); break;
+ case BC_TSETM: mres -= (int32_t)bc_a(*pc); break;
+ default: if (bc_op(*pc) < BC_FUNCF) mres = 0; break;
+ }
+ ra_allockreg(as, mres, RID_RET); /* Return MULTRES or 0. */
+ } else if (baseslot) {
+ /* Save modified BASE for linking to trace with higher start frame. */
+ emit_setgl(as, RID_BASE, jit_base);
+ }
+ emit_addptr(as, RID_BASE, 8*(int32_t)baseslot);
+
+ /* Sync the interpreter state with the on-trace state. */
+ asm_stack_restore(as, snap);
+
+ /* Root traces that add frames need to check the stack at the end. */
+ if (!as->parent && gotframe)
+ asm_stack_check(as, as->topslot, NULL, as->freeset & RSET_GPR, snapno);
+}
+
+/* -- Trace setup --------------------------------------------------------- */
+
+/* Clear reg/sp for all instructions and add register hints. */
+static void asm_setup_regsp(ASMState *as)
+{
+ GCtrace *T = as->T;
+ int sink = T->sinktags;
+ IRRef nins = T->nins;
+ IRIns *ir, *lastir;
+ int inloop;
+#if LJ_TARGET_ARM
+ uint32_t rload = 0xa6402a64;
+#endif
+
+ ra_setup(as);
+
+ /* Clear reg/sp for constants. */
+ for (ir = IR(T->nk), lastir = IR(REF_BASE); ir < lastir; ir++)
+ ir->prev = REGSP_INIT;
+
+ /* REF_BASE is used for implicit references to the BASE register. */
+ lastir->prev = REGSP_HINT(RID_BASE);
+
+ ir = IR(nins-1);
+ if (ir->o == IR_RENAME) {
+ do { ir--; nins--; } while (ir->o == IR_RENAME);
+ T->nins = nins; /* Remove any renames left over from ASM restart. */
+ }
+ as->snaprename = nins;
+ as->snapref = nins;
+ as->snapno = T->nsnap;
+
+ as->stopins = REF_BASE;
+ as->orignins = nins;
+ as->curins = nins;
+
+ /* Setup register hints for parent link instructions. */
+ ir = IR(REF_FIRST);
+ if (as->parent) {
+ uint16_t *p;
+ lastir = lj_snap_regspmap(as->parent, as->J->exitno, ir);
+ if (lastir - ir > LJ_MAX_JSLOTS)
+ lj_trace_err(as->J, LJ_TRERR_NYICOAL);
+ as->stopins = (IRRef)((lastir-1) - as->ir);
+ for (p = as->parentmap; ir < lastir; ir++) {
+ RegSP rs = ir->prev;
+ *p++ = (uint16_t)rs; /* Copy original parent RegSP to parentmap. */
+ if (!ra_hasspill(regsp_spill(rs)))
+ ir->prev = (uint16_t)REGSP_HINT(regsp_reg(rs));
+ else
+ ir->prev = REGSP_INIT;
+ }
+ }
+
+ inloop = 0;
+ as->evenspill = SPS_FIRST;
+ for (lastir = IR(nins); ir < lastir; ir++) {
+ if (sink) {
+ if (ir->r == RID_SINK)
+ continue;
+ if (ir->r == RID_SUNK) { /* Revert after ASM restart. */
+ ir->r = RID_SINK;
+ continue;
+ }
+ }
+ switch (ir->o) {
+ case IR_LOOP:
+ inloop = 1;
+ break;
+#if LJ_TARGET_ARM
+ case IR_SLOAD:
+ if (!((ir->op2 & IRSLOAD_TYPECHECK) || (ir+1)->o == IR_HIOP))
+ break;
+ /* fallthrough */
+ case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:
+ if (!LJ_SOFTFP && irt_isnum(ir->t)) break;
+ ir->prev = (uint16_t)REGSP_HINT((rload & 15));
+ rload = lj_ror(rload, 4);
+ continue;
+#endif
+ case IR_CALLXS: {
+ CCallInfo ci;
+ ci.flags = asm_callx_flags(as, ir);
+ ir->prev = asm_setup_call_slots(as, ir, &ci);
+ if (inloop)
+ as->modset |= RSET_SCRATCH;
+ continue;
+ }
+ case IR_CALLN: case IR_CALLL: case IR_CALLS: {
+ const CCallInfo *ci = &lj_ir_callinfo[ir->op2];
+ ir->prev = asm_setup_call_slots(as, ir, ci);
+ if (inloop)
+ as->modset |= (ci->flags & CCI_NOFPRCLOBBER) ?
+ (RSET_SCRATCH & ~RSET_FPR) : RSET_SCRATCH;
+ continue;
+ }
+#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI)
+ case IR_HIOP:
+ switch ((ir-1)->o) {
+#if LJ_SOFTFP && LJ_TARGET_ARM
+ case IR_SLOAD: case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:
+ if (ra_hashint((ir-1)->r)) {
+ ir->prev = (ir-1)->prev + 1;
+ continue;
+ }
+ break;
+#endif
+#if !LJ_SOFTFP && LJ_NEED_FP64
+ case IR_CONV:
+ if (irt_isfp((ir-1)->t)) {
+ ir->prev = REGSP_HINT(RID_FPRET);
+ continue;
+ }
+ /* fallthrough */
+#endif
+ case IR_CALLN: case IR_CALLXS:
+#if LJ_SOFTFP
+ case IR_MIN: case IR_MAX:
+#endif
+ (ir-1)->prev = REGSP_HINT(RID_RETLO);
+ ir->prev = REGSP_HINT(RID_RETHI);
+ continue;
+ default:
+ break;
+ }
+ break;
+#endif
+#if LJ_SOFTFP
+ case IR_MIN: case IR_MAX:
+ if ((ir+1)->o != IR_HIOP) break;
+ /* fallthrough */
+#endif
+ /* C calls evict all scratch regs and return results in RID_RET. */
+ case IR_SNEW: case IR_XSNEW: case IR_NEWREF:
+ if (REGARG_NUMGPR < 3 && as->evenspill < 3)
+ as->evenspill = 3; /* lj_str_new and lj_tab_newkey need 3 args. */
+ /* fallthrough */
+ case IR_TNEW: case IR_TDUP: case IR_CNEW: case IR_CNEWI: case IR_TOSTR:
+ ir->prev = REGSP_HINT(RID_RET);
+ if (inloop)
+ as->modset = RSET_SCRATCH;
+ continue;
+ case IR_STRTO: case IR_OBAR:
+ if (inloop)
+ as->modset = RSET_SCRATCH;
+ break;
+#if !LJ_TARGET_X86ORX64 && !LJ_SOFTFP
+ case IR_ATAN2: case IR_LDEXP:
+#endif
+ case IR_POW:
+ if (!LJ_SOFTFP && irt_isnum(ir->t)) {
+#if LJ_TARGET_X86ORX64
+ ir->prev = REGSP_HINT(RID_XMM0);
+ if (inloop)
+ as->modset |= RSET_RANGE(RID_XMM0, RID_XMM1+1)|RID2RSET(RID_EAX);
+#else
+ ir->prev = REGSP_HINT(RID_FPRET);
+ if (inloop)
+ as->modset |= RSET_SCRATCH;
+#endif
+ continue;
+ }
+ /* fallthrough */ /* for integer POW */
+ case IR_DIV: case IR_MOD:
+ if (!irt_isnum(ir->t)) {
+ ir->prev = REGSP_HINT(RID_RET);
+ if (inloop)
+ as->modset |= (RSET_SCRATCH & RSET_GPR);
+ continue;
+ }
+ break;
+ case IR_FPMATH:
+#if LJ_TARGET_X86ORX64
+ if (ir->op2 == IRFPM_EXP2) { /* May be joined to lj_vm_pow_sse. */
+ ir->prev = REGSP_HINT(RID_XMM0);
+#if !LJ_64
+ if (as->evenspill < 4) /* Leave room for 16 byte scratch area. */
+ as->evenspill = 4;
+#endif
+ if (inloop)
+ as->modset |= RSET_RANGE(RID_XMM0, RID_XMM2+1)|RID2RSET(RID_EAX);
+ continue;
+ } else if (ir->op2 <= IRFPM_TRUNC && !(as->flags & JIT_F_SSE4_1)) {
+ ir->prev = REGSP_HINT(RID_XMM0);
+ if (inloop)
+ as->modset |= RSET_RANGE(RID_XMM0, RID_XMM3+1)|RID2RSET(RID_EAX);
+ continue;
+ }
+ break;
+#else
+ ir->prev = REGSP_HINT(RID_FPRET);
+ if (inloop)
+ as->modset |= RSET_SCRATCH;
+ continue;
+#endif
+#if LJ_TARGET_X86ORX64
+ /* Non-constant shift counts need to be in RID_ECX on x86/x64. */
+ case IR_BSHL: case IR_BSHR: case IR_BSAR: case IR_BROL: case IR_BROR:
+ if (!irref_isk(ir->op2) && !ra_hashint(IR(ir->op2)->r)) {
+ IR(ir->op2)->r = REGSP_HINT(RID_ECX);
+ if (inloop)
+ rset_set(as->modset, RID_ECX);
+ }
+ break;
+#endif
+ /* Do not propagate hints across type conversions or loads. */
+ case IR_TOBIT:
+ case IR_XLOAD:
+#if !LJ_TARGET_ARM
+ case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:
+#endif
+ break;
+ case IR_CONV:
+ if (irt_isfp(ir->t) || (ir->op2 & IRCONV_SRCMASK) == IRT_NUM ||
+ (ir->op2 & IRCONV_SRCMASK) == IRT_FLOAT)
+ break;
+ /* fallthrough */
+ default:
+ /* Propagate hints across likely 'op reg, imm' or 'op reg'. */
+ if (irref_isk(ir->op2) && !irref_isk(ir->op1) &&
+ ra_hashint(regsp_reg(IR(ir->op1)->prev))) {
+ ir->prev = IR(ir->op1)->prev;
+ continue;
+ }
+ break;
+ }
+ ir->prev = REGSP_INIT;
+ }
+ if ((as->evenspill & 1))
+ as->oddspill = as->evenspill++;
+ else
+ as->oddspill = 0;
+}
+
+/* -- Assembler core ------------------------------------------------------ */
+
+/* Assemble a trace. */
+void lj_asm_trace(jit_State *J, GCtrace *T)
+{
+ ASMState as_;
+ ASMState *as = &as_;
+ MCode *origtop;
+
+ /* Ensure an initialized instruction beyond the last one for HIOP checks. */
+ J->cur.nins = lj_ir_nextins(J);
+ J->cur.ir[J->cur.nins].o = IR_NOP;
+
+ /* Setup initial state. Copy some fields to reduce indirections. */
+ as->J = J;
+ as->T = T;
+ as->ir = T->ir;
+ as->flags = J->flags;
+ as->loopref = J->loopref;
+ as->realign = NULL;
+ as->loopinv = 0;
+ as->parent = J->parent ? traceref(J, J->parent) : NULL;
+
+ /* Reserve MCode memory. */
+ as->mctop = origtop = lj_mcode_reserve(J, &as->mcbot);
+ as->mcp = as->mctop;
+ as->mclim = as->mcbot + MCLIM_REDZONE;
+ asm_setup_target(as);
+
+ do {
+ as->mcp = as->mctop;
+#ifdef LUA_USE_ASSERT
+ as->mcp_prev = as->mcp;
+#endif
+ as->curins = T->nins;
+ RA_DBG_START();
+ RA_DBGX((as, "===== STOP ====="));
+
+ /* General trace setup. Emit tail of trace. */
+ asm_tail_prep(as);
+ as->mcloop = NULL;
+ as->flagmcp = NULL;
+ as->topslot = 0;
+ as->gcsteps = 0;
+ as->sectref = as->loopref;
+ as->fuseref = (as->flags & JIT_F_OPT_FUSE) ? as->loopref : FUSE_DISABLED;
+ asm_setup_regsp(as);
+ if (!as->loopref)
+ asm_tail_link(as);
+
+ /* Assemble a trace in linear backwards order. */
+ for (as->curins--; as->curins > as->stopins; as->curins--) {
+ IRIns *ir = IR(as->curins);
+ lua_assert(!(LJ_32 && irt_isint64(ir->t))); /* Handled by SPLIT. */
+ if (!ra_used(ir) && !ir_sideeff(ir) && (as->flags & JIT_F_OPT_DCE))
+ continue; /* Dead-code elimination can be soooo easy. */
+ if (irt_isguard(ir->t))
+ asm_snap_prep(as);
+ RA_DBG_REF();
+ checkmclim(as);
+ asm_ir(as, ir);
+ }
+ } while (as->realign); /* Retry in case the MCode needs to be realigned. */
+
+ /* Emit head of trace. */
+ RA_DBG_REF();
+ checkmclim(as);
+ if (as->gcsteps > 0) {
+ as->curins = as->T->snap[0].ref;
+ asm_snap_prep(as); /* The GC check is a guard. */
+ asm_gc_check(as);
+ }
+ ra_evictk(as);
+ if (as->parent)
+ asm_head_side(as);
+ else
+ asm_head_root(as);
+ asm_phi_fixup(as);
+
+ RA_DBGX((as, "===== START ===="));
+ RA_DBG_FLUSH();
+ if (as->freeset != RSET_ALL)
+ lj_trace_err(as->J, LJ_TRERR_BADRA); /* Ouch! Should never happen. */
+
+ /* Set trace entry point before fixing up tail to allow link to self. */
+ T->mcode = as->mcp;
+ T->mcloop = as->mcloop ? (MSize)((char *)as->mcloop - (char *)as->mcp) : 0;
+ if (!as->loopref)
+ asm_tail_fixup(as, T->link); /* Note: this may change as->mctop! */
+ T->szmcode = (MSize)((char *)as->mctop - (char *)as->mcp);
+ lj_mcode_sync(T->mcode, origtop);
+}
+
+#undef IR
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_asm.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_asm.h
new file mode 100644
index 0000000..2819481
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_asm.h
@@ -0,0 +1,17 @@
+/*
+** IR assembler (SSA IR -> machine code).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_ASM_H
+#define _LJ_ASM_H
+
+#include "lj_jit.h"
+
+#if LJ_HASJIT
+LJ_FUNC void lj_asm_trace(jit_State *J, GCtrace *T);
+LJ_FUNC void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno,
+ MCode *target);
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_asm_arm.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_asm_arm.h
new file mode 100644
index 0000000..961f7e3
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_asm_arm.h
@@ -0,0 +1,2360 @@
+/*
+** ARM IR assembler (SSA IR -> machine code).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* -- Register allocator extensions --------------------------------------- */
+
+/* Allocate a register with a hint. */
+static Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow)
+{
+ Reg r = IR(ref)->r;
+ if (ra_noreg(r)) {
+ if (!ra_hashint(r) && !iscrossref(as, ref))
+ ra_sethint(IR(ref)->r, hint); /* Propagate register hint. */
+ r = ra_allocref(as, ref, allow);
+ }
+ ra_noweak(as, r);
+ return r;
+}
+
+/* Allocate a scratch register pair. */
+static Reg ra_scratchpair(ASMState *as, RegSet allow)
+{
+ RegSet pick1 = as->freeset & allow;
+ RegSet pick2 = pick1 & (pick1 >> 1) & RSET_GPREVEN;
+ Reg r;
+ if (pick2) {
+ r = rset_picktop(pick2);
+ } else {
+ RegSet pick = pick1 & (allow >> 1) & RSET_GPREVEN;
+ if (pick) {
+ r = rset_picktop(pick);
+ ra_restore(as, regcost_ref(as->cost[r+1]));
+ } else {
+ pick = pick1 & (allow << 1) & RSET_GPRODD;
+ if (pick) {
+ r = ra_restore(as, regcost_ref(as->cost[rset_picktop(pick)-1]));
+ } else {
+ r = ra_evict(as, allow & (allow >> 1) & RSET_GPREVEN);
+ ra_restore(as, regcost_ref(as->cost[r+1]));
+ }
+ }
+ }
+ lua_assert(rset_test(RSET_GPREVEN, r));
+ ra_modified(as, r);
+ ra_modified(as, r+1);
+ RA_DBGX((as, "scratchpair $r $r", r, r+1));
+ return r;
+}
+
+#if !LJ_SOFTFP
+/* Allocate two source registers for three-operand instructions. */
+static Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow)
+{
+ IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);
+ Reg left = irl->r, right = irr->r;
+ if (ra_hasreg(left)) {
+ ra_noweak(as, left);
+ if (ra_noreg(right))
+ right = ra_allocref(as, ir->op2, rset_exclude(allow, left));
+ else
+ ra_noweak(as, right);
+ } else if (ra_hasreg(right)) {
+ ra_noweak(as, right);
+ left = ra_allocref(as, ir->op1, rset_exclude(allow, right));
+ } else if (ra_hashint(right)) {
+ right = ra_allocref(as, ir->op2, allow);
+ left = ra_alloc1(as, ir->op1, rset_exclude(allow, right));
+ } else {
+ left = ra_allocref(as, ir->op1, allow);
+ right = ra_alloc1(as, ir->op2, rset_exclude(allow, left));
+ }
+ return left | (right << 8);
+}
+#endif
+
+/* -- Guard handling ------------------------------------------------------ */
+
+/* Generate an exit stub group at the bottom of the reserved MCode memory. */
+static MCode *asm_exitstub_gen(ASMState *as, ExitNo group)
+{
+ MCode *mxp = as->mcbot;
+ int i;
+ if (mxp + 4*4+4*EXITSTUBS_PER_GROUP >= as->mctop)
+ asm_mclimit(as);
+ /* str lr, [sp]; bl ->vm_exit_handler; .long DISPATCH_address, group. */
+ *mxp++ = ARMI_STR|ARMI_LS_P|ARMI_LS_U|ARMF_D(RID_LR)|ARMF_N(RID_SP);
+ *mxp = ARMI_BL|((((MCode *)(void *)lj_vm_exit_handler-mxp)-2)&0x00ffffffu);
+ mxp++;
+ *mxp++ = (MCode)i32ptr(J2GG(as->J)->dispatch); /* DISPATCH address */
+ *mxp++ = group*EXITSTUBS_PER_GROUP;
+ for (i = 0; i < EXITSTUBS_PER_GROUP; i++)
+ *mxp++ = ARMI_B|((-6-i)&0x00ffffffu);
+ lj_mcode_sync(as->mcbot, mxp);
+ lj_mcode_commitbot(as->J, mxp);
+ as->mcbot = mxp;
+ as->mclim = as->mcbot + MCLIM_REDZONE;
+ return mxp - EXITSTUBS_PER_GROUP;
+}
+
+/* Setup all needed exit stubs. */
+static void asm_exitstub_setup(ASMState *as, ExitNo nexits)
+{
+ ExitNo i;
+ if (nexits >= EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR)
+ lj_trace_err(as->J, LJ_TRERR_SNAPOV);
+ for (i = 0; i < (nexits+EXITSTUBS_PER_GROUP-1)/EXITSTUBS_PER_GROUP; i++)
+ if (as->J->exitstubgroup[i] == NULL)
+ as->J->exitstubgroup[i] = asm_exitstub_gen(as, i);
+}
+
+/* Emit conditional branch to exit for guard. */
+static void asm_guardcc(ASMState *as, ARMCC cc)
+{
+ MCode *target = exitstub_addr(as->J, as->snapno);
+ MCode *p = as->mcp;
+ if (LJ_UNLIKELY(p == as->invmcp)) {
+ as->loopinv = 1;
+ *p = ARMI_BL | ((target-p-2) & 0x00ffffffu);
+ emit_branch(as, ARMF_CC(ARMI_B, cc^1), p+1);
+ return;
+ }
+ emit_branch(as, ARMF_CC(ARMI_BL, cc), target);
+}
+
+/* -- Operand fusion ------------------------------------------------------ */
+
+/* Limit linear search to this distance. Avoids O(n^2) behavior. */
+#define CONFLICT_SEARCH_LIM 31
+
+/* Check if there's no conflicting instruction between curins and ref. */
+static int noconflict(ASMState *as, IRRef ref, IROp conflict)
+{
+ IRIns *ir = as->ir;
+ IRRef i = as->curins;
+ if (i > ref + CONFLICT_SEARCH_LIM)
+ return 0; /* Give up, ref is too far away. */
+ while (--i > ref)
+ if (ir[i].o == conflict)
+ return 0; /* Conflict found. */
+ return 1; /* Ok, no conflict. */
+}
+
+/* Fuse the array base of colocated arrays. */
+static int32_t asm_fuseabase(ASMState *as, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE &&
+ !neverfuse(as) && noconflict(as, ref, IR_NEWREF))
+ return (int32_t)sizeof(GCtab);
+ return 0;
+}
+
+/* Fuse array/hash/upvalue reference into register+offset operand. */
+static Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow,
+ int lim)
+{
+ IRIns *ir = IR(ref);
+ if (ra_noreg(ir->r)) {
+ if (ir->o == IR_AREF) {
+ if (mayfuse(as, ref)) {
+ if (irref_isk(ir->op2)) {
+ IRRef tab = IR(ir->op1)->op1;
+ int32_t ofs = asm_fuseabase(as, tab);
+ IRRef refa = ofs ? tab : ir->op1;
+ ofs += 8*IR(ir->op2)->i;
+ if (ofs > -lim && ofs < lim) {
+ *ofsp = ofs;
+ return ra_alloc1(as, refa, allow);
+ }
+ }
+ }
+ } else if (ir->o == IR_HREFK) {
+ if (mayfuse(as, ref)) {
+ int32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node));
+ if (ofs < lim) {
+ *ofsp = ofs;
+ return ra_alloc1(as, ir->op1, allow);
+ }
+ }
+ } else if (ir->o == IR_UREFC) {
+ if (irref_isk(ir->op1)) {
+ GCfunc *fn = ir_kfunc(IR(ir->op1));
+ int32_t ofs = i32ptr(&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv);
+ *ofsp = (ofs & 255); /* Mask out less bits to allow LDRD. */
+ return ra_allock(as, (ofs & ~255), allow);
+ }
+ }
+ }
+ *ofsp = 0;
+ return ra_alloc1(as, ref, allow);
+}
+
+/* Fuse m operand into arithmetic/logic instructions. */
+static uint32_t asm_fuseopm(ASMState *as, ARMIns ai, IRRef ref, RegSet allow)
+{
+ IRIns *ir = IR(ref);
+ if (ra_hasreg(ir->r)) {
+ ra_noweak(as, ir->r);
+ return ARMF_M(ir->r);
+ } else if (irref_isk(ref)) {
+ uint32_t k = emit_isk12(ai, ir->i);
+ if (k)
+ return k;
+ } else if (mayfuse(as, ref)) {
+ if (ir->o >= IR_BSHL && ir->o <= IR_BROR) {
+ Reg m = ra_alloc1(as, ir->op1, allow);
+ ARMShift sh = ir->o == IR_BSHL ? ARMSH_LSL :
+ ir->o == IR_BSHR ? ARMSH_LSR :
+ ir->o == IR_BSAR ? ARMSH_ASR : ARMSH_ROR;
+ if (irref_isk(ir->op2)) {
+ return m | ARMF_SH(sh, (IR(ir->op2)->i & 31));
+ } else {
+ Reg s = ra_alloc1(as, ir->op2, rset_exclude(allow, m));
+ return m | ARMF_RSH(sh, s);
+ }
+ } else if (ir->o == IR_ADD && ir->op1 == ir->op2) {
+ Reg m = ra_alloc1(as, ir->op1, allow);
+ return m | ARMF_SH(ARMSH_LSL, 1);
+ }
+ }
+ return ra_allocref(as, ref, allow);
+}
+
+/* Fuse shifts into loads/stores. Only bother with BSHL 2 => lsl #2. */
+static IRRef asm_fuselsl2(ASMState *as, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ if (ra_noreg(ir->r) && mayfuse(as, ref) && ir->o == IR_BSHL &&
+ irref_isk(ir->op2) && IR(ir->op2)->i == 2)
+ return ir->op1;
+ return 0; /* No fusion. */
+}
+
+/* Fuse XLOAD/XSTORE reference into load/store operand. */
+static void asm_fusexref(ASMState *as, ARMIns ai, Reg rd, IRRef ref,
+ RegSet allow, int32_t ofs)
+{
+ IRIns *ir = IR(ref);
+ Reg base;
+ if (ra_noreg(ir->r) && canfuse(as, ir)) {
+ int32_t lim = (!LJ_SOFTFP && (ai & 0x08000000)) ? 1024 :
+ (ai & 0x04000000) ? 4096 : 256;
+ if (ir->o == IR_ADD) {
+ int32_t ofs2;
+ if (irref_isk(ir->op2) &&
+ (ofs2 = ofs + IR(ir->op2)->i) > -lim && ofs2 < lim &&
+ (!(!LJ_SOFTFP && (ai & 0x08000000)) || !(ofs2 & 3))) {
+ ofs = ofs2;
+ ref = ir->op1;
+ } else if (ofs == 0 && !(!LJ_SOFTFP && (ai & 0x08000000))) {
+ IRRef lref = ir->op1, rref = ir->op2;
+ Reg rn, rm;
+ if ((ai & 0x04000000)) {
+ IRRef sref = asm_fuselsl2(as, rref);
+ if (sref) {
+ rref = sref;
+ ai |= ARMF_SH(ARMSH_LSL, 2);
+ } else if ((sref = asm_fuselsl2(as, lref)) != 0) {
+ lref = rref;
+ rref = sref;
+ ai |= ARMF_SH(ARMSH_LSL, 2);
+ }
+ }
+ rn = ra_alloc1(as, lref, allow);
+ rm = ra_alloc1(as, rref, rset_exclude(allow, rn));
+ if ((ai & 0x04000000)) ai |= ARMI_LS_R;
+ emit_dnm(as, ai|ARMI_LS_P|ARMI_LS_U, rd, rn, rm);
+ return;
+ }
+ } else if (ir->o == IR_STRREF && !(!LJ_SOFTFP && (ai & 0x08000000))) {
+ lua_assert(ofs == 0);
+ ofs = (int32_t)sizeof(GCstr);
+ if (irref_isk(ir->op2)) {
+ ofs += IR(ir->op2)->i;
+ ref = ir->op1;
+ } else if (irref_isk(ir->op1)) {
+ ofs += IR(ir->op1)->i;
+ ref = ir->op2;
+ } else {
+ /* NYI: Fuse ADD with constant. */
+ Reg rn = ra_alloc1(as, ir->op1, allow);
+ uint32_t m = asm_fuseopm(as, 0, ir->op2, rset_exclude(allow, rn));
+ if ((ai & 0x04000000))
+ emit_lso(as, ai, rd, rd, ofs);
+ else
+ emit_lsox(as, ai, rd, rd, ofs);
+ emit_dn(as, ARMI_ADD^m, rd, rn);
+ return;
+ }
+ if (ofs <= -lim || ofs >= lim) {
+ Reg rn = ra_alloc1(as, ref, allow);
+ Reg rm = ra_allock(as, ofs, rset_exclude(allow, rn));
+ if ((ai & 0x04000000)) ai |= ARMI_LS_R;
+ emit_dnm(as, ai|ARMI_LS_P|ARMI_LS_U, rd, rn, rm);
+ return;
+ }
+ }
+ }
+ base = ra_alloc1(as, ref, allow);
+#if !LJ_SOFTFP
+ if ((ai & 0x08000000))
+ emit_vlso(as, ai, rd, base, ofs);
+ else
+#endif
+ if ((ai & 0x04000000))
+ emit_lso(as, ai, rd, base, ofs);
+ else
+ emit_lsox(as, ai, rd, base, ofs);
+}
+
+#if !LJ_SOFTFP
+/* Fuse to multiply-add/sub instruction. */
+static int asm_fusemadd(ASMState *as, IRIns *ir, ARMIns ai, ARMIns air)
+{
+ IRRef lref = ir->op1, rref = ir->op2;
+ IRIns *irm;
+ if (lref != rref &&
+ ((mayfuse(as, lref) && (irm = IR(lref), irm->o == IR_MUL) &&
+ ra_noreg(irm->r)) ||
+ (mayfuse(as, rref) && (irm = IR(rref), irm->o == IR_MUL) &&
+ (rref = lref, ai = air, ra_noreg(irm->r))))) {
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg add = ra_hintalloc(as, rref, dest, RSET_FPR);
+ Reg right, left = ra_alloc2(as, irm,
+ rset_exclude(rset_exclude(RSET_FPR, dest), add));
+ right = (left >> 8); left &= 255;
+ emit_dnm(as, ai, (dest & 15), (left & 15), (right & 15));
+ if (dest != add) emit_dm(as, ARMI_VMOV_D, (dest & 15), (add & 15));
+ return 1;
+ }
+ return 0;
+}
+#endif
+
+/* -- Calls --------------------------------------------------------------- */
+
+/* Generate a call to a C function. */
+static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)
+{
+ uint32_t n, nargs = CCI_NARGS(ci);
+ int32_t ofs = 0;
+#if LJ_SOFTFP
+ Reg gpr = REGARG_FIRSTGPR;
+#else
+ Reg gpr, fpr = REGARG_FIRSTFPR, fprodd = 0;
+#endif
+ if ((void *)ci->func)
+ emit_call(as, (void *)ci->func);
+#if !LJ_SOFTFP
+ for (gpr = REGARG_FIRSTGPR; gpr <= REGARG_LASTGPR; gpr++)
+ as->cost[gpr] = REGCOST(~0u, ASMREF_L);
+ gpr = REGARG_FIRSTGPR;
+#endif
+ for (n = 0; n < nargs; n++) { /* Setup args. */
+ IRRef ref = args[n];
+ IRIns *ir = IR(ref);
+#if !LJ_SOFTFP
+ if (ref && irt_isfp(ir->t)) {
+ RegSet of = as->freeset;
+ Reg src;
+ if (!LJ_ABI_SOFTFP && !(ci->flags & CCI_VARARG)) {
+ if (irt_isnum(ir->t)) {
+ if (fpr <= REGARG_LASTFPR) {
+ ra_leftov(as, fpr, ref);
+ fpr++;
+ continue;
+ }
+ } else if (fprodd) { /* Ick. */
+ src = ra_alloc1(as, ref, RSET_FPR);
+ emit_dm(as, ARMI_VMOV_S, (fprodd & 15), (src & 15) | 0x00400000);
+ fprodd = 0;
+ continue;
+ } else if (fpr <= REGARG_LASTFPR) {
+ ra_leftov(as, fpr, ref);
+ fprodd = fpr++;
+ continue;
+ }
+ /* Workaround to protect argument GPRs from being used for remat. */
+ as->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1);
+ src = ra_alloc1(as, ref, RSET_FPR); /* May alloc GPR to remat FPR. */
+ as->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1));
+ fprodd = 0;
+ goto stackfp;
+ }
+ /* Workaround to protect argument GPRs from being used for remat. */
+ as->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1);
+ src = ra_alloc1(as, ref, RSET_FPR); /* May alloc GPR to remat FPR. */
+ as->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1));
+ if (irt_isnum(ir->t)) gpr = (gpr+1) & ~1u;
+ if (gpr <= REGARG_LASTGPR) {
+ lua_assert(rset_test(as->freeset, gpr)); /* Must have been evicted. */
+ if (irt_isnum(ir->t)) {
+ lua_assert(rset_test(as->freeset, gpr+1)); /* Ditto. */
+ emit_dnm(as, ARMI_VMOV_RR_D, gpr, gpr+1, (src & 15));
+ gpr += 2;
+ } else {
+ emit_dn(as, ARMI_VMOV_R_S, gpr, (src & 15));
+ gpr++;
+ }
+ } else {
+ stackfp:
+ if (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4;
+ emit_spstore(as, ir, src, ofs);
+ ofs += irt_isnum(ir->t) ? 8 : 4;
+ }
+ } else
+#endif
+ {
+ if (gpr <= REGARG_LASTGPR) {
+ lua_assert(rset_test(as->freeset, gpr)); /* Must have been evicted. */
+ if (ref) ra_leftov(as, gpr, ref);
+ gpr++;
+ } else {
+ if (ref) {
+ Reg r = ra_alloc1(as, ref, RSET_GPR);
+ emit_spstore(as, ir, r, ofs);
+ }
+ ofs += 4;
+ }
+ }
+ }
+}
+
+/* Setup result reg/sp for call. Evict scratch regs. */
+static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci)
+{
+ RegSet drop = RSET_SCRATCH;
+ int hiop = ((ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t));
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ if (hiop && ra_hasreg((ir+1)->r))
+ rset_clear(drop, (ir+1)->r); /* Dest reg handled below. */
+ ra_evictset(as, drop); /* Evictions must be performed first. */
+ if (ra_used(ir)) {
+ lua_assert(!irt_ispri(ir->t));
+ if (!LJ_SOFTFP && irt_isfp(ir->t)) {
+ if (LJ_ABI_SOFTFP || (ci->flags & (CCI_CASTU64|CCI_VARARG))) {
+ Reg dest = (ra_dest(as, ir, RSET_FPR) & 15);
+ if (irt_isnum(ir->t))
+ emit_dnm(as, ARMI_VMOV_D_RR, RID_RETLO, RID_RETHI, dest);
+ else
+ emit_dn(as, ARMI_VMOV_S_R, RID_RET, dest);
+ } else {
+ ra_destreg(as, ir, RID_FPRET);
+ }
+ } else if (hiop) {
+ ra_destpair(as, ir);
+ } else {
+ ra_destreg(as, ir, RID_RET);
+ }
+ }
+ UNUSED(ci);
+}
+
+static void asm_call(ASMState *as, IRIns *ir)
+{
+ IRRef args[CCI_NARGS_MAX];
+ const CCallInfo *ci = &lj_ir_callinfo[ir->op2];
+ asm_collectargs(as, ir, ci, args);
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+
+static void asm_callx(ASMState *as, IRIns *ir)
+{
+ IRRef args[CCI_NARGS_MAX*2];
+ CCallInfo ci;
+ IRRef func;
+ IRIns *irf;
+ ci.flags = asm_callx_flags(as, ir);
+ asm_collectargs(as, ir, &ci, args);
+ asm_setupresult(as, ir, &ci);
+ func = ir->op2; irf = IR(func);
+ if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }
+ if (irref_isk(func)) { /* Call to constant address. */
+ ci.func = (ASMFunction)(void *)(irf->i);
+ } else { /* Need a non-argument register for indirect calls. */
+ Reg freg = ra_alloc1(as, func, RSET_RANGE(RID_R4, RID_R12+1));
+ emit_m(as, ARMI_BLXr, freg);
+ ci.func = (ASMFunction)(void *)0;
+ }
+ asm_gencall(as, &ci, args);
+}
+
+/* -- Returns ------------------------------------------------------------- */
+
+/* Return to lower frame. Guard that it goes to the right spot. */
+static void asm_retf(ASMState *as, IRIns *ir)
+{
+ Reg base = ra_alloc1(as, REF_BASE, RSET_GPR);
+ void *pc = ir_kptr(IR(ir->op2));
+ int32_t delta = 1+bc_a(*((const BCIns *)pc - 1));
+ as->topslot -= (BCReg)delta;
+ if ((int32_t)as->topslot < 0) as->topslot = 0;
+ irt_setmark(IR(REF_BASE)->t); /* Children must not coalesce with BASE reg. */
+ /* Need to force a spill on REF_BASE now to update the stack slot. */
+ emit_lso(as, ARMI_STR, base, RID_SP, ra_spill(as, IR(REF_BASE)));
+ emit_setgl(as, base, jit_base);
+ emit_addptr(as, base, -8*delta);
+ asm_guardcc(as, CC_NE);
+ emit_nm(as, ARMI_CMP, RID_TMP,
+ ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base)));
+ emit_lso(as, ARMI_LDR, RID_TMP, base, -4);
+}
+
+/* -- Type conversions ---------------------------------------------------- */
+
+#if !LJ_SOFTFP
+static void asm_tointg(ASMState *as, IRIns *ir, Reg left)
+{
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ asm_guardcc(as, CC_NE);
+ emit_d(as, ARMI_VMRS, 0);
+ emit_dm(as, ARMI_VCMP_D, (tmp & 15), (left & 15));
+ emit_dm(as, ARMI_VCVT_F64_S32, (tmp & 15), (tmp & 15));
+ emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15));
+ emit_dm(as, ARMI_VCVT_S32_F64, (tmp & 15), (left & 15));
+}
+
+static void asm_tobit(ASMState *as, IRIns *ir)
+{
+ RegSet allow = RSET_FPR;
+ Reg left = ra_alloc1(as, ir->op1, allow);
+ Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left));
+ Reg tmp = ra_scratch(as, rset_clear(allow, right));
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15));
+ emit_dnm(as, ARMI_VADD_D, (tmp & 15), (left & 15), (right & 15));
+}
+#endif
+
+static void asm_conv(ASMState *as, IRIns *ir)
+{
+ IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);
+#if !LJ_SOFTFP
+ int stfp = (st == IRT_NUM || st == IRT_FLOAT);
+#endif
+ IRRef lref = ir->op1;
+ /* 64 bit integer conversions are handled by SPLIT. */
+ lua_assert(!irt_isint64(ir->t) && !(st == IRT_I64 || st == IRT_U64));
+#if LJ_SOFTFP
+ /* FP conversions are handled by SPLIT. */
+ lua_assert(!irt_isfp(ir->t) && !(st == IRT_NUM || st == IRT_FLOAT));
+ /* Can't check for same types: SPLIT uses CONV int.int + BXOR for sfp NEG. */
+#else
+ lua_assert(irt_type(ir->t) != st);
+ if (irt_isfp(ir->t)) {
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ if (stfp) { /* FP to FP conversion. */
+ emit_dm(as, st == IRT_NUM ? ARMI_VCVT_F32_F64 : ARMI_VCVT_F64_F32,
+ (dest & 15), (ra_alloc1(as, lref, RSET_FPR) & 15));
+ } else { /* Integer to FP conversion. */
+ Reg left = ra_alloc1(as, lref, RSET_GPR);
+ ARMIns ai = irt_isfloat(ir->t) ?
+ (st == IRT_INT ? ARMI_VCVT_F32_S32 : ARMI_VCVT_F32_U32) :
+ (st == IRT_INT ? ARMI_VCVT_F64_S32 : ARMI_VCVT_F64_U32);
+ emit_dm(as, ai, (dest & 15), (dest & 15));
+ emit_dn(as, ARMI_VMOV_S_R, left, (dest & 15));
+ }
+ } else if (stfp) { /* FP to integer conversion. */
+ if (irt_isguard(ir->t)) {
+ /* Checked conversions are only supported from number to int. */
+ lua_assert(irt_isint(ir->t) && st == IRT_NUM);
+ asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR));
+ } else {
+ Reg left = ra_alloc1(as, lref, RSET_FPR);
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ ARMIns ai;
+ emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15));
+ ai = irt_isint(ir->t) ?
+ (st == IRT_NUM ? ARMI_VCVT_S32_F64 : ARMI_VCVT_S32_F32) :
+ (st == IRT_NUM ? ARMI_VCVT_U32_F64 : ARMI_VCVT_U32_F32);
+ emit_dm(as, ai, (tmp & 15), (left & 15));
+ }
+ } else
+#endif
+ {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */
+ Reg left = ra_alloc1(as, lref, RSET_GPR);
+ lua_assert(irt_isint(ir->t) || irt_isu32(ir->t));
+ if ((as->flags & JIT_F_ARMV6)) {
+ ARMIns ai = st == IRT_I8 ? ARMI_SXTB :
+ st == IRT_U8 ? ARMI_UXTB :
+ st == IRT_I16 ? ARMI_SXTH : ARMI_UXTH;
+ emit_dm(as, ai, dest, left);
+ } else if (st == IRT_U8) {
+ emit_dn(as, ARMI_AND|ARMI_K12|255, dest, left);
+ } else {
+ uint32_t shift = st == IRT_I8 ? 24 : 16;
+ ARMShift sh = st == IRT_U16 ? ARMSH_LSR : ARMSH_ASR;
+ emit_dm(as, ARMI_MOV|ARMF_SH(sh, shift), dest, RID_TMP);
+ emit_dm(as, ARMI_MOV|ARMF_SH(ARMSH_LSL, shift), RID_TMP, left);
+ }
+ } else { /* Handle 32/32 bit no-op (cast). */
+ ra_leftov(as, dest, lref); /* Do nothing, but may need to move regs. */
+ }
+ }
+}
+
+#if !LJ_SOFTFP && LJ_HASFFI
+static void asm_conv64(ASMState *as, IRIns *ir)
+{
+ IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK);
+ IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH);
+ IRCallID id;
+ CCallInfo ci;
+ IRRef args[2];
+ args[0] = (ir-1)->op1;
+ args[1] = ir->op1;
+ if (st == IRT_NUM || st == IRT_FLOAT) {
+ id = IRCALL_fp64_d2l + ((st == IRT_FLOAT) ? 2 : 0) + (dt - IRT_I64);
+ ir--;
+ } else {
+ id = IRCALL_fp64_l2d + ((dt == IRT_FLOAT) ? 2 : 0) + (st - IRT_I64);
+ }
+ ci = lj_ir_callinfo[id];
+#if !LJ_ABI_SOFTFP
+ ci.flags |= CCI_VARARG; /* These calls don't use the hard-float ABI! */
+#endif
+ asm_setupresult(as, ir, &ci);
+ asm_gencall(as, &ci, args);
+}
+#endif
+
+static void asm_strto(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num];
+ IRRef args[2];
+ Reg rlo = 0, rhi = 0, tmp;
+ int destused = ra_used(ir);
+ int32_t ofs = 0;
+ ra_evictset(as, RSET_SCRATCH);
+#if LJ_SOFTFP
+ if (destused) {
+ if (ra_hasspill(ir->s) && ra_hasspill((ir+1)->s) &&
+ (ir->s & 1) == 0 && ir->s + 1 == (ir+1)->s) {
+ int i;
+ for (i = 0; i < 2; i++) {
+ Reg r = (ir+i)->r;
+ if (ra_hasreg(r)) {
+ ra_free(as, r);
+ ra_modified(as, r);
+ emit_spload(as, ir+i, r, sps_scale((ir+i)->s));
+ }
+ }
+ ofs = sps_scale(ir->s);
+ destused = 0;
+ } else {
+ rhi = ra_dest(as, ir+1, RSET_GPR);
+ rlo = ra_dest(as, ir, rset_exclude(RSET_GPR, rhi));
+ }
+ }
+ asm_guardcc(as, CC_EQ);
+ if (destused) {
+ emit_lso(as, ARMI_LDR, rhi, RID_SP, 4);
+ emit_lso(as, ARMI_LDR, rlo, RID_SP, 0);
+ }
+#else
+ UNUSED(rhi);
+ if (destused) {
+ if (ra_hasspill(ir->s)) {
+ ofs = sps_scale(ir->s);
+ destused = 0;
+ if (ra_hasreg(ir->r)) {
+ ra_free(as, ir->r);
+ ra_modified(as, ir->r);
+ emit_spload(as, ir, ir->r, ofs);
+ }
+ } else {
+ rlo = ra_dest(as, ir, RSET_FPR);
+ }
+ }
+ asm_guardcc(as, CC_EQ);
+ if (destused)
+ emit_vlso(as, ARMI_VLDR_D, rlo, RID_SP, 0);
+#endif
+ emit_n(as, ARMI_CMP|ARMI_K12|0, RID_RET); /* Test return status. */
+ args[0] = ir->op1; /* GCstr *str */
+ args[1] = ASMREF_TMP1; /* TValue *n */
+ asm_gencall(as, ci, args);
+ tmp = ra_releasetmp(as, ASMREF_TMP1);
+ if (ofs == 0)
+ emit_dm(as, ARMI_MOV, tmp, RID_SP);
+ else
+ emit_opk(as, ARMI_ADD, tmp, RID_SP, ofs, RSET_GPR);
+}
+
+/* Get pointer to TValue. */
+static void asm_tvptr(ASMState *as, Reg dest, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ if (irt_isnum(ir->t)) {
+ if (irref_isk(ref)) {
+ /* Use the number constant itself as a TValue. */
+ ra_allockreg(as, i32ptr(ir_knum(ir)), dest);
+ } else {
+#if LJ_SOFTFP
+ lua_assert(0);
+#else
+ /* Otherwise force a spill and use the spill slot. */
+ emit_opk(as, ARMI_ADD, dest, RID_SP, ra_spill(as, ir), RSET_GPR);
+#endif
+ }
+ } else {
+ /* Otherwise use [sp] and [sp+4] to hold the TValue. */
+ RegSet allow = rset_exclude(RSET_GPR, dest);
+ Reg type;
+ emit_dm(as, ARMI_MOV, dest, RID_SP);
+ if (!irt_ispri(ir->t)) {
+ Reg src = ra_alloc1(as, ref, allow);
+ emit_lso(as, ARMI_STR, src, RID_SP, 0);
+ }
+ if ((ir+1)->o == IR_HIOP)
+ type = ra_alloc1(as, ref+1, allow);
+ else
+ type = ra_allock(as, irt_toitype(ir->t), allow);
+ emit_lso(as, ARMI_STR, type, RID_SP, 4);
+ }
+}
+
+static void asm_tostr(ASMState *as, IRIns *ir)
+{
+ IRRef args[2];
+ args[0] = ASMREF_L;
+ as->gcsteps++;
+ if (irt_isnum(IR(ir->op1)->t) || (ir+1)->o == IR_HIOP) {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromnum];
+ args[1] = ASMREF_TMP1; /* const lua_Number * */
+ asm_setupresult(as, ir, ci); /* GCstr * */
+ asm_gencall(as, ci, args);
+ asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op1);
+ } else {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromint];
+ args[1] = ir->op1; /* int32_t k */
+ asm_setupresult(as, ir, ci); /* GCstr * */
+ asm_gencall(as, ci, args);
+ }
+}
+
+/* -- Memory references --------------------------------------------------- */
+
+static void asm_aref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg idx, base;
+ if (irref_isk(ir->op2)) {
+ IRRef tab = IR(ir->op1)->op1;
+ int32_t ofs = asm_fuseabase(as, tab);
+ IRRef refa = ofs ? tab : ir->op1;
+ uint32_t k = emit_isk12(ARMI_ADD, ofs + 8*IR(ir->op2)->i);
+ if (k) {
+ base = ra_alloc1(as, refa, RSET_GPR);
+ emit_dn(as, ARMI_ADD^k, dest, base);
+ return;
+ }
+ }
+ base = ra_alloc1(as, ir->op1, RSET_GPR);
+ idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base));
+ emit_dnm(as, ARMI_ADD|ARMF_SH(ARMSH_LSL, 3), dest, base, idx);
+}
+
+/* Inlined hash lookup. Specialized for key type and for const keys.
+** The equivalent C code is:
+** Node *n = hashkey(t, key);
+** do {
+** if (lj_obj_equal(&n->key, key)) return &n->val;
+** } while ((n = nextnode(n)));
+** return niltv(L);
+*/
+static void asm_href(ASMState *as, IRIns *ir, IROp merge)
+{
+ RegSet allow = RSET_GPR;
+ int destused = ra_used(ir);
+ Reg dest = ra_dest(as, ir, allow);
+ Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest));
+ Reg key = 0, keyhi = 0, keynumhi = RID_NONE, tmp = RID_TMP;
+ IRRef refkey = ir->op2;
+ IRIns *irkey = IR(refkey);
+ IRType1 kt = irkey->t;
+ int32_t k = 0, khi = emit_isk12(ARMI_CMP, irt_toitype(kt));
+ uint32_t khash;
+ MCLabel l_end, l_loop;
+ rset_clear(allow, tab);
+ if (!irref_isk(refkey) || irt_isstr(kt)) {
+#if LJ_SOFTFP
+ key = ra_alloc1(as, refkey, allow);
+ rset_clear(allow, key);
+ if (irkey[1].o == IR_HIOP) {
+ if (ra_hasreg((irkey+1)->r)) {
+ keynumhi = (irkey+1)->r;
+ keyhi = RID_TMP;
+ ra_noweak(as, keynumhi);
+ } else {
+ keyhi = keynumhi = ra_allocref(as, refkey+1, allow);
+ }
+ rset_clear(allow, keynumhi);
+ khi = 0;
+ }
+#else
+ if (irt_isnum(kt)) {
+ key = ra_scratch(as, allow);
+ rset_clear(allow, key);
+ keyhi = keynumhi = ra_scratch(as, allow);
+ rset_clear(allow, keyhi);
+ khi = 0;
+ } else {
+ key = ra_alloc1(as, refkey, allow);
+ rset_clear(allow, key);
+ }
+#endif
+ } else if (irt_isnum(kt)) {
+ int32_t val = (int32_t)ir_knum(irkey)->u32.lo;
+ k = emit_isk12(ARMI_CMP, val);
+ if (!k) {
+ key = ra_allock(as, val, allow);
+ rset_clear(allow, key);
+ }
+ val = (int32_t)ir_knum(irkey)->u32.hi;
+ khi = emit_isk12(ARMI_CMP, val);
+ if (!khi) {
+ keyhi = ra_allock(as, val, allow);
+ rset_clear(allow, keyhi);
+ }
+ } else if (!irt_ispri(kt)) {
+ k = emit_isk12(ARMI_CMP, irkey->i);
+ if (!k) {
+ key = ra_alloc1(as, refkey, allow);
+ rset_clear(allow, key);
+ }
+ }
+ if (!irt_ispri(kt))
+ tmp = ra_scratchpair(as, allow);
+
+ /* Key not found in chain: jump to exit (if merged) or load niltv. */
+ l_end = emit_label(as);
+ as->invmcp = NULL;
+ if (merge == IR_NE)
+ asm_guardcc(as, CC_AL);
+ else if (destused)
+ emit_loada(as, dest, niltvg(J2G(as->J)));
+
+ /* Follow hash chain until the end. */
+ l_loop = --as->mcp;
+ emit_n(as, ARMI_CMP|ARMI_K12|0, dest);
+ emit_lso(as, ARMI_LDR, dest, dest, (int32_t)offsetof(Node, next));
+
+ /* Type and value comparison. */
+ if (merge == IR_EQ)
+ asm_guardcc(as, CC_EQ);
+ else
+ emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end);
+ if (!irt_ispri(kt)) {
+ emit_nm(as, ARMF_CC(ARMI_CMP, CC_EQ)^k, tmp, key);
+ emit_nm(as, ARMI_CMP^khi, tmp+1, keyhi);
+ emit_lsox(as, ARMI_LDRD, tmp, dest, (int32_t)offsetof(Node, key));
+ } else {
+ emit_n(as, ARMI_CMP^khi, tmp);
+ emit_lso(as, ARMI_LDR, tmp, dest, (int32_t)offsetof(Node, key.it));
+ }
+ *l_loop = ARMF_CC(ARMI_B, CC_NE) | ((as->mcp-l_loop-2) & 0x00ffffffu);
+
+ /* Load main position relative to tab->node into dest. */
+ khash = irref_isk(refkey) ? ir_khash(irkey) : 1;
+ if (khash == 0) {
+ emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node));
+ } else {
+ emit_dnm(as, ARMI_ADD|ARMF_SH(ARMSH_LSL, 3), dest, dest, tmp);
+ emit_dnm(as, ARMI_ADD|ARMF_SH(ARMSH_LSL, 1), tmp, tmp, tmp);
+ if (irt_isstr(kt)) { /* Fetch of str->hash is cheaper than ra_allock. */
+ emit_dnm(as, ARMI_AND, tmp, tmp+1, RID_TMP);
+ emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node));
+ emit_lso(as, ARMI_LDR, tmp+1, key, (int32_t)offsetof(GCstr, hash));
+ emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask));
+ } else if (irref_isk(refkey)) {
+ emit_opk(as, ARMI_AND, tmp, RID_TMP, (int32_t)khash,
+ rset_exclude(rset_exclude(RSET_GPR, tab), dest));
+ emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node));
+ emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask));
+ } else { /* Must match with hash*() in lj_tab.c. */
+ if (ra_hasreg(keynumhi)) { /* Canonicalize +-0.0 to 0.0. */
+ if (keyhi == RID_TMP)
+ emit_dm(as, ARMF_CC(ARMI_MOV, CC_NE), keyhi, keynumhi);
+ emit_d(as, ARMF_CC(ARMI_MOV, CC_EQ)|ARMI_K12|0, keyhi);
+ }
+ emit_dnm(as, ARMI_AND, tmp, tmp, RID_TMP);
+ emit_dnm(as, ARMI_SUB|ARMF_SH(ARMSH_ROR, 32-HASH_ROT3), tmp, tmp, tmp+1);
+ emit_lso(as, ARMI_LDR, dest, tab, (int32_t)offsetof(GCtab, node));
+ emit_dnm(as, ARMI_EOR|ARMF_SH(ARMSH_ROR, 32-((HASH_ROT2+HASH_ROT1)&31)),
+ tmp, tmp+1, tmp);
+ emit_lso(as, ARMI_LDR, RID_TMP, tab, (int32_t)offsetof(GCtab, hmask));
+ emit_dnm(as, ARMI_SUB|ARMF_SH(ARMSH_ROR, 32-HASH_ROT1), tmp+1, tmp+1, tmp);
+ if (ra_hasreg(keynumhi)) {
+ emit_dnm(as, ARMI_EOR, tmp+1, tmp, key);
+ emit_dnm(as, ARMI_ORR|ARMI_S, RID_TMP, tmp, key); /* Test for +-0.0. */
+ emit_dnm(as, ARMI_ADD, tmp, keynumhi, keynumhi);
+#if !LJ_SOFTFP
+ emit_dnm(as, ARMI_VMOV_RR_D, key, keynumhi,
+ (ra_alloc1(as, refkey, RSET_FPR) & 15));
+#endif
+ } else {
+ emit_dnm(as, ARMI_EOR, tmp+1, tmp, key);
+ emit_opk(as, ARMI_ADD, tmp, key, (int32_t)HASH_BIAS,
+ rset_exclude(rset_exclude(RSET_GPR, tab), key));
+ }
+ }
+ }
+}
+
+static void asm_hrefk(ASMState *as, IRIns *ir)
+{
+ IRIns *kslot = IR(ir->op2);
+ IRIns *irkey = IR(kslot->op1);
+ int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node));
+ int32_t kofs = ofs + (int32_t)offsetof(Node, key);
+ Reg dest = (ra_used(ir) || ofs > 4095) ? ra_dest(as, ir, RSET_GPR) : RID_NONE;
+ Reg node = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg key = RID_NONE, type = RID_TMP, idx = node;
+ RegSet allow = rset_exclude(RSET_GPR, node);
+ lua_assert(ofs % sizeof(Node) == 0);
+ if (ofs > 4095) {
+ idx = dest;
+ rset_clear(allow, dest);
+ kofs = (int32_t)offsetof(Node, key);
+ } else if (ra_hasreg(dest)) {
+ emit_opk(as, ARMI_ADD, dest, node, ofs, allow);
+ }
+ asm_guardcc(as, CC_NE);
+ if (!irt_ispri(irkey->t)) {
+ RegSet even = (as->freeset & allow);
+ even = even & (even >> 1) & RSET_GPREVEN;
+ if (even) {
+ key = ra_scratch(as, even);
+ if (rset_test(as->freeset, key+1)) {
+ type = key+1;
+ ra_modified(as, type);
+ }
+ } else {
+ key = ra_scratch(as, allow);
+ }
+ rset_clear(allow, key);
+ }
+ rset_clear(allow, type);
+ if (irt_isnum(irkey->t)) {
+ emit_opk(as, ARMF_CC(ARMI_CMP, CC_EQ), 0, type,
+ (int32_t)ir_knum(irkey)->u32.hi, allow);
+ emit_opk(as, ARMI_CMP, 0, key,
+ (int32_t)ir_knum(irkey)->u32.lo, allow);
+ } else {
+ if (ra_hasreg(key))
+ emit_opk(as, ARMF_CC(ARMI_CMP, CC_EQ), 0, key, irkey->i, allow);
+ emit_n(as, ARMI_CMN|ARMI_K12|-irt_toitype(irkey->t), type);
+ }
+ emit_lso(as, ARMI_LDR, type, idx, kofs+4);
+ if (ra_hasreg(key)) emit_lso(as, ARMI_LDR, key, idx, kofs);
+ if (ofs > 4095)
+ emit_opk(as, ARMI_ADD, dest, node, ofs, RSET_GPR);
+}
+
+static void asm_newref(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_newkey];
+ IRRef args[3];
+ if (ir->r == RID_SINK)
+ return;
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ir->op1; /* GCtab *t */
+ args[2] = ASMREF_TMP1; /* cTValue *key */
+ asm_setupresult(as, ir, ci); /* TValue * */
+ asm_gencall(as, ci, args);
+ asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op2);
+}
+
+static void asm_uref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (irref_isk(ir->op1)) {
+ GCfunc *fn = ir_kfunc(IR(ir->op1));
+ MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v;
+ emit_lsptr(as, ARMI_LDR, dest, v);
+ } else {
+ Reg uv = ra_scratch(as, RSET_GPR);
+ Reg func = ra_alloc1(as, ir->op1, RSET_GPR);
+ if (ir->o == IR_UREFC) {
+ asm_guardcc(as, CC_NE);
+ emit_n(as, ARMI_CMP|ARMI_K12|1, RID_TMP);
+ emit_opk(as, ARMI_ADD, dest, uv,
+ (int32_t)offsetof(GCupval, tv), RSET_GPR);
+ emit_lso(as, ARMI_LDRB, RID_TMP, uv, (int32_t)offsetof(GCupval, closed));
+ } else {
+ emit_lso(as, ARMI_LDR, dest, uv, (int32_t)offsetof(GCupval, v));
+ }
+ emit_lso(as, ARMI_LDR, uv, func,
+ (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8));
+ }
+}
+
+static void asm_fref(ASMState *as, IRIns *ir)
+{
+ UNUSED(as); UNUSED(ir);
+ lua_assert(!ra_used(ir));
+}
+
+static void asm_strref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ IRRef ref = ir->op2, refk = ir->op1;
+ Reg r;
+ if (irref_isk(ref)) {
+ IRRef tmp = refk; refk = ref; ref = tmp;
+ } else if (!irref_isk(refk)) {
+ uint32_t k, m = ARMI_K12|sizeof(GCstr);
+ Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);
+ IRIns *irr = IR(ir->op2);
+ if (ra_hasreg(irr->r)) {
+ ra_noweak(as, irr->r);
+ right = irr->r;
+ } else if (mayfuse(as, irr->op2) &&
+ irr->o == IR_ADD && irref_isk(irr->op2) &&
+ (k = emit_isk12(ARMI_ADD,
+ (int32_t)sizeof(GCstr) + IR(irr->op2)->i))) {
+ m = k;
+ right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left));
+ } else {
+ right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left));
+ }
+ emit_dn(as, ARMI_ADD^m, dest, dest);
+ emit_dnm(as, ARMI_ADD, dest, left, right);
+ return;
+ }
+ r = ra_alloc1(as, ref, RSET_GPR);
+ emit_opk(as, ARMI_ADD, dest, r,
+ sizeof(GCstr) + IR(refk)->i, rset_exclude(RSET_GPR, r));
+}
+
+/* -- Loads and stores ---------------------------------------------------- */
+
+static ARMIns asm_fxloadins(IRIns *ir)
+{
+ switch (irt_type(ir->t)) {
+ case IRT_I8: return ARMI_LDRSB;
+ case IRT_U8: return ARMI_LDRB;
+ case IRT_I16: return ARMI_LDRSH;
+ case IRT_U16: return ARMI_LDRH;
+ case IRT_NUM: lua_assert(!LJ_SOFTFP); return ARMI_VLDR_D;
+ case IRT_FLOAT: if (!LJ_SOFTFP) return ARMI_VLDR_S;
+ default: return ARMI_LDR;
+ }
+}
+
+static ARMIns asm_fxstoreins(IRIns *ir)
+{
+ switch (irt_type(ir->t)) {
+ case IRT_I8: case IRT_U8: return ARMI_STRB;
+ case IRT_I16: case IRT_U16: return ARMI_STRH;
+ case IRT_NUM: lua_assert(!LJ_SOFTFP); return ARMI_VSTR_D;
+ case IRT_FLOAT: if (!LJ_SOFTFP) return ARMI_VSTR_S;
+ default: return ARMI_STR;
+ }
+}
+
+static void asm_fload(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg idx = ra_alloc1(as, ir->op1, RSET_GPR);
+ ARMIns ai = asm_fxloadins(ir);
+ int32_t ofs;
+ if (ir->op2 == IRFL_TAB_ARRAY) {
+ ofs = asm_fuseabase(as, ir->op1);
+ if (ofs) { /* Turn the t->array load into an add for colocated arrays. */
+ emit_dn(as, ARMI_ADD|ARMI_K12|ofs, dest, idx);
+ return;
+ }
+ }
+ ofs = field_ofs[ir->op2];
+ if ((ai & 0x04000000))
+ emit_lso(as, ai, dest, idx, ofs);
+ else
+ emit_lsox(as, ai, dest, idx, ofs);
+}
+
+static void asm_fstore(ASMState *as, IRIns *ir)
+{
+ if (ir->r != RID_SINK) {
+ Reg src = ra_alloc1(as, ir->op2, RSET_GPR);
+ IRIns *irf = IR(ir->op1);
+ Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src));
+ int32_t ofs = field_ofs[irf->op2];
+ ARMIns ai = asm_fxstoreins(ir);
+ if ((ai & 0x04000000))
+ emit_lso(as, ai, src, idx, ofs);
+ else
+ emit_lsox(as, ai, src, idx, ofs);
+ }
+}
+
+static void asm_xload(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir,
+ (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR);
+ lua_assert(!(ir->op2 & IRXLOAD_UNALIGNED));
+ asm_fusexref(as, asm_fxloadins(ir), dest, ir->op1, RSET_GPR, 0);
+}
+
+static void asm_xstore(ASMState *as, IRIns *ir, int32_t ofs)
+{
+ if (ir->r != RID_SINK) {
+ Reg src = ra_alloc1(as, ir->op2,
+ (!LJ_SOFTFP && irt_isfp(ir->t)) ? RSET_FPR : RSET_GPR);
+ asm_fusexref(as, asm_fxstoreins(ir), src, ir->op1,
+ rset_exclude(RSET_GPR, src), ofs);
+ }
+}
+
+static void asm_ahuvload(ASMState *as, IRIns *ir)
+{
+ int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP);
+ IRType t = hiop ? IRT_NUM : irt_type(ir->t);
+ Reg dest = RID_NONE, type = RID_NONE, idx;
+ RegSet allow = RSET_GPR;
+ int32_t ofs = 0;
+ if (hiop && ra_used(ir+1)) {
+ type = ra_dest(as, ir+1, allow);
+ rset_clear(allow, type);
+ }
+ if (ra_used(ir)) {
+ lua_assert((LJ_SOFTFP ? 0 : irt_isnum(ir->t)) ||
+ irt_isint(ir->t) || irt_isaddr(ir->t));
+ dest = ra_dest(as, ir, (!LJ_SOFTFP && t == IRT_NUM) ? RSET_FPR : allow);
+ rset_clear(allow, dest);
+ }
+ idx = asm_fuseahuref(as, ir->op1, &ofs, allow,
+ (!LJ_SOFTFP && t == IRT_NUM) ? 1024 : 4096);
+ if (!hiop || type == RID_NONE) {
+ rset_clear(allow, idx);
+ if (ofs < 256 && ra_hasreg(dest) && (dest & 1) == 0 &&
+ rset_test((as->freeset & allow), dest+1)) {
+ type = dest+1;
+ ra_modified(as, type);
+ } else {
+ type = RID_TMP;
+ }
+ }
+ asm_guardcc(as, t == IRT_NUM ? CC_HS : CC_NE);
+ emit_n(as, ARMI_CMN|ARMI_K12|-irt_toitype_(t), type);
+ if (ra_hasreg(dest)) {
+#if !LJ_SOFTFP
+ if (t == IRT_NUM)
+ emit_vlso(as, ARMI_VLDR_D, dest, idx, ofs);
+ else
+#endif
+ emit_lso(as, ARMI_LDR, dest, idx, ofs);
+ }
+ emit_lso(as, ARMI_LDR, type, idx, ofs+4);
+}
+
+static void asm_ahustore(ASMState *as, IRIns *ir)
+{
+ if (ir->r != RID_SINK) {
+ RegSet allow = RSET_GPR;
+ Reg idx, src = RID_NONE, type = RID_NONE;
+ int32_t ofs = 0;
+#if !LJ_SOFTFP
+ if (irt_isnum(ir->t)) {
+ src = ra_alloc1(as, ir->op2, RSET_FPR);
+ idx = asm_fuseahuref(as, ir->op1, &ofs, allow, 1024);
+ emit_vlso(as, ARMI_VSTR_D, src, idx, ofs);
+ } else
+#endif
+ {
+ int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP);
+ if (!irt_ispri(ir->t)) {
+ src = ra_alloc1(as, ir->op2, allow);
+ rset_clear(allow, src);
+ }
+ if (hiop)
+ type = ra_alloc1(as, (ir+1)->op2, allow);
+ else
+ type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);
+ idx = asm_fuseahuref(as, ir->op1, &ofs, rset_exclude(allow, type), 4096);
+ if (ra_hasreg(src)) emit_lso(as, ARMI_STR, src, idx, ofs);
+ emit_lso(as, ARMI_STR, type, idx, ofs+4);
+ }
+ }
+}
+
+static void asm_sload(ASMState *as, IRIns *ir)
+{
+ int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 4 : 0);
+ int hiop = (LJ_SOFTFP && (ir+1)->o == IR_HIOP);
+ IRType t = hiop ? IRT_NUM : irt_type(ir->t);
+ Reg dest = RID_NONE, type = RID_NONE, base;
+ RegSet allow = RSET_GPR;
+ lua_assert(!(ir->op2 & IRSLOAD_PARENT)); /* Handled by asm_head_side(). */
+ lua_assert(irt_isguard(ir->t) || !(ir->op2 & IRSLOAD_TYPECHECK));
+#if LJ_SOFTFP
+ lua_assert(!(ir->op2 & IRSLOAD_CONVERT)); /* Handled by LJ_SOFTFP SPLIT. */
+ if (hiop && ra_used(ir+1)) {
+ type = ra_dest(as, ir+1, allow);
+ rset_clear(allow, type);
+ }
+#else
+ if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(ir->t) && t == IRT_INT) {
+ dest = ra_scratch(as, RSET_FPR);
+ asm_tointg(as, ir, dest);
+ t = IRT_NUM; /* Continue with a regular number type check. */
+ } else
+#endif
+ if (ra_used(ir)) {
+ Reg tmp = RID_NONE;
+ if ((ir->op2 & IRSLOAD_CONVERT))
+ tmp = ra_scratch(as, t == IRT_INT ? RSET_FPR : RSET_GPR);
+ lua_assert((LJ_SOFTFP ? 0 : irt_isnum(ir->t)) ||
+ irt_isint(ir->t) || irt_isaddr(ir->t));
+ dest = ra_dest(as, ir, (!LJ_SOFTFP && t == IRT_NUM) ? RSET_FPR : allow);
+ rset_clear(allow, dest);
+ base = ra_alloc1(as, REF_BASE, allow);
+ if ((ir->op2 & IRSLOAD_CONVERT)) {
+ if (t == IRT_INT) {
+ emit_dn(as, ARMI_VMOV_R_S, dest, (tmp & 15));
+ emit_dm(as, ARMI_VCVT_S32_F64, (tmp & 15), (tmp & 15));
+ t = IRT_NUM; /* Check for original type. */
+ } else {
+ emit_dm(as, ARMI_VCVT_F64_S32, (dest & 15), (dest & 15));
+ emit_dn(as, ARMI_VMOV_S_R, tmp, (dest & 15));
+ t = IRT_INT; /* Check for original type. */
+ }
+ dest = tmp;
+ }
+ goto dotypecheck;
+ }
+ base = ra_alloc1(as, REF_BASE, allow);
+dotypecheck:
+ rset_clear(allow, base);
+ if ((ir->op2 & IRSLOAD_TYPECHECK)) {
+ if (ra_noreg(type)) {
+ if (ofs < 256 && ra_hasreg(dest) && (dest & 1) == 0 &&
+ rset_test((as->freeset & allow), dest+1)) {
+ type = dest+1;
+ ra_modified(as, type);
+ } else {
+ type = RID_TMP;
+ }
+ }
+ asm_guardcc(as, t == IRT_NUM ? CC_HS : CC_NE);
+ emit_n(as, ARMI_CMN|ARMI_K12|-irt_toitype_(t), type);
+ }
+ if (ra_hasreg(dest)) {
+#if !LJ_SOFTFP
+ if (t == IRT_NUM) {
+ if (ofs < 1024) {
+ emit_vlso(as, ARMI_VLDR_D, dest, base, ofs);
+ } else {
+ if (ra_hasreg(type)) emit_lso(as, ARMI_LDR, type, base, ofs+4);
+ emit_vlso(as, ARMI_VLDR_D, dest, RID_TMP, 0);
+ emit_opk(as, ARMI_ADD, RID_TMP, base, ofs, allow);
+ return;
+ }
+ } else
+#endif
+ emit_lso(as, ARMI_LDR, dest, base, ofs);
+ }
+ if (ra_hasreg(type)) emit_lso(as, ARMI_LDR, type, base, ofs+4);
+}
+
+/* -- Allocations --------------------------------------------------------- */
+
+#if LJ_HASFFI
+static void asm_cnew(ASMState *as, IRIns *ir)
+{
+ CTState *cts = ctype_ctsG(J2G(as->J));
+ CTypeID ctypeid = (CTypeID)IR(ir->op1)->i;
+ CTSize sz = (ir->o == IR_CNEWI || ir->op2 == REF_NIL) ?
+ lj_ctype_size(cts, ctypeid) : (CTSize)IR(ir->op2)->i;
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];
+ IRRef args[2];
+ RegSet allow = (RSET_GPR & ~RSET_SCRATCH);
+ RegSet drop = RSET_SCRATCH;
+ lua_assert(sz != CTSIZE_INVALID);
+
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ASMREF_TMP1; /* MSize size */
+ as->gcsteps++;
+
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ ra_evictset(as, drop);
+ if (ra_used(ir))
+ ra_destreg(as, ir, RID_RET); /* GCcdata * */
+
+ /* Initialize immutable cdata object. */
+ if (ir->o == IR_CNEWI) {
+ int32_t ofs = sizeof(GCcdata);
+ lua_assert(sz == 4 || sz == 8);
+ if (sz == 8) {
+ ofs += 4; ir++;
+ lua_assert(ir->o == IR_HIOP);
+ }
+ for (;;) {
+ Reg r = ra_alloc1(as, ir->op2, allow);
+ emit_lso(as, ARMI_STR, r, RID_RET, ofs);
+ rset_clear(allow, r);
+ if (ofs == sizeof(GCcdata)) break;
+ ofs -= 4; ir--;
+ }
+ }
+ /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */
+ {
+ uint32_t k = emit_isk12(ARMI_MOV, ctypeid);
+ Reg r = k ? RID_R1 : ra_allock(as, ctypeid, allow);
+ emit_lso(as, ARMI_STRB, RID_TMP, RID_RET, offsetof(GCcdata, gct));
+ emit_lsox(as, ARMI_STRH, r, RID_RET, offsetof(GCcdata, ctypeid));
+ emit_d(as, ARMI_MOV|ARMI_K12|~LJ_TCDATA, RID_TMP);
+ if (k) emit_d(as, ARMI_MOV^k, RID_R1);
+ }
+ asm_gencall(as, ci, args);
+ ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)),
+ ra_releasetmp(as, ASMREF_TMP1));
+}
+#else
+#define asm_cnew(as, ir) ((void)0)
+#endif
+
+/* -- Write barriers ------------------------------------------------------ */
+
+static void asm_tbar(ASMState *as, IRIns *ir)
+{
+ Reg tab = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg link = ra_scratch(as, rset_exclude(RSET_GPR, tab));
+ Reg gr = ra_allock(as, i32ptr(J2G(as->J)),
+ rset_exclude(rset_exclude(RSET_GPR, tab), link));
+ Reg mark = RID_TMP;
+ MCLabel l_end = emit_label(as);
+ emit_lso(as, ARMI_STR, link, tab, (int32_t)offsetof(GCtab, gclist));
+ emit_lso(as, ARMI_STRB, mark, tab, (int32_t)offsetof(GCtab, marked));
+ emit_lso(as, ARMI_STR, tab, gr,
+ (int32_t)offsetof(global_State, gc.grayagain));
+ emit_dn(as, ARMI_BIC|ARMI_K12|LJ_GC_BLACK, mark, mark);
+ emit_lso(as, ARMI_LDR, link, gr,
+ (int32_t)offsetof(global_State, gc.grayagain));
+ emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end);
+ emit_n(as, ARMI_TST|ARMI_K12|LJ_GC_BLACK, mark);
+ emit_lso(as, ARMI_LDRB, mark, tab, (int32_t)offsetof(GCtab, marked));
+}
+
+static void asm_obar(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv];
+ IRRef args[2];
+ MCLabel l_end;
+ Reg obj, val, tmp;
+ /* No need for other object barriers (yet). */
+ lua_assert(IR(ir->op1)->o == IR_UREFC);
+ ra_evictset(as, RSET_SCRATCH);
+ l_end = emit_label(as);
+ args[0] = ASMREF_TMP1; /* global_State *g */
+ args[1] = ir->op1; /* TValue *tv */
+ asm_gencall(as, ci, args);
+ if ((l_end[-1] >> 28) == CC_AL)
+ l_end[-1] = ARMF_CC(l_end[-1], CC_NE);
+ else
+ emit_branch(as, ARMF_CC(ARMI_B, CC_EQ), l_end);
+ ra_allockreg(as, i32ptr(J2G(as->J)), ra_releasetmp(as, ASMREF_TMP1));
+ obj = IR(ir->op1)->r;
+ tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj));
+ emit_n(as, ARMF_CC(ARMI_TST, CC_NE)|ARMI_K12|LJ_GC_BLACK, tmp);
+ emit_n(as, ARMI_TST|ARMI_K12|LJ_GC_WHITES, RID_TMP);
+ val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj));
+ emit_lso(as, ARMI_LDRB, tmp, obj,
+ (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv));
+ emit_lso(as, ARMI_LDRB, RID_TMP, val, (int32_t)offsetof(GChead, marked));
+}
+
+/* -- Arithmetic and logic operations ------------------------------------- */
+
+#if !LJ_SOFTFP
+static void asm_fparith(ASMState *as, IRIns *ir, ARMIns ai)
+{
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg right, left = ra_alloc2(as, ir, RSET_FPR);
+ right = (left >> 8); left &= 255;
+ emit_dnm(as, ai, (dest & 15), (left & 15), (right & 15));
+}
+
+static void asm_fpunary(ASMState *as, IRIns *ir, ARMIns ai)
+{
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR);
+ emit_dm(as, ai, (dest & 15), (left & 15));
+}
+
+static int asm_fpjoin_pow(ASMState *as, IRIns *ir)
+{
+ IRIns *irp = IR(ir->op1);
+ if (irp == ir-1 && irp->o == IR_MUL && !ra_used(irp)) {
+ IRIns *irpp = IR(irp->op1);
+ if (irpp == ir-2 && irpp->o == IR_FPMATH &&
+ irpp->op2 == IRFPM_LOG2 && !ra_used(irpp)) {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_pow];
+ IRRef args[2];
+ args[0] = irpp->op1;
+ args[1] = irp->op2;
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+ return 1;
+ }
+ }
+ return 0;
+}
+#endif
+
+static int asm_swapops(ASMState *as, IRRef lref, IRRef rref)
+{
+ IRIns *ir;
+ if (irref_isk(rref))
+ return 0; /* Don't swap constants to the left. */
+ if (irref_isk(lref))
+ return 1; /* But swap constants to the right. */
+ ir = IR(rref);
+ if ((ir->o >= IR_BSHL && ir->o <= IR_BROR) ||
+ (ir->o == IR_ADD && ir->op1 == ir->op2))
+ return 0; /* Don't swap fusable operands to the left. */
+ ir = IR(lref);
+ if ((ir->o >= IR_BSHL && ir->o <= IR_BROR) ||
+ (ir->o == IR_ADD && ir->op1 == ir->op2))
+ return 1; /* But swap fusable operands to the right. */
+ return 0; /* Otherwise don't swap. */
+}
+
+static void asm_intop(ASMState *as, IRIns *ir, ARMIns ai)
+{
+ IRRef lref = ir->op1, rref = ir->op2;
+ Reg left, dest = ra_dest(as, ir, RSET_GPR);
+ uint32_t m;
+ if (asm_swapops(as, lref, rref)) {
+ IRRef tmp = lref; lref = rref; rref = tmp;
+ if ((ai & ~ARMI_S) == ARMI_SUB || (ai & ~ARMI_S) == ARMI_SBC)
+ ai ^= (ARMI_SUB^ARMI_RSB);
+ }
+ left = ra_hintalloc(as, lref, dest, RSET_GPR);
+ m = asm_fuseopm(as, ai, rref, rset_exclude(RSET_GPR, left));
+ if (irt_isguard(ir->t)) { /* For IR_ADDOV etc. */
+ asm_guardcc(as, CC_VS);
+ ai |= ARMI_S;
+ }
+ emit_dn(as, ai^m, dest, left);
+}
+
+static void asm_intop_s(ASMState *as, IRIns *ir, ARMIns ai)
+{
+ if (as->flagmcp == as->mcp) { /* Drop cmp r, #0. */
+ as->flagmcp = NULL;
+ as->mcp++;
+ ai |= ARMI_S;
+ }
+ asm_intop(as, ir, ai);
+}
+
+static void asm_bitop(ASMState *as, IRIns *ir, ARMIns ai)
+{
+ if (as->flagmcp == as->mcp) { /* Try to drop cmp r, #0. */
+ uint32_t cc = (as->mcp[1] >> 28);
+ as->flagmcp = NULL;
+ if (cc <= CC_NE) {
+ as->mcp++;
+ ai |= ARMI_S;
+ } else if (cc == CC_GE) {
+ *++as->mcp ^= ((CC_GE^CC_PL) << 28);
+ ai |= ARMI_S;
+ } else if (cc == CC_LT) {
+ *++as->mcp ^= ((CC_LT^CC_MI) << 28);
+ ai |= ARMI_S;
+ } /* else: other conds don't work with bit ops. */
+ }
+ if (ir->op2 == 0) {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ uint32_t m = asm_fuseopm(as, ai, ir->op1, RSET_GPR);
+ emit_d(as, ai^m, dest);
+ } else {
+ /* NYI: Turn BAND !k12 into uxtb, uxth or bfc or shl+shr. */
+ asm_intop(as, ir, ai);
+ }
+}
+
+static void asm_intneg(ASMState *as, IRIns *ir, ARMIns ai)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ emit_dn(as, ai|ARMI_K12|0, dest, left);
+}
+
+/* NYI: use add/shift for MUL(OV) with constants. FOLD only does 2^k. */
+static void asm_intmul(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, dest));
+ Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ Reg tmp = RID_NONE;
+ /* ARMv5 restriction: dest != left and dest_hi != left. */
+ if (dest == left && left != right) { left = right; right = dest; }
+ if (irt_isguard(ir->t)) { /* IR_MULOV */
+ if (!(as->flags & JIT_F_ARMV6) && dest == left)
+ tmp = left = ra_scratch(as, rset_exclude(RSET_GPR, left));
+ asm_guardcc(as, CC_NE);
+ emit_nm(as, ARMI_TEQ|ARMF_SH(ARMSH_ASR, 31), RID_TMP, dest);
+ emit_dnm(as, ARMI_SMULL|ARMF_S(right), dest, RID_TMP, left);
+ } else {
+ if (!(as->flags & JIT_F_ARMV6) && dest == left) tmp = left = RID_TMP;
+ emit_nm(as, ARMI_MUL|ARMF_S(right), dest, left);
+ }
+ /* Only need this for the dest == left == right case. */
+ if (ra_hasreg(tmp)) emit_dm(as, ARMI_MOV, tmp, right);
+}
+
+static void asm_add(ASMState *as, IRIns *ir)
+{
+#if !LJ_SOFTFP
+ if (irt_isnum(ir->t)) {
+ if (!asm_fusemadd(as, ir, ARMI_VMLA_D, ARMI_VMLA_D))
+ asm_fparith(as, ir, ARMI_VADD_D);
+ return;
+ }
+#endif
+ asm_intop_s(as, ir, ARMI_ADD);
+}
+
+static void asm_sub(ASMState *as, IRIns *ir)
+{
+#if !LJ_SOFTFP
+ if (irt_isnum(ir->t)) {
+ if (!asm_fusemadd(as, ir, ARMI_VNMLS_D, ARMI_VMLS_D))
+ asm_fparith(as, ir, ARMI_VSUB_D);
+ return;
+ }
+#endif
+ asm_intop_s(as, ir, ARMI_SUB);
+}
+
+static void asm_mul(ASMState *as, IRIns *ir)
+{
+#if !LJ_SOFTFP
+ if (irt_isnum(ir->t)) {
+ asm_fparith(as, ir, ARMI_VMUL_D);
+ return;
+ }
+#endif
+ asm_intmul(as, ir);
+}
+
+static void asm_neg(ASMState *as, IRIns *ir)
+{
+#if !LJ_SOFTFP
+ if (irt_isnum(ir->t)) {
+ asm_fpunary(as, ir, ARMI_VNEG_D);
+ return;
+ }
+#endif
+ asm_intneg(as, ir, ARMI_RSB);
+}
+
+static void asm_callid(ASMState *as, IRIns *ir, IRCallID id)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[id];
+ IRRef args[2];
+ args[0] = ir->op1;
+ args[1] = ir->op2;
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+
+#if !LJ_SOFTFP
+static void asm_callround(ASMState *as, IRIns *ir, int id)
+{
+ /* The modified regs must match with the *.dasc implementation. */
+ RegSet drop = RID2RSET(RID_R0)|RID2RSET(RID_R1)|RID2RSET(RID_R2)|
+ RID2RSET(RID_R3)|RID2RSET(RID_R12);
+ RegSet of;
+ Reg dest, src;
+ ra_evictset(as, drop);
+ dest = ra_dest(as, ir, RSET_FPR);
+ emit_dnm(as, ARMI_VMOV_D_RR, RID_RETLO, RID_RETHI, (dest & 15));
+ emit_call(as, id == IRFPM_FLOOR ? (void *)lj_vm_floor_sf :
+ id == IRFPM_CEIL ? (void *)lj_vm_ceil_sf :
+ (void *)lj_vm_trunc_sf);
+ /* Workaround to protect argument GPRs from being used for remat. */
+ of = as->freeset;
+ as->freeset &= ~RSET_RANGE(RID_R0, RID_R1+1);
+ as->cost[RID_R0] = as->cost[RID_R1] = REGCOST(~0u, ASMREF_L);
+ src = ra_alloc1(as, ir->op1, RSET_FPR); /* May alloc GPR to remat FPR. */
+ as->freeset |= (of & RSET_RANGE(RID_R0, RID_R1+1));
+ emit_dnm(as, ARMI_VMOV_RR_D, RID_R0, RID_R1, (src & 15));
+}
+#endif
+
+static void asm_bitswap(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
+ if ((as->flags & JIT_F_ARMV6)) {
+ emit_dm(as, ARMI_REV, dest, left);
+ } else {
+ Reg tmp2 = dest;
+ if (tmp2 == left)
+ tmp2 = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, dest), left));
+ emit_dnm(as, ARMI_EOR|ARMF_SH(ARMSH_LSR, 8), dest, tmp2, RID_TMP);
+ emit_dm(as, ARMI_MOV|ARMF_SH(ARMSH_ROR, 8), tmp2, left);
+ emit_dn(as, ARMI_BIC|ARMI_K12|256*8|255, RID_TMP, RID_TMP);
+ emit_dnm(as, ARMI_EOR|ARMF_SH(ARMSH_ROR, 16), RID_TMP, left, left);
+ }
+}
+
+static void asm_bitshift(ASMState *as, IRIns *ir, ARMShift sh)
+{
+ if (irref_isk(ir->op2)) { /* Constant shifts. */
+ /* NYI: Turn SHL+SHR or BAND+SHR into uxtb, uxth or ubfx. */
+ /* NYI: Turn SHL+ASR into sxtb, sxth or sbfx. */
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
+ int32_t shift = (IR(ir->op2)->i & 31);
+ emit_dm(as, ARMI_MOV|ARMF_SH(sh, shift), dest, left);
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_dm(as, ARMI_MOV|ARMF_RSH(sh, right), dest, left);
+ }
+}
+
+static void asm_intmin_max(ASMState *as, IRIns *ir, int cc)
+{
+ uint32_t kcmp = 0, kmov = 0;
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ Reg right = 0;
+ if (irref_isk(ir->op2)) {
+ kcmp = emit_isk12(ARMI_CMP, IR(ir->op2)->i);
+ if (kcmp) kmov = emit_isk12(ARMI_MOV, IR(ir->op2)->i);
+ }
+ if (!kmov) {
+ kcmp = 0;
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ }
+ if (kmov || dest != right) {
+ emit_dm(as, ARMF_CC(ARMI_MOV, cc)^kmov, dest, right);
+ cc ^= 1; /* Must use opposite conditions for paired moves. */
+ } else {
+ cc ^= (CC_LT^CC_GT); /* Otherwise may swap CC_LT <-> CC_GT. */
+ }
+ if (dest != left) emit_dm(as, ARMF_CC(ARMI_MOV, cc), dest, left);
+ emit_nm(as, ARMI_CMP^kcmp, left, right);
+}
+
+#if LJ_SOFTFP
+static void asm_sfpmin_max(ASMState *as, IRIns *ir, int cc)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_softfp_cmp];
+ RegSet drop = RSET_SCRATCH;
+ Reg r;
+ IRRef args[4];
+ args[0] = ir->op1; args[1] = (ir+1)->op1;
+ args[2] = ir->op2; args[3] = (ir+1)->op2;
+ /* __aeabi_cdcmple preserves r0-r3. */
+ if (ra_hasreg(ir->r)) rset_clear(drop, ir->r);
+ if (ra_hasreg((ir+1)->r)) rset_clear(drop, (ir+1)->r);
+ if (!rset_test(as->freeset, RID_R2) &&
+ regcost_ref(as->cost[RID_R2]) == args[2]) rset_clear(drop, RID_R2);
+ if (!rset_test(as->freeset, RID_R3) &&
+ regcost_ref(as->cost[RID_R3]) == args[3]) rset_clear(drop, RID_R3);
+ ra_evictset(as, drop);
+ ra_destpair(as, ir);
+ emit_dm(as, ARMF_CC(ARMI_MOV, cc), RID_RETHI, RID_R3);
+ emit_dm(as, ARMF_CC(ARMI_MOV, cc), RID_RETLO, RID_R2);
+ emit_call(as, (void *)ci->func);
+ for (r = RID_R0; r <= RID_R3; r++)
+ ra_leftov(as, r, args[r-RID_R0]);
+}
+#else
+static void asm_fpmin_max(ASMState *as, IRIns *ir, int cc)
+{
+ Reg dest = (ra_dest(as, ir, RSET_FPR) & 15);
+ Reg right, left = ra_alloc2(as, ir, RSET_FPR);
+ right = ((left >> 8) & 15); left &= 15;
+ if (dest != left) emit_dm(as, ARMF_CC(ARMI_VMOV_D, cc^1), dest, left);
+ if (dest != right) emit_dm(as, ARMF_CC(ARMI_VMOV_D, cc), dest, right);
+ emit_d(as, ARMI_VMRS, 0);
+ emit_dm(as, ARMI_VCMP_D, left, right);
+}
+#endif
+
+static void asm_min_max(ASMState *as, IRIns *ir, int cc, int fcc)
+{
+#if LJ_SOFTFP
+ UNUSED(fcc);
+#else
+ if (irt_isnum(ir->t))
+ asm_fpmin_max(as, ir, fcc);
+ else
+#endif
+ asm_intmin_max(as, ir, cc);
+}
+
+/* -- Comparisons --------------------------------------------------------- */
+
+/* Map of comparisons to flags. ORDER IR. */
+static const uint8_t asm_compmap[IR_ABC+1] = {
+ /* op FP swp int cc FP cc */
+ /* LT */ CC_GE + (CC_HS << 4),
+ /* GE x */ CC_LT + (CC_HI << 4),
+ /* LE */ CC_GT + (CC_HI << 4),
+ /* GT x */ CC_LE + (CC_HS << 4),
+ /* ULT x */ CC_HS + (CC_LS << 4),
+ /* UGE */ CC_LO + (CC_LO << 4),
+ /* ULE x */ CC_HI + (CC_LO << 4),
+ /* UGT */ CC_LS + (CC_LS << 4),
+ /* EQ */ CC_NE + (CC_NE << 4),
+ /* NE */ CC_EQ + (CC_EQ << 4),
+ /* ABC */ CC_LS + (CC_LS << 4) /* Same as UGT. */
+};
+
+#if LJ_SOFTFP
+/* FP comparisons. */
+static void asm_sfpcomp(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_softfp_cmp];
+ RegSet drop = RSET_SCRATCH;
+ Reg r;
+ IRRef args[4];
+ int swp = (((ir->o ^ (ir->o >> 2)) & ~(ir->o >> 3) & 1) << 1);
+ args[swp^0] = ir->op1; args[swp^1] = (ir+1)->op1;
+ args[swp^2] = ir->op2; args[swp^3] = (ir+1)->op2;
+ /* __aeabi_cdcmple preserves r0-r3. This helps to reduce spills. */
+ for (r = RID_R0; r <= RID_R3; r++)
+ if (!rset_test(as->freeset, r) &&
+ regcost_ref(as->cost[r]) == args[r-RID_R0]) rset_clear(drop, r);
+ ra_evictset(as, drop);
+ asm_guardcc(as, (asm_compmap[ir->o] >> 4));
+ emit_call(as, (void *)ci->func);
+ for (r = RID_R0; r <= RID_R3; r++)
+ ra_leftov(as, r, args[r-RID_R0]);
+}
+#else
+/* FP comparisons. */
+static void asm_fpcomp(ASMState *as, IRIns *ir)
+{
+ Reg left, right;
+ ARMIns ai;
+ int swp = ((ir->o ^ (ir->o >> 2)) & ~(ir->o >> 3) & 1);
+ if (!swp && irref_isk(ir->op2) && ir_knum(IR(ir->op2))->u64 == 0) {
+ left = (ra_alloc1(as, ir->op1, RSET_FPR) & 15);
+ right = 0;
+ ai = ARMI_VCMPZ_D;
+ } else {
+ left = ra_alloc2(as, ir, RSET_FPR);
+ if (swp) {
+ right = (left & 15); left = ((left >> 8) & 15);
+ } else {
+ right = ((left >> 8) & 15); left &= 15;
+ }
+ ai = ARMI_VCMP_D;
+ }
+ asm_guardcc(as, (asm_compmap[ir->o] >> 4));
+ emit_d(as, ARMI_VMRS, 0);
+ emit_dm(as, ai, left, right);
+}
+#endif
+
+/* Integer comparisons. */
+static void asm_intcomp(ASMState *as, IRIns *ir)
+{
+ ARMCC cc = (asm_compmap[ir->o] & 15);
+ IRRef lref = ir->op1, rref = ir->op2;
+ Reg left;
+ uint32_t m;
+ int cmpprev0 = 0;
+ lua_assert(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t));
+ if (asm_swapops(as, lref, rref)) {
+ Reg tmp = lref; lref = rref; rref = tmp;
+ if (cc >= CC_GE) cc ^= 7; /* LT <-> GT, LE <-> GE */
+ else if (cc > CC_NE) cc ^= 11; /* LO <-> HI, LS <-> HS */
+ }
+ if (irref_isk(rref) && IR(rref)->i == 0) {
+ IRIns *irl = IR(lref);
+ cmpprev0 = (irl+1 == ir);
+ /* Combine comp(BAND(left, right), 0) into tst left, right. */
+ if (cmpprev0 && irl->o == IR_BAND && !ra_used(irl)) {
+ IRRef blref = irl->op1, brref = irl->op2;
+ uint32_t m2 = 0;
+ Reg bleft;
+ if (asm_swapops(as, blref, brref)) {
+ Reg tmp = blref; blref = brref; brref = tmp;
+ }
+ if (irref_isk(brref)) {
+ m2 = emit_isk12(ARMI_AND, IR(brref)->i);
+ if ((m2 & (ARMI_AND^ARMI_BIC)))
+ goto notst; /* Not beneficial if we miss a constant operand. */
+ }
+ if (cc == CC_GE) cc = CC_PL;
+ else if (cc == CC_LT) cc = CC_MI;
+ else if (cc > CC_NE) goto notst; /* Other conds don't work with tst. */
+ bleft = ra_alloc1(as, blref, RSET_GPR);
+ if (!m2) m2 = asm_fuseopm(as, 0, brref, rset_exclude(RSET_GPR, bleft));
+ asm_guardcc(as, cc);
+ emit_n(as, ARMI_TST^m2, bleft);
+ return;
+ }
+ }
+notst:
+ left = ra_alloc1(as, lref, RSET_GPR);
+ m = asm_fuseopm(as, ARMI_CMP, rref, rset_exclude(RSET_GPR, left));
+ asm_guardcc(as, cc);
+ emit_n(as, ARMI_CMP^m, left);
+ /* Signed comparison with zero and referencing previous ins? */
+ if (cmpprev0 && (cc <= CC_NE || cc >= CC_GE))
+ as->flagmcp = as->mcp; /* Allow elimination of the compare. */
+}
+
+#if LJ_HASFFI
+/* 64 bit integer comparisons. */
+static void asm_int64comp(ASMState *as, IRIns *ir)
+{
+ int signedcomp = (ir->o <= IR_GT);
+ ARMCC cclo, cchi;
+ Reg leftlo, lefthi;
+ uint32_t mlo, mhi;
+ RegSet allow = RSET_GPR, oldfree;
+
+ /* Always use unsigned comparison for loword. */
+ cclo = asm_compmap[ir->o + (signedcomp ? 4 : 0)] & 15;
+ leftlo = ra_alloc1(as, ir->op1, allow);
+ oldfree = as->freeset;
+ mlo = asm_fuseopm(as, ARMI_CMP, ir->op2, rset_clear(allow, leftlo));
+ allow &= ~(oldfree & ~as->freeset); /* Update for allocs of asm_fuseopm. */
+
+ /* Use signed or unsigned comparison for hiword. */
+ cchi = asm_compmap[ir->o] & 15;
+ lefthi = ra_alloc1(as, (ir+1)->op1, allow);
+ mhi = asm_fuseopm(as, ARMI_CMP, (ir+1)->op2, rset_clear(allow, lefthi));
+
+ /* All register allocations must be performed _before_ this point. */
+ if (signedcomp) {
+ MCLabel l_around = emit_label(as);
+ asm_guardcc(as, cclo);
+ emit_n(as, ARMI_CMP^mlo, leftlo);
+ emit_branch(as, ARMF_CC(ARMI_B, CC_NE), l_around);
+ if (cchi == CC_GE || cchi == CC_LE) cchi ^= 6; /* GE -> GT, LE -> LT */
+ asm_guardcc(as, cchi);
+ } else {
+ asm_guardcc(as, cclo);
+ emit_n(as, ARMF_CC(ARMI_CMP, CC_EQ)^mlo, leftlo);
+ }
+ emit_n(as, ARMI_CMP^mhi, lefthi);
+}
+#endif
+
+/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */
+
+/* Hiword op of a split 64 bit op. Previous op must be the loword op. */
+static void asm_hiop(ASMState *as, IRIns *ir)
+{
+#if LJ_HASFFI || LJ_SOFTFP
+ /* HIOP is marked as a store because it needs its own DCE logic. */
+ int uselo = ra_used(ir-1), usehi = ra_used(ir); /* Loword/hiword used? */
+ if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1;
+ if ((ir-1)->o <= IR_NE) { /* 64 bit integer or FP comparisons. ORDER IR. */
+ as->curins--; /* Always skip the loword comparison. */
+#if LJ_SOFTFP
+ if (!irt_isint(ir->t)) {
+ asm_sfpcomp(as, ir-1);
+ return;
+ }
+#endif
+#if LJ_HASFFI
+ asm_int64comp(as, ir-1);
+#endif
+ return;
+#if LJ_SOFTFP
+ } else if ((ir-1)->o == IR_MIN || (ir-1)->o == IR_MAX) {
+ as->curins--; /* Always skip the loword min/max. */
+ if (uselo || usehi)
+ asm_sfpmin_max(as, ir-1, (ir-1)->o == IR_MIN ? CC_HI : CC_LO);
+ return;
+#elif LJ_HASFFI
+ } else if ((ir-1)->o == IR_CONV) {
+ as->curins--; /* Always skip the CONV. */
+ if (usehi || uselo)
+ asm_conv64(as, ir);
+ return;
+#endif
+ } else if ((ir-1)->o == IR_XSTORE) {
+ if ((ir-1)->r != RID_SINK)
+ asm_xstore(as, ir, 4);
+ return;
+ }
+ if (!usehi) return; /* Skip unused hiword op for all remaining ops. */
+ switch ((ir-1)->o) {
+#if LJ_HASFFI
+ case IR_ADD:
+ as->curins--;
+ asm_intop(as, ir, ARMI_ADC);
+ asm_intop(as, ir-1, ARMI_ADD|ARMI_S);
+ break;
+ case IR_SUB:
+ as->curins--;
+ asm_intop(as, ir, ARMI_SBC);
+ asm_intop(as, ir-1, ARMI_SUB|ARMI_S);
+ break;
+ case IR_NEG:
+ as->curins--;
+ asm_intneg(as, ir, ARMI_RSC);
+ asm_intneg(as, ir-1, ARMI_RSB|ARMI_S);
+ break;
+#endif
+#if LJ_SOFTFP
+ case IR_SLOAD: case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:
+ case IR_STRTO:
+ if (!uselo)
+ ra_allocref(as, ir->op1, RSET_GPR); /* Mark lo op as used. */
+ break;
+#endif
+ case IR_CALLN:
+ case IR_CALLS:
+ case IR_CALLXS:
+ if (!uselo)
+ ra_allocref(as, ir->op1, RID2RSET(RID_RETLO)); /* Mark lo op as used. */
+ break;
+#if LJ_SOFTFP
+ case IR_ASTORE: case IR_HSTORE: case IR_USTORE: case IR_TOSTR:
+#endif
+ case IR_CNEWI:
+ /* Nothing to do here. Handled by lo op itself. */
+ break;
+ default: lua_assert(0); break;
+ }
+#else
+ UNUSED(as); UNUSED(ir); lua_assert(0);
+#endif
+}
+
+/* -- Stack handling ------------------------------------------------------ */
+
+/* Check Lua stack size for overflow. Use exit handler as fallback. */
+static void asm_stack_check(ASMState *as, BCReg topslot,
+ IRIns *irp, RegSet allow, ExitNo exitno)
+{
+ Reg pbase;
+ uint32_t k;
+ if (irp) {
+ if (!ra_hasspill(irp->s)) {
+ pbase = irp->r;
+ lua_assert(ra_hasreg(pbase));
+ } else if (allow) {
+ pbase = rset_pickbot(allow);
+ } else {
+ pbase = RID_RET;
+ emit_lso(as, ARMI_LDR, RID_RET, RID_SP, 0); /* Restore temp. register. */
+ }
+ } else {
+ pbase = RID_BASE;
+ }
+ emit_branch(as, ARMF_CC(ARMI_BL, CC_LS), exitstub_addr(as->J, exitno));
+ k = emit_isk12(0, (int32_t)(8*topslot));
+ lua_assert(k);
+ emit_n(as, ARMI_CMP^k, RID_TMP);
+ emit_dnm(as, ARMI_SUB, RID_TMP, RID_TMP, pbase);
+ emit_lso(as, ARMI_LDR, RID_TMP, RID_TMP,
+ (int32_t)offsetof(lua_State, maxstack));
+ if (irp) { /* Must not spill arbitrary registers in head of side trace. */
+ int32_t i = i32ptr(&J2G(as->J)->jit_L);
+ if (ra_hasspill(irp->s))
+ emit_lso(as, ARMI_LDR, pbase, RID_SP, sps_scale(irp->s));
+ emit_lso(as, ARMI_LDR, RID_TMP, RID_TMP, (i & 4095));
+ if (ra_hasspill(irp->s) && !allow)
+ emit_lso(as, ARMI_STR, RID_RET, RID_SP, 0); /* Save temp. register. */
+ emit_loadi(as, RID_TMP, (i & ~4095));
+ } else {
+ emit_getgl(as, RID_TMP, jit_L);
+ }
+}
+
+/* Restore Lua stack from on-trace state. */
+static void asm_stack_restore(ASMState *as, SnapShot *snap)
+{
+ SnapEntry *map = &as->T->snapmap[snap->mapofs];
+ SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1];
+ MSize n, nent = snap->nent;
+ /* Store the value of all modified slots to the Lua stack. */
+ for (n = 0; n < nent; n++) {
+ SnapEntry sn = map[n];
+ BCReg s = snap_slot(sn);
+ int32_t ofs = 8*((int32_t)s-1);
+ IRRef ref = snap_ref(sn);
+ IRIns *ir = IR(ref);
+ if ((sn & SNAP_NORESTORE))
+ continue;
+ if (irt_isnum(ir->t)) {
+#if LJ_SOFTFP
+ RegSet odd = rset_exclude(RSET_GPRODD, RID_BASE);
+ Reg tmp;
+ lua_assert(irref_isk(ref)); /* LJ_SOFTFP: must be a number constant. */
+ tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.lo,
+ rset_exclude(RSET_GPREVEN, RID_BASE));
+ emit_lso(as, ARMI_STR, tmp, RID_BASE, ofs);
+ if (rset_test(as->freeset, tmp+1)) odd = RID2RSET(tmp+1);
+ tmp = ra_allock(as, (int32_t)ir_knum(ir)->u32.hi, odd);
+ emit_lso(as, ARMI_STR, tmp, RID_BASE, ofs+4);
+#else
+ Reg src = ra_alloc1(as, ref, RSET_FPR);
+ emit_vlso(as, ARMI_VSTR_D, src, RID_BASE, ofs);
+#endif
+ } else {
+ RegSet odd = rset_exclude(RSET_GPRODD, RID_BASE);
+ Reg type;
+ lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t));
+ if (!irt_ispri(ir->t)) {
+ Reg src = ra_alloc1(as, ref, rset_exclude(RSET_GPREVEN, RID_BASE));
+ emit_lso(as, ARMI_STR, src, RID_BASE, ofs);
+ if (rset_test(as->freeset, src+1)) odd = RID2RSET(src+1);
+ }
+ if ((sn & (SNAP_CONT|SNAP_FRAME))) {
+ if (s == 0) continue; /* Do not overwrite link to previous frame. */
+ type = ra_allock(as, (int32_t)(*flinks--), odd);
+#if LJ_SOFTFP
+ } else if ((sn & SNAP_SOFTFPNUM)) {
+ type = ra_alloc1(as, ref+1, rset_exclude(RSET_GPRODD, RID_BASE));
+#endif
+ } else {
+ type = ra_allock(as, (int32_t)irt_toitype(ir->t), odd);
+ }
+ emit_lso(as, ARMI_STR, type, RID_BASE, ofs+4);
+ }
+ checkmclim(as);
+ }
+ lua_assert(map + nent == flinks);
+}
+
+/* -- GC handling --------------------------------------------------------- */
+
+/* Check GC threshold and do one or more GC steps. */
+static void asm_gc_check(ASMState *as)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit];
+ IRRef args[2];
+ MCLabel l_end;
+ Reg tmp1, tmp2;
+ ra_evictset(as, RSET_SCRATCH);
+ l_end = emit_label(as);
+ /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */
+ asm_guardcc(as, CC_NE); /* Assumes asm_snap_prep() already done. */
+ emit_n(as, ARMI_CMP|ARMI_K12|0, RID_RET);
+ args[0] = ASMREF_TMP1; /* global_State *g */
+ args[1] = ASMREF_TMP2; /* MSize steps */
+ asm_gencall(as, ci, args);
+ tmp1 = ra_releasetmp(as, ASMREF_TMP1);
+ tmp2 = ra_releasetmp(as, ASMREF_TMP2);
+ emit_loadi(as, tmp2, as->gcsteps);
+ /* Jump around GC step if GC total < GC threshold. */
+ emit_branch(as, ARMF_CC(ARMI_B, CC_LS), l_end);
+ emit_nm(as, ARMI_CMP, RID_TMP, tmp2);
+ emit_lso(as, ARMI_LDR, tmp2, tmp1,
+ (int32_t)offsetof(global_State, gc.threshold));
+ emit_lso(as, ARMI_LDR, RID_TMP, tmp1,
+ (int32_t)offsetof(global_State, gc.total));
+ ra_allockreg(as, i32ptr(J2G(as->J)), tmp1);
+ as->gcsteps = 0;
+ checkmclim(as);
+}
+
+/* -- Loop handling ------------------------------------------------------- */
+
+/* Fixup the loop branch. */
+static void asm_loop_fixup(ASMState *as)
+{
+ MCode *p = as->mctop;
+ MCode *target = as->mcp;
+ if (as->loopinv) { /* Inverted loop branch? */
+ /* asm_guardcc already inverted the bcc and patched the final bl. */
+ p[-2] |= ((uint32_t)(target-p) & 0x00ffffffu);
+ } else {
+ p[-1] = ARMI_B | ((uint32_t)((target-p)-1) & 0x00ffffffu);
+ }
+}
+
+/* -- Head of trace ------------------------------------------------------- */
+
+/* Reload L register from g->jit_L. */
+static void asm_head_lreg(ASMState *as)
+{
+ IRIns *ir = IR(ASMREF_L);
+ if (ra_used(ir)) {
+ Reg r = ra_dest(as, ir, RSET_GPR);
+ emit_getgl(as, r, jit_L);
+ ra_evictk(as);
+ }
+}
+
+/* Coalesce BASE register for a root trace. */
+static void asm_head_root_base(ASMState *as)
+{
+ IRIns *ir;
+ asm_head_lreg(as);
+ ir = IR(REF_BASE);
+ if (ra_hasreg(ir->r) && (rset_test(as->modset, ir->r) || irt_ismarked(ir->t)))
+ ra_spill(as, ir);
+ ra_destreg(as, ir, RID_BASE);
+}
+
+/* Coalesce BASE register for a side trace. */
+static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow)
+{
+ IRIns *ir;
+ asm_head_lreg(as);
+ ir = IR(REF_BASE);
+ if (ra_hasreg(ir->r) && (rset_test(as->modset, ir->r) || irt_ismarked(ir->t)))
+ ra_spill(as, ir);
+ if (ra_hasspill(irp->s)) {
+ rset_clear(allow, ra_dest(as, ir, allow));
+ } else {
+ Reg r = irp->r;
+ lua_assert(ra_hasreg(r));
+ rset_clear(allow, r);
+ if (r != ir->r && !rset_test(as->freeset, r))
+ ra_restore(as, regcost_ref(as->cost[r]));
+ ra_destreg(as, ir, r);
+ }
+ return allow;
+}
+
+/* -- Tail of trace ------------------------------------------------------- */
+
+/* Fixup the tail code. */
+static void asm_tail_fixup(ASMState *as, TraceNo lnk)
+{
+ MCode *p = as->mctop;
+ MCode *target;
+ int32_t spadj = as->T->spadjust;
+ if (spadj == 0) {
+ as->mctop = --p;
+ } else {
+ /* Patch stack adjustment. */
+ uint32_t k = emit_isk12(ARMI_ADD, spadj);
+ lua_assert(k);
+ p[-2] = (ARMI_ADD^k) | ARMF_D(RID_SP) | ARMF_N(RID_SP);
+ }
+ /* Patch exit branch. */
+ target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp;
+ p[-1] = ARMI_B|(((target-p)-1)&0x00ffffffu);
+}
+
+/* Prepare tail of code. */
+static void asm_tail_prep(ASMState *as)
+{
+ MCode *p = as->mctop - 1; /* Leave room for exit branch. */
+ if (as->loopref) {
+ as->invmcp = as->mcp = p;
+ } else {
+ as->mcp = p-1; /* Leave room for stack pointer adjustment. */
+ as->invmcp = NULL;
+ }
+ *p = 0; /* Prevent load/store merging. */
+}
+
+/* -- Instruction dispatch ------------------------------------------------ */
+
+/* Assemble a single instruction. */
+static void asm_ir(ASMState *as, IRIns *ir)
+{
+ switch ((IROp)ir->o) {
+ /* Miscellaneous ops. */
+ case IR_LOOP: asm_loop(as); break;
+ case IR_NOP: case IR_XBAR: lua_assert(!ra_used(ir)); break;
+ case IR_USE:
+ ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break;
+ case IR_PHI: asm_phi(as, ir); break;
+ case IR_HIOP: asm_hiop(as, ir); break;
+ case IR_GCSTEP: asm_gcstep(as, ir); break;
+
+ /* Guarded assertions. */
+ case IR_EQ: case IR_NE:
+ if ((ir-1)->o == IR_HREF && ir->op1 == as->curins-1) {
+ as->curins--;
+ asm_href(as, ir-1, (IROp)ir->o);
+ break;
+ }
+ /* fallthrough */
+ case IR_LT: case IR_GE: case IR_LE: case IR_GT:
+ case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT:
+ case IR_ABC:
+#if !LJ_SOFTFP
+ if (irt_isnum(ir->t)) { asm_fpcomp(as, ir); break; }
+#endif
+ asm_intcomp(as, ir);
+ break;
+
+ case IR_RETF: asm_retf(as, ir); break;
+
+ /* Bit ops. */
+ case IR_BNOT: asm_bitop(as, ir, ARMI_MVN); break;
+ case IR_BSWAP: asm_bitswap(as, ir); break;
+
+ case IR_BAND: asm_bitop(as, ir, ARMI_AND); break;
+ case IR_BOR: asm_bitop(as, ir, ARMI_ORR); break;
+ case IR_BXOR: asm_bitop(as, ir, ARMI_EOR); break;
+
+ case IR_BSHL: asm_bitshift(as, ir, ARMSH_LSL); break;
+ case IR_BSHR: asm_bitshift(as, ir, ARMSH_LSR); break;
+ case IR_BSAR: asm_bitshift(as, ir, ARMSH_ASR); break;
+ case IR_BROR: asm_bitshift(as, ir, ARMSH_ROR); break;
+ case IR_BROL: lua_assert(0); break;
+
+ /* Arithmetic ops. */
+ case IR_ADD: case IR_ADDOV: asm_add(as, ir); break;
+ case IR_SUB: case IR_SUBOV: asm_sub(as, ir); break;
+ case IR_MUL: case IR_MULOV: asm_mul(as, ir); break;
+ case IR_MOD: asm_callid(as, ir, IRCALL_lj_vm_modi); break;
+ case IR_NEG: asm_neg(as, ir); break;
+
+#if LJ_SOFTFP
+ case IR_DIV: case IR_POW: case IR_ABS:
+ case IR_ATAN2: case IR_LDEXP: case IR_FPMATH: case IR_TOBIT:
+ lua_assert(0); /* Unused for LJ_SOFTFP. */
+ break;
+#else
+ case IR_DIV: asm_fparith(as, ir, ARMI_VDIV_D); break;
+ case IR_POW: asm_callid(as, ir, IRCALL_lj_vm_powi); break;
+ case IR_ABS: asm_fpunary(as, ir, ARMI_VABS_D); break;
+ case IR_ATAN2: asm_callid(as, ir, IRCALL_atan2); break;
+ case IR_LDEXP: asm_callid(as, ir, IRCALL_ldexp); break;
+ case IR_FPMATH:
+ if (ir->op2 == IRFPM_EXP2 && asm_fpjoin_pow(as, ir))
+ break;
+ if (ir->op2 <= IRFPM_TRUNC)
+ asm_callround(as, ir, ir->op2);
+ else if (ir->op2 == IRFPM_SQRT)
+ asm_fpunary(as, ir, ARMI_VSQRT_D);
+ else
+ asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2);
+ break;
+ case IR_TOBIT: asm_tobit(as, ir); break;
+#endif
+
+ case IR_MIN: asm_min_max(as, ir, CC_GT, CC_HI); break;
+ case IR_MAX: asm_min_max(as, ir, CC_LT, CC_LO); break;
+
+ /* Memory references. */
+ case IR_AREF: asm_aref(as, ir); break;
+ case IR_HREF: asm_href(as, ir, 0); break;
+ case IR_HREFK: asm_hrefk(as, ir); break;
+ case IR_NEWREF: asm_newref(as, ir); break;
+ case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break;
+ case IR_FREF: asm_fref(as, ir); break;
+ case IR_STRREF: asm_strref(as, ir); break;
+
+ /* Loads and stores. */
+ case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:
+ asm_ahuvload(as, ir);
+ break;
+ case IR_FLOAD: asm_fload(as, ir); break;
+ case IR_XLOAD: asm_xload(as, ir); break;
+ case IR_SLOAD: asm_sload(as, ir); break;
+
+ case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break;
+ case IR_FSTORE: asm_fstore(as, ir); break;
+ case IR_XSTORE: asm_xstore(as, ir, 0); break;
+
+ /* Allocations. */
+ case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break;
+ case IR_TNEW: asm_tnew(as, ir); break;
+ case IR_TDUP: asm_tdup(as, ir); break;
+ case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break;
+
+ /* Write barriers. */
+ case IR_TBAR: asm_tbar(as, ir); break;
+ case IR_OBAR: asm_obar(as, ir); break;
+
+ /* Type conversions. */
+ case IR_CONV: asm_conv(as, ir); break;
+ case IR_TOSTR: asm_tostr(as, ir); break;
+ case IR_STRTO: asm_strto(as, ir); break;
+
+ /* Calls. */
+ case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break;
+ case IR_CALLXS: asm_callx(as, ir); break;
+ case IR_CARG: break;
+
+ default:
+ setintV(&as->J->errinfo, ir->o);
+ lj_trace_err_info(as->J, LJ_TRERR_NYIIR);
+ break;
+ }
+}
+
+/* -- Trace setup --------------------------------------------------------- */
+
+/* Ensure there are enough stack slots for call arguments. */
+static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)
+{
+ IRRef args[CCI_NARGS_MAX*2];
+ uint32_t i, nargs = (int)CCI_NARGS(ci);
+ int nslots = 0, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR, fprodd = 0;
+ asm_collectargs(as, ir, ci, args);
+ for (i = 0; i < nargs; i++) {
+ if (!LJ_SOFTFP && args[i] && irt_isfp(IR(args[i])->t)) {
+ if (!LJ_ABI_SOFTFP && !(ci->flags & CCI_VARARG)) {
+ if (irt_isnum(IR(args[i])->t)) {
+ if (nfpr > 0) nfpr--;
+ else fprodd = 0, nslots = (nslots + 3) & ~1;
+ } else {
+ if (fprodd) fprodd--;
+ else if (nfpr > 0) fprodd = 1, nfpr--;
+ else nslots++;
+ }
+ } else if (irt_isnum(IR(args[i])->t)) {
+ ngpr &= ~1;
+ if (ngpr > 0) ngpr -= 2; else nslots += 2;
+ } else {
+ if (ngpr > 0) ngpr--; else nslots++;
+ }
+ } else {
+ if (ngpr > 0) ngpr--; else nslots++;
+ }
+ }
+ if (nslots > as->evenspill) /* Leave room for args in stack slots. */
+ as->evenspill = nslots;
+ return REGSP_HINT(RID_RET);
+}
+
+static void asm_setup_target(ASMState *as)
+{
+ /* May need extra exit for asm_stack_check on side traces. */
+ asm_exitstub_setup(as, as->T->nsnap + (as->parent ? 1 : 0));
+}
+
+/* -- Trace patching ------------------------------------------------------ */
+
+/* Patch exit jumps of existing machine code to a new target. */
+void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target)
+{
+ MCode *p = T->mcode;
+ MCode *pe = (MCode *)((char *)p + T->szmcode);
+ MCode *cstart = NULL, *cend = p;
+ MCode *mcarea = lj_mcode_patch(J, p, 0);
+ MCode *px = exitstub_addr(J, exitno) - 2;
+ for (; p < pe; p++) {
+ /* Look for bl_cc exitstub, replace with b_cc target. */
+ uint32_t ins = *p;
+ if ((ins & 0x0f000000u) == 0x0b000000u && ins < 0xf0000000u &&
+ ((ins ^ (px-p)) & 0x00ffffffu) == 0) {
+ *p = (ins & 0xfe000000u) | (((target-p)-2) & 0x00ffffffu);
+ cend = p+1;
+ if (!cstart) cstart = p;
+ }
+ }
+ lua_assert(cstart != NULL);
+ lj_mcode_sync(cstart, cend);
+ lj_mcode_patch(J, mcarea, 1);
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_asm_mips.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_asm_mips.h
new file mode 100644
index 0000000..7631190
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_asm_mips.h
@@ -0,0 +1,1977 @@
+/*
+** MIPS IR assembler (SSA IR -> machine code).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* -- Register allocator extensions --------------------------------------- */
+
+/* Allocate a register with a hint. */
+static Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow)
+{
+ Reg r = IR(ref)->r;
+ if (ra_noreg(r)) {
+ if (!ra_hashint(r) && !iscrossref(as, ref))
+ ra_sethint(IR(ref)->r, hint); /* Propagate register hint. */
+ r = ra_allocref(as, ref, allow);
+ }
+ ra_noweak(as, r);
+ return r;
+}
+
+/* Allocate a register or RID_ZERO. */
+static Reg ra_alloc1z(ASMState *as, IRRef ref, RegSet allow)
+{
+ Reg r = IR(ref)->r;
+ if (ra_noreg(r)) {
+ if (!(allow & RSET_FPR) && irref_isk(ref) && IR(ref)->i == 0)
+ return RID_ZERO;
+ r = ra_allocref(as, ref, allow);
+ } else {
+ ra_noweak(as, r);
+ }
+ return r;
+}
+
+/* Allocate two source registers for three-operand instructions. */
+static Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow)
+{
+ IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);
+ Reg left = irl->r, right = irr->r;
+ if (ra_hasreg(left)) {
+ ra_noweak(as, left);
+ if (ra_noreg(right))
+ right = ra_alloc1z(as, ir->op2, rset_exclude(allow, left));
+ else
+ ra_noweak(as, right);
+ } else if (ra_hasreg(right)) {
+ ra_noweak(as, right);
+ left = ra_alloc1z(as, ir->op1, rset_exclude(allow, right));
+ } else if (ra_hashint(right)) {
+ right = ra_alloc1z(as, ir->op2, allow);
+ left = ra_alloc1z(as, ir->op1, rset_exclude(allow, right));
+ } else {
+ left = ra_alloc1z(as, ir->op1, allow);
+ right = ra_alloc1z(as, ir->op2, rset_exclude(allow, left));
+ }
+ return left | (right << 8);
+}
+
+/* -- Guard handling ------------------------------------------------------ */
+
+/* Need some spare long-range jump slots, for out-of-range branches. */
+#define MIPS_SPAREJUMP 4
+
+/* Setup spare long-range jump slots per mcarea. */
+static void asm_sparejump_setup(ASMState *as)
+{
+ MCode *mxp = as->mcbot;
+ if (((uintptr_t)mxp & (LJ_PAGESIZE-1)) == sizeof(MCLink)) {
+ lua_assert(MIPSI_NOP == 0);
+ memset(mxp, 0, MIPS_SPAREJUMP*2*sizeof(MCode));
+ mxp += MIPS_SPAREJUMP*2;
+ lua_assert(mxp < as->mctop);
+ lj_mcode_sync(as->mcbot, mxp);
+ lj_mcode_commitbot(as->J, mxp);
+ as->mcbot = mxp;
+ as->mclim = as->mcbot + MCLIM_REDZONE;
+ }
+}
+
+/* Setup exit stub after the end of each trace. */
+static void asm_exitstub_setup(ASMState *as)
+{
+ MCode *mxp = as->mctop;
+ /* sw TMP, 0(sp); j ->vm_exit_handler; li TMP, traceno */
+ *--mxp = MIPSI_LI|MIPSF_T(RID_TMP)|as->T->traceno;
+ *--mxp = MIPSI_J|((((uintptr_t)(void *)lj_vm_exit_handler)>>2)&0x03ffffffu);
+ lua_assert(((uintptr_t)mxp ^ (uintptr_t)(void *)lj_vm_exit_handler)>>28 == 0);
+ *--mxp = MIPSI_SW|MIPSF_T(RID_TMP)|MIPSF_S(RID_SP)|0;
+ as->mctop = mxp;
+}
+
+/* Keep this in-sync with exitstub_trace_addr(). */
+#define asm_exitstub_addr(as) ((as)->mctop)
+
+/* Emit conditional branch to exit for guard. */
+static void asm_guard(ASMState *as, MIPSIns mi, Reg rs, Reg rt)
+{
+ MCode *target = asm_exitstub_addr(as);
+ MCode *p = as->mcp;
+ if (LJ_UNLIKELY(p == as->invmcp)) {
+ as->invmcp = NULL;
+ as->loopinv = 1;
+ as->mcp = p+1;
+ mi = mi ^ ((mi>>28) == 1 ? 0x04000000u : 0x00010000u); /* Invert cond. */
+ target = p; /* Patch target later in asm_loop_fixup. */
+ }
+ emit_ti(as, MIPSI_LI, RID_TMP, as->snapno);
+ emit_branch(as, mi, rs, rt, target);
+}
+
+/* -- Operand fusion ------------------------------------------------------ */
+
+/* Limit linear search to this distance. Avoids O(n^2) behavior. */
+#define CONFLICT_SEARCH_LIM 31
+
+/* Check if there's no conflicting instruction between curins and ref. */
+static int noconflict(ASMState *as, IRRef ref, IROp conflict)
+{
+ IRIns *ir = as->ir;
+ IRRef i = as->curins;
+ if (i > ref + CONFLICT_SEARCH_LIM)
+ return 0; /* Give up, ref is too far away. */
+ while (--i > ref)
+ if (ir[i].o == conflict)
+ return 0; /* Conflict found. */
+ return 1; /* Ok, no conflict. */
+}
+
+/* Fuse the array base of colocated arrays. */
+static int32_t asm_fuseabase(ASMState *as, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE &&
+ !neverfuse(as) && noconflict(as, ref, IR_NEWREF))
+ return (int32_t)sizeof(GCtab);
+ return 0;
+}
+
+/* Fuse array/hash/upvalue reference into register+offset operand. */
+static Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow)
+{
+ IRIns *ir = IR(ref);
+ if (ra_noreg(ir->r)) {
+ if (ir->o == IR_AREF) {
+ if (mayfuse(as, ref)) {
+ if (irref_isk(ir->op2)) {
+ IRRef tab = IR(ir->op1)->op1;
+ int32_t ofs = asm_fuseabase(as, tab);
+ IRRef refa = ofs ? tab : ir->op1;
+ ofs += 8*IR(ir->op2)->i;
+ if (checki16(ofs)) {
+ *ofsp = ofs;
+ return ra_alloc1(as, refa, allow);
+ }
+ }
+ }
+ } else if (ir->o == IR_HREFK) {
+ if (mayfuse(as, ref)) {
+ int32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node));
+ if (checki16(ofs)) {
+ *ofsp = ofs;
+ return ra_alloc1(as, ir->op1, allow);
+ }
+ }
+ } else if (ir->o == IR_UREFC) {
+ if (irref_isk(ir->op1)) {
+ GCfunc *fn = ir_kfunc(IR(ir->op1));
+ int32_t ofs = i32ptr(&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv);
+ int32_t jgl = (intptr_t)J2G(as->J);
+ if ((uint32_t)(ofs-jgl) < 65536) {
+ *ofsp = ofs-jgl-32768;
+ return RID_JGL;
+ } else {
+ *ofsp = (int16_t)ofs;
+ return ra_allock(as, ofs-(int16_t)ofs, allow);
+ }
+ }
+ }
+ }
+ *ofsp = 0;
+ return ra_alloc1(as, ref, allow);
+}
+
+/* Fuse XLOAD/XSTORE reference into load/store operand. */
+static void asm_fusexref(ASMState *as, MIPSIns mi, Reg rt, IRRef ref,
+ RegSet allow, int32_t ofs)
+{
+ IRIns *ir = IR(ref);
+ Reg base;
+ if (ra_noreg(ir->r) && canfuse(as, ir)) {
+ if (ir->o == IR_ADD) {
+ int32_t ofs2;
+ if (irref_isk(ir->op2) && (ofs2 = ofs + IR(ir->op2)->i, checki16(ofs2))) {
+ ref = ir->op1;
+ ofs = ofs2;
+ }
+ } else if (ir->o == IR_STRREF) {
+ int32_t ofs2 = 65536;
+ lua_assert(ofs == 0);
+ ofs = (int32_t)sizeof(GCstr);
+ if (irref_isk(ir->op2)) {
+ ofs2 = ofs + IR(ir->op2)->i;
+ ref = ir->op1;
+ } else if (irref_isk(ir->op1)) {
+ ofs2 = ofs + IR(ir->op1)->i;
+ ref = ir->op2;
+ }
+ if (!checki16(ofs2)) {
+ /* NYI: Fuse ADD with constant. */
+ Reg right, left = ra_alloc2(as, ir, allow);
+ right = (left >> 8); left &= 255;
+ emit_hsi(as, mi, rt, RID_TMP, ofs);
+ emit_dst(as, MIPSI_ADDU, RID_TMP, left, right);
+ return;
+ }
+ ofs = ofs2;
+ }
+ }
+ base = ra_alloc1(as, ref, allow);
+ emit_hsi(as, mi, rt, base, ofs);
+}
+
+/* -- Calls --------------------------------------------------------------- */
+
+/* Generate a call to a C function. */
+static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)
+{
+ uint32_t n, nargs = CCI_NARGS(ci);
+ int32_t ofs = 16;
+ Reg gpr, fpr = REGARG_FIRSTFPR;
+ if ((void *)ci->func)
+ emit_call(as, (void *)ci->func);
+ for (gpr = REGARG_FIRSTGPR; gpr <= REGARG_LASTGPR; gpr++)
+ as->cost[gpr] = REGCOST(~0u, ASMREF_L);
+ gpr = REGARG_FIRSTGPR;
+ for (n = 0; n < nargs; n++) { /* Setup args. */
+ IRRef ref = args[n];
+ if (ref) {
+ IRIns *ir = IR(ref);
+ if (irt_isfp(ir->t) && fpr <= REGARG_LASTFPR &&
+ !(ci->flags & CCI_VARARG)) {
+ lua_assert(rset_test(as->freeset, fpr)); /* Already evicted. */
+ ra_leftov(as, fpr, ref);
+ fpr += 2;
+ gpr += irt_isnum(ir->t) ? 2 : 1;
+ } else {
+ fpr = REGARG_LASTFPR+1;
+ if (irt_isnum(ir->t)) gpr = (gpr+1) & ~1;
+ if (gpr <= REGARG_LASTGPR) {
+ lua_assert(rset_test(as->freeset, gpr)); /* Already evicted. */
+ if (irt_isfp(ir->t)) {
+ RegSet of = as->freeset;
+ Reg r;
+ /* Workaround to protect argument GPRs from being used for remat. */
+ as->freeset &= ~RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1);
+ r = ra_alloc1(as, ref, RSET_FPR);
+ as->freeset |= (of & RSET_RANGE(REGARG_FIRSTGPR, REGARG_LASTGPR+1));
+ if (irt_isnum(ir->t)) {
+ emit_tg(as, MIPSI_MFC1, gpr+(LJ_BE?0:1), r+1);
+ emit_tg(as, MIPSI_MFC1, gpr+(LJ_BE?1:0), r);
+ lua_assert(rset_test(as->freeset, gpr+1)); /* Already evicted. */
+ gpr += 2;
+ } else if (irt_isfloat(ir->t)) {
+ emit_tg(as, MIPSI_MFC1, gpr, r);
+ gpr++;
+ }
+ } else {
+ ra_leftov(as, gpr, ref);
+ gpr++;
+ }
+ } else {
+ Reg r = ra_alloc1z(as, ref, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);
+ if (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4;
+ emit_spstore(as, ir, r, ofs);
+ ofs += irt_isnum(ir->t) ? 8 : 4;
+ }
+ }
+ } else {
+ fpr = REGARG_LASTFPR+1;
+ if (gpr <= REGARG_LASTGPR)
+ gpr++;
+ else
+ ofs += 4;
+ }
+ checkmclim(as);
+ }
+}
+
+/* Setup result reg/sp for call. Evict scratch regs. */
+static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci)
+{
+ RegSet drop = RSET_SCRATCH;
+ int hiop = ((ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t));
+ if ((ci->flags & CCI_NOFPRCLOBBER))
+ drop &= ~RSET_FPR;
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ if (hiop && ra_hasreg((ir+1)->r))
+ rset_clear(drop, (ir+1)->r); /* Dest reg handled below. */
+ ra_evictset(as, drop); /* Evictions must be performed first. */
+ if (ra_used(ir)) {
+ lua_assert(!irt_ispri(ir->t));
+ if (irt_isfp(ir->t)) {
+ if ((ci->flags & CCI_CASTU64)) {
+ int32_t ofs = sps_scale(ir->s);
+ Reg dest = ir->r;
+ if (ra_hasreg(dest)) {
+ ra_free(as, dest);
+ ra_modified(as, dest);
+ emit_tg(as, MIPSI_MTC1, RID_RETHI, dest+1);
+ emit_tg(as, MIPSI_MTC1, RID_RETLO, dest);
+ }
+ if (ofs) {
+ emit_tsi(as, MIPSI_SW, RID_RETLO, RID_SP, ofs+(LJ_BE?4:0));
+ emit_tsi(as, MIPSI_SW, RID_RETHI, RID_SP, ofs+(LJ_BE?0:4));
+ }
+ } else {
+ ra_destreg(as, ir, RID_FPRET);
+ }
+ } else if (hiop) {
+ ra_destpair(as, ir);
+ } else {
+ ra_destreg(as, ir, RID_RET);
+ }
+ }
+}
+
+static void asm_call(ASMState *as, IRIns *ir)
+{
+ IRRef args[CCI_NARGS_MAX];
+ const CCallInfo *ci = &lj_ir_callinfo[ir->op2];
+ asm_collectargs(as, ir, ci, args);
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+
+static void asm_callx(ASMState *as, IRIns *ir)
+{
+ IRRef args[CCI_NARGS_MAX*2];
+ CCallInfo ci;
+ IRRef func;
+ IRIns *irf;
+ ci.flags = asm_callx_flags(as, ir);
+ asm_collectargs(as, ir, &ci, args);
+ asm_setupresult(as, ir, &ci);
+ func = ir->op2; irf = IR(func);
+ if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }
+ if (irref_isk(func)) { /* Call to constant address. */
+ ci.func = (ASMFunction)(void *)(irf->i);
+ } else { /* Need specific register for indirect calls. */
+ Reg r = ra_alloc1(as, func, RID2RSET(RID_CFUNCADDR));
+ MCode *p = as->mcp;
+ if (r == RID_CFUNCADDR)
+ *--p = MIPSI_NOP;
+ else
+ *--p = MIPSI_MOVE | MIPSF_D(RID_CFUNCADDR) | MIPSF_S(r);
+ *--p = MIPSI_JALR | MIPSF_S(r);
+ as->mcp = p;
+ ci.func = (ASMFunction)(void *)0;
+ }
+ asm_gencall(as, &ci, args);
+}
+
+static void asm_callid(ASMState *as, IRIns *ir, IRCallID id)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[id];
+ IRRef args[2];
+ args[0] = ir->op1;
+ args[1] = ir->op2;
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+
+static void asm_callround(ASMState *as, IRIns *ir, IRCallID id)
+{
+ /* The modified regs must match with the *.dasc implementation. */
+ RegSet drop = RID2RSET(RID_R1)|RID2RSET(RID_R12)|RID2RSET(RID_FPRET)|
+ RID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(REGARG_FIRSTFPR);
+ if (ra_hasreg(ir->r)) rset_clear(drop, ir->r);
+ ra_evictset(as, drop);
+ ra_destreg(as, ir, RID_FPRET);
+ emit_call(as, (void *)lj_ir_callinfo[id].func);
+ ra_leftov(as, REGARG_FIRSTFPR, ir->op1);
+}
+
+/* -- Returns ------------------------------------------------------------- */
+
+/* Return to lower frame. Guard that it goes to the right spot. */
+static void asm_retf(ASMState *as, IRIns *ir)
+{
+ Reg base = ra_alloc1(as, REF_BASE, RSET_GPR);
+ void *pc = ir_kptr(IR(ir->op2));
+ int32_t delta = 1+bc_a(*((const BCIns *)pc - 1));
+ as->topslot -= (BCReg)delta;
+ if ((int32_t)as->topslot < 0) as->topslot = 0;
+ irt_setmark(IR(REF_BASE)->t); /* Children must not coalesce with BASE reg. */
+ emit_setgl(as, base, jit_base);
+ emit_addptr(as, base, -8*delta);
+ asm_guard(as, MIPSI_BNE, RID_TMP,
+ ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base)));
+ emit_tsi(as, MIPSI_LW, RID_TMP, base, -8);
+}
+
+/* -- Type conversions ---------------------------------------------------- */
+
+static void asm_tointg(ASMState *as, IRIns *ir, Reg left)
+{
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ asm_guard(as, MIPSI_BC1F, 0, 0);
+ emit_fgh(as, MIPSI_C_EQ_D, 0, tmp, left);
+ emit_fg(as, MIPSI_CVT_D_W, tmp, tmp);
+ emit_tg(as, MIPSI_MFC1, dest, tmp);
+ emit_fg(as, MIPSI_CVT_W_D, tmp, left);
+}
+
+static void asm_tobit(ASMState *as, IRIns *ir)
+{
+ RegSet allow = RSET_FPR;
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, ir->op1, allow);
+ Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left));
+ Reg tmp = ra_scratch(as, rset_clear(allow, right));
+ emit_tg(as, MIPSI_MFC1, dest, tmp);
+ emit_fgh(as, MIPSI_ADD_D, tmp, left, right);
+}
+
+static void asm_conv(ASMState *as, IRIns *ir)
+{
+ IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);
+ int stfp = (st == IRT_NUM || st == IRT_FLOAT);
+ IRRef lref = ir->op1;
+ lua_assert(irt_type(ir->t) != st);
+ lua_assert(!(irt_isint64(ir->t) ||
+ (st == IRT_I64 || st == IRT_U64))); /* Handled by SPLIT. */
+ if (irt_isfp(ir->t)) {
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ if (stfp) { /* FP to FP conversion. */
+ emit_fg(as, st == IRT_NUM ? MIPSI_CVT_S_D : MIPSI_CVT_D_S,
+ dest, ra_alloc1(as, lref, RSET_FPR));
+ } else if (st == IRT_U32) { /* U32 to FP conversion. */
+ /* y = (x ^ 0x8000000) + 2147483648.0 */
+ Reg left = ra_alloc1(as, lref, RSET_GPR);
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, dest));
+ if (irt_isfloat(ir->t))
+ emit_fg(as, MIPSI_CVT_S_D, dest, dest);
+ /* Must perform arithmetic with doubles to keep the precision. */
+ emit_fgh(as, MIPSI_ADD_D, dest, dest, tmp);
+ emit_fg(as, MIPSI_CVT_D_W, dest, dest);
+ emit_lsptr(as, MIPSI_LDC1, (tmp & 31),
+ (void *)lj_ir_k64_find(as->J, U64x(41e00000,00000000)),
+ RSET_GPR);
+ emit_tg(as, MIPSI_MTC1, RID_TMP, dest);
+ emit_dst(as, MIPSI_XOR, RID_TMP, RID_TMP, left);
+ emit_ti(as, MIPSI_LUI, RID_TMP, 0x8000);
+ } else { /* Integer to FP conversion. */
+ Reg left = ra_alloc1(as, lref, RSET_GPR);
+ emit_fg(as, irt_isfloat(ir->t) ? MIPSI_CVT_S_W : MIPSI_CVT_D_W,
+ dest, dest);
+ emit_tg(as, MIPSI_MTC1, left, dest);
+ }
+ } else if (stfp) { /* FP to integer conversion. */
+ if (irt_isguard(ir->t)) {
+ /* Checked conversions are only supported from number to int. */
+ lua_assert(irt_isint(ir->t) && st == IRT_NUM);
+ asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR));
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, lref, RSET_FPR);
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));
+ if (irt_isu32(ir->t)) {
+ /* y = (int)floor(x - 2147483648.0) ^ 0x80000000 */
+ emit_dst(as, MIPSI_XOR, dest, dest, RID_TMP);
+ emit_ti(as, MIPSI_LUI, RID_TMP, 0x8000);
+ emit_tg(as, MIPSI_MFC1, dest, tmp);
+ emit_fg(as, st == IRT_FLOAT ? MIPSI_FLOOR_W_S : MIPSI_FLOOR_W_D,
+ tmp, tmp);
+ emit_fgh(as, st == IRT_FLOAT ? MIPSI_SUB_S : MIPSI_SUB_D,
+ tmp, left, tmp);
+ if (st == IRT_FLOAT)
+ emit_lsptr(as, MIPSI_LWC1, (tmp & 31),
+ (void *)lj_ir_k64_find(as->J, U64x(4f000000,4f000000)),
+ RSET_GPR);
+ else
+ emit_lsptr(as, MIPSI_LDC1, (tmp & 31),
+ (void *)lj_ir_k64_find(as->J, U64x(41e00000,00000000)),
+ RSET_GPR);
+ } else {
+ emit_tg(as, MIPSI_MFC1, dest, tmp);
+ emit_fg(as, st == IRT_FLOAT ? MIPSI_TRUNC_W_S : MIPSI_TRUNC_W_D,
+ tmp, left);
+ }
+ }
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */
+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
+ lua_assert(irt_isint(ir->t) || irt_isu32(ir->t));
+ if ((ir->op2 & IRCONV_SEXT)) {
+ if ((as->flags & JIT_F_MIPS32R2)) {
+ emit_dst(as, st == IRT_I8 ? MIPSI_SEB : MIPSI_SEH, dest, 0, left);
+ } else {
+ uint32_t shift = st == IRT_I8 ? 24 : 16;
+ emit_dta(as, MIPSI_SRA, dest, dest, shift);
+ emit_dta(as, MIPSI_SLL, dest, left, shift);
+ }
+ } else {
+ emit_tsi(as, MIPSI_ANDI, dest, left,
+ (int32_t)(st == IRT_U8 ? 0xff : 0xffff));
+ }
+ } else { /* 32/64 bit integer conversions. */
+ /* Only need to handle 32/32 bit no-op (cast) on 32 bit archs. */
+ ra_leftov(as, dest, lref); /* Do nothing, but may need to move regs. */
+ }
+ }
+}
+
+#if LJ_HASFFI
+static void asm_conv64(ASMState *as, IRIns *ir)
+{
+ IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK);
+ IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH);
+ IRCallID id;
+ const CCallInfo *ci;
+ IRRef args[2];
+ args[LJ_BE?0:1] = ir->op1;
+ args[LJ_BE?1:0] = (ir-1)->op1;
+ if (st == IRT_NUM || st == IRT_FLOAT) {
+ id = IRCALL_fp64_d2l + ((st == IRT_FLOAT) ? 2 : 0) + (dt - IRT_I64);
+ ir--;
+ } else {
+ id = IRCALL_fp64_l2d + ((dt == IRT_FLOAT) ? 2 : 0) + (st - IRT_I64);
+ }
+ ci = &lj_ir_callinfo[id];
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+#endif
+
+static void asm_strto(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num];
+ IRRef args[2];
+ RegSet drop = RSET_SCRATCH;
+ if (ra_hasreg(ir->r)) rset_set(drop, ir->r); /* Spill dest reg (if any). */
+ ra_evictset(as, drop);
+ asm_guard(as, MIPSI_BEQ, RID_RET, RID_ZERO); /* Test return status. */
+ args[0] = ir->op1; /* GCstr *str */
+ args[1] = ASMREF_TMP1; /* TValue *n */
+ asm_gencall(as, ci, args);
+ /* Store the result to the spill slot or temp slots. */
+ emit_tsi(as, MIPSI_ADDIU, ra_releasetmp(as, ASMREF_TMP1),
+ RID_SP, sps_scale(ir->s));
+}
+
+/* Get pointer to TValue. */
+static void asm_tvptr(ASMState *as, Reg dest, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ if (irt_isnum(ir->t)) {
+ if (irref_isk(ref)) /* Use the number constant itself as a TValue. */
+ ra_allockreg(as, i32ptr(ir_knum(ir)), dest);
+ else /* Otherwise force a spill and use the spill slot. */
+ emit_tsi(as, MIPSI_ADDIU, dest, RID_SP, ra_spill(as, ir));
+ } else {
+ /* Otherwise use g->tmptv to hold the TValue. */
+ RegSet allow = rset_exclude(RSET_GPR, dest);
+ Reg type;
+ emit_tsi(as, MIPSI_ADDIU, dest, RID_JGL, offsetof(global_State, tmptv)-32768);
+ if (!irt_ispri(ir->t)) {
+ Reg src = ra_alloc1(as, ref, allow);
+ emit_setgl(as, src, tmptv.gcr);
+ }
+ type = ra_allock(as, irt_toitype(ir->t), allow);
+ emit_setgl(as, type, tmptv.it);
+ }
+}
+
+static void asm_tostr(ASMState *as, IRIns *ir)
+{
+ IRRef args[2];
+ args[0] = ASMREF_L;
+ as->gcsteps++;
+ if (irt_isnum(IR(ir->op1)->t) || (ir+1)->o == IR_HIOP) {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromnum];
+ args[1] = ASMREF_TMP1; /* const lua_Number * */
+ asm_setupresult(as, ir, ci); /* GCstr * */
+ asm_gencall(as, ci, args);
+ asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op1);
+ } else {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromint];
+ args[1] = ir->op1; /* int32_t k */
+ asm_setupresult(as, ir, ci); /* GCstr * */
+ asm_gencall(as, ci, args);
+ }
+}
+
+/* -- Memory references --------------------------------------------------- */
+
+static void asm_aref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg idx, base;
+ if (irref_isk(ir->op2)) {
+ IRRef tab = IR(ir->op1)->op1;
+ int32_t ofs = asm_fuseabase(as, tab);
+ IRRef refa = ofs ? tab : ir->op1;
+ ofs += 8*IR(ir->op2)->i;
+ if (checki16(ofs)) {
+ base = ra_alloc1(as, refa, RSET_GPR);
+ emit_tsi(as, MIPSI_ADDIU, dest, base, ofs);
+ return;
+ }
+ }
+ base = ra_alloc1(as, ir->op1, RSET_GPR);
+ idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base));
+ emit_dst(as, MIPSI_ADDU, dest, RID_TMP, base);
+ emit_dta(as, MIPSI_SLL, RID_TMP, idx, 3);
+}
+
+/* Inlined hash lookup. Specialized for key type and for const keys.
+** The equivalent C code is:
+** Node *n = hashkey(t, key);
+** do {
+** if (lj_obj_equal(&n->key, key)) return &n->val;
+** } while ((n = nextnode(n)));
+** return niltv(L);
+*/
+static void asm_href(ASMState *as, IRIns *ir)
+{
+ RegSet allow = RSET_GPR;
+ int destused = ra_used(ir);
+ Reg dest = ra_dest(as, ir, allow);
+ Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest));
+ Reg key = RID_NONE, type = RID_NONE, tmpnum = RID_NONE, tmp1 = RID_TMP, tmp2;
+ IRRef refkey = ir->op2;
+ IRIns *irkey = IR(refkey);
+ IRType1 kt = irkey->t;
+ uint32_t khash;
+ MCLabel l_end, l_loop, l_next;
+
+ rset_clear(allow, tab);
+ if (irt_isnum(kt)) {
+ key = ra_alloc1(as, refkey, RSET_FPR);
+ tmpnum = ra_scratch(as, rset_exclude(RSET_FPR, key));
+ } else if (!irt_ispri(kt)) {
+ key = ra_alloc1(as, refkey, allow);
+ rset_clear(allow, key);
+ type = ra_allock(as, irt_toitype(irkey->t), allow);
+ rset_clear(allow, type);
+ }
+ tmp2 = ra_scratch(as, allow);
+ rset_clear(allow, tmp2);
+
+ /* Key not found in chain: load niltv. */
+ l_end = emit_label(as);
+ if (destused)
+ emit_loada(as, dest, niltvg(J2G(as->J)));
+ else
+ *--as->mcp = MIPSI_NOP;
+ /* Follow hash chain until the end. */
+ emit_move(as, dest, tmp1);
+ l_loop = --as->mcp;
+ emit_tsi(as, MIPSI_LW, tmp1, dest, (int32_t)offsetof(Node, next));
+ l_next = emit_label(as);
+
+ /* Type and value comparison. */
+ if (irt_isnum(kt)) {
+ emit_branch(as, MIPSI_BC1T, 0, 0, l_end);
+ emit_fgh(as, MIPSI_C_EQ_D, 0, tmpnum, key);
+ emit_tg(as, MIPSI_MFC1, tmp1, key+1);
+ emit_branch(as, MIPSI_BEQ, tmp1, RID_ZERO, l_next);
+ emit_tsi(as, MIPSI_SLTIU, tmp1, tmp1, (int32_t)LJ_TISNUM);
+ emit_hsi(as, MIPSI_LDC1, tmpnum, dest, (int32_t)offsetof(Node, key.n));
+ } else {
+ if (irt_ispri(kt)) {
+ emit_branch(as, MIPSI_BEQ, tmp1, type, l_end);
+ } else {
+ emit_branch(as, MIPSI_BEQ, tmp2, key, l_end);
+ emit_tsi(as, MIPSI_LW, tmp2, dest, (int32_t)offsetof(Node, key.gcr));
+ emit_branch(as, MIPSI_BNE, tmp1, type, l_next);
+ }
+ }
+ emit_tsi(as, MIPSI_LW, tmp1, dest, (int32_t)offsetof(Node, key.it));
+ *l_loop = MIPSI_BNE | MIPSF_S(tmp1) | ((as->mcp-l_loop-1) & 0xffffu);
+
+ /* Load main position relative to tab->node into dest. */
+ khash = irref_isk(refkey) ? ir_khash(irkey) : 1;
+ if (khash == 0) {
+ emit_tsi(as, MIPSI_LW, dest, tab, (int32_t)offsetof(GCtab, node));
+ } else {
+ Reg tmphash = tmp1;
+ if (irref_isk(refkey))
+ tmphash = ra_allock(as, khash, allow);
+ emit_dst(as, MIPSI_ADDU, dest, dest, tmp1);
+ lua_assert(sizeof(Node) == 24);
+ emit_dst(as, MIPSI_SUBU, tmp1, tmp2, tmp1);
+ emit_dta(as, MIPSI_SLL, tmp1, tmp1, 3);
+ emit_dta(as, MIPSI_SLL, tmp2, tmp1, 5);
+ emit_dst(as, MIPSI_AND, tmp1, tmp2, tmphash);
+ emit_tsi(as, MIPSI_LW, dest, tab, (int32_t)offsetof(GCtab, node));
+ emit_tsi(as, MIPSI_LW, tmp2, tab, (int32_t)offsetof(GCtab, hmask));
+ if (irref_isk(refkey)) {
+ /* Nothing to do. */
+ } else if (irt_isstr(kt)) {
+ emit_tsi(as, MIPSI_LW, tmp1, key, (int32_t)offsetof(GCstr, hash));
+ } else { /* Must match with hash*() in lj_tab.c. */
+ emit_dst(as, MIPSI_SUBU, tmp1, tmp1, tmp2);
+ emit_rotr(as, tmp2, tmp2, dest, (-HASH_ROT3)&31);
+ emit_dst(as, MIPSI_XOR, tmp1, tmp1, tmp2);
+ emit_rotr(as, tmp1, tmp1, dest, (-HASH_ROT2-HASH_ROT1)&31);
+ emit_dst(as, MIPSI_SUBU, tmp2, tmp2, dest);
+ if (irt_isnum(kt)) {
+ emit_dst(as, MIPSI_XOR, tmp2, tmp2, tmp1);
+ if ((as->flags & JIT_F_MIPS32R2)) {
+ emit_dta(as, MIPSI_ROTR, dest, tmp1, (-HASH_ROT1)&31);
+ } else {
+ emit_dst(as, MIPSI_OR, dest, dest, tmp1);
+ emit_dta(as, MIPSI_SLL, tmp1, tmp1, HASH_ROT1);
+ emit_dta(as, MIPSI_SRL, dest, tmp1, (-HASH_ROT1)&31);
+ }
+ emit_dst(as, MIPSI_ADDU, tmp1, tmp1, tmp1);
+ emit_tg(as, MIPSI_MFC1, tmp2, key);
+ emit_tg(as, MIPSI_MFC1, tmp1, key+1);
+ } else {
+ emit_dst(as, MIPSI_XOR, tmp2, key, tmp1);
+ emit_rotr(as, dest, tmp1, tmp2, (-HASH_ROT1)&31);
+ emit_dst(as, MIPSI_ADDU, tmp1, key, ra_allock(as, HASH_BIAS, allow));
+ }
+ }
+ }
+}
+
+static void asm_hrefk(ASMState *as, IRIns *ir)
+{
+ IRIns *kslot = IR(ir->op2);
+ IRIns *irkey = IR(kslot->op1);
+ int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node));
+ int32_t kofs = ofs + (int32_t)offsetof(Node, key);
+ Reg dest = (ra_used(ir)||ofs > 32736) ? ra_dest(as, ir, RSET_GPR) : RID_NONE;
+ Reg node = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg key = RID_NONE, type = RID_TMP, idx = node;
+ RegSet allow = rset_exclude(RSET_GPR, node);
+ int32_t lo, hi;
+ lua_assert(ofs % sizeof(Node) == 0);
+ if (ofs > 32736) {
+ idx = dest;
+ rset_clear(allow, dest);
+ kofs = (int32_t)offsetof(Node, key);
+ } else if (ra_hasreg(dest)) {
+ emit_tsi(as, MIPSI_ADDIU, dest, node, ofs);
+ }
+ if (!irt_ispri(irkey->t)) {
+ key = ra_scratch(as, allow);
+ rset_clear(allow, key);
+ }
+ if (irt_isnum(irkey->t)) {
+ lo = (int32_t)ir_knum(irkey)->u32.lo;
+ hi = (int32_t)ir_knum(irkey)->u32.hi;
+ } else {
+ lo = irkey->i;
+ hi = irt_toitype(irkey->t);
+ if (!ra_hasreg(key))
+ goto nolo;
+ }
+ asm_guard(as, MIPSI_BNE, key, lo ? ra_allock(as, lo, allow) : RID_ZERO);
+nolo:
+ asm_guard(as, MIPSI_BNE, type, hi ? ra_allock(as, hi, allow) : RID_ZERO);
+ if (ra_hasreg(key)) emit_tsi(as, MIPSI_LW, key, idx, kofs+(LJ_BE?4:0));
+ emit_tsi(as, MIPSI_LW, type, idx, kofs+(LJ_BE?0:4));
+ if (ofs > 32736)
+ emit_tsi(as, MIPSI_ADDU, dest, node, ra_allock(as, ofs, allow));
+}
+
+static void asm_newref(ASMState *as, IRIns *ir)
+{
+ if (ir->r != RID_SINK) {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_newkey];
+ IRRef args[3];
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ir->op1; /* GCtab *t */
+ args[2] = ASMREF_TMP1; /* cTValue *key */
+ asm_setupresult(as, ir, ci); /* TValue * */
+ asm_gencall(as, ci, args);
+ asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op2);
+ }
+}
+
+static void asm_uref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (irref_isk(ir->op1)) {
+ GCfunc *fn = ir_kfunc(IR(ir->op1));
+ MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v;
+ emit_lsptr(as, MIPSI_LW, dest, v, RSET_GPR);
+ } else {
+ Reg uv = ra_scratch(as, RSET_GPR);
+ Reg func = ra_alloc1(as, ir->op1, RSET_GPR);
+ if (ir->o == IR_UREFC) {
+ asm_guard(as, MIPSI_BEQ, RID_TMP, RID_ZERO);
+ emit_tsi(as, MIPSI_ADDIU, dest, uv, (int32_t)offsetof(GCupval, tv));
+ emit_tsi(as, MIPSI_LBU, RID_TMP, uv, (int32_t)offsetof(GCupval, closed));
+ } else {
+ emit_tsi(as, MIPSI_LW, dest, uv, (int32_t)offsetof(GCupval, v));
+ }
+ emit_tsi(as, MIPSI_LW, uv, func,
+ (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8));
+ }
+}
+
+static void asm_fref(ASMState *as, IRIns *ir)
+{
+ UNUSED(as); UNUSED(ir);
+ lua_assert(!ra_used(ir));
+}
+
+static void asm_strref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ IRRef ref = ir->op2, refk = ir->op1;
+ int32_t ofs = (int32_t)sizeof(GCstr);
+ Reg r;
+ if (irref_isk(ref)) {
+ IRRef tmp = refk; refk = ref; ref = tmp;
+ } else if (!irref_isk(refk)) {
+ Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);
+ IRIns *irr = IR(ir->op2);
+ if (ra_hasreg(irr->r)) {
+ ra_noweak(as, irr->r);
+ right = irr->r;
+ } else if (mayfuse(as, irr->op2) &&
+ irr->o == IR_ADD && irref_isk(irr->op2) &&
+ checki16(ofs + IR(irr->op2)->i)) {
+ ofs += IR(irr->op2)->i;
+ right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left));
+ } else {
+ right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left));
+ }
+ emit_tsi(as, MIPSI_ADDIU, dest, dest, ofs);
+ emit_dst(as, MIPSI_ADDU, dest, left, right);
+ return;
+ }
+ r = ra_alloc1(as, ref, RSET_GPR);
+ ofs += IR(refk)->i;
+ if (checki16(ofs))
+ emit_tsi(as, MIPSI_ADDIU, dest, r, ofs);
+ else
+ emit_dst(as, MIPSI_ADDU, dest, r,
+ ra_allock(as, ofs, rset_exclude(RSET_GPR, r)));
+}
+
+/* -- Loads and stores ---------------------------------------------------- */
+
+static MIPSIns asm_fxloadins(IRIns *ir)
+{
+ switch (irt_type(ir->t)) {
+ case IRT_I8: return MIPSI_LB;
+ case IRT_U8: return MIPSI_LBU;
+ case IRT_I16: return MIPSI_LH;
+ case IRT_U16: return MIPSI_LHU;
+ case IRT_NUM: return MIPSI_LDC1;
+ case IRT_FLOAT: return MIPSI_LWC1;
+ default: return MIPSI_LW;
+ }
+}
+
+static MIPSIns asm_fxstoreins(IRIns *ir)
+{
+ switch (irt_type(ir->t)) {
+ case IRT_I8: case IRT_U8: return MIPSI_SB;
+ case IRT_I16: case IRT_U16: return MIPSI_SH;
+ case IRT_NUM: return MIPSI_SDC1;
+ case IRT_FLOAT: return MIPSI_SWC1;
+ default: return MIPSI_SW;
+ }
+}
+
+static void asm_fload(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg idx = ra_alloc1(as, ir->op1, RSET_GPR);
+ MIPSIns mi = asm_fxloadins(ir);
+ int32_t ofs;
+ if (ir->op2 == IRFL_TAB_ARRAY) {
+ ofs = asm_fuseabase(as, ir->op1);
+ if (ofs) { /* Turn the t->array load into an add for colocated arrays. */
+ emit_tsi(as, MIPSI_ADDIU, dest, idx, ofs);
+ return;
+ }
+ }
+ ofs = field_ofs[ir->op2];
+ lua_assert(!irt_isfp(ir->t));
+ emit_tsi(as, mi, dest, idx, ofs);
+}
+
+static void asm_fstore(ASMState *as, IRIns *ir)
+{
+ if (ir->r != RID_SINK) {
+ Reg src = ra_alloc1z(as, ir->op2, RSET_GPR);
+ IRIns *irf = IR(ir->op1);
+ Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src));
+ int32_t ofs = field_ofs[irf->op2];
+ MIPSIns mi = asm_fxstoreins(ir);
+ lua_assert(!irt_isfp(ir->t));
+ emit_tsi(as, mi, src, idx, ofs);
+ }
+}
+
+static void asm_xload(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);
+ lua_assert(!(ir->op2 & IRXLOAD_UNALIGNED));
+ asm_fusexref(as, asm_fxloadins(ir), dest, ir->op1, RSET_GPR, 0);
+}
+
+static void asm_xstore(ASMState *as, IRIns *ir, int32_t ofs)
+{
+ if (ir->r != RID_SINK) {
+ Reg src = ra_alloc1z(as, ir->op2, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);
+ asm_fusexref(as, asm_fxstoreins(ir), src, ir->op1,
+ rset_exclude(RSET_GPR, src), ofs);
+ }
+}
+
+static void asm_ahuvload(ASMState *as, IRIns *ir)
+{
+ IRType1 t = ir->t;
+ Reg dest = RID_NONE, type = RID_TMP, idx;
+ RegSet allow = RSET_GPR;
+ int32_t ofs = 0;
+ if (ra_used(ir)) {
+ lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t));
+ dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : RSET_GPR);
+ rset_clear(allow, dest);
+ }
+ idx = asm_fuseahuref(as, ir->op1, &ofs, allow);
+ rset_clear(allow, idx);
+ if (irt_isnum(t)) {
+ asm_guard(as, MIPSI_BEQ, type, RID_ZERO);
+ emit_tsi(as, MIPSI_SLTIU, type, type, (int32_t)LJ_TISNUM);
+ if (ra_hasreg(dest))
+ emit_hsi(as, MIPSI_LDC1, dest, idx, ofs);
+ } else {
+ asm_guard(as, MIPSI_BNE, type, ra_allock(as, irt_toitype(t), allow));
+ if (ra_hasreg(dest)) emit_tsi(as, MIPSI_LW, dest, idx, ofs+(LJ_BE?4:0));
+ }
+ emit_tsi(as, MIPSI_LW, type, idx, ofs+(LJ_BE?0:4));
+}
+
+static void asm_ahustore(ASMState *as, IRIns *ir)
+{
+ RegSet allow = RSET_GPR;
+ Reg idx, src = RID_NONE, type = RID_NONE;
+ int32_t ofs = 0;
+ if (ir->r == RID_SINK)
+ return;
+ if (irt_isnum(ir->t)) {
+ src = ra_alloc1(as, ir->op2, RSET_FPR);
+ } else {
+ if (!irt_ispri(ir->t)) {
+ src = ra_alloc1(as, ir->op2, allow);
+ rset_clear(allow, src);
+ }
+ type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);
+ rset_clear(allow, type);
+ }
+ idx = asm_fuseahuref(as, ir->op1, &ofs, allow);
+ if (irt_isnum(ir->t)) {
+ emit_hsi(as, MIPSI_SDC1, src, idx, ofs);
+ } else {
+ if (ra_hasreg(src))
+ emit_tsi(as, MIPSI_SW, src, idx, ofs+(LJ_BE?4:0));
+ emit_tsi(as, MIPSI_SW, type, idx, ofs+(LJ_BE?0:4));
+ }
+}
+
+static void asm_sload(ASMState *as, IRIns *ir)
+{
+ int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 4 : 0);
+ IRType1 t = ir->t;
+ Reg dest = RID_NONE, type = RID_NONE, base;
+ RegSet allow = RSET_GPR;
+ lua_assert(!(ir->op2 & IRSLOAD_PARENT)); /* Handled by asm_head_side(). */
+ lua_assert(irt_isguard(t) || !(ir->op2 & IRSLOAD_TYPECHECK));
+ lua_assert(!irt_isint(t) || (ir->op2 & (IRSLOAD_CONVERT|IRSLOAD_FRAME)));
+ if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(t) && irt_isint(t)) {
+ dest = ra_scratch(as, RSET_FPR);
+ asm_tointg(as, ir, dest);
+ t.irt = IRT_NUM; /* Continue with a regular number type check. */
+ } else if (ra_used(ir)) {
+ lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t));
+ dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : RSET_GPR);
+ rset_clear(allow, dest);
+ base = ra_alloc1(as, REF_BASE, allow);
+ rset_clear(allow, base);
+ if ((ir->op2 & IRSLOAD_CONVERT)) {
+ if (irt_isint(t)) {
+ Reg tmp = ra_scratch(as, RSET_FPR);
+ emit_tg(as, MIPSI_MFC1, dest, tmp);
+ emit_fg(as, MIPSI_CVT_W_D, tmp, tmp);
+ dest = tmp;
+ t.irt = IRT_NUM; /* Check for original type. */
+ } else {
+ Reg tmp = ra_scratch(as, RSET_GPR);
+ emit_fg(as, MIPSI_CVT_D_W, dest, dest);
+ emit_tg(as, MIPSI_MTC1, tmp, dest);
+ dest = tmp;
+ t.irt = IRT_INT; /* Check for original type. */
+ }
+ }
+ goto dotypecheck;
+ }
+ base = ra_alloc1(as, REF_BASE, allow);
+ rset_clear(allow, base);
+dotypecheck:
+ if (irt_isnum(t)) {
+ if ((ir->op2 & IRSLOAD_TYPECHECK)) {
+ asm_guard(as, MIPSI_BEQ, RID_TMP, RID_ZERO);
+ emit_tsi(as, MIPSI_SLTIU, RID_TMP, RID_TMP, (int32_t)LJ_TISNUM);
+ type = RID_TMP;
+ }
+ if (ra_hasreg(dest)) emit_hsi(as, MIPSI_LDC1, dest, base, ofs);
+ } else {
+ if ((ir->op2 & IRSLOAD_TYPECHECK)) {
+ Reg ktype = ra_allock(as, irt_toitype(t), allow);
+ asm_guard(as, MIPSI_BNE, RID_TMP, ktype);
+ type = RID_TMP;
+ }
+ if (ra_hasreg(dest)) emit_tsi(as, MIPSI_LW, dest, base, ofs ^ (LJ_BE?4:0));
+ }
+ if (ra_hasreg(type)) emit_tsi(as, MIPSI_LW, type, base, ofs ^ (LJ_BE?0:4));
+}
+
+/* -- Allocations --------------------------------------------------------- */
+
+#if LJ_HASFFI
+static void asm_cnew(ASMState *as, IRIns *ir)
+{
+ CTState *cts = ctype_ctsG(J2G(as->J));
+ CTypeID ctypeid = (CTypeID)IR(ir->op1)->i;
+ CTSize sz = (ir->o == IR_CNEWI || ir->op2 == REF_NIL) ?
+ lj_ctype_size(cts, ctypeid) : (CTSize)IR(ir->op2)->i;
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];
+ IRRef args[2];
+ RegSet allow = (RSET_GPR & ~RSET_SCRATCH);
+ RegSet drop = RSET_SCRATCH;
+ lua_assert(sz != CTSIZE_INVALID);
+
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ASMREF_TMP1; /* MSize size */
+ as->gcsteps++;
+
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ ra_evictset(as, drop);
+ if (ra_used(ir))
+ ra_destreg(as, ir, RID_RET); /* GCcdata * */
+
+ /* Initialize immutable cdata object. */
+ if (ir->o == IR_CNEWI) {
+ int32_t ofs = sizeof(GCcdata);
+ lua_assert(sz == 4 || sz == 8);
+ if (sz == 8) {
+ ofs += 4;
+ lua_assert((ir+1)->o == IR_HIOP);
+ if (LJ_LE) ir++;
+ }
+ for (;;) {
+ Reg r = ra_alloc1z(as, ir->op2, allow);
+ emit_tsi(as, MIPSI_SW, r, RID_RET, ofs);
+ rset_clear(allow, r);
+ if (ofs == sizeof(GCcdata)) break;
+ ofs -= 4; if (LJ_BE) ir++; else ir--;
+ }
+ }
+ /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */
+ emit_tsi(as, MIPSI_SB, RID_RET+1, RID_RET, offsetof(GCcdata, gct));
+ emit_tsi(as, MIPSI_SH, RID_TMP, RID_RET, offsetof(GCcdata, ctypeid));
+ emit_ti(as, MIPSI_LI, RID_RET+1, ~LJ_TCDATA);
+ emit_ti(as, MIPSI_LI, RID_TMP, ctypeid); /* Lower 16 bit used. Sign-ext ok. */
+ asm_gencall(as, ci, args);
+ ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)),
+ ra_releasetmp(as, ASMREF_TMP1));
+}
+#else
+#define asm_cnew(as, ir) ((void)0)
+#endif
+
+/* -- Write barriers ------------------------------------------------------ */
+
+static void asm_tbar(ASMState *as, IRIns *ir)
+{
+ Reg tab = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg mark = ra_scratch(as, rset_exclude(RSET_GPR, tab));
+ Reg link = RID_TMP;
+ MCLabel l_end = emit_label(as);
+ emit_tsi(as, MIPSI_SW, link, tab, (int32_t)offsetof(GCtab, gclist));
+ emit_tsi(as, MIPSI_SB, mark, tab, (int32_t)offsetof(GCtab, marked));
+ emit_setgl(as, tab, gc.grayagain);
+ emit_getgl(as, link, gc.grayagain);
+ emit_dst(as, MIPSI_XOR, mark, mark, RID_TMP); /* Clear black bit. */
+ emit_branch(as, MIPSI_BEQ, RID_TMP, RID_ZERO, l_end);
+ emit_tsi(as, MIPSI_ANDI, RID_TMP, mark, LJ_GC_BLACK);
+ emit_tsi(as, MIPSI_LBU, mark, tab, (int32_t)offsetof(GCtab, marked));
+}
+
+static void asm_obar(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv];
+ IRRef args[2];
+ MCLabel l_end;
+ Reg obj, val, tmp;
+ /* No need for other object barriers (yet). */
+ lua_assert(IR(ir->op1)->o == IR_UREFC);
+ ra_evictset(as, RSET_SCRATCH);
+ l_end = emit_label(as);
+ args[0] = ASMREF_TMP1; /* global_State *g */
+ args[1] = ir->op1; /* TValue *tv */
+ asm_gencall(as, ci, args);
+ emit_tsi(as, MIPSI_ADDIU, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768);
+ obj = IR(ir->op1)->r;
+ tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj));
+ emit_branch(as, MIPSI_BEQ, RID_TMP, RID_ZERO, l_end);
+ emit_tsi(as, MIPSI_ANDI, tmp, tmp, LJ_GC_BLACK);
+ emit_branch(as, MIPSI_BEQ, RID_TMP, RID_ZERO, l_end);
+ emit_tsi(as, MIPSI_ANDI, RID_TMP, RID_TMP, LJ_GC_WHITES);
+ val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj));
+ emit_tsi(as, MIPSI_LBU, tmp, obj,
+ (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv));
+ emit_tsi(as, MIPSI_LBU, RID_TMP, val, (int32_t)offsetof(GChead, marked));
+}
+
+/* -- Arithmetic and logic operations ------------------------------------- */
+
+static void asm_fparith(ASMState *as, IRIns *ir, MIPSIns mi)
+{
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg right, left = ra_alloc2(as, ir, RSET_FPR);
+ right = (left >> 8); left &= 255;
+ emit_fgh(as, mi, dest, left, right);
+}
+
+static void asm_fpunary(ASMState *as, IRIns *ir, MIPSIns mi)
+{
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR);
+ emit_fg(as, mi, dest, left);
+}
+
+static int asm_fpjoin_pow(ASMState *as, IRIns *ir)
+{
+ IRIns *irp = IR(ir->op1);
+ if (irp == ir-1 && irp->o == IR_MUL && !ra_used(irp)) {
+ IRIns *irpp = IR(irp->op1);
+ if (irpp == ir-2 && irpp->o == IR_FPMATH &&
+ irpp->op2 == IRFPM_LOG2 && !ra_used(irpp)) {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_pow];
+ IRRef args[2];
+ args[0] = irpp->op1;
+ args[1] = irp->op2;
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static void asm_add(ASMState *as, IRIns *ir)
+{
+ if (irt_isnum(ir->t)) {
+ asm_fparith(as, ir, MIPSI_ADD_D);
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (checki16(k)) {
+ emit_tsi(as, MIPSI_ADDIU, dest, left, k);
+ return;
+ }
+ }
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_dst(as, MIPSI_ADDU, dest, left, right);
+ }
+}
+
+static void asm_sub(ASMState *as, IRIns *ir)
+{
+ if (irt_isnum(ir->t)) {
+ asm_fparith(as, ir, MIPSI_SUB_D);
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ emit_dst(as, MIPSI_SUBU, dest, left, right);
+ }
+}
+
+static void asm_mul(ASMState *as, IRIns *ir)
+{
+ if (irt_isnum(ir->t)) {
+ asm_fparith(as, ir, MIPSI_MUL_D);
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ emit_dst(as, MIPSI_MUL, dest, left, right);
+ }
+}
+
+static void asm_neg(ASMState *as, IRIns *ir)
+{
+ if (irt_isnum(ir->t)) {
+ asm_fpunary(as, ir, MIPSI_NEG_D);
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ emit_dst(as, MIPSI_SUBU, dest, RID_ZERO, left);
+ }
+}
+
+static void asm_arithov(ASMState *as, IRIns *ir)
+{
+ Reg right, left, tmp, dest = ra_dest(as, ir, RSET_GPR);
+ if (irref_isk(ir->op2)) {
+ int k = IR(ir->op2)->i;
+ if (ir->o == IR_SUBOV) k = -k;
+ if (checki16(k)) { /* (dest < left) == (k >= 0 ? 1 : 0) */
+ left = ra_alloc1(as, ir->op1, RSET_GPR);
+ asm_guard(as, k >= 0 ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO);
+ emit_dst(as, MIPSI_SLT, RID_TMP, dest, dest == left ? RID_TMP : left);
+ emit_tsi(as, MIPSI_ADDIU, dest, left, k);
+ if (dest == left) emit_move(as, RID_TMP, left);
+ return;
+ }
+ }
+ left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ tmp = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_GPR, left),
+ right), dest));
+ asm_guard(as, MIPSI_BLTZ, RID_TMP, 0);
+ emit_dst(as, MIPSI_AND, RID_TMP, RID_TMP, tmp);
+ if (ir->o == IR_ADDOV) { /* ((dest^left) & (dest^right)) < 0 */
+ emit_dst(as, MIPSI_XOR, RID_TMP, dest, dest == right ? RID_TMP : right);
+ } else { /* ((dest^left) & (dest^~right)) < 0 */
+ emit_dst(as, MIPSI_XOR, RID_TMP, RID_TMP, dest);
+ emit_dst(as, MIPSI_NOR, RID_TMP, dest == right ? RID_TMP : right, RID_ZERO);
+ }
+ emit_dst(as, MIPSI_XOR, tmp, dest, dest == left ? RID_TMP : left);
+ emit_dst(as, ir->o == IR_ADDOV ? MIPSI_ADDU : MIPSI_SUBU, dest, left, right);
+ if (dest == left || dest == right)
+ emit_move(as, RID_TMP, dest == left ? left : right);
+}
+
+static void asm_mulov(ASMState *as, IRIns *ir)
+{
+#if LJ_DUALNUM
+#error "NYI: MULOV"
+#else
+ UNUSED(as); UNUSED(ir); lua_assert(0); /* Unused in single-number mode. */
+#endif
+}
+
+#if LJ_HASFFI
+static void asm_add64(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (k == 0) {
+ emit_dst(as, MIPSI_ADDU, dest, left, RID_TMP);
+ goto loarith;
+ } else if (checki16(k)) {
+ emit_dst(as, MIPSI_ADDU, dest, dest, RID_TMP);
+ emit_tsi(as, MIPSI_ADDIU, dest, left, k);
+ goto loarith;
+ }
+ }
+ emit_dst(as, MIPSI_ADDU, dest, dest, RID_TMP);
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_dst(as, MIPSI_ADDU, dest, left, right);
+loarith:
+ ir--;
+ dest = ra_dest(as, ir, RSET_GPR);
+ left = ra_alloc1(as, ir->op1, RSET_GPR);
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (k == 0) {
+ if (dest != left)
+ emit_move(as, dest, left);
+ return;
+ } else if (checki16(k)) {
+ if (dest == left) {
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, left));
+ emit_move(as, dest, tmp);
+ dest = tmp;
+ }
+ emit_dst(as, MIPSI_SLTU, RID_TMP, dest, left);
+ emit_tsi(as, MIPSI_ADDIU, dest, left, k);
+ return;
+ }
+ }
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ if (dest == left && dest == right) {
+ Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), right));
+ emit_move(as, dest, tmp);
+ dest = tmp;
+ }
+ emit_dst(as, MIPSI_SLTU, RID_TMP, dest, dest == left ? right : left);
+ emit_dst(as, MIPSI_ADDU, dest, left, right);
+}
+
+static void asm_sub64(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ emit_dst(as, MIPSI_SUBU, dest, dest, RID_TMP);
+ emit_dst(as, MIPSI_SUBU, dest, left, right);
+ ir--;
+ dest = ra_dest(as, ir, RSET_GPR);
+ left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ if (dest == left) {
+ Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), right));
+ emit_move(as, dest, tmp);
+ dest = tmp;
+ }
+ emit_dst(as, MIPSI_SLTU, RID_TMP, left, dest);
+ emit_dst(as, MIPSI_SUBU, dest, left, right);
+}
+
+static void asm_neg64(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
+ emit_dst(as, MIPSI_SUBU, dest, dest, RID_TMP);
+ emit_dst(as, MIPSI_SUBU, dest, RID_ZERO, left);
+ ir--;
+ dest = ra_dest(as, ir, RSET_GPR);
+ left = ra_alloc1(as, ir->op1, RSET_GPR);
+ emit_dst(as, MIPSI_SLTU, RID_TMP, RID_ZERO, dest);
+ emit_dst(as, MIPSI_SUBU, dest, RID_ZERO, left);
+}
+#endif
+
+static void asm_bitnot(ASMState *as, IRIns *ir)
+{
+ Reg left, right, dest = ra_dest(as, ir, RSET_GPR);
+ IRIns *irl = IR(ir->op1);
+ if (mayfuse(as, ir->op1) && irl->o == IR_BOR) {
+ left = ra_alloc2(as, irl, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ } else {
+ left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ right = RID_ZERO;
+ }
+ emit_dst(as, MIPSI_NOR, dest, left, right);
+}
+
+static void asm_bitswap(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
+ if ((as->flags & JIT_F_MIPS32R2)) {
+ emit_dta(as, MIPSI_ROTR, dest, RID_TMP, 16);
+ emit_dst(as, MIPSI_WSBH, RID_TMP, 0, left);
+ } else {
+ Reg tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), dest));
+ emit_dst(as, MIPSI_OR, dest, dest, tmp);
+ emit_dst(as, MIPSI_OR, dest, dest, RID_TMP);
+ emit_tsi(as, MIPSI_ANDI, dest, dest, 0xff00);
+ emit_dta(as, MIPSI_SLL, RID_TMP, RID_TMP, 8);
+ emit_dta(as, MIPSI_SRL, dest, left, 8);
+ emit_tsi(as, MIPSI_ANDI, RID_TMP, left, 0xff00);
+ emit_dst(as, MIPSI_OR, tmp, tmp, RID_TMP);
+ emit_dta(as, MIPSI_SRL, tmp, left, 24);
+ emit_dta(as, MIPSI_SLL, RID_TMP, left, 24);
+ }
+}
+
+static void asm_bitop(ASMState *as, IRIns *ir, MIPSIns mi, MIPSIns mik)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (checku16(k)) {
+ emit_tsi(as, mik, dest, left, k);
+ return;
+ }
+ }
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_dst(as, mi, dest, left, right);
+}
+
+static void asm_bitshift(ASMState *as, IRIns *ir, MIPSIns mi, MIPSIns mik)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (irref_isk(ir->op2)) { /* Constant shifts. */
+ uint32_t shift = (uint32_t)(IR(ir->op2)->i & 31);
+ emit_dta(as, mik, dest, ra_hintalloc(as, ir->op1, dest, RSET_GPR), shift);
+ } else {
+ Reg right, left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ emit_dst(as, mi, dest, right, left); /* Shift amount is in rs. */
+ }
+}
+
+static void asm_bitror(ASMState *as, IRIns *ir)
+{
+ if ((as->flags & JIT_F_MIPS32R2)) {
+ asm_bitshift(as, ir, MIPSI_ROTRV, MIPSI_ROTR);
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (irref_isk(ir->op2)) { /* Constant shifts. */
+ uint32_t shift = (uint32_t)(IR(ir->op2)->i & 31);
+ Reg left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ emit_rotr(as, dest, left, RID_TMP, shift);
+ } else {
+ Reg right, left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ emit_dst(as, MIPSI_OR, dest, dest, RID_TMP);
+ emit_dst(as, MIPSI_SRLV, dest, right, left);
+ emit_dst(as, MIPSI_SLLV, RID_TMP, RID_TMP, left);
+ emit_dst(as, MIPSI_SUBU, RID_TMP, ra_allock(as, 32, RSET_GPR), right);
+ }
+ }
+}
+
+static void asm_min_max(ASMState *as, IRIns *ir, int ismax)
+{
+ if (irt_isnum(ir->t)) {
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg right, left = ra_alloc2(as, ir, RSET_FPR);
+ right = (left >> 8); left &= 255;
+ if (dest == left) {
+ emit_fg(as, MIPSI_MOVT_D, dest, right);
+ } else {
+ emit_fg(as, MIPSI_MOVF_D, dest, left);
+ if (dest != right) emit_fg(as, MIPSI_MOV_D, dest, right);
+ }
+ emit_fgh(as, MIPSI_C_OLT_D, 0, ismax ? left : right, ismax ? right : left);
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ if (dest == left) {
+ emit_dst(as, MIPSI_MOVN, dest, right, RID_TMP);
+ } else {
+ emit_dst(as, MIPSI_MOVZ, dest, left, RID_TMP);
+ if (dest != right) emit_move(as, dest, right);
+ }
+ emit_dst(as, MIPSI_SLT, RID_TMP,
+ ismax ? left : right, ismax ? right : left);
+ }
+}
+
+/* -- Comparisons --------------------------------------------------------- */
+
+static void asm_comp(ASMState *as, IRIns *ir)
+{
+ /* ORDER IR: LT GE LE GT ULT UGE ULE UGT. */
+ IROp op = ir->o;
+ if (irt_isnum(ir->t)) {
+ Reg right, left = ra_alloc2(as, ir, RSET_FPR);
+ right = (left >> 8); left &= 255;
+ asm_guard(as, (op&1) ? MIPSI_BC1T : MIPSI_BC1F, 0, 0);
+ emit_fgh(as, MIPSI_C_OLT_D + ((op&3) ^ ((op>>2)&1)), 0, left, right);
+ } else {
+ Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);
+ if (op == IR_ABC) op = IR_UGT;
+ if ((op&4) == 0 && irref_isk(ir->op2) && IR(ir->op2)->i == 0) {
+ MIPSIns mi = (op&2) ? ((op&1) ? MIPSI_BLEZ : MIPSI_BGTZ) :
+ ((op&1) ? MIPSI_BLTZ : MIPSI_BGEZ);
+ asm_guard(as, mi, left, 0);
+ } else {
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if ((op&2)) k++;
+ if (checki16(k)) {
+ asm_guard(as, (op&1) ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO);
+ emit_tsi(as, (op&4) ? MIPSI_SLTIU : MIPSI_SLTI,
+ RID_TMP, left, k);
+ return;
+ }
+ }
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ asm_guard(as, ((op^(op>>1))&1) ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO);
+ emit_dst(as, (op&4) ? MIPSI_SLTU : MIPSI_SLT,
+ RID_TMP, (op&2) ? right : left, (op&2) ? left : right);
+ }
+ }
+}
+
+static void asm_compeq(ASMState *as, IRIns *ir)
+{
+ Reg right, left = ra_alloc2(as, ir, irt_isnum(ir->t) ? RSET_FPR : RSET_GPR);
+ right = (left >> 8); left &= 255;
+ if (irt_isnum(ir->t)) {
+ asm_guard(as, (ir->o & 1) ? MIPSI_BC1T : MIPSI_BC1F, 0, 0);
+ emit_fgh(as, MIPSI_C_EQ_D, 0, left, right);
+ } else {
+ asm_guard(as, (ir->o & 1) ? MIPSI_BEQ : MIPSI_BNE, left, right);
+ }
+}
+
+#if LJ_HASFFI
+/* 64 bit integer comparisons. */
+static void asm_comp64(ASMState *as, IRIns *ir)
+{
+ /* ORDER IR: LT GE LE GT ULT UGE ULE UGT. */
+ IROp op = (ir-1)->o;
+ MCLabel l_end;
+ Reg rightlo, leftlo, righthi, lefthi = ra_alloc2(as, ir, RSET_GPR);
+ righthi = (lefthi >> 8); lefthi &= 255;
+ leftlo = ra_alloc2(as, ir-1,
+ rset_exclude(rset_exclude(RSET_GPR, lefthi), righthi));
+ rightlo = (leftlo >> 8); leftlo &= 255;
+ asm_guard(as, ((op^(op>>1))&1) ? MIPSI_BNE : MIPSI_BEQ, RID_TMP, RID_ZERO);
+ l_end = emit_label(as);
+ if (lefthi != righthi)
+ emit_dst(as, (op&4) ? MIPSI_SLTU : MIPSI_SLT, RID_TMP,
+ (op&2) ? righthi : lefthi, (op&2) ? lefthi : righthi);
+ emit_dst(as, MIPSI_SLTU, RID_TMP,
+ (op&2) ? rightlo : leftlo, (op&2) ? leftlo : rightlo);
+ if (lefthi != righthi)
+ emit_branch(as, MIPSI_BEQ, lefthi, righthi, l_end);
+}
+
+static void asm_comp64eq(ASMState *as, IRIns *ir)
+{
+ Reg tmp, right, left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ asm_guard(as, ((ir-1)->o & 1) ? MIPSI_BEQ : MIPSI_BNE, RID_TMP, RID_ZERO);
+ tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR, left), right));
+ emit_dst(as, MIPSI_OR, RID_TMP, RID_TMP, tmp);
+ emit_dst(as, MIPSI_XOR, tmp, left, right);
+ left = ra_alloc2(as, ir-1, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ emit_dst(as, MIPSI_XOR, RID_TMP, left, right);
+}
+#endif
+
+/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */
+
+/* Hiword op of a split 64 bit op. Previous op must be the loword op. */
+static void asm_hiop(ASMState *as, IRIns *ir)
+{
+#if LJ_HASFFI
+ /* HIOP is marked as a store because it needs its own DCE logic. */
+ int uselo = ra_used(ir-1), usehi = ra_used(ir); /* Loword/hiword used? */
+ if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1;
+ if ((ir-1)->o == IR_CONV) { /* Conversions to/from 64 bit. */
+ as->curins--; /* Always skip the CONV. */
+ if (usehi || uselo)
+ asm_conv64(as, ir);
+ return;
+ } else if ((ir-1)->o < IR_EQ) { /* 64 bit integer comparisons. ORDER IR. */
+ as->curins--; /* Always skip the loword comparison. */
+ asm_comp64(as, ir);
+ return;
+ } else if ((ir-1)->o <= IR_NE) { /* 64 bit integer comparisons. ORDER IR. */
+ as->curins--; /* Always skip the loword comparison. */
+ asm_comp64eq(as, ir);
+ return;
+ } else if ((ir-1)->o == IR_XSTORE) {
+ as->curins--; /* Handle both stores here. */
+ if ((ir-1)->r != RID_SINK) {
+ asm_xstore(as, ir, LJ_LE ? 4 : 0);
+ asm_xstore(as, ir-1, LJ_LE ? 0 : 4);
+ }
+ return;
+ }
+ if (!usehi) return; /* Skip unused hiword op for all remaining ops. */
+ switch ((ir-1)->o) {
+ case IR_ADD: as->curins--; asm_add64(as, ir); break;
+ case IR_SUB: as->curins--; asm_sub64(as, ir); break;
+ case IR_NEG: as->curins--; asm_neg64(as, ir); break;
+ case IR_CALLN:
+ case IR_CALLXS:
+ if (!uselo)
+ ra_allocref(as, ir->op1, RID2RSET(RID_RETLO)); /* Mark lo op as used. */
+ break;
+ case IR_CNEWI:
+ /* Nothing to do here. Handled by lo op itself. */
+ break;
+ default: lua_assert(0); break;
+ }
+#else
+ UNUSED(as); UNUSED(ir); lua_assert(0); /* Unused without FFI. */
+#endif
+}
+
+/* -- Stack handling ------------------------------------------------------ */
+
+/* Check Lua stack size for overflow. Use exit handler as fallback. */
+static void asm_stack_check(ASMState *as, BCReg topslot,
+ IRIns *irp, RegSet allow, ExitNo exitno)
+{
+ /* Try to get an unused temp. register, otherwise spill/restore RID_RET*. */
+ Reg tmp, pbase = irp ? (ra_hasreg(irp->r) ? irp->r : RID_TMP) : RID_BASE;
+ ExitNo oldsnap = as->snapno;
+ rset_clear(allow, pbase);
+ tmp = allow ? rset_pickbot(allow) :
+ (pbase == RID_RETHI ? RID_RETLO : RID_RETHI);
+ as->snapno = exitno;
+ asm_guard(as, MIPSI_BNE, RID_TMP, RID_ZERO);
+ as->snapno = oldsnap;
+ if (allow == RSET_EMPTY) /* Restore temp. register. */
+ emit_tsi(as, MIPSI_LW, tmp, RID_SP, 0);
+ else
+ ra_modified(as, tmp);
+ emit_tsi(as, MIPSI_SLTIU, RID_TMP, RID_TMP, (int32_t)(8*topslot));
+ emit_dst(as, MIPSI_SUBU, RID_TMP, tmp, pbase);
+ emit_tsi(as, MIPSI_LW, tmp, tmp, offsetof(lua_State, maxstack));
+ if (pbase == RID_TMP)
+ emit_getgl(as, RID_TMP, jit_base);
+ emit_getgl(as, tmp, jit_L);
+ if (allow == RSET_EMPTY) /* Spill temp. register. */
+ emit_tsi(as, MIPSI_SW, tmp, RID_SP, 0);
+}
+
+/* Restore Lua stack from on-trace state. */
+static void asm_stack_restore(ASMState *as, SnapShot *snap)
+{
+ SnapEntry *map = &as->T->snapmap[snap->mapofs];
+ SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1];
+ MSize n, nent = snap->nent;
+ /* Store the value of all modified slots to the Lua stack. */
+ for (n = 0; n < nent; n++) {
+ SnapEntry sn = map[n];
+ BCReg s = snap_slot(sn);
+ int32_t ofs = 8*((int32_t)s-1);
+ IRRef ref = snap_ref(sn);
+ IRIns *ir = IR(ref);
+ if ((sn & SNAP_NORESTORE))
+ continue;
+ if (irt_isnum(ir->t)) {
+ Reg src = ra_alloc1(as, ref, RSET_FPR);
+ emit_hsi(as, MIPSI_SDC1, src, RID_BASE, ofs);
+ } else {
+ Reg type;
+ RegSet allow = rset_exclude(RSET_GPR, RID_BASE);
+ lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t));
+ if (!irt_ispri(ir->t)) {
+ Reg src = ra_alloc1(as, ref, allow);
+ rset_clear(allow, src);
+ emit_tsi(as, MIPSI_SW, src, RID_BASE, ofs+(LJ_BE?4:0));
+ }
+ if ((sn & (SNAP_CONT|SNAP_FRAME))) {
+ if (s == 0) continue; /* Do not overwrite link to previous frame. */
+ type = ra_allock(as, (int32_t)(*flinks--), allow);
+ } else {
+ type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);
+ }
+ emit_tsi(as, MIPSI_SW, type, RID_BASE, ofs+(LJ_BE?0:4));
+ }
+ checkmclim(as);
+ }
+ lua_assert(map + nent == flinks);
+}
+
+/* -- GC handling --------------------------------------------------------- */
+
+/* Check GC threshold and do one or more GC steps. */
+static void asm_gc_check(ASMState *as)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit];
+ IRRef args[2];
+ MCLabel l_end;
+ Reg tmp;
+ ra_evictset(as, RSET_SCRATCH);
+ l_end = emit_label(as);
+ /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */
+ /* Assumes asm_snap_prep() already done. */
+ asm_guard(as, MIPSI_BNE, RID_RET, RID_ZERO);
+ args[0] = ASMREF_TMP1; /* global_State *g */
+ args[1] = ASMREF_TMP2; /* MSize steps */
+ asm_gencall(as, ci, args);
+ emit_tsi(as, MIPSI_ADDIU, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768);
+ tmp = ra_releasetmp(as, ASMREF_TMP2);
+ emit_loadi(as, tmp, as->gcsteps);
+ /* Jump around GC step if GC total < GC threshold. */
+ emit_branch(as, MIPSI_BNE, RID_TMP, RID_ZERO, l_end);
+ emit_dst(as, MIPSI_SLTU, RID_TMP, RID_TMP, tmp);
+ emit_getgl(as, tmp, gc.threshold);
+ emit_getgl(as, RID_TMP, gc.total);
+ as->gcsteps = 0;
+ checkmclim(as);
+}
+
+/* -- Loop handling ------------------------------------------------------- */
+
+/* Fixup the loop branch. */
+static void asm_loop_fixup(ASMState *as)
+{
+ MCode *p = as->mctop;
+ MCode *target = as->mcp;
+ p[-1] = MIPSI_NOP;
+ if (as->loopinv) { /* Inverted loop branch? */
+ /* asm_guard already inverted the cond branch. Only patch the target. */
+ p[-3] |= ((target-p+2) & 0x0000ffffu);
+ } else {
+ p[-2] = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu);
+ }
+}
+
+/* -- Head of trace ------------------------------------------------------- */
+
+/* Coalesce BASE register for a root trace. */
+static void asm_head_root_base(ASMState *as)
+{
+ IRIns *ir = IR(REF_BASE);
+ Reg r = ir->r;
+ if (as->loopinv) as->mctop--;
+ if (ra_hasreg(r)) {
+ ra_free(as, r);
+ if (rset_test(as->modset, r) || irt_ismarked(ir->t))
+ ir->r = RID_INIT; /* No inheritance for modified BASE register. */
+ if (r != RID_BASE)
+ emit_move(as, r, RID_BASE);
+ }
+}
+
+/* Coalesce BASE register for a side trace. */
+static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow)
+{
+ IRIns *ir = IR(REF_BASE);
+ Reg r = ir->r;
+ if (as->loopinv) as->mctop--;
+ if (ra_hasreg(r)) {
+ ra_free(as, r);
+ if (rset_test(as->modset, r) || irt_ismarked(ir->t))
+ ir->r = RID_INIT; /* No inheritance for modified BASE register. */
+ if (irp->r == r) {
+ rset_clear(allow, r); /* Mark same BASE register as coalesced. */
+ } else if (ra_hasreg(irp->r) && rset_test(as->freeset, irp->r)) {
+ rset_clear(allow, irp->r);
+ emit_move(as, r, irp->r); /* Move from coalesced parent reg. */
+ } else {
+ emit_getgl(as, r, jit_base); /* Otherwise reload BASE. */
+ }
+ }
+ return allow;
+}
+
+/* -- Tail of trace ------------------------------------------------------- */
+
+/* Fixup the tail code. */
+static void asm_tail_fixup(ASMState *as, TraceNo lnk)
+{
+ MCode *target = lnk ? traceref(as->J,lnk)->mcode : (MCode *)lj_vm_exit_interp;
+ int32_t spadj = as->T->spadjust;
+ MCode *p = as->mctop-1;
+ *p = spadj ? (MIPSI_ADDIU|MIPSF_T(RID_SP)|MIPSF_S(RID_SP)|spadj) : MIPSI_NOP;
+ p[-1] = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu);
+}
+
+/* Prepare tail of code. */
+static void asm_tail_prep(ASMState *as)
+{
+ as->mcp = as->mctop-2; /* Leave room for branch plus nop or stack adj. */
+ as->invmcp = as->loopref ? as->mcp : NULL;
+}
+
+/* -- Instruction dispatch ------------------------------------------------ */
+
+/* Assemble a single instruction. */
+static void asm_ir(ASMState *as, IRIns *ir)
+{
+ switch ((IROp)ir->o) {
+ /* Miscellaneous ops. */
+ case IR_LOOP: asm_loop(as); break;
+ case IR_NOP: case IR_XBAR: lua_assert(!ra_used(ir)); break;
+ case IR_USE:
+ ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break;
+ case IR_PHI: asm_phi(as, ir); break;
+ case IR_HIOP: asm_hiop(as, ir); break;
+ case IR_GCSTEP: asm_gcstep(as, ir); break;
+
+ /* Guarded assertions. */
+ case IR_EQ: case IR_NE: asm_compeq(as, ir); break;
+ case IR_LT: case IR_GE: case IR_LE: case IR_GT:
+ case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT:
+ case IR_ABC:
+ asm_comp(as, ir);
+ break;
+
+ case IR_RETF: asm_retf(as, ir); break;
+
+ /* Bit ops. */
+ case IR_BNOT: asm_bitnot(as, ir); break;
+ case IR_BSWAP: asm_bitswap(as, ir); break;
+
+ case IR_BAND: asm_bitop(as, ir, MIPSI_AND, MIPSI_ANDI); break;
+ case IR_BOR: asm_bitop(as, ir, MIPSI_OR, MIPSI_ORI); break;
+ case IR_BXOR: asm_bitop(as, ir, MIPSI_XOR, MIPSI_XORI); break;
+
+ case IR_BSHL: asm_bitshift(as, ir, MIPSI_SLLV, MIPSI_SLL); break;
+ case IR_BSHR: asm_bitshift(as, ir, MIPSI_SRLV, MIPSI_SRL); break;
+ case IR_BSAR: asm_bitshift(as, ir, MIPSI_SRAV, MIPSI_SRA); break;
+ case IR_BROL: lua_assert(0); break;
+ case IR_BROR: asm_bitror(as, ir); break;
+
+ /* Arithmetic ops. */
+ case IR_ADD: asm_add(as, ir); break;
+ case IR_SUB: asm_sub(as, ir); break;
+ case IR_MUL: asm_mul(as, ir); break;
+ case IR_DIV: asm_fparith(as, ir, MIPSI_DIV_D); break;
+ case IR_MOD: asm_callid(as, ir, IRCALL_lj_vm_modi); break;
+ case IR_POW: asm_callid(as, ir, IRCALL_lj_vm_powi); break;
+ case IR_NEG: asm_neg(as, ir); break;
+
+ case IR_ABS: asm_fpunary(as, ir, MIPSI_ABS_D); break;
+ case IR_ATAN2: asm_callid(as, ir, IRCALL_atan2); break;
+ case IR_LDEXP: asm_callid(as, ir, IRCALL_ldexp); break;
+ case IR_MIN: asm_min_max(as, ir, 0); break;
+ case IR_MAX: asm_min_max(as, ir, 1); break;
+ case IR_FPMATH:
+ if (ir->op2 == IRFPM_EXP2 && asm_fpjoin_pow(as, ir))
+ break;
+ if (ir->op2 <= IRFPM_TRUNC)
+ asm_callround(as, ir, IRCALL_lj_vm_floor + ir->op2);
+ else if (ir->op2 == IRFPM_SQRT)
+ asm_fpunary(as, ir, MIPSI_SQRT_D);
+ else
+ asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2);
+ break;
+
+ /* Overflow-checking arithmetic ops. */
+ case IR_ADDOV: asm_arithov(as, ir); break;
+ case IR_SUBOV: asm_arithov(as, ir); break;
+ case IR_MULOV: asm_mulov(as, ir); break;
+
+ /* Memory references. */
+ case IR_AREF: asm_aref(as, ir); break;
+ case IR_HREF: asm_href(as, ir); break;
+ case IR_HREFK: asm_hrefk(as, ir); break;
+ case IR_NEWREF: asm_newref(as, ir); break;
+ case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break;
+ case IR_FREF: asm_fref(as, ir); break;
+ case IR_STRREF: asm_strref(as, ir); break;
+
+ /* Loads and stores. */
+ case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:
+ asm_ahuvload(as, ir);
+ break;
+ case IR_FLOAD: asm_fload(as, ir); break;
+ case IR_XLOAD: asm_xload(as, ir); break;
+ case IR_SLOAD: asm_sload(as, ir); break;
+
+ case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break;
+ case IR_FSTORE: asm_fstore(as, ir); break;
+ case IR_XSTORE: asm_xstore(as, ir, 0); break;
+
+ /* Allocations. */
+ case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break;
+ case IR_TNEW: asm_tnew(as, ir); break;
+ case IR_TDUP: asm_tdup(as, ir); break;
+ case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break;
+
+ /* Write barriers. */
+ case IR_TBAR: asm_tbar(as, ir); break;
+ case IR_OBAR: asm_obar(as, ir); break;
+
+ /* Type conversions. */
+ case IR_CONV: asm_conv(as, ir); break;
+ case IR_TOBIT: asm_tobit(as, ir); break;
+ case IR_TOSTR: asm_tostr(as, ir); break;
+ case IR_STRTO: asm_strto(as, ir); break;
+
+ /* Calls. */
+ case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break;
+ case IR_CALLXS: asm_callx(as, ir); break;
+ case IR_CARG: break;
+
+ default:
+ setintV(&as->J->errinfo, ir->o);
+ lj_trace_err_info(as->J, LJ_TRERR_NYIIR);
+ break;
+ }
+}
+
+/* -- Trace setup --------------------------------------------------------- */
+
+/* Ensure there are enough stack slots for call arguments. */
+static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)
+{
+ IRRef args[CCI_NARGS_MAX*2];
+ uint32_t i, nargs = (int)CCI_NARGS(ci);
+ int nslots = 4, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR;
+ asm_collectargs(as, ir, ci, args);
+ for (i = 0; i < nargs; i++) {
+ if (args[i] && irt_isfp(IR(args[i])->t) &&
+ nfpr > 0 && !(ci->flags & CCI_VARARG)) {
+ nfpr--;
+ ngpr -= irt_isnum(IR(args[i])->t) ? 2 : 1;
+ } else if (args[i] && irt_isnum(IR(args[i])->t)) {
+ nfpr = 0;
+ ngpr = ngpr & ~1;
+ if (ngpr > 0) ngpr -= 2; else nslots = (nslots+3) & ~1;
+ } else {
+ nfpr = 0;
+ if (ngpr > 0) ngpr--; else nslots++;
+ }
+ }
+ if (nslots > as->evenspill) /* Leave room for args in stack slots. */
+ as->evenspill = nslots;
+ return irt_isfp(ir->t) ? REGSP_HINT(RID_FPRET) : REGSP_HINT(RID_RET);
+}
+
+static void asm_setup_target(ASMState *as)
+{
+ asm_sparejump_setup(as);
+ asm_exitstub_setup(as);
+}
+
+/* -- Trace patching ------------------------------------------------------ */
+
+/* Patch exit jumps of existing machine code to a new target. */
+void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target)
+{
+ MCode *p = T->mcode;
+ MCode *pe = (MCode *)((char *)p + T->szmcode);
+ MCode *px = exitstub_trace_addr(T, exitno);
+ MCode *cstart = NULL, *cstop = NULL;
+ MCode *mcarea = lj_mcode_patch(J, p, 0);
+ MCode exitload = MIPSI_LI | MIPSF_T(RID_TMP) | exitno;
+ MCode tjump = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu);
+ for (p++; p < pe; p++) {
+ if (*p == exitload) { /* Look for load of exit number. */
+ /* Look for exitstub branch. Yes, this covers all used branch variants. */
+ if (((p[-1] ^ (px-p)) & 0xffffu) == 0 &&
+ ((p[-1] & 0xf0000000u) == MIPSI_BEQ ||
+ (p[-1] & 0xfc1e0000u) == MIPSI_BLTZ ||
+ (p[-1] & 0xffe00000u) == MIPSI_BC1F)) {
+ ptrdiff_t delta = target - p;
+ if (((delta + 0x8000) >> 16) == 0) { /* Patch in-range branch. */
+ patchbranch:
+ p[-1] = (p[-1] & 0xffff0000u) | (delta & 0xffffu);
+ *p = MIPSI_NOP; /* Replace the load of the exit number. */
+ cstop = p;
+ if (!cstart) cstart = p-1;
+ } else { /* Branch out of range. Use spare jump slot in mcarea. */
+ int i;
+ for (i = (int)(sizeof(MCLink)/sizeof(MCode));
+ i < (int)(sizeof(MCLink)/sizeof(MCode)+MIPS_SPAREJUMP*2);
+ i += 2) {
+ if (mcarea[i] == tjump) {
+ delta = mcarea+i - p;
+ goto patchbranch;
+ } else if (mcarea[i] == MIPSI_NOP) {
+ mcarea[i] = tjump;
+ cstart = mcarea+i;
+ delta = mcarea+i - p;
+ goto patchbranch;
+ }
+ }
+ /* Ignore jump slot overflow. Child trace is simply not attached. */
+ }
+ } else if (p+1 == pe) {
+ /* Patch NOP after code for inverted loop branch. Use of J is ok. */
+ lua_assert(p[1] == MIPSI_NOP);
+ p[1] = tjump;
+ *p = MIPSI_NOP; /* Replace the load of the exit number. */
+ cstop = p+2;
+ if (!cstart) cstart = p+1;
+ }
+ }
+ }
+ if (cstart) lj_mcode_sync(cstart, cstop);
+ lj_mcode_patch(J, mcarea, 1);
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_asm_ppc.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_asm_ppc.h
new file mode 100644
index 0000000..d8a14c8
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_asm_ppc.h
@@ -0,0 +1,2168 @@
+/*
+** PPC IR assembler (SSA IR -> machine code).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* -- Register allocator extensions --------------------------------------- */
+
+/* Allocate a register with a hint. */
+static Reg ra_hintalloc(ASMState *as, IRRef ref, Reg hint, RegSet allow)
+{
+ Reg r = IR(ref)->r;
+ if (ra_noreg(r)) {
+ if (!ra_hashint(r) && !iscrossref(as, ref))
+ ra_sethint(IR(ref)->r, hint); /* Propagate register hint. */
+ r = ra_allocref(as, ref, allow);
+ }
+ ra_noweak(as, r);
+ return r;
+}
+
+/* Allocate two source registers for three-operand instructions. */
+static Reg ra_alloc2(ASMState *as, IRIns *ir, RegSet allow)
+{
+ IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);
+ Reg left = irl->r, right = irr->r;
+ if (ra_hasreg(left)) {
+ ra_noweak(as, left);
+ if (ra_noreg(right))
+ right = ra_allocref(as, ir->op2, rset_exclude(allow, left));
+ else
+ ra_noweak(as, right);
+ } else if (ra_hasreg(right)) {
+ ra_noweak(as, right);
+ left = ra_allocref(as, ir->op1, rset_exclude(allow, right));
+ } else if (ra_hashint(right)) {
+ right = ra_allocref(as, ir->op2, allow);
+ left = ra_alloc1(as, ir->op1, rset_exclude(allow, right));
+ } else {
+ left = ra_allocref(as, ir->op1, allow);
+ right = ra_alloc1(as, ir->op2, rset_exclude(allow, left));
+ }
+ return left | (right << 8);
+}
+
+/* -- Guard handling ------------------------------------------------------ */
+
+/* Setup exit stubs after the end of each trace. */
+static void asm_exitstub_setup(ASMState *as, ExitNo nexits)
+{
+ ExitNo i;
+ MCode *mxp = as->mctop;
+ if (mxp - (nexits + 3 + MCLIM_REDZONE) < as->mclim)
+ asm_mclimit(as);
+ /* 1: mflr r0; bl ->vm_exit_handler; li r0, traceno; bl <1; bl <1; ... */
+ for (i = nexits-1; (int32_t)i >= 0; i--)
+ *--mxp = PPCI_BL|(((-3-i)&0x00ffffffu)<<2);
+ *--mxp = PPCI_LI|PPCF_T(RID_TMP)|as->T->traceno; /* Read by exit handler. */
+ mxp--;
+ *mxp = PPCI_BL|((((MCode *)(void *)lj_vm_exit_handler-mxp)&0x00ffffffu)<<2);
+ *--mxp = PPCI_MFLR|PPCF_T(RID_TMP);
+ as->mctop = mxp;
+}
+
+static MCode *asm_exitstub_addr(ASMState *as, ExitNo exitno)
+{
+ /* Keep this in-sync with exitstub_trace_addr(). */
+ return as->mctop + exitno + 3;
+}
+
+/* Emit conditional branch to exit for guard. */
+static void asm_guardcc(ASMState *as, PPCCC cc)
+{
+ MCode *target = asm_exitstub_addr(as, as->snapno);
+ MCode *p = as->mcp;
+ if (LJ_UNLIKELY(p == as->invmcp)) {
+ as->loopinv = 1;
+ *p = PPCI_B | (((target-p) & 0x00ffffffu) << 2);
+ emit_condbranch(as, PPCI_BC, cc^4, p);
+ return;
+ }
+ emit_condbranch(as, PPCI_BC, cc, target);
+}
+
+/* -- Operand fusion ------------------------------------------------------ */
+
+/* Limit linear search to this distance. Avoids O(n^2) behavior. */
+#define CONFLICT_SEARCH_LIM 31
+
+/* Check if there's no conflicting instruction between curins and ref. */
+static int noconflict(ASMState *as, IRRef ref, IROp conflict)
+{
+ IRIns *ir = as->ir;
+ IRRef i = as->curins;
+ if (i > ref + CONFLICT_SEARCH_LIM)
+ return 0; /* Give up, ref is too far away. */
+ while (--i > ref)
+ if (ir[i].o == conflict)
+ return 0; /* Conflict found. */
+ return 1; /* Ok, no conflict. */
+}
+
+/* Fuse the array base of colocated arrays. */
+static int32_t asm_fuseabase(ASMState *as, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ if (ir->o == IR_TNEW && ir->op1 <= LJ_MAX_COLOSIZE &&
+ !neverfuse(as) && noconflict(as, ref, IR_NEWREF))
+ return (int32_t)sizeof(GCtab);
+ return 0;
+}
+
+/* Indicates load/store indexed is ok. */
+#define AHUREF_LSX ((int32_t)0x80000000)
+
+/* Fuse array/hash/upvalue reference into register+offset operand. */
+static Reg asm_fuseahuref(ASMState *as, IRRef ref, int32_t *ofsp, RegSet allow)
+{
+ IRIns *ir = IR(ref);
+ if (ra_noreg(ir->r)) {
+ if (ir->o == IR_AREF) {
+ if (mayfuse(as, ref)) {
+ if (irref_isk(ir->op2)) {
+ IRRef tab = IR(ir->op1)->op1;
+ int32_t ofs = asm_fuseabase(as, tab);
+ IRRef refa = ofs ? tab : ir->op1;
+ ofs += 8*IR(ir->op2)->i;
+ if (checki16(ofs)) {
+ *ofsp = ofs;
+ return ra_alloc1(as, refa, allow);
+ }
+ }
+ if (*ofsp == AHUREF_LSX) {
+ Reg base = ra_alloc1(as, ir->op1, allow);
+ Reg idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base));
+ return base | (idx << 8);
+ }
+ }
+ } else if (ir->o == IR_HREFK) {
+ if (mayfuse(as, ref)) {
+ int32_t ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node));
+ if (checki16(ofs)) {
+ *ofsp = ofs;
+ return ra_alloc1(as, ir->op1, allow);
+ }
+ }
+ } else if (ir->o == IR_UREFC) {
+ if (irref_isk(ir->op1)) {
+ GCfunc *fn = ir_kfunc(IR(ir->op1));
+ int32_t ofs = i32ptr(&gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.tv);
+ int32_t jgl = (intptr_t)J2G(as->J);
+ if ((uint32_t)(ofs-jgl) < 65536) {
+ *ofsp = ofs-jgl-32768;
+ return RID_JGL;
+ } else {
+ *ofsp = (int16_t)ofs;
+ return ra_allock(as, ofs-(int16_t)ofs, allow);
+ }
+ }
+ }
+ }
+ *ofsp = 0;
+ return ra_alloc1(as, ref, allow);
+}
+
+/* Fuse XLOAD/XSTORE reference into load/store operand. */
+static void asm_fusexref(ASMState *as, PPCIns pi, Reg rt, IRRef ref,
+ RegSet allow, int32_t ofs)
+{
+ IRIns *ir = IR(ref);
+ Reg base;
+ if (ra_noreg(ir->r) && canfuse(as, ir)) {
+ if (ir->o == IR_ADD) {
+ int32_t ofs2;
+ if (irref_isk(ir->op2) && (ofs2 = ofs + IR(ir->op2)->i, checki16(ofs2))) {
+ ofs = ofs2;
+ ref = ir->op1;
+ } else if (ofs == 0) {
+ Reg right, left = ra_alloc2(as, ir, allow);
+ right = (left >> 8); left &= 255;
+ emit_fab(as, PPCI_LWZX | ((pi >> 20) & 0x780), rt, left, right);
+ return;
+ }
+ } else if (ir->o == IR_STRREF) {
+ lua_assert(ofs == 0);
+ ofs = (int32_t)sizeof(GCstr);
+ if (irref_isk(ir->op2)) {
+ ofs += IR(ir->op2)->i;
+ ref = ir->op1;
+ } else if (irref_isk(ir->op1)) {
+ ofs += IR(ir->op1)->i;
+ ref = ir->op2;
+ } else {
+ /* NYI: Fuse ADD with constant. */
+ Reg tmp, right, left = ra_alloc2(as, ir, allow);
+ right = (left >> 8); left &= 255;
+ tmp = ra_scratch(as, rset_exclude(rset_exclude(allow, left), right));
+ emit_fai(as, pi, rt, tmp, ofs);
+ emit_tab(as, PPCI_ADD, tmp, left, right);
+ return;
+ }
+ if (!checki16(ofs)) {
+ Reg left = ra_alloc1(as, ref, allow);
+ Reg right = ra_allock(as, ofs, rset_exclude(allow, left));
+ emit_fab(as, PPCI_LWZX | ((pi >> 20) & 0x780), rt, left, right);
+ return;
+ }
+ }
+ }
+ base = ra_alloc1(as, ref, allow);
+ emit_fai(as, pi, rt, base, ofs);
+}
+
+/* Fuse XLOAD/XSTORE reference into indexed-only load/store operand. */
+static void asm_fusexrefx(ASMState *as, PPCIns pi, Reg rt, IRRef ref,
+ RegSet allow)
+{
+ IRIns *ira = IR(ref);
+ Reg right, left;
+ if (canfuse(as, ira) && ira->o == IR_ADD && ra_noreg(ira->r)) {
+ left = ra_alloc2(as, ira, allow);
+ right = (left >> 8); left &= 255;
+ } else {
+ right = ra_alloc1(as, ref, allow);
+ left = RID_R0;
+ }
+ emit_tab(as, pi, rt, left, right);
+}
+
+/* Fuse to multiply-add/sub instruction. */
+static int asm_fusemadd(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pir)
+{
+ IRRef lref = ir->op1, rref = ir->op2;
+ IRIns *irm;
+ if (lref != rref &&
+ ((mayfuse(as, lref) && (irm = IR(lref), irm->o == IR_MUL) &&
+ ra_noreg(irm->r)) ||
+ (mayfuse(as, rref) && (irm = IR(rref), irm->o == IR_MUL) &&
+ (rref = lref, pi = pir, ra_noreg(irm->r))))) {
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg add = ra_alloc1(as, rref, RSET_FPR);
+ Reg right, left = ra_alloc2(as, irm, rset_exclude(RSET_FPR, add));
+ right = (left >> 8); left &= 255;
+ emit_facb(as, pi, dest, left, right, add);
+ return 1;
+ }
+ return 0;
+}
+
+/* -- Calls --------------------------------------------------------------- */
+
+/* Generate a call to a C function. */
+static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)
+{
+ uint32_t n, nargs = CCI_NARGS(ci);
+ int32_t ofs = 8;
+ Reg gpr = REGARG_FIRSTGPR, fpr = REGARG_FIRSTFPR;
+ if ((void *)ci->func)
+ emit_call(as, (void *)ci->func);
+ for (n = 0; n < nargs; n++) { /* Setup args. */
+ IRRef ref = args[n];
+ if (ref) {
+ IRIns *ir = IR(ref);
+ if (irt_isfp(ir->t)) {
+ if (fpr <= REGARG_LASTFPR) {
+ lua_assert(rset_test(as->freeset, fpr)); /* Already evicted. */
+ ra_leftov(as, fpr, ref);
+ fpr++;
+ } else {
+ Reg r = ra_alloc1(as, ref, RSET_FPR);
+ if (irt_isnum(ir->t)) ofs = (ofs + 4) & ~4;
+ emit_spstore(as, ir, r, ofs);
+ ofs += irt_isnum(ir->t) ? 8 : 4;
+ }
+ } else {
+ if (gpr <= REGARG_LASTGPR) {
+ lua_assert(rset_test(as->freeset, gpr)); /* Already evicted. */
+ ra_leftov(as, gpr, ref);
+ gpr++;
+ } else {
+ Reg r = ra_alloc1(as, ref, RSET_GPR);
+ emit_spstore(as, ir, r, ofs);
+ ofs += 4;
+ }
+ }
+ } else {
+ if (gpr <= REGARG_LASTGPR)
+ gpr++;
+ else
+ ofs += 4;
+ }
+ checkmclim(as);
+ }
+ if ((ci->flags & CCI_VARARG)) /* Vararg calls need to know about FPR use. */
+ emit_tab(as, fpr == REGARG_FIRSTFPR ? PPCI_CRXOR : PPCI_CREQV, 6, 6, 6);
+}
+
+/* Setup result reg/sp for call. Evict scratch regs. */
+static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci)
+{
+ RegSet drop = RSET_SCRATCH;
+ int hiop = ((ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t));
+ if ((ci->flags & CCI_NOFPRCLOBBER))
+ drop &= ~RSET_FPR;
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ if (hiop && ra_hasreg((ir+1)->r))
+ rset_clear(drop, (ir+1)->r); /* Dest reg handled below. */
+ ra_evictset(as, drop); /* Evictions must be performed first. */
+ if (ra_used(ir)) {
+ lua_assert(!irt_ispri(ir->t));
+ if (irt_isfp(ir->t)) {
+ if ((ci->flags & CCI_CASTU64)) {
+ /* Use spill slot or temp slots. */
+ int32_t ofs = ir->s ? sps_scale(ir->s) : SPOFS_TMP;
+ Reg dest = ir->r;
+ if (ra_hasreg(dest)) {
+ ra_free(as, dest);
+ ra_modified(as, dest);
+ emit_fai(as, PPCI_LFD, dest, RID_SP, ofs);
+ }
+ emit_tai(as, PPCI_STW, RID_RETHI, RID_SP, ofs);
+ emit_tai(as, PPCI_STW, RID_RETLO, RID_SP, ofs+4);
+ } else {
+ ra_destreg(as, ir, RID_FPRET);
+ }
+ } else if (hiop) {
+ ra_destpair(as, ir);
+ } else {
+ ra_destreg(as, ir, RID_RET);
+ }
+ }
+}
+
+static void asm_call(ASMState *as, IRIns *ir)
+{
+ IRRef args[CCI_NARGS_MAX];
+ const CCallInfo *ci = &lj_ir_callinfo[ir->op2];
+ asm_collectargs(as, ir, ci, args);
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+
+static void asm_callx(ASMState *as, IRIns *ir)
+{
+ IRRef args[CCI_NARGS_MAX*2];
+ CCallInfo ci;
+ IRRef func;
+ IRIns *irf;
+ ci.flags = asm_callx_flags(as, ir);
+ asm_collectargs(as, ir, &ci, args);
+ asm_setupresult(as, ir, &ci);
+ func = ir->op2; irf = IR(func);
+ if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }
+ if (irref_isk(func)) { /* Call to constant address. */
+ ci.func = (ASMFunction)(void *)(irf->i);
+ } else { /* Need a non-argument register for indirect calls. */
+ RegSet allow = RSET_GPR & ~RSET_RANGE(RID_R0, REGARG_LASTGPR+1);
+ Reg freg = ra_alloc1(as, func, allow);
+ *--as->mcp = PPCI_BCTRL;
+ *--as->mcp = PPCI_MTCTR | PPCF_T(freg);
+ ci.func = (ASMFunction)(void *)0;
+ }
+ asm_gencall(as, &ci, args);
+}
+
+static void asm_callid(ASMState *as, IRIns *ir, IRCallID id)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[id];
+ IRRef args[2];
+ args[0] = ir->op1;
+ args[1] = ir->op2;
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+
+/* -- Returns ------------------------------------------------------------- */
+
+/* Return to lower frame. Guard that it goes to the right spot. */
+static void asm_retf(ASMState *as, IRIns *ir)
+{
+ Reg base = ra_alloc1(as, REF_BASE, RSET_GPR);
+ void *pc = ir_kptr(IR(ir->op2));
+ int32_t delta = 1+bc_a(*((const BCIns *)pc - 1));
+ as->topslot -= (BCReg)delta;
+ if ((int32_t)as->topslot < 0) as->topslot = 0;
+ irt_setmark(IR(REF_BASE)->t); /* Children must not coalesce with BASE reg. */
+ emit_setgl(as, base, jit_base);
+ emit_addptr(as, base, -8*delta);
+ asm_guardcc(as, CC_NE);
+ emit_ab(as, PPCI_CMPW, RID_TMP,
+ ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base)));
+ emit_tai(as, PPCI_LWZ, RID_TMP, base, -8);
+}
+
+/* -- Type conversions ---------------------------------------------------- */
+
+static void asm_tointg(ASMState *as, IRIns *ir, Reg left)
+{
+ RegSet allow = RSET_FPR;
+ Reg tmp = ra_scratch(as, rset_clear(allow, left));
+ Reg fbias = ra_scratch(as, rset_clear(allow, tmp));
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg hibias = ra_allock(as, 0x43300000, rset_exclude(RSET_GPR, dest));
+ asm_guardcc(as, CC_NE);
+ emit_fab(as, PPCI_FCMPU, 0, tmp, left);
+ emit_fab(as, PPCI_FSUB, tmp, tmp, fbias);
+ emit_fai(as, PPCI_LFD, tmp, RID_SP, SPOFS_TMP);
+ emit_tai(as, PPCI_STW, RID_TMP, RID_SP, SPOFS_TMPLO);
+ emit_tai(as, PPCI_STW, hibias, RID_SP, SPOFS_TMPHI);
+ emit_asi(as, PPCI_XORIS, RID_TMP, dest, 0x8000);
+ emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO);
+ emit_lsptr(as, PPCI_LFS, (fbias & 31),
+ (void *)lj_ir_k64_find(as->J, U64x(59800004,59800000)),
+ RSET_GPR);
+ emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);
+ emit_fb(as, PPCI_FCTIWZ, tmp, left);
+}
+
+static void asm_tobit(ASMState *as, IRIns *ir)
+{
+ RegSet allow = RSET_FPR;
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, ir->op1, allow);
+ Reg right = ra_alloc1(as, ir->op2, rset_clear(allow, left));
+ Reg tmp = ra_scratch(as, rset_clear(allow, right));
+ emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO);
+ emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);
+ emit_fab(as, PPCI_FADD, tmp, left, right);
+}
+
+static void asm_conv(ASMState *as, IRIns *ir)
+{
+ IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);
+ int stfp = (st == IRT_NUM || st == IRT_FLOAT);
+ IRRef lref = ir->op1;
+ lua_assert(irt_type(ir->t) != st);
+ lua_assert(!(irt_isint64(ir->t) ||
+ (st == IRT_I64 || st == IRT_U64))); /* Handled by SPLIT. */
+ if (irt_isfp(ir->t)) {
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ if (stfp) { /* FP to FP conversion. */
+ if (st == IRT_NUM) /* double -> float conversion. */
+ emit_fb(as, PPCI_FRSP, dest, ra_alloc1(as, lref, RSET_FPR));
+ else /* float -> double conversion is a no-op on PPC. */
+ ra_leftov(as, dest, lref); /* Do nothing, but may need to move regs. */
+ } else { /* Integer to FP conversion. */
+ /* IRT_INT: Flip hibit, bias with 2^52, subtract 2^52+2^31. */
+ /* IRT_U32: Bias with 2^52, subtract 2^52. */
+ RegSet allow = RSET_GPR;
+ Reg left = ra_alloc1(as, lref, allow);
+ Reg hibias = ra_allock(as, 0x43300000, rset_clear(allow, left));
+ Reg fbias = ra_scratch(as, rset_exclude(RSET_FPR, dest));
+ const float *kbias;
+ if (irt_isfloat(ir->t)) emit_fb(as, PPCI_FRSP, dest, dest);
+ emit_fab(as, PPCI_FSUB, dest, dest, fbias);
+ emit_fai(as, PPCI_LFD, dest, RID_SP, SPOFS_TMP);
+ kbias = (const float *)lj_ir_k64_find(as->J, U64x(59800004,59800000));
+ if (st == IRT_U32) kbias++;
+ emit_lsptr(as, PPCI_LFS, (fbias & 31), (void *)kbias,
+ rset_clear(allow, hibias));
+ emit_tai(as, PPCI_STW, st == IRT_U32 ? left : RID_TMP,
+ RID_SP, SPOFS_TMPLO);
+ emit_tai(as, PPCI_STW, hibias, RID_SP, SPOFS_TMPHI);
+ if (st != IRT_U32) emit_asi(as, PPCI_XORIS, RID_TMP, left, 0x8000);
+ }
+ } else if (stfp) { /* FP to integer conversion. */
+ if (irt_isguard(ir->t)) {
+ /* Checked conversions are only supported from number to int. */
+ lua_assert(irt_isint(ir->t) && st == IRT_NUM);
+ asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR));
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, lref, RSET_FPR);
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));
+ if (irt_isu32(ir->t)) {
+ /* Convert both x and x-2^31 to int and merge results. */
+ Reg tmpi = ra_scratch(as, rset_exclude(RSET_GPR, dest));
+ emit_asb(as, PPCI_OR, dest, dest, tmpi); /* Select with mask idiom. */
+ emit_asb(as, PPCI_AND, tmpi, tmpi, RID_TMP);
+ emit_asb(as, PPCI_ANDC, dest, dest, RID_TMP);
+ emit_tai(as, PPCI_LWZ, tmpi, RID_SP, SPOFS_TMPLO); /* tmp = (int)(x) */
+ emit_tai(as, PPCI_ADDIS, dest, dest, 0x8000); /* dest += 2^31 */
+ emit_asb(as, PPCI_SRAWI, RID_TMP, dest, 31); /* mask = -(dest < 0) */
+ emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);
+ emit_tai(as, PPCI_LWZ, dest,
+ RID_SP, SPOFS_TMPLO); /* dest = (int)(x-2^31) */
+ emit_fb(as, PPCI_FCTIWZ, tmp, left);
+ emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);
+ emit_fb(as, PPCI_FCTIWZ, tmp, tmp);
+ emit_fab(as, PPCI_FSUB, tmp, left, tmp);
+ emit_lsptr(as, PPCI_LFS, (tmp & 31),
+ (void *)lj_ir_k64_find(as->J, U64x(4f000000,00000000)),
+ RSET_GPR);
+ } else {
+ emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO);
+ emit_fai(as, PPCI_STFD, tmp, RID_SP, SPOFS_TMP);
+ emit_fb(as, PPCI_FCTIWZ, tmp, left);
+ }
+ }
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */
+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
+ lua_assert(irt_isint(ir->t) || irt_isu32(ir->t));
+ if ((ir->op2 & IRCONV_SEXT))
+ emit_as(as, st == IRT_I8 ? PPCI_EXTSB : PPCI_EXTSH, dest, left);
+ else
+ emit_rot(as, PPCI_RLWINM, dest, left, 0, st == IRT_U8 ? 24 : 16, 31);
+ } else { /* 32/64 bit integer conversions. */
+ /* Only need to handle 32/32 bit no-op (cast) on 32 bit archs. */
+ ra_leftov(as, dest, lref); /* Do nothing, but may need to move regs. */
+ }
+ }
+}
+
+#if LJ_HASFFI
+static void asm_conv64(ASMState *as, IRIns *ir)
+{
+ IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK);
+ IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH);
+ IRCallID id;
+ const CCallInfo *ci;
+ IRRef args[2];
+ args[0] = ir->op1;
+ args[1] = (ir-1)->op1;
+ if (st == IRT_NUM || st == IRT_FLOAT) {
+ id = IRCALL_fp64_d2l + ((st == IRT_FLOAT) ? 2 : 0) + (dt - IRT_I64);
+ ir--;
+ } else {
+ id = IRCALL_fp64_l2d + ((dt == IRT_FLOAT) ? 2 : 0) + (st - IRT_I64);
+ }
+ ci = &lj_ir_callinfo[id];
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+#endif
+
+static void asm_strto(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num];
+ IRRef args[2];
+ int32_t ofs;
+ RegSet drop = RSET_SCRATCH;
+ if (ra_hasreg(ir->r)) rset_set(drop, ir->r); /* Spill dest reg (if any). */
+ ra_evictset(as, drop);
+ asm_guardcc(as, CC_EQ);
+ emit_ai(as, PPCI_CMPWI, RID_RET, 0); /* Test return status. */
+ args[0] = ir->op1; /* GCstr *str */
+ args[1] = ASMREF_TMP1; /* TValue *n */
+ asm_gencall(as, ci, args);
+ /* Store the result to the spill slot or temp slots. */
+ ofs = ir->s ? sps_scale(ir->s) : SPOFS_TMP;
+ emit_tai(as, PPCI_ADDI, ra_releasetmp(as, ASMREF_TMP1), RID_SP, ofs);
+}
+
+/* Get pointer to TValue. */
+static void asm_tvptr(ASMState *as, Reg dest, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ if (irt_isnum(ir->t)) {
+ if (irref_isk(ref)) /* Use the number constant itself as a TValue. */
+ ra_allockreg(as, i32ptr(ir_knum(ir)), dest);
+ else /* Otherwise force a spill and use the spill slot. */
+ emit_tai(as, PPCI_ADDI, dest, RID_SP, ra_spill(as, ir));
+ } else {
+ /* Otherwise use g->tmptv to hold the TValue. */
+ RegSet allow = rset_exclude(RSET_GPR, dest);
+ Reg type;
+ emit_tai(as, PPCI_ADDI, dest, RID_JGL, offsetof(global_State, tmptv)-32768);
+ if (!irt_ispri(ir->t)) {
+ Reg src = ra_alloc1(as, ref, allow);
+ emit_setgl(as, src, tmptv.gcr);
+ }
+ type = ra_allock(as, irt_toitype(ir->t), allow);
+ emit_setgl(as, type, tmptv.it);
+ }
+}
+
+static void asm_tostr(ASMState *as, IRIns *ir)
+{
+ IRRef args[2];
+ args[0] = ASMREF_L;
+ as->gcsteps++;
+ if (irt_isnum(IR(ir->op1)->t) || (ir+1)->o == IR_HIOP) {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromnum];
+ args[1] = ASMREF_TMP1; /* const lua_Number * */
+ asm_setupresult(as, ir, ci); /* GCstr * */
+ asm_gencall(as, ci, args);
+ asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op1);
+ } else {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromint];
+ args[1] = ir->op1; /* int32_t k */
+ asm_setupresult(as, ir, ci); /* GCstr * */
+ asm_gencall(as, ci, args);
+ }
+}
+
+/* -- Memory references --------------------------------------------------- */
+
+static void asm_aref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg idx, base;
+ if (irref_isk(ir->op2)) {
+ IRRef tab = IR(ir->op1)->op1;
+ int32_t ofs = asm_fuseabase(as, tab);
+ IRRef refa = ofs ? tab : ir->op1;
+ ofs += 8*IR(ir->op2)->i;
+ if (checki16(ofs)) {
+ base = ra_alloc1(as, refa, RSET_GPR);
+ emit_tai(as, PPCI_ADDI, dest, base, ofs);
+ return;
+ }
+ }
+ base = ra_alloc1(as, ir->op1, RSET_GPR);
+ idx = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, base));
+ emit_tab(as, PPCI_ADD, dest, RID_TMP, base);
+ emit_slwi(as, RID_TMP, idx, 3);
+}
+
+/* Inlined hash lookup. Specialized for key type and for const keys.
+** The equivalent C code is:
+** Node *n = hashkey(t, key);
+** do {
+** if (lj_obj_equal(&n->key, key)) return &n->val;
+** } while ((n = nextnode(n)));
+** return niltv(L);
+*/
+static void asm_href(ASMState *as, IRIns *ir, IROp merge)
+{
+ RegSet allow = RSET_GPR;
+ int destused = ra_used(ir);
+ Reg dest = ra_dest(as, ir, allow);
+ Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest));
+ Reg key = RID_NONE, tmp1 = RID_TMP, tmp2;
+ Reg tisnum = RID_NONE, tmpnum = RID_NONE;
+ IRRef refkey = ir->op2;
+ IRIns *irkey = IR(refkey);
+ IRType1 kt = irkey->t;
+ uint32_t khash;
+ MCLabel l_end, l_loop, l_next;
+
+ rset_clear(allow, tab);
+ if (irt_isnum(kt)) {
+ key = ra_alloc1(as, refkey, RSET_FPR);
+ tmpnum = ra_scratch(as, rset_exclude(RSET_FPR, key));
+ tisnum = ra_allock(as, (int32_t)LJ_TISNUM, allow);
+ rset_clear(allow, tisnum);
+ } else if (!irt_ispri(kt)) {
+ key = ra_alloc1(as, refkey, allow);
+ rset_clear(allow, key);
+ }
+ tmp2 = ra_scratch(as, allow);
+ rset_clear(allow, tmp2);
+
+ /* Key not found in chain: jump to exit (if merged) or load niltv. */
+ l_end = emit_label(as);
+ as->invmcp = NULL;
+ if (merge == IR_NE)
+ asm_guardcc(as, CC_EQ);
+ else if (destused)
+ emit_loada(as, dest, niltvg(J2G(as->J)));
+
+ /* Follow hash chain until the end. */
+ l_loop = --as->mcp;
+ emit_ai(as, PPCI_CMPWI, dest, 0);
+ emit_tai(as, PPCI_LWZ, dest, dest, (int32_t)offsetof(Node, next));
+ l_next = emit_label(as);
+
+ /* Type and value comparison. */
+ if (merge == IR_EQ)
+ asm_guardcc(as, CC_EQ);
+ else
+ emit_condbranch(as, PPCI_BC|PPCF_Y, CC_EQ, l_end);
+ if (irt_isnum(kt)) {
+ emit_fab(as, PPCI_FCMPU, 0, tmpnum, key);
+ emit_condbranch(as, PPCI_BC, CC_GE, l_next);
+ emit_ab(as, PPCI_CMPLW, tmp1, tisnum);
+ emit_fai(as, PPCI_LFD, tmpnum, dest, (int32_t)offsetof(Node, key.n));
+ } else {
+ if (!irt_ispri(kt)) {
+ emit_ab(as, PPCI_CMPW, tmp2, key);
+ emit_condbranch(as, PPCI_BC, CC_NE, l_next);
+ }
+ emit_ai(as, PPCI_CMPWI, tmp1, irt_toitype(irkey->t));
+ if (!irt_ispri(kt))
+ emit_tai(as, PPCI_LWZ, tmp2, dest, (int32_t)offsetof(Node, key.gcr));
+ }
+ emit_tai(as, PPCI_LWZ, tmp1, dest, (int32_t)offsetof(Node, key.it));
+ *l_loop = PPCI_BC | PPCF_Y | PPCF_CC(CC_NE) |
+ (((char *)as->mcp-(char *)l_loop) & 0xffffu);
+
+ /* Load main position relative to tab->node into dest. */
+ khash = irref_isk(refkey) ? ir_khash(irkey) : 1;
+ if (khash == 0) {
+ emit_tai(as, PPCI_LWZ, dest, tab, (int32_t)offsetof(GCtab, node));
+ } else {
+ Reg tmphash = tmp1;
+ if (irref_isk(refkey))
+ tmphash = ra_allock(as, khash, allow);
+ emit_tab(as, PPCI_ADD, dest, dest, tmp1);
+ emit_tai(as, PPCI_MULLI, tmp1, tmp1, sizeof(Node));
+ emit_asb(as, PPCI_AND, tmp1, tmp2, tmphash);
+ emit_tai(as, PPCI_LWZ, dest, tab, (int32_t)offsetof(GCtab, node));
+ emit_tai(as, PPCI_LWZ, tmp2, tab, (int32_t)offsetof(GCtab, hmask));
+ if (irref_isk(refkey)) {
+ /* Nothing to do. */
+ } else if (irt_isstr(kt)) {
+ emit_tai(as, PPCI_LWZ, tmp1, key, (int32_t)offsetof(GCstr, hash));
+ } else { /* Must match with hash*() in lj_tab.c. */
+ emit_tab(as, PPCI_SUBF, tmp1, tmp2, tmp1);
+ emit_rotlwi(as, tmp2, tmp2, HASH_ROT3);
+ emit_asb(as, PPCI_XOR, tmp1, tmp1, tmp2);
+ emit_rotlwi(as, tmp1, tmp1, (HASH_ROT2+HASH_ROT1)&31);
+ emit_tab(as, PPCI_SUBF, tmp2, dest, tmp2);
+ if (irt_isnum(kt)) {
+ int32_t ofs = ra_spill(as, irkey);
+ emit_asb(as, PPCI_XOR, tmp2, tmp2, tmp1);
+ emit_rotlwi(as, dest, tmp1, HASH_ROT1);
+ emit_tab(as, PPCI_ADD, tmp1, tmp1, tmp1);
+ emit_tai(as, PPCI_LWZ, tmp2, RID_SP, ofs+4);
+ emit_tai(as, PPCI_LWZ, tmp1, RID_SP, ofs);
+ } else {
+ emit_asb(as, PPCI_XOR, tmp2, key, tmp1);
+ emit_rotlwi(as, dest, tmp1, HASH_ROT1);
+ emit_tai(as, PPCI_ADDI, tmp1, tmp2, HASH_BIAS);
+ emit_tai(as, PPCI_ADDIS, tmp2, key, (HASH_BIAS + 32768)>>16);
+ }
+ }
+ }
+}
+
+static void asm_hrefk(ASMState *as, IRIns *ir)
+{
+ IRIns *kslot = IR(ir->op2);
+ IRIns *irkey = IR(kslot->op1);
+ int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node));
+ int32_t kofs = ofs + (int32_t)offsetof(Node, key);
+ Reg dest = (ra_used(ir)||ofs > 32736) ? ra_dest(as, ir, RSET_GPR) : RID_NONE;
+ Reg node = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg key = RID_NONE, type = RID_TMP, idx = node;
+ RegSet allow = rset_exclude(RSET_GPR, node);
+ lua_assert(ofs % sizeof(Node) == 0);
+ if (ofs > 32736) {
+ idx = dest;
+ rset_clear(allow, dest);
+ kofs = (int32_t)offsetof(Node, key);
+ } else if (ra_hasreg(dest)) {
+ emit_tai(as, PPCI_ADDI, dest, node, ofs);
+ }
+ asm_guardcc(as, CC_NE);
+ if (!irt_ispri(irkey->t)) {
+ key = ra_scratch(as, allow);
+ rset_clear(allow, key);
+ }
+ rset_clear(allow, type);
+ if (irt_isnum(irkey->t)) {
+ emit_cmpi(as, key, (int32_t)ir_knum(irkey)->u32.lo);
+ asm_guardcc(as, CC_NE);
+ emit_cmpi(as, type, (int32_t)ir_knum(irkey)->u32.hi);
+ } else {
+ if (ra_hasreg(key)) {
+ emit_cmpi(as, key, irkey->i); /* May use RID_TMP, i.e. type. */
+ asm_guardcc(as, CC_NE);
+ }
+ emit_ai(as, PPCI_CMPWI, type, irt_toitype(irkey->t));
+ }
+ if (ra_hasreg(key)) emit_tai(as, PPCI_LWZ, key, idx, kofs+4);
+ emit_tai(as, PPCI_LWZ, type, idx, kofs);
+ if (ofs > 32736) {
+ emit_tai(as, PPCI_ADDIS, dest, dest, (ofs + 32768) >> 16);
+ emit_tai(as, PPCI_ADDI, dest, node, ofs);
+ }
+}
+
+static void asm_newref(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_newkey];
+ IRRef args[3];
+ if (ir->r == RID_SINK)
+ return;
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ir->op1; /* GCtab *t */
+ args[2] = ASMREF_TMP1; /* cTValue *key */
+ asm_setupresult(as, ir, ci); /* TValue * */
+ asm_gencall(as, ci, args);
+ asm_tvptr(as, ra_releasetmp(as, ASMREF_TMP1), ir->op2);
+}
+
+static void asm_uref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (irref_isk(ir->op1)) {
+ GCfunc *fn = ir_kfunc(IR(ir->op1));
+ MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v;
+ emit_lsptr(as, PPCI_LWZ, dest, v, RSET_GPR);
+ } else {
+ Reg uv = ra_scratch(as, RSET_GPR);
+ Reg func = ra_alloc1(as, ir->op1, RSET_GPR);
+ if (ir->o == IR_UREFC) {
+ asm_guardcc(as, CC_NE);
+ emit_ai(as, PPCI_CMPWI, RID_TMP, 1);
+ emit_tai(as, PPCI_ADDI, dest, uv, (int32_t)offsetof(GCupval, tv));
+ emit_tai(as, PPCI_LBZ, RID_TMP, uv, (int32_t)offsetof(GCupval, closed));
+ } else {
+ emit_tai(as, PPCI_LWZ, dest, uv, (int32_t)offsetof(GCupval, v));
+ }
+ emit_tai(as, PPCI_LWZ, uv, func,
+ (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8));
+ }
+}
+
+static void asm_fref(ASMState *as, IRIns *ir)
+{
+ UNUSED(as); UNUSED(ir);
+ lua_assert(!ra_used(ir));
+}
+
+static void asm_strref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ IRRef ref = ir->op2, refk = ir->op1;
+ int32_t ofs = (int32_t)sizeof(GCstr);
+ Reg r;
+ if (irref_isk(ref)) {
+ IRRef tmp = refk; refk = ref; ref = tmp;
+ } else if (!irref_isk(refk)) {
+ Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);
+ IRIns *irr = IR(ir->op2);
+ if (ra_hasreg(irr->r)) {
+ ra_noweak(as, irr->r);
+ right = irr->r;
+ } else if (mayfuse(as, irr->op2) &&
+ irr->o == IR_ADD && irref_isk(irr->op2) &&
+ checki16(ofs + IR(irr->op2)->i)) {
+ ofs += IR(irr->op2)->i;
+ right = ra_alloc1(as, irr->op1, rset_exclude(RSET_GPR, left));
+ } else {
+ right = ra_allocref(as, ir->op2, rset_exclude(RSET_GPR, left));
+ }
+ emit_tai(as, PPCI_ADDI, dest, dest, ofs);
+ emit_tab(as, PPCI_ADD, dest, left, right);
+ return;
+ }
+ r = ra_alloc1(as, ref, RSET_GPR);
+ ofs += IR(refk)->i;
+ if (checki16(ofs))
+ emit_tai(as, PPCI_ADDI, dest, r, ofs);
+ else
+ emit_tab(as, PPCI_ADD, dest, r,
+ ra_allock(as, ofs, rset_exclude(RSET_GPR, r)));
+}
+
+/* -- Loads and stores ---------------------------------------------------- */
+
+static PPCIns asm_fxloadins(IRIns *ir)
+{
+ switch (irt_type(ir->t)) {
+ case IRT_I8: return PPCI_LBZ; /* Needs sign-extension. */
+ case IRT_U8: return PPCI_LBZ;
+ case IRT_I16: return PPCI_LHA;
+ case IRT_U16: return PPCI_LHZ;
+ case IRT_NUM: return PPCI_LFD;
+ case IRT_FLOAT: return PPCI_LFS;
+ default: return PPCI_LWZ;
+ }
+}
+
+static PPCIns asm_fxstoreins(IRIns *ir)
+{
+ switch (irt_type(ir->t)) {
+ case IRT_I8: case IRT_U8: return PPCI_STB;
+ case IRT_I16: case IRT_U16: return PPCI_STH;
+ case IRT_NUM: return PPCI_STFD;
+ case IRT_FLOAT: return PPCI_STFS;
+ default: return PPCI_STW;
+ }
+}
+
+static void asm_fload(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg idx = ra_alloc1(as, ir->op1, RSET_GPR);
+ PPCIns pi = asm_fxloadins(ir);
+ int32_t ofs;
+ if (ir->op2 == IRFL_TAB_ARRAY) {
+ ofs = asm_fuseabase(as, ir->op1);
+ if (ofs) { /* Turn the t->array load into an add for colocated arrays. */
+ emit_tai(as, PPCI_ADDI, dest, idx, ofs);
+ return;
+ }
+ }
+ ofs = field_ofs[ir->op2];
+ lua_assert(!irt_isi8(ir->t));
+ emit_tai(as, pi, dest, idx, ofs);
+}
+
+static void asm_fstore(ASMState *as, IRIns *ir)
+{
+ if (ir->r != RID_SINK) {
+ Reg src = ra_alloc1(as, ir->op2, RSET_GPR);
+ IRIns *irf = IR(ir->op1);
+ Reg idx = ra_alloc1(as, irf->op1, rset_exclude(RSET_GPR, src));
+ int32_t ofs = field_ofs[irf->op2];
+ PPCIns pi = asm_fxstoreins(ir);
+ emit_tai(as, pi, src, idx, ofs);
+ }
+}
+
+static void asm_xload(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);
+ lua_assert(!(ir->op2 & IRXLOAD_UNALIGNED));
+ if (irt_isi8(ir->t))
+ emit_as(as, PPCI_EXTSB, dest, dest);
+ asm_fusexref(as, asm_fxloadins(ir), dest, ir->op1, RSET_GPR, 0);
+}
+
+static void asm_xstore(ASMState *as, IRIns *ir, int32_t ofs)
+{
+ IRIns *irb;
+ if (ir->r == RID_SINK)
+ return;
+ if (ofs == 0 && mayfuse(as, ir->op2) && (irb = IR(ir->op2))->o == IR_BSWAP &&
+ ra_noreg(irb->r) && (irt_isint(ir->t) || irt_isu32(ir->t))) {
+ /* Fuse BSWAP with XSTORE to stwbrx. */
+ Reg src = ra_alloc1(as, irb->op1, RSET_GPR);
+ asm_fusexrefx(as, PPCI_STWBRX, src, ir->op1, rset_exclude(RSET_GPR, src));
+ } else {
+ Reg src = ra_alloc1(as, ir->op2, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);
+ asm_fusexref(as, asm_fxstoreins(ir), src, ir->op1,
+ rset_exclude(RSET_GPR, src), ofs);
+ }
+}
+
+static void asm_ahuvload(ASMState *as, IRIns *ir)
+{
+ IRType1 t = ir->t;
+ Reg dest = RID_NONE, type = RID_TMP, tmp = RID_TMP, idx;
+ RegSet allow = RSET_GPR;
+ int32_t ofs = AHUREF_LSX;
+ if (ra_used(ir)) {
+ lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t));
+ if (!irt_isnum(t)) ofs = 0;
+ dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : RSET_GPR);
+ rset_clear(allow, dest);
+ }
+ idx = asm_fuseahuref(as, ir->op1, &ofs, allow);
+ if (irt_isnum(t)) {
+ Reg tisnum = ra_allock(as, (int32_t)LJ_TISNUM, rset_exclude(allow, idx));
+ asm_guardcc(as, CC_GE);
+ emit_ab(as, PPCI_CMPLW, type, tisnum);
+ if (ra_hasreg(dest)) {
+ if (ofs == AHUREF_LSX) {
+ tmp = ra_scratch(as, rset_exclude(rset_exclude(RSET_GPR,
+ (idx&255)), (idx>>8)));
+ emit_fab(as, PPCI_LFDX, dest, (idx&255), tmp);
+ } else {
+ emit_fai(as, PPCI_LFD, dest, idx, ofs);
+ }
+ }
+ } else {
+ asm_guardcc(as, CC_NE);
+ emit_ai(as, PPCI_CMPWI, type, irt_toitype(t));
+ if (ra_hasreg(dest)) emit_tai(as, PPCI_LWZ, dest, idx, ofs+4);
+ }
+ if (ofs == AHUREF_LSX) {
+ emit_tab(as, PPCI_LWZX, type, (idx&255), tmp);
+ emit_slwi(as, tmp, (idx>>8), 3);
+ } else {
+ emit_tai(as, PPCI_LWZ, type, idx, ofs);
+ }
+}
+
+static void asm_ahustore(ASMState *as, IRIns *ir)
+{
+ RegSet allow = RSET_GPR;
+ Reg idx, src = RID_NONE, type = RID_NONE;
+ int32_t ofs = AHUREF_LSX;
+ if (ir->r == RID_SINK)
+ return;
+ if (irt_isnum(ir->t)) {
+ src = ra_alloc1(as, ir->op2, RSET_FPR);
+ } else {
+ if (!irt_ispri(ir->t)) {
+ src = ra_alloc1(as, ir->op2, allow);
+ rset_clear(allow, src);
+ ofs = 0;
+ }
+ type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);
+ rset_clear(allow, type);
+ }
+ idx = asm_fuseahuref(as, ir->op1, &ofs, allow);
+ if (irt_isnum(ir->t)) {
+ if (ofs == AHUREF_LSX) {
+ emit_fab(as, PPCI_STFDX, src, (idx&255), RID_TMP);
+ emit_slwi(as, RID_TMP, (idx>>8), 3);
+ } else {
+ emit_fai(as, PPCI_STFD, src, idx, ofs);
+ }
+ } else {
+ if (ra_hasreg(src))
+ emit_tai(as, PPCI_STW, src, idx, ofs+4);
+ if (ofs == AHUREF_LSX) {
+ emit_tab(as, PPCI_STWX, type, (idx&255), RID_TMP);
+ emit_slwi(as, RID_TMP, (idx>>8), 3);
+ } else {
+ emit_tai(as, PPCI_STW, type, idx, ofs);
+ }
+ }
+}
+
+static void asm_sload(ASMState *as, IRIns *ir)
+{
+ int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 0 : 4);
+ IRType1 t = ir->t;
+ Reg dest = RID_NONE, type = RID_NONE, base;
+ RegSet allow = RSET_GPR;
+ lua_assert(!(ir->op2 & IRSLOAD_PARENT)); /* Handled by asm_head_side(). */
+ lua_assert(irt_isguard(t) || !(ir->op2 & IRSLOAD_TYPECHECK));
+ lua_assert(LJ_DUALNUM ||
+ !irt_isint(t) || (ir->op2 & (IRSLOAD_CONVERT|IRSLOAD_FRAME)));
+ if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(t) && irt_isint(t)) {
+ dest = ra_scratch(as, RSET_FPR);
+ asm_tointg(as, ir, dest);
+ t.irt = IRT_NUM; /* Continue with a regular number type check. */
+ } else if (ra_used(ir)) {
+ lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t));
+ dest = ra_dest(as, ir, irt_isnum(t) ? RSET_FPR : RSET_GPR);
+ rset_clear(allow, dest);
+ base = ra_alloc1(as, REF_BASE, allow);
+ rset_clear(allow, base);
+ if ((ir->op2 & IRSLOAD_CONVERT)) {
+ if (irt_isint(t)) {
+ emit_tai(as, PPCI_LWZ, dest, RID_SP, SPOFS_TMPLO);
+ dest = ra_scratch(as, RSET_FPR);
+ emit_fai(as, PPCI_STFD, dest, RID_SP, SPOFS_TMP);
+ emit_fb(as, PPCI_FCTIWZ, dest, dest);
+ t.irt = IRT_NUM; /* Check for original type. */
+ } else {
+ Reg tmp = ra_scratch(as, allow);
+ Reg hibias = ra_allock(as, 0x43300000, rset_clear(allow, tmp));
+ Reg fbias = ra_scratch(as, rset_exclude(RSET_FPR, dest));
+ emit_fab(as, PPCI_FSUB, dest, dest, fbias);
+ emit_fai(as, PPCI_LFD, dest, RID_SP, SPOFS_TMP);
+ emit_lsptr(as, PPCI_LFS, (fbias & 31),
+ (void *)lj_ir_k64_find(as->J, U64x(59800004,59800000)),
+ rset_clear(allow, hibias));
+ emit_tai(as, PPCI_STW, tmp, RID_SP, SPOFS_TMPLO);
+ emit_tai(as, PPCI_STW, hibias, RID_SP, SPOFS_TMPHI);
+ emit_asi(as, PPCI_XORIS, tmp, tmp, 0x8000);
+ dest = tmp;
+ t.irt = IRT_INT; /* Check for original type. */
+ }
+ }
+ goto dotypecheck;
+ }
+ base = ra_alloc1(as, REF_BASE, allow);
+ rset_clear(allow, base);
+dotypecheck:
+ if (irt_isnum(t)) {
+ if ((ir->op2 & IRSLOAD_TYPECHECK)) {
+ Reg tisnum = ra_allock(as, (int32_t)LJ_TISNUM, allow);
+ asm_guardcc(as, CC_GE);
+ emit_ab(as, PPCI_CMPLW, RID_TMP, tisnum);
+ type = RID_TMP;
+ }
+ if (ra_hasreg(dest)) emit_fai(as, PPCI_LFD, dest, base, ofs-4);
+ } else {
+ if ((ir->op2 & IRSLOAD_TYPECHECK)) {
+ asm_guardcc(as, CC_NE);
+ emit_ai(as, PPCI_CMPWI, RID_TMP, irt_toitype(t));
+ type = RID_TMP;
+ }
+ if (ra_hasreg(dest)) emit_tai(as, PPCI_LWZ, dest, base, ofs);
+ }
+ if (ra_hasreg(type)) emit_tai(as, PPCI_LWZ, type, base, ofs-4);
+}
+
+/* -- Allocations --------------------------------------------------------- */
+
+#if LJ_HASFFI
+static void asm_cnew(ASMState *as, IRIns *ir)
+{
+ CTState *cts = ctype_ctsG(J2G(as->J));
+ CTypeID ctypeid = (CTypeID)IR(ir->op1)->i;
+ CTSize sz = (ir->o == IR_CNEWI || ir->op2 == REF_NIL) ?
+ lj_ctype_size(cts, ctypeid) : (CTSize)IR(ir->op2)->i;
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];
+ IRRef args[2];
+ RegSet allow = (RSET_GPR & ~RSET_SCRATCH);
+ RegSet drop = RSET_SCRATCH;
+ lua_assert(sz != CTSIZE_INVALID);
+
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ASMREF_TMP1; /* MSize size */
+ as->gcsteps++;
+
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ ra_evictset(as, drop);
+ if (ra_used(ir))
+ ra_destreg(as, ir, RID_RET); /* GCcdata * */
+
+ /* Initialize immutable cdata object. */
+ if (ir->o == IR_CNEWI) {
+ int32_t ofs = sizeof(GCcdata);
+ lua_assert(sz == 4 || sz == 8);
+ if (sz == 8) {
+ ofs += 4;
+ lua_assert((ir+1)->o == IR_HIOP);
+ }
+ for (;;) {
+ Reg r = ra_alloc1(as, ir->op2, allow);
+ emit_tai(as, PPCI_STW, r, RID_RET, ofs);
+ rset_clear(allow, r);
+ if (ofs == sizeof(GCcdata)) break;
+ ofs -= 4; ir++;
+ }
+ }
+ /* Initialize gct and ctypeid. lj_mem_newgco() already sets marked. */
+ emit_tai(as, PPCI_STB, RID_RET+1, RID_RET, offsetof(GCcdata, gct));
+ emit_tai(as, PPCI_STH, RID_TMP, RID_RET, offsetof(GCcdata, ctypeid));
+ emit_ti(as, PPCI_LI, RID_RET+1, ~LJ_TCDATA);
+ emit_ti(as, PPCI_LI, RID_TMP, ctypeid); /* Lower 16 bit used. Sign-ext ok. */
+ asm_gencall(as, ci, args);
+ ra_allockreg(as, (int32_t)(sz+sizeof(GCcdata)),
+ ra_releasetmp(as, ASMREF_TMP1));
+}
+#else
+#define asm_cnew(as, ir) ((void)0)
+#endif
+
+/* -- Write barriers ------------------------------------------------------ */
+
+static void asm_tbar(ASMState *as, IRIns *ir)
+{
+ Reg tab = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg mark = ra_scratch(as, rset_exclude(RSET_GPR, tab));
+ Reg link = RID_TMP;
+ MCLabel l_end = emit_label(as);
+ emit_tai(as, PPCI_STW, link, tab, (int32_t)offsetof(GCtab, gclist));
+ emit_tai(as, PPCI_STB, mark, tab, (int32_t)offsetof(GCtab, marked));
+ emit_setgl(as, tab, gc.grayagain);
+ lua_assert(LJ_GC_BLACK == 0x04);
+ emit_rot(as, PPCI_RLWINM, mark, mark, 0, 30, 28); /* Clear black bit. */
+ emit_getgl(as, link, gc.grayagain);
+ emit_condbranch(as, PPCI_BC|PPCF_Y, CC_EQ, l_end);
+ emit_asi(as, PPCI_ANDIDOT, RID_TMP, mark, LJ_GC_BLACK);
+ emit_tai(as, PPCI_LBZ, mark, tab, (int32_t)offsetof(GCtab, marked));
+}
+
+static void asm_obar(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv];
+ IRRef args[2];
+ MCLabel l_end;
+ Reg obj, val, tmp;
+ /* No need for other object barriers (yet). */
+ lua_assert(IR(ir->op1)->o == IR_UREFC);
+ ra_evictset(as, RSET_SCRATCH);
+ l_end = emit_label(as);
+ args[0] = ASMREF_TMP1; /* global_State *g */
+ args[1] = ir->op1; /* TValue *tv */
+ asm_gencall(as, ci, args);
+ emit_tai(as, PPCI_ADDI, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768);
+ obj = IR(ir->op1)->r;
+ tmp = ra_scratch(as, rset_exclude(RSET_GPR, obj));
+ emit_condbranch(as, PPCI_BC|PPCF_Y, CC_EQ, l_end);
+ emit_asi(as, PPCI_ANDIDOT, tmp, tmp, LJ_GC_BLACK);
+ emit_condbranch(as, PPCI_BC, CC_EQ, l_end);
+ emit_asi(as, PPCI_ANDIDOT, RID_TMP, RID_TMP, LJ_GC_WHITES);
+ val = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, obj));
+ emit_tai(as, PPCI_LBZ, tmp, obj,
+ (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv));
+ emit_tai(as, PPCI_LBZ, RID_TMP, val, (int32_t)offsetof(GChead, marked));
+}
+
+/* -- Arithmetic and logic operations ------------------------------------- */
+
+static void asm_fparith(ASMState *as, IRIns *ir, PPCIns pi)
+{
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg right, left = ra_alloc2(as, ir, RSET_FPR);
+ right = (left >> 8); left &= 255;
+ if (pi == PPCI_FMUL)
+ emit_fac(as, pi, dest, left, right);
+ else
+ emit_fab(as, pi, dest, left, right);
+}
+
+static void asm_fpunary(ASMState *as, IRIns *ir, PPCIns pi)
+{
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg left = ra_hintalloc(as, ir->op1, dest, RSET_FPR);
+ emit_fb(as, pi, dest, left);
+}
+
+static int asm_fpjoin_pow(ASMState *as, IRIns *ir)
+{
+ IRIns *irp = IR(ir->op1);
+ if (irp == ir-1 && irp->o == IR_MUL && !ra_used(irp)) {
+ IRIns *irpp = IR(irp->op1);
+ if (irpp == ir-2 && irpp->o == IR_FPMATH &&
+ irpp->op2 == IRFPM_LOG2 && !ra_used(irpp)) {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_pow];
+ IRRef args[2];
+ args[0] = irpp->op1;
+ args[1] = irp->op2;
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static void asm_add(ASMState *as, IRIns *ir)
+{
+ if (irt_isnum(ir->t)) {
+ if (!asm_fusemadd(as, ir, PPCI_FMADD, PPCI_FMADD))
+ asm_fparith(as, ir, PPCI_FADD);
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ PPCIns pi;
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (checki16(k)) {
+ pi = PPCI_ADDI;
+ /* May fail due to spills/restores above, but simplifies the logic. */
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ pi = PPCI_ADDICDOT;
+ }
+ emit_tai(as, pi, dest, left, k);
+ return;
+ } else if ((k & 0xffff) == 0) {
+ emit_tai(as, PPCI_ADDIS, dest, left, (k >> 16));
+ return;
+ } else if (!as->sectref) {
+ emit_tai(as, PPCI_ADDIS, dest, dest, (k + 32768) >> 16);
+ emit_tai(as, PPCI_ADDI, dest, left, k);
+ return;
+ }
+ }
+ pi = PPCI_ADD;
+ /* May fail due to spills/restores above, but simplifies the logic. */
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ pi |= PPCF_DOT;
+ }
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_tab(as, pi, dest, left, right);
+ }
+}
+
+static void asm_sub(ASMState *as, IRIns *ir)
+{
+ if (irt_isnum(ir->t)) {
+ if (!asm_fusemadd(as, ir, PPCI_FMSUB, PPCI_FNMSUB))
+ asm_fparith(as, ir, PPCI_FSUB);
+ } else {
+ PPCIns pi = PPCI_SUBF;
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left, right;
+ if (irref_isk(ir->op1)) {
+ int32_t k = IR(ir->op1)->i;
+ if (checki16(k)) {
+ right = ra_alloc1(as, ir->op2, RSET_GPR);
+ emit_tai(as, PPCI_SUBFIC, dest, right, k);
+ return;
+ }
+ }
+ /* May fail due to spills/restores above, but simplifies the logic. */
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ pi |= PPCF_DOT;
+ }
+ left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_tab(as, pi, dest, right, left); /* Subtract right _from_ left. */
+ }
+}
+
+static void asm_mul(ASMState *as, IRIns *ir)
+{
+ if (irt_isnum(ir->t)) {
+ asm_fparith(as, ir, PPCI_FMUL);
+ } else {
+ PPCIns pi = PPCI_MULLW;
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (checki16(k)) {
+ emit_tai(as, PPCI_MULLI, dest, left, k);
+ return;
+ }
+ }
+ /* May fail due to spills/restores above, but simplifies the logic. */
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ pi |= PPCF_DOT;
+ }
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_tab(as, pi, dest, left, right);
+ }
+}
+
+static void asm_neg(ASMState *as, IRIns *ir)
+{
+ if (irt_isnum(ir->t)) {
+ asm_fpunary(as, ir, PPCI_FNEG);
+ } else {
+ Reg dest, left;
+ PPCIns pi = PPCI_NEG;
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ pi |= PPCF_DOT;
+ }
+ dest = ra_dest(as, ir, RSET_GPR);
+ left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ emit_tab(as, pi, dest, left, 0);
+ }
+}
+
+static void asm_arithov(ASMState *as, IRIns *ir, PPCIns pi)
+{
+ Reg dest, left, right;
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ }
+ asm_guardcc(as, CC_SO);
+ dest = ra_dest(as, ir, RSET_GPR);
+ left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ if (pi == PPCI_SUBFO) { Reg tmp = left; left = right; right = tmp; }
+ emit_tab(as, pi|PPCF_DOT, dest, left, right);
+}
+
+#if LJ_HASFFI
+static void asm_add64(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_alloc1(as, ir->op1, RSET_GPR);
+ PPCIns pi = PPCI_ADDE;
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (k == 0)
+ pi = PPCI_ADDZE;
+ else if (k == -1)
+ pi = PPCI_ADDME;
+ else
+ goto needright;
+ right = 0;
+ } else {
+ needright:
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ }
+ emit_tab(as, pi, dest, left, right);
+ ir--;
+ dest = ra_dest(as, ir, RSET_GPR);
+ left = ra_alloc1(as, ir->op1, RSET_GPR);
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (checki16(k)) {
+ emit_tai(as, PPCI_ADDIC, dest, left, k);
+ return;
+ }
+ }
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_tab(as, PPCI_ADDC, dest, left, right);
+}
+
+static void asm_sub64(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left, right = ra_alloc1(as, ir->op2, RSET_GPR);
+ PPCIns pi = PPCI_SUBFE;
+ if (irref_isk(ir->op1)) {
+ int32_t k = IR(ir->op1)->i;
+ if (k == 0)
+ pi = PPCI_SUBFZE;
+ else if (k == -1)
+ pi = PPCI_SUBFME;
+ else
+ goto needleft;
+ left = 0;
+ } else {
+ needleft:
+ left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, right));
+ }
+ emit_tab(as, pi, dest, right, left); /* Subtract right _from_ left. */
+ ir--;
+ dest = ra_dest(as, ir, RSET_GPR);
+ right = ra_alloc1(as, ir->op2, RSET_GPR);
+ if (irref_isk(ir->op1)) {
+ int32_t k = IR(ir->op1)->i;
+ if (checki16(k)) {
+ emit_tai(as, PPCI_SUBFIC, dest, right, k);
+ return;
+ }
+ }
+ left = ra_alloc1(as, ir->op1, rset_exclude(RSET_GPR, right));
+ emit_tab(as, PPCI_SUBFC, dest, right, left);
+}
+
+static void asm_neg64(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
+ emit_tab(as, PPCI_SUBFZE, dest, left, 0);
+ ir--;
+ dest = ra_dest(as, ir, RSET_GPR);
+ left = ra_alloc1(as, ir->op1, RSET_GPR);
+ emit_tai(as, PPCI_SUBFIC, dest, left, 0);
+}
+#endif
+
+static void asm_bitnot(ASMState *as, IRIns *ir)
+{
+ Reg dest, left, right;
+ PPCIns pi = PPCI_NOR;
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ pi |= PPCF_DOT;
+ }
+ dest = ra_dest(as, ir, RSET_GPR);
+ if (mayfuse(as, ir->op1)) {
+ IRIns *irl = IR(ir->op1);
+ if (irl->o == IR_BAND)
+ pi ^= (PPCI_NOR ^ PPCI_NAND);
+ else if (irl->o == IR_BXOR)
+ pi ^= (PPCI_NOR ^ PPCI_EQV);
+ else if (irl->o != IR_BOR)
+ goto nofuse;
+ left = ra_hintalloc(as, irl->op1, dest, RSET_GPR);
+ right = ra_alloc1(as, irl->op2, rset_exclude(RSET_GPR, left));
+ } else {
+nofuse:
+ left = right = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ }
+ emit_asb(as, pi, dest, left, right);
+}
+
+static void asm_bitswap(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ IRIns *irx;
+ if (mayfuse(as, ir->op1) && (irx = IR(ir->op1))->o == IR_XLOAD &&
+ ra_noreg(irx->r) && (irt_isint(irx->t) || irt_isu32(irx->t))) {
+ /* Fuse BSWAP with XLOAD to lwbrx. */
+ asm_fusexrefx(as, PPCI_LWBRX, dest, irx->op1, RSET_GPR);
+ } else {
+ Reg left = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg tmp = dest;
+ if (tmp == left) {
+ tmp = RID_TMP;
+ emit_mr(as, dest, RID_TMP);
+ }
+ emit_rot(as, PPCI_RLWIMI, tmp, left, 24, 16, 23);
+ emit_rot(as, PPCI_RLWIMI, tmp, left, 24, 0, 7);
+ emit_rotlwi(as, tmp, left, 8);
+ }
+}
+
+static void asm_bitop(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pik)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg right, left = ra_hintalloc(as, ir->op1, dest, RSET_GPR);
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ Reg tmp = left;
+ if ((checku16(k) || (k & 0xffff) == 0) || (tmp = dest, !as->sectref)) {
+ if (!checku16(k)) {
+ emit_asi(as, pik ^ (PPCI_ORI ^ PPCI_ORIS), dest, tmp, (k >> 16));
+ if ((k & 0xffff) == 0) return;
+ }
+ emit_asi(as, pik, dest, left, k);
+ return;
+ }
+ }
+ /* May fail due to spills/restores above, but simplifies the logic. */
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ pi |= PPCF_DOT;
+ }
+ right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_asb(as, pi, dest, left, right);
+}
+
+/* Fuse BAND with contiguous bitmask and a shift to rlwinm. */
+static void asm_fuseandsh(ASMState *as, PPCIns pi, int32_t mask, IRRef ref)
+{
+ IRIns *ir;
+ Reg left;
+ if (mayfuse(as, ref) && (ir = IR(ref), ra_noreg(ir->r)) &&
+ irref_isk(ir->op2) && ir->o >= IR_BSHL && ir->o <= IR_BROR) {
+ int32_t sh = (IR(ir->op2)->i & 31);
+ switch (ir->o) {
+ case IR_BSHL:
+ if ((mask & ((1u<<sh)-1))) goto nofuse;
+ break;
+ case IR_BSHR:
+ if ((mask & ~((~0u)>>sh))) goto nofuse;
+ sh = ((32-sh)&31);
+ break;
+ case IR_BROL:
+ break;
+ default:
+ goto nofuse;
+ }
+ left = ra_alloc1(as, ir->op1, RSET_GPR);
+ *--as->mcp = pi | PPCF_T(left) | PPCF_B(sh);
+ return;
+ }
+nofuse:
+ left = ra_alloc1(as, ref, RSET_GPR);
+ *--as->mcp = pi | PPCF_T(left);
+}
+
+static void asm_bitand(ASMState *as, IRIns *ir)
+{
+ Reg dest, left, right;
+ IRRef lref = ir->op1;
+ PPCIns dot = 0;
+ IRRef op2;
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ dot = PPCF_DOT;
+ }
+ dest = ra_dest(as, ir, RSET_GPR);
+ if (irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (k) {
+ /* First check for a contiguous bitmask as used by rlwinm. */
+ uint32_t s1 = lj_ffs((uint32_t)k);
+ uint32_t k1 = ((uint32_t)k >> s1);
+ if ((k1 & (k1+1)) == 0) {
+ asm_fuseandsh(as, PPCI_RLWINM|dot | PPCF_A(dest) |
+ PPCF_MB(31-lj_fls((uint32_t)k)) | PPCF_ME(31-s1),
+ k, lref);
+ return;
+ }
+ if (~(uint32_t)k) {
+ uint32_t s2 = lj_ffs(~(uint32_t)k);
+ uint32_t k2 = (~(uint32_t)k >> s2);
+ if ((k2 & (k2+1)) == 0) {
+ asm_fuseandsh(as, PPCI_RLWINM|dot | PPCF_A(dest) |
+ PPCF_MB(32-s2) | PPCF_ME(30-lj_fls(~(uint32_t)k)),
+ k, lref);
+ return;
+ }
+ }
+ }
+ if (checku16(k)) {
+ left = ra_alloc1(as, lref, RSET_GPR);
+ emit_asi(as, PPCI_ANDIDOT, dest, left, k);
+ return;
+ } else if ((k & 0xffff) == 0) {
+ left = ra_alloc1(as, lref, RSET_GPR);
+ emit_asi(as, PPCI_ANDISDOT, dest, left, (k >> 16));
+ return;
+ }
+ }
+ op2 = ir->op2;
+ if (mayfuse(as, op2) && IR(op2)->o == IR_BNOT && ra_noreg(IR(op2)->r)) {
+ dot ^= (PPCI_AND ^ PPCI_ANDC);
+ op2 = IR(op2)->op1;
+ }
+ left = ra_hintalloc(as, lref, dest, RSET_GPR);
+ right = ra_alloc1(as, op2, rset_exclude(RSET_GPR, left));
+ emit_asb(as, PPCI_AND ^ dot, dest, left, right);
+}
+
+static void asm_bitshift(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pik)
+{
+ Reg dest, left;
+ Reg dot = 0;
+ if (as->flagmcp == as->mcp) {
+ as->flagmcp = NULL;
+ as->mcp++;
+ dot = PPCF_DOT;
+ }
+ dest = ra_dest(as, ir, RSET_GPR);
+ left = ra_alloc1(as, ir->op1, RSET_GPR);
+ if (irref_isk(ir->op2)) { /* Constant shifts. */
+ int32_t shift = (IR(ir->op2)->i & 31);
+ if (pik == 0) /* SLWI */
+ emit_rot(as, PPCI_RLWINM|dot, dest, left, shift, 0, 31-shift);
+ else if (pik == 1) /* SRWI */
+ emit_rot(as, PPCI_RLWINM|dot, dest, left, (32-shift)&31, shift, 31);
+ else
+ emit_asb(as, pik|dot, dest, left, shift);
+ } else {
+ Reg right = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, left));
+ emit_asb(as, pi|dot, dest, left, right);
+ }
+}
+
+static void asm_min_max(ASMState *as, IRIns *ir, int ismax)
+{
+ if (irt_isnum(ir->t)) {
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg tmp = dest;
+ Reg right, left = ra_alloc2(as, ir, RSET_FPR);
+ right = (left >> 8); left &= 255;
+ if (tmp == left || tmp == right)
+ tmp = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_FPR,
+ dest), left), right));
+ emit_facb(as, PPCI_FSEL, dest, tmp,
+ ismax ? left : right, ismax ? right : left);
+ emit_fab(as, PPCI_FSUB, tmp, left, right);
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg tmp1 = RID_TMP, tmp2 = dest;
+ Reg right, left = ra_alloc2(as, ir, RSET_GPR);
+ right = (left >> 8); left &= 255;
+ if (tmp2 == left || tmp2 == right)
+ tmp2 = ra_scratch(as, rset_exclude(rset_exclude(rset_exclude(RSET_GPR,
+ dest), left), right));
+ emit_tab(as, PPCI_ADD, dest, tmp2, right);
+ emit_asb(as, ismax ? PPCI_ANDC : PPCI_AND, tmp2, tmp2, tmp1);
+ emit_tab(as, PPCI_SUBFE, tmp1, tmp1, tmp1);
+ emit_tab(as, PPCI_SUBFC, tmp2, tmp2, tmp1);
+ emit_asi(as, PPCI_XORIS, tmp2, right, 0x8000);
+ emit_asi(as, PPCI_XORIS, tmp1, left, 0x8000);
+ }
+}
+
+/* -- Comparisons --------------------------------------------------------- */
+
+#define CC_UNSIGNED 0x08 /* Unsigned integer comparison. */
+#define CC_TWO 0x80 /* Check two flags for FP comparison. */
+
+/* Map of comparisons to flags. ORDER IR. */
+static const uint8_t asm_compmap[IR_ABC+1] = {
+ /* op int cc FP cc */
+ /* LT */ CC_GE + (CC_GE<<4),
+ /* GE */ CC_LT + (CC_LE<<4) + CC_TWO,
+ /* LE */ CC_GT + (CC_GE<<4) + CC_TWO,
+ /* GT */ CC_LE + (CC_LE<<4),
+ /* ULT */ CC_GE + CC_UNSIGNED + (CC_GT<<4) + CC_TWO,
+ /* UGE */ CC_LT + CC_UNSIGNED + (CC_LT<<4),
+ /* ULE */ CC_GT + CC_UNSIGNED + (CC_GT<<4),
+ /* UGT */ CC_LE + CC_UNSIGNED + (CC_LT<<4) + CC_TWO,
+ /* EQ */ CC_NE + (CC_NE<<4),
+ /* NE */ CC_EQ + (CC_EQ<<4),
+ /* ABC */ CC_LE + CC_UNSIGNED + (CC_LT<<4) + CC_TWO /* Same as UGT. */
+};
+
+static void asm_intcomp_(ASMState *as, IRRef lref, IRRef rref, Reg cr, PPCCC cc)
+{
+ Reg right, left = ra_alloc1(as, lref, RSET_GPR);
+ if (irref_isk(rref)) {
+ int32_t k = IR(rref)->i;
+ if ((cc & CC_UNSIGNED) == 0) { /* Signed comparison with constant. */
+ if (checki16(k)) {
+ emit_tai(as, PPCI_CMPWI, cr, left, k);
+ /* Signed comparison with zero and referencing previous ins? */
+ if (k == 0 && lref == as->curins-1)
+ as->flagmcp = as->mcp; /* Allow elimination of the compare. */
+ return;
+ } else if ((cc & 3) == (CC_EQ & 3)) { /* Use CMPLWI for EQ or NE. */
+ if (checku16(k)) {
+ emit_tai(as, PPCI_CMPLWI, cr, left, k);
+ return;
+ } else if (!as->sectref && ra_noreg(IR(rref)->r)) {
+ emit_tai(as, PPCI_CMPLWI, cr, RID_TMP, k);
+ emit_asi(as, PPCI_XORIS, RID_TMP, left, (k >> 16));
+ return;
+ }
+ }
+ } else { /* Unsigned comparison with constant. */
+ if (checku16(k)) {
+ emit_tai(as, PPCI_CMPLWI, cr, left, k);
+ return;
+ }
+ }
+ }
+ right = ra_alloc1(as, rref, rset_exclude(RSET_GPR, left));
+ emit_tab(as, (cc & CC_UNSIGNED) ? PPCI_CMPLW : PPCI_CMPW, cr, left, right);
+}
+
+static void asm_comp(ASMState *as, IRIns *ir)
+{
+ PPCCC cc = asm_compmap[ir->o];
+ if (irt_isnum(ir->t)) {
+ Reg right, left = ra_alloc2(as, ir, RSET_FPR);
+ right = (left >> 8); left &= 255;
+ asm_guardcc(as, (cc >> 4));
+ if ((cc & CC_TWO))
+ emit_tab(as, PPCI_CROR, ((cc>>4)&3), ((cc>>4)&3), (CC_EQ&3));
+ emit_fab(as, PPCI_FCMPU, 0, left, right);
+ } else {
+ IRRef lref = ir->op1, rref = ir->op2;
+ if (irref_isk(lref) && !irref_isk(rref)) {
+ /* Swap constants to the right (only for ABC). */
+ IRRef tmp = lref; lref = rref; rref = tmp;
+ if ((cc & 2) == 0) cc ^= 1; /* LT <-> GT, LE <-> GE */
+ }
+ asm_guardcc(as, cc);
+ asm_intcomp_(as, lref, rref, 0, cc);
+ }
+}
+
+#if LJ_HASFFI
+/* 64 bit integer comparisons. */
+static void asm_comp64(ASMState *as, IRIns *ir)
+{
+ PPCCC cc = asm_compmap[(ir-1)->o];
+ if ((cc&3) == (CC_EQ&3)) {
+ asm_guardcc(as, cc);
+ emit_tab(as, (cc&4) ? PPCI_CRAND : PPCI_CROR,
+ (CC_EQ&3), (CC_EQ&3), 4+(CC_EQ&3));
+ } else {
+ asm_guardcc(as, CC_EQ);
+ emit_tab(as, PPCI_CROR, (CC_EQ&3), (CC_EQ&3), ((cc^~(cc>>2))&1));
+ emit_tab(as, (cc&4) ? PPCI_CRAND : PPCI_CRANDC,
+ (CC_EQ&3), (CC_EQ&3), 4+(cc&3));
+ }
+ /* Loword comparison sets cr1 and is unsigned, except for equality. */
+ asm_intcomp_(as, (ir-1)->op1, (ir-1)->op2, 4,
+ cc | ((cc&3) == (CC_EQ&3) ? 0 : CC_UNSIGNED));
+ /* Hiword comparison sets cr0. */
+ asm_intcomp_(as, ir->op1, ir->op2, 0, cc);
+ as->flagmcp = NULL; /* Doesn't work here. */
+}
+#endif
+
+/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */
+
+/* Hiword op of a split 64 bit op. Previous op must be the loword op. */
+static void asm_hiop(ASMState *as, IRIns *ir)
+{
+#if LJ_HASFFI
+ /* HIOP is marked as a store because it needs its own DCE logic. */
+ int uselo = ra_used(ir-1), usehi = ra_used(ir); /* Loword/hiword used? */
+ if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1;
+ if ((ir-1)->o == IR_CONV) { /* Conversions to/from 64 bit. */
+ as->curins--; /* Always skip the CONV. */
+ if (usehi || uselo)
+ asm_conv64(as, ir);
+ return;
+ } else if ((ir-1)->o <= IR_NE) { /* 64 bit integer comparisons. ORDER IR. */
+ as->curins--; /* Always skip the loword comparison. */
+ asm_comp64(as, ir);
+ return;
+ } else if ((ir-1)->o == IR_XSTORE) {
+ as->curins--; /* Handle both stores here. */
+ if ((ir-1)->r != RID_SINK) {
+ asm_xstore(as, ir, 0);
+ asm_xstore(as, ir-1, 4);
+ }
+ return;
+ }
+ if (!usehi) return; /* Skip unused hiword op for all remaining ops. */
+ switch ((ir-1)->o) {
+ case IR_ADD: as->curins--; asm_add64(as, ir); break;
+ case IR_SUB: as->curins--; asm_sub64(as, ir); break;
+ case IR_NEG: as->curins--; asm_neg64(as, ir); break;
+ case IR_CALLN:
+ case IR_CALLXS:
+ if (!uselo)
+ ra_allocref(as, ir->op1, RID2RSET(RID_RETLO)); /* Mark lo op as used. */
+ break;
+ case IR_CNEWI:
+ /* Nothing to do here. Handled by lo op itself. */
+ break;
+ default: lua_assert(0); break;
+ }
+#else
+ UNUSED(as); UNUSED(ir); lua_assert(0); /* Unused without FFI. */
+#endif
+}
+
+/* -- Stack handling ------------------------------------------------------ */
+
+/* Check Lua stack size for overflow. Use exit handler as fallback. */
+static void asm_stack_check(ASMState *as, BCReg topslot,
+ IRIns *irp, RegSet allow, ExitNo exitno)
+{
+ /* Try to get an unused temp. register, otherwise spill/restore RID_RET*. */
+ Reg tmp, pbase = irp ? (ra_hasreg(irp->r) ? irp->r : RID_TMP) : RID_BASE;
+ rset_clear(allow, pbase);
+ tmp = allow ? rset_pickbot(allow) :
+ (pbase == RID_RETHI ? RID_RETLO : RID_RETHI);
+ emit_condbranch(as, PPCI_BC, CC_LT, asm_exitstub_addr(as, exitno));
+ if (allow == RSET_EMPTY) /* Restore temp. register. */
+ emit_tai(as, PPCI_LWZ, tmp, RID_SP, SPOFS_TMPW);
+ else
+ ra_modified(as, tmp);
+ emit_ai(as, PPCI_CMPLWI, RID_TMP, (int32_t)(8*topslot));
+ emit_tab(as, PPCI_SUBF, RID_TMP, pbase, tmp);
+ emit_tai(as, PPCI_LWZ, tmp, tmp, offsetof(lua_State, maxstack));
+ if (pbase == RID_TMP)
+ emit_getgl(as, RID_TMP, jit_base);
+ emit_getgl(as, tmp, jit_L);
+ if (allow == RSET_EMPTY) /* Spill temp. register. */
+ emit_tai(as, PPCI_STW, tmp, RID_SP, SPOFS_TMPW);
+}
+
+/* Restore Lua stack from on-trace state. */
+static void asm_stack_restore(ASMState *as, SnapShot *snap)
+{
+ SnapEntry *map = &as->T->snapmap[snap->mapofs];
+ SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1];
+ MSize n, nent = snap->nent;
+ /* Store the value of all modified slots to the Lua stack. */
+ for (n = 0; n < nent; n++) {
+ SnapEntry sn = map[n];
+ BCReg s = snap_slot(sn);
+ int32_t ofs = 8*((int32_t)s-1);
+ IRRef ref = snap_ref(sn);
+ IRIns *ir = IR(ref);
+ if ((sn & SNAP_NORESTORE))
+ continue;
+ if (irt_isnum(ir->t)) {
+ Reg src = ra_alloc1(as, ref, RSET_FPR);
+ emit_fai(as, PPCI_STFD, src, RID_BASE, ofs);
+ } else {
+ Reg type;
+ RegSet allow = rset_exclude(RSET_GPR, RID_BASE);
+ lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) || irt_isinteger(ir->t));
+ if (!irt_ispri(ir->t)) {
+ Reg src = ra_alloc1(as, ref, allow);
+ rset_clear(allow, src);
+ emit_tai(as, PPCI_STW, src, RID_BASE, ofs+4);
+ }
+ if ((sn & (SNAP_CONT|SNAP_FRAME))) {
+ if (s == 0) continue; /* Do not overwrite link to previous frame. */
+ type = ra_allock(as, (int32_t)(*flinks--), allow);
+ } else {
+ type = ra_allock(as, (int32_t)irt_toitype(ir->t), allow);
+ }
+ emit_tai(as, PPCI_STW, type, RID_BASE, ofs);
+ }
+ checkmclim(as);
+ }
+ lua_assert(map + nent == flinks);
+}
+
+/* -- GC handling --------------------------------------------------------- */
+
+/* Check GC threshold and do one or more GC steps. */
+static void asm_gc_check(ASMState *as)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit];
+ IRRef args[2];
+ MCLabel l_end;
+ Reg tmp;
+ ra_evictset(as, RSET_SCRATCH);
+ l_end = emit_label(as);
+ /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */
+ asm_guardcc(as, CC_NE); /* Assumes asm_snap_prep() already done. */
+ emit_ai(as, PPCI_CMPWI, RID_RET, 0);
+ args[0] = ASMREF_TMP1; /* global_State *g */
+ args[1] = ASMREF_TMP2; /* MSize steps */
+ asm_gencall(as, ci, args);
+ emit_tai(as, PPCI_ADDI, ra_releasetmp(as, ASMREF_TMP1), RID_JGL, -32768);
+ tmp = ra_releasetmp(as, ASMREF_TMP2);
+ emit_loadi(as, tmp, as->gcsteps);
+ /* Jump around GC step if GC total < GC threshold. */
+ emit_condbranch(as, PPCI_BC|PPCF_Y, CC_LT, l_end);
+ emit_ab(as, PPCI_CMPLW, RID_TMP, tmp);
+ emit_getgl(as, tmp, gc.threshold);
+ emit_getgl(as, RID_TMP, gc.total);
+ as->gcsteps = 0;
+ checkmclim(as);
+}
+
+/* -- Loop handling ------------------------------------------------------- */
+
+/* Fixup the loop branch. */
+static void asm_loop_fixup(ASMState *as)
+{
+ MCode *p = as->mctop;
+ MCode *target = as->mcp;
+ if (as->loopinv) { /* Inverted loop branch? */
+ /* asm_guardcc already inverted the cond branch and patched the final b. */
+ p[-2] = (p[-2] & (0xffff0000u & ~PPCF_Y)) | (((target-p+2) & 0x3fffu) << 2);
+ } else {
+ p[-1] = PPCI_B|(((target-p+1)&0x00ffffffu)<<2);
+ }
+}
+
+/* -- Head of trace ------------------------------------------------------- */
+
+/* Coalesce BASE register for a root trace. */
+static void asm_head_root_base(ASMState *as)
+{
+ IRIns *ir = IR(REF_BASE);
+ Reg r = ir->r;
+ if (ra_hasreg(r)) {
+ ra_free(as, r);
+ if (rset_test(as->modset, r) || irt_ismarked(ir->t))
+ ir->r = RID_INIT; /* No inheritance for modified BASE register. */
+ if (r != RID_BASE)
+ emit_mr(as, r, RID_BASE);
+ }
+}
+
+/* Coalesce BASE register for a side trace. */
+static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow)
+{
+ IRIns *ir = IR(REF_BASE);
+ Reg r = ir->r;
+ if (ra_hasreg(r)) {
+ ra_free(as, r);
+ if (rset_test(as->modset, r) || irt_ismarked(ir->t))
+ ir->r = RID_INIT; /* No inheritance for modified BASE register. */
+ if (irp->r == r) {
+ rset_clear(allow, r); /* Mark same BASE register as coalesced. */
+ } else if (ra_hasreg(irp->r) && rset_test(as->freeset, irp->r)) {
+ rset_clear(allow, irp->r);
+ emit_mr(as, r, irp->r); /* Move from coalesced parent reg. */
+ } else {
+ emit_getgl(as, r, jit_base); /* Otherwise reload BASE. */
+ }
+ }
+ return allow;
+}
+
+/* -- Tail of trace ------------------------------------------------------- */
+
+/* Fixup the tail code. */
+static void asm_tail_fixup(ASMState *as, TraceNo lnk)
+{
+ MCode *p = as->mctop;
+ MCode *target;
+ int32_t spadj = as->T->spadjust;
+ if (spadj == 0) {
+ *--p = PPCI_NOP;
+ *--p = PPCI_NOP;
+ as->mctop = p;
+ } else {
+ /* Patch stack adjustment. */
+ lua_assert(checki16(CFRAME_SIZE+spadj));
+ p[-3] = PPCI_ADDI | PPCF_T(RID_TMP) | PPCF_A(RID_SP) | (CFRAME_SIZE+spadj);
+ p[-2] = PPCI_STWU | PPCF_T(RID_TMP) | PPCF_A(RID_SP) | spadj;
+ }
+ /* Patch exit branch. */
+ target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp;
+ p[-1] = PPCI_B|(((target-p+1)&0x00ffffffu)<<2);
+}
+
+/* Prepare tail of code. */
+static void asm_tail_prep(ASMState *as)
+{
+ MCode *p = as->mctop - 1; /* Leave room for exit branch. */
+ if (as->loopref) {
+ as->invmcp = as->mcp = p;
+ } else {
+ as->mcp = p-2; /* Leave room for stack pointer adjustment. */
+ as->invmcp = NULL;
+ }
+}
+
+/* -- Instruction dispatch ------------------------------------------------ */
+
+/* Assemble a single instruction. */
+static void asm_ir(ASMState *as, IRIns *ir)
+{
+ switch ((IROp)ir->o) {
+ /* Miscellaneous ops. */
+ case IR_LOOP: asm_loop(as); break;
+ case IR_NOP: case IR_XBAR: lua_assert(!ra_used(ir)); break;
+ case IR_USE:
+ ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break;
+ case IR_PHI: asm_phi(as, ir); break;
+ case IR_HIOP: asm_hiop(as, ir); break;
+ case IR_GCSTEP: asm_gcstep(as, ir); break;
+
+ /* Guarded assertions. */
+ case IR_EQ: case IR_NE:
+ if ((ir-1)->o == IR_HREF && ir->op1 == as->curins-1) {
+ as->curins--;
+ asm_href(as, ir-1, (IROp)ir->o);
+ break;
+ }
+ /* fallthrough */
+ case IR_LT: case IR_GE: case IR_LE: case IR_GT:
+ case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT:
+ case IR_ABC:
+ asm_comp(as, ir);
+ break;
+
+ case IR_RETF: asm_retf(as, ir); break;
+
+ /* Bit ops. */
+ case IR_BNOT: asm_bitnot(as, ir); break;
+ case IR_BSWAP: asm_bitswap(as, ir); break;
+
+ case IR_BAND: asm_bitand(as, ir); break;
+ case IR_BOR: asm_bitop(as, ir, PPCI_OR, PPCI_ORI); break;
+ case IR_BXOR: asm_bitop(as, ir, PPCI_XOR, PPCI_XORI); break;
+
+ case IR_BSHL: asm_bitshift(as, ir, PPCI_SLW, 0); break;
+ case IR_BSHR: asm_bitshift(as, ir, PPCI_SRW, 1); break;
+ case IR_BSAR: asm_bitshift(as, ir, PPCI_SRAW, PPCI_SRAWI); break;
+ case IR_BROL: asm_bitshift(as, ir, PPCI_RLWNM|PPCF_MB(0)|PPCF_ME(31),
+ PPCI_RLWINM|PPCF_MB(0)|PPCF_ME(31)); break;
+ case IR_BROR: lua_assert(0); break;
+
+ /* Arithmetic ops. */
+ case IR_ADD: asm_add(as, ir); break;
+ case IR_SUB: asm_sub(as, ir); break;
+ case IR_MUL: asm_mul(as, ir); break;
+ case IR_DIV: asm_fparith(as, ir, PPCI_FDIV); break;
+ case IR_MOD: asm_callid(as, ir, IRCALL_lj_vm_modi); break;
+ case IR_POW: asm_callid(as, ir, IRCALL_lj_vm_powi); break;
+ case IR_NEG: asm_neg(as, ir); break;
+
+ case IR_ABS: asm_fpunary(as, ir, PPCI_FABS); break;
+ case IR_ATAN2: asm_callid(as, ir, IRCALL_atan2); break;
+ case IR_LDEXP: asm_callid(as, ir, IRCALL_ldexp); break;
+ case IR_MIN: asm_min_max(as, ir, 0); break;
+ case IR_MAX: asm_min_max(as, ir, 1); break;
+ case IR_FPMATH:
+ if (ir->op2 == IRFPM_EXP2 && asm_fpjoin_pow(as, ir))
+ break;
+ if (ir->op2 == IRFPM_SQRT && (as->flags & JIT_F_SQRT))
+ asm_fpunary(as, ir, PPCI_FSQRT);
+ else
+ asm_callid(as, ir, IRCALL_lj_vm_floor + ir->op2);
+ break;
+
+ /* Overflow-checking arithmetic ops. */
+ case IR_ADDOV: asm_arithov(as, ir, PPCI_ADDO); break;
+ case IR_SUBOV: asm_arithov(as, ir, PPCI_SUBFO); break;
+ case IR_MULOV: asm_arithov(as, ir, PPCI_MULLWO); break;
+
+ /* Memory references. */
+ case IR_AREF: asm_aref(as, ir); break;
+ case IR_HREF: asm_href(as, ir, 0); break;
+ case IR_HREFK: asm_hrefk(as, ir); break;
+ case IR_NEWREF: asm_newref(as, ir); break;
+ case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break;
+ case IR_FREF: asm_fref(as, ir); break;
+ case IR_STRREF: asm_strref(as, ir); break;
+
+ /* Loads and stores. */
+ case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:
+ asm_ahuvload(as, ir);
+ break;
+ case IR_FLOAD: asm_fload(as, ir); break;
+ case IR_XLOAD: asm_xload(as, ir); break;
+ case IR_SLOAD: asm_sload(as, ir); break;
+
+ case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break;
+ case IR_FSTORE: asm_fstore(as, ir); break;
+ case IR_XSTORE: asm_xstore(as, ir, 0); break;
+
+ /* Allocations. */
+ case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break;
+ case IR_TNEW: asm_tnew(as, ir); break;
+ case IR_TDUP: asm_tdup(as, ir); break;
+ case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break;
+
+ /* Write barriers. */
+ case IR_TBAR: asm_tbar(as, ir); break;
+ case IR_OBAR: asm_obar(as, ir); break;
+
+ /* Type conversions. */
+ case IR_CONV: asm_conv(as, ir); break;
+ case IR_TOBIT: asm_tobit(as, ir); break;
+ case IR_TOSTR: asm_tostr(as, ir); break;
+ case IR_STRTO: asm_strto(as, ir); break;
+
+ /* Calls. */
+ case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break;
+ case IR_CALLXS: asm_callx(as, ir); break;
+ case IR_CARG: break;
+
+ default:
+ setintV(&as->J->errinfo, ir->o);
+ lj_trace_err_info(as->J, LJ_TRERR_NYIIR);
+ break;
+ }
+}
+
+/* -- Trace setup --------------------------------------------------------- */
+
+/* Ensure there are enough stack slots for call arguments. */
+static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)
+{
+ IRRef args[CCI_NARGS_MAX*2];
+ uint32_t i, nargs = (int)CCI_NARGS(ci);
+ int nslots = 2, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR;
+ asm_collectargs(as, ir, ci, args);
+ for (i = 0; i < nargs; i++)
+ if (args[i] && irt_isfp(IR(args[i])->t)) {
+ if (nfpr > 0) nfpr--; else nslots = (nslots+3) & ~1;
+ } else {
+ if (ngpr > 0) ngpr--; else nslots++;
+ }
+ if (nslots > as->evenspill) /* Leave room for args in stack slots. */
+ as->evenspill = nslots;
+ return irt_isfp(ir->t) ? REGSP_HINT(RID_FPRET) : REGSP_HINT(RID_RET);
+}
+
+static void asm_setup_target(ASMState *as)
+{
+ asm_exitstub_setup(as, as->T->nsnap + (as->parent ? 1 : 0));
+}
+
+/* -- Trace patching ------------------------------------------------------ */
+
+/* Patch exit jumps of existing machine code to a new target. */
+void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target)
+{
+ MCode *p = T->mcode;
+ MCode *pe = (MCode *)((char *)p + T->szmcode);
+ MCode *px = exitstub_trace_addr(T, exitno);
+ MCode *cstart = NULL;
+ MCode *mcarea = lj_mcode_patch(J, p, 0);
+ int clearso = 0;
+ for (; p < pe; p++) {
+ /* Look for exitstub branch, try to replace with branch to target. */
+ uint32_t ins = *p;
+ if ((ins & 0xfc000000u) == 0x40000000u &&
+ ((ins ^ ((char *)px-(char *)p)) & 0xffffu) == 0) {
+ ptrdiff_t delta = (char *)target - (char *)p;
+ if (((ins >> 16) & 3) == (CC_SO&3)) {
+ clearso = sizeof(MCode);
+ delta -= sizeof(MCode);
+ }
+ /* Many, but not all short-range branches can be patched directly. */
+ if (((delta + 0x8000) >> 16) == 0) {
+ *p = (ins & 0xffdf0000u) | ((uint32_t)delta & 0xffffu) |
+ ((delta & 0x8000) * (PPCF_Y/0x8000));
+ if (!cstart) cstart = p;
+ }
+ } else if ((ins & 0xfc000000u) == PPCI_B &&
+ ((ins ^ ((char *)px-(char *)p)) & 0x03ffffffu) == 0) {
+ ptrdiff_t delta = (char *)target - (char *)p;
+ lua_assert(((delta + 0x02000000) >> 26) == 0);
+ *p = PPCI_B | ((uint32_t)delta & 0x03ffffffu);
+ if (!cstart) cstart = p;
+ }
+ }
+ { /* Always patch long-range branch in exit stub itself. */
+ ptrdiff_t delta = (char *)target - (char *)px - clearso;
+ lua_assert(((delta + 0x02000000) >> 26) == 0);
+ *px = PPCI_B | ((uint32_t)delta & 0x03ffffffu);
+ }
+ if (!cstart) cstart = px;
+ lj_mcode_sync(cstart, px+1);
+ if (clearso) { /* Extend the current trace. Ugly workaround. */
+ MCode *pp = J->cur.mcode;
+ J->cur.szmcode += sizeof(MCode);
+ *--pp = PPCI_MCRXR; /* Clear SO flag. */
+ J->cur.mcode = pp;
+ lj_mcode_sync(pp, pp+1);
+ }
+ lj_mcode_patch(J, mcarea, 1);
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_asm_x86.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_asm_x86.h
new file mode 100644
index 0000000..10468bb
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_asm_x86.h
@@ -0,0 +1,2900 @@
+/*
+** x86/x64 IR assembler (SSA IR -> machine code).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* -- Guard handling ------------------------------------------------------ */
+
+/* Generate an exit stub group at the bottom of the reserved MCode memory. */
+static MCode *asm_exitstub_gen(ASMState *as, ExitNo group)
+{
+ ExitNo i, groupofs = (group*EXITSTUBS_PER_GROUP) & 0xff;
+ MCode *mxp = as->mcbot;
+ MCode *mxpstart = mxp;
+ if (mxp + (2+2)*EXITSTUBS_PER_GROUP+8+5 >= as->mctop)
+ asm_mclimit(as);
+ /* Push low byte of exitno for each exit stub. */
+ *mxp++ = XI_PUSHi8; *mxp++ = (MCode)groupofs;
+ for (i = 1; i < EXITSTUBS_PER_GROUP; i++) {
+ *mxp++ = XI_JMPs; *mxp++ = (MCode)((2+2)*(EXITSTUBS_PER_GROUP - i) - 2);
+ *mxp++ = XI_PUSHi8; *mxp++ = (MCode)(groupofs + i);
+ }
+ /* Push the high byte of the exitno for each exit stub group. */
+ *mxp++ = XI_PUSHi8; *mxp++ = (MCode)((group*EXITSTUBS_PER_GROUP)>>8);
+ /* Store DISPATCH at original stack slot 0. Account for the two push ops. */
+ *mxp++ = XI_MOVmi;
+ *mxp++ = MODRM(XM_OFS8, 0, RID_ESP);
+ *mxp++ = MODRM(XM_SCALE1, RID_ESP, RID_ESP);
+ *mxp++ = 2*sizeof(void *);
+ *(int32_t *)mxp = ptr2addr(J2GG(as->J)->dispatch); mxp += 4;
+ /* Jump to exit handler which fills in the ExitState. */
+ *mxp++ = XI_JMP; mxp += 4;
+ *((int32_t *)(mxp-4)) = jmprel(mxp, (MCode *)(void *)lj_vm_exit_handler);
+ /* Commit the code for this group (even if assembly fails later on). */
+ lj_mcode_commitbot(as->J, mxp);
+ as->mcbot = mxp;
+ as->mclim = as->mcbot + MCLIM_REDZONE;
+ return mxpstart;
+}
+
+/* Setup all needed exit stubs. */
+static void asm_exitstub_setup(ASMState *as, ExitNo nexits)
+{
+ ExitNo i;
+ if (nexits >= EXITSTUBS_PER_GROUP*LJ_MAX_EXITSTUBGR)
+ lj_trace_err(as->J, LJ_TRERR_SNAPOV);
+ for (i = 0; i < (nexits+EXITSTUBS_PER_GROUP-1)/EXITSTUBS_PER_GROUP; i++)
+ if (as->J->exitstubgroup[i] == NULL)
+ as->J->exitstubgroup[i] = asm_exitstub_gen(as, i);
+}
+
+/* Emit conditional branch to exit for guard.
+** It's important to emit this *after* all registers have been allocated,
+** because rematerializations may invalidate the flags.
+*/
+static void asm_guardcc(ASMState *as, int cc)
+{
+ MCode *target = exitstub_addr(as->J, as->snapno);
+ MCode *p = as->mcp;
+ if (LJ_UNLIKELY(p == as->invmcp)) {
+ as->loopinv = 1;
+ *(int32_t *)(p+1) = jmprel(p+5, target);
+ target = p;
+ cc ^= 1;
+ if (as->realign) {
+ emit_sjcc(as, cc, target);
+ return;
+ }
+ }
+ emit_jcc(as, cc, target);
+}
+
+/* -- Memory operand fusion ----------------------------------------------- */
+
+/* Limit linear search to this distance. Avoids O(n^2) behavior. */
+#define CONFLICT_SEARCH_LIM 31
+
+/* Check if a reference is a signed 32 bit constant. */
+static int asm_isk32(ASMState *as, IRRef ref, int32_t *k)
+{
+ if (irref_isk(ref)) {
+ IRIns *ir = IR(ref);
+ if (ir->o != IR_KINT64) {
+ *k = ir->i;
+ return 1;
+ } else if (checki32((int64_t)ir_kint64(ir)->u64)) {
+ *k = (int32_t)ir_kint64(ir)->u64;
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/* Check if there's no conflicting instruction between curins and ref.
+** Also avoid fusing loads if there are multiple references.
+*/
+static int noconflict(ASMState *as, IRRef ref, IROp conflict, int noload)
+{
+ IRIns *ir = as->ir;
+ IRRef i = as->curins;
+ if (i > ref + CONFLICT_SEARCH_LIM)
+ return 0; /* Give up, ref is too far away. */
+ while (--i > ref) {
+ if (ir[i].o == conflict)
+ return 0; /* Conflict found. */
+ else if (!noload && (ir[i].op1 == ref || ir[i].op2 == ref))
+ return 0;
+ }
+ return 1; /* Ok, no conflict. */
+}
+
+/* Fuse array base into memory operand. */
+static IRRef asm_fuseabase(ASMState *as, IRRef ref)
+{
+ IRIns *irb = IR(ref);
+ as->mrm.ofs = 0;
+ if (irb->o == IR_FLOAD) {
+ IRIns *ira = IR(irb->op1);
+ lua_assert(irb->op2 == IRFL_TAB_ARRAY);
+ /* We can avoid the FLOAD of t->array for colocated arrays. */
+ if (ira->o == IR_TNEW && ira->op1 <= LJ_MAX_COLOSIZE &&
+ !neverfuse(as) && noconflict(as, irb->op1, IR_NEWREF, 1)) {
+ as->mrm.ofs = (int32_t)sizeof(GCtab); /* Ofs to colocated array. */
+ return irb->op1; /* Table obj. */
+ }
+ } else if (irb->o == IR_ADD && irref_isk(irb->op2)) {
+ /* Fuse base offset (vararg load). */
+ as->mrm.ofs = IR(irb->op2)->i;
+ return irb->op1;
+ }
+ return ref; /* Otherwise use the given array base. */
+}
+
+/* Fuse array reference into memory operand. */
+static void asm_fusearef(ASMState *as, IRIns *ir, RegSet allow)
+{
+ IRIns *irx;
+ lua_assert(ir->o == IR_AREF);
+ as->mrm.base = (uint8_t)ra_alloc1(as, asm_fuseabase(as, ir->op1), allow);
+ irx = IR(ir->op2);
+ if (irref_isk(ir->op2)) {
+ as->mrm.ofs += 8*irx->i;
+ as->mrm.idx = RID_NONE;
+ } else {
+ rset_clear(allow, as->mrm.base);
+ as->mrm.scale = XM_SCALE8;
+ /* Fuse a constant ADD (e.g. t[i+1]) into the offset.
+ ** Doesn't help much without ABCelim, but reduces register pressure.
+ */
+ if (!LJ_64 && /* Has bad effects with negative index on x64. */
+ mayfuse(as, ir->op2) && ra_noreg(irx->r) &&
+ irx->o == IR_ADD && irref_isk(irx->op2)) {
+ as->mrm.ofs += 8*IR(irx->op2)->i;
+ as->mrm.idx = (uint8_t)ra_alloc1(as, irx->op1, allow);
+ } else {
+ as->mrm.idx = (uint8_t)ra_alloc1(as, ir->op2, allow);
+ }
+ }
+}
+
+/* Fuse array/hash/upvalue reference into memory operand.
+** Caveat: this may allocate GPRs for the base/idx registers. Be sure to
+** pass the final allow mask, excluding any GPRs used for other inputs.
+** In particular: 2-operand GPR instructions need to call ra_dest() first!
+*/
+static void asm_fuseahuref(ASMState *as, IRRef ref, RegSet allow)
+{
+ IRIns *ir = IR(ref);
+ if (ra_noreg(ir->r)) {
+ switch ((IROp)ir->o) {
+ case IR_AREF:
+ if (mayfuse(as, ref)) {
+ asm_fusearef(as, ir, allow);
+ return;
+ }
+ break;
+ case IR_HREFK:
+ if (mayfuse(as, ref)) {
+ as->mrm.base = (uint8_t)ra_alloc1(as, ir->op1, allow);
+ as->mrm.ofs = (int32_t)(IR(ir->op2)->op2 * sizeof(Node));
+ as->mrm.idx = RID_NONE;
+ return;
+ }
+ break;
+ case IR_UREFC:
+ if (irref_isk(ir->op1)) {
+ GCfunc *fn = ir_kfunc(IR(ir->op1));
+ GCupval *uv = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv;
+ as->mrm.ofs = ptr2addr(&uv->tv);
+ as->mrm.base = as->mrm.idx = RID_NONE;
+ return;
+ }
+ break;
+ default:
+ lua_assert(ir->o == IR_HREF || ir->o == IR_NEWREF || ir->o == IR_UREFO ||
+ ir->o == IR_KKPTR);
+ break;
+ }
+ }
+ as->mrm.base = (uint8_t)ra_alloc1(as, ref, allow);
+ as->mrm.ofs = 0;
+ as->mrm.idx = RID_NONE;
+}
+
+/* Fuse FLOAD/FREF reference into memory operand. */
+static void asm_fusefref(ASMState *as, IRIns *ir, RegSet allow)
+{
+ lua_assert(ir->o == IR_FLOAD || ir->o == IR_FREF);
+ as->mrm.ofs = field_ofs[ir->op2];
+ as->mrm.idx = RID_NONE;
+ if (irref_isk(ir->op1)) {
+ as->mrm.ofs += IR(ir->op1)->i;
+ as->mrm.base = RID_NONE;
+ } else {
+ as->mrm.base = (uint8_t)ra_alloc1(as, ir->op1, allow);
+ }
+}
+
+/* Fuse string reference into memory operand. */
+static void asm_fusestrref(ASMState *as, IRIns *ir, RegSet allow)
+{
+ IRIns *irr;
+ lua_assert(ir->o == IR_STRREF);
+ as->mrm.base = as->mrm.idx = RID_NONE;
+ as->mrm.scale = XM_SCALE1;
+ as->mrm.ofs = sizeof(GCstr);
+ if (irref_isk(ir->op1)) {
+ as->mrm.ofs += IR(ir->op1)->i;
+ } else {
+ Reg r = ra_alloc1(as, ir->op1, allow);
+ rset_clear(allow, r);
+ as->mrm.base = (uint8_t)r;
+ }
+ irr = IR(ir->op2);
+ if (irref_isk(ir->op2)) {
+ as->mrm.ofs += irr->i;
+ } else {
+ Reg r;
+ /* Fuse a constant add into the offset, e.g. string.sub(s, i+10). */
+ if (!LJ_64 && /* Has bad effects with negative index on x64. */
+ mayfuse(as, ir->op2) && irr->o == IR_ADD && irref_isk(irr->op2)) {
+ as->mrm.ofs += IR(irr->op2)->i;
+ r = ra_alloc1(as, irr->op1, allow);
+ } else {
+ r = ra_alloc1(as, ir->op2, allow);
+ }
+ if (as->mrm.base == RID_NONE)
+ as->mrm.base = (uint8_t)r;
+ else
+ as->mrm.idx = (uint8_t)r;
+ }
+}
+
+static void asm_fusexref(ASMState *as, IRRef ref, RegSet allow)
+{
+ IRIns *ir = IR(ref);
+ as->mrm.idx = RID_NONE;
+ if (ir->o == IR_KPTR || ir->o == IR_KKPTR) {
+ as->mrm.ofs = ir->i;
+ as->mrm.base = RID_NONE;
+ } else if (ir->o == IR_STRREF) {
+ asm_fusestrref(as, ir, allow);
+ } else {
+ as->mrm.ofs = 0;
+ if (canfuse(as, ir) && ir->o == IR_ADD && ra_noreg(ir->r)) {
+ /* Gather (base+idx*sz)+ofs as emitted by cdata ptr/array indexing. */
+ IRIns *irx;
+ IRRef idx;
+ Reg r;
+ if (asm_isk32(as, ir->op2, &as->mrm.ofs)) { /* Recognize x+ofs. */
+ ref = ir->op1;
+ ir = IR(ref);
+ if (!(ir->o == IR_ADD && canfuse(as, ir) && ra_noreg(ir->r)))
+ goto noadd;
+ }
+ as->mrm.scale = XM_SCALE1;
+ idx = ir->op1;
+ ref = ir->op2;
+ irx = IR(idx);
+ if (!(irx->o == IR_BSHL || irx->o == IR_ADD)) { /* Try other operand. */
+ idx = ir->op2;
+ ref = ir->op1;
+ irx = IR(idx);
+ }
+ if (canfuse(as, irx) && ra_noreg(irx->r)) {
+ if (irx->o == IR_BSHL && irref_isk(irx->op2) && IR(irx->op2)->i <= 3) {
+ /* Recognize idx<<b with b = 0-3, corresponding to sz = (1),2,4,8. */
+ idx = irx->op1;
+ as->mrm.scale = (uint8_t)(IR(irx->op2)->i << 6);
+ } else if (irx->o == IR_ADD && irx->op1 == irx->op2) {
+ /* FOLD does idx*2 ==> idx<<1 ==> idx+idx. */
+ idx = irx->op1;
+ as->mrm.scale = XM_SCALE2;
+ }
+ }
+ r = ra_alloc1(as, idx, allow);
+ rset_clear(allow, r);
+ as->mrm.idx = (uint8_t)r;
+ }
+ noadd:
+ as->mrm.base = (uint8_t)ra_alloc1(as, ref, allow);
+ }
+}
+
+/* Fuse load into memory operand. */
+static Reg asm_fuseload(ASMState *as, IRRef ref, RegSet allow)
+{
+ IRIns *ir = IR(ref);
+ if (ra_hasreg(ir->r)) {
+ if (allow != RSET_EMPTY) { /* Fast path. */
+ ra_noweak(as, ir->r);
+ return ir->r;
+ }
+ fusespill:
+ /* Force a spill if only memory operands are allowed (asm_x87load). */
+ as->mrm.base = RID_ESP;
+ as->mrm.ofs = ra_spill(as, ir);
+ as->mrm.idx = RID_NONE;
+ return RID_MRM;
+ }
+ if (ir->o == IR_KNUM) {
+ RegSet avail = as->freeset & ~as->modset & RSET_FPR;
+ lua_assert(allow != RSET_EMPTY);
+ if (!(avail & (avail-1))) { /* Fuse if less than two regs available. */
+ as->mrm.ofs = ptr2addr(ir_knum(ir));
+ as->mrm.base = as->mrm.idx = RID_NONE;
+ return RID_MRM;
+ }
+ } else if (ref == REF_BASE || ir->o == IR_KINT64) {
+ RegSet avail = as->freeset & ~as->modset & RSET_GPR;
+ lua_assert(allow != RSET_EMPTY);
+ if (!(avail & (avail-1))) { /* Fuse if less than two regs available. */
+ as->mrm.ofs = ptr2addr(ref == REF_BASE ? (void *)&J2G(as->J)->jit_base : (void *)ir_kint64(ir));
+ as->mrm.base = as->mrm.idx = RID_NONE;
+ return RID_MRM;
+ }
+ } else if (mayfuse(as, ref)) {
+ RegSet xallow = (allow & RSET_GPR) ? allow : RSET_GPR;
+ if (ir->o == IR_SLOAD) {
+ if (!(ir->op2 & (IRSLOAD_PARENT|IRSLOAD_CONVERT)) &&
+ noconflict(as, ref, IR_RETF, 0)) {
+ as->mrm.base = (uint8_t)ra_alloc1(as, REF_BASE, xallow);
+ as->mrm.ofs = 8*((int32_t)ir->op1-1) + ((ir->op2&IRSLOAD_FRAME)?4:0);
+ as->mrm.idx = RID_NONE;
+ return RID_MRM;
+ }
+ } else if (ir->o == IR_FLOAD) {
+ /* Generic fusion is only ok for 32 bit operand (but see asm_comp). */
+ if ((irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t)) &&
+ noconflict(as, ref, IR_FSTORE, 0)) {
+ asm_fusefref(as, ir, xallow);
+ return RID_MRM;
+ }
+ } else if (ir->o == IR_ALOAD || ir->o == IR_HLOAD || ir->o == IR_ULOAD) {
+ if (noconflict(as, ref, ir->o + IRDELTA_L2S, 0)) {
+ asm_fuseahuref(as, ir->op1, xallow);
+ return RID_MRM;
+ }
+ } else if (ir->o == IR_XLOAD) {
+ /* Generic fusion is not ok for 8/16 bit operands (but see asm_comp).
+ ** Fusing unaligned memory operands is ok on x86 (except for SIMD types).
+ */
+ if ((!irt_typerange(ir->t, IRT_I8, IRT_U16)) &&
+ noconflict(as, ref, IR_XSTORE, 0)) {
+ asm_fusexref(as, ir->op1, xallow);
+ return RID_MRM;
+ }
+ } else if (ir->o == IR_VLOAD) {
+ asm_fuseahuref(as, ir->op1, xallow);
+ return RID_MRM;
+ }
+ }
+ if (!(as->freeset & allow) && !emit_canremat(ref) &&
+ (allow == RSET_EMPTY || ra_hasspill(ir->s) || iscrossref(as, ref)))
+ goto fusespill;
+ return ra_allocref(as, ref, allow);
+}
+
+#if LJ_64
+/* Don't fuse a 32 bit load into a 64 bit operation. */
+static Reg asm_fuseloadm(ASMState *as, IRRef ref, RegSet allow, int is64)
+{
+ if (is64 && !irt_is64(IR(ref)->t))
+ return ra_alloc1(as, ref, allow);
+ return asm_fuseload(as, ref, allow);
+}
+#else
+#define asm_fuseloadm(as, ref, allow, is64) asm_fuseload(as, (ref), (allow))
+#endif
+
+/* -- Calls --------------------------------------------------------------- */
+
+/* Count the required number of stack slots for a call. */
+static int asm_count_call_slots(ASMState *as, const CCallInfo *ci, IRRef *args)
+{
+ uint32_t i, nargs = CCI_NARGS(ci);
+ int nslots = 0;
+#if LJ_64
+ if (LJ_ABI_WIN) {
+ nslots = (int)(nargs*2); /* Only matters for more than four args. */
+ } else {
+ int ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR;
+ for (i = 0; i < nargs; i++)
+ if (args[i] && irt_isfp(IR(args[i])->t)) {
+ if (nfpr > 0) nfpr--; else nslots += 2;
+ } else {
+ if (ngpr > 0) ngpr--; else nslots += 2;
+ }
+ }
+#else
+ int ngpr = 0;
+ if ((ci->flags & CCI_CC_MASK) == CCI_CC_FASTCALL)
+ ngpr = 2;
+ else if ((ci->flags & CCI_CC_MASK) == CCI_CC_THISCALL)
+ ngpr = 1;
+ for (i = 0; i < nargs; i++)
+ if (args[i] && irt_isfp(IR(args[i])->t)) {
+ nslots += irt_isnum(IR(args[i])->t) ? 2 : 1;
+ } else {
+ if (ngpr > 0) ngpr--; else nslots++;
+ }
+#endif
+ return nslots;
+}
+
+/* Generate a call to a C function. */
+static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)
+{
+ uint32_t n, nargs = CCI_NARGS(ci);
+ int32_t ofs = STACKARG_OFS;
+#if LJ_64
+ uint32_t gprs = REGARG_GPRS;
+ Reg fpr = REGARG_FIRSTFPR;
+#if !LJ_ABI_WIN
+ MCode *patchnfpr = NULL;
+#endif
+#else
+ uint32_t gprs = 0;
+ if ((ci->flags & CCI_CC_MASK) != CCI_CC_CDECL) {
+ if ((ci->flags & CCI_CC_MASK) == CCI_CC_THISCALL)
+ gprs = (REGARG_GPRS & 31);
+ else if ((ci->flags & CCI_CC_MASK) == CCI_CC_FASTCALL)
+ gprs = REGARG_GPRS;
+ }
+#endif
+ if ((void *)ci->func)
+ emit_call(as, ci->func);
+#if LJ_64
+ if ((ci->flags & CCI_VARARG)) { /* Special handling for vararg calls. */
+#if LJ_ABI_WIN
+ for (n = 0; n < 4 && n < nargs; n++) {
+ IRIns *ir = IR(args[n]);
+ if (irt_isfp(ir->t)) /* Duplicate FPRs in GPRs. */
+ emit_rr(as, XO_MOVDto, (irt_isnum(ir->t) ? REX_64 : 0) | (fpr+n),
+ ((gprs >> (n*5)) & 31)); /* Either MOVD or MOVQ. */
+ }
+#else
+ patchnfpr = --as->mcp; /* Indicate number of used FPRs in register al. */
+ *--as->mcp = XI_MOVrib | RID_EAX;
+#endif
+ }
+#endif
+ for (n = 0; n < nargs; n++) { /* Setup args. */
+ IRRef ref = args[n];
+ IRIns *ir = IR(ref);
+ Reg r;
+#if LJ_64 && LJ_ABI_WIN
+ /* Windows/x64 argument registers are strictly positional. */
+ r = irt_isfp(ir->t) ? (fpr <= REGARG_LASTFPR ? fpr : 0) : (gprs & 31);
+ fpr++; gprs >>= 5;
+#elif LJ_64
+ /* POSIX/x64 argument registers are used in order of appearance. */
+ if (irt_isfp(ir->t)) {
+ r = fpr <= REGARG_LASTFPR ? fpr++ : 0;
+ } else {
+ r = gprs & 31; gprs >>= 5;
+ }
+#else
+ if (ref && irt_isfp(ir->t)) {
+ r = 0;
+ } else {
+ r = gprs & 31; gprs >>= 5;
+ if (!ref) continue;
+ }
+#endif
+ if (r) { /* Argument is in a register. */
+ if (r < RID_MAX_GPR && ref < ASMREF_TMP1) {
+#if LJ_64
+ if (ir->o == IR_KINT64)
+ emit_loadu64(as, r, ir_kint64(ir)->u64);
+ else
+#endif
+ emit_loadi(as, r, ir->i);
+ } else {
+ lua_assert(rset_test(as->freeset, r)); /* Must have been evicted. */
+ if (ra_hasreg(ir->r)) {
+ ra_noweak(as, ir->r);
+ emit_movrr(as, ir, r, ir->r);
+ } else {
+ ra_allocref(as, ref, RID2RSET(r));
+ }
+ }
+ } else if (irt_isfp(ir->t)) { /* FP argument is on stack. */
+ lua_assert(!(irt_isfloat(ir->t) && irref_isk(ref))); /* No float k. */
+ if (LJ_32 && (ofs & 4) && irref_isk(ref)) {
+ /* Split stores for unaligned FP consts. */
+ emit_movmroi(as, RID_ESP, ofs, (int32_t)ir_knum(ir)->u32.lo);
+ emit_movmroi(as, RID_ESP, ofs+4, (int32_t)ir_knum(ir)->u32.hi);
+ } else {
+ r = ra_alloc1(as, ref, RSET_FPR);
+ emit_rmro(as, irt_isnum(ir->t) ? XO_MOVSDto : XO_MOVSSto,
+ r, RID_ESP, ofs);
+ }
+ ofs += (LJ_32 && irt_isfloat(ir->t)) ? 4 : 8;
+ } else { /* Non-FP argument is on stack. */
+ if (LJ_32 && ref < ASMREF_TMP1) {
+ emit_movmroi(as, RID_ESP, ofs, ir->i);
+ } else {
+ r = ra_alloc1(as, ref, RSET_GPR);
+ emit_movtomro(as, REX_64 + r, RID_ESP, ofs);
+ }
+ ofs += sizeof(intptr_t);
+ }
+ checkmclim(as);
+ }
+#if LJ_64 && !LJ_ABI_WIN
+ if (patchnfpr) *patchnfpr = fpr - REGARG_FIRSTFPR;
+#endif
+}
+
+/* Setup result reg/sp for call. Evict scratch regs. */
+static void asm_setupresult(ASMState *as, IRIns *ir, const CCallInfo *ci)
+{
+ RegSet drop = RSET_SCRATCH;
+ int hiop = (LJ_32 && (ir+1)->o == IR_HIOP && !irt_isnil((ir+1)->t));
+ if ((ci->flags & CCI_NOFPRCLOBBER))
+ drop &= ~RSET_FPR;
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ if (hiop && ra_hasreg((ir+1)->r))
+ rset_clear(drop, (ir+1)->r); /* Dest reg handled below. */
+ ra_evictset(as, drop); /* Evictions must be performed first. */
+ if (ra_used(ir)) {
+ if (irt_isfp(ir->t)) {
+ int32_t ofs = sps_scale(ir->s); /* Use spill slot or temp slots. */
+#if LJ_64
+ if ((ci->flags & CCI_CASTU64)) {
+ Reg dest = ir->r;
+ if (ra_hasreg(dest)) {
+ ra_free(as, dest);
+ ra_modified(as, dest);
+ emit_rr(as, XO_MOVD, dest|REX_64, RID_RET); /* Really MOVQ. */
+ }
+ if (ofs) emit_movtomro(as, RID_RET|REX_64, RID_ESP, ofs);
+ } else {
+ ra_destreg(as, ir, RID_FPRET);
+ }
+#else
+ /* Number result is in x87 st0 for x86 calling convention. */
+ Reg dest = ir->r;
+ if (ra_hasreg(dest)) {
+ ra_free(as, dest);
+ ra_modified(as, dest);
+ emit_rmro(as, irt_isnum(ir->t) ? XMM_MOVRM(as) : XO_MOVSS,
+ dest, RID_ESP, ofs);
+ }
+ if ((ci->flags & CCI_CASTU64)) {
+ emit_movtomro(as, RID_RETLO, RID_ESP, ofs);
+ emit_movtomro(as, RID_RETHI, RID_ESP, ofs+4);
+ } else {
+ emit_rmro(as, irt_isnum(ir->t) ? XO_FSTPq : XO_FSTPd,
+ irt_isnum(ir->t) ? XOg_FSTPq : XOg_FSTPd, RID_ESP, ofs);
+ }
+#endif
+#if LJ_32
+ } else if (hiop) {
+ ra_destpair(as, ir);
+#endif
+ } else {
+ lua_assert(!irt_ispri(ir->t));
+ ra_destreg(as, ir, RID_RET);
+ }
+ } else if (LJ_32 && irt_isfp(ir->t) && !(ci->flags & CCI_CASTU64)) {
+ emit_x87op(as, XI_FPOP); /* Pop unused result from x87 st0. */
+ }
+}
+
+static void asm_call(ASMState *as, IRIns *ir)
+{
+ IRRef args[CCI_NARGS_MAX];
+ const CCallInfo *ci = &lj_ir_callinfo[ir->op2];
+ asm_collectargs(as, ir, ci, args);
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+
+/* Return a constant function pointer or NULL for indirect calls. */
+static void *asm_callx_func(ASMState *as, IRIns *irf, IRRef func)
+{
+#if LJ_32
+ UNUSED(as);
+ if (irref_isk(func))
+ return (void *)irf->i;
+#else
+ if (irref_isk(func)) {
+ MCode *p;
+ if (irf->o == IR_KINT64)
+ p = (MCode *)(void *)ir_k64(irf)->u64;
+ else
+ p = (MCode *)(void *)(uintptr_t)(uint32_t)irf->i;
+ if (p - as->mcp == (int32_t)(p - as->mcp))
+ return p; /* Call target is still in +-2GB range. */
+ /* Avoid the indirect case of emit_call(). Try to hoist func addr. */
+ }
+#endif
+ return NULL;
+}
+
+static void asm_callx(ASMState *as, IRIns *ir)
+{
+ IRRef args[CCI_NARGS_MAX*2];
+ CCallInfo ci;
+ IRRef func;
+ IRIns *irf;
+ int32_t spadj = 0;
+ ci.flags = asm_callx_flags(as, ir);
+ asm_collectargs(as, ir, &ci, args);
+ asm_setupresult(as, ir, &ci);
+#if LJ_32
+ /* Have to readjust stack after non-cdecl calls due to callee cleanup. */
+ if ((ci.flags & CCI_CC_MASK) != CCI_CC_CDECL)
+ spadj = 4 * asm_count_call_slots(as, &ci, args);
+#endif
+ func = ir->op2; irf = IR(func);
+ if (irf->o == IR_CARG) { func = irf->op1; irf = IR(func); }
+ ci.func = (ASMFunction)asm_callx_func(as, irf, func);
+ if (!(void *)ci.func) {
+ /* Use a (hoistable) non-scratch register for indirect calls. */
+ RegSet allow = (RSET_GPR & ~RSET_SCRATCH);
+ Reg r = ra_alloc1(as, func, allow);
+ if (LJ_32) emit_spsub(as, spadj); /* Above code may cause restores! */
+ emit_rr(as, XO_GROUP5, XOg_CALL, r);
+ } else if (LJ_32) {
+ emit_spsub(as, spadj);
+ }
+ asm_gencall(as, &ci, args);
+}
+
+/* -- Returns ------------------------------------------------------------- */
+
+/* Return to lower frame. Guard that it goes to the right spot. */
+static void asm_retf(ASMState *as, IRIns *ir)
+{
+ Reg base = ra_alloc1(as, REF_BASE, RSET_GPR);
+ void *pc = ir_kptr(IR(ir->op2));
+ int32_t delta = 1+bc_a(*((const BCIns *)pc - 1));
+ as->topslot -= (BCReg)delta;
+ if ((int32_t)as->topslot < 0) as->topslot = 0;
+ irt_setmark(IR(REF_BASE)->t); /* Children must not coalesce with BASE reg. */
+ emit_setgl(as, base, jit_base);
+ emit_addptr(as, base, -8*delta);
+ asm_guardcc(as, CC_NE);
+ emit_gmroi(as, XG_ARITHi(XOg_CMP), base, -4, ptr2addr(pc));
+}
+
+/* -- Type conversions ---------------------------------------------------- */
+
+static void asm_tointg(ASMState *as, IRIns *ir, Reg left)
+{
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_FPR, left));
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ asm_guardcc(as, CC_P);
+ asm_guardcc(as, CC_NE);
+ emit_rr(as, XO_UCOMISD, left, tmp);
+ emit_rr(as, XO_CVTSI2SD, tmp, dest);
+ if (!(as->flags & JIT_F_SPLIT_XMM))
+ emit_rr(as, XO_XORPS, tmp, tmp); /* Avoid partial register stall. */
+ emit_rr(as, XO_CVTTSD2SI, dest, left);
+ /* Can't fuse since left is needed twice. */
+}
+
+static void asm_tobit(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ Reg tmp = ra_noreg(IR(ir->op1)->r) ?
+ ra_alloc1(as, ir->op1, RSET_FPR) :
+ ra_scratch(as, RSET_FPR);
+ Reg right = asm_fuseload(as, ir->op2, rset_exclude(RSET_FPR, tmp));
+ emit_rr(as, XO_MOVDto, tmp, dest);
+ emit_mrm(as, XO_ADDSD, tmp, right);
+ ra_left(as, tmp, ir->op1);
+}
+
+static void asm_conv(ASMState *as, IRIns *ir)
+{
+ IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);
+ int st64 = (st == IRT_I64 || st == IRT_U64 || (LJ_64 && st == IRT_P64));
+ int stfp = (st == IRT_NUM || st == IRT_FLOAT);
+ IRRef lref = ir->op1;
+ lua_assert(irt_type(ir->t) != st);
+ lua_assert(!(LJ_32 && (irt_isint64(ir->t) || st64))); /* Handled by SPLIT. */
+ if (irt_isfp(ir->t)) {
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ if (stfp) { /* FP to FP conversion. */
+ Reg left = asm_fuseload(as, lref, RSET_FPR);
+ emit_mrm(as, st == IRT_NUM ? XO_CVTSD2SS : XO_CVTSS2SD, dest, left);
+ if (left == dest) return; /* Avoid the XO_XORPS. */
+ } else if (LJ_32 && st == IRT_U32) { /* U32 to FP conversion on x86. */
+ /* number = (2^52+2^51 .. u32) - (2^52+2^51) */
+ cTValue *k = lj_ir_k64_find(as->J, U64x(43380000,00000000));
+ Reg bias = ra_scratch(as, rset_exclude(RSET_FPR, dest));
+ if (irt_isfloat(ir->t))
+ emit_rr(as, XO_CVTSD2SS, dest, dest);
+ emit_rr(as, XO_SUBSD, dest, bias); /* Subtract 2^52+2^51 bias. */
+ emit_rr(as, XO_XORPS, dest, bias); /* Merge bias and integer. */
+ emit_loadn(as, bias, k);
+ emit_mrm(as, XO_MOVD, dest, asm_fuseload(as, lref, RSET_GPR));
+ return;
+ } else { /* Integer to FP conversion. */
+ Reg left = (LJ_64 && (st == IRT_U32 || st == IRT_U64)) ?
+ ra_alloc1(as, lref, RSET_GPR) :
+ asm_fuseloadm(as, lref, RSET_GPR, st64);
+ if (LJ_64 && st == IRT_U64) {
+ MCLabel l_end = emit_label(as);
+ const void *k = lj_ir_k64_find(as->J, U64x(43f00000,00000000));
+ emit_rma(as, XO_ADDSD, dest, k); /* Add 2^64 to compensate. */
+ emit_sjcc(as, CC_NS, l_end);
+ emit_rr(as, XO_TEST, left|REX_64, left); /* Check if u64 >= 2^63. */
+ }
+ emit_mrm(as, irt_isnum(ir->t) ? XO_CVTSI2SD : XO_CVTSI2SS,
+ dest|((LJ_64 && (st64 || st == IRT_U32)) ? REX_64 : 0), left);
+ }
+ if (!(as->flags & JIT_F_SPLIT_XMM))
+ emit_rr(as, XO_XORPS, dest, dest); /* Avoid partial register stall. */
+ } else if (stfp) { /* FP to integer conversion. */
+ if (irt_isguard(ir->t)) {
+ /* Checked conversions are only supported from number to int. */
+ lua_assert(irt_isint(ir->t) && st == IRT_NUM);
+ asm_tointg(as, ir, ra_alloc1(as, lref, RSET_FPR));
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ x86Op op = st == IRT_NUM ?
+ ((ir->op2 & IRCONV_TRUNC) ? XO_CVTTSD2SI : XO_CVTSD2SI) :
+ ((ir->op2 & IRCONV_TRUNC) ? XO_CVTTSS2SI : XO_CVTSS2SI);
+ if (LJ_64 ? irt_isu64(ir->t) : irt_isu32(ir->t)) {
+ /* LJ_64: For inputs >= 2^63 add -2^64, convert again. */
+ /* LJ_32: For inputs >= 2^31 add -2^31, convert again and add 2^31. */
+ Reg tmp = ra_noreg(IR(lref)->r) ? ra_alloc1(as, lref, RSET_FPR) :
+ ra_scratch(as, RSET_FPR);
+ MCLabel l_end = emit_label(as);
+ if (LJ_32)
+ emit_gri(as, XG_ARITHi(XOg_ADD), dest, (int32_t)0x80000000);
+ emit_rr(as, op, dest|REX_64, tmp);
+ if (st == IRT_NUM)
+ emit_rma(as, XO_ADDSD, tmp, lj_ir_k64_find(as->J,
+ LJ_64 ? U64x(c3f00000,00000000) : U64x(c1e00000,00000000)));
+ else
+ emit_rma(as, XO_ADDSS, tmp, lj_ir_k64_find(as->J,
+ LJ_64 ? U64x(00000000,df800000) : U64x(00000000,cf000000)));
+ emit_sjcc(as, CC_NS, l_end);
+ emit_rr(as, XO_TEST, dest|REX_64, dest); /* Check if dest negative. */
+ emit_rr(as, op, dest|REX_64, tmp);
+ ra_left(as, tmp, lref);
+ } else {
+ Reg left = asm_fuseload(as, lref, RSET_FPR);
+ if (LJ_64 && irt_isu32(ir->t))
+ emit_rr(as, XO_MOV, dest, dest); /* Zero hiword. */
+ emit_mrm(as, op,
+ dest|((LJ_64 &&
+ (irt_is64(ir->t) || irt_isu32(ir->t))) ? REX_64 : 0),
+ left);
+ }
+ }
+ } else if (st >= IRT_I8 && st <= IRT_U16) { /* Extend to 32 bit integer. */
+ Reg left, dest = ra_dest(as, ir, RSET_GPR);
+ RegSet allow = RSET_GPR;
+ x86Op op;
+ lua_assert(irt_isint(ir->t) || irt_isu32(ir->t));
+ if (st == IRT_I8) {
+ op = XO_MOVSXb; allow = RSET_GPR8; dest |= FORCE_REX;
+ } else if (st == IRT_U8) {
+ op = XO_MOVZXb; allow = RSET_GPR8; dest |= FORCE_REX;
+ } else if (st == IRT_I16) {
+ op = XO_MOVSXw;
+ } else {
+ op = XO_MOVZXw;
+ }
+ left = asm_fuseload(as, lref, allow);
+ /* Add extra MOV if source is already in wrong register. */
+ if (!LJ_64 && left != RID_MRM && !rset_test(allow, left)) {
+ Reg tmp = ra_scratch(as, allow);
+ emit_rr(as, op, dest, tmp);
+ emit_rr(as, XO_MOV, tmp, left);
+ } else {
+ emit_mrm(as, op, dest, left);
+ }
+ } else { /* 32/64 bit integer conversions. */
+ if (LJ_32) { /* Only need to handle 32/32 bit no-op (cast) on x86. */
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ ra_left(as, dest, lref); /* Do nothing, but may need to move regs. */
+ } else if (irt_is64(ir->t)) {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (st64 || !(ir->op2 & IRCONV_SEXT)) {
+ /* 64/64 bit no-op (cast) or 32 to 64 bit zero extension. */
+ ra_left(as, dest, lref); /* Do nothing, but may need to move regs. */
+ } else { /* 32 to 64 bit sign extension. */
+ Reg left = asm_fuseload(as, lref, RSET_GPR);
+ emit_mrm(as, XO_MOVSXd, dest|REX_64, left);
+ }
+ } else {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (st64) {
+ Reg left = asm_fuseload(as, lref, RSET_GPR);
+ /* This is either a 32 bit reg/reg mov which zeroes the hiword
+ ** or a load of the loword from a 64 bit address.
+ */
+ emit_mrm(as, XO_MOV, dest, left);
+ } else { /* 32/32 bit no-op (cast). */
+ ra_left(as, dest, lref); /* Do nothing, but may need to move regs. */
+ }
+ }
+ }
+}
+
+#if LJ_32 && LJ_HASFFI
+/* No SSE conversions to/from 64 bit on x86, so resort to ugly x87 code. */
+
+/* 64 bit integer to FP conversion in 32 bit mode. */
+static void asm_conv_fp_int64(ASMState *as, IRIns *ir)
+{
+ Reg hi = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg lo = ra_alloc1(as, (ir-1)->op1, rset_exclude(RSET_GPR, hi));
+ int32_t ofs = sps_scale(ir->s); /* Use spill slot or temp slots. */
+ Reg dest = ir->r;
+ if (ra_hasreg(dest)) {
+ ra_free(as, dest);
+ ra_modified(as, dest);
+ emit_rmro(as, irt_isnum(ir->t) ? XMM_MOVRM(as) : XO_MOVSS,
+ dest, RID_ESP, ofs);
+ }
+ emit_rmro(as, irt_isnum(ir->t) ? XO_FSTPq : XO_FSTPd,
+ irt_isnum(ir->t) ? XOg_FSTPq : XOg_FSTPd, RID_ESP, ofs);
+ if (((ir-1)->op2 & IRCONV_SRCMASK) == IRT_U64) {
+ /* For inputs in [2^63,2^64-1] add 2^64 to compensate. */
+ MCLabel l_end = emit_label(as);
+ emit_rma(as, XO_FADDq, XOg_FADDq,
+ lj_ir_k64_find(as->J, U64x(43f00000,00000000)));
+ emit_sjcc(as, CC_NS, l_end);
+ emit_rr(as, XO_TEST, hi, hi); /* Check if u64 >= 2^63. */
+ } else {
+ lua_assert(((ir-1)->op2 & IRCONV_SRCMASK) == IRT_I64);
+ }
+ emit_rmro(as, XO_FILDq, XOg_FILDq, RID_ESP, 0);
+ /* NYI: Avoid narrow-to-wide store-to-load forwarding stall. */
+ emit_rmro(as, XO_MOVto, hi, RID_ESP, 4);
+ emit_rmro(as, XO_MOVto, lo, RID_ESP, 0);
+}
+
+/* FP to 64 bit integer conversion in 32 bit mode. */
+static void asm_conv_int64_fp(ASMState *as, IRIns *ir)
+{
+ IRType st = (IRType)((ir-1)->op2 & IRCONV_SRCMASK);
+ IRType dt = (((ir-1)->op2 & IRCONV_DSTMASK) >> IRCONV_DSH);
+ Reg lo, hi;
+ lua_assert(st == IRT_NUM || st == IRT_FLOAT);
+ lua_assert(dt == IRT_I64 || dt == IRT_U64);
+ lua_assert(((ir-1)->op2 & IRCONV_TRUNC));
+ hi = ra_dest(as, ir, RSET_GPR);
+ lo = ra_dest(as, ir-1, rset_exclude(RSET_GPR, hi));
+ if (ra_used(ir-1)) emit_rmro(as, XO_MOV, lo, RID_ESP, 0);
+ /* NYI: Avoid wide-to-narrow store-to-load forwarding stall. */
+ if (!(as->flags & JIT_F_SSE3)) { /* Set FPU rounding mode to default. */
+ emit_rmro(as, XO_FLDCW, XOg_FLDCW, RID_ESP, 4);
+ emit_rmro(as, XO_MOVto, lo, RID_ESP, 4);
+ emit_gri(as, XG_ARITHi(XOg_AND), lo, 0xf3ff);
+ }
+ if (dt == IRT_U64) {
+ /* For inputs in [2^63,2^64-1] add -2^64 and convert again. */
+ MCLabel l_pop, l_end = emit_label(as);
+ emit_x87op(as, XI_FPOP);
+ l_pop = emit_label(as);
+ emit_sjmp(as, l_end);
+ emit_rmro(as, XO_MOV, hi, RID_ESP, 4);
+ if ((as->flags & JIT_F_SSE3))
+ emit_rmro(as, XO_FISTTPq, XOg_FISTTPq, RID_ESP, 0);
+ else
+ emit_rmro(as, XO_FISTPq, XOg_FISTPq, RID_ESP, 0);
+ emit_rma(as, XO_FADDq, XOg_FADDq,
+ lj_ir_k64_find(as->J, U64x(c3f00000,00000000)));
+ emit_sjcc(as, CC_NS, l_pop);
+ emit_rr(as, XO_TEST, hi, hi); /* Check if out-of-range (2^63). */
+ }
+ emit_rmro(as, XO_MOV, hi, RID_ESP, 4);
+ if ((as->flags & JIT_F_SSE3)) { /* Truncation is easy with SSE3. */
+ emit_rmro(as, XO_FISTTPq, XOg_FISTTPq, RID_ESP, 0);
+ } else { /* Otherwise set FPU rounding mode to truncate before the store. */
+ emit_rmro(as, XO_FISTPq, XOg_FISTPq, RID_ESP, 0);
+ emit_rmro(as, XO_FLDCW, XOg_FLDCW, RID_ESP, 0);
+ emit_rmro(as, XO_MOVtow, lo, RID_ESP, 0);
+ emit_rmro(as, XO_ARITHw(XOg_OR), lo, RID_ESP, 0);
+ emit_loadi(as, lo, 0xc00);
+ emit_rmro(as, XO_FNSTCW, XOg_FNSTCW, RID_ESP, 0);
+ }
+ if (dt == IRT_U64)
+ emit_x87op(as, XI_FDUP);
+ emit_mrm(as, st == IRT_NUM ? XO_FLDq : XO_FLDd,
+ st == IRT_NUM ? XOg_FLDq: XOg_FLDd,
+ asm_fuseload(as, ir->op1, RSET_EMPTY));
+}
+#endif
+
+static void asm_strto(ASMState *as, IRIns *ir)
+{
+ /* Force a spill slot for the destination register (if any). */
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_strscan_num];
+ IRRef args[2];
+ RegSet drop = RSET_SCRATCH;
+ if ((drop & RSET_FPR) != RSET_FPR && ra_hasreg(ir->r))
+ rset_set(drop, ir->r); /* WIN64 doesn't spill all FPRs. */
+ ra_evictset(as, drop);
+ asm_guardcc(as, CC_E);
+ emit_rr(as, XO_TEST, RID_RET, RID_RET); /* Test return status. */
+ args[0] = ir->op1; /* GCstr *str */
+ args[1] = ASMREF_TMP1; /* TValue *n */
+ asm_gencall(as, ci, args);
+ /* Store the result to the spill slot or temp slots. */
+ emit_rmro(as, XO_LEA, ra_releasetmp(as, ASMREF_TMP1)|REX_64,
+ RID_ESP, sps_scale(ir->s));
+}
+
+static void asm_tostr(ASMState *as, IRIns *ir)
+{
+ IRIns *irl = IR(ir->op1);
+ IRRef args[2];
+ args[0] = ASMREF_L;
+ as->gcsteps++;
+ if (irt_isnum(irl->t)) {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromnum];
+ args[1] = ASMREF_TMP1; /* const lua_Number * */
+ asm_setupresult(as, ir, ci); /* GCstr * */
+ asm_gencall(as, ci, args);
+ emit_rmro(as, XO_LEA, ra_releasetmp(as, ASMREF_TMP1)|REX_64,
+ RID_ESP, ra_spill(as, irl));
+ } else {
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_str_fromint];
+ args[1] = ir->op1; /* int32_t k */
+ asm_setupresult(as, ir, ci); /* GCstr * */
+ asm_gencall(as, ci, args);
+ }
+}
+
+/* -- Memory references --------------------------------------------------- */
+
+static void asm_aref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ asm_fusearef(as, ir, RSET_GPR);
+ if (!(as->mrm.idx == RID_NONE && as->mrm.ofs == 0))
+ emit_mrm(as, XO_LEA, dest, RID_MRM);
+ else if (as->mrm.base != dest)
+ emit_rr(as, XO_MOV, dest, as->mrm.base);
+}
+
+/* Merge NE(HREF, niltv) check. */
+static MCode *merge_href_niltv(ASMState *as, IRIns *ir)
+{
+ /* Assumes nothing else generates NE of HREF. */
+ if ((ir[1].o == IR_NE || ir[1].o == IR_EQ) && ir[1].op1 == as->curins &&
+ ra_hasreg(ir->r)) {
+ MCode *p = as->mcp;
+ p += (LJ_64 && *p != XI_ARITHi) ? 7+6 : 6+6;
+ /* Ensure no loop branch inversion happened. */
+ if (p[-6] == 0x0f && p[-5] == XI_JCCn+(CC_NE^(ir[1].o & 1))) {
+ as->mcp = p; /* Kill cmp reg, imm32 + jz exit. */
+ return p + *(int32_t *)(p-4); /* Return exit address. */
+ }
+ }
+ return NULL;
+}
+
+/* Inlined hash lookup. Specialized for key type and for const keys.
+** The equivalent C code is:
+** Node *n = hashkey(t, key);
+** do {
+** if (lj_obj_equal(&n->key, key)) return &n->val;
+** } while ((n = nextnode(n)));
+** return niltv(L);
+*/
+static void asm_href(ASMState *as, IRIns *ir)
+{
+ MCode *nilexit = merge_href_niltv(as, ir); /* Do this before any restores. */
+ RegSet allow = RSET_GPR;
+ Reg dest = ra_dest(as, ir, allow);
+ Reg tab = ra_alloc1(as, ir->op1, rset_clear(allow, dest));
+ Reg key = RID_NONE, tmp = RID_NONE;
+ IRIns *irkey = IR(ir->op2);
+ int isk = irref_isk(ir->op2);
+ IRType1 kt = irkey->t;
+ uint32_t khash;
+ MCLabel l_end, l_loop, l_next;
+
+ if (!isk) {
+ rset_clear(allow, tab);
+ key = ra_alloc1(as, ir->op2, irt_isnum(kt) ? RSET_FPR : allow);
+ if (!irt_isstr(kt))
+ tmp = ra_scratch(as, rset_exclude(allow, key));
+ }
+
+ /* Key not found in chain: jump to exit (if merged with NE) or load niltv. */
+ l_end = emit_label(as);
+ if (nilexit && ir[1].o == IR_NE) {
+ emit_jcc(as, CC_E, nilexit); /* XI_JMP is not found by lj_asm_patchexit. */
+ nilexit = NULL;
+ } else {
+ emit_loada(as, dest, niltvg(J2G(as->J)));
+ }
+
+ /* Follow hash chain until the end. */
+ l_loop = emit_sjcc_label(as, CC_NZ);
+ emit_rr(as, XO_TEST, dest, dest);
+ emit_rmro(as, XO_MOV, dest, dest, offsetof(Node, next));
+ l_next = emit_label(as);
+
+ /* Type and value comparison. */
+ if (nilexit)
+ emit_jcc(as, CC_E, nilexit);
+ else
+ emit_sjcc(as, CC_E, l_end);
+ if (irt_isnum(kt)) {
+ if (isk) {
+ /* Assumes -0.0 is already canonicalized to +0.0. */
+ emit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.u32.lo),
+ (int32_t)ir_knum(irkey)->u32.lo);
+ emit_sjcc(as, CC_NE, l_next);
+ emit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.u32.hi),
+ (int32_t)ir_knum(irkey)->u32.hi);
+ } else {
+ emit_sjcc(as, CC_P, l_next);
+ emit_rmro(as, XO_UCOMISD, key, dest, offsetof(Node, key.n));
+ emit_sjcc(as, CC_AE, l_next);
+ /* The type check avoids NaN penalties and complaints from Valgrind. */
+#if LJ_64
+ emit_u32(as, LJ_TISNUM);
+ emit_rmro(as, XO_ARITHi, XOg_CMP, dest, offsetof(Node, key.it));
+#else
+ emit_i8(as, LJ_TISNUM);
+ emit_rmro(as, XO_ARITHi8, XOg_CMP, dest, offsetof(Node, key.it));
+#endif
+ }
+#if LJ_64
+ } else if (irt_islightud(kt)) {
+ emit_rmro(as, XO_CMP, key|REX_64, dest, offsetof(Node, key.u64));
+#endif
+ } else {
+ if (!irt_ispri(kt)) {
+ lua_assert(irt_isaddr(kt));
+ if (isk)
+ emit_gmroi(as, XG_ARITHi(XOg_CMP), dest, offsetof(Node, key.gcr),
+ ptr2addr(ir_kgc(irkey)));
+ else
+ emit_rmro(as, XO_CMP, key, dest, offsetof(Node, key.gcr));
+ emit_sjcc(as, CC_NE, l_next);
+ }
+ lua_assert(!irt_isnil(kt));
+ emit_i8(as, irt_toitype(kt));
+ emit_rmro(as, XO_ARITHi8, XOg_CMP, dest, offsetof(Node, key.it));
+ }
+ emit_sfixup(as, l_loop);
+ checkmclim(as);
+
+ /* Load main position relative to tab->node into dest. */
+ khash = isk ? ir_khash(irkey) : 1;
+ if (khash == 0) {
+ emit_rmro(as, XO_MOV, dest, tab, offsetof(GCtab, node));
+ } else {
+ emit_rmro(as, XO_ARITH(XOg_ADD), dest, tab, offsetof(GCtab, node));
+ if ((as->flags & JIT_F_PREFER_IMUL)) {
+ emit_i8(as, sizeof(Node));
+ emit_rr(as, XO_IMULi8, dest, dest);
+ } else {
+ emit_shifti(as, XOg_SHL, dest, 3);
+ emit_rmrxo(as, XO_LEA, dest, dest, dest, XM_SCALE2, 0);
+ }
+ if (isk) {
+ emit_gri(as, XG_ARITHi(XOg_AND), dest, (int32_t)khash);
+ emit_rmro(as, XO_MOV, dest, tab, offsetof(GCtab, hmask));
+ } else if (irt_isstr(kt)) {
+ emit_rmro(as, XO_ARITH(XOg_AND), dest, key, offsetof(GCstr, hash));
+ emit_rmro(as, XO_MOV, dest, tab, offsetof(GCtab, hmask));
+ } else { /* Must match with hashrot() in lj_tab.c. */
+ emit_rmro(as, XO_ARITH(XOg_AND), dest, tab, offsetof(GCtab, hmask));
+ emit_rr(as, XO_ARITH(XOg_SUB), dest, tmp);
+ emit_shifti(as, XOg_ROL, tmp, HASH_ROT3);
+ emit_rr(as, XO_ARITH(XOg_XOR), dest, tmp);
+ emit_shifti(as, XOg_ROL, dest, HASH_ROT2);
+ emit_rr(as, XO_ARITH(XOg_SUB), tmp, dest);
+ emit_shifti(as, XOg_ROL, dest, HASH_ROT1);
+ emit_rr(as, XO_ARITH(XOg_XOR), tmp, dest);
+ if (irt_isnum(kt)) {
+ emit_rr(as, XO_ARITH(XOg_ADD), dest, dest);
+#if LJ_64
+ emit_shifti(as, XOg_SHR|REX_64, dest, 32);
+ emit_rr(as, XO_MOV, tmp, dest);
+ emit_rr(as, XO_MOVDto, key|REX_64, dest);
+#else
+ emit_rmro(as, XO_MOV, dest, RID_ESP, ra_spill(as, irkey)+4);
+ emit_rr(as, XO_MOVDto, key, tmp);
+#endif
+ } else {
+ emit_rr(as, XO_MOV, tmp, key);
+ emit_rmro(as, XO_LEA, dest, key, HASH_BIAS);
+ }
+ }
+ }
+}
+
+static void asm_hrefk(ASMState *as, IRIns *ir)
+{
+ IRIns *kslot = IR(ir->op2);
+ IRIns *irkey = IR(kslot->op1);
+ int32_t ofs = (int32_t)(kslot->op2 * sizeof(Node));
+ Reg dest = ra_used(ir) ? ra_dest(as, ir, RSET_GPR) : RID_NONE;
+ Reg node = ra_alloc1(as, ir->op1, RSET_GPR);
+#if !LJ_64
+ MCLabel l_exit;
+#endif
+ lua_assert(ofs % sizeof(Node) == 0);
+ if (ra_hasreg(dest)) {
+ if (ofs != 0) {
+ if (dest == node && !(as->flags & JIT_F_LEA_AGU))
+ emit_gri(as, XG_ARITHi(XOg_ADD), dest, ofs);
+ else
+ emit_rmro(as, XO_LEA, dest, node, ofs);
+ } else if (dest != node) {
+ emit_rr(as, XO_MOV, dest, node);
+ }
+ }
+ asm_guardcc(as, CC_NE);
+#if LJ_64
+ if (!irt_ispri(irkey->t)) {
+ Reg key = ra_scratch(as, rset_exclude(RSET_GPR, node));
+ emit_rmro(as, XO_CMP, key|REX_64, node,
+ ofs + (int32_t)offsetof(Node, key.u64));
+ lua_assert(irt_isnum(irkey->t) || irt_isgcv(irkey->t));
+ /* Assumes -0.0 is already canonicalized to +0.0. */
+ emit_loadu64(as, key, irt_isnum(irkey->t) ? ir_knum(irkey)->u64 :
+ ((uint64_t)irt_toitype(irkey->t) << 32) |
+ (uint64_t)(uint32_t)ptr2addr(ir_kgc(irkey)));
+ } else {
+ lua_assert(!irt_isnil(irkey->t));
+ emit_i8(as, irt_toitype(irkey->t));
+ emit_rmro(as, XO_ARITHi8, XOg_CMP, node,
+ ofs + (int32_t)offsetof(Node, key.it));
+ }
+#else
+ l_exit = emit_label(as);
+ if (irt_isnum(irkey->t)) {
+ /* Assumes -0.0 is already canonicalized to +0.0. */
+ emit_gmroi(as, XG_ARITHi(XOg_CMP), node,
+ ofs + (int32_t)offsetof(Node, key.u32.lo),
+ (int32_t)ir_knum(irkey)->u32.lo);
+ emit_sjcc(as, CC_NE, l_exit);
+ emit_gmroi(as, XG_ARITHi(XOg_CMP), node,
+ ofs + (int32_t)offsetof(Node, key.u32.hi),
+ (int32_t)ir_knum(irkey)->u32.hi);
+ } else {
+ if (!irt_ispri(irkey->t)) {
+ lua_assert(irt_isgcv(irkey->t));
+ emit_gmroi(as, XG_ARITHi(XOg_CMP), node,
+ ofs + (int32_t)offsetof(Node, key.gcr),
+ ptr2addr(ir_kgc(irkey)));
+ emit_sjcc(as, CC_NE, l_exit);
+ }
+ lua_assert(!irt_isnil(irkey->t));
+ emit_i8(as, irt_toitype(irkey->t));
+ emit_rmro(as, XO_ARITHi8, XOg_CMP, node,
+ ofs + (int32_t)offsetof(Node, key.it));
+ }
+#endif
+}
+
+static void asm_newref(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_tab_newkey];
+ IRRef args[3];
+ IRIns *irkey;
+ Reg tmp;
+ if (ir->r == RID_SINK)
+ return;
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ir->op1; /* GCtab *t */
+ args[2] = ASMREF_TMP1; /* cTValue *key */
+ asm_setupresult(as, ir, ci); /* TValue * */
+ asm_gencall(as, ci, args);
+ tmp = ra_releasetmp(as, ASMREF_TMP1);
+ irkey = IR(ir->op2);
+ if (irt_isnum(irkey->t)) {
+ /* For numbers use the constant itself or a spill slot as a TValue. */
+ if (irref_isk(ir->op2))
+ emit_loada(as, tmp, ir_knum(irkey));
+ else
+ emit_rmro(as, XO_LEA, tmp|REX_64, RID_ESP, ra_spill(as, irkey));
+ } else {
+ /* Otherwise use g->tmptv to hold the TValue. */
+ if (!irref_isk(ir->op2)) {
+ Reg src = ra_alloc1(as, ir->op2, rset_exclude(RSET_GPR, tmp));
+ emit_movtomro(as, REX_64IR(irkey, src), tmp, 0);
+ } else if (!irt_ispri(irkey->t)) {
+ emit_movmroi(as, tmp, 0, irkey->i);
+ }
+ if (!(LJ_64 && irt_islightud(irkey->t)))
+ emit_movmroi(as, tmp, 4, irt_toitype(irkey->t));
+ emit_loada(as, tmp, &J2G(as->J)->tmptv);
+ }
+}
+
+static void asm_uref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (irref_isk(ir->op1)) {
+ GCfunc *fn = ir_kfunc(IR(ir->op1));
+ MRef *v = &gcref(fn->l.uvptr[(ir->op2 >> 8)])->uv.v;
+ emit_rma(as, XO_MOV, dest, v);
+ } else {
+ Reg uv = ra_scratch(as, RSET_GPR);
+ Reg func = ra_alloc1(as, ir->op1, RSET_GPR);
+ if (ir->o == IR_UREFC) {
+ emit_rmro(as, XO_LEA, dest, uv, offsetof(GCupval, tv));
+ asm_guardcc(as, CC_NE);
+ emit_i8(as, 1);
+ emit_rmro(as, XO_ARITHib, XOg_CMP, uv, offsetof(GCupval, closed));
+ } else {
+ emit_rmro(as, XO_MOV, dest, uv, offsetof(GCupval, v));
+ }
+ emit_rmro(as, XO_MOV, uv, func,
+ (int32_t)offsetof(GCfuncL, uvptr) + 4*(int32_t)(ir->op2 >> 8));
+ }
+}
+
+static void asm_fref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ asm_fusefref(as, ir, RSET_GPR);
+ emit_mrm(as, XO_LEA, dest, RID_MRM);
+}
+
+static void asm_strref(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ asm_fusestrref(as, ir, RSET_GPR);
+ if (as->mrm.base == RID_NONE)
+ emit_loadi(as, dest, as->mrm.ofs);
+ else if (as->mrm.base == dest && as->mrm.idx == RID_NONE)
+ emit_gri(as, XG_ARITHi(XOg_ADD), dest, as->mrm.ofs);
+ else
+ emit_mrm(as, XO_LEA, dest, RID_MRM);
+}
+
+/* -- Loads and stores ---------------------------------------------------- */
+
+static void asm_fxload(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR);
+ x86Op xo;
+ if (ir->o == IR_FLOAD)
+ asm_fusefref(as, ir, RSET_GPR);
+ else
+ asm_fusexref(as, ir->op1, RSET_GPR);
+ /* ir->op2 is ignored -- unaligned loads are ok on x86. */
+ switch (irt_type(ir->t)) {
+ case IRT_I8: xo = XO_MOVSXb; break;
+ case IRT_U8: xo = XO_MOVZXb; break;
+ case IRT_I16: xo = XO_MOVSXw; break;
+ case IRT_U16: xo = XO_MOVZXw; break;
+ case IRT_NUM: xo = XMM_MOVRM(as); break;
+ case IRT_FLOAT: xo = XO_MOVSS; break;
+ default:
+ if (LJ_64 && irt_is64(ir->t))
+ dest |= REX_64;
+ else
+ lua_assert(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t));
+ xo = XO_MOV;
+ break;
+ }
+ emit_mrm(as, xo, dest, RID_MRM);
+}
+
+static void asm_fxstore(ASMState *as, IRIns *ir)
+{
+ RegSet allow = RSET_GPR;
+ Reg src = RID_NONE, osrc = RID_NONE;
+ int32_t k = 0;
+ if (ir->r == RID_SINK)
+ return;
+ /* The IRT_I16/IRT_U16 stores should never be simplified for constant
+ ** values since mov word [mem], imm16 has a length-changing prefix.
+ */
+ if (irt_isi16(ir->t) || irt_isu16(ir->t) || irt_isfp(ir->t) ||
+ !asm_isk32(as, ir->op2, &k)) {
+ RegSet allow8 = irt_isfp(ir->t) ? RSET_FPR :
+ (irt_isi8(ir->t) || irt_isu8(ir->t)) ? RSET_GPR8 : RSET_GPR;
+ src = osrc = ra_alloc1(as, ir->op2, allow8);
+ if (!LJ_64 && !rset_test(allow8, src)) { /* Already in wrong register. */
+ rset_clear(allow, osrc);
+ src = ra_scratch(as, allow8);
+ }
+ rset_clear(allow, src);
+ }
+ if (ir->o == IR_FSTORE) {
+ asm_fusefref(as, IR(ir->op1), allow);
+ } else {
+ asm_fusexref(as, ir->op1, allow);
+ if (LJ_32 && ir->o == IR_HIOP) as->mrm.ofs += 4;
+ }
+ if (ra_hasreg(src)) {
+ x86Op xo;
+ switch (irt_type(ir->t)) {
+ case IRT_I8: case IRT_U8: xo = XO_MOVtob; src |= FORCE_REX; break;
+ case IRT_I16: case IRT_U16: xo = XO_MOVtow; break;
+ case IRT_NUM: xo = XO_MOVSDto; break;
+ case IRT_FLOAT: xo = XO_MOVSSto; break;
+#if LJ_64
+ case IRT_LIGHTUD: lua_assert(0); /* NYI: mask 64 bit lightuserdata. */
+#endif
+ default:
+ if (LJ_64 && irt_is64(ir->t))
+ src |= REX_64;
+ else
+ lua_assert(irt_isint(ir->t) || irt_isu32(ir->t) || irt_isaddr(ir->t));
+ xo = XO_MOVto;
+ break;
+ }
+ emit_mrm(as, xo, src, RID_MRM);
+ if (!LJ_64 && src != osrc) {
+ ra_noweak(as, osrc);
+ emit_rr(as, XO_MOV, src, osrc);
+ }
+ } else {
+ if (irt_isi8(ir->t) || irt_isu8(ir->t)) {
+ emit_i8(as, k);
+ emit_mrm(as, XO_MOVmib, 0, RID_MRM);
+ } else {
+ lua_assert(irt_is64(ir->t) || irt_isint(ir->t) || irt_isu32(ir->t) ||
+ irt_isaddr(ir->t));
+ emit_i32(as, k);
+ emit_mrm(as, XO_MOVmi, REX_64IR(ir, 0), RID_MRM);
+ }
+ }
+}
+
+#if LJ_64
+static Reg asm_load_lightud64(ASMState *as, IRIns *ir, int typecheck)
+{
+ if (ra_used(ir) || typecheck) {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ if (typecheck) {
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, dest));
+ asm_guardcc(as, CC_NE);
+ emit_i8(as, -2);
+ emit_rr(as, XO_ARITHi8, XOg_CMP, tmp);
+ emit_shifti(as, XOg_SAR|REX_64, tmp, 47);
+ emit_rr(as, XO_MOV, tmp|REX_64, dest);
+ }
+ return dest;
+ } else {
+ return RID_NONE;
+ }
+}
+#endif
+
+static void asm_ahuvload(ASMState *as, IRIns *ir)
+{
+ lua_assert(irt_isnum(ir->t) || irt_ispri(ir->t) || irt_isaddr(ir->t) ||
+ (LJ_DUALNUM && irt_isint(ir->t)));
+#if LJ_64
+ if (irt_islightud(ir->t)) {
+ Reg dest = asm_load_lightud64(as, ir, 1);
+ if (ra_hasreg(dest)) {
+ asm_fuseahuref(as, ir->op1, RSET_GPR);
+ emit_mrm(as, XO_MOV, dest|REX_64, RID_MRM);
+ }
+ return;
+ } else
+#endif
+ if (ra_used(ir)) {
+ RegSet allow = irt_isnum(ir->t) ? RSET_FPR : RSET_GPR;
+ Reg dest = ra_dest(as, ir, allow);
+ asm_fuseahuref(as, ir->op1, RSET_GPR);
+ emit_mrm(as, dest < RID_MAX_GPR ? XO_MOV : XMM_MOVRM(as), dest, RID_MRM);
+ } else {
+ asm_fuseahuref(as, ir->op1, RSET_GPR);
+ }
+ /* Always do the type check, even if the load result is unused. */
+ as->mrm.ofs += 4;
+ asm_guardcc(as, irt_isnum(ir->t) ? CC_AE : CC_NE);
+ if (LJ_64 && irt_type(ir->t) >= IRT_NUM) {
+ lua_assert(irt_isinteger(ir->t) || irt_isnum(ir->t));
+ emit_u32(as, LJ_TISNUM);
+ emit_mrm(as, XO_ARITHi, XOg_CMP, RID_MRM);
+ } else {
+ emit_i8(as, irt_toitype(ir->t));
+ emit_mrm(as, XO_ARITHi8, XOg_CMP, RID_MRM);
+ }
+}
+
+static void asm_ahustore(ASMState *as, IRIns *ir)
+{
+ if (ir->r == RID_SINK)
+ return;
+ if (irt_isnum(ir->t)) {
+ Reg src = ra_alloc1(as, ir->op2, RSET_FPR);
+ asm_fuseahuref(as, ir->op1, RSET_GPR);
+ emit_mrm(as, XO_MOVSDto, src, RID_MRM);
+#if LJ_64
+ } else if (irt_islightud(ir->t)) {
+ Reg src = ra_alloc1(as, ir->op2, RSET_GPR);
+ asm_fuseahuref(as, ir->op1, rset_exclude(RSET_GPR, src));
+ emit_mrm(as, XO_MOVto, src|REX_64, RID_MRM);
+#endif
+ } else {
+ IRIns *irr = IR(ir->op2);
+ RegSet allow = RSET_GPR;
+ Reg src = RID_NONE;
+ if (!irref_isk(ir->op2)) {
+ src = ra_alloc1(as, ir->op2, allow);
+ rset_clear(allow, src);
+ }
+ asm_fuseahuref(as, ir->op1, allow);
+ if (ra_hasreg(src)) {
+ emit_mrm(as, XO_MOVto, src, RID_MRM);
+ } else if (!irt_ispri(irr->t)) {
+ lua_assert(irt_isaddr(ir->t) || (LJ_DUALNUM && irt_isinteger(ir->t)));
+ emit_i32(as, irr->i);
+ emit_mrm(as, XO_MOVmi, 0, RID_MRM);
+ }
+ as->mrm.ofs += 4;
+ emit_i32(as, (int32_t)irt_toitype(ir->t));
+ emit_mrm(as, XO_MOVmi, 0, RID_MRM);
+ }
+}
+
+static void asm_sload(ASMState *as, IRIns *ir)
+{
+ int32_t ofs = 8*((int32_t)ir->op1-1) + ((ir->op2 & IRSLOAD_FRAME) ? 4 : 0);
+ IRType1 t = ir->t;
+ Reg base;
+ lua_assert(!(ir->op2 & IRSLOAD_PARENT)); /* Handled by asm_head_side(). */
+ lua_assert(irt_isguard(t) || !(ir->op2 & IRSLOAD_TYPECHECK));
+ lua_assert(LJ_DUALNUM ||
+ !irt_isint(t) || (ir->op2 & (IRSLOAD_CONVERT|IRSLOAD_FRAME)));
+ if ((ir->op2 & IRSLOAD_CONVERT) && irt_isguard(t) && irt_isint(t)) {
+ Reg left = ra_scratch(as, RSET_FPR);
+ asm_tointg(as, ir, left); /* Frees dest reg. Do this before base alloc. */
+ base = ra_alloc1(as, REF_BASE, RSET_GPR);
+ emit_rmro(as, XMM_MOVRM(as), left, base, ofs);
+ t.irt = IRT_NUM; /* Continue with a regular number type check. */
+#if LJ_64
+ } else if (irt_islightud(t)) {
+ Reg dest = asm_load_lightud64(as, ir, (ir->op2 & IRSLOAD_TYPECHECK));
+ if (ra_hasreg(dest)) {
+ base = ra_alloc1(as, REF_BASE, RSET_GPR);
+ emit_rmro(as, XO_MOV, dest|REX_64, base, ofs);
+ }
+ return;
+#endif
+ } else if (ra_used(ir)) {
+ RegSet allow = irt_isnum(t) ? RSET_FPR : RSET_GPR;
+ Reg dest = ra_dest(as, ir, allow);
+ base = ra_alloc1(as, REF_BASE, RSET_GPR);
+ lua_assert(irt_isnum(t) || irt_isint(t) || irt_isaddr(t));
+ if ((ir->op2 & IRSLOAD_CONVERT)) {
+ t.irt = irt_isint(t) ? IRT_NUM : IRT_INT; /* Check for original type. */
+ emit_rmro(as, irt_isint(t) ? XO_CVTSI2SD : XO_CVTSD2SI, dest, base, ofs);
+ } else if (irt_isnum(t)) {
+ emit_rmro(as, XMM_MOVRM(as), dest, base, ofs);
+ } else {
+ emit_rmro(as, XO_MOV, dest, base, ofs);
+ }
+ } else {
+ if (!(ir->op2 & IRSLOAD_TYPECHECK))
+ return; /* No type check: avoid base alloc. */
+ base = ra_alloc1(as, REF_BASE, RSET_GPR);
+ }
+ if ((ir->op2 & IRSLOAD_TYPECHECK)) {
+ /* Need type check, even if the load result is unused. */
+ asm_guardcc(as, irt_isnum(t) ? CC_AE : CC_NE);
+ if (LJ_64 && irt_type(t) >= IRT_NUM) {
+ lua_assert(irt_isinteger(t) || irt_isnum(t));
+ emit_u32(as, LJ_TISNUM);
+ emit_rmro(as, XO_ARITHi, XOg_CMP, base, ofs+4);
+ } else {
+ emit_i8(as, irt_toitype(t));
+ emit_rmro(as, XO_ARITHi8, XOg_CMP, base, ofs+4);
+ }
+ }
+}
+
+/* -- Allocations --------------------------------------------------------- */
+
+#if LJ_HASFFI
+static void asm_cnew(ASMState *as, IRIns *ir)
+{
+ CTState *cts = ctype_ctsG(J2G(as->J));
+ CTypeID ctypeid = (CTypeID)IR(ir->op1)->i;
+ CTSize sz = (ir->o == IR_CNEWI || ir->op2 == REF_NIL) ?
+ lj_ctype_size(cts, ctypeid) : (CTSize)IR(ir->op2)->i;
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_mem_newgco];
+ IRRef args[2];
+ lua_assert(sz != CTSIZE_INVALID);
+
+ args[0] = ASMREF_L; /* lua_State *L */
+ args[1] = ASMREF_TMP1; /* MSize size */
+ as->gcsteps++;
+ asm_setupresult(as, ir, ci); /* GCcdata * */
+
+ /* Initialize immutable cdata object. */
+ if (ir->o == IR_CNEWI) {
+ RegSet allow = (RSET_GPR & ~RSET_SCRATCH);
+#if LJ_64
+ Reg r64 = sz == 8 ? REX_64 : 0;
+ if (irref_isk(ir->op2)) {
+ IRIns *irk = IR(ir->op2);
+ uint64_t k = irk->o == IR_KINT64 ? ir_k64(irk)->u64 :
+ (uint64_t)(uint32_t)irk->i;
+ if (sz == 4 || checki32((int64_t)k)) {
+ emit_i32(as, (int32_t)k);
+ emit_rmro(as, XO_MOVmi, r64, RID_RET, sizeof(GCcdata));
+ } else {
+ emit_movtomro(as, RID_ECX + r64, RID_RET, sizeof(GCcdata));
+ emit_loadu64(as, RID_ECX, k);
+ }
+ } else {
+ Reg r = ra_alloc1(as, ir->op2, allow);
+ emit_movtomro(as, r + r64, RID_RET, sizeof(GCcdata));
+ }
+#else
+ int32_t ofs = sizeof(GCcdata);
+ if (sz == 8) {
+ ofs += 4; ir++;
+ lua_assert(ir->o == IR_HIOP);
+ }
+ do {
+ if (irref_isk(ir->op2)) {
+ emit_movmroi(as, RID_RET, ofs, IR(ir->op2)->i);
+ } else {
+ Reg r = ra_alloc1(as, ir->op2, allow);
+ emit_movtomro(as, r, RID_RET, ofs);
+ rset_clear(allow, r);
+ }
+ if (ofs == sizeof(GCcdata)) break;
+ ofs -= 4; ir--;
+ } while (1);
+#endif
+ lua_assert(sz == 4 || sz == 8);
+ }
+
+ /* Combine initialization of marked, gct and ctypeid. */
+ emit_movtomro(as, RID_ECX, RID_RET, offsetof(GCcdata, marked));
+ emit_gri(as, XG_ARITHi(XOg_OR), RID_ECX,
+ (int32_t)((~LJ_TCDATA<<8)+(ctypeid<<16)));
+ emit_gri(as, XG_ARITHi(XOg_AND), RID_ECX, LJ_GC_WHITES);
+ emit_opgl(as, XO_MOVZXb, RID_ECX, gc.currentwhite);
+
+ asm_gencall(as, ci, args);
+ emit_loadi(as, ra_releasetmp(as, ASMREF_TMP1), (int32_t)(sz+sizeof(GCcdata)));
+}
+#else
+#define asm_cnew(as, ir) ((void)0)
+#endif
+
+/* -- Write barriers ------------------------------------------------------ */
+
+static void asm_tbar(ASMState *as, IRIns *ir)
+{
+ Reg tab = ra_alloc1(as, ir->op1, RSET_GPR);
+ Reg tmp = ra_scratch(as, rset_exclude(RSET_GPR, tab));
+ MCLabel l_end = emit_label(as);
+ emit_movtomro(as, tmp, tab, offsetof(GCtab, gclist));
+ emit_setgl(as, tab, gc.grayagain);
+ emit_getgl(as, tmp, gc.grayagain);
+ emit_i8(as, ~LJ_GC_BLACK);
+ emit_rmro(as, XO_ARITHib, XOg_AND, tab, offsetof(GCtab, marked));
+ emit_sjcc(as, CC_Z, l_end);
+ emit_i8(as, LJ_GC_BLACK);
+ emit_rmro(as, XO_GROUP3b, XOg_TEST, tab, offsetof(GCtab, marked));
+}
+
+static void asm_obar(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_barrieruv];
+ IRRef args[2];
+ MCLabel l_end;
+ Reg obj;
+ /* No need for other object barriers (yet). */
+ lua_assert(IR(ir->op1)->o == IR_UREFC);
+ ra_evictset(as, RSET_SCRATCH);
+ l_end = emit_label(as);
+ args[0] = ASMREF_TMP1; /* global_State *g */
+ args[1] = ir->op1; /* TValue *tv */
+ asm_gencall(as, ci, args);
+ emit_loada(as, ra_releasetmp(as, ASMREF_TMP1), J2G(as->J));
+ obj = IR(ir->op1)->r;
+ emit_sjcc(as, CC_Z, l_end);
+ emit_i8(as, LJ_GC_WHITES);
+ if (irref_isk(ir->op2)) {
+ GCobj *vp = ir_kgc(IR(ir->op2));
+ emit_rma(as, XO_GROUP3b, XOg_TEST, &vp->gch.marked);
+ } else {
+ Reg val = ra_alloc1(as, ir->op2, rset_exclude(RSET_SCRATCH&RSET_GPR, obj));
+ emit_rmro(as, XO_GROUP3b, XOg_TEST, val, (int32_t)offsetof(GChead, marked));
+ }
+ emit_sjcc(as, CC_Z, l_end);
+ emit_i8(as, LJ_GC_BLACK);
+ emit_rmro(as, XO_GROUP3b, XOg_TEST, obj,
+ (int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv));
+}
+
+/* -- FP/int arithmetic and logic operations ------------------------------ */
+
+/* Load reference onto x87 stack. Force a spill to memory if needed. */
+static void asm_x87load(ASMState *as, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ if (ir->o == IR_KNUM) {
+ cTValue *tv = ir_knum(ir);
+ if (tvispzero(tv)) /* Use fldz only for +0. */
+ emit_x87op(as, XI_FLDZ);
+ else if (tvispone(tv))
+ emit_x87op(as, XI_FLD1);
+ else
+ emit_rma(as, XO_FLDq, XOg_FLDq, tv);
+ } else if (ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT && !ra_used(ir) &&
+ !irref_isk(ir->op1) && mayfuse(as, ir->op1)) {
+ IRIns *iri = IR(ir->op1);
+ emit_rmro(as, XO_FILDd, XOg_FILDd, RID_ESP, ra_spill(as, iri));
+ } else {
+ emit_mrm(as, XO_FLDq, XOg_FLDq, asm_fuseload(as, ref, RSET_EMPTY));
+ }
+}
+
+/* Try to rejoin pow from EXP2, MUL and LOG2 (if still unsplit). */
+static int fpmjoin_pow(ASMState *as, IRIns *ir)
+{
+ IRIns *irp = IR(ir->op1);
+ if (irp == ir-1 && irp->o == IR_MUL && !ra_used(irp)) {
+ IRIns *irpp = IR(irp->op1);
+ if (irpp == ir-2 && irpp->o == IR_FPMATH &&
+ irpp->op2 == IRFPM_LOG2 && !ra_used(irpp)) {
+ /* The modified regs must match with the *.dasc implementation. */
+ RegSet drop = RSET_RANGE(RID_XMM0, RID_XMM2+1)|RID2RSET(RID_EAX);
+ IRIns *irx;
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ ra_evictset(as, drop);
+ ra_destreg(as, ir, RID_XMM0);
+ emit_call(as, lj_vm_pow_sse);
+ irx = IR(irpp->op1);
+ if (ra_noreg(irx->r) && ra_gethint(irx->r) == RID_XMM1)
+ irx->r = RID_INIT; /* Avoid allocating xmm1 for x. */
+ ra_left(as, RID_XMM0, irpp->op1);
+ ra_left(as, RID_XMM1, irp->op2);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static void asm_fpmath(ASMState *as, IRIns *ir)
+{
+ IRFPMathOp fpm = ir->o == IR_FPMATH ? (IRFPMathOp)ir->op2 : IRFPM_OTHER;
+ if (fpm == IRFPM_SQRT) {
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg left = asm_fuseload(as, ir->op1, RSET_FPR);
+ emit_mrm(as, XO_SQRTSD, dest, left);
+ } else if (fpm <= IRFPM_TRUNC) {
+ if (as->flags & JIT_F_SSE4_1) { /* SSE4.1 has a rounding instruction. */
+ Reg dest = ra_dest(as, ir, RSET_FPR);
+ Reg left = asm_fuseload(as, ir->op1, RSET_FPR);
+ /* ROUNDSD has a 4-byte opcode which doesn't fit in x86Op.
+ ** Let's pretend it's a 3-byte opcode, and compensate afterwards.
+ ** This is atrocious, but the alternatives are much worse.
+ */
+ /* Round down/up/trunc == 1001/1010/1011. */
+ emit_i8(as, 0x09 + fpm);
+ emit_mrm(as, XO_ROUNDSD, dest, left);
+ if (LJ_64 && as->mcp[1] != (MCode)(XO_ROUNDSD >> 16)) {
+ as->mcp[0] = as->mcp[1]; as->mcp[1] = 0x0f; /* Swap 0F and REX. */
+ }
+ *--as->mcp = 0x66; /* 1st byte of ROUNDSD opcode. */
+ } else { /* Call helper functions for SSE2 variant. */
+ /* The modified regs must match with the *.dasc implementation. */
+ RegSet drop = RSET_RANGE(RID_XMM0, RID_XMM3+1)|RID2RSET(RID_EAX);
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ ra_evictset(as, drop);
+ ra_destreg(as, ir, RID_XMM0);
+ emit_call(as, fpm == IRFPM_FLOOR ? lj_vm_floor_sse :
+ fpm == IRFPM_CEIL ? lj_vm_ceil_sse : lj_vm_trunc_sse);
+ ra_left(as, RID_XMM0, ir->op1);
+ }
+ } else if (fpm == IRFPM_EXP2 && fpmjoin_pow(as, ir)) {
+ /* Rejoined to pow(). */
+ } else { /* Handle x87 ops. */
+ int32_t ofs = sps_scale(ir->s); /* Use spill slot or temp slots. */
+ Reg dest = ir->r;
+ if (ra_hasreg(dest)) {
+ ra_free(as, dest);
+ ra_modified(as, dest);
+ emit_rmro(as, XMM_MOVRM(as), dest, RID_ESP, ofs);
+ }
+ emit_rmro(as, XO_FSTPq, XOg_FSTPq, RID_ESP, ofs);
+ switch (fpm) { /* st0 = lj_vm_*(st0) */
+ case IRFPM_EXP: emit_call(as, lj_vm_exp_x87); break;
+ case IRFPM_EXP2: emit_call(as, lj_vm_exp2_x87); break;
+ case IRFPM_SIN: emit_x87op(as, XI_FSIN); break;
+ case IRFPM_COS: emit_x87op(as, XI_FCOS); break;
+ case IRFPM_TAN: emit_x87op(as, XI_FPOP); emit_x87op(as, XI_FPTAN); break;
+ case IRFPM_LOG: case IRFPM_LOG2: case IRFPM_LOG10:
+ /* Note: the use of fyl2xp1 would be pointless here. When computing
+ ** log(1.0+eps) the precision is already lost after 1.0 is added.
+ ** Subtracting 1.0 won't recover it. OTOH math.log1p would make sense.
+ */
+ emit_x87op(as, XI_FYL2X); break;
+ case IRFPM_OTHER:
+ switch (ir->o) {
+ case IR_ATAN2:
+ emit_x87op(as, XI_FPATAN); asm_x87load(as, ir->op2); break;
+ case IR_LDEXP:
+ emit_x87op(as, XI_FPOP1); emit_x87op(as, XI_FSCALE); break;
+ default: lua_assert(0); break;
+ }
+ break;
+ default: lua_assert(0); break;
+ }
+ asm_x87load(as, ir->op1);
+ switch (fpm) {
+ case IRFPM_LOG: emit_x87op(as, XI_FLDLN2); break;
+ case IRFPM_LOG2: emit_x87op(as, XI_FLD1); break;
+ case IRFPM_LOG10: emit_x87op(as, XI_FLDLG2); break;
+ case IRFPM_OTHER:
+ if (ir->o == IR_LDEXP) asm_x87load(as, ir->op2);
+ break;
+ default: break;
+ }
+ }
+}
+
+static void asm_fppowi(ASMState *as, IRIns *ir)
+{
+ /* The modified regs must match with the *.dasc implementation. */
+ RegSet drop = RSET_RANGE(RID_XMM0, RID_XMM1+1)|RID2RSET(RID_EAX);
+ if (ra_hasreg(ir->r))
+ rset_clear(drop, ir->r); /* Dest reg handled below. */
+ ra_evictset(as, drop);
+ ra_destreg(as, ir, RID_XMM0);
+ emit_call(as, lj_vm_powi_sse);
+ ra_left(as, RID_XMM0, ir->op1);
+ ra_left(as, RID_EAX, ir->op2);
+}
+
+#if LJ_64 && LJ_HASFFI
+static void asm_arith64(ASMState *as, IRIns *ir, IRCallID id)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[id];
+ IRRef args[2];
+ args[0] = ir->op1;
+ args[1] = ir->op2;
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+#endif
+
+static void asm_intmod(ASMState *as, IRIns *ir)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_vm_modi];
+ IRRef args[2];
+ args[0] = ir->op1;
+ args[1] = ir->op2;
+ asm_setupresult(as, ir, ci);
+ asm_gencall(as, ci, args);
+}
+
+static int asm_swapops(ASMState *as, IRIns *ir)
+{
+ IRIns *irl = IR(ir->op1);
+ IRIns *irr = IR(ir->op2);
+ lua_assert(ra_noreg(irr->r));
+ if (!irm_iscomm(lj_ir_mode[ir->o]))
+ return 0; /* Can't swap non-commutative operations. */
+ if (irref_isk(ir->op2))
+ return 0; /* Don't swap constants to the left. */
+ if (ra_hasreg(irl->r))
+ return 1; /* Swap if left already has a register. */
+ if (ra_samehint(ir->r, irr->r))
+ return 1; /* Swap if dest and right have matching hints. */
+ if (as->curins > as->loopref) { /* In variant part? */
+ if (ir->op2 < as->loopref && !irt_isphi(irr->t))
+ return 0; /* Keep invariants on the right. */
+ if (ir->op1 < as->loopref && !irt_isphi(irl->t))
+ return 1; /* Swap invariants to the right. */
+ }
+ if (opisfusableload(irl->o))
+ return 1; /* Swap fusable loads to the right. */
+ return 0; /* Otherwise don't swap. */
+}
+
+static void asm_fparith(ASMState *as, IRIns *ir, x86Op xo)
+{
+ IRRef lref = ir->op1;
+ IRRef rref = ir->op2;
+ RegSet allow = RSET_FPR;
+ Reg dest;
+ Reg right = IR(rref)->r;
+ if (ra_hasreg(right)) {
+ rset_clear(allow, right);
+ ra_noweak(as, right);
+ }
+ dest = ra_dest(as, ir, allow);
+ if (lref == rref) {
+ right = dest;
+ } else if (ra_noreg(right)) {
+ if (asm_swapops(as, ir)) {
+ IRRef tmp = lref; lref = rref; rref = tmp;
+ }
+ right = asm_fuseload(as, rref, rset_clear(allow, dest));
+ }
+ emit_mrm(as, xo, dest, right);
+ ra_left(as, dest, lref);
+}
+
+static void asm_intarith(ASMState *as, IRIns *ir, x86Arith xa)
+{
+ IRRef lref = ir->op1;
+ IRRef rref = ir->op2;
+ RegSet allow = RSET_GPR;
+ Reg dest, right;
+ int32_t k = 0;
+ if (as->flagmcp == as->mcp) { /* Drop test r,r instruction. */
+ MCode *p = as->mcp + ((LJ_64 && *as->mcp < XI_TESTb) ? 3 : 2);
+ if ((p[1] & 15) < 14) {
+ if ((p[1] & 15) >= 12) p[1] -= 4; /* L <->S, NL <-> NS */
+ as->flagmcp = NULL;
+ as->mcp = p;
+ } /* else: cannot transform LE/NLE to cc without use of OF. */
+ }
+ right = IR(rref)->r;
+ if (ra_hasreg(right)) {
+ rset_clear(allow, right);
+ ra_noweak(as, right);
+ }
+ dest = ra_dest(as, ir, allow);
+ if (lref == rref) {
+ right = dest;
+ } else if (ra_noreg(right) && !asm_isk32(as, rref, &k)) {
+ if (asm_swapops(as, ir)) {
+ IRRef tmp = lref; lref = rref; rref = tmp;
+ }
+ right = asm_fuseloadm(as, rref, rset_clear(allow, dest), irt_is64(ir->t));
+ }
+ if (irt_isguard(ir->t)) /* For IR_ADDOV etc. */
+ asm_guardcc(as, CC_O);
+ if (xa != XOg_X_IMUL) {
+ if (ra_hasreg(right))
+ emit_mrm(as, XO_ARITH(xa), REX_64IR(ir, dest), right);
+ else
+ emit_gri(as, XG_ARITHi(xa), REX_64IR(ir, dest), k);
+ } else if (ra_hasreg(right)) { /* IMUL r, mrm. */
+ emit_mrm(as, XO_IMUL, REX_64IR(ir, dest), right);
+ } else { /* IMUL r, r, k. */
+ /* NYI: use lea/shl/add/sub (FOLD only does 2^k) depending on CPU. */
+ Reg left = asm_fuseloadm(as, lref, RSET_GPR, irt_is64(ir->t));
+ x86Op xo;
+ if (checki8(k)) { emit_i8(as, k); xo = XO_IMULi8;
+ } else { emit_i32(as, k); xo = XO_IMULi; }
+ emit_mrm(as, xo, REX_64IR(ir, dest), left);
+ return;
+ }
+ ra_left(as, dest, lref);
+}
+
+/* LEA is really a 4-operand ADD with an independent destination register,
+** up to two source registers and an immediate. One register can be scaled
+** by 1, 2, 4 or 8. This can be used to avoid moves or to fuse several
+** instructions.
+**
+** Currently only a few common cases are supported:
+** - 3-operand ADD: y = a+b; y = a+k with a and b already allocated
+** - Left ADD fusion: y = (a+b)+k; y = (a+k)+b
+** - Right ADD fusion: y = a+(b+k)
+** The ommited variants have already been reduced by FOLD.
+**
+** There are more fusion opportunities, like gathering shifts or joining
+** common references. But these are probably not worth the trouble, since
+** array indexing is not decomposed and already makes use of all fields
+** of the ModRM operand.
+*/
+static int asm_lea(ASMState *as, IRIns *ir)
+{
+ IRIns *irl = IR(ir->op1);
+ IRIns *irr = IR(ir->op2);
+ RegSet allow = RSET_GPR;
+ Reg dest;
+ as->mrm.base = as->mrm.idx = RID_NONE;
+ as->mrm.scale = XM_SCALE1;
+ as->mrm.ofs = 0;
+ if (ra_hasreg(irl->r)) {
+ rset_clear(allow, irl->r);
+ ra_noweak(as, irl->r);
+ as->mrm.base = irl->r;
+ if (irref_isk(ir->op2) || ra_hasreg(irr->r)) {
+ /* The PHI renaming logic does a better job in some cases. */
+ if (ra_hasreg(ir->r) &&
+ ((irt_isphi(irl->t) && as->phireg[ir->r] == ir->op1) ||
+ (irt_isphi(irr->t) && as->phireg[ir->r] == ir->op2)))
+ return 0;
+ if (irref_isk(ir->op2)) {
+ as->mrm.ofs = irr->i;
+ } else {
+ rset_clear(allow, irr->r);
+ ra_noweak(as, irr->r);
+ as->mrm.idx = irr->r;
+ }
+ } else if (irr->o == IR_ADD && mayfuse(as, ir->op2) &&
+ irref_isk(irr->op2)) {
+ Reg idx = ra_alloc1(as, irr->op1, allow);
+ rset_clear(allow, idx);
+ as->mrm.idx = (uint8_t)idx;
+ as->mrm.ofs = IR(irr->op2)->i;
+ } else {
+ return 0;
+ }
+ } else if (ir->op1 != ir->op2 && irl->o == IR_ADD && mayfuse(as, ir->op1) &&
+ (irref_isk(ir->op2) || irref_isk(irl->op2))) {
+ Reg idx, base = ra_alloc1(as, irl->op1, allow);
+ rset_clear(allow, base);
+ as->mrm.base = (uint8_t)base;
+ if (irref_isk(ir->op2)) {
+ as->mrm.ofs = irr->i;
+ idx = ra_alloc1(as, irl->op2, allow);
+ } else {
+ as->mrm.ofs = IR(irl->op2)->i;
+ idx = ra_alloc1(as, ir->op2, allow);
+ }
+ rset_clear(allow, idx);
+ as->mrm.idx = (uint8_t)idx;
+ } else {
+ return 0;
+ }
+ dest = ra_dest(as, ir, allow);
+ emit_mrm(as, XO_LEA, dest, RID_MRM);
+ return 1; /* Success. */
+}
+
+static void asm_add(ASMState *as, IRIns *ir)
+{
+ if (irt_isnum(ir->t))
+ asm_fparith(as, ir, XO_ADDSD);
+ else if ((as->flags & JIT_F_LEA_AGU) || as->flagmcp == as->mcp ||
+ irt_is64(ir->t) || !asm_lea(as, ir))
+ asm_intarith(as, ir, XOg_ADD);
+}
+
+static void asm_neg_not(ASMState *as, IRIns *ir, x86Group3 xg)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ emit_rr(as, XO_GROUP3, REX_64IR(ir, xg), dest);
+ ra_left(as, dest, ir->op1);
+}
+
+static void asm_min_max(ASMState *as, IRIns *ir, int cc)
+{
+ Reg right, dest = ra_dest(as, ir, RSET_GPR);
+ IRRef lref = ir->op1, rref = ir->op2;
+ if (irref_isk(rref)) { lref = rref; rref = ir->op1; }
+ right = ra_alloc1(as, rref, rset_exclude(RSET_GPR, dest));
+ emit_rr(as, XO_CMOV + (cc<<24), REX_64IR(ir, dest), right);
+ emit_rr(as, XO_CMP, REX_64IR(ir, dest), right);
+ ra_left(as, dest, lref);
+}
+
+static void asm_bitswap(ASMState *as, IRIns *ir)
+{
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ as->mcp = emit_op(XO_BSWAP + ((dest&7) << 24),
+ REX_64IR(ir, 0), dest, 0, as->mcp, 1);
+ ra_left(as, dest, ir->op1);
+}
+
+static void asm_bitshift(ASMState *as, IRIns *ir, x86Shift xs)
+{
+ IRRef rref = ir->op2;
+ IRIns *irr = IR(rref);
+ Reg dest;
+ if (irref_isk(rref)) { /* Constant shifts. */
+ int shift;
+ dest = ra_dest(as, ir, RSET_GPR);
+ shift = irr->i & (irt_is64(ir->t) ? 63 : 31);
+ switch (shift) {
+ case 0: break;
+ case 1: emit_rr(as, XO_SHIFT1, REX_64IR(ir, xs), dest); break;
+ default: emit_shifti(as, REX_64IR(ir, xs), dest, shift); break;
+ }
+ } else { /* Variable shifts implicitly use register cl (i.e. ecx). */
+ Reg right;
+ dest = ra_dest(as, ir, rset_exclude(RSET_GPR, RID_ECX));
+ if (dest == RID_ECX) {
+ dest = ra_scratch(as, rset_exclude(RSET_GPR, RID_ECX));
+ emit_rr(as, XO_MOV, RID_ECX, dest);
+ }
+ right = irr->r;
+ if (ra_noreg(right))
+ right = ra_allocref(as, rref, RID2RSET(RID_ECX));
+ else if (right != RID_ECX)
+ ra_scratch(as, RID2RSET(RID_ECX));
+ emit_rr(as, XO_SHIFTcl, REX_64IR(ir, xs), dest);
+ ra_noweak(as, right);
+ if (right != RID_ECX)
+ emit_rr(as, XO_MOV, RID_ECX, right);
+ }
+ ra_left(as, dest, ir->op1);
+ /*
+ ** Note: avoid using the flags resulting from a shift or rotate!
+ ** All of them cause a partial flag stall, except for r,1 shifts
+ ** (but not rotates). And a shift count of 0 leaves the flags unmodified.
+ */
+}
+
+/* -- Comparisons --------------------------------------------------------- */
+
+/* Virtual flags for unordered FP comparisons. */
+#define VCC_U 0x1000 /* Unordered. */
+#define VCC_P 0x2000 /* Needs extra CC_P branch. */
+#define VCC_S 0x4000 /* Swap avoids CC_P branch. */
+#define VCC_PS (VCC_P|VCC_S)
+
+/* Map of comparisons to flags. ORDER IR. */
+#define COMPFLAGS(ci, cin, cu, cf) ((ci)+((cu)<<4)+((cin)<<8)+(cf))
+static const uint16_t asm_compmap[IR_ABC+1] = {
+ /* signed non-eq unsigned flags */
+ /* LT */ COMPFLAGS(CC_GE, CC_G, CC_AE, VCC_PS),
+ /* GE */ COMPFLAGS(CC_L, CC_L, CC_B, 0),
+ /* LE */ COMPFLAGS(CC_G, CC_G, CC_A, VCC_PS),
+ /* GT */ COMPFLAGS(CC_LE, CC_L, CC_BE, 0),
+ /* ULT */ COMPFLAGS(CC_AE, CC_A, CC_AE, VCC_U),
+ /* UGE */ COMPFLAGS(CC_B, CC_B, CC_B, VCC_U|VCC_PS),
+ /* ULE */ COMPFLAGS(CC_A, CC_A, CC_A, VCC_U),
+ /* UGT */ COMPFLAGS(CC_BE, CC_B, CC_BE, VCC_U|VCC_PS),
+ /* EQ */ COMPFLAGS(CC_NE, CC_NE, CC_NE, VCC_P),
+ /* NE */ COMPFLAGS(CC_E, CC_E, CC_E, VCC_U|VCC_P),
+ /* ABC */ COMPFLAGS(CC_BE, CC_B, CC_BE, VCC_U|VCC_PS) /* Same as UGT. */
+};
+
+/* FP and integer comparisons. */
+static void asm_comp(ASMState *as, IRIns *ir, uint32_t cc)
+{
+ if (irt_isnum(ir->t)) {
+ IRRef lref = ir->op1;
+ IRRef rref = ir->op2;
+ Reg left, right;
+ MCLabel l_around;
+ /*
+ ** An extra CC_P branch is required to preserve ordered/unordered
+ ** semantics for FP comparisons. This can be avoided by swapping
+ ** the operands and inverting the condition (except for EQ and UNE).
+ ** So always try to swap if possible.
+ **
+ ** Another option would be to swap operands to achieve better memory
+ ** operand fusion. But it's unlikely that this outweighs the cost
+ ** of the extra branches.
+ */
+ if (cc & VCC_S) { /* Swap? */
+ IRRef tmp = lref; lref = rref; rref = tmp;
+ cc ^= (VCC_PS|(5<<4)); /* A <-> B, AE <-> BE, PS <-> none */
+ }
+ left = ra_alloc1(as, lref, RSET_FPR);
+ right = asm_fuseload(as, rref, rset_exclude(RSET_FPR, left));
+ l_around = emit_label(as);
+ asm_guardcc(as, cc >> 4);
+ if (cc & VCC_P) { /* Extra CC_P branch required? */
+ if (!(cc & VCC_U)) {
+ asm_guardcc(as, CC_P); /* Branch to exit for ordered comparisons. */
+ } else if (l_around != as->invmcp) {
+ emit_sjcc(as, CC_P, l_around); /* Branch around for unordered. */
+ } else {
+ /* Patched to mcloop by asm_loop_fixup. */
+ as->loopinv = 2;
+ if (as->realign)
+ emit_sjcc(as, CC_P, as->mcp);
+ else
+ emit_jcc(as, CC_P, as->mcp);
+ }
+ }
+ emit_mrm(as, XO_UCOMISD, left, right);
+ } else {
+ IRRef lref = ir->op1, rref = ir->op2;
+ IROp leftop = (IROp)(IR(lref)->o);
+ Reg r64 = REX_64IR(ir, 0);
+ int32_t imm = 0;
+ lua_assert(irt_is64(ir->t) || irt_isint(ir->t) ||
+ irt_isu32(ir->t) || irt_isaddr(ir->t) || irt_isu8(ir->t));
+ /* Swap constants (only for ABC) and fusable loads to the right. */
+ if (irref_isk(lref) || (!irref_isk(rref) && opisfusableload(leftop))) {
+ if ((cc & 0xc) == 0xc) cc ^= 0x53; /* L <-> G, LE <-> GE */
+ else if ((cc & 0xa) == 0x2) cc ^= 0x55; /* A <-> B, AE <-> BE */
+ lref = ir->op2; rref = ir->op1;
+ }
+ if (asm_isk32(as, rref, &imm)) {
+ IRIns *irl = IR(lref);
+ /* Check wether we can use test ins. Not for unsigned, since CF=0. */
+ int usetest = (imm == 0 && (cc & 0xa) != 0x2);
+ if (usetest && irl->o == IR_BAND && irl+1 == ir && !ra_used(irl)) {
+ /* Combine comp(BAND(ref, r/imm), 0) into test mrm, r/imm. */
+ Reg right, left = RID_NONE;
+ RegSet allow = RSET_GPR;
+ if (!asm_isk32(as, irl->op2, &imm)) {
+ left = ra_alloc1(as, irl->op2, allow);
+ rset_clear(allow, left);
+ } else { /* Try to Fuse IRT_I8/IRT_U8 loads, too. See below. */
+ IRIns *irll = IR(irl->op1);
+ if (opisfusableload((IROp)irll->o) &&
+ (irt_isi8(irll->t) || irt_isu8(irll->t))) {
+ IRType1 origt = irll->t; /* Temporarily flip types. */
+ irll->t.irt = (irll->t.irt & ~IRT_TYPE) | IRT_INT;
+ as->curins--; /* Skip to BAND to avoid failing in noconflict(). */
+ right = asm_fuseload(as, irl->op1, RSET_GPR);
+ as->curins++;
+ irll->t = origt;
+ if (right != RID_MRM) goto test_nofuse;
+ /* Fusion succeeded, emit test byte mrm, imm8. */
+ asm_guardcc(as, cc);
+ emit_i8(as, (imm & 0xff));
+ emit_mrm(as, XO_GROUP3b, XOg_TEST, RID_MRM);
+ return;
+ }
+ }
+ as->curins--; /* Skip to BAND to avoid failing in noconflict(). */
+ right = asm_fuseloadm(as, irl->op1, allow, r64);
+ as->curins++; /* Undo the above. */
+ test_nofuse:
+ asm_guardcc(as, cc);
+ if (ra_noreg(left)) {
+ emit_i32(as, imm);
+ emit_mrm(as, XO_GROUP3, r64 + XOg_TEST, right);
+ } else {
+ emit_mrm(as, XO_TEST, r64 + left, right);
+ }
+ } else {
+ Reg left;
+ if (opisfusableload((IROp)irl->o) &&
+ ((irt_isu8(irl->t) && checku8(imm)) ||
+ ((irt_isi8(irl->t) || irt_isi16(irl->t)) && checki8(imm)) ||
+ (irt_isu16(irl->t) && checku16(imm) && checki8((int16_t)imm)))) {
+ /* Only the IRT_INT case is fused by asm_fuseload.
+ ** The IRT_I8/IRT_U8 loads and some IRT_I16/IRT_U16 loads
+ ** are handled here.
+ ** Note that cmp word [mem], imm16 should not be generated,
+ ** since it has a length-changing prefix. Compares of a word
+ ** against a sign-extended imm8 are ok, however.
+ */
+ IRType1 origt = irl->t; /* Temporarily flip types. */
+ irl->t.irt = (irl->t.irt & ~IRT_TYPE) | IRT_INT;
+ left = asm_fuseload(as, lref, RSET_GPR);
+ irl->t = origt;
+ if (left == RID_MRM) { /* Fusion succeeded? */
+ if (irt_isu8(irl->t) || irt_isu16(irl->t))
+ cc >>= 4; /* Need unsigned compare. */
+ asm_guardcc(as, cc);
+ emit_i8(as, imm);
+ emit_mrm(as, (irt_isi8(origt) || irt_isu8(origt)) ?
+ XO_ARITHib : XO_ARITHiw8, r64 + XOg_CMP, RID_MRM);
+ return;
+ } /* Otherwise handle register case as usual. */
+ } else {
+ left = asm_fuseloadm(as, lref,
+ irt_isu8(ir->t) ? RSET_GPR8 : RSET_GPR, r64);
+ }
+ asm_guardcc(as, cc);
+ if (usetest && left != RID_MRM) {
+ /* Use test r,r instead of cmp r,0. */
+ x86Op xo = XO_TEST;
+ if (irt_isu8(ir->t)) {
+ lua_assert(ir->o == IR_EQ || ir->o == IR_NE);
+ xo = XO_TESTb;
+ if (!rset_test(RSET_RANGE(RID_EAX, RID_EBX+1), left)) {
+ if (LJ_64) {
+ left |= FORCE_REX;
+ } else {
+ emit_i32(as, 0xff);
+ emit_mrm(as, XO_GROUP3, XOg_TEST, left);
+ return;
+ }
+ }
+ }
+ emit_rr(as, xo, r64 + left, left);
+ if (irl+1 == ir) /* Referencing previous ins? */
+ as->flagmcp = as->mcp; /* Set flag to drop test r,r if possible. */
+ } else {
+ emit_gmrmi(as, XG_ARITHi(XOg_CMP), r64 + left, imm);
+ }
+ }
+ } else {
+ Reg left = ra_alloc1(as, lref, RSET_GPR);
+ Reg right = asm_fuseloadm(as, rref, rset_exclude(RSET_GPR, left), r64);
+ asm_guardcc(as, cc);
+ emit_mrm(as, XO_CMP, r64 + left, right);
+ }
+ }
+}
+
+#if LJ_32 && LJ_HASFFI
+/* 64 bit integer comparisons in 32 bit mode. */
+static void asm_comp_int64(ASMState *as, IRIns *ir)
+{
+ uint32_t cc = asm_compmap[(ir-1)->o];
+ RegSet allow = RSET_GPR;
+ Reg lefthi = RID_NONE, leftlo = RID_NONE;
+ Reg righthi = RID_NONE, rightlo = RID_NONE;
+ MCLabel l_around;
+ x86ModRM mrm;
+
+ as->curins--; /* Skip loword ins. Avoids failing in noconflict(), too. */
+
+ /* Allocate/fuse hiword operands. */
+ if (irref_isk(ir->op2)) {
+ lefthi = asm_fuseload(as, ir->op1, allow);
+ } else {
+ lefthi = ra_alloc1(as, ir->op1, allow);
+ rset_clear(allow, lefthi);
+ righthi = asm_fuseload(as, ir->op2, allow);
+ if (righthi == RID_MRM) {
+ if (as->mrm.base != RID_NONE) rset_clear(allow, as->mrm.base);
+ if (as->mrm.idx != RID_NONE) rset_clear(allow, as->mrm.idx);
+ } else {
+ rset_clear(allow, righthi);
+ }
+ }
+ mrm = as->mrm; /* Save state for hiword instruction. */
+
+ /* Allocate/fuse loword operands. */
+ if (irref_isk((ir-1)->op2)) {
+ leftlo = asm_fuseload(as, (ir-1)->op1, allow);
+ } else {
+ leftlo = ra_alloc1(as, (ir-1)->op1, allow);
+ rset_clear(allow, leftlo);
+ rightlo = asm_fuseload(as, (ir-1)->op2, allow);
+ }
+
+ /* All register allocations must be performed _before_ this point. */
+ l_around = emit_label(as);
+ as->invmcp = as->flagmcp = NULL; /* Cannot use these optimizations. */
+
+ /* Loword comparison and branch. */
+ asm_guardcc(as, cc >> 4); /* Always use unsigned compare for loword. */
+ if (ra_noreg(rightlo)) {
+ int32_t imm = IR((ir-1)->op2)->i;
+ if (imm == 0 && ((cc >> 4) & 0xa) != 0x2 && leftlo != RID_MRM)
+ emit_rr(as, XO_TEST, leftlo, leftlo);
+ else
+ emit_gmrmi(as, XG_ARITHi(XOg_CMP), leftlo, imm);
+ } else {
+ emit_mrm(as, XO_CMP, leftlo, rightlo);
+ }
+
+ /* Hiword comparison and branches. */
+ if ((cc & 15) != CC_NE)
+ emit_sjcc(as, CC_NE, l_around); /* Hiword unequal: skip loword compare. */
+ if ((cc & 15) != CC_E)
+ asm_guardcc(as, cc >> 8); /* Hiword compare without equality check. */
+ as->mrm = mrm; /* Restore state. */
+ if (ra_noreg(righthi)) {
+ int32_t imm = IR(ir->op2)->i;
+ if (imm == 0 && (cc & 0xa) != 0x2 && lefthi != RID_MRM)
+ emit_rr(as, XO_TEST, lefthi, lefthi);
+ else
+ emit_gmrmi(as, XG_ARITHi(XOg_CMP), lefthi, imm);
+ } else {
+ emit_mrm(as, XO_CMP, lefthi, righthi);
+ }
+}
+#endif
+
+/* -- Support for 64 bit ops in 32 bit mode ------------------------------- */
+
+/* Hiword op of a split 64 bit op. Previous op must be the loword op. */
+static void asm_hiop(ASMState *as, IRIns *ir)
+{
+#if LJ_32 && LJ_HASFFI
+ /* HIOP is marked as a store because it needs its own DCE logic. */
+ int uselo = ra_used(ir-1), usehi = ra_used(ir); /* Loword/hiword used? */
+ if (LJ_UNLIKELY(!(as->flags & JIT_F_OPT_DCE))) uselo = usehi = 1;
+ if ((ir-1)->o == IR_CONV) { /* Conversions to/from 64 bit. */
+ if (usehi || uselo) {
+ if (irt_isfp(ir->t))
+ asm_conv_fp_int64(as, ir);
+ else
+ asm_conv_int64_fp(as, ir);
+ }
+ as->curins--; /* Always skip the CONV. */
+ return;
+ } else if ((ir-1)->o <= IR_NE) { /* 64 bit integer comparisons. ORDER IR. */
+ asm_comp_int64(as, ir);
+ return;
+ } else if ((ir-1)->o == IR_XSTORE) {
+ if ((ir-1)->r != RID_SINK)
+ asm_fxstore(as, ir);
+ return;
+ }
+ if (!usehi) return; /* Skip unused hiword op for all remaining ops. */
+ switch ((ir-1)->o) {
+ case IR_ADD:
+ as->flagmcp = NULL;
+ as->curins--;
+ asm_intarith(as, ir, XOg_ADC);
+ asm_intarith(as, ir-1, XOg_ADD);
+ break;
+ case IR_SUB:
+ as->flagmcp = NULL;
+ as->curins--;
+ asm_intarith(as, ir, XOg_SBB);
+ asm_intarith(as, ir-1, XOg_SUB);
+ break;
+ case IR_NEG: {
+ Reg dest = ra_dest(as, ir, RSET_GPR);
+ emit_rr(as, XO_GROUP3, XOg_NEG, dest);
+ emit_i8(as, 0);
+ emit_rr(as, XO_ARITHi8, XOg_ADC, dest);
+ ra_left(as, dest, ir->op1);
+ as->curins--;
+ asm_neg_not(as, ir-1, XOg_NEG);
+ break;
+ }
+ case IR_CALLN:
+ case IR_CALLXS:
+ if (!uselo)
+ ra_allocref(as, ir->op1, RID2RSET(RID_RETLO)); /* Mark lo op as used. */
+ break;
+ case IR_CNEWI:
+ /* Nothing to do here. Handled by CNEWI itself. */
+ break;
+ default: lua_assert(0); break;
+ }
+#else
+ UNUSED(as); UNUSED(ir); lua_assert(0); /* Unused on x64 or without FFI. */
+#endif
+}
+
+/* -- Stack handling ------------------------------------------------------ */
+
+/* Check Lua stack size for overflow. Use exit handler as fallback. */
+static void asm_stack_check(ASMState *as, BCReg topslot,
+ IRIns *irp, RegSet allow, ExitNo exitno)
+{
+ /* Try to get an unused temp. register, otherwise spill/restore eax. */
+ Reg pbase = irp ? irp->r : RID_BASE;
+ Reg r = allow ? rset_pickbot(allow) : RID_EAX;
+ emit_jcc(as, CC_B, exitstub_addr(as->J, exitno));
+ if (allow == RSET_EMPTY) /* Restore temp. register. */
+ emit_rmro(as, XO_MOV, r|REX_64, RID_ESP, 0);
+ else
+ ra_modified(as, r);
+ emit_gri(as, XG_ARITHi(XOg_CMP), r, (int32_t)(8*topslot));
+ if (ra_hasreg(pbase) && pbase != r)
+ emit_rr(as, XO_ARITH(XOg_SUB), r, pbase);
+ else
+ emit_rmro(as, XO_ARITH(XOg_SUB), r, RID_NONE,
+ ptr2addr(&J2G(as->J)->jit_base));
+ emit_rmro(as, XO_MOV, r, r, offsetof(lua_State, maxstack));
+ emit_getgl(as, r, jit_L);
+ if (allow == RSET_EMPTY) /* Spill temp. register. */
+ emit_rmro(as, XO_MOVto, r|REX_64, RID_ESP, 0);
+}
+
+/* Restore Lua stack from on-trace state. */
+static void asm_stack_restore(ASMState *as, SnapShot *snap)
+{
+ SnapEntry *map = &as->T->snapmap[snap->mapofs];
+ SnapEntry *flinks = &as->T->snapmap[snap_nextofs(as->T, snap)-1];
+ MSize n, nent = snap->nent;
+ /* Store the value of all modified slots to the Lua stack. */
+ for (n = 0; n < nent; n++) {
+ SnapEntry sn = map[n];
+ BCReg s = snap_slot(sn);
+ int32_t ofs = 8*((int32_t)s-1);
+ IRRef ref = snap_ref(sn);
+ IRIns *ir = IR(ref);
+ if ((sn & SNAP_NORESTORE))
+ continue;
+ if (irt_isnum(ir->t)) {
+ Reg src = ra_alloc1(as, ref, RSET_FPR);
+ emit_rmro(as, XO_MOVSDto, src, RID_BASE, ofs);
+ } else {
+ lua_assert(irt_ispri(ir->t) || irt_isaddr(ir->t) ||
+ (LJ_DUALNUM && irt_isinteger(ir->t)));
+ if (!irref_isk(ref)) {
+ Reg src = ra_alloc1(as, ref, rset_exclude(RSET_GPR, RID_BASE));
+ emit_movtomro(as, REX_64IR(ir, src), RID_BASE, ofs);
+ } else if (!irt_ispri(ir->t)) {
+ emit_movmroi(as, RID_BASE, ofs, ir->i);
+ }
+ if ((sn & (SNAP_CONT|SNAP_FRAME))) {
+ if (s != 0) /* Do not overwrite link to previous frame. */
+ emit_movmroi(as, RID_BASE, ofs+4, (int32_t)(*flinks--));
+ } else {
+ if (!(LJ_64 && irt_islightud(ir->t)))
+ emit_movmroi(as, RID_BASE, ofs+4, irt_toitype(ir->t));
+ }
+ }
+ checkmclim(as);
+ }
+ lua_assert(map + nent == flinks);
+}
+
+/* -- GC handling --------------------------------------------------------- */
+
+/* Check GC threshold and do one or more GC steps. */
+static void asm_gc_check(ASMState *as)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[IRCALL_lj_gc_step_jit];
+ IRRef args[2];
+ MCLabel l_end;
+ Reg tmp;
+ ra_evictset(as, RSET_SCRATCH);
+ l_end = emit_label(as);
+ /* Exit trace if in GCSatomic or GCSfinalize. Avoids syncing GC objects. */
+ asm_guardcc(as, CC_NE); /* Assumes asm_snap_prep() already done. */
+ emit_rr(as, XO_TEST, RID_RET, RID_RET);
+ args[0] = ASMREF_TMP1; /* global_State *g */
+ args[1] = ASMREF_TMP2; /* MSize steps */
+ asm_gencall(as, ci, args);
+ tmp = ra_releasetmp(as, ASMREF_TMP1);
+ emit_loada(as, tmp, J2G(as->J));
+ emit_loadi(as, ra_releasetmp(as, ASMREF_TMP2), as->gcsteps);
+ /* Jump around GC step if GC total < GC threshold. */
+ emit_sjcc(as, CC_B, l_end);
+ emit_opgl(as, XO_ARITH(XOg_CMP), tmp, gc.threshold);
+ emit_getgl(as, tmp, gc.total);
+ as->gcsteps = 0;
+ checkmclim(as);
+}
+
+/* -- Loop handling ------------------------------------------------------- */
+
+/* Fixup the loop branch. */
+static void asm_loop_fixup(ASMState *as)
+{
+ MCode *p = as->mctop;
+ MCode *target = as->mcp;
+ if (as->realign) { /* Realigned loops use short jumps. */
+ as->realign = NULL; /* Stop another retry. */
+ lua_assert(((intptr_t)target & 15) == 0);
+ if (as->loopinv) { /* Inverted loop branch? */
+ p -= 5;
+ p[0] = XI_JMP;
+ lua_assert(target - p >= -128);
+ p[-1] = (MCode)(target - p); /* Patch sjcc. */
+ if (as->loopinv == 2)
+ p[-3] = (MCode)(target - p + 2); /* Patch opt. short jp. */
+ } else {
+ lua_assert(target - p >= -128);
+ p[-1] = (MCode)(int8_t)(target - p); /* Patch short jmp. */
+ p[-2] = XI_JMPs;
+ }
+ } else {
+ MCode *newloop;
+ p[-5] = XI_JMP;
+ if (as->loopinv) { /* Inverted loop branch? */
+ /* asm_guardcc already inverted the jcc and patched the jmp. */
+ p -= 5;
+ newloop = target+4;
+ *(int32_t *)(p-4) = (int32_t)(target - p); /* Patch jcc. */
+ if (as->loopinv == 2) {
+ *(int32_t *)(p-10) = (int32_t)(target - p + 6); /* Patch opt. jp. */
+ newloop = target+8;
+ }
+ } else { /* Otherwise just patch jmp. */
+ *(int32_t *)(p-4) = (int32_t)(target - p);
+ newloop = target+3;
+ }
+ /* Realign small loops and shorten the loop branch. */
+ if (newloop >= p - 128) {
+ as->realign = newloop; /* Force a retry and remember alignment. */
+ as->curins = as->stopins; /* Abort asm_trace now. */
+ as->T->nins = as->orignins; /* Remove any added renames. */
+ }
+ }
+}
+
+/* -- Head of trace ------------------------------------------------------- */
+
+/* Coalesce BASE register for a root trace. */
+static void asm_head_root_base(ASMState *as)
+{
+ IRIns *ir = IR(REF_BASE);
+ Reg r = ir->r;
+ if (ra_hasreg(r)) {
+ ra_free(as, r);
+ if (rset_test(as->modset, r) || irt_ismarked(ir->t))
+ ir->r = RID_INIT; /* No inheritance for modified BASE register. */
+ if (r != RID_BASE)
+ emit_rr(as, XO_MOV, r, RID_BASE);
+ }
+}
+
+/* Coalesce or reload BASE register for a side trace. */
+static RegSet asm_head_side_base(ASMState *as, IRIns *irp, RegSet allow)
+{
+ IRIns *ir = IR(REF_BASE);
+ Reg r = ir->r;
+ if (ra_hasreg(r)) {
+ ra_free(as, r);
+ if (rset_test(as->modset, r) || irt_ismarked(ir->t))
+ ir->r = RID_INIT; /* No inheritance for modified BASE register. */
+ if (irp->r == r) {
+ rset_clear(allow, r); /* Mark same BASE register as coalesced. */
+ } else if (ra_hasreg(irp->r) && rset_test(as->freeset, irp->r)) {
+ rset_clear(allow, irp->r);
+ emit_rr(as, XO_MOV, r, irp->r); /* Move from coalesced parent reg. */
+ } else {
+ emit_getgl(as, r, jit_base); /* Otherwise reload BASE. */
+ }
+ }
+ return allow;
+}
+
+/* -- Tail of trace ------------------------------------------------------- */
+
+/* Fixup the tail code. */
+static void asm_tail_fixup(ASMState *as, TraceNo lnk)
+{
+ /* Note: don't use as->mcp swap + emit_*: emit_op overwrites more bytes. */
+ MCode *p = as->mctop;
+ MCode *target, *q;
+ int32_t spadj = as->T->spadjust;
+ if (spadj == 0) {
+ p -= ((as->flags & JIT_F_LEA_AGU) ? 7 : 6) + (LJ_64 ? 1 : 0);
+ } else {
+ MCode *p1;
+ /* Patch stack adjustment. */
+ if (checki8(spadj)) {
+ p -= 3;
+ p1 = p-6;
+ *p1 = (MCode)spadj;
+ } else {
+ p1 = p-9;
+ *(int32_t *)p1 = spadj;
+ }
+ if ((as->flags & JIT_F_LEA_AGU)) {
+#if LJ_64
+ p1[-4] = 0x48;
+#endif
+ p1[-3] = (MCode)XI_LEA;
+ p1[-2] = MODRM(checki8(spadj) ? XM_OFS8 : XM_OFS32, RID_ESP, RID_ESP);
+ p1[-1] = MODRM(XM_SCALE1, RID_ESP, RID_ESP);
+ } else {
+#if LJ_64
+ p1[-3] = 0x48;
+#endif
+ p1[-2] = (MCode)(checki8(spadj) ? XI_ARITHi8 : XI_ARITHi);
+ p1[-1] = MODRM(XM_REG, XOg_ADD, RID_ESP);
+ }
+ }
+ /* Patch exit branch. */
+ target = lnk ? traceref(as->J, lnk)->mcode : (MCode *)lj_vm_exit_interp;
+ *(int32_t *)(p-4) = jmprel(p, target);
+ p[-5] = XI_JMP;
+ /* Drop unused mcode tail. Fill with NOPs to make the prefetcher happy. */
+ for (q = as->mctop-1; q >= p; q--)
+ *q = XI_NOP;
+ as->mctop = p;
+}
+
+/* Prepare tail of code. */
+static void asm_tail_prep(ASMState *as)
+{
+ MCode *p = as->mctop;
+ /* Realign and leave room for backwards loop branch or exit branch. */
+ if (as->realign) {
+ int i = ((int)(intptr_t)as->realign) & 15;
+ /* Fill unused mcode tail with NOPs to make the prefetcher happy. */
+ while (i-- > 0)
+ *--p = XI_NOP;
+ as->mctop = p;
+ p -= (as->loopinv ? 5 : 2); /* Space for short/near jmp. */
+ } else {
+ p -= 5; /* Space for exit branch (near jmp). */
+ }
+ if (as->loopref) {
+ as->invmcp = as->mcp = p;
+ } else {
+ /* Leave room for ESP adjustment: add esp, imm or lea esp, [esp+imm] */
+ as->mcp = p - (((as->flags & JIT_F_LEA_AGU) ? 7 : 6) + (LJ_64 ? 1 : 0));
+ as->invmcp = NULL;
+ }
+}
+
+/* -- Instruction dispatch ------------------------------------------------ */
+
+/* Assemble a single instruction. */
+static void asm_ir(ASMState *as, IRIns *ir)
+{
+ switch ((IROp)ir->o) {
+ /* Miscellaneous ops. */
+ case IR_LOOP: asm_loop(as); break;
+ case IR_NOP: case IR_XBAR: lua_assert(!ra_used(ir)); break;
+ case IR_USE:
+ ra_alloc1(as, ir->op1, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); break;
+ case IR_PHI: asm_phi(as, ir); break;
+ case IR_HIOP: asm_hiop(as, ir); break;
+ case IR_GCSTEP: asm_gcstep(as, ir); break;
+
+ /* Guarded assertions. */
+ case IR_LT: case IR_GE: case IR_LE: case IR_GT:
+ case IR_ULT: case IR_UGE: case IR_ULE: case IR_UGT:
+ case IR_EQ: case IR_NE: case IR_ABC:
+ asm_comp(as, ir, asm_compmap[ir->o]);
+ break;
+
+ case IR_RETF: asm_retf(as, ir); break;
+
+ /* Bit ops. */
+ case IR_BNOT: asm_neg_not(as, ir, XOg_NOT); break;
+ case IR_BSWAP: asm_bitswap(as, ir); break;
+
+ case IR_BAND: asm_intarith(as, ir, XOg_AND); break;
+ case IR_BOR: asm_intarith(as, ir, XOg_OR); break;
+ case IR_BXOR: asm_intarith(as, ir, XOg_XOR); break;
+
+ case IR_BSHL: asm_bitshift(as, ir, XOg_SHL); break;
+ case IR_BSHR: asm_bitshift(as, ir, XOg_SHR); break;
+ case IR_BSAR: asm_bitshift(as, ir, XOg_SAR); break;
+ case IR_BROL: asm_bitshift(as, ir, XOg_ROL); break;
+ case IR_BROR: asm_bitshift(as, ir, XOg_ROR); break;
+
+ /* Arithmetic ops. */
+ case IR_ADD: asm_add(as, ir); break;
+ case IR_SUB:
+ if (irt_isnum(ir->t))
+ asm_fparith(as, ir, XO_SUBSD);
+ else /* Note: no need for LEA trick here. i-k is encoded as i+(-k). */
+ asm_intarith(as, ir, XOg_SUB);
+ break;
+ case IR_MUL:
+ if (irt_isnum(ir->t))
+ asm_fparith(as, ir, XO_MULSD);
+ else
+ asm_intarith(as, ir, XOg_X_IMUL);
+ break;
+ case IR_DIV:
+#if LJ_64 && LJ_HASFFI
+ if (!irt_isnum(ir->t))
+ asm_arith64(as, ir, irt_isi64(ir->t) ? IRCALL_lj_carith_divi64 :
+ IRCALL_lj_carith_divu64);
+ else
+#endif
+ asm_fparith(as, ir, XO_DIVSD);
+ break;
+ case IR_MOD:
+#if LJ_64 && LJ_HASFFI
+ if (!irt_isint(ir->t))
+ asm_arith64(as, ir, irt_isi64(ir->t) ? IRCALL_lj_carith_modi64 :
+ IRCALL_lj_carith_modu64);
+ else
+#endif
+ asm_intmod(as, ir);
+ break;
+
+ case IR_NEG:
+ if (irt_isnum(ir->t))
+ asm_fparith(as, ir, XO_XORPS);
+ else
+ asm_neg_not(as, ir, XOg_NEG);
+ break;
+ case IR_ABS: asm_fparith(as, ir, XO_ANDPS); break;
+
+ case IR_MIN:
+ if (irt_isnum(ir->t))
+ asm_fparith(as, ir, XO_MINSD);
+ else
+ asm_min_max(as, ir, CC_G);
+ break;
+ case IR_MAX:
+ if (irt_isnum(ir->t))
+ asm_fparith(as, ir, XO_MAXSD);
+ else
+ asm_min_max(as, ir, CC_L);
+ break;
+
+ case IR_FPMATH: case IR_ATAN2: case IR_LDEXP:
+ asm_fpmath(as, ir);
+ break;
+ case IR_POW:
+#if LJ_64 && LJ_HASFFI
+ if (!irt_isnum(ir->t))
+ asm_arith64(as, ir, irt_isi64(ir->t) ? IRCALL_lj_carith_powi64 :
+ IRCALL_lj_carith_powu64);
+ else
+#endif
+ asm_fppowi(as, ir);
+ break;
+
+ /* Overflow-checking arithmetic ops. Note: don't use LEA here! */
+ case IR_ADDOV: asm_intarith(as, ir, XOg_ADD); break;
+ case IR_SUBOV: asm_intarith(as, ir, XOg_SUB); break;
+ case IR_MULOV: asm_intarith(as, ir, XOg_X_IMUL); break;
+
+ /* Memory references. */
+ case IR_AREF: asm_aref(as, ir); break;
+ case IR_HREF: asm_href(as, ir); break;
+ case IR_HREFK: asm_hrefk(as, ir); break;
+ case IR_NEWREF: asm_newref(as, ir); break;
+ case IR_UREFO: case IR_UREFC: asm_uref(as, ir); break;
+ case IR_FREF: asm_fref(as, ir); break;
+ case IR_STRREF: asm_strref(as, ir); break;
+
+ /* Loads and stores. */
+ case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:
+ asm_ahuvload(as, ir);
+ break;
+ case IR_FLOAD: case IR_XLOAD: asm_fxload(as, ir); break;
+ case IR_SLOAD: asm_sload(as, ir); break;
+
+ case IR_ASTORE: case IR_HSTORE: case IR_USTORE: asm_ahustore(as, ir); break;
+ case IR_FSTORE: case IR_XSTORE: asm_fxstore(as, ir); break;
+
+ /* Allocations. */
+ case IR_SNEW: case IR_XSNEW: asm_snew(as, ir); break;
+ case IR_TNEW: asm_tnew(as, ir); break;
+ case IR_TDUP: asm_tdup(as, ir); break;
+ case IR_CNEW: case IR_CNEWI: asm_cnew(as, ir); break;
+
+ /* Write barriers. */
+ case IR_TBAR: asm_tbar(as, ir); break;
+ case IR_OBAR: asm_obar(as, ir); break;
+
+ /* Type conversions. */
+ case IR_TOBIT: asm_tobit(as, ir); break;
+ case IR_CONV: asm_conv(as, ir); break;
+ case IR_TOSTR: asm_tostr(as, ir); break;
+ case IR_STRTO: asm_strto(as, ir); break;
+
+ /* Calls. */
+ case IR_CALLN: case IR_CALLL: case IR_CALLS: asm_call(as, ir); break;
+ case IR_CALLXS: asm_callx(as, ir); break;
+ case IR_CARG: break;
+
+ default:
+ setintV(&as->J->errinfo, ir->o);
+ lj_trace_err_info(as->J, LJ_TRERR_NYIIR);
+ break;
+ }
+}
+
+/* -- Trace setup --------------------------------------------------------- */
+
+/* Ensure there are enough stack slots for call arguments. */
+static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)
+{
+ IRRef args[CCI_NARGS_MAX*2];
+ int nslots;
+ asm_collectargs(as, ir, ci, args);
+ nslots = asm_count_call_slots(as, ci, args);
+ if (nslots > as->evenspill) /* Leave room for args in stack slots. */
+ as->evenspill = nslots;
+#if LJ_64
+ return irt_isfp(ir->t) ? REGSP_HINT(RID_FPRET) : REGSP_HINT(RID_RET);
+#else
+ return irt_isfp(ir->t) ? REGSP_INIT : REGSP_HINT(RID_RET);
+#endif
+}
+
+/* Target-specific setup. */
+static void asm_setup_target(ASMState *as)
+{
+ asm_exitstub_setup(as, as->T->nsnap);
+}
+
+/* -- Trace patching ------------------------------------------------------ */
+
+static const uint8_t map_op1[256] = {
+0x92,0x92,0x92,0x92,0x52,0x45,0x51,0x51,0x92,0x92,0x92,0x92,0x52,0x45,0x51,0x20,
+0x92,0x92,0x92,0x92,0x52,0x45,0x51,0x51,0x92,0x92,0x92,0x92,0x52,0x45,0x51,0x51,
+0x92,0x92,0x92,0x92,0x52,0x45,0x10,0x51,0x92,0x92,0x92,0x92,0x52,0x45,0x10,0x51,
+0x92,0x92,0x92,0x92,0x52,0x45,0x10,0x51,0x92,0x92,0x92,0x92,0x52,0x45,0x10,0x51,
+#if LJ_64
+0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,
+#else
+0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,
+#endif
+0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,
+0x51,0x51,0x92,0x92,0x10,0x10,0x12,0x11,0x45,0x86,0x52,0x93,0x51,0x51,0x51,0x51,
+0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,
+0x93,0x86,0x93,0x93,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,
+0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x51,0x47,0x51,0x51,0x51,0x51,0x51,
+#if LJ_64
+0x59,0x59,0x59,0x59,0x51,0x51,0x51,0x51,0x52,0x45,0x51,0x51,0x51,0x51,0x51,0x51,
+#else
+0x55,0x55,0x55,0x55,0x51,0x51,0x51,0x51,0x52,0x45,0x51,0x51,0x51,0x51,0x51,0x51,
+#endif
+0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x05,0x05,0x05,0x05,0x05,0x05,0x05,0x05,
+0x93,0x93,0x53,0x51,0x70,0x71,0x93,0x86,0x54,0x51,0x53,0x51,0x51,0x52,0x51,0x51,
+0x92,0x92,0x92,0x92,0x52,0x52,0x51,0x51,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,
+0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x45,0x45,0x47,0x52,0x51,0x51,0x51,0x51,
+0x10,0x51,0x10,0x10,0x51,0x51,0x63,0x66,0x51,0x51,0x51,0x51,0x51,0x51,0x92,0x92
+};
+
+static const uint8_t map_op2[256] = {
+0x93,0x93,0x93,0x93,0x52,0x52,0x52,0x52,0x52,0x52,0x51,0x52,0x51,0x93,0x52,0x94,
+0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+0x53,0x53,0x53,0x53,0x53,0x53,0x53,0x53,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x34,0x51,0x35,0x51,0x51,0x51,0x51,0x51,
+0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+0x53,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+0x94,0x54,0x54,0x54,0x93,0x93,0x93,0x52,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,0x46,
+0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+0x52,0x52,0x52,0x93,0x94,0x93,0x51,0x51,0x52,0x52,0x52,0x93,0x94,0x93,0x93,0x93,
+0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x94,0x93,0x93,0x93,0x93,0x93,
+0x93,0x93,0x94,0x93,0x94,0x94,0x94,0x93,0x52,0x52,0x52,0x52,0x52,0x52,0x52,0x52,
+0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,
+0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x93,0x52
+};
+
+static uint32_t asm_x86_inslen(const uint8_t* p)
+{
+ uint32_t result = 0;
+ uint32_t prefixes = 0;
+ uint32_t x = map_op1[*p];
+ for (;;) {
+ switch (x >> 4) {
+ case 0: return result + x + (prefixes & 4);
+ case 1: prefixes |= x; x = map_op1[*++p]; result++; break;
+ case 2: x = map_op2[*++p]; break;
+ case 3: p++; goto mrm;
+ case 4: result -= (prefixes & 2); /* fallthrough */
+ case 5: return result + (x & 15);
+ case 6: /* Group 3. */
+ if (p[1] & 0x38) x = 2;
+ else if ((prefixes & 2) && (x == 0x66)) x = 4;
+ goto mrm;
+ case 7: /* VEX c4/c5. */
+ if (LJ_32 && p[1] < 0xc0) {
+ x = 2;
+ goto mrm;
+ }
+ if (x == 0x70) {
+ x = *++p & 0x1f;
+ result++;
+ if (x >= 2) {
+ p += 2;
+ result += 2;
+ goto mrm;
+ }
+ }
+ p++;
+ result++;
+ x = map_op2[*++p];
+ break;
+ case 8: result -= (prefixes & 2); /* fallthrough */
+ case 9: mrm: /* ModR/M and possibly SIB. */
+ result += (x & 15);
+ x = *++p;
+ switch (x >> 6) {
+ case 0: if ((x & 7) == 5) return result + 4; break;
+ case 1: result++; break;
+ case 2: result += 4; break;
+ case 3: return result;
+ }
+ if ((x & 7) == 4) {
+ result++;
+ if (x < 0x40 && (p[1] & 7) == 5) result += 4;
+ }
+ return result;
+ }
+ }
+}
+
+/* Patch exit jumps of existing machine code to a new target. */
+void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target)
+{
+ MCode *p = T->mcode;
+ MCode *mcarea = lj_mcode_patch(J, p, 0);
+ MSize len = T->szmcode;
+ MCode *px = exitstub_addr(J, exitno) - 6;
+ MCode *pe = p+len-6;
+ uint32_t stateaddr = u32ptr(&J2G(J)->vmstate);
+ if (len > 5 && p[len-5] == XI_JMP && p+len-6 + *(int32_t *)(p+len-4) == px)
+ *(int32_t *)(p+len-4) = jmprel(p+len, target);
+ /* Do not patch parent exit for a stack check. Skip beyond vmstate update. */
+ for (; p < pe; p += asm_x86_inslen(p))
+ if (*(uint32_t *)(p+(LJ_64 ? 3 : 2)) == stateaddr && p[0] == XI_MOVmi)
+ break;
+ lua_assert(p < pe);
+ for (; p < pe; p += asm_x86_inslen(p))
+ if ((*(uint16_t *)p & 0xf0ff) == 0x800f && p + *(int32_t *)(p+2) == px)
+ *(int32_t *)(p+2) = jmprel(p+6, target);
+ lj_mcode_sync(T->mcode, T->mcode + T->szmcode);
+ lj_mcode_patch(J, mcarea, 1);
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_bc.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_bc.c
new file mode 100644
index 0000000..a597692
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_bc.c
@@ -0,0 +1,14 @@
+/*
+** Bytecode instruction modes.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_bc_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#include "lj_bc.h"
+
+/* Bytecode offsets and bytecode instruction modes. */
+#include "lj_bcdef.h"
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_bc.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_bc.h
new file mode 100644
index 0000000..108c10f
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_bc.h
@@ -0,0 +1,261 @@
+/*
+** Bytecode instruction format.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_BC_H
+#define _LJ_BC_H
+
+#include "lj_def.h"
+#include "lj_arch.h"
+
+/* Bytecode instruction format, 32 bit wide, fields of 8 or 16 bit:
+**
+** +----+----+----+----+
+** | B | C | A | OP | Format ABC
+** +----+----+----+----+
+** | D | A | OP | Format AD
+** +--------------------
+** MSB LSB
+**
+** In-memory instructions are always stored in host byte order.
+*/
+
+/* Operand ranges and related constants. */
+#define BCMAX_A 0xff
+#define BCMAX_B 0xff
+#define BCMAX_C 0xff
+#define BCMAX_D 0xffff
+#define BCBIAS_J 0x8000
+#define NO_REG BCMAX_A
+#define NO_JMP (~(BCPos)0)
+
+/* Macros to get instruction fields. */
+#define bc_op(i) ((BCOp)((i)&0xff))
+#define bc_a(i) ((BCReg)(((i)>>8)&0xff))
+#define bc_b(i) ((BCReg)((i)>>24))
+#define bc_c(i) ((BCReg)(((i)>>16)&0xff))
+#define bc_d(i) ((BCReg)((i)>>16))
+#define bc_j(i) ((ptrdiff_t)bc_d(i)-BCBIAS_J)
+
+/* Macros to set instruction fields. */
+#define setbc_byte(p, x, ofs) \
+ ((uint8_t *)(p))[LJ_ENDIAN_SELECT(ofs, 3-ofs)] = (uint8_t)(x)
+#define setbc_op(p, x) setbc_byte(p, (x), 0)
+#define setbc_a(p, x) setbc_byte(p, (x), 1)
+#define setbc_b(p, x) setbc_byte(p, (x), 3)
+#define setbc_c(p, x) setbc_byte(p, (x), 2)
+#define setbc_d(p, x) \
+ ((uint16_t *)(p))[LJ_ENDIAN_SELECT(1, 0)] = (uint16_t)(x)
+#define setbc_j(p, x) setbc_d(p, (BCPos)((int32_t)(x)+BCBIAS_J))
+
+/* Macros to compose instructions. */
+#define BCINS_ABC(o, a, b, c) \
+ (((BCIns)(o))|((BCIns)(a)<<8)|((BCIns)(b)<<24)|((BCIns)(c)<<16))
+#define BCINS_AD(o, a, d) \
+ (((BCIns)(o))|((BCIns)(a)<<8)|((BCIns)(d)<<16))
+#define BCINS_AJ(o, a, j) BCINS_AD(o, a, (BCPos)((int32_t)(j)+BCBIAS_J))
+
+/* Bytecode instruction definition. Order matters, see below.
+**
+** (name, filler, Amode, Bmode, Cmode or Dmode, metamethod)
+**
+** The opcode name suffixes specify the type for RB/RC or RD:
+** V = variable slot
+** S = string const
+** N = number const
+** P = primitive type (~itype)
+** B = unsigned byte literal
+** M = multiple args/results
+*/
+#define BCDEF(_) \
+ /* Comparison ops. ORDER OPR. */ \
+ _(ISLT, var, ___, var, lt) \
+ _(ISGE, var, ___, var, lt) \
+ _(ISLE, var, ___, var, le) \
+ _(ISGT, var, ___, var, le) \
+ \
+ _(ISEQV, var, ___, var, eq) \
+ _(ISNEV, var, ___, var, eq) \
+ _(ISEQS, var, ___, str, eq) \
+ _(ISNES, var, ___, str, eq) \
+ _(ISEQN, var, ___, num, eq) \
+ _(ISNEN, var, ___, num, eq) \
+ _(ISEQP, var, ___, pri, eq) \
+ _(ISNEP, var, ___, pri, eq) \
+ \
+ /* Unary test and copy ops. */ \
+ _(ISTC, dst, ___, var, ___) \
+ _(ISFC, dst, ___, var, ___) \
+ _(IST, ___, ___, var, ___) \
+ _(ISF, ___, ___, var, ___) \
+ \
+ /* Unary ops. */ \
+ _(MOV, dst, ___, var, ___) \
+ _(NOT, dst, ___, var, ___) \
+ _(UNM, dst, ___, var, unm) \
+ _(LEN, dst, ___, var, len) \
+ \
+ /* Binary ops. ORDER OPR. VV last, POW must be next. */ \
+ _(ADDVN, dst, var, num, add) \
+ _(SUBVN, dst, var, num, sub) \
+ _(MULVN, dst, var, num, mul) \
+ _(DIVVN, dst, var, num, div) \
+ _(MODVN, dst, var, num, mod) \
+ \
+ _(ADDNV, dst, var, num, add) \
+ _(SUBNV, dst, var, num, sub) \
+ _(MULNV, dst, var, num, mul) \
+ _(DIVNV, dst, var, num, div) \
+ _(MODNV, dst, var, num, mod) \
+ \
+ _(ADDVV, dst, var, var, add) \
+ _(SUBVV, dst, var, var, sub) \
+ _(MULVV, dst, var, var, mul) \
+ _(DIVVV, dst, var, var, div) \
+ _(MODVV, dst, var, var, mod) \
+ \
+ _(POW, dst, var, var, pow) \
+ _(CAT, dst, rbase, rbase, concat) \
+ \
+ /* Constant ops. */ \
+ _(KSTR, dst, ___, str, ___) \
+ _(KCDATA, dst, ___, cdata, ___) \
+ _(KSHORT, dst, ___, lits, ___) \
+ _(KNUM, dst, ___, num, ___) \
+ _(KPRI, dst, ___, pri, ___) \
+ _(KNIL, base, ___, base, ___) \
+ \
+ /* Upvalue and function ops. */ \
+ _(UGET, dst, ___, uv, ___) \
+ _(USETV, uv, ___, var, ___) \
+ _(USETS, uv, ___, str, ___) \
+ _(USETN, uv, ___, num, ___) \
+ _(USETP, uv, ___, pri, ___) \
+ _(UCLO, rbase, ___, jump, ___) \
+ _(FNEW, dst, ___, func, gc) \
+ \
+ /* Table ops. */ \
+ _(TNEW, dst, ___, lit, gc) \
+ _(TDUP, dst, ___, tab, gc) \
+ _(GGET, dst, ___, str, index) \
+ _(GSET, var, ___, str, newindex) \
+ _(TGETV, dst, var, var, index) \
+ _(TGETS, dst, var, str, index) \
+ _(TGETB, dst, var, lit, index) \
+ _(TSETV, var, var, var, newindex) \
+ _(TSETS, var, var, str, newindex) \
+ _(TSETB, var, var, lit, newindex) \
+ _(TSETM, base, ___, num, newindex) \
+ \
+ /* Calls and vararg handling. T = tail call. */ \
+ _(CALLM, base, lit, lit, call) \
+ _(CALL, base, lit, lit, call) \
+ _(CALLMT, base, ___, lit, call) \
+ _(CALLT, base, ___, lit, call) \
+ _(ITERC, base, lit, lit, call) \
+ _(ITERN, base, lit, lit, call) \
+ _(VARG, base, lit, lit, ___) \
+ _(ISNEXT, base, ___, jump, ___) \
+ \
+ /* Returns. */ \
+ _(RETM, base, ___, lit, ___) \
+ _(RET, rbase, ___, lit, ___) \
+ _(RET0, rbase, ___, lit, ___) \
+ _(RET1, rbase, ___, lit, ___) \
+ \
+ /* Loops and branches. I/J = interp/JIT, I/C/L = init/call/loop. */ \
+ _(FORI, base, ___, jump, ___) \
+ _(JFORI, base, ___, jump, ___) \
+ \
+ _(FORL, base, ___, jump, ___) \
+ _(IFORL, base, ___, jump, ___) \
+ _(JFORL, base, ___, lit, ___) \
+ \
+ _(ITERL, base, ___, jump, ___) \
+ _(IITERL, base, ___, jump, ___) \
+ _(JITERL, base, ___, lit, ___) \
+ \
+ _(LOOP, rbase, ___, jump, ___) \
+ _(ILOOP, rbase, ___, jump, ___) \
+ _(JLOOP, rbase, ___, lit, ___) \
+ \
+ _(JMP, rbase, ___, jump, ___) \
+ \
+ /* Function headers. I/J = interp/JIT, F/V/C = fixarg/vararg/C func. */ \
+ _(FUNCF, rbase, ___, ___, ___) \
+ _(IFUNCF, rbase, ___, ___, ___) \
+ _(JFUNCF, rbase, ___, lit, ___) \
+ _(FUNCV, rbase, ___, ___, ___) \
+ _(IFUNCV, rbase, ___, ___, ___) \
+ _(JFUNCV, rbase, ___, lit, ___) \
+ _(FUNCC, rbase, ___, ___, ___) \
+ _(FUNCCW, rbase, ___, ___, ___)
+
+/* Bytecode opcode numbers. */
+typedef enum {
+#define BCENUM(name, ma, mb, mc, mt) BC_##name,
+BCDEF(BCENUM)
+#undef BCENUM
+ BC__MAX
+} BCOp;
+
+LJ_STATIC_ASSERT((int)BC_ISEQV+1 == (int)BC_ISNEV);
+LJ_STATIC_ASSERT(((int)BC_ISEQV^1) == (int)BC_ISNEV);
+LJ_STATIC_ASSERT(((int)BC_ISEQS^1) == (int)BC_ISNES);
+LJ_STATIC_ASSERT(((int)BC_ISEQN^1) == (int)BC_ISNEN);
+LJ_STATIC_ASSERT(((int)BC_ISEQP^1) == (int)BC_ISNEP);
+LJ_STATIC_ASSERT(((int)BC_ISLT^1) == (int)BC_ISGE);
+LJ_STATIC_ASSERT(((int)BC_ISLE^1) == (int)BC_ISGT);
+LJ_STATIC_ASSERT(((int)BC_ISLT^3) == (int)BC_ISGT);
+LJ_STATIC_ASSERT((int)BC_IST-(int)BC_ISTC == (int)BC_ISF-(int)BC_ISFC);
+LJ_STATIC_ASSERT((int)BC_CALLT-(int)BC_CALL == (int)BC_CALLMT-(int)BC_CALLM);
+LJ_STATIC_ASSERT((int)BC_CALLMT + 1 == (int)BC_CALLT);
+LJ_STATIC_ASSERT((int)BC_RETM + 1 == (int)BC_RET);
+LJ_STATIC_ASSERT((int)BC_FORL + 1 == (int)BC_IFORL);
+LJ_STATIC_ASSERT((int)BC_FORL + 2 == (int)BC_JFORL);
+LJ_STATIC_ASSERT((int)BC_ITERL + 1 == (int)BC_IITERL);
+LJ_STATIC_ASSERT((int)BC_ITERL + 2 == (int)BC_JITERL);
+LJ_STATIC_ASSERT((int)BC_LOOP + 1 == (int)BC_ILOOP);
+LJ_STATIC_ASSERT((int)BC_LOOP + 2 == (int)BC_JLOOP);
+LJ_STATIC_ASSERT((int)BC_FUNCF + 1 == (int)BC_IFUNCF);
+LJ_STATIC_ASSERT((int)BC_FUNCF + 2 == (int)BC_JFUNCF);
+LJ_STATIC_ASSERT((int)BC_FUNCV + 1 == (int)BC_IFUNCV);
+LJ_STATIC_ASSERT((int)BC_FUNCV + 2 == (int)BC_JFUNCV);
+
+/* This solves a circular dependency problem, change as needed. */
+#define FF_next_N 4
+
+/* Stack slots used by FORI/FORL, relative to operand A. */
+enum {
+ FORL_IDX, FORL_STOP, FORL_STEP, FORL_EXT
+};
+
+/* Bytecode operand modes. ORDER BCMode */
+typedef enum {
+ BCMnone, BCMdst, BCMbase, BCMvar, BCMrbase, BCMuv, /* Mode A must be <= 7 */
+ BCMlit, BCMlits, BCMpri, BCMnum, BCMstr, BCMtab, BCMfunc, BCMjump, BCMcdata,
+ BCM_max
+} BCMode;
+#define BCM___ BCMnone
+
+#define bcmode_a(op) ((BCMode)(lj_bc_mode[op] & 7))
+#define bcmode_b(op) ((BCMode)((lj_bc_mode[op]>>3) & 15))
+#define bcmode_c(op) ((BCMode)((lj_bc_mode[op]>>7) & 15))
+#define bcmode_d(op) bcmode_c(op)
+#define bcmode_hasd(op) ((lj_bc_mode[op] & (15<<3)) == (BCMnone<<3))
+#define bcmode_mm(op) ((MMS)(lj_bc_mode[op]>>11))
+
+#define BCMODE(name, ma, mb, mc, mm) \
+ (BCM##ma|(BCM##mb<<3)|(BCM##mc<<7)|(MM_##mm<<11)),
+#define BCMODE_FF 0
+
+static LJ_AINLINE int bc_isret(BCOp op)
+{
+ return (op == BC_RETM || op == BC_RET || op == BC_RET0 || op == BC_RET1);
+}
+
+LJ_DATA const uint16_t lj_bc_mode[];
+LJ_DATA const uint16_t lj_bc_ofs[];
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_bcdump.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_bcdump.h
new file mode 100644
index 0000000..ba53c0a
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_bcdump.h
@@ -0,0 +1,66 @@
+/*
+** Bytecode dump definitions.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_BCDUMP_H
+#define _LJ_BCDUMP_H
+
+#include "lj_obj.h"
+#include "lj_lex.h"
+
+/* -- Bytecode dump format ------------------------------------------------ */
+
+/*
+** dump = header proto+ 0U
+** header = ESC 'L' 'J' versionB flagsU [namelenU nameB*]
+** proto = lengthU pdata
+** pdata = phead bcinsW* uvdataH* kgc* knum* [debugB*]
+** phead = flagsB numparamsB framesizeB numuvB numkgcU numknU numbcU
+** [debuglenU [firstlineU numlineU]]
+** kgc = kgctypeU { ktab | (loU hiU) | (rloU rhiU iloU ihiU) | strB* }
+** knum = intU0 | (loU1 hiU)
+** ktab = narrayU nhashU karray* khash*
+** karray = ktabk
+** khash = ktabk ktabk
+** ktabk = ktabtypeU { intU | (loU hiU) | strB* }
+**
+** B = 8 bit, H = 16 bit, W = 32 bit, U = ULEB128 of W, U0/U1 = ULEB128 of W+1
+*/
+
+/* Bytecode dump header. */
+#define BCDUMP_HEAD1 0x1b
+#define BCDUMP_HEAD2 0x4c
+#define BCDUMP_HEAD3 0x4a
+
+/* If you perform *any* kind of private modifications to the bytecode itself
+** or to the dump format, you *must* set BCDUMP_VERSION to 0x80 or higher.
+*/
+#define BCDUMP_VERSION 1
+
+/* Compatibility flags. */
+#define BCDUMP_F_BE 0x01
+#define BCDUMP_F_STRIP 0x02
+#define BCDUMP_F_FFI 0x04
+
+#define BCDUMP_F_KNOWN (BCDUMP_F_FFI*2-1)
+
+/* Type codes for the GC constants of a prototype. Plus length for strings. */
+enum {
+ BCDUMP_KGC_CHILD, BCDUMP_KGC_TAB, BCDUMP_KGC_I64, BCDUMP_KGC_U64,
+ BCDUMP_KGC_COMPLEX, BCDUMP_KGC_STR
+};
+
+/* Type codes for the keys/values of a constant table. */
+enum {
+ BCDUMP_KTAB_NIL, BCDUMP_KTAB_FALSE, BCDUMP_KTAB_TRUE,
+ BCDUMP_KTAB_INT, BCDUMP_KTAB_NUM, BCDUMP_KTAB_STR
+};
+
+/* -- Bytecode reader/writer ---------------------------------------------- */
+
+LJ_FUNC int lj_bcwrite(lua_State *L, GCproto *pt, lua_Writer writer,
+ void *data, int strip);
+LJ_FUNC GCproto *lj_bcread(LexState *ls);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_bcread.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_bcread.c
new file mode 100644
index 0000000..6a462bd
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_bcread.c
@@ -0,0 +1,476 @@
+/*
+** Bytecode reader.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_bcread_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_bc.h"
+#if LJ_HASFFI
+#include "lj_ctype.h"
+#include "lj_cdata.h"
+#include "lualib.h"
+#endif
+#include "lj_lex.h"
+#include "lj_bcdump.h"
+#include "lj_state.h"
+
+/* Reuse some lexer fields for our own purposes. */
+#define bcread_flags(ls) ls->level
+#define bcread_swap(ls) \
+ ((bcread_flags(ls) & BCDUMP_F_BE) != LJ_BE*BCDUMP_F_BE)
+#define bcread_oldtop(L, ls) restorestack(L, ls->lastline)
+#define bcread_savetop(L, ls, top) \
+ ls->lastline = (BCLine)savestack(L, (top))
+
+/* -- Input buffer handling ----------------------------------------------- */
+
+/* Throw reader error. */
+static LJ_NOINLINE void bcread_error(LexState *ls, ErrMsg em)
+{
+ lua_State *L = ls->L;
+ const char *name = ls->chunkarg;
+ if (*name == BCDUMP_HEAD1) name = "(binary)";
+ else if (*name == '@' || *name == '=') name++;
+ lj_str_pushf(L, "%s: %s", name, err2msg(em));
+ lj_err_throw(L, LUA_ERRSYNTAX);
+}
+
+/* Resize input buffer. */
+static void bcread_resize(LexState *ls, MSize len)
+{
+ if (ls->sb.sz < len) {
+ MSize sz = ls->sb.sz * 2;
+ while (len > sz) sz = sz * 2;
+ lj_str_resizebuf(ls->L, &ls->sb, sz);
+ /* Caveat: this may change ls->sb.buf which may affect ls->p. */
+ }
+}
+
+/* Refill buffer if needed. */
+static LJ_NOINLINE void bcread_fill(LexState *ls, MSize len, int need)
+{
+ lua_assert(len != 0);
+ if (len > LJ_MAX_MEM || ls->current < 0)
+ bcread_error(ls, LJ_ERR_BCBAD);
+ do {
+ const char *buf;
+ size_t size;
+ if (ls->n) { /* Copy remainder to buffer. */
+ if (ls->sb.n) { /* Move down in buffer. */
+ lua_assert(ls->p + ls->n == ls->sb.buf + ls->sb.n);
+ if (ls->n != ls->sb.n)
+ memmove(ls->sb.buf, ls->p, ls->n);
+ } else { /* Copy from buffer provided by reader. */
+ bcread_resize(ls, len);
+ memcpy(ls->sb.buf, ls->p, ls->n);
+ }
+ ls->p = ls->sb.buf;
+ }
+ ls->sb.n = ls->n;
+ buf = ls->rfunc(ls->L, ls->rdata, &size); /* Get more data from reader. */
+ if (buf == NULL || size == 0) { /* EOF? */
+ if (need) bcread_error(ls, LJ_ERR_BCBAD);
+ ls->current = -1; /* Only bad if we get called again. */
+ break;
+ }
+ if (ls->sb.n) { /* Append to buffer. */
+ MSize n = ls->sb.n + (MSize)size;
+ bcread_resize(ls, n < len ? len : n);
+ memcpy(ls->sb.buf + ls->sb.n, buf, size);
+ ls->n = ls->sb.n = n;
+ ls->p = ls->sb.buf;
+ } else { /* Return buffer provided by reader. */
+ ls->n = (MSize)size;
+ ls->p = buf;
+ }
+ } while (ls->n < len);
+}
+
+/* Need a certain number of bytes. */
+static LJ_AINLINE void bcread_need(LexState *ls, MSize len)
+{
+ if (LJ_UNLIKELY(ls->n < len))
+ bcread_fill(ls, len, 1);
+}
+
+/* Want to read up to a certain number of bytes, but may need less. */
+static LJ_AINLINE void bcread_want(LexState *ls, MSize len)
+{
+ if (LJ_UNLIKELY(ls->n < len))
+ bcread_fill(ls, len, 0);
+}
+
+#define bcread_dec(ls) check_exp(ls->n > 0, ls->n--)
+#define bcread_consume(ls, len) check_exp(ls->n >= (len), ls->n -= (len))
+
+/* Return memory block from buffer. */
+static uint8_t *bcread_mem(LexState *ls, MSize len)
+{
+ uint8_t *p = (uint8_t *)ls->p;
+ bcread_consume(ls, len);
+ ls->p = (char *)p + len;
+ return p;
+}
+
+/* Copy memory block from buffer. */
+static void bcread_block(LexState *ls, void *q, MSize len)
+{
+ memcpy(q, bcread_mem(ls, len), len);
+}
+
+/* Read byte from buffer. */
+static LJ_AINLINE uint32_t bcread_byte(LexState *ls)
+{
+ bcread_dec(ls);
+ return (uint32_t)(uint8_t)*ls->p++;
+}
+
+/* Read ULEB128 value from buffer. */
+static uint32_t bcread_uleb128(LexState *ls)
+{
+ const uint8_t *p = (const uint8_t *)ls->p;
+ uint32_t v = *p++;
+ if (LJ_UNLIKELY(v >= 0x80)) {
+ int sh = 0;
+ v &= 0x7f;
+ do {
+ v |= ((*p & 0x7f) << (sh += 7));
+ bcread_dec(ls);
+ } while (*p++ >= 0x80);
+ }
+ bcread_dec(ls);
+ ls->p = (char *)p;
+ return v;
+}
+
+/* Read top 32 bits of 33 bit ULEB128 value from buffer. */
+static uint32_t bcread_uleb128_33(LexState *ls)
+{
+ const uint8_t *p = (const uint8_t *)ls->p;
+ uint32_t v = (*p++ >> 1);
+ if (LJ_UNLIKELY(v >= 0x40)) {
+ int sh = -1;
+ v &= 0x3f;
+ do {
+ v |= ((*p & 0x7f) << (sh += 7));
+ bcread_dec(ls);
+ } while (*p++ >= 0x80);
+ }
+ bcread_dec(ls);
+ ls->p = (char *)p;
+ return v;
+}
+
+/* -- Bytecode reader ----------------------------------------------------- */
+
+/* Read debug info of a prototype. */
+static void bcread_dbg(LexState *ls, GCproto *pt, MSize sizedbg)
+{
+ void *lineinfo = (void *)proto_lineinfo(pt);
+ bcread_block(ls, lineinfo, sizedbg);
+ /* Swap lineinfo if the endianess differs. */
+ if (bcread_swap(ls) && pt->numline >= 256) {
+ MSize i, n = pt->sizebc-1;
+ if (pt->numline < 65536) {
+ uint16_t *p = (uint16_t *)lineinfo;
+ for (i = 0; i < n; i++) p[i] = (uint16_t)((p[i] >> 8)|(p[i] << 8));
+ } else {
+ uint32_t *p = (uint32_t *)lineinfo;
+ for (i = 0; i < n; i++) p[i] = lj_bswap(p[i]);
+ }
+ }
+}
+
+/* Find pointer to varinfo. */
+static const void *bcread_varinfo(GCproto *pt)
+{
+ const uint8_t *p = proto_uvinfo(pt);
+ MSize n = pt->sizeuv;
+ if (n) while (*p++ || --n) ;
+ return p;
+}
+
+/* Read a single constant key/value of a template table. */
+static void bcread_ktabk(LexState *ls, TValue *o)
+{
+ MSize tp = bcread_uleb128(ls);
+ if (tp >= BCDUMP_KTAB_STR) {
+ MSize len = tp - BCDUMP_KTAB_STR;
+ const char *p = (const char *)bcread_mem(ls, len);
+ setstrV(ls->L, o, lj_str_new(ls->L, p, len));
+ } else if (tp == BCDUMP_KTAB_INT) {
+ setintV(o, (int32_t)bcread_uleb128(ls));
+ } else if (tp == BCDUMP_KTAB_NUM) {
+ o->u32.lo = bcread_uleb128(ls);
+ o->u32.hi = bcread_uleb128(ls);
+ } else {
+ lua_assert(tp <= BCDUMP_KTAB_TRUE);
+ setitype(o, ~tp);
+ }
+}
+
+/* Read a template table. */
+static GCtab *bcread_ktab(LexState *ls)
+{
+ MSize narray = bcread_uleb128(ls);
+ MSize nhash = bcread_uleb128(ls);
+ GCtab *t = lj_tab_new(ls->L, narray, hsize2hbits(nhash));
+ if (narray) { /* Read array entries. */
+ MSize i;
+ TValue *o = tvref(t->array);
+ for (i = 0; i < narray; i++, o++)
+ bcread_ktabk(ls, o);
+ }
+ if (nhash) { /* Read hash entries. */
+ MSize i;
+ for (i = 0; i < nhash; i++) {
+ TValue key;
+ bcread_ktabk(ls, &key);
+ lua_assert(!tvisnil(&key));
+ bcread_ktabk(ls, lj_tab_set(ls->L, t, &key));
+ }
+ }
+ return t;
+}
+
+/* Read GC constants of a prototype. */
+static void bcread_kgc(LexState *ls, GCproto *pt, MSize sizekgc)
+{
+ MSize i;
+ GCRef *kr = mref(pt->k, GCRef) - (ptrdiff_t)sizekgc;
+ for (i = 0; i < sizekgc; i++, kr++) {
+ MSize tp = bcread_uleb128(ls);
+ if (tp >= BCDUMP_KGC_STR) {
+ MSize len = tp - BCDUMP_KGC_STR;
+ const char *p = (const char *)bcread_mem(ls, len);
+ setgcref(*kr, obj2gco(lj_str_new(ls->L, p, len)));
+ } else if (tp == BCDUMP_KGC_TAB) {
+ setgcref(*kr, obj2gco(bcread_ktab(ls)));
+#if LJ_HASFFI
+ } else if (tp != BCDUMP_KGC_CHILD) {
+ CTypeID id = tp == BCDUMP_KGC_COMPLEX ? CTID_COMPLEX_DOUBLE :
+ tp == BCDUMP_KGC_I64 ? CTID_INT64 : CTID_UINT64;
+ CTSize sz = tp == BCDUMP_KGC_COMPLEX ? 16 : 8;
+ GCcdata *cd = lj_cdata_new_(ls->L, id, sz);
+ TValue *p = (TValue *)cdataptr(cd);
+ setgcref(*kr, obj2gco(cd));
+ p[0].u32.lo = bcread_uleb128(ls);
+ p[0].u32.hi = bcread_uleb128(ls);
+ if (tp == BCDUMP_KGC_COMPLEX) {
+ p[1].u32.lo = bcread_uleb128(ls);
+ p[1].u32.hi = bcread_uleb128(ls);
+ }
+#endif
+ } else {
+ lua_State *L = ls->L;
+ lua_assert(tp == BCDUMP_KGC_CHILD);
+ if (L->top <= bcread_oldtop(L, ls)) /* Stack underflow? */
+ bcread_error(ls, LJ_ERR_BCBAD);
+ L->top--;
+ setgcref(*kr, obj2gco(protoV(L->top)));
+ }
+ }
+}
+
+/* Read number constants of a prototype. */
+static void bcread_knum(LexState *ls, GCproto *pt, MSize sizekn)
+{
+ MSize i;
+ TValue *o = mref(pt->k, TValue);
+ for (i = 0; i < sizekn; i++, o++) {
+ int isnum = (ls->p[0] & 1);
+ uint32_t lo = bcread_uleb128_33(ls);
+ if (isnum) {
+ o->u32.lo = lo;
+ o->u32.hi = bcread_uleb128(ls);
+ } else {
+ setintV(o, lo);
+ }
+ }
+}
+
+/* Read bytecode instructions. */
+static void bcread_bytecode(LexState *ls, GCproto *pt, MSize sizebc)
+{
+ BCIns *bc = proto_bc(pt);
+ bc[0] = BCINS_AD((pt->flags & PROTO_VARARG) ? BC_FUNCV : BC_FUNCF,
+ pt->framesize, 0);
+ bcread_block(ls, bc+1, (sizebc-1)*(MSize)sizeof(BCIns));
+ /* Swap bytecode instructions if the endianess differs. */
+ if (bcread_swap(ls)) {
+ MSize i;
+ for (i = 1; i < sizebc; i++) bc[i] = lj_bswap(bc[i]);
+ }
+}
+
+/* Read upvalue refs. */
+static void bcread_uv(LexState *ls, GCproto *pt, MSize sizeuv)
+{
+ if (sizeuv) {
+ uint16_t *uv = proto_uv(pt);
+ bcread_block(ls, uv, sizeuv*2);
+ /* Swap upvalue refs if the endianess differs. */
+ if (bcread_swap(ls)) {
+ MSize i;
+ for (i = 0; i < sizeuv; i++)
+ uv[i] = (uint16_t)((uv[i] >> 8)|(uv[i] << 8));
+ }
+ }
+}
+
+/* Read a prototype. */
+static GCproto *bcread_proto(LexState *ls)
+{
+ GCproto *pt;
+ MSize framesize, numparams, flags, sizeuv, sizekgc, sizekn, sizebc, sizept;
+ MSize ofsk, ofsuv, ofsdbg;
+ MSize sizedbg = 0;
+ BCLine firstline = 0, numline = 0;
+ MSize len, startn;
+
+ /* Read length. */
+ if (ls->n > 0 && ls->p[0] == 0) { /* Shortcut EOF. */
+ ls->n--; ls->p++;
+ return NULL;
+ }
+ bcread_want(ls, 5);
+ len = bcread_uleb128(ls);
+ if (!len) return NULL; /* EOF */
+ bcread_need(ls, len);
+ startn = ls->n;
+
+ /* Read prototype header. */
+ flags = bcread_byte(ls);
+ numparams = bcread_byte(ls);
+ framesize = bcread_byte(ls);
+ sizeuv = bcread_byte(ls);
+ sizekgc = bcread_uleb128(ls);
+ sizekn = bcread_uleb128(ls);
+ sizebc = bcread_uleb128(ls) + 1;
+ if (!(bcread_flags(ls) & BCDUMP_F_STRIP)) {
+ sizedbg = bcread_uleb128(ls);
+ if (sizedbg) {
+ firstline = bcread_uleb128(ls);
+ numline = bcread_uleb128(ls);
+ }
+ }
+
+ /* Calculate total size of prototype including all colocated arrays. */
+ sizept = (MSize)sizeof(GCproto) +
+ sizebc*(MSize)sizeof(BCIns) +
+ sizekgc*(MSize)sizeof(GCRef);
+ sizept = (sizept + (MSize)sizeof(TValue)-1) & ~((MSize)sizeof(TValue)-1);
+ ofsk = sizept; sizept += sizekn*(MSize)sizeof(TValue);
+ ofsuv = sizept; sizept += ((sizeuv+1)&~1)*2;
+ ofsdbg = sizept; sizept += sizedbg;
+
+ /* Allocate prototype object and initialize its fields. */
+ pt = (GCproto *)lj_mem_newgco(ls->L, (MSize)sizept);
+ pt->gct = ~LJ_TPROTO;
+ pt->numparams = (uint8_t)numparams;
+ pt->framesize = (uint8_t)framesize;
+ pt->sizebc = sizebc;
+ setmref(pt->k, (char *)pt + ofsk);
+ setmref(pt->uv, (char *)pt + ofsuv);
+ pt->sizekgc = 0; /* Set to zero until fully initialized. */
+ pt->sizekn = sizekn;
+ pt->sizept = sizept;
+ pt->sizeuv = (uint8_t)sizeuv;
+ pt->flags = (uint8_t)flags;
+ pt->trace = 0;
+ setgcref(pt->chunkname, obj2gco(ls->chunkname));
+
+ /* Close potentially uninitialized gap between bc and kgc. */
+ *(uint32_t *)((char *)pt + ofsk - sizeof(GCRef)*(sizekgc+1)) = 0;
+
+ /* Read bytecode instructions and upvalue refs. */
+ bcread_bytecode(ls, pt, sizebc);
+ bcread_uv(ls, pt, sizeuv);
+
+ /* Read constants. */
+ bcread_kgc(ls, pt, sizekgc);
+ pt->sizekgc = sizekgc;
+ bcread_knum(ls, pt, sizekn);
+
+ /* Read and initialize debug info. */
+ pt->firstline = firstline;
+ pt->numline = numline;
+ if (sizedbg) {
+ MSize sizeli = (sizebc-1) << (numline < 256 ? 0 : numline < 65536 ? 1 : 2);
+ setmref(pt->lineinfo, (char *)pt + ofsdbg);
+ setmref(pt->uvinfo, (char *)pt + ofsdbg + sizeli);
+ bcread_dbg(ls, pt, sizedbg);
+ setmref(pt->varinfo, bcread_varinfo(pt));
+ } else {
+ setmref(pt->lineinfo, NULL);
+ setmref(pt->uvinfo, NULL);
+ setmref(pt->varinfo, NULL);
+ }
+
+ if (len != startn - ls->n)
+ bcread_error(ls, LJ_ERR_BCBAD);
+ return pt;
+}
+
+/* Read and check header of bytecode dump. */
+static int bcread_header(LexState *ls)
+{
+ uint32_t flags;
+ bcread_want(ls, 3+5+5);
+ if (bcread_byte(ls) != BCDUMP_HEAD2 ||
+ bcread_byte(ls) != BCDUMP_HEAD3 ||
+ bcread_byte(ls) != BCDUMP_VERSION) return 0;
+ bcread_flags(ls) = flags = bcread_uleb128(ls);
+ if ((flags & ~(BCDUMP_F_KNOWN)) != 0) return 0;
+ if ((flags & BCDUMP_F_FFI)) {
+#if LJ_HASFFI
+ lua_State *L = ls->L;
+ if (!ctype_ctsG(G(L))) {
+ ptrdiff_t oldtop = savestack(L, L->top);
+ luaopen_ffi(L); /* Load FFI library on-demand. */
+ L->top = restorestack(L, oldtop);
+ }
+#else
+ return 0;
+#endif
+ }
+ if ((flags & BCDUMP_F_STRIP)) {
+ ls->chunkname = lj_str_newz(ls->L, ls->chunkarg);
+ } else {
+ MSize len = bcread_uleb128(ls);
+ bcread_need(ls, len);
+ ls->chunkname = lj_str_new(ls->L, (const char *)bcread_mem(ls, len), len);
+ }
+ return 1; /* Ok. */
+}
+
+/* Read a bytecode dump. */
+GCproto *lj_bcread(LexState *ls)
+{
+ lua_State *L = ls->L;
+ lua_assert(ls->current == BCDUMP_HEAD1);
+ bcread_savetop(L, ls, L->top);
+ lj_str_resetbuf(&ls->sb);
+ /* Check for a valid bytecode dump header. */
+ if (!bcread_header(ls))
+ bcread_error(ls, LJ_ERR_BCFMT);
+ for (;;) { /* Process all prototypes in the bytecode dump. */
+ GCproto *pt = bcread_proto(ls);
+ if (!pt) break;
+ setprotoV(L, L->top, pt);
+ incr_top(L);
+ }
+ if ((int32_t)ls->n > 0 || L->top-1 != bcread_oldtop(L, ls))
+ bcread_error(ls, LJ_ERR_BCBAD);
+ /* Pop off last prototype. */
+ L->top--;
+ return protoV(L->top);
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_bcwrite.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_bcwrite.c
new file mode 100644
index 0000000..fae1ebb
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_bcwrite.c
@@ -0,0 +1,396 @@
+/*
+** Bytecode writer.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_bcwrite_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_str.h"
+#include "lj_bc.h"
+#if LJ_HASFFI
+#include "lj_ctype.h"
+#endif
+#if LJ_HASJIT
+#include "lj_dispatch.h"
+#include "lj_jit.h"
+#endif
+#include "lj_bcdump.h"
+#include "lj_vm.h"
+
+/* Context for bytecode writer. */
+typedef struct BCWriteCtx {
+ SBuf sb; /* Output buffer. */
+ lua_State *L; /* Lua state. */
+ GCproto *pt; /* Root prototype. */
+ lua_Writer wfunc; /* Writer callback. */
+ void *wdata; /* Writer callback data. */
+ int strip; /* Strip debug info. */
+ int status; /* Status from writer callback. */
+} BCWriteCtx;
+
+/* -- Output buffer handling ---------------------------------------------- */
+
+/* Resize buffer if needed. */
+static LJ_NOINLINE void bcwrite_resize(BCWriteCtx *ctx, MSize len)
+{
+ MSize sz = ctx->sb.sz * 2;
+ while (ctx->sb.n + len > sz) sz = sz * 2;
+ lj_str_resizebuf(ctx->L, &ctx->sb, sz);
+}
+
+/* Need a certain amount of buffer space. */
+static LJ_AINLINE void bcwrite_need(BCWriteCtx *ctx, MSize len)
+{
+ if (LJ_UNLIKELY(ctx->sb.n + len > ctx->sb.sz))
+ bcwrite_resize(ctx, len);
+}
+
+/* Add memory block to buffer. */
+static void bcwrite_block(BCWriteCtx *ctx, const void *p, MSize len)
+{
+ uint8_t *q = (uint8_t *)(ctx->sb.buf + ctx->sb.n);
+ MSize i;
+ ctx->sb.n += len;
+ for (i = 0; i < len; i++) q[i] = ((uint8_t *)p)[i];
+}
+
+/* Add byte to buffer. */
+static LJ_AINLINE void bcwrite_byte(BCWriteCtx *ctx, uint8_t b)
+{
+ ctx->sb.buf[ctx->sb.n++] = b;
+}
+
+/* Add ULEB128 value to buffer. */
+static void bcwrite_uleb128(BCWriteCtx *ctx, uint32_t v)
+{
+ MSize n = ctx->sb.n;
+ uint8_t *p = (uint8_t *)ctx->sb.buf;
+ for (; v >= 0x80; v >>= 7)
+ p[n++] = (uint8_t)((v & 0x7f) | 0x80);
+ p[n++] = (uint8_t)v;
+ ctx->sb.n = n;
+}
+
+/* -- Bytecode writer ----------------------------------------------------- */
+
+/* Write a single constant key/value of a template table. */
+static void bcwrite_ktabk(BCWriteCtx *ctx, cTValue *o, int narrow)
+{
+ bcwrite_need(ctx, 1+10);
+ if (tvisstr(o)) {
+ const GCstr *str = strV(o);
+ MSize len = str->len;
+ bcwrite_need(ctx, 5+len);
+ bcwrite_uleb128(ctx, BCDUMP_KTAB_STR+len);
+ bcwrite_block(ctx, strdata(str), len);
+ } else if (tvisint(o)) {
+ bcwrite_byte(ctx, BCDUMP_KTAB_INT);
+ bcwrite_uleb128(ctx, intV(o));
+ } else if (tvisnum(o)) {
+ if (!LJ_DUALNUM && narrow) { /* Narrow number constants to integers. */
+ lua_Number num = numV(o);
+ int32_t k = lj_num2int(num);
+ if (num == (lua_Number)k) { /* -0 is never a constant. */
+ bcwrite_byte(ctx, BCDUMP_KTAB_INT);
+ bcwrite_uleb128(ctx, k);
+ return;
+ }
+ }
+ bcwrite_byte(ctx, BCDUMP_KTAB_NUM);
+ bcwrite_uleb128(ctx, o->u32.lo);
+ bcwrite_uleb128(ctx, o->u32.hi);
+ } else {
+ lua_assert(tvispri(o));
+ bcwrite_byte(ctx, BCDUMP_KTAB_NIL+~itype(o));
+ }
+}
+
+/* Write a template table. */
+static void bcwrite_ktab(BCWriteCtx *ctx, const GCtab *t)
+{
+ MSize narray = 0, nhash = 0;
+ if (t->asize > 0) { /* Determine max. length of array part. */
+ ptrdiff_t i;
+ TValue *array = tvref(t->array);
+ for (i = (ptrdiff_t)t->asize-1; i >= 0; i--)
+ if (!tvisnil(&array[i]))
+ break;
+ narray = (MSize)(i+1);
+ }
+ if (t->hmask > 0) { /* Count number of used hash slots. */
+ MSize i, hmask = t->hmask;
+ Node *node = noderef(t->node);
+ for (i = 0; i <= hmask; i++)
+ nhash += !tvisnil(&node[i].val);
+ }
+ /* Write number of array slots and hash slots. */
+ bcwrite_uleb128(ctx, narray);
+ bcwrite_uleb128(ctx, nhash);
+ if (narray) { /* Write array entries (may contain nil). */
+ MSize i;
+ TValue *o = tvref(t->array);
+ for (i = 0; i < narray; i++, o++)
+ bcwrite_ktabk(ctx, o, 1);
+ }
+ if (nhash) { /* Write hash entries. */
+ MSize i = nhash;
+ Node *node = noderef(t->node) + t->hmask;
+ for (;; node--)
+ if (!tvisnil(&node->val)) {
+ bcwrite_ktabk(ctx, &node->key, 0);
+ bcwrite_ktabk(ctx, &node->val, 1);
+ if (--i == 0) break;
+ }
+ }
+}
+
+/* Write GC constants of a prototype. */
+static void bcwrite_kgc(BCWriteCtx *ctx, GCproto *pt)
+{
+ MSize i, sizekgc = pt->sizekgc;
+ GCRef *kr = mref(pt->k, GCRef) - (ptrdiff_t)sizekgc;
+ for (i = 0; i < sizekgc; i++, kr++) {
+ GCobj *o = gcref(*kr);
+ MSize tp, need = 1;
+ /* Determine constant type and needed size. */
+ if (o->gch.gct == ~LJ_TSTR) {
+ tp = BCDUMP_KGC_STR + gco2str(o)->len;
+ need = 5+gco2str(o)->len;
+ } else if (o->gch.gct == ~LJ_TPROTO) {
+ lua_assert((pt->flags & PROTO_CHILD));
+ tp = BCDUMP_KGC_CHILD;
+#if LJ_HASFFI
+ } else if (o->gch.gct == ~LJ_TCDATA) {
+ CTypeID id = gco2cd(o)->ctypeid;
+ need = 1+4*5;
+ if (id == CTID_INT64) {
+ tp = BCDUMP_KGC_I64;
+ } else if (id == CTID_UINT64) {
+ tp = BCDUMP_KGC_U64;
+ } else {
+ lua_assert(id == CTID_COMPLEX_DOUBLE);
+ tp = BCDUMP_KGC_COMPLEX;
+ }
+#endif
+ } else {
+ lua_assert(o->gch.gct == ~LJ_TTAB);
+ tp = BCDUMP_KGC_TAB;
+ need = 1+2*5;
+ }
+ /* Write constant type. */
+ bcwrite_need(ctx, need);
+ bcwrite_uleb128(ctx, tp);
+ /* Write constant data (if any). */
+ if (tp >= BCDUMP_KGC_STR) {
+ bcwrite_block(ctx, strdata(gco2str(o)), gco2str(o)->len);
+ } else if (tp == BCDUMP_KGC_TAB) {
+ bcwrite_ktab(ctx, gco2tab(o));
+#if LJ_HASFFI
+ } else if (tp != BCDUMP_KGC_CHILD) {
+ cTValue *p = (TValue *)cdataptr(gco2cd(o));
+ bcwrite_uleb128(ctx, p[0].u32.lo);
+ bcwrite_uleb128(ctx, p[0].u32.hi);
+ if (tp == BCDUMP_KGC_COMPLEX) {
+ bcwrite_uleb128(ctx, p[1].u32.lo);
+ bcwrite_uleb128(ctx, p[1].u32.hi);
+ }
+#endif
+ }
+ }
+}
+
+/* Write number constants of a prototype. */
+static void bcwrite_knum(BCWriteCtx *ctx, GCproto *pt)
+{
+ MSize i, sizekn = pt->sizekn;
+ cTValue *o = mref(pt->k, TValue);
+ bcwrite_need(ctx, 10*sizekn);
+ for (i = 0; i < sizekn; i++, o++) {
+ int32_t k;
+ if (tvisint(o)) {
+ k = intV(o);
+ goto save_int;
+ } else {
+ /* Write a 33 bit ULEB128 for the int (lsb=0) or loword (lsb=1). */
+ if (!LJ_DUALNUM) { /* Narrow number constants to integers. */
+ lua_Number num = numV(o);
+ k = lj_num2int(num);
+ if (num == (lua_Number)k) { /* -0 is never a constant. */
+ save_int:
+ bcwrite_uleb128(ctx, 2*(uint32_t)k | ((uint32_t)k & 0x80000000u));
+ if (k < 0) {
+ char *p = &ctx->sb.buf[ctx->sb.n-1];
+ *p = (*p & 7) | ((k>>27) & 0x18);
+ }
+ continue;
+ }
+ }
+ bcwrite_uleb128(ctx, 1+(2*o->u32.lo | (o->u32.lo & 0x80000000u)));
+ if (o->u32.lo >= 0x80000000u) {
+ char *p = &ctx->sb.buf[ctx->sb.n-1];
+ *p = (*p & 7) | ((o->u32.lo>>27) & 0x18);
+ }
+ bcwrite_uleb128(ctx, o->u32.hi);
+ }
+ }
+}
+
+/* Write bytecode instructions. */
+static void bcwrite_bytecode(BCWriteCtx *ctx, GCproto *pt)
+{
+ MSize nbc = pt->sizebc-1; /* Omit the [JI]FUNC* header. */
+#if LJ_HASJIT
+ uint8_t *p = (uint8_t *)&ctx->sb.buf[ctx->sb.n];
+#endif
+ bcwrite_block(ctx, proto_bc(pt)+1, nbc*(MSize)sizeof(BCIns));
+#if LJ_HASJIT
+ /* Unpatch modified bytecode containing ILOOP/JLOOP etc. */
+ if ((pt->flags & PROTO_ILOOP) || pt->trace) {
+ jit_State *J = L2J(ctx->L);
+ MSize i;
+ for (i = 0; i < nbc; i++, p += sizeof(BCIns)) {
+ BCOp op = (BCOp)p[LJ_ENDIAN_SELECT(0, 3)];
+ if (op == BC_IFORL || op == BC_IITERL || op == BC_ILOOP ||
+ op == BC_JFORI) {
+ p[LJ_ENDIAN_SELECT(0, 3)] = (uint8_t)(op-BC_IFORL+BC_FORL);
+ } else if (op == BC_JFORL || op == BC_JITERL || op == BC_JLOOP) {
+ BCReg rd = p[LJ_ENDIAN_SELECT(2, 1)] + (p[LJ_ENDIAN_SELECT(3, 0)] << 8);
+ BCIns ins = traceref(J, rd)->startins;
+ p[LJ_ENDIAN_SELECT(0, 3)] = (uint8_t)(op-BC_JFORL+BC_FORL);
+ p[LJ_ENDIAN_SELECT(2, 1)] = bc_c(ins);
+ p[LJ_ENDIAN_SELECT(3, 0)] = bc_b(ins);
+ }
+ }
+ }
+#endif
+}
+
+/* Write prototype. */
+static void bcwrite_proto(BCWriteCtx *ctx, GCproto *pt)
+{
+ MSize sizedbg = 0;
+
+ /* Recursively write children of prototype. */
+ if ((pt->flags & PROTO_CHILD)) {
+ ptrdiff_t i, n = pt->sizekgc;
+ GCRef *kr = mref(pt->k, GCRef) - 1;
+ for (i = 0; i < n; i++, kr--) {
+ GCobj *o = gcref(*kr);
+ if (o->gch.gct == ~LJ_TPROTO)
+ bcwrite_proto(ctx, gco2pt(o));
+ }
+ }
+
+ /* Start writing the prototype info to a buffer. */
+ lj_str_resetbuf(&ctx->sb);
+ ctx->sb.n = 5; /* Leave room for final size. */
+ bcwrite_need(ctx, 4+6*5+(pt->sizebc-1)*(MSize)sizeof(BCIns)+pt->sizeuv*2);
+
+ /* Write prototype header. */
+ bcwrite_byte(ctx, (pt->flags & (PROTO_CHILD|PROTO_VARARG|PROTO_FFI)));
+ bcwrite_byte(ctx, pt->numparams);
+ bcwrite_byte(ctx, pt->framesize);
+ bcwrite_byte(ctx, pt->sizeuv);
+ bcwrite_uleb128(ctx, pt->sizekgc);
+ bcwrite_uleb128(ctx, pt->sizekn);
+ bcwrite_uleb128(ctx, pt->sizebc-1);
+ if (!ctx->strip) {
+ if (proto_lineinfo(pt))
+ sizedbg = pt->sizept - (MSize)((char *)proto_lineinfo(pt) - (char *)pt);
+ bcwrite_uleb128(ctx, sizedbg);
+ if (sizedbg) {
+ bcwrite_uleb128(ctx, pt->firstline);
+ bcwrite_uleb128(ctx, pt->numline);
+ }
+ }
+
+ /* Write bytecode instructions and upvalue refs. */
+ bcwrite_bytecode(ctx, pt);
+ bcwrite_block(ctx, proto_uv(pt), pt->sizeuv*2);
+
+ /* Write constants. */
+ bcwrite_kgc(ctx, pt);
+ bcwrite_knum(ctx, pt);
+
+ /* Write debug info, if not stripped. */
+ if (sizedbg) {
+ bcwrite_need(ctx, sizedbg);
+ bcwrite_block(ctx, proto_lineinfo(pt), sizedbg);
+ }
+
+ /* Pass buffer to writer function. */
+ if (ctx->status == 0) {
+ MSize n = ctx->sb.n - 5;
+ MSize nn = (lj_fls(n)+8)*9 >> 6;
+ ctx->sb.n = 5 - nn;
+ bcwrite_uleb128(ctx, n); /* Fill in final size. */
+ lua_assert(ctx->sb.n == 5);
+ ctx->status = ctx->wfunc(ctx->L, ctx->sb.buf+5-nn, nn+n, ctx->wdata);
+ }
+}
+
+/* Write header of bytecode dump. */
+static void bcwrite_header(BCWriteCtx *ctx)
+{
+ GCstr *chunkname = proto_chunkname(ctx->pt);
+ const char *name = strdata(chunkname);
+ MSize len = chunkname->len;
+ lj_str_resetbuf(&ctx->sb);
+ bcwrite_need(ctx, 5+5+len);
+ bcwrite_byte(ctx, BCDUMP_HEAD1);
+ bcwrite_byte(ctx, BCDUMP_HEAD2);
+ bcwrite_byte(ctx, BCDUMP_HEAD3);
+ bcwrite_byte(ctx, BCDUMP_VERSION);
+ bcwrite_byte(ctx, (ctx->strip ? BCDUMP_F_STRIP : 0) +
+ (LJ_BE ? BCDUMP_F_BE : 0) +
+ ((ctx->pt->flags & PROTO_FFI) ? BCDUMP_F_FFI : 0));
+ if (!ctx->strip) {
+ bcwrite_uleb128(ctx, len);
+ bcwrite_block(ctx, name, len);
+ }
+ ctx->status = ctx->wfunc(ctx->L, ctx->sb.buf, ctx->sb.n, ctx->wdata);
+}
+
+/* Write footer of bytecode dump. */
+static void bcwrite_footer(BCWriteCtx *ctx)
+{
+ if (ctx->status == 0) {
+ uint8_t zero = 0;
+ ctx->status = ctx->wfunc(ctx->L, &zero, 1, ctx->wdata);
+ }
+}
+
+/* Protected callback for bytecode writer. */
+static TValue *cpwriter(lua_State *L, lua_CFunction dummy, void *ud)
+{
+ BCWriteCtx *ctx = (BCWriteCtx *)ud;
+ UNUSED(dummy);
+ lj_str_resizebuf(L, &ctx->sb, 1024); /* Avoids resize for most prototypes. */
+ bcwrite_header(ctx);
+ bcwrite_proto(ctx, ctx->pt);
+ bcwrite_footer(ctx);
+ return NULL;
+}
+
+/* Write bytecode for a prototype. */
+int lj_bcwrite(lua_State *L, GCproto *pt, lua_Writer writer, void *data,
+ int strip)
+{
+ BCWriteCtx ctx;
+ int status;
+ ctx.L = L;
+ ctx.pt = pt;
+ ctx.wfunc = writer;
+ ctx.wdata = data;
+ ctx.strip = strip;
+ ctx.status = 0;
+ lj_str_initbuf(&ctx.sb);
+ status = lj_vm_cpcall(L, NULL, &ctx, cpwriter);
+ if (status == 0) status = ctx.status;
+ lj_str_freebuf(G(ctx.L), &ctx.sb);
+ return status;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_carith.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_carith.c
new file mode 100644
index 0000000..c34596c
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_carith.c
@@ -0,0 +1,362 @@
+/*
+** C data arithmetic.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#include "lj_obj.h"
+
+#if LJ_HASFFI
+
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_tab.h"
+#include "lj_meta.h"
+#include "lj_ctype.h"
+#include "lj_cconv.h"
+#include "lj_cdata.h"
+#include "lj_carith.h"
+
+/* -- C data arithmetic --------------------------------------------------- */
+
+/* Binary operands of an operator converted to ctypes. */
+typedef struct CDArith {
+ uint8_t *p[2];
+ CType *ct[2];
+} CDArith;
+
+/* Check arguments for arithmetic metamethods. */
+static int carith_checkarg(lua_State *L, CTState *cts, CDArith *ca)
+{
+ TValue *o = L->base;
+ int ok = 1;
+ MSize i;
+ if (o+1 >= L->top)
+ lj_err_argt(L, 1, LUA_TCDATA);
+ for (i = 0; i < 2; i++, o++) {
+ if (tviscdata(o)) {
+ GCcdata *cd = cdataV(o);
+ CTypeID id = (CTypeID)cd->ctypeid;
+ CType *ct = ctype_raw(cts, id);
+ uint8_t *p = (uint8_t *)cdataptr(cd);
+ if (ctype_isptr(ct->info)) {
+ p = (uint8_t *)cdata_getptr(p, ct->size);
+ if (ctype_isref(ct->info)) ct = ctype_rawchild(cts, ct);
+ } else if (ctype_isfunc(ct->info)) {
+ p = (uint8_t *)*(void **)p;
+ ct = ctype_get(cts,
+ lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR));
+ }
+ if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);
+ ca->ct[i] = ct;
+ ca->p[i] = p;
+ } else if (tvisint(o)) {
+ ca->ct[i] = ctype_get(cts, CTID_INT32);
+ ca->p[i] = (uint8_t *)&o->i;
+ } else if (tvisnum(o)) {
+ ca->ct[i] = ctype_get(cts, CTID_DOUBLE);
+ ca->p[i] = (uint8_t *)&o->n;
+ } else if (tvisnil(o)) {
+ ca->ct[i] = ctype_get(cts, CTID_P_VOID);
+ ca->p[i] = (uint8_t *)0;
+ } else if (tvisstr(o)) {
+ TValue *o2 = i == 0 ? o+1 : o-1;
+ CType *ct = ctype_raw(cts, cdataV(o2)->ctypeid);
+ ca->ct[i] = NULL;
+ ca->p[i] = (uint8_t *)strVdata(o);
+ ok = 0;
+ if (ctype_isenum(ct->info)) {
+ CTSize ofs;
+ CType *cct = lj_ctype_getfield(cts, ct, strV(o), &ofs);
+ if (cct && ctype_isconstval(cct->info)) {
+ ca->ct[i] = ctype_child(cts, cct);
+ ca->p[i] = (uint8_t *)&cct->size; /* Assumes ct does not grow. */
+ ok = 1;
+ } else {
+ ca->ct[1-i] = ct; /* Use enum to improve error message. */
+ ca->p[1-i] = NULL;
+ break;
+ }
+ }
+ } else {
+ ca->ct[i] = NULL;
+ ca->p[i] = (void *)(intptr_t)1; /* To make it unequal. */
+ ok = 0;
+ }
+ }
+ return ok;
+}
+
+/* Pointer arithmetic. */
+static int carith_ptr(lua_State *L, CTState *cts, CDArith *ca, MMS mm)
+{
+ CType *ctp = ca->ct[0];
+ uint8_t *pp = ca->p[0];
+ ptrdiff_t idx;
+ CTSize sz;
+ CTypeID id;
+ GCcdata *cd;
+ if (ctype_isptr(ctp->info) || ctype_isrefarray(ctp->info)) {
+ if ((mm == MM_sub || mm == MM_eq || mm == MM_lt || mm == MM_le) &&
+ (ctype_isptr(ca->ct[1]->info) || ctype_isrefarray(ca->ct[1]->info))) {
+ uint8_t *pp2 = ca->p[1];
+ if (mm == MM_eq) { /* Pointer equality. Incompatible pointers are ok. */
+ setboolV(L->top-1, (pp == pp2));
+ return 1;
+ }
+ if (!lj_cconv_compatptr(cts, ctp, ca->ct[1], CCF_IGNQUAL))
+ return 0;
+ if (mm == MM_sub) { /* Pointer difference. */
+ intptr_t diff;
+ sz = lj_ctype_size(cts, ctype_cid(ctp->info)); /* Element size. */
+ if (sz == 0 || sz == CTSIZE_INVALID)
+ return 0;
+ diff = ((intptr_t)pp - (intptr_t)pp2) / (int32_t)sz;
+ /* All valid pointer differences on x64 are in (-2^47, +2^47),
+ ** which fits into a double without loss of precision.
+ */
+ setintptrV(L->top-1, (int32_t)diff);
+ return 1;
+ } else if (mm == MM_lt) { /* Pointer comparison (unsigned). */
+ setboolV(L->top-1, ((uintptr_t)pp < (uintptr_t)pp2));
+ return 1;
+ } else {
+ lua_assert(mm == MM_le);
+ setboolV(L->top-1, ((uintptr_t)pp <= (uintptr_t)pp2));
+ return 1;
+ }
+ }
+ if (!((mm == MM_add || mm == MM_sub) && ctype_isnum(ca->ct[1]->info)))
+ return 0;
+ lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), ca->ct[1],
+ (uint8_t *)&idx, ca->p[1], 0);
+ if (mm == MM_sub) idx = -idx;
+ } else if (mm == MM_add && ctype_isnum(ctp->info) &&
+ (ctype_isptr(ca->ct[1]->info) || ctype_isrefarray(ca->ct[1]->info))) {
+ /* Swap pointer and index. */
+ ctp = ca->ct[1]; pp = ca->p[1];
+ lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), ca->ct[0],
+ (uint8_t *)&idx, ca->p[0], 0);
+ } else {
+ return 0;
+ }
+ sz = lj_ctype_size(cts, ctype_cid(ctp->info)); /* Element size. */
+ if (sz == CTSIZE_INVALID)
+ return 0;
+ pp += idx*(int32_t)sz; /* Compute pointer + index. */
+ id = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(ctp->info)),
+ CTSIZE_PTR);
+ cd = lj_cdata_new(cts, id, CTSIZE_PTR);
+ *(uint8_t **)cdataptr(cd) = pp;
+ setcdataV(L, L->top-1, cd);
+ lj_gc_check(L);
+ return 1;
+}
+
+/* 64 bit integer arithmetic. */
+static int carith_int64(lua_State *L, CTState *cts, CDArith *ca, MMS mm)
+{
+ if (ctype_isnum(ca->ct[0]->info) && ca->ct[0]->size <= 8 &&
+ ctype_isnum(ca->ct[1]->info) && ca->ct[1]->size <= 8) {
+ CTypeID id = (((ca->ct[0]->info & CTF_UNSIGNED) && ca->ct[0]->size == 8) ||
+ ((ca->ct[1]->info & CTF_UNSIGNED) && ca->ct[1]->size == 8)) ?
+ CTID_UINT64 : CTID_INT64;
+ CType *ct = ctype_get(cts, id);
+ GCcdata *cd;
+ uint64_t u0, u1, *up;
+ lj_cconv_ct_ct(cts, ct, ca->ct[0], (uint8_t *)&u0, ca->p[0], 0);
+ if (mm != MM_unm)
+ lj_cconv_ct_ct(cts, ct, ca->ct[1], (uint8_t *)&u1, ca->p[1], 0);
+ switch (mm) {
+ case MM_eq:
+ setboolV(L->top-1, (u0 == u1));
+ return 1;
+ case MM_lt:
+ setboolV(L->top-1,
+ id == CTID_INT64 ? ((int64_t)u0 < (int64_t)u1) : (u0 < u1));
+ return 1;
+ case MM_le:
+ setboolV(L->top-1,
+ id == CTID_INT64 ? ((int64_t)u0 <= (int64_t)u1) : (u0 <= u1));
+ return 1;
+ default: break;
+ }
+ cd = lj_cdata_new(cts, id, 8);
+ up = (uint64_t *)cdataptr(cd);
+ setcdataV(L, L->top-1, cd);
+ switch (mm) {
+ case MM_add: *up = u0 + u1; break;
+ case MM_sub: *up = u0 - u1; break;
+ case MM_mul: *up = u0 * u1; break;
+ case MM_div:
+ if (id == CTID_INT64)
+ *up = (uint64_t)lj_carith_divi64((int64_t)u0, (int64_t)u1);
+ else
+ *up = lj_carith_divu64(u0, u1);
+ break;
+ case MM_mod:
+ if (id == CTID_INT64)
+ *up = (uint64_t)lj_carith_modi64((int64_t)u0, (int64_t)u1);
+ else
+ *up = lj_carith_modu64(u0, u1);
+ break;
+ case MM_pow:
+ if (id == CTID_INT64)
+ *up = (uint64_t)lj_carith_powi64((int64_t)u0, (int64_t)u1);
+ else
+ *up = lj_carith_powu64(u0, u1);
+ break;
+ case MM_unm: *up = (uint64_t)-(int64_t)u0; break;
+ default: lua_assert(0); break;
+ }
+ lj_gc_check(L);
+ return 1;
+ }
+ return 0;
+}
+
+/* Handle ctype arithmetic metamethods. */
+static int lj_carith_meta(lua_State *L, CTState *cts, CDArith *ca, MMS mm)
+{
+ cTValue *tv = NULL;
+ if (tviscdata(L->base)) {
+ CTypeID id = cdataV(L->base)->ctypeid;
+ CType *ct = ctype_raw(cts, id);
+ if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);
+ tv = lj_ctype_meta(cts, id, mm);
+ }
+ if (!tv && L->base+1 < L->top && tviscdata(L->base+1)) {
+ CTypeID id = cdataV(L->base+1)->ctypeid;
+ CType *ct = ctype_raw(cts, id);
+ if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);
+ tv = lj_ctype_meta(cts, id, mm);
+ }
+ if (!tv) {
+ const char *repr[2];
+ int i, isenum = -1, isstr = -1;
+ if (mm == MM_eq) { /* Equality checks never raise an error. */
+ int eq = ca->p[0] == ca->p[1];
+ setboolV(L->top-1, eq);
+ setboolV(&G(L)->tmptv2, eq); /* Remember for trace recorder. */
+ return 1;
+ }
+ for (i = 0; i < 2; i++) {
+ if (ca->ct[i] && tviscdata(L->base+i)) {
+ if (ctype_isenum(ca->ct[i]->info)) isenum = i;
+ repr[i] = strdata(lj_ctype_repr(L, ctype_typeid(cts, ca->ct[i]), NULL));
+ } else {
+ if (tvisstr(&L->base[i])) isstr = i;
+ repr[i] = lj_typename(&L->base[i]);
+ }
+ }
+ if ((isenum ^ isstr) == 1)
+ lj_err_callerv(L, LJ_ERR_FFI_BADCONV, repr[isstr], repr[isenum]);
+ lj_err_callerv(L, mm == MM_len ? LJ_ERR_FFI_BADLEN :
+ mm == MM_concat ? LJ_ERR_FFI_BADCONCAT :
+ mm < MM_add ? LJ_ERR_FFI_BADCOMP : LJ_ERR_FFI_BADARITH,
+ repr[0], repr[1]);
+ }
+ return lj_meta_tailcall(L, tv);
+}
+
+/* Arithmetic operators for cdata. */
+int lj_carith_op(lua_State *L, MMS mm)
+{
+ CTState *cts = ctype_cts(L);
+ CDArith ca;
+ if (carith_checkarg(L, cts, &ca)) {
+ if (carith_int64(L, cts, &ca, mm) || carith_ptr(L, cts, &ca, mm)) {
+ copyTV(L, &G(L)->tmptv2, L->top-1); /* Remember for trace recorder. */
+ return 1;
+ }
+ }
+ return lj_carith_meta(L, cts, &ca, mm);
+}
+
+/* No built-in functionality for length of cdata. */
+int lj_carith_len(lua_State *L)
+{
+ CTState *cts = ctype_cts(L);
+ CDArith ca;
+ carith_checkarg(L, cts, &ca);
+ return lj_carith_meta(L, cts, &ca, MM_len);
+}
+
+/* -- 64 bit integer arithmetic helpers ----------------------------------- */
+
+#if LJ_32 && LJ_HASJIT
+/* Signed/unsigned 64 bit multiplication. */
+int64_t lj_carith_mul64(int64_t a, int64_t b)
+{
+ return a * b;
+}
+#endif
+
+/* Unsigned 64 bit division. */
+uint64_t lj_carith_divu64(uint64_t a, uint64_t b)
+{
+ if (b == 0) return U64x(80000000,00000000);
+ return a / b;
+}
+
+/* Signed 64 bit division. */
+int64_t lj_carith_divi64(int64_t a, int64_t b)
+{
+ if (b == 0 || (a == (int64_t)U64x(80000000,00000000) && b == -1))
+ return U64x(80000000,00000000);
+ return a / b;
+}
+
+/* Unsigned 64 bit modulo. */
+uint64_t lj_carith_modu64(uint64_t a, uint64_t b)
+{
+ if (b == 0) return U64x(80000000,00000000);
+ return a % b;
+}
+
+/* Signed 64 bit modulo. */
+int64_t lj_carith_modi64(int64_t a, int64_t b)
+{
+ if (b == 0) return U64x(80000000,00000000);
+ if (a == (int64_t)U64x(80000000,00000000) && b == -1) return 0;
+ return a % b;
+}
+
+/* Unsigned 64 bit x^k. */
+uint64_t lj_carith_powu64(uint64_t x, uint64_t k)
+{
+ uint64_t y;
+ if (k == 0)
+ return 1;
+ for (; (k & 1) == 0; k >>= 1) x *= x;
+ y = x;
+ if ((k >>= 1) != 0) {
+ for (;;) {
+ x *= x;
+ if (k == 1) break;
+ if (k & 1) y *= x;
+ k >>= 1;
+ }
+ y *= x;
+ }
+ return y;
+}
+
+/* Signed 64 bit x^k. */
+int64_t lj_carith_powi64(int64_t x, int64_t k)
+{
+ if (k == 0)
+ return 1;
+ if (k < 0) {
+ if (x == 0)
+ return U64x(7fffffff,ffffffff);
+ else if (x == 1)
+ return 1;
+ else if (x == -1)
+ return (k & 1) ? -1 : 1;
+ else
+ return 0;
+ }
+ return (int64_t)lj_carith_powu64((uint64_t)x, (uint64_t)k);
+}
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_carith.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_carith.h
new file mode 100644
index 0000000..82fc824
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_carith.h
@@ -0,0 +1,28 @@
+/*
+** C data arithmetic.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_CARITH_H
+#define _LJ_CARITH_H
+
+#include "lj_obj.h"
+
+#if LJ_HASFFI
+
+LJ_FUNC int lj_carith_op(lua_State *L, MMS mm);
+LJ_FUNC int lj_carith_len(lua_State *L);
+
+#if LJ_32 && LJ_HASJIT
+LJ_FUNC int64_t lj_carith_mul64(int64_t x, int64_t k);
+#endif
+LJ_FUNC uint64_t lj_carith_divu64(uint64_t a, uint64_t b);
+LJ_FUNC int64_t lj_carith_divi64(int64_t a, int64_t b);
+LJ_FUNC uint64_t lj_carith_modu64(uint64_t a, uint64_t b);
+LJ_FUNC int64_t lj_carith_modi64(int64_t a, int64_t b);
+LJ_FUNC uint64_t lj_carith_powu64(uint64_t x, uint64_t k);
+LJ_FUNC int64_t lj_carith_powi64(int64_t x, int64_t k);
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_ccall.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_ccall.c
new file mode 100644
index 0000000..65076e7
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_ccall.c
@@ -0,0 +1,900 @@
+/*
+** FFI C call handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#include "lj_obj.h"
+
+#if LJ_HASFFI
+
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_ctype.h"
+#include "lj_cconv.h"
+#include "lj_cdata.h"
+#include "lj_ccall.h"
+#include "lj_trace.h"
+
+/* Target-specific handling of register arguments. */
+#if LJ_TARGET_X86
+/* -- x86 calling conventions --------------------------------------------- */
+
+#if LJ_ABI_WIN
+
+#define CCALL_HANDLE_STRUCTRET \
+ /* Return structs bigger than 8 by reference (on stack only). */ \
+ cc->retref = (sz > 8); \
+ if (cc->retref) cc->stack[nsp++] = (GPRArg)dp;
+
+#define CCALL_HANDLE_COMPLEXRET CCALL_HANDLE_STRUCTRET
+
+#else
+
+#if LJ_TARGET_OSX
+
+#define CCALL_HANDLE_STRUCTRET \
+ /* Return structs of size 1, 2, 4 or 8 in registers. */ \
+ cc->retref = !(sz == 1 || sz == 2 || sz == 4 || sz == 8); \
+ if (cc->retref) { \
+ if (ngpr < maxgpr) \
+ cc->gpr[ngpr++] = (GPRArg)dp; \
+ else \
+ cc->stack[nsp++] = (GPRArg)dp; \
+ } else { /* Struct with single FP field ends up in FPR. */ \
+ cc->resx87 = ccall_classify_struct(cts, ctr); \
+ }
+
+#define CCALL_HANDLE_STRUCTRET2 \
+ if (cc->resx87) sp = (uint8_t *)&cc->fpr[0]; \
+ memcpy(dp, sp, ctr->size);
+
+#else
+
+#define CCALL_HANDLE_STRUCTRET \
+ cc->retref = 1; /* Return all structs by reference (in reg or on stack). */ \
+ if (ngpr < maxgpr) \
+ cc->gpr[ngpr++] = (GPRArg)dp; \
+ else \
+ cc->stack[nsp++] = (GPRArg)dp;
+
+#endif
+
+#define CCALL_HANDLE_COMPLEXRET \
+ /* Return complex float in GPRs and complex double by reference. */ \
+ cc->retref = (sz > 8); \
+ if (cc->retref) { \
+ if (ngpr < maxgpr) \
+ cc->gpr[ngpr++] = (GPRArg)dp; \
+ else \
+ cc->stack[nsp++] = (GPRArg)dp; \
+ }
+
+#endif
+
+#define CCALL_HANDLE_COMPLEXRET2 \
+ if (!cc->retref) \
+ *(int64_t *)dp = *(int64_t *)sp; /* Copy complex float from GPRs. */
+
+#define CCALL_HANDLE_STRUCTARG \
+ ngpr = maxgpr; /* Pass all structs by value on the stack. */
+
+#define CCALL_HANDLE_COMPLEXARG \
+ isfp = 1; /* Pass complex by value on stack. */
+
+#define CCALL_HANDLE_REGARG \
+ if (!isfp) { /* Only non-FP values may be passed in registers. */ \
+ if (n > 1) { /* Anything > 32 bit is passed on the stack. */ \
+ if (!LJ_ABI_WIN) ngpr = maxgpr; /* Prevent reordering. */ \
+ } else if (ngpr + 1 <= maxgpr) { \
+ dp = &cc->gpr[ngpr]; \
+ ngpr += n; \
+ goto done; \
+ } \
+ }
+
+#elif LJ_TARGET_X64 && LJ_ABI_WIN
+/* -- Windows/x64 calling conventions ------------------------------------- */
+
+#define CCALL_HANDLE_STRUCTRET \
+ /* Return structs of size 1, 2, 4 or 8 in a GPR. */ \
+ cc->retref = !(sz == 1 || sz == 2 || sz == 4 || sz == 8); \
+ if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp;
+
+#define CCALL_HANDLE_COMPLEXRET CCALL_HANDLE_STRUCTRET
+
+#define CCALL_HANDLE_COMPLEXRET2 \
+ if (!cc->retref) \
+ *(int64_t *)dp = *(int64_t *)sp; /* Copy complex float from GPRs. */
+
+#define CCALL_HANDLE_STRUCTARG \
+ /* Pass structs of size 1, 2, 4 or 8 in a GPR by value. */ \
+ if (!(sz == 1 || sz == 2 || sz == 4 || sz == 8)) { \
+ rp = cdataptr(lj_cdata_new(cts, did, sz)); \
+ sz = CTSIZE_PTR; /* Pass all other structs by reference. */ \
+ }
+
+#define CCALL_HANDLE_COMPLEXARG \
+ /* Pass complex float in a GPR and complex double by reference. */ \
+ if (sz != 2*sizeof(float)) { \
+ rp = cdataptr(lj_cdata_new(cts, did, sz)); \
+ sz = CTSIZE_PTR; \
+ }
+
+/* Windows/x64 argument registers are strictly positional (use ngpr). */
+#define CCALL_HANDLE_REGARG \
+ if (isfp) { \
+ if (ngpr < maxgpr) { dp = &cc->fpr[ngpr++]; nfpr = ngpr; goto done; } \
+ } else { \
+ if (ngpr < maxgpr) { dp = &cc->gpr[ngpr++]; goto done; } \
+ }
+
+#elif LJ_TARGET_X64
+/* -- POSIX/x64 calling conventions --------------------------------------- */
+
+#define CCALL_HANDLE_STRUCTRET \
+ int rcl[2]; rcl[0] = rcl[1] = 0; \
+ if (ccall_classify_struct(cts, ctr, rcl, 0)) { \
+ cc->retref = 1; /* Return struct by reference. */ \
+ cc->gpr[ngpr++] = (GPRArg)dp; \
+ } else { \
+ cc->retref = 0; /* Return small structs in registers. */ \
+ }
+
+#define CCALL_HANDLE_STRUCTRET2 \
+ int rcl[2]; rcl[0] = rcl[1] = 0; \
+ ccall_classify_struct(cts, ctr, rcl, 0); \
+ ccall_struct_ret(cc, rcl, dp, ctr->size);
+
+#define CCALL_HANDLE_COMPLEXRET \
+ /* Complex values are returned in one or two FPRs. */ \
+ cc->retref = 0;
+
+#define CCALL_HANDLE_COMPLEXRET2 \
+ if (ctr->size == 2*sizeof(float)) { /* Copy complex float from FPR. */ \
+ *(int64_t *)dp = cc->fpr[0].l[0]; \
+ } else { /* Copy non-contiguous complex double from FPRs. */ \
+ ((int64_t *)dp)[0] = cc->fpr[0].l[0]; \
+ ((int64_t *)dp)[1] = cc->fpr[1].l[0]; \
+ }
+
+#define CCALL_HANDLE_STRUCTARG \
+ int rcl[2]; rcl[0] = rcl[1] = 0; \
+ if (!ccall_classify_struct(cts, d, rcl, 0)) { \
+ cc->nsp = nsp; cc->ngpr = ngpr; cc->nfpr = nfpr; \
+ if (ccall_struct_arg(cc, cts, d, rcl, o, narg)) goto err_nyi; \
+ nsp = cc->nsp; ngpr = cc->ngpr; nfpr = cc->nfpr; \
+ continue; \
+ } /* Pass all other structs by value on stack. */
+
+#define CCALL_HANDLE_COMPLEXARG \
+ isfp = 2; /* Pass complex in FPRs or on stack. Needs postprocessing. */
+
+#define CCALL_HANDLE_REGARG \
+ if (isfp) { /* Try to pass argument in FPRs. */ \
+ int n2 = ctype_isvector(d->info) ? 1 : n; \
+ if (nfpr + n2 <= CCALL_NARG_FPR) { \
+ dp = &cc->fpr[nfpr]; \
+ nfpr += n2; \
+ goto done; \
+ } \
+ } else { /* Try to pass argument in GPRs. */ \
+ /* Note that reordering is explicitly allowed in the x64 ABI. */ \
+ if (n <= 2 && ngpr + n <= maxgpr) { \
+ dp = &cc->gpr[ngpr]; \
+ ngpr += n; \
+ goto done; \
+ } \
+ }
+
+#elif LJ_TARGET_ARM
+/* -- ARM calling conventions --------------------------------------------- */
+
+#if LJ_ABI_SOFTFP
+
+#define CCALL_HANDLE_STRUCTRET \
+ /* Return structs of size <= 4 in a GPR. */ \
+ cc->retref = !(sz <= 4); \
+ if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp;
+
+#define CCALL_HANDLE_COMPLEXRET \
+ cc->retref = 1; /* Return all complex values by reference. */ \
+ cc->gpr[ngpr++] = (GPRArg)dp;
+
+#define CCALL_HANDLE_COMPLEXRET2 \
+ UNUSED(dp); /* Nothing to do. */
+
+#define CCALL_HANDLE_STRUCTARG \
+ /* Pass all structs by value in registers and/or on the stack. */
+
+#define CCALL_HANDLE_COMPLEXARG \
+ /* Pass complex by value in 2 or 4 GPRs. */
+
+#define CCALL_HANDLE_REGARG_FP1
+#define CCALL_HANDLE_REGARG_FP2
+
+#else
+
+#define CCALL_HANDLE_STRUCTRET \
+ cc->retref = !ccall_classify_struct(cts, ctr, ct); \
+ if (cc->retref) cc->gpr[ngpr++] = (GPRArg)dp;
+
+#define CCALL_HANDLE_STRUCTRET2 \
+ if (ccall_classify_struct(cts, ctr, ct) > 1) sp = (uint8_t *)&cc->fpr[0]; \
+ memcpy(dp, sp, ctr->size);
+
+#define CCALL_HANDLE_COMPLEXRET \
+ if (!(ct->info & CTF_VARARG)) cc->retref = 0; /* Return complex in FPRs. */
+
+#define CCALL_HANDLE_COMPLEXRET2 \
+ if (!(ct->info & CTF_VARARG)) memcpy(dp, &cc->fpr[0], ctr->size);
+
+#define CCALL_HANDLE_STRUCTARG \
+ isfp = (ccall_classify_struct(cts, d, ct) > 1);
+ /* Pass all structs by value in registers and/or on the stack. */
+
+#define CCALL_HANDLE_COMPLEXARG \
+ isfp = 1; /* Pass complex by value in FPRs or on stack. */
+
+#define CCALL_HANDLE_REGARG_FP1 \
+ if (isfp && !(ct->info & CTF_VARARG)) { \
+ if ((d->info & CTF_ALIGN) > CTALIGN_PTR) { \
+ if (nfpr + (n >> 1) <= CCALL_NARG_FPR) { \
+ dp = &cc->fpr[nfpr]; \
+ nfpr += (n >> 1); \
+ goto done; \
+ } \
+ } else { \
+ if (sz > 1 && fprodd != nfpr) fprodd = 0; \
+ if (fprodd) { \
+ if (2*nfpr+n <= 2*CCALL_NARG_FPR+1) { \
+ dp = (void *)&cc->fpr[fprodd-1].f[1]; \
+ nfpr += (n >> 1); \
+ if ((n & 1)) fprodd = 0; else fprodd = nfpr-1; \
+ goto done; \
+ } \
+ } else { \
+ if (2*nfpr+n <= 2*CCALL_NARG_FPR) { \
+ dp = (void *)&cc->fpr[nfpr]; \
+ nfpr += (n >> 1); \
+ if ((n & 1)) fprodd = ++nfpr; else fprodd = 0; \
+ goto done; \
+ } \
+ } \
+ } \
+ fprodd = 0; /* No reordering after the first FP value is on stack. */ \
+ } else {
+
+#define CCALL_HANDLE_REGARG_FP2 }
+
+#endif
+
+#define CCALL_HANDLE_REGARG \
+ CCALL_HANDLE_REGARG_FP1 \
+ if ((d->info & CTF_ALIGN) > CTALIGN_PTR) { \
+ if (ngpr < maxgpr) \
+ ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \
+ } \
+ if (ngpr < maxgpr) { \
+ dp = &cc->gpr[ngpr]; \
+ if (ngpr + n > maxgpr) { \
+ nsp += ngpr + n - maxgpr; /* Assumes contiguous gpr/stack fields. */ \
+ if (nsp > CCALL_MAXSTACK) goto err_nyi; /* Too many arguments. */ \
+ ngpr = maxgpr; \
+ } else { \
+ ngpr += n; \
+ } \
+ goto done; \
+ } CCALL_HANDLE_REGARG_FP2
+
+#define CCALL_HANDLE_RET \
+ if ((ct->info & CTF_VARARG)) sp = (uint8_t *)&cc->gpr[0];
+
+#elif LJ_TARGET_PPC
+/* -- PPC calling conventions --------------------------------------------- */
+
+#define CCALL_HANDLE_STRUCTRET \
+ cc->retref = 1; /* Return all structs by reference. */ \
+ cc->gpr[ngpr++] = (GPRArg)dp;
+
+#define CCALL_HANDLE_COMPLEXRET \
+ /* Complex values are returned in 2 or 4 GPRs. */ \
+ cc->retref = 0;
+
+#define CCALL_HANDLE_COMPLEXRET2 \
+ memcpy(dp, sp, ctr->size); /* Copy complex from GPRs. */
+
+#define CCALL_HANDLE_STRUCTARG \
+ rp = cdataptr(lj_cdata_new(cts, did, sz)); \
+ sz = CTSIZE_PTR; /* Pass all structs by reference. */
+
+#define CCALL_HANDLE_COMPLEXARG \
+ /* Pass complex by value in 2 or 4 GPRs. */
+
+#define CCALL_HANDLE_REGARG \
+ if (isfp) { /* Try to pass argument in FPRs. */ \
+ if (nfpr + 1 <= CCALL_NARG_FPR) { \
+ dp = &cc->fpr[nfpr]; \
+ nfpr += 1; \
+ d = ctype_get(cts, CTID_DOUBLE); /* FPRs always hold doubles. */ \
+ goto done; \
+ } \
+ } else { /* Try to pass argument in GPRs. */ \
+ if (n > 1) { \
+ lua_assert(n == 2 || n == 4); /* int64_t or complex (float). */ \
+ if (ctype_isinteger(d->info)) \
+ ngpr = (ngpr + 1u) & ~1u; /* Align int64_t to regpair. */ \
+ else if (ngpr + n > maxgpr) \
+ ngpr = maxgpr; /* Prevent reordering. */ \
+ } \
+ if (ngpr + n <= maxgpr) { \
+ dp = &cc->gpr[ngpr]; \
+ ngpr += n; \
+ goto done; \
+ } \
+ }
+
+#define CCALL_HANDLE_RET \
+ if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \
+ ctr = ctype_get(cts, CTID_DOUBLE); /* FPRs always hold doubles. */
+
+#elif LJ_TARGET_PPCSPE
+/* -- PPC/SPE calling conventions ----------------------------------------- */
+
+#define CCALL_HANDLE_STRUCTRET \
+ cc->retref = 1; /* Return all structs by reference. */ \
+ cc->gpr[ngpr++] = (GPRArg)dp;
+
+#define CCALL_HANDLE_COMPLEXRET \
+ /* Complex values are returned in 2 or 4 GPRs. */ \
+ cc->retref = 0;
+
+#define CCALL_HANDLE_COMPLEXRET2 \
+ memcpy(dp, sp, ctr->size); /* Copy complex from GPRs. */
+
+#define CCALL_HANDLE_STRUCTARG \
+ rp = cdataptr(lj_cdata_new(cts, did, sz)); \
+ sz = CTSIZE_PTR; /* Pass all structs by reference. */
+
+#define CCALL_HANDLE_COMPLEXARG \
+ /* Pass complex by value in 2 or 4 GPRs. */
+
+/* PPC/SPE has a softfp ABI. */
+#define CCALL_HANDLE_REGARG \
+ if (n > 1) { /* Doesn't fit in a single GPR? */ \
+ lua_assert(n == 2 || n == 4); /* int64_t, double or complex (float). */ \
+ if (n == 2) \
+ ngpr = (ngpr + 1u) & ~1u; /* Only align 64 bit value to regpair. */ \
+ else if (ngpr + n > maxgpr) \
+ ngpr = maxgpr; /* Prevent reordering. */ \
+ } \
+ if (ngpr + n <= maxgpr) { \
+ dp = &cc->gpr[ngpr]; \
+ ngpr += n; \
+ goto done; \
+ }
+
+#elif LJ_TARGET_MIPS
+/* -- MIPS calling conventions -------------------------------------------- */
+
+#define CCALL_HANDLE_STRUCTRET \
+ cc->retref = 1; /* Return all structs by reference. */ \
+ cc->gpr[ngpr++] = (GPRArg)dp;
+
+#define CCALL_HANDLE_COMPLEXRET \
+ /* Complex values are returned in 1 or 2 FPRs. */ \
+ cc->retref = 0;
+
+#define CCALL_HANDLE_COMPLEXRET2 \
+ if (ctr->size == 2*sizeof(float)) { /* Copy complex float from FPRs. */ \
+ ((float *)dp)[0] = cc->fpr[0].f; \
+ ((float *)dp)[1] = cc->fpr[1].f; \
+ } else { /* Copy complex double from FPRs. */ \
+ ((double *)dp)[0] = cc->fpr[0].d; \
+ ((double *)dp)[1] = cc->fpr[1].d; \
+ }
+
+#define CCALL_HANDLE_STRUCTARG \
+ /* Pass all structs by value in registers and/or on the stack. */
+
+#define CCALL_HANDLE_COMPLEXARG \
+ /* Pass complex by value in 2 or 4 GPRs. */
+
+#define CCALL_HANDLE_REGARG \
+ if (isfp && nfpr < CCALL_NARG_FPR && !(ct->info & CTF_VARARG)) { \
+ /* Try to pass argument in FPRs. */ \
+ dp = n == 1 ? (void *)&cc->fpr[nfpr].f : (void *)&cc->fpr[nfpr].d; \
+ nfpr++; ngpr += n; \
+ goto done; \
+ } else { /* Try to pass argument in GPRs. */ \
+ nfpr = CCALL_NARG_FPR; \
+ if ((d->info & CTF_ALIGN) > CTALIGN_PTR) \
+ ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \
+ if (ngpr < maxgpr) { \
+ dp = &cc->gpr[ngpr]; \
+ if (ngpr + n > maxgpr) { \
+ nsp += ngpr + n - maxgpr; /* Assumes contiguous gpr/stack fields. */ \
+ if (nsp > CCALL_MAXSTACK) goto err_nyi; /* Too many arguments. */ \
+ ngpr = maxgpr; \
+ } else { \
+ ngpr += n; \
+ } \
+ goto done; \
+ } \
+ }
+
+#define CCALL_HANDLE_RET \
+ if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \
+ sp = (uint8_t *)&cc->fpr[0].f;
+
+#else
+#error "Missing calling convention definitions for this architecture"
+#endif
+
+#ifndef CCALL_HANDLE_STRUCTRET2
+#define CCALL_HANDLE_STRUCTRET2 \
+ memcpy(dp, sp, ctr->size); /* Copy struct return value from GPRs. */
+#endif
+
+/* -- x86 OSX ABI struct classification ----------------------------------- */
+
+#if LJ_TARGET_X86 && LJ_TARGET_OSX
+
+/* Check for struct with single FP field. */
+static int ccall_classify_struct(CTState *cts, CType *ct)
+{
+ CTSize sz = ct->size;
+ if (!(sz == sizeof(float) || sz == sizeof(double))) return 0;
+ if ((ct->info & CTF_UNION)) return 0;
+ while (ct->sib) {
+ ct = ctype_get(cts, ct->sib);
+ if (ctype_isfield(ct->info)) {
+ CType *sct = ctype_rawchild(cts, ct);
+ if (ctype_isfp(sct->info)) {
+ if (sct->size == sz)
+ return (sz >> 2); /* Return 1 for float or 2 for double. */
+ } else if (ctype_isstruct(sct->info)) {
+ if (sct->size)
+ return ccall_classify_struct(cts, sct);
+ } else {
+ break;
+ }
+ } else if (ctype_isbitfield(ct->info)) {
+ break;
+ } else if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) {
+ CType *sct = ctype_rawchild(cts, ct);
+ if (sct->size)
+ return ccall_classify_struct(cts, sct);
+ }
+ }
+ return 0;
+}
+
+#endif
+
+/* -- x64 struct classification ------------------------------------------- */
+
+#if LJ_TARGET_X64 && !LJ_ABI_WIN
+
+/* Register classes for x64 struct classification. */
+#define CCALL_RCL_INT 1
+#define CCALL_RCL_SSE 2
+#define CCALL_RCL_MEM 4
+/* NYI: classify vectors. */
+
+static int ccall_classify_struct(CTState *cts, CType *ct, int *rcl, CTSize ofs);
+
+/* Classify a C type. */
+static void ccall_classify_ct(CTState *cts, CType *ct, int *rcl, CTSize ofs)
+{
+ if (ctype_isarray(ct->info)) {
+ CType *cct = ctype_rawchild(cts, ct);
+ CTSize eofs, esz = cct->size, asz = ct->size;
+ for (eofs = 0; eofs < asz; eofs += esz)
+ ccall_classify_ct(cts, cct, rcl, ofs+eofs);
+ } else if (ctype_isstruct(ct->info)) {
+ ccall_classify_struct(cts, ct, rcl, ofs);
+ } else {
+ int cl = ctype_isfp(ct->info) ? CCALL_RCL_SSE : CCALL_RCL_INT;
+ lua_assert(ctype_hassize(ct->info));
+ if ((ofs & (ct->size-1))) cl = CCALL_RCL_MEM; /* Unaligned. */
+ rcl[(ofs >= 8)] |= cl;
+ }
+}
+
+/* Recursively classify a struct based on its fields. */
+static int ccall_classify_struct(CTState *cts, CType *ct, int *rcl, CTSize ofs)
+{
+ if (ct->size > 16) return CCALL_RCL_MEM; /* Too big, gets memory class. */
+ while (ct->sib) {
+ CTSize fofs;
+ ct = ctype_get(cts, ct->sib);
+ fofs = ofs+ct->size;
+ if (ctype_isfield(ct->info))
+ ccall_classify_ct(cts, ctype_rawchild(cts, ct), rcl, fofs);
+ else if (ctype_isbitfield(ct->info))
+ rcl[(fofs >= 8)] |= CCALL_RCL_INT; /* NYI: unaligned bitfields? */
+ else if (ctype_isxattrib(ct->info, CTA_SUBTYPE))
+ ccall_classify_struct(cts, ctype_rawchild(cts, ct), rcl, fofs);
+ }
+ return ((rcl[0]|rcl[1]) & CCALL_RCL_MEM); /* Memory class? */
+}
+
+/* Try to split up a small struct into registers. */
+static int ccall_struct_reg(CCallState *cc, GPRArg *dp, int *rcl)
+{
+ MSize ngpr = cc->ngpr, nfpr = cc->nfpr;
+ uint32_t i;
+ for (i = 0; i < 2; i++) {
+ lua_assert(!(rcl[i] & CCALL_RCL_MEM));
+ if ((rcl[i] & CCALL_RCL_INT)) { /* Integer class takes precedence. */
+ if (ngpr >= CCALL_NARG_GPR) return 1; /* Register overflow. */
+ cc->gpr[ngpr++] = dp[i];
+ } else if ((rcl[i] & CCALL_RCL_SSE)) {
+ if (nfpr >= CCALL_NARG_FPR) return 1; /* Register overflow. */
+ cc->fpr[nfpr++].l[0] = dp[i];
+ }
+ }
+ cc->ngpr = ngpr; cc->nfpr = nfpr;
+ return 0; /* Ok. */
+}
+
+/* Pass a small struct argument. */
+static int ccall_struct_arg(CCallState *cc, CTState *cts, CType *d, int *rcl,
+ TValue *o, int narg)
+{
+ GPRArg dp[2];
+ dp[0] = dp[1] = 0;
+ /* Convert to temp. struct. */
+ lj_cconv_ct_tv(cts, d, (uint8_t *)dp, o, CCF_ARG(narg));
+ if (ccall_struct_reg(cc, dp, rcl)) { /* Register overflow? Pass on stack. */
+ MSize nsp = cc->nsp, n = rcl[1] ? 2 : 1;
+ if (nsp + n > CCALL_MAXSTACK) return 1; /* Too many arguments. */
+ cc->nsp = nsp + n;
+ memcpy(&cc->stack[nsp], dp, n*CTSIZE_PTR);
+ }
+ return 0; /* Ok. */
+}
+
+/* Combine returned small struct. */
+static void ccall_struct_ret(CCallState *cc, int *rcl, uint8_t *dp, CTSize sz)
+{
+ GPRArg sp[2];
+ MSize ngpr = 0, nfpr = 0;
+ uint32_t i;
+ for (i = 0; i < 2; i++) {
+ if ((rcl[i] & CCALL_RCL_INT)) { /* Integer class takes precedence. */
+ sp[i] = cc->gpr[ngpr++];
+ } else if ((rcl[i] & CCALL_RCL_SSE)) {
+ sp[i] = cc->fpr[nfpr++].l[0];
+ }
+ }
+ memcpy(dp, sp, sz);
+}
+#endif
+
+/* -- ARM hard-float ABI struct classification ---------------------------- */
+
+#if LJ_TARGET_ARM && !LJ_ABI_SOFTFP
+
+/* Classify a struct based on its fields. */
+static unsigned int ccall_classify_struct(CTState *cts, CType *ct, CType *ctf)
+{
+ CTSize sz = ct->size;
+ unsigned int r = 0, n = 0, isu = (ct->info & CTF_UNION);
+ if ((ctf->info & CTF_VARARG)) goto noth;
+ while (ct->sib) {
+ CType *sct;
+ ct = ctype_get(cts, ct->sib);
+ if (ctype_isfield(ct->info)) {
+ sct = ctype_rawchild(cts, ct);
+ if (ctype_isfp(sct->info)) {
+ r |= sct->size;
+ if (!isu) n++; else if (n == 0) n = 1;
+ } else if (ctype_iscomplex(sct->info)) {
+ r |= (sct->size >> 1);
+ if (!isu) n += 2; else if (n < 2) n = 2;
+ } else if (ctype_isstruct(sct->info)) {
+ goto substruct;
+ } else {
+ goto noth;
+ }
+ } else if (ctype_isbitfield(ct->info)) {
+ goto noth;
+ } else if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) {
+ sct = ctype_rawchild(cts, ct);
+ substruct:
+ if (sct->size > 0) {
+ unsigned int s = ccall_classify_struct(cts, sct, ctf);
+ if (s <= 1) goto noth;
+ r |= (s & 255);
+ if (!isu) n += (s >> 8); else if (n < (s >>8)) n = (s >> 8);
+ }
+ }
+ }
+ if ((r == 4 || r == 8) && n <= 4)
+ return r + (n << 8);
+noth: /* Not a homogeneous float/double aggregate. */
+ return (sz <= 4); /* Return structs of size <= 4 in a GPR. */
+}
+
+#endif
+
+/* -- Common C call handling ---------------------------------------------- */
+
+/* Infer the destination CTypeID for a vararg argument. */
+CTypeID lj_ccall_ctid_vararg(CTState *cts, cTValue *o)
+{
+ if (tvisnumber(o)) {
+ return CTID_DOUBLE;
+ } else if (tviscdata(o)) {
+ CTypeID id = cdataV(o)->ctypeid;
+ CType *s = ctype_get(cts, id);
+ if (ctype_isrefarray(s->info)) {
+ return lj_ctype_intern(cts,
+ CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(s->info)), CTSIZE_PTR);
+ } else if (ctype_isstruct(s->info) || ctype_isfunc(s->info)) {
+ /* NYI: how to pass a struct by value in a vararg argument? */
+ return lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR);
+ } else if (ctype_isfp(s->info) && s->size == sizeof(float)) {
+ return CTID_DOUBLE;
+ } else {
+ return id;
+ }
+ } else if (tvisstr(o)) {
+ return CTID_P_CCHAR;
+ } else if (tvisbool(o)) {
+ return CTID_BOOL;
+ } else {
+ return CTID_P_VOID;
+ }
+}
+
+/* Setup arguments for C call. */
+static int ccall_set_args(lua_State *L, CTState *cts, CType *ct,
+ CCallState *cc)
+{
+ int gcsteps = 0;
+ TValue *o, *top = L->top;
+ CTypeID fid;
+ CType *ctr;
+ MSize maxgpr, ngpr = 0, nsp = 0, narg;
+#if CCALL_NARG_FPR
+ MSize nfpr = 0;
+#if LJ_TARGET_ARM
+ MSize fprodd = 0;
+#endif
+#endif
+
+ /* Clear unused regs to get some determinism in case of misdeclaration. */
+ memset(cc->gpr, 0, sizeof(cc->gpr));
+#if CCALL_NUM_FPR
+ memset(cc->fpr, 0, sizeof(cc->fpr));
+#endif
+
+#if LJ_TARGET_X86
+ /* x86 has several different calling conventions. */
+ cc->resx87 = 0;
+ switch (ctype_cconv(ct->info)) {
+ case CTCC_FASTCALL: maxgpr = 2; break;
+ case CTCC_THISCALL: maxgpr = 1; break;
+ default: maxgpr = 0; break;
+ }
+#else
+ maxgpr = CCALL_NARG_GPR;
+#endif
+
+ /* Perform required setup for some result types. */
+ ctr = ctype_rawchild(cts, ct);
+ if (ctype_isvector(ctr->info)) {
+ if (!(CCALL_VECTOR_REG && (ctr->size == 8 || ctr->size == 16)))
+ goto err_nyi;
+ } else if (ctype_iscomplex(ctr->info) || ctype_isstruct(ctr->info)) {
+ /* Preallocate cdata object and anchor it after arguments. */
+ CTSize sz = ctr->size;
+ GCcdata *cd = lj_cdata_new(cts, ctype_cid(ct->info), sz);
+ void *dp = cdataptr(cd);
+ setcdataV(L, L->top++, cd);
+ if (ctype_isstruct(ctr->info)) {
+ CCALL_HANDLE_STRUCTRET
+ } else {
+ CCALL_HANDLE_COMPLEXRET
+ }
+#if LJ_TARGET_X86
+ } else if (ctype_isfp(ctr->info)) {
+ cc->resx87 = ctr->size == sizeof(float) ? 1 : 2;
+#endif
+ }
+
+ /* Skip initial attributes. */
+ fid = ct->sib;
+ while (fid) {
+ CType *ctf = ctype_get(cts, fid);
+ if (!ctype_isattrib(ctf->info)) break;
+ fid = ctf->sib;
+ }
+
+ /* Walk through all passed arguments. */
+ for (o = L->base+1, narg = 1; o < top; o++, narg++) {
+ CTypeID did;
+ CType *d;
+ CTSize sz;
+ MSize n, isfp = 0, isva = 0;
+ void *dp, *rp = NULL;
+
+ if (fid) { /* Get argument type from field. */
+ CType *ctf = ctype_get(cts, fid);
+ fid = ctf->sib;
+ lua_assert(ctype_isfield(ctf->info));
+ did = ctype_cid(ctf->info);
+ } else {
+ if (!(ct->info & CTF_VARARG))
+ lj_err_caller(L, LJ_ERR_FFI_NUMARG); /* Too many arguments. */
+ did = lj_ccall_ctid_vararg(cts, o); /* Infer vararg type. */
+ isva = 1;
+ }
+ d = ctype_raw(cts, did);
+ sz = d->size;
+
+ /* Find out how (by value/ref) and where (GPR/FPR) to pass an argument. */
+ if (ctype_isnum(d->info)) {
+ if (sz > 8) goto err_nyi;
+ if ((d->info & CTF_FP))
+ isfp = 1;
+ } else if (ctype_isvector(d->info)) {
+ if (CCALL_VECTOR_REG && (sz == 8 || sz == 16))
+ isfp = 1;
+ else
+ goto err_nyi;
+ } else if (ctype_isstruct(d->info)) {
+ CCALL_HANDLE_STRUCTARG
+ } else if (ctype_iscomplex(d->info)) {
+ CCALL_HANDLE_COMPLEXARG
+ } else {
+ sz = CTSIZE_PTR;
+ }
+ sz = (sz + CTSIZE_PTR-1) & ~(CTSIZE_PTR-1);
+ n = sz / CTSIZE_PTR; /* Number of GPRs or stack slots needed. */
+
+ CCALL_HANDLE_REGARG /* Handle register arguments. */
+
+ /* Otherwise pass argument on stack. */
+ if (CCALL_ALIGN_STACKARG && !rp && (d->info & CTF_ALIGN) > CTALIGN_PTR) {
+ MSize align = (1u << ctype_align(d->info-CTALIGN_PTR)) -1;
+ nsp = (nsp + align) & ~align; /* Align argument on stack. */
+ }
+ if (nsp + n > CCALL_MAXSTACK) { /* Too many arguments. */
+ err_nyi:
+ lj_err_caller(L, LJ_ERR_FFI_NYICALL);
+ }
+ dp = &cc->stack[nsp];
+ nsp += n;
+ isva = 0;
+
+ done:
+ if (rp) { /* Pass by reference. */
+ gcsteps++;
+ *(void **)dp = rp;
+ dp = rp;
+ }
+ lj_cconv_ct_tv(cts, d, (uint8_t *)dp, o, CCF_ARG(narg));
+ /* Extend passed integers to 32 bits at least. */
+ if (ctype_isinteger_or_bool(d->info) && d->size < 4) {
+ if (d->info & CTF_UNSIGNED)
+ *(uint32_t *)dp = d->size == 1 ? (uint32_t)*(uint8_t *)dp :
+ (uint32_t)*(uint16_t *)dp;
+ else
+ *(int32_t *)dp = d->size == 1 ? (int32_t)*(int8_t *)dp :
+ (int32_t)*(int16_t *)dp;
+ }
+#if LJ_TARGET_X64 && LJ_ABI_WIN
+ if (isva) { /* Windows/x64 mirrors varargs in both register sets. */
+ if (nfpr == ngpr)
+ cc->gpr[ngpr-1] = cc->fpr[ngpr-1].l[0];
+ else
+ cc->fpr[ngpr-1].l[0] = cc->gpr[ngpr-1];
+ }
+#else
+ UNUSED(isva);
+#endif
+#if LJ_TARGET_X64 && !LJ_ABI_WIN
+ if (isfp == 2 && n == 2 && (uint8_t *)dp == (uint8_t *)&cc->fpr[nfpr-2]) {
+ cc->fpr[nfpr-1].d[0] = cc->fpr[nfpr-2].d[1]; /* Split complex double. */
+ cc->fpr[nfpr-2].d[1] = 0;
+ }
+#else
+ UNUSED(isfp);
+#endif
+ }
+ if (fid) lj_err_caller(L, LJ_ERR_FFI_NUMARG); /* Too few arguments. */
+
+#if LJ_TARGET_X64 || LJ_TARGET_PPC
+ cc->nfpr = nfpr; /* Required for vararg functions. */
+#endif
+ cc->nsp = nsp;
+ cc->spadj = (CCALL_SPS_FREE + CCALL_SPS_EXTRA)*CTSIZE_PTR;
+ if (nsp > CCALL_SPS_FREE)
+ cc->spadj += (((nsp-CCALL_SPS_FREE)*CTSIZE_PTR + 15u) & ~15u);
+ return gcsteps;
+}
+
+/* Get results from C call. */
+static int ccall_get_results(lua_State *L, CTState *cts, CType *ct,
+ CCallState *cc, int *ret)
+{
+ CType *ctr = ctype_rawchild(cts, ct);
+ uint8_t *sp = (uint8_t *)&cc->gpr[0];
+ if (ctype_isvoid(ctr->info)) {
+ *ret = 0; /* Zero results. */
+ return 0; /* No additional GC step. */
+ }
+ *ret = 1; /* One result. */
+ if (ctype_isstruct(ctr->info)) {
+ /* Return cdata object which is already on top of stack. */
+ if (!cc->retref) {
+ void *dp = cdataptr(cdataV(L->top-1)); /* Use preallocated object. */
+ CCALL_HANDLE_STRUCTRET2
+ }
+ return 1; /* One GC step. */
+ }
+ if (ctype_iscomplex(ctr->info)) {
+ /* Return cdata object which is already on top of stack. */
+ void *dp = cdataptr(cdataV(L->top-1)); /* Use preallocated object. */
+ CCALL_HANDLE_COMPLEXRET2
+ return 1; /* One GC step. */
+ }
+ if (LJ_BE && ctype_isinteger_or_bool(ctr->info) && ctr->size < CTSIZE_PTR)
+ sp += (CTSIZE_PTR - ctr->size);
+#if CCALL_NUM_FPR
+ if (ctype_isfp(ctr->info) || ctype_isvector(ctr->info))
+ sp = (uint8_t *)&cc->fpr[0];
+#endif
+#ifdef CCALL_HANDLE_RET
+ CCALL_HANDLE_RET
+#endif
+ /* No reference types end up here, so there's no need for the CTypeID. */
+ lua_assert(!(ctype_isrefarray(ctr->info) || ctype_isstruct(ctr->info)));
+ return lj_cconv_tv_ct(cts, ctr, 0, L->top-1, sp);
+}
+
+/* Call C function. */
+int lj_ccall_func(lua_State *L, GCcdata *cd)
+{
+ CTState *cts = ctype_cts(L);
+ CType *ct = ctype_raw(cts, cd->ctypeid);
+ CTSize sz = CTSIZE_PTR;
+ if (ctype_isptr(ct->info)) {
+ sz = ct->size;
+ ct = ctype_rawchild(cts, ct);
+ }
+ if (ctype_isfunc(ct->info)) {
+ CCallState cc;
+ int gcsteps, ret;
+ cc.func = (void (*)(void))cdata_getptr(cdataptr(cd), sz);
+ gcsteps = ccall_set_args(L, cts, ct, &cc);
+ ct = (CType *)((intptr_t)ct-(intptr_t)cts->tab);
+ cts->cb.slot = ~0u;
+ lj_vm_ffi_call(&cc);
+ if (cts->cb.slot != ~0u) { /* Blacklist function that called a callback. */
+ TValue tv;
+ setlightudV(&tv, (void *)cc.func);
+ setboolV(lj_tab_set(L, cts->miscmap, &tv), 1);
+ }
+ ct = (CType *)((intptr_t)ct+(intptr_t)cts->tab); /* May be reallocated. */
+ gcsteps += ccall_get_results(L, cts, ct, &cc, &ret);
+#if LJ_TARGET_X86 && LJ_ABI_WIN
+ /* Automatically detect __stdcall and fix up C function declaration. */
+ if (cc.spadj && ctype_cconv(ct->info) == CTCC_CDECL) {
+ CTF_INSERT(ct->info, CCONV, CTCC_STDCALL);
+ lj_trace_abort(G(L));
+ }
+#endif
+ while (gcsteps-- > 0)
+ lj_gc_check(L);
+ return ret;
+ }
+ return -1; /* Not a function. */
+}
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_ccall.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_ccall.h
new file mode 100644
index 0000000..9089e6c
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_ccall.h
@@ -0,0 +1,171 @@
+/*
+** FFI C call handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_CCALL_H
+#define _LJ_CCALL_H
+
+#include "lj_obj.h"
+#include "lj_ctype.h"
+
+#if LJ_HASFFI
+
+/* -- C calling conventions ----------------------------------------------- */
+
+#if LJ_TARGET_X86ORX64
+
+#if LJ_TARGET_X86
+#define CCALL_NARG_GPR 2 /* For fastcall arguments. */
+#define CCALL_NARG_FPR 0
+#define CCALL_NRET_GPR 2
+#define CCALL_NRET_FPR 1 /* For FP results on x87 stack. */
+#define CCALL_ALIGN_STACKARG 0 /* Don't align argument on stack. */
+#elif LJ_ABI_WIN
+#define CCALL_NARG_GPR 4
+#define CCALL_NARG_FPR 4
+#define CCALL_NRET_GPR 1
+#define CCALL_NRET_FPR 1
+#define CCALL_SPS_EXTRA 4
+#else
+#define CCALL_NARG_GPR 6
+#define CCALL_NARG_FPR 8
+#define CCALL_NRET_GPR 2
+#define CCALL_NRET_FPR 2
+#define CCALL_VECTOR_REG 1 /* Pass vectors in registers. */
+#endif
+
+#define CCALL_SPS_FREE 1
+#define CCALL_ALIGN_CALLSTATE 16
+
+typedef LJ_ALIGN(16) union FPRArg {
+ double d[2];
+ float f[4];
+ uint8_t b[16];
+ uint16_t s[8];
+ int i[4];
+ int64_t l[2];
+} FPRArg;
+
+typedef intptr_t GPRArg;
+
+#elif LJ_TARGET_ARM
+
+#define CCALL_NARG_GPR 4
+#define CCALL_NRET_GPR 2 /* For softfp double. */
+#if LJ_ABI_SOFTFP
+#define CCALL_NARG_FPR 0
+#define CCALL_NRET_FPR 0
+#else
+#define CCALL_NARG_FPR 8
+#define CCALL_NRET_FPR 4
+#endif
+#define CCALL_SPS_FREE 0
+
+typedef intptr_t GPRArg;
+typedef union FPRArg {
+ double d;
+ float f[2];
+} FPRArg;
+
+#elif LJ_TARGET_PPC
+
+#define CCALL_NARG_GPR 8
+#define CCALL_NARG_FPR 8
+#define CCALL_NRET_GPR 4 /* For complex double. */
+#define CCALL_NRET_FPR 1
+#define CCALL_SPS_EXTRA 4
+#define CCALL_SPS_FREE 0
+
+typedef intptr_t GPRArg;
+typedef double FPRArg;
+
+#elif LJ_TARGET_PPCSPE
+
+#define CCALL_NARG_GPR 8
+#define CCALL_NARG_FPR 0
+#define CCALL_NRET_GPR 4 /* For softfp complex double. */
+#define CCALL_NRET_FPR 0
+#define CCALL_SPS_FREE 0 /* NYI */
+
+typedef intptr_t GPRArg;
+
+#elif LJ_TARGET_MIPS
+
+#define CCALL_NARG_GPR 4
+#define CCALL_NARG_FPR 2
+#define CCALL_NRET_GPR 2
+#define CCALL_NRET_FPR 2
+#define CCALL_SPS_EXTRA 7
+#define CCALL_SPS_FREE 1
+
+typedef intptr_t GPRArg;
+typedef union FPRArg {
+ double d;
+ struct { LJ_ENDIAN_LOHI(float f; , float g;) };
+} FPRArg;
+
+#else
+#error "Missing calling convention definitions for this architecture"
+#endif
+
+#ifndef CCALL_SPS_EXTRA
+#define CCALL_SPS_EXTRA 0
+#endif
+#ifndef CCALL_VECTOR_REG
+#define CCALL_VECTOR_REG 0
+#endif
+#ifndef CCALL_ALIGN_STACKARG
+#define CCALL_ALIGN_STACKARG 1
+#endif
+#ifndef CCALL_ALIGN_CALLSTATE
+#define CCALL_ALIGN_CALLSTATE 8
+#endif
+
+#define CCALL_NUM_GPR \
+ (CCALL_NARG_GPR > CCALL_NRET_GPR ? CCALL_NARG_GPR : CCALL_NRET_GPR)
+#define CCALL_NUM_FPR \
+ (CCALL_NARG_FPR > CCALL_NRET_FPR ? CCALL_NARG_FPR : CCALL_NRET_FPR)
+
+/* Check against constants in lj_ctype.h. */
+LJ_STATIC_ASSERT(CCALL_NUM_GPR <= CCALL_MAX_GPR);
+LJ_STATIC_ASSERT(CCALL_NUM_FPR <= CCALL_MAX_FPR);
+
+#define CCALL_MAXSTACK 32
+
+/* -- C call state -------------------------------------------------------- */
+
+typedef LJ_ALIGN(CCALL_ALIGN_CALLSTATE) struct CCallState {
+ void (*func)(void); /* Pointer to called function. */
+ uint32_t spadj; /* Stack pointer adjustment. */
+ uint8_t nsp; /* Number of stack slots. */
+ uint8_t retref; /* Return value by reference. */
+#if LJ_TARGET_X64
+ uint8_t ngpr; /* Number of arguments in GPRs. */
+ uint8_t nfpr; /* Number of arguments in FPRs. */
+#elif LJ_TARGET_X86
+ uint8_t resx87; /* Result on x87 stack: 1:float, 2:double. */
+#elif LJ_TARGET_PPC
+ uint8_t nfpr; /* Number of arguments in FPRs. */
+#endif
+#if LJ_32
+ int32_t align1;
+#endif
+#if CCALL_NUM_FPR
+ FPRArg fpr[CCALL_NUM_FPR]; /* Arguments/results in FPRs. */
+#endif
+ GPRArg gpr[CCALL_NUM_GPR]; /* Arguments/results in GPRs. */
+ GPRArg stack[CCALL_MAXSTACK]; /* Stack slots. */
+} CCallState;
+
+/* -- C call handling ----------------------------------------------------- */
+
+/* Really belongs to lj_vm.h. */
+LJ_ASMF void LJ_FASTCALL lj_vm_ffi_call(CCallState *cc);
+
+LJ_FUNC CTypeID lj_ccall_ctid_vararg(CTState *cts, cTValue *o);
+LJ_FUNC int lj_ccall_func(lua_State *L, GCcdata *cd);
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_ccallback.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_ccallback.c
new file mode 100644
index 0000000..06a7401
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_ccallback.c
@@ -0,0 +1,644 @@
+/*
+** FFI C callback handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#include "lj_obj.h"
+
+#if LJ_HASFFI
+
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_tab.h"
+#include "lj_state.h"
+#include "lj_frame.h"
+#include "lj_ctype.h"
+#include "lj_cconv.h"
+#include "lj_ccall.h"
+#include "lj_ccallback.h"
+#include "lj_target.h"
+#include "lj_mcode.h"
+#include "lj_trace.h"
+#include "lj_vm.h"
+
+/* -- Target-specific handling of callback slots -------------------------- */
+
+#define CALLBACK_MCODE_SIZE (LJ_PAGESIZE * LJ_NUM_CBPAGE)
+
+#if LJ_OS_NOJIT
+
+/* Disabled callback support. */
+#define CALLBACK_SLOT2OFS(slot) (0*(slot))
+#define CALLBACK_OFS2SLOT(ofs) (0*(ofs))
+#define CALLBACK_MAX_SLOT 0
+
+#elif LJ_TARGET_X86ORX64
+
+#define CALLBACK_MCODE_HEAD (LJ_64 ? 8 : 0)
+#define CALLBACK_MCODE_GROUP (-2+1+2+5+(LJ_64 ? 6 : 5))
+
+#define CALLBACK_SLOT2OFS(slot) \
+ (CALLBACK_MCODE_HEAD + CALLBACK_MCODE_GROUP*((slot)/32) + 4*(slot))
+
+static MSize CALLBACK_OFS2SLOT(MSize ofs)
+{
+ MSize group;
+ ofs -= CALLBACK_MCODE_HEAD;
+ group = ofs / (32*4 + CALLBACK_MCODE_GROUP);
+ return (ofs % (32*4 + CALLBACK_MCODE_GROUP))/4 + group*32;
+}
+
+#define CALLBACK_MAX_SLOT \
+ (((CALLBACK_MCODE_SIZE-CALLBACK_MCODE_HEAD)/(CALLBACK_MCODE_GROUP+4*32))*32)
+
+#elif LJ_TARGET_ARM
+
+#define CALLBACK_MCODE_HEAD 32
+#define CALLBACK_SLOT2OFS(slot) (CALLBACK_MCODE_HEAD + 8*(slot))
+#define CALLBACK_OFS2SLOT(ofs) (((ofs)-CALLBACK_MCODE_HEAD)/8)
+#define CALLBACK_MAX_SLOT (CALLBACK_OFS2SLOT(CALLBACK_MCODE_SIZE))
+
+#elif LJ_TARGET_PPC
+
+#define CALLBACK_MCODE_HEAD 24
+#define CALLBACK_SLOT2OFS(slot) (CALLBACK_MCODE_HEAD + 8*(slot))
+#define CALLBACK_OFS2SLOT(ofs) (((ofs)-CALLBACK_MCODE_HEAD)/8)
+#define CALLBACK_MAX_SLOT (CALLBACK_OFS2SLOT(CALLBACK_MCODE_SIZE))
+
+#elif LJ_TARGET_MIPS
+
+#define CALLBACK_MCODE_HEAD 24
+#define CALLBACK_SLOT2OFS(slot) (CALLBACK_MCODE_HEAD + 8*(slot))
+#define CALLBACK_OFS2SLOT(ofs) (((ofs)-CALLBACK_MCODE_HEAD)/8)
+#define CALLBACK_MAX_SLOT (CALLBACK_OFS2SLOT(CALLBACK_MCODE_SIZE))
+
+#else
+
+/* Missing support for this architecture. */
+#define CALLBACK_SLOT2OFS(slot) (0*(slot))
+#define CALLBACK_OFS2SLOT(ofs) (0*(ofs))
+#define CALLBACK_MAX_SLOT 0
+
+#endif
+
+/* Convert callback slot number to callback function pointer. */
+static void *callback_slot2ptr(CTState *cts, MSize slot)
+{
+ return (uint8_t *)cts->cb.mcode + CALLBACK_SLOT2OFS(slot);
+}
+
+/* Convert callback function pointer to slot number. */
+MSize lj_ccallback_ptr2slot(CTState *cts, void *p)
+{
+ uintptr_t ofs = (uintptr_t)((uint8_t *)p -(uint8_t *)cts->cb.mcode);
+ if (ofs < CALLBACK_MCODE_SIZE) {
+ MSize slot = CALLBACK_OFS2SLOT((MSize)ofs);
+ if (CALLBACK_SLOT2OFS(slot) == (MSize)ofs)
+ return slot;
+ }
+ return ~0u; /* Not a known callback function pointer. */
+}
+
+/* Initialize machine code for callback function pointers. */
+#if LJ_OS_NOJIT
+/* Disabled callback support. */
+#define callback_mcode_init(g, p) UNUSED(p)
+#elif LJ_TARGET_X86ORX64
+static void callback_mcode_init(global_State *g, uint8_t *page)
+{
+ uint8_t *p = page;
+ uint8_t *target = (uint8_t *)(void *)lj_vm_ffi_callback;
+ MSize slot;
+#if LJ_64
+ *(void **)p = target; p += 8;
+#endif
+ for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) {
+ /* mov al, slot; jmp group */
+ *p++ = XI_MOVrib | RID_EAX; *p++ = (uint8_t)slot;
+ if ((slot & 31) == 31 || slot == CALLBACK_MAX_SLOT-1) {
+ /* push ebp/rbp; mov ah, slot>>8; mov ebp, &g. */
+ *p++ = XI_PUSH + RID_EBP;
+ *p++ = XI_MOVrib | (RID_EAX+4); *p++ = (uint8_t)(slot >> 8);
+ *p++ = XI_MOVri | RID_EBP;
+ *(int32_t *)p = i32ptr(g); p += 4;
+#if LJ_64
+ /* jmp [rip-pageofs] where lj_vm_ffi_callback is stored. */
+ *p++ = XI_GROUP5; *p++ = XM_OFS0 + (XOg_JMP<<3) + RID_EBP;
+ *(int32_t *)p = (int32_t)(page-(p+4)); p += 4;
+#else
+ /* jmp lj_vm_ffi_callback. */
+ *p++ = XI_JMP; *(int32_t *)p = target-(p+4); p += 4;
+#endif
+ } else {
+ *p++ = XI_JMPs; *p++ = (uint8_t)((2+2)*(31-(slot&31)) - 2);
+ }
+ }
+ lua_assert(p - page <= CALLBACK_MCODE_SIZE);
+}
+#elif LJ_TARGET_ARM
+static void callback_mcode_init(global_State *g, uint32_t *page)
+{
+ uint32_t *p = page;
+ void *target = (void *)lj_vm_ffi_callback;
+ MSize slot;
+ /* This must match with the saveregs macro in buildvm_arm.dasc. */
+ *p++ = ARMI_SUB|ARMF_D(RID_R12)|ARMF_N(RID_R12)|ARMF_M(RID_PC);
+ *p++ = ARMI_PUSH|ARMF_N(RID_SP)|RSET_RANGE(RID_R4,RID_R11+1)|RID2RSET(RID_LR);
+ *p++ = ARMI_SUB|ARMI_K12|ARMF_D(RID_R12)|ARMF_N(RID_R12)|CALLBACK_MCODE_HEAD;
+ *p++ = ARMI_STR|ARMI_LS_P|ARMI_LS_W|ARMF_D(RID_R12)|ARMF_N(RID_SP)|(CFRAME_SIZE-4*9);
+ *p++ = ARMI_LDR|ARMI_LS_P|ARMI_LS_U|ARMF_D(RID_R12)|ARMF_N(RID_PC);
+ *p++ = ARMI_LDR|ARMI_LS_P|ARMI_LS_U|ARMF_D(RID_PC)|ARMF_N(RID_PC);
+ *p++ = u32ptr(g);
+ *p++ = u32ptr(target);
+ for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) {
+ *p++ = ARMI_MOV|ARMF_D(RID_R12)|ARMF_M(RID_PC);
+ *p = ARMI_B | ((page-p-2) & 0x00ffffffu);
+ p++;
+ }
+ lua_assert(p - page <= CALLBACK_MCODE_SIZE);
+}
+#elif LJ_TARGET_PPC
+static void callback_mcode_init(global_State *g, uint32_t *page)
+{
+ uint32_t *p = page;
+ void *target = (void *)lj_vm_ffi_callback;
+ MSize slot;
+ *p++ = PPCI_LIS | PPCF_T(RID_TMP) | (u32ptr(target) >> 16);
+ *p++ = PPCI_LIS | PPCF_T(RID_R12) | (u32ptr(g) >> 16);
+ *p++ = PPCI_ORI | PPCF_A(RID_TMP)|PPCF_T(RID_TMP) | (u32ptr(target) & 0xffff);
+ *p++ = PPCI_ORI | PPCF_A(RID_R12)|PPCF_T(RID_R12) | (u32ptr(g) & 0xffff);
+ *p++ = PPCI_MTCTR | PPCF_T(RID_TMP);
+ *p++ = PPCI_BCTR;
+ for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) {
+ *p++ = PPCI_LI | PPCF_T(RID_R11) | slot;
+ *p = PPCI_B | (((page-p) & 0x00ffffffu) << 2);
+ p++;
+ }
+ lua_assert(p - page <= CALLBACK_MCODE_SIZE);
+}
+#elif LJ_TARGET_MIPS
+static void callback_mcode_init(global_State *g, uint32_t *page)
+{
+ uint32_t *p = page;
+ void *target = (void *)lj_vm_ffi_callback;
+ MSize slot;
+ *p++ = MIPSI_SW | MIPSF_T(RID_R1)|MIPSF_S(RID_SP) | 0;
+ *p++ = MIPSI_LUI | MIPSF_T(RID_R3) | (u32ptr(target) >> 16);
+ *p++ = MIPSI_LUI | MIPSF_T(RID_R2) | (u32ptr(g) >> 16);
+ *p++ = MIPSI_ORI | MIPSF_T(RID_R3)|MIPSF_S(RID_R3) |(u32ptr(target)&0xffff);
+ *p++ = MIPSI_JR | MIPSF_S(RID_R3);
+ *p++ = MIPSI_ORI | MIPSF_T(RID_R2)|MIPSF_S(RID_R2) | (u32ptr(g)&0xffff);
+ for (slot = 0; slot < CALLBACK_MAX_SLOT; slot++) {
+ *p = MIPSI_B | ((page-p-1) & 0x0000ffffu);
+ p++;
+ *p++ = MIPSI_LI | MIPSF_T(RID_R1) | slot;
+ }
+ lua_assert(p - page <= CALLBACK_MCODE_SIZE);
+}
+#else
+/* Missing support for this architecture. */
+#define callback_mcode_init(g, p) UNUSED(p)
+#endif
+
+/* -- Machine code management --------------------------------------------- */
+
+#if LJ_TARGET_WINDOWS
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#elif LJ_TARGET_POSIX
+
+#include <sys/mman.h>
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS MAP_ANON
+#endif
+
+#endif
+
+/* Allocate and initialize area for callback function pointers. */
+static void callback_mcode_new(CTState *cts)
+{
+ size_t sz = (size_t)CALLBACK_MCODE_SIZE;
+ void *p;
+ if (CALLBACK_MAX_SLOT == 0)
+ lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV);
+#if LJ_TARGET_WINDOWS
+ p = VirtualAlloc(NULL, sz, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
+ if (!p)
+ lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV);
+#elif LJ_TARGET_POSIX
+ p = mmap(NULL, sz, (PROT_READ|PROT_WRITE), MAP_PRIVATE|MAP_ANONYMOUS,
+ -1, 0);
+ if (p == MAP_FAILED)
+ lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV);
+#else
+ /* Fallback allocator. Fails if memory is not executable by default. */
+ p = lj_mem_new(cts->L, sz);
+#endif
+ cts->cb.mcode = p;
+ callback_mcode_init(cts->g, p);
+ lj_mcode_sync(p, (char *)p + sz);
+#if LJ_TARGET_WINDOWS
+ {
+ DWORD oprot;
+ VirtualProtect(p, sz, PAGE_EXECUTE_READ, &oprot);
+ }
+#elif LJ_TARGET_POSIX
+ mprotect(p, sz, (PROT_READ|PROT_EXEC));
+#endif
+}
+
+/* Free area for callback function pointers. */
+void lj_ccallback_mcode_free(CTState *cts)
+{
+ size_t sz = (size_t)CALLBACK_MCODE_SIZE;
+ void *p = cts->cb.mcode;
+ if (p == NULL) return;
+#if LJ_TARGET_WINDOWS
+ VirtualFree(p, 0, MEM_RELEASE);
+ UNUSED(sz);
+#elif LJ_TARGET_POSIX
+ munmap(p, sz);
+#else
+ lj_mem_free(cts->g, p, sz);
+#endif
+}
+
+/* -- C callback entry ---------------------------------------------------- */
+
+/* Target-specific handling of register arguments. Similar to lj_ccall.c. */
+#if LJ_TARGET_X86
+
+#define CALLBACK_HANDLE_REGARG \
+ if (!isfp) { /* Only non-FP values may be passed in registers. */ \
+ if (n > 1) { /* Anything > 32 bit is passed on the stack. */ \
+ if (!LJ_ABI_WIN) ngpr = maxgpr; /* Prevent reordering. */ \
+ } else if (ngpr + 1 <= maxgpr) { \
+ sp = &cts->cb.gpr[ngpr]; \
+ ngpr += n; \
+ goto done; \
+ } \
+ }
+
+#elif LJ_TARGET_X64 && LJ_ABI_WIN
+
+/* Windows/x64 argument registers are strictly positional (use ngpr). */
+#define CALLBACK_HANDLE_REGARG \
+ if (isfp) { \
+ if (ngpr < maxgpr) { sp = &cts->cb.fpr[ngpr++]; UNUSED(nfpr); goto done; } \
+ } else { \
+ if (ngpr < maxgpr) { sp = &cts->cb.gpr[ngpr++]; goto done; } \
+ }
+
+#elif LJ_TARGET_X64
+
+#define CALLBACK_HANDLE_REGARG \
+ if (isfp) { \
+ if (nfpr + n <= CCALL_NARG_FPR) { \
+ sp = &cts->cb.fpr[nfpr]; \
+ nfpr += n; \
+ goto done; \
+ } \
+ } else { \
+ if (ngpr + n <= maxgpr) { \
+ sp = &cts->cb.gpr[ngpr]; \
+ ngpr += n; \
+ goto done; \
+ } \
+ }
+
+#elif LJ_TARGET_ARM
+
+#if LJ_ABI_SOFTFP
+
+#define CALLBACK_HANDLE_REGARG_FP1 UNUSED(isfp);
+#define CALLBACK_HANDLE_REGARG_FP2
+
+#else
+
+#define CALLBACK_HANDLE_REGARG_FP1 \
+ if (isfp) { \
+ if (n == 1) { \
+ if (fprodd) { \
+ sp = &cts->cb.fpr[fprodd-1]; \
+ fprodd = 0; \
+ goto done; \
+ } else if (nfpr + 1 <= CCALL_NARG_FPR) { \
+ sp = &cts->cb.fpr[nfpr++]; \
+ fprodd = nfpr; \
+ goto done; \
+ } \
+ } else { \
+ if (nfpr + 1 <= CCALL_NARG_FPR) { \
+ sp = &cts->cb.fpr[nfpr++]; \
+ goto done; \
+ } \
+ } \
+ fprodd = 0; /* No reordering after the first FP value is on stack. */ \
+ } else {
+
+#define CALLBACK_HANDLE_REGARG_FP2 }
+
+#endif
+
+#define CALLBACK_HANDLE_REGARG \
+ CALLBACK_HANDLE_REGARG_FP1 \
+ if (n > 1) ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \
+ if (ngpr + n <= maxgpr) { \
+ sp = &cts->cb.gpr[ngpr]; \
+ ngpr += n; \
+ goto done; \
+ } CALLBACK_HANDLE_REGARG_FP2
+
+#elif LJ_TARGET_PPC
+
+#define CALLBACK_HANDLE_REGARG \
+ if (isfp) { \
+ if (nfpr + 1 <= CCALL_NARG_FPR) { \
+ sp = &cts->cb.fpr[nfpr++]; \
+ cta = ctype_get(cts, CTID_DOUBLE); /* FPRs always hold doubles. */ \
+ goto done; \
+ } \
+ } else { /* Try to pass argument in GPRs. */ \
+ if (n > 1) { \
+ lua_assert(ctype_isinteger(cta->info) && n == 2); /* int64_t. */ \
+ ngpr = (ngpr + 1u) & ~1u; /* Align int64_t to regpair. */ \
+ } \
+ if (ngpr + n <= maxgpr) { \
+ sp = &cts->cb.gpr[ngpr]; \
+ ngpr += n; \
+ goto done; \
+ } \
+ }
+
+#define CALLBACK_HANDLE_RET \
+ if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \
+ *(double *)dp = *(float *)dp; /* FPRs always hold doubles. */
+
+#elif LJ_TARGET_MIPS
+
+#define CALLBACK_HANDLE_REGARG \
+ if (isfp && nfpr < CCALL_NARG_FPR) { /* Try to pass argument in FPRs. */ \
+ sp = (void *)((uint8_t *)&cts->cb.fpr[nfpr] + ((LJ_BE && n==1) ? 4 : 0)); \
+ nfpr++; ngpr += n; \
+ goto done; \
+ } else { /* Try to pass argument in GPRs. */ \
+ nfpr = CCALL_NARG_FPR; \
+ if (n > 1) ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \
+ if (ngpr + n <= maxgpr) { \
+ sp = &cts->cb.gpr[ngpr]; \
+ ngpr += n; \
+ goto done; \
+ } \
+ }
+
+#define CALLBACK_HANDLE_RET \
+ if (ctype_isfp(ctr->info) && ctr->size == sizeof(float)) \
+ ((float *)dp)[1] = *(float *)dp;
+
+#else
+#error "Missing calling convention definitions for this architecture"
+#endif
+
+/* Convert and push callback arguments to Lua stack. */
+static void callback_conv_args(CTState *cts, lua_State *L)
+{
+ TValue *o = L->top;
+ intptr_t *stack = cts->cb.stack;
+ MSize slot = cts->cb.slot;
+ CTypeID id = 0, rid, fid;
+ int gcsteps = 0;
+ CType *ct;
+ GCfunc *fn;
+ MSize ngpr = 0, nsp = 0, maxgpr = CCALL_NARG_GPR;
+#if CCALL_NARG_FPR
+ MSize nfpr = 0;
+#if LJ_TARGET_ARM
+ MSize fprodd = 0;
+#endif
+#endif
+
+ if (slot < cts->cb.sizeid && (id = cts->cb.cbid[slot]) != 0) {
+ ct = ctype_get(cts, id);
+ rid = ctype_cid(ct->info);
+ fn = funcV(lj_tab_getint(cts->miscmap, (int32_t)slot));
+ } else { /* Must set up frame first, before throwing the error. */
+ ct = NULL;
+ rid = 0;
+ fn = (GCfunc *)L;
+ }
+ o->u32.lo = LJ_CONT_FFI_CALLBACK; /* Continuation returns from callback. */
+ o->u32.hi = rid; /* Return type. x86: +(spadj<<16). */
+ o++;
+ setframe_gc(o, obj2gco(fn));
+ setframe_ftsz(o, (int)((char *)(o+1) - (char *)L->base) + FRAME_CONT);
+ L->top = L->base = ++o;
+ if (!ct)
+ lj_err_caller(cts->L, LJ_ERR_FFI_BADCBACK);
+ if (isluafunc(fn))
+ setcframe_pc(L->cframe, proto_bc(funcproto(fn))+1);
+ lj_state_checkstack(L, LUA_MINSTACK); /* May throw. */
+ o = L->base; /* Might have been reallocated. */
+
+#if LJ_TARGET_X86
+ /* x86 has several different calling conventions. */
+ switch (ctype_cconv(ct->info)) {
+ case CTCC_FASTCALL: maxgpr = 2; break;
+ case CTCC_THISCALL: maxgpr = 1; break;
+ default: maxgpr = 0; break;
+ }
+#endif
+
+ fid = ct->sib;
+ while (fid) {
+ CType *ctf = ctype_get(cts, fid);
+ if (!ctype_isattrib(ctf->info)) {
+ CType *cta;
+ void *sp;
+ CTSize sz;
+ int isfp;
+ MSize n;
+ lua_assert(ctype_isfield(ctf->info));
+ cta = ctype_rawchild(cts, ctf);
+ isfp = ctype_isfp(cta->info);
+ sz = (cta->size + CTSIZE_PTR-1) & ~(CTSIZE_PTR-1);
+ n = sz / CTSIZE_PTR; /* Number of GPRs or stack slots needed. */
+
+ CALLBACK_HANDLE_REGARG /* Handle register arguments. */
+
+ /* Otherwise pass argument on stack. */
+ if (CCALL_ALIGN_STACKARG && LJ_32 && sz == 8)
+ nsp = (nsp + 1) & ~1u; /* Align 64 bit argument on stack. */
+ sp = &stack[nsp];
+ nsp += n;
+
+ done:
+ if (LJ_BE && cta->size < CTSIZE_PTR)
+ sp = (void *)((uint8_t *)sp + CTSIZE_PTR-cta->size);
+ gcsteps += lj_cconv_tv_ct(cts, cta, 0, o++, sp);
+ }
+ fid = ctf->sib;
+ }
+ L->top = o;
+#if LJ_TARGET_X86
+ /* Store stack adjustment for returns from non-cdecl callbacks. */
+ if (ctype_cconv(ct->info) != CTCC_CDECL)
+ (L->base-2)->u32.hi |= (nsp << (16+2));
+#endif
+ while (gcsteps-- > 0)
+ lj_gc_check(L);
+}
+
+/* Convert Lua object to callback result. */
+static void callback_conv_result(CTState *cts, lua_State *L, TValue *o)
+{
+ CType *ctr = ctype_raw(cts, (uint16_t)(L->base-2)->u32.hi);
+#if LJ_TARGET_X86
+ cts->cb.gpr[2] = 0;
+#endif
+ if (!ctype_isvoid(ctr->info)) {
+ uint8_t *dp = (uint8_t *)&cts->cb.gpr[0];
+#if CCALL_NUM_FPR
+ if (ctype_isfp(ctr->info))
+ dp = (uint8_t *)&cts->cb.fpr[0];
+#endif
+ lj_cconv_ct_tv(cts, ctr, dp, o, 0);
+#ifdef CALLBACK_HANDLE_RET
+ CALLBACK_HANDLE_RET
+#endif
+ /* Extend returned integers to (at least) 32 bits. */
+ if (ctype_isinteger_or_bool(ctr->info) && ctr->size < 4) {
+ if (ctr->info & CTF_UNSIGNED)
+ *(uint32_t *)dp = ctr->size == 1 ? (uint32_t)*(uint8_t *)dp :
+ (uint32_t)*(uint16_t *)dp;
+ else
+ *(int32_t *)dp = ctr->size == 1 ? (int32_t)*(int8_t *)dp :
+ (int32_t)*(int16_t *)dp;
+ }
+#if LJ_TARGET_X86
+ if (ctype_isfp(ctr->info))
+ cts->cb.gpr[2] = ctr->size == sizeof(float) ? 1 : 2;
+#endif
+ }
+}
+
+/* Enter callback. */
+lua_State * LJ_FASTCALL lj_ccallback_enter(CTState *cts, void *cf)
+{
+ lua_State *L = cts->L;
+ global_State *g = cts->g;
+ lua_assert(L != NULL);
+ if (gcref(g->jit_L)) {
+ setstrV(L, L->top++, lj_err_str(L, LJ_ERR_FFI_BADCBACK));
+ if (g->panic) g->panic(L);
+ exit(EXIT_FAILURE);
+ }
+ lj_trace_abort(g); /* Never record across callback. */
+ /* Setup C frame. */
+ cframe_prev(cf) = L->cframe;
+ setcframe_L(cf, L);
+ cframe_errfunc(cf) = -1;
+ cframe_nres(cf) = 0;
+ L->cframe = cf;
+ callback_conv_args(cts, L);
+ return L; /* Now call the function on this stack. */
+}
+
+/* Leave callback. */
+void LJ_FASTCALL lj_ccallback_leave(CTState *cts, TValue *o)
+{
+ lua_State *L = cts->L;
+ GCfunc *fn;
+ TValue *obase = L->base;
+ L->base = L->top; /* Keep continuation frame for throwing errors. */
+ if (o >= L->base) {
+ /* PC of RET* is lost. Point to last line for result conv. errors. */
+ fn = curr_func(L);
+ if (isluafunc(fn)) {
+ GCproto *pt = funcproto(fn);
+ setcframe_pc(L->cframe, proto_bc(pt)+pt->sizebc+1);
+ }
+ }
+ callback_conv_result(cts, L, o);
+ /* Finally drop C frame and continuation frame. */
+ L->cframe = cframe_prev(L->cframe);
+ L->top -= 2;
+ L->base = obase;
+ cts->cb.slot = 0; /* Blacklist C function that called the callback. */
+}
+
+/* -- C callback management ----------------------------------------------- */
+
+/* Get an unused slot in the callback slot table. */
+static MSize callback_slot_new(CTState *cts, CType *ct)
+{
+ CTypeID id = ctype_typeid(cts, ct);
+ CTypeID1 *cbid = cts->cb.cbid;
+ MSize top;
+ for (top = cts->cb.topid; top < cts->cb.sizeid; top++)
+ if (LJ_LIKELY(cbid[top] == 0))
+ goto found;
+#if CALLBACK_MAX_SLOT
+ if (top >= CALLBACK_MAX_SLOT)
+#endif
+ lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV);
+ if (!cts->cb.mcode)
+ callback_mcode_new(cts);
+ lj_mem_growvec(cts->L, cbid, cts->cb.sizeid, CALLBACK_MAX_SLOT, CTypeID1);
+ cts->cb.cbid = cbid;
+ memset(cbid+top, 0, (cts->cb.sizeid-top)*sizeof(CTypeID1));
+found:
+ cbid[top] = id;
+ cts->cb.topid = top+1;
+ return top;
+}
+
+/* Check for function pointer and supported argument/result types. */
+static CType *callback_checkfunc(CTState *cts, CType *ct)
+{
+ int narg = 0;
+ if (!ctype_isptr(ct->info) || (LJ_64 && ct->size != CTSIZE_PTR))
+ return NULL;
+ ct = ctype_rawchild(cts, ct);
+ if (ctype_isfunc(ct->info)) {
+ CType *ctr = ctype_rawchild(cts, ct);
+ CTypeID fid = ct->sib;
+ if (!(ctype_isvoid(ctr->info) || ctype_isenum(ctr->info) ||
+ ctype_isptr(ctr->info) || (ctype_isnum(ctr->info) && ctr->size <= 8)))
+ return NULL;
+ if ((ct->info & CTF_VARARG))
+ return NULL;
+ while (fid) {
+ CType *ctf = ctype_get(cts, fid);
+ if (!ctype_isattrib(ctf->info)) {
+ CType *cta;
+ lua_assert(ctype_isfield(ctf->info));
+ cta = ctype_rawchild(cts, ctf);
+ if (!(ctype_isenum(cta->info) || ctype_isptr(cta->info) ||
+ (ctype_isnum(cta->info) && cta->size <= 8)) ||
+ ++narg >= LUA_MINSTACK-3)
+ return NULL;
+ }
+ fid = ctf->sib;
+ }
+ return ct;
+ }
+ return NULL;
+}
+
+/* Create a new callback and return the callback function pointer. */
+void *lj_ccallback_new(CTState *cts, CType *ct, GCfunc *fn)
+{
+ ct = callback_checkfunc(cts, ct);
+ if (ct) {
+ MSize slot = callback_slot_new(cts, ct);
+ GCtab *t = cts->miscmap;
+ setfuncV(cts->L, lj_tab_setint(cts->L, t, (int32_t)slot), fn);
+ lj_gc_anybarriert(cts->L, t);
+ return callback_slot2ptr(cts, slot);
+ }
+ return NULL; /* Bad conversion. */
+}
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_ccallback.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_ccallback.h
new file mode 100644
index 0000000..a8cdad3
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_ccallback.h
@@ -0,0 +1,25 @@
+/*
+** FFI C callback handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_CCALLBACK_H
+#define _LJ_CCALLBACK_H
+
+#include "lj_obj.h"
+#include "lj_ctype.h"
+
+#if LJ_HASFFI
+
+/* Really belongs to lj_vm.h. */
+LJ_ASMF void lj_vm_ffi_callback(void);
+
+LJ_FUNC MSize lj_ccallback_ptr2slot(CTState *cts, void *p);
+LJ_FUNCA lua_State * LJ_FASTCALL lj_ccallback_enter(CTState *cts, void *cf);
+LJ_FUNCA void LJ_FASTCALL lj_ccallback_leave(CTState *cts, TValue *o);
+LJ_FUNC void *lj_ccallback_new(CTState *cts, CType *ct, GCfunc *fn);
+LJ_FUNC void lj_ccallback_mcode_free(CTState *cts);
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_cconv.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_cconv.c
new file mode 100644
index 0000000..ab398ad
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_cconv.c
@@ -0,0 +1,752 @@
+/*
+** C type conversions.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#include "lj_obj.h"
+
+#if LJ_HASFFI
+
+#include "lj_err.h"
+#include "lj_tab.h"
+#include "lj_ctype.h"
+#include "lj_cdata.h"
+#include "lj_cconv.h"
+#include "lj_ccallback.h"
+
+/* -- Conversion errors --------------------------------------------------- */
+
+/* Bad conversion. */
+LJ_NORET static void cconv_err_conv(CTState *cts, CType *d, CType *s,
+ CTInfo flags)
+{
+ const char *dst = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, d), NULL));
+ const char *src;
+ if ((flags & CCF_FROMTV))
+ src = lj_obj_typename[1+(ctype_isnum(s->info) ? LUA_TNUMBER :
+ ctype_isarray(s->info) ? LUA_TSTRING : LUA_TNIL)];
+ else
+ src = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, s), NULL));
+ if (CCF_GETARG(flags))
+ lj_err_argv(cts->L, CCF_GETARG(flags), LJ_ERR_FFI_BADCONV, src, dst);
+ else
+ lj_err_callerv(cts->L, LJ_ERR_FFI_BADCONV, src, dst);
+}
+
+/* Bad conversion from TValue. */
+LJ_NORET static void cconv_err_convtv(CTState *cts, CType *d, TValue *o,
+ CTInfo flags)
+{
+ const char *dst = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, d), NULL));
+ const char *src = lj_typename(o);
+ if (CCF_GETARG(flags))
+ lj_err_argv(cts->L, CCF_GETARG(flags), LJ_ERR_FFI_BADCONV, src, dst);
+ else
+ lj_err_callerv(cts->L, LJ_ERR_FFI_BADCONV, src, dst);
+}
+
+/* Initializer overflow. */
+LJ_NORET static void cconv_err_initov(CTState *cts, CType *d)
+{
+ const char *dst = strdata(lj_ctype_repr(cts->L, ctype_typeid(cts, d), NULL));
+ lj_err_callerv(cts->L, LJ_ERR_FFI_INITOV, dst);
+}
+
+/* -- C type compatibility checks ----------------------------------------- */
+
+/* Get raw type and qualifiers for a child type. Resolves enums, too. */
+static CType *cconv_childqual(CTState *cts, CType *ct, CTInfo *qual)
+{
+ ct = ctype_child(cts, ct);
+ for (;;) {
+ if (ctype_isattrib(ct->info)) {
+ if (ctype_attrib(ct->info) == CTA_QUAL) *qual |= ct->size;
+ } else if (!ctype_isenum(ct->info)) {
+ break;
+ }
+ ct = ctype_child(cts, ct);
+ }
+ *qual |= (ct->info & CTF_QUAL);
+ return ct;
+}
+
+/* Check for compatible types when converting to a pointer.
+** Note: these checks are more relaxed than what C99 mandates.
+*/
+int lj_cconv_compatptr(CTState *cts, CType *d, CType *s, CTInfo flags)
+{
+ if (!((flags & CCF_CAST) || d == s)) {
+ CTInfo dqual = 0, squal = 0;
+ d = cconv_childqual(cts, d, &dqual);
+ if (!ctype_isstruct(s->info))
+ s = cconv_childqual(cts, s, &squal);
+ if ((flags & CCF_SAME)) {
+ if (dqual != squal)
+ return 0; /* Different qualifiers. */
+ } else if (!(flags & CCF_IGNQUAL)) {
+ if ((dqual & squal) != squal)
+ return 0; /* Discarded qualifiers. */
+ if (ctype_isvoid(d->info) || ctype_isvoid(s->info))
+ return 1; /* Converting to/from void * is always ok. */
+ }
+ if (ctype_type(d->info) != ctype_type(s->info) ||
+ d->size != s->size)
+ return 0; /* Different type or different size. */
+ if (ctype_isnum(d->info)) {
+ if (((d->info ^ s->info) & (CTF_BOOL|CTF_FP)))
+ return 0; /* Different numeric types. */
+ } else if (ctype_ispointer(d->info)) {
+ /* Check child types for compatibility. */
+ return lj_cconv_compatptr(cts, d, s, flags|CCF_SAME);
+ } else if (ctype_isstruct(d->info)) {
+ if (d != s)
+ return 0; /* Must be exact same type for struct/union. */
+ } else if (ctype_isfunc(d->info)) {
+ /* NYI: structural equality of functions. */
+ }
+ }
+ return 1; /* Types are compatible. */
+}
+
+/* -- C type to C type conversion ----------------------------------------- */
+
+/* Convert C type to C type. Caveat: expects to get the raw CType!
+**
+** Note: This is only used by the interpreter and not optimized at all.
+** The JIT compiler will do a much better job specializing for each case.
+*/
+void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s,
+ uint8_t *dp, uint8_t *sp, CTInfo flags)
+{
+ CTSize dsize = d->size, ssize = s->size;
+ CTInfo dinfo = d->info, sinfo = s->info;
+ void *tmpptr;
+
+ lua_assert(!ctype_isenum(dinfo) && !ctype_isenum(sinfo));
+ lua_assert(!ctype_isattrib(dinfo) && !ctype_isattrib(sinfo));
+
+ if (ctype_type(dinfo) > CT_MAYCONVERT || ctype_type(sinfo) > CT_MAYCONVERT)
+ goto err_conv;
+
+ /* Some basic sanity checks. */
+ lua_assert(!ctype_isnum(dinfo) || dsize > 0);
+ lua_assert(!ctype_isnum(sinfo) || ssize > 0);
+ lua_assert(!ctype_isbool(dinfo) || dsize == 1 || dsize == 4);
+ lua_assert(!ctype_isbool(sinfo) || ssize == 1 || ssize == 4);
+ lua_assert(!ctype_isinteger(dinfo) || (1u<<lj_fls(dsize)) == dsize);
+ lua_assert(!ctype_isinteger(sinfo) || (1u<<lj_fls(ssize)) == ssize);
+
+ switch (cconv_idx2(dinfo, sinfo)) {
+ /* Destination is a bool. */
+ case CCX(B, B):
+ /* Source operand is already normalized. */
+ if (dsize == 1) *dp = *sp; else *(int *)dp = *sp;
+ break;
+ case CCX(B, I): {
+ MSize i;
+ uint8_t b = 0;
+ for (i = 0; i < ssize; i++) b |= sp[i];
+ b = (b != 0);
+ if (dsize == 1) *dp = b; else *(int *)dp = b;
+ break;
+ }
+ case CCX(B, F): {
+ uint8_t b;
+ if (ssize == sizeof(double)) b = (*(double *)sp != 0);
+ else if (ssize == sizeof(float)) b = (*(float *)sp != 0);
+ else goto err_conv; /* NYI: long double. */
+ if (dsize == 1) *dp = b; else *(int *)dp = b;
+ break;
+ }
+
+ /* Destination is an integer. */
+ case CCX(I, B):
+ case CCX(I, I):
+ conv_I_I:
+ if (dsize > ssize) { /* Zero-extend or sign-extend LSB. */
+#if LJ_LE
+ uint8_t fill = (!(sinfo & CTF_UNSIGNED) && (sp[ssize-1]&0x80)) ? 0xff : 0;
+ memcpy(dp, sp, ssize);
+ memset(dp + ssize, fill, dsize-ssize);
+#else
+ uint8_t fill = (!(sinfo & CTF_UNSIGNED) && (sp[0]&0x80)) ? 0xff : 0;
+ memset(dp, fill, dsize-ssize);
+ memcpy(dp + (dsize-ssize), sp, ssize);
+#endif
+ } else { /* Copy LSB. */
+#if LJ_LE
+ memcpy(dp, sp, dsize);
+#else
+ memcpy(dp, sp + (ssize-dsize), dsize);
+#endif
+ }
+ break;
+ case CCX(I, F): {
+ double n; /* Always convert via double. */
+ conv_I_F:
+ /* Convert source to double. */
+ if (ssize == sizeof(double)) n = *(double *)sp;
+ else if (ssize == sizeof(float)) n = (double)*(float *)sp;
+ else goto err_conv; /* NYI: long double. */
+ /* Then convert double to integer. */
+ /* The conversion must exactly match the semantics of JIT-compiled code! */
+ if (dsize < 4 || (dsize == 4 && !(dinfo & CTF_UNSIGNED))) {
+ int32_t i = (int32_t)n;
+ if (dsize == 4) *(int32_t *)dp = i;
+ else if (dsize == 2) *(int16_t *)dp = (int16_t)i;
+ else *(int8_t *)dp = (int8_t)i;
+ } else if (dsize == 4) {
+ *(uint32_t *)dp = (uint32_t)n;
+ } else if (dsize == 8) {
+ if (!(dinfo & CTF_UNSIGNED))
+ *(int64_t *)dp = (int64_t)n;
+ else
+ *(uint64_t *)dp = lj_num2u64(n);
+ } else {
+ goto err_conv; /* NYI: conversion to >64 bit integers. */
+ }
+ break;
+ }
+ case CCX(I, C):
+ s = ctype_child(cts, s);
+ sinfo = s->info;
+ ssize = s->size;
+ goto conv_I_F; /* Just convert re. */
+ case CCX(I, P):
+ if (!(flags & CCF_CAST)) goto err_conv;
+ sinfo = CTINFO(CT_NUM, CTF_UNSIGNED);
+ goto conv_I_I;
+ case CCX(I, A):
+ if (!(flags & CCF_CAST)) goto err_conv;
+ sinfo = CTINFO(CT_NUM, CTF_UNSIGNED);
+ ssize = CTSIZE_PTR;
+ tmpptr = sp;
+ sp = (uint8_t *)&tmpptr;
+ goto conv_I_I;
+
+ /* Destination is a floating-point number. */
+ case CCX(F, B):
+ case CCX(F, I): {
+ double n; /* Always convert via double. */
+ conv_F_I:
+ /* First convert source to double. */
+ /* The conversion must exactly match the semantics of JIT-compiled code! */
+ if (ssize < 4 || (ssize == 4 && !(sinfo & CTF_UNSIGNED))) {
+ int32_t i;
+ if (ssize == 4) {
+ i = *(int32_t *)sp;
+ } else if (!(sinfo & CTF_UNSIGNED)) {
+ if (ssize == 2) i = *(int16_t *)sp;
+ else i = *(int8_t *)sp;
+ } else {
+ if (ssize == 2) i = *(uint16_t *)sp;
+ else i = *(uint8_t *)sp;
+ }
+ n = (double)i;
+ } else if (ssize == 4) {
+ n = (double)*(uint32_t *)sp;
+ } else if (ssize == 8) {
+ if (!(sinfo & CTF_UNSIGNED)) n = (double)*(int64_t *)sp;
+ else n = (double)*(uint64_t *)sp;
+ } else {
+ goto err_conv; /* NYI: conversion from >64 bit integers. */
+ }
+ /* Convert double to destination. */
+ if (dsize == sizeof(double)) *(double *)dp = n;
+ else if (dsize == sizeof(float)) *(float *)dp = (float)n;
+ else goto err_conv; /* NYI: long double. */
+ break;
+ }
+ case CCX(F, F): {
+ double n; /* Always convert via double. */
+ conv_F_F:
+ if (ssize == dsize) goto copyval;
+ /* Convert source to double. */
+ if (ssize == sizeof(double)) n = *(double *)sp;
+ else if (ssize == sizeof(float)) n = (double)*(float *)sp;
+ else goto err_conv; /* NYI: long double. */
+ /* Convert double to destination. */
+ if (dsize == sizeof(double)) *(double *)dp = n;
+ else if (dsize == sizeof(float)) *(float *)dp = (float)n;
+ else goto err_conv; /* NYI: long double. */
+ break;
+ }
+ case CCX(F, C):
+ s = ctype_child(cts, s);
+ sinfo = s->info;
+ ssize = s->size;
+ goto conv_F_F; /* Ignore im, and convert from re. */
+
+ /* Destination is a complex number. */
+ case CCX(C, I):
+ d = ctype_child(cts, d);
+ dinfo = d->info;
+ dsize = d->size;
+ memset(dp + dsize, 0, dsize); /* Clear im. */
+ goto conv_F_I; /* Convert to re. */
+ case CCX(C, F):
+ d = ctype_child(cts, d);
+ dinfo = d->info;
+ dsize = d->size;
+ memset(dp + dsize, 0, dsize); /* Clear im. */
+ goto conv_F_F; /* Convert to re. */
+
+ case CCX(C, C):
+ if (dsize != ssize) { /* Different types: convert re/im separately. */
+ CType *dc = ctype_child(cts, d);
+ CType *sc = ctype_child(cts, s);
+ lj_cconv_ct_ct(cts, dc, sc, dp, sp, flags);
+ lj_cconv_ct_ct(cts, dc, sc, dp + dc->size, sp + sc->size, flags);
+ return;
+ }
+ goto copyval; /* Otherwise this is easy. */
+
+ /* Destination is a vector. */
+ case CCX(V, I):
+ case CCX(V, F):
+ case CCX(V, C): {
+ CType *dc = ctype_child(cts, d);
+ CTSize esize;
+ /* First convert the scalar to the first element. */
+ lj_cconv_ct_ct(cts, dc, s, dp, sp, flags);
+ /* Then replicate it to the other elements (splat). */
+ for (sp = dp, esize = dc->size; dsize > esize; dsize -= esize) {
+ dp += esize;
+ memcpy(dp, sp, esize);
+ }
+ break;
+ }
+
+ case CCX(V, V):
+ /* Copy same-sized vectors, even for different lengths/element-types. */
+ if (dsize != ssize) goto err_conv;
+ goto copyval;
+
+ /* Destination is a pointer. */
+ case CCX(P, I):
+ if (!(flags & CCF_CAST)) goto err_conv;
+ dinfo = CTINFO(CT_NUM, CTF_UNSIGNED);
+ goto conv_I_I;
+
+ case CCX(P, F):
+ if (!(flags & CCF_CAST) || !(flags & CCF_FROMTV)) goto err_conv;
+ /* The signed conversion is cheaper. x64 really has 47 bit pointers. */
+ dinfo = CTINFO(CT_NUM, (LJ_64 && dsize == 8) ? 0 : CTF_UNSIGNED);
+ goto conv_I_F;
+
+ case CCX(P, P):
+ if (!lj_cconv_compatptr(cts, d, s, flags)) goto err_conv;
+ cdata_setptr(dp, dsize, cdata_getptr(sp, ssize));
+ break;
+
+ case CCX(P, A):
+ case CCX(P, S):
+ if (!lj_cconv_compatptr(cts, d, s, flags)) goto err_conv;
+ cdata_setptr(dp, dsize, sp);
+ break;
+
+ /* Destination is an array. */
+ case CCX(A, A):
+ if ((flags & CCF_CAST) || (d->info & CTF_VLA) || dsize != ssize ||
+ d->size == CTSIZE_INVALID || !lj_cconv_compatptr(cts, d, s, flags))
+ goto err_conv;
+ goto copyval;
+
+ /* Destination is a struct/union. */
+ case CCX(S, S):
+ if ((flags & CCF_CAST) || (d->info & CTF_VLA) || d != s)
+ goto err_conv; /* Must be exact same type. */
+copyval: /* Copy value. */
+ lua_assert(dsize == ssize);
+ memcpy(dp, sp, dsize);
+ break;
+
+ default:
+ err_conv:
+ cconv_err_conv(cts, d, s, flags);
+ }
+}
+
+/* -- C type to TValue conversion ----------------------------------------- */
+
+/* Convert C type to TValue. Caveat: expects to get the raw CType! */
+int lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid,
+ TValue *o, uint8_t *sp)
+{
+ CTInfo sinfo = s->info;
+ if (ctype_isnum(sinfo)) {
+ if (!ctype_isbool(sinfo)) {
+ if (ctype_isinteger(sinfo) && s->size > 4) goto copyval;
+ if (LJ_DUALNUM && ctype_isinteger(sinfo)) {
+ int32_t i;
+ lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT32), s,
+ (uint8_t *)&i, sp, 0);
+ if ((sinfo & CTF_UNSIGNED) && i < 0)
+ setnumV(o, (lua_Number)(uint32_t)i);
+ else
+ setintV(o, i);
+ } else {
+ lj_cconv_ct_ct(cts, ctype_get(cts, CTID_DOUBLE), s,
+ (uint8_t *)&o->n, sp, 0);
+ /* Numbers are NOT canonicalized here! Beware of uninitialized data. */
+ lua_assert(tvisnum(o));
+ }
+ } else {
+ uint32_t b = s->size == 1 ? (*sp != 0) : (*(int *)sp != 0);
+ setboolV(o, b);
+ setboolV(&cts->g->tmptv2, b); /* Remember for trace recorder. */
+ }
+ return 0;
+ } else if (ctype_isrefarray(sinfo) || ctype_isstruct(sinfo)) {
+ /* Create reference. */
+ setcdataV(cts->L, o, lj_cdata_newref(cts, sp, sid));
+ return 1; /* Need GC step. */
+ } else {
+ GCcdata *cd;
+ CTSize sz;
+ copyval: /* Copy value. */
+ sz = s->size;
+ lua_assert(sz != CTSIZE_INVALID);
+ /* Attributes are stripped, qualifiers are kept (but mostly ignored). */
+ cd = lj_cdata_new(cts, ctype_typeid(cts, s), sz);
+ setcdataV(cts->L, o, cd);
+ memcpy(cdataptr(cd), sp, sz);
+ return 1; /* Need GC step. */
+ }
+}
+
+/* Convert bitfield to TValue. */
+int lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp)
+{
+ CTInfo info = s->info;
+ CTSize pos, bsz;
+ uint32_t val;
+ lua_assert(ctype_isbitfield(info));
+ /* NYI: packed bitfields may cause misaligned reads. */
+ switch (ctype_bitcsz(info)) {
+ case 4: val = *(uint32_t *)sp; break;
+ case 2: val = *(uint16_t *)sp; break;
+ case 1: val = *(uint8_t *)sp; break;
+ default: lua_assert(0); val = 0; break;
+ }
+ /* Check if a packed bitfield crosses a container boundary. */
+ pos = ctype_bitpos(info);
+ bsz = ctype_bitbsz(info);
+ lua_assert(pos < 8*ctype_bitcsz(info));
+ lua_assert(bsz > 0 && bsz <= 8*ctype_bitcsz(info));
+ if (pos + bsz > 8*ctype_bitcsz(info))
+ lj_err_caller(cts->L, LJ_ERR_FFI_NYIPACKBIT);
+ if (!(info & CTF_BOOL)) {
+ CTSize shift = 32 - bsz;
+ if (!(info & CTF_UNSIGNED)) {
+ setintV(o, (int32_t)(val << (shift-pos)) >> shift);
+ } else {
+ val = (val << (shift-pos)) >> shift;
+ if (!LJ_DUALNUM || (int32_t)val < 0)
+ setnumV(o, (lua_Number)(uint32_t)val);
+ else
+ setintV(o, (int32_t)val);
+ }
+ } else {
+ lua_assert(bsz == 1);
+ setboolV(o, (val >> pos) & 1);
+ }
+ return 0; /* No GC step needed. */
+}
+
+/* -- TValue to C type conversion ----------------------------------------- */
+
+/* Convert table to array. */
+static void cconv_array_tab(CTState *cts, CType *d,
+ uint8_t *dp, GCtab *t, CTInfo flags)
+{
+ int32_t i;
+ CType *dc = ctype_rawchild(cts, d); /* Array element type. */
+ CTSize size = d->size, esize = dc->size, ofs = 0;
+ for (i = 0; ; i++) {
+ TValue *tv = (TValue *)lj_tab_getint(t, i);
+ if (!tv || tvisnil(tv)) {
+ if (i == 0) continue; /* Try again for 1-based tables. */
+ break; /* Stop at first nil. */
+ }
+ if (ofs >= size)
+ cconv_err_initov(cts, d);
+ lj_cconv_ct_tv(cts, dc, dp + ofs, tv, flags);
+ ofs += esize;
+ }
+ if (size != CTSIZE_INVALID) { /* Only fill up arrays with known size. */
+ if (ofs == esize) { /* Replicate a single element. */
+ for (; ofs < size; ofs += esize) memcpy(dp + ofs, dp, esize);
+ } else { /* Otherwise fill the remainder with zero. */
+ memset(dp + ofs, 0, size - ofs);
+ }
+ }
+}
+
+/* Convert table to sub-struct/union. */
+static void cconv_substruct_tab(CTState *cts, CType *d, uint8_t *dp,
+ GCtab *t, int32_t *ip, CTInfo flags)
+{
+ CTypeID id = d->sib;
+ while (id) {
+ CType *df = ctype_get(cts, id);
+ id = df->sib;
+ if (ctype_isfield(df->info) || ctype_isbitfield(df->info)) {
+ TValue *tv;
+ int32_t i = *ip, iz = i;
+ if (!gcref(df->name)) continue; /* Ignore unnamed fields. */
+ if (i >= 0) {
+ retry:
+ tv = (TValue *)lj_tab_getint(t, i);
+ if (!tv || tvisnil(tv)) {
+ if (i == 0) { i = 1; goto retry; } /* 1-based tables. */
+ if (iz == 0) { *ip = i = -1; goto tryname; } /* Init named fields. */
+ break; /* Stop at first nil. */
+ }
+ *ip = i + 1;
+ } else {
+ tryname:
+ tv = (TValue *)lj_tab_getstr(t, gco2str(gcref(df->name)));
+ if (!tv || tvisnil(tv)) continue;
+ }
+ if (ctype_isfield(df->info))
+ lj_cconv_ct_tv(cts, ctype_rawchild(cts, df), dp+df->size, tv, flags);
+ else
+ lj_cconv_bf_tv(cts, df, dp+df->size, tv);
+ if ((d->info & CTF_UNION)) break;
+ } else if (ctype_isxattrib(df->info, CTA_SUBTYPE)) {
+ cconv_substruct_tab(cts, ctype_rawchild(cts, df),
+ dp+df->size, t, ip, flags);
+ } /* Ignore all other entries in the chain. */
+ }
+}
+
+/* Convert table to struct/union. */
+static void cconv_struct_tab(CTState *cts, CType *d,
+ uint8_t *dp, GCtab *t, CTInfo flags)
+{
+ int32_t i = 0;
+ memset(dp, 0, d->size); /* Much simpler to clear the struct first. */
+ cconv_substruct_tab(cts, d, dp, t, &i, flags);
+}
+
+/* Convert TValue to C type. Caveat: expects to get the raw CType! */
+void lj_cconv_ct_tv(CTState *cts, CType *d,
+ uint8_t *dp, TValue *o, CTInfo flags)
+{
+ CTypeID sid = CTID_P_VOID;
+ CType *s;
+ void *tmpptr;
+ uint8_t tmpbool, *sp = (uint8_t *)&tmpptr;
+ if (LJ_LIKELY(tvisint(o))) {
+ sp = (uint8_t *)&o->i;
+ sid = CTID_INT32;
+ flags |= CCF_FROMTV;
+ } else if (LJ_LIKELY(tvisnum(o))) {
+ sp = (uint8_t *)&o->n;
+ sid = CTID_DOUBLE;
+ flags |= CCF_FROMTV;
+ } else if (tviscdata(o)) {
+ sp = cdataptr(cdataV(o));
+ sid = cdataV(o)->ctypeid;
+ s = ctype_get(cts, sid);
+ if (ctype_isref(s->info)) { /* Resolve reference for value. */
+ lua_assert(s->size == CTSIZE_PTR);
+ sp = *(void **)sp;
+ sid = ctype_cid(s->info);
+ }
+ s = ctype_raw(cts, sid);
+ if (ctype_isfunc(s->info)) {
+ sid = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|sid), CTSIZE_PTR);
+ } else {
+ if (ctype_isenum(s->info)) s = ctype_child(cts, s);
+ goto doconv;
+ }
+ } else if (tvisstr(o)) {
+ GCstr *str = strV(o);
+ if (ctype_isenum(d->info)) { /* Match string against enum constant. */
+ CTSize ofs;
+ CType *cct = lj_ctype_getfield(cts, d, str, &ofs);
+ if (!cct || !ctype_isconstval(cct->info))
+ goto err_conv;
+ lua_assert(d->size == 4);
+ sp = (uint8_t *)&cct->size;
+ sid = ctype_cid(cct->info);
+ } else if (ctype_isrefarray(d->info)) { /* Copy string to array. */
+ CType *dc = ctype_rawchild(cts, d);
+ CTSize sz = str->len+1;
+ if (!ctype_isinteger(dc->info) || dc->size != 1)
+ goto err_conv;
+ if (d->size != 0 && d->size < sz)
+ sz = d->size;
+ memcpy(dp, strdata(str), sz);
+ return;
+ } else { /* Otherwise pass it as a const char[]. */
+ sp = (uint8_t *)strdata(str);
+ sid = CTID_A_CCHAR;
+ flags |= CCF_FROMTV;
+ }
+ } else if (tvistab(o)) {
+ if (ctype_isarray(d->info)) {
+ cconv_array_tab(cts, d, dp, tabV(o), flags);
+ return;
+ } else if (ctype_isstruct(d->info)) {
+ cconv_struct_tab(cts, d, dp, tabV(o), flags);
+ return;
+ } else {
+ goto err_conv;
+ }
+ } else if (tvisbool(o)) {
+ tmpbool = boolV(o);
+ sp = &tmpbool;
+ sid = CTID_BOOL;
+ } else if (tvisnil(o)) {
+ tmpptr = (void *)0;
+ flags |= CCF_FROMTV;
+ } else if (tvisudata(o)) {
+ GCudata *ud = udataV(o);
+ tmpptr = uddata(ud);
+ if (ud->udtype == UDTYPE_IO_FILE)
+ tmpptr = *(void **)tmpptr;
+ } else if (tvislightud(o)) {
+ tmpptr = lightudV(o);
+ } else if (tvisfunc(o)) {
+ void *p = lj_ccallback_new(cts, d, funcV(o));
+ if (p) {
+ *(void **)dp = p;
+ return;
+ }
+ goto err_conv;
+ } else {
+ err_conv:
+ cconv_err_convtv(cts, d, o, flags);
+ }
+ s = ctype_get(cts, sid);
+doconv:
+ if (ctype_isenum(d->info)) d = ctype_child(cts, d);
+ lj_cconv_ct_ct(cts, d, s, dp, sp, flags);
+}
+
+/* Convert TValue to bitfield. */
+void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o)
+{
+ CTInfo info = d->info;
+ CTSize pos, bsz;
+ uint32_t val, mask;
+ lua_assert(ctype_isbitfield(info));
+ if ((info & CTF_BOOL)) {
+ uint8_t tmpbool;
+ lua_assert(ctype_bitbsz(info) == 1);
+ lj_cconv_ct_tv(cts, ctype_get(cts, CTID_BOOL), &tmpbool, o, 0);
+ val = tmpbool;
+ } else {
+ CTypeID did = (info & CTF_UNSIGNED) ? CTID_UINT32 : CTID_INT32;
+ lj_cconv_ct_tv(cts, ctype_get(cts, did), (uint8_t *)&val, o, 0);
+ }
+ pos = ctype_bitpos(info);
+ bsz = ctype_bitbsz(info);
+ lua_assert(pos < 8*ctype_bitcsz(info));
+ lua_assert(bsz > 0 && bsz <= 8*ctype_bitcsz(info));
+ /* Check if a packed bitfield crosses a container boundary. */
+ if (pos + bsz > 8*ctype_bitcsz(info))
+ lj_err_caller(cts->L, LJ_ERR_FFI_NYIPACKBIT);
+ mask = ((1u << bsz) - 1u) << pos;
+ val = (val << pos) & mask;
+ /* NYI: packed bitfields may cause misaligned reads/writes. */
+ switch (ctype_bitcsz(info)) {
+ case 4: *(uint32_t *)dp = (*(uint32_t *)dp & ~mask) | (uint32_t)val; break;
+ case 2: *(uint16_t *)dp = (*(uint16_t *)dp & ~mask) | (uint16_t)val; break;
+ case 1: *(uint8_t *)dp = (*(uint8_t *)dp & ~mask) | (uint8_t)val; break;
+ default: lua_assert(0); break;
+ }
+}
+
+/* -- Initialize C type with TValues -------------------------------------- */
+
+/* Initialize an array with TValues. */
+static void cconv_array_init(CTState *cts, CType *d, CTSize sz, uint8_t *dp,
+ TValue *o, MSize len)
+{
+ CType *dc = ctype_rawchild(cts, d); /* Array element type. */
+ CTSize ofs, esize = dc->size;
+ MSize i;
+ if (len*esize > sz)
+ cconv_err_initov(cts, d);
+ for (i = 0, ofs = 0; i < len; i++, ofs += esize)
+ lj_cconv_ct_tv(cts, dc, dp + ofs, o + i, 0);
+ if (ofs == esize) { /* Replicate a single element. */
+ for (; ofs < sz; ofs += esize) memcpy(dp + ofs, dp, esize);
+ } else { /* Otherwise fill the remainder with zero. */
+ memset(dp + ofs, 0, sz - ofs);
+ }
+}
+
+/* Initialize a sub-struct/union with TValues. */
+static void cconv_substruct_init(CTState *cts, CType *d, uint8_t *dp,
+ TValue *o, MSize len, MSize *ip)
+{
+ CTypeID id = d->sib;
+ while (id) {
+ CType *df = ctype_get(cts, id);
+ id = df->sib;
+ if (ctype_isfield(df->info) || ctype_isbitfield(df->info)) {
+ MSize i = *ip;
+ if (!gcref(df->name)) continue; /* Ignore unnamed fields. */
+ if (i >= len) break;
+ *ip = i + 1;
+ if (ctype_isfield(df->info))
+ lj_cconv_ct_tv(cts, ctype_rawchild(cts, df), dp+df->size, o + i, 0);
+ else
+ lj_cconv_bf_tv(cts, df, dp+df->size, o + i);
+ if ((d->info & CTF_UNION)) break;
+ } else if (ctype_isxattrib(df->info, CTA_SUBTYPE)) {
+ cconv_substruct_init(cts, ctype_rawchild(cts, df),
+ dp+df->size, o, len, ip);
+ if ((d->info & CTF_UNION)) break;
+ } /* Ignore all other entries in the chain. */
+ }
+}
+
+/* Initialize a struct/union with TValues. */
+static void cconv_struct_init(CTState *cts, CType *d, CTSize sz, uint8_t *dp,
+ TValue *o, MSize len)
+{
+ MSize i = 0;
+ memset(dp, 0, sz); /* Much simpler to clear the struct first. */
+ cconv_substruct_init(cts, d, dp, o, len, &i);
+ if (i < len)
+ cconv_err_initov(cts, d);
+}
+
+/* Check whether to use a multi-value initializer.
+** This is true if an aggregate is to be initialized with a value.
+** Valarrays are treated as values here so ct_tv handles (V|C, I|F).
+*/
+int lj_cconv_multi_init(CTState *cts, CType *d, TValue *o)
+{
+ if (!(ctype_isrefarray(d->info) || ctype_isstruct(d->info)))
+ return 0; /* Destination is not an aggregate. */
+ if (tvistab(o) || (tvisstr(o) && !ctype_isstruct(d->info)))
+ return 0; /* Initializer is not a value. */
+ if (tviscdata(o) && lj_ctype_rawref(cts, cdataV(o)->ctypeid) == d)
+ return 0; /* Source and destination are identical aggregates. */
+ return 1; /* Otherwise the initializer is a value. */
+}
+
+/* Initialize C type with TValues. Caveat: expects to get the raw CType! */
+void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz,
+ uint8_t *dp, TValue *o, MSize len)
+{
+ if (len == 0)
+ memset(dp, 0, sz);
+ else if (len == 1 && !lj_cconv_multi_init(cts, d, o))
+ lj_cconv_ct_tv(cts, d, dp, o, 0);
+ else if (ctype_isarray(d->info)) /* Also handles valarray init with len>1. */
+ cconv_array_init(cts, d, sz, dp, o, len);
+ else if (ctype_isstruct(d->info))
+ cconv_struct_init(cts, d, sz, dp, o, len);
+ else
+ cconv_err_initov(cts, d);
+}
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_cconv.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_cconv.h
new file mode 100644
index 0000000..0a0b66c
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_cconv.h
@@ -0,0 +1,70 @@
+/*
+** C type conversions.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_CCONV_H
+#define _LJ_CCONV_H
+
+#include "lj_obj.h"
+#include "lj_ctype.h"
+
+#if LJ_HASFFI
+
+/* Compressed C type index. ORDER CCX. */
+enum {
+ CCX_B, /* Bool. */
+ CCX_I, /* Integer. */
+ CCX_F, /* Floating-point number. */
+ CCX_C, /* Complex. */
+ CCX_V, /* Vector. */
+ CCX_P, /* Pointer. */
+ CCX_A, /* Refarray. */
+ CCX_S /* Struct/union. */
+};
+
+/* Convert C type info to compressed C type index. ORDER CT. ORDER CCX. */
+static LJ_AINLINE uint32_t cconv_idx(CTInfo info)
+{
+ uint32_t idx = ((info >> 26) & 15u); /* Dispatch bits. */
+ lua_assert(ctype_type(info) <= CT_MAYCONVERT);
+#if LJ_64
+ idx = ((uint32_t)(U64x(f436fff5,fff7f021) >> 4*idx) & 15u);
+#else
+ idx = (((idx < 8 ? 0xfff7f021u : 0xf436fff5) >> 4*(idx & 7u)) & 15u);
+#endif
+ lua_assert(idx < 8);
+ return idx;
+}
+
+#define cconv_idx2(dinfo, sinfo) \
+ ((cconv_idx((dinfo)) << 3) + cconv_idx((sinfo)))
+
+#define CCX(dst, src) ((CCX_##dst << 3) + CCX_##src)
+
+/* Conversion flags. */
+#define CCF_CAST 0x00000001u
+#define CCF_FROMTV 0x00000002u
+#define CCF_SAME 0x00000004u
+#define CCF_IGNQUAL 0x00000008u
+
+#define CCF_ARG_SHIFT 8
+#define CCF_ARG(n) ((n) << CCF_ARG_SHIFT)
+#define CCF_GETARG(f) ((f) >> CCF_ARG_SHIFT)
+
+LJ_FUNC int lj_cconv_compatptr(CTState *cts, CType *d, CType *s, CTInfo flags);
+LJ_FUNC void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s,
+ uint8_t *dp, uint8_t *sp, CTInfo flags);
+LJ_FUNC int lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid,
+ TValue *o, uint8_t *sp);
+LJ_FUNC int lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp);
+LJ_FUNC void lj_cconv_ct_tv(CTState *cts, CType *d,
+ uint8_t *dp, TValue *o, CTInfo flags);
+LJ_FUNC void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o);
+LJ_FUNC int lj_cconv_multi_init(CTState *cts, CType *d, TValue *o);
+LJ_FUNC void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz,
+ uint8_t *dp, TValue *o, MSize len);
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_cdata.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_cdata.c
new file mode 100644
index 0000000..49b1aa5
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_cdata.c
@@ -0,0 +1,285 @@
+/*
+** C data management.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#include "lj_obj.h"
+
+#if LJ_HASFFI
+
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_ctype.h"
+#include "lj_cconv.h"
+#include "lj_cdata.h"
+
+/* -- C data allocation --------------------------------------------------- */
+
+/* Allocate a new C data object holding a reference to another object. */
+GCcdata *lj_cdata_newref(CTState *cts, const void *p, CTypeID id)
+{
+ CTypeID refid = lj_ctype_intern(cts, CTINFO_REF(id), CTSIZE_PTR);
+ GCcdata *cd = lj_cdata_new(cts, refid, CTSIZE_PTR);
+ *(const void **)cdataptr(cd) = p;
+ return cd;
+}
+
+/* Allocate variable-sized or specially aligned C data object. */
+GCcdata *lj_cdata_newv(CTState *cts, CTypeID id, CTSize sz, CTSize align)
+{
+ global_State *g;
+ MSize extra = sizeof(GCcdataVar) + sizeof(GCcdata) +
+ (align > CT_MEMALIGN ? (1u<<align) - (1u<<CT_MEMALIGN) : 0);
+ char *p = lj_mem_newt(cts->L, extra + sz, char);
+ uintptr_t adata = (uintptr_t)p + sizeof(GCcdataVar) + sizeof(GCcdata);
+ uintptr_t almask = (1u << align) - 1u;
+ GCcdata *cd = (GCcdata *)(((adata + almask) & ~almask) - sizeof(GCcdata));
+ lua_assert((char *)cd - p < 65536);
+ cdatav(cd)->offset = (uint16_t)((char *)cd - p);
+ cdatav(cd)->extra = extra;
+ cdatav(cd)->len = sz;
+ g = cts->g;
+ setgcrefr(cd->nextgc, g->gc.root);
+ setgcref(g->gc.root, obj2gco(cd));
+ newwhite(g, obj2gco(cd));
+ cd->marked |= 0x80;
+ cd->gct = ~LJ_TCDATA;
+ cd->ctypeid = id;
+ return cd;
+}
+
+/* Free a C data object. */
+void LJ_FASTCALL lj_cdata_free(global_State *g, GCcdata *cd)
+{
+ if (LJ_UNLIKELY(cd->marked & LJ_GC_CDATA_FIN)) {
+ GCobj *root;
+ makewhite(g, obj2gco(cd));
+ markfinalized(obj2gco(cd));
+ if ((root = gcref(g->gc.mmudata)) != NULL) {
+ setgcrefr(cd->nextgc, root->gch.nextgc);
+ setgcref(root->gch.nextgc, obj2gco(cd));
+ setgcref(g->gc.mmudata, obj2gco(cd));
+ } else {
+ setgcref(cd->nextgc, obj2gco(cd));
+ setgcref(g->gc.mmudata, obj2gco(cd));
+ }
+ } else if (LJ_LIKELY(!cdataisv(cd))) {
+ CType *ct = ctype_raw(ctype_ctsG(g), cd->ctypeid);
+ CTSize sz = ctype_hassize(ct->info) ? ct->size : CTSIZE_PTR;
+ lua_assert(ctype_hassize(ct->info) || ctype_isfunc(ct->info) ||
+ ctype_isextern(ct->info));
+ lj_mem_free(g, cd, sizeof(GCcdata) + sz);
+ } else {
+ lj_mem_free(g, memcdatav(cd), sizecdatav(cd));
+ }
+}
+
+TValue * LJ_FASTCALL lj_cdata_setfin(lua_State *L, GCcdata *cd)
+{
+ global_State *g = G(L);
+ GCtab *t = ctype_ctsG(g)->finalizer;
+ if (gcref(t->metatable)) {
+ /* Add cdata to finalizer table, if still enabled. */
+ TValue *tv, tmp;
+ setcdataV(L, &tmp, cd);
+ lj_gc_anybarriert(L, t);
+ tv = lj_tab_set(L, t, &tmp);
+ cd->marked |= LJ_GC_CDATA_FIN;
+ return tv;
+ } else {
+ /* Otherwise return dummy TValue. */
+ return &g->tmptv;
+ }
+}
+
+/* -- C data indexing ----------------------------------------------------- */
+
+/* Index C data by a TValue. Return CType and pointer. */
+CType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key, uint8_t **pp,
+ CTInfo *qual)
+{
+ uint8_t *p = (uint8_t *)cdataptr(cd);
+ CType *ct = ctype_get(cts, cd->ctypeid);
+ ptrdiff_t idx;
+
+ /* Resolve reference for cdata object. */
+ if (ctype_isref(ct->info)) {
+ lua_assert(ct->size == CTSIZE_PTR);
+ p = *(uint8_t **)p;
+ ct = ctype_child(cts, ct);
+ }
+
+collect_attrib:
+ /* Skip attributes and collect qualifiers. */
+ while (ctype_isattrib(ct->info)) {
+ if (ctype_attrib(ct->info) == CTA_QUAL) *qual |= ct->size;
+ ct = ctype_child(cts, ct);
+ }
+ lua_assert(!ctype_isref(ct->info)); /* Interning rejects refs to refs. */
+
+ if (tvisint(key)) {
+ idx = (ptrdiff_t)intV(key);
+ goto integer_key;
+ } else if (tvisnum(key)) { /* Numeric key. */
+ idx = LJ_64 ? (ptrdiff_t)numV(key) : (ptrdiff_t)lj_num2int(numV(key));
+ integer_key:
+ if (ctype_ispointer(ct->info)) {
+ CTSize sz = lj_ctype_size(cts, ctype_cid(ct->info)); /* Element size. */
+ if (sz == CTSIZE_INVALID)
+ lj_err_caller(cts->L, LJ_ERR_FFI_INVSIZE);
+ if (ctype_isptr(ct->info)) {
+ p = (uint8_t *)cdata_getptr(p, ct->size);
+ } else if ((ct->info & (CTF_VECTOR|CTF_COMPLEX))) {
+ if ((ct->info & CTF_COMPLEX)) idx &= 1;
+ *qual |= CTF_CONST; /* Valarray elements are constant. */
+ }
+ *pp = p + idx*(int32_t)sz;
+ return ct;
+ }
+ } else if (tviscdata(key)) { /* Integer cdata key. */
+ GCcdata *cdk = cdataV(key);
+ CType *ctk = ctype_raw(cts, cdk->ctypeid);
+ if (ctype_isenum(ctk->info)) ctk = ctype_child(cts, ctk);
+ if (ctype_isinteger(ctk->info)) {
+ lj_cconv_ct_ct(cts, ctype_get(cts, CTID_INT_PSZ), ctk,
+ (uint8_t *)&idx, cdataptr(cdk), 0);
+ goto integer_key;
+ }
+ } else if (tvisstr(key)) { /* String key. */
+ GCstr *name = strV(key);
+ if (ctype_isstruct(ct->info)) {
+ CTSize ofs;
+ CType *fct = lj_ctype_getfieldq(cts, ct, name, &ofs, qual);
+ if (fct) {
+ *pp = p + ofs;
+ return fct;
+ }
+ } else if (ctype_iscomplex(ct->info)) {
+ if (name->len == 2) {
+ *qual |= CTF_CONST; /* Complex fields are constant. */
+ if (strdata(name)[0] == 'r' && strdata(name)[1] == 'e') {
+ *pp = p;
+ return ct;
+ } else if (strdata(name)[0] == 'i' && strdata(name)[1] == 'm') {
+ *pp = p + (ct->size >> 1);
+ return ct;
+ }
+ }
+ } else if (cd->ctypeid == CTID_CTYPEID) {
+ /* Allow indexing a (pointer to) struct constructor to get constants. */
+ CType *sct = ctype_raw(cts, *(CTypeID *)p);
+ if (ctype_isptr(sct->info))
+ sct = ctype_rawchild(cts, sct);
+ if (ctype_isstruct(sct->info)) {
+ CTSize ofs;
+ CType *fct = lj_ctype_getfield(cts, sct, name, &ofs);
+ if (fct && ctype_isconstval(fct->info))
+ return fct;
+ }
+ ct = sct; /* Allow resolving metamethods for constructors, too. */
+ }
+ }
+ if (ctype_isptr(ct->info)) { /* Automatically perform '->'. */
+ if (ctype_isstruct(ctype_rawchild(cts, ct)->info)) {
+ p = (uint8_t *)cdata_getptr(p, ct->size);
+ ct = ctype_child(cts, ct);
+ goto collect_attrib;
+ }
+ }
+ *qual |= 1; /* Lookup failed. */
+ return ct; /* But return the resolved raw type. */
+}
+
+/* -- C data getters ------------------------------------------------------ */
+
+/* Get constant value and convert to TValue. */
+static void cdata_getconst(CTState *cts, TValue *o, CType *ct)
+{
+ CType *ctt = ctype_child(cts, ct);
+ lua_assert(ctype_isinteger(ctt->info) && ctt->size <= 4);
+ /* Constants are already zero-extended/sign-extended to 32 bits. */
+ if ((ctt->info & CTF_UNSIGNED) && (int32_t)ct->size < 0)
+ setnumV(o, (lua_Number)(uint32_t)ct->size);
+ else
+ setintV(o, (int32_t)ct->size);
+}
+
+/* Get C data value and convert to TValue. */
+int lj_cdata_get(CTState *cts, CType *s, TValue *o, uint8_t *sp)
+{
+ CTypeID sid;
+
+ if (ctype_isconstval(s->info)) {
+ cdata_getconst(cts, o, s);
+ return 0; /* No GC step needed. */
+ } else if (ctype_isbitfield(s->info)) {
+ return lj_cconv_tv_bf(cts, s, o, sp);
+ }
+
+ /* Get child type of pointer/array/field. */
+ lua_assert(ctype_ispointer(s->info) || ctype_isfield(s->info));
+ sid = ctype_cid(s->info);
+ s = ctype_get(cts, sid);
+
+ /* Resolve reference for field. */
+ if (ctype_isref(s->info)) {
+ lua_assert(s->size == CTSIZE_PTR);
+ sp = *(uint8_t **)sp;
+ sid = ctype_cid(s->info);
+ s = ctype_get(cts, sid);
+ }
+
+ /* Skip attributes. */
+ while (ctype_isattrib(s->info))
+ s = ctype_child(cts, s);
+
+ return lj_cconv_tv_ct(cts, s, sid, o, sp);
+}
+
+/* -- C data setters ------------------------------------------------------ */
+
+/* Convert TValue and set C data value. */
+void lj_cdata_set(CTState *cts, CType *d, uint8_t *dp, TValue *o, CTInfo qual)
+{
+ if (ctype_isconstval(d->info)) {
+ goto err_const;
+ } else if (ctype_isbitfield(d->info)) {
+ if (((d->info|qual) & CTF_CONST)) goto err_const;
+ lj_cconv_bf_tv(cts, d, dp, o);
+ return;
+ }
+
+ /* Get child type of pointer/array/field. */
+ lua_assert(ctype_ispointer(d->info) || ctype_isfield(d->info));
+ d = ctype_child(cts, d);
+
+ /* Resolve reference for field. */
+ if (ctype_isref(d->info)) {
+ lua_assert(d->size == CTSIZE_PTR);
+ dp = *(uint8_t **)dp;
+ d = ctype_child(cts, d);
+ }
+
+ /* Skip attributes and collect qualifiers. */
+ for (;;) {
+ if (ctype_isattrib(d->info)) {
+ if (ctype_attrib(d->info) == CTA_QUAL) qual |= d->size;
+ } else {
+ break;
+ }
+ d = ctype_child(cts, d);
+ }
+
+ lua_assert(ctype_hassize(d->info) && !ctype_isvoid(d->info));
+
+ if (((d->info|qual) & CTF_CONST)) {
+ err_const:
+ lj_err_caller(cts->L, LJ_ERR_FFI_WRCONST);
+ }
+
+ lj_cconv_ct_tv(cts, d, dp, o, 0);
+}
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_cdata.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_cdata.h
new file mode 100644
index 0000000..4bb65db
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_cdata.h
@@ -0,0 +1,75 @@
+/*
+** C data management.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_CDATA_H
+#define _LJ_CDATA_H
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_ctype.h"
+
+#if LJ_HASFFI
+
+/* Get C data pointer. */
+static LJ_AINLINE void *cdata_getptr(void *p, CTSize sz)
+{
+ if (LJ_64 && sz == 4) { /* Support 32 bit pointers on 64 bit targets. */
+ return ((void *)(uintptr_t)*(uint32_t *)p);
+ } else {
+ lua_assert(sz == CTSIZE_PTR);
+ return *(void **)p;
+ }
+}
+
+/* Set C data pointer. */
+static LJ_AINLINE void cdata_setptr(void *p, CTSize sz, const void *v)
+{
+ if (LJ_64 && sz == 4) { /* Support 32 bit pointers on 64 bit targets. */
+ *(uint32_t *)p = (uint32_t)(uintptr_t)v;
+ } else {
+ lua_assert(sz == CTSIZE_PTR);
+ *(void **)p = (void *)v;
+ }
+}
+
+/* Allocate fixed-size C data object. */
+static LJ_AINLINE GCcdata *lj_cdata_new(CTState *cts, CTypeID id, CTSize sz)
+{
+ GCcdata *cd;
+#ifdef LUA_USE_ASSERT
+ CType *ct = ctype_raw(cts, id);
+ lua_assert((ctype_hassize(ct->info) ? ct->size : CTSIZE_PTR) == sz);
+#endif
+ cd = (GCcdata *)lj_mem_newgco(cts->L, sizeof(GCcdata) + sz);
+ cd->gct = ~LJ_TCDATA;
+ cd->ctypeid = ctype_check(cts, id);
+ return cd;
+}
+
+/* Variant which works without a valid CTState. */
+static LJ_AINLINE GCcdata *lj_cdata_new_(lua_State *L, CTypeID id, CTSize sz)
+{
+ GCcdata *cd = (GCcdata *)lj_mem_newgco(L, sizeof(GCcdata) + sz);
+ cd->gct = ~LJ_TCDATA;
+ cd->ctypeid = id;
+ return cd;
+}
+
+LJ_FUNC GCcdata *lj_cdata_newref(CTState *cts, const void *pp, CTypeID id);
+LJ_FUNC GCcdata *lj_cdata_newv(CTState *cts, CTypeID id, CTSize sz,
+ CTSize align);
+
+LJ_FUNC void LJ_FASTCALL lj_cdata_free(global_State *g, GCcdata *cd);
+LJ_FUNCA TValue * LJ_FASTCALL lj_cdata_setfin(lua_State *L, GCcdata *cd);
+
+LJ_FUNC CType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key,
+ uint8_t **pp, CTInfo *qual);
+LJ_FUNC int lj_cdata_get(CTState *cts, CType *s, TValue *o, uint8_t *sp);
+LJ_FUNC void lj_cdata_set(CTState *cts, CType *d, uint8_t *dp, TValue *o,
+ CTInfo qual);
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_char.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_char.c
new file mode 100644
index 0000000..11f23ef
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_char.c
@@ -0,0 +1,43 @@
+/*
+** Character types.
+** Donated to the public domain.
+**
+** This is intended to replace the problematic libc single-byte NLS functions.
+** These just don't make sense anymore with UTF-8 locales becoming the norm
+** on POSIX systems. It never worked too well on Windows systems since hardly
+** anyone bothered to call setlocale().
+**
+** This table is hardcoded for ASCII. Identifiers include the characters
+** 128-255, too. This allows for the use of all non-ASCII chars as identifiers
+** in the lexer. This is a broad definition, but works well in practice
+** for both UTF-8 locales and most single-byte locales (such as ISO-8859-*).
+**
+** If you really need proper character types for UTF-8 strings, please use
+** an add-on library such as slnunicode: http://luaforge.net/projects/sln/
+*/
+
+#define lj_char_c
+#define LUA_CORE
+
+#include "lj_char.h"
+
+LJ_DATADEF const uint8_t lj_char_bits[257] = {
+ 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 152,152,152,152,152,152,152,152,152,152, 4, 4, 4, 4, 4, 4,
+ 4,176,176,176,176,176,176,160,160,160,160,160,160,160,160,160,
+ 160,160,160,160,160,160,160,160,160,160,160, 4, 4, 4, 4,132,
+ 4,208,208,208,208,208,208,192,192,192,192,192,192,192,192,192,
+ 192,192,192,192,192,192,192,192,192,192,192, 4, 4, 4, 4, 1,
+ 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
+ 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
+ 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
+ 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
+ 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
+ 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
+ 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
+ 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128
+};
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_char.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_char.h
new file mode 100644
index 0000000..c3c86d3
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_char.h
@@ -0,0 +1,42 @@
+/*
+** Character types.
+** Donated to the public domain.
+*/
+
+#ifndef _LJ_CHAR_H
+#define _LJ_CHAR_H
+
+#include "lj_def.h"
+
+#define LJ_CHAR_CNTRL 0x01
+#define LJ_CHAR_SPACE 0x02
+#define LJ_CHAR_PUNCT 0x04
+#define LJ_CHAR_DIGIT 0x08
+#define LJ_CHAR_XDIGIT 0x10
+#define LJ_CHAR_UPPER 0x20
+#define LJ_CHAR_LOWER 0x40
+#define LJ_CHAR_IDENT 0x80
+#define LJ_CHAR_ALPHA (LJ_CHAR_LOWER|LJ_CHAR_UPPER)
+#define LJ_CHAR_ALNUM (LJ_CHAR_ALPHA|LJ_CHAR_DIGIT)
+#define LJ_CHAR_GRAPH (LJ_CHAR_ALNUM|LJ_CHAR_PUNCT)
+
+/* Only pass -1 or 0..255 to these macros. Never pass a signed char! */
+#define lj_char_isa(c, t) ((lj_char_bits+1)[(c)] & t)
+#define lj_char_iscntrl(c) lj_char_isa((c), LJ_CHAR_CNTRL)
+#define lj_char_isspace(c) lj_char_isa((c), LJ_CHAR_SPACE)
+#define lj_char_ispunct(c) lj_char_isa((c), LJ_CHAR_PUNCT)
+#define lj_char_isdigit(c) lj_char_isa((c), LJ_CHAR_DIGIT)
+#define lj_char_isxdigit(c) lj_char_isa((c), LJ_CHAR_XDIGIT)
+#define lj_char_isupper(c) lj_char_isa((c), LJ_CHAR_UPPER)
+#define lj_char_islower(c) lj_char_isa((c), LJ_CHAR_LOWER)
+#define lj_char_isident(c) lj_char_isa((c), LJ_CHAR_IDENT)
+#define lj_char_isalpha(c) lj_char_isa((c), LJ_CHAR_ALPHA)
+#define lj_char_isalnum(c) lj_char_isa((c), LJ_CHAR_ALNUM)
+#define lj_char_isgraph(c) lj_char_isa((c), LJ_CHAR_GRAPH)
+
+#define lj_char_toupper(c) ((c) - (lj_char_islower(c) >> 1))
+#define lj_char_tolower(c) ((c) + lj_char_isupper(c))
+
+LJ_DATA const uint8_t lj_char_bits[257];
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_clib.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_clib.c
new file mode 100644
index 0000000..8dc3c10
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_clib.c
@@ -0,0 +1,409 @@
+/*
+** FFI C library loader.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#include "lj_obj.h"
+
+#if LJ_HASFFI
+
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_tab.h"
+#include "lj_str.h"
+#include "lj_udata.h"
+#include "lj_ctype.h"
+#include "lj_cconv.h"
+#include "lj_cdata.h"
+#include "lj_clib.h"
+
+/* -- OS-specific functions ----------------------------------------------- */
+
+#if LJ_TARGET_DLOPEN
+
+#include <dlfcn.h>
+#include <stdio.h>
+
+#if defined(RTLD_DEFAULT)
+#define CLIB_DEFHANDLE RTLD_DEFAULT
+#elif LJ_TARGET_OSX || LJ_TARGET_BSD
+#define CLIB_DEFHANDLE ((void *)(intptr_t)-2)
+#else
+#define CLIB_DEFHANDLE NULL
+#endif
+
+LJ_NORET LJ_NOINLINE static void clib_error_(lua_State *L)
+{
+ lj_err_callermsg(L, dlerror());
+}
+
+#define clib_error(L, fmt, name) clib_error_(L)
+
+#if LJ_TARGET_CYGWIN
+#define CLIB_SOPREFIX "cyg"
+#else
+#define CLIB_SOPREFIX "lib"
+#endif
+
+#if LJ_TARGET_OSX
+#define CLIB_SOEXT "%s.dylib"
+#elif LJ_TARGET_CYGWIN
+#define CLIB_SOEXT "%s.dll"
+#else
+#define CLIB_SOEXT "%s.so"
+#endif
+
+static const char *clib_extname(lua_State *L, const char *name)
+{
+ if (!strchr(name, '/')
+#if LJ_TARGET_CYGWIN
+ && !strchr(name, '\\')
+#endif
+ ) {
+ if (!strchr(name, '.')) {
+ name = lj_str_pushf(L, CLIB_SOEXT, name);
+ L->top--;
+#if LJ_TARGET_CYGWIN
+ } else {
+ return name;
+#endif
+ }
+ if (!(name[0] == CLIB_SOPREFIX[0] && name[1] == CLIB_SOPREFIX[1] &&
+ name[2] == CLIB_SOPREFIX[2])) {
+ name = lj_str_pushf(L, CLIB_SOPREFIX "%s", name);
+ L->top--;
+ }
+ }
+ return name;
+}
+
+/* Check for a recognized ld script line. */
+static const char *clib_check_lds(lua_State *L, const char *buf)
+{
+ char *p, *e;
+ if ((!strncmp(buf, "GROUP", 5) || !strncmp(buf, "INPUT", 5)) &&
+ (p = strchr(buf, '('))) {
+ while (*++p == ' ') ;
+ for (e = p; *e && *e != ' ' && *e != ')'; e++) ;
+ return strdata(lj_str_new(L, p, e-p));
+ }
+ return NULL;
+}
+
+/* Quick and dirty solution to resolve shared library name from ld script. */
+static const char *clib_resolve_lds(lua_State *L, const char *name)
+{
+ FILE *fp = fopen(name, "r");
+ const char *p = NULL;
+ if (fp) {
+ char buf[256];
+ if (fgets(buf, sizeof(buf), fp)) {
+ if (!strncmp(buf, "/* GNU ld script", 16)) { /* ld script magic? */
+ while (fgets(buf, sizeof(buf), fp)) { /* Check all lines. */
+ p = clib_check_lds(L, buf);
+ if (p) break;
+ }
+ } else { /* Otherwise check only the first line. */
+ p = clib_check_lds(L, buf);
+ }
+ }
+ fclose(fp);
+ }
+ return p;
+}
+
+static void *clib_loadlib(lua_State *L, const char *name, int global)
+{
+ void *h = dlopen(clib_extname(L, name),
+ RTLD_LAZY | (global?RTLD_GLOBAL:RTLD_LOCAL));
+ if (!h) {
+ const char *e, *err = dlerror();
+ if (*err == '/' && (e = strchr(err, ':')) &&
+ (name = clib_resolve_lds(L, strdata(lj_str_new(L, err, e-err))))) {
+ h = dlopen(name, RTLD_LAZY | (global?RTLD_GLOBAL:RTLD_LOCAL));
+ if (h) return h;
+ err = dlerror();
+ }
+ lj_err_callermsg(L, err);
+ }
+ return h;
+}
+
+static void clib_unloadlib(CLibrary *cl)
+{
+ if (cl->handle && cl->handle != CLIB_DEFHANDLE)
+ dlclose(cl->handle);
+}
+
+static void *clib_getsym(CLibrary *cl, const char *name)
+{
+ void *p = dlsym(cl->handle, name);
+ return p;
+}
+
+#elif LJ_TARGET_WINDOWS
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#ifndef GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
+#define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS 4
+#define GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT 2
+BOOL WINAPI GetModuleHandleExA(DWORD, LPCSTR, HMODULE*);
+#endif
+
+#define CLIB_DEFHANDLE ((void *)-1)
+
+/* Default libraries. */
+enum {
+ CLIB_HANDLE_EXE,
+ CLIB_HANDLE_DLL,
+ CLIB_HANDLE_CRT,
+ CLIB_HANDLE_KERNEL32,
+ CLIB_HANDLE_USER32,
+ CLIB_HANDLE_GDI32,
+ CLIB_HANDLE_MAX
+};
+
+static void *clib_def_handle[CLIB_HANDLE_MAX];
+
+LJ_NORET LJ_NOINLINE static void clib_error(lua_State *L, const char *fmt,
+ const char *name)
+{
+ DWORD err = GetLastError();
+ char buf[128];
+ if (!FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL, err, 0, buf, sizeof(buf), NULL))
+ buf[0] = '\0';
+ lj_err_callermsg(L, lj_str_pushf(L, fmt, name, buf));
+}
+
+static int clib_needext(const char *s)
+{
+ while (*s) {
+ if (*s == '/' || *s == '\\' || *s == '.') return 0;
+ s++;
+ }
+ return 1;
+}
+
+static const char *clib_extname(lua_State *L, const char *name)
+{
+ if (clib_needext(name)) {
+ name = lj_str_pushf(L, "%s.dll", name);
+ L->top--;
+ }
+ return name;
+}
+
+static void *clib_loadlib(lua_State *L, const char *name, int global)
+{
+ DWORD oldwerr = GetLastError();
+ void *h = (void *)LoadLibraryA(clib_extname(L, name));
+ if (!h) clib_error(L, "cannot load module " LUA_QS ": %s", name);
+ SetLastError(oldwerr);
+ UNUSED(global);
+ return h;
+}
+
+static void clib_unloadlib(CLibrary *cl)
+{
+ if (cl->handle == CLIB_DEFHANDLE) {
+ MSize i;
+ for (i = CLIB_HANDLE_KERNEL32; i < CLIB_HANDLE_MAX; i++) {
+ void *h = clib_def_handle[i];
+ if (h) {
+ clib_def_handle[i] = NULL;
+ FreeLibrary((HINSTANCE)h);
+ }
+ }
+ } else if (cl->handle) {
+ FreeLibrary((HINSTANCE)cl->handle);
+ }
+}
+
+static void *clib_getsym(CLibrary *cl, const char *name)
+{
+ void *p = NULL;
+ if (cl->handle == CLIB_DEFHANDLE) { /* Search default libraries. */
+ MSize i;
+ for (i = 0; i < CLIB_HANDLE_MAX; i++) {
+ HINSTANCE h = (HINSTANCE)clib_def_handle[i];
+ if (!(void *)h) { /* Resolve default library handles (once). */
+ switch (i) {
+ case CLIB_HANDLE_EXE: GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, NULL, &h); break;
+ case CLIB_HANDLE_DLL:
+ GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ (const char *)clib_def_handle, &h);
+ break;
+ case CLIB_HANDLE_CRT:
+ GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ (const char *)&_fmode, &h);
+ break;
+ case CLIB_HANDLE_KERNEL32: h = LoadLibraryA("kernel32.dll"); break;
+ case CLIB_HANDLE_USER32: h = LoadLibraryA("user32.dll"); break;
+ case CLIB_HANDLE_GDI32: h = LoadLibraryA("gdi32.dll"); break;
+ }
+ if (!h) continue;
+ clib_def_handle[i] = (void *)h;
+ }
+ p = (void *)GetProcAddress(h, name);
+ if (p) break;
+ }
+ } else {
+ p = (void *)GetProcAddress((HINSTANCE)cl->handle, name);
+ }
+ return p;
+}
+
+#else
+
+#define CLIB_DEFHANDLE NULL
+
+LJ_NORET LJ_NOINLINE static void clib_error(lua_State *L, const char *fmt,
+ const char *name)
+{
+ lj_err_callermsg(L, lj_str_pushf(L, fmt, name, "no support for this OS"));
+}
+
+static void *clib_loadlib(lua_State *L, const char *name, int global)
+{
+ lj_err_callermsg(L, "no support for loading dynamic libraries for this OS");
+ UNUSED(name); UNUSED(global);
+ return NULL;
+}
+
+static void clib_unloadlib(CLibrary *cl)
+{
+ UNUSED(cl);
+}
+
+static void *clib_getsym(CLibrary *cl, const char *name)
+{
+ UNUSED(cl); UNUSED(name);
+ return NULL;
+}
+
+#endif
+
+/* -- C library indexing -------------------------------------------------- */
+
+#if LJ_TARGET_X86 && LJ_ABI_WIN
+/* Compute argument size for fastcall/stdcall functions. */
+static CTSize clib_func_argsize(CTState *cts, CType *ct)
+{
+ CTSize n = 0;
+ while (ct->sib) {
+ CType *d;
+ ct = ctype_get(cts, ct->sib);
+ if (ctype_isfield(ct->info)) {
+ d = ctype_rawchild(cts, ct);
+ n += ((d->size + 3) & ~3);
+ }
+ }
+ return n;
+}
+#endif
+
+/* Get redirected or mangled external symbol. */
+static const char *clib_extsym(CTState *cts, CType *ct, GCstr *name)
+{
+ if (ct->sib) {
+ CType *ctf = ctype_get(cts, ct->sib);
+ if (ctype_isxattrib(ctf->info, CTA_REDIR))
+ return strdata(gco2str(gcref(ctf->name)));
+ }
+ return strdata(name);
+}
+
+/* Index a C library by name. */
+TValue *lj_clib_index(lua_State *L, CLibrary *cl, GCstr *name)
+{
+ TValue *tv = lj_tab_setstr(L, cl->cache, name);
+ if (LJ_UNLIKELY(tvisnil(tv))) {
+ CTState *cts = ctype_cts(L);
+ CType *ct;
+ CTypeID id = lj_ctype_getname(cts, &ct, name, CLNS_INDEX);
+ if (!id)
+ lj_err_callerv(L, LJ_ERR_FFI_NODECL, strdata(name));
+ if (ctype_isconstval(ct->info)) {
+ CType *ctt = ctype_child(cts, ct);
+ lua_assert(ctype_isinteger(ctt->info) && ctt->size <= 4);
+ if ((ctt->info & CTF_UNSIGNED) && (int32_t)ct->size < 0)
+ setnumV(tv, (lua_Number)(uint32_t)ct->size);
+ else
+ setintV(tv, (int32_t)ct->size);
+ } else {
+ const char *sym = clib_extsym(cts, ct, name);
+#if LJ_TARGET_WINDOWS
+ DWORD oldwerr = GetLastError();
+#endif
+ void *p = clib_getsym(cl, sym);
+ GCcdata *cd;
+ lua_assert(ctype_isfunc(ct->info) || ctype_isextern(ct->info));
+#if LJ_TARGET_X86 && LJ_ABI_WIN
+ /* Retry with decorated name for fastcall/stdcall functions. */
+ if (!p && ctype_isfunc(ct->info)) {
+ CTInfo cconv = ctype_cconv(ct->info);
+ if (cconv == CTCC_FASTCALL || cconv == CTCC_STDCALL) {
+ CTSize sz = clib_func_argsize(cts, ct);
+ const char *symd = lj_str_pushf(L,
+ cconv == CTCC_FASTCALL ? "@%s@%d" : "_%s@%d",
+ sym, sz);
+ L->top--;
+ p = clib_getsym(cl, symd);
+ }
+ }
+#endif
+ if (!p)
+ clib_error(L, "cannot resolve symbol " LUA_QS ": %s", sym);
+#if LJ_TARGET_WINDOWS
+ SetLastError(oldwerr);
+#endif
+ cd = lj_cdata_new(cts, id, CTSIZE_PTR);
+ *(void **)cdataptr(cd) = p;
+ setcdataV(L, tv, cd);
+ }
+ }
+ return tv;
+}
+
+/* -- C library management ------------------------------------------------ */
+
+/* Create a new CLibrary object and push it on the stack. */
+static CLibrary *clib_new(lua_State *L, GCtab *mt)
+{
+ GCtab *t = lj_tab_new(L, 0, 0);
+ GCudata *ud = lj_udata_new(L, sizeof(CLibrary), t);
+ CLibrary *cl = (CLibrary *)uddata(ud);
+ cl->cache = t;
+ ud->udtype = UDTYPE_FFI_CLIB;
+ /* NOBARRIER: The GCudata is new (marked white). */
+ setgcref(ud->metatable, obj2gco(mt));
+ setudataV(L, L->top++, ud);
+ return cl;
+}
+
+/* Load a C library. */
+void lj_clib_load(lua_State *L, GCtab *mt, GCstr *name, int global)
+{
+ void *handle = clib_loadlib(L, strdata(name), global);
+ CLibrary *cl = clib_new(L, mt);
+ cl->handle = handle;
+}
+
+/* Unload a C library. */
+void lj_clib_unload(CLibrary *cl)
+{
+ clib_unloadlib(cl);
+ cl->handle = NULL;
+}
+
+/* Create the default C library object. */
+void lj_clib_default(lua_State *L, GCtab *mt)
+{
+ CLibrary *cl = clib_new(L, mt);
+ cl->handle = CLIB_DEFHANDLE;
+}
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_clib.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_clib.h
new file mode 100644
index 0000000..fcc9dac
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_clib.h
@@ -0,0 +1,29 @@
+/*
+** FFI C library loader.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_CLIB_H
+#define _LJ_CLIB_H
+
+#include "lj_obj.h"
+
+#if LJ_HASFFI
+
+/* Namespace for C library indexing. */
+#define CLNS_INDEX ((1u<<CT_FUNC)|(1u<<CT_EXTERN)|(1u<<CT_CONSTVAL))
+
+/* C library namespace. */
+typedef struct CLibrary {
+ void *handle; /* Opaque handle for dynamic library loader. */
+ GCtab *cache; /* Cache for resolved symbols. Anchored in ud->env. */
+} CLibrary;
+
+LJ_FUNC TValue *lj_clib_index(lua_State *L, CLibrary *cl, GCstr *name);
+LJ_FUNC void lj_clib_load(lua_State *L, GCtab *mt, GCstr *name, int global);
+LJ_FUNC void lj_clib_unload(CLibrary *cl);
+LJ_FUNC void lj_clib_default(lua_State *L, GCtab *mt);
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_cparse.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_cparse.c
new file mode 100644
index 0000000..f111537
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_cparse.c
@@ -0,0 +1,1891 @@
+/*
+** C declaration parser.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#include "lj_obj.h"
+
+#if LJ_HASFFI
+
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_ctype.h"
+#include "lj_cparse.h"
+#include "lj_frame.h"
+#include "lj_vm.h"
+#include "lj_char.h"
+#include "lj_strscan.h"
+
+/*
+** Important note: this is NOT a validating C parser! This is a minimal
+** C declaration parser, solely for use by the LuaJIT FFI.
+**
+** It ought to return correct results for properly formed C declarations,
+** but it may accept some invalid declarations, too (and return nonsense).
+** Also, it shows rather generic error messages to avoid unnecessary bloat.
+** If in doubt, please check the input against your favorite C compiler.
+*/
+
+/* -- C lexer ------------------------------------------------------------- */
+
+/* C lexer token names. */
+static const char *const ctoknames[] = {
+#define CTOKSTR(name, str) str,
+CTOKDEF(CTOKSTR)
+#undef CTOKSTR
+ NULL
+};
+
+/* Forward declaration. */
+LJ_NORET static void cp_err(CPState *cp, ErrMsg em);
+
+static const char *cp_tok2str(CPState *cp, CPToken tok)
+{
+ lua_assert(tok < CTOK_FIRSTDECL);
+ if (tok > CTOK_OFS)
+ return ctoknames[tok-CTOK_OFS-1];
+ else if (!lj_char_iscntrl(tok))
+ return lj_str_pushf(cp->L, "%c", tok);
+ else
+ return lj_str_pushf(cp->L, "char(%d)", tok);
+}
+
+/* End-of-line? */
+static LJ_AINLINE int cp_iseol(CPChar c)
+{
+ return (c == '\n' || c == '\r');
+}
+
+/* Peek next raw character. */
+static LJ_AINLINE CPChar cp_rawpeek(CPState *cp)
+{
+ return (CPChar)(uint8_t)(*cp->p);
+}
+
+static LJ_NOINLINE CPChar cp_get_bs(CPState *cp);
+
+/* Get next character. */
+static LJ_AINLINE CPChar cp_get(CPState *cp)
+{
+ cp->c = (CPChar)(uint8_t)(*cp->p++);
+ if (LJ_LIKELY(cp->c != '\\')) return cp->c;
+ return cp_get_bs(cp);
+}
+
+/* Transparently skip backslash-escaped line breaks. */
+static LJ_NOINLINE CPChar cp_get_bs(CPState *cp)
+{
+ CPChar c2, c = cp_rawpeek(cp);
+ if (!cp_iseol(c)) return cp->c;
+ cp->p++;
+ c2 = cp_rawpeek(cp);
+ if (cp_iseol(c2) && c2 != c) cp->p++;
+ cp->linenumber++;
+ return cp_get(cp);
+}
+
+/* Grow save buffer. */
+static LJ_NOINLINE void cp_save_grow(CPState *cp, CPChar c)
+{
+ MSize newsize;
+ if (cp->sb.sz >= CPARSE_MAX_BUF/2)
+ cp_err(cp, LJ_ERR_XELEM);
+ newsize = cp->sb.sz * 2;
+ lj_str_resizebuf(cp->L, &cp->sb, newsize);
+ cp->sb.buf[cp->sb.n++] = (char)c;
+}
+
+/* Save character in buffer. */
+static LJ_AINLINE void cp_save(CPState *cp, CPChar c)
+{
+ if (LJ_UNLIKELY(cp->sb.n + 1 > cp->sb.sz))
+ cp_save_grow(cp, c);
+ else
+ cp->sb.buf[cp->sb.n++] = (char)c;
+}
+
+/* Skip line break. Handles "\n", "\r", "\r\n" or "\n\r". */
+static void cp_newline(CPState *cp)
+{
+ CPChar c = cp_rawpeek(cp);
+ if (cp_iseol(c) && c != cp->c) cp->p++;
+ cp->linenumber++;
+}
+
+LJ_NORET static void cp_errmsg(CPState *cp, CPToken tok, ErrMsg em, ...)
+{
+ const char *msg, *tokstr;
+ lua_State *L;
+ va_list argp;
+ if (tok == 0) {
+ tokstr = NULL;
+ } else if (tok == CTOK_IDENT || tok == CTOK_INTEGER || tok == CTOK_STRING ||
+ tok >= CTOK_FIRSTDECL) {
+ if (cp->sb.n == 0) cp_save(cp, '$');
+ cp_save(cp, '\0');
+ tokstr = cp->sb.buf;
+ } else {
+ tokstr = cp_tok2str(cp, tok);
+ }
+ L = cp->L;
+ va_start(argp, em);
+ msg = lj_str_pushvf(L, err2msg(em), argp);
+ va_end(argp);
+ if (tokstr)
+ msg = lj_str_pushf(L, err2msg(LJ_ERR_XNEAR), msg, tokstr);
+ if (cp->linenumber > 1)
+ msg = lj_str_pushf(L, "%s at line %d", msg, cp->linenumber);
+ lj_err_callermsg(L, msg);
+}
+
+LJ_NORET LJ_NOINLINE static void cp_err_token(CPState *cp, CPToken tok)
+{
+ cp_errmsg(cp, cp->tok, LJ_ERR_XTOKEN, cp_tok2str(cp, tok));
+}
+
+LJ_NORET LJ_NOINLINE static void cp_err_badidx(CPState *cp, CType *ct)
+{
+ GCstr *s = lj_ctype_repr(cp->cts->L, ctype_typeid(cp->cts, ct), NULL);
+ cp_errmsg(cp, 0, LJ_ERR_FFI_BADIDX, strdata(s));
+}
+
+LJ_NORET LJ_NOINLINE static void cp_err(CPState *cp, ErrMsg em)
+{
+ cp_errmsg(cp, 0, em);
+}
+
+/* -- Main lexical scanner ------------------------------------------------ */
+
+/* Parse number literal. Only handles int32_t/uint32_t right now. */
+static CPToken cp_number(CPState *cp)
+{
+ StrScanFmt fmt;
+ TValue o;
+ do { cp_save(cp, cp->c); } while (lj_char_isident(cp_get(cp)));
+ cp_save(cp, '\0');
+ fmt = lj_strscan_scan((const uint8_t *)cp->sb.buf, &o, STRSCAN_OPT_C);
+ if (fmt == STRSCAN_INT) cp->val.id = CTID_INT32;
+ else if (fmt == STRSCAN_U32) cp->val.id = CTID_UINT32;
+ else if (!(cp->mode & CPARSE_MODE_SKIP))
+ cp_errmsg(cp, CTOK_INTEGER, LJ_ERR_XNUMBER);
+ cp->val.u32 = (uint32_t)o.i;
+ return CTOK_INTEGER;
+}
+
+/* Parse identifier or keyword. */
+static CPToken cp_ident(CPState *cp)
+{
+ do { cp_save(cp, cp->c); } while (lj_char_isident(cp_get(cp)));
+ cp->str = lj_str_new(cp->L, cp->sb.buf, cp->sb.n);
+ cp->val.id = lj_ctype_getname(cp->cts, &cp->ct, cp->str, cp->tmask);
+ if (ctype_type(cp->ct->info) == CT_KW)
+ return ctype_cid(cp->ct->info);
+ return CTOK_IDENT;
+}
+
+/* Parse parameter. */
+static CPToken cp_param(CPState *cp)
+{
+ CPChar c = cp_get(cp);
+ TValue *o = cp->param;
+ if (lj_char_isident(c) || c == '$') /* Reserve $xyz for future extensions. */
+ cp_errmsg(cp, c, LJ_ERR_XSYNTAX);
+ if (!o || o >= cp->L->top)
+ cp_err(cp, LJ_ERR_FFI_NUMPARAM);
+ cp->param = o+1;
+ if (tvisstr(o)) {
+ cp->str = strV(o);
+ cp->val.id = 0;
+ cp->ct = &cp->cts->tab[0];
+ return CTOK_IDENT;
+ } else if (tvisnumber(o)) {
+ cp->val.i32 = numberVint(o);
+ cp->val.id = CTID_INT32;
+ return CTOK_INTEGER;
+ } else {
+ GCcdata *cd;
+ if (!tviscdata(o))
+ lj_err_argtype(cp->L, (int)(o-cp->L->base)+1, "type parameter");
+ cd = cdataV(o);
+ if (cd->ctypeid == CTID_CTYPEID)
+ cp->val.id = *(CTypeID *)cdataptr(cd);
+ else
+ cp->val.id = cd->ctypeid;
+ return '$';
+ }
+}
+
+/* Parse string or character constant. */
+static CPToken cp_string(CPState *cp)
+{
+ CPChar delim = cp->c;
+ cp_get(cp);
+ while (cp->c != delim) {
+ CPChar c = cp->c;
+ if (c == '\0') cp_errmsg(cp, CTOK_EOF, LJ_ERR_XSTR);
+ if (c == '\\') {
+ c = cp_get(cp);
+ switch (c) {
+ case '\0': cp_errmsg(cp, CTOK_EOF, LJ_ERR_XSTR); break;
+ case 'a': c = '\a'; break;
+ case 'b': c = '\b'; break;
+ case 'f': c = '\f'; break;
+ case 'n': c = '\n'; break;
+ case 'r': c = '\r'; break;
+ case 't': c = '\t'; break;
+ case 'v': c = '\v'; break;
+ case 'e': c = 27; break;
+ case 'x':
+ c = 0;
+ while (lj_char_isxdigit(cp_get(cp)))
+ c = (c<<4) + (lj_char_isdigit(cp->c) ? cp->c-'0' : (cp->c&15)+9);
+ cp_save(cp, (c & 0xff));
+ continue;
+ default:
+ if (lj_char_isdigit(c)) {
+ c -= '0';
+ if (lj_char_isdigit(cp_get(cp))) {
+ c = c*8 + (cp->c - '0');
+ if (lj_char_isdigit(cp_get(cp))) {
+ c = c*8 + (cp->c - '0');
+ cp_get(cp);
+ }
+ }
+ cp_save(cp, (c & 0xff));
+ continue;
+ }
+ break;
+ }
+ }
+ cp_save(cp, c);
+ cp_get(cp);
+ }
+ cp_get(cp);
+ if (delim == '"') {
+ cp->str = lj_str_new(cp->L, cp->sb.buf, cp->sb.n);
+ return CTOK_STRING;
+ } else {
+ if (cp->sb.n != 1) cp_err_token(cp, '\'');
+ cp->val.i32 = (int32_t)(char)cp->sb.buf[0];
+ cp->val.id = CTID_INT32;
+ return CTOK_INTEGER;
+ }
+}
+
+/* Skip C comment. */
+static void cp_comment_c(CPState *cp)
+{
+ do {
+ if (cp_get(cp) == '*') {
+ do {
+ if (cp_get(cp) == '/') { cp_get(cp); return; }
+ } while (cp->c == '*');
+ }
+ if (cp_iseol(cp->c)) cp_newline(cp);
+ } while (cp->c != '\0');
+}
+
+/* Skip C++ comment. */
+static void cp_comment_cpp(CPState *cp)
+{
+ while (!cp_iseol(cp_get(cp)) && cp->c != '\0')
+ ;
+}
+
+/* Lexical scanner for C. Only a minimal subset is implemented. */
+static CPToken cp_next_(CPState *cp)
+{
+ lj_str_resetbuf(&cp->sb);
+ for (;;) {
+ if (lj_char_isident(cp->c))
+ return lj_char_isdigit(cp->c) ? cp_number(cp) : cp_ident(cp);
+ switch (cp->c) {
+ case '\n': case '\r': cp_newline(cp); /* fallthrough. */
+ case ' ': case '\t': case '\v': case '\f': cp_get(cp); break;
+ case '"': case '\'': return cp_string(cp);
+ case '/':
+ if (cp_get(cp) == '*') cp_comment_c(cp);
+ else if (cp->c == '/') cp_comment_cpp(cp);
+ else return '/';
+ break;
+ case '|':
+ if (cp_get(cp) != '|') return '|';
+ cp_get(cp); return CTOK_OROR;
+ case '&':
+ if (cp_get(cp) != '&') return '&';
+ cp_get(cp); return CTOK_ANDAND;
+ case '=':
+ if (cp_get(cp) != '=') return '=';
+ cp_get(cp); return CTOK_EQ;
+ case '!':
+ if (cp_get(cp) != '=') return '!';
+ cp_get(cp); return CTOK_NE;
+ case '<':
+ if (cp_get(cp) == '=') { cp_get(cp); return CTOK_LE; }
+ else if (cp->c == '<') { cp_get(cp); return CTOK_SHL; }
+ return '<';
+ case '>':
+ if (cp_get(cp) == '=') { cp_get(cp); return CTOK_GE; }
+ else if (cp->c == '>') { cp_get(cp); return CTOK_SHR; }
+ return '>';
+ case '-':
+ if (cp_get(cp) != '>') return '-';
+ cp_get(cp); return CTOK_DEREF;
+ case '$':
+ return cp_param(cp);
+ case '\0': return CTOK_EOF;
+ default: { CPToken c = cp->c; cp_get(cp); return c; }
+ }
+ }
+}
+
+static LJ_NOINLINE CPToken cp_next(CPState *cp)
+{
+ return (cp->tok = cp_next_(cp));
+}
+
+/* -- C parser ------------------------------------------------------------ */
+
+/* Namespaces for resolving identifiers. */
+#define CPNS_DEFAULT \
+ ((1u<<CT_KW)|(1u<<CT_TYPEDEF)|(1u<<CT_FUNC)|(1u<<CT_EXTERN)|(1u<<CT_CONSTVAL))
+#define CPNS_STRUCT ((1u<<CT_KW)|(1u<<CT_STRUCT)|(1u<<CT_ENUM))
+
+typedef CTypeID CPDeclIdx; /* Index into declaration stack. */
+typedef uint32_t CPscl; /* Storage class flags. */
+
+/* Type declaration context. */
+typedef struct CPDecl {
+ CPDeclIdx top; /* Top of declaration stack. */
+ CPDeclIdx pos; /* Insertion position in declaration chain. */
+ CPDeclIdx specpos; /* Saved position for declaration specifier. */
+ uint32_t mode; /* Declarator mode. */
+ CPState *cp; /* C parser state. */
+ GCstr *name; /* Name of declared identifier (if direct). */
+ GCstr *redir; /* Redirected symbol name. */
+ CTypeID nameid; /* Existing typedef for declared identifier. */
+ CTInfo attr; /* Attributes. */
+ CTInfo fattr; /* Function attributes. */
+ CTInfo specattr; /* Saved attributes. */
+ CTInfo specfattr; /* Saved function attributes. */
+ CTSize bits; /* Field size in bits (if any). */
+ CType stack[CPARSE_MAX_DECLSTACK]; /* Type declaration stack. */
+} CPDecl;
+
+/* Forward declarations. */
+static CPscl cp_decl_spec(CPState *cp, CPDecl *decl, CPscl scl);
+static void cp_declarator(CPState *cp, CPDecl *decl);
+static CTypeID cp_decl_abstract(CPState *cp);
+
+/* Initialize C parser state. Caller must set up: L, p, srcname, mode. */
+static void cp_init(CPState *cp)
+{
+ cp->linenumber = 1;
+ cp->depth = 0;
+ cp->curpack = 0;
+ cp->packstack[0] = 255;
+ lj_str_initbuf(&cp->sb);
+ lj_str_resizebuf(cp->L, &cp->sb, LJ_MIN_SBUF);
+ lua_assert(cp->p != NULL);
+ cp_get(cp); /* Read-ahead first char. */
+ cp->tok = 0;
+ cp->tmask = CPNS_DEFAULT;
+ cp_next(cp); /* Read-ahead first token. */
+}
+
+/* Cleanup C parser state. */
+static void cp_cleanup(CPState *cp)
+{
+ global_State *g = G(cp->L);
+ lj_str_freebuf(g, &cp->sb);
+}
+
+/* Check and consume optional token. */
+static int cp_opt(CPState *cp, CPToken tok)
+{
+ if (cp->tok == tok) { cp_next(cp); return 1; }
+ return 0;
+}
+
+/* Check and consume token. */
+static void cp_check(CPState *cp, CPToken tok)
+{
+ if (cp->tok != tok) cp_err_token(cp, tok);
+ cp_next(cp);
+}
+
+/* Check if the next token may start a type declaration. */
+static int cp_istypedecl(CPState *cp)
+{
+ if (cp->tok >= CTOK_FIRSTDECL && cp->tok <= CTOK_LASTDECL) return 1;
+ if (cp->tok == CTOK_IDENT && ctype_istypedef(cp->ct->info)) return 1;
+ if (cp->tok == '$') return 1;
+ return 0;
+}
+
+/* -- Constant expression evaluator --------------------------------------- */
+
+/* Forward declarations. */
+static void cp_expr_unary(CPState *cp, CPValue *k);
+static void cp_expr_sub(CPState *cp, CPValue *k, int pri);
+
+/* Please note that type handling is very weak here. Most ops simply
+** assume integer operands. Accessors are only needed to compute types and
+** return synthetic values. The only purpose of the expression evaluator
+** is to compute the values of constant expressions one would typically
+** find in C header files. And again: this is NOT a validating C parser!
+*/
+
+/* Parse comma separated expression and return last result. */
+static void cp_expr_comma(CPState *cp, CPValue *k)
+{
+ do { cp_expr_sub(cp, k, 0); } while (cp_opt(cp, ','));
+}
+
+/* Parse sizeof/alignof operator. */
+static void cp_expr_sizeof(CPState *cp, CPValue *k, int wantsz)
+{
+ CTSize sz;
+ CTInfo info;
+ if (cp_opt(cp, '(')) {
+ if (cp_istypedecl(cp))
+ k->id = cp_decl_abstract(cp);
+ else
+ cp_expr_comma(cp, k);
+ cp_check(cp, ')');
+ } else {
+ cp_expr_unary(cp, k);
+ }
+ info = lj_ctype_info(cp->cts, k->id, &sz);
+ if (wantsz) {
+ if (sz != CTSIZE_INVALID)
+ k->u32 = sz;
+ else if (k->id != CTID_A_CCHAR) /* Special case for sizeof("string"). */
+ cp_err(cp, LJ_ERR_FFI_INVSIZE);
+ } else {
+ k->u32 = 1u << ctype_align(info);
+ }
+ k->id = CTID_UINT32; /* Really size_t. */
+}
+
+/* Parse prefix operators. */
+static void cp_expr_prefix(CPState *cp, CPValue *k)
+{
+ if (cp->tok == CTOK_INTEGER) {
+ *k = cp->val; cp_next(cp);
+ } else if (cp_opt(cp, '+')) {
+ cp_expr_unary(cp, k); /* Nothing to do (well, integer promotion). */
+ } else if (cp_opt(cp, '-')) {
+ cp_expr_unary(cp, k); k->i32 = -k->i32;
+ } else if (cp_opt(cp, '~')) {
+ cp_expr_unary(cp, k); k->i32 = ~k->i32;
+ } else if (cp_opt(cp, '!')) {
+ cp_expr_unary(cp, k); k->i32 = !k->i32; k->id = CTID_INT32;
+ } else if (cp_opt(cp, '(')) {
+ if (cp_istypedecl(cp)) { /* Cast operator. */
+ CTypeID id = cp_decl_abstract(cp);
+ cp_check(cp, ')');
+ cp_expr_unary(cp, k);
+ k->id = id; /* No conversion performed. */
+ } else { /* Sub-expression. */
+ cp_expr_comma(cp, k);
+ cp_check(cp, ')');
+ }
+ } else if (cp_opt(cp, '*')) { /* Indirection. */
+ CType *ct;
+ cp_expr_unary(cp, k);
+ ct = lj_ctype_rawref(cp->cts, k->id);
+ if (!ctype_ispointer(ct->info))
+ cp_err_badidx(cp, ct);
+ k->u32 = 0; k->id = ctype_cid(ct->info);
+ } else if (cp_opt(cp, '&')) { /* Address operator. */
+ cp_expr_unary(cp, k);
+ k->id = lj_ctype_intern(cp->cts, CTINFO(CT_PTR, CTALIGN_PTR+k->id),
+ CTSIZE_PTR);
+ } else if (cp_opt(cp, CTOK_SIZEOF)) {
+ cp_expr_sizeof(cp, k, 1);
+ } else if (cp_opt(cp, CTOK_ALIGNOF)) {
+ cp_expr_sizeof(cp, k, 0);
+ } else if (cp->tok == CTOK_IDENT) {
+ if (ctype_type(cp->ct->info) == CT_CONSTVAL) {
+ k->u32 = cp->ct->size; k->id = ctype_cid(cp->ct->info);
+ } else if (ctype_type(cp->ct->info) == CT_EXTERN) {
+ k->u32 = cp->val.id; k->id = ctype_cid(cp->ct->info);
+ } else if (ctype_type(cp->ct->info) == CT_FUNC) {
+ k->u32 = cp->val.id; k->id = cp->val.id;
+ } else {
+ goto err_expr;
+ }
+ cp_next(cp);
+ } else if (cp->tok == CTOK_STRING) {
+ CTSize sz = cp->str->len;
+ while (cp_next(cp) == CTOK_STRING)
+ sz += cp->str->len;
+ k->u32 = sz + 1;
+ k->id = CTID_A_CCHAR;
+ } else {
+ err_expr:
+ cp_errmsg(cp, cp->tok, LJ_ERR_XSYMBOL);
+ }
+}
+
+/* Parse postfix operators. */
+static void cp_expr_postfix(CPState *cp, CPValue *k)
+{
+ for (;;) {
+ CType *ct;
+ if (cp_opt(cp, '[')) { /* Array/pointer index. */
+ CPValue k2;
+ cp_expr_comma(cp, &k2);
+ ct = lj_ctype_rawref(cp->cts, k->id);
+ if (!ctype_ispointer(ct->info)) {
+ ct = lj_ctype_rawref(cp->cts, k2.id);
+ if (!ctype_ispointer(ct->info))
+ cp_err_badidx(cp, ct);
+ }
+ cp_check(cp, ']');
+ k->u32 = 0;
+ } else if (cp->tok == '.' || cp->tok == CTOK_DEREF) { /* Struct deref. */
+ CTSize ofs;
+ CType *fct;
+ ct = lj_ctype_rawref(cp->cts, k->id);
+ if (cp->tok == CTOK_DEREF) {
+ if (!ctype_ispointer(ct->info))
+ cp_err_badidx(cp, ct);
+ ct = lj_ctype_rawref(cp->cts, ctype_cid(ct->info));
+ }
+ cp_next(cp);
+ if (cp->tok != CTOK_IDENT) cp_err_token(cp, CTOK_IDENT);
+ if (!ctype_isstruct(ct->info) || ct->size == CTSIZE_INVALID ||
+ !(fct = lj_ctype_getfield(cp->cts, ct, cp->str, &ofs)) ||
+ ctype_isbitfield(fct->info)) {
+ GCstr *s = lj_ctype_repr(cp->cts->L, ctype_typeid(cp->cts, ct), NULL);
+ cp_errmsg(cp, 0, LJ_ERR_FFI_BADMEMBER, strdata(s), strdata(cp->str));
+ }
+ ct = fct;
+ k->u32 = ctype_isconstval(ct->info) ? ct->size : 0;
+ cp_next(cp);
+ } else {
+ return;
+ }
+ k->id = ctype_cid(ct->info);
+ }
+}
+
+/* Parse infix operators. */
+static void cp_expr_infix(CPState *cp, CPValue *k, int pri)
+{
+ CPValue k2;
+ k2.u32 = 0; k2.id = 0; /* Silence the compiler. */
+ for (;;) {
+ switch (pri) {
+ case 0:
+ if (cp_opt(cp, '?')) {
+ CPValue k3;
+ cp_expr_comma(cp, &k2); /* Right-associative. */
+ cp_check(cp, ':');
+ cp_expr_sub(cp, &k3, 0);
+ k->u32 = k->u32 ? k2.u32 : k3.u32;
+ k->id = k2.id > k3.id ? k2.id : k3.id;
+ continue;
+ }
+ /* fallthrough */
+ case 1:
+ if (cp_opt(cp, CTOK_OROR)) {
+ cp_expr_sub(cp, &k2, 2); k->i32 = k->u32 || k2.u32; k->id = CTID_INT32;
+ continue;
+ }
+ /* fallthrough */
+ case 2:
+ if (cp_opt(cp, CTOK_ANDAND)) {
+ cp_expr_sub(cp, &k2, 3); k->i32 = k->u32 && k2.u32; k->id = CTID_INT32;
+ continue;
+ }
+ /* fallthrough */
+ case 3:
+ if (cp_opt(cp, '|')) {
+ cp_expr_sub(cp, &k2, 4); k->u32 = k->u32 | k2.u32; goto arith_result;
+ }
+ /* fallthrough */
+ case 4:
+ if (cp_opt(cp, '^')) {
+ cp_expr_sub(cp, &k2, 5); k->u32 = k->u32 ^ k2.u32; goto arith_result;
+ }
+ /* fallthrough */
+ case 5:
+ if (cp_opt(cp, '&')) {
+ cp_expr_sub(cp, &k2, 6); k->u32 = k->u32 & k2.u32; goto arith_result;
+ }
+ /* fallthrough */
+ case 6:
+ if (cp_opt(cp, CTOK_EQ)) {
+ cp_expr_sub(cp, &k2, 7); k->i32 = k->u32 == k2.u32; k->id = CTID_INT32;
+ continue;
+ } else if (cp_opt(cp, CTOK_NE)) {
+ cp_expr_sub(cp, &k2, 7); k->i32 = k->u32 != k2.u32; k->id = CTID_INT32;
+ continue;
+ }
+ /* fallthrough */
+ case 7:
+ if (cp_opt(cp, '<')) {
+ cp_expr_sub(cp, &k2, 8);
+ if (k->id == CTID_INT32 && k2.id == CTID_INT32)
+ k->i32 = k->i32 < k2.i32;
+ else
+ k->i32 = k->u32 < k2.u32;
+ k->id = CTID_INT32;
+ continue;
+ } else if (cp_opt(cp, '>')) {
+ cp_expr_sub(cp, &k2, 8);
+ if (k->id == CTID_INT32 && k2.id == CTID_INT32)
+ k->i32 = k->i32 > k2.i32;
+ else
+ k->i32 = k->u32 > k2.u32;
+ k->id = CTID_INT32;
+ continue;
+ } else if (cp_opt(cp, CTOK_LE)) {
+ cp_expr_sub(cp, &k2, 8);
+ if (k->id == CTID_INT32 && k2.id == CTID_INT32)
+ k->i32 = k->i32 <= k2.i32;
+ else
+ k->i32 = k->u32 <= k2.u32;
+ k->id = CTID_INT32;
+ continue;
+ } else if (cp_opt(cp, CTOK_GE)) {
+ cp_expr_sub(cp, &k2, 8);
+ if (k->id == CTID_INT32 && k2.id == CTID_INT32)
+ k->i32 = k->i32 >= k2.i32;
+ else
+ k->i32 = k->u32 >= k2.u32;
+ k->id = CTID_INT32;
+ continue;
+ }
+ /* fallthrough */
+ case 8:
+ if (cp_opt(cp, CTOK_SHL)) {
+ cp_expr_sub(cp, &k2, 9); k->u32 = k->u32 << k2.u32;
+ continue;
+ } else if (cp_opt(cp, CTOK_SHR)) {
+ cp_expr_sub(cp, &k2, 9);
+ if (k->id == CTID_INT32)
+ k->i32 = k->i32 >> k2.i32;
+ else
+ k->u32 = k->u32 >> k2.u32;
+ continue;
+ }
+ /* fallthrough */
+ case 9:
+ if (cp_opt(cp, '+')) {
+ cp_expr_sub(cp, &k2, 10); k->u32 = k->u32 + k2.u32;
+ arith_result:
+ if (k2.id > k->id) k->id = k2.id; /* Trivial promotion to unsigned. */
+ continue;
+ } else if (cp_opt(cp, '-')) {
+ cp_expr_sub(cp, &k2, 10); k->u32 = k->u32 - k2.u32; goto arith_result;
+ }
+ /* fallthrough */
+ case 10:
+ if (cp_opt(cp, '*')) {
+ cp_expr_unary(cp, &k2); k->u32 = k->u32 * k2.u32; goto arith_result;
+ } else if (cp_opt(cp, '/')) {
+ cp_expr_unary(cp, &k2);
+ if (k2.id > k->id) k->id = k2.id; /* Trivial promotion to unsigned. */
+ if (k2.u32 == 0 ||
+ (k->id == CTID_INT32 && k->u32 == 0x80000000u && k2.i32 == -1))
+ cp_err(cp, LJ_ERR_BADVAL);
+ if (k->id == CTID_INT32)
+ k->i32 = k->i32 / k2.i32;
+ else
+ k->u32 = k->u32 / k2.u32;
+ continue;
+ } else if (cp_opt(cp, '%')) {
+ cp_expr_unary(cp, &k2);
+ if (k2.id > k->id) k->id = k2.id; /* Trivial promotion to unsigned. */
+ if (k2.u32 == 0 ||
+ (k->id == CTID_INT32 && k->u32 == 0x80000000u && k2.i32 == -1))
+ cp_err(cp, LJ_ERR_BADVAL);
+ if (k->id == CTID_INT32)
+ k->i32 = k->i32 % k2.i32;
+ else
+ k->u32 = k->u32 % k2.u32;
+ continue;
+ }
+ default:
+ return;
+ }
+ }
+}
+
+/* Parse and evaluate unary expression. */
+static void cp_expr_unary(CPState *cp, CPValue *k)
+{
+ if (++cp->depth > CPARSE_MAX_DECLDEPTH) cp_err(cp, LJ_ERR_XLEVELS);
+ cp_expr_prefix(cp, k);
+ cp_expr_postfix(cp, k);
+ cp->depth--;
+}
+
+/* Parse and evaluate sub-expression. */
+static void cp_expr_sub(CPState *cp, CPValue *k, int pri)
+{
+ cp_expr_unary(cp, k);
+ cp_expr_infix(cp, k, pri);
+}
+
+/* Parse constant integer expression. */
+static void cp_expr_kint(CPState *cp, CPValue *k)
+{
+ CType *ct;
+ cp_expr_sub(cp, k, 0);
+ ct = ctype_raw(cp->cts, k->id);
+ if (!ctype_isinteger(ct->info)) cp_err(cp, LJ_ERR_BADVAL);
+}
+
+/* Parse (non-negative) size expression. */
+static CTSize cp_expr_ksize(CPState *cp)
+{
+ CPValue k;
+ cp_expr_kint(cp, &k);
+ if (k.u32 >= 0x80000000u) cp_err(cp, LJ_ERR_FFI_INVSIZE);
+ return k.u32;
+}
+
+/* -- Type declaration stack management ----------------------------------- */
+
+/* Add declaration element behind the insertion position. */
+static CPDeclIdx cp_add(CPDecl *decl, CTInfo info, CTSize size)
+{
+ CPDeclIdx top = decl->top;
+ if (top >= CPARSE_MAX_DECLSTACK) cp_err(decl->cp, LJ_ERR_XLEVELS);
+ decl->stack[top].info = info;
+ decl->stack[top].size = size;
+ decl->stack[top].sib = 0;
+ setgcrefnull(decl->stack[top].name);
+ decl->stack[top].next = decl->stack[decl->pos].next;
+ decl->stack[decl->pos].next = (CTypeID1)top;
+ decl->top = top+1;
+ return top;
+}
+
+/* Push declaration element before the insertion position. */
+static CPDeclIdx cp_push(CPDecl *decl, CTInfo info, CTSize size)
+{
+ return (decl->pos = cp_add(decl, info, size));
+}
+
+/* Push or merge attributes. */
+static void cp_push_attributes(CPDecl *decl)
+{
+ CType *ct = &decl->stack[decl->pos];
+ if (ctype_isfunc(ct->info)) { /* Ok to modify in-place. */
+#if LJ_TARGET_X86
+ if ((decl->fattr & CTFP_CCONV))
+ ct->info = (ct->info & (CTMASK_NUM|CTF_VARARG|CTMASK_CID)) +
+ (decl->fattr & ~CTMASK_CID);
+#endif
+ } else {
+ if ((decl->attr & CTFP_ALIGNED) && !(decl->mode & CPARSE_MODE_FIELD))
+ cp_push(decl, CTINFO(CT_ATTRIB, CTATTRIB(CTA_ALIGN)),
+ ctype_align(decl->attr));
+ }
+}
+
+/* Push unrolled type to declaration stack and merge qualifiers. */
+static void cp_push_type(CPDecl *decl, CTypeID id)
+{
+ CType *ct = ctype_get(decl->cp->cts, id);
+ CTInfo info = ct->info;
+ CTSize size = ct->size;
+ switch (ctype_type(info)) {
+ case CT_STRUCT: case CT_ENUM:
+ cp_push(decl, CTINFO(CT_TYPEDEF, id), 0); /* Don't copy unique types. */
+ if ((decl->attr & CTF_QUAL)) { /* Push unmerged qualifiers. */
+ cp_push(decl, CTINFO(CT_ATTRIB, CTATTRIB(CTA_QUAL)),
+ (decl->attr & CTF_QUAL));
+ decl->attr &= ~CTF_QUAL;
+ }
+ break;
+ case CT_ATTRIB:
+ if (ctype_isxattrib(info, CTA_QUAL))
+ decl->attr &= ~size; /* Remove redundant qualifiers. */
+ cp_push_type(decl, ctype_cid(info)); /* Unroll. */
+ cp_push(decl, info & ~CTMASK_CID, size); /* Copy type. */
+ break;
+ case CT_ARRAY:
+ if ((ct->info & (CTF_VECTOR|CTF_COMPLEX))) {
+ info |= (decl->attr & CTF_QUAL);
+ decl->attr &= ~CTF_QUAL;
+ }
+ cp_push_type(decl, ctype_cid(info)); /* Unroll. */
+ cp_push(decl, info & ~CTMASK_CID, size); /* Copy type. */
+ decl->stack[decl->pos].sib = 1; /* Mark as already checked and sized. */
+ /* Note: this is not copied to the ct->sib in the C type table. */
+ break;
+ case CT_FUNC:
+ /* Copy type, link parameters (shared). */
+ decl->stack[cp_push(decl, info, size)].sib = ct->sib;
+ break;
+ default:
+ /* Copy type, merge common qualifiers. */
+ cp_push(decl, info|(decl->attr & CTF_QUAL), size);
+ decl->attr &= ~CTF_QUAL;
+ break;
+ }
+}
+
+/* Consume the declaration element chain and intern the C type. */
+static CTypeID cp_decl_intern(CPState *cp, CPDecl *decl)
+{
+ CTypeID id = 0;
+ CPDeclIdx idx = 0;
+ CTSize csize = CTSIZE_INVALID;
+ CTSize cinfo = 0;
+ do {
+ CType *ct = &decl->stack[idx];
+ CTInfo info = ct->info;
+ CTInfo size = ct->size;
+ /* The cid is already part of info for copies of pointers/functions. */
+ idx = ct->next;
+ if (ctype_istypedef(info)) {
+ lua_assert(id == 0);
+ id = ctype_cid(info);
+ /* Always refetch info/size, since struct/enum may have been completed. */
+ cinfo = ctype_get(cp->cts, id)->info;
+ csize = ctype_get(cp->cts, id)->size;
+ lua_assert(ctype_isstruct(cinfo) || ctype_isenum(cinfo));
+ } else if (ctype_isfunc(info)) { /* Intern function. */
+ CType *fct;
+ CTypeID fid;
+ CTypeID sib;
+ if (id) {
+ CType *refct = ctype_raw(cp->cts, id);
+ /* Reject function or refarray return types. */
+ if (ctype_isfunc(refct->info) || ctype_isrefarray(refct->info))
+ cp_err(cp, LJ_ERR_FFI_INVTYPE);
+ }
+ /* No intervening attributes allowed, skip forward. */
+ while (idx) {
+ CType *ctn = &decl->stack[idx];
+ if (!ctype_isattrib(ctn->info)) break;
+ idx = ctn->next; /* Skip attribute. */
+ }
+ sib = ct->sib; /* Next line may reallocate the C type table. */
+ fid = lj_ctype_new(cp->cts, &fct);
+ csize = CTSIZE_INVALID;
+ fct->info = cinfo = info + id;
+ fct->size = size;
+ fct->sib = sib;
+ id = fid;
+ } else if (ctype_isattrib(info)) {
+ if (ctype_isxattrib(info, CTA_QUAL))
+ cinfo |= size;
+ else if (ctype_isxattrib(info, CTA_ALIGN))
+ CTF_INSERT(cinfo, ALIGN, size);
+ id = lj_ctype_intern(cp->cts, info+id, size);
+ /* Inherit csize/cinfo from original type. */
+ } else {
+ if (ctype_isnum(info)) { /* Handle mode/vector-size attributes. */
+ lua_assert(id == 0);
+ if (!(info & CTF_BOOL)) {
+ CTSize msize = ctype_msizeP(decl->attr);
+ CTSize vsize = ctype_vsizeP(decl->attr);
+ if (msize && (!(info & CTF_FP) || (msize == 4 || msize == 8))) {
+ CTSize malign = lj_fls(msize);
+ if (malign > 4) malign = 4; /* Limit alignment. */
+ CTF_INSERT(info, ALIGN, malign);
+ size = msize; /* Override size via mode. */
+ }
+ if (vsize) { /* Vector size set? */
+ CTSize esize = lj_fls(size);
+ if (vsize >= esize) {
+ /* Intern the element type first. */
+ id = lj_ctype_intern(cp->cts, info, size);
+ /* Then create a vector (array) with vsize alignment. */
+ size = (1u << vsize);
+ if (vsize > 4) vsize = 4; /* Limit alignment. */
+ if (ctype_align(info) > vsize) vsize = ctype_align(info);
+ info = CTINFO(CT_ARRAY, (info & CTF_QUAL) + CTF_VECTOR +
+ CTALIGN(vsize));
+ }
+ }
+ }
+ } else if (ctype_isptr(info)) {
+ /* Reject pointer/ref to ref. */
+ if (id && ctype_isref(ctype_raw(cp->cts, id)->info))
+ cp_err(cp, LJ_ERR_FFI_INVTYPE);
+ if (ctype_isref(info)) {
+ info &= ~CTF_VOLATILE; /* Refs are always const, never volatile. */
+ /* No intervening attributes allowed, skip forward. */
+ while (idx) {
+ CType *ctn = &decl->stack[idx];
+ if (!ctype_isattrib(ctn->info)) break;
+ idx = ctn->next; /* Skip attribute. */
+ }
+ }
+ } else if (ctype_isarray(info)) { /* Check for valid array size etc. */
+ if (ct->sib == 0) { /* Only check/size arrays not copied by unroll. */
+ if (ctype_isref(cinfo)) /* Reject arrays of refs. */
+ cp_err(cp, LJ_ERR_FFI_INVTYPE);
+ /* Reject VLS or unknown-sized types. */
+ if (ctype_isvltype(cinfo) || csize == CTSIZE_INVALID)
+ cp_err(cp, LJ_ERR_FFI_INVSIZE);
+ /* a[] and a[?] keep their invalid size. */
+ if (size != CTSIZE_INVALID) {
+ uint64_t xsz = (uint64_t)size * csize;
+ if (xsz >= 0x80000000u) cp_err(cp, LJ_ERR_FFI_INVSIZE);
+ size = (CTSize)xsz;
+ }
+ }
+ if ((cinfo & CTF_ALIGN) > (info & CTF_ALIGN)) /* Find max. align. */
+ info = (info & ~CTF_ALIGN) | (cinfo & CTF_ALIGN);
+ info |= (cinfo & CTF_QUAL); /* Inherit qual. */
+ } else {
+ lua_assert(ctype_isvoid(info));
+ }
+ csize = size;
+ cinfo = info+id;
+ id = lj_ctype_intern(cp->cts, info+id, size);
+ }
+ } while (idx);
+ return id;
+}
+
+/* -- C declaration parser ------------------------------------------------ */
+
+#define H_(le, be) LJ_ENDIAN_SELECT(0x##le, 0x##be)
+
+/* Reset declaration state to declaration specifier. */
+static void cp_decl_reset(CPDecl *decl)
+{
+ decl->pos = decl->specpos;
+ decl->top = decl->specpos+1;
+ decl->stack[decl->specpos].next = 0;
+ decl->attr = decl->specattr;
+ decl->fattr = decl->specfattr;
+ decl->name = NULL;
+ decl->redir = NULL;
+}
+
+/* Parse constant initializer. */
+/* NYI: FP constants and strings as initializers. */
+static CTypeID cp_decl_constinit(CPState *cp, CType **ctp, CTypeID ctypeid)
+{
+ CType *ctt = ctype_get(cp->cts, ctypeid);
+ CTInfo info;
+ CTSize size;
+ CPValue k;
+ CTypeID constid;
+ while (ctype_isattrib(ctt->info)) { /* Skip attributes. */
+ ctypeid = ctype_cid(ctt->info); /* Update ID, too. */
+ ctt = ctype_get(cp->cts, ctypeid);
+ }
+ info = ctt->info;
+ size = ctt->size;
+ if (!ctype_isinteger(info) || !(info & CTF_CONST) || size > 4)
+ cp_err(cp, LJ_ERR_FFI_INVTYPE);
+ cp_check(cp, '=');
+ cp_expr_sub(cp, &k, 0);
+ constid = lj_ctype_new(cp->cts, ctp);
+ (*ctp)->info = CTINFO(CT_CONSTVAL, CTF_CONST|ctypeid);
+ k.u32 <<= 8*(4-size);
+ if ((info & CTF_UNSIGNED))
+ k.u32 >>= 8*(4-size);
+ else
+ k.u32 = (uint32_t)((int32_t)k.u32 >> 8*(4-size));
+ (*ctp)->size = k.u32;
+ return constid;
+}
+
+/* Parse size in parentheses as part of attribute. */
+static CTSize cp_decl_sizeattr(CPState *cp)
+{
+ CTSize sz;
+ uint32_t oldtmask = cp->tmask;
+ cp->tmask = CPNS_DEFAULT; /* Required for expression evaluator. */
+ cp_check(cp, '(');
+ sz = cp_expr_ksize(cp);
+ cp->tmask = oldtmask;
+ cp_check(cp, ')');
+ return sz;
+}
+
+/* Parse alignment attribute. */
+static void cp_decl_align(CPState *cp, CPDecl *decl)
+{
+ CTSize al = 4; /* Unspecified alignment is 16 bytes. */
+ if (cp->tok == '(') {
+ al = cp_decl_sizeattr(cp);
+ al = al ? lj_fls(al) : 0;
+ }
+ CTF_INSERT(decl->attr, ALIGN, al);
+ decl->attr |= CTFP_ALIGNED;
+}
+
+/* Parse GCC asm("name") redirect. */
+static void cp_decl_asm(CPState *cp, CPDecl *decl)
+{
+ UNUSED(decl);
+ cp_next(cp);
+ cp_check(cp, '(');
+ if (cp->tok == CTOK_STRING) {
+ GCstr *str = cp->str;
+ while (cp_next(cp) == CTOK_STRING) {
+ lj_str_pushf(cp->L, "%s%s", strdata(str), strdata(cp->str));
+ cp->L->top--;
+ str = strV(cp->L->top);
+ }
+ decl->redir = str;
+ }
+ cp_check(cp, ')');
+}
+
+/* Parse GCC __attribute__((mode(...))). */
+static void cp_decl_mode(CPState *cp, CPDecl *decl)
+{
+ cp_check(cp, '(');
+ if (cp->tok == CTOK_IDENT) {
+ const char *s = strdata(cp->str);
+ CTSize sz = 0, vlen = 0;
+ if (s[0] == '_' && s[1] == '_') s += 2;
+ if (*s == 'V') {
+ s++;
+ vlen = *s++ - '0';
+ if (*s >= '0' && *s <= '9')
+ vlen = vlen*10 + (*s++ - '0');
+ }
+ switch (*s++) {
+ case 'Q': sz = 1; break;
+ case 'H': sz = 2; break;
+ case 'S': sz = 4; break;
+ case 'D': sz = 8; break;
+ case 'T': sz = 16; break;
+ case 'O': sz = 32; break;
+ default: goto bad_size;
+ }
+ if (*s == 'I' || *s == 'F') {
+ CTF_INSERT(decl->attr, MSIZEP, sz);
+ if (vlen) CTF_INSERT(decl->attr, VSIZEP, lj_fls(vlen*sz));
+ }
+ bad_size:
+ cp_next(cp);
+ }
+ cp_check(cp, ')');
+}
+
+/* Parse GCC __attribute__((...)). */
+static void cp_decl_gccattribute(CPState *cp, CPDecl *decl)
+{
+ cp_next(cp);
+ cp_check(cp, '(');
+ cp_check(cp, '(');
+ while (cp->tok != ')') {
+ if (cp->tok == CTOK_IDENT) {
+ GCstr *attrstr = cp->str;
+ cp_next(cp);
+ switch (attrstr->hash) {
+ case H_(64a9208e,8ce14319): case H_(8e6331b2,95a282af): /* aligned */
+ cp_decl_align(cp, decl);
+ break;
+ case H_(42eb47de,f0ede26c): case H_(29f48a09,cf383e0c): /* packed */
+ decl->attr |= CTFP_PACKED;
+ break;
+ case H_(0a84eef6,8dfab04c): case H_(995cf92c,d5696591): /* mode */
+ cp_decl_mode(cp, decl);
+ break;
+ case H_(0ab31997,2d5213fa): case H_(bf875611,200e9990): /* vector_size */
+ {
+ CTSize vsize = cp_decl_sizeattr(cp);
+ if (vsize) CTF_INSERT(decl->attr, VSIZEP, lj_fls(vsize));
+ }
+ break;
+#if LJ_TARGET_X86
+ case H_(5ad22db8,c689b848): case H_(439150fa,65ea78cb): /* regparm */
+ CTF_INSERT(decl->fattr, REGPARM, cp_decl_sizeattr(cp));
+ decl->fattr |= CTFP_CCONV;
+ break;
+ case H_(18fc0b98,7ff4c074): case H_(4e62abed,0a747424): /* cdecl */
+ CTF_INSERT(decl->fattr, CCONV, CTCC_CDECL);
+ decl->fattr |= CTFP_CCONV;
+ break;
+ case H_(72b2e41b,494c5a44): case H_(f2356d59,f25fc9bd): /* thiscall */
+ CTF_INSERT(decl->fattr, CCONV, CTCC_THISCALL);
+ decl->fattr |= CTFP_CCONV;
+ break;
+ case H_(0d0ffc42,ab746f88): case H_(21c54ba1,7f0ca7e3): /* fastcall */
+ CTF_INSERT(decl->fattr, CCONV, CTCC_FASTCALL);
+ decl->fattr |= CTFP_CCONV;
+ break;
+ case H_(ef76b040,9412e06a): case H_(de56697b,c750e6e1): /* stdcall */
+ CTF_INSERT(decl->fattr, CCONV, CTCC_STDCALL);
+ decl->fattr |= CTFP_CCONV;
+ break;
+ case H_(ea78b622,f234bd8e): case H_(252ffb06,8d50f34b): /* sseregparm */
+ decl->fattr |= CTF_SSEREGPARM;
+ decl->fattr |= CTFP_CCONV;
+ break;
+#endif
+ default: /* Skip all other attributes. */
+ goto skip_attr;
+ }
+ } else if (cp->tok >= CTOK_FIRSTDECL) { /* For __attribute((const)) etc. */
+ cp_next(cp);
+ skip_attr:
+ if (cp_opt(cp, '(')) {
+ while (cp->tok != ')' && cp->tok != CTOK_EOF) cp_next(cp);
+ cp_check(cp, ')');
+ }
+ } else {
+ break;
+ }
+ if (!cp_opt(cp, ',')) break;
+ }
+ cp_check(cp, ')');
+ cp_check(cp, ')');
+}
+
+/* Parse MSVC __declspec(...). */
+static void cp_decl_msvcattribute(CPState *cp, CPDecl *decl)
+{
+ cp_next(cp);
+ cp_check(cp, '(');
+ while (cp->tok == CTOK_IDENT) {
+ GCstr *attrstr = cp->str;
+ cp_next(cp);
+ switch (attrstr->hash) {
+ case H_(bc2395fa,98f267f8): /* align */
+ cp_decl_align(cp, decl);
+ break;
+ default: /* Ignore all other attributes. */
+ if (cp_opt(cp, '(')) {
+ while (cp->tok != ')' && cp->tok != CTOK_EOF) cp_next(cp);
+ cp_check(cp, ')');
+ }
+ break;
+ }
+ }
+ cp_check(cp, ')');
+}
+
+/* Parse declaration attributes (and common qualifiers). */
+static void cp_decl_attributes(CPState *cp, CPDecl *decl)
+{
+ for (;;) {
+ switch (cp->tok) {
+ case CTOK_CONST: decl->attr |= CTF_CONST; break;
+ case CTOK_VOLATILE: decl->attr |= CTF_VOLATILE; break;
+ case CTOK_RESTRICT: break; /* Ignore. */
+ case CTOK_EXTENSION: break; /* Ignore. */
+ case CTOK_ATTRIBUTE: cp_decl_gccattribute(cp, decl); continue;
+ case CTOK_ASM: cp_decl_asm(cp, decl); continue;
+ case CTOK_DECLSPEC: cp_decl_msvcattribute(cp, decl); continue;
+ case CTOK_CCDECL:
+#if LJ_TARGET_X86
+ CTF_INSERT(decl->fattr, CCONV, cp->ct->size);
+ decl->fattr |= CTFP_CCONV;
+#endif
+ break;
+ case CTOK_PTRSZ:
+#if LJ_64
+ CTF_INSERT(decl->attr, MSIZEP, cp->ct->size);
+#endif
+ break;
+ default: return;
+ }
+ cp_next(cp);
+ }
+}
+
+/* Parse struct/union/enum name. */
+static CTypeID cp_struct_name(CPState *cp, CPDecl *sdecl, CTInfo info)
+{
+ CTypeID sid;
+ CType *ct;
+ cp->tmask = CPNS_STRUCT;
+ cp_next(cp);
+ cp_decl_attributes(cp, sdecl);
+ cp->tmask = CPNS_DEFAULT;
+ if (cp->tok != '{') {
+ if (cp->tok != CTOK_IDENT) cp_err_token(cp, CTOK_IDENT);
+ if (cp->val.id) { /* Name of existing struct/union/enum. */
+ sid = cp->val.id;
+ ct = cp->ct;
+ if ((ct->info ^ info) & (CTMASK_NUM|CTF_UNION)) /* Wrong type. */
+ cp_errmsg(cp, 0, LJ_ERR_FFI_REDEF, strdata(gco2str(gcref(ct->name))));
+ } else { /* Create named, incomplete struct/union/enum. */
+ if ((cp->mode & CPARSE_MODE_NOIMPLICIT))
+ cp_errmsg(cp, 0, LJ_ERR_FFI_BADTAG, strdata(cp->str));
+ sid = lj_ctype_new(cp->cts, &ct);
+ ct->info = info;
+ ct->size = CTSIZE_INVALID;
+ ctype_setname(ct, cp->str);
+ lj_ctype_addname(cp->cts, ct, sid);
+ }
+ cp_next(cp);
+ } else { /* Create anonymous, incomplete struct/union/enum. */
+ sid = lj_ctype_new(cp->cts, &ct);
+ ct->info = info;
+ ct->size = CTSIZE_INVALID;
+ }
+ if (cp->tok == '{') {
+ if (ct->size != CTSIZE_INVALID || ct->sib)
+ cp_errmsg(cp, 0, LJ_ERR_FFI_REDEF, strdata(gco2str(gcref(ct->name))));
+ ct->sib = 1; /* Indicate the type is currently being defined. */
+ }
+ return sid;
+}
+
+/* Determine field alignment. */
+static CTSize cp_field_align(CPState *cp, CType *ct, CTInfo info)
+{
+ CTSize align = ctype_align(info);
+ UNUSED(cp); UNUSED(ct);
+#if (LJ_TARGET_X86 && !LJ_ABI_WIN) || (LJ_TARGET_ARM && __APPLE__)
+ /* The SYSV i386 and iOS ABIs limit alignment of non-vector fields to 2^2. */
+ if (align > 2 && !(info & CTFP_ALIGNED)) {
+ if (ctype_isarray(info) && !(info & CTF_VECTOR)) {
+ do {
+ ct = ctype_rawchild(cp->cts, ct);
+ info = ct->info;
+ } while (ctype_isarray(info) && !(info & CTF_VECTOR));
+ }
+ if (ctype_isnum(info) || ctype_isenum(info))
+ align = 2;
+ }
+#endif
+ return align;
+}
+
+/* Layout struct/union fields. */
+static void cp_struct_layout(CPState *cp, CTypeID sid, CTInfo sattr)
+{
+ CTSize bofs = 0, bmaxofs = 0; /* Bit offset and max. bit offset. */
+ CTSize maxalign = ctype_align(sattr);
+ CType *sct = ctype_get(cp->cts, sid);
+ CTInfo sinfo = sct->info;
+ CTypeID fieldid = sct->sib;
+ while (fieldid) {
+ CType *ct = ctype_get(cp->cts, fieldid);
+ CTInfo attr = ct->size; /* Field declaration attributes (temp.). */
+
+ if (ctype_isfield(ct->info) ||
+ (ctype_isxattrib(ct->info, CTA_SUBTYPE) && attr)) {
+ CTSize align, amask; /* Alignment (pow2) and alignment mask (bits). */
+ CTSize sz;
+ CTInfo info = lj_ctype_info(cp->cts, ctype_cid(ct->info), &sz);
+ CTSize bsz, csz = 8*sz; /* Field size and container size (in bits). */
+ sinfo |= (info & (CTF_QUAL|CTF_VLA)); /* Merge pseudo-qualifiers. */
+
+ /* Check for size overflow and determine alignment. */
+ if (sz >= 0x20000000u || bofs + csz < bofs || (info & CTF_VLA)) {
+ if (!(sz == CTSIZE_INVALID && ctype_isarray(info) &&
+ !(sinfo & CTF_UNION)))
+ cp_err(cp, LJ_ERR_FFI_INVSIZE);
+ csz = sz = 0; /* Treat a[] and a[?] as zero-sized. */
+ }
+ align = cp_field_align(cp, ct, info);
+ if (((attr|sattr) & CTFP_PACKED) ||
+ ((attr & CTFP_ALIGNED) && ctype_align(attr) > align))
+ align = ctype_align(attr);
+ if (cp->packstack[cp->curpack] < align)
+ align = cp->packstack[cp->curpack];
+ if (align > maxalign) maxalign = align;
+ amask = (8u << align) - 1;
+
+ bsz = ctype_bitcsz(ct->info); /* Bitfield size (temp.). */
+ if (bsz == CTBSZ_FIELD || !ctype_isfield(ct->info)) {
+ bsz = csz; /* Regular fields or subtypes always fill the container. */
+ bofs = (bofs + amask) & ~amask; /* Start new aligned field. */
+ ct->size = (bofs >> 3); /* Store field offset. */
+ } else { /* Bitfield. */
+ if (bsz == 0 || (attr & CTFP_ALIGNED) ||
+ (!((attr|sattr) & CTFP_PACKED) && (bofs & amask) + bsz > csz))
+ bofs = (bofs + amask) & ~amask; /* Start new aligned field. */
+
+ /* Prefer regular field over bitfield. */
+ if (bsz == csz && (bofs & amask) == 0) {
+ ct->info = CTINFO(CT_FIELD, ctype_cid(ct->info));
+ ct->size = (bofs >> 3); /* Store field offset. */
+ } else {
+ ct->info = CTINFO(CT_BITFIELD,
+ (info & (CTF_QUAL|CTF_UNSIGNED|CTF_BOOL)) +
+ (csz << (CTSHIFT_BITCSZ-3)) + (bsz << CTSHIFT_BITBSZ));
+#if LJ_BE
+ ct->info += ((csz - (bofs & (csz-1)) - bsz) << CTSHIFT_BITPOS);
+#else
+ ct->info += ((bofs & (csz-1)) << CTSHIFT_BITPOS);
+#endif
+ ct->size = ((bofs & ~(csz-1)) >> 3); /* Store container offset. */
+ }
+ }
+
+ /* Determine next offset or max. offset. */
+ if ((sinfo & CTF_UNION)) {
+ if (bsz > bmaxofs) bmaxofs = bsz;
+ } else {
+ bofs += bsz;
+ }
+ } /* All other fields in the chain are already set up. */
+
+ fieldid = ct->sib;
+ }
+
+ /* Complete struct/union. */
+ sct->info = sinfo + CTALIGN(maxalign);
+ bofs = (sinfo & CTF_UNION) ? bmaxofs : bofs;
+ maxalign = (8u << maxalign) - 1;
+ sct->size = (((bofs + maxalign) & ~maxalign) >> 3);
+}
+
+/* Parse struct/union declaration. */
+static CTypeID cp_decl_struct(CPState *cp, CPDecl *sdecl, CTInfo sinfo)
+{
+ CTypeID sid = cp_struct_name(cp, sdecl, sinfo);
+ if (cp_opt(cp, '{')) { /* Struct/union definition. */
+ CTypeID lastid = sid;
+ int lastdecl = 0;
+ while (cp->tok != '}') {
+ CPDecl decl;
+ CPscl scl = cp_decl_spec(cp, &decl, CDF_STATIC);
+ decl.mode = scl ? CPARSE_MODE_DIRECT :
+ CPARSE_MODE_DIRECT|CPARSE_MODE_ABSTRACT|CPARSE_MODE_FIELD;
+
+ for (;;) {
+ CTypeID ctypeid;
+
+ if (lastdecl) cp_err_token(cp, '}');
+
+ /* Parse field declarator. */
+ decl.bits = CTSIZE_INVALID;
+ cp_declarator(cp, &decl);
+ ctypeid = cp_decl_intern(cp, &decl);
+
+ if ((scl & CDF_STATIC)) { /* Static constant in struct namespace. */
+ CType *ct;
+ CTypeID fieldid = cp_decl_constinit(cp, &ct, ctypeid);
+ ctype_get(cp->cts, lastid)->sib = fieldid;
+ lastid = fieldid;
+ ctype_setname(ct, decl.name);
+ } else {
+ CTSize bsz = CTBSZ_FIELD; /* Temp. for layout phase. */
+ CType *ct;
+ CTypeID fieldid = lj_ctype_new(cp->cts, &ct); /* Do this first. */
+ CType *tct = ctype_raw(cp->cts, ctypeid);
+
+ if (decl.bits == CTSIZE_INVALID) { /* Regular field. */
+ if (ctype_isarray(tct->info) && tct->size == CTSIZE_INVALID)
+ lastdecl = 1; /* a[] or a[?] must be the last declared field. */
+
+ /* Accept transparent struct/union/enum. */
+ if (!decl.name) {
+ if (!((ctype_isstruct(tct->info) && !(tct->info & CTF_VLA)) ||
+ ctype_isenum(tct->info)))
+ cp_err_token(cp, CTOK_IDENT);
+ ct->info = CTINFO(CT_ATTRIB, CTATTRIB(CTA_SUBTYPE) + ctypeid);
+ ct->size = ctype_isstruct(tct->info) ?
+ (decl.attr|0x80000000u) : 0; /* For layout phase. */
+ goto add_field;
+ }
+ } else { /* Bitfield. */
+ bsz = decl.bits;
+ if (!ctype_isinteger_or_bool(tct->info) ||
+ (bsz == 0 && decl.name) || 8*tct->size > CTBSZ_MAX ||
+ bsz > ((tct->info & CTF_BOOL) ? 1 : 8*tct->size))
+ cp_errmsg(cp, ':', LJ_ERR_BADVAL);
+ }
+
+ /* Create temporary field for layout phase. */
+ ct->info = CTINFO(CT_FIELD, ctypeid + (bsz << CTSHIFT_BITCSZ));
+ ct->size = decl.attr;
+ if (decl.name) ctype_setname(ct, decl.name);
+
+ add_field:
+ ctype_get(cp->cts, lastid)->sib = fieldid;
+ lastid = fieldid;
+ }
+ if (!cp_opt(cp, ',')) break;
+ cp_decl_reset(&decl);
+ }
+ cp_check(cp, ';');
+ }
+ cp_check(cp, '}');
+ ctype_get(cp->cts, lastid)->sib = 0; /* Drop sib = 1 for empty structs. */
+ cp_decl_attributes(cp, sdecl); /* Layout phase needs postfix attributes. */
+ cp_struct_layout(cp, sid, sdecl->attr);
+ }
+ return sid;
+}
+
+/* Parse enum declaration. */
+static CTypeID cp_decl_enum(CPState *cp, CPDecl *sdecl)
+{
+ CTypeID eid = cp_struct_name(cp, sdecl, CTINFO(CT_ENUM, CTID_VOID));
+ CTInfo einfo = CTINFO(CT_ENUM, CTALIGN(2) + CTID_UINT32);
+ CTSize esize = 4; /* Only 32 bit enums are supported. */
+ if (cp_opt(cp, '{')) { /* Enum definition. */
+ CPValue k;
+ CTypeID lastid = eid;
+ k.u32 = 0;
+ k.id = CTID_INT32;
+ do {
+ GCstr *name = cp->str;
+ if (cp->tok != CTOK_IDENT) cp_err_token(cp, CTOK_IDENT);
+ if (cp->val.id) cp_errmsg(cp, 0, LJ_ERR_FFI_REDEF, strdata(name));
+ cp_next(cp);
+ if (cp_opt(cp, '=')) {
+ cp_expr_kint(cp, &k);
+ if (k.id == CTID_UINT32) {
+ /* C99 says that enum constants are always (signed) integers.
+ ** But since unsigned constants like 0x80000000 are quite common,
+ ** those are left as uint32_t.
+ */
+ if (k.i32 >= 0) k.id = CTID_INT32;
+ } else {
+ /* OTOH it's common practice and even mandated by some ABIs
+ ** that the enum type itself is unsigned, unless there are any
+ ** negative constants.
+ */
+ k.id = CTID_INT32;
+ if (k.i32 < 0) einfo = CTINFO(CT_ENUM, CTALIGN(2) + CTID_INT32);
+ }
+ }
+ /* Add named enum constant. */
+ {
+ CType *ct;
+ CTypeID constid = lj_ctype_new(cp->cts, &ct);
+ ctype_get(cp->cts, lastid)->sib = constid;
+ lastid = constid;
+ ctype_setname(ct, name);
+ ct->info = CTINFO(CT_CONSTVAL, CTF_CONST|k.id);
+ ct->size = k.u32++;
+ if (k.u32 == 0x80000000u) k.id = CTID_UINT32;
+ lj_ctype_addname(cp->cts, ct, constid);
+ }
+ if (!cp_opt(cp, ',')) break;
+ } while (cp->tok != '}'); /* Trailing ',' is ok. */
+ cp_check(cp, '}');
+ /* Complete enum. */
+ ctype_get(cp->cts, eid)->info = einfo;
+ ctype_get(cp->cts, eid)->size = esize;
+ }
+ return eid;
+}
+
+/* Parse declaration specifiers. */
+static CPscl cp_decl_spec(CPState *cp, CPDecl *decl, CPscl scl)
+{
+ uint32_t cds = 0, sz = 0;
+ CTypeID tdef = 0;
+
+ decl->cp = cp;
+ decl->mode = cp->mode;
+ decl->name = NULL;
+ decl->redir = NULL;
+ decl->attr = 0;
+ decl->fattr = 0;
+ decl->pos = decl->top = 0;
+ decl->stack[0].next = 0;
+
+ for (;;) { /* Parse basic types. */
+ cp_decl_attributes(cp, decl);
+ if (cp->tok >= CTOK_FIRSTDECL && cp->tok <= CTOK_LASTDECLFLAG) {
+ uint32_t cbit;
+ if (cp->ct->size) {
+ if (sz) goto end_decl;
+ sz = cp->ct->size;
+ }
+ cbit = (1u << (cp->tok - CTOK_FIRSTDECL));
+ cds = cds | cbit | ((cbit & cds & CDF_LONG) << 1);
+ if (cp->tok >= CTOK_FIRSTSCL) {
+ if (!(scl & cbit)) cp_errmsg(cp, cp->tok, LJ_ERR_FFI_BADSCL);
+ } else if (tdef) {
+ goto end_decl;
+ }
+ cp_next(cp);
+ continue;
+ }
+ if (sz || tdef ||
+ (cds & (CDF_SHORT|CDF_LONG|CDF_SIGNED|CDF_UNSIGNED|CDF_COMPLEX)))
+ break;
+ switch (cp->tok) {
+ case CTOK_STRUCT:
+ tdef = cp_decl_struct(cp, decl, CTINFO(CT_STRUCT, 0));
+ continue;
+ case CTOK_UNION:
+ tdef = cp_decl_struct(cp, decl, CTINFO(CT_STRUCT, CTF_UNION));
+ continue;
+ case CTOK_ENUM:
+ tdef = cp_decl_enum(cp, decl);
+ continue;
+ case CTOK_IDENT:
+ if (ctype_istypedef(cp->ct->info)) {
+ tdef = ctype_cid(cp->ct->info); /* Get typedef. */
+ cp_next(cp);
+ continue;
+ }
+ break;
+ case '$':
+ tdef = cp->val.id;
+ cp_next(cp);
+ continue;
+ default:
+ break;
+ }
+ break;
+ }
+end_decl:
+
+ if ((cds & CDF_COMPLEX)) /* Use predefined complex types. */
+ tdef = sz == 4 ? CTID_COMPLEX_FLOAT : CTID_COMPLEX_DOUBLE;
+
+ if (tdef) {
+ cp_push_type(decl, tdef);
+ } else if ((cds & CDF_VOID)) {
+ cp_push(decl, CTINFO(CT_VOID, (decl->attr & CTF_QUAL)), CTSIZE_INVALID);
+ decl->attr &= ~CTF_QUAL;
+ } else {
+ /* Determine type info and size. */
+ CTInfo info = CTINFO(CT_NUM, (cds & CDF_UNSIGNED) ? CTF_UNSIGNED : 0);
+ if ((cds & CDF_BOOL)) {
+ if ((cds & ~(CDF_SCL|CDF_BOOL|CDF_INT|CDF_SIGNED|CDF_UNSIGNED)))
+ cp_errmsg(cp, 0, LJ_ERR_FFI_INVTYPE);
+ info |= CTF_BOOL;
+ if (!(cds & CDF_SIGNED)) info |= CTF_UNSIGNED;
+ if (!sz) {
+ sz = 1;
+ }
+ } else if ((cds & CDF_FP)) {
+ info = CTINFO(CT_NUM, CTF_FP);
+ if ((cds & CDF_LONG)) sz = sizeof(long double);
+ } else if ((cds & CDF_CHAR)) {
+ if ((cds & (CDF_CHAR|CDF_SIGNED|CDF_UNSIGNED)) == CDF_CHAR)
+ info |= CTF_UCHAR; /* Handle platforms where char is unsigned. */
+ } else if ((cds & CDF_SHORT)) {
+ sz = sizeof(short);
+ } else if ((cds & CDF_LONGLONG)) {
+ sz = 8;
+ } else if ((cds & CDF_LONG)) {
+ info |= CTF_LONG;
+ sz = sizeof(long);
+ } else if (!sz) {
+ if (!(cds & (CDF_SIGNED|CDF_UNSIGNED)))
+ cp_errmsg(cp, cp->tok, LJ_ERR_FFI_DECLSPEC);
+ sz = sizeof(int);
+ }
+ lua_assert(sz != 0);
+ info += CTALIGN(lj_fls(sz)); /* Use natural alignment. */
+ info += (decl->attr & CTF_QUAL); /* Merge qualifiers. */
+ cp_push(decl, info, sz);
+ decl->attr &= ~CTF_QUAL;
+ }
+ decl->specpos = decl->pos;
+ decl->specattr = decl->attr;
+ decl->specfattr = decl->fattr;
+ return (cds & CDF_SCL); /* Return storage class. */
+}
+
+/* Parse array declaration. */
+static void cp_decl_array(CPState *cp, CPDecl *decl)
+{
+ CTInfo info = CTINFO(CT_ARRAY, 0);
+ CTSize nelem = CTSIZE_INVALID; /* Default size for a[] or a[?]. */
+ cp_decl_attributes(cp, decl);
+ if (cp_opt(cp, '?'))
+ info |= CTF_VLA; /* Create variable-length array a[?]. */
+ else if (cp->tok != ']')
+ nelem = cp_expr_ksize(cp);
+ cp_check(cp, ']');
+ cp_add(decl, info, nelem);
+}
+
+/* Parse function declaration. */
+static void cp_decl_func(CPState *cp, CPDecl *fdecl)
+{
+ CTSize nargs = 0;
+ CTInfo info = CTINFO(CT_FUNC, 0);
+ CTypeID lastid = 0, anchor = 0;
+ if (cp->tok != ')') {
+ do {
+ CPDecl decl;
+ CTypeID ctypeid, fieldid;
+ CType *ct;
+ if (cp_opt(cp, '.')) { /* Vararg function. */
+ cp_check(cp, '.'); /* Workaround for the minimalistic lexer. */
+ cp_check(cp, '.');
+ info |= CTF_VARARG;
+ break;
+ }
+ cp_decl_spec(cp, &decl, CDF_REGISTER);
+ decl.mode = CPARSE_MODE_DIRECT|CPARSE_MODE_ABSTRACT;
+ cp_declarator(cp, &decl);
+ ctypeid = cp_decl_intern(cp, &decl);
+ ct = ctype_raw(cp->cts, ctypeid);
+ if (ctype_isvoid(ct->info))
+ break;
+ else if (ctype_isrefarray(ct->info))
+ ctypeid = lj_ctype_intern(cp->cts,
+ CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(ct->info)), CTSIZE_PTR);
+ else if (ctype_isfunc(ct->info))
+ ctypeid = lj_ctype_intern(cp->cts,
+ CTINFO(CT_PTR, CTALIGN_PTR|ctypeid), CTSIZE_PTR);
+ /* Add new parameter. */
+ fieldid = lj_ctype_new(cp->cts, &ct);
+ if (anchor)
+ ctype_get(cp->cts, lastid)->sib = fieldid;
+ else
+ anchor = fieldid;
+ lastid = fieldid;
+ if (decl.name) ctype_setname(ct, decl.name);
+ ct->info = CTINFO(CT_FIELD, ctypeid);
+ ct->size = nargs++;
+ } while (cp_opt(cp, ','));
+ }
+ cp_check(cp, ')');
+ if (cp_opt(cp, '{')) { /* Skip function definition. */
+ int level = 1;
+ cp->mode |= CPARSE_MODE_SKIP;
+ for (;;) {
+ if (cp->tok == '{') level++;
+ else if (cp->tok == '}' && --level == 0) break;
+ else if (cp->tok == CTOK_EOF) cp_err_token(cp, '}');
+ cp_next(cp);
+ }
+ cp->mode &= ~CPARSE_MODE_SKIP;
+ cp->tok = ';'; /* Ok for cp_decl_multi(), error in cp_decl_single(). */
+ }
+ info |= (fdecl->fattr & ~CTMASK_CID);
+ fdecl->fattr = 0;
+ fdecl->stack[cp_add(fdecl, info, nargs)].sib = anchor;
+}
+
+/* Parse declarator. */
+static void cp_declarator(CPState *cp, CPDecl *decl)
+{
+ if (++cp->depth > CPARSE_MAX_DECLDEPTH) cp_err(cp, LJ_ERR_XLEVELS);
+
+ for (;;) { /* Head of declarator. */
+ if (cp_opt(cp, '*')) { /* Pointer. */
+ CTSize sz;
+ CTInfo info;
+ cp_decl_attributes(cp, decl);
+ sz = CTSIZE_PTR;
+ info = CTINFO(CT_PTR, CTALIGN_PTR);
+#if LJ_64
+ if (ctype_msizeP(decl->attr) == 4) {
+ sz = 4;
+ info = CTINFO(CT_PTR, CTALIGN(2));
+ }
+#endif
+ info += (decl->attr & (CTF_QUAL|CTF_REF));
+ decl->attr &= ~(CTF_QUAL|(CTMASK_MSIZEP<<CTSHIFT_MSIZEP));
+ cp_push(decl, info, sz);
+ } else if (cp_opt(cp, '&') || cp_opt(cp, CTOK_ANDAND)) { /* Reference. */
+ decl->attr &= ~(CTF_QUAL|(CTMASK_MSIZEP<<CTSHIFT_MSIZEP));
+ cp_push(decl, CTINFO_REF(0), CTSIZE_PTR);
+ } else {
+ break;
+ }
+ }
+
+ if (cp_opt(cp, '(')) { /* Inner declarator. */
+ CPDeclIdx pos;
+ cp_decl_attributes(cp, decl);
+ /* Resolve ambiguity between inner declarator and 1st function parameter. */
+ if ((decl->mode & CPARSE_MODE_ABSTRACT) &&
+ (cp->tok == ')' || cp_istypedecl(cp))) goto func_decl;
+ pos = decl->pos;
+ cp_declarator(cp, decl);
+ cp_check(cp, ')');
+ decl->pos = pos;
+ } else if (cp->tok == CTOK_IDENT) { /* Direct declarator. */
+ if (!(decl->mode & CPARSE_MODE_DIRECT)) cp_err_token(cp, CTOK_EOF);
+ decl->name = cp->str;
+ decl->nameid = cp->val.id;
+ cp_next(cp);
+ } else { /* Abstract declarator. */
+ if (!(decl->mode & CPARSE_MODE_ABSTRACT)) cp_err_token(cp, CTOK_IDENT);
+ }
+
+ for (;;) { /* Tail of declarator. */
+ if (cp_opt(cp, '[')) { /* Array. */
+ cp_decl_array(cp, decl);
+ } else if (cp_opt(cp, '(')) { /* Function. */
+ func_decl:
+ cp_decl_func(cp, decl);
+ } else {
+ break;
+ }
+ }
+
+ if ((decl->mode & CPARSE_MODE_FIELD) && cp_opt(cp, ':')) /* Field width. */
+ decl->bits = cp_expr_ksize(cp);
+
+ /* Process postfix attributes. */
+ cp_decl_attributes(cp, decl);
+ cp_push_attributes(decl);
+
+ cp->depth--;
+}
+
+/* Parse an abstract type declaration and return it's C type ID. */
+static CTypeID cp_decl_abstract(CPState *cp)
+{
+ CPDecl decl;
+ cp_decl_spec(cp, &decl, 0);
+ decl.mode = CPARSE_MODE_ABSTRACT;
+ cp_declarator(cp, &decl);
+ return cp_decl_intern(cp, &decl);
+}
+
+/* Handle pragmas. */
+static void cp_pragma(CPState *cp, BCLine pragmaline)
+{
+ cp_next(cp);
+ if (cp->tok == CTOK_IDENT &&
+ cp->str->hash == H_(e79b999f,42ca3e85)) { /* pack */
+ cp_next(cp);
+ cp_check(cp, '(');
+ if (cp->tok == CTOK_IDENT) {
+ if (cp->str->hash == H_(738e923c,a1b65954)) { /* push */
+ if (cp->curpack < CPARSE_MAX_PACKSTACK) {
+ cp->packstack[cp->curpack+1] = cp->packstack[cp->curpack];
+ cp->curpack++;
+ }
+ } else if (cp->str->hash == H_(6c71cf27,6c71cf27)) { /* pop */
+ if (cp->curpack > 0) cp->curpack--;
+ } else {
+ cp_errmsg(cp, cp->tok, LJ_ERR_XSYMBOL);
+ }
+ cp_next(cp);
+ if (!cp_opt(cp, ',')) goto end_pack;
+ }
+ if (cp->tok == CTOK_INTEGER) {
+ cp->packstack[cp->curpack] = cp->val.u32 ? lj_fls(cp->val.u32) : 0;
+ cp_next(cp);
+ } else {
+ cp->packstack[cp->curpack] = 255;
+ }
+ end_pack:
+ cp_check(cp, ')');
+ } else { /* Ignore all other pragmas. */
+ while (cp->tok != CTOK_EOF && cp->linenumber == pragmaline)
+ cp_next(cp);
+ }
+}
+
+/* Parse multiple C declarations of types or extern identifiers. */
+static void cp_decl_multi(CPState *cp)
+{
+ int first = 1;
+ while (cp->tok != CTOK_EOF) {
+ CPDecl decl;
+ CPscl scl;
+ if (cp_opt(cp, ';')) { /* Skip empty statements. */
+ first = 0;
+ continue;
+ }
+ if (cp->tok == '#') { /* Workaround, since we have no preprocessor, yet. */
+ BCLine pragmaline = cp->linenumber;
+ if (!(cp_next(cp) == CTOK_IDENT &&
+ cp->str->hash == H_(f5e6b4f8,1d509107))) /* pragma */
+ cp_errmsg(cp, cp->tok, LJ_ERR_XSYMBOL);
+ cp_pragma(cp, pragmaline);
+ continue;
+ }
+ scl = cp_decl_spec(cp, &decl, CDF_TYPEDEF|CDF_EXTERN|CDF_STATIC);
+ if ((cp->tok == ';' || cp->tok == CTOK_EOF) &&
+ ctype_istypedef(decl.stack[0].info)) {
+ CTInfo info = ctype_rawchild(cp->cts, &decl.stack[0])->info;
+ if (ctype_isstruct(info) || ctype_isenum(info))
+ goto decl_end; /* Accept empty declaration of struct/union/enum. */
+ }
+ for (;;) {
+ CTypeID ctypeid;
+ cp_declarator(cp, &decl);
+ ctypeid = cp_decl_intern(cp, &decl);
+ if (decl.name && !decl.nameid) { /* NYI: redeclarations are ignored. */
+ CType *ct;
+ CTypeID id;
+ if ((scl & CDF_TYPEDEF)) { /* Create new typedef. */
+ id = lj_ctype_new(cp->cts, &ct);
+ ct->info = CTINFO(CT_TYPEDEF, ctypeid);
+ goto noredir;
+ } else if (ctype_isfunc(ctype_get(cp->cts, ctypeid)->info)) {
+ /* Treat both static and extern function declarations as extern. */
+ ct = ctype_get(cp->cts, ctypeid);
+ /* We always get new anonymous functions (typedefs are copied). */
+ lua_assert(gcref(ct->name) == NULL);
+ id = ctypeid; /* Just name it. */
+ } else if ((scl & CDF_STATIC)) { /* Accept static constants. */
+ id = cp_decl_constinit(cp, &ct, ctypeid);
+ goto noredir;
+ } else { /* External references have extern or no storage class. */
+ id = lj_ctype_new(cp->cts, &ct);
+ ct->info = CTINFO(CT_EXTERN, ctypeid);
+ }
+ if (decl.redir) { /* Add attribute for redirected symbol name. */
+ CType *cta;
+ CTypeID aid = lj_ctype_new(cp->cts, &cta);
+ ct = ctype_get(cp->cts, id); /* Table may have been reallocated. */
+ cta->info = CTINFO(CT_ATTRIB, CTATTRIB(CTA_REDIR));
+ cta->sib = ct->sib;
+ ct->sib = aid;
+ ctype_setname(cta, decl.redir);
+ }
+ noredir:
+ ctype_setname(ct, decl.name);
+ lj_ctype_addname(cp->cts, ct, id);
+ }
+ if (!cp_opt(cp, ',')) break;
+ cp_decl_reset(&decl);
+ }
+ decl_end:
+ if (cp->tok == CTOK_EOF && first) break; /* May omit ';' for 1 decl. */
+ first = 0;
+ cp_check(cp, ';');
+ }
+}
+
+/* Parse a single C type declaration. */
+static void cp_decl_single(CPState *cp)
+{
+ CPDecl decl;
+ cp_decl_spec(cp, &decl, 0);
+ cp_declarator(cp, &decl);
+ cp->val.id = cp_decl_intern(cp, &decl);
+ if (cp->tok != CTOK_EOF) cp_err_token(cp, CTOK_EOF);
+}
+
+#undef H_
+
+/* ------------------------------------------------------------------------ */
+
+/* Protected callback for C parser. */
+static TValue *cpcparser(lua_State *L, lua_CFunction dummy, void *ud)
+{
+ CPState *cp = (CPState *)ud;
+ UNUSED(dummy);
+ cframe_errfunc(L->cframe) = -1; /* Inherit error function. */
+ cp_init(cp);
+ if ((cp->mode & CPARSE_MODE_MULTI))
+ cp_decl_multi(cp);
+ else
+ cp_decl_single(cp);
+ if (cp->param && cp->param != cp->L->top)
+ cp_err(cp, LJ_ERR_FFI_NUMPARAM);
+ lua_assert(cp->depth == 0);
+ return NULL;
+}
+
+/* C parser. */
+int lj_cparse(CPState *cp)
+{
+ LJ_CTYPE_SAVE(cp->cts);
+ int errcode = lj_vm_cpcall(cp->L, NULL, cp, cpcparser);
+ if (errcode)
+ LJ_CTYPE_RESTORE(cp->cts);
+ cp_cleanup(cp);
+ return errcode;
+}
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_cparse.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_cparse.h
new file mode 100644
index 0000000..bad1060
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_cparse.h
@@ -0,0 +1,65 @@
+/*
+** C declaration parser.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_CPARSE_H
+#define _LJ_CPARSE_H
+
+#include "lj_obj.h"
+#include "lj_ctype.h"
+
+#if LJ_HASFFI
+
+/* C parser limits. */
+#define CPARSE_MAX_BUF 32768 /* Max. token buffer size. */
+#define CPARSE_MAX_DECLSTACK 100 /* Max. declaration stack depth. */
+#define CPARSE_MAX_DECLDEPTH 20 /* Max. recursive declaration depth. */
+#define CPARSE_MAX_PACKSTACK 7 /* Max. pack pragma stack depth. */
+
+/* Flags for C parser mode. */
+#define CPARSE_MODE_MULTI 1 /* Process multiple declarations. */
+#define CPARSE_MODE_ABSTRACT 2 /* Accept abstract declarators. */
+#define CPARSE_MODE_DIRECT 4 /* Accept direct declarators. */
+#define CPARSE_MODE_FIELD 8 /* Accept field width in bits, too. */
+#define CPARSE_MODE_NOIMPLICIT 16 /* Reject implicit declarations. */
+#define CPARSE_MODE_SKIP 32 /* Skip definitions, ignore errors. */
+
+typedef int CPChar; /* C parser character. Unsigned ext. from char. */
+typedef int CPToken; /* C parser token. */
+
+/* C parser internal value representation. */
+typedef struct CPValue {
+ union {
+ int32_t i32; /* Value for CTID_INT32. */
+ uint32_t u32; /* Value for CTID_UINT32. */
+ };
+ CTypeID id; /* C Type ID of the value. */
+} CPValue;
+
+/* C parser state. */
+typedef struct CPState {
+ CPChar c; /* Current character. */
+ CPToken tok; /* Current token. */
+ CPValue val; /* Token value. */
+ GCstr *str; /* Interned string of identifier/keyword. */
+ CType *ct; /* C type table entry. */
+ const char *p; /* Current position in input buffer. */
+ SBuf sb; /* String buffer for tokens. */
+ lua_State *L; /* Lua state. */
+ CTState *cts; /* C type state. */
+ TValue *param; /* C type parameters. */
+ const char *srcname; /* Current source name. */
+ BCLine linenumber; /* Input line counter. */
+ int depth; /* Recursive declaration depth. */
+ uint32_t tmask; /* Type mask for next identifier. */
+ uint32_t mode; /* C parser mode. */
+ uint8_t packstack[CPARSE_MAX_PACKSTACK]; /* Stack for pack pragmas. */
+ uint8_t curpack; /* Current position in pack pragma stack. */
+} CPState;
+
+LJ_FUNC int lj_cparse(CPState *cp);
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_crecord.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_crecord.c
new file mode 100644
index 0000000..bc88d63
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_crecord.c
@@ -0,0 +1,1674 @@
+/*
+** Trace recorder for C data operations.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_ffrecord_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT && LJ_HASFFI
+
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_frame.h"
+#include "lj_ctype.h"
+#include "lj_cdata.h"
+#include "lj_cparse.h"
+#include "lj_cconv.h"
+#include "lj_clib.h"
+#include "lj_ccall.h"
+#include "lj_ff.h"
+#include "lj_ir.h"
+#include "lj_jit.h"
+#include "lj_ircall.h"
+#include "lj_iropt.h"
+#include "lj_trace.h"
+#include "lj_record.h"
+#include "lj_ffrecord.h"
+#include "lj_snap.h"
+#include "lj_crecord.h"
+#include "lj_dispatch.h"
+
+/* Some local macros to save typing. Undef'd at the end. */
+#define IR(ref) (&J->cur.ir[(ref)])
+
+/* Pass IR on to next optimization in chain (FOLD). */
+#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))
+
+#define emitconv(a, dt, st, flags) \
+ emitir(IRT(IR_CONV, (dt)), (a), (st)|((dt) << 5)|(flags))
+
+/* -- C type checks ------------------------------------------------------- */
+
+static GCcdata *argv2cdata(jit_State *J, TRef tr, cTValue *o)
+{
+ GCcdata *cd;
+ TRef trtypeid;
+ if (!tref_iscdata(tr))
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ cd = cdataV(o);
+ /* Specialize to the CTypeID. */
+ trtypeid = emitir(IRT(IR_FLOAD, IRT_U16), tr, IRFL_CDATA_CTYPEID);
+ emitir(IRTG(IR_EQ, IRT_INT), trtypeid, lj_ir_kint(J, (int32_t)cd->ctypeid));
+ return cd;
+}
+
+/* Specialize to the CTypeID held by a cdata constructor. */
+static CTypeID crec_constructor(jit_State *J, GCcdata *cd, TRef tr)
+{
+ CTypeID id;
+ lua_assert(tref_iscdata(tr) && cd->ctypeid == CTID_CTYPEID);
+ id = *(CTypeID *)cdataptr(cd);
+ tr = emitir(IRT(IR_FLOAD, IRT_INT), tr, IRFL_CDATA_INT);
+ emitir(IRTG(IR_EQ, IRT_INT), tr, lj_ir_kint(J, (int32_t)id));
+ return id;
+}
+
+static CTypeID argv2ctype(jit_State *J, TRef tr, cTValue *o)
+{
+ if (tref_isstr(tr)) {
+ GCstr *s = strV(o);
+ CPState cp;
+ CTypeID oldtop;
+ /* Specialize to the string containing the C type declaration. */
+ emitir(IRTG(IR_EQ, IRT_STR), tr, lj_ir_kstr(J, s));
+ cp.L = J->L;
+ cp.cts = ctype_ctsG(J2G(J));
+ oldtop = cp.cts->top;
+ cp.srcname = strdata(s);
+ cp.p = strdata(s);
+ cp.param = NULL;
+ cp.mode = CPARSE_MODE_ABSTRACT|CPARSE_MODE_NOIMPLICIT;
+ if (lj_cparse(&cp) || cp.cts->top > oldtop) /* Avoid new struct defs. */
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ return cp.val.id;
+ } else {
+ GCcdata *cd = argv2cdata(J, tr, o);
+ return cd->ctypeid == CTID_CTYPEID ? crec_constructor(J, cd, tr) :
+ cd->ctypeid;
+ }
+}
+
+/* Convert CType to IRType (if possible). */
+static IRType crec_ct2irt(CTState *cts, CType *ct)
+{
+ if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);
+ if (LJ_LIKELY(ctype_isnum(ct->info))) {
+ if ((ct->info & CTF_FP)) {
+ if (ct->size == sizeof(double))
+ return IRT_NUM;
+ else if (ct->size == sizeof(float))
+ return IRT_FLOAT;
+ } else {
+ uint32_t b = lj_fls(ct->size);
+ if (b <= 3)
+ return IRT_I8 + 2*b + ((ct->info & CTF_UNSIGNED) ? 1 : 0);
+ }
+ } else if (ctype_isptr(ct->info)) {
+ return (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32;
+ } else if (ctype_iscomplex(ct->info)) {
+ if (ct->size == 2*sizeof(double))
+ return IRT_NUM;
+ else if (ct->size == 2*sizeof(float))
+ return IRT_FLOAT;
+ }
+ return IRT_CDATA;
+}
+
+/* -- Optimized memory fill and copy -------------------------------------- */
+
+/* Maximum length and unroll of inlined copy/fill. */
+#define CREC_COPY_MAXUNROLL 16
+#define CREC_COPY_MAXLEN 128
+
+#define CREC_FILL_MAXUNROLL 16
+
+/* Number of windowed registers used for optimized memory copy. */
+#if LJ_TARGET_X86
+#define CREC_COPY_REGWIN 2
+#elif LJ_TARGET_PPC || LJ_TARGET_MIPS
+#define CREC_COPY_REGWIN 8
+#else
+#define CREC_COPY_REGWIN 4
+#endif
+
+/* List of memory offsets for copy/fill. */
+typedef struct CRecMemList {
+ CTSize ofs; /* Offset in bytes. */
+ IRType tp; /* Type of load/store. */
+ TRef trofs; /* TRef of interned offset. */
+ TRef trval; /* TRef of load value. */
+} CRecMemList;
+
+/* Generate copy list for element-wise struct copy. */
+static MSize crec_copy_struct(CRecMemList *ml, CTState *cts, CType *ct)
+{
+ CTypeID fid = ct->sib;
+ MSize mlp = 0;
+ while (fid) {
+ CType *df = ctype_get(cts, fid);
+ fid = df->sib;
+ if (ctype_isfield(df->info)) {
+ CType *cct;
+ IRType tp;
+ if (!gcref(df->name)) continue; /* Ignore unnamed fields. */
+ cct = ctype_rawchild(cts, df); /* Field type. */
+ tp = crec_ct2irt(cts, cct);
+ if (tp == IRT_CDATA) return 0; /* NYI: aggregates. */
+ if (mlp >= CREC_COPY_MAXUNROLL) return 0;
+ ml[mlp].ofs = df->size;
+ ml[mlp].tp = tp;
+ mlp++;
+ if (ctype_iscomplex(cct->info)) {
+ if (mlp >= CREC_COPY_MAXUNROLL) return 0;
+ ml[mlp].ofs = df->size + (cct->size >> 1);
+ ml[mlp].tp = tp;
+ mlp++;
+ }
+ } else if (!ctype_isconstval(df->info)) {
+ /* NYI: bitfields and sub-structures. */
+ return 0;
+ }
+ }
+ return mlp;
+}
+
+/* Generate unrolled copy list, from highest to lowest step size/alignment. */
+static MSize crec_copy_unroll(CRecMemList *ml, CTSize len, CTSize step,
+ IRType tp)
+{
+ CTSize ofs = 0;
+ MSize mlp = 0;
+ if (tp == IRT_CDATA) tp = IRT_U8 + 2*lj_fls(step);
+ do {
+ while (ofs + step <= len) {
+ if (mlp >= CREC_COPY_MAXUNROLL) return 0;
+ ml[mlp].ofs = ofs;
+ ml[mlp].tp = tp;
+ mlp++;
+ ofs += step;
+ }
+ step >>= 1;
+ tp -= 2;
+ } while (ofs < len);
+ return mlp;
+}
+
+/*
+** Emit copy list with windowed loads/stores.
+** LJ_TARGET_UNALIGNED: may emit unaligned loads/stores (not marked as such).
+*/
+static void crec_copy_emit(jit_State *J, CRecMemList *ml, MSize mlp,
+ TRef trdst, TRef trsrc)
+{
+ MSize i, j, rwin = 0;
+ for (i = 0, j = 0; i < mlp; ) {
+ TRef trofs = lj_ir_kintp(J, ml[i].ofs);
+ TRef trsptr = emitir(IRT(IR_ADD, IRT_PTR), trsrc, trofs);
+ ml[i].trval = emitir(IRT(IR_XLOAD, ml[i].tp), trsptr, 0);
+ ml[i].trofs = trofs;
+ i++;
+ rwin += (LJ_SOFTFP && ml[i].tp == IRT_NUM) ? 2 : 1;
+ if (rwin >= CREC_COPY_REGWIN || i >= mlp) { /* Flush buffered stores. */
+ rwin = 0;
+ for ( ; j < i; j++) {
+ TRef trdptr = emitir(IRT(IR_ADD, IRT_PTR), trdst, ml[j].trofs);
+ emitir(IRT(IR_XSTORE, ml[j].tp), trdptr, ml[j].trval);
+ }
+ }
+ }
+}
+
+/* Optimized memory copy. */
+static void crec_copy(jit_State *J, TRef trdst, TRef trsrc, TRef trlen,
+ CType *ct)
+{
+ if (tref_isk(trlen)) { /* Length must be constant. */
+ CRecMemList ml[CREC_COPY_MAXUNROLL];
+ MSize mlp = 0;
+ CTSize step = 1, len = (CTSize)IR(tref_ref(trlen))->i;
+ IRType tp = IRT_CDATA;
+ int needxbar = 0;
+ if (len == 0) return; /* Shortcut. */
+ if (len > CREC_COPY_MAXLEN) goto fallback;
+ if (ct) {
+ CTState *cts = ctype_ctsG(J2G(J));
+ lua_assert(ctype_isarray(ct->info) || ctype_isstruct(ct->info));
+ if (ctype_isarray(ct->info)) {
+ CType *cct = ctype_rawchild(cts, ct);
+ tp = crec_ct2irt(cts, cct);
+ if (tp == IRT_CDATA) goto rawcopy;
+ step = lj_ir_type_size[tp];
+ lua_assert((len & (step-1)) == 0);
+ } else if ((ct->info & CTF_UNION)) {
+ step = (1u << ctype_align(ct->info));
+ goto rawcopy;
+ } else {
+ mlp = crec_copy_struct(ml, cts, ct);
+ goto emitcopy;
+ }
+ } else {
+ rawcopy:
+ needxbar = 1;
+ if (LJ_TARGET_UNALIGNED || step >= CTSIZE_PTR)
+ step = CTSIZE_PTR;
+ }
+ mlp = crec_copy_unroll(ml, len, step, tp);
+ emitcopy:
+ if (mlp) {
+ crec_copy_emit(J, ml, mlp, trdst, trsrc);
+ if (needxbar)
+ emitir(IRT(IR_XBAR, IRT_NIL), 0, 0);
+ return;
+ }
+ }
+fallback:
+ /* Call memcpy. Always needs a barrier to disable alias analysis. */
+ lj_ir_call(J, IRCALL_memcpy, trdst, trsrc, trlen);
+ emitir(IRT(IR_XBAR, IRT_NIL), 0, 0);
+}
+
+/* Generate unrolled fill list, from highest to lowest step size/alignment. */
+static MSize crec_fill_unroll(CRecMemList *ml, CTSize len, CTSize step)
+{
+ CTSize ofs = 0;
+ MSize mlp = 0;
+ IRType tp = IRT_U8 + 2*lj_fls(step);
+ do {
+ while (ofs + step <= len) {
+ if (mlp >= CREC_COPY_MAXUNROLL) return 0;
+ ml[mlp].ofs = ofs;
+ ml[mlp].tp = tp;
+ mlp++;
+ ofs += step;
+ }
+ step >>= 1;
+ tp -= 2;
+ } while (ofs < len);
+ return mlp;
+}
+
+/*
+** Emit stores for fill list.
+** LJ_TARGET_UNALIGNED: may emit unaligned stores (not marked as such).
+*/
+static void crec_fill_emit(jit_State *J, CRecMemList *ml, MSize mlp,
+ TRef trdst, TRef trfill)
+{
+ MSize i;
+ for (i = 0; i < mlp; i++) {
+ TRef trofs = lj_ir_kintp(J, ml[i].ofs);
+ TRef trdptr = emitir(IRT(IR_ADD, IRT_PTR), trdst, trofs);
+ emitir(IRT(IR_XSTORE, ml[i].tp), trdptr, trfill);
+ }
+}
+
+/* Optimized memory fill. */
+static void crec_fill(jit_State *J, TRef trdst, TRef trlen, TRef trfill,
+ CTSize step)
+{
+ if (tref_isk(trlen)) { /* Length must be constant. */
+ CRecMemList ml[CREC_FILL_MAXUNROLL];
+ MSize mlp;
+ CTSize len = (CTSize)IR(tref_ref(trlen))->i;
+ if (len == 0) return; /* Shortcut. */
+ if (LJ_TARGET_UNALIGNED || step >= CTSIZE_PTR)
+ step = CTSIZE_PTR;
+ if (step * CREC_FILL_MAXUNROLL < len) goto fallback;
+ mlp = crec_fill_unroll(ml, len, step);
+ if (!mlp) goto fallback;
+ if (tref_isk(trfill) || ml[0].tp != IRT_U8)
+ trfill = emitconv(trfill, IRT_INT, IRT_U8, 0);
+ if (ml[0].tp != IRT_U8) { /* Scatter U8 to U16/U32/U64. */
+ if (CTSIZE_PTR == 8 && ml[0].tp == IRT_U64) {
+ if (tref_isk(trfill)) /* Pointless on x64 with zero-extended regs. */
+ trfill = emitconv(trfill, IRT_U64, IRT_U32, 0);
+ trfill = emitir(IRT(IR_MUL, IRT_U64), trfill,
+ lj_ir_kint64(J, U64x(01010101,01010101)));
+ } else {
+ trfill = emitir(IRTI(IR_MUL), trfill,
+ lj_ir_kint(J, ml[0].tp == IRT_U16 ? 0x0101 : 0x01010101));
+ }
+ }
+ crec_fill_emit(J, ml, mlp, trdst, trfill);
+ } else {
+fallback:
+ /* Call memset. Always needs a barrier to disable alias analysis. */
+ lj_ir_call(J, IRCALL_memset, trdst, trfill, trlen); /* Note: arg order! */
+ }
+ emitir(IRT(IR_XBAR, IRT_NIL), 0, 0);
+}
+
+/* -- Convert C type to C type -------------------------------------------- */
+
+/*
+** This code mirrors the code in lj_cconv.c. It performs the same steps
+** for the trace recorder that lj_cconv.c does for the interpreter.
+**
+** One major difference is that we can get away with much fewer checks
+** here. E.g. checks for casts, constness or correct types can often be
+** omitted, even if they might fail. The interpreter subsequently throws
+** an error, which aborts the trace.
+**
+** All operations are specialized to their C types, so the on-trace
+** outcome must be the same as the outcome in the interpreter. If the
+** interpreter doesn't throw an error, then the trace is correct, too.
+** Care must be taken not to generate invalid (temporary) IR or to
+** trigger asserts.
+*/
+
+/* Determine whether a passed number or cdata number is non-zero. */
+static int crec_isnonzero(CType *s, void *p)
+{
+ if (p == (void *)0)
+ return 0;
+ if (p == (void *)1)
+ return 1;
+ if ((s->info & CTF_FP)) {
+ if (s->size == sizeof(float))
+ return (*(float *)p != 0);
+ else
+ return (*(double *)p != 0);
+ } else {
+ if (s->size == 1)
+ return (*(uint8_t *)p != 0);
+ else if (s->size == 2)
+ return (*(uint16_t *)p != 0);
+ else if (s->size == 4)
+ return (*(uint32_t *)p != 0);
+ else
+ return (*(uint64_t *)p != 0);
+ }
+}
+
+static TRef crec_ct_ct(jit_State *J, CType *d, CType *s, TRef dp, TRef sp,
+ void *svisnz)
+{
+ IRType dt = crec_ct2irt(ctype_ctsG(J2G(J)), d);
+ IRType st = crec_ct2irt(ctype_ctsG(J2G(J)), s);
+ CTSize dsize = d->size, ssize = s->size;
+ CTInfo dinfo = d->info, sinfo = s->info;
+
+ if (ctype_type(dinfo) > CT_MAYCONVERT || ctype_type(sinfo) > CT_MAYCONVERT)
+ goto err_conv;
+
+ /*
+ ** Note: Unlike lj_cconv_ct_ct(), sp holds the _value_ of pointers and
+ ** numbers up to 8 bytes. Otherwise sp holds a pointer.
+ */
+
+ switch (cconv_idx2(dinfo, sinfo)) {
+ /* Destination is a bool. */
+ case CCX(B, B):
+ goto xstore; /* Source operand is already normalized. */
+ case CCX(B, I):
+ case CCX(B, F):
+ if (st != IRT_CDATA) {
+ /* Specialize to the result of a comparison against 0. */
+ TRef zero = (st == IRT_NUM || st == IRT_FLOAT) ? lj_ir_knum(J, 0) :
+ (st == IRT_I64 || st == IRT_U64) ? lj_ir_kint64(J, 0) :
+ lj_ir_kint(J, 0);
+ int isnz = crec_isnonzero(s, svisnz);
+ emitir(IRTG(isnz ? IR_NE : IR_EQ, st), sp, zero);
+ sp = lj_ir_kint(J, isnz);
+ goto xstore;
+ }
+ goto err_nyi;
+
+ /* Destination is an integer. */
+ case CCX(I, B):
+ case CCX(I, I):
+ conv_I_I:
+ if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi;
+ /* Extend 32 to 64 bit integer. */
+ if (dsize == 8 && ssize < 8 && !(LJ_64 && (sinfo & CTF_UNSIGNED)))
+ sp = emitconv(sp, dt, ssize < 4 ? IRT_INT : st,
+ (sinfo & CTF_UNSIGNED) ? 0 : IRCONV_SEXT);
+ else if (dsize < 8 && ssize == 8) /* Truncate from 64 bit integer. */
+ sp = emitconv(sp, dsize < 4 ? IRT_INT : dt, st, 0);
+ else if (st == IRT_INT)
+ sp = lj_opt_narrow_toint(J, sp);
+ xstore:
+ if (dt == IRT_I64 || dt == IRT_U64) lj_needsplit(J);
+ if (dp == 0) return sp;
+ emitir(IRT(IR_XSTORE, dt), dp, sp);
+ break;
+ case CCX(I, C):
+ sp = emitir(IRT(IR_XLOAD, st), sp, 0); /* Load re. */
+ /* fallthrough */
+ case CCX(I, F):
+ if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi;
+ sp = emitconv(sp, dsize < 4 ? IRT_INT : dt, st, IRCONV_TRUNC|IRCONV_ANY);
+ goto xstore;
+ case CCX(I, P):
+ case CCX(I, A):
+ sinfo = CTINFO(CT_NUM, CTF_UNSIGNED);
+ ssize = CTSIZE_PTR;
+ st = IRT_UINTP;
+ if (((dsize ^ ssize) & 8) == 0) { /* Must insert no-op type conversion. */
+ sp = emitconv(sp, dsize < 4 ? IRT_INT : dt, IRT_PTR, 0);
+ goto xstore;
+ }
+ goto conv_I_I;
+
+ /* Destination is a floating-point number. */
+ case CCX(F, B):
+ case CCX(F, I):
+ conv_F_I:
+ if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi;
+ sp = emitconv(sp, dt, ssize < 4 ? IRT_INT : st, 0);
+ goto xstore;
+ case CCX(F, C):
+ sp = emitir(IRT(IR_XLOAD, st), sp, 0); /* Load re. */
+ /* fallthrough */
+ case CCX(F, F):
+ conv_F_F:
+ if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi;
+ if (dt != st) sp = emitconv(sp, dt, st, 0);
+ goto xstore;
+
+ /* Destination is a complex number. */
+ case CCX(C, I):
+ case CCX(C, F):
+ { /* Clear im. */
+ TRef ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, (dsize >> 1)));
+ emitir(IRT(IR_XSTORE, dt), ptr, lj_ir_knum(J, 0));
+ }
+ /* Convert to re. */
+ if ((sinfo & CTF_FP)) goto conv_F_F; else goto conv_F_I;
+
+ case CCX(C, C):
+ if (dt == IRT_CDATA || st == IRT_CDATA) goto err_nyi;
+ {
+ TRef re, im, ptr;
+ re = emitir(IRT(IR_XLOAD, st), sp, 0);
+ ptr = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, (ssize >> 1)));
+ im = emitir(IRT(IR_XLOAD, st), ptr, 0);
+ if (dt != st) {
+ re = emitconv(re, dt, st, 0);
+ im = emitconv(im, dt, st, 0);
+ }
+ emitir(IRT(IR_XSTORE, dt), dp, re);
+ ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, (dsize >> 1)));
+ emitir(IRT(IR_XSTORE, dt), ptr, im);
+ }
+ break;
+
+ /* Destination is a vector. */
+ case CCX(V, I):
+ case CCX(V, F):
+ case CCX(V, C):
+ case CCX(V, V):
+ goto err_nyi;
+
+ /* Destination is a pointer. */
+ case CCX(P, P):
+ case CCX(P, A):
+ case CCX(P, S):
+ /* There are only 32 bit pointers/addresses on 32 bit machines.
+ ** Also ok on x64, since all 32 bit ops clear the upper part of the reg.
+ */
+ goto xstore;
+ case CCX(P, I):
+ if (st == IRT_CDATA) goto err_nyi;
+ if (!LJ_64 && ssize == 8) /* Truncate from 64 bit integer. */
+ sp = emitconv(sp, IRT_U32, st, 0);
+ goto xstore;
+ case CCX(P, F):
+ if (st == IRT_CDATA) goto err_nyi;
+ /* The signed conversion is cheaper. x64 really has 47 bit pointers. */
+ sp = emitconv(sp, (LJ_64 && dsize == 8) ? IRT_I64 : IRT_U32,
+ st, IRCONV_TRUNC|IRCONV_ANY);
+ goto xstore;
+
+ /* Destination is an array. */
+ case CCX(A, A):
+ /* Destination is a struct/union. */
+ case CCX(S, S):
+ if (dp == 0) goto err_conv;
+ crec_copy(J, dp, sp, lj_ir_kint(J, dsize), d);
+ break;
+
+ default:
+ err_conv:
+ err_nyi:
+ lj_trace_err(J, LJ_TRERR_NYICONV);
+ break;
+ }
+ return 0;
+}
+
+/* -- Convert C type to TValue (load) ------------------------------------- */
+
+static TRef crec_tv_ct(jit_State *J, CType *s, CTypeID sid, TRef sp)
+{
+ CTState *cts = ctype_ctsG(J2G(J));
+ IRType t = crec_ct2irt(cts, s);
+ CTInfo sinfo = s->info;
+ if (ctype_isnum(sinfo)) {
+ TRef tr;
+ if (t == IRT_CDATA)
+ goto err_nyi; /* NYI: copyval of >64 bit integers. */
+ tr = emitir(IRT(IR_XLOAD, t), sp, 0);
+ if (t == IRT_FLOAT || t == IRT_U32) { /* Keep uint32_t/float as numbers. */
+ return emitconv(tr, IRT_NUM, t, 0);
+ } else if (t == IRT_I64 || t == IRT_U64) { /* Box 64 bit integer. */
+ sp = tr;
+ lj_needsplit(J);
+ } else if ((sinfo & CTF_BOOL)) {
+ /* Assume not equal to zero. Fixup and emit pending guard later. */
+ lj_ir_set(J, IRTGI(IR_NE), tr, lj_ir_kint(J, 0));
+ J->postproc = LJ_POST_FIXGUARD;
+ return TREF_TRUE;
+ } else {
+ return tr;
+ }
+ } else if (ctype_isptr(sinfo) || ctype_isenum(sinfo)) {
+ sp = emitir(IRT(IR_XLOAD, t), sp, 0); /* Box pointers and enums. */
+ } else if (ctype_isrefarray(sinfo) || ctype_isstruct(sinfo)) {
+ cts->L = J->L;
+ sid = lj_ctype_intern(cts, CTINFO_REF(sid), CTSIZE_PTR); /* Create ref. */
+ } else if (ctype_iscomplex(sinfo)) { /* Unbox/box complex. */
+ ptrdiff_t esz = (ptrdiff_t)(s->size >> 1);
+ TRef ptr, tr1, tr2, dp;
+ dp = emitir(IRTG(IR_CNEW, IRT_CDATA), lj_ir_kint(J, sid), TREF_NIL);
+ tr1 = emitir(IRT(IR_XLOAD, t), sp, 0);
+ ptr = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, esz));
+ tr2 = emitir(IRT(IR_XLOAD, t), ptr, 0);
+ ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, sizeof(GCcdata)));
+ emitir(IRT(IR_XSTORE, t), ptr, tr1);
+ ptr = emitir(IRT(IR_ADD, IRT_PTR), dp, lj_ir_kintp(J, sizeof(GCcdata)+esz));
+ emitir(IRT(IR_XSTORE, t), ptr, tr2);
+ return dp;
+ } else {
+ /* NYI: copyval of vectors. */
+ err_nyi:
+ lj_trace_err(J, LJ_TRERR_NYICONV);
+ }
+ /* Box pointer, ref, enum or 64 bit integer. */
+ return emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, sid), sp);
+}
+
+/* -- Convert TValue to C type (store) ------------------------------------ */
+
+static TRef crec_ct_tv(jit_State *J, CType *d, TRef dp, TRef sp, cTValue *sval)
+{
+ CTState *cts = ctype_ctsG(J2G(J));
+ CTypeID sid = CTID_P_VOID;
+ void *svisnz = 0;
+ CType *s;
+ if (LJ_LIKELY(tref_isinteger(sp))) {
+ sid = CTID_INT32;
+ svisnz = (void *)(intptr_t)(tvisint(sval)?(intV(sval)!=0):!tviszero(sval));
+ } else if (tref_isnum(sp)) {
+ sid = CTID_DOUBLE;
+ svisnz = (void *)(intptr_t)(tvisint(sval)?(intV(sval)!=0):!tviszero(sval));
+ } else if (tref_isbool(sp)) {
+ sp = lj_ir_kint(J, tref_istrue(sp) ? 1 : 0);
+ sid = CTID_BOOL;
+ } else if (tref_isnil(sp)) {
+ sp = lj_ir_kptr(J, NULL);
+ } else if (tref_isudata(sp)) {
+ GCudata *ud = udataV(sval);
+ if (ud->udtype == UDTYPE_IO_FILE) {
+ TRef tr = emitir(IRT(IR_FLOAD, IRT_U8), sp, IRFL_UDATA_UDTYPE);
+ emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, UDTYPE_IO_FILE));
+ sp = emitir(IRT(IR_FLOAD, IRT_PTR), sp, IRFL_UDATA_FILE);
+ } else {
+ sp = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, sizeof(GCudata)));
+ }
+ } else if (tref_isstr(sp)) {
+ if (ctype_isenum(d->info)) { /* Match string against enum constant. */
+ GCstr *str = strV(sval);
+ CTSize ofs;
+ CType *cct = lj_ctype_getfield(cts, d, str, &ofs);
+ /* Specialize to the name of the enum constant. */
+ emitir(IRTG(IR_EQ, IRT_STR), sp, lj_ir_kstr(J, str));
+ if (cct && ctype_isconstval(cct->info)) {
+ lua_assert(ctype_child(cts, cct)->size == 4);
+ svisnz = (void *)(intptr_t)(ofs != 0);
+ sp = lj_ir_kint(J, (int32_t)ofs);
+ sid = ctype_cid(cct->info);
+ } /* else: interpreter will throw. */
+ } else if (ctype_isrefarray(d->info)) { /* Copy string to array. */
+ lj_trace_err(J, LJ_TRERR_BADTYPE); /* NYI */
+ } else { /* Otherwise pass the string data as a const char[]. */
+ /* Don't use STRREF. It folds with SNEW, which loses the trailing NUL. */
+ sp = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, sizeof(GCstr)));
+ sid = CTID_A_CCHAR;
+ }
+ } else { /* NYI: tref_istab(sp), tref_islightud(sp). */
+ IRType t;
+ sid = argv2cdata(J, sp, sval)->ctypeid;
+ s = ctype_raw(cts, sid);
+ svisnz = cdataptr(cdataV(sval));
+ t = crec_ct2irt(cts, s);
+ if (ctype_isptr(s->info)) {
+ sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_PTR);
+ if (ctype_isref(s->info)) {
+ svisnz = *(void **)svisnz;
+ s = ctype_rawchild(cts, s);
+ if (ctype_isenum(s->info)) s = ctype_child(cts, s);
+ t = crec_ct2irt(cts, s);
+ } else {
+ goto doconv;
+ }
+ } else if (t == IRT_I64 || t == IRT_U64) {
+ sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_INT64);
+ lj_needsplit(J);
+ goto doconv;
+ } else if (t == IRT_INT || t == IRT_U32) {
+ if (ctype_isenum(s->info)) s = ctype_child(cts, s);
+ sp = emitir(IRT(IR_FLOAD, t), sp, IRFL_CDATA_INT);
+ goto doconv;
+ } else {
+ sp = emitir(IRT(IR_ADD, IRT_PTR), sp, lj_ir_kintp(J, sizeof(GCcdata)));
+ }
+ if (ctype_isnum(s->info) && t != IRT_CDATA)
+ sp = emitir(IRT(IR_XLOAD, t), sp, 0); /* Load number value. */
+ goto doconv;
+ }
+ s = ctype_get(cts, sid);
+doconv:
+ if (ctype_isenum(d->info)) d = ctype_child(cts, d);
+ return crec_ct_ct(J, d, s, dp, sp, svisnz);
+}
+
+/* -- C data metamethods -------------------------------------------------- */
+
+/* This would be rather difficult in FOLD, so do it here:
+** (base+k)+(idx*sz)+ofs ==> (base+idx*sz)+(ofs+k)
+** (base+(idx+k)*sz)+ofs ==> (base+idx*sz)+(ofs+k*sz)
+*/
+static TRef crec_reassoc_ofs(jit_State *J, TRef tr, ptrdiff_t *ofsp, MSize sz)
+{
+ IRIns *ir = IR(tref_ref(tr));
+ if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && irref_isk(ir->op2) &&
+ (ir->o == IR_ADD || ir->o == IR_ADDOV || ir->o == IR_SUBOV)) {
+ IRIns *irk = IR(ir->op2);
+ ptrdiff_t k;
+ if (LJ_64 && irk->o == IR_KINT64)
+ k = (ptrdiff_t)ir_kint64(irk)->u64 * sz;
+ else
+ k = (ptrdiff_t)irk->i * sz;
+ if (ir->o == IR_SUBOV) *ofsp -= k; else *ofsp += k;
+ tr = ir->op1; /* Not a TRef, but the caller doesn't care. */
+ }
+ return tr;
+}
+
+/* Record ctype __index/__newindex metamethods. */
+static void crec_index_meta(jit_State *J, CTState *cts, CType *ct,
+ RecordFFData *rd)
+{
+ CTypeID id = ctype_typeid(cts, ct);
+ cTValue *tv = lj_ctype_meta(cts, id, rd->data ? MM_newindex : MM_index);
+ if (!tv)
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ if (tvisfunc(tv)) {
+ J->base[-1] = lj_ir_kfunc(J, funcV(tv)) | TREF_FRAME;
+ rd->nres = -1; /* Pending tailcall. */
+ } else if (rd->data == 0 && tvistab(tv) && tref_isstr(J->base[1])) {
+ /* Specialize to result of __index lookup. */
+ cTValue *o = lj_tab_get(J->L, tabV(tv), &rd->argv[1]);
+ J->base[0] = lj_record_constify(J, o);
+ if (!J->base[0])
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ /* Always specialize to the key. */
+ emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, strV(&rd->argv[1])));
+ } else {
+ /* NYI: resolving of non-function metamethods. */
+ /* NYI: non-string keys for __index table. */
+ /* NYI: stores to __newindex table. */
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ }
+}
+
+void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd)
+{
+ TRef idx, ptr = J->base[0];
+ ptrdiff_t ofs = sizeof(GCcdata);
+ GCcdata *cd = argv2cdata(J, ptr, &rd->argv[0]);
+ CTState *cts = ctype_ctsG(J2G(J));
+ CType *ct = ctype_raw(cts, cd->ctypeid);
+ CTypeID sid = 0;
+
+ /* Resolve pointer or reference for cdata object. */
+ if (ctype_isptr(ct->info)) {
+ IRType t = (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32;
+ if (ctype_isref(ct->info)) ct = ctype_rawchild(cts, ct);
+ ptr = emitir(IRT(IR_FLOAD, t), ptr, IRFL_CDATA_PTR);
+ ofs = 0;
+ ptr = crec_reassoc_ofs(J, ptr, &ofs, 1);
+ }
+
+again:
+ idx = J->base[1];
+ if (tref_isnumber(idx)) {
+ idx = lj_opt_narrow_cindex(J, idx);
+ if (ctype_ispointer(ct->info)) {
+ CTSize sz;
+ integer_key:
+ if ((ct->info & CTF_COMPLEX))
+ idx = emitir(IRT(IR_BAND, IRT_INTP), idx, lj_ir_kintp(J, 1));
+ sz = lj_ctype_size(cts, (sid = ctype_cid(ct->info)));
+ idx = crec_reassoc_ofs(J, idx, &ofs, sz);
+#if LJ_TARGET_ARM || LJ_TARGET_PPC
+ /* Hoist base add to allow fusion of index/shift into operands. */
+ if (LJ_LIKELY(J->flags & JIT_F_OPT_LOOP) && ofs
+#if LJ_TARGET_ARM
+ && (sz == 1 || sz == 4)
+#endif
+ ) {
+ ptr = emitir(IRT(IR_ADD, IRT_PTR), ptr, lj_ir_kintp(J, ofs));
+ ofs = 0;
+ }
+#endif
+ idx = emitir(IRT(IR_MUL, IRT_INTP), idx, lj_ir_kintp(J, sz));
+ ptr = emitir(IRT(IR_ADD, IRT_PTR), idx, ptr);
+ }
+ } else if (tref_iscdata(idx)) {
+ GCcdata *cdk = cdataV(&rd->argv[1]);
+ CType *ctk = ctype_raw(cts, cdk->ctypeid);
+ IRType t = crec_ct2irt(cts, ctk);
+ if (ctype_ispointer(ct->info) && t >= IRT_I8 && t <= IRT_U64) {
+ if (ctk->size == 8) {
+ idx = emitir(IRT(IR_FLOAD, t), idx, IRFL_CDATA_INT64);
+ } else if (ctk->size == 4) {
+ idx = emitir(IRT(IR_FLOAD, t), idx, IRFL_CDATA_INT);
+ } else {
+ idx = emitir(IRT(IR_ADD, IRT_PTR), idx,
+ lj_ir_kintp(J, sizeof(GCcdata)));
+ idx = emitir(IRT(IR_XLOAD, t), idx, 0);
+ }
+ if (LJ_64 && ctk->size < sizeof(intptr_t) && !(ctk->info & CTF_UNSIGNED))
+ idx = emitconv(idx, IRT_INTP, IRT_INT, IRCONV_SEXT);
+ if (!LJ_64 && ctk->size > sizeof(intptr_t)) {
+ idx = emitconv(idx, IRT_INTP, t, 0);
+ lj_needsplit(J);
+ }
+ goto integer_key;
+ }
+ } else if (tref_isstr(idx)) {
+ GCstr *name = strV(&rd->argv[1]);
+ if (cd && cd->ctypeid == CTID_CTYPEID)
+ ct = ctype_raw(cts, crec_constructor(J, cd, ptr));
+ if (ctype_isstruct(ct->info)) {
+ CTSize fofs;
+ CType *fct;
+ fct = lj_ctype_getfield(cts, ct, name, &fofs);
+ if (fct) {
+ /* Always specialize to the field name. */
+ emitir(IRTG(IR_EQ, IRT_STR), idx, lj_ir_kstr(J, name));
+ if (ctype_isconstval(fct->info)) {
+ if (fct->size >= 0x80000000u &&
+ (ctype_child(cts, fct)->info & CTF_UNSIGNED)) {
+ J->base[0] = lj_ir_knum(J, (lua_Number)(uint32_t)fct->size);
+ return;
+ }
+ J->base[0] = lj_ir_kint(J, (int32_t)fct->size);
+ return; /* Interpreter will throw for newindex. */
+ } else if (ctype_isbitfield(fct->info)) {
+ lj_trace_err(J, LJ_TRERR_NYICONV);
+ } else {
+ lua_assert(ctype_isfield(fct->info));
+ sid = ctype_cid(fct->info);
+ }
+ ofs += (ptrdiff_t)fofs;
+ }
+ } else if (ctype_iscomplex(ct->info)) {
+ if (name->len == 2 &&
+ ((strdata(name)[0] == 'r' && strdata(name)[1] == 'e') ||
+ (strdata(name)[0] == 'i' && strdata(name)[1] == 'm'))) {
+ /* Always specialize to the field name. */
+ emitir(IRTG(IR_EQ, IRT_STR), idx, lj_ir_kstr(J, name));
+ if (strdata(name)[0] == 'i') ofs += (ct->size >> 1);
+ sid = ctype_cid(ct->info);
+ }
+ }
+ }
+ if (!sid) {
+ if (ctype_isptr(ct->info)) { /* Automatically perform '->'. */
+ CType *cct = ctype_rawchild(cts, ct);
+ if (ctype_isstruct(cct->info)) {
+ ct = cct;
+ cd = NULL;
+ if (tref_isstr(idx)) goto again;
+ }
+ }
+ crec_index_meta(J, cts, ct, rd);
+ return;
+ }
+
+ if (ofs)
+ ptr = emitir(IRT(IR_ADD, IRT_PTR), ptr, lj_ir_kintp(J, ofs));
+
+ /* Resolve reference for field. */
+ ct = ctype_get(cts, sid);
+ if (ctype_isref(ct->info)) {
+ ptr = emitir(IRT(IR_XLOAD, IRT_PTR), ptr, 0);
+ sid = ctype_cid(ct->info);
+ ct = ctype_get(cts, sid);
+ }
+
+ while (ctype_isattrib(ct->info))
+ ct = ctype_child(cts, ct); /* Skip attributes. */
+
+ if (rd->data == 0) { /* __index metamethod. */
+ J->base[0] = crec_tv_ct(J, ct, sid, ptr);
+ } else { /* __newindex metamethod. */
+ rd->nres = 0;
+ J->needsnap = 1;
+ crec_ct_tv(J, ct, ptr, J->base[2], &rd->argv[2]);
+ }
+}
+
+/* Record setting a finalizer. */
+static void crec_finalizer(jit_State *J, TRef trcd, cTValue *fin)
+{
+ TRef trlo = lj_ir_call(J, IRCALL_lj_cdata_setfin, trcd);
+ TRef trhi = emitir(IRT(IR_ADD, IRT_P32), trlo, lj_ir_kint(J, 4));
+ if (LJ_BE) { TRef tmp = trlo; trlo = trhi; trhi = tmp; }
+ if (tvisfunc(fin)) {
+ emitir(IRT(IR_XSTORE, IRT_P32), trlo, lj_ir_kfunc(J, funcV(fin)));
+ emitir(IRTI(IR_XSTORE), trhi, lj_ir_kint(J, LJ_TFUNC));
+ } else if (tviscdata(fin)) {
+ emitir(IRT(IR_XSTORE, IRT_P32), trlo,
+ lj_ir_kgc(J, obj2gco(cdataV(fin)), IRT_CDATA));
+ emitir(IRTI(IR_XSTORE), trhi, lj_ir_kint(J, LJ_TCDATA));
+ } else {
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ }
+ J->needsnap = 1;
+}
+
+/* Record cdata allocation. */
+static void crec_alloc(jit_State *J, RecordFFData *rd, CTypeID id)
+{
+ CTState *cts = ctype_ctsG(J2G(J));
+ CTSize sz;
+ CTInfo info = lj_ctype_info(cts, id, &sz);
+ CType *d = ctype_raw(cts, id);
+ TRef trid;
+ if (!sz || sz > 128 || (info & CTF_VLA) || ctype_align(info) > CT_MEMALIGN)
+ lj_trace_err(J, LJ_TRERR_NYICONV); /* NYI: large/special allocations. */
+ trid = lj_ir_kint(J, id);
+ /* Use special instruction to box pointer or 32/64 bit integer. */
+ if (ctype_isptr(info) || (ctype_isinteger(info) && (sz == 4 || sz == 8))) {
+ TRef sp = J->base[1] ? crec_ct_tv(J, d, 0, J->base[1], &rd->argv[1]) :
+ ctype_isptr(info) ? lj_ir_kptr(J, NULL) :
+ sz == 4 ? lj_ir_kint(J, 0) :
+ (lj_needsplit(J), lj_ir_kint64(J, 0));
+ J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), trid, sp);
+ } else {
+ TRef trcd = emitir(IRTG(IR_CNEW, IRT_CDATA), trid, TREF_NIL);
+ cTValue *fin;
+ J->base[0] = trcd;
+ if (J->base[1] && !J->base[2] &&
+ !lj_cconv_multi_init(cts, d, &rd->argv[1])) {
+ goto single_init;
+ } else if (ctype_isarray(d->info)) {
+ CType *dc = ctype_rawchild(cts, d); /* Array element type. */
+ CTSize ofs, esize = dc->size;
+ TRef sp = 0;
+ TValue tv;
+ TValue *sval = &tv;
+ MSize i;
+ tv.u64 = 0;
+ if (!(ctype_isnum(dc->info) || ctype_isptr(dc->info)))
+ lj_trace_err(J, LJ_TRERR_NYICONV); /* NYI: init array of aggregates. */
+ for (i = 1, ofs = 0; ofs < sz; ofs += esize) {
+ TRef dp = emitir(IRT(IR_ADD, IRT_PTR), trcd,
+ lj_ir_kintp(J, ofs + sizeof(GCcdata)));
+ if (J->base[i]) {
+ sp = J->base[i];
+ sval = &rd->argv[i];
+ i++;
+ } else if (i != 2) {
+ sp = ctype_isnum(dc->info) ? lj_ir_kint(J, 0) : TREF_NIL;
+ }
+ crec_ct_tv(J, dc, dp, sp, sval);
+ }
+ } else if (ctype_isstruct(d->info)) {
+ CTypeID fid = d->sib;
+ MSize i = 1;
+ while (fid) {
+ CType *df = ctype_get(cts, fid);
+ fid = df->sib;
+ if (ctype_isfield(df->info)) {
+ CType *dc;
+ TRef sp, dp;
+ TValue tv;
+ TValue *sval = &tv;
+ setintV(&tv, 0);
+ if (!gcref(df->name)) continue; /* Ignore unnamed fields. */
+ dc = ctype_rawchild(cts, df); /* Field type. */
+ if (!(ctype_isnum(dc->info) || ctype_isptr(dc->info) ||
+ ctype_isenum(dc->info)))
+ lj_trace_err(J, LJ_TRERR_NYICONV); /* NYI: init aggregates. */
+ if (J->base[i]) {
+ sp = J->base[i];
+ sval = &rd->argv[i];
+ i++;
+ } else {
+ sp = ctype_isptr(dc->info) ? TREF_NIL : lj_ir_kint(J, 0);
+ }
+ dp = emitir(IRT(IR_ADD, IRT_PTR), trcd,
+ lj_ir_kintp(J, df->size + sizeof(GCcdata)));
+ crec_ct_tv(J, dc, dp, sp, sval);
+ } else if (!ctype_isconstval(df->info)) {
+ /* NYI: init bitfields and sub-structures. */
+ lj_trace_err(J, LJ_TRERR_NYICONV);
+ }
+ }
+ } else {
+ TRef dp;
+ single_init:
+ dp = emitir(IRT(IR_ADD, IRT_PTR), trcd, lj_ir_kintp(J, sizeof(GCcdata)));
+ if (J->base[1]) {
+ crec_ct_tv(J, d, dp, J->base[1], &rd->argv[1]);
+ } else {
+ TValue tv;
+ tv.u64 = 0;
+ crec_ct_tv(J, d, dp, lj_ir_kint(J, 0), &tv);
+ }
+ }
+ /* Handle __gc metamethod. */
+ fin = lj_ctype_meta(cts, id, MM_gc);
+ if (fin)
+ crec_finalizer(J, trcd, fin);
+ }
+}
+
+/* Record argument conversions. */
+static TRef crec_call_args(jit_State *J, RecordFFData *rd,
+ CTState *cts, CType *ct)
+{
+ TRef args[CCI_NARGS_MAX];
+ CTypeID fid;
+ MSize i, n;
+ TRef tr, *base;
+ cTValue *o;
+#if LJ_TARGET_X86
+#if LJ_ABI_WIN
+ TRef *arg0 = NULL, *arg1 = NULL;
+#endif
+ int ngpr = 0;
+ if (ctype_cconv(ct->info) == CTCC_THISCALL)
+ ngpr = 1;
+ else if (ctype_cconv(ct->info) == CTCC_FASTCALL)
+ ngpr = 2;
+#endif
+
+ /* Skip initial attributes. */
+ fid = ct->sib;
+ while (fid) {
+ CType *ctf = ctype_get(cts, fid);
+ if (!ctype_isattrib(ctf->info)) break;
+ fid = ctf->sib;
+ }
+ args[0] = TREF_NIL;
+ for (n = 0, base = J->base+1, o = rd->argv+1; *base; n++, base++, o++) {
+ CTypeID did;
+ CType *d;
+
+ if (n >= CCI_NARGS_MAX)
+ lj_trace_err(J, LJ_TRERR_NYICALL);
+
+ if (fid) { /* Get argument type from field. */
+ CType *ctf = ctype_get(cts, fid);
+ fid = ctf->sib;
+ lua_assert(ctype_isfield(ctf->info));
+ did = ctype_cid(ctf->info);
+ } else {
+ if (!(ct->info & CTF_VARARG))
+ lj_trace_err(J, LJ_TRERR_NYICALL); /* Too many arguments. */
+ did = lj_ccall_ctid_vararg(cts, o); /* Infer vararg type. */
+ }
+ d = ctype_raw(cts, did);
+ if (!(ctype_isnum(d->info) || ctype_isptr(d->info) ||
+ ctype_isenum(d->info)))
+ lj_trace_err(J, LJ_TRERR_NYICALL);
+ tr = crec_ct_tv(J, d, 0, *base, o);
+ if (ctype_isinteger_or_bool(d->info)) {
+ if (d->size < 4) {
+ if ((d->info & CTF_UNSIGNED))
+ tr = emitconv(tr, IRT_INT, d->size==1 ? IRT_U8 : IRT_U16, 0);
+ else
+ tr = emitconv(tr, IRT_INT, d->size==1 ? IRT_I8 : IRT_I16,IRCONV_SEXT);
+ }
+ } else if (LJ_SOFTFP && ctype_isfp(d->info) && d->size > 4) {
+ lj_needsplit(J);
+ }
+#if LJ_TARGET_X86
+ /* 64 bit args must not end up in registers for fastcall/thiscall. */
+#if LJ_ABI_WIN
+ if (!ctype_isfp(d->info)) {
+ /* Sigh, the Windows/x86 ABI allows reordering across 64 bit args. */
+ if (tref_typerange(tr, IRT_I64, IRT_U64)) {
+ if (ngpr) {
+ arg0 = &args[n]; args[n++] = TREF_NIL; ngpr--;
+ if (ngpr) {
+ arg1 = &args[n]; args[n++] = TREF_NIL; ngpr--;
+ }
+ }
+ } else {
+ if (arg0) { *arg0 = tr; arg0 = NULL; n--; continue; }
+ if (arg1) { *arg1 = tr; arg1 = NULL; n--; continue; }
+ if (ngpr) ngpr--;
+ }
+ }
+#else
+ if (!ctype_isfp(d->info) && ngpr) {
+ if (tref_typerange(tr, IRT_I64, IRT_U64)) {
+ /* No reordering for other x86 ABIs. Simply add alignment args. */
+ do { args[n++] = TREF_NIL; } while (--ngpr);
+ } else {
+ ngpr--;
+ }
+ }
+#endif
+#endif
+ args[n] = tr;
+ }
+ tr = args[0];
+ for (i = 1; i < n; i++)
+ tr = emitir(IRT(IR_CARG, IRT_NIL), tr, args[i]);
+ return tr;
+}
+
+/* Create a snapshot for the caller, simulating a 'false' return value. */
+static void crec_snap_caller(jit_State *J)
+{
+ lua_State *L = J->L;
+ TValue *base = L->base, *top = L->top;
+ const BCIns *pc = J->pc;
+ TRef ftr = J->base[-1];
+ ptrdiff_t delta;
+ if (!frame_islua(base-1) || J->framedepth <= 0)
+ lj_trace_err(J, LJ_TRERR_NYICALL);
+ J->pc = frame_pc(base-1); delta = 1+bc_a(J->pc[-1]);
+ L->top = base; L->base = base - delta;
+ J->base[-1] = TREF_FALSE;
+ J->base -= delta; J->baseslot -= (BCReg)delta;
+ J->maxslot = (BCReg)delta; J->framedepth--;
+ lj_snap_add(J);
+ L->base = base; L->top = top;
+ J->framedepth++; J->maxslot = 1;
+ J->base += delta; J->baseslot += (BCReg)delta;
+ J->base[-1] = ftr; J->pc = pc;
+}
+
+/* Record function call. */
+static int crec_call(jit_State *J, RecordFFData *rd, GCcdata *cd)
+{
+ CTState *cts = ctype_ctsG(J2G(J));
+ CType *ct = ctype_raw(cts, cd->ctypeid);
+ IRType tp = IRT_PTR;
+ if (ctype_isptr(ct->info)) {
+ tp = (LJ_64 && ct->size == 8) ? IRT_P64 : IRT_P32;
+ ct = ctype_rawchild(cts, ct);
+ }
+ if (ctype_isfunc(ct->info)) {
+ TRef func = emitir(IRT(IR_FLOAD, tp), J->base[0], IRFL_CDATA_PTR);
+ CType *ctr = ctype_rawchild(cts, ct);
+ IRType t = crec_ct2irt(cts, ctr);
+ TRef tr;
+ TValue tv;
+ /* Check for blacklisted C functions that might call a callback. */
+ setlightudV(&tv,
+ cdata_getptr(cdataptr(cd), (LJ_64 && tp == IRT_P64) ? 8 : 4));
+ if (tvistrue(lj_tab_get(J->L, cts->miscmap, &tv)))
+ lj_trace_err(J, LJ_TRERR_BLACKL);
+ if (ctype_isvoid(ctr->info)) {
+ t = IRT_NIL;
+ rd->nres = 0;
+ } else if (!(ctype_isnum(ctr->info) || ctype_isptr(ctr->info) ||
+ ctype_isenum(ctr->info)) || t == IRT_CDATA) {
+ lj_trace_err(J, LJ_TRERR_NYICALL);
+ }
+ if ((ct->info & CTF_VARARG)
+#if LJ_TARGET_X86
+ || ctype_cconv(ct->info) != CTCC_CDECL
+#endif
+ )
+ func = emitir(IRT(IR_CARG, IRT_NIL), func,
+ lj_ir_kint(J, ctype_typeid(cts, ct)));
+ tr = emitir(IRT(IR_CALLXS, t), crec_call_args(J, rd, cts, ct), func);
+ if (ctype_isbool(ctr->info)) {
+ if (frame_islua(J->L->base-1) && bc_b(frame_pc(J->L->base-1)[-1]) == 1) {
+ /* Don't check result if ignored. */
+ tr = TREF_NIL;
+ } else {
+ crec_snap_caller(J);
+#if LJ_TARGET_X86ORX64
+ /* Note: only the x86/x64 backend supports U8 and only for EQ(tr, 0). */
+ lj_ir_set(J, IRTG(IR_NE, IRT_U8), tr, lj_ir_kint(J, 0));
+#else
+ lj_ir_set(J, IRTGI(IR_NE), tr, lj_ir_kint(J, 0));
+#endif
+ J->postproc = LJ_POST_FIXGUARDSNAP;
+ tr = TREF_TRUE;
+ }
+ } else if (t == IRT_PTR || (LJ_64 && t == IRT_P32) ||
+ t == IRT_I64 || t == IRT_U64 || ctype_isenum(ctr->info)) {
+ TRef trid = lj_ir_kint(J, ctype_cid(ct->info));
+ tr = emitir(IRTG(IR_CNEWI, IRT_CDATA), trid, tr);
+ if (t == IRT_I64 || t == IRT_U64) lj_needsplit(J);
+ } else if (t == IRT_FLOAT || t == IRT_U32) {
+ tr = emitconv(tr, IRT_NUM, t, 0);
+ } else if (t == IRT_I8 || t == IRT_I16) {
+ tr = emitconv(tr, IRT_INT, t, IRCONV_SEXT);
+ } else if (t == IRT_U8 || t == IRT_U16) {
+ tr = emitconv(tr, IRT_INT, t, 0);
+ }
+ J->base[0] = tr;
+ J->needsnap = 1;
+ return 1;
+ }
+ return 0;
+}
+
+void LJ_FASTCALL recff_cdata_call(jit_State *J, RecordFFData *rd)
+{
+ CTState *cts = ctype_ctsG(J2G(J));
+ GCcdata *cd = argv2cdata(J, J->base[0], &rd->argv[0]);
+ CTypeID id = cd->ctypeid;
+ CType *ct;
+ cTValue *tv;
+ MMS mm = MM_call;
+ if (id == CTID_CTYPEID) {
+ id = crec_constructor(J, cd, J->base[0]);
+ mm = MM_new;
+ } else if (crec_call(J, rd, cd)) {
+ return;
+ }
+ /* Record ctype __call/__new metamethod. */
+ ct = ctype_raw(cts, id);
+ tv = lj_ctype_meta(cts, ctype_isptr(ct->info) ? ctype_cid(ct->info) : id, mm);
+ if (tv) {
+ if (tvisfunc(tv)) {
+ J->base[-1] = lj_ir_kfunc(J, funcV(tv)) | TREF_FRAME;
+ rd->nres = -1; /* Pending tailcall. */
+ return;
+ }
+ } else if (mm == MM_new) {
+ crec_alloc(J, rd, id);
+ return;
+ }
+ /* No metamethod or NYI: non-function metamethods. */
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+}
+
+static TRef crec_arith_int64(jit_State *J, TRef *sp, CType **s, MMS mm)
+{
+ if (sp[0] && sp[1] && ctype_isnum(s[0]->info) && ctype_isnum(s[1]->info)) {
+ IRType dt;
+ CTypeID id;
+ TRef tr;
+ MSize i;
+ IROp op;
+ lj_needsplit(J);
+ if (((s[0]->info & CTF_UNSIGNED) && s[0]->size == 8) ||
+ ((s[1]->info & CTF_UNSIGNED) && s[1]->size == 8)) {
+ dt = IRT_U64; id = CTID_UINT64;
+ } else {
+ dt = IRT_I64; id = CTID_INT64;
+ if (mm < MM_add &&
+ !((s[0]->info | s[1]->info) & CTF_FP) &&
+ s[0]->size == 4 && s[1]->size == 4) { /* Try to narrow comparison. */
+ if (!((s[0]->info ^ s[1]->info) & CTF_UNSIGNED) ||
+ (tref_isk(sp[1]) && IR(tref_ref(sp[1]))->i >= 0)) {
+ dt = (s[0]->info & CTF_UNSIGNED) ? IRT_U32 : IRT_INT;
+ goto comp;
+ } else if (tref_isk(sp[0]) && IR(tref_ref(sp[0]))->i >= 0) {
+ dt = (s[1]->info & CTF_UNSIGNED) ? IRT_U32 : IRT_INT;
+ goto comp;
+ }
+ }
+ }
+ for (i = 0; i < 2; i++) {
+ IRType st = tref_type(sp[i]);
+ if (st == IRT_NUM || st == IRT_FLOAT)
+ sp[i] = emitconv(sp[i], dt, st, IRCONV_TRUNC|IRCONV_ANY);
+ else if (!(st == IRT_I64 || st == IRT_U64))
+ sp[i] = emitconv(sp[i], dt, IRT_INT,
+ (s[i]->info & CTF_UNSIGNED) ? 0 : IRCONV_SEXT);
+ }
+ if (mm < MM_add) {
+ comp:
+ /* Assume true comparison. Fixup and emit pending guard later. */
+ if (mm == MM_eq) {
+ op = IR_EQ;
+ } else {
+ op = mm == MM_lt ? IR_LT : IR_LE;
+ if (dt == IRT_U32 || dt == IRT_U64)
+ op += (IR_ULT-IR_LT);
+ }
+ lj_ir_set(J, IRTG(op, dt), sp[0], sp[1]);
+ J->postproc = LJ_POST_FIXGUARD;
+ return TREF_TRUE;
+ } else {
+ tr = emitir(IRT(mm+(int)IR_ADD-(int)MM_add, dt), sp[0], sp[1]);
+ }
+ return emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr);
+ }
+ return 0;
+}
+
+static TRef crec_arith_ptr(jit_State *J, TRef *sp, CType **s, MMS mm)
+{
+ CTState *cts = ctype_ctsG(J2G(J));
+ CType *ctp = s[0];
+ if (!(sp[0] && sp[1])) return 0;
+ if (ctype_isptr(ctp->info) || ctype_isrefarray(ctp->info)) {
+ if ((mm == MM_sub || mm == MM_eq || mm == MM_lt || mm == MM_le) &&
+ (ctype_isptr(s[1]->info) || ctype_isrefarray(s[1]->info))) {
+ if (mm == MM_sub) { /* Pointer difference. */
+ TRef tr;
+ CTSize sz = lj_ctype_size(cts, ctype_cid(ctp->info));
+ if (sz == 0 || (sz & (sz-1)) != 0)
+ return 0; /* NYI: integer division. */
+ tr = emitir(IRT(IR_SUB, IRT_INTP), sp[0], sp[1]);
+ tr = emitir(IRT(IR_BSAR, IRT_INTP), tr, lj_ir_kint(J, lj_fls(sz)));
+#if LJ_64
+ tr = emitconv(tr, IRT_NUM, IRT_INTP, 0);
+#endif
+ return tr;
+ } else { /* Pointer comparison (unsigned). */
+ /* Assume true comparison. Fixup and emit pending guard later. */
+ IROp op = mm == MM_eq ? IR_EQ : mm == MM_lt ? IR_ULT : IR_ULE;
+ lj_ir_set(J, IRTG(op, IRT_PTR), sp[0], sp[1]);
+ J->postproc = LJ_POST_FIXGUARD;
+ return TREF_TRUE;
+ }
+ }
+ if (!((mm == MM_add || mm == MM_sub) && ctype_isnum(s[1]->info)))
+ return 0;
+ } else if (mm == MM_add && ctype_isnum(ctp->info) &&
+ (ctype_isptr(s[1]->info) || ctype_isrefarray(s[1]->info))) {
+ TRef tr = sp[0]; sp[0] = sp[1]; sp[1] = tr; /* Swap pointer and index. */
+ ctp = s[1];
+ } else {
+ return 0;
+ }
+ {
+ TRef tr = sp[1];
+ IRType t = tref_type(tr);
+ CTSize sz = lj_ctype_size(cts, ctype_cid(ctp->info));
+ CTypeID id;
+#if LJ_64
+ if (t == IRT_NUM || t == IRT_FLOAT)
+ tr = emitconv(tr, IRT_INTP, t, IRCONV_TRUNC|IRCONV_ANY);
+ else if (!(t == IRT_I64 || t == IRT_U64))
+ tr = emitconv(tr, IRT_INTP, IRT_INT,
+ ((t - IRT_I8) & 1) ? 0 : IRCONV_SEXT);
+#else
+ if (!tref_typerange(sp[1], IRT_I8, IRT_U32)) {
+ tr = emitconv(tr, IRT_INTP, t,
+ (t == IRT_NUM || t == IRT_FLOAT) ?
+ IRCONV_TRUNC|IRCONV_ANY : 0);
+ }
+#endif
+ tr = emitir(IRT(IR_MUL, IRT_INTP), tr, lj_ir_kintp(J, sz));
+ tr = emitir(IRT(mm+(int)IR_ADD-(int)MM_add, IRT_PTR), sp[0], tr);
+ id = lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|ctype_cid(ctp->info)),
+ CTSIZE_PTR);
+ return emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr);
+ }
+}
+
+/* Record ctype arithmetic metamethods. */
+static TRef crec_arith_meta(jit_State *J, TRef *sp, CType **s, CTState *cts,
+ RecordFFData *rd)
+{
+ cTValue *tv = NULL;
+ if (J->base[0]) {
+ if (tviscdata(&rd->argv[0])) {
+ CTypeID id = argv2cdata(J, J->base[0], &rd->argv[0])->ctypeid;
+ CType *ct = ctype_raw(cts, id);
+ if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);
+ tv = lj_ctype_meta(cts, id, (MMS)rd->data);
+ }
+ if (!tv && J->base[1] && tviscdata(&rd->argv[1])) {
+ CTypeID id = argv2cdata(J, J->base[1], &rd->argv[1])->ctypeid;
+ CType *ct = ctype_raw(cts, id);
+ if (ctype_isptr(ct->info)) id = ctype_cid(ct->info);
+ tv = lj_ctype_meta(cts, id, (MMS)rd->data);
+ }
+ }
+ if (tv) {
+ if (tvisfunc(tv)) {
+ J->base[-1] = lj_ir_kfunc(J, funcV(tv)) | TREF_FRAME;
+ rd->nres = -1; /* Pending tailcall. */
+ return 0;
+ } /* NYI: non-function metamethods. */
+ } else if ((MMS)rd->data == MM_eq) { /* Fallback cdata pointer comparison. */
+ if (sp[0] && sp[1] && ctype_isnum(s[0]->info) == ctype_isnum(s[1]->info)) {
+ /* Assume true comparison. Fixup and emit pending guard later. */
+ lj_ir_set(J, IRTG(IR_EQ, IRT_PTR), sp[0], sp[1]);
+ J->postproc = LJ_POST_FIXGUARD;
+ return TREF_TRUE;
+ } else {
+ return TREF_FALSE;
+ }
+ }
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ return 0;
+}
+
+void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd)
+{
+ CTState *cts = ctype_ctsG(J2G(J));
+ TRef sp[2];
+ CType *s[2];
+ MSize i;
+ for (i = 0; i < 2; i++) {
+ TRef tr = J->base[i];
+ CType *ct = ctype_get(cts, CTID_DOUBLE);
+ if (!tr) {
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ } else if (tref_iscdata(tr)) {
+ CTypeID id = argv2cdata(J, tr, &rd->argv[i])->ctypeid;
+ IRType t;
+ ct = ctype_raw(cts, id);
+ t = crec_ct2irt(cts, ct);
+ if (ctype_isptr(ct->info)) { /* Resolve pointer or reference. */
+ tr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_PTR);
+ if (ctype_isref(ct->info)) {
+ ct = ctype_rawchild(cts, ct);
+ t = crec_ct2irt(cts, ct);
+ }
+ } else if (t == IRT_I64 || t == IRT_U64) {
+ tr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_INT64);
+ lj_needsplit(J);
+ goto ok;
+ } else if (t == IRT_INT || t == IRT_U32) {
+ tr = emitir(IRT(IR_FLOAD, t), tr, IRFL_CDATA_INT);
+ if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);
+ goto ok;
+ } else if (ctype_isfunc(ct->info)) {
+ tr = emitir(IRT(IR_FLOAD, IRT_PTR), tr, IRFL_CDATA_PTR);
+ ct = ctype_get(cts,
+ lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR));
+ goto ok;
+ } else {
+ tr = emitir(IRT(IR_ADD, IRT_PTR), tr, lj_ir_kintp(J, sizeof(GCcdata)));
+ }
+ if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);
+ if (ctype_isnum(ct->info)) {
+ if (t == IRT_CDATA) {
+ tr = 0;
+ } else {
+ if (t == IRT_I64 || t == IRT_U64) lj_needsplit(J);
+ tr = emitir(IRT(IR_XLOAD, t), tr, 0);
+ }
+ }
+ } else if (tref_isnil(tr)) {
+ tr = lj_ir_kptr(J, NULL);
+ ct = ctype_get(cts, CTID_P_VOID);
+ } else if (tref_isinteger(tr)) {
+ ct = ctype_get(cts, CTID_INT32);
+ } else if (tref_isstr(tr)) {
+ TRef tr2 = J->base[1-i];
+ CTypeID id = argv2cdata(J, tr2, &rd->argv[1-i])->ctypeid;
+ ct = ctype_raw(cts, id);
+ if (ctype_isenum(ct->info)) { /* Match string against enum constant. */
+ GCstr *str = strV(&rd->argv[i]);
+ CTSize ofs;
+ CType *cct = lj_ctype_getfield(cts, ct, str, &ofs);
+ if (cct && ctype_isconstval(cct->info)) {
+ /* Specialize to the name of the enum constant. */
+ emitir(IRTG(IR_EQ, IRT_STR), tr, lj_ir_kstr(J, str));
+ ct = ctype_child(cts, cct);
+ tr = lj_ir_kint(J, (int32_t)ofs);
+ } else { /* Interpreter will throw or return false. */
+ ct = ctype_get(cts, CTID_P_VOID);
+ }
+ } else if (ctype_isptr(ct->info)) {
+ tr = emitir(IRT(IR_ADD, IRT_PTR), tr, lj_ir_kintp(J, sizeof(GCstr)));
+ } else {
+ ct = ctype_get(cts, CTID_P_VOID);
+ }
+ } else if (!tref_isnum(tr)) {
+ tr = 0;
+ ct = ctype_get(cts, CTID_P_VOID);
+ }
+ ok:
+ s[i] = ct;
+ sp[i] = tr;
+ }
+ {
+ TRef tr;
+ if (!(tr = crec_arith_int64(J, sp, s, (MMS)rd->data)) &&
+ !(tr = crec_arith_ptr(J, sp, s, (MMS)rd->data)) &&
+ !(tr = crec_arith_meta(J, sp, s, cts, rd)))
+ return;
+ J->base[0] = tr;
+ /* Fixup cdata comparisons, too. Avoids some cdata escapes. */
+ if (J->postproc == LJ_POST_FIXGUARD && frame_iscont(J->L->base-1) &&
+ !irt_isguard(J->guardemit)) {
+ const BCIns *pc = frame_contpc(J->L->base-1) - 1;
+ if (bc_op(*pc) <= BC_ISNEP) {
+ setframe_pc(&J2G(J)->tmptv, pc);
+ J2G(J)->tmptv.u32.lo = ((tref_istrue(tr) ^ bc_op(*pc)) & 1);
+ J->postproc = LJ_POST_FIXCOMP;
+ }
+ }
+ }
+}
+
+/* -- C library namespace metamethods ------------------------------------- */
+
+void LJ_FASTCALL recff_clib_index(jit_State *J, RecordFFData *rd)
+{
+ CTState *cts = ctype_ctsG(J2G(J));
+ if (tref_isudata(J->base[0]) && tref_isstr(J->base[1]) &&
+ udataV(&rd->argv[0])->udtype == UDTYPE_FFI_CLIB) {
+ CLibrary *cl = (CLibrary *)uddata(udataV(&rd->argv[0]));
+ GCstr *name = strV(&rd->argv[1]);
+ CType *ct;
+ CTypeID id = lj_ctype_getname(cts, &ct, name, CLNS_INDEX);
+ cTValue *tv = lj_tab_getstr(cl->cache, name);
+ rd->nres = rd->data;
+ if (id && tv && !tvisnil(tv)) {
+ /* Specialize to the symbol name and make the result a constant. */
+ emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, name));
+ if (ctype_isconstval(ct->info)) {
+ if (ct->size >= 0x80000000u &&
+ (ctype_child(cts, ct)->info & CTF_UNSIGNED))
+ J->base[0] = lj_ir_knum(J, (lua_Number)(uint32_t)ct->size);
+ else
+ J->base[0] = lj_ir_kint(J, (int32_t)ct->size);
+ } else if (ctype_isextern(ct->info)) {
+ CTypeID sid = ctype_cid(ct->info);
+ void *sp = *(void **)cdataptr(cdataV(tv));
+ TRef ptr;
+ ct = ctype_raw(cts, sid);
+ if (LJ_64 && !checkptr32(sp))
+ ptr = lj_ir_kintp(J, (uintptr_t)sp);
+ else
+ ptr = lj_ir_kptr(J, sp);
+ if (rd->data) {
+ J->base[0] = crec_tv_ct(J, ct, sid, ptr);
+ } else {
+ J->needsnap = 1;
+ crec_ct_tv(J, ct, ptr, J->base[2], &rd->argv[2]);
+ }
+ } else {
+ J->base[0] = lj_ir_kgc(J, obj2gco(cdataV(tv)), IRT_CDATA);
+ }
+ } else {
+ lj_trace_err(J, LJ_TRERR_NOCACHE);
+ }
+ } /* else: interpreter will throw. */
+}
+
+/* -- FFI library functions ----------------------------------------------- */
+
+static TRef crec_toint(jit_State *J, CTState *cts, TRef sp, TValue *sval)
+{
+ return crec_ct_tv(J, ctype_get(cts, CTID_INT32), 0, sp, sval);
+}
+
+void LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd)
+{
+ crec_alloc(J, rd, argv2ctype(J, J->base[0], &rd->argv[0]));
+}
+
+void LJ_FASTCALL recff_ffi_errno(jit_State *J, RecordFFData *rd)
+{
+ UNUSED(rd);
+ if (J->base[0])
+ lj_trace_err(J, LJ_TRERR_NYICALL);
+ J->base[0] = lj_ir_call(J, IRCALL_lj_vm_errno);
+}
+
+void LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd)
+{
+ CTState *cts = ctype_ctsG(J2G(J));
+ TRef tr = J->base[0];
+ if (tr) {
+ TRef trlen = J->base[1];
+ if (!tref_isnil(trlen)) {
+ trlen = crec_toint(J, cts, trlen, &rd->argv[1]);
+ tr = crec_ct_tv(J, ctype_get(cts, CTID_P_CVOID), 0, tr, &rd->argv[0]);
+ } else {
+ tr = crec_ct_tv(J, ctype_get(cts, CTID_P_CCHAR), 0, tr, &rd->argv[0]);
+ trlen = lj_ir_call(J, IRCALL_strlen, tr);
+ }
+ J->base[0] = emitir(IRT(IR_XSNEW, IRT_STR), tr, trlen);
+ } /* else: interpreter will throw. */
+}
+
+void LJ_FASTCALL recff_ffi_copy(jit_State *J, RecordFFData *rd)
+{
+ CTState *cts = ctype_ctsG(J2G(J));
+ TRef trdst = J->base[0], trsrc = J->base[1], trlen = J->base[2];
+ if (trdst && trsrc && (trlen || tref_isstr(trsrc))) {
+ trdst = crec_ct_tv(J, ctype_get(cts, CTID_P_VOID), 0, trdst, &rd->argv[0]);
+ trsrc = crec_ct_tv(J, ctype_get(cts, CTID_P_CVOID), 0, trsrc, &rd->argv[1]);
+ if (trlen) {
+ trlen = crec_toint(J, cts, trlen, &rd->argv[2]);
+ } else {
+ trlen = emitir(IRTI(IR_FLOAD), J->base[1], IRFL_STR_LEN);
+ trlen = emitir(IRTI(IR_ADD), trlen, lj_ir_kint(J, 1));
+ }
+ rd->nres = 0;
+ crec_copy(J, trdst, trsrc, trlen, NULL);
+ } /* else: interpreter will throw. */
+}
+
+void LJ_FASTCALL recff_ffi_fill(jit_State *J, RecordFFData *rd)
+{
+ CTState *cts = ctype_ctsG(J2G(J));
+ TRef trdst = J->base[0], trlen = J->base[1], trfill = J->base[2];
+ if (trdst && trlen) {
+ CTSize step = 1;
+ if (tviscdata(&rd->argv[0])) { /* Get alignment of original destination. */
+ CTSize sz;
+ CType *ct = ctype_raw(cts, cdataV(&rd->argv[0])->ctypeid);
+ if (ctype_isptr(ct->info))
+ ct = ctype_rawchild(cts, ct);
+ step = (1u<<ctype_align(lj_ctype_info(cts, ctype_typeid(cts, ct), &sz)));
+ }
+ trdst = crec_ct_tv(J, ctype_get(cts, CTID_P_VOID), 0, trdst, &rd->argv[0]);
+ trlen = crec_toint(J, cts, trlen, &rd->argv[1]);
+ if (trfill)
+ trfill = crec_toint(J, cts, trfill, &rd->argv[2]);
+ else
+ trfill = lj_ir_kint(J, 0);
+ rd->nres = 0;
+ crec_fill(J, trdst, trlen, trfill, step);
+ } /* else: interpreter will throw. */
+}
+
+void LJ_FASTCALL recff_ffi_typeof(jit_State *J, RecordFFData *rd)
+{
+ if (tref_iscdata(J->base[0])) {
+ TRef trid = lj_ir_kint(J, argv2ctype(J, J->base[0], &rd->argv[0]));
+ J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA),
+ lj_ir_kint(J, CTID_CTYPEID), trid);
+ } else {
+ setfuncV(J->L, &J->errinfo, J->fn);
+ lj_trace_err_info(J, LJ_TRERR_NYIFFU);
+ }
+}
+
+void LJ_FASTCALL recff_ffi_istype(jit_State *J, RecordFFData *rd)
+{
+ argv2ctype(J, J->base[0], &rd->argv[0]);
+ if (tref_iscdata(J->base[1])) {
+ argv2ctype(J, J->base[1], &rd->argv[1]);
+ J->postproc = LJ_POST_FIXBOOL;
+ J->base[0] = TREF_TRUE;
+ } else {
+ J->base[0] = TREF_FALSE;
+ }
+}
+
+void LJ_FASTCALL recff_ffi_abi(jit_State *J, RecordFFData *rd)
+{
+ if (tref_isstr(J->base[0])) {
+ /* Specialize to the ABI string to make the boolean result a constant. */
+ emitir(IRTG(IR_EQ, IRT_STR), J->base[0], lj_ir_kstr(J, strV(&rd->argv[0])));
+ J->postproc = LJ_POST_FIXBOOL;
+ J->base[0] = TREF_TRUE;
+ } else {
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ }
+}
+
+/* Record ffi.sizeof(), ffi.alignof(), ffi.offsetof(). */
+void LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd)
+{
+ CTypeID id = argv2ctype(J, J->base[0], &rd->argv[0]);
+ if (rd->data == FF_ffi_sizeof) {
+ CType *ct = lj_ctype_rawref(ctype_ctsG(J2G(J)), id);
+ if (ctype_isvltype(ct->info))
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ } else if (rd->data == FF_ffi_offsetof) { /* Specialize to the field name. */
+ if (!tref_isstr(J->base[1]))
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, strV(&rd->argv[1])));
+ rd->nres = 3; /* Just in case. */
+ }
+ J->postproc = LJ_POST_FIXCONST;
+ J->base[0] = J->base[1] = J->base[2] = TREF_NIL;
+}
+
+void LJ_FASTCALL recff_ffi_gc(jit_State *J, RecordFFData *rd)
+{
+ argv2cdata(J, J->base[0], &rd->argv[0]);
+ crec_finalizer(J, J->base[0], &rd->argv[1]);
+}
+
+/* -- Miscellaneous library functions ------------------------------------- */
+
+void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd)
+{
+ CTState *cts = ctype_ctsG(J2G(J));
+ CType *d, *ct = lj_ctype_rawref(cts, cdataV(&rd->argv[0])->ctypeid);
+ if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);
+ if (ctype_isnum(ct->info) || ctype_iscomplex(ct->info)) {
+ if (ctype_isinteger_or_bool(ct->info) && ct->size <= 4 &&
+ !(ct->size == 4 && (ct->info & CTF_UNSIGNED)))
+ d = ctype_get(cts, CTID_INT32);
+ else
+ d = ctype_get(cts, CTID_DOUBLE);
+ J->base[0] = crec_ct_tv(J, d, 0, J->base[0], &rd->argv[0]);
+ } else {
+ /* Specialize to the ctype that couldn't be converted. */
+ argv2cdata(J, J->base[0], &rd->argv[0]);
+ J->base[0] = TREF_NIL;
+ }
+}
+
+#undef IR
+#undef emitir
+#undef emitconv
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_crecord.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_crecord.h
new file mode 100644
index 0000000..8e0afd1
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_crecord.h
@@ -0,0 +1,31 @@
+/*
+** Trace recorder for C data operations.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_CRECORD_H
+#define _LJ_CRECORD_H
+
+#include "lj_obj.h"
+#include "lj_jit.h"
+#include "lj_ffrecord.h"
+
+#if LJ_HASJIT && LJ_HASFFI
+LJ_FUNC void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_cdata_call(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_clib_index(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_errno(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_copy(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_fill(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_typeof(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_istype(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_abi(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL recff_ffi_gc(jit_State *J, RecordFFData *rd);
+LJ_FUNC void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd);
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_ctype.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_ctype.c
new file mode 100644
index 0000000..9417500
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_ctype.c
@@ -0,0 +1,634 @@
+/*
+** C type management.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#include "lj_obj.h"
+
+#if LJ_HASFFI
+
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_ctype.h"
+#include "lj_ccallback.h"
+
+/* -- C type definitions -------------------------------------------------- */
+
+/* Predefined typedefs. */
+#define CTTDDEF(_) \
+ /* Vararg handling. */ \
+ _("va_list", P_VOID) \
+ _("__builtin_va_list", P_VOID) \
+ _("__gnuc_va_list", P_VOID) \
+ /* From stddef.h. */ \
+ _("ptrdiff_t", INT_PSZ) \
+ _("size_t", UINT_PSZ) \
+ _("wchar_t", WCHAR) \
+ /* Subset of stdint.h. */ \
+ _("int8_t", INT8) \
+ _("int16_t", INT16) \
+ _("int32_t", INT32) \
+ _("int64_t", INT64) \
+ _("uint8_t", UINT8) \
+ _("uint16_t", UINT16) \
+ _("uint32_t", UINT32) \
+ _("uint64_t", UINT64) \
+ _("intptr_t", INT_PSZ) \
+ _("uintptr_t", UINT_PSZ) \
+ /* End of typedef list. */
+
+/* Keywords (only the ones we actually care for). */
+#define CTKWDEF(_) \
+ /* Type specifiers. */ \
+ _("void", -1, CTOK_VOID) \
+ _("_Bool", 0, CTOK_BOOL) \
+ _("bool", 1, CTOK_BOOL) \
+ _("char", 1, CTOK_CHAR) \
+ _("int", 4, CTOK_INT) \
+ _("__int8", 1, CTOK_INT) \
+ _("__int16", 2, CTOK_INT) \
+ _("__int32", 4, CTOK_INT) \
+ _("__int64", 8, CTOK_INT) \
+ _("float", 4, CTOK_FP) \
+ _("double", 8, CTOK_FP) \
+ _("long", 0, CTOK_LONG) \
+ _("short", 0, CTOK_SHORT) \
+ _("_Complex", 0, CTOK_COMPLEX) \
+ _("complex", 0, CTOK_COMPLEX) \
+ _("__complex", 0, CTOK_COMPLEX) \
+ _("__complex__", 0, CTOK_COMPLEX) \
+ _("signed", 0, CTOK_SIGNED) \
+ _("__signed", 0, CTOK_SIGNED) \
+ _("__signed__", 0, CTOK_SIGNED) \
+ _("unsigned", 0, CTOK_UNSIGNED) \
+ /* Type qualifiers. */ \
+ _("const", 0, CTOK_CONST) \
+ _("__const", 0, CTOK_CONST) \
+ _("__const__", 0, CTOK_CONST) \
+ _("volatile", 0, CTOK_VOLATILE) \
+ _("__volatile", 0, CTOK_VOLATILE) \
+ _("__volatile__", 0, CTOK_VOLATILE) \
+ _("restrict", 0, CTOK_RESTRICT) \
+ _("__restrict", 0, CTOK_RESTRICT) \
+ _("__restrict__", 0, CTOK_RESTRICT) \
+ _("inline", 0, CTOK_INLINE) \
+ _("__inline", 0, CTOK_INLINE) \
+ _("__inline__", 0, CTOK_INLINE) \
+ /* Storage class specifiers. */ \
+ _("typedef", 0, CTOK_TYPEDEF) \
+ _("extern", 0, CTOK_EXTERN) \
+ _("static", 0, CTOK_STATIC) \
+ _("auto", 0, CTOK_AUTO) \
+ _("register", 0, CTOK_REGISTER) \
+ /* GCC Attributes. */ \
+ _("__extension__", 0, CTOK_EXTENSION) \
+ _("__attribute", 0, CTOK_ATTRIBUTE) \
+ _("__attribute__", 0, CTOK_ATTRIBUTE) \
+ _("asm", 0, CTOK_ASM) \
+ _("__asm", 0, CTOK_ASM) \
+ _("__asm__", 0, CTOK_ASM) \
+ /* MSVC Attributes. */ \
+ _("__declspec", 0, CTOK_DECLSPEC) \
+ _("__cdecl", CTCC_CDECL, CTOK_CCDECL) \
+ _("__thiscall", CTCC_THISCALL, CTOK_CCDECL) \
+ _("__fastcall", CTCC_FASTCALL, CTOK_CCDECL) \
+ _("__stdcall", CTCC_STDCALL, CTOK_CCDECL) \
+ _("__ptr32", 4, CTOK_PTRSZ) \
+ _("__ptr64", 8, CTOK_PTRSZ) \
+ /* Other type specifiers. */ \
+ _("struct", 0, CTOK_STRUCT) \
+ _("union", 0, CTOK_UNION) \
+ _("enum", 0, CTOK_ENUM) \
+ /* Operators. */ \
+ _("sizeof", 0, CTOK_SIZEOF) \
+ _("__alignof", 0, CTOK_ALIGNOF) \
+ _("__alignof__", 0, CTOK_ALIGNOF) \
+ /* End of keyword list. */
+
+/* Type info for predefined types. Size merged in. */
+static CTInfo lj_ctype_typeinfo[] = {
+#define CTTYINFODEF(id, sz, ct, info) CTINFO((ct),(((sz)&0x3fu)<<10)+(info)),
+#define CTTDINFODEF(name, id) CTINFO(CT_TYPEDEF, CTID_##id),
+#define CTKWINFODEF(name, sz, kw) CTINFO(CT_KW,(((sz)&0x3fu)<<10)+(kw)),
+CTTYDEF(CTTYINFODEF)
+CTTDDEF(CTTDINFODEF)
+CTKWDEF(CTKWINFODEF)
+#undef CTTYINFODEF
+#undef CTTDINFODEF
+#undef CTKWINFODEF
+ 0
+};
+
+/* Predefined type names collected in a single string. */
+static const char * const lj_ctype_typenames =
+#define CTTDNAMEDEF(name, id) name "\0"
+#define CTKWNAMEDEF(name, sz, cds) name "\0"
+CTTDDEF(CTTDNAMEDEF)
+CTKWDEF(CTKWNAMEDEF)
+#undef CTTDNAMEDEF
+#undef CTKWNAMEDEF
+;
+
+#define CTTYPEINFO_NUM (sizeof(lj_ctype_typeinfo)/sizeof(CTInfo)-1)
+#ifdef LUAJIT_CTYPE_CHECK_ANCHOR
+#define CTTYPETAB_MIN CTTYPEINFO_NUM
+#else
+#define CTTYPETAB_MIN 128
+#endif
+
+/* -- C type interning ---------------------------------------------------- */
+
+#define ct_hashtype(info, size) (hashrot(info, size) & CTHASH_MASK)
+#define ct_hashname(name) \
+ (hashrot(u32ptr(name), u32ptr(name) + HASH_BIAS) & CTHASH_MASK)
+
+/* Create new type element. */
+CTypeID lj_ctype_new(CTState *cts, CType **ctp)
+{
+ CTypeID id = cts->top;
+ CType *ct;
+ lua_assert(cts->L);
+ if (LJ_UNLIKELY(id >= cts->sizetab)) {
+ if (id >= CTID_MAX) lj_err_msg(cts->L, LJ_ERR_TABOV);
+#ifdef LUAJIT_CTYPE_CHECK_ANCHOR
+ ct = lj_mem_newvec(cts->L, id+1, CType);
+ memcpy(ct, cts->tab, id*sizeof(CType));
+ memset(cts->tab, 0, id*sizeof(CType));
+ lj_mem_freevec(cts->g, cts->tab, cts->sizetab, CType);
+ cts->tab = ct;
+ cts->sizetab = id+1;
+#else
+ lj_mem_growvec(cts->L, cts->tab, cts->sizetab, CTID_MAX, CType);
+#endif
+ }
+ cts->top = id+1;
+ *ctp = ct = &cts->tab[id];
+ ct->info = 0;
+ ct->size = 0;
+ ct->sib = 0;
+ ct->next = 0;
+ setgcrefnull(ct->name);
+ return id;
+}
+
+/* Intern a type element. */
+CTypeID lj_ctype_intern(CTState *cts, CTInfo info, CTSize size)
+{
+ uint32_t h = ct_hashtype(info, size);
+ CTypeID id = cts->hash[h];
+ lua_assert(cts->L);
+ while (id) {
+ CType *ct = ctype_get(cts, id);
+ if (ct->info == info && ct->size == size)
+ return id;
+ id = ct->next;
+ }
+ id = cts->top;
+ if (LJ_UNLIKELY(id >= cts->sizetab)) {
+ if (id >= CTID_MAX) lj_err_msg(cts->L, LJ_ERR_TABOV);
+ lj_mem_growvec(cts->L, cts->tab, cts->sizetab, CTID_MAX, CType);
+ }
+ cts->top = id+1;
+ cts->tab[id].info = info;
+ cts->tab[id].size = size;
+ cts->tab[id].sib = 0;
+ cts->tab[id].next = cts->hash[h];
+ setgcrefnull(cts->tab[id].name);
+ cts->hash[h] = (CTypeID1)id;
+ return id;
+}
+
+/* Add type element to hash table. */
+static void ctype_addtype(CTState *cts, CType *ct, CTypeID id)
+{
+ uint32_t h = ct_hashtype(ct->info, ct->size);
+ ct->next = cts->hash[h];
+ cts->hash[h] = (CTypeID1)id;
+}
+
+/* Add named element to hash table. */
+void lj_ctype_addname(CTState *cts, CType *ct, CTypeID id)
+{
+ uint32_t h = ct_hashname(gcref(ct->name));
+ ct->next = cts->hash[h];
+ cts->hash[h] = (CTypeID1)id;
+}
+
+/* Get a C type by name, matching the type mask. */
+CTypeID lj_ctype_getname(CTState *cts, CType **ctp, GCstr *name, uint32_t tmask)
+{
+ CTypeID id = cts->hash[ct_hashname(name)];
+ while (id) {
+ CType *ct = ctype_get(cts, id);
+ if (gcref(ct->name) == obj2gco(name) &&
+ ((tmask >> ctype_type(ct->info)) & 1)) {
+ *ctp = ct;
+ return id;
+ }
+ id = ct->next;
+ }
+ *ctp = &cts->tab[0]; /* Simplify caller logic. ctype_get() would assert. */
+ return 0;
+}
+
+/* Get a struct/union/enum/function field by name. */
+CType *lj_ctype_getfieldq(CTState *cts, CType *ct, GCstr *name, CTSize *ofs,
+ CTInfo *qual)
+{
+ while (ct->sib) {
+ ct = ctype_get(cts, ct->sib);
+ if (gcref(ct->name) == obj2gco(name)) {
+ *ofs = ct->size;
+ return ct;
+ }
+ if (ctype_isxattrib(ct->info, CTA_SUBTYPE)) {
+ CType *fct, *cct = ctype_child(cts, ct);
+ CTInfo q = 0;
+ while (ctype_isattrib(cct->info)) {
+ if (ctype_attrib(cct->info) == CTA_QUAL) q |= cct->size;
+ cct = ctype_child(cts, cct);
+ }
+ fct = lj_ctype_getfieldq(cts, cct, name, ofs, qual);
+ if (fct) {
+ if (qual) *qual |= q;
+ *ofs += ct->size;
+ return fct;
+ }
+ }
+ }
+ return NULL; /* Not found. */
+}
+
+/* -- C type information -------------------------------------------------- */
+
+/* Follow references and get raw type for a C type ID. */
+CType *lj_ctype_rawref(CTState *cts, CTypeID id)
+{
+ CType *ct = ctype_get(cts, id);
+ while (ctype_isattrib(ct->info) || ctype_isref(ct->info))
+ ct = ctype_child(cts, ct);
+ return ct;
+}
+
+/* Get size for a C type ID. Does NOT support VLA/VLS. */
+CTSize lj_ctype_size(CTState *cts, CTypeID id)
+{
+ CType *ct = ctype_raw(cts, id);
+ return ctype_hassize(ct->info) ? ct->size : CTSIZE_INVALID;
+}
+
+/* Get size for a variable-length C type. Does NOT support other C types. */
+CTSize lj_ctype_vlsize(CTState *cts, CType *ct, CTSize nelem)
+{
+ uint64_t xsz = 0;
+ if (ctype_isstruct(ct->info)) {
+ CTypeID arrid = 0, fid = ct->sib;
+ xsz = ct->size; /* Add the struct size. */
+ while (fid) {
+ CType *ctf = ctype_get(cts, fid);
+ if (ctype_type(ctf->info) == CT_FIELD)
+ arrid = ctype_cid(ctf->info); /* Remember last field of VLS. */
+ fid = ctf->sib;
+ }
+ ct = ctype_raw(cts, arrid);
+ }
+ lua_assert(ctype_isvlarray(ct->info)); /* Must be a VLA. */
+ ct = ctype_rawchild(cts, ct); /* Get array element. */
+ lua_assert(ctype_hassize(ct->info));
+ /* Calculate actual size of VLA and check for overflow. */
+ xsz += (uint64_t)ct->size * nelem;
+ return xsz < 0x80000000u ? (CTSize)xsz : CTSIZE_INVALID;
+}
+
+/* Get type, qualifiers, size and alignment for a C type ID. */
+CTInfo lj_ctype_info(CTState *cts, CTypeID id, CTSize *szp)
+{
+ CTInfo qual = 0;
+ CType *ct = ctype_get(cts, id);
+ for (;;) {
+ CTInfo info = ct->info;
+ if (ctype_isenum(info)) {
+ /* Follow child. Need to look at its attributes, too. */
+ } else if (ctype_isattrib(info)) {
+ if (ctype_isxattrib(info, CTA_QUAL))
+ qual |= ct->size;
+ else if (ctype_isxattrib(info, CTA_ALIGN) && !(qual & CTFP_ALIGNED))
+ qual |= CTFP_ALIGNED + CTALIGN(ct->size);
+ } else {
+ if (!(qual & CTFP_ALIGNED)) qual |= (info & CTF_ALIGN);
+ qual |= (info & ~(CTF_ALIGN|CTMASK_CID));
+ lua_assert(ctype_hassize(info) || ctype_isfunc(info));
+ *szp = ctype_isfunc(info) ? CTSIZE_INVALID : ct->size;
+ break;
+ }
+ ct = ctype_get(cts, ctype_cid(info));
+ }
+ return qual;
+}
+
+/* Get ctype metamethod. */
+cTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm)
+{
+ CType *ct = ctype_get(cts, id);
+ cTValue *tv;
+ while (ctype_isattrib(ct->info) || ctype_isref(ct->info)) {
+ id = ctype_cid(ct->info);
+ ct = ctype_get(cts, id);
+ }
+ if (ctype_isptr(ct->info) &&
+ ctype_isfunc(ctype_get(cts, ctype_cid(ct->info))->info))
+ tv = lj_tab_getstr(cts->miscmap, &cts->g->strempty);
+ else
+ tv = lj_tab_getinth(cts->miscmap, -(int32_t)id);
+ if (tv && tvistab(tv) &&
+ (tv = lj_tab_getstr(tabV(tv), mmname_str(cts->g, mm))) && !tvisnil(tv))
+ return tv;
+ return NULL;
+}
+
+/* -- C type representation ----------------------------------------------- */
+
+/* Fixed max. length of a C type representation. */
+#define CTREPR_MAX 512
+
+typedef struct CTRepr {
+ char *pb, *pe;
+ CTState *cts;
+ lua_State *L;
+ int needsp;
+ int ok;
+ char buf[CTREPR_MAX];
+} CTRepr;
+
+/* Prepend string. */
+static void ctype_prepstr(CTRepr *ctr, const char *str, MSize len)
+{
+ char *p = ctr->pb;
+ if (ctr->buf + len+1 > p) { ctr->ok = 0; return; }
+ if (ctr->needsp) *--p = ' ';
+ ctr->needsp = 1;
+ p -= len;
+ while (len-- > 0) p[len] = str[len];
+ ctr->pb = p;
+}
+
+#define ctype_preplit(ctr, str) ctype_prepstr((ctr), "" str, sizeof(str)-1)
+
+/* Prepend char. */
+static void ctype_prepc(CTRepr *ctr, int c)
+{
+ if (ctr->buf >= ctr->pb) { ctr->ok = 0; return; }
+ *--ctr->pb = c;
+}
+
+/* Prepend number. */
+static void ctype_prepnum(CTRepr *ctr, uint32_t n)
+{
+ char *p = ctr->pb;
+ if (ctr->buf + 10+1 > p) { ctr->ok = 0; return; }
+ do { *--p = (char)('0' + n % 10); } while (n /= 10);
+ ctr->pb = p;
+ ctr->needsp = 0;
+}
+
+/* Append char. */
+static void ctype_appc(CTRepr *ctr, int c)
+{
+ if (ctr->pe >= ctr->buf + CTREPR_MAX) { ctr->ok = 0; return; }
+ *ctr->pe++ = c;
+}
+
+/* Append number. */
+static void ctype_appnum(CTRepr *ctr, uint32_t n)
+{
+ char buf[10];
+ char *p = buf+sizeof(buf);
+ char *q = ctr->pe;
+ if (q > ctr->buf + CTREPR_MAX - 10) { ctr->ok = 0; return; }
+ do { *--p = (char)('0' + n % 10); } while (n /= 10);
+ do { *q++ = *p++; } while (p < buf+sizeof(buf));
+ ctr->pe = q;
+}
+
+/* Prepend qualifiers. */
+static void ctype_prepqual(CTRepr *ctr, CTInfo info)
+{
+ if ((info & CTF_VOLATILE)) ctype_preplit(ctr, "volatile");
+ if ((info & CTF_CONST)) ctype_preplit(ctr, "const");
+}
+
+/* Prepend named type. */
+static void ctype_preptype(CTRepr *ctr, CType *ct, CTInfo qual, const char *t)
+{
+ if (gcref(ct->name)) {
+ GCstr *str = gco2str(gcref(ct->name));
+ ctype_prepstr(ctr, strdata(str), str->len);
+ } else {
+ if (ctr->needsp) ctype_prepc(ctr, ' ');
+ ctype_prepnum(ctr, ctype_typeid(ctr->cts, ct));
+ ctr->needsp = 1;
+ }
+ ctype_prepstr(ctr, t, (MSize)strlen(t));
+ ctype_prepqual(ctr, qual);
+}
+
+static void ctype_repr(CTRepr *ctr, CTypeID id)
+{
+ CType *ct = ctype_get(ctr->cts, id);
+ CTInfo qual = 0;
+ int ptrto = 0;
+ for (;;) {
+ CTInfo info = ct->info;
+ CTSize size = ct->size;
+ switch (ctype_type(info)) {
+ case CT_NUM:
+ if ((info & CTF_BOOL)) {
+ ctype_preplit(ctr, "bool");
+ } else if ((info & CTF_FP)) {
+ if (size == sizeof(double)) ctype_preplit(ctr, "double");
+ else if (size == sizeof(float)) ctype_preplit(ctr, "float");
+ else ctype_preplit(ctr, "long double");
+ } else if (size == 1) {
+ if (!((info ^ CTF_UCHAR) & CTF_UNSIGNED)) ctype_preplit(ctr, "char");
+ else if (CTF_UCHAR) ctype_preplit(ctr, "signed char");
+ else ctype_preplit(ctr, "unsigned char");
+ } else if (size < 8) {
+ if (size == 4) ctype_preplit(ctr, "int");
+ else ctype_preplit(ctr, "short");
+ if ((info & CTF_UNSIGNED)) ctype_preplit(ctr, "unsigned");
+ } else {
+ ctype_preplit(ctr, "_t");
+ ctype_prepnum(ctr, size*8);
+ ctype_preplit(ctr, "int");
+ if ((info & CTF_UNSIGNED)) ctype_prepc(ctr, 'u');
+ }
+ ctype_prepqual(ctr, (qual|info));
+ return;
+ case CT_VOID:
+ ctype_preplit(ctr, "void");
+ ctype_prepqual(ctr, (qual|info));
+ return;
+ case CT_STRUCT:
+ ctype_preptype(ctr, ct, qual, (info & CTF_UNION) ? "union" : "struct");
+ return;
+ case CT_ENUM:
+ if (id == CTID_CTYPEID) {
+ ctype_preplit(ctr, "ctype");
+ return;
+ }
+ ctype_preptype(ctr, ct, qual, "enum");
+ return;
+ case CT_ATTRIB:
+ if (ctype_attrib(info) == CTA_QUAL) qual |= size;
+ break;
+ case CT_PTR:
+ if ((info & CTF_REF)) {
+ ctype_prepc(ctr, '&');
+ } else {
+ ctype_prepqual(ctr, (qual|info));
+ if (LJ_64 && size == 4) ctype_preplit(ctr, "__ptr32");
+ ctype_prepc(ctr, '*');
+ }
+ qual = 0;
+ ptrto = 1;
+ ctr->needsp = 1;
+ break;
+ case CT_ARRAY:
+ if (ctype_isrefarray(info)) {
+ ctr->needsp = 1;
+ if (ptrto) { ptrto = 0; ctype_prepc(ctr, '('); ctype_appc(ctr, ')'); }
+ ctype_appc(ctr, '[');
+ if (size != CTSIZE_INVALID) {
+ CTSize csize = ctype_child(ctr->cts, ct)->size;
+ ctype_appnum(ctr, csize ? size/csize : 0);
+ } else if ((info & CTF_VLA)) {
+ ctype_appc(ctr, '?');
+ }
+ ctype_appc(ctr, ']');
+ } else if ((info & CTF_COMPLEX)) {
+ if (size == 2*sizeof(float)) ctype_preplit(ctr, "float");
+ ctype_preplit(ctr, "complex");
+ return;
+ } else {
+ ctype_preplit(ctr, ")))");
+ ctype_prepnum(ctr, size);
+ ctype_preplit(ctr, "__attribute__((vector_size(");
+ }
+ break;
+ case CT_FUNC:
+ ctr->needsp = 1;
+ if (ptrto) { ptrto = 0; ctype_prepc(ctr, '('); ctype_appc(ctr, ')'); }
+ ctype_appc(ctr, '(');
+ ctype_appc(ctr, ')');
+ break;
+ default:
+ lua_assert(0);
+ break;
+ }
+ ct = ctype_get(ctr->cts, ctype_cid(info));
+ }
+}
+
+/* Return a printable representation of a C type. */
+GCstr *lj_ctype_repr(lua_State *L, CTypeID id, GCstr *name)
+{
+ global_State *g = G(L);
+ CTRepr ctr;
+ ctr.pb = ctr.pe = &ctr.buf[CTREPR_MAX/2];
+ ctr.cts = ctype_ctsG(g);
+ ctr.L = L;
+ ctr.ok = 1;
+ ctr.needsp = 0;
+ if (name) ctype_prepstr(&ctr, strdata(name), name->len);
+ ctype_repr(&ctr, id);
+ if (LJ_UNLIKELY(!ctr.ok)) return lj_str_newlit(L, "?");
+ return lj_str_new(L, ctr.pb, ctr.pe - ctr.pb);
+}
+
+/* Convert int64_t/uint64_t to string with 'LL' or 'ULL' suffix. */
+GCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned)
+{
+ char buf[1+20+3];
+ char *p = buf+sizeof(buf);
+ int sign = 0;
+ *--p = 'L'; *--p = 'L';
+ if (isunsigned) {
+ *--p = 'U';
+ } else if ((int64_t)n < 0) {
+ n = (uint64_t)-(int64_t)n;
+ sign = 1;
+ }
+ do { *--p = (char)('0' + n % 10); } while (n /= 10);
+ if (sign) *--p = '-';
+ return lj_str_new(L, p, (size_t)(buf+sizeof(buf)-p));
+}
+
+/* Convert complex to string with 'i' or 'I' suffix. */
+GCstr *lj_ctype_repr_complex(lua_State *L, void *sp, CTSize size)
+{
+ char buf[2*LJ_STR_NUMBUF+2+1];
+ TValue re, im;
+ size_t len;
+ if (size == 2*sizeof(double)) {
+ re.n = *(double *)sp; im.n = ((double *)sp)[1];
+ } else {
+ re.n = (double)*(float *)sp; im.n = (double)((float *)sp)[1];
+ }
+ len = lj_str_bufnum(buf, &re);
+ if (!(im.u32.hi & 0x80000000u) || im.n != im.n) buf[len++] = '+';
+ len += lj_str_bufnum(buf+len, &im);
+ buf[len] = buf[len-1] >= 'a' ? 'I' : 'i';
+ return lj_str_new(L, buf, len+1);
+}
+
+/* -- C type state -------------------------------------------------------- */
+
+/* Initialize C type table and state. */
+CTState *lj_ctype_init(lua_State *L)
+{
+ CTState *cts = lj_mem_newt(L, sizeof(CTState), CTState);
+ CType *ct = lj_mem_newvec(L, CTTYPETAB_MIN, CType);
+ const char *name = lj_ctype_typenames;
+ CTypeID id;
+ memset(cts, 0, sizeof(CTState));
+ cts->tab = ct;
+ cts->sizetab = CTTYPETAB_MIN;
+ cts->top = CTTYPEINFO_NUM;
+ cts->L = NULL;
+ cts->g = G(L);
+ for (id = 0; id < CTTYPEINFO_NUM; id++, ct++) {
+ CTInfo info = lj_ctype_typeinfo[id];
+ ct->size = (CTSize)((int32_t)(info << 16) >> 26);
+ ct->info = info & 0xffff03ffu;
+ ct->sib = 0;
+ if (ctype_type(info) == CT_KW || ctype_istypedef(info)) {
+ size_t len = strlen(name);
+ GCstr *str = lj_str_new(L, name, len);
+ ctype_setname(ct, str);
+ name += len+1;
+ lj_ctype_addname(cts, ct, id);
+ } else {
+ setgcrefnull(ct->name);
+ ct->next = 0;
+ if (!ctype_isenum(info)) ctype_addtype(cts, ct, id);
+ }
+ }
+ setmref(G(L)->ctype_state, cts);
+ return cts;
+}
+
+/* Free C type table and state. */
+void lj_ctype_freestate(global_State *g)
+{
+ CTState *cts = ctype_ctsG(g);
+ if (cts) {
+ lj_ccallback_mcode_free(cts);
+ lj_mem_freevec(g, cts->tab, cts->sizetab, CType);
+ lj_mem_freevec(g, cts->cb.cbid, cts->cb.sizeid, CTypeID1);
+ lj_mem_freet(g, cts);
+ }
+}
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_ctype.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_ctype.h
new file mode 100644
index 0000000..2aefd3b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_ctype.h
@@ -0,0 +1,461 @@
+/*
+** C type management.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_CTYPE_H
+#define _LJ_CTYPE_H
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+
+#if LJ_HASFFI
+
+/* -- C type definitions -------------------------------------------------- */
+
+/* C type numbers. Highest 4 bits of C type info. ORDER CT. */
+enum {
+ /* Externally visible types. */
+ CT_NUM, /* Integer or floating-point numbers. */
+ CT_STRUCT, /* Struct or union. */
+ CT_PTR, /* Pointer or reference. */
+ CT_ARRAY, /* Array or complex type. */
+ CT_MAYCONVERT = CT_ARRAY,
+ CT_VOID, /* Void type. */
+ CT_ENUM, /* Enumeration. */
+ CT_HASSIZE = CT_ENUM, /* Last type where ct->size holds the actual size. */
+ CT_FUNC, /* Function. */
+ CT_TYPEDEF, /* Typedef. */
+ CT_ATTRIB, /* Miscellaneous attributes. */
+ /* Internal element types. */
+ CT_FIELD, /* Struct/union field or function parameter. */
+ CT_BITFIELD, /* Struct/union bitfield. */
+ CT_CONSTVAL, /* Constant value. */
+ CT_EXTERN, /* External reference. */
+ CT_KW /* Keyword. */
+};
+
+LJ_STATIC_ASSERT(((int)CT_PTR & (int)CT_ARRAY) == CT_PTR);
+LJ_STATIC_ASSERT(((int)CT_STRUCT & (int)CT_ARRAY) == CT_STRUCT);
+
+/*
+** ---------- info ------------
+** |type flags... A cid | size | sib | next | name |
+** +----------------------------+--------+-------+-------+-------+--
+** |NUM BFcvUL.. A | size | | type | |
+** |STRUCT ..cvU..V A | size | field | name? | name? |
+** |PTR ..cvR... A cid | size | | type | |
+** |ARRAY VCcv...V A cid | size | | type | |
+** |VOID ..cv.... A | size | | type | |
+** |ENUM A cid | size | const | name? | name? |
+** |FUNC ....VS.. cc cid | nargs | field | name? | name? |
+** |TYPEDEF cid | | | name | name |
+** |ATTRIB attrnum cid | attr | sib? | type? | |
+** |FIELD cid | offset | field | | name? |
+** |BITFIELD B.cvU csz bsz pos | offset | field | | name? |
+** |CONSTVAL c cid | value | const | name | name |
+** |EXTERN cid | | sib? | name | name |
+** |KW tok | size | | name | name |
+** +----------------------------+--------+-------+-------+-------+--
+** ^^ ^^--- bits used for C type conversion dispatch
+*/
+
+/* C type info flags. TFFArrrr */
+#define CTF_BOOL 0x08000000u /* Boolean: NUM, BITFIELD. */
+#define CTF_FP 0x04000000u /* Floating-point: NUM. */
+#define CTF_CONST 0x02000000u /* Const qualifier. */
+#define CTF_VOLATILE 0x01000000u /* Volatile qualifier. */
+#define CTF_UNSIGNED 0x00800000u /* Unsigned: NUM, BITFIELD. */
+#define CTF_LONG 0x00400000u /* Long: NUM. */
+#define CTF_VLA 0x00100000u /* Variable-length: ARRAY, STRUCT. */
+#define CTF_REF 0x00800000u /* Reference: PTR. */
+#define CTF_VECTOR 0x08000000u /* Vector: ARRAY. */
+#define CTF_COMPLEX 0x04000000u /* Complex: ARRAY. */
+#define CTF_UNION 0x00800000u /* Union: STRUCT. */
+#define CTF_VARARG 0x00800000u /* Vararg: FUNC. */
+#define CTF_SSEREGPARM 0x00400000u /* SSE register parameters: FUNC. */
+
+#define CTF_QUAL (CTF_CONST|CTF_VOLATILE)
+#define CTF_ALIGN (CTMASK_ALIGN<<CTSHIFT_ALIGN)
+#define CTF_UCHAR ((char)-1 > 0 ? CTF_UNSIGNED : 0)
+
+/* Flags used in parser. .F.Ammvf cp->attr */
+#define CTFP_ALIGNED 0x00000001u /* cp->attr + ALIGN */
+#define CTFP_PACKED 0x00000002u /* cp->attr */
+/* ...C...f cp->fattr */
+#define CTFP_CCONV 0x00000001u /* cp->fattr + CCONV/[SSE]REGPARM */
+
+/* C type info bitfields. */
+#define CTMASK_CID 0x0000ffffu /* Max. 65536 type IDs. */
+#define CTMASK_NUM 0xf0000000u /* Max. 16 type numbers. */
+#define CTSHIFT_NUM 28
+#define CTMASK_ALIGN 15 /* Max. alignment is 2^15. */
+#define CTSHIFT_ALIGN 16
+#define CTMASK_ATTRIB 255 /* Max. 256 attributes. */
+#define CTSHIFT_ATTRIB 16
+#define CTMASK_CCONV 3 /* Max. 4 calling conventions. */
+#define CTSHIFT_CCONV 16
+#define CTMASK_REGPARM 3 /* Max. 0-3 regparms. */
+#define CTSHIFT_REGPARM 18
+/* Bitfields only used in parser. */
+#define CTMASK_VSIZEP 15 /* Max. vector size is 2^15. */
+#define CTSHIFT_VSIZEP 4
+#define CTMASK_MSIZEP 255 /* Max. type size (via mode) is 128. */
+#define CTSHIFT_MSIZEP 8
+
+/* Info bits for BITFIELD. Max. size of bitfield is 64 bits. */
+#define CTBSZ_MAX 32 /* Max. size of bitfield is 32 bit. */
+#define CTBSZ_FIELD 127 /* Temp. marker for regular field. */
+#define CTMASK_BITPOS 127
+#define CTMASK_BITBSZ 127
+#define CTMASK_BITCSZ 127
+#define CTSHIFT_BITPOS 0
+#define CTSHIFT_BITBSZ 8
+#define CTSHIFT_BITCSZ 16
+
+#define CTF_INSERT(info, field, val) \
+ info = (info & ~(CTMASK_##field<<CTSHIFT_##field)) | \
+ (((CTSize)(val) & CTMASK_##field) << CTSHIFT_##field)
+
+/* Calling conventions. ORDER CC */
+enum { CTCC_CDECL, CTCC_THISCALL, CTCC_FASTCALL, CTCC_STDCALL };
+
+/* Attribute numbers. */
+enum {
+ CTA_NONE, /* Ignored attribute. Must be zero. */
+ CTA_QUAL, /* Unmerged qualifiers. */
+ CTA_ALIGN, /* Alignment override. */
+ CTA_SUBTYPE, /* Transparent sub-type. */
+ CTA_REDIR, /* Redirected symbol name. */
+ CTA_BAD, /* To catch bad IDs. */
+ CTA__MAX
+};
+
+/* Special sizes. */
+#define CTSIZE_INVALID 0xffffffffu
+
+typedef uint32_t CTInfo; /* Type info. */
+typedef uint32_t CTSize; /* Type size. */
+typedef uint32_t CTypeID; /* Type ID. */
+typedef uint16_t CTypeID1; /* Minimum-sized type ID. */
+
+/* C type table element. */
+typedef struct CType {
+ CTInfo info; /* Type info. */
+ CTSize size; /* Type size or other info. */
+ CTypeID1 sib; /* Sibling element. */
+ CTypeID1 next; /* Next element in hash chain. */
+ GCRef name; /* Element name (GCstr). */
+} CType;
+
+#define CTHASH_SIZE 128 /* Number of hash anchors. */
+#define CTHASH_MASK (CTHASH_SIZE-1)
+
+/* Simplify target-specific configuration. Checked in lj_ccall.h. */
+#define CCALL_MAX_GPR 8
+#define CCALL_MAX_FPR 8
+
+typedef LJ_ALIGN(8) union FPRCBArg { double d; float f[2]; } FPRCBArg;
+
+/* C callback state. Defined here, to avoid dragging in lj_ccall.h. */
+
+typedef LJ_ALIGN(8) struct CCallback {
+ FPRCBArg fpr[CCALL_MAX_FPR]; /* Arguments/results in FPRs. */
+ intptr_t gpr[CCALL_MAX_GPR]; /* Arguments/results in GPRs. */
+ intptr_t *stack; /* Pointer to arguments on stack. */
+ void *mcode; /* Machine code for callback func. pointers. */
+ CTypeID1 *cbid; /* Callback type table. */
+ MSize sizeid; /* Size of callback type table. */
+ MSize topid; /* Highest unused callback type table slot. */
+ MSize slot; /* Current callback slot. */
+} CCallback;
+
+/* C type state. */
+typedef struct CTState {
+ CType *tab; /* C type table. */
+ CTypeID top; /* Current top of C type table. */
+ MSize sizetab; /* Size of C type table. */
+ lua_State *L; /* Lua state (needed for errors and allocations). */
+ global_State *g; /* Global state. */
+ GCtab *finalizer; /* Map of cdata to finalizer. */
+ GCtab *miscmap; /* Map of -CTypeID to metatable and cb slot to func. */
+ CCallback cb; /* Temporary callback state. */
+ CTypeID1 hash[CTHASH_SIZE]; /* Hash anchors for C type table. */
+} CTState;
+
+#define CTINFO(ct, flags) (((CTInfo)(ct) << CTSHIFT_NUM) + (flags))
+#define CTALIGN(al) ((CTSize)(al) << CTSHIFT_ALIGN)
+#define CTATTRIB(at) ((CTInfo)(at) << CTSHIFT_ATTRIB)
+
+#define ctype_type(info) ((info) >> CTSHIFT_NUM)
+#define ctype_cid(info) ((CTypeID)((info) & CTMASK_CID))
+#define ctype_align(info) (((info) >> CTSHIFT_ALIGN) & CTMASK_ALIGN)
+#define ctype_attrib(info) (((info) >> CTSHIFT_ATTRIB) & CTMASK_ATTRIB)
+#define ctype_bitpos(info) (((info) >> CTSHIFT_BITPOS) & CTMASK_BITPOS)
+#define ctype_bitbsz(info) (((info) >> CTSHIFT_BITBSZ) & CTMASK_BITBSZ)
+#define ctype_bitcsz(info) (((info) >> CTSHIFT_BITCSZ) & CTMASK_BITCSZ)
+#define ctype_vsizeP(info) (((info) >> CTSHIFT_VSIZEP) & CTMASK_VSIZEP)
+#define ctype_msizeP(info) (((info) >> CTSHIFT_MSIZEP) & CTMASK_MSIZEP)
+#define ctype_cconv(info) (((info) >> CTSHIFT_CCONV) & CTMASK_CCONV)
+
+/* Simple type checks. */
+#define ctype_isnum(info) (ctype_type((info)) == CT_NUM)
+#define ctype_isvoid(info) (ctype_type((info)) == CT_VOID)
+#define ctype_isptr(info) (ctype_type((info)) == CT_PTR)
+#define ctype_isarray(info) (ctype_type((info)) == CT_ARRAY)
+#define ctype_isstruct(info) (ctype_type((info)) == CT_STRUCT)
+#define ctype_isfunc(info) (ctype_type((info)) == CT_FUNC)
+#define ctype_isenum(info) (ctype_type((info)) == CT_ENUM)
+#define ctype_istypedef(info) (ctype_type((info)) == CT_TYPEDEF)
+#define ctype_isattrib(info) (ctype_type((info)) == CT_ATTRIB)
+#define ctype_isfield(info) (ctype_type((info)) == CT_FIELD)
+#define ctype_isbitfield(info) (ctype_type((info)) == CT_BITFIELD)
+#define ctype_isconstval(info) (ctype_type((info)) == CT_CONSTVAL)
+#define ctype_isextern(info) (ctype_type((info)) == CT_EXTERN)
+#define ctype_hassize(info) (ctype_type((info)) <= CT_HASSIZE)
+
+/* Combined type and flag checks. */
+#define ctype_isinteger(info) \
+ (((info) & (CTMASK_NUM|CTF_BOOL|CTF_FP)) == CTINFO(CT_NUM, 0))
+#define ctype_isinteger_or_bool(info) \
+ (((info) & (CTMASK_NUM|CTF_FP)) == CTINFO(CT_NUM, 0))
+#define ctype_isbool(info) \
+ (((info) & (CTMASK_NUM|CTF_BOOL)) == CTINFO(CT_NUM, CTF_BOOL))
+#define ctype_isfp(info) \
+ (((info) & (CTMASK_NUM|CTF_FP)) == CTINFO(CT_NUM, CTF_FP))
+
+#define ctype_ispointer(info) \
+ ((ctype_type(info) >> 1) == (CT_PTR >> 1)) /* Pointer or array. */
+#define ctype_isref(info) \
+ (((info) & (CTMASK_NUM|CTF_REF)) == CTINFO(CT_PTR, CTF_REF))
+
+#define ctype_isrefarray(info) \
+ (((info) & (CTMASK_NUM|CTF_VECTOR|CTF_COMPLEX)) == CTINFO(CT_ARRAY, 0))
+#define ctype_isvector(info) \
+ (((info) & (CTMASK_NUM|CTF_VECTOR)) == CTINFO(CT_ARRAY, CTF_VECTOR))
+#define ctype_iscomplex(info) \
+ (((info) & (CTMASK_NUM|CTF_COMPLEX)) == CTINFO(CT_ARRAY, CTF_COMPLEX))
+
+#define ctype_isvltype(info) \
+ (((info) & ((CTMASK_NUM|CTF_VLA) - (2u<<CTSHIFT_NUM))) == \
+ CTINFO(CT_STRUCT, CTF_VLA)) /* VL array or VL struct. */
+#define ctype_isvlarray(info) \
+ (((info) & (CTMASK_NUM|CTF_VLA)) == CTINFO(CT_ARRAY, CTF_VLA))
+
+#define ctype_isxattrib(info, at) \
+ (((info) & (CTMASK_NUM|CTATTRIB(CTMASK_ATTRIB))) == \
+ CTINFO(CT_ATTRIB, CTATTRIB(at)))
+
+/* Target-dependent sizes and alignments. */
+#if LJ_64
+#define CTSIZE_PTR 8
+#define CTALIGN_PTR CTALIGN(3)
+#else
+#define CTSIZE_PTR 4
+#define CTALIGN_PTR CTALIGN(2)
+#endif
+
+#define CTINFO_REF(ref) \
+ CTINFO(CT_PTR, (CTF_CONST|CTF_REF|CTALIGN_PTR) + (ref))
+
+#define CT_MEMALIGN 3 /* Alignment guaranteed by memory allocator. */
+
+/* -- Predefined types ---------------------------------------------------- */
+
+/* Target-dependent types. */
+#if LJ_TARGET_PPC || LJ_TARGET_PPCSPE
+#define CTTYDEFP(_) \
+ _(LINT32, 4, CT_NUM, CTF_LONG|CTALIGN(2))
+#else
+#define CTTYDEFP(_)
+#endif
+
+/* Common types. */
+#define CTTYDEF(_) \
+ _(NONE, 0, CT_ATTRIB, CTATTRIB(CTA_BAD)) \
+ _(VOID, -1, CT_VOID, CTALIGN(0)) \
+ _(CVOID, -1, CT_VOID, CTF_CONST|CTALIGN(0)) \
+ _(BOOL, 1, CT_NUM, CTF_BOOL|CTF_UNSIGNED|CTALIGN(0)) \
+ _(CCHAR, 1, CT_NUM, CTF_CONST|CTF_UCHAR|CTALIGN(0)) \
+ _(INT8, 1, CT_NUM, CTALIGN(0)) \
+ _(UINT8, 1, CT_NUM, CTF_UNSIGNED|CTALIGN(0)) \
+ _(INT16, 2, CT_NUM, CTALIGN(1)) \
+ _(UINT16, 2, CT_NUM, CTF_UNSIGNED|CTALIGN(1)) \
+ _(INT32, 4, CT_NUM, CTALIGN(2)) \
+ _(UINT32, 4, CT_NUM, CTF_UNSIGNED|CTALIGN(2)) \
+ _(INT64, 8, CT_NUM, CTF_LONG|CTALIGN(3)) \
+ _(UINT64, 8, CT_NUM, CTF_UNSIGNED|CTF_LONG|CTALIGN(3)) \
+ _(FLOAT, 4, CT_NUM, CTF_FP|CTALIGN(2)) \
+ _(DOUBLE, 8, CT_NUM, CTF_FP|CTALIGN(3)) \
+ _(COMPLEX_FLOAT, 8, CT_ARRAY, CTF_COMPLEX|CTALIGN(2)|CTID_FLOAT) \
+ _(COMPLEX_DOUBLE, 16, CT_ARRAY, CTF_COMPLEX|CTALIGN(3)|CTID_DOUBLE) \
+ _(P_VOID, CTSIZE_PTR, CT_PTR, CTALIGN_PTR|CTID_VOID) \
+ _(P_CVOID, CTSIZE_PTR, CT_PTR, CTALIGN_PTR|CTID_CVOID) \
+ _(P_CCHAR, CTSIZE_PTR, CT_PTR, CTALIGN_PTR|CTID_CCHAR) \
+ _(A_CCHAR, -1, CT_ARRAY, CTF_CONST|CTALIGN(0)|CTID_CCHAR) \
+ _(CTYPEID, 4, CT_ENUM, CTALIGN(2)|CTID_INT32) \
+ CTTYDEFP(_) \
+ /* End of type list. */
+
+/* Public predefined type IDs. */
+enum {
+#define CTTYIDDEF(id, sz, ct, info) CTID_##id,
+CTTYDEF(CTTYIDDEF)
+#undef CTTYIDDEF
+ /* Predefined typedefs and keywords follow. */
+ CTID_MAX = 65536
+};
+
+/* Target-dependent type IDs. */
+#if LJ_64
+#define CTID_INT_PSZ CTID_INT64
+#define CTID_UINT_PSZ CTID_UINT64
+#else
+#define CTID_INT_PSZ CTID_INT32
+#define CTID_UINT_PSZ CTID_UINT32
+#endif
+
+#if LJ_ABI_WIN
+#define CTID_WCHAR CTID_UINT16
+#elif LJ_TARGET_PPC
+#define CTID_WCHAR CTID_LINT32
+#else
+#define CTID_WCHAR CTID_INT32
+#endif
+
+/* -- C tokens and keywords ----------------------------------------------- */
+
+/* C lexer keywords. */
+#define CTOKDEF(_) \
+ _(IDENT, "<identifier>") _(STRING, "<string>") \
+ _(INTEGER, "<integer>") _(EOF, "<eof>") \
+ _(OROR, "||") _(ANDAND, "&&") _(EQ, "==") _(NE, "!=") \
+ _(LE, "<=") _(GE, ">=") _(SHL, "<<") _(SHR, ">>") _(DEREF, "->")
+
+/* Simple declaration specifiers. */
+#define CDSDEF(_) \
+ _(VOID) _(BOOL) _(CHAR) _(INT) _(FP) \
+ _(LONG) _(LONGLONG) _(SHORT) _(COMPLEX) _(SIGNED) _(UNSIGNED) \
+ _(CONST) _(VOLATILE) _(RESTRICT) _(INLINE) \
+ _(TYPEDEF) _(EXTERN) _(STATIC) _(AUTO) _(REGISTER)
+
+/* C keywords. */
+#define CKWDEF(_) \
+ CDSDEF(_) _(EXTENSION) _(ASM) _(ATTRIBUTE) \
+ _(DECLSPEC) _(CCDECL) _(PTRSZ) \
+ _(STRUCT) _(UNION) _(ENUM) \
+ _(SIZEOF) _(ALIGNOF)
+
+/* C token numbers. */
+enum {
+ CTOK_OFS = 255,
+#define CTOKNUM(name, sym) CTOK_##name,
+#define CKWNUM(name) CTOK_##name,
+CTOKDEF(CTOKNUM)
+CKWDEF(CKWNUM)
+#undef CTOKNUM
+#undef CKWNUM
+ CTOK_FIRSTDECL = CTOK_VOID,
+ CTOK_FIRSTSCL = CTOK_TYPEDEF,
+ CTOK_LASTDECLFLAG = CTOK_REGISTER,
+ CTOK_LASTDECL = CTOK_ENUM
+};
+
+/* Declaration specifier flags. */
+enum {
+#define CDSFLAG(name) CDF_##name = (1u << (CTOK_##name - CTOK_FIRSTDECL)),
+CDSDEF(CDSFLAG)
+#undef CDSFLAG
+ CDF__END
+};
+
+#define CDF_SCL (CDF_TYPEDEF|CDF_EXTERN|CDF_STATIC|CDF_AUTO|CDF_REGISTER)
+
+/* -- C type management --------------------------------------------------- */
+
+#define ctype_ctsG(g) (mref((g)->ctype_state, CTState))
+
+/* Get C type state. */
+static LJ_AINLINE CTState *ctype_cts(lua_State *L)
+{
+ CTState *cts = ctype_ctsG(G(L));
+ cts->L = L; /* Save L for errors and allocations. */
+ return cts;
+}
+
+/* Save and restore state of C type table. */
+#define LJ_CTYPE_SAVE(cts) CTState savects_ = *(cts)
+#define LJ_CTYPE_RESTORE(cts) \
+ ((cts)->top = savects_.top, \
+ memcpy((cts)->hash, savects_.hash, sizeof(savects_.hash)))
+
+/* Check C type ID for validity when assertions are enabled. */
+static LJ_AINLINE CTypeID ctype_check(CTState *cts, CTypeID id)
+{
+ lua_assert(id > 0 && id < cts->top); UNUSED(cts);
+ return id;
+}
+
+/* Get C type for C type ID. */
+static LJ_AINLINE CType *ctype_get(CTState *cts, CTypeID id)
+{
+ return &cts->tab[ctype_check(cts, id)];
+}
+
+/* Get C type ID for a C type. */
+#define ctype_typeid(cts, ct) ((CTypeID)((ct) - (cts)->tab))
+
+/* Get child C type. */
+static LJ_AINLINE CType *ctype_child(CTState *cts, CType *ct)
+{
+ lua_assert(!(ctype_isvoid(ct->info) || ctype_isstruct(ct->info) ||
+ ctype_isbitfield(ct->info))); /* These don't have children. */
+ return ctype_get(cts, ctype_cid(ct->info));
+}
+
+/* Get raw type for a C type ID. */
+static LJ_AINLINE CType *ctype_raw(CTState *cts, CTypeID id)
+{
+ CType *ct = ctype_get(cts, id);
+ while (ctype_isattrib(ct->info)) ct = ctype_child(cts, ct);
+ return ct;
+}
+
+/* Get raw type of the child of a C type. */
+static LJ_AINLINE CType *ctype_rawchild(CTState *cts, CType *ct)
+{
+ do { ct = ctype_child(cts, ct); } while (ctype_isattrib(ct->info));
+ return ct;
+}
+
+/* Set the name of a C type table element. */
+static LJ_AINLINE void ctype_setname(CType *ct, GCstr *s)
+{
+ /* NOBARRIER: mark string as fixed -- the C type table is never collected. */
+ fixstring(s);
+ setgcref(ct->name, obj2gco(s));
+}
+
+LJ_FUNC CTypeID lj_ctype_new(CTState *cts, CType **ctp);
+LJ_FUNC CTypeID lj_ctype_intern(CTState *cts, CTInfo info, CTSize size);
+LJ_FUNC void lj_ctype_addname(CTState *cts, CType *ct, CTypeID id);
+LJ_FUNC CTypeID lj_ctype_getname(CTState *cts, CType **ctp, GCstr *name,
+ uint32_t tmask);
+LJ_FUNC CType *lj_ctype_getfieldq(CTState *cts, CType *ct, GCstr *name,
+ CTSize *ofs, CTInfo *qual);
+#define lj_ctype_getfield(cts, ct, name, ofs) \
+ lj_ctype_getfieldq((cts), (ct), (name), (ofs), NULL)
+LJ_FUNC CType *lj_ctype_rawref(CTState *cts, CTypeID id);
+LJ_FUNC CTSize lj_ctype_size(CTState *cts, CTypeID id);
+LJ_FUNC CTSize lj_ctype_vlsize(CTState *cts, CType *ct, CTSize nelem);
+LJ_FUNC CTInfo lj_ctype_info(CTState *cts, CTypeID id, CTSize *szp);
+LJ_FUNC cTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm);
+LJ_FUNC GCstr *lj_ctype_repr(lua_State *L, CTypeID id, GCstr *name);
+LJ_FUNC GCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned);
+LJ_FUNC GCstr *lj_ctype_repr_complex(lua_State *L, void *sp, CTSize size);
+LJ_FUNC CTState *lj_ctype_init(lua_State *L);
+LJ_FUNC void lj_ctype_freestate(global_State *g);
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_debug.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_debug.c
new file mode 100644
index 0000000..a684302
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_debug.c
@@ -0,0 +1,605 @@
+/*
+** Debugging and introspection.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_debug_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#include "lj_err.h"
+#include "lj_debug.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_state.h"
+#include "lj_frame.h"
+#include "lj_bc.h"
+#include "lj_vm.h"
+#if LJ_HASJIT
+#include "lj_jit.h"
+#endif
+
+/* -- Frames -------------------------------------------------------------- */
+
+/* Get frame corresponding to a level. */
+cTValue *lj_debug_frame(lua_State *L, int level, int *size)
+{
+ cTValue *frame, *nextframe, *bot = tvref(L->stack);
+ /* Traverse frames backwards. */
+ for (nextframe = frame = L->base-1; frame > bot; ) {
+ if (frame_gc(frame) == obj2gco(L))
+ level++; /* Skip dummy frames. See lj_meta_call(). */
+ if (level-- == 0) {
+ *size = (int)(nextframe - frame);
+ return frame; /* Level found. */
+ }
+ nextframe = frame;
+ if (frame_islua(frame)) {
+ frame = frame_prevl(frame);
+ } else {
+ if (frame_isvarg(frame))
+ level++; /* Skip vararg pseudo-frame. */
+ frame = frame_prevd(frame);
+ }
+ }
+ *size = level;
+ return NULL; /* Level not found. */
+}
+
+/* Invalid bytecode position. */
+#define NO_BCPOS (~(BCPos)0)
+
+/* Return bytecode position for function/frame or NO_BCPOS. */
+static BCPos debug_framepc(lua_State *L, GCfunc *fn, cTValue *nextframe)
+{
+ const BCIns *ins;
+ GCproto *pt;
+ BCPos pos;
+ lua_assert(fn->c.gct == ~LJ_TFUNC || fn->c.gct == ~LJ_TTHREAD);
+ if (!isluafunc(fn)) { /* Cannot derive a PC for non-Lua functions. */
+ return NO_BCPOS;
+ } else if (nextframe == NULL) { /* Lua function on top. */
+ void *cf = cframe_raw(L->cframe);
+ if (cf == NULL || (char *)cframe_pc(cf) == (char *)cframe_L(cf))
+ return NO_BCPOS;
+ ins = cframe_pc(cf); /* Only happens during error/hook handling. */
+ } else {
+ if (frame_islua(nextframe)) {
+ ins = frame_pc(nextframe);
+ } else if (frame_iscont(nextframe)) {
+ ins = frame_contpc(nextframe);
+ } else {
+ /* Lua function below errfunc/gc/hook: find cframe to get the PC. */
+ void *cf = cframe_raw(L->cframe);
+ TValue *f = L->base-1;
+ for (;;) {
+ if (cf == NULL)
+ return NO_BCPOS;
+ while (cframe_nres(cf) < 0) {
+ if (f >= restorestack(L, -cframe_nres(cf)))
+ break;
+ cf = cframe_raw(cframe_prev(cf));
+ if (cf == NULL)
+ return NO_BCPOS;
+ }
+ if (f < nextframe)
+ break;
+ if (frame_islua(f)) {
+ f = frame_prevl(f);
+ } else {
+ if (frame_isc(f) || (LJ_HASFFI && frame_iscont(f) &&
+ (f-1)->u32.lo == LJ_CONT_FFI_CALLBACK))
+ cf = cframe_raw(cframe_prev(cf));
+ f = frame_prevd(f);
+ }
+ }
+ ins = cframe_pc(cf);
+ }
+ }
+ pt = funcproto(fn);
+ pos = proto_bcpos(pt, ins) - 1;
+#if LJ_HASJIT
+ if (pos > pt->sizebc) { /* Undo the effects of lj_trace_exit for JLOOP. */
+ GCtrace *T = (GCtrace *)((char *)(ins-1) - offsetof(GCtrace, startins));
+ lua_assert(bc_isret(bc_op(ins[-1])));
+ pos = proto_bcpos(pt, mref(T->startpc, const BCIns));
+ }
+#endif
+ return pos;
+}
+
+/* -- Line numbers -------------------------------------------------------- */
+
+/* Get line number for a bytecode position. */
+BCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc)
+{
+ const void *lineinfo = proto_lineinfo(pt);
+ if (pc <= pt->sizebc && lineinfo) {
+ BCLine first = pt->firstline;
+ if (pc == pt->sizebc) return first + pt->numline;
+ if (pc-- == 0) return first;
+ if (pt->numline < 256)
+ return first + (BCLine)((const uint8_t *)lineinfo)[pc];
+ else if (pt->numline < 65536)
+ return first + (BCLine)((const uint16_t *)lineinfo)[pc];
+ else
+ return first + (BCLine)((const uint32_t *)lineinfo)[pc];
+ }
+ return 0;
+}
+
+/* Get line number for function/frame. */
+static BCLine debug_frameline(lua_State *L, GCfunc *fn, cTValue *nextframe)
+{
+ BCPos pc = debug_framepc(L, fn, nextframe);
+ if (pc != NO_BCPOS) {
+ GCproto *pt = funcproto(fn);
+ lua_assert(pc <= pt->sizebc);
+ return lj_debug_line(pt, pc);
+ }
+ return -1;
+}
+
+/* -- Variable names ------------------------------------------------------ */
+
+/* Read ULEB128 value. */
+static uint32_t debug_read_uleb128(const uint8_t **pp)
+{
+ const uint8_t *p = *pp;
+ uint32_t v = *p++;
+ if (LJ_UNLIKELY(v >= 0x80)) {
+ int sh = 0;
+ v &= 0x7f;
+ do { v |= ((*p & 0x7f) << (sh += 7)); } while (*p++ >= 0x80);
+ }
+ *pp = p;
+ return v;
+}
+
+/* Get name of a local variable from slot number and PC. */
+static const char *debug_varname(const GCproto *pt, BCPos pc, BCReg slot)
+{
+ const uint8_t *p = proto_varinfo(pt);
+ if (p) {
+ BCPos lastpc = 0;
+ for (;;) {
+ const char *name = (const char *)p;
+ uint32_t vn = *p++;
+ BCPos startpc, endpc;
+ if (vn < VARNAME__MAX) {
+ if (vn == VARNAME_END) break; /* End of varinfo. */
+ } else {
+ while (*p++) ; /* Skip over variable name string. */
+ }
+ lastpc = startpc = lastpc + debug_read_uleb128(&p);
+ if (startpc > pc) break;
+ endpc = startpc + debug_read_uleb128(&p);
+ if (pc < endpc && slot-- == 0) {
+ if (vn < VARNAME__MAX) {
+#define VARNAMESTR(name, str) str "\0"
+ name = VARNAMEDEF(VARNAMESTR);
+#undef VARNAMESTR
+ if (--vn) while (*name++ || --vn) ;
+ }
+ return name;
+ }
+ }
+ }
+ return NULL;
+}
+
+/* Get name of local variable from 1-based slot number and function/frame. */
+static TValue *debug_localname(lua_State *L, const lua_Debug *ar,
+ const char **name, BCReg slot1)
+{
+ uint32_t offset = (uint32_t)ar->i_ci & 0xffff;
+ uint32_t size = (uint32_t)ar->i_ci >> 16;
+ TValue *frame = tvref(L->stack) + offset;
+ TValue *nextframe = size ? frame + size : NULL;
+ GCfunc *fn = frame_func(frame);
+ BCPos pc = debug_framepc(L, fn, nextframe);
+ if (!nextframe) nextframe = L->top;
+ if ((int)slot1 < 0) { /* Negative slot number is for varargs. */
+ if (pc != NO_BCPOS) {
+ GCproto *pt = funcproto(fn);
+ if ((pt->flags & PROTO_VARARG)) {
+ slot1 = pt->numparams + (BCReg)(-(int)slot1);
+ if (frame_isvarg(frame)) { /* Vararg frame has been set up? (pc!=0) */
+ nextframe = frame;
+ frame = frame_prevd(frame);
+ }
+ if (frame + slot1 < nextframe) {
+ *name = "(*vararg)";
+ return frame+slot1;
+ }
+ }
+ }
+ return NULL;
+ }
+ if (pc != NO_BCPOS &&
+ (*name = debug_varname(funcproto(fn), pc, slot1-1)) != NULL)
+ ;
+ else if (slot1 > 0 && frame + slot1 < nextframe)
+ *name = "(*temporary)";
+ return frame+slot1;
+}
+
+/* Get name of upvalue. */
+const char *lj_debug_uvname(GCproto *pt, uint32_t idx)
+{
+ const uint8_t *p = proto_uvinfo(pt);
+ lua_assert(idx < pt->sizeuv);
+ if (!p) return "";
+ if (idx) while (*p++ || --idx) ;
+ return (const char *)p;
+}
+
+/* Get name and value of upvalue. */
+const char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp)
+{
+ if (tvisfunc(o)) {
+ GCfunc *fn = funcV(o);
+ if (isluafunc(fn)) {
+ GCproto *pt = funcproto(fn);
+ if (idx < pt->sizeuv) {
+ *tvp = uvval(&gcref(fn->l.uvptr[idx])->uv);
+ return lj_debug_uvname(pt, idx);
+ }
+ } else {
+ if (idx < fn->c.nupvalues) {
+ *tvp = &fn->c.upvalue[idx];
+ return "";
+ }
+ }
+ }
+ return NULL;
+}
+
+/* Deduce name of an object from slot number and PC. */
+const char *lj_debug_slotname(GCproto *pt, const BCIns *ip, BCReg slot,
+ const char **name)
+{
+ const char *lname;
+restart:
+ lname = debug_varname(pt, proto_bcpos(pt, ip), slot);
+ if (lname != NULL) { *name = lname; return "local"; }
+ while (--ip > proto_bc(pt)) {
+ BCIns ins = *ip;
+ BCOp op = bc_op(ins);
+ BCReg ra = bc_a(ins);
+ if (bcmode_a(op) == BCMbase) {
+ if (slot >= ra && (op != BC_KNIL || slot <= bc_d(ins)))
+ return NULL;
+ } else if (bcmode_a(op) == BCMdst && ra == slot) {
+ switch (bc_op(ins)) {
+ case BC_MOV:
+ if (ra == slot) { slot = bc_d(ins); goto restart; }
+ break;
+ case BC_GGET:
+ *name = strdata(gco2str(proto_kgc(pt, ~(ptrdiff_t)bc_d(ins))));
+ return "global";
+ case BC_TGETS:
+ *name = strdata(gco2str(proto_kgc(pt, ~(ptrdiff_t)bc_c(ins))));
+ if (ip > proto_bc(pt)) {
+ BCIns insp = ip[-1];
+ if (bc_op(insp) == BC_MOV && bc_a(insp) == ra+1 &&
+ bc_d(insp) == bc_b(ins))
+ return "method";
+ }
+ return "field";
+ case BC_UGET:
+ *name = lj_debug_uvname(pt, bc_d(ins));
+ return "upvalue";
+ default:
+ return NULL;
+ }
+ }
+ }
+ return NULL;
+}
+
+/* Deduce function name from caller of a frame. */
+const char *lj_debug_funcname(lua_State *L, TValue *frame, const char **name)
+{
+ TValue *pframe;
+ GCfunc *fn;
+ BCPos pc;
+ if (frame <= tvref(L->stack))
+ return NULL;
+ if (frame_isvarg(frame))
+ frame = frame_prevd(frame);
+ pframe = frame_prev(frame);
+ fn = frame_func(pframe);
+ pc = debug_framepc(L, fn, frame);
+ if (pc != NO_BCPOS) {
+ GCproto *pt = funcproto(fn);
+ const BCIns *ip = &proto_bc(pt)[check_exp(pc < pt->sizebc, pc)];
+ MMS mm = bcmode_mm(bc_op(*ip));
+ if (mm == MM_call) {
+ BCReg slot = bc_a(*ip);
+ if (bc_op(*ip) == BC_ITERC) slot -= 3;
+ return lj_debug_slotname(pt, ip, slot, name);
+ } else if (mm != MM__MAX) {
+ *name = strdata(mmname_str(G(L), mm));
+ return "metamethod";
+ }
+ }
+ return NULL;
+}
+
+/* -- Source code locations ----------------------------------------------- */
+
+/* Generate shortened source name. */
+void lj_debug_shortname(char *out, GCstr *str)
+{
+ const char *src = strdata(str);
+ if (*src == '=') {
+ strncpy(out, src+1, LUA_IDSIZE); /* Remove first char. */
+ out[LUA_IDSIZE-1] = '\0'; /* Ensures null termination. */
+ } else if (*src == '@') { /* Output "source", or "...source". */
+ size_t len = str->len-1;
+ src++; /* Skip the `@' */
+ if (len >= LUA_IDSIZE) {
+ src += len-(LUA_IDSIZE-4); /* Get last part of file name. */
+ *out++ = '.'; *out++ = '.'; *out++ = '.';
+ }
+ strcpy(out, src);
+ } else { /* Output [string "string"]. */
+ size_t len; /* Length, up to first control char. */
+ for (len = 0; len < LUA_IDSIZE-12; len++)
+ if (((const unsigned char *)src)[len] < ' ') break;
+ strcpy(out, "[string \""); out += 9;
+ if (src[len] != '\0') { /* Must truncate? */
+ if (len > LUA_IDSIZE-15) len = LUA_IDSIZE-15;
+ strncpy(out, src, len); out += len;
+ strcpy(out, "..."); out += 3;
+ } else {
+ strcpy(out, src); out += len;
+ }
+ strcpy(out, "\"]");
+ }
+}
+
+/* Add current location of a frame to error message. */
+void lj_debug_addloc(lua_State *L, const char *msg,
+ cTValue *frame, cTValue *nextframe)
+{
+ if (frame) {
+ GCfunc *fn = frame_func(frame);
+ if (isluafunc(fn)) {
+ BCLine line = debug_frameline(L, fn, nextframe);
+ if (line >= 0) {
+ char buf[LUA_IDSIZE];
+ lj_debug_shortname(buf, proto_chunkname(funcproto(fn)));
+ lj_str_pushf(L, "%s:%d: %s", buf, line, msg);
+ return;
+ }
+ }
+ }
+ lj_str_pushf(L, "%s", msg);
+}
+
+/* Push location string for a bytecode position to Lua stack. */
+void lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc)
+{
+ GCstr *name = proto_chunkname(pt);
+ const char *s = strdata(name);
+ MSize i, len = name->len;
+ BCLine line = lj_debug_line(pt, pc);
+ if (*s == '@') {
+ s++; len--;
+ for (i = len; i > 0; i--)
+ if (s[i] == '/' || s[i] == '\\') {
+ s += i+1;
+ break;
+ }
+ lj_str_pushf(L, "%s:%d", s, line);
+ } else if (len > 40) {
+ lj_str_pushf(L, "%p:%d", pt, line);
+ } else if (*s == '=') {
+ lj_str_pushf(L, "%s:%d", s+1, line);
+ } else {
+ lj_str_pushf(L, "\"%s\":%d", s, line);
+ }
+}
+
+/* -- Public debug API ---------------------------------------------------- */
+
+/* lua_getupvalue() and lua_setupvalue() are in lj_api.c. */
+
+LUA_API const char *lua_getlocal(lua_State *L, const lua_Debug *ar, int n)
+{
+ const char *name = NULL;
+ if (ar) {
+ TValue *o = debug_localname(L, ar, &name, (BCReg)n);
+ if (name) {
+ copyTV(L, L->top, o);
+ incr_top(L);
+ }
+ } else if (tvisfunc(L->top-1) && isluafunc(funcV(L->top-1))) {
+ name = debug_varname(funcproto(funcV(L->top-1)), 0, (BCReg)n-1);
+ }
+ return name;
+}
+
+LUA_API const char *lua_setlocal(lua_State *L, const lua_Debug *ar, int n)
+{
+ const char *name = NULL;
+ TValue *o = debug_localname(L, ar, &name, (BCReg)n);
+ if (name)
+ copyTV(L, o, L->top-1);
+ L->top--;
+ return name;
+}
+
+int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar, int ext)
+{
+ int opt_f = 0, opt_L = 0;
+ TValue *frame = NULL;
+ TValue *nextframe = NULL;
+ GCfunc *fn;
+ if (*what == '>') {
+ TValue *func = L->top - 1;
+ api_check(L, tvisfunc(func));
+ fn = funcV(func);
+ L->top--;
+ what++;
+ } else {
+ uint32_t offset = (uint32_t)ar->i_ci & 0xffff;
+ uint32_t size = (uint32_t)ar->i_ci >> 16;
+ lua_assert(offset != 0);
+ frame = tvref(L->stack) + offset;
+ if (size) nextframe = frame + size;
+ lua_assert(frame <= tvref(L->maxstack) &&
+ (!nextframe || nextframe <= tvref(L->maxstack)));
+ fn = frame_func(frame);
+ lua_assert(fn->c.gct == ~LJ_TFUNC);
+ }
+ for (; *what; what++) {
+ if (*what == 'S') {
+ if (isluafunc(fn)) {
+ GCproto *pt = funcproto(fn);
+ BCLine firstline = pt->firstline;
+ GCstr *name = proto_chunkname(pt);
+ ar->source = strdata(name);
+ lj_debug_shortname(ar->short_src, name);
+ ar->linedefined = (int)firstline;
+ ar->lastlinedefined = (int)(firstline + pt->numline);
+ ar->what = (firstline || !pt->numline) ? "Lua" : "main";
+ } else {
+ ar->source = "=[C]";
+ ar->short_src[0] = '[';
+ ar->short_src[1] = 'C';
+ ar->short_src[2] = ']';
+ ar->short_src[3] = '\0';
+ ar->linedefined = -1;
+ ar->lastlinedefined = -1;
+ ar->what = "C";
+ }
+ } else if (*what == 'l') {
+ ar->currentline = frame ? debug_frameline(L, fn, nextframe) : -1;
+ } else if (*what == 'u') {
+ ar->nups = fn->c.nupvalues;
+ if (ext) {
+ if (isluafunc(fn)) {
+ GCproto *pt = funcproto(fn);
+ ar->nparams = pt->numparams;
+ ar->isvararg = !!(pt->flags & PROTO_VARARG);
+ } else {
+ ar->nparams = 0;
+ ar->isvararg = 1;
+ }
+ }
+ } else if (*what == 'n') {
+ ar->namewhat = frame ? lj_debug_funcname(L, frame, &ar->name) : NULL;
+ if (ar->namewhat == NULL) {
+ ar->namewhat = "";
+ ar->name = NULL;
+ }
+ } else if (*what == 'f') {
+ opt_f = 1;
+ } else if (*what == 'L') {
+ opt_L = 1;
+ } else {
+ return 0; /* Bad option. */
+ }
+ }
+ if (opt_f) {
+ setfuncV(L, L->top, fn);
+ incr_top(L);
+ }
+ if (opt_L) {
+ if (isluafunc(fn)) {
+ GCtab *t = lj_tab_new(L, 0, 0);
+ GCproto *pt = funcproto(fn);
+ const void *lineinfo = proto_lineinfo(pt);
+ if (lineinfo) {
+ BCLine first = pt->firstline;
+ int sz = pt->numline < 256 ? 1 : pt->numline < 65536 ? 2 : 4;
+ MSize i, szl = pt->sizebc-1;
+ for (i = 0; i < szl; i++) {
+ BCLine line = first +
+ (sz == 1 ? (BCLine)((const uint8_t *)lineinfo)[i] :
+ sz == 2 ? (BCLine)((const uint16_t *)lineinfo)[i] :
+ (BCLine)((const uint32_t *)lineinfo)[i]);
+ setboolV(lj_tab_setint(L, t, line), 1);
+ }
+ }
+ settabV(L, L->top, t);
+ } else {
+ setnilV(L->top);
+ }
+ incr_top(L);
+ }
+ return 1; /* Ok. */
+}
+
+LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar)
+{
+ return lj_debug_getinfo(L, what, (lj_Debug *)ar, 0);
+}
+
+LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar)
+{
+ int size;
+ cTValue *frame = lj_debug_frame(L, level, &size);
+ if (frame) {
+ ar->i_ci = (size << 16) + (int)(frame - tvref(L->stack));
+ return 1;
+ } else {
+ ar->i_ci = level - size;
+ return 0;
+ }
+}
+
+/* Number of frames for the leading and trailing part of a traceback. */
+#define TRACEBACK_LEVELS1 12
+#define TRACEBACK_LEVELS2 10
+
+LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,
+ int level)
+{
+ int top = (int)(L->top - L->base);
+ int lim = TRACEBACK_LEVELS1;
+ lua_Debug ar;
+ if (msg) lua_pushfstring(L, "%s\n", msg);
+ lua_pushliteral(L, "stack traceback:");
+ while (lua_getstack(L1, level++, &ar)) {
+ GCfunc *fn;
+ if (level > lim) {
+ if (!lua_getstack(L1, level + TRACEBACK_LEVELS2, &ar)) {
+ level--;
+ } else {
+ lua_pushliteral(L, "\n\t...");
+ lua_getstack(L1, -10, &ar);
+ level = ar.i_ci - TRACEBACK_LEVELS2;
+ }
+ lim = 2147483647;
+ continue;
+ }
+ lua_getinfo(L1, "Snlf", &ar);
+ fn = funcV(L1->top-1); L1->top--;
+ if (isffunc(fn) && !*ar.namewhat)
+ lua_pushfstring(L, "\n\t[builtin#%d]:", fn->c.ffid);
+ else
+ lua_pushfstring(L, "\n\t%s:", ar.short_src);
+ if (ar.currentline > 0)
+ lua_pushfstring(L, "%d:", ar.currentline);
+ if (*ar.namewhat) {
+ lua_pushfstring(L, " in function " LUA_QS, ar.name);
+ } else {
+ if (*ar.what == 'm') {
+ lua_pushliteral(L, " in main chunk");
+ } else if (*ar.what == 'C') {
+ lua_pushfstring(L, " at %p", fn->c.f);
+ } else {
+ lua_pushfstring(L, " in function <%s:%d>",
+ ar.short_src, ar.linedefined);
+ }
+ }
+ if ((int)(L->top - L->base) - top >= 15)
+ lua_concat(L, (int)(L->top - L->base) - top);
+ }
+ lua_concat(L, (int)(L->top - L->base) - top);
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_debug.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_debug.h
new file mode 100644
index 0000000..d10d0da
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_debug.h
@@ -0,0 +1,61 @@
+/*
+** Debugging and introspection.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_DEBUG_H
+#define _LJ_DEBUG_H
+
+#include "lj_obj.h"
+
+typedef struct lj_Debug {
+ /* Common fields. Must be in the same order as in lua.h. */
+ int event;
+ const char *name;
+ const char *namewhat;
+ const char *what;
+ const char *source;
+ int currentline;
+ int nups;
+ int linedefined;
+ int lastlinedefined;
+ char short_src[LUA_IDSIZE];
+ int i_ci;
+ /* Extended fields. Only valid if lj_debug_getinfo() is called with ext = 1.*/
+ int nparams;
+ int isvararg;
+} lj_Debug;
+
+LJ_FUNC cTValue *lj_debug_frame(lua_State *L, int level, int *size);
+LJ_FUNC BCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc);
+LJ_FUNC const char *lj_debug_uvname(GCproto *pt, uint32_t idx);
+LJ_FUNC const char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp);
+LJ_FUNC const char *lj_debug_slotname(GCproto *pt, const BCIns *pc,
+ BCReg slot, const char **name);
+LJ_FUNC const char *lj_debug_funcname(lua_State *L, TValue *frame,
+ const char **name);
+LJ_FUNC void lj_debug_shortname(char *out, GCstr *str);
+LJ_FUNC void lj_debug_addloc(lua_State *L, const char *msg,
+ cTValue *frame, cTValue *nextframe);
+LJ_FUNC void lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc);
+LJ_FUNC int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar,
+ int ext);
+
+/* Fixed internal variable names. */
+#define VARNAMEDEF(_) \
+ _(FOR_IDX, "(for index)") \
+ _(FOR_STOP, "(for limit)") \
+ _(FOR_STEP, "(for step)") \
+ _(FOR_GEN, "(for generator)") \
+ _(FOR_STATE, "(for state)") \
+ _(FOR_CTL, "(for control)")
+
+enum {
+ VARNAME_END,
+#define VARNAMEENUM(name, str) VARNAME_##name,
+ VARNAMEDEF(VARNAMEENUM)
+#undef VARNAMEENUM
+ VARNAME__MAX
+};
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_def.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_def.h
new file mode 100644
index 0000000..21cc59a
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_def.h
@@ -0,0 +1,353 @@
+/*
+** LuaJIT common internal definitions.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_DEF_H
+#define _LJ_DEF_H
+
+#include "lua.h"
+
+#if defined(_MSC_VER)
+/* MSVC is stuck in the last century and doesn't have C99's stdint.h. */
+typedef __int8 int8_t;
+typedef __int16 int16_t;
+typedef __int32 int32_t;
+typedef __int64 int64_t;
+typedef unsigned __int8 uint8_t;
+typedef unsigned __int16 uint16_t;
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int64 uint64_t;
+#ifdef _WIN64
+typedef __int64 intptr_t;
+typedef unsigned __int64 uintptr_t;
+#else
+typedef __int32 intptr_t;
+typedef unsigned __int32 uintptr_t;
+#endif
+#elif defined(__symbian__)
+/* Cough. */
+typedef signed char int8_t;
+typedef short int int16_t;
+typedef int int32_t;
+typedef long long int64_t;
+typedef unsigned char uint8_t;
+typedef unsigned short int uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
+typedef int intptr_t;
+typedef unsigned int uintptr_t;
+#else
+#include <stdint.h>
+#endif
+
+/* Needed everywhere. */
+#include <string.h>
+#include <stdlib.h>
+
+/* Various VM limits. */
+#define LJ_MAX_MEM 0x7fffff00 /* Max. total memory allocation. */
+#define LJ_MAX_ALLOC LJ_MAX_MEM /* Max. individual allocation length. */
+#define LJ_MAX_STR LJ_MAX_MEM /* Max. string length. */
+#define LJ_MAX_UDATA LJ_MAX_MEM /* Max. userdata length. */
+
+#define LJ_MAX_STRTAB (1<<26) /* Max. string table size. */
+#define LJ_MAX_HBITS 26 /* Max. hash bits. */
+#define LJ_MAX_ABITS 28 /* Max. bits of array key. */
+#define LJ_MAX_ASIZE ((1<<(LJ_MAX_ABITS-1))+1) /* Max. array part size. */
+#define LJ_MAX_COLOSIZE 16 /* Max. elems for colocated array. */
+
+#define LJ_MAX_LINE LJ_MAX_MEM /* Max. source code line number. */
+#define LJ_MAX_XLEVEL 200 /* Max. syntactic nesting level. */
+#define LJ_MAX_BCINS (1<<26) /* Max. # of bytecode instructions. */
+#define LJ_MAX_SLOTS 250 /* Max. # of slots in a Lua func. */
+#define LJ_MAX_LOCVAR 200 /* Max. # of local variables. */
+#define LJ_MAX_UPVAL 60 /* Max. # of upvalues. */
+
+#define LJ_MAX_IDXCHAIN 100 /* __index/__newindex chain limit. */
+#define LJ_STACK_EXTRA 5 /* Extra stack space (metamethods). */
+
+#define LJ_NUM_CBPAGE 1 /* Number of FFI callback pages. */
+
+/* Minimum table/buffer sizes. */
+#define LJ_MIN_GLOBAL 6 /* Min. global table size (hbits). */
+#define LJ_MIN_REGISTRY 2 /* Min. registry size (hbits). */
+#define LJ_MIN_STRTAB 256 /* Min. string table size (pow2). */
+#define LJ_MIN_SBUF 32 /* Min. string buffer length. */
+#define LJ_MIN_VECSZ 8 /* Min. size for growable vectors. */
+#define LJ_MIN_IRSZ 32 /* Min. size for growable IR. */
+#define LJ_MIN_K64SZ 16 /* Min. size for chained K64Array. */
+
+/* JIT compiler limits. */
+#define LJ_MAX_JSLOTS 250 /* Max. # of stack slots for a trace. */
+#define LJ_MAX_PHI 64 /* Max. # of PHIs for a loop. */
+#define LJ_MAX_EXITSTUBGR 16 /* Max. # of exit stub groups. */
+
+/* Various macros. */
+#ifndef UNUSED
+#define UNUSED(x) ((void)(x)) /* to avoid warnings */
+#endif
+
+#define U64x(hi, lo) (((uint64_t)0x##hi << 32) + (uint64_t)0x##lo)
+#define i32ptr(p) ((int32_t)(intptr_t)(void *)(p))
+#define u32ptr(p) ((uint32_t)(intptr_t)(void *)(p))
+
+#define checki8(x) ((x) == (int32_t)(int8_t)(x))
+#define checku8(x) ((x) == (int32_t)(uint8_t)(x))
+#define checki16(x) ((x) == (int32_t)(int16_t)(x))
+#define checku16(x) ((x) == (int32_t)(uint16_t)(x))
+#define checki32(x) ((x) == (int32_t)(x))
+#define checku32(x) ((x) == (uint32_t)(x))
+#define checkptr32(x) ((uintptr_t)(x) == (uint32_t)(uintptr_t)(x))
+
+/* Every half-decent C compiler transforms this into a rotate instruction. */
+#define lj_rol(x, n) (((x)<<(n)) | ((x)>>(-(int)(n)&(8*sizeof(x)-1))))
+#define lj_ror(x, n) (((x)<<(-(int)(n)&(8*sizeof(x)-1))) | ((x)>>(n)))
+
+/* A really naive Bloom filter. But sufficient for our needs. */
+typedef uintptr_t BloomFilter;
+#define BLOOM_MASK (8*sizeof(BloomFilter) - 1)
+#define bloombit(x) ((uintptr_t)1 << ((x) & BLOOM_MASK))
+#define bloomset(b, x) ((b) |= bloombit((x)))
+#define bloomtest(b, x) ((b) & bloombit((x)))
+
+#if defined(__GNUC__) || defined(__psp2__)
+
+#define LJ_NORET __attribute__((noreturn))
+#define LJ_ALIGN(n) __attribute__((aligned(n)))
+#define LJ_INLINE inline
+#define LJ_AINLINE inline __attribute__((always_inline))
+#define LJ_NOINLINE __attribute__((noinline))
+
+#if defined(__ELF__) || defined(__MACH__) || defined(__psp2__)
+#if !((defined(__sun__) && defined(__svr4__)) || defined(__CELLOS_LV2__))
+#define LJ_NOAPI extern __attribute__((visibility("hidden")))
+#endif
+#endif
+
+/* Note: it's only beneficial to use fastcall on x86 and then only for up to
+** two non-FP args. The amalgamated compile covers all LJ_FUNC cases. Only
+** indirect calls and related tail-called C functions are marked as fastcall.
+*/
+#if defined(__i386__)
+#define LJ_FASTCALL __attribute__((fastcall))
+#endif
+
+#define LJ_LIKELY(x) __builtin_expect(!!(x), 1)
+#define LJ_UNLIKELY(x) __builtin_expect(!!(x), 0)
+
+#define lj_ffs(x) ((uint32_t)__builtin_ctz(x))
+/* Don't ask ... */
+#if defined(__INTEL_COMPILER) && (defined(__i386__) || defined(__x86_64__))
+static LJ_AINLINE uint32_t lj_fls(uint32_t x)
+{
+ uint32_t r; __asm__("bsrl %1, %0" : "=r" (r) : "rm" (x) : "cc"); return r;
+}
+#else
+#define lj_fls(x) ((uint32_t)(__builtin_clz(x)^31))
+#endif
+
+#if defined(__arm__)
+static LJ_AINLINE uint32_t lj_bswap(uint32_t x)
+{
+#if defined(__psp2__)
+ return __builtin_rev(x);
+#else
+ uint32_t r;
+#if __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6T2__ || __ARM_ARCH_6Z__ ||\
+ __ARM_ARCH_6ZK__ || __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__
+ __asm__("rev %0, %1" : "=r" (r) : "r" (x));
+ return r;
+#else
+#ifdef __thumb__
+ r = x ^ lj_ror(x, 16);
+#else
+ __asm__("eor %0, %1, %1, ror #16" : "=r" (r) : "r" (x));
+#endif
+ return ((r & 0xff00ffffu) >> 8) ^ lj_ror(x, 8);
+#endif
+#endif
+}
+
+static LJ_AINLINE uint64_t lj_bswap64(uint64_t x)
+{
+ return ((uint64_t)lj_bswap((uint32_t)x)<<32) | lj_bswap((uint32_t)(x>>32));
+}
+#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+static LJ_AINLINE uint32_t lj_bswap(uint32_t x)
+{
+ return (uint32_t)__builtin_bswap32((int32_t)x);
+}
+
+static LJ_AINLINE uint64_t lj_bswap64(uint64_t x)
+{
+ return (uint64_t)__builtin_bswap64((int64_t)x);
+}
+#elif defined(__i386__) || defined(__x86_64__)
+static LJ_AINLINE uint32_t lj_bswap(uint32_t x)
+{
+ uint32_t r; __asm__("bswap %0" : "=r" (r) : "0" (x)); return r;
+}
+
+#if defined(__i386__)
+static LJ_AINLINE uint64_t lj_bswap64(uint64_t x)
+{
+ return ((uint64_t)lj_bswap((uint32_t)x)<<32) | lj_bswap((uint32_t)(x>>32));
+}
+#else
+static LJ_AINLINE uint64_t lj_bswap64(uint64_t x)
+{
+ uint64_t r; __asm__("bswap %0" : "=r" (r) : "0" (x)); return r;
+}
+#endif
+#else
+static LJ_AINLINE uint32_t lj_bswap(uint32_t x)
+{
+ return (x << 24) | ((x & 0xff00) << 8) | ((x >> 8) & 0xff00) | (x >> 24);
+}
+
+static LJ_AINLINE uint64_t lj_bswap64(uint64_t x)
+{
+ return (uint64_t)lj_bswap((uint32_t)(x >> 32)) |
+ ((uint64_t)lj_bswap((uint32_t)x) << 32);
+}
+#endif
+
+typedef union __attribute__((packed)) Unaligned16 {
+ uint16_t u;
+ uint8_t b[2];
+} Unaligned16;
+
+typedef union __attribute__((packed)) Unaligned32 {
+ uint32_t u;
+ uint8_t b[4];
+} Unaligned32;
+
+/* Unaligned load of uint16_t. */
+static LJ_AINLINE uint16_t lj_getu16(const void *p)
+{
+ return ((const Unaligned16 *)p)->u;
+}
+
+/* Unaligned load of uint32_t. */
+static LJ_AINLINE uint32_t lj_getu32(const void *p)
+{
+ return ((const Unaligned32 *)p)->u;
+}
+
+#elif defined(_MSC_VER)
+
+#define LJ_NORET __declspec(noreturn)
+#define LJ_ALIGN(n) __declspec(align(n))
+#define LJ_INLINE __inline
+#define LJ_AINLINE __forceinline
+#define LJ_NOINLINE __declspec(noinline)
+#if defined(_M_IX86)
+#define LJ_FASTCALL __fastcall
+#endif
+
+#ifdef _M_PPC
+unsigned int _CountLeadingZeros(long);
+#pragma intrinsic(_CountLeadingZeros)
+static LJ_AINLINE uint32_t lj_fls(uint32_t x)
+{
+ return _CountLeadingZeros(x) ^ 31;
+}
+#else
+unsigned char _BitScanForward(uint32_t *, unsigned long);
+unsigned char _BitScanReverse(uint32_t *, unsigned long);
+#pragma intrinsic(_BitScanForward)
+#pragma intrinsic(_BitScanReverse)
+
+static LJ_AINLINE uint32_t lj_ffs(uint32_t x)
+{
+ uint32_t r; _BitScanForward(&r, x); return r;
+}
+
+static LJ_AINLINE uint32_t lj_fls(uint32_t x)
+{
+ uint32_t r; _BitScanReverse(&r, x); return r;
+}
+#endif
+
+unsigned long _byteswap_ulong(unsigned long);
+uint64_t _byteswap_uint64(uint64_t);
+#define lj_bswap(x) (_byteswap_ulong((x)))
+#define lj_bswap64(x) (_byteswap_uint64((x)))
+
+#if defined(_M_PPC) && defined(LUAJIT_NO_UNALIGNED)
+/*
+** Replacement for unaligned loads on Xbox 360. Disabled by default since it's
+** usually more costly than the occasional stall when crossing a cache-line.
+*/
+static LJ_AINLINE uint16_t lj_getu16(const void *v)
+{
+ const uint8_t *p = (const uint8_t *)v;
+ return (uint16_t)((p[0]<<8) | p[1]);
+}
+static LJ_AINLINE uint32_t lj_getu32(const void *v)
+{
+ const uint8_t *p = (const uint8_t *)v;
+ return (uint32_t)((p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]);
+}
+#else
+/* Unaligned loads are generally ok on x86/x64. */
+#define lj_getu16(p) (*(uint16_t *)(p))
+#define lj_getu32(p) (*(uint32_t *)(p))
+#endif
+
+#else
+#error "missing defines for your compiler"
+#endif
+
+/* Optional defines. */
+#ifndef LJ_FASTCALL
+#define LJ_FASTCALL
+#endif
+#ifndef LJ_NORET
+#define LJ_NORET
+#endif
+#ifndef LJ_NOAPI
+#define LJ_NOAPI extern
+#endif
+#ifndef LJ_LIKELY
+#define LJ_LIKELY(x) (x)
+#define LJ_UNLIKELY(x) (x)
+#endif
+
+/* Attributes for internal functions. */
+#define LJ_DATA LJ_NOAPI
+#define LJ_DATADEF
+#define LJ_ASMF LJ_NOAPI
+#define LJ_FUNCA LJ_NOAPI
+#if defined(ljamalg_c)
+#define LJ_FUNC static
+#else
+#define LJ_FUNC LJ_NOAPI
+#endif
+#define LJ_FUNC_NORET LJ_FUNC LJ_NORET
+#define LJ_FUNCA_NORET LJ_FUNCA LJ_NORET
+#define LJ_ASMF_NORET LJ_ASMF LJ_NORET
+
+/* Runtime assertions. */
+#ifdef lua_assert
+#define check_exp(c, e) (lua_assert(c), (e))
+#define api_check(l, e) lua_assert(e)
+#else
+#define lua_assert(c) ((void)0)
+#define check_exp(c, e) (e)
+#define api_check luai_apicheck
+#endif
+
+/* Static assertions. */
+#define LJ_ASSERT_NAME2(name, line) name ## line
+#define LJ_ASSERT_NAME(line) LJ_ASSERT_NAME2(lj_assert_, line)
+#ifdef __COUNTER__
+#define LJ_STATIC_ASSERT(cond) \
+ extern void LJ_ASSERT_NAME(__COUNTER__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
+#else
+#define LJ_STATIC_ASSERT(cond) \
+ extern void LJ_ASSERT_NAME(__LINE__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_dispatch.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_dispatch.c
new file mode 100644
index 0000000..627379a
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_dispatch.c
@@ -0,0 +1,494 @@
+/*
+** Instruction dispatch handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_dispatch_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#include "lj_err.h"
+#include "lj_func.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_meta.h"
+#include "lj_debug.h"
+#include "lj_state.h"
+#include "lj_frame.h"
+#include "lj_bc.h"
+#include "lj_ff.h"
+#if LJ_HASJIT
+#include "lj_jit.h"
+#endif
+#if LJ_HASFFI
+#include "lj_ccallback.h"
+#endif
+#include "lj_trace.h"
+#include "lj_dispatch.h"
+#include "lj_vm.h"
+#include "luajit.h"
+
+/* Bump GG_NUM_ASMFF in lj_dispatch.h as needed. Ugly. */
+LJ_STATIC_ASSERT(GG_NUM_ASMFF == FF_NUM_ASMFUNC);
+
+/* -- Dispatch table management ------------------------------------------- */
+
+#if LJ_TARGET_MIPS
+#include <math.h>
+LJ_FUNCA_NORET void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L,
+ lua_State *co);
+
+#define GOTFUNC(name) (ASMFunction)name,
+static const ASMFunction dispatch_got[] = {
+ GOTDEF(GOTFUNC)
+};
+#undef GOTFUNC
+#endif
+
+/* Initialize instruction dispatch table and hot counters. */
+void lj_dispatch_init(GG_State *GG)
+{
+ uint32_t i;
+ ASMFunction *disp = GG->dispatch;
+ for (i = 0; i < GG_LEN_SDISP; i++)
+ disp[GG_LEN_DDISP+i] = disp[i] = makeasmfunc(lj_bc_ofs[i]);
+ for (i = GG_LEN_SDISP; i < GG_LEN_DDISP; i++)
+ disp[i] = makeasmfunc(lj_bc_ofs[i]);
+ /* The JIT engine is off by default. luaopen_jit() turns it on. */
+ disp[BC_FORL] = disp[BC_IFORL];
+ disp[BC_ITERL] = disp[BC_IITERL];
+ disp[BC_LOOP] = disp[BC_ILOOP];
+ disp[BC_FUNCF] = disp[BC_IFUNCF];
+ disp[BC_FUNCV] = disp[BC_IFUNCV];
+ GG->g.bc_cfunc_ext = GG->g.bc_cfunc_int = BCINS_AD(BC_FUNCC, LUA_MINSTACK, 0);
+ for (i = 0; i < GG_NUM_ASMFF; i++)
+ GG->bcff[i] = BCINS_AD(BC__MAX+i, 0, 0);
+#if LJ_TARGET_MIPS
+ memcpy(GG->got, dispatch_got, LJ_GOT__MAX*4);
+#endif
+}
+
+#if LJ_HASJIT
+/* Initialize hotcount table. */
+void lj_dispatch_init_hotcount(global_State *g)
+{
+ int32_t hotloop = G2J(g)->param[JIT_P_hotloop];
+ HotCount start = (HotCount)(hotloop*HOTCOUNT_LOOP - 1);
+ HotCount *hotcount = G2GG(g)->hotcount;
+ uint32_t i;
+ for (i = 0; i < HOTCOUNT_SIZE; i++)
+ hotcount[i] = start;
+}
+#endif
+
+/* Internal dispatch mode bits. */
+#define DISPMODE_JIT 0x01 /* JIT compiler on. */
+#define DISPMODE_REC 0x02 /* Recording active. */
+#define DISPMODE_INS 0x04 /* Override instruction dispatch. */
+#define DISPMODE_CALL 0x08 /* Override call dispatch. */
+#define DISPMODE_RET 0x10 /* Override return dispatch. */
+
+/* Update dispatch table depending on various flags. */
+void lj_dispatch_update(global_State *g)
+{
+ uint8_t oldmode = g->dispatchmode;
+ uint8_t mode = 0;
+#if LJ_HASJIT
+ mode |= (G2J(g)->flags & JIT_F_ON) ? DISPMODE_JIT : 0;
+ mode |= G2J(g)->state != LJ_TRACE_IDLE ?
+ (DISPMODE_REC|DISPMODE_INS|DISPMODE_CALL) : 0;
+#endif
+ mode |= (g->hookmask & (LUA_MASKLINE|LUA_MASKCOUNT)) ? DISPMODE_INS : 0;
+ mode |= (g->hookmask & LUA_MASKCALL) ? DISPMODE_CALL : 0;
+ mode |= (g->hookmask & LUA_MASKRET) ? DISPMODE_RET : 0;
+ if (oldmode != mode) { /* Mode changed? */
+ ASMFunction *disp = G2GG(g)->dispatch;
+ ASMFunction f_forl, f_iterl, f_loop, f_funcf, f_funcv;
+ g->dispatchmode = mode;
+
+ /* Hotcount if JIT is on, but not while recording. */
+ if ((mode & (DISPMODE_JIT|DISPMODE_REC)) == DISPMODE_JIT) {
+ f_forl = makeasmfunc(lj_bc_ofs[BC_FORL]);
+ f_iterl = makeasmfunc(lj_bc_ofs[BC_ITERL]);
+ f_loop = makeasmfunc(lj_bc_ofs[BC_LOOP]);
+ f_funcf = makeasmfunc(lj_bc_ofs[BC_FUNCF]);
+ f_funcv = makeasmfunc(lj_bc_ofs[BC_FUNCV]);
+ } else { /* Otherwise use the non-hotcounting instructions. */
+ f_forl = disp[GG_LEN_DDISP+BC_IFORL];
+ f_iterl = disp[GG_LEN_DDISP+BC_IITERL];
+ f_loop = disp[GG_LEN_DDISP+BC_ILOOP];
+ f_funcf = makeasmfunc(lj_bc_ofs[BC_IFUNCF]);
+ f_funcv = makeasmfunc(lj_bc_ofs[BC_IFUNCV]);
+ }
+ /* Init static counting instruction dispatch first (may be copied below). */
+ disp[GG_LEN_DDISP+BC_FORL] = f_forl;
+ disp[GG_LEN_DDISP+BC_ITERL] = f_iterl;
+ disp[GG_LEN_DDISP+BC_LOOP] = f_loop;
+
+ /* Set dynamic instruction dispatch. */
+ if ((oldmode ^ mode) & (DISPMODE_REC|DISPMODE_INS)) {
+ /* Need to update the whole table. */
+ if (!(mode & (DISPMODE_REC|DISPMODE_INS))) { /* No ins dispatch? */
+ /* Copy static dispatch table to dynamic dispatch table. */
+ memcpy(&disp[0], &disp[GG_LEN_DDISP], GG_LEN_SDISP*sizeof(ASMFunction));
+ /* Overwrite with dynamic return dispatch. */
+ if ((mode & DISPMODE_RET)) {
+ disp[BC_RETM] = lj_vm_rethook;
+ disp[BC_RET] = lj_vm_rethook;
+ disp[BC_RET0] = lj_vm_rethook;
+ disp[BC_RET1] = lj_vm_rethook;
+ }
+ } else {
+ /* The recording dispatch also checks for hooks. */
+ ASMFunction f = (mode & DISPMODE_REC) ? lj_vm_record : lj_vm_inshook;
+ uint32_t i;
+ for (i = 0; i < GG_LEN_SDISP; i++)
+ disp[i] = f;
+ }
+ } else if (!(mode & (DISPMODE_REC|DISPMODE_INS))) {
+ /* Otherwise set dynamic counting ins. */
+ disp[BC_FORL] = f_forl;
+ disp[BC_ITERL] = f_iterl;
+ disp[BC_LOOP] = f_loop;
+ /* Set dynamic return dispatch. */
+ if ((mode & DISPMODE_RET)) {
+ disp[BC_RETM] = lj_vm_rethook;
+ disp[BC_RET] = lj_vm_rethook;
+ disp[BC_RET0] = lj_vm_rethook;
+ disp[BC_RET1] = lj_vm_rethook;
+ } else {
+ disp[BC_RETM] = disp[GG_LEN_DDISP+BC_RETM];
+ disp[BC_RET] = disp[GG_LEN_DDISP+BC_RET];
+ disp[BC_RET0] = disp[GG_LEN_DDISP+BC_RET0];
+ disp[BC_RET1] = disp[GG_LEN_DDISP+BC_RET1];
+ }
+ }
+
+ /* Set dynamic call dispatch. */
+ if ((oldmode ^ mode) & DISPMODE_CALL) { /* Update the whole table? */
+ uint32_t i;
+ if ((mode & DISPMODE_CALL) == 0) { /* No call hooks? */
+ for (i = GG_LEN_SDISP; i < GG_LEN_DDISP; i++)
+ disp[i] = makeasmfunc(lj_bc_ofs[i]);
+ } else {
+ for (i = GG_LEN_SDISP; i < GG_LEN_DDISP; i++)
+ disp[i] = lj_vm_callhook;
+ }
+ }
+ if (!(mode & DISPMODE_CALL)) { /* Overwrite dynamic counting ins. */
+ disp[BC_FUNCF] = f_funcf;
+ disp[BC_FUNCV] = f_funcv;
+ }
+
+#if LJ_HASJIT
+ /* Reset hotcounts for JIT off to on transition. */
+ if ((mode & DISPMODE_JIT) && !(oldmode & DISPMODE_JIT))
+ lj_dispatch_init_hotcount(g);
+#endif
+ }
+}
+
+/* -- JIT mode setting ---------------------------------------------------- */
+
+#if LJ_HASJIT
+/* Set JIT mode for a single prototype. */
+static void setptmode(global_State *g, GCproto *pt, int mode)
+{
+ if ((mode & LUAJIT_MODE_ON)) { /* (Re-)enable JIT compilation. */
+ pt->flags &= ~PROTO_NOJIT;
+ lj_trace_reenableproto(pt); /* Unpatch all ILOOP etc. bytecodes. */
+ } else { /* Flush and/or disable JIT compilation. */
+ if (!(mode & LUAJIT_MODE_FLUSH))
+ pt->flags |= PROTO_NOJIT;
+ lj_trace_flushproto(g, pt); /* Flush all traces of prototype. */
+ }
+}
+
+/* Recursively set the JIT mode for all children of a prototype. */
+static void setptmode_all(global_State *g, GCproto *pt, int mode)
+{
+ ptrdiff_t i;
+ if (!(pt->flags & PROTO_CHILD)) return;
+ for (i = -(ptrdiff_t)pt->sizekgc; i < 0; i++) {
+ GCobj *o = proto_kgc(pt, i);
+ if (o->gch.gct == ~LJ_TPROTO) {
+ setptmode(g, gco2pt(o), mode);
+ setptmode_all(g, gco2pt(o), mode);
+ }
+ }
+}
+#endif
+
+/* Public API function: control the JIT engine. */
+int luaJIT_setmode(lua_State *L, int idx, int mode)
+{
+ global_State *g = G(L);
+ int mm = mode & LUAJIT_MODE_MASK;
+ lj_trace_abort(g); /* Abort recording on any state change. */
+ /* Avoid pulling the rug from under our own feet. */
+ if ((g->hookmask & HOOK_GC))
+ lj_err_caller(L, LJ_ERR_NOGCMM);
+ switch (mm) {
+#if LJ_HASJIT
+ case LUAJIT_MODE_ENGINE:
+ if ((mode & LUAJIT_MODE_FLUSH)) {
+ lj_trace_flushall(L);
+ } else {
+ if (!(mode & LUAJIT_MODE_ON))
+ G2J(g)->flags &= ~(uint32_t)JIT_F_ON;
+#if LJ_TARGET_X86ORX64
+ else if ((G2J(g)->flags & JIT_F_SSE2))
+ G2J(g)->flags |= (uint32_t)JIT_F_ON;
+ else
+ return 0; /* Don't turn on JIT compiler without SSE2 support. */
+#else
+ else
+ G2J(g)->flags |= (uint32_t)JIT_F_ON;
+#endif
+ lj_dispatch_update(g);
+ }
+ break;
+ case LUAJIT_MODE_FUNC:
+ case LUAJIT_MODE_ALLFUNC:
+ case LUAJIT_MODE_ALLSUBFUNC: {
+ cTValue *tv = idx == 0 ? frame_prev(L->base-1) :
+ idx > 0 ? L->base + (idx-1) : L->top + idx;
+ GCproto *pt;
+ if ((idx == 0 || tvisfunc(tv)) && isluafunc(&gcval(tv)->fn))
+ pt = funcproto(&gcval(tv)->fn); /* Cannot use funcV() for frame slot. */
+ else if (tvisproto(tv))
+ pt = protoV(tv);
+ else
+ return 0; /* Failed. */
+ if (mm != LUAJIT_MODE_ALLSUBFUNC)
+ setptmode(g, pt, mode);
+ if (mm != LUAJIT_MODE_FUNC)
+ setptmode_all(g, pt, mode);
+ break;
+ }
+ case LUAJIT_MODE_TRACE:
+ if (!(mode & LUAJIT_MODE_FLUSH))
+ return 0; /* Failed. */
+ lj_trace_flush(G2J(g), idx);
+ break;
+#else
+ case LUAJIT_MODE_ENGINE:
+ case LUAJIT_MODE_FUNC:
+ case LUAJIT_MODE_ALLFUNC:
+ case LUAJIT_MODE_ALLSUBFUNC:
+ UNUSED(idx);
+ if ((mode & LUAJIT_MODE_ON))
+ return 0; /* Failed. */
+ break;
+#endif
+ case LUAJIT_MODE_WRAPCFUNC:
+ if ((mode & LUAJIT_MODE_ON)) {
+ if (idx != 0) {
+ cTValue *tv = idx > 0 ? L->base + (idx-1) : L->top + idx;
+ if (tvislightud(tv))
+ g->wrapf = (lua_CFunction)lightudV(tv);
+ else
+ return 0; /* Failed. */
+ } else {
+ return 0; /* Failed. */
+ }
+ g->bc_cfunc_ext = BCINS_AD(BC_FUNCCW, 0, 0);
+ } else {
+ g->bc_cfunc_ext = BCINS_AD(BC_FUNCC, 0, 0);
+ }
+ break;
+ default:
+ return 0; /* Failed. */
+ }
+ return 1; /* OK. */
+}
+
+/* Enforce (dynamic) linker error for version mismatches. See luajit.c. */
+LUA_API void LUAJIT_VERSION_SYM(void)
+{
+}
+
+/* -- Hooks --------------------------------------------------------------- */
+
+/* This function can be called asynchronously (e.g. during a signal). */
+LUA_API int lua_sethook(lua_State *L, lua_Hook func, int mask, int count)
+{
+ global_State *g = G(L);
+ mask &= HOOK_EVENTMASK;
+ if (func == NULL || mask == 0) { mask = 0; func = NULL; } /* Consistency. */
+ g->hookf = func;
+ g->hookcount = g->hookcstart = (int32_t)count;
+ g->hookmask = (uint8_t)((g->hookmask & ~HOOK_EVENTMASK) | mask);
+ lj_trace_abort(g); /* Abort recording on any hook change. */
+ lj_dispatch_update(g);
+ return 1;
+}
+
+LUA_API lua_Hook lua_gethook(lua_State *L)
+{
+ return G(L)->hookf;
+}
+
+LUA_API int lua_gethookmask(lua_State *L)
+{
+ return G(L)->hookmask & HOOK_EVENTMASK;
+}
+
+LUA_API int lua_gethookcount(lua_State *L)
+{
+ return (int)G(L)->hookcstart;
+}
+
+/* Call a hook. */
+static void callhook(lua_State *L, int event, BCLine line)
+{
+ global_State *g = G(L);
+ lua_Hook hookf = g->hookf;
+ if (hookf && !hook_active(g)) {
+ lua_Debug ar;
+ lj_trace_abort(g); /* Abort recording on any hook call. */
+ ar.event = event;
+ ar.currentline = line;
+ /* Top frame, nextframe = NULL. */
+ ar.i_ci = (int)((L->base-1) - tvref(L->stack));
+ lj_state_checkstack(L, 1+LUA_MINSTACK);
+ hook_enter(g);
+ hookf(L, &ar);
+ lua_assert(hook_active(g));
+ hook_leave(g);
+ }
+}
+
+/* -- Dispatch callbacks -------------------------------------------------- */
+
+/* Calculate number of used stack slots in the current frame. */
+static BCReg cur_topslot(GCproto *pt, const BCIns *pc, uint32_t nres)
+{
+ BCIns ins = pc[-1];
+ if (bc_op(ins) == BC_UCLO)
+ ins = pc[bc_j(ins)];
+ switch (bc_op(ins)) {
+ case BC_CALLM: case BC_CALLMT: return bc_a(ins) + bc_c(ins) + nres-1+1;
+ case BC_RETM: return bc_a(ins) + bc_d(ins) + nres-1;
+ case BC_TSETM: return bc_a(ins) + nres-1;
+ default: return pt->framesize;
+ }
+}
+
+/* Instruction dispatch. Used by instr/line/return hooks or when recording. */
+void LJ_FASTCALL lj_dispatch_ins(lua_State *L, const BCIns *pc)
+{
+ ERRNO_SAVE
+ GCfunc *fn = curr_func(L);
+ GCproto *pt = funcproto(fn);
+ void *cf = cframe_raw(L->cframe);
+ const BCIns *oldpc = cframe_pc(cf);
+ global_State *g = G(L);
+ BCReg slots;
+ setcframe_pc(cf, pc);
+ slots = cur_topslot(pt, pc, cframe_multres_n(cf));
+ L->top = L->base + slots; /* Fix top. */
+#if LJ_HASJIT
+ {
+ jit_State *J = G2J(g);
+ if (J->state != LJ_TRACE_IDLE) {
+#ifdef LUA_USE_ASSERT
+ ptrdiff_t delta = L->top - L->base;
+#endif
+ J->L = L;
+ lj_trace_ins(J, pc-1); /* The interpreter bytecode PC is offset by 1. */
+ lua_assert(L->top - L->base == delta);
+ }
+ }
+#endif
+ if ((g->hookmask & LUA_MASKCOUNT) && g->hookcount == 0) {
+ g->hookcount = g->hookcstart;
+ callhook(L, LUA_HOOKCOUNT, -1);
+ L->top = L->base + slots; /* Fix top again. */
+ }
+ if ((g->hookmask & LUA_MASKLINE)) {
+ BCPos npc = proto_bcpos(pt, pc) - 1;
+ BCPos opc = proto_bcpos(pt, oldpc) - 1;
+ BCLine line = lj_debug_line(pt, npc);
+ if (pc <= oldpc || opc >= pt->sizebc || line != lj_debug_line(pt, opc)) {
+ callhook(L, LUA_HOOKLINE, line);
+ L->top = L->base + slots; /* Fix top again. */
+ }
+ }
+ if ((g->hookmask & LUA_MASKRET) && bc_isret(bc_op(pc[-1])))
+ callhook(L, LUA_HOOKRET, -1);
+ ERRNO_RESTORE
+}
+
+/* Initialize call. Ensure stack space and return # of missing parameters. */
+static int call_init(lua_State *L, GCfunc *fn)
+{
+ if (isluafunc(fn)) {
+ GCproto *pt = funcproto(fn);
+ int numparams = pt->numparams;
+ int gotparams = (int)(L->top - L->base);
+ int need = pt->framesize;
+ if ((pt->flags & PROTO_VARARG)) need += 1+gotparams;
+ lj_state_checkstack(L, (MSize)need);
+ numparams -= gotparams;
+ return numparams >= 0 ? numparams : 0;
+ } else {
+ lj_state_checkstack(L, LUA_MINSTACK);
+ return 0;
+ }
+}
+
+/* Call dispatch. Used by call hooks, hot calls or when recording. */
+ASMFunction LJ_FASTCALL lj_dispatch_call(lua_State *L, const BCIns *pc)
+{
+ ERRNO_SAVE
+ GCfunc *fn = curr_func(L);
+ BCOp op;
+ global_State *g = G(L);
+#if LJ_HASJIT
+ jit_State *J = G2J(g);
+#endif
+ int missing = call_init(L, fn);
+#if LJ_HASJIT
+ J->L = L;
+ if ((uintptr_t)pc & 1) { /* Marker for hot call. */
+#ifdef LUA_USE_ASSERT
+ ptrdiff_t delta = L->top - L->base;
+#endif
+ pc = (const BCIns *)((uintptr_t)pc & ~(uintptr_t)1);
+ lj_trace_hot(J, pc);
+ lua_assert(L->top - L->base == delta);
+ goto out;
+ } else if (J->state != LJ_TRACE_IDLE &&
+ !(g->hookmask & (HOOK_GC|HOOK_VMEVENT))) {
+#ifdef LUA_USE_ASSERT
+ ptrdiff_t delta = L->top - L->base;
+#endif
+ /* Record the FUNC* bytecodes, too. */
+ lj_trace_ins(J, pc-1); /* The interpreter bytecode PC is offset by 1. */
+ lua_assert(L->top - L->base == delta);
+ }
+#endif
+ if ((g->hookmask & LUA_MASKCALL)) {
+ int i;
+ for (i = 0; i < missing; i++) /* Add missing parameters. */
+ setnilV(L->top++);
+ callhook(L, LUA_HOOKCALL, -1);
+ /* Preserve modifications of missing parameters by lua_setlocal(). */
+ while (missing-- > 0 && tvisnil(L->top - 1))
+ L->top--;
+ }
+#if LJ_HASJIT
+out:
+#endif
+ op = bc_op(pc[-1]); /* Get FUNC* op. */
+#if LJ_HASJIT
+ /* Use the non-hotcounting variants if JIT is off or while recording. */
+ if ((!(J->flags & JIT_F_ON) || J->state != LJ_TRACE_IDLE) &&
+ (op == BC_FUNCF || op == BC_FUNCV))
+ op = (BCOp)((int)op+(int)BC_IFUNCF-(int)BC_FUNCF);
+#endif
+ ERRNO_RESTORE
+ return makeasmfunc(lj_bc_ofs[op]); /* Return static dispatch target. */
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_dispatch.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_dispatch.h
new file mode 100644
index 0000000..e46a0ee
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_dispatch.h
@@ -0,0 +1,131 @@
+/*
+** Instruction dispatch handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_DISPATCH_H
+#define _LJ_DISPATCH_H
+
+#include "lj_obj.h"
+#include "lj_bc.h"
+#if LJ_HASJIT
+#include "lj_jit.h"
+#endif
+
+#if LJ_TARGET_MIPS
+/* Need our own global offset table for the dreaded MIPS calling conventions. */
+#if LJ_HASJIT
+#define JITGOTDEF(_) _(lj_trace_exit) _(lj_trace_hot)
+#else
+#define JITGOTDEF(_)
+#endif
+#if LJ_HASFFI
+#define FFIGOTDEF(_) \
+ _(lj_meta_equal_cd) _(lj_ccallback_enter) _(lj_ccallback_leave)
+#else
+#define FFIGOTDEF(_)
+#endif
+#define GOTDEF(_) \
+ _(floor) _(ceil) _(trunc) _(log) _(log10) _(exp) _(sin) _(cos) _(tan) \
+ _(asin) _(acos) _(atan) _(sinh) _(cosh) _(tanh) _(frexp) _(modf) _(atan2) \
+ _(pow) _(fmod) _(ldexp) \
+ _(lj_dispatch_call) _(lj_dispatch_ins) _(lj_err_throw) \
+ _(lj_ffh_coroutine_wrap_err) _(lj_func_closeuv) _(lj_func_newL_gc) \
+ _(lj_gc_barrieruv) _(lj_gc_step) _(lj_gc_step_fixtop) _(lj_meta_arith) \
+ _(lj_meta_call) _(lj_meta_cat) _(lj_meta_comp) _(lj_meta_equal) \
+ _(lj_meta_for) _(lj_meta_len) _(lj_meta_tget) _(lj_meta_tset) \
+ _(lj_state_growstack) _(lj_str_fromnum) _(lj_str_fromnumber) _(lj_str_new) \
+ _(lj_tab_dup) _(lj_tab_get) _(lj_tab_getinth) _(lj_tab_len) _(lj_tab_new) \
+ _(lj_tab_newkey) _(lj_tab_next) _(lj_tab_reasize) \
+ JITGOTDEF(_) FFIGOTDEF(_)
+
+enum {
+#define GOTENUM(name) LJ_GOT_##name,
+GOTDEF(GOTENUM)
+#undef GOTENUM
+ LJ_GOT__MAX
+};
+#endif
+
+/* Type of hot counter. Must match the code in the assembler VM. */
+/* 16 bits are sufficient. Only 0.0015% overhead with maximum slot penalty. */
+typedef uint16_t HotCount;
+
+/* Number of hot counter hash table entries (must be a power of two). */
+#define HOTCOUNT_SIZE 64
+#define HOTCOUNT_PCMASK ((HOTCOUNT_SIZE-1)*sizeof(HotCount))
+
+/* Hotcount decrements. */
+#define HOTCOUNT_LOOP 2
+#define HOTCOUNT_CALL 1
+
+/* This solves a circular dependency problem -- bump as needed. Sigh. */
+#define GG_NUM_ASMFF 62
+
+#define GG_LEN_DDISP (BC__MAX + GG_NUM_ASMFF)
+#define GG_LEN_SDISP BC_FUNCF
+#define GG_LEN_DISP (GG_LEN_DDISP + GG_LEN_SDISP)
+
+/* Global state, main thread and extra fields are allocated together. */
+typedef struct GG_State {
+ lua_State L; /* Main thread. */
+ global_State g; /* Global state. */
+#if LJ_TARGET_MIPS
+ ASMFunction got[LJ_GOT__MAX]; /* Global offset table. */
+#endif
+#if LJ_HASJIT
+ jit_State J; /* JIT state. */
+ HotCount hotcount[HOTCOUNT_SIZE]; /* Hot counters. */
+#endif
+ ASMFunction dispatch[GG_LEN_DISP]; /* Instruction dispatch tables. */
+ BCIns bcff[GG_NUM_ASMFF]; /* Bytecode for ASM fast functions. */
+} GG_State;
+
+#define GG_OFS(field) ((int)offsetof(GG_State, field))
+#define G2GG(gl) ((GG_State *)((char *)(gl) - GG_OFS(g)))
+#define J2GG(j) ((GG_State *)((char *)(j) - GG_OFS(J)))
+#define L2GG(L) (G2GG(G(L)))
+#define J2G(J) (&J2GG(J)->g)
+#define G2J(gl) (&G2GG(gl)->J)
+#define L2J(L) (&L2GG(L)->J)
+#define GG_G2DISP (GG_OFS(dispatch) - GG_OFS(g))
+#define GG_DISP2G (GG_OFS(g) - GG_OFS(dispatch))
+#define GG_DISP2J (GG_OFS(J) - GG_OFS(dispatch))
+#define GG_DISP2HOT (GG_OFS(hotcount) - GG_OFS(dispatch))
+#define GG_DISP2STATIC (GG_LEN_DDISP*(int)sizeof(ASMFunction))
+
+#define hotcount_get(gg, pc) \
+ (gg)->hotcount[(u32ptr(pc)>>2) & (HOTCOUNT_SIZE-1)]
+#define hotcount_set(gg, pc, val) \
+ (hotcount_get((gg), (pc)) = (HotCount)(val))
+
+/* Dispatch table management. */
+LJ_FUNC void lj_dispatch_init(GG_State *GG);
+#if LJ_HASJIT
+LJ_FUNC void lj_dispatch_init_hotcount(global_State *g);
+#endif
+LJ_FUNC void lj_dispatch_update(global_State *g);
+
+/* Instruction dispatch callback for hooks or when recording. */
+LJ_FUNCA void LJ_FASTCALL lj_dispatch_ins(lua_State *L, const BCIns *pc);
+LJ_FUNCA ASMFunction LJ_FASTCALL lj_dispatch_call(lua_State *L, const BCIns*pc);
+LJ_FUNCA void LJ_FASTCALL lj_dispatch_return(lua_State *L, const BCIns *pc);
+
+#if LJ_HASFFI && !defined(_BUILDVM_H)
+/* Save/restore errno and GetLastError() around hooks, exits and recording. */
+#include <errno.h>
+#if LJ_TARGET_WINDOWS
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#define ERRNO_SAVE int olderr = errno; DWORD oldwerr = GetLastError();
+#define ERRNO_RESTORE errno = olderr; SetLastError(oldwerr);
+#else
+#define ERRNO_SAVE int olderr = errno;
+#define ERRNO_RESTORE errno = olderr;
+#endif
+#else
+#define ERRNO_SAVE
+#define ERRNO_RESTORE
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_emit_arm.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_emit_arm.h
new file mode 100644
index 0000000..285c98d
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_emit_arm.h
@@ -0,0 +1,356 @@
+/*
+** ARM instruction emitter.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* -- Constant encoding --------------------------------------------------- */
+
+static uint8_t emit_invai[16] = {
+ /* AND */ (ARMI_AND^ARMI_BIC) >> 21,
+ /* EOR */ 0,
+ /* SUB */ (ARMI_SUB^ARMI_ADD) >> 21,
+ /* RSB */ 0,
+ /* ADD */ (ARMI_ADD^ARMI_SUB) >> 21,
+ /* ADC */ (ARMI_ADC^ARMI_SBC) >> 21,
+ /* SBC */ (ARMI_SBC^ARMI_ADC) >> 21,
+ /* RSC */ 0,
+ /* TST */ 0,
+ /* TEQ */ 0,
+ /* CMP */ (ARMI_CMP^ARMI_CMN) >> 21,
+ /* CMN */ (ARMI_CMN^ARMI_CMP) >> 21,
+ /* ORR */ 0,
+ /* MOV */ (ARMI_MOV^ARMI_MVN) >> 21,
+ /* BIC */ (ARMI_BIC^ARMI_AND) >> 21,
+ /* MVN */ (ARMI_MVN^ARMI_MOV) >> 21
+};
+
+/* Encode constant in K12 format for data processing instructions. */
+static uint32_t emit_isk12(ARMIns ai, int32_t n)
+{
+ uint32_t invai, i, m = (uint32_t)n;
+ /* K12: unsigned 8 bit value, rotated in steps of two bits. */
+ for (i = 0; i < 4096; i += 256, m = lj_rol(m, 2))
+ if (m <= 255) return ARMI_K12|m|i;
+ /* Otherwise try negation/complement with the inverse instruction. */
+ invai = emit_invai[((ai >> 21) & 15)];
+ if (!invai) return 0; /* Failed. No inverse instruction. */
+ m = ~(uint32_t)n;
+ if (invai == ((ARMI_SUB^ARMI_ADD) >> 21) ||
+ invai == (ARMI_CMP^ARMI_CMN) >> 21) m++;
+ for (i = 0; i < 4096; i += 256, m = lj_rol(m, 2))
+ if (m <= 255) return ARMI_K12|(invai<<21)|m|i;
+ return 0; /* Failed. */
+}
+
+/* -- Emit basic instructions --------------------------------------------- */
+
+static void emit_dnm(ASMState *as, ARMIns ai, Reg rd, Reg rn, Reg rm)
+{
+ *--as->mcp = ai | ARMF_D(rd) | ARMF_N(rn) | ARMF_M(rm);
+}
+
+static void emit_dm(ASMState *as, ARMIns ai, Reg rd, Reg rm)
+{
+ *--as->mcp = ai | ARMF_D(rd) | ARMF_M(rm);
+}
+
+static void emit_dn(ASMState *as, ARMIns ai, Reg rd, Reg rn)
+{
+ *--as->mcp = ai | ARMF_D(rd) | ARMF_N(rn);
+}
+
+static void emit_nm(ASMState *as, ARMIns ai, Reg rn, Reg rm)
+{
+ *--as->mcp = ai | ARMF_N(rn) | ARMF_M(rm);
+}
+
+static void emit_d(ASMState *as, ARMIns ai, Reg rd)
+{
+ *--as->mcp = ai | ARMF_D(rd);
+}
+
+static void emit_n(ASMState *as, ARMIns ai, Reg rn)
+{
+ *--as->mcp = ai | ARMF_N(rn);
+}
+
+static void emit_m(ASMState *as, ARMIns ai, Reg rm)
+{
+ *--as->mcp = ai | ARMF_M(rm);
+}
+
+static void emit_lsox(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs)
+{
+ lua_assert(ofs >= -255 && ofs <= 255);
+ if (ofs < 0) ofs = -ofs; else ai |= ARMI_LS_U;
+ *--as->mcp = ai | ARMI_LS_P | ARMI_LSX_I | ARMF_D(rd) | ARMF_N(rn) |
+ ((ofs & 0xf0) << 4) | (ofs & 0x0f);
+}
+
+static void emit_lso(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs)
+{
+ lua_assert(ofs >= -4095 && ofs <= 4095);
+ /* Combine LDR/STR pairs to LDRD/STRD. */
+ if (*as->mcp == (ai|ARMI_LS_P|ARMI_LS_U|ARMF_D(rd^1)|ARMF_N(rn)|(ofs^4)) &&
+ (ai & ~(ARMI_LDR^ARMI_STR)) == ARMI_STR && rd != rn &&
+ (uint32_t)ofs <= 252 && !(ofs & 3) && !((rd ^ (ofs >>2)) & 1) &&
+ as->mcp != as->mcloop) {
+ as->mcp++;
+ emit_lsox(as, ai == ARMI_LDR ? ARMI_LDRD : ARMI_STRD, rd&~1, rn, ofs&~4);
+ return;
+ }
+ if (ofs < 0) ofs = -ofs; else ai |= ARMI_LS_U;
+ *--as->mcp = ai | ARMI_LS_P | ARMF_D(rd) | ARMF_N(rn) | ofs;
+}
+
+#if !LJ_SOFTFP
+static void emit_vlso(ASMState *as, ARMIns ai, Reg rd, Reg rn, int32_t ofs)
+{
+ lua_assert(ofs >= -1020 && ofs <= 1020 && (ofs&3) == 0);
+ if (ofs < 0) ofs = -ofs; else ai |= ARMI_LS_U;
+ *--as->mcp = ai | ARMI_LS_P | ARMF_D(rd & 15) | ARMF_N(rn) | (ofs >> 2);
+}
+#endif
+
+/* -- Emit loads/stores --------------------------------------------------- */
+
+/* Prefer spills of BASE/L. */
+#define emit_canremat(ref) ((ref) < ASMREF_L)
+
+/* Try to find a one step delta relative to another constant. */
+static int emit_kdelta1(ASMState *as, Reg d, int32_t i)
+{
+ RegSet work = ~as->freeset & RSET_GPR;
+ while (work) {
+ Reg r = rset_picktop(work);
+ IRRef ref = regcost_ref(as->cost[r]);
+ lua_assert(r != d);
+ if (emit_canremat(ref)) {
+ int32_t delta = i - (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i);
+ uint32_t k = emit_isk12(ARMI_ADD, delta);
+ if (k) {
+ if (k == ARMI_K12)
+ emit_dm(as, ARMI_MOV, d, r);
+ else
+ emit_dn(as, ARMI_ADD^k, d, r);
+ return 1;
+ }
+ }
+ rset_clear(work, r);
+ }
+ return 0; /* Failed. */
+}
+
+/* Try to find a two step delta relative to another constant. */
+static int emit_kdelta2(ASMState *as, Reg d, int32_t i)
+{
+ RegSet work = ~as->freeset & RSET_GPR;
+ while (work) {
+ Reg r = rset_picktop(work);
+ IRRef ref = regcost_ref(as->cost[r]);
+ lua_assert(r != d);
+ if (emit_canremat(ref)) {
+ int32_t other = ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i;
+ if (other) {
+ int32_t delta = i - other;
+ uint32_t sh, inv = 0, k2, k;
+ if (delta < 0) { delta = -delta; inv = ARMI_ADD^ARMI_SUB; }
+ sh = lj_ffs(delta) & ~1;
+ k2 = emit_isk12(0, delta & (255 << sh));
+ k = emit_isk12(0, delta & ~(255 << sh));
+ if (k) {
+ emit_dn(as, ARMI_ADD^k2^inv, d, d);
+ emit_dn(as, ARMI_ADD^k^inv, d, r);
+ return 1;
+ }
+ }
+ }
+ rset_clear(work, r);
+ }
+ return 0; /* Failed. */
+}
+
+/* Load a 32 bit constant into a GPR. */
+static void emit_loadi(ASMState *as, Reg r, int32_t i)
+{
+ uint32_t k = emit_isk12(ARMI_MOV, i);
+ lua_assert(rset_test(as->freeset, r) || r == RID_TMP);
+ if (k) {
+ /* Standard K12 constant. */
+ emit_d(as, ARMI_MOV^k, r);
+ } else if ((as->flags & JIT_F_ARMV6T2) && (uint32_t)i < 0x00010000u) {
+ /* 16 bit loword constant for ARMv6T2. */
+ emit_d(as, ARMI_MOVW|(i & 0x0fff)|((i & 0xf000)<<4), r);
+ } else if (emit_kdelta1(as, r, i)) {
+ /* One step delta relative to another constant. */
+ } else if ((as->flags & JIT_F_ARMV6T2)) {
+ /* 32 bit hiword/loword constant for ARMv6T2. */
+ emit_d(as, ARMI_MOVT|((i>>16) & 0x0fff)|(((i>>16) & 0xf000)<<4), r);
+ emit_d(as, ARMI_MOVW|(i & 0x0fff)|((i & 0xf000)<<4), r);
+ } else if (emit_kdelta2(as, r, i)) {
+ /* Two step delta relative to another constant. */
+ } else {
+ /* Otherwise construct the constant with up to 4 instructions. */
+ /* NYI: use mvn+bic, use pc-relative loads. */
+ for (;;) {
+ uint32_t sh = lj_ffs(i) & ~1;
+ int32_t m = i & (255 << sh);
+ i &= ~(255 << sh);
+ if (i == 0) {
+ emit_d(as, ARMI_MOV ^ emit_isk12(0, m), r);
+ break;
+ }
+ emit_dn(as, ARMI_ORR ^ emit_isk12(0, m), r, r);
+ }
+ }
+}
+
+#define emit_loada(as, r, addr) emit_loadi(as, (r), i32ptr((addr)))
+
+static Reg ra_allock(ASMState *as, int32_t k, RegSet allow);
+
+/* Get/set from constant pointer. */
+static void emit_lsptr(ASMState *as, ARMIns ai, Reg r, void *p)
+{
+ int32_t i = i32ptr(p);
+ emit_lso(as, ai, r, ra_allock(as, (i & ~4095), rset_exclude(RSET_GPR, r)),
+ (i & 4095));
+}
+
+#if !LJ_SOFTFP
+/* Load a number constant into an FPR. */
+static void emit_loadn(ASMState *as, Reg r, cTValue *tv)
+{
+ int32_t i;
+ if ((as->flags & JIT_F_VFPV3) && !tv->u32.lo) {
+ uint32_t hi = tv->u32.hi;
+ uint32_t b = ((hi >> 22) & 0x1ff);
+ if (!(hi & 0xffff) && (b == 0x100 || b == 0x0ff)) {
+ *--as->mcp = ARMI_VMOVI_D | ARMF_D(r & 15) |
+ ((tv->u32.hi >> 12) & 0x00080000) |
+ ((tv->u32.hi >> 4) & 0x00070000) |
+ ((tv->u32.hi >> 16) & 0x0000000f);
+ return;
+ }
+ }
+ i = i32ptr(tv);
+ emit_vlso(as, ARMI_VLDR_D, r,
+ ra_allock(as, (i & ~1020), RSET_GPR), (i & 1020));
+}
+#endif
+
+/* Get/set global_State fields. */
+#define emit_getgl(as, r, field) \
+ emit_lsptr(as, ARMI_LDR, (r), (void *)&J2G(as->J)->field)
+#define emit_setgl(as, r, field) \
+ emit_lsptr(as, ARMI_STR, (r), (void *)&J2G(as->J)->field)
+
+/* Trace number is determined from pc of exit instruction. */
+#define emit_setvmstate(as, i) UNUSED(i)
+
+/* -- Emit control-flow instructions -------------------------------------- */
+
+/* Label for internal jumps. */
+typedef MCode *MCLabel;
+
+/* Return label pointing to current PC. */
+#define emit_label(as) ((as)->mcp)
+
+static void emit_branch(ASMState *as, ARMIns ai, MCode *target)
+{
+ MCode *p = as->mcp;
+ ptrdiff_t delta = (target - p) - 1;
+ lua_assert(((delta + 0x00800000) >> 24) == 0);
+ *--p = ai | ((uint32_t)delta & 0x00ffffffu);
+ as->mcp = p;
+}
+
+#define emit_jmp(as, target) emit_branch(as, ARMI_B, (target))
+
+static void emit_call(ASMState *as, void *target)
+{
+ MCode *p = --as->mcp;
+ ptrdiff_t delta = ((char *)target - (char *)p) - 8;
+ if ((((delta>>2) + 0x00800000) >> 24) == 0) {
+ if ((delta & 1))
+ *p = ARMI_BLX | ((uint32_t)(delta>>2) & 0x00ffffffu) | ((delta&2) << 23);
+ else
+ *p = ARMI_BL | ((uint32_t)(delta>>2) & 0x00ffffffu);
+ } else { /* Target out of range: need indirect call. But don't use R0-R3. */
+ Reg r = ra_allock(as, i32ptr(target), RSET_RANGE(RID_R4, RID_R12+1));
+ *p = ARMI_BLXr | ARMF_M(r);
+ }
+}
+
+/* -- Emit generic operations --------------------------------------------- */
+
+/* Generic move between two regs. */
+static void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src)
+{
+#if LJ_SOFTFP
+ lua_assert(!irt_isnum(ir->t)); UNUSED(ir);
+#else
+ if (dst >= RID_MAX_GPR) {
+ emit_dm(as, irt_isnum(ir->t) ? ARMI_VMOV_D : ARMI_VMOV_S,
+ (dst & 15), (src & 15));
+ return;
+ }
+#endif
+ if (as->mcp != as->mcloop) { /* Swap early registers for loads/stores. */
+ MCode ins = *as->mcp, swp = (src^dst);
+ if ((ins & 0x0c000000) == 0x04000000 && (ins & 0x02000010) != 0x02000010) {
+ if (!((ins ^ (dst << 16)) & 0x000f0000))
+ *as->mcp = ins ^ (swp << 16); /* Swap N in load/store. */
+ if (!(ins & 0x00100000) && !((ins ^ (dst << 12)) & 0x0000f000))
+ *as->mcp = ins ^ (swp << 12); /* Swap D in store. */
+ }
+ }
+ emit_dm(as, ARMI_MOV, dst, src);
+}
+
+/* Generic load of register from stack slot. */
+static void emit_spload(ASMState *as, IRIns *ir, Reg r, int32_t ofs)
+{
+#if LJ_SOFTFP
+ lua_assert(!irt_isnum(ir->t)); UNUSED(ir);
+#else
+ if (r >= RID_MAX_GPR)
+ emit_vlso(as, irt_isnum(ir->t) ? ARMI_VLDR_D : ARMI_VLDR_S, r, RID_SP, ofs);
+ else
+#endif
+ emit_lso(as, ARMI_LDR, r, RID_SP, ofs);
+}
+
+/* Generic store of register to stack slot. */
+static void emit_spstore(ASMState *as, IRIns *ir, Reg r, int32_t ofs)
+{
+#if LJ_SOFTFP
+ lua_assert(!irt_isnum(ir->t)); UNUSED(ir);
+#else
+ if (r >= RID_MAX_GPR)
+ emit_vlso(as, irt_isnum(ir->t) ? ARMI_VSTR_D : ARMI_VSTR_S, r, RID_SP, ofs);
+ else
+#endif
+ emit_lso(as, ARMI_STR, r, RID_SP, ofs);
+}
+
+/* Emit an arithmetic/logic operation with a constant operand. */
+static void emit_opk(ASMState *as, ARMIns ai, Reg dest, Reg src,
+ int32_t i, RegSet allow)
+{
+ uint32_t k = emit_isk12(ai, i);
+ if (k)
+ emit_dn(as, ai^k, dest, src);
+ else
+ emit_dnm(as, ai, dest, src, ra_allock(as, i, allow));
+}
+
+/* Add offset to pointer. */
+static void emit_addptr(ASMState *as, Reg r, int32_t ofs)
+{
+ if (ofs)
+ emit_opk(as, ARMI_ADD, r, r, ofs, rset_exclude(RSET_GPR, r));
+}
+
+#define emit_spsub(as, ofs) emit_addptr(as, RID_SP, -(ofs))
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_emit_mips.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_emit_mips.h
new file mode 100644
index 0000000..ed62608
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_emit_mips.h
@@ -0,0 +1,211 @@
+/*
+** MIPS instruction emitter.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* -- Emit basic instructions --------------------------------------------- */
+
+static void emit_dst(ASMState *as, MIPSIns mi, Reg rd, Reg rs, Reg rt)
+{
+ *--as->mcp = mi | MIPSF_D(rd) | MIPSF_S(rs) | MIPSF_T(rt);
+}
+
+static void emit_dta(ASMState *as, MIPSIns mi, Reg rd, Reg rt, uint32_t a)
+{
+ *--as->mcp = mi | MIPSF_D(rd) | MIPSF_T(rt) | MIPSF_A(a);
+}
+
+#define emit_ds(as, mi, rd, rs) emit_dst(as, (mi), (rd), (rs), 0)
+#define emit_tg(as, mi, rt, rg) emit_dst(as, (mi), (rg)&31, 0, (rt))
+
+static void emit_tsi(ASMState *as, MIPSIns mi, Reg rt, Reg rs, int32_t i)
+{
+ *--as->mcp = mi | MIPSF_T(rt) | MIPSF_S(rs) | (i & 0xffff);
+}
+
+#define emit_ti(as, mi, rt, i) emit_tsi(as, (mi), (rt), 0, (i))
+#define emit_hsi(as, mi, rh, rs, i) emit_tsi(as, (mi), (rh) & 31, (rs), (i))
+
+static void emit_fgh(ASMState *as, MIPSIns mi, Reg rf, Reg rg, Reg rh)
+{
+ *--as->mcp = mi | MIPSF_F(rf&31) | MIPSF_G(rg&31) | MIPSF_H(rh&31);
+}
+
+#define emit_fg(as, mi, rf, rg) emit_fgh(as, (mi), (rf), (rg), 0)
+
+static void emit_rotr(ASMState *as, Reg dest, Reg src, Reg tmp, uint32_t shift)
+{
+ if ((as->flags & JIT_F_MIPS32R2)) {
+ emit_dta(as, MIPSI_ROTR, dest, src, shift);
+ } else {
+ emit_dst(as, MIPSI_OR, dest, dest, tmp);
+ emit_dta(as, MIPSI_SLL, dest, src, (-shift)&31);
+ emit_dta(as, MIPSI_SRL, tmp, src, shift);
+ }
+}
+
+/* -- Emit loads/stores --------------------------------------------------- */
+
+/* Prefer rematerialization of BASE/L from global_State over spills. */
+#define emit_canremat(ref) ((ref) <= REF_BASE)
+
+/* Try to find a one step delta relative to another constant. */
+static int emit_kdelta1(ASMState *as, Reg t, int32_t i)
+{
+ RegSet work = ~as->freeset & RSET_GPR;
+ while (work) {
+ Reg r = rset_picktop(work);
+ IRRef ref = regcost_ref(as->cost[r]);
+ lua_assert(r != t);
+ if (ref < ASMREF_L) {
+ int32_t delta = i - (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i);
+ if (checki16(delta)) {
+ emit_tsi(as, MIPSI_ADDIU, t, r, delta);
+ return 1;
+ }
+ }
+ rset_clear(work, r);
+ }
+ return 0; /* Failed. */
+}
+
+/* Load a 32 bit constant into a GPR. */
+static void emit_loadi(ASMState *as, Reg r, int32_t i)
+{
+ if (checki16(i)) {
+ emit_ti(as, MIPSI_LI, r, i);
+ } else {
+ if ((i & 0xffff)) {
+ int32_t jgl = i32ptr(J2G(as->J));
+ if ((uint32_t)(i-jgl) < 65536) {
+ emit_tsi(as, MIPSI_ADDIU, r, RID_JGL, i-jgl-32768);
+ return;
+ } else if (emit_kdelta1(as, r, i)) {
+ return;
+ } else if ((i >> 16) == 0) {
+ emit_tsi(as, MIPSI_ORI, r, RID_ZERO, i);
+ return;
+ }
+ emit_tsi(as, MIPSI_ORI, r, r, i);
+ }
+ emit_ti(as, MIPSI_LUI, r, (i >> 16));
+ }
+}
+
+#define emit_loada(as, r, addr) emit_loadi(as, (r), i32ptr((addr)))
+
+static Reg ra_allock(ASMState *as, int32_t k, RegSet allow);
+static void ra_allockreg(ASMState *as, int32_t k, Reg r);
+
+/* Get/set from constant pointer. */
+static void emit_lsptr(ASMState *as, MIPSIns mi, Reg r, void *p, RegSet allow)
+{
+ int32_t jgl = i32ptr(J2G(as->J));
+ int32_t i = i32ptr(p);
+ Reg base;
+ if ((uint32_t)(i-jgl) < 65536) {
+ i = i-jgl-32768;
+ base = RID_JGL;
+ } else {
+ base = ra_allock(as, i-(int16_t)i, allow);
+ }
+ emit_tsi(as, mi, r, base, i);
+}
+
+#define emit_loadn(as, r, tv) \
+ emit_lsptr(as, MIPSI_LDC1, ((r) & 31), (void *)(tv), RSET_GPR)
+
+/* Get/set global_State fields. */
+static void emit_lsglptr(ASMState *as, MIPSIns mi, Reg r, int32_t ofs)
+{
+ emit_tsi(as, mi, r, RID_JGL, ofs-32768);
+}
+
+#define emit_getgl(as, r, field) \
+ emit_lsglptr(as, MIPSI_LW, (r), (int32_t)offsetof(global_State, field))
+#define emit_setgl(as, r, field) \
+ emit_lsglptr(as, MIPSI_SW, (r), (int32_t)offsetof(global_State, field))
+
+/* Trace number is determined from per-trace exit stubs. */
+#define emit_setvmstate(as, i) UNUSED(i)
+
+/* -- Emit control-flow instructions -------------------------------------- */
+
+/* Label for internal jumps. */
+typedef MCode *MCLabel;
+
+/* Return label pointing to current PC. */
+#define emit_label(as) ((as)->mcp)
+
+static void emit_branch(ASMState *as, MIPSIns mi, Reg rs, Reg rt, MCode *target)
+{
+ MCode *p = as->mcp;
+ ptrdiff_t delta = target - p;
+ lua_assert(((delta + 0x8000) >> 16) == 0);
+ *--p = mi | MIPSF_S(rs) | MIPSF_T(rt) | ((uint32_t)delta & 0xffffu);
+ as->mcp = p;
+}
+
+static void emit_jmp(ASMState *as, MCode *target)
+{
+ *--as->mcp = MIPSI_NOP;
+ emit_branch(as, MIPSI_B, RID_ZERO, RID_ZERO, (target));
+}
+
+static void emit_call(ASMState *as, void *target)
+{
+ MCode *p = as->mcp;
+ *--p = MIPSI_NOP;
+ if ((((uintptr_t)target ^ (uintptr_t)p) >> 28) == 0)
+ *--p = MIPSI_JAL | (((uintptr_t)target >>2) & 0x03ffffffu);
+ else /* Target out of range: need indirect call. */
+ *--p = MIPSI_JALR | MIPSF_S(RID_CFUNCADDR);
+ as->mcp = p;
+ ra_allockreg(as, i32ptr(target), RID_CFUNCADDR);
+}
+
+/* -- Emit generic operations --------------------------------------------- */
+
+#define emit_move(as, dst, src) \
+ emit_ds(as, MIPSI_MOVE, (dst), (src))
+
+/* Generic move between two regs. */
+static void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src)
+{
+ if (dst < RID_MAX_GPR)
+ emit_move(as, dst, src);
+ else
+ emit_fg(as, irt_isnum(ir->t) ? MIPSI_MOV_D : MIPSI_MOV_S, dst, src);
+}
+
+/* Generic load of register from stack slot. */
+static void emit_spload(ASMState *as, IRIns *ir, Reg r, int32_t ofs)
+{
+ if (r < RID_MAX_GPR)
+ emit_tsi(as, MIPSI_LW, r, RID_SP, ofs);
+ else
+ emit_tsi(as, irt_isnum(ir->t) ? MIPSI_LDC1 : MIPSI_LWC1,
+ (r & 31), RID_SP, ofs);
+}
+
+/* Generic store of register to stack slot. */
+static void emit_spstore(ASMState *as, IRIns *ir, Reg r, int32_t ofs)
+{
+ if (r < RID_MAX_GPR)
+ emit_tsi(as, MIPSI_SW, r, RID_SP, ofs);
+ else
+ emit_tsi(as, irt_isnum(ir->t) ? MIPSI_SDC1 : MIPSI_SWC1,
+ (r&31), RID_SP, ofs);
+}
+
+/* Add offset to pointer. */
+static void emit_addptr(ASMState *as, Reg r, int32_t ofs)
+{
+ if (ofs) {
+ lua_assert(checki16(ofs));
+ emit_tsi(as, MIPSI_ADDIU, r, r, ofs);
+ }
+}
+
+#define emit_spsub(as, ofs) emit_addptr(as, RID_SP, -(ofs))
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_emit_ppc.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_emit_ppc.h
new file mode 100644
index 0000000..1409930
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_emit_ppc.h
@@ -0,0 +1,238 @@
+/*
+** PPC instruction emitter.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* -- Emit basic instructions --------------------------------------------- */
+
+static void emit_tab(ASMState *as, PPCIns pi, Reg rt, Reg ra, Reg rb)
+{
+ *--as->mcp = pi | PPCF_T(rt) | PPCF_A(ra) | PPCF_B(rb);
+}
+
+#define emit_asb(as, pi, ra, rs, rb) emit_tab(as, (pi), (rs), (ra), (rb))
+#define emit_as(as, pi, ra, rs) emit_tab(as, (pi), (rs), (ra), 0)
+#define emit_ab(as, pi, ra, rb) emit_tab(as, (pi), 0, (ra), (rb))
+
+static void emit_tai(ASMState *as, PPCIns pi, Reg rt, Reg ra, int32_t i)
+{
+ *--as->mcp = pi | PPCF_T(rt) | PPCF_A(ra) | (i & 0xffff);
+}
+
+#define emit_ti(as, pi, rt, i) emit_tai(as, (pi), (rt), 0, (i))
+#define emit_ai(as, pi, ra, i) emit_tai(as, (pi), 0, (ra), (i))
+#define emit_asi(as, pi, ra, rs, i) emit_tai(as, (pi), (rs), (ra), (i))
+
+#define emit_fab(as, pi, rf, ra, rb) \
+ emit_tab(as, (pi), (rf)&31, (ra)&31, (rb)&31)
+#define emit_fb(as, pi, rf, rb) emit_tab(as, (pi), (rf)&31, 0, (rb)&31)
+#define emit_fac(as, pi, rf, ra, rc) \
+ emit_tab(as, (pi) | PPCF_C((rc) & 31), (rf)&31, (ra)&31, 0)
+#define emit_facb(as, pi, rf, ra, rc, rb) \
+ emit_tab(as, (pi) | PPCF_C((rc) & 31), (rf)&31, (ra)&31, (rb)&31)
+#define emit_fai(as, pi, rf, ra, i) emit_tai(as, (pi), (rf)&31, (ra), (i))
+
+static void emit_rot(ASMState *as, PPCIns pi, Reg ra, Reg rs,
+ int32_t n, int32_t b, int32_t e)
+{
+ *--as->mcp = pi | PPCF_T(rs) | PPCF_A(ra) | PPCF_B(n) |
+ PPCF_MB(b) | PPCF_ME(e);
+}
+
+static void emit_slwi(ASMState *as, Reg ra, Reg rs, int32_t n)
+{
+ lua_assert(n >= 0 && n < 32);
+ emit_rot(as, PPCI_RLWINM, ra, rs, n, 0, 31-n);
+}
+
+static void emit_rotlwi(ASMState *as, Reg ra, Reg rs, int32_t n)
+{
+ lua_assert(n >= 0 && n < 32);
+ emit_rot(as, PPCI_RLWINM, ra, rs, n, 0, 31);
+}
+
+/* -- Emit loads/stores --------------------------------------------------- */
+
+/* Prefer rematerialization of BASE/L from global_State over spills. */
+#define emit_canremat(ref) ((ref) <= REF_BASE)
+
+/* Try to find a one step delta relative to another constant. */
+static int emit_kdelta1(ASMState *as, Reg t, int32_t i)
+{
+ RegSet work = ~as->freeset & RSET_GPR;
+ while (work) {
+ Reg r = rset_picktop(work);
+ IRRef ref = regcost_ref(as->cost[r]);
+ lua_assert(r != t);
+ if (ref < ASMREF_L) {
+ int32_t delta = i - (ra_iskref(ref) ? ra_krefk(as, ref) : IR(ref)->i);
+ if (checki16(delta)) {
+ emit_tai(as, PPCI_ADDI, t, r, delta);
+ return 1;
+ }
+ }
+ rset_clear(work, r);
+ }
+ return 0; /* Failed. */
+}
+
+/* Load a 32 bit constant into a GPR. */
+static void emit_loadi(ASMState *as, Reg r, int32_t i)
+{
+ if (checki16(i)) {
+ emit_ti(as, PPCI_LI, r, i);
+ } else {
+ if ((i & 0xffff)) {
+ int32_t jgl = i32ptr(J2G(as->J));
+ if ((uint32_t)(i-jgl) < 65536) {
+ emit_tai(as, PPCI_ADDI, r, RID_JGL, i-jgl-32768);
+ return;
+ } else if (emit_kdelta1(as, r, i)) {
+ return;
+ }
+ emit_asi(as, PPCI_ORI, r, r, i);
+ }
+ emit_ti(as, PPCI_LIS, r, (i >> 16));
+ }
+}
+
+#define emit_loada(as, r, addr) emit_loadi(as, (r), i32ptr((addr)))
+
+static Reg ra_allock(ASMState *as, int32_t k, RegSet allow);
+
+/* Get/set from constant pointer. */
+static void emit_lsptr(ASMState *as, PPCIns pi, Reg r, void *p, RegSet allow)
+{
+ int32_t jgl = i32ptr(J2G(as->J));
+ int32_t i = i32ptr(p);
+ Reg base;
+ if ((uint32_t)(i-jgl) < 65536) {
+ i = i-jgl-32768;
+ base = RID_JGL;
+ } else {
+ base = ra_allock(as, i-(int16_t)i, allow);
+ }
+ emit_tai(as, pi, r, base, i);
+}
+
+#define emit_loadn(as, r, tv) \
+ emit_lsptr(as, PPCI_LFD, ((r) & 31), (void *)(tv), RSET_GPR)
+
+/* Get/set global_State fields. */
+static void emit_lsglptr(ASMState *as, PPCIns pi, Reg r, int32_t ofs)
+{
+ emit_tai(as, pi, r, RID_JGL, ofs-32768);
+}
+
+#define emit_getgl(as, r, field) \
+ emit_lsglptr(as, PPCI_LWZ, (r), (int32_t)offsetof(global_State, field))
+#define emit_setgl(as, r, field) \
+ emit_lsglptr(as, PPCI_STW, (r), (int32_t)offsetof(global_State, field))
+
+/* Trace number is determined from per-trace exit stubs. */
+#define emit_setvmstate(as, i) UNUSED(i)
+
+/* -- Emit control-flow instructions -------------------------------------- */
+
+/* Label for internal jumps. */
+typedef MCode *MCLabel;
+
+/* Return label pointing to current PC. */
+#define emit_label(as) ((as)->mcp)
+
+static void emit_condbranch(ASMState *as, PPCIns pi, PPCCC cc, MCode *target)
+{
+ MCode *p = --as->mcp;
+ ptrdiff_t delta = (char *)target - (char *)p;
+ lua_assert(((delta + 0x8000) >> 16) == 0);
+ pi ^= (delta & 0x8000) * (PPCF_Y/0x8000);
+ *p = pi | PPCF_CC(cc) | ((uint32_t)delta & 0xffffu);
+}
+
+static void emit_jmp(ASMState *as, MCode *target)
+{
+ MCode *p = --as->mcp;
+ ptrdiff_t delta = (char *)target - (char *)p;
+ *p = PPCI_B | (delta & 0x03fffffcu);
+}
+
+static void emit_call(ASMState *as, void *target)
+{
+ MCode *p = --as->mcp;
+ ptrdiff_t delta = (char *)target - (char *)p;
+ if ((((delta>>2) + 0x00800000) >> 24) == 0) {
+ *p = PPCI_BL | (delta & 0x03fffffcu);
+ } else { /* Target out of range: need indirect call. Don't use arg reg. */
+ RegSet allow = RSET_GPR & ~RSET_RANGE(RID_R0, REGARG_LASTGPR+1);
+ Reg r = ra_allock(as, i32ptr(target), allow);
+ *p = PPCI_BCTRL;
+ p[-1] = PPCI_MTCTR | PPCF_T(r);
+ as->mcp = p-1;
+ }
+}
+
+/* -- Emit generic operations --------------------------------------------- */
+
+#define emit_mr(as, dst, src) \
+ emit_asb(as, PPCI_MR, (dst), (src), (src))
+
+/* Generic move between two regs. */
+static void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src)
+{
+ UNUSED(ir);
+ if (dst < RID_MAX_GPR)
+ emit_mr(as, dst, src);
+ else
+ emit_fb(as, PPCI_FMR, dst, src);
+}
+
+/* Generic load of register from stack slot. */
+static void emit_spload(ASMState *as, IRIns *ir, Reg r, int32_t ofs)
+{
+ if (r < RID_MAX_GPR)
+ emit_tai(as, PPCI_LWZ, r, RID_SP, ofs);
+ else
+ emit_fai(as, irt_isnum(ir->t) ? PPCI_LFD : PPCI_LFS, r, RID_SP, ofs);
+}
+
+/* Generic store of register to stack slot. */
+static void emit_spstore(ASMState *as, IRIns *ir, Reg r, int32_t ofs)
+{
+ if (r < RID_MAX_GPR)
+ emit_tai(as, PPCI_STW, r, RID_SP, ofs);
+ else
+ emit_fai(as, irt_isnum(ir->t) ? PPCI_STFD : PPCI_STFS, r, RID_SP, ofs);
+}
+
+/* Emit a compare (for equality) with a constant operand. */
+static void emit_cmpi(ASMState *as, Reg r, int32_t k)
+{
+ if (checki16(k)) {
+ emit_ai(as, PPCI_CMPWI, r, k);
+ } else if (checku16(k)) {
+ emit_ai(as, PPCI_CMPLWI, r, k);
+ } else {
+ emit_ai(as, PPCI_CMPLWI, RID_TMP, k);
+ emit_asi(as, PPCI_XORIS, RID_TMP, r, (k >> 16));
+ }
+}
+
+/* Add offset to pointer. */
+static void emit_addptr(ASMState *as, Reg r, int32_t ofs)
+{
+ if (ofs) {
+ emit_tai(as, PPCI_ADDI, r, r, ofs);
+ if (!checki16(ofs))
+ emit_tai(as, PPCI_ADDIS, r, r, (ofs + 32768) >> 16);
+ }
+}
+
+static void emit_spsub(ASMState *as, int32_t ofs)
+{
+ if (ofs) {
+ emit_tai(as, PPCI_STWU, RID_TMP, RID_SP, -ofs);
+ emit_tai(as, PPCI_ADDI, RID_TMP, RID_SP,
+ CFRAME_SIZE + (as->parent ? as->parent->spadjust : 0));
+ }
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_emit_x86.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_emit_x86.h
new file mode 100644
index 0000000..9c371a9
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_emit_x86.h
@@ -0,0 +1,468 @@
+/*
+** x86/x64 instruction emitter.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* -- Emit basic instructions --------------------------------------------- */
+
+#define MODRM(mode, r1, r2) ((MCode)((mode)+(((r1)&7)<<3)+((r2)&7)))
+
+#if LJ_64
+#define REXRB(p, rr, rb) \
+ { MCode rex = 0x40 + (((rr)>>1)&4) + (((rb)>>3)&1); \
+ if (rex != 0x40) *--(p) = rex; }
+#define FORCE_REX 0x200
+#define REX_64 (FORCE_REX|0x080000)
+#else
+#define REXRB(p, rr, rb) ((void)0)
+#define FORCE_REX 0
+#define REX_64 0
+#endif
+
+#define emit_i8(as, i) (*--as->mcp = (MCode)(i))
+#define emit_i32(as, i) (*(int32_t *)(as->mcp-4) = (i), as->mcp -= 4)
+#define emit_u32(as, u) (*(uint32_t *)(as->mcp-4) = (u), as->mcp -= 4)
+
+#define emit_x87op(as, xo) \
+ (*(uint16_t *)(as->mcp-2) = (uint16_t)(xo), as->mcp -= 2)
+
+/* op */
+static LJ_AINLINE MCode *emit_op(x86Op xo, Reg rr, Reg rb, Reg rx,
+ MCode *p, int delta)
+{
+ int n = (int8_t)xo;
+#if defined(__GNUC__)
+ if (__builtin_constant_p(xo) && n == -2)
+ p[delta-2] = (MCode)(xo >> 24);
+ else if (__builtin_constant_p(xo) && n == -3)
+ *(uint16_t *)(p+delta-3) = (uint16_t)(xo >> 16);
+ else
+#endif
+ *(uint32_t *)(p+delta-5) = (uint32_t)xo;
+ p += n + delta;
+#if LJ_64
+ {
+ uint32_t rex = 0x40 + ((rr>>1)&(4+(FORCE_REX>>1)))+((rx>>2)&2)+((rb>>3)&1);
+ if (rex != 0x40) {
+ rex |= (rr >> 16);
+ if (n == -4) { *p = (MCode)rex; rex = (MCode)(xo >> 8); }
+ else if ((xo & 0xffffff) == 0x6600fd) { *p = (MCode)rex; rex = 0x66; }
+ *--p = (MCode)rex;
+ }
+ }
+#else
+ UNUSED(rr); UNUSED(rb); UNUSED(rx);
+#endif
+ return p;
+}
+
+/* op + modrm */
+#define emit_opm(xo, mode, rr, rb, p, delta) \
+ (p[(delta)-1] = MODRM((mode), (rr), (rb)), \
+ emit_op((xo), (rr), (rb), 0, (p), (delta)))
+
+/* op + modrm + sib */
+#define emit_opmx(xo, mode, scale, rr, rb, rx, p) \
+ (p[-1] = MODRM((scale), (rx), (rb)), \
+ p[-2] = MODRM((mode), (rr), RID_ESP), \
+ emit_op((xo), (rr), (rb), (rx), (p), -1))
+
+/* op r1, r2 */
+static void emit_rr(ASMState *as, x86Op xo, Reg r1, Reg r2)
+{
+ MCode *p = as->mcp;
+ as->mcp = emit_opm(xo, XM_REG, r1, r2, p, 0);
+}
+
+#if LJ_64 && defined(LUA_USE_ASSERT)
+/* [addr] is sign-extended in x64 and must be in lower 2G (not 4G). */
+static int32_t ptr2addr(const void *p)
+{
+ lua_assert((uintptr_t)p < (uintptr_t)0x80000000);
+ return i32ptr(p);
+}
+#else
+#define ptr2addr(p) (i32ptr((p)))
+#endif
+
+/* op r, [addr] */
+static void emit_rma(ASMState *as, x86Op xo, Reg rr, const void *addr)
+{
+ MCode *p = as->mcp;
+ *(int32_t *)(p-4) = ptr2addr(addr);
+#if LJ_64
+ p[-5] = MODRM(XM_SCALE1, RID_ESP, RID_EBP);
+ as->mcp = emit_opm(xo, XM_OFS0, rr, RID_ESP, p, -5);
+#else
+ as->mcp = emit_opm(xo, XM_OFS0, rr, RID_EBP, p, -4);
+#endif
+}
+
+/* op r, [base+ofs] */
+static void emit_rmro(ASMState *as, x86Op xo, Reg rr, Reg rb, int32_t ofs)
+{
+ MCode *p = as->mcp;
+ x86Mode mode;
+ if (ra_hasreg(rb)) {
+ if (ofs == 0 && (rb&7) != RID_EBP) {
+ mode = XM_OFS0;
+ } else if (checki8(ofs)) {
+ *--p = (MCode)ofs;
+ mode = XM_OFS8;
+ } else {
+ p -= 4;
+ *(int32_t *)p = ofs;
+ mode = XM_OFS32;
+ }
+ if ((rb&7) == RID_ESP)
+ *--p = MODRM(XM_SCALE1, RID_ESP, RID_ESP);
+ } else {
+ *(int32_t *)(p-4) = ofs;
+#if LJ_64
+ p[-5] = MODRM(XM_SCALE1, RID_ESP, RID_EBP);
+ p -= 5;
+ rb = RID_ESP;
+#else
+ p -= 4;
+ rb = RID_EBP;
+#endif
+ mode = XM_OFS0;
+ }
+ as->mcp = emit_opm(xo, mode, rr, rb, p, 0);
+}
+
+/* op r, [base+idx*scale+ofs] */
+static void emit_rmrxo(ASMState *as, x86Op xo, Reg rr, Reg rb, Reg rx,
+ x86Mode scale, int32_t ofs)
+{
+ MCode *p = as->mcp;
+ x86Mode mode;
+ if (ofs == 0 && (rb&7) != RID_EBP) {
+ mode = XM_OFS0;
+ } else if (checki8(ofs)) {
+ mode = XM_OFS8;
+ *--p = (MCode)ofs;
+ } else {
+ mode = XM_OFS32;
+ p -= 4;
+ *(int32_t *)p = ofs;
+ }
+ as->mcp = emit_opmx(xo, mode, scale, rr, rb, rx, p);
+}
+
+/* op r, i */
+static void emit_gri(ASMState *as, x86Group xg, Reg rb, int32_t i)
+{
+ MCode *p = as->mcp;
+ x86Op xo;
+ if (checki8(i)) {
+ *--p = (MCode)i;
+ xo = XG_TOXOi8(xg);
+ } else {
+ p -= 4;
+ *(int32_t *)p = i;
+ xo = XG_TOXOi(xg);
+ }
+ as->mcp = emit_opm(xo, XM_REG, (Reg)(xg & 7) | (rb & REX_64), rb, p, 0);
+}
+
+/* op [base+ofs], i */
+static void emit_gmroi(ASMState *as, x86Group xg, Reg rb, int32_t ofs,
+ int32_t i)
+{
+ x86Op xo;
+ if (checki8(i)) {
+ emit_i8(as, i);
+ xo = XG_TOXOi8(xg);
+ } else {
+ emit_i32(as, i);
+ xo = XG_TOXOi(xg);
+ }
+ emit_rmro(as, xo, (Reg)(xg & 7), rb, ofs);
+}
+
+#define emit_shifti(as, xg, r, i) \
+ (emit_i8(as, (i)), emit_rr(as, XO_SHIFTi, (Reg)(xg), (r)))
+
+/* op r, rm/mrm */
+static void emit_mrm(ASMState *as, x86Op xo, Reg rr, Reg rb)
+{
+ MCode *p = as->mcp;
+ x86Mode mode = XM_REG;
+ if (rb == RID_MRM) {
+ rb = as->mrm.base;
+ if (rb == RID_NONE) {
+ rb = RID_EBP;
+ mode = XM_OFS0;
+ p -= 4;
+ *(int32_t *)p = as->mrm.ofs;
+ if (as->mrm.idx != RID_NONE)
+ goto mrmidx;
+#if LJ_64
+ *--p = MODRM(XM_SCALE1, RID_ESP, RID_EBP);
+ rb = RID_ESP;
+#endif
+ } else {
+ if (as->mrm.ofs == 0 && (rb&7) != RID_EBP) {
+ mode = XM_OFS0;
+ } else if (checki8(as->mrm.ofs)) {
+ *--p = (MCode)as->mrm.ofs;
+ mode = XM_OFS8;
+ } else {
+ p -= 4;
+ *(int32_t *)p = as->mrm.ofs;
+ mode = XM_OFS32;
+ }
+ if (as->mrm.idx != RID_NONE) {
+ mrmidx:
+ as->mcp = emit_opmx(xo, mode, as->mrm.scale, rr, rb, as->mrm.idx, p);
+ return;
+ }
+ if ((rb&7) == RID_ESP)
+ *--p = MODRM(XM_SCALE1, RID_ESP, RID_ESP);
+ }
+ }
+ as->mcp = emit_opm(xo, mode, rr, rb, p, 0);
+}
+
+/* op rm/mrm, i */
+static void emit_gmrmi(ASMState *as, x86Group xg, Reg rb, int32_t i)
+{
+ x86Op xo;
+ if (checki8(i)) {
+ emit_i8(as, i);
+ xo = XG_TOXOi8(xg);
+ } else {
+ emit_i32(as, i);
+ xo = XG_TOXOi(xg);
+ }
+ emit_mrm(as, xo, (Reg)(xg & 7) | (rb & REX_64), (rb & ~REX_64));
+}
+
+/* -- Emit loads/stores --------------------------------------------------- */
+
+/* Instruction selection for XMM moves. */
+#define XMM_MOVRR(as) ((as->flags & JIT_F_SPLIT_XMM) ? XO_MOVSD : XO_MOVAPS)
+#define XMM_MOVRM(as) ((as->flags & JIT_F_SPLIT_XMM) ? XO_MOVLPD : XO_MOVSD)
+
+/* mov [base+ofs], i */
+static void emit_movmroi(ASMState *as, Reg base, int32_t ofs, int32_t i)
+{
+ emit_i32(as, i);
+ emit_rmro(as, XO_MOVmi, 0, base, ofs);
+}
+
+/* mov [base+ofs], r */
+#define emit_movtomro(as, r, base, ofs) \
+ emit_rmro(as, XO_MOVto, (r), (base), (ofs))
+
+/* Get/set global_State fields. */
+#define emit_opgl(as, xo, r, field) \
+ emit_rma(as, (xo), (r), (void *)&J2G(as->J)->field)
+#define emit_getgl(as, r, field) emit_opgl(as, XO_MOV, (r), field)
+#define emit_setgl(as, r, field) emit_opgl(as, XO_MOVto, (r), field)
+
+#define emit_setvmstate(as, i) \
+ (emit_i32(as, i), emit_opgl(as, XO_MOVmi, 0, vmstate))
+
+/* mov r, i / xor r, r */
+static void emit_loadi(ASMState *as, Reg r, int32_t i)
+{
+ /* XOR r,r is shorter, but modifies the flags. This is bad for HIOP/jcc. */
+ if (i == 0 && !(LJ_32 && (IR(as->curins)->o == IR_HIOP ||
+ (as->curins+1 < as->T->nins &&
+ IR(as->curins+1)->o == IR_HIOP))) &&
+ !((*as->mcp == 0x0f && (as->mcp[1] & 0xf0) == XI_JCCn) ||
+ (*as->mcp & 0xf0) == XI_JCCs)) {
+ emit_rr(as, XO_ARITH(XOg_XOR), r, r);
+ } else {
+ MCode *p = as->mcp;
+ *(int32_t *)(p-4) = i;
+ p[-5] = (MCode)(XI_MOVri+(r&7));
+ p -= 5;
+ REXRB(p, 0, r);
+ as->mcp = p;
+ }
+}
+
+/* mov r, addr */
+#define emit_loada(as, r, addr) \
+ emit_loadi(as, (r), ptr2addr((addr)))
+
+#if LJ_64
+/* mov r, imm64 or shorter 32 bit extended load. */
+static void emit_loadu64(ASMState *as, Reg r, uint64_t u64)
+{
+ if (checku32(u64)) { /* 32 bit load clears upper 32 bits. */
+ emit_loadi(as, r, (int32_t)u64);
+ } else if (checki32((int64_t)u64)) { /* Sign-extended 32 bit load. */
+ MCode *p = as->mcp;
+ *(int32_t *)(p-4) = (int32_t)u64;
+ as->mcp = emit_opm(XO_MOVmi, XM_REG, REX_64, r, p, -4);
+ } else { /* Full-size 64 bit load. */
+ MCode *p = as->mcp;
+ *(uint64_t *)(p-8) = u64;
+ p[-9] = (MCode)(XI_MOVri+(r&7));
+ p[-10] = 0x48 + ((r>>3)&1);
+ p -= 10;
+ as->mcp = p;
+ }
+}
+#endif
+
+/* movsd r, [&tv->n] / xorps r, r */
+static void emit_loadn(ASMState *as, Reg r, cTValue *tv)
+{
+ if (tvispzero(tv)) /* Use xor only for +0. */
+ emit_rr(as, XO_XORPS, r, r);
+ else
+ emit_rma(as, XMM_MOVRM(as), r, &tv->n);
+}
+
+/* -- Emit control-flow instructions -------------------------------------- */
+
+/* Label for short jumps. */
+typedef MCode *MCLabel;
+
+#if LJ_32 && LJ_HASFFI
+/* jmp short target */
+static void emit_sjmp(ASMState *as, MCLabel target)
+{
+ MCode *p = as->mcp;
+ ptrdiff_t delta = target - p;
+ lua_assert(delta == (int8_t)delta);
+ p[-1] = (MCode)(int8_t)delta;
+ p[-2] = XI_JMPs;
+ as->mcp = p - 2;
+}
+#endif
+
+/* jcc short target */
+static void emit_sjcc(ASMState *as, int cc, MCLabel target)
+{
+ MCode *p = as->mcp;
+ ptrdiff_t delta = target - p;
+ lua_assert(delta == (int8_t)delta);
+ p[-1] = (MCode)(int8_t)delta;
+ p[-2] = (MCode)(XI_JCCs+(cc&15));
+ as->mcp = p - 2;
+}
+
+/* jcc short (pending target) */
+static MCLabel emit_sjcc_label(ASMState *as, int cc)
+{
+ MCode *p = as->mcp;
+ p[-1] = 0;
+ p[-2] = (MCode)(XI_JCCs+(cc&15));
+ as->mcp = p - 2;
+ return p;
+}
+
+/* Fixup jcc short target. */
+static void emit_sfixup(ASMState *as, MCLabel source)
+{
+ source[-1] = (MCode)(as->mcp-source);
+}
+
+/* Return label pointing to current PC. */
+#define emit_label(as) ((as)->mcp)
+
+/* Compute relative 32 bit offset for jump and call instructions. */
+static LJ_AINLINE int32_t jmprel(MCode *p, MCode *target)
+{
+ ptrdiff_t delta = target - p;
+ lua_assert(delta == (int32_t)delta);
+ return (int32_t)delta;
+}
+
+/* jcc target */
+static void emit_jcc(ASMState *as, int cc, MCode *target)
+{
+ MCode *p = as->mcp;
+ *(int32_t *)(p-4) = jmprel(p, target);
+ p[-5] = (MCode)(XI_JCCn+(cc&15));
+ p[-6] = 0x0f;
+ as->mcp = p - 6;
+}
+
+/* jmp target */
+static void emit_jmp(ASMState *as, MCode *target)
+{
+ MCode *p = as->mcp;
+ *(int32_t *)(p-4) = jmprel(p, target);
+ p[-5] = XI_JMP;
+ as->mcp = p - 5;
+}
+
+/* call target */
+static void emit_call_(ASMState *as, MCode *target)
+{
+ MCode *p = as->mcp;
+#if LJ_64
+ if (target-p != (int32_t)(target-p)) {
+ /* Assumes RID_RET is never an argument to calls and always clobbered. */
+ emit_rr(as, XO_GROUP5, XOg_CALL, RID_RET);
+ emit_loadu64(as, RID_RET, (uint64_t)target);
+ return;
+ }
+#endif
+ *(int32_t *)(p-4) = jmprel(p, target);
+ p[-5] = XI_CALL;
+ as->mcp = p - 5;
+}
+
+#define emit_call(as, f) emit_call_(as, (MCode *)(void *)(f))
+
+/* -- Emit generic operations --------------------------------------------- */
+
+/* Use 64 bit operations to handle 64 bit IR types. */
+#if LJ_64
+#define REX_64IR(ir, r) ((r) + (irt_is64((ir)->t) ? REX_64 : 0))
+#else
+#define REX_64IR(ir, r) (r)
+#endif
+
+/* Generic move between two regs. */
+static void emit_movrr(ASMState *as, IRIns *ir, Reg dst, Reg src)
+{
+ UNUSED(ir);
+ if (dst < RID_MAX_GPR)
+ emit_rr(as, XO_MOV, REX_64IR(ir, dst), src);
+ else
+ emit_rr(as, XMM_MOVRR(as), dst, src);
+}
+
+/* Generic load of register from stack slot. */
+static void emit_spload(ASMState *as, IRIns *ir, Reg r, int32_t ofs)
+{
+ if (r < RID_MAX_GPR)
+ emit_rmro(as, XO_MOV, REX_64IR(ir, r), RID_ESP, ofs);
+ else
+ emit_rmro(as, irt_isnum(ir->t) ? XMM_MOVRM(as) : XO_MOVSS, r, RID_ESP, ofs);
+}
+
+/* Generic store of register to stack slot. */
+static void emit_spstore(ASMState *as, IRIns *ir, Reg r, int32_t ofs)
+{
+ if (r < RID_MAX_GPR)
+ emit_rmro(as, XO_MOVto, REX_64IR(ir, r), RID_ESP, ofs);
+ else
+ emit_rmro(as, irt_isnum(ir->t) ? XO_MOVSDto : XO_MOVSSto, r, RID_ESP, ofs);
+}
+
+/* Add offset to pointer. */
+static void emit_addptr(ASMState *as, Reg r, int32_t ofs)
+{
+ if (ofs) {
+ if ((as->flags & JIT_F_LEA_AGU))
+ emit_rmro(as, XO_LEA, r, r, ofs);
+ else
+ emit_gri(as, XG_ARITHi(XOg_ADD), r, ofs);
+ }
+}
+
+#define emit_spsub(as, ofs) emit_addptr(as, RID_ESP|REX_64, -(ofs))
+
+/* Prefer rematerialization of BASE/L from global_State over spills. */
+#define emit_canremat(ref) ((ref) <= REF_BASE)
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_err.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_err.c
new file mode 100644
index 0000000..13a1ded
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_err.c
@@ -0,0 +1,803 @@
+/*
+** Error handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_err_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#include "lj_err.h"
+#include "lj_debug.h"
+#include "lj_str.h"
+#include "lj_func.h"
+#include "lj_state.h"
+#include "lj_frame.h"
+#include "lj_ff.h"
+#include "lj_trace.h"
+#include "lj_vm.h"
+
+/*
+** LuaJIT can either use internal or external frame unwinding:
+**
+** - Internal frame unwinding (INT) is free-standing and doesn't require
+** any OS or library support.
+**
+** - External frame unwinding (EXT) uses the system-provided unwind handler.
+**
+** Pros and Cons:
+**
+** - EXT requires unwind tables for *all* functions on the C stack between
+** the pcall/catch and the error/throw. This is the default on x64,
+** but needs to be manually enabled on x86/PPC for non-C++ code.
+**
+** - INT is faster when actually throwing errors (but this happens rarely).
+** Setting up error handlers is zero-cost in any case.
+**
+** - EXT provides full interoperability with C++ exceptions. You can throw
+** Lua errors or C++ exceptions through a mix of Lua frames and C++ frames.
+** C++ destructors are called as needed. C++ exceptions caught by pcall
+** are converted to the string "C++ exception". Lua errors can be caught
+** with catch (...) in C++.
+**
+** - INT has only limited support for automatically catching C++ exceptions
+** on POSIX systems using DWARF2 stack unwinding. Other systems may use
+** the wrapper function feature. Lua errors thrown through C++ frames
+** cannot be caught by C++ code and C++ destructors are not run.
+**
+** EXT is the default on x64 systems, INT is the default on all other systems.
+**
+** EXT can be manually enabled on POSIX systems using GCC and DWARF2 stack
+** unwinding with -DLUAJIT_UNWIND_EXTERNAL. *All* C code must be compiled
+** with -funwind-tables (or -fexceptions). This includes LuaJIT itself (set
+** TARGET_CFLAGS), all of your C/Lua binding code, all loadable C modules
+** and all C libraries that have callbacks which may be used to call back
+** into Lua. C++ code must *not* be compiled with -fno-exceptions.
+**
+** EXT cannot be enabled on WIN32 since system exceptions use code-driven SEH.
+** EXT is mandatory on WIN64 since the calling convention has an abundance
+** of callee-saved registers (rbx, rbp, rsi, rdi, r12-r15, xmm6-xmm15).
+** The POSIX/x64 interpreter only saves r12/r13 for INT (e.g. PS4).
+*/
+
+#if defined(__GNUC__) && (LJ_TARGET_X64 || defined(LUAJIT_UNWIND_EXTERNAL)) && !LJ_NO_UNWIND
+#define LJ_UNWIND_EXT 1
+#elif LJ_TARGET_X64 && LJ_TARGET_WINDOWS
+#define LJ_UNWIND_EXT 1
+#endif
+
+/* -- Error messages ------------------------------------------------------ */
+
+/* Error message strings. */
+LJ_DATADEF const char *lj_err_allmsg =
+#define ERRDEF(name, msg) msg "\0"
+#include "lj_errmsg.h"
+;
+
+/* -- Internal frame unwinding -------------------------------------------- */
+
+/* Unwind Lua stack and move error message to new top. */
+LJ_NOINLINE static void unwindstack(lua_State *L, TValue *top)
+{
+ lj_func_closeuv(L, top);
+ if (top < L->top-1) {
+ copyTV(L, top, L->top-1);
+ L->top = top+1;
+ }
+ lj_state_relimitstack(L);
+}
+
+/* Unwind until stop frame. Optionally cleanup frames. */
+static void *err_unwind(lua_State *L, void *stopcf, int errcode)
+{
+ TValue *frame = L->base-1;
+ void *cf = L->cframe;
+ while (cf) {
+ int32_t nres = cframe_nres(cframe_raw(cf));
+ if (nres < 0) { /* C frame without Lua frame? */
+ TValue *top = restorestack(L, -nres);
+ if (frame < top) { /* Frame reached? */
+ if (errcode) {
+ L->cframe = cframe_prev(cf);
+ L->base = frame+1;
+ unwindstack(L, top);
+ }
+ return cf;
+ }
+ }
+ if (frame <= tvref(L->stack))
+ break;
+ switch (frame_typep(frame)) {
+ case FRAME_LUA: /* Lua frame. */
+ case FRAME_LUAP:
+ frame = frame_prevl(frame);
+ break;
+ case FRAME_C: /* C frame. */
+#if LJ_HASFFI
+ unwind_c:
+#endif
+#if LJ_UNWIND_EXT
+ if (errcode) {
+ L->cframe = cframe_prev(cf);
+ L->base = frame_prevd(frame) + 1;
+ unwindstack(L, frame);
+ } else if (cf != stopcf) {
+ cf = cframe_prev(cf);
+ frame = frame_prevd(frame);
+ break;
+ }
+ return NULL; /* Continue unwinding. */
+#else
+ UNUSED(stopcf);
+ cf = cframe_prev(cf);
+ frame = frame_prevd(frame);
+ break;
+#endif
+ case FRAME_CP: /* Protected C frame. */
+ if (cframe_canyield(cf)) { /* Resume? */
+ if (errcode) {
+ hook_leave(G(L)); /* Assumes nobody uses coroutines inside hooks. */
+ L->cframe = NULL;
+ L->status = (uint8_t)errcode;
+ }
+ return cf;
+ }
+ if (errcode) {
+ L->cframe = cframe_prev(cf);
+ L->base = frame_prevd(frame) + 1;
+ unwindstack(L, frame);
+ }
+ return cf;
+ case FRAME_CONT: /* Continuation frame. */
+#if LJ_HASFFI
+ if ((frame-1)->u32.lo == LJ_CONT_FFI_CALLBACK)
+ goto unwind_c;
+#endif
+ /* fallthrough */
+ case FRAME_VARG: /* Vararg frame. */
+ frame = frame_prevd(frame);
+ break;
+ case FRAME_PCALL: /* FF pcall() frame. */
+ case FRAME_PCALLH: /* FF pcall() frame inside hook. */
+ if (errcode) {
+ if (errcode == LUA_YIELD) {
+ frame = frame_prevd(frame);
+ break;
+ }
+ if (frame_typep(frame) == FRAME_PCALL)
+ hook_leave(G(L));
+ L->cframe = cf;
+ L->base = frame_prevd(frame) + 1;
+ unwindstack(L, L->base);
+ }
+ return (void *)((intptr_t)cf | CFRAME_UNWIND_FF);
+ }
+ }
+ /* No C frame. */
+ if (errcode) {
+ L->cframe = NULL;
+ L->base = tvref(L->stack)+1;
+ unwindstack(L, L->base);
+ if (G(L)->panic)
+ G(L)->panic(L);
+ exit(EXIT_FAILURE);
+ }
+ return L; /* Anything non-NULL will do. */
+}
+
+/* -- External frame unwinding -------------------------------------------- */
+
+#if defined(__GNUC__) && !LJ_NO_UNWIND && !LJ_ABI_WIN
+
+/*
+** We have to use our own definitions instead of the mandatory (!) unwind.h,
+** since various OS, distros and compilers mess up the header installation.
+*/
+
+typedef struct _Unwind_Exception
+{
+ uint64_t exclass;
+ void (*excleanup)(int, struct _Unwind_Exception *);
+ uintptr_t p1, p2;
+} __attribute__((__aligned__)) _Unwind_Exception;
+
+typedef struct _Unwind_Context _Unwind_Context;
+
+#define _URC_OK 0
+#define _URC_FATAL_PHASE1_ERROR 3
+#define _URC_HANDLER_FOUND 6
+#define _URC_INSTALL_CONTEXT 7
+#define _URC_CONTINUE_UNWIND 8
+#define _URC_FAILURE 9
+
+#if !LJ_TARGET_ARM
+
+extern uintptr_t _Unwind_GetCFA(_Unwind_Context *);
+extern void _Unwind_SetGR(_Unwind_Context *, int, uintptr_t);
+extern void _Unwind_SetIP(_Unwind_Context *, uintptr_t);
+extern void _Unwind_DeleteException(_Unwind_Exception *);
+extern int _Unwind_RaiseException(_Unwind_Exception *);
+
+#define _UA_SEARCH_PHASE 1
+#define _UA_CLEANUP_PHASE 2
+#define _UA_HANDLER_FRAME 4
+#define _UA_FORCE_UNWIND 8
+
+#define LJ_UEXCLASS 0x4c55414a49543200ULL /* LUAJIT2\0 */
+#define LJ_UEXCLASS_MAKE(c) (LJ_UEXCLASS | (uint64_t)(c))
+#define LJ_UEXCLASS_CHECK(cl) (((cl) ^ LJ_UEXCLASS) <= 0xff)
+#define LJ_UEXCLASS_ERRCODE(cl) ((int)((cl) & 0xff))
+
+/* DWARF2 personality handler referenced from interpreter .eh_frame. */
+LJ_FUNCA int lj_err_unwind_dwarf(int version, int actions,
+ uint64_t uexclass, _Unwind_Exception *uex, _Unwind_Context *ctx)
+{
+ void *cf;
+ lua_State *L;
+ if (version != 1)
+ return _URC_FATAL_PHASE1_ERROR;
+ UNUSED(uexclass);
+ cf = (void *)_Unwind_GetCFA(ctx);
+ L = cframe_L(cf);
+ if ((actions & _UA_SEARCH_PHASE)) {
+#if LJ_UNWIND_EXT
+ if (err_unwind(L, cf, 0) == NULL)
+ return _URC_CONTINUE_UNWIND;
+#endif
+ if (!LJ_UEXCLASS_CHECK(uexclass)) {
+ setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRCPP));
+ }
+ return _URC_HANDLER_FOUND;
+ }
+ if ((actions & _UA_CLEANUP_PHASE)) {
+ int errcode;
+ if (LJ_UEXCLASS_CHECK(uexclass)) {
+ errcode = LJ_UEXCLASS_ERRCODE(uexclass);
+ } else {
+ if ((actions & _UA_HANDLER_FRAME))
+ _Unwind_DeleteException(uex);
+ errcode = LUA_ERRRUN;
+ }
+#if LJ_UNWIND_EXT
+ cf = err_unwind(L, cf, errcode);
+ if ((actions & _UA_FORCE_UNWIND)) {
+ return _URC_CONTINUE_UNWIND;
+ } else if (cf) {
+ _Unwind_SetGR(ctx, LJ_TARGET_EHRETREG, errcode);
+ _Unwind_SetIP(ctx, (uintptr_t)(cframe_unwind_ff(cf) ?
+ lj_vm_unwind_ff_eh :
+ lj_vm_unwind_c_eh));
+ return _URC_INSTALL_CONTEXT;
+ }
+#if LJ_TARGET_X86ORX64
+ else if ((actions & _UA_HANDLER_FRAME)) {
+ /* Workaround for ancient libgcc bug. Still present in RHEL 5.5. :-/
+ ** Real fix: http://gcc.gnu.org/viewcvs/trunk/gcc/unwind-dw2.c?r1=121165&r2=124837&pathrev=153877&diff_format=h
+ */
+ _Unwind_SetGR(ctx, LJ_TARGET_EHRETREG, errcode);
+ _Unwind_SetIP(ctx, (uintptr_t)lj_vm_unwind_rethrow);
+ return _URC_INSTALL_CONTEXT;
+ }
+#endif
+#else
+ /* This is not the proper way to escape from the unwinder. We get away with
+ ** it on non-x64 because the interpreter restores all callee-saved regs.
+ */
+ lj_err_throw(L, errcode);
+#endif
+ }
+ return _URC_CONTINUE_UNWIND;
+}
+
+#if LJ_UNWIND_EXT
+#if LJ_TARGET_OSX || defined(__OpenBSD__)
+/* Sorry, no thread safety for OSX. Complain to Apple, not me. */
+static _Unwind_Exception static_uex;
+#else
+static __thread _Unwind_Exception static_uex;
+#endif
+
+/* Raise DWARF2 exception. */
+static void err_raise_ext(int errcode)
+{
+ static_uex.exclass = LJ_UEXCLASS_MAKE(errcode);
+ static_uex.excleanup = NULL;
+ _Unwind_RaiseException(&static_uex);
+}
+#endif
+
+#else
+
+extern void _Unwind_DeleteException(void *);
+extern int __gnu_unwind_frame (void *, _Unwind_Context *);
+extern int _Unwind_VRS_Set(_Unwind_Context *, int, uint32_t, int, void *);
+extern int _Unwind_VRS_Get(_Unwind_Context *, int, uint32_t, int, void *);
+
+static inline uint32_t _Unwind_GetGR(_Unwind_Context *ctx, int r)
+{
+ uint32_t v;
+ _Unwind_VRS_Get(ctx, 0, r, 0, &v);
+ return v;
+}
+
+static inline void _Unwind_SetGR(_Unwind_Context *ctx, int r, uint32_t v)
+{
+ _Unwind_VRS_Set(ctx, 0, r, 0, &v);
+}
+
+#define _US_VIRTUAL_UNWIND_FRAME 0
+#define _US_UNWIND_FRAME_STARTING 1
+#define _US_ACTION_MASK 3
+#define _US_FORCE_UNWIND 8
+
+/* ARM unwinder personality handler referenced from interpreter .ARM.extab. */
+LJ_FUNCA int lj_err_unwind_arm(int state, void *ucb, _Unwind_Context *ctx)
+{
+ void *cf = (void *)_Unwind_GetGR(ctx, 13);
+ lua_State *L = cframe_L(cf);
+ if ((state & _US_ACTION_MASK) == _US_VIRTUAL_UNWIND_FRAME) {
+ setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRCPP));
+ return _URC_HANDLER_FOUND;
+ }
+ if ((state&(_US_ACTION_MASK|_US_FORCE_UNWIND)) == _US_UNWIND_FRAME_STARTING) {
+ _Unwind_DeleteException(ucb);
+ _Unwind_SetGR(ctx, 15, (uint32_t)(void *)lj_err_throw);
+ _Unwind_SetGR(ctx, 0, (uint32_t)L);
+ _Unwind_SetGR(ctx, 1, (uint32_t)LUA_ERRRUN);
+ return _URC_INSTALL_CONTEXT;
+ }
+ if (__gnu_unwind_frame(ucb, ctx) != _URC_OK)
+ return _URC_FAILURE;
+ return _URC_CONTINUE_UNWIND;
+}
+
+#endif
+
+#elif LJ_TARGET_X64 && LJ_ABI_WIN
+
+/*
+** Someone in Redmond owes me several days of my life. A lot of this is
+** undocumented or just plain wrong on MSDN. Some of it can be gathered
+** from 3rd party docs or must be found by trial-and-error. They really
+** don't want you to write your own language-specific exception handler
+** or to interact gracefully with MSVC. :-(
+**
+** Apparently MSVC doesn't call C++ destructors for foreign exceptions
+** unless you compile your C++ code with /EHa. Unfortunately this means
+** catch (...) also catches things like access violations. The use of
+** _set_se_translator doesn't really help, because it requires /EHa, too.
+*/
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+/* Taken from: http://www.nynaeve.net/?p=99 */
+typedef struct UndocumentedDispatcherContext {
+ ULONG64 ControlPc;
+ ULONG64 ImageBase;
+ PRUNTIME_FUNCTION FunctionEntry;
+ ULONG64 EstablisherFrame;
+ ULONG64 TargetIp;
+ PCONTEXT ContextRecord;
+ void (*LanguageHandler)(void);
+ PVOID HandlerData;
+ PUNWIND_HISTORY_TABLE HistoryTable;
+ ULONG ScopeIndex;
+ ULONG Fill0;
+} UndocumentedDispatcherContext;
+
+/* Another wild guess. */
+extern void __DestructExceptionObject(EXCEPTION_RECORD *rec, int nothrow);
+
+#ifdef MINGW_SDK_INIT
+/* Workaround for broken MinGW64 declaration. */
+VOID RtlUnwindEx_FIXED(PVOID,PVOID,PVOID,PVOID,PVOID,PVOID) asm("RtlUnwindEx");
+#define RtlUnwindEx RtlUnwindEx_FIXED
+#endif
+
+#define LJ_MSVC_EXCODE ((DWORD)0xe06d7363)
+#define LJ_GCC_EXCODE ((DWORD)0x20474343)
+
+#define LJ_EXCODE ((DWORD)0xe24c4a00)
+#define LJ_EXCODE_MAKE(c) (LJ_EXCODE | (DWORD)(c))
+#define LJ_EXCODE_CHECK(cl) (((cl) ^ LJ_EXCODE) <= 0xff)
+#define LJ_EXCODE_ERRCODE(cl) ((int)((cl) & 0xff))
+
+/* Win64 exception handler for interpreter frame. */
+LJ_FUNCA EXCEPTION_DISPOSITION lj_err_unwind_win64(EXCEPTION_RECORD *rec,
+ void *cf, CONTEXT *ctx, UndocumentedDispatcherContext *dispatch)
+{
+ lua_State *L = cframe_L(cf);
+ int errcode = LJ_EXCODE_CHECK(rec->ExceptionCode) ?
+ LJ_EXCODE_ERRCODE(rec->ExceptionCode) : LUA_ERRRUN;
+ if ((rec->ExceptionFlags & 6)) { /* EH_UNWINDING|EH_EXIT_UNWIND */
+ /* Unwind internal frames. */
+ err_unwind(L, cf, errcode);
+ } else {
+ void *cf2 = err_unwind(L, cf, 0);
+ if (cf2) { /* We catch it, so start unwinding the upper frames. */
+ if (rec->ExceptionCode == LJ_MSVC_EXCODE ||
+ rec->ExceptionCode == LJ_GCC_EXCODE) {
+#if LJ_TARGET_WINDOWS
+ __DestructExceptionObject(rec, 1);
+#endif
+ setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRCPP));
+ } else if (!LJ_EXCODE_CHECK(rec->ExceptionCode)) {
+ /* Don't catch access violations etc. */
+ return ExceptionContinueSearch;
+ }
+ /* Unwind the stack and call all handlers for all lower C frames
+ ** (including ourselves) again with EH_UNWINDING set. Then set
+ ** rsp = cf, rax = errcode and jump to the specified target.
+ */
+ RtlUnwindEx(cf, (void *)((cframe_unwind_ff(cf2) && errcode != LUA_YIELD) ?
+ lj_vm_unwind_ff_eh :
+ lj_vm_unwind_c_eh),
+ rec, (void *)(uintptr_t)errcode, ctx, dispatch->HistoryTable);
+ /* RtlUnwindEx should never return. */
+ }
+ }
+ return ExceptionContinueSearch;
+}
+
+/* Raise Windows exception. */
+static void err_raise_ext(int errcode)
+{
+ RaiseException(LJ_EXCODE_MAKE(errcode), 1 /* EH_NONCONTINUABLE */, 0, NULL);
+}
+
+#endif
+
+/* -- Error handling ------------------------------------------------------ */
+
+/* Throw error. Find catch frame, unwind stack and continue. */
+LJ_NOINLINE void LJ_FASTCALL lj_err_throw(lua_State *L, int errcode)
+{
+ global_State *g = G(L);
+ lj_trace_abort(g);
+ setgcrefnull(g->jit_L);
+ L->status = 0;
+#if LJ_UNWIND_EXT
+ err_raise_ext(errcode);
+ /*
+ ** A return from this function signals a corrupt C stack that cannot be
+ ** unwound. We have no choice but to call the panic function and exit.
+ **
+ ** Usually this is caused by a C function without unwind information.
+ ** This should never happen on x64, but may happen if you've manually
+ ** enabled LUAJIT_UNWIND_EXTERNAL and forgot to recompile *every*
+ ** non-C++ file with -funwind-tables.
+ */
+ if (G(L)->panic)
+ G(L)->panic(L);
+#else
+ {
+ void *cf = err_unwind(L, NULL, errcode);
+ if (cframe_unwind_ff(cf))
+ lj_vm_unwind_ff(cframe_raw(cf));
+ else
+ lj_vm_unwind_c(cframe_raw(cf), errcode);
+ }
+#endif
+ exit(EXIT_FAILURE);
+}
+
+/* Return string object for error message. */
+LJ_NOINLINE GCstr *lj_err_str(lua_State *L, ErrMsg em)
+{
+ return lj_str_newz(L, err2msg(em));
+}
+
+/* Out-of-memory error. */
+LJ_NOINLINE void lj_err_mem(lua_State *L)
+{
+ if (L->status == LUA_ERRERR+1) /* Don't touch the stack during lua_open. */
+ lj_vm_unwind_c(L->cframe, LUA_ERRMEM);
+ setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRMEM));
+ lj_err_throw(L, LUA_ERRMEM);
+}
+
+/* Find error function for runtime errors. Requires an extra stack traversal. */
+static ptrdiff_t finderrfunc(lua_State *L)
+{
+ cTValue *frame = L->base-1, *bot = tvref(L->stack);
+ void *cf = L->cframe;
+ while (frame > bot && cf) {
+ while (cframe_nres(cframe_raw(cf)) < 0) { /* cframe without frame? */
+ if (frame >= restorestack(L, -cframe_nres(cf)))
+ break;
+ if (cframe_errfunc(cf) >= 0) /* Error handler not inherited (-1)? */
+ return cframe_errfunc(cf);
+ cf = cframe_prev(cf); /* Else unwind cframe and continue searching. */
+ if (cf == NULL)
+ return 0;
+ }
+ switch (frame_typep(frame)) {
+ case FRAME_LUA:
+ case FRAME_LUAP:
+ frame = frame_prevl(frame);
+ break;
+ case FRAME_C:
+ cf = cframe_prev(cf);
+ /* fallthrough */
+ case FRAME_VARG:
+ frame = frame_prevd(frame);
+ break;
+ case FRAME_CONT:
+#if LJ_HASFFI
+ if ((frame-1)->u32.lo == LJ_CONT_FFI_CALLBACK)
+ cf = cframe_prev(cf);
+#endif
+ frame = frame_prevd(frame);
+ break;
+ case FRAME_CP:
+ if (cframe_canyield(cf)) return 0;
+ if (cframe_errfunc(cf) >= 0)
+ return cframe_errfunc(cf);
+ frame = frame_prevd(frame);
+ break;
+ case FRAME_PCALL:
+ case FRAME_PCALLH:
+ if (frame_ftsz(frame) >= (ptrdiff_t)(2*sizeof(TValue))) /* xpcall? */
+ return savestack(L, frame-1); /* Point to xpcall's errorfunc. */
+ return 0;
+ default:
+ lua_assert(0);
+ return 0;
+ }
+ }
+ return 0;
+}
+
+/* Runtime error. */
+LJ_NOINLINE void lj_err_run(lua_State *L)
+{
+ ptrdiff_t ef = finderrfunc(L);
+ if (ef) {
+ TValue *errfunc = restorestack(L, ef);
+ TValue *top = L->top;
+ lj_trace_abort(G(L));
+ if (!tvisfunc(errfunc) || L->status == LUA_ERRERR) {
+ setstrV(L, top-1, lj_err_str(L, LJ_ERR_ERRERR));
+ lj_err_throw(L, LUA_ERRERR);
+ }
+ L->status = LUA_ERRERR;
+ copyTV(L, top, top-1);
+ copyTV(L, top-1, errfunc);
+ L->top = top+1;
+ lj_vm_call(L, top, 1+1); /* Stack: |errfunc|msg| -> |msg| */
+ }
+ lj_err_throw(L, LUA_ERRRUN);
+}
+
+/* Formatted runtime error message. */
+LJ_NORET LJ_NOINLINE static void err_msgv(lua_State *L, ErrMsg em, ...)
+{
+ const char *msg;
+ va_list argp;
+ va_start(argp, em);
+ if (curr_funcisL(L)) L->top = curr_topL(L);
+ msg = lj_str_pushvf(L, err2msg(em), argp);
+ va_end(argp);
+ lj_debug_addloc(L, msg, L->base-1, NULL);
+ lj_err_run(L);
+}
+
+/* Non-vararg variant for better calling conventions. */
+LJ_NOINLINE void lj_err_msg(lua_State *L, ErrMsg em)
+{
+ err_msgv(L, em);
+}
+
+/* Lexer error. */
+LJ_NOINLINE void lj_err_lex(lua_State *L, GCstr *src, const char *tok,
+ BCLine line, ErrMsg em, va_list argp)
+{
+ char buff[LUA_IDSIZE];
+ const char *msg;
+ lj_debug_shortname(buff, src);
+ msg = lj_str_pushvf(L, err2msg(em), argp);
+ msg = lj_str_pushf(L, "%s:%d: %s", buff, line, msg);
+ if (tok)
+ lj_str_pushf(L, err2msg(LJ_ERR_XNEAR), msg, tok);
+ lj_err_throw(L, LUA_ERRSYNTAX);
+}
+
+/* Typecheck error for operands. */
+LJ_NOINLINE void lj_err_optype(lua_State *L, cTValue *o, ErrMsg opm)
+{
+ const char *tname = lj_typename(o);
+ const char *opname = err2msg(opm);
+ if (curr_funcisL(L)) {
+ GCproto *pt = curr_proto(L);
+ const BCIns *pc = cframe_Lpc(L) - 1;
+ const char *oname = NULL;
+ const char *kind = lj_debug_slotname(pt, pc, (BCReg)(o-L->base), &oname);
+ if (kind)
+ err_msgv(L, LJ_ERR_BADOPRT, opname, kind, oname, tname);
+ }
+ err_msgv(L, LJ_ERR_BADOPRV, opname, tname);
+}
+
+/* Typecheck error for ordered comparisons. */
+LJ_NOINLINE void lj_err_comp(lua_State *L, cTValue *o1, cTValue *o2)
+{
+ const char *t1 = lj_typename(o1);
+ const char *t2 = lj_typename(o2);
+ err_msgv(L, t1 == t2 ? LJ_ERR_BADCMPV : LJ_ERR_BADCMPT, t1, t2);
+ /* This assumes the two "boolean" entries are commoned by the C compiler. */
+}
+
+/* Typecheck error for __call. */
+LJ_NOINLINE void lj_err_optype_call(lua_State *L, TValue *o)
+{
+ /* Gross hack if lua_[p]call or pcall/xpcall fail for a non-callable object:
+ ** L->base still points to the caller. So add a dummy frame with L instead
+ ** of a function. See lua_getstack().
+ */
+ const BCIns *pc = cframe_Lpc(L);
+ if (((ptrdiff_t)pc & FRAME_TYPE) != FRAME_LUA) {
+ const char *tname = lj_typename(o);
+ setframe_pc(o, pc);
+ setframe_gc(o, obj2gco(L));
+ L->top = L->base = o+1;
+ err_msgv(L, LJ_ERR_BADCALL, tname);
+ }
+ lj_err_optype(L, o, LJ_ERR_OPCALL);
+}
+
+/* Error in context of caller. */
+LJ_NOINLINE void lj_err_callermsg(lua_State *L, const char *msg)
+{
+ TValue *frame = L->base-1;
+ TValue *pframe = NULL;
+ if (frame_islua(frame)) {
+ pframe = frame_prevl(frame);
+ } else if (frame_iscont(frame)) {
+#if LJ_HASFFI
+ if ((frame-1)->u32.lo == LJ_CONT_FFI_CALLBACK) {
+ pframe = frame;
+ frame = NULL;
+ } else
+#endif
+ {
+ pframe = frame_prevd(frame);
+#if LJ_HASFFI
+ /* Remove frame for FFI metamethods. */
+ if (frame_func(frame)->c.ffid >= FF_ffi_meta___index &&
+ frame_func(frame)->c.ffid <= FF_ffi_meta___tostring) {
+ L->base = pframe+1;
+ L->top = frame;
+ setcframe_pc(cframe_raw(L->cframe), frame_contpc(frame));
+ }
+#endif
+ }
+ }
+ lj_debug_addloc(L, msg, pframe, frame);
+ lj_err_run(L);
+}
+
+/* Formatted error in context of caller. */
+LJ_NOINLINE void lj_err_callerv(lua_State *L, ErrMsg em, ...)
+{
+ const char *msg;
+ va_list argp;
+ va_start(argp, em);
+ msg = lj_str_pushvf(L, err2msg(em), argp);
+ va_end(argp);
+ lj_err_callermsg(L, msg);
+}
+
+/* Error in context of caller. */
+LJ_NOINLINE void lj_err_caller(lua_State *L, ErrMsg em)
+{
+ lj_err_callermsg(L, err2msg(em));
+}
+
+/* Argument error message. */
+LJ_NORET LJ_NOINLINE static void err_argmsg(lua_State *L, int narg,
+ const char *msg)
+{
+ const char *fname = "?";
+ const char *ftype = lj_debug_funcname(L, L->base - 1, &fname);
+ if (narg < 0 && narg > LUA_REGISTRYINDEX)
+ narg = (int)(L->top - L->base) + narg + 1;
+ if (ftype && ftype[3] == 'h' && --narg == 0) /* Check for "method". */
+ msg = lj_str_pushf(L, err2msg(LJ_ERR_BADSELF), fname, msg);
+ else
+ msg = lj_str_pushf(L, err2msg(LJ_ERR_BADARG), narg, fname, msg);
+ lj_err_callermsg(L, msg);
+}
+
+/* Formatted argument error. */
+LJ_NOINLINE void lj_err_argv(lua_State *L, int narg, ErrMsg em, ...)
+{
+ const char *msg;
+ va_list argp;
+ va_start(argp, em);
+ msg = lj_str_pushvf(L, err2msg(em), argp);
+ va_end(argp);
+ err_argmsg(L, narg, msg);
+}
+
+/* Argument error. */
+LJ_NOINLINE void lj_err_arg(lua_State *L, int narg, ErrMsg em)
+{
+ err_argmsg(L, narg, err2msg(em));
+}
+
+/* Typecheck error for arguments. */
+LJ_NOINLINE void lj_err_argtype(lua_State *L, int narg, const char *xname)
+{
+ const char *tname, *msg;
+ if (narg <= LUA_REGISTRYINDEX) {
+ if (narg >= LUA_GLOBALSINDEX) {
+ tname = lj_obj_itypename[~LJ_TTAB];
+ } else {
+ GCfunc *fn = curr_func(L);
+ int idx = LUA_GLOBALSINDEX - narg;
+ if (idx <= fn->c.nupvalues)
+ tname = lj_typename(&fn->c.upvalue[idx-1]);
+ else
+ tname = lj_obj_typename[0];
+ }
+ } else {
+ TValue *o = narg < 0 ? L->top + narg : L->base + narg-1;
+ tname = o < L->top ? lj_typename(o) : lj_obj_typename[0];
+ }
+ msg = lj_str_pushf(L, err2msg(LJ_ERR_BADTYPE), xname, tname);
+ err_argmsg(L, narg, msg);
+}
+
+/* Typecheck error for arguments. */
+LJ_NOINLINE void lj_err_argt(lua_State *L, int narg, int tt)
+{
+ lj_err_argtype(L, narg, lj_obj_typename[tt+1]);
+}
+
+/* -- Public error handling API ------------------------------------------- */
+
+LUA_API lua_CFunction lua_atpanic(lua_State *L, lua_CFunction panicf)
+{
+ lua_CFunction old = G(L)->panic;
+ G(L)->panic = panicf;
+ return old;
+}
+
+/* Forwarders for the public API (C calling convention and no LJ_NORET). */
+LUA_API int lua_error(lua_State *L)
+{
+ lj_err_run(L);
+ return 0; /* unreachable */
+}
+
+LUALIB_API int luaL_argerror(lua_State *L, int narg, const char *msg)
+{
+ err_argmsg(L, narg, msg);
+ return 0; /* unreachable */
+}
+
+LUALIB_API int luaL_typerror(lua_State *L, int narg, const char *xname)
+{
+ lj_err_argtype(L, narg, xname);
+ return 0; /* unreachable */
+}
+
+LUALIB_API void luaL_where(lua_State *L, int level)
+{
+ int size;
+ cTValue *frame = lj_debug_frame(L, level, &size);
+ lj_debug_addloc(L, "", frame, size ? frame+size : NULL);
+}
+
+LUALIB_API int luaL_error(lua_State *L, const char *fmt, ...)
+{
+ const char *msg;
+ va_list argp;
+ va_start(argp, fmt);
+ msg = lj_str_pushvf(L, fmt, argp);
+ va_end(argp);
+ lj_err_callermsg(L, msg);
+ return 0; /* unreachable */
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_err.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_err.h
new file mode 100644
index 0000000..cba5fb7
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_err.h
@@ -0,0 +1,41 @@
+/*
+** Error handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_ERR_H
+#define _LJ_ERR_H
+
+#include <stdarg.h>
+
+#include "lj_obj.h"
+
+typedef enum {
+#define ERRDEF(name, msg) \
+ LJ_ERR_##name, LJ_ERR_##name##_ = LJ_ERR_##name + sizeof(msg)-1,
+#include "lj_errmsg.h"
+ LJ_ERR__MAX
+} ErrMsg;
+
+LJ_DATA const char *lj_err_allmsg;
+#define err2msg(em) (lj_err_allmsg+(int)(em))
+
+LJ_FUNC GCstr *lj_err_str(lua_State *L, ErrMsg em);
+LJ_FUNCA_NORET void LJ_FASTCALL lj_err_throw(lua_State *L, int errcode);
+LJ_FUNC_NORET void lj_err_mem(lua_State *L);
+LJ_FUNC_NORET void lj_err_run(lua_State *L);
+LJ_FUNC_NORET void lj_err_msg(lua_State *L, ErrMsg em);
+LJ_FUNC_NORET void lj_err_lex(lua_State *L, GCstr *src, const char *tok,
+ BCLine line, ErrMsg em, va_list argp);
+LJ_FUNC_NORET void lj_err_optype(lua_State *L, cTValue *o, ErrMsg opm);
+LJ_FUNC_NORET void lj_err_comp(lua_State *L, cTValue *o1, cTValue *o2);
+LJ_FUNC_NORET void lj_err_optype_call(lua_State *L, TValue *o);
+LJ_FUNC_NORET void lj_err_callermsg(lua_State *L, const char *msg);
+LJ_FUNC_NORET void lj_err_callerv(lua_State *L, ErrMsg em, ...);
+LJ_FUNC_NORET void lj_err_caller(lua_State *L, ErrMsg em);
+LJ_FUNC_NORET void lj_err_arg(lua_State *L, int narg, ErrMsg em);
+LJ_FUNC_NORET void lj_err_argv(lua_State *L, int narg, ErrMsg em, ...);
+LJ_FUNC_NORET void lj_err_argtype(lua_State *L, int narg, const char *xname);
+LJ_FUNC_NORET void lj_err_argt(lua_State *L, int narg, int tt);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_errmsg.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_errmsg.h
new file mode 100644
index 0000000..ac552f4
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_errmsg.h
@@ -0,0 +1,193 @@
+/*
+** VM error messages.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* This file may be included multiple times with different ERRDEF macros. */
+
+/* Basic error handling. */
+ERRDEF(ERRMEM, "not enough memory")
+ERRDEF(ERRERR, "error in error handling")
+ERRDEF(ERRCPP, "C++ exception")
+
+/* Allocations. */
+ERRDEF(STROV, "string length overflow")
+ERRDEF(UDATAOV, "userdata length overflow")
+ERRDEF(STKOV, "stack overflow")
+ERRDEF(STKOVM, "stack overflow (%s)")
+ERRDEF(TABOV, "table overflow")
+
+/* Table indexing. */
+ERRDEF(NANIDX, "table index is NaN")
+ERRDEF(NILIDX, "table index is nil")
+ERRDEF(NEXTIDX, "invalid key to " LUA_QL("next"))
+
+/* Metamethod resolving. */
+ERRDEF(BADCALL, "attempt to call a %s value")
+ERRDEF(BADOPRT, "attempt to %s %s " LUA_QS " (a %s value)")
+ERRDEF(BADOPRV, "attempt to %s a %s value")
+ERRDEF(BADCMPT, "attempt to compare %s with %s")
+ERRDEF(BADCMPV, "attempt to compare two %s values")
+ERRDEF(GETLOOP, "loop in gettable")
+ERRDEF(SETLOOP, "loop in settable")
+ERRDEF(OPCALL, "call")
+ERRDEF(OPINDEX, "index")
+ERRDEF(OPARITH, "perform arithmetic on")
+ERRDEF(OPCAT, "concatenate")
+ERRDEF(OPLEN, "get length of")
+
+/* Type checks. */
+ERRDEF(BADSELF, "calling " LUA_QS " on bad self (%s)")
+ERRDEF(BADARG, "bad argument #%d to " LUA_QS " (%s)")
+ERRDEF(BADTYPE, "%s expected, got %s")
+ERRDEF(BADVAL, "invalid value")
+ERRDEF(NOVAL, "value expected")
+ERRDEF(NOCORO, "coroutine expected")
+ERRDEF(NOTABN, "nil or table expected")
+ERRDEF(NOLFUNC, "Lua function expected")
+ERRDEF(NOFUNCL, "function or level expected")
+ERRDEF(NOSFT, "string/function/table expected")
+ERRDEF(NOPROXY, "boolean or proxy expected")
+ERRDEF(FORINIT, LUA_QL("for") " initial value must be a number")
+ERRDEF(FORLIM, LUA_QL("for") " limit must be a number")
+ERRDEF(FORSTEP, LUA_QL("for") " step must be a number")
+
+/* C API checks. */
+ERRDEF(NOENV, "no calling environment")
+ERRDEF(CYIELD, "attempt to yield across C-call boundary")
+ERRDEF(BADLU, "bad light userdata pointer")
+ERRDEF(NOGCMM, "bad action while in __gc metamethod")
+#if LJ_TARGET_WINDOWS
+ERRDEF(BADFPU, "bad FPU precision (use D3DCREATE_FPU_PRESERVE with DirectX)")
+#endif
+
+/* Standard library function errors. */
+ERRDEF(ASSERT, "assertion failed!")
+ERRDEF(PROTMT, "cannot change a protected metatable")
+ERRDEF(UNPACK, "too many results to unpack")
+ERRDEF(RDRSTR, "reader function must return a string")
+ERRDEF(PRTOSTR, LUA_QL("tostring") " must return a string to " LUA_QL("print"))
+ERRDEF(IDXRNG, "index out of range")
+ERRDEF(BASERNG, "base out of range")
+ERRDEF(LVLRNG, "level out of range")
+ERRDEF(INVLVL, "invalid level")
+ERRDEF(INVOPT, "invalid option")
+ERRDEF(INVOPTM, "invalid option " LUA_QS)
+ERRDEF(INVFMT, "invalid format")
+ERRDEF(SETFENV, LUA_QL("setfenv") " cannot change environment of given object")
+ERRDEF(CORUN, "cannot resume running coroutine")
+ERRDEF(CODEAD, "cannot resume dead coroutine")
+ERRDEF(COSUSP, "cannot resume non-suspended coroutine")
+ERRDEF(TABINS, "wrong number of arguments to " LUA_QL("insert"))
+ERRDEF(TABCAT, "invalid value (%s) at index %d in table for " LUA_QL("concat"))
+ERRDEF(TABSORT, "invalid order function for sorting")
+ERRDEF(IOCLFL, "attempt to use a closed file")
+ERRDEF(IOSTDCL, "standard file is closed")
+ERRDEF(OSUNIQF, "unable to generate a unique filename")
+ERRDEF(OSDATEF, "field " LUA_QS " missing in date table")
+ERRDEF(STRDUMP, "unable to dump given function")
+ERRDEF(STRSLC, "string slice too long")
+ERRDEF(STRPATB, "missing " LUA_QL("[") " after " LUA_QL("%f") " in pattern")
+ERRDEF(STRPATC, "invalid pattern capture")
+ERRDEF(STRPATE, "malformed pattern (ends with " LUA_QL("%") ")")
+ERRDEF(STRPATM, "malformed pattern (missing " LUA_QL("]") ")")
+ERRDEF(STRPATU, "unbalanced pattern")
+ERRDEF(STRPATX, "pattern too complex")
+ERRDEF(STRCAPI, "invalid capture index")
+ERRDEF(STRCAPN, "too many captures")
+ERRDEF(STRCAPU, "unfinished capture")
+ERRDEF(STRFMTO, "invalid option " LUA_QL("%%%c") " to " LUA_QL("format"))
+ERRDEF(STRFMTR, "invalid format (repeated flags)")
+ERRDEF(STRFMTW, "invalid format (width or precision too long)")
+ERRDEF(STRGSRV, "invalid replacement value (a %s)")
+ERRDEF(BADMODN, "name conflict for module " LUA_QS)
+#if LJ_HASJIT
+ERRDEF(JITPROT, "runtime code generation failed, restricted kernel?")
+#if LJ_TARGET_X86ORX64
+ERRDEF(NOJIT, "JIT compiler disabled, CPU does not support SSE2")
+#else
+ERRDEF(NOJIT, "JIT compiler disabled")
+#endif
+#elif defined(LJ_ARCH_NOJIT)
+ERRDEF(NOJIT, "no JIT compiler for this architecture (yet)")
+#else
+ERRDEF(NOJIT, "JIT compiler permanently disabled by build option")
+#endif
+ERRDEF(JITOPT, "unknown or malformed optimization flag " LUA_QS)
+
+/* Lexer/parser errors. */
+ERRDEF(XMODE, "attempt to load chunk with wrong mode")
+ERRDEF(XNEAR, "%s near " LUA_QS)
+ERRDEF(XELEM, "lexical element too long")
+ERRDEF(XLINES, "chunk has too many lines")
+ERRDEF(XLEVELS, "chunk has too many syntax levels")
+ERRDEF(XNUMBER, "malformed number")
+ERRDEF(XLSTR, "unfinished long string")
+ERRDEF(XLCOM, "unfinished long comment")
+ERRDEF(XSTR, "unfinished string")
+ERRDEF(XESC, "invalid escape sequence")
+ERRDEF(XLDELIM, "invalid long string delimiter")
+ERRDEF(XTOKEN, LUA_QS " expected")
+ERRDEF(XJUMP, "control structure too long")
+ERRDEF(XSLOTS, "function or expression too complex")
+ERRDEF(XLIMC, "chunk has more than %d local variables")
+ERRDEF(XLIMM, "main function has more than %d %s")
+ERRDEF(XLIMF, "function at line %d has more than %d %s")
+ERRDEF(XMATCH, LUA_QS " expected (to close " LUA_QS " at line %d)")
+ERRDEF(XFIXUP, "function too long for return fixup")
+ERRDEF(XPARAM, "<name> or " LUA_QL("...") " expected")
+#if !LJ_52
+ERRDEF(XAMBIG, "ambiguous syntax (function call x new statement)")
+#endif
+ERRDEF(XFUNARG, "function arguments expected")
+ERRDEF(XSYMBOL, "unexpected symbol")
+ERRDEF(XDOTS, "cannot use " LUA_QL("...") " outside a vararg function")
+ERRDEF(XSYNTAX, "syntax error")
+ERRDEF(XFOR, LUA_QL("=") " or " LUA_QL("in") " expected")
+ERRDEF(XBREAK, "no loop to break")
+ERRDEF(XLUNDEF, "undefined label " LUA_QS)
+ERRDEF(XLDUP, "duplicate label " LUA_QS)
+ERRDEF(XGSCOPE, "<goto %s> jumps into the scope of local " LUA_QS)
+
+/* Bytecode reader errors. */
+ERRDEF(BCFMT, "cannot load incompatible bytecode")
+ERRDEF(BCBAD, "cannot load malformed bytecode")
+
+#if LJ_HASFFI
+/* FFI errors. */
+ERRDEF(FFI_INVTYPE, "invalid C type")
+ERRDEF(FFI_INVSIZE, "size of C type is unknown or too large")
+ERRDEF(FFI_BADSCL, "bad storage class")
+ERRDEF(FFI_DECLSPEC, "declaration specifier expected")
+ERRDEF(FFI_BADTAG, "undeclared or implicit tag " LUA_QS)
+ERRDEF(FFI_REDEF, "attempt to redefine " LUA_QS)
+ERRDEF(FFI_NUMPARAM, "wrong number of type parameters")
+ERRDEF(FFI_INITOV, "too many initializers for " LUA_QS)
+ERRDEF(FFI_BADCONV, "cannot convert " LUA_QS " to " LUA_QS)
+ERRDEF(FFI_BADLEN, "attempt to get length of " LUA_QS)
+ERRDEF(FFI_BADCONCAT, "attempt to concatenate " LUA_QS " and " LUA_QS)
+ERRDEF(FFI_BADARITH, "attempt to perform arithmetic on " LUA_QS " and " LUA_QS)
+ERRDEF(FFI_BADCOMP, "attempt to compare " LUA_QS " with " LUA_QS)
+ERRDEF(FFI_BADCALL, LUA_QS " is not callable")
+ERRDEF(FFI_NUMARG, "wrong number of arguments for function call")
+ERRDEF(FFI_BADMEMBER, LUA_QS " has no member named " LUA_QS)
+ERRDEF(FFI_BADIDX, LUA_QS " cannot be indexed")
+ERRDEF(FFI_BADIDXW, LUA_QS " cannot be indexed with " LUA_QS)
+ERRDEF(FFI_BADMM, LUA_QS " has no " LUA_QS " metamethod")
+ERRDEF(FFI_WRCONST, "attempt to write to constant location")
+ERRDEF(FFI_NODECL, "missing declaration for symbol " LUA_QS)
+ERRDEF(FFI_BADCBACK, "bad callback")
+#if LJ_OS_NOJIT
+ERRDEF(FFI_CBACKOV, "no support for callbacks on this OS")
+#else
+ERRDEF(FFI_CBACKOV, "too many callbacks")
+#endif
+ERRDEF(FFI_NYIPACKBIT, "NYI: packed bit fields")
+ERRDEF(FFI_NYICALL, "NYI: cannot call this C function (yet)")
+#endif
+
+#undef ERRDEF
+
+/* Detecting unused error messages:
+ awk -F, '/^ERRDEF/ { gsub(/ERRDEF./, ""); printf "grep -q LJ_ERR_%s *.[ch] || echo %s\n", $1, $1}' lj_errmsg.h | sh
+*/
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_ff.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_ff.h
new file mode 100644
index 0000000..31d65a0
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_ff.h
@@ -0,0 +1,18 @@
+/*
+** Fast function IDs.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_FF_H
+#define _LJ_FF_H
+
+/* Fast function ID. */
+typedef enum {
+ FF_LUA_ = FF_LUA, /* Lua function (must be 0). */
+ FF_C_ = FF_C, /* Regular C function (must be 1). */
+#define FFDEF(name) FF_##name,
+#include "lj_ffdef.h"
+ FF__MAX
+} FastFunc;
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_ffrecord.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_ffrecord.c
new file mode 100644
index 0000000..da09dca
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_ffrecord.c
@@ -0,0 +1,887 @@
+/*
+** Fast function call recorder.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_ffrecord_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT
+
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_frame.h"
+#include "lj_bc.h"
+#include "lj_ff.h"
+#include "lj_ir.h"
+#include "lj_jit.h"
+#include "lj_ircall.h"
+#include "lj_iropt.h"
+#include "lj_trace.h"
+#include "lj_record.h"
+#include "lj_ffrecord.h"
+#include "lj_crecord.h"
+#include "lj_dispatch.h"
+#include "lj_vm.h"
+#include "lj_strscan.h"
+
+/* Some local macros to save typing. Undef'd at the end. */
+#define IR(ref) (&J->cur.ir[(ref)])
+
+/* Pass IR on to next optimization in chain (FOLD). */
+#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))
+
+/* -- Fast function recording handlers ------------------------------------ */
+
+/* Conventions for fast function call handlers:
+**
+** The argument slots start at J->base[0]. All of them are guaranteed to be
+** valid and type-specialized references. J->base[J->maxslot] is set to 0
+** as a sentinel. The runtime argument values start at rd->argv[0].
+**
+** In general fast functions should check for presence of all of their
+** arguments and for the correct argument types. Some simplifications
+** are allowed if the interpreter throws instead. But even if recording
+** is aborted, the generated IR must be consistent (no zero-refs).
+**
+** The number of results in rd->nres is set to 1. Handlers that return
+** a different number of results need to override it. A negative value
+** prevents return processing (e.g. for pending calls).
+**
+** Results need to be stored starting at J->base[0]. Return processing
+** moves them to the right slots later.
+**
+** The per-ffid auxiliary data is the value of the 2nd part of the
+** LJLIB_REC() annotation. This allows handling similar functionality
+** in a common handler.
+*/
+
+/* Type of handler to record a fast function. */
+typedef void (LJ_FASTCALL *RecordFunc)(jit_State *J, RecordFFData *rd);
+
+/* Get runtime value of int argument. */
+static int32_t argv2int(jit_State *J, TValue *o)
+{
+ if (!lj_strscan_numberobj(o))
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ return tvisint(o) ? intV(o) : lj_num2int(numV(o));
+}
+
+/* Get runtime value of string argument. */
+static GCstr *argv2str(jit_State *J, TValue *o)
+{
+ if (LJ_LIKELY(tvisstr(o))) {
+ return strV(o);
+ } else {
+ GCstr *s;
+ if (!tvisnumber(o))
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ if (tvisint(o))
+ s = lj_str_fromint(J->L, intV(o));
+ else
+ s = lj_str_fromnum(J->L, &o->n);
+ setstrV(J->L, o, s);
+ return s;
+ }
+}
+
+/* Return number of results wanted by caller. */
+static ptrdiff_t results_wanted(jit_State *J)
+{
+ TValue *frame = J->L->base-1;
+ if (frame_islua(frame))
+ return (ptrdiff_t)bc_b(frame_pc(frame)[-1]) - 1;
+ else
+ return -1;
+}
+
+/* Throw error for unsupported variant of fast function. */
+LJ_NORET static void recff_nyiu(jit_State *J)
+{
+ setfuncV(J->L, &J->errinfo, J->fn);
+ lj_trace_err_info(J, LJ_TRERR_NYIFFU);
+}
+
+/* Fallback handler for all fast functions that are not recorded (yet). */
+static void LJ_FASTCALL recff_nyi(jit_State *J, RecordFFData *rd)
+{
+ setfuncV(J->L, &J->errinfo, J->fn);
+ lj_trace_err_info(J, LJ_TRERR_NYIFF);
+ UNUSED(rd);
+}
+
+/* C functions can have arbitrary side-effects and are not recorded (yet). */
+static void LJ_FASTCALL recff_c(jit_State *J, RecordFFData *rd)
+{
+ setfuncV(J->L, &J->errinfo, J->fn);
+ lj_trace_err_info(J, LJ_TRERR_NYICF);
+ UNUSED(rd);
+}
+
+/* -- Base library fast functions ----------------------------------------- */
+
+static void LJ_FASTCALL recff_assert(jit_State *J, RecordFFData *rd)
+{
+ /* Arguments already specialized. The interpreter throws for nil/false. */
+ rd->nres = J->maxslot; /* Pass through all arguments. */
+}
+
+static void LJ_FASTCALL recff_type(jit_State *J, RecordFFData *rd)
+{
+ /* Arguments already specialized. Result is a constant string. Neat, huh? */
+ uint32_t t;
+ if (tvisnumber(&rd->argv[0]))
+ t = ~LJ_TNUMX;
+ else if (LJ_64 && tvislightud(&rd->argv[0]))
+ t = ~LJ_TLIGHTUD;
+ else
+ t = ~itype(&rd->argv[0]);
+ J->base[0] = lj_ir_kstr(J, strV(&J->fn->c.upvalue[t]));
+ UNUSED(rd);
+}
+
+static void LJ_FASTCALL recff_getmetatable(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = J->base[0];
+ if (tr) {
+ RecordIndex ix;
+ ix.tab = tr;
+ copyTV(J->L, &ix.tabv, &rd->argv[0]);
+ if (lj_record_mm_lookup(J, &ix, MM_metatable))
+ J->base[0] = ix.mobj;
+ else
+ J->base[0] = ix.mt;
+ } /* else: Interpreter will throw. */
+}
+
+static void LJ_FASTCALL recff_setmetatable(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = J->base[0];
+ TRef mt = J->base[1];
+ if (tref_istab(tr) && (tref_istab(mt) || (mt && tref_isnil(mt)))) {
+ TRef fref, mtref;
+ RecordIndex ix;
+ ix.tab = tr;
+ copyTV(J->L, &ix.tabv, &rd->argv[0]);
+ lj_record_mm_lookup(J, &ix, MM_metatable); /* Guard for no __metatable. */
+ fref = emitir(IRT(IR_FREF, IRT_P32), tr, IRFL_TAB_META);
+ mtref = tref_isnil(mt) ? lj_ir_knull(J, IRT_TAB) : mt;
+ emitir(IRT(IR_FSTORE, IRT_TAB), fref, mtref);
+ if (!tref_isnil(mt))
+ emitir(IRT(IR_TBAR, IRT_TAB), tr, 0);
+ J->base[0] = tr;
+ J->needsnap = 1;
+ } /* else: Interpreter will throw. */
+}
+
+static void LJ_FASTCALL recff_rawget(jit_State *J, RecordFFData *rd)
+{
+ RecordIndex ix;
+ ix.tab = J->base[0]; ix.key = J->base[1];
+ if (tref_istab(ix.tab) && ix.key) {
+ ix.val = 0; ix.idxchain = 0;
+ settabV(J->L, &ix.tabv, tabV(&rd->argv[0]));
+ copyTV(J->L, &ix.keyv, &rd->argv[1]);
+ J->base[0] = lj_record_idx(J, &ix);
+ } /* else: Interpreter will throw. */
+}
+
+static void LJ_FASTCALL recff_rawset(jit_State *J, RecordFFData *rd)
+{
+ RecordIndex ix;
+ ix.tab = J->base[0]; ix.key = J->base[1]; ix.val = J->base[2];
+ if (tref_istab(ix.tab) && ix.key && ix.val) {
+ ix.idxchain = 0;
+ settabV(J->L, &ix.tabv, tabV(&rd->argv[0]));
+ copyTV(J->L, &ix.keyv, &rd->argv[1]);
+ copyTV(J->L, &ix.valv, &rd->argv[2]);
+ lj_record_idx(J, &ix);
+ /* Pass through table at J->base[0] as result. */
+ } /* else: Interpreter will throw. */
+}
+
+static void LJ_FASTCALL recff_rawequal(jit_State *J, RecordFFData *rd)
+{
+ TRef tra = J->base[0];
+ TRef trb = J->base[1];
+ if (tra && trb) {
+ int diff = lj_record_objcmp(J, tra, trb, &rd->argv[0], &rd->argv[1]);
+ J->base[0] = diff ? TREF_FALSE : TREF_TRUE;
+ } /* else: Interpreter will throw. */
+}
+
+#if LJ_52
+static void LJ_FASTCALL recff_rawlen(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = J->base[0];
+ if (tref_isstr(tr))
+ J->base[0] = emitir(IRTI(IR_FLOAD), tr, IRFL_STR_LEN);
+ else if (tref_istab(tr))
+ J->base[0] = lj_ir_call(J, IRCALL_lj_tab_len, tr);
+ /* else: Interpreter will throw. */
+ UNUSED(rd);
+}
+#endif
+
+/* Determine mode of select() call. */
+int32_t lj_ffrecord_select_mode(jit_State *J, TRef tr, TValue *tv)
+{
+ if (tref_isstr(tr) && *strVdata(tv) == '#') { /* select('#', ...) */
+ if (strV(tv)->len == 1) {
+ emitir(IRTG(IR_EQ, IRT_STR), tr, lj_ir_kstr(J, strV(tv)));
+ } else {
+ TRef trptr = emitir(IRT(IR_STRREF, IRT_P32), tr, lj_ir_kint(J, 0));
+ TRef trchar = emitir(IRT(IR_XLOAD, IRT_U8), trptr, IRXLOAD_READONLY);
+ emitir(IRTG(IR_EQ, IRT_INT), trchar, lj_ir_kint(J, '#'));
+ }
+ return 0;
+ } else { /* select(n, ...) */
+ int32_t start = argv2int(J, tv);
+ if (start == 0) lj_trace_err(J, LJ_TRERR_BADTYPE); /* A bit misleading. */
+ return start;
+ }
+}
+
+static void LJ_FASTCALL recff_select(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = J->base[0];
+ if (tr) {
+ ptrdiff_t start = lj_ffrecord_select_mode(J, tr, &rd->argv[0]);
+ if (start == 0) { /* select('#', ...) */
+ J->base[0] = lj_ir_kint(J, J->maxslot - 1);
+ } else if (tref_isk(tr)) { /* select(k, ...) */
+ ptrdiff_t n = (ptrdiff_t)J->maxslot;
+ if (start < 0) start += n;
+ else if (start > n) start = n;
+ rd->nres = n - start;
+ if (start >= 1) {
+ ptrdiff_t i;
+ for (i = 0; i < n - start; i++)
+ J->base[i] = J->base[start+i];
+ } /* else: Interpreter will throw. */
+ } else {
+ recff_nyiu(J);
+ }
+ } /* else: Interpreter will throw. */
+}
+
+static void LJ_FASTCALL recff_tonumber(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = J->base[0];
+ TRef base = J->base[1];
+ if (tr && !tref_isnil(base)) {
+ base = lj_opt_narrow_toint(J, base);
+ if (!tref_isk(base) || IR(tref_ref(base))->i != 10)
+ recff_nyiu(J);
+ }
+ if (tref_isnumber_str(tr)) {
+ if (tref_isstr(tr)) {
+ TValue tmp;
+ if (!lj_strscan_num(strV(&rd->argv[0]), &tmp))
+ recff_nyiu(J); /* Would need an inverted STRTO for this case. */
+ tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);
+ }
+#if LJ_HASFFI
+ } else if (tref_iscdata(tr)) {
+ lj_crecord_tonumber(J, rd);
+ return;
+#endif
+ } else {
+ tr = TREF_NIL;
+ }
+ J->base[0] = tr;
+ UNUSED(rd);
+}
+
+static TValue *recff_metacall_cp(lua_State *L, lua_CFunction dummy, void *ud)
+{
+ jit_State *J = (jit_State *)ud;
+ lj_record_tailcall(J, 0, 1);
+ UNUSED(L); UNUSED(dummy);
+ return NULL;
+}
+
+static int recff_metacall(jit_State *J, RecordFFData *rd, MMS mm)
+{
+ RecordIndex ix;
+ ix.tab = J->base[0];
+ copyTV(J->L, &ix.tabv, &rd->argv[0]);
+ if (lj_record_mm_lookup(J, &ix, mm)) { /* Has metamethod? */
+ int errcode;
+ TValue argv0;
+ /* Temporarily insert metamethod below object. */
+ J->base[1] = J->base[0];
+ J->base[0] = ix.mobj;
+ copyTV(J->L, &argv0, &rd->argv[0]);
+ copyTV(J->L, &rd->argv[1], &rd->argv[0]);
+ copyTV(J->L, &rd->argv[0], &ix.mobjv);
+ /* Need to protect lj_record_tailcall because it may throw. */
+ errcode = lj_vm_cpcall(J->L, NULL, J, recff_metacall_cp);
+ /* Always undo Lua stack changes to avoid confusing the interpreter. */
+ copyTV(J->L, &rd->argv[0], &argv0);
+ if (errcode)
+ lj_err_throw(J->L, errcode); /* Propagate errors. */
+ rd->nres = -1; /* Pending call. */
+ return 1; /* Tailcalled to metamethod. */
+ }
+ return 0;
+}
+
+static void LJ_FASTCALL recff_tostring(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = J->base[0];
+ if (tref_isstr(tr)) {
+ /* Ignore __tostring in the string base metatable. */
+ /* Pass on result in J->base[0]. */
+ } else if (!recff_metacall(J, rd, MM_tostring)) {
+ if (tref_isnumber(tr)) {
+ J->base[0] = emitir(IRT(IR_TOSTR, IRT_STR), tr, 0);
+ } else if (tref_ispri(tr)) {
+ J->base[0] = lj_ir_kstr(J, strV(&J->fn->c.upvalue[tref_type(tr)]));
+ } else {
+ recff_nyiu(J);
+ }
+ }
+}
+
+static void LJ_FASTCALL recff_ipairs_aux(jit_State *J, RecordFFData *rd)
+{
+ RecordIndex ix;
+ ix.tab = J->base[0];
+ if (tref_istab(ix.tab)) {
+ if (!tvisnumber(&rd->argv[1])) /* No support for string coercion. */
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ setintV(&ix.keyv, numberVint(&rd->argv[1])+1);
+ settabV(J->L, &ix.tabv, tabV(&rd->argv[0]));
+ ix.val = 0; ix.idxchain = 0;
+ ix.key = lj_opt_narrow_toint(J, J->base[1]);
+ J->base[0] = ix.key = emitir(IRTI(IR_ADD), ix.key, lj_ir_kint(J, 1));
+ J->base[1] = lj_record_idx(J, &ix);
+ rd->nres = tref_isnil(J->base[1]) ? 0 : 2;
+ } /* else: Interpreter will throw. */
+}
+
+static void LJ_FASTCALL recff_ipairs(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = J->base[0];
+ if (!((LJ_52 || (LJ_HASFFI && tref_iscdata(tr))) &&
+ recff_metacall(J, rd, MM_ipairs))) {
+ if (tref_istab(tr)) {
+ J->base[0] = lj_ir_kfunc(J, funcV(&J->fn->c.upvalue[0]));
+ J->base[1] = tr;
+ J->base[2] = lj_ir_kint(J, 0);
+ rd->nres = 3;
+ } /* else: Interpreter will throw. */
+ }
+}
+
+static void LJ_FASTCALL recff_pcall(jit_State *J, RecordFFData *rd)
+{
+ if (J->maxslot >= 1) {
+ lj_record_call(J, 0, J->maxslot - 1);
+ rd->nres = -1; /* Pending call. */
+ } /* else: Interpreter will throw. */
+}
+
+static TValue *recff_xpcall_cp(lua_State *L, lua_CFunction dummy, void *ud)
+{
+ jit_State *J = (jit_State *)ud;
+ lj_record_call(J, 1, J->maxslot - 2);
+ UNUSED(L); UNUSED(dummy);
+ return NULL;
+}
+
+static void LJ_FASTCALL recff_xpcall(jit_State *J, RecordFFData *rd)
+{
+ if (J->maxslot >= 2) {
+ TValue argv0, argv1;
+ TRef tmp;
+ int errcode;
+ /* Swap function and traceback. */
+ tmp = J->base[0]; J->base[0] = J->base[1]; J->base[1] = tmp;
+ copyTV(J->L, &argv0, &rd->argv[0]);
+ copyTV(J->L, &argv1, &rd->argv[1]);
+ copyTV(J->L, &rd->argv[0], &argv1);
+ copyTV(J->L, &rd->argv[1], &argv0);
+ /* Need to protect lj_record_call because it may throw. */
+ errcode = lj_vm_cpcall(J->L, NULL, J, recff_xpcall_cp);
+ /* Always undo Lua stack swap to avoid confusing the interpreter. */
+ copyTV(J->L, &rd->argv[0], &argv0);
+ copyTV(J->L, &rd->argv[1], &argv1);
+ if (errcode)
+ lj_err_throw(J->L, errcode); /* Propagate errors. */
+ rd->nres = -1; /* Pending call. */
+ } /* else: Interpreter will throw. */
+}
+
+/* -- Math library fast functions ----------------------------------------- */
+
+static void LJ_FASTCALL recff_math_abs(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = lj_ir_tonum(J, J->base[0]);
+ J->base[0] = emitir(IRTN(IR_ABS), tr, lj_ir_knum_abs(J));
+ UNUSED(rd);
+}
+
+/* Record rounding functions math.floor and math.ceil. */
+static void LJ_FASTCALL recff_math_round(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = J->base[0];
+ if (!tref_isinteger(tr)) { /* Pass through integers unmodified. */
+ tr = emitir(IRTN(IR_FPMATH), lj_ir_tonum(J, tr), rd->data);
+ /* Result is integral (or NaN/Inf), but may not fit an int32_t. */
+ if (LJ_DUALNUM) { /* Try to narrow using a guarded conversion to int. */
+ lua_Number n = lj_vm_foldfpm(numberVnum(&rd->argv[0]), rd->data);
+ if (n == (lua_Number)lj_num2int(n))
+ tr = emitir(IRTGI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_CHECK);
+ }
+ J->base[0] = tr;
+ }
+}
+
+/* Record unary math.* functions, mapped to IR_FPMATH opcode. */
+static void LJ_FASTCALL recff_math_unary(jit_State *J, RecordFFData *rd)
+{
+ J->base[0] = emitir(IRTN(IR_FPMATH), lj_ir_tonum(J, J->base[0]), rd->data);
+}
+
+/* Record math.log. */
+static void LJ_FASTCALL recff_math_log(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = lj_ir_tonum(J, J->base[0]);
+ if (J->base[1]) {
+#ifdef LUAJIT_NO_LOG2
+ uint32_t fpm = IRFPM_LOG;
+#else
+ uint32_t fpm = IRFPM_LOG2;
+#endif
+ TRef trb = lj_ir_tonum(J, J->base[1]);
+ tr = emitir(IRTN(IR_FPMATH), tr, fpm);
+ trb = emitir(IRTN(IR_FPMATH), trb, fpm);
+ trb = emitir(IRTN(IR_DIV), lj_ir_knum_one(J), trb);
+ tr = emitir(IRTN(IR_MUL), tr, trb);
+ } else {
+ tr = emitir(IRTN(IR_FPMATH), tr, IRFPM_LOG);
+ }
+ J->base[0] = tr;
+ UNUSED(rd);
+}
+
+/* Record math.atan2. */
+static void LJ_FASTCALL recff_math_atan2(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = lj_ir_tonum(J, J->base[0]);
+ TRef tr2 = lj_ir_tonum(J, J->base[1]);
+ J->base[0] = emitir(IRTN(IR_ATAN2), tr, tr2);
+ UNUSED(rd);
+}
+
+/* Record math.ldexp. */
+static void LJ_FASTCALL recff_math_ldexp(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = lj_ir_tonum(J, J->base[0]);
+#if LJ_TARGET_X86ORX64
+ TRef tr2 = lj_ir_tonum(J, J->base[1]);
+#else
+ TRef tr2 = lj_opt_narrow_toint(J, J->base[1]);
+#endif
+ J->base[0] = emitir(IRTN(IR_LDEXP), tr, tr2);
+ UNUSED(rd);
+}
+
+/* Record math.asin, math.acos, math.atan. */
+static void LJ_FASTCALL recff_math_atrig(jit_State *J, RecordFFData *rd)
+{
+ TRef y = lj_ir_tonum(J, J->base[0]);
+ TRef x = lj_ir_knum_one(J);
+ uint32_t ffid = rd->data;
+ if (ffid != FF_math_atan) {
+ TRef tmp = emitir(IRTN(IR_MUL), y, y);
+ tmp = emitir(IRTN(IR_SUB), x, tmp);
+ tmp = emitir(IRTN(IR_FPMATH), tmp, IRFPM_SQRT);
+ if (ffid == FF_math_asin) { x = tmp; } else { x = y; y = tmp; }
+ }
+ J->base[0] = emitir(IRTN(IR_ATAN2), y, x);
+}
+
+static void LJ_FASTCALL recff_math_htrig(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = lj_ir_tonum(J, J->base[0]);
+ J->base[0] = emitir(IRTN(IR_CALLN), tr, rd->data);
+}
+
+static void LJ_FASTCALL recff_math_modf(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = J->base[0];
+ if (tref_isinteger(tr)) {
+ J->base[0] = tr;
+ J->base[1] = lj_ir_kint(J, 0);
+ } else {
+ TRef trt;
+ tr = lj_ir_tonum(J, tr);
+ trt = emitir(IRTN(IR_FPMATH), tr, IRFPM_TRUNC);
+ J->base[0] = trt;
+ J->base[1] = emitir(IRTN(IR_SUB), tr, trt);
+ }
+ rd->nres = 2;
+}
+
+static void LJ_FASTCALL recff_math_degrad(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = lj_ir_tonum(J, J->base[0]);
+ TRef trm = lj_ir_knum(J, numV(&J->fn->c.upvalue[0]));
+ J->base[0] = emitir(IRTN(IR_MUL), tr, trm);
+ UNUSED(rd);
+}
+
+static void LJ_FASTCALL recff_math_pow(jit_State *J, RecordFFData *rd)
+{
+ J->base[0] = lj_opt_narrow_pow(J, J->base[0], J->base[1],
+ &rd->argv[0], &rd->argv[1]);
+ UNUSED(rd);
+}
+
+static void LJ_FASTCALL recff_math_minmax(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = lj_ir_tonumber(J, J->base[0]);
+ uint32_t op = rd->data;
+ BCReg i;
+ for (i = 1; J->base[i] != 0; i++) {
+ TRef tr2 = lj_ir_tonumber(J, J->base[i]);
+ IRType t = IRT_INT;
+ if (!(tref_isinteger(tr) && tref_isinteger(tr2))) {
+ if (tref_isinteger(tr)) tr = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT);
+ if (tref_isinteger(tr2)) tr2 = emitir(IRTN(IR_CONV), tr2, IRCONV_NUM_INT);
+ t = IRT_NUM;
+ }
+ tr = emitir(IRT(op, t), tr, tr2);
+ }
+ J->base[0] = tr;
+}
+
+static void LJ_FASTCALL recff_math_random(jit_State *J, RecordFFData *rd)
+{
+ GCudata *ud = udataV(&J->fn->c.upvalue[0]);
+ TRef tr, one;
+ lj_ir_kgc(J, obj2gco(ud), IRT_UDATA); /* Prevent collection. */
+ tr = lj_ir_call(J, IRCALL_lj_math_random_step, lj_ir_kptr(J, uddata(ud)));
+ one = lj_ir_knum_one(J);
+ tr = emitir(IRTN(IR_SUB), tr, one);
+ if (J->base[0]) {
+ TRef tr1 = lj_ir_tonum(J, J->base[0]);
+ if (J->base[1]) { /* d = floor(d*(r2-r1+1.0)) + r1 */
+ TRef tr2 = lj_ir_tonum(J, J->base[1]);
+ tr2 = emitir(IRTN(IR_SUB), tr2, tr1);
+ tr2 = emitir(IRTN(IR_ADD), tr2, one);
+ tr = emitir(IRTN(IR_MUL), tr, tr2);
+ tr = emitir(IRTN(IR_FPMATH), tr, IRFPM_FLOOR);
+ tr = emitir(IRTN(IR_ADD), tr, tr1);
+ } else { /* d = floor(d*r1) + 1.0 */
+ tr = emitir(IRTN(IR_MUL), tr, tr1);
+ tr = emitir(IRTN(IR_FPMATH), tr, IRFPM_FLOOR);
+ tr = emitir(IRTN(IR_ADD), tr, one);
+ }
+ }
+ J->base[0] = tr;
+ UNUSED(rd);
+}
+
+/* -- Bit library fast functions ------------------------------------------ */
+
+/* Record unary bit.tobit, bit.bnot, bit.bswap. */
+static void LJ_FASTCALL recff_bit_unary(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = lj_opt_narrow_tobit(J, J->base[0]);
+ J->base[0] = (rd->data == IR_TOBIT) ? tr : emitir(IRTI(rd->data), tr, 0);
+}
+
+/* Record N-ary bit.band, bit.bor, bit.bxor. */
+static void LJ_FASTCALL recff_bit_nary(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = lj_opt_narrow_tobit(J, J->base[0]);
+ uint32_t op = rd->data;
+ BCReg i;
+ for (i = 1; J->base[i] != 0; i++)
+ tr = emitir(IRTI(op), tr, lj_opt_narrow_tobit(J, J->base[i]));
+ J->base[0] = tr;
+}
+
+/* Record bit shifts. */
+static void LJ_FASTCALL recff_bit_shift(jit_State *J, RecordFFData *rd)
+{
+ TRef tr = lj_opt_narrow_tobit(J, J->base[0]);
+ TRef tsh = lj_opt_narrow_tobit(J, J->base[1]);
+ IROp op = (IROp)rd->data;
+ if (!(op < IR_BROL ? LJ_TARGET_MASKSHIFT : LJ_TARGET_MASKROT) &&
+ !tref_isk(tsh))
+ tsh = emitir(IRTI(IR_BAND), tsh, lj_ir_kint(J, 31));
+#ifdef LJ_TARGET_UNIFYROT
+ if (op == (LJ_TARGET_UNIFYROT == 1 ? IR_BROR : IR_BROL)) {
+ op = LJ_TARGET_UNIFYROT == 1 ? IR_BROL : IR_BROR;
+ tsh = emitir(IRTI(IR_NEG), tsh, tsh);
+ }
+#endif
+ J->base[0] = emitir(IRTI(op), tr, tsh);
+}
+
+/* -- String library fast functions --------------------------------------- */
+
+static void LJ_FASTCALL recff_string_len(jit_State *J, RecordFFData *rd)
+{
+ J->base[0] = emitir(IRTI(IR_FLOAD), lj_ir_tostr(J, J->base[0]), IRFL_STR_LEN);
+ UNUSED(rd);
+}
+
+/* Handle string.byte (rd->data = 0) and string.sub (rd->data = 1). */
+static void LJ_FASTCALL recff_string_range(jit_State *J, RecordFFData *rd)
+{
+ TRef trstr = lj_ir_tostr(J, J->base[0]);
+ TRef trlen = emitir(IRTI(IR_FLOAD), trstr, IRFL_STR_LEN);
+ TRef tr0 = lj_ir_kint(J, 0);
+ TRef trstart, trend;
+ GCstr *str = argv2str(J, &rd->argv[0]);
+ int32_t start, end;
+ if (rd->data) { /* string.sub(str, start [,end]) */
+ start = argv2int(J, &rd->argv[1]);
+ trstart = lj_opt_narrow_toint(J, J->base[1]);
+ trend = J->base[2];
+ if (tref_isnil(trend)) {
+ trend = lj_ir_kint(J, -1);
+ end = -1;
+ } else {
+ trend = lj_opt_narrow_toint(J, trend);
+ end = argv2int(J, &rd->argv[2]);
+ }
+ } else { /* string.byte(str, [,start [,end]]) */
+ if (tref_isnil(J->base[1])) {
+ start = 1;
+ trstart = lj_ir_kint(J, 1);
+ } else {
+ start = argv2int(J, &rd->argv[1]);
+ trstart = lj_opt_narrow_toint(J, J->base[1]);
+ }
+ if (J->base[1] && !tref_isnil(J->base[2])) {
+ trend = lj_opt_narrow_toint(J, J->base[2]);
+ end = argv2int(J, &rd->argv[2]);
+ } else {
+ trend = trstart;
+ end = start;
+ }
+ }
+ if (end < 0) {
+ emitir(IRTGI(IR_LT), trend, tr0);
+ trend = emitir(IRTI(IR_ADD), emitir(IRTI(IR_ADD), trlen, trend),
+ lj_ir_kint(J, 1));
+ end = end+(int32_t)str->len+1;
+ } else if ((MSize)end <= str->len) {
+ emitir(IRTGI(IR_ULE), trend, trlen);
+ } else {
+ emitir(IRTGI(IR_GT), trend, trlen);
+ end = (int32_t)str->len;
+ trend = trlen;
+ }
+ if (start < 0) {
+ emitir(IRTGI(IR_LT), trstart, tr0);
+ trstart = emitir(IRTI(IR_ADD), trlen, trstart);
+ start = start+(int32_t)str->len;
+ emitir(start < 0 ? IRTGI(IR_LT) : IRTGI(IR_GE), trstart, tr0);
+ if (start < 0) {
+ trstart = tr0;
+ start = 0;
+ }
+ } else {
+ if (start == 0) {
+ emitir(IRTGI(IR_EQ), trstart, tr0);
+ trstart = tr0;
+ } else {
+ trstart = emitir(IRTI(IR_ADD), trstart, lj_ir_kint(J, -1));
+ emitir(IRTGI(IR_GE), trstart, tr0);
+ start--;
+ }
+ }
+ if (rd->data) { /* Return string.sub result. */
+ if (end - start >= 0) {
+ /* Also handle empty range here, to avoid extra traces. */
+ TRef trptr, trslen = emitir(IRTI(IR_SUB), trend, trstart);
+ emitir(IRTGI(IR_GE), trslen, tr0);
+ trptr = emitir(IRT(IR_STRREF, IRT_P32), trstr, trstart);
+ J->base[0] = emitir(IRT(IR_SNEW, IRT_STR), trptr, trslen);
+ } else { /* Range underflow: return empty string. */
+ emitir(IRTGI(IR_LT), trend, trstart);
+ J->base[0] = lj_ir_kstr(J, lj_str_new(J->L, strdata(str), 0));
+ }
+ } else { /* Return string.byte result(s). */
+ ptrdiff_t i, len = end - start;
+ if (len > 0) {
+ TRef trslen = emitir(IRTI(IR_SUB), trend, trstart);
+ emitir(IRTGI(IR_EQ), trslen, lj_ir_kint(J, (int32_t)len));
+ if (J->baseslot + len > LJ_MAX_JSLOTS)
+ lj_trace_err_info(J, LJ_TRERR_STACKOV);
+ rd->nres = len;
+ for (i = 0; i < len; i++) {
+ TRef tmp = emitir(IRTI(IR_ADD), trstart, lj_ir_kint(J, (int32_t)i));
+ tmp = emitir(IRT(IR_STRREF, IRT_P32), trstr, tmp);
+ J->base[i] = emitir(IRT(IR_XLOAD, IRT_U8), tmp, IRXLOAD_READONLY);
+ }
+ } else { /* Empty range or range underflow: return no results. */
+ emitir(IRTGI(IR_LE), trend, trstart);
+ rd->nres = 0;
+ }
+ }
+}
+
+/* -- Table library fast functions ---------------------------------------- */
+
+static void LJ_FASTCALL recff_table_getn(jit_State *J, RecordFFData *rd)
+{
+ if (tref_istab(J->base[0]))
+ J->base[0] = lj_ir_call(J, IRCALL_lj_tab_len, J->base[0]);
+ /* else: Interpreter will throw. */
+ UNUSED(rd);
+}
+
+static void LJ_FASTCALL recff_table_remove(jit_State *J, RecordFFData *rd)
+{
+ TRef tab = J->base[0];
+ rd->nres = 0;
+ if (tref_istab(tab)) {
+ if (tref_isnil(J->base[1])) { /* Simple pop: t[#t] = nil */
+ TRef trlen = lj_ir_call(J, IRCALL_lj_tab_len, tab);
+ GCtab *t = tabV(&rd->argv[0]);
+ MSize len = lj_tab_len(t);
+ emitir(IRTGI(len ? IR_NE : IR_EQ), trlen, lj_ir_kint(J, 0));
+ if (len) {
+ RecordIndex ix;
+ ix.tab = tab;
+ ix.key = trlen;
+ settabV(J->L, &ix.tabv, t);
+ setintV(&ix.keyv, len);
+ ix.idxchain = 0;
+ if (results_wanted(J) != 0) { /* Specialize load only if needed. */
+ ix.val = 0;
+ J->base[0] = lj_record_idx(J, &ix); /* Load previous value. */
+ rd->nres = 1;
+ /* Assumes ix.key/ix.tab is not modified for raw lj_record_idx(). */
+ }
+ ix.val = TREF_NIL;
+ lj_record_idx(J, &ix); /* Remove value. */
+ }
+ } else { /* Complex case: remove in the middle. */
+ recff_nyiu(J);
+ }
+ } /* else: Interpreter will throw. */
+}
+
+static void LJ_FASTCALL recff_table_insert(jit_State *J, RecordFFData *rd)
+{
+ RecordIndex ix;
+ ix.tab = J->base[0];
+ ix.val = J->base[1];
+ rd->nres = 0;
+ if (tref_istab(ix.tab) && ix.val) {
+ if (!J->base[2]) { /* Simple push: t[#t+1] = v */
+ TRef trlen = lj_ir_call(J, IRCALL_lj_tab_len, ix.tab);
+ GCtab *t = tabV(&rd->argv[0]);
+ ix.key = emitir(IRTI(IR_ADD), trlen, lj_ir_kint(J, 1));
+ settabV(J->L, &ix.tabv, t);
+ setintV(&ix.keyv, lj_tab_len(t) + 1);
+ ix.idxchain = 0;
+ lj_record_idx(J, &ix); /* Set new value. */
+ } else { /* Complex case: insert in the middle. */
+ recff_nyiu(J);
+ }
+ } /* else: Interpreter will throw. */
+}
+
+/* -- I/O library fast functions ------------------------------------------ */
+
+/* Get FILE* for I/O function. Any I/O error aborts recording, so there's
+** no need to encode the alternate cases for any of the guards.
+*/
+static TRef recff_io_fp(jit_State *J, TRef *udp, int32_t id)
+{
+ TRef tr, ud, fp;
+ if (id) { /* io.func() */
+ tr = lj_ir_kptr(J, &J2G(J)->gcroot[id]);
+ ud = emitir(IRT(IR_XLOAD, IRT_UDATA), tr, 0);
+ } else { /* fp:method() */
+ ud = J->base[0];
+ if (!tref_isudata(ud))
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ tr = emitir(IRT(IR_FLOAD, IRT_U8), ud, IRFL_UDATA_UDTYPE);
+ emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, UDTYPE_IO_FILE));
+ }
+ *udp = ud;
+ fp = emitir(IRT(IR_FLOAD, IRT_PTR), ud, IRFL_UDATA_FILE);
+ emitir(IRTG(IR_NE, IRT_PTR), fp, lj_ir_knull(J, IRT_PTR));
+ return fp;
+}
+
+static void LJ_FASTCALL recff_io_write(jit_State *J, RecordFFData *rd)
+{
+ TRef ud, fp = recff_io_fp(J, &ud, rd->data);
+ TRef zero = lj_ir_kint(J, 0);
+ TRef one = lj_ir_kint(J, 1);
+ ptrdiff_t i = rd->data == 0 ? 1 : 0;
+ for (; J->base[i]; i++) {
+ TRef str = lj_ir_tostr(J, J->base[i]);
+ TRef buf = emitir(IRT(IR_STRREF, IRT_P32), str, zero);
+ TRef len = emitir(IRTI(IR_FLOAD), str, IRFL_STR_LEN);
+ if (tref_isk(len) && IR(tref_ref(len))->i == 1) {
+ TRef tr = emitir(IRT(IR_XLOAD, IRT_U8), buf, IRXLOAD_READONLY);
+ tr = lj_ir_call(J, IRCALL_fputc, tr, fp);
+ if (results_wanted(J) != 0) /* Check result only if not ignored. */
+ emitir(IRTGI(IR_NE), tr, lj_ir_kint(J, -1));
+ } else {
+ TRef tr = lj_ir_call(J, IRCALL_fwrite, buf, one, len, fp);
+ if (results_wanted(J) != 0) /* Check result only if not ignored. */
+ emitir(IRTGI(IR_EQ), tr, len);
+ }
+ }
+ J->base[0] = LJ_52 ? ud : TREF_TRUE;
+}
+
+static void LJ_FASTCALL recff_io_flush(jit_State *J, RecordFFData *rd)
+{
+ TRef ud, fp = recff_io_fp(J, &ud, rd->data);
+ TRef tr = lj_ir_call(J, IRCALL_fflush, fp);
+ if (results_wanted(J) != 0) /* Check result only if not ignored. */
+ emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, 0));
+ J->base[0] = TREF_TRUE;
+}
+
+/* -- Record calls to fast functions -------------------------------------- */
+
+#include "lj_recdef.h"
+
+static uint32_t recdef_lookup(GCfunc *fn)
+{
+ if (fn->c.ffid < sizeof(recff_idmap)/sizeof(recff_idmap[0]))
+ return recff_idmap[fn->c.ffid];
+ else
+ return 0;
+}
+
+/* Record entry to a fast function or C function. */
+void lj_ffrecord_func(jit_State *J)
+{
+ RecordFFData rd;
+ uint32_t m = recdef_lookup(J->fn);
+ rd.data = m & 0xff;
+ rd.nres = 1; /* Default is one result. */
+ rd.argv = J->L->base;
+ J->base[J->maxslot] = 0; /* Mark end of arguments. */
+ (recff_func[m >> 8])(J, &rd); /* Call recff_* handler. */
+ if (rd.nres >= 0) {
+ if (J->postproc == LJ_POST_NONE) J->postproc = LJ_POST_FFRETRY;
+ lj_record_ret(J, 0, rd.nres);
+ }
+}
+
+#undef IR
+#undef emitir
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_ffrecord.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_ffrecord.h
new file mode 100644
index 0000000..3b40745
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_ffrecord.h
@@ -0,0 +1,24 @@
+/*
+** Fast function call recorder.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_FFRECORD_H
+#define _LJ_FFRECORD_H
+
+#include "lj_obj.h"
+#include "lj_jit.h"
+
+#if LJ_HASJIT
+/* Data used by handlers to record a fast function. */
+typedef struct RecordFFData {
+ TValue *argv; /* Runtime argument values. */
+ ptrdiff_t nres; /* Number of returned results (defaults to 1). */
+ uint32_t data; /* Per-ffid auxiliary data (opcode, literal etc.). */
+} RecordFFData;
+
+LJ_FUNC int32_t lj_ffrecord_select_mode(jit_State *J, TRef tr, TValue *tv);
+LJ_FUNC void lj_ffrecord_func(jit_State *J);
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_frame.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_frame.h
new file mode 100644
index 0000000..eb5df30
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_frame.h
@@ -0,0 +1,187 @@
+/*
+** Stack frames.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_FRAME_H
+#define _LJ_FRAME_H
+
+#include "lj_obj.h"
+#include "lj_bc.h"
+
+/* -- Lua stack frame ----------------------------------------------------- */
+
+/* Frame type markers in callee function slot (callee base-1). */
+enum {
+ FRAME_LUA, FRAME_C, FRAME_CONT, FRAME_VARG,
+ FRAME_LUAP, FRAME_CP, FRAME_PCALL, FRAME_PCALLH
+};
+#define FRAME_TYPE 3
+#define FRAME_P 4
+#define FRAME_TYPEP (FRAME_TYPE|FRAME_P)
+
+/* Macros to access and modify Lua frames. */
+#define frame_gc(f) (gcref((f)->fr.func))
+#define frame_func(f) (&frame_gc(f)->fn)
+#define frame_ftsz(f) ((f)->fr.tp.ftsz)
+
+#define frame_type(f) (frame_ftsz(f) & FRAME_TYPE)
+#define frame_typep(f) (frame_ftsz(f) & FRAME_TYPEP)
+#define frame_islua(f) (frame_type(f) == FRAME_LUA)
+#define frame_isc(f) (frame_type(f) == FRAME_C)
+#define frame_iscont(f) (frame_typep(f) == FRAME_CONT)
+#define frame_isvarg(f) (frame_typep(f) == FRAME_VARG)
+#define frame_ispcall(f) ((frame_ftsz(f) & 6) == FRAME_PCALL)
+
+#define frame_pc(f) (mref((f)->fr.tp.pcr, const BCIns))
+#define frame_contpc(f) (frame_pc((f)-1))
+#if LJ_64
+#define frame_contf(f) \
+ ((ASMFunction)(void *)((intptr_t)lj_vm_asm_begin + \
+ (intptr_t)(int32_t)((f)-1)->u32.lo))
+#else
+#define frame_contf(f) ((ASMFunction)gcrefp(((f)-1)->gcr, void))
+#endif
+#define frame_delta(f) (frame_ftsz(f) >> 3)
+#define frame_sized(f) (frame_ftsz(f) & ~FRAME_TYPEP)
+
+#define frame_prevl(f) ((f) - (1+bc_a(frame_pc(f)[-1])))
+#define frame_prevd(f) ((TValue *)((char *)(f) - frame_sized(f)))
+#define frame_prev(f) (frame_islua(f)?frame_prevl(f):frame_prevd(f))
+/* Note: this macro does not skip over FRAME_VARG. */
+
+#define setframe_pc(f, pc) (setmref((f)->fr.tp.pcr, (pc)))
+#define setframe_ftsz(f, sz) ((f)->fr.tp.ftsz = (sz))
+#define setframe_gc(f, p) (setgcref((f)->fr.func, (p)))
+
+/* -- C stack frame ------------------------------------------------------- */
+
+/* Macros to access and modify the C stack frame chain. */
+
+/* These definitions must match with the arch-specific *.dasc files. */
+#if LJ_TARGET_X86
+#define CFRAME_OFS_ERRF (15*4)
+#define CFRAME_OFS_NRES (14*4)
+#define CFRAME_OFS_PREV (13*4)
+#define CFRAME_OFS_L (12*4)
+#define CFRAME_OFS_PC (6*4)
+#define CFRAME_OFS_MULTRES (5*4)
+#define CFRAME_SIZE (12*4)
+#define CFRAME_SHIFT_MULTRES 0
+#elif LJ_TARGET_X64
+#if LJ_ABI_WIN
+#define CFRAME_OFS_PREV (13*8)
+#define CFRAME_OFS_PC (25*4)
+#define CFRAME_OFS_L (24*4)
+#define CFRAME_OFS_ERRF (23*4)
+#define CFRAME_OFS_NRES (22*4)
+#define CFRAME_OFS_MULTRES (21*4)
+#define CFRAME_SIZE (10*8)
+#define CFRAME_SIZE_JIT (CFRAME_SIZE + 9*16 + 4*8)
+#define CFRAME_SHIFT_MULTRES 0
+#else
+#define CFRAME_OFS_PREV (4*8)
+#define CFRAME_OFS_PC (7*4)
+#define CFRAME_OFS_L (6*4)
+#define CFRAME_OFS_ERRF (5*4)
+#define CFRAME_OFS_NRES (4*4)
+#define CFRAME_OFS_MULTRES (1*4)
+#if LJ_NO_UNWIND
+#define CFRAME_SIZE (12*8)
+#else
+#define CFRAME_SIZE (10*8)
+#endif
+#define CFRAME_SIZE_JIT (CFRAME_SIZE + 16)
+#define CFRAME_SHIFT_MULTRES 0
+#endif
+#elif LJ_TARGET_ARM
+#define CFRAME_OFS_ERRF 24
+#define CFRAME_OFS_NRES 20
+#define CFRAME_OFS_PREV 16
+#define CFRAME_OFS_L 12
+#define CFRAME_OFS_PC 8
+#define CFRAME_OFS_MULTRES 4
+#if LJ_ARCH_HASFPU
+#define CFRAME_SIZE 128
+#else
+#define CFRAME_SIZE 64
+#endif
+#define CFRAME_SHIFT_MULTRES 3
+#elif LJ_TARGET_PPC
+#if LJ_TARGET_XBOX360
+#define CFRAME_OFS_ERRF 424
+#define CFRAME_OFS_NRES 420
+#define CFRAME_OFS_PREV 400
+#define CFRAME_OFS_L 416
+#define CFRAME_OFS_PC 412
+#define CFRAME_OFS_MULTRES 408
+#define CFRAME_SIZE 384
+#define CFRAME_SHIFT_MULTRES 3
+#elif LJ_ARCH_PPC64
+#define CFRAME_OFS_ERRF 472
+#define CFRAME_OFS_NRES 468
+#define CFRAME_OFS_PREV 448
+#define CFRAME_OFS_L 464
+#define CFRAME_OFS_PC 460
+#define CFRAME_OFS_MULTRES 456
+#define CFRAME_SIZE 400
+#define CFRAME_SHIFT_MULTRES 3
+#else
+#define CFRAME_OFS_ERRF 48
+#define CFRAME_OFS_NRES 44
+#define CFRAME_OFS_PREV 40
+#define CFRAME_OFS_L 36
+#define CFRAME_OFS_PC 32
+#define CFRAME_OFS_MULTRES 28
+#define CFRAME_SIZE 272
+#define CFRAME_SHIFT_MULTRES 3
+#endif
+#elif LJ_TARGET_PPCSPE
+#define CFRAME_OFS_ERRF 28
+#define CFRAME_OFS_NRES 24
+#define CFRAME_OFS_PREV 20
+#define CFRAME_OFS_L 16
+#define CFRAME_OFS_PC 12
+#define CFRAME_OFS_MULTRES 8
+#define CFRAME_SIZE 184
+#define CFRAME_SHIFT_MULTRES 3
+#elif LJ_TARGET_MIPS
+#define CFRAME_OFS_ERRF 124
+#define CFRAME_OFS_NRES 120
+#define CFRAME_OFS_PREV 116
+#define CFRAME_OFS_L 112
+#define CFRAME_OFS_PC 20
+#define CFRAME_OFS_MULTRES 16
+#define CFRAME_SIZE 112
+#define CFRAME_SHIFT_MULTRES 3
+#else
+#error "Missing CFRAME_* definitions for this architecture"
+#endif
+
+#ifndef CFRAME_SIZE_JIT
+#define CFRAME_SIZE_JIT CFRAME_SIZE
+#endif
+
+#define CFRAME_RESUME 1
+#define CFRAME_UNWIND_FF 2 /* Only used in unwinder. */
+#define CFRAME_RAWMASK (~(intptr_t)(CFRAME_RESUME|CFRAME_UNWIND_FF))
+
+#define cframe_errfunc(cf) (*(int32_t *)(((char *)(cf))+CFRAME_OFS_ERRF))
+#define cframe_nres(cf) (*(int32_t *)(((char *)(cf))+CFRAME_OFS_NRES))
+#define cframe_prev(cf) (*(void **)(((char *)(cf))+CFRAME_OFS_PREV))
+#define cframe_multres(cf) (*(uint32_t *)(((char *)(cf))+CFRAME_OFS_MULTRES))
+#define cframe_multres_n(cf) (cframe_multres((cf)) >> CFRAME_SHIFT_MULTRES)
+#define cframe_L(cf) \
+ (&gcref(*(GCRef *)(((char *)(cf))+CFRAME_OFS_L))->th)
+#define cframe_pc(cf) \
+ (mref(*(MRef *)(((char *)(cf))+CFRAME_OFS_PC), const BCIns))
+#define setcframe_L(cf, L) \
+ (setmref(*(MRef *)(((char *)(cf))+CFRAME_OFS_L), (L)))
+#define setcframe_pc(cf, pc) \
+ (setmref(*(MRef *)(((char *)(cf))+CFRAME_OFS_PC), (pc)))
+#define cframe_canyield(cf) ((intptr_t)(cf) & CFRAME_RESUME)
+#define cframe_unwind_ff(cf) ((intptr_t)(cf) & CFRAME_UNWIND_FF)
+#define cframe_raw(cf) ((void *)((intptr_t)(cf) & CFRAME_RAWMASK))
+#define cframe_Lpc(L) cframe_pc(cframe_raw(L->cframe))
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_func.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_func.c
new file mode 100644
index 0000000..639dad8
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_func.c
@@ -0,0 +1,187 @@
+/*
+** Function handling (prototypes, functions and upvalues).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#define lj_func_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_func.h"
+#include "lj_trace.h"
+#include "lj_vm.h"
+
+/* -- Prototypes ---------------------------------------------------------- */
+
+void LJ_FASTCALL lj_func_freeproto(global_State *g, GCproto *pt)
+{
+ lj_mem_free(g, pt, pt->sizept);
+}
+
+/* -- Upvalues ------------------------------------------------------------ */
+
+static void unlinkuv(GCupval *uv)
+{
+ lua_assert(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv);
+ setgcrefr(uvnext(uv)->prev, uv->prev);
+ setgcrefr(uvprev(uv)->next, uv->next);
+}
+
+/* Find existing open upvalue for a stack slot or create a new one. */
+static GCupval *func_finduv(lua_State *L, TValue *slot)
+{
+ global_State *g = G(L);
+ GCRef *pp = &L->openupval;
+ GCupval *p;
+ GCupval *uv;
+ /* Search the sorted list of open upvalues. */
+ while (gcref(*pp) != NULL && uvval((p = gco2uv(gcref(*pp)))) >= slot) {
+ lua_assert(!p->closed && uvval(p) != &p->tv);
+ if (uvval(p) == slot) { /* Found open upvalue pointing to same slot? */
+ if (isdead(g, obj2gco(p))) /* Resurrect it, if it's dead. */
+ flipwhite(obj2gco(p));
+ return p;
+ }
+ pp = &p->nextgc;
+ }
+ /* No matching upvalue found. Create a new one. */
+ uv = lj_mem_newt(L, sizeof(GCupval), GCupval);
+ newwhite(g, uv);
+ uv->gct = ~LJ_TUPVAL;
+ uv->closed = 0; /* Still open. */
+ setmref(uv->v, slot); /* Pointing to the stack slot. */
+ /* NOBARRIER: The GCupval is new (marked white) and open. */
+ setgcrefr(uv->nextgc, *pp); /* Insert into sorted list of open upvalues. */
+ setgcref(*pp, obj2gco(uv));
+ setgcref(uv->prev, obj2gco(&g->uvhead)); /* Insert into GC list, too. */
+ setgcrefr(uv->next, g->uvhead.next);
+ setgcref(uvnext(uv)->prev, obj2gco(uv));
+ setgcref(g->uvhead.next, obj2gco(uv));
+ lua_assert(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv);
+ return uv;
+}
+
+/* Create an empty and closed upvalue. */
+static GCupval *func_emptyuv(lua_State *L)
+{
+ GCupval *uv = (GCupval *)lj_mem_newgco(L, sizeof(GCupval));
+ uv->gct = ~LJ_TUPVAL;
+ uv->closed = 1;
+ setnilV(&uv->tv);
+ setmref(uv->v, &uv->tv);
+ return uv;
+}
+
+/* Close all open upvalues pointing to some stack level or above. */
+void LJ_FASTCALL lj_func_closeuv(lua_State *L, TValue *level)
+{
+ GCupval *uv;
+ global_State *g = G(L);
+ while (gcref(L->openupval) != NULL &&
+ uvval((uv = gco2uv(gcref(L->openupval)))) >= level) {
+ GCobj *o = obj2gco(uv);
+ lua_assert(!isblack(o) && !uv->closed && uvval(uv) != &uv->tv);
+ setgcrefr(L->openupval, uv->nextgc); /* No longer in open list. */
+ if (isdead(g, o)) {
+ lj_func_freeuv(g, uv);
+ } else {
+ unlinkuv(uv);
+ lj_gc_closeuv(g, uv);
+ }
+ }
+}
+
+void LJ_FASTCALL lj_func_freeuv(global_State *g, GCupval *uv)
+{
+ if (!uv->closed)
+ unlinkuv(uv);
+ lj_mem_freet(g, uv);
+}
+
+/* -- Functions (closures) ------------------------------------------------ */
+
+GCfunc *lj_func_newC(lua_State *L, MSize nelems, GCtab *env)
+{
+ GCfunc *fn = (GCfunc *)lj_mem_newgco(L, sizeCfunc(nelems));
+ fn->c.gct = ~LJ_TFUNC;
+ fn->c.ffid = FF_C;
+ fn->c.nupvalues = (uint8_t)nelems;
+ /* NOBARRIER: The GCfunc is new (marked white). */
+ setmref(fn->c.pc, &G(L)->bc_cfunc_ext);
+ setgcref(fn->c.env, obj2gco(env));
+ return fn;
+}
+
+static GCfunc *func_newL(lua_State *L, GCproto *pt, GCtab *env)
+{
+ uint32_t count;
+ GCfunc *fn = (GCfunc *)lj_mem_newgco(L, sizeLfunc((MSize)pt->sizeuv));
+ fn->l.gct = ~LJ_TFUNC;
+ fn->l.ffid = FF_LUA;
+ fn->l.nupvalues = 0; /* Set to zero until upvalues are initialized. */
+ /* NOBARRIER: Really a setgcref. But the GCfunc is new (marked white). */
+ setmref(fn->l.pc, proto_bc(pt));
+ setgcref(fn->l.env, obj2gco(env));
+ /* Saturating 3 bit counter (0..7) for created closures. */
+ count = (uint32_t)pt->flags + PROTO_CLCOUNT;
+ pt->flags = (uint8_t)(count - ((count >> PROTO_CLC_BITS) & PROTO_CLCOUNT));
+ return fn;
+}
+
+/* Create a new Lua function with empty upvalues. */
+GCfunc *lj_func_newL_empty(lua_State *L, GCproto *pt, GCtab *env)
+{
+ GCfunc *fn = func_newL(L, pt, env);
+ MSize i, nuv = pt->sizeuv;
+ /* NOBARRIER: The GCfunc is new (marked white). */
+ for (i = 0; i < nuv; i++) {
+ GCupval *uv = func_emptyuv(L);
+ int32_t v = proto_uv(pt)[i];
+ uv->immutable = ((v / PROTO_UV_IMMUTABLE) & 1);
+ uv->dhash = (uint32_t)(uintptr_t)pt ^ (v << 24);
+ setgcref(fn->l.uvptr[i], obj2gco(uv));
+ }
+ fn->l.nupvalues = (uint8_t)nuv;
+ return fn;
+}
+
+/* Do a GC check and create a new Lua function with inherited upvalues. */
+GCfunc *lj_func_newL_gc(lua_State *L, GCproto *pt, GCfuncL *parent)
+{
+ GCfunc *fn;
+ GCRef *puv;
+ MSize i, nuv;
+ TValue *base;
+ lj_gc_check_fixtop(L);
+ fn = func_newL(L, pt, tabref(parent->env));
+ /* NOBARRIER: The GCfunc is new (marked white). */
+ puv = parent->uvptr;
+ nuv = pt->sizeuv;
+ base = L->base;
+ for (i = 0; i < nuv; i++) {
+ uint32_t v = proto_uv(pt)[i];
+ GCupval *uv;
+ if ((v & PROTO_UV_LOCAL)) {
+ uv = func_finduv(L, base + (v & 0xff));
+ uv->immutable = ((v / PROTO_UV_IMMUTABLE) & 1);
+ uv->dhash = (uint32_t)(uintptr_t)mref(parent->pc, char) ^ (v << 24);
+ } else {
+ uv = &gcref(puv[v])->uv;
+ }
+ setgcref(fn->l.uvptr[i], obj2gco(uv));
+ }
+ fn->l.nupvalues = (uint8_t)nuv;
+ return fn;
+}
+
+void LJ_FASTCALL lj_func_free(global_State *g, GCfunc *fn)
+{
+ MSize size = isluafunc(fn) ? sizeLfunc((MSize)fn->l.nupvalues) :
+ sizeCfunc((MSize)fn->c.nupvalues);
+ lj_mem_free(g, fn, size);
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_func.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_func.h
new file mode 100644
index 0000000..901751b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_func.h
@@ -0,0 +1,24 @@
+/*
+** Function handling (prototypes, functions and upvalues).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_FUNC_H
+#define _LJ_FUNC_H
+
+#include "lj_obj.h"
+
+/* Prototypes. */
+LJ_FUNC void LJ_FASTCALL lj_func_freeproto(global_State *g, GCproto *pt);
+
+/* Upvalues. */
+LJ_FUNCA void LJ_FASTCALL lj_func_closeuv(lua_State *L, TValue *level);
+LJ_FUNC void LJ_FASTCALL lj_func_freeuv(global_State *g, GCupval *uv);
+
+/* Functions (closures). */
+LJ_FUNC GCfunc *lj_func_newC(lua_State *L, MSize nelems, GCtab *env);
+LJ_FUNC GCfunc *lj_func_newL_empty(lua_State *L, GCproto *pt, GCtab *env);
+LJ_FUNCA GCfunc *lj_func_newL_gc(lua_State *L, GCproto *pt, GCfuncL *parent);
+LJ_FUNC void LJ_FASTCALL lj_func_free(global_State *g, GCfunc *c);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_gc.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_gc.c
new file mode 100644
index 0000000..a5d32ea
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_gc.c
@@ -0,0 +1,856 @@
+/*
+** Garbage collector.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Major portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#define lj_gc_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_func.h"
+#include "lj_udata.h"
+#include "lj_meta.h"
+#include "lj_state.h"
+#include "lj_frame.h"
+#if LJ_HASFFI
+#include "lj_ctype.h"
+#include "lj_cdata.h"
+#endif
+#include "lj_trace.h"
+#include "lj_vm.h"
+
+#define GCSTEPSIZE 1024u
+#define GCSWEEPMAX 40
+#define GCSWEEPCOST 10
+#define GCFINALIZECOST 100
+
+/* Macros to set GCobj colors and flags. */
+#define white2gray(x) ((x)->gch.marked &= (uint8_t)~LJ_GC_WHITES)
+#define gray2black(x) ((x)->gch.marked |= LJ_GC_BLACK)
+#define isfinalized(u) ((u)->marked & LJ_GC_FINALIZED)
+
+/* -- Mark phase ---------------------------------------------------------- */
+
+/* Mark a TValue (if needed). */
+#define gc_marktv(g, tv) \
+ { lua_assert(!tvisgcv(tv) || (~itype(tv) == gcval(tv)->gch.gct)); \
+ if (tviswhite(tv)) gc_mark(g, gcV(tv)); }
+
+/* Mark a GCobj (if needed). */
+#define gc_markobj(g, o) \
+ { if (iswhite(obj2gco(o))) gc_mark(g, obj2gco(o)); }
+
+/* Mark a string object. */
+#define gc_mark_str(s) ((s)->marked &= (uint8_t)~LJ_GC_WHITES)
+
+/* Mark a white GCobj. */
+static void gc_mark(global_State *g, GCobj *o)
+{
+ int gct = o->gch.gct;
+ lua_assert(iswhite(o) && !isdead(g, o));
+ white2gray(o);
+ if (LJ_UNLIKELY(gct == ~LJ_TUDATA)) {
+ GCtab *mt = tabref(gco2ud(o)->metatable);
+ gray2black(o); /* Userdata are never gray. */
+ if (mt) gc_markobj(g, mt);
+ gc_markobj(g, tabref(gco2ud(o)->env));
+ } else if (LJ_UNLIKELY(gct == ~LJ_TUPVAL)) {
+ GCupval *uv = gco2uv(o);
+ gc_marktv(g, uvval(uv));
+ if (uv->closed)
+ gray2black(o); /* Closed upvalues are never gray. */
+ } else if (gct != ~LJ_TSTR && gct != ~LJ_TCDATA) {
+ lua_assert(gct == ~LJ_TFUNC || gct == ~LJ_TTAB ||
+ gct == ~LJ_TTHREAD || gct == ~LJ_TPROTO);
+ setgcrefr(o->gch.gclist, g->gc.gray);
+ setgcref(g->gc.gray, o);
+ }
+}
+
+/* Mark GC roots. */
+static void gc_mark_gcroot(global_State *g)
+{
+ ptrdiff_t i;
+ for (i = 0; i < GCROOT_MAX; i++)
+ if (gcref(g->gcroot[i]) != NULL)
+ gc_markobj(g, gcref(g->gcroot[i]));
+}
+
+/* Start a GC cycle and mark the root set. */
+static void gc_mark_start(global_State *g)
+{
+ setgcrefnull(g->gc.gray);
+ setgcrefnull(g->gc.grayagain);
+ setgcrefnull(g->gc.weak);
+ gc_markobj(g, mainthread(g));
+ gc_markobj(g, tabref(mainthread(g)->env));
+ gc_marktv(g, &g->registrytv);
+ gc_mark_gcroot(g);
+ g->gc.state = GCSpropagate;
+}
+
+/* Mark open upvalues. */
+static void gc_mark_uv(global_State *g)
+{
+ GCupval *uv;
+ for (uv = uvnext(&g->uvhead); uv != &g->uvhead; uv = uvnext(uv)) {
+ lua_assert(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv);
+ if (isgray(obj2gco(uv)))
+ gc_marktv(g, uvval(uv));
+ }
+}
+
+/* Mark userdata in mmudata list. */
+static void gc_mark_mmudata(global_State *g)
+{
+ GCobj *root = gcref(g->gc.mmudata);
+ GCobj *u = root;
+ if (u) {
+ do {
+ u = gcnext(u);
+ makewhite(g, u); /* Could be from previous GC. */
+ gc_mark(g, u);
+ } while (u != root);
+ }
+}
+
+/* Separate userdata objects to be finalized to mmudata list. */
+size_t lj_gc_separateudata(global_State *g, int all)
+{
+ size_t m = 0;
+ GCRef *p = &mainthread(g)->nextgc;
+ GCobj *o;
+ while ((o = gcref(*p)) != NULL) {
+ if (!(iswhite(o) || all) || isfinalized(gco2ud(o))) {
+ p = &o->gch.nextgc; /* Nothing to do. */
+ } else if (!lj_meta_fastg(g, tabref(gco2ud(o)->metatable), MM_gc)) {
+ markfinalized(o); /* Done, as there's no __gc metamethod. */
+ p = &o->gch.nextgc;
+ } else { /* Otherwise move userdata to be finalized to mmudata list. */
+ m += sizeudata(gco2ud(o));
+ markfinalized(o);
+ *p = o->gch.nextgc;
+ if (gcref(g->gc.mmudata)) { /* Link to end of mmudata list. */
+ GCobj *root = gcref(g->gc.mmudata);
+ setgcrefr(o->gch.nextgc, root->gch.nextgc);
+ setgcref(root->gch.nextgc, o);
+ setgcref(g->gc.mmudata, o);
+ } else { /* Create circular list. */
+ setgcref(o->gch.nextgc, o);
+ setgcref(g->gc.mmudata, o);
+ }
+ }
+ }
+ return m;
+}
+
+/* -- Propagation phase --------------------------------------------------- */
+
+/* Traverse a table. */
+static int gc_traverse_tab(global_State *g, GCtab *t)
+{
+ int weak = 0;
+ cTValue *mode;
+ GCtab *mt = tabref(t->metatable);
+ if (mt)
+ gc_markobj(g, mt);
+ mode = lj_meta_fastg(g, mt, MM_mode);
+ if (mode && tvisstr(mode)) { /* Valid __mode field? */
+ const char *modestr = strVdata(mode);
+ int c;
+ while ((c = *modestr++)) {
+ if (c == 'k') weak |= LJ_GC_WEAKKEY;
+ else if (c == 'v') weak |= LJ_GC_WEAKVAL;
+ }
+ if (weak) { /* Weak tables are cleared in the atomic phase. */
+#if LJ_HASFFI
+ CTState *cts = ctype_ctsG(g);
+ if (cts && cts->finalizer == t) {
+ weak = (int)(~0u & ~LJ_GC_WEAKVAL);
+ } else
+#endif
+ {
+ t->marked = (uint8_t)((t->marked & ~LJ_GC_WEAK) | weak);
+ setgcrefr(t->gclist, g->gc.weak);
+ setgcref(g->gc.weak, obj2gco(t));
+ }
+ }
+ }
+ if (weak == LJ_GC_WEAK) /* Nothing to mark if both keys/values are weak. */
+ return 1;
+ if (!(weak & LJ_GC_WEAKVAL)) { /* Mark array part. */
+ MSize i, asize = t->asize;
+ for (i = 0; i < asize; i++)
+ gc_marktv(g, arrayslot(t, i));
+ }
+ if (t->hmask > 0) { /* Mark hash part. */
+ Node *node = noderef(t->node);
+ MSize i, hmask = t->hmask;
+ for (i = 0; i <= hmask; i++) {
+ Node *n = &node[i];
+ if (!tvisnil(&n->val)) { /* Mark non-empty slot. */
+ lua_assert(!tvisnil(&n->key));
+ if (!(weak & LJ_GC_WEAKKEY)) gc_marktv(g, &n->key);
+ if (!(weak & LJ_GC_WEAKVAL)) gc_marktv(g, &n->val);
+ }
+ }
+ }
+ return weak;
+}
+
+/* Traverse a function. */
+static void gc_traverse_func(global_State *g, GCfunc *fn)
+{
+ gc_markobj(g, tabref(fn->c.env));
+ if (isluafunc(fn)) {
+ uint32_t i;
+ lua_assert(fn->l.nupvalues <= funcproto(fn)->sizeuv);
+ gc_markobj(g, funcproto(fn));
+ for (i = 0; i < fn->l.nupvalues; i++) /* Mark Lua function upvalues. */
+ gc_markobj(g, &gcref(fn->l.uvptr[i])->uv);
+ } else {
+ uint32_t i;
+ for (i = 0; i < fn->c.nupvalues; i++) /* Mark C function upvalues. */
+ gc_marktv(g, &fn->c.upvalue[i]);
+ }
+}
+
+#if LJ_HASJIT
+/* Mark a trace. */
+static void gc_marktrace(global_State *g, TraceNo traceno)
+{
+ GCobj *o = obj2gco(traceref(G2J(g), traceno));
+ lua_assert(traceno != G2J(g)->cur.traceno);
+ if (iswhite(o)) {
+ white2gray(o);
+ setgcrefr(o->gch.gclist, g->gc.gray);
+ setgcref(g->gc.gray, o);
+ }
+}
+
+/* Traverse a trace. */
+static void gc_traverse_trace(global_State *g, GCtrace *T)
+{
+ IRRef ref;
+ if (T->traceno == 0) return;
+ for (ref = T->nk; ref < REF_TRUE; ref++) {
+ IRIns *ir = &T->ir[ref];
+ if (ir->o == IR_KGC)
+ gc_markobj(g, ir_kgc(ir));
+ }
+ if (T->link) gc_marktrace(g, T->link);
+ if (T->nextroot) gc_marktrace(g, T->nextroot);
+ if (T->nextside) gc_marktrace(g, T->nextside);
+ gc_markobj(g, gcref(T->startpt));
+}
+
+/* The current trace is a GC root while not anchored in the prototype (yet). */
+#define gc_traverse_curtrace(g) gc_traverse_trace(g, &G2J(g)->cur)
+#else
+#define gc_traverse_curtrace(g) UNUSED(g)
+#endif
+
+/* Traverse a prototype. */
+static void gc_traverse_proto(global_State *g, GCproto *pt)
+{
+ ptrdiff_t i;
+ gc_mark_str(proto_chunkname(pt));
+ for (i = -(ptrdiff_t)pt->sizekgc; i < 0; i++) /* Mark collectable consts. */
+ gc_markobj(g, proto_kgc(pt, i));
+#if LJ_HASJIT
+ if (pt->trace) gc_marktrace(g, pt->trace);
+#endif
+}
+
+/* Traverse the frame structure of a stack. */
+static MSize gc_traverse_frames(global_State *g, lua_State *th)
+{
+ TValue *frame, *top = th->top-1, *bot = tvref(th->stack);
+ /* Note: extra vararg frame not skipped, marks function twice (harmless). */
+ for (frame = th->base-1; frame > bot; frame = frame_prev(frame)) {
+ GCfunc *fn = frame_func(frame);
+ TValue *ftop = frame;
+ if (isluafunc(fn)) ftop += funcproto(fn)->framesize;
+ if (ftop > top) top = ftop;
+ gc_markobj(g, fn); /* Need to mark hidden function (or L). */
+ }
+ top++; /* Correct bias of -1 (frame == base-1). */
+ if (top > tvref(th->maxstack)) top = tvref(th->maxstack);
+ return (MSize)(top - bot); /* Return minimum needed stack size. */
+}
+
+/* Traverse a thread object. */
+static void gc_traverse_thread(global_State *g, lua_State *th)
+{
+ TValue *o, *top = th->top;
+ for (o = tvref(th->stack)+1; o < top; o++)
+ gc_marktv(g, o);
+ if (g->gc.state == GCSatomic) {
+ top = tvref(th->stack) + th->stacksize;
+ for (; o < top; o++) /* Clear unmarked slots. */
+ setnilV(o);
+ }
+ gc_markobj(g, tabref(th->env));
+ lj_state_shrinkstack(th, gc_traverse_frames(g, th));
+}
+
+/* Propagate one gray object. Traverse it and turn it black. */
+static size_t propagatemark(global_State *g)
+{
+ GCobj *o = gcref(g->gc.gray);
+ int gct = o->gch.gct;
+ lua_assert(isgray(o));
+ gray2black(o);
+ setgcrefr(g->gc.gray, o->gch.gclist); /* Remove from gray list. */
+ if (LJ_LIKELY(gct == ~LJ_TTAB)) {
+ GCtab *t = gco2tab(o);
+ if (gc_traverse_tab(g, t) > 0)
+ black2gray(o); /* Keep weak tables gray. */
+ return sizeof(GCtab) + sizeof(TValue) * t->asize +
+ (t->hmask ? sizeof(Node) * (t->hmask + 1) : 0);
+ } else if (LJ_LIKELY(gct == ~LJ_TFUNC)) {
+ GCfunc *fn = gco2func(o);
+ gc_traverse_func(g, fn);
+ return isluafunc(fn) ? sizeLfunc((MSize)fn->l.nupvalues) :
+ sizeCfunc((MSize)fn->c.nupvalues);
+ } else if (LJ_LIKELY(gct == ~LJ_TPROTO)) {
+ GCproto *pt = gco2pt(o);
+ gc_traverse_proto(g, pt);
+ return pt->sizept;
+ } else if (LJ_LIKELY(gct == ~LJ_TTHREAD)) {
+ lua_State *th = gco2th(o);
+ setgcrefr(th->gclist, g->gc.grayagain);
+ setgcref(g->gc.grayagain, o);
+ black2gray(o); /* Threads are never black. */
+ gc_traverse_thread(g, th);
+ return sizeof(lua_State) + sizeof(TValue) * th->stacksize;
+ } else {
+#if LJ_HASJIT
+ GCtrace *T = gco2trace(o);
+ gc_traverse_trace(g, T);
+ return ((sizeof(GCtrace)+7)&~7) + (T->nins-T->nk)*sizeof(IRIns) +
+ T->nsnap*sizeof(SnapShot) + T->nsnapmap*sizeof(SnapEntry);
+#else
+ lua_assert(0);
+ return 0;
+#endif
+ }
+}
+
+/* Propagate all gray objects. */
+static size_t gc_propagate_gray(global_State *g)
+{
+ size_t m = 0;
+ while (gcref(g->gc.gray) != NULL)
+ m += propagatemark(g);
+ return m;
+}
+
+/* -- Sweep phase --------------------------------------------------------- */
+
+/* Try to shrink some common data structures. */
+static void gc_shrink(global_State *g, lua_State *L)
+{
+ if (g->strnum <= (g->strmask >> 2) && g->strmask > LJ_MIN_STRTAB*2-1)
+ lj_str_resize(L, g->strmask >> 1); /* Shrink string table. */
+ if (g->tmpbuf.sz > LJ_MIN_SBUF*2)
+ lj_str_resizebuf(L, &g->tmpbuf, g->tmpbuf.sz >> 1); /* Shrink temp buf. */
+}
+
+/* Type of GC free functions. */
+typedef void (LJ_FASTCALL *GCFreeFunc)(global_State *g, GCobj *o);
+
+/* GC free functions for LJ_TSTR .. LJ_TUDATA. ORDER LJ_T */
+static const GCFreeFunc gc_freefunc[] = {
+ (GCFreeFunc)lj_str_free,
+ (GCFreeFunc)lj_func_freeuv,
+ (GCFreeFunc)lj_state_free,
+ (GCFreeFunc)lj_func_freeproto,
+ (GCFreeFunc)lj_func_free,
+#if LJ_HASJIT
+ (GCFreeFunc)lj_trace_free,
+#else
+ (GCFreeFunc)0,
+#endif
+#if LJ_HASFFI
+ (GCFreeFunc)lj_cdata_free,
+#else
+ (GCFreeFunc)0,
+#endif
+ (GCFreeFunc)lj_tab_free,
+ (GCFreeFunc)lj_udata_free
+};
+
+/* Full sweep of a GC list. */
+#define gc_fullsweep(g, p) gc_sweep(g, (p), LJ_MAX_MEM)
+
+/* Partial sweep of a GC list. */
+static GCRef *gc_sweep(global_State *g, GCRef *p, uint32_t lim)
+{
+ /* Mask with other white and LJ_GC_FIXED. Or LJ_GC_SFIXED on shutdown. */
+ int ow = otherwhite(g);
+ GCobj *o;
+ while ((o = gcref(*p)) != NULL && lim-- > 0) {
+ if (o->gch.gct == ~LJ_TTHREAD) /* Need to sweep open upvalues, too. */
+ gc_fullsweep(g, &gco2th(o)->openupval);
+ if (((o->gch.marked ^ LJ_GC_WHITES) & ow)) { /* Black or current white? */
+ lua_assert(!isdead(g, o) || (o->gch.marked & LJ_GC_FIXED));
+ makewhite(g, o); /* Value is alive, change to the current white. */
+ p = &o->gch.nextgc;
+ } else { /* Otherwise value is dead, free it. */
+ lua_assert(isdead(g, o) || ow == LJ_GC_SFIXED);
+ setgcrefr(*p, o->gch.nextgc);
+ if (o == gcref(g->gc.root))
+ setgcrefr(g->gc.root, o->gch.nextgc); /* Adjust list anchor. */
+ gc_freefunc[o->gch.gct - ~LJ_TSTR](g, o);
+ }
+ }
+ return p;
+}
+
+/* Check whether we can clear a key or a value slot from a table. */
+static int gc_mayclear(cTValue *o, int val)
+{
+ if (tvisgcv(o)) { /* Only collectable objects can be weak references. */
+ if (tvisstr(o)) { /* But strings cannot be used as weak references. */
+ gc_mark_str(strV(o)); /* And need to be marked. */
+ return 0;
+ }
+ if (iswhite(gcV(o)))
+ return 1; /* Object is about to be collected. */
+ if (tvisudata(o) && val && isfinalized(udataV(o)))
+ return 1; /* Finalized userdata is dropped only from values. */
+ }
+ return 0; /* Cannot clear. */
+}
+
+/* Clear collected entries from weak tables. */
+static void gc_clearweak(GCobj *o)
+{
+ while (o) {
+ GCtab *t = gco2tab(o);
+ lua_assert((t->marked & LJ_GC_WEAK));
+ if ((t->marked & LJ_GC_WEAKVAL)) {
+ MSize i, asize = t->asize;
+ for (i = 0; i < asize; i++) {
+ /* Clear array slot when value is about to be collected. */
+ TValue *tv = arrayslot(t, i);
+ if (gc_mayclear(tv, 1))
+ setnilV(tv);
+ }
+ }
+ if (t->hmask > 0) {
+ Node *node = noderef(t->node);
+ MSize i, hmask = t->hmask;
+ for (i = 0; i <= hmask; i++) {
+ Node *n = &node[i];
+ /* Clear hash slot when key or value is about to be collected. */
+ if (!tvisnil(&n->val) && (gc_mayclear(&n->key, 0) ||
+ gc_mayclear(&n->val, 1)))
+ setnilV(&n->val);
+ }
+ }
+ o = gcref(t->gclist);
+ }
+}
+
+/* Call a userdata or cdata finalizer. */
+static void gc_call_finalizer(global_State *g, lua_State *L,
+ cTValue *mo, GCobj *o)
+{
+ /* Save and restore lots of state around the __gc callback. */
+ uint8_t oldh = hook_save(g);
+ MSize oldt = g->gc.threshold;
+ int errcode;
+ TValue *top;
+ lj_trace_abort(g);
+ top = L->top;
+ L->top = top+2;
+ hook_entergc(g); /* Disable hooks and new traces during __gc. */
+ g->gc.threshold = LJ_MAX_MEM; /* Prevent GC steps. */
+ copyTV(L, top, mo);
+ setgcV(L, top+1, o, ~o->gch.gct);
+ errcode = lj_vm_pcall(L, top+1, 1+0, -1); /* Stack: |mo|o| -> | */
+ hook_restore(g, oldh);
+ g->gc.threshold = oldt; /* Restore GC threshold. */
+ if (errcode)
+ lj_err_throw(L, errcode); /* Propagate errors. */
+}
+
+/* Finalize one userdata or cdata object from the mmudata list. */
+static void gc_finalize(lua_State *L)
+{
+ global_State *g = G(L);
+ GCobj *o = gcnext(gcref(g->gc.mmudata));
+ cTValue *mo;
+ lua_assert(gcref(g->jit_L) == NULL); /* Must not be called on trace. */
+ /* Unchain from list of userdata to be finalized. */
+ if (o == gcref(g->gc.mmudata))
+ setgcrefnull(g->gc.mmudata);
+ else
+ setgcrefr(gcref(g->gc.mmudata)->gch.nextgc, o->gch.nextgc);
+#if LJ_HASFFI
+ if (o->gch.gct == ~LJ_TCDATA) {
+ TValue tmp, *tv;
+ /* Add cdata back to the GC list and make it white. */
+ setgcrefr(o->gch.nextgc, g->gc.root);
+ setgcref(g->gc.root, o);
+ makewhite(g, o);
+ o->gch.marked &= (uint8_t)~LJ_GC_CDATA_FIN;
+ /* Resolve finalizer. */
+ setcdataV(L, &tmp, gco2cd(o));
+ tv = lj_tab_set(L, ctype_ctsG(g)->finalizer, &tmp);
+ if (!tvisnil(tv)) {
+ g->gc.nocdatafin = 0;
+ copyTV(L, &tmp, tv);
+ setnilV(tv); /* Clear entry in finalizer table. */
+ gc_call_finalizer(g, L, &tmp, o);
+ }
+ return;
+ }
+#endif
+ /* Add userdata back to the main userdata list and make it white. */
+ setgcrefr(o->gch.nextgc, mainthread(g)->nextgc);
+ setgcref(mainthread(g)->nextgc, o);
+ makewhite(g, o);
+ /* Resolve the __gc metamethod. */
+ mo = lj_meta_fastg(g, tabref(gco2ud(o)->metatable), MM_gc);
+ if (mo)
+ gc_call_finalizer(g, L, mo, o);
+}
+
+/* Finalize all userdata objects from mmudata list. */
+void lj_gc_finalize_udata(lua_State *L)
+{
+ while (gcref(G(L)->gc.mmudata) != NULL)
+ gc_finalize(L);
+}
+
+#if LJ_HASFFI
+/* Finalize all cdata objects from finalizer table. */
+void lj_gc_finalize_cdata(lua_State *L)
+{
+ global_State *g = G(L);
+ CTState *cts = ctype_ctsG(g);
+ if (cts) {
+ GCtab *t = cts->finalizer;
+ Node *node = noderef(t->node);
+ ptrdiff_t i;
+ setgcrefnull(t->metatable); /* Mark finalizer table as disabled. */
+ for (i = (ptrdiff_t)t->hmask; i >= 0; i--)
+ if (!tvisnil(&node[i].val) && tviscdata(&node[i].key)) {
+ GCobj *o = gcV(&node[i].key);
+ TValue tmp;
+ makewhite(g, o);
+ o->gch.marked &= (uint8_t)~LJ_GC_CDATA_FIN;
+ copyTV(L, &tmp, &node[i].val);
+ setnilV(&node[i].val);
+ gc_call_finalizer(g, L, &tmp, o);
+ }
+ }
+}
+#endif
+
+/* Free all remaining GC objects. */
+void lj_gc_freeall(global_State *g)
+{
+ MSize i, strmask;
+ /* Free everything, except super-fixed objects (the main thread). */
+ g->gc.currentwhite = LJ_GC_WHITES | LJ_GC_SFIXED;
+ gc_fullsweep(g, &g->gc.root);
+ strmask = g->strmask;
+ for (i = 0; i <= strmask; i++) /* Free all string hash chains. */
+ gc_fullsweep(g, &g->strhash[i]);
+}
+
+/* -- Collector ----------------------------------------------------------- */
+
+/* Atomic part of the GC cycle, transitioning from mark to sweep phase. */
+static void atomic(global_State *g, lua_State *L)
+{
+ size_t udsize;
+
+ gc_mark_uv(g); /* Need to remark open upvalues (the thread may be dead). */
+ gc_propagate_gray(g); /* Propagate any left-overs. */
+
+ setgcrefr(g->gc.gray, g->gc.weak); /* Empty the list of weak tables. */
+ setgcrefnull(g->gc.weak);
+ lua_assert(!iswhite(obj2gco(mainthread(g))));
+ gc_markobj(g, L); /* Mark running thread. */
+ gc_traverse_curtrace(g); /* Traverse current trace. */
+ gc_mark_gcroot(g); /* Mark GC roots (again). */
+ gc_propagate_gray(g); /* Propagate all of the above. */
+
+ setgcrefr(g->gc.gray, g->gc.grayagain); /* Empty the 2nd chance list. */
+ setgcrefnull(g->gc.grayagain);
+ gc_propagate_gray(g); /* Propagate it. */
+
+ udsize = lj_gc_separateudata(g, 0); /* Separate userdata to be finalized. */
+ gc_mark_mmudata(g); /* Mark them. */
+ udsize += gc_propagate_gray(g); /* And propagate the marks. */
+
+ /* All marking done, clear weak tables. */
+ gc_clearweak(gcref(g->gc.weak));
+
+ /* Prepare for sweep phase. */
+ g->gc.currentwhite = (uint8_t)otherwhite(g); /* Flip current white. */
+ g->strempty.marked = g->gc.currentwhite;
+ setmref(g->gc.sweep, &g->gc.root);
+ g->gc.estimate = g->gc.total - (MSize)udsize; /* Initial estimate. */
+}
+
+/* GC state machine. Returns a cost estimate for each step performed. */
+static size_t gc_onestep(lua_State *L)
+{
+ global_State *g = G(L);
+ switch (g->gc.state) {
+ case GCSpause:
+ gc_mark_start(g); /* Start a new GC cycle by marking all GC roots. */
+ return 0;
+ case GCSpropagate:
+ if (gcref(g->gc.gray) != NULL)
+ return propagatemark(g); /* Propagate one gray object. */
+ g->gc.state = GCSatomic; /* End of mark phase. */
+ return 0;
+ case GCSatomic:
+ if (gcref(g->jit_L)) /* Don't run atomic phase on trace. */
+ return LJ_MAX_MEM;
+ atomic(g, L);
+ g->gc.state = GCSsweepstring; /* Start of sweep phase. */
+ g->gc.sweepstr = 0;
+ return 0;
+ case GCSsweepstring: {
+ MSize old = g->gc.total;
+ gc_fullsweep(g, &g->strhash[g->gc.sweepstr++]); /* Sweep one chain. */
+ if (g->gc.sweepstr > g->strmask)
+ g->gc.state = GCSsweep; /* All string hash chains sweeped. */
+ lua_assert(old >= g->gc.total);
+ g->gc.estimate -= old - g->gc.total;
+ return GCSWEEPCOST;
+ }
+ case GCSsweep: {
+ MSize old = g->gc.total;
+ setmref(g->gc.sweep, gc_sweep(g, mref(g->gc.sweep, GCRef), GCSWEEPMAX));
+ lua_assert(old >= g->gc.total);
+ g->gc.estimate -= old - g->gc.total;
+ if (gcref(*mref(g->gc.sweep, GCRef)) == NULL) {
+ gc_shrink(g, L);
+ if (gcref(g->gc.mmudata)) { /* Need any finalizations? */
+ g->gc.state = GCSfinalize;
+#if LJ_HASFFI
+ g->gc.nocdatafin = 1;
+#endif
+ } else { /* Otherwise skip this phase to help the JIT. */
+ g->gc.state = GCSpause; /* End of GC cycle. */
+ g->gc.debt = 0;
+ }
+ }
+ return GCSWEEPMAX*GCSWEEPCOST;
+ }
+ case GCSfinalize:
+ if (gcref(g->gc.mmudata) != NULL) {
+ if (gcref(g->jit_L)) /* Don't call finalizers on trace. */
+ return LJ_MAX_MEM;
+ gc_finalize(L); /* Finalize one userdata object. */
+ if (g->gc.estimate > GCFINALIZECOST)
+ g->gc.estimate -= GCFINALIZECOST;
+ return GCFINALIZECOST;
+ }
+#if LJ_HASFFI
+ if (!g->gc.nocdatafin) lj_tab_rehash(L, ctype_ctsG(g)->finalizer);
+#endif
+ g->gc.state = GCSpause; /* End of GC cycle. */
+ g->gc.debt = 0;
+ return 0;
+ default:
+ lua_assert(0);
+ return 0;
+ }
+}
+
+/* Perform a limited amount of incremental GC steps. */
+int LJ_FASTCALL lj_gc_step(lua_State *L)
+{
+ global_State *g = G(L);
+ MSize lim;
+ int32_t ostate = g->vmstate;
+ setvmstate(g, GC);
+ lim = (GCSTEPSIZE/100) * g->gc.stepmul;
+ if (lim == 0)
+ lim = LJ_MAX_MEM;
+ if (g->gc.total > g->gc.threshold)
+ g->gc.debt += g->gc.total - g->gc.threshold;
+ do {
+ lim -= (MSize)gc_onestep(L);
+ if (g->gc.state == GCSpause) {
+ g->gc.threshold = (g->gc.estimate/100) * g->gc.pause;
+ g->vmstate = ostate;
+ return 1; /* Finished a GC cycle. */
+ }
+ } while ((int32_t)lim > 0);
+ if (g->gc.debt < GCSTEPSIZE) {
+ g->gc.threshold = g->gc.total + GCSTEPSIZE;
+ g->vmstate = ostate;
+ return -1;
+ } else {
+ g->gc.debt -= GCSTEPSIZE;
+ g->gc.threshold = g->gc.total;
+ g->vmstate = ostate;
+ return 0;
+ }
+}
+
+/* Ditto, but fix the stack top first. */
+void LJ_FASTCALL lj_gc_step_fixtop(lua_State *L)
+{
+ if (curr_funcisL(L)) L->top = curr_topL(L);
+ lj_gc_step(L);
+}
+
+#if LJ_HASJIT
+/* Perform multiple GC steps. Called from JIT-compiled code. */
+int LJ_FASTCALL lj_gc_step_jit(global_State *g, MSize steps)
+{
+ lua_State *L = gco2th(gcref(g->jit_L));
+ L->base = mref(G(L)->jit_base, TValue);
+ L->top = curr_topL(L);
+ while (steps-- > 0 && lj_gc_step(L) == 0)
+ ;
+ /* Return 1 to force a trace exit. */
+ return (G(L)->gc.state == GCSatomic || G(L)->gc.state == GCSfinalize);
+}
+#endif
+
+/* Perform a full GC cycle. */
+void lj_gc_fullgc(lua_State *L)
+{
+ global_State *g = G(L);
+ int32_t ostate = g->vmstate;
+ setvmstate(g, GC);
+ if (g->gc.state <= GCSatomic) { /* Caught somewhere in the middle. */
+ setmref(g->gc.sweep, &g->gc.root); /* Sweep everything (preserving it). */
+ setgcrefnull(g->gc.gray); /* Reset lists from partial propagation. */
+ setgcrefnull(g->gc.grayagain);
+ setgcrefnull(g->gc.weak);
+ g->gc.state = GCSsweepstring; /* Fast forward to the sweep phase. */
+ g->gc.sweepstr = 0;
+ }
+ while (g->gc.state == GCSsweepstring || g->gc.state == GCSsweep)
+ gc_onestep(L); /* Finish sweep. */
+ lua_assert(g->gc.state == GCSfinalize || g->gc.state == GCSpause);
+ /* Now perform a full GC. */
+ g->gc.state = GCSpause;
+ do { gc_onestep(L); } while (g->gc.state != GCSpause);
+ g->gc.threshold = (g->gc.estimate/100) * g->gc.pause;
+ g->vmstate = ostate;
+}
+
+/* -- Write barriers ------------------------------------------------------ */
+
+/* Move the GC propagation frontier forward. */
+void lj_gc_barrierf(global_State *g, GCobj *o, GCobj *v)
+{
+ lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
+ lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause);
+ lua_assert(o->gch.gct != ~LJ_TTAB);
+ /* Preserve invariant during propagation. Otherwise it doesn't matter. */
+ if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic)
+ gc_mark(g, v); /* Move frontier forward. */
+ else
+ makewhite(g, o); /* Make it white to avoid the following barrier. */
+}
+
+/* Specialized barrier for closed upvalue. Pass &uv->tv. */
+void LJ_FASTCALL lj_gc_barrieruv(global_State *g, TValue *tv)
+{
+#define TV2MARKED(x) \
+ (*((uint8_t *)(x) - offsetof(GCupval, tv) + offsetof(GCupval, marked)))
+ if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic)
+ gc_mark(g, gcV(tv));
+ else
+ TV2MARKED(tv) = (TV2MARKED(tv) & (uint8_t)~LJ_GC_COLORS) | curwhite(g);
+#undef TV2MARKED
+}
+
+/* Close upvalue. Also needs a write barrier. */
+void lj_gc_closeuv(global_State *g, GCupval *uv)
+{
+ GCobj *o = obj2gco(uv);
+ /* Copy stack slot to upvalue itself and point to the copy. */
+ copyTV(mainthread(g), &uv->tv, uvval(uv));
+ setmref(uv->v, &uv->tv);
+ uv->closed = 1;
+ setgcrefr(o->gch.nextgc, g->gc.root);
+ setgcref(g->gc.root, o);
+ if (isgray(o)) { /* A closed upvalue is never gray, so fix this. */
+ if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic) {
+ gray2black(o); /* Make it black and preserve invariant. */
+ if (tviswhite(&uv->tv))
+ lj_gc_barrierf(g, o, gcV(&uv->tv));
+ } else {
+ makewhite(g, o); /* Make it white, i.e. sweep the upvalue. */
+ lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause);
+ }
+ }
+}
+
+#if LJ_HASJIT
+/* Mark a trace if it's saved during the propagation phase. */
+void lj_gc_barriertrace(global_State *g, uint32_t traceno)
+{
+ if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic)
+ gc_marktrace(g, traceno);
+}
+#endif
+
+/* -- Allocator ----------------------------------------------------------- */
+
+/* Call pluggable memory allocator to allocate or resize a fragment. */
+void *lj_mem_realloc(lua_State *L, void *p, MSize osz, MSize nsz)
+{
+ global_State *g = G(L);
+ lua_assert((osz == 0) == (p == NULL));
+ p = g->allocf(g->allocd, p, osz, nsz);
+ if (p == NULL && nsz > 0)
+ lj_err_mem(L);
+ lua_assert((nsz == 0) == (p == NULL));
+ lua_assert(checkptr32(p));
+ g->gc.total = (g->gc.total - osz) + nsz;
+ return p;
+}
+
+/* Allocate new GC object and link it to the root set. */
+void * LJ_FASTCALL lj_mem_newgco(lua_State *L, MSize size)
+{
+ global_State *g = G(L);
+ GCobj *o = (GCobj *)g->allocf(g->allocd, NULL, 0, size);
+ if (o == NULL)
+ lj_err_mem(L);
+ lua_assert(checkptr32(o));
+ g->gc.total += size;
+ setgcrefr(o->gch.nextgc, g->gc.root);
+ setgcref(g->gc.root, o);
+ newwhite(g, o);
+ return o;
+}
+
+/* Resize growable vector. */
+void *lj_mem_grow(lua_State *L, void *p, MSize *szp, MSize lim, MSize esz)
+{
+ MSize sz = (*szp) << 1;
+ if (sz < LJ_MIN_VECSZ)
+ sz = LJ_MIN_VECSZ;
+ if (sz > lim)
+ sz = lim;
+ p = lj_mem_realloc(L, p, (*szp)*esz, sz*esz);
+ *szp = sz;
+ return p;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_gc.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_gc.h
new file mode 100644
index 0000000..57ac714
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_gc.h
@@ -0,0 +1,134 @@
+/*
+** Garbage collector.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_GC_H
+#define _LJ_GC_H
+
+#include "lj_obj.h"
+
+/* Garbage collector states. Order matters. */
+enum {
+ GCSpause, GCSpropagate, GCSatomic, GCSsweepstring, GCSsweep, GCSfinalize
+};
+
+/* Bitmasks for marked field of GCobj. */
+#define LJ_GC_WHITE0 0x01
+#define LJ_GC_WHITE1 0x02
+#define LJ_GC_BLACK 0x04
+#define LJ_GC_FINALIZED 0x08
+#define LJ_GC_WEAKKEY 0x08
+#define LJ_GC_WEAKVAL 0x10
+#define LJ_GC_CDATA_FIN 0x10
+#define LJ_GC_FIXED 0x20
+#define LJ_GC_SFIXED 0x40
+
+#define LJ_GC_WHITES (LJ_GC_WHITE0 | LJ_GC_WHITE1)
+#define LJ_GC_COLORS (LJ_GC_WHITES | LJ_GC_BLACK)
+#define LJ_GC_WEAK (LJ_GC_WEAKKEY | LJ_GC_WEAKVAL)
+
+/* Macros to test and set GCobj colors. */
+#define iswhite(x) ((x)->gch.marked & LJ_GC_WHITES)
+#define isblack(x) ((x)->gch.marked & LJ_GC_BLACK)
+#define isgray(x) (!((x)->gch.marked & (LJ_GC_BLACK|LJ_GC_WHITES)))
+#define tviswhite(x) (tvisgcv(x) && iswhite(gcV(x)))
+#define otherwhite(g) (g->gc.currentwhite ^ LJ_GC_WHITES)
+#define isdead(g, v) ((v)->gch.marked & otherwhite(g) & LJ_GC_WHITES)
+
+#define curwhite(g) ((g)->gc.currentwhite & LJ_GC_WHITES)
+#define newwhite(g, x) (obj2gco(x)->gch.marked = (uint8_t)curwhite(g))
+#define makewhite(g, x) \
+ ((x)->gch.marked = ((x)->gch.marked & (uint8_t)~LJ_GC_COLORS) | curwhite(g))
+#define flipwhite(x) ((x)->gch.marked ^= LJ_GC_WHITES)
+#define black2gray(x) ((x)->gch.marked &= (uint8_t)~LJ_GC_BLACK)
+#define fixstring(s) ((s)->marked |= LJ_GC_FIXED)
+#define markfinalized(x) ((x)->gch.marked |= LJ_GC_FINALIZED)
+
+/* Collector. */
+LJ_FUNC size_t lj_gc_separateudata(global_State *g, int all);
+LJ_FUNC void lj_gc_finalize_udata(lua_State *L);
+#if LJ_HASFFI
+LJ_FUNC void lj_gc_finalize_cdata(lua_State *L);
+#else
+#define lj_gc_finalize_cdata(L) UNUSED(L)
+#endif
+LJ_FUNC void lj_gc_freeall(global_State *g);
+LJ_FUNCA int LJ_FASTCALL lj_gc_step(lua_State *L);
+LJ_FUNCA void LJ_FASTCALL lj_gc_step_fixtop(lua_State *L);
+#if LJ_HASJIT
+LJ_FUNC int LJ_FASTCALL lj_gc_step_jit(global_State *g, MSize steps);
+#endif
+LJ_FUNC void lj_gc_fullgc(lua_State *L);
+
+/* GC check: drive collector forward if the GC threshold has been reached. */
+#define lj_gc_check(L) \
+ { if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) \
+ lj_gc_step(L); }
+#define lj_gc_check_fixtop(L) \
+ { if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) \
+ lj_gc_step_fixtop(L); }
+
+/* Write barriers. */
+LJ_FUNC void lj_gc_barrierf(global_State *g, GCobj *o, GCobj *v);
+LJ_FUNCA void LJ_FASTCALL lj_gc_barrieruv(global_State *g, TValue *tv);
+LJ_FUNC void lj_gc_closeuv(global_State *g, GCupval *uv);
+#if LJ_HASJIT
+LJ_FUNC void lj_gc_barriertrace(global_State *g, uint32_t traceno);
+#endif
+
+/* Move the GC propagation frontier back for tables (make it gray again). */
+static LJ_AINLINE void lj_gc_barrierback(global_State *g, GCtab *t)
+{
+ GCobj *o = obj2gco(t);
+ lua_assert(isblack(o) && !isdead(g, o));
+ lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause);
+ black2gray(o);
+ setgcrefr(t->gclist, g->gc.grayagain);
+ setgcref(g->gc.grayagain, o);
+}
+
+/* Barrier for stores to table objects. TValue and GCobj variant. */
+#define lj_gc_anybarriert(L, t) \
+ { if (LJ_UNLIKELY(isblack(obj2gco(t)))) lj_gc_barrierback(G(L), (t)); }
+#define lj_gc_barriert(L, t, tv) \
+ { if (tviswhite(tv) && isblack(obj2gco(t))) \
+ lj_gc_barrierback(G(L), (t)); }
+#define lj_gc_objbarriert(L, t, o) \
+ { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) \
+ lj_gc_barrierback(G(L), (t)); }
+
+/* Barrier for stores to any other object. TValue and GCobj variant. */
+#define lj_gc_barrier(L, p, tv) \
+ { if (tviswhite(tv) && isblack(obj2gco(p))) \
+ lj_gc_barrierf(G(L), obj2gco(p), gcV(tv)); }
+#define lj_gc_objbarrier(L, p, o) \
+ { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
+ lj_gc_barrierf(G(L), obj2gco(p), obj2gco(o)); }
+
+/* Allocator. */
+LJ_FUNC void *lj_mem_realloc(lua_State *L, void *p, MSize osz, MSize nsz);
+LJ_FUNC void * LJ_FASTCALL lj_mem_newgco(lua_State *L, MSize size);
+LJ_FUNC void *lj_mem_grow(lua_State *L, void *p,
+ MSize *szp, MSize lim, MSize esz);
+
+#define lj_mem_new(L, s) lj_mem_realloc(L, NULL, 0, (s))
+
+static LJ_AINLINE void lj_mem_free(global_State *g, void *p, size_t osize)
+{
+ g->gc.total -= (MSize)osize;
+ g->allocf(g->allocd, p, osize, 0);
+}
+
+#define lj_mem_newvec(L, n, t) ((t *)lj_mem_new(L, (MSize)((n)*sizeof(t))))
+#define lj_mem_reallocvec(L, p, on, n, t) \
+ ((p) = (t *)lj_mem_realloc(L, p, (on)*sizeof(t), (MSize)((n)*sizeof(t))))
+#define lj_mem_growvec(L, p, n, m, t) \
+ ((p) = (t *)lj_mem_grow(L, (p), &(n), (m), (MSize)sizeof(t)))
+#define lj_mem_freevec(g, p, n, t) lj_mem_free(g, (p), (n)*sizeof(t))
+
+#define lj_mem_newobj(L, t) ((t *)lj_mem_newgco(L, sizeof(t)))
+#define lj_mem_newt(L, s, t) ((t *)lj_mem_new(L, (s)))
+#define lj_mem_freet(g, p) lj_mem_free(g, (p), sizeof(*(p)))
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_gdbjit.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_gdbjit.c
new file mode 100644
index 0000000..eeb017b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_gdbjit.c
@@ -0,0 +1,795 @@
+/*
+** Client for the GDB JIT API.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_gdbjit_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT
+
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_debug.h"
+#include "lj_frame.h"
+#include "lj_jit.h"
+#include "lj_dispatch.h"
+
+/* This is not compiled in by default.
+** Enable with -DLUAJIT_USE_GDBJIT in the Makefile and recompile everything.
+*/
+#ifdef LUAJIT_USE_GDBJIT
+
+/* The GDB JIT API allows JIT compilers to pass debug information about
+** JIT-compiled code back to GDB. You need at least GDB 7.0 or higher
+** to see it in action.
+**
+** This is a passive API, so it works even when not running under GDB
+** or when attaching to an already running process. Alas, this implies
+** enabling it always has a non-negligible overhead -- do not use in
+** release mode!
+**
+** The LuaJIT GDB JIT client is rather minimal at the moment. It gives
+** each trace a symbol name and adds a source location and frame unwind
+** information. Obviously LuaJIT itself and any embedding C application
+** should be compiled with debug symbols, too (see the Makefile).
+**
+** Traces are named TRACE_1, TRACE_2, ... these correspond to the trace
+** numbers from -jv or -jdump. Use "break TRACE_1" or "tbreak TRACE_1" etc.
+** to set breakpoints on specific traces (even ahead of their creation).
+**
+** The source location for each trace allows listing the corresponding
+** source lines with the GDB command "list" (but only if the Lua source
+** has been loaded from a file). Currently this is always set to the
+** location where the trace has been started.
+**
+** Frame unwind information can be inspected with the GDB command
+** "info frame". This also allows proper backtraces across JIT-compiled
+** code with the GDB command "bt".
+**
+** You probably want to add the following settings to a .gdbinit file
+** (or add them to ~/.gdbinit):
+** set disassembly-flavor intel
+** set breakpoint pending on
+**
+** Here's a sample GDB session:
+** ------------------------------------------------------------------------
+
+$ cat >x.lua
+for outer=1,100 do
+ for inner=1,100 do end
+end
+^D
+
+$ luajit -jv x.lua
+[TRACE 1 x.lua:2]
+[TRACE 2 (1/3) x.lua:1 -> 1]
+
+$ gdb --quiet --args luajit x.lua
+(gdb) tbreak TRACE_1
+Function "TRACE_1" not defined.
+Temporary breakpoint 1 (TRACE_1) pending.
+(gdb) run
+Starting program: luajit x.lua
+
+Temporary breakpoint 1, TRACE_1 () at x.lua:2
+2 for inner=1,100 do end
+(gdb) list
+1 for outer=1,100 do
+2 for inner=1,100 do end
+3 end
+(gdb) bt
+#0 TRACE_1 () at x.lua:2
+#1 0x08053690 in lua_pcall [...]
+[...]
+#7 0x0806ff90 in main [...]
+(gdb) disass TRACE_1
+Dump of assembler code for function TRACE_1:
+0xf7fd9fba <TRACE_1+0>: mov DWORD PTR ds:0xf7e0e2a0,0x1
+0xf7fd9fc4 <TRACE_1+10>: movsd xmm7,QWORD PTR [edx+0x20]
+[...]
+0xf7fd9ff8 <TRACE_1+62>: jmp 0xf7fd2014
+End of assembler dump.
+(gdb) tbreak TRACE_2
+Function "TRACE_2" not defined.
+Temporary breakpoint 2 (TRACE_2) pending.
+(gdb) cont
+Continuing.
+
+Temporary breakpoint 2, TRACE_2 () at x.lua:1
+1 for outer=1,100 do
+(gdb) info frame
+Stack level 0, frame at 0xffffd7c0:
+ eip = 0xf7fd9f60 in TRACE_2 (x.lua:1); saved eip 0x8053690
+ called by frame at 0xffffd7e0
+ source language unknown.
+ Arglist at 0xffffd78c, args:
+ Locals at 0xffffd78c, Previous frame's sp is 0xffffd7c0
+ Saved registers:
+ ebx at 0xffffd7ac, ebp at 0xffffd7b8, esi at 0xffffd7b0, edi at 0xffffd7b4,
+ eip at 0xffffd7bc
+(gdb)
+
+** ------------------------------------------------------------------------
+*/
+
+/* -- GDB JIT API --------------------------------------------------------- */
+
+/* GDB JIT actions. */
+enum {
+ GDBJIT_NOACTION = 0,
+ GDBJIT_REGISTER,
+ GDBJIT_UNREGISTER
+};
+
+/* GDB JIT entry. */
+typedef struct GDBJITentry {
+ struct GDBJITentry *next_entry;
+ struct GDBJITentry *prev_entry;
+ const char *symfile_addr;
+ uint64_t symfile_size;
+} GDBJITentry;
+
+/* GDB JIT descriptor. */
+typedef struct GDBJITdesc {
+ uint32_t version;
+ uint32_t action_flag;
+ GDBJITentry *relevant_entry;
+ GDBJITentry *first_entry;
+} GDBJITdesc;
+
+GDBJITdesc __jit_debug_descriptor = {
+ 1, GDBJIT_NOACTION, NULL, NULL
+};
+
+/* GDB sets a breakpoint at this function. */
+void LJ_NOINLINE __jit_debug_register_code()
+{
+ __asm__ __volatile__("");
+};
+
+/* -- In-memory ELF object definitions ------------------------------------ */
+
+/* ELF definitions. */
+typedef struct ELFheader {
+ uint8_t emagic[4];
+ uint8_t eclass;
+ uint8_t eendian;
+ uint8_t eversion;
+ uint8_t eosabi;
+ uint8_t eabiversion;
+ uint8_t epad[7];
+ uint16_t type;
+ uint16_t machine;
+ uint32_t version;
+ uintptr_t entry;
+ uintptr_t phofs;
+ uintptr_t shofs;
+ uint32_t flags;
+ uint16_t ehsize;
+ uint16_t phentsize;
+ uint16_t phnum;
+ uint16_t shentsize;
+ uint16_t shnum;
+ uint16_t shstridx;
+} ELFheader;
+
+typedef struct ELFsectheader {
+ uint32_t name;
+ uint32_t type;
+ uintptr_t flags;
+ uintptr_t addr;
+ uintptr_t ofs;
+ uintptr_t size;
+ uint32_t link;
+ uint32_t info;
+ uintptr_t align;
+ uintptr_t entsize;
+} ELFsectheader;
+
+#define ELFSECT_IDX_ABS 0xfff1
+
+enum {
+ ELFSECT_TYPE_PROGBITS = 1,
+ ELFSECT_TYPE_SYMTAB = 2,
+ ELFSECT_TYPE_STRTAB = 3,
+ ELFSECT_TYPE_NOBITS = 8
+};
+
+#define ELFSECT_FLAGS_WRITE 1
+#define ELFSECT_FLAGS_ALLOC 2
+#define ELFSECT_FLAGS_EXEC 4
+
+typedef struct ELFsymbol {
+#if LJ_64
+ uint32_t name;
+ uint8_t info;
+ uint8_t other;
+ uint16_t sectidx;
+ uintptr_t value;
+ uint64_t size;
+#else
+ uint32_t name;
+ uintptr_t value;
+ uint32_t size;
+ uint8_t info;
+ uint8_t other;
+ uint16_t sectidx;
+#endif
+} ELFsymbol;
+
+enum {
+ ELFSYM_TYPE_FUNC = 2,
+ ELFSYM_TYPE_FILE = 4,
+ ELFSYM_BIND_LOCAL = 0 << 4,
+ ELFSYM_BIND_GLOBAL = 1 << 4,
+};
+
+/* DWARF definitions. */
+#define DW_CIE_VERSION 1
+
+enum {
+ DW_CFA_nop = 0x0,
+ DW_CFA_offset_extended = 0x5,
+ DW_CFA_def_cfa = 0xc,
+ DW_CFA_def_cfa_offset = 0xe,
+ DW_CFA_offset_extended_sf = 0x11,
+ DW_CFA_advance_loc = 0x40,
+ DW_CFA_offset = 0x80
+};
+
+enum {
+ DW_EH_PE_udata4 = 3,
+ DW_EH_PE_textrel = 0x20
+};
+
+enum {
+ DW_TAG_compile_unit = 0x11
+};
+
+enum {
+ DW_children_no = 0,
+ DW_children_yes = 1
+};
+
+enum {
+ DW_AT_name = 0x03,
+ DW_AT_stmt_list = 0x10,
+ DW_AT_low_pc = 0x11,
+ DW_AT_high_pc = 0x12
+};
+
+enum {
+ DW_FORM_addr = 0x01,
+ DW_FORM_data4 = 0x06,
+ DW_FORM_string = 0x08
+};
+
+enum {
+ DW_LNS_extended_op = 0,
+ DW_LNS_copy = 1,
+ DW_LNS_advance_pc = 2,
+ DW_LNS_advance_line = 3
+};
+
+enum {
+ DW_LNE_end_sequence = 1,
+ DW_LNE_set_address = 2
+};
+
+enum {
+#if LJ_TARGET_X86
+ DW_REG_AX, DW_REG_CX, DW_REG_DX, DW_REG_BX,
+ DW_REG_SP, DW_REG_BP, DW_REG_SI, DW_REG_DI,
+ DW_REG_RA,
+#elif LJ_TARGET_X64
+ /* Yes, the order is strange, but correct. */
+ DW_REG_AX, DW_REG_DX, DW_REG_CX, DW_REG_BX,
+ DW_REG_SI, DW_REG_DI, DW_REG_BP, DW_REG_SP,
+ DW_REG_8, DW_REG_9, DW_REG_10, DW_REG_11,
+ DW_REG_12, DW_REG_13, DW_REG_14, DW_REG_15,
+ DW_REG_RA,
+#elif LJ_TARGET_ARM
+ DW_REG_SP = 13,
+ DW_REG_RA = 14,
+#elif LJ_TARGET_PPC
+ DW_REG_SP = 1,
+ DW_REG_RA = 65,
+ DW_REG_CR = 70,
+#elif LJ_TARGET_MIPS
+ DW_REG_SP = 29,
+ DW_REG_RA = 31,
+#else
+#error "Unsupported target architecture"
+#endif
+};
+
+/* Minimal list of sections for the in-memory ELF object. */
+enum {
+ GDBJIT_SECT_NULL,
+ GDBJIT_SECT_text,
+ GDBJIT_SECT_eh_frame,
+ GDBJIT_SECT_shstrtab,
+ GDBJIT_SECT_strtab,
+ GDBJIT_SECT_symtab,
+ GDBJIT_SECT_debug_info,
+ GDBJIT_SECT_debug_abbrev,
+ GDBJIT_SECT_debug_line,
+ GDBJIT_SECT__MAX
+};
+
+enum {
+ GDBJIT_SYM_UNDEF,
+ GDBJIT_SYM_FILE,
+ GDBJIT_SYM_FUNC,
+ GDBJIT_SYM__MAX
+};
+
+/* In-memory ELF object. */
+typedef struct GDBJITobj {
+ ELFheader hdr; /* ELF header. */
+ ELFsectheader sect[GDBJIT_SECT__MAX]; /* ELF sections. */
+ ELFsymbol sym[GDBJIT_SYM__MAX]; /* ELF symbol table. */
+ uint8_t space[4096]; /* Space for various section data. */
+} GDBJITobj;
+
+/* Combined structure for GDB JIT entry and ELF object. */
+typedef struct GDBJITentryobj {
+ GDBJITentry entry;
+ size_t sz;
+ GDBJITobj obj;
+} GDBJITentryobj;
+
+/* Template for in-memory ELF header. */
+static const ELFheader elfhdr_template = {
+ .emagic = { 0x7f, 'E', 'L', 'F' },
+ .eclass = LJ_64 ? 2 : 1,
+ .eendian = LJ_ENDIAN_SELECT(1, 2),
+ .eversion = 1,
+#if LJ_TARGET_LINUX
+ .eosabi = 0, /* Nope, it's not 3. */
+#elif defined(__FreeBSD__)
+ .eosabi = 9,
+#elif defined(__NetBSD__)
+ .eosabi = 2,
+#elif defined(__OpenBSD__)
+ .eosabi = 12,
+#elif defined(__DragonFly__)
+ .eosabi = 0,
+#elif (defined(__sun__) && defined(__svr4__))
+ .eosabi = 6,
+#else
+ .eosabi = 0,
+#endif
+ .eabiversion = 0,
+ .epad = { 0, 0, 0, 0, 0, 0, 0 },
+ .type = 1,
+#if LJ_TARGET_X86
+ .machine = 3,
+#elif LJ_TARGET_X64
+ .machine = 62,
+#elif LJ_TARGET_ARM
+ .machine = 40,
+#elif LJ_TARGET_PPC
+ .machine = 20,
+#elif LJ_TARGET_MIPS
+ .machine = 8,
+#else
+#error "Unsupported target architecture"
+#endif
+ .version = 1,
+ .entry = 0,
+ .phofs = 0,
+ .shofs = offsetof(GDBJITobj, sect),
+ .flags = 0,
+ .ehsize = sizeof(ELFheader),
+ .phentsize = 0,
+ .phnum = 0,
+ .shentsize = sizeof(ELFsectheader),
+ .shnum = GDBJIT_SECT__MAX,
+ .shstridx = GDBJIT_SECT_shstrtab
+};
+
+/* -- In-memory ELF object generation ------------------------------------- */
+
+/* Context for generating the ELF object for the GDB JIT API. */
+typedef struct GDBJITctx {
+ uint8_t *p; /* Pointer to next address in obj.space. */
+ uint8_t *startp; /* Pointer to start address in obj.space. */
+ GCtrace *T; /* Generate symbols for this trace. */
+ uintptr_t mcaddr; /* Machine code address. */
+ MSize szmcode; /* Size of machine code. */
+ MSize spadjp; /* Stack adjustment for parent trace or interpreter. */
+ MSize spadj; /* Stack adjustment for trace itself. */
+ BCLine lineno; /* Starting line number. */
+ const char *filename; /* Starting file name. */
+ size_t objsize; /* Final size of ELF object. */
+ GDBJITobj obj; /* In-memory ELF object. */
+} GDBJITctx;
+
+/* Add a zero-terminated string. */
+static uint32_t gdbjit_strz(GDBJITctx *ctx, const char *str)
+{
+ uint8_t *p = ctx->p;
+ uint32_t ofs = (uint32_t)(p - ctx->startp);
+ do {
+ *p++ = (uint8_t)*str;
+ } while (*str++);
+ ctx->p = p;
+ return ofs;
+}
+
+/* Append a decimal number. */
+static void gdbjit_catnum(GDBJITctx *ctx, uint32_t n)
+{
+ if (n >= 10) { uint32_t m = n / 10; n = n % 10; gdbjit_catnum(ctx, m); }
+ *ctx->p++ = '0' + n;
+}
+
+/* Add a ULEB128 value. */
+static void gdbjit_uleb128(GDBJITctx *ctx, uint32_t v)
+{
+ uint8_t *p = ctx->p;
+ for (; v >= 0x80; v >>= 7)
+ *p++ = (uint8_t)((v & 0x7f) | 0x80);
+ *p++ = (uint8_t)v;
+ ctx->p = p;
+}
+
+/* Add a SLEB128 value. */
+static void gdbjit_sleb128(GDBJITctx *ctx, int32_t v)
+{
+ uint8_t *p = ctx->p;
+ for (; (uint32_t)(v+0x40) >= 0x80; v >>= 7)
+ *p++ = (uint8_t)((v & 0x7f) | 0x80);
+ *p++ = (uint8_t)(v & 0x7f);
+ ctx->p = p;
+}
+
+/* Shortcuts to generate DWARF structures. */
+#define DB(x) (*p++ = (x))
+#define DI8(x) (*(int8_t *)p = (x), p++)
+#define DU16(x) (*(uint16_t *)p = (x), p += 2)
+#define DU32(x) (*(uint32_t *)p = (x), p += 4)
+#define DADDR(x) (*(uintptr_t *)p = (x), p += sizeof(uintptr_t))
+#define DUV(x) (ctx->p = p, gdbjit_uleb128(ctx, (x)), p = ctx->p)
+#define DSV(x) (ctx->p = p, gdbjit_sleb128(ctx, (x)), p = ctx->p)
+#define DSTR(str) (ctx->p = p, gdbjit_strz(ctx, (str)), p = ctx->p)
+#define DALIGNNOP(s) while ((uintptr_t)p & ((s)-1)) *p++ = DW_CFA_nop
+#define DSECT(name, stmt) \
+ { uint32_t *szp_##name = (uint32_t *)p; p += 4; stmt \
+ *szp_##name = (uint32_t)((p-(uint8_t *)szp_##name)-4); } \
+
+/* Initialize ELF section headers. */
+static void LJ_FASTCALL gdbjit_secthdr(GDBJITctx *ctx)
+{
+ ELFsectheader *sect;
+
+ *ctx->p++ = '\0'; /* Empty string at start of string table. */
+
+#define SECTDEF(id, tp, al) \
+ sect = &ctx->obj.sect[GDBJIT_SECT_##id]; \
+ sect->name = gdbjit_strz(ctx, "." #id); \
+ sect->type = ELFSECT_TYPE_##tp; \
+ sect->align = (al)
+
+ SECTDEF(text, NOBITS, 16);
+ sect->flags = ELFSECT_FLAGS_ALLOC|ELFSECT_FLAGS_EXEC;
+ sect->addr = ctx->mcaddr;
+ sect->ofs = 0;
+ sect->size = ctx->szmcode;
+
+ SECTDEF(eh_frame, PROGBITS, sizeof(uintptr_t));
+ sect->flags = ELFSECT_FLAGS_ALLOC;
+
+ SECTDEF(shstrtab, STRTAB, 1);
+ SECTDEF(strtab, STRTAB, 1);
+
+ SECTDEF(symtab, SYMTAB, sizeof(uintptr_t));
+ sect->ofs = offsetof(GDBJITobj, sym);
+ sect->size = sizeof(ctx->obj.sym);
+ sect->link = GDBJIT_SECT_strtab;
+ sect->entsize = sizeof(ELFsymbol);
+ sect->info = GDBJIT_SYM_FUNC;
+
+ SECTDEF(debug_info, PROGBITS, 1);
+ SECTDEF(debug_abbrev, PROGBITS, 1);
+ SECTDEF(debug_line, PROGBITS, 1);
+
+#undef SECTDEF
+}
+
+/* Initialize symbol table. */
+static void LJ_FASTCALL gdbjit_symtab(GDBJITctx *ctx)
+{
+ ELFsymbol *sym;
+
+ *ctx->p++ = '\0'; /* Empty string at start of string table. */
+
+ sym = &ctx->obj.sym[GDBJIT_SYM_FILE];
+ sym->name = gdbjit_strz(ctx, "JIT mcode");
+ sym->sectidx = ELFSECT_IDX_ABS;
+ sym->info = ELFSYM_TYPE_FILE|ELFSYM_BIND_LOCAL;
+
+ sym = &ctx->obj.sym[GDBJIT_SYM_FUNC];
+ sym->name = gdbjit_strz(ctx, "TRACE_"); ctx->p--;
+ gdbjit_catnum(ctx, ctx->T->traceno); *ctx->p++ = '\0';
+ sym->sectidx = GDBJIT_SECT_text;
+ sym->value = 0;
+ sym->size = ctx->szmcode;
+ sym->info = ELFSYM_TYPE_FUNC|ELFSYM_BIND_GLOBAL;
+}
+
+/* Initialize .eh_frame section. */
+static void LJ_FASTCALL gdbjit_ehframe(GDBJITctx *ctx)
+{
+ uint8_t *p = ctx->p;
+ uint8_t *framep = p;
+
+ /* Emit DWARF EH CIE. */
+ DSECT(CIE,
+ DU32(0); /* Offset to CIE itself. */
+ DB(DW_CIE_VERSION);
+ DSTR("zR"); /* Augmentation. */
+ DUV(1); /* Code alignment factor. */
+ DSV(-(int32_t)sizeof(uintptr_t)); /* Data alignment factor. */
+ DB(DW_REG_RA); /* Return address register. */
+ DB(1); DB(DW_EH_PE_textrel|DW_EH_PE_udata4); /* Augmentation data. */
+ DB(DW_CFA_def_cfa); DUV(DW_REG_SP); DUV(sizeof(uintptr_t));
+#if LJ_TARGET_PPC
+ DB(DW_CFA_offset_extended_sf); DB(DW_REG_RA); DSV(-1);
+#else
+ DB(DW_CFA_offset|DW_REG_RA); DUV(1);
+#endif
+ DALIGNNOP(sizeof(uintptr_t));
+ )
+
+ /* Emit DWARF EH FDE. */
+ DSECT(FDE,
+ DU32((uint32_t)(p-framep)); /* Offset to CIE. */
+ DU32(0); /* Machine code offset relative to .text. */
+ DU32(ctx->szmcode); /* Machine code length. */
+ DB(0); /* Augmentation data. */
+ /* Registers saved in CFRAME. */
+#if LJ_TARGET_X86
+ DB(DW_CFA_offset|DW_REG_BP); DUV(2);
+ DB(DW_CFA_offset|DW_REG_DI); DUV(3);
+ DB(DW_CFA_offset|DW_REG_SI); DUV(4);
+ DB(DW_CFA_offset|DW_REG_BX); DUV(5);
+#elif LJ_TARGET_X64
+ DB(DW_CFA_offset|DW_REG_BP); DUV(2);
+ DB(DW_CFA_offset|DW_REG_BX); DUV(3);
+ DB(DW_CFA_offset|DW_REG_15); DUV(4);
+ DB(DW_CFA_offset|DW_REG_14); DUV(5);
+ /* Extra registers saved for JIT-compiled code. */
+ DB(DW_CFA_offset|DW_REG_13); DUV(9);
+ DB(DW_CFA_offset|DW_REG_12); DUV(10);
+#elif LJ_TARGET_ARM
+ {
+ int i;
+ for (i = 11; i >= 4; i--) { DB(DW_CFA_offset|i); DUV(2+(11-i)); }
+ }
+#elif LJ_TARGET_PPC
+ {
+ int i;
+ DB(DW_CFA_offset_extended); DB(DW_REG_CR); DUV(55);
+ for (i = 14; i <= 31; i++) {
+ DB(DW_CFA_offset|i); DUV(37+(31-i));
+ DB(DW_CFA_offset|32|i); DUV(2+2*(31-i));
+ }
+ }
+#elif LJ_TARGET_MIPS
+ {
+ int i;
+ DB(DW_CFA_offset|30); DUV(2);
+ for (i = 23; i >= 16; i--) { DB(DW_CFA_offset|i); DUV(26-i); }
+ for (i = 30; i >= 20; i -= 2) { DB(DW_CFA_offset|32|i); DUV(42-i); }
+ }
+#else
+#error "Unsupported target architecture"
+#endif
+ if (ctx->spadjp != ctx->spadj) { /* Parent/interpreter stack frame size. */
+ DB(DW_CFA_def_cfa_offset); DUV(ctx->spadjp);
+ DB(DW_CFA_advance_loc|1); /* Only an approximation. */
+ }
+ DB(DW_CFA_def_cfa_offset); DUV(ctx->spadj); /* Trace stack frame size. */
+ DALIGNNOP(sizeof(uintptr_t));
+ )
+
+ ctx->p = p;
+}
+
+/* Initialize .debug_info section. */
+static void LJ_FASTCALL gdbjit_debuginfo(GDBJITctx *ctx)
+{
+ uint8_t *p = ctx->p;
+
+ DSECT(info,
+ DU16(2); /* DWARF version. */
+ DU32(0); /* Abbrev offset. */
+ DB(sizeof(uintptr_t)); /* Pointer size. */
+
+ DUV(1); /* Abbrev #1: DW_TAG_compile_unit. */
+ DSTR(ctx->filename); /* DW_AT_name. */
+ DADDR(ctx->mcaddr); /* DW_AT_low_pc. */
+ DADDR(ctx->mcaddr + ctx->szmcode); /* DW_AT_high_pc. */
+ DU32(0); /* DW_AT_stmt_list. */
+ )
+
+ ctx->p = p;
+}
+
+/* Initialize .debug_abbrev section. */
+static void LJ_FASTCALL gdbjit_debugabbrev(GDBJITctx *ctx)
+{
+ uint8_t *p = ctx->p;
+
+ /* Abbrev #1: DW_TAG_compile_unit. */
+ DUV(1); DUV(DW_TAG_compile_unit);
+ DB(DW_children_no);
+ DUV(DW_AT_name); DUV(DW_FORM_string);
+ DUV(DW_AT_low_pc); DUV(DW_FORM_addr);
+ DUV(DW_AT_high_pc); DUV(DW_FORM_addr);
+ DUV(DW_AT_stmt_list); DUV(DW_FORM_data4);
+ DB(0); DB(0);
+
+ ctx->p = p;
+}
+
+#define DLNE(op, s) (DB(DW_LNS_extended_op), DUV(1+(s)), DB((op)))
+
+/* Initialize .debug_line section. */
+static void LJ_FASTCALL gdbjit_debugline(GDBJITctx *ctx)
+{
+ uint8_t *p = ctx->p;
+
+ DSECT(line,
+ DU16(2); /* DWARF version. */
+ DSECT(header,
+ DB(1); /* Minimum instruction length. */
+ DB(1); /* is_stmt. */
+ DI8(0); /* Line base for special opcodes. */
+ DB(2); /* Line range for special opcodes. */
+ DB(3+1); /* Opcode base at DW_LNS_advance_line+1. */
+ DB(0); DB(1); DB(1); /* Standard opcode lengths. */
+ /* Directory table. */
+ DB(0);
+ /* File name table. */
+ DSTR(ctx->filename); DUV(0); DUV(0); DUV(0);
+ DB(0);
+ )
+
+ DLNE(DW_LNE_set_address, sizeof(uintptr_t)); DADDR(ctx->mcaddr);
+ if (ctx->lineno) {
+ DB(DW_LNS_advance_line); DSV(ctx->lineno-1);
+ }
+ DB(DW_LNS_copy);
+ DB(DW_LNS_advance_pc); DUV(ctx->szmcode);
+ DLNE(DW_LNE_end_sequence, 0);
+ )
+
+ ctx->p = p;
+}
+
+#undef DLNE
+
+/* Undef shortcuts. */
+#undef DB
+#undef DI8
+#undef DU16
+#undef DU32
+#undef DADDR
+#undef DUV
+#undef DSV
+#undef DSTR
+#undef DALIGNNOP
+#undef DSECT
+
+/* Type of a section initializer callback. */
+typedef void (LJ_FASTCALL *GDBJITinitf)(GDBJITctx *ctx);
+
+/* Call section initializer and set the section offset and size. */
+static void gdbjit_initsect(GDBJITctx *ctx, int sect, GDBJITinitf initf)
+{
+ ctx->startp = ctx->p;
+ ctx->obj.sect[sect].ofs = (uintptr_t)((char *)ctx->p - (char *)&ctx->obj);
+ initf(ctx);
+ ctx->obj.sect[sect].size = (uintptr_t)(ctx->p - ctx->startp);
+}
+
+#define SECTALIGN(p, a) \
+ ((p) = (uint8_t *)(((uintptr_t)(p) + ((a)-1)) & ~(uintptr_t)((a)-1)))
+
+/* Build in-memory ELF object. */
+static void gdbjit_buildobj(GDBJITctx *ctx)
+{
+ GDBJITobj *obj = &ctx->obj;
+ /* Fill in ELF header and clear structures. */
+ memcpy(&obj->hdr, &elfhdr_template, sizeof(ELFheader));
+ memset(&obj->sect, 0, sizeof(ELFsectheader)*GDBJIT_SECT__MAX);
+ memset(&obj->sym, 0, sizeof(ELFsymbol)*GDBJIT_SYM__MAX);
+ /* Initialize sections. */
+ ctx->p = obj->space;
+ gdbjit_initsect(ctx, GDBJIT_SECT_shstrtab, gdbjit_secthdr);
+ gdbjit_initsect(ctx, GDBJIT_SECT_strtab, gdbjit_symtab);
+ gdbjit_initsect(ctx, GDBJIT_SECT_debug_info, gdbjit_debuginfo);
+ gdbjit_initsect(ctx, GDBJIT_SECT_debug_abbrev, gdbjit_debugabbrev);
+ gdbjit_initsect(ctx, GDBJIT_SECT_debug_line, gdbjit_debugline);
+ SECTALIGN(ctx->p, sizeof(uintptr_t));
+ gdbjit_initsect(ctx, GDBJIT_SECT_eh_frame, gdbjit_ehframe);
+ ctx->objsize = (size_t)((char *)ctx->p - (char *)obj);
+ lua_assert(ctx->objsize < sizeof(GDBJITobj));
+}
+
+#undef SECTALIGN
+
+/* -- Interface to GDB JIT API -------------------------------------------- */
+
+/* Add new entry to GDB JIT symbol chain. */
+static void gdbjit_newentry(lua_State *L, GDBJITctx *ctx)
+{
+ /* Allocate memory for GDB JIT entry and ELF object. */
+ MSize sz = (MSize)(sizeof(GDBJITentryobj) - sizeof(GDBJITobj) + ctx->objsize);
+ GDBJITentryobj *eo = lj_mem_newt(L, sz, GDBJITentryobj);
+ memcpy(&eo->obj, &ctx->obj, ctx->objsize); /* Copy ELF object. */
+ eo->sz = sz;
+ ctx->T->gdbjit_entry = (void *)eo;
+ /* Link new entry to chain and register it. */
+ eo->entry.prev_entry = NULL;
+ eo->entry.next_entry = __jit_debug_descriptor.first_entry;
+ if (eo->entry.next_entry)
+ eo->entry.next_entry->prev_entry = &eo->entry;
+ eo->entry.symfile_addr = (const char *)&eo->obj;
+ eo->entry.symfile_size = ctx->objsize;
+ __jit_debug_descriptor.first_entry = &eo->entry;
+ __jit_debug_descriptor.relevant_entry = &eo->entry;
+ __jit_debug_descriptor.action_flag = GDBJIT_REGISTER;
+ __jit_debug_register_code();
+}
+
+/* Add debug info for newly compiled trace and notify GDB. */
+void lj_gdbjit_addtrace(jit_State *J, GCtrace *T)
+{
+ GDBJITctx ctx;
+ GCproto *pt = &gcref(T->startpt)->pt;
+ TraceNo parent = T->ir[REF_BASE].op1;
+ const BCIns *startpc = mref(T->startpc, const BCIns);
+ ctx.T = T;
+ ctx.mcaddr = (uintptr_t)T->mcode;
+ ctx.szmcode = T->szmcode;
+ ctx.spadjp = CFRAME_SIZE_JIT +
+ (MSize)(parent ? traceref(J, parent)->spadjust : 0);
+ ctx.spadj = CFRAME_SIZE_JIT + T->spadjust;
+ lua_assert(startpc >= proto_bc(pt) && startpc < proto_bc(pt) + pt->sizebc);
+ ctx.lineno = lj_debug_line(pt, proto_bcpos(pt, startpc));
+ ctx.filename = proto_chunknamestr(pt);
+ if (*ctx.filename == '@' || *ctx.filename == '=')
+ ctx.filename++;
+ else
+ ctx.filename = "(string)";
+ gdbjit_buildobj(&ctx);
+ gdbjit_newentry(J->L, &ctx);
+}
+
+/* Delete debug info for trace and notify GDB. */
+void lj_gdbjit_deltrace(jit_State *J, GCtrace *T)
+{
+ GDBJITentryobj *eo = (GDBJITentryobj *)T->gdbjit_entry;
+ if (eo) {
+ if (eo->entry.prev_entry)
+ eo->entry.prev_entry->next_entry = eo->entry.next_entry;
+ else
+ __jit_debug_descriptor.first_entry = eo->entry.next_entry;
+ if (eo->entry.next_entry)
+ eo->entry.next_entry->prev_entry = eo->entry.prev_entry;
+ __jit_debug_descriptor.relevant_entry = &eo->entry;
+ __jit_debug_descriptor.action_flag = GDBJIT_UNREGISTER;
+ __jit_debug_register_code();
+ lj_mem_free(J2G(J), eo, eo->sz);
+ }
+}
+
+#endif
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_gdbjit.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_gdbjit.h
new file mode 100644
index 0000000..bbaa156
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_gdbjit.h
@@ -0,0 +1,22 @@
+/*
+** Client for the GDB JIT API.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_GDBJIT_H
+#define _LJ_GDBJIT_H
+
+#include "lj_obj.h"
+#include "lj_jit.h"
+
+#if LJ_HASJIT && defined(LUAJIT_USE_GDBJIT)
+
+LJ_FUNC void lj_gdbjit_addtrace(jit_State *J, GCtrace *T);
+LJ_FUNC void lj_gdbjit_deltrace(jit_State *J, GCtrace *T);
+
+#else
+#define lj_gdbjit_addtrace(J, T) UNUSED(T)
+#define lj_gdbjit_deltrace(J, T) UNUSED(T)
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_ir.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_ir.c
new file mode 100644
index 0000000..1e4860d
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_ir.c
@@ -0,0 +1,501 @@
+/*
+** SSA IR (Intermediate Representation) emitter.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_ir_c
+#define LUA_CORE
+
+/* For pointers to libc/libm functions. */
+#include <stdio.h>
+#include <math.h>
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT
+
+#include "lj_gc.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_ir.h"
+#include "lj_jit.h"
+#include "lj_ircall.h"
+#include "lj_iropt.h"
+#include "lj_trace.h"
+#if LJ_HASFFI
+#include "lj_ctype.h"
+#include "lj_cdata.h"
+#include "lj_carith.h"
+#endif
+#include "lj_vm.h"
+#include "lj_strscan.h"
+#include "lj_lib.h"
+
+/* Some local macros to save typing. Undef'd at the end. */
+#define IR(ref) (&J->cur.ir[(ref)])
+#define fins (&J->fold.ins)
+
+/* Pass IR on to next optimization in chain (FOLD). */
+#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))
+
+/* -- IR tables ----------------------------------------------------------- */
+
+/* IR instruction modes. */
+LJ_DATADEF const uint8_t lj_ir_mode[IR__MAX+1] = {
+IRDEF(IRMODE)
+ 0
+};
+
+/* IR type sizes. */
+LJ_DATADEF const uint8_t lj_ir_type_size[IRT__MAX+1] = {
+#define IRTSIZE(name, size) size,
+IRTDEF(IRTSIZE)
+#undef IRTSIZE
+ 0
+};
+
+/* C call info for CALL* instructions. */
+LJ_DATADEF const CCallInfo lj_ir_callinfo[] = {
+#define IRCALLCI(cond, name, nargs, kind, type, flags) \
+ { (ASMFunction)IRCALLCOND_##cond(name), \
+ (nargs)|(CCI_CALL_##kind)|(IRT_##type<<CCI_OTSHIFT)|(flags) },
+IRCALLDEF(IRCALLCI)
+#undef IRCALLCI
+ { NULL, 0 }
+};
+
+/* -- IR emitter ---------------------------------------------------------- */
+
+/* Grow IR buffer at the top. */
+void LJ_FASTCALL lj_ir_growtop(jit_State *J)
+{
+ IRIns *baseir = J->irbuf + J->irbotlim;
+ MSize szins = J->irtoplim - J->irbotlim;
+ if (szins) {
+ baseir = (IRIns *)lj_mem_realloc(J->L, baseir, szins*sizeof(IRIns),
+ 2*szins*sizeof(IRIns));
+ J->irtoplim = J->irbotlim + 2*szins;
+ } else {
+ baseir = (IRIns *)lj_mem_realloc(J->L, NULL, 0, LJ_MIN_IRSZ*sizeof(IRIns));
+ J->irbotlim = REF_BASE - LJ_MIN_IRSZ/4;
+ J->irtoplim = J->irbotlim + LJ_MIN_IRSZ;
+ }
+ J->cur.ir = J->irbuf = baseir - J->irbotlim;
+}
+
+/* Grow IR buffer at the bottom or shift it up. */
+static void lj_ir_growbot(jit_State *J)
+{
+ IRIns *baseir = J->irbuf + J->irbotlim;
+ MSize szins = J->irtoplim - J->irbotlim;
+ lua_assert(szins != 0);
+ lua_assert(J->cur.nk == J->irbotlim);
+ if (J->cur.nins + (szins >> 1) < J->irtoplim) {
+ /* More than half of the buffer is free on top: shift up by a quarter. */
+ MSize ofs = szins >> 2;
+ memmove(baseir + ofs, baseir, (J->cur.nins - J->irbotlim)*sizeof(IRIns));
+ J->irbotlim -= ofs;
+ J->irtoplim -= ofs;
+ J->cur.ir = J->irbuf = baseir - J->irbotlim;
+ } else {
+ /* Double the buffer size, but split the growth amongst top/bottom. */
+ IRIns *newbase = lj_mem_newt(J->L, 2*szins*sizeof(IRIns), IRIns);
+ MSize ofs = szins >= 256 ? 128 : (szins >> 1); /* Limit bottom growth. */
+ memcpy(newbase + ofs, baseir, (J->cur.nins - J->irbotlim)*sizeof(IRIns));
+ lj_mem_free(G(J->L), baseir, szins*sizeof(IRIns));
+ J->irbotlim -= ofs;
+ J->irtoplim = J->irbotlim + 2*szins;
+ J->cur.ir = J->irbuf = newbase - J->irbotlim;
+ }
+}
+
+/* Emit IR without any optimizations. */
+TRef LJ_FASTCALL lj_ir_emit(jit_State *J)
+{
+ IRRef ref = lj_ir_nextins(J);
+ IRIns *ir = IR(ref);
+ IROp op = fins->o;
+ ir->prev = J->chain[op];
+ J->chain[op] = (IRRef1)ref;
+ ir->o = op;
+ ir->op1 = fins->op1;
+ ir->op2 = fins->op2;
+ J->guardemit.irt |= fins->t.irt;
+ return TREF(ref, irt_t((ir->t = fins->t)));
+}
+
+/* Emit call to a C function. */
+TRef lj_ir_call(jit_State *J, IRCallID id, ...)
+{
+ const CCallInfo *ci = &lj_ir_callinfo[id];
+ uint32_t n = CCI_NARGS(ci);
+ TRef tr = TREF_NIL;
+ va_list argp;
+ va_start(argp, id);
+ if ((ci->flags & CCI_L)) n--;
+ if (n > 0)
+ tr = va_arg(argp, IRRef);
+ while (n-- > 1)
+ tr = emitir(IRT(IR_CARG, IRT_NIL), tr, va_arg(argp, IRRef));
+ va_end(argp);
+ if (CCI_OP(ci) == IR_CALLS)
+ J->needsnap = 1; /* Need snapshot after call with side effect. */
+ return emitir(CCI_OPTYPE(ci), tr, id);
+}
+
+/* -- Interning of constants ---------------------------------------------- */
+
+/*
+** IR instructions for constants are kept between J->cur.nk >= ref < REF_BIAS.
+** They are chained like all other instructions, but grow downwards.
+** The are interned (like strings in the VM) to facilitate reference
+** comparisons. The same constant must get the same reference.
+*/
+
+/* Get ref of next IR constant and optionally grow IR.
+** Note: this may invalidate all IRIns *!
+*/
+static LJ_AINLINE IRRef ir_nextk(jit_State *J)
+{
+ IRRef ref = J->cur.nk;
+ if (LJ_UNLIKELY(ref <= J->irbotlim)) lj_ir_growbot(J);
+ J->cur.nk = --ref;
+ return ref;
+}
+
+/* Intern int32_t constant. */
+TRef LJ_FASTCALL lj_ir_kint(jit_State *J, int32_t k)
+{
+ IRIns *ir, *cir = J->cur.ir;
+ IRRef ref;
+ for (ref = J->chain[IR_KINT]; ref; ref = cir[ref].prev)
+ if (cir[ref].i == k)
+ goto found;
+ ref = ir_nextk(J);
+ ir = IR(ref);
+ ir->i = k;
+ ir->t.irt = IRT_INT;
+ ir->o = IR_KINT;
+ ir->prev = J->chain[IR_KINT];
+ J->chain[IR_KINT] = (IRRef1)ref;
+found:
+ return TREF(ref, IRT_INT);
+}
+
+/* The MRef inside the KNUM/KINT64 IR instructions holds the address of the
+** 64 bit constant. The constants themselves are stored in a chained array
+** and shared across traces.
+**
+** Rationale for choosing this data structure:
+** - The address of the constants is embedded in the generated machine code
+** and must never move. A resizable array or hash table wouldn't work.
+** - Most apps need very few non-32 bit integer constants (less than a dozen).
+** - Linear search is hard to beat in terms of speed and low complexity.
+*/
+typedef struct K64Array {
+ MRef next; /* Pointer to next list. */
+ MSize numk; /* Number of used elements in this array. */
+ TValue k[LJ_MIN_K64SZ]; /* Array of constants. */
+} K64Array;
+
+/* Free all chained arrays. */
+void lj_ir_k64_freeall(jit_State *J)
+{
+ K64Array *k;
+ for (k = mref(J->k64, K64Array); k; ) {
+ K64Array *next = mref(k->next, K64Array);
+ lj_mem_free(J2G(J), k, sizeof(K64Array));
+ k = next;
+ }
+}
+
+/* Find 64 bit constant in chained array or add it. */
+cTValue *lj_ir_k64_find(jit_State *J, uint64_t u64)
+{
+ K64Array *k, *kp = NULL;
+ TValue *ntv;
+ MSize idx;
+ /* Search for the constant in the whole chain of arrays. */
+ for (k = mref(J->k64, K64Array); k; k = mref(k->next, K64Array)) {
+ kp = k; /* Remember previous element in list. */
+ for (idx = 0; idx < k->numk; idx++) { /* Search one array. */
+ TValue *tv = &k->k[idx];
+ if (tv->u64 == u64) /* Needed for +-0/NaN/absmask. */
+ return tv;
+ }
+ }
+ /* Constant was not found, need to add it. */
+ if (!(kp && kp->numk < LJ_MIN_K64SZ)) { /* Allocate a new array. */
+ K64Array *kn = lj_mem_newt(J->L, sizeof(K64Array), K64Array);
+ setmref(kn->next, NULL);
+ kn->numk = 0;
+ if (kp)
+ setmref(kp->next, kn); /* Chain to the end of the list. */
+ else
+ setmref(J->k64, kn); /* Link first array. */
+ kp = kn;
+ }
+ ntv = &kp->k[kp->numk++]; /* Add to current array. */
+ ntv->u64 = u64;
+ return ntv;
+}
+
+/* Intern 64 bit constant, given by its address. */
+TRef lj_ir_k64(jit_State *J, IROp op, cTValue *tv)
+{
+ IRIns *ir, *cir = J->cur.ir;
+ IRRef ref;
+ IRType t = op == IR_KNUM ? IRT_NUM : IRT_I64;
+ for (ref = J->chain[op]; ref; ref = cir[ref].prev)
+ if (ir_k64(&cir[ref]) == tv)
+ goto found;
+ ref = ir_nextk(J);
+ ir = IR(ref);
+ lua_assert(checkptr32(tv));
+ setmref(ir->ptr, tv);
+ ir->t.irt = t;
+ ir->o = op;
+ ir->prev = J->chain[op];
+ J->chain[op] = (IRRef1)ref;
+found:
+ return TREF(ref, t);
+}
+
+/* Intern FP constant, given by its 64 bit pattern. */
+TRef lj_ir_knum_u64(jit_State *J, uint64_t u64)
+{
+ return lj_ir_k64(J, IR_KNUM, lj_ir_k64_find(J, u64));
+}
+
+/* Intern 64 bit integer constant. */
+TRef lj_ir_kint64(jit_State *J, uint64_t u64)
+{
+ return lj_ir_k64(J, IR_KINT64, lj_ir_k64_find(J, u64));
+}
+
+/* Check whether a number is int and return it. -0 is NOT considered an int. */
+static int numistrueint(lua_Number n, int32_t *kp)
+{
+ int32_t k = lj_num2int(n);
+ if (n == (lua_Number)k) {
+ if (kp) *kp = k;
+ if (k == 0) { /* Special check for -0. */
+ TValue tv;
+ setnumV(&tv, n);
+ if (tv.u32.hi != 0)
+ return 0;
+ }
+ return 1;
+ }
+ return 0;
+}
+
+/* Intern number as int32_t constant if possible, otherwise as FP constant. */
+TRef lj_ir_knumint(jit_State *J, lua_Number n)
+{
+ int32_t k;
+ if (numistrueint(n, &k))
+ return lj_ir_kint(J, k);
+ else
+ return lj_ir_knum(J, n);
+}
+
+/* Intern GC object "constant". */
+TRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t)
+{
+ IRIns *ir, *cir = J->cur.ir;
+ IRRef ref;
+ lua_assert(!isdead(J2G(J), o));
+ for (ref = J->chain[IR_KGC]; ref; ref = cir[ref].prev)
+ if (ir_kgc(&cir[ref]) == o)
+ goto found;
+ ref = ir_nextk(J);
+ ir = IR(ref);
+ /* NOBARRIER: Current trace is a GC root. */
+ setgcref(ir->gcr, o);
+ ir->t.irt = (uint8_t)t;
+ ir->o = IR_KGC;
+ ir->prev = J->chain[IR_KGC];
+ J->chain[IR_KGC] = (IRRef1)ref;
+found:
+ return TREF(ref, t);
+}
+
+/* Intern 32 bit pointer constant. */
+TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr)
+{
+ IRIns *ir, *cir = J->cur.ir;
+ IRRef ref;
+ lua_assert((void *)(intptr_t)i32ptr(ptr) == ptr);
+ for (ref = J->chain[op]; ref; ref = cir[ref].prev)
+ if (mref(cir[ref].ptr, void) == ptr)
+ goto found;
+ ref = ir_nextk(J);
+ ir = IR(ref);
+ setmref(ir->ptr, ptr);
+ ir->t.irt = IRT_P32;
+ ir->o = op;
+ ir->prev = J->chain[op];
+ J->chain[op] = (IRRef1)ref;
+found:
+ return TREF(ref, IRT_P32);
+}
+
+/* Intern typed NULL constant. */
+TRef lj_ir_knull(jit_State *J, IRType t)
+{
+ IRIns *ir, *cir = J->cur.ir;
+ IRRef ref;
+ for (ref = J->chain[IR_KNULL]; ref; ref = cir[ref].prev)
+ if (irt_t(cir[ref].t) == t)
+ goto found;
+ ref = ir_nextk(J);
+ ir = IR(ref);
+ ir->i = 0;
+ ir->t.irt = (uint8_t)t;
+ ir->o = IR_KNULL;
+ ir->prev = J->chain[IR_KNULL];
+ J->chain[IR_KNULL] = (IRRef1)ref;
+found:
+ return TREF(ref, t);
+}
+
+/* Intern key slot. */
+TRef lj_ir_kslot(jit_State *J, TRef key, IRRef slot)
+{
+ IRIns *ir, *cir = J->cur.ir;
+ IRRef2 op12 = IRREF2((IRRef1)key, (IRRef1)slot);
+ IRRef ref;
+ /* Const part is not touched by CSE/DCE, so 0-65535 is ok for IRMlit here. */
+ lua_assert(tref_isk(key) && slot == (IRRef)(IRRef1)slot);
+ for (ref = J->chain[IR_KSLOT]; ref; ref = cir[ref].prev)
+ if (cir[ref].op12 == op12)
+ goto found;
+ ref = ir_nextk(J);
+ ir = IR(ref);
+ ir->op12 = op12;
+ ir->t.irt = IRT_P32;
+ ir->o = IR_KSLOT;
+ ir->prev = J->chain[IR_KSLOT];
+ J->chain[IR_KSLOT] = (IRRef1)ref;
+found:
+ return TREF(ref, IRT_P32);
+}
+
+/* -- Access to IR constants ---------------------------------------------- */
+
+/* Copy value of IR constant. */
+void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir)
+{
+ UNUSED(L);
+ lua_assert(ir->o != IR_KSLOT); /* Common mistake. */
+ switch (ir->o) {
+ case IR_KPRI: setitype(tv, irt_toitype(ir->t)); break;
+ case IR_KINT: setintV(tv, ir->i); break;
+ case IR_KGC: setgcV(L, tv, ir_kgc(ir), irt_toitype(ir->t)); break;
+ case IR_KPTR: case IR_KKPTR: case IR_KNULL:
+ setlightudV(tv, mref(ir->ptr, void));
+ break;
+ case IR_KNUM: setnumV(tv, ir_knum(ir)->n); break;
+#if LJ_HASFFI
+ case IR_KINT64: {
+ GCcdata *cd = lj_cdata_new_(L, CTID_INT64, 8);
+ *(uint64_t *)cdataptr(cd) = ir_kint64(ir)->u64;
+ setcdataV(L, tv, cd);
+ break;
+ }
+#endif
+ default: lua_assert(0); break;
+ }
+}
+
+/* -- Convert IR operand types -------------------------------------------- */
+
+/* Convert from string to number. */
+TRef LJ_FASTCALL lj_ir_tonumber(jit_State *J, TRef tr)
+{
+ if (!tref_isnumber(tr)) {
+ if (tref_isstr(tr))
+ tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);
+ else
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ }
+ return tr;
+}
+
+/* Convert from integer or string to number. */
+TRef LJ_FASTCALL lj_ir_tonum(jit_State *J, TRef tr)
+{
+ if (!tref_isnum(tr)) {
+ if (tref_isinteger(tr))
+ tr = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT);
+ else if (tref_isstr(tr))
+ tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);
+ else
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ }
+ return tr;
+}
+
+/* Convert from integer or number to string. */
+TRef LJ_FASTCALL lj_ir_tostr(jit_State *J, TRef tr)
+{
+ if (!tref_isstr(tr)) {
+ if (!tref_isnumber(tr))
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ tr = emitir(IRT(IR_TOSTR, IRT_STR), tr, 0);
+ }
+ return tr;
+}
+
+/* -- Miscellaneous IR ops ------------------------------------------------ */
+
+/* Evaluate numeric comparison. */
+int lj_ir_numcmp(lua_Number a, lua_Number b, IROp op)
+{
+ switch (op) {
+ case IR_EQ: return (a == b);
+ case IR_NE: return (a != b);
+ case IR_LT: return (a < b);
+ case IR_GE: return (a >= b);
+ case IR_LE: return (a <= b);
+ case IR_GT: return (a > b);
+ case IR_ULT: return !(a >= b);
+ case IR_UGE: return !(a < b);
+ case IR_ULE: return !(a > b);
+ case IR_UGT: return !(a <= b);
+ default: lua_assert(0); return 0;
+ }
+}
+
+/* Evaluate string comparison. */
+int lj_ir_strcmp(GCstr *a, GCstr *b, IROp op)
+{
+ int res = lj_str_cmp(a, b);
+ switch (op) {
+ case IR_LT: return (res < 0);
+ case IR_GE: return (res >= 0);
+ case IR_LE: return (res <= 0);
+ case IR_GT: return (res > 0);
+ default: lua_assert(0); return 0;
+ }
+}
+
+/* Rollback IR to previous state. */
+void lj_ir_rollback(jit_State *J, IRRef ref)
+{
+ IRRef nins = J->cur.nins;
+ while (nins > ref) {
+ IRIns *ir;
+ nins--;
+ ir = IR(nins);
+ J->chain[ir->o] = ir->prev;
+ }
+ J->cur.nins = nins;
+}
+
+#undef IR
+#undef fins
+#undef emitir
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_ir.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_ir.h
new file mode 100644
index 0000000..ded3e0e
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_ir.h
@@ -0,0 +1,551 @@
+/*
+** SSA IR (Intermediate Representation) format.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_IR_H
+#define _LJ_IR_H
+
+#include "lj_obj.h"
+
+/* -- IR instructions ----------------------------------------------------- */
+
+/* IR instruction definition. Order matters, see below. ORDER IR */
+#define IRDEF(_) \
+ /* Guarded assertions. */ \
+ /* Must be properly aligned to flip opposites (^1) and (un)ordered (^4). */ \
+ _(LT, N , ref, ref) \
+ _(GE, N , ref, ref) \
+ _(LE, N , ref, ref) \
+ _(GT, N , ref, ref) \
+ \
+ _(ULT, N , ref, ref) \
+ _(UGE, N , ref, ref) \
+ _(ULE, N , ref, ref) \
+ _(UGT, N , ref, ref) \
+ \
+ _(EQ, C , ref, ref) \
+ _(NE, C , ref, ref) \
+ \
+ _(ABC, N , ref, ref) \
+ _(RETF, S , ref, ref) \
+ \
+ /* Miscellaneous ops. */ \
+ _(NOP, N , ___, ___) \
+ _(BASE, N , lit, lit) \
+ _(PVAL, N , lit, ___) \
+ _(GCSTEP, S , ___, ___) \
+ _(HIOP, S , ref, ref) \
+ _(LOOP, S , ___, ___) \
+ _(USE, S , ref, ___) \
+ _(PHI, S , ref, ref) \
+ _(RENAME, S , ref, lit) \
+ \
+ /* Constants. */ \
+ _(KPRI, N , ___, ___) \
+ _(KINT, N , cst, ___) \
+ _(KGC, N , cst, ___) \
+ _(KPTR, N , cst, ___) \
+ _(KKPTR, N , cst, ___) \
+ _(KNULL, N , cst, ___) \
+ _(KNUM, N , cst, ___) \
+ _(KINT64, N , cst, ___) \
+ _(KSLOT, N , ref, lit) \
+ \
+ /* Bit ops. */ \
+ _(BNOT, N , ref, ___) \
+ _(BSWAP, N , ref, ___) \
+ _(BAND, C , ref, ref) \
+ _(BOR, C , ref, ref) \
+ _(BXOR, C , ref, ref) \
+ _(BSHL, N , ref, ref) \
+ _(BSHR, N , ref, ref) \
+ _(BSAR, N , ref, ref) \
+ _(BROL, N , ref, ref) \
+ _(BROR, N , ref, ref) \
+ \
+ /* Arithmetic ops. ORDER ARITH */ \
+ _(ADD, C , ref, ref) \
+ _(SUB, N , ref, ref) \
+ _(MUL, C , ref, ref) \
+ _(DIV, N , ref, ref) \
+ _(MOD, N , ref, ref) \
+ _(POW, N , ref, ref) \
+ _(NEG, N , ref, ref) \
+ \
+ _(ABS, N , ref, ref) \
+ _(ATAN2, N , ref, ref) \
+ _(LDEXP, N , ref, ref) \
+ _(MIN, C , ref, ref) \
+ _(MAX, C , ref, ref) \
+ _(FPMATH, N , ref, lit) \
+ \
+ /* Overflow-checking arithmetic ops. */ \
+ _(ADDOV, CW, ref, ref) \
+ _(SUBOV, NW, ref, ref) \
+ _(MULOV, CW, ref, ref) \
+ \
+ /* Memory ops. A = array, H = hash, U = upvalue, F = field, S = stack. */ \
+ \
+ /* Memory references. */ \
+ _(AREF, R , ref, ref) \
+ _(HREFK, R , ref, ref) \
+ _(HREF, L , ref, ref) \
+ _(NEWREF, S , ref, ref) \
+ _(UREFO, LW, ref, lit) \
+ _(UREFC, LW, ref, lit) \
+ _(FREF, R , ref, lit) \
+ _(STRREF, N , ref, ref) \
+ \
+ /* Loads and Stores. These must be in the same order. */ \
+ _(ALOAD, L , ref, ___) \
+ _(HLOAD, L , ref, ___) \
+ _(ULOAD, L , ref, ___) \
+ _(FLOAD, L , ref, lit) \
+ _(XLOAD, L , ref, lit) \
+ _(SLOAD, L , lit, lit) \
+ _(VLOAD, L , ref, ___) \
+ \
+ _(ASTORE, S , ref, ref) \
+ _(HSTORE, S , ref, ref) \
+ _(USTORE, S , ref, ref) \
+ _(FSTORE, S , ref, ref) \
+ _(XSTORE, S , ref, ref) \
+ \
+ /* Allocations. */ \
+ _(SNEW, N , ref, ref) /* CSE is ok, not marked as A. */ \
+ _(XSNEW, A , ref, ref) \
+ _(TNEW, AW, lit, lit) \
+ _(TDUP, AW, ref, ___) \
+ _(CNEW, AW, ref, ref) \
+ _(CNEWI, NW, ref, ref) /* CSE is ok, not marked as A. */ \
+ \
+ /* Barriers. */ \
+ _(TBAR, S , ref, ___) \
+ _(OBAR, S , ref, ref) \
+ _(XBAR, S , ___, ___) \
+ \
+ /* Type conversions. */ \
+ _(CONV, NW, ref, lit) \
+ _(TOBIT, N , ref, ref) \
+ _(TOSTR, N , ref, ___) \
+ _(STRTO, N , ref, ___) \
+ \
+ /* Calls. */ \
+ _(CALLN, N , ref, lit) \
+ _(CALLL, L , ref, lit) \
+ _(CALLS, S , ref, lit) \
+ _(CALLXS, S , ref, ref) \
+ _(CARG, N , ref, ref) \
+ \
+ /* End of list. */
+
+/* IR opcodes (max. 256). */
+typedef enum {
+#define IRENUM(name, m, m1, m2) IR_##name,
+IRDEF(IRENUM)
+#undef IRENUM
+ IR__MAX
+} IROp;
+
+/* Stored opcode. */
+typedef uint8_t IROp1;
+
+LJ_STATIC_ASSERT(((int)IR_EQ^1) == (int)IR_NE);
+LJ_STATIC_ASSERT(((int)IR_LT^1) == (int)IR_GE);
+LJ_STATIC_ASSERT(((int)IR_LE^1) == (int)IR_GT);
+LJ_STATIC_ASSERT(((int)IR_LT^3) == (int)IR_GT);
+LJ_STATIC_ASSERT(((int)IR_LT^4) == (int)IR_ULT);
+
+/* Delta between xLOAD and xSTORE. */
+#define IRDELTA_L2S ((int)IR_ASTORE - (int)IR_ALOAD)
+
+LJ_STATIC_ASSERT((int)IR_HLOAD + IRDELTA_L2S == (int)IR_HSTORE);
+LJ_STATIC_ASSERT((int)IR_ULOAD + IRDELTA_L2S == (int)IR_USTORE);
+LJ_STATIC_ASSERT((int)IR_FLOAD + IRDELTA_L2S == (int)IR_FSTORE);
+LJ_STATIC_ASSERT((int)IR_XLOAD + IRDELTA_L2S == (int)IR_XSTORE);
+
+/* -- Named IR literals --------------------------------------------------- */
+
+/* FPMATH sub-functions. ORDER FPM. */
+#define IRFPMDEF(_) \
+ _(FLOOR) _(CEIL) _(TRUNC) /* Must be first and in this order. */ \
+ _(SQRT) _(EXP) _(EXP2) _(LOG) _(LOG2) _(LOG10) \
+ _(SIN) _(COS) _(TAN) \
+ _(OTHER)
+
+typedef enum {
+#define FPMENUM(name) IRFPM_##name,
+IRFPMDEF(FPMENUM)
+#undef FPMENUM
+ IRFPM__MAX
+} IRFPMathOp;
+
+/* FLOAD fields. */
+#define IRFLDEF(_) \
+ _(STR_LEN, offsetof(GCstr, len)) \
+ _(FUNC_ENV, offsetof(GCfunc, l.env)) \
+ _(FUNC_PC, offsetof(GCfunc, l.pc)) \
+ _(TAB_META, offsetof(GCtab, metatable)) \
+ _(TAB_ARRAY, offsetof(GCtab, array)) \
+ _(TAB_NODE, offsetof(GCtab, node)) \
+ _(TAB_ASIZE, offsetof(GCtab, asize)) \
+ _(TAB_HMASK, offsetof(GCtab, hmask)) \
+ _(TAB_NOMM, offsetof(GCtab, nomm)) \
+ _(UDATA_META, offsetof(GCudata, metatable)) \
+ _(UDATA_UDTYPE, offsetof(GCudata, udtype)) \
+ _(UDATA_FILE, sizeof(GCudata)) \
+ _(CDATA_CTYPEID, offsetof(GCcdata, ctypeid)) \
+ _(CDATA_PTR, sizeof(GCcdata)) \
+ _(CDATA_INT, sizeof(GCcdata)) \
+ _(CDATA_INT64, sizeof(GCcdata)) \
+ _(CDATA_INT64_4, sizeof(GCcdata) + 4)
+
+typedef enum {
+#define FLENUM(name, ofs) IRFL_##name,
+IRFLDEF(FLENUM)
+#undef FLENUM
+ IRFL__MAX
+} IRFieldID;
+
+/* SLOAD mode bits, stored in op2. */
+#define IRSLOAD_PARENT 0x01 /* Coalesce with parent trace. */
+#define IRSLOAD_FRAME 0x02 /* Load hiword of frame. */
+#define IRSLOAD_TYPECHECK 0x04 /* Needs type check. */
+#define IRSLOAD_CONVERT 0x08 /* Number to integer conversion. */
+#define IRSLOAD_READONLY 0x10 /* Read-only, omit slot store. */
+#define IRSLOAD_INHERIT 0x20 /* Inherited by exits/side traces. */
+
+/* XLOAD mode, stored in op2. */
+#define IRXLOAD_READONLY 1 /* Load from read-only data. */
+#define IRXLOAD_VOLATILE 2 /* Load from volatile data. */
+#define IRXLOAD_UNALIGNED 4 /* Unaligned load. */
+
+/* CONV mode, stored in op2. */
+#define IRCONV_SRCMASK 0x001f /* Source IRType. */
+#define IRCONV_DSTMASK 0x03e0 /* Dest. IRType (also in ir->t). */
+#define IRCONV_DSH 5
+#define IRCONV_NUM_INT ((IRT_NUM<<IRCONV_DSH)|IRT_INT)
+#define IRCONV_INT_NUM ((IRT_INT<<IRCONV_DSH)|IRT_NUM)
+#define IRCONV_TRUNC 0x0400 /* Truncate number to integer. */
+#define IRCONV_SEXT 0x0800 /* Sign-extend integer to integer. */
+#define IRCONV_MODEMASK 0x0fff
+#define IRCONV_CONVMASK 0xf000
+#define IRCONV_CSH 12
+/* Number to integer conversion mode. Ordered by strength of the checks. */
+#define IRCONV_TOBIT (0<<IRCONV_CSH) /* None. Cache only: TOBIT conv. */
+#define IRCONV_ANY (1<<IRCONV_CSH) /* Any FP number is ok. */
+#define IRCONV_INDEX (2<<IRCONV_CSH) /* Check + special backprop rules. */
+#define IRCONV_CHECK (3<<IRCONV_CSH) /* Number checked for integerness. */
+
+/* -- IR operands --------------------------------------------------------- */
+
+/* IR operand mode (2 bit). */
+typedef enum {
+ IRMref, /* IR reference. */
+ IRMlit, /* 16 bit unsigned literal. */
+ IRMcst, /* Constant literal: i, gcr or ptr. */
+ IRMnone /* Unused operand. */
+} IRMode;
+#define IRM___ IRMnone
+
+/* Mode bits: Commutative, {Normal/Ref, Alloc, Load, Store}, Non-weak guard. */
+#define IRM_C 0x10
+
+#define IRM_N 0x00
+#define IRM_R IRM_N
+#define IRM_A 0x20
+#define IRM_L 0x40
+#define IRM_S 0x60
+
+#define IRM_W 0x80
+
+#define IRM_NW (IRM_N|IRM_W)
+#define IRM_CW (IRM_C|IRM_W)
+#define IRM_AW (IRM_A|IRM_W)
+#define IRM_LW (IRM_L|IRM_W)
+
+#define irm_op1(m) ((IRMode)((m)&3))
+#define irm_op2(m) ((IRMode)(((m)>>2)&3))
+#define irm_iscomm(m) ((m) & IRM_C)
+#define irm_kind(m) ((m) & IRM_S)
+
+#define IRMODE(name, m, m1, m2) (((IRM##m1)|((IRM##m2)<<2)|(IRM_##m))^IRM_W),
+
+LJ_DATA const uint8_t lj_ir_mode[IR__MAX+1];
+
+/* -- IR instruction types ------------------------------------------------ */
+
+/* Map of itypes to non-negative numbers. ORDER LJ_T.
+** LJ_TUPVAL/LJ_TTRACE never appear in a TValue. Use these itypes for
+** IRT_P32 and IRT_P64, which never escape the IR.
+** The various integers are only used in the IR and can only escape to
+** a TValue after implicit or explicit conversion. Their types must be
+** contiguous and next to IRT_NUM (see the typerange macros below).
+*/
+#define IRTDEF(_) \
+ _(NIL, 4) _(FALSE, 4) _(TRUE, 4) _(LIGHTUD, LJ_64 ? 8 : 4) _(STR, 4) \
+ _(P32, 4) _(THREAD, 4) _(PROTO, 4) _(FUNC, 4) _(P64, 8) _(CDATA, 4) \
+ _(TAB, 4) _(UDATA, 4) \
+ _(FLOAT, 4) _(NUM, 8) _(I8, 1) _(U8, 1) _(I16, 2) _(U16, 2) \
+ _(INT, 4) _(U32, 4) _(I64, 8) _(U64, 8) \
+ _(SOFTFP, 4) /* There is room for 9 more types. */
+
+/* IR result type and flags (8 bit). */
+typedef enum {
+#define IRTENUM(name, size) IRT_##name,
+IRTDEF(IRTENUM)
+#undef IRTENUM
+ IRT__MAX,
+
+ /* Native pointer type and the corresponding integer type. */
+ IRT_PTR = LJ_64 ? IRT_P64 : IRT_P32,
+ IRT_INTP = LJ_64 ? IRT_I64 : IRT_INT,
+ IRT_UINTP = LJ_64 ? IRT_U64 : IRT_U32,
+
+ /* Additional flags. */
+ IRT_MARK = 0x20, /* Marker for misc. purposes. */
+ IRT_ISPHI = 0x40, /* Instruction is left or right PHI operand. */
+ IRT_GUARD = 0x80, /* Instruction is a guard. */
+
+ /* Masks. */
+ IRT_TYPE = 0x1f,
+ IRT_T = 0xff
+} IRType;
+
+#define irtype_ispri(irt) ((uint32_t)(irt) <= IRT_TRUE)
+
+/* Stored IRType. */
+typedef struct IRType1 { uint8_t irt; } IRType1;
+
+#define IRT(o, t) ((uint32_t)(((o)<<8) | (t)))
+#define IRTI(o) (IRT((o), IRT_INT))
+#define IRTN(o) (IRT((o), IRT_NUM))
+#define IRTG(o, t) (IRT((o), IRT_GUARD|(t)))
+#define IRTGI(o) (IRT((o), IRT_GUARD|IRT_INT))
+
+#define irt_t(t) ((IRType)(t).irt)
+#define irt_type(t) ((IRType)((t).irt & IRT_TYPE))
+#define irt_sametype(t1, t2) ((((t1).irt ^ (t2).irt) & IRT_TYPE) == 0)
+#define irt_typerange(t, first, last) \
+ ((uint32_t)((t).irt & IRT_TYPE) - (uint32_t)(first) <= (uint32_t)(last-first))
+
+#define irt_isnil(t) (irt_type(t) == IRT_NIL)
+#define irt_ispri(t) ((uint32_t)irt_type(t) <= IRT_TRUE)
+#define irt_islightud(t) (irt_type(t) == IRT_LIGHTUD)
+#define irt_isstr(t) (irt_type(t) == IRT_STR)
+#define irt_istab(t) (irt_type(t) == IRT_TAB)
+#define irt_iscdata(t) (irt_type(t) == IRT_CDATA)
+#define irt_isfloat(t) (irt_type(t) == IRT_FLOAT)
+#define irt_isnum(t) (irt_type(t) == IRT_NUM)
+#define irt_isint(t) (irt_type(t) == IRT_INT)
+#define irt_isi8(t) (irt_type(t) == IRT_I8)
+#define irt_isu8(t) (irt_type(t) == IRT_U8)
+#define irt_isi16(t) (irt_type(t) == IRT_I16)
+#define irt_isu16(t) (irt_type(t) == IRT_U16)
+#define irt_isu32(t) (irt_type(t) == IRT_U32)
+#define irt_isi64(t) (irt_type(t) == IRT_I64)
+#define irt_isu64(t) (irt_type(t) == IRT_U64)
+
+#define irt_isfp(t) (irt_isnum(t) || irt_isfloat(t))
+#define irt_isinteger(t) (irt_typerange((t), IRT_I8, IRT_INT))
+#define irt_isgcv(t) (irt_typerange((t), IRT_STR, IRT_UDATA))
+#define irt_isaddr(t) (irt_typerange((t), IRT_LIGHTUD, IRT_UDATA))
+#define irt_isint64(t) (irt_typerange((t), IRT_I64, IRT_U64))
+
+#if LJ_64
+#define IRT_IS64 \
+ ((1u<<IRT_NUM)|(1u<<IRT_I64)|(1u<<IRT_U64)|(1u<<IRT_P64)|(1u<<IRT_LIGHTUD))
+#else
+#define IRT_IS64 \
+ ((1u<<IRT_NUM)|(1u<<IRT_I64)|(1u<<IRT_U64))
+#endif
+
+#define irt_is64(t) ((IRT_IS64 >> irt_type(t)) & 1)
+#define irt_is64orfp(t) (((IRT_IS64|(1u<<IRT_FLOAT))>>irt_type(t)) & 1)
+
+#define irt_size(t) (lj_ir_type_size[irt_t((t))])
+
+LJ_DATA const uint8_t lj_ir_type_size[];
+
+static LJ_AINLINE IRType itype2irt(const TValue *tv)
+{
+ if (tvisint(tv))
+ return IRT_INT;
+ else if (tvisnum(tv))
+ return IRT_NUM;
+#if LJ_64
+ else if (tvislightud(tv))
+ return IRT_LIGHTUD;
+#endif
+ else
+ return (IRType)~itype(tv);
+}
+
+static LJ_AINLINE uint32_t irt_toitype_(IRType t)
+{
+ lua_assert(!LJ_64 || t != IRT_LIGHTUD);
+ if (LJ_DUALNUM && t > IRT_NUM) {
+ return LJ_TISNUM;
+ } else {
+ lua_assert(t <= IRT_NUM);
+ return ~(uint32_t)t;
+ }
+}
+
+#define irt_toitype(t) irt_toitype_(irt_type((t)))
+
+#define irt_isguard(t) ((t).irt & IRT_GUARD)
+#define irt_ismarked(t) ((t).irt & IRT_MARK)
+#define irt_setmark(t) ((t).irt |= IRT_MARK)
+#define irt_clearmark(t) ((t).irt &= ~IRT_MARK)
+#define irt_isphi(t) ((t).irt & IRT_ISPHI)
+#define irt_setphi(t) ((t).irt |= IRT_ISPHI)
+#define irt_clearphi(t) ((t).irt &= ~IRT_ISPHI)
+
+/* Stored combined IR opcode and type. */
+typedef uint16_t IROpT;
+
+/* -- IR references ------------------------------------------------------- */
+
+/* IR references. */
+typedef uint16_t IRRef1; /* One stored reference. */
+typedef uint32_t IRRef2; /* Two stored references. */
+typedef uint32_t IRRef; /* Used to pass around references. */
+
+/* Fixed references. */
+enum {
+ REF_BIAS = 0x8000,
+ REF_TRUE = REF_BIAS-3,
+ REF_FALSE = REF_BIAS-2,
+ REF_NIL = REF_BIAS-1, /* \--- Constants grow downwards. */
+ REF_BASE = REF_BIAS, /* /--- IR grows upwards. */
+ REF_FIRST = REF_BIAS+1,
+ REF_DROP = 0xffff
+};
+
+/* Note: IRMlit operands must be < REF_BIAS, too!
+** This allows for fast and uniform manipulation of all operands
+** without looking up the operand mode in lj_ir_mode:
+** - CSE calculates the maximum reference of two operands.
+** This must work with mixed reference/literal operands, too.
+** - DCE marking only checks for operand >= REF_BIAS.
+** - LOOP needs to substitute reference operands.
+** Constant references and literals must not be modified.
+*/
+
+#define IRREF2(lo, hi) ((IRRef2)(lo) | ((IRRef2)(hi) << 16))
+
+#define irref_isk(ref) ((ref) < REF_BIAS)
+
+/* Tagged IR references (32 bit).
+**
+** +-------+-------+---------------+
+** | irt | flags | ref |
+** +-------+-------+---------------+
+**
+** The tag holds a copy of the IRType and speeds up IR type checks.
+*/
+typedef uint32_t TRef;
+
+#define TREF_REFMASK 0x0000ffff
+#define TREF_FRAME 0x00010000
+#define TREF_CONT 0x00020000
+
+#define TREF(ref, t) ((TRef)((ref) + ((t)<<24)))
+
+#define tref_ref(tr) ((IRRef1)(tr))
+#define tref_t(tr) ((IRType)((tr)>>24))
+#define tref_type(tr) ((IRType)(((tr)>>24) & IRT_TYPE))
+#define tref_typerange(tr, first, last) \
+ ((((tr)>>24) & IRT_TYPE) - (TRef)(first) <= (TRef)(last-first))
+
+#define tref_istype(tr, t) (((tr) & (IRT_TYPE<<24)) == ((t)<<24))
+#define tref_isnil(tr) (tref_istype((tr), IRT_NIL))
+#define tref_isfalse(tr) (tref_istype((tr), IRT_FALSE))
+#define tref_istrue(tr) (tref_istype((tr), IRT_TRUE))
+#define tref_isstr(tr) (tref_istype((tr), IRT_STR))
+#define tref_isfunc(tr) (tref_istype((tr), IRT_FUNC))
+#define tref_iscdata(tr) (tref_istype((tr), IRT_CDATA))
+#define tref_istab(tr) (tref_istype((tr), IRT_TAB))
+#define tref_isudata(tr) (tref_istype((tr), IRT_UDATA))
+#define tref_isnum(tr) (tref_istype((tr), IRT_NUM))
+#define tref_isint(tr) (tref_istype((tr), IRT_INT))
+
+#define tref_isbool(tr) (tref_typerange((tr), IRT_FALSE, IRT_TRUE))
+#define tref_ispri(tr) (tref_typerange((tr), IRT_NIL, IRT_TRUE))
+#define tref_istruecond(tr) (!tref_typerange((tr), IRT_NIL, IRT_FALSE))
+#define tref_isinteger(tr) (tref_typerange((tr), IRT_I8, IRT_INT))
+#define tref_isnumber(tr) (tref_typerange((tr), IRT_NUM, IRT_INT))
+#define tref_isnumber_str(tr) (tref_isnumber((tr)) || tref_isstr((tr)))
+#define tref_isgcv(tr) (tref_typerange((tr), IRT_STR, IRT_UDATA))
+
+#define tref_isk(tr) (irref_isk(tref_ref((tr))))
+#define tref_isk2(tr1, tr2) (irref_isk(tref_ref((tr1) | (tr2))))
+
+#define TREF_PRI(t) (TREF(REF_NIL-(t), (t)))
+#define TREF_NIL (TREF_PRI(IRT_NIL))
+#define TREF_FALSE (TREF_PRI(IRT_FALSE))
+#define TREF_TRUE (TREF_PRI(IRT_TRUE))
+
+/* -- IR format ----------------------------------------------------------- */
+
+/* IR instruction format (64 bit).
+**
+** 16 16 8 8 8 8
+** +-------+-------+---+---+---+---+
+** | op1 | op2 | t | o | r | s |
+** +-------+-------+---+---+---+---+
+** | op12/i/gco | ot | prev | (alternative fields in union)
+** +---------------+-------+-------+
+** 32 16 16
+**
+** prev is only valid prior to register allocation and then reused for r + s.
+*/
+
+typedef union IRIns {
+ struct {
+ LJ_ENDIAN_LOHI(
+ IRRef1 op1; /* IR operand 1. */
+ , IRRef1 op2; /* IR operand 2. */
+ )
+ IROpT ot; /* IR opcode and type (overlaps t and o). */
+ IRRef1 prev; /* Previous ins in same chain (overlaps r and s). */
+ };
+ struct {
+ IRRef2 op12; /* IR operand 1 and 2 (overlaps op1 and op2). */
+ LJ_ENDIAN_LOHI(
+ IRType1 t; /* IR type. */
+ , IROp1 o; /* IR opcode. */
+ )
+ LJ_ENDIAN_LOHI(
+ uint8_t r; /* Register allocation (overlaps prev). */
+ , uint8_t s; /* Spill slot allocation (overlaps prev). */
+ )
+ };
+ int32_t i; /* 32 bit signed integer literal (overlaps op12). */
+ GCRef gcr; /* GCobj constant (overlaps op12). */
+ MRef ptr; /* Pointer constant (overlaps op12). */
+} IRIns;
+
+#define ir_kgc(ir) check_exp((ir)->o == IR_KGC, gcref((ir)->gcr))
+#define ir_kstr(ir) (gco2str(ir_kgc((ir))))
+#define ir_ktab(ir) (gco2tab(ir_kgc((ir))))
+#define ir_kfunc(ir) (gco2func(ir_kgc((ir))))
+#define ir_kcdata(ir) (gco2cd(ir_kgc((ir))))
+#define ir_knum(ir) check_exp((ir)->o == IR_KNUM, mref((ir)->ptr, cTValue))
+#define ir_kint64(ir) check_exp((ir)->o == IR_KINT64, mref((ir)->ptr,cTValue))
+#define ir_k64(ir) \
+ check_exp((ir)->o == IR_KNUM || (ir)->o == IR_KINT64, mref((ir)->ptr,cTValue))
+#define ir_kptr(ir) \
+ check_exp((ir)->o == IR_KPTR || (ir)->o == IR_KKPTR, mref((ir)->ptr, void))
+
+/* A store or any other op with a non-weak guard has a side-effect. */
+static LJ_AINLINE int ir_sideeff(IRIns *ir)
+{
+ return (((ir->t.irt | ~IRT_GUARD) & lj_ir_mode[ir->o]) >= IRM_S);
+}
+
+LJ_STATIC_ASSERT((int)IRT_GUARD == (int)IRM_W);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_ircall.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_ircall.h
new file mode 100644
index 0000000..44afde3
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_ircall.h
@@ -0,0 +1,271 @@
+/*
+** IR CALL* instruction definitions.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_IRCALL_H
+#define _LJ_IRCALL_H
+
+#include "lj_obj.h"
+#include "lj_ir.h"
+#include "lj_jit.h"
+
+/* C call info for CALL* instructions. */
+typedef struct CCallInfo {
+ ASMFunction func; /* Function pointer. */
+ uint32_t flags; /* Number of arguments and flags. */
+} CCallInfo;
+
+#define CCI_NARGS(ci) ((ci)->flags & 0xff) /* Extract # of args. */
+#define CCI_NARGS_MAX 32 /* Max. # of args. */
+
+#define CCI_OTSHIFT 16
+#define CCI_OPTYPE(ci) ((ci)->flags >> CCI_OTSHIFT) /* Get op/type. */
+#define CCI_OPSHIFT 24
+#define CCI_OP(ci) ((ci)->flags >> CCI_OPSHIFT) /* Get op. */
+
+#define CCI_CALL_N (IR_CALLN << CCI_OPSHIFT)
+#define CCI_CALL_L (IR_CALLL << CCI_OPSHIFT)
+#define CCI_CALL_S (IR_CALLS << CCI_OPSHIFT)
+#define CCI_CALL_FN (CCI_CALL_N|CCI_CC_FASTCALL)
+#define CCI_CALL_FL (CCI_CALL_L|CCI_CC_FASTCALL)
+#define CCI_CALL_FS (CCI_CALL_S|CCI_CC_FASTCALL)
+
+/* C call info flags. */
+#define CCI_L 0x0100 /* Implicit L arg. */
+#define CCI_CASTU64 0x0200 /* Cast u64 result to number. */
+#define CCI_NOFPRCLOBBER 0x0400 /* Does not clobber any FPRs. */
+#define CCI_VARARG 0x0800 /* Vararg function. */
+
+#define CCI_CC_MASK 0x3000 /* Calling convention mask. */
+#define CCI_CC_SHIFT 12
+/* ORDER CC */
+#define CCI_CC_CDECL 0x0000 /* Default cdecl calling convention. */
+#define CCI_CC_THISCALL 0x1000 /* Thiscall calling convention. */
+#define CCI_CC_FASTCALL 0x2000 /* Fastcall calling convention. */
+#define CCI_CC_STDCALL 0x3000 /* Stdcall calling convention. */
+
+/* Helpers for conditional function definitions. */
+#define IRCALLCOND_ANY(x) x
+
+#if LJ_TARGET_X86ORX64
+#define IRCALLCOND_FPMATH(x) NULL
+#else
+#define IRCALLCOND_FPMATH(x) x
+#endif
+
+#if LJ_SOFTFP
+#define IRCALLCOND_SOFTFP(x) x
+#if LJ_HASFFI
+#define IRCALLCOND_SOFTFP_FFI(x) x
+#else
+#define IRCALLCOND_SOFTFP_FFI(x) NULL
+#endif
+#else
+#define IRCALLCOND_SOFTFP(x) NULL
+#define IRCALLCOND_SOFTFP_FFI(x) NULL
+#endif
+
+#define LJ_NEED_FP64 (LJ_TARGET_ARM || LJ_TARGET_PPC || LJ_TARGET_MIPS)
+
+#if LJ_HASFFI && (LJ_SOFTFP || LJ_NEED_FP64)
+#define IRCALLCOND_FP64_FFI(x) x
+#else
+#define IRCALLCOND_FP64_FFI(x) NULL
+#endif
+
+#if LJ_HASFFI
+#define IRCALLCOND_FFI(x) x
+#if LJ_32
+#define IRCALLCOND_FFI32(x) x
+#else
+#define IRCALLCOND_FFI32(x) NULL
+#endif
+#else
+#define IRCALLCOND_FFI(x) NULL
+#define IRCALLCOND_FFI32(x) NULL
+#endif
+
+#if LJ_SOFTFP
+#define ARG1_FP 2 /* Treat as 2 32 bit arguments. */
+#else
+#define ARG1_FP 1
+#endif
+
+#if LJ_32
+#define ARG2_64 4 /* Treat as 4 32 bit arguments. */
+#else
+#define ARG2_64 2
+#endif
+
+/* Function definitions for CALL* instructions. */
+#define IRCALLDEF(_) \
+ _(ANY, lj_str_cmp, 2, FN, INT, CCI_NOFPRCLOBBER) \
+ _(ANY, lj_str_new, 3, S, STR, CCI_L) \
+ _(ANY, lj_strscan_num, 2, FN, INT, 0) \
+ _(ANY, lj_str_fromint, 2, FN, STR, CCI_L) \
+ _(ANY, lj_str_fromnum, 2, FN, STR, CCI_L) \
+ _(ANY, lj_tab_new1, 2, FS, TAB, CCI_L) \
+ _(ANY, lj_tab_dup, 2, FS, TAB, CCI_L) \
+ _(ANY, lj_tab_newkey, 3, S, P32, CCI_L) \
+ _(ANY, lj_tab_len, 1, FL, INT, 0) \
+ _(ANY, lj_gc_step_jit, 2, FS, NIL, CCI_L) \
+ _(ANY, lj_gc_barrieruv, 2, FS, NIL, 0) \
+ _(ANY, lj_mem_newgco, 2, FS, P32, CCI_L) \
+ _(ANY, lj_math_random_step, 1, FS, NUM, CCI_CASTU64) \
+ _(ANY, lj_vm_modi, 2, FN, INT, 0) \
+ _(ANY, sinh, ARG1_FP, N, NUM, 0) \
+ _(ANY, cosh, ARG1_FP, N, NUM, 0) \
+ _(ANY, tanh, ARG1_FP, N, NUM, 0) \
+ _(ANY, fputc, 2, S, INT, 0) \
+ _(ANY, fwrite, 4, S, INT, 0) \
+ _(ANY, fflush, 1, S, INT, 0) \
+ /* ORDER FPM */ \
+ _(FPMATH, lj_vm_floor, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, lj_vm_ceil, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, lj_vm_trunc, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, sqrt, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, exp, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, lj_vm_exp2, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, log, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, lj_vm_log2, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, log10, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, sin, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, cos, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, tan, ARG1_FP, N, NUM, 0) \
+ _(FPMATH, lj_vm_powi, ARG1_FP+1, N, NUM, 0) \
+ _(FPMATH, pow, ARG1_FP*2, N, NUM, 0) \
+ _(FPMATH, atan2, ARG1_FP*2, N, NUM, 0) \
+ _(FPMATH, ldexp, ARG1_FP+1, N, NUM, 0) \
+ _(SOFTFP, lj_vm_tobit, 2, N, INT, 0) \
+ _(SOFTFP, softfp_add, 4, N, NUM, 0) \
+ _(SOFTFP, softfp_sub, 4, N, NUM, 0) \
+ _(SOFTFP, softfp_mul, 4, N, NUM, 0) \
+ _(SOFTFP, softfp_div, 4, N, NUM, 0) \
+ _(SOFTFP, softfp_cmp, 4, N, NIL, 0) \
+ _(SOFTFP, softfp_i2d, 1, N, NUM, 0) \
+ _(SOFTFP, softfp_d2i, 2, N, INT, 0) \
+ _(SOFTFP_FFI, softfp_ui2d, 1, N, NUM, 0) \
+ _(SOFTFP_FFI, softfp_f2d, 1, N, NUM, 0) \
+ _(SOFTFP_FFI, softfp_d2ui, 2, N, INT, 0) \
+ _(SOFTFP_FFI, softfp_d2f, 2, N, FLOAT, 0) \
+ _(SOFTFP_FFI, softfp_i2f, 1, N, FLOAT, 0) \
+ _(SOFTFP_FFI, softfp_ui2f, 1, N, FLOAT, 0) \
+ _(SOFTFP_FFI, softfp_f2i, 1, N, INT, 0) \
+ _(SOFTFP_FFI, softfp_f2ui, 1, N, INT, 0) \
+ _(FP64_FFI, fp64_l2d, 2, N, NUM, 0) \
+ _(FP64_FFI, fp64_ul2d, 2, N, NUM, 0) \
+ _(FP64_FFI, fp64_l2f, 2, N, FLOAT, 0) \
+ _(FP64_FFI, fp64_ul2f, 2, N, FLOAT, 0) \
+ _(FP64_FFI, fp64_d2l, ARG1_FP, N, I64, 0) \
+ _(FP64_FFI, fp64_d2ul, ARG1_FP, N, U64, 0) \
+ _(FP64_FFI, fp64_f2l, 1, N, I64, 0) \
+ _(FP64_FFI, fp64_f2ul, 1, N, U64, 0) \
+ _(FFI, lj_carith_divi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \
+ _(FFI, lj_carith_divu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \
+ _(FFI, lj_carith_modi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \
+ _(FFI, lj_carith_modu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \
+ _(FFI, lj_carith_powi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \
+ _(FFI, lj_carith_powu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \
+ _(FFI, lj_cdata_setfin, 2, FN, P32, CCI_L) \
+ _(FFI, strlen, 1, L, INTP, 0) \
+ _(FFI, memcpy, 3, S, PTR, 0) \
+ _(FFI, memset, 3, S, PTR, 0) \
+ _(FFI, lj_vm_errno, 0, S, INT, CCI_NOFPRCLOBBER) \
+ _(FFI32, lj_carith_mul64, ARG2_64, N, I64, CCI_NOFPRCLOBBER)
+ \
+ /* End of list. */
+
+typedef enum {
+#define IRCALLENUM(cond, name, nargs, kind, type, flags) IRCALL_##name,
+IRCALLDEF(IRCALLENUM)
+#undef IRCALLENUM
+ IRCALL__MAX
+} IRCallID;
+
+LJ_FUNC TRef lj_ir_call(jit_State *J, IRCallID id, ...);
+
+LJ_DATA const CCallInfo lj_ir_callinfo[IRCALL__MAX+1];
+
+/* Soft-float declarations. */
+#if LJ_SOFTFP
+#if LJ_TARGET_ARM
+#define softfp_add __aeabi_dadd
+#define softfp_sub __aeabi_dsub
+#define softfp_mul __aeabi_dmul
+#define softfp_div __aeabi_ddiv
+#define softfp_cmp __aeabi_cdcmple
+#define softfp_i2d __aeabi_i2d
+#define softfp_d2i __aeabi_d2iz
+#define softfp_ui2d __aeabi_ui2d
+#define softfp_f2d __aeabi_f2d
+#define softfp_d2ui __aeabi_d2uiz
+#define softfp_d2f __aeabi_d2f
+#define softfp_i2f __aeabi_i2f
+#define softfp_ui2f __aeabi_ui2f
+#define softfp_f2i __aeabi_f2iz
+#define softfp_f2ui __aeabi_f2uiz
+#define fp64_l2d __aeabi_l2d
+#define fp64_ul2d __aeabi_ul2d
+#define fp64_l2f __aeabi_l2f
+#define fp64_ul2f __aeabi_ul2f
+#if LJ_TARGET_IOS
+#define fp64_d2l __fixdfdi
+#define fp64_d2ul __fixunsdfdi
+#define fp64_f2l __fixsfdi
+#define fp64_f2ul __fixunssfdi
+#else
+#define fp64_d2l __aeabi_d2lz
+#define fp64_d2ul __aeabi_d2ulz
+#define fp64_f2l __aeabi_f2lz
+#define fp64_f2ul __aeabi_f2ulz
+#endif
+#else
+#error "Missing soft-float definitions for target architecture"
+#endif
+extern double softfp_add(double a, double b);
+extern double softfp_sub(double a, double b);
+extern double softfp_mul(double a, double b);
+extern double softfp_div(double a, double b);
+extern void softfp_cmp(double a, double b);
+extern double softfp_i2d(int32_t a);
+extern int32_t softfp_d2i(double a);
+#if LJ_HASFFI
+extern double softfp_ui2d(uint32_t a);
+extern double softfp_f2d(float a);
+extern uint32_t softfp_d2ui(double a);
+extern float softfp_d2f(double a);
+extern float softfp_i2f(int32_t a);
+extern float softfp_ui2f(uint32_t a);
+extern int32_t softfp_f2i(float a);
+extern uint32_t softfp_f2ui(float a);
+#endif
+#endif
+
+#if LJ_HASFFI && LJ_NEED_FP64 && !(LJ_TARGET_ARM && LJ_SOFTFP)
+#ifdef __GNUC__
+#define fp64_l2d __floatdidf
+#define fp64_ul2d __floatundidf
+#define fp64_l2f __floatdisf
+#define fp64_ul2f __floatundisf
+#define fp64_d2l __fixdfdi
+#define fp64_d2ul __fixunsdfdi
+#define fp64_f2l __fixsfdi
+#define fp64_f2ul __fixunssfdi
+#else
+#error "Missing fp64 helper definitions for this compiler"
+#endif
+#endif
+
+#if LJ_HASFFI && (LJ_SOFTFP || LJ_NEED_FP64)
+extern double fp64_l2d(int64_t a);
+extern double fp64_ul2d(uint64_t a);
+extern float fp64_l2f(int64_t a);
+extern float fp64_ul2f(uint64_t a);
+extern int64_t fp64_d2l(double a);
+extern uint64_t fp64_d2ul(double a);
+extern int64_t fp64_f2l(float a);
+extern uint64_t fp64_f2ul(float a);
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_iropt.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_iropt.h
new file mode 100644
index 0000000..b5081e0
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_iropt.h
@@ -0,0 +1,161 @@
+/*
+** Common header for IR emitter and optimizations.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_IROPT_H
+#define _LJ_IROPT_H
+
+#include <stdarg.h>
+
+#include "lj_obj.h"
+#include "lj_jit.h"
+
+#if LJ_HASJIT
+/* IR emitter. */
+LJ_FUNC void LJ_FASTCALL lj_ir_growtop(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_ir_emit(jit_State *J);
+
+/* Save current IR in J->fold.ins, but do not emit it (yet). */
+static LJ_AINLINE void lj_ir_set_(jit_State *J, uint16_t ot, IRRef1 a, IRRef1 b)
+{
+ J->fold.ins.ot = ot; J->fold.ins.op1 = a; J->fold.ins.op2 = b;
+}
+
+#define lj_ir_set(J, ot, a, b) \
+ lj_ir_set_(J, (uint16_t)(ot), (IRRef1)(a), (IRRef1)(b))
+
+/* Get ref of next IR instruction and optionally grow IR.
+** Note: this may invalidate all IRIns*!
+*/
+static LJ_AINLINE IRRef lj_ir_nextins(jit_State *J)
+{
+ IRRef ref = J->cur.nins;
+ if (LJ_UNLIKELY(ref >= J->irtoplim)) lj_ir_growtop(J);
+ J->cur.nins = ref + 1;
+ return ref;
+}
+
+/* Interning of constants. */
+LJ_FUNC TRef LJ_FASTCALL lj_ir_kint(jit_State *J, int32_t k);
+LJ_FUNC void lj_ir_k64_freeall(jit_State *J);
+LJ_FUNC TRef lj_ir_k64(jit_State *J, IROp op, cTValue *tv);
+LJ_FUNC cTValue *lj_ir_k64_find(jit_State *J, uint64_t u64);
+LJ_FUNC TRef lj_ir_knum_u64(jit_State *J, uint64_t u64);
+LJ_FUNC TRef lj_ir_knumint(jit_State *J, lua_Number n);
+LJ_FUNC TRef lj_ir_kint64(jit_State *J, uint64_t u64);
+LJ_FUNC TRef lj_ir_kgc(jit_State *J, GCobj *o, IRType t);
+LJ_FUNC TRef lj_ir_kptr_(jit_State *J, IROp op, void *ptr);
+LJ_FUNC TRef lj_ir_knull(jit_State *J, IRType t);
+LJ_FUNC TRef lj_ir_kslot(jit_State *J, TRef key, IRRef slot);
+
+#if LJ_64
+#define lj_ir_kintp(J, k) lj_ir_kint64(J, (uint64_t)(k))
+#else
+#define lj_ir_kintp(J, k) lj_ir_kint(J, (int32_t)(k))
+#endif
+
+static LJ_AINLINE TRef lj_ir_knum(jit_State *J, lua_Number n)
+{
+ TValue tv;
+ tv.n = n;
+ return lj_ir_knum_u64(J, tv.u64);
+}
+
+#define lj_ir_kstr(J, str) lj_ir_kgc(J, obj2gco((str)), IRT_STR)
+#define lj_ir_ktab(J, tab) lj_ir_kgc(J, obj2gco((tab)), IRT_TAB)
+#define lj_ir_kfunc(J, func) lj_ir_kgc(J, obj2gco((func)), IRT_FUNC)
+#define lj_ir_kptr(J, ptr) lj_ir_kptr_(J, IR_KPTR, (ptr))
+#define lj_ir_kkptr(J, ptr) lj_ir_kptr_(J, IR_KKPTR, (ptr))
+
+/* Special FP constants. */
+#define lj_ir_knum_zero(J) lj_ir_knum_u64(J, U64x(00000000,00000000))
+#define lj_ir_knum_one(J) lj_ir_knum_u64(J, U64x(3ff00000,00000000))
+#define lj_ir_knum_tobit(J) lj_ir_knum_u64(J, U64x(43380000,00000000))
+
+/* Special 128 bit SIMD constants. */
+#define lj_ir_knum_abs(J) lj_ir_k64(J, IR_KNUM, LJ_KSIMD(J, LJ_KSIMD_ABS))
+#define lj_ir_knum_neg(J) lj_ir_k64(J, IR_KNUM, LJ_KSIMD(J, LJ_KSIMD_NEG))
+
+/* Access to constants. */
+LJ_FUNC void lj_ir_kvalue(lua_State *L, TValue *tv, const IRIns *ir);
+
+/* Convert IR operand types. */
+LJ_FUNC TRef LJ_FASTCALL lj_ir_tonumber(jit_State *J, TRef tr);
+LJ_FUNC TRef LJ_FASTCALL lj_ir_tonum(jit_State *J, TRef tr);
+LJ_FUNC TRef LJ_FASTCALL lj_ir_tostr(jit_State *J, TRef tr);
+
+/* Miscellaneous IR ops. */
+LJ_FUNC int lj_ir_numcmp(lua_Number a, lua_Number b, IROp op);
+LJ_FUNC int lj_ir_strcmp(GCstr *a, GCstr *b, IROp op);
+LJ_FUNC void lj_ir_rollback(jit_State *J, IRRef ref);
+
+/* Emit IR instructions with on-the-fly optimizations. */
+LJ_FUNC TRef LJ_FASTCALL lj_opt_fold(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_cse(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_cselim(jit_State *J, IRRef lim);
+
+/* Special return values for the fold functions. */
+enum {
+ NEXTFOLD, /* Couldn't fold, pass on. */
+ RETRYFOLD, /* Retry fold with modified fins. */
+ KINTFOLD, /* Return ref for int constant in fins->i. */
+ FAILFOLD, /* Guard would always fail. */
+ DROPFOLD, /* Guard eliminated. */
+ MAX_FOLD
+};
+
+#define INTFOLD(k) ((J->fold.ins.i = (k)), (TRef)KINTFOLD)
+#define INT64FOLD(k) (lj_ir_kint64(J, (k)))
+#define CONDFOLD(cond) ((TRef)FAILFOLD + (TRef)(cond))
+#define LEFTFOLD (J->fold.ins.op1)
+#define RIGHTFOLD (J->fold.ins.op2)
+#define CSEFOLD (lj_opt_cse(J))
+#define EMITFOLD (lj_ir_emit(J))
+
+/* Load/store forwarding. */
+LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_aload(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_hload(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_uload(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_fload(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_xload(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_tab_len(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_fwd_hrefk(jit_State *J);
+LJ_FUNC int LJ_FASTCALL lj_opt_fwd_href_nokey(jit_State *J);
+LJ_FUNC int LJ_FASTCALL lj_opt_fwd_tptr(jit_State *J, IRRef lim);
+LJ_FUNC int lj_opt_fwd_wasnonnil(jit_State *J, IROpT loadop, IRRef xref);
+
+/* Dead-store elimination. */
+LJ_FUNC TRef LJ_FASTCALL lj_opt_dse_ahstore(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_dse_ustore(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_dse_fstore(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_dse_xstore(jit_State *J);
+
+/* Narrowing. */
+LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_convert(jit_State *J);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_index(jit_State *J, TRef key);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_toint(jit_State *J, TRef tr);
+LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_tobit(jit_State *J, TRef tr);
+#if LJ_HASFFI
+LJ_FUNC TRef LJ_FASTCALL lj_opt_narrow_cindex(jit_State *J, TRef key);
+#endif
+LJ_FUNC TRef lj_opt_narrow_arith(jit_State *J, TRef rb, TRef rc,
+ TValue *vb, TValue *vc, IROp op);
+LJ_FUNC TRef lj_opt_narrow_unm(jit_State *J, TRef rc, TValue *vc);
+LJ_FUNC TRef lj_opt_narrow_mod(jit_State *J, TRef rb, TRef rc, TValue *vb, TValue *vc);
+LJ_FUNC TRef lj_opt_narrow_pow(jit_State *J, TRef rb, TRef rc, TValue *vb, TValue *vc);
+LJ_FUNC IRType lj_opt_narrow_forl(jit_State *J, cTValue *forbase);
+
+/* Optimization passes. */
+LJ_FUNC void lj_opt_dce(jit_State *J);
+LJ_FUNC int lj_opt_loop(jit_State *J);
+#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI)
+LJ_FUNC void lj_opt_split(jit_State *J);
+#else
+#define lj_opt_split(J) UNUSED(J)
+#endif
+LJ_FUNC void lj_opt_sink(jit_State *J);
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_jit.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_jit.h
new file mode 100644
index 0000000..3f38d28
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_jit.h
@@ -0,0 +1,423 @@
+/*
+** Common definitions for the JIT compiler.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_JIT_H
+#define _LJ_JIT_H
+
+#include "lj_obj.h"
+#include "lj_ir.h"
+
+/* JIT engine flags. */
+#define JIT_F_ON 0x00000001
+
+/* CPU-specific JIT engine flags. */
+#if LJ_TARGET_X86ORX64
+#define JIT_F_CMOV 0x00000010
+#define JIT_F_SSE2 0x00000020
+#define JIT_F_SSE3 0x00000040
+#define JIT_F_SSE4_1 0x00000080
+#define JIT_F_P4 0x00000100
+#define JIT_F_PREFER_IMUL 0x00000200
+#define JIT_F_SPLIT_XMM 0x00000400
+#define JIT_F_LEA_AGU 0x00000800
+
+/* Names for the CPU-specific flags. Must match the order above. */
+#define JIT_F_CPU_FIRST JIT_F_CMOV
+#define JIT_F_CPUSTRING "\4CMOV\4SSE2\4SSE3\6SSE4.1\2P4\3AMD\2K8\4ATOM"
+#elif LJ_TARGET_ARM
+#define JIT_F_ARMV6_ 0x00000010
+#define JIT_F_ARMV6T2_ 0x00000020
+#define JIT_F_ARMV7 0x00000040
+#define JIT_F_VFPV2 0x00000080
+#define JIT_F_VFPV3 0x00000100
+
+#define JIT_F_ARMV6 (JIT_F_ARMV6_|JIT_F_ARMV6T2_|JIT_F_ARMV7)
+#define JIT_F_ARMV6T2 (JIT_F_ARMV6T2_|JIT_F_ARMV7)
+#define JIT_F_VFP (JIT_F_VFPV2|JIT_F_VFPV3)
+
+/* Names for the CPU-specific flags. Must match the order above. */
+#define JIT_F_CPU_FIRST JIT_F_ARMV6_
+#define JIT_F_CPUSTRING "\5ARMv6\7ARMv6T2\5ARMv7\5VFPv2\5VFPv3"
+#elif LJ_TARGET_PPC
+#define JIT_F_SQRT 0x00000010
+#define JIT_F_ROUND 0x00000020
+
+/* Names for the CPU-specific flags. Must match the order above. */
+#define JIT_F_CPU_FIRST JIT_F_SQRT
+#define JIT_F_CPUSTRING "\4SQRT\5ROUND"
+#elif LJ_TARGET_MIPS
+#define JIT_F_MIPS32R2 0x00000010
+
+/* Names for the CPU-specific flags. Must match the order above. */
+#define JIT_F_CPU_FIRST JIT_F_MIPS32R2
+#define JIT_F_CPUSTRING "\010MIPS32R2"
+#else
+#define JIT_F_CPU_FIRST 0
+#define JIT_F_CPUSTRING ""
+#endif
+
+/* Optimization flags. */
+#define JIT_F_OPT_MASK 0x0fff0000
+
+#define JIT_F_OPT_FOLD 0x00010000
+#define JIT_F_OPT_CSE 0x00020000
+#define JIT_F_OPT_DCE 0x00040000
+#define JIT_F_OPT_FWD 0x00080000
+#define JIT_F_OPT_DSE 0x00100000
+#define JIT_F_OPT_NARROW 0x00200000
+#define JIT_F_OPT_LOOP 0x00400000
+#define JIT_F_OPT_ABC 0x00800000
+#define JIT_F_OPT_SINK 0x01000000
+#define JIT_F_OPT_FUSE 0x02000000
+
+/* Optimizations names for -O. Must match the order above. */
+#define JIT_F_OPT_FIRST JIT_F_OPT_FOLD
+#define JIT_F_OPTSTRING \
+ "\4fold\3cse\3dce\3fwd\3dse\6narrow\4loop\3abc\4sink\4fuse"
+
+/* Optimization levels set a fixed combination of flags. */
+#define JIT_F_OPT_0 0
+#define JIT_F_OPT_1 (JIT_F_OPT_FOLD|JIT_F_OPT_CSE|JIT_F_OPT_DCE)
+#define JIT_F_OPT_2 (JIT_F_OPT_1|JIT_F_OPT_NARROW|JIT_F_OPT_LOOP)
+#define JIT_F_OPT_3 (JIT_F_OPT_2|\
+ JIT_F_OPT_FWD|JIT_F_OPT_DSE|JIT_F_OPT_ABC|JIT_F_OPT_SINK|JIT_F_OPT_FUSE)
+#define JIT_F_OPT_DEFAULT JIT_F_OPT_3
+
+#if LJ_TARGET_WINDOWS || LJ_64
+/* See: http://blogs.msdn.com/oldnewthing/archive/2003/10/08/55239.aspx */
+#define JIT_P_sizemcode_DEFAULT 64
+#else
+/* Could go as low as 4K, but the mmap() overhead would be rather high. */
+#define JIT_P_sizemcode_DEFAULT 32
+#endif
+
+/* Optimization parameters and their defaults. Length is a char in octal! */
+#define JIT_PARAMDEF(_) \
+ _(\010, maxtrace, 1000) /* Max. # of traces in cache. */ \
+ _(\011, maxrecord, 4000) /* Max. # of recorded IR instructions. */ \
+ _(\012, maxirconst, 500) /* Max. # of IR constants of a trace. */ \
+ _(\007, maxside, 100) /* Max. # of side traces of a root trace. */ \
+ _(\007, maxsnap, 500) /* Max. # of snapshots for a trace. */ \
+ \
+ _(\007, hotloop, 56) /* # of iter. to detect a hot loop/call. */ \
+ _(\007, hotexit, 10) /* # of taken exits to start a side trace. */ \
+ _(\007, tryside, 4) /* # of attempts to compile a side trace. */ \
+ \
+ _(\012, instunroll, 4) /* Max. unroll for instable loops. */ \
+ _(\012, loopunroll, 15) /* Max. unroll for loop ops in side traces. */ \
+ _(\012, callunroll, 3) /* Max. unroll for recursive calls. */ \
+ _(\011, recunroll, 2) /* Min. unroll for true recursion. */ \
+ \
+ /* Size of each machine code area (in KBytes). */ \
+ _(\011, sizemcode, JIT_P_sizemcode_DEFAULT) \
+ /* Max. total size of all machine code areas (in KBytes). */ \
+ _(\010, maxmcode, 512) \
+ /* End of list. */
+
+enum {
+#define JIT_PARAMENUM(len, name, value) JIT_P_##name,
+JIT_PARAMDEF(JIT_PARAMENUM)
+#undef JIT_PARAMENUM
+ JIT_P__MAX
+};
+
+#define JIT_PARAMSTR(len, name, value) #len #name
+#define JIT_P_STRING JIT_PARAMDEF(JIT_PARAMSTR)
+
+/* Trace compiler state. */
+typedef enum {
+ LJ_TRACE_IDLE, /* Trace compiler idle. */
+ LJ_TRACE_ACTIVE = 0x10,
+ LJ_TRACE_RECORD, /* Bytecode recording active. */
+ LJ_TRACE_START, /* New trace started. */
+ LJ_TRACE_END, /* End of trace. */
+ LJ_TRACE_ASM, /* Assemble trace. */
+ LJ_TRACE_ERR /* Trace aborted with error. */
+} TraceState;
+
+/* Post-processing action. */
+typedef enum {
+ LJ_POST_NONE, /* No action. */
+ LJ_POST_FIXCOMP, /* Fixup comparison and emit pending guard. */
+ LJ_POST_FIXGUARD, /* Fixup and emit pending guard. */
+ LJ_POST_FIXGUARDSNAP, /* Fixup and emit pending guard and snapshot. */
+ LJ_POST_FIXBOOL, /* Fixup boolean result. */
+ LJ_POST_FIXCONST, /* Fixup constant results. */
+ LJ_POST_FFRETRY /* Suppress recording of retried fast functions. */
+} PostProc;
+
+/* Machine code type. */
+#if LJ_TARGET_X86ORX64
+typedef uint8_t MCode;
+#else
+typedef uint32_t MCode;
+#endif
+
+/* Linked list of MCode areas. */
+typedef struct MCLink {
+ MCode *next; /* Next area. */
+ size_t size; /* Size of current area. */
+} MCLink;
+
+/* Stack snapshot header. */
+typedef struct SnapShot {
+ uint16_t mapofs; /* Offset into snapshot map. */
+ IRRef1 ref; /* First IR ref for this snapshot. */
+ uint8_t nslots; /* Number of valid slots. */
+ uint8_t topslot; /* Maximum frame extent. */
+ uint8_t nent; /* Number of compressed entries. */
+ uint8_t count; /* Count of taken exits for this snapshot. */
+} SnapShot;
+
+#define SNAPCOUNT_DONE 255 /* Already compiled and linked a side trace. */
+
+/* Compressed snapshot entry. */
+typedef uint32_t SnapEntry;
+
+#define SNAP_FRAME 0x010000 /* Frame slot. */
+#define SNAP_CONT 0x020000 /* Continuation slot. */
+#define SNAP_NORESTORE 0x040000 /* No need to restore slot. */
+#define SNAP_SOFTFPNUM 0x080000 /* Soft-float number. */
+LJ_STATIC_ASSERT(SNAP_FRAME == TREF_FRAME);
+LJ_STATIC_ASSERT(SNAP_CONT == TREF_CONT);
+
+#define SNAP(slot, flags, ref) (((SnapEntry)(slot) << 24) + (flags) + (ref))
+#define SNAP_TR(slot, tr) \
+ (((SnapEntry)(slot) << 24) + ((tr) & (TREF_CONT|TREF_FRAME|TREF_REFMASK)))
+#define SNAP_MKPC(pc) ((SnapEntry)u32ptr(pc))
+#define SNAP_MKFTSZ(ftsz) ((SnapEntry)(ftsz))
+#define snap_ref(sn) ((sn) & 0xffff)
+#define snap_slot(sn) ((BCReg)((sn) >> 24))
+#define snap_isframe(sn) ((sn) & SNAP_FRAME)
+#define snap_pc(sn) ((const BCIns *)(uintptr_t)(sn))
+#define snap_setref(sn, ref) (((sn) & (0xffff0000&~SNAP_NORESTORE)) | (ref))
+
+/* Snapshot and exit numbers. */
+typedef uint32_t SnapNo;
+typedef uint32_t ExitNo;
+
+/* Trace number. */
+typedef uint32_t TraceNo; /* Used to pass around trace numbers. */
+typedef uint16_t TraceNo1; /* Stored trace number. */
+
+/* Type of link. ORDER LJ_TRLINK */
+typedef enum {
+ LJ_TRLINK_NONE, /* Incomplete trace. No link, yet. */
+ LJ_TRLINK_ROOT, /* Link to other root trace. */
+ LJ_TRLINK_LOOP, /* Loop to same trace. */
+ LJ_TRLINK_TAILREC, /* Tail-recursion. */
+ LJ_TRLINK_UPREC, /* Up-recursion. */
+ LJ_TRLINK_DOWNREC, /* Down-recursion. */
+ LJ_TRLINK_INTERP, /* Fallback to interpreter. */
+ LJ_TRLINK_RETURN /* Return to interpreter. */
+} TraceLink;
+
+/* Trace object. */
+typedef struct GCtrace {
+ GCHeader;
+ uint8_t topslot; /* Top stack slot already checked to be allocated. */
+ uint8_t linktype; /* Type of link. */
+ IRRef nins; /* Next IR instruction. Biased with REF_BIAS. */
+ GCRef gclist;
+ IRIns *ir; /* IR instructions/constants. Biased with REF_BIAS. */
+ IRRef nk; /* Lowest IR constant. Biased with REF_BIAS. */
+ uint16_t nsnap; /* Number of snapshots. */
+ uint16_t nsnapmap; /* Number of snapshot map elements. */
+ SnapShot *snap; /* Snapshot array. */
+ SnapEntry *snapmap; /* Snapshot map. */
+ GCRef startpt; /* Starting prototype. */
+ MRef startpc; /* Bytecode PC of starting instruction. */
+ BCIns startins; /* Original bytecode of starting instruction. */
+ MSize szmcode; /* Size of machine code. */
+ MCode *mcode; /* Start of machine code. */
+ MSize mcloop; /* Offset of loop start in machine code. */
+ uint16_t nchild; /* Number of child traces (root trace only). */
+ uint16_t spadjust; /* Stack pointer adjustment (offset in bytes). */
+ TraceNo1 traceno; /* Trace number. */
+ TraceNo1 link; /* Linked trace (or self for loops). */
+ TraceNo1 root; /* Root trace of side trace (or 0 for root traces). */
+ TraceNo1 nextroot; /* Next root trace for same prototype. */
+ TraceNo1 nextside; /* Next side trace of same root trace. */
+ uint8_t sinktags; /* Trace has SINK tags. */
+ uint8_t unused1;
+#ifdef LUAJIT_USE_GDBJIT
+ void *gdbjit_entry; /* GDB JIT entry. */
+#endif
+} GCtrace;
+
+#define gco2trace(o) check_exp((o)->gch.gct == ~LJ_TTRACE, (GCtrace *)(o))
+#define traceref(J, n) \
+ check_exp((n)>0 && (MSize)(n)<J->sizetrace, (GCtrace *)gcref(J->trace[(n)]))
+
+LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCtrace, gclist));
+
+static LJ_AINLINE MSize snap_nextofs(GCtrace *T, SnapShot *snap)
+{
+ if (snap+1 == &T->snap[T->nsnap])
+ return T->nsnapmap;
+ else
+ return (snap+1)->mapofs;
+}
+
+/* Round-robin penalty cache for bytecodes leading to aborted traces. */
+typedef struct HotPenalty {
+ MRef pc; /* Starting bytecode PC. */
+ uint16_t val; /* Penalty value, i.e. hotcount start. */
+ uint16_t reason; /* Abort reason (really TraceErr). */
+} HotPenalty;
+
+#define PENALTY_SLOTS 64 /* Penalty cache slot. Must be a power of 2. */
+#define PENALTY_MIN (36*2) /* Minimum penalty value. */
+#define PENALTY_MAX 60000 /* Maximum penalty value. */
+#define PENALTY_RNDBITS 4 /* # of random bits to add to penalty value. */
+
+/* Round-robin backpropagation cache for narrowing conversions. */
+typedef struct BPropEntry {
+ IRRef1 key; /* Key: original reference. */
+ IRRef1 val; /* Value: reference after conversion. */
+ IRRef mode; /* Mode for this entry (currently IRCONV_*). */
+} BPropEntry;
+
+/* Number of slots for the backpropagation cache. Must be a power of 2. */
+#define BPROP_SLOTS 16
+
+/* Scalar evolution analysis cache. */
+typedef struct ScEvEntry {
+ MRef pc; /* Bytecode PC of FORI. */
+ IRRef1 idx; /* Index reference. */
+ IRRef1 start; /* Constant start reference. */
+ IRRef1 stop; /* Constant stop reference. */
+ IRRef1 step; /* Constant step reference. */
+ IRType1 t; /* Scalar type. */
+ uint8_t dir; /* Direction. 1: +, 0: -. */
+} ScEvEntry;
+
+/* 128 bit SIMD constants. */
+enum {
+ LJ_KSIMD_ABS,
+ LJ_KSIMD_NEG,
+ LJ_KSIMD__MAX
+};
+
+/* Get 16 byte aligned pointer to SIMD constant. */
+#define LJ_KSIMD(J, n) \
+ ((TValue *)(((intptr_t)&J->ksimd[2*(n)] + 15) & ~(intptr_t)15))
+
+/* Set/reset flag to activate the SPLIT pass for the current trace. */
+#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI)
+#define lj_needsplit(J) (J->needsplit = 1)
+#define lj_resetsplit(J) (J->needsplit = 0)
+#else
+#define lj_needsplit(J) UNUSED(J)
+#define lj_resetsplit(J) UNUSED(J)
+#endif
+
+/* Fold state is used to fold instructions on-the-fly. */
+typedef struct FoldState {
+ IRIns ins; /* Currently emitted instruction. */
+ IRIns left; /* Instruction referenced by left operand. */
+ IRIns right; /* Instruction referenced by right operand. */
+} FoldState;
+
+/* JIT compiler state. */
+typedef struct jit_State {
+ GCtrace cur; /* Current trace. */
+
+ lua_State *L; /* Current Lua state. */
+ const BCIns *pc; /* Current PC. */
+ GCfunc *fn; /* Current function. */
+ GCproto *pt; /* Current prototype. */
+ TRef *base; /* Current frame base, points into J->slots. */
+
+ uint32_t flags; /* JIT engine flags. */
+ BCReg maxslot; /* Relative to baseslot. */
+ BCReg baseslot; /* Current frame base, offset into J->slots. */
+
+ uint8_t mergesnap; /* Allowed to merge with next snapshot. */
+ uint8_t needsnap; /* Need snapshot before recording next bytecode. */
+ IRType1 guardemit; /* Accumulated IRT_GUARD for emitted instructions. */
+ uint8_t bcskip; /* Number of bytecode instructions to skip. */
+
+ FoldState fold; /* Fold state. */
+
+ const BCIns *bc_min; /* Start of allowed bytecode range for root trace. */
+ MSize bc_extent; /* Extent of the range. */
+
+ TraceState state; /* Trace compiler state. */
+
+ int32_t instunroll; /* Unroll counter for instable loops. */
+ int32_t loopunroll; /* Unroll counter for loop ops in side traces. */
+ int32_t tailcalled; /* Number of successive tailcalls. */
+ int32_t framedepth; /* Current frame depth. */
+ int32_t retdepth; /* Return frame depth (count of RETF). */
+
+ MRef k64; /* Pointer to chained array of 64 bit constants. */
+ TValue ksimd[LJ_KSIMD__MAX*2+1]; /* 16 byte aligned SIMD constants. */
+
+ IRIns *irbuf; /* Temp. IR instruction buffer. Biased with REF_BIAS. */
+ IRRef irtoplim; /* Upper limit of instuction buffer (biased). */
+ IRRef irbotlim; /* Lower limit of instuction buffer (biased). */
+ IRRef loopref; /* Last loop reference or ref of final LOOP (or 0). */
+
+ MSize sizesnap; /* Size of temp. snapshot buffer. */
+ SnapShot *snapbuf; /* Temp. snapshot buffer. */
+ SnapEntry *snapmapbuf; /* Temp. snapshot map buffer. */
+ MSize sizesnapmap; /* Size of temp. snapshot map buffer. */
+
+ PostProc postproc; /* Required post-processing after execution. */
+#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI)
+ int needsplit; /* Need SPLIT pass. */
+#endif
+
+ GCRef *trace; /* Array of traces. */
+ TraceNo freetrace; /* Start of scan for next free trace. */
+ MSize sizetrace; /* Size of trace array. */
+
+ IRRef1 chain[IR__MAX]; /* IR instruction skip-list chain anchors. */
+ TRef slot[LJ_MAX_JSLOTS+LJ_STACK_EXTRA]; /* Stack slot map. */
+
+ int32_t param[JIT_P__MAX]; /* JIT engine parameters. */
+
+ MCode *exitstubgroup[LJ_MAX_EXITSTUBGR]; /* Exit stub group addresses. */
+
+ HotPenalty penalty[PENALTY_SLOTS]; /* Penalty slots. */
+ uint32_t penaltyslot; /* Round-robin index into penalty slots. */
+ uint32_t prngstate; /* PRNG state. */
+
+ BPropEntry bpropcache[BPROP_SLOTS]; /* Backpropagation cache slots. */
+ uint32_t bpropslot; /* Round-robin index into bpropcache slots. */
+
+ ScEvEntry scev; /* Scalar evolution analysis cache slots. */
+
+ const BCIns *startpc; /* Bytecode PC of starting instruction. */
+ TraceNo parent; /* Parent of current side trace (0 for root traces). */
+ ExitNo exitno; /* Exit number in parent of current side trace. */
+
+ BCIns *patchpc; /* PC for pending re-patch. */
+ BCIns patchins; /* Instruction for pending re-patch. */
+
+ int mcprot; /* Protection of current mcode area. */
+ MCode *mcarea; /* Base of current mcode area. */
+ MCode *mctop; /* Top of current mcode area. */
+ MCode *mcbot; /* Bottom of current mcode area. */
+ size_t szmcarea; /* Size of current mcode area. */
+ size_t szallmcarea; /* Total size of all allocated mcode areas. */
+
+ TValue errinfo; /* Additional info element for trace errors. */
+}
+#if LJ_TARGET_ARM
+LJ_ALIGN(16) /* For DISPATCH-relative addresses in assembler part. */
+#endif
+jit_State;
+
+/* Trivial PRNG e.g. used for penalty randomization. */
+static LJ_AINLINE uint32_t LJ_PRNG_BITS(jit_State *J, int bits)
+{
+ /* Yes, this LCG is very weak, but that doesn't matter for our use case. */
+ J->prngstate = J->prngstate * 1103515245 + 12345;
+ return J->prngstate >> (32-bits);
+}
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_lex.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_lex.c
new file mode 100644
index 0000000..3660316
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_lex.c
@@ -0,0 +1,482 @@
+/*
+** Lexical analyzer.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Major portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#define lj_lex_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_str.h"
+#if LJ_HASFFI
+#include "lj_tab.h"
+#include "lj_ctype.h"
+#include "lj_cdata.h"
+#include "lualib.h"
+#endif
+#include "lj_state.h"
+#include "lj_lex.h"
+#include "lj_parse.h"
+#include "lj_char.h"
+#include "lj_strscan.h"
+
+/* Lua lexer token names. */
+static const char *const tokennames[] = {
+#define TKSTR1(name) #name,
+#define TKSTR2(name, sym) #sym,
+TKDEF(TKSTR1, TKSTR2)
+#undef TKSTR1
+#undef TKSTR2
+ NULL
+};
+
+/* -- Buffer handling ----------------------------------------------------- */
+
+#define char2int(c) ((int)(uint8_t)(c))
+#define next(ls) \
+ (ls->current = (ls->n--) > 0 ? char2int(*ls->p++) : fillbuf(ls))
+#define save_and_next(ls) (save(ls, ls->current), next(ls))
+#define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r')
+#define END_OF_STREAM (-1)
+
+static int fillbuf(LexState *ls)
+{
+ size_t sz;
+ const char *buf = ls->rfunc(ls->L, ls->rdata, &sz);
+ if (buf == NULL || sz == 0) return END_OF_STREAM;
+ ls->n = (MSize)sz - 1;
+ ls->p = buf;
+ return char2int(*(ls->p++));
+}
+
+static LJ_NOINLINE void save_grow(LexState *ls, int c)
+{
+ MSize newsize;
+ if (ls->sb.sz >= LJ_MAX_STR/2)
+ lj_lex_error(ls, 0, LJ_ERR_XELEM);
+ newsize = ls->sb.sz * 2;
+ lj_str_resizebuf(ls->L, &ls->sb, newsize);
+ ls->sb.buf[ls->sb.n++] = (char)c;
+}
+
+static LJ_AINLINE void save(LexState *ls, int c)
+{
+ if (LJ_UNLIKELY(ls->sb.n + 1 > ls->sb.sz))
+ save_grow(ls, c);
+ else
+ ls->sb.buf[ls->sb.n++] = (char)c;
+}
+
+static void inclinenumber(LexState *ls)
+{
+ int old = ls->current;
+ lua_assert(currIsNewline(ls));
+ next(ls); /* skip `\n' or `\r' */
+ if (currIsNewline(ls) && ls->current != old)
+ next(ls); /* skip `\n\r' or `\r\n' */
+ if (++ls->linenumber >= LJ_MAX_LINE)
+ lj_lex_error(ls, ls->token, LJ_ERR_XLINES);
+}
+
+/* -- Scanner for terminals ----------------------------------------------- */
+
+/* Parse a number literal. */
+static void lex_number(LexState *ls, TValue *tv)
+{
+ StrScanFmt fmt;
+ int c, xp = 'e';
+ lua_assert(lj_char_isdigit(ls->current));
+ if ((c = ls->current) == '0') {
+ save_and_next(ls);
+ if ((ls->current | 0x20) == 'x') xp = 'p';
+ }
+ while (lj_char_isident(ls->current) || ls->current == '.' ||
+ ((ls->current == '-' || ls->current == '+') && (c | 0x20) == xp)) {
+ c = ls->current;
+ save_and_next(ls);
+ }
+ save(ls, '\0');
+ fmt = lj_strscan_scan((const uint8_t *)ls->sb.buf, tv,
+ (LJ_DUALNUM ? STRSCAN_OPT_TOINT : STRSCAN_OPT_TONUM) |
+ (LJ_HASFFI ? (STRSCAN_OPT_LL|STRSCAN_OPT_IMAG) : 0));
+ if (LJ_DUALNUM && fmt == STRSCAN_INT) {
+ setitype(tv, LJ_TISNUM);
+ } else if (fmt == STRSCAN_NUM) {
+ /* Already in correct format. */
+#if LJ_HASFFI
+ } else if (fmt != STRSCAN_ERROR) {
+ lua_State *L = ls->L;
+ GCcdata *cd;
+ lua_assert(fmt == STRSCAN_I64 || fmt == STRSCAN_U64 || fmt == STRSCAN_IMAG);
+ if (!ctype_ctsG(G(L))) {
+ ptrdiff_t oldtop = savestack(L, L->top);
+ luaopen_ffi(L); /* Load FFI library on-demand. */
+ L->top = restorestack(L, oldtop);
+ }
+ if (fmt == STRSCAN_IMAG) {
+ cd = lj_cdata_new_(L, CTID_COMPLEX_DOUBLE, 2*sizeof(double));
+ ((double *)cdataptr(cd))[0] = 0;
+ ((double *)cdataptr(cd))[1] = numV(tv);
+ } else {
+ cd = lj_cdata_new_(L, fmt==STRSCAN_I64 ? CTID_INT64 : CTID_UINT64, 8);
+ *(uint64_t *)cdataptr(cd) = tv->u64;
+ }
+ lj_parse_keepcdata(ls, tv, cd);
+#endif
+ } else {
+ lua_assert(fmt == STRSCAN_ERROR);
+ lj_lex_error(ls, TK_number, LJ_ERR_XNUMBER);
+ }
+}
+
+static int skip_sep(LexState *ls)
+{
+ int count = 0;
+ int s = ls->current;
+ lua_assert(s == '[' || s == ']');
+ save_and_next(ls);
+ while (ls->current == '=') {
+ save_and_next(ls);
+ count++;
+ }
+ return (ls->current == s) ? count : (-count) - 1;
+}
+
+static void read_long_string(LexState *ls, TValue *tv, int sep)
+{
+ save_and_next(ls); /* skip 2nd `[' */
+ if (currIsNewline(ls)) /* string starts with a newline? */
+ inclinenumber(ls); /* skip it */
+ for (;;) {
+ switch (ls->current) {
+ case END_OF_STREAM:
+ lj_lex_error(ls, TK_eof, tv ? LJ_ERR_XLSTR : LJ_ERR_XLCOM);
+ break;
+ case ']':
+ if (skip_sep(ls) == sep) {
+ save_and_next(ls); /* skip 2nd `]' */
+ goto endloop;
+ }
+ break;
+ case '\n':
+ case '\r':
+ save(ls, '\n');
+ inclinenumber(ls);
+ if (!tv) lj_str_resetbuf(&ls->sb); /* avoid wasting space */
+ break;
+ default:
+ if (tv) save_and_next(ls);
+ else next(ls);
+ break;
+ }
+ } endloop:
+ if (tv) {
+ GCstr *str = lj_parse_keepstr(ls, ls->sb.buf + (2 + (MSize)sep),
+ ls->sb.n - 2*(2 + (MSize)sep));
+ setstrV(ls->L, tv, str);
+ }
+}
+
+static void read_string(LexState *ls, int delim, TValue *tv)
+{
+ save_and_next(ls);
+ while (ls->current != delim) {
+ switch (ls->current) {
+ case END_OF_STREAM:
+ lj_lex_error(ls, TK_eof, LJ_ERR_XSTR);
+ continue;
+ case '\n':
+ case '\r':
+ lj_lex_error(ls, TK_string, LJ_ERR_XSTR);
+ continue;
+ case '\\': {
+ int c = next(ls); /* Skip the '\\'. */
+ switch (c) {
+ case 'a': c = '\a'; break;
+ case 'b': c = '\b'; break;
+ case 'f': c = '\f'; break;
+ case 'n': c = '\n'; break;
+ case 'r': c = '\r'; break;
+ case 't': c = '\t'; break;
+ case 'v': c = '\v'; break;
+ case 'x': /* Hexadecimal escape '\xXX'. */
+ c = (next(ls) & 15u) << 4;
+ if (!lj_char_isdigit(ls->current)) {
+ if (!lj_char_isxdigit(ls->current)) goto err_xesc;
+ c += 9 << 4;
+ }
+ c += (next(ls) & 15u);
+ if (!lj_char_isdigit(ls->current)) {
+ if (!lj_char_isxdigit(ls->current)) goto err_xesc;
+ c += 9;
+ }
+ break;
+ case 'z': /* Skip whitespace. */
+ next(ls);
+ while (lj_char_isspace(ls->current))
+ if (currIsNewline(ls)) inclinenumber(ls); else next(ls);
+ continue;
+ case '\n': case '\r': save(ls, '\n'); inclinenumber(ls); continue;
+ case '\\': case '\"': case '\'': break;
+ case END_OF_STREAM: continue;
+ default:
+ if (!lj_char_isdigit(c))
+ goto err_xesc;
+ c -= '0'; /* Decimal escape '\ddd'. */
+ if (lj_char_isdigit(next(ls))) {
+ c = c*10 + (ls->current - '0');
+ if (lj_char_isdigit(next(ls))) {
+ c = c*10 + (ls->current - '0');
+ if (c > 255) {
+ err_xesc:
+ lj_lex_error(ls, TK_string, LJ_ERR_XESC);
+ }
+ next(ls);
+ }
+ }
+ save(ls, c);
+ continue;
+ }
+ save(ls, c);
+ next(ls);
+ continue;
+ }
+ default:
+ save_and_next(ls);
+ break;
+ }
+ }
+ save_and_next(ls); /* skip delimiter */
+ setstrV(ls->L, tv, lj_parse_keepstr(ls, ls->sb.buf + 1, ls->sb.n - 2));
+}
+
+/* -- Main lexical scanner ------------------------------------------------ */
+
+static int llex(LexState *ls, TValue *tv)
+{
+ lj_str_resetbuf(&ls->sb);
+ for (;;) {
+ if (lj_char_isident(ls->current)) {
+ GCstr *s;
+ if (lj_char_isdigit(ls->current)) { /* Numeric literal. */
+ lex_number(ls, tv);
+ return TK_number;
+ }
+ /* Identifier or reserved word. */
+ do {
+ save_and_next(ls);
+ } while (lj_char_isident(ls->current));
+ s = lj_parse_keepstr(ls, ls->sb.buf, ls->sb.n);
+ setstrV(ls->L, tv, s);
+ if (s->reserved > 0) /* Reserved word? */
+ return TK_OFS + s->reserved;
+ return TK_name;
+ }
+ switch (ls->current) {
+ case '\n':
+ case '\r':
+ inclinenumber(ls);
+ continue;
+ case ' ':
+ case '\t':
+ case '\v':
+ case '\f':
+ next(ls);
+ continue;
+ case '-':
+ next(ls);
+ if (ls->current != '-') return '-';
+ /* else is a comment */
+ next(ls);
+ if (ls->current == '[') {
+ int sep = skip_sep(ls);
+ lj_str_resetbuf(&ls->sb); /* `skip_sep' may dirty the buffer */
+ if (sep >= 0) {
+ read_long_string(ls, NULL, sep); /* long comment */
+ lj_str_resetbuf(&ls->sb);
+ continue;
+ }
+ }
+ /* else short comment */
+ while (!currIsNewline(ls) && ls->current != END_OF_STREAM)
+ next(ls);
+ continue;
+ case '[': {
+ int sep = skip_sep(ls);
+ if (sep >= 0) {
+ read_long_string(ls, tv, sep);
+ return TK_string;
+ } else if (sep == -1) {
+ return '[';
+ } else {
+ lj_lex_error(ls, TK_string, LJ_ERR_XLDELIM);
+ continue;
+ }
+ }
+ case '=':
+ next(ls);
+ if (ls->current != '=') return '='; else { next(ls); return TK_eq; }
+ case '<':
+ next(ls);
+ if (ls->current != '=') return '<'; else { next(ls); return TK_le; }
+ case '>':
+ next(ls);
+ if (ls->current != '=') return '>'; else { next(ls); return TK_ge; }
+ case '~':
+ next(ls);
+ if (ls->current != '=') return '~'; else { next(ls); return TK_ne; }
+ case ':':
+ next(ls);
+ if (ls->current != ':') return ':'; else { next(ls); return TK_label; }
+ case '"':
+ case '\'':
+ read_string(ls, ls->current, tv);
+ return TK_string;
+ case '.':
+ save_and_next(ls);
+ if (ls->current == '.') {
+ next(ls);
+ if (ls->current == '.') {
+ next(ls);
+ return TK_dots; /* ... */
+ }
+ return TK_concat; /* .. */
+ } else if (!lj_char_isdigit(ls->current)) {
+ return '.';
+ } else {
+ lex_number(ls, tv);
+ return TK_number;
+ }
+ case END_OF_STREAM:
+ return TK_eof;
+ default: {
+ int c = ls->current;
+ next(ls);
+ return c; /* Single-char tokens (+ - / ...). */
+ }
+ }
+ }
+}
+
+/* -- Lexer API ----------------------------------------------------------- */
+
+/* Setup lexer state. */
+int lj_lex_setup(lua_State *L, LexState *ls)
+{
+ int header = 0;
+ ls->L = L;
+ ls->fs = NULL;
+ ls->n = 0;
+ ls->p = NULL;
+ ls->vstack = NULL;
+ ls->sizevstack = 0;
+ ls->vtop = 0;
+ ls->bcstack = NULL;
+ ls->sizebcstack = 0;
+ ls->token = 0;
+ ls->lookahead = TK_eof; /* No look-ahead token. */
+ ls->linenumber = 1;
+ ls->lastline = 1;
+ lj_str_resizebuf(ls->L, &ls->sb, LJ_MIN_SBUF);
+ next(ls); /* Read-ahead first char. */
+ if (ls->current == 0xef && ls->n >= 2 && char2int(ls->p[0]) == 0xbb &&
+ char2int(ls->p[1]) == 0xbf) { /* Skip UTF-8 BOM (if buffered). */
+ ls->n -= 2;
+ ls->p += 2;
+ next(ls);
+ header = 1;
+ }
+ if (ls->current == '#') { /* Skip POSIX #! header line. */
+ do {
+ next(ls);
+ if (ls->current == END_OF_STREAM) return 0;
+ } while (!currIsNewline(ls));
+ inclinenumber(ls);
+ header = 1;
+ }
+ if (ls->current == LUA_SIGNATURE[0]) { /* Bytecode dump. */
+ if (header) {
+ /*
+ ** Loading bytecode with an extra header is disabled for security
+ ** reasons. This may circumvent the usual check for bytecode vs.
+ ** Lua code by looking at the first char. Since this is a potential
+ ** security violation no attempt is made to echo the chunkname either.
+ */
+ setstrV(L, L->top++, lj_err_str(L, LJ_ERR_BCBAD));
+ lj_err_throw(L, LUA_ERRSYNTAX);
+ }
+ return 1;
+ }
+ return 0;
+}
+
+/* Cleanup lexer state. */
+void lj_lex_cleanup(lua_State *L, LexState *ls)
+{
+ global_State *g = G(L);
+ lj_mem_freevec(g, ls->bcstack, ls->sizebcstack, BCInsLine);
+ lj_mem_freevec(g, ls->vstack, ls->sizevstack, VarInfo);
+ lj_str_freebuf(g, &ls->sb);
+}
+
+void lj_lex_next(LexState *ls)
+{
+ ls->lastline = ls->linenumber;
+ if (LJ_LIKELY(ls->lookahead == TK_eof)) { /* No lookahead token? */
+ ls->token = llex(ls, &ls->tokenval); /* Get next token. */
+ } else { /* Otherwise return lookahead token. */
+ ls->token = ls->lookahead;
+ ls->lookahead = TK_eof;
+ ls->tokenval = ls->lookaheadval;
+ }
+}
+
+LexToken lj_lex_lookahead(LexState *ls)
+{
+ lua_assert(ls->lookahead == TK_eof);
+ ls->lookahead = llex(ls, &ls->lookaheadval);
+ return ls->lookahead;
+}
+
+const char *lj_lex_token2str(LexState *ls, LexToken token)
+{
+ if (token > TK_OFS)
+ return tokennames[token-TK_OFS-1];
+ else if (!lj_char_iscntrl(token))
+ return lj_str_pushf(ls->L, "%c", token);
+ else
+ return lj_str_pushf(ls->L, "char(%d)", token);
+}
+
+void lj_lex_error(LexState *ls, LexToken token, ErrMsg em, ...)
+{
+ const char *tok;
+ va_list argp;
+ if (token == 0) {
+ tok = NULL;
+ } else if (token == TK_name || token == TK_string || token == TK_number) {
+ save(ls, '\0');
+ tok = ls->sb.buf;
+ } else {
+ tok = lj_lex_token2str(ls, token);
+ }
+ va_start(argp, em);
+ lj_err_lex(ls->L, ls->chunkname, tok, ls->linenumber, em, argp);
+ va_end(argp);
+}
+
+void lj_lex_init(lua_State *L)
+{
+ uint32_t i;
+ for (i = 0; i < TK_RESERVED; i++) {
+ GCstr *s = lj_str_newz(L, tokennames[i]);
+ fixstring(s); /* Reserved words are never collected. */
+ s->reserved = (uint8_t)(i+1);
+ }
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_lex.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_lex.h
new file mode 100644
index 0000000..41c03f9
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_lex.h
@@ -0,0 +1,85 @@
+/*
+** Lexical analyzer.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_LEX_H
+#define _LJ_LEX_H
+
+#include <stdarg.h>
+
+#include "lj_obj.h"
+#include "lj_err.h"
+
+/* Lua lexer tokens. */
+#define TKDEF(_, __) \
+ _(and) _(break) _(do) _(else) _(elseif) _(end) _(false) \
+ _(for) _(function) _(goto) _(if) _(in) _(local) _(nil) _(not) _(or) \
+ _(repeat) _(return) _(then) _(true) _(until) _(while) \
+ __(concat, ..) __(dots, ...) __(eq, ==) __(ge, >=) __(le, <=) __(ne, ~=) \
+ __(label, ::) __(number, <number>) __(name, <name>) __(string, <string>) \
+ __(eof, <eof>)
+
+enum {
+ TK_OFS = 256,
+#define TKENUM1(name) TK_##name,
+#define TKENUM2(name, sym) TK_##name,
+TKDEF(TKENUM1, TKENUM2)
+#undef TKENUM1
+#undef TKENUM2
+ TK_RESERVED = TK_while - TK_OFS
+};
+
+typedef int LexToken;
+
+/* Combined bytecode ins/line. Only used during bytecode generation. */
+typedef struct BCInsLine {
+ BCIns ins; /* Bytecode instruction. */
+ BCLine line; /* Line number for this bytecode. */
+} BCInsLine;
+
+/* Info for local variables. Only used during bytecode generation. */
+typedef struct VarInfo {
+ GCRef name; /* Local variable name or goto/label name. */
+ BCPos startpc; /* First point where the local variable is active. */
+ BCPos endpc; /* First point where the local variable is dead. */
+ uint8_t slot; /* Variable slot. */
+ uint8_t info; /* Variable/goto/label info. */
+} VarInfo;
+
+/* Lua lexer state. */
+typedef struct LexState {
+ struct FuncState *fs; /* Current FuncState. Defined in lj_parse.c. */
+ struct lua_State *L; /* Lua state. */
+ TValue tokenval; /* Current token value. */
+ TValue lookaheadval; /* Lookahead token value. */
+ int current; /* Current character (charint). */
+ LexToken token; /* Current token. */
+ LexToken lookahead; /* Lookahead token. */
+ MSize n; /* Bytes left in input buffer. */
+ const char *p; /* Current position in input buffer. */
+ SBuf sb; /* String buffer for tokens. */
+ lua_Reader rfunc; /* Reader callback. */
+ void *rdata; /* Reader callback data. */
+ BCLine linenumber; /* Input line counter. */
+ BCLine lastline; /* Line of last token. */
+ GCstr *chunkname; /* Current chunk name (interned string). */
+ const char *chunkarg; /* Chunk name argument. */
+ const char *mode; /* Allow loading bytecode (b) and/or source text (t). */
+ VarInfo *vstack; /* Stack for names and extents of local variables. */
+ MSize sizevstack; /* Size of variable stack. */
+ MSize vtop; /* Top of variable stack. */
+ BCInsLine *bcstack; /* Stack for bytecode instructions/line numbers. */
+ MSize sizebcstack; /* Size of bytecode stack. */
+ uint32_t level; /* Syntactical nesting level. */
+} LexState;
+
+LJ_FUNC int lj_lex_setup(lua_State *L, LexState *ls);
+LJ_FUNC void lj_lex_cleanup(lua_State *L, LexState *ls);
+LJ_FUNC void lj_lex_next(LexState *ls);
+LJ_FUNC LexToken lj_lex_lookahead(LexState *ls);
+LJ_FUNC const char *lj_lex_token2str(LexState *ls, LexToken token);
+LJ_FUNC_NORET void lj_lex_error(LexState *ls, LexToken token, ErrMsg em, ...);
+LJ_FUNC void lj_lex_init(lua_State *L);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_lib.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_lib.c
new file mode 100644
index 0000000..a1bb6a2
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_lib.c
@@ -0,0 +1,258 @@
+/*
+** Library function support.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_lib_c
+#define LUA_CORE
+
+#include "lauxlib.h"
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_func.h"
+#include "lj_bc.h"
+#include "lj_dispatch.h"
+#include "lj_vm.h"
+#include "lj_strscan.h"
+#include "lj_lib.h"
+
+/* -- Library initialization ---------------------------------------------- */
+
+static GCtab *lib_create_table(lua_State *L, const char *libname, int hsize)
+{
+ if (libname) {
+ luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16);
+ lua_getfield(L, -1, libname);
+ if (!tvistab(L->top-1)) {
+ L->top--;
+ if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, hsize) != NULL)
+ lj_err_callerv(L, LJ_ERR_BADMODN, libname);
+ settabV(L, L->top, tabV(L->top-1));
+ L->top++;
+ lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */
+ }
+ L->top--;
+ settabV(L, L->top-1, tabV(L->top));
+ } else {
+ lua_createtable(L, 0, hsize);
+ }
+ return tabV(L->top-1);
+}
+
+void lj_lib_register(lua_State *L, const char *libname,
+ const uint8_t *p, const lua_CFunction *cf)
+{
+ GCtab *env = tabref(L->env);
+ GCfunc *ofn = NULL;
+ int ffid = *p++;
+ BCIns *bcff = &L2GG(L)->bcff[*p++];
+ GCtab *tab = lib_create_table(L, libname, *p++);
+ ptrdiff_t tpos = L->top - L->base;
+
+ /* Avoid barriers further down. */
+ lj_gc_anybarriert(L, tab);
+ tab->nomm = 0;
+
+ for (;;) {
+ uint32_t tag = *p++;
+ MSize len = tag & LIBINIT_LENMASK;
+ tag &= LIBINIT_TAGMASK;
+ if (tag != LIBINIT_STRING) {
+ const char *name;
+ MSize nuv = (MSize)(L->top - L->base - tpos);
+ GCfunc *fn = lj_func_newC(L, nuv, env);
+ if (nuv) {
+ L->top = L->base + tpos;
+ memcpy(fn->c.upvalue, L->top, sizeof(TValue)*nuv);
+ }
+ fn->c.ffid = (uint8_t)(ffid++);
+ name = (const char *)p;
+ p += len;
+ if (tag == LIBINIT_CF)
+ setmref(fn->c.pc, &G(L)->bc_cfunc_int);
+ else
+ setmref(fn->c.pc, bcff++);
+ if (tag == LIBINIT_ASM_)
+ fn->c.f = ofn->c.f; /* Copy handler from previous function. */
+ else
+ fn->c.f = *cf++; /* Get cf or handler from C function table. */
+ if (len) {
+ /* NOBARRIER: See above for common barrier. */
+ setfuncV(L, lj_tab_setstr(L, tab, lj_str_new(L, name, len)), fn);
+ }
+ ofn = fn;
+ } else {
+ switch (tag | len) {
+ case LIBINIT_SET:
+ L->top -= 2;
+ if (tvisstr(L->top+1) && strV(L->top+1)->len == 0)
+ env = tabV(L->top);
+ else /* NOBARRIER: See above for common barrier. */
+ copyTV(L, lj_tab_set(L, tab, L->top+1), L->top);
+ break;
+ case LIBINIT_NUMBER:
+ memcpy(&L->top->n, p, sizeof(double));
+ L->top++;
+ p += sizeof(double);
+ break;
+ case LIBINIT_COPY:
+ copyTV(L, L->top, L->top - *p++);
+ L->top++;
+ break;
+ case LIBINIT_LASTCL:
+ setfuncV(L, L->top++, ofn);
+ break;
+ case LIBINIT_FFID:
+ ffid++;
+ break;
+ case LIBINIT_END:
+ return;
+ default:
+ setstrV(L, L->top++, lj_str_new(L, (const char *)p, len));
+ p += len;
+ break;
+ }
+ }
+ }
+}
+
+/* -- Type checks --------------------------------------------------------- */
+
+TValue *lj_lib_checkany(lua_State *L, int narg)
+{
+ TValue *o = L->base + narg-1;
+ if (o >= L->top)
+ lj_err_arg(L, narg, LJ_ERR_NOVAL);
+ return o;
+}
+
+GCstr *lj_lib_checkstr(lua_State *L, int narg)
+{
+ TValue *o = L->base + narg-1;
+ if (o < L->top) {
+ if (LJ_LIKELY(tvisstr(o))) {
+ return strV(o);
+ } else if (tvisnumber(o)) {
+ GCstr *s = lj_str_fromnumber(L, o);
+ setstrV(L, o, s);
+ return s;
+ }
+ }
+ lj_err_argt(L, narg, LUA_TSTRING);
+ return NULL; /* unreachable */
+}
+
+GCstr *lj_lib_optstr(lua_State *L, int narg)
+{
+ TValue *o = L->base + narg-1;
+ return (o < L->top && !tvisnil(o)) ? lj_lib_checkstr(L, narg) : NULL;
+}
+
+#if LJ_DUALNUM
+void lj_lib_checknumber(lua_State *L, int narg)
+{
+ TValue *o = L->base + narg-1;
+ if (!(o < L->top && lj_strscan_numberobj(o)))
+ lj_err_argt(L, narg, LUA_TNUMBER);
+}
+#endif
+
+lua_Number lj_lib_checknum(lua_State *L, int narg)
+{
+ TValue *o = L->base + narg-1;
+ if (!(o < L->top &&
+ (tvisnumber(o) || (tvisstr(o) && lj_strscan_num(strV(o), o)))))
+ lj_err_argt(L, narg, LUA_TNUMBER);
+ if (LJ_UNLIKELY(tvisint(o))) {
+ lua_Number n = (lua_Number)intV(o);
+ setnumV(o, n);
+ return n;
+ } else {
+ return numV(o);
+ }
+}
+
+int32_t lj_lib_checkint(lua_State *L, int narg)
+{
+ TValue *o = L->base + narg-1;
+ if (!(o < L->top && lj_strscan_numberobj(o)))
+ lj_err_argt(L, narg, LUA_TNUMBER);
+ if (LJ_LIKELY(tvisint(o))) {
+ return intV(o);
+ } else {
+ int32_t i = lj_num2int(numV(o));
+ if (LJ_DUALNUM) setintV(o, i);
+ return i;
+ }
+}
+
+int32_t lj_lib_optint(lua_State *L, int narg, int32_t def)
+{
+ TValue *o = L->base + narg-1;
+ return (o < L->top && !tvisnil(o)) ? lj_lib_checkint(L, narg) : def;
+}
+
+int32_t lj_lib_checkbit(lua_State *L, int narg)
+{
+ TValue *o = L->base + narg-1;
+ if (!(o < L->top && lj_strscan_numberobj(o)))
+ lj_err_argt(L, narg, LUA_TNUMBER);
+ if (LJ_LIKELY(tvisint(o))) {
+ return intV(o);
+ } else {
+ int32_t i = lj_num2bit(numV(o));
+ if (LJ_DUALNUM) setintV(o, i);
+ return i;
+ }
+}
+
+GCfunc *lj_lib_checkfunc(lua_State *L, int narg)
+{
+ TValue *o = L->base + narg-1;
+ if (!(o < L->top && tvisfunc(o)))
+ lj_err_argt(L, narg, LUA_TFUNCTION);
+ return funcV(o);
+}
+
+GCtab *lj_lib_checktab(lua_State *L, int narg)
+{
+ TValue *o = L->base + narg-1;
+ if (!(o < L->top && tvistab(o)))
+ lj_err_argt(L, narg, LUA_TTABLE);
+ return tabV(o);
+}
+
+GCtab *lj_lib_checktabornil(lua_State *L, int narg)
+{
+ TValue *o = L->base + narg-1;
+ if (o < L->top) {
+ if (tvistab(o))
+ return tabV(o);
+ else if (tvisnil(o))
+ return NULL;
+ }
+ lj_err_arg(L, narg, LJ_ERR_NOTABN);
+ return NULL; /* unreachable */
+}
+
+int lj_lib_checkopt(lua_State *L, int narg, int def, const char *lst)
+{
+ GCstr *s = def >= 0 ? lj_lib_optstr(L, narg) : lj_lib_checkstr(L, narg);
+ if (s) {
+ const char *opt = strdata(s);
+ MSize len = s->len;
+ int i;
+ for (i = 0; *(const uint8_t *)lst; i++) {
+ if (*(const uint8_t *)lst == len && memcmp(opt, lst+1, len) == 0)
+ return i;
+ lst += 1+*(const uint8_t *)lst;
+ }
+ lj_err_argv(L, narg, LJ_ERR_INVOPTM, opt);
+ }
+ return def;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_lib.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_lib.h
new file mode 100644
index 0000000..aa87407
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_lib.h
@@ -0,0 +1,112 @@
+/*
+** Library function support.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_LIB_H
+#define _LJ_LIB_H
+
+#include "lj_obj.h"
+
+/*
+** A fallback handler is called by the assembler VM if the fast path fails:
+**
+** - too few arguments: unrecoverable.
+** - wrong argument type: recoverable, if coercion succeeds.
+** - bad argument value: unrecoverable.
+** - stack overflow: recoverable, if stack reallocation succeeds.
+** - extra handling: recoverable.
+**
+** The unrecoverable cases throw an error with lj_err_arg(), lj_err_argtype(),
+** lj_err_caller() or lj_err_callermsg().
+** The recoverable cases return 0 or the number of results + 1.
+** The assembler VM retries the fast path only if 0 is returned.
+** This time the fallback must not be called again or it gets stuck in a loop.
+*/
+
+/* Return values from fallback handler. */
+#define FFH_RETRY 0
+#define FFH_UNREACHABLE FFH_RETRY
+#define FFH_RES(n) ((n)+1)
+#define FFH_TAILCALL (-1)
+
+LJ_FUNC TValue *lj_lib_checkany(lua_State *L, int narg);
+LJ_FUNC GCstr *lj_lib_checkstr(lua_State *L, int narg);
+LJ_FUNC GCstr *lj_lib_optstr(lua_State *L, int narg);
+#if LJ_DUALNUM
+LJ_FUNC void lj_lib_checknumber(lua_State *L, int narg);
+#else
+#define lj_lib_checknumber(L, narg) lj_lib_checknum((L), (narg))
+#endif
+LJ_FUNC lua_Number lj_lib_checknum(lua_State *L, int narg);
+LJ_FUNC int32_t lj_lib_checkint(lua_State *L, int narg);
+LJ_FUNC int32_t lj_lib_optint(lua_State *L, int narg, int32_t def);
+LJ_FUNC int32_t lj_lib_checkbit(lua_State *L, int narg);
+LJ_FUNC GCfunc *lj_lib_checkfunc(lua_State *L, int narg);
+LJ_FUNC GCtab *lj_lib_checktab(lua_State *L, int narg);
+LJ_FUNC GCtab *lj_lib_checktabornil(lua_State *L, int narg);
+LJ_FUNC int lj_lib_checkopt(lua_State *L, int narg, int def, const char *lst);
+
+/* Avoid including lj_frame.h. */
+#define lj_lib_upvalue(L, n) \
+ (&gcref((L->base-1)->fr.func)->fn.c.upvalue[(n)-1])
+
+#if LJ_TARGET_WINDOWS
+#define lj_lib_checkfpu(L) \
+ do { setnumV(L->top++, (lua_Number)1437217655); \
+ if (lua_tointeger(L, -1) != 1437217655) lj_err_caller(L, LJ_ERR_BADFPU); \
+ L->top--; } while (0)
+#else
+#define lj_lib_checkfpu(L) UNUSED(L)
+#endif
+
+/* Push internal function on the stack. */
+static LJ_AINLINE void lj_lib_pushcc(lua_State *L, lua_CFunction f,
+ int id, int n)
+{
+ GCfunc *fn;
+ lua_pushcclosure(L, f, n);
+ fn = funcV(L->top-1);
+ fn->c.ffid = (uint8_t)id;
+ setmref(fn->c.pc, &G(L)->bc_cfunc_int);
+}
+
+#define lj_lib_pushcf(L, fn, id) (lj_lib_pushcc(L, (fn), (id), 0))
+
+/* Library function declarations. Scanned by buildvm. */
+#define LJLIB_CF(name) static int lj_cf_##name(lua_State *L)
+#define LJLIB_ASM(name) static int lj_ffh_##name(lua_State *L)
+#define LJLIB_ASM_(name)
+#define LJLIB_SET(name)
+#define LJLIB_PUSH(arg)
+#define LJLIB_REC(handler)
+#define LJLIB_NOREGUV
+#define LJLIB_NOREG
+
+#define LJ_LIB_REG(L, regname, name) \
+ lj_lib_register(L, regname, lj_lib_init_##name, lj_lib_cf_##name)
+
+LJ_FUNC void lj_lib_register(lua_State *L, const char *libname,
+ const uint8_t *init, const lua_CFunction *cf);
+
+/* Library init data tags. */
+#define LIBINIT_LENMASK 0x3f
+#define LIBINIT_TAGMASK 0xc0
+#define LIBINIT_CF 0x00
+#define LIBINIT_ASM 0x40
+#define LIBINIT_ASM_ 0x80
+#define LIBINIT_STRING 0xc0
+#define LIBINIT_MAXSTR 0x39
+#define LIBINIT_SET 0xfa
+#define LIBINIT_NUMBER 0xfb
+#define LIBINIT_COPY 0xfc
+#define LIBINIT_LASTCL 0xfd
+#define LIBINIT_FFID 0xfe
+#define LIBINIT_END 0xff
+
+/* Exported library functions. */
+
+typedef struct RandomState RandomState;
+LJ_FUNC uint64_t LJ_FASTCALL lj_math_random_step(RandomState *rs);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_load.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_load.c
new file mode 100644
index 0000000..20be8eb
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_load.c
@@ -0,0 +1,168 @@
+/*
+** Load and dump code.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#include <errno.h>
+#include <stdio.h>
+
+#define lj_load_c
+#define LUA_CORE
+
+#include "lua.h"
+#include "lauxlib.h"
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_func.h"
+#include "lj_frame.h"
+#include "lj_vm.h"
+#include "lj_lex.h"
+#include "lj_bcdump.h"
+#include "lj_parse.h"
+
+/* -- Load Lua source code and bytecode ----------------------------------- */
+
+static TValue *cpparser(lua_State *L, lua_CFunction dummy, void *ud)
+{
+ LexState *ls = (LexState *)ud;
+ GCproto *pt;
+ GCfunc *fn;
+ int bc;
+ UNUSED(dummy);
+ cframe_errfunc(L->cframe) = -1; /* Inherit error function. */
+ bc = lj_lex_setup(L, ls);
+ if (ls->mode && !strchr(ls->mode, bc ? 'b' : 't')) {
+ setstrV(L, L->top++, lj_err_str(L, LJ_ERR_XMODE));
+ lj_err_throw(L, LUA_ERRSYNTAX);
+ }
+ pt = bc ? lj_bcread(ls) : lj_parse(ls);
+ fn = lj_func_newL_empty(L, pt, tabref(L->env));
+ /* Don't combine above/below into one statement. */
+ setfuncV(L, L->top++, fn);
+ return NULL;
+}
+
+LUA_API int lua_loadx(lua_State *L, lua_Reader reader, void *data,
+ const char *chunkname, const char *mode)
+{
+ LexState ls;
+ int status;
+ ls.rfunc = reader;
+ ls.rdata = data;
+ ls.chunkarg = chunkname ? chunkname : "?";
+ ls.mode = mode;
+ lj_str_initbuf(&ls.sb);
+ status = lj_vm_cpcall(L, NULL, &ls, cpparser);
+ lj_lex_cleanup(L, &ls);
+ lj_gc_check(L);
+ return status;
+}
+
+LUA_API int lua_load(lua_State *L, lua_Reader reader, void *data,
+ const char *chunkname)
+{
+ return lua_loadx(L, reader, data, chunkname, NULL);
+}
+
+typedef struct FileReaderCtx {
+ FILE *fp;
+ char buf[LUAL_BUFFERSIZE];
+} FileReaderCtx;
+
+static const char *reader_file(lua_State *L, void *ud, size_t *size)
+{
+ FileReaderCtx *ctx = (FileReaderCtx *)ud;
+ UNUSED(L);
+ if (feof(ctx->fp)) return NULL;
+ *size = fread(ctx->buf, 1, sizeof(ctx->buf), ctx->fp);
+ return *size > 0 ? ctx->buf : NULL;
+}
+
+LUALIB_API int luaL_loadfilex(lua_State *L, const char *filename,
+ const char *mode)
+{
+ FileReaderCtx ctx;
+ int status;
+ const char *chunkname;
+ if (filename) {
+ ctx.fp = fopen(filename, "rb");
+ if (ctx.fp == NULL) {
+ lua_pushfstring(L, "cannot open %s: %s", filename, strerror(errno));
+ return LUA_ERRFILE;
+ }
+ chunkname = lua_pushfstring(L, "@%s", filename);
+ } else {
+ ctx.fp = stdin;
+ chunkname = "=stdin";
+ }
+ status = lua_loadx(L, reader_file, &ctx, chunkname, mode);
+ if (ferror(ctx.fp)) {
+ L->top -= filename ? 2 : 1;
+ lua_pushfstring(L, "cannot read %s: %s", chunkname+1, strerror(errno));
+ if (filename)
+ fclose(ctx.fp);
+ return LUA_ERRFILE;
+ }
+ if (filename) {
+ L->top--;
+ copyTV(L, L->top-1, L->top);
+ fclose(ctx.fp);
+ }
+ return status;
+}
+
+LUALIB_API int luaL_loadfile(lua_State *L, const char *filename)
+{
+ return luaL_loadfilex(L, filename, NULL);
+}
+
+typedef struct StringReaderCtx {
+ const char *str;
+ size_t size;
+} StringReaderCtx;
+
+static const char *reader_string(lua_State *L, void *ud, size_t *size)
+{
+ StringReaderCtx *ctx = (StringReaderCtx *)ud;
+ UNUSED(L);
+ if (ctx->size == 0) return NULL;
+ *size = ctx->size;
+ ctx->size = 0;
+ return ctx->str;
+}
+
+LUALIB_API int luaL_loadbufferx(lua_State *L, const char *buf, size_t size,
+ const char *name, const char *mode)
+{
+ StringReaderCtx ctx;
+ ctx.str = buf;
+ ctx.size = size;
+ return lua_loadx(L, reader_string, &ctx, name, mode);
+}
+
+LUALIB_API int luaL_loadbuffer(lua_State *L, const char *buf, size_t size,
+ const char *name)
+{
+ return luaL_loadbufferx(L, buf, size, name, NULL);
+}
+
+LUALIB_API int luaL_loadstring(lua_State *L, const char *s)
+{
+ return luaL_loadbuffer(L, s, strlen(s), s);
+}
+
+/* -- Dump bytecode ------------------------------------------------------- */
+
+LUA_API int lua_dump(lua_State *L, lua_Writer writer, void *data)
+{
+ cTValue *o = L->top-1;
+ api_check(L, L->top > L->base);
+ if (tvisfunc(o) && isluafunc(funcV(o)))
+ return lj_bcwrite(L, funcproto(funcV(o)), writer, data, 0);
+ else
+ return 1;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_mcode.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_mcode.c
new file mode 100644
index 0000000..5ea89f6
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_mcode.c
@@ -0,0 +1,381 @@
+/*
+** Machine code management.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_mcode_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#if LJ_HASJIT
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_jit.h"
+#include "lj_mcode.h"
+#include "lj_trace.h"
+#include "lj_dispatch.h"
+#endif
+#if LJ_HASJIT || LJ_HASFFI
+#include "lj_vm.h"
+#endif
+
+/* -- OS-specific functions ----------------------------------------------- */
+
+#if LJ_HASJIT || LJ_HASFFI
+
+/* Define this if you want to run LuaJIT with Valgrind. */
+#ifdef LUAJIT_USE_VALGRIND
+#include <valgrind/valgrind.h>
+#endif
+
+#if LJ_TARGET_IOS
+void sys_icache_invalidate(void *start, size_t len);
+#endif
+
+/* Synchronize data/instruction cache. */
+void lj_mcode_sync(void *start, void *end)
+{
+#ifdef LUAJIT_USE_VALGRIND
+ VALGRIND_DISCARD_TRANSLATIONS(start, (char *)end-(char *)start);
+#endif
+#if LJ_TARGET_X86ORX64
+ UNUSED(start); UNUSED(end);
+#elif LJ_TARGET_IOS
+ sys_icache_invalidate(start, (char *)end-(char *)start);
+#elif LJ_TARGET_PPC
+ lj_vm_cachesync(start, end);
+#elif defined(__GNUC__)
+ __clear_cache(start, end);
+#else
+#error "Missing builtin to flush instruction cache"
+#endif
+}
+
+#endif
+
+#if LJ_HASJIT
+
+#if LJ_TARGET_WINDOWS
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#define MCPROT_RW PAGE_READWRITE
+#define MCPROT_RX PAGE_EXECUTE_READ
+#define MCPROT_RWX PAGE_EXECUTE_READWRITE
+
+static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, DWORD prot)
+{
+ void *p = VirtualAlloc((void *)hint, sz,
+ MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN, prot);
+ if (!p && !hint)
+ lj_trace_err(J, LJ_TRERR_MCODEAL);
+ return p;
+}
+
+static void mcode_free(jit_State *J, void *p, size_t sz)
+{
+ UNUSED(J); UNUSED(sz);
+ VirtualFree(p, 0, MEM_RELEASE);
+}
+
+static int mcode_setprot(void *p, size_t sz, DWORD prot)
+{
+ DWORD oprot;
+ return !VirtualProtect(p, sz, prot, &oprot);
+}
+
+#elif LJ_TARGET_POSIX
+
+#include <sys/mman.h>
+
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS MAP_ANON
+#endif
+
+#define MCPROT_RW (PROT_READ|PROT_WRITE)
+#define MCPROT_RX (PROT_READ|PROT_EXEC)
+#define MCPROT_RWX (PROT_READ|PROT_WRITE|PROT_EXEC)
+
+static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot)
+{
+ void *p = mmap((void *)hint, sz, prot, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+ if (p == MAP_FAILED) {
+ if (!hint) lj_trace_err(J, LJ_TRERR_MCODEAL);
+ p = NULL;
+ }
+ return p;
+}
+
+static void mcode_free(jit_State *J, void *p, size_t sz)
+{
+ UNUSED(J);
+ munmap(p, sz);
+}
+
+static int mcode_setprot(void *p, size_t sz, int prot)
+{
+ return mprotect(p, sz, prot);
+}
+
+#elif LJ_64
+
+#error "Missing OS support for explicit placement of executable memory"
+
+#else
+
+/* Fallback allocator. This will fail if memory is not executable by default. */
+#define LUAJIT_UNPROTECT_MCODE
+#define MCPROT_RW 0
+#define MCPROT_RX 0
+#define MCPROT_RWX 0
+
+static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot)
+{
+ UNUSED(hint); UNUSED(prot);
+ return lj_mem_new(J->L, sz);
+}
+
+static void mcode_free(jit_State *J, void *p, size_t sz)
+{
+ lj_mem_free(J2G(J), p, sz);
+}
+
+#endif
+
+/* -- MCode area protection ----------------------------------------------- */
+
+/* Define this ONLY if page protection twiddling becomes a bottleneck. */
+#ifdef LUAJIT_UNPROTECT_MCODE
+
+/* It's generally considered to be a potential security risk to have
+** pages with simultaneous write *and* execute access in a process.
+**
+** Do not even think about using this mode for server processes or
+** apps handling untrusted external data (such as a browser).
+**
+** The security risk is not in LuaJIT itself -- but if an adversary finds
+** any *other* flaw in your C application logic, then any RWX memory page
+** simplifies writing an exploit considerably.
+*/
+#define MCPROT_GEN MCPROT_RWX
+#define MCPROT_RUN MCPROT_RWX
+
+static void mcode_protect(jit_State *J, int prot)
+{
+ UNUSED(J); UNUSED(prot);
+}
+
+#else
+
+/* This is the default behaviour and much safer:
+**
+** Most of the time the memory pages holding machine code are executable,
+** but NONE of them is writable.
+**
+** The current memory area is marked read-write (but NOT executable) only
+** during the short time window while the assembler generates machine code.
+*/
+#define MCPROT_GEN MCPROT_RW
+#define MCPROT_RUN MCPROT_RX
+
+/* Protection twiddling failed. Probably due to kernel security. */
+static LJ_NOINLINE void mcode_protfail(jit_State *J)
+{
+ lua_CFunction panic = J2G(J)->panic;
+ if (panic) {
+ lua_State *L = J->L;
+ setstrV(L, L->top++, lj_err_str(L, LJ_ERR_JITPROT));
+ panic(L);
+ }
+}
+
+/* Change protection of MCode area. */
+static void mcode_protect(jit_State *J, int prot)
+{
+ if (J->mcprot != prot) {
+ if (LJ_UNLIKELY(mcode_setprot(J->mcarea, J->szmcarea, prot)))
+ mcode_protfail(J);
+ J->mcprot = prot;
+ }
+}
+
+#endif
+
+/* -- MCode area allocation ----------------------------------------------- */
+
+#if LJ_64
+#define mcode_validptr(p) (p)
+#else
+#define mcode_validptr(p) ((p) && (uintptr_t)(p) < 0xffff0000)
+#endif
+
+#ifdef LJ_TARGET_JUMPRANGE
+
+/* Get memory within relative jump distance of our code in 64 bit mode. */
+static void *mcode_alloc(jit_State *J, size_t sz)
+{
+ /* Target an address in the static assembler code (64K aligned).
+ ** Try addresses within a distance of target-range/2+1MB..target+range/2-1MB.
+ ** Use half the jump range so every address in the range can reach any other.
+ */
+#if LJ_TARGET_MIPS
+ /* Use the middle of the 256MB-aligned region. */
+ uintptr_t target = ((uintptr_t)(void *)lj_vm_exit_handler & 0xf0000000u) +
+ 0x08000000u;
+#else
+ uintptr_t target = (uintptr_t)(void *)lj_vm_exit_handler & ~(uintptr_t)0xffff;
+#endif
+ const uintptr_t range = (1u << (LJ_TARGET_JUMPRANGE-1)) - (1u << 21);
+ /* First try a contiguous area below the last one. */
+ uintptr_t hint = J->mcarea ? (uintptr_t)J->mcarea - sz : 0;
+ int i;
+ /* Limit probing iterations, depending on the available pool size. */
+ for (i = 0; i < LJ_TARGET_JUMPRANGE; i++) {
+ if (mcode_validptr(hint)) {
+ void *p = mcode_alloc_at(J, hint, sz, MCPROT_GEN);
+
+ if (mcode_validptr(p) &&
+ ((uintptr_t)p + sz - target < range || target - (uintptr_t)p < range))
+ return p;
+ if (p) mcode_free(J, p, sz); /* Free badly placed area. */
+ }
+ /* Next try probing 64K-aligned pseudo-random addresses. */
+ do {
+ hint = LJ_PRNG_BITS(J, LJ_TARGET_JUMPRANGE-16) << 16;
+ } while (!(hint + sz < range+range));
+ hint = target + hint - range;
+ }
+ lj_trace_err(J, LJ_TRERR_MCODEAL); /* Give up. OS probably ignores hints? */
+ return NULL;
+}
+
+#else
+
+/* All memory addresses are reachable by relative jumps. */
+static void *mcode_alloc(jit_State *J, size_t sz)
+{
+#ifdef __OpenBSD__
+ /* Allow better executable memory allocation for OpenBSD W^X mode. */
+ void *p = mcode_alloc_at(J, 0, sz, MCPROT_RUN);
+ if (p && mcode_setprot(p, sz, MCPROT_GEN)) {
+ mcode_free(J, p, sz);
+ return NULL;
+ }
+ return p;
+#else
+ return mcode_alloc_at(J, 0, sz, MCPROT_GEN);
+#endif
+}
+
+#endif
+
+/* -- MCode area management ----------------------------------------------- */
+
+/* Allocate a new MCode area. */
+static void mcode_allocarea(jit_State *J)
+{
+ MCode *oldarea = J->mcarea;
+ size_t sz = (size_t)J->param[JIT_P_sizemcode] << 10;
+ sz = (sz + LJ_PAGESIZE-1) & ~(size_t)(LJ_PAGESIZE - 1);
+ J->mcarea = (MCode *)mcode_alloc(J, sz);
+ J->szmcarea = sz;
+ J->mcprot = MCPROT_GEN;
+ J->mctop = (MCode *)((char *)J->mcarea + J->szmcarea);
+ J->mcbot = (MCode *)((char *)J->mcarea + sizeof(MCLink));
+ ((MCLink *)J->mcarea)->next = oldarea;
+ ((MCLink *)J->mcarea)->size = sz;
+ J->szallmcarea += sz;
+}
+
+/* Free all MCode areas. */
+void lj_mcode_free(jit_State *J)
+{
+ MCode *mc = J->mcarea;
+ J->mcarea = NULL;
+ J->szallmcarea = 0;
+ while (mc) {
+ MCode *next = ((MCLink *)mc)->next;
+ mcode_free(J, mc, ((MCLink *)mc)->size);
+ mc = next;
+ }
+}
+
+/* -- MCode transactions -------------------------------------------------- */
+
+/* Reserve the remainder of the current MCode area. */
+MCode *lj_mcode_reserve(jit_State *J, MCode **lim)
+{
+ if (!J->mcarea)
+ mcode_allocarea(J);
+ else
+ mcode_protect(J, MCPROT_GEN);
+ *lim = J->mcbot;
+ return J->mctop;
+}
+
+/* Commit the top part of the current MCode area. */
+void lj_mcode_commit(jit_State *J, MCode *top)
+{
+ J->mctop = top;
+ mcode_protect(J, MCPROT_RUN);
+}
+
+/* Abort the reservation. */
+void lj_mcode_abort(jit_State *J)
+{
+ if (J->mcarea)
+ mcode_protect(J, MCPROT_RUN);
+}
+
+/* Set/reset protection to allow patching of MCode areas. */
+MCode *lj_mcode_patch(jit_State *J, MCode *ptr, int finish)
+{
+#ifdef LUAJIT_UNPROTECT_MCODE
+ UNUSED(J); UNUSED(ptr); UNUSED(finish);
+ return NULL;
+#else
+ if (finish) {
+ if (J->mcarea == ptr)
+ mcode_protect(J, MCPROT_RUN);
+ else if (LJ_UNLIKELY(mcode_setprot(ptr, ((MCLink *)ptr)->size, MCPROT_RUN)))
+ mcode_protfail(J);
+ return NULL;
+ } else {
+ MCode *mc = J->mcarea;
+ /* Try current area first to use the protection cache. */
+ if (ptr >= mc && ptr < (MCode *)((char *)mc + J->szmcarea)) {
+ mcode_protect(J, MCPROT_GEN);
+ return mc;
+ }
+ /* Otherwise search through the list of MCode areas. */
+ for (;;) {
+ mc = ((MCLink *)mc)->next;
+ lua_assert(mc != NULL);
+ if (ptr >= mc && ptr < (MCode *)((char *)mc + ((MCLink *)mc)->size)) {
+ if (LJ_UNLIKELY(mcode_setprot(mc, ((MCLink *)mc)->size, MCPROT_GEN)))
+ mcode_protfail(J);
+ return mc;
+ }
+ }
+ }
+#endif
+}
+
+/* Limit of MCode reservation reached. */
+void lj_mcode_limiterr(jit_State *J, size_t need)
+{
+ size_t sizemcode, maxmcode;
+ lj_mcode_abort(J);
+ sizemcode = (size_t)J->param[JIT_P_sizemcode] << 10;
+ sizemcode = (sizemcode + LJ_PAGESIZE-1) & ~(size_t)(LJ_PAGESIZE - 1);
+ maxmcode = (size_t)J->param[JIT_P_maxmcode] << 10;
+ if ((size_t)need > sizemcode)
+ lj_trace_err(J, LJ_TRERR_MCODEOV); /* Too long for any area. */
+ if (J->szallmcarea + sizemcode > maxmcode)
+ lj_trace_err(J, LJ_TRERR_MCODEAL);
+ mcode_allocarea(J);
+ lj_trace_err(J, LJ_TRERR_MCODELM); /* Retry with new area. */
+}
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_mcode.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_mcode.h
new file mode 100644
index 0000000..f0847e9
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_mcode.h
@@ -0,0 +1,30 @@
+/*
+** Machine code management.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_MCODE_H
+#define _LJ_MCODE_H
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT || LJ_HASFFI
+LJ_FUNC void lj_mcode_sync(void *start, void *end);
+#endif
+
+#if LJ_HASJIT
+
+#include "lj_jit.h"
+
+LJ_FUNC void lj_mcode_free(jit_State *J);
+LJ_FUNC MCode *lj_mcode_reserve(jit_State *J, MCode **lim);
+LJ_FUNC void lj_mcode_commit(jit_State *J, MCode *m);
+LJ_FUNC void lj_mcode_abort(jit_State *J);
+LJ_FUNC MCode *lj_mcode_patch(jit_State *J, MCode *ptr, int finish);
+LJ_FUNC_NORET void lj_mcode_limiterr(jit_State *J, size_t need);
+
+#define lj_mcode_commitbot(J, m) (J->mcbot = (m))
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_meta.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_meta.c
new file mode 100644
index 0000000..10e3498
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_meta.c
@@ -0,0 +1,466 @@
+/*
+** Metamethod handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#define lj_meta_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_meta.h"
+#include "lj_frame.h"
+#include "lj_bc.h"
+#include "lj_vm.h"
+#include "lj_strscan.h"
+
+/* -- Metamethod handling ------------------------------------------------- */
+
+/* String interning of metamethod names for fast indexing. */
+void lj_meta_init(lua_State *L)
+{
+#define MMNAME(name) "__" #name
+ const char *metanames = MMDEF(MMNAME);
+#undef MMNAME
+ global_State *g = G(L);
+ const char *p, *q;
+ uint32_t mm;
+ for (mm = 0, p = metanames; *p; mm++, p = q) {
+ GCstr *s;
+ for (q = p+2; *q && *q != '_'; q++) ;
+ s = lj_str_new(L, p, (size_t)(q-p));
+ /* NOBARRIER: g->gcroot[] is a GC root. */
+ setgcref(g->gcroot[GCROOT_MMNAME+mm], obj2gco(s));
+ }
+}
+
+/* Negative caching of a few fast metamethods. See the lj_meta_fast() macro. */
+cTValue *lj_meta_cache(GCtab *mt, MMS mm, GCstr *name)
+{
+ cTValue *mo = lj_tab_getstr(mt, name);
+ lua_assert(mm <= MM_FAST);
+ if (!mo || tvisnil(mo)) { /* No metamethod? */
+ mt->nomm |= (uint8_t)(1u<<mm); /* Set negative cache flag. */
+ return NULL;
+ }
+ return mo;
+}
+
+/* Lookup metamethod for object. */
+cTValue *lj_meta_lookup(lua_State *L, cTValue *o, MMS mm)
+{
+ GCtab *mt;
+ if (tvistab(o))
+ mt = tabref(tabV(o)->metatable);
+ else if (tvisudata(o))
+ mt = tabref(udataV(o)->metatable);
+ else
+ mt = tabref(basemt_obj(G(L), o));
+ if (mt) {
+ cTValue *mo = lj_tab_getstr(mt, mmname_str(G(L), mm));
+ if (mo)
+ return mo;
+ }
+ return niltv(L);
+}
+
+#if LJ_HASFFI
+/* Tailcall from C function. */
+int lj_meta_tailcall(lua_State *L, cTValue *tv)
+{
+ TValue *base = L->base;
+ TValue *top = L->top;
+ const BCIns *pc = frame_pc(base-1); /* Preserve old PC from frame. */
+ copyTV(L, base-1, tv); /* Replace frame with new object. */
+ top->u32.lo = LJ_CONT_TAILCALL;
+ setframe_pc(top, pc);
+ setframe_gc(top+1, obj2gco(L)); /* Dummy frame object. */
+ setframe_ftsz(top+1, (int)((char *)(top+2) - (char *)base) + FRAME_CONT);
+ L->base = L->top = top+2;
+ /*
+ ** before: [old_mo|PC] [... ...]
+ ** ^base ^top
+ ** after: [new_mo|itype] [... ...] [NULL|PC] [dummy|delta]
+ ** ^base/top
+ ** tailcall: [new_mo|PC] [... ...]
+ ** ^base ^top
+ */
+ return 0;
+}
+#endif
+
+/* Setup call to metamethod to be run by Assembler VM. */
+static TValue *mmcall(lua_State *L, ASMFunction cont, cTValue *mo,
+ cTValue *a, cTValue *b)
+{
+ /*
+ ** |-- framesize -> top top+1 top+2 top+3
+ ** before: [func slots ...]
+ ** mm setup: [func slots ...] [cont|?] [mo|tmtype] [a] [b]
+ ** in asm: [func slots ...] [cont|PC] [mo|delta] [a] [b]
+ ** ^-- func base ^-- mm base
+ ** after mm: [func slots ...] [result]
+ ** ^-- copy to base[PC_RA] --/ for lj_cont_ra
+ ** istruecond + branch for lj_cont_cond*
+ ** ignore for lj_cont_nop
+ ** next PC: [func slots ...]
+ */
+ TValue *top = L->top;
+ if (curr_funcisL(L)) top = curr_topL(L);
+ setcont(top, cont); /* Assembler VM stores PC in upper word. */
+ copyTV(L, top+1, mo); /* Store metamethod and two arguments. */
+ copyTV(L, top+2, a);
+ copyTV(L, top+3, b);
+ return top+2; /* Return new base. */
+}
+
+/* -- C helpers for some instructions, called from assembler VM ----------- */
+
+/* Helper for TGET*. __index chain and metamethod. */
+cTValue *lj_meta_tget(lua_State *L, cTValue *o, cTValue *k)
+{
+ int loop;
+ for (loop = 0; loop < LJ_MAX_IDXCHAIN; loop++) {
+ cTValue *mo;
+ if (LJ_LIKELY(tvistab(o))) {
+ GCtab *t = tabV(o);
+ cTValue *tv = lj_tab_get(L, t, k);
+ if (!tvisnil(tv) ||
+ !(mo = lj_meta_fast(L, tabref(t->metatable), MM_index)))
+ return tv;
+ } else if (tvisnil(mo = lj_meta_lookup(L, o, MM_index))) {
+ lj_err_optype(L, o, LJ_ERR_OPINDEX);
+ return NULL; /* unreachable */
+ }
+ if (tvisfunc(mo)) {
+ L->top = mmcall(L, lj_cont_ra, mo, o, k);
+ return NULL; /* Trigger metamethod call. */
+ }
+ o = mo;
+ }
+ lj_err_msg(L, LJ_ERR_GETLOOP);
+ return NULL; /* unreachable */
+}
+
+/* Helper for TSET*. __newindex chain and metamethod. */
+TValue *lj_meta_tset(lua_State *L, cTValue *o, cTValue *k)
+{
+ TValue tmp;
+ int loop;
+ for (loop = 0; loop < LJ_MAX_IDXCHAIN; loop++) {
+ cTValue *mo;
+ if (LJ_LIKELY(tvistab(o))) {
+ GCtab *t = tabV(o);
+ cTValue *tv = lj_tab_get(L, t, k);
+ if (LJ_LIKELY(!tvisnil(tv))) {
+ t->nomm = 0; /* Invalidate negative metamethod cache. */
+ lj_gc_anybarriert(L, t);
+ return (TValue *)tv;
+ } else if (!(mo = lj_meta_fast(L, tabref(t->metatable), MM_newindex))) {
+ t->nomm = 0; /* Invalidate negative metamethod cache. */
+ lj_gc_anybarriert(L, t);
+ if (tv != niltv(L))
+ return (TValue *)tv;
+ if (tvisnil(k)) lj_err_msg(L, LJ_ERR_NILIDX);
+ else if (tvisint(k)) { setnumV(&tmp, (lua_Number)intV(k)); k = &tmp; }
+ else if (tvisnum(k) && tvisnan(k)) lj_err_msg(L, LJ_ERR_NANIDX);
+ return lj_tab_newkey(L, t, k);
+ }
+ } else if (tvisnil(mo = lj_meta_lookup(L, o, MM_newindex))) {
+ lj_err_optype(L, o, LJ_ERR_OPINDEX);
+ return NULL; /* unreachable */
+ }
+ if (tvisfunc(mo)) {
+ L->top = mmcall(L, lj_cont_nop, mo, o, k);
+ /* L->top+2 = v filled in by caller. */
+ return NULL; /* Trigger metamethod call. */
+ }
+ copyTV(L, &tmp, mo);
+ o = &tmp;
+ }
+ lj_err_msg(L, LJ_ERR_SETLOOP);
+ return NULL; /* unreachable */
+}
+
+static cTValue *str2num(cTValue *o, TValue *n)
+{
+ if (tvisnum(o))
+ return o;
+ else if (tvisint(o))
+ return (setnumV(n, (lua_Number)intV(o)), n);
+ else if (tvisstr(o) && lj_strscan_num(strV(o), n))
+ return n;
+ else
+ return NULL;
+}
+
+/* Helper for arithmetic instructions. Coercion, metamethod. */
+TValue *lj_meta_arith(lua_State *L, TValue *ra, cTValue *rb, cTValue *rc,
+ BCReg op)
+{
+ MMS mm = bcmode_mm(op);
+ TValue tempb, tempc;
+ cTValue *b, *c;
+ if ((b = str2num(rb, &tempb)) != NULL &&
+ (c = str2num(rc, &tempc)) != NULL) { /* Try coercion first. */
+ setnumV(ra, lj_vm_foldarith(numV(b), numV(c), (int)mm-MM_add));
+ return NULL;
+ } else {
+ cTValue *mo = lj_meta_lookup(L, rb, mm);
+ if (tvisnil(mo)) {
+ mo = lj_meta_lookup(L, rc, mm);
+ if (tvisnil(mo)) {
+ if (str2num(rb, &tempb) == NULL) rc = rb;
+ lj_err_optype(L, rc, LJ_ERR_OPARITH);
+ return NULL; /* unreachable */
+ }
+ }
+ return mmcall(L, lj_cont_ra, mo, rb, rc);
+ }
+}
+
+/* In-place coercion of a number to a string. */
+static LJ_AINLINE int tostring(lua_State *L, TValue *o)
+{
+ if (tvisstr(o)) {
+ return 1;
+ } else if (tvisnumber(o)) {
+ setstrV(L, o, lj_str_fromnumber(L, o));
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+/* Helper for CAT. Coercion, iterative concat, __concat metamethod. */
+TValue *lj_meta_cat(lua_State *L, TValue *top, int left)
+{
+ int fromc = 0;
+ if (left < 0) { left = -left; fromc = 1; }
+ do {
+ int n = 1;
+ if (!(tvisstr(top-1) || tvisnumber(top-1)) || !tostring(L, top)) {
+ cTValue *mo = lj_meta_lookup(L, top-1, MM_concat);
+ if (tvisnil(mo)) {
+ mo = lj_meta_lookup(L, top, MM_concat);
+ if (tvisnil(mo)) {
+ if (tvisstr(top-1) || tvisnumber(top-1)) top++;
+ lj_err_optype(L, top-1, LJ_ERR_OPCAT);
+ return NULL; /* unreachable */
+ }
+ }
+ /* One of the top two elements is not a string, call __cat metamethod:
+ **
+ ** before: [...][CAT stack .........................]
+ ** top-1 top top+1 top+2
+ ** pick two: [...][CAT stack ...] [o1] [o2]
+ ** setup mm: [...][CAT stack ...] [cont|?] [mo|tmtype] [o1] [o2]
+ ** in asm: [...][CAT stack ...] [cont|PC] [mo|delta] [o1] [o2]
+ ** ^-- func base ^-- mm base
+ ** after mm: [...][CAT stack ...] <--push-- [result]
+ ** next step: [...][CAT stack .............]
+ */
+ copyTV(L, top+2, top); /* Careful with the order of stack copies! */
+ copyTV(L, top+1, top-1);
+ copyTV(L, top, mo);
+ setcont(top-1, lj_cont_cat);
+ return top+1; /* Trigger metamethod call. */
+ } else if (strV(top)->len == 0) { /* Shortcut. */
+ (void)tostring(L, top-1);
+ } else {
+ /* Pick as many strings as possible from the top and concatenate them:
+ **
+ ** before: [...][CAT stack ...........................]
+ ** pick str: [...][CAT stack ...] [...... strings ......]
+ ** concat: [...][CAT stack ...] [result]
+ ** next step: [...][CAT stack ............]
+ */
+ MSize tlen = strV(top)->len;
+ char *buffer;
+ int i;
+ for (n = 1; n <= left && tostring(L, top-n); n++) {
+ MSize len = strV(top-n)->len;
+ if (len >= LJ_MAX_STR - tlen)
+ lj_err_msg(L, LJ_ERR_STROV);
+ tlen += len;
+ }
+ buffer = lj_str_needbuf(L, &G(L)->tmpbuf, tlen);
+ n--;
+ tlen = 0;
+ for (i = n; i >= 0; i--) {
+ MSize len = strV(top-i)->len;
+ memcpy(buffer + tlen, strVdata(top-i), len);
+ tlen += len;
+ }
+ setstrV(L, top-n, lj_str_new(L, buffer, tlen));
+ }
+ left -= n;
+ top -= n;
+ } while (left >= 1);
+ if (LJ_UNLIKELY(G(L)->gc.total >= G(L)->gc.threshold)) {
+ if (!fromc) L->top = curr_topL(L);
+ lj_gc_step(L);
+ }
+ return NULL;
+}
+
+/* Helper for LEN. __len metamethod. */
+TValue * LJ_FASTCALL lj_meta_len(lua_State *L, cTValue *o)
+{
+ cTValue *mo = lj_meta_lookup(L, o, MM_len);
+ if (tvisnil(mo)) {
+ if (LJ_52 && tvistab(o))
+ tabref(tabV(o)->metatable)->nomm |= (uint8_t)(1u<<MM_len);
+ else
+ lj_err_optype(L, o, LJ_ERR_OPLEN);
+ return NULL;
+ }
+ return mmcall(L, lj_cont_ra, mo, o, LJ_52 ? o : niltv(L));
+}
+
+/* Helper for equality comparisons. __eq metamethod. */
+TValue *lj_meta_equal(lua_State *L, GCobj *o1, GCobj *o2, int ne)
+{
+ /* Field metatable must be at same offset for GCtab and GCudata! */
+ cTValue *mo = lj_meta_fast(L, tabref(o1->gch.metatable), MM_eq);
+ if (mo) {
+ TValue *top;
+ uint32_t it;
+ if (tabref(o1->gch.metatable) != tabref(o2->gch.metatable)) {
+ cTValue *mo2 = lj_meta_fast(L, tabref(o2->gch.metatable), MM_eq);
+ if (mo2 == NULL || !lj_obj_equal(mo, mo2))
+ return (TValue *)(intptr_t)ne;
+ }
+ top = curr_top(L);
+ setcont(top, ne ? lj_cont_condf : lj_cont_condt);
+ copyTV(L, top+1, mo);
+ it = ~(uint32_t)o1->gch.gct;
+ setgcV(L, top+2, o1, it);
+ setgcV(L, top+3, o2, it);
+ return top+2; /* Trigger metamethod call. */
+ }
+ return (TValue *)(intptr_t)ne;
+}
+
+#if LJ_HASFFI
+TValue * LJ_FASTCALL lj_meta_equal_cd(lua_State *L, BCIns ins)
+{
+ ASMFunction cont = (bc_op(ins) & 1) ? lj_cont_condf : lj_cont_condt;
+ int op = (int)bc_op(ins) & ~1;
+ TValue tv;
+ cTValue *mo, *o2, *o1 = &L->base[bc_a(ins)];
+ cTValue *o1mm = o1;
+ if (op == BC_ISEQV) {
+ o2 = &L->base[bc_d(ins)];
+ if (!tviscdata(o1mm)) o1mm = o2;
+ } else if (op == BC_ISEQS) {
+ setstrV(L, &tv, gco2str(proto_kgc(curr_proto(L), ~(ptrdiff_t)bc_d(ins))));
+ o2 = &tv;
+ } else if (op == BC_ISEQN) {
+ o2 = &mref(curr_proto(L)->k, cTValue)[bc_d(ins)];
+ } else {
+ lua_assert(op == BC_ISEQP);
+ setitype(&tv, ~bc_d(ins));
+ o2 = &tv;
+ }
+ mo = lj_meta_lookup(L, o1mm, MM_eq);
+ if (LJ_LIKELY(!tvisnil(mo)))
+ return mmcall(L, cont, mo, o1, o2);
+ else
+ return (TValue *)(intptr_t)(bc_op(ins) & 1);
+}
+#endif
+
+/* Helper for ordered comparisons. String compare, __lt/__le metamethods. */
+TValue *lj_meta_comp(lua_State *L, cTValue *o1, cTValue *o2, int op)
+{
+ if (LJ_HASFFI && (tviscdata(o1) || tviscdata(o2))) {
+ ASMFunction cont = (op & 1) ? lj_cont_condf : lj_cont_condt;
+ MMS mm = (op & 2) ? MM_le : MM_lt;
+ cTValue *mo = lj_meta_lookup(L, tviscdata(o1) ? o1 : o2, mm);
+ if (LJ_UNLIKELY(tvisnil(mo))) goto err;
+ return mmcall(L, cont, mo, o1, o2);
+ } else if (LJ_52 || itype(o1) == itype(o2)) {
+ /* Never called with two numbers. */
+ if (tvisstr(o1) && tvisstr(o2)) {
+ int32_t res = lj_str_cmp(strV(o1), strV(o2));
+ return (TValue *)(intptr_t)(((op&2) ? res <= 0 : res < 0) ^ (op&1));
+ } else {
+ trymt:
+ while (1) {
+ ASMFunction cont = (op & 1) ? lj_cont_condf : lj_cont_condt;
+ MMS mm = (op & 2) ? MM_le : MM_lt;
+ cTValue *mo = lj_meta_lookup(L, o1, mm);
+#if LJ_52
+ if (tvisnil(mo) && tvisnil((mo = lj_meta_lookup(L, o2, mm))))
+#else
+ cTValue *mo2 = lj_meta_lookup(L, o2, mm);
+ if (tvisnil(mo) || !lj_obj_equal(mo, mo2))
+#endif
+ {
+ if (op & 2) { /* MM_le not found: retry with MM_lt. */
+ cTValue *ot = o1; o1 = o2; o2 = ot; /* Swap operands. */
+ op ^= 3; /* Use LT and flip condition. */
+ continue;
+ }
+ goto err;
+ }
+ return mmcall(L, cont, mo, o1, o2);
+ }
+ }
+ } else if (tvisbool(o1) && tvisbool(o2)) {
+ goto trymt;
+ } else {
+ err:
+ lj_err_comp(L, o1, o2);
+ return NULL;
+ }
+}
+
+/* Helper for calls. __call metamethod. */
+void lj_meta_call(lua_State *L, TValue *func, TValue *top)
+{
+ cTValue *mo = lj_meta_lookup(L, func, MM_call);
+ TValue *p;
+ if (!tvisfunc(mo))
+ lj_err_optype_call(L, func);
+ for (p = top; p > func; p--) copyTV(L, p, p-1);
+ copyTV(L, func, mo);
+}
+
+/* Helper for FORI. Coercion. */
+void LJ_FASTCALL lj_meta_for(lua_State *L, TValue *o)
+{
+ if (!lj_strscan_numberobj(o)) lj_err_msg(L, LJ_ERR_FORINIT);
+ if (!lj_strscan_numberobj(o+1)) lj_err_msg(L, LJ_ERR_FORLIM);
+ if (!lj_strscan_numberobj(o+2)) lj_err_msg(L, LJ_ERR_FORSTEP);
+ if (LJ_DUALNUM) {
+ /* Ensure all slots are integers or all slots are numbers. */
+ int32_t k[3];
+ int nint = 0;
+ ptrdiff_t i;
+ for (i = 0; i <= 2; i++) {
+ if (tvisint(o+i)) {
+ k[i] = intV(o+i); nint++;
+ } else {
+ k[i] = lj_num2int(numV(o+i)); nint += ((lua_Number)k[i] == numV(o+i));
+ }
+ }
+ if (nint == 3) { /* Narrow to integers. */
+ setintV(o, k[0]);
+ setintV(o+1, k[1]);
+ setintV(o+2, k[2]);
+ } else if (nint != 0) { /* Widen to numbers. */
+ if (tvisint(o)) setnumV(o, (lua_Number)intV(o));
+ if (tvisint(o+1)) setnumV(o+1, (lua_Number)intV(o+1));
+ if (tvisint(o+2)) setnumV(o+2, (lua_Number)intV(o+2));
+ }
+ }
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_meta.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_meta.h
new file mode 100644
index 0000000..e061d99
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_meta.h
@@ -0,0 +1,37 @@
+/*
+** Metamethod handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_META_H
+#define _LJ_META_H
+
+#include "lj_obj.h"
+
+/* Metamethod handling */
+LJ_FUNC void lj_meta_init(lua_State *L);
+LJ_FUNC cTValue *lj_meta_cache(GCtab *mt, MMS mm, GCstr *name);
+LJ_FUNC cTValue *lj_meta_lookup(lua_State *L, cTValue *o, MMS mm);
+#if LJ_HASFFI
+LJ_FUNC int lj_meta_tailcall(lua_State *L, cTValue *tv);
+#endif
+
+#define lj_meta_fastg(g, mt, mm) \
+ ((mt) == NULL ? NULL : ((mt)->nomm & (1u<<(mm))) ? NULL : \
+ lj_meta_cache(mt, mm, mmname_str(g, mm)))
+#define lj_meta_fast(L, mt, mm) lj_meta_fastg(G(L), mt, mm)
+
+/* C helpers for some instructions, called from assembler VM. */
+LJ_FUNCA cTValue *lj_meta_tget(lua_State *L, cTValue *o, cTValue *k);
+LJ_FUNCA TValue *lj_meta_tset(lua_State *L, cTValue *o, cTValue *k);
+LJ_FUNCA TValue *lj_meta_arith(lua_State *L, TValue *ra, cTValue *rb,
+ cTValue *rc, BCReg op);
+LJ_FUNCA TValue *lj_meta_cat(lua_State *L, TValue *top, int left);
+LJ_FUNCA TValue * LJ_FASTCALL lj_meta_len(lua_State *L, cTValue *o);
+LJ_FUNCA TValue *lj_meta_equal(lua_State *L, GCobj *o1, GCobj *o2, int ne);
+LJ_FUNCA TValue * LJ_FASTCALL lj_meta_equal_cd(lua_State *L, BCIns ins);
+LJ_FUNCA TValue *lj_meta_comp(lua_State *L, cTValue *o1, cTValue *o2, int op);
+LJ_FUNCA void lj_meta_call(lua_State *L, TValue *func, TValue *top);
+LJ_FUNCA void LJ_FASTCALL lj_meta_for(lua_State *L, TValue *o);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_obj.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_obj.c
new file mode 100644
index 0000000..4779d26
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_obj.c
@@ -0,0 +1,35 @@
+/*
+** Miscellaneous object handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_obj_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+
+/* Object type names. */
+LJ_DATADEF const char *const lj_obj_typename[] = { /* ORDER LUA_T */
+ "no value", "nil", "boolean", "userdata", "number", "string",
+ "table", "function", "userdata", "thread", "proto", "cdata"
+};
+
+LJ_DATADEF const char *const lj_obj_itypename[] = { /* ORDER LJ_T */
+ "nil", "boolean", "boolean", "userdata", "string", "upval", "thread",
+ "proto", "function", "trace", "cdata", "table", "userdata", "number"
+};
+
+/* Compare two objects without calling metamethods. */
+int lj_obj_equal(cTValue *o1, cTValue *o2)
+{
+ if (itype(o1) == itype(o2)) {
+ if (tvispri(o1))
+ return 1;
+ if (!tvisnum(o1))
+ return gcrefeq(o1->gcr, o2->gcr);
+ } else if (!tvisnumber(o1) || !tvisnumber(o2)) {
+ return 0;
+ }
+ return numberVnum(o1) == numberVnum(o2);
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_obj.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_obj.h
new file mode 100644
index 0000000..2ee526c
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_obj.h
@@ -0,0 +1,864 @@
+/*
+** LuaJIT VM tags, values and objects.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#ifndef _LJ_OBJ_H
+#define _LJ_OBJ_H
+
+#include "lua.h"
+#include "lj_def.h"
+#include "lj_arch.h"
+
+/* -- Memory references (32 bit address space) ---------------------------- */
+
+/* Memory size. */
+typedef uint32_t MSize;
+
+/* Memory reference */
+typedef struct MRef {
+ uint32_t ptr32; /* Pseudo 32 bit pointer. */
+} MRef;
+
+#define mref(r, t) ((t *)(void *)(uintptr_t)(r).ptr32)
+
+#define setmref(r, p) ((r).ptr32 = (uint32_t)(uintptr_t)(void *)(p))
+#define setmrefr(r, v) ((r).ptr32 = (v).ptr32)
+
+/* -- GC object references (32 bit address space) ------------------------- */
+
+/* GCobj reference */
+typedef struct GCRef {
+ uint32_t gcptr32; /* Pseudo 32 bit pointer. */
+} GCRef;
+
+/* Common GC header for all collectable objects. */
+#define GCHeader GCRef nextgc; uint8_t marked; uint8_t gct
+/* This occupies 6 bytes, so use the next 2 bytes for non-32 bit fields. */
+
+#define gcref(r) ((GCobj *)(uintptr_t)(r).gcptr32)
+#define gcrefp(r, t) ((t *)(void *)(uintptr_t)(r).gcptr32)
+#define gcrefu(r) ((r).gcptr32)
+#define gcrefi(r) ((int32_t)(r).gcptr32)
+#define gcrefeq(r1, r2) ((r1).gcptr32 == (r2).gcptr32)
+#define gcnext(gc) (gcref((gc)->gch.nextgc))
+
+#define setgcref(r, gc) ((r).gcptr32 = (uint32_t)(uintptr_t)&(gc)->gch)
+#define setgcrefi(r, i) ((r).gcptr32 = (uint32_t)(i))
+#define setgcrefp(r, p) ((r).gcptr32 = (uint32_t)(uintptr_t)(p))
+#define setgcrefnull(r) ((r).gcptr32 = 0)
+#define setgcrefr(r, v) ((r).gcptr32 = (v).gcptr32)
+
+/* IMPORTANT NOTE:
+**
+** All uses of the setgcref* macros MUST be accompanied with a write barrier.
+**
+** This is to ensure the integrity of the incremental GC. The invariant
+** to preserve is that a black object never points to a white object.
+** I.e. never store a white object into a field of a black object.
+**
+** It's ok to LEAVE OUT the write barrier ONLY in the following cases:
+** - The source is not a GC object (NULL).
+** - The target is a GC root. I.e. everything in global_State.
+** - The target is a lua_State field (threads are never black).
+** - The target is a stack slot, see setgcV et al.
+** - The target is an open upvalue, i.e. pointing to a stack slot.
+** - The target is a newly created object (i.e. marked white). But make
+** sure nothing invokes the GC inbetween.
+** - The target and the source are the same object (self-reference).
+** - The target already contains the object (e.g. moving elements around).
+**
+** The most common case is a store to a stack slot. All other cases where
+** a barrier has been omitted are annotated with a NOBARRIER comment.
+**
+** The same logic applies for stores to table slots (array part or hash
+** part). ALL uses of lj_tab_set* require a barrier for the stored value
+** *and* the stored key, based on the above rules. In practice this means
+** a barrier is needed if *either* of the key or value are a GC object.
+**
+** It's ok to LEAVE OUT the write barrier in the following special cases:
+** - The stored value is nil. The key doesn't matter because it's either
+** not resurrected or lj_tab_newkey() will take care of the key barrier.
+** - The key doesn't matter if the *previously* stored value is guaranteed
+** to be non-nil (because the key is kept alive in the table).
+** - The key doesn't matter if it's guaranteed not to be part of the table,
+** since lj_tab_newkey() takes care of the key barrier. This applies
+** trivially to new tables, but watch out for resurrected keys. Storing
+** a nil value leaves the key in the table!
+**
+** In case of doubt use lj_gc_anybarriert() as it's rather cheap. It's used
+** by the interpreter for all table stores.
+**
+** Note: In contrast to Lua's GC, LuaJIT's GC does *not* specially mark
+** dead keys in tables. The reference is left in, but it's guaranteed to
+** be never dereferenced as long as the value is nil. It's ok if the key is
+** freed or if any object subsequently gets the same address.
+**
+** Not destroying dead keys helps to keep key hash slots stable. This avoids
+** specialization back-off for HREFK when a value flips between nil and
+** non-nil and the GC gets in the way. It also allows safely hoisting
+** HREF/HREFK across GC steps. Dead keys are only removed if a table is
+** resized (i.e. by NEWREF) and xREF must not be CSEd across a resize.
+**
+** The trade-off is that a write barrier for tables must take the key into
+** account, too. Implicitly resurrecting the key by storing a non-nil value
+** may invalidate the incremental GC invariant.
+*/
+
+/* -- Common type definitions --------------------------------------------- */
+
+/* Types for handling bytecodes. Need this here, details in lj_bc.h. */
+typedef uint32_t BCIns; /* Bytecode instruction. */
+typedef uint32_t BCPos; /* Bytecode position. */
+typedef uint32_t BCReg; /* Bytecode register. */
+typedef int32_t BCLine; /* Bytecode line number. */
+
+/* Internal assembler functions. Never call these directly from C. */
+typedef void (*ASMFunction)(void);
+
+/* Resizable string buffer. Need this here, details in lj_str.h. */
+typedef struct SBuf {
+ char *buf; /* String buffer base. */
+ MSize n; /* String buffer length. */
+ MSize sz; /* String buffer size. */
+} SBuf;
+
+/* -- Tags and values ----------------------------------------------------- */
+
+/* Frame link. */
+typedef union {
+ int32_t ftsz; /* Frame type and size of previous frame. */
+ MRef pcr; /* Overlaps PC for Lua frames. */
+} FrameLink;
+
+/* Tagged value. */
+typedef LJ_ALIGN(8) union TValue {
+ uint64_t u64; /* 64 bit pattern overlaps number. */
+ lua_Number n; /* Number object overlaps split tag/value object. */
+ struct {
+ LJ_ENDIAN_LOHI(
+ union {
+ GCRef gcr; /* GCobj reference (if any). */
+ int32_t i; /* Integer value. */
+ };
+ , uint32_t it; /* Internal object tag. Must overlap MSW of number. */
+ )
+ };
+ struct {
+ LJ_ENDIAN_LOHI(
+ GCRef func; /* Function for next frame (or dummy L). */
+ , FrameLink tp; /* Link to previous frame. */
+ )
+ } fr;
+ struct {
+ LJ_ENDIAN_LOHI(
+ uint32_t lo; /* Lower 32 bits of number. */
+ , uint32_t hi; /* Upper 32 bits of number. */
+ )
+ } u32;
+} TValue;
+
+typedef const TValue cTValue;
+
+#define tvref(r) (mref(r, TValue))
+
+/* More external and GCobj tags for internal objects. */
+#define LAST_TT LUA_TTHREAD
+#define LUA_TPROTO (LAST_TT+1)
+#define LUA_TCDATA (LAST_TT+2)
+
+/* Internal object tags.
+**
+** Internal tags overlap the MSW of a number object (must be a double).
+** Interpreted as a double these are special NaNs. The FPU only generates
+** one type of NaN (0xfff8_0000_0000_0000). So MSWs > 0xfff80000 are available
+** for use as internal tags. Small negative numbers are used to shorten the
+** encoding of type comparisons (reg/mem against sign-ext. 8 bit immediate).
+**
+** ---MSW---.---LSW---
+** primitive types | itype | |
+** lightuserdata | itype | void * | (32 bit platforms)
+** lightuserdata |ffff| void * | (64 bit platforms, 47 bit pointers)
+** GC objects | itype | GCRef |
+** int (LJ_DUALNUM)| itype | int |
+** number -------double------
+**
+** ORDER LJ_T
+** Primitive types nil/false/true must be first, lightuserdata next.
+** GC objects are at the end, table/userdata must be lowest.
+** Also check lj_ir.h for similar ordering constraints.
+*/
+#define LJ_TNIL (~0u)
+#define LJ_TFALSE (~1u)
+#define LJ_TTRUE (~2u)
+#define LJ_TLIGHTUD (~3u)
+#define LJ_TSTR (~4u)
+#define LJ_TUPVAL (~5u)
+#define LJ_TTHREAD (~6u)
+#define LJ_TPROTO (~7u)
+#define LJ_TFUNC (~8u)
+#define LJ_TTRACE (~9u)
+#define LJ_TCDATA (~10u)
+#define LJ_TTAB (~11u)
+#define LJ_TUDATA (~12u)
+/* This is just the canonical number type used in some places. */
+#define LJ_TNUMX (~13u)
+
+/* Integers have itype == LJ_TISNUM doubles have itype < LJ_TISNUM */
+#if LJ_64
+#define LJ_TISNUM 0xfffeffffu
+#else
+#define LJ_TISNUM LJ_TNUMX
+#endif
+#define LJ_TISTRUECOND LJ_TFALSE
+#define LJ_TISPRI LJ_TTRUE
+#define LJ_TISGCV (LJ_TSTR+1)
+#define LJ_TISTABUD LJ_TTAB
+
+/* -- String object ------------------------------------------------------- */
+
+/* String object header. String payload follows. */
+typedef struct GCstr {
+ GCHeader;
+ uint8_t reserved; /* Used by lexer for fast lookup of reserved words. */
+ uint8_t unused;
+ MSize hash; /* Hash of string. */
+ MSize len; /* Size of string. */
+} GCstr;
+
+#define strref(r) (&gcref((r))->str)
+#define strdata(s) ((const char *)((s)+1))
+#define strdatawr(s) ((char *)((s)+1))
+#define strVdata(o) strdata(strV(o))
+#define sizestring(s) (sizeof(struct GCstr)+(s)->len+1)
+
+/* -- Userdata object ----------------------------------------------------- */
+
+/* Userdata object. Payload follows. */
+typedef struct GCudata {
+ GCHeader;
+ uint8_t udtype; /* Userdata type. */
+ uint8_t unused2;
+ GCRef env; /* Should be at same offset in GCfunc. */
+ MSize len; /* Size of payload. */
+ GCRef metatable; /* Must be at same offset in GCtab. */
+ uint32_t align1; /* To force 8 byte alignment of the payload. */
+} GCudata;
+
+/* Userdata types. */
+enum {
+ UDTYPE_USERDATA, /* Regular userdata. */
+ UDTYPE_IO_FILE, /* I/O library FILE. */
+ UDTYPE_FFI_CLIB, /* FFI C library namespace. */
+ UDTYPE__MAX
+};
+
+#define uddata(u) ((void *)((u)+1))
+#define sizeudata(u) (sizeof(struct GCudata)+(u)->len)
+
+/* -- C data object ------------------------------------------------------- */
+
+/* C data object. Payload follows. */
+typedef struct GCcdata {
+ GCHeader;
+ uint16_t ctypeid; /* C type ID. */
+} GCcdata;
+
+/* Prepended to variable-sized or realigned C data objects. */
+typedef struct GCcdataVar {
+ uint16_t offset; /* Offset to allocated memory (relative to GCcdata). */
+ uint16_t extra; /* Extra space allocated (incl. GCcdata + GCcdatav). */
+ MSize len; /* Size of payload. */
+} GCcdataVar;
+
+#define cdataptr(cd) ((void *)((cd)+1))
+#define cdataisv(cd) ((cd)->marked & 0x80)
+#define cdatav(cd) ((GCcdataVar *)((char *)(cd) - sizeof(GCcdataVar)))
+#define cdatavlen(cd) check_exp(cdataisv(cd), cdatav(cd)->len)
+#define sizecdatav(cd) (cdatavlen(cd) + cdatav(cd)->extra)
+#define memcdatav(cd) ((void *)((char *)(cd) - cdatav(cd)->offset))
+
+/* -- Prototype object ---------------------------------------------------- */
+
+#define SCALE_NUM_GCO ((int32_t)sizeof(lua_Number)/sizeof(GCRef))
+#define round_nkgc(n) (((n) + SCALE_NUM_GCO-1) & ~(SCALE_NUM_GCO-1))
+
+typedef struct GCproto {
+ GCHeader;
+ uint8_t numparams; /* Number of parameters. */
+ uint8_t framesize; /* Fixed frame size. */
+ MSize sizebc; /* Number of bytecode instructions. */
+ GCRef gclist;
+ MRef k; /* Split constant array (points to the middle). */
+ MRef uv; /* Upvalue list. local slot|0x8000 or parent uv idx. */
+ MSize sizekgc; /* Number of collectable constants. */
+ MSize sizekn; /* Number of lua_Number constants. */
+ MSize sizept; /* Total size including colocated arrays. */
+ uint8_t sizeuv; /* Number of upvalues. */
+ uint8_t flags; /* Miscellaneous flags (see below). */
+ uint16_t trace; /* Anchor for chain of root traces. */
+ /* ------ The following fields are for debugging/tracebacks only ------ */
+ GCRef chunkname; /* Name of the chunk this function was defined in. */
+ BCLine firstline; /* First line of the function definition. */
+ BCLine numline; /* Number of lines for the function definition. */
+ MRef lineinfo; /* Compressed map from bytecode ins. to source line. */
+ MRef uvinfo; /* Upvalue names. */
+ MRef varinfo; /* Names and compressed extents of local variables. */
+} GCproto;
+
+/* Flags for prototype. */
+#define PROTO_CHILD 0x01 /* Has child prototypes. */
+#define PROTO_VARARG 0x02 /* Vararg function. */
+#define PROTO_FFI 0x04 /* Uses BC_KCDATA for FFI datatypes. */
+#define PROTO_NOJIT 0x08 /* JIT disabled for this function. */
+#define PROTO_ILOOP 0x10 /* Patched bytecode with ILOOP etc. */
+/* Only used during parsing. */
+#define PROTO_HAS_RETURN 0x20 /* Already emitted a return. */
+#define PROTO_FIXUP_RETURN 0x40 /* Need to fixup emitted returns. */
+/* Top bits used for counting created closures. */
+#define PROTO_CLCOUNT 0x20 /* Base of saturating 3 bit counter. */
+#define PROTO_CLC_BITS 3
+#define PROTO_CLC_POLY (3*PROTO_CLCOUNT) /* Polymorphic threshold. */
+
+#define PROTO_UV_LOCAL 0x8000 /* Upvalue for local slot. */
+#define PROTO_UV_IMMUTABLE 0x4000 /* Immutable upvalue. */
+
+#define proto_kgc(pt, idx) \
+ check_exp((uintptr_t)(intptr_t)(idx) >= (uintptr_t)-(intptr_t)(pt)->sizekgc, \
+ gcref(mref((pt)->k, GCRef)[(idx)]))
+#define proto_knumtv(pt, idx) \
+ check_exp((uintptr_t)(idx) < (pt)->sizekn, &mref((pt)->k, TValue)[(idx)])
+#define proto_bc(pt) ((BCIns *)((char *)(pt) + sizeof(GCproto)))
+#define proto_bcpos(pt, pc) ((BCPos)((pc) - proto_bc(pt)))
+#define proto_uv(pt) (mref((pt)->uv, uint16_t))
+
+#define proto_chunkname(pt) (strref((pt)->chunkname))
+#define proto_chunknamestr(pt) (strdata(proto_chunkname((pt))))
+#define proto_lineinfo(pt) (mref((pt)->lineinfo, const void))
+#define proto_uvinfo(pt) (mref((pt)->uvinfo, const uint8_t))
+#define proto_varinfo(pt) (mref((pt)->varinfo, const uint8_t))
+
+/* -- Upvalue object ------------------------------------------------------ */
+
+typedef struct GCupval {
+ GCHeader;
+ uint8_t closed; /* Set if closed (i.e. uv->v == &uv->u.value). */
+ uint8_t immutable; /* Immutable value. */
+ union {
+ TValue tv; /* If closed: the value itself. */
+ struct { /* If open: double linked list, anchored at thread. */
+ GCRef prev;
+ GCRef next;
+ };
+ };
+ MRef v; /* Points to stack slot (open) or above (closed). */
+ uint32_t dhash; /* Disambiguation hash: dh1 != dh2 => cannot alias. */
+} GCupval;
+
+#define uvprev(uv_) (&gcref((uv_)->prev)->uv)
+#define uvnext(uv_) (&gcref((uv_)->next)->uv)
+#define uvval(uv_) (mref((uv_)->v, TValue))
+
+/* -- Function object (closures) ------------------------------------------ */
+
+/* Common header for functions. env should be at same offset in GCudata. */
+#define GCfuncHeader \
+ GCHeader; uint8_t ffid; uint8_t nupvalues; \
+ GCRef env; GCRef gclist; MRef pc
+
+typedef struct GCfuncC {
+ GCfuncHeader;
+ lua_CFunction f; /* C function to be called. */
+ TValue upvalue[1]; /* Array of upvalues (TValue). */
+} GCfuncC;
+
+typedef struct GCfuncL {
+ GCfuncHeader;
+ GCRef uvptr[1]; /* Array of _pointers_ to upvalue objects (GCupval). */
+} GCfuncL;
+
+typedef union GCfunc {
+ GCfuncC c;
+ GCfuncL l;
+} GCfunc;
+
+#define FF_LUA 0
+#define FF_C 1
+#define isluafunc(fn) ((fn)->c.ffid == FF_LUA)
+#define iscfunc(fn) ((fn)->c.ffid == FF_C)
+#define isffunc(fn) ((fn)->c.ffid > FF_C)
+#define funcproto(fn) \
+ check_exp(isluafunc(fn), (GCproto *)(mref((fn)->l.pc, char)-sizeof(GCproto)))
+#define sizeCfunc(n) (sizeof(GCfuncC)-sizeof(TValue)+sizeof(TValue)*(n))
+#define sizeLfunc(n) (sizeof(GCfuncL)-sizeof(GCRef)+sizeof(GCRef)*(n))
+
+/* -- Table object -------------------------------------------------------- */
+
+/* Hash node. */
+typedef struct Node {
+ TValue val; /* Value object. Must be first field. */
+ TValue key; /* Key object. */
+ MRef next; /* Hash chain. */
+ MRef freetop; /* Top of free elements (stored in t->node[0]). */
+} Node;
+
+LJ_STATIC_ASSERT(offsetof(Node, val) == 0);
+
+typedef struct GCtab {
+ GCHeader;
+ uint8_t nomm; /* Negative cache for fast metamethods. */
+ int8_t colo; /* Array colocation. */
+ MRef array; /* Array part. */
+ GCRef gclist;
+ GCRef metatable; /* Must be at same offset in GCudata. */
+ MRef node; /* Hash part. */
+ uint32_t asize; /* Size of array part (keys [0, asize-1]). */
+ uint32_t hmask; /* Hash part mask (size of hash part - 1). */
+} GCtab;
+
+#define sizetabcolo(n) ((n)*sizeof(TValue) + sizeof(GCtab))
+#define tabref(r) (&gcref((r))->tab)
+#define noderef(r) (mref((r), Node))
+#define nextnode(n) (mref((n)->next, Node))
+
+/* -- State objects ------------------------------------------------------- */
+
+/* VM states. */
+enum {
+ LJ_VMST_INTERP, /* Interpreter. */
+ LJ_VMST_C, /* C function. */
+ LJ_VMST_GC, /* Garbage collector. */
+ LJ_VMST_EXIT, /* Trace exit handler. */
+ LJ_VMST_RECORD, /* Trace recorder. */
+ LJ_VMST_OPT, /* Optimizer. */
+ LJ_VMST_ASM, /* Assembler. */
+ LJ_VMST__MAX
+};
+
+#define setvmstate(g, st) ((g)->vmstate = ~LJ_VMST_##st)
+
+/* Metamethods. ORDER MM */
+#ifdef LJ_HASFFI
+#define MMDEF_FFI(_) _(new)
+#else
+#define MMDEF_FFI(_)
+#endif
+
+#if LJ_52 || LJ_HASFFI
+#define MMDEF_PAIRS(_) _(pairs) _(ipairs)
+#else
+#define MMDEF_PAIRS(_)
+#define MM_pairs 255
+#define MM_ipairs 255
+#endif
+
+#define MMDEF(_) \
+ _(index) _(newindex) _(gc) _(mode) _(eq) _(len) \
+ /* Only the above (fast) metamethods are negative cached (max. 8). */ \
+ _(lt) _(le) _(concat) _(call) \
+ /* The following must be in ORDER ARITH. */ \
+ _(add) _(sub) _(mul) _(div) _(mod) _(pow) _(unm) \
+ /* The following are used in the standard libraries. */ \
+ _(metatable) _(tostring) MMDEF_FFI(_) MMDEF_PAIRS(_)
+
+typedef enum {
+#define MMENUM(name) MM_##name,
+MMDEF(MMENUM)
+#undef MMENUM
+ MM__MAX,
+ MM____ = MM__MAX,
+ MM_FAST = MM_len
+} MMS;
+
+/* GC root IDs. */
+typedef enum {
+ GCROOT_MMNAME, /* Metamethod names. */
+ GCROOT_MMNAME_LAST = GCROOT_MMNAME + MM__MAX-1,
+ GCROOT_BASEMT, /* Metatables for base types. */
+ GCROOT_BASEMT_NUM = GCROOT_BASEMT + ~LJ_TNUMX,
+ GCROOT_IO_INPUT, /* Userdata for default I/O input file. */
+ GCROOT_IO_OUTPUT, /* Userdata for default I/O output file. */
+ GCROOT_MAX
+} GCRootID;
+
+#define basemt_it(g, it) ((g)->gcroot[GCROOT_BASEMT+~(it)])
+#define basemt_obj(g, o) ((g)->gcroot[GCROOT_BASEMT+itypemap(o)])
+#define mmname_str(g, mm) (strref((g)->gcroot[GCROOT_MMNAME+(mm)]))
+
+typedef struct GCState {
+ MSize total; /* Memory currently allocated. */
+ MSize threshold; /* Memory threshold. */
+ uint8_t currentwhite; /* Current white color. */
+ uint8_t state; /* GC state. */
+ uint8_t nocdatafin; /* No cdata finalizer called. */
+ uint8_t unused2;
+ MSize sweepstr; /* Sweep position in string table. */
+ GCRef root; /* List of all collectable objects. */
+ MRef sweep; /* Sweep position in root list. */
+ GCRef gray; /* List of gray objects. */
+ GCRef grayagain; /* List of objects for atomic traversal. */
+ GCRef weak; /* List of weak tables (to be cleared). */
+ GCRef mmudata; /* List of userdata (to be finalized). */
+ MSize stepmul; /* Incremental GC step granularity. */
+ MSize debt; /* Debt (how much GC is behind schedule). */
+ MSize estimate; /* Estimate of memory actually in use. */
+ MSize pause; /* Pause between successive GC cycles. */
+} GCState;
+
+/* Global state, shared by all threads of a Lua universe. */
+typedef struct global_State {
+ GCRef *strhash; /* String hash table (hash chain anchors). */
+ MSize strmask; /* String hash mask (size of hash table - 1). */
+ MSize strnum; /* Number of strings in hash table. */
+ lua_Alloc allocf; /* Memory allocator. */
+ void *allocd; /* Memory allocator data. */
+ GCState gc; /* Garbage collector. */
+ SBuf tmpbuf; /* Temporary buffer for string concatenation. */
+ Node nilnode; /* Fallback 1-element hash part (nil key and value). */
+ GCstr strempty; /* Empty string. */
+ uint8_t stremptyz; /* Zero terminator of empty string. */
+ uint8_t hookmask; /* Hook mask. */
+ uint8_t dispatchmode; /* Dispatch mode. */
+ uint8_t vmevmask; /* VM event mask. */
+ GCRef mainthref; /* Link to main thread. */
+ TValue registrytv; /* Anchor for registry. */
+ TValue tmptv, tmptv2; /* Temporary TValues. */
+ GCupval uvhead; /* Head of double-linked list of all open upvalues. */
+ int32_t hookcount; /* Instruction hook countdown. */
+ int32_t hookcstart; /* Start count for instruction hook counter. */
+ lua_Hook hookf; /* Hook function. */
+ lua_CFunction wrapf; /* Wrapper for C function calls. */
+ lua_CFunction panic; /* Called as a last resort for errors. */
+ volatile int32_t vmstate; /* VM state or current JIT code trace number. */
+ BCIns bc_cfunc_int; /* Bytecode for internal C function calls. */
+ BCIns bc_cfunc_ext; /* Bytecode for external C function calls. */
+ GCRef jit_L; /* Current JIT code lua_State or NULL. */
+ MRef jit_base; /* Current JIT code L->base. */
+ MRef ctype_state; /* Pointer to C type state. */
+ GCRef gcroot[GCROOT_MAX]; /* GC roots. */
+} global_State;
+
+#define mainthread(g) (&gcref(g->mainthref)->th)
+#define niltv(L) \
+ check_exp(tvisnil(&G(L)->nilnode.val), &G(L)->nilnode.val)
+#define niltvg(g) \
+ check_exp(tvisnil(&(g)->nilnode.val), &(g)->nilnode.val)
+
+/* Hook management. Hook event masks are defined in lua.h. */
+#define HOOK_EVENTMASK 0x0f
+#define HOOK_ACTIVE 0x10
+#define HOOK_ACTIVE_SHIFT 4
+#define HOOK_VMEVENT 0x20
+#define HOOK_GC 0x40
+#define hook_active(g) ((g)->hookmask & HOOK_ACTIVE)
+#define hook_enter(g) ((g)->hookmask |= HOOK_ACTIVE)
+#define hook_entergc(g) ((g)->hookmask |= (HOOK_ACTIVE|HOOK_GC))
+#define hook_vmevent(g) ((g)->hookmask |= (HOOK_ACTIVE|HOOK_VMEVENT))
+#define hook_leave(g) ((g)->hookmask &= ~HOOK_ACTIVE)
+#define hook_save(g) ((g)->hookmask & ~HOOK_EVENTMASK)
+#define hook_restore(g, h) \
+ ((g)->hookmask = ((g)->hookmask & HOOK_EVENTMASK) | (h))
+
+/* Per-thread state object. */
+struct lua_State {
+ GCHeader;
+ uint8_t dummy_ffid; /* Fake FF_C for curr_funcisL() on dummy frames. */
+ uint8_t status; /* Thread status. */
+ MRef glref; /* Link to global state. */
+ GCRef gclist; /* GC chain. */
+ TValue *base; /* Base of currently executing function. */
+ TValue *top; /* First free slot in the stack. */
+ MRef maxstack; /* Last free slot in the stack. */
+ MRef stack; /* Stack base. */
+ GCRef openupval; /* List of open upvalues in the stack. */
+ GCRef env; /* Thread environment (table of globals). */
+ void *cframe; /* End of C stack frame chain. */
+ MSize stacksize; /* True stack size (incl. LJ_STACK_EXTRA). */
+};
+
+#define G(L) (mref(L->glref, global_State))
+#define registry(L) (&G(L)->registrytv)
+
+/* Macros to access the currently executing (Lua) function. */
+#define curr_func(L) (&gcref((L->base-1)->fr.func)->fn)
+#define curr_funcisL(L) (isluafunc(curr_func(L)))
+#define curr_proto(L) (funcproto(curr_func(L)))
+#define curr_topL(L) (L->base + curr_proto(L)->framesize)
+#define curr_top(L) (curr_funcisL(L) ? curr_topL(L) : L->top)
+
+/* -- GC object definition and conversions -------------------------------- */
+
+/* GC header for generic access to common fields of GC objects. */
+typedef struct GChead {
+ GCHeader;
+ uint8_t unused1;
+ uint8_t unused2;
+ GCRef env;
+ GCRef gclist;
+ GCRef metatable;
+} GChead;
+
+/* The env field SHOULD be at the same offset for all GC objects. */
+LJ_STATIC_ASSERT(offsetof(GChead, env) == offsetof(GCfuncL, env));
+LJ_STATIC_ASSERT(offsetof(GChead, env) == offsetof(GCudata, env));
+
+/* The metatable field MUST be at the same offset for all GC objects. */
+LJ_STATIC_ASSERT(offsetof(GChead, metatable) == offsetof(GCtab, metatable));
+LJ_STATIC_ASSERT(offsetof(GChead, metatable) == offsetof(GCudata, metatable));
+
+/* The gclist field MUST be at the same offset for all GC objects. */
+LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(lua_State, gclist));
+LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCproto, gclist));
+LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCfuncL, gclist));
+LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCtab, gclist));
+
+typedef union GCobj {
+ GChead gch;
+ GCstr str;
+ GCupval uv;
+ lua_State th;
+ GCproto pt;
+ GCfunc fn;
+ GCcdata cd;
+ GCtab tab;
+ GCudata ud;
+} GCobj;
+
+/* Macros to convert a GCobj pointer into a specific value. */
+#define gco2str(o) check_exp((o)->gch.gct == ~LJ_TSTR, &(o)->str)
+#define gco2uv(o) check_exp((o)->gch.gct == ~LJ_TUPVAL, &(o)->uv)
+#define gco2th(o) check_exp((o)->gch.gct == ~LJ_TTHREAD, &(o)->th)
+#define gco2pt(o) check_exp((o)->gch.gct == ~LJ_TPROTO, &(o)->pt)
+#define gco2func(o) check_exp((o)->gch.gct == ~LJ_TFUNC, &(o)->fn)
+#define gco2cd(o) check_exp((o)->gch.gct == ~LJ_TCDATA, &(o)->cd)
+#define gco2tab(o) check_exp((o)->gch.gct == ~LJ_TTAB, &(o)->tab)
+#define gco2ud(o) check_exp((o)->gch.gct == ~LJ_TUDATA, &(o)->ud)
+
+/* Macro to convert any collectable object into a GCobj pointer. */
+#define obj2gco(v) ((GCobj *)(v))
+
+/* -- TValue getters/setters ---------------------------------------------- */
+
+#ifdef LUA_USE_ASSERT
+#include "lj_gc.h"
+#endif
+
+/* Macros to test types. */
+#define itype(o) ((o)->it)
+#define tvisnil(o) (itype(o) == LJ_TNIL)
+#define tvisfalse(o) (itype(o) == LJ_TFALSE)
+#define tvistrue(o) (itype(o) == LJ_TTRUE)
+#define tvisbool(o) (tvisfalse(o) || tvistrue(o))
+#if LJ_64
+#define tvislightud(o) (((int32_t)itype(o) >> 15) == -2)
+#else
+#define tvislightud(o) (itype(o) == LJ_TLIGHTUD)
+#endif
+#define tvisstr(o) (itype(o) == LJ_TSTR)
+#define tvisfunc(o) (itype(o) == LJ_TFUNC)
+#define tvisthread(o) (itype(o) == LJ_TTHREAD)
+#define tvisproto(o) (itype(o) == LJ_TPROTO)
+#define tviscdata(o) (itype(o) == LJ_TCDATA)
+#define tvistab(o) (itype(o) == LJ_TTAB)
+#define tvisudata(o) (itype(o) == LJ_TUDATA)
+#define tvisnumber(o) (itype(o) <= LJ_TISNUM)
+#define tvisint(o) (LJ_DUALNUM && itype(o) == LJ_TISNUM)
+#define tvisnum(o) (itype(o) < LJ_TISNUM)
+
+#define tvistruecond(o) (itype(o) < LJ_TISTRUECOND)
+#define tvispri(o) (itype(o) >= LJ_TISPRI)
+#define tvistabud(o) (itype(o) <= LJ_TISTABUD) /* && !tvisnum() */
+#define tvisgcv(o) ((itype(o) - LJ_TISGCV) > (LJ_TNUMX - LJ_TISGCV))
+
+/* Special macros to test numbers for NaN, +0, -0, +1 and raw equality. */
+#define tvisnan(o) ((o)->n != (o)->n)
+#if LJ_64
+#define tviszero(o) (((o)->u64 << 1) == 0)
+#else
+#define tviszero(o) (((o)->u32.lo | ((o)->u32.hi << 1)) == 0)
+#endif
+#define tvispzero(o) ((o)->u64 == 0)
+#define tvismzero(o) ((o)->u64 == U64x(80000000,00000000))
+#define tvispone(o) ((o)->u64 == U64x(3ff00000,00000000))
+#define rawnumequal(o1, o2) ((o1)->u64 == (o2)->u64)
+
+/* Macros to convert type ids. */
+#if LJ_64
+#define itypemap(o) \
+ (tvisnumber(o) ? ~LJ_TNUMX : tvislightud(o) ? ~LJ_TLIGHTUD : ~itype(o))
+#else
+#define itypemap(o) (tvisnumber(o) ? ~LJ_TNUMX : ~itype(o))
+#endif
+
+/* Macros to get tagged values. */
+#define gcval(o) (gcref((o)->gcr))
+#define boolV(o) check_exp(tvisbool(o), (LJ_TFALSE - (o)->it))
+#if LJ_64
+#define lightudV(o) \
+ check_exp(tvislightud(o), (void *)((o)->u64 & U64x(00007fff,ffffffff)))
+#else
+#define lightudV(o) check_exp(tvislightud(o), gcrefp((o)->gcr, void))
+#endif
+#define gcV(o) check_exp(tvisgcv(o), gcval(o))
+#define strV(o) check_exp(tvisstr(o), &gcval(o)->str)
+#define funcV(o) check_exp(tvisfunc(o), &gcval(o)->fn)
+#define threadV(o) check_exp(tvisthread(o), &gcval(o)->th)
+#define protoV(o) check_exp(tvisproto(o), &gcval(o)->pt)
+#define cdataV(o) check_exp(tviscdata(o), &gcval(o)->cd)
+#define tabV(o) check_exp(tvistab(o), &gcval(o)->tab)
+#define udataV(o) check_exp(tvisudata(o), &gcval(o)->ud)
+#define numV(o) check_exp(tvisnum(o), (o)->n)
+#define intV(o) check_exp(tvisint(o), (int32_t)(o)->i)
+
+/* Macros to set tagged values. */
+#define setitype(o, i) ((o)->it = (i))
+#define setnilV(o) ((o)->it = LJ_TNIL)
+#define setboolV(o, x) ((o)->it = LJ_TFALSE-(uint32_t)(x))
+
+static LJ_AINLINE void setlightudV(TValue *o, void *p)
+{
+#if LJ_64
+ o->u64 = (uint64_t)p | (((uint64_t)0xffff) << 48);
+#else
+ setgcrefp(o->gcr, p); setitype(o, LJ_TLIGHTUD);
+#endif
+}
+
+#if LJ_64
+#define checklightudptr(L, p) \
+ (((uint64_t)(p) >> 47) ? (lj_err_msg(L, LJ_ERR_BADLU), NULL) : (p))
+#define setcont(o, f) \
+ ((o)->u64 = (uint64_t)(void *)(f) - (uint64_t)lj_vm_asm_begin)
+#else
+#define checklightudptr(L, p) (p)
+#define setcont(o, f) setlightudV((o), (void *)(f))
+#endif
+
+#define tvchecklive(L, o) \
+ UNUSED(L), lua_assert(!tvisgcv(o) || \
+ ((~itype(o) == gcval(o)->gch.gct) && !isdead(G(L), gcval(o))))
+
+static LJ_AINLINE void setgcV(lua_State *L, TValue *o, GCobj *v, uint32_t itype)
+{
+ setgcref(o->gcr, v); setitype(o, itype); tvchecklive(L, o);
+}
+
+#define define_setV(name, type, tag) \
+static LJ_AINLINE void name(lua_State *L, TValue *o, type *v) \
+{ \
+ setgcV(L, o, obj2gco(v), tag); \
+}
+define_setV(setstrV, GCstr, LJ_TSTR)
+define_setV(setthreadV, lua_State, LJ_TTHREAD)
+define_setV(setprotoV, GCproto, LJ_TPROTO)
+define_setV(setfuncV, GCfunc, LJ_TFUNC)
+define_setV(setcdataV, GCcdata, LJ_TCDATA)
+define_setV(settabV, GCtab, LJ_TTAB)
+define_setV(setudataV, GCudata, LJ_TUDATA)
+
+#define setnumV(o, x) ((o)->n = (x))
+#define setnanV(o) ((o)->u64 = U64x(fff80000,00000000))
+#define setpinfV(o) ((o)->u64 = U64x(7ff00000,00000000))
+#define setminfV(o) ((o)->u64 = U64x(fff00000,00000000))
+
+static LJ_AINLINE void setintV(TValue *o, int32_t i)
+{
+#if LJ_DUALNUM
+ o->i = (uint32_t)i; setitype(o, LJ_TISNUM);
+#else
+ o->n = (lua_Number)i;
+#endif
+}
+
+static LJ_AINLINE void setint64V(TValue *o, int64_t i)
+{
+ if (LJ_DUALNUM && LJ_LIKELY(i == (int64_t)(int32_t)i))
+ setintV(o, (int32_t)i);
+ else
+ setnumV(o, (lua_Number)i);
+}
+
+#if LJ_64
+#define setintptrV(o, i) setint64V((o), (i))
+#else
+#define setintptrV(o, i) setintV((o), (i))
+#endif
+
+/* Copy tagged values. */
+static LJ_AINLINE void copyTV(lua_State *L, TValue *o1, const TValue *o2)
+{
+ *o1 = *o2; tvchecklive(L, o1);
+}
+
+/* -- Number to integer conversion ---------------------------------------- */
+
+#if LJ_SOFTFP
+LJ_ASMF int32_t lj_vm_tobit(double x);
+#endif
+
+static LJ_AINLINE int32_t lj_num2bit(lua_Number n)
+{
+#if LJ_SOFTFP
+ return lj_vm_tobit(n);
+#else
+ TValue o;
+ o.n = n + 6755399441055744.0; /* 2^52 + 2^51 */
+ return (int32_t)o.u32.lo;
+#endif
+}
+
+#if LJ_TARGET_X86 && !defined(__SSE2__)
+#define lj_num2int(n) lj_num2bit((n))
+#else
+#define lj_num2int(n) ((int32_t)(n))
+#endif
+
+/*
+** This must match the JIT backend behavior. In particular for archs
+** that don't have a common hardware instruction for this conversion.
+** Note that signed FP to unsigned int conversions have an undefined
+** result and should never be relied upon in portable FFI code.
+** See also: C99 or C11 standard, 6.3.1.4, footnote of (1).
+*/
+static LJ_AINLINE uint64_t lj_num2u64(lua_Number n)
+{
+#if LJ_TARGET_X86ORX64 || LJ_TARGET_MIPS
+ int64_t i = (int64_t)n;
+ if (i < 0) i = (int64_t)(n - 18446744073709551616.0);
+ return (uint64_t)i;
+#else
+ return (uint64_t)n;
+#endif
+}
+
+static LJ_AINLINE int32_t numberVint(cTValue *o)
+{
+ if (LJ_LIKELY(tvisint(o)))
+ return intV(o);
+ else
+ return lj_num2int(numV(o));
+}
+
+static LJ_AINLINE lua_Number numberVnum(cTValue *o)
+{
+ if (LJ_UNLIKELY(tvisint(o)))
+ return (lua_Number)intV(o);
+ else
+ return numV(o);
+}
+
+/* -- Miscellaneous object handling --------------------------------------- */
+
+/* Names and maps for internal and external object tags. */
+LJ_DATA const char *const lj_obj_typename[1+LUA_TCDATA+1];
+LJ_DATA const char *const lj_obj_itypename[~LJ_TNUMX+1];
+
+#define lj_typename(o) (lj_obj_itypename[itypemap(o)])
+
+/* Compare two objects without calling metamethods. */
+LJ_FUNC int lj_obj_equal(cTValue *o1, cTValue *o2);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_dce.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_dce.c
new file mode 100644
index 0000000..2417f32
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_dce.c
@@ -0,0 +1,78 @@
+/*
+** DCE: Dead Code Elimination. Pre-LOOP only -- ASM already performs DCE.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_opt_dce_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT
+
+#include "lj_ir.h"
+#include "lj_jit.h"
+#include "lj_iropt.h"
+
+/* Some local macros to save typing. Undef'd at the end. */
+#define IR(ref) (&J->cur.ir[(ref)])
+
+/* Scan through all snapshots and mark all referenced instructions. */
+static void dce_marksnap(jit_State *J)
+{
+ SnapNo i, nsnap = J->cur.nsnap;
+ for (i = 0; i < nsnap; i++) {
+ SnapShot *snap = &J->cur.snap[i];
+ SnapEntry *map = &J->cur.snapmap[snap->mapofs];
+ MSize n, nent = snap->nent;
+ for (n = 0; n < nent; n++) {
+ IRRef ref = snap_ref(map[n]);
+ if (ref >= REF_FIRST)
+ irt_setmark(IR(ref)->t);
+ }
+ }
+}
+
+/* Backwards propagate marks. Replace unused instructions with NOPs. */
+static void dce_propagate(jit_State *J)
+{
+ IRRef1 *pchain[IR__MAX];
+ IRRef ins;
+ uint32_t i;
+ for (i = 0; i < IR__MAX; i++) pchain[i] = &J->chain[i];
+ for (ins = J->cur.nins-1; ins >= REF_FIRST; ins--) {
+ IRIns *ir = IR(ins);
+ if (irt_ismarked(ir->t)) {
+ irt_clearmark(ir->t);
+ pchain[ir->o] = &ir->prev;
+ } else if (!ir_sideeff(ir)) {
+ *pchain[ir->o] = ir->prev; /* Reroute original instruction chain. */
+ ir->t.irt = IRT_NIL;
+ ir->o = IR_NOP; /* Replace instruction with NOP. */
+ ir->op1 = ir->op2 = 0;
+ ir->prev = 0;
+ continue;
+ }
+ if (ir->op1 >= REF_FIRST) irt_setmark(IR(ir->op1)->t);
+ if (ir->op2 >= REF_FIRST) irt_setmark(IR(ir->op2)->t);
+ }
+}
+
+/* Dead Code Elimination.
+**
+** First backpropagate marks for all used instructions. Then replace
+** the unused ones with a NOP. Note that compressing the IR to eliminate
+** the NOPs does not pay off.
+*/
+void lj_opt_dce(jit_State *J)
+{
+ if ((J->flags & JIT_F_OPT_DCE)) {
+ dce_marksnap(J);
+ dce_propagate(J);
+ memset(J->bpropcache, 0, sizeof(J->bpropcache)); /* Invalidate cache. */
+ }
+}
+
+#undef IR
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_fold.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_fold.c
new file mode 100644
index 0000000..5dc7ae3
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_fold.c
@@ -0,0 +1,2304 @@
+/*
+** FOLD: Constant Folding, Algebraic Simplifications and Reassociation.
+** ABCelim: Array Bounds Check Elimination.
+** CSE: Common-Subexpression Elimination.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_opt_fold_c
+#define LUA_CORE
+
+#include <math.h>
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT
+
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_ir.h"
+#include "lj_jit.h"
+#include "lj_iropt.h"
+#include "lj_trace.h"
+#if LJ_HASFFI
+#include "lj_ctype.h"
+#endif
+#include "lj_carith.h"
+#include "lj_vm.h"
+#include "lj_strscan.h"
+
+/* Here's a short description how the FOLD engine processes instructions:
+**
+** The FOLD engine receives a single instruction stored in fins (J->fold.ins).
+** The instruction and its operands are used to select matching fold rules.
+** These are applied iteratively until a fixed point is reached.
+**
+** The 8 bit opcode of the instruction itself plus the opcodes of the
+** two instructions referenced by its operands form a 24 bit key
+** 'ins left right' (unused operands -> 0, literals -> lowest 8 bits).
+**
+** This key is used for partial matching against the fold rules. The
+** left/right operand fields of the key are successively masked with
+** the 'any' wildcard, from most specific to least specific:
+**
+** ins left right
+** ins any right
+** ins left any
+** ins any any
+**
+** The masked key is used to lookup a matching fold rule in a semi-perfect
+** hash table. If a matching rule is found, the related fold function is run.
+** Multiple rules can share the same fold function. A fold rule may return
+** one of several special values:
+**
+** - NEXTFOLD means no folding was applied, because an additional test
+** inside the fold function failed. Matching continues against less
+** specific fold rules. Finally the instruction is passed on to CSE.
+**
+** - RETRYFOLD means the instruction was modified in-place. Folding is
+** retried as if this instruction had just been received.
+**
+** All other return values are terminal actions -- no further folding is
+** applied:
+**
+** - INTFOLD(i) returns a reference to the integer constant i.
+**
+** - LEFTFOLD and RIGHTFOLD return the left/right operand reference
+** without emitting an instruction.
+**
+** - CSEFOLD and EMITFOLD pass the instruction directly to CSE or emit
+** it without passing through any further optimizations.
+**
+** - FAILFOLD, DROPFOLD and CONDFOLD only apply to instructions which have
+** no result (e.g. guarded assertions): FAILFOLD means the guard would
+** always fail, i.e. the current trace is pointless. DROPFOLD means
+** the guard is always true and has been eliminated. CONDFOLD is a
+** shortcut for FAILFOLD + cond (i.e. drop if true, otherwise fail).
+**
+** - Any other return value is interpreted as an IRRef or TRef. This
+** can be a reference to an existing or a newly created instruction.
+** Only the least-significant 16 bits (IRRef1) are used to form a TRef
+** which is finally returned to the caller.
+**
+** The FOLD engine receives instructions both from the trace recorder and
+** substituted instructions from LOOP unrolling. This means all types
+** of instructions may end up here, even though the recorder bypasses
+** FOLD in some cases. Thus all loads, stores and allocations must have
+** an any/any rule to avoid being passed on to CSE.
+**
+** Carefully read the following requirements before adding or modifying
+** any fold rules:
+**
+** Requirement #1: All fold rules must preserve their destination type.
+**
+** Consistently use INTFOLD() (KINT result) or lj_ir_knum() (KNUM result).
+** Never use lj_ir_knumint() which can have either a KINT or KNUM result.
+**
+** Requirement #2: Fold rules should not create *new* instructions which
+** reference operands *across* PHIs.
+**
+** E.g. a RETRYFOLD with 'fins->op1 = fleft->op1' is invalid if the
+** left operand is a PHI. Then fleft->op1 would point across the PHI
+** frontier to an invariant instruction. Adding a PHI for this instruction
+** would be counterproductive. The solution is to add a barrier which
+** prevents folding across PHIs, i.e. 'PHIBARRIER(fleft)' in this case.
+** The only exception is for recurrences with high latencies like
+** repeated int->num->int conversions.
+**
+** One could relax this condition a bit if the referenced instruction is
+** a PHI, too. But this often leads to worse code due to excessive
+** register shuffling.
+**
+** Note: returning *existing* instructions (e.g. LEFTFOLD) is ok, though.
+** Even returning fleft->op1 would be ok, because a new PHI will added,
+** if needed. But again, this leads to excessive register shuffling and
+** should be avoided.
+**
+** Requirement #3: The set of all fold rules must be monotonic to guarantee
+** termination.
+**
+** The goal is optimization, so one primarily wants to add strength-reducing
+** rules. This means eliminating an instruction or replacing an instruction
+** with one or more simpler instructions. Don't add fold rules which point
+** into the other direction.
+**
+** Some rules (like commutativity) do not directly reduce the strength of
+** an instruction, but enable other fold rules (e.g. by moving constants
+** to the right operand). These rules must be made unidirectional to avoid
+** cycles.
+**
+** Rule of thumb: the trace recorder expands the IR and FOLD shrinks it.
+*/
+
+/* Some local macros to save typing. Undef'd at the end. */
+#define IR(ref) (&J->cur.ir[(ref)])
+#define fins (&J->fold.ins)
+#define fleft (&J->fold.left)
+#define fright (&J->fold.right)
+#define knumleft (ir_knum(fleft)->n)
+#define knumright (ir_knum(fright)->n)
+
+/* Pass IR on to next optimization in chain (FOLD). */
+#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))
+
+/* Fold function type. Fastcall on x86 significantly reduces their size. */
+typedef IRRef (LJ_FASTCALL *FoldFunc)(jit_State *J);
+
+/* Macros for the fold specs, so buildvm can recognize them. */
+#define LJFOLD(x)
+#define LJFOLDX(x)
+#define LJFOLDF(name) static TRef LJ_FASTCALL fold_##name(jit_State *J)
+/* Note: They must be at the start of a line or buildvm ignores them! */
+
+/* Barrier to prevent using operands across PHIs. */
+#define PHIBARRIER(ir) if (irt_isphi((ir)->t)) return NEXTFOLD
+
+/* Barrier to prevent folding across a GC step.
+** GC steps can only happen at the head of a trace and at LOOP.
+** And the GC is only driven forward if there is at least one allocation.
+*/
+#define gcstep_barrier(J, ref) \
+ ((ref) < J->chain[IR_LOOP] && \
+ (J->chain[IR_SNEW] || J->chain[IR_XSNEW] || \
+ J->chain[IR_TNEW] || J->chain[IR_TDUP] || \
+ J->chain[IR_CNEW] || J->chain[IR_CNEWI] || J->chain[IR_TOSTR]))
+
+/* -- Constant folding for FP numbers ------------------------------------- */
+
+LJFOLD(ADD KNUM KNUM)
+LJFOLD(SUB KNUM KNUM)
+LJFOLD(MUL KNUM KNUM)
+LJFOLD(DIV KNUM KNUM)
+LJFOLD(NEG KNUM KNUM)
+LJFOLD(ABS KNUM KNUM)
+LJFOLD(ATAN2 KNUM KNUM)
+LJFOLD(LDEXP KNUM KNUM)
+LJFOLD(MIN KNUM KNUM)
+LJFOLD(MAX KNUM KNUM)
+LJFOLDF(kfold_numarith)
+{
+ lua_Number a = knumleft;
+ lua_Number b = knumright;
+ lua_Number y = lj_vm_foldarith(a, b, fins->o - IR_ADD);
+ return lj_ir_knum(J, y);
+}
+
+LJFOLD(LDEXP KNUM KINT)
+LJFOLDF(kfold_ldexp)
+{
+#if LJ_TARGET_X86ORX64
+ UNUSED(J);
+ return NEXTFOLD;
+#else
+ return lj_ir_knum(J, ldexp(knumleft, fright->i));
+#endif
+}
+
+LJFOLD(FPMATH KNUM any)
+LJFOLDF(kfold_fpmath)
+{
+ lua_Number a = knumleft;
+ lua_Number y = lj_vm_foldfpm(a, fins->op2);
+ return lj_ir_knum(J, y);
+}
+
+LJFOLD(POW KNUM KINT)
+LJFOLDF(kfold_numpow)
+{
+ lua_Number a = knumleft;
+ lua_Number b = (lua_Number)fright->i;
+ lua_Number y = lj_vm_foldarith(a, b, IR_POW - IR_ADD);
+ return lj_ir_knum(J, y);
+}
+
+/* Must not use kfold_kref for numbers (could be NaN). */
+LJFOLD(EQ KNUM KNUM)
+LJFOLD(NE KNUM KNUM)
+LJFOLD(LT KNUM KNUM)
+LJFOLD(GE KNUM KNUM)
+LJFOLD(LE KNUM KNUM)
+LJFOLD(GT KNUM KNUM)
+LJFOLD(ULT KNUM KNUM)
+LJFOLD(UGE KNUM KNUM)
+LJFOLD(ULE KNUM KNUM)
+LJFOLD(UGT KNUM KNUM)
+LJFOLDF(kfold_numcomp)
+{
+ return CONDFOLD(lj_ir_numcmp(knumleft, knumright, (IROp)fins->o));
+}
+
+/* -- Constant folding for 32 bit integers -------------------------------- */
+
+static int32_t kfold_intop(int32_t k1, int32_t k2, IROp op)
+{
+ switch (op) {
+ case IR_ADD: k1 += k2; break;
+ case IR_SUB: k1 -= k2; break;
+ case IR_MUL: k1 *= k2; break;
+ case IR_MOD: k1 = lj_vm_modi(k1, k2); break;
+ case IR_NEG: k1 = -k1; break;
+ case IR_BAND: k1 &= k2; break;
+ case IR_BOR: k1 |= k2; break;
+ case IR_BXOR: k1 ^= k2; break;
+ case IR_BSHL: k1 <<= (k2 & 31); break;
+ case IR_BSHR: k1 = (int32_t)((uint32_t)k1 >> (k2 & 31)); break;
+ case IR_BSAR: k1 >>= (k2 & 31); break;
+ case IR_BROL: k1 = (int32_t)lj_rol((uint32_t)k1, (k2 & 31)); break;
+ case IR_BROR: k1 = (int32_t)lj_ror((uint32_t)k1, (k2 & 31)); break;
+ case IR_MIN: k1 = k1 < k2 ? k1 : k2; break;
+ case IR_MAX: k1 = k1 > k2 ? k1 : k2; break;
+ default: lua_assert(0); break;
+ }
+ return k1;
+}
+
+LJFOLD(ADD KINT KINT)
+LJFOLD(SUB KINT KINT)
+LJFOLD(MUL KINT KINT)
+LJFOLD(MOD KINT KINT)
+LJFOLD(NEG KINT KINT)
+LJFOLD(BAND KINT KINT)
+LJFOLD(BOR KINT KINT)
+LJFOLD(BXOR KINT KINT)
+LJFOLD(BSHL KINT KINT)
+LJFOLD(BSHR KINT KINT)
+LJFOLD(BSAR KINT KINT)
+LJFOLD(BROL KINT KINT)
+LJFOLD(BROR KINT KINT)
+LJFOLD(MIN KINT KINT)
+LJFOLD(MAX KINT KINT)
+LJFOLDF(kfold_intarith)
+{
+ return INTFOLD(kfold_intop(fleft->i, fright->i, (IROp)fins->o));
+}
+
+LJFOLD(ADDOV KINT KINT)
+LJFOLD(SUBOV KINT KINT)
+LJFOLD(MULOV KINT KINT)
+LJFOLDF(kfold_intovarith)
+{
+ lua_Number n = lj_vm_foldarith((lua_Number)fleft->i, (lua_Number)fright->i,
+ fins->o - IR_ADDOV);
+ int32_t k = lj_num2int(n);
+ if (n != (lua_Number)k)
+ return FAILFOLD;
+ return INTFOLD(k);
+}
+
+LJFOLD(BNOT KINT)
+LJFOLDF(kfold_bnot)
+{
+ return INTFOLD(~fleft->i);
+}
+
+LJFOLD(BSWAP KINT)
+LJFOLDF(kfold_bswap)
+{
+ return INTFOLD((int32_t)lj_bswap((uint32_t)fleft->i));
+}
+
+LJFOLD(LT KINT KINT)
+LJFOLD(GE KINT KINT)
+LJFOLD(LE KINT KINT)
+LJFOLD(GT KINT KINT)
+LJFOLD(ULT KINT KINT)
+LJFOLD(UGE KINT KINT)
+LJFOLD(ULE KINT KINT)
+LJFOLD(UGT KINT KINT)
+LJFOLD(ABC KINT KINT)
+LJFOLDF(kfold_intcomp)
+{
+ int32_t a = fleft->i, b = fright->i;
+ switch ((IROp)fins->o) {
+ case IR_LT: return CONDFOLD(a < b);
+ case IR_GE: return CONDFOLD(a >= b);
+ case IR_LE: return CONDFOLD(a <= b);
+ case IR_GT: return CONDFOLD(a > b);
+ case IR_ULT: return CONDFOLD((uint32_t)a < (uint32_t)b);
+ case IR_UGE: return CONDFOLD((uint32_t)a >= (uint32_t)b);
+ case IR_ULE: return CONDFOLD((uint32_t)a <= (uint32_t)b);
+ case IR_ABC:
+ case IR_UGT: return CONDFOLD((uint32_t)a > (uint32_t)b);
+ default: lua_assert(0); return FAILFOLD;
+ }
+}
+
+LJFOLD(UGE any KINT)
+LJFOLDF(kfold_intcomp0)
+{
+ if (fright->i == 0)
+ return DROPFOLD;
+ return NEXTFOLD;
+}
+
+/* -- Constant folding for 64 bit integers -------------------------------- */
+
+static uint64_t kfold_int64arith(uint64_t k1, uint64_t k2, IROp op)
+{
+ switch (op) {
+#if LJ_64 || LJ_HASFFI
+ case IR_ADD: k1 += k2; break;
+ case IR_SUB: k1 -= k2; break;
+#endif
+#if LJ_HASFFI
+ case IR_MUL: k1 *= k2; break;
+ case IR_BAND: k1 &= k2; break;
+ case IR_BOR: k1 |= k2; break;
+ case IR_BXOR: k1 ^= k2; break;
+#endif
+ default: UNUSED(k2); lua_assert(0); break;
+ }
+ return k1;
+}
+
+LJFOLD(ADD KINT64 KINT64)
+LJFOLD(SUB KINT64 KINT64)
+LJFOLD(MUL KINT64 KINT64)
+LJFOLD(BAND KINT64 KINT64)
+LJFOLD(BOR KINT64 KINT64)
+LJFOLD(BXOR KINT64 KINT64)
+LJFOLDF(kfold_int64arith)
+{
+ return INT64FOLD(kfold_int64arith(ir_k64(fleft)->u64,
+ ir_k64(fright)->u64, (IROp)fins->o));
+}
+
+LJFOLD(DIV KINT64 KINT64)
+LJFOLD(MOD KINT64 KINT64)
+LJFOLD(POW KINT64 KINT64)
+LJFOLDF(kfold_int64arith2)
+{
+#if LJ_HASFFI
+ uint64_t k1 = ir_k64(fleft)->u64, k2 = ir_k64(fright)->u64;
+ if (irt_isi64(fins->t)) {
+ k1 = fins->o == IR_DIV ? lj_carith_divi64((int64_t)k1, (int64_t)k2) :
+ fins->o == IR_MOD ? lj_carith_modi64((int64_t)k1, (int64_t)k2) :
+ lj_carith_powi64((int64_t)k1, (int64_t)k2);
+ } else {
+ k1 = fins->o == IR_DIV ? lj_carith_divu64(k1, k2) :
+ fins->o == IR_MOD ? lj_carith_modu64(k1, k2) :
+ lj_carith_powu64(k1, k2);
+ }
+ return INT64FOLD(k1);
+#else
+ UNUSED(J); lua_assert(0); return FAILFOLD;
+#endif
+}
+
+LJFOLD(BSHL KINT64 KINT)
+LJFOLD(BSHR KINT64 KINT)
+LJFOLD(BSAR KINT64 KINT)
+LJFOLD(BROL KINT64 KINT)
+LJFOLD(BROR KINT64 KINT)
+LJFOLDF(kfold_int64shift)
+{
+#if LJ_HASFFI || LJ_64
+ uint64_t k = ir_k64(fleft)->u64;
+ int32_t sh = (fright->i & 63);
+ switch ((IROp)fins->o) {
+ case IR_BSHL: k <<= sh; break;
+#if LJ_HASFFI
+ case IR_BSHR: k >>= sh; break;
+ case IR_BSAR: k = (uint64_t)((int64_t)k >> sh); break;
+ case IR_BROL: k = lj_rol(k, sh); break;
+ case IR_BROR: k = lj_ror(k, sh); break;
+#endif
+ default: lua_assert(0); break;
+ }
+ return INT64FOLD(k);
+#else
+ UNUSED(J); lua_assert(0); return FAILFOLD;
+#endif
+}
+
+LJFOLD(BNOT KINT64)
+LJFOLDF(kfold_bnot64)
+{
+#if LJ_HASFFI
+ return INT64FOLD(~ir_k64(fleft)->u64);
+#else
+ UNUSED(J); lua_assert(0); return FAILFOLD;
+#endif
+}
+
+LJFOLD(BSWAP KINT64)
+LJFOLDF(kfold_bswap64)
+{
+#if LJ_HASFFI
+ return INT64FOLD(lj_bswap64(ir_k64(fleft)->u64));
+#else
+ UNUSED(J); lua_assert(0); return FAILFOLD;
+#endif
+}
+
+LJFOLD(LT KINT64 KINT64)
+LJFOLD(GE KINT64 KINT64)
+LJFOLD(LE KINT64 KINT64)
+LJFOLD(GT KINT64 KINT64)
+LJFOLD(ULT KINT64 KINT64)
+LJFOLD(UGE KINT64 KINT64)
+LJFOLD(ULE KINT64 KINT64)
+LJFOLD(UGT KINT64 KINT64)
+LJFOLDF(kfold_int64comp)
+{
+#if LJ_HASFFI
+ uint64_t a = ir_k64(fleft)->u64, b = ir_k64(fright)->u64;
+ switch ((IROp)fins->o) {
+ case IR_LT: return CONDFOLD((int64_t)a < (int64_t)b);
+ case IR_GE: return CONDFOLD((int64_t)a >= (int64_t)b);
+ case IR_LE: return CONDFOLD((int64_t)a <= (int64_t)b);
+ case IR_GT: return CONDFOLD((int64_t)a > (int64_t)b);
+ case IR_ULT: return CONDFOLD(a < b);
+ case IR_UGE: return CONDFOLD(a >= b);
+ case IR_ULE: return CONDFOLD(a <= b);
+ case IR_UGT: return CONDFOLD(a > b);
+ default: lua_assert(0); return FAILFOLD;
+ }
+#else
+ UNUSED(J); lua_assert(0); return FAILFOLD;
+#endif
+}
+
+LJFOLD(UGE any KINT64)
+LJFOLDF(kfold_int64comp0)
+{
+#if LJ_HASFFI
+ if (ir_k64(fright)->u64 == 0)
+ return DROPFOLD;
+ return NEXTFOLD;
+#else
+ UNUSED(J); lua_assert(0); return FAILFOLD;
+#endif
+}
+
+/* -- Constant folding for strings ---------------------------------------- */
+
+LJFOLD(SNEW KKPTR KINT)
+LJFOLDF(kfold_snew_kptr)
+{
+ GCstr *s = lj_str_new(J->L, (const char *)ir_kptr(fleft), (size_t)fright->i);
+ return lj_ir_kstr(J, s);
+}
+
+LJFOLD(SNEW any KINT)
+LJFOLDF(kfold_snew_empty)
+{
+ if (fright->i == 0)
+ return lj_ir_kstr(J, &J2G(J)->strempty);
+ return NEXTFOLD;
+}
+
+LJFOLD(STRREF KGC KINT)
+LJFOLDF(kfold_strref)
+{
+ GCstr *str = ir_kstr(fleft);
+ lua_assert((MSize)fright->i <= str->len);
+ return lj_ir_kkptr(J, (char *)strdata(str) + fright->i);
+}
+
+LJFOLD(STRREF SNEW any)
+LJFOLDF(kfold_strref_snew)
+{
+ PHIBARRIER(fleft);
+ if (irref_isk(fins->op2) && fright->i == 0) {
+ return fleft->op1; /* strref(snew(ptr, len), 0) ==> ptr */
+ } else {
+ /* Reassociate: strref(snew(strref(str, a), len), b) ==> strref(str, a+b) */
+ IRIns *ir = IR(fleft->op1);
+ if (ir->o == IR_STRREF) {
+ IRRef1 str = ir->op1; /* IRIns * is not valid across emitir. */
+ PHIBARRIER(ir);
+ fins->op2 = emitir(IRTI(IR_ADD), ir->op2, fins->op2); /* Clobbers fins! */
+ fins->op1 = str;
+ fins->ot = IRT(IR_STRREF, IRT_P32);
+ return RETRYFOLD;
+ }
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(CALLN CARG IRCALL_lj_str_cmp)
+LJFOLDF(kfold_strcmp)
+{
+ if (irref_isk(fleft->op1) && irref_isk(fleft->op2)) {
+ GCstr *a = ir_kstr(IR(fleft->op1));
+ GCstr *b = ir_kstr(IR(fleft->op2));
+ return INTFOLD(lj_str_cmp(a, b));
+ }
+ return NEXTFOLD;
+}
+
+/* -- Constant folding of pointer arithmetic ------------------------------ */
+
+LJFOLD(ADD KGC KINT)
+LJFOLD(ADD KGC KINT64)
+LJFOLDF(kfold_add_kgc)
+{
+ GCobj *o = ir_kgc(fleft);
+#if LJ_64
+ ptrdiff_t ofs = (ptrdiff_t)ir_kint64(fright)->u64;
+#else
+ ptrdiff_t ofs = fright->i;
+#endif
+#if LJ_HASFFI
+ if (irt_iscdata(fleft->t)) {
+ CType *ct = ctype_raw(ctype_ctsG(J2G(J)), gco2cd(o)->ctypeid);
+ if (ctype_isnum(ct->info) || ctype_isenum(ct->info) ||
+ ctype_isptr(ct->info) || ctype_isfunc(ct->info) ||
+ ctype_iscomplex(ct->info) || ctype_isvector(ct->info))
+ return lj_ir_kkptr(J, (char *)o + ofs);
+ }
+#endif
+ return lj_ir_kptr(J, (char *)o + ofs);
+}
+
+LJFOLD(ADD KPTR KINT)
+LJFOLD(ADD KPTR KINT64)
+LJFOLD(ADD KKPTR KINT)
+LJFOLD(ADD KKPTR KINT64)
+LJFOLDF(kfold_add_kptr)
+{
+ void *p = ir_kptr(fleft);
+#if LJ_64
+ ptrdiff_t ofs = (ptrdiff_t)ir_kint64(fright)->u64;
+#else
+ ptrdiff_t ofs = fright->i;
+#endif
+ return lj_ir_kptr_(J, fleft->o, (char *)p + ofs);
+}
+
+LJFOLD(ADD any KGC)
+LJFOLD(ADD any KPTR)
+LJFOLD(ADD any KKPTR)
+LJFOLDF(kfold_add_kright)
+{
+ if (fleft->o == IR_KINT || fleft->o == IR_KINT64) {
+ IRRef1 tmp = fins->op1; fins->op1 = fins->op2; fins->op2 = tmp;
+ return RETRYFOLD;
+ }
+ return NEXTFOLD;
+}
+
+/* -- Constant folding of conversions ------------------------------------- */
+
+LJFOLD(TOBIT KNUM KNUM)
+LJFOLDF(kfold_tobit)
+{
+ return INTFOLD(lj_num2bit(knumleft));
+}
+
+LJFOLD(CONV KINT IRCONV_NUM_INT)
+LJFOLDF(kfold_conv_kint_num)
+{
+ return lj_ir_knum(J, (lua_Number)fleft->i);
+}
+
+LJFOLD(CONV KINT IRCONV_NUM_U32)
+LJFOLDF(kfold_conv_kintu32_num)
+{
+ return lj_ir_knum(J, (lua_Number)(uint32_t)fleft->i);
+}
+
+LJFOLD(CONV KINT IRCONV_INT_I8)
+LJFOLD(CONV KINT IRCONV_INT_U8)
+LJFOLD(CONV KINT IRCONV_INT_I16)
+LJFOLD(CONV KINT IRCONV_INT_U16)
+LJFOLDF(kfold_conv_kint_ext)
+{
+ int32_t k = fleft->i;
+ if ((fins->op2 & IRCONV_SRCMASK) == IRT_I8) k = (int8_t)k;
+ else if ((fins->op2 & IRCONV_SRCMASK) == IRT_U8) k = (uint8_t)k;
+ else if ((fins->op2 & IRCONV_SRCMASK) == IRT_I16) k = (int16_t)k;
+ else k = (uint16_t)k;
+ return INTFOLD(k);
+}
+
+LJFOLD(CONV KINT IRCONV_I64_INT)
+LJFOLD(CONV KINT IRCONV_U64_INT)
+LJFOLD(CONV KINT IRCONV_I64_U32)
+LJFOLD(CONV KINT IRCONV_U64_U32)
+LJFOLDF(kfold_conv_kint_i64)
+{
+ if ((fins->op2 & IRCONV_SEXT))
+ return INT64FOLD((uint64_t)(int64_t)fleft->i);
+ else
+ return INT64FOLD((uint64_t)(int64_t)(uint32_t)fleft->i);
+}
+
+LJFOLD(CONV KINT64 IRCONV_NUM_I64)
+LJFOLDF(kfold_conv_kint64_num_i64)
+{
+ return lj_ir_knum(J, (lua_Number)(int64_t)ir_kint64(fleft)->u64);
+}
+
+LJFOLD(CONV KINT64 IRCONV_NUM_U64)
+LJFOLDF(kfold_conv_kint64_num_u64)
+{
+ return lj_ir_knum(J, (lua_Number)ir_kint64(fleft)->u64);
+}
+
+LJFOLD(CONV KINT64 IRCONV_INT_I64)
+LJFOLD(CONV KINT64 IRCONV_U32_I64)
+LJFOLDF(kfold_conv_kint64_int_i64)
+{
+ return INTFOLD((int32_t)ir_kint64(fleft)->u64);
+}
+
+LJFOLD(CONV KNUM IRCONV_INT_NUM)
+LJFOLDF(kfold_conv_knum_int_num)
+{
+ lua_Number n = knumleft;
+ if (!(fins->op2 & IRCONV_TRUNC)) {
+ int32_t k = lj_num2int(n);
+ if (irt_isguard(fins->t) && n != (lua_Number)k) {
+ /* We're about to create a guard which always fails, like CONV +1.5.
+ ** Some pathological loops cause this during LICM, e.g.:
+ ** local x,k,t = 0,1.5,{1,[1.5]=2}
+ ** for i=1,200 do x = x+ t[k]; k = k == 1 and 1.5 or 1 end
+ ** assert(x == 300)
+ */
+ return FAILFOLD;
+ }
+ return INTFOLD(k);
+ } else {
+ return INTFOLD((int32_t)n);
+ }
+}
+
+LJFOLD(CONV KNUM IRCONV_U32_NUM)
+LJFOLDF(kfold_conv_knum_u32_num)
+{
+ lua_assert((fins->op2 & IRCONV_TRUNC));
+#ifdef _MSC_VER
+ { /* Workaround for MSVC bug. */
+ volatile uint32_t u = (uint32_t)knumleft;
+ return INTFOLD((int32_t)u);
+ }
+#else
+ return INTFOLD((int32_t)(uint32_t)knumleft);
+#endif
+}
+
+LJFOLD(CONV KNUM IRCONV_I64_NUM)
+LJFOLDF(kfold_conv_knum_i64_num)
+{
+ lua_assert((fins->op2 & IRCONV_TRUNC));
+ return INT64FOLD((uint64_t)(int64_t)knumleft);
+}
+
+LJFOLD(CONV KNUM IRCONV_U64_NUM)
+LJFOLDF(kfold_conv_knum_u64_num)
+{
+ lua_assert((fins->op2 & IRCONV_TRUNC));
+ return INT64FOLD(lj_num2u64(knumleft));
+}
+
+LJFOLD(TOSTR KNUM)
+LJFOLDF(kfold_tostr_knum)
+{
+ return lj_ir_kstr(J, lj_str_fromnum(J->L, &knumleft));
+}
+
+LJFOLD(TOSTR KINT)
+LJFOLDF(kfold_tostr_kint)
+{
+ return lj_ir_kstr(J, lj_str_fromint(J->L, fleft->i));
+}
+
+LJFOLD(STRTO KGC)
+LJFOLDF(kfold_strto)
+{
+ TValue n;
+ if (lj_strscan_num(ir_kstr(fleft), &n))
+ return lj_ir_knum(J, numV(&n));
+ return FAILFOLD;
+}
+
+/* -- Constant folding of equality checks --------------------------------- */
+
+/* Don't constant-fold away FLOAD checks against KNULL. */
+LJFOLD(EQ FLOAD KNULL)
+LJFOLD(NE FLOAD KNULL)
+LJFOLDX(lj_opt_cse)
+
+/* But fold all other KNULL compares, since only KNULL is equal to KNULL. */
+LJFOLD(EQ any KNULL)
+LJFOLD(NE any KNULL)
+LJFOLD(EQ KNULL any)
+LJFOLD(NE KNULL any)
+LJFOLD(EQ KINT KINT) /* Constants are unique, so same refs <==> same value. */
+LJFOLD(NE KINT KINT)
+LJFOLD(EQ KINT64 KINT64)
+LJFOLD(NE KINT64 KINT64)
+LJFOLD(EQ KGC KGC)
+LJFOLD(NE KGC KGC)
+LJFOLDF(kfold_kref)
+{
+ return CONDFOLD((fins->op1 == fins->op2) ^ (fins->o == IR_NE));
+}
+
+/* -- Algebraic shortcuts ------------------------------------------------- */
+
+LJFOLD(FPMATH FPMATH IRFPM_FLOOR)
+LJFOLD(FPMATH FPMATH IRFPM_CEIL)
+LJFOLD(FPMATH FPMATH IRFPM_TRUNC)
+LJFOLDF(shortcut_round)
+{
+ IRFPMathOp op = (IRFPMathOp)fleft->op2;
+ if (op == IRFPM_FLOOR || op == IRFPM_CEIL || op == IRFPM_TRUNC)
+ return LEFTFOLD; /* round(round_left(x)) = round_left(x) */
+ return NEXTFOLD;
+}
+
+LJFOLD(ABS ABS KNUM)
+LJFOLDF(shortcut_left)
+{
+ return LEFTFOLD; /* f(g(x)) ==> g(x) */
+}
+
+LJFOLD(ABS NEG KNUM)
+LJFOLDF(shortcut_dropleft)
+{
+ PHIBARRIER(fleft);
+ fins->op1 = fleft->op1; /* abs(neg(x)) ==> abs(x) */
+ return RETRYFOLD;
+}
+
+/* Note: no safe shortcuts with STRTO and TOSTR ("1e2" ==> +100 ==> "100"). */
+LJFOLD(NEG NEG any)
+LJFOLD(BNOT BNOT)
+LJFOLD(BSWAP BSWAP)
+LJFOLDF(shortcut_leftleft)
+{
+ PHIBARRIER(fleft); /* See above. Fold would be ok, but not beneficial. */
+ return fleft->op1; /* f(g(x)) ==> x */
+}
+
+/* -- FP algebraic simplifications ---------------------------------------- */
+
+/* FP arithmetic is tricky -- there's not much to simplify.
+** Please note the following common pitfalls before sending "improvements":
+** x+0 ==> x is INVALID for x=-0
+** 0-x ==> -x is INVALID for x=+0
+** x*0 ==> 0 is INVALID for x=-0, x=+-Inf or x=NaN
+*/
+
+LJFOLD(ADD NEG any)
+LJFOLDF(simplify_numadd_negx)
+{
+ PHIBARRIER(fleft);
+ fins->o = IR_SUB; /* (-a) + b ==> b - a */
+ fins->op1 = fins->op2;
+ fins->op2 = fleft->op1;
+ return RETRYFOLD;
+}
+
+LJFOLD(ADD any NEG)
+LJFOLDF(simplify_numadd_xneg)
+{
+ PHIBARRIER(fright);
+ fins->o = IR_SUB; /* a + (-b) ==> a - b */
+ fins->op2 = fright->op1;
+ return RETRYFOLD;
+}
+
+LJFOLD(SUB any KNUM)
+LJFOLDF(simplify_numsub_k)
+{
+ lua_Number n = knumright;
+ if (n == 0.0) /* x - (+-0) ==> x */
+ return LEFTFOLD;
+ return NEXTFOLD;
+}
+
+LJFOLD(SUB NEG KNUM)
+LJFOLDF(simplify_numsub_negk)
+{
+ PHIBARRIER(fleft);
+ fins->op2 = fleft->op1; /* (-x) - k ==> (-k) - x */
+ fins->op1 = (IRRef1)lj_ir_knum(J, -knumright);
+ return RETRYFOLD;
+}
+
+LJFOLD(SUB any NEG)
+LJFOLDF(simplify_numsub_xneg)
+{
+ PHIBARRIER(fright);
+ fins->o = IR_ADD; /* a - (-b) ==> a + b */
+ fins->op2 = fright->op1;
+ return RETRYFOLD;
+}
+
+LJFOLD(MUL any KNUM)
+LJFOLD(DIV any KNUM)
+LJFOLDF(simplify_nummuldiv_k)
+{
+ lua_Number n = knumright;
+ if (n == 1.0) { /* x o 1 ==> x */
+ return LEFTFOLD;
+ } else if (n == -1.0) { /* x o -1 ==> -x */
+ fins->o = IR_NEG;
+ fins->op2 = (IRRef1)lj_ir_knum_neg(J);
+ return RETRYFOLD;
+ } else if (fins->o == IR_MUL && n == 2.0) { /* x * 2 ==> x + x */
+ fins->o = IR_ADD;
+ fins->op2 = fins->op1;
+ return RETRYFOLD;
+ } else if (fins->o == IR_DIV) { /* x / 2^k ==> x * 2^-k */
+ uint64_t u = ir_knum(fright)->u64;
+ uint32_t ex = ((uint32_t)(u >> 52) & 0x7ff);
+ if ((u & U64x(000fffff,ffffffff)) == 0 && ex - 1 < 0x7fd) {
+ u = (u & ((uint64_t)1 << 63)) | ((uint64_t)(0x7fe - ex) << 52);
+ fins->o = IR_MUL; /* Multiply by exact reciprocal. */
+ fins->op2 = lj_ir_knum_u64(J, u);
+ return RETRYFOLD;
+ }
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(MUL NEG KNUM)
+LJFOLD(DIV NEG KNUM)
+LJFOLDF(simplify_nummuldiv_negk)
+{
+ PHIBARRIER(fleft);
+ fins->op1 = fleft->op1; /* (-a) o k ==> a o (-k) */
+ fins->op2 = (IRRef1)lj_ir_knum(J, -knumright);
+ return RETRYFOLD;
+}
+
+LJFOLD(MUL NEG NEG)
+LJFOLD(DIV NEG NEG)
+LJFOLDF(simplify_nummuldiv_negneg)
+{
+ PHIBARRIER(fleft);
+ PHIBARRIER(fright);
+ fins->op1 = fleft->op1; /* (-a) o (-b) ==> a o b */
+ fins->op2 = fright->op1;
+ return RETRYFOLD;
+}
+
+LJFOLD(POW any KINT)
+LJFOLDF(simplify_numpow_xk)
+{
+ int32_t k = fright->i;
+ TRef ref = fins->op1;
+ if (k == 0) /* x ^ 0 ==> 1 */
+ return lj_ir_knum_one(J); /* Result must be a number, not an int. */
+ if (k == 1) /* x ^ 1 ==> x */
+ return LEFTFOLD;
+ if ((uint32_t)(k+65536) > 2*65536u) /* Limit code explosion. */
+ return NEXTFOLD;
+ if (k < 0) { /* x ^ (-k) ==> (1/x) ^ k. */
+ ref = emitir(IRTN(IR_DIV), lj_ir_knum_one(J), ref);
+ k = -k;
+ }
+ /* Unroll x^k for 1 <= k <= 65536. */
+ for (; (k & 1) == 0; k >>= 1) /* Handle leading zeros. */
+ ref = emitir(IRTN(IR_MUL), ref, ref);
+ if ((k >>= 1) != 0) { /* Handle trailing bits. */
+ TRef tmp = emitir(IRTN(IR_MUL), ref, ref);
+ for (; k != 1; k >>= 1) {
+ if (k & 1)
+ ref = emitir(IRTN(IR_MUL), ref, tmp);
+ tmp = emitir(IRTN(IR_MUL), tmp, tmp);
+ }
+ ref = emitir(IRTN(IR_MUL), ref, tmp);
+ }
+ return ref;
+}
+
+LJFOLD(POW KNUM any)
+LJFOLDF(simplify_numpow_kx)
+{
+ lua_Number n = knumleft;
+ if (n == 2.0) { /* 2.0 ^ i ==> ldexp(1.0, tonum(i)) */
+ fins->o = IR_CONV;
+#if LJ_TARGET_X86ORX64
+ fins->op1 = fins->op2;
+ fins->op2 = IRCONV_NUM_INT;
+ fins->op2 = (IRRef1)lj_opt_fold(J);
+#endif
+ fins->op1 = (IRRef1)lj_ir_knum_one(J);
+ fins->o = IR_LDEXP;
+ return RETRYFOLD;
+ }
+ return NEXTFOLD;
+}
+
+/* -- Simplify conversions ------------------------------------------------ */
+
+LJFOLD(CONV CONV IRCONV_NUM_INT) /* _NUM */
+LJFOLDF(shortcut_conv_num_int)
+{
+ PHIBARRIER(fleft);
+ /* Only safe with a guarded conversion to int. */
+ if ((fleft->op2 & IRCONV_SRCMASK) == IRT_NUM && irt_isguard(fleft->t))
+ return fleft->op1; /* f(g(x)) ==> x */
+ return NEXTFOLD;
+}
+
+LJFOLD(CONV CONV IRCONV_INT_NUM) /* _INT */
+LJFOLD(CONV CONV IRCONV_U32_NUM) /* _U32*/
+LJFOLDF(simplify_conv_int_num)
+{
+ /* Fold even across PHI to avoid expensive num->int conversions in loop. */
+ if ((fleft->op2 & IRCONV_SRCMASK) ==
+ ((fins->op2 & IRCONV_DSTMASK) >> IRCONV_DSH))
+ return fleft->op1;
+ return NEXTFOLD;
+}
+
+LJFOLD(CONV CONV IRCONV_I64_NUM) /* _INT or _U32 */
+LJFOLD(CONV CONV IRCONV_U64_NUM) /* _INT or _U32 */
+LJFOLDF(simplify_conv_i64_num)
+{
+ PHIBARRIER(fleft);
+ if ((fleft->op2 & IRCONV_SRCMASK) == IRT_INT) {
+ /* Reduce to a sign-extension. */
+ fins->op1 = fleft->op1;
+ fins->op2 = ((IRT_I64<<5)|IRT_INT|IRCONV_SEXT);
+ return RETRYFOLD;
+ } else if ((fleft->op2 & IRCONV_SRCMASK) == IRT_U32) {
+#if LJ_TARGET_X64
+ return fleft->op1;
+#else
+ /* Reduce to a zero-extension. */
+ fins->op1 = fleft->op1;
+ fins->op2 = (IRT_I64<<5)|IRT_U32;
+ return RETRYFOLD;
+#endif
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(CONV CONV IRCONV_INT_I64) /* _INT or _U32 */
+LJFOLD(CONV CONV IRCONV_INT_U64) /* _INT or _U32 */
+LJFOLD(CONV CONV IRCONV_U32_I64) /* _INT or _U32 */
+LJFOLD(CONV CONV IRCONV_U32_U64) /* _INT or _U32 */
+LJFOLDF(simplify_conv_int_i64)
+{
+ int src;
+ PHIBARRIER(fleft);
+ src = (fleft->op2 & IRCONV_SRCMASK);
+ if (src == IRT_INT || src == IRT_U32) {
+ if (src == ((fins->op2 & IRCONV_DSTMASK) >> IRCONV_DSH)) {
+ return fleft->op1;
+ } else {
+ fins->op2 = ((fins->op2 & IRCONV_DSTMASK) | src);
+ fins->op1 = fleft->op1;
+ return RETRYFOLD;
+ }
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(CONV CONV IRCONV_FLOAT_NUM) /* _FLOAT */
+LJFOLDF(simplify_conv_flt_num)
+{
+ PHIBARRIER(fleft);
+ if ((fleft->op2 & IRCONV_SRCMASK) == IRT_FLOAT)
+ return fleft->op1;
+ return NEXTFOLD;
+}
+
+/* Shortcut TOBIT + IRT_NUM <- IRT_INT/IRT_U32 conversion. */
+LJFOLD(TOBIT CONV KNUM)
+LJFOLDF(simplify_tobit_conv)
+{
+ /* Fold even across PHI to avoid expensive num->int conversions in loop. */
+ if ((fleft->op2 & IRCONV_SRCMASK) == IRT_INT) {
+ lua_assert(irt_isnum(fleft->t));
+ return fleft->op1;
+ } else if ((fleft->op2 & IRCONV_SRCMASK) == IRT_U32) {
+ lua_assert(irt_isnum(fleft->t));
+ fins->o = IR_CONV;
+ fins->op1 = fleft->op1;
+ fins->op2 = (IRT_INT<<5)|IRT_U32;
+ return RETRYFOLD;
+ }
+ return NEXTFOLD;
+}
+
+/* Shortcut floor/ceil/round + IRT_NUM <- IRT_INT/IRT_U32 conversion. */
+LJFOLD(FPMATH CONV IRFPM_FLOOR)
+LJFOLD(FPMATH CONV IRFPM_CEIL)
+LJFOLD(FPMATH CONV IRFPM_TRUNC)
+LJFOLDF(simplify_floor_conv)
+{
+ if ((fleft->op2 & IRCONV_SRCMASK) == IRT_INT ||
+ (fleft->op2 & IRCONV_SRCMASK) == IRT_U32)
+ return LEFTFOLD;
+ return NEXTFOLD;
+}
+
+/* Strength reduction of widening. */
+LJFOLD(CONV any IRCONV_I64_INT)
+LJFOLD(CONV any IRCONV_U64_INT)
+LJFOLDF(simplify_conv_sext)
+{
+ IRRef ref = fins->op1;
+ int64_t ofs = 0;
+ if (!(fins->op2 & IRCONV_SEXT))
+ return NEXTFOLD;
+ PHIBARRIER(fleft);
+ if (fleft->o == IR_XLOAD && (irt_isu8(fleft->t) || irt_isu16(fleft->t)))
+ goto ok_reduce;
+ if (fleft->o == IR_ADD && irref_isk(fleft->op2)) {
+ ofs = (int64_t)IR(fleft->op2)->i;
+ ref = fleft->op1;
+ }
+ /* Use scalar evolution analysis results to strength-reduce sign-extension. */
+ if (ref == J->scev.idx) {
+ IRRef lo = J->scev.dir ? J->scev.start : J->scev.stop;
+ lua_assert(irt_isint(J->scev.t));
+ if (lo && IR(lo)->o == IR_KINT && IR(lo)->i + ofs >= 0) {
+ ok_reduce:
+#if LJ_TARGET_X64
+ /* Eliminate widening. All 32 bit ops do an implicit zero-extension. */
+ return LEFTFOLD;
+#else
+ /* Reduce to a (cheaper) zero-extension. */
+ fins->op2 &= ~IRCONV_SEXT;
+ return RETRYFOLD;
+#endif
+ }
+ }
+ return NEXTFOLD;
+}
+
+/* Strength reduction of narrowing. */
+LJFOLD(CONV ADD IRCONV_INT_I64)
+LJFOLD(CONV SUB IRCONV_INT_I64)
+LJFOLD(CONV MUL IRCONV_INT_I64)
+LJFOLD(CONV ADD IRCONV_INT_U64)
+LJFOLD(CONV SUB IRCONV_INT_U64)
+LJFOLD(CONV MUL IRCONV_INT_U64)
+LJFOLD(CONV ADD IRCONV_U32_I64)
+LJFOLD(CONV SUB IRCONV_U32_I64)
+LJFOLD(CONV MUL IRCONV_U32_I64)
+LJFOLD(CONV ADD IRCONV_U32_U64)
+LJFOLD(CONV SUB IRCONV_U32_U64)
+LJFOLD(CONV MUL IRCONV_U32_U64)
+LJFOLDF(simplify_conv_narrow)
+{
+ IROp op = (IROp)fleft->o;
+ IRType t = irt_type(fins->t);
+ IRRef op1 = fleft->op1, op2 = fleft->op2, mode = fins->op2;
+ PHIBARRIER(fleft);
+ op1 = emitir(IRTI(IR_CONV), op1, mode);
+ op2 = emitir(IRTI(IR_CONV), op2, mode);
+ fins->ot = IRT(op, t);
+ fins->op1 = op1;
+ fins->op2 = op2;
+ return RETRYFOLD;
+}
+
+/* Special CSE rule for CONV. */
+LJFOLD(CONV any any)
+LJFOLDF(cse_conv)
+{
+ if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) {
+ IRRef op1 = fins->op1, op2 = (fins->op2 & IRCONV_MODEMASK);
+ uint8_t guard = irt_isguard(fins->t);
+ IRRef ref = J->chain[IR_CONV];
+ while (ref > op1) {
+ IRIns *ir = IR(ref);
+ /* Commoning with stronger checks is ok. */
+ if (ir->op1 == op1 && (ir->op2 & IRCONV_MODEMASK) == op2 &&
+ irt_isguard(ir->t) >= guard)
+ return ref;
+ ref = ir->prev;
+ }
+ }
+ return EMITFOLD; /* No fallthrough to regular CSE. */
+}
+
+/* FP conversion narrowing. */
+LJFOLD(TOBIT ADD KNUM)
+LJFOLD(TOBIT SUB KNUM)
+LJFOLD(CONV ADD IRCONV_INT_NUM)
+LJFOLD(CONV SUB IRCONV_INT_NUM)
+LJFOLD(CONV ADD IRCONV_I64_NUM)
+LJFOLD(CONV SUB IRCONV_I64_NUM)
+LJFOLDF(narrow_convert)
+{
+ PHIBARRIER(fleft);
+ /* Narrowing ignores PHIs and repeating it inside the loop is not useful. */
+ if (J->chain[IR_LOOP])
+ return NEXTFOLD;
+ lua_assert(fins->o != IR_CONV || (fins->op2&IRCONV_CONVMASK) != IRCONV_TOBIT);
+ return lj_opt_narrow_convert(J);
+}
+
+/* -- Integer algebraic simplifications ----------------------------------- */
+
+LJFOLD(ADD any KINT)
+LJFOLD(ADDOV any KINT)
+LJFOLD(SUBOV any KINT)
+LJFOLDF(simplify_intadd_k)
+{
+ if (fright->i == 0) /* i o 0 ==> i */
+ return LEFTFOLD;
+ return NEXTFOLD;
+}
+
+LJFOLD(MULOV any KINT)
+LJFOLDF(simplify_intmul_k)
+{
+ if (fright->i == 0) /* i * 0 ==> 0 */
+ return RIGHTFOLD;
+ if (fright->i == 1) /* i * 1 ==> i */
+ return LEFTFOLD;
+ if (fright->i == 2) { /* i * 2 ==> i + i */
+ fins->o = IR_ADDOV;
+ fins->op2 = fins->op1;
+ return RETRYFOLD;
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(SUB any KINT)
+LJFOLDF(simplify_intsub_k)
+{
+ if (fright->i == 0) /* i - 0 ==> i */
+ return LEFTFOLD;
+ fins->o = IR_ADD; /* i - k ==> i + (-k) */
+ fins->op2 = (IRRef1)lj_ir_kint(J, -fright->i); /* Overflow for -2^31 ok. */
+ return RETRYFOLD;
+}
+
+LJFOLD(SUB KINT any)
+LJFOLD(SUB KINT64 any)
+LJFOLDF(simplify_intsub_kleft)
+{
+ if (fleft->o == IR_KINT ? (fleft->i == 0) : (ir_kint64(fleft)->u64 == 0)) {
+ fins->o = IR_NEG; /* 0 - i ==> -i */
+ fins->op1 = fins->op2;
+ return RETRYFOLD;
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(ADD any KINT64)
+LJFOLDF(simplify_intadd_k64)
+{
+ if (ir_kint64(fright)->u64 == 0) /* i + 0 ==> i */
+ return LEFTFOLD;
+ return NEXTFOLD;
+}
+
+LJFOLD(SUB any KINT64)
+LJFOLDF(simplify_intsub_k64)
+{
+ uint64_t k = ir_kint64(fright)->u64;
+ if (k == 0) /* i - 0 ==> i */
+ return LEFTFOLD;
+ fins->o = IR_ADD; /* i - k ==> i + (-k) */
+ fins->op2 = (IRRef1)lj_ir_kint64(J, (uint64_t)-(int64_t)k);
+ return RETRYFOLD;
+}
+
+static TRef simplify_intmul_k(jit_State *J, int32_t k)
+{
+ /* Note: many more simplifications are possible, e.g. 2^k1 +- 2^k2.
+ ** But this is mainly intended for simple address arithmetic.
+ ** Also it's easier for the backend to optimize the original multiplies.
+ */
+ if (k == 1) { /* i * 1 ==> i */
+ return LEFTFOLD;
+ } else if ((k & (k-1)) == 0) { /* i * 2^k ==> i << k */
+ fins->o = IR_BSHL;
+ fins->op2 = lj_ir_kint(J, lj_fls((uint32_t)k));
+ return RETRYFOLD;
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(MUL any KINT)
+LJFOLDF(simplify_intmul_k32)
+{
+ if (fright->i == 0) /* i * 0 ==> 0 */
+ return INTFOLD(0);
+ else if (fright->i > 0)
+ return simplify_intmul_k(J, fright->i);
+ return NEXTFOLD;
+}
+
+LJFOLD(MUL any KINT64)
+LJFOLDF(simplify_intmul_k64)
+{
+ if (ir_kint64(fright)->u64 == 0) /* i * 0 ==> 0 */
+ return INT64FOLD(0);
+#if LJ_64
+ /* NYI: SPLIT for BSHL and 32 bit backend support. */
+ else if (ir_kint64(fright)->u64 < 0x80000000u)
+ return simplify_intmul_k(J, (int32_t)ir_kint64(fright)->u64);
+#endif
+ return NEXTFOLD;
+}
+
+LJFOLD(MOD any KINT)
+LJFOLDF(simplify_intmod_k)
+{
+ int32_t k = fright->i;
+ lua_assert(k != 0);
+ if (k > 0 && (k & (k-1)) == 0) { /* i % (2^k) ==> i & (2^k-1) */
+ fins->o = IR_BAND;
+ fins->op2 = lj_ir_kint(J, k-1);
+ return RETRYFOLD;
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(MOD KINT any)
+LJFOLDF(simplify_intmod_kleft)
+{
+ if (fleft->i == 0)
+ return INTFOLD(0);
+ return NEXTFOLD;
+}
+
+LJFOLD(SUB any any)
+LJFOLD(SUBOV any any)
+LJFOLDF(simplify_intsub)
+{
+ if (fins->op1 == fins->op2 && !irt_isnum(fins->t)) /* i - i ==> 0 */
+ return irt_is64(fins->t) ? INT64FOLD(0) : INTFOLD(0);
+ return NEXTFOLD;
+}
+
+LJFOLD(SUB ADD any)
+LJFOLDF(simplify_intsubadd_leftcancel)
+{
+ if (!irt_isnum(fins->t)) {
+ PHIBARRIER(fleft);
+ if (fins->op2 == fleft->op1) /* (i + j) - i ==> j */
+ return fleft->op2;
+ if (fins->op2 == fleft->op2) /* (i + j) - j ==> i */
+ return fleft->op1;
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(SUB SUB any)
+LJFOLDF(simplify_intsubsub_leftcancel)
+{
+ if (!irt_isnum(fins->t)) {
+ PHIBARRIER(fleft);
+ if (fins->op2 == fleft->op1) { /* (i - j) - i ==> 0 - j */
+ fins->op1 = (IRRef1)lj_ir_kint(J, 0);
+ fins->op2 = fleft->op2;
+ return RETRYFOLD;
+ }
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(SUB any SUB)
+LJFOLDF(simplify_intsubsub_rightcancel)
+{
+ if (!irt_isnum(fins->t)) {
+ PHIBARRIER(fright);
+ if (fins->op1 == fright->op1) /* i - (i - j) ==> j */
+ return fright->op2;
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(SUB any ADD)
+LJFOLDF(simplify_intsubadd_rightcancel)
+{
+ if (!irt_isnum(fins->t)) {
+ PHIBARRIER(fright);
+ if (fins->op1 == fright->op1) { /* i - (i + j) ==> 0 - j */
+ fins->op2 = fright->op2;
+ fins->op1 = (IRRef1)lj_ir_kint(J, 0);
+ return RETRYFOLD;
+ }
+ if (fins->op1 == fright->op2) { /* i - (j + i) ==> 0 - j */
+ fins->op2 = fright->op1;
+ fins->op1 = (IRRef1)lj_ir_kint(J, 0);
+ return RETRYFOLD;
+ }
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(SUB ADD ADD)
+LJFOLDF(simplify_intsubaddadd_cancel)
+{
+ if (!irt_isnum(fins->t)) {
+ PHIBARRIER(fleft);
+ PHIBARRIER(fright);
+ if (fleft->op1 == fright->op1) { /* (i + j1) - (i + j2) ==> j1 - j2 */
+ fins->op1 = fleft->op2;
+ fins->op2 = fright->op2;
+ return RETRYFOLD;
+ }
+ if (fleft->op1 == fright->op2) { /* (i + j1) - (j2 + i) ==> j1 - j2 */
+ fins->op1 = fleft->op2;
+ fins->op2 = fright->op1;
+ return RETRYFOLD;
+ }
+ if (fleft->op2 == fright->op1) { /* (j1 + i) - (i + j2) ==> j1 - j2 */
+ fins->op1 = fleft->op1;
+ fins->op2 = fright->op2;
+ return RETRYFOLD;
+ }
+ if (fleft->op2 == fright->op2) { /* (j1 + i) - (j2 + i) ==> j1 - j2 */
+ fins->op1 = fleft->op1;
+ fins->op2 = fright->op1;
+ return RETRYFOLD;
+ }
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(BAND any KINT)
+LJFOLD(BAND any KINT64)
+LJFOLDF(simplify_band_k)
+{
+ int64_t k = fright->o == IR_KINT ? (int64_t)fright->i :
+ (int64_t)ir_k64(fright)->u64;
+ if (k == 0) /* i & 0 ==> 0 */
+ return RIGHTFOLD;
+ if (k == -1) /* i & -1 ==> i */
+ return LEFTFOLD;
+ return NEXTFOLD;
+}
+
+LJFOLD(BOR any KINT)
+LJFOLD(BOR any KINT64)
+LJFOLDF(simplify_bor_k)
+{
+ int64_t k = fright->o == IR_KINT ? (int64_t)fright->i :
+ (int64_t)ir_k64(fright)->u64;
+ if (k == 0) /* i | 0 ==> i */
+ return LEFTFOLD;
+ if (k == -1) /* i | -1 ==> -1 */
+ return RIGHTFOLD;
+ return NEXTFOLD;
+}
+
+LJFOLD(BXOR any KINT)
+LJFOLD(BXOR any KINT64)
+LJFOLDF(simplify_bxor_k)
+{
+ int64_t k = fright->o == IR_KINT ? (int64_t)fright->i :
+ (int64_t)ir_k64(fright)->u64;
+ if (k == 0) /* i xor 0 ==> i */
+ return LEFTFOLD;
+ if (k == -1) { /* i xor -1 ==> ~i */
+ fins->o = IR_BNOT;
+ fins->op2 = 0;
+ return RETRYFOLD;
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(BSHL any KINT)
+LJFOLD(BSHR any KINT)
+LJFOLD(BSAR any KINT)
+LJFOLD(BROL any KINT)
+LJFOLD(BROR any KINT)
+LJFOLDF(simplify_shift_ik)
+{
+ int32_t mask = irt_is64(fins->t) ? 63 : 31;
+ int32_t k = (fright->i & mask);
+ if (k == 0) /* i o 0 ==> i */
+ return LEFTFOLD;
+ if (k == 1 && fins->o == IR_BSHL) { /* i << 1 ==> i + i */
+ fins->o = IR_ADD;
+ fins->op2 = fins->op1;
+ return RETRYFOLD;
+ }
+ if (k != fright->i) { /* i o k ==> i o (k & mask) */
+ fins->op2 = (IRRef1)lj_ir_kint(J, k);
+ return RETRYFOLD;
+ }
+#ifndef LJ_TARGET_UNIFYROT
+ if (fins->o == IR_BROR) { /* bror(i, k) ==> brol(i, (-k)&mask) */
+ fins->o = IR_BROL;
+ fins->op2 = (IRRef1)lj_ir_kint(J, (-k)&mask);
+ return RETRYFOLD;
+ }
+#endif
+ return NEXTFOLD;
+}
+
+LJFOLD(BSHL any BAND)
+LJFOLD(BSHR any BAND)
+LJFOLD(BSAR any BAND)
+LJFOLD(BROL any BAND)
+LJFOLD(BROR any BAND)
+LJFOLDF(simplify_shift_andk)
+{
+ IRIns *irk = IR(fright->op2);
+ PHIBARRIER(fright);
+ if ((fins->o < IR_BROL ? LJ_TARGET_MASKSHIFT : LJ_TARGET_MASKROT) &&
+ irk->o == IR_KINT) { /* i o (j & mask) ==> i o j */
+ int32_t mask = irt_is64(fins->t) ? 63 : 31;
+ int32_t k = irk->i & mask;
+ if (k == mask) {
+ fins->op2 = fright->op1;
+ return RETRYFOLD;
+ }
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(BSHL KINT any)
+LJFOLD(BSHR KINT any)
+LJFOLD(BSHL KINT64 any)
+LJFOLD(BSHR KINT64 any)
+LJFOLDF(simplify_shift1_ki)
+{
+ int64_t k = fleft->o == IR_KINT ? (int64_t)fleft->i :
+ (int64_t)ir_k64(fleft)->u64;
+ if (k == 0) /* 0 o i ==> 0 */
+ return LEFTFOLD;
+ return NEXTFOLD;
+}
+
+LJFOLD(BSAR KINT any)
+LJFOLD(BROL KINT any)
+LJFOLD(BROR KINT any)
+LJFOLD(BSAR KINT64 any)
+LJFOLD(BROL KINT64 any)
+LJFOLD(BROR KINT64 any)
+LJFOLDF(simplify_shift2_ki)
+{
+ int64_t k = fleft->o == IR_KINT ? (int64_t)fleft->i :
+ (int64_t)ir_k64(fleft)->u64;
+ if (k == 0 || k == -1) /* 0 o i ==> 0; -1 o i ==> -1 */
+ return LEFTFOLD;
+ return NEXTFOLD;
+}
+
+LJFOLD(BSHL BAND KINT)
+LJFOLD(BSHR BAND KINT)
+LJFOLD(BROL BAND KINT)
+LJFOLD(BROR BAND KINT)
+LJFOLDF(simplify_shiftk_andk)
+{
+ IRIns *irk = IR(fleft->op2);
+ PHIBARRIER(fleft);
+ if (irk->o == IR_KINT) { /* (i & k1) o k2 ==> (i o k2) & (k1 o k2) */
+ int32_t k = kfold_intop(irk->i, fright->i, (IROp)fins->o);
+ fins->op1 = fleft->op1;
+ fins->op1 = (IRRef1)lj_opt_fold(J);
+ fins->op2 = (IRRef1)lj_ir_kint(J, k);
+ fins->ot = IRTI(IR_BAND);
+ return RETRYFOLD;
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(BAND BSHL KINT)
+LJFOLD(BAND BSHR KINT)
+LJFOLDF(simplify_andk_shiftk)
+{
+ IRIns *irk = IR(fleft->op2);
+ if (irk->o == IR_KINT &&
+ kfold_intop(-1, irk->i, (IROp)fleft->o) == fright->i)
+ return LEFTFOLD; /* (i o k1) & k2 ==> i, if (-1 o k1) == k2 */
+ return NEXTFOLD;
+}
+
+/* -- Reassociation ------------------------------------------------------- */
+
+LJFOLD(ADD ADD KINT)
+LJFOLD(MUL MUL KINT)
+LJFOLD(BAND BAND KINT)
+LJFOLD(BOR BOR KINT)
+LJFOLD(BXOR BXOR KINT)
+LJFOLDF(reassoc_intarith_k)
+{
+ IRIns *irk = IR(fleft->op2);
+ if (irk->o == IR_KINT) {
+ int32_t k = kfold_intop(irk->i, fright->i, (IROp)fins->o);
+ if (k == irk->i) /* (i o k1) o k2 ==> i o k1, if (k1 o k2) == k1. */
+ return LEFTFOLD;
+ PHIBARRIER(fleft);
+ fins->op1 = fleft->op1;
+ fins->op2 = (IRRef1)lj_ir_kint(J, k);
+ return RETRYFOLD; /* (i o k1) o k2 ==> i o (k1 o k2) */
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(ADD ADD KINT64)
+LJFOLD(MUL MUL KINT64)
+LJFOLD(BAND BAND KINT64)
+LJFOLD(BOR BOR KINT64)
+LJFOLD(BXOR BXOR KINT64)
+LJFOLDF(reassoc_intarith_k64)
+{
+#if LJ_HASFFI || LJ_64
+ IRIns *irk = IR(fleft->op2);
+ if (irk->o == IR_KINT64) {
+ uint64_t k = kfold_int64arith(ir_k64(irk)->u64,
+ ir_k64(fright)->u64, (IROp)fins->o);
+ PHIBARRIER(fleft);
+ fins->op1 = fleft->op1;
+ fins->op2 = (IRRef1)lj_ir_kint64(J, k);
+ return RETRYFOLD; /* (i o k1) o k2 ==> i o (k1 o k2) */
+ }
+ return NEXTFOLD;
+#else
+ UNUSED(J); lua_assert(0); return FAILFOLD;
+#endif
+}
+
+LJFOLD(MIN MIN any)
+LJFOLD(MAX MAX any)
+LJFOLD(BAND BAND any)
+LJFOLD(BOR BOR any)
+LJFOLDF(reassoc_dup)
+{
+ if (fins->op2 == fleft->op1 || fins->op2 == fleft->op2)
+ return LEFTFOLD; /* (a o b) o a ==> a o b; (a o b) o b ==> a o b */
+ return NEXTFOLD;
+}
+
+LJFOLD(BXOR BXOR any)
+LJFOLDF(reassoc_bxor)
+{
+ PHIBARRIER(fleft);
+ if (fins->op2 == fleft->op1) /* (a xor b) xor a ==> b */
+ return fleft->op2;
+ if (fins->op2 == fleft->op2) /* (a xor b) xor b ==> a */
+ return fleft->op1;
+ return NEXTFOLD;
+}
+
+LJFOLD(BSHL BSHL KINT)
+LJFOLD(BSHR BSHR KINT)
+LJFOLD(BSAR BSAR KINT)
+LJFOLD(BROL BROL KINT)
+LJFOLD(BROR BROR KINT)
+LJFOLDF(reassoc_shift)
+{
+ IRIns *irk = IR(fleft->op2);
+ PHIBARRIER(fleft); /* The (shift any KINT) rule covers k2 == 0 and more. */
+ if (irk->o == IR_KINT) { /* (i o k1) o k2 ==> i o (k1 + k2) */
+ int32_t mask = irt_is64(fins->t) ? 63 : 31;
+ int32_t k = (irk->i & mask) + (fright->i & mask);
+ if (k > mask) { /* Combined shift too wide? */
+ if (fins->o == IR_BSHL || fins->o == IR_BSHR)
+ return mask == 31 ? INTFOLD(0) : INT64FOLD(0);
+ else if (fins->o == IR_BSAR)
+ k = mask;
+ else
+ k &= mask;
+ }
+ fins->op1 = fleft->op1;
+ fins->op2 = (IRRef1)lj_ir_kint(J, k);
+ return RETRYFOLD;
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(MIN MIN KNUM)
+LJFOLD(MAX MAX KNUM)
+LJFOLD(MIN MIN KINT)
+LJFOLD(MAX MAX KINT)
+LJFOLDF(reassoc_minmax_k)
+{
+ IRIns *irk = IR(fleft->op2);
+ if (irk->o == IR_KNUM) {
+ lua_Number a = ir_knum(irk)->n;
+ lua_Number y = lj_vm_foldarith(a, knumright, fins->o - IR_ADD);
+ if (a == y) /* (x o k1) o k2 ==> x o k1, if (k1 o k2) == k1. */
+ return LEFTFOLD;
+ PHIBARRIER(fleft);
+ fins->op1 = fleft->op1;
+ fins->op2 = (IRRef1)lj_ir_knum(J, y);
+ return RETRYFOLD; /* (x o k1) o k2 ==> x o (k1 o k2) */
+ } else if (irk->o == IR_KINT) {
+ int32_t a = irk->i;
+ int32_t y = kfold_intop(a, fright->i, fins->o);
+ if (a == y) /* (x o k1) o k2 ==> x o k1, if (k1 o k2) == k1. */
+ return LEFTFOLD;
+ PHIBARRIER(fleft);
+ fins->op1 = fleft->op1;
+ fins->op2 = (IRRef1)lj_ir_kint(J, y);
+ return RETRYFOLD; /* (x o k1) o k2 ==> x o (k1 o k2) */
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(MIN MAX any)
+LJFOLD(MAX MIN any)
+LJFOLDF(reassoc_minmax_left)
+{
+ if (fins->op2 == fleft->op1 || fins->op2 == fleft->op2)
+ return RIGHTFOLD; /* (b o1 a) o2 b ==> b; (a o1 b) o2 b ==> b */
+ return NEXTFOLD;
+}
+
+LJFOLD(MIN any MAX)
+LJFOLD(MAX any MIN)
+LJFOLDF(reassoc_minmax_right)
+{
+ if (fins->op1 == fright->op1 || fins->op1 == fright->op2)
+ return LEFTFOLD; /* a o2 (a o1 b) ==> a; a o2 (b o1 a) ==> a */
+ return NEXTFOLD;
+}
+
+/* -- Array bounds check elimination -------------------------------------- */
+
+/* Eliminate ABC across PHIs to handle t[i-1] forwarding case.
+** ABC(asize, (i+k)+(-k)) ==> ABC(asize, i), but only if it already exists.
+** Could be generalized to (i+k1)+k2 ==> i+(k1+k2), but needs better disambig.
+*/
+LJFOLD(ABC any ADD)
+LJFOLDF(abc_fwd)
+{
+ if (LJ_LIKELY(J->flags & JIT_F_OPT_ABC)) {
+ if (irref_isk(fright->op2)) {
+ IRIns *add2 = IR(fright->op1);
+ if (add2->o == IR_ADD && irref_isk(add2->op2) &&
+ IR(fright->op2)->i == -IR(add2->op2)->i) {
+ IRRef ref = J->chain[IR_ABC];
+ IRRef lim = add2->op1;
+ if (fins->op1 > lim) lim = fins->op1;
+ while (ref > lim) {
+ IRIns *ir = IR(ref);
+ if (ir->op1 == fins->op1 && ir->op2 == add2->op1)
+ return DROPFOLD;
+ ref = ir->prev;
+ }
+ }
+ }
+ }
+ return NEXTFOLD;
+}
+
+/* Eliminate ABC for constants.
+** ABC(asize, k1), ABC(asize k2) ==> ABC(asize, max(k1, k2))
+** Drop second ABC if k2 is lower. Otherwise patch first ABC with k2.
+*/
+LJFOLD(ABC any KINT)
+LJFOLDF(abc_k)
+{
+ if (LJ_LIKELY(J->flags & JIT_F_OPT_ABC)) {
+ IRRef ref = J->chain[IR_ABC];
+ IRRef asize = fins->op1;
+ while (ref > asize) {
+ IRIns *ir = IR(ref);
+ if (ir->op1 == asize && irref_isk(ir->op2)) {
+ int32_t k = IR(ir->op2)->i;
+ if (fright->i > k)
+ ir->op2 = fins->op2;
+ return DROPFOLD;
+ }
+ ref = ir->prev;
+ }
+ return EMITFOLD; /* Already performed CSE. */
+ }
+ return NEXTFOLD;
+}
+
+/* Eliminate invariant ABC inside loop. */
+LJFOLD(ABC any any)
+LJFOLDF(abc_invar)
+{
+ /* Invariant ABC marked as PTR. Drop if op1 is invariant, too. */
+ if (!irt_isint(fins->t) && fins->op1 < J->chain[IR_LOOP] &&
+ !irt_isphi(IR(fins->op1)->t))
+ return DROPFOLD;
+ return NEXTFOLD;
+}
+
+/* -- Commutativity ------------------------------------------------------- */
+
+/* The refs of commutative ops are canonicalized. Lower refs go to the right.
+** Rationale behind this:
+** - It (also) moves constants to the right.
+** - It reduces the number of FOLD rules (e.g. (BOR any KINT) suffices).
+** - It helps CSE to find more matches.
+** - The assembler generates better code with constants at the right.
+*/
+
+LJFOLD(ADD any any)
+LJFOLD(MUL any any)
+LJFOLD(ADDOV any any)
+LJFOLD(MULOV any any)
+LJFOLDF(comm_swap)
+{
+ if (fins->op1 < fins->op2) { /* Move lower ref to the right. */
+ IRRef1 tmp = fins->op1;
+ fins->op1 = fins->op2;
+ fins->op2 = tmp;
+ return RETRYFOLD;
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(EQ any any)
+LJFOLD(NE any any)
+LJFOLDF(comm_equal)
+{
+ /* For non-numbers only: x == x ==> drop; x ~= x ==> fail */
+ if (fins->op1 == fins->op2 && !irt_isnum(fins->t))
+ return CONDFOLD(fins->o == IR_EQ);
+ return fold_comm_swap(J);
+}
+
+LJFOLD(LT any any)
+LJFOLD(GE any any)
+LJFOLD(LE any any)
+LJFOLD(GT any any)
+LJFOLD(ULT any any)
+LJFOLD(UGE any any)
+LJFOLD(ULE any any)
+LJFOLD(UGT any any)
+LJFOLDF(comm_comp)
+{
+ /* For non-numbers only: x <=> x ==> drop; x <> x ==> fail */
+ if (fins->op1 == fins->op2 && !irt_isnum(fins->t))
+ return CONDFOLD((fins->o ^ (fins->o >> 1)) & 1);
+ if (fins->op1 < fins->op2) { /* Move lower ref to the right. */
+ IRRef1 tmp = fins->op1;
+ fins->op1 = fins->op2;
+ fins->op2 = tmp;
+ fins->o ^= 3; /* GT <-> LT, GE <-> LE, does not affect U */
+ return RETRYFOLD;
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(BAND any any)
+LJFOLD(BOR any any)
+LJFOLD(MIN any any)
+LJFOLD(MAX any any)
+LJFOLDF(comm_dup)
+{
+ if (fins->op1 == fins->op2) /* x o x ==> x */
+ return LEFTFOLD;
+ return fold_comm_swap(J);
+}
+
+LJFOLD(BXOR any any)
+LJFOLDF(comm_bxor)
+{
+ if (fins->op1 == fins->op2) /* i xor i ==> 0 */
+ return irt_is64(fins->t) ? INT64FOLD(0) : INTFOLD(0);
+ return fold_comm_swap(J);
+}
+
+/* -- Simplification of compound expressions ------------------------------ */
+
+static TRef kfold_xload(jit_State *J, IRIns *ir, const void *p)
+{
+ int32_t k;
+ switch (irt_type(ir->t)) {
+ case IRT_NUM: return lj_ir_knum_u64(J, *(uint64_t *)p);
+ case IRT_I8: k = (int32_t)*(int8_t *)p; break;
+ case IRT_U8: k = (int32_t)*(uint8_t *)p; break;
+ case IRT_I16: k = (int32_t)(int16_t)lj_getu16(p); break;
+ case IRT_U16: k = (int32_t)(uint16_t)lj_getu16(p); break;
+ case IRT_INT: case IRT_U32: k = (int32_t)lj_getu32(p); break;
+ case IRT_I64: case IRT_U64: return lj_ir_kint64(J, *(uint64_t *)p);
+ default: return 0;
+ }
+ return lj_ir_kint(J, k);
+}
+
+/* Turn: string.sub(str, a, b) == kstr
+** into: string.byte(str, a) == string.byte(kstr, 1) etc.
+** Note: this creates unaligned XLOADs on x86/x64.
+*/
+LJFOLD(EQ SNEW KGC)
+LJFOLD(NE SNEW KGC)
+LJFOLDF(merge_eqne_snew_kgc)
+{
+ GCstr *kstr = ir_kstr(fright);
+ int32_t len = (int32_t)kstr->len;
+ lua_assert(irt_isstr(fins->t));
+
+#if LJ_TARGET_UNALIGNED
+#define FOLD_SNEW_MAX_LEN 4 /* Handle string lengths 0, 1, 2, 3, 4. */
+#define FOLD_SNEW_TYPE8 IRT_I8 /* Creates shorter immediates. */
+#else
+#define FOLD_SNEW_MAX_LEN 1 /* Handle string lengths 0 or 1. */
+#define FOLD_SNEW_TYPE8 IRT_U8 /* Prefer unsigned loads. */
+#endif
+
+ PHIBARRIER(fleft);
+ if (len <= FOLD_SNEW_MAX_LEN) {
+ IROp op = (IROp)fins->o;
+ IRRef strref = fleft->op1;
+ if (IR(strref)->o != IR_STRREF)
+ return NEXTFOLD;
+ if (op == IR_EQ) {
+ emitir(IRTGI(IR_EQ), fleft->op2, lj_ir_kint(J, len));
+ /* Caveat: fins/fleft/fright is no longer valid after emitir. */
+ } else {
+ /* NE is not expanded since this would need an OR of two conds. */
+ if (!irref_isk(fleft->op2)) /* Only handle the constant length case. */
+ return NEXTFOLD;
+ if (IR(fleft->op2)->i != len)
+ return DROPFOLD;
+ }
+ if (len > 0) {
+ /* A 4 byte load for length 3 is ok -- all strings have an extra NUL. */
+ uint16_t ot = (uint16_t)(len == 1 ? IRT(IR_XLOAD, FOLD_SNEW_TYPE8) :
+ len == 2 ? IRT(IR_XLOAD, IRT_U16) :
+ IRTI(IR_XLOAD));
+ TRef tmp = emitir(ot, strref,
+ IRXLOAD_READONLY | (len > 1 ? IRXLOAD_UNALIGNED : 0));
+ TRef val = kfold_xload(J, IR(tref_ref(tmp)), strdata(kstr));
+ if (len == 3)
+ tmp = emitir(IRTI(IR_BAND), tmp,
+ lj_ir_kint(J, LJ_ENDIAN_SELECT(0x00ffffff, 0xffffff00)));
+ fins->op1 = (IRRef1)tmp;
+ fins->op2 = (IRRef1)val;
+ fins->ot = (IROpT)IRTGI(op);
+ return RETRYFOLD;
+ } else {
+ return DROPFOLD;
+ }
+ }
+ return NEXTFOLD;
+}
+
+/* -- Loads --------------------------------------------------------------- */
+
+/* Loads cannot be folded or passed on to CSE in general.
+** Alias analysis is needed to check for forwarding opportunities.
+**
+** Caveat: *all* loads must be listed here or they end up at CSE!
+*/
+
+LJFOLD(ALOAD any)
+LJFOLDX(lj_opt_fwd_aload)
+
+/* From HREF fwd (see below). Must eliminate, not supported by fwd/backend. */
+LJFOLD(HLOAD KKPTR)
+LJFOLDF(kfold_hload_kkptr)
+{
+ UNUSED(J);
+ lua_assert(ir_kptr(fleft) == niltvg(J2G(J)));
+ return TREF_NIL;
+}
+
+LJFOLD(HLOAD any)
+LJFOLDX(lj_opt_fwd_hload)
+
+LJFOLD(ULOAD any)
+LJFOLDX(lj_opt_fwd_uload)
+
+LJFOLD(CALLL any IRCALL_lj_tab_len)
+LJFOLDX(lj_opt_fwd_tab_len)
+
+/* Upvalue refs are really loads, but there are no corresponding stores.
+** So CSE is ok for them, except for UREFO across a GC step (see below).
+** If the referenced function is const, its upvalue addresses are const, too.
+** This can be used to improve CSE by looking for the same address,
+** even if the upvalues originate from a different function.
+*/
+LJFOLD(UREFO KGC any)
+LJFOLD(UREFC KGC any)
+LJFOLDF(cse_uref)
+{
+ if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) {
+ IRRef ref = J->chain[fins->o];
+ GCfunc *fn = ir_kfunc(fleft);
+ GCupval *uv = gco2uv(gcref(fn->l.uvptr[(fins->op2 >> 8)]));
+ while (ref > 0) {
+ IRIns *ir = IR(ref);
+ if (irref_isk(ir->op1)) {
+ GCfunc *fn2 = ir_kfunc(IR(ir->op1));
+ if (gco2uv(gcref(fn2->l.uvptr[(ir->op2 >> 8)])) == uv) {
+ if (fins->o == IR_UREFO && gcstep_barrier(J, ref))
+ break;
+ return ref;
+ }
+ }
+ ref = ir->prev;
+ }
+ }
+ return EMITFOLD;
+}
+
+LJFOLD(HREFK any any)
+LJFOLDX(lj_opt_fwd_hrefk)
+
+LJFOLD(HREF TNEW any)
+LJFOLDF(fwd_href_tnew)
+{
+ if (lj_opt_fwd_href_nokey(J))
+ return lj_ir_kkptr(J, niltvg(J2G(J)));
+ return NEXTFOLD;
+}
+
+LJFOLD(HREF TDUP KPRI)
+LJFOLD(HREF TDUP KGC)
+LJFOLD(HREF TDUP KNUM)
+LJFOLDF(fwd_href_tdup)
+{
+ TValue keyv;
+ lj_ir_kvalue(J->L, &keyv, fright);
+ if (lj_tab_get(J->L, ir_ktab(IR(fleft->op1)), &keyv) == niltvg(J2G(J)) &&
+ lj_opt_fwd_href_nokey(J))
+ return lj_ir_kkptr(J, niltvg(J2G(J)));
+ return NEXTFOLD;
+}
+
+/* We can safely FOLD/CSE array/hash refs and field loads, since there
+** are no corresponding stores. But we need to check for any NEWREF with
+** an aliased table, as it may invalidate all of the pointers and fields.
+** Only HREF needs the NEWREF check -- AREF and HREFK already depend on
+** FLOADs. And NEWREF itself is treated like a store (see below).
+*/
+LJFOLD(FLOAD TNEW IRFL_TAB_ASIZE)
+LJFOLDF(fload_tab_tnew_asize)
+{
+ if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1))
+ return INTFOLD(fleft->op1);
+ return NEXTFOLD;
+}
+
+LJFOLD(FLOAD TNEW IRFL_TAB_HMASK)
+LJFOLDF(fload_tab_tnew_hmask)
+{
+ if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1))
+ return INTFOLD((1 << fleft->op2)-1);
+ return NEXTFOLD;
+}
+
+LJFOLD(FLOAD TDUP IRFL_TAB_ASIZE)
+LJFOLDF(fload_tab_tdup_asize)
+{
+ if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1))
+ return INTFOLD((int32_t)ir_ktab(IR(fleft->op1))->asize);
+ return NEXTFOLD;
+}
+
+LJFOLD(FLOAD TDUP IRFL_TAB_HMASK)
+LJFOLDF(fload_tab_tdup_hmask)
+{
+ if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD) && lj_opt_fwd_tptr(J, fins->op1))
+ return INTFOLD((int32_t)ir_ktab(IR(fleft->op1))->hmask);
+ return NEXTFOLD;
+}
+
+LJFOLD(HREF any any)
+LJFOLD(FLOAD any IRFL_TAB_ARRAY)
+LJFOLD(FLOAD any IRFL_TAB_NODE)
+LJFOLD(FLOAD any IRFL_TAB_ASIZE)
+LJFOLD(FLOAD any IRFL_TAB_HMASK)
+LJFOLDF(fload_tab_ah)
+{
+ TRef tr = lj_opt_cse(J);
+ return lj_opt_fwd_tptr(J, tref_ref(tr)) ? tr : EMITFOLD;
+}
+
+/* Strings are immutable, so we can safely FOLD/CSE the related FLOAD. */
+LJFOLD(FLOAD KGC IRFL_STR_LEN)
+LJFOLDF(fload_str_len_kgc)
+{
+ if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD))
+ return INTFOLD((int32_t)ir_kstr(fleft)->len);
+ return NEXTFOLD;
+}
+
+LJFOLD(FLOAD SNEW IRFL_STR_LEN)
+LJFOLDF(fload_str_len_snew)
+{
+ if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) {
+ PHIBARRIER(fleft);
+ return fleft->op2;
+ }
+ return NEXTFOLD;
+}
+
+/* The C type ID of cdata objects is immutable. */
+LJFOLD(FLOAD KGC IRFL_CDATA_CTYPEID)
+LJFOLDF(fload_cdata_typeid_kgc)
+{
+ if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD))
+ return INTFOLD((int32_t)ir_kcdata(fleft)->ctypeid);
+ return NEXTFOLD;
+}
+
+/* Get the contents of immutable cdata objects. */
+LJFOLD(FLOAD KGC IRFL_CDATA_PTR)
+LJFOLD(FLOAD KGC IRFL_CDATA_INT)
+LJFOLD(FLOAD KGC IRFL_CDATA_INT64)
+LJFOLDF(fload_cdata_int64_kgc)
+{
+ if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD)) {
+ void *p = cdataptr(ir_kcdata(fleft));
+ if (irt_is64(fins->t))
+ return INT64FOLD(*(uint64_t *)p);
+ else
+ return INTFOLD(*(int32_t *)p);
+ }
+ return NEXTFOLD;
+}
+
+LJFOLD(FLOAD CNEW IRFL_CDATA_CTYPEID)
+LJFOLD(FLOAD CNEWI IRFL_CDATA_CTYPEID)
+LJFOLDF(fload_cdata_typeid_cnew)
+{
+ if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD))
+ return fleft->op1; /* No PHI barrier needed. CNEW/CNEWI op1 is const. */
+ return NEXTFOLD;
+}
+
+/* Pointer, int and int64 cdata objects are immutable. */
+LJFOLD(FLOAD CNEWI IRFL_CDATA_PTR)
+LJFOLD(FLOAD CNEWI IRFL_CDATA_INT)
+LJFOLD(FLOAD CNEWI IRFL_CDATA_INT64)
+LJFOLDF(fload_cdata_ptr_int64_cnew)
+{
+ if (LJ_LIKELY(J->flags & JIT_F_OPT_FOLD))
+ return fleft->op2; /* Fold even across PHI to avoid allocations. */
+ return NEXTFOLD;
+}
+
+LJFOLD(FLOAD any IRFL_STR_LEN)
+LJFOLD(FLOAD any IRFL_CDATA_CTYPEID)
+LJFOLD(FLOAD any IRFL_CDATA_PTR)
+LJFOLD(FLOAD any IRFL_CDATA_INT)
+LJFOLD(FLOAD any IRFL_CDATA_INT64)
+LJFOLD(VLOAD any any) /* Vararg loads have no corresponding stores. */
+LJFOLDX(lj_opt_cse)
+
+/* All other field loads need alias analysis. */
+LJFOLD(FLOAD any any)
+LJFOLDX(lj_opt_fwd_fload)
+
+/* This is for LOOP only. Recording handles SLOADs internally. */
+LJFOLD(SLOAD any any)
+LJFOLDF(fwd_sload)
+{
+ if ((fins->op2 & IRSLOAD_FRAME)) {
+ TRef tr = lj_opt_cse(J);
+ return tref_ref(tr) < J->chain[IR_RETF] ? EMITFOLD : tr;
+ } else {
+ lua_assert(J->slot[fins->op1] != 0);
+ return J->slot[fins->op1];
+ }
+}
+
+/* Only fold for KKPTR. The pointer _and_ the contents must be const. */
+LJFOLD(XLOAD KKPTR any)
+LJFOLDF(xload_kptr)
+{
+ TRef tr = kfold_xload(J, fins, ir_kptr(fleft));
+ return tr ? tr : NEXTFOLD;
+}
+
+LJFOLD(XLOAD any any)
+LJFOLDX(lj_opt_fwd_xload)
+
+/* -- Write barriers ------------------------------------------------------ */
+
+/* Write barriers are amenable to CSE, but not across any incremental
+** GC steps.
+**
+** The same logic applies to open upvalue references, because a stack
+** may be resized during a GC step (not the current stack, but maybe that
+** of a coroutine).
+*/
+LJFOLD(TBAR any)
+LJFOLD(OBAR any any)
+LJFOLD(UREFO any any)
+LJFOLDF(barrier_tab)
+{
+ TRef tr = lj_opt_cse(J);
+ if (gcstep_barrier(J, tref_ref(tr))) /* CSE across GC step? */
+ return EMITFOLD; /* Raw emit. Assumes fins is left intact by CSE. */
+ return tr;
+}
+
+LJFOLD(TBAR TNEW)
+LJFOLD(TBAR TDUP)
+LJFOLDF(barrier_tnew_tdup)
+{
+ /* New tables are always white and never need a barrier. */
+ if (fins->op1 < J->chain[IR_LOOP]) /* Except across a GC step. */
+ return NEXTFOLD;
+ return DROPFOLD;
+}
+
+/* -- Stores and allocations ---------------------------------------------- */
+
+/* Stores and allocations cannot be folded or passed on to CSE in general.
+** But some stores can be eliminated with dead-store elimination (DSE).
+**
+** Caveat: *all* stores and allocs must be listed here or they end up at CSE!
+*/
+
+LJFOLD(ASTORE any any)
+LJFOLD(HSTORE any any)
+LJFOLDX(lj_opt_dse_ahstore)
+
+LJFOLD(USTORE any any)
+LJFOLDX(lj_opt_dse_ustore)
+
+LJFOLD(FSTORE any any)
+LJFOLDX(lj_opt_dse_fstore)
+
+LJFOLD(XSTORE any any)
+LJFOLDX(lj_opt_dse_xstore)
+
+LJFOLD(NEWREF any any) /* Treated like a store. */
+LJFOLD(CALLS any any)
+LJFOLD(CALLL any any) /* Safeguard fallback. */
+LJFOLD(CALLXS any any)
+LJFOLD(XBAR)
+LJFOLD(RETF any any) /* Modifies BASE. */
+LJFOLD(TNEW any any)
+LJFOLD(TDUP any)
+LJFOLD(CNEW any any)
+LJFOLD(XSNEW any any)
+LJFOLDX(lj_ir_emit)
+
+/* ------------------------------------------------------------------------ */
+
+/* Every entry in the generated hash table is a 32 bit pattern:
+**
+** xxxxxxxx iiiiiii lllllll rrrrrrrrrr
+**
+** xxxxxxxx = 8 bit index into fold function table
+** iiiiiii = 7 bit folded instruction opcode
+** lllllll = 7 bit left instruction opcode
+** rrrrrrrrrr = 8 bit right instruction opcode or 10 bits from literal field
+*/
+
+#include "lj_folddef.h"
+
+/* ------------------------------------------------------------------------ */
+
+/* Fold IR instruction. */
+TRef LJ_FASTCALL lj_opt_fold(jit_State *J)
+{
+ uint32_t key, any;
+ IRRef ref;
+
+ if (LJ_UNLIKELY((J->flags & JIT_F_OPT_MASK) != JIT_F_OPT_DEFAULT)) {
+ lua_assert(((JIT_F_OPT_FOLD|JIT_F_OPT_FWD|JIT_F_OPT_CSE|JIT_F_OPT_DSE) |
+ JIT_F_OPT_DEFAULT) == JIT_F_OPT_DEFAULT);
+ /* Folding disabled? Chain to CSE, but not for loads/stores/allocs. */
+ if (!(J->flags & JIT_F_OPT_FOLD) && irm_kind(lj_ir_mode[fins->o]) == IRM_N)
+ return lj_opt_cse(J);
+
+ /* No FOLD, forwarding or CSE? Emit raw IR for loads, except for SLOAD. */
+ if ((J->flags & (JIT_F_OPT_FOLD|JIT_F_OPT_FWD|JIT_F_OPT_CSE)) !=
+ (JIT_F_OPT_FOLD|JIT_F_OPT_FWD|JIT_F_OPT_CSE) &&
+ irm_kind(lj_ir_mode[fins->o]) == IRM_L && fins->o != IR_SLOAD)
+ return lj_ir_emit(J);
+
+ /* No FOLD or DSE? Emit raw IR for stores. */
+ if ((J->flags & (JIT_F_OPT_FOLD|JIT_F_OPT_DSE)) !=
+ (JIT_F_OPT_FOLD|JIT_F_OPT_DSE) &&
+ irm_kind(lj_ir_mode[fins->o]) == IRM_S)
+ return lj_ir_emit(J);
+ }
+
+ /* Fold engine start/retry point. */
+retry:
+ /* Construct key from opcode and operand opcodes (unless literal/none). */
+ key = ((uint32_t)fins->o << 17);
+ if (fins->op1 >= J->cur.nk) {
+ key += (uint32_t)IR(fins->op1)->o << 10;
+ *fleft = *IR(fins->op1);
+ }
+ if (fins->op2 >= J->cur.nk) {
+ key += (uint32_t)IR(fins->op2)->o;
+ *fright = *IR(fins->op2);
+ } else {
+ key += (fins->op2 & 0x3ffu); /* Literal mask. Must include IRCONV_*MASK. */
+ }
+
+ /* Check for a match in order from most specific to least specific. */
+ any = 0;
+ for (;;) {
+ uint32_t k = key | (any & 0x1ffff);
+ uint32_t h = fold_hashkey(k);
+ uint32_t fh = fold_hash[h]; /* Lookup key in semi-perfect hash table. */
+ if ((fh & 0xffffff) == k || (fh = fold_hash[h+1], (fh & 0xffffff) == k)) {
+ ref = (IRRef)tref_ref(fold_func[fh >> 24](J));
+ if (ref != NEXTFOLD)
+ break;
+ }
+ if (any == 0xfffff) /* Exhausted folding. Pass on to CSE. */
+ return lj_opt_cse(J);
+ any = (any | (any >> 10)) ^ 0xffc00;
+ }
+
+ /* Return value processing, ordered by frequency. */
+ if (LJ_LIKELY(ref >= MAX_FOLD))
+ return TREF(ref, irt_t(IR(ref)->t));
+ if (ref == RETRYFOLD)
+ goto retry;
+ if (ref == KINTFOLD)
+ return lj_ir_kint(J, fins->i);
+ if (ref == FAILFOLD)
+ lj_trace_err(J, LJ_TRERR_GFAIL);
+ lua_assert(ref == DROPFOLD);
+ return REF_DROP;
+}
+
+/* -- Common-Subexpression Elimination ------------------------------------ */
+
+/* CSE an IR instruction. This is very fast due to the skip-list chains. */
+TRef LJ_FASTCALL lj_opt_cse(jit_State *J)
+{
+ /* Avoid narrow to wide store-to-load forwarding stall */
+ IRRef2 op12 = (IRRef2)fins->op1 + ((IRRef2)fins->op2 << 16);
+ IROp op = fins->o;
+ if (LJ_LIKELY(J->flags & JIT_F_OPT_CSE)) {
+ /* Limited search for same operands in per-opcode chain. */
+ IRRef ref = J->chain[op];
+ IRRef lim = fins->op1;
+ if (fins->op2 > lim) lim = fins->op2; /* Relies on lit < REF_BIAS. */
+ while (ref > lim) {
+ if (IR(ref)->op12 == op12)
+ return TREF(ref, irt_t(IR(ref)->t)); /* Common subexpression found. */
+ ref = IR(ref)->prev;
+ }
+ }
+ /* Otherwise emit IR (inlined for speed). */
+ {
+ IRRef ref = lj_ir_nextins(J);
+ IRIns *ir = IR(ref);
+ ir->prev = J->chain[op];
+ ir->op12 = op12;
+ J->chain[op] = (IRRef1)ref;
+ ir->o = fins->o;
+ J->guardemit.irt |= fins->t.irt;
+ return TREF(ref, irt_t((ir->t = fins->t)));
+ }
+}
+
+/* CSE with explicit search limit. */
+TRef LJ_FASTCALL lj_opt_cselim(jit_State *J, IRRef lim)
+{
+ IRRef ref = J->chain[fins->o];
+ IRRef2 op12 = (IRRef2)fins->op1 + ((IRRef2)fins->op2 << 16);
+ while (ref > lim) {
+ if (IR(ref)->op12 == op12)
+ return ref;
+ ref = IR(ref)->prev;
+ }
+ return lj_ir_emit(J);
+}
+
+/* ------------------------------------------------------------------------ */
+
+#undef IR
+#undef fins
+#undef fleft
+#undef fright
+#undef knumleft
+#undef knumright
+#undef emitir
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_loop.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_loop.c
new file mode 100644
index 0000000..36317b3
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_loop.c
@@ -0,0 +1,436 @@
+/*
+** LOOP: Loop Optimizations.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_opt_loop_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT
+
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_ir.h"
+#include "lj_jit.h"
+#include "lj_iropt.h"
+#include "lj_trace.h"
+#include "lj_snap.h"
+#include "lj_vm.h"
+
+/* Loop optimization:
+**
+** Traditional Loop-Invariant Code Motion (LICM) splits the instructions
+** of a loop into invariant and variant instructions. The invariant
+** instructions are hoisted out of the loop and only the variant
+** instructions remain inside the loop body.
+**
+** Unfortunately LICM is mostly useless for compiling dynamic languages.
+** The IR has many guards and most of the subsequent instructions are
+** control-dependent on them. The first non-hoistable guard would
+** effectively prevent hoisting of all subsequent instructions.
+**
+** That's why we use a special form of unrolling using copy-substitution,
+** combined with redundancy elimination:
+**
+** The recorded instruction stream is re-emitted to the compiler pipeline
+** with substituted operands. The substitution table is filled with the
+** refs returned by re-emitting each instruction. This can be done
+** on-the-fly, because the IR is in strict SSA form, where every ref is
+** defined before its use.
+**
+** This aproach generates two code sections, separated by the LOOP
+** instruction:
+**
+** 1. The recorded instructions form a kind of pre-roll for the loop. It
+** contains a mix of invariant and variant instructions and performs
+** exactly one loop iteration (but not necessarily the 1st iteration).
+**
+** 2. The loop body contains only the variant instructions and performs
+** all remaining loop iterations.
+**
+** On first sight that looks like a waste of space, because the variant
+** instructions are present twice. But the key insight is that the
+** pre-roll honors the control-dependencies for *both* the pre-roll itself
+** *and* the loop body!
+**
+** It also means one doesn't have to explicitly model control-dependencies
+** (which, BTW, wouldn't help LICM much). And it's much easier to
+** integrate sparse snapshotting with this approach.
+**
+** One of the nicest aspects of this approach is that all of the
+** optimizations of the compiler pipeline (FOLD, CSE, FWD, etc.) can be
+** reused with only minor restrictions (e.g. one should not fold
+** instructions across loop-carried dependencies).
+**
+** But in general all optimizations can be applied which only need to look
+** backwards into the generated instruction stream. At any point in time
+** during the copy-substitution process this contains both a static loop
+** iteration (the pre-roll) and a dynamic one (from the to-be-copied
+** instruction up to the end of the partial loop body).
+**
+** Since control-dependencies are implicitly kept, CSE also applies to all
+** kinds of guards. The major advantage is that all invariant guards can
+** be hoisted, too.
+**
+** Load/store forwarding works across loop iterations, too. This is
+** important if loop-carried dependencies are kept in upvalues or tables.
+** E.g. 'self.idx = self.idx + 1' deep down in some OO-style method may
+** become a forwarded loop-recurrence after inlining.
+**
+** Since the IR is in SSA form, loop-carried dependencies have to be
+** modeled with PHI instructions. The potential candidates for PHIs are
+** collected on-the-fly during copy-substitution. After eliminating the
+** redundant ones, PHI instructions are emitted *below* the loop body.
+**
+** Note that this departure from traditional SSA form doesn't change the
+** semantics of the PHI instructions themselves. But it greatly simplifies
+** on-the-fly generation of the IR and the machine code.
+*/
+
+/* Some local macros to save typing. Undef'd at the end. */
+#define IR(ref) (&J->cur.ir[(ref)])
+
+/* Pass IR on to next optimization in chain (FOLD). */
+#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))
+
+/* Emit raw IR without passing through optimizations. */
+#define emitir_raw(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J))
+
+/* -- PHI elimination ----------------------------------------------------- */
+
+/* Emit or eliminate collected PHIs. */
+static void loop_emit_phi(jit_State *J, IRRef1 *subst, IRRef1 *phi, IRRef nphi,
+ SnapNo onsnap)
+{
+ int passx = 0;
+ IRRef i, j, nslots;
+ IRRef invar = J->chain[IR_LOOP];
+ /* Pass #1: mark redundant and potentially redundant PHIs. */
+ for (i = 0, j = 0; i < nphi; i++) {
+ IRRef lref = phi[i];
+ IRRef rref = subst[lref];
+ if (lref == rref || rref == REF_DROP) { /* Invariants are redundant. */
+ irt_clearphi(IR(lref)->t);
+ } else {
+ phi[j++] = (IRRef1)lref;
+ if (!(IR(rref)->op1 == lref || IR(rref)->op2 == lref)) {
+ /* Quick check for simple recurrences failed, need pass2. */
+ irt_setmark(IR(lref)->t);
+ passx = 1;
+ }
+ }
+ }
+ nphi = j;
+ /* Pass #2: traverse variant part and clear marks of non-redundant PHIs. */
+ if (passx) {
+ SnapNo s;
+ for (i = J->cur.nins-1; i > invar; i--) {
+ IRIns *ir = IR(i);
+ if (!irref_isk(ir->op2)) irt_clearmark(IR(ir->op2)->t);
+ if (!irref_isk(ir->op1)) {
+ irt_clearmark(IR(ir->op1)->t);
+ if (ir->op1 < invar &&
+ ir->o >= IR_CALLN && ir->o <= IR_CARG) { /* ORDER IR */
+ ir = IR(ir->op1);
+ while (ir->o == IR_CARG) {
+ if (!irref_isk(ir->op2)) irt_clearmark(IR(ir->op2)->t);
+ if (irref_isk(ir->op1)) break;
+ ir = IR(ir->op1);
+ irt_clearmark(ir->t);
+ }
+ }
+ }
+ }
+ for (s = J->cur.nsnap-1; s >= onsnap; s--) {
+ SnapShot *snap = &J->cur.snap[s];
+ SnapEntry *map = &J->cur.snapmap[snap->mapofs];
+ MSize n, nent = snap->nent;
+ for (n = 0; n < nent; n++) {
+ IRRef ref = snap_ref(map[n]);
+ if (!irref_isk(ref)) irt_clearmark(IR(ref)->t);
+ }
+ }
+ }
+ /* Pass #3: add PHIs for variant slots without a corresponding SLOAD. */
+ nslots = J->baseslot+J->maxslot;
+ for (i = 1; i < nslots; i++) {
+ IRRef ref = tref_ref(J->slot[i]);
+ while (!irref_isk(ref) && ref != subst[ref]) {
+ IRIns *ir = IR(ref);
+ irt_clearmark(ir->t); /* Unmark potential uses, too. */
+ if (irt_isphi(ir->t) || irt_ispri(ir->t))
+ break;
+ irt_setphi(ir->t);
+ if (nphi >= LJ_MAX_PHI)
+ lj_trace_err(J, LJ_TRERR_PHIOV);
+ phi[nphi++] = (IRRef1)ref;
+ ref = subst[ref];
+ if (ref > invar)
+ break;
+ }
+ }
+ /* Pass #4: propagate non-redundant PHIs. */
+ while (passx) {
+ passx = 0;
+ for (i = 0; i < nphi; i++) {
+ IRRef lref = phi[i];
+ IRIns *ir = IR(lref);
+ if (!irt_ismarked(ir->t)) { /* Propagate only from unmarked PHIs. */
+ IRIns *irr = IR(subst[lref]);
+ if (irt_ismarked(irr->t)) { /* Right ref points to other PHI? */
+ irt_clearmark(irr->t); /* Mark that PHI as non-redundant. */
+ passx = 1; /* Retry. */
+ }
+ }
+ }
+ }
+ /* Pass #5: emit PHI instructions or eliminate PHIs. */
+ for (i = 0; i < nphi; i++) {
+ IRRef lref = phi[i];
+ IRIns *ir = IR(lref);
+ if (!irt_ismarked(ir->t)) { /* Emit PHI if not marked. */
+ IRRef rref = subst[lref];
+ if (rref > invar)
+ irt_setphi(IR(rref)->t);
+ emitir_raw(IRT(IR_PHI, irt_type(ir->t)), lref, rref);
+ } else { /* Otherwise eliminate PHI. */
+ irt_clearmark(ir->t);
+ irt_clearphi(ir->t);
+ }
+ }
+}
+
+/* -- Loop unrolling using copy-substitution ------------------------------ */
+
+/* Copy-substitute snapshot. */
+static void loop_subst_snap(jit_State *J, SnapShot *osnap,
+ SnapEntry *loopmap, IRRef1 *subst)
+{
+ SnapEntry *nmap, *omap = &J->cur.snapmap[osnap->mapofs];
+ SnapEntry *nextmap = &J->cur.snapmap[snap_nextofs(&J->cur, osnap)];
+ MSize nmapofs;
+ MSize on, ln, nn, onent = osnap->nent;
+ BCReg nslots = osnap->nslots;
+ SnapShot *snap = &J->cur.snap[J->cur.nsnap];
+ if (irt_isguard(J->guardemit)) { /* Guard inbetween? */
+ nmapofs = J->cur.nsnapmap;
+ J->cur.nsnap++; /* Add new snapshot. */
+ } else { /* Otherwise overwrite previous snapshot. */
+ snap--;
+ nmapofs = snap->mapofs;
+ }
+ J->guardemit.irt = 0;
+ /* Setup new snapshot. */
+ snap->mapofs = (uint16_t)nmapofs;
+ snap->ref = (IRRef1)J->cur.nins;
+ snap->nslots = nslots;
+ snap->topslot = osnap->topslot;
+ snap->count = 0;
+ nmap = &J->cur.snapmap[nmapofs];
+ /* Substitute snapshot slots. */
+ on = ln = nn = 0;
+ while (on < onent) {
+ SnapEntry osn = omap[on], lsn = loopmap[ln];
+ if (snap_slot(lsn) < snap_slot(osn)) { /* Copy slot from loop map. */
+ nmap[nn++] = lsn;
+ ln++;
+ } else { /* Copy substituted slot from snapshot map. */
+ if (snap_slot(lsn) == snap_slot(osn)) ln++; /* Shadowed loop slot. */
+ if (!irref_isk(snap_ref(osn)))
+ osn = snap_setref(osn, subst[snap_ref(osn)]);
+ nmap[nn++] = osn;
+ on++;
+ }
+ }
+ while (snap_slot(loopmap[ln]) < nslots) /* Copy remaining loop slots. */
+ nmap[nn++] = loopmap[ln++];
+ snap->nent = (uint8_t)nn;
+ omap += onent;
+ nmap += nn;
+ while (omap < nextmap) /* Copy PC + frame links. */
+ *nmap++ = *omap++;
+ J->cur.nsnapmap = (uint16_t)(nmap - J->cur.snapmap);
+}
+
+/* Unroll loop. */
+static void loop_unroll(jit_State *J)
+{
+ IRRef1 phi[LJ_MAX_PHI];
+ uint32_t nphi = 0;
+ IRRef1 *subst;
+ SnapNo onsnap;
+ SnapShot *osnap, *loopsnap;
+ SnapEntry *loopmap, *psentinel;
+ IRRef ins, invar;
+
+ /* Use temp buffer for substitution table.
+ ** Only non-constant refs in [REF_BIAS,invar) are valid indexes.
+ ** Caveat: don't call into the VM or run the GC or the buffer may be gone.
+ */
+ invar = J->cur.nins;
+ subst = (IRRef1 *)lj_str_needbuf(J->L, &G(J->L)->tmpbuf,
+ (invar-REF_BIAS)*sizeof(IRRef1)) - REF_BIAS;
+ subst[REF_BASE] = REF_BASE;
+
+ /* LOOP separates the pre-roll from the loop body. */
+ emitir_raw(IRTG(IR_LOOP, IRT_NIL), 0, 0);
+
+ /* Grow snapshot buffer and map for copy-substituted snapshots.
+ ** Need up to twice the number of snapshots minus #0 and loop snapshot.
+ ** Need up to twice the number of entries plus fallback substitutions
+ ** from the loop snapshot entries for each new snapshot.
+ ** Caveat: both calls may reallocate J->cur.snap and J->cur.snapmap!
+ */
+ onsnap = J->cur.nsnap;
+ lj_snap_grow_buf(J, 2*onsnap-2);
+ lj_snap_grow_map(J, J->cur.nsnapmap*2+(onsnap-2)*J->cur.snap[onsnap-1].nent);
+
+ /* The loop snapshot is used for fallback substitutions. */
+ loopsnap = &J->cur.snap[onsnap-1];
+ loopmap = &J->cur.snapmap[loopsnap->mapofs];
+ /* The PC of snapshot #0 and the loop snapshot must match. */
+ psentinel = &loopmap[loopsnap->nent];
+ lua_assert(*psentinel == J->cur.snapmap[J->cur.snap[0].nent]);
+ *psentinel = SNAP(255, 0, 0); /* Replace PC with temporary sentinel. */
+
+ /* Start substitution with snapshot #1 (#0 is empty for root traces). */
+ osnap = &J->cur.snap[1];
+
+ /* Copy and substitute all recorded instructions and snapshots. */
+ for (ins = REF_FIRST; ins < invar; ins++) {
+ IRIns *ir;
+ IRRef op1, op2;
+
+ if (ins >= osnap->ref) /* Instruction belongs to next snapshot? */
+ loop_subst_snap(J, osnap++, loopmap, subst); /* Copy-substitute it. */
+
+ /* Substitute instruction operands. */
+ ir = IR(ins);
+ op1 = ir->op1;
+ if (!irref_isk(op1)) op1 = subst[op1];
+ op2 = ir->op2;
+ if (!irref_isk(op2)) op2 = subst[op2];
+ if (irm_kind(lj_ir_mode[ir->o]) == IRM_N &&
+ op1 == ir->op1 && op2 == ir->op2) { /* Regular invariant ins? */
+ subst[ins] = (IRRef1)ins; /* Shortcut. */
+ } else {
+ /* Re-emit substituted instruction to the FOLD/CSE/etc. pipeline. */
+ IRType1 t = ir->t; /* Get this first, since emitir may invalidate ir. */
+ IRRef ref = tref_ref(emitir(ir->ot & ~IRT_ISPHI, op1, op2));
+ subst[ins] = (IRRef1)ref;
+ if (ref != ins) {
+ IRIns *irr = IR(ref);
+ if (ref < invar) { /* Loop-carried dependency? */
+ /* Potential PHI? */
+ if (!irref_isk(ref) && !irt_isphi(irr->t) && !irt_ispri(irr->t)) {
+ irt_setphi(irr->t);
+ if (nphi >= LJ_MAX_PHI)
+ lj_trace_err(J, LJ_TRERR_PHIOV);
+ phi[nphi++] = (IRRef1)ref;
+ }
+ /* Check all loop-carried dependencies for type instability. */
+ if (!irt_sametype(t, irr->t)) {
+ if (irt_isinteger(t) && irt_isinteger(irr->t))
+ continue;
+ else if (irt_isnum(t) && irt_isinteger(irr->t)) /* Fix int->num. */
+ ref = tref_ref(emitir(IRTN(IR_CONV), ref, IRCONV_NUM_INT));
+ else if (irt_isnum(irr->t) && irt_isinteger(t)) /* Fix num->int. */
+ ref = tref_ref(emitir(IRTGI(IR_CONV), ref,
+ IRCONV_INT_NUM|IRCONV_CHECK));
+ else
+ lj_trace_err(J, LJ_TRERR_TYPEINS);
+ subst[ins] = (IRRef1)ref;
+ irr = IR(ref);
+ goto phiconv;
+ }
+ } else if (ref != REF_DROP && irr->o == IR_CONV &&
+ ref > invar && irr->op1 < invar) {
+ /* May need an extra PHI for a CONV. */
+ ref = irr->op1;
+ irr = IR(ref);
+ phiconv:
+ if (ref < invar && !irref_isk(ref) && !irt_isphi(irr->t)) {
+ irt_setphi(irr->t);
+ if (nphi >= LJ_MAX_PHI)
+ lj_trace_err(J, LJ_TRERR_PHIOV);
+ phi[nphi++] = (IRRef1)ref;
+ }
+ }
+ }
+ }
+ }
+ if (!irt_isguard(J->guardemit)) /* Drop redundant snapshot. */
+ J->cur.nsnapmap = (uint16_t)J->cur.snap[--J->cur.nsnap].mapofs;
+ lua_assert(J->cur.nsnapmap <= J->sizesnapmap);
+ *psentinel = J->cur.snapmap[J->cur.snap[0].nent]; /* Restore PC. */
+
+ loop_emit_phi(J, subst, phi, nphi, onsnap);
+}
+
+/* Undo any partial changes made by the loop optimization. */
+static void loop_undo(jit_State *J, IRRef ins, SnapNo nsnap, MSize nsnapmap)
+{
+ ptrdiff_t i;
+ SnapShot *snap = &J->cur.snap[nsnap-1];
+ SnapEntry *map = J->cur.snapmap;
+ map[snap->mapofs + snap->nent] = map[J->cur.snap[0].nent]; /* Restore PC. */
+ J->cur.nsnapmap = (uint16_t)nsnapmap;
+ J->cur.nsnap = nsnap;
+ J->guardemit.irt = 0;
+ lj_ir_rollback(J, ins);
+ for (i = 0; i < BPROP_SLOTS; i++) { /* Remove backprop. cache entries. */
+ BPropEntry *bp = &J->bpropcache[i];
+ if (bp->val >= ins)
+ bp->key = 0;
+ }
+ for (ins--; ins >= REF_FIRST; ins--) { /* Remove flags. */
+ IRIns *ir = IR(ins);
+ irt_clearphi(ir->t);
+ irt_clearmark(ir->t);
+ }
+}
+
+/* Protected callback for loop optimization. */
+static TValue *cploop_opt(lua_State *L, lua_CFunction dummy, void *ud)
+{
+ UNUSED(L); UNUSED(dummy);
+ loop_unroll((jit_State *)ud);
+ return NULL;
+}
+
+/* Loop optimization. */
+int lj_opt_loop(jit_State *J)
+{
+ IRRef nins = J->cur.nins;
+ SnapNo nsnap = J->cur.nsnap;
+ MSize nsnapmap = J->cur.nsnapmap;
+ int errcode = lj_vm_cpcall(J->L, NULL, J, cploop_opt);
+ if (LJ_UNLIKELY(errcode)) {
+ lua_State *L = J->L;
+ if (errcode == LUA_ERRRUN && tvisnumber(L->top-1)) { /* Trace error? */
+ int32_t e = numberVint(L->top-1);
+ switch ((TraceError)e) {
+ case LJ_TRERR_TYPEINS: /* Type instability. */
+ case LJ_TRERR_GFAIL: /* Guard would always fail. */
+ /* Unrolling via recording fixes many cases, e.g. a flipped boolean. */
+ if (--J->instunroll < 0) /* But do not unroll forever. */
+ break;
+ L->top--; /* Remove error object. */
+ loop_undo(J, nins, nsnap, nsnapmap);
+ return 1; /* Loop optimization failed, continue recording. */
+ default:
+ break;
+ }
+ }
+ lj_err_throw(L, errcode); /* Propagate all other errors. */
+ }
+ return 0; /* Loop optimization is ok. */
+}
+
+#undef IR
+#undef emitir
+#undef emitir_raw
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_mem.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_mem.c
new file mode 100644
index 0000000..9f71405
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_mem.c
@@ -0,0 +1,916 @@
+/*
+** Memory access optimizations.
+** AA: Alias Analysis using high-level semantic disambiguation.
+** FWD: Load Forwarding (L2L) + Store Forwarding (S2L).
+** DSE: Dead-Store Elimination.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_opt_mem_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT
+
+#include "lj_tab.h"
+#include "lj_ir.h"
+#include "lj_jit.h"
+#include "lj_iropt.h"
+
+/* Some local macros to save typing. Undef'd at the end. */
+#define IR(ref) (&J->cur.ir[(ref)])
+#define fins (&J->fold.ins)
+#define fleft (&J->fold.left)
+#define fright (&J->fold.right)
+
+/*
+** Caveat #1: return value is not always a TRef -- only use with tref_ref().
+** Caveat #2: FWD relies on active CSE for xREF operands -- see lj_opt_fold().
+*/
+
+/* Return values from alias analysis. */
+typedef enum {
+ ALIAS_NO, /* The two refs CANNOT alias (exact). */
+ ALIAS_MAY, /* The two refs MAY alias (inexact). */
+ ALIAS_MUST /* The two refs MUST alias (exact). */
+} AliasRet;
+
+/* -- ALOAD/HLOAD forwarding and ASTORE/HSTORE elimination ---------------- */
+
+/* Simplified escape analysis: check for intervening stores. */
+static AliasRet aa_escape(jit_State *J, IRIns *ir, IRIns *stop)
+{
+ IRRef ref = (IRRef)(ir - J->cur.ir); /* The ref that might be stored. */
+ for (ir++; ir < stop; ir++)
+ if (ir->op2 == ref &&
+ (ir->o == IR_ASTORE || ir->o == IR_HSTORE ||
+ ir->o == IR_USTORE || ir->o == IR_FSTORE))
+ return ALIAS_MAY; /* Reference was stored and might alias. */
+ return ALIAS_NO; /* Reference was not stored. */
+}
+
+/* Alias analysis for two different table references. */
+static AliasRet aa_table(jit_State *J, IRRef ta, IRRef tb)
+{
+ IRIns *taba = IR(ta), *tabb = IR(tb);
+ int newa, newb;
+ lua_assert(ta != tb);
+ lua_assert(irt_istab(taba->t) && irt_istab(tabb->t));
+ /* Disambiguate new allocations. */
+ newa = (taba->o == IR_TNEW || taba->o == IR_TDUP);
+ newb = (tabb->o == IR_TNEW || tabb->o == IR_TDUP);
+ if (newa && newb)
+ return ALIAS_NO; /* Two different allocations never alias. */
+ if (newb) { /* At least one allocation? */
+ IRIns *tmp = taba; taba = tabb; tabb = tmp;
+ } else if (!newa) {
+ return ALIAS_MAY; /* Anything else: we just don't know. */
+ }
+ return aa_escape(J, taba, tabb);
+}
+
+/* Alias analysis for array and hash access using key-based disambiguation. */
+static AliasRet aa_ahref(jit_State *J, IRIns *refa, IRIns *refb)
+{
+ IRRef ka = refa->op2;
+ IRRef kb = refb->op2;
+ IRIns *keya, *keyb;
+ IRRef ta, tb;
+ if (refa == refb)
+ return ALIAS_MUST; /* Shortcut for same refs. */
+ keya = IR(ka);
+ if (keya->o == IR_KSLOT) { ka = keya->op1; keya = IR(ka); }
+ keyb = IR(kb);
+ if (keyb->o == IR_KSLOT) { kb = keyb->op1; keyb = IR(kb); }
+ ta = (refa->o==IR_HREFK || refa->o==IR_AREF) ? IR(refa->op1)->op1 : refa->op1;
+ tb = (refb->o==IR_HREFK || refb->o==IR_AREF) ? IR(refb->op1)->op1 : refb->op1;
+ if (ka == kb) {
+ /* Same key. Check for same table with different ref (NEWREF vs. HREF). */
+ if (ta == tb)
+ return ALIAS_MUST; /* Same key, same table. */
+ else
+ return aa_table(J, ta, tb); /* Same key, possibly different table. */
+ }
+ if (irref_isk(ka) && irref_isk(kb))
+ return ALIAS_NO; /* Different constant keys. */
+ if (refa->o == IR_AREF) {
+ /* Disambiguate array references based on index arithmetic. */
+ int32_t ofsa = 0, ofsb = 0;
+ IRRef basea = ka, baseb = kb;
+ lua_assert(refb->o == IR_AREF);
+ /* Gather base and offset from t[base] or t[base+-ofs]. */
+ if (keya->o == IR_ADD && irref_isk(keya->op2)) {
+ basea = keya->op1;
+ ofsa = IR(keya->op2)->i;
+ if (basea == kb && ofsa != 0)
+ return ALIAS_NO; /* t[base+-ofs] vs. t[base]. */
+ }
+ if (keyb->o == IR_ADD && irref_isk(keyb->op2)) {
+ baseb = keyb->op1;
+ ofsb = IR(keyb->op2)->i;
+ if (ka == baseb && ofsb != 0)
+ return ALIAS_NO; /* t[base] vs. t[base+-ofs]. */
+ }
+ if (basea == baseb && ofsa != ofsb)
+ return ALIAS_NO; /* t[base+-o1] vs. t[base+-o2] and o1 != o2. */
+ } else {
+ /* Disambiguate hash references based on the type of their keys. */
+ lua_assert((refa->o==IR_HREF || refa->o==IR_HREFK || refa->o==IR_NEWREF) &&
+ (refb->o==IR_HREF || refb->o==IR_HREFK || refb->o==IR_NEWREF));
+ if (!irt_sametype(keya->t, keyb->t))
+ return ALIAS_NO; /* Different key types. */
+ }
+ if (ta == tb)
+ return ALIAS_MAY; /* Same table, cannot disambiguate keys. */
+ else
+ return aa_table(J, ta, tb); /* Try to disambiguate tables. */
+}
+
+/* Array and hash load forwarding. */
+static TRef fwd_ahload(jit_State *J, IRRef xref)
+{
+ IRIns *xr = IR(xref);
+ IRRef lim = xref; /* Search limit. */
+ IRRef ref;
+
+ /* Search for conflicting stores. */
+ ref = J->chain[fins->o+IRDELTA_L2S];
+ while (ref > xref) {
+ IRIns *store = IR(ref);
+ switch (aa_ahref(J, xr, IR(store->op1))) {
+ case ALIAS_NO: break; /* Continue searching. */
+ case ALIAS_MAY: lim = ref; goto cselim; /* Limit search for load. */
+ case ALIAS_MUST: return store->op2; /* Store forwarding. */
+ }
+ ref = store->prev;
+ }
+
+ /* No conflicting store (yet): const-fold loads from allocations. */
+ {
+ IRIns *ir = (xr->o == IR_HREFK || xr->o == IR_AREF) ? IR(xr->op1) : xr;
+ IRRef tab = ir->op1;
+ ir = IR(tab);
+ if (ir->o == IR_TNEW || (ir->o == IR_TDUP && irref_isk(xr->op2))) {
+ /* A NEWREF with a number key may end up pointing to the array part.
+ ** But it's referenced from HSTORE and not found in the ASTORE chain.
+ ** For now simply consider this a conflict without forwarding anything.
+ */
+ if (xr->o == IR_AREF) {
+ IRRef ref2 = J->chain[IR_NEWREF];
+ while (ref2 > tab) {
+ IRIns *newref = IR(ref2);
+ if (irt_isnum(IR(newref->op2)->t))
+ goto cselim;
+ ref2 = newref->prev;
+ }
+ }
+ /* NEWREF inhibits CSE for HREF, and dependent FLOADs from HREFK/AREF.
+ ** But the above search for conflicting stores was limited by xref.
+ ** So continue searching, limited by the TNEW/TDUP. Store forwarding
+ ** is ok, too. A conflict does NOT limit the search for a matching load.
+ */
+ while (ref > tab) {
+ IRIns *store = IR(ref);
+ switch (aa_ahref(J, xr, IR(store->op1))) {
+ case ALIAS_NO: break; /* Continue searching. */
+ case ALIAS_MAY: goto cselim; /* Conflicting store. */
+ case ALIAS_MUST: return store->op2; /* Store forwarding. */
+ }
+ ref = store->prev;
+ }
+ lua_assert(ir->o != IR_TNEW || irt_isnil(fins->t));
+ if (irt_ispri(fins->t)) {
+ return TREF_PRI(irt_type(fins->t));
+ } else if (irt_isnum(fins->t) || (LJ_DUALNUM && irt_isint(fins->t)) ||
+ irt_isstr(fins->t)) {
+ TValue keyv;
+ cTValue *tv;
+ IRIns *key = IR(xr->op2);
+ if (key->o == IR_KSLOT) key = IR(key->op1);
+ lj_ir_kvalue(J->L, &keyv, key);
+ tv = lj_tab_get(J->L, ir_ktab(IR(ir->op1)), &keyv);
+ lua_assert(itype2irt(tv) == irt_type(fins->t));
+ if (irt_isnum(fins->t))
+ return lj_ir_knum_u64(J, tv->u64);
+ else if (LJ_DUALNUM && irt_isint(fins->t))
+ return lj_ir_kint(J, intV(tv));
+ else
+ return lj_ir_kstr(J, strV(tv));
+ }
+ /* Othwerwise: don't intern as a constant. */
+ }
+ }
+
+cselim:
+ /* Try to find a matching load. Below the conflicting store, if any. */
+ ref = J->chain[fins->o];
+ while (ref > lim) {
+ IRIns *load = IR(ref);
+ if (load->op1 == xref)
+ return ref; /* Load forwarding. */
+ ref = load->prev;
+ }
+ return 0; /* Conflict or no match. */
+}
+
+/* Reassociate ALOAD across PHIs to handle t[i-1] forwarding case. */
+static TRef fwd_aload_reassoc(jit_State *J)
+{
+ IRIns *irx = IR(fins->op1);
+ IRIns *key = IR(irx->op2);
+ if (key->o == IR_ADD && irref_isk(key->op2)) {
+ IRIns *add2 = IR(key->op1);
+ if (add2->o == IR_ADD && irref_isk(add2->op2) &&
+ IR(key->op2)->i == -IR(add2->op2)->i) {
+ IRRef ref = J->chain[IR_AREF];
+ IRRef lim = add2->op1;
+ if (irx->op1 > lim) lim = irx->op1;
+ while (ref > lim) {
+ IRIns *ir = IR(ref);
+ if (ir->op1 == irx->op1 && ir->op2 == add2->op1)
+ return fwd_ahload(J, ref);
+ ref = ir->prev;
+ }
+ }
+ }
+ return 0;
+}
+
+/* ALOAD forwarding. */
+TRef LJ_FASTCALL lj_opt_fwd_aload(jit_State *J)
+{
+ IRRef ref;
+ if ((ref = fwd_ahload(J, fins->op1)) ||
+ (ref = fwd_aload_reassoc(J)))
+ return ref;
+ return EMITFOLD;
+}
+
+/* HLOAD forwarding. */
+TRef LJ_FASTCALL lj_opt_fwd_hload(jit_State *J)
+{
+ IRRef ref = fwd_ahload(J, fins->op1);
+ if (ref)
+ return ref;
+ return EMITFOLD;
+}
+
+/* HREFK forwarding. */
+TRef LJ_FASTCALL lj_opt_fwd_hrefk(jit_State *J)
+{
+ IRRef tab = fleft->op1;
+ IRRef ref = J->chain[IR_NEWREF];
+ while (ref > tab) {
+ IRIns *newref = IR(ref);
+ if (tab == newref->op1) {
+ if (fright->op1 == newref->op2)
+ return ref; /* Forward from NEWREF. */
+ else
+ goto docse;
+ } else if (aa_table(J, tab, newref->op1) != ALIAS_NO) {
+ goto docse;
+ }
+ ref = newref->prev;
+ }
+ /* No conflicting NEWREF: key location unchanged for HREFK of TDUP. */
+ if (IR(tab)->o == IR_TDUP)
+ fins->t.irt &= ~IRT_GUARD; /* Drop HREFK guard. */
+docse:
+ return CSEFOLD;
+}
+
+/* Check whether HREF of TNEW/TDUP can be folded to niltv. */
+int LJ_FASTCALL lj_opt_fwd_href_nokey(jit_State *J)
+{
+ IRRef lim = fins->op1; /* Search limit. */
+ IRRef ref;
+
+ /* The key for an ASTORE may end up in the hash part after a NEWREF. */
+ if (irt_isnum(fright->t) && J->chain[IR_NEWREF] > lim) {
+ ref = J->chain[IR_ASTORE];
+ while (ref > lim) {
+ if (ref < J->chain[IR_NEWREF])
+ return 0; /* Conflict. */
+ ref = IR(ref)->prev;
+ }
+ }
+
+ /* Search for conflicting stores. */
+ ref = J->chain[IR_HSTORE];
+ while (ref > lim) {
+ IRIns *store = IR(ref);
+ if (aa_ahref(J, fins, IR(store->op1)) != ALIAS_NO)
+ return 0; /* Conflict. */
+ ref = store->prev;
+ }
+
+ return 1; /* No conflict. Can fold to niltv. */
+}
+
+/* Check whether there's no aliasing NEWREF for the left operand. */
+int LJ_FASTCALL lj_opt_fwd_tptr(jit_State *J, IRRef lim)
+{
+ IRRef ta = fins->op1;
+ IRRef ref = J->chain[IR_NEWREF];
+ while (ref > lim) {
+ IRIns *newref = IR(ref);
+ if (ta == newref->op1 || aa_table(J, ta, newref->op1) != ALIAS_NO)
+ return 0; /* Conflict. */
+ ref = newref->prev;
+ }
+ return 1; /* No conflict. Can safely FOLD/CSE. */
+}
+
+/* ASTORE/HSTORE elimination. */
+TRef LJ_FASTCALL lj_opt_dse_ahstore(jit_State *J)
+{
+ IRRef xref = fins->op1; /* xREF reference. */
+ IRRef val = fins->op2; /* Stored value reference. */
+ IRIns *xr = IR(xref);
+ IRRef1 *refp = &J->chain[fins->o];
+ IRRef ref = *refp;
+ while (ref > xref) { /* Search for redundant or conflicting stores. */
+ IRIns *store = IR(ref);
+ switch (aa_ahref(J, xr, IR(store->op1))) {
+ case ALIAS_NO:
+ break; /* Continue searching. */
+ case ALIAS_MAY: /* Store to MAYBE the same location. */
+ if (store->op2 != val) /* Conflict if the value is different. */
+ goto doemit;
+ break; /* Otherwise continue searching. */
+ case ALIAS_MUST: /* Store to the same location. */
+ if (store->op2 == val) /* Same value: drop the new store. */
+ return DROPFOLD;
+ /* Different value: try to eliminate the redundant store. */
+ if (ref > J->chain[IR_LOOP]) { /* Quick check to avoid crossing LOOP. */
+ IRIns *ir;
+ /* Check for any intervening guards (includes conflicting loads). */
+ for (ir = IR(J->cur.nins-1); ir > store; ir--)
+ if (irt_isguard(ir->t) || ir->o == IR_CALLL)
+ goto doemit; /* No elimination possible. */
+ /* Remove redundant store from chain and replace with NOP. */
+ *refp = store->prev;
+ store->o = IR_NOP;
+ store->t.irt = IRT_NIL;
+ store->op1 = store->op2 = 0;
+ store->prev = 0;
+ /* Now emit the new store instead. */
+ }
+ goto doemit;
+ }
+ ref = *(refp = &store->prev);
+ }
+doemit:
+ return EMITFOLD; /* Otherwise we have a conflict or simply no match. */
+}
+
+/* -- ULOAD forwarding ---------------------------------------------------- */
+
+/* The current alias analysis for upvalues is very simplistic. It only
+** disambiguates between the unique upvalues of the same function.
+** This is good enough for now, since most upvalues are read-only.
+**
+** A more precise analysis would be feasible with the help of the parser:
+** generate a unique key for every upvalue, even across all prototypes.
+** Lacking a realistic use-case, it's unclear whether this is beneficial.
+*/
+static AliasRet aa_uref(IRIns *refa, IRIns *refb)
+{
+ if (refa->o != refb->o)
+ return ALIAS_NO; /* Different UREFx type. */
+ if (refa->op1 == refb->op1) { /* Same function. */
+ if (refa->op2 == refb->op2)
+ return ALIAS_MUST; /* Same function, same upvalue idx. */
+ else
+ return ALIAS_NO; /* Same function, different upvalue idx. */
+ } else { /* Different functions, check disambiguation hash values. */
+ if (((refa->op2 ^ refb->op2) & 0xff))
+ return ALIAS_NO; /* Upvalues with different hash values cannot alias. */
+ else
+ return ALIAS_MAY; /* No conclusion can be drawn for same hash value. */
+ }
+}
+
+/* ULOAD forwarding. */
+TRef LJ_FASTCALL lj_opt_fwd_uload(jit_State *J)
+{
+ IRRef uref = fins->op1;
+ IRRef lim = REF_BASE; /* Search limit. */
+ IRIns *xr = IR(uref);
+ IRRef ref;
+
+ /* Search for conflicting stores. */
+ ref = J->chain[IR_USTORE];
+ while (ref > lim) {
+ IRIns *store = IR(ref);
+ switch (aa_uref(xr, IR(store->op1))) {
+ case ALIAS_NO: break; /* Continue searching. */
+ case ALIAS_MAY: lim = ref; goto cselim; /* Limit search for load. */
+ case ALIAS_MUST: return store->op2; /* Store forwarding. */
+ }
+ ref = store->prev;
+ }
+
+cselim:
+ /* Try to find a matching load. Below the conflicting store, if any. */
+
+ ref = J->chain[IR_ULOAD];
+ while (ref > lim) {
+ IRIns *ir = IR(ref);
+ if (ir->op1 == uref ||
+ (IR(ir->op1)->op12 == IR(uref)->op12 && IR(ir->op1)->o == IR(uref)->o))
+ return ref; /* Match for identical or equal UREFx (non-CSEable UREFO). */
+ ref = ir->prev;
+ }
+ return lj_ir_emit(J);
+}
+
+/* USTORE elimination. */
+TRef LJ_FASTCALL lj_opt_dse_ustore(jit_State *J)
+{
+ IRRef xref = fins->op1; /* xREF reference. */
+ IRRef val = fins->op2; /* Stored value reference. */
+ IRIns *xr = IR(xref);
+ IRRef1 *refp = &J->chain[IR_USTORE];
+ IRRef ref = *refp;
+ while (ref > xref) { /* Search for redundant or conflicting stores. */
+ IRIns *store = IR(ref);
+ switch (aa_uref(xr, IR(store->op1))) {
+ case ALIAS_NO:
+ break; /* Continue searching. */
+ case ALIAS_MAY: /* Store to MAYBE the same location. */
+ if (store->op2 != val) /* Conflict if the value is different. */
+ goto doemit;
+ break; /* Otherwise continue searching. */
+ case ALIAS_MUST: /* Store to the same location. */
+ if (store->op2 == val) /* Same value: drop the new store. */
+ return DROPFOLD;
+ /* Different value: try to eliminate the redundant store. */
+ if (ref > J->chain[IR_LOOP]) { /* Quick check to avoid crossing LOOP. */
+ IRIns *ir;
+ /* Check for any intervening guards (includes conflicting loads). */
+ for (ir = IR(J->cur.nins-1); ir > store; ir--)
+ if (irt_isguard(ir->t))
+ goto doemit; /* No elimination possible. */
+ /* Remove redundant store from chain and replace with NOP. */
+ *refp = store->prev;
+ store->o = IR_NOP;
+ store->t.irt = IRT_NIL;
+ store->op1 = store->op2 = 0;
+ store->prev = 0;
+ if (ref+1 < J->cur.nins &&
+ store[1].o == IR_OBAR && store[1].op1 == xref) {
+ IRRef1 *bp = &J->chain[IR_OBAR];
+ IRIns *obar;
+ for (obar = IR(*bp); *bp > ref+1; obar = IR(*bp))
+ bp = &obar->prev;
+ /* Remove OBAR, too. */
+ *bp = obar->prev;
+ obar->o = IR_NOP;
+ obar->t.irt = IRT_NIL;
+ obar->op1 = obar->op2 = 0;
+ obar->prev = 0;
+ }
+ /* Now emit the new store instead. */
+ }
+ goto doemit;
+ }
+ ref = *(refp = &store->prev);
+ }
+doemit:
+ return EMITFOLD; /* Otherwise we have a conflict or simply no match. */
+}
+
+/* -- FLOAD forwarding and FSTORE elimination ----------------------------- */
+
+/* Alias analysis for field access.
+** Field loads are cheap and field stores are rare.
+** Simple disambiguation based on field types is good enough.
+*/
+static AliasRet aa_fref(jit_State *J, IRIns *refa, IRIns *refb)
+{
+ if (refa->op2 != refb->op2)
+ return ALIAS_NO; /* Different fields. */
+ if (refa->op1 == refb->op1)
+ return ALIAS_MUST; /* Same field, same object. */
+ else if (refa->op2 >= IRFL_TAB_META && refa->op2 <= IRFL_TAB_NOMM)
+ return aa_table(J, refa->op1, refb->op1); /* Disambiguate tables. */
+ else
+ return ALIAS_MAY; /* Same field, possibly different object. */
+}
+
+/* Only the loads for mutable fields end up here (see FOLD). */
+TRef LJ_FASTCALL lj_opt_fwd_fload(jit_State *J)
+{
+ IRRef oref = fins->op1; /* Object reference. */
+ IRRef fid = fins->op2; /* Field ID. */
+ IRRef lim = oref; /* Search limit. */
+ IRRef ref;
+
+ /* Search for conflicting stores. */
+ ref = J->chain[IR_FSTORE];
+ while (ref > oref) {
+ IRIns *store = IR(ref);
+ switch (aa_fref(J, fins, IR(store->op1))) {
+ case ALIAS_NO: break; /* Continue searching. */
+ case ALIAS_MAY: lim = ref; goto cselim; /* Limit search for load. */
+ case ALIAS_MUST: return store->op2; /* Store forwarding. */
+ }
+ ref = store->prev;
+ }
+
+ /* No conflicting store: const-fold field loads from allocations. */
+ if (fid == IRFL_TAB_META) {
+ IRIns *ir = IR(oref);
+ if (ir->o == IR_TNEW || ir->o == IR_TDUP)
+ return lj_ir_knull(J, IRT_TAB);
+ }
+
+cselim:
+ /* Try to find a matching load. Below the conflicting store, if any. */
+ return lj_opt_cselim(J, lim);
+}
+
+/* FSTORE elimination. */
+TRef LJ_FASTCALL lj_opt_dse_fstore(jit_State *J)
+{
+ IRRef fref = fins->op1; /* FREF reference. */
+ IRRef val = fins->op2; /* Stored value reference. */
+ IRIns *xr = IR(fref);
+ IRRef1 *refp = &J->chain[IR_FSTORE];
+ IRRef ref = *refp;
+ while (ref > fref) { /* Search for redundant or conflicting stores. */
+ IRIns *store = IR(ref);
+ switch (aa_fref(J, xr, IR(store->op1))) {
+ case ALIAS_NO:
+ break; /* Continue searching. */
+ case ALIAS_MAY:
+ if (store->op2 != val) /* Conflict if the value is different. */
+ goto doemit;
+ break; /* Otherwise continue searching. */
+ case ALIAS_MUST:
+ if (store->op2 == val) /* Same value: drop the new store. */
+ return DROPFOLD;
+ /* Different value: try to eliminate the redundant store. */
+ if (ref > J->chain[IR_LOOP]) { /* Quick check to avoid crossing LOOP. */
+ IRIns *ir;
+ /* Check for any intervening guards or conflicting loads. */
+ for (ir = IR(J->cur.nins-1); ir > store; ir--)
+ if (irt_isguard(ir->t) || (ir->o == IR_FLOAD && ir->op2 == xr->op2))
+ goto doemit; /* No elimination possible. */
+ /* Remove redundant store from chain and replace with NOP. */
+ *refp = store->prev;
+ store->o = IR_NOP;
+ store->t.irt = IRT_NIL;
+ store->op1 = store->op2 = 0;
+ store->prev = 0;
+ /* Now emit the new store instead. */
+ }
+ goto doemit;
+ }
+ ref = *(refp = &store->prev);
+ }
+doemit:
+ return EMITFOLD; /* Otherwise we have a conflict or simply no match. */
+}
+
+/* -- XLOAD forwarding and XSTORE elimination ----------------------------- */
+
+/* Find cdata allocation for a reference (if any). */
+static IRIns *aa_findcnew(jit_State *J, IRIns *ir)
+{
+ while (ir->o == IR_ADD) {
+ if (!irref_isk(ir->op1)) {
+ IRIns *ir1 = aa_findcnew(J, IR(ir->op1)); /* Left-recursion. */
+ if (ir1) return ir1;
+ }
+ if (irref_isk(ir->op2)) return NULL;
+ ir = IR(ir->op2); /* Flatten right-recursion. */
+ }
+ return ir->o == IR_CNEW ? ir : NULL;
+}
+
+/* Alias analysis for two cdata allocations. */
+static AliasRet aa_cnew(jit_State *J, IRIns *refa, IRIns *refb)
+{
+ IRIns *cnewa = aa_findcnew(J, refa);
+ IRIns *cnewb = aa_findcnew(J, refb);
+ if (cnewa == cnewb)
+ return ALIAS_MAY; /* Same allocation or neither is an allocation. */
+ if (cnewa && cnewb)
+ return ALIAS_NO; /* Two different allocations never alias. */
+ if (cnewb) { cnewa = cnewb; refb = refa; }
+ return aa_escape(J, cnewa, refb);
+}
+
+/* Alias analysis for XLOAD/XSTORE. */
+static AliasRet aa_xref(jit_State *J, IRIns *refa, IRIns *xa, IRIns *xb)
+{
+ ptrdiff_t ofsa = 0, ofsb = 0;
+ IRIns *refb = IR(xb->op1);
+ IRIns *basea = refa, *baseb = refb;
+ if (refa == refb && irt_sametype(xa->t, xb->t))
+ return ALIAS_MUST; /* Shortcut for same refs with identical type. */
+ /* Offset-based disambiguation. */
+ if (refa->o == IR_ADD && irref_isk(refa->op2)) {
+ IRIns *irk = IR(refa->op2);
+ basea = IR(refa->op1);
+ ofsa = (LJ_64 && irk->o == IR_KINT64) ? (ptrdiff_t)ir_k64(irk)->u64 :
+ (ptrdiff_t)irk->i;
+ }
+ if (refb->o == IR_ADD && irref_isk(refb->op2)) {
+ IRIns *irk = IR(refb->op2);
+ baseb = IR(refb->op1);
+ ofsb = (LJ_64 && irk->o == IR_KINT64) ? (ptrdiff_t)ir_k64(irk)->u64 :
+ (ptrdiff_t)irk->i;
+ }
+ /* Treat constified pointers like base vs. base+offset. */
+ if (basea->o == IR_KPTR && baseb->o == IR_KPTR) {
+ ofsb += (char *)ir_kptr(baseb) - (char *)ir_kptr(basea);
+ baseb = basea;
+ }
+ /* This implements (very) strict aliasing rules.
+ ** Different types do NOT alias, except for differences in signedness.
+ ** Type punning through unions is allowed (but forces a reload).
+ */
+ if (basea == baseb) {
+ ptrdiff_t sza = irt_size(xa->t), szb = irt_size(xb->t);
+ if (ofsa == ofsb) {
+ if (sza == szb && irt_isfp(xa->t) == irt_isfp(xb->t))
+ return ALIAS_MUST; /* Same-sized, same-kind. May need to convert. */
+ } else if (ofsa + sza <= ofsb || ofsb + szb <= ofsa) {
+ return ALIAS_NO; /* Non-overlapping base+-o1 vs. base+-o2. */
+ }
+ /* NYI: extract, extend or reinterpret bits (int <-> fp). */
+ return ALIAS_MAY; /* Overlapping or type punning: force reload. */
+ }
+ if (!irt_sametype(xa->t, xb->t) &&
+ !(irt_typerange(xa->t, IRT_I8, IRT_U64) &&
+ ((xa->t.irt - IRT_I8) ^ (xb->t.irt - IRT_I8)) == 1))
+ return ALIAS_NO;
+ /* NYI: structural disambiguation. */
+ return aa_cnew(J, basea, baseb); /* Try to disambiguate allocations. */
+}
+
+/* Return CSEd reference or 0. Caveat: swaps lower ref to the right! */
+static IRRef reassoc_trycse(jit_State *J, IROp op, IRRef op1, IRRef op2)
+{
+ IRRef ref = J->chain[op];
+ IRRef lim = op1;
+ if (op2 > lim) { lim = op2; op2 = op1; op1 = lim; }
+ while (ref > lim) {
+ IRIns *ir = IR(ref);
+ if (ir->op1 == op1 && ir->op2 == op2)
+ return ref;
+ ref = ir->prev;
+ }
+ return 0;
+}
+
+/* Reassociate index references. */
+static IRRef reassoc_xref(jit_State *J, IRIns *ir)
+{
+ ptrdiff_t ofs = 0;
+ if (ir->o == IR_ADD && irref_isk(ir->op2)) { /* Get constant offset. */
+ IRIns *irk = IR(ir->op2);
+ ofs = (LJ_64 && irk->o == IR_KINT64) ? (ptrdiff_t)ir_k64(irk)->u64 :
+ (ptrdiff_t)irk->i;
+ ir = IR(ir->op1);
+ }
+ if (ir->o == IR_ADD) { /* Add of base + index. */
+ /* Index ref > base ref for loop-carried dependences. Only check op1. */
+ IRIns *ir2, *ir1 = IR(ir->op1);
+ int32_t shift = 0;
+ IRRef idxref;
+ /* Determine index shifts. Don't bother with IR_MUL here. */
+ if (ir1->o == IR_BSHL && irref_isk(ir1->op2))
+ shift = IR(ir1->op2)->i;
+ else if (ir1->o == IR_ADD && ir1->op1 == ir1->op2)
+ shift = 1;
+ else
+ ir1 = ir;
+ ir2 = IR(ir1->op1);
+ /* A non-reassociated add. Must be a loop-carried dependence. */
+ if (ir2->o == IR_ADD && irt_isint(ir2->t) && irref_isk(ir2->op2))
+ ofs += (ptrdiff_t)IR(ir2->op2)->i << shift;
+ else
+ return 0;
+ idxref = ir2->op1;
+ /* Try to CSE the reassociated chain. Give up if not found. */
+ if (ir1 != ir &&
+ !(idxref = reassoc_trycse(J, ir1->o, idxref,
+ ir1->o == IR_BSHL ? ir1->op2 : idxref)))
+ return 0;
+ if (!(idxref = reassoc_trycse(J, IR_ADD, idxref, ir->op2)))
+ return 0;
+ if (ofs != 0) {
+ IRRef refk = tref_ref(lj_ir_kintp(J, ofs));
+ if (!(idxref = reassoc_trycse(J, IR_ADD, idxref, refk)))
+ return 0;
+ }
+ return idxref; /* Success, found a reassociated index reference. Phew. */
+ }
+ return 0; /* Failure. */
+}
+
+/* XLOAD forwarding. */
+TRef LJ_FASTCALL lj_opt_fwd_xload(jit_State *J)
+{
+ IRRef xref = fins->op1;
+ IRIns *xr = IR(xref);
+ IRRef lim = xref; /* Search limit. */
+ IRRef ref;
+
+ if ((fins->op2 & IRXLOAD_READONLY))
+ goto cselim;
+ if ((fins->op2 & IRXLOAD_VOLATILE))
+ goto doemit;
+
+ /* Search for conflicting stores. */
+ ref = J->chain[IR_XSTORE];
+retry:
+ if (J->chain[IR_CALLXS] > lim) lim = J->chain[IR_CALLXS];
+ if (J->chain[IR_XBAR] > lim) lim = J->chain[IR_XBAR];
+ while (ref > lim) {
+ IRIns *store = IR(ref);
+ switch (aa_xref(J, xr, fins, store)) {
+ case ALIAS_NO: break; /* Continue searching. */
+ case ALIAS_MAY: lim = ref; goto cselim; /* Limit search for load. */
+ case ALIAS_MUST:
+ /* Emit conversion if the loaded type doesn't match the forwarded type. */
+ if (!irt_sametype(fins->t, IR(store->op2)->t)) {
+ IRType dt = irt_type(fins->t), st = irt_type(IR(store->op2)->t);
+ if (dt == IRT_I8 || dt == IRT_I16) { /* Trunc + sign-extend. */
+ st = dt | IRCONV_SEXT;
+ dt = IRT_INT;
+ } else if (dt == IRT_U8 || dt == IRT_U16) { /* Trunc + zero-extend. */
+ st = dt;
+ dt = IRT_INT;
+ }
+ fins->ot = IRT(IR_CONV, dt);
+ fins->op1 = store->op2;
+ fins->op2 = (dt<<5)|st;
+ return RETRYFOLD;
+ }
+ return store->op2; /* Store forwarding. */
+ }
+ ref = store->prev;
+ }
+
+cselim:
+ /* Try to find a matching load. Below the conflicting store, if any. */
+ ref = J->chain[IR_XLOAD];
+ while (ref > lim) {
+ /* CSE for XLOAD depends on the type, but not on the IRXLOAD_* flags. */
+ if (IR(ref)->op1 == xref && irt_sametype(IR(ref)->t, fins->t))
+ return ref;
+ ref = IR(ref)->prev;
+ }
+
+ /* Reassociate XLOAD across PHIs to handle a[i-1] forwarding case. */
+ if (!(fins->op2 & IRXLOAD_READONLY) && J->chain[IR_LOOP] &&
+ xref == fins->op1 && (xref = reassoc_xref(J, xr)) != 0) {
+ ref = J->chain[IR_XSTORE];
+ while (ref > lim) /* Skip stores that have already been checked. */
+ ref = IR(ref)->prev;
+ lim = xref;
+ xr = IR(xref);
+ goto retry; /* Retry with the reassociated reference. */
+ }
+doemit:
+ return EMITFOLD;
+}
+
+/* XSTORE elimination. */
+TRef LJ_FASTCALL lj_opt_dse_xstore(jit_State *J)
+{
+ IRRef xref = fins->op1;
+ IRIns *xr = IR(xref);
+ IRRef lim = xref; /* Search limit. */
+ IRRef val = fins->op2; /* Stored value reference. */
+ IRRef1 *refp = &J->chain[IR_XSTORE];
+ IRRef ref = *refp;
+ if (J->chain[IR_CALLXS] > lim) lim = J->chain[IR_CALLXS];
+ if (J->chain[IR_XBAR] > lim) lim = J->chain[IR_XBAR];
+ if (J->chain[IR_XSNEW] > lim) lim = J->chain[IR_XSNEW];
+ while (ref > lim) { /* Search for redundant or conflicting stores. */
+ IRIns *store = IR(ref);
+ switch (aa_xref(J, xr, fins, store)) {
+ case ALIAS_NO:
+ break; /* Continue searching. */
+ case ALIAS_MAY:
+ if (store->op2 != val) /* Conflict if the value is different. */
+ goto doemit;
+ break; /* Otherwise continue searching. */
+ case ALIAS_MUST:
+ if (store->op2 == val) /* Same value: drop the new store. */
+ return DROPFOLD;
+ /* Different value: try to eliminate the redundant store. */
+ if (ref > J->chain[IR_LOOP]) { /* Quick check to avoid crossing LOOP. */
+ IRIns *ir;
+ /* Check for any intervening guards or any XLOADs (no AA performed). */
+ for (ir = IR(J->cur.nins-1); ir > store; ir--)
+ if (irt_isguard(ir->t) || ir->o == IR_XLOAD)
+ goto doemit; /* No elimination possible. */
+ /* Remove redundant store from chain and replace with NOP. */
+ *refp = store->prev;
+ store->o = IR_NOP;
+ store->t.irt = IRT_NIL;
+ store->op1 = store->op2 = 0;
+ store->prev = 0;
+ /* Now emit the new store instead. */
+ }
+ goto doemit;
+ }
+ ref = *(refp = &store->prev);
+ }
+doemit:
+ return EMITFOLD; /* Otherwise we have a conflict or simply no match. */
+}
+
+/* -- Forwarding of lj_tab_len -------------------------------------------- */
+
+/* This is rather simplistic right now, but better than nothing. */
+TRef LJ_FASTCALL lj_opt_fwd_tab_len(jit_State *J)
+{
+ IRRef tab = fins->op1; /* Table reference. */
+ IRRef lim = tab; /* Search limit. */
+ IRRef ref;
+
+ /* Any ASTORE is a conflict and limits the search. */
+ if (J->chain[IR_ASTORE] > lim) lim = J->chain[IR_ASTORE];
+
+ /* Search for conflicting HSTORE with numeric key. */
+ ref = J->chain[IR_HSTORE];
+ while (ref > lim) {
+ IRIns *store = IR(ref);
+ IRIns *href = IR(store->op1);
+ IRIns *key = IR(href->op2);
+ if (irt_isnum(key->o == IR_KSLOT ? IR(key->op1)->t : key->t)) {
+ lim = ref; /* Conflicting store found, limits search for TLEN. */
+ break;
+ }
+ ref = store->prev;
+ }
+
+ /* Try to find a matching load. Below the conflicting store, if any. */
+ return lj_opt_cselim(J, lim);
+}
+
+/* -- ASTORE/HSTORE previous type analysis -------------------------------- */
+
+/* Check whether the previous value for a table store is non-nil.
+** This can be derived either from a previous store or from a previous
+** load (because all loads from tables perform a type check).
+**
+** The result of the analysis can be used to avoid the metatable check
+** and the guard against HREF returning niltv. Both of these are cheap,
+** so let's not spend too much effort on the analysis.
+**
+** A result of 1 is exact: previous value CANNOT be nil.
+** A result of 0 is inexact: previous value MAY be nil.
+*/
+int lj_opt_fwd_wasnonnil(jit_State *J, IROpT loadop, IRRef xref)
+{
+ /* First check stores. */
+ IRRef ref = J->chain[loadop+IRDELTA_L2S];
+ while (ref > xref) {
+ IRIns *store = IR(ref);
+ if (store->op1 == xref) { /* Same xREF. */
+ /* A nil store MAY alias, but a non-nil store MUST alias. */
+ return !irt_isnil(store->t);
+ } else if (irt_isnil(store->t)) { /* Must check any nil store. */
+ IRRef skref = IR(store->op1)->op2;
+ IRRef xkref = IR(xref)->op2;
+ /* Same key type MAY alias. Need ALOAD check due to multiple int types. */
+ if (loadop == IR_ALOAD || irt_sametype(IR(skref)->t, IR(xkref)->t)) {
+ if (skref == xkref || !irref_isk(skref) || !irref_isk(xkref))
+ return 0; /* A nil store with same const key or var key MAY alias. */
+ /* Different const keys CANNOT alias. */
+ } /* Different key types CANNOT alias. */
+ } /* Other non-nil stores MAY alias. */
+ ref = store->prev;
+ }
+
+ /* Check loads since nothing could be derived from stores. */
+ ref = J->chain[loadop];
+ while (ref > xref) {
+ IRIns *load = IR(ref);
+ if (load->op1 == xref) { /* Same xREF. */
+ /* A nil load MAY alias, but a non-nil load MUST alias. */
+ return !irt_isnil(load->t);
+ } /* Other non-nil loads MAY alias. */
+ ref = load->prev;
+ }
+ return 0; /* Nothing derived at all, previous value MAY be nil. */
+}
+
+/* ------------------------------------------------------------------------ */
+
+#undef IR
+#undef fins
+#undef fleft
+#undef fright
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_narrow.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_narrow.c
new file mode 100644
index 0000000..7336595
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_narrow.c
@@ -0,0 +1,654 @@
+/*
+** NARROW: Narrowing of numbers to integers (double to int32_t).
+** STRIPOV: Stripping of overflow checks.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_opt_narrow_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT
+
+#include "lj_bc.h"
+#include "lj_ir.h"
+#include "lj_jit.h"
+#include "lj_iropt.h"
+#include "lj_trace.h"
+#include "lj_vm.h"
+#include "lj_strscan.h"
+
+/* Rationale for narrowing optimizations:
+**
+** Lua has only a single number type and this is a FP double by default.
+** Narrowing doubles to integers does not pay off for the interpreter on a
+** current-generation x86/x64 machine. Most FP operations need the same
+** amount of execution resources as their integer counterparts, except
+** with slightly longer latencies. Longer latencies are a non-issue for
+** the interpreter, since they are usually hidden by other overhead.
+**
+** The total CPU execution bandwidth is the sum of the bandwidth of the FP
+** and the integer units, because they execute in parallel. The FP units
+** have an equal or higher bandwidth than the integer units. Not using
+** them means losing execution bandwidth. Moving work away from them to
+** the already quite busy integer units is a losing proposition.
+**
+** The situation for JIT-compiled code is a bit different: the higher code
+** density makes the extra latencies much more visible. Tight loops expose
+** the latencies for updating the induction variables. Array indexing
+** requires narrowing conversions with high latencies and additional
+** guards (to check that the index is really an integer). And many common
+** optimizations only work on integers.
+**
+** One solution would be speculative, eager narrowing of all number loads.
+** This causes many problems, like losing -0 or the need to resolve type
+** mismatches between traces. It also effectively forces the integer type
+** to have overflow-checking semantics. This impedes many basic
+** optimizations and requires adding overflow checks to all integer
+** arithmetic operations (whereas FP arithmetics can do without).
+**
+** Always replacing an FP op with an integer op plus an overflow check is
+** counter-productive on a current-generation super-scalar CPU. Although
+** the overflow check branches are highly predictable, they will clog the
+** execution port for the branch unit and tie up reorder buffers. This is
+** turning a pure data-flow dependency into a different data-flow
+** dependency (with slightly lower latency) *plus* a control dependency.
+** In general, you don't want to do this since latencies due to data-flow
+** dependencies can be well hidden by out-of-order execution.
+**
+** A better solution is to keep all numbers as FP values and only narrow
+** when it's beneficial to do so. LuaJIT uses predictive narrowing for
+** induction variables and demand-driven narrowing for index expressions,
+** integer arguments and bit operations. Additionally it can eliminate or
+** hoist most of the resulting overflow checks. Regular arithmetic
+** computations are never narrowed to integers.
+**
+** The integer type in the IR has convenient wrap-around semantics and
+** ignores overflow. Extra operations have been added for
+** overflow-checking arithmetic (ADDOV/SUBOV) instead of an extra type.
+** Apart from reducing overall complexity of the compiler, this also
+** nicely solves the problem where you want to apply algebraic
+** simplifications to ADD, but not to ADDOV. And the x86/x64 assembler can
+** use lea instead of an add for integer ADD, but not for ADDOV (lea does
+** not affect the flags, but it helps to avoid register moves).
+**
+**
+** All of the above has to be reconsidered for architectures with slow FP
+** operations or without a hardware FPU. The dual-number mode of LuaJIT
+** addresses this issue. Arithmetic operations are performed on integers
+** as far as possible and overflow checks are added as needed.
+**
+** This implies that narrowing for integer arguments and bit operations
+** should also strip overflow checks, e.g. replace ADDOV with ADD. The
+** original overflow guards are weak and can be eliminated by DCE, if
+** there's no other use.
+**
+** A slight twist is that it's usually beneficial to use overflow-checked
+** integer arithmetics if all inputs are already integers. This is the only
+** change that affects the single-number mode, too.
+*/
+
+/* Some local macros to save typing. Undef'd at the end. */
+#define IR(ref) (&J->cur.ir[(ref)])
+#define fins (&J->fold.ins)
+
+/* Pass IR on to next optimization in chain (FOLD). */
+#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))
+
+#define emitir_raw(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J))
+
+/* -- Elimination of narrowing type conversions --------------------------- */
+
+/* Narrowing of index expressions and bit operations is demand-driven. The
+** trace recorder emits a narrowing type conversion (CONV.int.num or TOBIT)
+** in all of these cases (e.g. array indexing or string indexing). FOLD
+** already takes care of eliminating simple redundant conversions like
+** CONV.int.num(CONV.num.int(x)) ==> x.
+**
+** But the surrounding code is FP-heavy and arithmetic operations are
+** performed on FP numbers (for the single-number mode). Consider a common
+** example such as 'x=t[i+1]', with 'i' already an integer (due to induction
+** variable narrowing). The index expression would be recorded as
+** CONV.int.num(ADD(CONV.num.int(i), 1))
+** which is clearly suboptimal.
+**
+** One can do better by recursively backpropagating the narrowing type
+** conversion across FP arithmetic operations. This turns FP ops into
+** their corresponding integer counterparts. Depending on the semantics of
+** the conversion they also need to check for overflow. Currently only ADD
+** and SUB are supported.
+**
+** The above example can be rewritten as
+** ADDOV(CONV.int.num(CONV.num.int(i)), 1)
+** and then into ADDOV(i, 1) after folding of the conversions. The original
+** FP ops remain in the IR and are eliminated by DCE since all references to
+** them are gone.
+**
+** [In dual-number mode the trace recorder already emits ADDOV etc., but
+** this can be further reduced. See below.]
+**
+** Special care has to be taken to avoid narrowing across an operation
+** which is potentially operating on non-integral operands. One obvious
+** case is when an expression contains a non-integral constant, but ends
+** up as an integer index at runtime (like t[x+1.5] with x=0.5).
+**
+** Operations with two non-constant operands illustrate a similar problem
+** (like t[a+b] with a=1.5 and b=2.5). Backpropagation has to stop there,
+** unless it can be proven that either operand is integral (e.g. by CSEing
+** a previous conversion). As a not-so-obvious corollary this logic also
+** applies for a whole expression tree (e.g. t[(a+1)+(b+1)]).
+**
+** Correctness of the transformation is guaranteed by avoiding to expand
+** the tree by adding more conversions than the one we would need to emit
+** if not backpropagating. TOBIT employs a more optimistic rule, because
+** the conversion has special semantics, designed to make the life of the
+** compiler writer easier. ;-)
+**
+** Using on-the-fly backpropagation of an expression tree doesn't work
+** because it's unknown whether the transform is correct until the end.
+** This either requires IR rollback and cache invalidation for every
+** subtree or a two-pass algorithm. The former didn't work out too well,
+** so the code now combines a recursive collector with a stack-based
+** emitter.
+**
+** [A recursive backpropagation algorithm with backtracking, employing
+** skip-list lookup and round-robin caching, emitting stack operations
+** on-the-fly for a stack-based interpreter -- and all of that in a meager
+** kilobyte? Yep, compilers are a great treasure chest. Throw away your
+** textbooks and read the codebase of a compiler today!]
+**
+** There's another optimization opportunity for array indexing: it's
+** always accompanied by an array bounds-check. The outermost overflow
+** check may be delegated to the ABC operation. This works because ABC is
+** an unsigned comparison and wrap-around due to overflow creates negative
+** numbers.
+**
+** But this optimization is only valid for constants that cannot overflow
+** an int32_t into the range of valid array indexes [0..2^27+1). A check
+** for +-2^30 is safe since -2^31 - 2^30 wraps to 2^30 and 2^31-1 + 2^30
+** wraps to -2^30-1.
+**
+** It's also good enough in practice, since e.g. t[i+1] or t[i-10] are
+** quite common. So the above example finally ends up as ADD(i, 1)!
+**
+** Later on, the assembler is able to fuse the whole array reference and
+** the ADD into the memory operands of loads and other instructions. This
+** is why LuaJIT is able to generate very pretty (and fast) machine code
+** for array indexing. And that, my dear, concludes another story about
+** one of the hidden secrets of LuaJIT ...
+*/
+
+/* Maximum backpropagation depth and maximum stack size. */
+#define NARROW_MAX_BACKPROP 100
+#define NARROW_MAX_STACK 256
+
+/* The stack machine has a 32 bit instruction format: [IROpT | IRRef1]
+** The lower 16 bits hold a reference (or 0). The upper 16 bits hold
+** the IR opcode + type or one of the following special opcodes:
+*/
+enum {
+ NARROW_REF, /* Push ref. */
+ NARROW_CONV, /* Push conversion of ref. */
+ NARROW_SEXT, /* Push sign-extension of ref. */
+ NARROW_INT /* Push KINT ref. The next code holds an int32_t. */
+};
+
+typedef uint32_t NarrowIns;
+
+#define NARROWINS(op, ref) (((op) << 16) + (ref))
+#define narrow_op(ins) ((IROpT)((ins) >> 16))
+#define narrow_ref(ins) ((IRRef1)(ins))
+
+/* Context used for narrowing of type conversions. */
+typedef struct NarrowConv {
+ jit_State *J; /* JIT compiler state. */
+ NarrowIns *sp; /* Current stack pointer. */
+ NarrowIns *maxsp; /* Maximum stack pointer minus redzone. */
+ IRRef mode; /* Conversion mode (IRCONV_*). */
+ IRType t; /* Destination type: IRT_INT or IRT_I64. */
+ NarrowIns stack[NARROW_MAX_STACK]; /* Stack holding stack-machine code. */
+} NarrowConv;
+
+/* Lookup a reference in the backpropagation cache. */
+static BPropEntry *narrow_bpc_get(jit_State *J, IRRef1 key, IRRef mode)
+{
+ ptrdiff_t i;
+ for (i = 0; i < BPROP_SLOTS; i++) {
+ BPropEntry *bp = &J->bpropcache[i];
+ /* Stronger checks are ok, too. */
+ if (bp->key == key && bp->mode >= mode &&
+ ((bp->mode ^ mode) & IRCONV_MODEMASK) == 0)
+ return bp;
+ }
+ return NULL;
+}
+
+/* Add an entry to the backpropagation cache. */
+static void narrow_bpc_set(jit_State *J, IRRef1 key, IRRef1 val, IRRef mode)
+{
+ uint32_t slot = J->bpropslot;
+ BPropEntry *bp = &J->bpropcache[slot];
+ J->bpropslot = (slot + 1) & (BPROP_SLOTS-1);
+ bp->key = key;
+ bp->val = val;
+ bp->mode = mode;
+}
+
+/* Backpropagate overflow stripping. */
+static void narrow_stripov_backprop(NarrowConv *nc, IRRef ref, int depth)
+{
+ jit_State *J = nc->J;
+ IRIns *ir = IR(ref);
+ if (ir->o == IR_ADDOV || ir->o == IR_SUBOV ||
+ (ir->o == IR_MULOV && (nc->mode & IRCONV_CONVMASK) == IRCONV_ANY)) {
+ BPropEntry *bp = narrow_bpc_get(nc->J, ref, IRCONV_TOBIT);
+ if (bp) {
+ ref = bp->val;
+ } else if (++depth < NARROW_MAX_BACKPROP && nc->sp < nc->maxsp) {
+ NarrowIns *savesp = nc->sp;
+ narrow_stripov_backprop(nc, ir->op1, depth);
+ if (nc->sp < nc->maxsp) {
+ narrow_stripov_backprop(nc, ir->op2, depth);
+ if (nc->sp < nc->maxsp) {
+ *nc->sp++ = NARROWINS(IRT(ir->o - IR_ADDOV + IR_ADD, IRT_INT), ref);
+ return;
+ }
+ }
+ nc->sp = savesp; /* Path too deep, need to backtrack. */
+ }
+ }
+ *nc->sp++ = NARROWINS(NARROW_REF, ref);
+}
+
+/* Backpropagate narrowing conversion. Return number of needed conversions. */
+static int narrow_conv_backprop(NarrowConv *nc, IRRef ref, int depth)
+{
+ jit_State *J = nc->J;
+ IRIns *ir = IR(ref);
+ IRRef cref;
+
+ if (nc->sp >= nc->maxsp) return 10; /* Path too deep. */
+
+ /* Check the easy cases first. */
+ if (ir->o == IR_CONV && (ir->op2 & IRCONV_SRCMASK) == IRT_INT) {
+ if ((nc->mode & IRCONV_CONVMASK) <= IRCONV_ANY)
+ narrow_stripov_backprop(nc, ir->op1, depth+1);
+ else
+ *nc->sp++ = NARROWINS(NARROW_REF, ir->op1); /* Undo conversion. */
+ if (nc->t == IRT_I64)
+ *nc->sp++ = NARROWINS(NARROW_SEXT, 0); /* Sign-extend integer. */
+ return 0;
+ } else if (ir->o == IR_KNUM) { /* Narrow FP constant. */
+ lua_Number n = ir_knum(ir)->n;
+ if ((nc->mode & IRCONV_CONVMASK) == IRCONV_TOBIT) {
+ /* Allows a wider range of constants. */
+ int64_t k64 = (int64_t)n;
+ if (n == (lua_Number)k64) { /* Only if const doesn't lose precision. */
+ *nc->sp++ = NARROWINS(NARROW_INT, 0);
+ *nc->sp++ = (NarrowIns)k64; /* But always truncate to 32 bits. */
+ return 0;
+ }
+ } else {
+ int32_t k = lj_num2int(n);
+ /* Only if constant is a small integer. */
+ if (checki16(k) && n == (lua_Number)k) {
+ *nc->sp++ = NARROWINS(NARROW_INT, 0);
+ *nc->sp++ = (NarrowIns)k;
+ return 0;
+ }
+ }
+ return 10; /* Never narrow other FP constants (this is rare). */
+ }
+
+ /* Try to CSE the conversion. Stronger checks are ok, too. */
+ cref = J->chain[fins->o];
+ while (cref > ref) {
+ IRIns *cr = IR(cref);
+ if (cr->op1 == ref &&
+ (fins->o == IR_TOBIT ||
+ ((cr->op2 & IRCONV_MODEMASK) == (nc->mode & IRCONV_MODEMASK) &&
+ irt_isguard(cr->t) >= irt_isguard(fins->t)))) {
+ *nc->sp++ = NARROWINS(NARROW_REF, cref);
+ return 0; /* Already there, no additional conversion needed. */
+ }
+ cref = cr->prev;
+ }
+
+ /* Backpropagate across ADD/SUB. */
+ if (ir->o == IR_ADD || ir->o == IR_SUB) {
+ /* Try cache lookup first. */
+ IRRef mode = nc->mode;
+ BPropEntry *bp;
+ /* Inner conversions need a stronger check. */
+ if ((mode & IRCONV_CONVMASK) == IRCONV_INDEX && depth > 0)
+ mode += IRCONV_CHECK-IRCONV_INDEX;
+ bp = narrow_bpc_get(nc->J, (IRRef1)ref, mode);
+ if (bp) {
+ *nc->sp++ = NARROWINS(NARROW_REF, bp->val);
+ return 0;
+ } else if (nc->t == IRT_I64) {
+ /* Try sign-extending from an existing (checked) conversion to int. */
+ mode = (IRT_INT<<5)|IRT_NUM|IRCONV_INDEX;
+ bp = narrow_bpc_get(nc->J, (IRRef1)ref, mode);
+ if (bp) {
+ *nc->sp++ = NARROWINS(NARROW_REF, bp->val);
+ *nc->sp++ = NARROWINS(NARROW_SEXT, 0);
+ return 0;
+ }
+ }
+ if (++depth < NARROW_MAX_BACKPROP && nc->sp < nc->maxsp) {
+ NarrowIns *savesp = nc->sp;
+ int count = narrow_conv_backprop(nc, ir->op1, depth);
+ count += narrow_conv_backprop(nc, ir->op2, depth);
+ if (count <= 1) { /* Limit total number of conversions. */
+ *nc->sp++ = NARROWINS(IRT(ir->o, nc->t), ref);
+ return count;
+ }
+ nc->sp = savesp; /* Too many conversions, need to backtrack. */
+ }
+ }
+
+ /* Otherwise add a conversion. */
+ *nc->sp++ = NARROWINS(NARROW_CONV, ref);
+ return 1;
+}
+
+/* Emit the conversions collected during backpropagation. */
+static IRRef narrow_conv_emit(jit_State *J, NarrowConv *nc)
+{
+ /* The fins fields must be saved now -- emitir() overwrites them. */
+ IROpT guardot = irt_isguard(fins->t) ? IRTG(IR_ADDOV-IR_ADD, 0) : 0;
+ IROpT convot = fins->ot;
+ IRRef1 convop2 = fins->op2;
+ NarrowIns *next = nc->stack; /* List of instructions from backpropagation. */
+ NarrowIns *last = nc->sp;
+ NarrowIns *sp = nc->stack; /* Recycle the stack to store operands. */
+ while (next < last) { /* Simple stack machine to process the ins. list. */
+ NarrowIns ref = *next++;
+ IROpT op = narrow_op(ref);
+ if (op == NARROW_REF) {
+ *sp++ = ref;
+ } else if (op == NARROW_CONV) {
+ *sp++ = emitir_raw(convot, ref, convop2); /* Raw emit avoids a loop. */
+ } else if (op == NARROW_SEXT) {
+ lua_assert(sp >= nc->stack+1);
+ sp[-1] = emitir(IRT(IR_CONV, IRT_I64), sp[-1],
+ (IRT_I64<<5)|IRT_INT|IRCONV_SEXT);
+ } else if (op == NARROW_INT) {
+ lua_assert(next < last);
+ *sp++ = nc->t == IRT_I64 ?
+ lj_ir_kint64(J, (int64_t)(int32_t)*next++) :
+ lj_ir_kint(J, *next++);
+ } else { /* Regular IROpT. Pops two operands and pushes one result. */
+ IRRef mode = nc->mode;
+ lua_assert(sp >= nc->stack+2);
+ sp--;
+ /* Omit some overflow checks for array indexing. See comments above. */
+ if ((mode & IRCONV_CONVMASK) == IRCONV_INDEX) {
+ if (next == last && irref_isk(narrow_ref(sp[0])) &&
+ (uint32_t)IR(narrow_ref(sp[0]))->i + 0x40000000u < 0x80000000u)
+ guardot = 0;
+ else /* Otherwise cache a stronger check. */
+ mode += IRCONV_CHECK-IRCONV_INDEX;
+ }
+ sp[-1] = emitir(op+guardot, sp[-1], sp[0]);
+ /* Add to cache. */
+ if (narrow_ref(ref))
+ narrow_bpc_set(J, narrow_ref(ref), narrow_ref(sp[-1]), mode);
+ }
+ }
+ lua_assert(sp == nc->stack+1);
+ return nc->stack[0];
+}
+
+/* Narrow a type conversion of an arithmetic operation. */
+TRef LJ_FASTCALL lj_opt_narrow_convert(jit_State *J)
+{
+ if ((J->flags & JIT_F_OPT_NARROW)) {
+ NarrowConv nc;
+ nc.J = J;
+ nc.sp = nc.stack;
+ nc.maxsp = &nc.stack[NARROW_MAX_STACK-4];
+ nc.t = irt_type(fins->t);
+ if (fins->o == IR_TOBIT) {
+ nc.mode = IRCONV_TOBIT; /* Used only in the backpropagation cache. */
+ } else {
+ nc.mode = fins->op2;
+ }
+ if (narrow_conv_backprop(&nc, fins->op1, 0) <= 1)
+ return narrow_conv_emit(J, &nc);
+ }
+ return NEXTFOLD;
+}
+
+/* -- Narrowing of implicit conversions ----------------------------------- */
+
+/* Recursively strip overflow checks. */
+static TRef narrow_stripov(jit_State *J, TRef tr, int lastop, IRRef mode)
+{
+ IRRef ref = tref_ref(tr);
+ IRIns *ir = IR(ref);
+ int op = ir->o;
+ if (op >= IR_ADDOV && op <= lastop) {
+ BPropEntry *bp = narrow_bpc_get(J, ref, mode);
+ if (bp) {
+ return TREF(bp->val, irt_t(IR(bp->val)->t));
+ } else {
+ IRRef op1 = ir->op1, op2 = ir->op2; /* The IR may be reallocated. */
+ op1 = narrow_stripov(J, op1, lastop, mode);
+ op2 = narrow_stripov(J, op2, lastop, mode);
+ tr = emitir(IRT(op - IR_ADDOV + IR_ADD,
+ ((mode & IRCONV_DSTMASK) >> IRCONV_DSH)), op1, op2);
+ narrow_bpc_set(J, ref, tref_ref(tr), mode);
+ }
+ } else if (LJ_64 && (mode & IRCONV_SEXT) && !irt_is64(ir->t)) {
+ tr = emitir(IRT(IR_CONV, IRT_INTP), tr, mode);
+ }
+ return tr;
+}
+
+/* Narrow array index. */
+TRef LJ_FASTCALL lj_opt_narrow_index(jit_State *J, TRef tr)
+{
+ IRIns *ir;
+ lua_assert(tref_isnumber(tr));
+ if (tref_isnum(tr)) /* Conversion may be narrowed, too. See above. */
+ return emitir(IRTGI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_INDEX);
+ /* Omit some overflow checks for array indexing. See comments above. */
+ ir = IR(tref_ref(tr));
+ if ((ir->o == IR_ADDOV || ir->o == IR_SUBOV) && irref_isk(ir->op2) &&
+ (uint32_t)IR(ir->op2)->i + 0x40000000u < 0x80000000u)
+ return emitir(IRTI(ir->o - IR_ADDOV + IR_ADD), ir->op1, ir->op2);
+ return tr;
+}
+
+/* Narrow conversion to integer operand (overflow undefined). */
+TRef LJ_FASTCALL lj_opt_narrow_toint(jit_State *J, TRef tr)
+{
+ if (tref_isstr(tr))
+ tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);
+ if (tref_isnum(tr)) /* Conversion may be narrowed, too. See above. */
+ return emitir(IRTI(IR_CONV), tr, IRCONV_INT_NUM|IRCONV_ANY);
+ if (!tref_isinteger(tr))
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ /*
+ ** Undefined overflow semantics allow stripping of ADDOV, SUBOV and MULOV.
+ ** Use IRCONV_TOBIT for the cache entries, since the semantics are the same.
+ */
+ return narrow_stripov(J, tr, IR_MULOV, (IRT_INT<<5)|IRT_INT|IRCONV_TOBIT);
+}
+
+/* Narrow conversion to bitop operand (overflow wrapped). */
+TRef LJ_FASTCALL lj_opt_narrow_tobit(jit_State *J, TRef tr)
+{
+ if (tref_isstr(tr))
+ tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);
+ if (tref_isnum(tr)) /* Conversion may be narrowed, too. See above. */
+ return emitir(IRTI(IR_TOBIT), tr, lj_ir_knum_tobit(J));
+ if (!tref_isinteger(tr))
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ /*
+ ** Wrapped overflow semantics allow stripping of ADDOV and SUBOV.
+ ** MULOV cannot be stripped due to precision widening.
+ */
+ return narrow_stripov(J, tr, IR_SUBOV, (IRT_INT<<5)|IRT_INT|IRCONV_TOBIT);
+}
+
+#if LJ_HASFFI
+/* Narrow C array index (overflow undefined). */
+TRef LJ_FASTCALL lj_opt_narrow_cindex(jit_State *J, TRef tr)
+{
+ lua_assert(tref_isnumber(tr));
+ if (tref_isnum(tr))
+ return emitir(IRT(IR_CONV, IRT_INTP), tr, (IRT_INTP<<5)|IRT_NUM|IRCONV_ANY);
+ /* Undefined overflow semantics allow stripping of ADDOV, SUBOV and MULOV. */
+ return narrow_stripov(J, tr, IR_MULOV,
+ LJ_64 ? ((IRT_INTP<<5)|IRT_INT|IRCONV_SEXT) :
+ ((IRT_INTP<<5)|IRT_INT|IRCONV_TOBIT));
+}
+#endif
+
+/* -- Narrowing of arithmetic operators ----------------------------------- */
+
+/* Check whether a number fits into an int32_t (-0 is ok, too). */
+static int numisint(lua_Number n)
+{
+ return (n == (lua_Number)lj_num2int(n));
+}
+
+/* Convert string to number. Error out for non-numeric string values. */
+static TRef conv_str_tonum(jit_State *J, TRef tr, TValue *o)
+{
+ if (tref_isstr(tr)) {
+ tr = emitir(IRTG(IR_STRTO, IRT_NUM), tr, 0);
+ /* Would need an inverted STRTO for this rare and useless case. */
+ if (!lj_strscan_num(strV(o), o)) /* Convert in-place. Value used below. */
+ lj_trace_err(J, LJ_TRERR_BADTYPE); /* Punt if non-numeric. */
+ }
+ return tr;
+}
+
+/* Narrowing of arithmetic operations. */
+TRef lj_opt_narrow_arith(jit_State *J, TRef rb, TRef rc,
+ TValue *vb, TValue *vc, IROp op)
+{
+ rb = conv_str_tonum(J, rb, vb);
+ rc = conv_str_tonum(J, rc, vc);
+ /* Must not narrow MUL in non-DUALNUM variant, because it loses -0. */
+ if ((op >= IR_ADD && op <= (LJ_DUALNUM ? IR_MUL : IR_SUB)) &&
+ tref_isinteger(rb) && tref_isinteger(rc) &&
+ numisint(lj_vm_foldarith(numberVnum(vb), numberVnum(vc),
+ (int)op - (int)IR_ADD)))
+ return emitir(IRTGI((int)op - (int)IR_ADD + (int)IR_ADDOV), rb, rc);
+ if (!tref_isnum(rb)) rb = emitir(IRTN(IR_CONV), rb, IRCONV_NUM_INT);
+ if (!tref_isnum(rc)) rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT);
+ return emitir(IRTN(op), rb, rc);
+}
+
+/* Narrowing of unary minus operator. */
+TRef lj_opt_narrow_unm(jit_State *J, TRef rc, TValue *vc)
+{
+ rc = conv_str_tonum(J, rc, vc);
+ if (tref_isinteger(rc)) {
+ if ((uint32_t)numberVint(vc) != 0x80000000u)
+ return emitir(IRTGI(IR_SUBOV), lj_ir_kint(J, 0), rc);
+ rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT);
+ }
+ return emitir(IRTN(IR_NEG), rc, lj_ir_knum_neg(J));
+}
+
+/* Narrowing of modulo operator. */
+TRef lj_opt_narrow_mod(jit_State *J, TRef rb, TRef rc, TValue *vb, TValue *vc)
+{
+ TRef tmp;
+ rb = conv_str_tonum(J, rb, vb);
+ rc = conv_str_tonum(J, rc, vc);
+ if ((LJ_DUALNUM || (J->flags & JIT_F_OPT_NARROW)) &&
+ tref_isinteger(rb) && tref_isinteger(rc) &&
+ (tvisint(vc) ? intV(vc) != 0 : !tviszero(vc))) {
+ emitir(IRTGI(IR_NE), rc, lj_ir_kint(J, 0));
+ return emitir(IRTI(IR_MOD), rb, rc);
+ }
+ /* b % c ==> b - floor(b/c)*c */
+ rb = lj_ir_tonum(J, rb);
+ rc = lj_ir_tonum(J, rc);
+ tmp = emitir(IRTN(IR_DIV), rb, rc);
+ tmp = emitir(IRTN(IR_FPMATH), tmp, IRFPM_FLOOR);
+ tmp = emitir(IRTN(IR_MUL), tmp, rc);
+ return emitir(IRTN(IR_SUB), rb, tmp);
+}
+
+/* Narrowing of power operator or math.pow. */
+TRef lj_opt_narrow_pow(jit_State *J, TRef rb, TRef rc, TValue *vb, TValue *vc)
+{
+ rb = conv_str_tonum(J, rb, vb);
+ rb = lj_ir_tonum(J, rb); /* Left arg is always treated as an FP number. */
+ rc = conv_str_tonum(J, rc, vc);
+ /* Narrowing must be unconditional to preserve (-x)^i semantics. */
+ if (tvisint(vc) || numisint(numV(vc))) {
+ int checkrange = 0;
+ /* Split pow is faster for bigger exponents. But do this only for (+k)^i. */
+ if (tref_isk(rb) && (int32_t)ir_knum(IR(tref_ref(rb)))->u32.hi >= 0) {
+ int32_t k = numberVint(vc);
+ if (!(k >= -65536 && k <= 65536)) goto split_pow;
+ checkrange = 1;
+ }
+ if (!tref_isinteger(rc)) {
+ /* Guarded conversion to integer! */
+ rc = emitir(IRTGI(IR_CONV), rc, IRCONV_INT_NUM|IRCONV_CHECK);
+ }
+ if (checkrange && !tref_isk(rc)) { /* Range guard: -65536 <= i <= 65536 */
+ TRef tmp = emitir(IRTI(IR_ADD), rc, lj_ir_kint(J, 65536));
+ emitir(IRTGI(IR_ULE), tmp, lj_ir_kint(J, 2*65536));
+ }
+ return emitir(IRTN(IR_POW), rb, rc);
+ }
+split_pow:
+ /* FOLD covers most cases, but some are easier to do here. */
+ if (tref_isk(rb) && tvispone(ir_knum(IR(tref_ref(rb)))))
+ return rb; /* 1 ^ x ==> 1 */
+ rc = lj_ir_tonum(J, rc);
+ if (tref_isk(rc) && ir_knum(IR(tref_ref(rc)))->n == 0.5)
+ return emitir(IRTN(IR_FPMATH), rb, IRFPM_SQRT); /* x ^ 0.5 ==> sqrt(x) */
+ /* Split up b^c into exp2(c*log2(b)). Assembler may rejoin later. */
+ rb = emitir(IRTN(IR_FPMATH), rb, IRFPM_LOG2);
+ rc = emitir(IRTN(IR_MUL), rb, rc);
+ return emitir(IRTN(IR_FPMATH), rc, IRFPM_EXP2);
+}
+
+/* -- Predictive narrowing of induction variables ------------------------- */
+
+/* Narrow a single runtime value. */
+static int narrow_forl(jit_State *J, cTValue *o)
+{
+ if (tvisint(o)) return 1;
+ if (LJ_DUALNUM || (J->flags & JIT_F_OPT_NARROW)) return numisint(numV(o));
+ return 0;
+}
+
+/* Narrow the FORL index type by looking at the runtime values. */
+IRType lj_opt_narrow_forl(jit_State *J, cTValue *tv)
+{
+ lua_assert(tvisnumber(&tv[FORL_IDX]) &&
+ tvisnumber(&tv[FORL_STOP]) &&
+ tvisnumber(&tv[FORL_STEP]));
+ /* Narrow only if the runtime values of start/stop/step are all integers. */
+ if (narrow_forl(J, &tv[FORL_IDX]) &&
+ narrow_forl(J, &tv[FORL_STOP]) &&
+ narrow_forl(J, &tv[FORL_STEP])) {
+ /* And if the loop index can't possibly overflow. */
+ lua_Number step = numberVnum(&tv[FORL_STEP]);
+ lua_Number sum = numberVnum(&tv[FORL_STOP]) + step;
+ if (0 <= step ? (sum <= 2147483647.0) : (sum >= -2147483648.0))
+ return IRT_INT;
+ }
+ return IRT_NUM;
+}
+
+#undef IR
+#undef fins
+#undef emitir
+#undef emitir_raw
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_sink.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_sink.c
new file mode 100644
index 0000000..4efe395
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_sink.c
@@ -0,0 +1,244 @@
+/*
+** SINK: Allocation Sinking and Store Sinking.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_opt_sink_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT
+
+#include "lj_ir.h"
+#include "lj_jit.h"
+#include "lj_iropt.h"
+#include "lj_target.h"
+
+/* Some local macros to save typing. Undef'd at the end. */
+#define IR(ref) (&J->cur.ir[(ref)])
+
+/* Check whether the store ref points to an eligible allocation. */
+static IRIns *sink_checkalloc(jit_State *J, IRIns *irs)
+{
+ IRIns *ir = IR(irs->op1);
+ if (!irref_isk(ir->op2))
+ return NULL; /* Non-constant key. */
+ if (ir->o == IR_HREFK || ir->o == IR_AREF)
+ ir = IR(ir->op1);
+ else if (!(ir->o == IR_HREF || ir->o == IR_NEWREF ||
+ ir->o == IR_FREF || ir->o == IR_ADD))
+ return NULL; /* Unhandled reference type (for XSTORE). */
+ ir = IR(ir->op1);
+ if (!(ir->o == IR_TNEW || ir->o == IR_TDUP || ir->o == IR_CNEW))
+ return NULL; /* Not an allocation. */
+ return ir; /* Return allocation. */
+}
+
+/* Recursively check whether a value depends on a PHI. */
+static int sink_phidep(jit_State *J, IRRef ref)
+{
+ IRIns *ir = IR(ref);
+ if (irt_isphi(ir->t)) return 1;
+ if (ir->op1 >= REF_FIRST && sink_phidep(J, ir->op1)) return 1;
+ if (ir->op2 >= REF_FIRST && sink_phidep(J, ir->op2)) return 1;
+ return 0;
+}
+
+/* Check whether a value is a sinkable PHI or loop-invariant. */
+static int sink_checkphi(jit_State *J, IRIns *ira, IRRef ref)
+{
+ if (ref >= REF_FIRST) {
+ IRIns *ir = IR(ref);
+ if (irt_isphi(ir->t) || (ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT &&
+ irt_isphi(IR(ir->op1)->t))) {
+ ira->prev++;
+ return 1; /* Sinkable PHI. */
+ }
+ /* Otherwise the value must be loop-invariant. */
+ return ref < J->loopref && !sink_phidep(J, ref);
+ }
+ return 1; /* Constant (non-PHI). */
+}
+
+/* Mark non-sinkable allocations using single-pass backward propagation.
+**
+** Roots for the marking process are:
+** - Some PHIs or snapshots (see below).
+** - Non-PHI, non-constant values stored to PHI allocations.
+** - All guards.
+** - Any remaining loads not eliminated by store-to-load forwarding.
+** - Stores with non-constant keys.
+** - All stored values.
+*/
+static void sink_mark_ins(jit_State *J)
+{
+ IRIns *ir, *irlast = IR(J->cur.nins-1);
+ for (ir = irlast ; ; ir--) {
+ switch (ir->o) {
+ case IR_BASE:
+ return; /* Finished. */
+ case IR_CALLL: /* IRCALL_lj_tab_len */
+ case IR_ALOAD: case IR_HLOAD: case IR_XLOAD: case IR_TBAR:
+ irt_setmark(IR(ir->op1)->t); /* Mark ref for remaining loads. */
+ break;
+ case IR_FLOAD:
+ if (irt_ismarked(ir->t) || ir->op2 == IRFL_TAB_META)
+ irt_setmark(IR(ir->op1)->t); /* Mark table for remaining loads. */
+ break;
+ case IR_ASTORE: case IR_HSTORE: case IR_FSTORE: case IR_XSTORE: {
+ IRIns *ira = sink_checkalloc(J, ir);
+ if (!ira || (irt_isphi(ira->t) && !sink_checkphi(J, ira, ir->op2)))
+ irt_setmark(IR(ir->op1)->t); /* Mark ineligible ref. */
+ irt_setmark(IR(ir->op2)->t); /* Mark stored value. */
+ break;
+ }
+#if LJ_HASFFI
+ case IR_CNEWI:
+ if (irt_isphi(ir->t) &&
+ (!sink_checkphi(J, ir, ir->op2) ||
+ (LJ_32 && ir+1 < irlast && (ir+1)->o == IR_HIOP &&
+ !sink_checkphi(J, ir, (ir+1)->op2))))
+ irt_setmark(ir->t); /* Mark ineligible allocation. */
+#endif
+ /* fallthrough */
+ case IR_USTORE:
+ irt_setmark(IR(ir->op2)->t); /* Mark stored value. */
+ break;
+#if LJ_HASFFI
+ case IR_CALLXS:
+#endif
+ case IR_CALLS:
+ irt_setmark(IR(ir->op1)->t); /* Mark (potentially) stored values. */
+ break;
+ case IR_PHI: {
+ IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);
+ irl->prev = irr->prev = 0; /* Clear PHI value counts. */
+ if (irl->o == irr->o &&
+ (irl->o == IR_TNEW || irl->o == IR_TDUP ||
+ (LJ_HASFFI && (irl->o == IR_CNEW || irl->o == IR_CNEWI))))
+ break;
+ irt_setmark(irl->t);
+ irt_setmark(irr->t);
+ break;
+ }
+ default:
+ if (irt_ismarked(ir->t) || irt_isguard(ir->t)) { /* Propagate mark. */
+ if (ir->op1 >= REF_FIRST) irt_setmark(IR(ir->op1)->t);
+ if (ir->op2 >= REF_FIRST) irt_setmark(IR(ir->op2)->t);
+ }
+ break;
+ }
+ }
+}
+
+/* Mark all instructions referenced by a snapshot. */
+static void sink_mark_snap(jit_State *J, SnapShot *snap)
+{
+ SnapEntry *map = &J->cur.snapmap[snap->mapofs];
+ MSize n, nent = snap->nent;
+ for (n = 0; n < nent; n++) {
+ IRRef ref = snap_ref(map[n]);
+ if (!irref_isk(ref))
+ irt_setmark(IR(ref)->t);
+ }
+}
+
+/* Iteratively remark PHI refs with differing marks or PHI value counts. */
+static void sink_remark_phi(jit_State *J)
+{
+ IRIns *ir;
+ int remark;
+ do {
+ remark = 0;
+ for (ir = IR(J->cur.nins-1); ir->o == IR_PHI; ir--) {
+ IRIns *irl = IR(ir->op1), *irr = IR(ir->op2);
+ if (!((irl->t.irt ^ irr->t.irt) & IRT_MARK) && irl->prev == irr->prev)
+ continue;
+ remark |= (~(irl->t.irt & irr->t.irt) & IRT_MARK);
+ irt_setmark(IR(ir->op1)->t);
+ irt_setmark(IR(ir->op2)->t);
+ }
+ } while (remark);
+}
+
+/* Sweep instructions and tag sunken allocations and stores. */
+static void sink_sweep_ins(jit_State *J)
+{
+ IRIns *ir, *irfirst = IR(J->cur.nk);
+ for (ir = IR(J->cur.nins-1) ; ir >= irfirst; ir--) {
+ switch (ir->o) {
+ case IR_ASTORE: case IR_HSTORE: case IR_FSTORE: case IR_XSTORE: {
+ IRIns *ira = sink_checkalloc(J, ir);
+ if (ira && !irt_ismarked(ira->t)) {
+ int delta = (int)(ir - ira);
+ ir->prev = REGSP(RID_SINK, delta > 255 ? 255 : delta);
+ } else {
+ ir->prev = REGSP_INIT;
+ }
+ break;
+ }
+ case IR_NEWREF:
+ if (!irt_ismarked(IR(ir->op1)->t)) {
+ ir->prev = REGSP(RID_SINK, 0);
+ } else {
+ irt_clearmark(ir->t);
+ ir->prev = REGSP_INIT;
+ }
+ break;
+#if LJ_HASFFI
+ case IR_CNEW: case IR_CNEWI:
+#endif
+ case IR_TNEW: case IR_TDUP:
+ if (!irt_ismarked(ir->t)) {
+ ir->t.irt &= ~IRT_GUARD;
+ ir->prev = REGSP(RID_SINK, 0);
+ J->cur.sinktags = 1; /* Signal present SINK tags to assembler. */
+ } else {
+ irt_clearmark(ir->t);
+ ir->prev = REGSP_INIT;
+ }
+ break;
+ case IR_PHI: {
+ IRIns *ira = IR(ir->op2);
+ if (!irt_ismarked(ira->t) &&
+ (ira->o == IR_TNEW || ira->o == IR_TDUP ||
+ (LJ_HASFFI && (ira->o == IR_CNEW || ira->o == IR_CNEWI)))) {
+ ir->prev = REGSP(RID_SINK, 0);
+ } else {
+ ir->prev = REGSP_INIT;
+ }
+ break;
+ }
+ default:
+ irt_clearmark(ir->t);
+ ir->prev = REGSP_INIT;
+ break;
+ }
+ }
+}
+
+/* Allocation sinking and store sinking.
+**
+** 1. Mark all non-sinkable allocations.
+** 2. Then sink all remaining allocations and the related stores.
+*/
+void lj_opt_sink(jit_State *J)
+{
+ const uint32_t need = (JIT_F_OPT_SINK|JIT_F_OPT_FWD|
+ JIT_F_OPT_DCE|JIT_F_OPT_CSE|JIT_F_OPT_FOLD);
+ if ((J->flags & need) == need &&
+ (J->chain[IR_TNEW] || J->chain[IR_TDUP] ||
+ (LJ_HASFFI && (J->chain[IR_CNEW] || J->chain[IR_CNEWI])))) {
+ if (!J->loopref)
+ sink_mark_snap(J, &J->cur.snap[J->cur.nsnap-1]);
+ sink_mark_ins(J);
+ if (J->loopref)
+ sink_remark_phi(J);
+ sink_sweep_ins(J);
+ }
+}
+
+#undef IR
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_split.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_split.c
new file mode 100644
index 0000000..8d7cd4c
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_opt_split.c
@@ -0,0 +1,732 @@
+/*
+** SPLIT: Split 64 bit IR instructions into 32 bit IR instructions.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_opt_split_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT && (LJ_SOFTFP || (LJ_32 && LJ_HASFFI))
+
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_ir.h"
+#include "lj_jit.h"
+#include "lj_ircall.h"
+#include "lj_iropt.h"
+#include "lj_vm.h"
+
+/* SPLIT pass:
+**
+** This pass splits up 64 bit IR instructions into multiple 32 bit IR
+** instructions. It's only active for soft-float targets or for 32 bit CPUs
+** which lack native 64 bit integer operations (the FFI is currently the
+** only emitter for 64 bit integer instructions).
+**
+** Splitting the IR in a separate pass keeps each 32 bit IR assembler
+** backend simple. Only a small amount of extra functionality needs to be
+** implemented. This is much easier than adding support for allocating
+** register pairs to each backend (believe me, I tried). A few simple, but
+** important optimizations can be performed by the SPLIT pass, which would
+** be tedious to do in the backend.
+**
+** The basic idea is to replace each 64 bit IR instruction with its 32 bit
+** equivalent plus an extra HIOP instruction. The splitted IR is not passed
+** through FOLD or any other optimizations, so each HIOP is guaranteed to
+** immediately follow it's counterpart. The actual functionality of HIOP is
+** inferred from the previous instruction.
+**
+** The operands of HIOP hold the hiword input references. The output of HIOP
+** is the hiword output reference, which is also used to hold the hiword
+** register or spill slot information. The register allocator treats this
+** instruction independently of any other instruction, which improves code
+** quality compared to using fixed register pairs.
+**
+** It's easier to split up some instructions into two regular 32 bit
+** instructions. E.g. XLOAD is split up into two XLOADs with two different
+** addresses. Obviously 64 bit constants need to be split up into two 32 bit
+** constants, too. Some hiword instructions can be entirely omitted, e.g.
+** when zero-extending a 32 bit value to 64 bits. 64 bit arguments for calls
+** are split up into two 32 bit arguments each.
+**
+** On soft-float targets, floating-point instructions are directly converted
+** to soft-float calls by the SPLIT pass (except for comparisons and MIN/MAX).
+** HIOP for number results has the type IRT_SOFTFP ("sfp" in -jdump).
+**
+** Here's the IR and x64 machine code for 'x.b = x.a + 1' for a struct with
+** two int64_t fields:
+**
+** 0100 p32 ADD base +8
+** 0101 i64 XLOAD 0100
+** 0102 i64 ADD 0101 +1
+** 0103 p32 ADD base +16
+** 0104 i64 XSTORE 0103 0102
+**
+** mov rax, [esi+0x8]
+** add rax, +0x01
+** mov [esi+0x10], rax
+**
+** Here's the transformed IR and the x86 machine code after the SPLIT pass:
+**
+** 0100 p32 ADD base +8
+** 0101 int XLOAD 0100
+** 0102 p32 ADD base +12
+** 0103 int XLOAD 0102
+** 0104 int ADD 0101 +1
+** 0105 int HIOP 0103 +0
+** 0106 p32 ADD base +16
+** 0107 int XSTORE 0106 0104
+** 0108 int HIOP 0106 0105
+**
+** mov eax, [esi+0x8]
+** mov ecx, [esi+0xc]
+** add eax, +0x01
+** adc ecx, +0x00
+** mov [esi+0x10], eax
+** mov [esi+0x14], ecx
+**
+** You may notice the reassociated hiword address computation, which is
+** later fused into the mov operands by the assembler.
+*/
+
+/* Some local macros to save typing. Undef'd at the end. */
+#define IR(ref) (&J->cur.ir[(ref)])
+
+/* Directly emit the transformed IR without updating chains etc. */
+static IRRef split_emit(jit_State *J, uint16_t ot, IRRef1 op1, IRRef1 op2)
+{
+ IRRef nref = lj_ir_nextins(J);
+ IRIns *ir = IR(nref);
+ ir->ot = ot;
+ ir->op1 = op1;
+ ir->op2 = op2;
+ return nref;
+}
+
+#if LJ_SOFTFP
+/* Emit a (checked) number to integer conversion. */
+static IRRef split_num2int(jit_State *J, IRRef lo, IRRef hi, int check)
+{
+ IRRef tmp, res;
+#if LJ_LE
+ tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), lo, hi);
+#else
+ tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hi, lo);
+#endif
+ res = split_emit(J, IRTI(IR_CALLN), tmp, IRCALL_softfp_d2i);
+ if (check) {
+ tmp = split_emit(J, IRTI(IR_CALLN), res, IRCALL_softfp_i2d);
+ split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp);
+ split_emit(J, IRTGI(IR_EQ), tmp, lo);
+ split_emit(J, IRTG(IR_HIOP, IRT_SOFTFP), tmp+1, hi);
+ }
+ return res;
+}
+
+/* Emit a CALLN with one split 64 bit argument. */
+static IRRef split_call_l(jit_State *J, IRRef1 *hisubst, IRIns *oir,
+ IRIns *ir, IRCallID id)
+{
+ IRRef tmp, op1 = ir->op1;
+ J->cur.nins--;
+#if LJ_LE
+ tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]);
+#else
+ tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev);
+#endif
+ ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, id);
+ return split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp);
+}
+
+/* Emit a CALLN with one split 64 bit argument and a 32 bit argument. */
+static IRRef split_call_li(jit_State *J, IRRef1 *hisubst, IRIns *oir,
+ IRIns *ir, IRCallID id)
+{
+ IRRef tmp, op1 = ir->op1, op2 = ir->op2;
+ J->cur.nins--;
+#if LJ_LE
+ tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]);
+#else
+ tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev);
+#endif
+ tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, oir[op2].prev);
+ ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, id);
+ return split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp);
+}
+#endif
+
+/* Emit a CALLN with two split 64 bit arguments. */
+static IRRef split_call_ll(jit_State *J, IRRef1 *hisubst, IRIns *oir,
+ IRIns *ir, IRCallID id)
+{
+ IRRef tmp, op1 = ir->op1, op2 = ir->op2;
+ J->cur.nins--;
+#if LJ_LE
+ tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]);
+ tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, oir[op2].prev);
+ tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, hisubst[op2]);
+#else
+ tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev);
+ tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, hisubst[op2]);
+ tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, oir[op2].prev);
+#endif
+ ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, id);
+ return split_emit(J,
+ IRT(IR_HIOP, (LJ_SOFTFP && irt_isnum(ir->t)) ? IRT_SOFTFP : IRT_INT),
+ tmp, tmp);
+}
+
+/* Get a pointer to the other 32 bit word (LE: hiword, BE: loword). */
+static IRRef split_ptr(jit_State *J, IRIns *oir, IRRef ref)
+{
+ IRRef nref = oir[ref].prev;
+ IRIns *ir = IR(nref);
+ int32_t ofs = 4;
+ if (ir->o == IR_KPTR)
+ return lj_ir_kptr(J, (char *)ir_kptr(ir) + ofs);
+ if (ir->o == IR_ADD && irref_isk(ir->op2) && !irt_isphi(oir[ref].t)) {
+ /* Reassociate address. */
+ ofs += IR(ir->op2)->i;
+ nref = ir->op1;
+ if (ofs == 0) return nref;
+ }
+ return split_emit(J, IRTI(IR_ADD), nref, lj_ir_kint(J, ofs));
+}
+
+/* Substitute references of a snapshot. */
+static void split_subst_snap(jit_State *J, SnapShot *snap, IRIns *oir)
+{
+ SnapEntry *map = &J->cur.snapmap[snap->mapofs];
+ MSize n, nent = snap->nent;
+ for (n = 0; n < nent; n++) {
+ SnapEntry sn = map[n];
+ IRIns *ir = &oir[snap_ref(sn)];
+ if (!(LJ_SOFTFP && (sn & SNAP_SOFTFPNUM) && irref_isk(snap_ref(sn))))
+ map[n] = ((sn & 0xffff0000) | ir->prev);
+ }
+}
+
+/* Transform the old IR to the new IR. */
+static void split_ir(jit_State *J)
+{
+ IRRef nins = J->cur.nins, nk = J->cur.nk;
+ MSize irlen = nins - nk;
+ MSize need = (irlen+1)*(sizeof(IRIns) + sizeof(IRRef1));
+ IRIns *oir = (IRIns *)lj_str_needbuf(J->L, &G(J->L)->tmpbuf, need);
+ IRRef1 *hisubst;
+ IRRef ref, snref;
+ SnapShot *snap;
+
+ /* Copy old IR to buffer. */
+ memcpy(oir, IR(nk), irlen*sizeof(IRIns));
+ /* Bias hiword substitution table and old IR. Loword kept in field prev. */
+ hisubst = (IRRef1 *)&oir[irlen] - nk;
+ oir -= nk;
+
+ /* Remove all IR instructions, but retain IR constants. */
+ J->cur.nins = REF_FIRST;
+ J->loopref = 0;
+
+ /* Process constants and fixed references. */
+ for (ref = nk; ref <= REF_BASE; ref++) {
+ IRIns *ir = &oir[ref];
+ if ((LJ_SOFTFP && ir->o == IR_KNUM) || ir->o == IR_KINT64) {
+ /* Split up 64 bit constant. */
+ TValue tv = *ir_k64(ir);
+ ir->prev = lj_ir_kint(J, (int32_t)tv.u32.lo);
+ hisubst[ref] = lj_ir_kint(J, (int32_t)tv.u32.hi);
+ } else {
+ ir->prev = ref; /* Identity substitution for loword. */
+ hisubst[ref] = 0;
+ }
+ }
+
+ /* Process old IR instructions. */
+ snap = J->cur.snap;
+ snref = snap->ref;
+ for (ref = REF_FIRST; ref < nins; ref++) {
+ IRIns *ir = &oir[ref];
+ IRRef nref = lj_ir_nextins(J);
+ IRIns *nir = IR(nref);
+ IRRef hi = 0;
+
+ if (ref >= snref) {
+ snap->ref = nref;
+ split_subst_snap(J, snap++, oir);
+ snref = snap < &J->cur.snap[J->cur.nsnap] ? snap->ref : ~(IRRef)0;
+ }
+
+ /* Copy-substitute old instruction to new instruction. */
+ nir->op1 = ir->op1 < nk ? ir->op1 : oir[ir->op1].prev;
+ nir->op2 = ir->op2 < nk ? ir->op2 : oir[ir->op2].prev;
+ ir->prev = nref; /* Loword substitution. */
+ nir->o = ir->o;
+ nir->t.irt = ir->t.irt & ~(IRT_MARK|IRT_ISPHI);
+ hisubst[ref] = 0;
+
+ /* Split 64 bit instructions. */
+#if LJ_SOFTFP
+ if (irt_isnum(ir->t)) {
+ nir->t.irt = IRT_INT | (nir->t.irt & IRT_GUARD); /* Turn into INT op. */
+ /* Note: hi ref = lo ref + 1! Required for SNAP_SOFTFPNUM logic. */
+ switch (ir->o) {
+ case IR_ADD:
+ hi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_add);
+ break;
+ case IR_SUB:
+ hi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_sub);
+ break;
+ case IR_MUL:
+ hi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_mul);
+ break;
+ case IR_DIV:
+ hi = split_call_ll(J, hisubst, oir, ir, IRCALL_softfp_div);
+ break;
+ case IR_POW:
+ hi = split_call_li(J, hisubst, oir, ir, IRCALL_lj_vm_powi);
+ break;
+ case IR_FPMATH:
+ /* Try to rejoin pow from EXP2, MUL and LOG2. */
+ if (nir->op2 == IRFPM_EXP2 && nir->op1 > J->loopref) {
+ IRIns *irp = IR(nir->op1);
+ if (irp->o == IR_CALLN && irp->op2 == IRCALL_softfp_mul) {
+ IRIns *irm4 = IR(irp->op1);
+ IRIns *irm3 = IR(irm4->op1);
+ IRIns *irm12 = IR(irm3->op1);
+ IRIns *irl1 = IR(irm12->op1);
+ if (irm12->op1 > J->loopref && irl1->o == IR_CALLN &&
+ irl1->op2 == IRCALL_lj_vm_log2) {
+ IRRef tmp = irl1->op1; /* Recycle first two args from LOG2. */
+ IRRef arg3 = irm3->op2, arg4 = irm4->op2;
+ J->cur.nins--;
+ tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, arg3);
+ tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), tmp, arg4);
+ ir->prev = tmp = split_emit(J, IRTI(IR_CALLN), tmp, IRCALL_pow);
+ hi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), tmp, tmp);
+ break;
+ }
+ }
+ }
+ hi = split_call_l(J, hisubst, oir, ir, IRCALL_lj_vm_floor + ir->op2);
+ break;
+ case IR_ATAN2:
+ hi = split_call_ll(J, hisubst, oir, ir, IRCALL_atan2);
+ break;
+ case IR_LDEXP:
+ hi = split_call_li(J, hisubst, oir, ir, IRCALL_ldexp);
+ break;
+ case IR_NEG: case IR_ABS:
+ nir->o = IR_CONV; /* Pass through loword. */
+ nir->op2 = (IRT_INT << 5) | IRT_INT;
+ hi = split_emit(J, IRT(ir->o == IR_NEG ? IR_BXOR : IR_BAND, IRT_SOFTFP),
+ hisubst[ir->op1], hisubst[ir->op2]);
+ break;
+ case IR_SLOAD:
+ if ((nir->op2 & IRSLOAD_CONVERT)) { /* Convert from int to number. */
+ nir->op2 &= ~IRSLOAD_CONVERT;
+ ir->prev = nref = split_emit(J, IRTI(IR_CALLN), nref,
+ IRCALL_softfp_i2d);
+ hi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref);
+ break;
+ }
+ /* fallthrough */
+ case IR_ALOAD: case IR_HLOAD: case IR_ULOAD: case IR_VLOAD:
+ case IR_STRTO:
+ hi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref);
+ break;
+ case IR_XLOAD: {
+ IRIns inslo = *nir; /* Save/undo the emit of the lo XLOAD. */
+ J->cur.nins--;
+ hi = split_ptr(J, oir, ir->op1); /* Insert the hiref ADD. */
+ nref = lj_ir_nextins(J);
+ nir = IR(nref);
+ *nir = inslo; /* Re-emit lo XLOAD immediately before hi XLOAD. */
+ hi = split_emit(J, IRT(IR_XLOAD, IRT_SOFTFP), hi, ir->op2);
+#if LJ_LE
+ ir->prev = nref;
+#else
+ ir->prev = hi; hi = nref;
+#endif
+ break;
+ }
+ case IR_ASTORE: case IR_HSTORE: case IR_USTORE: case IR_XSTORE:
+ split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nir->op1, hisubst[ir->op2]);
+ break;
+ case IR_CONV: { /* Conversion to number. Others handled below. */
+ IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);
+ UNUSED(st);
+#if LJ_32 && LJ_HASFFI
+ if (st == IRT_I64 || st == IRT_U64) {
+ hi = split_call_l(J, hisubst, oir, ir,
+ st == IRT_I64 ? IRCALL_fp64_l2d : IRCALL_fp64_ul2d);
+ break;
+ }
+#endif
+ lua_assert(st == IRT_INT ||
+ (LJ_32 && LJ_HASFFI && (st == IRT_U32 || st == IRT_FLOAT)));
+ nir->o = IR_CALLN;
+#if LJ_32 && LJ_HASFFI
+ nir->op2 = st == IRT_INT ? IRCALL_softfp_i2d :
+ st == IRT_FLOAT ? IRCALL_softfp_f2d :
+ IRCALL_softfp_ui2d;
+#else
+ nir->op2 = IRCALL_softfp_i2d;
+#endif
+ hi = split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref);
+ break;
+ }
+ case IR_CALLN:
+ case IR_CALLL:
+ case IR_CALLS:
+ case IR_CALLXS:
+ goto split_call;
+ case IR_PHI:
+ if (nir->op1 == nir->op2)
+ J->cur.nins--; /* Drop useless PHIs. */
+ if (hisubst[ir->op1] != hisubst[ir->op2])
+ split_emit(J, IRT(IR_PHI, IRT_SOFTFP),
+ hisubst[ir->op1], hisubst[ir->op2]);
+ break;
+ case IR_HIOP:
+ J->cur.nins--; /* Drop joining HIOP. */
+ ir->prev = nir->op1;
+ hi = nir->op2;
+ break;
+ default:
+ lua_assert(ir->o <= IR_NE || ir->o == IR_MIN || ir->o == IR_MAX);
+ hi = split_emit(J, IRTG(IR_HIOP, IRT_SOFTFP),
+ hisubst[ir->op1], hisubst[ir->op2]);
+ break;
+ }
+ } else
+#endif
+#if LJ_32 && LJ_HASFFI
+ if (irt_isint64(ir->t)) {
+ IRRef hiref = hisubst[ir->op1];
+ nir->t.irt = IRT_INT | (nir->t.irt & IRT_GUARD); /* Turn into INT op. */
+ switch (ir->o) {
+ case IR_ADD:
+ case IR_SUB:
+ /* Use plain op for hiword if loword cannot produce a carry/borrow. */
+ if (irref_isk(nir->op2) && IR(nir->op2)->i == 0) {
+ ir->prev = nir->op1; /* Pass through loword. */
+ nir->op1 = hiref; nir->op2 = hisubst[ir->op2];
+ hi = nref;
+ break;
+ }
+ /* fallthrough */
+ case IR_NEG:
+ hi = split_emit(J, IRTI(IR_HIOP), hiref, hisubst[ir->op2]);
+ break;
+ case IR_MUL:
+ hi = split_call_ll(J, hisubst, oir, ir, IRCALL_lj_carith_mul64);
+ break;
+ case IR_DIV:
+ hi = split_call_ll(J, hisubst, oir, ir,
+ irt_isi64(ir->t) ? IRCALL_lj_carith_divi64 :
+ IRCALL_lj_carith_divu64);
+ break;
+ case IR_MOD:
+ hi = split_call_ll(J, hisubst, oir, ir,
+ irt_isi64(ir->t) ? IRCALL_lj_carith_modi64 :
+ IRCALL_lj_carith_modu64);
+ break;
+ case IR_POW:
+ hi = split_call_ll(J, hisubst, oir, ir,
+ irt_isi64(ir->t) ? IRCALL_lj_carith_powi64 :
+ IRCALL_lj_carith_powu64);
+ break;
+ case IR_FLOAD:
+ lua_assert(ir->op2 == IRFL_CDATA_INT64);
+ hi = split_emit(J, IRTI(IR_FLOAD), nir->op1, IRFL_CDATA_INT64_4);
+#if LJ_BE
+ ir->prev = hi; hi = nref;
+#endif
+ break;
+ case IR_XLOAD:
+ hi = split_emit(J, IRTI(IR_XLOAD), split_ptr(J, oir, ir->op1), ir->op2);
+#if LJ_BE
+ ir->prev = hi; hi = nref;
+#endif
+ break;
+ case IR_XSTORE:
+ split_emit(J, IRTI(IR_HIOP), nir->op1, hisubst[ir->op2]);
+ break;
+ case IR_CONV: { /* Conversion to 64 bit integer. Others handled below. */
+ IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);
+#if LJ_SOFTFP
+ if (st == IRT_NUM) { /* NUM to 64 bit int conv. */
+ hi = split_call_l(J, hisubst, oir, ir,
+ irt_isi64(ir->t) ? IRCALL_fp64_d2l : IRCALL_fp64_d2ul);
+ } else if (st == IRT_FLOAT) { /* FLOAT to 64 bit int conv. */
+ nir->o = IR_CALLN;
+ nir->op2 = irt_isi64(ir->t) ? IRCALL_fp64_f2l : IRCALL_fp64_f2ul;
+ hi = split_emit(J, IRTI(IR_HIOP), nref, nref);
+ }
+#else
+ if (st == IRT_NUM || st == IRT_FLOAT) { /* FP to 64 bit int conv. */
+ hi = split_emit(J, IRTI(IR_HIOP), nir->op1, nref);
+ }
+#endif
+ else if (st == IRT_I64 || st == IRT_U64) { /* 64/64 bit cast. */
+ /* Drop cast, since assembler doesn't care. But fwd both parts. */
+ hi = hiref;
+ goto fwdlo;
+ } else if ((ir->op2 & IRCONV_SEXT)) { /* Sign-extend to 64 bit. */
+ IRRef k31 = lj_ir_kint(J, 31);
+ nir = IR(nref); /* May have been reallocated. */
+ ir->prev = nir->op1; /* Pass through loword. */
+ nir->o = IR_BSAR; /* hi = bsar(lo, 31). */
+ nir->op2 = k31;
+ hi = nref;
+ } else { /* Zero-extend to 64 bit. */
+ hi = lj_ir_kint(J, 0);
+ goto fwdlo;
+ }
+ break;
+ }
+ case IR_CALLXS:
+ goto split_call;
+ case IR_PHI: {
+ IRRef hiref2;
+ if ((irref_isk(nir->op1) && irref_isk(nir->op2)) ||
+ nir->op1 == nir->op2)
+ J->cur.nins--; /* Drop useless PHIs. */
+ hiref2 = hisubst[ir->op2];
+ if (!((irref_isk(hiref) && irref_isk(hiref2)) || hiref == hiref2))
+ split_emit(J, IRTI(IR_PHI), hiref, hiref2);
+ break;
+ }
+ case IR_HIOP:
+ J->cur.nins--; /* Drop joining HIOP. */
+ ir->prev = nir->op1;
+ hi = nir->op2;
+ break;
+ default:
+ lua_assert(ir->o <= IR_NE); /* Comparisons. */
+ split_emit(J, IRTGI(IR_HIOP), hiref, hisubst[ir->op2]);
+ break;
+ }
+ } else
+#endif
+#if LJ_SOFTFP
+ if (ir->o == IR_SLOAD) {
+ if ((nir->op2 & IRSLOAD_CONVERT)) { /* Convert from number to int. */
+ nir->op2 &= ~IRSLOAD_CONVERT;
+ if (!(nir->op2 & IRSLOAD_TYPECHECK))
+ nir->t.irt = IRT_INT; /* Drop guard. */
+ split_emit(J, IRT(IR_HIOP, IRT_SOFTFP), nref, nref);
+ ir->prev = split_num2int(J, nref, nref+1, irt_isguard(ir->t));
+ }
+ } else if (ir->o == IR_TOBIT) {
+ IRRef tmp, op1 = ir->op1;
+ J->cur.nins--;
+#if LJ_LE
+ tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), oir[op1].prev, hisubst[op1]);
+#else
+ tmp = split_emit(J, IRT(IR_CARG, IRT_NIL), hisubst[op1], oir[op1].prev);
+#endif
+ ir->prev = split_emit(J, IRTI(IR_CALLN), tmp, IRCALL_lj_vm_tobit);
+ } else if (ir->o == IR_TOSTR) {
+ if (hisubst[ir->op1]) {
+ if (irref_isk(ir->op1))
+ nir->op1 = ir->op1;
+ else
+ split_emit(J, IRT(IR_HIOP, IRT_NIL), hisubst[ir->op1], nref);
+ }
+ } else if (ir->o == IR_HREF || ir->o == IR_NEWREF) {
+ if (irref_isk(ir->op2) && hisubst[ir->op2])
+ nir->op2 = ir->op2;
+ } else
+#endif
+ if (ir->o == IR_CONV) { /* See above, too. */
+ IRType st = (IRType)(ir->op2 & IRCONV_SRCMASK);
+#if LJ_32 && LJ_HASFFI
+ if (st == IRT_I64 || st == IRT_U64) { /* Conversion from 64 bit int. */
+#if LJ_SOFTFP
+ if (irt_isfloat(ir->t)) {
+ split_call_l(J, hisubst, oir, ir,
+ st == IRT_I64 ? IRCALL_fp64_l2f : IRCALL_fp64_ul2f);
+ J->cur.nins--; /* Drop unused HIOP. */
+ }
+#else
+ if (irt_isfp(ir->t)) { /* 64 bit integer to FP conversion. */
+ ir->prev = split_emit(J, IRT(IR_HIOP, irt_type(ir->t)),
+ hisubst[ir->op1], nref);
+ }
+#endif
+ else { /* Truncate to lower 32 bits. */
+ fwdlo:
+ ir->prev = nir->op1; /* Forward loword. */
+ /* Replace with NOP to avoid messing up the snapshot logic. */
+ nir->ot = IRT(IR_NOP, IRT_NIL);
+ nir->op1 = nir->op2 = 0;
+ }
+ }
+#endif
+#if LJ_SOFTFP && LJ_32 && LJ_HASFFI
+ else if (irt_isfloat(ir->t)) {
+ if (st == IRT_NUM) {
+ split_call_l(J, hisubst, oir, ir, IRCALL_softfp_d2f);
+ J->cur.nins--; /* Drop unused HIOP. */
+ } else {
+ nir->o = IR_CALLN;
+ nir->op2 = st == IRT_INT ? IRCALL_softfp_i2f : IRCALL_softfp_ui2f;
+ }
+ } else if (st == IRT_FLOAT) {
+ nir->o = IR_CALLN;
+ nir->op2 = irt_isint(ir->t) ? IRCALL_softfp_f2i : IRCALL_softfp_f2ui;
+ } else
+#endif
+#if LJ_SOFTFP
+ if (st == IRT_NUM || (LJ_32 && LJ_HASFFI && st == IRT_FLOAT)) {
+ if (irt_isguard(ir->t)) {
+ lua_assert(st == IRT_NUM && irt_isint(ir->t));
+ J->cur.nins--;
+ ir->prev = split_num2int(J, nir->op1, hisubst[ir->op1], 1);
+ } else {
+ split_call_l(J, hisubst, oir, ir,
+#if LJ_32 && LJ_HASFFI
+ st == IRT_NUM ?
+ (irt_isint(ir->t) ? IRCALL_softfp_d2i : IRCALL_softfp_d2ui) :
+ (irt_isint(ir->t) ? IRCALL_softfp_f2i : IRCALL_softfp_f2ui)
+#else
+ IRCALL_softfp_d2i
+#endif
+ );
+ J->cur.nins--; /* Drop unused HIOP. */
+ }
+ }
+#endif
+ } else if (ir->o == IR_CALLXS) {
+ IRRef hiref;
+ split_call:
+ hiref = hisubst[ir->op1];
+ if (hiref) {
+ IROpT ot = nir->ot;
+ IRRef op2 = nir->op2;
+ nir->ot = IRT(IR_CARG, IRT_NIL);
+#if LJ_LE
+ nir->op2 = hiref;
+#else
+ nir->op2 = nir->op1; nir->op1 = hiref;
+#endif
+ ir->prev = nref = split_emit(J, ot, nref, op2);
+ }
+ if (LJ_SOFTFP ? irt_is64(ir->t) : irt_isint64(ir->t))
+ hi = split_emit(J,
+ IRT(IR_HIOP, (LJ_SOFTFP && irt_isnum(ir->t)) ? IRT_SOFTFP : IRT_INT),
+ nref, nref);
+ } else if (ir->o == IR_CARG) {
+ IRRef hiref = hisubst[ir->op1];
+ if (hiref) {
+ IRRef op2 = nir->op2;
+#if LJ_LE
+ nir->op2 = hiref;
+#else
+ nir->op2 = nir->op1; nir->op1 = hiref;
+#endif
+ ir->prev = nref = split_emit(J, IRT(IR_CARG, IRT_NIL), nref, op2);
+ nir = IR(nref);
+ }
+ hiref = hisubst[ir->op2];
+ if (hiref) {
+#if !LJ_TARGET_X86
+ int carg = 0;
+ IRIns *cir;
+ for (cir = IR(nir->op1); cir->o == IR_CARG; cir = IR(cir->op1))
+ carg++;
+ if ((carg & 1) == 0) { /* Align 64 bit arguments. */
+ IRRef op2 = nir->op2;
+ nir->op2 = REF_NIL;
+ nref = split_emit(J, IRT(IR_CARG, IRT_NIL), nref, op2);
+ nir = IR(nref);
+ }
+#endif
+#if LJ_BE
+ { IRRef tmp = nir->op2; nir->op2 = hiref; hiref = tmp; }
+#endif
+ ir->prev = split_emit(J, IRT(IR_CARG, IRT_NIL), nref, hiref);
+ }
+ } else if (ir->o == IR_CNEWI) {
+ if (hisubst[ir->op2])
+ split_emit(J, IRT(IR_HIOP, IRT_NIL), nref, hisubst[ir->op2]);
+ } else if (ir->o == IR_LOOP) {
+ J->loopref = nref; /* Needed by assembler. */
+ }
+ hisubst[ref] = hi; /* Store hiword substitution. */
+ }
+ if (snref == nins) { /* Substitution for last snapshot. */
+ snap->ref = J->cur.nins;
+ split_subst_snap(J, snap, oir);
+ }
+
+ /* Add PHI marks. */
+ for (ref = J->cur.nins-1; ref >= REF_FIRST; ref--) {
+ IRIns *ir = IR(ref);
+ if (ir->o != IR_PHI) break;
+ if (!irref_isk(ir->op1)) irt_setphi(IR(ir->op1)->t);
+ if (ir->op2 > J->loopref) irt_setphi(IR(ir->op2)->t);
+ }
+}
+
+/* Protected callback for split pass. */
+static TValue *cpsplit(lua_State *L, lua_CFunction dummy, void *ud)
+{
+ jit_State *J = (jit_State *)ud;
+ split_ir(J);
+ UNUSED(L); UNUSED(dummy);
+ return NULL;
+}
+
+#if defined(LUA_USE_ASSERT) || LJ_SOFTFP
+/* Slow, but sure way to check whether a SPLIT pass is needed. */
+static int split_needsplit(jit_State *J)
+{
+ IRIns *ir, *irend;
+ IRRef ref;
+ for (ir = IR(REF_FIRST), irend = IR(J->cur.nins); ir < irend; ir++)
+ if (LJ_SOFTFP ? irt_is64orfp(ir->t) : irt_isint64(ir->t))
+ return 1;
+ if (LJ_SOFTFP) {
+ for (ref = J->chain[IR_SLOAD]; ref; ref = IR(ref)->prev)
+ if ((IR(ref)->op2 & IRSLOAD_CONVERT))
+ return 1;
+ if (J->chain[IR_TOBIT])
+ return 1;
+ }
+ for (ref = J->chain[IR_CONV]; ref; ref = IR(ref)->prev) {
+ IRType st = (IR(ref)->op2 & IRCONV_SRCMASK);
+ if ((LJ_SOFTFP && (st == IRT_NUM || st == IRT_FLOAT)) ||
+ st == IRT_I64 || st == IRT_U64)
+ return 1;
+ }
+ return 0; /* Nope. */
+}
+#endif
+
+/* SPLIT pass. */
+void lj_opt_split(jit_State *J)
+{
+#if LJ_SOFTFP
+ if (!J->needsplit)
+ J->needsplit = split_needsplit(J);
+#else
+ lua_assert(J->needsplit >= split_needsplit(J)); /* Verify flag. */
+#endif
+ if (J->needsplit) {
+ int errcode = lj_vm_cpcall(J->L, NULL, J, cpsplit);
+ if (errcode) {
+ /* Completely reset the trace to avoid inconsistent dump on abort. */
+ J->cur.nins = J->cur.nk = REF_BASE;
+ J->cur.nsnap = 0;
+ lj_err_throw(J->L, errcode); /* Propagate errors. */
+ }
+ }
+}
+
+#undef IR
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_parse.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_parse.c
new file mode 100644
index 0000000..6785495
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_parse.c
@@ -0,0 +1,2757 @@
+/*
+** Lua parser (source code -> bytecode).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Major portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#define lj_parse_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_debug.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_func.h"
+#include "lj_state.h"
+#include "lj_bc.h"
+#if LJ_HASFFI
+#include "lj_ctype.h"
+#endif
+#include "lj_lex.h"
+#include "lj_parse.h"
+#include "lj_vm.h"
+#include "lj_vmevent.h"
+
+/* -- Parser structures and definitions ----------------------------------- */
+
+/* Expression kinds. */
+typedef enum {
+ /* Constant expressions must be first and in this order: */
+ VKNIL,
+ VKFALSE,
+ VKTRUE,
+ VKSTR, /* sval = string value */
+ VKNUM, /* nval = number value */
+ VKLAST = VKNUM,
+ VKCDATA, /* nval = cdata value, not treated as a constant expression */
+ /* Non-constant expressions follow: */
+ VLOCAL, /* info = local register, aux = vstack index */
+ VUPVAL, /* info = upvalue index, aux = vstack index */
+ VGLOBAL, /* sval = string value */
+ VINDEXED, /* info = table register, aux = index reg/byte/string const */
+ VJMP, /* info = instruction PC */
+ VRELOCABLE, /* info = instruction PC */
+ VNONRELOC, /* info = result register */
+ VCALL, /* info = instruction PC, aux = base */
+ VVOID
+} ExpKind;
+
+/* Expression descriptor. */
+typedef struct ExpDesc {
+ union {
+ struct {
+ uint32_t info; /* Primary info. */
+ uint32_t aux; /* Secondary info. */
+ } s;
+ TValue nval; /* Number value. */
+ GCstr *sval; /* String value. */
+ } u;
+ ExpKind k;
+ BCPos t; /* True condition jump list. */
+ BCPos f; /* False condition jump list. */
+} ExpDesc;
+
+/* Macros for expressions. */
+#define expr_hasjump(e) ((e)->t != (e)->f)
+
+#define expr_isk(e) ((e)->k <= VKLAST)
+#define expr_isk_nojump(e) (expr_isk(e) && !expr_hasjump(e))
+#define expr_isnumk(e) ((e)->k == VKNUM)
+#define expr_isnumk_nojump(e) (expr_isnumk(e) && !expr_hasjump(e))
+#define expr_isstrk(e) ((e)->k == VKSTR)
+
+#define expr_numtv(e) check_exp(expr_isnumk((e)), &(e)->u.nval)
+#define expr_numberV(e) numberVnum(expr_numtv((e)))
+
+/* Initialize expression. */
+static LJ_AINLINE void expr_init(ExpDesc *e, ExpKind k, uint32_t info)
+{
+ e->k = k;
+ e->u.s.info = info;
+ e->f = e->t = NO_JMP;
+}
+
+/* Check number constant for +-0. */
+static int expr_numiszero(ExpDesc *e)
+{
+ TValue *o = expr_numtv(e);
+ return tvisint(o) ? (intV(o) == 0) : tviszero(o);
+}
+
+/* Per-function linked list of scope blocks. */
+typedef struct FuncScope {
+ struct FuncScope *prev; /* Link to outer scope. */
+ MSize vstart; /* Start of block-local variables. */
+ uint8_t nactvar; /* Number of active vars outside the scope. */
+ uint8_t flags; /* Scope flags. */
+} FuncScope;
+
+#define FSCOPE_LOOP 0x01 /* Scope is a (breakable) loop. */
+#define FSCOPE_BREAK 0x02 /* Break used in scope. */
+#define FSCOPE_GOLA 0x04 /* Goto or label used in scope. */
+#define FSCOPE_UPVAL 0x08 /* Upvalue in scope. */
+#define FSCOPE_NOCLOSE 0x10 /* Do not close upvalues. */
+
+#define NAME_BREAK ((GCstr *)(uintptr_t)1)
+
+/* Index into variable stack. */
+typedef uint16_t VarIndex;
+#define LJ_MAX_VSTACK (65536 - LJ_MAX_UPVAL)
+
+/* Variable/goto/label info. */
+#define VSTACK_VAR_RW 0x01 /* R/W variable. */
+#define VSTACK_GOTO 0x02 /* Pending goto. */
+#define VSTACK_LABEL 0x04 /* Label. */
+
+/* Per-function state. */
+typedef struct FuncState {
+ GCtab *kt; /* Hash table for constants. */
+ LexState *ls; /* Lexer state. */
+ lua_State *L; /* Lua state. */
+ FuncScope *bl; /* Current scope. */
+ struct FuncState *prev; /* Enclosing function. */
+ BCPos pc; /* Next bytecode position. */
+ BCPos lasttarget; /* Bytecode position of last jump target. */
+ BCPos jpc; /* Pending jump list to next bytecode. */
+ BCReg freereg; /* First free register. */
+ BCReg nactvar; /* Number of active local variables. */
+ BCReg nkn, nkgc; /* Number of lua_Number/GCobj constants */
+ BCLine linedefined; /* First line of the function definition. */
+ BCInsLine *bcbase; /* Base of bytecode stack. */
+ BCPos bclim; /* Limit of bytecode stack. */
+ MSize vbase; /* Base of variable stack for this function. */
+ uint8_t flags; /* Prototype flags. */
+ uint8_t numparams; /* Number of parameters. */
+ uint8_t framesize; /* Fixed frame size. */
+ uint8_t nuv; /* Number of upvalues */
+ VarIndex varmap[LJ_MAX_LOCVAR]; /* Map from register to variable idx. */
+ VarIndex uvmap[LJ_MAX_UPVAL]; /* Map from upvalue to variable idx. */
+ VarIndex uvtmp[LJ_MAX_UPVAL]; /* Temporary upvalue map. */
+} FuncState;
+
+/* Binary and unary operators. ORDER OPR */
+typedef enum BinOpr {
+ OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, /* ORDER ARITH */
+ OPR_CONCAT,
+ OPR_NE, OPR_EQ,
+ OPR_LT, OPR_GE, OPR_LE, OPR_GT,
+ OPR_AND, OPR_OR,
+ OPR_NOBINOPR
+} BinOpr;
+
+LJ_STATIC_ASSERT((int)BC_ISGE-(int)BC_ISLT == (int)OPR_GE-(int)OPR_LT);
+LJ_STATIC_ASSERT((int)BC_ISLE-(int)BC_ISLT == (int)OPR_LE-(int)OPR_LT);
+LJ_STATIC_ASSERT((int)BC_ISGT-(int)BC_ISLT == (int)OPR_GT-(int)OPR_LT);
+LJ_STATIC_ASSERT((int)BC_SUBVV-(int)BC_ADDVV == (int)OPR_SUB-(int)OPR_ADD);
+LJ_STATIC_ASSERT((int)BC_MULVV-(int)BC_ADDVV == (int)OPR_MUL-(int)OPR_ADD);
+LJ_STATIC_ASSERT((int)BC_DIVVV-(int)BC_ADDVV == (int)OPR_DIV-(int)OPR_ADD);
+LJ_STATIC_ASSERT((int)BC_MODVV-(int)BC_ADDVV == (int)OPR_MOD-(int)OPR_ADD);
+
+/* -- Error handling ------------------------------------------------------ */
+
+LJ_NORET LJ_NOINLINE static void err_syntax(LexState *ls, ErrMsg em)
+{
+ lj_lex_error(ls, ls->token, em);
+}
+
+LJ_NORET LJ_NOINLINE static void err_token(LexState *ls, LexToken token)
+{
+ lj_lex_error(ls, ls->token, LJ_ERR_XTOKEN, lj_lex_token2str(ls, token));
+}
+
+LJ_NORET static void err_limit(FuncState *fs, uint32_t limit, const char *what)
+{
+ if (fs->linedefined == 0)
+ lj_lex_error(fs->ls, 0, LJ_ERR_XLIMM, limit, what);
+ else
+ lj_lex_error(fs->ls, 0, LJ_ERR_XLIMF, fs->linedefined, limit, what);
+}
+
+#define checklimit(fs, v, l, m) if ((v) >= (l)) err_limit(fs, l, m)
+#define checklimitgt(fs, v, l, m) if ((v) > (l)) err_limit(fs, l, m)
+#define checkcond(ls, c, em) { if (!(c)) err_syntax(ls, em); }
+
+/* -- Management of constants --------------------------------------------- */
+
+/* Return bytecode encoding for primitive constant. */
+#define const_pri(e) check_exp((e)->k <= VKTRUE, (e)->k)
+
+#define tvhaskslot(o) ((o)->u32.hi == 0)
+#define tvkslot(o) ((o)->u32.lo)
+
+/* Add a number constant. */
+static BCReg const_num(FuncState *fs, ExpDesc *e)
+{
+ lua_State *L = fs->L;
+ TValue *o;
+ lua_assert(expr_isnumk(e));
+ o = lj_tab_set(L, fs->kt, &e->u.nval);
+ if (tvhaskslot(o))
+ return tvkslot(o);
+ o->u64 = fs->nkn;
+ return fs->nkn++;
+}
+
+/* Add a GC object constant. */
+static BCReg const_gc(FuncState *fs, GCobj *gc, uint32_t itype)
+{
+ lua_State *L = fs->L;
+ TValue key, *o;
+ setgcV(L, &key, gc, itype);
+ /* NOBARRIER: the key is new or kept alive. */
+ o = lj_tab_set(L, fs->kt, &key);
+ if (tvhaskslot(o))
+ return tvkslot(o);
+ o->u64 = fs->nkgc;
+ return fs->nkgc++;
+}
+
+/* Add a string constant. */
+static BCReg const_str(FuncState *fs, ExpDesc *e)
+{
+ lua_assert(expr_isstrk(e) || e->k == VGLOBAL);
+ return const_gc(fs, obj2gco(e->u.sval), LJ_TSTR);
+}
+
+/* Anchor string constant to avoid GC. */
+GCstr *lj_parse_keepstr(LexState *ls, const char *str, size_t len)
+{
+ /* NOBARRIER: the key is new or kept alive. */
+ lua_State *L = ls->L;
+ GCstr *s = lj_str_new(L, str, len);
+ TValue *tv = lj_tab_setstr(L, ls->fs->kt, s);
+ if (tvisnil(tv)) setboolV(tv, 1);
+ lj_gc_check(L);
+ return s;
+}
+
+#if LJ_HASFFI
+/* Anchor cdata to avoid GC. */
+void lj_parse_keepcdata(LexState *ls, TValue *tv, GCcdata *cd)
+{
+ /* NOBARRIER: the key is new or kept alive. */
+ lua_State *L = ls->L;
+ setcdataV(L, tv, cd);
+ setboolV(lj_tab_set(L, ls->fs->kt, tv), 1);
+}
+#endif
+
+/* -- Jump list handling -------------------------------------------------- */
+
+/* Get next element in jump list. */
+static BCPos jmp_next(FuncState *fs, BCPos pc)
+{
+ ptrdiff_t delta = bc_j(fs->bcbase[pc].ins);
+ if ((BCPos)delta == NO_JMP)
+ return NO_JMP;
+ else
+ return (BCPos)(((ptrdiff_t)pc+1)+delta);
+}
+
+/* Check if any of the instructions on the jump list produce no value. */
+static int jmp_novalue(FuncState *fs, BCPos list)
+{
+ for (; list != NO_JMP; list = jmp_next(fs, list)) {
+ BCIns p = fs->bcbase[list >= 1 ? list-1 : list].ins;
+ if (!(bc_op(p) == BC_ISTC || bc_op(p) == BC_ISFC || bc_a(p) == NO_REG))
+ return 1;
+ }
+ return 0;
+}
+
+/* Patch register of test instructions. */
+static int jmp_patchtestreg(FuncState *fs, BCPos pc, BCReg reg)
+{
+ BCInsLine *ilp = &fs->bcbase[pc >= 1 ? pc-1 : pc];
+ BCOp op = bc_op(ilp->ins);
+ if (op == BC_ISTC || op == BC_ISFC) {
+ if (reg != NO_REG && reg != bc_d(ilp->ins)) {
+ setbc_a(&ilp->ins, reg);
+ } else { /* Nothing to store or already in the right register. */
+ setbc_op(&ilp->ins, op+(BC_IST-BC_ISTC));
+ setbc_a(&ilp->ins, 0);
+ }
+ } else if (bc_a(ilp->ins) == NO_REG) {
+ if (reg == NO_REG) {
+ ilp->ins = BCINS_AJ(BC_JMP, bc_a(fs->bcbase[pc].ins), 0);
+ } else {
+ setbc_a(&ilp->ins, reg);
+ if (reg >= bc_a(ilp[1].ins))
+ setbc_a(&ilp[1].ins, reg+1);
+ }
+ } else {
+ return 0; /* Cannot patch other instructions. */
+ }
+ return 1;
+}
+
+/* Drop values for all instructions on jump list. */
+static void jmp_dropval(FuncState *fs, BCPos list)
+{
+ for (; list != NO_JMP; list = jmp_next(fs, list))
+ jmp_patchtestreg(fs, list, NO_REG);
+}
+
+/* Patch jump instruction to target. */
+static void jmp_patchins(FuncState *fs, BCPos pc, BCPos dest)
+{
+ BCIns *jmp = &fs->bcbase[pc].ins;
+ BCPos offset = dest-(pc+1)+BCBIAS_J;
+ lua_assert(dest != NO_JMP);
+ if (offset > BCMAX_D)
+ err_syntax(fs->ls, LJ_ERR_XJUMP);
+ setbc_d(jmp, offset);
+}
+
+/* Append to jump list. */
+static void jmp_append(FuncState *fs, BCPos *l1, BCPos l2)
+{
+ if (l2 == NO_JMP) {
+ return;
+ } else if (*l1 == NO_JMP) {
+ *l1 = l2;
+ } else {
+ BCPos list = *l1;
+ BCPos next;
+ while ((next = jmp_next(fs, list)) != NO_JMP) /* Find last element. */
+ list = next;
+ jmp_patchins(fs, list, l2);
+ }
+}
+
+/* Patch jump list and preserve produced values. */
+static void jmp_patchval(FuncState *fs, BCPos list, BCPos vtarget,
+ BCReg reg, BCPos dtarget)
+{
+ while (list != NO_JMP) {
+ BCPos next = jmp_next(fs, list);
+ if (jmp_patchtestreg(fs, list, reg))
+ jmp_patchins(fs, list, vtarget); /* Jump to target with value. */
+ else
+ jmp_patchins(fs, list, dtarget); /* Jump to default target. */
+ list = next;
+ }
+}
+
+/* Jump to following instruction. Append to list of pending jumps. */
+static void jmp_tohere(FuncState *fs, BCPos list)
+{
+ fs->lasttarget = fs->pc;
+ jmp_append(fs, &fs->jpc, list);
+}
+
+/* Patch jump list to target. */
+static void jmp_patch(FuncState *fs, BCPos list, BCPos target)
+{
+ if (target == fs->pc) {
+ jmp_tohere(fs, list);
+ } else {
+ lua_assert(target < fs->pc);
+ jmp_patchval(fs, list, target, NO_REG, target);
+ }
+}
+
+/* -- Bytecode register allocator ----------------------------------------- */
+
+/* Bump frame size. */
+static void bcreg_bump(FuncState *fs, BCReg n)
+{
+ BCReg sz = fs->freereg + n;
+ if (sz > fs->framesize) {
+ if (sz >= LJ_MAX_SLOTS)
+ err_syntax(fs->ls, LJ_ERR_XSLOTS);
+ fs->framesize = (uint8_t)sz;
+ }
+}
+
+/* Reserve registers. */
+static void bcreg_reserve(FuncState *fs, BCReg n)
+{
+ bcreg_bump(fs, n);
+ fs->freereg += n;
+}
+
+/* Free register. */
+static void bcreg_free(FuncState *fs, BCReg reg)
+{
+ if (reg >= fs->nactvar) {
+ fs->freereg--;
+ lua_assert(reg == fs->freereg);
+ }
+}
+
+/* Free register for expression. */
+static void expr_free(FuncState *fs, ExpDesc *e)
+{
+ if (e->k == VNONRELOC)
+ bcreg_free(fs, e->u.s.info);
+}
+
+/* -- Bytecode emitter ---------------------------------------------------- */
+
+/* Emit bytecode instruction. */
+static BCPos bcemit_INS(FuncState *fs, BCIns ins)
+{
+ BCPos pc = fs->pc;
+ LexState *ls = fs->ls;
+ jmp_patchval(fs, fs->jpc, pc, NO_REG, pc);
+ fs->jpc = NO_JMP;
+ if (LJ_UNLIKELY(pc >= fs->bclim)) {
+ ptrdiff_t base = fs->bcbase - ls->bcstack;
+ checklimit(fs, ls->sizebcstack, LJ_MAX_BCINS, "bytecode instructions");
+ lj_mem_growvec(fs->L, ls->bcstack, ls->sizebcstack, LJ_MAX_BCINS,BCInsLine);
+ fs->bclim = (BCPos)(ls->sizebcstack - base);
+ fs->bcbase = ls->bcstack + base;
+ }
+ fs->bcbase[pc].ins = ins;
+ fs->bcbase[pc].line = ls->lastline;
+ fs->pc = pc+1;
+ return pc;
+}
+
+#define bcemit_ABC(fs, o, a, b, c) bcemit_INS(fs, BCINS_ABC(o, a, b, c))
+#define bcemit_AD(fs, o, a, d) bcemit_INS(fs, BCINS_AD(o, a, d))
+#define bcemit_AJ(fs, o, a, j) bcemit_INS(fs, BCINS_AJ(o, a, j))
+
+#define bcptr(fs, e) (&(fs)->bcbase[(e)->u.s.info].ins)
+
+/* -- Bytecode emitter for expressions ------------------------------------ */
+
+/* Discharge non-constant expression to any register. */
+static void expr_discharge(FuncState *fs, ExpDesc *e)
+{
+ BCIns ins;
+ if (e->k == VUPVAL) {
+ ins = BCINS_AD(BC_UGET, 0, e->u.s.info);
+ } else if (e->k == VGLOBAL) {
+ ins = BCINS_AD(BC_GGET, 0, const_str(fs, e));
+ } else if (e->k == VINDEXED) {
+ BCReg rc = e->u.s.aux;
+ if ((int32_t)rc < 0) {
+ ins = BCINS_ABC(BC_TGETS, 0, e->u.s.info, ~rc);
+ } else if (rc > BCMAX_C) {
+ ins = BCINS_ABC(BC_TGETB, 0, e->u.s.info, rc-(BCMAX_C+1));
+ } else {
+ bcreg_free(fs, rc);
+ ins = BCINS_ABC(BC_TGETV, 0, e->u.s.info, rc);
+ }
+ bcreg_free(fs, e->u.s.info);
+ } else if (e->k == VCALL) {
+ e->u.s.info = e->u.s.aux;
+ e->k = VNONRELOC;
+ return;
+ } else if (e->k == VLOCAL) {
+ e->k = VNONRELOC;
+ return;
+ } else {
+ return;
+ }
+ e->u.s.info = bcemit_INS(fs, ins);
+ e->k = VRELOCABLE;
+}
+
+/* Emit bytecode to set a range of registers to nil. */
+static void bcemit_nil(FuncState *fs, BCReg from, BCReg n)
+{
+ if (fs->pc > fs->lasttarget) { /* No jumps to current position? */
+ BCIns *ip = &fs->bcbase[fs->pc-1].ins;
+ BCReg pto, pfrom = bc_a(*ip);
+ switch (bc_op(*ip)) { /* Try to merge with the previous instruction. */
+ case BC_KPRI:
+ if (bc_d(*ip) != ~LJ_TNIL) break;
+ if (from == pfrom) {
+ if (n == 1) return;
+ } else if (from == pfrom+1) {
+ from = pfrom;
+ n++;
+ } else {
+ break;
+ }
+ *ip = BCINS_AD(BC_KNIL, from, from+n-1); /* Replace KPRI. */
+ return;
+ case BC_KNIL:
+ pto = bc_d(*ip);
+ if (pfrom <= from && from <= pto+1) { /* Can we connect both ranges? */
+ if (from+n-1 > pto)
+ setbc_d(ip, from+n-1); /* Patch previous instruction range. */
+ return;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ /* Emit new instruction or replace old instruction. */
+ bcemit_INS(fs, n == 1 ? BCINS_AD(BC_KPRI, from, VKNIL) :
+ BCINS_AD(BC_KNIL, from, from+n-1));
+}
+
+/* Discharge an expression to a specific register. Ignore branches. */
+static void expr_toreg_nobranch(FuncState *fs, ExpDesc *e, BCReg reg)
+{
+ BCIns ins;
+ expr_discharge(fs, e);
+ if (e->k == VKSTR) {
+ ins = BCINS_AD(BC_KSTR, reg, const_str(fs, e));
+ } else if (e->k == VKNUM) {
+#if LJ_DUALNUM
+ cTValue *tv = expr_numtv(e);
+ if (tvisint(tv) && checki16(intV(tv)))
+ ins = BCINS_AD(BC_KSHORT, reg, (BCReg)(uint16_t)intV(tv));
+ else
+#else
+ lua_Number n = expr_numberV(e);
+ int32_t k = lj_num2int(n);
+ if (checki16(k) && n == (lua_Number)k)
+ ins = BCINS_AD(BC_KSHORT, reg, (BCReg)(uint16_t)k);
+ else
+#endif
+ ins = BCINS_AD(BC_KNUM, reg, const_num(fs, e));
+#if LJ_HASFFI
+ } else if (e->k == VKCDATA) {
+ fs->flags |= PROTO_FFI;
+ ins = BCINS_AD(BC_KCDATA, reg,
+ const_gc(fs, obj2gco(cdataV(&e->u.nval)), LJ_TCDATA));
+#endif
+ } else if (e->k == VRELOCABLE) {
+ setbc_a(bcptr(fs, e), reg);
+ goto noins;
+ } else if (e->k == VNONRELOC) {
+ if (reg == e->u.s.info)
+ goto noins;
+ ins = BCINS_AD(BC_MOV, reg, e->u.s.info);
+ } else if (e->k == VKNIL) {
+ bcemit_nil(fs, reg, 1);
+ goto noins;
+ } else if (e->k <= VKTRUE) {
+ ins = BCINS_AD(BC_KPRI, reg, const_pri(e));
+ } else {
+ lua_assert(e->k == VVOID || e->k == VJMP);
+ return;
+ }
+ bcemit_INS(fs, ins);
+noins:
+ e->u.s.info = reg;
+ e->k = VNONRELOC;
+}
+
+/* Forward declaration. */
+static BCPos bcemit_jmp(FuncState *fs);
+
+/* Discharge an expression to a specific register. */
+static void expr_toreg(FuncState *fs, ExpDesc *e, BCReg reg)
+{
+ expr_toreg_nobranch(fs, e, reg);
+ if (e->k == VJMP)
+ jmp_append(fs, &e->t, e->u.s.info); /* Add it to the true jump list. */
+ if (expr_hasjump(e)) { /* Discharge expression with branches. */
+ BCPos jend, jfalse = NO_JMP, jtrue = NO_JMP;
+ if (jmp_novalue(fs, e->t) || jmp_novalue(fs, e->f)) {
+ BCPos jval = (e->k == VJMP) ? NO_JMP : bcemit_jmp(fs);
+ jfalse = bcemit_AD(fs, BC_KPRI, reg, VKFALSE);
+ bcemit_AJ(fs, BC_JMP, fs->freereg, 1);
+ jtrue = bcemit_AD(fs, BC_KPRI, reg, VKTRUE);
+ jmp_tohere(fs, jval);
+ }
+ jend = fs->pc;
+ fs->lasttarget = jend;
+ jmp_patchval(fs, e->f, jend, reg, jfalse);
+ jmp_patchval(fs, e->t, jend, reg, jtrue);
+ }
+ e->f = e->t = NO_JMP;
+ e->u.s.info = reg;
+ e->k = VNONRELOC;
+}
+
+/* Discharge an expression to the next free register. */
+static void expr_tonextreg(FuncState *fs, ExpDesc *e)
+{
+ expr_discharge(fs, e);
+ expr_free(fs, e);
+ bcreg_reserve(fs, 1);
+ expr_toreg(fs, e, fs->freereg - 1);
+}
+
+/* Discharge an expression to any register. */
+static BCReg expr_toanyreg(FuncState *fs, ExpDesc *e)
+{
+ expr_discharge(fs, e);
+ if (e->k == VNONRELOC) {
+ if (!expr_hasjump(e)) return e->u.s.info; /* Already in a register. */
+ if (e->u.s.info >= fs->nactvar) {
+ expr_toreg(fs, e, e->u.s.info); /* Discharge to temp. register. */
+ return e->u.s.info;
+ }
+ }
+ expr_tonextreg(fs, e); /* Discharge to next register. */
+ return e->u.s.info;
+}
+
+/* Partially discharge expression to a value. */
+static void expr_toval(FuncState *fs, ExpDesc *e)
+{
+ if (expr_hasjump(e))
+ expr_toanyreg(fs, e);
+ else
+ expr_discharge(fs, e);
+}
+
+/* Emit store for LHS expression. */
+static void bcemit_store(FuncState *fs, ExpDesc *var, ExpDesc *e)
+{
+ BCIns ins;
+ if (var->k == VLOCAL) {
+ fs->ls->vstack[var->u.s.aux].info |= VSTACK_VAR_RW;
+ expr_free(fs, e);
+ expr_toreg(fs, e, var->u.s.info);
+ return;
+ } else if (var->k == VUPVAL) {
+ fs->ls->vstack[var->u.s.aux].info |= VSTACK_VAR_RW;
+ expr_toval(fs, e);
+ if (e->k <= VKTRUE)
+ ins = BCINS_AD(BC_USETP, var->u.s.info, const_pri(e));
+ else if (e->k == VKSTR)
+ ins = BCINS_AD(BC_USETS, var->u.s.info, const_str(fs, e));
+ else if (e->k == VKNUM)
+ ins = BCINS_AD(BC_USETN, var->u.s.info, const_num(fs, e));
+ else
+ ins = BCINS_AD(BC_USETV, var->u.s.info, expr_toanyreg(fs, e));
+ } else if (var->k == VGLOBAL) {
+ BCReg ra = expr_toanyreg(fs, e);
+ ins = BCINS_AD(BC_GSET, ra, const_str(fs, var));
+ } else {
+ BCReg ra, rc;
+ lua_assert(var->k == VINDEXED);
+ ra = expr_toanyreg(fs, e);
+ rc = var->u.s.aux;
+ if ((int32_t)rc < 0) {
+ ins = BCINS_ABC(BC_TSETS, ra, var->u.s.info, ~rc);
+ } else if (rc > BCMAX_C) {
+ ins = BCINS_ABC(BC_TSETB, ra, var->u.s.info, rc-(BCMAX_C+1));
+ } else {
+ /* Free late alloced key reg to avoid assert on free of value reg. */
+ /* This can only happen when called from expr_table(). */
+ lua_assert(e->k != VNONRELOC || ra < fs->nactvar ||
+ rc < ra || (bcreg_free(fs, rc),1));
+ ins = BCINS_ABC(BC_TSETV, ra, var->u.s.info, rc);
+ }
+ }
+ bcemit_INS(fs, ins);
+ expr_free(fs, e);
+}
+
+/* Emit method lookup expression. */
+static void bcemit_method(FuncState *fs, ExpDesc *e, ExpDesc *key)
+{
+ BCReg idx, func, obj = expr_toanyreg(fs, e);
+ expr_free(fs, e);
+ func = fs->freereg;
+ bcemit_AD(fs, BC_MOV, func+1, obj); /* Copy object to first argument. */
+ lua_assert(expr_isstrk(key));
+ idx = const_str(fs, key);
+ if (idx <= BCMAX_C) {
+ bcreg_reserve(fs, 2);
+ bcemit_ABC(fs, BC_TGETS, func, obj, idx);
+ } else {
+ bcreg_reserve(fs, 3);
+ bcemit_AD(fs, BC_KSTR, func+2, idx);
+ bcemit_ABC(fs, BC_TGETV, func, obj, func+2);
+ fs->freereg--;
+ }
+ e->u.s.info = func;
+ e->k = VNONRELOC;
+}
+
+/* -- Bytecode emitter for branches --------------------------------------- */
+
+/* Emit unconditional branch. */
+static BCPos bcemit_jmp(FuncState *fs)
+{
+ BCPos jpc = fs->jpc;
+ BCPos j = fs->pc - 1;
+ BCIns *ip = &fs->bcbase[j].ins;
+ fs->jpc = NO_JMP;
+ if ((int32_t)j >= (int32_t)fs->lasttarget && bc_op(*ip) == BC_UCLO) {
+ setbc_j(ip, NO_JMP);
+ fs->lasttarget = j+1;
+ } else {
+ j = bcemit_AJ(fs, BC_JMP, fs->freereg, NO_JMP);
+ }
+ jmp_append(fs, &j, jpc);
+ return j;
+}
+
+/* Invert branch condition of bytecode instruction. */
+static void invertcond(FuncState *fs, ExpDesc *e)
+{
+ BCIns *ip = &fs->bcbase[e->u.s.info - 1].ins;
+ setbc_op(ip, bc_op(*ip)^1);
+}
+
+/* Emit conditional branch. */
+static BCPos bcemit_branch(FuncState *fs, ExpDesc *e, int cond)
+{
+ BCPos pc;
+ if (e->k == VRELOCABLE) {
+ BCIns *ip = bcptr(fs, e);
+ if (bc_op(*ip) == BC_NOT) {
+ *ip = BCINS_AD(cond ? BC_ISF : BC_IST, 0, bc_d(*ip));
+ return bcemit_jmp(fs);
+ }
+ }
+ if (e->k != VNONRELOC) {
+ bcreg_reserve(fs, 1);
+ expr_toreg_nobranch(fs, e, fs->freereg-1);
+ }
+ bcemit_AD(fs, cond ? BC_ISTC : BC_ISFC, NO_REG, e->u.s.info);
+ pc = bcemit_jmp(fs);
+ expr_free(fs, e);
+ return pc;
+}
+
+/* Emit branch on true condition. */
+static void bcemit_branch_t(FuncState *fs, ExpDesc *e)
+{
+ BCPos pc;
+ expr_discharge(fs, e);
+ if (e->k == VKSTR || e->k == VKNUM || e->k == VKTRUE)
+ pc = NO_JMP; /* Never jump. */
+ else if (e->k == VJMP)
+ invertcond(fs, e), pc = e->u.s.info;
+ else if (e->k == VKFALSE || e->k == VKNIL)
+ expr_toreg_nobranch(fs, e, NO_REG), pc = bcemit_jmp(fs);
+ else
+ pc = bcemit_branch(fs, e, 0);
+ jmp_append(fs, &e->f, pc);
+ jmp_tohere(fs, e->t);
+ e->t = NO_JMP;
+}
+
+/* Emit branch on false condition. */
+static void bcemit_branch_f(FuncState *fs, ExpDesc *e)
+{
+ BCPos pc;
+ expr_discharge(fs, e);
+ if (e->k == VKNIL || e->k == VKFALSE)
+ pc = NO_JMP; /* Never jump. */
+ else if (e->k == VJMP)
+ pc = e->u.s.info;
+ else if (e->k == VKSTR || e->k == VKNUM || e->k == VKTRUE)
+ expr_toreg_nobranch(fs, e, NO_REG), pc = bcemit_jmp(fs);
+ else
+ pc = bcemit_branch(fs, e, 1);
+ jmp_append(fs, &e->t, pc);
+ jmp_tohere(fs, e->f);
+ e->f = NO_JMP;
+}
+
+/* -- Bytecode emitter for operators -------------------------------------- */
+
+/* Try constant-folding of arithmetic operators. */
+static int foldarith(BinOpr opr, ExpDesc *e1, ExpDesc *e2)
+{
+ TValue o;
+ lua_Number n;
+ if (!expr_isnumk_nojump(e1) || !expr_isnumk_nojump(e2)) return 0;
+ n = lj_vm_foldarith(expr_numberV(e1), expr_numberV(e2), (int)opr-OPR_ADD);
+ setnumV(&o, n);
+ if (tvisnan(&o) || tvismzero(&o)) return 0; /* Avoid NaN and -0 as consts. */
+ if (LJ_DUALNUM) {
+ int32_t k = lj_num2int(n);
+ if ((lua_Number)k == n) {
+ setintV(&e1->u.nval, k);
+ return 1;
+ }
+ }
+ setnumV(&e1->u.nval, n);
+ return 1;
+}
+
+/* Emit arithmetic operator. */
+static void bcemit_arith(FuncState *fs, BinOpr opr, ExpDesc *e1, ExpDesc *e2)
+{
+ BCReg rb, rc, t;
+ uint32_t op;
+ if (foldarith(opr, e1, e2))
+ return;
+ if (opr == OPR_POW) {
+ op = BC_POW;
+ rc = expr_toanyreg(fs, e2);
+ rb = expr_toanyreg(fs, e1);
+ } else {
+ op = opr-OPR_ADD+BC_ADDVV;
+ /* Must discharge 2nd operand first since VINDEXED might free regs. */
+ expr_toval(fs, e2);
+ if (expr_isnumk(e2) && (rc = const_num(fs, e2)) <= BCMAX_C)
+ op -= BC_ADDVV-BC_ADDVN;
+ else
+ rc = expr_toanyreg(fs, e2);
+ /* 1st operand discharged by bcemit_binop_left, but need KNUM/KSHORT. */
+ lua_assert(expr_isnumk(e1) || e1->k == VNONRELOC);
+ expr_toval(fs, e1);
+ /* Avoid two consts to satisfy bytecode constraints. */
+ if (expr_isnumk(e1) && !expr_isnumk(e2) &&
+ (t = const_num(fs, e1)) <= BCMAX_B) {
+ rb = rc; rc = t; op -= BC_ADDVV-BC_ADDNV;
+ } else {
+ rb = expr_toanyreg(fs, e1);
+ }
+ }
+ /* Using expr_free might cause asserts if the order is wrong. */
+ if (e1->k == VNONRELOC && e1->u.s.info >= fs->nactvar) fs->freereg--;
+ if (e2->k == VNONRELOC && e2->u.s.info >= fs->nactvar) fs->freereg--;
+ e1->u.s.info = bcemit_ABC(fs, op, 0, rb, rc);
+ e1->k = VRELOCABLE;
+}
+
+/* Emit comparison operator. */
+static void bcemit_comp(FuncState *fs, BinOpr opr, ExpDesc *e1, ExpDesc *e2)
+{
+ ExpDesc *eret = e1;
+ BCIns ins;
+ expr_toval(fs, e1);
+ if (opr == OPR_EQ || opr == OPR_NE) {
+ BCOp op = opr == OPR_EQ ? BC_ISEQV : BC_ISNEV;
+ BCReg ra;
+ if (expr_isk(e1)) { e1 = e2; e2 = eret; } /* Need constant in 2nd arg. */
+ ra = expr_toanyreg(fs, e1); /* First arg must be in a reg. */
+ expr_toval(fs, e2);
+ switch (e2->k) {
+ case VKNIL: case VKFALSE: case VKTRUE:
+ ins = BCINS_AD(op+(BC_ISEQP-BC_ISEQV), ra, const_pri(e2));
+ break;
+ case VKSTR:
+ ins = BCINS_AD(op+(BC_ISEQS-BC_ISEQV), ra, const_str(fs, e2));
+ break;
+ case VKNUM:
+ ins = BCINS_AD(op+(BC_ISEQN-BC_ISEQV), ra, const_num(fs, e2));
+ break;
+ default:
+ ins = BCINS_AD(op, ra, expr_toanyreg(fs, e2));
+ break;
+ }
+ } else {
+ uint32_t op = opr-OPR_LT+BC_ISLT;
+ BCReg ra, rd;
+ if ((op-BC_ISLT) & 1) { /* GT -> LT, GE -> LE */
+ e1 = e2; e2 = eret; /* Swap operands. */
+ op = ((op-BC_ISLT)^3)+BC_ISLT;
+ expr_toval(fs, e1);
+ }
+ rd = expr_toanyreg(fs, e2);
+ ra = expr_toanyreg(fs, e1);
+ ins = BCINS_AD(op, ra, rd);
+ }
+ /* Using expr_free might cause asserts if the order is wrong. */
+ if (e1->k == VNONRELOC && e1->u.s.info >= fs->nactvar) fs->freereg--;
+ if (e2->k == VNONRELOC && e2->u.s.info >= fs->nactvar) fs->freereg--;
+ bcemit_INS(fs, ins);
+ eret->u.s.info = bcemit_jmp(fs);
+ eret->k = VJMP;
+}
+
+/* Fixup left side of binary operator. */
+static void bcemit_binop_left(FuncState *fs, BinOpr op, ExpDesc *e)
+{
+ if (op == OPR_AND) {
+ bcemit_branch_t(fs, e);
+ } else if (op == OPR_OR) {
+ bcemit_branch_f(fs, e);
+ } else if (op == OPR_CONCAT) {
+ expr_tonextreg(fs, e);
+ } else if (op == OPR_EQ || op == OPR_NE) {
+ if (!expr_isk_nojump(e)) expr_toanyreg(fs, e);
+ } else {
+ if (!expr_isnumk_nojump(e)) expr_toanyreg(fs, e);
+ }
+}
+
+/* Emit binary operator. */
+static void bcemit_binop(FuncState *fs, BinOpr op, ExpDesc *e1, ExpDesc *e2)
+{
+ if (op <= OPR_POW) {
+ bcemit_arith(fs, op, e1, e2);
+ } else if (op == OPR_AND) {
+ lua_assert(e1->t == NO_JMP); /* List must be closed. */
+ expr_discharge(fs, e2);
+ jmp_append(fs, &e2->f, e1->f);
+ *e1 = *e2;
+ } else if (op == OPR_OR) {
+ lua_assert(e1->f == NO_JMP); /* List must be closed. */
+ expr_discharge(fs, e2);
+ jmp_append(fs, &e2->t, e1->t);
+ *e1 = *e2;
+ } else if (op == OPR_CONCAT) {
+ expr_toval(fs, e2);
+ if (e2->k == VRELOCABLE && bc_op(*bcptr(fs, e2)) == BC_CAT) {
+ lua_assert(e1->u.s.info == bc_b(*bcptr(fs, e2))-1);
+ expr_free(fs, e1);
+ setbc_b(bcptr(fs, e2), e1->u.s.info);
+ e1->u.s.info = e2->u.s.info;
+ } else {
+ expr_tonextreg(fs, e2);
+ expr_free(fs, e2);
+ expr_free(fs, e1);
+ e1->u.s.info = bcemit_ABC(fs, BC_CAT, 0, e1->u.s.info, e2->u.s.info);
+ }
+ e1->k = VRELOCABLE;
+ } else {
+ lua_assert(op == OPR_NE || op == OPR_EQ ||
+ op == OPR_LT || op == OPR_GE || op == OPR_LE || op == OPR_GT);
+ bcemit_comp(fs, op, e1, e2);
+ }
+}
+
+/* Emit unary operator. */
+static void bcemit_unop(FuncState *fs, BCOp op, ExpDesc *e)
+{
+ if (op == BC_NOT) {
+ /* Swap true and false lists. */
+ { BCPos temp = e->f; e->f = e->t; e->t = temp; }
+ jmp_dropval(fs, e->f);
+ jmp_dropval(fs, e->t);
+ expr_discharge(fs, e);
+ if (e->k == VKNIL || e->k == VKFALSE) {
+ e->k = VKTRUE;
+ return;
+ } else if (expr_isk(e) || (LJ_HASFFI && e->k == VKCDATA)) {
+ e->k = VKFALSE;
+ return;
+ } else if (e->k == VJMP) {
+ invertcond(fs, e);
+ return;
+ } else if (e->k == VRELOCABLE) {
+ bcreg_reserve(fs, 1);
+ setbc_a(bcptr(fs, e), fs->freereg-1);
+ e->u.s.info = fs->freereg-1;
+ e->k = VNONRELOC;
+ } else {
+ lua_assert(e->k == VNONRELOC);
+ }
+ } else {
+ lua_assert(op == BC_UNM || op == BC_LEN);
+ if (op == BC_UNM && !expr_hasjump(e)) { /* Constant-fold negations. */
+#if LJ_HASFFI
+ if (e->k == VKCDATA) { /* Fold in-place since cdata is not interned. */
+ GCcdata *cd = cdataV(&e->u.nval);
+ int64_t *p = (int64_t *)cdataptr(cd);
+ if (cd->ctypeid == CTID_COMPLEX_DOUBLE)
+ p[1] ^= (int64_t)U64x(80000000,00000000);
+ else
+ *p = -*p;
+ return;
+ } else
+#endif
+ if (expr_isnumk(e) && !expr_numiszero(e)) { /* Avoid folding to -0. */
+ TValue *o = expr_numtv(e);
+ if (tvisint(o)) {
+ int32_t k = intV(o);
+ if (k == -k)
+ setnumV(o, -(lua_Number)k);
+ else
+ setintV(o, -k);
+ return;
+ } else {
+ o->u64 ^= U64x(80000000,00000000);
+ return;
+ }
+ }
+ }
+ expr_toanyreg(fs, e);
+ }
+ expr_free(fs, e);
+ e->u.s.info = bcemit_AD(fs, op, 0, e->u.s.info);
+ e->k = VRELOCABLE;
+}
+
+/* -- Lexer support ------------------------------------------------------- */
+
+/* Check and consume optional token. */
+static int lex_opt(LexState *ls, LexToken tok)
+{
+ if (ls->token == tok) {
+ lj_lex_next(ls);
+ return 1;
+ }
+ return 0;
+}
+
+/* Check and consume token. */
+static void lex_check(LexState *ls, LexToken tok)
+{
+ if (ls->token != tok)
+ err_token(ls, tok);
+ lj_lex_next(ls);
+}
+
+/* Check for matching token. */
+static void lex_match(LexState *ls, LexToken what, LexToken who, BCLine line)
+{
+ if (!lex_opt(ls, what)) {
+ if (line == ls->linenumber) {
+ err_token(ls, what);
+ } else {
+ const char *swhat = lj_lex_token2str(ls, what);
+ const char *swho = lj_lex_token2str(ls, who);
+ lj_lex_error(ls, ls->token, LJ_ERR_XMATCH, swhat, swho, line);
+ }
+ }
+}
+
+/* Check for string token. */
+static GCstr *lex_str(LexState *ls)
+{
+ GCstr *s;
+ if (ls->token != TK_name && (LJ_52 || ls->token != TK_goto))
+ err_token(ls, TK_name);
+ s = strV(&ls->tokenval);
+ lj_lex_next(ls);
+ return s;
+}
+
+/* -- Variable handling --------------------------------------------------- */
+
+#define var_get(ls, fs, i) ((ls)->vstack[(fs)->varmap[(i)]])
+
+/* Define a new local variable. */
+static void var_new(LexState *ls, BCReg n, GCstr *name)
+{
+ FuncState *fs = ls->fs;
+ MSize vtop = ls->vtop;
+ checklimit(fs, fs->nactvar+n, LJ_MAX_LOCVAR, "local variables");
+ if (LJ_UNLIKELY(vtop >= ls->sizevstack)) {
+ if (ls->sizevstack >= LJ_MAX_VSTACK)
+ lj_lex_error(ls, 0, LJ_ERR_XLIMC, LJ_MAX_VSTACK);
+ lj_mem_growvec(ls->L, ls->vstack, ls->sizevstack, LJ_MAX_VSTACK, VarInfo);
+ }
+ lua_assert((uintptr_t)name < VARNAME__MAX ||
+ lj_tab_getstr(fs->kt, name) != NULL);
+ /* NOBARRIER: name is anchored in fs->kt and ls->vstack is not a GCobj. */
+ setgcref(ls->vstack[vtop].name, obj2gco(name));
+ fs->varmap[fs->nactvar+n] = (uint16_t)vtop;
+ ls->vtop = vtop+1;
+}
+
+#define var_new_lit(ls, n, v) \
+ var_new(ls, (n), lj_parse_keepstr(ls, "" v, sizeof(v)-1))
+
+#define var_new_fixed(ls, n, vn) \
+ var_new(ls, (n), (GCstr *)(uintptr_t)(vn))
+
+/* Add local variables. */
+static void var_add(LexState *ls, BCReg nvars)
+{
+ FuncState *fs = ls->fs;
+ BCReg nactvar = fs->nactvar;
+ while (nvars--) {
+ VarInfo *v = &var_get(ls, fs, nactvar);
+ v->startpc = fs->pc;
+ v->slot = nactvar++;
+ v->info = 0;
+ }
+ fs->nactvar = nactvar;
+}
+
+/* Remove local variables. */
+static void var_remove(LexState *ls, BCReg tolevel)
+{
+ FuncState *fs = ls->fs;
+ while (fs->nactvar > tolevel)
+ var_get(ls, fs, --fs->nactvar).endpc = fs->pc;
+}
+
+/* Lookup local variable name. */
+static BCReg var_lookup_local(FuncState *fs, GCstr *n)
+{
+ int i;
+ for (i = fs->nactvar-1; i >= 0; i--) {
+ if (n == strref(var_get(fs->ls, fs, i).name))
+ return (BCReg)i;
+ }
+ return (BCReg)-1; /* Not found. */
+}
+
+/* Lookup or add upvalue index. */
+static MSize var_lookup_uv(FuncState *fs, MSize vidx, ExpDesc *e)
+{
+ MSize i, n = fs->nuv;
+ for (i = 0; i < n; i++)
+ if (fs->uvmap[i] == vidx)
+ return i; /* Already exists. */
+ /* Otherwise create a new one. */
+ checklimit(fs, fs->nuv, LJ_MAX_UPVAL, "upvalues");
+ lua_assert(e->k == VLOCAL || e->k == VUPVAL);
+ fs->uvmap[n] = (uint16_t)vidx;
+ fs->uvtmp[n] = (uint16_t)(e->k == VLOCAL ? vidx : LJ_MAX_VSTACK+e->u.s.info);
+ fs->nuv = n+1;
+ return n;
+}
+
+/* Forward declaration. */
+static void fscope_uvmark(FuncState *fs, BCReg level);
+
+/* Recursively lookup variables in enclosing functions. */
+static MSize var_lookup_(FuncState *fs, GCstr *name, ExpDesc *e, int first)
+{
+ if (fs) {
+ BCReg reg = var_lookup_local(fs, name);
+ if ((int32_t)reg >= 0) { /* Local in this function? */
+ expr_init(e, VLOCAL, reg);
+ if (!first)
+ fscope_uvmark(fs, reg); /* Scope now has an upvalue. */
+ return (MSize)(e->u.s.aux = (uint32_t)fs->varmap[reg]);
+ } else {
+ MSize vidx = var_lookup_(fs->prev, name, e, 0); /* Var in outer func? */
+ if ((int32_t)vidx >= 0) { /* Yes, make it an upvalue here. */
+ e->u.s.info = (uint8_t)var_lookup_uv(fs, vidx, e);
+ e->k = VUPVAL;
+ return vidx;
+ }
+ }
+ } else { /* Not found in any function, must be a global. */
+ expr_init(e, VGLOBAL, 0);
+ e->u.sval = name;
+ }
+ return (MSize)-1; /* Global. */
+}
+
+/* Lookup variable name. */
+#define var_lookup(ls, e) \
+ var_lookup_((ls)->fs, lex_str(ls), (e), 1)
+
+/* -- Goto an label handling ---------------------------------------------- */
+
+/* Add a new goto or label. */
+static MSize gola_new(LexState *ls, GCstr *name, uint8_t info, BCPos pc)
+{
+ FuncState *fs = ls->fs;
+ MSize vtop = ls->vtop;
+ if (LJ_UNLIKELY(vtop >= ls->sizevstack)) {
+ if (ls->sizevstack >= LJ_MAX_VSTACK)
+ lj_lex_error(ls, 0, LJ_ERR_XLIMC, LJ_MAX_VSTACK);
+ lj_mem_growvec(ls->L, ls->vstack, ls->sizevstack, LJ_MAX_VSTACK, VarInfo);
+ }
+ lua_assert(name == NAME_BREAK || lj_tab_getstr(fs->kt, name) != NULL);
+ /* NOBARRIER: name is anchored in fs->kt and ls->vstack is not a GCobj. */
+ setgcref(ls->vstack[vtop].name, obj2gco(name));
+ ls->vstack[vtop].startpc = pc;
+ ls->vstack[vtop].slot = (uint8_t)fs->nactvar;
+ ls->vstack[vtop].info = info;
+ ls->vtop = vtop+1;
+ return vtop;
+}
+
+#define gola_isgoto(v) ((v)->info & VSTACK_GOTO)
+#define gola_islabel(v) ((v)->info & VSTACK_LABEL)
+#define gola_isgotolabel(v) ((v)->info & (VSTACK_GOTO|VSTACK_LABEL))
+
+/* Patch goto to jump to label. */
+static void gola_patch(LexState *ls, VarInfo *vg, VarInfo *vl)
+{
+ FuncState *fs = ls->fs;
+ BCPos pc = vg->startpc;
+ setgcrefnull(vg->name); /* Invalidate pending goto. */
+ setbc_a(&fs->bcbase[pc].ins, vl->slot);
+ jmp_patch(fs, pc, vl->startpc);
+}
+
+/* Patch goto to close upvalues. */
+static void gola_close(LexState *ls, VarInfo *vg)
+{
+ FuncState *fs = ls->fs;
+ BCPos pc = vg->startpc;
+ BCIns *ip = &fs->bcbase[pc].ins;
+ lua_assert(gola_isgoto(vg));
+ lua_assert(bc_op(*ip) == BC_JMP || bc_op(*ip) == BC_UCLO);
+ setbc_a(ip, vg->slot);
+ if (bc_op(*ip) == BC_JMP) {
+ BCPos next = jmp_next(fs, pc);
+ if (next != NO_JMP) jmp_patch(fs, next, pc); /* Jump to UCLO. */
+ setbc_op(ip, BC_UCLO); /* Turn into UCLO. */
+ setbc_j(ip, NO_JMP);
+ }
+}
+
+/* Resolve pending forward gotos for label. */
+static void gola_resolve(LexState *ls, FuncScope *bl, MSize idx)
+{
+ VarInfo *vg = ls->vstack + bl->vstart;
+ VarInfo *vl = ls->vstack + idx;
+ for (; vg < vl; vg++)
+ if (gcrefeq(vg->name, vl->name) && gola_isgoto(vg)) {
+ if (vg->slot < vl->slot) {
+ GCstr *name = strref(var_get(ls, ls->fs, vg->slot).name);
+ lua_assert((uintptr_t)name >= VARNAME__MAX);
+ ls->linenumber = ls->fs->bcbase[vg->startpc].line;
+ lua_assert(strref(vg->name) != NAME_BREAK);
+ lj_lex_error(ls, 0, LJ_ERR_XGSCOPE,
+ strdata(strref(vg->name)), strdata(name));
+ }
+ gola_patch(ls, vg, vl);
+ }
+}
+
+/* Fixup remaining gotos and labels for scope. */
+static void gola_fixup(LexState *ls, FuncScope *bl)
+{
+ VarInfo *v = ls->vstack + bl->vstart;
+ VarInfo *ve = ls->vstack + ls->vtop;
+ for (; v < ve; v++) {
+ GCstr *name = strref(v->name);
+ if (name != NULL) { /* Only consider remaining valid gotos/labels. */
+ if (gola_islabel(v)) {
+ VarInfo *vg;
+ setgcrefnull(v->name); /* Invalidate label that goes out of scope. */
+ for (vg = v+1; vg < ve; vg++) /* Resolve pending backward gotos. */
+ if (strref(vg->name) == name && gola_isgoto(vg)) {
+ if ((bl->flags&FSCOPE_UPVAL) && vg->slot > v->slot)
+ gola_close(ls, vg);
+ gola_patch(ls, vg, v);
+ }
+ } else if (gola_isgoto(v)) {
+ if (bl->prev) { /* Propagate goto or break to outer scope. */
+ bl->prev->flags |= name == NAME_BREAK ? FSCOPE_BREAK : FSCOPE_GOLA;
+ v->slot = bl->nactvar;
+ if ((bl->flags & FSCOPE_UPVAL))
+ gola_close(ls, v);
+ } else { /* No outer scope: undefined goto label or no loop. */
+ ls->linenumber = ls->fs->bcbase[v->startpc].line;
+ if (name == NAME_BREAK)
+ lj_lex_error(ls, 0, LJ_ERR_XBREAK);
+ else
+ lj_lex_error(ls, 0, LJ_ERR_XLUNDEF, strdata(name));
+ }
+ }
+ }
+ }
+}
+
+/* Find existing label. */
+static VarInfo *gola_findlabel(LexState *ls, GCstr *name)
+{
+ VarInfo *v = ls->vstack + ls->fs->bl->vstart;
+ VarInfo *ve = ls->vstack + ls->vtop;
+ for (; v < ve; v++)
+ if (strref(v->name) == name && gola_islabel(v))
+ return v;
+ return NULL;
+}
+
+/* -- Scope handling ------------------------------------------------------ */
+
+/* Begin a scope. */
+static void fscope_begin(FuncState *fs, FuncScope *bl, int flags)
+{
+ bl->nactvar = (uint8_t)fs->nactvar;
+ bl->flags = flags;
+ bl->vstart = fs->ls->vtop;
+ bl->prev = fs->bl;
+ fs->bl = bl;
+ lua_assert(fs->freereg == fs->nactvar);
+}
+
+/* End a scope. */
+static void fscope_end(FuncState *fs)
+{
+ FuncScope *bl = fs->bl;
+ LexState *ls = fs->ls;
+ fs->bl = bl->prev;
+ var_remove(ls, bl->nactvar);
+ fs->freereg = fs->nactvar;
+ lua_assert(bl->nactvar == fs->nactvar);
+ if ((bl->flags & (FSCOPE_UPVAL|FSCOPE_NOCLOSE)) == FSCOPE_UPVAL)
+ bcemit_AJ(fs, BC_UCLO, bl->nactvar, 0);
+ if ((bl->flags & FSCOPE_BREAK)) {
+ if ((bl->flags & FSCOPE_LOOP)) {
+ MSize idx = gola_new(ls, NAME_BREAK, VSTACK_LABEL, fs->pc);
+ ls->vtop = idx; /* Drop break label immediately. */
+ gola_resolve(ls, bl, idx);
+ } else { /* Need the fixup step to propagate the breaks. */
+ gola_fixup(ls, bl);
+ return;
+ }
+ }
+ if ((bl->flags & FSCOPE_GOLA)) {
+ gola_fixup(ls, bl);
+ }
+}
+
+/* Mark scope as having an upvalue. */
+static void fscope_uvmark(FuncState *fs, BCReg level)
+{
+ FuncScope *bl;
+ for (bl = fs->bl; bl && bl->nactvar > level; bl = bl->prev)
+ ;
+ if (bl)
+ bl->flags |= FSCOPE_UPVAL;
+}
+
+/* -- Function state management ------------------------------------------- */
+
+/* Fixup bytecode for prototype. */
+static void fs_fixup_bc(FuncState *fs, GCproto *pt, BCIns *bc, MSize n)
+{
+ BCInsLine *base = fs->bcbase;
+ MSize i;
+ pt->sizebc = n;
+ bc[0] = BCINS_AD((fs->flags & PROTO_VARARG) ? BC_FUNCV : BC_FUNCF,
+ fs->framesize, 0);
+ for (i = 1; i < n; i++)
+ bc[i] = base[i].ins;
+}
+
+/* Fixup upvalues for child prototype, step #2. */
+static void fs_fixup_uv2(FuncState *fs, GCproto *pt)
+{
+ VarInfo *vstack = fs->ls->vstack;
+ uint16_t *uv = proto_uv(pt);
+ MSize i, n = pt->sizeuv;
+ for (i = 0; i < n; i++) {
+ VarIndex vidx = uv[i];
+ if (vidx >= LJ_MAX_VSTACK)
+ uv[i] = vidx - LJ_MAX_VSTACK;
+ else if ((vstack[vidx].info & VSTACK_VAR_RW))
+ uv[i] = vstack[vidx].slot | PROTO_UV_LOCAL;
+ else
+ uv[i] = vstack[vidx].slot | PROTO_UV_LOCAL | PROTO_UV_IMMUTABLE;
+ }
+}
+
+/* Fixup constants for prototype. */
+static void fs_fixup_k(FuncState *fs, GCproto *pt, void *kptr)
+{
+ GCtab *kt;
+ TValue *array;
+ Node *node;
+ MSize i, hmask;
+ checklimitgt(fs, fs->nkn, BCMAX_D+1, "constants");
+ checklimitgt(fs, fs->nkgc, BCMAX_D+1, "constants");
+ setmref(pt->k, kptr);
+ pt->sizekn = fs->nkn;
+ pt->sizekgc = fs->nkgc;
+ kt = fs->kt;
+ array = tvref(kt->array);
+ for (i = 0; i < kt->asize; i++)
+ if (tvhaskslot(&array[i])) {
+ TValue *tv = &((TValue *)kptr)[tvkslot(&array[i])];
+ if (LJ_DUALNUM)
+ setintV(tv, (int32_t)i);
+ else
+ setnumV(tv, (lua_Number)i);
+ }
+ node = noderef(kt->node);
+ hmask = kt->hmask;
+ for (i = 0; i <= hmask; i++) {
+ Node *n = &node[i];
+ if (tvhaskslot(&n->val)) {
+ ptrdiff_t kidx = (ptrdiff_t)tvkslot(&n->val);
+ lua_assert(!tvisint(&n->key));
+ if (tvisnum(&n->key)) {
+ TValue *tv = &((TValue *)kptr)[kidx];
+ if (LJ_DUALNUM) {
+ lua_Number nn = numV(&n->key);
+ int32_t k = lj_num2int(nn);
+ lua_assert(!tvismzero(&n->key));
+ if ((lua_Number)k == nn)
+ setintV(tv, k);
+ else
+ *tv = n->key;
+ } else {
+ *tv = n->key;
+ }
+ } else {
+ GCobj *o = gcV(&n->key);
+ setgcref(((GCRef *)kptr)[~kidx], o);
+ lj_gc_objbarrier(fs->L, pt, o);
+ if (tvisproto(&n->key))
+ fs_fixup_uv2(fs, gco2pt(o));
+ }
+ }
+ }
+}
+
+/* Fixup upvalues for prototype, step #1. */
+static void fs_fixup_uv1(FuncState *fs, GCproto *pt, uint16_t *uv)
+{
+ setmref(pt->uv, uv);
+ pt->sizeuv = fs->nuv;
+ memcpy(uv, fs->uvtmp, fs->nuv*sizeof(VarIndex));
+}
+
+#ifndef LUAJIT_DISABLE_DEBUGINFO
+/* Prepare lineinfo for prototype. */
+static size_t fs_prep_line(FuncState *fs, BCLine numline)
+{
+ return (fs->pc-1) << (numline < 256 ? 0 : numline < 65536 ? 1 : 2);
+}
+
+/* Fixup lineinfo for prototype. */
+static void fs_fixup_line(FuncState *fs, GCproto *pt,
+ void *lineinfo, BCLine numline)
+{
+ BCInsLine *base = fs->bcbase + 1;
+ BCLine first = fs->linedefined;
+ MSize i = 0, n = fs->pc-1;
+ pt->firstline = fs->linedefined;
+ pt->numline = numline;
+ setmref(pt->lineinfo, lineinfo);
+ if (LJ_LIKELY(numline < 256)) {
+ uint8_t *li = (uint8_t *)lineinfo;
+ do {
+ BCLine delta = base[i].line - first;
+ lua_assert(delta >= 0 && delta < 256);
+ li[i] = (uint8_t)delta;
+ } while (++i < n);
+ } else if (LJ_LIKELY(numline < 65536)) {
+ uint16_t *li = (uint16_t *)lineinfo;
+ do {
+ BCLine delta = base[i].line - first;
+ lua_assert(delta >= 0 && delta < 65536);
+ li[i] = (uint16_t)delta;
+ } while (++i < n);
+ } else {
+ uint32_t *li = (uint32_t *)lineinfo;
+ do {
+ BCLine delta = base[i].line - first;
+ lua_assert(delta >= 0);
+ li[i] = (uint32_t)delta;
+ } while (++i < n);
+ }
+}
+
+/* Resize buffer if needed. */
+static LJ_NOINLINE void fs_buf_resize(LexState *ls, MSize len)
+{
+ MSize sz = ls->sb.sz * 2;
+ while (ls->sb.n + len > sz) sz = sz * 2;
+ lj_str_resizebuf(ls->L, &ls->sb, sz);
+}
+
+static LJ_AINLINE void fs_buf_need(LexState *ls, MSize len)
+{
+ if (LJ_UNLIKELY(ls->sb.n + len > ls->sb.sz))
+ fs_buf_resize(ls, len);
+}
+
+/* Add string to buffer. */
+static void fs_buf_str(LexState *ls, const char *str, MSize len)
+{
+ char *p = ls->sb.buf + ls->sb.n;
+ MSize i;
+ ls->sb.n += len;
+ for (i = 0; i < len; i++) p[i] = str[i];
+}
+
+/* Add ULEB128 value to buffer. */
+static void fs_buf_uleb128(LexState *ls, uint32_t v)
+{
+ MSize n = ls->sb.n;
+ uint8_t *p = (uint8_t *)ls->sb.buf;
+ for (; v >= 0x80; v >>= 7)
+ p[n++] = (uint8_t)((v & 0x7f) | 0x80);
+ p[n++] = (uint8_t)v;
+ ls->sb.n = n;
+}
+
+/* Prepare variable info for prototype. */
+static size_t fs_prep_var(LexState *ls, FuncState *fs, size_t *ofsvar)
+{
+ VarInfo *vs =ls->vstack, *ve;
+ MSize i, n;
+ BCPos lastpc;
+ lj_str_resetbuf(&ls->sb); /* Copy to temp. string buffer. */
+ /* Store upvalue names. */
+ for (i = 0, n = fs->nuv; i < n; i++) {
+ GCstr *s = strref(vs[fs->uvmap[i]].name);
+ MSize len = s->len+1;
+ fs_buf_need(ls, len);
+ fs_buf_str(ls, strdata(s), len);
+ }
+ *ofsvar = ls->sb.n;
+ lastpc = 0;
+ /* Store local variable names and compressed ranges. */
+ for (ve = vs + ls->vtop, vs += fs->vbase; vs < ve; vs++) {
+ if (!gola_isgotolabel(vs)) {
+ GCstr *s = strref(vs->name);
+ BCPos startpc;
+ if ((uintptr_t)s < VARNAME__MAX) {
+ fs_buf_need(ls, 1 + 2*5);
+ ls->sb.buf[ls->sb.n++] = (uint8_t)(uintptr_t)s;
+ } else {
+ MSize len = s->len+1;
+ fs_buf_need(ls, len + 2*5);
+ fs_buf_str(ls, strdata(s), len);
+ }
+ startpc = vs->startpc;
+ fs_buf_uleb128(ls, startpc-lastpc);
+ fs_buf_uleb128(ls, vs->endpc-startpc);
+ lastpc = startpc;
+ }
+ }
+ fs_buf_need(ls, 1);
+ ls->sb.buf[ls->sb.n++] = '\0'; /* Terminator for varinfo. */
+ return ls->sb.n;
+}
+
+/* Fixup variable info for prototype. */
+static void fs_fixup_var(LexState *ls, GCproto *pt, uint8_t *p, size_t ofsvar)
+{
+ setmref(pt->uvinfo, p);
+ setmref(pt->varinfo, (char *)p + ofsvar);
+ memcpy(p, ls->sb.buf, ls->sb.n); /* Copy from temp. string buffer. */
+}
+#else
+
+/* Initialize with empty debug info, if disabled. */
+#define fs_prep_line(fs, numline) (UNUSED(numline), 0)
+#define fs_fixup_line(fs, pt, li, numline) \
+ pt->firstline = pt->numline = 0, setmref((pt)->lineinfo, NULL)
+#define fs_prep_var(ls, fs, ofsvar) (UNUSED(ofsvar), 0)
+#define fs_fixup_var(ls, pt, p, ofsvar) \
+ setmref((pt)->uvinfo, NULL), setmref((pt)->varinfo, NULL)
+
+#endif
+
+/* Check if bytecode op returns. */
+static int bcopisret(BCOp op)
+{
+ switch (op) {
+ case BC_CALLMT: case BC_CALLT:
+ case BC_RETM: case BC_RET: case BC_RET0: case BC_RET1:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+/* Fixup return instruction for prototype. */
+static void fs_fixup_ret(FuncState *fs)
+{
+ BCPos lastpc = fs->pc;
+ if (lastpc <= fs->lasttarget || !bcopisret(bc_op(fs->bcbase[lastpc-1].ins))) {
+ if ((fs->bl->flags & FSCOPE_UPVAL))
+ bcemit_AJ(fs, BC_UCLO, 0, 0);
+ bcemit_AD(fs, BC_RET0, 0, 1); /* Need final return. */
+ }
+ fs->bl->flags |= FSCOPE_NOCLOSE; /* Handled above. */
+ fscope_end(fs);
+ lua_assert(fs->bl == NULL);
+ /* May need to fixup returns encoded before first function was created. */
+ if (fs->flags & PROTO_FIXUP_RETURN) {
+ BCPos pc;
+ for (pc = 1; pc < lastpc; pc++) {
+ BCIns ins = fs->bcbase[pc].ins;
+ BCPos offset;
+ switch (bc_op(ins)) {
+ case BC_CALLMT: case BC_CALLT:
+ case BC_RETM: case BC_RET: case BC_RET0: case BC_RET1:
+ offset = bcemit_INS(fs, ins); /* Copy original instruction. */
+ fs->bcbase[offset].line = fs->bcbase[pc].line;
+ offset = offset-(pc+1)+BCBIAS_J;
+ if (offset > BCMAX_D)
+ err_syntax(fs->ls, LJ_ERR_XFIXUP);
+ /* Replace with UCLO plus branch. */
+ fs->bcbase[pc].ins = BCINS_AD(BC_UCLO, 0, offset);
+ break;
+ case BC_UCLO:
+ return; /* We're done. */
+ default:
+ break;
+ }
+ }
+ }
+}
+
+/* Finish a FuncState and return the new prototype. */
+static GCproto *fs_finish(LexState *ls, BCLine line)
+{
+ lua_State *L = ls->L;
+ FuncState *fs = ls->fs;
+ BCLine numline = line - fs->linedefined;
+ size_t sizept, ofsk, ofsuv, ofsli, ofsdbg, ofsvar;
+ GCproto *pt;
+
+ /* Apply final fixups. */
+ fs_fixup_ret(fs);
+
+ /* Calculate total size of prototype including all colocated arrays. */
+ sizept = sizeof(GCproto) + fs->pc*sizeof(BCIns) + fs->nkgc*sizeof(GCRef);
+ sizept = (sizept + sizeof(TValue)-1) & ~(sizeof(TValue)-1);
+ ofsk = sizept; sizept += fs->nkn*sizeof(TValue);
+ ofsuv = sizept; sizept += ((fs->nuv+1)&~1)*2;
+ ofsli = sizept; sizept += fs_prep_line(fs, numline);
+ ofsdbg = sizept; sizept += fs_prep_var(ls, fs, &ofsvar);
+
+ /* Allocate prototype and initialize its fields. */
+ pt = (GCproto *)lj_mem_newgco(L, (MSize)sizept);
+ pt->gct = ~LJ_TPROTO;
+ pt->sizept = (MSize)sizept;
+ pt->trace = 0;
+ pt->flags = (uint8_t)(fs->flags & ~(PROTO_HAS_RETURN|PROTO_FIXUP_RETURN));
+ pt->numparams = fs->numparams;
+ pt->framesize = fs->framesize;
+ setgcref(pt->chunkname, obj2gco(ls->chunkname));
+
+ /* Close potentially uninitialized gap between bc and kgc. */
+ *(uint32_t *)((char *)pt + ofsk - sizeof(GCRef)*(fs->nkgc+1)) = 0;
+ fs_fixup_bc(fs, pt, (BCIns *)((char *)pt + sizeof(GCproto)), fs->pc);
+ fs_fixup_k(fs, pt, (void *)((char *)pt + ofsk));
+ fs_fixup_uv1(fs, pt, (uint16_t *)((char *)pt + ofsuv));
+ fs_fixup_line(fs, pt, (void *)((char *)pt + ofsli), numline);
+ fs_fixup_var(ls, pt, (uint8_t *)((char *)pt + ofsdbg), ofsvar);
+
+ lj_vmevent_send(L, BC,
+ setprotoV(L, L->top++, pt);
+ );
+
+ L->top--; /* Pop table of constants. */
+ ls->vtop = fs->vbase; /* Reset variable stack. */
+ ls->fs = fs->prev;
+ lua_assert(ls->fs != NULL || ls->token == TK_eof);
+ return pt;
+}
+
+/* Initialize a new FuncState. */
+static void fs_init(LexState *ls, FuncState *fs)
+{
+ lua_State *L = ls->L;
+ fs->prev = ls->fs; ls->fs = fs; /* Append to list. */
+ fs->ls = ls;
+ fs->vbase = ls->vtop;
+ fs->L = L;
+ fs->pc = 0;
+ fs->lasttarget = 0;
+ fs->jpc = NO_JMP;
+ fs->freereg = 0;
+ fs->nkgc = 0;
+ fs->nkn = 0;
+ fs->nactvar = 0;
+ fs->nuv = 0;
+ fs->bl = NULL;
+ fs->flags = 0;
+ fs->framesize = 1; /* Minimum frame size. */
+ fs->kt = lj_tab_new(L, 0, 0);
+ /* Anchor table of constants in stack to avoid being collected. */
+ settabV(L, L->top, fs->kt);
+ incr_top(L);
+}
+
+/* -- Expressions --------------------------------------------------------- */
+
+/* Forward declaration. */
+static void expr(LexState *ls, ExpDesc *v);
+
+/* Return string expression. */
+static void expr_str(LexState *ls, ExpDesc *e)
+{
+ expr_init(e, VKSTR, 0);
+ e->u.sval = lex_str(ls);
+}
+
+/* Return index expression. */
+static void expr_index(FuncState *fs, ExpDesc *t, ExpDesc *e)
+{
+ /* Already called: expr_toval(fs, e). */
+ t->k = VINDEXED;
+ if (expr_isnumk(e)) {
+#if LJ_DUALNUM
+ if (tvisint(expr_numtv(e))) {
+ int32_t k = intV(expr_numtv(e));
+ if (checku8(k)) {
+ t->u.s.aux = BCMAX_C+1+(uint32_t)k; /* 256..511: const byte key */
+ return;
+ }
+ }
+#else
+ lua_Number n = expr_numberV(e);
+ int32_t k = lj_num2int(n);
+ if (checku8(k) && n == (lua_Number)k) {
+ t->u.s.aux = BCMAX_C+1+(uint32_t)k; /* 256..511: const byte key */
+ return;
+ }
+#endif
+ } else if (expr_isstrk(e)) {
+ BCReg idx = const_str(fs, e);
+ if (idx <= BCMAX_C) {
+ t->u.s.aux = ~idx; /* -256..-1: const string key */
+ return;
+ }
+ }
+ t->u.s.aux = expr_toanyreg(fs, e); /* 0..255: register */
+}
+
+/* Parse index expression with named field. */
+static void expr_field(LexState *ls, ExpDesc *v)
+{
+ FuncState *fs = ls->fs;
+ ExpDesc key;
+ expr_toanyreg(fs, v);
+ lj_lex_next(ls); /* Skip dot or colon. */
+ expr_str(ls, &key);
+ expr_index(fs, v, &key);
+}
+
+/* Parse index expression with brackets. */
+static void expr_bracket(LexState *ls, ExpDesc *v)
+{
+ lj_lex_next(ls); /* Skip '['. */
+ expr(ls, v);
+ expr_toval(ls->fs, v);
+ lex_check(ls, ']');
+}
+
+/* Get value of constant expression. */
+static void expr_kvalue(TValue *v, ExpDesc *e)
+{
+ if (e->k <= VKTRUE) {
+ setitype(v, ~(uint32_t)e->k);
+ } else if (e->k == VKSTR) {
+ setgcref(v->gcr, obj2gco(e->u.sval));
+ setitype(v, LJ_TSTR);
+ } else {
+ lua_assert(tvisnumber(expr_numtv(e)));
+ *v = *expr_numtv(e);
+ }
+}
+
+/* Parse table constructor expression. */
+static void expr_table(LexState *ls, ExpDesc *e)
+{
+ FuncState *fs = ls->fs;
+ BCLine line = ls->linenumber;
+ GCtab *t = NULL;
+ int vcall = 0, needarr = 0, fixt = 0;
+ uint32_t narr = 1; /* First array index. */
+ uint32_t nhash = 0; /* Number of hash entries. */
+ BCReg freg = fs->freereg;
+ BCPos pc = bcemit_AD(fs, BC_TNEW, freg, 0);
+ expr_init(e, VNONRELOC, freg);
+ bcreg_reserve(fs, 1);
+ freg++;
+ lex_check(ls, '{');
+ while (ls->token != '}') {
+ ExpDesc key, val;
+ vcall = 0;
+ if (ls->token == '[') {
+ expr_bracket(ls, &key); /* Already calls expr_toval. */
+ if (!expr_isk(&key)) expr_index(fs, e, &key);
+ if (expr_isnumk(&key) && expr_numiszero(&key)) needarr = 1; else nhash++;
+ lex_check(ls, '=');
+ } else if ((ls->token == TK_name || (!LJ_52 && ls->token == TK_goto)) &&
+ lj_lex_lookahead(ls) == '=') {
+ expr_str(ls, &key);
+ lex_check(ls, '=');
+ nhash++;
+ } else {
+ expr_init(&key, VKNUM, 0);
+ setintV(&key.u.nval, (int)narr);
+ narr++;
+ needarr = vcall = 1;
+ }
+ expr(ls, &val);
+ if (expr_isk(&key) && key.k != VKNIL &&
+ (key.k == VKSTR || expr_isk_nojump(&val))) {
+ TValue k, *v;
+ if (!t) { /* Create template table on demand. */
+ BCReg kidx;
+ t = lj_tab_new(fs->L, needarr ? narr : 0, hsize2hbits(nhash));
+ kidx = const_gc(fs, obj2gco(t), LJ_TTAB);
+ fs->bcbase[pc].ins = BCINS_AD(BC_TDUP, freg-1, kidx);
+ }
+ vcall = 0;
+ expr_kvalue(&k, &key);
+ v = lj_tab_set(fs->L, t, &k);
+ lj_gc_anybarriert(fs->L, t);
+ if (expr_isk_nojump(&val)) { /* Add const key/value to template table. */
+ expr_kvalue(v, &val);
+ } else { /* Otherwise create dummy string key (avoids lj_tab_newkey). */
+ settabV(fs->L, v, t); /* Preserve key with table itself as value. */
+ fixt = 1; /* Fix this later, after all resizes. */
+ goto nonconst;
+ }
+ } else {
+ nonconst:
+ if (val.k != VCALL) { expr_toanyreg(fs, &val); vcall = 0; }
+ if (expr_isk(&key)) expr_index(fs, e, &key);
+ bcemit_store(fs, e, &val);
+ }
+ fs->freereg = freg;
+ if (!lex_opt(ls, ',') && !lex_opt(ls, ';')) break;
+ }
+ lex_match(ls, '}', '{', line);
+ if (vcall) {
+ BCInsLine *ilp = &fs->bcbase[fs->pc-1];
+ ExpDesc en;
+ lua_assert(bc_a(ilp->ins) == freg &&
+ bc_op(ilp->ins) == (narr > 256 ? BC_TSETV : BC_TSETB));
+ expr_init(&en, VKNUM, 0);
+ en.u.nval.u32.lo = narr-1;
+ en.u.nval.u32.hi = 0x43300000; /* Biased integer to avoid denormals. */
+ if (narr > 256) { fs->pc--; ilp--; }
+ ilp->ins = BCINS_AD(BC_TSETM, freg, const_num(fs, &en));
+ setbc_b(&ilp[-1].ins, 0);
+ }
+ if (pc == fs->pc-1) { /* Make expr relocable if possible. */
+ e->u.s.info = pc;
+ fs->freereg--;
+ e->k = VRELOCABLE;
+ } else {
+ e->k = VNONRELOC; /* May have been changed by expr_index. */
+ }
+ if (!t) { /* Construct TNEW RD: hhhhhaaaaaaaaaaa. */
+ BCIns *ip = &fs->bcbase[pc].ins;
+ if (!needarr) narr = 0;
+ else if (narr < 3) narr = 3;
+ else if (narr > 0x7ff) narr = 0x7ff;
+ setbc_d(ip, narr|(hsize2hbits(nhash)<<11));
+ } else {
+ if (needarr && t->asize < narr)
+ lj_tab_reasize(fs->L, t, narr-1);
+ if (fixt) { /* Fix value for dummy keys in template table. */
+ Node *node = noderef(t->node);
+ uint32_t i, hmask = t->hmask;
+ for (i = 0; i <= hmask; i++) {
+ Node *n = &node[i];
+ if (tvistab(&n->val)) {
+ lua_assert(tabV(&n->val) == t);
+ setnilV(&n->val); /* Turn value into nil. */
+ }
+ }
+ }
+ lj_gc_check(fs->L);
+ }
+}
+
+/* Parse function parameters. */
+static BCReg parse_params(LexState *ls, int needself)
+{
+ FuncState *fs = ls->fs;
+ BCReg nparams = 0;
+ lex_check(ls, '(');
+ if (needself)
+ var_new_lit(ls, nparams++, "self");
+ if (ls->token != ')') {
+ do {
+ if (ls->token == TK_name || (!LJ_52 && ls->token == TK_goto)) {
+ var_new(ls, nparams++, lex_str(ls));
+ } else if (ls->token == TK_dots) {
+ lj_lex_next(ls);
+ fs->flags |= PROTO_VARARG;
+ break;
+ } else {
+ err_syntax(ls, LJ_ERR_XPARAM);
+ }
+ } while (lex_opt(ls, ','));
+ }
+ var_add(ls, nparams);
+ lua_assert(fs->nactvar == nparams);
+ bcreg_reserve(fs, nparams);
+ lex_check(ls, ')');
+ return nparams;
+}
+
+/* Forward declaration. */
+static void parse_chunk(LexState *ls);
+
+/* Parse body of a function. */
+static void parse_body(LexState *ls, ExpDesc *e, int needself, BCLine line)
+{
+ FuncState fs, *pfs = ls->fs;
+ FuncScope bl;
+ GCproto *pt;
+ ptrdiff_t oldbase = pfs->bcbase - ls->bcstack;
+ fs_init(ls, &fs);
+ fscope_begin(&fs, &bl, 0);
+ fs.linedefined = line;
+ fs.numparams = (uint8_t)parse_params(ls, needself);
+ fs.bcbase = pfs->bcbase + pfs->pc;
+ fs.bclim = pfs->bclim - pfs->pc;
+ bcemit_AD(&fs, BC_FUNCF, 0, 0); /* Placeholder. */
+ parse_chunk(ls);
+ if (ls->token != TK_end) lex_match(ls, TK_end, TK_function, line);
+ pt = fs_finish(ls, (ls->lastline = ls->linenumber));
+ pfs->bcbase = ls->bcstack + oldbase; /* May have been reallocated. */
+ pfs->bclim = (BCPos)(ls->sizebcstack - oldbase);
+ /* Store new prototype in the constant array of the parent. */
+ expr_init(e, VRELOCABLE,
+ bcemit_AD(pfs, BC_FNEW, 0, const_gc(pfs, obj2gco(pt), LJ_TPROTO)));
+#if LJ_HASFFI
+ pfs->flags |= (fs.flags & PROTO_FFI);
+#endif
+ if (!(pfs->flags & PROTO_CHILD)) {
+ if (pfs->flags & PROTO_HAS_RETURN)
+ pfs->flags |= PROTO_FIXUP_RETURN;
+ pfs->flags |= PROTO_CHILD;
+ }
+ lj_lex_next(ls);
+}
+
+/* Parse expression list. Last expression is left open. */
+static BCReg expr_list(LexState *ls, ExpDesc *v)
+{
+ BCReg n = 1;
+ expr(ls, v);
+ while (lex_opt(ls, ',')) {
+ expr_tonextreg(ls->fs, v);
+ expr(ls, v);
+ n++;
+ }
+ return n;
+}
+
+/* Parse function argument list. */
+static void parse_args(LexState *ls, ExpDesc *e)
+{
+ FuncState *fs = ls->fs;
+ ExpDesc args;
+ BCIns ins;
+ BCReg base;
+ BCLine line = ls->linenumber;
+ if (ls->token == '(') {
+#if !LJ_52
+ if (line != ls->lastline)
+ err_syntax(ls, LJ_ERR_XAMBIG);
+#endif
+ lj_lex_next(ls);
+ if (ls->token == ')') { /* f(). */
+ args.k = VVOID;
+ } else {
+ expr_list(ls, &args);
+ if (args.k == VCALL) /* f(a, b, g()) or f(a, b, ...). */
+ setbc_b(bcptr(fs, &args), 0); /* Pass on multiple results. */
+ }
+ lex_match(ls, ')', '(', line);
+ } else if (ls->token == '{') {
+ expr_table(ls, &args);
+ } else if (ls->token == TK_string) {
+ expr_init(&args, VKSTR, 0);
+ args.u.sval = strV(&ls->tokenval);
+ lj_lex_next(ls);
+ } else {
+ err_syntax(ls, LJ_ERR_XFUNARG);
+ return; /* Silence compiler. */
+ }
+ lua_assert(e->k == VNONRELOC);
+ base = e->u.s.info; /* Base register for call. */
+ if (args.k == VCALL) {
+ ins = BCINS_ABC(BC_CALLM, base, 2, args.u.s.aux - base - 1);
+ } else {
+ if (args.k != VVOID)
+ expr_tonextreg(fs, &args);
+ ins = BCINS_ABC(BC_CALL, base, 2, fs->freereg - base);
+ }
+ expr_init(e, VCALL, bcemit_INS(fs, ins));
+ e->u.s.aux = base;
+ fs->bcbase[fs->pc - 1].line = line;
+ fs->freereg = base+1; /* Leave one result by default. */
+}
+
+/* Parse primary expression. */
+static void expr_primary(LexState *ls, ExpDesc *v)
+{
+ FuncState *fs = ls->fs;
+ /* Parse prefix expression. */
+ if (ls->token == '(') {
+ BCLine line = ls->linenumber;
+ lj_lex_next(ls);
+ expr(ls, v);
+ lex_match(ls, ')', '(', line);
+ expr_discharge(ls->fs, v);
+ } else if (ls->token == TK_name || (!LJ_52 && ls->token == TK_goto)) {
+ var_lookup(ls, v);
+ } else {
+ err_syntax(ls, LJ_ERR_XSYMBOL);
+ }
+ for (;;) { /* Parse multiple expression suffixes. */
+ if (ls->token == '.') {
+ expr_field(ls, v);
+ } else if (ls->token == '[') {
+ ExpDesc key;
+ expr_toanyreg(fs, v);
+ expr_bracket(ls, &key);
+ expr_index(fs, v, &key);
+ } else if (ls->token == ':') {
+ ExpDesc key;
+ lj_lex_next(ls);
+ expr_str(ls, &key);
+ bcemit_method(fs, v, &key);
+ parse_args(ls, v);
+ } else if (ls->token == '(' || ls->token == TK_string || ls->token == '{') {
+ expr_tonextreg(fs, v);
+ parse_args(ls, v);
+ } else {
+ break;
+ }
+ }
+}
+
+/* Parse simple expression. */
+static void expr_simple(LexState *ls, ExpDesc *v)
+{
+ switch (ls->token) {
+ case TK_number:
+ expr_init(v, (LJ_HASFFI && tviscdata(&ls->tokenval)) ? VKCDATA : VKNUM, 0);
+ copyTV(ls->L, &v->u.nval, &ls->tokenval);
+ break;
+ case TK_string:
+ expr_init(v, VKSTR, 0);
+ v->u.sval = strV(&ls->tokenval);
+ break;
+ case TK_nil:
+ expr_init(v, VKNIL, 0);
+ break;
+ case TK_true:
+ expr_init(v, VKTRUE, 0);
+ break;
+ case TK_false:
+ expr_init(v, VKFALSE, 0);
+ break;
+ case TK_dots: { /* Vararg. */
+ FuncState *fs = ls->fs;
+ BCReg base;
+ checkcond(ls, fs->flags & PROTO_VARARG, LJ_ERR_XDOTS);
+ bcreg_reserve(fs, 1);
+ base = fs->freereg-1;
+ expr_init(v, VCALL, bcemit_ABC(fs, BC_VARG, base, 2, fs->numparams));
+ v->u.s.aux = base;
+ break;
+ }
+ case '{': /* Table constructor. */
+ expr_table(ls, v);
+ return;
+ case TK_function:
+ lj_lex_next(ls);
+ parse_body(ls, v, 0, ls->linenumber);
+ return;
+ default:
+ expr_primary(ls, v);
+ return;
+ }
+ lj_lex_next(ls);
+}
+
+/* Manage syntactic levels to avoid blowing up the stack. */
+static void synlevel_begin(LexState *ls)
+{
+ if (++ls->level >= LJ_MAX_XLEVEL)
+ lj_lex_error(ls, 0, LJ_ERR_XLEVELS);
+}
+
+#define synlevel_end(ls) ((ls)->level--)
+
+/* Convert token to binary operator. */
+static BinOpr token2binop(LexToken tok)
+{
+ switch (tok) {
+ case '+': return OPR_ADD;
+ case '-': return OPR_SUB;
+ case '*': return OPR_MUL;
+ case '/': return OPR_DIV;
+ case '%': return OPR_MOD;
+ case '^': return OPR_POW;
+ case TK_concat: return OPR_CONCAT;
+ case TK_ne: return OPR_NE;
+ case TK_eq: return OPR_EQ;
+ case '<': return OPR_LT;
+ case TK_le: return OPR_LE;
+ case '>': return OPR_GT;
+ case TK_ge: return OPR_GE;
+ case TK_and: return OPR_AND;
+ case TK_or: return OPR_OR;
+ default: return OPR_NOBINOPR;
+ }
+}
+
+/* Priorities for each binary operator. ORDER OPR. */
+static const struct {
+ uint8_t left; /* Left priority. */
+ uint8_t right; /* Right priority. */
+} priority[] = {
+ {6,6}, {6,6}, {7,7}, {7,7}, {7,7}, /* ADD SUB MUL DIV MOD */
+ {10,9}, {5,4}, /* POW CONCAT (right associative) */
+ {3,3}, {3,3}, /* EQ NE */
+ {3,3}, {3,3}, {3,3}, {3,3}, /* LT GE GT LE */
+ {2,2}, {1,1} /* AND OR */
+};
+
+#define UNARY_PRIORITY 8 /* Priority for unary operators. */
+
+/* Forward declaration. */
+static BinOpr expr_binop(LexState *ls, ExpDesc *v, uint32_t limit);
+
+/* Parse unary expression. */
+static void expr_unop(LexState *ls, ExpDesc *v)
+{
+ BCOp op;
+ if (ls->token == TK_not) {
+ op = BC_NOT;
+ } else if (ls->token == '-') {
+ op = BC_UNM;
+ } else if (ls->token == '#') {
+ op = BC_LEN;
+ } else {
+ expr_simple(ls, v);
+ return;
+ }
+ lj_lex_next(ls);
+ expr_binop(ls, v, UNARY_PRIORITY);
+ bcemit_unop(ls->fs, op, v);
+}
+
+/* Parse binary expressions with priority higher than the limit. */
+static BinOpr expr_binop(LexState *ls, ExpDesc *v, uint32_t limit)
+{
+ BinOpr op;
+ synlevel_begin(ls);
+ expr_unop(ls, v);
+ op = token2binop(ls->token);
+ while (op != OPR_NOBINOPR && priority[op].left > limit) {
+ ExpDesc v2;
+ BinOpr nextop;
+ lj_lex_next(ls);
+ bcemit_binop_left(ls->fs, op, v);
+ /* Parse binary expression with higher priority. */
+ nextop = expr_binop(ls, &v2, priority[op].right);
+ bcemit_binop(ls->fs, op, v, &v2);
+ op = nextop;
+ }
+ synlevel_end(ls);
+ return op; /* Return unconsumed binary operator (if any). */
+}
+
+/* Parse expression. */
+static void expr(LexState *ls, ExpDesc *v)
+{
+ expr_binop(ls, v, 0); /* Priority 0: parse whole expression. */
+}
+
+/* Assign expression to the next register. */
+static void expr_next(LexState *ls)
+{
+ ExpDesc e;
+ expr(ls, &e);
+ expr_tonextreg(ls->fs, &e);
+}
+
+/* Parse conditional expression. */
+static BCPos expr_cond(LexState *ls)
+{
+ ExpDesc v;
+ expr(ls, &v);
+ if (v.k == VKNIL) v.k = VKFALSE;
+ bcemit_branch_t(ls->fs, &v);
+ return v.f;
+}
+
+/* -- Assignments --------------------------------------------------------- */
+
+/* List of LHS variables. */
+typedef struct LHSVarList {
+ ExpDesc v; /* LHS variable. */
+ struct LHSVarList *prev; /* Link to previous LHS variable. */
+} LHSVarList;
+
+/* Eliminate write-after-read hazards for local variable assignment. */
+static void assign_hazard(LexState *ls, LHSVarList *lh, const ExpDesc *v)
+{
+ FuncState *fs = ls->fs;
+ BCReg reg = v->u.s.info; /* Check against this variable. */
+ BCReg tmp = fs->freereg; /* Rename to this temp. register (if needed). */
+ int hazard = 0;
+ for (; lh; lh = lh->prev) {
+ if (lh->v.k == VINDEXED) {
+ if (lh->v.u.s.info == reg) { /* t[i], t = 1, 2 */
+ hazard = 1;
+ lh->v.u.s.info = tmp;
+ }
+ if (lh->v.u.s.aux == reg) { /* t[i], i = 1, 2 */
+ hazard = 1;
+ lh->v.u.s.aux = tmp;
+ }
+ }
+ }
+ if (hazard) {
+ bcemit_AD(fs, BC_MOV, tmp, reg); /* Rename conflicting variable. */
+ bcreg_reserve(fs, 1);
+ }
+}
+
+/* Adjust LHS/RHS of an assignment. */
+static void assign_adjust(LexState *ls, BCReg nvars, BCReg nexps, ExpDesc *e)
+{
+ FuncState *fs = ls->fs;
+ int32_t extra = (int32_t)nvars - (int32_t)nexps;
+ if (e->k == VCALL) {
+ extra++; /* Compensate for the VCALL itself. */
+ if (extra < 0) extra = 0;
+ setbc_b(bcptr(fs, e), extra+1); /* Fixup call results. */
+ if (extra > 1) bcreg_reserve(fs, (BCReg)extra-1);
+ } else {
+ if (e->k != VVOID)
+ expr_tonextreg(fs, e); /* Close last expression. */
+ if (extra > 0) { /* Leftover LHS are set to nil. */
+ BCReg reg = fs->freereg;
+ bcreg_reserve(fs, (BCReg)extra);
+ bcemit_nil(fs, reg, (BCReg)extra);
+ }
+ }
+ if (nexps > nvars)
+ ls->fs->freereg -= nexps - nvars; /* Drop leftover regs. */
+}
+
+/* Recursively parse assignment statement. */
+static void parse_assignment(LexState *ls, LHSVarList *lh, BCReg nvars)
+{
+ ExpDesc e;
+ checkcond(ls, VLOCAL <= lh->v.k && lh->v.k <= VINDEXED, LJ_ERR_XSYNTAX);
+ if (lex_opt(ls, ',')) { /* Collect LHS list and recurse upwards. */
+ LHSVarList vl;
+ vl.prev = lh;
+ expr_primary(ls, &vl.v);
+ if (vl.v.k == VLOCAL)
+ assign_hazard(ls, lh, &vl.v);
+ checklimit(ls->fs, ls->level + nvars, LJ_MAX_XLEVEL, "variable names");
+ parse_assignment(ls, &vl, nvars+1);
+ } else { /* Parse RHS. */
+ BCReg nexps;
+ lex_check(ls, '=');
+ nexps = expr_list(ls, &e);
+ if (nexps == nvars) {
+ if (e.k == VCALL) {
+ if (bc_op(*bcptr(ls->fs, &e)) == BC_VARG) { /* Vararg assignment. */
+ ls->fs->freereg--;
+ e.k = VRELOCABLE;
+ } else { /* Multiple call results. */
+ e.u.s.info = e.u.s.aux; /* Base of call is not relocatable. */
+ e.k = VNONRELOC;
+ }
+ }
+ bcemit_store(ls->fs, &lh->v, &e);
+ return;
+ }
+ assign_adjust(ls, nvars, nexps, &e);
+ }
+ /* Assign RHS to LHS and recurse downwards. */
+ expr_init(&e, VNONRELOC, ls->fs->freereg-1);
+ bcemit_store(ls->fs, &lh->v, &e);
+}
+
+/* Parse call statement or assignment. */
+static void parse_call_assign(LexState *ls)
+{
+ FuncState *fs = ls->fs;
+ LHSVarList vl;
+ expr_primary(ls, &vl.v);
+ if (vl.v.k == VCALL) { /* Function call statement. */
+ setbc_b(bcptr(fs, &vl.v), 1); /* No results. */
+ } else { /* Start of an assignment. */
+ vl.prev = NULL;
+ parse_assignment(ls, &vl, 1);
+ }
+}
+
+/* Parse 'local' statement. */
+static void parse_local(LexState *ls)
+{
+ if (lex_opt(ls, TK_function)) { /* Local function declaration. */
+ ExpDesc v, b;
+ FuncState *fs = ls->fs;
+ var_new(ls, 0, lex_str(ls));
+ expr_init(&v, VLOCAL, fs->freereg);
+ v.u.s.aux = fs->varmap[fs->freereg];
+ bcreg_reserve(fs, 1);
+ var_add(ls, 1);
+ parse_body(ls, &b, 0, ls->linenumber);
+ /* bcemit_store(fs, &v, &b) without setting VSTACK_VAR_RW. */
+ expr_free(fs, &b);
+ expr_toreg(fs, &b, v.u.s.info);
+ /* The upvalue is in scope, but the local is only valid after the store. */
+ var_get(ls, fs, fs->nactvar - 1).startpc = fs->pc;
+ } else { /* Local variable declaration. */
+ ExpDesc e;
+ BCReg nexps, nvars = 0;
+ do { /* Collect LHS. */
+ var_new(ls, nvars++, lex_str(ls));
+ } while (lex_opt(ls, ','));
+ if (lex_opt(ls, '=')) { /* Optional RHS. */
+ nexps = expr_list(ls, &e);
+ } else { /* Or implicitly set to nil. */
+ e.k = VVOID;
+ nexps = 0;
+ }
+ assign_adjust(ls, nvars, nexps, &e);
+ var_add(ls, nvars);
+ }
+}
+
+/* Parse 'function' statement. */
+static void parse_func(LexState *ls, BCLine line)
+{
+ FuncState *fs;
+ ExpDesc v, b;
+ int needself = 0;
+ lj_lex_next(ls); /* Skip 'function'. */
+ /* Parse function name. */
+ var_lookup(ls, &v);
+ while (ls->token == '.') /* Multiple dot-separated fields. */
+ expr_field(ls, &v);
+ if (ls->token == ':') { /* Optional colon to signify method call. */
+ needself = 1;
+ expr_field(ls, &v);
+ }
+ parse_body(ls, &b, needself, line);
+ fs = ls->fs;
+ bcemit_store(fs, &v, &b);
+ fs->bcbase[fs->pc - 1].line = line; /* Set line for the store. */
+}
+
+/* -- Control transfer statements ----------------------------------------- */
+
+/* Check for end of block. */
+static int endofblock(LexToken token)
+{
+ switch (token) {
+ case TK_else: case TK_elseif: case TK_end: case TK_until: case TK_eof:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+/* Parse 'return' statement. */
+static void parse_return(LexState *ls)
+{
+ BCIns ins;
+ FuncState *fs = ls->fs;
+ lj_lex_next(ls); /* Skip 'return'. */
+ fs->flags |= PROTO_HAS_RETURN;
+ if (endofblock(ls->token) || ls->token == ';') { /* Bare return. */
+ ins = BCINS_AD(BC_RET0, 0, 1);
+ } else { /* Return with one or more values. */
+ ExpDesc e; /* Receives the _last_ expression in the list. */
+ BCReg nret = expr_list(ls, &e);
+ if (nret == 1) { /* Return one result. */
+ if (e.k == VCALL) { /* Check for tail call. */
+ BCIns *ip = bcptr(fs, &e);
+ /* It doesn't pay off to add BC_VARGT just for 'return ...'. */
+ if (bc_op(*ip) == BC_VARG) goto notailcall;
+ fs->pc--;
+ ins = BCINS_AD(bc_op(*ip)-BC_CALL+BC_CALLT, bc_a(*ip), bc_c(*ip));
+ } else { /* Can return the result from any register. */
+ ins = BCINS_AD(BC_RET1, expr_toanyreg(fs, &e), 2);
+ }
+ } else {
+ if (e.k == VCALL) { /* Append all results from a call. */
+ notailcall:
+ setbc_b(bcptr(fs, &e), 0);
+ ins = BCINS_AD(BC_RETM, fs->nactvar, e.u.s.aux - fs->nactvar);
+ } else {
+ expr_tonextreg(fs, &e); /* Force contiguous registers. */
+ ins = BCINS_AD(BC_RET, fs->nactvar, nret+1);
+ }
+ }
+ }
+ if (fs->flags & PROTO_CHILD)
+ bcemit_AJ(fs, BC_UCLO, 0, 0); /* May need to close upvalues first. */
+ bcemit_INS(fs, ins);
+}
+
+/* Parse 'break' statement. */
+static void parse_break(LexState *ls)
+{
+ ls->fs->bl->flags |= FSCOPE_BREAK;
+ gola_new(ls, NAME_BREAK, VSTACK_GOTO, bcemit_jmp(ls->fs));
+}
+
+/* Parse 'goto' statement. */
+static void parse_goto(LexState *ls)
+{
+ FuncState *fs = ls->fs;
+ GCstr *name = lex_str(ls);
+ VarInfo *vl = gola_findlabel(ls, name);
+ if (vl) /* Treat backwards goto within same scope like a loop. */
+ bcemit_AJ(fs, BC_LOOP, vl->slot, -1); /* No BC range check. */
+ fs->bl->flags |= FSCOPE_GOLA;
+ gola_new(ls, name, VSTACK_GOTO, bcemit_jmp(fs));
+}
+
+/* Parse label. */
+static void parse_label(LexState *ls)
+{
+ FuncState *fs = ls->fs;
+ GCstr *name;
+ MSize idx;
+ fs->lasttarget = fs->pc;
+ fs->bl->flags |= FSCOPE_GOLA;
+ lj_lex_next(ls); /* Skip '::'. */
+ name = lex_str(ls);
+ if (gola_findlabel(ls, name))
+ lj_lex_error(ls, 0, LJ_ERR_XLDUP, strdata(name));
+ idx = gola_new(ls, name, VSTACK_LABEL, fs->pc);
+ lex_check(ls, TK_label);
+ /* Recursively parse trailing statements: labels and ';' (Lua 5.2 only). */
+ for (;;) {
+ if (ls->token == TK_label) {
+ synlevel_begin(ls);
+ parse_label(ls);
+ synlevel_end(ls);
+ } else if (LJ_52 && ls->token == ';') {
+ lj_lex_next(ls);
+ } else {
+ break;
+ }
+ }
+ /* Trailing label is considered to be outside of scope. */
+ if (endofblock(ls->token) && ls->token != TK_until)
+ ls->vstack[idx].slot = fs->bl->nactvar;
+ gola_resolve(ls, fs->bl, idx);
+}
+
+/* -- Blocks, loops and conditional statements ---------------------------- */
+
+/* Parse a block. */
+static void parse_block(LexState *ls)
+{
+ FuncState *fs = ls->fs;
+ FuncScope bl;
+ fscope_begin(fs, &bl, 0);
+ parse_chunk(ls);
+ fscope_end(fs);
+}
+
+/* Parse 'while' statement. */
+static void parse_while(LexState *ls, BCLine line)
+{
+ FuncState *fs = ls->fs;
+ BCPos start, loop, condexit;
+ FuncScope bl;
+ lj_lex_next(ls); /* Skip 'while'. */
+ start = fs->lasttarget = fs->pc;
+ condexit = expr_cond(ls);
+ fscope_begin(fs, &bl, FSCOPE_LOOP);
+ lex_check(ls, TK_do);
+ loop = bcemit_AD(fs, BC_LOOP, fs->nactvar, 0);
+ parse_block(ls);
+ jmp_patch(fs, bcemit_jmp(fs), start);
+ lex_match(ls, TK_end, TK_while, line);
+ fscope_end(fs);
+ jmp_tohere(fs, condexit);
+ jmp_patchins(fs, loop, fs->pc);
+}
+
+/* Parse 'repeat' statement. */
+static void parse_repeat(LexState *ls, BCLine line)
+{
+ FuncState *fs = ls->fs;
+ BCPos loop = fs->lasttarget = fs->pc;
+ BCPos condexit;
+ FuncScope bl1, bl2;
+ fscope_begin(fs, &bl1, FSCOPE_LOOP); /* Breakable loop scope. */
+ fscope_begin(fs, &bl2, 0); /* Inner scope. */
+ lj_lex_next(ls); /* Skip 'repeat'. */
+ bcemit_AD(fs, BC_LOOP, fs->nactvar, 0);
+ parse_chunk(ls);
+ lex_match(ls, TK_until, TK_repeat, line);
+ condexit = expr_cond(ls); /* Parse condition (still inside inner scope). */
+ if (!(bl2.flags & FSCOPE_UPVAL)) { /* No upvalues? Just end inner scope. */
+ fscope_end(fs);
+ } else { /* Otherwise generate: cond: UCLO+JMP out, !cond: UCLO+JMP loop. */
+ parse_break(ls); /* Break from loop and close upvalues. */
+ jmp_tohere(fs, condexit);
+ fscope_end(fs); /* End inner scope and close upvalues. */
+ condexit = bcemit_jmp(fs);
+ }
+ jmp_patch(fs, condexit, loop); /* Jump backwards if !cond. */
+ jmp_patchins(fs, loop, fs->pc);
+ fscope_end(fs); /* End loop scope. */
+}
+
+/* Parse numeric 'for'. */
+static void parse_for_num(LexState *ls, GCstr *varname, BCLine line)
+{
+ FuncState *fs = ls->fs;
+ BCReg base = fs->freereg;
+ FuncScope bl;
+ BCPos loop, loopend;
+ /* Hidden control variables. */
+ var_new_fixed(ls, FORL_IDX, VARNAME_FOR_IDX);
+ var_new_fixed(ls, FORL_STOP, VARNAME_FOR_STOP);
+ var_new_fixed(ls, FORL_STEP, VARNAME_FOR_STEP);
+ /* Visible copy of index variable. */
+ var_new(ls, FORL_EXT, varname);
+ lex_check(ls, '=');
+ expr_next(ls);
+ lex_check(ls, ',');
+ expr_next(ls);
+ if (lex_opt(ls, ',')) {
+ expr_next(ls);
+ } else {
+ bcemit_AD(fs, BC_KSHORT, fs->freereg, 1); /* Default step is 1. */
+ bcreg_reserve(fs, 1);
+ }
+ var_add(ls, 3); /* Hidden control variables. */
+ lex_check(ls, TK_do);
+ loop = bcemit_AJ(fs, BC_FORI, base, NO_JMP);
+ fscope_begin(fs, &bl, 0); /* Scope for visible variables. */
+ var_add(ls, 1);
+ bcreg_reserve(fs, 1);
+ parse_block(ls);
+ fscope_end(fs);
+ /* Perform loop inversion. Loop control instructions are at the end. */
+ loopend = bcemit_AJ(fs, BC_FORL, base, NO_JMP);
+ fs->bcbase[loopend].line = line; /* Fix line for control ins. */
+ jmp_patchins(fs, loopend, loop+1);
+ jmp_patchins(fs, loop, fs->pc);
+}
+
+/* Try to predict whether the iterator is next() and specialize the bytecode.
+** Detecting next() and pairs() by name is simplistic, but quite effective.
+** The interpreter backs off if the check for the closure fails at runtime.
+*/
+static int predict_next(LexState *ls, FuncState *fs, BCPos pc)
+{
+ BCIns ins = fs->bcbase[pc].ins;
+ GCstr *name;
+ cTValue *o;
+ switch (bc_op(ins)) {
+ case BC_MOV:
+ name = gco2str(gcref(var_get(ls, fs, bc_d(ins)).name));
+ break;
+ case BC_UGET:
+ name = gco2str(gcref(ls->vstack[fs->uvmap[bc_d(ins)]].name));
+ break;
+ case BC_GGET:
+ /* There's no inverse index (yet), so lookup the strings. */
+ o = lj_tab_getstr(fs->kt, lj_str_newlit(ls->L, "pairs"));
+ if (o && tvhaskslot(o) && tvkslot(o) == bc_d(ins))
+ return 1;
+ o = lj_tab_getstr(fs->kt, lj_str_newlit(ls->L, "next"));
+ if (o && tvhaskslot(o) && tvkslot(o) == bc_d(ins))
+ return 1;
+ return 0;
+ default:
+ return 0;
+ }
+ return (name->len == 5 && !strcmp(strdata(name), "pairs")) ||
+ (name->len == 4 && !strcmp(strdata(name), "next"));
+}
+
+/* Parse 'for' iterator. */
+static void parse_for_iter(LexState *ls, GCstr *indexname)
+{
+ FuncState *fs = ls->fs;
+ ExpDesc e;
+ BCReg nvars = 0;
+ BCLine line;
+ BCReg base = fs->freereg + 3;
+ BCPos loop, loopend, exprpc = fs->pc;
+ FuncScope bl;
+ int isnext;
+ /* Hidden control variables. */
+ var_new_fixed(ls, nvars++, VARNAME_FOR_GEN);
+ var_new_fixed(ls, nvars++, VARNAME_FOR_STATE);
+ var_new_fixed(ls, nvars++, VARNAME_FOR_CTL);
+ /* Visible variables returned from iterator. */
+ var_new(ls, nvars++, indexname);
+ while (lex_opt(ls, ','))
+ var_new(ls, nvars++, lex_str(ls));
+ lex_check(ls, TK_in);
+ line = ls->linenumber;
+ assign_adjust(ls, 3, expr_list(ls, &e), &e);
+ bcreg_bump(fs, 3); /* The iterator needs another 3 slots (func + 2 args). */
+ isnext = (nvars <= 5 && predict_next(ls, fs, exprpc));
+ var_add(ls, 3); /* Hidden control variables. */
+ lex_check(ls, TK_do);
+ loop = bcemit_AJ(fs, isnext ? BC_ISNEXT : BC_JMP, base, NO_JMP);
+ fscope_begin(fs, &bl, 0); /* Scope for visible variables. */
+ var_add(ls, nvars-3);
+ bcreg_reserve(fs, nvars-3);
+ parse_block(ls);
+ fscope_end(fs);
+ /* Perform loop inversion. Loop control instructions are at the end. */
+ jmp_patchins(fs, loop, fs->pc);
+ bcemit_ABC(fs, isnext ? BC_ITERN : BC_ITERC, base, nvars-3+1, 2+1);
+ loopend = bcemit_AJ(fs, BC_ITERL, base, NO_JMP);
+ fs->bcbase[loopend-1].line = line; /* Fix line for control ins. */
+ fs->bcbase[loopend].line = line;
+ jmp_patchins(fs, loopend, loop+1);
+}
+
+/* Parse 'for' statement. */
+static void parse_for(LexState *ls, BCLine line)
+{
+ FuncState *fs = ls->fs;
+ GCstr *varname;
+ FuncScope bl;
+ fscope_begin(fs, &bl, FSCOPE_LOOP);
+ lj_lex_next(ls); /* Skip 'for'. */
+ varname = lex_str(ls); /* Get first variable name. */
+ if (ls->token == '=')
+ parse_for_num(ls, varname, line);
+ else if (ls->token == ',' || ls->token == TK_in)
+ parse_for_iter(ls, varname);
+ else
+ err_syntax(ls, LJ_ERR_XFOR);
+ lex_match(ls, TK_end, TK_for, line);
+ fscope_end(fs); /* Resolve break list. */
+}
+
+/* Parse condition and 'then' block. */
+static BCPos parse_then(LexState *ls)
+{
+ BCPos condexit;
+ lj_lex_next(ls); /* Skip 'if' or 'elseif'. */
+ condexit = expr_cond(ls);
+ lex_check(ls, TK_then);
+ parse_block(ls);
+ return condexit;
+}
+
+/* Parse 'if' statement. */
+static void parse_if(LexState *ls, BCLine line)
+{
+ FuncState *fs = ls->fs;
+ BCPos flist;
+ BCPos escapelist = NO_JMP;
+ flist = parse_then(ls);
+ while (ls->token == TK_elseif) { /* Parse multiple 'elseif' blocks. */
+ jmp_append(fs, &escapelist, bcemit_jmp(fs));
+ jmp_tohere(fs, flist);
+ flist = parse_then(ls);
+ }
+ if (ls->token == TK_else) { /* Parse optional 'else' block. */
+ jmp_append(fs, &escapelist, bcemit_jmp(fs));
+ jmp_tohere(fs, flist);
+ lj_lex_next(ls); /* Skip 'else'. */
+ parse_block(ls);
+ } else {
+ jmp_append(fs, &escapelist, flist);
+ }
+ jmp_tohere(fs, escapelist);
+ lex_match(ls, TK_end, TK_if, line);
+}
+
+/* -- Parse statements ---------------------------------------------------- */
+
+/* Parse a statement. Returns 1 if it must be the last one in a chunk. */
+static int parse_stmt(LexState *ls)
+{
+ BCLine line = ls->linenumber;
+ switch (ls->token) {
+ case TK_if:
+ parse_if(ls, line);
+ break;
+ case TK_while:
+ parse_while(ls, line);
+ break;
+ case TK_do:
+ lj_lex_next(ls);
+ parse_block(ls);
+ lex_match(ls, TK_end, TK_do, line);
+ break;
+ case TK_for:
+ parse_for(ls, line);
+ break;
+ case TK_repeat:
+ parse_repeat(ls, line);
+ break;
+ case TK_function:
+ parse_func(ls, line);
+ break;
+ case TK_local:
+ lj_lex_next(ls);
+ parse_local(ls);
+ break;
+ case TK_return:
+ parse_return(ls);
+ return 1; /* Must be last. */
+ case TK_break:
+ lj_lex_next(ls);
+ parse_break(ls);
+ return !LJ_52; /* Must be last in Lua 5.1. */
+#if LJ_52
+ case ';':
+ lj_lex_next(ls);
+ break;
+#endif
+ case TK_label:
+ parse_label(ls);
+ break;
+ case TK_goto:
+ if (LJ_52 || lj_lex_lookahead(ls) == TK_name) {
+ lj_lex_next(ls);
+ parse_goto(ls);
+ break;
+ }
+ /* fallthrough */
+ default:
+ parse_call_assign(ls);
+ break;
+ }
+ return 0;
+}
+
+/* A chunk is a list of statements optionally separated by semicolons. */
+static void parse_chunk(LexState *ls)
+{
+ int islast = 0;
+ synlevel_begin(ls);
+ while (!islast && !endofblock(ls->token)) {
+ islast = parse_stmt(ls);
+ lex_opt(ls, ';');
+ lua_assert(ls->fs->framesize >= ls->fs->freereg &&
+ ls->fs->freereg >= ls->fs->nactvar);
+ ls->fs->freereg = ls->fs->nactvar; /* Free registers after each stmt. */
+ }
+ synlevel_end(ls);
+}
+
+/* Entry point of bytecode parser. */
+GCproto *lj_parse(LexState *ls)
+{
+ FuncState fs;
+ FuncScope bl;
+ GCproto *pt;
+ lua_State *L = ls->L;
+#ifdef LUAJIT_DISABLE_DEBUGINFO
+ ls->chunkname = lj_str_newlit(L, "=");
+#else
+ ls->chunkname = lj_str_newz(L, ls->chunkarg);
+#endif
+ setstrV(L, L->top, ls->chunkname); /* Anchor chunkname string. */
+ incr_top(L);
+ ls->level = 0;
+ fs_init(ls, &fs);
+ fs.linedefined = 0;
+ fs.numparams = 0;
+ fs.bcbase = NULL;
+ fs.bclim = 0;
+ fs.flags |= PROTO_VARARG; /* Main chunk is always a vararg func. */
+ fscope_begin(&fs, &bl, 0);
+ bcemit_AD(&fs, BC_FUNCV, 0, 0); /* Placeholder. */
+ lj_lex_next(ls); /* Read-ahead first token. */
+ parse_chunk(ls);
+ if (ls->token != TK_eof)
+ err_token(ls, TK_eof);
+ pt = fs_finish(ls, ls->linenumber);
+ L->top--; /* Drop chunkname. */
+ lua_assert(fs.prev == NULL);
+ lua_assert(ls->fs == NULL);
+ lua_assert(pt->sizeuv == 0);
+ return pt;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_parse.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_parse.h
new file mode 100644
index 0000000..ceeab69
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_parse.h
@@ -0,0 +1,18 @@
+/*
+** Lua parser (source code -> bytecode).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_PARSE_H
+#define _LJ_PARSE_H
+
+#include "lj_obj.h"
+#include "lj_lex.h"
+
+LJ_FUNC GCproto *lj_parse(LexState *ls);
+LJ_FUNC GCstr *lj_parse_keepstr(LexState *ls, const char *str, size_t l);
+#if LJ_HASFFI
+LJ_FUNC void lj_parse_keepcdata(LexState *ls, TValue *tv, GCcdata *cd);
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_record.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_record.c
new file mode 100644
index 0000000..bc4e8a6
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_record.c
@@ -0,0 +1,2263 @@
+/*
+** Trace recorder (bytecode -> SSA IR).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_record_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT
+
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_meta.h"
+#include "lj_frame.h"
+#if LJ_HASFFI
+#include "lj_ctype.h"
+#endif
+#include "lj_bc.h"
+#include "lj_ff.h"
+#include "lj_ir.h"
+#include "lj_jit.h"
+#include "lj_ircall.h"
+#include "lj_iropt.h"
+#include "lj_trace.h"
+#include "lj_record.h"
+#include "lj_ffrecord.h"
+#include "lj_snap.h"
+#include "lj_dispatch.h"
+#include "lj_vm.h"
+
+/* Some local macros to save typing. Undef'd at the end. */
+#define IR(ref) (&J->cur.ir[(ref)])
+
+/* Pass IR on to next optimization in chain (FOLD). */
+#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))
+
+/* Emit raw IR without passing through optimizations. */
+#define emitir_raw(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J))
+
+/* -- Sanity checks ------------------------------------------------------- */
+
+#ifdef LUA_USE_ASSERT
+/* Sanity check the whole IR -- sloooow. */
+static void rec_check_ir(jit_State *J)
+{
+ IRRef i, nins = J->cur.nins, nk = J->cur.nk;
+ lua_assert(nk <= REF_BIAS && nins >= REF_BIAS && nins < 65536);
+ for (i = nins-1; i >= nk; i--) {
+ IRIns *ir = IR(i);
+ uint32_t mode = lj_ir_mode[ir->o];
+ IRRef op1 = ir->op1;
+ IRRef op2 = ir->op2;
+ switch (irm_op1(mode)) {
+ case IRMnone: lua_assert(op1 == 0); break;
+ case IRMref: lua_assert(op1 >= nk);
+ lua_assert(i >= REF_BIAS ? op1 < i : op1 > i); break;
+ case IRMlit: break;
+ case IRMcst: lua_assert(i < REF_BIAS); continue;
+ }
+ switch (irm_op2(mode)) {
+ case IRMnone: lua_assert(op2 == 0); break;
+ case IRMref: lua_assert(op2 >= nk);
+ lua_assert(i >= REF_BIAS ? op2 < i : op2 > i); break;
+ case IRMlit: break;
+ case IRMcst: lua_assert(0); break;
+ }
+ if (ir->prev) {
+ lua_assert(ir->prev >= nk);
+ lua_assert(i >= REF_BIAS ? ir->prev < i : ir->prev > i);
+ lua_assert(ir->o == IR_NOP || IR(ir->prev)->o == ir->o);
+ }
+ }
+}
+
+/* Compare stack slots and frames of the recorder and the VM. */
+static void rec_check_slots(jit_State *J)
+{
+ BCReg s, nslots = J->baseslot + J->maxslot;
+ int32_t depth = 0;
+ cTValue *base = J->L->base - J->baseslot;
+ lua_assert(J->baseslot >= 1);
+ lua_assert(J->baseslot == 1 || (J->slot[J->baseslot-1] & TREF_FRAME));
+ lua_assert(nslots <= LJ_MAX_JSLOTS);
+ for (s = 0; s < nslots; s++) {
+ TRef tr = J->slot[s];
+ if (tr) {
+ cTValue *tv = &base[s];
+ IRRef ref = tref_ref(tr);
+ IRIns *ir;
+ lua_assert(ref >= J->cur.nk && ref < J->cur.nins);
+ ir = IR(ref);
+ lua_assert(irt_t(ir->t) == tref_t(tr));
+ if (s == 0) {
+ lua_assert(tref_isfunc(tr));
+ } else if ((tr & TREF_FRAME)) {
+ GCfunc *fn = gco2func(frame_gc(tv));
+ BCReg delta = (BCReg)(tv - frame_prev(tv));
+ lua_assert(tref_isfunc(tr));
+ if (tref_isk(tr)) lua_assert(fn == ir_kfunc(ir));
+ lua_assert(s > delta ? (J->slot[s-delta] & TREF_FRAME) : (s == delta));
+ depth++;
+ } else if ((tr & TREF_CONT)) {
+ lua_assert(ir_kptr(ir) == gcrefp(tv->gcr, void));
+ lua_assert((J->slot[s+1] & TREF_FRAME));
+ depth++;
+ } else {
+ if (tvisnumber(tv))
+ lua_assert(tref_isnumber(tr)); /* Could be IRT_INT etc., too. */
+ else
+ lua_assert(itype2irt(tv) == tref_type(tr));
+ if (tref_isk(tr)) { /* Compare constants. */
+ TValue tvk;
+ lj_ir_kvalue(J->L, &tvk, ir);
+ if (!(tvisnum(&tvk) && tvisnan(&tvk)))
+ lua_assert(lj_obj_equal(tv, &tvk));
+ else
+ lua_assert(tvisnum(tv) && tvisnan(tv));
+ }
+ }
+ }
+ }
+ lua_assert(J->framedepth == depth);
+}
+#endif
+
+/* -- Type handling and specialization ------------------------------------ */
+
+/* Note: these functions return tagged references (TRef). */
+
+/* Specialize a slot to a specific type. Note: slot can be negative! */
+static TRef sloadt(jit_State *J, int32_t slot, IRType t, int mode)
+{
+ /* Caller may set IRT_GUARD in t. */
+ TRef ref = emitir_raw(IRT(IR_SLOAD, t), (int32_t)J->baseslot+slot, mode);
+ J->base[slot] = ref;
+ return ref;
+}
+
+/* Specialize a slot to the runtime type. Note: slot can be negative! */
+static TRef sload(jit_State *J, int32_t slot)
+{
+ IRType t = itype2irt(&J->L->base[slot]);
+ TRef ref = emitir_raw(IRTG(IR_SLOAD, t), (int32_t)J->baseslot+slot,
+ IRSLOAD_TYPECHECK);
+ if (irtype_ispri(t)) ref = TREF_PRI(t); /* Canonicalize primitive refs. */
+ J->base[slot] = ref;
+ return ref;
+}
+
+/* Get TRef from slot. Load slot and specialize if not done already. */
+#define getslot(J, s) (J->base[(s)] ? J->base[(s)] : sload(J, (int32_t)(s)))
+
+/* Get TRef for current function. */
+static TRef getcurrf(jit_State *J)
+{
+ if (J->base[-1])
+ return J->base[-1];
+ lua_assert(J->baseslot == 1);
+ return sloadt(J, -1, IRT_FUNC, IRSLOAD_READONLY);
+}
+
+/* Compare for raw object equality.
+** Returns 0 if the objects are the same.
+** Returns 1 if they are different, but the same type.
+** Returns 2 for two different types.
+** Comparisons between primitives always return 1 -- no caller cares about it.
+*/
+int lj_record_objcmp(jit_State *J, TRef a, TRef b, cTValue *av, cTValue *bv)
+{
+ int diff = !lj_obj_equal(av, bv);
+ if (!tref_isk2(a, b)) { /* Shortcut, also handles primitives. */
+ IRType ta = tref_isinteger(a) ? IRT_INT : tref_type(a);
+ IRType tb = tref_isinteger(b) ? IRT_INT : tref_type(b);
+ if (ta != tb) {
+ /* Widen mixed number/int comparisons to number/number comparison. */
+ if (ta == IRT_INT && tb == IRT_NUM) {
+ a = emitir(IRTN(IR_CONV), a, IRCONV_NUM_INT);
+ ta = IRT_NUM;
+ } else if (ta == IRT_NUM && tb == IRT_INT) {
+ b = emitir(IRTN(IR_CONV), b, IRCONV_NUM_INT);
+ } else {
+ return 2; /* Two different types are never equal. */
+ }
+ }
+ emitir(IRTG(diff ? IR_NE : IR_EQ, ta), a, b);
+ }
+ return diff;
+}
+
+/* Constify a value. Returns 0 for non-representable object types. */
+TRef lj_record_constify(jit_State *J, cTValue *o)
+{
+ if (tvisgcv(o))
+ return lj_ir_kgc(J, gcV(o), itype2irt(o));
+ else if (tvisint(o))
+ return lj_ir_kint(J, intV(o));
+ else if (tvisnum(o))
+ return lj_ir_knumint(J, numV(o));
+ else if (tvisbool(o))
+ return TREF_PRI(itype2irt(o));
+ else
+ return 0; /* Can't represent lightuserdata (pointless). */
+}
+
+/* -- Record loop ops ----------------------------------------------------- */
+
+/* Loop event. */
+typedef enum {
+ LOOPEV_LEAVE, /* Loop is left or not entered. */
+ LOOPEV_ENTERLO, /* Loop is entered with a low iteration count left. */
+ LOOPEV_ENTER /* Loop is entered. */
+} LoopEvent;
+
+/* Canonicalize slots: convert integers to numbers. */
+static void canonicalize_slots(jit_State *J)
+{
+ BCReg s;
+ if (LJ_DUALNUM) return;
+ for (s = J->baseslot+J->maxslot-1; s >= 1; s--) {
+ TRef tr = J->slot[s];
+ if (tref_isinteger(tr)) {
+ IRIns *ir = IR(tref_ref(tr));
+ if (!(ir->o == IR_SLOAD && (ir->op2 & IRSLOAD_READONLY)))
+ J->slot[s] = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT);
+ }
+ }
+}
+
+/* Stop recording. */
+static void rec_stop(jit_State *J, TraceLink linktype, TraceNo lnk)
+{
+ lj_trace_end(J);
+ J->cur.linktype = (uint8_t)linktype;
+ J->cur.link = (uint16_t)lnk;
+ /* Looping back at the same stack level? */
+ if (lnk == J->cur.traceno && J->framedepth + J->retdepth == 0) {
+ if ((J->flags & JIT_F_OPT_LOOP)) /* Shall we try to create a loop? */
+ goto nocanon; /* Do not canonicalize or we lose the narrowing. */
+ if (J->cur.root) /* Otherwise ensure we always link to the root trace. */
+ J->cur.link = J->cur.root;
+ }
+ canonicalize_slots(J);
+nocanon:
+ /* Note: all loop ops must set J->pc to the following instruction! */
+ lj_snap_add(J); /* Add loop snapshot. */
+ J->needsnap = 0;
+ J->mergesnap = 1; /* In case recording continues. */
+}
+
+/* Search bytecode backwards for a int/num constant slot initializer. */
+static TRef find_kinit(jit_State *J, const BCIns *endpc, BCReg slot, IRType t)
+{
+ /* This algorithm is rather simplistic and assumes quite a bit about
+ ** how the bytecode is generated. It works fine for FORI initializers,
+ ** but it won't necessarily work in other cases (e.g. iterator arguments).
+ ** It doesn't do anything fancy, either (like backpropagating MOVs).
+ */
+ const BCIns *pc, *startpc = proto_bc(J->pt);
+ for (pc = endpc-1; pc > startpc; pc--) {
+ BCIns ins = *pc;
+ BCOp op = bc_op(ins);
+ /* First try to find the last instruction that stores to this slot. */
+ if (bcmode_a(op) == BCMbase && bc_a(ins) <= slot) {
+ return 0; /* Multiple results, e.g. from a CALL or KNIL. */
+ } else if (bcmode_a(op) == BCMdst && bc_a(ins) == slot) {
+ if (op == BC_KSHORT || op == BC_KNUM) { /* Found const. initializer. */
+ /* Now try to verify there's no forward jump across it. */
+ const BCIns *kpc = pc;
+ for (; pc > startpc; pc--)
+ if (bc_op(*pc) == BC_JMP) {
+ const BCIns *target = pc+bc_j(*pc)+1;
+ if (target > kpc && target <= endpc)
+ return 0; /* Conditional assignment. */
+ }
+ if (op == BC_KSHORT) {
+ int32_t k = (int32_t)(int16_t)bc_d(ins);
+ return t == IRT_INT ? lj_ir_kint(J, k) : lj_ir_knum(J, (lua_Number)k);
+ } else {
+ cTValue *tv = proto_knumtv(J->pt, bc_d(ins));
+ if (t == IRT_INT) {
+ int32_t k = numberVint(tv);
+ if (tvisint(tv) || numV(tv) == (lua_Number)k) /* -0 is ok here. */
+ return lj_ir_kint(J, k);
+ return 0; /* Type mismatch. */
+ } else {
+ return lj_ir_knum(J, numberVnum(tv));
+ }
+ }
+ }
+ return 0; /* Non-constant initializer. */
+ }
+ }
+ return 0; /* No assignment to this slot found? */
+}
+
+/* Load and optionally convert a FORI argument from a slot. */
+static TRef fori_load(jit_State *J, BCReg slot, IRType t, int mode)
+{
+ int conv = (tvisint(&J->L->base[slot]) != (t==IRT_INT)) ? IRSLOAD_CONVERT : 0;
+ return sloadt(J, (int32_t)slot,
+ t + (((mode & IRSLOAD_TYPECHECK) ||
+ (conv && t == IRT_INT && !(mode >> 16))) ?
+ IRT_GUARD : 0),
+ mode + conv);
+}
+
+/* Peek before FORI to find a const initializer. Otherwise load from slot. */
+static TRef fori_arg(jit_State *J, const BCIns *fori, BCReg slot,
+ IRType t, int mode)
+{
+ TRef tr = J->base[slot];
+ if (!tr) {
+ tr = find_kinit(J, fori, slot, t);
+ if (!tr)
+ tr = fori_load(J, slot, t, mode);
+ }
+ return tr;
+}
+
+/* Return the direction of the FOR loop iterator.
+** It's important to exactly reproduce the semantics of the interpreter.
+*/
+static int rec_for_direction(cTValue *o)
+{
+ return (tvisint(o) ? intV(o) : (int32_t)o->u32.hi) >= 0;
+}
+
+/* Simulate the runtime behavior of the FOR loop iterator. */
+static LoopEvent rec_for_iter(IROp *op, cTValue *o, int isforl)
+{
+ lua_Number stopv = numberVnum(&o[FORL_STOP]);
+ lua_Number idxv = numberVnum(&o[FORL_IDX]);
+ lua_Number stepv = numberVnum(&o[FORL_STEP]);
+ if (isforl)
+ idxv += stepv;
+ if (rec_for_direction(&o[FORL_STEP])) {
+ if (idxv <= stopv) {
+ *op = IR_LE;
+ return idxv + 2*stepv > stopv ? LOOPEV_ENTERLO : LOOPEV_ENTER;
+ }
+ *op = IR_GT; return LOOPEV_LEAVE;
+ } else {
+ if (stopv <= idxv) {
+ *op = IR_GE;
+ return idxv + 2*stepv < stopv ? LOOPEV_ENTERLO : LOOPEV_ENTER;
+ }
+ *op = IR_LT; return LOOPEV_LEAVE;
+ }
+}
+
+/* Record checks for FOR loop overflow and step direction. */
+static void rec_for_check(jit_State *J, IRType t, int dir,
+ TRef stop, TRef step, int init)
+{
+ if (!tref_isk(step)) {
+ /* Non-constant step: need a guard for the direction. */
+ TRef zero = (t == IRT_INT) ? lj_ir_kint(J, 0) : lj_ir_knum_zero(J);
+ emitir(IRTG(dir ? IR_GE : IR_LT, t), step, zero);
+ /* Add hoistable overflow checks for a narrowed FORL index. */
+ if (init && t == IRT_INT) {
+ if (tref_isk(stop)) {
+ /* Constant stop: optimize check away or to a range check for step. */
+ int32_t k = IR(tref_ref(stop))->i;
+ if (dir) {
+ if (k > 0)
+ emitir(IRTGI(IR_LE), step, lj_ir_kint(J, (int32_t)0x7fffffff-k));
+ } else {
+ if (k < 0)
+ emitir(IRTGI(IR_GE), step, lj_ir_kint(J, (int32_t)0x80000000-k));
+ }
+ } else {
+ /* Stop+step variable: need full overflow check. */
+ TRef tr = emitir(IRTGI(IR_ADDOV), step, stop);
+ emitir(IRTI(IR_USE), tr, 0); /* ADDOV is weak. Avoid dead result. */
+ }
+ }
+ } else if (init && t == IRT_INT && !tref_isk(stop)) {
+ /* Constant step: optimize overflow check to a range check for stop. */
+ int32_t k = IR(tref_ref(step))->i;
+ k = (int32_t)(dir ? 0x7fffffff : 0x80000000) - k;
+ emitir(IRTGI(dir ? IR_LE : IR_GE), stop, lj_ir_kint(J, k));
+ }
+}
+
+/* Record a FORL instruction. */
+static void rec_for_loop(jit_State *J, const BCIns *fori, ScEvEntry *scev,
+ int init)
+{
+ BCReg ra = bc_a(*fori);
+ cTValue *tv = &J->L->base[ra];
+ TRef idx = J->base[ra+FORL_IDX];
+ IRType t = idx ? tref_type(idx) :
+ (init || LJ_DUALNUM) ? lj_opt_narrow_forl(J, tv) : IRT_NUM;
+ int mode = IRSLOAD_INHERIT +
+ ((!LJ_DUALNUM || tvisint(tv) == (t == IRT_INT)) ? IRSLOAD_READONLY : 0);
+ TRef stop = fori_arg(J, fori, ra+FORL_STOP, t, mode);
+ TRef step = fori_arg(J, fori, ra+FORL_STEP, t, mode);
+ int tc, dir = rec_for_direction(&tv[FORL_STEP]);
+ lua_assert(bc_op(*fori) == BC_FORI || bc_op(*fori) == BC_JFORI);
+ scev->t.irt = t;
+ scev->dir = dir;
+ scev->stop = tref_ref(stop);
+ scev->step = tref_ref(step);
+ rec_for_check(J, t, dir, stop, step, init);
+ scev->start = tref_ref(find_kinit(J, fori, ra+FORL_IDX, IRT_INT));
+ tc = (LJ_DUALNUM &&
+ !(scev->start && irref_isk(scev->stop) && irref_isk(scev->step) &&
+ tvisint(&tv[FORL_IDX]) == (t == IRT_INT))) ?
+ IRSLOAD_TYPECHECK : 0;
+ if (tc) {
+ J->base[ra+FORL_STOP] = stop;
+ J->base[ra+FORL_STEP] = step;
+ }
+ if (!idx)
+ idx = fori_load(J, ra+FORL_IDX, t,
+ IRSLOAD_INHERIT + tc + (J->scev.start << 16));
+ if (!init)
+ J->base[ra+FORL_IDX] = idx = emitir(IRT(IR_ADD, t), idx, step);
+ J->base[ra+FORL_EXT] = idx;
+ scev->idx = tref_ref(idx);
+ setmref(scev->pc, fori);
+ J->maxslot = ra+FORL_EXT+1;
+}
+
+/* Record FORL/JFORL or FORI/JFORI. */
+static LoopEvent rec_for(jit_State *J, const BCIns *fori, int isforl)
+{
+ BCReg ra = bc_a(*fori);
+ TValue *tv = &J->L->base[ra];
+ TRef *tr = &J->base[ra];
+ IROp op;
+ LoopEvent ev;
+ TRef stop;
+ IRType t;
+ if (isforl) { /* Handle FORL/JFORL opcodes. */
+ TRef idx = tr[FORL_IDX];
+ if (mref(J->scev.pc, const BCIns) == fori && tref_ref(idx) == J->scev.idx) {
+ t = J->scev.t.irt;
+ stop = J->scev.stop;
+ idx = emitir(IRT(IR_ADD, t), idx, J->scev.step);
+ tr[FORL_EXT] = tr[FORL_IDX] = idx;
+ } else {
+ ScEvEntry scev;
+ rec_for_loop(J, fori, &scev, 0);
+ t = scev.t.irt;
+ stop = scev.stop;
+ }
+ } else { /* Handle FORI/JFORI opcodes. */
+ BCReg i;
+ lj_meta_for(J->L, tv);
+ t = (LJ_DUALNUM || tref_isint(tr[FORL_IDX])) ? lj_opt_narrow_forl(J, tv) :
+ IRT_NUM;
+ for (i = FORL_IDX; i <= FORL_STEP; i++) {
+ if (!tr[i]) sload(J, ra+i);
+ lua_assert(tref_isnumber_str(tr[i]));
+ if (tref_isstr(tr[i]))
+ tr[i] = emitir(IRTG(IR_STRTO, IRT_NUM), tr[i], 0);
+ if (t == IRT_INT) {
+ if (!tref_isinteger(tr[i]))
+ tr[i] = emitir(IRTGI(IR_CONV), tr[i], IRCONV_INT_NUM|IRCONV_CHECK);
+ } else {
+ if (!tref_isnum(tr[i]))
+ tr[i] = emitir(IRTN(IR_CONV), tr[i], IRCONV_NUM_INT);
+ }
+ }
+ tr[FORL_EXT] = tr[FORL_IDX];
+ stop = tr[FORL_STOP];
+ rec_for_check(J, t, rec_for_direction(&tv[FORL_STEP]),
+ stop, tr[FORL_STEP], 1);
+ }
+
+ ev = rec_for_iter(&op, tv, isforl);
+ if (ev == LOOPEV_LEAVE) {
+ J->maxslot = ra+FORL_EXT+1;
+ J->pc = fori+1;
+ } else {
+ J->maxslot = ra;
+ J->pc = fori+bc_j(*fori)+1;
+ }
+ lj_snap_add(J);
+
+ emitir(IRTG(op, t), tr[FORL_IDX], stop);
+
+ if (ev == LOOPEV_LEAVE) {
+ J->maxslot = ra;
+ J->pc = fori+bc_j(*fori)+1;
+ } else {
+ J->maxslot = ra+FORL_EXT+1;
+ J->pc = fori+1;
+ }
+ J->needsnap = 1;
+ return ev;
+}
+
+/* Record ITERL/JITERL. */
+static LoopEvent rec_iterl(jit_State *J, const BCIns iterins)
+{
+ BCReg ra = bc_a(iterins);
+ lua_assert(J->base[ra] != 0);
+ if (!tref_isnil(J->base[ra])) { /* Looping back? */
+ J->base[ra-1] = J->base[ra]; /* Copy result of ITERC to control var. */
+ J->maxslot = ra-1+bc_b(J->pc[-1]);
+ J->pc += bc_j(iterins)+1;
+ return LOOPEV_ENTER;
+ } else {
+ J->maxslot = ra-3;
+ J->pc++;
+ return LOOPEV_LEAVE;
+ }
+}
+
+/* Record LOOP/JLOOP. Now, that was easy. */
+static LoopEvent rec_loop(jit_State *J, BCReg ra)
+{
+ if (ra < J->maxslot) J->maxslot = ra;
+ J->pc++;
+ return LOOPEV_ENTER;
+}
+
+/* Check if a loop repeatedly failed to trace because it didn't loop back. */
+static int innerloopleft(jit_State *J, const BCIns *pc)
+{
+ ptrdiff_t i;
+ for (i = 0; i < PENALTY_SLOTS; i++)
+ if (mref(J->penalty[i].pc, const BCIns) == pc) {
+ if ((J->penalty[i].reason == LJ_TRERR_LLEAVE ||
+ J->penalty[i].reason == LJ_TRERR_LINNER) &&
+ J->penalty[i].val >= 2*PENALTY_MIN)
+ return 1;
+ break;
+ }
+ return 0;
+}
+
+/* Handle the case when an interpreted loop op is hit. */
+static void rec_loop_interp(jit_State *J, const BCIns *pc, LoopEvent ev)
+{
+ if (J->parent == 0) {
+ if (pc == J->startpc && J->framedepth + J->retdepth == 0) {
+ /* Same loop? */
+ if (ev == LOOPEV_LEAVE) /* Must loop back to form a root trace. */
+ lj_trace_err(J, LJ_TRERR_LLEAVE);
+ rec_stop(J, LJ_TRLINK_LOOP, J->cur.traceno); /* Looping root trace. */
+ } else if (ev != LOOPEV_LEAVE) { /* Entering inner loop? */
+ /* It's usually better to abort here and wait until the inner loop
+ ** is traced. But if the inner loop repeatedly didn't loop back,
+ ** this indicates a low trip count. In this case try unrolling
+ ** an inner loop even in a root trace. But it's better to be a bit
+ ** more conservative here and only do it for very short loops.
+ */
+ if (bc_j(*pc) != -1 && !innerloopleft(J, pc))
+ lj_trace_err(J, LJ_TRERR_LINNER); /* Root trace hit an inner loop. */
+ if ((ev != LOOPEV_ENTERLO &&
+ J->loopref && J->cur.nins - J->loopref > 24) || --J->loopunroll < 0)
+ lj_trace_err(J, LJ_TRERR_LUNROLL); /* Limit loop unrolling. */
+ J->loopref = J->cur.nins;
+ }
+ } else if (ev != LOOPEV_LEAVE) { /* Side trace enters an inner loop. */
+ J->loopref = J->cur.nins;
+ if (--J->loopunroll < 0)
+ lj_trace_err(J, LJ_TRERR_LUNROLL); /* Limit loop unrolling. */
+ } /* Side trace continues across a loop that's left or not entered. */
+}
+
+/* Handle the case when an already compiled loop op is hit. */
+static void rec_loop_jit(jit_State *J, TraceNo lnk, LoopEvent ev)
+{
+ if (J->parent == 0) { /* Root trace hit an inner loop. */
+ /* Better let the inner loop spawn a side trace back here. */
+ lj_trace_err(J, LJ_TRERR_LINNER);
+ } else if (ev != LOOPEV_LEAVE) { /* Side trace enters a compiled loop. */
+ J->instunroll = 0; /* Cannot continue across a compiled loop op. */
+ if (J->pc == J->startpc && J->framedepth + J->retdepth == 0)
+ rec_stop(J, LJ_TRLINK_LOOP, J->cur.traceno); /* Form an extra loop. */
+ else
+ rec_stop(J, LJ_TRLINK_ROOT, lnk); /* Link to the loop. */
+ } /* Side trace continues across a loop that's left or not entered. */
+}
+
+/* -- Record calls and returns -------------------------------------------- */
+
+/* Specialize to the runtime value of the called function or its prototype. */
+static TRef rec_call_specialize(jit_State *J, GCfunc *fn, TRef tr)
+{
+ TRef kfunc;
+ if (isluafunc(fn)) {
+ GCproto *pt = funcproto(fn);
+ /* Too many closures created? Probably not a monomorphic function. */
+ if (pt->flags >= PROTO_CLC_POLY) { /* Specialize to prototype instead. */
+ TRef trpt = emitir(IRT(IR_FLOAD, IRT_P32), tr, IRFL_FUNC_PC);
+ emitir(IRTG(IR_EQ, IRT_P32), trpt, lj_ir_kptr(J, proto_bc(pt)));
+ (void)lj_ir_kgc(J, obj2gco(pt), IRT_PROTO); /* Prevent GC of proto. */
+ return tr;
+ }
+ }
+ /* Otherwise specialize to the function (closure) value itself. */
+ kfunc = lj_ir_kfunc(J, fn);
+ emitir(IRTG(IR_EQ, IRT_FUNC), tr, kfunc);
+ return kfunc;
+}
+
+/* Record call setup. */
+static void rec_call_setup(jit_State *J, BCReg func, ptrdiff_t nargs)
+{
+ RecordIndex ix;
+ TValue *functv = &J->L->base[func];
+ TRef *fbase = &J->base[func];
+ ptrdiff_t i;
+ for (i = 0; i <= nargs; i++)
+ (void)getslot(J, func+i); /* Ensure func and all args have a reference. */
+ if (!tref_isfunc(fbase[0])) { /* Resolve __call metamethod. */
+ ix.tab = fbase[0];
+ copyTV(J->L, &ix.tabv, functv);
+ if (!lj_record_mm_lookup(J, &ix, MM_call) || !tref_isfunc(ix.mobj))
+ lj_trace_err(J, LJ_TRERR_NOMM);
+ for (i = ++nargs; i > 0; i--) /* Shift arguments up. */
+ fbase[i] = fbase[i-1];
+ fbase[0] = ix.mobj; /* Replace function. */
+ functv = &ix.mobjv;
+ }
+ fbase[0] = TREF_FRAME | rec_call_specialize(J, funcV(functv), fbase[0]);
+ J->maxslot = (BCReg)nargs;
+}
+
+/* Record call. */
+void lj_record_call(jit_State *J, BCReg func, ptrdiff_t nargs)
+{
+ rec_call_setup(J, func, nargs);
+ /* Bump frame. */
+ J->framedepth++;
+ J->base += func+1;
+ J->baseslot += func+1;
+ if (J->baseslot + J->maxslot >= LJ_MAX_JSLOTS)
+ lj_trace_err(J, LJ_TRERR_STACKOV);
+}
+
+/* Record tail call. */
+void lj_record_tailcall(jit_State *J, BCReg func, ptrdiff_t nargs)
+{
+ rec_call_setup(J, func, nargs);
+ if (frame_isvarg(J->L->base - 1)) {
+ BCReg cbase = (BCReg)frame_delta(J->L->base - 1);
+ if (--J->framedepth < 0)
+ lj_trace_err(J, LJ_TRERR_NYIRETL);
+ J->baseslot -= (BCReg)cbase;
+ J->base -= cbase;
+ func += cbase;
+ }
+ /* Move func + args down. */
+ memmove(&J->base[-1], &J->base[func], sizeof(TRef)*(J->maxslot+1));
+ /* Note: the new TREF_FRAME is now at J->base[-1] (even for slot #0). */
+ /* Tailcalls can form a loop, so count towards the loop unroll limit. */
+ if (++J->tailcalled > J->loopunroll)
+ lj_trace_err(J, LJ_TRERR_LUNROLL);
+}
+
+/* Check unroll limits for down-recursion. */
+static int check_downrec_unroll(jit_State *J, GCproto *pt)
+{
+ IRRef ptref;
+ for (ptref = J->chain[IR_KGC]; ptref; ptref = IR(ptref)->prev)
+ if (ir_kgc(IR(ptref)) == obj2gco(pt)) {
+ int count = 0;
+ IRRef ref;
+ for (ref = J->chain[IR_RETF]; ref; ref = IR(ref)->prev)
+ if (IR(ref)->op1 == ptref)
+ count++;
+ if (count) {
+ if (J->pc == J->startpc) {
+ if (count + J->tailcalled > J->param[JIT_P_recunroll])
+ return 1;
+ } else {
+ lj_trace_err(J, LJ_TRERR_DOWNREC);
+ }
+ }
+ }
+ return 0;
+}
+
+/* Record return. */
+void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults)
+{
+ TValue *frame = J->L->base - 1;
+ ptrdiff_t i;
+ for (i = 0; i < gotresults; i++)
+ (void)getslot(J, rbase+i); /* Ensure all results have a reference. */
+ while (frame_ispcall(frame)) { /* Immediately resolve pcall() returns. */
+ BCReg cbase = (BCReg)frame_delta(frame);
+ if (--J->framedepth <= 0)
+ lj_trace_err(J, LJ_TRERR_NYIRETL);
+ lua_assert(J->baseslot > 1);
+ gotresults++;
+ rbase += cbase;
+ J->baseslot -= (BCReg)cbase;
+ J->base -= cbase;
+ J->base[--rbase] = TREF_TRUE; /* Prepend true to results. */
+ frame = frame_prevd(frame);
+ }
+ /* Return to lower frame via interpreter for unhandled cases. */
+ if (J->framedepth == 0 && J->pt && bc_isret(bc_op(*J->pc)) &&
+ (!frame_islua(frame) ||
+ (J->parent == 0 && !bc_isret(bc_op(J->cur.startins))))) {
+ /* NYI: specialize to frame type and return directly, not via RET*. */
+ for (i = 0; i < (ptrdiff_t)rbase; i++)
+ J->base[i] = 0; /* Purge dead slots. */
+ J->maxslot = rbase + (BCReg)gotresults;
+ rec_stop(J, LJ_TRLINK_RETURN, 0); /* Return to interpreter. */
+ return;
+ }
+ if (frame_isvarg(frame)) {
+ BCReg cbase = (BCReg)frame_delta(frame);
+ if (--J->framedepth < 0) /* NYI: return of vararg func to lower frame. */
+ lj_trace_err(J, LJ_TRERR_NYIRETL);
+ lua_assert(J->baseslot > 1);
+ rbase += cbase;
+ J->baseslot -= (BCReg)cbase;
+ J->base -= cbase;
+ frame = frame_prevd(frame);
+ }
+ if (frame_islua(frame)) { /* Return to Lua frame. */
+ BCIns callins = *(frame_pc(frame)-1);
+ ptrdiff_t nresults = bc_b(callins) ? (ptrdiff_t)bc_b(callins)-1 :gotresults;
+ BCReg cbase = bc_a(callins);
+ GCproto *pt = funcproto(frame_func(frame - (cbase+1)));
+ if ((pt->flags & PROTO_NOJIT))
+ lj_trace_err(J, LJ_TRERR_CJITOFF);
+ if (J->framedepth == 0 && J->pt && frame == J->L->base - 1) {
+ if (check_downrec_unroll(J, pt)) {
+ J->maxslot = (BCReg)(rbase + gotresults);
+ lj_snap_purge(J);
+ rec_stop(J, LJ_TRLINK_DOWNREC, J->cur.traceno); /* Down-recursion. */
+ return;
+ }
+ lj_snap_add(J);
+ }
+ for (i = 0; i < nresults; i++) /* Adjust results. */
+ J->base[i-1] = i < gotresults ? J->base[rbase+i] : TREF_NIL;
+ J->maxslot = cbase+(BCReg)nresults;
+ if (J->framedepth > 0) { /* Return to a frame that is part of the trace. */
+ J->framedepth--;
+ lua_assert(J->baseslot > cbase+1);
+ J->baseslot -= cbase+1;
+ J->base -= cbase+1;
+ } else if (J->parent == 0 && !bc_isret(bc_op(J->cur.startins))) {
+ /* Return to lower frame would leave the loop in a root trace. */
+ lj_trace_err(J, LJ_TRERR_LLEAVE);
+ } else if (J->needsnap) { /* Tailcalled to ff with side-effects. */
+ lj_trace_err(J, LJ_TRERR_NYIRETL); /* No way to insert snapshot here. */
+ } else { /* Return to lower frame. Guard for the target we return to. */
+ TRef trpt = lj_ir_kgc(J, obj2gco(pt), IRT_PROTO);
+ TRef trpc = lj_ir_kptr(J, (void *)frame_pc(frame));
+ emitir(IRTG(IR_RETF, IRT_P32), trpt, trpc);
+ J->retdepth++;
+ J->needsnap = 1;
+ lua_assert(J->baseslot == 1);
+ /* Shift result slots up and clear the slots of the new frame below. */
+ memmove(J->base + cbase, J->base-1, sizeof(TRef)*nresults);
+ memset(J->base-1, 0, sizeof(TRef)*(cbase+1));
+ }
+ } else if (frame_iscont(frame)) { /* Return to continuation frame. */
+ ASMFunction cont = frame_contf(frame);
+ BCReg cbase = (BCReg)frame_delta(frame);
+ if ((J->framedepth -= 2) < 0)
+ lj_trace_err(J, LJ_TRERR_NYIRETL);
+ J->baseslot -= (BCReg)cbase;
+ J->base -= cbase;
+ J->maxslot = cbase-2;
+ if (cont == lj_cont_ra) {
+ /* Copy result to destination slot. */
+ BCReg dst = bc_a(*(frame_contpc(frame)-1));
+ J->base[dst] = gotresults ? J->base[cbase+rbase] : TREF_NIL;
+ if (dst >= J->maxslot) J->maxslot = dst+1;
+ } else if (cont == lj_cont_nop) {
+ /* Nothing to do here. */
+ } else if (cont == lj_cont_cat) {
+ lua_assert(0);
+ } else {
+ /* Result type already specialized. */
+ lua_assert(cont == lj_cont_condf || cont == lj_cont_condt);
+ }
+ } else {
+ lj_trace_err(J, LJ_TRERR_NYIRETL); /* NYI: handle return to C frame. */
+ }
+ lua_assert(J->baseslot >= 1);
+}
+
+/* -- Metamethod handling ------------------------------------------------- */
+
+/* Prepare to record call to metamethod. */
+static BCReg rec_mm_prep(jit_State *J, ASMFunction cont)
+{
+ BCReg s, top = curr_proto(J->L)->framesize;
+ TRef trcont;
+ setcont(&J->L->base[top], cont);
+#if LJ_64
+ trcont = lj_ir_kptr(J, (void *)((int64_t)cont - (int64_t)lj_vm_asm_begin));
+#else
+ trcont = lj_ir_kptr(J, (void *)cont);
+#endif
+ J->base[top] = trcont | TREF_CONT;
+ J->framedepth++;
+ for (s = J->maxslot; s < top; s++)
+ J->base[s] = 0; /* Clear frame gap to avoid resurrecting previous refs. */
+ return top+1;
+}
+
+/* Record metamethod lookup. */
+int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm)
+{
+ RecordIndex mix;
+ GCtab *mt;
+ if (tref_istab(ix->tab)) {
+ mt = tabref(tabV(&ix->tabv)->metatable);
+ mix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_TAB_META);
+ } else if (tref_isudata(ix->tab)) {
+ int udtype = udataV(&ix->tabv)->udtype;
+ mt = tabref(udataV(&ix->tabv)->metatable);
+ /* The metatables of special userdata objects are treated as immutable. */
+ if (udtype != UDTYPE_USERDATA) {
+ cTValue *mo;
+ if (LJ_HASFFI && udtype == UDTYPE_FFI_CLIB) {
+ /* Specialize to the C library namespace object. */
+ emitir(IRTG(IR_EQ, IRT_P32), ix->tab, lj_ir_kptr(J, udataV(&ix->tabv)));
+ } else {
+ /* Specialize to the type of userdata. */
+ TRef tr = emitir(IRT(IR_FLOAD, IRT_U8), ix->tab, IRFL_UDATA_UDTYPE);
+ emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, udtype));
+ }
+ immutable_mt:
+ mo = lj_tab_getstr(mt, mmname_str(J2G(J), mm));
+ if (!mo || tvisnil(mo))
+ return 0; /* No metamethod. */
+ /* Treat metamethod or index table as immutable, too. */
+ if (!(tvisfunc(mo) || tvistab(mo)))
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ copyTV(J->L, &ix->mobjv, mo);
+ ix->mobj = lj_ir_kgc(J, gcV(mo), tvisfunc(mo) ? IRT_FUNC : IRT_TAB);
+ ix->mtv = mt;
+ ix->mt = TREF_NIL; /* Dummy value for comparison semantics. */
+ return 1; /* Got metamethod or index table. */
+ }
+ mix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_UDATA_META);
+ } else {
+ /* Specialize to base metatable. Must flush mcode in lua_setmetatable(). */
+ mt = tabref(basemt_obj(J2G(J), &ix->tabv));
+ if (mt == NULL) {
+ ix->mt = TREF_NIL;
+ return 0; /* No metamethod. */
+ }
+ /* The cdata metatable is treated as immutable. */
+ if (LJ_HASFFI && tref_iscdata(ix->tab)) goto immutable_mt;
+ ix->mt = mix.tab = lj_ir_ktab(J, mt);
+ goto nocheck;
+ }
+ ix->mt = mt ? mix.tab : TREF_NIL;
+ emitir(IRTG(mt ? IR_NE : IR_EQ, IRT_TAB), mix.tab, lj_ir_knull(J, IRT_TAB));
+nocheck:
+ if (mt) {
+ GCstr *mmstr = mmname_str(J2G(J), mm);
+ cTValue *mo = lj_tab_getstr(mt, mmstr);
+ if (mo && !tvisnil(mo))
+ copyTV(J->L, &ix->mobjv, mo);
+ ix->mtv = mt;
+ settabV(J->L, &mix.tabv, mt);
+ setstrV(J->L, &mix.keyv, mmstr);
+ mix.key = lj_ir_kstr(J, mmstr);
+ mix.val = 0;
+ mix.idxchain = 0;
+ ix->mobj = lj_record_idx(J, &mix);
+ return !tref_isnil(ix->mobj); /* 1 if metamethod found, 0 if not. */
+ }
+ return 0; /* No metamethod. */
+}
+
+/* Record call to arithmetic metamethod. */
+static TRef rec_mm_arith(jit_State *J, RecordIndex *ix, MMS mm)
+{
+ /* Set up metamethod call first to save ix->tab and ix->tabv. */
+ BCReg func = rec_mm_prep(J, lj_cont_ra);
+ TRef *base = J->base + func;
+ TValue *basev = J->L->base + func;
+ base[1] = ix->tab; base[2] = ix->key;
+ copyTV(J->L, basev+1, &ix->tabv);
+ copyTV(J->L, basev+2, &ix->keyv);
+ if (!lj_record_mm_lookup(J, ix, mm)) { /* Lookup mm on 1st operand. */
+ if (mm != MM_unm) {
+ ix->tab = ix->key;
+ copyTV(J->L, &ix->tabv, &ix->keyv);
+ if (lj_record_mm_lookup(J, ix, mm)) /* Lookup mm on 2nd operand. */
+ goto ok;
+ }
+ lj_trace_err(J, LJ_TRERR_NOMM);
+ }
+ok:
+ base[0] = ix->mobj;
+ copyTV(J->L, basev+0, &ix->mobjv);
+ lj_record_call(J, func, 2);
+ return 0; /* No result yet. */
+}
+
+/* Record call to __len metamethod. */
+static TRef rec_mm_len(jit_State *J, TRef tr, TValue *tv)
+{
+ RecordIndex ix;
+ ix.tab = tr;
+ copyTV(J->L, &ix.tabv, tv);
+ if (lj_record_mm_lookup(J, &ix, MM_len)) {
+ BCReg func = rec_mm_prep(J, lj_cont_ra);
+ TRef *base = J->base + func;
+ TValue *basev = J->L->base + func;
+ base[0] = ix.mobj; copyTV(J->L, basev+0, &ix.mobjv);
+ base[1] = tr; copyTV(J->L, basev+1, tv);
+#if LJ_52
+ base[2] = tr; copyTV(J->L, basev+2, tv);
+#else
+ base[2] = TREF_NIL; setnilV(basev+2);
+#endif
+ lj_record_call(J, func, 2);
+ } else {
+ if (LJ_52 && tref_istab(tr))
+ return lj_ir_call(J, IRCALL_lj_tab_len, tr);
+ lj_trace_err(J, LJ_TRERR_NOMM);
+ }
+ return 0; /* No result yet. */
+}
+
+/* Call a comparison metamethod. */
+static void rec_mm_callcomp(jit_State *J, RecordIndex *ix, int op)
+{
+ BCReg func = rec_mm_prep(J, (op&1) ? lj_cont_condf : lj_cont_condt);
+ TRef *base = J->base + func;
+ TValue *tv = J->L->base + func;
+ base[0] = ix->mobj; base[1] = ix->val; base[2] = ix->key;
+ copyTV(J->L, tv+0, &ix->mobjv);
+ copyTV(J->L, tv+1, &ix->valv);
+ copyTV(J->L, tv+2, &ix->keyv);
+ lj_record_call(J, func, 2);
+}
+
+/* Record call to equality comparison metamethod (for tab and udata only). */
+static void rec_mm_equal(jit_State *J, RecordIndex *ix, int op)
+{
+ ix->tab = ix->val;
+ copyTV(J->L, &ix->tabv, &ix->valv);
+ if (lj_record_mm_lookup(J, ix, MM_eq)) { /* Lookup mm on 1st operand. */
+ cTValue *bv;
+ TRef mo1 = ix->mobj;
+ TValue mo1v;
+ copyTV(J->L, &mo1v, &ix->mobjv);
+ /* Avoid the 2nd lookup and the objcmp if the metatables are equal. */
+ bv = &ix->keyv;
+ if (tvistab(bv) && tabref(tabV(bv)->metatable) == ix->mtv) {
+ TRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_TAB_META);
+ emitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt);
+ } else if (tvisudata(bv) && tabref(udataV(bv)->metatable) == ix->mtv) {
+ TRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_UDATA_META);
+ emitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt);
+ } else { /* Lookup metamethod on 2nd operand and compare both. */
+ ix->tab = ix->key;
+ copyTV(J->L, &ix->tabv, bv);
+ if (!lj_record_mm_lookup(J, ix, MM_eq) ||
+ lj_record_objcmp(J, mo1, ix->mobj, &mo1v, &ix->mobjv))
+ return;
+ }
+ rec_mm_callcomp(J, ix, op);
+ }
+}
+
+/* Record call to ordered comparison metamethods (for arbitrary objects). */
+static void rec_mm_comp(jit_State *J, RecordIndex *ix, int op)
+{
+ ix->tab = ix->val;
+ copyTV(J->L, &ix->tabv, &ix->valv);
+ while (1) {
+ MMS mm = (op & 2) ? MM_le : MM_lt; /* Try __le + __lt or only __lt. */
+#if LJ_52
+ if (!lj_record_mm_lookup(J, ix, mm)) { /* Lookup mm on 1st operand. */
+ ix->tab = ix->key;
+ copyTV(J->L, &ix->tabv, &ix->keyv);
+ if (!lj_record_mm_lookup(J, ix, mm)) /* Lookup mm on 2nd operand. */
+ goto nomatch;
+ }
+ rec_mm_callcomp(J, ix, op);
+ return;
+#else
+ if (lj_record_mm_lookup(J, ix, mm)) { /* Lookup mm on 1st operand. */
+ cTValue *bv;
+ TRef mo1 = ix->mobj;
+ TValue mo1v;
+ copyTV(J->L, &mo1v, &ix->mobjv);
+ /* Avoid the 2nd lookup and the objcmp if the metatables are equal. */
+ bv = &ix->keyv;
+ if (tvistab(bv) && tabref(tabV(bv)->metatable) == ix->mtv) {
+ TRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_TAB_META);
+ emitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt);
+ } else if (tvisudata(bv) && tabref(udataV(bv)->metatable) == ix->mtv) {
+ TRef mt2 = emitir(IRT(IR_FLOAD, IRT_TAB), ix->key, IRFL_UDATA_META);
+ emitir(IRTG(IR_EQ, IRT_TAB), mt2, ix->mt);
+ } else { /* Lookup metamethod on 2nd operand and compare both. */
+ ix->tab = ix->key;
+ copyTV(J->L, &ix->tabv, bv);
+ if (!lj_record_mm_lookup(J, ix, mm) ||
+ lj_record_objcmp(J, mo1, ix->mobj, &mo1v, &ix->mobjv))
+ goto nomatch;
+ }
+ rec_mm_callcomp(J, ix, op);
+ return;
+ }
+#endif
+ nomatch:
+ /* Lookup failed. Retry with __lt and swapped operands. */
+ if (!(op & 2)) break; /* Already at __lt. Interpreter will throw. */
+ ix->tab = ix->key; ix->key = ix->val; ix->val = ix->tab;
+ copyTV(J->L, &ix->tabv, &ix->keyv);
+ copyTV(J->L, &ix->keyv, &ix->valv);
+ copyTV(J->L, &ix->valv, &ix->tabv);
+ op ^= 3;
+ }
+}
+
+#if LJ_HASFFI
+/* Setup call to cdata comparison metamethod. */
+static void rec_mm_comp_cdata(jit_State *J, RecordIndex *ix, int op, MMS mm)
+{
+ lj_snap_add(J);
+ if (tref_iscdata(ix->val)) {
+ ix->tab = ix->val;
+ copyTV(J->L, &ix->tabv, &ix->valv);
+ } else {
+ lua_assert(tref_iscdata(ix->key));
+ ix->tab = ix->key;
+ copyTV(J->L, &ix->tabv, &ix->keyv);
+ }
+ lj_record_mm_lookup(J, ix, mm);
+ rec_mm_callcomp(J, ix, op);
+}
+#endif
+
+/* -- Indexed access ------------------------------------------------------ */
+
+/* Record bounds-check. */
+static void rec_idx_abc(jit_State *J, TRef asizeref, TRef ikey, uint32_t asize)
+{
+ /* Try to emit invariant bounds checks. */
+ if ((J->flags & (JIT_F_OPT_LOOP|JIT_F_OPT_ABC)) ==
+ (JIT_F_OPT_LOOP|JIT_F_OPT_ABC)) {
+ IRRef ref = tref_ref(ikey);
+ IRIns *ir = IR(ref);
+ int32_t ofs = 0;
+ IRRef ofsref = 0;
+ /* Handle constant offsets. */
+ if (ir->o == IR_ADD && irref_isk(ir->op2)) {
+ ofsref = ir->op2;
+ ofs = IR(ofsref)->i;
+ ref = ir->op1;
+ ir = IR(ref);
+ }
+ /* Got scalar evolution analysis results for this reference? */
+ if (ref == J->scev.idx) {
+ int32_t stop;
+ lua_assert(irt_isint(J->scev.t) && ir->o == IR_SLOAD);
+ stop = numberVint(&(J->L->base - J->baseslot)[ir->op1 + FORL_STOP]);
+ /* Runtime value for stop of loop is within bounds? */
+ if ((uint64_t)stop + ofs < (uint64_t)asize) {
+ /* Emit invariant bounds check for stop. */
+ emitir(IRTG(IR_ABC, IRT_P32), asizeref, ofs == 0 ? J->scev.stop :
+ emitir(IRTI(IR_ADD), J->scev.stop, ofsref));
+ /* Emit invariant bounds check for start, if not const or negative. */
+ if (!(J->scev.dir && J->scev.start &&
+ (int64_t)IR(J->scev.start)->i + ofs >= 0))
+ emitir(IRTG(IR_ABC, IRT_P32), asizeref, ikey);
+ return;
+ }
+ }
+ }
+ emitir(IRTGI(IR_ABC), asizeref, ikey); /* Emit regular bounds check. */
+}
+
+/* Record indexed key lookup. */
+static TRef rec_idx_key(jit_State *J, RecordIndex *ix)
+{
+ TRef key;
+ GCtab *t = tabV(&ix->tabv);
+ ix->oldv = lj_tab_get(J->L, t, &ix->keyv); /* Lookup previous value. */
+
+ /* Integer keys are looked up in the array part first. */
+ key = ix->key;
+ if (tref_isnumber(key)) {
+ int32_t k = numberVint(&ix->keyv);
+ if (!tvisint(&ix->keyv) && numV(&ix->keyv) != (lua_Number)k)
+ k = LJ_MAX_ASIZE;
+ if ((MSize)k < LJ_MAX_ASIZE) { /* Potential array key? */
+ TRef ikey = lj_opt_narrow_index(J, key);
+ TRef asizeref = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_ASIZE);
+ if ((MSize)k < t->asize) { /* Currently an array key? */
+ TRef arrayref;
+ rec_idx_abc(J, asizeref, ikey, t->asize);
+ arrayref = emitir(IRT(IR_FLOAD, IRT_P32), ix->tab, IRFL_TAB_ARRAY);
+ return emitir(IRT(IR_AREF, IRT_P32), arrayref, ikey);
+ } else { /* Currently not in array (may be an array extension)? */
+ emitir(IRTGI(IR_ULE), asizeref, ikey); /* Inv. bounds check. */
+ if (k == 0 && tref_isk(key))
+ key = lj_ir_knum_zero(J); /* Canonicalize 0 or +-0.0 to +0.0. */
+ /* And continue with the hash lookup. */
+ }
+ } else if (!tref_isk(key)) {
+ /* We can rule out const numbers which failed the integerness test
+ ** above. But all other numbers are potential array keys.
+ */
+ if (t->asize == 0) { /* True sparse tables have an empty array part. */
+ /* Guard that the array part stays empty. */
+ TRef tmp = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_ASIZE);
+ emitir(IRTGI(IR_EQ), tmp, lj_ir_kint(J, 0));
+ } else {
+ lj_trace_err(J, LJ_TRERR_NYITMIX);
+ }
+ }
+ }
+
+ /* Otherwise the key is located in the hash part. */
+ if (t->hmask == 0) { /* Shortcut for empty hash part. */
+ /* Guard that the hash part stays empty. */
+ TRef tmp = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_HMASK);
+ emitir(IRTGI(IR_EQ), tmp, lj_ir_kint(J, 0));
+ return lj_ir_kkptr(J, niltvg(J2G(J)));
+ }
+ if (tref_isinteger(key)) /* Hash keys are based on numbers, not ints. */
+ key = emitir(IRTN(IR_CONV), key, IRCONV_NUM_INT);
+ if (tref_isk(key)) {
+ /* Optimize lookup of constant hash keys. */
+ MSize hslot = (MSize)((char *)ix->oldv - (char *)&noderef(t->node)[0].val);
+ if (t->hmask > 0 && hslot <= t->hmask*(MSize)sizeof(Node) &&
+ hslot <= 65535*(MSize)sizeof(Node)) {
+ TRef node, kslot;
+ TRef hm = emitir(IRTI(IR_FLOAD), ix->tab, IRFL_TAB_HMASK);
+ emitir(IRTGI(IR_EQ), hm, lj_ir_kint(J, (int32_t)t->hmask));
+ node = emitir(IRT(IR_FLOAD, IRT_P32), ix->tab, IRFL_TAB_NODE);
+ kslot = lj_ir_kslot(J, key, hslot / sizeof(Node));
+ return emitir(IRTG(IR_HREFK, IRT_P32), node, kslot);
+ }
+ }
+ /* Fall back to a regular hash lookup. */
+ return emitir(IRT(IR_HREF, IRT_P32), ix->tab, key);
+}
+
+/* Determine whether a key is NOT one of the fast metamethod names. */
+static int nommstr(jit_State *J, TRef key)
+{
+ if (tref_isstr(key)) {
+ if (tref_isk(key)) {
+ GCstr *str = ir_kstr(IR(tref_ref(key)));
+ uint32_t mm;
+ for (mm = 0; mm <= MM_FAST; mm++)
+ if (mmname_str(J2G(J), mm) == str)
+ return 0; /* MUST be one the fast metamethod names. */
+ } else {
+ return 0; /* Variable string key MAY be a metamethod name. */
+ }
+ }
+ return 1; /* CANNOT be a metamethod name. */
+}
+
+/* Record indexed load/store. */
+TRef lj_record_idx(jit_State *J, RecordIndex *ix)
+{
+ TRef xref;
+ IROp xrefop, loadop;
+ cTValue *oldv;
+
+ while (!tref_istab(ix->tab)) { /* Handle non-table lookup. */
+ /* Never call raw lj_record_idx() on non-table. */
+ lua_assert(ix->idxchain != 0);
+ if (!lj_record_mm_lookup(J, ix, ix->val ? MM_newindex : MM_index))
+ lj_trace_err(J, LJ_TRERR_NOMM);
+ handlemm:
+ if (tref_isfunc(ix->mobj)) { /* Handle metamethod call. */
+ BCReg func = rec_mm_prep(J, ix->val ? lj_cont_nop : lj_cont_ra);
+ TRef *base = J->base + func;
+ TValue *tv = J->L->base + func;
+ base[0] = ix->mobj; base[1] = ix->tab; base[2] = ix->key;
+ setfuncV(J->L, tv+0, funcV(&ix->mobjv));
+ copyTV(J->L, tv+1, &ix->tabv);
+ copyTV(J->L, tv+2, &ix->keyv);
+ if (ix->val) {
+ base[3] = ix->val;
+ copyTV(J->L, tv+3, &ix->valv);
+ lj_record_call(J, func, 3); /* mobj(tab, key, val) */
+ return 0;
+ } else {
+ lj_record_call(J, func, 2); /* res = mobj(tab, key) */
+ return 0; /* No result yet. */
+ }
+ }
+ /* Otherwise retry lookup with metaobject. */
+ ix->tab = ix->mobj;
+ copyTV(J->L, &ix->tabv, &ix->mobjv);
+ if (--ix->idxchain == 0)
+ lj_trace_err(J, LJ_TRERR_IDXLOOP);
+ }
+
+ /* First catch nil and NaN keys for tables. */
+ if (tvisnil(&ix->keyv) || (tvisnum(&ix->keyv) && tvisnan(&ix->keyv))) {
+ if (ix->val) /* Better fail early. */
+ lj_trace_err(J, LJ_TRERR_STORENN);
+ if (tref_isk(ix->key)) {
+ if (ix->idxchain && lj_record_mm_lookup(J, ix, MM_index))
+ goto handlemm;
+ return TREF_NIL;
+ }
+ }
+
+ /* Record the key lookup. */
+ xref = rec_idx_key(J, ix);
+ xrefop = IR(tref_ref(xref))->o;
+ loadop = xrefop == IR_AREF ? IR_ALOAD : IR_HLOAD;
+ /* The lj_meta_tset() inconsistency is gone, but better play safe. */
+ oldv = xrefop == IR_KKPTR ? (cTValue *)ir_kptr(IR(tref_ref(xref))) : ix->oldv;
+
+ if (ix->val == 0) { /* Indexed load */
+ IRType t = itype2irt(oldv);
+ TRef res;
+ if (oldv == niltvg(J2G(J))) {
+ emitir(IRTG(IR_EQ, IRT_P32), xref, lj_ir_kkptr(J, niltvg(J2G(J))));
+ res = TREF_NIL;
+ } else {
+ res = emitir(IRTG(loadop, t), xref, 0);
+ }
+ if (t == IRT_NIL && ix->idxchain && lj_record_mm_lookup(J, ix, MM_index))
+ goto handlemm;
+ if (irtype_ispri(t)) res = TREF_PRI(t); /* Canonicalize primitives. */
+ return res;
+ } else { /* Indexed store. */
+ GCtab *mt = tabref(tabV(&ix->tabv)->metatable);
+ int keybarrier = tref_isgcv(ix->key) && !tref_isnil(ix->val);
+ if (tvisnil(oldv)) { /* Previous value was nil? */
+ /* Need to duplicate the hasmm check for the early guards. */
+ int hasmm = 0;
+ if (ix->idxchain && mt) {
+ cTValue *mo = lj_tab_getstr(mt, mmname_str(J2G(J), MM_newindex));
+ hasmm = mo && !tvisnil(mo);
+ }
+ if (hasmm)
+ emitir(IRTG(loadop, IRT_NIL), xref, 0); /* Guard for nil value. */
+ else if (xrefop == IR_HREF)
+ emitir(IRTG(oldv == niltvg(J2G(J)) ? IR_EQ : IR_NE, IRT_P32),
+ xref, lj_ir_kkptr(J, niltvg(J2G(J))));
+ if (ix->idxchain && lj_record_mm_lookup(J, ix, MM_newindex)) {
+ lua_assert(hasmm);
+ goto handlemm;
+ }
+ lua_assert(!hasmm);
+ if (oldv == niltvg(J2G(J))) { /* Need to insert a new key. */
+ TRef key = ix->key;
+ if (tref_isinteger(key)) /* NEWREF needs a TValue as a key. */
+ key = emitir(IRTN(IR_CONV), key, IRCONV_NUM_INT);
+ xref = emitir(IRT(IR_NEWREF, IRT_P32), ix->tab, key);
+ keybarrier = 0; /* NEWREF already takes care of the key barrier. */
+ }
+ } else if (!lj_opt_fwd_wasnonnil(J, loadop, tref_ref(xref))) {
+ /* Cannot derive that the previous value was non-nil, must do checks. */
+ if (xrefop == IR_HREF) /* Guard against store to niltv. */
+ emitir(IRTG(IR_NE, IRT_P32), xref, lj_ir_kkptr(J, niltvg(J2G(J))));
+ if (ix->idxchain) { /* Metamethod lookup required? */
+ /* A check for NULL metatable is cheaper (hoistable) than a load. */
+ if (!mt) {
+ TRef mtref = emitir(IRT(IR_FLOAD, IRT_TAB), ix->tab, IRFL_TAB_META);
+ emitir(IRTG(IR_EQ, IRT_TAB), mtref, lj_ir_knull(J, IRT_TAB));
+ } else {
+ IRType t = itype2irt(oldv);
+ emitir(IRTG(loadop, t), xref, 0); /* Guard for non-nil value. */
+ }
+ }
+ } else {
+ keybarrier = 0; /* Previous non-nil value kept the key alive. */
+ }
+ /* Convert int to number before storing. */
+ if (!LJ_DUALNUM && tref_isinteger(ix->val))
+ ix->val = emitir(IRTN(IR_CONV), ix->val, IRCONV_NUM_INT);
+ emitir(IRT(loadop+IRDELTA_L2S, tref_type(ix->val)), xref, ix->val);
+ if (keybarrier || tref_isgcv(ix->val))
+ emitir(IRT(IR_TBAR, IRT_NIL), ix->tab, 0);
+ /* Invalidate neg. metamethod cache for stores with certain string keys. */
+ if (!nommstr(J, ix->key)) {
+ TRef fref = emitir(IRT(IR_FREF, IRT_P32), ix->tab, IRFL_TAB_NOMM);
+ emitir(IRT(IR_FSTORE, IRT_U8), fref, lj_ir_kint(J, 0));
+ }
+ J->needsnap = 1;
+ return 0;
+ }
+}
+
+/* -- Upvalue access ------------------------------------------------------ */
+
+/* Check whether upvalue is immutable and ok to constify. */
+static int rec_upvalue_constify(jit_State *J, GCupval *uvp)
+{
+ if (uvp->immutable) {
+ cTValue *o = uvval(uvp);
+ /* Don't constify objects that may retain large amounts of memory. */
+#if LJ_HASFFI
+ if (tviscdata(o)) {
+ GCcdata *cd = cdataV(o);
+ if (!cdataisv(cd) && !(cd->marked & LJ_GC_CDATA_FIN)) {
+ CType *ct = ctype_raw(ctype_ctsG(J2G(J)), cd->ctypeid);
+ if (!ctype_hassize(ct->info) || ct->size <= 16)
+ return 1;
+ }
+ return 0;
+ }
+#else
+ UNUSED(J);
+#endif
+ if (!(tvistab(o) || tvisudata(o) || tvisthread(o)))
+ return 1;
+ }
+ return 0;
+}
+
+/* Record upvalue load/store. */
+static TRef rec_upvalue(jit_State *J, uint32_t uv, TRef val)
+{
+ GCupval *uvp = &gcref(J->fn->l.uvptr[uv])->uv;
+ TRef fn = getcurrf(J);
+ IRRef uref;
+ int needbarrier = 0;
+ if (rec_upvalue_constify(J, uvp)) { /* Try to constify immutable upvalue. */
+ TRef tr, kfunc;
+ lua_assert(val == 0);
+ if (!tref_isk(fn)) { /* Late specialization of current function. */
+ if (J->pt->flags >= PROTO_CLC_POLY)
+ goto noconstify;
+ kfunc = lj_ir_kfunc(J, J->fn);
+ emitir(IRTG(IR_EQ, IRT_FUNC), fn, kfunc);
+ J->base[-1] = TREF_FRAME | kfunc;
+ fn = kfunc;
+ }
+ tr = lj_record_constify(J, uvval(uvp));
+ if (tr)
+ return tr;
+ }
+noconstify:
+ /* Note: this effectively limits LJ_MAX_UPVAL to 127. */
+ uv = (uv << 8) | (hashrot(uvp->dhash, uvp->dhash + HASH_BIAS) & 0xff);
+ if (!uvp->closed) {
+ uref = tref_ref(emitir(IRTG(IR_UREFO, IRT_P32), fn, uv));
+ /* In current stack? */
+ if (uvval(uvp) >= tvref(J->L->stack) &&
+ uvval(uvp) < tvref(J->L->maxstack)) {
+ int32_t slot = (int32_t)(uvval(uvp) - (J->L->base - J->baseslot));
+ if (slot >= 0) { /* Aliases an SSA slot? */
+ emitir(IRTG(IR_EQ, IRT_P32),
+ REF_BASE,
+ emitir(IRT(IR_ADD, IRT_P32), uref,
+ lj_ir_kint(J, (slot - 1) * -8)));
+ slot -= (int32_t)J->baseslot; /* Note: slot number may be negative! */
+ if (val == 0) {
+ return getslot(J, slot);
+ } else {
+ J->base[slot] = val;
+ if (slot >= (int32_t)J->maxslot) J->maxslot = (BCReg)(slot+1);
+ return 0;
+ }
+ }
+ }
+ emitir(IRTG(IR_UGT, IRT_P32),
+ emitir(IRT(IR_SUB, IRT_P32), uref, REF_BASE),
+ lj_ir_kint(J, (J->baseslot + J->maxslot) * 8));
+ } else {
+ needbarrier = 1;
+ uref = tref_ref(emitir(IRTG(IR_UREFC, IRT_P32), fn, uv));
+ }
+ if (val == 0) { /* Upvalue load */
+ IRType t = itype2irt(uvval(uvp));
+ TRef res = emitir(IRTG(IR_ULOAD, t), uref, 0);
+ if (irtype_ispri(t)) res = TREF_PRI(t); /* Canonicalize primitive refs. */
+ return res;
+ } else { /* Upvalue store. */
+ /* Convert int to number before storing. */
+ if (!LJ_DUALNUM && tref_isinteger(val))
+ val = emitir(IRTN(IR_CONV), val, IRCONV_NUM_INT);
+ emitir(IRT(IR_USTORE, tref_type(val)), uref, val);
+ if (needbarrier && tref_isgcv(val))
+ emitir(IRT(IR_OBAR, IRT_NIL), uref, val);
+ J->needsnap = 1;
+ return 0;
+ }
+}
+
+/* -- Record calls to Lua functions --------------------------------------- */
+
+/* Check unroll limits for calls. */
+static void check_call_unroll(jit_State *J, TraceNo lnk)
+{
+ cTValue *frame = J->L->base - 1;
+ void *pc = mref(frame_func(frame)->l.pc, void);
+ int32_t depth = J->framedepth;
+ int32_t count = 0;
+ if ((J->pt->flags & PROTO_VARARG)) depth--; /* Vararg frame still missing. */
+ for (; depth > 0; depth--) { /* Count frames with same prototype. */
+ if (frame_iscont(frame)) depth--;
+ frame = frame_prev(frame);
+ if (mref(frame_func(frame)->l.pc, void) == pc)
+ count++;
+ }
+ if (J->pc == J->startpc) {
+ if (count + J->tailcalled > J->param[JIT_P_recunroll]) {
+ J->pc++;
+ if (J->framedepth + J->retdepth == 0)
+ rec_stop(J, LJ_TRLINK_TAILREC, J->cur.traceno); /* Tail-recursion. */
+ else
+ rec_stop(J, LJ_TRLINK_UPREC, J->cur.traceno); /* Up-recursion. */
+ }
+ } else {
+ if (count > J->param[JIT_P_callunroll]) {
+ if (lnk) { /* Possible tail- or up-recursion. */
+ lj_trace_flush(J, lnk); /* Flush trace that only returns. */
+ /* Set a small, pseudo-random hotcount for a quick retry of JFUNC*. */
+ hotcount_set(J2GG(J), J->pc+1, LJ_PRNG_BITS(J, 4));
+ }
+ lj_trace_err(J, LJ_TRERR_CUNROLL);
+ }
+ }
+}
+
+/* Record Lua function setup. */
+static void rec_func_setup(jit_State *J)
+{
+ GCproto *pt = J->pt;
+ BCReg s, numparams = pt->numparams;
+ if ((pt->flags & PROTO_NOJIT))
+ lj_trace_err(J, LJ_TRERR_CJITOFF);
+ if (J->baseslot + pt->framesize >= LJ_MAX_JSLOTS)
+ lj_trace_err(J, LJ_TRERR_STACKOV);
+ /* Fill up missing parameters with nil. */
+ for (s = J->maxslot; s < numparams; s++)
+ J->base[s] = TREF_NIL;
+ /* The remaining slots should never be read before they are written. */
+ J->maxslot = numparams;
+}
+
+/* Record Lua vararg function setup. */
+static void rec_func_vararg(jit_State *J)
+{
+ GCproto *pt = J->pt;
+ BCReg s, fixargs, vframe = J->maxslot+1;
+ lua_assert((pt->flags & PROTO_VARARG));
+ if (J->baseslot + vframe + pt->framesize >= LJ_MAX_JSLOTS)
+ lj_trace_err(J, LJ_TRERR_STACKOV);
+ J->base[vframe-1] = J->base[-1]; /* Copy function up. */
+ /* Copy fixarg slots up and set their original slots to nil. */
+ fixargs = pt->numparams < J->maxslot ? pt->numparams : J->maxslot;
+ for (s = 0; s < fixargs; s++) {
+ J->base[vframe+s] = J->base[s];
+ J->base[s] = TREF_NIL;
+ }
+ J->maxslot = fixargs;
+ J->framedepth++;
+ J->base += vframe;
+ J->baseslot += vframe;
+}
+
+/* Record entry to a Lua function. */
+static void rec_func_lua(jit_State *J)
+{
+ rec_func_setup(J);
+ check_call_unroll(J, 0);
+}
+
+/* Record entry to an already compiled function. */
+static void rec_func_jit(jit_State *J, TraceNo lnk)
+{
+ GCtrace *T;
+ rec_func_setup(J);
+ T = traceref(J, lnk);
+ if (T->linktype == LJ_TRLINK_RETURN) { /* Trace returns to interpreter? */
+ check_call_unroll(J, lnk);
+ /* Temporarily unpatch JFUNC* to continue recording across function. */
+ J->patchins = *J->pc;
+ J->patchpc = (BCIns *)J->pc;
+ *J->patchpc = T->startins;
+ return;
+ }
+ J->instunroll = 0; /* Cannot continue across a compiled function. */
+ if (J->pc == J->startpc && J->framedepth + J->retdepth == 0)
+ rec_stop(J, LJ_TRLINK_TAILREC, J->cur.traceno); /* Extra tail-recursion. */
+ else
+ rec_stop(J, LJ_TRLINK_ROOT, lnk); /* Link to the function. */
+}
+
+/* -- Vararg handling ----------------------------------------------------- */
+
+/* Detect y = select(x, ...) idiom. */
+static int select_detect(jit_State *J)
+{
+ BCIns ins = J->pc[1];
+ if (bc_op(ins) == BC_CALLM && bc_b(ins) == 2 && bc_c(ins) == 1) {
+ cTValue *func = &J->L->base[bc_a(ins)];
+ if (tvisfunc(func) && funcV(func)->c.ffid == FF_select) {
+ TRef kfunc = lj_ir_kfunc(J, funcV(func));
+ emitir(IRTG(IR_EQ, IRT_FUNC), getslot(J, bc_a(ins)), kfunc);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/* Record vararg instruction. */
+static void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults)
+{
+ int32_t numparams = J->pt->numparams;
+ ptrdiff_t nvararg = frame_delta(J->L->base-1) - numparams - 1;
+ lua_assert(frame_isvarg(J->L->base-1));
+ if (J->framedepth > 0) { /* Simple case: varargs defined on-trace. */
+ ptrdiff_t i;
+ if (nvararg < 0) nvararg = 0;
+ if (nresults == -1) {
+ nresults = nvararg;
+ J->maxslot = dst + (BCReg)nvararg;
+ } else if (dst + nresults > J->maxslot) {
+ J->maxslot = dst + (BCReg)nresults;
+ }
+ for (i = 0; i < nresults; i++)
+ J->base[dst+i] = i < nvararg ? getslot(J, i - nvararg - 1) : TREF_NIL;
+ } else { /* Unknown number of varargs passed to trace. */
+ TRef fr = emitir(IRTI(IR_SLOAD), 0, IRSLOAD_READONLY|IRSLOAD_FRAME);
+ int32_t frofs = 8*(1+numparams)+FRAME_VARG;
+ if (nresults >= 0) { /* Known fixed number of results. */
+ ptrdiff_t i;
+ if (nvararg > 0) {
+ ptrdiff_t nload = nvararg >= nresults ? nresults : nvararg;
+ TRef vbase;
+ if (nvararg >= nresults)
+ emitir(IRTGI(IR_GE), fr, lj_ir_kint(J, frofs+8*(int32_t)nresults));
+ else
+ emitir(IRTGI(IR_EQ), fr, lj_ir_kint(J, frame_ftsz(J->L->base-1)));
+ vbase = emitir(IRTI(IR_SUB), REF_BASE, fr);
+ vbase = emitir(IRT(IR_ADD, IRT_P32), vbase, lj_ir_kint(J, frofs-8));
+ for (i = 0; i < nload; i++) {
+ IRType t = itype2irt(&J->L->base[i-1-nvararg]);
+ TRef aref = emitir(IRT(IR_AREF, IRT_P32),
+ vbase, lj_ir_kint(J, (int32_t)i));
+ TRef tr = emitir(IRTG(IR_VLOAD, t), aref, 0);
+ if (irtype_ispri(t)) tr = TREF_PRI(t); /* Canonicalize primitives. */
+ J->base[dst+i] = tr;
+ }
+ } else {
+ emitir(IRTGI(IR_LE), fr, lj_ir_kint(J, frofs));
+ nvararg = 0;
+ }
+ for (i = nvararg; i < nresults; i++)
+ J->base[dst+i] = TREF_NIL;
+ if (dst + (BCReg)nresults > J->maxslot)
+ J->maxslot = dst + (BCReg)nresults;
+ } else if (select_detect(J)) { /* y = select(x, ...) */
+ TRef tridx = J->base[dst-1];
+ TRef tr = TREF_NIL;
+ ptrdiff_t idx = lj_ffrecord_select_mode(J, tridx, &J->L->base[dst-1]);
+ if (idx < 0) goto nyivarg;
+ if (idx != 0 && !tref_isinteger(tridx))
+ tridx = emitir(IRTGI(IR_CONV), tridx, IRCONV_INT_NUM|IRCONV_INDEX);
+ if (idx != 0 && tref_isk(tridx)) {
+ emitir(IRTGI(idx <= nvararg ? IR_GE : IR_LT),
+ fr, lj_ir_kint(J, frofs+8*(int32_t)idx));
+ frofs -= 8; /* Bias for 1-based index. */
+ } else if (idx <= nvararg) { /* Compute size. */
+ TRef tmp = emitir(IRTI(IR_ADD), fr, lj_ir_kint(J, -frofs));
+ if (numparams)
+ emitir(IRTGI(IR_GE), tmp, lj_ir_kint(J, 0));
+ tr = emitir(IRTI(IR_BSHR), tmp, lj_ir_kint(J, 3));
+ if (idx != 0) {
+ tridx = emitir(IRTI(IR_ADD), tridx, lj_ir_kint(J, -1));
+ rec_idx_abc(J, tr, tridx, (uint32_t)nvararg);
+ }
+ } else {
+ TRef tmp = lj_ir_kint(J, frofs);
+ if (idx != 0) {
+ TRef tmp2 = emitir(IRTI(IR_BSHL), tridx, lj_ir_kint(J, 3));
+ tmp = emitir(IRTI(IR_ADD), tmp2, tmp);
+ } else {
+ tr = lj_ir_kint(J, 0);
+ }
+ emitir(IRTGI(IR_LT), fr, tmp);
+ }
+ if (idx != 0 && idx <= nvararg) {
+ IRType t;
+ TRef aref, vbase = emitir(IRTI(IR_SUB), REF_BASE, fr);
+ vbase = emitir(IRT(IR_ADD, IRT_P32), vbase, lj_ir_kint(J, frofs-8));
+ t = itype2irt(&J->L->base[idx-2-nvararg]);
+ aref = emitir(IRT(IR_AREF, IRT_P32), vbase, tridx);
+ tr = emitir(IRTG(IR_VLOAD, t), aref, 0);
+ if (irtype_ispri(t)) tr = TREF_PRI(t); /* Canonicalize primitives. */
+ }
+ J->base[dst-2] = tr;
+ J->maxslot = dst-1;
+ J->bcskip = 2; /* Skip CALLM + select. */
+ } else {
+ nyivarg:
+ setintV(&J->errinfo, BC_VARG);
+ lj_trace_err_info(J, LJ_TRERR_NYIBC);
+ }
+ }
+}
+
+/* -- Record allocations -------------------------------------------------- */
+
+static TRef rec_tnew(jit_State *J, uint32_t ah)
+{
+ uint32_t asize = ah & 0x7ff;
+ uint32_t hbits = ah >> 11;
+ if (asize == 0x7ff) asize = 0x801;
+ return emitir(IRTG(IR_TNEW, IRT_TAB), asize, hbits);
+}
+
+/* -- Record bytecode ops ------------------------------------------------- */
+
+/* Prepare for comparison. */
+static void rec_comp_prep(jit_State *J)
+{
+ /* Prevent merging with snapshot #0 (GC exit) since we fixup the PC. */
+ if (J->cur.nsnap == 1 && J->cur.snap[0].ref == J->cur.nins)
+ emitir_raw(IRT(IR_NOP, IRT_NIL), 0, 0);
+ lj_snap_add(J);
+}
+
+/* Fixup comparison. */
+static void rec_comp_fixup(jit_State *J, const BCIns *pc, int cond)
+{
+ BCIns jmpins = pc[1];
+ const BCIns *npc = pc + 2 + (cond ? bc_j(jmpins) : 0);
+ SnapShot *snap = &J->cur.snap[J->cur.nsnap-1];
+ /* Set PC to opposite target to avoid re-recording the comp. in side trace. */
+ J->cur.snapmap[snap->mapofs + snap->nent] = SNAP_MKPC(npc);
+ J->needsnap = 1;
+ if (bc_a(jmpins) < J->maxslot) J->maxslot = bc_a(jmpins);
+ lj_snap_shrink(J); /* Shrink last snapshot if possible. */
+}
+
+/* Record the next bytecode instruction (_before_ it's executed). */
+void lj_record_ins(jit_State *J)
+{
+ cTValue *lbase;
+ RecordIndex ix;
+ const BCIns *pc;
+ BCIns ins;
+ BCOp op;
+ TRef ra, rb, rc;
+
+ /* Perform post-processing action before recording the next instruction. */
+ if (LJ_UNLIKELY(J->postproc != LJ_POST_NONE)) {
+ switch (J->postproc) {
+ case LJ_POST_FIXCOMP: /* Fixup comparison. */
+ pc = frame_pc(&J2G(J)->tmptv);
+ rec_comp_fixup(J, pc, (!tvistruecond(&J2G(J)->tmptv2) ^ (bc_op(*pc)&1)));
+ /* fallthrough */
+ case LJ_POST_FIXGUARD: /* Fixup and emit pending guard. */
+ case LJ_POST_FIXGUARDSNAP: /* Fixup and emit pending guard and snapshot. */
+ if (!tvistruecond(&J2G(J)->tmptv2)) {
+ J->fold.ins.o ^= 1; /* Flip guard to opposite. */
+ if (J->postproc == LJ_POST_FIXGUARDSNAP) {
+ SnapShot *snap = &J->cur.snap[J->cur.nsnap-1];
+ J->cur.snapmap[snap->mapofs+snap->nent-1]--; /* False -> true. */
+ }
+ }
+ lj_opt_fold(J); /* Emit pending guard. */
+ /* fallthrough */
+ case LJ_POST_FIXBOOL:
+ if (!tvistruecond(&J2G(J)->tmptv2)) {
+ BCReg s;
+ TValue *tv = J->L->base;
+ for (s = 0; s < J->maxslot; s++) /* Fixup stack slot (if any). */
+ if (J->base[s] == TREF_TRUE && tvisfalse(&tv[s])) {
+ J->base[s] = TREF_FALSE;
+ break;
+ }
+ }
+ break;
+ case LJ_POST_FIXCONST:
+ {
+ BCReg s;
+ TValue *tv = J->L->base;
+ for (s = 0; s < J->maxslot; s++) /* Constify stack slots (if any). */
+ if (J->base[s] == TREF_NIL && !tvisnil(&tv[s]))
+ J->base[s] = lj_record_constify(J, &tv[s]);
+ }
+ break;
+ case LJ_POST_FFRETRY: /* Suppress recording of retried fast function. */
+ if (bc_op(*J->pc) >= BC__MAX)
+ return;
+ break;
+ default: lua_assert(0); break;
+ }
+ J->postproc = LJ_POST_NONE;
+ }
+
+ /* Need snapshot before recording next bytecode (e.g. after a store). */
+ if (J->needsnap) {
+ J->needsnap = 0;
+ lj_snap_purge(J);
+ lj_snap_add(J);
+ J->mergesnap = 1;
+ }
+
+ /* Skip some bytecodes. */
+ if (LJ_UNLIKELY(J->bcskip > 0)) {
+ J->bcskip--;
+ return;
+ }
+
+ /* Record only closed loops for root traces. */
+ pc = J->pc;
+ if (J->framedepth == 0 &&
+ (MSize)((char *)pc - (char *)J->bc_min) >= J->bc_extent)
+ lj_trace_err(J, LJ_TRERR_LLEAVE);
+
+#ifdef LUA_USE_ASSERT
+ rec_check_slots(J);
+ rec_check_ir(J);
+#endif
+
+ /* Keep a copy of the runtime values of var/num/str operands. */
+#define rav (&ix.valv)
+#define rbv (&ix.tabv)
+#define rcv (&ix.keyv)
+
+ lbase = J->L->base;
+ ins = *pc;
+ op = bc_op(ins);
+ ra = bc_a(ins);
+ ix.val = 0;
+ switch (bcmode_a(op)) {
+ case BCMvar:
+ copyTV(J->L, rav, &lbase[ra]); ix.val = ra = getslot(J, ra); break;
+ default: break; /* Handled later. */
+ }
+ rb = bc_b(ins);
+ rc = bc_c(ins);
+ switch (bcmode_b(op)) {
+ case BCMnone: rb = 0; rc = bc_d(ins); break; /* Upgrade rc to 'rd'. */
+ case BCMvar:
+ copyTV(J->L, rbv, &lbase[rb]); ix.tab = rb = getslot(J, rb); break;
+ default: break; /* Handled later. */
+ }
+ switch (bcmode_c(op)) {
+ case BCMvar:
+ copyTV(J->L, rcv, &lbase[rc]); ix.key = rc = getslot(J, rc); break;
+ case BCMpri: setitype(rcv, ~rc); ix.key = rc = TREF_PRI(IRT_NIL+rc); break;
+ case BCMnum: { cTValue *tv = proto_knumtv(J->pt, rc);
+ copyTV(J->L, rcv, tv); ix.key = rc = tvisint(tv) ? lj_ir_kint(J, intV(tv)) :
+ lj_ir_knumint(J, numV(tv)); } break;
+ case BCMstr: { GCstr *s = gco2str(proto_kgc(J->pt, ~(ptrdiff_t)rc));
+ setstrV(J->L, rcv, s); ix.key = rc = lj_ir_kstr(J, s); } break;
+ default: break; /* Handled later. */
+ }
+
+ switch (op) {
+
+ /* -- Comparison ops ---------------------------------------------------- */
+
+ case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:
+#if LJ_HASFFI
+ if (tref_iscdata(ra) || tref_iscdata(rc)) {
+ rec_mm_comp_cdata(J, &ix, op, ((int)op & 2) ? MM_le : MM_lt);
+ break;
+ }
+#endif
+ /* Emit nothing for two numeric or string consts. */
+ if (!(tref_isk2(ra,rc) && tref_isnumber_str(ra) && tref_isnumber_str(rc))) {
+ IRType ta = tref_isinteger(ra) ? IRT_INT : tref_type(ra);
+ IRType tc = tref_isinteger(rc) ? IRT_INT : tref_type(rc);
+ int irop;
+ if (ta != tc) {
+ /* Widen mixed number/int comparisons to number/number comparison. */
+ if (ta == IRT_INT && tc == IRT_NUM) {
+ ra = emitir(IRTN(IR_CONV), ra, IRCONV_NUM_INT);
+ ta = IRT_NUM;
+ } else if (ta == IRT_NUM && tc == IRT_INT) {
+ rc = emitir(IRTN(IR_CONV), rc, IRCONV_NUM_INT);
+ } else if (LJ_52) {
+ ta = IRT_NIL; /* Force metamethod for different types. */
+ } else if (!((ta == IRT_FALSE || ta == IRT_TRUE) &&
+ (tc == IRT_FALSE || tc == IRT_TRUE))) {
+ break; /* Interpreter will throw for two different types. */
+ }
+ }
+ rec_comp_prep(J);
+ irop = (int)op - (int)BC_ISLT + (int)IR_LT;
+ if (ta == IRT_NUM) {
+ if ((irop & 1)) irop ^= 4; /* ISGE/ISGT are unordered. */
+ if (!lj_ir_numcmp(numberVnum(rav), numberVnum(rcv), (IROp)irop))
+ irop ^= 5;
+ } else if (ta == IRT_INT) {
+ if (!lj_ir_numcmp(numberVnum(rav), numberVnum(rcv), (IROp)irop))
+ irop ^= 1;
+ } else if (ta == IRT_STR) {
+ if (!lj_ir_strcmp(strV(rav), strV(rcv), (IROp)irop)) irop ^= 1;
+ ra = lj_ir_call(J, IRCALL_lj_str_cmp, ra, rc);
+ rc = lj_ir_kint(J, 0);
+ ta = IRT_INT;
+ } else {
+ rec_mm_comp(J, &ix, (int)op);
+ break;
+ }
+ emitir(IRTG(irop, ta), ra, rc);
+ rec_comp_fixup(J, J->pc, ((int)op ^ irop) & 1);
+ }
+ break;
+
+ case BC_ISEQV: case BC_ISNEV:
+ case BC_ISEQS: case BC_ISNES:
+ case BC_ISEQN: case BC_ISNEN:
+ case BC_ISEQP: case BC_ISNEP:
+#if LJ_HASFFI
+ if (tref_iscdata(ra) || tref_iscdata(rc)) {
+ rec_mm_comp_cdata(J, &ix, op, MM_eq);
+ break;
+ }
+#endif
+ /* Emit nothing for two non-table, non-udata consts. */
+ if (!(tref_isk2(ra, rc) && !(tref_istab(ra) || tref_isudata(ra)))) {
+ int diff;
+ rec_comp_prep(J);
+ diff = lj_record_objcmp(J, ra, rc, rav, rcv);
+ if (diff == 2 || !(tref_istab(ra) || tref_isudata(ra)))
+ rec_comp_fixup(J, J->pc, ((int)op & 1) == !diff);
+ else if (diff == 1) /* Only check __eq if different, but same type. */
+ rec_mm_equal(J, &ix, (int)op);
+ }
+ break;
+
+ /* -- Unary test and copy ops ------------------------------------------- */
+
+ case BC_ISTC: case BC_ISFC:
+ if ((op & 1) == tref_istruecond(rc))
+ rc = 0; /* Don't store if condition is not true. */
+ /* fallthrough */
+ case BC_IST: case BC_ISF: /* Type specialization suffices. */
+ if (bc_a(pc[1]) < J->maxslot)
+ J->maxslot = bc_a(pc[1]); /* Shrink used slots. */
+ break;
+
+ /* -- Unary ops --------------------------------------------------------- */
+
+ case BC_NOT:
+ /* Type specialization already forces const result. */
+ rc = tref_istruecond(rc) ? TREF_FALSE : TREF_TRUE;
+ break;
+
+ case BC_LEN:
+ if (tref_isstr(rc))
+ rc = emitir(IRTI(IR_FLOAD), rc, IRFL_STR_LEN);
+ else if (!LJ_52 && tref_istab(rc))
+ rc = lj_ir_call(J, IRCALL_lj_tab_len, rc);
+ else
+ rc = rec_mm_len(J, rc, rcv);
+ break;
+
+ /* -- Arithmetic ops ---------------------------------------------------- */
+
+ case BC_UNM:
+ if (tref_isnumber_str(rc)) {
+ rc = lj_opt_narrow_unm(J, rc, rcv);
+ } else {
+ ix.tab = rc;
+ copyTV(J->L, &ix.tabv, rcv);
+ rc = rec_mm_arith(J, &ix, MM_unm);
+ }
+ break;
+
+ case BC_ADDNV: case BC_SUBNV: case BC_MULNV: case BC_DIVNV: case BC_MODNV:
+ /* Swap rb/rc and rbv/rcv. rav is temp. */
+ ix.tab = rc; ix.key = rc = rb; rb = ix.tab;
+ copyTV(J->L, rav, rbv);
+ copyTV(J->L, rbv, rcv);
+ copyTV(J->L, rcv, rav);
+ if (op == BC_MODNV)
+ goto recmod;
+ /* fallthrough */
+ case BC_ADDVN: case BC_SUBVN: case BC_MULVN: case BC_DIVVN:
+ case BC_ADDVV: case BC_SUBVV: case BC_MULVV: case BC_DIVVV: {
+ MMS mm = bcmode_mm(op);
+ if (tref_isnumber_str(rb) && tref_isnumber_str(rc))
+ rc = lj_opt_narrow_arith(J, rb, rc, rbv, rcv,
+ (int)mm - (int)MM_add + (int)IR_ADD);
+ else
+ rc = rec_mm_arith(J, &ix, mm);
+ break;
+ }
+
+ case BC_MODVN: case BC_MODVV:
+ recmod:
+ if (tref_isnumber_str(rb) && tref_isnumber_str(rc))
+ rc = lj_opt_narrow_mod(J, rb, rc, rbv, rcv);
+ else
+ rc = rec_mm_arith(J, &ix, MM_mod);
+ break;
+
+ case BC_POW:
+ if (tref_isnumber_str(rb) && tref_isnumber_str(rc))
+ rc = lj_opt_narrow_pow(J, rb, rc, rbv, rcv);
+ else
+ rc = rec_mm_arith(J, &ix, MM_pow);
+ break;
+
+ /* -- Constant and move ops --------------------------------------------- */
+
+ case BC_MOV:
+ /* Clear gap of method call to avoid resurrecting previous refs. */
+ if (ra > J->maxslot) J->base[ra-1] = 0;
+ break;
+ case BC_KSTR: case BC_KNUM: case BC_KPRI:
+ break;
+ case BC_KSHORT:
+ rc = lj_ir_kint(J, (int32_t)(int16_t)rc);
+ break;
+ case BC_KNIL:
+ while (ra <= rc)
+ J->base[ra++] = TREF_NIL;
+ if (rc >= J->maxslot) J->maxslot = rc+1;
+ break;
+#if LJ_HASFFI
+ case BC_KCDATA:
+ rc = lj_ir_kgc(J, proto_kgc(J->pt, ~(ptrdiff_t)rc), IRT_CDATA);
+ break;
+#endif
+
+ /* -- Upvalue and function ops ------------------------------------------ */
+
+ case BC_UGET:
+ rc = rec_upvalue(J, rc, 0);
+ break;
+ case BC_USETV: case BC_USETS: case BC_USETN: case BC_USETP:
+ rec_upvalue(J, ra, rc);
+ break;
+
+ /* -- Table ops --------------------------------------------------------- */
+
+ case BC_GGET: case BC_GSET:
+ settabV(J->L, &ix.tabv, tabref(J->fn->l.env));
+ ix.tab = emitir(IRT(IR_FLOAD, IRT_TAB), getcurrf(J), IRFL_FUNC_ENV);
+ ix.idxchain = LJ_MAX_IDXCHAIN;
+ rc = lj_record_idx(J, &ix);
+ break;
+
+ case BC_TGETB: case BC_TSETB:
+ setintV(&ix.keyv, (int32_t)rc);
+ ix.key = lj_ir_kint(J, (int32_t)rc);
+ /* fallthrough */
+ case BC_TGETV: case BC_TGETS: case BC_TSETV: case BC_TSETS:
+ ix.idxchain = LJ_MAX_IDXCHAIN;
+ rc = lj_record_idx(J, &ix);
+ break;
+
+ case BC_TNEW:
+ rc = rec_tnew(J, rc);
+ break;
+ case BC_TDUP:
+ rc = emitir(IRTG(IR_TDUP, IRT_TAB),
+ lj_ir_ktab(J, gco2tab(proto_kgc(J->pt, ~(ptrdiff_t)rc))), 0);
+ break;
+
+ /* -- Calls and vararg handling ----------------------------------------- */
+
+ case BC_ITERC:
+ J->base[ra] = getslot(J, ra-3);
+ J->base[ra+1] = getslot(J, ra-2);
+ J->base[ra+2] = getslot(J, ra-1);
+ { /* Do the actual copy now because lj_record_call needs the values. */
+ TValue *b = &J->L->base[ra];
+ copyTV(J->L, b, b-3);
+ copyTV(J->L, b+1, b-2);
+ copyTV(J->L, b+2, b-1);
+ }
+ lj_record_call(J, ra, (ptrdiff_t)rc-1);
+ break;
+
+ /* L->top is set to L->base+ra+rc+NARGS-1+1. See lj_dispatch_ins(). */
+ case BC_CALLM:
+ rc = (BCReg)(J->L->top - J->L->base) - ra;
+ /* fallthrough */
+ case BC_CALL:
+ lj_record_call(J, ra, (ptrdiff_t)rc-1);
+ break;
+
+ case BC_CALLMT:
+ rc = (BCReg)(J->L->top - J->L->base) - ra;
+ /* fallthrough */
+ case BC_CALLT:
+ lj_record_tailcall(J, ra, (ptrdiff_t)rc-1);
+ break;
+
+ case BC_VARG:
+ rec_varg(J, ra, (ptrdiff_t)rb-1);
+ break;
+
+ /* -- Returns ----------------------------------------------------------- */
+
+ case BC_RETM:
+ /* L->top is set to L->base+ra+rc+NRESULTS-1, see lj_dispatch_ins(). */
+ rc = (BCReg)(J->L->top - J->L->base) - ra + 1;
+ /* fallthrough */
+ case BC_RET: case BC_RET0: case BC_RET1:
+ lj_record_ret(J, ra, (ptrdiff_t)rc-1);
+ break;
+
+ /* -- Loops and branches ------------------------------------------------ */
+
+ case BC_FORI:
+ if (rec_for(J, pc, 0) != LOOPEV_LEAVE)
+ J->loopref = J->cur.nins;
+ break;
+ case BC_JFORI:
+ lua_assert(bc_op(pc[(ptrdiff_t)rc-BCBIAS_J]) == BC_JFORL);
+ if (rec_for(J, pc, 0) != LOOPEV_LEAVE) /* Link to existing loop. */
+ rec_stop(J, LJ_TRLINK_ROOT, bc_d(pc[(ptrdiff_t)rc-BCBIAS_J]));
+ /* Continue tracing if the loop is not entered. */
+ break;
+
+ case BC_FORL:
+ rec_loop_interp(J, pc, rec_for(J, pc+((ptrdiff_t)rc-BCBIAS_J), 1));
+ break;
+ case BC_ITERL:
+ rec_loop_interp(J, pc, rec_iterl(J, *pc));
+ break;
+ case BC_LOOP:
+ rec_loop_interp(J, pc, rec_loop(J, ra));
+ break;
+
+ case BC_JFORL:
+ rec_loop_jit(J, rc, rec_for(J, pc+bc_j(traceref(J, rc)->startins), 1));
+ break;
+ case BC_JITERL:
+ rec_loop_jit(J, rc, rec_iterl(J, traceref(J, rc)->startins));
+ break;
+ case BC_JLOOP:
+ rec_loop_jit(J, rc, rec_loop(J, ra));
+ break;
+
+ case BC_IFORL:
+ case BC_IITERL:
+ case BC_ILOOP:
+ case BC_IFUNCF:
+ case BC_IFUNCV:
+ lj_trace_err(J, LJ_TRERR_BLACKL);
+ break;
+
+ case BC_JMP:
+ if (ra < J->maxslot)
+ J->maxslot = ra; /* Shrink used slots. */
+ break;
+
+ /* -- Function headers -------------------------------------------------- */
+
+ case BC_FUNCF:
+ rec_func_lua(J);
+ break;
+ case BC_JFUNCF:
+ rec_func_jit(J, rc);
+ break;
+
+ case BC_FUNCV:
+ rec_func_vararg(J);
+ rec_func_lua(J);
+ break;
+ case BC_JFUNCV:
+ lua_assert(0); /* Cannot happen. No hotcall counting for varag funcs. */
+ break;
+
+ case BC_FUNCC:
+ case BC_FUNCCW:
+ lj_ffrecord_func(J);
+ break;
+
+ default:
+ if (op >= BC__MAX) {
+ lj_ffrecord_func(J);
+ break;
+ }
+ /* fallthrough */
+ case BC_ITERN:
+ case BC_ISNEXT:
+ case BC_CAT:
+ case BC_UCLO:
+ case BC_FNEW:
+ case BC_TSETM:
+ setintV(&J->errinfo, (int32_t)op);
+ lj_trace_err_info(J, LJ_TRERR_NYIBC);
+ break;
+ }
+
+ /* rc == 0 if we have no result yet, e.g. pending __index metamethod call. */
+ if (bcmode_a(op) == BCMdst && rc) {
+ J->base[ra] = rc;
+ if (ra >= J->maxslot) J->maxslot = ra+1;
+ }
+
+#undef rav
+#undef rbv
+#undef rcv
+
+ /* Limit the number of recorded IR instructions. */
+ if (J->cur.nins > REF_FIRST+(IRRef)J->param[JIT_P_maxrecord])
+ lj_trace_err(J, LJ_TRERR_TRACEOV);
+}
+
+/* -- Recording setup ----------------------------------------------------- */
+
+/* Setup recording for a root trace started by a hot loop. */
+static const BCIns *rec_setup_root(jit_State *J)
+{
+ /* Determine the next PC and the bytecode range for the loop. */
+ const BCIns *pcj, *pc = J->pc;
+ BCIns ins = *pc;
+ BCReg ra = bc_a(ins);
+ switch (bc_op(ins)) {
+ case BC_FORL:
+ J->bc_extent = (MSize)(-bc_j(ins))*sizeof(BCIns);
+ pc += 1+bc_j(ins);
+ J->bc_min = pc;
+ break;
+ case BC_ITERL:
+ lua_assert(bc_op(pc[-1]) == BC_ITERC);
+ J->maxslot = ra + bc_b(pc[-1]) - 1;
+ J->bc_extent = (MSize)(-bc_j(ins))*sizeof(BCIns);
+ pc += 1+bc_j(ins);
+ lua_assert(bc_op(pc[-1]) == BC_JMP);
+ J->bc_min = pc;
+ break;
+ case BC_LOOP:
+ /* Only check BC range for real loops, but not for "repeat until true". */
+ pcj = pc + bc_j(ins);
+ ins = *pcj;
+ if (bc_op(ins) == BC_JMP && bc_j(ins) < 0) {
+ J->bc_min = pcj+1 + bc_j(ins);
+ J->bc_extent = (MSize)(-bc_j(ins))*sizeof(BCIns);
+ }
+ J->maxslot = ra;
+ pc++;
+ break;
+ case BC_RET:
+ case BC_RET0:
+ case BC_RET1:
+ /* No bytecode range check for down-recursive root traces. */
+ J->maxslot = ra + bc_d(ins) - 1;
+ break;
+ case BC_FUNCF:
+ /* No bytecode range check for root traces started by a hot call. */
+ J->maxslot = J->pt->numparams;
+ pc++;
+ break;
+ default:
+ lua_assert(0);
+ break;
+ }
+ return pc;
+}
+
+/* Setup for recording a new trace. */
+void lj_record_setup(jit_State *J)
+{
+ uint32_t i;
+
+ /* Initialize state related to current trace. */
+ memset(J->slot, 0, sizeof(J->slot));
+ memset(J->chain, 0, sizeof(J->chain));
+ memset(J->bpropcache, 0, sizeof(J->bpropcache));
+ J->scev.idx = REF_NIL;
+ setmref(J->scev.pc, NULL);
+
+ J->baseslot = 1; /* Invoking function is at base[-1]. */
+ J->base = J->slot + J->baseslot;
+ J->maxslot = 0;
+ J->framedepth = 0;
+ J->retdepth = 0;
+
+ J->instunroll = J->param[JIT_P_instunroll];
+ J->loopunroll = J->param[JIT_P_loopunroll];
+ J->tailcalled = 0;
+ J->loopref = 0;
+
+ J->bc_min = NULL; /* Means no limit. */
+ J->bc_extent = ~(MSize)0;
+
+ /* Emit instructions for fixed references. Also triggers initial IR alloc. */
+ emitir_raw(IRT(IR_BASE, IRT_P32), J->parent, J->exitno);
+ for (i = 0; i <= 2; i++) {
+ IRIns *ir = IR(REF_NIL-i);
+ ir->i = 0;
+ ir->t.irt = (uint8_t)(IRT_NIL+i);
+ ir->o = IR_KPRI;
+ ir->prev = 0;
+ }
+ J->cur.nk = REF_TRUE;
+
+ J->startpc = J->pc;
+ setmref(J->cur.startpc, J->pc);
+ if (J->parent) { /* Side trace. */
+ GCtrace *T = traceref(J, J->parent);
+ TraceNo root = T->root ? T->root : J->parent;
+ J->cur.root = (uint16_t)root;
+ J->cur.startins = BCINS_AD(BC_JMP, 0, 0);
+ /* Check whether we could at least potentially form an extra loop. */
+ if (J->exitno == 0 && T->snap[0].nent == 0) {
+ /* We can narrow a FORL for some side traces, too. */
+ if (J->pc > proto_bc(J->pt) && bc_op(J->pc[-1]) == BC_JFORI &&
+ bc_d(J->pc[bc_j(J->pc[-1])-1]) == root) {
+ lj_snap_add(J);
+ rec_for_loop(J, J->pc-1, &J->scev, 1);
+ goto sidecheck;
+ }
+ } else {
+ J->startpc = NULL; /* Prevent forming an extra loop. */
+ }
+ lj_snap_replay(J, T);
+ sidecheck:
+ if (traceref(J, J->cur.root)->nchild >= J->param[JIT_P_maxside] ||
+ T->snap[J->exitno].count >= J->param[JIT_P_hotexit] +
+ J->param[JIT_P_tryside]) {
+ rec_stop(J, LJ_TRLINK_INTERP, 0);
+ }
+ } else { /* Root trace. */
+ J->cur.root = 0;
+ J->cur.startins = *J->pc;
+ J->pc = rec_setup_root(J);
+ /* Note: the loop instruction itself is recorded at the end and not
+ ** at the start! So snapshot #0 needs to point to the *next* instruction.
+ */
+ lj_snap_add(J);
+ if (bc_op(J->cur.startins) == BC_FORL)
+ rec_for_loop(J, J->pc-1, &J->scev, 1);
+ if (1 + J->pt->framesize >= LJ_MAX_JSLOTS)
+ lj_trace_err(J, LJ_TRERR_STACKOV);
+ }
+#ifdef LUAJIT_ENABLE_CHECKHOOK
+ /* Regularly check for instruction/line hooks from compiled code and
+ ** exit to the interpreter if the hooks are set.
+ **
+ ** This is a compile-time option and disabled by default, since the
+ ** hook checks may be quite expensive in tight loops.
+ **
+ ** Note this is only useful if hooks are *not* set most of the time.
+ ** Use this only if you want to *asynchronously* interrupt the execution.
+ **
+ ** You can set the instruction hook via lua_sethook() with a count of 1
+ ** from a signal handler or another native thread. Please have a look
+ ** at the first few functions in luajit.c for an example (Ctrl-C handler).
+ */
+ {
+ TRef tr = emitir(IRT(IR_XLOAD, IRT_U8),
+ lj_ir_kptr(J, &J2G(J)->hookmask), IRXLOAD_VOLATILE);
+ tr = emitir(IRTI(IR_BAND), tr, lj_ir_kint(J, (LUA_MASKLINE|LUA_MASKCOUNT)));
+ emitir(IRTGI(IR_EQ), tr, lj_ir_kint(J, 0));
+ }
+#endif
+}
+
+#undef IR
+#undef emitir_raw
+#undef emitir
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_record.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_record.h
new file mode 100644
index 0000000..2bbbde5
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_record.h
@@ -0,0 +1,44 @@
+/*
+** Trace recorder (bytecode -> SSA IR).
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_RECORD_H
+#define _LJ_RECORD_H
+
+#include "lj_obj.h"
+#include "lj_jit.h"
+
+#if LJ_HASJIT
+/* Context for recording an indexed load/store. */
+typedef struct RecordIndex {
+ TValue tabv; /* Runtime value of table (or indexed object). */
+ TValue keyv; /* Runtime value of key. */
+ TValue valv; /* Runtime value of stored value. */
+ TValue mobjv; /* Runtime value of metamethod object. */
+ GCtab *mtv; /* Runtime value of metatable object. */
+ cTValue *oldv; /* Runtime value of previously stored value. */
+ TRef tab; /* Table (or indexed object) reference. */
+ TRef key; /* Key reference. */
+ TRef val; /* Value reference for a store or 0 for a load. */
+ TRef mt; /* Metatable reference. */
+ TRef mobj; /* Metamethod object reference. */
+ int idxchain; /* Index indirections left or 0 for raw lookup. */
+} RecordIndex;
+
+LJ_FUNC int lj_record_objcmp(jit_State *J, TRef a, TRef b,
+ cTValue *av, cTValue *bv);
+LJ_FUNC TRef lj_record_constify(jit_State *J, cTValue *o);
+
+LJ_FUNC void lj_record_call(jit_State *J, BCReg func, ptrdiff_t nargs);
+LJ_FUNC void lj_record_tailcall(jit_State *J, BCReg func, ptrdiff_t nargs);
+LJ_FUNC void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults);
+
+LJ_FUNC int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm);
+LJ_FUNC TRef lj_record_idx(jit_State *J, RecordIndex *ix);
+
+LJ_FUNC void lj_record_ins(jit_State *J);
+LJ_FUNC void lj_record_setup(jit_State *J);
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_snap.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_snap.c
new file mode 100644
index 0000000..e891f7a
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_snap.c
@@ -0,0 +1,862 @@
+/*
+** Snapshot handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_snap_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT
+
+#include "lj_gc.h"
+#include "lj_tab.h"
+#include "lj_state.h"
+#include "lj_frame.h"
+#include "lj_bc.h"
+#include "lj_ir.h"
+#include "lj_jit.h"
+#include "lj_iropt.h"
+#include "lj_trace.h"
+#include "lj_snap.h"
+#include "lj_target.h"
+#if LJ_HASFFI
+#include "lj_ctype.h"
+#include "lj_cdata.h"
+#endif
+
+/* Pass IR on to next optimization in chain (FOLD). */
+#define emitir(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_opt_fold(J))
+
+/* Emit raw IR without passing through optimizations. */
+#define emitir_raw(ot, a, b) (lj_ir_set(J, (ot), (a), (b)), lj_ir_emit(J))
+
+/* -- Snapshot buffer allocation ------------------------------------------ */
+
+/* Grow snapshot buffer. */
+void lj_snap_grow_buf_(jit_State *J, MSize need)
+{
+ MSize maxsnap = (MSize)J->param[JIT_P_maxsnap];
+ if (need > maxsnap)
+ lj_trace_err(J, LJ_TRERR_SNAPOV);
+ lj_mem_growvec(J->L, J->snapbuf, J->sizesnap, maxsnap, SnapShot);
+ J->cur.snap = J->snapbuf;
+}
+
+/* Grow snapshot map buffer. */
+void lj_snap_grow_map_(jit_State *J, MSize need)
+{
+ if (need < 2*J->sizesnapmap)
+ need = 2*J->sizesnapmap;
+ else if (need < 64)
+ need = 64;
+ J->snapmapbuf = (SnapEntry *)lj_mem_realloc(J->L, J->snapmapbuf,
+ J->sizesnapmap*sizeof(SnapEntry), need*sizeof(SnapEntry));
+ J->cur.snapmap = J->snapmapbuf;
+ J->sizesnapmap = need;
+}
+
+/* -- Snapshot generation ------------------------------------------------- */
+
+/* Add all modified slots to the snapshot. */
+static MSize snapshot_slots(jit_State *J, SnapEntry *map, BCReg nslots)
+{
+ IRRef retf = J->chain[IR_RETF]; /* Limits SLOAD restore elimination. */
+ BCReg s;
+ MSize n = 0;
+ for (s = 0; s < nslots; s++) {
+ TRef tr = J->slot[s];
+ IRRef ref = tref_ref(tr);
+ if (ref) {
+ SnapEntry sn = SNAP_TR(s, tr);
+ IRIns *ir = &J->cur.ir[ref];
+ if (!(sn & (SNAP_CONT|SNAP_FRAME)) &&
+ ir->o == IR_SLOAD && ir->op1 == s && ref > retf) {
+ /* No need to snapshot unmodified non-inherited slots. */
+ if (!(ir->op2 & IRSLOAD_INHERIT))
+ continue;
+ /* No need to restore readonly slots and unmodified non-parent slots. */
+ if (!(LJ_DUALNUM && (ir->op2 & IRSLOAD_CONVERT)) &&
+ (ir->op2 & (IRSLOAD_READONLY|IRSLOAD_PARENT)) != IRSLOAD_PARENT)
+ sn |= SNAP_NORESTORE;
+ }
+ if (LJ_SOFTFP && irt_isnum(ir->t))
+ sn |= SNAP_SOFTFPNUM;
+ map[n++] = sn;
+ }
+ }
+ return n;
+}
+
+/* Add frame links at the end of the snapshot. */
+static BCReg snapshot_framelinks(jit_State *J, SnapEntry *map)
+{
+ cTValue *frame = J->L->base - 1;
+ cTValue *lim = J->L->base - J->baseslot;
+ cTValue *ftop = frame + funcproto(frame_func(frame))->framesize;
+ MSize f = 0;
+ map[f++] = SNAP_MKPC(J->pc); /* The current PC is always the first entry. */
+ while (frame > lim) { /* Backwards traversal of all frames above base. */
+ if (frame_islua(frame)) {
+ map[f++] = SNAP_MKPC(frame_pc(frame));
+ frame = frame_prevl(frame);
+ } else if (frame_iscont(frame)) {
+ map[f++] = SNAP_MKFTSZ(frame_ftsz(frame));
+ map[f++] = SNAP_MKPC(frame_contpc(frame));
+ frame = frame_prevd(frame);
+ } else {
+ lua_assert(!frame_isc(frame));
+ map[f++] = SNAP_MKFTSZ(frame_ftsz(frame));
+ frame = frame_prevd(frame);
+ continue;
+ }
+ if (frame + funcproto(frame_func(frame))->framesize > ftop)
+ ftop = frame + funcproto(frame_func(frame))->framesize;
+ }
+ lua_assert(f == (MSize)(1 + J->framedepth));
+ return (BCReg)(ftop - lim);
+}
+
+/* Take a snapshot of the current stack. */
+static void snapshot_stack(jit_State *J, SnapShot *snap, MSize nsnapmap)
+{
+ BCReg nslots = J->baseslot + J->maxslot;
+ MSize nent;
+ SnapEntry *p;
+ /* Conservative estimate. */
+ lj_snap_grow_map(J, nsnapmap + nslots + (MSize)J->framedepth+1);
+ p = &J->cur.snapmap[nsnapmap];
+ nent = snapshot_slots(J, p, nslots);
+ snap->topslot = (uint8_t)snapshot_framelinks(J, p + nent);
+ snap->mapofs = (uint16_t)nsnapmap;
+ snap->ref = (IRRef1)J->cur.nins;
+ snap->nent = (uint8_t)nent;
+ snap->nslots = (uint8_t)nslots;
+ snap->count = 0;
+ J->cur.nsnapmap = (uint16_t)(nsnapmap + nent + 1 + J->framedepth);
+}
+
+/* Add or merge a snapshot. */
+void lj_snap_add(jit_State *J)
+{
+ MSize nsnap = J->cur.nsnap;
+ MSize nsnapmap = J->cur.nsnapmap;
+ /* Merge if no ins. inbetween or if requested and no guard inbetween. */
+ if (J->mergesnap ? !irt_isguard(J->guardemit) :
+ (nsnap > 0 && J->cur.snap[nsnap-1].ref == J->cur.nins)) {
+ if (nsnap == 1) { /* But preserve snap #0 PC. */
+ emitir_raw(IRT(IR_NOP, IRT_NIL), 0, 0);
+ goto nomerge;
+ }
+ nsnapmap = J->cur.snap[--nsnap].mapofs;
+ } else {
+ nomerge:
+ lj_snap_grow_buf(J, nsnap+1);
+ J->cur.nsnap = (uint16_t)(nsnap+1);
+ }
+ J->mergesnap = 0;
+ J->guardemit.irt = 0;
+ snapshot_stack(J, &J->cur.snap[nsnap], nsnapmap);
+}
+
+/* -- Snapshot modification ----------------------------------------------- */
+
+#define SNAP_USEDEF_SLOTS (LJ_MAX_JSLOTS+LJ_STACK_EXTRA)
+
+/* Find unused slots with reaching-definitions bytecode data-flow analysis. */
+static BCReg snap_usedef(jit_State *J, uint8_t *udf,
+ const BCIns *pc, BCReg maxslot)
+{
+ BCReg s;
+ GCobj *o;
+
+ if (maxslot == 0) return 0;
+#ifdef LUAJIT_USE_VALGRIND
+ /* Avoid errors for harmless reads beyond maxslot. */
+ memset(udf, 1, SNAP_USEDEF_SLOTS);
+#else
+ memset(udf, 1, maxslot);
+#endif
+
+ /* Treat open upvalues as used. */
+ o = gcref(J->L->openupval);
+ while (o) {
+ if (uvval(gco2uv(o)) < J->L->base) break;
+ udf[uvval(gco2uv(o)) - J->L->base] = 0;
+ o = gcref(o->gch.nextgc);
+ }
+
+#define USE_SLOT(s) udf[(s)] &= ~1
+#define DEF_SLOT(s) udf[(s)] *= 3
+
+ /* Scan through following bytecode and check for uses/defs. */
+ lua_assert(pc >= proto_bc(J->pt) && pc < proto_bc(J->pt) + J->pt->sizebc);
+ for (;;) {
+ BCIns ins = *pc++;
+ BCOp op = bc_op(ins);
+ switch (bcmode_b(op)) {
+ case BCMvar: USE_SLOT(bc_b(ins)); break;
+ default: break;
+ }
+ switch (bcmode_c(op)) {
+ case BCMvar: USE_SLOT(bc_c(ins)); break;
+ case BCMrbase:
+ lua_assert(op == BC_CAT);
+ for (s = bc_b(ins); s <= bc_c(ins); s++) USE_SLOT(s);
+ for (; s < maxslot; s++) DEF_SLOT(s);
+ break;
+ case BCMjump:
+ handle_jump: {
+ BCReg minslot = bc_a(ins);
+ if (op >= BC_FORI && op <= BC_JFORL) minslot += FORL_EXT;
+ else if (op >= BC_ITERL && op <= BC_JITERL) minslot += bc_b(pc[-2])-1;
+ else if (op == BC_UCLO) { pc += bc_j(ins); break; }
+ for (s = minslot; s < maxslot; s++) DEF_SLOT(s);
+ return minslot < maxslot ? minslot : maxslot;
+ }
+ case BCMlit:
+ if (op == BC_JFORL || op == BC_JITERL || op == BC_JLOOP) {
+ goto handle_jump;
+ } else if (bc_isret(op)) {
+ BCReg top = op == BC_RETM ? maxslot : (bc_a(ins) + bc_d(ins)-1);
+ for (s = 0; s < bc_a(ins); s++) DEF_SLOT(s);
+ for (; s < top; s++) USE_SLOT(s);
+ for (; s < maxslot; s++) DEF_SLOT(s);
+ return 0;
+ }
+ break;
+ case BCMfunc: return maxslot; /* NYI: will abort, anyway. */
+ default: break;
+ }
+ switch (bcmode_a(op)) {
+ case BCMvar: USE_SLOT(bc_a(ins)); break;
+ case BCMdst:
+ if (!(op == BC_ISTC || op == BC_ISFC)) DEF_SLOT(bc_a(ins));
+ break;
+ case BCMbase:
+ if (op >= BC_CALLM && op <= BC_VARG) {
+ BCReg top = (op == BC_CALLM || op == BC_CALLMT || bc_c(ins) == 0) ?
+ maxslot : (bc_a(ins) + bc_c(ins));
+ s = bc_a(ins) - ((op == BC_ITERC || op == BC_ITERN) ? 3 : 0);
+ for (; s < top; s++) USE_SLOT(s);
+ for (; s < maxslot; s++) DEF_SLOT(s);
+ if (op == BC_CALLT || op == BC_CALLMT) {
+ for (s = 0; s < bc_a(ins); s++) DEF_SLOT(s);
+ return 0;
+ }
+ } else if (op == BC_KNIL) {
+ for (s = bc_a(ins); s <= bc_d(ins); s++) DEF_SLOT(s);
+ } else if (op == BC_TSETM) {
+ for (s = bc_a(ins)-1; s < maxslot; s++) USE_SLOT(s);
+ }
+ break;
+ default: break;
+ }
+ lua_assert(pc >= proto_bc(J->pt) && pc < proto_bc(J->pt) + J->pt->sizebc);
+ }
+
+#undef USE_SLOT
+#undef DEF_SLOT
+
+ return 0; /* unreachable */
+}
+
+/* Purge dead slots before the next snapshot. */
+void lj_snap_purge(jit_State *J)
+{
+ uint8_t udf[SNAP_USEDEF_SLOTS];
+ BCReg maxslot = J->maxslot;
+ BCReg s = snap_usedef(J, udf, J->pc, maxslot);
+ for (; s < maxslot; s++)
+ if (udf[s] != 0)
+ J->base[s] = 0; /* Purge dead slots. */
+}
+
+/* Shrink last snapshot. */
+void lj_snap_shrink(jit_State *J)
+{
+ SnapShot *snap = &J->cur.snap[J->cur.nsnap-1];
+ SnapEntry *map = &J->cur.snapmap[snap->mapofs];
+ MSize n, m, nlim, nent = snap->nent;
+ uint8_t udf[SNAP_USEDEF_SLOTS];
+ BCReg maxslot = J->maxslot;
+ BCReg minslot = snap_usedef(J, udf, snap_pc(map[nent]), maxslot);
+ BCReg baseslot = J->baseslot;
+ maxslot += baseslot;
+ minslot += baseslot;
+ snap->nslots = (uint8_t)maxslot;
+ for (n = m = 0; n < nent; n++) { /* Remove unused slots from snapshot. */
+ BCReg s = snap_slot(map[n]);
+ if (s < minslot || (s < maxslot && udf[s-baseslot] == 0))
+ map[m++] = map[n]; /* Only copy used slots. */
+ }
+ snap->nent = (uint8_t)m;
+ nlim = J->cur.nsnapmap - snap->mapofs - 1;
+ while (n <= nlim) map[m++] = map[n++]; /* Move PC + frame links down. */
+ J->cur.nsnapmap = (uint16_t)(snap->mapofs + m); /* Free up space in map. */
+}
+
+/* -- Snapshot access ----------------------------------------------------- */
+
+/* Initialize a Bloom Filter with all renamed refs.
+** There are very few renames (often none), so the filter has
+** very few bits set. This makes it suitable for negative filtering.
+*/
+static BloomFilter snap_renamefilter(GCtrace *T, SnapNo lim)
+{
+ BloomFilter rfilt = 0;
+ IRIns *ir;
+ for (ir = &T->ir[T->nins-1]; ir->o == IR_RENAME; ir--)
+ if (ir->op2 <= lim)
+ bloomset(rfilt, ir->op1);
+ return rfilt;
+}
+
+/* Process matching renames to find the original RegSP. */
+static RegSP snap_renameref(GCtrace *T, SnapNo lim, IRRef ref, RegSP rs)
+{
+ IRIns *ir;
+ for (ir = &T->ir[T->nins-1]; ir->o == IR_RENAME; ir--)
+ if (ir->op1 == ref && ir->op2 <= lim)
+ rs = ir->prev;
+ return rs;
+}
+
+/* Copy RegSP from parent snapshot to the parent links of the IR. */
+IRIns *lj_snap_regspmap(GCtrace *T, SnapNo snapno, IRIns *ir)
+{
+ SnapShot *snap = &T->snap[snapno];
+ SnapEntry *map = &T->snapmap[snap->mapofs];
+ BloomFilter rfilt = snap_renamefilter(T, snapno);
+ MSize n = 0;
+ IRRef ref = 0;
+ for ( ; ; ir++) {
+ uint32_t rs;
+ if (ir->o == IR_SLOAD) {
+ if (!(ir->op2 & IRSLOAD_PARENT)) break;
+ for ( ; ; n++) {
+ lua_assert(n < snap->nent);
+ if (snap_slot(map[n]) == ir->op1) {
+ ref = snap_ref(map[n++]);
+ break;
+ }
+ }
+ } else if (LJ_SOFTFP && ir->o == IR_HIOP) {
+ ref++;
+ } else if (ir->o == IR_PVAL) {
+ ref = ir->op1 + REF_BIAS;
+ } else {
+ break;
+ }
+ rs = T->ir[ref].prev;
+ if (bloomtest(rfilt, ref))
+ rs = snap_renameref(T, snapno, ref, rs);
+ ir->prev = (uint16_t)rs;
+ lua_assert(regsp_used(rs));
+ }
+ return ir;
+}
+
+/* -- Snapshot replay ----------------------------------------------------- */
+
+/* Replay constant from parent trace. */
+static TRef snap_replay_const(jit_State *J, IRIns *ir)
+{
+ /* Only have to deal with constants that can occur in stack slots. */
+ switch ((IROp)ir->o) {
+ case IR_KPRI: return TREF_PRI(irt_type(ir->t));
+ case IR_KINT: return lj_ir_kint(J, ir->i);
+ case IR_KGC: return lj_ir_kgc(J, ir_kgc(ir), irt_t(ir->t));
+ case IR_KNUM: return lj_ir_k64(J, IR_KNUM, ir_knum(ir));
+ case IR_KINT64: return lj_ir_k64(J, IR_KINT64, ir_kint64(ir));
+ case IR_KPTR: return lj_ir_kptr(J, ir_kptr(ir)); /* Continuation. */
+ default: lua_assert(0); return TREF_NIL; break;
+ }
+}
+
+/* De-duplicate parent reference. */
+static TRef snap_dedup(jit_State *J, SnapEntry *map, MSize nmax, IRRef ref)
+{
+ MSize j;
+ for (j = 0; j < nmax; j++)
+ if (snap_ref(map[j]) == ref)
+ return J->slot[snap_slot(map[j])] & ~(SNAP_CONT|SNAP_FRAME);
+ return 0;
+}
+
+/* Emit parent reference with de-duplication. */
+static TRef snap_pref(jit_State *J, GCtrace *T, SnapEntry *map, MSize nmax,
+ BloomFilter seen, IRRef ref)
+{
+ IRIns *ir = &T->ir[ref];
+ TRef tr;
+ if (irref_isk(ref))
+ tr = snap_replay_const(J, ir);
+ else if (!regsp_used(ir->prev))
+ tr = 0;
+ else if (!bloomtest(seen, ref) || (tr = snap_dedup(J, map, nmax, ref)) == 0)
+ tr = emitir(IRT(IR_PVAL, irt_type(ir->t)), ref - REF_BIAS, 0);
+ return tr;
+}
+
+/* Check whether a sunk store corresponds to an allocation. Slow path. */
+static int snap_sunk_store2(GCtrace *T, IRIns *ira, IRIns *irs)
+{
+ if (irs->o == IR_ASTORE || irs->o == IR_HSTORE ||
+ irs->o == IR_FSTORE || irs->o == IR_XSTORE) {
+ IRIns *irk = &T->ir[irs->op1];
+ if (irk->o == IR_AREF || irk->o == IR_HREFK)
+ irk = &T->ir[irk->op1];
+ return (&T->ir[irk->op1] == ira);
+ }
+ return 0;
+}
+
+/* Check whether a sunk store corresponds to an allocation. Fast path. */
+static LJ_AINLINE int snap_sunk_store(GCtrace *T, IRIns *ira, IRIns *irs)
+{
+ if (irs->s != 255)
+ return (ira + irs->s == irs); /* Fast check. */
+ return snap_sunk_store2(T, ira, irs);
+}
+
+/* Replay snapshot state to setup side trace. */
+void lj_snap_replay(jit_State *J, GCtrace *T)
+{
+ SnapShot *snap = &T->snap[J->exitno];
+ SnapEntry *map = &T->snapmap[snap->mapofs];
+ MSize n, nent = snap->nent;
+ BloomFilter seen = 0;
+ int pass23 = 0;
+ J->framedepth = 0;
+ /* Emit IR for slots inherited from parent snapshot. */
+ for (n = 0; n < nent; n++) {
+ SnapEntry sn = map[n];
+ BCReg s = snap_slot(sn);
+ IRRef ref = snap_ref(sn);
+ IRIns *ir = &T->ir[ref];
+ TRef tr;
+ /* The bloom filter avoids O(nent^2) overhead for de-duping slots. */
+ if (bloomtest(seen, ref) && (tr = snap_dedup(J, map, n, ref)) != 0)
+ goto setslot;
+ bloomset(seen, ref);
+ if (irref_isk(ref)) {
+ tr = snap_replay_const(J, ir);
+ } else if (!regsp_used(ir->prev)) {
+ pass23 = 1;
+ lua_assert(s != 0);
+ tr = s;
+ } else {
+ IRType t = irt_type(ir->t);
+ uint32_t mode = IRSLOAD_INHERIT|IRSLOAD_PARENT;
+ if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM)) t = IRT_NUM;
+ if (ir->o == IR_SLOAD) mode |= (ir->op2 & IRSLOAD_READONLY);
+ tr = emitir_raw(IRT(IR_SLOAD, t), s, mode);
+ }
+ setslot:
+ J->slot[s] = tr | (sn&(SNAP_CONT|SNAP_FRAME)); /* Same as TREF_* flags. */
+ J->framedepth += ((sn & (SNAP_CONT|SNAP_FRAME)) && s);
+ if ((sn & SNAP_FRAME))
+ J->baseslot = s+1;
+ }
+ if (pass23) {
+ IRIns *irlast = &T->ir[snap->ref];
+ pass23 = 0;
+ /* Emit dependent PVALs. */
+ for (n = 0; n < nent; n++) {
+ SnapEntry sn = map[n];
+ IRRef refp = snap_ref(sn);
+ IRIns *ir = &T->ir[refp];
+ if (regsp_reg(ir->r) == RID_SUNK) {
+ if (J->slot[snap_slot(sn)] != snap_slot(sn)) continue;
+ pass23 = 1;
+ lua_assert(ir->o == IR_TNEW || ir->o == IR_TDUP ||
+ ir->o == IR_CNEW || ir->o == IR_CNEWI);
+ if (ir->op1 >= T->nk) snap_pref(J, T, map, nent, seen, ir->op1);
+ if (ir->op2 >= T->nk) snap_pref(J, T, map, nent, seen, ir->op2);
+ if (LJ_HASFFI && ir->o == IR_CNEWI) {
+ if (LJ_32 && refp+1 < T->nins && (ir+1)->o == IR_HIOP)
+ snap_pref(J, T, map, nent, seen, (ir+1)->op2);
+ } else {
+ IRIns *irs;
+ for (irs = ir+1; irs < irlast; irs++)
+ if (irs->r == RID_SINK && snap_sunk_store(T, ir, irs)) {
+ if (snap_pref(J, T, map, nent, seen, irs->op2) == 0)
+ snap_pref(J, T, map, nent, seen, T->ir[irs->op2].op1);
+ else if ((LJ_SOFTFP || (LJ_32 && LJ_HASFFI)) &&
+ irs+1 < irlast && (irs+1)->o == IR_HIOP)
+ snap_pref(J, T, map, nent, seen, (irs+1)->op2);
+ }
+ }
+ } else if (!irref_isk(refp) && !regsp_used(ir->prev)) {
+ lua_assert(ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT);
+ J->slot[snap_slot(sn)] = snap_pref(J, T, map, nent, seen, ir->op1);
+ }
+ }
+ /* Replay sunk instructions. */
+ for (n = 0; pass23 && n < nent; n++) {
+ SnapEntry sn = map[n];
+ IRRef refp = snap_ref(sn);
+ IRIns *ir = &T->ir[refp];
+ if (regsp_reg(ir->r) == RID_SUNK) {
+ TRef op1, op2;
+ if (J->slot[snap_slot(sn)] != snap_slot(sn)) { /* De-dup allocs. */
+ J->slot[snap_slot(sn)] = J->slot[J->slot[snap_slot(sn)]];
+ continue;
+ }
+ op1 = ir->op1;
+ if (op1 >= T->nk) op1 = snap_pref(J, T, map, nent, seen, op1);
+ op2 = ir->op2;
+ if (op2 >= T->nk) op2 = snap_pref(J, T, map, nent, seen, op2);
+ if (LJ_HASFFI && ir->o == IR_CNEWI) {
+ if (LJ_32 && refp+1 < T->nins && (ir+1)->o == IR_HIOP) {
+ lj_needsplit(J); /* Emit joining HIOP. */
+ op2 = emitir_raw(IRT(IR_HIOP, IRT_I64), op2,
+ snap_pref(J, T, map, nent, seen, (ir+1)->op2));
+ }
+ J->slot[snap_slot(sn)] = emitir(ir->ot & ~(IRT_MARK|IRT_ISPHI), op1, op2);
+ } else {
+ IRIns *irs;
+ TRef tr = emitir(ir->ot, op1, op2);
+ J->slot[snap_slot(sn)] = tr;
+ for (irs = ir+1; irs < irlast; irs++)
+ if (irs->r == RID_SINK && snap_sunk_store(T, ir, irs)) {
+ IRIns *irr = &T->ir[irs->op1];
+ TRef val, key = irr->op2, tmp = tr;
+ if (irr->o != IR_FREF) {
+ IRIns *irk = &T->ir[key];
+ if (irr->o == IR_HREFK)
+ key = lj_ir_kslot(J, snap_replay_const(J, &T->ir[irk->op1]),
+ irk->op2);
+ else
+ key = snap_replay_const(J, irk);
+ if (irr->o == IR_HREFK || irr->o == IR_AREF) {
+ IRIns *irf = &T->ir[irr->op1];
+ tmp = emitir(irf->ot, tmp, irf->op2);
+ }
+ }
+ tmp = emitir(irr->ot, tmp, key);
+ val = snap_pref(J, T, map, nent, seen, irs->op2);
+ if (val == 0) {
+ IRIns *irc = &T->ir[irs->op2];
+ lua_assert(irc->o == IR_CONV && irc->op2 == IRCONV_NUM_INT);
+ val = snap_pref(J, T, map, nent, seen, irc->op1);
+ val = emitir(IRTN(IR_CONV), val, IRCONV_NUM_INT);
+ } else if ((LJ_SOFTFP || (LJ_32 && LJ_HASFFI)) &&
+ irs+1 < irlast && (irs+1)->o == IR_HIOP) {
+ IRType t = IRT_I64;
+ if (LJ_SOFTFP && irt_type((irs+1)->t) == IRT_SOFTFP)
+ t = IRT_NUM;
+ lj_needsplit(J);
+ if (irref_isk(irs->op2) && irref_isk((irs+1)->op2)) {
+ uint64_t k = (uint32_t)T->ir[irs->op2].i +
+ ((uint64_t)T->ir[(irs+1)->op2].i << 32);
+ val = lj_ir_k64(J, t == IRT_I64 ? IR_KINT64 : IR_KNUM,
+ lj_ir_k64_find(J, k));
+ } else {
+ val = emitir_raw(IRT(IR_HIOP, t), val,
+ snap_pref(J, T, map, nent, seen, (irs+1)->op2));
+ }
+ tmp = emitir(IRT(irs->o, t), tmp, val);
+ continue;
+ }
+ tmp = emitir(irs->ot, tmp, val);
+ } else if (LJ_HASFFI && irs->o == IR_XBAR && ir->o == IR_CNEW) {
+ emitir(IRT(IR_XBAR, IRT_NIL), 0, 0);
+ }
+ }
+ }
+ }
+ }
+ J->base = J->slot + J->baseslot;
+ J->maxslot = snap->nslots - J->baseslot;
+ lj_snap_add(J);
+ if (pass23) /* Need explicit GC step _after_ initial snapshot. */
+ emitir_raw(IRTG(IR_GCSTEP, IRT_NIL), 0, 0);
+}
+
+/* -- Snapshot restore ---------------------------------------------------- */
+
+static void snap_unsink(jit_State *J, GCtrace *T, ExitState *ex,
+ SnapNo snapno, BloomFilter rfilt,
+ IRIns *ir, TValue *o);
+
+/* Restore a value from the trace exit state. */
+static void snap_restoreval(jit_State *J, GCtrace *T, ExitState *ex,
+ SnapNo snapno, BloomFilter rfilt,
+ IRRef ref, TValue *o)
+{
+ IRIns *ir = &T->ir[ref];
+ IRType1 t = ir->t;
+ RegSP rs = ir->prev;
+ if (irref_isk(ref)) { /* Restore constant slot. */
+ lj_ir_kvalue(J->L, o, ir);
+ return;
+ }
+ if (LJ_UNLIKELY(bloomtest(rfilt, ref)))
+ rs = snap_renameref(T, snapno, ref, rs);
+ if (ra_hasspill(regsp_spill(rs))) { /* Restore from spill slot. */
+ int32_t *sps = &ex->spill[regsp_spill(rs)];
+ if (irt_isinteger(t)) {
+ setintV(o, *sps);
+#if !LJ_SOFTFP
+ } else if (irt_isnum(t)) {
+ o->u64 = *(uint64_t *)sps;
+#endif
+ } else if (LJ_64 && irt_islightud(t)) {
+ /* 64 bit lightuserdata which may escape already has the tag bits. */
+ o->u64 = *(uint64_t *)sps;
+ } else {
+ lua_assert(!irt_ispri(t)); /* PRI refs never have a spill slot. */
+ setgcrefi(o->gcr, *sps);
+ setitype(o, irt_toitype(t));
+ }
+ } else { /* Restore from register. */
+ Reg r = regsp_reg(rs);
+ if (ra_noreg(r)) {
+ lua_assert(ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT);
+ snap_restoreval(J, T, ex, snapno, rfilt, ir->op1, o);
+ if (LJ_DUALNUM) setnumV(o, (lua_Number)intV(o));
+ return;
+ } else if (irt_isinteger(t)) {
+ setintV(o, (int32_t)ex->gpr[r-RID_MIN_GPR]);
+#if !LJ_SOFTFP
+ } else if (irt_isnum(t)) {
+ setnumV(o, ex->fpr[r-RID_MIN_FPR]);
+#endif
+ } else if (LJ_64 && irt_islightud(t)) {
+ /* 64 bit lightuserdata which may escape already has the tag bits. */
+ o->u64 = ex->gpr[r-RID_MIN_GPR];
+ } else {
+ if (!irt_ispri(t))
+ setgcrefi(o->gcr, ex->gpr[r-RID_MIN_GPR]);
+ setitype(o, irt_toitype(t));
+ }
+ }
+}
+
+#if LJ_HASFFI
+/* Restore raw data from the trace exit state. */
+static void snap_restoredata(GCtrace *T, ExitState *ex,
+ SnapNo snapno, BloomFilter rfilt,
+ IRRef ref, void *dst, CTSize sz)
+{
+ IRIns *ir = &T->ir[ref];
+ RegSP rs = ir->prev;
+ int32_t *src;
+ uint64_t tmp;
+ if (irref_isk(ref)) {
+ if (ir->o == IR_KNUM || ir->o == IR_KINT64) {
+ src = mref(ir->ptr, int32_t);
+ } else if (sz == 8) {
+ tmp = (uint64_t)(uint32_t)ir->i;
+ src = (int32_t *)&tmp;
+ } else {
+ src = &ir->i;
+ }
+ } else {
+ if (LJ_UNLIKELY(bloomtest(rfilt, ref)))
+ rs = snap_renameref(T, snapno, ref, rs);
+ if (ra_hasspill(regsp_spill(rs))) {
+ src = &ex->spill[regsp_spill(rs)];
+ if (sz == 8 && !irt_is64(ir->t)) {
+ tmp = (uint64_t)(uint32_t)*src;
+ src = (int32_t *)&tmp;
+ }
+ } else {
+ Reg r = regsp_reg(rs);
+ if (ra_noreg(r)) {
+ /* Note: this assumes CNEWI is never used for SOFTFP split numbers. */
+ lua_assert(sz == 8 && ir->o == IR_CONV && ir->op2 == IRCONV_NUM_INT);
+ snap_restoredata(T, ex, snapno, rfilt, ir->op1, dst, 4);
+ *(lua_Number *)dst = (lua_Number)*(int32_t *)dst;
+ return;
+ }
+ src = (int32_t *)&ex->gpr[r-RID_MIN_GPR];
+#if !LJ_SOFTFP
+ if (r >= RID_MAX_GPR) {
+ src = (int32_t *)&ex->fpr[r-RID_MIN_FPR];
+#if LJ_TARGET_PPC
+ if (sz == 4) { /* PPC FPRs are always doubles. */
+ *(float *)dst = (float)*(double *)src;
+ return;
+ }
+#else
+ if (LJ_BE && sz == 4) src++;
+#endif
+ }
+#endif
+ }
+ }
+ lua_assert(sz == 1 || sz == 2 || sz == 4 || sz == 8);
+ if (sz == 4) *(int32_t *)dst = *src;
+ else if (sz == 8) *(int64_t *)dst = *(int64_t *)src;
+ else if (sz == 1) *(int8_t *)dst = (int8_t)*src;
+ else *(int16_t *)dst = (int16_t)*src;
+}
+#endif
+
+/* Unsink allocation from the trace exit state. Unsink sunk stores. */
+static void snap_unsink(jit_State *J, GCtrace *T, ExitState *ex,
+ SnapNo snapno, BloomFilter rfilt,
+ IRIns *ir, TValue *o)
+{
+ lua_assert(ir->o == IR_TNEW || ir->o == IR_TDUP ||
+ ir->o == IR_CNEW || ir->o == IR_CNEWI);
+#if LJ_HASFFI
+ if (ir->o == IR_CNEW || ir->o == IR_CNEWI) {
+ CTState *cts = ctype_cts(J->L);
+ CTypeID id = (CTypeID)T->ir[ir->op1].i;
+ CTSize sz = lj_ctype_size(cts, id);
+ GCcdata *cd = lj_cdata_new(cts, id, sz);
+ setcdataV(J->L, o, cd);
+ if (ir->o == IR_CNEWI) {
+ uint8_t *p = (uint8_t *)cdataptr(cd);
+ lua_assert(sz == 4 || sz == 8);
+ if (LJ_32 && sz == 8 && ir+1 < T->ir + T->nins && (ir+1)->o == IR_HIOP) {
+ snap_restoredata(T, ex, snapno, rfilt, (ir+1)->op2, LJ_LE?p+4:p, 4);
+ if (LJ_BE) p += 4;
+ sz = 4;
+ }
+ snap_restoredata(T, ex, snapno, rfilt, ir->op2, p, sz);
+ } else {
+ IRIns *irs, *irlast = &T->ir[T->snap[snapno].ref];
+ for (irs = ir+1; irs < irlast; irs++)
+ if (irs->r == RID_SINK && snap_sunk_store(T, ir, irs)) {
+ IRIns *iro = &T->ir[T->ir[irs->op1].op2];
+ uint8_t *p = (uint8_t *)cd;
+ CTSize szs;
+ lua_assert(irs->o == IR_XSTORE && T->ir[irs->op1].o == IR_ADD);
+ lua_assert(iro->o == IR_KINT || iro->o == IR_KINT64);
+ if (irt_is64(irs->t)) szs = 8;
+ else if (irt_isi8(irs->t) || irt_isu8(irs->t)) szs = 1;
+ else if (irt_isi16(irs->t) || irt_isu16(irs->t)) szs = 2;
+ else szs = 4;
+ if (LJ_64 && iro->o == IR_KINT64)
+ p += (int64_t)ir_k64(iro)->u64;
+ else
+ p += iro->i;
+ lua_assert(p >= (uint8_t *)cdataptr(cd) &&
+ p + szs <= (uint8_t *)cdataptr(cd) + sz);
+ if (LJ_32 && irs+1 < T->ir + T->nins && (irs+1)->o == IR_HIOP) {
+ lua_assert(szs == 4);
+ snap_restoredata(T, ex, snapno, rfilt, (irs+1)->op2, LJ_LE?p+4:p,4);
+ if (LJ_BE) p += 4;
+ }
+ snap_restoredata(T, ex, snapno, rfilt, irs->op2, p, szs);
+ }
+ }
+ } else
+#endif
+ {
+ IRIns *irs, *irlast;
+ GCtab *t = ir->o == IR_TNEW ? lj_tab_new(J->L, ir->op1, ir->op2) :
+ lj_tab_dup(J->L, ir_ktab(&T->ir[ir->op1]));
+ settabV(J->L, o, t);
+ irlast = &T->ir[T->snap[snapno].ref];
+ for (irs = ir+1; irs < irlast; irs++)
+ if (irs->r == RID_SINK && snap_sunk_store(T, ir, irs)) {
+ IRIns *irk = &T->ir[irs->op1];
+ TValue tmp, *val;
+ lua_assert(irs->o == IR_ASTORE || irs->o == IR_HSTORE ||
+ irs->o == IR_FSTORE);
+ if (irk->o == IR_FREF) {
+ lua_assert(irk->op2 == IRFL_TAB_META);
+ snap_restoreval(J, T, ex, snapno, rfilt, irs->op2, &tmp);
+ /* NOBARRIER: The table is new (marked white). */
+ setgcref(t->metatable, obj2gco(tabV(&tmp)));
+ } else {
+ irk = &T->ir[irk->op2];
+ if (irk->o == IR_KSLOT) irk = &T->ir[irk->op1];
+ lj_ir_kvalue(J->L, &tmp, irk);
+ val = lj_tab_set(J->L, t, &tmp);
+ /* NOBARRIER: The table is new (marked white). */
+ snap_restoreval(J, T, ex, snapno, rfilt, irs->op2, val);
+ if (LJ_SOFTFP && irs+1 < T->ir + T->nins && (irs+1)->o == IR_HIOP) {
+ snap_restoreval(J, T, ex, snapno, rfilt, (irs+1)->op2, &tmp);
+ val->u32.hi = tmp.u32.lo;
+ }
+ }
+ }
+ }
+}
+
+/* Restore interpreter state from exit state with the help of a snapshot. */
+const BCIns *lj_snap_restore(jit_State *J, void *exptr)
+{
+ ExitState *ex = (ExitState *)exptr;
+ SnapNo snapno = J->exitno; /* For now, snapno == exitno. */
+ GCtrace *T = traceref(J, J->parent);
+ SnapShot *snap = &T->snap[snapno];
+ MSize n, nent = snap->nent;
+ SnapEntry *map = &T->snapmap[snap->mapofs];
+ SnapEntry *flinks = &T->snapmap[snap_nextofs(T, snap)-1];
+ int32_t ftsz0;
+ TValue *frame;
+ BloomFilter rfilt = snap_renamefilter(T, snapno);
+ const BCIns *pc = snap_pc(map[nent]);
+ lua_State *L = J->L;
+
+ /* Set interpreter PC to the next PC to get correct error messages. */
+ setcframe_pc(cframe_raw(L->cframe), pc+1);
+
+ /* Make sure the stack is big enough for the slots from the snapshot. */
+ if (LJ_UNLIKELY(L->base + snap->topslot >= tvref(L->maxstack))) {
+ L->top = curr_topL(L);
+ lj_state_growstack(L, snap->topslot - curr_proto(L)->framesize);
+ }
+
+ /* Fill stack slots with data from the registers and spill slots. */
+ frame = L->base-1;
+ ftsz0 = frame_ftsz(frame); /* Preserve link to previous frame in slot #0. */
+ for (n = 0; n < nent; n++) {
+ SnapEntry sn = map[n];
+ if (!(sn & SNAP_NORESTORE)) {
+ TValue *o = &frame[snap_slot(sn)];
+ IRRef ref = snap_ref(sn);
+ IRIns *ir = &T->ir[ref];
+ if (ir->r == RID_SUNK) {
+ MSize j;
+ for (j = 0; j < n; j++)
+ if (snap_ref(map[j]) == ref) { /* De-duplicate sunk allocations. */
+ copyTV(L, o, &frame[snap_slot(map[j])]);
+ goto dupslot;
+ }
+ snap_unsink(J, T, ex, snapno, rfilt, ir, o);
+ dupslot:
+ continue;
+ }
+ snap_restoreval(J, T, ex, snapno, rfilt, ref, o);
+ if (LJ_SOFTFP && (sn & SNAP_SOFTFPNUM) && tvisint(o)) {
+ TValue tmp;
+ snap_restoreval(J, T, ex, snapno, rfilt, ref+1, &tmp);
+ o->u32.hi = tmp.u32.lo;
+ } else if ((sn & (SNAP_CONT|SNAP_FRAME))) {
+ /* Overwrite tag with frame link. */
+ o->fr.tp.ftsz = snap_slot(sn) != 0 ? (int32_t)*flinks-- : ftsz0;
+ L->base = o+1;
+ }
+ }
+ }
+ lua_assert(map + nent == flinks);
+
+ /* Compute current stack top. */
+ switch (bc_op(*pc)) {
+ default:
+ if (bc_op(*pc) < BC_FUNCF) {
+ L->top = curr_topL(L);
+ break;
+ }
+ /* fallthrough */
+ case BC_CALLM: case BC_CALLMT: case BC_RETM: case BC_TSETM:
+ L->top = frame + snap->nslots;
+ break;
+ }
+ return pc;
+}
+
+#undef emitir_raw
+#undef emitir
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_snap.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_snap.h
new file mode 100644
index 0000000..2c9ae3d
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_snap.h
@@ -0,0 +1,34 @@
+/*
+** Snapshot handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_SNAP_H
+#define _LJ_SNAP_H
+
+#include "lj_obj.h"
+#include "lj_jit.h"
+
+#if LJ_HASJIT
+LJ_FUNC void lj_snap_add(jit_State *J);
+LJ_FUNC void lj_snap_purge(jit_State *J);
+LJ_FUNC void lj_snap_shrink(jit_State *J);
+LJ_FUNC IRIns *lj_snap_regspmap(GCtrace *T, SnapNo snapno, IRIns *ir);
+LJ_FUNC void lj_snap_replay(jit_State *J, GCtrace *T);
+LJ_FUNC const BCIns *lj_snap_restore(jit_State *J, void *exptr);
+LJ_FUNC void lj_snap_grow_buf_(jit_State *J, MSize need);
+LJ_FUNC void lj_snap_grow_map_(jit_State *J, MSize need);
+
+static LJ_AINLINE void lj_snap_grow_buf(jit_State *J, MSize need)
+{
+ if (LJ_UNLIKELY(need > J->sizesnap)) lj_snap_grow_buf_(J, need);
+}
+
+static LJ_AINLINE void lj_snap_grow_map(jit_State *J, MSize need)
+{
+ if (LJ_UNLIKELY(need > J->sizesnapmap)) lj_snap_grow_map_(J, need);
+}
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_state.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_state.c
new file mode 100644
index 0000000..f891351
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_state.c
@@ -0,0 +1,287 @@
+/*
+** State and stack handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#define lj_state_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_func.h"
+#include "lj_meta.h"
+#include "lj_state.h"
+#include "lj_frame.h"
+#if LJ_HASFFI
+#include "lj_ctype.h"
+#endif
+#include "lj_trace.h"
+#include "lj_dispatch.h"
+#include "lj_vm.h"
+#include "lj_lex.h"
+#include "lj_alloc.h"
+
+/* -- Stack handling ------------------------------------------------------ */
+
+/* Stack sizes. */
+#define LJ_STACK_MIN LUA_MINSTACK /* Min. stack size. */
+#define LJ_STACK_MAX LUAI_MAXSTACK /* Max. stack size. */
+#define LJ_STACK_START (2*LJ_STACK_MIN) /* Starting stack size. */
+#define LJ_STACK_MAXEX (LJ_STACK_MAX + 1 + LJ_STACK_EXTRA)
+
+/* Explanation of LJ_STACK_EXTRA:
+**
+** Calls to metamethods store their arguments beyond the current top
+** without checking for the stack limit. This avoids stack resizes which
+** would invalidate passed TValue pointers. The stack check is performed
+** later by the function header. This can safely resize the stack or raise
+** an error. Thus we need some extra slots beyond the current stack limit.
+**
+** Most metamethods need 4 slots above top (cont, mobj, arg1, arg2) plus
+** one extra slot if mobj is not a function. Only lj_meta_tset needs 5
+** slots above top, but then mobj is always a function. So we can get by
+** with 5 extra slots.
+*/
+
+/* Resize stack slots and adjust pointers in state. */
+static void resizestack(lua_State *L, MSize n)
+{
+ TValue *st, *oldst = tvref(L->stack);
+ ptrdiff_t delta;
+ MSize oldsize = L->stacksize;
+ MSize realsize = n + 1 + LJ_STACK_EXTRA;
+ GCobj *up;
+ lua_assert((MSize)(tvref(L->maxstack)-oldst)==L->stacksize-LJ_STACK_EXTRA-1);
+ st = (TValue *)lj_mem_realloc(L, tvref(L->stack),
+ (MSize)(L->stacksize*sizeof(TValue)),
+ (MSize)(realsize*sizeof(TValue)));
+ setmref(L->stack, st);
+ delta = (char *)st - (char *)oldst;
+ setmref(L->maxstack, st + n);
+ while (oldsize < realsize) /* Clear new slots. */
+ setnilV(st + oldsize++);
+ L->stacksize = realsize;
+ L->base = (TValue *)((char *)L->base + delta);
+ L->top = (TValue *)((char *)L->top + delta);
+ for (up = gcref(L->openupval); up != NULL; up = gcnext(up))
+ setmref(gco2uv(up)->v, (TValue *)((char *)uvval(gco2uv(up)) + delta));
+ if (obj2gco(L) == gcref(G(L)->jit_L))
+ setmref(G(L)->jit_base, mref(G(L)->jit_base, char) + delta);
+}
+
+/* Relimit stack after error, in case the limit was overdrawn. */
+void lj_state_relimitstack(lua_State *L)
+{
+ if (L->stacksize > LJ_STACK_MAXEX && L->top-tvref(L->stack) < LJ_STACK_MAX-1)
+ resizestack(L, LJ_STACK_MAX);
+}
+
+/* Try to shrink the stack (called from GC). */
+void lj_state_shrinkstack(lua_State *L, MSize used)
+{
+ if (L->stacksize > LJ_STACK_MAXEX)
+ return; /* Avoid stack shrinking while handling stack overflow. */
+ if (4*used < L->stacksize &&
+ 2*(LJ_STACK_START+LJ_STACK_EXTRA) < L->stacksize &&
+ obj2gco(L) != gcref(G(L)->jit_L)) /* Don't shrink stack of live trace. */
+ resizestack(L, L->stacksize >> 1);
+}
+
+/* Try to grow stack. */
+void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need)
+{
+ MSize n;
+ if (L->stacksize > LJ_STACK_MAXEX) /* Overflow while handling overflow? */
+ lj_err_throw(L, LUA_ERRERR);
+ n = L->stacksize + need;
+ if (n > LJ_STACK_MAX) {
+ n += 2*LUA_MINSTACK;
+ } else if (n < 2*L->stacksize) {
+ n = 2*L->stacksize;
+ if (n >= LJ_STACK_MAX)
+ n = LJ_STACK_MAX;
+ }
+ resizestack(L, n);
+ if (L->stacksize > LJ_STACK_MAXEX)
+ lj_err_msg(L, LJ_ERR_STKOV);
+}
+
+void LJ_FASTCALL lj_state_growstack1(lua_State *L)
+{
+ lj_state_growstack(L, 1);
+}
+
+/* Allocate basic stack for new state. */
+static void stack_init(lua_State *L1, lua_State *L)
+{
+ TValue *stend, *st = lj_mem_newvec(L, LJ_STACK_START+LJ_STACK_EXTRA, TValue);
+ setmref(L1->stack, st);
+ L1->stacksize = LJ_STACK_START + LJ_STACK_EXTRA;
+ stend = st + L1->stacksize;
+ setmref(L1->maxstack, stend - LJ_STACK_EXTRA - 1);
+ L1->base = L1->top = st+1;
+ setthreadV(L1, st, L1); /* Needed for curr_funcisL() on empty stack. */
+ while (st < stend) /* Clear new slots. */
+ setnilV(st++);
+}
+
+/* -- State handling ------------------------------------------------------ */
+
+/* Open parts that may cause memory-allocation errors. */
+static TValue *cpluaopen(lua_State *L, lua_CFunction dummy, void *ud)
+{
+ global_State *g = G(L);
+ UNUSED(dummy);
+ UNUSED(ud);
+ stack_init(L, L);
+ /* NOBARRIER: State initialization, all objects are white. */
+ setgcref(L->env, obj2gco(lj_tab_new(L, 0, LJ_MIN_GLOBAL)));
+ settabV(L, registry(L), lj_tab_new(L, 0, LJ_MIN_REGISTRY));
+ lj_str_resize(L, LJ_MIN_STRTAB-1);
+ lj_meta_init(L);
+ lj_lex_init(L);
+ fixstring(lj_err_str(L, LJ_ERR_ERRMEM)); /* Preallocate memory error msg. */
+ g->gc.threshold = 4*g->gc.total;
+ lj_trace_initstate(g);
+ return NULL;
+}
+
+static void close_state(lua_State *L)
+{
+ global_State *g = G(L);
+ lj_func_closeuv(L, tvref(L->stack));
+ lj_gc_freeall(g);
+ lua_assert(gcref(g->gc.root) == obj2gco(L));
+ lua_assert(g->strnum == 0);
+ lj_trace_freestate(g);
+#if LJ_HASFFI
+ lj_ctype_freestate(g);
+#endif
+ lj_mem_freevec(g, g->strhash, g->strmask+1, GCRef);
+ lj_str_freebuf(g, &g->tmpbuf);
+ lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue);
+ lua_assert(g->gc.total == sizeof(GG_State));
+#ifndef LUAJIT_USE_SYSMALLOC
+ if (g->allocf == lj_alloc_f)
+ lj_alloc_destroy(g->allocd);
+ else
+#endif
+ g->allocf(g->allocd, G2GG(g), sizeof(GG_State), 0);
+}
+
+#if LJ_64 && !(defined(LUAJIT_USE_VALGRIND) && defined(LUAJIT_USE_SYSMALLOC))
+lua_State *lj_state_newstate(lua_Alloc f, void *ud)
+#else
+LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud)
+#endif
+{
+ GG_State *GG = (GG_State *)f(ud, NULL, 0, sizeof(GG_State));
+ lua_State *L = &GG->L;
+ global_State *g = &GG->g;
+ if (GG == NULL || !checkptr32(GG)) return NULL;
+ memset(GG, 0, sizeof(GG_State));
+ L->gct = ~LJ_TTHREAD;
+ L->marked = LJ_GC_WHITE0 | LJ_GC_FIXED | LJ_GC_SFIXED; /* Prevent free. */
+ L->dummy_ffid = FF_C;
+ setmref(L->glref, g);
+ g->gc.currentwhite = LJ_GC_WHITE0 | LJ_GC_FIXED;
+ g->strempty.marked = LJ_GC_WHITE0;
+ g->strempty.gct = ~LJ_TSTR;
+ g->allocf = f;
+ g->allocd = ud;
+ setgcref(g->mainthref, obj2gco(L));
+ setgcref(g->uvhead.prev, obj2gco(&g->uvhead));
+ setgcref(g->uvhead.next, obj2gco(&g->uvhead));
+ g->strmask = ~(MSize)0;
+ setnilV(registry(L));
+ setnilV(&g->nilnode.val);
+ setnilV(&g->nilnode.key);
+ setmref(g->nilnode.freetop, &g->nilnode);
+ lj_str_initbuf(&g->tmpbuf);
+ g->gc.state = GCSpause;
+ setgcref(g->gc.root, obj2gco(L));
+ setmref(g->gc.sweep, &g->gc.root);
+ g->gc.total = sizeof(GG_State);
+ g->gc.pause = LUAI_GCPAUSE;
+ g->gc.stepmul = LUAI_GCMUL;
+ lj_dispatch_init((GG_State *)L);
+ L->status = LUA_ERRERR+1; /* Avoid touching the stack upon memory error. */
+ if (lj_vm_cpcall(L, NULL, NULL, cpluaopen) != 0) {
+ /* Memory allocation error: free partial state. */
+ close_state(L);
+ return NULL;
+ }
+ L->status = 0;
+ return L;
+}
+
+static TValue *cpfinalize(lua_State *L, lua_CFunction dummy, void *ud)
+{
+ UNUSED(dummy);
+ UNUSED(ud);
+ lj_gc_finalize_cdata(L);
+ lj_gc_finalize_udata(L);
+ /* Frame pop omitted. */
+ return NULL;
+}
+
+LUA_API void lua_close(lua_State *L)
+{
+ global_State *g = G(L);
+ int i;
+ L = mainthread(g); /* Only the main thread can be closed. */
+ lj_func_closeuv(L, tvref(L->stack));
+ lj_gc_separateudata(g, 1); /* Separate udata which have GC metamethods. */
+#if LJ_HASJIT
+ G2J(g)->flags &= ~JIT_F_ON;
+ G2J(g)->state = LJ_TRACE_IDLE;
+ lj_dispatch_update(g);
+#endif
+ for (i = 0;;) {
+ hook_enter(g);
+ L->status = 0;
+ L->cframe = NULL;
+ L->base = L->top = tvref(L->stack) + 1;
+ if (lj_vm_cpcall(L, NULL, NULL, cpfinalize) == 0) {
+ if (++i >= 10) break;
+ lj_gc_separateudata(g, 1); /* Separate udata again. */
+ if (gcref(g->gc.mmudata) == NULL) /* Until nothing is left to do. */
+ break;
+ }
+ }
+ close_state(L);
+}
+
+lua_State *lj_state_new(lua_State *L)
+{
+ lua_State *L1 = lj_mem_newobj(L, lua_State);
+ L1->gct = ~LJ_TTHREAD;
+ L1->dummy_ffid = FF_C;
+ L1->status = 0;
+ L1->stacksize = 0;
+ setmref(L1->stack, NULL);
+ L1->cframe = NULL;
+ /* NOBARRIER: The lua_State is new (marked white). */
+ setgcrefnull(L1->openupval);
+ setmrefr(L1->glref, L->glref);
+ setgcrefr(L1->env, L->env);
+ stack_init(L1, L); /* init stack */
+ lua_assert(iswhite(obj2gco(L1)));
+ return L1;
+}
+
+void LJ_FASTCALL lj_state_free(global_State *g, lua_State *L)
+{
+ lua_assert(L != mainthread(g));
+ lj_func_closeuv(L, tvref(L->stack));
+ lua_assert(gcref(L->openupval) == NULL);
+ lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue);
+ lj_mem_freet(g, L);
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_state.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_state.h
new file mode 100644
index 0000000..d5b476b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_state.h
@@ -0,0 +1,35 @@
+/*
+** State and stack handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_STATE_H
+#define _LJ_STATE_H
+
+#include "lj_obj.h"
+
+#define incr_top(L) \
+ (++L->top >= tvref(L->maxstack) && (lj_state_growstack1(L), 0))
+
+#define savestack(L, p) ((char *)(p) - mref(L->stack, char))
+#define restorestack(L, n) ((TValue *)(mref(L->stack, char) + (n)))
+
+LJ_FUNC void lj_state_relimitstack(lua_State *L);
+LJ_FUNC void lj_state_shrinkstack(lua_State *L, MSize used);
+LJ_FUNCA void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need);
+LJ_FUNC void LJ_FASTCALL lj_state_growstack1(lua_State *L);
+
+static LJ_AINLINE void lj_state_checkstack(lua_State *L, MSize need)
+{
+ if ((mref(L->maxstack, char) - (char *)L->top) <=
+ (ptrdiff_t)need*(ptrdiff_t)sizeof(TValue))
+ lj_state_growstack(L, need);
+}
+
+LJ_FUNC lua_State *lj_state_new(lua_State *L);
+LJ_FUNC void LJ_FASTCALL lj_state_free(global_State *g, lua_State *L);
+#if LJ_64
+LJ_FUNC lua_State *lj_state_newstate(lua_Alloc f, void *ud);
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_str.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_str.c
new file mode 100644
index 0000000..aae6ec5
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_str.c
@@ -0,0 +1,339 @@
+/*
+** String handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#include <stdio.h>
+
+#define lj_str_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_str.h"
+#include "lj_state.h"
+#include "lj_char.h"
+
+/* -- String interning ---------------------------------------------------- */
+
+/* Ordered compare of strings. Assumes string data is 4-byte aligned. */
+int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b)
+{
+ MSize i, n = a->len > b->len ? b->len : a->len;
+ for (i = 0; i < n; i += 4) {
+ /* Note: innocuous access up to end of string + 3. */
+ uint32_t va = *(const uint32_t *)(strdata(a)+i);
+ uint32_t vb = *(const uint32_t *)(strdata(b)+i);
+ if (va != vb) {
+#if LJ_LE
+ va = lj_bswap(va); vb = lj_bswap(vb);
+#endif
+ i -= n;
+ if ((int32_t)i >= -3) {
+ va >>= 32+(i<<3); vb >>= 32+(i<<3);
+ if (va == vb) break;
+ }
+ return va < vb ? -1 : 1;
+ }
+ }
+ return (int32_t)(a->len - b->len);
+}
+
+/* Fast string data comparison. Caveat: unaligned access to 1st string! */
+static LJ_AINLINE int str_fastcmp(const char *a, const char *b, MSize len)
+{
+ MSize i = 0;
+ lua_assert(len > 0);
+ lua_assert((((uintptr_t)a+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4);
+ do { /* Note: innocuous access up to end of string + 3. */
+ uint32_t v = lj_getu32(a+i) ^ *(const uint32_t *)(b+i);
+ if (v) {
+ i -= len;
+#if LJ_LE
+ return (int32_t)i >= -3 ? (v << (32+(i<<3))) : 1;
+#else
+ return (int32_t)i >= -3 ? (v >> (32+(i<<3))) : 1;
+#endif
+ }
+ i += 4;
+ } while (i < len);
+ return 0;
+}
+
+/* Resize the string hash table (grow and shrink). */
+void lj_str_resize(lua_State *L, MSize newmask)
+{
+ global_State *g = G(L);
+ GCRef *newhash;
+ MSize i;
+ if (g->gc.state == GCSsweepstring || newmask >= LJ_MAX_STRTAB-1)
+ return; /* No resizing during GC traversal or if already too big. */
+ newhash = lj_mem_newvec(L, newmask+1, GCRef);
+ memset(newhash, 0, (newmask+1)*sizeof(GCRef));
+ for (i = g->strmask; i != ~(MSize)0; i--) { /* Rehash old table. */
+ GCobj *p = gcref(g->strhash[i]);
+ while (p) { /* Follow each hash chain and reinsert all strings. */
+ MSize h = gco2str(p)->hash & newmask;
+ GCobj *next = gcnext(p);
+ /* NOBARRIER: The string table is a GC root. */
+ setgcrefr(p->gch.nextgc, newhash[h]);
+ setgcref(newhash[h], p);
+ p = next;
+ }
+ }
+ lj_mem_freevec(g, g->strhash, g->strmask+1, GCRef);
+ g->strmask = newmask;
+ g->strhash = newhash;
+}
+
+/* Intern a string and return string object. */
+GCstr *lj_str_new(lua_State *L, const char *str, size_t lenx)
+{
+ global_State *g;
+ GCstr *s;
+ GCobj *o;
+ MSize len = (MSize)lenx;
+ MSize a, b, h = len;
+ if (lenx >= LJ_MAX_STR)
+ lj_err_msg(L, LJ_ERR_STROV);
+ g = G(L);
+ /* Compute string hash. Constants taken from lookup3 hash by Bob Jenkins. */
+ if (len >= 4) { /* Caveat: unaligned access! */
+ a = lj_getu32(str);
+ h ^= lj_getu32(str+len-4);
+ b = lj_getu32(str+(len>>1)-2);
+ h ^= b; h -= lj_rol(b, 14);
+ b += lj_getu32(str+(len>>2)-1);
+ } else if (len > 0) {
+ a = *(const uint8_t *)str;
+ h ^= *(const uint8_t *)(str+len-1);
+ b = *(const uint8_t *)(str+(len>>1));
+ h ^= b; h -= lj_rol(b, 14);
+ } else {
+ return &g->strempty;
+ }
+ a ^= h; a -= lj_rol(h, 11);
+ b ^= a; b -= lj_rol(a, 25);
+ h ^= b; h -= lj_rol(b, 16);
+ /* Check if the string has already been interned. */
+ o = gcref(g->strhash[h & g->strmask]);
+ if (LJ_LIKELY((((uintptr_t)str+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4)) {
+ while (o != NULL) {
+ GCstr *sx = gco2str(o);
+ if (sx->len == len && str_fastcmp(str, strdata(sx), len) == 0) {
+ /* Resurrect if dead. Can only happen with fixstring() (keywords). */
+ if (isdead(g, o)) flipwhite(o);
+ return sx; /* Return existing string. */
+ }
+ o = gcnext(o);
+ }
+ } else { /* Slow path: end of string is too close to a page boundary. */
+ while (o != NULL) {
+ GCstr *sx = gco2str(o);
+ if (sx->len == len && memcmp(str, strdata(sx), len) == 0) {
+ /* Resurrect if dead. Can only happen with fixstring() (keywords). */
+ if (isdead(g, o)) flipwhite(o);
+ return sx; /* Return existing string. */
+ }
+ o = gcnext(o);
+ }
+ }
+ /* Nope, create a new string. */
+ s = lj_mem_newt(L, sizeof(GCstr)+len+1, GCstr);
+ newwhite(g, s);
+ s->gct = ~LJ_TSTR;
+ s->len = len;
+ s->hash = h;
+ s->reserved = 0;
+ memcpy(strdatawr(s), str, len);
+ strdatawr(s)[len] = '\0'; /* Zero-terminate string. */
+ /* Add it to string hash table. */
+ h &= g->strmask;
+ s->nextgc = g->strhash[h];
+ /* NOBARRIER: The string table is a GC root. */
+ setgcref(g->strhash[h], obj2gco(s));
+ if (g->strnum++ > g->strmask) /* Allow a 100% load factor. */
+ lj_str_resize(L, (g->strmask<<1)+1); /* Grow string table. */
+ return s; /* Return newly interned string. */
+}
+
+void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s)
+{
+ g->strnum--;
+ lj_mem_free(g, s, sizestring(s));
+}
+
+/* -- Type conversions ---------------------------------------------------- */
+
+/* Print number to buffer. Canonicalizes non-finite values. */
+size_t LJ_FASTCALL lj_str_bufnum(char *s, cTValue *o)
+{
+ if (LJ_LIKELY((o->u32.hi << 1) < 0xffe00000)) { /* Finite? */
+ lua_Number n = o->n;
+#if __BIONIC__
+ if (tvismzero(o)) { s[0] = '-'; s[1] = '0'; return 2; }
+#endif
+ return (size_t)lua_number2str(s, n);
+ } else if (((o->u32.hi & 0x000fffff) | o->u32.lo) != 0) {
+ s[0] = 'n'; s[1] = 'a'; s[2] = 'n'; return 3;
+ } else if ((o->u32.hi & 0x80000000) == 0) {
+ s[0] = 'i'; s[1] = 'n'; s[2] = 'f'; return 3;
+ } else {
+ s[0] = '-'; s[1] = 'i'; s[2] = 'n'; s[3] = 'f'; return 4;
+ }
+}
+
+/* Print integer to buffer. Returns pointer to start. */
+char * LJ_FASTCALL lj_str_bufint(char *p, int32_t k)
+{
+ uint32_t u = (uint32_t)(k < 0 ? -k : k);
+ p += 1+10;
+ do { *--p = (char)('0' + u % 10); } while (u /= 10);
+ if (k < 0) *--p = '-';
+ return p;
+}
+
+/* Convert number to string. */
+GCstr * LJ_FASTCALL lj_str_fromnum(lua_State *L, const lua_Number *np)
+{
+ char buf[LJ_STR_NUMBUF];
+ size_t len = lj_str_bufnum(buf, (TValue *)np);
+ return lj_str_new(L, buf, len);
+}
+
+/* Convert integer to string. */
+GCstr * LJ_FASTCALL lj_str_fromint(lua_State *L, int32_t k)
+{
+ char s[1+10];
+ char *p = lj_str_bufint(s, k);
+ return lj_str_new(L, p, (size_t)(s+sizeof(s)-p));
+}
+
+GCstr * LJ_FASTCALL lj_str_fromnumber(lua_State *L, cTValue *o)
+{
+ return tvisint(o) ? lj_str_fromint(L, intV(o)) : lj_str_fromnum(L, &o->n);
+}
+
+/* -- String formatting --------------------------------------------------- */
+
+static void addstr(lua_State *L, SBuf *sb, const char *str, MSize len)
+{
+ char *p;
+ MSize i;
+ if (sb->n + len > sb->sz) {
+ MSize sz = sb->sz * 2;
+ while (sb->n + len > sz) sz = sz * 2;
+ lj_str_resizebuf(L, sb, sz);
+ }
+ p = sb->buf + sb->n;
+ sb->n += len;
+ for (i = 0; i < len; i++) p[i] = str[i];
+}
+
+static void addchar(lua_State *L, SBuf *sb, int c)
+{
+ if (sb->n + 1 > sb->sz) {
+ MSize sz = sb->sz * 2;
+ lj_str_resizebuf(L, sb, sz);
+ }
+ sb->buf[sb->n++] = (char)c;
+}
+
+/* Push formatted message as a string object to Lua stack. va_list variant. */
+const char *lj_str_pushvf(lua_State *L, const char *fmt, va_list argp)
+{
+ SBuf *sb = &G(L)->tmpbuf;
+ lj_str_needbuf(L, sb, (MSize)strlen(fmt));
+ lj_str_resetbuf(sb);
+ for (;;) {
+ const char *e = strchr(fmt, '%');
+ if (e == NULL) break;
+ addstr(L, sb, fmt, (MSize)(e-fmt));
+ /* This function only handles %s, %c, %d, %f and %p formats. */
+ switch (e[1]) {
+ case 's': {
+ const char *s = va_arg(argp, char *);
+ if (s == NULL) s = "(null)";
+ addstr(L, sb, s, (MSize)strlen(s));
+ break;
+ }
+ case 'c':
+ addchar(L, sb, va_arg(argp, int));
+ break;
+ case 'd': {
+ char buf[LJ_STR_INTBUF];
+ char *p = lj_str_bufint(buf, va_arg(argp, int32_t));
+ addstr(L, sb, p, (MSize)(buf+LJ_STR_INTBUF-p));
+ break;
+ }
+ case 'f': {
+ char buf[LJ_STR_NUMBUF];
+ TValue tv;
+ MSize len;
+ tv.n = (lua_Number)(va_arg(argp, LUAI_UACNUMBER));
+ len = (MSize)lj_str_bufnum(buf, &tv);
+ addstr(L, sb, buf, len);
+ break;
+ }
+ case 'p': {
+#define FMTP_CHARS (2*sizeof(ptrdiff_t))
+ char buf[2+FMTP_CHARS];
+ ptrdiff_t p = (ptrdiff_t)(va_arg(argp, void *));
+ ptrdiff_t i, lasti = 2+FMTP_CHARS;
+ if (p == 0) {
+ addstr(L, sb, "NULL", 4);
+ break;
+ }
+#if LJ_64
+ /* Shorten output for 64 bit pointers. */
+ lasti = 2+2*4+((p >> 32) ? 2+2*(lj_fls((uint32_t)(p >> 32))>>3) : 0);
+#endif
+ buf[0] = '0';
+ buf[1] = 'x';
+ for (i = lasti-1; i >= 2; i--, p >>= 4)
+ buf[i] = "0123456789abcdef"[(p & 15)];
+ addstr(L, sb, buf, (MSize)lasti);
+ break;
+ }
+ case '%':
+ addchar(L, sb, '%');
+ break;
+ default:
+ addchar(L, sb, '%');
+ addchar(L, sb, e[1]);
+ break;
+ }
+ fmt = e+2;
+ }
+ addstr(L, sb, fmt, (MSize)strlen(fmt));
+ setstrV(L, L->top, lj_str_new(L, sb->buf, sb->n));
+ incr_top(L);
+ return strVdata(L->top - 1);
+}
+
+/* Push formatted message as a string object to Lua stack. Vararg variant. */
+const char *lj_str_pushf(lua_State *L, const char *fmt, ...)
+{
+ const char *msg;
+ va_list argp;
+ va_start(argp, fmt);
+ msg = lj_str_pushvf(L, fmt, argp);
+ va_end(argp);
+ return msg;
+}
+
+/* -- Buffer handling ----------------------------------------------------- */
+
+char *lj_str_needbuf(lua_State *L, SBuf *sb, MSize sz)
+{
+ if (sz > sb->sz) {
+ if (sz < LJ_MIN_SBUF) sz = LJ_MIN_SBUF;
+ lj_str_resizebuf(L, sb, sz);
+ }
+ return sb->buf;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_str.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_str.h
new file mode 100644
index 0000000..be04a97
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_str.h
@@ -0,0 +1,50 @@
+/*
+** String handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_STR_H
+#define _LJ_STR_H
+
+#include <stdarg.h>
+
+#include "lj_obj.h"
+
+/* String interning. */
+LJ_FUNC int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b);
+LJ_FUNC void lj_str_resize(lua_State *L, MSize newmask);
+LJ_FUNCA GCstr *lj_str_new(lua_State *L, const char *str, size_t len);
+LJ_FUNC void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s);
+
+#define lj_str_newz(L, s) (lj_str_new(L, s, strlen(s)))
+#define lj_str_newlit(L, s) (lj_str_new(L, "" s, sizeof(s)-1))
+
+/* Type conversions. */
+LJ_FUNC size_t LJ_FASTCALL lj_str_bufnum(char *s, cTValue *o);
+LJ_FUNC char * LJ_FASTCALL lj_str_bufint(char *p, int32_t k);
+LJ_FUNCA GCstr * LJ_FASTCALL lj_str_fromnum(lua_State *L, const lua_Number *np);
+LJ_FUNC GCstr * LJ_FASTCALL lj_str_fromint(lua_State *L, int32_t k);
+LJ_FUNCA GCstr * LJ_FASTCALL lj_str_fromnumber(lua_State *L, cTValue *o);
+
+#define LJ_STR_INTBUF (1+10)
+#define LJ_STR_NUMBUF LUAI_MAXNUMBER2STR
+
+/* String formatting. */
+LJ_FUNC const char *lj_str_pushvf(lua_State *L, const char *fmt, va_list argp);
+LJ_FUNC const char *lj_str_pushf(lua_State *L, const char *fmt, ...)
+#if defined(__GNUC__)
+ __attribute__ ((format (printf, 2, 3)))
+#endif
+ ;
+
+/* Resizable string buffers. Struct definition in lj_obj.h. */
+LJ_FUNC char *lj_str_needbuf(lua_State *L, SBuf *sb, MSize sz);
+
+#define lj_str_initbuf(sb) ((sb)->buf = NULL, (sb)->sz = 0)
+#define lj_str_resetbuf(sb) ((sb)->n = 0)
+#define lj_str_resizebuf(L, sb, size) \
+ ((sb)->buf = (char *)lj_mem_realloc(L, (sb)->buf, (sb)->sz, (size)), \
+ (sb)->sz = (size))
+#define lj_str_freebuf(g, sb) lj_mem_free(g, (void *)(sb)->buf, (sb)->sz)
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_strscan.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_strscan.c
new file mode 100644
index 0000000..f1e34a3
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_strscan.c
@@ -0,0 +1,498 @@
+/*
+** String scanning.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#include <math.h>
+
+#define lj_strscan_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#include "lj_char.h"
+#include "lj_strscan.h"
+
+/* -- Scanning numbers ---------------------------------------------------- */
+
+/*
+** Rationale for the builtin string to number conversion library:
+**
+** It removes a dependency on libc's strtod(), which is a true portability
+** nightmare. Mainly due to the plethora of supported OS and toolchain
+** combinations. Sadly, the various implementations
+** a) are often buggy, incomplete (no hex floats) and/or imprecise,
+** b) sometimes crash or hang on certain inputs,
+** c) return non-standard NaNs that need to be filtered out, and
+** d) fail if the locale-specific decimal separator is not a dot,
+** which can only be fixed with atrocious workarounds.
+**
+** Also, most of the strtod() implementations are hopelessly bloated,
+** which is not just an I-cache hog, but a problem for static linkage
+** on embedded systems, too.
+**
+** OTOH the builtin conversion function is very compact. Even though it
+** does a lot more, like parsing long longs, octal or imaginary numbers
+** and returning the result in different formats:
+** a) It needs less than 3 KB (!) of machine code (on x64 with -Os),
+** b) it doesn't perform any dynamic allocation and,
+** c) it needs only around 600 bytes of stack space.
+**
+** The builtin function is faster than strtod() for typical inputs, e.g.
+** "123", "1.5" or "1e6". Arguably, it's slower for very large exponents,
+** which are not very common (this could be fixed, if needed).
+**
+** And most importantly, the builtin function is equally precise on all
+** platforms. It correctly converts and rounds any input to a double.
+** If this is not the case, please send a bug report -- but PLEASE verify
+** that the implementation you're comparing to is not the culprit!
+**
+** The implementation quickly pre-scans the entire string first and
+** handles simple integers on-the-fly. Otherwise, it dispatches to the
+** base-specific parser. Hex and octal is straightforward.
+**
+** Decimal to binary conversion uses a fixed-length circular buffer in
+** base 100. Some simple cases are handled directly. For other cases, the
+** number in the buffer is up-scaled or down-scaled until the integer part
+** is in the proper range. Then the integer part is rounded and converted
+** to a double which is finally rescaled to the result. Denormals need
+** special treatment to prevent incorrect 'double rounding'.
+*/
+
+/* Definitions for circular decimal digit buffer (base 100 = 2 digits/byte). */
+#define STRSCAN_DIG 1024
+#define STRSCAN_MAXDIG 800 /* 772 + extra are sufficient. */
+#define STRSCAN_DDIG (STRSCAN_DIG/2)
+#define STRSCAN_DMASK (STRSCAN_DDIG-1)
+
+/* Helpers for circular buffer. */
+#define DNEXT(a) (((a)+1) & STRSCAN_DMASK)
+#define DPREV(a) (((a)-1) & STRSCAN_DMASK)
+#define DLEN(lo, hi) ((int32_t)(((lo)-(hi)) & STRSCAN_DMASK))
+
+#define casecmp(c, k) (((c) | 0x20) == k)
+
+/* Final conversion to double. */
+static void strscan_double(uint64_t x, TValue *o, int32_t ex2, int32_t neg)
+{
+ double n;
+
+ /* Avoid double rounding for denormals. */
+ if (LJ_UNLIKELY(ex2 <= -1075 && x != 0)) {
+ /* NYI: all of this generates way too much code on 32 bit CPUs. */
+#if defined(__GNUC__) && LJ_64
+ int32_t b = (int32_t)(__builtin_clzll(x)^63);
+#else
+ int32_t b = (x>>32) ? 32+(int32_t)lj_fls((uint32_t)(x>>32)) :
+ (int32_t)lj_fls((uint32_t)x);
+#endif
+ if ((int32_t)b + ex2 <= -1023 && (int32_t)b + ex2 >= -1075) {
+ uint64_t rb = (uint64_t)1 << (-1075-ex2);
+ if ((x & rb) && ((x & (rb+rb+rb-1)))) x += rb+rb;
+ x = (x & ~(rb+rb-1));
+ }
+ }
+
+ /* Convert to double using a signed int64_t conversion, then rescale. */
+ lua_assert((int64_t)x >= 0);
+ n = (double)(int64_t)x;
+ if (neg) n = -n;
+ if (ex2) n = ldexp(n, ex2);
+ o->n = n;
+}
+
+/* Parse hexadecimal number. */
+static StrScanFmt strscan_hex(const uint8_t *p, TValue *o,
+ StrScanFmt fmt, uint32_t opt,
+ int32_t ex2, int32_t neg, uint32_t dig)
+{
+ uint64_t x = 0;
+ uint32_t i;
+
+ /* Scan hex digits. */
+ for (i = dig > 16 ? 16 : dig ; i; i--, p++) {
+ uint32_t d = (*p != '.' ? *p : *++p); if (d > '9') d += 9;
+ x = (x << 4) + (d & 15);
+ }
+
+ /* Summarize rounding-effect of excess digits. */
+ for (i = 16; i < dig; i++, p++)
+ x |= ((*p != '.' ? *p : *++p) != '0'), ex2 += 4;
+
+ /* Format-specific handling. */
+ switch (fmt) {
+ case STRSCAN_INT:
+ if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) {
+ o->i = neg ? -(int32_t)x : (int32_t)x;
+ return STRSCAN_INT; /* Fast path for 32 bit integers. */
+ }
+ if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; break; }
+ /* fallthrough */
+ case STRSCAN_U32:
+ if (dig > 8) return STRSCAN_ERROR;
+ o->i = neg ? -(int32_t)x : (int32_t)x;
+ return STRSCAN_U32;
+ case STRSCAN_I64:
+ case STRSCAN_U64:
+ if (dig > 16) return STRSCAN_ERROR;
+ o->u64 = neg ? (uint64_t)-(int64_t)x : x;
+ return fmt;
+ default:
+ break;
+ }
+
+ /* Reduce range then convert to double. */
+ if ((x & U64x(c0000000,0000000))) { x = (x >> 2) | (x & 3); ex2 += 2; }
+ strscan_double(x, o, ex2, neg);
+ return fmt;
+}
+
+/* Parse octal number. */
+static StrScanFmt strscan_oct(const uint8_t *p, TValue *o,
+ StrScanFmt fmt, int32_t neg, uint32_t dig)
+{
+ uint64_t x = 0;
+
+ /* Scan octal digits. */
+ if (dig > 22 || (dig == 22 && *p > '1')) return STRSCAN_ERROR;
+ while (dig-- > 0) {
+ if (!(*p >= '0' && *p <= '7')) return STRSCAN_ERROR;
+ x = (x << 3) + (*p++ & 7);
+ }
+
+ /* Format-specific handling. */
+ switch (fmt) {
+ case STRSCAN_INT:
+ if (x >= 0x80000000u+neg) fmt = STRSCAN_U32;
+ /* fallthrough */
+ case STRSCAN_U32:
+ if ((x >> 32)) return STRSCAN_ERROR;
+ o->i = neg ? -(int32_t)x : (int32_t)x;
+ break;
+ default:
+ case STRSCAN_I64:
+ case STRSCAN_U64:
+ o->u64 = neg ? (uint64_t)-(int64_t)x : x;
+ break;
+ }
+ return fmt;
+}
+
+/* Parse decimal number. */
+static StrScanFmt strscan_dec(const uint8_t *p, TValue *o,
+ StrScanFmt fmt, uint32_t opt,
+ int32_t ex10, int32_t neg, uint32_t dig)
+{
+ uint8_t xi[STRSCAN_DDIG], *xip = xi;
+
+ if (dig) {
+ uint32_t i = dig;
+ if (i > STRSCAN_MAXDIG) {
+ ex10 += (int32_t)(i - STRSCAN_MAXDIG);
+ i = STRSCAN_MAXDIG;
+ }
+ /* Scan unaligned leading digit. */
+ if (((ex10^i) & 1))
+ *xip++ = ((*p != '.' ? *p : *++p) & 15), i--, p++;
+ /* Scan aligned double-digits. */
+ for ( ; i > 1; i -= 2) {
+ uint32_t d = 10 * ((*p != '.' ? *p : *++p) & 15); p++;
+ *xip++ = d + ((*p != '.' ? *p : *++p) & 15); p++;
+ }
+ /* Scan and realign trailing digit. */
+ if (i) *xip++ = 10 * ((*p != '.' ? *p : *++p) & 15), ex10--, dig++, p++;
+
+ /* Summarize rounding-effect of excess digits. */
+ if (dig > STRSCAN_MAXDIG) {
+ do {
+ if ((*p != '.' ? *p : *++p) != '0') { xip[-1] |= 1; break; }
+ p++;
+ } while (--dig > STRSCAN_MAXDIG);
+ dig = STRSCAN_MAXDIG;
+ } else { /* Simplify exponent. */
+ while (ex10 > 0 && dig <= 18) *xip++ = 0, ex10 -= 2, dig += 2;
+ }
+ } else { /* Only got zeros. */
+ ex10 = 0;
+ xi[0] = 0;
+ }
+
+ /* Fast path for numbers in integer format (but handles e.g. 1e6, too). */
+ if (dig <= 20 && ex10 == 0) {
+ uint8_t *xis;
+ uint64_t x = xi[0];
+ double n;
+ for (xis = xi+1; xis < xip; xis++) x = x * 100 + *xis;
+ if (!(dig == 20 && (xi[0] > 18 || (int64_t)x >= 0))) { /* No overflow? */
+ /* Format-specific handling. */
+ switch (fmt) {
+ case STRSCAN_INT:
+ if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) {
+ o->i = neg ? -(int32_t)x : (int32_t)x;
+ return STRSCAN_INT; /* Fast path for 32 bit integers. */
+ }
+ if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; goto plainnumber; }
+ /* fallthrough */
+ case STRSCAN_U32:
+ if ((x >> 32) != 0) return STRSCAN_ERROR;
+ o->i = neg ? -(int32_t)x : (int32_t)x;
+ return STRSCAN_U32;
+ case STRSCAN_I64:
+ case STRSCAN_U64:
+ o->u64 = neg ? (uint64_t)-(int64_t)x : x;
+ return fmt;
+ default:
+ plainnumber: /* Fast path for plain numbers < 2^63. */
+ if ((int64_t)x < 0) break;
+ n = (double)(int64_t)x;
+ if (neg) n = -n;
+ o->n = n;
+ return fmt;
+ }
+ }
+ }
+
+ /* Slow non-integer path. */
+ if (fmt == STRSCAN_INT) {
+ if ((opt & STRSCAN_OPT_C)) return STRSCAN_ERROR;
+ fmt = STRSCAN_NUM;
+ } else if (fmt > STRSCAN_INT) {
+ return STRSCAN_ERROR;
+ }
+ {
+ uint32_t hi = 0, lo = (uint32_t)(xip-xi);
+ int32_t ex2 = 0, idig = (int32_t)lo + (ex10 >> 1);
+
+ lua_assert(lo > 0 && (ex10 & 1) == 0);
+
+ /* Handle simple overflow/underflow. */
+ if (idig > 310/2) { if (neg) setminfV(o); else setpinfV(o); return fmt; }
+ else if (idig < -326/2) { o->n = neg ? -0.0 : 0.0; return fmt; }
+
+ /* Scale up until we have at least 17 or 18 integer part digits. */
+ while (idig < 9 && idig < DLEN(lo, hi)) {
+ uint32_t i, cy = 0;
+ ex2 -= 6;
+ for (i = DPREV(lo); ; i = DPREV(i)) {
+ uint32_t d = (xi[i] << 6) + cy;
+ cy = (((d >> 2) * 5243) >> 17); d = d - cy * 100; /* Div/mod 100. */
+ xi[i] = (uint8_t)d;
+ if (i == hi) break;
+ if (d == 0 && i == DPREV(lo)) lo = i;
+ }
+ if (cy) {
+ hi = DPREV(hi);
+ if (xi[DPREV(lo)] == 0) lo = DPREV(lo);
+ else if (hi == lo) { lo = DPREV(lo); xi[DPREV(lo)] |= xi[lo]; }
+ xi[hi] = (uint8_t)cy; idig++;
+ }
+ }
+
+ /* Scale down until no more than 17 or 18 integer part digits remain. */
+ while (idig > 9) {
+ uint32_t i = hi, cy = 0;
+ ex2 += 6;
+ do {
+ cy += xi[i];
+ xi[i] = (cy >> 6);
+ cy = 100 * (cy & 0x3f);
+ if (xi[i] == 0 && i == hi) hi = DNEXT(hi), idig--;
+ i = DNEXT(i);
+ } while (i != lo);
+ while (cy) {
+ if (hi == lo) { xi[DPREV(lo)] |= 1; break; }
+ xi[lo] = (cy >> 6); lo = DNEXT(lo);
+ cy = 100 * (cy & 0x3f);
+ }
+ }
+
+ /* Collect integer part digits and convert to rescaled double. */
+ {
+ uint64_t x = xi[hi];
+ uint32_t i;
+ for (i = DNEXT(hi); --idig > 0 && i != lo; i = DNEXT(i))
+ x = x * 100 + xi[i];
+ if (i == lo) {
+ while (--idig >= 0) x = x * 100;
+ } else { /* Gather round bit from remaining digits. */
+ x <<= 1; ex2--;
+ do {
+ if (xi[i]) { x |= 1; break; }
+ i = DNEXT(i);
+ } while (i != lo);
+ }
+ strscan_double(x, o, ex2, neg);
+ }
+ }
+ return fmt;
+}
+
+/* Scan string containing a number. Returns format. Returns value in o. */
+StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt)
+{
+ int32_t neg = 0;
+
+ /* Remove leading space, parse sign and non-numbers. */
+ if (LJ_UNLIKELY(!lj_char_isdigit(*p))) {
+ while (lj_char_isspace(*p)) p++;
+ if (*p == '+' || *p == '-') neg = (*p++ == '-');
+ if (LJ_UNLIKELY(*p >= 'A')) { /* Parse "inf", "infinity" or "nan". */
+ TValue tmp;
+ setnanV(&tmp);
+ if (casecmp(p[0],'i') && casecmp(p[1],'n') && casecmp(p[2],'f')) {
+ if (neg) setminfV(&tmp); else setpinfV(&tmp);
+ p += 3;
+ if (casecmp(p[0],'i') && casecmp(p[1],'n') && casecmp(p[2],'i') &&
+ casecmp(p[3],'t') && casecmp(p[4],'y')) p += 5;
+ } else if (casecmp(p[0],'n') && casecmp(p[1],'a') && casecmp(p[2],'n')) {
+ p += 3;
+ }
+ while (lj_char_isspace(*p)) p++;
+ if (*p) return STRSCAN_ERROR;
+ o->u64 = tmp.u64;
+ return STRSCAN_NUM;
+ }
+ }
+
+ /* Parse regular number. */
+ {
+ StrScanFmt fmt = STRSCAN_INT;
+ int cmask = LJ_CHAR_DIGIT;
+ int base = (opt & STRSCAN_OPT_C) && *p == '0' ? 0 : 10;
+ const uint8_t *sp, *dp = NULL;
+ uint32_t dig = 0, hasdig = 0, x = 0;
+ int32_t ex = 0;
+
+ /* Determine base and skip leading zeros. */
+ if (LJ_UNLIKELY(*p <= '0')) {
+ if (*p == '0' && casecmp(p[1], 'x'))
+ base = 16, cmask = LJ_CHAR_XDIGIT, p += 2;
+ for ( ; ; p++) {
+ if (*p == '0') {
+ hasdig = 1;
+ } else if (*p == '.') {
+ if (dp) return STRSCAN_ERROR;
+ dp = p;
+ } else {
+ break;
+ }
+ }
+ }
+
+ /* Preliminary digit and decimal point scan. */
+ for (sp = p; ; p++) {
+ if (LJ_LIKELY(lj_char_isa(*p, cmask))) {
+ x = x * 10 + (*p & 15); /* For fast path below. */
+ dig++;
+ } else if (*p == '.') {
+ if (dp) return STRSCAN_ERROR;
+ dp = p;
+ } else {
+ break;
+ }
+ }
+ if (!(hasdig | dig)) return STRSCAN_ERROR;
+
+ /* Handle decimal point. */
+ if (dp) {
+ fmt = STRSCAN_NUM;
+ if (dig) {
+ ex = (int32_t)(dp-(p-1)); dp = p-1;
+ while (ex < 0 && *dp-- == '0') ex++, dig--; /* Skip trailing zeros. */
+ if (base == 16) ex *= 4;
+ }
+ }
+
+ /* Parse exponent. */
+ if (casecmp(*p, (uint32_t)(base == 16 ? 'p' : 'e'))) {
+ uint32_t xx;
+ int negx = 0;
+ fmt = STRSCAN_NUM; p++;
+ if (*p == '+' || *p == '-') negx = (*p++ == '-');
+ if (!lj_char_isdigit(*p)) return STRSCAN_ERROR;
+ xx = (*p++ & 15);
+ while (lj_char_isdigit(*p)) {
+ if (xx < 65536) xx = xx * 10 + (*p & 15);
+ p++;
+ }
+ ex += negx ? -(int32_t)xx : (int32_t)xx;
+ }
+
+ /* Parse suffix. */
+ if (*p) {
+ /* I (IMAG), U (U32), LL (I64), ULL/LLU (U64), L (long), UL/LU (ulong). */
+ /* NYI: f (float). Not needed until cp_number() handles non-integers. */
+ if (casecmp(*p, 'i')) {
+ if (!(opt & STRSCAN_OPT_IMAG)) return STRSCAN_ERROR;
+ p++; fmt = STRSCAN_IMAG;
+ } else if (fmt == STRSCAN_INT) {
+ if (casecmp(*p, 'u')) p++, fmt = STRSCAN_U32;
+ if (casecmp(*p, 'l')) {
+ p++;
+ if (casecmp(*p, 'l')) p++, fmt += STRSCAN_I64 - STRSCAN_INT;
+ else if (!(opt & STRSCAN_OPT_C)) return STRSCAN_ERROR;
+ else if (sizeof(long) == 8) fmt += STRSCAN_I64 - STRSCAN_INT;
+ }
+ if (casecmp(*p, 'u') && (fmt == STRSCAN_INT || fmt == STRSCAN_I64))
+ p++, fmt += STRSCAN_U32 - STRSCAN_INT;
+ if ((fmt == STRSCAN_U32 && !(opt & STRSCAN_OPT_C)) ||
+ (fmt >= STRSCAN_I64 && !(opt & STRSCAN_OPT_LL)))
+ return STRSCAN_ERROR;
+ }
+ while (lj_char_isspace(*p)) p++;
+ if (*p) return STRSCAN_ERROR;
+ }
+
+ /* Fast path for decimal 32 bit integers. */
+ if (fmt == STRSCAN_INT && base == 10 &&
+ (dig < 10 || (dig == 10 && *sp <= '2' && x < 0x80000000u+neg))) {
+ int32_t y = neg ? -(int32_t)x : (int32_t)x;
+ if ((opt & STRSCAN_OPT_TONUM)) {
+ o->n = (double)y;
+ return STRSCAN_NUM;
+ } else {
+ o->i = y;
+ return STRSCAN_INT;
+ }
+ }
+
+ /* Dispatch to base-specific parser. */
+ if (base == 0 && !(fmt == STRSCAN_NUM || fmt == STRSCAN_IMAG))
+ return strscan_oct(sp, o, fmt, neg, dig);
+ if (base == 16)
+ fmt = strscan_hex(sp, o, fmt, opt, ex, neg, dig);
+ else
+ fmt = strscan_dec(sp, o, fmt, opt, ex, neg, dig);
+
+ /* Try to convert number to integer, if requested. */
+ if (fmt == STRSCAN_NUM && (opt & STRSCAN_OPT_TOINT)) {
+ double n = o->n;
+ int32_t i = lj_num2int(n);
+ if (n == (lua_Number)i) { o->i = i; return STRSCAN_INT; }
+ }
+ return fmt;
+ }
+}
+
+int LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o)
+{
+ StrScanFmt fmt = lj_strscan_scan((const uint8_t *)strdata(str), o,
+ STRSCAN_OPT_TONUM);
+ lua_assert(fmt == STRSCAN_ERROR || fmt == STRSCAN_NUM);
+ return (fmt != STRSCAN_ERROR);
+}
+
+#if LJ_DUALNUM
+int LJ_FASTCALL lj_strscan_number(GCstr *str, TValue *o)
+{
+ StrScanFmt fmt = lj_strscan_scan((const uint8_t *)strdata(str), o,
+ STRSCAN_OPT_TOINT);
+ lua_assert(fmt == STRSCAN_ERROR || fmt == STRSCAN_NUM || fmt == STRSCAN_INT);
+ if (fmt == STRSCAN_INT) setitype(o, LJ_TISNUM);
+ return (fmt != STRSCAN_ERROR);
+}
+#endif
+
+#undef DNEXT
+#undef DPREV
+#undef DLEN
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_strscan.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_strscan.h
new file mode 100644
index 0000000..6fb0dda
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_strscan.h
@@ -0,0 +1,39 @@
+/*
+** String scanning.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_STRSCAN_H
+#define _LJ_STRSCAN_H
+
+#include "lj_obj.h"
+
+/* Options for accepted/returned formats. */
+#define STRSCAN_OPT_TOINT 0x01 /* Convert to int32_t, if possible. */
+#define STRSCAN_OPT_TONUM 0x02 /* Always convert to double. */
+#define STRSCAN_OPT_IMAG 0x04
+#define STRSCAN_OPT_LL 0x08
+#define STRSCAN_OPT_C 0x10
+
+/* Returned format. */
+typedef enum {
+ STRSCAN_ERROR,
+ STRSCAN_NUM, STRSCAN_IMAG,
+ STRSCAN_INT, STRSCAN_U32, STRSCAN_I64, STRSCAN_U64,
+} StrScanFmt;
+
+LJ_FUNC StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt);
+LJ_FUNC int LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o);
+#if LJ_DUALNUM
+LJ_FUNC int LJ_FASTCALL lj_strscan_number(GCstr *str, TValue *o);
+#else
+#define lj_strscan_number(s, o) lj_strscan_num((s), (o))
+#endif
+
+/* Check for number or convert string to number/int in-place (!). */
+static LJ_AINLINE int lj_strscan_numberobj(TValue *o)
+{
+ return tvisnumber(o) || (tvisstr(o) && lj_strscan_number(strV(o), o));
+}
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_tab.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_tab.c
new file mode 100644
index 0000000..f2f3c0b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_tab.c
@@ -0,0 +1,654 @@
+/*
+** Table handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Major portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#define lj_tab_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_tab.h"
+
+/* -- Object hashing ------------------------------------------------------ */
+
+/* Hash values are masked with the table hash mask and used as an index. */
+static LJ_AINLINE Node *hashmask(const GCtab *t, uint32_t hash)
+{
+ Node *n = noderef(t->node);
+ return &n[hash & t->hmask];
+}
+
+/* String hashes are precomputed when they are interned. */
+#define hashstr(t, s) hashmask(t, (s)->hash)
+
+#define hashlohi(t, lo, hi) hashmask((t), hashrot((lo), (hi)))
+#define hashnum(t, o) hashlohi((t), (o)->u32.lo, ((o)->u32.hi << 1))
+#define hashptr(t, p) hashlohi((t), u32ptr(p), u32ptr(p) + HASH_BIAS)
+#define hashgcref(t, r) hashlohi((t), gcrefu(r), gcrefu(r) + HASH_BIAS)
+
+/* Hash an arbitrary key and return its anchor position in the hash table. */
+static Node *hashkey(const GCtab *t, cTValue *key)
+{
+ lua_assert(!tvisint(key));
+ if (tvisstr(key))
+ return hashstr(t, strV(key));
+ else if (tvisnum(key))
+ return hashnum(t, key);
+ else if (tvisbool(key))
+ return hashmask(t, boolV(key));
+ else
+ return hashgcref(t, key->gcr);
+ /* Only hash 32 bits of lightuserdata on a 64 bit CPU. Good enough? */
+}
+
+/* -- Table creation and destruction -------------------------------------- */
+
+/* Create new hash part for table. */
+static LJ_AINLINE void newhpart(lua_State *L, GCtab *t, uint32_t hbits)
+{
+ uint32_t hsize;
+ Node *node;
+ lua_assert(hbits != 0);
+ if (hbits > LJ_MAX_HBITS)
+ lj_err_msg(L, LJ_ERR_TABOV);
+ hsize = 1u << hbits;
+ node = lj_mem_newvec(L, hsize, Node);
+ setmref(node->freetop, &node[hsize]);
+ setmref(t->node, node);
+ t->hmask = hsize-1;
+}
+
+/*
+** Q: Why all of these copies of t->hmask, t->node etc. to local variables?
+** A: Because alias analysis for C is _really_ tough.
+** Even state-of-the-art C compilers won't produce good code without this.
+*/
+
+/* Clear hash part of table. */
+static LJ_AINLINE void clearhpart(GCtab *t)
+{
+ uint32_t i, hmask = t->hmask;
+ Node *node = noderef(t->node);
+ lua_assert(t->hmask != 0);
+ for (i = 0; i <= hmask; i++) {
+ Node *n = &node[i];
+ setmref(n->next, NULL);
+ setnilV(&n->key);
+ setnilV(&n->val);
+ }
+}
+
+/* Clear array part of table. */
+static LJ_AINLINE void clearapart(GCtab *t)
+{
+ uint32_t i, asize = t->asize;
+ TValue *array = tvref(t->array);
+ for (i = 0; i < asize; i++)
+ setnilV(&array[i]);
+}
+
+/* Create a new table. Note: the slots are not initialized (yet). */
+static GCtab *newtab(lua_State *L, uint32_t asize, uint32_t hbits)
+{
+ GCtab *t;
+ /* First try to colocate the array part. */
+ if (LJ_MAX_COLOSIZE != 0 && asize > 0 && asize <= LJ_MAX_COLOSIZE) {
+ lua_assert((sizeof(GCtab) & 7) == 0);
+ t = (GCtab *)lj_mem_newgco(L, sizetabcolo(asize));
+ t->gct = ~LJ_TTAB;
+ t->nomm = (uint8_t)~0;
+ t->colo = (int8_t)asize;
+ setmref(t->array, (TValue *)((char *)t + sizeof(GCtab)));
+ setgcrefnull(t->metatable);
+ t->asize = asize;
+ t->hmask = 0;
+ setmref(t->node, &G(L)->nilnode);
+ } else { /* Otherwise separately allocate the array part. */
+ t = lj_mem_newobj(L, GCtab);
+ t->gct = ~LJ_TTAB;
+ t->nomm = (uint8_t)~0;
+ t->colo = 0;
+ setmref(t->array, NULL);
+ setgcrefnull(t->metatable);
+ t->asize = 0; /* In case the array allocation fails. */
+ t->hmask = 0;
+ setmref(t->node, &G(L)->nilnode);
+ if (asize > 0) {
+ if (asize > LJ_MAX_ASIZE)
+ lj_err_msg(L, LJ_ERR_TABOV);
+ setmref(t->array, lj_mem_newvec(L, asize, TValue));
+ t->asize = asize;
+ }
+ }
+ if (hbits)
+ newhpart(L, t, hbits);
+ return t;
+}
+
+/* Create a new table.
+**
+** IMPORTANT NOTE: The API differs from lua_createtable()!
+**
+** The array size is non-inclusive. E.g. asize=128 creates array slots
+** for 0..127, but not for 128. If you need slots 1..128, pass asize=129
+** (slot 0 is wasted in this case).
+**
+** The hash size is given in hash bits. hbits=0 means no hash part.
+** hbits=1 creates 2 hash slots, hbits=2 creates 4 hash slots and so on.
+*/
+GCtab *lj_tab_new(lua_State *L, uint32_t asize, uint32_t hbits)
+{
+ GCtab *t = newtab(L, asize, hbits);
+ clearapart(t);
+ if (t->hmask > 0) clearhpart(t);
+ return t;
+}
+
+#if LJ_HASJIT
+GCtab * LJ_FASTCALL lj_tab_new1(lua_State *L, uint32_t ahsize)
+{
+ GCtab *t = newtab(L, ahsize & 0xffffff, ahsize >> 24);
+ clearapart(t);
+ if (t->hmask > 0) clearhpart(t);
+ return t;
+}
+#endif
+
+/* Duplicate a table. */
+GCtab * LJ_FASTCALL lj_tab_dup(lua_State *L, const GCtab *kt)
+{
+ GCtab *t;
+ uint32_t asize, hmask;
+ t = newtab(L, kt->asize, kt->hmask > 0 ? lj_fls(kt->hmask)+1 : 0);
+ lua_assert(kt->asize == t->asize && kt->hmask == t->hmask);
+ t->nomm = 0; /* Keys with metamethod names may be present. */
+ asize = kt->asize;
+ if (asize > 0) {
+ TValue *array = tvref(t->array);
+ TValue *karray = tvref(kt->array);
+ if (asize < 64) { /* An inlined loop beats memcpy for < 512 bytes. */
+ uint32_t i;
+ for (i = 0; i < asize; i++)
+ copyTV(L, &array[i], &karray[i]);
+ } else {
+ memcpy(array, karray, asize*sizeof(TValue));
+ }
+ }
+ hmask = kt->hmask;
+ if (hmask > 0) {
+ uint32_t i;
+ Node *node = noderef(t->node);
+ Node *knode = noderef(kt->node);
+ ptrdiff_t d = (char *)node - (char *)knode;
+ setmref(node->freetop, (Node *)((char *)noderef(knode->freetop) + d));
+ for (i = 0; i <= hmask; i++) {
+ Node *kn = &knode[i];
+ Node *n = &node[i];
+ Node *next = nextnode(kn);
+ /* Don't use copyTV here, since it asserts on a copy of a dead key. */
+ n->val = kn->val; n->key = kn->key;
+ setmref(n->next, next == NULL? next : (Node *)((char *)next + d));
+ }
+ }
+ return t;
+}
+
+/* Free a table. */
+void LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t)
+{
+ if (t->hmask > 0)
+ lj_mem_freevec(g, noderef(t->node), t->hmask+1, Node);
+ if (t->asize > 0 && LJ_MAX_COLOSIZE != 0 && t->colo <= 0)
+ lj_mem_freevec(g, tvref(t->array), t->asize, TValue);
+ if (LJ_MAX_COLOSIZE != 0 && t->colo)
+ lj_mem_free(g, t, sizetabcolo((uint32_t)t->colo & 0x7f));
+ else
+ lj_mem_freet(g, t);
+}
+
+/* -- Table resizing ------------------------------------------------------ */
+
+/* Resize a table to fit the new array/hash part sizes. */
+static void resizetab(lua_State *L, GCtab *t, uint32_t asize, uint32_t hbits)
+{
+ Node *oldnode = noderef(t->node);
+ uint32_t oldasize = t->asize;
+ uint32_t oldhmask = t->hmask;
+ if (asize > oldasize) { /* Array part grows? */
+ TValue *array;
+ uint32_t i;
+ if (asize > LJ_MAX_ASIZE)
+ lj_err_msg(L, LJ_ERR_TABOV);
+ if (LJ_MAX_COLOSIZE != 0 && t->colo > 0) {
+ /* A colocated array must be separated and copied. */
+ TValue *oarray = tvref(t->array);
+ array = lj_mem_newvec(L, asize, TValue);
+ t->colo = (int8_t)(t->colo | 0x80); /* Mark as separated (colo < 0). */
+ for (i = 0; i < oldasize; i++)
+ copyTV(L, &array[i], &oarray[i]);
+ } else {
+ array = (TValue *)lj_mem_realloc(L, tvref(t->array),
+ oldasize*sizeof(TValue), asize*sizeof(TValue));
+ }
+ setmref(t->array, array);
+ t->asize = asize;
+ for (i = oldasize; i < asize; i++) /* Clear newly allocated slots. */
+ setnilV(&array[i]);
+ }
+ /* Create new (empty) hash part. */
+ if (hbits) {
+ newhpart(L, t, hbits);
+ clearhpart(t);
+ } else {
+ global_State *g = G(L);
+ setmref(t->node, &g->nilnode);
+ t->hmask = 0;
+ }
+ if (asize < oldasize) { /* Array part shrinks? */
+ TValue *array = tvref(t->array);
+ uint32_t i;
+ t->asize = asize; /* Note: This 'shrinks' even colocated arrays. */
+ for (i = asize; i < oldasize; i++) /* Reinsert old array values. */
+ if (!tvisnil(&array[i]))
+ copyTV(L, lj_tab_setinth(L, t, (int32_t)i), &array[i]);
+ /* Physically shrink only separated arrays. */
+ if (LJ_MAX_COLOSIZE != 0 && t->colo <= 0)
+ setmref(t->array, lj_mem_realloc(L, array,
+ oldasize*sizeof(TValue), asize*sizeof(TValue)));
+ }
+ if (oldhmask > 0) { /* Reinsert pairs from old hash part. */
+ global_State *g;
+ uint32_t i;
+ for (i = 0; i <= oldhmask; i++) {
+ Node *n = &oldnode[i];
+ if (!tvisnil(&n->val))
+ copyTV(L, lj_tab_set(L, t, &n->key), &n->val);
+ }
+ g = G(L);
+ lj_mem_freevec(g, oldnode, oldhmask+1, Node);
+ }
+}
+
+static uint32_t countint(cTValue *key, uint32_t *bins)
+{
+ lua_assert(!tvisint(key));
+ if (tvisnum(key)) {
+ lua_Number nk = numV(key);
+ int32_t k = lj_num2int(nk);
+ if ((uint32_t)k < LJ_MAX_ASIZE && nk == (lua_Number)k) {
+ bins[(k > 2 ? lj_fls((uint32_t)(k-1)) : 0)]++;
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static uint32_t countarray(const GCtab *t, uint32_t *bins)
+{
+ uint32_t na, b, i;
+ if (t->asize == 0) return 0;
+ for (na = i = b = 0; b < LJ_MAX_ABITS; b++) {
+ uint32_t n, top = 2u << b;
+ TValue *array;
+ if (top >= t->asize) {
+ top = t->asize-1;
+ if (i > top)
+ break;
+ }
+ array = tvref(t->array);
+ for (n = 0; i <= top; i++)
+ if (!tvisnil(&array[i]))
+ n++;
+ bins[b] += n;
+ na += n;
+ }
+ return na;
+}
+
+static uint32_t counthash(const GCtab *t, uint32_t *bins, uint32_t *narray)
+{
+ uint32_t total, na, i, hmask = t->hmask;
+ Node *node = noderef(t->node);
+ for (total = na = 0, i = 0; i <= hmask; i++) {
+ Node *n = &node[i];
+ if (!tvisnil(&n->val)) {
+ na += countint(&n->key, bins);
+ total++;
+ }
+ }
+ *narray += na;
+ return total;
+}
+
+static uint32_t bestasize(uint32_t bins[], uint32_t *narray)
+{
+ uint32_t b, sum, na = 0, sz = 0, nn = *narray;
+ for (b = 0, sum = 0; 2*nn > (1u<<b) && sum != nn; b++)
+ if (bins[b] > 0 && 2*(sum += bins[b]) > (1u<<b)) {
+ sz = (2u<<b)+1;
+ na = sum;
+ }
+ *narray = sz;
+ return na;
+}
+
+static void rehashtab(lua_State *L, GCtab *t, cTValue *ek)
+{
+ uint32_t bins[LJ_MAX_ABITS];
+ uint32_t total, asize, na, i;
+ for (i = 0; i < LJ_MAX_ABITS; i++) bins[i] = 0;
+ asize = countarray(t, bins);
+ total = 1 + asize;
+ total += counthash(t, bins, &asize);
+ asize += countint(ek, bins);
+ na = bestasize(bins, &asize);
+ total -= na;
+ resizetab(L, t, asize, hsize2hbits(total));
+}
+
+#if LJ_HASFFI
+void lj_tab_rehash(lua_State *L, GCtab *t)
+{
+ rehashtab(L, t, niltv(L));
+}
+#endif
+
+void lj_tab_reasize(lua_State *L, GCtab *t, uint32_t nasize)
+{
+ resizetab(L, t, nasize+1, t->hmask > 0 ? lj_fls(t->hmask)+1 : 0);
+}
+
+/* -- Table getters ------------------------------------------------------- */
+
+cTValue * LJ_FASTCALL lj_tab_getinth(GCtab *t, int32_t key)
+{
+ TValue k;
+ Node *n;
+ k.n = (lua_Number)key;
+ n = hashnum(t, &k);
+ do {
+ if (tvisnum(&n->key) && n->key.n == k.n)
+ return &n->val;
+ } while ((n = nextnode(n)));
+ return NULL;
+}
+
+cTValue *lj_tab_getstr(GCtab *t, GCstr *key)
+{
+ Node *n = hashstr(t, key);
+ do {
+ if (tvisstr(&n->key) && strV(&n->key) == key)
+ return &n->val;
+ } while ((n = nextnode(n)));
+ return NULL;
+}
+
+cTValue *lj_tab_get(lua_State *L, GCtab *t, cTValue *key)
+{
+ if (tvisstr(key)) {
+ cTValue *tv = lj_tab_getstr(t, strV(key));
+ if (tv)
+ return tv;
+ } else if (tvisint(key)) {
+ cTValue *tv = lj_tab_getint(t, intV(key));
+ if (tv)
+ return tv;
+ } else if (tvisnum(key)) {
+ lua_Number nk = numV(key);
+ int32_t k = lj_num2int(nk);
+ if (nk == (lua_Number)k) {
+ cTValue *tv = lj_tab_getint(t, k);
+ if (tv)
+ return tv;
+ } else {
+ goto genlookup; /* Else use the generic lookup. */
+ }
+ } else if (!tvisnil(key)) {
+ Node *n;
+ genlookup:
+ n = hashkey(t, key);
+ do {
+ if (lj_obj_equal(&n->key, key))
+ return &n->val;
+ } while ((n = nextnode(n)));
+ }
+ return niltv(L);
+}
+
+/* -- Table setters ------------------------------------------------------- */
+
+/* Insert new key. Use Brent's variation to optimize the chain length. */
+TValue *lj_tab_newkey(lua_State *L, GCtab *t, cTValue *key)
+{
+ Node *n = hashkey(t, key);
+ if (!tvisnil(&n->val) || t->hmask == 0) {
+ Node *nodebase = noderef(t->node);
+ Node *collide, *freenode = noderef(nodebase->freetop);
+ lua_assert(freenode >= nodebase && freenode <= nodebase+t->hmask+1);
+ do {
+ if (freenode == nodebase) { /* No free node found? */
+ rehashtab(L, t, key); /* Rehash table. */
+ return lj_tab_set(L, t, key); /* Retry key insertion. */
+ }
+ } while (!tvisnil(&(--freenode)->key));
+ setmref(nodebase->freetop, freenode);
+ lua_assert(freenode != &G(L)->nilnode);
+ collide = hashkey(t, &n->key);
+ if (collide != n) { /* Colliding node not the main node? */
+ while (noderef(collide->next) != n) /* Find predecessor. */
+ collide = nextnode(collide);
+ setmref(collide->next, freenode); /* Relink chain. */
+ /* Copy colliding node into free node and free main node. */
+ freenode->val = n->val;
+ freenode->key = n->key;
+ freenode->next = n->next;
+ setmref(n->next, NULL);
+ setnilV(&n->val);
+ /* Rechain pseudo-resurrected string keys with colliding hashes. */
+ while (nextnode(freenode)) {
+ Node *nn = nextnode(freenode);
+ if (tvisstr(&nn->key) && !tvisnil(&nn->val) &&
+ hashstr(t, strV(&nn->key)) == n) {
+ freenode->next = nn->next;
+ nn->next = n->next;
+ setmref(n->next, nn);
+ /*
+ ** Rechaining a resurrected string key creates a new dilemma:
+ ** Another string key may have originally been resurrected via
+ ** _any_ of the previous nodes as a chain anchor. Including
+ ** a node that had to be moved, which makes them unreachable.
+ ** It's not feasible to check for all previous nodes, so rechain
+ ** any string key that's currently in a non-main positions.
+ */
+ while ((nn = nextnode(freenode))) {
+ if (tvisstr(&nn->key) && !tvisnil(&nn->val)) {
+ Node *mn = hashstr(t, strV(&nn->key));
+ if (mn != freenode) {
+ freenode->next = nn->next;
+ nn->next = mn->next;
+ setmref(mn->next, nn);
+ } else {
+ freenode = nn;
+ }
+ } else {
+ freenode = nn;
+ }
+ }
+ break;
+ } else {
+ freenode = nn;
+ }
+ }
+ } else { /* Otherwise use free node. */
+ setmrefr(freenode->next, n->next); /* Insert into chain. */
+ setmref(n->next, freenode);
+ n = freenode;
+ }
+ }
+ n->key.u64 = key->u64;
+ if (LJ_UNLIKELY(tvismzero(&n->key)))
+ n->key.u64 = 0;
+ lj_gc_anybarriert(L, t);
+ lua_assert(tvisnil(&n->val));
+ return &n->val;
+}
+
+TValue *lj_tab_setinth(lua_State *L, GCtab *t, int32_t key)
+{
+ TValue k;
+ Node *n;
+ k.n = (lua_Number)key;
+ n = hashnum(t, &k);
+ do {
+ if (tvisnum(&n->key) && n->key.n == k.n)
+ return &n->val;
+ } while ((n = nextnode(n)));
+ return lj_tab_newkey(L, t, &k);
+}
+
+TValue *lj_tab_setstr(lua_State *L, GCtab *t, GCstr *key)
+{
+ TValue k;
+ Node *n = hashstr(t, key);
+ do {
+ if (tvisstr(&n->key) && strV(&n->key) == key)
+ return &n->val;
+ } while ((n = nextnode(n)));
+ setstrV(L, &k, key);
+ return lj_tab_newkey(L, t, &k);
+}
+
+TValue *lj_tab_set(lua_State *L, GCtab *t, cTValue *key)
+{
+ Node *n;
+ t->nomm = 0; /* Invalidate negative metamethod cache. */
+ if (tvisstr(key)) {
+ return lj_tab_setstr(L, t, strV(key));
+ } else if (tvisint(key)) {
+ return lj_tab_setint(L, t, intV(key));
+ } else if (tvisnum(key)) {
+ lua_Number nk = numV(key);
+ int32_t k = lj_num2int(nk);
+ if (nk == (lua_Number)k)
+ return lj_tab_setint(L, t, k);
+ if (tvisnan(key))
+ lj_err_msg(L, LJ_ERR_NANIDX);
+ /* Else use the generic lookup. */
+ } else if (tvisnil(key)) {
+ lj_err_msg(L, LJ_ERR_NILIDX);
+ }
+ n = hashkey(t, key);
+ do {
+ if (lj_obj_equal(&n->key, key))
+ return &n->val;
+ } while ((n = nextnode(n)));
+ return lj_tab_newkey(L, t, key);
+}
+
+/* -- Table traversal ----------------------------------------------------- */
+
+/* Get the traversal index of a key. */
+static uint32_t keyindex(lua_State *L, GCtab *t, cTValue *key)
+{
+ TValue tmp;
+ if (tvisint(key)) {
+ int32_t k = intV(key);
+ if ((uint32_t)k < t->asize)
+ return (uint32_t)k; /* Array key indexes: [0..t->asize-1] */
+ setnumV(&tmp, (lua_Number)k);
+ key = &tmp;
+ } else if (tvisnum(key)) {
+ lua_Number nk = numV(key);
+ int32_t k = lj_num2int(nk);
+ if ((uint32_t)k < t->asize && nk == (lua_Number)k)
+ return (uint32_t)k; /* Array key indexes: [0..t->asize-1] */
+ }
+ if (!tvisnil(key)) {
+ Node *n = hashkey(t, key);
+ do {
+ if (lj_obj_equal(&n->key, key))
+ return t->asize + (uint32_t)(n - noderef(t->node));
+ /* Hash key indexes: [t->asize..t->asize+t->nmask] */
+ } while ((n = nextnode(n)));
+ if (key->u32.hi == 0xfffe7fff) /* ITERN was despecialized while running. */
+ return key->u32.lo - 1;
+ lj_err_msg(L, LJ_ERR_NEXTIDX);
+ return 0; /* unreachable */
+ }
+ return ~0u; /* A nil key starts the traversal. */
+}
+
+/* Advance to the next step in a table traversal. */
+int lj_tab_next(lua_State *L, GCtab *t, TValue *key)
+{
+ uint32_t i = keyindex(L, t, key); /* Find predecessor key index. */
+ for (i++; i < t->asize; i++) /* First traverse the array keys. */
+ if (!tvisnil(arrayslot(t, i))) {
+ setintV(key, i);
+ copyTV(L, key+1, arrayslot(t, i));
+ return 1;
+ }
+ for (i -= t->asize; i <= t->hmask; i++) { /* Then traverse the hash keys. */
+ Node *n = &noderef(t->node)[i];
+ if (!tvisnil(&n->val)) {
+ copyTV(L, key, &n->key);
+ copyTV(L, key+1, &n->val);
+ return 1;
+ }
+ }
+ return 0; /* End of traversal. */
+}
+
+/* -- Table length calculation -------------------------------------------- */
+
+static MSize unbound_search(GCtab *t, MSize j)
+{
+ cTValue *tv;
+ MSize i = j; /* i is zero or a present index */
+ j++;
+ /* find `i' and `j' such that i is present and j is not */
+ while ((tv = lj_tab_getint(t, (int32_t)j)) && !tvisnil(tv)) {
+ i = j;
+ j *= 2;
+ if (j > (MSize)(INT_MAX-2)) { /* overflow? */
+ /* table was built with bad purposes: resort to linear search */
+ i = 1;
+ while ((tv = lj_tab_getint(t, (int32_t)i)) && !tvisnil(tv)) i++;
+ return i - 1;
+ }
+ }
+ /* now do a binary search between them */
+ while (j - i > 1) {
+ MSize m = (i+j)/2;
+ cTValue *tvb = lj_tab_getint(t, (int32_t)m);
+ if (tvb && !tvisnil(tvb)) i = m; else j = m;
+ }
+ return i;
+}
+
+/*
+** Try to find a boundary in table `t'. A `boundary' is an integer index
+** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).
+*/
+MSize LJ_FASTCALL lj_tab_len(GCtab *t)
+{
+ MSize j = (MSize)t->asize;
+ if (j > 1 && tvisnil(arrayslot(t, j-1))) {
+ MSize i = 1;
+ while (j - i > 1) {
+ MSize m = (i+j)/2;
+ if (tvisnil(arrayslot(t, m-1))) j = m; else i = m;
+ }
+ return i-1;
+ }
+ if (j) j--;
+ if (t->hmask <= 0)
+ return j;
+ return unbound_search(t, j);
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_tab.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_tab.h
new file mode 100644
index 0000000..36ce7cd
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_tab.h
@@ -0,0 +1,70 @@
+/*
+** Table handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_TAB_H
+#define _LJ_TAB_H
+
+#include "lj_obj.h"
+
+/* Hash constants. Tuned using a brute force search. */
+#define HASH_BIAS (-0x04c11db7)
+#define HASH_ROT1 14
+#define HASH_ROT2 5
+#define HASH_ROT3 13
+
+/* Scramble the bits of numbers and pointers. */
+static LJ_AINLINE uint32_t hashrot(uint32_t lo, uint32_t hi)
+{
+#if LJ_TARGET_X86ORX64
+ /* Prefer variant that compiles well for a 2-operand CPU. */
+ lo ^= hi; hi = lj_rol(hi, HASH_ROT1);
+ lo -= hi; hi = lj_rol(hi, HASH_ROT2);
+ hi ^= lo; hi -= lj_rol(lo, HASH_ROT3);
+#else
+ lo ^= hi;
+ lo = lo - lj_rol(hi, HASH_ROT1);
+ hi = lo ^ lj_rol(hi, HASH_ROT1 + HASH_ROT2);
+ hi = hi - lj_rol(lo, HASH_ROT3);
+#endif
+ return hi;
+}
+
+#define hsize2hbits(s) ((s) ? ((s)==1 ? 1 : 1+lj_fls((uint32_t)((s)-1))) : 0)
+
+LJ_FUNCA GCtab *lj_tab_new(lua_State *L, uint32_t asize, uint32_t hbits);
+#if LJ_HASJIT
+LJ_FUNC GCtab * LJ_FASTCALL lj_tab_new1(lua_State *L, uint32_t ahsize);
+#endif
+LJ_FUNCA GCtab * LJ_FASTCALL lj_tab_dup(lua_State *L, const GCtab *kt);
+LJ_FUNC void LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t);
+#if LJ_HASFFI
+LJ_FUNC void lj_tab_rehash(lua_State *L, GCtab *t);
+#endif
+LJ_FUNCA void lj_tab_reasize(lua_State *L, GCtab *t, uint32_t nasize);
+
+/* Caveat: all getters except lj_tab_get() can return NULL! */
+
+LJ_FUNCA cTValue * LJ_FASTCALL lj_tab_getinth(GCtab *t, int32_t key);
+LJ_FUNC cTValue *lj_tab_getstr(GCtab *t, GCstr *key);
+LJ_FUNCA cTValue *lj_tab_get(lua_State *L, GCtab *t, cTValue *key);
+
+/* Caveat: all setters require a write barrier for the stored value. */
+
+LJ_FUNCA TValue *lj_tab_newkey(lua_State *L, GCtab *t, cTValue *key);
+LJ_FUNC TValue *lj_tab_setinth(lua_State *L, GCtab *t, int32_t key);
+LJ_FUNC TValue *lj_tab_setstr(lua_State *L, GCtab *t, GCstr *key);
+LJ_FUNC TValue *lj_tab_set(lua_State *L, GCtab *t, cTValue *key);
+
+#define inarray(t, key) ((MSize)(key) < (MSize)(t)->asize)
+#define arrayslot(t, i) (&tvref((t)->array)[(i)])
+#define lj_tab_getint(t, key) \
+ (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_getinth((t), (key)))
+#define lj_tab_setint(L, t, key) \
+ (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_setinth(L, (t), (key)))
+
+LJ_FUNCA int lj_tab_next(lua_State *L, GCtab *t, TValue *key);
+LJ_FUNCA MSize LJ_FASTCALL lj_tab_len(GCtab *t);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_target.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_target.h
new file mode 100644
index 0000000..53bfa6b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_target.h
@@ -0,0 +1,162 @@
+/*
+** Definitions for target CPU.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_TARGET_H
+#define _LJ_TARGET_H
+
+#include "lj_def.h"
+#include "lj_arch.h"
+
+/* -- Registers and spill slots ------------------------------------------- */
+
+/* Register type (uint8_t in ir->r). */
+typedef uint32_t Reg;
+
+/* The hi-bit is NOT set for an allocated register. This means the value
+** can be directly used without masking. The hi-bit is set for a register
+** allocation hint or for RID_INIT, RID_SINK or RID_SUNK.
+*/
+#define RID_NONE 0x80
+#define RID_MASK 0x7f
+#define RID_INIT (RID_NONE|RID_MASK)
+#define RID_SINK (RID_INIT-1)
+#define RID_SUNK (RID_INIT-2)
+
+#define ra_noreg(r) ((r) & RID_NONE)
+#define ra_hasreg(r) (!((r) & RID_NONE))
+
+/* The ra_hashint() macro assumes a previous test for ra_noreg(). */
+#define ra_hashint(r) ((r) < RID_SUNK)
+#define ra_gethint(r) ((Reg)((r) & RID_MASK))
+#define ra_sethint(rr, r) rr = (uint8_t)((r)|RID_NONE)
+#define ra_samehint(r1, r2) (ra_gethint((r1)^(r2)) == 0)
+
+/* Spill slot 0 means no spill slot has been allocated. */
+#define SPS_NONE 0
+
+#define ra_hasspill(s) ((s) != SPS_NONE)
+
+/* Combined register and spill slot (uint16_t in ir->prev). */
+typedef uint32_t RegSP;
+
+#define REGSP(r, s) ((r) + ((s) << 8))
+#define REGSP_HINT(r) ((r)|RID_NONE)
+#define REGSP_INIT REGSP(RID_INIT, 0)
+
+#define regsp_reg(rs) ((rs) & 255)
+#define regsp_spill(rs) ((rs) >> 8)
+#define regsp_used(rs) \
+ (((rs) & ~REGSP(RID_MASK, 0)) != REGSP(RID_NONE, 0))
+
+/* -- Register sets ------------------------------------------------------- */
+
+/* Bitset for registers. 32 registers suffice for most architectures.
+** Note that one set holds bits for both GPRs and FPRs.
+*/
+#if LJ_TARGET_PPC || LJ_TARGET_MIPS
+typedef uint64_t RegSet;
+#else
+typedef uint32_t RegSet;
+#endif
+
+#define RID2RSET(r) (((RegSet)1) << (r))
+#define RSET_EMPTY ((RegSet)0)
+#define RSET_RANGE(lo, hi) ((RID2RSET((hi)-(lo))-1) << (lo))
+
+#define rset_test(rs, r) ((int)((rs) >> (r)) & 1)
+#define rset_set(rs, r) (rs |= RID2RSET(r))
+#define rset_clear(rs, r) (rs &= ~RID2RSET(r))
+#define rset_exclude(rs, r) (rs & ~RID2RSET(r))
+#if LJ_TARGET_PPC || LJ_TARGET_MIPS
+#define rset_picktop(rs) ((Reg)(__builtin_clzll(rs)^63))
+#define rset_pickbot(rs) ((Reg)__builtin_ctzll(rs))
+#else
+#define rset_picktop(rs) ((Reg)lj_fls(rs))
+#define rset_pickbot(rs) ((Reg)lj_ffs(rs))
+#endif
+
+/* -- Register allocation cost -------------------------------------------- */
+
+/* The register allocation heuristic keeps track of the cost for allocating
+** a specific register:
+**
+** A free register (obviously) has a cost of 0 and a 1-bit in the free mask.
+**
+** An already allocated register has the (non-zero) IR reference in the lowest
+** bits and the result of a blended cost-model in the higher bits.
+**
+** The allocator first checks the free mask for a hit. Otherwise an (unrolled)
+** linear search for the minimum cost is used. The search doesn't need to
+** keep track of the position of the minimum, which makes it very fast.
+** The lowest bits of the minimum cost show the desired IR reference whose
+** register is the one to evict.
+**
+** Without the cost-model this degenerates to the standard heuristics for
+** (reverse) linear-scan register allocation. Since code generation is done
+** in reverse, a live interval extends from the last use to the first def.
+** For an SSA IR the IR reference is the first (and only) def and thus
+** trivially marks the end of the interval. The LSRA heuristics says to pick
+** the register whose live interval has the furthest extent, i.e. the lowest
+** IR reference in our case.
+**
+** A cost-model should take into account other factors, like spill-cost and
+** restore- or rematerialization-cost, which depend on the kind of instruction.
+** E.g. constants have zero spill costs, variant instructions have higher
+** costs than invariants and PHIs should preferably never be spilled.
+**
+** Here's a first cut at simple, but effective blended cost-model for R-LSRA:
+** - Due to careful design of the IR, constants already have lower IR
+** references than invariants and invariants have lower IR references
+** than variants.
+** - The cost in the upper 16 bits is the sum of the IR reference and a
+** weighted score. The score currently only takes into account whether
+** the IRT_ISPHI bit is set in the instruction type.
+** - The PHI weight is the minimum distance (in IR instructions) a PHI
+** reference has to be further apart from a non-PHI reference to be spilled.
+** - It should be a power of two (for speed) and must be between 2 and 32768.
+** Good values for the PHI weight seem to be between 40 and 150.
+** - Further study is required.
+*/
+#define REGCOST_PHI_WEIGHT 64
+
+/* Cost for allocating a specific register. */
+typedef uint32_t RegCost;
+
+/* Note: assumes 16 bit IRRef1. */
+#define REGCOST(cost, ref) ((RegCost)(ref) + ((RegCost)(cost) << 16))
+#define regcost_ref(rc) ((IRRef1)(rc))
+
+#define REGCOST_T(t) \
+ ((RegCost)((t)&IRT_ISPHI) * (((RegCost)(REGCOST_PHI_WEIGHT)<<16)/IRT_ISPHI))
+#define REGCOST_REF_T(ref, t) (REGCOST((ref), (ref)) + REGCOST_T((t)))
+
+/* -- Target-specific definitions ----------------------------------------- */
+
+#if LJ_TARGET_X86ORX64
+#include "lj_target_x86.h"
+#elif LJ_TARGET_ARM
+#include "lj_target_arm.h"
+#elif LJ_TARGET_PPC
+#include "lj_target_ppc.h"
+#elif LJ_TARGET_MIPS
+#include "lj_target_mips.h"
+#else
+#error "Missing include for target CPU"
+#endif
+
+#ifdef EXITSTUBS_PER_GROUP
+/* Return the address of an exit stub. */
+static LJ_AINLINE char *exitstub_addr_(char **group, uint32_t exitno)
+{
+ lua_assert(group[exitno / EXITSTUBS_PER_GROUP] != NULL);
+ return (char *)group[exitno / EXITSTUBS_PER_GROUP] +
+ EXITSTUB_SPACING*(exitno % EXITSTUBS_PER_GROUP);
+}
+/* Avoid dependence on lj_jit.h if only including lj_target.h. */
+#define exitstub_addr(J, exitno) \
+ ((MCode *)exitstub_addr_((char **)((J)->exitstubgroup), (exitno)))
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_target_arm.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_target_arm.h
new file mode 100644
index 0000000..d02cbf8
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_target_arm.h
@@ -0,0 +1,274 @@
+/*
+** Definitions for ARM CPUs.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_TARGET_ARM_H
+#define _LJ_TARGET_ARM_H
+
+/* -- Registers IDs ------------------------------------------------------- */
+
+#define GPRDEF(_) \
+ _(R0) _(R1) _(R2) _(R3) _(R4) _(R5) _(R6) _(R7) \
+ _(R8) _(R9) _(R10) _(R11) _(R12) _(SP) _(LR) _(PC)
+#if LJ_SOFTFP
+#define FPRDEF(_)
+#else
+#define FPRDEF(_) \
+ _(D0) _(D1) _(D2) _(D3) _(D4) _(D5) _(D6) _(D7) \
+ _(D8) _(D9) _(D10) _(D11) _(D12) _(D13) _(D14) _(D15)
+#endif
+#define VRIDDEF(_)
+
+#define RIDENUM(name) RID_##name,
+
+enum {
+ GPRDEF(RIDENUM) /* General-purpose registers (GPRs). */
+ FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */
+ RID_MAX,
+ RID_TMP = RID_LR,
+
+ /* Calling conventions. */
+ RID_RET = RID_R0,
+ RID_RETLO = RID_R0,
+ RID_RETHI = RID_R1,
+#if LJ_SOFTFP
+ RID_FPRET = RID_R0,
+#else
+ RID_FPRET = RID_D0,
+#endif
+
+ /* These definitions must match with the *.dasc file(s): */
+ RID_BASE = RID_R9, /* Interpreter BASE. */
+ RID_LPC = RID_R6, /* Interpreter PC. */
+ RID_DISPATCH = RID_R7, /* Interpreter DISPATCH table. */
+ RID_LREG = RID_R8, /* Interpreter L. */
+
+ /* Register ranges [min, max) and number of registers. */
+ RID_MIN_GPR = RID_R0,
+ RID_MAX_GPR = RID_PC+1,
+ RID_MIN_FPR = RID_MAX_GPR,
+#if LJ_SOFTFP
+ RID_MAX_FPR = RID_MIN_FPR,
+#else
+ RID_MAX_FPR = RID_D15+1,
+#endif
+ RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,
+ RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR
+};
+
+#define RID_NUM_KREF RID_NUM_GPR
+#define RID_MIN_KREF RID_R0
+
+/* -- Register sets ------------------------------------------------------- */
+
+/* Make use of all registers, except sp, lr and pc. */
+#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_R12+1))
+#define RSET_GPREVEN \
+ (RID2RSET(RID_R0)|RID2RSET(RID_R2)|RID2RSET(RID_R4)|RID2RSET(RID_R6)| \
+ RID2RSET(RID_R8)|RID2RSET(RID_R10))
+#define RSET_GPRODD \
+ (RID2RSET(RID_R1)|RID2RSET(RID_R3)|RID2RSET(RID_R5)|RID2RSET(RID_R7)| \
+ RID2RSET(RID_R9)|RID2RSET(RID_R11))
+#if LJ_SOFTFP
+#define RSET_FPR 0
+#else
+#define RSET_FPR (RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR))
+#endif
+#define RSET_ALL (RSET_GPR|RSET_FPR)
+#define RSET_INIT RSET_ALL
+
+/* ABI-specific register sets. lr is an implicit scratch register. */
+#define RSET_SCRATCH_GPR_ (RSET_RANGE(RID_R0, RID_R3+1)|RID2RSET(RID_R12))
+#ifdef __APPLE__
+#define RSET_SCRATCH_GPR (RSET_SCRATCH_GPR_|RID2RSET(RID_R9))
+#else
+#define RSET_SCRATCH_GPR RSET_SCRATCH_GPR_
+#endif
+#if LJ_SOFTFP
+#define RSET_SCRATCH_FPR 0
+#else
+#define RSET_SCRATCH_FPR (RSET_RANGE(RID_D0, RID_D7+1))
+#endif
+#define RSET_SCRATCH (RSET_SCRATCH_GPR|RSET_SCRATCH_FPR)
+#define REGARG_FIRSTGPR RID_R0
+#define REGARG_LASTGPR RID_R3
+#define REGARG_NUMGPR 4
+#if LJ_ABI_SOFTFP
+#define REGARG_FIRSTFPR 0
+#define REGARG_LASTFPR 0
+#define REGARG_NUMFPR 0
+#else
+#define REGARG_FIRSTFPR RID_D0
+#define REGARG_LASTFPR RID_D7
+#define REGARG_NUMFPR 8
+#endif
+
+/* -- Spill slots --------------------------------------------------------- */
+
+/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.
+**
+** SPS_FIXED: Available fixed spill slots in interpreter frame.
+** This definition must match with the *.dasc file(s).
+**
+** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots.
+*/
+#define SPS_FIXED 2
+#define SPS_FIRST 2
+
+#define SPOFS_TMP 0
+
+#define sps_scale(slot) (4 * (int32_t)(slot))
+#define sps_align(slot) (((slot) - SPS_FIXED + 1) & ~1)
+
+/* -- Exit state ---------------------------------------------------------- */
+
+/* This definition must match with the *.dasc file(s). */
+typedef struct {
+#if !LJ_SOFTFP
+ lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */
+#endif
+ int32_t gpr[RID_NUM_GPR]; /* General-purpose registers. */
+ int32_t spill[256]; /* Spill slots. */
+} ExitState;
+
+/* PC after instruction that caused an exit. Used to find the trace number. */
+#define EXITSTATE_PCREG RID_PC
+/* Highest exit + 1 indicates stack check. */
+#define EXITSTATE_CHECKEXIT 1
+
+#define EXITSTUB_SPACING 4
+#define EXITSTUBS_PER_GROUP 32
+
+/* -- Instructions -------------------------------------------------------- */
+
+/* Instruction fields. */
+#define ARMF_CC(ai, cc) (((ai) ^ ARMI_CCAL) | ((cc) << 28))
+#define ARMF_N(r) ((r) << 16)
+#define ARMF_D(r) ((r) << 12)
+#define ARMF_S(r) ((r) << 8)
+#define ARMF_M(r) (r)
+#define ARMF_SH(sh, n) (((sh) << 5) | ((n) << 7))
+#define ARMF_RSH(sh, r) (0x10 | ((sh) << 5) | ARMF_S(r))
+
+typedef enum ARMIns {
+ ARMI_CCAL = 0xe0000000,
+ ARMI_S = 0x000100000,
+ ARMI_K12 = 0x02000000,
+ ARMI_KNEG = 0x00200000,
+ ARMI_LS_W = 0x00200000,
+ ARMI_LS_U = 0x00800000,
+ ARMI_LS_P = 0x01000000,
+ ARMI_LS_R = 0x02000000,
+ ARMI_LSX_I = 0x00400000,
+
+ ARMI_AND = 0xe0000000,
+ ARMI_EOR = 0xe0200000,
+ ARMI_SUB = 0xe0400000,
+ ARMI_RSB = 0xe0600000,
+ ARMI_ADD = 0xe0800000,
+ ARMI_ADC = 0xe0a00000,
+ ARMI_SBC = 0xe0c00000,
+ ARMI_RSC = 0xe0e00000,
+ ARMI_TST = 0xe1100000,
+ ARMI_TEQ = 0xe1300000,
+ ARMI_CMP = 0xe1500000,
+ ARMI_CMN = 0xe1700000,
+ ARMI_ORR = 0xe1800000,
+ ARMI_MOV = 0xe1a00000,
+ ARMI_BIC = 0xe1c00000,
+ ARMI_MVN = 0xe1e00000,
+
+ ARMI_NOP = 0xe1a00000,
+
+ ARMI_MUL = 0xe0000090,
+ ARMI_SMULL = 0xe0c00090,
+
+ ARMI_LDR = 0xe4100000,
+ ARMI_LDRB = 0xe4500000,
+ ARMI_LDRH = 0xe01000b0,
+ ARMI_LDRSB = 0xe01000d0,
+ ARMI_LDRSH = 0xe01000f0,
+ ARMI_LDRD = 0xe00000d0,
+ ARMI_STR = 0xe4000000,
+ ARMI_STRB = 0xe4400000,
+ ARMI_STRH = 0xe00000b0,
+ ARMI_STRD = 0xe00000f0,
+ ARMI_PUSH = 0xe92d0000,
+
+ ARMI_B = 0xea000000,
+ ARMI_BL = 0xeb000000,
+ ARMI_BLX = 0xfa000000,
+ ARMI_BLXr = 0xe12fff30,
+
+ /* ARMv6 */
+ ARMI_REV = 0xe6bf0f30,
+ ARMI_SXTB = 0xe6af0070,
+ ARMI_SXTH = 0xe6bf0070,
+ ARMI_UXTB = 0xe6ef0070,
+ ARMI_UXTH = 0xe6ff0070,
+
+ /* ARMv6T2 */
+ ARMI_MOVW = 0xe3000000,
+ ARMI_MOVT = 0xe3400000,
+
+ /* VFP */
+ ARMI_VMOV_D = 0xeeb00b40,
+ ARMI_VMOV_S = 0xeeb00a40,
+ ARMI_VMOVI_D = 0xeeb00b00,
+
+ ARMI_VMOV_R_S = 0xee100a10,
+ ARMI_VMOV_S_R = 0xee000a10,
+ ARMI_VMOV_RR_D = 0xec500b10,
+ ARMI_VMOV_D_RR = 0xec400b10,
+
+ ARMI_VADD_D = 0xee300b00,
+ ARMI_VSUB_D = 0xee300b40,
+ ARMI_VMUL_D = 0xee200b00,
+ ARMI_VMLA_D = 0xee000b00,
+ ARMI_VMLS_D = 0xee000b40,
+ ARMI_VNMLS_D = 0xee100b00,
+ ARMI_VDIV_D = 0xee800b00,
+
+ ARMI_VABS_D = 0xeeb00bc0,
+ ARMI_VNEG_D = 0xeeb10b40,
+ ARMI_VSQRT_D = 0xeeb10bc0,
+
+ ARMI_VCMP_D = 0xeeb40b40,
+ ARMI_VCMPZ_D = 0xeeb50b40,
+
+ ARMI_VMRS = 0xeef1fa10,
+
+ ARMI_VCVT_S32_F32 = 0xeebd0ac0,
+ ARMI_VCVT_S32_F64 = 0xeebd0bc0,
+ ARMI_VCVT_U32_F32 = 0xeebc0ac0,
+ ARMI_VCVT_U32_F64 = 0xeebc0bc0,
+ ARMI_VCVTR_S32_F32 = 0xeebd0a40,
+ ARMI_VCVTR_S32_F64 = 0xeebd0b40,
+ ARMI_VCVTR_U32_F32 = 0xeebc0a40,
+ ARMI_VCVTR_U32_F64 = 0xeebc0b40,
+ ARMI_VCVT_F32_S32 = 0xeeb80ac0,
+ ARMI_VCVT_F64_S32 = 0xeeb80bc0,
+ ARMI_VCVT_F32_U32 = 0xeeb80a40,
+ ARMI_VCVT_F64_U32 = 0xeeb80b40,
+ ARMI_VCVT_F32_F64 = 0xeeb70bc0,
+ ARMI_VCVT_F64_F32 = 0xeeb70ac0,
+
+ ARMI_VLDR_S = 0xed100a00,
+ ARMI_VLDR_D = 0xed100b00,
+ ARMI_VSTR_S = 0xed000a00,
+ ARMI_VSTR_D = 0xed000b00,
+} ARMIns;
+
+typedef enum ARMShift {
+ ARMSH_LSL, ARMSH_LSR, ARMSH_ASR, ARMSH_ROR
+} ARMShift;
+
+/* ARM condition codes. */
+typedef enum ARMCC {
+ CC_EQ, CC_NE, CC_CS, CC_CC, CC_MI, CC_PL, CC_VS, CC_VC,
+ CC_HI, CC_LS, CC_GE, CC_LT, CC_GT, CC_LE, CC_AL,
+ CC_HS = CC_CS, CC_LO = CC_CC
+} ARMCC;
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_target_mips.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_target_mips.h
new file mode 100644
index 0000000..bed174b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_target_mips.h
@@ -0,0 +1,258 @@
+/*
+** Definitions for MIPS CPUs.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_TARGET_MIPS_H
+#define _LJ_TARGET_MIPS_H
+
+/* -- Registers IDs ------------------------------------------------------- */
+
+#define GPRDEF(_) \
+ _(R0) _(R1) _(R2) _(R3) _(R4) _(R5) _(R6) _(R7) \
+ _(R8) _(R9) _(R10) _(R11) _(R12) _(R13) _(R14) _(R15) \
+ _(R16) _(R17) _(R18) _(R19) _(R20) _(R21) _(R22) _(R23) \
+ _(R24) _(R25) _(SYS1) _(SYS2) _(R28) _(SP) _(R30) _(RA)
+#define FPRDEF(_) \
+ _(F0) _(F1) _(F2) _(F3) _(F4) _(F5) _(F6) _(F7) \
+ _(F8) _(F9) _(F10) _(F11) _(F12) _(F13) _(F14) _(F15) \
+ _(F16) _(F17) _(F18) _(F19) _(F20) _(F21) _(F22) _(F23) \
+ _(F24) _(F25) _(F26) _(F27) _(F28) _(F29) _(F30) _(F31)
+#define VRIDDEF(_)
+
+#define RIDENUM(name) RID_##name,
+
+enum {
+ GPRDEF(RIDENUM) /* General-purpose registers (GPRs). */
+ FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */
+ RID_MAX,
+ RID_ZERO = RID_R0,
+ RID_TMP = RID_RA,
+ RID_GP = RID_R28,
+
+ /* Calling conventions. */
+ RID_RET = RID_R2,
+#if LJ_LE
+ RID_RETHI = RID_R3,
+ RID_RETLO = RID_R2,
+#else
+ RID_RETHI = RID_R2,
+ RID_RETLO = RID_R3,
+#endif
+ RID_FPRET = RID_F0,
+ RID_CFUNCADDR = RID_R25,
+
+ /* These definitions must match with the *.dasc file(s): */
+ RID_BASE = RID_R16, /* Interpreter BASE. */
+ RID_LPC = RID_R18, /* Interpreter PC. */
+ RID_DISPATCH = RID_R19, /* Interpreter DISPATCH table. */
+ RID_LREG = RID_R20, /* Interpreter L. */
+ RID_JGL = RID_R30, /* On-trace: global_State + 32768. */
+
+ /* Register ranges [min, max) and number of registers. */
+ RID_MIN_GPR = RID_R0,
+ RID_MAX_GPR = RID_RA+1,
+ RID_MIN_FPR = RID_F0,
+ RID_MAX_FPR = RID_F31+1,
+ RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,
+ RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR /* Only even regs are used. */
+};
+
+#define RID_NUM_KREF RID_NUM_GPR
+#define RID_MIN_KREF RID_R0
+
+/* -- Register sets ------------------------------------------------------- */
+
+/* Make use of all registers, except ZERO, TMP, SP, SYS1, SYS2, JGL and GP. */
+#define RSET_FIXED \
+ (RID2RSET(RID_ZERO)|RID2RSET(RID_TMP)|RID2RSET(RID_SP)|\
+ RID2RSET(RID_SYS1)|RID2RSET(RID_SYS2)|RID2RSET(RID_JGL)|RID2RSET(RID_GP))
+#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) - RSET_FIXED)
+#define RSET_FPR \
+ (RID2RSET(RID_F0)|RID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(RID_F6)|\
+ RID2RSET(RID_F8)|RID2RSET(RID_F10)|RID2RSET(RID_F12)|RID2RSET(RID_F14)|\
+ RID2RSET(RID_F16)|RID2RSET(RID_F18)|RID2RSET(RID_F20)|RID2RSET(RID_F22)|\
+ RID2RSET(RID_F24)|RID2RSET(RID_F26)|RID2RSET(RID_F28)|RID2RSET(RID_F30))
+#define RSET_ALL (RSET_GPR|RSET_FPR)
+#define RSET_INIT RSET_ALL
+
+#define RSET_SCRATCH_GPR \
+ (RSET_RANGE(RID_R1, RID_R15+1)|\
+ RID2RSET(RID_R24)|RID2RSET(RID_R25))
+#define RSET_SCRATCH_FPR \
+ (RID2RSET(RID_F0)|RID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(RID_F6)|\
+ RID2RSET(RID_F8)|RID2RSET(RID_F10)|RID2RSET(RID_F12)|RID2RSET(RID_F14)|\
+ RID2RSET(RID_F16)|RID2RSET(RID_F18))
+#define RSET_SCRATCH (RSET_SCRATCH_GPR|RSET_SCRATCH_FPR)
+#define REGARG_FIRSTGPR RID_R4
+#define REGARG_LASTGPR RID_R7
+#define REGARG_NUMGPR 4
+#define REGARG_FIRSTFPR RID_F12
+#define REGARG_LASTFPR RID_F14
+#define REGARG_NUMFPR 2
+
+/* -- Spill slots --------------------------------------------------------- */
+
+/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.
+**
+** SPS_FIXED: Available fixed spill slots in interpreter frame.
+** This definition must match with the *.dasc file(s).
+**
+** SPS_FIRST: First spill slot for general use.
+*/
+#define SPS_FIXED 5
+#define SPS_FIRST 4
+
+#define SPOFS_TMP 0
+
+#define sps_scale(slot) (4 * (int32_t)(slot))
+#define sps_align(slot) (((slot) - SPS_FIXED + 1) & ~1)
+
+/* -- Exit state ---------------------------------------------------------- */
+
+/* This definition must match with the *.dasc file(s). */
+typedef struct {
+ lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */
+ int32_t gpr[RID_NUM_GPR]; /* General-purpose registers. */
+ int32_t spill[256]; /* Spill slots. */
+} ExitState;
+
+/* Highest exit + 1 indicates stack check. */
+#define EXITSTATE_CHECKEXIT 1
+
+/* Return the address of a per-trace exit stub. */
+static LJ_AINLINE uint32_t *exitstub_trace_addr_(uint32_t *p)
+{
+ while (*p == 0x00000000) p++; /* Skip MIPSI_NOP. */
+ return p;
+}
+/* Avoid dependence on lj_jit.h if only including lj_target.h. */
+#define exitstub_trace_addr(T, exitno) \
+ exitstub_trace_addr_((MCode *)((char *)(T)->mcode + (T)->szmcode))
+
+/* -- Instructions -------------------------------------------------------- */
+
+/* Instruction fields. */
+#define MIPSF_S(r) ((r) << 21)
+#define MIPSF_T(r) ((r) << 16)
+#define MIPSF_D(r) ((r) << 11)
+#define MIPSF_R(r) ((r) << 21)
+#define MIPSF_H(r) ((r) << 16)
+#define MIPSF_G(r) ((r) << 11)
+#define MIPSF_F(r) ((r) << 6)
+#define MIPSF_A(n) ((n) << 6)
+#define MIPSF_M(n) ((n) << 11)
+
+typedef enum MIPSIns {
+ /* Integer instructions. */
+ MIPSI_MOVE = 0x00000021,
+ MIPSI_NOP = 0x00000000,
+
+ MIPSI_LI = 0x24000000,
+ MIPSI_LU = 0x34000000,
+ MIPSI_LUI = 0x3c000000,
+
+ MIPSI_ADDIU = 0x24000000,
+ MIPSI_ANDI = 0x30000000,
+ MIPSI_ORI = 0x34000000,
+ MIPSI_XORI = 0x38000000,
+ MIPSI_SLTI = 0x28000000,
+ MIPSI_SLTIU = 0x2c000000,
+
+ MIPSI_ADDU = 0x00000021,
+ MIPSI_SUBU = 0x00000023,
+ MIPSI_MUL = 0x70000002,
+ MIPSI_AND = 0x00000024,
+ MIPSI_OR = 0x00000025,
+ MIPSI_XOR = 0x00000026,
+ MIPSI_NOR = 0x00000027,
+ MIPSI_SLT = 0x0000002a,
+ MIPSI_SLTU = 0x0000002b,
+ MIPSI_MOVZ = 0x0000000a,
+ MIPSI_MOVN = 0x0000000b,
+
+ MIPSI_SLL = 0x00000000,
+ MIPSI_SRL = 0x00000002,
+ MIPSI_SRA = 0x00000003,
+ MIPSI_ROTR = 0x00200002, /* MIPS32R2 */
+ MIPSI_SLLV = 0x00000004,
+ MIPSI_SRLV = 0x00000006,
+ MIPSI_SRAV = 0x00000007,
+ MIPSI_ROTRV = 0x00000046, /* MIPS32R2 */
+
+ MIPSI_SEB = 0x7c000420, /* MIPS32R2 */
+ MIPSI_SEH = 0x7c000620, /* MIPS32R2 */
+ MIPSI_WSBH = 0x7c0000a0, /* MIPS32R2 */
+
+ MIPSI_B = 0x10000000,
+ MIPSI_J = 0x08000000,
+ MIPSI_JAL = 0x0c000000,
+ MIPSI_JR = 0x00000008,
+ MIPSI_JALR = 0x0000f809,
+
+ MIPSI_BEQ = 0x10000000,
+ MIPSI_BNE = 0x14000000,
+ MIPSI_BLEZ = 0x18000000,
+ MIPSI_BGTZ = 0x1c000000,
+ MIPSI_BLTZ = 0x04000000,
+ MIPSI_BGEZ = 0x04010000,
+
+ /* Load/store instructions. */
+ MIPSI_LW = 0x8c000000,
+ MIPSI_SW = 0xac000000,
+ MIPSI_LB = 0x80000000,
+ MIPSI_SB = 0xa0000000,
+ MIPSI_LH = 0x84000000,
+ MIPSI_SH = 0xa4000000,
+ MIPSI_LBU = 0x90000000,
+ MIPSI_LHU = 0x94000000,
+ MIPSI_LWC1 = 0xc4000000,
+ MIPSI_SWC1 = 0xe4000000,
+ MIPSI_LDC1 = 0xd4000000,
+ MIPSI_SDC1 = 0xf4000000,
+
+ /* FP instructions. */
+ MIPSI_MOV_S = 0x46000006,
+ MIPSI_MOV_D = 0x46200006,
+ MIPSI_MOVT_D = 0x46210011,
+ MIPSI_MOVF_D = 0x46200011,
+
+ MIPSI_ABS_D = 0x46200005,
+ MIPSI_NEG_D = 0x46200007,
+
+ MIPSI_ADD_D = 0x46200000,
+ MIPSI_SUB_D = 0x46200001,
+ MIPSI_MUL_D = 0x46200002,
+ MIPSI_DIV_D = 0x46200003,
+ MIPSI_SQRT_D = 0x46200004,
+
+ MIPSI_ADD_S = 0x46000000,
+ MIPSI_SUB_S = 0x46000001,
+
+ MIPSI_CVT_D_S = 0x46000021,
+ MIPSI_CVT_W_S = 0x46000024,
+ MIPSI_CVT_S_D = 0x46200020,
+ MIPSI_CVT_W_D = 0x46200024,
+ MIPSI_CVT_S_W = 0x46800020,
+ MIPSI_CVT_D_W = 0x46800021,
+
+ MIPSI_TRUNC_W_S = 0x4600000d,
+ MIPSI_TRUNC_W_D = 0x4620000d,
+ MIPSI_FLOOR_W_S = 0x4600000f,
+ MIPSI_FLOOR_W_D = 0x4620000f,
+
+ MIPSI_MFC1 = 0x44000000,
+ MIPSI_MTC1 = 0x44800000,
+
+ MIPSI_BC1F = 0x45000000,
+ MIPSI_BC1T = 0x45010000,
+
+ MIPSI_C_EQ_D = 0x46200032,
+ MIPSI_C_OLT_D = 0x46200034,
+ MIPSI_C_ULT_D = 0x46200035,
+ MIPSI_C_OLE_D = 0x46200036,
+ MIPSI_C_ULE_D = 0x46200037,
+
+} MIPSIns;
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_target_ppc.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_target_ppc.h
new file mode 100644
index 0000000..e57e27d
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_target_ppc.h
@@ -0,0 +1,280 @@
+/*
+** Definitions for PPC CPUs.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_TARGET_PPC_H
+#define _LJ_TARGET_PPC_H
+
+/* -- Registers IDs ------------------------------------------------------- */
+
+#define GPRDEF(_) \
+ _(R0) _(SP) _(SYS1) _(R3) _(R4) _(R5) _(R6) _(R7) \
+ _(R8) _(R9) _(R10) _(R11) _(R12) _(SYS2) _(R14) _(R15) \
+ _(R16) _(R17) _(R18) _(R19) _(R20) _(R21) _(R22) _(R23) \
+ _(R24) _(R25) _(R26) _(R27) _(R28) _(R29) _(R30) _(R31)
+#define FPRDEF(_) \
+ _(F0) _(F1) _(F2) _(F3) _(F4) _(F5) _(F6) _(F7) \
+ _(F8) _(F9) _(F10) _(F11) _(F12) _(F13) _(F14) _(F15) \
+ _(F16) _(F17) _(F18) _(F19) _(F20) _(F21) _(F22) _(F23) \
+ _(F24) _(F25) _(F26) _(F27) _(F28) _(F29) _(F30) _(F31)
+#define VRIDDEF(_)
+
+#define RIDENUM(name) RID_##name,
+
+enum {
+ GPRDEF(RIDENUM) /* General-purpose registers (GPRs). */
+ FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */
+ RID_MAX,
+ RID_TMP = RID_R0,
+
+ /* Calling conventions. */
+ RID_RET = RID_R3,
+ RID_RETHI = RID_R3,
+ RID_RETLO = RID_R4,
+ RID_FPRET = RID_F1,
+
+ /* These definitions must match with the *.dasc file(s): */
+ RID_BASE = RID_R14, /* Interpreter BASE. */
+ RID_LPC = RID_R16, /* Interpreter PC. */
+ RID_DISPATCH = RID_R17, /* Interpreter DISPATCH table. */
+ RID_LREG = RID_R18, /* Interpreter L. */
+ RID_JGL = RID_R31, /* On-trace: global_State + 32768. */
+
+ /* Register ranges [min, max) and number of registers. */
+ RID_MIN_GPR = RID_R0,
+ RID_MAX_GPR = RID_R31+1,
+ RID_MIN_FPR = RID_F0,
+ RID_MAX_FPR = RID_F31+1,
+ RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,
+ RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR
+};
+
+#define RID_NUM_KREF RID_NUM_GPR
+#define RID_MIN_KREF RID_R0
+
+/* -- Register sets ------------------------------------------------------- */
+
+/* Make use of all registers, except TMP, SP, SYS1, SYS2 and JGL. */
+#define RSET_FIXED \
+ (RID2RSET(RID_TMP)|RID2RSET(RID_SP)|RID2RSET(RID_SYS1)|\
+ RID2RSET(RID_SYS2)|RID2RSET(RID_JGL))
+#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) - RSET_FIXED)
+#define RSET_FPR RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR)
+#define RSET_ALL (RSET_GPR|RSET_FPR)
+#define RSET_INIT RSET_ALL
+
+#define RSET_SCRATCH_GPR (RSET_RANGE(RID_R3, RID_R12+1))
+#define RSET_SCRATCH_FPR (RSET_RANGE(RID_F0, RID_F13+1))
+#define RSET_SCRATCH (RSET_SCRATCH_GPR|RSET_SCRATCH_FPR)
+#define REGARG_FIRSTGPR RID_R3
+#define REGARG_LASTGPR RID_R10
+#define REGARG_NUMGPR 8
+#define REGARG_FIRSTFPR RID_F1
+#define REGARG_LASTFPR RID_F8
+#define REGARG_NUMFPR 8
+
+/* -- Spill slots --------------------------------------------------------- */
+
+/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.
+**
+** SPS_FIXED: Available fixed spill slots in interpreter frame.
+** This definition must match with the *.dasc file(s).
+**
+** SPS_FIRST: First spill slot for general use.
+** [sp+12] tmplo word \
+** [sp+ 8] tmphi word / tmp dword, parameter area for callee
+** [sp+ 4] tmpw, LR of callee
+** [sp+ 0] stack chain
+*/
+#define SPS_FIXED 7
+#define SPS_FIRST 4
+
+/* Stack offsets for temporary slots. Used for FP<->int conversions etc. */
+#define SPOFS_TMPW 4
+#define SPOFS_TMP 8
+#define SPOFS_TMPHI 8
+#define SPOFS_TMPLO 12
+
+#define sps_scale(slot) (4 * (int32_t)(slot))
+#define sps_align(slot) (((slot) - SPS_FIXED + 3) & ~3)
+
+/* -- Exit state ---------------------------------------------------------- */
+
+/* This definition must match with the *.dasc file(s). */
+typedef struct {
+ lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */
+ int32_t gpr[RID_NUM_GPR]; /* General-purpose registers. */
+ int32_t spill[256]; /* Spill slots. */
+} ExitState;
+
+/* Highest exit + 1 indicates stack check. */
+#define EXITSTATE_CHECKEXIT 1
+
+/* Return the address of a per-trace exit stub. */
+static LJ_AINLINE uint32_t *exitstub_trace_addr_(uint32_t *p, uint32_t exitno)
+{
+ while (*p == 0x60000000) p++; /* Skip PPCI_NOP. */
+ return p + 3 + exitno;
+}
+/* Avoid dependence on lj_jit.h if only including lj_target.h. */
+#define exitstub_trace_addr(T, exitno) \
+ exitstub_trace_addr_((MCode *)((char *)(T)->mcode + (T)->szmcode), (exitno))
+
+/* -- Instructions -------------------------------------------------------- */
+
+/* Instruction fields. */
+#define PPCF_CC(cc) ((((cc) & 3) << 16) | (((cc) & 4) << 22))
+#define PPCF_T(r) ((r) << 21)
+#define PPCF_A(r) ((r) << 16)
+#define PPCF_B(r) ((r) << 11)
+#define PPCF_C(r) ((r) << 6)
+#define PPCF_MB(n) ((n) << 6)
+#define PPCF_ME(n) ((n) << 1)
+#define PPCF_Y 0x00200000
+#define PPCF_DOT 0x00000001
+
+typedef enum PPCIns {
+ /* Integer instructions. */
+ PPCI_MR = 0x7c000378,
+ PPCI_NOP = 0x60000000,
+
+ PPCI_LI = 0x38000000,
+ PPCI_LIS = 0x3c000000,
+
+ PPCI_ADD = 0x7c000214,
+ PPCI_ADDC = 0x7c000014,
+ PPCI_ADDO = 0x7c000614,
+ PPCI_ADDE = 0x7c000114,
+ PPCI_ADDZE = 0x7c000194,
+ PPCI_ADDME = 0x7c0001d4,
+ PPCI_ADDI = 0x38000000,
+ PPCI_ADDIS = 0x3c000000,
+ PPCI_ADDIC = 0x30000000,
+ PPCI_ADDICDOT = 0x34000000,
+
+ PPCI_SUBF = 0x7c000050,
+ PPCI_SUBFC = 0x7c000010,
+ PPCI_SUBFO = 0x7c000450,
+ PPCI_SUBFE = 0x7c000110,
+ PPCI_SUBFZE = 0x7c000190,
+ PPCI_SUBFME = 0x7c0001d0,
+ PPCI_SUBFIC = 0x20000000,
+
+ PPCI_NEG = 0x7c0000d0,
+
+ PPCI_AND = 0x7c000038,
+ PPCI_ANDC = 0x7c000078,
+ PPCI_NAND = 0x7c0003b8,
+ PPCI_ANDIDOT = 0x70000000,
+ PPCI_ANDISDOT = 0x74000000,
+
+ PPCI_OR = 0x7c000378,
+ PPCI_NOR = 0x7c0000f8,
+ PPCI_ORI = 0x60000000,
+ PPCI_ORIS = 0x64000000,
+
+ PPCI_XOR = 0x7c000278,
+ PPCI_EQV = 0x7c000238,
+ PPCI_XORI = 0x68000000,
+ PPCI_XORIS = 0x6c000000,
+
+ PPCI_CMPW = 0x7c000000,
+ PPCI_CMPLW = 0x7c000040,
+ PPCI_CMPWI = 0x2c000000,
+ PPCI_CMPLWI = 0x28000000,
+
+ PPCI_MULLW = 0x7c0001d6,
+ PPCI_MULLI = 0x1c000000,
+ PPCI_MULLWO = 0x7c0005d6,
+
+ PPCI_EXTSB = 0x7c000774,
+ PPCI_EXTSH = 0x7c000734,
+
+ PPCI_SLW = 0x7c000030,
+ PPCI_SRW = 0x7c000430,
+ PPCI_SRAW = 0x7c000630,
+ PPCI_SRAWI = 0x7c000670,
+
+ PPCI_RLWNM = 0x5c000000,
+ PPCI_RLWINM = 0x54000000,
+ PPCI_RLWIMI = 0x50000000,
+
+ PPCI_B = 0x48000000,
+ PPCI_BL = 0x48000001,
+ PPCI_BC = 0x40800000,
+ PPCI_BCL = 0x40800001,
+ PPCI_BCTR = 0x4e800420,
+ PPCI_BCTRL = 0x4e800421,
+
+ PPCI_CRANDC = 0x4c000102,
+ PPCI_CRXOR = 0x4c000182,
+ PPCI_CRAND = 0x4c000202,
+ PPCI_CREQV = 0x4c000242,
+ PPCI_CRORC = 0x4c000342,
+ PPCI_CROR = 0x4c000382,
+
+ PPCI_MFLR = 0x7c0802a6,
+ PPCI_MTCTR = 0x7c0903a6,
+
+ PPCI_MCRXR = 0x7c000400,
+
+ /* Load/store instructions. */
+ PPCI_LWZ = 0x80000000,
+ PPCI_LBZ = 0x88000000,
+ PPCI_STW = 0x90000000,
+ PPCI_STB = 0x98000000,
+ PPCI_LHZ = 0xa0000000,
+ PPCI_LHA = 0xa8000000,
+ PPCI_STH = 0xb0000000,
+
+ PPCI_STWU = 0x94000000,
+
+ PPCI_LFS = 0xc0000000,
+ PPCI_LFD = 0xc8000000,
+ PPCI_STFS = 0xd0000000,
+ PPCI_STFD = 0xd8000000,
+
+ PPCI_LWZX = 0x7c00002e,
+ PPCI_LBZX = 0x7c0000ae,
+ PPCI_STWX = 0x7c00012e,
+ PPCI_STBX = 0x7c0001ae,
+ PPCI_LHZX = 0x7c00022e,
+ PPCI_LHAX = 0x7c0002ae,
+ PPCI_STHX = 0x7c00032e,
+
+ PPCI_LWBRX = 0x7c00042c,
+ PPCI_STWBRX = 0x7c00052c,
+
+ PPCI_LFSX = 0x7c00042e,
+ PPCI_LFDX = 0x7c0004ae,
+ PPCI_STFSX = 0x7c00052e,
+ PPCI_STFDX = 0x7c0005ae,
+
+ /* FP instructions. */
+ PPCI_FMR = 0xfc000090,
+ PPCI_FNEG = 0xfc000050,
+ PPCI_FABS = 0xfc000210,
+
+ PPCI_FRSP = 0xfc000018,
+ PPCI_FCTIWZ = 0xfc00001e,
+
+ PPCI_FADD = 0xfc00002a,
+ PPCI_FSUB = 0xfc000028,
+ PPCI_FMUL = 0xfc000032,
+ PPCI_FDIV = 0xfc000024,
+ PPCI_FSQRT = 0xfc00002c,
+
+ PPCI_FMADD = 0xfc00003a,
+ PPCI_FMSUB = 0xfc000038,
+ PPCI_FNMSUB = 0xfc00003c,
+
+ PPCI_FCMPU = 0xfc000000,
+ PPCI_FSEL = 0xfc00002e,
+} PPCIns;
+
+typedef enum PPCCC {
+ CC_GE, CC_LE, CC_NE, CC_NS, CC_LT, CC_GT, CC_EQ, CC_SO
+} PPCCC;
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_target_x86.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_target_x86.h
new file mode 100644
index 0000000..4426cc8
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_target_x86.h
@@ -0,0 +1,342 @@
+/*
+** Definitions for x86 and x64 CPUs.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_TARGET_X86_H
+#define _LJ_TARGET_X86_H
+
+/* -- Registers IDs ------------------------------------------------------- */
+
+#if LJ_64
+#define GPRDEF(_) \
+ _(EAX) _(ECX) _(EDX) _(EBX) _(ESP) _(EBP) _(ESI) _(EDI) \
+ _(R8D) _(R9D) _(R10D) _(R11D) _(R12D) _(R13D) _(R14D) _(R15D)
+#define FPRDEF(_) \
+ _(XMM0) _(XMM1) _(XMM2) _(XMM3) _(XMM4) _(XMM5) _(XMM6) _(XMM7) \
+ _(XMM8) _(XMM9) _(XMM10) _(XMM11) _(XMM12) _(XMM13) _(XMM14) _(XMM15)
+#else
+#define GPRDEF(_) \
+ _(EAX) _(ECX) _(EDX) _(EBX) _(ESP) _(EBP) _(ESI) _(EDI)
+#define FPRDEF(_) \
+ _(XMM0) _(XMM1) _(XMM2) _(XMM3) _(XMM4) _(XMM5) _(XMM6) _(XMM7)
+#endif
+#define VRIDDEF(_) \
+ _(MRM)
+
+#define RIDENUM(name) RID_##name,
+
+enum {
+ GPRDEF(RIDENUM) /* General-purpose registers (GPRs). */
+ FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */
+ RID_MAX,
+ RID_MRM = RID_MAX, /* Pseudo-id for ModRM operand. */
+
+ /* Calling conventions. */
+ RID_RET = RID_EAX,
+#if LJ_64
+ RID_FPRET = RID_XMM0,
+#else
+ RID_RETLO = RID_EAX,
+ RID_RETHI = RID_EDX,
+#endif
+
+ /* These definitions must match with the *.dasc file(s): */
+ RID_BASE = RID_EDX, /* Interpreter BASE. */
+#if LJ_64 && !LJ_ABI_WIN
+ RID_LPC = RID_EBX, /* Interpreter PC. */
+ RID_DISPATCH = RID_R14D, /* Interpreter DISPATCH table. */
+#else
+ RID_LPC = RID_ESI, /* Interpreter PC. */
+ RID_DISPATCH = RID_EBX, /* Interpreter DISPATCH table. */
+#endif
+
+ /* Register ranges [min, max) and number of registers. */
+ RID_MIN_GPR = RID_EAX,
+ RID_MIN_FPR = RID_XMM0,
+ RID_MAX_GPR = RID_MIN_FPR,
+ RID_MAX_FPR = RID_MAX,
+ RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,
+ RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR,
+};
+
+/* -- Register sets ------------------------------------------------------- */
+
+/* Make use of all registers, except the stack pointer. */
+#define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR)-RID2RSET(RID_ESP))
+#define RSET_FPR (RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR))
+#define RSET_ALL (RSET_GPR|RSET_FPR)
+#define RSET_INIT RSET_ALL
+
+#if LJ_64
+/* Note: this requires the use of FORCE_REX! */
+#define RSET_GPR8 RSET_GPR
+#else
+#define RSET_GPR8 (RSET_RANGE(RID_EAX, RID_EBX+1))
+#endif
+
+/* ABI-specific register sets. */
+#define RSET_ACD (RID2RSET(RID_EAX)|RID2RSET(RID_ECX)|RID2RSET(RID_EDX))
+#if LJ_64
+#if LJ_ABI_WIN
+/* Windows x64 ABI. */
+#define RSET_SCRATCH \
+ (RSET_ACD|RSET_RANGE(RID_R8D, RID_R11D+1)|RSET_RANGE(RID_XMM0, RID_XMM5+1))
+#define REGARG_GPRS \
+ (RID_ECX|((RID_EDX|((RID_R8D|(RID_R9D<<5))<<5))<<5))
+#define REGARG_NUMGPR 4
+#define REGARG_NUMFPR 4
+#define REGARG_FIRSTFPR RID_XMM0
+#define REGARG_LASTFPR RID_XMM3
+#define STACKARG_OFS (4*8)
+#else
+/* The rest of the civilized x64 world has a common ABI. */
+#define RSET_SCRATCH \
+ (RSET_ACD|RSET_RANGE(RID_ESI, RID_R11D+1)|RSET_FPR)
+#define REGARG_GPRS \
+ (RID_EDI|((RID_ESI|((RID_EDX|((RID_ECX|((RID_R8D|(RID_R9D \
+ <<5))<<5))<<5))<<5))<<5))
+#define REGARG_NUMGPR 6
+#define REGARG_NUMFPR 8
+#define REGARG_FIRSTFPR RID_XMM0
+#define REGARG_LASTFPR RID_XMM7
+#define STACKARG_OFS 0
+#endif
+#else
+/* Common x86 ABI. */
+#define RSET_SCRATCH (RSET_ACD|RSET_FPR)
+#define REGARG_GPRS (RID_ECX|(RID_EDX<<5)) /* Fastcall only. */
+#define REGARG_NUMGPR 2 /* Fastcall only. */
+#define REGARG_NUMFPR 0
+#define STACKARG_OFS 0
+#endif
+
+#if LJ_64
+/* Prefer the low 8 regs of each type to reduce REX prefixes. */
+#undef rset_picktop
+#define rset_picktop(rs) (lj_fls(lj_bswap(rs)) ^ 0x18)
+#endif
+
+/* -- Spill slots --------------------------------------------------------- */
+
+/* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.
+**
+** SPS_FIXED: Available fixed spill slots in interpreter frame.
+** This definition must match with the *.dasc file(s).
+**
+** SPS_FIRST: First spill slot for general use. Reserve min. two 32 bit slots.
+*/
+#if LJ_64
+#if LJ_ABI_WIN
+#define SPS_FIXED (4*2)
+#define SPS_FIRST (4*2) /* Don't use callee register save area. */
+#else
+#define SPS_FIXED 4
+#define SPS_FIRST 2
+#endif
+#else
+#define SPS_FIXED 6
+#define SPS_FIRST 2
+#endif
+
+#define SPOFS_TMP 0
+
+#define sps_scale(slot) (4 * (int32_t)(slot))
+#define sps_align(slot) (((slot) - SPS_FIXED + 3) & ~3)
+
+/* -- Exit state ---------------------------------------------------------- */
+
+/* This definition must match with the *.dasc file(s). */
+typedef struct {
+ lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */
+ intptr_t gpr[RID_NUM_GPR]; /* General-purpose registers. */
+ int32_t spill[256]; /* Spill slots. */
+} ExitState;
+
+/* Limited by the range of a short fwd jump (127): (2+2)*(32-1)-2 = 122. */
+#define EXITSTUB_SPACING (2+2)
+#define EXITSTUBS_PER_GROUP 32
+
+/* -- x86 ModRM operand encoding ------------------------------------------ */
+
+typedef enum {
+ XM_OFS0 = 0x00, XM_OFS8 = 0x40, XM_OFS32 = 0x80, XM_REG = 0xc0,
+ XM_SCALE1 = 0x00, XM_SCALE2 = 0x40, XM_SCALE4 = 0x80, XM_SCALE8 = 0xc0,
+ XM_MASK = 0xc0
+} x86Mode;
+
+/* Structure to hold variable ModRM operand. */
+typedef struct {
+ int32_t ofs; /* Offset. */
+ uint8_t base; /* Base register or RID_NONE. */
+ uint8_t idx; /* Index register or RID_NONE. */
+ uint8_t scale; /* Index scale (XM_SCALE1 .. XM_SCALE8). */
+} x86ModRM;
+
+/* -- Opcodes ------------------------------------------------------------- */
+
+/* Macros to construct variable-length x86 opcodes. -(len+1) is in LSB. */
+#define XO_(o) ((uint32_t)(0x0000fe + (0x##o<<24)))
+#define XO_FPU(a,b) ((uint32_t)(0x00fd + (0x##a<<16)+(0x##b<<24)))
+#define XO_0f(o) ((uint32_t)(0x0f00fd + (0x##o<<24)))
+#define XO_66(o) ((uint32_t)(0x6600fd + (0x##o<<24)))
+#define XO_660f(o) ((uint32_t)(0x0f66fc + (0x##o<<24)))
+#define XO_f20f(o) ((uint32_t)(0x0ff2fc + (0x##o<<24)))
+#define XO_f30f(o) ((uint32_t)(0x0ff3fc + (0x##o<<24)))
+
+/* This list of x86 opcodes is not intended to be complete. Opcodes are only
+** included when needed. Take a look at DynASM or jit.dis_x86 to see the
+** whole mess.
+*/
+typedef enum {
+ /* Fixed length opcodes. XI_* prefix. */
+ XI_NOP = 0x90,
+ XI_XCHGa = 0x90,
+ XI_CALL = 0xe8,
+ XI_JMP = 0xe9,
+ XI_JMPs = 0xeb,
+ XI_PUSH = 0x50, /* Really 50+r. */
+ XI_JCCs = 0x70, /* Really 7x. */
+ XI_JCCn = 0x80, /* Really 0f8x. */
+ XI_LEA = 0x8d,
+ XI_MOVrib = 0xb0, /* Really b0+r. */
+ XI_MOVri = 0xb8, /* Really b8+r. */
+ XI_ARITHib = 0x80,
+ XI_ARITHi = 0x81,
+ XI_ARITHi8 = 0x83,
+ XI_PUSHi8 = 0x6a,
+ XI_TESTb = 0x84,
+ XI_TEST = 0x85,
+ XI_MOVmi = 0xc7,
+ XI_GROUP5 = 0xff,
+
+ /* Note: little-endian byte-order! */
+ XI_FLDZ = 0xeed9,
+ XI_FLD1 = 0xe8d9,
+ XI_FLDLG2 = 0xecd9,
+ XI_FLDLN2 = 0xedd9,
+ XI_FDUP = 0xc0d9, /* Really fld st0. */
+ XI_FPOP = 0xd8dd, /* Really fstp st0. */
+ XI_FPOP1 = 0xd9dd, /* Really fstp st1. */
+ XI_FRNDINT = 0xfcd9,
+ XI_FSIN = 0xfed9,
+ XI_FCOS = 0xffd9,
+ XI_FPTAN = 0xf2d9,
+ XI_FPATAN = 0xf3d9,
+ XI_FSCALE = 0xfdd9,
+ XI_FYL2X = 0xf1d9,
+
+ /* Variable-length opcodes. XO_* prefix. */
+ XO_MOV = XO_(8b),
+ XO_MOVto = XO_(89),
+ XO_MOVtow = XO_66(89),
+ XO_MOVtob = XO_(88),
+ XO_MOVmi = XO_(c7),
+ XO_MOVmib = XO_(c6),
+ XO_LEA = XO_(8d),
+ XO_ARITHib = XO_(80),
+ XO_ARITHi = XO_(81),
+ XO_ARITHi8 = XO_(83),
+ XO_ARITHiw8 = XO_66(83),
+ XO_SHIFTi = XO_(c1),
+ XO_SHIFT1 = XO_(d1),
+ XO_SHIFTcl = XO_(d3),
+ XO_IMUL = XO_0f(af),
+ XO_IMULi = XO_(69),
+ XO_IMULi8 = XO_(6b),
+ XO_CMP = XO_(3b),
+ XO_TESTb = XO_(84),
+ XO_TEST = XO_(85),
+ XO_GROUP3b = XO_(f6),
+ XO_GROUP3 = XO_(f7),
+ XO_GROUP5b = XO_(fe),
+ XO_GROUP5 = XO_(ff),
+ XO_MOVZXb = XO_0f(b6),
+ XO_MOVZXw = XO_0f(b7),
+ XO_MOVSXb = XO_0f(be),
+ XO_MOVSXw = XO_0f(bf),
+ XO_MOVSXd = XO_(63),
+ XO_BSWAP = XO_0f(c8),
+ XO_CMOV = XO_0f(40),
+
+ XO_MOVSD = XO_f20f(10),
+ XO_MOVSDto = XO_f20f(11),
+ XO_MOVSS = XO_f30f(10),
+ XO_MOVSSto = XO_f30f(11),
+ XO_MOVLPD = XO_660f(12),
+ XO_MOVAPS = XO_0f(28),
+ XO_XORPS = XO_0f(57),
+ XO_ANDPS = XO_0f(54),
+ XO_ADDSD = XO_f20f(58),
+ XO_SUBSD = XO_f20f(5c),
+ XO_MULSD = XO_f20f(59),
+ XO_DIVSD = XO_f20f(5e),
+ XO_SQRTSD = XO_f20f(51),
+ XO_MINSD = XO_f20f(5d),
+ XO_MAXSD = XO_f20f(5f),
+ XO_ROUNDSD = 0x0b3a0ffc, /* Really 66 0f 3a 0b. See asm_fpmath. */
+ XO_UCOMISD = XO_660f(2e),
+ XO_CVTSI2SD = XO_f20f(2a),
+ XO_CVTSD2SI = XO_f20f(2d),
+ XO_CVTTSD2SI= XO_f20f(2c),
+ XO_CVTSI2SS = XO_f30f(2a),
+ XO_CVTSS2SI = XO_f30f(2d),
+ XO_CVTTSS2SI= XO_f30f(2c),
+ XO_CVTSS2SD = XO_f30f(5a),
+ XO_CVTSD2SS = XO_f20f(5a),
+ XO_ADDSS = XO_f30f(58),
+ XO_MOVD = XO_660f(6e),
+ XO_MOVDto = XO_660f(7e),
+
+ XO_FLDd = XO_(d9), XOg_FLDd = 0,
+ XO_FLDq = XO_(dd), XOg_FLDq = 0,
+ XO_FILDd = XO_(db), XOg_FILDd = 0,
+ XO_FILDq = XO_(df), XOg_FILDq = 5,
+ XO_FSTPd = XO_(d9), XOg_FSTPd = 3,
+ XO_FSTPq = XO_(dd), XOg_FSTPq = 3,
+ XO_FISTPq = XO_(df), XOg_FISTPq = 7,
+ XO_FISTTPq = XO_(dd), XOg_FISTTPq = 1,
+ XO_FADDq = XO_(dc), XOg_FADDq = 0,
+ XO_FLDCW = XO_(d9), XOg_FLDCW = 5,
+ XO_FNSTCW = XO_(d9), XOg_FNSTCW = 7
+} x86Op;
+
+/* x86 opcode groups. */
+typedef uint32_t x86Group;
+
+#define XG_(i8, i, g) ((x86Group)(((i8) << 16) + ((i) << 8) + (g)))
+#define XG_ARITHi(g) XG_(XI_ARITHi8, XI_ARITHi, g)
+#define XG_TOXOi(xg) ((x86Op)(0x000000fe + (((xg)<<16) & 0xff000000)))
+#define XG_TOXOi8(xg) ((x86Op)(0x000000fe + (((xg)<<8) & 0xff000000)))
+
+#define XO_ARITH(a) ((x86Op)(0x030000fe + ((a)<<27)))
+#define XO_ARITHw(a) ((x86Op)(0x036600fd + ((a)<<27)))
+
+typedef enum {
+ XOg_ADD, XOg_OR, XOg_ADC, XOg_SBB, XOg_AND, XOg_SUB, XOg_XOR, XOg_CMP,
+ XOg_X_IMUL
+} x86Arith;
+
+typedef enum {
+ XOg_ROL, XOg_ROR, XOg_RCL, XOg_RCR, XOg_SHL, XOg_SHR, XOg_SAL, XOg_SAR
+} x86Shift;
+
+typedef enum {
+ XOg_TEST, XOg_TEST_, XOg_NOT, XOg_NEG, XOg_MUL, XOg_IMUL, XOg_DIV, XOg_IDIV
+} x86Group3;
+
+typedef enum {
+ XOg_INC, XOg_DEC, XOg_CALL, XOg_CALLfar, XOg_JMP, XOg_JMPfar, XOg_PUSH
+} x86Group5;
+
+/* x86 condition codes. */
+typedef enum {
+ CC_O, CC_NO, CC_B, CC_NB, CC_E, CC_NE, CC_BE, CC_NBE,
+ CC_S, CC_NS, CC_P, CC_NP, CC_L, CC_NL, CC_LE, CC_NLE,
+ CC_C = CC_B, CC_NAE = CC_C, CC_NC = CC_NB, CC_AE = CC_NB,
+ CC_Z = CC_E, CC_NZ = CC_NE, CC_NA = CC_BE, CC_A = CC_NBE,
+ CC_PE = CC_P, CC_PO = CC_NP, CC_NGE = CC_L, CC_GE = CC_NL,
+ CC_NG = CC_LE, CC_G = CC_NLE
+} x86CC;
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_trace.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_trace.c
new file mode 100644
index 0000000..6f8dc1a
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_trace.c
@@ -0,0 +1,824 @@
+/*
+** Trace management.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_trace_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT
+
+#include "lj_gc.h"
+#include "lj_err.h"
+#include "lj_debug.h"
+#include "lj_str.h"
+#include "lj_frame.h"
+#include "lj_state.h"
+#include "lj_bc.h"
+#include "lj_ir.h"
+#include "lj_jit.h"
+#include "lj_iropt.h"
+#include "lj_mcode.h"
+#include "lj_trace.h"
+#include "lj_snap.h"
+#include "lj_gdbjit.h"
+#include "lj_record.h"
+#include "lj_asm.h"
+#include "lj_dispatch.h"
+#include "lj_vm.h"
+#include "lj_vmevent.h"
+#include "lj_target.h"
+
+/* -- Error handling ------------------------------------------------------ */
+
+/* Synchronous abort with error message. */
+void lj_trace_err(jit_State *J, TraceError e)
+{
+ setnilV(&J->errinfo); /* No error info. */
+ setintV(J->L->top++, (int32_t)e);
+ lj_err_throw(J->L, LUA_ERRRUN);
+}
+
+/* Synchronous abort with error message and error info. */
+void lj_trace_err_info(jit_State *J, TraceError e)
+{
+ setintV(J->L->top++, (int32_t)e);
+ lj_err_throw(J->L, LUA_ERRRUN);
+}
+
+/* -- Trace management ---------------------------------------------------- */
+
+/* The current trace is first assembled in J->cur. The variable length
+** arrays point to shared, growable buffers (J->irbuf etc.). When trace
+** recording ends successfully, the current trace and its data structures
+** are copied to a new (compact) GCtrace object.
+*/
+
+/* Find a free trace number. */
+static TraceNo trace_findfree(jit_State *J)
+{
+ MSize osz, lim;
+ if (J->freetrace == 0)
+ J->freetrace = 1;
+ for (; J->freetrace < J->sizetrace; J->freetrace++)
+ if (traceref(J, J->freetrace) == NULL)
+ return J->freetrace++;
+ /* Need to grow trace array. */
+ lim = (MSize)J->param[JIT_P_maxtrace] + 1;
+ if (lim < 2) lim = 2; else if (lim > 65535) lim = 65535;
+ osz = J->sizetrace;
+ if (osz >= lim)
+ return 0; /* Too many traces. */
+ lj_mem_growvec(J->L, J->trace, J->sizetrace, lim, GCRef);
+ for (; osz < J->sizetrace; osz++)
+ setgcrefnull(J->trace[osz]);
+ return J->freetrace;
+}
+
+#define TRACE_APPENDVEC(field, szfield, tp) \
+ T->field = (tp *)p; \
+ memcpy(p, J->cur.field, J->cur.szfield*sizeof(tp)); \
+ p += J->cur.szfield*sizeof(tp);
+
+#ifdef LUAJIT_USE_PERFTOOLS
+/*
+** Create symbol table of JIT-compiled code. For use with Linux perf tools.
+** Example usage:
+** perf record -f -e cycles luajit test.lua
+** perf report -s symbol
+** rm perf.data /tmp/perf-*.map
+*/
+#include <stdio.h>
+#include <unistd.h>
+
+static void perftools_addtrace(GCtrace *T)
+{
+ static FILE *fp;
+ GCproto *pt = &gcref(T->startpt)->pt;
+ const BCIns *startpc = mref(T->startpc, const BCIns);
+ const char *name = proto_chunknamestr(pt);
+ BCLine lineno;
+ if (name[0] == '@' || name[0] == '=')
+ name++;
+ else
+ name = "(string)";
+ lua_assert(startpc >= proto_bc(pt) && startpc < proto_bc(pt) + pt->sizebc);
+ lineno = lj_debug_line(pt, proto_bcpos(pt, startpc));
+ if (!fp) {
+ char fname[40];
+ sprintf(fname, "/tmp/perf-%d.map", getpid());
+ if (!(fp = fopen(fname, "w"))) return;
+ setlinebuf(fp);
+ }
+ fprintf(fp, "%lx %x TRACE_%d::%s:%u\n",
+ (long)T->mcode, T->szmcode, T->traceno, name, lineno);
+}
+#endif
+
+/* Allocate space for copy of trace. */
+static GCtrace *trace_save_alloc(jit_State *J)
+{
+ size_t sztr = ((sizeof(GCtrace)+7)&~7);
+ size_t szins = (J->cur.nins-J->cur.nk)*sizeof(IRIns);
+ size_t sz = sztr + szins +
+ J->cur.nsnap*sizeof(SnapShot) +
+ J->cur.nsnapmap*sizeof(SnapEntry);
+ return lj_mem_newt(J->L, (MSize)sz, GCtrace);
+}
+
+/* Save current trace by copying and compacting it. */
+static void trace_save(jit_State *J, GCtrace *T)
+{
+ size_t sztr = ((sizeof(GCtrace)+7)&~7);
+ size_t szins = (J->cur.nins-J->cur.nk)*sizeof(IRIns);
+ char *p = (char *)T + sztr;
+ memcpy(T, &J->cur, sizeof(GCtrace));
+ setgcrefr(T->nextgc, J2G(J)->gc.root);
+ setgcrefp(J2G(J)->gc.root, T);
+ newwhite(J2G(J), T);
+ T->gct = ~LJ_TTRACE;
+ T->ir = (IRIns *)p - J->cur.nk;
+ memcpy(p, J->cur.ir+J->cur.nk, szins);
+ p += szins;
+ TRACE_APPENDVEC(snap, nsnap, SnapShot)
+ TRACE_APPENDVEC(snapmap, nsnapmap, SnapEntry)
+ J->cur.traceno = 0;
+ setgcrefp(J->trace[T->traceno], T);
+ lj_gc_barriertrace(J2G(J), T->traceno);
+ lj_gdbjit_addtrace(J, T);
+#ifdef LUAJIT_USE_PERFTOOLS
+ perftools_addtrace(T);
+#endif
+}
+
+void LJ_FASTCALL lj_trace_free(global_State *g, GCtrace *T)
+{
+ jit_State *J = G2J(g);
+ if (T->traceno) {
+ lj_gdbjit_deltrace(J, T);
+ if (T->traceno < J->freetrace)
+ J->freetrace = T->traceno;
+ setgcrefnull(J->trace[T->traceno]);
+ }
+ lj_mem_free(g, T,
+ ((sizeof(GCtrace)+7)&~7) + (T->nins-T->nk)*sizeof(IRIns) +
+ T->nsnap*sizeof(SnapShot) + T->nsnapmap*sizeof(SnapEntry));
+}
+
+/* Re-enable compiling a prototype by unpatching any modified bytecode. */
+void lj_trace_reenableproto(GCproto *pt)
+{
+ if ((pt->flags & PROTO_ILOOP)) {
+ BCIns *bc = proto_bc(pt);
+ BCPos i, sizebc = pt->sizebc;;
+ pt->flags &= ~PROTO_ILOOP;
+ if (bc_op(bc[0]) == BC_IFUNCF)
+ setbc_op(&bc[0], BC_FUNCF);
+ for (i = 1; i < sizebc; i++) {
+ BCOp op = bc_op(bc[i]);
+ if (op == BC_IFORL || op == BC_IITERL || op == BC_ILOOP)
+ setbc_op(&bc[i], (int)op+(int)BC_LOOP-(int)BC_ILOOP);
+ }
+ }
+}
+
+/* Unpatch the bytecode modified by a root trace. */
+static void trace_unpatch(jit_State *J, GCtrace *T)
+{
+ BCOp op = bc_op(T->startins);
+ BCIns *pc = mref(T->startpc, BCIns);
+ UNUSED(J);
+ if (op == BC_JMP)
+ return; /* No need to unpatch branches in parent traces (yet). */
+ switch (bc_op(*pc)) {
+ case BC_JFORL:
+ lua_assert(traceref(J, bc_d(*pc)) == T);
+ *pc = T->startins;
+ pc += bc_j(T->startins);
+ lua_assert(bc_op(*pc) == BC_JFORI);
+ setbc_op(pc, BC_FORI);
+ break;
+ case BC_JITERL:
+ case BC_JLOOP:
+ lua_assert(op == BC_ITERL || op == BC_LOOP || bc_isret(op));
+ *pc = T->startins;
+ break;
+ case BC_JMP:
+ lua_assert(op == BC_ITERL);
+ pc += bc_j(*pc)+2;
+ if (bc_op(*pc) == BC_JITERL) {
+ lua_assert(traceref(J, bc_d(*pc)) == T);
+ *pc = T->startins;
+ }
+ break;
+ case BC_JFUNCF:
+ lua_assert(op == BC_FUNCF);
+ *pc = T->startins;
+ break;
+ default: /* Already unpatched. */
+ break;
+ }
+}
+
+/* Flush a root trace. */
+static void trace_flushroot(jit_State *J, GCtrace *T)
+{
+ GCproto *pt = &gcref(T->startpt)->pt;
+ lua_assert(T->root == 0 && pt != NULL);
+ /* First unpatch any modified bytecode. */
+ trace_unpatch(J, T);
+ /* Unlink root trace from chain anchored in prototype. */
+ if (pt->trace == T->traceno) { /* Trace is first in chain. Easy. */
+ pt->trace = T->nextroot;
+ } else if (pt->trace) { /* Otherwise search in chain of root traces. */
+ GCtrace *T2 = traceref(J, pt->trace);
+ if (T2) {
+ for (; T2->nextroot; T2 = traceref(J, T2->nextroot))
+ if (T2->nextroot == T->traceno) {
+ T2->nextroot = T->nextroot; /* Unlink from chain. */
+ break;
+ }
+ }
+ }
+}
+
+/* Flush a trace. Only root traces are considered. */
+void lj_trace_flush(jit_State *J, TraceNo traceno)
+{
+ if (traceno > 0 && traceno < J->sizetrace) {
+ GCtrace *T = traceref(J, traceno);
+ if (T && T->root == 0)
+ trace_flushroot(J, T);
+ }
+}
+
+/* Flush all traces associated with a prototype. */
+void lj_trace_flushproto(global_State *g, GCproto *pt)
+{
+ while (pt->trace != 0)
+ trace_flushroot(G2J(g), traceref(G2J(g), pt->trace));
+}
+
+/* Flush all traces. */
+int lj_trace_flushall(lua_State *L)
+{
+ jit_State *J = L2J(L);
+ ptrdiff_t i;
+ if ((J2G(J)->hookmask & HOOK_GC))
+ return 1;
+ for (i = (ptrdiff_t)J->sizetrace-1; i > 0; i--) {
+ GCtrace *T = traceref(J, i);
+ if (T) {
+ if (T->root == 0)
+ trace_flushroot(J, T);
+ lj_gdbjit_deltrace(J, T);
+ T->traceno = 0;
+ setgcrefnull(J->trace[i]);
+ }
+ }
+ J->cur.traceno = 0;
+ J->freetrace = 0;
+ /* Clear penalty cache. */
+ memset(J->penalty, 0, sizeof(J->penalty));
+ /* Free the whole machine code and invalidate all exit stub groups. */
+ lj_mcode_free(J);
+ memset(J->exitstubgroup, 0, sizeof(J->exitstubgroup));
+ lj_vmevent_send(L, TRACE,
+ setstrV(L, L->top++, lj_str_newlit(L, "flush"));
+ );
+ return 0;
+}
+
+/* Initialize JIT compiler state. */
+void lj_trace_initstate(global_State *g)
+{
+ jit_State *J = G2J(g);
+ TValue *tv;
+ /* Initialize SIMD constants. */
+ tv = LJ_KSIMD(J, LJ_KSIMD_ABS);
+ tv[0].u64 = U64x(7fffffff,ffffffff);
+ tv[1].u64 = U64x(7fffffff,ffffffff);
+ tv = LJ_KSIMD(J, LJ_KSIMD_NEG);
+ tv[0].u64 = U64x(80000000,00000000);
+ tv[1].u64 = U64x(80000000,00000000);
+}
+
+/* Free everything associated with the JIT compiler state. */
+void lj_trace_freestate(global_State *g)
+{
+ jit_State *J = G2J(g);
+#ifdef LUA_USE_ASSERT
+ { /* This assumes all traces have already been freed. */
+ ptrdiff_t i;
+ for (i = 1; i < (ptrdiff_t)J->sizetrace; i++)
+ lua_assert(i == (ptrdiff_t)J->cur.traceno || traceref(J, i) == NULL);
+ }
+#endif
+ lj_mcode_free(J);
+ lj_ir_k64_freeall(J);
+ lj_mem_freevec(g, J->snapmapbuf, J->sizesnapmap, SnapEntry);
+ lj_mem_freevec(g, J->snapbuf, J->sizesnap, SnapShot);
+ lj_mem_freevec(g, J->irbuf + J->irbotlim, J->irtoplim - J->irbotlim, IRIns);
+ lj_mem_freevec(g, J->trace, J->sizetrace, GCRef);
+}
+
+/* -- Penalties and blacklisting ------------------------------------------ */
+
+/* Blacklist a bytecode instruction. */
+static void blacklist_pc(GCproto *pt, BCIns *pc)
+{
+ setbc_op(pc, (int)bc_op(*pc)+(int)BC_ILOOP-(int)BC_LOOP);
+ pt->flags |= PROTO_ILOOP;
+}
+
+/* Penalize a bytecode instruction. */
+static void penalty_pc(jit_State *J, GCproto *pt, BCIns *pc, TraceError e)
+{
+ uint32_t i, val = PENALTY_MIN;
+ for (i = 0; i < PENALTY_SLOTS; i++)
+ if (mref(J->penalty[i].pc, const BCIns) == pc) { /* Cache slot found? */
+ /* First try to bump its hotcount several times. */
+ val = ((uint32_t)J->penalty[i].val << 1) +
+ LJ_PRNG_BITS(J, PENALTY_RNDBITS);
+ if (val > PENALTY_MAX) {
+ blacklist_pc(pt, pc); /* Blacklist it, if that didn't help. */
+ return;
+ }
+ goto setpenalty;
+ }
+ /* Assign a new penalty cache slot. */
+ i = J->penaltyslot;
+ J->penaltyslot = (J->penaltyslot + 1) & (PENALTY_SLOTS-1);
+ setmref(J->penalty[i].pc, pc);
+setpenalty:
+ J->penalty[i].val = (uint16_t)val;
+ J->penalty[i].reason = e;
+ hotcount_set(J2GG(J), pc+1, val);
+}
+
+/* -- Trace compiler state machine ---------------------------------------- */
+
+/* Start tracing. */
+static void trace_start(jit_State *J)
+{
+ lua_State *L;
+ TraceNo traceno;
+
+ if ((J->pt->flags & PROTO_NOJIT)) { /* JIT disabled for this proto? */
+ if (J->parent == 0) {
+ /* Lazy bytecode patching to disable hotcount events. */
+ lua_assert(bc_op(*J->pc) == BC_FORL || bc_op(*J->pc) == BC_ITERL ||
+ bc_op(*J->pc) == BC_LOOP || bc_op(*J->pc) == BC_FUNCF);
+ setbc_op(J->pc, (int)bc_op(*J->pc)+(int)BC_ILOOP-(int)BC_LOOP);
+ J->pt->flags |= PROTO_ILOOP;
+ }
+ J->state = LJ_TRACE_IDLE; /* Silently ignored. */
+ return;
+ }
+
+ /* Get a new trace number. */
+ traceno = trace_findfree(J);
+ if (LJ_UNLIKELY(traceno == 0)) { /* No free trace? */
+ lua_assert((J2G(J)->hookmask & HOOK_GC) == 0);
+ lj_trace_flushall(J->L);
+ J->state = LJ_TRACE_IDLE; /* Silently ignored. */
+ return;
+ }
+ setgcrefp(J->trace[traceno], &J->cur);
+
+ /* Setup enough of the current trace to be able to send the vmevent. */
+ memset(&J->cur, 0, sizeof(GCtrace));
+ J->cur.traceno = traceno;
+ J->cur.nins = J->cur.nk = REF_BASE;
+ J->cur.ir = J->irbuf;
+ J->cur.snap = J->snapbuf;
+ J->cur.snapmap = J->snapmapbuf;
+ J->mergesnap = 0;
+ J->needsnap = 0;
+ J->bcskip = 0;
+ J->guardemit.irt = 0;
+ J->postproc = LJ_POST_NONE;
+ lj_resetsplit(J);
+ setgcref(J->cur.startpt, obj2gco(J->pt));
+
+ L = J->L;
+ lj_vmevent_send(L, TRACE,
+ setstrV(L, L->top++, lj_str_newlit(L, "start"));
+ setintV(L->top++, traceno);
+ setfuncV(L, L->top++, J->fn);
+ setintV(L->top++, proto_bcpos(J->pt, J->pc));
+ if (J->parent) {
+ setintV(L->top++, J->parent);
+ setintV(L->top++, J->exitno);
+ }
+ );
+ lj_record_setup(J);
+}
+
+/* Stop tracing. */
+static void trace_stop(jit_State *J)
+{
+ BCIns *pc = mref(J->cur.startpc, BCIns);
+ BCOp op = bc_op(J->cur.startins);
+ GCproto *pt = &gcref(J->cur.startpt)->pt;
+ TraceNo traceno = J->cur.traceno;
+ GCtrace *T = trace_save_alloc(J); /* Do this first. May throw OOM. */
+ lua_State *L;
+
+ switch (op) {
+ case BC_FORL:
+ setbc_op(pc+bc_j(J->cur.startins), BC_JFORI); /* Patch FORI, too. */
+ /* fallthrough */
+ case BC_LOOP:
+ case BC_ITERL:
+ case BC_FUNCF:
+ /* Patch bytecode of starting instruction in root trace. */
+ setbc_op(pc, (int)op+(int)BC_JLOOP-(int)BC_LOOP);
+ setbc_d(pc, traceno);
+ addroot:
+ /* Add to root trace chain in prototype. */
+ J->cur.nextroot = pt->trace;
+ pt->trace = (TraceNo1)traceno;
+ break;
+ case BC_RET:
+ case BC_RET0:
+ case BC_RET1:
+ *pc = BCINS_AD(BC_JLOOP, J->cur.snap[0].nslots, traceno);
+ goto addroot;
+ case BC_JMP:
+ /* Patch exit branch in parent to side trace entry. */
+ lua_assert(J->parent != 0 && J->cur.root != 0);
+ lj_asm_patchexit(J, traceref(J, J->parent), J->exitno, J->cur.mcode);
+ /* Avoid compiling a side trace twice (stack resizing uses parent exit). */
+ traceref(J, J->parent)->snap[J->exitno].count = SNAPCOUNT_DONE;
+ /* Add to side trace chain in root trace. */
+ {
+ GCtrace *root = traceref(J, J->cur.root);
+ root->nchild++;
+ J->cur.nextside = root->nextside;
+ root->nextside = (TraceNo1)traceno;
+ }
+ break;
+ default:
+ lua_assert(0);
+ break;
+ }
+
+ /* Commit new mcode only after all patching is done. */
+ lj_mcode_commit(J, J->cur.mcode);
+ J->postproc = LJ_POST_NONE;
+ trace_save(J, T);
+
+ L = J->L;
+ lj_vmevent_send(L, TRACE,
+ setstrV(L, L->top++, lj_str_newlit(L, "stop"));
+ setintV(L->top++, traceno);
+ );
+}
+
+/* Start a new root trace for down-recursion. */
+static int trace_downrec(jit_State *J)
+{
+ /* Restart recording at the return instruction. */
+ lua_assert(J->pt != NULL);
+ lua_assert(bc_isret(bc_op(*J->pc)));
+ if (bc_op(*J->pc) == BC_RETM)
+ return 0; /* NYI: down-recursion with RETM. */
+ J->parent = 0;
+ J->exitno = 0;
+ J->state = LJ_TRACE_RECORD;
+ trace_start(J);
+ return 1;
+}
+
+/* Abort tracing. */
+static int trace_abort(jit_State *J)
+{
+ lua_State *L = J->L;
+ TraceError e = LJ_TRERR_RECERR;
+ TraceNo traceno;
+
+ J->postproc = LJ_POST_NONE;
+ lj_mcode_abort(J);
+ if (tvisnumber(L->top-1))
+ e = (TraceError)numberVint(L->top-1);
+ if (e == LJ_TRERR_MCODELM) {
+ L->top--; /* Remove error object */
+ J->state = LJ_TRACE_ASM;
+ return 1; /* Retry ASM with new MCode area. */
+ }
+ /* Penalize or blacklist starting bytecode instruction. */
+ if (J->parent == 0 && !bc_isret(bc_op(J->cur.startins)))
+ penalty_pc(J, &gcref(J->cur.startpt)->pt, mref(J->cur.startpc, BCIns), e);
+
+ /* Is there anything to abort? */
+ traceno = J->cur.traceno;
+ if (traceno) {
+ ptrdiff_t errobj = savestack(L, L->top-1); /* Stack may be resized. */
+ J->cur.link = 0;
+ J->cur.linktype = LJ_TRLINK_NONE;
+ lj_vmevent_send(L, TRACE,
+ TValue *frame;
+ const BCIns *pc;
+ GCfunc *fn;
+ setstrV(L, L->top++, lj_str_newlit(L, "abort"));
+ setintV(L->top++, traceno);
+ /* Find original Lua function call to generate a better error message. */
+ frame = J->L->base-1;
+ pc = J->pc;
+ while (!isluafunc(frame_func(frame))) {
+ pc = (frame_iscont(frame) ? frame_contpc(frame) : frame_pc(frame)) - 1;
+ frame = frame_prev(frame);
+ }
+ fn = frame_func(frame);
+ setfuncV(L, L->top++, fn);
+ setintV(L->top++, proto_bcpos(funcproto(fn), pc));
+ copyTV(L, L->top++, restorestack(L, errobj));
+ copyTV(L, L->top++, &J->errinfo);
+ );
+ /* Drop aborted trace after the vmevent (which may still access it). */
+ setgcrefnull(J->trace[traceno]);
+ if (traceno < J->freetrace)
+ J->freetrace = traceno;
+ J->cur.traceno = 0;
+ }
+ L->top--; /* Remove error object */
+ if (e == LJ_TRERR_DOWNREC)
+ return trace_downrec(J);
+ else if (e == LJ_TRERR_MCODEAL)
+ lj_trace_flushall(L);
+ return 0;
+}
+
+/* Perform pending re-patch of a bytecode instruction. */
+static LJ_AINLINE void trace_pendpatch(jit_State *J, int force)
+{
+ if (LJ_UNLIKELY(J->patchpc)) {
+ if (force || J->bcskip == 0) {
+ *J->patchpc = J->patchins;
+ J->patchpc = NULL;
+ } else {
+ J->bcskip = 0;
+ }
+ }
+}
+
+/* State machine for the trace compiler. Protected callback. */
+static TValue *trace_state(lua_State *L, lua_CFunction dummy, void *ud)
+{
+ jit_State *J = (jit_State *)ud;
+ UNUSED(dummy);
+ do {
+ retry:
+ switch (J->state) {
+ case LJ_TRACE_START:
+ J->state = LJ_TRACE_RECORD; /* trace_start() may change state. */
+ trace_start(J);
+ lj_dispatch_update(J2G(J));
+ break;
+
+ case LJ_TRACE_RECORD:
+ trace_pendpatch(J, 0);
+ setvmstate(J2G(J), RECORD);
+ lj_vmevent_send_(L, RECORD,
+ /* Save/restore tmptv state for trace recorder. */
+ TValue savetv = J2G(J)->tmptv;
+ TValue savetv2 = J2G(J)->tmptv2;
+ setintV(L->top++, J->cur.traceno);
+ setfuncV(L, L->top++, J->fn);
+ setintV(L->top++, J->pt ? (int32_t)proto_bcpos(J->pt, J->pc) : -1);
+ setintV(L->top++, J->framedepth);
+ ,
+ J2G(J)->tmptv = savetv;
+ J2G(J)->tmptv2 = savetv2;
+ );
+ lj_record_ins(J);
+ break;
+
+ case LJ_TRACE_END:
+ trace_pendpatch(J, 1);
+ J->loopref = 0;
+ if ((J->flags & JIT_F_OPT_LOOP) &&
+ J->cur.link == J->cur.traceno && J->framedepth + J->retdepth == 0) {
+ setvmstate(J2G(J), OPT);
+ lj_opt_dce(J);
+ if (lj_opt_loop(J)) { /* Loop optimization failed? */
+ J->cur.link = 0;
+ J->cur.linktype = LJ_TRLINK_NONE;
+ J->loopref = J->cur.nins;
+ J->state = LJ_TRACE_RECORD; /* Try to continue recording. */
+ break;
+ }
+ J->loopref = J->chain[IR_LOOP]; /* Needed by assembler. */
+ }
+ lj_opt_split(J);
+ lj_opt_sink(J);
+ if (!J->loopref) J->cur.snap[J->cur.nsnap-1].count = SNAPCOUNT_DONE;
+ J->state = LJ_TRACE_ASM;
+ break;
+
+ case LJ_TRACE_ASM:
+ setvmstate(J2G(J), ASM);
+ lj_asm_trace(J, &J->cur);
+ trace_stop(J);
+ setvmstate(J2G(J), INTERP);
+ J->state = LJ_TRACE_IDLE;
+ lj_dispatch_update(J2G(J));
+ return NULL;
+
+ default: /* Trace aborted asynchronously. */
+ setintV(L->top++, (int32_t)LJ_TRERR_RECERR);
+ /* fallthrough */
+ case LJ_TRACE_ERR:
+ trace_pendpatch(J, 1);
+ if (trace_abort(J))
+ goto retry;
+ setvmstate(J2G(J), INTERP);
+ J->state = LJ_TRACE_IDLE;
+ lj_dispatch_update(J2G(J));
+ return NULL;
+ }
+ } while (J->state > LJ_TRACE_RECORD);
+ return NULL;
+}
+
+/* -- Event handling ------------------------------------------------------ */
+
+/* A bytecode instruction is about to be executed. Record it. */
+void lj_trace_ins(jit_State *J, const BCIns *pc)
+{
+ /* Note: J->L must already be set. pc is the true bytecode PC here. */
+ J->pc = pc;
+ J->fn = curr_func(J->L);
+ J->pt = isluafunc(J->fn) ? funcproto(J->fn) : NULL;
+ while (lj_vm_cpcall(J->L, NULL, (void *)J, trace_state) != 0)
+ J->state = LJ_TRACE_ERR;
+}
+
+/* A hotcount triggered. Start recording a root trace. */
+void LJ_FASTCALL lj_trace_hot(jit_State *J, const BCIns *pc)
+{
+ /* Note: pc is the interpreter bytecode PC here. It's offset by 1. */
+ ERRNO_SAVE
+ /* Reset hotcount. */
+ hotcount_set(J2GG(J), pc, J->param[JIT_P_hotloop]*HOTCOUNT_LOOP);
+ /* Only start a new trace if not recording or inside __gc call or vmevent. */
+ if (J->state == LJ_TRACE_IDLE &&
+ !(J2G(J)->hookmask & (HOOK_GC|HOOK_VMEVENT))) {
+ J->parent = 0; /* Root trace. */
+ J->exitno = 0;
+ J->state = LJ_TRACE_START;
+ lj_trace_ins(J, pc-1);
+ }
+ ERRNO_RESTORE
+}
+
+/* Check for a hot side exit. If yes, start recording a side trace. */
+static void trace_hotside(jit_State *J, const BCIns *pc)
+{
+ SnapShot *snap = &traceref(J, J->parent)->snap[J->exitno];
+ if (!(J2G(J)->hookmask & (HOOK_GC|HOOK_VMEVENT)) &&
+ snap->count != SNAPCOUNT_DONE &&
+ ++snap->count >= J->param[JIT_P_hotexit]) {
+ lua_assert(J->state == LJ_TRACE_IDLE);
+ /* J->parent is non-zero for a side trace. */
+ J->state = LJ_TRACE_START;
+ lj_trace_ins(J, pc);
+ }
+}
+
+/* Tiny struct to pass data to protected call. */
+typedef struct ExitDataCP {
+ jit_State *J;
+ void *exptr; /* Pointer to exit state. */
+ const BCIns *pc; /* Restart interpreter at this PC. */
+} ExitDataCP;
+
+/* Need to protect lj_snap_restore because it may throw. */
+static TValue *trace_exit_cp(lua_State *L, lua_CFunction dummy, void *ud)
+{
+ ExitDataCP *exd = (ExitDataCP *)ud;
+ cframe_errfunc(L->cframe) = -1; /* Inherit error function. */
+ exd->pc = lj_snap_restore(exd->J, exd->exptr);
+ UNUSED(dummy);
+ return NULL;
+}
+
+#ifndef LUAJIT_DISABLE_VMEVENT
+/* Push all registers from exit state. */
+static void trace_exit_regs(lua_State *L, ExitState *ex)
+{
+ int32_t i;
+ setintV(L->top++, RID_NUM_GPR);
+ setintV(L->top++, RID_NUM_FPR);
+ for (i = 0; i < RID_NUM_GPR; i++) {
+ if (sizeof(ex->gpr[i]) == sizeof(int32_t))
+ setintV(L->top++, (int32_t)ex->gpr[i]);
+ else
+ setnumV(L->top++, (lua_Number)ex->gpr[i]);
+ }
+#if !LJ_SOFTFP
+ for (i = 0; i < RID_NUM_FPR; i++) {
+ setnumV(L->top, ex->fpr[i]);
+ if (LJ_UNLIKELY(tvisnan(L->top)))
+ setnanV(L->top);
+ L->top++;
+ }
+#endif
+}
+#endif
+
+#ifdef EXITSTATE_PCREG
+/* Determine trace number from pc of exit instruction. */
+static TraceNo trace_exit_find(jit_State *J, MCode *pc)
+{
+ TraceNo traceno;
+ for (traceno = 1; traceno < J->sizetrace; traceno++) {
+ GCtrace *T = traceref(J, traceno);
+ if (T && pc >= T->mcode && pc < (MCode *)((char *)T->mcode + T->szmcode))
+ return traceno;
+ }
+ lua_assert(0);
+ return 0;
+}
+#endif
+
+/* A trace exited. Restore interpreter state. */
+int LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr)
+{
+ ERRNO_SAVE
+ lua_State *L = J->L;
+ ExitState *ex = (ExitState *)exptr;
+ ExitDataCP exd;
+ int errcode;
+ const BCIns *pc;
+ void *cf;
+ GCtrace *T;
+#ifdef EXITSTATE_PCREG
+ J->parent = trace_exit_find(J, (MCode *)(intptr_t)ex->gpr[EXITSTATE_PCREG]);
+#endif
+ T = traceref(J, J->parent); UNUSED(T);
+#ifdef EXITSTATE_CHECKEXIT
+ if (J->exitno == T->nsnap) { /* Treat stack check like a parent exit. */
+ lua_assert(T->root != 0);
+ J->exitno = T->ir[REF_BASE].op2;
+ J->parent = T->ir[REF_BASE].op1;
+ T = traceref(J, J->parent);
+ }
+#endif
+ lua_assert(T != NULL && J->exitno < T->nsnap);
+ exd.J = J;
+ exd.exptr = exptr;
+ errcode = lj_vm_cpcall(L, NULL, &exd, trace_exit_cp);
+ if (errcode)
+ return -errcode; /* Return negated error code. */
+
+ lj_vmevent_send(L, TEXIT,
+ lj_state_checkstack(L, 4+RID_NUM_GPR+RID_NUM_FPR+LUA_MINSTACK);
+ setintV(L->top++, J->parent);
+ setintV(L->top++, J->exitno);
+ trace_exit_regs(L, ex);
+ );
+
+ pc = exd.pc;
+ cf = cframe_raw(L->cframe);
+ setcframe_pc(cf, pc);
+ if (G(L)->gc.state == GCSatomic || G(L)->gc.state == GCSfinalize) {
+ if (!(G(L)->hookmask & HOOK_GC))
+ lj_gc_step(L); /* Exited because of GC: drive GC forward. */
+ } else {
+ trace_hotside(J, pc);
+ }
+ if (bc_op(*pc) == BC_JLOOP) {
+ BCIns *retpc = &traceref(J, bc_d(*pc))->startins;
+ if (bc_isret(bc_op(*retpc))) {
+ if (J->state == LJ_TRACE_RECORD) {
+ J->patchins = *pc;
+ J->patchpc = (BCIns *)pc;
+ *J->patchpc = *retpc;
+ J->bcskip = 1;
+ } else {
+ pc = retpc;
+ setcframe_pc(cf, pc);
+ }
+ }
+ }
+ /* Return MULTRES or 0. */
+ ERRNO_RESTORE
+ switch (bc_op(*pc)) {
+ case BC_CALLM: case BC_CALLMT:
+ return (int)((BCReg)(L->top - L->base) - bc_a(*pc) - bc_c(*pc));
+ case BC_RETM:
+ return (int)((BCReg)(L->top - L->base) + 1 - bc_a(*pc) - bc_d(*pc));
+ case BC_TSETM:
+ return (int)((BCReg)(L->top - L->base) + 1 - bc_a(*pc));
+ default:
+ if (bc_op(*pc) >= BC_FUNCF)
+ return (int)((BCReg)(L->top - L->base) + 1);
+ return 0;
+ }
+}
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_trace.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_trace.h
new file mode 100644
index 0000000..edc7af0
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_trace.h
@@ -0,0 +1,53 @@
+/*
+** Trace management.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_TRACE_H
+#define _LJ_TRACE_H
+
+#include "lj_obj.h"
+
+#if LJ_HASJIT
+#include "lj_jit.h"
+#include "lj_dispatch.h"
+
+/* Trace errors. */
+typedef enum {
+#define TREDEF(name, msg) LJ_TRERR_##name,
+#include "lj_traceerr.h"
+ LJ_TRERR__MAX
+} TraceError;
+
+LJ_FUNC_NORET void lj_trace_err(jit_State *J, TraceError e);
+LJ_FUNC_NORET void lj_trace_err_info(jit_State *J, TraceError e);
+
+/* Trace management. */
+LJ_FUNC void LJ_FASTCALL lj_trace_free(global_State *g, GCtrace *T);
+LJ_FUNC void lj_trace_reenableproto(GCproto *pt);
+LJ_FUNC void lj_trace_flushproto(global_State *g, GCproto *pt);
+LJ_FUNC void lj_trace_flush(jit_State *J, TraceNo traceno);
+LJ_FUNC int lj_trace_flushall(lua_State *L);
+LJ_FUNC void lj_trace_initstate(global_State *g);
+LJ_FUNC void lj_trace_freestate(global_State *g);
+
+/* Event handling. */
+LJ_FUNC void lj_trace_ins(jit_State *J, const BCIns *pc);
+LJ_FUNCA void LJ_FASTCALL lj_trace_hot(jit_State *J, const BCIns *pc);
+LJ_FUNCA int LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr);
+
+/* Signal asynchronous abort of trace or end of trace. */
+#define lj_trace_abort(g) (G2J(g)->state &= ~LJ_TRACE_ACTIVE)
+#define lj_trace_end(J) (J->state = LJ_TRACE_END)
+
+#else
+
+#define lj_trace_flushall(L) (UNUSED(L), 0)
+#define lj_trace_initstate(g) UNUSED(g)
+#define lj_trace_freestate(g) UNUSED(g)
+#define lj_trace_abort(g) UNUSED(g)
+#define lj_trace_end(J) UNUSED(J)
+
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_traceerr.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_traceerr.h
new file mode 100644
index 0000000..f920e5e
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_traceerr.h
@@ -0,0 +1,61 @@
+/*
+** Trace compiler error messages.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/* This file may be included multiple times with different TREDEF macros. */
+
+/* Recording. */
+TREDEF(RECERR, "error thrown or hook called during recording")
+TREDEF(TRACEOV, "trace too long")
+TREDEF(STACKOV, "trace too deep")
+TREDEF(SNAPOV, "too many snapshots")
+TREDEF(BLACKL, "blacklisted")
+TREDEF(NYIBC, "NYI: bytecode %d")
+
+/* Recording loop ops. */
+TREDEF(LLEAVE, "leaving loop in root trace")
+TREDEF(LINNER, "inner loop in root trace")
+TREDEF(LUNROLL, "loop unroll limit reached")
+
+/* Recording calls/returns. */
+TREDEF(BADTYPE, "bad argument type")
+TREDEF(CJITOFF, "JIT compilation disabled for function")
+TREDEF(CUNROLL, "call unroll limit reached")
+TREDEF(DOWNREC, "down-recursion, restarting")
+TREDEF(NYICF, "NYI: C function %s")
+TREDEF(NYIFF, "NYI: FastFunc %s")
+TREDEF(NYIFFU, "NYI: unsupported variant of FastFunc %s")
+TREDEF(NYIRETL, "NYI: return to lower frame")
+
+/* Recording indexed load/store. */
+TREDEF(STORENN, "store with nil or NaN key")
+TREDEF(NOMM, "missing metamethod")
+TREDEF(IDXLOOP, "looping index lookup")
+TREDEF(NYITMIX, "NYI: mixed sparse/dense table")
+
+/* Recording C data operations. */
+TREDEF(NOCACHE, "symbol not in cache")
+TREDEF(NYICONV, "NYI: unsupported C type conversion")
+TREDEF(NYICALL, "NYI: unsupported C function type")
+
+/* Optimizations. */
+TREDEF(GFAIL, "guard would always fail")
+TREDEF(PHIOV, "too many PHIs")
+TREDEF(TYPEINS, "persistent type instability")
+
+/* Assembler. */
+TREDEF(MCODEAL, "failed to allocate mcode memory")
+TREDEF(MCODEOV, "machine code too long")
+TREDEF(MCODELM, "hit mcode limit (retrying)")
+TREDEF(SPILLOV, "too many spill slots")
+TREDEF(BADRA, "inconsistent register allocation")
+TREDEF(NYIIR, "NYI: cannot assemble IR instruction %d")
+TREDEF(NYIPHI, "NYI: PHI shuffling too complex")
+TREDEF(NYICOAL, "NYI: register coalescing too complex")
+
+#undef TREDEF
+
+/* Detecting unused error messages:
+ awk -F, '/^TREDEF/ { gsub(/TREDEF./, ""); printf "grep -q LJ_TRERR_%s *.[ch] || echo %s\n", $1, $1}' lj_traceerr.h | sh
+*/
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_udata.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_udata.c
new file mode 100644
index 0000000..bd0321b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_udata.c
@@ -0,0 +1,34 @@
+/*
+** Userdata handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_udata_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#include "lj_gc.h"
+#include "lj_udata.h"
+
+GCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env)
+{
+ GCudata *ud = lj_mem_newt(L, sizeof(GCudata) + sz, GCudata);
+ global_State *g = G(L);
+ newwhite(g, ud); /* Not finalized. */
+ ud->gct = ~LJ_TUDATA;
+ ud->udtype = UDTYPE_USERDATA;
+ ud->len = sz;
+ /* NOBARRIER: The GCudata is new (marked white). */
+ setgcrefnull(ud->metatable);
+ setgcref(ud->env, obj2gco(env));
+ /* Chain to userdata list (after main thread). */
+ setgcrefr(ud->nextgc, mainthread(g)->nextgc);
+ setgcref(mainthread(g)->nextgc, obj2gco(ud));
+ return ud;
+}
+
+void LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud)
+{
+ lj_mem_free(g, ud, sizeudata(ud));
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_udata.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_udata.h
new file mode 100644
index 0000000..f271a42
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_udata.h
@@ -0,0 +1,14 @@
+/*
+** Userdata handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_UDATA_H
+#define _LJ_UDATA_H
+
+#include "lj_obj.h"
+
+LJ_FUNC GCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env);
+LJ_FUNC void LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_vm.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_vm.h
new file mode 100644
index 0000000..3ffa76b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_vm.h
@@ -0,0 +1,116 @@
+/*
+** Assembler VM interface definitions.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_VM_H
+#define _LJ_VM_H
+
+#include "lj_obj.h"
+
+/* Entry points for ASM parts of VM. */
+LJ_ASMF void lj_vm_call(lua_State *L, TValue *base, int nres1);
+LJ_ASMF int lj_vm_pcall(lua_State *L, TValue *base, int nres1, ptrdiff_t ef);
+typedef TValue *(*lua_CPFunction)(lua_State *L, lua_CFunction func, void *ud);
+LJ_ASMF int lj_vm_cpcall(lua_State *L, lua_CFunction func, void *ud,
+ lua_CPFunction cp);
+LJ_ASMF int lj_vm_resume(lua_State *L, TValue *base, int nres1, ptrdiff_t ef);
+LJ_ASMF_NORET void LJ_FASTCALL lj_vm_unwind_c(void *cframe, int errcode);
+LJ_ASMF_NORET void LJ_FASTCALL lj_vm_unwind_ff(void *cframe);
+LJ_ASMF void lj_vm_unwind_c_eh(void);
+LJ_ASMF void lj_vm_unwind_ff_eh(void);
+#if LJ_TARGET_X86ORX64
+LJ_ASMF void lj_vm_unwind_rethrow(void);
+#endif
+
+/* Miscellaneous functions. */
+#if LJ_TARGET_X86ORX64
+LJ_ASMF int lj_vm_cpuid(uint32_t f, uint32_t res[4]);
+#endif
+#if LJ_TARGET_PPC
+void lj_vm_cachesync(void *start, void *end);
+#endif
+LJ_ASMF double lj_vm_foldarith(double x, double y, int op);
+#if LJ_HASJIT
+LJ_ASMF double lj_vm_foldfpm(double x, int op);
+#endif
+#if !LJ_ARCH_HASFPU
+/* Declared in lj_obj.h: LJ_ASMF int32_t lj_vm_tobit(double x); */
+#endif
+
+/* Dispatch targets for recording and hooks. */
+LJ_ASMF void lj_vm_record(void);
+LJ_ASMF void lj_vm_inshook(void);
+LJ_ASMF void lj_vm_rethook(void);
+LJ_ASMF void lj_vm_callhook(void);
+
+/* Trace exit handling. */
+LJ_ASMF void lj_vm_exit_handler(void);
+LJ_ASMF void lj_vm_exit_interp(void);
+
+/* Internal math helper functions. */
+#if LJ_TARGET_X86ORX64 || LJ_TARGET_PPC
+#define lj_vm_floor floor
+#define lj_vm_ceil ceil
+#else
+LJ_ASMF double lj_vm_floor(double);
+LJ_ASMF double lj_vm_ceil(double);
+#if LJ_TARGET_ARM
+LJ_ASMF double lj_vm_floor_sf(double);
+LJ_ASMF double lj_vm_ceil_sf(double);
+#endif
+#endif
+#if defined(LUAJIT_NO_LOG2) || LJ_TARGET_X86ORX64
+LJ_ASMF double lj_vm_log2(double);
+#else
+#define lj_vm_log2 log2
+#endif
+
+#if LJ_HASJIT
+#if LJ_TARGET_X86ORX64
+LJ_ASMF void lj_vm_floor_sse(void);
+LJ_ASMF void lj_vm_ceil_sse(void);
+LJ_ASMF void lj_vm_trunc_sse(void);
+LJ_ASMF void lj_vm_exp_x87(void);
+LJ_ASMF void lj_vm_exp2_x87(void);
+LJ_ASMF void lj_vm_pow_sse(void);
+LJ_ASMF void lj_vm_powi_sse(void);
+#else
+#if LJ_TARGET_PPC
+#define lj_vm_trunc trunc
+#else
+LJ_ASMF double lj_vm_trunc(double);
+#if LJ_TARGET_ARM
+LJ_ASMF double lj_vm_trunc_sf(double);
+#endif
+#endif
+LJ_ASMF double lj_vm_powi(double, int32_t);
+#ifdef LUAJIT_NO_EXP2
+LJ_ASMF double lj_vm_exp2(double);
+#else
+#define lj_vm_exp2 exp2
+#endif
+#endif
+LJ_ASMF int32_t LJ_FASTCALL lj_vm_modi(int32_t, int32_t);
+#if LJ_HASFFI
+LJ_ASMF int lj_vm_errno(void);
+#endif
+#endif
+
+/* Continuations for metamethods. */
+LJ_ASMF void lj_cont_cat(void); /* Continue with concatenation. */
+LJ_ASMF void lj_cont_ra(void); /* Store result in RA from instruction. */
+LJ_ASMF void lj_cont_nop(void); /* Do nothing, just continue execution. */
+LJ_ASMF void lj_cont_condt(void); /* Branch if result is true. */
+LJ_ASMF void lj_cont_condf(void); /* Branch if result is false. */
+LJ_ASMF void lj_cont_hook(void); /* Continue from hook yield. */
+
+enum { LJ_CONT_TAILCALL, LJ_CONT_FFI_CALLBACK }; /* Special continuations. */
+
+/* Start of the ASM code. */
+LJ_ASMF char lj_vm_asm_begin[];
+
+/* Bytecode offsets are relative to lj_vm_asm_begin. */
+#define makeasmfunc(ofs) ((ASMFunction)(lj_vm_asm_begin + (ofs)))
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_vmevent.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_vmevent.c
new file mode 100644
index 0000000..7b6d7bf
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_vmevent.c
@@ -0,0 +1,57 @@
+/*
+** VM event handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#include <stdio.h>
+
+#define lj_vmevent_c
+#define LUA_CORE
+
+#include "lj_obj.h"
+#include "lj_str.h"
+#include "lj_tab.h"
+#include "lj_state.h"
+#include "lj_dispatch.h"
+#include "lj_vm.h"
+#include "lj_vmevent.h"
+
+ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev)
+{
+ global_State *g = G(L);
+ GCstr *s = lj_str_newlit(L, LJ_VMEVENTS_REGKEY);
+ cTValue *tv = lj_tab_getstr(tabV(registry(L)), s);
+ if (tvistab(tv)) {
+ int hash = VMEVENT_HASH(ev);
+ tv = lj_tab_getint(tabV(tv), hash);
+ if (tv && tvisfunc(tv)) {
+ lj_state_checkstack(L, LUA_MINSTACK);
+ setfuncV(L, L->top++, funcV(tv));
+ return savestack(L, L->top);
+ }
+ }
+ g->vmevmask &= ~VMEVENT_MASK(ev); /* No handler: cache this fact. */
+ return 0;
+}
+
+void lj_vmevent_call(lua_State *L, ptrdiff_t argbase)
+{
+ global_State *g = G(L);
+ uint8_t oldmask = g->vmevmask;
+ uint8_t oldh = hook_save(g);
+ int status;
+ g->vmevmask = 0; /* Disable all events. */
+ hook_vmevent(g);
+ status = lj_vm_pcall(L, restorestack(L, argbase), 0+1, 0);
+ if (LJ_UNLIKELY(status)) {
+ /* Really shouldn't use stderr here, but where else to complain? */
+ L->top--;
+ fputs("VM handler failed: ", stderr);
+ fputs(tvisstr(L->top) ? strVdata(L->top) : "?", stderr);
+ fputc('\n', stderr);
+ }
+ hook_restore(g, oldh);
+ if (g->vmevmask != VMEVENT_NOCACHE)
+ g->vmevmask = oldmask; /* Restore event mask, but not if not modified. */
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_vmevent.h b/src/3rdparty/LuaJIT-2.0.5/src/lj_vmevent.h
new file mode 100644
index 0000000..050fb4d
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_vmevent.h
@@ -0,0 +1,59 @@
+/*
+** VM event handling.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LJ_VMEVENT_H
+#define _LJ_VMEVENT_H
+
+#include "lj_obj.h"
+
+/* Registry key for VM event handler table. */
+#define LJ_VMEVENTS_REGKEY "_VMEVENTS"
+#define LJ_VMEVENTS_HSIZE 4
+
+#define VMEVENT_MASK(ev) ((uint8_t)1 << ((int)(ev) & 7))
+#define VMEVENT_HASH(ev) ((int)(ev) & ~7)
+#define VMEVENT_HASHIDX(h) ((int)(h) << 3)
+#define VMEVENT_NOCACHE 255
+
+#define VMEVENT_DEF(name, hash) \
+ LJ_VMEVENT_##name##_, \
+ LJ_VMEVENT_##name = ((LJ_VMEVENT_##name##_) & 7)|((hash) << 3)
+
+/* VM event IDs. */
+typedef enum {
+ VMEVENT_DEF(BC, 0x00003883),
+ VMEVENT_DEF(TRACE, 0xb2d91467),
+ VMEVENT_DEF(RECORD, 0x9284bf4f),
+ VMEVENT_DEF(TEXIT, 0xb29df2b0),
+ LJ_VMEVENT__MAX
+} VMEvent;
+
+#ifdef LUAJIT_DISABLE_VMEVENT
+#define lj_vmevent_send(L, ev, args) UNUSED(L)
+#define lj_vmevent_send_(L, ev, args, post) UNUSED(L)
+#else
+#define lj_vmevent_send(L, ev, args) \
+ if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \
+ ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \
+ if (argbase) { \
+ args \
+ lj_vmevent_call(L, argbase); \
+ } \
+ }
+#define lj_vmevent_send_(L, ev, args, post) \
+ if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \
+ ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \
+ if (argbase) { \
+ args \
+ lj_vmevent_call(L, argbase); \
+ post \
+ } \
+ }
+
+LJ_FUNC ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev);
+LJ_FUNC void lj_vmevent_call(lua_State *L, ptrdiff_t argbase);
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lj_vmmath.c b/src/3rdparty/LuaJIT-2.0.5/src/lj_vmmath.c
new file mode 100644
index 0000000..73fc667
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lj_vmmath.c
@@ -0,0 +1,140 @@
+/*
+** Math helper functions for assembler VM.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#define lj_vmmath_c
+#define LUA_CORE
+
+#include <errno.h>
+#include <math.h>
+
+#include "lj_obj.h"
+#include "lj_ir.h"
+#include "lj_vm.h"
+
+/* -- Helper functions for generated machine code ------------------------- */
+
+#if LJ_TARGET_X86ORX64
+/* Wrapper functions to avoid linker issues on OSX. */
+LJ_FUNCA double lj_vm_sinh(double x) { return sinh(x); }
+LJ_FUNCA double lj_vm_cosh(double x) { return cosh(x); }
+LJ_FUNCA double lj_vm_tanh(double x) { return tanh(x); }
+#endif
+
+#if !LJ_TARGET_X86ORX64
+double lj_vm_foldarith(double x, double y, int op)
+{
+ switch (op) {
+ case IR_ADD - IR_ADD: return x+y; break;
+ case IR_SUB - IR_ADD: return x-y; break;
+ case IR_MUL - IR_ADD: return x*y; break;
+ case IR_DIV - IR_ADD: return x/y; break;
+ case IR_MOD - IR_ADD: return x-lj_vm_floor(x/y)*y; break;
+ case IR_POW - IR_ADD: return pow(x, y); break;
+ case IR_NEG - IR_ADD: return -x; break;
+ case IR_ABS - IR_ADD: return fabs(x); break;
+#if LJ_HASJIT
+ case IR_ATAN2 - IR_ADD: return atan2(x, y); break;
+ case IR_LDEXP - IR_ADD: return ldexp(x, (int)y); break;
+ case IR_MIN - IR_ADD: return x > y ? y : x; break;
+ case IR_MAX - IR_ADD: return x < y ? y : x; break;
+#endif
+ default: return x;
+ }
+}
+#endif
+
+#if LJ_HASJIT
+
+#ifdef LUAJIT_NO_LOG2
+double lj_vm_log2(double a)
+{
+ return log(a) * 1.4426950408889634074;
+}
+#endif
+
+#ifdef LUAJIT_NO_EXP2
+double lj_vm_exp2(double a)
+{
+ return exp(a * 0.6931471805599453);
+}
+#endif
+
+#if !(LJ_TARGET_ARM || LJ_TARGET_PPC)
+int32_t LJ_FASTCALL lj_vm_modi(int32_t a, int32_t b)
+{
+ uint32_t y, ua, ub;
+ lua_assert(b != 0); /* This must be checked before using this function. */
+ ua = a < 0 ? (uint32_t)-a : (uint32_t)a;
+ ub = b < 0 ? (uint32_t)-b : (uint32_t)b;
+ y = ua % ub;
+ if (y != 0 && (a^b) < 0) y = y - ub;
+ if (((int32_t)y^b) < 0) y = (uint32_t)-(int32_t)y;
+ return (int32_t)y;
+}
+#endif
+
+#if !LJ_TARGET_X86ORX64
+/* Unsigned x^k. */
+static double lj_vm_powui(double x, uint32_t k)
+{
+ double y;
+ lua_assert(k != 0);
+ for (; (k & 1) == 0; k >>= 1) x *= x;
+ y = x;
+ if ((k >>= 1) != 0) {
+ for (;;) {
+ x *= x;
+ if (k == 1) break;
+ if (k & 1) y *= x;
+ k >>= 1;
+ }
+ y *= x;
+ }
+ return y;
+}
+
+/* Signed x^k. */
+double lj_vm_powi(double x, int32_t k)
+{
+ if (k > 1)
+ return lj_vm_powui(x, (uint32_t)k);
+ else if (k == 1)
+ return x;
+ else if (k == 0)
+ return 1.0;
+ else
+ return 1.0 / lj_vm_powui(x, (uint32_t)-k);
+}
+
+/* Computes fpm(x) for extended math functions. */
+double lj_vm_foldfpm(double x, int fpm)
+{
+ switch (fpm) {
+ case IRFPM_FLOOR: return lj_vm_floor(x);
+ case IRFPM_CEIL: return lj_vm_ceil(x);
+ case IRFPM_TRUNC: return lj_vm_trunc(x);
+ case IRFPM_SQRT: return sqrt(x);
+ case IRFPM_EXP: return exp(x);
+ case IRFPM_EXP2: return lj_vm_exp2(x);
+ case IRFPM_LOG: return log(x);
+ case IRFPM_LOG2: return lj_vm_log2(x);
+ case IRFPM_LOG10: return log10(x);
+ case IRFPM_SIN: return sin(x);
+ case IRFPM_COS: return cos(x);
+ case IRFPM_TAN: return tan(x);
+ default: lua_assert(0);
+ }
+ return 0;
+}
+#endif
+
+#if LJ_HASFFI
+int lj_vm_errno(void)
+{
+ return errno;
+}
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/ljamalg.c b/src/3rdparty/LuaJIT-2.0.5/src/ljamalg.c
new file mode 100644
index 0000000..654fe82
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/ljamalg.c
@@ -0,0 +1,93 @@
+/*
+** LuaJIT core and libraries amalgamation.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+/*
++--------------------------------------------------------------------------+
+| WARNING: Compiling the amalgamation needs a lot of virtual memory |
+| (around 300 MB with GCC 4.x)! If you don't have enough physical memory |
+| your machine will start swapping to disk and the compile will not finish |
+| within a reasonable amount of time. |
+| So either compile on a bigger machine or use the non-amalgamated build. |
++--------------------------------------------------------------------------+
+*/
+
+#define ljamalg_c
+#define LUA_CORE
+
+/* To get the mremap prototype. Must be defined before any system includes. */
+#if defined(__linux__) && !defined(_GNU_SOURCE)
+#define _GNU_SOURCE
+#endif
+
+#ifndef WINVER
+#define WINVER 0x0501
+#endif
+
+#include "lua.h"
+#include "lauxlib.h"
+
+#include "lj_gc.c"
+#include "lj_err.c"
+#include "lj_char.c"
+#include "lj_bc.c"
+#include "lj_obj.c"
+#include "lj_str.c"
+#include "lj_tab.c"
+#include "lj_func.c"
+#include "lj_udata.c"
+#include "lj_meta.c"
+#include "lj_debug.c"
+#include "lj_state.c"
+#include "lj_dispatch.c"
+#include "lj_vmevent.c"
+#include "lj_vmmath.c"
+#include "lj_strscan.c"
+#include "lj_api.c"
+#include "lj_lex.c"
+#include "lj_parse.c"
+#include "lj_bcread.c"
+#include "lj_bcwrite.c"
+#include "lj_load.c"
+#include "lj_ctype.c"
+#include "lj_cdata.c"
+#include "lj_cconv.c"
+#include "lj_ccall.c"
+#include "lj_ccallback.c"
+#include "lj_carith.c"
+#include "lj_clib.c"
+#include "lj_cparse.c"
+#include "lj_lib.c"
+#include "lj_ir.c"
+#include "lj_opt_mem.c"
+#include "lj_opt_fold.c"
+#include "lj_opt_narrow.c"
+#include "lj_opt_dce.c"
+#include "lj_opt_loop.c"
+#include "lj_opt_split.c"
+#include "lj_opt_sink.c"
+#include "lj_mcode.c"
+#include "lj_snap.c"
+#include "lj_record.c"
+#include "lj_crecord.c"
+#include "lj_ffrecord.c"
+#include "lj_asm.c"
+#include "lj_trace.c"
+#include "lj_gdbjit.c"
+#include "lj_alloc.c"
+
+#include "lib_aux.c"
+#include "lib_base.c"
+#include "lib_math.c"
+#include "lib_string.c"
+#include "lib_table.c"
+#include "lib_io.c"
+#include "lib_os.c"
+#include "lib_package.c"
+#include "lib_debug.c"
+#include "lib_bit.c"
+#include "lib_jit.c"
+#include "lib_ffi.c"
+#include "lib_init.c"
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lua.h b/src/3rdparty/LuaJIT-2.0.5/src/lua.h
new file mode 100644
index 0000000..c83fd3b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lua.h
@@ -0,0 +1,393 @@
+/*
+** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $
+** Lua - An Extensible Extension Language
+** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
+** See Copyright Notice at the end of this file
+*/
+
+
+#ifndef lua_h
+#define lua_h
+
+#include <stdarg.h>
+#include <stddef.h>
+
+
+#include "luaconf.h"
+
+
+#define LUA_VERSION "Lua 5.1"
+#define LUA_RELEASE "Lua 5.1.4"
+#define LUA_VERSION_NUM 501
+#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio"
+#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
+
+
+/* mark for precompiled code (`<esc>Lua') */
+#define LUA_SIGNATURE "\033Lua"
+
+/* option for multiple returns in `lua_pcall' and `lua_call' */
+#define LUA_MULTRET (-1)
+
+
+/*
+** pseudo-indices
+*/
+#define LUA_REGISTRYINDEX (-10000)
+#define LUA_ENVIRONINDEX (-10001)
+#define LUA_GLOBALSINDEX (-10002)
+#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i))
+
+
+/* thread status; 0 is OK */
+#define LUA_YIELD 1
+#define LUA_ERRRUN 2
+#define LUA_ERRSYNTAX 3
+#define LUA_ERRMEM 4
+#define LUA_ERRERR 5
+
+
+typedef struct lua_State lua_State;
+
+typedef int (*lua_CFunction) (lua_State *L);
+
+
+/*
+** functions that read/write blocks when loading/dumping Lua chunks
+*/
+typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
+
+typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);
+
+
+/*
+** prototype for memory-allocation functions
+*/
+typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
+
+
+/*
+** basic types
+*/
+#define LUA_TNONE (-1)
+
+#define LUA_TNIL 0
+#define LUA_TBOOLEAN 1
+#define LUA_TLIGHTUSERDATA 2
+#define LUA_TNUMBER 3
+#define LUA_TSTRING 4
+#define LUA_TTABLE 5
+#define LUA_TFUNCTION 6
+#define LUA_TUSERDATA 7
+#define LUA_TTHREAD 8
+
+
+
+/* minimum Lua stack available to a C function */
+#define LUA_MINSTACK 20
+
+
+/*
+** generic extra include file
+*/
+#if defined(LUA_USER_H)
+#include LUA_USER_H
+#endif
+
+
+/* type of numbers in Lua */
+typedef LUA_NUMBER lua_Number;
+
+
+/* type for integer functions */
+typedef LUA_INTEGER lua_Integer;
+
+
+
+/*
+** state manipulation
+*/
+LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
+LUA_API void (lua_close) (lua_State *L);
+LUA_API lua_State *(lua_newthread) (lua_State *L);
+
+LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
+
+
+/*
+** basic stack manipulation
+*/
+LUA_API int (lua_gettop) (lua_State *L);
+LUA_API void (lua_settop) (lua_State *L, int idx);
+LUA_API void (lua_pushvalue) (lua_State *L, int idx);
+LUA_API void (lua_remove) (lua_State *L, int idx);
+LUA_API void (lua_insert) (lua_State *L, int idx);
+LUA_API void (lua_replace) (lua_State *L, int idx);
+LUA_API int (lua_checkstack) (lua_State *L, int sz);
+
+LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
+
+
+/*
+** access functions (stack -> C)
+*/
+
+LUA_API int (lua_isnumber) (lua_State *L, int idx);
+LUA_API int (lua_isstring) (lua_State *L, int idx);
+LUA_API int (lua_iscfunction) (lua_State *L, int idx);
+LUA_API int (lua_isuserdata) (lua_State *L, int idx);
+LUA_API int (lua_type) (lua_State *L, int idx);
+LUA_API const char *(lua_typename) (lua_State *L, int tp);
+
+LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2);
+LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
+LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2);
+
+LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx);
+LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx);
+LUA_API int (lua_toboolean) (lua_State *L, int idx);
+LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
+LUA_API size_t (lua_objlen) (lua_State *L, int idx);
+LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
+LUA_API void *(lua_touserdata) (lua_State *L, int idx);
+LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
+LUA_API const void *(lua_topointer) (lua_State *L, int idx);
+
+
+/*
+** push functions (C -> stack)
+*/
+LUA_API void (lua_pushnil) (lua_State *L);
+LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
+LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
+LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l);
+LUA_API void (lua_pushstring) (lua_State *L, const char *s);
+LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
+ va_list argp);
+LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
+LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
+LUA_API void (lua_pushboolean) (lua_State *L, int b);
+LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
+LUA_API int (lua_pushthread) (lua_State *L);
+
+
+/*
+** get functions (Lua -> stack)
+*/
+LUA_API void (lua_gettable) (lua_State *L, int idx);
+LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k);
+LUA_API void (lua_rawget) (lua_State *L, int idx);
+LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n);
+LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
+LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
+LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
+LUA_API void (lua_getfenv) (lua_State *L, int idx);
+
+
+/*
+** set functions (stack -> Lua)
+*/
+LUA_API void (lua_settable) (lua_State *L, int idx);
+LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
+LUA_API void (lua_rawset) (lua_State *L, int idx);
+LUA_API void (lua_rawseti) (lua_State *L, int idx, int n);
+LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
+LUA_API int (lua_setfenv) (lua_State *L, int idx);
+
+
+/*
+** `load' and `call' functions (load and run Lua code)
+*/
+LUA_API void (lua_call) (lua_State *L, int nargs, int nresults);
+LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
+LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);
+LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
+ const char *chunkname);
+
+LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
+
+
+/*
+** coroutine functions
+*/
+LUA_API int (lua_yield) (lua_State *L, int nresults);
+LUA_API int (lua_resume) (lua_State *L, int narg);
+LUA_API int (lua_status) (lua_State *L);
+
+/*
+** garbage-collection function and options
+*/
+
+#define LUA_GCSTOP 0
+#define LUA_GCRESTART 1
+#define LUA_GCCOLLECT 2
+#define LUA_GCCOUNT 3
+#define LUA_GCCOUNTB 4
+#define LUA_GCSTEP 5
+#define LUA_GCSETPAUSE 6
+#define LUA_GCSETSTEPMUL 7
+
+LUA_API int (lua_gc) (lua_State *L, int what, int data);
+
+
+/*
+** miscellaneous functions
+*/
+
+LUA_API int (lua_error) (lua_State *L);
+
+LUA_API int (lua_next) (lua_State *L, int idx);
+
+LUA_API void (lua_concat) (lua_State *L, int n);
+
+LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
+LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
+
+
+
+/*
+** ===============================================================
+** some useful macros
+** ===============================================================
+*/
+
+#define lua_pop(L,n) lua_settop(L, -(n)-1)
+
+#define lua_newtable(L) lua_createtable(L, 0, 0)
+
+#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
+
+#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
+
+#define lua_strlen(L,i) lua_objlen(L, (i))
+
+#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
+#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
+#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
+#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
+#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
+#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
+#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
+#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
+
+#define lua_pushliteral(L, s) \
+ lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
+
+#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s))
+#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s))
+
+#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
+
+
+
+/*
+** compatibility macros and functions
+*/
+
+#define lua_open() luaL_newstate()
+
+#define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX)
+
+#define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0)
+
+#define lua_Chunkreader lua_Reader
+#define lua_Chunkwriter lua_Writer
+
+
+/* hack */
+LUA_API void lua_setlevel (lua_State *from, lua_State *to);
+
+
+/*
+** {======================================================================
+** Debug API
+** =======================================================================
+*/
+
+
+/*
+** Event codes
+*/
+#define LUA_HOOKCALL 0
+#define LUA_HOOKRET 1
+#define LUA_HOOKLINE 2
+#define LUA_HOOKCOUNT 3
+#define LUA_HOOKTAILRET 4
+
+
+/*
+** Event masks
+*/
+#define LUA_MASKCALL (1 << LUA_HOOKCALL)
+#define LUA_MASKRET (1 << LUA_HOOKRET)
+#define LUA_MASKLINE (1 << LUA_HOOKLINE)
+#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
+
+typedef struct lua_Debug lua_Debug; /* activation record */
+
+
+/* Functions to be called by the debuger in specific events */
+typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
+
+
+LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);
+LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
+LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
+LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
+LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);
+LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);
+LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
+LUA_API lua_Hook lua_gethook (lua_State *L);
+LUA_API int lua_gethookmask (lua_State *L);
+LUA_API int lua_gethookcount (lua_State *L);
+
+/* From Lua 5.2. */
+LUA_API void *lua_upvalueid (lua_State *L, int idx, int n);
+LUA_API void lua_upvaluejoin (lua_State *L, int idx1, int n1, int idx2, int n2);
+LUA_API int lua_loadx (lua_State *L, lua_Reader reader, void *dt,
+ const char *chunkname, const char *mode);
+
+
+struct lua_Debug {
+ int event;
+ const char *name; /* (n) */
+ const char *namewhat; /* (n) `global', `local', `field', `method' */
+ const char *what; /* (S) `Lua', `C', `main', `tail' */
+ const char *source; /* (S) */
+ int currentline; /* (l) */
+ int nups; /* (u) number of upvalues */
+ int linedefined; /* (S) */
+ int lastlinedefined; /* (S) */
+ char short_src[LUA_IDSIZE]; /* (S) */
+ /* private part */
+ int i_ci; /* active function */
+};
+
+/* }====================================================================== */
+
+
+/******************************************************************************
+* Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining
+* a copy of this software and associated documentation files (the
+* "Software"), to deal in the Software without restriction, including
+* without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to
+* permit persons to whom the Software is furnished to do so, subject to
+* the following conditions:
+*
+* The above copyright notice and this permission notice shall be
+* included in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+******************************************************************************/
+
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lua.hpp b/src/3rdparty/LuaJIT-2.0.5/src/lua.hpp
new file mode 100644
index 0000000..07e9002
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lua.hpp
@@ -0,0 +1,9 @@
+// C++ wrapper for LuaJIT header files.
+
+extern "C" {
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+#include "luajit.h"
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lua51.dll b/src/3rdparty/LuaJIT-2.0.5/src/lua51.dll
new file mode 100644
index 0000000..c9edadf
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lua51.dll
Binary files differ
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lua51.lib b/src/3rdparty/LuaJIT-2.0.5/src/lua51.lib
new file mode 100644
index 0000000..36f6e7c
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lua51.lib
Binary files differ
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/luaconf.h b/src/3rdparty/LuaJIT-2.0.5/src/luaconf.h
new file mode 100644
index 0000000..b33e91b
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/luaconf.h
@@ -0,0 +1,156 @@
+/*
+** Configuration header.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef luaconf_h
+#define luaconf_h
+
+#ifndef WINVER
+#define WINVER 0x0501
+#endif
+#include <limits.h>
+#include <stddef.h>
+
+/* Default path for loading Lua and C modules with require(). */
+#if defined(_WIN32)
+/*
+** In Windows, any exclamation mark ('!') in the path is replaced by the
+** path of the directory of the executable file of the current process.
+*/
+#define LUA_LDIR "!\\lua\\"
+#define LUA_CDIR "!\\"
+#define LUA_PATH_DEFAULT \
+ ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;"
+#define LUA_CPATH_DEFAULT \
+ ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
+#else
+/*
+** Note to distribution maintainers: do NOT patch the following lines!
+** Please read ../doc/install.html#distro and pass PREFIX=/usr instead.
+*/
+#ifndef LUA_MULTILIB
+#define LUA_MULTILIB "lib"
+#endif
+#ifndef LUA_LMULTILIB
+#define LUA_LMULTILIB "lib"
+#endif
+#define LUA_LROOT "/usr/local"
+#define LUA_LUADIR "/lua/5.1/"
+#define LUA_LJDIR "/luajit-2.0.5/"
+
+#ifdef LUA_ROOT
+#define LUA_JROOT LUA_ROOT
+#define LUA_RLDIR LUA_ROOT "/share" LUA_LUADIR
+#define LUA_RCDIR LUA_ROOT "/" LUA_MULTILIB LUA_LUADIR
+#define LUA_RLPATH ";" LUA_RLDIR "?.lua;" LUA_RLDIR "?/init.lua"
+#define LUA_RCPATH ";" LUA_RCDIR "?.so"
+#else
+#define LUA_JROOT LUA_LROOT
+#define LUA_RLPATH
+#define LUA_RCPATH
+#endif
+
+#define LUA_JPATH ";" LUA_JROOT "/share" LUA_LJDIR "?.lua"
+#define LUA_LLDIR LUA_LROOT "/share" LUA_LUADIR
+#define LUA_LCDIR LUA_LROOT "/" LUA_LMULTILIB LUA_LUADIR
+#define LUA_LLPATH ";" LUA_LLDIR "?.lua;" LUA_LLDIR "?/init.lua"
+#define LUA_LCPATH1 ";" LUA_LCDIR "?.so"
+#define LUA_LCPATH2 ";" LUA_LCDIR "loadall.so"
+
+#define LUA_PATH_DEFAULT "./?.lua" LUA_JPATH LUA_LLPATH LUA_RLPATH
+#define LUA_CPATH_DEFAULT "./?.so" LUA_LCPATH1 LUA_RCPATH LUA_LCPATH2
+#endif
+
+/* Environment variable names for path overrides and initialization code. */
+#define LUA_PATH "LUA_PATH"
+#define LUA_CPATH "LUA_CPATH"
+#define LUA_INIT "LUA_INIT"
+
+/* Special file system characters. */
+#if defined(_WIN32)
+#define LUA_DIRSEP "\\"
+#else
+#define LUA_DIRSEP "/"
+#endif
+#define LUA_PATHSEP ";"
+#define LUA_PATH_MARK "?"
+#define LUA_EXECDIR "!"
+#define LUA_IGMARK "-"
+#define LUA_PATH_CONFIG \
+ LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" \
+ LUA_EXECDIR "\n" LUA_IGMARK
+
+/* Quoting in error messages. */
+#define LUA_QL(x) "'" x "'"
+#define LUA_QS LUA_QL("%s")
+
+/* Various tunables. */
+#define LUAI_MAXSTACK 65500 /* Max. # of stack slots for a thread (<64K). */
+#define LUAI_MAXCSTACK 8000 /* Max. # of stack slots for a C func (<10K). */
+#define LUAI_GCPAUSE 200 /* Pause GC until memory is at 200%. */
+#define LUAI_GCMUL 200 /* Run GC at 200% of allocation speed. */
+#define LUA_MAXCAPTURES 32 /* Max. pattern captures. */
+
+/* Compatibility with older library function names. */
+#define LUA_COMPAT_MOD /* OLD: math.mod, NEW: math.fmod */
+#define LUA_COMPAT_GFIND /* OLD: string.gfind, NEW: string.gmatch */
+
+/* Configuration for the frontend (the luajit executable). */
+#if defined(luajit_c)
+#define LUA_PROGNAME "luajit" /* Fallback frontend name. */
+#define LUA_PROMPT "> " /* Interactive prompt. */
+#define LUA_PROMPT2 ">> " /* Continuation prompt. */
+#define LUA_MAXINPUT 512 /* Max. input line length. */
+#endif
+
+/* Note: changing the following defines breaks the Lua 5.1 ABI. */
+#define LUA_INTEGER ptrdiff_t
+#define LUA_IDSIZE 60 /* Size of lua_Debug.short_src. */
+/*
+** Size of lauxlib and io.* on-stack buffers. Weird workaround to avoid using
+** unreasonable amounts of stack space, but still retain ABI compatibility.
+** Blame Lua for depending on BUFSIZ in the ABI, blame **** for wrecking it.
+*/
+#define LUAL_BUFFERSIZE (BUFSIZ > 16384 ? 8192 : BUFSIZ)
+
+/* The following defines are here only for compatibility with luaconf.h
+** from the standard Lua distribution. They must not be changed for LuaJIT.
+*/
+#define LUA_NUMBER_DOUBLE
+#define LUA_NUMBER double
+#define LUAI_UACNUMBER double
+#define LUA_NUMBER_SCAN "%lf"
+#define LUA_NUMBER_FMT "%.14g"
+#define lua_number2str(s, n) sprintf((s), LUA_NUMBER_FMT, (n))
+#define LUAI_MAXNUMBER2STR 32
+#define LUA_INTFRMLEN "l"
+#define LUA_INTFRM_T long
+
+/* Linkage of public API functions. */
+#if defined(LUA_BUILD_AS_DLL)
+#if defined(LUA_CORE) || defined(LUA_LIB)
+#define LUA_API __declspec(dllexport)
+#else
+#define LUA_API __declspec(dllimport)
+#endif
+#else
+#define LUA_API extern
+#endif
+
+#define LUALIB_API LUA_API
+
+/* Support for internal assertions. */
+#if defined(LUA_USE_ASSERT) || defined(LUA_USE_APICHECK)
+#include <assert.h>
+#endif
+#ifdef LUA_USE_ASSERT
+#define lua_assert(x) assert(x)
+#endif
+#ifdef LUA_USE_APICHECK
+#define luai_apicheck(L, o) { (void)L; assert(o); }
+#else
+#define luai_apicheck(L, o) { (void)L; }
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/luajit.c b/src/3rdparty/LuaJIT-2.0.5/src/luajit.c
new file mode 100644
index 0000000..9ede59c
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/luajit.c
@@ -0,0 +1,573 @@
+/*
+** LuaJIT frontend. Runs commands, scripts, read-eval-print (REPL) etc.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+**
+** Major portions taken verbatim or adapted from the Lua interpreter.
+** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define luajit_c
+
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+#include "luajit.h"
+
+#include "lj_arch.h"
+
+#if LJ_TARGET_POSIX
+#include <unistd.h>
+#define lua_stdin_is_tty() isatty(0)
+#elif LJ_TARGET_WINDOWS
+#include <io.h>
+#ifdef __BORLANDC__
+#define lua_stdin_is_tty() isatty(_fileno(stdin))
+#else
+#define lua_stdin_is_tty() _isatty(_fileno(stdin))
+#endif
+#else
+#define lua_stdin_is_tty() 1
+#endif
+
+#if !LJ_TARGET_CONSOLE
+#include <signal.h>
+#endif
+
+static lua_State *globalL = NULL;
+static const char *progname = LUA_PROGNAME;
+
+#if !LJ_TARGET_CONSOLE
+static void lstop(lua_State *L, lua_Debug *ar)
+{
+ (void)ar; /* unused arg. */
+ lua_sethook(L, NULL, 0, 0);
+ /* Avoid luaL_error -- a C hook doesn't add an extra frame. */
+ luaL_where(L, 0);
+ lua_pushfstring(L, "%sinterrupted!", lua_tostring(L, -1));
+ lua_error(L);
+}
+
+static void laction(int i)
+{
+ signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
+ terminate process (default action) */
+ lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
+}
+#endif
+
+static void print_usage(void)
+{
+ fprintf(stderr,
+ "usage: %s [options]... [script [args]...].\n"
+ "Available options are:\n"
+ " -e chunk Execute string " LUA_QL("chunk") ".\n"
+ " -l name Require library " LUA_QL("name") ".\n"
+ " -b ... Save or list bytecode.\n"
+ " -j cmd Perform LuaJIT control command.\n"
+ " -O[opt] Control LuaJIT optimizations.\n"
+ " -i Enter interactive mode after executing " LUA_QL("script") ".\n"
+ " -v Show version information.\n"
+ " -E Ignore environment variables.\n"
+ " -- Stop handling options.\n"
+ " - Execute stdin and stop handling options.\n"
+ ,
+ progname);
+ fflush(stderr);
+}
+
+static void l_message(const char *pname, const char *msg)
+{
+ if (pname) fprintf(stderr, "%s: ", pname);
+ fprintf(stderr, "%s\n", msg);
+ fflush(stderr);
+}
+
+static int report(lua_State *L, int status)
+{
+ if (status && !lua_isnil(L, -1)) {
+ const char *msg = lua_tostring(L, -1);
+ if (msg == NULL) msg = "(error object is not a string)";
+ l_message(progname, msg);
+ lua_pop(L, 1);
+ }
+ return status;
+}
+
+static int traceback(lua_State *L)
+{
+ if (!lua_isstring(L, 1)) { /* Non-string error object? Try metamethod. */
+ if (lua_isnoneornil(L, 1) ||
+ !luaL_callmeta(L, 1, "__tostring") ||
+ !lua_isstring(L, -1))
+ return 1; /* Return non-string error object. */
+ lua_remove(L, 1); /* Replace object by result of __tostring metamethod. */
+ }
+ luaL_traceback(L, L, lua_tostring(L, 1), 1);
+ return 1;
+}
+
+static int docall(lua_State *L, int narg, int clear)
+{
+ int status;
+ int base = lua_gettop(L) - narg; /* function index */
+ lua_pushcfunction(L, traceback); /* push traceback function */
+ lua_insert(L, base); /* put it under chunk and args */
+#if !LJ_TARGET_CONSOLE
+ signal(SIGINT, laction);
+#endif
+ status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
+#if !LJ_TARGET_CONSOLE
+ signal(SIGINT, SIG_DFL);
+#endif
+ lua_remove(L, base); /* remove traceback function */
+ /* force a complete garbage collection in case of errors */
+ if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);
+ return status;
+}
+
+static void print_version(void)
+{
+ fputs(LUAJIT_VERSION " -- " LUAJIT_COPYRIGHT ". " LUAJIT_URL "\n", stdout);
+}
+
+static void print_jit_status(lua_State *L)
+{
+ int n;
+ const char *s;
+ lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
+ lua_getfield(L, -1, "jit"); /* Get jit.* module table. */
+ lua_remove(L, -2);
+ lua_getfield(L, -1, "status");
+ lua_remove(L, -2);
+ n = lua_gettop(L);
+ lua_call(L, 0, LUA_MULTRET);
+ fputs(lua_toboolean(L, n) ? "JIT: ON" : "JIT: OFF", stdout);
+ for (n++; (s = lua_tostring(L, n)); n++) {
+ putc(' ', stdout);
+ fputs(s, stdout);
+ }
+ putc('\n', stdout);
+ lua_settop(L, 0); /* clear stack */
+}
+
+static int getargs(lua_State *L, char **argv, int n)
+{
+ int narg;
+ int i;
+ int argc = 0;
+ while (argv[argc]) argc++; /* count total number of arguments */
+ narg = argc - (n + 1); /* number of arguments to the script */
+ luaL_checkstack(L, narg + 3, "too many arguments to script");
+ for (i = n+1; i < argc; i++)
+ lua_pushstring(L, argv[i]);
+ lua_createtable(L, narg, n + 1);
+ for (i = 0; i < argc; i++) {
+ lua_pushstring(L, argv[i]);
+ lua_rawseti(L, -2, i - n);
+ }
+ return narg;
+}
+
+static int dofile(lua_State *L, const char *name)
+{
+ int status = luaL_loadfile(L, name) || docall(L, 0, 1);
+ return report(L, status);
+}
+
+static int dostring(lua_State *L, const char *s, const char *name)
+{
+ int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1);
+ return report(L, status);
+}
+
+static int dolibrary(lua_State *L, const char *name)
+{
+ lua_getglobal(L, "require");
+ lua_pushstring(L, name);
+ return report(L, docall(L, 1, 1));
+}
+
+static void write_prompt(lua_State *L, int firstline)
+{
+ const char *p;
+ lua_getfield(L, LUA_GLOBALSINDEX, firstline ? "_PROMPT" : "_PROMPT2");
+ p = lua_tostring(L, -1);
+ if (p == NULL) p = firstline ? LUA_PROMPT : LUA_PROMPT2;
+ fputs(p, stdout);
+ fflush(stdout);
+ lua_pop(L, 1); /* remove global */
+}
+
+static int incomplete(lua_State *L, int status)
+{
+ if (status == LUA_ERRSYNTAX) {
+ size_t lmsg;
+ const char *msg = lua_tolstring(L, -1, &lmsg);
+ const char *tp = msg + lmsg - (sizeof(LUA_QL("<eof>")) - 1);
+ if (strstr(msg, LUA_QL("<eof>")) == tp) {
+ lua_pop(L, 1);
+ return 1;
+ }
+ }
+ return 0; /* else... */
+}
+
+static int pushline(lua_State *L, int firstline)
+{
+ char buf[LUA_MAXINPUT];
+ write_prompt(L, firstline);
+ if (fgets(buf, LUA_MAXINPUT, stdin)) {
+ size_t len = strlen(buf);
+ if (len > 0 && buf[len-1] == '\n')
+ buf[len-1] = '\0';
+ if (firstline && buf[0] == '=')
+ lua_pushfstring(L, "return %s", buf+1);
+ else
+ lua_pushstring(L, buf);
+ return 1;
+ }
+ return 0;
+}
+
+static int loadline(lua_State *L)
+{
+ int status;
+ lua_settop(L, 0);
+ if (!pushline(L, 1))
+ return -1; /* no input */
+ for (;;) { /* repeat until gets a complete line */
+ status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin");
+ if (!incomplete(L, status)) break; /* cannot try to add lines? */
+ if (!pushline(L, 0)) /* no more input? */
+ return -1;
+ lua_pushliteral(L, "\n"); /* add a new line... */
+ lua_insert(L, -2); /* ...between the two lines */
+ lua_concat(L, 3); /* join them */
+ }
+ lua_remove(L, 1); /* remove line */
+ return status;
+}
+
+static void dotty(lua_State *L)
+{
+ int status;
+ const char *oldprogname = progname;
+ progname = NULL;
+ while ((status = loadline(L)) != -1) {
+ if (status == 0) status = docall(L, 0, 0);
+ report(L, status);
+ if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
+ lua_getglobal(L, "print");
+ lua_insert(L, 1);
+ if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
+ l_message(progname,
+ lua_pushfstring(L, "error calling " LUA_QL("print") " (%s)",
+ lua_tostring(L, -1)));
+ }
+ }
+ lua_settop(L, 0); /* clear stack */
+ fputs("\n", stdout);
+ fflush(stdout);
+ progname = oldprogname;
+}
+
+static int handle_script(lua_State *L, char **argv, int n)
+{
+ int status;
+ const char *fname;
+ int narg = getargs(L, argv, n); /* collect arguments */
+ lua_setglobal(L, "arg");
+ fname = argv[n];
+ if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0)
+ fname = NULL; /* stdin */
+ status = luaL_loadfile(L, fname);
+ lua_insert(L, -(narg+1));
+ if (status == 0)
+ status = docall(L, narg, 0);
+ else
+ lua_pop(L, narg);
+ return report(L, status);
+}
+
+/* Load add-on module. */
+static int loadjitmodule(lua_State *L)
+{
+ lua_getglobal(L, "require");
+ lua_pushliteral(L, "jit.");
+ lua_pushvalue(L, -3);
+ lua_concat(L, 2);
+ if (lua_pcall(L, 1, 1, 0)) {
+ const char *msg = lua_tostring(L, -1);
+ if (msg && !strncmp(msg, "module ", 7))
+ goto nomodule;
+ return report(L, 1);
+ }
+ lua_getfield(L, -1, "start");
+ if (lua_isnil(L, -1)) {
+ nomodule:
+ l_message(progname,
+ "unknown luaJIT command or jit.* modules not installed");
+ return 1;
+ }
+ lua_remove(L, -2); /* Drop module table. */
+ return 0;
+}
+
+/* Run command with options. */
+static int runcmdopt(lua_State *L, const char *opt)
+{
+ int narg = 0;
+ if (opt && *opt) {
+ for (;;) { /* Split arguments. */
+ const char *p = strchr(opt, ',');
+ narg++;
+ if (!p) break;
+ if (p == opt)
+ lua_pushnil(L);
+ else
+ lua_pushlstring(L, opt, (size_t)(p - opt));
+ opt = p + 1;
+ }
+ if (*opt)
+ lua_pushstring(L, opt);
+ else
+ lua_pushnil(L);
+ }
+ return report(L, lua_pcall(L, narg, 0, 0));
+}
+
+/* JIT engine control command: try jit library first or load add-on module. */
+static int dojitcmd(lua_State *L, const char *cmd)
+{
+ const char *opt = strchr(cmd, '=');
+ lua_pushlstring(L, cmd, opt ? (size_t)(opt - cmd) : strlen(cmd));
+ lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
+ lua_getfield(L, -1, "jit"); /* Get jit.* module table. */
+ lua_remove(L, -2);
+ lua_pushvalue(L, -2);
+ lua_gettable(L, -2); /* Lookup library function. */
+ if (!lua_isfunction(L, -1)) {
+ lua_pop(L, 2); /* Drop non-function and jit.* table, keep module name. */
+ if (loadjitmodule(L))
+ return 1;
+ } else {
+ lua_remove(L, -2); /* Drop jit.* table. */
+ }
+ lua_remove(L, -2); /* Drop module name. */
+ return runcmdopt(L, opt ? opt+1 : opt);
+}
+
+/* Optimization flags. */
+static int dojitopt(lua_State *L, const char *opt)
+{
+ lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
+ lua_getfield(L, -1, "jit.opt"); /* Get jit.opt.* module table. */
+ lua_remove(L, -2);
+ lua_getfield(L, -1, "start");
+ lua_remove(L, -2);
+ return runcmdopt(L, opt);
+}
+
+/* Save or list bytecode. */
+static int dobytecode(lua_State *L, char **argv)
+{
+ int narg = 0;
+ lua_pushliteral(L, "bcsave");
+ if (loadjitmodule(L))
+ return 1;
+ if (argv[0][2]) {
+ narg++;
+ argv[0][1] = '-';
+ lua_pushstring(L, argv[0]+1);
+ }
+ for (argv++; *argv != NULL; narg++, argv++)
+ lua_pushstring(L, *argv);
+ return report(L, lua_pcall(L, narg, 0, 0));
+}
+
+/* check that argument has no extra characters at the end */
+#define notail(x) {if ((x)[2] != '\0') return -1;}
+
+#define FLAGS_INTERACTIVE 1
+#define FLAGS_VERSION 2
+#define FLAGS_EXEC 4
+#define FLAGS_OPTION 8
+#define FLAGS_NOENV 16
+
+static int collectargs(char **argv, int *flags)
+{
+ int i;
+ for (i = 1; argv[i] != NULL; i++) {
+ if (argv[i][0] != '-') /* Not an option? */
+ return i;
+ switch (argv[i][1]) { /* Check option. */
+ case '-':
+ notail(argv[i]);
+ return (argv[i+1] != NULL ? i+1 : 0);
+ case '\0':
+ return i;
+ case 'i':
+ notail(argv[i]);
+ *flags |= FLAGS_INTERACTIVE;
+ /* fallthrough */
+ case 'v':
+ notail(argv[i]);
+ *flags |= FLAGS_VERSION;
+ break;
+ case 'e':
+ *flags |= FLAGS_EXEC;
+ /* fallthrough */
+ case 'j': /* LuaJIT extension */
+ case 'l':
+ *flags |= FLAGS_OPTION;
+ if (argv[i][2] == '\0') {
+ i++;
+ if (argv[i] == NULL) return -1;
+ }
+ break;
+ case 'O': break; /* LuaJIT extension */
+ case 'b': /* LuaJIT extension */
+ if (*flags) return -1;
+ *flags |= FLAGS_EXEC;
+ return 0;
+ case 'E':
+ *flags |= FLAGS_NOENV;
+ break;
+ default: return -1; /* invalid option */
+ }
+ }
+ return 0;
+}
+
+static int runargs(lua_State *L, char **argv, int n)
+{
+ int i;
+ for (i = 1; i < n; i++) {
+ if (argv[i] == NULL) continue;
+ lua_assert(argv[i][0] == '-');
+ switch (argv[i][1]) { /* option */
+ case 'e': {
+ const char *chunk = argv[i] + 2;
+ if (*chunk == '\0') chunk = argv[++i];
+ lua_assert(chunk != NULL);
+ if (dostring(L, chunk, "=(command line)") != 0)
+ return 1;
+ break;
+ }
+ case 'l': {
+ const char *filename = argv[i] + 2;
+ if (*filename == '\0') filename = argv[++i];
+ lua_assert(filename != NULL);
+ if (dolibrary(L, filename))
+ return 1; /* stop if file fails */
+ break;
+ }
+ case 'j': { /* LuaJIT extension */
+ const char *cmd = argv[i] + 2;
+ if (*cmd == '\0') cmd = argv[++i];
+ lua_assert(cmd != NULL);
+ if (dojitcmd(L, cmd))
+ return 1;
+ break;
+ }
+ case 'O': /* LuaJIT extension */
+ if (dojitopt(L, argv[i] + 2))
+ return 1;
+ break;
+ case 'b': /* LuaJIT extension */
+ return dobytecode(L, argv+i);
+ default: break;
+ }
+ }
+ return 0;
+}
+
+static int handle_luainit(lua_State *L)
+{
+#if LJ_TARGET_CONSOLE
+ const char *init = NULL;
+#else
+ const char *init = getenv(LUA_INIT);
+#endif
+ if (init == NULL)
+ return 0; /* status OK */
+ else if (init[0] == '@')
+ return dofile(L, init+1);
+ else
+ return dostring(L, init, "=" LUA_INIT);
+}
+
+static struct Smain {
+ char **argv;
+ int argc;
+ int status;
+} smain;
+
+static int pmain(lua_State *L)
+{
+ struct Smain *s = &smain;
+ char **argv = s->argv;
+ int script;
+ int flags = 0;
+ globalL = L;
+ if (argv[0] && argv[0][0]) progname = argv[0];
+ LUAJIT_VERSION_SYM(); /* linker-enforced version check */
+ script = collectargs(argv, &flags);
+ if (script < 0) { /* invalid args? */
+ print_usage();
+ s->status = 1;
+ return 0;
+ }
+ if ((flags & FLAGS_NOENV)) {
+ lua_pushboolean(L, 1);
+ lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
+ }
+ lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
+ luaL_openlibs(L); /* open libraries */
+ lua_gc(L, LUA_GCRESTART, -1);
+ if (!(flags & FLAGS_NOENV)) {
+ s->status = handle_luainit(L);
+ if (s->status != 0) return 0;
+ }
+ if ((flags & FLAGS_VERSION)) print_version();
+ s->status = runargs(L, argv, (script > 0) ? script : s->argc);
+ if (s->status != 0) return 0;
+ if (script) {
+ s->status = handle_script(L, argv, script);
+ if (s->status != 0) return 0;
+ }
+ if ((flags & FLAGS_INTERACTIVE)) {
+ print_jit_status(L);
+ dotty(L);
+ } else if (script == 0 && !(flags & (FLAGS_EXEC|FLAGS_VERSION))) {
+ if (lua_stdin_is_tty()) {
+ print_version();
+ print_jit_status(L);
+ dotty(L);
+ } else {
+ dofile(L, NULL); /* executes stdin as a file */
+ }
+ }
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ int status;
+ lua_State *L = lua_open(); /* create state */
+ if (L == NULL) {
+ l_message(argv[0], "cannot create state: not enough memory");
+ return EXIT_FAILURE;
+ }
+ smain.argc = argc;
+ smain.argv = argv;
+ status = lua_cpcall(L, pmain, NULL);
+ report(L, status);
+ lua_close(L);
+ return (status || smain.status) ? EXIT_FAILURE : EXIT_SUCCESS;
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/luajit.h b/src/3rdparty/LuaJIT-2.0.5/src/luajit.h
new file mode 100644
index 0000000..c5ff3ac
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/luajit.h
@@ -0,0 +1,70 @@
+/*
+** LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/
+**
+** Copyright (C) 2005-2017 Mike Pall. All rights reserved.
+**
+** Permission is hereby granted, free of charge, to any person obtaining
+** a copy of this software and associated documentation files (the
+** "Software"), to deal in the Software without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Software, and to
+** permit persons to whom the Software is furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be
+** included in all copies or substantial portions of the Software.
+**
+** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+**
+** [ MIT license: http://www.opensource.org/licenses/mit-license.php ]
+*/
+
+#ifndef _LUAJIT_H
+#define _LUAJIT_H
+
+#include "lua.h"
+
+#define LUAJIT_VERSION "LuaJIT 2.0.5"
+#define LUAJIT_VERSION_NUM 20005 /* Version 2.0.5 = 02.00.05. */
+#define LUAJIT_VERSION_SYM luaJIT_version_2_0_5
+#define LUAJIT_COPYRIGHT "Copyright (C) 2005-2017 Mike Pall"
+#define LUAJIT_URL "http://luajit.org/"
+
+/* Modes for luaJIT_setmode. */
+#define LUAJIT_MODE_MASK 0x00ff
+
+enum {
+ LUAJIT_MODE_ENGINE, /* Set mode for whole JIT engine. */
+ LUAJIT_MODE_DEBUG, /* Set debug mode (idx = level). */
+
+ LUAJIT_MODE_FUNC, /* Change mode for a function. */
+ LUAJIT_MODE_ALLFUNC, /* Recurse into subroutine protos. */
+ LUAJIT_MODE_ALLSUBFUNC, /* Change only the subroutines. */
+
+ LUAJIT_MODE_TRACE, /* Flush a compiled trace. */
+
+ LUAJIT_MODE_WRAPCFUNC = 0x10, /* Set wrapper mode for C function calls. */
+
+ LUAJIT_MODE_MAX
+};
+
+/* Flags or'ed in to the mode. */
+#define LUAJIT_MODE_OFF 0x0000 /* Turn feature off. */
+#define LUAJIT_MODE_ON 0x0100 /* Turn feature on. */
+#define LUAJIT_MODE_FLUSH 0x0200 /* Flush JIT-compiled code. */
+
+/* LuaJIT public C API. */
+
+/* Control the JIT engine. */
+LUA_API int luaJIT_setmode(lua_State *L, int idx, int mode);
+
+/* Enforce (dynamic) linker error for version mismatches. Call from main. */
+LUA_API void LUAJIT_VERSION_SYM(void);
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/lualib.h b/src/3rdparty/LuaJIT-2.0.5/src/lualib.h
new file mode 100644
index 0000000..bfc130a
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/lualib.h
@@ -0,0 +1,43 @@
+/*
+** Standard library header.
+** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+*/
+
+#ifndef _LUALIB_H
+#define _LUALIB_H
+
+#include "lua.h"
+
+#define LUA_FILEHANDLE "FILE*"
+
+#define LUA_COLIBNAME "coroutine"
+#define LUA_MATHLIBNAME "math"
+#define LUA_STRLIBNAME "string"
+#define LUA_TABLIBNAME "table"
+#define LUA_IOLIBNAME "io"
+#define LUA_OSLIBNAME "os"
+#define LUA_LOADLIBNAME "package"
+#define LUA_DBLIBNAME "debug"
+#define LUA_BITLIBNAME "bit"
+#define LUA_JITLIBNAME "jit"
+#define LUA_FFILIBNAME "ffi"
+
+LUALIB_API int luaopen_base(lua_State *L);
+LUALIB_API int luaopen_math(lua_State *L);
+LUALIB_API int luaopen_string(lua_State *L);
+LUALIB_API int luaopen_table(lua_State *L);
+LUALIB_API int luaopen_io(lua_State *L);
+LUALIB_API int luaopen_os(lua_State *L);
+LUALIB_API int luaopen_package(lua_State *L);
+LUALIB_API int luaopen_debug(lua_State *L);
+LUALIB_API int luaopen_bit(lua_State *L);
+LUALIB_API int luaopen_jit(lua_State *L);
+LUALIB_API int luaopen_ffi(lua_State *L);
+
+LUALIB_API void luaL_openlibs(lua_State *L);
+
+#ifndef lua_assert
+#define lua_assert(x) ((void)0)
+#endif
+
+#endif
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/minilua.lib b/src/3rdparty/LuaJIT-2.0.5/src/minilua.lib
new file mode 100644
index 0000000..e2b3ac3
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/minilua.lib
Binary files differ
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/msvcbuild.bat b/src/3rdparty/LuaJIT-2.0.5/src/msvcbuild.bat
new file mode 100644
index 0000000..42e3652
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/msvcbuild.bat
@@ -0,0 +1,115 @@
+@rem Script to build LuaJIT with MSVC.
+@rem Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+@rem
+@rem Either open a "Visual Studio .NET Command Prompt"
+@rem (Note that the Express Edition does not contain an x64 compiler)
+@rem -or-
+@rem Open a "Windows SDK Command Shell" and set the compiler environment:
+@rem setenv /release /x86
+@rem -or-
+@rem setenv /release /x64
+@rem
+@rem Then cd to this directory and run this script.
+
+@if not defined INCLUDE goto :FAIL
+
+@setlocal
+@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_STDIO_INLINE=__declspec(dllexport)__inline
+@set LJLINK=link /nologo
+@set LJMT=mt /nologo
+@set LJLIB=lib /nologo /nodefaultlib
+@set DASMDIR=..\dynasm
+@set DASM=%DASMDIR%\dynasm.lua
+@set LJDLLNAME=lua51.dll
+@set LJLIBNAME=lua51.lib
+@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c
+
+%LJCOMPILE% host\minilua.c
+@if errorlevel 1 goto :BAD
+%LJLINK% /out:minilua.exe minilua.obj
+@if errorlevel 1 goto :BAD
+if exist minilua.exe.manifest^
+ %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe
+
+@set DASMFLAGS=-D WIN -D JIT -D FFI -D P64
+@set LJARCH=x64
+@minilua
+@if errorlevel 8 goto :X64
+@set DASMFLAGS=-D WIN -D JIT -D FFI
+@set LJARCH=x86
+:X64
+minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_x86.dasc
+@if errorlevel 1 goto :BAD
+
+%LJCOMPILE% /I "." /I %DASMDIR% host\buildvm*.c
+@if errorlevel 1 goto :BAD
+%LJLINK% /out:buildvm.exe buildvm*.obj
+@if errorlevel 1 goto :BAD
+if exist buildvm.exe.manifest^
+ %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe
+
+buildvm -m peobj -o lj_vm.obj
+@if errorlevel 1 goto :BAD
+buildvm -m bcdef -o lj_bcdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m ffdef -o lj_ffdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m libdef -o lj_libdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m recdef -o lj_recdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
+@if errorlevel 1 goto :BAD
+
+@if "%1" neq "debug" goto :NODEBUG
+@shift
+@set LJCOMPILE=%LJCOMPILE% /Zi
+@set LJLINK=%LJLINK% /debug
+:NODEBUG
+@if "%1"=="amalg" goto :AMALGDLL
+@if "%1"=="static" goto :STATIC
+%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL lj_*.c lib_*.c
+@if errorlevel 1 goto :BAD
+%LJLINK% /DLL /out:%LJDLLNAME% lj_*.obj lib_*.obj
+@if errorlevel 1 goto :BAD
+@goto :MTDLL
+:STATIC
+%LJCOMPILE% lj_*.c lib_*.c
+@if errorlevel 1 goto :BAD
+%LJLIB% /OUT:%LJLIBNAME% lj_*.obj lib_*.obj
+@if errorlevel 1 goto :BAD
+@goto :MTDLL
+:AMALGDLL
+%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL ljamalg.c
+@if errorlevel 1 goto :BAD
+%LJLINK% /DLL /out:%LJDLLNAME% ljamalg.obj lj_vm.obj
+@if errorlevel 1 goto :BAD
+:MTDLL
+if exist %LJDLLNAME%.manifest^
+ %LJMT% -manifest %LJDLLNAME%.manifest -outputresource:%LJDLLNAME%;2
+
+%LJCOMPILE% luajit.c
+@if errorlevel 1 goto :BAD
+%LJLINK% /out:luajit.exe luajit.obj %LJLIBNAME%
+@if errorlevel 1 goto :BAD
+if exist luajit.exe.manifest^
+ %LJMT% -manifest luajit.exe.manifest -outputresource:luajit.exe
+
+@del *.obj *.manifest minilua.exe buildvm.exe
+@del host\buildvm_arch.h
+@del lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h
+@echo.
+@echo === Successfully built LuaJIT for Windows/%LJARCH% ===
+
+@goto :END
+:BAD
+@echo.
+@echo *******************************************************
+@echo *** Build FAILED -- Please check the error messages ***
+@echo *******************************************************
+@goto :END
+:FAIL
+@echo You must open a "Visual Studio .NET Command Prompt" to run this script
+:END
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/ps4build.bat b/src/3rdparty/LuaJIT-2.0.5/src/ps4build.bat
new file mode 100644
index 0000000..bcfc0d5
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/ps4build.bat
@@ -0,0 +1,103 @@
+@rem Script to build LuaJIT with the PS4 SDK.
+@rem Donated to the public domain.
+@rem
+@rem Open a "Visual Studio .NET Command Prompt" (64 bit host compiler)
+@rem Then cd to this directory and run this script.
+
+@if not defined INCLUDE goto :FAIL
+@if not defined SCE_ORBIS_SDK_DIR goto :FAIL
+
+@setlocal
+@rem ---- Host compiler ----
+@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE
+@set LJLINK=link /nologo
+@set LJMT=mt /nologo
+@set DASMDIR=..\dynasm
+@set DASM=%DASMDIR%\dynasm.lua
+@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c
+
+%LJCOMPILE% host\minilua.c
+@if errorlevel 1 goto :BAD
+%LJLINK% /out:minilua.exe minilua.obj
+@if errorlevel 1 goto :BAD
+if exist minilua.exe.manifest^
+ %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe
+
+@rem Check for 64 bit host compiler.
+@minilua
+@if not errorlevel 8 goto :FAIL
+
+@set DASMFLAGS=-D P64 -D NO_UNWIND
+minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_x86.dasc
+@if errorlevel 1 goto :BAD
+
+%LJCOMPILE% /I "." /I %DASMDIR% -DLUAJIT_TARGET=LUAJIT_ARCH_X64 -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_NO_UNWIND host\buildvm*.c
+@if errorlevel 1 goto :BAD
+%LJLINK% /out:buildvm.exe buildvm*.obj
+@if errorlevel 1 goto :BAD
+if exist buildvm.exe.manifest^
+ %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe
+
+buildvm -m elfasm -o lj_vm.s
+@if errorlevel 1 goto :BAD
+buildvm -m bcdef -o lj_bcdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m ffdef -o lj_ffdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m libdef -o lj_libdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m recdef -o lj_recdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
+@if errorlevel 1 goto :BAD
+
+@rem ---- Cross compiler ----
+@set LJCOMPILE="%SCE_ORBIS_SDK_DIR%\host_tools\bin\orbis-clang" -c -Wall -DLUAJIT_DISABLE_FFI
+@set LJLIB="%SCE_ORBIS_SDK_DIR%\host_tools\bin\orbis-ar" rcus
+@set INCLUDE=""
+
+orbis-as -o lj_vm.o lj_vm.s
+
+@if "%1" neq "debug" goto :NODEBUG
+@shift
+@set LJCOMPILE=%LJCOMPILE% -g -O0
+@set TARGETLIB=libluajitD.a
+goto :BUILD
+:NODEBUG
+@set LJCOMPILE=%LJCOMPILE% -O2
+@set TARGETLIB=libluajit.a
+:BUILD
+del %TARGETLIB%
+@if "%1"=="amalg" goto :AMALG
+for %%f in (lj_*.c lib_*.c) do (
+ %LJCOMPILE% %%f
+ @if errorlevel 1 goto :BAD
+)
+
+%LJLIB% %TARGETLIB% lj_*.o lib_*.o
+@if errorlevel 1 goto :BAD
+@goto :NOAMALG
+:AMALG
+%LJCOMPILE% ljamalg.c
+@if errorlevel 1 goto :BAD
+%LJLIB% %TARGETLIB% ljamalg.o lj_vm.o
+@if errorlevel 1 goto :BAD
+:NOAMALG
+
+@del *.o *.obj *.manifest minilua.exe buildvm.exe
+@echo.
+@echo === Successfully built LuaJIT for PS4 ===
+
+@goto :END
+:BAD
+@echo.
+@echo *******************************************************
+@echo *** Build FAILED -- Please check the error messages ***
+@echo *******************************************************
+@goto :END
+:FAIL
+@echo To run this script you must open a "Visual Studio .NET Command Prompt"
+@echo (64 bit host compiler). The PS4 Orbis SDK must be installed, too.
+:END
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/psvitabuild.bat b/src/3rdparty/LuaJIT-2.0.5/src/psvitabuild.bat
new file mode 100644
index 0000000..515f354
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/psvitabuild.bat
@@ -0,0 +1,93 @@
+@rem Script to build LuaJIT with the PS Vita SDK.
+@rem Donated to the public domain.
+@rem
+@rem Open a "Visual Studio .NET Command Prompt" (32 bit host compiler)
+@rem Then cd to this directory and run this script.
+
+@if not defined INCLUDE goto :FAIL
+@if not defined SCE_PSP2_SDK_DIR goto :FAIL
+
+@setlocal
+@rem ---- Host compiler ----
+@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE
+@set LJLINK=link /nologo
+@set LJMT=mt /nologo
+@set DASMDIR=..\dynasm
+@set DASM=%DASMDIR%\dynasm.lua
+@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c
+
+%LJCOMPILE% host\minilua.c
+@if errorlevel 1 goto :BAD
+%LJLINK% /out:minilua.exe minilua.obj
+@if errorlevel 1 goto :BAD
+if exist minilua.exe.manifest^
+ %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe
+
+@rem Check for 32 bit host compiler.
+@minilua
+@if errorlevel 8 goto :FAIL
+
+@set DASMFLAGS=-D FPU -D HFABI
+minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_arm.dasc
+@if errorlevel 1 goto :BAD
+
+%LJCOMPILE% /I "." /I %DASMDIR% -DLUAJIT_TARGET=LUAJIT_ARCH_ARM -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLJ_TARGET_PSVITA=1 host\buildvm*.c
+@if errorlevel 1 goto :BAD
+%LJLINK% /out:buildvm.exe buildvm*.obj
+@if errorlevel 1 goto :BAD
+if exist buildvm.exe.manifest^
+ %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe
+
+buildvm -m elfasm -o lj_vm.s
+@if errorlevel 1 goto :BAD
+buildvm -m bcdef -o lj_bcdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m ffdef -o lj_ffdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m libdef -o lj_libdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m recdef -o lj_recdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
+@if errorlevel 1 goto :BAD
+
+@rem ---- Cross compiler ----
+@set LJCOMPILE="%SCE_PSP2_SDK_DIR%\host_tools\build\bin\psp2snc" -c -w -DLUAJIT_DISABLE_FFI -DLUAJIT_USE_SYSMALLOC
+@set LJLIB="%SCE_PSP2_SDK_DIR%\host_tools\build\bin\psp2ld32" -r --output=
+@set INCLUDE=""
+
+"%SCE_PSP2_SDK_DIR%\host_tools\build\bin\psp2as" -o lj_vm.o lj_vm.s
+
+@if "%1" neq "debug" goto :NODEBUG
+@shift
+@set LJCOMPILE=%LJCOMPILE% -g -O0
+@set TARGETLIB=libluajitD.a
+goto :BUILD
+:NODEBUG
+@set LJCOMPILE=%LJCOMPILE% -O2
+@set TARGETLIB=libluajit.a
+:BUILD
+del %TARGETLIB%
+
+%LJCOMPILE% ljamalg.c
+@if errorlevel 1 goto :BAD
+%LJLIB%%TARGETLIB% ljamalg.o lj_vm.o
+@if errorlevel 1 goto :BAD
+
+@del *.o *.obj *.manifest minilua.exe buildvm.exe
+@echo.
+@echo === Successfully built LuaJIT for PS Vita ===
+
+@goto :END
+:BAD
+@echo.
+@echo *******************************************************
+@echo *** Build FAILED -- Please check the error messages ***
+@echo *******************************************************
+@goto :END
+:FAIL
+@echo To run this script you must open a "Visual Studio .NET Command Prompt"
+@echo (32 bit host compiler). The PS Vita SDK must be installed, too.
+:END
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/vm_arm.dasc b/src/3rdparty/LuaJIT-2.0.5/src/vm_arm.dasc
new file mode 100644
index 0000000..be5540c
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/vm_arm.dasc
@@ -0,0 +1,4486 @@
+|// Low-level VM code for ARM CPUs.
+|// Bytecode interpreter, fast functions and helper functions.
+|// Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+|
+|.arch arm
+|.section code_op, code_sub
+|
+|.actionlist build_actionlist
+|.globals GLOB_
+|.globalnames globnames
+|.externnames extnames
+|
+|// Note: The ragged indentation of the instructions is intentional.
+|// The starting columns indicate data dependencies.
+|
+|//-----------------------------------------------------------------------
+|
+|// Fixed register assignments for the interpreter.
+|
+|// The following must be C callee-save.
+|.define MASKR8, r4 // 255*8 constant for fast bytecode decoding.
+|.define KBASE, r5 // Constants of current Lua function.
+|.define PC, r6 // Next PC.
+|.define DISPATCH, r7 // Opcode dispatch table.
+|.define LREG, r8 // Register holding lua_State (also in SAVE_L).
+|
+|// C callee-save in EABI, but often refetched. Temporary in iOS 3.0+.
+|.define BASE, r9 // Base of current Lua stack frame.
+|
+|// The following temporaries are not saved across C calls, except for RA/RC.
+|.define RA, r10 // Callee-save.
+|.define RC, r11 // Callee-save.
+|.define RB, r12
+|.define OP, r12 // Overlaps RB, must not be lr.
+|.define INS, lr
+|
+|// Calling conventions. Also used as temporaries.
+|.define CARG1, r0
+|.define CARG2, r1
+|.define CARG3, r2
+|.define CARG4, r3
+|.define CARG12, r0 // For 1st soft-fp double.
+|.define CARG34, r2 // For 2nd soft-fp double.
+|
+|.define CRET1, r0
+|.define CRET2, r1
+|
+|// Stack layout while in interpreter. Must match with lj_frame.h.
+|.define SAVE_R4, [sp, #28]
+|.define CFRAME_SPACE, #28
+|.define SAVE_ERRF, [sp, #24]
+|.define SAVE_NRES, [sp, #20]
+|.define SAVE_CFRAME, [sp, #16]
+|.define SAVE_L, [sp, #12]
+|.define SAVE_PC, [sp, #8]
+|.define SAVE_MULTRES, [sp, #4]
+|.define ARG5, [sp]
+|
+|.define TMPDhi, [sp, #4]
+|.define TMPDlo, [sp]
+|.define TMPD, [sp]
+|.define TMPDp, sp
+|
+|.if FPU
+|.macro saveregs
+| push {r5, r6, r7, r8, r9, r10, r11, lr}
+| vpush {d8-d15}
+| sub sp, sp, CFRAME_SPACE+4
+| str r4, SAVE_R4
+|.endmacro
+|.macro restoreregs_ret
+| ldr r4, SAVE_R4
+| add sp, sp, CFRAME_SPACE+4
+| vpop {d8-d15}
+| pop {r5, r6, r7, r8, r9, r10, r11, pc}
+|.endmacro
+|.else
+|.macro saveregs
+| push {r4, r5, r6, r7, r8, r9, r10, r11, lr}
+| sub sp, sp, CFRAME_SPACE
+|.endmacro
+|.macro restoreregs_ret
+| add sp, sp, CFRAME_SPACE
+| pop {r4, r5, r6, r7, r8, r9, r10, r11, pc}
+|.endmacro
+|.endif
+|
+|// Type definitions. Some of these are only used for documentation.
+|.type L, lua_State, LREG
+|.type GL, global_State
+|.type TVALUE, TValue
+|.type GCOBJ, GCobj
+|.type STR, GCstr
+|.type TAB, GCtab
+|.type LFUNC, GCfuncL
+|.type CFUNC, GCfuncC
+|.type PROTO, GCproto
+|.type UPVAL, GCupval
+|.type NODE, Node
+|.type NARGS8, int
+|.type TRACE, GCtrace
+|
+|//-----------------------------------------------------------------------
+|
+|// Trap for not-yet-implemented parts.
+|.macro NYI; ud; .endmacro
+|
+|//-----------------------------------------------------------------------
+|
+|// Access to frame relative to BASE.
+|.define FRAME_FUNC, #-8
+|.define FRAME_PC, #-4
+|
+|.macro decode_RA8, dst, ins; and dst, MASKR8, ins, lsr #5; .endmacro
+|.macro decode_RB8, dst, ins; and dst, MASKR8, ins, lsr #21; .endmacro
+|.macro decode_RC8, dst, ins; and dst, MASKR8, ins, lsr #13; .endmacro
+|.macro decode_RD, dst, ins; lsr dst, ins, #16; .endmacro
+|.macro decode_OP, dst, ins; and dst, ins, #255; .endmacro
+|
+|// Instruction fetch.
+|.macro ins_NEXT1
+| ldrb OP, [PC]
+|.endmacro
+|.macro ins_NEXT2
+| ldr INS, [PC], #4
+|.endmacro
+|// Instruction decode+dispatch.
+|.macro ins_NEXT3
+| ldr OP, [DISPATCH, OP, lsl #2]
+| decode_RA8 RA, INS
+| decode_RD RC, INS
+| bx OP
+|.endmacro
+|.macro ins_NEXT
+| ins_NEXT1
+| ins_NEXT2
+| ins_NEXT3
+|.endmacro
+|
+|// Instruction footer.
+|.if 1
+| // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.
+| .define ins_next, ins_NEXT
+| .define ins_next_, ins_NEXT
+| .define ins_next1, ins_NEXT1
+| .define ins_next2, ins_NEXT2
+| .define ins_next3, ins_NEXT3
+|.else
+| // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.
+| // Affects only certain kinds of benchmarks (and only with -j off).
+| .macro ins_next
+| b ->ins_next
+| .endmacro
+| .macro ins_next1
+| .endmacro
+| .macro ins_next2
+| .endmacro
+| .macro ins_next3
+| b ->ins_next
+| .endmacro
+| .macro ins_next_
+| ->ins_next:
+| ins_NEXT
+| .endmacro
+|.endif
+|
+|// Avoid register name substitution for field name.
+#define field_pc pc
+|
+|// Call decode and dispatch.
+|.macro ins_callt
+| // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC
+| ldr PC, LFUNC:CARG3->field_pc
+| ldrb OP, [PC] // STALL: load PC. early PC.
+| ldr INS, [PC], #4
+| ldr OP, [DISPATCH, OP, lsl #2] // STALL: load OP. early OP.
+| decode_RA8 RA, INS
+| add RA, RA, BASE
+| bx OP
+|.endmacro
+|
+|.macro ins_call
+| // BASE = new base, CARG3 = LFUNC/CFUNC, RC = nargs*8, PC = caller PC
+| str PC, [BASE, FRAME_PC]
+| ins_callt // STALL: locked PC.
+|.endmacro
+|
+|//-----------------------------------------------------------------------
+|
+|// Macros to test operand types.
+|.macro checktp, reg, tp; cmn reg, #-tp; .endmacro
+|.macro checktpeq, reg, tp; cmneq reg, #-tp; .endmacro
+|.macro checktpne, reg, tp; cmnne reg, #-tp; .endmacro
+|.macro checkstr, reg, target; checktp reg, LJ_TSTR; bne target; .endmacro
+|.macro checktab, reg, target; checktp reg, LJ_TTAB; bne target; .endmacro
+|.macro checkfunc, reg, target; checktp reg, LJ_TFUNC; bne target; .endmacro
+|
+|// Assumes DISPATCH is relative to GL.
+#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field))
+#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field))
+|
+#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
+|
+|.macro hotcheck, delta
+| lsr CARG1, PC, #1
+| and CARG1, CARG1, #126
+| sub CARG1, CARG1, #-GG_DISP2HOT
+| ldrh CARG2, [DISPATCH, CARG1]
+| subs CARG2, CARG2, #delta
+| strh CARG2, [DISPATCH, CARG1]
+|.endmacro
+|
+|.macro hotloop
+| hotcheck HOTCOUNT_LOOP
+| blo ->vm_hotloop
+|.endmacro
+|
+|.macro hotcall
+| hotcheck HOTCOUNT_CALL
+| blo ->vm_hotcall
+|.endmacro
+|
+|// Set current VM state.
+|.macro mv_vmstate, reg, st; mvn reg, #LJ_VMST_..st; .endmacro
+|.macro st_vmstate, reg; str reg, [DISPATCH, #DISPATCH_GL(vmstate)]; .endmacro
+|
+|// Move table write barrier back. Overwrites mark and tmp.
+|.macro barrierback, tab, mark, tmp
+| ldr tmp, [DISPATCH, #DISPATCH_GL(gc.grayagain)]
+| bic mark, mark, #LJ_GC_BLACK // black2gray(tab)
+| str tab, [DISPATCH, #DISPATCH_GL(gc.grayagain)]
+| strb mark, tab->marked
+| str tmp, tab->gclist
+|.endmacro
+|
+|.macro .IOS, a, b
+|.if IOS
+| a, b
+|.endif
+|.endmacro
+|
+|//-----------------------------------------------------------------------
+
+#if !LJ_DUALNUM
+#error "Only dual-number mode supported for ARM target"
+#endif
+
+/* Generate subroutines used by opcodes and other parts of the VM. */
+/* The .code_sub section should be last to help static branch prediction. */
+static void build_subroutines(BuildCtx *ctx)
+{
+ |.code_sub
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Return handling ----------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_returnp:
+ | // See vm_return. Also: RB = previous base.
+ | tst PC, #FRAME_P
+ | beq ->cont_dispatch
+ |
+ | // Return from pcall or xpcall fast func.
+ | ldr PC, [RB, FRAME_PC] // Fetch PC of previous frame.
+ | mvn CARG2, #~LJ_TTRUE
+ | mov BASE, RB
+ | // Prepending may overwrite the pcall frame, so do it at the end.
+ | str CARG2, [RA, FRAME_PC] // Prepend true to results.
+ | sub RA, RA, #8
+ |
+ |->vm_returnc:
+ | adds RC, RC, #8 // RC = (nresults+1)*8.
+ | mov CRET1, #LUA_YIELD
+ | beq ->vm_unwind_c_eh
+ | str RC, SAVE_MULTRES
+ | ands CARG1, PC, #FRAME_TYPE
+ | beq ->BC_RET_Z // Handle regular return to Lua.
+ |
+ |->vm_return:
+ | // BASE = base, RA = resultptr, RC/MULTRES = (nresults+1)*8, PC = return
+ | // CARG1 = PC & FRAME_TYPE
+ | bic RB, PC, #FRAME_TYPEP
+ | cmp CARG1, #FRAME_C
+ | sub RB, BASE, RB // RB = previous base.
+ | bne ->vm_returnp
+ |
+ | str RB, L->base
+ | ldr KBASE, SAVE_NRES
+ | mv_vmstate CARG4, C
+ | sub BASE, BASE, #8
+ | subs CARG3, RC, #8
+ | lsl KBASE, KBASE, #3 // KBASE = (nresults_wanted+1)*8
+ | st_vmstate CARG4
+ | beq >2
+ |1:
+ | subs CARG3, CARG3, #8
+ | ldrd CARG12, [RA], #8
+ | strd CARG12, [BASE], #8
+ | bne <1
+ |2:
+ | cmp KBASE, RC // More/less results wanted?
+ | bne >6
+ |3:
+ | str BASE, L->top // Store new top.
+ |
+ |->vm_leave_cp:
+ | ldr RC, SAVE_CFRAME // Restore previous C frame.
+ | mov CRET1, #0 // Ok return status for vm_pcall.
+ | str RC, L->cframe
+ |
+ |->vm_leave_unw:
+ | restoreregs_ret
+ |
+ |6:
+ | blt >7 // Less results wanted?
+ | // More results wanted. Check stack size and fill up results with nil.
+ | ldr CARG3, L->maxstack
+ | mvn CARG2, #~LJ_TNIL
+ | cmp BASE, CARG3
+ | bhs >8
+ | str CARG2, [BASE, #4]
+ | add RC, RC, #8
+ | add BASE, BASE, #8
+ | b <2
+ |
+ |7: // Less results wanted.
+ | sub CARG1, RC, KBASE
+ | cmp KBASE, #0 // LUA_MULTRET+1 case?
+ | subne BASE, BASE, CARG1 // Either keep top or shrink it.
+ | b <3
+ |
+ |8: // Corner case: need to grow stack for filling up results.
+ | // This can happen if:
+ | // - A C function grows the stack (a lot).
+ | // - The GC shrinks the stack in between.
+ | // - A return back from a lua_call() with (high) nresults adjustment.
+ | str BASE, L->top // Save current top held in BASE (yes).
+ | lsr CARG2, KBASE, #3
+ | mov CARG1, L
+ | bl extern lj_state_growstack // (lua_State *L, int n)
+ | ldr BASE, L->top // Need the (realloced) L->top in BASE.
+ | b <2
+ |
+ |->vm_unwind_c: // Unwind C stack, return from vm_pcall.
+ | // (void *cframe, int errcode)
+ | mov sp, CARG1
+ | mov CRET1, CARG2
+ |->vm_unwind_c_eh: // Landing pad for external unwinder.
+ | ldr L, SAVE_L
+ | mv_vmstate CARG4, C
+ | ldr GL:CARG3, L->glref
+ | str CARG4, GL:CARG3->vmstate
+ | b ->vm_leave_unw
+ |
+ |->vm_unwind_ff: // Unwind C stack, return from ff pcall.
+ | // (void *cframe)
+ | bic CARG1, CARG1, #~CFRAME_RAWMASK // Use two steps: bic sp is deprecated.
+ | mov sp, CARG1
+ |->vm_unwind_ff_eh: // Landing pad for external unwinder.
+ | ldr L, SAVE_L
+ | mov MASKR8, #255
+ | mov RC, #16 // 2 results: false + error message.
+ | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
+ | ldr BASE, L->base
+ | ldr DISPATCH, L->glref // Setup pointer to dispatch table.
+ | mvn CARG1, #~LJ_TFALSE
+ | sub RA, BASE, #8 // Results start at BASE-8.
+ | ldr PC, [BASE, FRAME_PC] // Fetch PC of previous frame.
+ | add DISPATCH, DISPATCH, #GG_G2DISP
+ | mv_vmstate CARG2, INTERP
+ | str CARG1, [BASE, #-4] // Prepend false to error message.
+ | st_vmstate CARG2
+ | b ->vm_returnc
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Grow stack for calls -----------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_growstack_c: // Grow stack for C function.
+ | // CARG1 = L
+ | mov CARG2, #LUA_MINSTACK
+ | b >2
+ |
+ |->vm_growstack_l: // Grow stack for Lua function.
+ | // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC
+ | add RC, BASE, RC
+ | sub RA, RA, BASE
+ | mov CARG1, L
+ | str BASE, L->base
+ | add PC, PC, #4 // Must point after first instruction.
+ | str RC, L->top
+ | lsr CARG2, RA, #3
+ |2:
+ | // L->base = new base, L->top = top
+ | str PC, SAVE_PC
+ | bl extern lj_state_growstack // (lua_State *L, int n)
+ | ldr BASE, L->base
+ | ldr RC, L->top
+ | ldr LFUNC:CARG3, [BASE, FRAME_FUNC]
+ | sub NARGS8:RC, RC, BASE
+ | // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC
+ | ins_callt // Just retry the call.
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Entry points into the assembler VM ---------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_resume: // Setup C frame and resume thread.
+ | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)
+ | saveregs
+ | mov L, CARG1
+ | ldr DISPATCH, L:CARG1->glref // Setup pointer to dispatch table.
+ | mov BASE, CARG2
+ | add DISPATCH, DISPATCH, #GG_G2DISP
+ | str L, SAVE_L
+ | mov PC, #FRAME_CP
+ | str CARG3, SAVE_NRES
+ | add CARG2, sp, #CFRAME_RESUME
+ | ldrb CARG1, L->status
+ | str CARG3, SAVE_ERRF
+ | str CARG2, L->cframe
+ | str CARG3, SAVE_CFRAME
+ | cmp CARG1, #0
+ | str L, SAVE_PC // Any value outside of bytecode is ok.
+ | beq >3
+ |
+ | // Resume after yield (like a return).
+ | mov RA, BASE
+ | ldr BASE, L->base
+ | ldr CARG1, L->top
+ | mov MASKR8, #255
+ | strb CARG3, L->status
+ | sub RC, CARG1, BASE
+ | ldr PC, [BASE, FRAME_PC]
+ | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
+ | mv_vmstate CARG2, INTERP
+ | add RC, RC, #8
+ | ands CARG1, PC, #FRAME_TYPE
+ | st_vmstate CARG2
+ | str RC, SAVE_MULTRES
+ | beq ->BC_RET_Z
+ | b ->vm_return
+ |
+ |->vm_pcall: // Setup protected C frame and enter VM.
+ | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)
+ | saveregs
+ | mov PC, #FRAME_CP
+ | str CARG4, SAVE_ERRF
+ | b >1
+ |
+ |->vm_call: // Setup C frame and enter VM.
+ | // (lua_State *L, TValue *base, int nres1)
+ | saveregs
+ | mov PC, #FRAME_C
+ |
+ |1: // Entry point for vm_pcall above (PC = ftype).
+ | ldr RC, L:CARG1->cframe
+ | str CARG3, SAVE_NRES
+ | mov L, CARG1
+ | str CARG1, SAVE_L
+ | mov BASE, CARG2
+ | str sp, L->cframe // Add our C frame to cframe chain.
+ | ldr DISPATCH, L->glref // Setup pointer to dispatch table.
+ | str CARG1, SAVE_PC // Any value outside of bytecode is ok.
+ | str RC, SAVE_CFRAME
+ | add DISPATCH, DISPATCH, #GG_G2DISP
+ |
+ |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).
+ | ldr RB, L->base // RB = old base (for vmeta_call).
+ | ldr CARG1, L->top
+ | mov MASKR8, #255
+ | add PC, PC, BASE
+ | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
+ | sub PC, PC, RB // PC = frame delta + frame type
+ | mv_vmstate CARG2, INTERP
+ | sub NARGS8:RC, CARG1, BASE
+ | st_vmstate CARG2
+ |
+ |->vm_call_dispatch:
+ | // RB = old base, BASE = new base, RC = nargs*8, PC = caller PC
+ | ldrd CARG34, [BASE, FRAME_FUNC]
+ | checkfunc CARG4, ->vmeta_call
+ |
+ |->vm_call_dispatch_f:
+ | ins_call
+ | // BASE = new base, CARG3 = func, RC = nargs*8, PC = caller PC
+ |
+ |->vm_cpcall: // Setup protected C frame, call C.
+ | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)
+ | saveregs
+ | mov L, CARG1
+ | ldr RA, L:CARG1->stack
+ | str CARG1, SAVE_L
+ | ldr RB, L->top
+ | str CARG1, SAVE_PC // Any value outside of bytecode is ok.
+ | ldr RC, L->cframe
+ | sub RA, RA, RB // Compute -savestack(L, L->top).
+ | str sp, L->cframe // Add our C frame to cframe chain.
+ | mov RB, #0
+ | str RA, SAVE_NRES // Neg. delta means cframe w/o frame.
+ | str RB, SAVE_ERRF // No error function.
+ | str RC, SAVE_CFRAME
+ | blx CARG4 // (lua_State *L, lua_CFunction func, void *ud)
+ | ldr DISPATCH, L->glref // Setup pointer to dispatch table.
+ | movs BASE, CRET1
+ | mov PC, #FRAME_CP
+ | add DISPATCH, DISPATCH, #GG_G2DISP
+ | bne <3 // Else continue with the call.
+ | b ->vm_leave_cp // No base? Just remove C frame.
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Metamethod handling ------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |//-- Continuation dispatch ----------------------------------------------
+ |
+ |->cont_dispatch:
+ | // BASE = meta base, RA = resultptr, RC = (nresults+1)*8
+ | ldr LFUNC:CARG3, [RB, FRAME_FUNC]
+ | ldr CARG1, [BASE, #-16] // Get continuation.
+ | mov CARG4, BASE
+ | mov BASE, RB // Restore caller BASE.
+ |.if FFI
+ | cmp CARG1, #1
+ |.endif
+ | ldr PC, [CARG4, #-12] // Restore PC from [cont|PC].
+ | ldr CARG3, LFUNC:CARG3->field_pc
+ | mvn INS, #~LJ_TNIL
+ | add CARG2, RA, RC
+ | str INS, [CARG2, #-4] // Ensure one valid arg.
+ |.if FFI
+ | bls >1
+ |.endif
+ | ldr KBASE, [CARG3, #PC2PROTO(k)]
+ | // BASE = base, RA = resultptr, CARG4 = meta base
+ | bx CARG1
+ |
+ |.if FFI
+ |1:
+ | beq ->cont_ffi_callback // cont = 1: return from FFI callback.
+ | // cont = 0: tailcall from C function.
+ | sub CARG4, CARG4, #16
+ | sub RC, CARG4, BASE
+ | b ->vm_call_tail
+ |.endif
+ |
+ |->cont_cat: // RA = resultptr, CARG4 = meta base
+ | ldr INS, [PC, #-4]
+ | sub CARG2, CARG4, #16
+ | ldrd CARG34, [RA]
+ | str BASE, L->base
+ | decode_RB8 RC, INS
+ | decode_RA8 RA, INS
+ | add CARG1, BASE, RC
+ | subs CARG1, CARG2, CARG1
+ | strdne CARG34, [CARG2]
+ | movne CARG3, CARG1
+ | bne ->BC_CAT_Z
+ | strd CARG34, [BASE, RA]
+ | b ->cont_nop
+ |
+ |//-- Table indexing metamethods -----------------------------------------
+ |
+ |->vmeta_tgets1:
+ | add CARG2, BASE, RB
+ | b >2
+ |
+ |->vmeta_tgets:
+ | sub CARG2, DISPATCH, #-DISPATCH_GL(tmptv)
+ | mvn CARG4, #~LJ_TTAB
+ | str TAB:RB, [CARG2]
+ | str CARG4, [CARG2, #4]
+ |2:
+ | mvn CARG4, #~LJ_TSTR
+ | str STR:RC, TMPDlo
+ | str CARG4, TMPDhi
+ | mov CARG3, TMPDp
+ | b >1
+ |
+ |->vmeta_tgetb: // RC = index
+ | decode_RB8 RB, INS
+ | str RC, TMPDlo
+ | mvn CARG4, #~LJ_TISNUM
+ | add CARG2, BASE, RB
+ | str CARG4, TMPDhi
+ | mov CARG3, TMPDp
+ | b >1
+ |
+ |->vmeta_tgetv:
+ | add CARG2, BASE, RB
+ | add CARG3, BASE, RC
+ |1:
+ | str BASE, L->base
+ | mov CARG1, L
+ | str PC, SAVE_PC
+ | bl extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k)
+ | // Returns TValue * (finished) or NULL (metamethod).
+ | .IOS ldr BASE, L->base
+ | cmp CRET1, #0
+ | beq >3
+ | ldrd CARG34, [CRET1]
+ | ins_next1
+ | ins_next2
+ | strd CARG34, [BASE, RA]
+ | ins_next3
+ |
+ |3: // Call __index metamethod.
+ | // BASE = base, L->top = new base, stack = cont/func/t/k
+ | rsb CARG1, BASE, #FRAME_CONT
+ | ldr BASE, L->top
+ | mov NARGS8:RC, #16 // 2 args for func(t, k).
+ | str PC, [BASE, #-12] // [cont|PC]
+ | add PC, CARG1, BASE
+ | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here.
+ | b ->vm_call_dispatch_f
+ |
+ |//-----------------------------------------------------------------------
+ |
+ |->vmeta_tsets1:
+ | add CARG2, BASE, RB
+ | b >2
+ |
+ |->vmeta_tsets:
+ | sub CARG2, DISPATCH, #-DISPATCH_GL(tmptv)
+ | mvn CARG4, #~LJ_TTAB
+ | str TAB:RB, [CARG2]
+ | str CARG4, [CARG2, #4]
+ |2:
+ | mvn CARG4, #~LJ_TSTR
+ | str STR:RC, TMPDlo
+ | str CARG4, TMPDhi
+ | mov CARG3, TMPDp
+ | b >1
+ |
+ |->vmeta_tsetb: // RC = index
+ | decode_RB8 RB, INS
+ | str RC, TMPDlo
+ | mvn CARG4, #~LJ_TISNUM
+ | add CARG2, BASE, RB
+ | str CARG4, TMPDhi
+ | mov CARG3, TMPDp
+ | b >1
+ |
+ |->vmeta_tsetv:
+ | add CARG2, BASE, RB
+ | add CARG3, BASE, RC
+ |1:
+ | str BASE, L->base
+ | mov CARG1, L
+ | str PC, SAVE_PC
+ | bl extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k)
+ | // Returns TValue * (finished) or NULL (metamethod).
+ | .IOS ldr BASE, L->base
+ | cmp CRET1, #0
+ | ldrd CARG34, [BASE, RA]
+ | beq >3
+ | ins_next1
+ | // NOBARRIER: lj_meta_tset ensures the table is not black.
+ | strd CARG34, [CRET1]
+ | ins_next2
+ | ins_next3
+ |
+ |3: // Call __newindex metamethod.
+ | // BASE = base, L->top = new base, stack = cont/func/t/k/(v)
+ | rsb CARG1, BASE, #FRAME_CONT
+ | ldr BASE, L->top
+ | mov NARGS8:RC, #24 // 3 args for func(t, k, v).
+ | strd CARG34, [BASE, #16] // Copy value to third argument.
+ | str PC, [BASE, #-12] // [cont|PC]
+ | add PC, CARG1, BASE
+ | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here.
+ | b ->vm_call_dispatch_f
+ |
+ |//-- Comparison metamethods ---------------------------------------------
+ |
+ |->vmeta_comp:
+ | mov CARG1, L
+ | sub PC, PC, #4
+ | mov CARG2, RA
+ | str BASE, L->base
+ | mov CARG3, RC
+ | str PC, SAVE_PC
+ | decode_OP CARG4, INS
+ | bl extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op)
+ | // Returns 0/1 or TValue * (metamethod).
+ |3:
+ | .IOS ldr BASE, L->base
+ | cmp CRET1, #1
+ | bhi ->vmeta_binop
+ |4:
+ | ldrh RB, [PC, #2]
+ | add PC, PC, #4
+ | add RB, PC, RB, lsl #2
+ | subhs PC, RB, #0x20000
+ |->cont_nop:
+ | ins_next
+ |
+ |->cont_ra: // RA = resultptr
+ | ldr INS, [PC, #-4]
+ | ldrd CARG12, [RA]
+ | decode_RA8 CARG3, INS
+ | strd CARG12, [BASE, CARG3]
+ | b ->cont_nop
+ |
+ |->cont_condt: // RA = resultptr
+ | ldr CARG2, [RA, #4]
+ | mvn CARG1, #~LJ_TTRUE
+ | cmp CARG1, CARG2 // Branch if result is true.
+ | b <4
+ |
+ |->cont_condf: // RA = resultptr
+ | ldr CARG2, [RA, #4]
+ | checktp CARG2, LJ_TFALSE // Branch if result is false.
+ | b <4
+ |
+ |->vmeta_equal:
+ | // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV.
+ | sub PC, PC, #4
+ | str BASE, L->base
+ | mov CARG1, L
+ | str PC, SAVE_PC
+ | bl extern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne)
+ | // Returns 0/1 or TValue * (metamethod).
+ | b <3
+ |
+ |->vmeta_equal_cd:
+ |.if FFI
+ | sub PC, PC, #4
+ | str BASE, L->base
+ | mov CARG1, L
+ | mov CARG2, INS
+ | str PC, SAVE_PC
+ | bl extern lj_meta_equal_cd // (lua_State *L, BCIns op)
+ | // Returns 0/1 or TValue * (metamethod).
+ | b <3
+ |.endif
+ |
+ |//-- Arithmetic metamethods ---------------------------------------------
+ |
+ |->vmeta_arith_vn:
+ | decode_RB8 RB, INS
+ | decode_RC8 RC, INS
+ | add CARG3, BASE, RB
+ | add CARG4, KBASE, RC
+ | b >1
+ |
+ |->vmeta_arith_nv:
+ | decode_RB8 RB, INS
+ | decode_RC8 RC, INS
+ | add CARG4, BASE, RB
+ | add CARG3, KBASE, RC
+ | b >1
+ |
+ |->vmeta_unm:
+ | ldr INS, [PC, #-8]
+ | sub PC, PC, #4
+ | add CARG3, BASE, RC
+ | add CARG4, BASE, RC
+ | b >1
+ |
+ |->vmeta_arith_vv:
+ | decode_RB8 RB, INS
+ | decode_RC8 RC, INS
+ | add CARG3, BASE, RB
+ | add CARG4, BASE, RC
+ |1:
+ | decode_OP OP, INS
+ | add CARG2, BASE, RA
+ | str BASE, L->base
+ | mov CARG1, L
+ | str PC, SAVE_PC
+ | str OP, ARG5
+ | bl extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)
+ | // Returns NULL (finished) or TValue * (metamethod).
+ | .IOS ldr BASE, L->base
+ | cmp CRET1, #0
+ | beq ->cont_nop
+ |
+ | // Call metamethod for binary op.
+ |->vmeta_binop:
+ | // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2
+ | sub CARG2, CRET1, BASE
+ | str PC, [CRET1, #-12] // [cont|PC]
+ | add PC, CARG2, #FRAME_CONT
+ | mov BASE, CRET1
+ | mov NARGS8:RC, #16 // 2 args for func(o1, o2).
+ | b ->vm_call_dispatch
+ |
+ |->vmeta_len:
+ | add CARG2, BASE, RC
+ | str BASE, L->base
+ | mov CARG1, L
+ | str PC, SAVE_PC
+ | bl extern lj_meta_len // (lua_State *L, TValue *o)
+ | // Returns NULL (retry) or TValue * (metamethod base).
+ | .IOS ldr BASE, L->base
+#if LJ_52
+ | cmp CRET1, #0
+ | bne ->vmeta_binop // Binop call for compatibility.
+ | ldr TAB:CARG1, [BASE, RC]
+ | b ->BC_LEN_Z
+#else
+ | b ->vmeta_binop // Binop call for compatibility.
+#endif
+ |
+ |//-- Call metamethod ----------------------------------------------------
+ |
+ |->vmeta_call: // Resolve and call __call metamethod.
+ | // RB = old base, BASE = new base, RC = nargs*8
+ | mov CARG1, L
+ | str RB, L->base // This is the callers base!
+ | sub CARG2, BASE, #8
+ | str PC, SAVE_PC
+ | add CARG3, BASE, NARGS8:RC
+ | .IOS mov RA, BASE
+ | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
+ | .IOS mov BASE, RA
+ | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here.
+ | add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now.
+ | ins_call
+ |
+ |->vmeta_callt: // Resolve __call for BC_CALLT.
+ | // BASE = old base, RA = new base, RC = nargs*8
+ | mov CARG1, L
+ | str BASE, L->base
+ | sub CARG2, RA, #8
+ | str PC, SAVE_PC
+ | add CARG3, RA, NARGS8:RC
+ | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
+ | .IOS ldr BASE, L->base
+ | ldr LFUNC:CARG3, [RA, FRAME_FUNC] // Guaranteed to be a function here.
+ | ldr PC, [BASE, FRAME_PC]
+ | add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now.
+ | b ->BC_CALLT2_Z
+ |
+ |//-- Argument coercion for 'for' statement ------------------------------
+ |
+ |->vmeta_for:
+ | mov CARG1, L
+ | str BASE, L->base
+ | mov CARG2, RA
+ | str PC, SAVE_PC
+ | bl extern lj_meta_for // (lua_State *L, TValue *base)
+ | .IOS ldr BASE, L->base
+ |.if JIT
+ | ldrb OP, [PC, #-4]
+ |.endif
+ | ldr INS, [PC, #-4]
+ |.if JIT
+ | cmp OP, #BC_JFORI
+ |.endif
+ | decode_RA8 RA, INS
+ | decode_RD RC, INS
+ |.if JIT
+ | beq =>BC_JFORI
+ |.endif
+ | b =>BC_FORI
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Fast functions -----------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |.macro .ffunc, name
+ |->ff_ .. name:
+ |.endmacro
+ |
+ |.macro .ffunc_1, name
+ |->ff_ .. name:
+ | ldrd CARG12, [BASE]
+ | cmp NARGS8:RC, #8
+ | blo ->fff_fallback
+ |.endmacro
+ |
+ |.macro .ffunc_2, name
+ |->ff_ .. name:
+ | ldrd CARG12, [BASE]
+ | ldrd CARG34, [BASE, #8]
+ | cmp NARGS8:RC, #16
+ | blo ->fff_fallback
+ |.endmacro
+ |
+ |.macro .ffunc_n, name
+ | .ffunc_1 name
+ | checktp CARG2, LJ_TISNUM
+ | bhs ->fff_fallback
+ |.endmacro
+ |
+ |.macro .ffunc_nn, name
+ | .ffunc_2 name
+ | checktp CARG2, LJ_TISNUM
+ | cmnlo CARG4, #-LJ_TISNUM
+ | bhs ->fff_fallback
+ |.endmacro
+ |
+ |.macro .ffunc_d, name
+ | .ffunc name
+ | ldr CARG2, [BASE, #4]
+ | cmp NARGS8:RC, #8
+ | vldr d0, [BASE]
+ | blo ->fff_fallback
+ | checktp CARG2, LJ_TISNUM
+ | bhs ->fff_fallback
+ |.endmacro
+ |
+ |.macro .ffunc_dd, name
+ | .ffunc name
+ | ldr CARG2, [BASE, #4]
+ | ldr CARG4, [BASE, #12]
+ | cmp NARGS8:RC, #16
+ | vldr d0, [BASE]
+ | vldr d1, [BASE, #8]
+ | blo ->fff_fallback
+ | checktp CARG2, LJ_TISNUM
+ | cmnlo CARG4, #-LJ_TISNUM
+ | bhs ->fff_fallback
+ |.endmacro
+ |
+ |// Inlined GC threshold check. Caveat: uses CARG1 and CARG2.
+ |.macro ffgccheck
+ | ldr CARG1, [DISPATCH, #DISPATCH_GL(gc.total)]
+ | ldr CARG2, [DISPATCH, #DISPATCH_GL(gc.threshold)]
+ | cmp CARG1, CARG2
+ | blge ->fff_gcstep
+ |.endmacro
+ |
+ |//-- Base library: checks -----------------------------------------------
+ |
+ |.ffunc_1 assert
+ | checktp CARG2, LJ_TTRUE
+ | bhi ->fff_fallback
+ | ldr PC, [BASE, FRAME_PC]
+ | strd CARG12, [BASE, #-8]
+ | mov RB, BASE
+ | subs RA, NARGS8:RC, #8
+ | add RC, NARGS8:RC, #8 // Compute (nresults+1)*8.
+ | beq ->fff_res // Done if exactly 1 argument.
+ |1:
+ | ldrd CARG12, [RB, #8]
+ | subs RA, RA, #8
+ | strd CARG12, [RB], #8
+ | bne <1
+ | b ->fff_res
+ |
+ |.ffunc type
+ | ldr CARG2, [BASE, #4]
+ | cmp NARGS8:RC, #8
+ | blo ->fff_fallback
+ | checktp CARG2, LJ_TISNUM
+ | mvnlo CARG2, #~LJ_TISNUM
+ | rsb CARG4, CARG2, #(int)(offsetof(GCfuncC, upvalue)>>3)-1
+ | lsl CARG4, CARG4, #3
+ | ldrd CARG12, [CFUNC:CARG3, CARG4]
+ | b ->fff_restv
+ |
+ |//-- Base library: getters and setters ---------------------------------
+ |
+ |.ffunc_1 getmetatable
+ | checktp CARG2, LJ_TTAB
+ | cmnne CARG2, #-LJ_TUDATA
+ | bne >6
+ |1: // Field metatable must be at same offset for GCtab and GCudata!
+ | ldr TAB:RB, TAB:CARG1->metatable
+ |2:
+ | mvn CARG2, #~LJ_TNIL
+ | ldr STR:RC, [DISPATCH, #DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])]
+ | cmp TAB:RB, #0
+ | beq ->fff_restv
+ | ldr CARG3, TAB:RB->hmask
+ | ldr CARG4, STR:RC->hash
+ | ldr NODE:INS, TAB:RB->node
+ | and CARG3, CARG3, CARG4 // idx = str->hash & tab->hmask
+ | add CARG3, CARG3, CARG3, lsl #1
+ | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8
+ |3: // Rearranged logic, because we expect _not_ to find the key.
+ | ldrd CARG34, NODE:INS->key // STALL: early NODE:INS.
+ | ldrd CARG12, NODE:INS->val
+ | ldr NODE:INS, NODE:INS->next
+ | checktp CARG4, LJ_TSTR
+ | cmpeq CARG3, STR:RC
+ | beq >5
+ | cmp NODE:INS, #0
+ | bne <3
+ |4:
+ | mov CARG1, RB // Use metatable as default result.
+ | mvn CARG2, #~LJ_TTAB
+ | b ->fff_restv
+ |5:
+ | checktp CARG2, LJ_TNIL
+ | bne ->fff_restv
+ | b <4
+ |
+ |6:
+ | checktp CARG2, LJ_TISNUM
+ | mvnhs CARG2, CARG2
+ | movlo CARG2, #~LJ_TISNUM
+ | add CARG4, DISPATCH, CARG2, lsl #2
+ | ldr TAB:RB, [CARG4, #DISPATCH_GL(gcroot[GCROOT_BASEMT])]
+ | b <2
+ |
+ |.ffunc_2 setmetatable
+ | // Fast path: no mt for table yet and not clearing the mt.
+ | checktp CARG2, LJ_TTAB
+ | ldreq TAB:RB, TAB:CARG1->metatable
+ | checktpeq CARG4, LJ_TTAB
+ | ldrbeq CARG4, TAB:CARG1->marked
+ | cmpeq TAB:RB, #0
+ | bne ->fff_fallback
+ | tst CARG4, #LJ_GC_BLACK // isblack(table)
+ | str TAB:CARG3, TAB:CARG1->metatable
+ | beq ->fff_restv
+ | barrierback TAB:CARG1, CARG4, CARG3
+ | b ->fff_restv
+ |
+ |.ffunc rawget
+ | ldrd CARG34, [BASE]
+ | cmp NARGS8:RC, #16
+ | blo ->fff_fallback
+ | mov CARG2, CARG3
+ | checktab CARG4, ->fff_fallback
+ | mov CARG1, L
+ | add CARG3, BASE, #8
+ | .IOS mov RA, BASE
+ | bl extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key)
+ | // Returns cTValue *.
+ | .IOS mov BASE, RA
+ | ldrd CARG12, [CRET1]
+ | b ->fff_restv
+ |
+ |//-- Base library: conversions ------------------------------------------
+ |
+ |.ffunc tonumber
+ | // Only handles the number case inline (without a base argument).
+ | ldrd CARG12, [BASE]
+ | cmp NARGS8:RC, #8
+ | bne ->fff_fallback
+ | checktp CARG2, LJ_TISNUM
+ | bls ->fff_restv
+ | b ->fff_fallback
+ |
+ |.ffunc_1 tostring
+ | // Only handles the string or number case inline.
+ | checktp CARG2, LJ_TSTR
+ | // A __tostring method in the string base metatable is ignored.
+ | beq ->fff_restv
+ | // Handle numbers inline, unless a number base metatable is present.
+ | ldr CARG4, [DISPATCH, #DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])]
+ | str BASE, L->base
+ | checktp CARG2, LJ_TISNUM
+ | cmpls CARG4, #0
+ | str PC, SAVE_PC // Redundant (but a defined value).
+ | bhi ->fff_fallback
+ | ffgccheck
+ | mov CARG1, L
+ | mov CARG2, BASE
+ | bl extern lj_str_fromnumber // (lua_State *L, cTValue *o)
+ | // Returns GCstr *.
+ | ldr BASE, L->base
+ | mvn CARG2, #~LJ_TSTR
+ | b ->fff_restv
+ |
+ |//-- Base library: iterators -------------------------------------------
+ |
+ |.ffunc_1 next
+ | mvn CARG4, #~LJ_TNIL
+ | checktab CARG2, ->fff_fallback
+ | strd CARG34, [BASE, NARGS8:RC] // Set missing 2nd arg to nil.
+ | ldr PC, [BASE, FRAME_PC]
+ | mov CARG2, CARG1
+ | str BASE, L->base // Add frame since C call can throw.
+ | mov CARG1, L
+ | str BASE, L->top // Dummy frame length is ok.
+ | add CARG3, BASE, #8
+ | str PC, SAVE_PC
+ | bl extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key)
+ | // Returns 0 at end of traversal.
+ | .IOS ldr BASE, L->base
+ | cmp CRET1, #0
+ | mvneq CRET2, #~LJ_TNIL
+ | beq ->fff_restv // End of traversal: return nil.
+ | ldrd CARG12, [BASE, #8] // Copy key and value to results.
+ | ldrd CARG34, [BASE, #16]
+ | mov RC, #(2+1)*8
+ | strd CARG12, [BASE, #-8]
+ | strd CARG34, [BASE]
+ | b ->fff_res
+ |
+ |.ffunc_1 pairs
+ | checktab CARG2, ->fff_fallback
+#if LJ_52
+ | ldr TAB:RB, TAB:CARG1->metatable
+#endif
+ | ldrd CFUNC:CARG34, CFUNC:CARG3->upvalue[0]
+ | ldr PC, [BASE, FRAME_PC]
+#if LJ_52
+ | cmp TAB:RB, #0
+ | bne ->fff_fallback
+#endif
+ | mvn CARG2, #~LJ_TNIL
+ | mov RC, #(3+1)*8
+ | strd CFUNC:CARG34, [BASE, #-8]
+ | str CARG2, [BASE, #12]
+ | b ->fff_res
+ |
+ |.ffunc_2 ipairs_aux
+ | checktp CARG2, LJ_TTAB
+ | checktpeq CARG4, LJ_TISNUM
+ | bne ->fff_fallback
+ | ldr RB, TAB:CARG1->asize
+ | ldr RC, TAB:CARG1->array
+ | add CARG3, CARG3, #1
+ | ldr PC, [BASE, FRAME_PC]
+ | cmp CARG3, RB
+ | add RC, RC, CARG3, lsl #3
+ | strd CARG34, [BASE, #-8]
+ | ldrdlo CARG12, [RC]
+ | mov RC, #(0+1)*8
+ | bhs >2 // Not in array part?
+ |1:
+ | checktp CARG2, LJ_TNIL
+ | movne RC, #(2+1)*8
+ | strdne CARG12, [BASE]
+ | b ->fff_res
+ |2: // Check for empty hash part first. Otherwise call C function.
+ | ldr RB, TAB:CARG1->hmask
+ | mov CARG2, CARG3
+ | cmp RB, #0
+ | beq ->fff_res
+ | .IOS mov RA, BASE
+ | bl extern lj_tab_getinth // (GCtab *t, int32_t key)
+ | // Returns cTValue * or NULL.
+ | .IOS mov BASE, RA
+ | cmp CRET1, #0
+ | beq ->fff_res
+ | ldrd CARG12, [CRET1]
+ | b <1
+ |
+ |.ffunc_1 ipairs
+ | checktab CARG2, ->fff_fallback
+#if LJ_52
+ | ldr TAB:RB, TAB:CARG1->metatable
+#endif
+ | ldrd CFUNC:CARG34, CFUNC:CARG3->upvalue[0]
+ | ldr PC, [BASE, FRAME_PC]
+#if LJ_52
+ | cmp TAB:RB, #0
+ | bne ->fff_fallback
+#endif
+ | mov CARG1, #0
+ | mvn CARG2, #~LJ_TISNUM
+ | mov RC, #(3+1)*8
+ | strd CFUNC:CARG34, [BASE, #-8]
+ | strd CARG12, [BASE, #8]
+ | b ->fff_res
+ |
+ |//-- Base library: catch errors ----------------------------------------
+ |
+ |.ffunc pcall
+ | ldrb RA, [DISPATCH, #DISPATCH_GL(hookmask)]
+ | cmp NARGS8:RC, #8
+ | blo ->fff_fallback
+ | tst RA, #HOOK_ACTIVE // Remember active hook before pcall.
+ | mov RB, BASE
+ | add BASE, BASE, #8
+ | moveq PC, #8+FRAME_PCALL
+ | movne PC, #8+FRAME_PCALLH
+ | sub NARGS8:RC, NARGS8:RC, #8
+ | b ->vm_call_dispatch
+ |
+ |.ffunc_2 xpcall
+ | ldrb RA, [DISPATCH, #DISPATCH_GL(hookmask)]
+ | checkfunc CARG4, ->fff_fallback // Traceback must be a function.
+ | mov RB, BASE
+ | strd CARG12, [BASE, #8] // Swap function and traceback.
+ | strd CARG34, [BASE]
+ | tst RA, #HOOK_ACTIVE // Remember active hook before pcall.
+ | add BASE, BASE, #16
+ | moveq PC, #16+FRAME_PCALL
+ | movne PC, #16+FRAME_PCALLH
+ | sub NARGS8:RC, NARGS8:RC, #16
+ | b ->vm_call_dispatch
+ |
+ |//-- Coroutine library --------------------------------------------------
+ |
+ |.macro coroutine_resume_wrap, resume
+ |.if resume
+ |.ffunc_1 coroutine_resume
+ | checktp CARG2, LJ_TTHREAD
+ | bne ->fff_fallback
+ |.else
+ |.ffunc coroutine_wrap_aux
+ | ldr L:CARG1, CFUNC:CARG3->upvalue[0].gcr
+ |.endif
+ | ldr PC, [BASE, FRAME_PC]
+ | str BASE, L->base
+ | ldr CARG2, L:CARG1->top
+ | ldrb RA, L:CARG1->status
+ | ldr RB, L:CARG1->base
+ | add CARG3, CARG2, NARGS8:RC
+ | add CARG4, CARG2, RA
+ | str PC, SAVE_PC
+ | cmp CARG4, RB
+ | beq ->fff_fallback
+ | ldr CARG4, L:CARG1->maxstack
+ | ldr RB, L:CARG1->cframe
+ | cmp RA, #LUA_YIELD
+ | cmpls CARG3, CARG4
+ | cmpls RB, #0
+ | bhi ->fff_fallback
+ |1:
+ |.if resume
+ | sub CARG3, CARG3, #8 // Keep resumed thread in stack for GC.
+ | add BASE, BASE, #8
+ | sub NARGS8:RC, NARGS8:RC, #8
+ |.endif
+ | str CARG3, L:CARG1->top
+ | str BASE, L->top
+ |2: // Move args to coroutine.
+ | ldrd CARG34, [BASE, RB]
+ | cmp RB, NARGS8:RC
+ | strdne CARG34, [CARG2, RB]
+ | add RB, RB, #8
+ | bne <2
+ |
+ | mov CARG3, #0
+ | mov L:RA, L:CARG1
+ | mov CARG4, #0
+ | bl ->vm_resume // (lua_State *L, TValue *base, 0, 0)
+ | // Returns thread status.
+ |4:
+ | ldr CARG3, L:RA->base
+ | mv_vmstate CARG2, INTERP
+ | ldr CARG4, L:RA->top
+ | st_vmstate CARG2
+ | cmp CRET1, #LUA_YIELD
+ | ldr BASE, L->base
+ | bhi >8
+ | subs RC, CARG4, CARG3
+ | ldr CARG1, L->maxstack
+ | add CARG2, BASE, RC
+ | beq >6 // No results?
+ | cmp CARG2, CARG1
+ | mov RB, #0
+ | bhi >9 // Need to grow stack?
+ |
+ | sub CARG4, RC, #8
+ | str CARG3, L:RA->top // Clear coroutine stack.
+ |5: // Move results from coroutine.
+ | ldrd CARG12, [CARG3, RB]
+ | cmp RB, CARG4
+ | strd CARG12, [BASE, RB]
+ | add RB, RB, #8
+ | bne <5
+ |6:
+ |.if resume
+ | mvn CARG3, #~LJ_TTRUE
+ | add RC, RC, #16
+ |7:
+ | str CARG3, [BASE, #-4] // Prepend true/false to results.
+ | sub RA, BASE, #8
+ |.else
+ | mov RA, BASE
+ | add RC, RC, #8
+ |.endif
+ | ands CARG1, PC, #FRAME_TYPE
+ | str PC, SAVE_PC
+ | str RC, SAVE_MULTRES
+ | beq ->BC_RET_Z
+ | b ->vm_return
+ |
+ |8: // Coroutine returned with error (at co->top-1).
+ |.if resume
+ | ldrd CARG12, [CARG4, #-8]!
+ | mvn CARG3, #~LJ_TFALSE
+ | mov RC, #(2+1)*8
+ | str CARG4, L:RA->top // Remove error from coroutine stack.
+ | strd CARG12, [BASE] // Copy error message.
+ | b <7
+ |.else
+ | mov CARG1, L
+ | mov CARG2, L:RA
+ | bl extern lj_ffh_coroutine_wrap_err // (lua_State *L, lua_State *co)
+ | // Never returns.
+ |.endif
+ |
+ |9: // Handle stack expansion on return from yield.
+ | mov CARG1, L
+ | lsr CARG2, RC, #3
+ | bl extern lj_state_growstack // (lua_State *L, int n)
+ | mov CRET1, #0
+ | b <4
+ |.endmacro
+ |
+ | coroutine_resume_wrap 1 // coroutine.resume
+ | coroutine_resume_wrap 0 // coroutine.wrap
+ |
+ |.ffunc coroutine_yield
+ | ldr CARG1, L->cframe
+ | add CARG2, BASE, NARGS8:RC
+ | str BASE, L->base
+ | tst CARG1, #CFRAME_RESUME
+ | str CARG2, L->top
+ | mov CRET1, #LUA_YIELD
+ | mov CARG3, #0
+ | beq ->fff_fallback
+ | str CARG3, L->cframe
+ | strb CRET1, L->status
+ | b ->vm_leave_unw
+ |
+ |//-- Math library -------------------------------------------------------
+ |
+ |.macro math_round, func
+ | .ffunc_1 math_ .. func
+ | checktp CARG2, LJ_TISNUM
+ | beq ->fff_restv
+ | bhi ->fff_fallback
+ | // Round FP value and normalize result.
+ | lsl CARG3, CARG2, #1
+ | adds RB, CARG3, #0x00200000
+ | bpl >2 // |x| < 1?
+ | mvn CARG4, #0x3e0
+ | subs RB, CARG4, RB, asr #21
+ | lsl CARG4, CARG2, #11
+ | lsl CARG3, CARG1, #11
+ | orr CARG4, CARG4, #0x80000000
+ | rsb INS, RB, #32
+ | orr CARG4, CARG4, CARG1, lsr #21
+ | bls >3 // |x| >= 2^31?
+ | orr CARG3, CARG3, CARG4, lsl INS
+ | lsr CARG1, CARG4, RB
+ |.if "func" == "floor"
+ | tst CARG3, CARG2, asr #31
+ | addne CARG1, CARG1, #1
+ |.else
+ | bics CARG3, CARG3, CARG2, asr #31
+ | addsne CARG1, CARG1, #1
+ | ldrdvs CARG12, >9
+ | bvs ->fff_restv
+ |.endif
+ | cmp CARG2, #0
+ | rsblt CARG1, CARG1, #0
+ |1:
+ | mvn CARG2, #~LJ_TISNUM
+ | b ->fff_restv
+ |
+ |2: // |x| < 1
+ | bcs ->fff_restv // |x| is not finite.
+ | orr CARG3, CARG3, CARG1 // ztest = abs(hi) | lo
+ |.if "func" == "floor"
+ | tst CARG3, CARG2, asr #31 // return (ztest & sign) == 0 ? 0 : -1
+ | moveq CARG1, #0
+ | mvnne CARG1, #0
+ |.else
+ | bics CARG3, CARG3, CARG2, asr #31 // return (ztest & ~sign) == 0 ? 0 : 1
+ | moveq CARG1, #0
+ | movne CARG1, #1
+ |.endif
+ | mvn CARG2, #~LJ_TISNUM
+ | b ->fff_restv
+ |
+ |3: // |x| >= 2^31. Check for x == -(2^31).
+ | cmpeq CARG4, #0x80000000
+ |.if "func" == "floor"
+ | cmpeq CARG3, #0
+ |.endif
+ | bne >4
+ | cmp CARG2, #0
+ | movmi CARG1, #0x80000000
+ | bmi <1
+ |4:
+ | bl ->vm_..func.._sf
+ | b ->fff_restv
+ |.endmacro
+ |
+ | math_round floor
+ | math_round ceil
+ |
+ |.align 8
+ |9:
+ | .long 0x00000000, 0x41e00000 // 2^31.
+ |
+ |.ffunc_1 math_abs
+ | checktp CARG2, LJ_TISNUM
+ | bhi ->fff_fallback
+ | bicne CARG2, CARG2, #0x80000000
+ | bne ->fff_restv
+ | cmp CARG1, #0
+ | rsbslt CARG1, CARG1, #0
+ | ldrdvs CARG12, <9
+ | // Fallthrough.
+ |
+ |->fff_restv:
+ | // CARG12 = TValue result.
+ | ldr PC, [BASE, FRAME_PC]
+ | strd CARG12, [BASE, #-8]
+ |->fff_res1:
+ | // PC = return.
+ | mov RC, #(1+1)*8
+ |->fff_res:
+ | // RC = (nresults+1)*8, PC = return.
+ | ands CARG1, PC, #FRAME_TYPE
+ | ldreq INS, [PC, #-4]
+ | str RC, SAVE_MULTRES
+ | sub RA, BASE, #8
+ | bne ->vm_return
+ | decode_RB8 RB, INS
+ |5:
+ | cmp RB, RC // More results expected?
+ | bhi >6
+ | decode_RA8 CARG1, INS
+ | ins_next1
+ | ins_next2
+ | // Adjust BASE. KBASE is assumed to be set for the calling frame.
+ | sub BASE, RA, CARG1
+ | ins_next3
+ |
+ |6: // Fill up results with nil.
+ | add CARG2, RA, RC
+ | mvn CARG1, #~LJ_TNIL
+ | add RC, RC, #8
+ | str CARG1, [CARG2, #-4]
+ | b <5
+ |
+ |.macro math_extern, func
+ |.if HFABI
+ | .ffunc_d math_ .. func
+ |.else
+ | .ffunc_n math_ .. func
+ |.endif
+ | .IOS mov RA, BASE
+ | bl extern func
+ | .IOS mov BASE, RA
+ |.if HFABI
+ | b ->fff_resd
+ |.else
+ | b ->fff_restv
+ |.endif
+ |.endmacro
+ |
+ |.macro math_extern2, func
+ |.if HFABI
+ | .ffunc_dd math_ .. func
+ |.else
+ | .ffunc_nn math_ .. func
+ |.endif
+ | .IOS mov RA, BASE
+ | bl extern func
+ | .IOS mov BASE, RA
+ |.if HFABI
+ | b ->fff_resd
+ |.else
+ | b ->fff_restv
+ |.endif
+ |.endmacro
+ |
+ |.if FPU
+ | .ffunc_d math_sqrt
+ | vsqrt.f64 d0, d0
+ |->fff_resd:
+ | ldr PC, [BASE, FRAME_PC]
+ | vstr d0, [BASE, #-8]
+ | b ->fff_res1
+ |.else
+ | math_extern sqrt
+ |.endif
+ |
+ |.ffunc math_log
+ |.if HFABI
+ | ldr CARG2, [BASE, #4]
+ | cmp NARGS8:RC, #8 // Need exactly 1 argument.
+ | vldr d0, [BASE]
+ | bne ->fff_fallback
+ |.else
+ | ldrd CARG12, [BASE]
+ | cmp NARGS8:RC, #8 // Need exactly 1 argument.
+ | bne ->fff_fallback
+ |.endif
+ | checktp CARG2, LJ_TISNUM
+ | bhs ->fff_fallback
+ | .IOS mov RA, BASE
+ | bl extern log
+ | .IOS mov BASE, RA
+ |.if HFABI
+ | b ->fff_resd
+ |.else
+ | b ->fff_restv
+ |.endif
+ |
+ | math_extern log10
+ | math_extern exp
+ | math_extern sin
+ | math_extern cos
+ | math_extern tan
+ | math_extern asin
+ | math_extern acos
+ | math_extern atan
+ | math_extern sinh
+ | math_extern cosh
+ | math_extern tanh
+ | math_extern2 pow
+ | math_extern2 atan2
+ | math_extern2 fmod
+ |
+ |->ff_math_deg:
+ |.if FPU
+ | .ffunc_d math_rad
+ | vldr d1, CFUNC:CARG3->upvalue[0]
+ | vmul.f64 d0, d0, d1
+ | b ->fff_resd
+ |.else
+ | .ffunc_n math_rad
+ | ldrd CARG34, CFUNC:CARG3->upvalue[0]
+ | bl extern __aeabi_dmul
+ | b ->fff_restv
+ |.endif
+ |
+ |.if HFABI
+ | .ffunc math_ldexp
+ | ldr CARG4, [BASE, #4]
+ | ldrd CARG12, [BASE, #8]
+ | cmp NARGS8:RC, #16
+ | blo ->fff_fallback
+ | vldr d0, [BASE]
+ | checktp CARG4, LJ_TISNUM
+ | bhs ->fff_fallback
+ | checktp CARG2, LJ_TISNUM
+ | bne ->fff_fallback
+ | .IOS mov RA, BASE
+ | bl extern ldexp // (double x, int exp)
+ | .IOS mov BASE, RA
+ | b ->fff_resd
+ |.else
+ |.ffunc_2 math_ldexp
+ | checktp CARG2, LJ_TISNUM
+ | bhs ->fff_fallback
+ | checktp CARG4, LJ_TISNUM
+ | bne ->fff_fallback
+ | .IOS mov RA, BASE
+ | bl extern ldexp // (double x, int exp)
+ | .IOS mov BASE, RA
+ | b ->fff_restv
+ |.endif
+ |
+ |.if HFABI
+ |.ffunc_d math_frexp
+ | mov CARG1, sp
+ | .IOS mov RA, BASE
+ | bl extern frexp
+ | .IOS mov BASE, RA
+ | ldr CARG3, [sp]
+ | mvn CARG4, #~LJ_TISNUM
+ | ldr PC, [BASE, FRAME_PC]
+ | vstr d0, [BASE, #-8]
+ | mov RC, #(2+1)*8
+ | strd CARG34, [BASE]
+ | b ->fff_res
+ |.else
+ |.ffunc_n math_frexp
+ | mov CARG3, sp
+ | .IOS mov RA, BASE
+ | bl extern frexp
+ | .IOS mov BASE, RA
+ | ldr CARG3, [sp]
+ | mvn CARG4, #~LJ_TISNUM
+ | ldr PC, [BASE, FRAME_PC]
+ | strd CARG12, [BASE, #-8]
+ | mov RC, #(2+1)*8
+ | strd CARG34, [BASE]
+ | b ->fff_res
+ |.endif
+ |
+ |.if HFABI
+ |.ffunc_d math_modf
+ | sub CARG1, BASE, #8
+ | ldr PC, [BASE, FRAME_PC]
+ | .IOS mov RA, BASE
+ | bl extern modf
+ | .IOS mov BASE, RA
+ | mov RC, #(2+1)*8
+ | vstr d0, [BASE]
+ | b ->fff_res
+ |.else
+ |.ffunc_n math_modf
+ | sub CARG3, BASE, #8
+ | ldr PC, [BASE, FRAME_PC]
+ | .IOS mov RA, BASE
+ | bl extern modf
+ | .IOS mov BASE, RA
+ | mov RC, #(2+1)*8
+ | strd CARG12, [BASE]
+ | b ->fff_res
+ |.endif
+ |
+ |.macro math_minmax, name, cond, fcond
+ |.if FPU
+ | .ffunc_1 name
+ | add RB, BASE, RC
+ | checktp CARG2, LJ_TISNUM
+ | add RA, BASE, #8
+ | bne >4
+ |1: // Handle integers.
+ | ldrd CARG34, [RA]
+ | cmp RA, RB
+ | bhs ->fff_restv
+ | checktp CARG4, LJ_TISNUM
+ | bne >3
+ | cmp CARG1, CARG3
+ | add RA, RA, #8
+ | mov..cond CARG1, CARG3
+ | b <1
+ |3: // Convert intermediate result to number and continue below.
+ | vmov s4, CARG1
+ | bhi ->fff_fallback
+ | vldr d1, [RA]
+ | vcvt.f64.s32 d0, s4
+ | b >6
+ |
+ |4:
+ | vldr d0, [BASE]
+ | bhi ->fff_fallback
+ |5: // Handle numbers.
+ | ldrd CARG34, [RA]
+ | vldr d1, [RA]
+ | cmp RA, RB
+ | bhs ->fff_resd
+ | checktp CARG4, LJ_TISNUM
+ | bhs >7
+ |6:
+ | vcmp.f64 d0, d1
+ | vmrs
+ | add RA, RA, #8
+ | vmov..fcond.f64 d0, d1
+ | b <5
+ |7: // Convert integer to number and continue above.
+ | vmov s4, CARG3
+ | bhi ->fff_fallback
+ | vcvt.f64.s32 d1, s4
+ | b <6
+ |
+ |.else
+ |
+ | .ffunc_1 name
+ | checktp CARG2, LJ_TISNUM
+ | mov RA, #8
+ | bne >4
+ |1: // Handle integers.
+ | ldrd CARG34, [BASE, RA]
+ | cmp RA, RC
+ | bhs ->fff_restv
+ | checktp CARG4, LJ_TISNUM
+ | bne >3
+ | cmp CARG1, CARG3
+ | add RA, RA, #8
+ | mov..cond CARG1, CARG3
+ | b <1
+ |3: // Convert intermediate result to number and continue below.
+ | bhi ->fff_fallback
+ | bl extern __aeabi_i2d
+ | ldrd CARG34, [BASE, RA]
+ | b >6
+ |
+ |4:
+ | bhi ->fff_fallback
+ |5: // Handle numbers.
+ | ldrd CARG34, [BASE, RA]
+ | cmp RA, RC
+ | bhs ->fff_restv
+ | checktp CARG4, LJ_TISNUM
+ | bhs >7
+ |6:
+ | bl extern __aeabi_cdcmple
+ | add RA, RA, #8
+ | mov..fcond CARG1, CARG3
+ | mov..fcond CARG2, CARG4
+ | b <5
+ |7: // Convert integer to number and continue above.
+ | bhi ->fff_fallback
+ | strd CARG12, TMPD
+ | mov CARG1, CARG3
+ | bl extern __aeabi_i2d
+ | ldrd CARG34, TMPD
+ | b <6
+ |.endif
+ |.endmacro
+ |
+ | math_minmax math_min, gt, hi
+ | math_minmax math_max, lt, lo
+ |
+ |//-- String library -----------------------------------------------------
+ |
+ |.ffunc_1 string_len
+ | checkstr CARG2, ->fff_fallback
+ | ldr CARG1, STR:CARG1->len
+ | mvn CARG2, #~LJ_TISNUM
+ | b ->fff_restv
+ |
+ |.ffunc string_byte // Only handle the 1-arg case here.
+ | ldrd CARG12, [BASE]
+ | ldr PC, [BASE, FRAME_PC]
+ | cmp NARGS8:RC, #8
+ | checktpeq CARG2, LJ_TSTR // Need exactly 1 argument.
+ | bne ->fff_fallback
+ | ldr CARG3, STR:CARG1->len
+ | ldrb CARG1, STR:CARG1[1] // Access is always ok (NUL at end).
+ | mvn CARG2, #~LJ_TISNUM
+ | cmp CARG3, #0
+ | moveq RC, #(0+1)*8
+ | movne RC, #(1+1)*8
+ | strd CARG12, [BASE, #-8]
+ | b ->fff_res
+ |
+ |.ffunc string_char // Only handle the 1-arg case here.
+ | ffgccheck
+ | ldrd CARG12, [BASE]
+ | ldr PC, [BASE, FRAME_PC]
+ | cmp NARGS8:RC, #8 // Need exactly 1 argument.
+ | checktpeq CARG2, LJ_TISNUM
+ | bicseq CARG4, CARG1, #255
+ | mov CARG3, #1
+ | bne ->fff_fallback
+ | str CARG1, TMPD
+ | mov CARG2, TMPDp // Points to stack. Little-endian.
+ |->fff_newstr:
+ | // CARG2 = str, CARG3 = len.
+ | str BASE, L->base
+ | mov CARG1, L
+ | str PC, SAVE_PC
+ | bl extern lj_str_new // (lua_State *L, char *str, size_t l)
+ | // Returns GCstr *.
+ | ldr BASE, L->base
+ | mvn CARG2, #~LJ_TSTR
+ | b ->fff_restv
+ |
+ |.ffunc string_sub
+ | ffgccheck
+ | ldrd CARG12, [BASE]
+ | ldrd CARG34, [BASE, #16]
+ | cmp NARGS8:RC, #16
+ | mvn RB, #0
+ | beq >1
+ | blo ->fff_fallback
+ | checktp CARG4, LJ_TISNUM
+ | mov RB, CARG3
+ | bne ->fff_fallback
+ |1:
+ | ldrd CARG34, [BASE, #8]
+ | checktp CARG2, LJ_TSTR
+ | ldreq CARG2, STR:CARG1->len
+ | checktpeq CARG4, LJ_TISNUM
+ | bne ->fff_fallback
+ | // CARG1 = str, CARG2 = str->len, CARG3 = start, RB = end
+ | add CARG4, CARG2, #1
+ | cmp CARG3, #0 // if (start < 0) start += len+1
+ | addlt CARG3, CARG3, CARG4
+ | cmp CARG3, #1 // if (start < 1) start = 1
+ | movlt CARG3, #1
+ | cmp RB, #0 // if (end < 0) end += len+1
+ | addlt RB, RB, CARG4
+ | bic RB, RB, RB, asr #31 // if (end < 0) end = 0
+ | cmp RB, CARG2 // if (end > len) end = len
+ | add CARG1, STR:CARG1, #sizeof(GCstr)-1
+ | movgt RB, CARG2
+ | add CARG2, CARG1, CARG3
+ | subs CARG3, RB, CARG3 // len = end - start
+ | add CARG3, CARG3, #1 // len += 1
+ | bge ->fff_newstr
+ |->fff_emptystr:
+ | sub STR:CARG1, DISPATCH, #-DISPATCH_GL(strempty)
+ | mvn CARG2, #~LJ_TSTR
+ | b ->fff_restv
+ |
+ |.ffunc string_rep // Only handle the 1-char case inline.
+ | ffgccheck
+ | ldrd CARG12, [BASE]
+ | ldrd CARG34, [BASE, #8]
+ | cmp NARGS8:RC, #16
+ | bne ->fff_fallback // Exactly 2 arguments
+ | checktp CARG2, LJ_TSTR
+ | checktpeq CARG4, LJ_TISNUM
+ | bne ->fff_fallback
+ | subs CARG4, CARG3, #1
+ | ldr CARG2, STR:CARG1->len
+ | blt ->fff_emptystr // Count <= 0?
+ | cmp CARG2, #1
+ | blo ->fff_emptystr // Zero-length string?
+ | bne ->fff_fallback // Fallback for > 1-char strings.
+ | ldr RB, [DISPATCH, #DISPATCH_GL(tmpbuf.sz)]
+ | ldr CARG2, [DISPATCH, #DISPATCH_GL(tmpbuf.buf)]
+ | ldr CARG1, STR:CARG1[1]
+ | cmp RB, CARG3
+ | blo ->fff_fallback
+ |1: // Fill buffer with char.
+ | strb CARG1, [CARG2, CARG4]
+ | subs CARG4, CARG4, #1
+ | bge <1
+ | b ->fff_newstr
+ |
+ |.ffunc string_reverse
+ | ffgccheck
+ | ldrd CARG12, [BASE]
+ | cmp NARGS8:RC, #8
+ | blo ->fff_fallback
+ | checkstr CARG2, ->fff_fallback
+ | ldr CARG3, STR:CARG1->len
+ | ldr RB, [DISPATCH, #DISPATCH_GL(tmpbuf.sz)]
+ | ldr CARG2, [DISPATCH, #DISPATCH_GL(tmpbuf.buf)]
+ | mov CARG4, CARG3
+ | add CARG1, STR:CARG1, #sizeof(GCstr)
+ | cmp RB, CARG3
+ | blo ->fff_fallback
+ |1: // Reverse string copy.
+ | ldrb RB, [CARG1], #1
+ | subs CARG4, CARG4, #1
+ | blt ->fff_newstr
+ | strb RB, [CARG2, CARG4]
+ | b <1
+ |
+ |.macro ffstring_case, name, lo
+ | .ffunc name
+ | ffgccheck
+ | ldrd CARG12, [BASE]
+ | cmp NARGS8:RC, #8
+ | blo ->fff_fallback
+ | checkstr CARG2, ->fff_fallback
+ | ldr CARG3, STR:CARG1->len
+ | ldr RB, [DISPATCH, #DISPATCH_GL(tmpbuf.sz)]
+ | ldr CARG2, [DISPATCH, #DISPATCH_GL(tmpbuf.buf)]
+ | mov CARG4, #0
+ | add CARG1, STR:CARG1, #sizeof(GCstr)
+ | cmp RB, CARG3
+ | blo ->fff_fallback
+ |1: // ASCII case conversion.
+ | ldrb RB, [CARG1, CARG4]
+ | cmp CARG4, CARG3
+ | bhs ->fff_newstr
+ | sub RC, RB, #lo
+ | cmp RC, #26
+ | eorlo RB, RB, #0x20
+ | strb RB, [CARG2, CARG4]
+ | add CARG4, CARG4, #1
+ | b <1
+ |.endmacro
+ |
+ |ffstring_case string_lower, 65
+ |ffstring_case string_upper, 97
+ |
+ |//-- Table library ------------------------------------------------------
+ |
+ |.ffunc_1 table_getn
+ | checktab CARG2, ->fff_fallback
+ | .IOS mov RA, BASE
+ | bl extern lj_tab_len // (GCtab *t)
+ | // Returns uint32_t (but less than 2^31).
+ | .IOS mov BASE, RA
+ | mvn CARG2, #~LJ_TISNUM
+ | b ->fff_restv
+ |
+ |//-- Bit library --------------------------------------------------------
+ |
+ |// FP number to bit conversion for soft-float. Clobbers r0-r3.
+ |->vm_tobit_fb:
+ | bhi ->fff_fallback
+ |->vm_tobit:
+ | lsl RB, CARG2, #1
+ | adds RB, RB, #0x00200000
+ | movpl CARG1, #0 // |x| < 1?
+ | bxpl lr
+ | mvn CARG4, #0x3e0
+ | subs RB, CARG4, RB, asr #21
+ | bmi >1 // |x| >= 2^32?
+ | lsl CARG4, CARG2, #11
+ | orr CARG4, CARG4, #0x80000000
+ | orr CARG4, CARG4, CARG1, lsr #21
+ | cmp CARG2, #0
+ | lsr CARG1, CARG4, RB
+ | rsblt CARG1, CARG1, #0
+ | bx lr
+ |1:
+ | add RB, RB, #21
+ | lsr CARG4, CARG1, RB
+ | rsb RB, RB, #20
+ | lsl CARG1, CARG2, #12
+ | cmp CARG2, #0
+ | orr CARG1, CARG4, CARG1, lsl RB
+ | rsblt CARG1, CARG1, #0
+ | bx lr
+ |
+ |.macro .ffunc_bit, name
+ | .ffunc_1 bit_..name
+ | checktp CARG2, LJ_TISNUM
+ | blne ->vm_tobit_fb
+ |.endmacro
+ |
+ |.ffunc_bit tobit
+ | mvn CARG2, #~LJ_TISNUM
+ | b ->fff_restv
+ |
+ |.macro .ffunc_bit_op, name, ins
+ | .ffunc_bit name
+ | mov CARG3, CARG1
+ | mov RA, #8
+ |1:
+ | ldrd CARG12, [BASE, RA]
+ | cmp RA, NARGS8:RC
+ | add RA, RA, #8
+ | bge >2
+ | checktp CARG2, LJ_TISNUM
+ | blne ->vm_tobit_fb
+ | ins CARG3, CARG3, CARG1
+ | b <1
+ |.endmacro
+ |
+ |.ffunc_bit_op band, and
+ |.ffunc_bit_op bor, orr
+ |.ffunc_bit_op bxor, eor
+ |
+ |2:
+ | mvn CARG4, #~LJ_TISNUM
+ | ldr PC, [BASE, FRAME_PC]
+ | strd CARG34, [BASE, #-8]
+ | b ->fff_res1
+ |
+ |.ffunc_bit bswap
+ | eor CARG3, CARG1, CARG1, ror #16
+ | bic CARG3, CARG3, #0x00ff0000
+ | ror CARG1, CARG1, #8
+ | mvn CARG2, #~LJ_TISNUM
+ | eor CARG1, CARG1, CARG3, lsr #8
+ | b ->fff_restv
+ |
+ |.ffunc_bit bnot
+ | mvn CARG1, CARG1
+ | mvn CARG2, #~LJ_TISNUM
+ | b ->fff_restv
+ |
+ |.macro .ffunc_bit_sh, name, ins, shmod
+ | .ffunc bit_..name
+ | ldrd CARG12, [BASE, #8]
+ | cmp NARGS8:RC, #16
+ | blo ->fff_fallback
+ | checktp CARG2, LJ_TISNUM
+ | blne ->vm_tobit_fb
+ |.if shmod == 0
+ | and RA, CARG1, #31
+ |.else
+ | rsb RA, CARG1, #0
+ |.endif
+ | ldrd CARG12, [BASE]
+ | checktp CARG2, LJ_TISNUM
+ | blne ->vm_tobit_fb
+ | ins CARG1, CARG1, RA
+ | mvn CARG2, #~LJ_TISNUM
+ | b ->fff_restv
+ |.endmacro
+ |
+ |.ffunc_bit_sh lshift, lsl, 0
+ |.ffunc_bit_sh rshift, lsr, 0
+ |.ffunc_bit_sh arshift, asr, 0
+ |.ffunc_bit_sh rol, ror, 1
+ |.ffunc_bit_sh ror, ror, 0
+ |
+ |//-----------------------------------------------------------------------
+ |
+ |->fff_fallback: // Call fast function fallback handler.
+ | // BASE = new base, RC = nargs*8
+ | ldr CARG3, [BASE, FRAME_FUNC]
+ | ldr CARG2, L->maxstack
+ | add CARG1, BASE, NARGS8:RC
+ | ldr PC, [BASE, FRAME_PC] // Fallback may overwrite PC.
+ | str CARG1, L->top
+ | ldr CARG3, CFUNC:CARG3->f
+ | str BASE, L->base
+ | add CARG1, CARG1, #8*LUA_MINSTACK
+ | str PC, SAVE_PC // Redundant (but a defined value).
+ | cmp CARG1, CARG2
+ | mov CARG1, L
+ | bhi >5 // Need to grow stack.
+ | blx CARG3 // (lua_State *L)
+ | // Either throws an error, or recovers and returns -1, 0 or nresults+1.
+ | ldr BASE, L->base
+ | cmp CRET1, #0
+ | lsl RC, CRET1, #3
+ | sub RA, BASE, #8
+ | bgt ->fff_res // Returned nresults+1?
+ |1: // Returned 0 or -1: retry fast path.
+ | ldr CARG1, L->top
+ | ldr LFUNC:CARG3, [BASE, FRAME_FUNC]
+ | sub NARGS8:RC, CARG1, BASE
+ | bne ->vm_call_tail // Returned -1?
+ | ins_callt // Returned 0: retry fast path.
+ |
+ |// Reconstruct previous base for vmeta_call during tailcall.
+ |->vm_call_tail:
+ | ands CARG1, PC, #FRAME_TYPE
+ | bic CARG2, PC, #FRAME_TYPEP
+ | ldreq INS, [PC, #-4]
+ | andeq CARG2, MASKR8, INS, lsr #5 // Conditional decode_RA8.
+ | addeq CARG2, CARG2, #8
+ | sub RB, BASE, CARG2
+ | b ->vm_call_dispatch // Resolve again for tailcall.
+ |
+ |5: // Grow stack for fallback handler.
+ | mov CARG2, #LUA_MINSTACK
+ | bl extern lj_state_growstack // (lua_State *L, int n)
+ | ldr BASE, L->base
+ | cmp CARG1, CARG1 // Set zero-flag to force retry.
+ | b <1
+ |
+ |->fff_gcstep: // Call GC step function.
+ | // BASE = new base, RC = nargs*8
+ | mov RA, lr
+ | str BASE, L->base
+ | add CARG2, BASE, NARGS8:RC
+ | str PC, SAVE_PC // Redundant (but a defined value).
+ | str CARG2, L->top
+ | mov CARG1, L
+ | bl extern lj_gc_step // (lua_State *L)
+ | ldr BASE, L->base
+ | mov lr, RA // Help return address predictor.
+ | ldr CFUNC:CARG3, [BASE, FRAME_FUNC]
+ | bx lr
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Special dispatch targets -------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_record: // Dispatch target for recording phase.
+ |.if JIT
+ | ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)]
+ | tst CARG1, #HOOK_VMEVENT // No recording while in vmevent.
+ | bne >5
+ | // Decrement the hookcount for consistency, but always do the call.
+ | ldr CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]
+ | tst CARG1, #HOOK_ACTIVE
+ | bne >1
+ | sub CARG2, CARG2, #1
+ | tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT
+ | strne CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]
+ | b >1
+ |.endif
+ |
+ |->vm_rethook: // Dispatch target for return hooks.
+ | ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)]
+ | tst CARG1, #HOOK_ACTIVE // Hook already active?
+ | beq >1
+ |5: // Re-dispatch to static ins.
+ | decode_OP OP, INS
+ | add OP, DISPATCH, OP, lsl #2
+ | ldr pc, [OP, #GG_DISP2STATIC]
+ |
+ |->vm_inshook: // Dispatch target for instr/line hooks.
+ | ldrb CARG1, [DISPATCH, #DISPATCH_GL(hookmask)]
+ | ldr CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]
+ | tst CARG1, #HOOK_ACTIVE // Hook already active?
+ | bne <5
+ | tst CARG1, #LUA_MASKLINE|LUA_MASKCOUNT
+ | beq <5
+ | subs CARG2, CARG2, #1
+ | str CARG2, [DISPATCH, #DISPATCH_GL(hookcount)]
+ | beq >1
+ | tst CARG1, #LUA_MASKLINE
+ | beq <5
+ |1:
+ | mov CARG1, L
+ | str BASE, L->base
+ | mov CARG2, PC
+ | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.
+ | bl extern lj_dispatch_ins // (lua_State *L, const BCIns *pc)
+ |3:
+ | ldr BASE, L->base
+ |4: // Re-dispatch to static ins.
+ | ldrb OP, [PC, #-4]
+ | ldr INS, [PC, #-4]
+ | add OP, DISPATCH, OP, lsl #2
+ | ldr OP, [OP, #GG_DISP2STATIC]
+ | decode_RA8 RA, INS
+ | decode_RD RC, INS
+ | bx OP
+ |
+ |->cont_hook: // Continue from hook yield.
+ | ldr CARG1, [CARG4, #-24]
+ | add PC, PC, #4
+ | str CARG1, SAVE_MULTRES // Restore MULTRES for *M ins.
+ | b <4
+ |
+ |->vm_hotloop: // Hot loop counter underflow.
+ |.if JIT
+ | ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Same as curr_topL(L).
+ | sub CARG1, DISPATCH, #-GG_DISP2J
+ | str PC, SAVE_PC
+ | ldr CARG3, LFUNC:CARG3->field_pc
+ | mov CARG2, PC
+ | str L, [DISPATCH, #DISPATCH_J(L)]
+ | ldrb CARG3, [CARG3, #PC2PROTO(framesize)]
+ | str BASE, L->base
+ | add CARG3, BASE, CARG3, lsl #3
+ | str CARG3, L->top
+ | bl extern lj_trace_hot // (jit_State *J, const BCIns *pc)
+ | b <3
+ |.endif
+ |
+ |->vm_callhook: // Dispatch target for call hooks.
+ | mov CARG2, PC
+ |.if JIT
+ | b >1
+ |.endif
+ |
+ |->vm_hotcall: // Hot call counter underflow.
+ |.if JIT
+ | orr CARG2, PC, #1
+ |1:
+ |.endif
+ | add CARG4, BASE, RC
+ | str PC, SAVE_PC
+ | mov CARG1, L
+ | str BASE, L->base
+ | sub RA, RA, BASE
+ | str CARG4, L->top
+ | bl extern lj_dispatch_call // (lua_State *L, const BCIns *pc)
+ | // Returns ASMFunction.
+ | ldr BASE, L->base
+ | ldr CARG4, L->top
+ | mov CARG2, #0
+ | add RA, BASE, RA
+ | sub NARGS8:RC, CARG4, BASE
+ | str CARG2, SAVE_PC // Invalidate for subsequent line hook.
+ | ldr LFUNC:CARG3, [BASE, FRAME_FUNC]
+ | ldr INS, [PC, #-4]
+ | bx CRET1
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Trace exit handler -------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_exit_handler:
+ |.if JIT
+ | sub sp, sp, #12
+ | push {r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12}
+ | ldr CARG1, [sp, #64] // Load original value of lr.
+ | ldr DISPATCH, [lr] // Load DISPATCH.
+ | add CARG3, sp, #64 // Recompute original value of sp.
+ | mv_vmstate CARG4, EXIT
+ | str CARG3, [sp, #52] // Store sp in RID_SP
+ | st_vmstate CARG4
+ | ldr CARG2, [CARG1, #-4]! // Get exit instruction.
+ | str CARG1, [sp, #56] // Store exit pc in RID_LR and RID_PC.
+ | str CARG1, [sp, #60]
+ |.if FPU
+ | vpush {d0-d15}
+ |.endif
+ | lsl CARG2, CARG2, #8
+ | add CARG1, CARG1, CARG2, asr #6
+ | ldr CARG2, [lr, #4] // Load exit stub group offset.
+ | sub CARG1, CARG1, lr
+ | ldr L, [DISPATCH, #DISPATCH_GL(jit_L)]
+ | add CARG1, CARG2, CARG1, lsr #2 // Compute exit number.
+ | ldr BASE, [DISPATCH, #DISPATCH_GL(jit_base)]
+ | str CARG1, [DISPATCH, #DISPATCH_J(exitno)]
+ | mov CARG4, #0
+ | str L, [DISPATCH, #DISPATCH_J(L)]
+ | str BASE, L->base
+ | str CARG4, [DISPATCH, #DISPATCH_GL(jit_L)]
+ | sub CARG1, DISPATCH, #-GG_DISP2J
+ | mov CARG2, sp
+ | bl extern lj_trace_exit // (jit_State *J, ExitState *ex)
+ | // Returns MULTRES (unscaled) or negated error code.
+ | ldr CARG2, L->cframe
+ | ldr BASE, L->base
+ | bic CARG2, CARG2, #~CFRAME_RAWMASK // Use two steps: bic sp is deprecated.
+ | mov sp, CARG2
+ | ldr PC, SAVE_PC // Get SAVE_PC.
+ | str L, SAVE_L // Set SAVE_L (on-trace resume/yield).
+ | b >1
+ |.endif
+ |->vm_exit_interp:
+ | // CARG1 = MULTRES or negated error code, BASE, PC and DISPATCH set.
+ |.if JIT
+ | ldr L, SAVE_L
+ |1:
+ | cmp CARG1, #0
+ | blt >3 // Check for error from exit.
+ | lsl RC, CARG1, #3
+ | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
+ | str RC, SAVE_MULTRES
+ | mov CARG3, #0
+ | ldr CARG2, LFUNC:CARG2->field_pc
+ | str CARG3, [DISPATCH, #DISPATCH_GL(jit_L)]
+ | mv_vmstate CARG4, INTERP
+ | ldr KBASE, [CARG2, #PC2PROTO(k)]
+ | // Modified copy of ins_next which handles function header dispatch, too.
+ | ldrb OP, [PC]
+ | mov MASKR8, #255
+ | ldr INS, [PC], #4
+ | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
+ | st_vmstate CARG4
+ | cmp OP, #BC_FUNCF // Function header?
+ | ldr OP, [DISPATCH, OP, lsl #2]
+ | decode_RA8 RA, INS
+ | lsrlo RC, INS, #16 // No: Decode operands A*8 and D.
+ | subhs RC, RC, #8
+ | addhs RA, RA, BASE // Yes: RA = BASE+framesize*8, RC = nargs*8
+ | bx OP
+ |
+ |3: // Rethrow error from the right C frame.
+ | rsb CARG2, CARG1, #0
+ | mov CARG1, L
+ | bl extern lj_err_throw // (lua_State *L, int errcode)
+ |.endif
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Math helper functions ----------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |// FP value rounding. Called from JIT code.
+ |//
+ |// double lj_vm_floor/ceil/trunc(double x);
+ |.macro vm_round, func, hf
+ |.if hf == 1
+ | vmov CARG1, CARG2, d0
+ |.endif
+ | lsl CARG3, CARG2, #1
+ | adds RB, CARG3, #0x00200000
+ | bpl >2 // |x| < 1?
+ | mvn CARG4, #0x3cc
+ | subs RB, CARG4, RB, asr #21 // 2^0: RB = 51, 2^51: RB = 0.
+ | bxlo lr // |x| >= 2^52: done.
+ | mvn CARG4, #1
+ | bic CARG3, CARG1, CARG4, lsl RB // ztest = lo & ~lomask
+ | and CARG1, CARG1, CARG4, lsl RB // lo &= lomask
+ | subs RB, RB, #32
+ | bicpl CARG4, CARG2, CARG4, lsl RB // |x| <= 2^20: ztest |= hi & ~himask
+ | orrpl CARG3, CARG3, CARG4
+ | mvnpl CARG4, #1
+ | andpl CARG2, CARG2, CARG4, lsl RB // |x| <= 2^20: hi &= himask
+ |.if "func" == "floor"
+ | tst CARG3, CARG2, asr #31 // iszero = ((ztest & signmask) == 0)
+ |.else
+ | bics CARG3, CARG3, CARG2, asr #31 // iszero = ((ztest & ~signmask) == 0)
+ |.endif
+ |.if hf == 1
+ | vmoveq d0, CARG1, CARG2
+ |.endif
+ | bxeq lr // iszero: done.
+ | mvn CARG4, #1
+ | cmp RB, #0
+ | lslpl CARG3, CARG4, RB
+ | mvnmi CARG3, #0
+ | add RB, RB, #32
+ | subs CARG1, CARG1, CARG4, lsl RB // lo = lo-lomask
+ | sbc CARG2, CARG2, CARG3 // hi = hi-himask+carry
+ |.if hf == 1
+ | vmov d0, CARG1, CARG2
+ |.endif
+ | bx lr
+ |
+ |2: // |x| < 1:
+ | bxcs lr // |x| is not finite.
+ | orr CARG3, CARG3, CARG1 // ztest = (2*hi) | lo
+ |.if "func" == "floor"
+ | tst CARG3, CARG2, asr #31 // iszero = ((ztest & signmask) == 0)
+ |.else
+ | bics CARG3, CARG3, CARG2, asr #31 // iszero = ((ztest & ~signmask) == 0)
+ |.endif
+ | mov CARG1, #0 // lo = 0
+ | and CARG2, CARG2, #0x80000000
+ | ldrne CARG4, <9 // hi = sign(x) | (iszero ? 0.0 : 1.0)
+ | orrne CARG2, CARG2, CARG4
+ |.if hf == 1
+ | vmov d0, CARG1, CARG2
+ |.endif
+ | bx lr
+ |.endmacro
+ |
+ |9:
+ | .long 0x3ff00000 // hiword(+1.0)
+ |
+ |->vm_floor:
+ |.if HFABI
+ | vm_round floor, 1
+ |.endif
+ |->vm_floor_sf:
+ | vm_round floor, 0
+ |
+ |->vm_ceil:
+ |.if HFABI
+ | vm_round ceil, 1
+ |.endif
+ |->vm_ceil_sf:
+ | vm_round ceil, 0
+ |
+ |.macro vm_trunc, hf
+ |.if JIT
+ |.if hf == 1
+ | vmov CARG1, CARG2, d0
+ |.endif
+ | lsl CARG3, CARG2, #1
+ | adds RB, CARG3, #0x00200000
+ | andpl CARG2, CARG2, #0x80000000 // |x| < 1? hi = sign(x), lo = 0.
+ | movpl CARG1, #0
+ |.if hf == 1
+ | vmovpl d0, CARG1, CARG2
+ |.endif
+ | bxpl lr
+ | mvn CARG4, #0x3cc
+ | subs RB, CARG4, RB, asr #21 // 2^0: RB = 51, 2^51: RB = 0.
+ | bxlo lr // |x| >= 2^52: already done.
+ | mvn CARG4, #1
+ | and CARG1, CARG1, CARG4, lsl RB // lo &= lomask
+ | subs RB, RB, #32
+ | andpl CARG2, CARG2, CARG4, lsl RB // |x| <= 2^20: hi &= himask
+ |.if hf == 1
+ | vmov d0, CARG1, CARG2
+ |.endif
+ | bx lr
+ |.endif
+ |.endmacro
+ |
+ |->vm_trunc:
+ |.if HFABI
+ | vm_trunc 1
+ |.endif
+ |->vm_trunc_sf:
+ | vm_trunc 0
+ |
+ | // double lj_vm_mod(double dividend, double divisor);
+ |->vm_mod:
+ |.if FPU
+ | // Special calling convention. Also, RC (r11) is not preserved.
+ | vdiv.f64 d0, d6, d7
+ | mov RC, lr
+ | vmov CARG1, CARG2, d0
+ | bl ->vm_floor_sf
+ | vmov d0, CARG1, CARG2
+ | vmul.f64 d0, d0, d7
+ | mov lr, RC
+ | vsub.f64 d6, d6, d0
+ | bx lr
+ |.else
+ | push {r0, r1, r2, r3, r4, lr}
+ | bl extern __aeabi_ddiv
+ | bl ->vm_floor_sf
+ | ldrd CARG34, [sp, #8]
+ | bl extern __aeabi_dmul
+ | ldrd CARG34, [sp]
+ | eor CARG2, CARG2, #0x80000000
+ | bl extern __aeabi_dadd
+ | add sp, sp, #20
+ | pop {pc}
+ |.endif
+ |
+ | // int lj_vm_modi(int dividend, int divisor);
+ |->vm_modi:
+ | ands RB, CARG1, #0x80000000
+ | rsbmi CARG1, CARG1, #0 // a = |dividend|
+ | eor RB, RB, CARG2, asr #1 // Keep signdiff and sign(divisor).
+ | cmp CARG2, #0
+ | rsbmi CARG2, CARG2, #0 // b = |divisor|
+ | subs CARG4, CARG2, #1
+ | cmpne CARG1, CARG2
+ | moveq CARG1, #0 // if (b == 1 || a == b) a = 0
+ | tsthi CARG2, CARG4
+ | andeq CARG1, CARG1, CARG4 // else if ((b & (b-1)) == 0) a &= b-1
+ | bls >1
+ | // Use repeated subtraction to get the remainder.
+ | clz CARG3, CARG1
+ | clz CARG4, CARG2
+ | sub CARG4, CARG4, CARG3
+ | rsbs CARG3, CARG4, #31 // entry = (31-(clz(b)-clz(a)))*8
+ | addne pc, pc, CARG3, lsl #3 // Duff's device.
+ | nop
+ {
+ int i;
+ for (i = 31; i >= 0; i--) {
+ | cmp CARG1, CARG2, lsl #i
+ | subhs CARG1, CARG1, CARG2, lsl #i
+ }
+ }
+ |1:
+ | cmp CARG1, #0
+ | cmpne RB, #0
+ | submi CARG1, CARG1, CARG2 // if (y != 0 && signdiff) y = y - b
+ | eors CARG2, CARG1, RB, lsl #1
+ | rsbmi CARG1, CARG1, #0 // if (sign(divisor) != sign(y)) y = -y
+ | bx lr
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Miscellaneous functions --------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |//-----------------------------------------------------------------------
+ |//-- FFI helper functions -----------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |// Handler for callback functions.
+ |// Saveregs already performed. Callback slot number in [sp], g in r12.
+ |->vm_ffi_callback:
+ |.if FFI
+ |.type CTSTATE, CTState, PC
+ | ldr CTSTATE, GL:r12->ctype_state
+ | add DISPATCH, r12, #GG_G2DISP
+ |.if FPU
+ | str r4, SAVE_R4
+ | add r4, sp, CFRAME_SPACE+4+8*8
+ | vstmdb r4!, {d8-d15}
+ |.endif
+ |.if HFABI
+ | add r12, CTSTATE, #offsetof(CTState, cb.fpr[8])
+ |.endif
+ | strd CARG34, CTSTATE->cb.gpr[2]
+ | strd CARG12, CTSTATE->cb.gpr[0]
+ |.if HFABI
+ | vstmdb r12!, {d0-d7}
+ |.endif
+ | ldr CARG4, [sp]
+ | add CARG3, sp, #CFRAME_SIZE
+ | mov CARG1, CTSTATE
+ | lsr CARG4, CARG4, #3
+ | str CARG3, CTSTATE->cb.stack
+ | mov CARG2, sp
+ | str CARG4, CTSTATE->cb.slot
+ | str CTSTATE, SAVE_PC // Any value outside of bytecode is ok.
+ | bl extern lj_ccallback_enter // (CTState *cts, void *cf)
+ | // Returns lua_State *.
+ | ldr BASE, L:CRET1->base
+ | mv_vmstate CARG2, INTERP
+ | ldr RC, L:CRET1->top
+ | mov MASKR8, #255
+ | ldr LFUNC:CARG3, [BASE, FRAME_FUNC]
+ | mov L, CRET1
+ | sub RC, RC, BASE
+ | lsl MASKR8, MASKR8, #3 // MASKR8 = 255*8.
+ | st_vmstate CARG2
+ | ins_callt
+ |.endif
+ |
+ |->cont_ffi_callback: // Return from FFI callback.
+ |.if FFI
+ | ldr CTSTATE, [DISPATCH, #DISPATCH_GL(ctype_state)]
+ | str BASE, L->base
+ | str CARG4, L->top
+ | str L, CTSTATE->L
+ | mov CARG1, CTSTATE
+ | mov CARG2, RA
+ | bl extern lj_ccallback_leave // (CTState *cts, TValue *o)
+ | ldrd CARG12, CTSTATE->cb.gpr[0]
+ |.if HFABI
+ | vldr d0, CTSTATE->cb.fpr[0]
+ |.endif
+ | b ->vm_leave_unw
+ |.endif
+ |
+ |->vm_ffi_call: // Call C function via FFI.
+ | // Caveat: needs special frame unwinding, see below.
+ |.if FFI
+ | .type CCSTATE, CCallState, r4
+ | push {CCSTATE, r5, r11, lr}
+ | mov CCSTATE, CARG1
+ | ldr CARG1, CCSTATE:CARG1->spadj
+ | ldrb CARG2, CCSTATE->nsp
+ | add CARG3, CCSTATE, #offsetof(CCallState, stack)
+ |.if HFABI
+ | add RB, CCSTATE, #offsetof(CCallState, fpr[0])
+ |.endif
+ | mov r11, sp
+ | sub sp, sp, CARG1 // Readjust stack.
+ | subs CARG2, CARG2, #1
+ |.if HFABI
+ | vldm RB, {d0-d7}
+ |.endif
+ | ldr RB, CCSTATE->func
+ | bmi >2
+ |1: // Copy stack slots.
+ | ldr CARG4, [CARG3, CARG2, lsl #2]
+ | str CARG4, [sp, CARG2, lsl #2]
+ | subs CARG2, CARG2, #1
+ | bpl <1
+ |2:
+ | ldrd CARG12, CCSTATE->gpr[0]
+ | ldrd CARG34, CCSTATE->gpr[2]
+ | blx RB
+ | mov sp, r11
+ |.if HFABI
+ | add r12, CCSTATE, #offsetof(CCallState, fpr[4])
+ |.endif
+ | strd CRET1, CCSTATE->gpr[0]
+ |.if HFABI
+ | vstmdb r12!, {d0-d3}
+ |.endif
+ | pop {CCSTATE, r5, r11, pc}
+ |.endif
+ |// Note: vm_ffi_call must be the last function in this object file!
+ |
+ |//-----------------------------------------------------------------------
+}
+
+/* Generate the code for a single instruction. */
+static void build_ins(BuildCtx *ctx, BCOp op, int defop)
+{
+ int vk = 0;
+ |=>defop:
+
+ switch (op) {
+
+ /* -- Comparison ops ---------------------------------------------------- */
+
+ /* Remember: all ops branch for a true comparison, fall through otherwise. */
+
+ case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:
+ | // RA = src1*8, RC = src2, JMP with RC = target
+ | lsl RC, RC, #3
+ | ldrd CARG12, [RA, BASE]!
+ | ldrh RB, [PC, #2]
+ | ldrd CARG34, [RC, BASE]!
+ | add PC, PC, #4
+ | add RB, PC, RB, lsl #2
+ | checktp CARG2, LJ_TISNUM
+ | bne >3
+ | checktp CARG4, LJ_TISNUM
+ | bne >4
+ | cmp CARG1, CARG3
+ if (op == BC_ISLT) {
+ | sublt PC, RB, #0x20000
+ } else if (op == BC_ISGE) {
+ | subge PC, RB, #0x20000
+ } else if (op == BC_ISLE) {
+ | suble PC, RB, #0x20000
+ } else {
+ | subgt PC, RB, #0x20000
+ }
+ |1:
+ | ins_next
+ |
+ |3: // CARG12 is not an integer.
+ |.if FPU
+ | vldr d0, [RA]
+ | bhi ->vmeta_comp
+ | // d0 is a number.
+ | checktp CARG4, LJ_TISNUM
+ | vldr d1, [RC]
+ | blo >5
+ | bhi ->vmeta_comp
+ | // d0 is a number, CARG3 is an integer.
+ | vmov s4, CARG3
+ | vcvt.f64.s32 d1, s4
+ | b >5
+ |4: // CARG1 is an integer, CARG34 is not an integer.
+ | vldr d1, [RC]
+ | bhi ->vmeta_comp
+ | // CARG1 is an integer, d1 is a number.
+ | vmov s4, CARG1
+ | vcvt.f64.s32 d0, s4
+ |5: // d0 and d1 are numbers.
+ | vcmp.f64 d0, d1
+ | vmrs
+ | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.
+ if (op == BC_ISLT) {
+ | sublo PC, RB, #0x20000
+ } else if (op == BC_ISGE) {
+ | subhs PC, RB, #0x20000
+ } else if (op == BC_ISLE) {
+ | subls PC, RB, #0x20000
+ } else {
+ | subhi PC, RB, #0x20000
+ }
+ | b <1
+ |.else
+ | bhi ->vmeta_comp
+ | // CARG12 is a number.
+ | checktp CARG4, LJ_TISNUM
+ | movlo RA, RB // Save RB.
+ | blo >5
+ | bhi ->vmeta_comp
+ | // CARG12 is a number, CARG3 is an integer.
+ | mov CARG1, CARG3
+ | mov RC, RA
+ | mov RA, RB // Save RB.
+ | bl extern __aeabi_i2d
+ | mov CARG3, CARG1
+ | mov CARG4, CARG2
+ | ldrd CARG12, [RC] // Restore first operand.
+ | b >5
+ |4: // CARG1 is an integer, CARG34 is not an integer.
+ | bhi ->vmeta_comp
+ | // CARG1 is an integer, CARG34 is a number.
+ | mov RA, RB // Save RB.
+ | bl extern __aeabi_i2d
+ | ldrd CARG34, [RC] // Restore second operand.
+ |5: // CARG12 and CARG34 are numbers.
+ | bl extern __aeabi_cdcmple
+ | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.
+ if (op == BC_ISLT) {
+ | sublo PC, RA, #0x20000
+ } else if (op == BC_ISGE) {
+ | subhs PC, RA, #0x20000
+ } else if (op == BC_ISLE) {
+ | subls PC, RA, #0x20000
+ } else {
+ | subhi PC, RA, #0x20000
+ }
+ | b <1
+ |.endif
+ break;
+
+ case BC_ISEQV: case BC_ISNEV:
+ vk = op == BC_ISEQV;
+ | // RA = src1*8, RC = src2, JMP with RC = target
+ | lsl RC, RC, #3
+ | ldrd CARG12, [RA, BASE]!
+ | ldrh RB, [PC, #2]
+ | ldrd CARG34, [RC, BASE]!
+ | add PC, PC, #4
+ | add RB, PC, RB, lsl #2
+ | checktp CARG2, LJ_TISNUM
+ | cmnls CARG4, #-LJ_TISNUM
+ if (vk) {
+ | bls ->BC_ISEQN_Z
+ } else {
+ | bls ->BC_ISNEN_Z
+ }
+ | // Either or both types are not numbers.
+ |.if FFI
+ | checktp CARG2, LJ_TCDATA
+ | checktpne CARG4, LJ_TCDATA
+ | beq ->vmeta_equal_cd
+ |.endif
+ | cmp CARG2, CARG4 // Compare types.
+ | bne >2 // Not the same type?
+ | checktp CARG2, LJ_TISPRI
+ | bhs >1 // Same type and primitive type?
+ |
+ | // Same types and not a primitive type. Compare GCobj or pvalue.
+ | cmp CARG1, CARG3
+ if (vk) {
+ | bne >3 // Different GCobjs or pvalues?
+ |1: // Branch if same.
+ | sub PC, RB, #0x20000
+ |2: // Different.
+ | ins_next
+ |3:
+ | checktp CARG2, LJ_TISTABUD
+ | bhi <2 // Different objects and not table/ud?
+ } else {
+ | beq >1 // Same GCobjs or pvalues?
+ | checktp CARG2, LJ_TISTABUD
+ | bhi >2 // Different objects and not table/ud?
+ }
+ | // Different tables or userdatas. Need to check __eq metamethod.
+ | // Field metatable must be at same offset for GCtab and GCudata!
+ | ldr TAB:RA, TAB:CARG1->metatable
+ | cmp TAB:RA, #0
+ if (vk) {
+ | beq <2 // No metatable?
+ } else {
+ | beq >2 // No metatable?
+ }
+ | ldrb RA, TAB:RA->nomm
+ | mov CARG4, #1-vk // ne = 0 or 1.
+ | mov CARG2, CARG1
+ | tst RA, #1<<MM_eq
+ | beq ->vmeta_equal // 'no __eq' flag not set?
+ if (vk) {
+ | b <2
+ } else {
+ |2: // Branch if different.
+ | sub PC, RB, #0x20000
+ |1: // Same.
+ | ins_next
+ }
+ break;
+
+ case BC_ISEQS: case BC_ISNES:
+ vk = op == BC_ISEQS;
+ | // RA = src*8, RC = str_const (~), JMP with RC = target
+ | mvn RC, RC
+ | ldrd CARG12, [BASE, RA]
+ | ldrh RB, [PC, #2]
+ | ldr STR:CARG3, [KBASE, RC, lsl #2]
+ | add PC, PC, #4
+ | add RB, PC, RB, lsl #2
+ | checktp CARG2, LJ_TSTR
+ |.if FFI
+ | bne >7
+ | cmp CARG1, CARG3
+ |.else
+ | cmpeq CARG1, CARG3
+ |.endif
+ if (vk) {
+ | subeq PC, RB, #0x20000
+ |1:
+ } else {
+ |1:
+ | subne PC, RB, #0x20000
+ }
+ | ins_next
+ |
+ |.if FFI
+ |7:
+ | checktp CARG2, LJ_TCDATA
+ | bne <1
+ | b ->vmeta_equal_cd
+ |.endif
+ break;
+
+ case BC_ISEQN: case BC_ISNEN:
+ vk = op == BC_ISEQN;
+ | // RA = src*8, RC = num_const (~), JMP with RC = target
+ | lsl RC, RC, #3
+ | ldrd CARG12, [RA, BASE]!
+ | ldrh RB, [PC, #2]
+ | ldrd CARG34, [RC, KBASE]!
+ | add PC, PC, #4
+ | add RB, PC, RB, lsl #2
+ if (vk) {
+ |->BC_ISEQN_Z:
+ } else {
+ |->BC_ISNEN_Z:
+ }
+ | checktp CARG2, LJ_TISNUM
+ | bne >3
+ | checktp CARG4, LJ_TISNUM
+ | bne >4
+ | cmp CARG1, CARG3
+ if (vk) {
+ | subeq PC, RB, #0x20000
+ |1:
+ } else {
+ |1:
+ | subne PC, RB, #0x20000
+ }
+ |2:
+ | ins_next
+ |
+ |3: // CARG12 is not an integer.
+ |.if FFI
+ | bhi >7
+ |.else
+ if (!vk) {
+ | subhi PC, RB, #0x20000
+ }
+ | bhi <2
+ |.endif
+ |.if FPU
+ | checktp CARG4, LJ_TISNUM
+ | vmov s4, CARG3
+ | vldr d0, [RA]
+ | vldrlo d1, [RC]
+ | vcvths.f64.s32 d1, s4
+ | b >5
+ |4: // CARG1 is an integer, d1 is a number.
+ | vmov s4, CARG1
+ | vldr d1, [RC]
+ | vcvt.f64.s32 d0, s4
+ |5: // d0 and d1 are numbers.
+ | vcmp.f64 d0, d1
+ | vmrs
+ if (vk) {
+ | subeq PC, RB, #0x20000
+ } else {
+ | subne PC, RB, #0x20000
+ }
+ | b <2
+ |.else
+ | // CARG12 is a number.
+ | checktp CARG4, LJ_TISNUM
+ | movlo RA, RB // Save RB.
+ | blo >5
+ | // CARG12 is a number, CARG3 is an integer.
+ | mov CARG1, CARG3
+ | mov RC, RA
+ |4: // CARG1 is an integer, CARG34 is a number.
+ | mov RA, RB // Save RB.
+ | bl extern __aeabi_i2d
+ | ldrd CARG34, [RC] // Restore other operand.
+ |5: // CARG12 and CARG34 are numbers.
+ | bl extern __aeabi_cdcmpeq
+ if (vk) {
+ | subeq PC, RA, #0x20000
+ } else {
+ | subne PC, RA, #0x20000
+ }
+ | b <2
+ |.endif
+ |
+ |.if FFI
+ |7:
+ | checktp CARG2, LJ_TCDATA
+ | bne <1
+ | b ->vmeta_equal_cd
+ |.endif
+ break;
+
+ case BC_ISEQP: case BC_ISNEP:
+ vk = op == BC_ISEQP;
+ | // RA = src*8, RC = primitive_type (~), JMP with RC = target
+ | ldrd CARG12, [BASE, RA]
+ | ldrh RB, [PC, #2]
+ | add PC, PC, #4
+ | mvn RC, RC
+ | add RB, PC, RB, lsl #2
+ |.if FFI
+ | checktp CARG2, LJ_TCDATA
+ | beq ->vmeta_equal_cd
+ |.endif
+ | cmp CARG2, RC
+ if (vk) {
+ | subeq PC, RB, #0x20000
+ } else {
+ | subne PC, RB, #0x20000
+ }
+ | ins_next
+ break;
+
+ /* -- Unary test and copy ops ------------------------------------------- */
+
+ case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:
+ | // RA = dst*8 or unused, RC = src, JMP with RC = target
+ | add RC, BASE, RC, lsl #3
+ | ldrh RB, [PC, #2]
+ | ldrd CARG12, [RC]
+ | add PC, PC, #4
+ | add RB, PC, RB, lsl #2
+ | checktp CARG2, LJ_TTRUE
+ if (op == BC_ISTC || op == BC_IST) {
+ | subls PC, RB, #0x20000
+ if (op == BC_ISTC) {
+ | strdls CARG12, [BASE, RA]
+ }
+ } else {
+ | subhi PC, RB, #0x20000
+ if (op == BC_ISFC) {
+ | strdhi CARG12, [BASE, RA]
+ }
+ }
+ | ins_next
+ break;
+
+ /* -- Unary ops --------------------------------------------------------- */
+
+ case BC_MOV:
+ | // RA = dst*8, RC = src
+ | lsl RC, RC, #3
+ | ins_next1
+ | ldrd CARG12, [BASE, RC]
+ | ins_next2
+ | strd CARG12, [BASE, RA]
+ | ins_next3
+ break;
+ case BC_NOT:
+ | // RA = dst*8, RC = src
+ | add RC, BASE, RC, lsl #3
+ | ins_next1
+ | ldr CARG1, [RC, #4]
+ | add RA, BASE, RA
+ | ins_next2
+ | checktp CARG1, LJ_TTRUE
+ | mvnls CARG2, #~LJ_TFALSE
+ | mvnhi CARG2, #~LJ_TTRUE
+ | str CARG2, [RA, #4]
+ | ins_next3
+ break;
+ case BC_UNM:
+ | // RA = dst*8, RC = src
+ | lsl RC, RC, #3
+ | ldrd CARG12, [BASE, RC]
+ | ins_next1
+ | ins_next2
+ | checktp CARG2, LJ_TISNUM
+ | bhi ->vmeta_unm
+ | eorne CARG2, CARG2, #0x80000000
+ | bne >5
+ | rsbseq CARG1, CARG1, #0
+ | ldrdvs CARG12, >9
+ |5:
+ | strd CARG12, [BASE, RA]
+ | ins_next3
+ |
+ |.align 8
+ |9:
+ | .long 0x00000000, 0x41e00000 // 2^31.
+ break;
+ case BC_LEN:
+ | // RA = dst*8, RC = src
+ | lsl RC, RC, #3
+ | ldrd CARG12, [BASE, RC]
+ | checkstr CARG2, >2
+ | ldr CARG1, STR:CARG1->len
+ |1:
+ | mvn CARG2, #~LJ_TISNUM
+ | ins_next1
+ | ins_next2
+ | strd CARG12, [BASE, RA]
+ | ins_next3
+ |2:
+ | checktab CARG2, ->vmeta_len
+#if LJ_52
+ | ldr TAB:CARG3, TAB:CARG1->metatable
+ | cmp TAB:CARG3, #0
+ | bne >9
+ |3:
+#endif
+ |->BC_LEN_Z:
+ | .IOS mov RC, BASE
+ | bl extern lj_tab_len // (GCtab *t)
+ | // Returns uint32_t (but less than 2^31).
+ | .IOS mov BASE, RC
+ | b <1
+#if LJ_52
+ |9:
+ | ldrb CARG4, TAB:CARG3->nomm
+ | tst CARG4, #1<<MM_len
+ | bne <3 // 'no __len' flag set: done.
+ | b ->vmeta_len
+#endif
+ break;
+
+ /* -- Binary ops -------------------------------------------------------- */
+
+ |.macro ins_arithcheck, cond, ncond, target
+ ||if (vk == 1) {
+ | cmn CARG4, #-LJ_TISNUM
+ | cmn..cond CARG2, #-LJ_TISNUM
+ ||} else {
+ | cmn CARG2, #-LJ_TISNUM
+ | cmn..cond CARG4, #-LJ_TISNUM
+ ||}
+ | b..ncond target
+ |.endmacro
+ |.macro ins_arithcheck_int, target
+ | ins_arithcheck eq, ne, target
+ |.endmacro
+ |.macro ins_arithcheck_num, target
+ | ins_arithcheck lo, hs, target
+ |.endmacro
+ |
+ |.macro ins_arithpre
+ | decode_RB8 RB, INS
+ | decode_RC8 RC, INS
+ | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8
+ ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
+ ||switch (vk) {
+ ||case 0:
+ | .if FPU
+ | ldrd CARG12, [RB, BASE]!
+ | ldrd CARG34, [RC, KBASE]!
+ | .else
+ | ldrd CARG12, [BASE, RB]
+ | ldrd CARG34, [KBASE, RC]
+ | .endif
+ || break;
+ ||case 1:
+ | .if FPU
+ | ldrd CARG34, [RB, BASE]!
+ | ldrd CARG12, [RC, KBASE]!
+ | .else
+ | ldrd CARG34, [BASE, RB]
+ | ldrd CARG12, [KBASE, RC]
+ | .endif
+ || break;
+ ||default:
+ | .if FPU
+ | ldrd CARG12, [RB, BASE]!
+ | ldrd CARG34, [RC, BASE]!
+ | .else
+ | ldrd CARG12, [BASE, RB]
+ | ldrd CARG34, [BASE, RC]
+ | .endif
+ || break;
+ ||}
+ |.endmacro
+ |
+ |.macro ins_arithpre_fpu, reg1, reg2
+ |.if FPU
+ ||if (vk == 1) {
+ | vldr reg2, [RB]
+ | vldr reg1, [RC]
+ ||} else {
+ | vldr reg1, [RB]
+ | vldr reg2, [RC]
+ ||}
+ |.endif
+ |.endmacro
+ |
+ |.macro ins_arithpost_fpu, reg
+ | ins_next1
+ | add RA, BASE, RA
+ | ins_next2
+ | vstr reg, [RA]
+ | ins_next3
+ |.endmacro
+ |
+ |.macro ins_arithfallback, ins
+ ||switch (vk) {
+ ||case 0:
+ | ins ->vmeta_arith_vn
+ || break;
+ ||case 1:
+ | ins ->vmeta_arith_nv
+ || break;
+ ||default:
+ | ins ->vmeta_arith_vv
+ || break;
+ ||}
+ |.endmacro
+ |
+ |.macro ins_arithdn, intins, fpins, fpcall
+ | ins_arithpre
+ |.if "intins" ~= "vm_modi" and not FPU
+ | ins_next1
+ |.endif
+ | ins_arithcheck_int >5
+ |.if "intins" == "smull"
+ | smull CARG1, RC, CARG3, CARG1
+ | cmp RC, CARG1, asr #31
+ | ins_arithfallback bne
+ |.elif "intins" == "vm_modi"
+ | movs CARG2, CARG3
+ | ins_arithfallback beq
+ | bl ->vm_modi
+ | mvn CARG2, #~LJ_TISNUM
+ |.else
+ | intins CARG1, CARG1, CARG3
+ | ins_arithfallback bvs
+ |.endif
+ |4:
+ |.if "intins" == "vm_modi" or FPU
+ | ins_next1
+ |.endif
+ | ins_next2
+ | strd CARG12, [BASE, RA]
+ | ins_next3
+ |5: // FP variant.
+ | ins_arithpre_fpu d6, d7
+ | ins_arithfallback ins_arithcheck_num
+ |.if FPU
+ |.if "intins" == "vm_modi"
+ | bl fpcall
+ |.else
+ | fpins d6, d6, d7
+ |.endif
+ | ins_arithpost_fpu d6
+ |.else
+ | bl fpcall
+ |.if "intins" ~= "vm_modi"
+ | ins_next1
+ |.endif
+ | b <4
+ |.endif
+ |.endmacro
+ |
+ |.macro ins_arithfp, fpins, fpcall
+ | ins_arithpre
+ |.if "fpins" ~= "extern" or HFABI
+ | ins_arithpre_fpu d0, d1
+ |.endif
+ | ins_arithfallback ins_arithcheck_num
+ |.if "fpins" == "extern"
+ | .IOS mov RC, BASE
+ | bl fpcall
+ | .IOS mov BASE, RC
+ |.elif FPU
+ | fpins d0, d0, d1
+ |.else
+ | bl fpcall
+ |.endif
+ |.if ("fpins" ~= "extern" or HFABI) and FPU
+ | ins_arithpost_fpu d0
+ |.else
+ | ins_next1
+ | ins_next2
+ | strd CARG12, [BASE, RA]
+ | ins_next3
+ |.endif
+ |.endmacro
+
+ case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:
+ | ins_arithdn adds, vadd.f64, extern __aeabi_dadd
+ break;
+ case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:
+ | ins_arithdn subs, vsub.f64, extern __aeabi_dsub
+ break;
+ case BC_MULVN: case BC_MULNV: case BC_MULVV:
+ | ins_arithdn smull, vmul.f64, extern __aeabi_dmul
+ break;
+ case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:
+ | ins_arithfp vdiv.f64, extern __aeabi_ddiv
+ break;
+ case BC_MODVN: case BC_MODNV: case BC_MODVV:
+ | ins_arithdn vm_modi, vm_mod, ->vm_mod
+ break;
+ case BC_POW:
+ | // NYI: (partial) integer arithmetic.
+ | ins_arithfp extern, extern pow
+ break;
+
+ case BC_CAT:
+ | decode_RB8 RC, INS
+ | decode_RC8 RB, INS
+ | // RA = dst*8, RC = src_start*8, RB = src_end*8 (note: RB/RC swapped!)
+ | sub CARG3, RB, RC
+ | str BASE, L->base
+ | add CARG2, BASE, RB
+ |->BC_CAT_Z:
+ | // RA = dst*8, RC = src_start*8, CARG2 = top-1
+ | mov CARG1, L
+ | str PC, SAVE_PC
+ | lsr CARG3, CARG3, #3
+ | bl extern lj_meta_cat // (lua_State *L, TValue *top, int left)
+ | // Returns NULL (finished) or TValue * (metamethod).
+ | ldr BASE, L->base
+ | cmp CRET1, #0
+ | bne ->vmeta_binop
+ | ldrd CARG34, [BASE, RC]
+ | ins_next1
+ | ins_next2
+ | strd CARG34, [BASE, RA] // Copy result to RA.
+ | ins_next3
+ break;
+
+ /* -- Constant ops ------------------------------------------------------ */
+
+ case BC_KSTR:
+ | // RA = dst*8, RC = str_const (~)
+ | mvn RC, RC
+ | ins_next1
+ | ldr CARG1, [KBASE, RC, lsl #2]
+ | mvn CARG2, #~LJ_TSTR
+ | ins_next2
+ | strd CARG12, [BASE, RA]
+ | ins_next3
+ break;
+ case BC_KCDATA:
+ |.if FFI
+ | // RA = dst*8, RC = cdata_const (~)
+ | mvn RC, RC
+ | ins_next1
+ | ldr CARG1, [KBASE, RC, lsl #2]
+ | mvn CARG2, #~LJ_TCDATA
+ | ins_next2
+ | strd CARG12, [BASE, RA]
+ | ins_next3
+ |.endif
+ break;
+ case BC_KSHORT:
+ | // RA = dst*8, (RC = int16_literal)
+ | mov CARG1, INS, asr #16 // Refetch sign-extended reg.
+ | mvn CARG2, #~LJ_TISNUM
+ | ins_next1
+ | ins_next2
+ | strd CARG12, [BASE, RA]
+ | ins_next3
+ break;
+ case BC_KNUM:
+ | // RA = dst*8, RC = num_const
+ | lsl RC, RC, #3
+ | ins_next1
+ | ldrd CARG12, [KBASE, RC]
+ | ins_next2
+ | strd CARG12, [BASE, RA]
+ | ins_next3
+ break;
+ case BC_KPRI:
+ | // RA = dst*8, RC = primitive_type (~)
+ | add RA, BASE, RA
+ | mvn RC, RC
+ | ins_next1
+ | ins_next2
+ | str RC, [RA, #4]
+ | ins_next3
+ break;
+ case BC_KNIL:
+ | // RA = base*8, RC = end
+ | add RA, BASE, RA
+ | add RC, BASE, RC, lsl #3
+ | mvn CARG1, #~LJ_TNIL
+ | str CARG1, [RA, #4]
+ | add RA, RA, #8
+ |1:
+ | str CARG1, [RA, #4]
+ | cmp RA, RC
+ | add RA, RA, #8
+ | blt <1
+ | ins_next_
+ break;
+
+ /* -- Upvalue and function ops ------------------------------------------ */
+
+ case BC_UGET:
+ | // RA = dst*8, RC = uvnum
+ | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
+ | lsl RC, RC, #2
+ | add RC, RC, #offsetof(GCfuncL, uvptr)
+ | ldr UPVAL:CARG2, [LFUNC:CARG2, RC]
+ | ldr CARG2, UPVAL:CARG2->v
+ | ldrd CARG34, [CARG2]
+ | ins_next1
+ | ins_next2
+ | strd CARG34, [BASE, RA]
+ | ins_next3
+ break;
+ case BC_USETV:
+ | // RA = uvnum*8, RC = src
+ | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
+ | lsr RA, RA, #1
+ | add RA, RA, #offsetof(GCfuncL, uvptr)
+ | lsl RC, RC, #3
+ | ldr UPVAL:CARG2, [LFUNC:CARG2, RA]
+ | ldrd CARG34, [BASE, RC]
+ | ldrb RB, UPVAL:CARG2->marked
+ | ldrb RC, UPVAL:CARG2->closed
+ | ldr CARG2, UPVAL:CARG2->v
+ | tst RB, #LJ_GC_BLACK // isblack(uv)
+ | add RB, CARG4, #-LJ_TISGCV
+ | cmpne RC, #0
+ | strd CARG34, [CARG2]
+ | bne >2 // Upvalue is closed and black?
+ |1:
+ | ins_next
+ |
+ |2: // Check if new value is collectable.
+ | cmn RB, #-(LJ_TNUMX - LJ_TISGCV)
+ | ldrbhi RC, GCOBJ:CARG3->gch.marked
+ | bls <1 // tvisgcv(v)
+ | sub CARG1, DISPATCH, #-GG_DISP2G
+ | tst RC, #LJ_GC_WHITES
+ | // Crossed a write barrier. Move the barrier forward.
+ |.if IOS
+ | beq <1
+ | mov RC, BASE
+ | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv)
+ | mov BASE, RC
+ |.else
+ | blne extern lj_gc_barrieruv // (global_State *g, TValue *tv)
+ |.endif
+ | b <1
+ break;
+ case BC_USETS:
+ | // RA = uvnum*8, RC = str_const (~)
+ | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
+ | lsr RA, RA, #1
+ | add RA, RA, #offsetof(GCfuncL, uvptr)
+ | mvn RC, RC
+ | ldr UPVAL:CARG2, [LFUNC:CARG2, RA]
+ | ldr STR:CARG3, [KBASE, RC, lsl #2]
+ | ldrb RB, UPVAL:CARG2->marked
+ | ldrb RC, UPVAL:CARG2->closed
+ | ldr CARG2, UPVAL:CARG2->v
+ | mvn CARG4, #~LJ_TSTR
+ | tst RB, #LJ_GC_BLACK // isblack(uv)
+ | ldrb RB, STR:CARG3->marked
+ | strd CARG34, [CARG2]
+ | bne >2
+ |1:
+ | ins_next
+ |
+ |2: // Check if string is white and ensure upvalue is closed.
+ | tst RB, #LJ_GC_WHITES // iswhite(str)
+ | cmpne RC, #0
+ | sub CARG1, DISPATCH, #-GG_DISP2G
+ | // Crossed a write barrier. Move the barrier forward.
+ |.if IOS
+ | beq <1
+ | mov RC, BASE
+ | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv)
+ | mov BASE, RC
+ |.else
+ | blne extern lj_gc_barrieruv // (global_State *g, TValue *tv)
+ |.endif
+ | b <1
+ break;
+ case BC_USETN:
+ | // RA = uvnum*8, RC = num_const
+ | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
+ | lsr RA, RA, #1
+ | add RA, RA, #offsetof(GCfuncL, uvptr)
+ | lsl RC, RC, #3
+ | ldr UPVAL:CARG2, [LFUNC:CARG2, RA]
+ | ldrd CARG34, [KBASE, RC]
+ | ldr CARG2, UPVAL:CARG2->v
+ | ins_next1
+ | ins_next2
+ | strd CARG34, [CARG2]
+ | ins_next3
+ break;
+ case BC_USETP:
+ | // RA = uvnum*8, RC = primitive_type (~)
+ | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
+ | lsr RA, RA, #1
+ | add RA, RA, #offsetof(GCfuncL, uvptr)
+ | ldr UPVAL:CARG2, [LFUNC:CARG2, RA]
+ | mvn RC, RC
+ | ldr CARG2, UPVAL:CARG2->v
+ | ins_next1
+ | ins_next2
+ | str RC, [CARG2, #4]
+ | ins_next3
+ break;
+
+ case BC_UCLO:
+ | // RA = level*8, RC = target
+ | ldr CARG3, L->openupval
+ | add RC, PC, RC, lsl #2
+ | str BASE, L->base
+ | cmp CARG3, #0
+ | sub PC, RC, #0x20000
+ | beq >1
+ | mov CARG1, L
+ | add CARG2, BASE, RA
+ | bl extern lj_func_closeuv // (lua_State *L, TValue *level)
+ | ldr BASE, L->base
+ |1:
+ | ins_next
+ break;
+
+ case BC_FNEW:
+ | // RA = dst*8, RC = proto_const (~) (holding function prototype)
+ | mvn RC, RC
+ | str BASE, L->base
+ | ldr CARG2, [KBASE, RC, lsl #2]
+ | str PC, SAVE_PC
+ | ldr CARG3, [BASE, FRAME_FUNC]
+ | mov CARG1, L
+ | // (lua_State *L, GCproto *pt, GCfuncL *parent)
+ | bl extern lj_func_newL_gc
+ | // Returns GCfuncL *.
+ | ldr BASE, L->base
+ | mvn CARG2, #~LJ_TFUNC
+ | ins_next1
+ | ins_next2
+ | strd CARG12, [BASE, RA]
+ | ins_next3
+ break;
+
+ /* -- Table ops --------------------------------------------------------- */
+
+ case BC_TNEW:
+ case BC_TDUP:
+ | // RA = dst*8, RC = (hbits|asize) | tab_const (~)
+ if (op == BC_TDUP) {
+ | mvn RC, RC
+ }
+ | ldr CARG3, [DISPATCH, #DISPATCH_GL(gc.total)]
+ | ldr CARG4, [DISPATCH, #DISPATCH_GL(gc.threshold)]
+ | str BASE, L->base
+ | str PC, SAVE_PC
+ | cmp CARG3, CARG4
+ | mov CARG1, L
+ | bhs >5
+ |1:
+ if (op == BC_TNEW) {
+ | lsl CARG2, RC, #21
+ | lsr CARG3, RC, #11
+ | asr RC, CARG2, #21
+ | lsr CARG2, CARG2, #21
+ | cmn RC, #1
+ | addeq CARG2, CARG2, #2
+ | bl extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits)
+ | // Returns GCtab *.
+ } else {
+ | ldr CARG2, [KBASE, RC, lsl #2]
+ | bl extern lj_tab_dup // (lua_State *L, Table *kt)
+ | // Returns GCtab *.
+ }
+ | ldr BASE, L->base
+ | mvn CARG2, #~LJ_TTAB
+ | ins_next1
+ | ins_next2
+ | strd CARG12, [BASE, RA]
+ | ins_next3
+ |5:
+ | bl extern lj_gc_step_fixtop // (lua_State *L)
+ | mov CARG1, L
+ | b <1
+ break;
+
+ case BC_GGET:
+ | // RA = dst*8, RC = str_const (~)
+ case BC_GSET:
+ | // RA = dst*8, RC = str_const (~)
+ | ldr LFUNC:CARG2, [BASE, FRAME_FUNC]
+ | mvn RC, RC
+ | ldr TAB:CARG1, LFUNC:CARG2->env
+ | ldr STR:RC, [KBASE, RC, lsl #2]
+ if (op == BC_GGET) {
+ | b ->BC_TGETS_Z
+ } else {
+ | b ->BC_TSETS_Z
+ }
+ break;
+
+ case BC_TGETV:
+ | decode_RB8 RB, INS
+ | decode_RC8 RC, INS
+ | // RA = dst*8, RB = table*8, RC = key*8
+ | ldrd TAB:CARG12, [BASE, RB]
+ | ldrd CARG34, [BASE, RC]
+ | checktab CARG2, ->vmeta_tgetv // STALL: load CARG12.
+ | checktp CARG4, LJ_TISNUM // Integer key?
+ | ldreq CARG4, TAB:CARG1->array
+ | ldreq CARG2, TAB:CARG1->asize
+ | bne >9
+ |
+ | add CARG4, CARG4, CARG3, lsl #3
+ | cmp CARG3, CARG2 // In array part?
+ | ldrdlo CARG34, [CARG4]
+ | bhs ->vmeta_tgetv
+ | ins_next1 // Overwrites RB!
+ | checktp CARG4, LJ_TNIL
+ | beq >5
+ |1:
+ | ins_next2
+ | strd CARG34, [BASE, RA]
+ | ins_next3
+ |
+ |5: // Check for __index if table value is nil.
+ | ldr TAB:CARG2, TAB:CARG1->metatable
+ | cmp TAB:CARG2, #0
+ | beq <1 // No metatable: done.
+ | ldrb CARG2, TAB:CARG2->nomm
+ | tst CARG2, #1<<MM_index
+ | bne <1 // 'no __index' flag set: done.
+ | decode_RB8 RB, INS // Restore RB.
+ | b ->vmeta_tgetv
+ |
+ |9:
+ | checktp CARG4, LJ_TSTR // String key?
+ | moveq STR:RC, CARG3
+ | beq ->BC_TGETS_Z
+ | b ->vmeta_tgetv
+ break;
+ case BC_TGETS:
+ | decode_RB8 RB, INS
+ | and RC, RC, #255
+ | // RA = dst*8, RB = table*8, RC = str_const (~)
+ | ldrd CARG12, [BASE, RB]
+ | mvn RC, RC
+ | ldr STR:RC, [KBASE, RC, lsl #2] // STALL: early RC.
+ | checktab CARG2, ->vmeta_tgets1
+ |->BC_TGETS_Z:
+ | // (TAB:RB =) TAB:CARG1 = GCtab *, STR:RC = GCstr *, RA = dst*8
+ | ldr CARG3, TAB:CARG1->hmask
+ | ldr CARG4, STR:RC->hash
+ | ldr NODE:INS, TAB:CARG1->node
+ | mov TAB:RB, TAB:CARG1
+ | and CARG3, CARG3, CARG4 // idx = str->hash & tab->hmask
+ | add CARG3, CARG3, CARG3, lsl #1
+ | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8
+ |1:
+ | ldrd CARG12, NODE:INS->key // STALL: early NODE:INS.
+ | ldrd CARG34, NODE:INS->val
+ | ldr NODE:INS, NODE:INS->next
+ | checktp CARG2, LJ_TSTR
+ | cmpeq CARG1, STR:RC
+ | bne >4
+ | checktp CARG4, LJ_TNIL
+ | beq >5
+ |3:
+ | ins_next1
+ | ins_next2
+ | strd CARG34, [BASE, RA]
+ | ins_next3
+ |
+ |4: // Follow hash chain.
+ | cmp NODE:INS, #0
+ | bne <1
+ | // End of hash chain: key not found, nil result.
+ |
+ |5: // Check for __index if table value is nil.
+ | ldr TAB:CARG1, TAB:RB->metatable
+ | mov CARG3, #0 // Optional clear of undef. value (during load stall).
+ | mvn CARG4, #~LJ_TNIL
+ | cmp TAB:CARG1, #0
+ | beq <3 // No metatable: done.
+ | ldrb CARG2, TAB:CARG1->nomm
+ | tst CARG2, #1<<MM_index
+ | bne <3 // 'no __index' flag set: done.
+ | b ->vmeta_tgets
+ break;
+ case BC_TGETB:
+ | decode_RB8 RB, INS
+ | and RC, RC, #255
+ | // RA = dst*8, RB = table*8, RC = index
+ | ldrd CARG12, [BASE, RB]
+ | checktab CARG2, ->vmeta_tgetb // STALL: load CARG12.
+ | ldr CARG3, TAB:CARG1->asize
+ | ldr CARG4, TAB:CARG1->array
+ | lsl CARG2, RC, #3
+ | cmp RC, CARG3
+ | ldrdlo CARG34, [CARG4, CARG2]
+ | bhs ->vmeta_tgetb
+ | ins_next1 // Overwrites RB!
+ | checktp CARG4, LJ_TNIL
+ | beq >5
+ |1:
+ | ins_next2
+ | strd CARG34, [BASE, RA]
+ | ins_next3
+ |
+ |5: // Check for __index if table value is nil.
+ | ldr TAB:CARG2, TAB:CARG1->metatable
+ | cmp TAB:CARG2, #0
+ | beq <1 // No metatable: done.
+ | ldrb CARG2, TAB:CARG2->nomm
+ | tst CARG2, #1<<MM_index
+ | bne <1 // 'no __index' flag set: done.
+ | b ->vmeta_tgetb
+ break;
+
+ case BC_TSETV:
+ | decode_RB8 RB, INS
+ | decode_RC8 RC, INS
+ | // RA = src*8, RB = table*8, RC = key*8
+ | ldrd TAB:CARG12, [BASE, RB]
+ | ldrd CARG34, [BASE, RC]
+ | checktab CARG2, ->vmeta_tsetv // STALL: load CARG12.
+ | checktp CARG4, LJ_TISNUM // Integer key?
+ | ldreq CARG2, TAB:CARG1->array
+ | ldreq CARG4, TAB:CARG1->asize
+ | bne >9
+ |
+ | add CARG2, CARG2, CARG3, lsl #3
+ | cmp CARG3, CARG4 // In array part?
+ | ldrlo INS, [CARG2, #4]
+ | bhs ->vmeta_tsetv
+ | ins_next1 // Overwrites RB!
+ | checktp INS, LJ_TNIL
+ | ldrb INS, TAB:CARG1->marked
+ | ldrd CARG34, [BASE, RA]
+ | beq >5
+ |1:
+ | tst INS, #LJ_GC_BLACK // isblack(table)
+ | strd CARG34, [CARG2]
+ | bne >7
+ |2:
+ | ins_next2
+ | ins_next3
+ |
+ |5: // Check for __newindex if previous value is nil.
+ | ldr TAB:RA, TAB:CARG1->metatable
+ | cmp TAB:RA, #0
+ | beq <1 // No metatable: done.
+ | ldrb RA, TAB:RA->nomm
+ | tst RA, #1<<MM_newindex
+ | bne <1 // 'no __newindex' flag set: done.
+ | ldr INS, [PC, #-4] // Restore RA and RB.
+ | decode_RB8 RB, INS
+ | decode_RA8 RA, INS
+ | b ->vmeta_tsetv
+ |
+ |7: // Possible table write barrier for the value. Skip valiswhite check.
+ | barrierback TAB:CARG1, INS, CARG3
+ | b <2
+ |
+ |9:
+ | checktp CARG4, LJ_TSTR // String key?
+ | moveq STR:RC, CARG3
+ | beq ->BC_TSETS_Z
+ | b ->vmeta_tsetv
+ break;
+ case BC_TSETS:
+ | decode_RB8 RB, INS
+ | and RC, RC, #255
+ | // RA = src*8, RB = table*8, RC = str_const (~)
+ | ldrd CARG12, [BASE, RB]
+ | mvn RC, RC
+ | ldr STR:RC, [KBASE, RC, lsl #2] // STALL: early RC.
+ | checktab CARG2, ->vmeta_tsets1
+ |->BC_TSETS_Z:
+ | // (TAB:RB =) TAB:CARG1 = GCtab *, STR:RC = GCstr *, RA = dst*8
+ | ldr CARG3, TAB:CARG1->hmask
+ | ldr CARG4, STR:RC->hash
+ | ldr NODE:INS, TAB:CARG1->node
+ | mov TAB:RB, TAB:CARG1
+ | and CARG3, CARG3, CARG4 // idx = str->hash & tab->hmask
+ | add CARG3, CARG3, CARG3, lsl #1
+ | mov CARG4, #0
+ | add NODE:INS, NODE:INS, CARG3, lsl #3 // node = tab->node + idx*3*8
+ | strb CARG4, TAB:RB->nomm // Clear metamethod cache.
+ |1:
+ | ldrd CARG12, NODE:INS->key
+ | ldr CARG4, NODE:INS->val.it
+ | ldr NODE:CARG3, NODE:INS->next
+ | checktp CARG2, LJ_TSTR
+ | cmpeq CARG1, STR:RC
+ | bne >5
+ | ldrb CARG2, TAB:RB->marked
+ | checktp CARG4, LJ_TNIL // Key found, but nil value?
+ | ldrd CARG34, [BASE, RA]
+ | beq >4
+ |2:
+ | tst CARG2, #LJ_GC_BLACK // isblack(table)
+ | strd CARG34, NODE:INS->val
+ | bne >7
+ |3:
+ | ins_next
+ |
+ |4: // Check for __newindex if previous value is nil.
+ | ldr TAB:CARG1, TAB:RB->metatable
+ | cmp TAB:CARG1, #0
+ | beq <2 // No metatable: done.
+ | ldrb CARG1, TAB:CARG1->nomm
+ | tst CARG1, #1<<MM_newindex
+ | bne <2 // 'no __newindex' flag set: done.
+ | b ->vmeta_tsets
+ |
+ |5: // Follow hash chain.
+ | movs NODE:INS, NODE:CARG3
+ | bne <1
+ | // End of hash chain: key not found, add a new one.
+ |
+ | // But check for __newindex first.
+ | ldr TAB:CARG1, TAB:RB->metatable
+ | mov CARG3, TMPDp
+ | str PC, SAVE_PC
+ | cmp TAB:CARG1, #0 // No metatable: continue.
+ | str BASE, L->base
+ | ldrbne CARG2, TAB:CARG1->nomm
+ | mov CARG1, L
+ | beq >6
+ | tst CARG2, #1<<MM_newindex
+ | beq ->vmeta_tsets // 'no __newindex' flag NOT set: check.
+ |6:
+ | mvn CARG4, #~LJ_TSTR
+ | str STR:RC, TMPDlo
+ | mov CARG2, TAB:RB
+ | str CARG4, TMPDhi
+ | bl extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k)
+ | // Returns TValue *.
+ | ldr BASE, L->base
+ | ldrd CARG34, [BASE, RA]
+ | strd CARG34, [CRET1]
+ | b <3 // No 2nd write barrier needed.
+ |
+ |7: // Possible table write barrier for the value. Skip valiswhite check.
+ | barrierback TAB:RB, CARG2, CARG3
+ | b <3
+ break;
+ case BC_TSETB:
+ | decode_RB8 RB, INS
+ | and RC, RC, #255
+ | // RA = src*8, RB = table*8, RC = index
+ | ldrd CARG12, [BASE, RB]
+ | checktab CARG2, ->vmeta_tsetb // STALL: load CARG12.
+ | ldr CARG3, TAB:CARG1->asize
+ | ldr RB, TAB:CARG1->array
+ | lsl CARG2, RC, #3
+ | cmp RC, CARG3
+ | ldrdlo CARG34, [CARG2, RB]!
+ | bhs ->vmeta_tsetb
+ | ins_next1 // Overwrites RB!
+ | checktp CARG4, LJ_TNIL
+ | ldrb INS, TAB:CARG1->marked
+ | ldrd CARG34, [BASE, RA]
+ | beq >5
+ |1:
+ | tst INS, #LJ_GC_BLACK // isblack(table)
+ | strd CARG34, [CARG2]
+ | bne >7
+ |2:
+ | ins_next2
+ | ins_next3
+ |
+ |5: // Check for __newindex if previous value is nil.
+ | ldr TAB:RA, TAB:CARG1->metatable
+ | cmp TAB:RA, #0
+ | beq <1 // No metatable: done.
+ | ldrb RA, TAB:RA->nomm
+ | tst RA, #1<<MM_newindex
+ | bne <1 // 'no __newindex' flag set: done.
+ | ldr INS, [PC, #-4] // Restore INS.
+ | decode_RA8 RA, INS
+ | b ->vmeta_tsetb
+ |
+ |7: // Possible table write barrier for the value. Skip valiswhite check.
+ | barrierback TAB:CARG1, INS, CARG3
+ | b <2
+ break;
+
+ case BC_TSETM:
+ | // RA = base*8 (table at base-1), RC = num_const (start index)
+ | add RA, BASE, RA
+ |1:
+ | ldr RB, SAVE_MULTRES
+ | ldr TAB:CARG2, [RA, #-8] // Guaranteed to be a table.
+ | ldr CARG1, [KBASE, RC, lsl #3] // Integer constant is in lo-word.
+ | subs RB, RB, #8
+ | ldr CARG4, TAB:CARG2->asize
+ | beq >4 // Nothing to copy?
+ | add CARG3, CARG1, RB, lsr #3
+ | cmp CARG3, CARG4
+ | ldr CARG4, TAB:CARG2->array
+ | add RB, RA, RB
+ | bhi >5
+ | add INS, CARG4, CARG1, lsl #3
+ | ldrb CARG1, TAB:CARG2->marked
+ |3: // Copy result slots to table.
+ | ldrd CARG34, [RA], #8
+ | strd CARG34, [INS], #8
+ | cmp RA, RB
+ | blo <3
+ | tst CARG1, #LJ_GC_BLACK // isblack(table)
+ | bne >7
+ |4:
+ | ins_next
+ |
+ |5: // Need to resize array part.
+ | str BASE, L->base
+ | mov CARG1, L
+ | str PC, SAVE_PC
+ | bl extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize)
+ | // Must not reallocate the stack.
+ | .IOS ldr BASE, L->base
+ | b <1
+ |
+ |7: // Possible table write barrier for any value. Skip valiswhite check.
+ | barrierback TAB:CARG2, CARG1, CARG3
+ | b <4
+ break;
+
+ /* -- Calls and vararg handling ----------------------------------------- */
+
+ case BC_CALLM:
+ | // RA = base*8, (RB = nresults+1,) RC = extra_nargs
+ | ldr CARG1, SAVE_MULTRES
+ | decode_RC8 NARGS8:RC, INS
+ | add NARGS8:RC, NARGS8:RC, CARG1
+ | b ->BC_CALL_Z
+ break;
+ case BC_CALL:
+ | decode_RC8 NARGS8:RC, INS
+ | // RA = base*8, (RB = nresults+1,) RC = (nargs+1)*8
+ |->BC_CALL_Z:
+ | mov RB, BASE // Save old BASE for vmeta_call.
+ | ldrd CARG34, [BASE, RA]!
+ | sub NARGS8:RC, NARGS8:RC, #8
+ | add BASE, BASE, #8
+ | checkfunc CARG4, ->vmeta_call
+ | ins_call
+ break;
+
+ case BC_CALLMT:
+ | // RA = base*8, (RB = 0,) RC = extra_nargs
+ | ldr CARG1, SAVE_MULTRES
+ | add NARGS8:RC, CARG1, RC, lsl #3
+ | b ->BC_CALLT1_Z
+ break;
+ case BC_CALLT:
+ | lsl NARGS8:RC, RC, #3
+ | // RA = base*8, (RB = 0,) RC = (nargs+1)*8
+ |->BC_CALLT1_Z:
+ | ldrd LFUNC:CARG34, [RA, BASE]!
+ | sub NARGS8:RC, NARGS8:RC, #8
+ | add RA, RA, #8
+ | checkfunc CARG4, ->vmeta_callt
+ | ldr PC, [BASE, FRAME_PC]
+ |->BC_CALLT2_Z:
+ | mov RB, #0
+ | ldrb CARG4, LFUNC:CARG3->ffid
+ | tst PC, #FRAME_TYPE
+ | bne >7
+ |1:
+ | str LFUNC:CARG3, [BASE, FRAME_FUNC] // Copy function down, but keep PC.
+ | cmp NARGS8:RC, #0
+ | beq >3
+ |2:
+ | ldrd CARG12, [RA, RB]
+ | add INS, RB, #8
+ | cmp INS, NARGS8:RC
+ | strd CARG12, [BASE, RB]
+ | mov RB, INS
+ | bne <2
+ |3:
+ | cmp CARG4, #1 // (> FF_C) Calling a fast function?
+ | bhi >5
+ |4:
+ | ins_callt
+ |
+ |5: // Tailcall to a fast function with a Lua frame below.
+ | ldr INS, [PC, #-4]
+ | decode_RA8 RA, INS
+ | sub CARG1, BASE, RA
+ | ldr LFUNC:CARG1, [CARG1, #-16]
+ | ldr CARG1, LFUNC:CARG1->field_pc
+ | ldr KBASE, [CARG1, #PC2PROTO(k)]
+ | b <4
+ |
+ |7: // Tailcall from a vararg function.
+ | eor PC, PC, #FRAME_VARG
+ | tst PC, #FRAME_TYPEP // Vararg frame below?
+ | movne CARG4, #0 // Clear ffid if no Lua function below.
+ | bne <1
+ | sub BASE, BASE, PC
+ | ldr PC, [BASE, FRAME_PC]
+ | tst PC, #FRAME_TYPE
+ | movne CARG4, #0 // Clear ffid if no Lua function below.
+ | b <1
+ break;
+
+ case BC_ITERC:
+ | // RA = base*8, (RB = nresults+1, RC = nargs+1 (2+1))
+ | add RA, BASE, RA
+ | mov RB, BASE // Save old BASE for vmeta_call.
+ | ldrd CARG34, [RA, #-16]
+ | ldrd CARG12, [RA, #-8]
+ | add BASE, RA, #8
+ | strd CARG34, [RA, #8] // Copy state.
+ | strd CARG12, [RA, #16] // Copy control var.
+ | // STALL: locked CARG34.
+ | ldrd LFUNC:CARG34, [RA, #-24]
+ | mov NARGS8:RC, #16 // Iterators get 2 arguments.
+ | // STALL: load CARG34.
+ | strd LFUNC:CARG34, [RA] // Copy callable.
+ | checkfunc CARG4, ->vmeta_call
+ | ins_call
+ break;
+
+ case BC_ITERN:
+ | // RA = base*8, (RB = nresults+1, RC = nargs+1 (2+1))
+ |.if JIT
+ | // NYI: add hotloop, record BC_ITERN.
+ |.endif
+ | add RA, BASE, RA
+ | ldr TAB:RB, [RA, #-16]
+ | ldr CARG1, [RA, #-8] // Get index from control var.
+ | ldr INS, TAB:RB->asize
+ | ldr CARG2, TAB:RB->array
+ | add PC, PC, #4
+ |1: // Traverse array part.
+ | subs RC, CARG1, INS
+ | add CARG3, CARG2, CARG1, lsl #3
+ | bhs >5 // Index points after array part?
+ | ldrd CARG34, [CARG3]
+ | checktp CARG4, LJ_TNIL
+ | addeq CARG1, CARG1, #1 // Skip holes in array part.
+ | beq <1
+ | ldrh RC, [PC, #-2]
+ | mvn CARG2, #~LJ_TISNUM
+ | strd CARG34, [RA, #8]
+ | add RC, PC, RC, lsl #2
+ | add RB, CARG1, #1
+ | strd CARG12, [RA]
+ | sub PC, RC, #0x20000
+ | str RB, [RA, #-8] // Update control var.
+ |3:
+ | ins_next
+ |
+ |5: // Traverse hash part.
+ | ldr CARG4, TAB:RB->hmask
+ | ldr NODE:RB, TAB:RB->node
+ |6:
+ | add CARG1, RC, RC, lsl #1
+ | cmp RC, CARG4 // End of iteration? Branch to ITERL+1.
+ | add NODE:CARG3, NODE:RB, CARG1, lsl #3 // node = tab->node + idx*3*8
+ | bhi <3
+ | ldrd CARG12, NODE:CARG3->val
+ | checktp CARG2, LJ_TNIL
+ | add RC, RC, #1
+ | beq <6 // Skip holes in hash part.
+ | ldrh RB, [PC, #-2]
+ | add RC, RC, INS
+ | ldrd CARG34, NODE:CARG3->key
+ | str RC, [RA, #-8] // Update control var.
+ | strd CARG12, [RA, #8]
+ | add RC, PC, RB, lsl #2
+ | sub PC, RC, #0x20000
+ | strd CARG34, [RA]
+ | b <3
+ break;
+
+ case BC_ISNEXT:
+ | // RA = base*8, RC = target (points to ITERN)
+ | add RA, BASE, RA
+ | add RC, PC, RC, lsl #2
+ | ldrd CFUNC:CARG12, [RA, #-24]
+ | ldr CARG3, [RA, #-12]
+ | ldr CARG4, [RA, #-4]
+ | checktp CARG2, LJ_TFUNC
+ | ldrbeq CARG1, CFUNC:CARG1->ffid
+ | checktpeq CARG3, LJ_TTAB
+ | checktpeq CARG4, LJ_TNIL
+ | cmpeq CARG1, #FF_next_N
+ | subeq PC, RC, #0x20000
+ | bne >5
+ | ins_next1
+ | ins_next2
+ | mov CARG1, #0
+ | mvn CARG2, #0x00018000
+ | strd CARG1, [RA, #-8] // Initialize control var.
+ |1:
+ | ins_next3
+ |5: // Despecialize bytecode if any of the checks fail.
+ | mov CARG1, #BC_JMP
+ | mov OP, #BC_ITERC
+ | strb CARG1, [PC, #-4]
+ | sub PC, RC, #0x20000
+ | strb OP, [PC] // Subsumes ins_next1.
+ | ins_next2
+ | b <1
+ break;
+
+ case BC_VARG:
+ | decode_RB8 RB, INS
+ | decode_RC8 RC, INS
+ | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8
+ | ldr CARG1, [BASE, FRAME_PC]
+ | add RC, BASE, RC
+ | add RA, BASE, RA
+ | add RC, RC, #FRAME_VARG
+ | add CARG4, RA, RB
+ | sub CARG3, BASE, #8 // CARG3 = vtop
+ | sub RC, RC, CARG1 // RC = vbase
+ | // Note: RC may now be even _above_ BASE if nargs was < numparams.
+ | cmp RB, #0
+ | sub CARG1, CARG3, RC
+ | beq >5 // Copy all varargs?
+ | sub CARG4, CARG4, #16
+ |1: // Copy vararg slots to destination slots.
+ | cmp RC, CARG3
+ | ldrdlo CARG12, [RC], #8
+ | mvnhs CARG2, #~LJ_TNIL
+ | cmp RA, CARG4
+ | strd CARG12, [RA], #8
+ | blo <1
+ |2:
+ | ins_next
+ |
+ |5: // Copy all varargs.
+ | ldr CARG4, L->maxstack
+ | cmp CARG1, #0
+ | movle RB, #8 // MULTRES = (0+1)*8
+ | addgt RB, CARG1, #8
+ | add CARG2, RA, CARG1
+ | str RB, SAVE_MULTRES
+ | ble <2
+ | cmp CARG2, CARG4
+ | bhi >7
+ |6:
+ | ldrd CARG12, [RC], #8
+ | strd CARG12, [RA], #8
+ | cmp RC, CARG3
+ | blo <6
+ | b <2
+ |
+ |7: // Grow stack for varargs.
+ | lsr CARG2, CARG1, #3
+ | str RA, L->top
+ | mov CARG1, L
+ | str BASE, L->base
+ | sub RC, RC, BASE // Need delta, because BASE may change.
+ | str PC, SAVE_PC
+ | sub RA, RA, BASE
+ | bl extern lj_state_growstack // (lua_State *L, int n)
+ | ldr BASE, L->base
+ | add RA, BASE, RA
+ | add RC, BASE, RC
+ | sub CARG3, BASE, #8
+ | b <6
+ break;
+
+ /* -- Returns ----------------------------------------------------------- */
+
+ case BC_RETM:
+ | // RA = results*8, RC = extra results
+ | ldr CARG1, SAVE_MULTRES
+ | ldr PC, [BASE, FRAME_PC]
+ | add RA, BASE, RA
+ | add RC, CARG1, RC, lsl #3
+ | b ->BC_RETM_Z
+ break;
+
+ case BC_RET:
+ | // RA = results*8, RC = nresults+1
+ | ldr PC, [BASE, FRAME_PC]
+ | lsl RC, RC, #3
+ | add RA, BASE, RA
+ |->BC_RETM_Z:
+ | str RC, SAVE_MULTRES
+ |1:
+ | ands CARG1, PC, #FRAME_TYPE
+ | eor CARG2, PC, #FRAME_VARG
+ | bne ->BC_RETV2_Z
+ |
+ |->BC_RET_Z:
+ | // BASE = base, RA = resultptr, RC = (nresults+1)*8, PC = return
+ | ldr INS, [PC, #-4]
+ | subs CARG4, RC, #8
+ | sub CARG3, BASE, #8
+ | beq >3
+ |2:
+ | ldrd CARG12, [RA], #8
+ | add BASE, BASE, #8
+ | subs CARG4, CARG4, #8
+ | strd CARG12, [BASE, #-16]
+ | bne <2
+ |3:
+ | decode_RA8 RA, INS
+ | sub CARG4, CARG3, RA
+ | decode_RB8 RB, INS
+ | ldr LFUNC:CARG1, [CARG4, FRAME_FUNC]
+ |5:
+ | cmp RB, RC // More results expected?
+ | bhi >6
+ | mov BASE, CARG4
+ | ldr CARG2, LFUNC:CARG1->field_pc
+ | ins_next1
+ | ins_next2
+ | ldr KBASE, [CARG2, #PC2PROTO(k)]
+ | ins_next3
+ |
+ |6: // Fill up results with nil.
+ | mvn CARG2, #~LJ_TNIL
+ | add BASE, BASE, #8
+ | add RC, RC, #8
+ | str CARG2, [BASE, #-12]
+ | b <5
+ |
+ |->BC_RETV1_Z: // Non-standard return case.
+ | add RA, BASE, RA
+ |->BC_RETV2_Z:
+ | tst CARG2, #FRAME_TYPEP
+ | bne ->vm_return
+ | // Return from vararg function: relocate BASE down.
+ | sub BASE, BASE, CARG2
+ | ldr PC, [BASE, FRAME_PC]
+ | b <1
+ break;
+
+ case BC_RET0: case BC_RET1:
+ | // RA = results*8, RC = nresults+1
+ | ldr PC, [BASE, FRAME_PC]
+ | lsl RC, RC, #3
+ | str RC, SAVE_MULTRES
+ | ands CARG1, PC, #FRAME_TYPE
+ | eor CARG2, PC, #FRAME_VARG
+ | ldreq INS, [PC, #-4]
+ | bne ->BC_RETV1_Z
+ if (op == BC_RET1) {
+ | ldrd CARG12, [BASE, RA]
+ }
+ | sub CARG4, BASE, #8
+ | decode_RA8 RA, INS
+ if (op == BC_RET1) {
+ | strd CARG12, [CARG4]
+ }
+ | sub BASE, CARG4, RA
+ | decode_RB8 RB, INS
+ | ldr LFUNC:CARG1, [BASE, FRAME_FUNC]
+ |5:
+ | cmp RB, RC
+ | bhi >6
+ | ldr CARG2, LFUNC:CARG1->field_pc
+ | ins_next1
+ | ins_next2
+ | ldr KBASE, [CARG2, #PC2PROTO(k)]
+ | ins_next3
+ |
+ |6: // Fill up results with nil.
+ | sub CARG2, CARG4, #4
+ | mvn CARG3, #~LJ_TNIL
+ | str CARG3, [CARG2, RC]
+ | add RC, RC, #8
+ | b <5
+ break;
+
+ /* -- Loops and branches ------------------------------------------------ */
+
+ |.define FOR_IDX, [RA]; .define FOR_TIDX, [RA, #4]
+ |.define FOR_STOP, [RA, #8]; .define FOR_TSTOP, [RA, #12]
+ |.define FOR_STEP, [RA, #16]; .define FOR_TSTEP, [RA, #20]
+ |.define FOR_EXT, [RA, #24]; .define FOR_TEXT, [RA, #28]
+
+ case BC_FORL:
+ |.if JIT
+ | hotloop
+ |.endif
+ | // Fall through. Assumes BC_IFORL follows.
+ break;
+
+ case BC_JFORI:
+ case BC_JFORL:
+#if !LJ_HASJIT
+ break;
+#endif
+ case BC_FORI:
+ case BC_IFORL:
+ | // RA = base*8, RC = target (after end of loop or start of loop)
+ vk = (op == BC_IFORL || op == BC_JFORL);
+ | ldrd CARG12, [RA, BASE]!
+ if (op != BC_JFORL) {
+ | add RC, PC, RC, lsl #2
+ }
+ if (!vk) {
+ | ldrd CARG34, FOR_STOP
+ | checktp CARG2, LJ_TISNUM
+ | ldr RB, FOR_TSTEP
+ | bne >5
+ | checktp CARG4, LJ_TISNUM
+ | ldr CARG4, FOR_STEP
+ | checktpeq RB, LJ_TISNUM
+ | bne ->vmeta_for
+ | cmp CARG4, #0
+ | blt >4
+ | cmp CARG1, CARG3
+ } else {
+ | ldrd CARG34, FOR_STEP
+ | checktp CARG2, LJ_TISNUM
+ | bne >5
+ | adds CARG1, CARG1, CARG3
+ | ldr CARG4, FOR_STOP
+ if (op == BC_IFORL) {
+ | addvs RC, PC, #0x20000 // Overflow: prevent branch.
+ } else {
+ | bvs >2 // Overflow: do not enter mcode.
+ }
+ | cmp CARG3, #0
+ | blt >4
+ | cmp CARG1, CARG4
+ }
+ |1:
+ if (op == BC_FORI) {
+ | subgt PC, RC, #0x20000
+ } else if (op == BC_JFORI) {
+ | sub PC, RC, #0x20000
+ | ldrhle RC, [PC, #-2]
+ } else if (op == BC_IFORL) {
+ | suble PC, RC, #0x20000
+ }
+ if (vk) {
+ | strd CARG12, FOR_IDX
+ }
+ |2:
+ | ins_next1
+ | ins_next2
+ | strd CARG12, FOR_EXT
+ if (op == BC_JFORI || op == BC_JFORL) {
+ | ble =>BC_JLOOP
+ }
+ |3:
+ | ins_next3
+ |
+ |4: // Invert check for negative step.
+ if (!vk) {
+ | cmp CARG3, CARG1
+ } else {
+ | cmp CARG4, CARG1
+ }
+ | b <1
+ |
+ |5: // FP loop.
+ if (!vk) {
+ | cmnlo CARG4, #-LJ_TISNUM
+ | cmnlo RB, #-LJ_TISNUM
+ | bhs ->vmeta_for
+ |.if FPU
+ | vldr d0, FOR_IDX
+ | vldr d1, FOR_STOP
+ | cmp RB, #0
+ | vstr d0, FOR_EXT
+ |.else
+ | cmp RB, #0
+ | strd CARG12, FOR_EXT
+ | blt >8
+ |.endif
+ } else {
+ |.if FPU
+ | vldr d0, FOR_IDX
+ | vldr d2, FOR_STEP
+ | vldr d1, FOR_STOP
+ | cmp CARG4, #0
+ | vadd.f64 d0, d0, d2
+ |.else
+ | cmp CARG4, #0
+ | blt >8
+ | bl extern __aeabi_dadd
+ | strd CARG12, FOR_IDX
+ | ldrd CARG34, FOR_STOP
+ | strd CARG12, FOR_EXT
+ |.endif
+ }
+ |6:
+ |.if FPU
+ | vcmpge.f64 d0, d1
+ | vcmplt.f64 d1, d0
+ | vmrs
+ |.else
+ | bl extern __aeabi_cdcmple
+ |.endif
+ if (vk) {
+ |.if FPU
+ | vstr d0, FOR_IDX
+ | vstr d0, FOR_EXT
+ |.endif
+ }
+ if (op == BC_FORI) {
+ | subhi PC, RC, #0x20000
+ } else if (op == BC_JFORI) {
+ | sub PC, RC, #0x20000
+ | ldrhls RC, [PC, #-2]
+ | bls =>BC_JLOOP
+ } else if (op == BC_IFORL) {
+ | subls PC, RC, #0x20000
+ } else {
+ | bls =>BC_JLOOP
+ }
+ | ins_next1
+ | ins_next2
+ | b <3
+ |
+ |.if not FPU
+ |8: // Invert check for negative step.
+ if (vk) {
+ | bl extern __aeabi_dadd
+ | strd CARG12, FOR_IDX
+ | strd CARG12, FOR_EXT
+ }
+ | mov CARG3, CARG1
+ | mov CARG4, CARG2
+ | ldrd CARG12, FOR_STOP
+ | b <6
+ |.endif
+ break;
+
+ case BC_ITERL:
+ |.if JIT
+ | hotloop
+ |.endif
+ | // Fall through. Assumes BC_IITERL follows.
+ break;
+
+ case BC_JITERL:
+#if !LJ_HASJIT
+ break;
+#endif
+ case BC_IITERL:
+ | // RA = base*8, RC = target
+ | ldrd CARG12, [RA, BASE]!
+ if (op == BC_JITERL) {
+ | cmn CARG2, #-LJ_TNIL // Stop if iterator returned nil.
+ | strdne CARG12, [RA, #-8]
+ | bne =>BC_JLOOP
+ } else {
+ | add RC, PC, RC, lsl #2
+ | // STALL: load CARG12.
+ | cmn CARG2, #-LJ_TNIL // Stop if iterator returned nil.
+ | subne PC, RC, #0x20000 // Otherwise save control var + branch.
+ | strdne CARG12, [RA, #-8]
+ }
+ | ins_next
+ break;
+
+ case BC_LOOP:
+ | // RA = base*8, RC = target (loop extent)
+ | // Note: RA/RC is only used by trace recorder to determine scope/extent
+ | // This opcode does NOT jump, it's only purpose is to detect a hot loop.
+ |.if JIT
+ | hotloop
+ |.endif
+ | // Fall through. Assumes BC_ILOOP follows.
+ break;
+
+ case BC_ILOOP:
+ | // RA = base*8, RC = target (loop extent)
+ | ins_next
+ break;
+
+ case BC_JLOOP:
+ |.if JIT
+ | // RA = base (ignored), RC = traceno
+ | ldr CARG1, [DISPATCH, #DISPATCH_J(trace)]
+ | mov CARG2, #0 // Traces on ARM don't store the trace number, so use 0.
+ | ldr TRACE:RC, [CARG1, RC, lsl #2]
+ | st_vmstate CARG2
+ | ldr RA, TRACE:RC->mcode
+ | str BASE, [DISPATCH, #DISPATCH_GL(jit_base)]
+ | str L, [DISPATCH, #DISPATCH_GL(jit_L)]
+ | bx RA
+ |.endif
+ break;
+
+ case BC_JMP:
+ | // RA = base*8 (only used by trace recorder), RC = target
+ | add RC, PC, RC, lsl #2
+ | sub PC, RC, #0x20000
+ | ins_next
+ break;
+
+ /* -- Function headers -------------------------------------------------- */
+
+ case BC_FUNCF:
+ |.if JIT
+ | hotcall
+ |.endif
+ case BC_FUNCV: /* NYI: compiled vararg functions. */
+ | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.
+ break;
+
+ case BC_JFUNCF:
+#if !LJ_HASJIT
+ break;
+#endif
+ case BC_IFUNCF:
+ | // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8
+ | ldr CARG1, L->maxstack
+ | ldrb CARG2, [PC, #-4+PC2PROTO(numparams)]
+ | ldr KBASE, [PC, #-4+PC2PROTO(k)]
+ | cmp RA, CARG1
+ | bhi ->vm_growstack_l
+ if (op != BC_JFUNCF) {
+ | ins_next1
+ | ins_next2
+ }
+ |2:
+ | cmp NARGS8:RC, CARG2, lsl #3 // Check for missing parameters.
+ | mvn CARG4, #~LJ_TNIL
+ | blo >3
+ if (op == BC_JFUNCF) {
+ | decode_RD RC, INS
+ | b =>BC_JLOOP
+ } else {
+ | ins_next3
+ }
+ |
+ |3: // Clear missing parameters.
+ | strd CARG34, [BASE, NARGS8:RC]
+ | add NARGS8:RC, NARGS8:RC, #8
+ | b <2
+ break;
+
+ case BC_JFUNCV:
+#if !LJ_HASJIT
+ break;
+#endif
+ | NYI // NYI: compiled vararg functions
+ break; /* NYI: compiled vararg functions. */
+
+ case BC_IFUNCV:
+ | // BASE = new base, RA = BASE+framesize*8, CARG3 = LFUNC, RC = nargs*8
+ | ldr CARG1, L->maxstack
+ | add CARG4, BASE, RC
+ | add RA, RA, RC
+ | str LFUNC:CARG3, [CARG4] // Store copy of LFUNC.
+ | add CARG2, RC, #8+FRAME_VARG
+ | ldr KBASE, [PC, #-4+PC2PROTO(k)]
+ | cmp RA, CARG1
+ | str CARG2, [CARG4, #4] // Store delta + FRAME_VARG.
+ | bhs ->vm_growstack_l
+ | ldrb RB, [PC, #-4+PC2PROTO(numparams)]
+ | mov RA, BASE
+ | mov RC, CARG4
+ | cmp RB, #0
+ | add BASE, CARG4, #8
+ | beq >3
+ | mvn CARG3, #~LJ_TNIL
+ |1:
+ | cmp RA, RC // Less args than parameters?
+ | ldrdlo CARG12, [RA], #8
+ | movhs CARG2, CARG3
+ | strlo CARG3, [RA, #-4] // Clear old fixarg slot (help the GC).
+ |2:
+ | subs RB, RB, #1
+ | strd CARG12, [CARG4, #8]!
+ | bne <1
+ |3:
+ | ins_next
+ break;
+
+ case BC_FUNCC:
+ case BC_FUNCCW:
+ | // BASE = new base, RA = BASE+framesize*8, CARG3 = CFUNC, RC = nargs*8
+ if (op == BC_FUNCC) {
+ | ldr CARG4, CFUNC:CARG3->f
+ } else {
+ | ldr CARG4, [DISPATCH, #DISPATCH_GL(wrapf)]
+ }
+ | add CARG2, RA, NARGS8:RC
+ | ldr CARG1, L->maxstack
+ | add RC, BASE, NARGS8:RC
+ | str BASE, L->base
+ | cmp CARG2, CARG1
+ | str RC, L->top
+ if (op == BC_FUNCCW) {
+ | ldr CARG2, CFUNC:CARG3->f
+ }
+ | mv_vmstate CARG3, C
+ | mov CARG1, L
+ | bhi ->vm_growstack_c // Need to grow stack.
+ | st_vmstate CARG3
+ | blx CARG4 // (lua_State *L [, lua_CFunction f])
+ | // Returns nresults.
+ | ldr BASE, L->base
+ | mv_vmstate CARG3, INTERP
+ | ldr CRET2, L->top
+ | lsl RC, CRET1, #3
+ | st_vmstate CARG3
+ | ldr PC, [BASE, FRAME_PC]
+ | sub RA, CRET2, RC // RA = L->top - nresults*8
+ | b ->vm_returnc
+ break;
+
+ /* ---------------------------------------------------------------------- */
+
+ default:
+ fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]);
+ exit(2);
+ break;
+ }
+}
+
+static int build_backend(BuildCtx *ctx)
+{
+ int op;
+
+ dasm_growpc(Dst, BC__MAX);
+
+ build_subroutines(ctx);
+
+ |.code_op
+ for (op = 0; op < BC__MAX; op++)
+ build_ins(ctx, (BCOp)op, op);
+
+ return BC__MAX;
+}
+
+/* Emit pseudo frame-info for all assembler functions. */
+static void emit_asm_debug(BuildCtx *ctx)
+{
+ int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);
+ int i;
+ switch (ctx->mode) {
+ case BUILD_elfasm:
+ fprintf(ctx->fp, "\t.section .debug_frame,\"\",%%progbits\n");
+ fprintf(ctx->fp,
+ ".Lframe0:\n"
+ "\t.long .LECIE0-.LSCIE0\n"
+ ".LSCIE0:\n"
+ "\t.long 0xffffffff\n"
+ "\t.byte 0x1\n"
+ "\t.string \"\"\n"
+ "\t.uleb128 0x1\n"
+ "\t.sleb128 -4\n"
+ "\t.byte 0xe\n" /* Return address is in lr. */
+ "\t.byte 0xc\n\t.uleb128 0xd\n\t.uleb128 0\n" /* def_cfa sp */
+ "\t.align 2\n"
+ ".LECIE0:\n\n");
+ fprintf(ctx->fp,
+ ".LSFDE0:\n"
+ "\t.long .LEFDE0-.LASFDE0\n"
+ ".LASFDE0:\n"
+ "\t.long .Lframe0\n"
+ "\t.long .Lbegin\n"
+ "\t.long %d\n"
+ "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
+ "\t.byte 0x8e\n\t.uleb128 1\n", /* offset lr */
+ fcofs, CFRAME_SIZE);
+ for (i = 11; i >= (LJ_ARCH_HASFPU ? 5 : 4); i--) /* offset r4-r11 */
+ fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 2+(11-i));
+#if LJ_ARCH_HASFPU
+ for (i = 15; i >= 8; i--) /* offset d8-d15 */
+ fprintf(ctx->fp, "\t.byte 5\n\t.uleb128 %d, %d\n",
+ 64+2*i, 10+2*(15-i));
+ fprintf(ctx->fp, "\t.byte 0x84\n\t.uleb128 %d\n", 25); /* offset r4 */
+#endif
+ fprintf(ctx->fp,
+ "\t.align 2\n"
+ ".LEFDE0:\n\n");
+#if LJ_HASFFI
+ fprintf(ctx->fp,
+ ".LSFDE1:\n"
+ "\t.long .LEFDE1-.LASFDE1\n"
+ ".LASFDE1:\n"
+ "\t.long .Lframe0\n"
+ "\t.long lj_vm_ffi_call\n"
+ "\t.long %d\n"
+ "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */
+ "\t.byte 0x8e\n\t.uleb128 1\n" /* offset lr */
+ "\t.byte 0x8b\n\t.uleb128 2\n" /* offset r11 */
+ "\t.byte 0x85\n\t.uleb128 3\n" /* offset r5 */
+ "\t.byte 0x84\n\t.uleb128 4\n" /* offset r4 */
+ "\t.byte 0xd\n\t.uleb128 0xb\n" /* def_cfa_register r11 */
+ "\t.align 2\n"
+ ".LEFDE1:\n\n", (int)ctx->codesz - fcofs);
+#endif
+ break;
+ default:
+ break;
+ }
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/vm_mips.dasc b/src/3rdparty/LuaJIT-2.0.5/src/vm_mips.dasc
new file mode 100644
index 0000000..3f9c98c
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/vm_mips.dasc
@@ -0,0 +1,4248 @@
+|// Low-level VM code for MIPS CPUs.
+|// Bytecode interpreter, fast functions and helper functions.
+|// Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+|
+|.arch mips
+|.section code_op, code_sub
+|
+|.actionlist build_actionlist
+|.globals GLOB_
+|.globalnames globnames
+|.externnames extnames
+|
+|// Note: The ragged indentation of the instructions is intentional.
+|// The starting columns indicate data dependencies.
+|
+|//-----------------------------------------------------------------------
+|
+|// Fixed register assignments for the interpreter.
+|// Don't use: r0 = 0, r26/r27 = reserved, r28 = gp, r29 = sp, r31 = ra
+|
+|// The following must be C callee-save (but BASE is often refetched).
+|.define BASE, r16 // Base of current Lua stack frame.
+|.define KBASE, r17 // Constants of current Lua function.
+|.define PC, r18 // Next PC.
+|.define DISPATCH, r19 // Opcode dispatch table.
+|.define LREG, r20 // Register holding lua_State (also in SAVE_L).
+|.define MULTRES, r21 // Size of multi-result: (nresults+1)*8.
+|// NYI: r22 currently unused.
+|
+|.define JGL, r30 // On-trace: global_State + 32768.
+|
+|// Constants for type-comparisons, stores and conversions. C callee-save.
+|.define TISNIL, r30
+|.define TOBIT, f30 // 2^52 + 2^51.
+|
+|// The following temporaries are not saved across C calls, except for RA.
+|.define RA, r23 // Callee-save.
+|.define RB, r8
+|.define RC, r9
+|.define RD, r10
+|.define INS, r11
+|
+|.define AT, r1 // Assembler temporary.
+|.define TMP0, r12
+|.define TMP1, r13
+|.define TMP2, r14
+|.define TMP3, r15
+|
+|// Calling conventions.
+|.define CFUNCADDR, r25
+|.define CARG1, r4
+|.define CARG2, r5
+|.define CARG3, r6
+|.define CARG4, r7
+|
+|.define CRET1, r2
+|.define CRET2, r3
+|
+|.define FARG1, f12
+|.define FARG2, f14
+|
+|.define FRET1, f0
+|.define FRET2, f2
+|
+|// Stack layout while in interpreter. Must match with lj_frame.h.
+|.define CFRAME_SPACE, 112 // Delta for sp.
+|
+|.define SAVE_ERRF, 124(sp) // 32 bit C frame info.
+|.define SAVE_NRES, 120(sp)
+|.define SAVE_CFRAME, 116(sp)
+|.define SAVE_L, 112(sp)
+|//----- 8 byte aligned, ^^^^ 16 byte register save area, owned by interpreter.
+|.define SAVE_GPR_, 72 // .. 72+10*4: 32 bit GPR saves.
+|.define SAVE_FPR_, 24 // .. 24+6*8: 64 bit FPR saves.
+|.define SAVE_PC, 20(sp)
+|.define ARG5, 16(sp)
+|.define CSAVE_4, 12(sp)
+|.define CSAVE_3, 8(sp)
+|.define CSAVE_2, 4(sp)
+|.define CSAVE_1, 0(sp)
+|//----- 8 byte aligned, ^^^^ 16 byte register save area, owned by callee.
+|
+|.define ARG5_OFS, 16
+|.define SAVE_MULTRES, ARG5
+|
+|.macro saveregs
+| addiu sp, sp, -CFRAME_SPACE
+| sw ra, SAVE_GPR_+9*4(sp)
+| sw r30, SAVE_GPR_+8*4(sp)
+| sdc1 f30, SAVE_FPR_+5*8(sp)
+| sw r23, SAVE_GPR_+7*4(sp)
+| sw r22, SAVE_GPR_+6*4(sp)
+| sdc1 f28, SAVE_FPR_+4*8(sp)
+| sw r21, SAVE_GPR_+5*4(sp)
+| sw r20, SAVE_GPR_+4*4(sp)
+| sdc1 f26, SAVE_FPR_+3*8(sp)
+| sw r19, SAVE_GPR_+3*4(sp)
+| sw r18, SAVE_GPR_+2*4(sp)
+| sdc1 f24, SAVE_FPR_+2*8(sp)
+| sw r17, SAVE_GPR_+1*4(sp)
+| sw r16, SAVE_GPR_+0*4(sp)
+| sdc1 f22, SAVE_FPR_+1*8(sp)
+| sdc1 f20, SAVE_FPR_+0*8(sp)
+|.endmacro
+|
+|.macro restoreregs_ret
+| lw ra, SAVE_GPR_+9*4(sp)
+| lw r30, SAVE_GPR_+8*4(sp)
+| ldc1 f30, SAVE_FPR_+5*8(sp)
+| lw r23, SAVE_GPR_+7*4(sp)
+| lw r22, SAVE_GPR_+6*4(sp)
+| ldc1 f28, SAVE_FPR_+4*8(sp)
+| lw r21, SAVE_GPR_+5*4(sp)
+| lw r20, SAVE_GPR_+4*4(sp)
+| ldc1 f26, SAVE_FPR_+3*8(sp)
+| lw r19, SAVE_GPR_+3*4(sp)
+| lw r18, SAVE_GPR_+2*4(sp)
+| ldc1 f24, SAVE_FPR_+2*8(sp)
+| lw r17, SAVE_GPR_+1*4(sp)
+| lw r16, SAVE_GPR_+0*4(sp)
+| ldc1 f22, SAVE_FPR_+1*8(sp)
+| ldc1 f20, SAVE_FPR_+0*8(sp)
+| jr ra
+| addiu sp, sp, CFRAME_SPACE
+|.endmacro
+|
+|// Type definitions. Some of these are only used for documentation.
+|.type L, lua_State, LREG
+|.type GL, global_State
+|.type TVALUE, TValue
+|.type GCOBJ, GCobj
+|.type STR, GCstr
+|.type TAB, GCtab
+|.type LFUNC, GCfuncL
+|.type CFUNC, GCfuncC
+|.type PROTO, GCproto
+|.type UPVAL, GCupval
+|.type NODE, Node
+|.type NARGS8, int
+|.type TRACE, GCtrace
+|
+|//-----------------------------------------------------------------------
+|
+|// Trap for not-yet-implemented parts.
+|.macro NYI; .long 0xf0f0f0f0; .endmacro
+|
+|// Macros to mark delay slots.
+|.macro ., a; a; .endmacro
+|.macro ., a,b; a,b; .endmacro
+|.macro ., a,b,c; a,b,c; .endmacro
+|
+|//-----------------------------------------------------------------------
+|
+|// Endian-specific defines.
+|.define FRAME_PC, LJ_ENDIAN_SELECT(-4,-8)
+|.define FRAME_FUNC, LJ_ENDIAN_SELECT(-8,-4)
+|.define HI, LJ_ENDIAN_SELECT(4,0)
+|.define LO, LJ_ENDIAN_SELECT(0,4)
+|.define OFS_RD, LJ_ENDIAN_SELECT(2,0)
+|.define OFS_RA, LJ_ENDIAN_SELECT(1,2)
+|.define OFS_OP, LJ_ENDIAN_SELECT(0,3)
+|
+|// Instruction decode.
+|.macro decode_OP1, dst, ins; andi dst, ins, 0xff; .endmacro
+|.macro decode_OP4a, dst, ins; andi dst, ins, 0xff; .endmacro
+|.macro decode_OP4b, dst; sll dst, dst, 2; .endmacro
+|.macro decode_RC4a, dst, ins; srl dst, ins, 14; .endmacro
+|.macro decode_RC4b, dst; andi dst, dst, 0x3fc; .endmacro
+|.macro decode_RD4b, dst; sll dst, dst, 2; .endmacro
+|.macro decode_RA8a, dst, ins; srl dst, ins, 5; .endmacro
+|.macro decode_RA8b, dst; andi dst, dst, 0x7f8; .endmacro
+|.macro decode_RB8a, dst, ins; srl dst, ins, 21; .endmacro
+|.macro decode_RB8b, dst; andi dst, dst, 0x7f8; .endmacro
+|.macro decode_RD8a, dst, ins; srl dst, ins, 16; .endmacro
+|.macro decode_RD8b, dst; sll dst, dst, 3; .endmacro
+|.macro decode_RDtoRC8, dst, src; andi dst, src, 0x7f8; .endmacro
+|
+|// Instruction fetch.
+|.macro ins_NEXT1
+| lw INS, 0(PC)
+| addiu PC, PC, 4
+|.endmacro
+|// Instruction decode+dispatch.
+|.macro ins_NEXT2
+| decode_OP4a TMP1, INS
+| decode_OP4b TMP1
+| addu TMP0, DISPATCH, TMP1
+| decode_RD8a RD, INS
+| lw AT, 0(TMP0)
+| decode_RA8a RA, INS
+| decode_RD8b RD
+| jr AT
+| decode_RA8b RA
+|.endmacro
+|.macro ins_NEXT
+| ins_NEXT1
+| ins_NEXT2
+|.endmacro
+|
+|// Instruction footer.
+|.if 1
+| // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.
+| .define ins_next, ins_NEXT
+| .define ins_next_, ins_NEXT
+| .define ins_next1, ins_NEXT1
+| .define ins_next2, ins_NEXT2
+|.else
+| // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.
+| // Affects only certain kinds of benchmarks (and only with -j off).
+| .macro ins_next
+| b ->ins_next
+| .endmacro
+| .macro ins_next1
+| .endmacro
+| .macro ins_next2
+| b ->ins_next
+| .endmacro
+| .macro ins_next_
+| ->ins_next:
+| ins_NEXT
+| .endmacro
+|.endif
+|
+|// Call decode and dispatch.
+|.macro ins_callt
+| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC
+| lw PC, LFUNC:RB->pc
+| lw INS, 0(PC)
+| addiu PC, PC, 4
+| decode_OP4a TMP1, INS
+| decode_RA8a RA, INS
+| decode_OP4b TMP1
+| decode_RA8b RA
+| addu TMP0, DISPATCH, TMP1
+| lw TMP0, 0(TMP0)
+| jr TMP0
+| addu RA, RA, BASE
+|.endmacro
+|
+|.macro ins_call
+| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, PC = caller PC
+| sw PC, FRAME_PC(BASE)
+| ins_callt
+|.endmacro
+|
+|//-----------------------------------------------------------------------
+|
+|.macro branch_RD
+| srl TMP0, RD, 1
+| lui AT, (-(BCBIAS_J*4 >> 16) & 65535)
+| addu TMP0, TMP0, AT
+| addu PC, PC, TMP0
+|.endmacro
+|
+|// Assumes DISPATCH is relative to GL.
+#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field))
+#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field))
+#define GG_DISP2GOT (GG_OFS(got) - GG_OFS(dispatch))
+#define DISPATCH_GOT(name) (GG_DISP2GOT + 4*LJ_GOT_##name)
+|
+#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
+|
+|.macro load_got, func
+| lw CFUNCADDR, DISPATCH_GOT(func)(DISPATCH)
+|.endmacro
+|// Much faster. Sadly, there's no easy way to force the required code layout.
+|// .macro call_intern, func; bal extern func; .endmacro
+|.macro call_intern, func; jalr CFUNCADDR; .endmacro
+|.macro call_extern; jalr CFUNCADDR; .endmacro
+|.macro jmp_extern; jr CFUNCADDR; .endmacro
+|
+|.macro hotcheck, delta, target
+| srl TMP1, PC, 1
+| andi TMP1, TMP1, 126
+| addu TMP1, TMP1, DISPATCH
+| lhu TMP2, GG_DISP2HOT(TMP1)
+| addiu TMP2, TMP2, -delta
+| bltz TMP2, target
+|. sh TMP2, GG_DISP2HOT(TMP1)
+|.endmacro
+|
+|.macro hotloop
+| hotcheck HOTCOUNT_LOOP, ->vm_hotloop
+|.endmacro
+|
+|.macro hotcall
+| hotcheck HOTCOUNT_CALL, ->vm_hotcall
+|.endmacro
+|
+|// Set current VM state. Uses TMP0.
+|.macro li_vmstate, st; li TMP0, ~LJ_VMST_..st; .endmacro
+|.macro st_vmstate; sw TMP0, DISPATCH_GL(vmstate)(DISPATCH); .endmacro
+|
+|// Move table write barrier back. Overwrites mark and tmp.
+|.macro barrierback, tab, mark, tmp, target
+| lw tmp, DISPATCH_GL(gc.grayagain)(DISPATCH)
+| andi mark, mark, ~LJ_GC_BLACK & 255 // black2gray(tab)
+| sw tab, DISPATCH_GL(gc.grayagain)(DISPATCH)
+| sb mark, tab->marked
+| b target
+|. sw tmp, tab->gclist
+|.endmacro
+|
+|//-----------------------------------------------------------------------
+
+/* Generate subroutines used by opcodes and other parts of the VM. */
+/* The .code_sub section should be last to help static branch prediction. */
+static void build_subroutines(BuildCtx *ctx)
+{
+ |.code_sub
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Return handling ----------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_returnp:
+ | // See vm_return. Also: TMP2 = previous base.
+ | andi AT, PC, FRAME_P
+ | beqz AT, ->cont_dispatch
+ |. li TMP1, LJ_TTRUE
+ |
+ | // Return from pcall or xpcall fast func.
+ | lw PC, FRAME_PC(TMP2) // Fetch PC of previous frame.
+ | move BASE, TMP2 // Restore caller base.
+ | // Prepending may overwrite the pcall frame, so do it at the end.
+ | sw TMP1, FRAME_PC(RA) // Prepend true to results.
+ | addiu RA, RA, -8
+ |
+ |->vm_returnc:
+ | addiu RD, RD, 8 // RD = (nresults+1)*8.
+ | andi TMP0, PC, FRAME_TYPE
+ | beqz RD, ->vm_unwind_c_eh
+ |. li CRET1, LUA_YIELD
+ | beqz TMP0, ->BC_RET_Z // Handle regular return to Lua.
+ |. move MULTRES, RD
+ |
+ |->vm_return:
+ | // BASE = base, RA = resultptr, RD/MULTRES = (nresults+1)*8, PC = return
+ | // TMP0 = PC & FRAME_TYPE
+ | li TMP2, -8
+ | xori AT, TMP0, FRAME_C
+ | and TMP2, PC, TMP2
+ | bnez AT, ->vm_returnp
+ | subu TMP2, BASE, TMP2 // TMP2 = previous base.
+ |
+ | addiu TMP1, RD, -8
+ | sw TMP2, L->base
+ | li_vmstate C
+ | lw TMP2, SAVE_NRES
+ | addiu BASE, BASE, -8
+ | st_vmstate
+ | beqz TMP1, >2
+ |. sll TMP2, TMP2, 3
+ |1:
+ | addiu TMP1, TMP1, -8
+ | ldc1 f0, 0(RA)
+ | addiu RA, RA, 8
+ | sdc1 f0, 0(BASE)
+ | bnez TMP1, <1
+ |. addiu BASE, BASE, 8
+ |
+ |2:
+ | bne TMP2, RD, >6
+ |3:
+ |. sw BASE, L->top // Store new top.
+ |
+ |->vm_leave_cp:
+ | lw TMP0, SAVE_CFRAME // Restore previous C frame.
+ | move CRET1, r0 // Ok return status for vm_pcall.
+ | sw TMP0, L->cframe
+ |
+ |->vm_leave_unw:
+ | restoreregs_ret
+ |
+ |6:
+ | lw TMP1, L->maxstack
+ | slt AT, TMP2, RD
+ | bnez AT, >7 // Less results wanted?
+ | // More results wanted. Check stack size and fill up results with nil.
+ |. slt AT, BASE, TMP1
+ | beqz AT, >8
+ |. nop
+ | sw TISNIL, HI(BASE)
+ | addiu RD, RD, 8
+ | b <2
+ |. addiu BASE, BASE, 8
+ |
+ |7: // Less results wanted.
+ | subu TMP0, RD, TMP2
+ | subu TMP0, BASE, TMP0 // Either keep top or shrink it.
+ | b <3
+ |. movn BASE, TMP0, TMP2 // LUA_MULTRET+1 case?
+ |
+ |8: // Corner case: need to grow stack for filling up results.
+ | // This can happen if:
+ | // - A C function grows the stack (a lot).
+ | // - The GC shrinks the stack in between.
+ | // - A return back from a lua_call() with (high) nresults adjustment.
+ | load_got lj_state_growstack
+ | move MULTRES, RD
+ | srl CARG2, TMP2, 3
+ | call_intern lj_state_growstack // (lua_State *L, int n)
+ |. move CARG1, L
+ | lw TMP2, SAVE_NRES
+ | lw BASE, L->top // Need the (realloced) L->top in BASE.
+ | move RD, MULTRES
+ | b <2
+ |. sll TMP2, TMP2, 3
+ |
+ |->vm_unwind_c: // Unwind C stack, return from vm_pcall.
+ | // (void *cframe, int errcode)
+ | move sp, CARG1
+ | move CRET1, CARG2
+ |->vm_unwind_c_eh: // Landing pad for external unwinder.
+ | lw L, SAVE_L
+ | li TMP0, ~LJ_VMST_C
+ | lw GL:TMP1, L->glref
+ | b ->vm_leave_unw
+ |. sw TMP0, GL:TMP1->vmstate
+ |
+ |->vm_unwind_ff: // Unwind C stack, return from ff pcall.
+ | // (void *cframe)
+ | li AT, -4
+ | and sp, CARG1, AT
+ |->vm_unwind_ff_eh: // Landing pad for external unwinder.
+ | lw L, SAVE_L
+ | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
+ | li TISNIL, LJ_TNIL
+ | lw BASE, L->base
+ | lw DISPATCH, L->glref // Setup pointer to dispatch table.
+ | mtc1 TMP3, TOBIT
+ | li TMP1, LJ_TFALSE
+ | li_vmstate INTERP
+ | lw PC, FRAME_PC(BASE) // Fetch PC of previous frame.
+ | cvt.d.s TOBIT, TOBIT
+ | addiu RA, BASE, -8 // Results start at BASE-8.
+ | addiu DISPATCH, DISPATCH, GG_G2DISP
+ | sw TMP1, HI(RA) // Prepend false to error message.
+ | st_vmstate
+ | b ->vm_returnc
+ |. li RD, 16 // 2 results: false + error message.
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Grow stack for calls -----------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_growstack_c: // Grow stack for C function.
+ | b >2
+ |. li CARG2, LUA_MINSTACK
+ |
+ |->vm_growstack_l: // Grow stack for Lua function.
+ | // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC
+ | addu RC, BASE, RC
+ | subu RA, RA, BASE
+ | sw BASE, L->base
+ | addiu PC, PC, 4 // Must point after first instruction.
+ | sw RC, L->top
+ | srl CARG2, RA, 3
+ |2:
+ | // L->base = new base, L->top = top
+ | load_got lj_state_growstack
+ | sw PC, SAVE_PC
+ | call_intern lj_state_growstack // (lua_State *L, int n)
+ |. move CARG1, L
+ | lw BASE, L->base
+ | lw RC, L->top
+ | lw LFUNC:RB, FRAME_FUNC(BASE)
+ | subu RC, RC, BASE
+ | // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC
+ | ins_callt // Just retry the call.
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Entry points into the assembler VM ---------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_resume: // Setup C frame and resume thread.
+ | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)
+ | saveregs
+ | move L, CARG1
+ | lw DISPATCH, L->glref // Setup pointer to dispatch table.
+ | move BASE, CARG2
+ | lbu TMP1, L->status
+ | sw L, SAVE_L
+ | li PC, FRAME_CP
+ | addiu TMP0, sp, CFRAME_RESUME
+ | addiu DISPATCH, DISPATCH, GG_G2DISP
+ | sw r0, SAVE_NRES
+ | sw r0, SAVE_ERRF
+ | sw TMP0, L->cframe
+ | sw r0, SAVE_CFRAME
+ | beqz TMP1, >3
+ |. sw CARG1, SAVE_PC // Any value outside of bytecode is ok.
+ |
+ | // Resume after yield (like a return).
+ | move RA, BASE
+ | lw BASE, L->base
+ | lw TMP1, L->top
+ | lw PC, FRAME_PC(BASE)
+ | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
+ | subu RD, TMP1, BASE
+ | mtc1 TMP3, TOBIT
+ | sb r0, L->status
+ | cvt.d.s TOBIT, TOBIT
+ | li_vmstate INTERP
+ | addiu RD, RD, 8
+ | st_vmstate
+ | move MULTRES, RD
+ | andi TMP0, PC, FRAME_TYPE
+ | beqz TMP0, ->BC_RET_Z
+ |. li TISNIL, LJ_TNIL
+ | b ->vm_return
+ |. nop
+ |
+ |->vm_pcall: // Setup protected C frame and enter VM.
+ | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)
+ | saveregs
+ | sw CARG4, SAVE_ERRF
+ | b >1
+ |. li PC, FRAME_CP
+ |
+ |->vm_call: // Setup C frame and enter VM.
+ | // (lua_State *L, TValue *base, int nres1)
+ | saveregs
+ | li PC, FRAME_C
+ |
+ |1: // Entry point for vm_pcall above (PC = ftype).
+ | lw TMP1, L:CARG1->cframe
+ | sw CARG3, SAVE_NRES
+ | move L, CARG1
+ | sw CARG1, SAVE_L
+ | move BASE, CARG2
+ | sw sp, L->cframe // Add our C frame to cframe chain.
+ | lw DISPATCH, L->glref // Setup pointer to dispatch table.
+ | sw CARG1, SAVE_PC // Any value outside of bytecode is ok.
+ | sw TMP1, SAVE_CFRAME
+ | addiu DISPATCH, DISPATCH, GG_G2DISP
+ |
+ |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).
+ | lw TMP2, L->base // TMP2 = old base (used in vmeta_call).
+ | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
+ | lw TMP1, L->top
+ | mtc1 TMP3, TOBIT
+ | addu PC, PC, BASE
+ | subu NARGS8:RC, TMP1, BASE
+ | subu PC, PC, TMP2 // PC = frame delta + frame type
+ | cvt.d.s TOBIT, TOBIT
+ | li_vmstate INTERP
+ | li TISNIL, LJ_TNIL
+ | st_vmstate
+ |
+ |->vm_call_dispatch:
+ | // TMP2 = old base, BASE = new base, RC = nargs*8, PC = caller PC
+ | lw TMP0, FRAME_PC(BASE)
+ | li AT, LJ_TFUNC
+ | bne TMP0, AT, ->vmeta_call
+ |. lw LFUNC:RB, FRAME_FUNC(BASE)
+ |
+ |->vm_call_dispatch_f:
+ | ins_call
+ | // BASE = new base, RB = func, RC = nargs*8, PC = caller PC
+ |
+ |->vm_cpcall: // Setup protected C frame, call C.
+ | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)
+ | saveregs
+ | move L, CARG1
+ | lw TMP0, L:CARG1->stack
+ | sw CARG1, SAVE_L
+ | lw TMP1, L->top
+ | sw CARG1, SAVE_PC // Any value outside of bytecode is ok.
+ | subu TMP0, TMP0, TMP1 // Compute -savestack(L, L->top).
+ | lw TMP1, L->cframe
+ | sw sp, L->cframe // Add our C frame to cframe chain.
+ | sw TMP0, SAVE_NRES // Neg. delta means cframe w/o frame.
+ | sw r0, SAVE_ERRF // No error function.
+ | move CFUNCADDR, CARG4
+ | jalr CARG4 // (lua_State *L, lua_CFunction func, void *ud)
+ |. sw TMP1, SAVE_CFRAME
+ | move BASE, CRET1
+ | lw DISPATCH, L->glref // Setup pointer to dispatch table.
+ | li PC, FRAME_CP
+ | bnez CRET1, <3 // Else continue with the call.
+ |. addiu DISPATCH, DISPATCH, GG_G2DISP
+ | b ->vm_leave_cp // No base? Just remove C frame.
+ |. nop
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Metamethod handling ------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |// The lj_meta_* functions (except for lj_meta_cat) don't reallocate the
+ |// stack, so BASE doesn't need to be reloaded across these calls.
+ |
+ |//-- Continuation dispatch ----------------------------------------------
+ |
+ |->cont_dispatch:
+ | // BASE = meta base, RA = resultptr, RD = (nresults+1)*8
+ | lw TMP0, -16+LO(BASE) // Continuation.
+ | move RB, BASE
+ | move BASE, TMP2 // Restore caller BASE.
+ | lw LFUNC:TMP1, FRAME_FUNC(TMP2)
+ |.if FFI
+ | sltiu AT, TMP0, 2
+ |.endif
+ | lw PC, -16+HI(RB) // Restore PC from [cont|PC].
+ | addu TMP2, RA, RD
+ | lw TMP1, LFUNC:TMP1->pc
+ |.if FFI
+ | bnez AT, >1
+ |.endif
+ |. sw TISNIL, -8+HI(TMP2) // Ensure one valid arg.
+ | // BASE = base, RA = resultptr, RB = meta base
+ | jr TMP0 // Jump to continuation.
+ |. lw KBASE, PC2PROTO(k)(TMP1)
+ |
+ |.if FFI
+ |1:
+ | bnez TMP0, ->cont_ffi_callback // cont = 1: return from FFI callback.
+ | // cont = 0: tailcall from C function.
+ |. addiu TMP1, RB, -16
+ | b ->vm_call_tail
+ |. subu RC, TMP1, BASE
+ |.endif
+ |
+ |->cont_cat: // RA = resultptr, RB = meta base
+ | lw INS, -4(PC)
+ | addiu CARG2, RB, -16
+ | ldc1 f0, 0(RA)
+ | decode_RB8a MULTRES, INS
+ | decode_RA8a RA, INS
+ | decode_RB8b MULTRES
+ | decode_RA8b RA
+ | addu TMP1, BASE, MULTRES
+ | sw BASE, L->base
+ | subu CARG3, CARG2, TMP1
+ | bne TMP1, CARG2, ->BC_CAT_Z
+ |. sdc1 f0, 0(CARG2)
+ | addu RA, BASE, RA
+ | b ->cont_nop
+ |. sdc1 f0, 0(RA)
+ |
+ |//-- Table indexing metamethods -----------------------------------------
+ |
+ |->vmeta_tgets1:
+ | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)
+ | li TMP0, LJ_TSTR
+ | sw STR:RC, LO(CARG3)
+ | b >1
+ |. sw TMP0, HI(CARG3)
+ |
+ |->vmeta_tgets:
+ | addiu CARG2, DISPATCH, DISPATCH_GL(tmptv)
+ | li TMP0, LJ_TTAB
+ | sw TAB:RB, LO(CARG2)
+ | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv2)
+ | sw TMP0, HI(CARG2)
+ | li TMP1, LJ_TSTR
+ | sw STR:RC, LO(CARG3)
+ | b >1
+ |. sw TMP1, HI(CARG3)
+ |
+ |->vmeta_tgetb: // TMP0 = index
+ | mtc1 TMP0, f0
+ | cvt.d.w f0, f0
+ | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)
+ | sdc1 f0, 0(CARG3)
+ |
+ |->vmeta_tgetv:
+ |1:
+ | load_got lj_meta_tget
+ | sw BASE, L->base
+ | sw PC, SAVE_PC
+ | call_intern lj_meta_tget // (lua_State *L, TValue *o, TValue *k)
+ |. move CARG1, L
+ | // Returns TValue * (finished) or NULL (metamethod).
+ | beqz CRET1, >3
+ |. addiu TMP1, BASE, -FRAME_CONT
+ | ldc1 f0, 0(CRET1)
+ | ins_next1
+ | sdc1 f0, 0(RA)
+ | ins_next2
+ |
+ |3: // Call __index metamethod.
+ | // BASE = base, L->top = new base, stack = cont/func/t/k
+ | lw BASE, L->top
+ | sw PC, -16+HI(BASE) // [cont|PC]
+ | subu PC, BASE, TMP1
+ | lw LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here.
+ | b ->vm_call_dispatch_f
+ |. li NARGS8:RC, 16 // 2 args for func(t, k).
+ |
+ |//-----------------------------------------------------------------------
+ |
+ |->vmeta_tsets1:
+ | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)
+ | li TMP0, LJ_TSTR
+ | sw STR:RC, LO(CARG3)
+ | b >1
+ |. sw TMP0, HI(CARG3)
+ |
+ |->vmeta_tsets:
+ | addiu CARG2, DISPATCH, DISPATCH_GL(tmptv)
+ | li TMP0, LJ_TTAB
+ | sw TAB:RB, LO(CARG2)
+ | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv2)
+ | sw TMP0, HI(CARG2)
+ | li TMP1, LJ_TSTR
+ | sw STR:RC, LO(CARG3)
+ | b >1
+ |. sw TMP1, HI(CARG3)
+ |
+ |->vmeta_tsetb: // TMP0 = index
+ | mtc1 TMP0, f0
+ | cvt.d.w f0, f0
+ | addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)
+ | sdc1 f0, 0(CARG3)
+ |
+ |->vmeta_tsetv:
+ |1:
+ | load_got lj_meta_tset
+ | sw BASE, L->base
+ | sw PC, SAVE_PC
+ | call_intern lj_meta_tset // (lua_State *L, TValue *o, TValue *k)
+ |. move CARG1, L
+ | // Returns TValue * (finished) or NULL (metamethod).
+ | beqz CRET1, >3
+ |. ldc1 f0, 0(RA)
+ | // NOBARRIER: lj_meta_tset ensures the table is not black.
+ | ins_next1
+ | sdc1 f0, 0(CRET1)
+ | ins_next2
+ |
+ |3: // Call __newindex metamethod.
+ | // BASE = base, L->top = new base, stack = cont/func/t/k/(v)
+ | addiu TMP1, BASE, -FRAME_CONT
+ | lw BASE, L->top
+ | sw PC, -16+HI(BASE) // [cont|PC]
+ | subu PC, BASE, TMP1
+ | lw LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here.
+ | sdc1 f0, 16(BASE) // Copy value to third argument.
+ | b ->vm_call_dispatch_f
+ |. li NARGS8:RC, 24 // 3 args for func(t, k, v)
+ |
+ |//-- Comparison metamethods ---------------------------------------------
+ |
+ |->vmeta_comp:
+ | // CARG2, CARG3 are already set by BC_ISLT/BC_ISGE/BC_ISLE/BC_ISGT.
+ | load_got lj_meta_comp
+ | addiu PC, PC, -4
+ | sw BASE, L->base
+ | sw PC, SAVE_PC
+ | decode_OP1 CARG4, INS
+ | call_intern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op)
+ |. move CARG1, L
+ | // Returns 0/1 or TValue * (metamethod).
+ |3:
+ | sltiu AT, CRET1, 2
+ | beqz AT, ->vmeta_binop
+ | negu TMP2, CRET1
+ |4:
+ | lhu RD, OFS_RD(PC)
+ | addiu PC, PC, 4
+ | lui TMP1, (-(BCBIAS_J*4 >> 16) & 65535)
+ | sll RD, RD, 2
+ | addu RD, RD, TMP1
+ | and RD, RD, TMP2
+ | addu PC, PC, RD
+ |->cont_nop:
+ | ins_next
+ |
+ |->cont_ra: // RA = resultptr
+ | lbu TMP1, -4+OFS_RA(PC)
+ | ldc1 f0, 0(RA)
+ | sll TMP1, TMP1, 3
+ | addu TMP1, BASE, TMP1
+ | b ->cont_nop
+ |. sdc1 f0, 0(TMP1)
+ |
+ |->cont_condt: // RA = resultptr
+ | lw TMP0, HI(RA)
+ | sltiu AT, TMP0, LJ_TISTRUECOND
+ | b <4
+ |. negu TMP2, AT // Branch if result is true.
+ |
+ |->cont_condf: // RA = resultptr
+ | lw TMP0, HI(RA)
+ | sltiu AT, TMP0, LJ_TISTRUECOND
+ | b <4
+ |. addiu TMP2, AT, -1 // Branch if result is false.
+ |
+ |->vmeta_equal:
+ | // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV.
+ | load_got lj_meta_equal
+ | addiu PC, PC, -4
+ | sw BASE, L->base
+ | sw PC, SAVE_PC
+ | call_intern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne)
+ |. move CARG1, L
+ | // Returns 0/1 or TValue * (metamethod).
+ | b <3
+ |. nop
+ |
+ |->vmeta_equal_cd:
+ |.if FFI
+ | load_got lj_meta_equal_cd
+ | move CARG2, INS
+ | addiu PC, PC, -4
+ | sw BASE, L->base
+ | sw PC, SAVE_PC
+ | call_intern lj_meta_equal_cd // (lua_State *L, BCIns op)
+ |. move CARG1, L
+ | // Returns 0/1 or TValue * (metamethod).
+ | b <3
+ |. nop
+ |.endif
+ |
+ |//-- Arithmetic metamethods ---------------------------------------------
+ |
+ |->vmeta_unm:
+ | move CARG4, CARG3
+ |
+ |->vmeta_arith:
+ | load_got lj_meta_arith
+ | decode_OP1 TMP0, INS
+ | sw BASE, L->base
+ | sw PC, SAVE_PC
+ | move CARG2, RA
+ | sw TMP0, ARG5
+ | call_intern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)
+ |. move CARG1, L
+ | // Returns NULL (finished) or TValue * (metamethod).
+ | beqz CRET1, ->cont_nop
+ |. nop
+ |
+ | // Call metamethod for binary op.
+ |->vmeta_binop:
+ | // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2
+ | subu TMP1, CRET1, BASE
+ | sw PC, -16+HI(CRET1) // [cont|PC]
+ | move TMP2, BASE
+ | addiu PC, TMP1, FRAME_CONT
+ | move BASE, CRET1
+ | b ->vm_call_dispatch
+ |. li NARGS8:RC, 16 // 2 args for func(o1, o2).
+ |
+ |->vmeta_len:
+ | // CARG2 already set by BC_LEN.
+#if LJ_52
+ | move MULTRES, CARG1
+#endif
+ | load_got lj_meta_len
+ | sw BASE, L->base
+ | sw PC, SAVE_PC
+ | call_intern lj_meta_len // (lua_State *L, TValue *o)
+ |. move CARG1, L
+ | // Returns NULL (retry) or TValue * (metamethod base).
+#if LJ_52
+ | bnez CRET1, ->vmeta_binop // Binop call for compatibility.
+ |. nop
+ | b ->BC_LEN_Z
+ |. move CARG1, MULTRES
+#else
+ | b ->vmeta_binop // Binop call for compatibility.
+ |. nop
+#endif
+ |
+ |//-- Call metamethod ----------------------------------------------------
+ |
+ |->vmeta_call: // Resolve and call __call metamethod.
+ | // TMP2 = old base, BASE = new base, RC = nargs*8
+ | load_got lj_meta_call
+ | sw TMP2, L->base // This is the callers base!
+ | addiu CARG2, BASE, -8
+ | sw PC, SAVE_PC
+ | addu CARG3, BASE, RC
+ | move MULTRES, NARGS8:RC
+ | call_intern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
+ |. move CARG1, L
+ | lw LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here.
+ | addiu NARGS8:RC, MULTRES, 8 // Got one more argument now.
+ | ins_call
+ |
+ |->vmeta_callt: // Resolve __call for BC_CALLT.
+ | // BASE = old base, RA = new base, RC = nargs*8
+ | load_got lj_meta_call
+ | sw BASE, L->base
+ | addiu CARG2, RA, -8
+ | sw PC, SAVE_PC
+ | addu CARG3, RA, RC
+ | move MULTRES, NARGS8:RC
+ | call_intern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
+ |. move CARG1, L
+ | lw TMP1, FRAME_PC(BASE)
+ | lw LFUNC:RB, FRAME_FUNC(RA) // Guaranteed to be a function here.
+ | b ->BC_CALLT_Z
+ |. addiu NARGS8:RC, MULTRES, 8 // Got one more argument now.
+ |
+ |//-- Argument coercion for 'for' statement ------------------------------
+ |
+ |->vmeta_for:
+ | load_got lj_meta_for
+ | sw BASE, L->base
+ | move CARG2, RA
+ | sw PC, SAVE_PC
+ | move MULTRES, INS
+ | call_intern lj_meta_for // (lua_State *L, TValue *base)
+ |. move CARG1, L
+ |.if JIT
+ | decode_OP1 TMP0, MULTRES
+ | li AT, BC_JFORI
+ |.endif
+ | decode_RA8a RA, MULTRES
+ | decode_RD8a RD, MULTRES
+ | decode_RA8b RA
+ |.if JIT
+ | beq TMP0, AT, =>BC_JFORI
+ |. decode_RD8b RD
+ | b =>BC_FORI
+ |. nop
+ |.else
+ | b =>BC_FORI
+ |. decode_RD8b RD
+ |.endif
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Fast functions -----------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |.macro .ffunc, name
+ |->ff_ .. name:
+ |.endmacro
+ |
+ |.macro .ffunc_1, name
+ |->ff_ .. name:
+ | beqz NARGS8:RC, ->fff_fallback
+ |. lw CARG3, HI(BASE)
+ | lw CARG1, LO(BASE)
+ |.endmacro
+ |
+ |.macro .ffunc_2, name
+ |->ff_ .. name:
+ | sltiu AT, NARGS8:RC, 16
+ | lw CARG3, HI(BASE)
+ | bnez AT, ->fff_fallback
+ |. lw CARG4, 8+HI(BASE)
+ | lw CARG1, LO(BASE)
+ | lw CARG2, 8+LO(BASE)
+ |.endmacro
+ |
+ |.macro .ffunc_n, name // Caveat: has delay slot!
+ |->ff_ .. name:
+ | lw CARG3, HI(BASE)
+ | beqz NARGS8:RC, ->fff_fallback
+ |. ldc1 FARG1, 0(BASE)
+ | sltiu AT, CARG3, LJ_TISNUM
+ | beqz AT, ->fff_fallback
+ |.endmacro
+ |
+ |.macro .ffunc_nn, name // Caveat: has delay slot!
+ |->ff_ .. name:
+ | sltiu AT, NARGS8:RC, 16
+ | lw CARG3, HI(BASE)
+ | bnez AT, ->fff_fallback
+ |. lw CARG4, 8+HI(BASE)
+ | ldc1 FARG1, 0(BASE)
+ | ldc1 FARG2, 8(BASE)
+ | sltiu TMP0, CARG3, LJ_TISNUM
+ | sltiu TMP1, CARG4, LJ_TISNUM
+ | and TMP0, TMP0, TMP1
+ | beqz TMP0, ->fff_fallback
+ |.endmacro
+ |
+ |// Inlined GC threshold check. Caveat: uses TMP0 and TMP1 and has delay slot!
+ |.macro ffgccheck
+ | lw TMP0, DISPATCH_GL(gc.total)(DISPATCH)
+ | lw TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)
+ | subu AT, TMP0, TMP1
+ | bgezal AT, ->fff_gcstep
+ |.endmacro
+ |
+ |//-- Base library: checks -----------------------------------------------
+ |
+ |.ffunc_1 assert
+ | sltiu AT, CARG3, LJ_TISTRUECOND
+ | beqz AT, ->fff_fallback
+ |. addiu RA, BASE, -8
+ | lw PC, FRAME_PC(BASE)
+ | addiu RD, NARGS8:RC, 8 // Compute (nresults+1)*8.
+ | addu TMP2, RA, NARGS8:RC
+ | sw CARG3, HI(RA)
+ | addiu TMP1, BASE, 8
+ | beq BASE, TMP2, ->fff_res // Done if exactly 1 argument.
+ |. sw CARG1, LO(RA)
+ |1:
+ | ldc1 f0, 0(TMP1)
+ | sdc1 f0, -8(TMP1)
+ | bne TMP1, TMP2, <1
+ |. addiu TMP1, TMP1, 8
+ | b ->fff_res
+ |. nop
+ |
+ |.ffunc type
+ | lw CARG3, HI(BASE)
+ | li TMP1, LJ_TISNUM
+ | beqz NARGS8:RC, ->fff_fallback
+ |. sltiu TMP0, CARG3, LJ_TISNUM
+ | movz TMP1, CARG3, TMP0
+ | not TMP1, TMP1
+ | sll TMP1, TMP1, 3
+ | addu TMP1, CFUNC:RB, TMP1
+ | b ->fff_resn
+ |. ldc1 FRET1, CFUNC:TMP1->upvalue
+ |
+ |//-- Base library: getters and setters ---------------------------------
+ |
+ |.ffunc_1 getmetatable
+ | li AT, LJ_TTAB
+ | bne CARG3, AT, >6
+ |. li AT, LJ_TUDATA
+ |1: // Field metatable must be at same offset for GCtab and GCudata!
+ | lw TAB:CARG1, TAB:CARG1->metatable
+ |2:
+ | lw STR:RC, DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])(DISPATCH)
+ | beqz TAB:CARG1, ->fff_restv
+ |. li CARG3, LJ_TNIL
+ | lw TMP0, TAB:CARG1->hmask
+ | li CARG3, LJ_TTAB // Use metatable as default result.
+ | lw TMP1, STR:RC->hash
+ | lw NODE:TMP2, TAB:CARG1->node
+ | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask
+ | sll TMP0, TMP1, 5
+ | sll TMP1, TMP1, 3
+ | subu TMP1, TMP0, TMP1
+ | addu NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8)
+ | li AT, LJ_TSTR
+ |3: // Rearranged logic, because we expect _not_ to find the key.
+ | lw CARG4, offsetof(Node, key)+HI(NODE:TMP2)
+ | lw TMP0, offsetof(Node, key)+LO(NODE:TMP2)
+ | lw NODE:TMP3, NODE:TMP2->next
+ | bne CARG4, AT, >4
+ |. lw CARG2, offsetof(Node, val)+HI(NODE:TMP2)
+ | beq TMP0, STR:RC, >5
+ |. lw TMP1, offsetof(Node, val)+LO(NODE:TMP2)
+ |4:
+ | beqz NODE:TMP3, ->fff_restv // Not found, keep default result.
+ |. move NODE:TMP2, NODE:TMP3
+ | b <3
+ |. nop
+ |5:
+ | beq CARG2, TISNIL, ->fff_restv // Ditto for nil value.
+ |. nop
+ | move CARG3, CARG2 // Return value of mt.__metatable.
+ | b ->fff_restv
+ |. move CARG1, TMP1
+ |
+ |6:
+ | beq CARG3, AT, <1
+ |. sltiu TMP0, CARG3, LJ_TISNUM
+ | li TMP1, LJ_TISNUM
+ | movz TMP1, CARG3, TMP0
+ | not TMP1, TMP1
+ | sll TMP1, TMP1, 2
+ | addu TMP1, DISPATCH, TMP1
+ | b <2
+ |. lw TAB:CARG1, DISPATCH_GL(gcroot[GCROOT_BASEMT])(TMP1)
+ |
+ |.ffunc_2 setmetatable
+ | // Fast path: no mt for table yet and not clearing the mt.
+ | li AT, LJ_TTAB
+ | bne CARG3, AT, ->fff_fallback
+ |. addiu CARG4, CARG4, -LJ_TTAB
+ | lw TAB:TMP1, TAB:CARG1->metatable
+ | lbu TMP3, TAB:CARG1->marked
+ | or AT, CARG4, TAB:TMP1
+ | bnez AT, ->fff_fallback
+ |. andi AT, TMP3, LJ_GC_BLACK // isblack(table)
+ | beqz AT, ->fff_restv
+ |. sw TAB:CARG2, TAB:CARG1->metatable
+ | barrierback TAB:CARG1, TMP3, TMP0, ->fff_restv
+ |
+ |.ffunc rawget
+ | lw CARG4, HI(BASE)
+ | sltiu AT, NARGS8:RC, 16
+ | lw TAB:CARG2, LO(BASE)
+ | load_got lj_tab_get
+ | addiu CARG4, CARG4, -LJ_TTAB
+ | or AT, AT, CARG4
+ | bnez AT, ->fff_fallback
+ | addiu CARG3, BASE, 8
+ | call_intern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key)
+ |. move CARG1, L
+ | // Returns cTValue *.
+ | b ->fff_resn
+ |. ldc1 FRET1, 0(CRET1)
+ |
+ |//-- Base library: conversions ------------------------------------------
+ |
+ |.ffunc tonumber
+ | // Only handles the number case inline (without a base argument).
+ | lw CARG1, HI(BASE)
+ | xori AT, NARGS8:RC, 8
+ | sltiu CARG1, CARG1, LJ_TISNUM
+ | movn CARG1, r0, AT
+ | beqz CARG1, ->fff_fallback // Exactly one number argument.
+ |. ldc1 FRET1, 0(BASE)
+ | b ->fff_resn
+ |. nop
+ |
+ |.ffunc_1 tostring
+ | // Only handles the string or number case inline.
+ | li AT, LJ_TSTR
+ | // A __tostring method in the string base metatable is ignored.
+ | beq CARG3, AT, ->fff_restv // String key?
+ | // Handle numbers inline, unless a number base metatable is present.
+ |. lw TMP1, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])(DISPATCH)
+ | sltiu TMP0, CARG3, LJ_TISNUM
+ | sltiu TMP1, TMP1, 1
+ | and TMP0, TMP0, TMP1
+ | beqz TMP0, ->fff_fallback
+ |. sw BASE, L->base // Add frame since C call can throw.
+ | ffgccheck
+ |. sw PC, SAVE_PC // Redundant (but a defined value).
+ | load_got lj_str_fromnum
+ | move CARG1, L
+ | call_intern lj_str_fromnum // (lua_State *L, lua_Number *np)
+ |. move CARG2, BASE
+ | // Returns GCstr *.
+ | li CARG3, LJ_TSTR
+ | b ->fff_restv
+ |. move CARG1, CRET1
+ |
+ |//-- Base library: iterators -------------------------------------------
+ |
+ |.ffunc next
+ | lw CARG1, HI(BASE)
+ | lw TAB:CARG2, LO(BASE)
+ | beqz NARGS8:RC, ->fff_fallback
+ |. addu TMP2, BASE, NARGS8:RC
+ | li AT, LJ_TTAB
+ | sw TISNIL, HI(TMP2) // Set missing 2nd arg to nil.
+ | bne CARG1, AT, ->fff_fallback
+ |. lw PC, FRAME_PC(BASE)
+ | load_got lj_tab_next
+ | sw BASE, L->base // Add frame since C call can throw.
+ | sw BASE, L->top // Dummy frame length is ok.
+ | addiu CARG3, BASE, 8
+ | sw PC, SAVE_PC
+ | call_intern lj_tab_next // (lua_State *L, GCtab *t, TValue *key)
+ |. move CARG1, L
+ | // Returns 0 at end of traversal.
+ | beqz CRET1, ->fff_restv // End of traversal: return nil.
+ |. li CARG3, LJ_TNIL
+ | ldc1 f0, 8(BASE) // Copy key and value to results.
+ | addiu RA, BASE, -8
+ | ldc1 f2, 16(BASE)
+ | li RD, (2+1)*8
+ | sdc1 f0, 0(RA)
+ | b ->fff_res
+ |. sdc1 f2, 8(RA)
+ |
+ |.ffunc_1 pairs
+ | li AT, LJ_TTAB
+ | bne CARG3, AT, ->fff_fallback
+ |. lw PC, FRAME_PC(BASE)
+#if LJ_52
+ | lw TAB:TMP2, TAB:CARG1->metatable
+ | ldc1 f0, CFUNC:RB->upvalue[0]
+ | bnez TAB:TMP2, ->fff_fallback
+#else
+ | ldc1 f0, CFUNC:RB->upvalue[0]
+#endif
+ |. addiu RA, BASE, -8
+ | sw TISNIL, 8+HI(BASE)
+ | li RD, (3+1)*8
+ | b ->fff_res
+ |. sdc1 f0, 0(RA)
+ |
+ |.ffunc ipairs_aux
+ | sltiu AT, NARGS8:RC, 16
+ | lw CARG3, HI(BASE)
+ | lw TAB:CARG1, LO(BASE)
+ | lw CARG4, 8+HI(BASE)
+ | bnez AT, ->fff_fallback
+ |. ldc1 FARG2, 8(BASE)
+ | addiu CARG3, CARG3, -LJ_TTAB
+ | sltiu AT, CARG4, LJ_TISNUM
+ | li TMP0, 1
+ | movn AT, r0, CARG3
+ | mtc1 TMP0, FARG1
+ | beqz AT, ->fff_fallback
+ |. lw PC, FRAME_PC(BASE)
+ | cvt.w.d FRET1, FARG2
+ | cvt.d.w FARG1, FARG1
+ | lw TMP0, TAB:CARG1->asize
+ | lw TMP1, TAB:CARG1->array
+ | mfc1 TMP2, FRET1
+ | addiu RA, BASE, -8
+ | add.d FARG2, FARG2, FARG1
+ | addiu TMP2, TMP2, 1
+ | sltu AT, TMP2, TMP0
+ | sll TMP3, TMP2, 3
+ | addu TMP3, TMP1, TMP3
+ | beqz AT, >2 // Not in array part?
+ |. sdc1 FARG2, 0(RA)
+ | lw TMP2, HI(TMP3)
+ | ldc1 f0, 0(TMP3)
+ |1:
+ | beq TMP2, TISNIL, ->fff_res // End of iteration, return 0 results.
+ |. li RD, (0+1)*8
+ | li RD, (2+1)*8
+ | b ->fff_res
+ |. sdc1 f0, 8(RA)
+ |2: // Check for empty hash part first. Otherwise call C function.
+ | lw TMP0, TAB:CARG1->hmask
+ | load_got lj_tab_getinth
+ | beqz TMP0, ->fff_res
+ |. li RD, (0+1)*8
+ | call_intern lj_tab_getinth // (GCtab *t, int32_t key)
+ |. move CARG2, TMP2
+ | // Returns cTValue * or NULL.
+ | beqz CRET1, ->fff_res
+ |. li RD, (0+1)*8
+ | lw TMP2, HI(CRET1)
+ | b <1
+ |. ldc1 f0, 0(CRET1)
+ |
+ |.ffunc_1 ipairs
+ | li AT, LJ_TTAB
+ | bne CARG3, AT, ->fff_fallback
+ |. lw PC, FRAME_PC(BASE)
+#if LJ_52
+ | lw TAB:TMP2, TAB:CARG1->metatable
+ | ldc1 f0, CFUNC:RB->upvalue[0]
+ | bnez TAB:TMP2, ->fff_fallback
+#else
+ | ldc1 f0, CFUNC:RB->upvalue[0]
+#endif
+ |. addiu RA, BASE, -8
+ | sw r0, 8+HI(BASE)
+ | sw r0, 8+LO(BASE)
+ | li RD, (3+1)*8
+ | b ->fff_res
+ |. sdc1 f0, 0(RA)
+ |
+ |//-- Base library: catch errors ----------------------------------------
+ |
+ |.ffunc pcall
+ | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)
+ | beqz NARGS8:RC, ->fff_fallback
+ | move TMP2, BASE
+ | addiu BASE, BASE, 8
+ | // Remember active hook before pcall.
+ | srl TMP3, TMP3, HOOK_ACTIVE_SHIFT
+ | andi TMP3, TMP3, 1
+ | addiu PC, TMP3, 8+FRAME_PCALL
+ | b ->vm_call_dispatch
+ |. addiu NARGS8:RC, NARGS8:RC, -8
+ |
+ |.ffunc xpcall
+ | sltiu AT, NARGS8:RC, 16
+ | lw CARG4, 8+HI(BASE)
+ | bnez AT, ->fff_fallback
+ |. ldc1 FARG2, 8(BASE)
+ | ldc1 FARG1, 0(BASE)
+ | lbu TMP1, DISPATCH_GL(hookmask)(DISPATCH)
+ | li AT, LJ_TFUNC
+ | move TMP2, BASE
+ | bne CARG4, AT, ->fff_fallback // Traceback must be a function.
+ | addiu BASE, BASE, 16
+ | // Remember active hook before pcall.
+ | srl TMP3, TMP3, HOOK_ACTIVE_SHIFT
+ | sdc1 FARG2, 0(TMP2) // Swap function and traceback.
+ | andi TMP3, TMP3, 1
+ | sdc1 FARG1, 8(TMP2)
+ | addiu PC, TMP3, 16+FRAME_PCALL
+ | b ->vm_call_dispatch
+ |. addiu NARGS8:RC, NARGS8:RC, -16
+ |
+ |//-- Coroutine library --------------------------------------------------
+ |
+ |.macro coroutine_resume_wrap, resume
+ |.if resume
+ |.ffunc_1 coroutine_resume
+ | li AT, LJ_TTHREAD
+ | bne CARG3, AT, ->fff_fallback
+ |.else
+ |.ffunc coroutine_wrap_aux
+ | lw L:CARG1, CFUNC:RB->upvalue[0].gcr
+ |.endif
+ | lbu TMP0, L:CARG1->status
+ | lw TMP1, L:CARG1->cframe
+ | lw CARG2, L:CARG1->top
+ | lw TMP2, L:CARG1->base
+ | addiu TMP3, TMP0, -LUA_YIELD
+ | bgtz TMP3, ->fff_fallback // st > LUA_YIELD?
+ |. xor TMP2, TMP2, CARG2
+ | bnez TMP1, ->fff_fallback // cframe != 0?
+ |. or AT, TMP2, TMP0
+ | lw TMP0, L:CARG1->maxstack
+ | beqz AT, ->fff_fallback // base == top && st == 0?
+ |. lw PC, FRAME_PC(BASE)
+ | addu TMP2, CARG2, NARGS8:RC
+ | sltu AT, TMP0, TMP2
+ | bnez AT, ->fff_fallback // Stack overflow?
+ |. sw PC, SAVE_PC
+ | sw BASE, L->base
+ |1:
+ |.if resume
+ | addiu BASE, BASE, 8 // Keep resumed thread in stack for GC.
+ | addiu NARGS8:RC, NARGS8:RC, -8
+ | addiu TMP2, TMP2, -8
+ |.endif
+ | sw TMP2, L:CARG1->top
+ | addu TMP1, BASE, NARGS8:RC
+ | move CARG3, CARG2
+ | sw BASE, L->top
+ |2: // Move args to coroutine.
+ | ldc1 f0, 0(BASE)
+ | sltu AT, BASE, TMP1
+ | beqz AT, >3
+ |. addiu BASE, BASE, 8
+ | sdc1 f0, 0(CARG3)
+ | b <2
+ |. addiu CARG3, CARG3, 8
+ |3:
+ | bal ->vm_resume // (lua_State *L, TValue *base, 0, 0)
+ |. move L:RA, L:CARG1
+ | // Returns thread status.
+ |4:
+ | lw TMP2, L:RA->base
+ | sltiu AT, CRET1, LUA_YIELD+1
+ | lw TMP3, L:RA->top
+ | li_vmstate INTERP
+ | lw BASE, L->base
+ | st_vmstate
+ | beqz AT, >8
+ |. subu RD, TMP3, TMP2
+ | lw TMP0, L->maxstack
+ | beqz RD, >6 // No results?
+ |. addu TMP1, BASE, RD
+ | sltu AT, TMP0, TMP1
+ | bnez AT, >9 // Need to grow stack?
+ |. addu TMP3, TMP2, RD
+ | sw TMP2, L:RA->top // Clear coroutine stack.
+ | move TMP1, BASE
+ |5: // Move results from coroutine.
+ | ldc1 f0, 0(TMP2)
+ | addiu TMP2, TMP2, 8
+ | sltu AT, TMP2, TMP3
+ | sdc1 f0, 0(TMP1)
+ | bnez AT, <5
+ |. addiu TMP1, TMP1, 8
+ |6:
+ | andi TMP0, PC, FRAME_TYPE
+ |.if resume
+ | li TMP1, LJ_TTRUE
+ | addiu RA, BASE, -8
+ | sw TMP1, -8+HI(BASE) // Prepend true to results.
+ | addiu RD, RD, 16
+ |.else
+ | move RA, BASE
+ | addiu RD, RD, 8
+ |.endif
+ |7:
+ | sw PC, SAVE_PC
+ | beqz TMP0, ->BC_RET_Z
+ |. move MULTRES, RD
+ | b ->vm_return
+ |. nop
+ |
+ |8: // Coroutine returned with error (at co->top-1).
+ |.if resume
+ | addiu TMP3, TMP3, -8
+ | li TMP1, LJ_TFALSE
+ | ldc1 f0, 0(TMP3)
+ | sw TMP3, L:RA->top // Remove error from coroutine stack.
+ | li RD, (2+1)*8
+ | sw TMP1, -8+HI(BASE) // Prepend false to results.
+ | addiu RA, BASE, -8
+ | sdc1 f0, 0(BASE) // Copy error message.
+ | b <7
+ |. andi TMP0, PC, FRAME_TYPE
+ |.else
+ | load_got lj_ffh_coroutine_wrap_err
+ | move CARG2, L:RA
+ | call_intern lj_ffh_coroutine_wrap_err // (lua_State *L, lua_State *co)
+ |. move CARG1, L
+ |.endif
+ |
+ |9: // Handle stack expansion on return from yield.
+ | load_got lj_state_growstack
+ | srl CARG2, RD, 3
+ | call_intern lj_state_growstack // (lua_State *L, int n)
+ |. move CARG1, L
+ | b <4
+ |. li CRET1, 0
+ |.endmacro
+ |
+ | coroutine_resume_wrap 1 // coroutine.resume
+ | coroutine_resume_wrap 0 // coroutine.wrap
+ |
+ |.ffunc coroutine_yield
+ | lw TMP0, L->cframe
+ | addu TMP1, BASE, NARGS8:RC
+ | sw BASE, L->base
+ | andi TMP0, TMP0, CFRAME_RESUME
+ | sw TMP1, L->top
+ | beqz TMP0, ->fff_fallback
+ |. li CRET1, LUA_YIELD
+ | sw r0, L->cframe
+ | b ->vm_leave_unw
+ |. sb CRET1, L->status
+ |
+ |//-- Math library -------------------------------------------------------
+ |
+ |.ffunc_n math_abs
+ |. abs.d FRET1, FARG1
+ |->fff_resn:
+ | lw PC, FRAME_PC(BASE)
+ | addiu RA, BASE, -8
+ | b ->fff_res1
+ |. sdc1 FRET1, -8(BASE)
+ |
+ |->fff_restv:
+ | // CARG3/CARG1 = TValue result.
+ | lw PC, FRAME_PC(BASE)
+ | sw CARG3, -8+HI(BASE)
+ | addiu RA, BASE, -8
+ | sw CARG1, -8+LO(BASE)
+ |->fff_res1:
+ | // RA = results, PC = return.
+ | li RD, (1+1)*8
+ |->fff_res:
+ | // RA = results, RD = (nresults+1)*8, PC = return.
+ | andi TMP0, PC, FRAME_TYPE
+ | bnez TMP0, ->vm_return
+ |. move MULTRES, RD
+ | lw INS, -4(PC)
+ | decode_RB8a RB, INS
+ | decode_RB8b RB
+ |5:
+ | sltu AT, RD, RB
+ | bnez AT, >6 // More results expected?
+ |. decode_RA8a TMP0, INS
+ | decode_RA8b TMP0
+ | ins_next1
+ | // Adjust BASE. KBASE is assumed to be set for the calling frame.
+ | subu BASE, RA, TMP0
+ | ins_next2
+ |
+ |6: // Fill up results with nil.
+ | addu TMP1, RA, RD
+ | addiu RD, RD, 8
+ | b <5
+ |. sw TISNIL, -8+HI(TMP1)
+ |
+ |.macro math_extern, func
+ |->ff_math_ .. func:
+ | lw CARG3, HI(BASE)
+ | beqz NARGS8:RC, ->fff_fallback
+ |. load_got func
+ | sltiu AT, CARG3, LJ_TISNUM
+ | beqz AT, ->fff_fallback
+ |. nop
+ | call_extern
+ |. ldc1 FARG1, 0(BASE)
+ | b ->fff_resn
+ |. nop
+ |.endmacro
+ |
+ |.macro math_extern2, func
+ | .ffunc_nn math_ .. func
+ |. load_got func
+ | call_extern
+ |. nop
+ | b ->fff_resn
+ |. nop
+ |.endmacro
+ |
+ |.macro math_round, func
+ | .ffunc_n math_ .. func
+ |. nop
+ | bal ->vm_ .. func
+ |. nop
+ | b ->fff_resn
+ |. nop
+ |.endmacro
+ |
+ | math_round floor
+ | math_round ceil
+ |
+ |.ffunc math_log
+ | lw CARG3, HI(BASE)
+ | li AT, 8
+ | bne NARGS8:RC, AT, ->fff_fallback // Exactly 1 argument.
+ |. load_got log
+ | sltiu AT, CARG3, LJ_TISNUM
+ | beqz AT, ->fff_fallback
+ |. nop
+ | call_extern
+ |. ldc1 FARG1, 0(BASE)
+ | b ->fff_resn
+ |. nop
+ |
+ | math_extern log10
+ | math_extern exp
+ | math_extern sin
+ | math_extern cos
+ | math_extern tan
+ | math_extern asin
+ | math_extern acos
+ | math_extern atan
+ | math_extern sinh
+ | math_extern cosh
+ | math_extern tanh
+ | math_extern2 pow
+ | math_extern2 atan2
+ | math_extern2 fmod
+ |
+ |.ffunc_n math_sqrt
+ |. sqrt.d FRET1, FARG1
+ | b ->fff_resn
+ |. nop
+ |
+ |->ff_math_deg:
+ |.ffunc_n math_rad
+ |. ldc1 FARG2, CFUNC:RB->upvalue[0]
+ | b ->fff_resn
+ |. mul.d FRET1, FARG1, FARG2
+ |
+ |.ffunc_nn math_ldexp
+ | cvt.w.d FARG2, FARG2
+ | load_got ldexp
+ | mfc1 CARG3, FARG2
+ | call_extern
+ |. nop
+ | b ->fff_resn
+ |. nop
+ |
+ |.ffunc_n math_frexp
+ | load_got frexp
+ | lw PC, FRAME_PC(BASE)
+ | call_extern
+ |. addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)
+ | lw TMP1, DISPATCH_GL(tmptv)(DISPATCH)
+ | addiu RA, BASE, -8
+ | mtc1 TMP1, FARG2
+ | sdc1 FRET1, 0(RA)
+ | cvt.d.w FARG2, FARG2
+ | sdc1 FARG2, 8(RA)
+ | b ->fff_res
+ |. li RD, (2+1)*8
+ |
+ |.ffunc_n math_modf
+ | load_got modf
+ | lw PC, FRAME_PC(BASE)
+ | call_extern
+ |. addiu CARG3, BASE, -8
+ | addiu RA, BASE, -8
+ | sdc1 FRET1, 0(BASE)
+ | b ->fff_res
+ |. li RD, (2+1)*8
+ |
+ |.macro math_minmax, name, ismax
+ |->ff_ .. name:
+ | lw CARG3, HI(BASE)
+ | beqz NARGS8:RC, ->fff_fallback
+ |. ldc1 FRET1, 0(BASE)
+ | sltiu AT, CARG3, LJ_TISNUM
+ | beqz AT, ->fff_fallback
+ |. addu TMP2, BASE, NARGS8:RC
+ | addiu TMP1, BASE, 8
+ | beq TMP1, TMP2, ->fff_resn
+ |1:
+ |. lw CARG3, HI(TMP1)
+ | ldc1 FARG1, 0(TMP1)
+ | addiu TMP1, TMP1, 8
+ | sltiu AT, CARG3, LJ_TISNUM
+ | beqz AT, ->fff_fallback
+ |.if ismax
+ |. c.olt.d FARG1, FRET1
+ |.else
+ |. c.olt.d FRET1, FARG1
+ |.endif
+ | bne TMP1, TMP2, <1
+ |. movf.d FRET1, FARG1
+ | b ->fff_resn
+ |. nop
+ |.endmacro
+ |
+ | math_minmax math_min, 0
+ | math_minmax math_max, 1
+ |
+ |//-- String library -----------------------------------------------------
+ |
+ |.ffunc_1 string_len
+ | li AT, LJ_TSTR
+ | bne CARG3, AT, ->fff_fallback
+ |. nop
+ | b ->fff_resi
+ |. lw CRET1, STR:CARG1->len
+ |
+ |.ffunc string_byte // Only handle the 1-arg case here.
+ | lw CARG3, HI(BASE)
+ | lw STR:CARG1, LO(BASE)
+ | xori AT, NARGS8:RC, 8
+ | addiu CARG3, CARG3, -LJ_TSTR
+ | or AT, AT, CARG3
+ | bnez AT, ->fff_fallback // Need exactly 1 string argument.
+ |. nop
+ | lw TMP0, STR:CARG1->len
+ | lbu TMP1, STR:CARG1[1] // Access is always ok (NUL at end).
+ | addiu RA, BASE, -8
+ | sltu RD, r0, TMP0
+ | mtc1 TMP1, f0
+ | addiu RD, RD, 1
+ | cvt.d.w f0, f0
+ | lw PC, FRAME_PC(BASE)
+ | sll RD, RD, 3 // RD = ((str->len != 0)+1)*8
+ | b ->fff_res
+ |. sdc1 f0, 0(RA)
+ |
+ |.ffunc string_char // Only handle the 1-arg case here.
+ | ffgccheck
+ |. nop
+ | lw CARG3, HI(BASE)
+ | ldc1 FARG1, 0(BASE)
+ | li AT, 8
+ | bne NARGS8:RC, AT, ->fff_fallback // Exactly 1 argument.
+ |. sltiu AT, CARG3, LJ_TISNUM
+ | beqz AT, ->fff_fallback
+ |. li CARG3, 1
+ | cvt.w.d FARG1, FARG1
+ | addiu CARG2, sp, ARG5_OFS
+ | sltiu AT, TMP0, 256
+ | mfc1 TMP0, FARG1
+ | beqz AT, ->fff_fallback
+ |. sw TMP0, ARG5
+ |->fff_newstr:
+ | load_got lj_str_new
+ | sw BASE, L->base
+ | sw PC, SAVE_PC
+ | call_intern lj_str_new // (lua_State *L, char *str, size_t l)
+ |. move CARG1, L
+ | // Returns GCstr *.
+ | lw BASE, L->base
+ | move CARG1, CRET1
+ | b ->fff_restv
+ |. li CARG3, LJ_TSTR
+ |
+ |.ffunc string_sub
+ | ffgccheck
+ |. nop
+ | addiu AT, NARGS8:RC, -16
+ | lw CARG3, 16+HI(BASE)
+ | ldc1 f0, 16(BASE)
+ | lw TMP0, HI(BASE)
+ | lw STR:CARG1, LO(BASE)
+ | bltz AT, ->fff_fallback
+ | lw CARG2, 8+HI(BASE)
+ | ldc1 f2, 8(BASE)
+ | beqz AT, >1
+ |. li CARG4, -1
+ | cvt.w.d f0, f0
+ | sltiu AT, CARG3, LJ_TISNUM
+ | beqz AT, ->fff_fallback
+ |. mfc1 CARG4, f0
+ |1:
+ | sltiu AT, CARG2, LJ_TISNUM
+ | beqz AT, ->fff_fallback
+ |. li AT, LJ_TSTR
+ | cvt.w.d f2, f2
+ | bne TMP0, AT, ->fff_fallback
+ |. lw CARG2, STR:CARG1->len
+ | mfc1 CARG3, f2
+ | // STR:CARG1 = str, CARG2 = str->len, CARG3 = start, CARG4 = end
+ | slt AT, CARG4, r0
+ | addiu TMP0, CARG2, 1
+ | addu TMP1, CARG4, TMP0
+ | slt TMP3, CARG3, r0
+ | movn CARG4, TMP1, AT // if (end < 0) end += len+1
+ | addu TMP1, CARG3, TMP0
+ | movn CARG3, TMP1, TMP3 // if (start < 0) start += len+1
+ | li TMP2, 1
+ | slt AT, CARG4, r0
+ | slt TMP3, r0, CARG3
+ | movn CARG4, r0, AT // if (end < 0) end = 0
+ | movz CARG3, TMP2, TMP3 // if (start < 1) start = 1
+ | slt AT, CARG2, CARG4
+ | movn CARG4, CARG2, AT // if (end > len) end = len
+ | addu CARG2, STR:CARG1, CARG3
+ | subu CARG3, CARG4, CARG3 // len = end - start
+ | addiu CARG2, CARG2, sizeof(GCstr)-1
+ | bgez CARG3, ->fff_newstr
+ |. addiu CARG3, CARG3, 1 // len++
+ |->fff_emptystr: // Return empty string.
+ | addiu STR:CARG1, DISPATCH, DISPATCH_GL(strempty)
+ | b ->fff_restv
+ |. li CARG3, LJ_TSTR
+ |
+ |.ffunc string_rep // Only handle the 1-char case inline.
+ | ffgccheck
+ |. nop
+ | lw TMP0, HI(BASE)
+ | addiu AT, NARGS8:RC, -16 // Exactly 2 arguments.
+ | lw CARG4, 8+HI(BASE)
+ | lw STR:CARG1, LO(BASE)
+ | addiu TMP0, TMP0, -LJ_TSTR
+ | ldc1 f0, 8(BASE)
+ | or AT, AT, TMP0
+ | bnez AT, ->fff_fallback
+ |. sltiu AT, CARG4, LJ_TISNUM
+ | cvt.w.d f0, f0
+ | beqz AT, ->fff_fallback
+ |. lw TMP0, STR:CARG1->len
+ | mfc1 CARG3, f0
+ | lw TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH)
+ | li AT, 1
+ | blez CARG3, ->fff_emptystr // Count <= 0?
+ |. sltu AT, AT, TMP0
+ | beqz TMP0, ->fff_emptystr // Zero length string?
+ |. sltu TMP0, TMP1, CARG3
+ | or AT, AT, TMP0
+ | lw CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH)
+ | bnez AT, ->fff_fallback // Fallback for > 1-char strings.
+ |. lbu TMP0, STR:CARG1[1]
+ | addu TMP2, CARG2, CARG3
+ |1: // Fill buffer with char. Yes, this is suboptimal code (do you care?).
+ | addiu TMP2, TMP2, -1
+ | sltu AT, CARG2, TMP2
+ | bnez AT, <1
+ |. sb TMP0, 0(TMP2)
+ | b ->fff_newstr
+ |. nop
+ |
+ |.ffunc string_reverse
+ | ffgccheck
+ |. nop
+ | lw CARG3, HI(BASE)
+ | lw STR:CARG1, LO(BASE)
+ | beqz NARGS8:RC, ->fff_fallback
+ |. li AT, LJ_TSTR
+ | bne CARG3, AT, ->fff_fallback
+ |. lw TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH)
+ | lw CARG3, STR:CARG1->len
+ | addiu CARG1, STR:CARG1, #STR
+ | lw CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH)
+ | sltu AT, TMP1, CARG3
+ | bnez AT, ->fff_fallback
+ |. addu TMP3, CARG1, CARG3
+ | addu CARG4, CARG2, CARG3
+ |1: // Reverse string copy.
+ | lbu TMP1, 0(CARG1)
+ | sltu AT, CARG1, TMP3
+ | beqz AT, ->fff_newstr
+ |. addiu CARG1, CARG1, 1
+ | addiu CARG4, CARG4, -1
+ | b <1
+ | sb TMP1, 0(CARG4)
+ |
+ |.macro ffstring_case, name, lo
+ | .ffunc name
+ | ffgccheck
+ |. nop
+ | lw CARG3, HI(BASE)
+ | lw STR:CARG1, LO(BASE)
+ | beqz NARGS8:RC, ->fff_fallback
+ |. li AT, LJ_TSTR
+ | bne CARG3, AT, ->fff_fallback
+ |. lw TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH)
+ | lw CARG3, STR:CARG1->len
+ | addiu CARG1, STR:CARG1, #STR
+ | lw CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH)
+ | sltu AT, TMP1, CARG3
+ | bnez AT, ->fff_fallback
+ |. addu TMP3, CARG1, CARG3
+ | move CARG4, CARG2
+ |1: // ASCII case conversion.
+ | lbu TMP1, 0(CARG1)
+ | sltu AT, CARG1, TMP3
+ | beqz AT, ->fff_newstr
+ |. addiu TMP0, TMP1, -lo
+ | xori TMP2, TMP1, 0x20
+ | sltiu AT, TMP0, 26
+ | movn TMP1, TMP2, AT
+ | addiu CARG1, CARG1, 1
+ | sb TMP1, 0(CARG4)
+ | b <1
+ |. addiu CARG4, CARG4, 1
+ |.endmacro
+ |
+ |ffstring_case string_lower, 65
+ |ffstring_case string_upper, 97
+ |
+ |//-- Table library ------------------------------------------------------
+ |
+ |.ffunc_1 table_getn
+ | li AT, LJ_TTAB
+ | bne CARG3, AT, ->fff_fallback
+ |. load_got lj_tab_len
+ | call_intern lj_tab_len // (GCtab *t)
+ |. nop
+ | // Returns uint32_t (but less than 2^31).
+ | b ->fff_resi
+ |. nop
+ |
+ |//-- Bit library --------------------------------------------------------
+ |
+ |.macro .ffunc_bit, name
+ | .ffunc_n bit_..name
+ |. add.d FARG1, FARG1, TOBIT
+ | mfc1 CRET1, FARG1
+ |.endmacro
+ |
+ |.macro .ffunc_bit_op, name, ins
+ | .ffunc_bit name
+ | addiu TMP1, BASE, 8
+ | addu TMP2, BASE, NARGS8:RC
+ |1:
+ | lw CARG4, HI(TMP1)
+ | beq TMP1, TMP2, ->fff_resi
+ |. ldc1 FARG1, 0(TMP1)
+ | sltiu AT, CARG4, LJ_TISNUM
+ | beqz AT, ->fff_fallback
+ | add.d FARG1, FARG1, TOBIT
+ | mfc1 CARG2, FARG1
+ | ins CRET1, CRET1, CARG2
+ | b <1
+ |. addiu TMP1, TMP1, 8
+ |.endmacro
+ |
+ |.ffunc_bit_op band, and
+ |.ffunc_bit_op bor, or
+ |.ffunc_bit_op bxor, xor
+ |
+ |.ffunc_bit bswap
+ | srl TMP0, CRET1, 24
+ | srl TMP2, CRET1, 8
+ | sll TMP1, CRET1, 24
+ | andi TMP2, TMP2, 0xff00
+ | or TMP0, TMP0, TMP1
+ | andi CRET1, CRET1, 0xff00
+ | or TMP0, TMP0, TMP2
+ | sll CRET1, CRET1, 8
+ | b ->fff_resi
+ |. or CRET1, TMP0, CRET1
+ |
+ |.ffunc_bit bnot
+ | b ->fff_resi
+ |. not CRET1, CRET1
+ |
+ |.macro .ffunc_bit_sh, name, ins, shmod
+ | .ffunc_nn bit_..name
+ |. add.d FARG1, FARG1, TOBIT
+ | add.d FARG2, FARG2, TOBIT
+ | mfc1 CARG1, FARG1
+ | mfc1 CARG2, FARG2
+ |.if shmod == 1
+ | li AT, 32
+ | subu TMP0, AT, CARG2
+ | sllv CARG2, CARG1, CARG2
+ | srlv CARG1, CARG1, TMP0
+ |.elif shmod == 2
+ | li AT, 32
+ | subu TMP0, AT, CARG2
+ | srlv CARG2, CARG1, CARG2
+ | sllv CARG1, CARG1, TMP0
+ |.endif
+ | b ->fff_resi
+ |. ins CRET1, CARG1, CARG2
+ |.endmacro
+ |
+ |.ffunc_bit_sh lshift, sllv, 0
+ |.ffunc_bit_sh rshift, srlv, 0
+ |.ffunc_bit_sh arshift, srav, 0
+ |// Can't use rotrv, since it's only in MIPS32R2.
+ |.ffunc_bit_sh rol, or, 1
+ |.ffunc_bit_sh ror, or, 2
+ |
+ |.ffunc_bit tobit
+ |->fff_resi:
+ | mtc1 CRET1, FRET1
+ | b ->fff_resn
+ |. cvt.d.w FRET1, FRET1
+ |
+ |//-----------------------------------------------------------------------
+ |
+ |->fff_fallback: // Call fast function fallback handler.
+ | // BASE = new base, RB = CFUNC, RC = nargs*8
+ | lw TMP3, CFUNC:RB->f
+ | addu TMP1, BASE, NARGS8:RC
+ | lw PC, FRAME_PC(BASE) // Fallback may overwrite PC.
+ | addiu TMP0, TMP1, 8*LUA_MINSTACK
+ | lw TMP2, L->maxstack
+ | sw PC, SAVE_PC // Redundant (but a defined value).
+ | sltu AT, TMP2, TMP0
+ | sw BASE, L->base
+ | sw TMP1, L->top
+ | bnez AT, >5 // Need to grow stack.
+ |. move CFUNCADDR, TMP3
+ | jalr TMP3 // (lua_State *L)
+ |. move CARG1, L
+ | // Either throws an error, or recovers and returns -1, 0 or nresults+1.
+ | lw BASE, L->base
+ | sll RD, CRET1, 3
+ | bgtz CRET1, ->fff_res // Returned nresults+1?
+ |. addiu RA, BASE, -8
+ |1: // Returned 0 or -1: retry fast path.
+ | lw TMP0, L->top
+ | lw LFUNC:RB, FRAME_FUNC(BASE)
+ | bnez CRET1, ->vm_call_tail // Returned -1?
+ |. subu NARGS8:RC, TMP0, BASE
+ | ins_callt // Returned 0: retry fast path.
+ |
+ |// Reconstruct previous base for vmeta_call during tailcall.
+ |->vm_call_tail:
+ | andi TMP0, PC, FRAME_TYPE
+ | li AT, -4
+ | bnez TMP0, >3
+ |. and TMP1, PC, AT
+ | lbu TMP1, OFS_RA(PC)
+ | sll TMP1, TMP1, 3
+ | addiu TMP1, TMP1, 8
+ |3:
+ | b ->vm_call_dispatch // Resolve again for tailcall.
+ |. subu TMP2, BASE, TMP1
+ |
+ |5: // Grow stack for fallback handler.
+ | load_got lj_state_growstack
+ | li CARG2, LUA_MINSTACK
+ | call_intern lj_state_growstack // (lua_State *L, int n)
+ |. move CARG1, L
+ | lw BASE, L->base
+ | b <1
+ |. li CRET1, 0 // Force retry.
+ |
+ |->fff_gcstep: // Call GC step function.
+ | // BASE = new base, RC = nargs*8
+ | move MULTRES, ra
+ | load_got lj_gc_step
+ | sw BASE, L->base
+ | addu TMP0, BASE, NARGS8:RC
+ | sw PC, SAVE_PC // Redundant (but a defined value).
+ | sw TMP0, L->top
+ | call_intern lj_gc_step // (lua_State *L)
+ |. move CARG1, L
+ | lw BASE, L->base
+ | move ra, MULTRES
+ | lw TMP0, L->top
+ | lw CFUNC:RB, FRAME_FUNC(BASE)
+ | jr ra
+ |. subu NARGS8:RC, TMP0, BASE
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Special dispatch targets -------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_record: // Dispatch target for recording phase.
+ |.if JIT
+ | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)
+ | andi AT, TMP3, HOOK_VMEVENT // No recording while in vmevent.
+ | bnez AT, >5
+ | // Decrement the hookcount for consistency, but always do the call.
+ |. lw TMP2, DISPATCH_GL(hookcount)(DISPATCH)
+ | andi AT, TMP3, HOOK_ACTIVE
+ | bnez AT, >1
+ |. addiu TMP2, TMP2, -1
+ | andi AT, TMP3, LUA_MASKLINE|LUA_MASKCOUNT
+ | beqz AT, >1
+ |. nop
+ | b >1
+ |. sw TMP2, DISPATCH_GL(hookcount)(DISPATCH)
+ |.endif
+ |
+ |->vm_rethook: // Dispatch target for return hooks.
+ | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)
+ | andi AT, TMP3, HOOK_ACTIVE // Hook already active?
+ | beqz AT, >1
+ |5: // Re-dispatch to static ins.
+ |. lw AT, GG_DISP2STATIC(TMP0) // Assumes TMP0 holds DISPATCH+OP*4.
+ | jr AT
+ |. nop
+ |
+ |->vm_inshook: // Dispatch target for instr/line hooks.
+ | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH)
+ | lw TMP2, DISPATCH_GL(hookcount)(DISPATCH)
+ | andi AT, TMP3, HOOK_ACTIVE // Hook already active?
+ | bnez AT, <5
+ |. andi AT, TMP3, LUA_MASKLINE|LUA_MASKCOUNT
+ | beqz AT, <5
+ |. addiu TMP2, TMP2, -1
+ | beqz TMP2, >1
+ |. sw TMP2, DISPATCH_GL(hookcount)(DISPATCH)
+ | andi AT, TMP3, LUA_MASKLINE
+ | beqz AT, <5
+ |1:
+ |. load_got lj_dispatch_ins
+ | sw MULTRES, SAVE_MULTRES
+ | move CARG2, PC
+ | sw BASE, L->base
+ | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.
+ | call_intern lj_dispatch_ins // (lua_State *L, const BCIns *pc)
+ |. move CARG1, L
+ |3:
+ | lw BASE, L->base
+ |4: // Re-dispatch to static ins.
+ | lw INS, -4(PC)
+ | decode_OP4a TMP1, INS
+ | decode_OP4b TMP1
+ | addu TMP0, DISPATCH, TMP1
+ | decode_RD8a RD, INS
+ | lw AT, GG_DISP2STATIC(TMP0)
+ | decode_RA8a RA, INS
+ | decode_RD8b RD
+ | jr AT
+ | decode_RA8b RA
+ |
+ |->cont_hook: // Continue from hook yield.
+ | addiu PC, PC, 4
+ | b <4
+ |. lw MULTRES, -24+LO(RB) // Restore MULTRES for *M ins.
+ |
+ |->vm_hotloop: // Hot loop counter underflow.
+ |.if JIT
+ | lw LFUNC:TMP1, FRAME_FUNC(BASE)
+ | addiu CARG1, DISPATCH, GG_DISP2J
+ | sw PC, SAVE_PC
+ | lw TMP1, LFUNC:TMP1->pc
+ | move CARG2, PC
+ | sw L, DISPATCH_J(L)(DISPATCH)
+ | lbu TMP1, PC2PROTO(framesize)(TMP1)
+ | load_got lj_trace_hot
+ | sw BASE, L->base
+ | sll TMP1, TMP1, 3
+ | addu TMP1, BASE, TMP1
+ | call_intern lj_trace_hot // (jit_State *J, const BCIns *pc)
+ |. sw TMP1, L->top
+ | b <3
+ |. nop
+ |.endif
+ |
+ |->vm_callhook: // Dispatch target for call hooks.
+ |.if JIT
+ | b >1
+ |.endif
+ |. move CARG2, PC
+ |
+ |->vm_hotcall: // Hot call counter underflow.
+ |.if JIT
+ | ori CARG2, PC, 1
+ |1:
+ |.endif
+ | load_got lj_dispatch_call
+ | addu TMP0, BASE, RC
+ | sw PC, SAVE_PC
+ | sw BASE, L->base
+ | subu RA, RA, BASE
+ | sw TMP0, L->top
+ | call_intern lj_dispatch_call // (lua_State *L, const BCIns *pc)
+ |. move CARG1, L
+ | // Returns ASMFunction.
+ | lw BASE, L->base
+ | lw TMP0, L->top
+ | sw r0, SAVE_PC // Invalidate for subsequent line hook.
+ | subu NARGS8:RC, TMP0, BASE
+ | addu RA, BASE, RA
+ | lw LFUNC:RB, FRAME_FUNC(BASE)
+ | jr CRET1
+ |. lw INS, -4(PC)
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Trace exit handler -------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |.macro savex_, a, b
+ | sdc1 f..a, 16+a*8(sp)
+ | sw r..a, 16+32*8+a*4(sp)
+ | sw r..b, 16+32*8+b*4(sp)
+ |.endmacro
+ |
+ |->vm_exit_handler:
+ |.if JIT
+ | addiu sp, sp, -(16+32*8+32*4)
+ | savex_ 0, 1
+ | savex_ 2, 3
+ | savex_ 4, 5
+ | savex_ 6, 7
+ | savex_ 8, 9
+ | savex_ 10, 11
+ | savex_ 12, 13
+ | savex_ 14, 15
+ | savex_ 16, 17
+ | savex_ 18, 19
+ | savex_ 20, 21
+ | savex_ 22, 23
+ | savex_ 24, 25
+ | savex_ 26, 27
+ | sdc1 f28, 16+28*8(sp)
+ | sw r28, 16+32*8+28*4(sp)
+ | sdc1 f30, 16+30*8(sp)
+ | sw r30, 16+32*8+30*4(sp)
+ | sw r0, 16+32*8+31*4(sp) // Clear RID_TMP.
+ | li_vmstate EXIT
+ | addiu TMP2, sp, 16+32*8+32*4 // Recompute original value of sp.
+ | addiu DISPATCH, JGL, -GG_DISP2G-32768
+ | lw TMP1, 0(TMP2) // Load exit number.
+ | st_vmstate
+ | sw TMP2, 16+32*8+29*4(sp) // Store sp in RID_SP.
+ | lw L, DISPATCH_GL(jit_L)(DISPATCH)
+ | lw BASE, DISPATCH_GL(jit_base)(DISPATCH)
+ | load_got lj_trace_exit
+ | sw L, DISPATCH_J(L)(DISPATCH)
+ | sw ra, DISPATCH_J(parent)(DISPATCH) // Store trace number.
+ | sw TMP1, DISPATCH_J(exitno)(DISPATCH) // Store exit number.
+ | addiu CARG1, DISPATCH, GG_DISP2J
+ | sw BASE, L->base
+ | call_intern lj_trace_exit // (jit_State *J, ExitState *ex)
+ |. addiu CARG2, sp, 16
+ | // Returns MULTRES (unscaled) or negated error code.
+ | lw TMP1, L->cframe
+ | li AT, -4
+ | lw BASE, L->base
+ | and sp, TMP1, AT
+ | lw PC, SAVE_PC // Get SAVE_PC.
+ | b >1
+ |. sw L, SAVE_L // Set SAVE_L (on-trace resume/yield).
+ |.endif
+ |->vm_exit_interp:
+ |.if JIT
+ | // CRET1 = MULTRES or negated error code, BASE, PC and JGL set.
+ | lw L, SAVE_L
+ | addiu DISPATCH, JGL, -GG_DISP2G-32768
+ |1:
+ | bltz CRET1, >3 // Check for error from exit.
+ |. lw LFUNC:TMP1, FRAME_FUNC(BASE)
+ | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
+ | sll MULTRES, CRET1, 3
+ | li TISNIL, LJ_TNIL
+ | sw MULTRES, SAVE_MULTRES
+ | mtc1 TMP3, TOBIT
+ | lw TMP1, LFUNC:TMP1->pc
+ | sw r0, DISPATCH_GL(jit_L)(DISPATCH)
+ | lw KBASE, PC2PROTO(k)(TMP1)
+ | cvt.d.s TOBIT, TOBIT
+ | // Modified copy of ins_next which handles function header dispatch, too.
+ | lw INS, 0(PC)
+ | addiu PC, PC, 4
+ | // Assumes TISNIL == ~LJ_VMST_INTERP == -1
+ | sw TISNIL, DISPATCH_GL(vmstate)(DISPATCH)
+ | decode_OP4a TMP1, INS
+ | decode_OP4b TMP1
+ | sltiu TMP2, TMP1, BC_FUNCF*4 // Function header?
+ | addu TMP0, DISPATCH, TMP1
+ | decode_RD8a RD, INS
+ | lw AT, 0(TMP0)
+ | decode_RA8a RA, INS
+ | beqz TMP2, >2
+ |. decode_RA8b RA
+ | jr AT
+ |. decode_RD8b RD
+ |2:
+ | addiu RC, MULTRES, -8
+ | jr AT
+ |. addu RA, RA, BASE
+ |
+ |3: // Rethrow error from the right C frame.
+ | load_got lj_err_throw
+ | negu CARG2, CRET1
+ | call_intern lj_err_throw // (lua_State *L, int errcode)
+ |. move CARG1, L
+ |.endif
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Math helper functions ----------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |// Modifies AT, TMP0, FRET1, FRET2, f4. Keeps all others incl. FARG1.
+ |.macro vm_round, func
+ | lui TMP0, 0x4330 // Hiword of 2^52 (double).
+ | mtc1 r0, f4
+ | mtc1 TMP0, f5
+ | abs.d FRET2, FARG1 // |x|
+ | mfc1 AT, f13
+ | c.olt.d 0, FRET2, f4
+ | add.d FRET1, FRET2, f4 // (|x| + 2^52) - 2^52
+ | bc1f 0, >1 // Truncate only if |x| < 2^52.
+ |. sub.d FRET1, FRET1, f4
+ | slt AT, AT, r0
+ |.if "func" == "ceil"
+ | lui TMP0, 0xbff0 // Hiword of -1 (double). Preserves -0.
+ |.else
+ | lui TMP0, 0x3ff0 // Hiword of +1 (double).
+ |.endif
+ |.if "func" == "trunc"
+ | mtc1 TMP0, f5
+ | c.olt.d 0, FRET2, FRET1 // |x| < result?
+ | sub.d FRET2, FRET1, f4
+ | movt.d FRET1, FRET2, 0 // If yes, subtract +1.
+ | neg.d FRET2, FRET1
+ | jr ra
+ |. movn.d FRET1, FRET2, AT // Merge sign bit back in.
+ |.else
+ | neg.d FRET2, FRET1
+ | mtc1 TMP0, f5
+ | movn.d FRET1, FRET2, AT // Merge sign bit back in.
+ |.if "func" == "ceil"
+ | c.olt.d 0, FRET1, FARG1 // x > result?
+ |.else
+ | c.olt.d 0, FARG1, FRET1 // x < result?
+ |.endif
+ | sub.d FRET2, FRET1, f4 // If yes, subtract +-1.
+ | jr ra
+ |. movt.d FRET1, FRET2, 0
+ |.endif
+ |1:
+ | jr ra
+ |. mov.d FRET1, FARG1
+ |.endmacro
+ |
+ |->vm_floor:
+ | vm_round floor
+ |->vm_ceil:
+ | vm_round ceil
+ |->vm_trunc:
+ |.if JIT
+ | vm_round trunc
+ |.endif
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Miscellaneous functions --------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |//-----------------------------------------------------------------------
+ |//-- FFI helper functions -----------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |// Handler for callback functions. Callback slot number in r1, g in r2.
+ |->vm_ffi_callback:
+ |.if FFI
+ |.type CTSTATE, CTState, PC
+ | saveregs
+ | lw CTSTATE, GL:r2->ctype_state
+ | addiu DISPATCH, r2, GG_G2DISP
+ | load_got lj_ccallback_enter
+ | sw r1, CTSTATE->cb.slot
+ | sw CARG1, CTSTATE->cb.gpr[0]
+ | sw CARG2, CTSTATE->cb.gpr[1]
+ | sdc1 FARG1, CTSTATE->cb.fpr[0]
+ | sw CARG3, CTSTATE->cb.gpr[2]
+ | sw CARG4, CTSTATE->cb.gpr[3]
+ | sdc1 FARG2, CTSTATE->cb.fpr[1]
+ | addiu TMP0, sp, CFRAME_SPACE+16
+ | sw TMP0, CTSTATE->cb.stack
+ | sw r0, SAVE_PC // Any value outside of bytecode is ok.
+ | move CARG2, sp
+ | call_intern lj_ccallback_enter // (CTState *cts, void *cf)
+ |. move CARG1, CTSTATE
+ | // Returns lua_State *.
+ | lw BASE, L:CRET1->base
+ | lw RC, L:CRET1->top
+ | move L, CRET1
+ | lui TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
+ | lw LFUNC:RB, FRAME_FUNC(BASE)
+ | mtc1 TMP3, TOBIT
+ | li_vmstate INTERP
+ | li TISNIL, LJ_TNIL
+ | subu RC, RC, BASE
+ | st_vmstate
+ | cvt.d.s TOBIT, TOBIT
+ | ins_callt
+ |.endif
+ |
+ |->cont_ffi_callback: // Return from FFI callback.
+ |.if FFI
+ | load_got lj_ccallback_leave
+ | lw CTSTATE, DISPATCH_GL(ctype_state)(DISPATCH)
+ | sw BASE, L->base
+ | sw RB, L->top
+ | sw L, CTSTATE->L
+ | move CARG2, RA
+ | call_intern lj_ccallback_leave // (CTState *cts, TValue *o)
+ |. move CARG1, CTSTATE
+ | lw CRET1, CTSTATE->cb.gpr[0]
+ | ldc1 FRET1, CTSTATE->cb.fpr[0]
+ | lw CRET2, CTSTATE->cb.gpr[1]
+ | b ->vm_leave_unw
+ |. ldc1 FRET2, CTSTATE->cb.fpr[1]
+ |.endif
+ |
+ |->vm_ffi_call: // Call C function via FFI.
+ | // Caveat: needs special frame unwinding, see below.
+ |.if FFI
+ | .type CCSTATE, CCallState, CARG1
+ | lw TMP1, CCSTATE->spadj
+ | lbu CARG2, CCSTATE->nsp
+ | move TMP2, sp
+ | subu sp, sp, TMP1
+ | sw ra, -4(TMP2)
+ | sll CARG2, CARG2, 2
+ | sw r16, -8(TMP2)
+ | sw CCSTATE, -12(TMP2)
+ | move r16, TMP2
+ | addiu TMP1, CCSTATE, offsetof(CCallState, stack)
+ | addiu TMP2, sp, 16
+ | beqz CARG2, >2
+ |. addu TMP3, TMP1, CARG2
+ |1:
+ | lw TMP0, 0(TMP1)
+ | addiu TMP1, TMP1, 4
+ | sltu AT, TMP1, TMP3
+ | sw TMP0, 0(TMP2)
+ | bnez AT, <1
+ |. addiu TMP2, TMP2, 4
+ |2:
+ | lw CFUNCADDR, CCSTATE->func
+ | lw CARG2, CCSTATE->gpr[1]
+ | lw CARG3, CCSTATE->gpr[2]
+ | lw CARG4, CCSTATE->gpr[3]
+ | ldc1 FARG1, CCSTATE->fpr[0]
+ | ldc1 FARG2, CCSTATE->fpr[1]
+ | jalr CFUNCADDR
+ |. lw CARG1, CCSTATE->gpr[0] // Do this last, since CCSTATE is CARG1.
+ | lw CCSTATE:TMP1, -12(r16)
+ | lw TMP2, -8(r16)
+ | lw ra, -4(r16)
+ | sw CRET1, CCSTATE:TMP1->gpr[0]
+ | sw CRET2, CCSTATE:TMP1->gpr[1]
+ | sdc1 FRET1, CCSTATE:TMP1->fpr[0]
+ | sdc1 FRET2, CCSTATE:TMP1->fpr[1]
+ | move sp, r16
+ | jr ra
+ |. move r16, TMP2
+ |.endif
+ |// Note: vm_ffi_call must be the last function in this object file!
+ |
+ |//-----------------------------------------------------------------------
+}
+
+/* Generate the code for a single instruction. */
+static void build_ins(BuildCtx *ctx, BCOp op, int defop)
+{
+ int vk = 0;
+ |=>defop:
+
+ switch (op) {
+
+ /* -- Comparison ops ---------------------------------------------------- */
+
+ /* Remember: all ops branch for a true comparison, fall through otherwise. */
+
+ case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:
+ | // RA = src1*8, RD = src2*8, JMP with RD = target
+ | addu CARG2, BASE, RA
+ | addu CARG3, BASE, RD
+ | lw TMP0, HI(CARG2)
+ | lw TMP1, HI(CARG3)
+ | ldc1 f0, 0(CARG2)
+ | ldc1 f2, 0(CARG3)
+ | sltiu TMP0, TMP0, LJ_TISNUM
+ | sltiu TMP1, TMP1, LJ_TISNUM
+ | lhu TMP2, OFS_RD(PC)
+ | and TMP0, TMP0, TMP1
+ | addiu PC, PC, 4
+ | beqz TMP0, ->vmeta_comp
+ |. lui TMP1, (-(BCBIAS_J*4 >> 16) & 65535)
+ | decode_RD4b TMP2
+ | addu TMP2, TMP2, TMP1
+ if (op == BC_ISLT || op == BC_ISGE) {
+ | c.olt.d f0, f2
+ } else {
+ | c.ole.d f0, f2
+ }
+ if (op == BC_ISLT || op == BC_ISLE) {
+ | movf TMP2, r0
+ } else {
+ | movt TMP2, r0
+ }
+ | addu PC, PC, TMP2
+ |1:
+ | ins_next
+ break;
+
+ case BC_ISEQV: case BC_ISNEV:
+ vk = op == BC_ISEQV;
+ | // RA = src1*8, RD = src2*8, JMP with RD = target
+ | addu RA, BASE, RA
+ | addiu PC, PC, 4
+ | lw TMP0, HI(RA)
+ | ldc1 f0, 0(RA)
+ | addu RD, BASE, RD
+ | lhu TMP2, -4+OFS_RD(PC)
+ | lw TMP1, HI(RD)
+ | ldc1 f2, 0(RD)
+ | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
+ | sltiu AT, TMP0, LJ_TISNUM
+ | sltiu CARG1, TMP1, LJ_TISNUM
+ | decode_RD4b TMP2
+ | and AT, AT, CARG1
+ | beqz AT, >5
+ |. addu TMP2, TMP2, TMP3
+ | c.eq.d f0, f2
+ if (vk) {
+ | movf TMP2, r0
+ } else {
+ | movt TMP2, r0
+ }
+ |1:
+ | addu PC, PC, TMP2
+ | ins_next
+ |5: // Either or both types are not numbers.
+ | lw CARG2, LO(RA)
+ | lw CARG3, LO(RD)
+ |.if FFI
+ | li TMP3, LJ_TCDATA
+ | beq TMP0, TMP3, ->vmeta_equal_cd
+ |.endif
+ |. sltiu AT, TMP0, LJ_TISPRI // Not a primitive?
+ |.if FFI
+ | beq TMP1, TMP3, ->vmeta_equal_cd
+ |.endif
+ |. xor TMP3, CARG2, CARG3 // Same tv?
+ | xor TMP1, TMP1, TMP0 // Same type?
+ | sltiu CARG1, TMP0, LJ_TISTABUD+1 // Table or userdata?
+ | movz TMP3, r0, AT // Ignore tv if primitive.
+ | movn CARG1, r0, TMP1 // Tab/ud and same type?
+ | or AT, TMP1, TMP3 // Same type && (pri||same tv).
+ | movz CARG1, r0, AT
+ | beqz CARG1, <1 // Done if not tab/ud or not same type or same tv.
+ if (vk) {
+ |. movn TMP2, r0, AT
+ } else {
+ |. movz TMP2, r0, AT
+ }
+ | // Different tables or userdatas. Need to check __eq metamethod.
+ | // Field metatable must be at same offset for GCtab and GCudata!
+ | lw TAB:TMP1, TAB:CARG2->metatable
+ | beqz TAB:TMP1, <1 // No metatable?
+ |. nop
+ | lbu TMP1, TAB:TMP1->nomm
+ | andi TMP1, TMP1, 1<<MM_eq
+ | bnez TMP1, <1 // Or 'no __eq' flag set?
+ |. nop
+ | b ->vmeta_equal // Handle __eq metamethod.
+ |. li CARG4, 1-vk // ne = 0 or 1.
+ break;
+
+ case BC_ISEQS: case BC_ISNES:
+ vk = op == BC_ISEQS;
+ | // RA = src*8, RD = str_const*8 (~), JMP with RD = target
+ | addu RA, BASE, RA
+ | addiu PC, PC, 4
+ | lw TMP0, HI(RA)
+ | srl RD, RD, 1
+ | lw STR:TMP3, LO(RA)
+ | subu RD, KBASE, RD
+ | lhu TMP2, -4+OFS_RD(PC)
+ |.if FFI
+ | li AT, LJ_TCDATA
+ | beq TMP0, AT, ->vmeta_equal_cd
+ |.endif
+ |. lw STR:TMP1, -4(RD) // KBASE-4-str_const*4
+ | addiu TMP0, TMP0, -LJ_TSTR
+ | decode_RD4b TMP2
+ | xor TMP1, STR:TMP1, STR:TMP3
+ | or TMP0, TMP0, TMP1
+ | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
+ | addu TMP2, TMP2, TMP3
+ if (vk) {
+ | movn TMP2, r0, TMP0
+ } else {
+ | movz TMP2, r0, TMP0
+ }
+ | addu PC, PC, TMP2
+ | ins_next
+ break;
+
+ case BC_ISEQN: case BC_ISNEN:
+ vk = op == BC_ISEQN;
+ | // RA = src*8, RD = num_const*8, JMP with RD = target
+ | addu RA, BASE, RA
+ | addiu PC, PC, 4
+ | lw TMP0, HI(RA)
+ | ldc1 f0, 0(RA)
+ | addu RD, KBASE, RD
+ | lhu TMP2, -4+OFS_RD(PC)
+ | ldc1 f2, 0(RD)
+ | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
+ | sltiu AT, TMP0, LJ_TISNUM
+ | decode_RD4b TMP2
+ |.if FFI
+ | beqz AT, >5
+ |.else
+ | beqz AT, >1
+ |.endif
+ |. addu TMP2, TMP2, TMP3
+ | c.eq.d f0, f2
+ if (vk) {
+ | movf TMP2, r0
+ | addu PC, PC, TMP2
+ |1:
+ } else {
+ | movt TMP2, r0
+ |1:
+ | addu PC, PC, TMP2
+ }
+ | ins_next
+ |.if FFI
+ |5:
+ | li AT, LJ_TCDATA
+ | beq TMP0, AT, ->vmeta_equal_cd
+ |. nop
+ | b <1
+ |. nop
+ |.endif
+ break;
+
+ case BC_ISEQP: case BC_ISNEP:
+ vk = op == BC_ISEQP;
+ | // RA = src*8, RD = primitive_type*8 (~), JMP with RD = target
+ | addu RA, BASE, RA
+ | srl TMP1, RD, 3
+ | lw TMP0, HI(RA)
+ | lhu TMP2, OFS_RD(PC)
+ | not TMP1, TMP1
+ | addiu PC, PC, 4
+ |.if FFI
+ | li AT, LJ_TCDATA
+ | beq TMP0, AT, ->vmeta_equal_cd
+ |.endif
+ |. xor TMP0, TMP0, TMP1
+ | decode_RD4b TMP2
+ | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
+ | addu TMP2, TMP2, TMP3
+ if (vk) {
+ | movn TMP2, r0, TMP0
+ } else {
+ | movz TMP2, r0, TMP0
+ }
+ | addu PC, PC, TMP2
+ | ins_next
+ break;
+
+ /* -- Unary test and copy ops ------------------------------------------- */
+
+ case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:
+ | // RA = dst*8 or unused, RD = src*8, JMP with RD = target
+ | addu RD, BASE, RD
+ | lhu TMP2, OFS_RD(PC)
+ | lw TMP0, HI(RD)
+ | addiu PC, PC, 4
+ if (op == BC_IST || op == BC_ISF) {
+ | sltiu TMP0, TMP0, LJ_TISTRUECOND
+ | decode_RD4b TMP2
+ | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
+ | addu TMP2, TMP2, TMP3
+ if (op == BC_IST) {
+ | movz TMP2, r0, TMP0
+ } else {
+ | movn TMP2, r0, TMP0
+ }
+ | addu PC, PC, TMP2
+ } else {
+ | sltiu TMP0, TMP0, LJ_TISTRUECOND
+ | ldc1 f0, 0(RD)
+ if (op == BC_ISTC) {
+ | beqz TMP0, >1
+ } else {
+ | bnez TMP0, >1
+ }
+ |. addu RA, BASE, RA
+ | decode_RD4b TMP2
+ | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
+ | addu TMP2, TMP2, TMP3
+ | sdc1 f0, 0(RA)
+ | addu PC, PC, TMP2
+ |1:
+ }
+ | ins_next
+ break;
+
+ /* -- Unary ops --------------------------------------------------------- */
+
+ case BC_MOV:
+ | // RA = dst*8, RD = src*8
+ | addu RD, BASE, RD
+ | addu RA, BASE, RA
+ | ldc1 f0, 0(RD)
+ | ins_next1
+ | sdc1 f0, 0(RA)
+ | ins_next2
+ break;
+ case BC_NOT:
+ | // RA = dst*8, RD = src*8
+ | addu RD, BASE, RD
+ | addu RA, BASE, RA
+ | lw TMP0, HI(RD)
+ | li TMP1, LJ_TFALSE
+ | sltiu TMP0, TMP0, LJ_TISTRUECOND
+ | addiu TMP1, TMP0, LJ_TTRUE
+ | ins_next1
+ | sw TMP1, HI(RA)
+ | ins_next2
+ break;
+ case BC_UNM:
+ | // RA = dst*8, RD = src*8
+ | addu CARG3, BASE, RD
+ | addu RA, BASE, RA
+ | lw TMP0, HI(CARG3)
+ | ldc1 f0, 0(CARG3)
+ | sltiu AT, TMP0, LJ_TISNUM
+ | beqz AT, ->vmeta_unm
+ |. neg.d f0, f0
+ | ins_next1
+ | sdc1 f0, 0(RA)
+ | ins_next2
+ break;
+ case BC_LEN:
+ | // RA = dst*8, RD = src*8
+ | addu CARG2, BASE, RD
+ | addu RA, BASE, RA
+ | lw TMP0, HI(CARG2)
+ | lw CARG1, LO(CARG2)
+ | li AT, LJ_TSTR
+ | bne TMP0, AT, >2
+ |. li AT, LJ_TTAB
+ | lw CRET1, STR:CARG1->len
+ |1:
+ | mtc1 CRET1, f0
+ | cvt.d.w f0, f0
+ | ins_next1
+ | sdc1 f0, 0(RA)
+ | ins_next2
+ |2:
+ | bne TMP0, AT, ->vmeta_len
+ |. nop
+#if LJ_52
+ | lw TAB:TMP2, TAB:CARG1->metatable
+ | bnez TAB:TMP2, >9
+ |. nop
+ |3:
+#endif
+ |->BC_LEN_Z:
+ | load_got lj_tab_len
+ | call_intern lj_tab_len // (GCtab *t)
+ |. nop
+ | // Returns uint32_t (but less than 2^31).
+ | b <1
+ |. nop
+#if LJ_52
+ |9:
+ | lbu TMP0, TAB:TMP2->nomm
+ | andi TMP0, TMP0, 1<<MM_len
+ | bnez TMP0, <3 // 'no __len' flag set: done.
+ |. nop
+ | b ->vmeta_len
+ |. nop
+#endif
+ break;
+
+ /* -- Binary ops -------------------------------------------------------- */
+
+ |.macro ins_arithpre
+ ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
+ | decode_RB8a RB, INS
+ | decode_RB8b RB
+ | decode_RDtoRC8 RC, RD
+ | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8
+ ||switch (vk) {
+ ||case 0:
+ | addu CARG3, BASE, RB
+ | addu CARG4, KBASE, RC
+ | lw TMP1, HI(CARG3)
+ | ldc1 f20, 0(CARG3)
+ | ldc1 f22, 0(CARG4)
+ | sltiu AT, TMP1, LJ_TISNUM
+ || break;
+ ||case 1:
+ | addu CARG4, BASE, RB
+ | addu CARG3, KBASE, RC
+ | lw TMP1, HI(CARG4)
+ | ldc1 f22, 0(CARG4)
+ | ldc1 f20, 0(CARG3)
+ | sltiu AT, TMP1, LJ_TISNUM
+ || break;
+ ||default:
+ | addu CARG3, BASE, RB
+ | addu CARG4, BASE, RC
+ | lw TMP1, HI(CARG3)
+ | lw TMP2, HI(CARG4)
+ | ldc1 f20, 0(CARG3)
+ | ldc1 f22, 0(CARG4)
+ | sltiu AT, TMP1, LJ_TISNUM
+ | sltiu TMP0, TMP2, LJ_TISNUM
+ | and AT, AT, TMP0
+ || break;
+ ||}
+ | beqz AT, ->vmeta_arith
+ |. addu RA, BASE, RA
+ |.endmacro
+ |
+ |.macro fpmod, a, b, c
+ |->BC_MODVN_Z:
+ | bal ->vm_floor // floor(b/c)
+ |. div.d FARG1, b, c
+ | mul.d a, FRET1, c
+ | sub.d a, b, a // b - floor(b/c)*c
+ |.endmacro
+ |
+ |.macro ins_arith, ins
+ | ins_arithpre
+ |.if "ins" == "fpmod_"
+ | b ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway.
+ |. nop
+ |.else
+ | ins f0, f20, f22
+ | ins_next1
+ | sdc1 f0, 0(RA)
+ | ins_next2
+ |.endif
+ |.endmacro
+
+ case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:
+ | ins_arith add.d
+ break;
+ case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:
+ | ins_arith sub.d
+ break;
+ case BC_MULVN: case BC_MULNV: case BC_MULVV:
+ | ins_arith mul.d
+ break;
+ case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:
+ | ins_arith div.d
+ break;
+ case BC_MODVN:
+ | ins_arith fpmod
+ break;
+ case BC_MODNV: case BC_MODVV:
+ | ins_arith fpmod_
+ break;
+ case BC_POW:
+ | decode_RB8a RB, INS
+ | decode_RB8b RB
+ | decode_RDtoRC8 RC, RD
+ | addu CARG3, BASE, RB
+ | addu CARG4, BASE, RC
+ | lw TMP1, HI(CARG3)
+ | lw TMP2, HI(CARG4)
+ | ldc1 FARG1, 0(CARG3)
+ | ldc1 FARG2, 0(CARG4)
+ | sltiu AT, TMP1, LJ_TISNUM
+ | sltiu TMP0, TMP2, LJ_TISNUM
+ | and AT, AT, TMP0
+ | load_got pow
+ | beqz AT, ->vmeta_arith
+ |. addu RA, BASE, RA
+ | call_extern
+ |. nop
+ | ins_next1
+ | sdc1 FRET1, 0(RA)
+ | ins_next2
+ break;
+
+ case BC_CAT:
+ | // RA = dst*8, RB = src_start*8, RC = src_end*8
+ | decode_RB8a RB, INS
+ | decode_RB8b RB
+ | decode_RDtoRC8 RC, RD
+ | subu CARG3, RC, RB
+ | sw BASE, L->base
+ | addu CARG2, BASE, RC
+ | move MULTRES, RB
+ |->BC_CAT_Z:
+ | load_got lj_meta_cat
+ | srl CARG3, CARG3, 3
+ | sw PC, SAVE_PC
+ | call_intern lj_meta_cat // (lua_State *L, TValue *top, int left)
+ |. move CARG1, L
+ | // Returns NULL (finished) or TValue * (metamethod).
+ | bnez CRET1, ->vmeta_binop
+ |. lw BASE, L->base
+ | addu RB, BASE, MULTRES
+ | ldc1 f0, 0(RB)
+ | addu RA, BASE, RA
+ | ins_next1
+ | sdc1 f0, 0(RA) // Copy result from RB to RA.
+ | ins_next2
+ break;
+
+ /* -- Constant ops ------------------------------------------------------ */
+
+ case BC_KSTR:
+ | // RA = dst*8, RD = str_const*8 (~)
+ | srl TMP1, RD, 1
+ | subu TMP1, KBASE, TMP1
+ | ins_next1
+ | lw TMP0, -4(TMP1) // KBASE-4-str_const*4
+ | addu RA, BASE, RA
+ | li TMP2, LJ_TSTR
+ | sw TMP0, LO(RA)
+ | sw TMP2, HI(RA)
+ | ins_next2
+ break;
+ case BC_KCDATA:
+ |.if FFI
+ | // RA = dst*8, RD = cdata_const*8 (~)
+ | srl TMP1, RD, 1
+ | subu TMP1, KBASE, TMP1
+ | ins_next1
+ | lw TMP0, -4(TMP1) // KBASE-4-cdata_const*4
+ | addu RA, BASE, RA
+ | li TMP2, LJ_TCDATA
+ | sw TMP0, LO(RA)
+ | sw TMP2, HI(RA)
+ | ins_next2
+ |.endif
+ break;
+ case BC_KSHORT:
+ | // RA = dst*8, RD = int16_literal*8
+ | sra RD, INS, 16
+ | mtc1 RD, f0
+ | addu RA, BASE, RA
+ | cvt.d.w f0, f0
+ | ins_next1
+ | sdc1 f0, 0(RA)
+ | ins_next2
+ break;
+ case BC_KNUM:
+ | // RA = dst*8, RD = num_const*8
+ | addu RD, KBASE, RD
+ | addu RA, BASE, RA
+ | ldc1 f0, 0(RD)
+ | ins_next1
+ | sdc1 f0, 0(RA)
+ | ins_next2
+ break;
+ case BC_KPRI:
+ | // RA = dst*8, RD = primitive_type*8 (~)
+ | srl TMP1, RD, 3
+ | addu RA, BASE, RA
+ | not TMP0, TMP1
+ | ins_next1
+ | sw TMP0, HI(RA)
+ | ins_next2
+ break;
+ case BC_KNIL:
+ | // RA = base*8, RD = end*8
+ | addu RA, BASE, RA
+ | sw TISNIL, HI(RA)
+ | addiu RA, RA, 8
+ | addu RD, BASE, RD
+ |1:
+ | sw TISNIL, HI(RA)
+ | slt AT, RA, RD
+ | bnez AT, <1
+ |. addiu RA, RA, 8
+ | ins_next_
+ break;
+
+ /* -- Upvalue and function ops ------------------------------------------ */
+
+ case BC_UGET:
+ | // RA = dst*8, RD = uvnum*8
+ | lw LFUNC:RB, FRAME_FUNC(BASE)
+ | srl RD, RD, 1
+ | addu RD, RD, LFUNC:RB
+ | lw UPVAL:RB, LFUNC:RD->uvptr
+ | ins_next1
+ | lw TMP1, UPVAL:RB->v
+ | ldc1 f0, 0(TMP1)
+ | addu RA, BASE, RA
+ | sdc1 f0, 0(RA)
+ | ins_next2
+ break;
+ case BC_USETV:
+ | // RA = uvnum*8, RD = src*8
+ | lw LFUNC:RB, FRAME_FUNC(BASE)
+ | srl RA, RA, 1
+ | addu RD, BASE, RD
+ | addu RA, RA, LFUNC:RB
+ | ldc1 f0, 0(RD)
+ | lw UPVAL:RB, LFUNC:RA->uvptr
+ | lbu TMP3, UPVAL:RB->marked
+ | lw CARG2, UPVAL:RB->v
+ | andi TMP3, TMP3, LJ_GC_BLACK // isblack(uv)
+ | lbu TMP0, UPVAL:RB->closed
+ | lw TMP2, HI(RD)
+ | sdc1 f0, 0(CARG2)
+ | li AT, LJ_GC_BLACK|1
+ | or TMP3, TMP3, TMP0
+ | beq TMP3, AT, >2 // Upvalue is closed and black?
+ |. addiu TMP2, TMP2, -(LJ_TNUMX+1)
+ |1:
+ | ins_next
+ |
+ |2: // Check if new value is collectable.
+ | sltiu AT, TMP2, LJ_TISGCV - (LJ_TNUMX+1)
+ | beqz AT, <1 // tvisgcv(v)
+ |. lw TMP1, LO(RD)
+ | lbu TMP3, GCOBJ:TMP1->gch.marked
+ | andi TMP3, TMP3, LJ_GC_WHITES // iswhite(v)
+ | beqz TMP3, <1
+ |. load_got lj_gc_barrieruv
+ | // Crossed a write barrier. Move the barrier forward.
+ | call_intern lj_gc_barrieruv // (global_State *g, TValue *tv)
+ |. addiu CARG1, DISPATCH, GG_DISP2G
+ | b <1
+ |. nop
+ break;
+ case BC_USETS:
+ | // RA = uvnum*8, RD = str_const*8 (~)
+ | lw LFUNC:RB, FRAME_FUNC(BASE)
+ | srl RA, RA, 1
+ | srl TMP1, RD, 1
+ | addu RA, RA, LFUNC:RB
+ | subu TMP1, KBASE, TMP1
+ | lw UPVAL:RB, LFUNC:RA->uvptr
+ | lw STR:TMP1, -4(TMP1) // KBASE-4-str_const*4
+ | lbu TMP2, UPVAL:RB->marked
+ | lw CARG2, UPVAL:RB->v
+ | lbu TMP3, STR:TMP1->marked
+ | andi AT, TMP2, LJ_GC_BLACK // isblack(uv)
+ | lbu TMP2, UPVAL:RB->closed
+ | li TMP0, LJ_TSTR
+ | sw STR:TMP1, LO(CARG2)
+ | bnez AT, >2
+ |. sw TMP0, HI(CARG2)
+ |1:
+ | ins_next
+ |
+ |2: // Check if string is white and ensure upvalue is closed.
+ | beqz TMP2, <1
+ |. andi AT, TMP3, LJ_GC_WHITES // iswhite(str)
+ | beqz AT, <1
+ |. load_got lj_gc_barrieruv
+ | // Crossed a write barrier. Move the barrier forward.
+ | call_intern lj_gc_barrieruv // (global_State *g, TValue *tv)
+ |. addiu CARG1, DISPATCH, GG_DISP2G
+ | b <1
+ |. nop
+ break;
+ case BC_USETN:
+ | // RA = uvnum*8, RD = num_const*8
+ | lw LFUNC:RB, FRAME_FUNC(BASE)
+ | srl RA, RA, 1
+ | addu RD, KBASE, RD
+ | addu RA, RA, LFUNC:RB
+ | ldc1 f0, 0(RD)
+ | lw UPVAL:RB, LFUNC:RA->uvptr
+ | ins_next1
+ | lw TMP1, UPVAL:RB->v
+ | sdc1 f0, 0(TMP1)
+ | ins_next2
+ break;
+ case BC_USETP:
+ | // RA = uvnum*8, RD = primitive_type*8 (~)
+ | lw LFUNC:RB, FRAME_FUNC(BASE)
+ | srl RA, RA, 1
+ | srl TMP0, RD, 3
+ | addu RA, RA, LFUNC:RB
+ | not TMP0, TMP0
+ | lw UPVAL:RB, LFUNC:RA->uvptr
+ | ins_next1
+ | lw TMP1, UPVAL:RB->v
+ | sw TMP0, HI(TMP1)
+ | ins_next2
+ break;
+
+ case BC_UCLO:
+ | // RA = level*8, RD = target
+ | lw TMP2, L->openupval
+ | branch_RD // Do this first since RD is not saved.
+ | load_got lj_func_closeuv
+ | sw BASE, L->base
+ | beqz TMP2, >1
+ |. move CARG1, L
+ | call_intern lj_func_closeuv // (lua_State *L, TValue *level)
+ |. addu CARG2, BASE, RA
+ | lw BASE, L->base
+ |1:
+ | ins_next
+ break;
+
+ case BC_FNEW:
+ | // RA = dst*8, RD = proto_const*8 (~) (holding function prototype)
+ | srl TMP1, RD, 1
+ | load_got lj_func_newL_gc
+ | subu TMP1, KBASE, TMP1
+ | lw CARG3, FRAME_FUNC(BASE)
+ | lw CARG2, -4(TMP1) // KBASE-4-tab_const*4
+ | sw BASE, L->base
+ | sw PC, SAVE_PC
+ | // (lua_State *L, GCproto *pt, GCfuncL *parent)
+ | call_intern lj_func_newL_gc
+ |. move CARG1, L
+ | // Returns GCfuncL *.
+ | lw BASE, L->base
+ | li TMP0, LJ_TFUNC
+ | ins_next1
+ | addu RA, BASE, RA
+ | sw TMP0, HI(RA)
+ | sw LFUNC:CRET1, LO(RA)
+ | ins_next2
+ break;
+
+ /* -- Table ops --------------------------------------------------------- */
+
+ case BC_TNEW:
+ case BC_TDUP:
+ | // RA = dst*8, RD = (hbits|asize)*8 | tab_const*8 (~)
+ | lw TMP0, DISPATCH_GL(gc.total)(DISPATCH)
+ | lw TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)
+ | sw BASE, L->base
+ | sw PC, SAVE_PC
+ | sltu AT, TMP0, TMP1
+ | beqz AT, >5
+ |1:
+ if (op == BC_TNEW) {
+ | load_got lj_tab_new
+ | srl CARG2, RD, 3
+ | andi CARG2, CARG2, 0x7ff
+ | li TMP0, 0x801
+ | addiu AT, CARG2, -0x7ff
+ | srl CARG3, RD, 14
+ | movz CARG2, TMP0, AT
+ | // (lua_State *L, int32_t asize, uint32_t hbits)
+ | call_intern lj_tab_new
+ |. move CARG1, L
+ | // Returns Table *.
+ } else {
+ | load_got lj_tab_dup
+ | srl TMP1, RD, 1
+ | subu TMP1, KBASE, TMP1
+ | move CARG1, L
+ | call_intern lj_tab_dup // (lua_State *L, Table *kt)
+ |. lw CARG2, -4(TMP1) // KBASE-4-str_const*4
+ | // Returns Table *.
+ }
+ | lw BASE, L->base
+ | ins_next1
+ | addu RA, BASE, RA
+ | li TMP0, LJ_TTAB
+ | sw TAB:CRET1, LO(RA)
+ | sw TMP0, HI(RA)
+ | ins_next2
+ |5:
+ | load_got lj_gc_step_fixtop
+ | move MULTRES, RD
+ | call_intern lj_gc_step_fixtop // (lua_State *L)
+ |. move CARG1, L
+ | b <1
+ |. move RD, MULTRES
+ break;
+
+ case BC_GGET:
+ | // RA = dst*8, RD = str_const*8 (~)
+ case BC_GSET:
+ | // RA = src*8, RD = str_const*8 (~)
+ | lw LFUNC:TMP2, FRAME_FUNC(BASE)
+ | srl TMP1, RD, 1
+ | subu TMP1, KBASE, TMP1
+ | lw TAB:RB, LFUNC:TMP2->env
+ | lw STR:RC, -4(TMP1) // KBASE-4-str_const*4
+ if (op == BC_GGET) {
+ | b ->BC_TGETS_Z
+ } else {
+ | b ->BC_TSETS_Z
+ }
+ |. addu RA, BASE, RA
+ break;
+
+ case BC_TGETV:
+ | // RA = dst*8, RB = table*8, RC = key*8
+ | decode_RB8a RB, INS
+ | decode_RB8b RB
+ | decode_RDtoRC8 RC, RD
+ | addu CARG2, BASE, RB
+ | addu CARG3, BASE, RC
+ | lw TMP1, HI(CARG2)
+ | lw TMP2, HI(CARG3)
+ | lw TAB:RB, LO(CARG2)
+ | li AT, LJ_TTAB
+ | ldc1 f0, 0(CARG3)
+ | bne TMP1, AT, ->vmeta_tgetv
+ |. addu RA, BASE, RA
+ | sltiu AT, TMP2, LJ_TISNUM
+ | beqz AT, >5
+ |. li AT, LJ_TSTR
+ |
+ | // Convert number key to integer, check for integerness and range.
+ | cvt.w.d f2, f0
+ | lw TMP0, TAB:RB->asize
+ | mfc1 TMP2, f2
+ | cvt.d.w f4, f2
+ | lw TMP1, TAB:RB->array
+ | c.eq.d f0, f4
+ | sltu AT, TMP2, TMP0
+ | movf AT, r0
+ | sll TMP2, TMP2, 3
+ | beqz AT, ->vmeta_tgetv // Integer key and in array part?
+ |. addu TMP2, TMP1, TMP2
+ | lw TMP0, HI(TMP2)
+ | beq TMP0, TISNIL, >2
+ |. ldc1 f0, 0(TMP2)
+ |1:
+ | ins_next1
+ | sdc1 f0, 0(RA)
+ | ins_next2
+ |
+ |2: // Check for __index if table value is nil.
+ | lw TAB:TMP2, TAB:RB->metatable
+ | beqz TAB:TMP2, <1 // No metatable: done.
+ |. nop
+ | lbu TMP0, TAB:TMP2->nomm
+ | andi TMP0, TMP0, 1<<MM_index
+ | bnez TMP0, <1 // 'no __index' flag set: done.
+ |. nop
+ | b ->vmeta_tgetv
+ |. nop
+ |
+ |5:
+ | bne TMP2, AT, ->vmeta_tgetv
+ |. lw STR:RC, LO(CARG3)
+ | b ->BC_TGETS_Z // String key?
+ |. nop
+ break;
+ case BC_TGETS:
+ | // RA = dst*8, RB = table*8, RC = str_const*4 (~)
+ | decode_RB8a RB, INS
+ | decode_RB8b RB
+ | addu CARG2, BASE, RB
+ | decode_RC4a RC, INS
+ | lw TMP0, HI(CARG2)
+ | decode_RC4b RC
+ | li AT, LJ_TTAB
+ | lw TAB:RB, LO(CARG2)
+ | subu CARG3, KBASE, RC
+ | lw STR:RC, -4(CARG3) // KBASE-4-str_const*4
+ | bne TMP0, AT, ->vmeta_tgets1
+ |. addu RA, BASE, RA
+ |->BC_TGETS_Z:
+ | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = dst*8
+ | lw TMP0, TAB:RB->hmask
+ | lw TMP1, STR:RC->hash
+ | lw NODE:TMP2, TAB:RB->node
+ | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask
+ | sll TMP0, TMP1, 5
+ | sll TMP1, TMP1, 3
+ | subu TMP1, TMP0, TMP1
+ | addu NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8)
+ |1:
+ | lw CARG1, offsetof(Node, key)+HI(NODE:TMP2)
+ | lw TMP0, offsetof(Node, key)+LO(NODE:TMP2)
+ | lw NODE:TMP1, NODE:TMP2->next
+ | lw CARG2, offsetof(Node, val)+HI(NODE:TMP2)
+ | addiu CARG1, CARG1, -LJ_TSTR
+ | xor TMP0, TMP0, STR:RC
+ | or AT, CARG1, TMP0
+ | bnez AT, >4
+ |. lw TAB:TMP3, TAB:RB->metatable
+ | beq CARG2, TISNIL, >5 // Key found, but nil value?
+ |. lw CARG1, offsetof(Node, val)+LO(NODE:TMP2)
+ |3:
+ | ins_next1
+ | sw CARG2, HI(RA)
+ | sw CARG1, LO(RA)
+ | ins_next2
+ |
+ |4: // Follow hash chain.
+ | bnez NODE:TMP1, <1
+ |. move NODE:TMP2, NODE:TMP1
+ | // End of hash chain: key not found, nil result.
+ |
+ |5: // Check for __index if table value is nil.
+ | beqz TAB:TMP3, <3 // No metatable: done.
+ |. li CARG2, LJ_TNIL
+ | lbu TMP0, TAB:TMP3->nomm
+ | andi TMP0, TMP0, 1<<MM_index
+ | bnez TMP0, <3 // 'no __index' flag set: done.
+ |. nop
+ | b ->vmeta_tgets
+ |. nop
+ break;
+ case BC_TGETB:
+ | // RA = dst*8, RB = table*8, RC = index*8
+ | decode_RB8a RB, INS
+ | decode_RB8b RB
+ | addu CARG2, BASE, RB
+ | decode_RDtoRC8 RC, RD
+ | lw CARG1, HI(CARG2)
+ | li AT, LJ_TTAB
+ | lw TAB:RB, LO(CARG2)
+ | addu RA, BASE, RA
+ | bne CARG1, AT, ->vmeta_tgetb
+ |. srl TMP0, RC, 3
+ | lw TMP1, TAB:RB->asize
+ | lw TMP2, TAB:RB->array
+ | sltu AT, TMP0, TMP1
+ | beqz AT, ->vmeta_tgetb
+ |. addu RC, TMP2, RC
+ | lw TMP1, HI(RC)
+ | beq TMP1, TISNIL, >5
+ |. ldc1 f0, 0(RC)
+ |1:
+ | ins_next1
+ | sdc1 f0, 0(RA)
+ | ins_next2
+ |
+ |5: // Check for __index if table value is nil.
+ | lw TAB:TMP2, TAB:RB->metatable
+ | beqz TAB:TMP2, <1 // No metatable: done.
+ |. nop
+ | lbu TMP1, TAB:TMP2->nomm
+ | andi TMP1, TMP1, 1<<MM_index
+ | bnez TMP1, <1 // 'no __index' flag set: done.
+ |. nop
+ | b ->vmeta_tgetb // Caveat: preserve TMP0!
+ |. nop
+ break;
+
+ case BC_TSETV:
+ | // RA = src*8, RB = table*8, RC = key*8
+ | decode_RB8a RB, INS
+ | decode_RB8b RB
+ | decode_RDtoRC8 RC, RD
+ | addu CARG2, BASE, RB
+ | addu CARG3, BASE, RC
+ | lw TMP1, HI(CARG2)
+ | lw TMP2, HI(CARG3)
+ | lw TAB:RB, LO(CARG2)
+ | li AT, LJ_TTAB
+ | ldc1 f0, 0(CARG3)
+ | bne TMP1, AT, ->vmeta_tsetv
+ |. addu RA, BASE, RA
+ | sltiu AT, TMP2, LJ_TISNUM
+ | beqz AT, >5
+ |. li AT, LJ_TSTR
+ |
+ | // Convert number key to integer, check for integerness and range.
+ | cvt.w.d f2, f0
+ | lw TMP0, TAB:RB->asize
+ | mfc1 TMP2, f2
+ | cvt.d.w f4, f2
+ | lw TMP1, TAB:RB->array
+ | c.eq.d f0, f4
+ | sltu AT, TMP2, TMP0
+ | movf AT, r0
+ | sll TMP2, TMP2, 3
+ | beqz AT, ->vmeta_tsetv // Integer key and in array part?
+ |. addu TMP1, TMP1, TMP2
+ | lbu TMP3, TAB:RB->marked
+ | lw TMP0, HI(TMP1)
+ | beq TMP0, TISNIL, >3
+ |. ldc1 f0, 0(RA)
+ |1:
+ | andi AT, TMP3, LJ_GC_BLACK // isblack(table)
+ | bnez AT, >7
+ |. sdc1 f0, 0(TMP1)
+ |2:
+ | ins_next
+ |
+ |3: // Check for __newindex if previous value is nil.
+ | lw TAB:TMP2, TAB:RB->metatable
+ | beqz TAB:TMP2, <1 // No metatable: done.
+ |. nop
+ | lbu TMP2, TAB:TMP2->nomm
+ | andi TMP2, TMP2, 1<<MM_newindex
+ | bnez TMP2, <1 // 'no __newindex' flag set: done.
+ |. nop
+ | b ->vmeta_tsetv
+ |. nop
+ |
+ |5:
+ | bne TMP2, AT, ->vmeta_tsetv
+ |. lw STR:RC, LO(CARG3)
+ | b ->BC_TSETS_Z // String key?
+ |. nop
+ |
+ |7: // Possible table write barrier for the value. Skip valiswhite check.
+ | barrierback TAB:RB, TMP3, TMP0, <2
+ break;
+ case BC_TSETS:
+ | // RA = src*8, RB = table*8, RC = str_const*8 (~)
+ | decode_RB8a RB, INS
+ | decode_RB8b RB
+ | addu CARG2, BASE, RB
+ | decode_RC4a RC, INS
+ | lw TMP0, HI(CARG2)
+ | decode_RC4b RC
+ | li AT, LJ_TTAB
+ | subu CARG3, KBASE, RC
+ | lw TAB:RB, LO(CARG2)
+ | lw STR:RC, -4(CARG3) // KBASE-4-str_const*4
+ | bne TMP0, AT, ->vmeta_tsets1
+ |. addu RA, BASE, RA
+ |->BC_TSETS_Z:
+ | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = BASE+src*8
+ | lw TMP0, TAB:RB->hmask
+ | lw TMP1, STR:RC->hash
+ | lw NODE:TMP2, TAB:RB->node
+ | sb r0, TAB:RB->nomm // Clear metamethod cache.
+ | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask
+ | sll TMP0, TMP1, 5
+ | sll TMP1, TMP1, 3
+ | subu TMP1, TMP0, TMP1
+ | addu NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8)
+ | ldc1 f20, 0(RA)
+ |1:
+ | lw CARG1, offsetof(Node, key)+HI(NODE:TMP2)
+ | lw TMP0, offsetof(Node, key)+LO(NODE:TMP2)
+ | li AT, LJ_TSTR
+ | lw NODE:TMP1, NODE:TMP2->next
+ | bne CARG1, AT, >5
+ |. lw CARG2, offsetof(Node, val)+HI(NODE:TMP2)
+ | bne TMP0, STR:RC, >5
+ |. lbu TMP3, TAB:RB->marked
+ | beq CARG2, TISNIL, >4 // Key found, but nil value?
+ |. lw TAB:TMP0, TAB:RB->metatable
+ |2:
+ | andi AT, TMP3, LJ_GC_BLACK // isblack(table)
+ | bnez AT, >7
+ |. sdc1 f20, NODE:TMP2->val
+ |3:
+ | ins_next
+ |
+ |4: // Check for __newindex if previous value is nil.
+ | beqz TAB:TMP0, <2 // No metatable: done.
+ |. nop
+ | lbu TMP0, TAB:TMP0->nomm
+ | andi TMP0, TMP0, 1<<MM_newindex
+ | bnez TMP0, <2 // 'no __newindex' flag set: done.
+ |. nop
+ | b ->vmeta_tsets
+ |. nop
+ |
+ |5: // Follow hash chain.
+ | bnez NODE:TMP1, <1
+ |. move NODE:TMP2, NODE:TMP1
+ | // End of hash chain: key not found, add a new one
+ |
+ | // But check for __newindex first.
+ | lw TAB:TMP2, TAB:RB->metatable
+ | beqz TAB:TMP2, >6 // No metatable: continue.
+ |. addiu CARG3, DISPATCH, DISPATCH_GL(tmptv)
+ | lbu TMP0, TAB:TMP2->nomm
+ | andi TMP0, TMP0, 1<<MM_newindex
+ | beqz TMP0, ->vmeta_tsets // 'no __newindex' flag NOT set: check.
+ |. li AT, LJ_TSTR
+ |6:
+ | load_got lj_tab_newkey
+ | sw STR:RC, LO(CARG3)
+ | sw AT, HI(CARG3)
+ | sw BASE, L->base
+ | move CARG2, TAB:RB
+ | sw PC, SAVE_PC
+ | call_intern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k
+ |. move CARG1, L
+ | // Returns TValue *.
+ | lw BASE, L->base
+ | b <3 // No 2nd write barrier needed.
+ |. sdc1 f20, 0(CRET1)
+ |
+ |7: // Possible table write barrier for the value. Skip valiswhite check.
+ | barrierback TAB:RB, TMP3, TMP0, <3
+ break;
+ case BC_TSETB:
+ | // RA = src*8, RB = table*8, RC = index*8
+ | decode_RB8a RB, INS
+ | decode_RB8b RB
+ | addu CARG2, BASE, RB
+ | decode_RDtoRC8 RC, RD
+ | lw CARG1, HI(CARG2)
+ | li AT, LJ_TTAB
+ | lw TAB:RB, LO(CARG2)
+ | addu RA, BASE, RA
+ | bne CARG1, AT, ->vmeta_tsetb
+ |. srl TMP0, RC, 3
+ | lw TMP1, TAB:RB->asize
+ | lw TMP2, TAB:RB->array
+ | sltu AT, TMP0, TMP1
+ | beqz AT, ->vmeta_tsetb
+ |. addu RC, TMP2, RC
+ | lw TMP1, HI(RC)
+ | lbu TMP3, TAB:RB->marked
+ | beq TMP1, TISNIL, >5
+ |. ldc1 f0, 0(RA)
+ |1:
+ | andi AT, TMP3, LJ_GC_BLACK // isblack(table)
+ | bnez AT, >7
+ |. sdc1 f0, 0(RC)
+ |2:
+ | ins_next
+ |
+ |5: // Check for __newindex if previous value is nil.
+ | lw TAB:TMP2, TAB:RB->metatable
+ | beqz TAB:TMP2, <1 // No metatable: done.
+ |. nop
+ | lbu TMP1, TAB:TMP2->nomm
+ | andi TMP1, TMP1, 1<<MM_newindex
+ | bnez TMP1, <1 // 'no __newindex' flag set: done.
+ |. nop
+ | b ->vmeta_tsetb // Caveat: preserve TMP0!
+ |. nop
+ |
+ |7: // Possible table write barrier for the value. Skip valiswhite check.
+ | barrierback TAB:RB, TMP3, TMP0, <2
+ break;
+
+ case BC_TSETM:
+ | // RA = base*8 (table at base-1), RD = num_const*8 (start index)
+ | addu RA, BASE, RA
+ |1:
+ | addu TMP3, KBASE, RD
+ | lw TAB:CARG2, -8+LO(RA) // Guaranteed to be a table.
+ | addiu TMP0, MULTRES, -8
+ | lw TMP3, LO(TMP3) // Integer constant is in lo-word.
+ | beqz TMP0, >4 // Nothing to copy?
+ |. srl CARG3, TMP0, 3
+ | addu CARG3, CARG3, TMP3
+ | lw TMP2, TAB:CARG2->asize
+ | sll TMP1, TMP3, 3
+ | lbu TMP3, TAB:CARG2->marked
+ | lw CARG1, TAB:CARG2->array
+ | sltu AT, TMP2, CARG3
+ | bnez AT, >5
+ |. addu TMP2, RA, TMP0
+ | addu TMP1, TMP1, CARG1
+ | andi TMP0, TMP3, LJ_GC_BLACK // isblack(table)
+ |3: // Copy result slots to table.
+ | ldc1 f0, 0(RA)
+ | addiu RA, RA, 8
+ | sltu AT, RA, TMP2
+ | sdc1 f0, 0(TMP1)
+ | bnez AT, <3
+ |. addiu TMP1, TMP1, 8
+ | bnez TMP0, >7
+ |. nop
+ |4:
+ | ins_next
+ |
+ |5: // Need to resize array part.
+ | load_got lj_tab_reasize
+ | sw BASE, L->base
+ | sw PC, SAVE_PC
+ | move BASE, RD
+ | call_intern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize)
+ |. move CARG1, L
+ | // Must not reallocate the stack.
+ | move RD, BASE
+ | b <1
+ |. lw BASE, L->base // Reload BASE for lack of a saved register.
+ |
+ |7: // Possible table write barrier for any value. Skip valiswhite check.
+ | barrierback TAB:CARG2, TMP3, TMP0, <4
+ break;
+
+ /* -- Calls and vararg handling ----------------------------------------- */
+
+ case BC_CALLM:
+ | // RA = base*8, (RB = (nresults+1)*8,) RC = extra_nargs*8
+ | decode_RDtoRC8 NARGS8:RC, RD
+ | b ->BC_CALL_Z
+ |. addu NARGS8:RC, NARGS8:RC, MULTRES
+ break;
+ case BC_CALL:
+ | // RA = base*8, (RB = (nresults+1)*8,) RC = (nargs+1)*8
+ | decode_RDtoRC8 NARGS8:RC, RD
+ |->BC_CALL_Z:
+ | move TMP2, BASE
+ | addu BASE, BASE, RA
+ | li AT, LJ_TFUNC
+ | lw TMP0, HI(BASE)
+ | lw LFUNC:RB, LO(BASE)
+ | addiu BASE, BASE, 8
+ | bne TMP0, AT, ->vmeta_call
+ |. addiu NARGS8:RC, NARGS8:RC, -8
+ | ins_call
+ break;
+
+ case BC_CALLMT:
+ | // RA = base*8, (RB = 0,) RC = extra_nargs*8
+ | addu NARGS8:RD, NARGS8:RD, MULTRES // BC_CALLT gets RC from RD.
+ | // Fall through. Assumes BC_CALLT follows.
+ break;
+ case BC_CALLT:
+ | // RA = base*8, (RB = 0,) RC = (nargs+1)*8
+ | addu RA, BASE, RA
+ | li AT, LJ_TFUNC
+ | lw TMP0, HI(RA)
+ | lw LFUNC:RB, LO(RA)
+ | move NARGS8:RC, RD
+ | lw TMP1, FRAME_PC(BASE)
+ | addiu RA, RA, 8
+ | bne TMP0, AT, ->vmeta_callt
+ |. addiu NARGS8:RC, NARGS8:RC, -8
+ |->BC_CALLT_Z:
+ | andi TMP0, TMP1, FRAME_TYPE // Caveat: preserve TMP0 until the 'or'.
+ | lbu TMP3, LFUNC:RB->ffid
+ | bnez TMP0, >7
+ |. xori TMP2, TMP1, FRAME_VARG
+ |1:
+ | sw LFUNC:RB, FRAME_FUNC(BASE) // Copy function down, but keep PC.
+ | sltiu AT, TMP3, 2 // (> FF_C) Calling a fast function?
+ | move TMP2, BASE
+ | beqz NARGS8:RC, >3
+ |. move TMP3, NARGS8:RC
+ |2:
+ | ldc1 f0, 0(RA)
+ | addiu RA, RA, 8
+ | addiu TMP3, TMP3, -8
+ | sdc1 f0, 0(TMP2)
+ | bnez TMP3, <2
+ |. addiu TMP2, TMP2, 8
+ |3:
+ | or TMP0, TMP0, AT
+ | beqz TMP0, >5
+ |. nop
+ |4:
+ | ins_callt
+ |
+ |5: // Tailcall to a fast function with a Lua frame below.
+ | lw INS, -4(TMP1)
+ | decode_RA8a RA, INS
+ | decode_RA8b RA
+ | subu TMP1, BASE, RA
+ | lw LFUNC:TMP1, -8+FRAME_FUNC(TMP1)
+ | lw TMP1, LFUNC:TMP1->pc
+ | b <4
+ |. lw KBASE, PC2PROTO(k)(TMP1) // Need to prepare KBASE.
+ |
+ |7: // Tailcall from a vararg function.
+ | andi AT, TMP2, FRAME_TYPEP
+ | bnez AT, <1 // Vararg frame below?
+ |. subu TMP2, BASE, TMP2 // Relocate BASE down.
+ | move BASE, TMP2
+ | lw TMP1, FRAME_PC(TMP2)
+ | b <1
+ |. andi TMP0, TMP1, FRAME_TYPE
+ break;
+
+ case BC_ITERC:
+ | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 ((2+1)*8))
+ | move TMP2, BASE
+ | addu BASE, BASE, RA
+ | li AT, LJ_TFUNC
+ | lw TMP1, -24+HI(BASE)
+ | lw LFUNC:RB, -24+LO(BASE)
+ | ldc1 f2, -8(BASE)
+ | ldc1 f0, -16(BASE)
+ | sw TMP1, HI(BASE) // Copy callable.
+ | sw LFUNC:RB, LO(BASE)
+ | sdc1 f2, 16(BASE) // Copy control var.
+ | sdc1 f0, 8(BASE) // Copy state.
+ | addiu BASE, BASE, 8
+ | bne TMP1, AT, ->vmeta_call
+ |. li NARGS8:RC, 16 // Iterators get 2 arguments.
+ | ins_call
+ break;
+
+ case BC_ITERN:
+ | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 (2+1)*8)
+ |.if JIT
+ | // NYI: add hotloop, record BC_ITERN.
+ |.endif
+ | addu RA, BASE, RA
+ | lw TAB:RB, -16+LO(RA)
+ | lw RC, -8+LO(RA) // Get index from control var.
+ | lw TMP0, TAB:RB->asize
+ | lw TMP1, TAB:RB->array
+ | addiu PC, PC, 4
+ |1: // Traverse array part.
+ | sltu AT, RC, TMP0
+ | beqz AT, >5 // Index points after array part?
+ |. sll TMP3, RC, 3
+ | addu TMP3, TMP1, TMP3
+ | lw TMP2, HI(TMP3)
+ | ldc1 f0, 0(TMP3)
+ | mtc1 RC, f2
+ | lhu RD, -4+OFS_RD(PC)
+ | beq TMP2, TISNIL, <1 // Skip holes in array part.
+ |. addiu RC, RC, 1
+ | cvt.d.w f2, f2
+ | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
+ | sdc1 f0, 8(RA)
+ | decode_RD4b RD
+ | addu RD, RD, TMP3
+ | sw RC, -8+LO(RA) // Update control var.
+ | addu PC, PC, RD
+ | sdc1 f2, 0(RA)
+ |3:
+ | ins_next
+ |
+ |5: // Traverse hash part.
+ | lw TMP1, TAB:RB->hmask
+ | subu RC, RC, TMP0
+ | lw TMP2, TAB:RB->node
+ |6:
+ | sltu AT, TMP1, RC // End of iteration? Branch to ITERL+1.
+ | bnez AT, <3
+ |. sll TMP3, RC, 5
+ | sll RB, RC, 3
+ | subu TMP3, TMP3, RB
+ | addu NODE:TMP3, TMP3, TMP2
+ | lw RB, HI(NODE:TMP3)
+ | ldc1 f0, 0(NODE:TMP3)
+ | lhu RD, -4+OFS_RD(PC)
+ | beq RB, TISNIL, <6 // Skip holes in hash part.
+ |. addiu RC, RC, 1
+ | ldc1 f2, NODE:TMP3->key
+ | lui TMP3, (-(BCBIAS_J*4 >> 16) & 65535)
+ | sdc1 f0, 8(RA)
+ | addu RC, RC, TMP0
+ | decode_RD4b RD
+ | addu RD, RD, TMP3
+ | sdc1 f2, 0(RA)
+ | addu PC, PC, RD
+ | b <3
+ |. sw RC, -8+LO(RA) // Update control var.
+ break;
+
+ case BC_ISNEXT:
+ | // RA = base*8, RD = target (points to ITERN)
+ | addu RA, BASE, RA
+ | srl TMP0, RD, 1
+ | lw CARG1, -24+HI(RA)
+ | lw CFUNC:CARG2, -24+LO(RA)
+ | addu TMP0, PC, TMP0
+ | lw CARG3, -16+HI(RA)
+ | lw CARG4, -8+HI(RA)
+ | li AT, LJ_TFUNC
+ | bne CARG1, AT, >5
+ |. lui TMP2, (-(BCBIAS_J*4 >> 16) & 65535)
+ | lbu CARG2, CFUNC:CARG2->ffid
+ | addiu CARG3, CARG3, -LJ_TTAB
+ | addiu CARG4, CARG4, -LJ_TNIL
+ | or CARG3, CARG3, CARG4
+ | addiu CARG2, CARG2, -FF_next_N
+ | or CARG2, CARG2, CARG3
+ | bnez CARG2, >5
+ |. lui TMP1, 0xfffe
+ | addu PC, TMP0, TMP2
+ | ori TMP1, TMP1, 0x7fff
+ | sw r0, -8+LO(RA) // Initialize control var.
+ | sw TMP1, -8+HI(RA)
+ |1:
+ | ins_next
+ |5: // Despecialize bytecode if any of the checks fail.
+ | li TMP3, BC_JMP
+ | li TMP1, BC_ITERC
+ | sb TMP3, -4+OFS_OP(PC)
+ | addu PC, TMP0, TMP2
+ | b <1
+ |. sb TMP1, OFS_OP(PC)
+ break;
+
+ case BC_VARG:
+ | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8
+ | lw TMP0, FRAME_PC(BASE)
+ | decode_RDtoRC8 RC, RD
+ | decode_RB8a RB, INS
+ | addu RC, BASE, RC
+ | decode_RB8b RB
+ | addu RA, BASE, RA
+ | addiu RC, RC, FRAME_VARG
+ | addu TMP2, RA, RB
+ | addiu TMP3, BASE, -8 // TMP3 = vtop
+ | subu RC, RC, TMP0 // RC = vbase
+ | // Note: RC may now be even _above_ BASE if nargs was < numparams.
+ | beqz RB, >5 // Copy all varargs?
+ |. subu TMP1, TMP3, RC
+ | addiu TMP2, TMP2, -16
+ |1: // Copy vararg slots to destination slots.
+ | lw CARG1, HI(RC)
+ | sltu AT, RC, TMP3
+ | lw CARG2, LO(RC)
+ | addiu RC, RC, 8
+ | movz CARG1, TISNIL, AT
+ | sw CARG1, HI(RA)
+ | sw CARG2, LO(RA)
+ | sltu AT, RA, TMP2
+ | bnez AT, <1
+ |. addiu RA, RA, 8
+ |3:
+ | ins_next
+ |
+ |5: // Copy all varargs.
+ | lw TMP0, L->maxstack
+ | blez TMP1, <3 // No vararg slots?
+ |. li MULTRES, 8 // MULTRES = (0+1)*8
+ | addu TMP2, RA, TMP1
+ | sltu AT, TMP0, TMP2
+ | bnez AT, >7
+ |. addiu MULTRES, TMP1, 8
+ |6:
+ | ldc1 f0, 0(RC)
+ | addiu RC, RC, 8
+ | sdc1 f0, 0(RA)
+ | sltu AT, RC, TMP3
+ | bnez AT, <6 // More vararg slots?
+ |. addiu RA, RA, 8
+ | b <3
+ |. nop
+ |
+ |7: // Grow stack for varargs.
+ | load_got lj_state_growstack
+ | sw RA, L->top
+ | subu RA, RA, BASE
+ | sw BASE, L->base
+ | subu BASE, RC, BASE // Need delta, because BASE may change.
+ | sw PC, SAVE_PC
+ | srl CARG2, TMP1, 3
+ | call_intern lj_state_growstack // (lua_State *L, int n)
+ |. move CARG1, L
+ | move RC, BASE
+ | lw BASE, L->base
+ | addu RA, BASE, RA
+ | addu RC, BASE, RC
+ | b <6
+ |. addiu TMP3, BASE, -8
+ break;
+
+ /* -- Returns ----------------------------------------------------------- */
+
+ case BC_RETM:
+ | // RA = results*8, RD = extra_nresults*8
+ | addu RD, RD, MULTRES // MULTRES >= 8, so RD >= 8.
+ | // Fall through. Assumes BC_RET follows.
+ break;
+
+ case BC_RET:
+ | // RA = results*8, RD = (nresults+1)*8
+ | lw PC, FRAME_PC(BASE)
+ | addu RA, BASE, RA
+ | move MULTRES, RD
+ |1:
+ | andi TMP0, PC, FRAME_TYPE
+ | bnez TMP0, ->BC_RETV_Z
+ |. xori TMP1, PC, FRAME_VARG
+ |
+ |->BC_RET_Z:
+ | // BASE = base, RA = resultptr, RD = (nresults+1)*8, PC = return
+ | lw INS, -4(PC)
+ | addiu TMP2, BASE, -8
+ | addiu RC, RD, -8
+ | decode_RA8a TMP0, INS
+ | decode_RB8a RB, INS
+ | decode_RA8b TMP0
+ | decode_RB8b RB
+ | addu TMP3, TMP2, RB
+ | beqz RC, >3
+ |. subu BASE, TMP2, TMP0
+ |2:
+ | ldc1 f0, 0(RA)
+ | addiu RA, RA, 8
+ | addiu RC, RC, -8
+ | sdc1 f0, 0(TMP2)
+ | bnez RC, <2
+ |. addiu TMP2, TMP2, 8
+ |3:
+ | addiu TMP3, TMP3, -8
+ |5:
+ | sltu AT, TMP2, TMP3
+ | bnez AT, >6
+ |. lw LFUNC:TMP1, FRAME_FUNC(BASE)
+ | ins_next1
+ | lw TMP1, LFUNC:TMP1->pc
+ | lw KBASE, PC2PROTO(k)(TMP1)
+ | ins_next2
+ |
+ |6: // Fill up results with nil.
+ | sw TISNIL, HI(TMP2)
+ | b <5
+ |. addiu TMP2, TMP2, 8
+ |
+ |->BC_RETV_Z: // Non-standard return case.
+ | andi TMP2, TMP1, FRAME_TYPEP
+ | bnez TMP2, ->vm_return
+ |. nop
+ | // Return from vararg function: relocate BASE down.
+ | subu BASE, BASE, TMP1
+ | b <1
+ |. lw PC, FRAME_PC(BASE)
+ break;
+
+ case BC_RET0: case BC_RET1:
+ | // RA = results*8, RD = (nresults+1)*8
+ | lw PC, FRAME_PC(BASE)
+ | addu RA, BASE, RA
+ | move MULTRES, RD
+ | andi TMP0, PC, FRAME_TYPE
+ | bnez TMP0, ->BC_RETV_Z
+ |. xori TMP1, PC, FRAME_VARG
+ |
+ | lw INS, -4(PC)
+ | addiu TMP2, BASE, -8
+ if (op == BC_RET1) {
+ | ldc1 f0, 0(RA)
+ }
+ | decode_RB8a RB, INS
+ | decode_RA8a RA, INS
+ | decode_RB8b RB
+ | decode_RA8b RA
+ if (op == BC_RET1) {
+ | sdc1 f0, 0(TMP2)
+ }
+ | subu BASE, TMP2, RA
+ |5:
+ | sltu AT, RD, RB
+ | bnez AT, >6
+ |. lw LFUNC:TMP1, FRAME_FUNC(BASE)
+ | ins_next1
+ | lw TMP1, LFUNC:TMP1->pc
+ | lw KBASE, PC2PROTO(k)(TMP1)
+ | ins_next2
+ |
+ |6: // Fill up results with nil.
+ | addiu TMP2, TMP2, 8
+ | addiu RD, RD, 8
+ | b <5
+ if (op == BC_RET1) {
+ |. sw TISNIL, HI(TMP2)
+ } else {
+ |. sw TISNIL, -8+HI(TMP2)
+ }
+ break;
+
+ /* -- Loops and branches ------------------------------------------------ */
+
+ case BC_FORL:
+ |.if JIT
+ | hotloop
+ |.endif
+ | // Fall through. Assumes BC_IFORL follows.
+ break;
+
+ case BC_JFORI:
+ case BC_JFORL:
+#if !LJ_HASJIT
+ break;
+#endif
+ case BC_FORI:
+ case BC_IFORL:
+ | // RA = base*8, RD = target (after end of loop or start of loop)
+ vk = (op == BC_IFORL || op == BC_JFORL);
+ | addu RA, BASE, RA
+ if (vk) {
+ | ldc1 f0, FORL_IDX*8(RA)
+ | ldc1 f4, FORL_STEP*8(RA)
+ | ldc1 f2, FORL_STOP*8(RA)
+ | lw TMP3, FORL_STEP*8+HI(RA)
+ | add.d f0, f0, f4
+ | sdc1 f0, FORL_IDX*8(RA)
+ } else {
+ | lw TMP1, FORL_IDX*8+HI(RA)
+ | lw TMP3, FORL_STEP*8+HI(RA)
+ | lw TMP2, FORL_STOP*8+HI(RA)
+ | sltiu TMP1, TMP1, LJ_TISNUM
+ | sltiu TMP0, TMP3, LJ_TISNUM
+ | sltiu TMP2, TMP2, LJ_TISNUM
+ | and TMP1, TMP1, TMP0
+ | and TMP1, TMP1, TMP2
+ | ldc1 f0, FORL_IDX*8(RA)
+ | beqz TMP1, ->vmeta_for
+ |. ldc1 f2, FORL_STOP*8(RA)
+ }
+ if (op != BC_JFORL) {
+ | srl RD, RD, 1
+ | lui TMP0, (-(BCBIAS_J*4 >> 16) & 65535)
+ }
+ | c.le.d 0, f0, f2
+ | c.le.d 1, f2, f0
+ | sdc1 f0, FORL_EXT*8(RA)
+ if (op == BC_JFORI) {
+ | li TMP1, 1
+ | li TMP2, 1
+ | addu TMP0, RD, TMP0
+ | slt TMP3, TMP3, r0
+ | movf TMP1, r0, 0
+ | addu PC, PC, TMP0
+ | movf TMP2, r0, 1
+ | lhu RD, -4+OFS_RD(PC)
+ | movn TMP1, TMP2, TMP3
+ | bnez TMP1, =>BC_JLOOP
+ |. decode_RD8b RD
+ } else if (op == BC_JFORL) {
+ | li TMP1, 1
+ | li TMP2, 1
+ | slt TMP3, TMP3, r0
+ | movf TMP1, r0, 0
+ | movf TMP2, r0, 1
+ | movn TMP1, TMP2, TMP3
+ | bnez TMP1, =>BC_JLOOP
+ |. nop
+ } else {
+ | addu TMP1, RD, TMP0
+ | slt TMP3, TMP3, r0
+ | move TMP2, TMP1
+ if (op == BC_FORI) {
+ | movt TMP1, r0, 0
+ | movt TMP2, r0, 1
+ } else {
+ | movf TMP1, r0, 0
+ | movf TMP2, r0, 1
+ }
+ | movn TMP1, TMP2, TMP3
+ | addu PC, PC, TMP1
+ }
+ | ins_next
+ break;
+
+ case BC_ITERL:
+ |.if JIT
+ | hotloop
+ |.endif
+ | // Fall through. Assumes BC_IITERL follows.
+ break;
+
+ case BC_JITERL:
+#if !LJ_HASJIT
+ break;
+#endif
+ case BC_IITERL:
+ | // RA = base*8, RD = target
+ | addu RA, BASE, RA
+ | lw TMP1, HI(RA)
+ | beq TMP1, TISNIL, >1 // Stop if iterator returned nil.
+ |. lw TMP2, LO(RA)
+ if (op == BC_JITERL) {
+ | sw TMP1, -8+HI(RA)
+ | b =>BC_JLOOP
+ |. sw TMP2, -8+LO(RA)
+ } else {
+ | branch_RD // Otherwise save control var + branch.
+ | sw TMP1, -8+HI(RA)
+ | sw TMP2, -8+LO(RA)
+ }
+ |1:
+ | ins_next
+ break;
+
+ case BC_LOOP:
+ | // RA = base*8, RD = target (loop extent)
+ | // Note: RA/RD is only used by trace recorder to determine scope/extent
+ | // This opcode does NOT jump, it's only purpose is to detect a hot loop.
+ |.if JIT
+ | hotloop
+ |.endif
+ | // Fall through. Assumes BC_ILOOP follows.
+ break;
+
+ case BC_ILOOP:
+ | // RA = base*8, RD = target (loop extent)
+ | ins_next
+ break;
+
+ case BC_JLOOP:
+ |.if JIT
+ | // RA = base*8 (ignored), RD = traceno*8
+ | lw TMP1, DISPATCH_J(trace)(DISPATCH)
+ | srl RD, RD, 1
+ | li AT, 0
+ | addu TMP1, TMP1, RD
+ | // Traces on MIPS don't store the trace number, so use 0.
+ | sw AT, DISPATCH_GL(vmstate)(DISPATCH)
+ | lw TRACE:TMP2, 0(TMP1)
+ | sw BASE, DISPATCH_GL(jit_base)(DISPATCH)
+ | sw L, DISPATCH_GL(jit_L)(DISPATCH)
+ | lw TMP2, TRACE:TMP2->mcode
+ | jr TMP2
+ |. addiu JGL, DISPATCH, GG_DISP2G+32768
+ |.endif
+ break;
+
+ case BC_JMP:
+ | // RA = base*8 (only used by trace recorder), RD = target
+ | branch_RD
+ | ins_next
+ break;
+
+ /* -- Function headers -------------------------------------------------- */
+
+ case BC_FUNCF:
+ |.if JIT
+ | hotcall
+ |.endif
+ case BC_FUNCV: /* NYI: compiled vararg functions. */
+ | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.
+ break;
+
+ case BC_JFUNCF:
+#if !LJ_HASJIT
+ break;
+#endif
+ case BC_IFUNCF:
+ | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8
+ | lw TMP2, L->maxstack
+ | lbu TMP1, -4+PC2PROTO(numparams)(PC)
+ | lw KBASE, -4+PC2PROTO(k)(PC)
+ | sltu AT, TMP2, RA
+ | bnez AT, ->vm_growstack_l
+ |. sll TMP1, TMP1, 3
+ if (op != BC_JFUNCF) {
+ | ins_next1
+ }
+ |2:
+ | sltu AT, NARGS8:RC, TMP1 // Check for missing parameters.
+ | bnez AT, >3
+ |. addu AT, BASE, NARGS8:RC
+ if (op == BC_JFUNCF) {
+ | decode_RD8a RD, INS
+ | b =>BC_JLOOP
+ |. decode_RD8b RD
+ } else {
+ | ins_next2
+ }
+ |
+ |3: // Clear missing parameters.
+ | sw TISNIL, HI(AT)
+ | b <2
+ |. addiu NARGS8:RC, NARGS8:RC, 8
+ break;
+
+ case BC_JFUNCV:
+#if !LJ_HASJIT
+ break;
+#endif
+ | NYI // NYI: compiled vararg functions
+ break; /* NYI: compiled vararg functions. */
+
+ case BC_IFUNCV:
+ | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8
+ | addu TMP1, BASE, RC
+ | lw TMP2, L->maxstack
+ | addu TMP0, RA, RC
+ | sw LFUNC:RB, LO(TMP1) // Store copy of LFUNC.
+ | addiu TMP3, RC, 8+FRAME_VARG
+ | sltu AT, TMP0, TMP2
+ | lw KBASE, -4+PC2PROTO(k)(PC)
+ | beqz AT, ->vm_growstack_l
+ |. sw TMP3, HI(TMP1) // Store delta + FRAME_VARG.
+ | lbu TMP2, -4+PC2PROTO(numparams)(PC)
+ | move RA, BASE
+ | move RC, TMP1
+ | ins_next1
+ | beqz TMP2, >3
+ |. addiu BASE, TMP1, 8
+ |1:
+ | lw TMP0, HI(RA)
+ | lw TMP3, LO(RA)
+ | sltu AT, RA, RC // Less args than parameters?
+ | move CARG1, TMP0
+ | movz TMP0, TISNIL, AT // Clear missing parameters.
+ | movn CARG1, TISNIL, AT // Clear old fixarg slot (help the GC).
+ | sw TMP3, 8+LO(TMP1)
+ | addiu TMP2, TMP2, -1
+ | sw TMP0, 8+HI(TMP1)
+ | addiu TMP1, TMP1, 8
+ | sw CARG1, HI(RA)
+ | bnez TMP2, <1
+ |. addiu RA, RA, 8
+ |3:
+ | ins_next2
+ break;
+
+ case BC_FUNCC:
+ case BC_FUNCCW:
+ | // BASE = new base, RA = BASE+framesize*8, RB = CFUNC, RC = nargs*8
+ if (op == BC_FUNCC) {
+ | lw CFUNCADDR, CFUNC:RB->f
+ } else {
+ | lw CFUNCADDR, DISPATCH_GL(wrapf)(DISPATCH)
+ }
+ | addu TMP1, RA, NARGS8:RC
+ | lw TMP2, L->maxstack
+ | addu RC, BASE, NARGS8:RC
+ | sw BASE, L->base
+ | sltu AT, TMP2, TMP1
+ | sw RC, L->top
+ | li_vmstate C
+ if (op == BC_FUNCCW) {
+ | lw CARG2, CFUNC:RB->f
+ }
+ | bnez AT, ->vm_growstack_c // Need to grow stack.
+ |. move CARG1, L
+ | jalr CFUNCADDR // (lua_State *L [, lua_CFunction f])
+ |. st_vmstate
+ | // Returns nresults.
+ | lw BASE, L->base
+ | sll RD, CRET1, 3
+ | lw TMP1, L->top
+ | li_vmstate INTERP
+ | lw PC, FRAME_PC(BASE) // Fetch PC of caller.
+ | subu RA, TMP1, RD // RA = L->top - nresults*8
+ | b ->vm_returnc
+ |. st_vmstate
+ break;
+
+ /* ---------------------------------------------------------------------- */
+
+ default:
+ fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]);
+ exit(2);
+ break;
+ }
+}
+
+static int build_backend(BuildCtx *ctx)
+{
+ int op;
+
+ dasm_growpc(Dst, BC__MAX);
+
+ build_subroutines(ctx);
+
+ |.code_op
+ for (op = 0; op < BC__MAX; op++)
+ build_ins(ctx, (BCOp)op, op);
+
+ return BC__MAX;
+}
+
+/* Emit pseudo frame-info for all assembler functions. */
+static void emit_asm_debug(BuildCtx *ctx)
+{
+ int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);
+ int i;
+ switch (ctx->mode) {
+ case BUILD_elfasm:
+ fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n");
+ fprintf(ctx->fp,
+ ".Lframe0:\n"
+ "\t.4byte .LECIE0-.LSCIE0\n"
+ ".LSCIE0:\n"
+ "\t.4byte 0xffffffff\n"
+ "\t.byte 0x1\n"
+ "\t.string \"\"\n"
+ "\t.uleb128 0x1\n"
+ "\t.sleb128 -4\n"
+ "\t.byte 31\n"
+ "\t.byte 0xc\n\t.uleb128 29\n\t.uleb128 0\n"
+ "\t.align 2\n"
+ ".LECIE0:\n\n");
+ fprintf(ctx->fp,
+ ".LSFDE0:\n"
+ "\t.4byte .LEFDE0-.LASFDE0\n"
+ ".LASFDE0:\n"
+ "\t.4byte .Lframe0\n"
+ "\t.4byte .Lbegin\n"
+ "\t.4byte %d\n"
+ "\t.byte 0xe\n\t.uleb128 %d\n"
+ "\t.byte 0x9f\n\t.sleb128 1\n"
+ "\t.byte 0x9e\n\t.sleb128 2\n",
+ fcofs, CFRAME_SIZE);
+ for (i = 23; i >= 16; i--)
+ fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 26-i);
+ for (i = 30; i >= 20; i -= 2)
+ fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+32+i, 42-i);
+ fprintf(ctx->fp,
+ "\t.align 2\n"
+ ".LEFDE0:\n\n");
+#if LJ_HASFFI
+ fprintf(ctx->fp,
+ ".LSFDE1:\n"
+ "\t.4byte .LEFDE1-.LASFDE1\n"
+ ".LASFDE1:\n"
+ "\t.4byte .Lframe0\n"
+ "\t.4byte lj_vm_ffi_call\n"
+ "\t.4byte %d\n"
+ "\t.byte 0x9f\n\t.uleb128 1\n"
+ "\t.byte 0x90\n\t.uleb128 2\n"
+ "\t.byte 0xd\n\t.uleb128 0x10\n"
+ "\t.align 2\n"
+ ".LEFDE1:\n\n", (int)ctx->codesz - fcofs);
+#endif
+#if !LJ_NO_UNWIND
+ fprintf(ctx->fp, "\t.section .eh_frame,\"aw\",@progbits\n");
+ fprintf(ctx->fp,
+ "\t.globl lj_err_unwind_dwarf\n"
+ ".Lframe1:\n"
+ "\t.4byte .LECIE1-.LSCIE1\n"
+ ".LSCIE1:\n"
+ "\t.4byte 0\n"
+ "\t.byte 0x1\n"
+ "\t.string \"zPR\"\n"
+ "\t.uleb128 0x1\n"
+ "\t.sleb128 -4\n"
+ "\t.byte 31\n"
+ "\t.uleb128 6\n" /* augmentation length */
+ "\t.byte 0\n"
+ "\t.4byte lj_err_unwind_dwarf\n"
+ "\t.byte 0\n"
+ "\t.byte 0xc\n\t.uleb128 29\n\t.uleb128 0\n"
+ "\t.align 2\n"
+ ".LECIE1:\n\n");
+ fprintf(ctx->fp,
+ ".LSFDE2:\n"
+ "\t.4byte .LEFDE2-.LASFDE2\n"
+ ".LASFDE2:\n"
+ "\t.4byte .LASFDE2-.Lframe1\n"
+ "\t.4byte .Lbegin\n"
+ "\t.4byte %d\n"
+ "\t.uleb128 0\n" /* augmentation length */
+ "\t.byte 0xe\n\t.uleb128 %d\n"
+ "\t.byte 0x9f\n\t.sleb128 1\n"
+ "\t.byte 0x9e\n\t.sleb128 2\n",
+ fcofs, CFRAME_SIZE);
+ for (i = 23; i >= 16; i--)
+ fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 26-i);
+ for (i = 30; i >= 20; i -= 2)
+ fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+32+i, 42-i);
+ fprintf(ctx->fp,
+ "\t.align 2\n"
+ ".LEFDE2:\n\n");
+#if LJ_HASFFI
+ fprintf(ctx->fp,
+ ".Lframe2:\n"
+ "\t.4byte .LECIE2-.LSCIE2\n"
+ ".LSCIE2:\n"
+ "\t.4byte 0\n"
+ "\t.byte 0x1\n"
+ "\t.string \"zR\"\n"
+ "\t.uleb128 0x1\n"
+ "\t.sleb128 -4\n"
+ "\t.byte 31\n"
+ "\t.uleb128 1\n" /* augmentation length */
+ "\t.byte 0\n"
+ "\t.byte 0xc\n\t.uleb128 29\n\t.uleb128 0\n"
+ "\t.align 2\n"
+ ".LECIE2:\n\n");
+ fprintf(ctx->fp,
+ ".LSFDE3:\n"
+ "\t.4byte .LEFDE3-.LASFDE3\n"
+ ".LASFDE3:\n"
+ "\t.4byte .LASFDE3-.Lframe2\n"
+ "\t.4byte lj_vm_ffi_call\n"
+ "\t.4byte %d\n"
+ "\t.uleb128 0\n" /* augmentation length */
+ "\t.byte 0x9f\n\t.uleb128 1\n"
+ "\t.byte 0x90\n\t.uleb128 2\n"
+ "\t.byte 0xd\n\t.uleb128 0x10\n"
+ "\t.align 2\n"
+ ".LEFDE3:\n\n", (int)ctx->codesz - fcofs);
+#endif
+#endif
+ break;
+ default:
+ break;
+ }
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/vm_ppc.dasc b/src/3rdparty/LuaJIT-2.0.5/src/vm_ppc.dasc
new file mode 100644
index 0000000..91f5003
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/vm_ppc.dasc
@@ -0,0 +1,5160 @@
+|// Low-level VM code for PowerPC CPUs.
+|// Bytecode interpreter, fast functions and helper functions.
+|// Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+|
+|.arch ppc
+|.section code_op, code_sub
+|
+|.actionlist build_actionlist
+|.globals GLOB_
+|.globalnames globnames
+|.externnames extnames
+|
+|// Note: The ragged indentation of the instructions is intentional.
+|// The starting columns indicate data dependencies.
+|
+|//-----------------------------------------------------------------------
+|
+|// DynASM defines used by the PPC port:
+|//
+|// P64 64 bit pointers (only for GPR64 testing).
+|// Note: a full PPC64 _LP64 port is not planned.
+|// GPR64 64 bit registers (but possibly 32 bit pointers, e.g. PS3).
+|// Affects reg saves, stack layout, carry/overflow/dot flags etc.
+|// FRAME32 Use 32 bit frame layout, even with GPR64 (Xbox 360).
+|// TOC Need table of contents (64 bit or 32 bit variant, e.g. PS3).
+|// Function pointers are really a struct: code, TOC, env (optional).
+|// TOCENV Function pointers have an environment pointer, too (not on PS3).
+|// PPE Power Processor Element of Cell (PS3) or Xenon (Xbox 360).
+|// Must avoid (slow) micro-coded instructions.
+|
+|.if P64
+|.define TOC, 1
+|.define TOCENV, 1
+|.macro lpx, a, b, c; ldx a, b, c; .endmacro
+|.macro lp, a, b; ld a, b; .endmacro
+|.macro stp, a, b; std a, b; .endmacro
+|.define decode_OPP, decode_OP8
+|.if FFI
+|// Missing: Calling conventions, 64 bit regs, TOC.
+|.error lib_ffi not yet implemented for PPC64
+|.endif
+|.else
+|.macro lpx, a, b, c; lwzx a, b, c; .endmacro
+|.macro lp, a, b; lwz a, b; .endmacro
+|.macro stp, a, b; stw a, b; .endmacro
+|.define decode_OPP, decode_OP4
+|.endif
+|
+|// Convenience macros for TOC handling.
+|.if TOC
+|// Linker needs a TOC patch area for every external call relocation.
+|.macro blex, target; bl extern target@plt; nop; .endmacro
+|.macro .toc, a, b; a, b; .endmacro
+|.if P64
+|.define TOC_OFS, 8
+|.define ENV_OFS, 16
+|.else
+|.define TOC_OFS, 4
+|.define ENV_OFS, 8
+|.endif
+|.else // No TOC.
+|.macro blex, target; bl extern target@plt; .endmacro
+|.macro .toc, a, b; .endmacro
+|.endif
+|.macro .tocenv, a, b; .if TOCENV; a, b; .endif; .endmacro
+|
+|.macro .gpr64, a, b; .if GPR64; a, b; .endif; .endmacro
+|
+|.macro andix., y, a, i
+|.if PPE
+| rlwinm y, a, 0, 31-lj_fls(i), 31-lj_ffs(i)
+| cmpwi y, 0
+|.else
+| andi. y, a, i
+|.endif
+|.endmacro
+|
+|.macro clrso, reg
+|.if PPE
+| li reg, 0
+| mtxer reg
+|.else
+| mcrxr cr0
+|.endif
+|.endmacro
+|
+|.macro checkov, reg, noov
+|.if PPE
+| mfxer reg
+| add reg, reg, reg
+| cmpwi reg, 0
+| li reg, 0
+| mtxer reg
+| bgey noov
+|.else
+| mcrxr cr0
+| bley noov
+|.endif
+|.endmacro
+|
+|//-----------------------------------------------------------------------
+|
+|// Fixed register assignments for the interpreter.
+|// Don't use: r1 = sp, r2 and r13 = reserved (TOC, TLS or SDATA)
+|
+|// The following must be C callee-save (but BASE is often refetched).
+|.define BASE, r14 // Base of current Lua stack frame.
+|.define KBASE, r15 // Constants of current Lua function.
+|.define PC, r16 // Next PC.
+|.define DISPATCH, r17 // Opcode dispatch table.
+|.define LREG, r18 // Register holding lua_State (also in SAVE_L).
+|.define MULTRES, r19 // Size of multi-result: (nresults+1)*8.
+|.define JGL, r31 // On-trace: global_State + 32768.
+|
+|// Constants for type-comparisons, stores and conversions. C callee-save.
+|.define TISNUM, r22
+|.define TISNIL, r23
+|.define ZERO, r24
+|.define TOBIT, f30 // 2^52 + 2^51.
+|.define TONUM, f31 // 2^52 + 2^51 + 2^31.
+|
+|// The following temporaries are not saved across C calls, except for RA.
+|.define RA, r20 // Callee-save.
+|.define RB, r10
+|.define RC, r11
+|.define RD, r12
+|.define INS, r7 // Overlaps CARG5.
+|
+|.define TMP0, r0
+|.define TMP1, r8
+|.define TMP2, r9
+|.define TMP3, r6 // Overlaps CARG4.
+|
+|// Saved temporaries.
+|.define SAVE0, r21
+|
+|// Calling conventions.
+|.define CARG1, r3
+|.define CARG2, r4
+|.define CARG3, r5
+|.define CARG4, r6 // Overlaps TMP3.
+|.define CARG5, r7 // Overlaps INS.
+|
+|.define FARG1, f1
+|.define FARG2, f2
+|
+|.define CRET1, r3
+|.define CRET2, r4
+|
+|.define TOCREG, r2 // TOC register (only used by C code).
+|.define ENVREG, r11 // Environment pointer (nested C functions).
+|
+|// Stack layout while in interpreter. Must match with lj_frame.h.
+|.if GPR64
+|.if FRAME32
+|
+|// 456(sp) // \ 32/64 bit C frame info
+|.define TONUM_LO, 452(sp) // |
+|.define TONUM_HI, 448(sp) // |
+|.define TMPD_LO, 444(sp) // |
+|.define TMPD_HI, 440(sp) // |
+|.define SAVE_CR, 432(sp) // | 64 bit CR save.
+|.define SAVE_ERRF, 424(sp) // > Parameter save area.
+|.define SAVE_NRES, 420(sp) // |
+|.define SAVE_L, 416(sp) // |
+|.define SAVE_PC, 412(sp) // |
+|.define SAVE_MULTRES, 408(sp) // |
+|.define SAVE_CFRAME, 400(sp) // / 64 bit C frame chain.
+|// 392(sp) // Reserved.
+|.define CFRAME_SPACE, 384 // Delta for sp.
+|// Back chain for sp: 384(sp) <-- sp entering interpreter
+|.define SAVE_LR, 376(sp) // 32 bit LR stored in hi-part.
+|.define SAVE_GPR_, 232 // .. 232+18*8: 64 bit GPR saves.
+|.define SAVE_FPR_, 88 // .. 88+18*8: 64 bit FPR saves.
+|// 80(sp) // Needed for 16 byte stack frame alignment.
+|// 16(sp) // Callee parameter save area (ABI mandated).
+|// 8(sp) // Reserved
+|// Back chain for sp: 0(sp) <-- sp while in interpreter
+|// 32 bit sp stored in hi-part of 0(sp).
+|
+|.define TMPD_BLO, 447(sp)
+|.define TMPD, TMPD_HI
+|.define TONUM_D, TONUM_HI
+|
+|.else
+|
+|// 508(sp) // \ 32 bit C frame info.
+|.define SAVE_ERRF, 472(sp) // |
+|.define SAVE_NRES, 468(sp) // |
+|.define SAVE_L, 464(sp) // > Parameter save area.
+|.define SAVE_PC, 460(sp) // |
+|.define SAVE_MULTRES, 456(sp) // |
+|.define SAVE_CFRAME, 448(sp) // / 64 bit C frame chain.
+|.define SAVE_LR, 416(sp)
+|.define CFRAME_SPACE, 400 // Delta for sp.
+|// Back chain for sp: 400(sp) <-- sp entering interpreter
+|.define SAVE_FPR_, 256 // .. 256+18*8: 64 bit FPR saves.
+|.define SAVE_GPR_, 112 // .. 112+18*8: 64 bit GPR saves.
+|// 48(sp) // Callee parameter save area (ABI mandated).
+|.define SAVE_TOC, 40(sp) // TOC save area.
+|.define TMPD_LO, 36(sp) // \ Link editor temp (ABI mandated).
+|.define TMPD_HI, 32(sp) // /
+|.define TONUM_LO, 28(sp) // \ Compiler temp (ABI mandated).
+|.define TONUM_HI, 24(sp) // /
+|// Next frame lr: 16(sp)
+|.define SAVE_CR, 8(sp) // 64 bit CR save.
+|// Back chain for sp: 0(sp) <-- sp while in interpreter
+|
+|.define TMPD_BLO, 39(sp)
+|.define TMPD, TMPD_HI
+|.define TONUM_D, TONUM_HI
+|
+|.endif
+|.else
+|
+|.define SAVE_LR, 276(sp)
+|.define CFRAME_SPACE, 272 // Delta for sp.
+|// Back chain for sp: 272(sp) <-- sp entering interpreter
+|.define SAVE_FPR_, 128 // .. 128+18*8: 64 bit FPR saves.
+|.define SAVE_GPR_, 56 // .. 56+18*4: 32 bit GPR saves.
+|.define SAVE_CR, 52(sp) // 32 bit CR save.
+|.define SAVE_ERRF, 48(sp) // 32 bit C frame info.
+|.define SAVE_NRES, 44(sp)
+|.define SAVE_CFRAME, 40(sp)
+|.define SAVE_L, 36(sp)
+|.define SAVE_PC, 32(sp)
+|.define SAVE_MULTRES, 28(sp)
+|.define UNUSED1, 24(sp)
+|.define TMPD_LO, 20(sp)
+|.define TMPD_HI, 16(sp)
+|.define TONUM_LO, 12(sp)
+|.define TONUM_HI, 8(sp)
+|// Next frame lr: 4(sp)
+|// Back chain for sp: 0(sp) <-- sp while in interpreter
+|
+|.define TMPD_BLO, 23(sp)
+|.define TMPD, TMPD_HI
+|.define TONUM_D, TONUM_HI
+|
+|.endif
+|
+|.macro save_, reg
+|.if GPR64
+| std r..reg, SAVE_GPR_+(reg-14)*8(sp)
+|.else
+| stw r..reg, SAVE_GPR_+(reg-14)*4(sp)
+|.endif
+| stfd f..reg, SAVE_FPR_+(reg-14)*8(sp)
+|.endmacro
+|.macro rest_, reg
+|.if GPR64
+| ld r..reg, SAVE_GPR_+(reg-14)*8(sp)
+|.else
+| lwz r..reg, SAVE_GPR_+(reg-14)*4(sp)
+|.endif
+| lfd f..reg, SAVE_FPR_+(reg-14)*8(sp)
+|.endmacro
+|
+|.macro saveregs
+|.if GPR64 and not FRAME32
+| stdu sp, -CFRAME_SPACE(sp)
+|.else
+| stwu sp, -CFRAME_SPACE(sp)
+|.endif
+| save_ 14; save_ 15; save_ 16
+| mflr r0
+| save_ 17; save_ 18; save_ 19; save_ 20; save_ 21; save_ 22
+|.if GPR64 and not FRAME32
+| std r0, SAVE_LR
+|.else
+| stw r0, SAVE_LR
+|.endif
+| save_ 23; save_ 24; save_ 25
+| mfcr r0
+| save_ 26; save_ 27; save_ 28; save_ 29; save_ 30; save_ 31
+|.if GPR64
+| std r0, SAVE_CR
+|.else
+| stw r0, SAVE_CR
+|.endif
+| .toc std TOCREG, SAVE_TOC
+|.endmacro
+|
+|.macro restoreregs
+|.if GPR64 and not FRAME32
+| ld r0, SAVE_LR
+|.else
+| lwz r0, SAVE_LR
+|.endif
+|.if GPR64
+| ld r12, SAVE_CR
+|.else
+| lwz r12, SAVE_CR
+|.endif
+| rest_ 14; rest_ 15; rest_ 16; rest_ 17; rest_ 18; rest_ 19
+| mtlr r0;
+|.if PPE; mtocrf 0x20, r12; .else; mtcrf 0x38, r12; .endif
+| rest_ 20; rest_ 21; rest_ 22; rest_ 23; rest_ 24; rest_ 25
+|.if PPE; mtocrf 0x10, r12; .endif
+| rest_ 26; rest_ 27; rest_ 28; rest_ 29; rest_ 30; rest_ 31
+|.if PPE; mtocrf 0x08, r12; .endif
+| addi sp, sp, CFRAME_SPACE
+|.endmacro
+|
+|// Type definitions. Some of these are only used for documentation.
+|.type L, lua_State, LREG
+|.type GL, global_State
+|.type TVALUE, TValue
+|.type GCOBJ, GCobj
+|.type STR, GCstr
+|.type TAB, GCtab
+|.type LFUNC, GCfuncL
+|.type CFUNC, GCfuncC
+|.type PROTO, GCproto
+|.type UPVAL, GCupval
+|.type NODE, Node
+|.type NARGS8, int
+|.type TRACE, GCtrace
+|
+|//-----------------------------------------------------------------------
+|
+|// These basic macros should really be part of DynASM.
+|.macro srwi, rx, ry, n; rlwinm rx, ry, 32-n, n, 31; .endmacro
+|.macro slwi, rx, ry, n; rlwinm rx, ry, n, 0, 31-n; .endmacro
+|.macro rotlwi, rx, ry, n; rlwinm rx, ry, n, 0, 31; .endmacro
+|.macro rotlw, rx, ry, rn; rlwnm rx, ry, rn, 0, 31; .endmacro
+|.macro subi, rx, ry, i; addi rx, ry, -i; .endmacro
+|
+|// Trap for not-yet-implemented parts.
+|.macro NYI; tw 4, sp, sp; .endmacro
+|
+|// int/FP conversions.
+|.macro tonum_i, freg, reg
+| xoris reg, reg, 0x8000
+| stw reg, TONUM_LO
+| lfd freg, TONUM_D
+| fsub freg, freg, TONUM
+|.endmacro
+|
+|.macro tonum_u, freg, reg
+| stw reg, TONUM_LO
+| lfd freg, TONUM_D
+| fsub freg, freg, TOBIT
+|.endmacro
+|
+|.macro toint, reg, freg, tmpfreg
+| fctiwz tmpfreg, freg
+| stfd tmpfreg, TMPD
+| lwz reg, TMPD_LO
+|.endmacro
+|
+|.macro toint, reg, freg
+| toint reg, freg, freg
+|.endmacro
+|
+|//-----------------------------------------------------------------------
+|
+|// Access to frame relative to BASE.
+|.define FRAME_PC, -8
+|.define FRAME_FUNC, -4
+|
+|// Instruction decode.
+|.macro decode_OP4, dst, ins; rlwinm dst, ins, 2, 22, 29; .endmacro
+|.macro decode_OP8, dst, ins; rlwinm dst, ins, 3, 21, 28; .endmacro
+|.macro decode_RA8, dst, ins; rlwinm dst, ins, 27, 21, 28; .endmacro
+|.macro decode_RB8, dst, ins; rlwinm dst, ins, 11, 21, 28; .endmacro
+|.macro decode_RC8, dst, ins; rlwinm dst, ins, 19, 21, 28; .endmacro
+|.macro decode_RD8, dst, ins; rlwinm dst, ins, 19, 13, 28; .endmacro
+|
+|.macro decode_OP1, dst, ins; rlwinm dst, ins, 0, 24, 31; .endmacro
+|.macro decode_RD4, dst, ins; rlwinm dst, ins, 18, 14, 29; .endmacro
+|
+|// Instruction fetch.
+|.macro ins_NEXT1
+| lwz INS, 0(PC)
+| addi PC, PC, 4
+|.endmacro
+|// Instruction decode+dispatch. Note: optimized for e300!
+|.macro ins_NEXT2
+| decode_OPP TMP1, INS
+| lpx TMP0, DISPATCH, TMP1
+| mtctr TMP0
+| decode_RB8 RB, INS
+| decode_RD8 RD, INS
+| decode_RA8 RA, INS
+| decode_RC8 RC, INS
+| bctr
+|.endmacro
+|.macro ins_NEXT
+| ins_NEXT1
+| ins_NEXT2
+|.endmacro
+|
+|// Instruction footer.
+|.if 1
+| // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.
+| .define ins_next, ins_NEXT
+| .define ins_next_, ins_NEXT
+| .define ins_next1, ins_NEXT1
+| .define ins_next2, ins_NEXT2
+|.else
+| // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.
+| // Affects only certain kinds of benchmarks (and only with -j off).
+| .macro ins_next
+| b ->ins_next
+| .endmacro
+| .macro ins_next1
+| .endmacro
+| .macro ins_next2
+| b ->ins_next
+| .endmacro
+| .macro ins_next_
+| ->ins_next:
+| ins_NEXT
+| .endmacro
+|.endif
+|
+|// Call decode and dispatch.
+|.macro ins_callt
+| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC
+| lwz PC, LFUNC:RB->pc
+| lwz INS, 0(PC)
+| addi PC, PC, 4
+| decode_OPP TMP1, INS
+| decode_RA8 RA, INS
+| lpx TMP0, DISPATCH, TMP1
+| add RA, RA, BASE
+| mtctr TMP0
+| bctr
+|.endmacro
+|
+|.macro ins_call
+| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, PC = caller PC
+| stw PC, FRAME_PC(BASE)
+| ins_callt
+|.endmacro
+|
+|//-----------------------------------------------------------------------
+|
+|// Macros to test operand types.
+|.macro checknum, reg; cmplw reg, TISNUM; .endmacro
+|.macro checknum, cr, reg; cmplw cr, reg, TISNUM; .endmacro
+|.macro checkstr, reg; cmpwi reg, LJ_TSTR; .endmacro
+|.macro checktab, reg; cmpwi reg, LJ_TTAB; .endmacro
+|.macro checkfunc, reg; cmpwi reg, LJ_TFUNC; .endmacro
+|.macro checknil, reg; cmpwi reg, LJ_TNIL; .endmacro
+|
+|.macro branch_RD
+| srwi TMP0, RD, 1
+| addis PC, PC, -(BCBIAS_J*4 >> 16)
+| add PC, PC, TMP0
+|.endmacro
+|
+|// Assumes DISPATCH is relative to GL.
+#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field))
+#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field))
+|
+#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
+|
+|.macro hotcheck, delta, target
+| rlwinm TMP1, PC, 31, 25, 30
+| addi TMP1, TMP1, GG_DISP2HOT
+| lhzx TMP2, DISPATCH, TMP1
+| addic. TMP2, TMP2, -delta
+| sthx TMP2, DISPATCH, TMP1
+| blt target
+|.endmacro
+|
+|.macro hotloop
+| hotcheck HOTCOUNT_LOOP, ->vm_hotloop
+|.endmacro
+|
+|.macro hotcall
+| hotcheck HOTCOUNT_CALL, ->vm_hotcall
+|.endmacro
+|
+|// Set current VM state. Uses TMP0.
+|.macro li_vmstate, st; li TMP0, ~LJ_VMST_..st; .endmacro
+|.macro st_vmstate; stw TMP0, DISPATCH_GL(vmstate)(DISPATCH); .endmacro
+|
+|// Move table write barrier back. Overwrites mark and tmp.
+|.macro barrierback, tab, mark, tmp
+| lwz tmp, DISPATCH_GL(gc.grayagain)(DISPATCH)
+| // Assumes LJ_GC_BLACK is 0x04.
+| rlwinm mark, mark, 0, 30, 28 // black2gray(tab)
+| stw tab, DISPATCH_GL(gc.grayagain)(DISPATCH)
+| stb mark, tab->marked
+| stw tmp, tab->gclist
+|.endmacro
+|
+|//-----------------------------------------------------------------------
+
+/* Generate subroutines used by opcodes and other parts of the VM. */
+/* The .code_sub section should be last to help static branch prediction. */
+static void build_subroutines(BuildCtx *ctx)
+{
+ |.code_sub
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Return handling ----------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_returnp:
+ | // See vm_return. Also: TMP2 = previous base.
+ | andix. TMP0, PC, FRAME_P
+ | li TMP1, LJ_TTRUE
+ | beq ->cont_dispatch
+ |
+ | // Return from pcall or xpcall fast func.
+ | lwz PC, FRAME_PC(TMP2) // Fetch PC of previous frame.
+ | mr BASE, TMP2 // Restore caller base.
+ | // Prepending may overwrite the pcall frame, so do it at the end.
+ | stwu TMP1, FRAME_PC(RA) // Prepend true to results.
+ |
+ |->vm_returnc:
+ | addi RD, RD, 8 // RD = (nresults+1)*8.
+ | andix. TMP0, PC, FRAME_TYPE
+ | cmpwi cr1, RD, 0
+ | li CRET1, LUA_YIELD
+ | beq cr1, ->vm_unwind_c_eh
+ | mr MULTRES, RD
+ | beq ->BC_RET_Z // Handle regular return to Lua.
+ |
+ |->vm_return:
+ | // BASE = base, RA = resultptr, RD/MULTRES = (nresults+1)*8, PC = return
+ | // TMP0 = PC & FRAME_TYPE
+ | cmpwi TMP0, FRAME_C
+ | rlwinm TMP2, PC, 0, 0, 28
+ | li_vmstate C
+ | sub TMP2, BASE, TMP2 // TMP2 = previous base.
+ | bney ->vm_returnp
+ |
+ | addic. TMP1, RD, -8
+ | stp TMP2, L->base
+ | lwz TMP2, SAVE_NRES
+ | subi BASE, BASE, 8
+ | st_vmstate
+ | slwi TMP2, TMP2, 3
+ | beq >2
+ |1:
+ | addic. TMP1, TMP1, -8
+ | lfd f0, 0(RA)
+ | addi RA, RA, 8
+ | stfd f0, 0(BASE)
+ | addi BASE, BASE, 8
+ | bney <1
+ |
+ |2:
+ | cmpw TMP2, RD // More/less results wanted?
+ | bne >6
+ |3:
+ | stp BASE, L->top // Store new top.
+ |
+ |->vm_leave_cp:
+ | lp TMP0, SAVE_CFRAME // Restore previous C frame.
+ | li CRET1, 0 // Ok return status for vm_pcall.
+ | stp TMP0, L->cframe
+ |
+ |->vm_leave_unw:
+ | restoreregs
+ | blr
+ |
+ |6:
+ | ble >7 // Less results wanted?
+ | // More results wanted. Check stack size and fill up results with nil.
+ | lwz TMP1, L->maxstack
+ | cmplw BASE, TMP1
+ | bge >8
+ | stw TISNIL, 0(BASE)
+ | addi RD, RD, 8
+ | addi BASE, BASE, 8
+ | b <2
+ |
+ |7: // Less results wanted.
+ | subfic TMP3, TMP2, 0 // LUA_MULTRET+1 case?
+ | sub TMP0, RD, TMP2
+ | subfe TMP1, TMP1, TMP1 // TMP1 = TMP2 == 0 ? 0 : -1
+ | and TMP0, TMP0, TMP1
+ | sub BASE, BASE, TMP0 // Either keep top or shrink it.
+ | b <3
+ |
+ |8: // Corner case: need to grow stack for filling up results.
+ | // This can happen if:
+ | // - A C function grows the stack (a lot).
+ | // - The GC shrinks the stack in between.
+ | // - A return back from a lua_call() with (high) nresults adjustment.
+ | stp BASE, L->top // Save current top held in BASE (yes).
+ | mr SAVE0, RD
+ | srwi CARG2, TMP2, 3
+ | mr CARG1, L
+ | bl extern lj_state_growstack // (lua_State *L, int n)
+ | lwz TMP2, SAVE_NRES
+ | mr RD, SAVE0
+ | slwi TMP2, TMP2, 3
+ | lp BASE, L->top // Need the (realloced) L->top in BASE.
+ | b <2
+ |
+ |->vm_unwind_c: // Unwind C stack, return from vm_pcall.
+ | // (void *cframe, int errcode)
+ | mr sp, CARG1
+ | mr CRET1, CARG2
+ |->vm_unwind_c_eh: // Landing pad for external unwinder.
+ | lwz L, SAVE_L
+ | .toc ld TOCREG, SAVE_TOC
+ | li TMP0, ~LJ_VMST_C
+ | lwz GL:TMP1, L->glref
+ | stw TMP0, GL:TMP1->vmstate
+ | b ->vm_leave_unw
+ |
+ |->vm_unwind_ff: // Unwind C stack, return from ff pcall.
+ | // (void *cframe)
+ |.if GPR64
+ | rldicr sp, CARG1, 0, 61
+ |.else
+ | rlwinm sp, CARG1, 0, 0, 29
+ |.endif
+ |->vm_unwind_ff_eh: // Landing pad for external unwinder.
+ | lwz L, SAVE_L
+ | .toc ld TOCREG, SAVE_TOC
+ | li TISNUM, LJ_TISNUM // Setup type comparison constants.
+ | lp BASE, L->base
+ | lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
+ | lwz DISPATCH, L->glref // Setup pointer to dispatch table.
+ | li ZERO, 0
+ | stw TMP3, TMPD
+ | li TMP1, LJ_TFALSE
+ | ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float).
+ | li TISNIL, LJ_TNIL
+ | li_vmstate INTERP
+ | lfs TOBIT, TMPD
+ | lwz PC, FRAME_PC(BASE) // Fetch PC of previous frame.
+ | la RA, -8(BASE) // Results start at BASE-8.
+ | stw TMP3, TMPD
+ | addi DISPATCH, DISPATCH, GG_G2DISP
+ | stw TMP1, 0(RA) // Prepend false to error message.
+ | li RD, 16 // 2 results: false + error message.
+ | st_vmstate
+ | lfs TONUM, TMPD
+ | b ->vm_returnc
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Grow stack for calls -----------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_growstack_c: // Grow stack for C function.
+ | li CARG2, LUA_MINSTACK
+ | b >2
+ |
+ |->vm_growstack_l: // Grow stack for Lua function.
+ | // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC
+ | add RC, BASE, RC
+ | sub RA, RA, BASE
+ | stp BASE, L->base
+ | addi PC, PC, 4 // Must point after first instruction.
+ | stp RC, L->top
+ | srwi CARG2, RA, 3
+ |2:
+ | // L->base = new base, L->top = top
+ | stw PC, SAVE_PC
+ | mr CARG1, L
+ | bl extern lj_state_growstack // (lua_State *L, int n)
+ | lp BASE, L->base
+ | lp RC, L->top
+ | lwz LFUNC:RB, FRAME_FUNC(BASE)
+ | sub RC, RC, BASE
+ | // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC
+ | ins_callt // Just retry the call.
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Entry points into the assembler VM ---------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_resume: // Setup C frame and resume thread.
+ | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)
+ | saveregs
+ | mr L, CARG1
+ | lwz DISPATCH, L->glref // Setup pointer to dispatch table.
+ | mr BASE, CARG2
+ | lbz TMP1, L->status
+ | stw L, SAVE_L
+ | li PC, FRAME_CP
+ | addi TMP0, sp, CFRAME_RESUME
+ | addi DISPATCH, DISPATCH, GG_G2DISP
+ | stw CARG3, SAVE_NRES
+ | cmplwi TMP1, 0
+ | stw CARG3, SAVE_ERRF
+ | stp TMP0, L->cframe
+ | stp CARG3, SAVE_CFRAME
+ | stw CARG1, SAVE_PC // Any value outside of bytecode is ok.
+ | beq >3
+ |
+ | // Resume after yield (like a return).
+ | mr RA, BASE
+ | lp BASE, L->base
+ | li TISNUM, LJ_TISNUM // Setup type comparison constants.
+ | lp TMP1, L->top
+ | lwz PC, FRAME_PC(BASE)
+ | lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
+ | stb CARG3, L->status
+ | stw TMP3, TMPD
+ | ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float).
+ | lfs TOBIT, TMPD
+ | sub RD, TMP1, BASE
+ | stw TMP3, TMPD
+ | lus TMP0, 0x4338 // Hiword of 2^52 + 2^51 (double)
+ | addi RD, RD, 8
+ | stw TMP0, TONUM_HI
+ | li_vmstate INTERP
+ | li ZERO, 0
+ | st_vmstate
+ | andix. TMP0, PC, FRAME_TYPE
+ | mr MULTRES, RD
+ | lfs TONUM, TMPD
+ | li TISNIL, LJ_TNIL
+ | beq ->BC_RET_Z
+ | b ->vm_return
+ |
+ |->vm_pcall: // Setup protected C frame and enter VM.
+ | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)
+ | saveregs
+ | li PC, FRAME_CP
+ | stw CARG4, SAVE_ERRF
+ | b >1
+ |
+ |->vm_call: // Setup C frame and enter VM.
+ | // (lua_State *L, TValue *base, int nres1)
+ | saveregs
+ | li PC, FRAME_C
+ |
+ |1: // Entry point for vm_pcall above (PC = ftype).
+ | lp TMP1, L:CARG1->cframe
+ | stw CARG3, SAVE_NRES
+ | mr L, CARG1
+ | stw CARG1, SAVE_L
+ | mr BASE, CARG2
+ | stp sp, L->cframe // Add our C frame to cframe chain.
+ | lwz DISPATCH, L->glref // Setup pointer to dispatch table.
+ | stw CARG1, SAVE_PC // Any value outside of bytecode is ok.
+ | stp TMP1, SAVE_CFRAME
+ | addi DISPATCH, DISPATCH, GG_G2DISP
+ |
+ |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).
+ | lp TMP2, L->base // TMP2 = old base (used in vmeta_call).
+ | li TISNUM, LJ_TISNUM // Setup type comparison constants.
+ | lp TMP1, L->top
+ | lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
+ | add PC, PC, BASE
+ | stw TMP3, TMPD
+ | li ZERO, 0
+ | ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float).
+ | lfs TOBIT, TMPD
+ | sub PC, PC, TMP2 // PC = frame delta + frame type
+ | stw TMP3, TMPD
+ | lus TMP0, 0x4338 // Hiword of 2^52 + 2^51 (double)
+ | sub NARGS8:RC, TMP1, BASE
+ | stw TMP0, TONUM_HI
+ | li_vmstate INTERP
+ | lfs TONUM, TMPD
+ | li TISNIL, LJ_TNIL
+ | st_vmstate
+ |
+ |->vm_call_dispatch:
+ | // TMP2 = old base, BASE = new base, RC = nargs*8, PC = caller PC
+ | lwz TMP0, FRAME_PC(BASE)
+ | lwz LFUNC:RB, FRAME_FUNC(BASE)
+ | checkfunc TMP0; bne ->vmeta_call
+ |
+ |->vm_call_dispatch_f:
+ | ins_call
+ | // BASE = new base, RB = func, RC = nargs*8, PC = caller PC
+ |
+ |->vm_cpcall: // Setup protected C frame, call C.
+ | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)
+ | saveregs
+ | mr L, CARG1
+ | lwz TMP0, L:CARG1->stack
+ | stw CARG1, SAVE_L
+ | lp TMP1, L->top
+ | stw CARG1, SAVE_PC // Any value outside of bytecode is ok.
+ | sub TMP0, TMP0, TMP1 // Compute -savestack(L, L->top).
+ | lp TMP1, L->cframe
+ | stp sp, L->cframe // Add our C frame to cframe chain.
+ | .toc lp CARG4, 0(CARG4)
+ | li TMP2, 0
+ | stw TMP0, SAVE_NRES // Neg. delta means cframe w/o frame.
+ | stw TMP2, SAVE_ERRF // No error function.
+ | stp TMP1, SAVE_CFRAME
+ | mtctr CARG4
+ | bctrl // (lua_State *L, lua_CFunction func, void *ud)
+ |.if PPE
+ | mr BASE, CRET1
+ | cmpwi CRET1, 0
+ |.else
+ | mr. BASE, CRET1
+ |.endif
+ | lwz DISPATCH, L->glref // Setup pointer to dispatch table.
+ | li PC, FRAME_CP
+ | addi DISPATCH, DISPATCH, GG_G2DISP
+ | bne <3 // Else continue with the call.
+ | b ->vm_leave_cp // No base? Just remove C frame.
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Metamethod handling ------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |// The lj_meta_* functions (except for lj_meta_cat) don't reallocate the
+ |// stack, so BASE doesn't need to be reloaded across these calls.
+ |
+ |//-- Continuation dispatch ----------------------------------------------
+ |
+ |->cont_dispatch:
+ | // BASE = meta base, RA = resultptr, RD = (nresults+1)*8
+ | lwz TMP0, -12(BASE) // Continuation.
+ | mr RB, BASE
+ | mr BASE, TMP2 // Restore caller BASE.
+ | lwz LFUNC:TMP1, FRAME_FUNC(TMP2)
+ |.if FFI
+ | cmplwi TMP0, 1
+ |.endif
+ | lwz PC, -16(RB) // Restore PC from [cont|PC].
+ | subi TMP2, RD, 8
+ | lwz TMP1, LFUNC:TMP1->pc
+ | stwx TISNIL, RA, TMP2 // Ensure one valid arg.
+ |.if FFI
+ | ble >1
+ |.endif
+ | lwz KBASE, PC2PROTO(k)(TMP1)
+ | // BASE = base, RA = resultptr, RB = meta base
+ | mtctr TMP0
+ | bctr // Jump to continuation.
+ |
+ |.if FFI
+ |1:
+ | beq ->cont_ffi_callback // cont = 1: return from FFI callback.
+ | // cont = 0: tailcall from C function.
+ | subi TMP1, RB, 16
+ | sub RC, TMP1, BASE
+ | b ->vm_call_tail
+ |.endif
+ |
+ |->cont_cat: // RA = resultptr, RB = meta base
+ | lwz INS, -4(PC)
+ | subi CARG2, RB, 16
+ | decode_RB8 SAVE0, INS
+ | lfd f0, 0(RA)
+ | add TMP1, BASE, SAVE0
+ | stp BASE, L->base
+ | cmplw TMP1, CARG2
+ | sub CARG3, CARG2, TMP1
+ | decode_RA8 RA, INS
+ | stfd f0, 0(CARG2)
+ | bney ->BC_CAT_Z
+ | stfdx f0, BASE, RA
+ | b ->cont_nop
+ |
+ |//-- Table indexing metamethods -----------------------------------------
+ |
+ |->vmeta_tgets1:
+ | la CARG3, DISPATCH_GL(tmptv)(DISPATCH)
+ | li TMP0, LJ_TSTR
+ | decode_RB8 RB, INS
+ | stw STR:RC, 4(CARG3)
+ | add CARG2, BASE, RB
+ | stw TMP0, 0(CARG3)
+ | b >1
+ |
+ |->vmeta_tgets:
+ | la CARG2, DISPATCH_GL(tmptv)(DISPATCH)
+ | li TMP0, LJ_TTAB
+ | stw TAB:RB, 4(CARG2)
+ | la CARG3, DISPATCH_GL(tmptv2)(DISPATCH)
+ | stw TMP0, 0(CARG2)
+ | li TMP1, LJ_TSTR
+ | stw STR:RC, 4(CARG3)
+ | stw TMP1, 0(CARG3)
+ | b >1
+ |
+ |->vmeta_tgetb: // TMP0 = index
+ |.if not DUALNUM
+ | tonum_u f0, TMP0
+ |.endif
+ | decode_RB8 RB, INS
+ | la CARG3, DISPATCH_GL(tmptv)(DISPATCH)
+ | add CARG2, BASE, RB
+ |.if DUALNUM
+ | stw TISNUM, 0(CARG3)
+ | stw TMP0, 4(CARG3)
+ |.else
+ | stfd f0, 0(CARG3)
+ |.endif
+ | b >1
+ |
+ |->vmeta_tgetv:
+ | decode_RB8 RB, INS
+ | decode_RC8 RC, INS
+ | add CARG2, BASE, RB
+ | add CARG3, BASE, RC
+ |1:
+ | stp BASE, L->base
+ | mr CARG1, L
+ | stw PC, SAVE_PC
+ | bl extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k)
+ | // Returns TValue * (finished) or NULL (metamethod).
+ | cmplwi CRET1, 0
+ | beq >3
+ | lfd f0, 0(CRET1)
+ | ins_next1
+ | stfdx f0, BASE, RA
+ | ins_next2
+ |
+ |3: // Call __index metamethod.
+ | // BASE = base, L->top = new base, stack = cont/func/t/k
+ | subfic TMP1, BASE, FRAME_CONT
+ | lp BASE, L->top
+ | stw PC, -16(BASE) // [cont|PC]
+ | add PC, TMP1, BASE
+ | lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here.
+ | li NARGS8:RC, 16 // 2 args for func(t, k).
+ | b ->vm_call_dispatch_f
+ |
+ |//-----------------------------------------------------------------------
+ |
+ |->vmeta_tsets1:
+ | la CARG3, DISPATCH_GL(tmptv)(DISPATCH)
+ | li TMP0, LJ_TSTR
+ | decode_RB8 RB, INS
+ | stw STR:RC, 4(CARG3)
+ | add CARG2, BASE, RB
+ | stw TMP0, 0(CARG3)
+ | b >1
+ |
+ |->vmeta_tsets:
+ | la CARG2, DISPATCH_GL(tmptv)(DISPATCH)
+ | li TMP0, LJ_TTAB
+ | stw TAB:RB, 4(CARG2)
+ | la CARG3, DISPATCH_GL(tmptv2)(DISPATCH)
+ | stw TMP0, 0(CARG2)
+ | li TMP1, LJ_TSTR
+ | stw STR:RC, 4(CARG3)
+ | stw TMP1, 0(CARG3)
+ | b >1
+ |
+ |->vmeta_tsetb: // TMP0 = index
+ |.if not DUALNUM
+ | tonum_u f0, TMP0
+ |.endif
+ | decode_RB8 RB, INS
+ | la CARG3, DISPATCH_GL(tmptv)(DISPATCH)
+ | add CARG2, BASE, RB
+ |.if DUALNUM
+ | stw TISNUM, 0(CARG3)
+ | stw TMP0, 4(CARG3)
+ |.else
+ | stfd f0, 0(CARG3)
+ |.endif
+ | b >1
+ |
+ |->vmeta_tsetv:
+ | decode_RB8 RB, INS
+ | decode_RC8 RC, INS
+ | add CARG2, BASE, RB
+ | add CARG3, BASE, RC
+ |1:
+ | stp BASE, L->base
+ | mr CARG1, L
+ | stw PC, SAVE_PC
+ | bl extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k)
+ | // Returns TValue * (finished) or NULL (metamethod).
+ | cmplwi CRET1, 0
+ | lfdx f0, BASE, RA
+ | beq >3
+ | // NOBARRIER: lj_meta_tset ensures the table is not black.
+ | ins_next1
+ | stfd f0, 0(CRET1)
+ | ins_next2
+ |
+ |3: // Call __newindex metamethod.
+ | // BASE = base, L->top = new base, stack = cont/func/t/k/(v)
+ | subfic TMP1, BASE, FRAME_CONT
+ | lp BASE, L->top
+ | stw PC, -16(BASE) // [cont|PC]
+ | add PC, TMP1, BASE
+ | lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here.
+ | li NARGS8:RC, 24 // 3 args for func(t, k, v)
+ | stfd f0, 16(BASE) // Copy value to third argument.
+ | b ->vm_call_dispatch_f
+ |
+ |//-- Comparison metamethods ---------------------------------------------
+ |
+ |->vmeta_comp:
+ | mr CARG1, L
+ | subi PC, PC, 4
+ |.if DUALNUM
+ | mr CARG2, RA
+ |.else
+ | add CARG2, BASE, RA
+ |.endif
+ | stw PC, SAVE_PC
+ |.if DUALNUM
+ | mr CARG3, RD
+ |.else
+ | add CARG3, BASE, RD
+ |.endif
+ | stp BASE, L->base
+ | decode_OP1 CARG4, INS
+ | bl extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op)
+ | // Returns 0/1 or TValue * (metamethod).
+ |3:
+ | cmplwi CRET1, 1
+ | bgt ->vmeta_binop
+ | subfic CRET1, CRET1, 0
+ |4:
+ | lwz INS, 0(PC)
+ | addi PC, PC, 4
+ | decode_RD4 TMP2, INS
+ | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)
+ | and TMP2, TMP2, CRET1
+ | add PC, PC, TMP2
+ |->cont_nop:
+ | ins_next
+ |
+ |->cont_ra: // RA = resultptr
+ | lwz INS, -4(PC)
+ | lfd f0, 0(RA)
+ | decode_RA8 TMP1, INS
+ | stfdx f0, BASE, TMP1
+ | b ->cont_nop
+ |
+ |->cont_condt: // RA = resultptr
+ | lwz TMP0, 0(RA)
+ | .gpr64 extsw TMP0, TMP0
+ | subfic TMP0, TMP0, LJ_TTRUE // Branch if result is true.
+ | subfe CRET1, CRET1, CRET1
+ | not CRET1, CRET1
+ | b <4
+ |
+ |->cont_condf: // RA = resultptr
+ | lwz TMP0, 0(RA)
+ | .gpr64 extsw TMP0, TMP0
+ | subfic TMP0, TMP0, LJ_TTRUE // Branch if result is false.
+ | subfe CRET1, CRET1, CRET1
+ | b <4
+ |
+ |->vmeta_equal:
+ | // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV.
+ | subi PC, PC, 4
+ | stp BASE, L->base
+ | mr CARG1, L
+ | stw PC, SAVE_PC
+ | bl extern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne)
+ | // Returns 0/1 or TValue * (metamethod).
+ | b <3
+ |
+ |->vmeta_equal_cd:
+ |.if FFI
+ | mr CARG2, INS
+ | subi PC, PC, 4
+ | stp BASE, L->base
+ | mr CARG1, L
+ | stw PC, SAVE_PC
+ | bl extern lj_meta_equal_cd // (lua_State *L, BCIns op)
+ | // Returns 0/1 or TValue * (metamethod).
+ | b <3
+ |.endif
+ |
+ |//-- Arithmetic metamethods ---------------------------------------------
+ |
+ |->vmeta_arith_nv:
+ | add CARG3, KBASE, RC
+ | add CARG4, BASE, RB
+ | b >1
+ |->vmeta_arith_nv2:
+ |.if DUALNUM
+ | mr CARG3, RC
+ | mr CARG4, RB
+ | b >1
+ |.endif
+ |
+ |->vmeta_unm:
+ | mr CARG3, RD
+ | mr CARG4, RD
+ | b >1
+ |
+ |->vmeta_arith_vn:
+ | add CARG3, BASE, RB
+ | add CARG4, KBASE, RC
+ | b >1
+ |
+ |->vmeta_arith_vv:
+ | add CARG3, BASE, RB
+ | add CARG4, BASE, RC
+ |.if DUALNUM
+ | b >1
+ |.endif
+ |->vmeta_arith_vn2:
+ |->vmeta_arith_vv2:
+ |.if DUALNUM
+ | mr CARG3, RB
+ | mr CARG4, RC
+ |.endif
+ |1:
+ | add CARG2, BASE, RA
+ | stp BASE, L->base
+ | mr CARG1, L
+ | stw PC, SAVE_PC
+ | decode_OP1 CARG5, INS // Caveat: CARG5 overlaps INS.
+ | bl extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)
+ | // Returns NULL (finished) or TValue * (metamethod).
+ | cmplwi CRET1, 0
+ | beq ->cont_nop
+ |
+ | // Call metamethod for binary op.
+ |->vmeta_binop:
+ | // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2
+ | sub TMP1, CRET1, BASE
+ | stw PC, -16(CRET1) // [cont|PC]
+ | mr TMP2, BASE
+ | addi PC, TMP1, FRAME_CONT
+ | mr BASE, CRET1
+ | li NARGS8:RC, 16 // 2 args for func(o1, o2).
+ | b ->vm_call_dispatch
+ |
+ |->vmeta_len:
+#if LJ_52
+ | mr SAVE0, CARG1
+#endif
+ | mr CARG2, RD
+ | stp BASE, L->base
+ | mr CARG1, L
+ | stw PC, SAVE_PC
+ | bl extern lj_meta_len // (lua_State *L, TValue *o)
+ | // Returns NULL (retry) or TValue * (metamethod base).
+#if LJ_52
+ | cmplwi CRET1, 0
+ | bne ->vmeta_binop // Binop call for compatibility.
+ | mr CARG1, SAVE0
+ | b ->BC_LEN_Z
+#else
+ | b ->vmeta_binop // Binop call for compatibility.
+#endif
+ |
+ |//-- Call metamethod ----------------------------------------------------
+ |
+ |->vmeta_call: // Resolve and call __call metamethod.
+ | // TMP2 = old base, BASE = new base, RC = nargs*8
+ | mr CARG1, L
+ | stp TMP2, L->base // This is the callers base!
+ | subi CARG2, BASE, 8
+ | stw PC, SAVE_PC
+ | add CARG3, BASE, RC
+ | mr SAVE0, NARGS8:RC
+ | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
+ | lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here.
+ | addi NARGS8:RC, SAVE0, 8 // Got one more argument now.
+ | ins_call
+ |
+ |->vmeta_callt: // Resolve __call for BC_CALLT.
+ | // BASE = old base, RA = new base, RC = nargs*8
+ | mr CARG1, L
+ | stp BASE, L->base
+ | subi CARG2, RA, 8
+ | stw PC, SAVE_PC
+ | add CARG3, RA, RC
+ | mr SAVE0, NARGS8:RC
+ | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
+ | lwz TMP1, FRAME_PC(BASE)
+ | addi NARGS8:RC, SAVE0, 8 // Got one more argument now.
+ | lwz LFUNC:RB, FRAME_FUNC(RA) // Guaranteed to be a function here.
+ | b ->BC_CALLT_Z
+ |
+ |//-- Argument coercion for 'for' statement ------------------------------
+ |
+ |->vmeta_for:
+ | mr CARG1, L
+ | stp BASE, L->base
+ | mr CARG2, RA
+ | stw PC, SAVE_PC
+ | mr SAVE0, INS
+ | bl extern lj_meta_for // (lua_State *L, TValue *base)
+ |.if JIT
+ | decode_OP1 TMP0, SAVE0
+ |.endif
+ | decode_RA8 RA, SAVE0
+ |.if JIT
+ | cmpwi TMP0, BC_JFORI
+ |.endif
+ | decode_RD8 RD, SAVE0
+ |.if JIT
+ | beqy =>BC_JFORI
+ |.endif
+ | b =>BC_FORI
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Fast functions -----------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |.macro .ffunc, name
+ |->ff_ .. name:
+ |.endmacro
+ |
+ |.macro .ffunc_1, name
+ |->ff_ .. name:
+ | cmplwi NARGS8:RC, 8
+ | lwz CARG3, 0(BASE)
+ | lwz CARG1, 4(BASE)
+ | blt ->fff_fallback
+ |.endmacro
+ |
+ |.macro .ffunc_2, name
+ |->ff_ .. name:
+ | cmplwi NARGS8:RC, 16
+ | lwz CARG3, 0(BASE)
+ | lwz CARG4, 8(BASE)
+ | lwz CARG1, 4(BASE)
+ | lwz CARG2, 12(BASE)
+ | blt ->fff_fallback
+ |.endmacro
+ |
+ |.macro .ffunc_n, name
+ |->ff_ .. name:
+ | cmplwi NARGS8:RC, 8
+ | lwz CARG3, 0(BASE)
+ | lfd FARG1, 0(BASE)
+ | blt ->fff_fallback
+ | checknum CARG3; bge ->fff_fallback
+ |.endmacro
+ |
+ |.macro .ffunc_nn, name
+ |->ff_ .. name:
+ | cmplwi NARGS8:RC, 16
+ | lwz CARG3, 0(BASE)
+ | lfd FARG1, 0(BASE)
+ | lwz CARG4, 8(BASE)
+ | lfd FARG2, 8(BASE)
+ | blt ->fff_fallback
+ | checknum CARG3; bge ->fff_fallback
+ | checknum CARG4; bge ->fff_fallback
+ |.endmacro
+ |
+ |// Inlined GC threshold check. Caveat: uses TMP0 and TMP1.
+ |.macro ffgccheck
+ | lwz TMP0, DISPATCH_GL(gc.total)(DISPATCH)
+ | lwz TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)
+ | cmplw TMP0, TMP1
+ | bgel ->fff_gcstep
+ |.endmacro
+ |
+ |//-- Base library: checks -----------------------------------------------
+ |
+ |.ffunc_1 assert
+ | li TMP1, LJ_TFALSE
+ | la RA, -8(BASE)
+ | cmplw cr1, CARG3, TMP1
+ | lwz PC, FRAME_PC(BASE)
+ | bge cr1, ->fff_fallback
+ | stw CARG3, 0(RA)
+ | addi RD, NARGS8:RC, 8 // Compute (nresults+1)*8.
+ | stw CARG1, 4(RA)
+ | beq ->fff_res // Done if exactly 1 argument.
+ | li TMP1, 8
+ | subi RC, RC, 8
+ |1:
+ | cmplw TMP1, RC
+ | lfdx f0, BASE, TMP1
+ | stfdx f0, RA, TMP1
+ | addi TMP1, TMP1, 8
+ | bney <1
+ | b ->fff_res
+ |
+ |.ffunc type
+ | cmplwi NARGS8:RC, 8
+ | lwz CARG1, 0(BASE)
+ | blt ->fff_fallback
+ | .gpr64 extsw CARG1, CARG1
+ | subfc TMP0, TISNUM, CARG1
+ | subfe TMP2, CARG1, CARG1
+ | orc TMP1, TMP2, TMP0
+ | addi TMP1, TMP1, ~LJ_TISNUM+1
+ | slwi TMP1, TMP1, 3
+ | la TMP2, CFUNC:RB->upvalue
+ | lfdx FARG1, TMP2, TMP1
+ | b ->fff_resn
+ |
+ |//-- Base library: getters and setters ---------------------------------
+ |
+ |.ffunc_1 getmetatable
+ | checktab CARG3; bne >6
+ |1: // Field metatable must be at same offset for GCtab and GCudata!
+ | lwz TAB:CARG1, TAB:CARG1->metatable
+ |2:
+ | li CARG3, LJ_TNIL
+ | cmplwi TAB:CARG1, 0
+ | lwz STR:RC, DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])(DISPATCH)
+ | beq ->fff_restv
+ | lwz TMP0, TAB:CARG1->hmask
+ | li CARG3, LJ_TTAB // Use metatable as default result.
+ | lwz TMP1, STR:RC->hash
+ | lwz NODE:TMP2, TAB:CARG1->node
+ | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask
+ | slwi TMP0, TMP1, 5
+ | slwi TMP1, TMP1, 3
+ | sub TMP1, TMP0, TMP1
+ | add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8)
+ |3: // Rearranged logic, because we expect _not_ to find the key.
+ | lwz CARG4, NODE:TMP2->key
+ | lwz TMP0, 4+offsetof(Node, key)(NODE:TMP2)
+ | lwz CARG2, NODE:TMP2->val
+ | lwz TMP1, 4+offsetof(Node, val)(NODE:TMP2)
+ | checkstr CARG4; bne >4
+ | cmpw TMP0, STR:RC; beq >5
+ |4:
+ | lwz NODE:TMP2, NODE:TMP2->next
+ | cmplwi NODE:TMP2, 0
+ | beq ->fff_restv // Not found, keep default result.
+ | b <3
+ |5:
+ | checknil CARG2
+ | beq ->fff_restv // Ditto for nil value.
+ | mr CARG3, CARG2 // Return value of mt.__metatable.
+ | mr CARG1, TMP1
+ | b ->fff_restv
+ |
+ |6:
+ | cmpwi CARG3, LJ_TUDATA; beq <1
+ | .gpr64 extsw CARG3, CARG3
+ | subfc TMP0, TISNUM, CARG3
+ | subfe TMP2, CARG3, CARG3
+ | orc TMP1, TMP2, TMP0
+ | addi TMP1, TMP1, ~LJ_TISNUM+1
+ | slwi TMP1, TMP1, 2
+ | la TMP2, DISPATCH_GL(gcroot[GCROOT_BASEMT])(DISPATCH)
+ | lwzx TAB:CARG1, TMP2, TMP1
+ | b <2
+ |
+ |.ffunc_2 setmetatable
+ | // Fast path: no mt for table yet and not clearing the mt.
+ | checktab CARG3; bne ->fff_fallback
+ | lwz TAB:TMP1, TAB:CARG1->metatable
+ | checktab CARG4; bne ->fff_fallback
+ | cmplwi TAB:TMP1, 0
+ | lbz TMP3, TAB:CARG1->marked
+ | bne ->fff_fallback
+ | andix. TMP0, TMP3, LJ_GC_BLACK // isblack(table)
+ | stw TAB:CARG2, TAB:CARG1->metatable
+ | beq ->fff_restv
+ | barrierback TAB:CARG1, TMP3, TMP0
+ | b ->fff_restv
+ |
+ |.ffunc rawget
+ | cmplwi NARGS8:RC, 16
+ | lwz CARG4, 0(BASE)
+ | lwz TAB:CARG2, 4(BASE)
+ | blt ->fff_fallback
+ | checktab CARG4; bne ->fff_fallback
+ | la CARG3, 8(BASE)
+ | mr CARG1, L
+ | bl extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key)
+ | // Returns cTValue *.
+ | lfd FARG1, 0(CRET1)
+ | b ->fff_resn
+ |
+ |//-- Base library: conversions ------------------------------------------
+ |
+ |.ffunc tonumber
+ | // Only handles the number case inline (without a base argument).
+ | cmplwi NARGS8:RC, 8
+ | lwz CARG1, 0(BASE)
+ | lfd FARG1, 0(BASE)
+ | bne ->fff_fallback // Exactly one argument.
+ | checknum CARG1; bgt ->fff_fallback
+ | b ->fff_resn
+ |
+ |.ffunc_1 tostring
+ | // Only handles the string or number case inline.
+ | checkstr CARG3
+ | // A __tostring method in the string base metatable is ignored.
+ | beq ->fff_restv // String key?
+ | // Handle numbers inline, unless a number base metatable is present.
+ | lwz TMP0, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])(DISPATCH)
+ | checknum CARG3
+ | cmplwi cr1, TMP0, 0
+ | stp BASE, L->base // Add frame since C call can throw.
+ | crorc 4*cr0+eq, 4*cr0+gt, 4*cr1+eq
+ | stw PC, SAVE_PC // Redundant (but a defined value).
+ | beq ->fff_fallback
+ | ffgccheck
+ | mr CARG1, L
+ | mr CARG2, BASE
+ |.if DUALNUM
+ | bl extern lj_str_fromnumber // (lua_State *L, cTValue *o)
+ |.else
+ | bl extern lj_str_fromnum // (lua_State *L, lua_Number *np)
+ |.endif
+ | // Returns GCstr *.
+ | li CARG3, LJ_TSTR
+ | b ->fff_restv
+ |
+ |//-- Base library: iterators -------------------------------------------
+ |
+ |.ffunc next
+ | cmplwi NARGS8:RC, 8
+ | lwz CARG1, 0(BASE)
+ | lwz TAB:CARG2, 4(BASE)
+ | blt ->fff_fallback
+ | stwx TISNIL, BASE, NARGS8:RC // Set missing 2nd arg to nil.
+ | checktab CARG1
+ | lwz PC, FRAME_PC(BASE)
+ | bne ->fff_fallback
+ | stp BASE, L->base // Add frame since C call can throw.
+ | mr CARG1, L
+ | stp BASE, L->top // Dummy frame length is ok.
+ | la CARG3, 8(BASE)
+ | stw PC, SAVE_PC
+ | bl extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key)
+ | // Returns 0 at end of traversal.
+ | cmplwi CRET1, 0
+ | li CARG3, LJ_TNIL
+ | beq ->fff_restv // End of traversal: return nil.
+ | lfd f0, 8(BASE) // Copy key and value to results.
+ | la RA, -8(BASE)
+ | lfd f1, 16(BASE)
+ | stfd f0, 0(RA)
+ | li RD, (2+1)*8
+ | stfd f1, 8(RA)
+ | b ->fff_res
+ |
+ |.ffunc_1 pairs
+ | checktab CARG3
+ | lwz PC, FRAME_PC(BASE)
+ | bne ->fff_fallback
+#if LJ_52
+ | lwz TAB:TMP2, TAB:CARG1->metatable
+ | lfd f0, CFUNC:RB->upvalue[0]
+ | cmplwi TAB:TMP2, 0
+ | la RA, -8(BASE)
+ | bne ->fff_fallback
+#else
+ | lfd f0, CFUNC:RB->upvalue[0]
+ | la RA, -8(BASE)
+#endif
+ | stw TISNIL, 8(BASE)
+ | li RD, (3+1)*8
+ | stfd f0, 0(RA)
+ | b ->fff_res
+ |
+ |.ffunc ipairs_aux
+ | cmplwi NARGS8:RC, 16
+ | lwz CARG3, 0(BASE)
+ | lwz TAB:CARG1, 4(BASE)
+ | lwz CARG4, 8(BASE)
+ |.if DUALNUM
+ | lwz TMP2, 12(BASE)
+ |.else
+ | lfd FARG2, 8(BASE)
+ |.endif
+ | blt ->fff_fallback
+ | checktab CARG3
+ | checknum cr1, CARG4
+ | lwz PC, FRAME_PC(BASE)
+ |.if DUALNUM
+ | bne ->fff_fallback
+ | bne cr1, ->fff_fallback
+ |.else
+ | lus TMP0, 0x3ff0
+ | stw ZERO, TMPD_LO
+ | bne ->fff_fallback
+ | stw TMP0, TMPD_HI
+ | bge cr1, ->fff_fallback
+ | lfd FARG1, TMPD
+ | toint TMP2, FARG2, f0
+ |.endif
+ | lwz TMP0, TAB:CARG1->asize
+ | lwz TMP1, TAB:CARG1->array
+ |.if not DUALNUM
+ | fadd FARG2, FARG2, FARG1
+ |.endif
+ | addi TMP2, TMP2, 1
+ | la RA, -8(BASE)
+ | cmplw TMP0, TMP2
+ |.if DUALNUM
+ | stw TISNUM, 0(RA)
+ | slwi TMP3, TMP2, 3
+ | stw TMP2, 4(RA)
+ |.else
+ | slwi TMP3, TMP2, 3
+ | stfd FARG2, 0(RA)
+ |.endif
+ | ble >2 // Not in array part?
+ | lwzx TMP2, TMP1, TMP3
+ | lfdx f0, TMP1, TMP3
+ |1:
+ | checknil TMP2
+ | li RD, (0+1)*8
+ | beq ->fff_res // End of iteration, return 0 results.
+ | li RD, (2+1)*8
+ | stfd f0, 8(RA)
+ | b ->fff_res
+ |2: // Check for empty hash part first. Otherwise call C function.
+ | lwz TMP0, TAB:CARG1->hmask
+ | cmplwi TMP0, 0
+ | li RD, (0+1)*8
+ | beq ->fff_res
+ | mr CARG2, TMP2
+ | bl extern lj_tab_getinth // (GCtab *t, int32_t key)
+ | // Returns cTValue * or NULL.
+ | cmplwi CRET1, 0
+ | li RD, (0+1)*8
+ | beq ->fff_res
+ | lwz TMP2, 0(CRET1)
+ | lfd f0, 0(CRET1)
+ | b <1
+ |
+ |.ffunc_1 ipairs
+ | checktab CARG3
+ | lwz PC, FRAME_PC(BASE)
+ | bne ->fff_fallback
+#if LJ_52
+ | lwz TAB:TMP2, TAB:CARG1->metatable
+ | lfd f0, CFUNC:RB->upvalue[0]
+ | cmplwi TAB:TMP2, 0
+ | la RA, -8(BASE)
+ | bne ->fff_fallback
+#else
+ | lfd f0, CFUNC:RB->upvalue[0]
+ | la RA, -8(BASE)
+#endif
+ |.if DUALNUM
+ | stw TISNUM, 8(BASE)
+ |.else
+ | stw ZERO, 8(BASE)
+ |.endif
+ | stw ZERO, 12(BASE)
+ | li RD, (3+1)*8
+ | stfd f0, 0(RA)
+ | b ->fff_res
+ |
+ |//-- Base library: catch errors ----------------------------------------
+ |
+ |.ffunc pcall
+ | cmplwi NARGS8:RC, 8
+ | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)
+ | blt ->fff_fallback
+ | mr TMP2, BASE
+ | la BASE, 8(BASE)
+ | // Remember active hook before pcall.
+ | rlwinm TMP3, TMP3, 32-HOOK_ACTIVE_SHIFT, 31, 31
+ | subi NARGS8:RC, NARGS8:RC, 8
+ | addi PC, TMP3, 8+FRAME_PCALL
+ | b ->vm_call_dispatch
+ |
+ |.ffunc xpcall
+ | cmplwi NARGS8:RC, 16
+ | lwz CARG4, 8(BASE)
+ | lfd FARG2, 8(BASE)
+ | lfd FARG1, 0(BASE)
+ | blt ->fff_fallback
+ | lbz TMP1, DISPATCH_GL(hookmask)(DISPATCH)
+ | mr TMP2, BASE
+ | checkfunc CARG4; bne ->fff_fallback // Traceback must be a function.
+ | la BASE, 16(BASE)
+ | // Remember active hook before pcall.
+ | rlwinm TMP1, TMP1, 32-HOOK_ACTIVE_SHIFT, 31, 31
+ | stfd FARG2, 0(TMP2) // Swap function and traceback.
+ | subi NARGS8:RC, NARGS8:RC, 16
+ | stfd FARG1, 8(TMP2)
+ | addi PC, TMP1, 16+FRAME_PCALL
+ | b ->vm_call_dispatch
+ |
+ |//-- Coroutine library --------------------------------------------------
+ |
+ |.macro coroutine_resume_wrap, resume
+ |.if resume
+ |.ffunc_1 coroutine_resume
+ | cmpwi CARG3, LJ_TTHREAD; bne ->fff_fallback
+ |.else
+ |.ffunc coroutine_wrap_aux
+ | lwz L:CARG1, CFUNC:RB->upvalue[0].gcr
+ |.endif
+ | lbz TMP0, L:CARG1->status
+ | lp TMP1, L:CARG1->cframe
+ | lp CARG2, L:CARG1->top
+ | cmplwi cr0, TMP0, LUA_YIELD
+ | lp TMP2, L:CARG1->base
+ | cmplwi cr1, TMP1, 0
+ | lwz TMP0, L:CARG1->maxstack
+ | cmplw cr7, CARG2, TMP2
+ | lwz PC, FRAME_PC(BASE)
+ | crorc 4*cr6+lt, 4*cr0+gt, 4*cr1+eq // st>LUA_YIELD || cframe!=0
+ | add TMP2, CARG2, NARGS8:RC
+ | crandc 4*cr6+gt, 4*cr7+eq, 4*cr0+eq // base==top && st!=LUA_YIELD
+ | cmplw cr1, TMP2, TMP0
+ | cror 4*cr6+lt, 4*cr6+lt, 4*cr6+gt
+ | stw PC, SAVE_PC
+ | cror 4*cr6+lt, 4*cr6+lt, 4*cr1+gt // cond1 || cond2 || stackov
+ | stp BASE, L->base
+ | blt cr6, ->fff_fallback
+ |1:
+ |.if resume
+ | addi BASE, BASE, 8 // Keep resumed thread in stack for GC.
+ | subi NARGS8:RC, NARGS8:RC, 8
+ | subi TMP2, TMP2, 8
+ |.endif
+ | stp TMP2, L:CARG1->top
+ | li TMP1, 0
+ | stp BASE, L->top
+ |2: // Move args to coroutine.
+ | cmpw TMP1, NARGS8:RC
+ | lfdx f0, BASE, TMP1
+ | beq >3
+ | stfdx f0, CARG2, TMP1
+ | addi TMP1, TMP1, 8
+ | b <2
+ |3:
+ | li CARG3, 0
+ | mr L:SAVE0, L:CARG1
+ | li CARG4, 0
+ | bl ->vm_resume // (lua_State *L, TValue *base, 0, 0)
+ | // Returns thread status.
+ |4:
+ | lp TMP2, L:SAVE0->base
+ | cmplwi CRET1, LUA_YIELD
+ | lp TMP3, L:SAVE0->top
+ | li_vmstate INTERP
+ | lp BASE, L->base
+ | st_vmstate
+ | bgt >8
+ | sub RD, TMP3, TMP2
+ | lwz TMP0, L->maxstack
+ | cmplwi RD, 0
+ | add TMP1, BASE, RD
+ | beq >6 // No results?
+ | cmplw TMP1, TMP0
+ | li TMP1, 0
+ | bgt >9 // Need to grow stack?
+ |
+ | subi TMP3, RD, 8
+ | stp TMP2, L:SAVE0->top // Clear coroutine stack.
+ |5: // Move results from coroutine.
+ | cmplw TMP1, TMP3
+ | lfdx f0, TMP2, TMP1
+ | stfdx f0, BASE, TMP1
+ | addi TMP1, TMP1, 8
+ | bne <5
+ |6:
+ | andix. TMP0, PC, FRAME_TYPE
+ |.if resume
+ | li TMP1, LJ_TTRUE
+ | la RA, -8(BASE)
+ | stw TMP1, -8(BASE) // Prepend true to results.
+ | addi RD, RD, 16
+ |.else
+ | mr RA, BASE
+ | addi RD, RD, 8
+ |.endif
+ |7:
+ | stw PC, SAVE_PC
+ | mr MULTRES, RD
+ | beq ->BC_RET_Z
+ | b ->vm_return
+ |
+ |8: // Coroutine returned with error (at co->top-1).
+ |.if resume
+ | andix. TMP0, PC, FRAME_TYPE
+ | la TMP3, -8(TMP3)
+ | li TMP1, LJ_TFALSE
+ | lfd f0, 0(TMP3)
+ | stp TMP3, L:SAVE0->top // Remove error from coroutine stack.
+ | li RD, (2+1)*8
+ | stw TMP1, -8(BASE) // Prepend false to results.
+ | la RA, -8(BASE)
+ | stfd f0, 0(BASE) // Copy error message.
+ | b <7
+ |.else
+ | mr CARG1, L
+ | mr CARG2, L:SAVE0
+ | bl extern lj_ffh_coroutine_wrap_err // (lua_State *L, lua_State *co)
+ |.endif
+ |
+ |9: // Handle stack expansion on return from yield.
+ | mr CARG1, L
+ | srwi CARG2, RD, 3
+ | bl extern lj_state_growstack // (lua_State *L, int n)
+ | li CRET1, 0
+ | b <4
+ |.endmacro
+ |
+ | coroutine_resume_wrap 1 // coroutine.resume
+ | coroutine_resume_wrap 0 // coroutine.wrap
+ |
+ |.ffunc coroutine_yield
+ | lp TMP0, L->cframe
+ | add TMP1, BASE, NARGS8:RC
+ | stp BASE, L->base
+ | andix. TMP0, TMP0, CFRAME_RESUME
+ | stp TMP1, L->top
+ | li CRET1, LUA_YIELD
+ | beq ->fff_fallback
+ | stp ZERO, L->cframe
+ | stb CRET1, L->status
+ | b ->vm_leave_unw
+ |
+ |//-- Math library -------------------------------------------------------
+ |
+ |.ffunc_1 math_abs
+ | checknum CARG3
+ |.if DUALNUM
+ | bne >2
+ | srawi TMP1, CARG1, 31
+ | xor TMP2, TMP1, CARG1
+ |.if GPR64
+ | lus TMP0, 0x8000
+ | sub CARG1, TMP2, TMP1
+ | cmplw CARG1, TMP0
+ | beq >1
+ |.else
+ | sub. CARG1, TMP2, TMP1
+ | blt >1
+ |.endif
+ |->fff_resi:
+ | lwz PC, FRAME_PC(BASE)
+ | la RA, -8(BASE)
+ | stw TISNUM, -8(BASE)
+ | stw CRET1, -4(BASE)
+ | b ->fff_res1
+ |1:
+ | lus CARG3, 0x41e0 // 2^31.
+ | li CARG1, 0
+ | b ->fff_restv
+ |2:
+ |.endif
+ | bge ->fff_fallback
+ | rlwinm CARG3, CARG3, 0, 1, 31
+ | // Fallthrough.
+ |
+ |->fff_restv:
+ | // CARG3/CARG1 = TValue result.
+ | lwz PC, FRAME_PC(BASE)
+ | stw CARG3, -8(BASE)
+ | la RA, -8(BASE)
+ | stw CARG1, -4(BASE)
+ |->fff_res1:
+ | // RA = results, PC = return.
+ | li RD, (1+1)*8
+ |->fff_res:
+ | // RA = results, RD = (nresults+1)*8, PC = return.
+ | andix. TMP0, PC, FRAME_TYPE
+ | mr MULTRES, RD
+ | bney ->vm_return
+ | lwz INS, -4(PC)
+ | decode_RB8 RB, INS
+ |5:
+ | cmplw RB, RD // More results expected?
+ | decode_RA8 TMP0, INS
+ | bgt >6
+ | ins_next1
+ | // Adjust BASE. KBASE is assumed to be set for the calling frame.
+ | sub BASE, RA, TMP0
+ | ins_next2
+ |
+ |6: // Fill up results with nil.
+ | subi TMP1, RD, 8
+ | addi RD, RD, 8
+ | stwx TISNIL, RA, TMP1
+ | b <5
+ |
+ |.macro math_extern, func
+ | .ffunc_n math_ .. func
+ | blex func
+ | b ->fff_resn
+ |.endmacro
+ |
+ |.macro math_extern2, func
+ | .ffunc_nn math_ .. func
+ | blex func
+ | b ->fff_resn
+ |.endmacro
+ |
+ |.macro math_round, func
+ | .ffunc_1 math_ .. func
+ | checknum CARG3; beqy ->fff_restv
+ | rlwinm TMP2, CARG3, 12, 21, 31
+ | bge ->fff_fallback
+ | addic. TMP2, TMP2, -1023 // exp = exponent(x) - 1023
+ | cmplwi cr1, TMP2, 31 // 0 <= exp < 31?
+ | subfic TMP0, TMP2, 31
+ | blt >3
+ | slwi TMP1, CARG3, 11
+ | srwi TMP3, CARG1, 21
+ | oris TMP1, TMP1, 0x8000
+ | addi TMP2, TMP2, 1
+ | or TMP1, TMP1, TMP3
+ | slwi CARG2, CARG1, 11
+ | bge cr1, >4
+ | slw TMP3, TMP1, TMP2
+ | srw RD, TMP1, TMP0
+ | or TMP3, TMP3, CARG2
+ | srawi TMP2, CARG3, 31
+ |.if "func" == "floor"
+ | and TMP1, TMP3, TMP2
+ | addic TMP0, TMP1, -1
+ | subfe TMP1, TMP0, TMP1
+ | add CARG1, RD, TMP1
+ | xor CARG1, CARG1, TMP2
+ | sub CARG1, CARG1, TMP2
+ | b ->fff_resi
+ |.else
+ | andc TMP1, TMP3, TMP2
+ | addic TMP0, TMP1, -1
+ | subfe TMP1, TMP0, TMP1
+ | add CARG1, RD, TMP1
+ | cmpw CARG1, RD
+ | xor CARG1, CARG1, TMP2
+ | sub CARG1, CARG1, TMP2
+ | bge ->fff_resi
+ | // Overflow to 2^31.
+ | lus CARG3, 0x41e0 // 2^31.
+ | li CARG1, 0
+ | b ->fff_restv
+ |.endif
+ |3: // |x| < 1
+ | slwi TMP2, CARG3, 1
+ | srawi TMP1, CARG3, 31
+ | or TMP2, CARG1, TMP2 // ztest = (hi+hi) | lo
+ |.if "func" == "floor"
+ | and TMP1, TMP2, TMP1 // (ztest & sign) == 0 ? 0 : -1
+ | subfic TMP2, TMP1, 0
+ | subfe CARG1, CARG1, CARG1
+ |.else
+ | andc TMP1, TMP2, TMP1 // (ztest & ~sign) == 0 ? 0 : 1
+ | addic TMP2, TMP1, -1
+ | subfe CARG1, TMP2, TMP1
+ |.endif
+ | b ->fff_resi
+ |4: // exp >= 31. Check for -(2^31).
+ | xoris TMP1, TMP1, 0x8000
+ | srawi TMP2, CARG3, 31
+ |.if "func" == "floor"
+ | or TMP1, TMP1, CARG2
+ |.endif
+ |.if PPE
+ | orc TMP1, TMP1, TMP2
+ | cmpwi TMP1, 0
+ |.else
+ | orc. TMP1, TMP1, TMP2
+ |.endif
+ | crand 4*cr0+eq, 4*cr0+eq, 4*cr1+eq
+ | lus CARG1, 0x8000 // -(2^31).
+ | beqy ->fff_resi
+ |5:
+ | lfd FARG1, 0(BASE)
+ | blex func
+ | b ->fff_resn
+ |.endmacro
+ |
+ |.if DUALNUM
+ | math_round floor
+ | math_round ceil
+ |.else
+ | // NYI: use internal implementation.
+ | math_extern floor
+ | math_extern ceil
+ |.endif
+ |
+ |.if SQRT
+ |.ffunc_n math_sqrt
+ | fsqrt FARG1, FARG1
+ | b ->fff_resn
+ |.else
+ | math_extern sqrt
+ |.endif
+ |
+ |.ffunc math_log
+ | cmplwi NARGS8:RC, 8
+ | lwz CARG3, 0(BASE)
+ | lfd FARG1, 0(BASE)
+ | bne ->fff_fallback // Need exactly 1 argument.
+ | checknum CARG3; bge ->fff_fallback
+ | blex log
+ | b ->fff_resn
+ |
+ | math_extern log10
+ | math_extern exp
+ | math_extern sin
+ | math_extern cos
+ | math_extern tan
+ | math_extern asin
+ | math_extern acos
+ | math_extern atan
+ | math_extern sinh
+ | math_extern cosh
+ | math_extern tanh
+ | math_extern2 pow
+ | math_extern2 atan2
+ | math_extern2 fmod
+ |
+ |->ff_math_deg:
+ |.ffunc_n math_rad
+ | lfd FARG2, CFUNC:RB->upvalue[0]
+ | fmul FARG1, FARG1, FARG2
+ | b ->fff_resn
+ |
+ |.if DUALNUM
+ |.ffunc math_ldexp
+ | cmplwi NARGS8:RC, 16
+ | lwz CARG3, 0(BASE)
+ | lfd FARG1, 0(BASE)
+ | lwz CARG4, 8(BASE)
+ |.if GPR64
+ | lwz CARG2, 12(BASE)
+ |.else
+ | lwz CARG1, 12(BASE)
+ |.endif
+ | blt ->fff_fallback
+ | checknum CARG3; bge ->fff_fallback
+ | checknum CARG4; bne ->fff_fallback
+ |.else
+ |.ffunc_nn math_ldexp
+ |.if GPR64
+ | toint CARG2, FARG2
+ |.else
+ | toint CARG1, FARG2
+ |.endif
+ |.endif
+ | blex ldexp
+ | b ->fff_resn
+ |
+ |.ffunc_n math_frexp
+ |.if GPR64
+ | la CARG2, DISPATCH_GL(tmptv)(DISPATCH)
+ |.else
+ | la CARG1, DISPATCH_GL(tmptv)(DISPATCH)
+ |.endif
+ | lwz PC, FRAME_PC(BASE)
+ | blex frexp
+ | lwz TMP1, DISPATCH_GL(tmptv)(DISPATCH)
+ | la RA, -8(BASE)
+ |.if not DUALNUM
+ | tonum_i FARG2, TMP1
+ |.endif
+ | stfd FARG1, 0(RA)
+ | li RD, (2+1)*8
+ |.if DUALNUM
+ | stw TISNUM, 8(RA)
+ | stw TMP1, 12(RA)
+ |.else
+ | stfd FARG2, 8(RA)
+ |.endif
+ | b ->fff_res
+ |
+ |.ffunc_n math_modf
+ |.if GPR64
+ | la CARG2, -8(BASE)
+ |.else
+ | la CARG1, -8(BASE)
+ |.endif
+ | lwz PC, FRAME_PC(BASE)
+ | blex modf
+ | la RA, -8(BASE)
+ | stfd FARG1, 0(BASE)
+ | li RD, (2+1)*8
+ | b ->fff_res
+ |
+ |.macro math_minmax, name, ismax
+ |.if DUALNUM
+ | .ffunc_1 name
+ | checknum CARG3
+ | addi TMP1, BASE, 8
+ | add TMP2, BASE, NARGS8:RC
+ | bne >4
+ |1: // Handle integers.
+ | lwz CARG4, 0(TMP1)
+ | cmplw cr1, TMP1, TMP2
+ | lwz CARG2, 4(TMP1)
+ | bge cr1, ->fff_resi
+ | checknum CARG4
+ | xoris TMP0, CARG1, 0x8000
+ | xoris TMP3, CARG2, 0x8000
+ | bne >3
+ | subfc TMP3, TMP3, TMP0
+ | subfe TMP0, TMP0, TMP0
+ |.if ismax
+ | andc TMP3, TMP3, TMP0
+ |.else
+ | and TMP3, TMP3, TMP0
+ |.endif
+ | add CARG1, TMP3, CARG2
+ |.if GPR64
+ | rldicl CARG1, CARG1, 0, 32
+ |.endif
+ | addi TMP1, TMP1, 8
+ | b <1
+ |3:
+ | bge ->fff_fallback
+ | // Convert intermediate result to number and continue below.
+ | tonum_i FARG1, CARG1
+ | lfd FARG2, 0(TMP1)
+ | b >6
+ |4:
+ | lfd FARG1, 0(BASE)
+ | bge ->fff_fallback
+ |5: // Handle numbers.
+ | lwz CARG4, 0(TMP1)
+ | cmplw cr1, TMP1, TMP2
+ | lfd FARG2, 0(TMP1)
+ | bge cr1, ->fff_resn
+ | checknum CARG4; bge >7
+ |6:
+ | fsub f0, FARG1, FARG2
+ | addi TMP1, TMP1, 8
+ |.if ismax
+ | fsel FARG1, f0, FARG1, FARG2
+ |.else
+ | fsel FARG1, f0, FARG2, FARG1
+ |.endif
+ | b <5
+ |7: // Convert integer to number and continue above.
+ | lwz CARG2, 4(TMP1)
+ | bne ->fff_fallback
+ | tonum_i FARG2, CARG2
+ | b <6
+ |.else
+ | .ffunc_n name
+ | li TMP1, 8
+ |1:
+ | lwzx CARG2, BASE, TMP1
+ | lfdx FARG2, BASE, TMP1
+ | cmplw cr1, TMP1, NARGS8:RC
+ | checknum CARG2
+ | bge cr1, ->fff_resn
+ | bge ->fff_fallback
+ | fsub f0, FARG1, FARG2
+ | addi TMP1, TMP1, 8
+ |.if ismax
+ | fsel FARG1, f0, FARG1, FARG2
+ |.else
+ | fsel FARG1, f0, FARG2, FARG1
+ |.endif
+ | b <1
+ |.endif
+ |.endmacro
+ |
+ | math_minmax math_min, 0
+ | math_minmax math_max, 1
+ |
+ |//-- String library -----------------------------------------------------
+ |
+ |.ffunc_1 string_len
+ | checkstr CARG3; bne ->fff_fallback
+ | lwz CRET1, STR:CARG1->len
+ | b ->fff_resi
+ |
+ |.ffunc string_byte // Only handle the 1-arg case here.
+ | cmplwi NARGS8:RC, 8
+ | lwz CARG3, 0(BASE)
+ | lwz STR:CARG1, 4(BASE)
+ | bne ->fff_fallback // Need exactly 1 argument.
+ | checkstr CARG3
+ | bne ->fff_fallback
+ | lwz TMP0, STR:CARG1->len
+ |.if DUALNUM
+ | lbz CARG1, STR:CARG1[1] // Access is always ok (NUL at end).
+ | li RD, (0+1)*8
+ | lwz PC, FRAME_PC(BASE)
+ | cmplwi TMP0, 0
+ | la RA, -8(BASE)
+ | beqy ->fff_res
+ | b ->fff_resi
+ |.else
+ | lbz TMP1, STR:CARG1[1] // Access is always ok (NUL at end).
+ | addic TMP3, TMP0, -1 // RD = ((str->len != 0)+1)*8
+ | subfe RD, TMP3, TMP0
+ | stw TMP1, TONUM_LO // Inlined tonum_u f0, TMP1.
+ | addi RD, RD, 1
+ | lfd f0, TONUM_D
+ | la RA, -8(BASE)
+ | lwz PC, FRAME_PC(BASE)
+ | fsub f0, f0, TOBIT
+ | slwi RD, RD, 3
+ | stfd f0, 0(RA)
+ | b ->fff_res
+ |.endif
+ |
+ |.ffunc string_char // Only handle the 1-arg case here.
+ | ffgccheck
+ | cmplwi NARGS8:RC, 8
+ | lwz CARG3, 0(BASE)
+ |.if DUALNUM
+ | lwz TMP0, 4(BASE)
+ | bne ->fff_fallback // Exactly 1 argument.
+ | checknum CARG3; bne ->fff_fallback
+ | la CARG2, 7(BASE)
+ |.else
+ | lfd FARG1, 0(BASE)
+ | bne ->fff_fallback // Exactly 1 argument.
+ | checknum CARG3; bge ->fff_fallback
+ | toint TMP0, FARG1
+ | la CARG2, TMPD_BLO
+ |.endif
+ | li CARG3, 1
+ | cmplwi TMP0, 255; bgt ->fff_fallback
+ |->fff_newstr:
+ | mr CARG1, L
+ | stp BASE, L->base
+ | stw PC, SAVE_PC
+ | bl extern lj_str_new // (lua_State *L, char *str, size_t l)
+ | // Returns GCstr *.
+ | lp BASE, L->base
+ | li CARG3, LJ_TSTR
+ | b ->fff_restv
+ |
+ |.ffunc string_sub
+ | ffgccheck
+ | cmplwi NARGS8:RC, 16
+ | lwz CARG3, 16(BASE)
+ |.if not DUALNUM
+ | lfd f0, 16(BASE)
+ |.endif
+ | lwz TMP0, 0(BASE)
+ | lwz STR:CARG1, 4(BASE)
+ | blt ->fff_fallback
+ | lwz CARG2, 8(BASE)
+ |.if DUALNUM
+ | lwz TMP1, 12(BASE)
+ |.else
+ | lfd f1, 8(BASE)
+ |.endif
+ | li TMP2, -1
+ | beq >1
+ |.if DUALNUM
+ | checknum CARG3
+ | lwz TMP2, 20(BASE)
+ | bne ->fff_fallback
+ |1:
+ | checknum CARG2; bne ->fff_fallback
+ |.else
+ | checknum CARG3; bge ->fff_fallback
+ | toint TMP2, f0
+ |1:
+ | checknum CARG2; bge ->fff_fallback
+ |.endif
+ | checkstr TMP0; bne ->fff_fallback
+ |.if not DUALNUM
+ | toint TMP1, f1
+ |.endif
+ | lwz TMP0, STR:CARG1->len
+ | cmplw TMP0, TMP2 // len < end? (unsigned compare)
+ | addi TMP3, TMP2, 1
+ | blt >5
+ |2:
+ | cmpwi TMP1, 0 // start <= 0?
+ | add TMP3, TMP1, TMP0
+ | ble >7
+ |3:
+ | sub CARG3, TMP2, TMP1
+ | addi CARG2, STR:CARG1, #STR-1
+ | srawi TMP0, CARG3, 31
+ | addi CARG3, CARG3, 1
+ | add CARG2, CARG2, TMP1
+ | andc CARG3, CARG3, TMP0
+ |.if GPR64
+ | rldicl CARG2, CARG2, 0, 32
+ | rldicl CARG3, CARG3, 0, 32
+ |.endif
+ | b ->fff_newstr
+ |
+ |5: // Negative end or overflow.
+ | cmpw TMP0, TMP2 // len >= end? (signed compare)
+ | add TMP2, TMP0, TMP3 // Negative end: end = end+len+1.
+ | bge <2
+ | mr TMP2, TMP0 // Overflow: end = len.
+ | b <2
+ |
+ |7: // Negative start or underflow.
+ | .gpr64 extsw TMP1, TMP1
+ | addic CARG3, TMP1, -1
+ | subfe CARG3, CARG3, CARG3
+ | srawi CARG2, TMP3, 31 // Note: modifies carry.
+ | andc TMP3, TMP3, CARG3
+ | andc TMP1, TMP3, CARG2
+ | addi TMP1, TMP1, 1 // start = 1 + (start ? start+len : 0)
+ | b <3
+ |
+ |.ffunc string_rep // Only handle the 1-char case inline.
+ | ffgccheck
+ | cmplwi NARGS8:RC, 16
+ | lwz TMP0, 0(BASE)
+ | lwz STR:CARG1, 4(BASE)
+ | lwz CARG4, 8(BASE)
+ |.if DUALNUM
+ | lwz CARG3, 12(BASE)
+ |.else
+ | lfd FARG2, 8(BASE)
+ |.endif
+ | bne ->fff_fallback // Exactly 2 arguments.
+ | checkstr TMP0; bne ->fff_fallback
+ |.if DUALNUM
+ | checknum CARG4; bne ->fff_fallback
+ |.else
+ | checknum CARG4; bge ->fff_fallback
+ | toint CARG3, FARG2
+ |.endif
+ | lwz TMP0, STR:CARG1->len
+ | cmpwi CARG3, 0
+ | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH)
+ | ble >2 // Count <= 0? (or non-int)
+ | cmplwi TMP0, 1
+ | subi TMP2, CARG3, 1
+ | blt >2 // Zero length string?
+ | cmplw cr1, TMP1, CARG3
+ | bne ->fff_fallback // Fallback for > 1-char strings.
+ | lbz TMP0, STR:CARG1[1]
+ | lp CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH)
+ | blt cr1, ->fff_fallback
+ |1: // Fill buffer with char. Yes, this is suboptimal code (do you care?).
+ | cmplwi TMP2, 0
+ | stbx TMP0, CARG2, TMP2
+ | subi TMP2, TMP2, 1
+ | bne <1
+ | b ->fff_newstr
+ |2: // Return empty string.
+ | la STR:CARG1, DISPATCH_GL(strempty)(DISPATCH)
+ | li CARG3, LJ_TSTR
+ | b ->fff_restv
+ |
+ |.ffunc string_reverse
+ | ffgccheck
+ | cmplwi NARGS8:RC, 8
+ | lwz CARG3, 0(BASE)
+ | lwz STR:CARG1, 4(BASE)
+ | blt ->fff_fallback
+ | checkstr CARG3
+ | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH)
+ | bne ->fff_fallback
+ | lwz CARG3, STR:CARG1->len
+ | la CARG1, #STR(STR:CARG1)
+ | lp CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH)
+ | li TMP2, 0
+ | cmplw TMP1, CARG3
+ | subi TMP3, CARG3, 1
+ | blt ->fff_fallback
+ |1: // Reverse string copy.
+ | cmpwi TMP3, 0
+ | lbzx TMP1, CARG1, TMP2
+ | blty ->fff_newstr
+ | stbx TMP1, CARG2, TMP3
+ | subi TMP3, TMP3, 1
+ | addi TMP2, TMP2, 1
+ | b <1
+ |
+ |.macro ffstring_case, name, lo
+ | .ffunc name
+ | ffgccheck
+ | cmplwi NARGS8:RC, 8
+ | lwz CARG3, 0(BASE)
+ | lwz STR:CARG1, 4(BASE)
+ | blt ->fff_fallback
+ | checkstr CARG3
+ | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH)
+ | bne ->fff_fallback
+ | lwz CARG3, STR:CARG1->len
+ | la CARG1, #STR(STR:CARG1)
+ | lp CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH)
+ | cmplw TMP1, CARG3
+ | li TMP2, 0
+ | blt ->fff_fallback
+ |1: // ASCII case conversion.
+ | cmplw TMP2, CARG3
+ | lbzx TMP1, CARG1, TMP2
+ | bgey ->fff_newstr
+ | subi TMP0, TMP1, lo
+ | xori TMP3, TMP1, 0x20
+ | addic TMP0, TMP0, -26
+ | subfe TMP3, TMP3, TMP3
+ | rlwinm TMP3, TMP3, 0, 26, 26 // x &= 0x20.
+ | xor TMP1, TMP1, TMP3
+ | stbx TMP1, CARG2, TMP2
+ | addi TMP2, TMP2, 1
+ | b <1
+ |.endmacro
+ |
+ |ffstring_case string_lower, 65
+ |ffstring_case string_upper, 97
+ |
+ |//-- Table library ------------------------------------------------------
+ |
+ |.ffunc_1 table_getn
+ | checktab CARG3; bne ->fff_fallback
+ | bl extern lj_tab_len // (GCtab *t)
+ | // Returns uint32_t (but less than 2^31).
+ | b ->fff_resi
+ |
+ |//-- Bit library --------------------------------------------------------
+ |
+ |.macro .ffunc_bit, name
+ |.if DUALNUM
+ | .ffunc_1 bit_..name
+ | checknum CARG3; bnel ->fff_tobit_fb
+ |.else
+ | .ffunc_n bit_..name
+ | fadd FARG1, FARG1, TOBIT
+ | stfd FARG1, TMPD
+ | lwz CARG1, TMPD_LO
+ |.endif
+ |.endmacro
+ |
+ |.macro .ffunc_bit_op, name, ins
+ | .ffunc_bit name
+ | addi TMP1, BASE, 8
+ | add TMP2, BASE, NARGS8:RC
+ |1:
+ | lwz CARG4, 0(TMP1)
+ | cmplw cr1, TMP1, TMP2
+ |.if DUALNUM
+ | lwz CARG2, 4(TMP1)
+ |.else
+ | lfd FARG1, 0(TMP1)
+ |.endif
+ | bgey cr1, ->fff_resi
+ | checknum CARG4
+ |.if DUALNUM
+ | bnel ->fff_bitop_fb
+ |.else
+ | fadd FARG1, FARG1, TOBIT
+ | bge ->fff_fallback
+ | stfd FARG1, TMPD
+ | lwz CARG2, TMPD_LO
+ |.endif
+ | ins CARG1, CARG1, CARG2
+ | addi TMP1, TMP1, 8
+ | b <1
+ |.endmacro
+ |
+ |.ffunc_bit_op band, and
+ |.ffunc_bit_op bor, or
+ |.ffunc_bit_op bxor, xor
+ |
+ |.ffunc_bit bswap
+ | rotlwi TMP0, CARG1, 8
+ | rlwimi TMP0, CARG1, 24, 0, 7
+ | rlwimi TMP0, CARG1, 24, 16, 23
+ | mr CRET1, TMP0
+ | b ->fff_resi
+ |
+ |.ffunc_bit bnot
+ | not CRET1, CARG1
+ | b ->fff_resi
+ |
+ |.macro .ffunc_bit_sh, name, ins, shmod
+ |.if DUALNUM
+ | .ffunc_2 bit_..name
+ | checknum CARG3; bnel ->fff_tobit_fb
+ | // Note: no inline conversion from number for 2nd argument!
+ | checknum CARG4; bne ->fff_fallback
+ |.else
+ | .ffunc_nn bit_..name
+ | fadd FARG1, FARG1, TOBIT
+ | fadd FARG2, FARG2, TOBIT
+ | stfd FARG1, TMPD
+ | lwz CARG1, TMPD_LO
+ | stfd FARG2, TMPD
+ | lwz CARG2, TMPD_LO
+ |.endif
+ |.if shmod == 1
+ | rlwinm CARG2, CARG2, 0, 27, 31
+ |.elif shmod == 2
+ | neg CARG2, CARG2
+ |.endif
+ | ins CRET1, CARG1, CARG2
+ | b ->fff_resi
+ |.endmacro
+ |
+ |.ffunc_bit_sh lshift, slw, 1
+ |.ffunc_bit_sh rshift, srw, 1
+ |.ffunc_bit_sh arshift, sraw, 1
+ |.ffunc_bit_sh rol, rotlw, 0
+ |.ffunc_bit_sh ror, rotlw, 2
+ |
+ |.ffunc_bit tobit
+ |.if DUALNUM
+ | b ->fff_resi
+ |.else
+ |->fff_resi:
+ | tonum_i FARG1, CRET1
+ |.endif
+ |->fff_resn:
+ | lwz PC, FRAME_PC(BASE)
+ | la RA, -8(BASE)
+ | stfd FARG1, -8(BASE)
+ | b ->fff_res1
+ |
+ |// Fallback FP number to bit conversion.
+ |->fff_tobit_fb:
+ |.if DUALNUM
+ | lfd FARG1, 0(BASE)
+ | bgt ->fff_fallback
+ | fadd FARG1, FARG1, TOBIT
+ | stfd FARG1, TMPD
+ | lwz CARG1, TMPD_LO
+ | blr
+ |.endif
+ |->fff_bitop_fb:
+ |.if DUALNUM
+ | lfd FARG1, 0(TMP1)
+ | bgt ->fff_fallback
+ | fadd FARG1, FARG1, TOBIT
+ | stfd FARG1, TMPD
+ | lwz CARG2, TMPD_LO
+ | blr
+ |.endif
+ |
+ |//-----------------------------------------------------------------------
+ |
+ |->fff_fallback: // Call fast function fallback handler.
+ | // BASE = new base, RB = CFUNC, RC = nargs*8
+ | lp TMP3, CFUNC:RB->f
+ | add TMP1, BASE, NARGS8:RC
+ | lwz PC, FRAME_PC(BASE) // Fallback may overwrite PC.
+ | addi TMP0, TMP1, 8*LUA_MINSTACK
+ | lwz TMP2, L->maxstack
+ | stw PC, SAVE_PC // Redundant (but a defined value).
+ | .toc lp TMP3, 0(TMP3)
+ | cmplw TMP0, TMP2
+ | stp BASE, L->base
+ | stp TMP1, L->top
+ | mr CARG1, L
+ | bgt >5 // Need to grow stack.
+ | mtctr TMP3
+ | bctrl // (lua_State *L)
+ | // Either throws an error, or recovers and returns -1, 0 or nresults+1.
+ | lp BASE, L->base
+ | cmpwi CRET1, 0
+ | slwi RD, CRET1, 3
+ | la RA, -8(BASE)
+ | bgt ->fff_res // Returned nresults+1?
+ |1: // Returned 0 or -1: retry fast path.
+ | lp TMP0, L->top
+ | lwz LFUNC:RB, FRAME_FUNC(BASE)
+ | sub NARGS8:RC, TMP0, BASE
+ | bne ->vm_call_tail // Returned -1?
+ | ins_callt // Returned 0: retry fast path.
+ |
+ |// Reconstruct previous base for vmeta_call during tailcall.
+ |->vm_call_tail:
+ | andix. TMP0, PC, FRAME_TYPE
+ | rlwinm TMP1, PC, 0, 0, 28
+ | bne >3
+ | lwz INS, -4(PC)
+ | decode_RA8 TMP1, INS
+ | addi TMP1, TMP1, 8
+ |3:
+ | sub TMP2, BASE, TMP1
+ | b ->vm_call_dispatch // Resolve again for tailcall.
+ |
+ |5: // Grow stack for fallback handler.
+ | li CARG2, LUA_MINSTACK
+ | bl extern lj_state_growstack // (lua_State *L, int n)
+ | lp BASE, L->base
+ | cmpw TMP0, TMP0 // Set 4*cr0+eq to force retry.
+ | b <1
+ |
+ |->fff_gcstep: // Call GC step function.
+ | // BASE = new base, RC = nargs*8
+ | mflr SAVE0
+ | stp BASE, L->base
+ | add TMP0, BASE, NARGS8:RC
+ | stw PC, SAVE_PC // Redundant (but a defined value).
+ | stp TMP0, L->top
+ | mr CARG1, L
+ | bl extern lj_gc_step // (lua_State *L)
+ | lp BASE, L->base
+ | mtlr SAVE0
+ | lp TMP0, L->top
+ | sub NARGS8:RC, TMP0, BASE
+ | lwz CFUNC:RB, FRAME_FUNC(BASE)
+ | blr
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Special dispatch targets -------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_record: // Dispatch target for recording phase.
+ |.if JIT
+ | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)
+ | andix. TMP0, TMP3, HOOK_VMEVENT // No recording while in vmevent.
+ | bne >5
+ | // Decrement the hookcount for consistency, but always do the call.
+ | lwz TMP2, DISPATCH_GL(hookcount)(DISPATCH)
+ | andix. TMP0, TMP3, HOOK_ACTIVE
+ | bne >1
+ | subi TMP2, TMP2, 1
+ | andi. TMP0, TMP3, LUA_MASKLINE|LUA_MASKCOUNT
+ | beqy >1
+ | stw TMP2, DISPATCH_GL(hookcount)(DISPATCH)
+ | b >1
+ |.endif
+ |
+ |->vm_rethook: // Dispatch target for return hooks.
+ | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)
+ | andix. TMP0, TMP3, HOOK_ACTIVE // Hook already active?
+ | beq >1
+ |5: // Re-dispatch to static ins.
+ | addi TMP1, TMP1, GG_DISP2STATIC // Assumes decode_OPP TMP1, INS.
+ | lpx TMP0, DISPATCH, TMP1
+ | mtctr TMP0
+ | bctr
+ |
+ |->vm_inshook: // Dispatch target for instr/line hooks.
+ | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)
+ | lwz TMP2, DISPATCH_GL(hookcount)(DISPATCH)
+ | andix. TMP0, TMP3, HOOK_ACTIVE // Hook already active?
+ | rlwinm TMP0, TMP3, 31-LUA_HOOKLINE, 31, 0
+ | bne <5
+ |
+ | cmpwi cr1, TMP0, 0
+ | addic. TMP2, TMP2, -1
+ | beq cr1, <5
+ | stw TMP2, DISPATCH_GL(hookcount)(DISPATCH)
+ | beq >1
+ | bge cr1, <5
+ |1:
+ | mr CARG1, L
+ | stw MULTRES, SAVE_MULTRES
+ | mr CARG2, PC
+ | stp BASE, L->base
+ | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.
+ | bl extern lj_dispatch_ins // (lua_State *L, const BCIns *pc)
+ |3:
+ | lp BASE, L->base
+ |4: // Re-dispatch to static ins.
+ | lwz INS, -4(PC)
+ | decode_OPP TMP1, INS
+ | decode_RB8 RB, INS
+ | addi TMP1, TMP1, GG_DISP2STATIC
+ | decode_RD8 RD, INS
+ | lpx TMP0, DISPATCH, TMP1
+ | decode_RA8 RA, INS
+ | decode_RC8 RC, INS
+ | mtctr TMP0
+ | bctr
+ |
+ |->cont_hook: // Continue from hook yield.
+ | addi PC, PC, 4
+ | lwz MULTRES, -20(RB) // Restore MULTRES for *M ins.
+ | b <4
+ |
+ |->vm_hotloop: // Hot loop counter underflow.
+ |.if JIT
+ | lwz LFUNC:TMP1, FRAME_FUNC(BASE)
+ | addi CARG1, DISPATCH, GG_DISP2J
+ | stw PC, SAVE_PC
+ | lwz TMP1, LFUNC:TMP1->pc
+ | mr CARG2, PC
+ | stw L, DISPATCH_J(L)(DISPATCH)
+ | lbz TMP1, PC2PROTO(framesize)(TMP1)
+ | stp BASE, L->base
+ | slwi TMP1, TMP1, 3
+ | add TMP1, BASE, TMP1
+ | stp TMP1, L->top
+ | bl extern lj_trace_hot // (jit_State *J, const BCIns *pc)
+ | b <3
+ |.endif
+ |
+ |->vm_callhook: // Dispatch target for call hooks.
+ | mr CARG2, PC
+ |.if JIT
+ | b >1
+ |.endif
+ |
+ |->vm_hotcall: // Hot call counter underflow.
+ |.if JIT
+ | ori CARG2, PC, 1
+ |1:
+ |.endif
+ | add TMP0, BASE, RC
+ | stw PC, SAVE_PC
+ | mr CARG1, L
+ | stp BASE, L->base
+ | sub RA, RA, BASE
+ | stp TMP0, L->top
+ | bl extern lj_dispatch_call // (lua_State *L, const BCIns *pc)
+ | // Returns ASMFunction.
+ | lp BASE, L->base
+ | lp TMP0, L->top
+ | stw ZERO, SAVE_PC // Invalidate for subsequent line hook.
+ | sub NARGS8:RC, TMP0, BASE
+ | add RA, BASE, RA
+ | lwz LFUNC:RB, FRAME_FUNC(BASE)
+ | lwz INS, -4(PC)
+ | mtctr CRET1
+ | bctr
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Trace exit handler -------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |.macro savex_, a, b, c, d
+ | stfd f..a, 16+a*8(sp)
+ | stfd f..b, 16+b*8(sp)
+ | stfd f..c, 16+c*8(sp)
+ | stfd f..d, 16+d*8(sp)
+ |.endmacro
+ |
+ |->vm_exit_handler:
+ |.if JIT
+ | addi sp, sp, -(16+32*8+32*4)
+ | stmw r2, 16+32*8+2*4(sp)
+ | addi DISPATCH, JGL, -GG_DISP2G-32768
+ | li CARG2, ~LJ_VMST_EXIT
+ | lwz CARG1, 16+32*8+32*4(sp) // Get stack chain.
+ | stw CARG2, DISPATCH_GL(vmstate)(DISPATCH)
+ | savex_ 0,1,2,3
+ | stw CARG1, 0(sp) // Store extended stack chain.
+ | clrso TMP1
+ | savex_ 4,5,6,7
+ | addi CARG2, sp, 16+32*8+32*4 // Recompute original value of sp.
+ | savex_ 8,9,10,11
+ | stw CARG2, 16+32*8+1*4(sp) // Store sp in RID_SP.
+ | savex_ 12,13,14,15
+ | mflr CARG3
+ | li TMP1, 0
+ | savex_ 16,17,18,19
+ | stw TMP1, 16+32*8+0*4(sp) // Clear RID_TMP.
+ | savex_ 20,21,22,23
+ | lhz CARG4, 2(CARG3) // Load trace number.
+ | savex_ 24,25,26,27
+ | lwz L, DISPATCH_GL(jit_L)(DISPATCH)
+ | savex_ 28,29,30,31
+ | sub CARG3, TMP0, CARG3 // Compute exit number.
+ | lp BASE, DISPATCH_GL(jit_base)(DISPATCH)
+ | srwi CARG3, CARG3, 2
+ | stw L, DISPATCH_J(L)(DISPATCH)
+ | subi CARG3, CARG3, 2
+ | stw TMP1, DISPATCH_GL(jit_L)(DISPATCH)
+ | stw CARG4, DISPATCH_J(parent)(DISPATCH)
+ | stp BASE, L->base
+ | addi CARG1, DISPATCH, GG_DISP2J
+ | stw CARG3, DISPATCH_J(exitno)(DISPATCH)
+ | addi CARG2, sp, 16
+ | bl extern lj_trace_exit // (jit_State *J, ExitState *ex)
+ | // Returns MULTRES (unscaled) or negated error code.
+ | lp TMP1, L->cframe
+ | lwz TMP2, 0(sp)
+ | lp BASE, L->base
+ |.if GPR64
+ | rldicr sp, TMP1, 0, 61
+ |.else
+ | rlwinm sp, TMP1, 0, 0, 29
+ |.endif
+ | lwz PC, SAVE_PC // Get SAVE_PC.
+ | stw TMP2, 0(sp)
+ | stw L, SAVE_L // Set SAVE_L (on-trace resume/yield).
+ | b >1
+ |.endif
+ |->vm_exit_interp:
+ |.if JIT
+ | // CARG1 = MULTRES or negated error code, BASE, PC and JGL set.
+ | lwz L, SAVE_L
+ | addi DISPATCH, JGL, -GG_DISP2G-32768
+ |1:
+ | cmpwi CARG1, 0
+ | blt >3 // Check for error from exit.
+ | lwz LFUNC:TMP1, FRAME_FUNC(BASE)
+ | slwi MULTRES, CARG1, 3
+ | li TMP2, 0
+ | stw MULTRES, SAVE_MULTRES
+ | lwz TMP1, LFUNC:TMP1->pc
+ | stw TMP2, DISPATCH_GL(jit_L)(DISPATCH)
+ | lwz KBASE, PC2PROTO(k)(TMP1)
+ | // Setup type comparison constants.
+ | li TISNUM, LJ_TISNUM
+ | lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
+ | stw TMP3, TMPD
+ | li ZERO, 0
+ | ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float).
+ | lfs TOBIT, TMPD
+ | stw TMP3, TMPD
+ | lus TMP0, 0x4338 // Hiword of 2^52 + 2^51 (double)
+ | li TISNIL, LJ_TNIL
+ | stw TMP0, TONUM_HI
+ | lfs TONUM, TMPD
+ | // Modified copy of ins_next which handles function header dispatch, too.
+ | lwz INS, 0(PC)
+ | addi PC, PC, 4
+ | // Assumes TISNIL == ~LJ_VMST_INTERP == -1.
+ | stw TISNIL, DISPATCH_GL(vmstate)(DISPATCH)
+ | decode_OPP TMP1, INS
+ | decode_RA8 RA, INS
+ | lpx TMP0, DISPATCH, TMP1
+ | mtctr TMP0
+ | cmplwi TMP1, BC_FUNCF*4 // Function header?
+ | bge >2
+ | decode_RB8 RB, INS
+ | decode_RD8 RD, INS
+ | decode_RC8 RC, INS
+ | bctr
+ |2:
+ | subi RC, MULTRES, 8
+ | add RA, RA, BASE
+ | bctr
+ |
+ |3: // Rethrow error from the right C frame.
+ | neg CARG2, CARG1
+ | mr CARG1, L
+ | bl extern lj_err_throw // (lua_State *L, int errcode)
+ |.endif
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Math helper functions ----------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |// NYI: Use internal implementations of floor, ceil, trunc.
+ |
+ |->vm_modi:
+ | divwo. TMP0, CARG1, CARG2
+ | bso >1
+ |.if GPR64
+ | xor CARG3, CARG1, CARG2
+ | cmpwi CARG3, 0
+ |.else
+ | xor. CARG3, CARG1, CARG2
+ |.endif
+ | mullw TMP0, TMP0, CARG2
+ | sub CARG1, CARG1, TMP0
+ | bgelr
+ | cmpwi CARG1, 0; beqlr
+ | add CARG1, CARG1, CARG2
+ | blr
+ |1:
+ | cmpwi CARG2, 0
+ | li CARG1, 0
+ | beqlr
+ | clrso TMP0 // Clear SO for -2147483648 % -1 and return 0.
+ | blr
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Miscellaneous functions --------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |// void lj_vm_cachesync(void *start, void *end)
+ |// Flush D-Cache and invalidate I-Cache. Assumes 32 byte cache line size.
+ |// This is a good lower bound, except for very ancient PPC models.
+ |->vm_cachesync:
+ |.if JIT or FFI
+ | // Compute start of first cache line and number of cache lines.
+ | rlwinm CARG1, CARG1, 0, 0, 26
+ | sub CARG2, CARG2, CARG1
+ | addi CARG2, CARG2, 31
+ | rlwinm. CARG2, CARG2, 27, 5, 31
+ | beqlr
+ | mtctr CARG2
+ | mr CARG3, CARG1
+ |1: // Flush D-Cache.
+ | dcbst r0, CARG1
+ | addi CARG1, CARG1, 32
+ | bdnz <1
+ | sync
+ | mtctr CARG2
+ |1: // Invalidate I-Cache.
+ | icbi r0, CARG3
+ | addi CARG3, CARG3, 32
+ | bdnz <1
+ | isync
+ | blr
+ |.endif
+ |
+ |//-----------------------------------------------------------------------
+ |//-- FFI helper functions -----------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |// Handler for callback functions. Callback slot number in r11, g in r12.
+ |->vm_ffi_callback:
+ |.if FFI
+ |.type CTSTATE, CTState, PC
+ | saveregs
+ | lwz CTSTATE, GL:r12->ctype_state
+ | addi DISPATCH, r12, GG_G2DISP
+ | stw r11, CTSTATE->cb.slot
+ | stw r3, CTSTATE->cb.gpr[0]
+ | stfd f1, CTSTATE->cb.fpr[0]
+ | stw r4, CTSTATE->cb.gpr[1]
+ | stfd f2, CTSTATE->cb.fpr[1]
+ | stw r5, CTSTATE->cb.gpr[2]
+ | stfd f3, CTSTATE->cb.fpr[2]
+ | stw r6, CTSTATE->cb.gpr[3]
+ | stfd f4, CTSTATE->cb.fpr[3]
+ | stw r7, CTSTATE->cb.gpr[4]
+ | stfd f5, CTSTATE->cb.fpr[4]
+ | stw r8, CTSTATE->cb.gpr[5]
+ | stfd f6, CTSTATE->cb.fpr[5]
+ | stw r9, CTSTATE->cb.gpr[6]
+ | stfd f7, CTSTATE->cb.fpr[6]
+ | stw r10, CTSTATE->cb.gpr[7]
+ | stfd f8, CTSTATE->cb.fpr[7]
+ | addi TMP0, sp, CFRAME_SPACE+8
+ | stw TMP0, CTSTATE->cb.stack
+ | mr CARG1, CTSTATE
+ | stw CTSTATE, SAVE_PC // Any value outside of bytecode is ok.
+ | mr CARG2, sp
+ | bl extern lj_ccallback_enter // (CTState *cts, void *cf)
+ | // Returns lua_State *.
+ | lp BASE, L:CRET1->base
+ | li TISNUM, LJ_TISNUM // Setup type comparison constants.
+ | lp RC, L:CRET1->top
+ | lus TMP3, 0x59c0 // TOBIT = 2^52 + 2^51 (float).
+ | li ZERO, 0
+ | mr L, CRET1
+ | stw TMP3, TMPD
+ | lus TMP0, 0x4338 // Hiword of 2^52 + 2^51 (double)
+ | lwz LFUNC:RB, FRAME_FUNC(BASE)
+ | ori TMP3, TMP3, 0x0004 // TONUM = 2^52 + 2^51 + 2^31 (float).
+ | stw TMP0, TONUM_HI
+ | li TISNIL, LJ_TNIL
+ | li_vmstate INTERP
+ | lfs TOBIT, TMPD
+ | stw TMP3, TMPD
+ | sub RC, RC, BASE
+ | st_vmstate
+ | lfs TONUM, TMPD
+ | ins_callt
+ |.endif
+ |
+ |->cont_ffi_callback: // Return from FFI callback.
+ |.if FFI
+ | lwz CTSTATE, DISPATCH_GL(ctype_state)(DISPATCH)
+ | stp BASE, L->base
+ | stp RB, L->top
+ | stp L, CTSTATE->L
+ | mr CARG1, CTSTATE
+ | mr CARG2, RA
+ | bl extern lj_ccallback_leave // (CTState *cts, TValue *o)
+ | lwz CRET1, CTSTATE->cb.gpr[0]
+ | lfd FARG1, CTSTATE->cb.fpr[0]
+ | lwz CRET2, CTSTATE->cb.gpr[1]
+ | b ->vm_leave_unw
+ |.endif
+ |
+ |->vm_ffi_call: // Call C function via FFI.
+ | // Caveat: needs special frame unwinding, see below.
+ |.if FFI
+ | .type CCSTATE, CCallState, CARG1
+ | lwz TMP1, CCSTATE->spadj
+ | mflr TMP0
+ | lbz CARG2, CCSTATE->nsp
+ | lbz CARG3, CCSTATE->nfpr
+ | neg TMP1, TMP1
+ | stw TMP0, 4(sp)
+ | cmpwi cr1, CARG3, 0
+ | mr TMP2, sp
+ | addic. CARG2, CARG2, -1
+ | stwux sp, sp, TMP1
+ | crnot 4*cr1+eq, 4*cr1+eq // For vararg calls.
+ | stw r14, -4(TMP2)
+ | stw CCSTATE, -8(TMP2)
+ | mr r14, TMP2
+ | la TMP1, CCSTATE->stack
+ | slwi CARG2, CARG2, 2
+ | blty >2
+ | la TMP2, 8(sp)
+ |1:
+ | lwzx TMP0, TMP1, CARG2
+ | stwx TMP0, TMP2, CARG2
+ | addic. CARG2, CARG2, -4
+ | bge <1
+ |2:
+ | bney cr1, >3
+ | lfd f1, CCSTATE->fpr[0]
+ | lfd f2, CCSTATE->fpr[1]
+ | lfd f3, CCSTATE->fpr[2]
+ | lfd f4, CCSTATE->fpr[3]
+ | lfd f5, CCSTATE->fpr[4]
+ | lfd f6, CCSTATE->fpr[5]
+ | lfd f7, CCSTATE->fpr[6]
+ | lfd f8, CCSTATE->fpr[7]
+ |3:
+ | lp TMP0, CCSTATE->func
+ | lwz CARG2, CCSTATE->gpr[1]
+ | lwz CARG3, CCSTATE->gpr[2]
+ | lwz CARG4, CCSTATE->gpr[3]
+ | lwz CARG5, CCSTATE->gpr[4]
+ | mtctr TMP0
+ | lwz r8, CCSTATE->gpr[5]
+ | lwz r9, CCSTATE->gpr[6]
+ | lwz r10, CCSTATE->gpr[7]
+ | lwz CARG1, CCSTATE->gpr[0] // Do this last, since CCSTATE is CARG1.
+ | bctrl
+ | lwz CCSTATE:TMP1, -8(r14)
+ | lwz TMP2, -4(r14)
+ | lwz TMP0, 4(r14)
+ | stw CARG1, CCSTATE:TMP1->gpr[0]
+ | stfd FARG1, CCSTATE:TMP1->fpr[0]
+ | stw CARG2, CCSTATE:TMP1->gpr[1]
+ | mtlr TMP0
+ | stw CARG3, CCSTATE:TMP1->gpr[2]
+ | mr sp, r14
+ | stw CARG4, CCSTATE:TMP1->gpr[3]
+ | mr r14, TMP2
+ | blr
+ |.endif
+ |// Note: vm_ffi_call must be the last function in this object file!
+ |
+ |//-----------------------------------------------------------------------
+}
+
+/* Generate the code for a single instruction. */
+static void build_ins(BuildCtx *ctx, BCOp op, int defop)
+{
+ int vk = 0;
+ |=>defop:
+
+ switch (op) {
+
+ /* -- Comparison ops ---------------------------------------------------- */
+
+ /* Remember: all ops branch for a true comparison, fall through otherwise. */
+
+ case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:
+ | // RA = src1*8, RD = src2*8, JMP with RD = target
+ |.if DUALNUM
+ | lwzux TMP0, RA, BASE
+ | addi PC, PC, 4
+ | lwz CARG2, 4(RA)
+ | lwzux TMP1, RD, BASE
+ | lwz TMP2, -4(PC)
+ | checknum cr0, TMP0
+ | lwz CARG3, 4(RD)
+ | decode_RD4 TMP2, TMP2
+ | checknum cr1, TMP1
+ | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)
+ | bne cr0, >7
+ | bne cr1, >8
+ | cmpw CARG2, CARG3
+ if (op == BC_ISLT) {
+ | bge >2
+ } else if (op == BC_ISGE) {
+ | blt >2
+ } else if (op == BC_ISLE) {
+ | bgt >2
+ } else {
+ | ble >2
+ }
+ |1:
+ | add PC, PC, TMP2
+ |2:
+ | ins_next
+ |
+ |7: // RA is not an integer.
+ | bgt cr0, ->vmeta_comp
+ | // RA is a number.
+ | lfd f0, 0(RA)
+ | bgt cr1, ->vmeta_comp
+ | blt cr1, >4
+ | // RA is a number, RD is an integer.
+ | tonum_i f1, CARG3
+ | b >5
+ |
+ |8: // RA is an integer, RD is not an integer.
+ | bgt cr1, ->vmeta_comp
+ | // RA is an integer, RD is a number.
+ | tonum_i f0, CARG2
+ |4:
+ | lfd f1, 0(RD)
+ |5:
+ | fcmpu cr0, f0, f1
+ if (op == BC_ISLT) {
+ | bge <2
+ } else if (op == BC_ISGE) {
+ | blt <2
+ } else if (op == BC_ISLE) {
+ | cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq
+ | bge <2
+ } else {
+ | cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq
+ | blt <2
+ }
+ | b <1
+ |.else
+ | lwzx TMP0, BASE, RA
+ | addi PC, PC, 4
+ | lfdx f0, BASE, RA
+ | lwzx TMP1, BASE, RD
+ | checknum cr0, TMP0
+ | lwz TMP2, -4(PC)
+ | lfdx f1, BASE, RD
+ | checknum cr1, TMP1
+ | decode_RD4 TMP2, TMP2
+ | bge cr0, ->vmeta_comp
+ | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)
+ | bge cr1, ->vmeta_comp
+ | fcmpu cr0, f0, f1
+ if (op == BC_ISLT) {
+ | bge >1
+ } else if (op == BC_ISGE) {
+ | blt >1
+ } else if (op == BC_ISLE) {
+ | cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq
+ | bge >1
+ } else {
+ | cror 4*cr0+lt, 4*cr0+lt, 4*cr0+eq
+ | blt >1
+ }
+ | add PC, PC, TMP2
+ |1:
+ | ins_next
+ |.endif
+ break;
+
+ case BC_ISEQV: case BC_ISNEV:
+ vk = op == BC_ISEQV;
+ | // RA = src1*8, RD = src2*8, JMP with RD = target
+ |.if DUALNUM
+ | lwzux TMP0, RA, BASE
+ | addi PC, PC, 4
+ | lwz CARG2, 4(RA)
+ | lwzux TMP1, RD, BASE
+ | checknum cr0, TMP0
+ | lwz TMP2, -4(PC)
+ | checknum cr1, TMP1
+ | decode_RD4 TMP2, TMP2
+ | lwz CARG3, 4(RD)
+ | cror 4*cr7+gt, 4*cr0+gt, 4*cr1+gt
+ | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)
+ if (vk) {
+ | ble cr7, ->BC_ISEQN_Z
+ } else {
+ | ble cr7, ->BC_ISNEN_Z
+ }
+ |.else
+ | lwzux TMP0, RA, BASE
+ | lwz TMP2, 0(PC)
+ | lfd f0, 0(RA)
+ | addi PC, PC, 4
+ | lwzux TMP1, RD, BASE
+ | checknum cr0, TMP0
+ | decode_RD4 TMP2, TMP2
+ | lfd f1, 0(RD)
+ | checknum cr1, TMP1
+ | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)
+ | bge cr0, >5
+ | bge cr1, >5
+ | fcmpu cr0, f0, f1
+ if (vk) {
+ | bne >1
+ | add PC, PC, TMP2
+ } else {
+ | beq >1
+ | add PC, PC, TMP2
+ }
+ |1:
+ | ins_next
+ |.endif
+ |5: // Either or both types are not numbers.
+ |.if not DUALNUM
+ | lwz CARG2, 4(RA)
+ | lwz CARG3, 4(RD)
+ |.endif
+ |.if FFI
+ | cmpwi cr7, TMP0, LJ_TCDATA
+ | cmpwi cr5, TMP1, LJ_TCDATA
+ |.endif
+ | not TMP3, TMP0
+ | cmplw TMP0, TMP1
+ | cmplwi cr1, TMP3, ~LJ_TISPRI // Primitive?
+ |.if FFI
+ | cror 4*cr7+eq, 4*cr7+eq, 4*cr5+eq
+ |.endif
+ | cmplwi cr6, TMP3, ~LJ_TISTABUD // Table or userdata?
+ |.if FFI
+ | beq cr7, ->vmeta_equal_cd
+ |.endif
+ | cmplw cr5, CARG2, CARG3
+ | crandc 4*cr0+gt, 4*cr0+eq, 4*cr1+gt // 2: Same type and primitive.
+ | crorc 4*cr0+lt, 4*cr5+eq, 4*cr0+eq // 1: Same tv or different type.
+ | crand 4*cr0+eq, 4*cr0+eq, 4*cr5+eq // 0: Same type and same tv.
+ | mr SAVE0, PC
+ | cror 4*cr0+eq, 4*cr0+eq, 4*cr0+gt // 0 or 2.
+ | cror 4*cr0+lt, 4*cr0+lt, 4*cr0+gt // 1 or 2.
+ if (vk) {
+ | bne cr0, >6
+ | add PC, PC, TMP2
+ |6:
+ } else {
+ | beq cr0, >6
+ | add PC, PC, TMP2
+ |6:
+ }
+ |.if DUALNUM
+ | bge cr0, >2 // Done if 1 or 2.
+ |1:
+ | ins_next
+ |2:
+ |.else
+ | blt cr0, <1 // Done if 1 or 2.
+ |.endif
+ | blt cr6, <1 // Done if not tab/ud.
+ |
+ | // Different tables or userdatas. Need to check __eq metamethod.
+ | // Field metatable must be at same offset for GCtab and GCudata!
+ | lwz TAB:TMP2, TAB:CARG2->metatable
+ | li CARG4, 1-vk // ne = 0 or 1.
+ | cmplwi TAB:TMP2, 0
+ | beq <1 // No metatable?
+ | lbz TMP2, TAB:TMP2->nomm
+ | andix. TMP2, TMP2, 1<<MM_eq
+ | bne <1 // Or 'no __eq' flag set?
+ | mr PC, SAVE0 // Restore old PC.
+ | b ->vmeta_equal // Handle __eq metamethod.
+ break;
+
+ case BC_ISEQS: case BC_ISNES:
+ vk = op == BC_ISEQS;
+ | // RA = src*8, RD = str_const*8 (~), JMP with RD = target
+ | lwzux TMP0, RA, BASE
+ | srwi RD, RD, 1
+ | lwz STR:TMP3, 4(RA)
+ | lwz TMP2, 0(PC)
+ | subfic RD, RD, -4
+ | addi PC, PC, 4
+ |.if FFI
+ | cmpwi TMP0, LJ_TCDATA
+ |.endif
+ | lwzx STR:TMP1, KBASE, RD // KBASE-4-str_const*4
+ | .gpr64 extsw TMP0, TMP0
+ | subfic TMP0, TMP0, LJ_TSTR
+ |.if FFI
+ | beq ->vmeta_equal_cd
+ |.endif
+ | sub TMP1, STR:TMP1, STR:TMP3
+ | or TMP0, TMP0, TMP1
+ | decode_RD4 TMP2, TMP2
+ | subfic TMP0, TMP0, 0
+ | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)
+ | subfe TMP1, TMP1, TMP1
+ if (vk) {
+ | andc TMP2, TMP2, TMP1
+ } else {
+ | and TMP2, TMP2, TMP1
+ }
+ | add PC, PC, TMP2
+ | ins_next
+ break;
+
+ case BC_ISEQN: case BC_ISNEN:
+ vk = op == BC_ISEQN;
+ | // RA = src*8, RD = num_const*8, JMP with RD = target
+ |.if DUALNUM
+ | lwzux TMP0, RA, BASE
+ | addi PC, PC, 4
+ | lwz CARG2, 4(RA)
+ | lwzux TMP1, RD, KBASE
+ | checknum cr0, TMP0
+ | lwz TMP2, -4(PC)
+ | checknum cr1, TMP1
+ | decode_RD4 TMP2, TMP2
+ | lwz CARG3, 4(RD)
+ | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)
+ if (vk) {
+ |->BC_ISEQN_Z:
+ } else {
+ |->BC_ISNEN_Z:
+ }
+ | bne cr0, >7
+ | bne cr1, >8
+ | cmpw CARG2, CARG3
+ |4:
+ |.else
+ if (vk) {
+ |->BC_ISEQN_Z: // Dummy label.
+ } else {
+ |->BC_ISNEN_Z: // Dummy label.
+ }
+ | lwzx TMP0, BASE, RA
+ | addi PC, PC, 4
+ | lfdx f0, BASE, RA
+ | lwz TMP2, -4(PC)
+ | lfdx f1, KBASE, RD
+ | decode_RD4 TMP2, TMP2
+ | checknum TMP0
+ | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)
+ | bge >3
+ | fcmpu cr0, f0, f1
+ |.endif
+ if (vk) {
+ | bne >1
+ | add PC, PC, TMP2
+ |1:
+ |.if not FFI
+ |3:
+ |.endif
+ } else {
+ | beq >2
+ |1:
+ |.if not FFI
+ |3:
+ |.endif
+ | add PC, PC, TMP2
+ |2:
+ }
+ | ins_next
+ |.if FFI
+ |3:
+ | cmpwi TMP0, LJ_TCDATA
+ | beq ->vmeta_equal_cd
+ | b <1
+ |.endif
+ |.if DUALNUM
+ |7: // RA is not an integer.
+ | bge cr0, <3
+ | // RA is a number.
+ | lfd f0, 0(RA)
+ | blt cr1, >1
+ | // RA is a number, RD is an integer.
+ | tonum_i f1, CARG3
+ | b >2
+ |
+ |8: // RA is an integer, RD is a number.
+ | tonum_i f0, CARG2
+ |1:
+ | lfd f1, 0(RD)
+ |2:
+ | fcmpu cr0, f0, f1
+ | b <4
+ |.endif
+ break;
+
+ case BC_ISEQP: case BC_ISNEP:
+ vk = op == BC_ISEQP;
+ | // RA = src*8, RD = primitive_type*8 (~), JMP with RD = target
+ | lwzx TMP0, BASE, RA
+ | srwi TMP1, RD, 3
+ | lwz TMP2, 0(PC)
+ | not TMP1, TMP1
+ | addi PC, PC, 4
+ |.if FFI
+ | cmpwi TMP0, LJ_TCDATA
+ |.endif
+ | sub TMP0, TMP0, TMP1
+ |.if FFI
+ | beq ->vmeta_equal_cd
+ |.endif
+ | decode_RD4 TMP2, TMP2
+ | .gpr64 extsw TMP0, TMP0
+ | addic TMP0, TMP0, -1
+ | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)
+ | subfe TMP1, TMP1, TMP1
+ if (vk) {
+ | and TMP2, TMP2, TMP1
+ } else {
+ | andc TMP2, TMP2, TMP1
+ }
+ | add PC, PC, TMP2
+ | ins_next
+ break;
+
+ /* -- Unary test and copy ops ------------------------------------------- */
+
+ case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:
+ | // RA = dst*8 or unused, RD = src*8, JMP with RD = target
+ | lwzx TMP0, BASE, RD
+ | lwz INS, 0(PC)
+ | addi PC, PC, 4
+ if (op == BC_IST || op == BC_ISF) {
+ | .gpr64 extsw TMP0, TMP0
+ | subfic TMP0, TMP0, LJ_TTRUE
+ | decode_RD4 TMP2, INS
+ | subfe TMP1, TMP1, TMP1
+ | addis TMP2, TMP2, -(BCBIAS_J*4 >> 16)
+ if (op == BC_IST) {
+ | andc TMP2, TMP2, TMP1
+ } else {
+ | and TMP2, TMP2, TMP1
+ }
+ | add PC, PC, TMP2
+ } else {
+ | li TMP1, LJ_TFALSE
+ | lfdx f0, BASE, RD
+ | cmplw TMP0, TMP1
+ if (op == BC_ISTC) {
+ | bge >1
+ } else {
+ | blt >1
+ }
+ | addis PC, PC, -(BCBIAS_J*4 >> 16)
+ | decode_RD4 TMP2, INS
+ | stfdx f0, BASE, RA
+ | add PC, PC, TMP2
+ |1:
+ }
+ | ins_next
+ break;
+
+ /* -- Unary ops --------------------------------------------------------- */
+
+ case BC_MOV:
+ | // RA = dst*8, RD = src*8
+ | ins_next1
+ | lfdx f0, BASE, RD
+ | stfdx f0, BASE, RA
+ | ins_next2
+ break;
+ case BC_NOT:
+ | // RA = dst*8, RD = src*8
+ | ins_next1
+ | lwzx TMP0, BASE, RD
+ | .gpr64 extsw TMP0, TMP0
+ | subfic TMP1, TMP0, LJ_TTRUE
+ | adde TMP0, TMP0, TMP1
+ | stwx TMP0, BASE, RA
+ | ins_next2
+ break;
+ case BC_UNM:
+ | // RA = dst*8, RD = src*8
+ | lwzux TMP1, RD, BASE
+ | lwz TMP0, 4(RD)
+ | checknum TMP1
+ |.if DUALNUM
+ | bne >5
+ |.if GPR64
+ | lus TMP2, 0x8000
+ | neg TMP0, TMP0
+ | cmplw TMP0, TMP2
+ | beq >4
+ |.else
+ | nego. TMP0, TMP0
+ | bso >4
+ |1:
+ |.endif
+ | ins_next1
+ | stwux TISNUM, RA, BASE
+ | stw TMP0, 4(RA)
+ |3:
+ | ins_next2
+ |4:
+ |.if not GPR64
+ | // Potential overflow.
+ | checkov TMP1, <1 // Ignore unrelated overflow.
+ |.endif
+ | lus TMP1, 0x41e0 // 2^31.
+ | li TMP0, 0
+ | b >7
+ |.endif
+ |5:
+ | bge ->vmeta_unm
+ | xoris TMP1, TMP1, 0x8000
+ |7:
+ | ins_next1
+ | stwux TMP1, RA, BASE
+ | stw TMP0, 4(RA)
+ |.if DUALNUM
+ | b <3
+ |.else
+ | ins_next2
+ |.endif
+ break;
+ case BC_LEN:
+ | // RA = dst*8, RD = src*8
+ | lwzux TMP0, RD, BASE
+ | lwz CARG1, 4(RD)
+ | checkstr TMP0; bne >2
+ | lwz CRET1, STR:CARG1->len
+ |1:
+ |.if DUALNUM
+ | ins_next1
+ | stwux TISNUM, RA, BASE
+ | stw CRET1, 4(RA)
+ |.else
+ | tonum_u f0, CRET1 // Result is a non-negative integer.
+ | ins_next1
+ | stfdx f0, BASE, RA
+ |.endif
+ | ins_next2
+ |2:
+ | checktab TMP0; bne ->vmeta_len
+#if LJ_52
+ | lwz TAB:TMP2, TAB:CARG1->metatable
+ | cmplwi TAB:TMP2, 0
+ | bne >9
+ |3:
+#endif
+ |->BC_LEN_Z:
+ | bl extern lj_tab_len // (GCtab *t)
+ | // Returns uint32_t (but less than 2^31).
+ | b <1
+#if LJ_52
+ |9:
+ | lbz TMP0, TAB:TMP2->nomm
+ | andix. TMP0, TMP0, 1<<MM_len
+ | bne <3 // 'no __len' flag set: done.
+ | b ->vmeta_len
+#endif
+ break;
+
+ /* -- Binary ops -------------------------------------------------------- */
+
+ |.macro ins_arithpre
+ | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8
+ ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
+ ||switch (vk) {
+ ||case 0:
+ | lwzx TMP1, BASE, RB
+ | .if DUALNUM
+ | lwzx TMP2, KBASE, RC
+ | .endif
+ | lfdx f14, BASE, RB
+ | lfdx f15, KBASE, RC
+ | .if DUALNUM
+ | checknum cr0, TMP1
+ | checknum cr1, TMP2
+ | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt
+ | bge ->vmeta_arith_vn
+ | .else
+ | checknum TMP1; bge ->vmeta_arith_vn
+ | .endif
+ || break;
+ ||case 1:
+ | lwzx TMP1, BASE, RB
+ | .if DUALNUM
+ | lwzx TMP2, KBASE, RC
+ | .endif
+ | lfdx f15, BASE, RB
+ | lfdx f14, KBASE, RC
+ | .if DUALNUM
+ | checknum cr0, TMP1
+ | checknum cr1, TMP2
+ | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt
+ | bge ->vmeta_arith_nv
+ | .else
+ | checknum TMP1; bge ->vmeta_arith_nv
+ | .endif
+ || break;
+ ||default:
+ | lwzx TMP1, BASE, RB
+ | lwzx TMP2, BASE, RC
+ | lfdx f14, BASE, RB
+ | lfdx f15, BASE, RC
+ | checknum cr0, TMP1
+ | checknum cr1, TMP2
+ | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt
+ | bge ->vmeta_arith_vv
+ || break;
+ ||}
+ |.endmacro
+ |
+ |.macro ins_arithfallback, ins
+ ||switch (vk) {
+ ||case 0:
+ | ins ->vmeta_arith_vn2
+ || break;
+ ||case 1:
+ | ins ->vmeta_arith_nv2
+ || break;
+ ||default:
+ | ins ->vmeta_arith_vv2
+ || break;
+ ||}
+ |.endmacro
+ |
+ |.macro intmod, a, b, c
+ | bl ->vm_modi
+ |.endmacro
+ |
+ |.macro fpmod, a, b, c
+ |->BC_MODVN_Z:
+ | fdiv FARG1, b, c
+ | // NYI: Use internal implementation of floor.
+ | blex floor // floor(b/c)
+ | fmul a, FARG1, c
+ | fsub a, b, a // b - floor(b/c)*c
+ |.endmacro
+ |
+ |.macro ins_arithfp, fpins
+ | ins_arithpre
+ |.if "fpins" == "fpmod_"
+ | b ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway.
+ |.else
+ | fpins f0, f14, f15
+ | ins_next1
+ | stfdx f0, BASE, RA
+ | ins_next2
+ |.endif
+ |.endmacro
+ |
+ |.macro ins_arithdn, intins, fpins
+ | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8
+ ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
+ ||switch (vk) {
+ ||case 0:
+ | lwzux TMP1, RB, BASE
+ | lwzux TMP2, RC, KBASE
+ | lwz CARG1, 4(RB)
+ | checknum cr0, TMP1
+ | lwz CARG2, 4(RC)
+ || break;
+ ||case 1:
+ | lwzux TMP1, RB, BASE
+ | lwzux TMP2, RC, KBASE
+ | lwz CARG2, 4(RB)
+ | checknum cr0, TMP1
+ | lwz CARG1, 4(RC)
+ || break;
+ ||default:
+ | lwzux TMP1, RB, BASE
+ | lwzux TMP2, RC, BASE
+ | lwz CARG1, 4(RB)
+ | checknum cr0, TMP1
+ | lwz CARG2, 4(RC)
+ || break;
+ ||}
+ | checknum cr1, TMP2
+ | bne >5
+ | bne cr1, >5
+ | intins CARG1, CARG1, CARG2
+ | bso >4
+ |1:
+ | ins_next1
+ | stwux TISNUM, RA, BASE
+ | stw CARG1, 4(RA)
+ |2:
+ | ins_next2
+ |4: // Overflow.
+ | checkov TMP0, <1 // Ignore unrelated overflow.
+ | ins_arithfallback b
+ |5: // FP variant.
+ ||if (vk == 1) {
+ | lfd f15, 0(RB)
+ | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt
+ | lfd f14, 0(RC)
+ ||} else {
+ | lfd f14, 0(RB)
+ | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt
+ | lfd f15, 0(RC)
+ ||}
+ | ins_arithfallback bge
+ |.if "fpins" == "fpmod_"
+ | b ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway.
+ |.else
+ | fpins f0, f14, f15
+ | ins_next1
+ | stfdx f0, BASE, RA
+ | b <2
+ |.endif
+ |.endmacro
+ |
+ |.macro ins_arith, intins, fpins
+ |.if DUALNUM
+ | ins_arithdn intins, fpins
+ |.else
+ | ins_arithfp fpins
+ |.endif
+ |.endmacro
+
+ case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:
+ |.if GPR64
+ |.macro addo32., y, a, b
+ | // Need to check overflow for (a<<32) + (b<<32).
+ | rldicr TMP0, a, 32, 31
+ | rldicr TMP3, b, 32, 31
+ | addo. TMP0, TMP0, TMP3
+ | add y, a, b
+ |.endmacro
+ | ins_arith addo32., fadd
+ |.else
+ | ins_arith addo., fadd
+ |.endif
+ break;
+ case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:
+ |.if GPR64
+ |.macro subo32., y, a, b
+ | // Need to check overflow for (a<<32) - (b<<32).
+ | rldicr TMP0, a, 32, 31
+ | rldicr TMP3, b, 32, 31
+ | subo. TMP0, TMP0, TMP3
+ | sub y, a, b
+ |.endmacro
+ | ins_arith subo32., fsub
+ |.else
+ | ins_arith subo., fsub
+ |.endif
+ break;
+ case BC_MULVN: case BC_MULNV: case BC_MULVV:
+ | ins_arith mullwo., fmul
+ break;
+ case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:
+ | ins_arithfp fdiv
+ break;
+ case BC_MODVN:
+ | ins_arith intmod, fpmod
+ break;
+ case BC_MODNV: case BC_MODVV:
+ | ins_arith intmod, fpmod_
+ break;
+ case BC_POW:
+ | // NYI: (partial) integer arithmetic.
+ | lwzx TMP1, BASE, RB
+ | lfdx FARG1, BASE, RB
+ | lwzx TMP2, BASE, RC
+ | lfdx FARG2, BASE, RC
+ | checknum cr0, TMP1
+ | checknum cr1, TMP2
+ | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt
+ | bge ->vmeta_arith_vv
+ | blex pow
+ | ins_next1
+ | stfdx FARG1, BASE, RA
+ | ins_next2
+ break;
+
+ case BC_CAT:
+ | // RA = dst*8, RB = src_start*8, RC = src_end*8
+ | sub CARG3, RC, RB
+ | stp BASE, L->base
+ | add CARG2, BASE, RC
+ | mr SAVE0, RB
+ |->BC_CAT_Z:
+ | stw PC, SAVE_PC
+ | mr CARG1, L
+ | srwi CARG3, CARG3, 3
+ | bl extern lj_meta_cat // (lua_State *L, TValue *top, int left)
+ | // Returns NULL (finished) or TValue * (metamethod).
+ | cmplwi CRET1, 0
+ | lp BASE, L->base
+ | bne ->vmeta_binop
+ | ins_next1
+ | lfdx f0, BASE, SAVE0 // Copy result from RB to RA.
+ | stfdx f0, BASE, RA
+ | ins_next2
+ break;
+
+ /* -- Constant ops ------------------------------------------------------ */
+
+ case BC_KSTR:
+ | // RA = dst*8, RD = str_const*8 (~)
+ | srwi TMP1, RD, 1
+ | subfic TMP1, TMP1, -4
+ | ins_next1
+ | lwzx TMP0, KBASE, TMP1 // KBASE-4-str_const*4
+ | li TMP2, LJ_TSTR
+ | stwux TMP2, RA, BASE
+ | stw TMP0, 4(RA)
+ | ins_next2
+ break;
+ case BC_KCDATA:
+ |.if FFI
+ | // RA = dst*8, RD = cdata_const*8 (~)
+ | srwi TMP1, RD, 1
+ | subfic TMP1, TMP1, -4
+ | ins_next1
+ | lwzx TMP0, KBASE, TMP1 // KBASE-4-cdata_const*4
+ | li TMP2, LJ_TCDATA
+ | stwux TMP2, RA, BASE
+ | stw TMP0, 4(RA)
+ | ins_next2
+ |.endif
+ break;
+ case BC_KSHORT:
+ | // RA = dst*8, RD = int16_literal*8
+ |.if DUALNUM
+ | slwi RD, RD, 13
+ | srawi RD, RD, 16
+ | ins_next1
+ | stwux TISNUM, RA, BASE
+ | stw RD, 4(RA)
+ | ins_next2
+ |.else
+ | // The soft-float approach is faster.
+ | slwi RD, RD, 13
+ | srawi TMP1, RD, 31
+ | xor TMP2, TMP1, RD
+ | sub TMP2, TMP2, TMP1 // TMP2 = abs(x)
+ | cntlzw TMP3, TMP2
+ | subfic TMP1, TMP3, 0x40d // TMP1 = exponent-1
+ | slw TMP2, TMP2, TMP3 // TMP2 = left aligned mantissa
+ | subfic TMP3, RD, 0
+ | slwi TMP1, TMP1, 20
+ | rlwimi RD, TMP2, 21, 1, 31 // hi = sign(x) | (mantissa>>11)
+ | subfe TMP0, TMP0, TMP0
+ | add RD, RD, TMP1 // hi = hi + exponent-1
+ | and RD, RD, TMP0 // hi = x == 0 ? 0 : hi
+ | ins_next1
+ | stwux RD, RA, BASE
+ | stw ZERO, 4(RA)
+ | ins_next2
+ |.endif
+ break;
+ case BC_KNUM:
+ | // RA = dst*8, RD = num_const*8
+ | ins_next1
+ | lfdx f0, KBASE, RD
+ | stfdx f0, BASE, RA
+ | ins_next2
+ break;
+ case BC_KPRI:
+ | // RA = dst*8, RD = primitive_type*8 (~)
+ | srwi TMP1, RD, 3
+ | not TMP0, TMP1
+ | ins_next1
+ | stwx TMP0, BASE, RA
+ | ins_next2
+ break;
+ case BC_KNIL:
+ | // RA = base*8, RD = end*8
+ | stwx TISNIL, BASE, RA
+ | addi RA, RA, 8
+ |1:
+ | stwx TISNIL, BASE, RA
+ | cmpw RA, RD
+ | addi RA, RA, 8
+ | blt <1
+ | ins_next_
+ break;
+
+ /* -- Upvalue and function ops ------------------------------------------ */
+
+ case BC_UGET:
+ | // RA = dst*8, RD = uvnum*8
+ | lwz LFUNC:RB, FRAME_FUNC(BASE)
+ | srwi RD, RD, 1
+ | addi RD, RD, offsetof(GCfuncL, uvptr)
+ | lwzx UPVAL:RB, LFUNC:RB, RD
+ | ins_next1
+ | lwz TMP1, UPVAL:RB->v
+ | lfd f0, 0(TMP1)
+ | stfdx f0, BASE, RA
+ | ins_next2
+ break;
+ case BC_USETV:
+ | // RA = uvnum*8, RD = src*8
+ | lwz LFUNC:RB, FRAME_FUNC(BASE)
+ | srwi RA, RA, 1
+ | addi RA, RA, offsetof(GCfuncL, uvptr)
+ | lfdux f0, RD, BASE
+ | lwzx UPVAL:RB, LFUNC:RB, RA
+ | lbz TMP3, UPVAL:RB->marked
+ | lwz CARG2, UPVAL:RB->v
+ | andix. TMP3, TMP3, LJ_GC_BLACK // isblack(uv)
+ | lbz TMP0, UPVAL:RB->closed
+ | lwz TMP2, 0(RD)
+ | stfd f0, 0(CARG2)
+ | cmplwi cr1, TMP0, 0
+ | lwz TMP1, 4(RD)
+ | cror 4*cr0+eq, 4*cr0+eq, 4*cr1+eq
+ | subi TMP2, TMP2, (LJ_TNUMX+1)
+ | bne >2 // Upvalue is closed and black?
+ |1:
+ | ins_next
+ |
+ |2: // Check if new value is collectable.
+ | cmplwi TMP2, LJ_TISGCV - (LJ_TNUMX+1)
+ | bge <1 // tvisgcv(v)
+ | lbz TMP3, GCOBJ:TMP1->gch.marked
+ | andix. TMP3, TMP3, LJ_GC_WHITES // iswhite(v)
+ | la CARG1, GG_DISP2G(DISPATCH)
+ | // Crossed a write barrier. Move the barrier forward.
+ | beq <1
+ | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv)
+ | b <1
+ break;
+ case BC_USETS:
+ | // RA = uvnum*8, RD = str_const*8 (~)
+ | lwz LFUNC:RB, FRAME_FUNC(BASE)
+ | srwi TMP1, RD, 1
+ | srwi RA, RA, 1
+ | subfic TMP1, TMP1, -4
+ | addi RA, RA, offsetof(GCfuncL, uvptr)
+ | lwzx STR:TMP1, KBASE, TMP1 // KBASE-4-str_const*4
+ | lwzx UPVAL:RB, LFUNC:RB, RA
+ | lbz TMP3, UPVAL:RB->marked
+ | lwz CARG2, UPVAL:RB->v
+ | andix. TMP3, TMP3, LJ_GC_BLACK // isblack(uv)
+ | lbz TMP3, STR:TMP1->marked
+ | lbz TMP2, UPVAL:RB->closed
+ | li TMP0, LJ_TSTR
+ | stw STR:TMP1, 4(CARG2)
+ | stw TMP0, 0(CARG2)
+ | bne >2
+ |1:
+ | ins_next
+ |
+ |2: // Check if string is white and ensure upvalue is closed.
+ | andix. TMP3, TMP3, LJ_GC_WHITES // iswhite(str)
+ | cmplwi cr1, TMP2, 0
+ | cror 4*cr0+eq, 4*cr0+eq, 4*cr1+eq
+ | la CARG1, GG_DISP2G(DISPATCH)
+ | // Crossed a write barrier. Move the barrier forward.
+ | beq <1
+ | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv)
+ | b <1
+ break;
+ case BC_USETN:
+ | // RA = uvnum*8, RD = num_const*8
+ | lwz LFUNC:RB, FRAME_FUNC(BASE)
+ | srwi RA, RA, 1
+ | addi RA, RA, offsetof(GCfuncL, uvptr)
+ | lfdx f0, KBASE, RD
+ | lwzx UPVAL:RB, LFUNC:RB, RA
+ | ins_next1
+ | lwz TMP1, UPVAL:RB->v
+ | stfd f0, 0(TMP1)
+ | ins_next2
+ break;
+ case BC_USETP:
+ | // RA = uvnum*8, RD = primitive_type*8 (~)
+ | lwz LFUNC:RB, FRAME_FUNC(BASE)
+ | srwi RA, RA, 1
+ | srwi TMP0, RD, 3
+ | addi RA, RA, offsetof(GCfuncL, uvptr)
+ | not TMP0, TMP0
+ | lwzx UPVAL:RB, LFUNC:RB, RA
+ | ins_next1
+ | lwz TMP1, UPVAL:RB->v
+ | stw TMP0, 0(TMP1)
+ | ins_next2
+ break;
+
+ case BC_UCLO:
+ | // RA = level*8, RD = target
+ | lwz TMP1, L->openupval
+ | branch_RD // Do this first since RD is not saved.
+ | stp BASE, L->base
+ | cmplwi TMP1, 0
+ | mr CARG1, L
+ | beq >1
+ | add CARG2, BASE, RA
+ | bl extern lj_func_closeuv // (lua_State *L, TValue *level)
+ | lp BASE, L->base
+ |1:
+ | ins_next
+ break;
+
+ case BC_FNEW:
+ | // RA = dst*8, RD = proto_const*8 (~) (holding function prototype)
+ | srwi TMP1, RD, 1
+ | stp BASE, L->base
+ | subfic TMP1, TMP1, -4
+ | stw PC, SAVE_PC
+ | lwzx CARG2, KBASE, TMP1 // KBASE-4-tab_const*4
+ | mr CARG1, L
+ | lwz CARG3, FRAME_FUNC(BASE)
+ | // (lua_State *L, GCproto *pt, GCfuncL *parent)
+ | bl extern lj_func_newL_gc
+ | // Returns GCfuncL *.
+ | lp BASE, L->base
+ | li TMP0, LJ_TFUNC
+ | stwux TMP0, RA, BASE
+ | stw LFUNC:CRET1, 4(RA)
+ | ins_next
+ break;
+
+ /* -- Table ops --------------------------------------------------------- */
+
+ case BC_TNEW:
+ case BC_TDUP:
+ | // RA = dst*8, RD = (hbits|asize)*8 | tab_const*8 (~)
+ | lwz TMP0, DISPATCH_GL(gc.total)(DISPATCH)
+ | mr CARG1, L
+ | lwz TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)
+ | stp BASE, L->base
+ | cmplw TMP0, TMP1
+ | stw PC, SAVE_PC
+ | bge >5
+ |1:
+ if (op == BC_TNEW) {
+ | rlwinm CARG2, RD, 29, 21, 31
+ | rlwinm CARG3, RD, 18, 27, 31
+ | cmpwi CARG2, 0x7ff; beq >3
+ |2:
+ | bl extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits)
+ | // Returns Table *.
+ } else {
+ | srwi TMP1, RD, 1
+ | subfic TMP1, TMP1, -4
+ | lwzx CARG2, KBASE, TMP1 // KBASE-4-tab_const*4
+ | bl extern lj_tab_dup // (lua_State *L, Table *kt)
+ | // Returns Table *.
+ }
+ | lp BASE, L->base
+ | li TMP0, LJ_TTAB
+ | stwux TMP0, RA, BASE
+ | stw TAB:CRET1, 4(RA)
+ | ins_next
+ if (op == BC_TNEW) {
+ |3:
+ | li CARG2, 0x801
+ | b <2
+ }
+ |5:
+ | mr SAVE0, RD
+ | bl extern lj_gc_step_fixtop // (lua_State *L)
+ | mr RD, SAVE0
+ | mr CARG1, L
+ | b <1
+ break;
+
+ case BC_GGET:
+ | // RA = dst*8, RD = str_const*8 (~)
+ case BC_GSET:
+ | // RA = src*8, RD = str_const*8 (~)
+ | lwz LFUNC:TMP2, FRAME_FUNC(BASE)
+ | srwi TMP1, RD, 1
+ | lwz TAB:RB, LFUNC:TMP2->env
+ | subfic TMP1, TMP1, -4
+ | lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4
+ if (op == BC_GGET) {
+ | b ->BC_TGETS_Z
+ } else {
+ | b ->BC_TSETS_Z
+ }
+ break;
+
+ case BC_TGETV:
+ | // RA = dst*8, RB = table*8, RC = key*8
+ | lwzux CARG1, RB, BASE
+ | lwzux CARG2, RC, BASE
+ | lwz TAB:RB, 4(RB)
+ |.if DUALNUM
+ | lwz RC, 4(RC)
+ |.else
+ | lfd f0, 0(RC)
+ |.endif
+ | checktab CARG1
+ | checknum cr1, CARG2
+ | bne ->vmeta_tgetv
+ |.if DUALNUM
+ | lwz TMP0, TAB:RB->asize
+ | bne cr1, >5
+ | lwz TMP1, TAB:RB->array
+ | cmplw TMP0, RC
+ | slwi TMP2, RC, 3
+ |.else
+ | bge cr1, >5
+ | // Convert number key to integer, check for integerness and range.
+ | fctiwz f1, f0
+ | fadd f2, f0, TOBIT
+ | stfd f1, TMPD
+ | lwz TMP0, TAB:RB->asize
+ | fsub f2, f2, TOBIT
+ | lwz TMP2, TMPD_LO
+ | lwz TMP1, TAB:RB->array
+ | fcmpu cr1, f0, f2
+ | cmplw cr0, TMP0, TMP2
+ | crand 4*cr0+gt, 4*cr0+gt, 4*cr1+eq
+ | slwi TMP2, TMP2, 3
+ |.endif
+ | ble ->vmeta_tgetv // Integer key and in array part?
+ | lwzx TMP0, TMP1, TMP2
+ | lfdx f14, TMP1, TMP2
+ | checknil TMP0; beq >2
+ |1:
+ | ins_next1
+ | stfdx f14, BASE, RA
+ | ins_next2
+ |
+ |2: // Check for __index if table value is nil.
+ | lwz TAB:TMP2, TAB:RB->metatable
+ | cmplwi TAB:TMP2, 0
+ | beq <1 // No metatable: done.
+ | lbz TMP0, TAB:TMP2->nomm
+ | andix. TMP0, TMP0, 1<<MM_index
+ | bne <1 // 'no __index' flag set: done.
+ | b ->vmeta_tgetv
+ |
+ |5:
+ | checkstr CARG2; bne ->vmeta_tgetv
+ |.if not DUALNUM
+ | lwz STR:RC, 4(RC)
+ |.endif
+ | b ->BC_TGETS_Z // String key?
+ break;
+ case BC_TGETS:
+ | // RA = dst*8, RB = table*8, RC = str_const*8 (~)
+ | lwzux CARG1, RB, BASE
+ | srwi TMP1, RC, 1
+ | lwz TAB:RB, 4(RB)
+ | subfic TMP1, TMP1, -4
+ | checktab CARG1
+ | lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4
+ | bne ->vmeta_tgets1
+ |->BC_TGETS_Z:
+ | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = dst*8
+ | lwz TMP0, TAB:RB->hmask
+ | lwz TMP1, STR:RC->hash
+ | lwz NODE:TMP2, TAB:RB->node
+ | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask
+ | slwi TMP0, TMP1, 5
+ | slwi TMP1, TMP1, 3
+ | sub TMP1, TMP0, TMP1
+ | add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8)
+ |1:
+ | lwz CARG1, NODE:TMP2->key
+ | lwz TMP0, 4+offsetof(Node, key)(NODE:TMP2)
+ | lwz CARG2, NODE:TMP2->val
+ | lwz TMP1, 4+offsetof(Node, val)(NODE:TMP2)
+ | checkstr CARG1; bne >4
+ | cmpw TMP0, STR:RC; bne >4
+ | checknil CARG2; beq >5 // Key found, but nil value?
+ |3:
+ | stwux CARG2, RA, BASE
+ | stw TMP1, 4(RA)
+ | ins_next
+ |
+ |4: // Follow hash chain.
+ | lwz NODE:TMP2, NODE:TMP2->next
+ | cmplwi NODE:TMP2, 0
+ | bne <1
+ | // End of hash chain: key not found, nil result.
+ | li CARG2, LJ_TNIL
+ |
+ |5: // Check for __index if table value is nil.
+ | lwz TAB:TMP2, TAB:RB->metatable
+ | cmplwi TAB:TMP2, 0
+ | beq <3 // No metatable: done.
+ | lbz TMP0, TAB:TMP2->nomm
+ | andix. TMP0, TMP0, 1<<MM_index
+ | bne <3 // 'no __index' flag set: done.
+ | b ->vmeta_tgets
+ break;
+ case BC_TGETB:
+ | // RA = dst*8, RB = table*8, RC = index*8
+ | lwzux CARG1, RB, BASE
+ | srwi TMP0, RC, 3
+ | lwz TAB:RB, 4(RB)
+ | checktab CARG1; bne ->vmeta_tgetb
+ | lwz TMP1, TAB:RB->asize
+ | lwz TMP2, TAB:RB->array
+ | cmplw TMP0, TMP1; bge ->vmeta_tgetb
+ | lwzx TMP1, TMP2, RC
+ | lfdx f0, TMP2, RC
+ | checknil TMP1; beq >5
+ |1:
+ | ins_next1
+ | stfdx f0, BASE, RA
+ | ins_next2
+ |
+ |5: // Check for __index if table value is nil.
+ | lwz TAB:TMP2, TAB:RB->metatable
+ | cmplwi TAB:TMP2, 0
+ | beq <1 // No metatable: done.
+ | lbz TMP2, TAB:TMP2->nomm
+ | andix. TMP2, TMP2, 1<<MM_index
+ | bne <1 // 'no __index' flag set: done.
+ | b ->vmeta_tgetb // Caveat: preserve TMP0!
+ break;
+
+ case BC_TSETV:
+ | // RA = src*8, RB = table*8, RC = key*8
+ | lwzux CARG1, RB, BASE
+ | lwzux CARG2, RC, BASE
+ | lwz TAB:RB, 4(RB)
+ |.if DUALNUM
+ | lwz RC, 4(RC)
+ |.else
+ | lfd f0, 0(RC)
+ |.endif
+ | checktab CARG1
+ | checknum cr1, CARG2
+ | bne ->vmeta_tsetv
+ |.if DUALNUM
+ | lwz TMP0, TAB:RB->asize
+ | bne cr1, >5
+ | lwz TMP1, TAB:RB->array
+ | cmplw TMP0, RC
+ | slwi TMP0, RC, 3
+ |.else
+ | bge cr1, >5
+ | // Convert number key to integer, check for integerness and range.
+ | fctiwz f1, f0
+ | fadd f2, f0, TOBIT
+ | stfd f1, TMPD
+ | lwz TMP0, TAB:RB->asize
+ | fsub f2, f2, TOBIT
+ | lwz TMP2, TMPD_LO
+ | lwz TMP1, TAB:RB->array
+ | fcmpu cr1, f0, f2
+ | cmplw cr0, TMP0, TMP2
+ | crand 4*cr0+gt, 4*cr0+gt, 4*cr1+eq
+ | slwi TMP0, TMP2, 3
+ |.endif
+ | ble ->vmeta_tsetv // Integer key and in array part?
+ | lwzx TMP2, TMP1, TMP0
+ | lbz TMP3, TAB:RB->marked
+ | lfdx f14, BASE, RA
+ | checknil TMP2; beq >3
+ |1:
+ | andix. TMP2, TMP3, LJ_GC_BLACK // isblack(table)
+ | stfdx f14, TMP1, TMP0
+ | bne >7
+ |2:
+ | ins_next
+ |
+ |3: // Check for __newindex if previous value is nil.
+ | lwz TAB:TMP2, TAB:RB->metatable
+ | cmplwi TAB:TMP2, 0
+ | beq <1 // No metatable: done.
+ | lbz TMP2, TAB:TMP2->nomm
+ | andix. TMP2, TMP2, 1<<MM_newindex
+ | bne <1 // 'no __newindex' flag set: done.
+ | b ->vmeta_tsetv
+ |
+ |5:
+ | checkstr CARG2; bne ->vmeta_tsetv
+ |.if not DUALNUM
+ | lwz STR:RC, 4(RC)
+ |.endif
+ | b ->BC_TSETS_Z // String key?
+ |
+ |7: // Possible table write barrier for the value. Skip valiswhite check.
+ | barrierback TAB:RB, TMP3, TMP0
+ | b <2
+ break;
+ case BC_TSETS:
+ | // RA = src*8, RB = table*8, RC = str_const*8 (~)
+ | lwzux CARG1, RB, BASE
+ | srwi TMP1, RC, 1
+ | lwz TAB:RB, 4(RB)
+ | subfic TMP1, TMP1, -4
+ | checktab CARG1
+ | lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4
+ | bne ->vmeta_tsets1
+ |->BC_TSETS_Z:
+ | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = src*8
+ | lwz TMP0, TAB:RB->hmask
+ | lwz TMP1, STR:RC->hash
+ | lwz NODE:TMP2, TAB:RB->node
+ | stb ZERO, TAB:RB->nomm // Clear metamethod cache.
+ | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask
+ | lfdx f14, BASE, RA
+ | slwi TMP0, TMP1, 5
+ | slwi TMP1, TMP1, 3
+ | sub TMP1, TMP0, TMP1
+ | lbz TMP3, TAB:RB->marked
+ | add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8)
+ |1:
+ | lwz CARG1, NODE:TMP2->key
+ | lwz TMP0, 4+offsetof(Node, key)(NODE:TMP2)
+ | lwz CARG2, NODE:TMP2->val
+ | lwz NODE:TMP1, NODE:TMP2->next
+ | checkstr CARG1; bne >5
+ | cmpw TMP0, STR:RC; bne >5
+ | checknil CARG2; beq >4 // Key found, but nil value?
+ |2:
+ | andix. TMP0, TMP3, LJ_GC_BLACK // isblack(table)
+ | stfd f14, NODE:TMP2->val
+ | bne >7
+ |3:
+ | ins_next
+ |
+ |4: // Check for __newindex if previous value is nil.
+ | lwz TAB:TMP1, TAB:RB->metatable
+ | cmplwi TAB:TMP1, 0
+ | beq <2 // No metatable: done.
+ | lbz TMP0, TAB:TMP1->nomm
+ | andix. TMP0, TMP0, 1<<MM_newindex
+ | bne <2 // 'no __newindex' flag set: done.
+ | b ->vmeta_tsets
+ |
+ |5: // Follow hash chain.
+ | cmplwi NODE:TMP1, 0
+ | mr NODE:TMP2, NODE:TMP1
+ | bne <1
+ | // End of hash chain: key not found, add a new one.
+ |
+ | // But check for __newindex first.
+ | lwz TAB:TMP1, TAB:RB->metatable
+ | la CARG3, DISPATCH_GL(tmptv)(DISPATCH)
+ | stw PC, SAVE_PC
+ | mr CARG1, L
+ | cmplwi TAB:TMP1, 0
+ | stp BASE, L->base
+ | beq >6 // No metatable: continue.
+ | lbz TMP0, TAB:TMP1->nomm
+ | andix. TMP0, TMP0, 1<<MM_newindex
+ | beq ->vmeta_tsets // 'no __newindex' flag NOT set: check.
+ |6:
+ | li TMP0, LJ_TSTR
+ | stw STR:RC, 4(CARG3)
+ | mr CARG2, TAB:RB
+ | stw TMP0, 0(CARG3)
+ | bl extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k)
+ | // Returns TValue *.
+ | lp BASE, L->base
+ | stfd f14, 0(CRET1)
+ | b <3 // No 2nd write barrier needed.
+ |
+ |7: // Possible table write barrier for the value. Skip valiswhite check.
+ | barrierback TAB:RB, TMP3, TMP0
+ | b <3
+ break;
+ case BC_TSETB:
+ | // RA = src*8, RB = table*8, RC = index*8
+ | lwzux CARG1, RB, BASE
+ | srwi TMP0, RC, 3
+ | lwz TAB:RB, 4(RB)
+ | checktab CARG1; bne ->vmeta_tsetb
+ | lwz TMP1, TAB:RB->asize
+ | lwz TMP2, TAB:RB->array
+ | lbz TMP3, TAB:RB->marked
+ | cmplw TMP0, TMP1
+ | lfdx f14, BASE, RA
+ | bge ->vmeta_tsetb
+ | lwzx TMP1, TMP2, RC
+ | checknil TMP1; beq >5
+ |1:
+ | andix. TMP0, TMP3, LJ_GC_BLACK // isblack(table)
+ | stfdx f14, TMP2, RC
+ | bne >7
+ |2:
+ | ins_next
+ |
+ |5: // Check for __newindex if previous value is nil.
+ | lwz TAB:TMP1, TAB:RB->metatable
+ | cmplwi TAB:TMP1, 0
+ | beq <1 // No metatable: done.
+ | lbz TMP1, TAB:TMP1->nomm
+ | andix. TMP1, TMP1, 1<<MM_newindex
+ | bne <1 // 'no __newindex' flag set: done.
+ | b ->vmeta_tsetb // Caveat: preserve TMP0!
+ |
+ |7: // Possible table write barrier for the value. Skip valiswhite check.
+ | barrierback TAB:RB, TMP3, TMP0
+ | b <2
+ break;
+
+ case BC_TSETM:
+ | // RA = base*8 (table at base-1), RD = num_const*8 (start index)
+ | add RA, BASE, RA
+ |1:
+ | add TMP3, KBASE, RD
+ | lwz TAB:CARG2, -4(RA) // Guaranteed to be a table.
+ | addic. TMP0, MULTRES, -8
+ | lwz TMP3, 4(TMP3) // Integer constant is in lo-word.
+ | srwi CARG3, TMP0, 3
+ | beq >4 // Nothing to copy?
+ | add CARG3, CARG3, TMP3
+ | lwz TMP2, TAB:CARG2->asize
+ | slwi TMP1, TMP3, 3
+ | lbz TMP3, TAB:CARG2->marked
+ | cmplw CARG3, TMP2
+ | add TMP2, RA, TMP0
+ | lwz TMP0, TAB:CARG2->array
+ | bgt >5
+ | add TMP1, TMP1, TMP0
+ | andix. TMP0, TMP3, LJ_GC_BLACK // isblack(table)
+ |3: // Copy result slots to table.
+ | lfd f0, 0(RA)
+ | addi RA, RA, 8
+ | cmpw cr1, RA, TMP2
+ | stfd f0, 0(TMP1)
+ | addi TMP1, TMP1, 8
+ | blt cr1, <3
+ | bne >7
+ |4:
+ | ins_next
+ |
+ |5: // Need to resize array part.
+ | stp BASE, L->base
+ | mr CARG1, L
+ | stw PC, SAVE_PC
+ | mr SAVE0, RD
+ | bl extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize)
+ | // Must not reallocate the stack.
+ | mr RD, SAVE0
+ | b <1
+ |
+ |7: // Possible table write barrier for any value. Skip valiswhite check.
+ | barrierback TAB:CARG2, TMP3, TMP0
+ | b <4
+ break;
+
+ /* -- Calls and vararg handling ----------------------------------------- */
+
+ case BC_CALLM:
+ | // RA = base*8, (RB = (nresults+1)*8,) RC = extra_nargs*8
+ | add NARGS8:RC, NARGS8:RC, MULTRES
+ | // Fall through. Assumes BC_CALL follows.
+ break;
+ case BC_CALL:
+ | // RA = base*8, (RB = (nresults+1)*8,) RC = (nargs+1)*8
+ | mr TMP2, BASE
+ | lwzux TMP0, BASE, RA
+ | lwz LFUNC:RB, 4(BASE)
+ | subi NARGS8:RC, NARGS8:RC, 8
+ | addi BASE, BASE, 8
+ | checkfunc TMP0; bne ->vmeta_call
+ | ins_call
+ break;
+
+ case BC_CALLMT:
+ | // RA = base*8, (RB = 0,) RC = extra_nargs*8
+ | add NARGS8:RC, NARGS8:RC, MULTRES
+ | // Fall through. Assumes BC_CALLT follows.
+ break;
+ case BC_CALLT:
+ | // RA = base*8, (RB = 0,) RC = (nargs+1)*8
+ | lwzux TMP0, RA, BASE
+ | lwz LFUNC:RB, 4(RA)
+ | subi NARGS8:RC, NARGS8:RC, 8
+ | lwz TMP1, FRAME_PC(BASE)
+ | checkfunc TMP0
+ | addi RA, RA, 8
+ | bne ->vmeta_callt
+ |->BC_CALLT_Z:
+ | andix. TMP0, TMP1, FRAME_TYPE // Caveat: preserve cr0 until the crand.
+ | lbz TMP3, LFUNC:RB->ffid
+ | xori TMP2, TMP1, FRAME_VARG
+ | cmplwi cr1, NARGS8:RC, 0
+ | bne >7
+ |1:
+ | stw LFUNC:RB, FRAME_FUNC(BASE) // Copy function down, but keep PC.
+ | li TMP2, 0
+ | cmplwi cr7, TMP3, 1 // (> FF_C) Calling a fast function?
+ | beq cr1, >3
+ |2:
+ | addi TMP3, TMP2, 8
+ | lfdx f0, RA, TMP2
+ | cmplw cr1, TMP3, NARGS8:RC
+ | stfdx f0, BASE, TMP2
+ | mr TMP2, TMP3
+ | bne cr1, <2
+ |3:
+ | crand 4*cr0+eq, 4*cr0+eq, 4*cr7+gt
+ | beq >5
+ |4:
+ | ins_callt
+ |
+ |5: // Tailcall to a fast function with a Lua frame below.
+ | lwz INS, -4(TMP1)
+ | decode_RA8 RA, INS
+ | sub TMP1, BASE, RA
+ | lwz LFUNC:TMP1, FRAME_FUNC-8(TMP1)
+ | lwz TMP1, LFUNC:TMP1->pc
+ | lwz KBASE, PC2PROTO(k)(TMP1) // Need to prepare KBASE.
+ | b <4
+ |
+ |7: // Tailcall from a vararg function.
+ | andix. TMP0, TMP2, FRAME_TYPEP
+ | bne <1 // Vararg frame below?
+ | sub BASE, BASE, TMP2 // Relocate BASE down.
+ | lwz TMP1, FRAME_PC(BASE)
+ | andix. TMP0, TMP1, FRAME_TYPE
+ | b <1
+ break;
+
+ case BC_ITERC:
+ | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 ((2+1)*8))
+ | mr TMP2, BASE
+ | add BASE, BASE, RA
+ | lwz TMP1, -24(BASE)
+ | lwz LFUNC:RB, -20(BASE)
+ | lfd f1, -8(BASE)
+ | lfd f0, -16(BASE)
+ | stw TMP1, 0(BASE) // Copy callable.
+ | stw LFUNC:RB, 4(BASE)
+ | checkfunc TMP1
+ | stfd f1, 16(BASE) // Copy control var.
+ | li NARGS8:RC, 16 // Iterators get 2 arguments.
+ | stfdu f0, 8(BASE) // Copy state.
+ | bne ->vmeta_call
+ | ins_call
+ break;
+
+ case BC_ITERN:
+ | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 (2+1)*8)
+ |.if JIT
+ | // NYI: add hotloop, record BC_ITERN.
+ |.endif
+ | add RA, BASE, RA
+ | lwz TAB:RB, -12(RA)
+ | lwz RC, -4(RA) // Get index from control var.
+ | lwz TMP0, TAB:RB->asize
+ | lwz TMP1, TAB:RB->array
+ | addi PC, PC, 4
+ |1: // Traverse array part.
+ | cmplw RC, TMP0
+ | slwi TMP3, RC, 3
+ | bge >5 // Index points after array part?
+ | lwzx TMP2, TMP1, TMP3
+ | lfdx f0, TMP1, TMP3
+ | checknil TMP2
+ | lwz INS, -4(PC)
+ | beq >4
+ |.if DUALNUM
+ | stw RC, 4(RA)
+ | stw TISNUM, 0(RA)
+ |.else
+ | tonum_u f1, RC
+ |.endif
+ | addi RC, RC, 1
+ | addis TMP3, PC, -(BCBIAS_J*4 >> 16)
+ | stfd f0, 8(RA)
+ | decode_RD4 TMP1, INS
+ | stw RC, -4(RA) // Update control var.
+ | add PC, TMP1, TMP3
+ |.if not DUALNUM
+ | stfd f1, 0(RA)
+ |.endif
+ |3:
+ | ins_next
+ |
+ |4: // Skip holes in array part.
+ | addi RC, RC, 1
+ | b <1
+ |
+ |5: // Traverse hash part.
+ | lwz TMP1, TAB:RB->hmask
+ | sub RC, RC, TMP0
+ | lwz TMP2, TAB:RB->node
+ |6:
+ | cmplw RC, TMP1 // End of iteration? Branch to ITERL+1.
+ | slwi TMP3, RC, 5
+ | bgty <3
+ | slwi RB, RC, 3
+ | sub TMP3, TMP3, RB
+ | lwzx RB, TMP2, TMP3
+ | lfdx f0, TMP2, TMP3
+ | add NODE:TMP3, TMP2, TMP3
+ | checknil RB
+ | lwz INS, -4(PC)
+ | beq >7
+ | lfd f1, NODE:TMP3->key
+ | addis TMP2, PC, -(BCBIAS_J*4 >> 16)
+ | stfd f0, 8(RA)
+ | add RC, RC, TMP0
+ | decode_RD4 TMP1, INS
+ | stfd f1, 0(RA)
+ | addi RC, RC, 1
+ | add PC, TMP1, TMP2
+ | stw RC, -4(RA) // Update control var.
+ | b <3
+ |
+ |7: // Skip holes in hash part.
+ | addi RC, RC, 1
+ | b <6
+ break;
+
+ case BC_ISNEXT:
+ | // RA = base*8, RD = target (points to ITERN)
+ | add RA, BASE, RA
+ | lwz TMP0, -24(RA)
+ | lwz CFUNC:TMP1, -20(RA)
+ | lwz TMP2, -16(RA)
+ | lwz TMP3, -8(RA)
+ | cmpwi cr0, TMP2, LJ_TTAB
+ | cmpwi cr1, TMP0, LJ_TFUNC
+ | cmpwi cr6, TMP3, LJ_TNIL
+ | bne cr1, >5
+ | lbz TMP1, CFUNC:TMP1->ffid
+ | crand 4*cr0+eq, 4*cr0+eq, 4*cr6+eq
+ | cmpwi cr7, TMP1, FF_next_N
+ | srwi TMP0, RD, 1
+ | crand 4*cr0+eq, 4*cr0+eq, 4*cr7+eq
+ | add TMP3, PC, TMP0
+ | bne cr0, >5
+ | lus TMP1, 0xfffe
+ | ori TMP1, TMP1, 0x7fff
+ | stw ZERO, -4(RA) // Initialize control var.
+ | stw TMP1, -8(RA)
+ | addis PC, TMP3, -(BCBIAS_J*4 >> 16)
+ |1:
+ | ins_next
+ |5: // Despecialize bytecode if any of the checks fail.
+ | li TMP0, BC_JMP
+ | li TMP1, BC_ITERC
+ | stb TMP0, -1(PC)
+ | addis PC, TMP3, -(BCBIAS_J*4 >> 16)
+ | stb TMP1, 3(PC)
+ | b <1
+ break;
+
+ case BC_VARG:
+ | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8
+ | lwz TMP0, FRAME_PC(BASE)
+ | add RC, BASE, RC
+ | add RA, BASE, RA
+ | addi RC, RC, FRAME_VARG
+ | add TMP2, RA, RB
+ | subi TMP3, BASE, 8 // TMP3 = vtop
+ | sub RC, RC, TMP0 // RC = vbase
+ | // Note: RC may now be even _above_ BASE if nargs was < numparams.
+ | cmplwi cr1, RB, 0
+ |.if PPE
+ | sub TMP1, TMP3, RC
+ | cmpwi TMP1, 0
+ |.else
+ | sub. TMP1, TMP3, RC
+ |.endif
+ | beq cr1, >5 // Copy all varargs?
+ | subi TMP2, TMP2, 16
+ | ble >2 // No vararg slots?
+ |1: // Copy vararg slots to destination slots.
+ | lfd f0, 0(RC)
+ | addi RC, RC, 8
+ | stfd f0, 0(RA)
+ | cmplw RA, TMP2
+ | cmplw cr1, RC, TMP3
+ | bge >3 // All destination slots filled?
+ | addi RA, RA, 8
+ | blt cr1, <1 // More vararg slots?
+ |2: // Fill up remainder with nil.
+ | stw TISNIL, 0(RA)
+ | cmplw RA, TMP2
+ | addi RA, RA, 8
+ | blt <2
+ |3:
+ | ins_next
+ |
+ |5: // Copy all varargs.
+ | lwz TMP0, L->maxstack
+ | li MULTRES, 8 // MULTRES = (0+1)*8
+ | bley <3 // No vararg slots?
+ | add TMP2, RA, TMP1
+ | cmplw TMP2, TMP0
+ | addi MULTRES, TMP1, 8
+ | bgt >7
+ |6:
+ | lfd f0, 0(RC)
+ | addi RC, RC, 8
+ | stfd f0, 0(RA)
+ | cmplw RC, TMP3
+ | addi RA, RA, 8
+ | blt <6 // More vararg slots?
+ | b <3
+ |
+ |7: // Grow stack for varargs.
+ | mr CARG1, L
+ | stp RA, L->top
+ | sub SAVE0, RC, BASE // Need delta, because BASE may change.
+ | stp BASE, L->base
+ | sub RA, RA, BASE
+ | stw PC, SAVE_PC
+ | srwi CARG2, TMP1, 3
+ | bl extern lj_state_growstack // (lua_State *L, int n)
+ | lp BASE, L->base
+ | add RA, BASE, RA
+ | add RC, BASE, SAVE0
+ | subi TMP3, BASE, 8
+ | b <6
+ break;
+
+ /* -- Returns ----------------------------------------------------------- */
+
+ case BC_RETM:
+ | // RA = results*8, RD = extra_nresults*8
+ | add RD, RD, MULTRES // MULTRES >= 8, so RD >= 8.
+ | // Fall through. Assumes BC_RET follows.
+ break;
+
+ case BC_RET:
+ | // RA = results*8, RD = (nresults+1)*8
+ | lwz PC, FRAME_PC(BASE)
+ | add RA, BASE, RA
+ | mr MULTRES, RD
+ |1:
+ | andix. TMP0, PC, FRAME_TYPE
+ | xori TMP1, PC, FRAME_VARG
+ | bne ->BC_RETV_Z
+ |
+ |->BC_RET_Z:
+ | // BASE = base, RA = resultptr, RD = (nresults+1)*8, PC = return
+ | lwz INS, -4(PC)
+ | cmpwi RD, 8
+ | subi TMP2, BASE, 8
+ | subi RC, RD, 8
+ | decode_RB8 RB, INS
+ | beq >3
+ | li TMP1, 0
+ |2:
+ | addi TMP3, TMP1, 8
+ | lfdx f0, RA, TMP1
+ | cmpw TMP3, RC
+ | stfdx f0, TMP2, TMP1
+ | beq >3
+ | addi TMP1, TMP3, 8
+ | lfdx f1, RA, TMP3
+ | cmpw TMP1, RC
+ | stfdx f1, TMP2, TMP3
+ | bne <2
+ |3:
+ |5:
+ | cmplw RB, RD
+ | decode_RA8 RA, INS
+ | bgt >6
+ | sub BASE, TMP2, RA
+ | lwz LFUNC:TMP1, FRAME_FUNC(BASE)
+ | ins_next1
+ | lwz TMP1, LFUNC:TMP1->pc
+ | lwz KBASE, PC2PROTO(k)(TMP1)
+ | ins_next2
+ |
+ |6: // Fill up results with nil.
+ | subi TMP1, RD, 8
+ | addi RD, RD, 8
+ | stwx TISNIL, TMP2, TMP1
+ | b <5
+ |
+ |->BC_RETV_Z: // Non-standard return case.
+ | andix. TMP2, TMP1, FRAME_TYPEP
+ | bne ->vm_return
+ | // Return from vararg function: relocate BASE down.
+ | sub BASE, BASE, TMP1
+ | lwz PC, FRAME_PC(BASE)
+ | b <1
+ break;
+
+ case BC_RET0: case BC_RET1:
+ | // RA = results*8, RD = (nresults+1)*8
+ | lwz PC, FRAME_PC(BASE)
+ | add RA, BASE, RA
+ | mr MULTRES, RD
+ | andix. TMP0, PC, FRAME_TYPE
+ | xori TMP1, PC, FRAME_VARG
+ | bney ->BC_RETV_Z
+ |
+ | lwz INS, -4(PC)
+ | subi TMP2, BASE, 8
+ | decode_RB8 RB, INS
+ if (op == BC_RET1) {
+ | lfd f0, 0(RA)
+ | stfd f0, 0(TMP2)
+ }
+ |5:
+ | cmplw RB, RD
+ | decode_RA8 RA, INS
+ | bgt >6
+ | sub BASE, TMP2, RA
+ | lwz LFUNC:TMP1, FRAME_FUNC(BASE)
+ | ins_next1
+ | lwz TMP1, LFUNC:TMP1->pc
+ | lwz KBASE, PC2PROTO(k)(TMP1)
+ | ins_next2
+ |
+ |6: // Fill up results with nil.
+ | subi TMP1, RD, 8
+ | addi RD, RD, 8
+ | stwx TISNIL, TMP2, TMP1
+ | b <5
+ break;
+
+ /* -- Loops and branches ------------------------------------------------ */
+
+ case BC_FORL:
+ |.if JIT
+ | hotloop
+ |.endif
+ | // Fall through. Assumes BC_IFORL follows.
+ break;
+
+ case BC_JFORI:
+ case BC_JFORL:
+#if !LJ_HASJIT
+ break;
+#endif
+ case BC_FORI:
+ case BC_IFORL:
+ | // RA = base*8, RD = target (after end of loop or start of loop)
+ vk = (op == BC_IFORL || op == BC_JFORL);
+ |.if DUALNUM
+ | // Integer loop.
+ | lwzux TMP1, RA, BASE
+ | lwz CARG1, FORL_IDX*8+4(RA)
+ | cmplw cr0, TMP1, TISNUM
+ if (vk) {
+ | lwz CARG3, FORL_STEP*8+4(RA)
+ | bne >9
+ |.if GPR64
+ | // Need to check overflow for (a<<32) + (b<<32).
+ | rldicr TMP0, CARG1, 32, 31
+ | rldicr TMP2, CARG3, 32, 31
+ | add CARG1, CARG1, CARG3
+ | addo. TMP0, TMP0, TMP2
+ |.else
+ | addo. CARG1, CARG1, CARG3
+ |.endif
+ | cmpwi cr6, CARG3, 0
+ | lwz CARG2, FORL_STOP*8+4(RA)
+ | bso >6
+ |4:
+ | stw CARG1, FORL_IDX*8+4(RA)
+ } else {
+ | lwz TMP3, FORL_STEP*8(RA)
+ | lwz CARG3, FORL_STEP*8+4(RA)
+ | lwz TMP2, FORL_STOP*8(RA)
+ | lwz CARG2, FORL_STOP*8+4(RA)
+ | cmplw cr7, TMP3, TISNUM
+ | cmplw cr1, TMP2, TISNUM
+ | crand 4*cr0+eq, 4*cr0+eq, 4*cr7+eq
+ | crand 4*cr0+eq, 4*cr0+eq, 4*cr1+eq
+ | cmpwi cr6, CARG3, 0
+ | bne >9
+ }
+ | blt cr6, >5
+ | cmpw CARG1, CARG2
+ |1:
+ | stw TISNUM, FORL_EXT*8(RA)
+ if (op != BC_JFORL) {
+ | srwi RD, RD, 1
+ }
+ | stw CARG1, FORL_EXT*8+4(RA)
+ if (op != BC_JFORL) {
+ | add RD, PC, RD
+ }
+ if (op == BC_FORI) {
+ | bgt >3 // See FP loop below.
+ } else if (op == BC_JFORI) {
+ | addis PC, RD, -(BCBIAS_J*4 >> 16)
+ | bley >7
+ } else if (op == BC_IFORL) {
+ | bgt >2
+ | addis PC, RD, -(BCBIAS_J*4 >> 16)
+ } else {
+ | bley =>BC_JLOOP
+ }
+ |2:
+ | ins_next
+ |5: // Invert check for negative step.
+ | cmpw CARG2, CARG1
+ | b <1
+ if (vk) {
+ |6: // Potential overflow.
+ | checkov TMP0, <4 // Ignore unrelated overflow.
+ | b <2
+ }
+ |.endif
+ if (vk) {
+ |.if DUALNUM
+ |9: // FP loop.
+ | lfd f1, FORL_IDX*8(RA)
+ |.else
+ | lfdux f1, RA, BASE
+ |.endif
+ | lfd f3, FORL_STEP*8(RA)
+ | lfd f2, FORL_STOP*8(RA)
+ | lwz TMP3, FORL_STEP*8(RA)
+ | fadd f1, f1, f3
+ | stfd f1, FORL_IDX*8(RA)
+ } else {
+ |.if DUALNUM
+ |9: // FP loop.
+ |.else
+ | lwzux TMP1, RA, BASE
+ | lwz TMP3, FORL_STEP*8(RA)
+ | lwz TMP2, FORL_STOP*8(RA)
+ | cmplw cr0, TMP1, TISNUM
+ | cmplw cr7, TMP3, TISNUM
+ | cmplw cr1, TMP2, TISNUM
+ |.endif
+ | lfd f1, FORL_IDX*8(RA)
+ | crand 4*cr0+lt, 4*cr0+lt, 4*cr7+lt
+ | crand 4*cr0+lt, 4*cr0+lt, 4*cr1+lt
+ | lfd f2, FORL_STOP*8(RA)
+ | bge ->vmeta_for
+ }
+ | cmpwi cr6, TMP3, 0
+ if (op != BC_JFORL) {
+ | srwi RD, RD, 1
+ }
+ | stfd f1, FORL_EXT*8(RA)
+ if (op != BC_JFORL) {
+ | add RD, PC, RD
+ }
+ | fcmpu cr0, f1, f2
+ if (op == BC_JFORI) {
+ | addis PC, RD, -(BCBIAS_J*4 >> 16)
+ }
+ | blt cr6, >5
+ if (op == BC_FORI) {
+ | bgt >3
+ } else if (op == BC_IFORL) {
+ |.if DUALNUM
+ | bgty <2
+ |.else
+ | bgt >2
+ |.endif
+ |1:
+ | addis PC, RD, -(BCBIAS_J*4 >> 16)
+ } else if (op == BC_JFORI) {
+ | bley >7
+ } else {
+ | bley =>BC_JLOOP
+ }
+ |.if DUALNUM
+ | b <2
+ |.else
+ |2:
+ | ins_next
+ |.endif
+ |5: // Negative step.
+ if (op == BC_FORI) {
+ | bge <2
+ |3: // Used by integer loop, too.
+ | addis PC, RD, -(BCBIAS_J*4 >> 16)
+ } else if (op == BC_IFORL) {
+ | bgey <1
+ } else if (op == BC_JFORI) {
+ | bgey >7
+ } else {
+ | bgey =>BC_JLOOP
+ }
+ | b <2
+ if (op == BC_JFORI) {
+ |7:
+ | lwz INS, -4(PC)
+ | decode_RD8 RD, INS
+ | b =>BC_JLOOP
+ }
+ break;
+
+ case BC_ITERL:
+ |.if JIT
+ | hotloop
+ |.endif
+ | // Fall through. Assumes BC_IITERL follows.
+ break;
+
+ case BC_JITERL:
+#if !LJ_HASJIT
+ break;
+#endif
+ case BC_IITERL:
+ | // RA = base*8, RD = target
+ | lwzux TMP1, RA, BASE
+ | lwz TMP2, 4(RA)
+ | checknil TMP1; beq >1 // Stop if iterator returned nil.
+ if (op == BC_JITERL) {
+ | stw TMP1, -8(RA)
+ | stw TMP2, -4(RA)
+ | b =>BC_JLOOP
+ } else {
+ | branch_RD // Otherwise save control var + branch.
+ | stw TMP1, -8(RA)
+ | stw TMP2, -4(RA)
+ }
+ |1:
+ | ins_next
+ break;
+
+ case BC_LOOP:
+ | // RA = base*8, RD = target (loop extent)
+ | // Note: RA/RD is only used by trace recorder to determine scope/extent
+ | // This opcode does NOT jump, it's only purpose is to detect a hot loop.
+ |.if JIT
+ | hotloop
+ |.endif
+ | // Fall through. Assumes BC_ILOOP follows.
+ break;
+
+ case BC_ILOOP:
+ | // RA = base*8, RD = target (loop extent)
+ | ins_next
+ break;
+
+ case BC_JLOOP:
+ |.if JIT
+ | // RA = base*8 (ignored), RD = traceno*8
+ | lwz TMP1, DISPATCH_J(trace)(DISPATCH)
+ | srwi RD, RD, 1
+ | // Traces on PPC don't store the trace number, so use 0.
+ | stw ZERO, DISPATCH_GL(vmstate)(DISPATCH)
+ | lwzx TRACE:TMP2, TMP1, RD
+ | clrso TMP1
+ | lp TMP2, TRACE:TMP2->mcode
+ | stw BASE, DISPATCH_GL(jit_base)(DISPATCH)
+ | mtctr TMP2
+ | stw L, DISPATCH_GL(jit_L)(DISPATCH)
+ | addi JGL, DISPATCH, GG_DISP2G+32768
+ | bctr
+ |.endif
+ break;
+
+ case BC_JMP:
+ | // RA = base*8 (only used by trace recorder), RD = target
+ | branch_RD
+ | ins_next
+ break;
+
+ /* -- Function headers -------------------------------------------------- */
+
+ case BC_FUNCF:
+ |.if JIT
+ | hotcall
+ |.endif
+ case BC_FUNCV: /* NYI: compiled vararg functions. */
+ | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.
+ break;
+
+ case BC_JFUNCF:
+#if !LJ_HASJIT
+ break;
+#endif
+ case BC_IFUNCF:
+ | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8
+ | lwz TMP2, L->maxstack
+ | lbz TMP1, -4+PC2PROTO(numparams)(PC)
+ | lwz KBASE, -4+PC2PROTO(k)(PC)
+ | cmplw RA, TMP2
+ | slwi TMP1, TMP1, 3
+ | bgt ->vm_growstack_l
+ if (op != BC_JFUNCF) {
+ | ins_next1
+ }
+ |2:
+ | cmplw NARGS8:RC, TMP1 // Check for missing parameters.
+ | blt >3
+ if (op == BC_JFUNCF) {
+ | decode_RD8 RD, INS
+ | b =>BC_JLOOP
+ } else {
+ | ins_next2
+ }
+ |
+ |3: // Clear missing parameters.
+ | stwx TISNIL, BASE, NARGS8:RC
+ | addi NARGS8:RC, NARGS8:RC, 8
+ | b <2
+ break;
+
+ case BC_JFUNCV:
+#if !LJ_HASJIT
+ break;
+#endif
+ | NYI // NYI: compiled vararg functions
+ break; /* NYI: compiled vararg functions. */
+
+ case BC_IFUNCV:
+ | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8
+ | lwz TMP2, L->maxstack
+ | add TMP1, BASE, RC
+ | add TMP0, RA, RC
+ | stw LFUNC:RB, 4(TMP1) // Store copy of LFUNC.
+ | addi TMP3, RC, 8+FRAME_VARG
+ | lwz KBASE, -4+PC2PROTO(k)(PC)
+ | cmplw TMP0, TMP2
+ | stw TMP3, 0(TMP1) // Store delta + FRAME_VARG.
+ | bge ->vm_growstack_l
+ | lbz TMP2, -4+PC2PROTO(numparams)(PC)
+ | mr RA, BASE
+ | mr RC, TMP1
+ | ins_next1
+ | cmpwi TMP2, 0
+ | addi BASE, TMP1, 8
+ | beq >3
+ |1:
+ | cmplw RA, RC // Less args than parameters?
+ | lwz TMP0, 0(RA)
+ | lwz TMP3, 4(RA)
+ | bge >4
+ | stw TISNIL, 0(RA) // Clear old fixarg slot (help the GC).
+ | addi RA, RA, 8
+ |2:
+ | addic. TMP2, TMP2, -1
+ | stw TMP0, 8(TMP1)
+ | stw TMP3, 12(TMP1)
+ | addi TMP1, TMP1, 8
+ | bne <1
+ |3:
+ | ins_next2
+ |
+ |4: // Clear missing parameters.
+ | li TMP0, LJ_TNIL
+ | b <2
+ break;
+
+ case BC_FUNCC:
+ case BC_FUNCCW:
+ | // BASE = new base, RA = BASE+framesize*8, RB = CFUNC, RC = nargs*8
+ if (op == BC_FUNCC) {
+ | lp RD, CFUNC:RB->f
+ } else {
+ | lp RD, DISPATCH_GL(wrapf)(DISPATCH)
+ }
+ | add TMP1, RA, NARGS8:RC
+ | lwz TMP2, L->maxstack
+ | .toc lp TMP3, 0(RD)
+ | add RC, BASE, NARGS8:RC
+ | stp BASE, L->base
+ | cmplw TMP1, TMP2
+ | stp RC, L->top
+ | li_vmstate C
+ |.if TOC
+ | mtctr TMP3
+ |.else
+ | mtctr RD
+ |.endif
+ if (op == BC_FUNCCW) {
+ | lp CARG2, CFUNC:RB->f
+ }
+ | mr CARG1, L
+ | bgt ->vm_growstack_c // Need to grow stack.
+ | .toc lp TOCREG, TOC_OFS(RD)
+ | .tocenv lp ENVREG, ENV_OFS(RD)
+ | st_vmstate
+ | bctrl // (lua_State *L [, lua_CFunction f])
+ | // Returns nresults.
+ | lp BASE, L->base
+ | .toc ld TOCREG, SAVE_TOC
+ | slwi RD, CRET1, 3
+ | lp TMP1, L->top
+ | li_vmstate INTERP
+ | lwz PC, FRAME_PC(BASE) // Fetch PC of caller.
+ | sub RA, TMP1, RD // RA = L->top - nresults*8
+ | st_vmstate
+ | b ->vm_returnc
+ break;
+
+ /* ---------------------------------------------------------------------- */
+
+ default:
+ fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]);
+ exit(2);
+ break;
+ }
+}
+
+static int build_backend(BuildCtx *ctx)
+{
+ int op;
+
+ dasm_growpc(Dst, BC__MAX);
+
+ build_subroutines(ctx);
+
+ |.code_op
+ for (op = 0; op < BC__MAX; op++)
+ build_ins(ctx, (BCOp)op, op);
+
+ return BC__MAX;
+}
+
+/* Emit pseudo frame-info for all assembler functions. */
+static void emit_asm_debug(BuildCtx *ctx)
+{
+ int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);
+ int i;
+ switch (ctx->mode) {
+ case BUILD_elfasm:
+ fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n");
+ fprintf(ctx->fp,
+ ".Lframe0:\n"
+ "\t.long .LECIE0-.LSCIE0\n"
+ ".LSCIE0:\n"
+ "\t.long 0xffffffff\n"
+ "\t.byte 0x1\n"
+ "\t.string \"\"\n"
+ "\t.uleb128 0x1\n"
+ "\t.sleb128 -4\n"
+ "\t.byte 65\n"
+ "\t.byte 0xc\n\t.uleb128 1\n\t.uleb128 0\n"
+ "\t.align 2\n"
+ ".LECIE0:\n\n");
+ fprintf(ctx->fp,
+ ".LSFDE0:\n"
+ "\t.long .LEFDE0-.LASFDE0\n"
+ ".LASFDE0:\n"
+ "\t.long .Lframe0\n"
+ "\t.long .Lbegin\n"
+ "\t.long %d\n"
+ "\t.byte 0xe\n\t.uleb128 %d\n"
+ "\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n"
+ "\t.byte 0x5\n\t.uleb128 70\n\t.uleb128 55\n",
+ fcofs, CFRAME_SIZE);
+ for (i = 14; i <= 31; i++)
+ fprintf(ctx->fp,
+ "\t.byte %d\n\t.uleb128 %d\n"
+ "\t.byte %d\n\t.uleb128 %d\n",
+ 0x80+i, 37+(31-i), 0x80+32+i, 2+2*(31-i));
+ fprintf(ctx->fp,
+ "\t.align 2\n"
+ ".LEFDE0:\n\n");
+#if LJ_HASFFI
+ fprintf(ctx->fp,
+ ".LSFDE1:\n"
+ "\t.long .LEFDE1-.LASFDE1\n"
+ ".LASFDE1:\n"
+ "\t.long .Lframe0\n"
+#if LJ_TARGET_PS3
+ "\t.long .lj_vm_ffi_call\n"
+#else
+ "\t.long lj_vm_ffi_call\n"
+#endif
+ "\t.long %d\n"
+ "\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n"
+ "\t.byte 0x8e\n\t.uleb128 2\n"
+ "\t.byte 0xd\n\t.uleb128 0xe\n"
+ "\t.align 2\n"
+ ".LEFDE1:\n\n", (int)ctx->codesz - fcofs);
+#endif
+#if !LJ_NO_UNWIND
+ fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@progbits\n");
+ fprintf(ctx->fp,
+ ".Lframe1:\n"
+ "\t.long .LECIE1-.LSCIE1\n"
+ ".LSCIE1:\n"
+ "\t.long 0\n"
+ "\t.byte 0x1\n"
+ "\t.string \"zPR\"\n"
+ "\t.uleb128 0x1\n"
+ "\t.sleb128 -4\n"
+ "\t.byte 65\n"
+ "\t.uleb128 6\n" /* augmentation length */
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.long lj_err_unwind_dwarf-.\n"
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.byte 0xc\n\t.uleb128 1\n\t.uleb128 0\n"
+ "\t.align 2\n"
+ ".LECIE1:\n\n");
+ fprintf(ctx->fp,
+ ".LSFDE2:\n"
+ "\t.long .LEFDE2-.LASFDE2\n"
+ ".LASFDE2:\n"
+ "\t.long .LASFDE2-.Lframe1\n"
+ "\t.long .Lbegin-.\n"
+ "\t.long %d\n"
+ "\t.uleb128 0\n" /* augmentation length */
+ "\t.byte 0xe\n\t.uleb128 %d\n"
+ "\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n"
+ "\t.byte 0x5\n\t.uleb128 70\n\t.uleb128 55\n",
+ fcofs, CFRAME_SIZE);
+ for (i = 14; i <= 31; i++)
+ fprintf(ctx->fp,
+ "\t.byte %d\n\t.uleb128 %d\n"
+ "\t.byte %d\n\t.uleb128 %d\n",
+ 0x80+i, 37+(31-i), 0x80+32+i, 2+2*(31-i));
+ fprintf(ctx->fp,
+ "\t.align 2\n"
+ ".LEFDE2:\n\n");
+#if LJ_HASFFI
+ fprintf(ctx->fp,
+ ".Lframe2:\n"
+ "\t.long .LECIE2-.LSCIE2\n"
+ ".LSCIE2:\n"
+ "\t.long 0\n"
+ "\t.byte 0x1\n"
+ "\t.string \"zR\"\n"
+ "\t.uleb128 0x1\n"
+ "\t.sleb128 -4\n"
+ "\t.byte 65\n"
+ "\t.uleb128 1\n" /* augmentation length */
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.byte 0xc\n\t.uleb128 1\n\t.uleb128 0\n"
+ "\t.align 2\n"
+ ".LECIE2:\n\n");
+ fprintf(ctx->fp,
+ ".LSFDE3:\n"
+ "\t.long .LEFDE3-.LASFDE3\n"
+ ".LASFDE3:\n"
+ "\t.long .LASFDE3-.Lframe2\n"
+ "\t.long lj_vm_ffi_call-.\n"
+ "\t.long %d\n"
+ "\t.uleb128 0\n" /* augmentation length */
+ "\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n"
+ "\t.byte 0x8e\n\t.uleb128 2\n"
+ "\t.byte 0xd\n\t.uleb128 0xe\n"
+ "\t.align 2\n"
+ ".LEFDE3:\n\n", (int)ctx->codesz - fcofs);
+#endif
+#endif
+ break;
+ default:
+ break;
+ }
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/vm_ppcspe.dasc b/src/3rdparty/LuaJIT-2.0.5/src/vm_ppcspe.dasc
new file mode 100644
index 0000000..2a57a41
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/vm_ppcspe.dasc
@@ -0,0 +1,3691 @@
+|// Low-level VM code for PowerPC/e500 CPUs.
+|// Bytecode interpreter, fast functions and helper functions.
+|// Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+|
+|.arch ppc
+|.section code_op, code_sub
+|
+|.actionlist build_actionlist
+|.globals GLOB_
+|.globalnames globnames
+|.externnames extnames
+|
+|// Note: The ragged indentation of the instructions is intentional.
+|// The starting columns indicate data dependencies.
+|
+|//-----------------------------------------------------------------------
+|
+|// Fixed register assignments for the interpreter.
+|// Don't use: r1 = sp, r2 and r13 = reserved and/or small data area ptr
+|
+|// The following must be C callee-save (but BASE is often refetched).
+|.define BASE, r14 // Base of current Lua stack frame.
+|.define KBASE, r15 // Constants of current Lua function.
+|.define PC, r16 // Next PC.
+|.define DISPATCH, r17 // Opcode dispatch table.
+|.define LREG, r18 // Register holding lua_State (also in SAVE_L).
+|.define MULTRES, r19 // Size of multi-result: (nresults+1)*8.
+|
+|// Constants for vectorized type-comparisons (hi+low GPR). C callee-save.
+|.define TISNUM, r22
+|.define TISSTR, r23
+|.define TISTAB, r24
+|.define TISFUNC, r25
+|.define TISNIL, r26
+|.define TOBIT, r27
+|.define ZERO, TOBIT // Zero in lo word.
+|
+|// The following temporaries are not saved across C calls, except for RA.
+|.define RA, r20 // Callee-save.
+|.define RB, r10
+|.define RC, r11
+|.define RD, r12
+|.define INS, r7 // Overlaps CARG5.
+|
+|.define TMP0, r0
+|.define TMP1, r8
+|.define TMP2, r9
+|.define TMP3, r6 // Overlaps CARG4.
+|
+|// Saved temporaries.
+|.define SAVE0, r21
+|
+|// Calling conventions.
+|.define CARG1, r3
+|.define CARG2, r4
+|.define CARG3, r5
+|.define CARG4, r6 // Overlaps TMP3.
+|.define CARG5, r7 // Overlaps INS.
+|
+|.define CRET1, r3
+|.define CRET2, r4
+|
+|// Stack layout while in interpreter. Must match with lj_frame.h.
+|.define SAVE_LR, 188(sp)
+|.define CFRAME_SPACE, 184 // Delta for sp.
+|// Back chain for sp: 184(sp) <-- sp entering interpreter
+|.define SAVE_r31, 176(sp) // 64 bit register saves.
+|.define SAVE_r30, 168(sp)
+|.define SAVE_r29, 160(sp)
+|.define SAVE_r28, 152(sp)
+|.define SAVE_r27, 144(sp)
+|.define SAVE_r26, 136(sp)
+|.define SAVE_r25, 128(sp)
+|.define SAVE_r24, 120(sp)
+|.define SAVE_r23, 112(sp)
+|.define SAVE_r22, 104(sp)
+|.define SAVE_r21, 96(sp)
+|.define SAVE_r20, 88(sp)
+|.define SAVE_r19, 80(sp)
+|.define SAVE_r18, 72(sp)
+|.define SAVE_r17, 64(sp)
+|.define SAVE_r16, 56(sp)
+|.define SAVE_r15, 48(sp)
+|.define SAVE_r14, 40(sp)
+|.define SAVE_CR, 36(sp)
+|.define UNUSED1, 32(sp)
+|.define SAVE_ERRF, 28(sp) // 32 bit C frame info.
+|.define SAVE_NRES, 24(sp)
+|.define SAVE_CFRAME, 20(sp)
+|.define SAVE_L, 16(sp)
+|.define SAVE_PC, 12(sp)
+|.define SAVE_MULTRES, 8(sp)
+|// Next frame lr: 4(sp)
+|// Back chain for sp: 0(sp) <-- sp while in interpreter
+|
+|.macro save_, reg; evstdd reg, SAVE_..reg; .endmacro
+|.macro rest_, reg; evldd reg, SAVE_..reg; .endmacro
+|
+|.macro saveregs
+| stwu sp, -CFRAME_SPACE(sp)
+| save_ r14; save_ r15; save_ r16; save_ r17; save_ r18; save_ r19
+| mflr r0; mfcr r12
+| save_ r20; save_ r21; save_ r22; save_ r23; save_ r24; save_ r25
+| stw r0, SAVE_LR; stw r12, SAVE_CR
+| save_ r26; save_ r27; save_ r28; save_ r29; save_ r30; save_ r31
+|.endmacro
+|
+|.macro restoreregs
+| lwz r0, SAVE_LR; lwz r12, SAVE_CR
+| rest_ r14; rest_ r15; rest_ r16; rest_ r17; rest_ r18; rest_ r19
+| mtlr r0; mtcrf 0x38, r12
+| rest_ r20; rest_ r21; rest_ r22; rest_ r23; rest_ r24; rest_ r25
+| rest_ r26; rest_ r27; rest_ r28; rest_ r29; rest_ r30; rest_ r31
+| addi sp, sp, CFRAME_SPACE
+|.endmacro
+|
+|// Type definitions. Some of these are only used for documentation.
+|.type L, lua_State, LREG
+|.type GL, global_State
+|.type TVALUE, TValue
+|.type GCOBJ, GCobj
+|.type STR, GCstr
+|.type TAB, GCtab
+|.type LFUNC, GCfuncL
+|.type CFUNC, GCfuncC
+|.type PROTO, GCproto
+|.type UPVAL, GCupval
+|.type NODE, Node
+|.type NARGS8, int
+|.type TRACE, GCtrace
+|
+|//-----------------------------------------------------------------------
+|
+|// These basic macros should really be part of DynASM.
+|.macro srwi, rx, ry, n; rlwinm rx, ry, 32-n, n, 31; .endmacro
+|.macro slwi, rx, ry, n; rlwinm rx, ry, n, 0, 31-n; .endmacro
+|.macro rotlwi, rx, ry, n; rlwinm rx, ry, n, 0, 31; .endmacro
+|.macro rotlw, rx, ry, rn; rlwnm rx, ry, rn, 0, 31; .endmacro
+|.macro subi, rx, ry, i; addi rx, ry, -i; .endmacro
+|
+|// Trap for not-yet-implemented parts.
+|.macro NYI; tw 4, sp, sp; .endmacro
+|
+|//-----------------------------------------------------------------------
+|
+|// Access to frame relative to BASE.
+|.define FRAME_PC, -8
+|.define FRAME_FUNC, -4
+|
+|// Instruction decode.
+|.macro decode_OP4, dst, ins; rlwinm dst, ins, 2, 22, 29; .endmacro
+|.macro decode_RA8, dst, ins; rlwinm dst, ins, 27, 21, 28; .endmacro
+|.macro decode_RB8, dst, ins; rlwinm dst, ins, 11, 21, 28; .endmacro
+|.macro decode_RC8, dst, ins; rlwinm dst, ins, 19, 21, 28; .endmacro
+|.macro decode_RD8, dst, ins; rlwinm dst, ins, 19, 13, 28; .endmacro
+|
+|.macro decode_OP1, dst, ins; rlwinm dst, ins, 0, 24, 31; .endmacro
+|.macro decode_RD4, dst, ins; rlwinm dst, ins, 18, 14, 29; .endmacro
+|
+|// Instruction fetch.
+|.macro ins_NEXT1
+| lwz INS, 0(PC)
+| addi PC, PC, 4
+|.endmacro
+|// Instruction decode+dispatch.
+|.macro ins_NEXT2
+| decode_OP4 TMP1, INS
+| decode_RB8 RB, INS
+| decode_RD8 RD, INS
+| lwzx TMP0, DISPATCH, TMP1
+| decode_RA8 RA, INS
+| decode_RC8 RC, INS
+| mtctr TMP0
+| bctr
+|.endmacro
+|.macro ins_NEXT
+| ins_NEXT1
+| ins_NEXT2
+|.endmacro
+|
+|// Instruction footer.
+|.if 1
+| // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.
+| .define ins_next, ins_NEXT
+| .define ins_next_, ins_NEXT
+| .define ins_next1, ins_NEXT1
+| .define ins_next2, ins_NEXT2
+|.else
+| // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.
+| // Affects only certain kinds of benchmarks (and only with -j off).
+| .macro ins_next
+| b ->ins_next
+| .endmacro
+| .macro ins_next1
+| .endmacro
+| .macro ins_next2
+| b ->ins_next
+| .endmacro
+| .macro ins_next_
+| ->ins_next:
+| ins_NEXT
+| .endmacro
+|.endif
+|
+|// Call decode and dispatch.
+|.macro ins_callt
+| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC
+| lwz PC, LFUNC:RB->pc
+| lwz INS, 0(PC)
+| addi PC, PC, 4
+| decode_OP4 TMP1, INS
+| decode_RA8 RA, INS
+| lwzx TMP0, DISPATCH, TMP1
+| add RA, RA, BASE
+| mtctr TMP0
+| bctr
+|.endmacro
+|
+|.macro ins_call
+| // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, PC = caller PC
+| stw PC, FRAME_PC(BASE)
+| ins_callt
+|.endmacro
+|
+|//-----------------------------------------------------------------------
+|
+|// Macros to test operand types.
+|.macro checknum, reg; evcmpltu reg, TISNUM; .endmacro
+|.macro checkstr, reg; evcmpeq reg, TISSTR; .endmacro
+|.macro checktab, reg; evcmpeq reg, TISTAB; .endmacro
+|.macro checkfunc, reg; evcmpeq reg, TISFUNC; .endmacro
+|.macro checknil, reg; evcmpeq reg, TISNIL; .endmacro
+|.macro checkok, label; blt label; .endmacro
+|.macro checkfail, label; bge label; .endmacro
+|.macro checkanyfail, label; bns label; .endmacro
+|.macro checkallok, label; bso label; .endmacro
+|
+|.macro branch_RD
+| srwi TMP0, RD, 1
+| add PC, PC, TMP0
+| addis PC, PC, -(BCBIAS_J*4 >> 16)
+|.endmacro
+|
+|// Assumes DISPATCH is relative to GL.
+#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field))
+#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field))
+|
+#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
+|
+|.macro hotloop
+| NYI
+|.endmacro
+|
+|.macro hotcall
+| NYI
+|.endmacro
+|
+|// Set current VM state. Uses TMP0.
+|.macro li_vmstate, st; li TMP0, ~LJ_VMST_..st; .endmacro
+|.macro st_vmstate; stw TMP0, DISPATCH_GL(vmstate)(DISPATCH); .endmacro
+|
+|// Move table write barrier back. Overwrites mark and tmp.
+|.macro barrierback, tab, mark, tmp
+| lwz tmp, DISPATCH_GL(gc.grayagain)(DISPATCH)
+| // Assumes LJ_GC_BLACK is 0x04.
+| rlwinm mark, mark, 0, 30, 28 // black2gray(tab)
+| stw tab, DISPATCH_GL(gc.grayagain)(DISPATCH)
+| stb mark, tab->marked
+| stw tmp, tab->gclist
+|.endmacro
+|
+|//-----------------------------------------------------------------------
+
+/* Generate subroutines used by opcodes and other parts of the VM. */
+/* The .code_sub section should be last to help static branch prediction. */
+static void build_subroutines(BuildCtx *ctx)
+{
+ |.code_sub
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Return handling ----------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_returnp:
+ | // See vm_return. Also: TMP2 = previous base.
+ | andi. TMP0, PC, FRAME_P
+ | evsplati TMP1, LJ_TTRUE
+ | beq ->cont_dispatch
+ |
+ | // Return from pcall or xpcall fast func.
+ | lwz PC, FRAME_PC(TMP2) // Fetch PC of previous frame.
+ | mr BASE, TMP2 // Restore caller base.
+ | // Prepending may overwrite the pcall frame, so do it at the end.
+ | stwu TMP1, FRAME_PC(RA) // Prepend true to results.
+ |
+ |->vm_returnc:
+ | addi RD, RD, 8 // RD = (nresults+1)*8.
+ | andi. TMP0, PC, FRAME_TYPE
+ | cmpwi cr1, RD, 0
+ | li CRET1, LUA_YIELD
+ | beq cr1, ->vm_unwind_c_eh
+ | mr MULTRES, RD
+ | beq ->BC_RET_Z // Handle regular return to Lua.
+ |
+ |->vm_return:
+ | // BASE = base, RA = resultptr, RD/MULTRES = (nresults+1)*8, PC = return
+ | // TMP0 = PC & FRAME_TYPE
+ | cmpwi TMP0, FRAME_C
+ | rlwinm TMP2, PC, 0, 0, 28
+ | li_vmstate C
+ | sub TMP2, BASE, TMP2 // TMP2 = previous base.
+ | bne ->vm_returnp
+ |
+ | addic. TMP1, RD, -8
+ | stw TMP2, L->base
+ | lwz TMP2, SAVE_NRES
+ | subi BASE, BASE, 8
+ | st_vmstate
+ | slwi TMP2, TMP2, 3
+ | beq >2
+ |1:
+ | addic. TMP1, TMP1, -8
+ | evldd TMP0, 0(RA)
+ | addi RA, RA, 8
+ | evstdd TMP0, 0(BASE)
+ | addi BASE, BASE, 8
+ | bne <1
+ |
+ |2:
+ | cmpw TMP2, RD // More/less results wanted?
+ | bne >6
+ |3:
+ | stw BASE, L->top // Store new top.
+ |
+ |->vm_leave_cp:
+ | lwz TMP0, SAVE_CFRAME // Restore previous C frame.
+ | li CRET1, 0 // Ok return status for vm_pcall.
+ | stw TMP0, L->cframe
+ |
+ |->vm_leave_unw:
+ | restoreregs
+ | blr
+ |
+ |6:
+ | ble >7 // Less results wanted?
+ | // More results wanted. Check stack size and fill up results with nil.
+ | lwz TMP1, L->maxstack
+ | cmplw BASE, TMP1
+ | bge >8
+ | evstdd TISNIL, 0(BASE)
+ | addi RD, RD, 8
+ | addi BASE, BASE, 8
+ | b <2
+ |
+ |7: // Less results wanted.
+ | sub TMP0, RD, TMP2
+ | cmpwi TMP2, 0 // LUA_MULTRET+1 case?
+ | sub TMP0, BASE, TMP0 // Subtract the difference.
+ | iseleq BASE, BASE, TMP0 // Either keep top or shrink it.
+ | b <3
+ |
+ |8: // Corner case: need to grow stack for filling up results.
+ | // This can happen if:
+ | // - A C function grows the stack (a lot).
+ | // - The GC shrinks the stack in between.
+ | // - A return back from a lua_call() with (high) nresults adjustment.
+ | stw BASE, L->top // Save current top held in BASE (yes).
+ | mr SAVE0, RD
+ | mr CARG2, TMP2
+ | mr CARG1, L
+ | bl extern lj_state_growstack // (lua_State *L, int n)
+ | lwz TMP2, SAVE_NRES
+ | mr RD, SAVE0
+ | slwi TMP2, TMP2, 3
+ | lwz BASE, L->top // Need the (realloced) L->top in BASE.
+ | b <2
+ |
+ |->vm_unwind_c: // Unwind C stack, return from vm_pcall.
+ | // (void *cframe, int errcode)
+ | mr sp, CARG1
+ | mr CRET1, CARG2
+ |->vm_unwind_c_eh: // Landing pad for external unwinder.
+ | lwz L, SAVE_L
+ | li TMP0, ~LJ_VMST_C
+ | lwz GL:TMP1, L->glref
+ | stw TMP0, GL:TMP1->vmstate
+ | b ->vm_leave_unw
+ |
+ |->vm_unwind_ff: // Unwind C stack, return from ff pcall.
+ | // (void *cframe)
+ | rlwinm sp, CARG1, 0, 0, 29
+ |->vm_unwind_ff_eh: // Landing pad for external unwinder.
+ | lwz L, SAVE_L
+ | evsplati TISNUM, LJ_TISNUM+1 // Setup type comparison constants.
+ | evsplati TISFUNC, LJ_TFUNC
+ | lus TOBIT, 0x4338
+ | evsplati TISTAB, LJ_TTAB
+ | li TMP0, 0
+ | lwz BASE, L->base
+ | evmergelo TOBIT, TOBIT, TMP0
+ | lwz DISPATCH, L->glref // Setup pointer to dispatch table.
+ | evsplati TISSTR, LJ_TSTR
+ | li TMP1, LJ_TFALSE
+ | evsplati TISNIL, LJ_TNIL
+ | li_vmstate INTERP
+ | lwz PC, FRAME_PC(BASE) // Fetch PC of previous frame.
+ | la RA, -8(BASE) // Results start at BASE-8.
+ | addi DISPATCH, DISPATCH, GG_G2DISP
+ | stw TMP1, 0(RA) // Prepend false to error message.
+ | li RD, 16 // 2 results: false + error message.
+ | st_vmstate
+ | b ->vm_returnc
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Grow stack for calls -----------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_growstack_c: // Grow stack for C function.
+ | li CARG2, LUA_MINSTACK
+ | b >2
+ |
+ |->vm_growstack_l: // Grow stack for Lua function.
+ | // BASE = new base, RA = BASE+framesize*8, RC = nargs*8, PC = first PC
+ | add RC, BASE, RC
+ | sub RA, RA, BASE
+ | stw BASE, L->base
+ | addi PC, PC, 4 // Must point after first instruction.
+ | stw RC, L->top
+ | srwi CARG2, RA, 3
+ |2:
+ | // L->base = new base, L->top = top
+ | stw PC, SAVE_PC
+ | mr CARG1, L
+ | bl extern lj_state_growstack // (lua_State *L, int n)
+ | lwz BASE, L->base
+ | lwz RC, L->top
+ | lwz LFUNC:RB, FRAME_FUNC(BASE)
+ | sub RC, RC, BASE
+ | // BASE = new base, RB = LFUNC/CFUNC, RC = nargs*8, FRAME_PC(BASE) = PC
+ | ins_callt // Just retry the call.
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Entry points into the assembler VM ---------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_resume: // Setup C frame and resume thread.
+ | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)
+ | saveregs
+ | mr L, CARG1
+ | lwz DISPATCH, L->glref // Setup pointer to dispatch table.
+ | mr BASE, CARG2
+ | lbz TMP1, L->status
+ | stw L, SAVE_L
+ | li PC, FRAME_CP
+ | addi TMP0, sp, CFRAME_RESUME
+ | addi DISPATCH, DISPATCH, GG_G2DISP
+ | stw CARG3, SAVE_NRES
+ | cmplwi TMP1, 0
+ | stw CARG3, SAVE_ERRF
+ | stw TMP0, L->cframe
+ | stw CARG3, SAVE_CFRAME
+ | stw CARG1, SAVE_PC // Any value outside of bytecode is ok.
+ | beq >3
+ |
+ | // Resume after yield (like a return).
+ | mr RA, BASE
+ | lwz BASE, L->base
+ | evsplati TISNUM, LJ_TISNUM+1 // Setup type comparison constants.
+ | lwz TMP1, L->top
+ | evsplati TISFUNC, LJ_TFUNC
+ | lus TOBIT, 0x4338
+ | evsplati TISTAB, LJ_TTAB
+ | lwz PC, FRAME_PC(BASE)
+ | li TMP2, 0
+ | evsplati TISSTR, LJ_TSTR
+ | sub RD, TMP1, BASE
+ | evmergelo TOBIT, TOBIT, TMP2
+ | stb CARG3, L->status
+ | andi. TMP0, PC, FRAME_TYPE
+ | li_vmstate INTERP
+ | addi RD, RD, 8
+ | evsplati TISNIL, LJ_TNIL
+ | mr MULTRES, RD
+ | st_vmstate
+ | beq ->BC_RET_Z
+ | b ->vm_return
+ |
+ |->vm_pcall: // Setup protected C frame and enter VM.
+ | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)
+ | saveregs
+ | li PC, FRAME_CP
+ | stw CARG4, SAVE_ERRF
+ | b >1
+ |
+ |->vm_call: // Setup C frame and enter VM.
+ | // (lua_State *L, TValue *base, int nres1)
+ | saveregs
+ | li PC, FRAME_C
+ |
+ |1: // Entry point for vm_pcall above (PC = ftype).
+ | lwz TMP1, L:CARG1->cframe
+ | stw CARG3, SAVE_NRES
+ | mr L, CARG1
+ | stw CARG1, SAVE_L
+ | mr BASE, CARG2
+ | stw sp, L->cframe // Add our C frame to cframe chain.
+ | lwz DISPATCH, L->glref // Setup pointer to dispatch table.
+ | stw CARG1, SAVE_PC // Any value outside of bytecode is ok.
+ | stw TMP1, SAVE_CFRAME
+ | addi DISPATCH, DISPATCH, GG_G2DISP
+ |
+ |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype).
+ | lwz TMP2, L->base // TMP2 = old base (used in vmeta_call).
+ | evsplati TISNUM, LJ_TISNUM+1 // Setup type comparison constants.
+ | lwz TMP1, L->top
+ | evsplati TISFUNC, LJ_TFUNC
+ | add PC, PC, BASE
+ | evsplati TISTAB, LJ_TTAB
+ | lus TOBIT, 0x4338
+ | li TMP0, 0
+ | sub PC, PC, TMP2 // PC = frame delta + frame type
+ | evsplati TISSTR, LJ_TSTR
+ | sub NARGS8:RC, TMP1, BASE
+ | evmergelo TOBIT, TOBIT, TMP0
+ | li_vmstate INTERP
+ | evsplati TISNIL, LJ_TNIL
+ | st_vmstate
+ |
+ |->vm_call_dispatch:
+ | // TMP2 = old base, BASE = new base, RC = nargs*8, PC = caller PC
+ | li TMP0, -8
+ | evlddx LFUNC:RB, BASE, TMP0
+ | checkfunc LFUNC:RB
+ | checkfail ->vmeta_call
+ |
+ |->vm_call_dispatch_f:
+ | ins_call
+ | // BASE = new base, RB = func, RC = nargs*8, PC = caller PC
+ |
+ |->vm_cpcall: // Setup protected C frame, call C.
+ | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)
+ | saveregs
+ | mr L, CARG1
+ | lwz TMP0, L:CARG1->stack
+ | stw CARG1, SAVE_L
+ | lwz TMP1, L->top
+ | stw CARG1, SAVE_PC // Any value outside of bytecode is ok.
+ | sub TMP0, TMP0, TMP1 // Compute -savestack(L, L->top).
+ | lwz TMP1, L->cframe
+ | stw sp, L->cframe // Add our C frame to cframe chain.
+ | li TMP2, 0
+ | stw TMP0, SAVE_NRES // Neg. delta means cframe w/o frame.
+ | stw TMP2, SAVE_ERRF // No error function.
+ | stw TMP1, SAVE_CFRAME
+ | mtctr CARG4
+ | bctrl // (lua_State *L, lua_CFunction func, void *ud)
+ | mr. BASE, CRET1
+ | lwz DISPATCH, L->glref // Setup pointer to dispatch table.
+ | li PC, FRAME_CP
+ | addi DISPATCH, DISPATCH, GG_G2DISP
+ | bne <3 // Else continue with the call.
+ | b ->vm_leave_cp // No base? Just remove C frame.
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Metamethod handling ------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |// The lj_meta_* functions (except for lj_meta_cat) don't reallocate the
+ |// stack, so BASE doesn't need to be reloaded across these calls.
+ |
+ |//-- Continuation dispatch ----------------------------------------------
+ |
+ |->cont_dispatch:
+ | // BASE = meta base, RA = resultptr, RD = (nresults+1)*8
+ | lwz TMP0, -12(BASE) // Continuation.
+ | mr RB, BASE
+ | mr BASE, TMP2 // Restore caller BASE.
+ | lwz LFUNC:TMP1, FRAME_FUNC(TMP2)
+ | cmplwi TMP0, 0
+ | lwz PC, -16(RB) // Restore PC from [cont|PC].
+ | beq >1
+ | subi TMP2, RD, 8
+ | lwz TMP1, LFUNC:TMP1->pc
+ | evstddx TISNIL, RA, TMP2 // Ensure one valid arg.
+ | lwz KBASE, PC2PROTO(k)(TMP1)
+ | // BASE = base, RA = resultptr, RB = meta base
+ | mtctr TMP0
+ | bctr // Jump to continuation.
+ |
+ |1: // Tail call from C function.
+ | subi TMP1, RB, 16
+ | sub RC, TMP1, BASE
+ | b ->vm_call_tail
+ |
+ |->cont_cat: // RA = resultptr, RB = meta base
+ | lwz INS, -4(PC)
+ | subi CARG2, RB, 16
+ | decode_RB8 SAVE0, INS
+ | evldd TMP0, 0(RA)
+ | add TMP1, BASE, SAVE0
+ | stw BASE, L->base
+ | cmplw TMP1, CARG2
+ | sub CARG3, CARG2, TMP1
+ | decode_RA8 RA, INS
+ | evstdd TMP0, 0(CARG2)
+ | bne ->BC_CAT_Z
+ | evstddx TMP0, BASE, RA
+ | b ->cont_nop
+ |
+ |//-- Table indexing metamethods -----------------------------------------
+ |
+ |->vmeta_tgets1:
+ | evmergelo STR:RC, TISSTR, STR:RC
+ | la CARG3, DISPATCH_GL(tmptv)(DISPATCH)
+ | decode_RB8 RB, INS
+ | evstdd STR:RC, 0(CARG3)
+ | add CARG2, BASE, RB
+ | b >1
+ |
+ |->vmeta_tgets:
+ | evmergelo TAB:RB, TISTAB, TAB:RB
+ | la CARG2, DISPATCH_GL(tmptv)(DISPATCH)
+ | evmergelo STR:RC, TISSTR, STR:RC
+ | evstdd TAB:RB, 0(CARG2)
+ | la CARG3, DISPATCH_GL(tmptv2)(DISPATCH)
+ | evstdd STR:RC, 0(CARG3)
+ | b >1
+ |
+ |->vmeta_tgetb: // TMP0 = index
+ | efdcfsi TMP0, TMP0
+ | decode_RB8 RB, INS
+ | la CARG3, DISPATCH_GL(tmptv)(DISPATCH)
+ | add CARG2, BASE, RB
+ | evstdd TMP0, 0(CARG3)
+ | b >1
+ |
+ |->vmeta_tgetv:
+ | decode_RB8 RB, INS
+ | decode_RC8 RC, INS
+ | add CARG2, BASE, RB
+ | add CARG3, BASE, RC
+ |1:
+ | stw BASE, L->base
+ | mr CARG1, L
+ | stw PC, SAVE_PC
+ | bl extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k)
+ | // Returns TValue * (finished) or NULL (metamethod).
+ | cmplwi CRET1, 0
+ | beq >3
+ | evldd TMP0, 0(CRET1)
+ | evstddx TMP0, BASE, RA
+ | ins_next
+ |
+ |3: // Call __index metamethod.
+ | // BASE = base, L->top = new base, stack = cont/func/t/k
+ | subfic TMP1, BASE, FRAME_CONT
+ | lwz BASE, L->top
+ | stw PC, -16(BASE) // [cont|PC]
+ | add PC, TMP1, BASE
+ | lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here.
+ | li NARGS8:RC, 16 // 2 args for func(t, k).
+ | b ->vm_call_dispatch_f
+ |
+ |//-----------------------------------------------------------------------
+ |
+ |->vmeta_tsets1:
+ | evmergelo STR:RC, TISSTR, STR:RC
+ | la CARG3, DISPATCH_GL(tmptv)(DISPATCH)
+ | decode_RB8 RB, INS
+ | evstdd STR:RC, 0(CARG3)
+ | add CARG2, BASE, RB
+ | b >1
+ |
+ |->vmeta_tsets:
+ | evmergelo TAB:RB, TISTAB, TAB:RB
+ | la CARG2, DISPATCH_GL(tmptv)(DISPATCH)
+ | evmergelo STR:RC, TISSTR, STR:RC
+ | evstdd TAB:RB, 0(CARG2)
+ | la CARG3, DISPATCH_GL(tmptv2)(DISPATCH)
+ | evstdd STR:RC, 0(CARG3)
+ | b >1
+ |
+ |->vmeta_tsetb: // TMP0 = index
+ | efdcfsi TMP0, TMP0
+ | decode_RB8 RB, INS
+ | la CARG3, DISPATCH_GL(tmptv)(DISPATCH)
+ | add CARG2, BASE, RB
+ | evstdd TMP0, 0(CARG3)
+ | b >1
+ |
+ |->vmeta_tsetv:
+ | decode_RB8 RB, INS
+ | decode_RC8 RC, INS
+ | add CARG2, BASE, RB
+ | add CARG3, BASE, RC
+ |1:
+ | stw BASE, L->base
+ | mr CARG1, L
+ | stw PC, SAVE_PC
+ | bl extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k)
+ | // Returns TValue * (finished) or NULL (metamethod).
+ | cmplwi CRET1, 0
+ | evlddx TMP0, BASE, RA
+ | beq >3
+ | // NOBARRIER: lj_meta_tset ensures the table is not black.
+ | evstdd TMP0, 0(CRET1)
+ | ins_next
+ |
+ |3: // Call __newindex metamethod.
+ | // BASE = base, L->top = new base, stack = cont/func/t/k/(v)
+ | subfic TMP1, BASE, FRAME_CONT
+ | lwz BASE, L->top
+ | stw PC, -16(BASE) // [cont|PC]
+ | add PC, TMP1, BASE
+ | lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here.
+ | li NARGS8:RC, 24 // 3 args for func(t, k, v)
+ | evstdd TMP0, 16(BASE) // Copy value to third argument.
+ | b ->vm_call_dispatch_f
+ |
+ |//-- Comparison metamethods ---------------------------------------------
+ |
+ |->vmeta_comp:
+ | mr CARG1, L
+ | subi PC, PC, 4
+ | add CARG2, BASE, RA
+ | stw PC, SAVE_PC
+ | add CARG3, BASE, RD
+ | stw BASE, L->base
+ | decode_OP1 CARG4, INS
+ | bl extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op)
+ | // Returns 0/1 or TValue * (metamethod).
+ |3:
+ | cmplwi CRET1, 1
+ | bgt ->vmeta_binop
+ |4:
+ | lwz INS, 0(PC)
+ | addi PC, PC, 4
+ | decode_RD4 TMP2, INS
+ | addis TMP3, PC, -(BCBIAS_J*4 >> 16)
+ | add TMP2, TMP2, TMP3
+ | isellt PC, PC, TMP2
+ |->cont_nop:
+ | ins_next
+ |
+ |->cont_ra: // RA = resultptr
+ | lwz INS, -4(PC)
+ | evldd TMP0, 0(RA)
+ | decode_RA8 TMP1, INS
+ | evstddx TMP0, BASE, TMP1
+ | b ->cont_nop
+ |
+ |->cont_condt: // RA = resultptr
+ | lwz TMP0, 0(RA)
+ | li TMP1, LJ_TTRUE
+ | cmplw TMP1, TMP0 // Branch if result is true.
+ | b <4
+ |
+ |->cont_condf: // RA = resultptr
+ | lwz TMP0, 0(RA)
+ | li TMP1, LJ_TFALSE
+ | cmplw TMP0, TMP1 // Branch if result is false.
+ | b <4
+ |
+ |->vmeta_equal:
+ | // CARG2, CARG3, CARG4 are already set by BC_ISEQV/BC_ISNEV.
+ | subi PC, PC, 4
+ | stw BASE, L->base
+ | mr CARG1, L
+ | stw PC, SAVE_PC
+ | bl extern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne)
+ | // Returns 0/1 or TValue * (metamethod).
+ | b <3
+ |
+ |//-- Arithmetic metamethods ---------------------------------------------
+ |
+ |->vmeta_arith_vn:
+ | add CARG3, BASE, RB
+ | add CARG4, KBASE, RC
+ | b >1
+ |
+ |->vmeta_arith_nv:
+ | add CARG3, KBASE, RC
+ | add CARG4, BASE, RB
+ | b >1
+ |
+ |->vmeta_unm:
+ | add CARG3, BASE, RD
+ | mr CARG4, CARG3
+ | b >1
+ |
+ |->vmeta_arith_vv:
+ | add CARG3, BASE, RB
+ | add CARG4, BASE, RC
+ |1:
+ | add CARG2, BASE, RA
+ | stw BASE, L->base
+ | mr CARG1, L
+ | stw PC, SAVE_PC
+ | decode_OP1 CARG5, INS // Caveat: CARG5 overlaps INS.
+ | bl extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)
+ | // Returns NULL (finished) or TValue * (metamethod).
+ | cmplwi CRET1, 0
+ | beq ->cont_nop
+ |
+ | // Call metamethod for binary op.
+ |->vmeta_binop:
+ | // BASE = old base, CRET1 = new base, stack = cont/func/o1/o2
+ | sub TMP1, CRET1, BASE
+ | stw PC, -16(CRET1) // [cont|PC]
+ | mr TMP2, BASE
+ | addi PC, TMP1, FRAME_CONT
+ | mr BASE, CRET1
+ | li NARGS8:RC, 16 // 2 args for func(o1, o2).
+ | b ->vm_call_dispatch
+ |
+ |->vmeta_len:
+#if LJ_52
+ | mr SAVE0, CARG1
+#endif
+ | add CARG2, BASE, RD
+ | stw BASE, L->base
+ | mr CARG1, L
+ | stw PC, SAVE_PC
+ | bl extern lj_meta_len // (lua_State *L, TValue *o)
+ | // Returns NULL (retry) or TValue * (metamethod base).
+#if LJ_52
+ | cmplwi CRET1, 0
+ | bne ->vmeta_binop // Binop call for compatibility.
+ | mr CARG1, SAVE0
+ | b ->BC_LEN_Z
+#else
+ | b ->vmeta_binop // Binop call for compatibility.
+#endif
+ |
+ |//-- Call metamethod ----------------------------------------------------
+ |
+ |->vmeta_call: // Resolve and call __call metamethod.
+ | // TMP2 = old base, BASE = new base, RC = nargs*8
+ | mr CARG1, L
+ | stw TMP2, L->base // This is the callers base!
+ | subi CARG2, BASE, 8
+ | stw PC, SAVE_PC
+ | add CARG3, BASE, RC
+ | mr SAVE0, NARGS8:RC
+ | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
+ | lwz LFUNC:RB, FRAME_FUNC(BASE) // Guaranteed to be a function here.
+ | addi NARGS8:RC, SAVE0, 8 // Got one more argument now.
+ | ins_call
+ |
+ |->vmeta_callt: // Resolve __call for BC_CALLT.
+ | // BASE = old base, RA = new base, RC = nargs*8
+ | mr CARG1, L
+ | stw BASE, L->base
+ | subi CARG2, RA, 8
+ | stw PC, SAVE_PC
+ | add CARG3, RA, RC
+ | mr SAVE0, NARGS8:RC
+ | bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
+ | lwz TMP1, FRAME_PC(BASE)
+ | addi NARGS8:RC, SAVE0, 8 // Got one more argument now.
+ | lwz LFUNC:RB, FRAME_FUNC(RA) // Guaranteed to be a function here.
+ | b ->BC_CALLT_Z
+ |
+ |//-- Argument coercion for 'for' statement ------------------------------
+ |
+ |->vmeta_for:
+ | mr CARG1, L
+ | stw BASE, L->base
+ | mr CARG2, RA
+ | stw PC, SAVE_PC
+ | mr SAVE0, INS
+ | bl extern lj_meta_for // (lua_State *L, TValue *base)
+ |.if JIT
+ | decode_OP1 TMP0, SAVE0
+ |.endif
+ | decode_RA8 RA, SAVE0
+ |.if JIT
+ | cmpwi TMP0, BC_JFORI
+ |.endif
+ | decode_RD8 RD, SAVE0
+ |.if JIT
+ | beq =>BC_JFORI
+ |.endif
+ | b =>BC_FORI
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Fast functions -----------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |.macro .ffunc, name
+ |->ff_ .. name:
+ |.endmacro
+ |
+ |.macro .ffunc_1, name
+ |->ff_ .. name:
+ | cmplwi NARGS8:RC, 8
+ | evldd CARG1, 0(BASE)
+ | blt ->fff_fallback
+ |.endmacro
+ |
+ |.macro .ffunc_2, name
+ |->ff_ .. name:
+ | cmplwi NARGS8:RC, 16
+ | evldd CARG1, 0(BASE)
+ | evldd CARG2, 8(BASE)
+ | blt ->fff_fallback
+ |.endmacro
+ |
+ |.macro .ffunc_n, name
+ | .ffunc_1 name
+ | checknum CARG1
+ | checkfail ->fff_fallback
+ |.endmacro
+ |
+ |.macro .ffunc_nn, name
+ | .ffunc_2 name
+ | evmergehi TMP0, CARG1, CARG2
+ | checknum TMP0
+ | checkanyfail ->fff_fallback
+ |.endmacro
+ |
+ |// Inlined GC threshold check. Caveat: uses TMP0 and TMP1.
+ |.macro ffgccheck
+ | lwz TMP0, DISPATCH_GL(gc.total)(DISPATCH)
+ | lwz TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)
+ | cmplw TMP0, TMP1
+ | bgel ->fff_gcstep
+ |.endmacro
+ |
+ |//-- Base library: checks -----------------------------------------------
+ |
+ |.ffunc assert
+ | cmplwi NARGS8:RC, 8
+ | evldd TMP0, 0(BASE)
+ | blt ->fff_fallback
+ | evaddw TMP1, TISNIL, TISNIL // Synthesize LJ_TFALSE.
+ | la RA, -8(BASE)
+ | evcmpltu cr1, TMP0, TMP1
+ | lwz PC, FRAME_PC(BASE)
+ | bge cr1, ->fff_fallback
+ | evstdd TMP0, 0(RA)
+ | addi RD, NARGS8:RC, 8 // Compute (nresults+1)*8.
+ | beq ->fff_res // Done if exactly 1 argument.
+ | li TMP1, 8
+ | subi RC, RC, 8
+ |1:
+ | cmplw TMP1, RC
+ | evlddx TMP0, BASE, TMP1
+ | evstddx TMP0, RA, TMP1
+ | addi TMP1, TMP1, 8
+ | bne <1
+ | b ->fff_res
+ |
+ |.ffunc type
+ | cmplwi NARGS8:RC, 8
+ | lwz CARG1, 0(BASE)
+ | blt ->fff_fallback
+ | li TMP2, ~LJ_TNUMX
+ | cmplw CARG1, TISNUM
+ | not TMP1, CARG1
+ | isellt TMP1, TMP2, TMP1
+ | slwi TMP1, TMP1, 3
+ | la TMP2, CFUNC:RB->upvalue
+ | evlddx STR:CRET1, TMP2, TMP1
+ | b ->fff_restv
+ |
+ |//-- Base library: getters and setters ---------------------------------
+ |
+ |.ffunc_1 getmetatable
+ | checktab CARG1
+ | evmergehi TMP1, CARG1, CARG1
+ | checkfail >6
+ |1: // Field metatable must be at same offset for GCtab and GCudata!
+ | lwz TAB:RB, TAB:CARG1->metatable
+ |2:
+ | evmr CRET1, TISNIL
+ | cmplwi TAB:RB, 0
+ | lwz STR:RC, DISPATCH_GL(gcroot[GCROOT_MMNAME+MM_metatable])(DISPATCH)
+ | beq ->fff_restv
+ | lwz TMP0, TAB:RB->hmask
+ | evmergelo CRET1, TISTAB, TAB:RB // Use metatable as default result.
+ | lwz TMP1, STR:RC->hash
+ | lwz NODE:TMP2, TAB:RB->node
+ | evmergelo STR:RC, TISSTR, STR:RC
+ | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask
+ | slwi TMP0, TMP1, 5
+ | slwi TMP1, TMP1, 3
+ | sub TMP1, TMP0, TMP1
+ | add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8)
+ |3: // Rearranged logic, because we expect _not_ to find the key.
+ | evldd TMP0, NODE:TMP2->key
+ | evldd TMP1, NODE:TMP2->val
+ | evcmpeq TMP0, STR:RC
+ | lwz NODE:TMP2, NODE:TMP2->next
+ | checkallok >5
+ | cmplwi NODE:TMP2, 0
+ | beq ->fff_restv // Not found, keep default result.
+ | b <3
+ |5:
+ | checknil TMP1
+ | checkok ->fff_restv // Ditto for nil value.
+ | evmr CRET1, TMP1 // Return value of mt.__metatable.
+ | b ->fff_restv
+ |
+ |6:
+ | cmpwi TMP1, LJ_TUDATA
+ | not TMP1, TMP1
+ | beq <1
+ | checknum CARG1
+ | slwi TMP1, TMP1, 2
+ | li TMP2, 4*~LJ_TNUMX
+ | isellt TMP1, TMP2, TMP1
+ | la TMP2, DISPATCH_GL(gcroot[GCROOT_BASEMT])(DISPATCH)
+ | lwzx TAB:RB, TMP2, TMP1
+ | b <2
+ |
+ |.ffunc_2 setmetatable
+ | // Fast path: no mt for table yet and not clearing the mt.
+ | evmergehi TMP0, TAB:CARG1, TAB:CARG2
+ | checktab TMP0
+ | checkanyfail ->fff_fallback
+ | lwz TAB:TMP1, TAB:CARG1->metatable
+ | cmplwi TAB:TMP1, 0
+ | lbz TMP3, TAB:CARG1->marked
+ | bne ->fff_fallback
+ | andi. TMP0, TMP3, LJ_GC_BLACK // isblack(table)
+ | stw TAB:CARG2, TAB:CARG1->metatable
+ | beq ->fff_restv
+ | barrierback TAB:CARG1, TMP3, TMP0
+ | b ->fff_restv
+ |
+ |.ffunc rawget
+ | cmplwi NARGS8:RC, 16
+ | evldd CARG2, 0(BASE)
+ | blt ->fff_fallback
+ | checktab CARG2
+ | la CARG3, 8(BASE)
+ | checkfail ->fff_fallback
+ | mr CARG1, L
+ | bl extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key)
+ | // Returns cTValue *.
+ | evldd CRET1, 0(CRET1)
+ | b ->fff_restv
+ |
+ |//-- Base library: conversions ------------------------------------------
+ |
+ |.ffunc tonumber
+ | // Only handles the number case inline (without a base argument).
+ | cmplwi NARGS8:RC, 8
+ | evldd CARG1, 0(BASE)
+ | bne ->fff_fallback // Exactly one argument.
+ | checknum CARG1
+ | checkok ->fff_restv
+ | b ->fff_fallback
+ |
+ |.ffunc_1 tostring
+ | // Only handles the string or number case inline.
+ | checkstr CARG1
+ | // A __tostring method in the string base metatable is ignored.
+ | checkok ->fff_restv // String key?
+ | // Handle numbers inline, unless a number base metatable is present.
+ | lwz TMP0, DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])(DISPATCH)
+ | checknum CARG1
+ | cmplwi cr1, TMP0, 0
+ | stw BASE, L->base // Add frame since C call can throw.
+ | crand 4*cr0+eq, 4*cr0+lt, 4*cr1+eq
+ | stw PC, SAVE_PC // Redundant (but a defined value).
+ | bne ->fff_fallback
+ | ffgccheck
+ | mr CARG1, L
+ | mr CARG2, BASE
+ | bl extern lj_str_fromnum // (lua_State *L, lua_Number *np)
+ | // Returns GCstr *.
+ | evmergelo STR:CRET1, TISSTR, STR:CRET1
+ | b ->fff_restv
+ |
+ |//-- Base library: iterators -------------------------------------------
+ |
+ |.ffunc next
+ | cmplwi NARGS8:RC, 8
+ | evldd CARG2, 0(BASE)
+ | blt ->fff_fallback
+ | evstddx TISNIL, BASE, NARGS8:RC // Set missing 2nd arg to nil.
+ | checktab TAB:CARG2
+ | lwz PC, FRAME_PC(BASE)
+ | checkfail ->fff_fallback
+ | stw BASE, L->base // Add frame since C call can throw.
+ | mr CARG1, L
+ | stw BASE, L->top // Dummy frame length is ok.
+ | la CARG3, 8(BASE)
+ | stw PC, SAVE_PC
+ | bl extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key)
+ | // Returns 0 at end of traversal.
+ | cmplwi CRET1, 0
+ | evmr CRET1, TISNIL
+ | beq ->fff_restv // End of traversal: return nil.
+ | evldd TMP0, 8(BASE) // Copy key and value to results.
+ | la RA, -8(BASE)
+ | evldd TMP1, 16(BASE)
+ | evstdd TMP0, 0(RA)
+ | li RD, (2+1)*8
+ | evstdd TMP1, 8(RA)
+ | b ->fff_res
+ |
+ |.ffunc_1 pairs
+ | checktab TAB:CARG1
+ | lwz PC, FRAME_PC(BASE)
+ | checkfail ->fff_fallback
+#if LJ_52
+ | lwz TAB:TMP2, TAB:CARG1->metatable
+ | evldd CFUNC:TMP0, CFUNC:RB->upvalue[0]
+ | cmplwi TAB:TMP2, 0
+ | la RA, -8(BASE)
+ | bne ->fff_fallback
+#else
+ | evldd CFUNC:TMP0, CFUNC:RB->upvalue[0]
+ | la RA, -8(BASE)
+#endif
+ | evstdd TISNIL, 8(BASE)
+ | li RD, (3+1)*8
+ | evstdd CFUNC:TMP0, 0(RA)
+ | b ->fff_res
+ |
+ |.ffunc_2 ipairs_aux
+ | checktab TAB:CARG1
+ | lwz PC, FRAME_PC(BASE)
+ | checkfail ->fff_fallback
+ | checknum CARG2
+ | lus TMP3, 0x3ff0
+ | checkfail ->fff_fallback
+ | efdctsi TMP2, CARG2
+ | lwz TMP0, TAB:CARG1->asize
+ | evmergelo TMP3, TMP3, ZERO
+ | lwz TMP1, TAB:CARG1->array
+ | efdadd CARG2, CARG2, TMP3
+ | addi TMP2, TMP2, 1
+ | la RA, -8(BASE)
+ | cmplw TMP0, TMP2
+ | slwi TMP3, TMP2, 3
+ | evstdd CARG2, 0(RA)
+ | ble >2 // Not in array part?
+ | evlddx TMP1, TMP1, TMP3
+ |1:
+ | checknil TMP1
+ | li RD, (0+1)*8
+ | checkok ->fff_res // End of iteration, return 0 results.
+ | li RD, (2+1)*8
+ | evstdd TMP1, 8(RA)
+ | b ->fff_res
+ |2: // Check for empty hash part first. Otherwise call C function.
+ | lwz TMP0, TAB:CARG1->hmask
+ | cmplwi TMP0, 0
+ | li RD, (0+1)*8
+ | beq ->fff_res
+ | mr CARG2, TMP2
+ | bl extern lj_tab_getinth // (GCtab *t, int32_t key)
+ | // Returns cTValue * or NULL.
+ | cmplwi CRET1, 0
+ | li RD, (0+1)*8
+ | beq ->fff_res
+ | evldd TMP1, 0(CRET1)
+ | b <1
+ |
+ |.ffunc_1 ipairs
+ | checktab TAB:CARG1
+ | lwz PC, FRAME_PC(BASE)
+ | checkfail ->fff_fallback
+#if LJ_52
+ | lwz TAB:TMP2, TAB:CARG1->metatable
+ | evldd CFUNC:TMP0, CFUNC:RB->upvalue[0]
+ | cmplwi TAB:TMP2, 0
+ | la RA, -8(BASE)
+ | bne ->fff_fallback
+#else
+ | evldd CFUNC:TMP0, CFUNC:RB->upvalue[0]
+ | la RA, -8(BASE)
+#endif
+ | evsplati TMP1, 0
+ | li RD, (3+1)*8
+ | evstdd TMP1, 8(BASE)
+ | evstdd CFUNC:TMP0, 0(RA)
+ | b ->fff_res
+ |
+ |//-- Base library: catch errors ----------------------------------------
+ |
+ |.ffunc pcall
+ | cmplwi NARGS8:RC, 8
+ | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)
+ | blt ->fff_fallback
+ | mr TMP2, BASE
+ | la BASE, 8(BASE)
+ | // Remember active hook before pcall.
+ | rlwinm TMP3, TMP3, 32-HOOK_ACTIVE_SHIFT, 31, 31
+ | subi NARGS8:RC, NARGS8:RC, 8
+ | addi PC, TMP3, 8+FRAME_PCALL
+ | b ->vm_call_dispatch
+ |
+ |.ffunc_2 xpcall
+ | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)
+ | mr TMP2, BASE
+ | checkfunc CARG2 // Traceback must be a function.
+ | checkfail ->fff_fallback
+ | la BASE, 16(BASE)
+ | // Remember active hook before pcall.
+ | rlwinm TMP3, TMP3, 32-HOOK_ACTIVE_SHIFT, 31, 31
+ | evstdd CARG2, 0(TMP2) // Swap function and traceback.
+ | subi NARGS8:RC, NARGS8:RC, 16
+ | evstdd CARG1, 8(TMP2)
+ | addi PC, TMP3, 16+FRAME_PCALL
+ | b ->vm_call_dispatch
+ |
+ |//-- Coroutine library --------------------------------------------------
+ |
+ |.macro coroutine_resume_wrap, resume
+ |.if resume
+ |.ffunc_1 coroutine_resume
+ | evmergehi TMP0, L:CARG1, L:CARG1
+ |.else
+ |.ffunc coroutine_wrap_aux
+ | lwz L:CARG1, CFUNC:RB->upvalue[0].gcr
+ |.endif
+ |.if resume
+ | cmpwi TMP0, LJ_TTHREAD
+ | bne ->fff_fallback
+ |.endif
+ | lbz TMP0, L:CARG1->status
+ | lwz TMP1, L:CARG1->cframe
+ | lwz CARG2, L:CARG1->top
+ | cmplwi cr0, TMP0, LUA_YIELD
+ | lwz TMP2, L:CARG1->base
+ | cmplwi cr1, TMP1, 0
+ | lwz TMP0, L:CARG1->maxstack
+ | cmplw cr7, CARG2, TMP2
+ | lwz PC, FRAME_PC(BASE)
+ | crorc 4*cr6+lt, 4*cr0+gt, 4*cr1+eq // st>LUA_YIELD || cframe!=0
+ | add TMP2, CARG2, NARGS8:RC
+ | crandc 4*cr6+gt, 4*cr7+eq, 4*cr0+eq // base==top && st!=LUA_YIELD
+ | cmplw cr1, TMP2, TMP0
+ | cror 4*cr6+lt, 4*cr6+lt, 4*cr6+gt
+ | stw PC, SAVE_PC
+ | cror 4*cr6+lt, 4*cr6+lt, 4*cr1+gt // cond1 || cond2 || stackov
+ | stw BASE, L->base
+ | blt cr6, ->fff_fallback
+ |1:
+ |.if resume
+ | addi BASE, BASE, 8 // Keep resumed thread in stack for GC.
+ | subi NARGS8:RC, NARGS8:RC, 8
+ | subi TMP2, TMP2, 8
+ |.endif
+ | stw TMP2, L:CARG1->top
+ | li TMP1, 0
+ | stw BASE, L->top
+ |2: // Move args to coroutine.
+ | cmpw TMP1, NARGS8:RC
+ | evlddx TMP0, BASE, TMP1
+ | beq >3
+ | evstddx TMP0, CARG2, TMP1
+ | addi TMP1, TMP1, 8
+ | b <2
+ |3:
+ | li CARG3, 0
+ | mr L:SAVE0, L:CARG1
+ | li CARG4, 0
+ | bl ->vm_resume // (lua_State *L, TValue *base, 0, 0)
+ | // Returns thread status.
+ |4:
+ | lwz TMP2, L:SAVE0->base
+ | cmplwi CRET1, LUA_YIELD
+ | lwz TMP3, L:SAVE0->top
+ | li_vmstate INTERP
+ | lwz BASE, L->base
+ | st_vmstate
+ | bgt >8
+ | sub RD, TMP3, TMP2
+ | lwz TMP0, L->maxstack
+ | cmplwi RD, 0
+ | add TMP1, BASE, RD
+ | beq >6 // No results?
+ | cmplw TMP1, TMP0
+ | li TMP1, 0
+ | bgt >9 // Need to grow stack?
+ |
+ | subi TMP3, RD, 8
+ | stw TMP2, L:SAVE0->top // Clear coroutine stack.
+ |5: // Move results from coroutine.
+ | cmplw TMP1, TMP3
+ | evlddx TMP0, TMP2, TMP1
+ | evstddx TMP0, BASE, TMP1
+ | addi TMP1, TMP1, 8
+ | bne <5
+ |6:
+ | andi. TMP0, PC, FRAME_TYPE
+ |.if resume
+ | li TMP1, LJ_TTRUE
+ | la RA, -8(BASE)
+ | stw TMP1, -8(BASE) // Prepend true to results.
+ | addi RD, RD, 16
+ |.else
+ | mr RA, BASE
+ | addi RD, RD, 8
+ |.endif
+ |7:
+ | stw PC, SAVE_PC
+ | mr MULTRES, RD
+ | beq ->BC_RET_Z
+ | b ->vm_return
+ |
+ |8: // Coroutine returned with error (at co->top-1).
+ |.if resume
+ | andi. TMP0, PC, FRAME_TYPE
+ | la TMP3, -8(TMP3)
+ | li TMP1, LJ_TFALSE
+ | evldd TMP0, 0(TMP3)
+ | stw TMP3, L:SAVE0->top // Remove error from coroutine stack.
+ | li RD, (2+1)*8
+ | stw TMP1, -8(BASE) // Prepend false to results.
+ | la RA, -8(BASE)
+ | evstdd TMP0, 0(BASE) // Copy error message.
+ | b <7
+ |.else
+ | mr CARG1, L
+ | mr CARG2, L:SAVE0
+ | bl extern lj_ffh_coroutine_wrap_err // (lua_State *L, lua_State *co)
+ |.endif
+ |
+ |9: // Handle stack expansion on return from yield.
+ | mr CARG1, L
+ | srwi CARG2, RD, 3
+ | bl extern lj_state_growstack // (lua_State *L, int n)
+ | li CRET1, 0
+ | b <4
+ |.endmacro
+ |
+ | coroutine_resume_wrap 1 // coroutine.resume
+ | coroutine_resume_wrap 0 // coroutine.wrap
+ |
+ |.ffunc coroutine_yield
+ | lwz TMP0, L->cframe
+ | add TMP1, BASE, NARGS8:RC
+ | stw BASE, L->base
+ | andi. TMP0, TMP0, CFRAME_RESUME
+ | stw TMP1, L->top
+ | li CRET1, LUA_YIELD
+ | beq ->fff_fallback
+ | stw ZERO, L->cframe
+ | stb CRET1, L->status
+ | b ->vm_leave_unw
+ |
+ |//-- Math library -------------------------------------------------------
+ |
+ |.ffunc_n math_abs
+ | efdabs CRET1, CARG1
+ | // Fallthrough.
+ |
+ |->fff_restv:
+ | // CRET1 = TValue result.
+ | lwz PC, FRAME_PC(BASE)
+ | la RA, -8(BASE)
+ | evstdd CRET1, 0(RA)
+ |->fff_res1:
+ | // RA = results, PC = return.
+ | li RD, (1+1)*8
+ |->fff_res:
+ | // RA = results, RD = (nresults+1)*8, PC = return.
+ | andi. TMP0, PC, FRAME_TYPE
+ | mr MULTRES, RD
+ | bne ->vm_return
+ | lwz INS, -4(PC)
+ | decode_RB8 RB, INS
+ |5:
+ | cmplw RB, RD // More results expected?
+ | decode_RA8 TMP0, INS
+ | bgt >6
+ | ins_next1
+ | // Adjust BASE. KBASE is assumed to be set for the calling frame.
+ | sub BASE, RA, TMP0
+ | ins_next2
+ |
+ |6: // Fill up results with nil.
+ | subi TMP1, RD, 8
+ | addi RD, RD, 8
+ | evstddx TISNIL, RA, TMP1
+ | b <5
+ |
+ |.macro math_extern, func
+ | .ffunc math_ .. func
+ | cmplwi NARGS8:RC, 8
+ | evldd CARG2, 0(BASE)
+ | blt ->fff_fallback
+ | checknum CARG2
+ | evmergehi CARG1, CARG2, CARG2
+ | checkfail ->fff_fallback
+ | bl extern func@plt
+ | evmergelo CRET1, CRET1, CRET2
+ | b ->fff_restv
+ |.endmacro
+ |
+ |.macro math_extern2, func
+ | .ffunc math_ .. func
+ | cmplwi NARGS8:RC, 16
+ | evldd CARG2, 0(BASE)
+ | evldd CARG4, 8(BASE)
+ | blt ->fff_fallback
+ | evmergehi CARG1, CARG4, CARG2
+ | checknum CARG1
+ | evmergehi CARG3, CARG4, CARG4
+ | checkanyfail ->fff_fallback
+ | bl extern func@plt
+ | evmergelo CRET1, CRET1, CRET2
+ | b ->fff_restv
+ |.endmacro
+ |
+ |.macro math_round, func
+ | .ffunc math_ .. func
+ | cmplwi NARGS8:RC, 8
+ | evldd CARG2, 0(BASE)
+ | blt ->fff_fallback
+ | checknum CARG2
+ | evmergehi CARG1, CARG2, CARG2
+ | checkfail ->fff_fallback
+ | lwz PC, FRAME_PC(BASE)
+ | bl ->vm_..func.._hilo;
+ | la RA, -8(BASE)
+ | evstdd CRET2, 0(RA)
+ | b ->fff_res1
+ |.endmacro
+ |
+ | math_round floor
+ | math_round ceil
+ |
+ | math_extern sqrt
+ |
+ |.ffunc math_log
+ | cmplwi NARGS8:RC, 8
+ | evldd CARG2, 0(BASE)
+ | bne ->fff_fallback // Need exactly 1 argument.
+ | checknum CARG2
+ | evmergehi CARG1, CARG2, CARG2
+ | checkfail ->fff_fallback
+ | bl extern log@plt
+ | evmergelo CRET1, CRET1, CRET2
+ | b ->fff_restv
+ |
+ | math_extern log10
+ | math_extern exp
+ | math_extern sin
+ | math_extern cos
+ | math_extern tan
+ | math_extern asin
+ | math_extern acos
+ | math_extern atan
+ | math_extern sinh
+ | math_extern cosh
+ | math_extern tanh
+ | math_extern2 pow
+ | math_extern2 atan2
+ | math_extern2 fmod
+ |
+ |->ff_math_deg:
+ |.ffunc_n math_rad
+ | evldd CARG2, CFUNC:RB->upvalue[0]
+ | efdmul CRET1, CARG1, CARG2
+ | b ->fff_restv
+ |
+ |.ffunc math_ldexp
+ | cmplwi NARGS8:RC, 16
+ | evldd CARG2, 0(BASE)
+ | evldd CARG4, 8(BASE)
+ | blt ->fff_fallback
+ | evmergehi CARG1, CARG4, CARG2
+ | checknum CARG1
+ | checkanyfail ->fff_fallback
+ | efdctsi CARG3, CARG4
+ | bl extern ldexp@plt
+ | evmergelo CRET1, CRET1, CRET2
+ | b ->fff_restv
+ |
+ |.ffunc math_frexp
+ | cmplwi NARGS8:RC, 8
+ | evldd CARG2, 0(BASE)
+ | blt ->fff_fallback
+ | checknum CARG2
+ | evmergehi CARG1, CARG2, CARG2
+ | checkfail ->fff_fallback
+ | la CARG3, DISPATCH_GL(tmptv)(DISPATCH)
+ | lwz PC, FRAME_PC(BASE)
+ | bl extern frexp@plt
+ | lwz TMP1, DISPATCH_GL(tmptv)(DISPATCH)
+ | evmergelo CRET1, CRET1, CRET2
+ | efdcfsi CRET2, TMP1
+ | la RA, -8(BASE)
+ | evstdd CRET1, 0(RA)
+ | li RD, (2+1)*8
+ | evstdd CRET2, 8(RA)
+ | b ->fff_res
+ |
+ |.ffunc math_modf
+ | cmplwi NARGS8:RC, 8
+ | evldd CARG2, 0(BASE)
+ | blt ->fff_fallback
+ | checknum CARG2
+ | evmergehi CARG1, CARG2, CARG2
+ | checkfail ->fff_fallback
+ | la CARG3, -8(BASE)
+ | lwz PC, FRAME_PC(BASE)
+ | bl extern modf@plt
+ | evmergelo CRET1, CRET1, CRET2
+ | la RA, -8(BASE)
+ | evstdd CRET1, 0(BASE)
+ | li RD, (2+1)*8
+ | b ->fff_res
+ |
+ |.macro math_minmax, name, cmpop
+ | .ffunc_1 name
+ | checknum CARG1
+ | li TMP1, 8
+ | checkfail ->fff_fallback
+ |1:
+ | evlddx CARG2, BASE, TMP1
+ | cmplw cr1, TMP1, NARGS8:RC
+ | checknum CARG2
+ | bge cr1, ->fff_restv // Ok, since CRET1 = CARG1.
+ | checkfail ->fff_fallback
+ | cmpop CARG2, CARG1
+ | addi TMP1, TMP1, 8
+ | crmove 4*cr0+lt, 4*cr0+gt
+ | evsel CARG1, CARG2, CARG1
+ | b <1
+ |.endmacro
+ |
+ | math_minmax math_min, efdtstlt
+ | math_minmax math_max, efdtstgt
+ |
+ |//-- String library -----------------------------------------------------
+ |
+ |.ffunc_1 string_len
+ | checkstr STR:CARG1
+ | checkfail ->fff_fallback
+ | lwz TMP0, STR:CARG1->len
+ | efdcfsi CRET1, TMP0
+ | b ->fff_restv
+ |
+ |.ffunc string_byte // Only handle the 1-arg case here.
+ | cmplwi NARGS8:RC, 8
+ | evldd STR:CARG1, 0(BASE)
+ | bne ->fff_fallback // Need exactly 1 argument.
+ | checkstr STR:CARG1
+ | la RA, -8(BASE)
+ | checkfail ->fff_fallback
+ | lwz TMP0, STR:CARG1->len
+ | li RD, (0+1)*8
+ | lbz TMP1, STR:CARG1[1] // Access is always ok (NUL at end).
+ | li TMP2, (1+1)*8
+ | cmplwi TMP0, 0
+ | lwz PC, FRAME_PC(BASE)
+ | efdcfsi CRET1, TMP1
+ | iseleq RD, RD, TMP2
+ | evstdd CRET1, 0(RA)
+ | b ->fff_res
+ |
+ |.ffunc string_char // Only handle the 1-arg case here.
+ | ffgccheck
+ | cmplwi NARGS8:RC, 8
+ | evldd CARG1, 0(BASE)
+ | bne ->fff_fallback // Exactly 1 argument.
+ | checknum CARG1
+ | la CARG2, DISPATCH_GL(tmptv)(DISPATCH)
+ | checkfail ->fff_fallback
+ | efdctsiz TMP0, CARG1
+ | li CARG3, 1
+ | cmplwi TMP0, 255
+ | stb TMP0, 0(CARG2)
+ | bgt ->fff_fallback
+ |->fff_newstr:
+ | mr CARG1, L
+ | stw BASE, L->base
+ | stw PC, SAVE_PC
+ | bl extern lj_str_new // (lua_State *L, char *str, size_t l)
+ | // Returns GCstr *.
+ | lwz BASE, L->base
+ | evmergelo STR:CRET1, TISSTR, STR:CRET1
+ | b ->fff_restv
+ |
+ |.ffunc string_sub
+ | ffgccheck
+ | cmplwi NARGS8:RC, 16
+ | evldd CARG3, 16(BASE)
+ | evldd STR:CARG1, 0(BASE)
+ | blt ->fff_fallback
+ | evldd CARG2, 8(BASE)
+ | li TMP2, -1
+ | beq >1
+ | checknum CARG3
+ | checkfail ->fff_fallback
+ | efdctsiz TMP2, CARG3
+ |1:
+ | checknum CARG2
+ | checkfail ->fff_fallback
+ | checkstr STR:CARG1
+ | efdctsiz TMP1, CARG2
+ | checkfail ->fff_fallback
+ | lwz TMP0, STR:CARG1->len
+ | cmplw TMP0, TMP2 // len < end? (unsigned compare)
+ | add TMP3, TMP2, TMP0
+ | blt >5
+ |2:
+ | cmpwi TMP1, 0 // start <= 0?
+ | add TMP3, TMP1, TMP0
+ | ble >7
+ |3:
+ | sub. CARG3, TMP2, TMP1
+ | addi CARG2, STR:CARG1, #STR-1
+ | addi CARG3, CARG3, 1
+ | add CARG2, CARG2, TMP1
+ | isellt CARG3, r0, CARG3
+ | b ->fff_newstr
+ |
+ |5: // Negative end or overflow.
+ | cmpw TMP0, TMP2
+ | addi TMP3, TMP3, 1
+ | iselgt TMP2, TMP3, TMP0 // end = end > len ? len : end+len+1
+ | b <2
+ |
+ |7: // Negative start or underflow.
+ | cmpwi cr1, TMP3, 0
+ | iseleq TMP1, r0, TMP3
+ | isel TMP1, r0, TMP1, 4*cr1+lt
+ | addi TMP1, TMP1, 1 // start = 1 + (start ? start+len : 0)
+ | b <3
+ |
+ |.ffunc string_rep // Only handle the 1-char case inline.
+ | ffgccheck
+ | cmplwi NARGS8:RC, 16
+ | evldd CARG1, 0(BASE)
+ | evldd CARG2, 8(BASE)
+ | bne ->fff_fallback // Exactly 2 arguments.
+ | checknum CARG2
+ | checkfail ->fff_fallback
+ | checkstr STR:CARG1
+ | efdctsiz CARG3, CARG2
+ | checkfail ->fff_fallback
+ | lwz TMP0, STR:CARG1->len
+ | cmpwi CARG3, 0
+ | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH)
+ | ble >2 // Count <= 0? (or non-int)
+ | cmplwi TMP0, 1
+ | subi TMP2, CARG3, 1
+ | blt >2 // Zero length string?
+ | cmplw cr1, TMP1, CARG3
+ | bne ->fff_fallback // Fallback for > 1-char strings.
+ | lbz TMP0, STR:CARG1[1]
+ | lwz CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH)
+ | blt cr1, ->fff_fallback
+ |1: // Fill buffer with char. Yes, this is suboptimal code (do you care?).
+ | cmplwi TMP2, 0
+ | stbx TMP0, CARG2, TMP2
+ | subi TMP2, TMP2, 1
+ | bne <1
+ | b ->fff_newstr
+ |2: // Return empty string.
+ | la STR:CRET1, DISPATCH_GL(strempty)(DISPATCH)
+ | evmergelo CRET1, TISSTR, STR:CRET1
+ | b ->fff_restv
+ |
+ |.ffunc string_reverse
+ | ffgccheck
+ | cmplwi NARGS8:RC, 8
+ | evldd CARG1, 0(BASE)
+ | blt ->fff_fallback
+ | checkstr STR:CARG1
+ | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH)
+ | checkfail ->fff_fallback
+ | lwz CARG3, STR:CARG1->len
+ | la CARG1, #STR(STR:CARG1)
+ | lwz CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH)
+ | li TMP2, 0
+ | cmplw TMP1, CARG3
+ | subi TMP3, CARG3, 1
+ | blt ->fff_fallback
+ |1: // Reverse string copy.
+ | cmpwi TMP3, 0
+ | lbzx TMP1, CARG1, TMP2
+ | blt ->fff_newstr
+ | stbx TMP1, CARG2, TMP3
+ | subi TMP3, TMP3, 1
+ | addi TMP2, TMP2, 1
+ | b <1
+ |
+ |.macro ffstring_case, name, lo
+ | .ffunc name
+ | ffgccheck
+ | cmplwi NARGS8:RC, 8
+ | evldd CARG1, 0(BASE)
+ | blt ->fff_fallback
+ | checkstr STR:CARG1
+ | lwz TMP1, DISPATCH_GL(tmpbuf.sz)(DISPATCH)
+ | checkfail ->fff_fallback
+ | lwz CARG3, STR:CARG1->len
+ | la CARG1, #STR(STR:CARG1)
+ | lwz CARG2, DISPATCH_GL(tmpbuf.buf)(DISPATCH)
+ | cmplw TMP1, CARG3
+ | li TMP2, 0
+ | blt ->fff_fallback
+ |1: // ASCII case conversion.
+ | cmplw TMP2, CARG3
+ | lbzx TMP1, CARG1, TMP2
+ | bge ->fff_newstr
+ | subi TMP0, TMP1, lo
+ | xori TMP3, TMP1, 0x20
+ | cmplwi TMP0, 26
+ | isellt TMP1, TMP3, TMP1
+ | stbx TMP1, CARG2, TMP2
+ | addi TMP2, TMP2, 1
+ | b <1
+ |.endmacro
+ |
+ |ffstring_case string_lower, 65
+ |ffstring_case string_upper, 97
+ |
+ |//-- Table library ------------------------------------------------------
+ |
+ |.ffunc_1 table_getn
+ | checktab CARG1
+ | checkfail ->fff_fallback
+ | bl extern lj_tab_len // (GCtab *t)
+ | // Returns uint32_t (but less than 2^31).
+ | efdcfsi CRET1, CRET1
+ | b ->fff_restv
+ |
+ |//-- Bit library --------------------------------------------------------
+ |
+ |.macro .ffunc_bit, name
+ | .ffunc_n bit_..name
+ | efdadd CARG1, CARG1, TOBIT
+ |.endmacro
+ |
+ |.ffunc_bit tobit
+ |->fff_resbit:
+ | efdcfsi CRET1, CARG1
+ | b ->fff_restv
+ |
+ |.macro .ffunc_bit_op, name, ins
+ | .ffunc_bit name
+ | li TMP1, 8
+ |1:
+ | evlddx CARG2, BASE, TMP1
+ | cmplw cr1, TMP1, NARGS8:RC
+ | checknum CARG2
+ | bge cr1, ->fff_resbit
+ | checkfail ->fff_fallback
+ | efdadd CARG2, CARG2, TOBIT
+ | ins CARG1, CARG1, CARG2
+ | addi TMP1, TMP1, 8
+ | b <1
+ |.endmacro
+ |
+ |.ffunc_bit_op band, and
+ |.ffunc_bit_op bor, or
+ |.ffunc_bit_op bxor, xor
+ |
+ |.ffunc_bit bswap
+ | rotlwi TMP0, CARG1, 8
+ | rlwimi TMP0, CARG1, 24, 0, 7
+ | rlwimi TMP0, CARG1, 24, 16, 23
+ | efdcfsi CRET1, TMP0
+ | b ->fff_restv
+ |
+ |.ffunc_bit bnot
+ | not TMP0, CARG1
+ | efdcfsi CRET1, TMP0
+ | b ->fff_restv
+ |
+ |.macro .ffunc_bit_sh, name, ins, shmod
+ | .ffunc_nn bit_..name
+ | efdadd CARG2, CARG2, TOBIT
+ | efdadd CARG1, CARG1, TOBIT
+ |.if shmod == 1
+ | rlwinm CARG2, CARG2, 0, 27, 31
+ |.elif shmod == 2
+ | neg CARG2, CARG2
+ |.endif
+ | ins TMP0, CARG1, CARG2
+ | efdcfsi CRET1, TMP0
+ | b ->fff_restv
+ |.endmacro
+ |
+ |.ffunc_bit_sh lshift, slw, 1
+ |.ffunc_bit_sh rshift, srw, 1
+ |.ffunc_bit_sh arshift, sraw, 1
+ |.ffunc_bit_sh rol, rotlw, 0
+ |.ffunc_bit_sh ror, rotlw, 2
+ |
+ |//-----------------------------------------------------------------------
+ |
+ |->fff_fallback: // Call fast function fallback handler.
+ | // BASE = new base, RB = CFUNC, RC = nargs*8
+ | lwz TMP3, CFUNC:RB->f
+ | add TMP1, BASE, NARGS8:RC
+ | lwz PC, FRAME_PC(BASE) // Fallback may overwrite PC.
+ | addi TMP0, TMP1, 8*LUA_MINSTACK
+ | lwz TMP2, L->maxstack
+ | stw PC, SAVE_PC // Redundant (but a defined value).
+ | cmplw TMP0, TMP2
+ | stw BASE, L->base
+ | stw TMP1, L->top
+ | mr CARG1, L
+ | bgt >5 // Need to grow stack.
+ | mtctr TMP3
+ | bctrl // (lua_State *L)
+ | // Either throws an error, or recovers and returns -1, 0 or nresults+1.
+ | lwz BASE, L->base
+ | cmpwi CRET1, 0
+ | slwi RD, CRET1, 3
+ | la RA, -8(BASE)
+ | bgt ->fff_res // Returned nresults+1?
+ |1: // Returned 0 or -1: retry fast path.
+ | lwz TMP0, L->top
+ | lwz LFUNC:RB, FRAME_FUNC(BASE)
+ | sub NARGS8:RC, TMP0, BASE
+ | bne ->vm_call_tail // Returned -1?
+ | ins_callt // Returned 0: retry fast path.
+ |
+ |// Reconstruct previous base for vmeta_call during tailcall.
+ |->vm_call_tail:
+ | andi. TMP0, PC, FRAME_TYPE
+ | rlwinm TMP1, PC, 0, 0, 28
+ | bne >3
+ | lwz INS, -4(PC)
+ | decode_RA8 TMP1, INS
+ | addi TMP1, TMP1, 8
+ |3:
+ | sub TMP2, BASE, TMP1
+ | b ->vm_call_dispatch // Resolve again for tailcall.
+ |
+ |5: // Grow stack for fallback handler.
+ | li CARG2, LUA_MINSTACK
+ | bl extern lj_state_growstack // (lua_State *L, int n)
+ | lwz BASE, L->base
+ | cmpw TMP0, TMP0 // Set 4*cr0+eq to force retry.
+ | b <1
+ |
+ |->fff_gcstep: // Call GC step function.
+ | // BASE = new base, RC = nargs*8
+ | mflr SAVE0
+ | stw BASE, L->base
+ | add TMP0, BASE, NARGS8:RC
+ | stw PC, SAVE_PC // Redundant (but a defined value).
+ | stw TMP0, L->top
+ | mr CARG1, L
+ | bl extern lj_gc_step // (lua_State *L)
+ | lwz BASE, L->base
+ | mtlr SAVE0
+ | lwz TMP0, L->top
+ | sub NARGS8:RC, TMP0, BASE
+ | lwz CFUNC:RB, FRAME_FUNC(BASE)
+ | blr
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Special dispatch targets -------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_record: // Dispatch target for recording phase.
+ |.if JIT
+ | NYI
+ |.endif
+ |
+ |->vm_rethook: // Dispatch target for return hooks.
+ | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)
+ | andi. TMP0, TMP3, HOOK_ACTIVE // Hook already active?
+ | beq >1
+ |5: // Re-dispatch to static ins.
+ | addi TMP1, TMP1, GG_DISP2STATIC // Assumes decode_OP4 TMP1, INS.
+ | lwzx TMP0, DISPATCH, TMP1
+ | mtctr TMP0
+ | bctr
+ |
+ |->vm_inshook: // Dispatch target for instr/line hooks.
+ | lbz TMP3, DISPATCH_GL(hookmask)(DISPATCH)
+ | lwz TMP2, DISPATCH_GL(hookcount)(DISPATCH)
+ | andi. TMP0, TMP3, HOOK_ACTIVE // Hook already active?
+ | rlwinm TMP0, TMP3, 31-LUA_HOOKLINE, 31, 0
+ | bne <5
+ |
+ | cmpwi cr1, TMP0, 0
+ | addic. TMP2, TMP2, -1
+ | beq cr1, <5
+ | stw TMP2, DISPATCH_GL(hookcount)(DISPATCH)
+ | beq >1
+ | bge cr1, <5
+ |1:
+ | mr CARG1, L
+ | stw MULTRES, SAVE_MULTRES
+ | mr CARG2, PC
+ | stw BASE, L->base
+ | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.
+ | bl extern lj_dispatch_ins // (lua_State *L, const BCIns *pc)
+ |3:
+ | lwz BASE, L->base
+ |4: // Re-dispatch to static ins.
+ | lwz INS, -4(PC)
+ | decode_OP4 TMP1, INS
+ | decode_RB8 RB, INS
+ | addi TMP1, TMP1, GG_DISP2STATIC
+ | decode_RD8 RD, INS
+ | lwzx TMP0, DISPATCH, TMP1
+ | decode_RA8 RA, INS
+ | decode_RC8 RC, INS
+ | mtctr TMP0
+ | bctr
+ |
+ |->cont_hook: // Continue from hook yield.
+ | addi PC, PC, 4
+ | lwz MULTRES, -20(RB) // Restore MULTRES for *M ins.
+ | b <4
+ |
+ |->vm_hotloop: // Hot loop counter underflow.
+ |.if JIT
+ | NYI
+ |.endif
+ |
+ |->vm_callhook: // Dispatch target for call hooks.
+ | mr CARG2, PC
+ |.if JIT
+ | b >1
+ |.endif
+ |
+ |->vm_hotcall: // Hot call counter underflow.
+ |.if JIT
+ | ori CARG2, PC, 1
+ |1:
+ |.endif
+ | add TMP0, BASE, RC
+ | stw PC, SAVE_PC
+ | mr CARG1, L
+ | stw BASE, L->base
+ | sub RA, RA, BASE
+ | stw TMP0, L->top
+ | bl extern lj_dispatch_call // (lua_State *L, const BCIns *pc)
+ | // Returns ASMFunction.
+ | lwz BASE, L->base
+ | lwz TMP0, L->top
+ | stw ZERO, SAVE_PC // Invalidate for subsequent line hook.
+ | sub NARGS8:RC, TMP0, BASE
+ | add RA, BASE, RA
+ | lwz LFUNC:RB, FRAME_FUNC(BASE)
+ | mtctr CRET1
+ | bctr
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Trace exit handler -------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_exit_handler:
+ |.if JIT
+ | NYI
+ |.endif
+ |->vm_exit_interp:
+ |.if JIT
+ | NYI
+ |.endif
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Math helper functions ----------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |// FP value rounding. Called by math.floor/math.ceil fast functions
+ |// and from JIT code.
+ |//
+ |// This can be inlined if the CPU has the frin/friz/frip/frim instructions.
+ |// The alternative hard-float approaches have a deep dependency chain.
+ |// The resulting latency is at least 3x-7x the double-precision FP latency
+ |// (e500v2: 6cy, e600: 5cy, Cell: 10cy) or around 20-70 cycles.
+ |//
+ |// The soft-float approach is tedious, but much faster (e500v2: ~11cy/~6cy).
+ |// However it relies on a fast way to transfer the FP value to GPRs
+ |// (e500v2: 0cy for lo-word, 1cy for hi-word).
+ |//
+ |.macro vm_round, name, mode
+ | // Used temporaries: TMP0, TMP1, TMP2, TMP3.
+ |->name.._efd: // Input: CARG2, output: CRET2
+ | evmergehi CARG1, CARG2, CARG2
+ |->name.._hilo:
+ | // Input: CARG1 (hi), CARG2 (hi, lo), output: CRET2
+ | rlwinm TMP2, CARG1, 12, 21, 31
+ | addic. TMP2, TMP2, -1023 // exp = exponent(x) - 1023
+ | li TMP1, -1
+ | cmplwi cr1, TMP2, 51 // 0 <= exp <= 51?
+ | subfic TMP0, TMP2, 52
+ | bgt cr1, >1
+ | lus TMP3, 0xfff0
+ | slw TMP0, TMP1, TMP0 // lomask = -1 << (52-exp)
+ | sraw TMP1, TMP3, TMP2 // himask = (int32_t)0xfff00000 >> exp
+ |.if mode == 2 // trunc(x):
+ | evmergelo TMP0, TMP1, TMP0
+ | evand CRET2, CARG2, TMP0 // hi &= himask, lo &= lomask
+ |.else
+ | andc TMP2, CARG2, TMP0
+ | andc TMP3, CARG1, TMP1
+ | or TMP2, TMP2, TMP3 // ztest = (hi&~himask) | (lo&~lomask)
+ | srawi TMP3, CARG1, 31 // signmask = (int32_t)hi >> 31
+ |.if mode == 0 // floor(x):
+ | and. TMP2, TMP2, TMP3 // iszero = ((ztest & signmask) == 0)
+ |.else // ceil(x):
+ | andc. TMP2, TMP2, TMP3 // iszero = ((ztest & ~signmask) == 0)
+ |.endif
+ | and CARG2, CARG2, TMP0 // lo &= lomask
+ | and CARG1, CARG1, TMP1 // hi &= himask
+ | subc TMP0, CARG2, TMP0
+ | iseleq TMP0, CARG2, TMP0 // lo = iszero ? lo : lo-lomask
+ | sube TMP1, CARG1, TMP1
+ | iseleq TMP1, CARG1, TMP1 // hi = iszero ? hi : hi-himask+carry
+ | evmergelo CRET2, TMP1, TMP0
+ |.endif
+ | blr
+ |1:
+ | bgtlr // Already done if >=2^52, +-inf or nan.
+ |.if mode == 2 // trunc(x):
+ | rlwinm TMP1, CARG1, 0, 0, 0 // hi = sign(x)
+ | li TMP0, 0
+ | evmergelo CRET2, TMP1, TMP0
+ |.else
+ | rlwinm TMP2, CARG1, 0, 1, 31
+ | srawi TMP0, CARG1, 31 // signmask = (int32_t)hi >> 31
+ | or TMP2, TMP2, CARG2 // ztest = abs(hi) | lo
+ | lus TMP1, 0x3ff0
+ |.if mode == 0 // floor(x):
+ | and. TMP2, TMP2, TMP0 // iszero = ((ztest & signmask) == 0)
+ |.else // ceil(x):
+ | andc. TMP2, TMP2, TMP0 // iszero = ((ztest & ~signmask) == 0)
+ |.endif
+ | li TMP0, 0
+ | iseleq TMP1, r0, TMP1
+ | rlwimi CARG1, TMP1, 0, 1, 31 // hi = sign(x) | (iszero ? 0.0 : 1.0)
+ | evmergelo CRET2, CARG1, TMP0
+ |.endif
+ | blr
+ |.endmacro
+ |
+ |->vm_floor:
+ | mflr CARG3
+ | evmergelo CARG2, CARG1, CARG2
+ | bl ->vm_floor_hilo
+ | mtlr CARG3
+ | evmergehi CRET1, CRET2, CRET2
+ | blr
+ |
+ | vm_round vm_floor, 0
+ | vm_round vm_ceil, 1
+ |.if JIT
+ | vm_round vm_trunc, 2
+ |.else
+ |->vm_trunc_efd:
+ |->vm_trunc_hilo:
+ |.endif
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Miscellaneous functions --------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |//-----------------------------------------------------------------------
+ |//-- FFI helper functions -----------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_ffi_call:
+ |.if FFI
+ | NYI
+ |.endif
+ |
+ |//-----------------------------------------------------------------------
+}
+
+/* Generate the code for a single instruction. */
+static void build_ins(BuildCtx *ctx, BCOp op, int defop)
+{
+ int vk = 0;
+ |=>defop:
+
+ switch (op) {
+
+ /* -- Comparison ops ---------------------------------------------------- */
+
+ /* Remember: all ops branch for a true comparison, fall through otherwise. */
+
+ case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:
+ | // RA = src1*8, RD = src2*8, JMP with RD = target
+ | evlddx TMP0, BASE, RA
+ | addi PC, PC, 4
+ | evlddx TMP1, BASE, RD
+ | addis TMP3, PC, -(BCBIAS_J*4 >> 16)
+ | lwz TMP2, -4(PC)
+ | evmergehi RB, TMP0, TMP1
+ | decode_RD4 TMP2, TMP2
+ | checknum RB
+ | add TMP2, TMP2, TMP3
+ | checkanyfail ->vmeta_comp
+ | efdcmplt TMP0, TMP1
+ if (op == BC_ISLE || op == BC_ISGT) {
+ | efdcmpeq cr1, TMP0, TMP1
+ | cror 4*cr0+gt, 4*cr0+gt, 4*cr1+gt
+ }
+ if (op == BC_ISLT || op == BC_ISLE) {
+ | iselgt PC, TMP2, PC
+ } else {
+ | iselgt PC, PC, TMP2
+ }
+ | ins_next
+ break;
+
+ case BC_ISEQV: case BC_ISNEV:
+ vk = op == BC_ISEQV;
+ | // RA = src1*8, RD = src2*8, JMP with RD = target
+ | evlddx CARG2, BASE, RA
+ | addi PC, PC, 4
+ | evlddx CARG3, BASE, RD
+ | addis TMP3, PC, -(BCBIAS_J*4 >> 16)
+ | lwz TMP2, -4(PC)
+ | evmergehi RB, CARG2, CARG3
+ | decode_RD4 TMP2, TMP2
+ | checknum RB
+ | add TMP2, TMP2, TMP3
+ | checkanyfail >5
+ | efdcmpeq CARG2, CARG3
+ if (vk) {
+ | iselgt PC, TMP2, PC
+ } else {
+ | iselgt PC, PC, TMP2
+ }
+ |1:
+ | ins_next
+ |
+ |5: // Either or both types are not numbers.
+ | evcmpeq CARG2, CARG3
+ | not TMP3, RB
+ | cmplwi cr1, TMP3, ~LJ_TISPRI // Primitive?
+ | crorc 4*cr7+lt, 4*cr0+so, 4*cr0+lt // 1: Same tv or different type.
+ | cmplwi cr6, TMP3, ~LJ_TISTABUD // Table or userdata?
+ | crandc 4*cr7+gt, 4*cr0+lt, 4*cr1+gt // 2: Same type and primitive.
+ | mr SAVE0, PC
+ if (vk) {
+ | isel PC, TMP2, PC, 4*cr7+gt
+ } else {
+ | isel TMP2, PC, TMP2, 4*cr7+gt
+ }
+ | cror 4*cr7+lt, 4*cr7+lt, 4*cr7+gt // 1 or 2.
+ if (vk) {
+ | isel PC, TMP2, PC, 4*cr0+so
+ } else {
+ | isel PC, PC, TMP2, 4*cr0+so
+ }
+ | blt cr7, <1 // Done if 1 or 2.
+ | blt cr6, <1 // Done if not tab/ud.
+ |
+ | // Different tables or userdatas. Need to check __eq metamethod.
+ | // Field metatable must be at same offset for GCtab and GCudata!
+ | lwz TAB:TMP2, TAB:CARG2->metatable
+ | li CARG4, 1-vk // ne = 0 or 1.
+ | cmplwi TAB:TMP2, 0
+ | beq <1 // No metatable?
+ | lbz TMP2, TAB:TMP2->nomm
+ | andi. TMP2, TMP2, 1<<MM_eq
+ | bne <1 // Or 'no __eq' flag set?
+ | mr PC, SAVE0 // Restore old PC.
+ | b ->vmeta_equal // Handle __eq metamethod.
+ break;
+
+ case BC_ISEQS: case BC_ISNES:
+ vk = op == BC_ISEQS;
+ | // RA = src*8, RD = str_const*8 (~), JMP with RD = target
+ | evlddx TMP0, BASE, RA
+ | srwi RD, RD, 1
+ | lwz INS, 0(PC)
+ | subfic RD, RD, -4
+ | addi PC, PC, 4
+ | lwzx STR:TMP1, KBASE, RD // KBASE-4-str_const*4
+ | addis TMP3, PC, -(BCBIAS_J*4 >> 16)
+ | decode_RD4 TMP2, INS
+ | evmergelo STR:TMP1, TISSTR, STR:TMP1
+ | add TMP2, TMP2, TMP3
+ | evcmpeq TMP0, STR:TMP1
+ if (vk) {
+ | isel PC, TMP2, PC, 4*cr0+so
+ } else {
+ | isel PC, PC, TMP2, 4*cr0+so
+ }
+ | ins_next
+ break;
+
+ case BC_ISEQN: case BC_ISNEN:
+ vk = op == BC_ISEQN;
+ | // RA = src*8, RD = num_const*8, JMP with RD = target
+ | evlddx TMP0, BASE, RA
+ | addi PC, PC, 4
+ | evlddx TMP1, KBASE, RD
+ | addis TMP3, PC, -(BCBIAS_J*4 >> 16)
+ | lwz INS, -4(PC)
+ | checknum TMP0
+ | checkfail >5
+ | efdcmpeq TMP0, TMP1
+ |1:
+ | decode_RD4 TMP2, INS
+ | add TMP2, TMP2, TMP3
+ if (vk) {
+ | iselgt PC, TMP2, PC
+ |5:
+ } else {
+ | iselgt PC, PC, TMP2
+ }
+ |3:
+ | ins_next
+ if (!vk) {
+ |5:
+ | decode_RD4 TMP2, INS
+ | add PC, TMP2, TMP3
+ | b <3
+ }
+ break;
+
+ case BC_ISEQP: case BC_ISNEP:
+ vk = op == BC_ISEQP;
+ | // RA = src*8, RD = primitive_type*8 (~), JMP with RD = target
+ | lwzx TMP0, BASE, RA
+ | srwi TMP1, RD, 3
+ | lwz INS, 0(PC)
+ | addi PC, PC, 4
+ | not TMP1, TMP1
+ | addis TMP3, PC, -(BCBIAS_J*4 >> 16)
+ | cmplw TMP0, TMP1
+ | decode_RD4 TMP2, INS
+ | add TMP2, TMP2, TMP3
+ if (vk) {
+ | iseleq PC, TMP2, PC
+ } else {
+ | iseleq PC, PC, TMP2
+ }
+ | ins_next
+ break;
+
+ /* -- Unary test and copy ops ------------------------------------------- */
+
+ case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:
+ | // RA = dst*8 or unused, RD = src*8, JMP with RD = target
+ | evlddx TMP0, BASE, RD
+ | evaddw TMP1, TISNIL, TISNIL // Synthesize LJ_TFALSE.
+ | lwz INS, 0(PC)
+ | evcmpltu TMP0, TMP1
+ | addi PC, PC, 4
+ if (op == BC_IST || op == BC_ISF) {
+ | addis TMP3, PC, -(BCBIAS_J*4 >> 16)
+ | decode_RD4 TMP2, INS
+ | add TMP2, TMP2, TMP3
+ if (op == BC_IST) {
+ | isellt PC, TMP2, PC
+ } else {
+ | isellt PC, PC, TMP2
+ }
+ } else {
+ if (op == BC_ISTC) {
+ | checkfail >1
+ } else {
+ | checkok >1
+ }
+ | addis PC, PC, -(BCBIAS_J*4 >> 16)
+ | decode_RD4 TMP2, INS
+ | evstddx TMP0, BASE, RA
+ | add PC, PC, TMP2
+ |1:
+ }
+ | ins_next
+ break;
+
+ /* -- Unary ops --------------------------------------------------------- */
+
+ case BC_MOV:
+ | // RA = dst*8, RD = src*8
+ | ins_next1
+ | evlddx TMP0, BASE, RD
+ | evstddx TMP0, BASE, RA
+ | ins_next2
+ break;
+ case BC_NOT:
+ | // RA = dst*8, RD = src*8
+ | ins_next1
+ | lwzx TMP0, BASE, RD
+ | subfic TMP1, TMP0, LJ_TTRUE
+ | adde TMP0, TMP0, TMP1
+ | stwx TMP0, BASE, RA
+ | ins_next2
+ break;
+ case BC_UNM:
+ | // RA = dst*8, RD = src*8
+ | evlddx TMP0, BASE, RD
+ | checknum TMP0
+ | checkfail ->vmeta_unm
+ | efdneg TMP0, TMP0
+ | ins_next1
+ | evstddx TMP0, BASE, RA
+ | ins_next2
+ break;
+ case BC_LEN:
+ | // RA = dst*8, RD = src*8
+ | evlddx CARG1, BASE, RD
+ | checkstr CARG1
+ | checkfail >2
+ | lwz CRET1, STR:CARG1->len
+ |1:
+ | ins_next1
+ | efdcfsi TMP0, CRET1
+ | evstddx TMP0, BASE, RA
+ | ins_next2
+ |2:
+ | checktab CARG1
+ | checkfail ->vmeta_len
+#if LJ_52
+ | lwz TAB:TMP2, TAB:CARG1->metatable
+ | cmplwi TAB:TMP2, 0
+ | bne >9
+ |3:
+#endif
+ |->BC_LEN_Z:
+ | bl extern lj_tab_len // (GCtab *t)
+ | // Returns uint32_t (but less than 2^31).
+ | b <1
+#if LJ_52
+ |9:
+ | lbz TMP0, TAB:TMP2->nomm
+ | andi. TMP0, TMP0, 1<<MM_len
+ | bne <3 // 'no __len' flag set: done.
+ | b ->vmeta_len
+#endif
+ break;
+
+ /* -- Binary ops -------------------------------------------------------- */
+
+ |.macro ins_arithpre, t0, t1
+ | // RA = dst*8, RB = src1*8, RC = src2*8 | num_const*8
+ ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
+ ||switch (vk) {
+ ||case 0:
+ | evlddx t0, BASE, RB
+ | checknum t0
+ | evlddx t1, KBASE, RC
+ | checkfail ->vmeta_arith_vn
+ || break;
+ ||case 1:
+ | evlddx t1, BASE, RB
+ | checknum t1
+ | evlddx t0, KBASE, RC
+ | checkfail ->vmeta_arith_nv
+ || break;
+ ||default:
+ | evlddx t0, BASE, RB
+ | evlddx t1, BASE, RC
+ | evmergehi TMP2, t0, t1
+ | checknum TMP2
+ | checkanyfail ->vmeta_arith_vv
+ || break;
+ ||}
+ |.endmacro
+ |
+ |.macro ins_arith, ins
+ | ins_arithpre TMP0, TMP1
+ | ins_next1
+ | ins TMP0, TMP0, TMP1
+ | evstddx TMP0, BASE, RA
+ | ins_next2
+ |.endmacro
+
+ case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:
+ | ins_arith efdadd
+ break;
+ case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:
+ | ins_arith efdsub
+ break;
+ case BC_MULVN: case BC_MULNV: case BC_MULVV:
+ | ins_arith efdmul
+ break;
+ case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:
+ | ins_arith efddiv
+ break;
+ case BC_MODVN:
+ | ins_arithpre RD, SAVE0
+ |->BC_MODVN_Z:
+ | efddiv CARG2, RD, SAVE0
+ | bl ->vm_floor_efd // floor(b/c)
+ | efdmul TMP0, CRET2, SAVE0
+ | ins_next1
+ | efdsub TMP0, RD, TMP0 // b - floor(b/c)*c
+ | evstddx TMP0, BASE, RA
+ | ins_next2
+ break;
+ case BC_MODNV: case BC_MODVV:
+ | ins_arithpre RD, SAVE0
+ | b ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway.
+ break;
+ case BC_POW:
+ | evlddx CARG2, BASE, RB
+ | evlddx CARG4, BASE, RC
+ | evmergehi CARG1, CARG4, CARG2
+ | checknum CARG1
+ | evmergehi CARG3, CARG4, CARG4
+ | checkanyfail ->vmeta_arith_vv
+ | bl extern pow@plt
+ | evmergelo CRET2, CRET1, CRET2
+ | evstddx CRET2, BASE, RA
+ | ins_next
+ break;
+
+ case BC_CAT:
+ | // RA = dst*8, RB = src_start*8, RC = src_end*8
+ | sub CARG3, RC, RB
+ | stw BASE, L->base
+ | add CARG2, BASE, RC
+ | mr SAVE0, RB
+ |->BC_CAT_Z:
+ | stw PC, SAVE_PC
+ | mr CARG1, L
+ | srwi CARG3, CARG3, 3
+ | bl extern lj_meta_cat // (lua_State *L, TValue *top, int left)
+ | // Returns NULL (finished) or TValue * (metamethod).
+ | cmplwi CRET1, 0
+ | lwz BASE, L->base
+ | bne ->vmeta_binop
+ | evlddx TMP0, BASE, SAVE0 // Copy result from RB to RA.
+ | evstddx TMP0, BASE, RA
+ | ins_next
+ break;
+
+ /* -- Constant ops ------------------------------------------------------ */
+
+ case BC_KSTR:
+ | // RA = dst*8, RD = str_const*8 (~)
+ | ins_next1
+ | srwi TMP1, RD, 1
+ | subfic TMP1, TMP1, -4
+ | lwzx TMP0, KBASE, TMP1 // KBASE-4-str_const*4
+ | evmergelo TMP0, TISSTR, TMP0
+ | evstddx TMP0, BASE, RA
+ | ins_next2
+ break;
+ case BC_KCDATA:
+ |.if FFI
+ | // RA = dst*8, RD = cdata_const*8 (~)
+ | ins_next1
+ | srwi TMP1, RD, 1
+ | subfic TMP1, TMP1, -4
+ | lwzx TMP0, KBASE, TMP1 // KBASE-4-cdata_const*4
+ | li TMP2, LJ_TCDATA
+ | evmergelo TMP0, TMP2, TMP0
+ | evstddx TMP0, BASE, RA
+ | ins_next2
+ |.endif
+ break;
+ case BC_KSHORT:
+ | // RA = dst*8, RD = int16_literal*8
+ | srwi TMP1, RD, 3
+ | extsh TMP1, TMP1
+ | ins_next1
+ | efdcfsi TMP0, TMP1
+ | evstddx TMP0, BASE, RA
+ | ins_next2
+ break;
+ case BC_KNUM:
+ | // RA = dst*8, RD = num_const*8
+ | evlddx TMP0, KBASE, RD
+ | ins_next1
+ | evstddx TMP0, BASE, RA
+ | ins_next2
+ break;
+ case BC_KPRI:
+ | // RA = dst*8, RD = primitive_type*8 (~)
+ | srwi TMP1, RD, 3
+ | not TMP0, TMP1
+ | ins_next1
+ | stwx TMP0, BASE, RA
+ | ins_next2
+ break;
+ case BC_KNIL:
+ | // RA = base*8, RD = end*8
+ | evstddx TISNIL, BASE, RA
+ | addi RA, RA, 8
+ |1:
+ | evstddx TISNIL, BASE, RA
+ | cmpw RA, RD
+ | addi RA, RA, 8
+ | blt <1
+ | ins_next_
+ break;
+
+ /* -- Upvalue and function ops ------------------------------------------ */
+
+ case BC_UGET:
+ | // RA = dst*8, RD = uvnum*8
+ | ins_next1
+ | lwz LFUNC:RB, FRAME_FUNC(BASE)
+ | srwi RD, RD, 1
+ | addi RD, RD, offsetof(GCfuncL, uvptr)
+ | lwzx UPVAL:RB, LFUNC:RB, RD
+ | lwz TMP1, UPVAL:RB->v
+ | evldd TMP0, 0(TMP1)
+ | evstddx TMP0, BASE, RA
+ | ins_next2
+ break;
+ case BC_USETV:
+ | // RA = uvnum*8, RD = src*8
+ | lwz LFUNC:RB, FRAME_FUNC(BASE)
+ | srwi RA, RA, 1
+ | addi RA, RA, offsetof(GCfuncL, uvptr)
+ | evlddx TMP1, BASE, RD
+ | lwzx UPVAL:RB, LFUNC:RB, RA
+ | lbz TMP3, UPVAL:RB->marked
+ | lwz CARG2, UPVAL:RB->v
+ | andi. TMP3, TMP3, LJ_GC_BLACK // isblack(uv)
+ | lbz TMP0, UPVAL:RB->closed
+ | evmergehi TMP2, TMP1, TMP1
+ | evstdd TMP1, 0(CARG2)
+ | cmplwi cr1, TMP0, 0
+ | cror 4*cr0+eq, 4*cr0+eq, 4*cr1+eq
+ | subi TMP2, TMP2, (LJ_TISNUM+1)
+ | bne >2 // Upvalue is closed and black?
+ |1:
+ | ins_next
+ |
+ |2: // Check if new value is collectable.
+ | cmplwi TMP2, LJ_TISGCV - (LJ_TISNUM+1)
+ | bge <1 // tvisgcv(v)
+ | lbz TMP3, GCOBJ:TMP1->gch.marked
+ | andi. TMP3, TMP3, LJ_GC_WHITES // iswhite(v)
+ | la CARG1, GG_DISP2G(DISPATCH)
+ | // Crossed a write barrier. Move the barrier forward.
+ | beq <1
+ | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv)
+ | b <1
+ break;
+ case BC_USETS:
+ | // RA = uvnum*8, RD = str_const*8 (~)
+ | lwz LFUNC:RB, FRAME_FUNC(BASE)
+ | srwi TMP1, RD, 1
+ | srwi RA, RA, 1
+ | subfic TMP1, TMP1, -4
+ | addi RA, RA, offsetof(GCfuncL, uvptr)
+ | lwzx STR:TMP1, KBASE, TMP1 // KBASE-4-str_const*4
+ | lwzx UPVAL:RB, LFUNC:RB, RA
+ | evmergelo STR:TMP1, TISSTR, STR:TMP1
+ | lbz TMP3, UPVAL:RB->marked
+ | lwz CARG2, UPVAL:RB->v
+ | andi. TMP3, TMP3, LJ_GC_BLACK // isblack(uv)
+ | lbz TMP3, STR:TMP1->marked
+ | lbz TMP2, UPVAL:RB->closed
+ | evstdd STR:TMP1, 0(CARG2)
+ | bne >2
+ |1:
+ | ins_next
+ |
+ |2: // Check if string is white and ensure upvalue is closed.
+ | andi. TMP3, TMP3, LJ_GC_WHITES // iswhite(str)
+ | cmplwi cr1, TMP2, 0
+ | cror 4*cr0+eq, 4*cr0+eq, 4*cr1+eq
+ | la CARG1, GG_DISP2G(DISPATCH)
+ | // Crossed a write barrier. Move the barrier forward.
+ | beq <1
+ | bl extern lj_gc_barrieruv // (global_State *g, TValue *tv)
+ | b <1
+ break;
+ case BC_USETN:
+ | // RA = uvnum*8, RD = num_const*8
+ | ins_next1
+ | lwz LFUNC:RB, FRAME_FUNC(BASE)
+ | srwi RA, RA, 1
+ | addi RA, RA, offsetof(GCfuncL, uvptr)
+ | evlddx TMP0, KBASE, RD
+ | lwzx UPVAL:RB, LFUNC:RB, RA
+ | lwz TMP1, UPVAL:RB->v
+ | evstdd TMP0, 0(TMP1)
+ | ins_next2
+ break;
+ case BC_USETP:
+ | // RA = uvnum*8, RD = primitive_type*8 (~)
+ | ins_next1
+ | lwz LFUNC:RB, FRAME_FUNC(BASE)
+ | srwi RA, RA, 1
+ | addi RA, RA, offsetof(GCfuncL, uvptr)
+ | srwi TMP0, RD, 3
+ | lwzx UPVAL:RB, LFUNC:RB, RA
+ | not TMP0, TMP0
+ | lwz TMP1, UPVAL:RB->v
+ | stw TMP0, 0(TMP1)
+ | ins_next2
+ break;
+
+ case BC_UCLO:
+ | // RA = level*8, RD = target
+ | lwz TMP1, L->openupval
+ | branch_RD // Do this first since RD is not saved.
+ | stw BASE, L->base
+ | cmplwi TMP1, 0
+ | mr CARG1, L
+ | beq >1
+ | add CARG2, BASE, RA
+ | bl extern lj_func_closeuv // (lua_State *L, TValue *level)
+ | lwz BASE, L->base
+ |1:
+ | ins_next
+ break;
+
+ case BC_FNEW:
+ | // RA = dst*8, RD = proto_const*8 (~) (holding function prototype)
+ | srwi TMP1, RD, 1
+ | stw BASE, L->base
+ | subfic TMP1, TMP1, -4
+ | stw PC, SAVE_PC
+ | lwzx CARG2, KBASE, TMP1 // KBASE-4-tab_const*4
+ | mr CARG1, L
+ | lwz CARG3, FRAME_FUNC(BASE)
+ | // (lua_State *L, GCproto *pt, GCfuncL *parent)
+ | bl extern lj_func_newL_gc
+ | // Returns GCfuncL *.
+ | lwz BASE, L->base
+ | evmergelo LFUNC:CRET1, TISFUNC, LFUNC:CRET1
+ | evstddx LFUNC:CRET1, BASE, RA
+ | ins_next
+ break;
+
+ /* -- Table ops --------------------------------------------------------- */
+
+ case BC_TNEW:
+ case BC_TDUP:
+ | // RA = dst*8, RD = (hbits|asize)*8 | tab_const*8 (~)
+ | lwz TMP0, DISPATCH_GL(gc.total)(DISPATCH)
+ | mr CARG1, L
+ | lwz TMP1, DISPATCH_GL(gc.threshold)(DISPATCH)
+ | stw BASE, L->base
+ | cmplw TMP0, TMP1
+ | stw PC, SAVE_PC
+ | bge >5
+ |1:
+ if (op == BC_TNEW) {
+ | rlwinm CARG2, RD, 29, 21, 31
+ | rlwinm CARG3, RD, 18, 27, 31
+ | cmpwi CARG2, 0x7ff
+ | li TMP1, 0x801
+ | iseleq CARG2, TMP1, CARG2
+ | bl extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits)
+ | // Returns Table *.
+ } else {
+ | srwi TMP1, RD, 1
+ | subfic TMP1, TMP1, -4
+ | lwzx CARG2, KBASE, TMP1 // KBASE-4-tab_const*4
+ | bl extern lj_tab_dup // (lua_State *L, Table *kt)
+ | // Returns Table *.
+ }
+ | lwz BASE, L->base
+ | evmergelo TAB:CRET1, TISTAB, TAB:CRET1
+ | evstddx TAB:CRET1, BASE, RA
+ | ins_next
+ |5:
+ | mr SAVE0, RD
+ | bl extern lj_gc_step_fixtop // (lua_State *L)
+ | mr RD, SAVE0
+ | mr CARG1, L
+ | b <1
+ break;
+
+ case BC_GGET:
+ | // RA = dst*8, RD = str_const*8 (~)
+ case BC_GSET:
+ | // RA = src*8, RD = str_const*8 (~)
+ | lwz LFUNC:TMP2, FRAME_FUNC(BASE)
+ | srwi TMP1, RD, 1
+ | lwz TAB:RB, LFUNC:TMP2->env
+ | subfic TMP1, TMP1, -4
+ | lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4
+ if (op == BC_GGET) {
+ | b ->BC_TGETS_Z
+ } else {
+ | b ->BC_TSETS_Z
+ }
+ break;
+
+ case BC_TGETV:
+ | // RA = dst*8, RB = table*8, RC = key*8
+ | evlddx TAB:RB, BASE, RB
+ | evlddx RC, BASE, RC
+ | checktab TAB:RB
+ | checkfail ->vmeta_tgetv
+ | checknum RC
+ | checkfail >5
+ | // Convert number key to integer
+ | efdctsi TMP2, RC
+ | lwz TMP0, TAB:RB->asize
+ | efdcfsi TMP1, TMP2
+ | cmplw cr0, TMP0, TMP2
+ | efdcmpeq cr1, RC, TMP1
+ | lwz TMP1, TAB:RB->array
+ | crand 4*cr0+gt, 4*cr0+gt, 4*cr1+gt
+ | slwi TMP2, TMP2, 3
+ | ble ->vmeta_tgetv // Integer key and in array part?
+ | evlddx TMP1, TMP1, TMP2
+ | checknil TMP1
+ | checkok >2
+ |1:
+ | evstddx TMP1, BASE, RA
+ | ins_next
+ |
+ |2: // Check for __index if table value is nil.
+ | lwz TAB:TMP2, TAB:RB->metatable
+ | cmplwi TAB:TMP2, 0
+ | beq <1 // No metatable: done.
+ | lbz TMP0, TAB:TMP2->nomm
+ | andi. TMP0, TMP0, 1<<MM_index
+ | bne <1 // 'no __index' flag set: done.
+ | b ->vmeta_tgetv
+ |
+ |5:
+ | checkstr STR:RC // String key?
+ | checkok ->BC_TGETS_Z
+ | b ->vmeta_tgetv
+ break;
+ case BC_TGETS:
+ | // RA = dst*8, RB = table*8, RC = str_const*8 (~)
+ | evlddx TAB:RB, BASE, RB
+ | srwi TMP1, RC, 1
+ | checktab TAB:RB
+ | subfic TMP1, TMP1, -4
+ | lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4
+ | checkfail ->vmeta_tgets1
+ |->BC_TGETS_Z:
+ | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = dst*8
+ | lwz TMP0, TAB:RB->hmask
+ | lwz TMP1, STR:RC->hash
+ | lwz NODE:TMP2, TAB:RB->node
+ | evmergelo STR:RC, TISSTR, STR:RC
+ | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask
+ | slwi TMP0, TMP1, 5
+ | slwi TMP1, TMP1, 3
+ | sub TMP1, TMP0, TMP1
+ | add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8)
+ |1:
+ | evldd TMP0, NODE:TMP2->key
+ | evldd TMP1, NODE:TMP2->val
+ | evcmpeq TMP0, STR:RC
+ | checkanyfail >4
+ | checknil TMP1
+ | checkok >5 // Key found, but nil value?
+ |3:
+ | evstddx TMP1, BASE, RA
+ | ins_next
+ |
+ |4: // Follow hash chain.
+ | lwz NODE:TMP2, NODE:TMP2->next
+ | cmplwi NODE:TMP2, 0
+ | bne <1
+ | // End of hash chain: key not found, nil result.
+ | evmr TMP1, TISNIL
+ |
+ |5: // Check for __index if table value is nil.
+ | lwz TAB:TMP2, TAB:RB->metatable
+ | cmplwi TAB:TMP2, 0
+ | beq <3 // No metatable: done.
+ | lbz TMP0, TAB:TMP2->nomm
+ | andi. TMP0, TMP0, 1<<MM_index
+ | bne <3 // 'no __index' flag set: done.
+ | b ->vmeta_tgets
+ break;
+ case BC_TGETB:
+ | // RA = dst*8, RB = table*8, RC = index*8
+ | evlddx TAB:RB, BASE, RB
+ | srwi TMP0, RC, 3
+ | checktab TAB:RB
+ | checkfail ->vmeta_tgetb
+ | lwz TMP1, TAB:RB->asize
+ | lwz TMP2, TAB:RB->array
+ | cmplw TMP0, TMP1
+ | bge ->vmeta_tgetb
+ | evlddx TMP1, TMP2, RC
+ | checknil TMP1
+ | checkok >5
+ |1:
+ | ins_next1
+ | evstddx TMP1, BASE, RA
+ | ins_next2
+ |
+ |5: // Check for __index if table value is nil.
+ | lwz TAB:TMP2, TAB:RB->metatable
+ | cmplwi TAB:TMP2, 0
+ | beq <1 // No metatable: done.
+ | lbz TMP2, TAB:TMP2->nomm
+ | andi. TMP2, TMP2, 1<<MM_index
+ | bne <1 // 'no __index' flag set: done.
+ | b ->vmeta_tgetb // Caveat: preserve TMP0!
+ break;
+
+ case BC_TSETV:
+ | // RA = src*8, RB = table*8, RC = key*8
+ | evlddx TAB:RB, BASE, RB
+ | evlddx RC, BASE, RC
+ | checktab TAB:RB
+ | checkfail ->vmeta_tsetv
+ | checknum RC
+ | checkfail >5
+ | // Convert number key to integer
+ | efdctsi TMP2, RC
+ | evlddx SAVE0, BASE, RA
+ | lwz TMP0, TAB:RB->asize
+ | efdcfsi TMP1, TMP2
+ | cmplw cr0, TMP0, TMP2
+ | efdcmpeq cr1, RC, TMP1
+ | lwz TMP1, TAB:RB->array
+ | crand 4*cr0+gt, 4*cr0+gt, 4*cr1+gt
+ | slwi TMP0, TMP2, 3
+ | ble ->vmeta_tsetv // Integer key and in array part?
+ | lbz TMP3, TAB:RB->marked
+ | evlddx TMP2, TMP1, TMP0
+ | checknil TMP2
+ | checkok >3
+ |1:
+ | andi. TMP2, TMP3, LJ_GC_BLACK // isblack(table)
+ | evstddx SAVE0, TMP1, TMP0
+ | bne >7
+ |2:
+ | ins_next
+ |
+ |3: // Check for __newindex if previous value is nil.
+ | lwz TAB:TMP2, TAB:RB->metatable
+ | cmplwi TAB:TMP2, 0
+ | beq <1 // No metatable: done.
+ | lbz TMP2, TAB:TMP2->nomm
+ | andi. TMP2, TMP2, 1<<MM_newindex
+ | bne <1 // 'no __newindex' flag set: done.
+ | b ->vmeta_tsetv
+ |
+ |5:
+ | checkstr STR:RC // String key?
+ | checkok ->BC_TSETS_Z
+ | b ->vmeta_tsetv
+ |
+ |7: // Possible table write barrier for the value. Skip valiswhite check.
+ | barrierback TAB:RB, TMP3, TMP0
+ | b <2
+ break;
+ case BC_TSETS:
+ | // RA = src*8, RB = table*8, RC = str_const*8 (~)
+ | evlddx TAB:RB, BASE, RB
+ | srwi TMP1, RC, 1
+ | checktab TAB:RB
+ | subfic TMP1, TMP1, -4
+ | lwzx STR:RC, KBASE, TMP1 // KBASE-4-str_const*4
+ | checkfail ->vmeta_tsets1
+ |->BC_TSETS_Z:
+ | // TAB:RB = GCtab *, STR:RC = GCstr *, RA = src*8
+ | lwz TMP0, TAB:RB->hmask
+ | lwz TMP1, STR:RC->hash
+ | lwz NODE:TMP2, TAB:RB->node
+ | evmergelo STR:RC, TISSTR, STR:RC
+ | stb ZERO, TAB:RB->nomm // Clear metamethod cache.
+ | and TMP1, TMP1, TMP0 // idx = str->hash & tab->hmask
+ | evlddx SAVE0, BASE, RA
+ | slwi TMP0, TMP1, 5
+ | slwi TMP1, TMP1, 3
+ | sub TMP1, TMP0, TMP1
+ | lbz TMP3, TAB:RB->marked
+ | add NODE:TMP2, NODE:TMP2, TMP1 // node = tab->node + (idx*32-idx*8)
+ |1:
+ | evldd TMP0, NODE:TMP2->key
+ | evldd TMP1, NODE:TMP2->val
+ | evcmpeq TMP0, STR:RC
+ | checkanyfail >5
+ | checknil TMP1
+ | checkok >4 // Key found, but nil value?
+ |2:
+ | andi. TMP0, TMP3, LJ_GC_BLACK // isblack(table)
+ | evstdd SAVE0, NODE:TMP2->val
+ | bne >7
+ |3:
+ | ins_next
+ |
+ |4: // Check for __newindex if previous value is nil.
+ | lwz TAB:TMP1, TAB:RB->metatable
+ | cmplwi TAB:TMP1, 0
+ | beq <2 // No metatable: done.
+ | lbz TMP0, TAB:TMP1->nomm
+ | andi. TMP0, TMP0, 1<<MM_newindex
+ | bne <2 // 'no __newindex' flag set: done.
+ | b ->vmeta_tsets
+ |
+ |5: // Follow hash chain.
+ | lwz NODE:TMP2, NODE:TMP2->next
+ | cmplwi NODE:TMP2, 0
+ | bne <1
+ | // End of hash chain: key not found, add a new one.
+ |
+ | // But check for __newindex first.
+ | lwz TAB:TMP1, TAB:RB->metatable
+ | la CARG3, DISPATCH_GL(tmptv)(DISPATCH)
+ | stw PC, SAVE_PC
+ | mr CARG1, L
+ | cmplwi TAB:TMP1, 0
+ | stw BASE, L->base
+ | beq >6 // No metatable: continue.
+ | lbz TMP0, TAB:TMP1->nomm
+ | andi. TMP0, TMP0, 1<<MM_newindex
+ | beq ->vmeta_tsets // 'no __newindex' flag NOT set: check.
+ |6:
+ | mr CARG2, TAB:RB
+ | evstdd STR:RC, 0(CARG3)
+ | bl extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k)
+ | // Returns TValue *.
+ | lwz BASE, L->base
+ | evstdd SAVE0, 0(CRET1)
+ | b <3 // No 2nd write barrier needed.
+ |
+ |7: // Possible table write barrier for the value. Skip valiswhite check.
+ | barrierback TAB:RB, TMP3, TMP0
+ | b <3
+ break;
+ case BC_TSETB:
+ | // RA = src*8, RB = table*8, RC = index*8
+ | evlddx TAB:RB, BASE, RB
+ | srwi TMP0, RC, 3
+ | checktab TAB:RB
+ | checkfail ->vmeta_tsetb
+ | lwz TMP1, TAB:RB->asize
+ | lwz TMP2, TAB:RB->array
+ | lbz TMP3, TAB:RB->marked
+ | cmplw TMP0, TMP1
+ | evlddx SAVE0, BASE, RA
+ | bge ->vmeta_tsetb
+ | evlddx TMP1, TMP2, RC
+ | checknil TMP1
+ | checkok >5
+ |1:
+ | andi. TMP0, TMP3, LJ_GC_BLACK // isblack(table)
+ | evstddx SAVE0, TMP2, RC
+ | bne >7
+ |2:
+ | ins_next
+ |
+ |5: // Check for __newindex if previous value is nil.
+ | lwz TAB:TMP1, TAB:RB->metatable
+ | cmplwi TAB:TMP1, 0
+ | beq <1 // No metatable: done.
+ | lbz TMP1, TAB:TMP1->nomm
+ | andi. TMP1, TMP1, 1<<MM_newindex
+ | bne <1 // 'no __newindex' flag set: done.
+ | b ->vmeta_tsetb // Caveat: preserve TMP0!
+ |
+ |7: // Possible table write barrier for the value. Skip valiswhite check.
+ | barrierback TAB:RB, TMP3, TMP0
+ | b <2
+ break;
+
+ case BC_TSETM:
+ | // RA = base*8 (table at base-1), RD = num_const*8 (start index)
+ | add RA, BASE, RA
+ |1:
+ | add TMP3, KBASE, RD
+ | lwz TAB:CARG2, -4(RA) // Guaranteed to be a table.
+ | addic. TMP0, MULTRES, -8
+ | lwz TMP3, 4(TMP3) // Integer constant is in lo-word.
+ | srwi CARG3, TMP0, 3
+ | beq >4 // Nothing to copy?
+ | add CARG3, CARG3, TMP3
+ | lwz TMP2, TAB:CARG2->asize
+ | slwi TMP1, TMP3, 3
+ | lbz TMP3, TAB:CARG2->marked
+ | cmplw CARG3, TMP2
+ | add TMP2, RA, TMP0
+ | lwz TMP0, TAB:CARG2->array
+ | bgt >5
+ | add TMP1, TMP1, TMP0
+ | andi. TMP0, TMP3, LJ_GC_BLACK // isblack(table)
+ |3: // Copy result slots to table.
+ | evldd TMP0, 0(RA)
+ | addi RA, RA, 8
+ | cmpw cr1, RA, TMP2
+ | evstdd TMP0, 0(TMP1)
+ | addi TMP1, TMP1, 8
+ | blt cr1, <3
+ | bne >7
+ |4:
+ | ins_next
+ |
+ |5: // Need to resize array part.
+ | stw BASE, L->base
+ | mr CARG1, L
+ | stw PC, SAVE_PC
+ | mr SAVE0, RD
+ | bl extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize)
+ | // Must not reallocate the stack.
+ | mr RD, SAVE0
+ | b <1
+ |
+ |7: // Possible table write barrier for any value. Skip valiswhite check.
+ | barrierback TAB:CARG2, TMP3, TMP0
+ | b <4
+ break;
+
+ /* -- Calls and vararg handling ----------------------------------------- */
+
+ case BC_CALLM:
+ | // RA = base*8, (RB = (nresults+1)*8,) RC = extra_nargs*8
+ | add NARGS8:RC, NARGS8:RC, MULTRES
+ | // Fall through. Assumes BC_CALL follows.
+ break;
+ case BC_CALL:
+ | // RA = base*8, (RB = (nresults+1)*8,) RC = (nargs+1)*8
+ | evlddx LFUNC:RB, BASE, RA
+ | mr TMP2, BASE
+ | add BASE, BASE, RA
+ | subi NARGS8:RC, NARGS8:RC, 8
+ | checkfunc LFUNC:RB
+ | addi BASE, BASE, 8
+ | checkfail ->vmeta_call
+ | ins_call
+ break;
+
+ case BC_CALLMT:
+ | // RA = base*8, (RB = 0,) RC = extra_nargs*8
+ | add NARGS8:RC, NARGS8:RC, MULTRES
+ | // Fall through. Assumes BC_CALLT follows.
+ break;
+ case BC_CALLT:
+ | // RA = base*8, (RB = 0,) RC = (nargs+1)*8
+ | evlddx LFUNC:RB, BASE, RA
+ | add RA, BASE, RA
+ | lwz TMP1, FRAME_PC(BASE)
+ | subi NARGS8:RC, NARGS8:RC, 8
+ | checkfunc LFUNC:RB
+ | addi RA, RA, 8
+ | checkfail ->vmeta_callt
+ |->BC_CALLT_Z:
+ | andi. TMP0, TMP1, FRAME_TYPE // Caveat: preserve cr0 until the crand.
+ | lbz TMP3, LFUNC:RB->ffid
+ | xori TMP2, TMP1, FRAME_VARG
+ | cmplwi cr1, NARGS8:RC, 0
+ | bne >7
+ |1:
+ | stw LFUNC:RB, FRAME_FUNC(BASE) // Copy function down, but keep PC.
+ | li TMP2, 0
+ | cmplwi cr7, TMP3, 1 // (> FF_C) Calling a fast function?
+ | beq cr1, >3
+ |2:
+ | addi TMP3, TMP2, 8
+ | evlddx TMP0, RA, TMP2
+ | cmplw cr1, TMP3, NARGS8:RC
+ | evstddx TMP0, BASE, TMP2
+ | mr TMP2, TMP3
+ | bne cr1, <2
+ |3:
+ | crand 4*cr0+eq, 4*cr0+eq, 4*cr7+gt
+ | beq >5
+ |4:
+ | ins_callt
+ |
+ |5: // Tailcall to a fast function with a Lua frame below.
+ | lwz INS, -4(TMP1)
+ | decode_RA8 RA, INS
+ | sub TMP1, BASE, RA
+ | lwz LFUNC:TMP1, FRAME_FUNC-8(TMP1)
+ | lwz TMP1, LFUNC:TMP1->pc
+ | lwz KBASE, PC2PROTO(k)(TMP1) // Need to prepare KBASE.
+ | b <4
+ |
+ |7: // Tailcall from a vararg function.
+ | andi. TMP0, TMP2, FRAME_TYPEP
+ | bne <1 // Vararg frame below?
+ | sub BASE, BASE, TMP2 // Relocate BASE down.
+ | lwz TMP1, FRAME_PC(BASE)
+ | andi. TMP0, TMP1, FRAME_TYPE
+ | b <1
+ break;
+
+ case BC_ITERC:
+ | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 ((2+1)*8))
+ | subi RA, RA, 24 // evldd doesn't support neg. offsets.
+ | mr TMP2, BASE
+ | evlddx LFUNC:RB, BASE, RA
+ | add BASE, BASE, RA
+ | evldd TMP0, 8(BASE)
+ | evldd TMP1, 16(BASE)
+ | evstdd LFUNC:RB, 24(BASE) // Copy callable.
+ | checkfunc LFUNC:RB
+ | evstdd TMP0, 32(BASE) // Copy state.
+ | li NARGS8:RC, 16 // Iterators get 2 arguments.
+ | evstdd TMP1, 40(BASE) // Copy control var.
+ | addi BASE, BASE, 32
+ | checkfail ->vmeta_call
+ | ins_call
+ break;
+
+ case BC_ITERN:
+ | // RA = base*8, (RB = (nresults+1)*8, RC = (nargs+1)*8 (2+1)*8)
+ |.if JIT
+ | // NYI: add hotloop, record BC_ITERN.
+ |.endif
+ | add RA, BASE, RA
+ | lwz TAB:RB, -12(RA)
+ | lwz RC, -4(RA) // Get index from control var.
+ | lwz TMP0, TAB:RB->asize
+ | lwz TMP1, TAB:RB->array
+ | addi PC, PC, 4
+ |1: // Traverse array part.
+ | cmplw RC, TMP0
+ | slwi TMP3, RC, 3
+ | bge >5 // Index points after array part?
+ | evlddx TMP2, TMP1, TMP3
+ | checknil TMP2
+ | lwz INS, -4(PC)
+ | checkok >4
+ | efdcfsi TMP0, RC
+ | addi RC, RC, 1
+ | addis TMP3, PC, -(BCBIAS_J*4 >> 16)
+ | evstdd TMP2, 8(RA)
+ | decode_RD4 TMP1, INS
+ | stw RC, -4(RA) // Update control var.
+ | add PC, TMP1, TMP3
+ | evstdd TMP0, 0(RA)
+ |3:
+ | ins_next
+ |
+ |4: // Skip holes in array part.
+ | addi RC, RC, 1
+ | b <1
+ |
+ |5: // Traverse hash part.
+ | lwz TMP1, TAB:RB->hmask
+ | sub RC, RC, TMP0
+ | lwz TMP2, TAB:RB->node
+ |6:
+ | cmplw RC, TMP1 // End of iteration? Branch to ITERL+1.
+ | slwi TMP3, RC, 5
+ | bgt <3
+ | slwi RB, RC, 3
+ | sub TMP3, TMP3, RB
+ | evlddx RB, TMP2, TMP3
+ | add NODE:TMP3, TMP2, TMP3
+ | checknil RB
+ | lwz INS, -4(PC)
+ | checkok >7
+ | evldd TMP3, NODE:TMP3->key
+ | addis TMP2, PC, -(BCBIAS_J*4 >> 16)
+ | evstdd RB, 8(RA)
+ | add RC, RC, TMP0
+ | decode_RD4 TMP1, INS
+ | evstdd TMP3, 0(RA)
+ | addi RC, RC, 1
+ | add PC, TMP1, TMP2
+ | stw RC, -4(RA) // Update control var.
+ | b <3
+ |
+ |7: // Skip holes in hash part.
+ | addi RC, RC, 1
+ | b <6
+ break;
+
+ case BC_ISNEXT:
+ | // RA = base*8, RD = target (points to ITERN)
+ | add RA, BASE, RA
+ | li TMP2, -24
+ | evlddx CFUNC:TMP1, RA, TMP2
+ | lwz TMP2, -16(RA)
+ | lwz TMP3, -8(RA)
+ | evmergehi TMP0, CFUNC:TMP1, CFUNC:TMP1
+ | cmpwi cr0, TMP2, LJ_TTAB
+ | cmpwi cr1, TMP0, LJ_TFUNC
+ | cmpwi cr6, TMP3, LJ_TNIL
+ | bne cr1, >5
+ | lbz TMP1, CFUNC:TMP1->ffid
+ | crand 4*cr0+eq, 4*cr0+eq, 4*cr6+eq
+ | cmpwi cr7, TMP1, FF_next_N
+ | srwi TMP0, RD, 1
+ | crand 4*cr0+eq, 4*cr0+eq, 4*cr7+eq
+ | add TMP3, PC, TMP0
+ | bne cr0, >5
+ | lus TMP1, 0xfffe
+ | ori TMP1, TMP1, 0x7fff
+ | stw ZERO, -4(RA) // Initialize control var.
+ | stw TMP1, -8(RA)
+ | addis PC, TMP3, -(BCBIAS_J*4 >> 16)
+ |1:
+ | ins_next
+ |5: // Despecialize bytecode if any of the checks fail.
+ | li TMP0, BC_JMP
+ | li TMP1, BC_ITERC
+ | stb TMP0, -1(PC)
+ | addis PC, TMP3, -(BCBIAS_J*4 >> 16)
+ | stb TMP1, 3(PC)
+ | b <1
+ break;
+
+ case BC_VARG:
+ | // RA = base*8, RB = (nresults+1)*8, RC = numparams*8
+ | lwz TMP0, FRAME_PC(BASE)
+ | add RC, BASE, RC
+ | add RA, BASE, RA
+ | addi RC, RC, FRAME_VARG
+ | add TMP2, RA, RB
+ | subi TMP3, BASE, 8 // TMP3 = vtop
+ | sub RC, RC, TMP0 // RC = vbase
+ | // Note: RC may now be even _above_ BASE if nargs was < numparams.
+ | cmplwi cr1, RB, 0
+ | sub. TMP1, TMP3, RC
+ | beq cr1, >5 // Copy all varargs?
+ | subi TMP2, TMP2, 16
+ | ble >2 // No vararg slots?
+ |1: // Copy vararg slots to destination slots.
+ | evldd TMP0, 0(RC)
+ | addi RC, RC, 8
+ | evstdd TMP0, 0(RA)
+ | cmplw RA, TMP2
+ | cmplw cr1, RC, TMP3
+ | bge >3 // All destination slots filled?
+ | addi RA, RA, 8
+ | blt cr1, <1 // More vararg slots?
+ |2: // Fill up remainder with nil.
+ | evstdd TISNIL, 0(RA)
+ | cmplw RA, TMP2
+ | addi RA, RA, 8
+ | blt <2
+ |3:
+ | ins_next
+ |
+ |5: // Copy all varargs.
+ | lwz TMP0, L->maxstack
+ | li MULTRES, 8 // MULTRES = (0+1)*8
+ | ble <3 // No vararg slots?
+ | add TMP2, RA, TMP1
+ | cmplw TMP2, TMP0
+ | addi MULTRES, TMP1, 8
+ | bgt >7
+ |6:
+ | evldd TMP0, 0(RC)
+ | addi RC, RC, 8
+ | evstdd TMP0, 0(RA)
+ | cmplw RC, TMP3
+ | addi RA, RA, 8
+ | blt <6 // More vararg slots?
+ | b <3
+ |
+ |7: // Grow stack for varargs.
+ | mr CARG1, L
+ | stw RA, L->top
+ | sub SAVE0, RC, BASE // Need delta, because BASE may change.
+ | stw BASE, L->base
+ | sub RA, RA, BASE
+ | stw PC, SAVE_PC
+ | srwi CARG2, TMP1, 3
+ | bl extern lj_state_growstack // (lua_State *L, int n)
+ | lwz BASE, L->base
+ | add RA, BASE, RA
+ | add RC, BASE, SAVE0
+ | subi TMP3, BASE, 8
+ | b <6
+ break;
+
+ /* -- Returns ----------------------------------------------------------- */
+
+ case BC_RETM:
+ | // RA = results*8, RD = extra_nresults*8
+ | add RD, RD, MULTRES // MULTRES >= 8, so RD >= 8.
+ | // Fall through. Assumes BC_RET follows.
+ break;
+
+ case BC_RET:
+ | // RA = results*8, RD = (nresults+1)*8
+ | lwz PC, FRAME_PC(BASE)
+ | add RA, BASE, RA
+ | mr MULTRES, RD
+ |1:
+ | andi. TMP0, PC, FRAME_TYPE
+ | xori TMP1, PC, FRAME_VARG
+ | bne ->BC_RETV_Z
+ |
+ |->BC_RET_Z:
+ | // BASE = base, RA = resultptr, RD = (nresults+1)*8, PC = return
+ | lwz INS, -4(PC)
+ | cmpwi RD, 8
+ | subi TMP2, BASE, 8
+ | subi RC, RD, 8
+ | decode_RB8 RB, INS
+ | beq >3
+ | li TMP1, 0
+ |2:
+ | addi TMP3, TMP1, 8
+ | evlddx TMP0, RA, TMP1
+ | cmpw TMP3, RC
+ | evstddx TMP0, TMP2, TMP1
+ | beq >3
+ | addi TMP1, TMP3, 8
+ | evlddx TMP0, RA, TMP3
+ | cmpw TMP1, RC
+ | evstddx TMP0, TMP2, TMP3
+ | bne <2
+ |3:
+ |5:
+ | cmplw RB, RD
+ | decode_RA8 RA, INS
+ | bgt >6
+ | sub BASE, TMP2, RA
+ | lwz LFUNC:TMP1, FRAME_FUNC(BASE)
+ | ins_next1
+ | lwz TMP1, LFUNC:TMP1->pc
+ | lwz KBASE, PC2PROTO(k)(TMP1)
+ | ins_next2
+ |
+ |6: // Fill up results with nil.
+ | subi TMP1, RD, 8
+ | addi RD, RD, 8
+ | evstddx TISNIL, TMP2, TMP1
+ | b <5
+ |
+ |->BC_RETV_Z: // Non-standard return case.
+ | andi. TMP2, TMP1, FRAME_TYPEP
+ | bne ->vm_return
+ | // Return from vararg function: relocate BASE down.
+ | sub BASE, BASE, TMP1
+ | lwz PC, FRAME_PC(BASE)
+ | b <1
+ break;
+
+ case BC_RET0: case BC_RET1:
+ | // RA = results*8, RD = (nresults+1)*8
+ | lwz PC, FRAME_PC(BASE)
+ | add RA, BASE, RA
+ | mr MULTRES, RD
+ | andi. TMP0, PC, FRAME_TYPE
+ | xori TMP1, PC, FRAME_VARG
+ | bne ->BC_RETV_Z
+ |
+ | lwz INS, -4(PC)
+ | subi TMP2, BASE, 8
+ | decode_RB8 RB, INS
+ if (op == BC_RET1) {
+ | evldd TMP0, 0(RA)
+ | evstdd TMP0, 0(TMP2)
+ }
+ |5:
+ | cmplw RB, RD
+ | decode_RA8 RA, INS
+ | bgt >6
+ | sub BASE, TMP2, RA
+ | lwz LFUNC:TMP1, FRAME_FUNC(BASE)
+ | ins_next1
+ | lwz TMP1, LFUNC:TMP1->pc
+ | lwz KBASE, PC2PROTO(k)(TMP1)
+ | ins_next2
+ |
+ |6: // Fill up results with nil.
+ | subi TMP1, RD, 8
+ | addi RD, RD, 8
+ | evstddx TISNIL, TMP2, TMP1
+ | b <5
+ break;
+
+ /* -- Loops and branches ------------------------------------------------ */
+
+ case BC_FORL:
+ |.if JIT
+ | hotloop
+ |.endif
+ | // Fall through. Assumes BC_IFORL follows.
+ break;
+
+ case BC_JFORI:
+ case BC_JFORL:
+#if !LJ_HASJIT
+ break;
+#endif
+ case BC_FORI:
+ case BC_IFORL:
+ | // RA = base*8, RD = target (after end of loop or start of loop)
+ vk = (op == BC_IFORL || op == BC_JFORL);
+ | add RA, BASE, RA
+ | evldd TMP1, FORL_IDX*8(RA)
+ | evldd TMP3, FORL_STEP*8(RA)
+ | evldd TMP2, FORL_STOP*8(RA)
+ if (!vk) {
+ | evcmpgtu cr0, TMP1, TISNUM
+ | evcmpgtu cr7, TMP3, TISNUM
+ | evcmpgtu cr1, TMP2, TISNUM
+ | cror 4*cr0+lt, 4*cr0+lt, 4*cr7+lt
+ | cror 4*cr0+lt, 4*cr0+lt, 4*cr1+lt
+ | blt ->vmeta_for
+ }
+ if (vk) {
+ | efdadd TMP1, TMP1, TMP3
+ | evstdd TMP1, FORL_IDX*8(RA)
+ }
+ | evcmpgts TMP3, TISNIL
+ | evstdd TMP1, FORL_EXT*8(RA)
+ | bge >2
+ | efdcmpgt TMP1, TMP2
+ |1:
+ if (op != BC_JFORL) {
+ | srwi RD, RD, 1
+ | add RD, PC, RD
+ if (op == BC_JFORI) {
+ | addis PC, RD, -(BCBIAS_J*4 >> 16)
+ } else {
+ | addis RD, RD, -(BCBIAS_J*4 >> 16)
+ }
+ }
+ if (op == BC_FORI) {
+ | iselgt PC, RD, PC
+ } else if (op == BC_IFORL) {
+ | iselgt PC, PC, RD
+ } else {
+ | ble =>BC_JLOOP
+ }
+ | ins_next
+ |2:
+ | efdcmpgt TMP2, TMP1
+ | b <1
+ break;
+
+ case BC_ITERL:
+ |.if JIT
+ | hotloop
+ |.endif
+ | // Fall through. Assumes BC_IITERL follows.
+ break;
+
+ case BC_JITERL:
+#if !LJ_HASJIT
+ break;
+#endif
+ case BC_IITERL:
+ | // RA = base*8, RD = target
+ | evlddx TMP1, BASE, RA
+ | subi RA, RA, 8
+ | checknil TMP1
+ | checkok >1 // Stop if iterator returned nil.
+ if (op == BC_JITERL) {
+ | NYI
+ } else {
+ | branch_RD // Otherwise save control var + branch.
+ | evstddx TMP1, BASE, RA
+ }
+ |1:
+ | ins_next
+ break;
+
+ case BC_LOOP:
+ | // RA = base*8, RD = target (loop extent)
+ | // Note: RA/RD is only used by trace recorder to determine scope/extent
+ | // This opcode does NOT jump, it's only purpose is to detect a hot loop.
+ |.if JIT
+ | hotloop
+ |.endif
+ | // Fall through. Assumes BC_ILOOP follows.
+ break;
+
+ case BC_ILOOP:
+ | // RA = base*8, RD = target (loop extent)
+ | ins_next
+ break;
+
+ case BC_JLOOP:
+ |.if JIT
+ | NYI
+ |.endif
+ break;
+
+ case BC_JMP:
+ | // RA = base*8 (only used by trace recorder), RD = target
+ | branch_RD
+ | ins_next
+ break;
+
+ /* -- Function headers -------------------------------------------------- */
+
+ case BC_FUNCF:
+ |.if JIT
+ | hotcall
+ |.endif
+ case BC_FUNCV: /* NYI: compiled vararg functions. */
+ | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow.
+ break;
+
+ case BC_JFUNCF:
+#if !LJ_HASJIT
+ break;
+#endif
+ case BC_IFUNCF:
+ | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8
+ | lwz TMP2, L->maxstack
+ | lbz TMP1, -4+PC2PROTO(numparams)(PC)
+ | lwz KBASE, -4+PC2PROTO(k)(PC)
+ | cmplw RA, TMP2
+ | slwi TMP1, TMP1, 3
+ | bgt ->vm_growstack_l
+ | ins_next1
+ |2:
+ | cmplw NARGS8:RC, TMP1 // Check for missing parameters.
+ | ble >3
+ if (op == BC_JFUNCF) {
+ | NYI
+ } else {
+ | ins_next2
+ }
+ |
+ |3: // Clear missing parameters.
+ | evstddx TISNIL, BASE, NARGS8:RC
+ | addi NARGS8:RC, NARGS8:RC, 8
+ | b <2
+ break;
+
+ case BC_JFUNCV:
+#if !LJ_HASJIT
+ break;
+#endif
+ | NYI // NYI: compiled vararg functions
+ break; /* NYI: compiled vararg functions. */
+
+ case BC_IFUNCV:
+ | // BASE = new base, RA = BASE+framesize*8, RB = LFUNC, RC = nargs*8
+ | lwz TMP2, L->maxstack
+ | add TMP1, BASE, RC
+ | add TMP0, RA, RC
+ | stw LFUNC:RB, 4(TMP1) // Store copy of LFUNC.
+ | addi TMP3, RC, 8+FRAME_VARG
+ | lwz KBASE, -4+PC2PROTO(k)(PC)
+ | cmplw TMP0, TMP2
+ | stw TMP3, 0(TMP1) // Store delta + FRAME_VARG.
+ | bge ->vm_growstack_l
+ | lbz TMP2, -4+PC2PROTO(numparams)(PC)
+ | mr RA, BASE
+ | mr RC, TMP1
+ | ins_next1
+ | cmpwi TMP2, 0
+ | addi BASE, TMP1, 8
+ | beq >3
+ |1:
+ | cmplw RA, RC // Less args than parameters?
+ | evldd TMP0, 0(RA)
+ | bge >4
+ | evstdd TISNIL, 0(RA) // Clear old fixarg slot (help the GC).
+ | addi RA, RA, 8
+ |2:
+ | addic. TMP2, TMP2, -1
+ | evstdd TMP0, 8(TMP1)
+ | addi TMP1, TMP1, 8
+ | bne <1
+ |3:
+ | ins_next2
+ |
+ |4: // Clear missing parameters.
+ | evmr TMP0, TISNIL
+ | b <2
+ break;
+
+ case BC_FUNCC:
+ case BC_FUNCCW:
+ | // BASE = new base, RA = BASE+framesize*8, RB = CFUNC, RC = nargs*8
+ if (op == BC_FUNCC) {
+ | lwz TMP3, CFUNC:RB->f
+ } else {
+ | lwz TMP3, DISPATCH_GL(wrapf)(DISPATCH)
+ }
+ | add TMP1, RA, NARGS8:RC
+ | lwz TMP2, L->maxstack
+ | add RC, BASE, NARGS8:RC
+ | stw BASE, L->base
+ | cmplw TMP1, TMP2
+ | stw RC, L->top
+ | li_vmstate C
+ | mtctr TMP3
+ if (op == BC_FUNCCW) {
+ | lwz CARG2, CFUNC:RB->f
+ }
+ | mr CARG1, L
+ | bgt ->vm_growstack_c // Need to grow stack.
+ | st_vmstate
+ | bctrl // (lua_State *L [, lua_CFunction f])
+ | // Returns nresults.
+ | lwz TMP1, L->top
+ | slwi RD, CRET1, 3
+ | lwz BASE, L->base
+ | li_vmstate INTERP
+ | lwz PC, FRAME_PC(BASE) // Fetch PC of caller.
+ | sub RA, TMP1, RD // RA = L->top - nresults*8
+ | st_vmstate
+ | b ->vm_returnc
+ break;
+
+ /* ---------------------------------------------------------------------- */
+
+ default:
+ fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]);
+ exit(2);
+ break;
+ }
+}
+
+static int build_backend(BuildCtx *ctx)
+{
+ int op;
+
+ dasm_growpc(Dst, BC__MAX);
+
+ build_subroutines(ctx);
+
+ |.code_op
+ for (op = 0; op < BC__MAX; op++)
+ build_ins(ctx, (BCOp)op, op);
+
+ return BC__MAX;
+}
+
+/* Emit pseudo frame-info for all assembler functions. */
+static void emit_asm_debug(BuildCtx *ctx)
+{
+ int i;
+ switch (ctx->mode) {
+ case BUILD_elfasm:
+ fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n");
+ fprintf(ctx->fp,
+ ".Lframe0:\n"
+ "\t.long .LECIE0-.LSCIE0\n"
+ ".LSCIE0:\n"
+ "\t.long 0xffffffff\n"
+ "\t.byte 0x1\n"
+ "\t.string \"\"\n"
+ "\t.uleb128 0x1\n"
+ "\t.sleb128 -4\n"
+ "\t.byte 65\n"
+ "\t.byte 0xc\n\t.uleb128 1\n\t.uleb128 0\n"
+ "\t.align 2\n"
+ ".LECIE0:\n\n");
+ fprintf(ctx->fp,
+ ".LSFDE0:\n"
+ "\t.long .LEFDE0-.LASFDE0\n"
+ ".LASFDE0:\n"
+ "\t.long .Lframe0\n"
+ "\t.long .Lbegin\n"
+ "\t.long %d\n"
+ "\t.byte 0xe\n\t.uleb128 %d\n"
+ "\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n"
+ "\t.byte 0x5\n\t.uleb128 70\n\t.sleb128 37\n",
+ (int)ctx->codesz, CFRAME_SIZE);
+ for (i = 14; i <= 31; i++)
+ fprintf(ctx->fp,
+ "\t.byte %d\n\t.uleb128 %d\n"
+ "\t.byte 5\n\t.uleb128 %d\n\t.uleb128 %d\n",
+ 0x80+i, 1+2*(31-i), 1200+i, 2+2*(31-i));
+ fprintf(ctx->fp,
+ "\t.align 2\n"
+ ".LEFDE0:\n\n");
+ fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@progbits\n");
+ fprintf(ctx->fp,
+ ".Lframe1:\n"
+ "\t.long .LECIE1-.LSCIE1\n"
+ ".LSCIE1:\n"
+ "\t.long 0\n"
+ "\t.byte 0x1\n"
+ "\t.string \"zPR\"\n"
+ "\t.uleb128 0x1\n"
+ "\t.sleb128 -4\n"
+ "\t.byte 65\n"
+ "\t.uleb128 6\n" /* augmentation length */
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.long lj_err_unwind_dwarf-.\n"
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.byte 0xc\n\t.uleb128 1\n\t.uleb128 0\n"
+ "\t.align 2\n"
+ ".LECIE1:\n\n");
+ fprintf(ctx->fp,
+ ".LSFDE1:\n"
+ "\t.long .LEFDE1-.LASFDE1\n"
+ ".LASFDE1:\n"
+ "\t.long .LASFDE1-.Lframe1\n"
+ "\t.long .Lbegin-.\n"
+ "\t.long %d\n"
+ "\t.uleb128 0\n" /* augmentation length */
+ "\t.byte 0xe\n\t.uleb128 %d\n"
+ "\t.byte 0x11\n\t.uleb128 65\n\t.sleb128 -1\n"
+ "\t.byte 0x5\n\t.uleb128 70\n\t.sleb128 37\n",
+ (int)ctx->codesz, CFRAME_SIZE);
+ for (i = 14; i <= 31; i++)
+ fprintf(ctx->fp,
+ "\t.byte %d\n\t.uleb128 %d\n"
+ "\t.byte 5\n\t.uleb128 %d\n\t.uleb128 %d\n",
+ 0x80+i, 1+2*(31-i), 1200+i, 2+2*(31-i));
+ fprintf(ctx->fp,
+ "\t.align 2\n"
+ ".LEFDE1:\n\n");
+ break;
+ default:
+ break;
+ }
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/vm_x86.dasc b/src/3rdparty/LuaJIT-2.0.5/src/vm_x86.dasc
new file mode 100644
index 0000000..359ad4f
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/vm_x86.dasc
@@ -0,0 +1,6401 @@
+|// Low-level VM code for x86 CPUs.
+|// Bytecode interpreter, fast functions and helper functions.
+|// Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
+|
+|.if P64
+|.arch x64
+|.else
+|.arch x86
+|.endif
+|.section code_op, code_sub
+|
+|.actionlist build_actionlist
+|.globals GLOB_
+|.globalnames globnames
+|.externnames extnames
+|
+|//-----------------------------------------------------------------------
+|
+|.if P64
+|.define X64, 1
+|.define SSE, 1
+|.if WIN
+|.define X64WIN, 1
+|.endif
+|.endif
+|
+|// Fixed register assignments for the interpreter.
+|// This is very fragile and has many dependencies. Caveat emptor.
+|.define BASE, edx // Not C callee-save, refetched anyway.
+|.if not X64
+|.define KBASE, edi // Must be C callee-save.
+|.define KBASEa, KBASE
+|.define PC, esi // Must be C callee-save.
+|.define PCa, PC
+|.define DISPATCH, ebx // Must be C callee-save.
+|.elif X64WIN
+|.define KBASE, edi // Must be C callee-save.
+|.define KBASEa, rdi
+|.define PC, esi // Must be C callee-save.
+|.define PCa, rsi
+|.define DISPATCH, ebx // Must be C callee-save.
+|.else
+|.define KBASE, r15d // Must be C callee-save.
+|.define KBASEa, r15
+|.define PC, ebx // Must be C callee-save.
+|.define PCa, rbx
+|.define DISPATCH, r14d // Must be C callee-save.
+|.endif
+|
+|.define RA, ecx
+|.define RAH, ch
+|.define RAL, cl
+|.define RB, ebp // Must be ebp (C callee-save).
+|.define RC, eax // Must be eax.
+|.define RCW, ax
+|.define RCH, ah
+|.define RCL, al
+|.define OP, RB
+|.define RD, RC
+|.define RDW, RCW
+|.define RDL, RCL
+|.if X64
+|.define RAa, rcx
+|.define RBa, rbp
+|.define RCa, rax
+|.define RDa, rax
+|.else
+|.define RAa, RA
+|.define RBa, RB
+|.define RCa, RC
+|.define RDa, RD
+|.endif
+|
+|.if not X64
+|.define FCARG1, ecx // x86 fastcall arguments.
+|.define FCARG2, edx
+|.elif X64WIN
+|.define CARG1, rcx // x64/WIN64 C call arguments.
+|.define CARG2, rdx
+|.define CARG3, r8
+|.define CARG4, r9
+|.define CARG1d, ecx
+|.define CARG2d, edx
+|.define CARG3d, r8d
+|.define CARG4d, r9d
+|.define FCARG1, CARG1d // Upwards compatible to x86 fastcall.
+|.define FCARG2, CARG2d
+|.else
+|.define CARG1, rdi // x64/POSIX C call arguments.
+|.define CARG2, rsi
+|.define CARG3, rdx
+|.define CARG4, rcx
+|.define CARG5, r8
+|.define CARG6, r9
+|.define CARG1d, edi
+|.define CARG2d, esi
+|.define CARG3d, edx
+|.define CARG4d, ecx
+|.define CARG5d, r8d
+|.define CARG6d, r9d
+|.define FCARG1, CARG1d // Simulate x86 fastcall.
+|.define FCARG2, CARG2d
+|.endif
+|
+|// Type definitions. Some of these are only used for documentation.
+|.type L, lua_State
+|.type GL, global_State
+|.type TVALUE, TValue
+|.type GCOBJ, GCobj
+|.type STR, GCstr
+|.type TAB, GCtab
+|.type LFUNC, GCfuncL
+|.type CFUNC, GCfuncC
+|.type PROTO, GCproto
+|.type UPVAL, GCupval
+|.type NODE, Node
+|.type NARGS, int
+|.type TRACE, GCtrace
+|
+|// Stack layout while in interpreter. Must match with lj_frame.h.
+|//-----------------------------------------------------------------------
+|.if not X64 // x86 stack layout.
+|
+|.define CFRAME_SPACE, aword*7 // Delta for esp (see <--).
+|.macro saveregs_
+| push edi; push esi; push ebx
+| sub esp, CFRAME_SPACE
+|.endmacro
+|.macro saveregs
+| push ebp; saveregs_
+|.endmacro
+|.macro restoreregs
+| add esp, CFRAME_SPACE
+| pop ebx; pop esi; pop edi; pop ebp
+|.endmacro
+|
+|.define SAVE_ERRF, aword [esp+aword*15] // vm_pcall/vm_cpcall only.
+|.define SAVE_NRES, aword [esp+aword*14]
+|.define SAVE_CFRAME, aword [esp+aword*13]
+|.define SAVE_L, aword [esp+aword*12]
+|//----- 16 byte aligned, ^^^ arguments from C caller
+|.define SAVE_RET, aword [esp+aword*11] //<-- esp entering interpreter.
+|.define SAVE_R4, aword [esp+aword*10]
+|.define SAVE_R3, aword [esp+aword*9]
+|.define SAVE_R2, aword [esp+aword*8]
+|//----- 16 byte aligned
+|.define SAVE_R1, aword [esp+aword*7] //<-- esp after register saves.
+|.define SAVE_PC, aword [esp+aword*6]
+|.define TMP2, aword [esp+aword*5]
+|.define TMP1, aword [esp+aword*4]
+|//----- 16 byte aligned
+|.define ARG4, aword [esp+aword*3]
+|.define ARG3, aword [esp+aword*2]
+|.define ARG2, aword [esp+aword*1]
+|.define ARG1, aword [esp] //<-- esp while in interpreter.
+|//----- 16 byte aligned, ^^^ arguments for C callee
+|
+|// FPARGx overlaps ARGx and ARG(x+1) on x86.
+|.define FPARG3, qword [esp+qword*1]
+|.define FPARG1, qword [esp]
+|// TMPQ overlaps TMP1/TMP2. ARG5/MULTRES overlap TMP1/TMP2 (and TMPQ).
+|.define TMPQ, qword [esp+aword*4]
+|.define TMP3, ARG4
+|.define ARG5, TMP1
+|.define TMPa, TMP1
+|.define MULTRES, TMP2
+|
+|// Arguments for vm_call and vm_pcall.
+|.define INARG_BASE, SAVE_CFRAME // Overwritten by SAVE_CFRAME!
+|
+|// Arguments for vm_cpcall.
+|.define INARG_CP_CALL, SAVE_ERRF
+|.define INARG_CP_UD, SAVE_NRES
+|.define INARG_CP_FUNC, SAVE_CFRAME
+|
+|//-----------------------------------------------------------------------
+|.elif X64WIN // x64/Windows stack layout
+|
+|.define CFRAME_SPACE, aword*5 // Delta for rsp (see <--).
+|.macro saveregs_
+| push rdi; push rsi; push rbx
+| sub rsp, CFRAME_SPACE
+|.endmacro
+|.macro saveregs
+| push rbp; saveregs_
+|.endmacro
+|.macro restoreregs
+| add rsp, CFRAME_SPACE
+| pop rbx; pop rsi; pop rdi; pop rbp
+|.endmacro
+|
+|.define SAVE_CFRAME, aword [rsp+aword*13]
+|.define SAVE_PC, dword [rsp+dword*25]
+|.define SAVE_L, dword [rsp+dword*24]
+|.define SAVE_ERRF, dword [rsp+dword*23]
+|.define SAVE_NRES, dword [rsp+dword*22]
+|.define TMP2, dword [rsp+dword*21]
+|.define TMP1, dword [rsp+dword*20]
+|//----- 16 byte aligned, ^^^ 32 byte register save area, owned by interpreter
+|.define SAVE_RET, aword [rsp+aword*9] //<-- rsp entering interpreter.
+|.define SAVE_R4, aword [rsp+aword*8]
+|.define SAVE_R3, aword [rsp+aword*7]
+|.define SAVE_R2, aword [rsp+aword*6]
+|.define SAVE_R1, aword [rsp+aword*5] //<-- rsp after register saves.
+|.define ARG5, aword [rsp+aword*4]
+|.define CSAVE_4, aword [rsp+aword*3]
+|.define CSAVE_3, aword [rsp+aword*2]
+|.define CSAVE_2, aword [rsp+aword*1]
+|.define CSAVE_1, aword [rsp] //<-- rsp while in interpreter.
+|//----- 16 byte aligned, ^^^ 32 byte register save area, owned by callee
+|
+|// TMPQ overlaps TMP1/TMP2. MULTRES overlaps TMP2 (and TMPQ).
+|.define TMPQ, qword [rsp+aword*10]
+|.define MULTRES, TMP2
+|.define TMPa, ARG5
+|.define ARG5d, dword [rsp+aword*4]
+|.define TMP3, ARG5d
+|
+|//-----------------------------------------------------------------------
+|.else // x64/POSIX stack layout
+|
+|.define CFRAME_SPACE, aword*5 // Delta for rsp (see <--).
+|.macro saveregs_
+| push rbx; push r15; push r14
+|.if NO_UNWIND
+| push r13; push r12
+|.endif
+| sub rsp, CFRAME_SPACE
+|.endmacro
+|.macro saveregs
+| push rbp; saveregs_
+|.endmacro
+|.macro restoreregs
+| add rsp, CFRAME_SPACE
+|.if NO_UNWIND
+| pop r12; pop r13
+|.endif
+| pop r14; pop r15; pop rbx; pop rbp
+|.endmacro
+|
+|//----- 16 byte aligned,
+|.if NO_UNWIND
+|.define SAVE_RET, aword [rsp+aword*11] //<-- rsp entering interpreter.
+|.define SAVE_R4, aword [rsp+aword*10]
+|.define SAVE_R3, aword [rsp+aword*9]
+|.define SAVE_R2, aword [rsp+aword*8]
+|.define SAVE_R1, aword [rsp+aword*7]
+|.define SAVE_RU2, aword [rsp+aword*6]
+|.define SAVE_RU1, aword [rsp+aword*5] //<-- rsp after register saves.
+|.else
+|.define SAVE_RET, aword [rsp+aword*9] //<-- rsp entering interpreter.
+|.define SAVE_R4, aword [rsp+aword*8]
+|.define SAVE_R3, aword [rsp+aword*7]
+|.define SAVE_R2, aword [rsp+aword*6]
+|.define SAVE_R1, aword [rsp+aword*5] //<-- rsp after register saves.
+|.endif
+|.define SAVE_CFRAME, aword [rsp+aword*4]
+|.define SAVE_PC, dword [rsp+dword*7]
+|.define SAVE_L, dword [rsp+dword*6]
+|.define SAVE_ERRF, dword [rsp+dword*5]
+|.define SAVE_NRES, dword [rsp+dword*4]
+|.define TMPa, aword [rsp+aword*1]
+|.define TMP2, dword [rsp+dword*1]
+|.define TMP1, dword [rsp] //<-- rsp while in interpreter.
+|//----- 16 byte aligned
+|
+|// TMPQ overlaps TMP1/TMP2. MULTRES overlaps TMP2 (and TMPQ).
+|.define TMPQ, qword [rsp]
+|.define TMP3, dword [rsp+aword*1]
+|.define MULTRES, TMP2
+|
+|.endif
+|
+|//-----------------------------------------------------------------------
+|
+|// Instruction headers.
+|.macro ins_A; .endmacro
+|.macro ins_AD; .endmacro
+|.macro ins_AJ; .endmacro
+|.macro ins_ABC; movzx RB, RCH; movzx RC, RCL; .endmacro
+|.macro ins_AB_; movzx RB, RCH; .endmacro
+|.macro ins_A_C; movzx RC, RCL; .endmacro
+|.macro ins_AND; not RDa; .endmacro
+|
+|// Instruction decode+dispatch. Carefully tuned (nope, lodsd is not faster).
+|.macro ins_NEXT
+| mov RC, [PC]
+| movzx RA, RCH
+| movzx OP, RCL
+| add PC, 4
+| shr RC, 16
+|.if X64
+| jmp aword [DISPATCH+OP*8]
+|.else
+| jmp aword [DISPATCH+OP*4]
+|.endif
+|.endmacro
+|
+|// Instruction footer.
+|.if 1
+| // Replicated dispatch. Less unpredictable branches, but higher I-Cache use.
+| .define ins_next, ins_NEXT
+| .define ins_next_, ins_NEXT
+|.else
+| // Common dispatch. Lower I-Cache use, only one (very) unpredictable branch.
+| // Affects only certain kinds of benchmarks (and only with -j off).
+| // Around 10%-30% slower on Core2, a lot more slower on P4.
+| .macro ins_next
+| jmp ->ins_next
+| .endmacro
+| .macro ins_next_
+| ->ins_next:
+| ins_NEXT
+| .endmacro
+|.endif
+|
+|// Call decode and dispatch.
+|.macro ins_callt
+| // BASE = new base, RB = LFUNC, RD = nargs+1, [BASE-4] = PC
+| mov PC, LFUNC:RB->pc
+| mov RA, [PC]
+| movzx OP, RAL
+| movzx RA, RAH
+| add PC, 4
+|.if X64
+| jmp aword [DISPATCH+OP*8]
+|.else
+| jmp aword [DISPATCH+OP*4]
+|.endif
+|.endmacro
+|
+|.macro ins_call
+| // BASE = new base, RB = LFUNC, RD = nargs+1
+| mov [BASE-4], PC
+| ins_callt
+|.endmacro
+|
+|//-----------------------------------------------------------------------
+|
+|// Macros to test operand types.
+|.macro checktp, reg, tp; cmp dword [BASE+reg*8+4], tp; .endmacro
+|.macro checknum, reg, target; checktp reg, LJ_TISNUM; jae target; .endmacro
+|.macro checkint, reg, target; checktp reg, LJ_TISNUM; jne target; .endmacro
+|.macro checkstr, reg, target; checktp reg, LJ_TSTR; jne target; .endmacro
+|.macro checktab, reg, target; checktp reg, LJ_TTAB; jne target; .endmacro
+|
+|// These operands must be used with movzx.
+|.define PC_OP, byte [PC-4]
+|.define PC_RA, byte [PC-3]
+|.define PC_RB, byte [PC-1]
+|.define PC_RC, byte [PC-2]
+|.define PC_RD, word [PC-2]
+|
+|.macro branchPC, reg
+| lea PC, [PC+reg*4-BCBIAS_J*4]
+|.endmacro
+|
+|// Assumes DISPATCH is relative to GL.
+#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field))
+#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field))
+|
+#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
+|
+|// Decrement hashed hotcount and trigger trace recorder if zero.
+|.macro hotloop, reg
+| mov reg, PC
+| shr reg, 1
+| and reg, HOTCOUNT_PCMASK
+| sub word [DISPATCH+reg+GG_DISP2HOT], HOTCOUNT_LOOP
+| jb ->vm_hotloop
+|.endmacro
+|
+|.macro hotcall, reg
+| mov reg, PC
+| shr reg, 1
+| and reg, HOTCOUNT_PCMASK
+| sub word [DISPATCH+reg+GG_DISP2HOT], HOTCOUNT_CALL
+| jb ->vm_hotcall
+|.endmacro
+|
+|// Set current VM state.
+|.macro set_vmstate, st
+| mov dword [DISPATCH+DISPATCH_GL(vmstate)], ~LJ_VMST_..st
+|.endmacro
+|
+|// x87 compares.
+|.macro fcomparepp // Compare and pop st0 >< st1.
+| fucomip st1
+| fpop
+|.endmacro
+|
+|.macro fdup; fld st0; .endmacro
+|.macro fpop1; fstp st1; .endmacro
+|
+|// Synthesize SSE FP constants.
+|.macro sseconst_abs, reg, tmp // Synthesize abs mask.
+|.if X64
+| mov64 tmp, U64x(7fffffff,ffffffff); movd reg, tmp
+|.else
+| pxor reg, reg; pcmpeqd reg, reg; psrlq reg, 1
+|.endif
+|.endmacro
+|
+|.macro sseconst_hi, reg, tmp, val // Synthesize hi-32 bit const.
+|.if X64
+| mov64 tmp, U64x(val,00000000); movd reg, tmp
+|.else
+| mov tmp, 0x .. val; movd reg, tmp; pshufd reg, reg, 0x51
+|.endif
+|.endmacro
+|
+|.macro sseconst_sign, reg, tmp // Synthesize sign mask.
+| sseconst_hi reg, tmp, 80000000
+|.endmacro
+|.macro sseconst_1, reg, tmp // Synthesize 1.0.
+| sseconst_hi reg, tmp, 3ff00000
+|.endmacro
+|.macro sseconst_m1, reg, tmp // Synthesize -1.0.
+| sseconst_hi reg, tmp, bff00000
+|.endmacro
+|.macro sseconst_2p52, reg, tmp // Synthesize 2^52.
+| sseconst_hi reg, tmp, 43300000
+|.endmacro
+|.macro sseconst_tobit, reg, tmp // Synthesize 2^52 + 2^51.
+| sseconst_hi reg, tmp, 43380000
+|.endmacro
+|
+|// Move table write barrier back. Overwrites reg.
+|.macro barrierback, tab, reg
+| and byte tab->marked, (uint8_t)~LJ_GC_BLACK // black2gray(tab)
+| mov reg, [DISPATCH+DISPATCH_GL(gc.grayagain)]
+| mov [DISPATCH+DISPATCH_GL(gc.grayagain)], tab
+| mov tab->gclist, reg
+|.endmacro
+|
+|//-----------------------------------------------------------------------
+
+/* Generate subroutines used by opcodes and other parts of the VM. */
+/* The .code_sub section should be last to help static branch prediction. */
+static void build_subroutines(BuildCtx *ctx)
+{
+ |.code_sub
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Return handling ----------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_returnp:
+ | test PC, FRAME_P
+ | jz ->cont_dispatch
+ |
+ | // Return from pcall or xpcall fast func.
+ | and PC, -8
+ | sub BASE, PC // Restore caller base.
+ | lea RAa, [RA+PC-8] // Rebase RA and prepend one result.
+ | mov PC, [BASE-4] // Fetch PC of previous frame.
+ | // Prepending may overwrite the pcall frame, so do it at the end.
+ | mov dword [BASE+RA+4], LJ_TTRUE // Prepend true to results.
+ |
+ |->vm_returnc:
+ | add RD, 1 // RD = nresults+1
+ | jz ->vm_unwind_yield
+ | mov MULTRES, RD
+ | test PC, FRAME_TYPE
+ | jz ->BC_RET_Z // Handle regular return to Lua.
+ |
+ |->vm_return:
+ | // BASE = base, RA = resultofs, RD = nresults+1 (= MULTRES), PC = return
+ | xor PC, FRAME_C
+ | test PC, FRAME_TYPE
+ | jnz ->vm_returnp
+ |
+ | // Return to C.
+ | set_vmstate C
+ | and PC, -8
+ | sub PC, BASE
+ | neg PC // Previous base = BASE - delta.
+ |
+ | sub RD, 1
+ | jz >2
+ |1: // Move results down.
+ |.if X64
+ | mov RBa, [BASE+RA]
+ | mov [BASE-8], RBa
+ |.else
+ | mov RB, [BASE+RA]
+ | mov [BASE-8], RB
+ | mov RB, [BASE+RA+4]
+ | mov [BASE-4], RB
+ |.endif
+ | add BASE, 8
+ | sub RD, 1
+ | jnz <1
+ |2:
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, PC
+ |3:
+ | mov RD, MULTRES
+ | mov RA, SAVE_NRES // RA = wanted nresults+1
+ |4:
+ | cmp RA, RD
+ | jne >6 // More/less results wanted?
+ |5:
+ | sub BASE, 8
+ | mov L:RB->top, BASE
+ |
+ |->vm_leave_cp:
+ | mov RAa, SAVE_CFRAME // Restore previous C frame.
+ | mov L:RB->cframe, RAa
+ | xor eax, eax // Ok return status for vm_pcall.
+ |
+ |->vm_leave_unw:
+ | restoreregs
+ | ret
+ |
+ |6:
+ | jb >7 // Less results wanted?
+ | // More results wanted. Check stack size and fill up results with nil.
+ | cmp BASE, L:RB->maxstack
+ | ja >8
+ | mov dword [BASE-4], LJ_TNIL
+ | add BASE, 8
+ | add RD, 1
+ | jmp <4
+ |
+ |7: // Less results wanted.
+ | test RA, RA
+ | jz <5 // But check for LUA_MULTRET+1.
+ | sub RA, RD // Negative result!
+ | lea BASE, [BASE+RA*8] // Correct top.
+ | jmp <5
+ |
+ |8: // Corner case: need to grow stack for filling up results.
+ | // This can happen if:
+ | // - A C function grows the stack (a lot).
+ | // - The GC shrinks the stack in between.
+ | // - A return back from a lua_call() with (high) nresults adjustment.
+ | mov L:RB->top, BASE // Save current top held in BASE (yes).
+ | mov MULTRES, RD // Need to fill only remainder with nil.
+ | mov FCARG2, RA
+ | mov FCARG1, L:RB
+ | call extern lj_state_growstack@8 // (lua_State *L, int n)
+ | mov BASE, L:RB->top // Need the (realloced) L->top in BASE.
+ | jmp <3
+ |
+ |->vm_unwind_yield:
+ | mov al, LUA_YIELD
+ | jmp ->vm_unwind_c_eh
+ |
+ |->vm_unwind_c@8: // Unwind C stack, return from vm_pcall.
+ | // (void *cframe, int errcode)
+ |.if X64
+ | mov eax, CARG2d // Error return status for vm_pcall.
+ | mov rsp, CARG1
+ |.else
+ | mov eax, FCARG2 // Error return status for vm_pcall.
+ | mov esp, FCARG1
+ |.endif
+ |->vm_unwind_c_eh: // Landing pad for external unwinder.
+ | mov L:RB, SAVE_L
+ | mov GL:RB, L:RB->glref
+ | mov dword GL:RB->vmstate, ~LJ_VMST_C
+ | jmp ->vm_leave_unw
+ |
+ |->vm_unwind_rethrow:
+ |.if X64 and not X64WIN
+ | mov FCARG1, SAVE_L
+ | mov FCARG2, eax
+ | restoreregs
+ | jmp extern lj_err_throw@8 // (lua_State *L, int errcode)
+ |.endif
+ |
+ |->vm_unwind_ff@4: // Unwind C stack, return from ff pcall.
+ | // (void *cframe)
+ |.if X64
+ | and CARG1, CFRAME_RAWMASK
+ | mov rsp, CARG1
+ |.else
+ | and FCARG1, CFRAME_RAWMASK
+ | mov esp, FCARG1
+ |.endif
+ |->vm_unwind_ff_eh: // Landing pad for external unwinder.
+ | mov L:RB, SAVE_L
+ | mov RAa, -8 // Results start at BASE+RA = BASE-8.
+ | mov RD, 1+1 // Really 1+2 results, incr. later.
+ | mov BASE, L:RB->base
+ | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table.
+ | add DISPATCH, GG_G2DISP
+ | mov PC, [BASE-4] // Fetch PC of previous frame.
+ | mov dword [BASE-4], LJ_TFALSE // Prepend false to error message.
+ | set_vmstate INTERP
+ | jmp ->vm_returnc // Increments RD/MULTRES and returns.
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Grow stack for calls -----------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_growstack_c: // Grow stack for C function.
+ | mov FCARG2, LUA_MINSTACK
+ | jmp >2
+ |
+ |->vm_growstack_v: // Grow stack for vararg Lua function.
+ | sub RD, 8
+ | jmp >1
+ |
+ |->vm_growstack_f: // Grow stack for fixarg Lua function.
+ | // BASE = new base, RD = nargs+1, RB = L, PC = first PC
+ | lea RD, [BASE+NARGS:RD*8-8]
+ |1:
+ | movzx RA, byte [PC-4+PC2PROTO(framesize)]
+ | add PC, 4 // Must point after first instruction.
+ | mov L:RB->base, BASE
+ | mov L:RB->top, RD
+ | mov SAVE_PC, PC
+ | mov FCARG2, RA
+ |2:
+ | // RB = L, L->base = new base, L->top = top
+ | mov FCARG1, L:RB
+ | call extern lj_state_growstack@8 // (lua_State *L, int n)
+ | mov BASE, L:RB->base
+ | mov RD, L:RB->top
+ | mov LFUNC:RB, [BASE-8]
+ | sub RD, BASE
+ | shr RD, 3
+ | add NARGS:RD, 1
+ | // BASE = new base, RB = LFUNC, RD = nargs+1
+ | ins_callt // Just retry the call.
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Entry points into the assembler VM ---------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_resume: // Setup C frame and resume thread.
+ | // (lua_State *L, TValue *base, int nres1 = 0, ptrdiff_t ef = 0)
+ | saveregs
+ |.if X64
+ | mov L:RB, CARG1d // Caveat: CARG1d may be RA.
+ | mov SAVE_L, CARG1d
+ | mov RA, CARG2d
+ |.else
+ | mov L:RB, SAVE_L
+ | mov RA, INARG_BASE // Caveat: overlaps SAVE_CFRAME!
+ |.endif
+ | mov PC, FRAME_CP
+ | xor RD, RD
+ | lea KBASEa, [esp+CFRAME_RESUME]
+ | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table.
+ | add DISPATCH, GG_G2DISP
+ | mov L:RB->cframe, KBASEa
+ | mov SAVE_PC, RD // Any value outside of bytecode is ok.
+ | mov SAVE_CFRAME, RDa
+ |.if X64
+ | mov SAVE_NRES, RD
+ | mov SAVE_ERRF, RD
+ |.endif
+ | cmp byte L:RB->status, RDL
+ | je >3 // Initial resume (like a call).
+ |
+ | // Resume after yield (like a return).
+ | set_vmstate INTERP
+ | mov byte L:RB->status, RDL
+ | mov BASE, L:RB->base
+ | mov RD, L:RB->top
+ | sub RD, RA
+ | shr RD, 3
+ | add RD, 1 // RD = nresults+1
+ | sub RA, BASE // RA = resultofs
+ | mov PC, [BASE-4]
+ | mov MULTRES, RD
+ | test PC, FRAME_TYPE
+ | jz ->BC_RET_Z
+ | jmp ->vm_return
+ |
+ |->vm_pcall: // Setup protected C frame and enter VM.
+ | // (lua_State *L, TValue *base, int nres1, ptrdiff_t ef)
+ | saveregs
+ | mov PC, FRAME_CP
+ |.if X64
+ | mov SAVE_ERRF, CARG4d
+ |.endif
+ | jmp >1
+ |
+ |->vm_call: // Setup C frame and enter VM.
+ | // (lua_State *L, TValue *base, int nres1)
+ | saveregs
+ | mov PC, FRAME_C
+ |
+ |1: // Entry point for vm_pcall above (PC = ftype).
+ |.if X64
+ | mov SAVE_NRES, CARG3d
+ | mov L:RB, CARG1d // Caveat: CARG1d may be RA.
+ | mov SAVE_L, CARG1d
+ | mov RA, CARG2d
+ |.else
+ | mov L:RB, SAVE_L
+ | mov RA, INARG_BASE // Caveat: overlaps SAVE_CFRAME!
+ |.endif
+ |
+ | mov KBASEa, L:RB->cframe // Add our C frame to cframe chain.
+ | mov SAVE_CFRAME, KBASEa
+ | mov SAVE_PC, L:RB // Any value outside of bytecode is ok.
+ |.if X64
+ | mov L:RB->cframe, rsp
+ |.else
+ | mov L:RB->cframe, esp
+ |.endif
+ |
+ |2: // Entry point for vm_cpcall below (RA = base, RB = L, PC = ftype).
+ | mov DISPATCH, L:RB->glref // Setup pointer to dispatch table.
+ | add DISPATCH, GG_G2DISP
+ |
+ |3: // Entry point for vm_resume above (RA = base, RB = L, PC = ftype).
+ | set_vmstate INTERP
+ | mov BASE, L:RB->base // BASE = old base (used in vmeta_call).
+ | add PC, RA
+ | sub PC, BASE // PC = frame delta + frame type
+ |
+ | mov RD, L:RB->top
+ | sub RD, RA
+ | shr NARGS:RD, 3
+ | add NARGS:RD, 1 // RD = nargs+1
+ |
+ |->vm_call_dispatch:
+ | mov LFUNC:RB, [RA-8]
+ | cmp dword [RA-4], LJ_TFUNC
+ | jne ->vmeta_call // Ensure KBASE defined and != BASE.
+ |
+ |->vm_call_dispatch_f:
+ | mov BASE, RA
+ | ins_call
+ | // BASE = new base, RB = func, RD = nargs+1, PC = caller PC
+ |
+ |->vm_cpcall: // Setup protected C frame, call C.
+ | // (lua_State *L, lua_CFunction func, void *ud, lua_CPFunction cp)
+ | saveregs
+ |.if X64
+ | mov L:RB, CARG1d // Caveat: CARG1d may be RA.
+ | mov SAVE_L, CARG1d
+ |.else
+ | mov L:RB, SAVE_L
+ | // Caveat: INARG_CP_* and SAVE_CFRAME/SAVE_NRES/SAVE_ERRF overlap!
+ | mov RC, INARG_CP_UD // Get args before they are overwritten.
+ | mov RA, INARG_CP_FUNC
+ | mov BASE, INARG_CP_CALL
+ |.endif
+ | mov SAVE_PC, L:RB // Any value outside of bytecode is ok.
+ |
+ | mov KBASE, L:RB->stack // Compute -savestack(L, L->top).
+ | sub KBASE, L:RB->top
+ | mov SAVE_ERRF, 0 // No error function.
+ | mov SAVE_NRES, KBASE // Neg. delta means cframe w/o frame.
+ | // Handler may change cframe_nres(L->cframe) or cframe_errfunc(L->cframe).
+ |
+ |.if X64
+ | mov KBASEa, L:RB->cframe // Add our C frame to cframe chain.
+ | mov SAVE_CFRAME, KBASEa
+ | mov L:RB->cframe, rsp
+ |
+ | call CARG4 // (lua_State *L, lua_CFunction func, void *ud)
+ |.else
+ | mov ARG3, RC // Have to copy args downwards.
+ | mov ARG2, RA
+ | mov ARG1, L:RB
+ |
+ | mov KBASE, L:RB->cframe // Add our C frame to cframe chain.
+ | mov SAVE_CFRAME, KBASE
+ | mov L:RB->cframe, esp
+ |
+ | call BASE // (lua_State *L, lua_CFunction func, void *ud)
+ |.endif
+ | // TValue * (new base) or NULL returned in eax (RC).
+ | test RC, RC
+ | jz ->vm_leave_cp // No base? Just remove C frame.
+ | mov RA, RC
+ | mov PC, FRAME_CP
+ | jmp <2 // Else continue with the call.
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Metamethod handling ------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |//-- Continuation dispatch ----------------------------------------------
+ |
+ |->cont_dispatch:
+ | // BASE = meta base, RA = resultofs, RD = nresults+1 (also in MULTRES)
+ | add RA, BASE
+ | and PC, -8
+ | mov RB, BASE
+ | sub BASE, PC // Restore caller BASE.
+ | mov dword [RA+RD*8-4], LJ_TNIL // Ensure one valid arg.
+ | mov RC, RA // ... in [RC]
+ | mov PC, [RB-12] // Restore PC from [cont|PC].
+ |.if X64
+ | movsxd RAa, dword [RB-16] // May be negative on WIN64 with debug.
+ |.if FFI
+ | cmp RA, 1
+ | jbe >1
+ |.endif
+ | lea KBASEa, qword [=>0]
+ | add RAa, KBASEa
+ |.else
+ | mov RA, dword [RB-16]
+ |.if FFI
+ | cmp RA, 1
+ | jbe >1
+ |.endif
+ |.endif
+ | mov LFUNC:KBASE, [BASE-8]
+ | mov KBASE, LFUNC:KBASE->pc
+ | mov KBASE, [KBASE+PC2PROTO(k)]
+ | // BASE = base, RC = result, RB = meta base
+ | jmp RAa // Jump to continuation.
+ |
+ |.if FFI
+ |1:
+ | je ->cont_ffi_callback // cont = 1: return from FFI callback.
+ | // cont = 0: Tail call from C function.
+ | sub RB, BASE
+ | shr RB, 3
+ | lea RD, [RB-1]
+ | jmp ->vm_call_tail
+ |.endif
+ |
+ |->cont_cat: // BASE = base, RC = result, RB = mbase
+ | movzx RA, PC_RB
+ | sub RB, 16
+ | lea RA, [BASE+RA*8]
+ | sub RA, RB
+ | je ->cont_ra
+ | neg RA
+ | shr RA, 3
+ |.if X64WIN
+ | mov CARG3d, RA
+ | mov L:CARG1d, SAVE_L
+ | mov L:CARG1d->base, BASE
+ | mov RCa, [RC]
+ | mov [RB], RCa
+ | mov CARG2d, RB
+ |.elif X64
+ | mov L:CARG1d, SAVE_L
+ | mov L:CARG1d->base, BASE
+ | mov CARG3d, RA
+ | mov RAa, [RC]
+ | mov [RB], RAa
+ | mov CARG2d, RB
+ |.else
+ | mov ARG3, RA
+ | mov RA, [RC+4]
+ | mov RC, [RC]
+ | mov [RB+4], RA
+ | mov [RB], RC
+ | mov ARG2, RB
+ |.endif
+ | jmp ->BC_CAT_Z
+ |
+ |//-- Table indexing metamethods -----------------------------------------
+ |
+ |->vmeta_tgets:
+ | mov TMP1, RC // RC = GCstr *
+ | mov TMP2, LJ_TSTR
+ | lea RCa, TMP1 // Store temp. TValue in TMP1/TMP2.
+ | cmp PC_OP, BC_GGET
+ | jne >1
+ | lea RA, [DISPATCH+DISPATCH_GL(tmptv)] // Store fn->l.env in g->tmptv.
+ | mov [RA], TAB:RB // RB = GCtab *
+ | mov dword [RA+4], LJ_TTAB
+ | mov RB, RA
+ | jmp >2
+ |
+ |->vmeta_tgetb:
+ | movzx RC, PC_RC
+ |.if DUALNUM
+ | mov TMP2, LJ_TISNUM
+ | mov TMP1, RC
+ |.elif SSE
+ | cvtsi2sd xmm0, RC
+ | movsd TMPQ, xmm0
+ |.else
+ | mov ARG4, RC
+ | fild ARG4
+ | fstp TMPQ
+ |.endif
+ | lea RCa, TMPQ // Store temp. TValue in TMPQ.
+ | jmp >1
+ |
+ |->vmeta_tgetv:
+ | movzx RC, PC_RC // Reload TValue *k from RC.
+ | lea RC, [BASE+RC*8]
+ |1:
+ | movzx RB, PC_RB // Reload TValue *t from RB.
+ | lea RB, [BASE+RB*8]
+ |2:
+ |.if X64
+ | mov L:CARG1d, SAVE_L
+ | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE.
+ | mov CARG2d, RB
+ | mov CARG3, RCa // May be 64 bit ptr to stack.
+ | mov L:RB, L:CARG1d
+ |.else
+ | mov ARG2, RB
+ | mov L:RB, SAVE_L
+ | mov ARG3, RC
+ | mov ARG1, L:RB
+ | mov L:RB->base, BASE
+ |.endif
+ | mov SAVE_PC, PC
+ | call extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k)
+ | // TValue * (finished) or NULL (metamethod) returned in eax (RC).
+ | mov BASE, L:RB->base
+ | test RC, RC
+ | jz >3
+ |->cont_ra: // BASE = base, RC = result
+ | movzx RA, PC_RA
+ |.if X64
+ | mov RBa, [RC]
+ | mov [BASE+RA*8], RBa
+ |.else
+ | mov RB, [RC+4]
+ | mov RC, [RC]
+ | mov [BASE+RA*8+4], RB
+ | mov [BASE+RA*8], RC
+ |.endif
+ | ins_next
+ |
+ |3: // Call __index metamethod.
+ | // BASE = base, L->top = new base, stack = cont/func/t/k
+ | mov RA, L:RB->top
+ | mov [RA-12], PC // [cont|PC]
+ | lea PC, [RA+FRAME_CONT]
+ | sub PC, BASE
+ | mov LFUNC:RB, [RA-8] // Guaranteed to be a function here.
+ | mov NARGS:RD, 2+1 // 2 args for func(t, k).
+ | jmp ->vm_call_dispatch_f
+ |
+ |//-----------------------------------------------------------------------
+ |
+ |->vmeta_tsets:
+ | mov TMP1, RC // RC = GCstr *
+ | mov TMP2, LJ_TSTR
+ | lea RCa, TMP1 // Store temp. TValue in TMP1/TMP2.
+ | cmp PC_OP, BC_GSET
+ | jne >1
+ | lea RA, [DISPATCH+DISPATCH_GL(tmptv)] // Store fn->l.env in g->tmptv.
+ | mov [RA], TAB:RB // RB = GCtab *
+ | mov dword [RA+4], LJ_TTAB
+ | mov RB, RA
+ | jmp >2
+ |
+ |->vmeta_tsetb:
+ | movzx RC, PC_RC
+ |.if DUALNUM
+ | mov TMP2, LJ_TISNUM
+ | mov TMP1, RC
+ |.elif SSE
+ | cvtsi2sd xmm0, RC
+ | movsd TMPQ, xmm0
+ |.else
+ | mov ARG4, RC
+ | fild ARG4
+ | fstp TMPQ
+ |.endif
+ | lea RCa, TMPQ // Store temp. TValue in TMPQ.
+ | jmp >1
+ |
+ |->vmeta_tsetv:
+ | movzx RC, PC_RC // Reload TValue *k from RC.
+ | lea RC, [BASE+RC*8]
+ |1:
+ | movzx RB, PC_RB // Reload TValue *t from RB.
+ | lea RB, [BASE+RB*8]
+ |2:
+ |.if X64
+ | mov L:CARG1d, SAVE_L
+ | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE.
+ | mov CARG2d, RB
+ | mov CARG3, RCa // May be 64 bit ptr to stack.
+ | mov L:RB, L:CARG1d
+ |.else
+ | mov ARG2, RB
+ | mov L:RB, SAVE_L
+ | mov ARG3, RC
+ | mov ARG1, L:RB
+ | mov L:RB->base, BASE
+ |.endif
+ | mov SAVE_PC, PC
+ | call extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k)
+ | // TValue * (finished) or NULL (metamethod) returned in eax (RC).
+ | mov BASE, L:RB->base
+ | test RC, RC
+ | jz >3
+ | // NOBARRIER: lj_meta_tset ensures the table is not black.
+ | movzx RA, PC_RA
+ |.if X64
+ | mov RBa, [BASE+RA*8]
+ | mov [RC], RBa
+ |.else
+ | mov RB, [BASE+RA*8+4]
+ | mov RA, [BASE+RA*8]
+ | mov [RC+4], RB
+ | mov [RC], RA
+ |.endif
+ |->cont_nop: // BASE = base, (RC = result)
+ | ins_next
+ |
+ |3: // Call __newindex metamethod.
+ | // BASE = base, L->top = new base, stack = cont/func/t/k/(v)
+ | mov RA, L:RB->top
+ | mov [RA-12], PC // [cont|PC]
+ | movzx RC, PC_RA
+ | // Copy value to third argument.
+ |.if X64
+ | mov RBa, [BASE+RC*8]
+ | mov [RA+16], RBa
+ |.else
+ | mov RB, [BASE+RC*8+4]
+ | mov RC, [BASE+RC*8]
+ | mov [RA+20], RB
+ | mov [RA+16], RC
+ |.endif
+ | lea PC, [RA+FRAME_CONT]
+ | sub PC, BASE
+ | mov LFUNC:RB, [RA-8] // Guaranteed to be a function here.
+ | mov NARGS:RD, 3+1 // 3 args for func(t, k, v).
+ | jmp ->vm_call_dispatch_f
+ |
+ |//-- Comparison metamethods ---------------------------------------------
+ |
+ |->vmeta_comp:
+ |.if X64
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE // Caveat: CARG2d/CARG3d == BASE.
+ |.if X64WIN
+ | lea CARG3d, [BASE+RD*8]
+ | lea CARG2d, [BASE+RA*8]
+ |.else
+ | lea CARG2d, [BASE+RA*8]
+ | lea CARG3d, [BASE+RD*8]
+ |.endif
+ | mov CARG1d, L:RB // Caveat: CARG1d/CARG4d == RA.
+ | movzx CARG4d, PC_OP
+ |.else
+ | movzx RB, PC_OP
+ | lea RD, [BASE+RD*8]
+ | lea RA, [BASE+RA*8]
+ | mov ARG4, RB
+ | mov L:RB, SAVE_L
+ | mov ARG3, RD
+ | mov ARG2, RA
+ | mov ARG1, L:RB
+ | mov L:RB->base, BASE
+ |.endif
+ | mov SAVE_PC, PC
+ | call extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op)
+ | // 0/1 or TValue * (metamethod) returned in eax (RC).
+ |3:
+ | mov BASE, L:RB->base
+ | cmp RC, 1
+ | ja ->vmeta_binop
+ |4:
+ | lea PC, [PC+4]
+ | jb >6
+ |5:
+ | movzx RD, PC_RD
+ | branchPC RD
+ |6:
+ | ins_next
+ |
+ |->cont_condt: // BASE = base, RC = result
+ | add PC, 4
+ | cmp dword [RC+4], LJ_TISTRUECOND // Branch if result is true.
+ | jb <5
+ | jmp <6
+ |
+ |->cont_condf: // BASE = base, RC = result
+ | cmp dword [RC+4], LJ_TISTRUECOND // Branch if result is false.
+ | jmp <4
+ |
+ |->vmeta_equal:
+ | sub PC, 4
+ |.if X64WIN
+ | mov CARG3d, RD
+ | mov CARG4d, RB
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE // Caveat: CARG2d == BASE.
+ | mov CARG2d, RA
+ | mov CARG1d, L:RB // Caveat: CARG1d == RA.
+ |.elif X64
+ | mov CARG2d, RA
+ | mov CARG4d, RB // Caveat: CARG4d == RA.
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE // Caveat: CARG3d == BASE.
+ | mov CARG3d, RD
+ | mov CARG1d, L:RB
+ |.else
+ | mov ARG4, RB
+ | mov L:RB, SAVE_L
+ | mov ARG3, RD
+ | mov ARG2, RA
+ | mov ARG1, L:RB
+ | mov L:RB->base, BASE
+ |.endif
+ | mov SAVE_PC, PC
+ | call extern lj_meta_equal // (lua_State *L, GCobj *o1, *o2, int ne)
+ | // 0/1 or TValue * (metamethod) returned in eax (RC).
+ | jmp <3
+ |
+ |->vmeta_equal_cd:
+ |.if FFI
+ | sub PC, 4
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE
+ | mov FCARG1, L:RB
+ | mov FCARG2, dword [PC-4]
+ | mov SAVE_PC, PC
+ | call extern lj_meta_equal_cd@8 // (lua_State *L, BCIns ins)
+ | // 0/1 or TValue * (metamethod) returned in eax (RC).
+ | jmp <3
+ |.endif
+ |
+ |//-- Arithmetic metamethods ---------------------------------------------
+ |
+ |->vmeta_arith_vno:
+ |.if DUALNUM
+ | movzx RB, PC_RB
+ |.endif
+ |->vmeta_arith_vn:
+ | lea RC, [KBASE+RC*8]
+ | jmp >1
+ |
+ |->vmeta_arith_nvo:
+ |.if DUALNUM
+ | movzx RC, PC_RC
+ |.endif
+ |->vmeta_arith_nv:
+ | lea RC, [KBASE+RC*8]
+ | lea RB, [BASE+RB*8]
+ | xchg RB, RC
+ | jmp >2
+ |
+ |->vmeta_unm:
+ | lea RC, [BASE+RD*8]
+ | mov RB, RC
+ | jmp >2
+ |
+ |->vmeta_arith_vvo:
+ |.if DUALNUM
+ | movzx RB, PC_RB
+ |.endif
+ |->vmeta_arith_vv:
+ | lea RC, [BASE+RC*8]
+ |1:
+ | lea RB, [BASE+RB*8]
+ |2:
+ | lea RA, [BASE+RA*8]
+ |.if X64WIN
+ | mov CARG3d, RB
+ | mov CARG4d, RC
+ | movzx RC, PC_OP
+ | mov ARG5d, RC
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE // Caveat: CARG2d == BASE.
+ | mov CARG2d, RA
+ | mov CARG1d, L:RB // Caveat: CARG1d == RA.
+ |.elif X64
+ | movzx CARG5d, PC_OP
+ | mov CARG2d, RA
+ | mov CARG4d, RC // Caveat: CARG4d == RA.
+ | mov L:CARG1d, SAVE_L
+ | mov L:CARG1d->base, BASE // Caveat: CARG3d == BASE.
+ | mov CARG3d, RB
+ | mov L:RB, L:CARG1d
+ |.else
+ | mov ARG3, RB
+ | mov L:RB, SAVE_L
+ | mov ARG4, RC
+ | movzx RC, PC_OP
+ | mov ARG2, RA
+ | mov ARG5, RC
+ | mov ARG1, L:RB
+ | mov L:RB->base, BASE
+ |.endif
+ | mov SAVE_PC, PC
+ | call extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)
+ | // NULL (finished) or TValue * (metamethod) returned in eax (RC).
+ | mov BASE, L:RB->base
+ | test RC, RC
+ | jz ->cont_nop
+ |
+ | // Call metamethod for binary op.
+ |->vmeta_binop:
+ | // BASE = base, RC = new base, stack = cont/func/o1/o2
+ | mov RA, RC
+ | sub RC, BASE
+ | mov [RA-12], PC // [cont|PC]
+ | lea PC, [RC+FRAME_CONT]
+ | mov NARGS:RD, 2+1 // 2 args for func(o1, o2).
+ | jmp ->vm_call_dispatch
+ |
+ |->vmeta_len:
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE
+ | lea FCARG2, [BASE+RD*8] // Caveat: FCARG2 == BASE
+ | mov L:FCARG1, L:RB
+ | mov SAVE_PC, PC
+ | call extern lj_meta_len@8 // (lua_State *L, TValue *o)
+ | // NULL (retry) or TValue * (metamethod) returned in eax (RC).
+ | mov BASE, L:RB->base
+#if LJ_52
+ | test RC, RC
+ | jne ->vmeta_binop // Binop call for compatibility.
+ | movzx RD, PC_RD
+ | mov TAB:FCARG1, [BASE+RD*8]
+ | jmp ->BC_LEN_Z
+#else
+ | jmp ->vmeta_binop // Binop call for compatibility.
+#endif
+ |
+ |//-- Call metamethod ----------------------------------------------------
+ |
+ |->vmeta_call_ra:
+ | lea RA, [BASE+RA*8+8]
+ |->vmeta_call: // Resolve and call __call metamethod.
+ | // BASE = old base, RA = new base, RC = nargs+1, PC = return
+ | mov TMP2, RA // Save RA, RC for us.
+ | mov TMP1, NARGS:RD
+ | sub RA, 8
+ |.if X64
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE // Caveat: CARG2d/CARG3d may be BASE.
+ | mov CARG2d, RA
+ | lea CARG3d, [RA+NARGS:RD*8]
+ | mov CARG1d, L:RB // Caveat: CARG1d may be RA.
+ |.else
+ | lea RC, [RA+NARGS:RD*8]
+ | mov L:RB, SAVE_L
+ | mov ARG2, RA
+ | mov ARG3, RC
+ | mov ARG1, L:RB
+ | mov L:RB->base, BASE // This is the callers base!
+ |.endif
+ | mov SAVE_PC, PC
+ | call extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
+ | mov BASE, L:RB->base
+ | mov RA, TMP2
+ | mov NARGS:RD, TMP1
+ | mov LFUNC:RB, [RA-8]
+ | add NARGS:RD, 1
+ | // This is fragile. L->base must not move, KBASE must always be defined.
+ | cmp KBASE, BASE // Continue with CALLT if flag set.
+ | je ->BC_CALLT_Z
+ | mov BASE, RA
+ | ins_call // Otherwise call resolved metamethod.
+ |
+ |//-- Argument coercion for 'for' statement ------------------------------
+ |
+ |->vmeta_for:
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE
+ | mov FCARG2, RA // Caveat: FCARG2 == BASE
+ | mov L:FCARG1, L:RB // Caveat: FCARG1 == RA
+ | mov SAVE_PC, PC
+ | call extern lj_meta_for@8 // (lua_State *L, TValue *base)
+ | mov BASE, L:RB->base
+ | mov RC, [PC-4]
+ | movzx RA, RCH
+ | movzx OP, RCL
+ | shr RC, 16
+ |.if X64
+ | jmp aword [DISPATCH+OP*8+GG_DISP2STATIC] // Retry FORI or JFORI.
+ |.else
+ | jmp aword [DISPATCH+OP*4+GG_DISP2STATIC] // Retry FORI or JFORI.
+ |.endif
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Fast functions -----------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |.macro .ffunc, name
+ |->ff_ .. name:
+ |.endmacro
+ |
+ |.macro .ffunc_1, name
+ |->ff_ .. name:
+ | cmp NARGS:RD, 1+1; jb ->fff_fallback
+ |.endmacro
+ |
+ |.macro .ffunc_2, name
+ |->ff_ .. name:
+ | cmp NARGS:RD, 2+1; jb ->fff_fallback
+ |.endmacro
+ |
+ |.macro .ffunc_n, name
+ | .ffunc_1 name
+ | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
+ | fld qword [BASE]
+ |.endmacro
+ |
+ |.macro .ffunc_n, name, op
+ | .ffunc_1 name
+ | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
+ | op
+ | fld qword [BASE]
+ |.endmacro
+ |
+ |.macro .ffunc_nsse, name, op
+ | .ffunc_1 name
+ | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
+ | op xmm0, qword [BASE]
+ |.endmacro
+ |
+ |.macro .ffunc_nsse, name
+ | .ffunc_nsse name, movsd
+ |.endmacro
+ |
+ |.macro .ffunc_nn, name
+ | .ffunc_2 name
+ | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
+ | cmp dword [BASE+12], LJ_TISNUM; jae ->fff_fallback
+ | fld qword [BASE]
+ | fld qword [BASE+8]
+ |.endmacro
+ |
+ |.macro .ffunc_nnsse, name
+ | .ffunc_2 name
+ | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
+ | cmp dword [BASE+12], LJ_TISNUM; jae ->fff_fallback
+ | movsd xmm0, qword [BASE]
+ | movsd xmm1, qword [BASE+8]
+ |.endmacro
+ |
+ |.macro .ffunc_nnr, name
+ | .ffunc_2 name
+ | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
+ | cmp dword [BASE+12], LJ_TISNUM; jae ->fff_fallback
+ | fld qword [BASE+8]
+ | fld qword [BASE]
+ |.endmacro
+ |
+ |// Inlined GC threshold check. Caveat: uses label 1.
+ |.macro ffgccheck
+ | mov RB, [DISPATCH+DISPATCH_GL(gc.total)]
+ | cmp RB, [DISPATCH+DISPATCH_GL(gc.threshold)]
+ | jb >1
+ | call ->fff_gcstep
+ |1:
+ |.endmacro
+ |
+ |//-- Base library: checks -----------------------------------------------
+ |
+ |.ffunc_1 assert
+ | mov RB, [BASE+4]
+ | cmp RB, LJ_TISTRUECOND; jae ->fff_fallback
+ | mov PC, [BASE-4]
+ | mov MULTRES, RD
+ | mov [BASE-4], RB
+ | mov RB, [BASE]
+ | mov [BASE-8], RB
+ | sub RD, 2
+ | jz >2
+ | mov RA, BASE
+ |1:
+ | add RA, 8
+ |.if X64
+ | mov RBa, [RA]
+ | mov [RA-8], RBa
+ |.else
+ | mov RB, [RA+4]
+ | mov [RA-4], RB
+ | mov RB, [RA]
+ | mov [RA-8], RB
+ |.endif
+ | sub RD, 1
+ | jnz <1
+ |2:
+ | mov RD, MULTRES
+ | jmp ->fff_res_
+ |
+ |.ffunc_1 type
+ | mov RB, [BASE+4]
+ |.if X64
+ | mov RA, RB
+ | sar RA, 15
+ | cmp RA, -2
+ | je >3
+ |.endif
+ | mov RC, ~LJ_TNUMX
+ | not RB
+ | cmp RC, RB
+ | cmova RC, RB
+ |2:
+ | mov CFUNC:RB, [BASE-8]
+ | mov STR:RC, [CFUNC:RB+RC*8+((char *)(&((GCfuncC *)0)->upvalue))]
+ | mov PC, [BASE-4]
+ | mov dword [BASE-4], LJ_TSTR
+ | mov [BASE-8], STR:RC
+ | jmp ->fff_res1
+ |.if X64
+ |3:
+ | mov RC, ~LJ_TLIGHTUD
+ | jmp <2
+ |.endif
+ |
+ |//-- Base library: getters and setters ---------------------------------
+ |
+ |.ffunc_1 getmetatable
+ | mov RB, [BASE+4]
+ | mov PC, [BASE-4]
+ | cmp RB, LJ_TTAB; jne >6
+ |1: // Field metatable must be at same offset for GCtab and GCudata!
+ | mov TAB:RB, [BASE]
+ | mov TAB:RB, TAB:RB->metatable
+ |2:
+ | test TAB:RB, TAB:RB
+ | mov dword [BASE-4], LJ_TNIL
+ | jz ->fff_res1
+ | mov STR:RC, [DISPATCH+DISPATCH_GL(gcroot)+4*(GCROOT_MMNAME+MM_metatable)]
+ | mov dword [BASE-4], LJ_TTAB // Store metatable as default result.
+ | mov [BASE-8], TAB:RB
+ | mov RA, TAB:RB->hmask
+ | and RA, STR:RC->hash
+ | imul RA, #NODE
+ | add NODE:RA, TAB:RB->node
+ |3: // Rearranged logic, because we expect _not_ to find the key.
+ | cmp dword NODE:RA->key.it, LJ_TSTR
+ | jne >4
+ | cmp dword NODE:RA->key.gcr, STR:RC
+ | je >5
+ |4:
+ | mov NODE:RA, NODE:RA->next
+ | test NODE:RA, NODE:RA
+ | jnz <3
+ | jmp ->fff_res1 // Not found, keep default result.
+ |5:
+ | mov RB, [RA+4]
+ | cmp RB, LJ_TNIL; je ->fff_res1 // Ditto for nil value.
+ | mov RC, [RA]
+ | mov [BASE-4], RB // Return value of mt.__metatable.
+ | mov [BASE-8], RC
+ | jmp ->fff_res1
+ |
+ |6:
+ | cmp RB, LJ_TUDATA; je <1
+ |.if X64
+ | cmp RB, LJ_TNUMX; ja >8
+ | cmp RB, LJ_TISNUM; jbe >7
+ | mov RB, LJ_TLIGHTUD
+ | jmp >8
+ |7:
+ |.else
+ | cmp RB, LJ_TISNUM; ja >8
+ |.endif
+ | mov RB, LJ_TNUMX
+ |8:
+ | not RB
+ | mov TAB:RB, [DISPATCH+RB*4+DISPATCH_GL(gcroot[GCROOT_BASEMT])]
+ | jmp <2
+ |
+ |.ffunc_2 setmetatable
+ | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
+ | // Fast path: no mt for table yet and not clearing the mt.
+ | mov TAB:RB, [BASE]
+ | cmp dword TAB:RB->metatable, 0; jne ->fff_fallback
+ | cmp dword [BASE+12], LJ_TTAB; jne ->fff_fallback
+ | mov TAB:RC, [BASE+8]
+ | mov TAB:RB->metatable, TAB:RC
+ | mov PC, [BASE-4]
+ | mov dword [BASE-4], LJ_TTAB // Return original table.
+ | mov [BASE-8], TAB:RB
+ | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table)
+ | jz >1
+ | // Possible write barrier. Table is black, but skip iswhite(mt) check.
+ | barrierback TAB:RB, RC
+ |1:
+ | jmp ->fff_res1
+ |
+ |.ffunc_2 rawget
+ | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
+ |.if X64WIN
+ | mov RB, BASE // Save BASE.
+ | lea CARG3d, [BASE+8]
+ | mov CARG2d, [BASE] // Caveat: CARG2d == BASE.
+ | mov CARG1d, SAVE_L
+ |.elif X64
+ | mov RB, BASE // Save BASE.
+ | mov CARG2d, [BASE]
+ | lea CARG3d, [BASE+8] // Caveat: CARG3d == BASE.
+ | mov CARG1d, SAVE_L
+ |.else
+ | mov TAB:RD, [BASE]
+ | mov L:RB, SAVE_L
+ | mov ARG2, TAB:RD
+ | mov ARG1, L:RB
+ | mov RB, BASE // Save BASE.
+ | add BASE, 8
+ | mov ARG3, BASE
+ |.endif
+ | call extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key)
+ | // cTValue * returned in eax (RD).
+ | mov BASE, RB // Restore BASE.
+ | // Copy table slot.
+ |.if X64
+ | mov RBa, [RD]
+ | mov PC, [BASE-4]
+ | mov [BASE-8], RBa
+ |.else
+ | mov RB, [RD]
+ | mov RD, [RD+4]
+ | mov PC, [BASE-4]
+ | mov [BASE-8], RB
+ | mov [BASE-4], RD
+ |.endif
+ | jmp ->fff_res1
+ |
+ |//-- Base library: conversions ------------------------------------------
+ |
+ |.ffunc tonumber
+ | // Only handles the number case inline (without a base argument).
+ | cmp NARGS:RD, 1+1; jne ->fff_fallback // Exactly one argument.
+ | cmp dword [BASE+4], LJ_TISNUM
+ |.if DUALNUM
+ | jne >1
+ | mov RB, dword [BASE]; jmp ->fff_resi
+ |1:
+ | ja ->fff_fallback
+ |.else
+ | jae ->fff_fallback
+ |.endif
+ |.if SSE
+ | movsd xmm0, qword [BASE]; jmp ->fff_resxmm0
+ |.else
+ | fld qword [BASE]; jmp ->fff_resn
+ |.endif
+ |
+ |.ffunc_1 tostring
+ | // Only handles the string or number case inline.
+ | mov PC, [BASE-4]
+ | cmp dword [BASE+4], LJ_TSTR; jne >3
+ | // A __tostring method in the string base metatable is ignored.
+ | mov STR:RD, [BASE]
+ |2:
+ | mov dword [BASE-4], LJ_TSTR
+ | mov [BASE-8], STR:RD
+ | jmp ->fff_res1
+ |3: // Handle numbers inline, unless a number base metatable is present.
+ | cmp dword [BASE+4], LJ_TISNUM; ja ->fff_fallback
+ | cmp dword [DISPATCH+DISPATCH_GL(gcroot[GCROOT_BASEMT_NUM])], 0
+ | jne ->fff_fallback
+ | ffgccheck // Caveat: uses label 1.
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE // Add frame since C call can throw.
+ | mov SAVE_PC, PC // Redundant (but a defined value).
+ |.if X64 and not X64WIN
+ | mov FCARG2, BASE // Otherwise: FCARG2 == BASE
+ |.endif
+ | mov L:FCARG1, L:RB
+ |.if DUALNUM
+ | call extern lj_str_fromnumber@8 // (lua_State *L, cTValue *o)
+ |.else
+ | call extern lj_str_fromnum@8 // (lua_State *L, lua_Number *np)
+ |.endif
+ | // GCstr returned in eax (RD).
+ | mov BASE, L:RB->base
+ | jmp <2
+ |
+ |//-- Base library: iterators -------------------------------------------
+ |
+ |.ffunc_1 next
+ | je >2 // Missing 2nd arg?
+ |1:
+ | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE // Add frame since C call can throw.
+ | mov L:RB->top, BASE // Dummy frame length is ok.
+ | mov PC, [BASE-4]
+ |.if X64WIN
+ | lea CARG3d, [BASE+8]
+ | mov CARG2d, [BASE] // Caveat: CARG2d == BASE.
+ | mov CARG1d, L:RB
+ |.elif X64
+ | mov CARG2d, [BASE]
+ | lea CARG3d, [BASE+8] // Caveat: CARG3d == BASE.
+ | mov CARG1d, L:RB
+ |.else
+ | mov TAB:RD, [BASE]
+ | mov ARG2, TAB:RD
+ | mov ARG1, L:RB
+ | add BASE, 8
+ | mov ARG3, BASE
+ |.endif
+ | mov SAVE_PC, PC // Needed for ITERN fallback.
+ | call extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key)
+ | // Flag returned in eax (RD).
+ | mov BASE, L:RB->base
+ | test RD, RD; jz >3 // End of traversal?
+ | // Copy key and value to results.
+ |.if X64
+ | mov RBa, [BASE+8]
+ | mov RDa, [BASE+16]
+ | mov [BASE-8], RBa
+ | mov [BASE], RDa
+ |.else
+ | mov RB, [BASE+8]
+ | mov RD, [BASE+12]
+ | mov [BASE-8], RB
+ | mov [BASE-4], RD
+ | mov RB, [BASE+16]
+ | mov RD, [BASE+20]
+ | mov [BASE], RB
+ | mov [BASE+4], RD
+ |.endif
+ |->fff_res2:
+ | mov RD, 1+2
+ | jmp ->fff_res
+ |2: // Set missing 2nd arg to nil.
+ | mov dword [BASE+12], LJ_TNIL
+ | jmp <1
+ |3: // End of traversal: return nil.
+ | mov dword [BASE-4], LJ_TNIL
+ | jmp ->fff_res1
+ |
+ |.ffunc_1 pairs
+ | mov TAB:RB, [BASE]
+ | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
+#if LJ_52
+ | cmp dword TAB:RB->metatable, 0; jne ->fff_fallback
+#endif
+ | mov CFUNC:RB, [BASE-8]
+ | mov CFUNC:RD, CFUNC:RB->upvalue[0]
+ | mov PC, [BASE-4]
+ | mov dword [BASE-4], LJ_TFUNC
+ | mov [BASE-8], CFUNC:RD
+ | mov dword [BASE+12], LJ_TNIL
+ | mov RD, 1+3
+ | jmp ->fff_res
+ |
+ |.ffunc_2 ipairs_aux
+ | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
+ | cmp dword [BASE+12], LJ_TISNUM
+ |.if DUALNUM
+ | jne ->fff_fallback
+ |.else
+ | jae ->fff_fallback
+ |.endif
+ | mov PC, [BASE-4]
+ |.if DUALNUM
+ | mov RD, dword [BASE+8]
+ | add RD, 1
+ | mov dword [BASE-4], LJ_TISNUM
+ | mov dword [BASE-8], RD
+ |.elif SSE
+ | movsd xmm0, qword [BASE+8]
+ | sseconst_1 xmm1, RBa
+ | addsd xmm0, xmm1
+ | cvtsd2si RD, xmm0
+ | movsd qword [BASE-8], xmm0
+ |.else
+ | fld qword [BASE+8]
+ | fld1
+ | faddp st1
+ | fist ARG1
+ | fstp qword [BASE-8]
+ | mov RD, ARG1
+ |.endif
+ | mov TAB:RB, [BASE]
+ | cmp RD, TAB:RB->asize; jae >2 // Not in array part?
+ | shl RD, 3
+ | add RD, TAB:RB->array
+ |1:
+ | cmp dword [RD+4], LJ_TNIL; je ->fff_res0
+ | // Copy array slot.
+ |.if X64
+ | mov RBa, [RD]
+ | mov [BASE], RBa
+ |.else
+ | mov RB, [RD]
+ | mov RD, [RD+4]
+ | mov [BASE], RB
+ | mov [BASE+4], RD
+ |.endif
+ | jmp ->fff_res2
+ |2: // Check for empty hash part first. Otherwise call C function.
+ | cmp dword TAB:RB->hmask, 0; je ->fff_res0
+ | mov FCARG1, TAB:RB
+ | mov RB, BASE // Save BASE.
+ | mov FCARG2, RD // Caveat: FCARG2 == BASE
+ | call extern lj_tab_getinth@8 // (GCtab *t, int32_t key)
+ | // cTValue * or NULL returned in eax (RD).
+ | mov BASE, RB
+ | test RD, RD
+ | jnz <1
+ |->fff_res0:
+ | mov RD, 1+0
+ | jmp ->fff_res
+ |
+ |.ffunc_1 ipairs
+ | mov TAB:RB, [BASE]
+ | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
+#if LJ_52
+ | cmp dword TAB:RB->metatable, 0; jne ->fff_fallback
+#endif
+ | mov CFUNC:RB, [BASE-8]
+ | mov CFUNC:RD, CFUNC:RB->upvalue[0]
+ | mov PC, [BASE-4]
+ | mov dword [BASE-4], LJ_TFUNC
+ | mov [BASE-8], CFUNC:RD
+ |.if DUALNUM
+ | mov dword [BASE+12], LJ_TISNUM
+ | mov dword [BASE+8], 0
+ |.elif SSE
+ | xorps xmm0, xmm0
+ | movsd qword [BASE+8], xmm0
+ |.else
+ | fldz
+ | fstp qword [BASE+8]
+ |.endif
+ | mov RD, 1+3
+ | jmp ->fff_res
+ |
+ |//-- Base library: catch errors ----------------------------------------
+ |
+ |.ffunc_1 pcall
+ | lea RA, [BASE+8]
+ | sub NARGS:RD, 1
+ | mov PC, 8+FRAME_PCALL
+ |1:
+ | movzx RB, byte [DISPATCH+DISPATCH_GL(hookmask)]
+ | shr RB, HOOK_ACTIVE_SHIFT
+ | and RB, 1
+ | add PC, RB // Remember active hook before pcall.
+ | jmp ->vm_call_dispatch
+ |
+ |.ffunc_2 xpcall
+ | cmp dword [BASE+12], LJ_TFUNC; jne ->fff_fallback
+ | mov RB, [BASE+4] // Swap function and traceback.
+ | mov [BASE+12], RB
+ | mov dword [BASE+4], LJ_TFUNC
+ | mov LFUNC:RB, [BASE]
+ | mov PC, [BASE+8]
+ | mov [BASE+8], LFUNC:RB
+ | mov [BASE], PC
+ | lea RA, [BASE+16]
+ | sub NARGS:RD, 2
+ | mov PC, 16+FRAME_PCALL
+ | jmp <1
+ |
+ |//-- Coroutine library --------------------------------------------------
+ |
+ |.macro coroutine_resume_wrap, resume
+ |.if resume
+ |.ffunc_1 coroutine_resume
+ | mov L:RB, [BASE]
+ |.else
+ |.ffunc coroutine_wrap_aux
+ | mov CFUNC:RB, [BASE-8]
+ | mov L:RB, CFUNC:RB->upvalue[0].gcr
+ |.endif
+ | mov PC, [BASE-4]
+ | mov SAVE_PC, PC
+ |.if X64
+ | mov TMP1, L:RB
+ |.else
+ | mov ARG1, L:RB
+ |.endif
+ |.if resume
+ | cmp dword [BASE+4], LJ_TTHREAD; jne ->fff_fallback
+ |.endif
+ | cmp aword L:RB->cframe, 0; jne ->fff_fallback
+ | cmp byte L:RB->status, LUA_YIELD; ja ->fff_fallback
+ | mov RA, L:RB->top
+ | je >1 // Status != LUA_YIELD (i.e. 0)?
+ | cmp RA, L:RB->base // Check for presence of initial func.
+ | je ->fff_fallback
+ |1:
+ |.if resume
+ | lea PC, [RA+NARGS:RD*8-16] // Check stack space (-1-thread).
+ |.else
+ | lea PC, [RA+NARGS:RD*8-8] // Check stack space (-1).
+ |.endif
+ | cmp PC, L:RB->maxstack; ja ->fff_fallback
+ | mov L:RB->top, PC
+ |
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE
+ |.if resume
+ | add BASE, 8 // Keep resumed thread in stack for GC.
+ |.endif
+ | mov L:RB->top, BASE
+ |.if resume
+ | lea RB, [BASE+NARGS:RD*8-24] // RB = end of source for stack move.
+ |.else
+ | lea RB, [BASE+NARGS:RD*8-16] // RB = end of source for stack move.
+ |.endif
+ | sub RBa, PCa // Relative to PC.
+ |
+ | cmp PC, RA
+ | je >3
+ |2: // Move args to coroutine.
+ |.if X64
+ | mov RCa, [PC+RB]
+ | mov [PC-8], RCa
+ |.else
+ | mov RC, [PC+RB+4]
+ | mov [PC-4], RC
+ | mov RC, [PC+RB]
+ | mov [PC-8], RC
+ |.endif
+ | sub PC, 8
+ | cmp PC, RA
+ | jne <2
+ |3:
+ |.if X64
+ | mov CARG2d, RA
+ | mov CARG1d, TMP1
+ |.else
+ | mov ARG2, RA
+ | xor RA, RA
+ | mov ARG4, RA
+ | mov ARG3, RA
+ |.endif
+ | call ->vm_resume // (lua_State *L, TValue *base, 0, 0)
+ | set_vmstate INTERP
+ |
+ | mov L:RB, SAVE_L
+ |.if X64
+ | mov L:PC, TMP1
+ |.else
+ | mov L:PC, ARG1 // The callee doesn't modify SAVE_L.
+ |.endif
+ | mov BASE, L:RB->base
+ | cmp eax, LUA_YIELD
+ | ja >8
+ |4:
+ | mov RA, L:PC->base
+ | mov KBASE, L:PC->top
+ | mov L:PC->top, RA // Clear coroutine stack.
+ | mov PC, KBASE
+ | sub PC, RA
+ | je >6 // No results?
+ | lea RD, [BASE+PC]
+ | shr PC, 3
+ | cmp RD, L:RB->maxstack
+ | ja >9 // Need to grow stack?
+ |
+ | mov RB, BASE
+ | sub RBa, RAa
+ |5: // Move results from coroutine.
+ |.if X64
+ | mov RDa, [RA]
+ | mov [RA+RB], RDa
+ |.else
+ | mov RD, [RA]
+ | mov [RA+RB], RD
+ | mov RD, [RA+4]
+ | mov [RA+RB+4], RD
+ |.endif
+ | add RA, 8
+ | cmp RA, KBASE
+ | jne <5
+ |6:
+ |.if resume
+ | lea RD, [PC+2] // nresults+1 = 1 + true + results.
+ | mov dword [BASE-4], LJ_TTRUE // Prepend true to results.
+ |.else
+ | lea RD, [PC+1] // nresults+1 = 1 + results.
+ |.endif
+ |7:
+ | mov PC, SAVE_PC
+ | mov MULTRES, RD
+ |.if resume
+ | mov RAa, -8
+ |.else
+ | xor RA, RA
+ |.endif
+ | test PC, FRAME_TYPE
+ | jz ->BC_RET_Z
+ | jmp ->vm_return
+ |
+ |8: // Coroutine returned with error (at co->top-1).
+ |.if resume
+ | mov dword [BASE-4], LJ_TFALSE // Prepend false to results.
+ | mov RA, L:PC->top
+ | sub RA, 8
+ | mov L:PC->top, RA // Clear error from coroutine stack.
+ | // Copy error message.
+ |.if X64
+ | mov RDa, [RA]
+ | mov [BASE], RDa
+ |.else
+ | mov RD, [RA]
+ | mov [BASE], RD
+ | mov RD, [RA+4]
+ | mov [BASE+4], RD
+ |.endif
+ | mov RD, 1+2 // nresults+1 = 1 + false + error.
+ | jmp <7
+ |.else
+ | mov FCARG2, L:PC
+ | mov FCARG1, L:RB
+ | call extern lj_ffh_coroutine_wrap_err@8 // (lua_State *L, lua_State *co)
+ | // Error function does not return.
+ |.endif
+ |
+ |9: // Handle stack expansion on return from yield.
+ |.if X64
+ | mov L:RA, TMP1
+ |.else
+ | mov L:RA, ARG1 // The callee doesn't modify SAVE_L.
+ |.endif
+ | mov L:RA->top, KBASE // Undo coroutine stack clearing.
+ | mov FCARG2, PC
+ | mov FCARG1, L:RB
+ | call extern lj_state_growstack@8 // (lua_State *L, int n)
+ |.if X64
+ | mov L:PC, TMP1
+ |.else
+ | mov L:PC, ARG1
+ |.endif
+ | mov BASE, L:RB->base
+ | jmp <4 // Retry the stack move.
+ |.endmacro
+ |
+ | coroutine_resume_wrap 1 // coroutine.resume
+ | coroutine_resume_wrap 0 // coroutine.wrap
+ |
+ |.ffunc coroutine_yield
+ | mov L:RB, SAVE_L
+ | test aword L:RB->cframe, CFRAME_RESUME
+ | jz ->fff_fallback
+ | mov L:RB->base, BASE
+ | lea RD, [BASE+NARGS:RD*8-8]
+ | mov L:RB->top, RD
+ | xor RD, RD
+ | mov aword L:RB->cframe, RDa
+ | mov al, LUA_YIELD
+ | mov byte L:RB->status, al
+ | jmp ->vm_leave_unw
+ |
+ |//-- Math library -------------------------------------------------------
+ |
+ |.if not DUALNUM
+ |->fff_resi: // Dummy.
+ |.endif
+ |
+ |.if SSE
+ |->fff_resn:
+ | mov PC, [BASE-4]
+ | fstp qword [BASE-8]
+ | jmp ->fff_res1
+ |.endif
+ |
+ | .ffunc_1 math_abs
+ |.if DUALNUM
+ | cmp dword [BASE+4], LJ_TISNUM; jne >2
+ | mov RB, dword [BASE]
+ | cmp RB, 0; jns ->fff_resi
+ | neg RB; js >1
+ |->fff_resbit:
+ |->fff_resi:
+ | mov PC, [BASE-4]
+ | mov dword [BASE-4], LJ_TISNUM
+ | mov dword [BASE-8], RB
+ | jmp ->fff_res1
+ |1:
+ | mov PC, [BASE-4]
+ | mov dword [BASE-4], 0x41e00000 // 2^31.
+ | mov dword [BASE-8], 0
+ | jmp ->fff_res1
+ |2:
+ | ja ->fff_fallback
+ |.else
+ | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
+ |.endif
+ |
+ |.if SSE
+ | movsd xmm0, qword [BASE]
+ | sseconst_abs xmm1, RDa
+ | andps xmm0, xmm1
+ |->fff_resxmm0:
+ | mov PC, [BASE-4]
+ | movsd qword [BASE-8], xmm0
+ | // fallthrough
+ |.else
+ | fld qword [BASE]
+ | fabs
+ | // fallthrough
+ |->fff_resxmm0: // Dummy.
+ |->fff_resn:
+ | mov PC, [BASE-4]
+ | fstp qword [BASE-8]
+ |.endif
+ |
+ |->fff_res1:
+ | mov RD, 1+1
+ |->fff_res:
+ | mov MULTRES, RD
+ |->fff_res_:
+ | test PC, FRAME_TYPE
+ | jnz >7
+ |5:
+ | cmp PC_RB, RDL // More results expected?
+ | ja >6
+ | // Adjust BASE. KBASE is assumed to be set for the calling frame.
+ | movzx RA, PC_RA
+ | not RAa // Note: ~RA = -(RA+1)
+ | lea BASE, [BASE+RA*8] // base = base - (RA+1)*8
+ | ins_next
+ |
+ |6: // Fill up results with nil.
+ | mov dword [BASE+RD*8-12], LJ_TNIL
+ | add RD, 1
+ | jmp <5
+ |
+ |7: // Non-standard return case.
+ | mov RAa, -8 // Results start at BASE+RA = BASE-8.
+ | jmp ->vm_return
+ |
+ |.macro math_round, func
+ | .ffunc math_ .. func
+ |.if DUALNUM
+ | cmp dword [BASE+4], LJ_TISNUM; jne >1
+ | mov RB, dword [BASE]; jmp ->fff_resi
+ |1:
+ | ja ->fff_fallback
+ |.else
+ | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
+ |.endif
+ |.if SSE
+ | movsd xmm0, qword [BASE]
+ | call ->vm_ .. func
+ | .if DUALNUM
+ | cvtsd2si RB, xmm0
+ | cmp RB, 0x80000000
+ | jne ->fff_resi
+ | cvtsi2sd xmm1, RB
+ | ucomisd xmm0, xmm1
+ | jp ->fff_resxmm0
+ | je ->fff_resi
+ | .endif
+ | jmp ->fff_resxmm0
+ |.else
+ | fld qword [BASE]
+ | call ->vm_ .. func
+ | .if DUALNUM
+ | fist ARG1
+ | mov RB, ARG1
+ | cmp RB, 0x80000000; jne >2
+ | fdup
+ | fild ARG1
+ | fcomparepp
+ | jp ->fff_resn
+ | jne ->fff_resn
+ |2:
+ | fpop
+ | jmp ->fff_resi
+ | .else
+ | jmp ->fff_resn
+ | .endif
+ |.endif
+ |.endmacro
+ |
+ | math_round floor
+ | math_round ceil
+ |
+ |.if SSE
+ |.ffunc_nsse math_sqrt, sqrtsd; jmp ->fff_resxmm0
+ |.else
+ |.ffunc_n math_sqrt; fsqrt; jmp ->fff_resn
+ |.endif
+ |
+ |.ffunc math_log
+ | cmp NARGS:RD, 1+1; jne ->fff_fallback // Exactly one argument.
+ | cmp dword [BASE+4], LJ_TISNUM; jae ->fff_fallback
+ | fldln2; fld qword [BASE]; fyl2x; jmp ->fff_resn
+ |
+ |.ffunc_n math_log10, fldlg2; fyl2x; jmp ->fff_resn
+ |.ffunc_n math_exp; call ->vm_exp_x87; jmp ->fff_resn
+ |
+ |.ffunc_n math_sin; fsin; jmp ->fff_resn
+ |.ffunc_n math_cos; fcos; jmp ->fff_resn
+ |.ffunc_n math_tan; fptan; fpop; jmp ->fff_resn
+ |
+ |.ffunc_n math_asin
+ | fdup; fmul st0; fld1; fsubrp st1; fsqrt; fpatan
+ | jmp ->fff_resn
+ |.ffunc_n math_acos
+ | fdup; fmul st0; fld1; fsubrp st1; fsqrt; fxch; fpatan
+ | jmp ->fff_resn
+ |.ffunc_n math_atan; fld1; fpatan; jmp ->fff_resn
+ |
+ |.macro math_extern, func
+ |.if SSE
+ | .ffunc_nsse math_ .. func
+ | .if not X64
+ | movsd FPARG1, xmm0
+ | .endif
+ |.else
+ | .ffunc_n math_ .. func
+ | fstp FPARG1
+ |.endif
+ | mov RB, BASE
+ | call extern lj_vm_ .. func
+ | mov BASE, RB
+ | .if X64
+ | jmp ->fff_resxmm0
+ | .else
+ | jmp ->fff_resn
+ | .endif
+ |.endmacro
+ |
+ | math_extern sinh
+ | math_extern cosh
+ | math_extern tanh
+ |
+ |->ff_math_deg:
+ |.if SSE
+ |.ffunc_nsse math_rad
+ | mov CFUNC:RB, [BASE-8]
+ | mulsd xmm0, qword CFUNC:RB->upvalue[0]
+ | jmp ->fff_resxmm0
+ |.else
+ |.ffunc_n math_rad
+ | mov CFUNC:RB, [BASE-8]
+ | fmul qword CFUNC:RB->upvalue[0]
+ | jmp ->fff_resn
+ |.endif
+ |
+ |.ffunc_nn math_atan2; fpatan; jmp ->fff_resn
+ |.ffunc_nnr math_ldexp; fscale; fpop1; jmp ->fff_resn
+ |
+ |.ffunc_1 math_frexp
+ | mov RB, [BASE+4]
+ | cmp RB, LJ_TISNUM; jae ->fff_fallback
+ | mov PC, [BASE-4]
+ | mov RC, [BASE]
+ | mov [BASE-4], RB; mov [BASE-8], RC
+ | shl RB, 1; cmp RB, 0xffe00000; jae >3
+ | or RC, RB; jz >3
+ | mov RC, 1022
+ | cmp RB, 0x00200000; jb >4
+ |1:
+ | shr RB, 21; sub RB, RC // Extract and unbias exponent.
+ |.if SSE
+ | cvtsi2sd xmm0, RB
+ |.else
+ | mov TMP1, RB; fild TMP1
+ |.endif
+ | mov RB, [BASE-4]
+ | and RB, 0x800fffff // Mask off exponent.
+ | or RB, 0x3fe00000 // Put mantissa in range [0.5,1) or 0.
+ | mov [BASE-4], RB
+ |2:
+ |.if SSE
+ | movsd qword [BASE], xmm0
+ |.else
+ | fstp qword [BASE]
+ |.endif
+ | mov RD, 1+2
+ | jmp ->fff_res
+ |3: // Return +-0, +-Inf, NaN unmodified and an exponent of 0.
+ |.if SSE
+ | xorps xmm0, xmm0; jmp <2
+ |.else
+ | fldz; jmp <2
+ |.endif
+ |4: // Handle denormals by multiplying with 2^54 and adjusting the bias.
+ |.if SSE
+ | movsd xmm0, qword [BASE]
+ | sseconst_hi xmm1, RBa, 43500000 // 2^54.
+ | mulsd xmm0, xmm1
+ | movsd qword [BASE-8], xmm0
+ |.else
+ | fld qword [BASE]
+ | mov TMP1, 0x5a800000; fmul TMP1 // x = x*2^54
+ | fstp qword [BASE-8]
+ |.endif
+ | mov RB, [BASE-4]; mov RC, 1076; shl RB, 1; jmp <1
+ |
+ |.if SSE
+ |.ffunc_nsse math_modf
+ |.else
+ |.ffunc_n math_modf
+ |.endif
+ | mov RB, [BASE+4]
+ | mov PC, [BASE-4]
+ | shl RB, 1; cmp RB, 0xffe00000; je >4 // +-Inf?
+ |.if SSE
+ | movaps xmm4, xmm0
+ | call ->vm_trunc
+ | subsd xmm4, xmm0
+ |1:
+ | movsd qword [BASE-8], xmm0
+ | movsd qword [BASE], xmm4
+ |.else
+ | fdup
+ | call ->vm_trunc
+ | fsub st1, st0
+ |1:
+ | fstp qword [BASE-8]
+ | fstp qword [BASE]
+ |.endif
+ | mov RC, [BASE-4]; mov RB, [BASE+4]
+ | xor RC, RB; js >3 // Need to adjust sign?
+ |2:
+ | mov RD, 1+2
+ | jmp ->fff_res
+ |3:
+ | xor RB, 0x80000000; mov [BASE+4], RB // Flip sign of fraction.
+ | jmp <2
+ |4:
+ |.if SSE
+ | xorps xmm4, xmm4; jmp <1 // Return +-Inf and +-0.
+ |.else
+ | fldz; fxch; jmp <1 // Return +-Inf and +-0.
+ |.endif
+ |
+ |.ffunc_nnr math_fmod
+ |1: ; fprem; fnstsw ax; and ax, 0x400; jnz <1
+ | fpop1
+ | jmp ->fff_resn
+ |
+ |.if SSE
+ |.ffunc_nnsse math_pow; call ->vm_pow; jmp ->fff_resxmm0
+ |.else
+ |.ffunc_nn math_pow; call ->vm_pow; jmp ->fff_resn
+ |.endif
+ |
+ |.macro math_minmax, name, cmovop, fcmovop, sseop
+ | .ffunc name
+ | mov RA, 2
+ | cmp dword [BASE+4], LJ_TISNUM
+ |.if DUALNUM
+ | jne >4
+ | mov RB, dword [BASE]
+ |1: // Handle integers.
+ | cmp RA, RD; jae ->fff_resi
+ | cmp dword [BASE+RA*8-4], LJ_TISNUM; jne >3
+ | cmp RB, dword [BASE+RA*8-8]
+ | cmovop RB, dword [BASE+RA*8-8]
+ | add RA, 1
+ | jmp <1
+ |3:
+ | ja ->fff_fallback
+ | // Convert intermediate result to number and continue below.
+ |.if SSE
+ | cvtsi2sd xmm0, RB
+ |.else
+ | mov TMP1, RB
+ | fild TMP1
+ |.endif
+ | jmp >6
+ |4:
+ | ja ->fff_fallback
+ |.else
+ | jae ->fff_fallback
+ |.endif
+ |
+ |.if SSE
+ | movsd xmm0, qword [BASE]
+ |5: // Handle numbers or integers.
+ | cmp RA, RD; jae ->fff_resxmm0
+ | cmp dword [BASE+RA*8-4], LJ_TISNUM
+ |.if DUALNUM
+ | jb >6
+ | ja ->fff_fallback
+ | cvtsi2sd xmm1, dword [BASE+RA*8-8]
+ | jmp >7
+ |.else
+ | jae ->fff_fallback
+ |.endif
+ |6:
+ | movsd xmm1, qword [BASE+RA*8-8]
+ |7:
+ | sseop xmm0, xmm1
+ | add RA, 1
+ | jmp <5
+ |.else
+ | fld qword [BASE]
+ |5: // Handle numbers or integers.
+ | cmp RA, RD; jae ->fff_resn
+ | cmp dword [BASE+RA*8-4], LJ_TISNUM
+ |.if DUALNUM
+ | jb >6
+ | ja >9
+ | fild dword [BASE+RA*8-8]
+ | jmp >7
+ |.else
+ | jae >9
+ |.endif
+ |6:
+ | fld qword [BASE+RA*8-8]
+ |7:
+ | fucomi st1; fcmovop st1; fpop1
+ | add RA, 1
+ | jmp <5
+ |.endif
+ |.endmacro
+ |
+ | math_minmax math_min, cmovg, fcmovnbe, minsd
+ | math_minmax math_max, cmovl, fcmovbe, maxsd
+ |.if not SSE
+ |9:
+ | fpop; jmp ->fff_fallback
+ |.endif
+ |
+ |//-- String library -----------------------------------------------------
+ |
+ |.ffunc_1 string_len
+ | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback
+ | mov STR:RB, [BASE]
+ |.if DUALNUM
+ | mov RB, dword STR:RB->len; jmp ->fff_resi
+ |.elif SSE
+ | cvtsi2sd xmm0, dword STR:RB->len; jmp ->fff_resxmm0
+ |.else
+ | fild dword STR:RB->len; jmp ->fff_resn
+ |.endif
+ |
+ |.ffunc string_byte // Only handle the 1-arg case here.
+ | cmp NARGS:RD, 1+1; jne ->fff_fallback
+ | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback
+ | mov STR:RB, [BASE]
+ | mov PC, [BASE-4]
+ | cmp dword STR:RB->len, 1
+ | jb ->fff_res0 // Return no results for empty string.
+ | movzx RB, byte STR:RB[1]
+ |.if DUALNUM
+ | jmp ->fff_resi
+ |.elif SSE
+ | cvtsi2sd xmm0, RB; jmp ->fff_resxmm0
+ |.else
+ | mov TMP1, RB; fild TMP1; jmp ->fff_resn
+ |.endif
+ |
+ |.ffunc string_char // Only handle the 1-arg case here.
+ | ffgccheck
+ | cmp NARGS:RD, 1+1; jne ->fff_fallback // *Exactly* 1 arg.
+ | cmp dword [BASE+4], LJ_TISNUM
+ |.if DUALNUM
+ | jne ->fff_fallback
+ | mov RB, dword [BASE]
+ | cmp RB, 255; ja ->fff_fallback
+ | mov TMP2, RB
+ |.elif SSE
+ | jae ->fff_fallback
+ | cvttsd2si RB, qword [BASE]
+ | cmp RB, 255; ja ->fff_fallback
+ | mov TMP2, RB
+ |.else
+ | jae ->fff_fallback
+ | fld qword [BASE]
+ | fistp TMP2
+ | cmp TMP2, 255; ja ->fff_fallback
+ |.endif
+ |.if X64
+ | mov TMP3, 1
+ |.else
+ | mov ARG3, 1
+ |.endif
+ | lea RDa, TMP2 // Points to stack. Little-endian.
+ |->fff_newstr:
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE
+ |.if X64
+ | mov CARG3d, TMP3 // Zero-extended to size_t.
+ | mov CARG2, RDa // May be 64 bit ptr to stack.
+ | mov CARG1d, L:RB
+ |.else
+ | mov ARG2, RD
+ | mov ARG1, L:RB
+ |.endif
+ | mov SAVE_PC, PC
+ | call extern lj_str_new // (lua_State *L, char *str, size_t l)
+ | // GCstr * returned in eax (RD).
+ | mov BASE, L:RB->base
+ | mov PC, [BASE-4]
+ | mov dword [BASE-4], LJ_TSTR
+ | mov [BASE-8], STR:RD
+ | jmp ->fff_res1
+ |
+ |.ffunc string_sub
+ | ffgccheck
+ | mov TMP2, -1
+ | cmp NARGS:RD, 1+2; jb ->fff_fallback
+ | jna >1
+ | cmp dword [BASE+20], LJ_TISNUM
+ |.if DUALNUM
+ | jne ->fff_fallback
+ | mov RB, dword [BASE+16]
+ | mov TMP2, RB
+ |.elif SSE
+ | jae ->fff_fallback
+ | cvttsd2si RB, qword [BASE+16]
+ | mov TMP2, RB
+ |.else
+ | jae ->fff_fallback
+ | fld qword [BASE+16]
+ | fistp TMP2
+ |.endif
+ |1:
+ | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback
+ | cmp dword [BASE+12], LJ_TISNUM
+ |.if DUALNUM
+ | jne ->fff_fallback
+ |.else
+ | jae ->fff_fallback
+ |.endif
+ | mov STR:RB, [BASE]
+ | mov TMP3, STR:RB
+ | mov RB, STR:RB->len
+ |.if DUALNUM
+ | mov RA, dword [BASE+8]
+ |.elif SSE
+ | cvttsd2si RA, qword [BASE+8]
+ |.else
+ | fld qword [BASE+8]
+ | fistp ARG3
+ | mov RA, ARG3
+ |.endif
+ | mov RC, TMP2
+ | cmp RB, RC // len < end? (unsigned compare)
+ | jb >5
+ |2:
+ | test RA, RA // start <= 0?
+ | jle >7
+ |3:
+ | mov STR:RB, TMP3
+ | sub RC, RA // start > end?
+ | jl ->fff_emptystr
+ | lea RB, [STR:RB+RA+#STR-1]
+ | add RC, 1
+ |4:
+ |.if X64
+ | mov TMP3, RC
+ |.else
+ | mov ARG3, RC
+ |.endif
+ | mov RD, RB
+ | jmp ->fff_newstr
+ |
+ |5: // Negative end or overflow.
+ | jl >6
+ | lea RC, [RC+RB+1] // end = end+(len+1)
+ | jmp <2
+ |6: // Overflow.
+ | mov RC, RB // end = len
+ | jmp <2
+ |
+ |7: // Negative start or underflow.
+ | je >8
+ | add RA, RB // start = start+(len+1)
+ | add RA, 1
+ | jg <3 // start > 0?
+ |8: // Underflow.
+ | mov RA, 1 // start = 1
+ | jmp <3
+ |
+ |->fff_emptystr: // Range underflow.
+ | xor RC, RC // Zero length. Any ptr in RB is ok.
+ | jmp <4
+ |
+ |.ffunc string_rep // Only handle the 1-char case inline.
+ | ffgccheck
+ | cmp NARGS:RD, 2+1; jne ->fff_fallback // Exactly 2 arguments.
+ | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback
+ | cmp dword [BASE+12], LJ_TISNUM
+ | mov STR:RB, [BASE]
+ |.if DUALNUM
+ | jne ->fff_fallback
+ | mov RC, dword [BASE+8]
+ |.elif SSE
+ | jae ->fff_fallback
+ | cvttsd2si RC, qword [BASE+8]
+ |.else
+ | jae ->fff_fallback
+ | fld qword [BASE+8]
+ | fistp TMP2
+ | mov RC, TMP2
+ |.endif
+ | test RC, RC
+ | jle ->fff_emptystr // Count <= 0? (or non-int)
+ | cmp dword STR:RB->len, 1
+ | jb ->fff_emptystr // Zero length string?
+ | jne ->fff_fallback_2 // Fallback for > 1-char strings.
+ | cmp [DISPATCH+DISPATCH_GL(tmpbuf.sz)], RC; jb ->fff_fallback_2
+ | movzx RA, byte STR:RB[1]
+ | mov RB, [DISPATCH+DISPATCH_GL(tmpbuf.buf)]
+ |.if X64
+ | mov TMP3, RC
+ |.else
+ | mov ARG3, RC
+ |.endif
+ |1: // Fill buffer with char. Yes, this is suboptimal code (do you care?).
+ | mov [RB], RAL
+ | add RB, 1
+ | sub RC, 1
+ | jnz <1
+ | mov RD, [DISPATCH+DISPATCH_GL(tmpbuf.buf)]
+ | jmp ->fff_newstr
+ |
+ |.ffunc_1 string_reverse
+ | ffgccheck
+ | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback
+ | mov STR:RB, [BASE]
+ | mov RC, STR:RB->len
+ | test RC, RC
+ | jz ->fff_emptystr // Zero length string?
+ | cmp [DISPATCH+DISPATCH_GL(tmpbuf.sz)], RC; jb ->fff_fallback_1
+ | add RB, #STR
+ | mov TMP2, PC // Need another temp register.
+ |.if X64
+ | mov TMP3, RC
+ |.else
+ | mov ARG3, RC
+ |.endif
+ | mov PC, [DISPATCH+DISPATCH_GL(tmpbuf.buf)]
+ |1:
+ | movzx RA, byte [RB]
+ | add RB, 1
+ | sub RC, 1
+ | mov [PC+RC], RAL
+ | jnz <1
+ | mov RD, PC
+ | mov PC, TMP2
+ | jmp ->fff_newstr
+ |
+ |.macro ffstring_case, name, lo, hi
+ | .ffunc_1 name
+ | ffgccheck
+ | cmp dword [BASE+4], LJ_TSTR; jne ->fff_fallback
+ | mov STR:RB, [BASE]
+ | mov RC, STR:RB->len
+ | cmp [DISPATCH+DISPATCH_GL(tmpbuf.sz)], RC; jb ->fff_fallback_1
+ | add RB, #STR
+ | mov TMP2, PC // Need another temp register.
+ |.if X64
+ | mov TMP3, RC
+ |.else
+ | mov ARG3, RC
+ |.endif
+ | mov PC, [DISPATCH+DISPATCH_GL(tmpbuf.buf)]
+ | jmp >3
+ |1: // ASCII case conversion. Yes, this is suboptimal code (do you care?).
+ | movzx RA, byte [RB+RC]
+ | cmp RA, lo
+ | jb >2
+ | cmp RA, hi
+ | ja >2
+ | xor RA, 0x20
+ |2:
+ | mov [PC+RC], RAL
+ |3:
+ | sub RC, 1
+ | jns <1
+ | mov RD, PC
+ | mov PC, TMP2
+ | jmp ->fff_newstr
+ |.endmacro
+ |
+ |ffstring_case string_lower, 0x41, 0x5a
+ |ffstring_case string_upper, 0x61, 0x7a
+ |
+ |//-- Table library ------------------------------------------------------
+ |
+ |.ffunc_1 table_getn
+ | cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
+ | mov RB, BASE // Save BASE.
+ | mov TAB:FCARG1, [BASE]
+ | call extern lj_tab_len@4 // LJ_FASTCALL (GCtab *t)
+ | // Length of table returned in eax (RD).
+ | mov BASE, RB // Restore BASE.
+ |.if DUALNUM
+ | mov RB, RD; jmp ->fff_resi
+ |.elif SSE
+ | cvtsi2sd xmm0, RD; jmp ->fff_resxmm0
+ |.else
+ | mov ARG1, RD; fild ARG1; jmp ->fff_resn
+ |.endif
+ |
+ |//-- Bit library --------------------------------------------------------
+ |
+ |.define TOBIT_BIAS, 0x59c00000 // 2^52 + 2^51 (float, not double!).
+ |
+ |.macro .ffunc_bit, name, kind, fdef
+ | fdef name
+ |.if kind == 2
+ |.if SSE
+ | sseconst_tobit xmm1, RBa
+ |.else
+ | mov TMP1, TOBIT_BIAS
+ |.endif
+ |.endif
+ | cmp dword [BASE+4], LJ_TISNUM
+ |.if DUALNUM
+ | jne >1
+ | mov RB, dword [BASE]
+ |.if kind > 0
+ | jmp >2
+ |.else
+ | jmp ->fff_resbit
+ |.endif
+ |1:
+ | ja ->fff_fallback
+ |.else
+ | jae ->fff_fallback
+ |.endif
+ |.if SSE
+ | movsd xmm0, qword [BASE]
+ |.if kind < 2
+ | sseconst_tobit xmm1, RBa
+ |.endif
+ | addsd xmm0, xmm1
+ | movd RB, xmm0
+ |.else
+ | fld qword [BASE]
+ |.if kind < 2
+ | mov TMP1, TOBIT_BIAS
+ |.endif
+ | fadd TMP1
+ | fstp FPARG1
+ |.if kind > 0
+ | mov RB, ARG1
+ |.endif
+ |.endif
+ |2:
+ |.endmacro
+ |
+ |.macro .ffunc_bit, name, kind
+ | .ffunc_bit name, kind, .ffunc_1
+ |.endmacro
+ |
+ |.ffunc_bit bit_tobit, 0
+ |.if DUALNUM or SSE
+ |.if not SSE
+ | mov RB, ARG1
+ |.endif
+ | jmp ->fff_resbit
+ |.else
+ | fild ARG1
+ | jmp ->fff_resn
+ |.endif
+ |
+ |.macro .ffunc_bit_op, name, ins
+ | .ffunc_bit name, 2
+ | mov TMP2, NARGS:RD // Save for fallback.
+ | lea RD, [BASE+NARGS:RD*8-16]
+ |1:
+ | cmp RD, BASE
+ | jbe ->fff_resbit
+ | cmp dword [RD+4], LJ_TISNUM
+ |.if DUALNUM
+ | jne >2
+ | ins RB, dword [RD]
+ | sub RD, 8
+ | jmp <1
+ |2:
+ | ja ->fff_fallback_bit_op
+ |.else
+ | jae ->fff_fallback_bit_op
+ |.endif
+ |.if SSE
+ | movsd xmm0, qword [RD]
+ | addsd xmm0, xmm1
+ | movd RA, xmm0
+ | ins RB, RA
+ |.else
+ | fld qword [RD]
+ | fadd TMP1
+ | fstp FPARG1
+ | ins RB, ARG1
+ |.endif
+ | sub RD, 8
+ | jmp <1
+ |.endmacro
+ |
+ |.ffunc_bit_op bit_band, and
+ |.ffunc_bit_op bit_bor, or
+ |.ffunc_bit_op bit_bxor, xor
+ |
+ |.ffunc_bit bit_bswap, 1
+ | bswap RB
+ | jmp ->fff_resbit
+ |
+ |.ffunc_bit bit_bnot, 1
+ | not RB
+ |.if DUALNUM
+ | jmp ->fff_resbit
+ |.elif SSE
+ |->fff_resbit:
+ | cvtsi2sd xmm0, RB
+ | jmp ->fff_resxmm0
+ |.else
+ |->fff_resbit:
+ | mov ARG1, RB
+ | fild ARG1
+ | jmp ->fff_resn
+ |.endif
+ |
+ |->fff_fallback_bit_op:
+ | mov NARGS:RD, TMP2 // Restore for fallback
+ | jmp ->fff_fallback
+ |
+ |.macro .ffunc_bit_sh, name, ins
+ |.if DUALNUM
+ | .ffunc_bit name, 1, .ffunc_2
+ | // Note: no inline conversion from number for 2nd argument!
+ | cmp dword [BASE+12], LJ_TISNUM; jne ->fff_fallback
+ | mov RA, dword [BASE+8]
+ |.elif SSE
+ | .ffunc_nnsse name
+ | sseconst_tobit xmm2, RBa
+ | addsd xmm0, xmm2
+ | addsd xmm1, xmm2
+ | movd RB, xmm0
+ | movd RA, xmm1
+ |.else
+ | .ffunc_nn name
+ | mov TMP1, TOBIT_BIAS
+ | fadd TMP1
+ | fstp FPARG3
+ | fadd TMP1
+ | fstp FPARG1
+ | mov RA, ARG3
+ | mov RB, ARG1
+ |.endif
+ | ins RB, cl // Assumes RA is ecx.
+ | jmp ->fff_resbit
+ |.endmacro
+ |
+ |.ffunc_bit_sh bit_lshift, shl
+ |.ffunc_bit_sh bit_rshift, shr
+ |.ffunc_bit_sh bit_arshift, sar
+ |.ffunc_bit_sh bit_rol, rol
+ |.ffunc_bit_sh bit_ror, ror
+ |
+ |//-----------------------------------------------------------------------
+ |
+ |->fff_fallback_2:
+ | mov NARGS:RD, 1+2 // Other args are ignored, anyway.
+ | jmp ->fff_fallback
+ |->fff_fallback_1:
+ | mov NARGS:RD, 1+1 // Other args are ignored, anyway.
+ |->fff_fallback: // Call fast function fallback handler.
+ | // BASE = new base, RD = nargs+1
+ | mov L:RB, SAVE_L
+ | mov PC, [BASE-4] // Fallback may overwrite PC.
+ | mov SAVE_PC, PC // Redundant (but a defined value).
+ | mov L:RB->base, BASE
+ | lea RD, [BASE+NARGS:RD*8-8]
+ | lea RA, [RD+8*LUA_MINSTACK] // Ensure enough space for handler.
+ | mov L:RB->top, RD
+ | mov CFUNC:RD, [BASE-8]
+ | cmp RA, L:RB->maxstack
+ | ja >5 // Need to grow stack.
+ |.if X64
+ | mov CARG1d, L:RB
+ |.else
+ | mov ARG1, L:RB
+ |.endif
+ | call aword CFUNC:RD->f // (lua_State *L)
+ | mov BASE, L:RB->base
+ | // Either throws an error, or recovers and returns -1, 0 or nresults+1.
+ | test RD, RD; jg ->fff_res // Returned nresults+1?
+ |1:
+ | mov RA, L:RB->top
+ | sub RA, BASE
+ | shr RA, 3
+ | test RD, RD
+ | lea NARGS:RD, [RA+1]
+ | mov LFUNC:RB, [BASE-8]
+ | jne ->vm_call_tail // Returned -1?
+ | ins_callt // Returned 0: retry fast path.
+ |
+ |// Reconstruct previous base for vmeta_call during tailcall.
+ |->vm_call_tail:
+ | mov RA, BASE
+ | test PC, FRAME_TYPE
+ | jnz >3
+ | movzx RB, PC_RA
+ | not RBa // Note: ~RB = -(RB+1)
+ | lea BASE, [BASE+RB*8] // base = base - (RB+1)*8
+ | jmp ->vm_call_dispatch // Resolve again for tailcall.
+ |3:
+ | mov RB, PC
+ | and RB, -8
+ | sub BASE, RB
+ | jmp ->vm_call_dispatch // Resolve again for tailcall.
+ |
+ |5: // Grow stack for fallback handler.
+ | mov FCARG2, LUA_MINSTACK
+ | mov FCARG1, L:RB
+ | call extern lj_state_growstack@8 // (lua_State *L, int n)
+ | mov BASE, L:RB->base
+ | xor RD, RD // Simulate a return 0.
+ | jmp <1 // Dumb retry (goes through ff first).
+ |
+ |->fff_gcstep: // Call GC step function.
+ | // BASE = new base, RD = nargs+1
+ | pop RBa // Must keep stack at same level.
+ | mov TMPa, RBa // Save return address
+ | mov L:RB, SAVE_L
+ | mov SAVE_PC, PC // Redundant (but a defined value).
+ | mov L:RB->base, BASE
+ | lea RD, [BASE+NARGS:RD*8-8]
+ | mov FCARG1, L:RB
+ | mov L:RB->top, RD
+ | call extern lj_gc_step@4 // (lua_State *L)
+ | mov BASE, L:RB->base
+ | mov RD, L:RB->top
+ | sub RD, BASE
+ | shr RD, 3
+ | add NARGS:RD, 1
+ | mov RBa, TMPa
+ | push RBa // Restore return address.
+ | ret
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Special dispatch targets -------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->vm_record: // Dispatch target for recording phase.
+ |.if JIT
+ | movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)]
+ | test RDL, HOOK_VMEVENT // No recording while in vmevent.
+ | jnz >5
+ | // Decrement the hookcount for consistency, but always do the call.
+ | test RDL, HOOK_ACTIVE
+ | jnz >1
+ | test RDL, LUA_MASKLINE|LUA_MASKCOUNT
+ | jz >1
+ | dec dword [DISPATCH+DISPATCH_GL(hookcount)]
+ | jmp >1
+ |.endif
+ |
+ |->vm_rethook: // Dispatch target for return hooks.
+ | movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)]
+ | test RDL, HOOK_ACTIVE // Hook already active?
+ | jnz >5
+ | jmp >1
+ |
+ |->vm_inshook: // Dispatch target for instr/line hooks.
+ | movzx RD, byte [DISPATCH+DISPATCH_GL(hookmask)]
+ | test RDL, HOOK_ACTIVE // Hook already active?
+ | jnz >5
+ |
+ | test RDL, LUA_MASKLINE|LUA_MASKCOUNT
+ | jz >5
+ | dec dword [DISPATCH+DISPATCH_GL(hookcount)]
+ | jz >1
+ | test RDL, LUA_MASKLINE
+ | jz >5
+ |1:
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE
+ | mov FCARG2, PC // Caveat: FCARG2 == BASE
+ | mov FCARG1, L:RB
+ | // SAVE_PC must hold the _previous_ PC. The callee updates it with PC.
+ | call extern lj_dispatch_ins@8 // (lua_State *L, BCIns *pc)
+ |3:
+ | mov BASE, L:RB->base
+ |4:
+ | movzx RA, PC_RA
+ |5:
+ | movzx OP, PC_OP
+ | movzx RD, PC_RD
+ |.if X64
+ | jmp aword [DISPATCH+OP*8+GG_DISP2STATIC] // Re-dispatch to static ins.
+ |.else
+ | jmp aword [DISPATCH+OP*4+GG_DISP2STATIC] // Re-dispatch to static ins.
+ |.endif
+ |
+ |->cont_hook: // Continue from hook yield.
+ | add PC, 4
+ | mov RA, [RB-24]
+ | mov MULTRES, RA // Restore MULTRES for *M ins.
+ | jmp <4
+ |
+ |->vm_hotloop: // Hot loop counter underflow.
+ |.if JIT
+ | mov LFUNC:RB, [BASE-8] // Same as curr_topL(L).
+ | mov RB, LFUNC:RB->pc
+ | movzx RD, byte [RB+PC2PROTO(framesize)]
+ | lea RD, [BASE+RD*8]
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE
+ | mov L:RB->top, RD
+ | mov FCARG2, PC
+ | lea FCARG1, [DISPATCH+GG_DISP2J]
+ | mov aword [DISPATCH+DISPATCH_J(L)], L:RBa
+ | mov SAVE_PC, PC
+ | call extern lj_trace_hot@8 // (jit_State *J, const BCIns *pc)
+ | jmp <3
+ |.endif
+ |
+ |->vm_callhook: // Dispatch target for call hooks.
+ | mov SAVE_PC, PC
+ |.if JIT
+ | jmp >1
+ |.endif
+ |
+ |->vm_hotcall: // Hot call counter underflow.
+ |.if JIT
+ | mov SAVE_PC, PC
+ | or PC, 1 // Marker for hot call.
+ |1:
+ |.endif
+ | lea RD, [BASE+NARGS:RD*8-8]
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE
+ | mov L:RB->top, RD
+ | mov FCARG2, PC
+ | mov FCARG1, L:RB
+ | call extern lj_dispatch_call@8 // (lua_State *L, const BCIns *pc)
+ | // ASMFunction returned in eax/rax (RDa).
+ | mov SAVE_PC, 0 // Invalidate for subsequent line hook.
+ |.if JIT
+ | and PC, -2
+ |.endif
+ | mov BASE, L:RB->base
+ | mov RAa, RDa
+ | mov RD, L:RB->top
+ | sub RD, BASE
+ | mov RBa, RAa
+ | movzx RA, PC_RA
+ | shr RD, 3
+ | add NARGS:RD, 1
+ | jmp RBa
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Trace exit handler -------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |// Called from an exit stub with the exit number on the stack.
+ |// The 16 bit exit number is stored with two (sign-extended) push imm8.
+ |->vm_exit_handler:
+ |.if JIT
+ |.if X64
+ | push r13; push r12
+ | push r11; push r10; push r9; push r8
+ | push rdi; push rsi; push rbp; lea rbp, [rsp+88]; push rbp
+ | push rbx; push rdx; push rcx; push rax
+ | movzx RC, byte [rbp-8] // Reconstruct exit number.
+ | mov RCH, byte [rbp-16]
+ | mov [rbp-8], r15; mov [rbp-16], r14
+ |.else
+ | push ebp; lea ebp, [esp+12]; push ebp
+ | push ebx; push edx; push ecx; push eax
+ | movzx RC, byte [ebp-4] // Reconstruct exit number.
+ | mov RCH, byte [ebp-8]
+ | mov [ebp-4], edi; mov [ebp-8], esi
+ |.endif
+ | // Caveat: DISPATCH is ebx.
+ | mov DISPATCH, [ebp]
+ | mov RA, [DISPATCH+DISPATCH_GL(vmstate)] // Get trace number.
+ | set_vmstate EXIT
+ | mov [DISPATCH+DISPATCH_J(exitno)], RC
+ | mov [DISPATCH+DISPATCH_J(parent)], RA
+ |.if X64
+ |.if X64WIN
+ | sub rsp, 16*8+4*8 // Room for SSE regs + save area.
+ |.else
+ | sub rsp, 16*8 // Room for SSE regs.
+ |.endif
+ | add rbp, -128
+ | movsd qword [rbp-8], xmm15; movsd qword [rbp-16], xmm14
+ | movsd qword [rbp-24], xmm13; movsd qword [rbp-32], xmm12
+ | movsd qword [rbp-40], xmm11; movsd qword [rbp-48], xmm10
+ | movsd qword [rbp-56], xmm9; movsd qword [rbp-64], xmm8
+ | movsd qword [rbp-72], xmm7; movsd qword [rbp-80], xmm6
+ | movsd qword [rbp-88], xmm5; movsd qword [rbp-96], xmm4
+ | movsd qword [rbp-104], xmm3; movsd qword [rbp-112], xmm2
+ | movsd qword [rbp-120], xmm1; movsd qword [rbp-128], xmm0
+ |.else
+ | sub esp, 8*8+16 // Room for SSE regs + args.
+ | movsd qword [ebp-40], xmm7; movsd qword [ebp-48], xmm6
+ | movsd qword [ebp-56], xmm5; movsd qword [ebp-64], xmm4
+ | movsd qword [ebp-72], xmm3; movsd qword [ebp-80], xmm2
+ | movsd qword [ebp-88], xmm1; movsd qword [ebp-96], xmm0
+ |.endif
+ | // Caveat: RB is ebp.
+ | mov L:RB, [DISPATCH+DISPATCH_GL(jit_L)]
+ | mov BASE, [DISPATCH+DISPATCH_GL(jit_base)]
+ | mov aword [DISPATCH+DISPATCH_J(L)], L:RBa
+ | mov dword [DISPATCH+DISPATCH_GL(jit_L)], 0
+ | mov L:RB->base, BASE
+ |.if X64WIN
+ | lea CARG2, [rsp+4*8]
+ |.elif X64
+ | mov CARG2, rsp
+ |.else
+ | lea FCARG2, [esp+16]
+ |.endif
+ | lea FCARG1, [DISPATCH+GG_DISP2J]
+ | call extern lj_trace_exit@8 // (jit_State *J, ExitState *ex)
+ | // MULTRES or negated error code returned in eax (RD).
+ | mov RAa, L:RB->cframe
+ | and RAa, CFRAME_RAWMASK
+ |.if X64WIN
+ | // Reposition stack later.
+ |.elif X64
+ | mov rsp, RAa // Reposition stack to C frame.
+ |.else
+ | mov esp, RAa // Reposition stack to C frame.
+ |.endif
+ | mov [RAa+CFRAME_OFS_L], L:RB // Set SAVE_L (on-trace resume/yield).
+ | mov BASE, L:RB->base
+ | mov PC, [RAa+CFRAME_OFS_PC] // Get SAVE_PC.
+ |.if X64
+ | jmp >1
+ |.endif
+ |.endif
+ |->vm_exit_interp:
+ | // RD = MULTRES or negated error code, BASE, PC and DISPATCH set.
+ |.if JIT
+ |.if X64
+ | // Restore additional callee-save registers only used in compiled code.
+ |.if X64WIN
+ | lea RAa, [rsp+9*16+4*8]
+ |1:
+ | movdqa xmm15, [RAa-9*16]
+ | movdqa xmm14, [RAa-8*16]
+ | movdqa xmm13, [RAa-7*16]
+ | movdqa xmm12, [RAa-6*16]
+ | movdqa xmm11, [RAa-5*16]
+ | movdqa xmm10, [RAa-4*16]
+ | movdqa xmm9, [RAa-3*16]
+ | movdqa xmm8, [RAa-2*16]
+ | movdqa xmm7, [RAa-1*16]
+ | mov rsp, RAa // Reposition stack to C frame.
+ | movdqa xmm6, [RAa]
+ | mov r15, CSAVE_3
+ | mov r14, CSAVE_4
+ |.else
+ | add rsp, 16 // Reposition stack to C frame.
+ |1:
+ |.endif
+ | mov r13, TMPa
+ | mov r12, TMPQ
+ |.endif
+ | test RD, RD; js >3 // Check for error from exit.
+ | mov MULTRES, RD
+ | mov LFUNC:KBASE, [BASE-8]
+ | mov KBASE, LFUNC:KBASE->pc
+ | mov KBASE, [KBASE+PC2PROTO(k)]
+ | mov dword [DISPATCH+DISPATCH_GL(jit_L)], 0
+ | set_vmstate INTERP
+ | // Modified copy of ins_next which handles function header dispatch, too.
+ | mov RC, [PC]
+ | movzx RA, RCH
+ | movzx OP, RCL
+ | add PC, 4
+ | shr RC, 16
+ | cmp OP, BC_FUNCF // Function header?
+ | jb >2
+ | mov RC, MULTRES // RC/RD holds nres+1.
+ |2:
+ |.if X64
+ | jmp aword [DISPATCH+OP*8]
+ |.else
+ | jmp aword [DISPATCH+OP*4]
+ |.endif
+ |
+ |3: // Rethrow error from the right C frame.
+ | neg RD
+ | mov FCARG1, L:RB
+ | mov FCARG2, RD
+ | call extern lj_err_throw@8 // (lua_State *L, int errcode)
+ |.endif
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Math helper functions ----------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |// FP value rounding. Called by math.floor/math.ceil fast functions
+ |// and from JIT code.
+ |
+ |// x87 variant: Arg/ret on x87 stack. No int/xmm registers modified.
+ |.macro vm_round_x87, mode1, mode2
+ | fnstcw word [esp+4] // Caveat: overwrites ARG1 and ARG2.
+ | mov [esp+8], eax
+ | mov ax, mode1
+ | or ax, [esp+4]
+ |.if mode2 ~= 0xffff
+ | and ax, mode2
+ |.endif
+ | mov [esp+6], ax
+ | fldcw word [esp+6]
+ | frndint
+ | fldcw word [esp+4]
+ | mov eax, [esp+8]
+ | ret
+ |.endmacro
+ |
+ |// SSE variant: arg/ret is xmm0. xmm0-xmm3 and RD (eax) modified.
+ |.macro vm_round_sse, mode
+ | sseconst_abs xmm2, RDa
+ | sseconst_2p52 xmm3, RDa
+ | movaps xmm1, xmm0
+ | andpd xmm1, xmm2 // |x|
+ | ucomisd xmm3, xmm1 // No truncation if 2^52 <= |x|.
+ | jbe >1
+ | andnpd xmm2, xmm0 // Isolate sign bit.
+ |.if mode == 2 // trunc(x)?
+ | movaps xmm0, xmm1
+ | addsd xmm1, xmm3 // (|x| + 2^52) - 2^52
+ | subsd xmm1, xmm3
+ | sseconst_1 xmm3, RDa
+ | cmpsd xmm0, xmm1, 1 // |x| < result?
+ | andpd xmm0, xmm3
+ | subsd xmm1, xmm0 // If yes, subtract -1.
+ | orpd xmm1, xmm2 // Merge sign bit back in.
+ |.else
+ | addsd xmm1, xmm3 // (|x| + 2^52) - 2^52
+ | subsd xmm1, xmm3
+ | orpd xmm1, xmm2 // Merge sign bit back in.
+ | .if mode == 1 // ceil(x)?
+ | sseconst_m1 xmm2, RDa // Must subtract -1 to preserve -0.
+ | cmpsd xmm0, xmm1, 6 // x > result?
+ | .else // floor(x)?
+ | sseconst_1 xmm2, RDa
+ | cmpsd xmm0, xmm1, 1 // x < result?
+ | .endif
+ | andpd xmm0, xmm2
+ | subsd xmm1, xmm0 // If yes, subtract +-1.
+ |.endif
+ | movaps xmm0, xmm1
+ |1:
+ | ret
+ |.endmacro
+ |
+ |.macro vm_round, name, ssemode, mode1, mode2
+ |->name:
+ |.if not SSE
+ | vm_round_x87 mode1, mode2
+ |.endif
+ |->name .. _sse:
+ | vm_round_sse ssemode
+ |.endmacro
+ |
+ | vm_round vm_floor, 0, 0x0400, 0xf7ff
+ | vm_round vm_ceil, 1, 0x0800, 0xfbff
+ | vm_round vm_trunc, 2, 0x0c00, 0xffff
+ |
+ |// FP modulo x%y. Called by BC_MOD* and vm_arith.
+ |->vm_mod:
+ |.if SSE
+ |// Args in xmm0/xmm1, return value in xmm0.
+ |// Caveat: xmm0-xmm5 and RC (eax) modified!
+ | movaps xmm5, xmm0
+ | divsd xmm0, xmm1
+ | sseconst_abs xmm2, RDa
+ | sseconst_2p52 xmm3, RDa
+ | movaps xmm4, xmm0
+ | andpd xmm4, xmm2 // |x/y|
+ | ucomisd xmm3, xmm4 // No truncation if 2^52 <= |x/y|.
+ | jbe >1
+ | andnpd xmm2, xmm0 // Isolate sign bit.
+ | addsd xmm4, xmm3 // (|x/y| + 2^52) - 2^52
+ | subsd xmm4, xmm3
+ | orpd xmm4, xmm2 // Merge sign bit back in.
+ | sseconst_1 xmm2, RDa
+ | cmpsd xmm0, xmm4, 1 // x/y < result?
+ | andpd xmm0, xmm2
+ | subsd xmm4, xmm0 // If yes, subtract 1.0.
+ | movaps xmm0, xmm5
+ | mulsd xmm1, xmm4
+ | subsd xmm0, xmm1
+ | ret
+ |1:
+ | mulsd xmm1, xmm0
+ | movaps xmm0, xmm5
+ | subsd xmm0, xmm1
+ | ret
+ |.else
+ |// Args/ret on x87 stack (y on top). No xmm registers modified.
+ |// Caveat: needs 3 slots on x87 stack! RC (eax) modified!
+ | fld st1
+ | fdiv st1
+ | fnstcw word [esp+4]
+ | mov ax, 0x0400
+ | or ax, [esp+4]
+ | and ax, 0xf7ff
+ | mov [esp+6], ax
+ | fldcw word [esp+6]
+ | frndint
+ | fldcw word [esp+4]
+ | fmulp st1
+ | fsubp st1
+ | ret
+ |.endif
+ |
+ |// FP log2(x). Called by math.log(x, base).
+ |->vm_log2:
+ |.if X64WIN
+ | movsd qword [rsp+8], xmm0 // Use scratch area.
+ | fld1
+ | fld qword [rsp+8]
+ | fyl2x
+ | fstp qword [rsp+8]
+ | movsd xmm0, qword [rsp+8]
+ |.elif X64
+ | movsd qword [rsp-8], xmm0 // Use red zone.
+ | fld1
+ | fld qword [rsp-8]
+ | fyl2x
+ | fstp qword [rsp-8]
+ | movsd xmm0, qword [rsp-8]
+ |.else
+ | fld1
+ | fld qword [esp+4]
+ | fyl2x
+ |.endif
+ | ret
+ |
+ |// FP exponentiation e^x and 2^x. Called by math.exp fast function and
+ |// from JIT code. Arg/ret on x87 stack. No int/xmm regs modified.
+ |// Caveat: needs 3 slots on x87 stack!
+ |->vm_exp_x87:
+ | fldl2e; fmulp st1 // e^x ==> 2^(x*log2(e))
+ |->vm_exp2_x87:
+ | .if X64WIN
+ | .define expscratch, dword [rsp+8] // Use scratch area.
+ | .elif X64
+ | .define expscratch, dword [rsp-8] // Use red zone.
+ | .else
+ | .define expscratch, dword [esp+4] // Needs 4 byte scratch area.
+ | .endif
+ | fst expscratch // Caveat: overwrites ARG1.
+ | cmp expscratch, 0x7f800000; je >1 // Special case: e^+Inf = +Inf
+ | cmp expscratch, 0xff800000; je >2 // Special case: e^-Inf = 0
+ |->vm_exp2raw: // Entry point for vm_pow. Without +-Inf check.
+ | fdup; frndint; fsub st1, st0; fxch // Split into frac/int part.
+ | f2xm1; fld1; faddp st1; fscale; fpop1 // ==> (2^frac-1 +1) << int
+ |1:
+ | ret
+ |2:
+ | fpop; fldz; ret
+ |
+ |// Generic power function x^y. Called by BC_POW, math.pow fast function,
+ |// and vm_arith.
+ |// Args/ret on x87 stack (y on top). RC (eax) modified.
+ |// Caveat: needs 3 slots on x87 stack!
+ |->vm_pow:
+ |.if not SSE
+ | fist dword [esp+4] // Store/reload int before comparison.
+ | fild dword [esp+4] // Integral exponent used in vm_powi.
+ | fucomip st1
+ | jnz >8 // Branch for FP exponents.
+ | jp >9 // Branch for NaN exponent.
+ | fpop // Pop y and fallthrough to vm_powi.
+ |
+ |// FP/int power function x^i. Arg1/ret on x87 stack.
+ |// Arg2 (int) on C stack. RC (eax) modified.
+ |// Caveat: needs 2 slots on x87 stack!
+ | mov eax, [esp+4]
+ | cmp eax, 1; jle >6 // i<=1?
+ | // Now 1 < (unsigned)i <= 0x80000000.
+ |1: // Handle leading zeros.
+ | test eax, 1; jnz >2
+ | fmul st0
+ | shr eax, 1
+ | jmp <1
+ |2:
+ | shr eax, 1; jz >5
+ | fdup
+ |3: // Handle trailing bits.
+ | fmul st0
+ | shr eax, 1; jz >4
+ | jnc <3
+ | fmul st1, st0
+ | jmp <3
+ |4:
+ | fmulp st1
+ |5:
+ | ret
+ |6:
+ | je <5 // x^1 ==> x
+ | jb >7
+ | fld1; fdivrp st1
+ | neg eax
+ | cmp eax, 1; je <5 // x^-1 ==> 1/x
+ | jmp <1 // x^-i ==> (1/x)^i
+ |7:
+ | fpop; fld1 // x^0 ==> 1
+ | ret
+ |
+ |8: // FP/FP power function x^y.
+ | fst dword [esp+4]
+ | fxch
+ | fst dword [esp+8]
+ | mov eax, [esp+4]; shl eax, 1
+ | cmp eax, 0xff000000; je >2 // x^+-Inf?
+ | mov eax, [esp+8]; shl eax, 1; je >4 // +-0^y?
+ | cmp eax, 0xff000000; je >4 // +-Inf^y?
+ | fyl2x
+ | jmp ->vm_exp2raw
+ |
+ |9: // Handle x^NaN.
+ | fld1
+ | fucomip st2
+ | je >1 // 1^NaN ==> 1
+ | fxch // x^NaN ==> NaN
+ |1:
+ | fpop
+ | ret
+ |
+ |2: // Handle x^+-Inf.
+ | fabs
+ | fld1
+ | fucomip st1
+ | je >3 // +-1^+-Inf ==> 1
+ | fpop; fabs; fldz; mov eax, 0; setc al
+ | ror eax, 1; xor eax, [esp+4]; jns >3 // |x|<>1, x^+-Inf ==> +Inf/0
+ | fxch
+ |3:
+ | fpop1; fabs
+ | ret
+ |
+ |4: // Handle +-0^y or +-Inf^y.
+ | cmp dword [esp+4], 0; jge <3 // y >= 0, x^y ==> |x|
+ | fpop; fpop
+ | test eax, eax; jz >5 // y < 0, +-0^y ==> +Inf
+ | fldz // y < 0, +-Inf^y ==> 0
+ | ret
+ |5:
+ | mov dword [esp+4], 0x7f800000 // Return +Inf.
+ | fld dword [esp+4]
+ | ret
+ |.endif
+ |
+ |// Args in xmm0/xmm1. Ret in xmm0. xmm0-xmm2 and RC (eax) modified.
+ |// Needs 16 byte scratch area for x86. Also called from JIT code.
+ |->vm_pow_sse:
+ | cvtsd2si eax, xmm1
+ | cvtsi2sd xmm2, eax
+ | ucomisd xmm1, xmm2
+ | jnz >8 // Branch for FP exponents.
+ | jp >9 // Branch for NaN exponent.
+ | // Fallthrough to vm_powi_sse.
+ |
+ |// Args in xmm0/eax. Ret in xmm0. xmm0-xmm1 and eax modified.
+ |->vm_powi_sse:
+ | cmp eax, 1; jle >6 // i<=1?
+ | // Now 1 < (unsigned)i <= 0x80000000.
+ |1: // Handle leading zeros.
+ | test eax, 1; jnz >2
+ | mulsd xmm0, xmm0
+ | shr eax, 1
+ | jmp <1
+ |2:
+ | shr eax, 1; jz >5
+ | movaps xmm1, xmm0
+ |3: // Handle trailing bits.
+ | mulsd xmm0, xmm0
+ | shr eax, 1; jz >4
+ | jnc <3
+ | mulsd xmm1, xmm0
+ | jmp <3
+ |4:
+ | mulsd xmm0, xmm1
+ |5:
+ | ret
+ |6:
+ | je <5 // x^1 ==> x
+ | jb >7 // x^0 ==> 1
+ | neg eax
+ | call <1
+ | sseconst_1 xmm1, RDa
+ | divsd xmm1, xmm0
+ | movaps xmm0, xmm1
+ | ret
+ |7:
+ | sseconst_1 xmm0, RDa
+ | ret
+ |
+ |8: // FP/FP power function x^y.
+ |.if X64
+ | movd rax, xmm1; shl rax, 1
+ | rol rax, 12; cmp rax, 0xffe; je >2 // x^+-Inf?
+ | movd rax, xmm0; shl rax, 1; je >4 // +-0^y?
+ | rol rax, 12; cmp rax, 0xffe; je >5 // +-Inf^y?
+ | .if X64WIN
+ | movsd qword [rsp+16], xmm1 // Use scratch area.
+ | movsd qword [rsp+8], xmm0
+ | fld qword [rsp+16]
+ | fld qword [rsp+8]
+ | .else
+ | movsd qword [rsp-16], xmm1 // Use red zone.
+ | movsd qword [rsp-8], xmm0
+ | fld qword [rsp-16]
+ | fld qword [rsp-8]
+ | .endif
+ |.else
+ | movsd qword [esp+12], xmm1 // Needs 16 byte scratch area.
+ | movsd qword [esp+4], xmm0
+ | cmp dword [esp+12], 0; jne >1
+ | mov eax, [esp+16]; shl eax, 1
+ | cmp eax, 0xffe00000; je >2 // x^+-Inf?
+ |1:
+ | cmp dword [esp+4], 0; jne >1
+ | mov eax, [esp+8]; shl eax, 1; je >4 // +-0^y?
+ | cmp eax, 0xffe00000; je >5 // +-Inf^y?
+ |1:
+ | fld qword [esp+12]
+ | fld qword [esp+4]
+ |.endif
+ | fyl2x // y*log2(x)
+ | fdup; frndint; fsub st1, st0; fxch // Split into frac/int part.
+ | f2xm1; fld1; faddp st1; fscale; fpop1 // ==> (2^frac-1 +1) << int
+ |.if X64WIN
+ | fstp qword [rsp+8] // Use scratch area.
+ | movsd xmm0, qword [rsp+8]
+ |.elif X64
+ | fstp qword [rsp-8] // Use red zone.
+ | movsd xmm0, qword [rsp-8]
+ |.else
+ | fstp qword [esp+4] // Needs 8 byte scratch area.
+ | movsd xmm0, qword [esp+4]
+ |.endif
+ | ret
+ |
+ |9: // Handle x^NaN.
+ | sseconst_1 xmm2, RDa
+ | ucomisd xmm0, xmm2; je >1 // 1^NaN ==> 1
+ | movaps xmm0, xmm1 // x^NaN ==> NaN
+ |1:
+ | ret
+ |
+ |2: // Handle x^+-Inf.
+ | sseconst_abs xmm2, RDa
+ | andpd xmm0, xmm2 // |x|
+ | sseconst_1 xmm2, RDa
+ | ucomisd xmm0, xmm2; je <1 // +-1^+-Inf ==> 1
+ | movmskpd eax, xmm1
+ | xorps xmm0, xmm0
+ | mov ah, al; setc al; xor al, ah; jne <1 // |x|<>1, x^+-Inf ==> +Inf/0
+ |3:
+ | sseconst_hi xmm0, RDa, 7ff00000 // +Inf
+ | ret
+ |
+ |4: // Handle +-0^y.
+ | movmskpd eax, xmm1; test eax, eax; jnz <3 // y < 0, +-0^y ==> +Inf
+ | xorps xmm0, xmm0 // y >= 0, +-0^y ==> 0
+ | ret
+ |
+ |5: // Handle +-Inf^y.
+ | movmskpd eax, xmm1; test eax, eax; jz <3 // y >= 0, +-Inf^y ==> +Inf
+ | xorps xmm0, xmm0 // y < 0, +-Inf^y ==> 0
+ | ret
+ |
+ |// Callable from C: double lj_vm_foldfpm(double x, int fpm)
+ |// Computes fpm(x) for extended math functions. ORDER FPM.
+ |->vm_foldfpm:
+ |.if JIT
+ |.if X64
+ | .if X64WIN
+ | .define fpmop, CARG2d
+ | .else
+ | .define fpmop, CARG1d
+ | .endif
+ | cmp fpmop, 1; jb ->vm_floor; je ->vm_ceil
+ | cmp fpmop, 3; jb ->vm_trunc; ja >2
+ | sqrtsd xmm0, xmm0; ret
+ |2:
+ | .if X64WIN
+ | movsd qword [rsp+8], xmm0 // Use scratch area.
+ | fld qword [rsp+8]
+ | .else
+ | movsd qword [rsp-8], xmm0 // Use red zone.
+ | fld qword [rsp-8]
+ | .endif
+ | cmp fpmop, 5; ja >2
+ | .if X64WIN; pop rax; .endif
+ | je >1
+ | call ->vm_exp_x87
+ | .if X64WIN; push rax; .endif
+ | jmp >7
+ |1:
+ | call ->vm_exp2_x87
+ | .if X64WIN; push rax; .endif
+ | jmp >7
+ |2: ; cmp fpmop, 7; je >1; ja >2
+ | fldln2; fxch; fyl2x; jmp >7
+ |1: ; fld1; fxch; fyl2x; jmp >7
+ |2: ; cmp fpmop, 9; je >1; ja >2
+ | fldlg2; fxch; fyl2x; jmp >7
+ |1: ; fsin; jmp >7
+ |2: ; cmp fpmop, 11; je >1; ja >9
+ | fcos; jmp >7
+ |1: ; fptan; fpop
+ |7:
+ | .if X64WIN
+ | fstp qword [rsp+8] // Use scratch area.
+ | movsd xmm0, qword [rsp+8]
+ | .else
+ | fstp qword [rsp-8] // Use red zone.
+ | movsd xmm0, qword [rsp-8]
+ | .endif
+ | ret
+ |.else // x86 calling convention.
+ | .define fpmop, eax
+ |.if SSE
+ | mov fpmop, [esp+12]
+ | movsd xmm0, qword [esp+4]
+ | cmp fpmop, 1; je >1; ja >2
+ | call ->vm_floor; jmp >7
+ |1: ; call ->vm_ceil; jmp >7
+ |2: ; cmp fpmop, 3; je >1; ja >2
+ | call ->vm_trunc; jmp >7
+ |1:
+ | sqrtsd xmm0, xmm0
+ |7:
+ | movsd qword [esp+4], xmm0 // Overwrite callee-owned args.
+ | fld qword [esp+4]
+ | ret
+ |2: ; fld qword [esp+4]
+ | cmp fpmop, 5; jb ->vm_exp_x87; je ->vm_exp2_x87
+ |2: ; cmp fpmop, 7; je >1; ja >2
+ | fldln2; fxch; fyl2x; ret
+ |1: ; fld1; fxch; fyl2x; ret
+ |2: ; cmp fpmop, 9; je >1; ja >2
+ | fldlg2; fxch; fyl2x; ret
+ |1: ; fsin; ret
+ |2: ; cmp fpmop, 11; je >1; ja >9
+ | fcos; ret
+ |1: ; fptan; fpop; ret
+ |.else
+ | mov fpmop, [esp+12]
+ | fld qword [esp+4]
+ | cmp fpmop, 1; jb ->vm_floor; je ->vm_ceil
+ | cmp fpmop, 3; jb ->vm_trunc; ja >2
+ | fsqrt; ret
+ |2: ; cmp fpmop, 5; jb ->vm_exp_x87; je ->vm_exp2_x87
+ | cmp fpmop, 7; je >1; ja >2
+ | fldln2; fxch; fyl2x; ret
+ |1: ; fld1; fxch; fyl2x; ret
+ |2: ; cmp fpmop, 9; je >1; ja >2
+ | fldlg2; fxch; fyl2x; ret
+ |1: ; fsin; ret
+ |2: ; cmp fpmop, 11; je >1; ja >9
+ | fcos; ret
+ |1: ; fptan; fpop; ret
+ |.endif
+ |.endif
+ |9: ; int3 // Bad fpm.
+ |.endif
+ |
+ |// Callable from C: double lj_vm_foldarith(double x, double y, int op)
+ |// Compute x op y for basic arithmetic operators (+ - * / % ^ and unary -)
+ |// and basic math functions. ORDER ARITH
+ |->vm_foldarith:
+ |.if X64
+ |
+ | .if X64WIN
+ | .define foldop, CARG3d
+ | .else
+ | .define foldop, CARG1d
+ | .endif
+ | cmp foldop, 1; je >1; ja >2
+ | addsd xmm0, xmm1; ret
+ |1: ; subsd xmm0, xmm1; ret
+ |2: ; cmp foldop, 3; je >1; ja >2
+ | mulsd xmm0, xmm1; ret
+ |1: ; divsd xmm0, xmm1; ret
+ |2: ; cmp foldop, 5; jb ->vm_mod; je ->vm_pow
+ | cmp foldop, 7; je >1; ja >2
+ | sseconst_sign xmm1, RDa; xorps xmm0, xmm1; ret
+ |1: ; sseconst_abs xmm1, RDa; andps xmm0, xmm1; ret
+ |2: ; cmp foldop, 9; ja >2
+ |.if X64WIN
+ | movsd qword [rsp+8], xmm0 // Use scratch area.
+ | movsd qword [rsp+16], xmm1
+ | fld qword [rsp+8]
+ | fld qword [rsp+16]
+ |.else
+ | movsd qword [rsp-8], xmm0 // Use red zone.
+ | movsd qword [rsp-16], xmm1
+ | fld qword [rsp-8]
+ | fld qword [rsp-16]
+ |.endif
+ | je >1
+ | fpatan
+ |7:
+ |.if X64WIN
+ | fstp qword [rsp+8] // Use scratch area.
+ | movsd xmm0, qword [rsp+8]
+ |.else
+ | fstp qword [rsp-8] // Use red zone.
+ | movsd xmm0, qword [rsp-8]
+ |.endif
+ | ret
+ |1: ; fxch; fscale; fpop1; jmp <7
+ |2: ; cmp foldop, 11; je >1; ja >9
+ | minsd xmm0, xmm1; ret
+ |1: ; maxsd xmm0, xmm1; ret
+ |9: ; int3 // Bad op.
+ |
+ |.elif SSE // x86 calling convention with SSE ops.
+ |
+ | .define foldop, eax
+ | mov foldop, [esp+20]
+ | movsd xmm0, qword [esp+4]
+ | movsd xmm1, qword [esp+12]
+ | cmp foldop, 1; je >1; ja >2
+ | addsd xmm0, xmm1
+ |7:
+ | movsd qword [esp+4], xmm0 // Overwrite callee-owned args.
+ | fld qword [esp+4]
+ | ret
+ |1: ; subsd xmm0, xmm1; jmp <7
+ |2: ; cmp foldop, 3; je >1; ja >2
+ | mulsd xmm0, xmm1; jmp <7
+ |1: ; divsd xmm0, xmm1; jmp <7
+ |2: ; cmp foldop, 5
+ | je >1; ja >2
+ | call ->vm_mod; jmp <7
+ |1: ; pop edx; call ->vm_pow; push edx; jmp <7 // Writes to scratch area.
+ |2: ; cmp foldop, 7; je >1; ja >2
+ | sseconst_sign xmm1, RDa; xorps xmm0, xmm1; jmp <7
+ |1: ; sseconst_abs xmm1, RDa; andps xmm0, xmm1; jmp <7
+ |2: ; cmp foldop, 9; ja >2
+ | fld qword [esp+4] // Reload from stack
+ | fld qword [esp+12]
+ | je >1
+ | fpatan; ret
+ |1: ; fxch; fscale; fpop1; ret
+ |2: ; cmp foldop, 11; je >1; ja >9
+ | minsd xmm0, xmm1; jmp <7
+ |1: ; maxsd xmm0, xmm1; jmp <7
+ |9: ; int3 // Bad op.
+ |
+ |.else // x86 calling convention with x87 ops.
+ |
+ | mov eax, [esp+20]
+ | fld qword [esp+4]
+ | fld qword [esp+12]
+ | cmp eax, 1; je >1; ja >2
+ | faddp st1; ret
+ |1: ; fsubp st1; ret
+ |2: ; cmp eax, 3; je >1; ja >2
+ | fmulp st1; ret
+ |1: ; fdivp st1; ret
+ |2: ; cmp eax, 5; jb ->vm_mod; je ->vm_pow
+ | cmp eax, 7; je >1; ja >2
+ | fpop; fchs; ret
+ |1: ; fpop; fabs; ret
+ |2: ; cmp eax, 9; je >1; ja >2
+ | fpatan; ret
+ |1: ; fxch; fscale; fpop1; ret
+ |2: ; cmp eax, 11; je >1; ja >9
+ | fucomi st1; fcmovnbe st1; fpop1; ret
+ |1: ; fucomi st1; fcmovbe st1; fpop1; ret
+ |9: ; int3 // Bad op.
+ |
+ |.endif
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Miscellaneous functions --------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |// int lj_vm_cpuid(uint32_t f, uint32_t res[4])
+ |->vm_cpuid:
+ |.if X64
+ | mov eax, CARG1d
+ | .if X64WIN; push rsi; mov rsi, CARG2; .endif
+ | push rbx
+ | cpuid
+ | mov [rsi], eax
+ | mov [rsi+4], ebx
+ | mov [rsi+8], ecx
+ | mov [rsi+12], edx
+ | pop rbx
+ | .if X64WIN; pop rsi; .endif
+ | ret
+ |.else
+ | pushfd
+ | pop edx
+ | mov ecx, edx
+ | xor edx, 0x00200000 // Toggle ID bit in flags.
+ | push edx
+ | popfd
+ | pushfd
+ | pop edx
+ | xor eax, eax // Zero means no features supported.
+ | cmp ecx, edx
+ | jz >1 // No ID toggle means no CPUID support.
+ | mov eax, [esp+4] // Argument 1 is function number.
+ | push edi
+ | push ebx
+ | cpuid
+ | mov edi, [esp+16] // Argument 2 is result area.
+ | mov [edi], eax
+ | mov [edi+4], ebx
+ | mov [edi+8], ecx
+ | mov [edi+12], edx
+ | pop ebx
+ | pop edi
+ |1:
+ | ret
+ |.endif
+ |
+ |//-----------------------------------------------------------------------
+ |//-- Assertions ---------------------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |->assert_bad_for_arg_type:
+#ifdef LUA_USE_ASSERT
+ | int3
+#endif
+ | int3
+ |
+ |//-----------------------------------------------------------------------
+ |//-- FFI helper functions -----------------------------------------------
+ |//-----------------------------------------------------------------------
+ |
+ |// Handler for callback functions. Callback slot number in ah/al.
+ |->vm_ffi_callback:
+ |.if FFI
+ |.type CTSTATE, CTState, PC
+ |.if not X64
+ | sub esp, 16 // Leave room for SAVE_ERRF etc.
+ |.endif
+ | saveregs_ // ebp/rbp already saved. ebp now holds global_State *.
+ | lea DISPATCH, [ebp+GG_G2DISP]
+ | mov CTSTATE, GL:ebp->ctype_state
+ | movzx eax, ax
+ | mov CTSTATE->cb.slot, eax
+ |.if X64
+ | mov CTSTATE->cb.gpr[0], CARG1
+ | mov CTSTATE->cb.gpr[1], CARG2
+ | mov CTSTATE->cb.gpr[2], CARG3
+ | mov CTSTATE->cb.gpr[3], CARG4
+ | movsd qword CTSTATE->cb.fpr[0], xmm0
+ | movsd qword CTSTATE->cb.fpr[1], xmm1
+ | movsd qword CTSTATE->cb.fpr[2], xmm2
+ | movsd qword CTSTATE->cb.fpr[3], xmm3
+ |.if X64WIN
+ | lea rax, [rsp+CFRAME_SIZE+4*8]
+ |.else
+ | lea rax, [rsp+CFRAME_SIZE]
+ | mov CTSTATE->cb.gpr[4], CARG5
+ | mov CTSTATE->cb.gpr[5], CARG6
+ | movsd qword CTSTATE->cb.fpr[4], xmm4
+ | movsd qword CTSTATE->cb.fpr[5], xmm5
+ | movsd qword CTSTATE->cb.fpr[6], xmm6
+ | movsd qword CTSTATE->cb.fpr[7], xmm7
+ |.endif
+ | mov CTSTATE->cb.stack, rax
+ | mov CARG2, rsp
+ |.else
+ | lea eax, [esp+CFRAME_SIZE+16]
+ | mov CTSTATE->cb.gpr[0], FCARG1
+ | mov CTSTATE->cb.gpr[1], FCARG2
+ | mov CTSTATE->cb.stack, eax
+ | mov FCARG1, [esp+CFRAME_SIZE+12] // Move around misplaced retaddr/ebp.
+ | mov FCARG2, [esp+CFRAME_SIZE+8]
+ | mov SAVE_RET, FCARG1
+ | mov SAVE_R4, FCARG2
+ | mov FCARG2, esp
+ |.endif
+ | mov SAVE_PC, CTSTATE // Any value outside of bytecode is ok.
+ | mov FCARG1, CTSTATE
+ | call extern lj_ccallback_enter@8 // (CTState *cts, void *cf)
+ | // lua_State * returned in eax (RD).
+ | set_vmstate INTERP
+ | mov BASE, L:RD->base
+ | mov RD, L:RD->top
+ | sub RD, BASE
+ | mov LFUNC:RB, [BASE-8]
+ | shr RD, 3
+ | add RD, 1
+ | ins_callt
+ |.endif
+ |
+ |->cont_ffi_callback: // Return from FFI callback.
+ |.if FFI
+ | mov L:RA, SAVE_L
+ | mov CTSTATE, [DISPATCH+DISPATCH_GL(ctype_state)]
+ | mov aword CTSTATE->L, L:RAa
+ | mov L:RA->base, BASE
+ | mov L:RA->top, RB
+ | mov FCARG1, CTSTATE
+ | mov FCARG2, RC
+ | call extern lj_ccallback_leave@8 // (CTState *cts, TValue *o)
+ |.if X64
+ | mov rax, CTSTATE->cb.gpr[0]
+ | movsd xmm0, qword CTSTATE->cb.fpr[0]
+ | jmp ->vm_leave_unw
+ |.else
+ | mov L:RB, SAVE_L
+ | mov eax, CTSTATE->cb.gpr[0]
+ | mov edx, CTSTATE->cb.gpr[1]
+ | cmp dword CTSTATE->cb.gpr[2], 1
+ | jb >7
+ | je >6
+ | fld qword CTSTATE->cb.fpr[0].d
+ | jmp >7
+ |6:
+ | fld dword CTSTATE->cb.fpr[0].f
+ |7:
+ | mov ecx, L:RB->top
+ | movzx ecx, word [ecx+6] // Get stack adjustment and copy up.
+ | mov SAVE_L, ecx // Must be one slot above SAVE_RET
+ | restoreregs
+ | pop ecx // Move return addr from SAVE_RET.
+ | add esp, [esp] // Adjust stack.
+ | add esp, 16
+ | push ecx
+ | ret
+ |.endif
+ |.endif
+ |
+ |->vm_ffi_call@4: // Call C function via FFI.
+ | // Caveat: needs special frame unwinding, see below.
+ |.if FFI
+ |.if X64
+ | .type CCSTATE, CCallState, rbx
+ | push rbp; mov rbp, rsp; push rbx; mov CCSTATE, CARG1
+ |.else
+ | .type CCSTATE, CCallState, ebx
+ | push ebp; mov ebp, esp; push ebx; mov CCSTATE, FCARG1
+ |.endif
+ |
+ | // Readjust stack.
+ |.if X64
+ | mov eax, CCSTATE->spadj
+ | sub rsp, rax
+ |.else
+ | sub esp, CCSTATE->spadj
+ |.if WIN
+ | mov CCSTATE->spadj, esp
+ |.endif
+ |.endif
+ |
+ | // Copy stack slots.
+ | movzx ecx, byte CCSTATE->nsp
+ | sub ecx, 1
+ | js >2
+ |1:
+ |.if X64
+ | mov rax, [CCSTATE+rcx*8+offsetof(CCallState, stack)]
+ | mov [rsp+rcx*8+CCALL_SPS_EXTRA*8], rax
+ |.else
+ | mov eax, [CCSTATE+ecx*4+offsetof(CCallState, stack)]
+ | mov [esp+ecx*4], eax
+ |.endif
+ | sub ecx, 1
+ | jns <1
+ |2:
+ |
+ |.if X64
+ | movzx eax, byte CCSTATE->nfpr
+ | mov CARG1, CCSTATE->gpr[0]
+ | mov CARG2, CCSTATE->gpr[1]
+ | mov CARG3, CCSTATE->gpr[2]
+ | mov CARG4, CCSTATE->gpr[3]
+ |.if not X64WIN
+ | mov CARG5, CCSTATE->gpr[4]
+ | mov CARG6, CCSTATE->gpr[5]
+ |.endif
+ | test eax, eax; jz >5
+ | movaps xmm0, CCSTATE->fpr[0]
+ | movaps xmm1, CCSTATE->fpr[1]
+ | movaps xmm2, CCSTATE->fpr[2]
+ | movaps xmm3, CCSTATE->fpr[3]
+ |.if not X64WIN
+ | cmp eax, 4; jbe >5
+ | movaps xmm4, CCSTATE->fpr[4]
+ | movaps xmm5, CCSTATE->fpr[5]
+ | movaps xmm6, CCSTATE->fpr[6]
+ | movaps xmm7, CCSTATE->fpr[7]
+ |.endif
+ |5:
+ |.else
+ | mov FCARG1, CCSTATE->gpr[0]
+ | mov FCARG2, CCSTATE->gpr[1]
+ |.endif
+ |
+ | call aword CCSTATE->func
+ |
+ |.if X64
+ | mov CCSTATE->gpr[0], rax
+ | movaps CCSTATE->fpr[0], xmm0
+ |.if not X64WIN
+ | mov CCSTATE->gpr[1], rdx
+ | movaps CCSTATE->fpr[1], xmm1
+ |.endif
+ |.else
+ | mov CCSTATE->gpr[0], eax
+ | mov CCSTATE->gpr[1], edx
+ | cmp byte CCSTATE->resx87, 1
+ | jb >7
+ | je >6
+ | fstp qword CCSTATE->fpr[0].d[0]
+ | jmp >7
+ |6:
+ | fstp dword CCSTATE->fpr[0].f[0]
+ |7:
+ |.if WIN
+ | sub CCSTATE->spadj, esp
+ |.endif
+ |.endif
+ |
+ |.if X64
+ | mov rbx, [rbp-8]; leave; ret
+ |.else
+ | mov ebx, [ebp-4]; leave; ret
+ |.endif
+ |.endif
+ |// Note: vm_ffi_call must be the last function in this object file!
+ |
+ |//-----------------------------------------------------------------------
+}
+
+/* Generate the code for a single instruction. */
+static void build_ins(BuildCtx *ctx, BCOp op, int defop)
+{
+ int vk = 0;
+ |// Note: aligning all instructions does not pay off.
+ |=>defop:
+
+ switch (op) {
+
+ /* -- Comparison ops ---------------------------------------------------- */
+
+ /* Remember: all ops branch for a true comparison, fall through otherwise. */
+
+ |.macro jmp_comp, lt, ge, le, gt, target
+ ||switch (op) {
+ ||case BC_ISLT:
+ | lt target
+ ||break;
+ ||case BC_ISGE:
+ | ge target
+ ||break;
+ ||case BC_ISLE:
+ | le target
+ ||break;
+ ||case BC_ISGT:
+ | gt target
+ ||break;
+ ||default: break; /* Shut up GCC. */
+ ||}
+ |.endmacro
+
+ case BC_ISLT: case BC_ISGE: case BC_ISLE: case BC_ISGT:
+ | // RA = src1, RD = src2, JMP with RD = target
+ | ins_AD
+ |.if DUALNUM
+ | checkint RA, >7
+ | checkint RD, >8
+ | mov RB, dword [BASE+RA*8]
+ | add PC, 4
+ | cmp RB, dword [BASE+RD*8]
+ | jmp_comp jge, jl, jg, jle, >9
+ |6:
+ | movzx RD, PC_RD
+ | branchPC RD
+ |9:
+ | ins_next
+ |
+ |7: // RA is not an integer.
+ | ja ->vmeta_comp
+ | // RA is a number.
+ | cmp dword [BASE+RD*8+4], LJ_TISNUM; jb >1; jne ->vmeta_comp
+ | // RA is a number, RD is an integer.
+ |.if SSE
+ | cvtsi2sd xmm0, dword [BASE+RD*8]
+ | jmp >2
+ |.else
+ | fld qword [BASE+RA*8]
+ | fild dword [BASE+RD*8]
+ | jmp >3
+ |.endif
+ |
+ |8: // RA is an integer, RD is not an integer.
+ | ja ->vmeta_comp
+ | // RA is an integer, RD is a number.
+ |.if SSE
+ | cvtsi2sd xmm1, dword [BASE+RA*8]
+ | movsd xmm0, qword [BASE+RD*8]
+ | add PC, 4
+ | ucomisd xmm0, xmm1
+ | jmp_comp jbe, ja, jb, jae, <9
+ | jmp <6
+ |.else
+ | fild dword [BASE+RA*8]
+ | jmp >2
+ |.endif
+ |.else
+ | checknum RA, ->vmeta_comp
+ | checknum RD, ->vmeta_comp
+ |.endif
+ |.if SSE
+ |1:
+ | movsd xmm0, qword [BASE+RD*8]
+ |2:
+ | add PC, 4
+ | ucomisd xmm0, qword [BASE+RA*8]
+ |3:
+ |.else
+ |1:
+ | fld qword [BASE+RA*8] // Reverse order, i.e like cmp D, A.
+ |2:
+ | fld qword [BASE+RD*8]
+ |3:
+ | add PC, 4
+ | fcomparepp
+ |.endif
+ | // Unordered: all of ZF CF PF set, ordered: PF clear.
+ | // To preserve NaN semantics GE/GT branch on unordered, but LT/LE don't.
+ |.if DUALNUM
+ | jmp_comp jbe, ja, jb, jae, <9
+ | jmp <6
+ |.else
+ | jmp_comp jbe, ja, jb, jae, >1
+ | movzx RD, PC_RD
+ | branchPC RD
+ |1:
+ | ins_next
+ |.endif
+ break;
+
+ case BC_ISEQV: case BC_ISNEV:
+ vk = op == BC_ISEQV;
+ | ins_AD // RA = src1, RD = src2, JMP with RD = target
+ | mov RB, [BASE+RD*8+4]
+ | add PC, 4
+ |.if DUALNUM
+ | cmp RB, LJ_TISNUM; jne >7
+ | checkint RA, >8
+ | mov RB, dword [BASE+RD*8]
+ | cmp RB, dword [BASE+RA*8]
+ if (vk) {
+ | jne >9
+ } else {
+ | je >9
+ }
+ | movzx RD, PC_RD
+ | branchPC RD
+ |9:
+ | ins_next
+ |
+ |7: // RD is not an integer.
+ | ja >5
+ | // RD is a number.
+ | cmp dword [BASE+RA*8+4], LJ_TISNUM; jb >1; jne >5
+ | // RD is a number, RA is an integer.
+ |.if SSE
+ | cvtsi2sd xmm0, dword [BASE+RA*8]
+ |.else
+ | fild dword [BASE+RA*8]
+ |.endif
+ | jmp >2
+ |
+ |8: // RD is an integer, RA is not an integer.
+ | ja >5
+ | // RD is an integer, RA is a number.
+ |.if SSE
+ | cvtsi2sd xmm0, dword [BASE+RD*8]
+ | ucomisd xmm0, qword [BASE+RA*8]
+ |.else
+ | fild dword [BASE+RD*8]
+ | fld qword [BASE+RA*8]
+ |.endif
+ | jmp >4
+ |
+ |.else
+ | cmp RB, LJ_TISNUM; jae >5
+ | checknum RA, >5
+ |.endif
+ |.if SSE
+ |1:
+ | movsd xmm0, qword [BASE+RA*8]
+ |2:
+ | ucomisd xmm0, qword [BASE+RD*8]
+ |4:
+ |.else
+ |1:
+ | fld qword [BASE+RA*8]
+ |2:
+ | fld qword [BASE+RD*8]
+ |4:
+ | fcomparepp
+ |.endif
+ iseqne_fp:
+ if (vk) {
+ | jp >2 // Unordered means not equal.
+ | jne >2
+ } else {
+ | jp >2 // Unordered means not equal.
+ | je >1
+ }
+ iseqne_end:
+ if (vk) {
+ |1: // EQ: Branch to the target.
+ | movzx RD, PC_RD
+ | branchPC RD
+ |2: // NE: Fallthrough to next instruction.
+ |.if not FFI
+ |3:
+ |.endif
+ } else {
+ |.if not FFI
+ |3:
+ |.endif
+ |2: // NE: Branch to the target.
+ | movzx RD, PC_RD
+ | branchPC RD
+ |1: // EQ: Fallthrough to next instruction.
+ }
+ if (LJ_DUALNUM && (op == BC_ISEQV || op == BC_ISNEV ||
+ op == BC_ISEQN || op == BC_ISNEN)) {
+ | jmp <9
+ } else {
+ | ins_next
+ }
+ |
+ if (op == BC_ISEQV || op == BC_ISNEV) {
+ |5: // Either or both types are not numbers.
+ |.if FFI
+ | cmp RB, LJ_TCDATA; je ->vmeta_equal_cd
+ | checktp RA, LJ_TCDATA; je ->vmeta_equal_cd
+ |.endif
+ | checktp RA, RB // Compare types.
+ | jne <2 // Not the same type?
+ | cmp RB, LJ_TISPRI
+ | jae <1 // Same type and primitive type?
+ |
+ | // Same types and not a primitive type. Compare GCobj or pvalue.
+ | mov RA, [BASE+RA*8]
+ | mov RD, [BASE+RD*8]
+ | cmp RA, RD
+ | je <1 // Same GCobjs or pvalues?
+ | cmp RB, LJ_TISTABUD
+ | ja <2 // Different objects and not table/ud?
+ |.if X64
+ | cmp RB, LJ_TUDATA // And not 64 bit lightuserdata.
+ | jb <2
+ |.endif
+ |
+ | // Different tables or userdatas. Need to check __eq metamethod.
+ | // Field metatable must be at same offset for GCtab and GCudata!
+ | mov TAB:RB, TAB:RA->metatable
+ | test TAB:RB, TAB:RB
+ | jz <2 // No metatable?
+ | test byte TAB:RB->nomm, 1<<MM_eq
+ | jnz <2 // Or 'no __eq' flag set?
+ if (vk) {
+ | xor RB, RB // ne = 0
+ } else {
+ | mov RB, 1 // ne = 1
+ }
+ | jmp ->vmeta_equal // Handle __eq metamethod.
+ } else {
+ |.if FFI
+ |3:
+ | cmp RB, LJ_TCDATA
+ if (LJ_DUALNUM && vk) {
+ | jne <9
+ } else {
+ | jne <2
+ }
+ | jmp ->vmeta_equal_cd
+ |.endif
+ }
+ break;
+ case BC_ISEQS: case BC_ISNES:
+ vk = op == BC_ISEQS;
+ | ins_AND // RA = src, RD = str const, JMP with RD = target
+ | mov RB, [BASE+RA*8+4]
+ | add PC, 4
+ | cmp RB, LJ_TSTR; jne >3
+ | mov RA, [BASE+RA*8]
+ | cmp RA, [KBASE+RD*4]
+ iseqne_test:
+ if (vk) {
+ | jne >2
+ } else {
+ | je >1
+ }
+ goto iseqne_end;
+ case BC_ISEQN: case BC_ISNEN:
+ vk = op == BC_ISEQN;
+ | ins_AD // RA = src, RD = num const, JMP with RD = target
+ | mov RB, [BASE+RA*8+4]
+ | add PC, 4
+ |.if DUALNUM
+ | cmp RB, LJ_TISNUM; jne >7
+ | cmp dword [KBASE+RD*8+4], LJ_TISNUM; jne >8
+ | mov RB, dword [KBASE+RD*8]
+ | cmp RB, dword [BASE+RA*8]
+ if (vk) {
+ | jne >9
+ } else {
+ | je >9
+ }
+ | movzx RD, PC_RD
+ | branchPC RD
+ |9:
+ | ins_next
+ |
+ |7: // RA is not an integer.
+ | ja >3
+ | // RA is a number.
+ | cmp dword [KBASE+RD*8+4], LJ_TISNUM; jb >1
+ | // RA is a number, RD is an integer.
+ |.if SSE
+ | cvtsi2sd xmm0, dword [KBASE+RD*8]
+ |.else
+ | fild dword [KBASE+RD*8]
+ |.endif
+ | jmp >2
+ |
+ |8: // RA is an integer, RD is a number.
+ |.if SSE
+ | cvtsi2sd xmm0, dword [BASE+RA*8]
+ | ucomisd xmm0, qword [KBASE+RD*8]
+ |.else
+ | fild dword [BASE+RA*8]
+ | fld qword [KBASE+RD*8]
+ |.endif
+ | jmp >4
+ |.else
+ | cmp RB, LJ_TISNUM; jae >3
+ |.endif
+ |.if SSE
+ |1:
+ | movsd xmm0, qword [KBASE+RD*8]
+ |2:
+ | ucomisd xmm0, qword [BASE+RA*8]
+ |4:
+ |.else
+ |1:
+ | fld qword [KBASE+RD*8]
+ |2:
+ | fld qword [BASE+RA*8]
+ |4:
+ | fcomparepp
+ |.endif
+ goto iseqne_fp;
+ case BC_ISEQP: case BC_ISNEP:
+ vk = op == BC_ISEQP;
+ | ins_AND // RA = src, RD = primitive type (~), JMP with RD = target
+ | mov RB, [BASE+RA*8+4]
+ | add PC, 4
+ | cmp RB, RD
+ if (!LJ_HASFFI) goto iseqne_test;
+ if (vk) {
+ | jne >3
+ | movzx RD, PC_RD
+ | branchPC RD
+ |2:
+ | ins_next
+ |3:
+ | cmp RB, LJ_TCDATA; jne <2
+ | jmp ->vmeta_equal_cd
+ } else {
+ | je >2
+ | cmp RB, LJ_TCDATA; je ->vmeta_equal_cd
+ | movzx RD, PC_RD
+ | branchPC RD
+ |2:
+ | ins_next
+ }
+ break;
+
+ /* -- Unary test and copy ops ------------------------------------------- */
+
+ case BC_ISTC: case BC_ISFC: case BC_IST: case BC_ISF:
+ | ins_AD // RA = dst or unused, RD = src, JMP with RD = target
+ | mov RB, [BASE+RD*8+4]
+ | add PC, 4
+ | cmp RB, LJ_TISTRUECOND
+ if (op == BC_IST || op == BC_ISTC) {
+ | jae >1
+ } else {
+ | jb >1
+ }
+ if (op == BC_ISTC || op == BC_ISFC) {
+ | mov [BASE+RA*8+4], RB
+ | mov RB, [BASE+RD*8]
+ | mov [BASE+RA*8], RB
+ }
+ | movzx RD, PC_RD
+ | branchPC RD
+ |1: // Fallthrough to the next instruction.
+ | ins_next
+ break;
+
+ /* -- Unary ops --------------------------------------------------------- */
+
+ case BC_MOV:
+ | ins_AD // RA = dst, RD = src
+ |.if X64
+ | mov RBa, [BASE+RD*8]
+ | mov [BASE+RA*8], RBa
+ |.else
+ | mov RB, [BASE+RD*8+4]
+ | mov RD, [BASE+RD*8]
+ | mov [BASE+RA*8+4], RB
+ | mov [BASE+RA*8], RD
+ |.endif
+ | ins_next_
+ break;
+ case BC_NOT:
+ | ins_AD // RA = dst, RD = src
+ | xor RB, RB
+ | checktp RD, LJ_TISTRUECOND
+ | adc RB, LJ_TTRUE
+ | mov [BASE+RA*8+4], RB
+ | ins_next
+ break;
+ case BC_UNM:
+ | ins_AD // RA = dst, RD = src
+ |.if DUALNUM
+ | checkint RD, >5
+ | mov RB, [BASE+RD*8]
+ | neg RB
+ | jo >4
+ | mov dword [BASE+RA*8+4], LJ_TISNUM
+ | mov dword [BASE+RA*8], RB
+ |9:
+ | ins_next
+ |4:
+ | mov dword [BASE+RA*8+4], 0x41e00000 // 2^31.
+ | mov dword [BASE+RA*8], 0
+ | jmp <9
+ |5:
+ | ja ->vmeta_unm
+ |.else
+ | checknum RD, ->vmeta_unm
+ |.endif
+ |.if SSE
+ | movsd xmm0, qword [BASE+RD*8]
+ | sseconst_sign xmm1, RDa
+ | xorps xmm0, xmm1
+ | movsd qword [BASE+RA*8], xmm0
+ |.else
+ | fld qword [BASE+RD*8]
+ | fchs
+ | fstp qword [BASE+RA*8]
+ |.endif
+ |.if DUALNUM
+ | jmp <9
+ |.else
+ | ins_next
+ |.endif
+ break;
+ case BC_LEN:
+ | ins_AD // RA = dst, RD = src
+ | checkstr RD, >2
+ | mov STR:RD, [BASE+RD*8]
+ |.if DUALNUM
+ | mov RD, dword STR:RD->len
+ |1:
+ | mov dword [BASE+RA*8+4], LJ_TISNUM
+ | mov dword [BASE+RA*8], RD
+ |.elif SSE
+ | xorps xmm0, xmm0
+ | cvtsi2sd xmm0, dword STR:RD->len
+ |1:
+ | movsd qword [BASE+RA*8], xmm0
+ |.else
+ | fild dword STR:RD->len
+ |1:
+ | fstp qword [BASE+RA*8]
+ |.endif
+ | ins_next
+ |2:
+ | checktab RD, ->vmeta_len
+ | mov TAB:FCARG1, [BASE+RD*8]
+#if LJ_52
+ | mov TAB:RB, TAB:FCARG1->metatable
+ | cmp TAB:RB, 0
+ | jnz >9
+ |3:
+#endif
+ |->BC_LEN_Z:
+ | mov RB, BASE // Save BASE.
+ | call extern lj_tab_len@4 // (GCtab *t)
+ | // Length of table returned in eax (RD).
+ |.if DUALNUM
+ | // Nothing to do.
+ |.elif SSE
+ | cvtsi2sd xmm0, RD
+ |.else
+ | mov ARG1, RD
+ | fild ARG1
+ |.endif
+ | mov BASE, RB // Restore BASE.
+ | movzx RA, PC_RA
+ | jmp <1
+#if LJ_52
+ |9: // Check for __len.
+ | test byte TAB:RB->nomm, 1<<MM_len
+ | jnz <3
+ | jmp ->vmeta_len // 'no __len' flag NOT set: check.
+#endif
+ break;
+
+ /* -- Binary ops -------------------------------------------------------- */
+
+ |.macro ins_arithpre, x87ins, sseins, ssereg
+ | ins_ABC
+ ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
+ ||switch (vk) {
+ ||case 0:
+ | checknum RB, ->vmeta_arith_vn
+ | .if DUALNUM
+ | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jae ->vmeta_arith_vn
+ | .endif
+ | .if SSE
+ | movsd xmm0, qword [BASE+RB*8]
+ | sseins ssereg, qword [KBASE+RC*8]
+ | .else
+ | fld qword [BASE+RB*8]
+ | x87ins qword [KBASE+RC*8]
+ | .endif
+ || break;
+ ||case 1:
+ | checknum RB, ->vmeta_arith_nv
+ | .if DUALNUM
+ | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jae ->vmeta_arith_nv
+ | .endif
+ | .if SSE
+ | movsd xmm0, qword [KBASE+RC*8]
+ | sseins ssereg, qword [BASE+RB*8]
+ | .else
+ | fld qword [KBASE+RC*8]
+ | x87ins qword [BASE+RB*8]
+ | .endif
+ || break;
+ ||default:
+ | checknum RB, ->vmeta_arith_vv
+ | checknum RC, ->vmeta_arith_vv
+ | .if SSE
+ | movsd xmm0, qword [BASE+RB*8]
+ | sseins ssereg, qword [BASE+RC*8]
+ | .else
+ | fld qword [BASE+RB*8]
+ | x87ins qword [BASE+RC*8]
+ | .endif
+ || break;
+ ||}
+ |.endmacro
+ |
+ |.macro ins_arithdn, intins
+ | ins_ABC
+ ||vk = ((int)op - BC_ADDVN) / (BC_ADDNV-BC_ADDVN);
+ ||switch (vk) {
+ ||case 0:
+ | checkint RB, ->vmeta_arith_vn
+ | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jne ->vmeta_arith_vn
+ | mov RB, [BASE+RB*8]
+ | intins RB, [KBASE+RC*8]; jo ->vmeta_arith_vno
+ || break;
+ ||case 1:
+ | checkint RB, ->vmeta_arith_nv
+ | cmp dword [KBASE+RC*8+4], LJ_TISNUM; jne ->vmeta_arith_nv
+ | mov RC, [KBASE+RC*8]
+ | intins RC, [BASE+RB*8]; jo ->vmeta_arith_nvo
+ || break;
+ ||default:
+ | checkint RB, ->vmeta_arith_vv
+ | checkint RC, ->vmeta_arith_vv
+ | mov RB, [BASE+RB*8]
+ | intins RB, [BASE+RC*8]; jo ->vmeta_arith_vvo
+ || break;
+ ||}
+ | mov dword [BASE+RA*8+4], LJ_TISNUM
+ ||if (vk == 1) {
+ | mov dword [BASE+RA*8], RC
+ ||} else {
+ | mov dword [BASE+RA*8], RB
+ ||}
+ | ins_next
+ |.endmacro
+ |
+ |.macro ins_arithpost
+ |.if SSE
+ | movsd qword [BASE+RA*8], xmm0
+ |.else
+ | fstp qword [BASE+RA*8]
+ |.endif
+ |.endmacro
+ |
+ |.macro ins_arith, x87ins, sseins
+ | ins_arithpre x87ins, sseins, xmm0
+ | ins_arithpost
+ | ins_next
+ |.endmacro
+ |
+ |.macro ins_arith, intins, x87ins, sseins
+ |.if DUALNUM
+ | ins_arithdn intins
+ |.else
+ | ins_arith, x87ins, sseins
+ |.endif
+ |.endmacro
+
+ | // RA = dst, RB = src1 or num const, RC = src2 or num const
+ case BC_ADDVN: case BC_ADDNV: case BC_ADDVV:
+ | ins_arith add, fadd, addsd
+ break;
+ case BC_SUBVN: case BC_SUBNV: case BC_SUBVV:
+ | ins_arith sub, fsub, subsd
+ break;
+ case BC_MULVN: case BC_MULNV: case BC_MULVV:
+ | ins_arith imul, fmul, mulsd
+ break;
+ case BC_DIVVN: case BC_DIVNV: case BC_DIVVV:
+ | ins_arith fdiv, divsd
+ break;
+ case BC_MODVN:
+ | ins_arithpre fld, movsd, xmm1
+ |->BC_MODVN_Z:
+ | call ->vm_mod
+ | ins_arithpost
+ | ins_next
+ break;
+ case BC_MODNV: case BC_MODVV:
+ | ins_arithpre fld, movsd, xmm1
+ | jmp ->BC_MODVN_Z // Avoid 3 copies. It's slow anyway.
+ break;
+ case BC_POW:
+ | ins_arithpre fld, movsd, xmm1
+ | call ->vm_pow
+ | ins_arithpost
+ | ins_next
+ break;
+
+ case BC_CAT:
+ | ins_ABC // RA = dst, RB = src_start, RC = src_end
+ |.if X64
+ | mov L:CARG1d, SAVE_L
+ | mov L:CARG1d->base, BASE
+ | lea CARG2d, [BASE+RC*8]
+ | mov CARG3d, RC
+ | sub CARG3d, RB
+ |->BC_CAT_Z:
+ | mov L:RB, L:CARG1d
+ |.else
+ | lea RA, [BASE+RC*8]
+ | sub RC, RB
+ | mov ARG2, RA
+ | mov ARG3, RC
+ |->BC_CAT_Z:
+ | mov L:RB, SAVE_L
+ | mov ARG1, L:RB
+ | mov L:RB->base, BASE
+ |.endif
+ | mov SAVE_PC, PC
+ | call extern lj_meta_cat // (lua_State *L, TValue *top, int left)
+ | // NULL (finished) or TValue * (metamethod) returned in eax (RC).
+ | mov BASE, L:RB->base
+ | test RC, RC
+ | jnz ->vmeta_binop
+ | movzx RB, PC_RB // Copy result to Stk[RA] from Stk[RB].
+ | movzx RA, PC_RA
+ |.if X64
+ | mov RCa, [BASE+RB*8]
+ | mov [BASE+RA*8], RCa
+ |.else
+ | mov RC, [BASE+RB*8+4]
+ | mov RB, [BASE+RB*8]
+ | mov [BASE+RA*8+4], RC
+ | mov [BASE+RA*8], RB
+ |.endif
+ | ins_next
+ break;
+
+ /* -- Constant ops ------------------------------------------------------ */
+
+ case BC_KSTR:
+ | ins_AND // RA = dst, RD = str const (~)
+ | mov RD, [KBASE+RD*4]
+ | mov dword [BASE+RA*8+4], LJ_TSTR
+ | mov [BASE+RA*8], RD
+ | ins_next
+ break;
+ case BC_KCDATA:
+ |.if FFI
+ | ins_AND // RA = dst, RD = cdata const (~)
+ | mov RD, [KBASE+RD*4]
+ | mov dword [BASE+RA*8+4], LJ_TCDATA
+ | mov [BASE+RA*8], RD
+ | ins_next
+ |.endif
+ break;
+ case BC_KSHORT:
+ | ins_AD // RA = dst, RD = signed int16 literal
+ |.if DUALNUM
+ | movsx RD, RDW
+ | mov dword [BASE+RA*8+4], LJ_TISNUM
+ | mov dword [BASE+RA*8], RD
+ |.elif SSE
+ | movsx RD, RDW // Sign-extend literal.
+ | cvtsi2sd xmm0, RD
+ | movsd qword [BASE+RA*8], xmm0
+ |.else
+ | fild PC_RD // Refetch signed RD from instruction.
+ | fstp qword [BASE+RA*8]
+ |.endif
+ | ins_next
+ break;
+ case BC_KNUM:
+ | ins_AD // RA = dst, RD = num const
+ |.if SSE
+ | movsd xmm0, qword [KBASE+RD*8]
+ | movsd qword [BASE+RA*8], xmm0
+ |.else
+ | fld qword [KBASE+RD*8]
+ | fstp qword [BASE+RA*8]
+ |.endif
+ | ins_next
+ break;
+ case BC_KPRI:
+ | ins_AND // RA = dst, RD = primitive type (~)
+ | mov [BASE+RA*8+4], RD
+ | ins_next
+ break;
+ case BC_KNIL:
+ | ins_AD // RA = dst_start, RD = dst_end
+ | lea RA, [BASE+RA*8+12]
+ | lea RD, [BASE+RD*8+4]
+ | mov RB, LJ_TNIL
+ | mov [RA-8], RB // Sets minimum 2 slots.
+ |1:
+ | mov [RA], RB
+ | add RA, 8
+ | cmp RA, RD
+ | jbe <1
+ | ins_next
+ break;
+
+ /* -- Upvalue and function ops ------------------------------------------ */
+
+ case BC_UGET:
+ | ins_AD // RA = dst, RD = upvalue #
+ | mov LFUNC:RB, [BASE-8]
+ | mov UPVAL:RB, [LFUNC:RB+RD*4+offsetof(GCfuncL, uvptr)]
+ | mov RB, UPVAL:RB->v
+ |.if X64
+ | mov RDa, [RB]
+ | mov [BASE+RA*8], RDa
+ |.else
+ | mov RD, [RB+4]
+ | mov RB, [RB]
+ | mov [BASE+RA*8+4], RD
+ | mov [BASE+RA*8], RB
+ |.endif
+ | ins_next
+ break;
+ case BC_USETV:
+#define TV2MARKOFS \
+ ((int32_t)offsetof(GCupval, marked)-(int32_t)offsetof(GCupval, tv))
+ | ins_AD // RA = upvalue #, RD = src
+ | mov LFUNC:RB, [BASE-8]
+ | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]
+ | cmp byte UPVAL:RB->closed, 0
+ | mov RB, UPVAL:RB->v
+ | mov RA, [BASE+RD*8]
+ | mov RD, [BASE+RD*8+4]
+ | mov [RB], RA
+ | mov [RB+4], RD
+ | jz >1
+ | // Check barrier for closed upvalue.
+ | test byte [RB+TV2MARKOFS], LJ_GC_BLACK // isblack(uv)
+ | jnz >2
+ |1:
+ | ins_next
+ |
+ |2: // Upvalue is black. Check if new value is collectable and white.
+ | sub RD, LJ_TISGCV
+ | cmp RD, LJ_TNUMX - LJ_TISGCV // tvisgcv(v)
+ | jbe <1
+ | test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES // iswhite(v)
+ | jz <1
+ | // Crossed a write barrier. Move the barrier forward.
+ |.if X64 and not X64WIN
+ | mov FCARG2, RB
+ | mov RB, BASE // Save BASE.
+ |.else
+ | xchg FCARG2, RB // Save BASE (FCARG2 == BASE).
+ |.endif
+ | lea GL:FCARG1, [DISPATCH+GG_DISP2G]
+ | call extern lj_gc_barrieruv@8 // (global_State *g, TValue *tv)
+ | mov BASE, RB // Restore BASE.
+ | jmp <1
+ break;
+#undef TV2MARKOFS
+ case BC_USETS:
+ | ins_AND // RA = upvalue #, RD = str const (~)
+ | mov LFUNC:RB, [BASE-8]
+ | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]
+ | mov GCOBJ:RA, [KBASE+RD*4]
+ | mov RD, UPVAL:RB->v
+ | mov [RD], GCOBJ:RA
+ | mov dword [RD+4], LJ_TSTR
+ | test byte UPVAL:RB->marked, LJ_GC_BLACK // isblack(uv)
+ | jnz >2
+ |1:
+ | ins_next
+ |
+ |2: // Check if string is white and ensure upvalue is closed.
+ | test byte GCOBJ:RA->gch.marked, LJ_GC_WHITES // iswhite(str)
+ | jz <1
+ | cmp byte UPVAL:RB->closed, 0
+ | jz <1
+ | // Crossed a write barrier. Move the barrier forward.
+ | mov RB, BASE // Save BASE (FCARG2 == BASE).
+ | mov FCARG2, RD
+ | lea GL:FCARG1, [DISPATCH+GG_DISP2G]
+ | call extern lj_gc_barrieruv@8 // (global_State *g, TValue *tv)
+ | mov BASE, RB // Restore BASE.
+ | jmp <1
+ break;
+ case BC_USETN:
+ | ins_AD // RA = upvalue #, RD = num const
+ | mov LFUNC:RB, [BASE-8]
+ |.if SSE
+ | movsd xmm0, qword [KBASE+RD*8]
+ |.else
+ | fld qword [KBASE+RD*8]
+ |.endif
+ | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]
+ | mov RA, UPVAL:RB->v
+ |.if SSE
+ | movsd qword [RA], xmm0
+ |.else
+ | fstp qword [RA]
+ |.endif
+ | ins_next
+ break;
+ case BC_USETP:
+ | ins_AND // RA = upvalue #, RD = primitive type (~)
+ | mov LFUNC:RB, [BASE-8]
+ | mov UPVAL:RB, [LFUNC:RB+RA*4+offsetof(GCfuncL, uvptr)]
+ | mov RA, UPVAL:RB->v
+ | mov [RA+4], RD
+ | ins_next
+ break;
+ case BC_UCLO:
+ | ins_AD // RA = level, RD = target
+ | branchPC RD // Do this first to free RD.
+ | mov L:RB, SAVE_L
+ | cmp dword L:RB->openupval, 0
+ | je >1
+ | mov L:RB->base, BASE
+ | lea FCARG2, [BASE+RA*8] // Caveat: FCARG2 == BASE
+ | mov L:FCARG1, L:RB // Caveat: FCARG1 == RA
+ | call extern lj_func_closeuv@8 // (lua_State *L, TValue *level)
+ | mov BASE, L:RB->base
+ |1:
+ | ins_next
+ break;
+
+ case BC_FNEW:
+ | ins_AND // RA = dst, RD = proto const (~) (holding function prototype)
+ |.if X64
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE // Caveat: CARG2d/CARG3d may be BASE.
+ | mov CARG3d, [BASE-8]
+ | mov CARG2d, [KBASE+RD*4] // Fetch GCproto *.
+ | mov CARG1d, L:RB
+ |.else
+ | mov LFUNC:RA, [BASE-8]
+ | mov PROTO:RD, [KBASE+RD*4] // Fetch GCproto *.
+ | mov L:RB, SAVE_L
+ | mov ARG3, LFUNC:RA
+ | mov ARG2, PROTO:RD
+ | mov ARG1, L:RB
+ | mov L:RB->base, BASE
+ |.endif
+ | mov SAVE_PC, PC
+ | // (lua_State *L, GCproto *pt, GCfuncL *parent)
+ | call extern lj_func_newL_gc
+ | // GCfuncL * returned in eax (RC).
+ | mov BASE, L:RB->base
+ | movzx RA, PC_RA
+ | mov [BASE+RA*8], LFUNC:RC
+ | mov dword [BASE+RA*8+4], LJ_TFUNC
+ | ins_next
+ break;
+
+ /* -- Table ops --------------------------------------------------------- */
+
+ case BC_TNEW:
+ | ins_AD // RA = dst, RD = hbits|asize
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE
+ | mov RA, [DISPATCH+DISPATCH_GL(gc.total)]
+ | cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)]
+ | mov SAVE_PC, PC
+ | jae >5
+ |1:
+ |.if X64
+ | mov CARG3d, RD
+ | and RD, 0x7ff
+ | shr CARG3d, 11
+ |.else
+ | mov RA, RD
+ | and RD, 0x7ff
+ | shr RA, 11
+ | mov ARG3, RA
+ |.endif
+ | cmp RD, 0x7ff
+ | je >3
+ |2:
+ |.if X64
+ | mov L:CARG1d, L:RB
+ | mov CARG2d, RD
+ |.else
+ | mov ARG1, L:RB
+ | mov ARG2, RD
+ |.endif
+ | call extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits)
+ | // Table * returned in eax (RC).
+ | mov BASE, L:RB->base
+ | movzx RA, PC_RA
+ | mov [BASE+RA*8], TAB:RC
+ | mov dword [BASE+RA*8+4], LJ_TTAB
+ | ins_next
+ |3: // Turn 0x7ff into 0x801.
+ | mov RD, 0x801
+ | jmp <2
+ |5:
+ | mov L:FCARG1, L:RB
+ | call extern lj_gc_step_fixtop@4 // (lua_State *L)
+ | movzx RD, PC_RD
+ | jmp <1
+ break;
+ case BC_TDUP:
+ | ins_AND // RA = dst, RD = table const (~) (holding template table)
+ | mov L:RB, SAVE_L
+ | mov RA, [DISPATCH+DISPATCH_GL(gc.total)]
+ | mov SAVE_PC, PC
+ | cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)]
+ | mov L:RB->base, BASE
+ | jae >3
+ |2:
+ | mov TAB:FCARG2, [KBASE+RD*4] // Caveat: FCARG2 == BASE
+ | mov L:FCARG1, L:RB // Caveat: FCARG1 == RA
+ | call extern lj_tab_dup@8 // (lua_State *L, Table *kt)
+ | // Table * returned in eax (RC).
+ | mov BASE, L:RB->base
+ | movzx RA, PC_RA
+ | mov [BASE+RA*8], TAB:RC
+ | mov dword [BASE+RA*8+4], LJ_TTAB
+ | ins_next
+ |3:
+ | mov L:FCARG1, L:RB
+ | call extern lj_gc_step_fixtop@4 // (lua_State *L)
+ | movzx RD, PC_RD // Need to reload RD.
+ | not RDa
+ | jmp <2
+ break;
+
+ case BC_GGET:
+ | ins_AND // RA = dst, RD = str const (~)
+ | mov LFUNC:RB, [BASE-8]
+ | mov TAB:RB, LFUNC:RB->env
+ | mov STR:RC, [KBASE+RD*4]
+ | jmp ->BC_TGETS_Z
+ break;
+ case BC_GSET:
+ | ins_AND // RA = src, RD = str const (~)
+ | mov LFUNC:RB, [BASE-8]
+ | mov TAB:RB, LFUNC:RB->env
+ | mov STR:RC, [KBASE+RD*4]
+ | jmp ->BC_TSETS_Z
+ break;
+
+ case BC_TGETV:
+ | ins_ABC // RA = dst, RB = table, RC = key
+ | checktab RB, ->vmeta_tgetv
+ | mov TAB:RB, [BASE+RB*8]
+ |
+ | // Integer key?
+ |.if DUALNUM
+ | checkint RC, >5
+ | mov RC, dword [BASE+RC*8]
+ |.else
+ | // Convert number to int and back and compare.
+ | checknum RC, >5
+ |.if SSE
+ | movsd xmm0, qword [BASE+RC*8]
+ | cvtsd2si RC, xmm0
+ | cvtsi2sd xmm1, RC
+ | ucomisd xmm0, xmm1
+ |.else
+ | fld qword [BASE+RC*8]
+ | fist ARG1
+ | fild ARG1
+ | fcomparepp
+ | mov RC, ARG1
+ |.endif
+ | jne ->vmeta_tgetv // Generic numeric key? Use fallback.
+ |.endif
+ | cmp RC, TAB:RB->asize // Takes care of unordered, too.
+ | jae ->vmeta_tgetv // Not in array part? Use fallback.
+ | shl RC, 3
+ | add RC, TAB:RB->array
+ | cmp dword [RC+4], LJ_TNIL // Avoid overwriting RB in fastpath.
+ | je >2
+ | // Get array slot.
+ |.if X64
+ | mov RBa, [RC]
+ | mov [BASE+RA*8], RBa
+ |.else
+ | mov RB, [RC]
+ | mov RC, [RC+4]
+ | mov [BASE+RA*8], RB
+ | mov [BASE+RA*8+4], RC
+ |.endif
+ |1:
+ | ins_next
+ |
+ |2: // Check for __index if table value is nil.
+ | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath.
+ | jz >3
+ | mov TAB:RA, TAB:RB->metatable
+ | test byte TAB:RA->nomm, 1<<MM_index
+ | jz ->vmeta_tgetv // 'no __index' flag NOT set: check.
+ | movzx RA, PC_RA // Restore RA.
+ |3:
+ | mov dword [BASE+RA*8+4], LJ_TNIL
+ | jmp <1
+ |
+ |5: // String key?
+ | checkstr RC, ->vmeta_tgetv
+ | mov STR:RC, [BASE+RC*8]
+ | jmp ->BC_TGETS_Z
+ break;
+ case BC_TGETS:
+ | ins_ABC // RA = dst, RB = table, RC = str const (~)
+ | not RCa
+ | mov STR:RC, [KBASE+RC*4]
+ | checktab RB, ->vmeta_tgets
+ | mov TAB:RB, [BASE+RB*8]
+ |->BC_TGETS_Z: // RB = GCtab *, RC = GCstr *, refetches PC_RA.
+ | mov RA, TAB:RB->hmask
+ | and RA, STR:RC->hash
+ | imul RA, #NODE
+ | add NODE:RA, TAB:RB->node
+ |1:
+ | cmp dword NODE:RA->key.it, LJ_TSTR
+ | jne >4
+ | cmp dword NODE:RA->key.gcr, STR:RC
+ | jne >4
+ | // Ok, key found. Assumes: offsetof(Node, val) == 0
+ | cmp dword [RA+4], LJ_TNIL // Avoid overwriting RB in fastpath.
+ | je >5 // Key found, but nil value?
+ | movzx RC, PC_RA
+ | // Get node value.
+ |.if X64
+ | mov RBa, [RA]
+ | mov [BASE+RC*8], RBa
+ |.else
+ | mov RB, [RA]
+ | mov RA, [RA+4]
+ | mov [BASE+RC*8], RB
+ | mov [BASE+RC*8+4], RA
+ |.endif
+ |2:
+ | ins_next
+ |
+ |3:
+ | movzx RC, PC_RA
+ | mov dword [BASE+RC*8+4], LJ_TNIL
+ | jmp <2
+ |
+ |4: // Follow hash chain.
+ | mov NODE:RA, NODE:RA->next
+ | test NODE:RA, NODE:RA
+ | jnz <1
+ | // End of hash chain: key not found, nil result.
+ |
+ |5: // Check for __index if table value is nil.
+ | mov TAB:RA, TAB:RB->metatable
+ | test TAB:RA, TAB:RA
+ | jz <3 // No metatable: done.
+ | test byte TAB:RA->nomm, 1<<MM_index
+ | jnz <3 // 'no __index' flag set: done.
+ | jmp ->vmeta_tgets // Caveat: preserve STR:RC.
+ break;
+ case BC_TGETB:
+ | ins_ABC // RA = dst, RB = table, RC = byte literal
+ | checktab RB, ->vmeta_tgetb
+ | mov TAB:RB, [BASE+RB*8]
+ | cmp RC, TAB:RB->asize
+ | jae ->vmeta_tgetb
+ | shl RC, 3
+ | add RC, TAB:RB->array
+ | cmp dword [RC+4], LJ_TNIL // Avoid overwriting RB in fastpath.
+ | je >2
+ | // Get array slot.
+ |.if X64
+ | mov RBa, [RC]
+ | mov [BASE+RA*8], RBa
+ |.else
+ | mov RB, [RC]
+ | mov RC, [RC+4]
+ | mov [BASE+RA*8], RB
+ | mov [BASE+RA*8+4], RC
+ |.endif
+ |1:
+ | ins_next
+ |
+ |2: // Check for __index if table value is nil.
+ | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath.
+ | jz >3
+ | mov TAB:RA, TAB:RB->metatable
+ | test byte TAB:RA->nomm, 1<<MM_index
+ | jz ->vmeta_tgetb // 'no __index' flag NOT set: check.
+ | movzx RA, PC_RA // Restore RA.
+ |3:
+ | mov dword [BASE+RA*8+4], LJ_TNIL
+ | jmp <1
+ break;
+
+ case BC_TSETV:
+ | ins_ABC // RA = src, RB = table, RC = key
+ | checktab RB, ->vmeta_tsetv
+ | mov TAB:RB, [BASE+RB*8]
+ |
+ | // Integer key?
+ |.if DUALNUM
+ | checkint RC, >5
+ | mov RC, dword [BASE+RC*8]
+ |.else
+ | // Convert number to int and back and compare.
+ | checknum RC, >5
+ |.if SSE
+ | movsd xmm0, qword [BASE+RC*8]
+ | cvtsd2si RC, xmm0
+ | cvtsi2sd xmm1, RC
+ | ucomisd xmm0, xmm1
+ |.else
+ | fld qword [BASE+RC*8]
+ | fist ARG1
+ | fild ARG1
+ | fcomparepp
+ | mov RC, ARG1
+ |.endif
+ | jne ->vmeta_tsetv // Generic numeric key? Use fallback.
+ |.endif
+ | cmp RC, TAB:RB->asize // Takes care of unordered, too.
+ | jae ->vmeta_tsetv
+ | shl RC, 3
+ | add RC, TAB:RB->array
+ | cmp dword [RC+4], LJ_TNIL
+ | je >3 // Previous value is nil?
+ |1:
+ | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table)
+ | jnz >7
+ |2: // Set array slot.
+ |.if X64
+ | mov RBa, [BASE+RA*8]
+ | mov [RC], RBa
+ |.else
+ | mov RB, [BASE+RA*8+4]
+ | mov RA, [BASE+RA*8]
+ | mov [RC+4], RB
+ | mov [RC], RA
+ |.endif
+ | ins_next
+ |
+ |3: // Check for __newindex if previous value is nil.
+ | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath.
+ | jz <1
+ | mov TAB:RA, TAB:RB->metatable
+ | test byte TAB:RA->nomm, 1<<MM_newindex
+ | jz ->vmeta_tsetv // 'no __newindex' flag NOT set: check.
+ | movzx RA, PC_RA // Restore RA.
+ | jmp <1
+ |
+ |5: // String key?
+ | checkstr RC, ->vmeta_tsetv
+ | mov STR:RC, [BASE+RC*8]
+ | jmp ->BC_TSETS_Z
+ |
+ |7: // Possible table write barrier for the value. Skip valiswhite check.
+ | barrierback TAB:RB, RA
+ | movzx RA, PC_RA // Restore RA.
+ | jmp <2
+ break;
+ case BC_TSETS:
+ | ins_ABC // RA = src, RB = table, RC = str const (~)
+ | not RCa
+ | mov STR:RC, [KBASE+RC*4]
+ | checktab RB, ->vmeta_tsets
+ | mov TAB:RB, [BASE+RB*8]
+ |->BC_TSETS_Z: // RB = GCtab *, RC = GCstr *, refetches PC_RA.
+ | mov RA, TAB:RB->hmask
+ | and RA, STR:RC->hash
+ | imul RA, #NODE
+ | mov byte TAB:RB->nomm, 0 // Clear metamethod cache.
+ | add NODE:RA, TAB:RB->node
+ |1:
+ | cmp dword NODE:RA->key.it, LJ_TSTR
+ | jne >5
+ | cmp dword NODE:RA->key.gcr, STR:RC
+ | jne >5
+ | // Ok, key found. Assumes: offsetof(Node, val) == 0
+ | cmp dword [RA+4], LJ_TNIL
+ | je >4 // Previous value is nil?
+ |2:
+ | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table)
+ | jnz >7
+ |3: // Set node value.
+ | movzx RC, PC_RA
+ |.if X64
+ | mov RBa, [BASE+RC*8]
+ | mov [RA], RBa
+ |.else
+ | mov RB, [BASE+RC*8+4]
+ | mov RC, [BASE+RC*8]
+ | mov [RA+4], RB
+ | mov [RA], RC
+ |.endif
+ | ins_next
+ |
+ |4: // Check for __newindex if previous value is nil.
+ | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath.
+ | jz <2
+ | mov TMP1, RA // Save RA.
+ | mov TAB:RA, TAB:RB->metatable
+ | test byte TAB:RA->nomm, 1<<MM_newindex
+ | jz ->vmeta_tsets // 'no __newindex' flag NOT set: check.
+ | mov RA, TMP1 // Restore RA.
+ | jmp <2
+ |
+ |5: // Follow hash chain.
+ | mov NODE:RA, NODE:RA->next
+ | test NODE:RA, NODE:RA
+ | jnz <1
+ | // End of hash chain: key not found, add a new one.
+ |
+ | // But check for __newindex first.
+ | mov TAB:RA, TAB:RB->metatable
+ | test TAB:RA, TAB:RA
+ | jz >6 // No metatable: continue.
+ | test byte TAB:RA->nomm, 1<<MM_newindex
+ | jz ->vmeta_tsets // 'no __newindex' flag NOT set: check.
+ |6:
+ | mov TMP1, STR:RC
+ | mov TMP2, LJ_TSTR
+ | mov TMP3, TAB:RB // Save TAB:RB for us.
+ |.if X64
+ | mov L:CARG1d, SAVE_L
+ | mov L:CARG1d->base, BASE
+ | lea CARG3, TMP1
+ | mov CARG2d, TAB:RB
+ | mov L:RB, L:CARG1d
+ |.else
+ | lea RC, TMP1 // Store temp. TValue in TMP1/TMP2.
+ | mov ARG2, TAB:RB
+ | mov L:RB, SAVE_L
+ | mov ARG3, RC
+ | mov ARG1, L:RB
+ | mov L:RB->base, BASE
+ |.endif
+ | mov SAVE_PC, PC
+ | call extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k)
+ | // Handles write barrier for the new key. TValue * returned in eax (RC).
+ | mov BASE, L:RB->base
+ | mov TAB:RB, TMP3 // Need TAB:RB for barrier.
+ | mov RA, eax
+ | jmp <2 // Must check write barrier for value.
+ |
+ |7: // Possible table write barrier for the value. Skip valiswhite check.
+ | barrierback TAB:RB, RC // Destroys STR:RC.
+ | jmp <3
+ break;
+ case BC_TSETB:
+ | ins_ABC // RA = src, RB = table, RC = byte literal
+ | checktab RB, ->vmeta_tsetb
+ | mov TAB:RB, [BASE+RB*8]
+ | cmp RC, TAB:RB->asize
+ | jae ->vmeta_tsetb
+ | shl RC, 3
+ | add RC, TAB:RB->array
+ | cmp dword [RC+4], LJ_TNIL
+ | je >3 // Previous value is nil?
+ |1:
+ | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table)
+ | jnz >7
+ |2: // Set array slot.
+ |.if X64
+ | mov RAa, [BASE+RA*8]
+ | mov [RC], RAa
+ |.else
+ | mov RB, [BASE+RA*8+4]
+ | mov RA, [BASE+RA*8]
+ | mov [RC+4], RB
+ | mov [RC], RA
+ |.endif
+ | ins_next
+ |
+ |3: // Check for __newindex if previous value is nil.
+ | cmp dword TAB:RB->metatable, 0 // Shouldn't overwrite RA for fastpath.
+ | jz <1
+ | mov TAB:RA, TAB:RB->metatable
+ | test byte TAB:RA->nomm, 1<<MM_newindex
+ | jz ->vmeta_tsetb // 'no __newindex' flag NOT set: check.
+ | movzx RA, PC_RA // Restore RA.
+ | jmp <1
+ |
+ |7: // Possible table write barrier for the value. Skip valiswhite check.
+ | barrierback TAB:RB, RA
+ | movzx RA, PC_RA // Restore RA.
+ | jmp <2
+ break;
+
+ case BC_TSETM:
+ | ins_AD // RA = base (table at base-1), RD = num const (start index)
+ | mov TMP1, KBASE // Need one more free register.
+ | mov KBASE, dword [KBASE+RD*8] // Integer constant is in lo-word.
+ |1:
+ | lea RA, [BASE+RA*8]
+ | mov TAB:RB, [RA-8] // Guaranteed to be a table.
+ | test byte TAB:RB->marked, LJ_GC_BLACK // isblack(table)
+ | jnz >7
+ |2:
+ | mov RD, MULTRES
+ | sub RD, 1
+ | jz >4 // Nothing to copy?
+ | add RD, KBASE // Compute needed size.
+ | cmp RD, TAB:RB->asize
+ | ja >5 // Doesn't fit into array part?
+ | sub RD, KBASE
+ | shl KBASE, 3
+ | add KBASE, TAB:RB->array
+ |3: // Copy result slots to table.
+ |.if X64
+ | mov RBa, [RA]
+ | add RA, 8
+ | mov [KBASE], RBa
+ |.else
+ | mov RB, [RA]
+ | mov [KBASE], RB
+ | mov RB, [RA+4]
+ | add RA, 8
+ | mov [KBASE+4], RB
+ |.endif
+ | add KBASE, 8
+ | sub RD, 1
+ | jnz <3
+ |4:
+ | mov KBASE, TMP1
+ | ins_next
+ |
+ |5: // Need to resize array part.
+ |.if X64
+ | mov L:CARG1d, SAVE_L
+ | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE.
+ | mov CARG2d, TAB:RB
+ | mov CARG3d, RD
+ | mov L:RB, L:CARG1d
+ |.else
+ | mov ARG2, TAB:RB
+ | mov L:RB, SAVE_L
+ | mov L:RB->base, BASE
+ | mov ARG3, RD
+ | mov ARG1, L:RB
+ |.endif
+ | mov SAVE_PC, PC
+ | call extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize)
+ | mov BASE, L:RB->base
+ | movzx RA, PC_RA // Restore RA.
+ | jmp <1 // Retry.
+ |
+ |7: // Possible table write barrier for any value. Skip valiswhite check.
+ | barrierback TAB:RB, RD
+ | jmp <2
+ break;
+
+ /* -- Calls and vararg handling ----------------------------------------- */
+
+ case BC_CALL: case BC_CALLM:
+ | ins_A_C // RA = base, (RB = nresults+1,) RC = nargs+1 | extra_nargs
+ if (op == BC_CALLM) {
+ | add NARGS:RD, MULTRES
+ }
+ | cmp dword [BASE+RA*8+4], LJ_TFUNC
+ | mov LFUNC:RB, [BASE+RA*8]
+ | jne ->vmeta_call_ra
+ | lea BASE, [BASE+RA*8+8]
+ | ins_call
+ break;
+
+ case BC_CALLMT:
+ | ins_AD // RA = base, RD = extra_nargs
+ | add NARGS:RD, MULTRES
+ | // Fall through. Assumes BC_CALLT follows and ins_AD is a no-op.
+ break;
+ case BC_CALLT:
+ | ins_AD // RA = base, RD = nargs+1
+ | lea RA, [BASE+RA*8+8]
+ | mov KBASE, BASE // Use KBASE for move + vmeta_call hint.
+ | mov LFUNC:RB, [RA-8]
+ | cmp dword [RA-4], LJ_TFUNC
+ | jne ->vmeta_call
+ |->BC_CALLT_Z:
+ | mov PC, [BASE-4]
+ | test PC, FRAME_TYPE
+ | jnz >7
+ |1:
+ | mov [BASE-8], LFUNC:RB // Copy function down, reloaded below.
+ | mov MULTRES, NARGS:RD
+ | sub NARGS:RD, 1
+ | jz >3
+ |2: // Move args down.
+ |.if X64
+ | mov RBa, [RA]
+ | add RA, 8
+ | mov [KBASE], RBa
+ |.else
+ | mov RB, [RA]
+ | mov [KBASE], RB
+ | mov RB, [RA+4]
+ | add RA, 8
+ | mov [KBASE+4], RB
+ |.endif
+ | add KBASE, 8
+ | sub NARGS:RD, 1
+ | jnz <2
+ |
+ | mov LFUNC:RB, [BASE-8]
+ |3:
+ | mov NARGS:RD, MULTRES
+ | cmp byte LFUNC:RB->ffid, 1 // (> FF_C) Calling a fast function?
+ | ja >5
+ |4:
+ | ins_callt
+ |
+ |5: // Tailcall to a fast function.
+ | test PC, FRAME_TYPE // Lua frame below?
+ | jnz <4
+ | movzx RA, PC_RA
+ | not RAa
+ | mov LFUNC:KBASE, [BASE+RA*8-8] // Need to prepare KBASE.
+ | mov KBASE, LFUNC:KBASE->pc
+ | mov KBASE, [KBASE+PC2PROTO(k)]
+ | jmp <4
+ |
+ |7: // Tailcall from a vararg function.
+ | sub PC, FRAME_VARG
+ | test PC, FRAME_TYPEP
+ | jnz >8 // Vararg frame below?
+ | sub BASE, PC // Need to relocate BASE/KBASE down.
+ | mov KBASE, BASE
+ | mov PC, [BASE-4]
+ | jmp <1
+ |8:
+ | add PC, FRAME_VARG
+ | jmp <1
+ break;
+
+ case BC_ITERC:
+ | ins_A // RA = base, (RB = nresults+1,) RC = nargs+1 (2+1)
+ | lea RA, [BASE+RA*8+8] // fb = base+1
+ |.if X64
+ | mov RBa, [RA-24] // Copy state. fb[0] = fb[-3].
+ | mov RCa, [RA-16] // Copy control var. fb[1] = fb[-2].
+ | mov [RA], RBa
+ | mov [RA+8], RCa
+ |.else
+ | mov RB, [RA-24] // Copy state. fb[0] = fb[-3].
+ | mov RC, [RA-20]
+ | mov [RA], RB
+ | mov [RA+4], RC
+ | mov RB, [RA-16] // Copy control var. fb[1] = fb[-2].
+ | mov RC, [RA-12]
+ | mov [RA+8], RB
+ | mov [RA+12], RC
+ |.endif
+ | mov LFUNC:RB, [RA-32] // Copy callable. fb[-1] = fb[-4]
+ | mov RC, [RA-28]
+ | mov [RA-8], LFUNC:RB
+ | mov [RA-4], RC
+ | cmp RC, LJ_TFUNC // Handle like a regular 2-arg call.
+ | mov NARGS:RD, 2+1
+ | jne ->vmeta_call
+ | mov BASE, RA
+ | ins_call
+ break;
+
+ case BC_ITERN:
+ | ins_A // RA = base, (RB = nresults+1, RC = nargs+1 (2+1))
+ |.if JIT
+ | // NYI: add hotloop, record BC_ITERN.
+ |.endif
+ | mov TMP1, KBASE // Need two more free registers.
+ | mov TMP2, DISPATCH
+ | mov TAB:RB, [BASE+RA*8-16]
+ | mov RC, [BASE+RA*8-8] // Get index from control var.
+ | mov DISPATCH, TAB:RB->asize
+ | add PC, 4
+ | mov KBASE, TAB:RB->array
+ |1: // Traverse array part.
+ | cmp RC, DISPATCH; jae >5 // Index points after array part?
+ | cmp dword [KBASE+RC*8+4], LJ_TNIL; je >4
+ |.if DUALNUM
+ | mov dword [BASE+RA*8+4], LJ_TISNUM
+ | mov dword [BASE+RA*8], RC
+ |.elif SSE
+ | cvtsi2sd xmm0, RC
+ |.else
+ | fild dword [BASE+RA*8-8]
+ |.endif
+ | // Copy array slot to returned value.
+ |.if X64
+ | mov RBa, [KBASE+RC*8]
+ | mov [BASE+RA*8+8], RBa
+ |.else
+ | mov RB, [KBASE+RC*8+4]
+ | mov [BASE+RA*8+12], RB
+ | mov RB, [KBASE+RC*8]
+ | mov [BASE+RA*8+8], RB
+ |.endif
+ | add RC, 1
+ | // Return array index as a numeric key.
+ |.if DUALNUM
+ | // See above.
+ |.elif SSE
+ | movsd qword [BASE+RA*8], xmm0
+ |.else
+ | fstp qword [BASE+RA*8]
+ |.endif
+ | mov [BASE+RA*8-8], RC // Update control var.
+ |2:
+ | movzx RD, PC_RD // Get target from ITERL.
+ | branchPC RD
+ |3:
+ | mov DISPATCH, TMP2
+ | mov KBASE, TMP1
+ | ins_next
+ |
+ |4: // Skip holes in array part.
+ | add RC, 1
+ |.if not (DUALNUM or SSE)
+ | mov [BASE+RA*8-8], RC
+ |.endif
+ | jmp <1
+ |
+ |5: // Traverse hash part.
+ | sub RC, DISPATCH
+ |6:
+ | cmp RC, TAB:RB->hmask; ja <3 // End of iteration? Branch to ITERL+1.
+ | imul KBASE, RC, #NODE
+ | add NODE:KBASE, TAB:RB->node
+ | cmp dword NODE:KBASE->val.it, LJ_TNIL; je >7
+ | lea DISPATCH, [RC+DISPATCH+1]
+ | // Copy key and value from hash slot.
+ |.if X64
+ | mov RBa, NODE:KBASE->key
+ | mov RCa, NODE:KBASE->val
+ | mov [BASE+RA*8], RBa
+ | mov [BASE+RA*8+8], RCa
+ |.else
+ | mov RB, NODE:KBASE->key.gcr
+ | mov RC, NODE:KBASE->key.it
+ | mov [BASE+RA*8], RB
+ | mov [BASE+RA*8+4], RC
+ | mov RB, NODE:KBASE->val.gcr
+ | mov RC, NODE:KBASE->val.it
+ | mov [BASE+RA*8+8], RB
+ | mov [BASE+RA*8+12], RC
+ |.endif
+ | mov [BASE+RA*8-8], DISPATCH
+ | jmp <2
+ |
+ |7: // Skip holes in hash part.
+ | add RC, 1
+ | jmp <6
+ break;
+
+ case BC_ISNEXT:
+ | ins_AD // RA = base, RD = target (points to ITERN)
+ | cmp dword [BASE+RA*8-20], LJ_TFUNC; jne >5
+ | mov CFUNC:RB, [BASE+RA*8-24]
+ | cmp dword [BASE+RA*8-12], LJ_TTAB; jne >5
+ | cmp dword [BASE+RA*8-4], LJ_TNIL; jne >5
+ | cmp byte CFUNC:RB->ffid, FF_next_N; jne >5
+ | branchPC RD
+ | mov dword [BASE+RA*8-8], 0 // Initialize control var.
+ | mov dword [BASE+RA*8-4], 0xfffe7fff
+ |1:
+ | ins_next
+ |5: // Despecialize bytecode if any of the checks fail.
+ | mov PC_OP, BC_JMP
+ | branchPC RD
+ | mov byte [PC], BC_ITERC
+ | jmp <1
+ break;
+
+ case BC_VARG:
+ | ins_ABC // RA = base, RB = nresults+1, RC = numparams
+ | mov TMP1, KBASE // Need one more free register.
+ | lea KBASE, [BASE+RC*8+(8+FRAME_VARG)]
+ | lea RA, [BASE+RA*8]
+ | sub KBASE, [BASE-4]
+ | // Note: KBASE may now be even _above_ BASE if nargs was < numparams.
+ | test RB, RB
+ | jz >5 // Copy all varargs?
+ | lea RB, [RA+RB*8-8]
+ | cmp KBASE, BASE // No vararg slots?
+ | jnb >2
+ |1: // Copy vararg slots to destination slots.
+ |.if X64
+ | mov RCa, [KBASE-8]
+ | add KBASE, 8
+ | mov [RA], RCa
+ |.else
+ | mov RC, [KBASE-8]
+ | mov [RA], RC
+ | mov RC, [KBASE-4]
+ | add KBASE, 8
+ | mov [RA+4], RC
+ |.endif
+ | add RA, 8
+ | cmp RA, RB // All destination slots filled?
+ | jnb >3
+ | cmp KBASE, BASE // No more vararg slots?
+ | jb <1
+ |2: // Fill up remainder with nil.
+ | mov dword [RA+4], LJ_TNIL
+ | add RA, 8
+ | cmp RA, RB
+ | jb <2
+ |3:
+ | mov KBASE, TMP1
+ | ins_next
+ |
+ |5: // Copy all varargs.
+ | mov MULTRES, 1 // MULTRES = 0+1
+ | mov RC, BASE
+ | sub RC, KBASE
+ | jbe <3 // No vararg slots?
+ | mov RB, RC
+ | shr RB, 3
+ | add RB, 1
+ | mov MULTRES, RB // MULTRES = #varargs+1
+ | mov L:RB, SAVE_L
+ | add RC, RA
+ | cmp RC, L:RB->maxstack
+ | ja >7 // Need to grow stack?
+ |6: // Copy all vararg slots.
+ |.if X64
+ | mov RCa, [KBASE-8]
+ | add KBASE, 8
+ | mov [RA], RCa
+ |.else
+ | mov RC, [KBASE-8]
+ | mov [RA], RC
+ | mov RC, [KBASE-4]
+ | add KBASE, 8
+ | mov [RA+4], RC
+ |.endif
+ | add RA, 8
+ | cmp KBASE, BASE // No more vararg slots?
+ | jb <6
+ | jmp <3
+ |
+ |7: // Grow stack for varargs.
+ | mov L:RB->base, BASE
+ | mov L:RB->top, RA
+ | mov SAVE_PC, PC
+ | sub KBASE, BASE // Need delta, because BASE may change.
+ | mov FCARG2, MULTRES
+ | sub FCARG2, 1
+ | mov FCARG1, L:RB
+ | call extern lj_state_growstack@8 // (lua_State *L, int n)
+ | mov BASE, L:RB->base
+ | mov RA, L:RB->top
+ | add KBASE, BASE
+ | jmp <6
+ break;
+
+ /* -- Returns ----------------------------------------------------------- */
+
+ case BC_RETM:
+ | ins_AD // RA = results, RD = extra_nresults
+ | add RD, MULTRES // MULTRES >=1, so RD >=1.
+ | // Fall through. Assumes BC_RET follows and ins_AD is a no-op.
+ break;
+
+ case BC_RET: case BC_RET0: case BC_RET1:
+ | ins_AD // RA = results, RD = nresults+1
+ if (op != BC_RET0) {
+ | shl RA, 3
+ }
+ |1:
+ | mov PC, [BASE-4]
+ | mov MULTRES, RD // Save nresults+1.
+ | test PC, FRAME_TYPE // Check frame type marker.
+ | jnz >7 // Not returning to a fixarg Lua func?
+ switch (op) {
+ case BC_RET:
+ |->BC_RET_Z:
+ | mov KBASE, BASE // Use KBASE for result move.
+ | sub RD, 1
+ | jz >3
+ |2: // Move results down.
+ |.if X64
+ | mov RBa, [KBASE+RA]
+ | mov [KBASE-8], RBa
+ |.else
+ | mov RB, [KBASE+RA]
+ | mov [KBASE-8], RB
+ | mov RB, [KBASE+RA+4]
+ | mov [KBASE-4], RB
+ |.endif
+ | add KBASE, 8
+ | sub RD, 1
+ | jnz <2
+ |3:
+ | mov RD, MULTRES // Note: MULTRES may be >255.
+ | movzx RB, PC_RB // So cannot compare with RDL!
+ |5:
+ | cmp RB, RD // More results expected?
+ | ja >6
+ break;
+ case BC_RET1:
+ |.if X64
+ | mov RBa, [BASE+RA]
+ | mov [BASE-8], RBa
+ |.else
+ | mov RB, [BASE+RA+4]
+ | mov [BASE-4], RB
+ | mov RB, [BASE+RA]
+ | mov [BASE-8], RB
+ |.endif
+ /* fallthrough */
+ case BC_RET0:
+ |5:
+ | cmp PC_RB, RDL // More results expected?
+ | ja >6
+ default:
+ break;
+ }
+ | movzx RA, PC_RA
+ | not RAa // Note: ~RA = -(RA+1)
+ | lea BASE, [BASE+RA*8] // base = base - (RA+1)*8
+ | mov LFUNC:KBASE, [BASE-8]
+ | mov KBASE, LFUNC:KBASE->pc
+ | mov KBASE, [KBASE+PC2PROTO(k)]
+ | ins_next
+ |
+ |6: // Fill up results with nil.
+ if (op == BC_RET) {
+ | mov dword [KBASE-4], LJ_TNIL // Note: relies on shifted base.
+ | add KBASE, 8
+ } else {
+ | mov dword [BASE+RD*8-12], LJ_TNIL
+ }
+ | add RD, 1
+ | jmp <5
+ |
+ |7: // Non-standard return case.
+ | lea RB, [PC-FRAME_VARG]
+ | test RB, FRAME_TYPEP
+ | jnz ->vm_return
+ | // Return from vararg function: relocate BASE down and RA up.
+ | sub BASE, RB
+ if (op != BC_RET0) {
+ | add RA, RB
+ }
+ | jmp <1
+ break;
+
+ /* -- Loops and branches ------------------------------------------------ */
+
+ |.define FOR_IDX, [RA]; .define FOR_TIDX, dword [RA+4]
+ |.define FOR_STOP, [RA+8]; .define FOR_TSTOP, dword [RA+12]
+ |.define FOR_STEP, [RA+16]; .define FOR_TSTEP, dword [RA+20]
+ |.define FOR_EXT, [RA+24]; .define FOR_TEXT, dword [RA+28]
+
+ case BC_FORL:
+ |.if JIT
+ | hotloop RB
+ |.endif
+ | // Fall through. Assumes BC_IFORL follows and ins_AJ is a no-op.
+ break;
+
+ case BC_JFORI:
+ case BC_JFORL:
+#if !LJ_HASJIT
+ break;
+#endif
+ case BC_FORI:
+ case BC_IFORL:
+ vk = (op == BC_IFORL || op == BC_JFORL);
+ | ins_AJ // RA = base, RD = target (after end of loop or start of loop)
+ | lea RA, [BASE+RA*8]
+ if (LJ_DUALNUM) {
+ | cmp FOR_TIDX, LJ_TISNUM; jne >9
+ if (!vk) {
+ | cmp FOR_TSTOP, LJ_TISNUM; jne ->vmeta_for
+ | cmp FOR_TSTEP, LJ_TISNUM; jne ->vmeta_for
+ | mov RB, dword FOR_IDX
+ | cmp dword FOR_STEP, 0; jl >5
+ } else {
+#ifdef LUA_USE_ASSERT
+ | cmp FOR_TSTOP, LJ_TISNUM; jne ->assert_bad_for_arg_type
+ | cmp FOR_TSTEP, LJ_TISNUM; jne ->assert_bad_for_arg_type
+#endif
+ | mov RB, dword FOR_STEP
+ | test RB, RB; js >5
+ | add RB, dword FOR_IDX; jo >1
+ | mov dword FOR_IDX, RB
+ }
+ | cmp RB, dword FOR_STOP
+ | mov FOR_TEXT, LJ_TISNUM
+ | mov dword FOR_EXT, RB
+ if (op == BC_FORI) {
+ | jle >7
+ |1:
+ |6:
+ | branchPC RD
+ } else if (op == BC_JFORI) {
+ | branchPC RD
+ | movzx RD, PC_RD
+ | jle =>BC_JLOOP
+ |1:
+ |6:
+ } else if (op == BC_IFORL) {
+ | jg >7
+ |6:
+ | branchPC RD
+ |1:
+ } else {
+ | jle =>BC_JLOOP
+ |1:
+ |6:
+ }
+ |7:
+ | ins_next
+ |
+ |5: // Invert check for negative step.
+ if (vk) {
+ | add RB, dword FOR_IDX; jo <1
+ | mov dword FOR_IDX, RB
+ }
+ | cmp RB, dword FOR_STOP
+ | mov FOR_TEXT, LJ_TISNUM
+ | mov dword FOR_EXT, RB
+ if (op == BC_FORI) {
+ | jge <7
+ } else if (op == BC_JFORI) {
+ | branchPC RD
+ | movzx RD, PC_RD
+ | jge =>BC_JLOOP
+ } else if (op == BC_IFORL) {
+ | jl <7
+ } else {
+ | jge =>BC_JLOOP
+ }
+ | jmp <6
+ |9: // Fallback to FP variant.
+ } else if (!vk) {
+ | cmp FOR_TIDX, LJ_TISNUM
+ }
+ if (!vk) {
+ | jae ->vmeta_for
+ | cmp FOR_TSTOP, LJ_TISNUM; jae ->vmeta_for
+ } else {
+#ifdef LUA_USE_ASSERT
+ | cmp FOR_TSTOP, LJ_TISNUM; jae ->assert_bad_for_arg_type
+ | cmp FOR_TSTEP, LJ_TISNUM; jae ->assert_bad_for_arg_type
+#endif
+ }
+ | mov RB, FOR_TSTEP // Load type/hiword of for step.
+ if (!vk) {
+ | cmp RB, LJ_TISNUM; jae ->vmeta_for
+ }
+ |.if SSE
+ | movsd xmm0, qword FOR_IDX
+ | movsd xmm1, qword FOR_STOP
+ if (vk) {
+ | addsd xmm0, qword FOR_STEP
+ | movsd qword FOR_IDX, xmm0
+ | test RB, RB; js >3
+ } else {
+ | jl >3
+ }
+ | ucomisd xmm1, xmm0
+ |1:
+ | movsd qword FOR_EXT, xmm0
+ |.else
+ | fld qword FOR_STOP
+ | fld qword FOR_IDX
+ if (vk) {
+ | fadd qword FOR_STEP // nidx = idx + step
+ | fst qword FOR_IDX
+ | fst qword FOR_EXT
+ | test RB, RB; js >1
+ } else {
+ | fst qword FOR_EXT
+ | jl >1
+ }
+ | fxch // Swap lim/(n)idx if step non-negative.
+ |1:
+ | fcomparepp
+ |.endif
+ if (op == BC_FORI) {
+ |.if DUALNUM
+ | jnb <7
+ |.else
+ | jnb >2
+ | branchPC RD
+ |.endif
+ } else if (op == BC_JFORI) {
+ | branchPC RD
+ | movzx RD, PC_RD
+ | jnb =>BC_JLOOP
+ } else if (op == BC_IFORL) {
+ |.if DUALNUM
+ | jb <7
+ |.else
+ | jb >2
+ | branchPC RD
+ |.endif
+ } else {
+ | jnb =>BC_JLOOP
+ }
+ |.if DUALNUM
+ | jmp <6
+ |.else
+ |2:
+ | ins_next
+ |.endif
+ |.if SSE
+ |3: // Invert comparison if step is negative.
+ | ucomisd xmm0, xmm1
+ | jmp <1
+ |.endif
+ break;
+
+ case BC_ITERL:
+ |.if JIT
+ | hotloop RB
+ |.endif
+ | // Fall through. Assumes BC_IITERL follows and ins_AJ is a no-op.
+ break;
+
+ case BC_JITERL:
+#if !LJ_HASJIT
+ break;
+#endif
+ case BC_IITERL:
+ | ins_AJ // RA = base, RD = target
+ | lea RA, [BASE+RA*8]
+ | mov RB, [RA+4]
+ | cmp RB, LJ_TNIL; je >1 // Stop if iterator returned nil.
+ if (op == BC_JITERL) {
+ | mov [RA-4], RB
+ | mov RB, [RA]
+ | mov [RA-8], RB
+ | jmp =>BC_JLOOP
+ } else {
+ | branchPC RD // Otherwise save control var + branch.
+ | mov RD, [RA]
+ | mov [RA-4], RB
+ | mov [RA-8], RD
+ }
+ |1:
+ | ins_next
+ break;
+
+ case BC_LOOP:
+ | ins_A // RA = base, RD = target (loop extent)
+ | // Note: RA/RD is only used by trace recorder to determine scope/extent
+ | // This opcode does NOT jump, it's only purpose is to detect a hot loop.
+ |.if JIT
+ | hotloop RB
+ |.endif
+ | // Fall through. Assumes BC_ILOOP follows and ins_A is a no-op.
+ break;
+
+ case BC_ILOOP:
+ | ins_A // RA = base, RD = target (loop extent)
+ | ins_next
+ break;
+
+ case BC_JLOOP:
+ |.if JIT
+ | ins_AD // RA = base (ignored), RD = traceno
+ | mov RA, [DISPATCH+DISPATCH_J(trace)]
+ | mov TRACE:RD, [RA+RD*4]
+ | mov RDa, TRACE:RD->mcode
+ | mov L:RB, SAVE_L
+ | mov [DISPATCH+DISPATCH_GL(jit_base)], BASE
+ | mov [DISPATCH+DISPATCH_GL(jit_L)], L:RB
+ | // Save additional callee-save registers only used in compiled code.
+ |.if X64WIN
+ | mov TMPQ, r12
+ | mov TMPa, r13
+ | mov CSAVE_4, r14
+ | mov CSAVE_3, r15
+ | mov RAa, rsp
+ | sub rsp, 9*16+4*8
+ | movdqa [RAa], xmm6
+ | movdqa [RAa-1*16], xmm7
+ | movdqa [RAa-2*16], xmm8
+ | movdqa [RAa-3*16], xmm9
+ | movdqa [RAa-4*16], xmm10
+ | movdqa [RAa-5*16], xmm11
+ | movdqa [RAa-6*16], xmm12
+ | movdqa [RAa-7*16], xmm13
+ | movdqa [RAa-8*16], xmm14
+ | movdqa [RAa-9*16], xmm15
+ |.elif X64
+ | mov TMPQ, r12
+ | mov TMPa, r13
+ | sub rsp, 16
+ |.endif
+ | jmp RDa
+ |.endif
+ break;
+
+ case BC_JMP:
+ | ins_AJ // RA = unused, RD = target
+ | branchPC RD
+ | ins_next
+ break;
+
+ /* -- Function headers -------------------------------------------------- */
+
+ /*
+ ** Reminder: A function may be called with func/args above L->maxstack,
+ ** i.e. occupying EXTRA_STACK slots. And vmeta_call may add one extra slot,
+ ** too. This means all FUNC* ops (including fast functions) must check
+ ** for stack overflow _before_ adding more slots!
+ */
+
+ case BC_FUNCF:
+ |.if JIT
+ | hotcall RB
+ |.endif
+ case BC_FUNCV: /* NYI: compiled vararg functions. */
+ | // Fall through. Assumes BC_IFUNCF/BC_IFUNCV follow and ins_AD is a no-op.
+ break;
+
+ case BC_JFUNCF:
+#if !LJ_HASJIT
+ break;
+#endif
+ case BC_IFUNCF:
+ | ins_AD // BASE = new base, RA = framesize, RD = nargs+1
+ | mov KBASE, [PC-4+PC2PROTO(k)]
+ | mov L:RB, SAVE_L
+ | lea RA, [BASE+RA*8] // Top of frame.
+ | cmp RA, L:RB->maxstack
+ | ja ->vm_growstack_f
+ | movzx RA, byte [PC-4+PC2PROTO(numparams)]
+ | cmp NARGS:RD, RA // Check for missing parameters.
+ | jbe >3
+ |2:
+ if (op == BC_JFUNCF) {
+ | movzx RD, PC_RD
+ | jmp =>BC_JLOOP
+ } else {
+ | ins_next
+ }
+ |
+ |3: // Clear missing parameters.
+ | mov dword [BASE+NARGS:RD*8-4], LJ_TNIL
+ | add NARGS:RD, 1
+ | cmp NARGS:RD, RA
+ | jbe <3
+ | jmp <2
+ break;
+
+ case BC_JFUNCV:
+#if !LJ_HASJIT
+ break;
+#endif
+ | int3 // NYI: compiled vararg functions
+ break; /* NYI: compiled vararg functions. */
+
+ case BC_IFUNCV:
+ | ins_AD // BASE = new base, RA = framesize, RD = nargs+1
+ | lea RB, [NARGS:RD*8+FRAME_VARG]
+ | lea RD, [BASE+NARGS:RD*8]
+ | mov LFUNC:KBASE, [BASE-8]
+ | mov [RD-4], RB // Store delta + FRAME_VARG.
+ | mov [RD-8], LFUNC:KBASE // Store copy of LFUNC.
+ | mov L:RB, SAVE_L
+ | lea RA, [RD+RA*8]
+ | cmp RA, L:RB->maxstack
+ | ja ->vm_growstack_v // Need to grow stack.
+ | mov RA, BASE
+ | mov BASE, RD
+ | movzx RB, byte [PC-4+PC2PROTO(numparams)]
+ | test RB, RB
+ | jz >2
+ |1: // Copy fixarg slots up to new frame.
+ | add RA, 8
+ | cmp RA, BASE
+ | jnb >3 // Less args than parameters?
+ | mov KBASE, [RA-8]
+ | mov [RD], KBASE
+ | mov KBASE, [RA-4]
+ | mov [RD+4], KBASE
+ | add RD, 8
+ | mov dword [RA-4], LJ_TNIL // Clear old fixarg slot (help the GC).
+ | sub RB, 1
+ | jnz <1
+ |2:
+ if (op == BC_JFUNCV) {
+ | movzx RD, PC_RD
+ | jmp =>BC_JLOOP
+ } else {
+ | mov KBASE, [PC-4+PC2PROTO(k)]
+ | ins_next
+ }
+ |
+ |3: // Clear missing parameters.
+ | mov dword [RD+4], LJ_TNIL
+ | add RD, 8
+ | sub RB, 1
+ | jnz <3
+ | jmp <2
+ break;
+
+ case BC_FUNCC:
+ case BC_FUNCCW:
+ | ins_AD // BASE = new base, RA = ins RA|RD (unused), RD = nargs+1
+ | mov CFUNC:RB, [BASE-8]
+ | mov KBASEa, CFUNC:RB->f
+ | mov L:RB, SAVE_L
+ | lea RD, [BASE+NARGS:RD*8-8]
+ | mov L:RB->base, BASE
+ | lea RA, [RD+8*LUA_MINSTACK]
+ | cmp RA, L:RB->maxstack
+ | mov L:RB->top, RD
+ if (op == BC_FUNCC) {
+ |.if X64
+ | mov CARG1d, L:RB // Caveat: CARG1d may be RA.
+ |.else
+ | mov ARG1, L:RB
+ |.endif
+ } else {
+ |.if X64
+ | mov CARG2, KBASEa
+ | mov CARG1d, L:RB // Caveat: CARG1d may be RA.
+ |.else
+ | mov ARG2, KBASEa
+ | mov ARG1, L:RB
+ |.endif
+ }
+ | ja ->vm_growstack_c // Need to grow stack.
+ | set_vmstate C
+ if (op == BC_FUNCC) {
+ | call KBASEa // (lua_State *L)
+ } else {
+ | // (lua_State *L, lua_CFunction f)
+ | call aword [DISPATCH+DISPATCH_GL(wrapf)]
+ }
+ | set_vmstate INTERP
+ | // nresults returned in eax (RD).
+ | mov BASE, L:RB->base
+ | lea RA, [BASE+RD*8]
+ | neg RA
+ | add RA, L:RB->top // RA = (L->top-(L->base+nresults))*8
+ | mov PC, [BASE-4] // Fetch PC of caller.
+ | jmp ->vm_returnc
+ break;
+
+ /* ---------------------------------------------------------------------- */
+
+ default:
+ fprintf(stderr, "Error: undefined opcode BC_%s\n", bc_names[op]);
+ exit(2);
+ break;
+ }
+}
+
+static int build_backend(BuildCtx *ctx)
+{
+ int op;
+ dasm_growpc(Dst, BC__MAX);
+ build_subroutines(ctx);
+ |.code_op
+ for (op = 0; op < BC__MAX; op++)
+ build_ins(ctx, (BCOp)op, op);
+ return BC__MAX;
+}
+
+/* Emit pseudo frame-info for all assembler functions. */
+static void emit_asm_debug(BuildCtx *ctx)
+{
+ int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);
+#if LJ_64
+#define SZPTR "8"
+#define BSZPTR "3"
+#define REG_SP "0x7"
+#define REG_RA "0x10"
+#else
+#define SZPTR "4"
+#define BSZPTR "2"
+#define REG_SP "0x4"
+#define REG_RA "0x8"
+#endif
+ switch (ctx->mode) {
+ case BUILD_elfasm:
+ fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n");
+ fprintf(ctx->fp,
+ ".Lframe0:\n"
+ "\t.long .LECIE0-.LSCIE0\n"
+ ".LSCIE0:\n"
+ "\t.long 0xffffffff\n"
+ "\t.byte 0x1\n"
+ "\t.string \"\"\n"
+ "\t.uleb128 0x1\n"
+ "\t.sleb128 -" SZPTR "\n"
+ "\t.byte " REG_RA "\n"
+ "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n"
+ "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n"
+ "\t.align " SZPTR "\n"
+ ".LECIE0:\n\n");
+ fprintf(ctx->fp,
+ ".LSFDE0:\n"
+ "\t.long .LEFDE0-.LASFDE0\n"
+ ".LASFDE0:\n"
+ "\t.long .Lframe0\n"
+#if LJ_64
+ "\t.quad .Lbegin\n"
+ "\t.quad %d\n"
+ "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
+ "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
+ "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
+ "\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */
+ "\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */
+#if LJ_NO_UNWIND
+ "\t.byte 0x8d\n\t.uleb128 0x6\n" /* offset r13 */
+ "\t.byte 0x8c\n\t.uleb128 0x7\n" /* offset r12 */
+#endif
+#else
+ "\t.long .Lbegin\n"
+ "\t.long %d\n"
+ "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
+ "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
+ "\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */
+ "\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */
+ "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */
+#endif
+ "\t.align " SZPTR "\n"
+ ".LEFDE0:\n\n", fcofs, CFRAME_SIZE);
+#if LJ_HASFFI
+ fprintf(ctx->fp,
+ ".LSFDE1:\n"
+ "\t.long .LEFDE1-.LASFDE1\n"
+ ".LASFDE1:\n"
+ "\t.long .Lframe0\n"
+#if LJ_64
+ "\t.quad lj_vm_ffi_call\n"
+ "\t.quad %d\n"
+ "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */
+ "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
+ "\t.byte 0xd\n\t.uleb128 0x6\n" /* def_cfa_register rbp */
+ "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
+#else
+ "\t.long lj_vm_ffi_call\n"
+ "\t.long %d\n"
+ "\t.byte 0xe\n\t.uleb128 8\n" /* def_cfa_offset */
+ "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
+ "\t.byte 0xd\n\t.uleb128 0x5\n" /* def_cfa_register ebp */
+ "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset ebx */
+#endif
+ "\t.align " SZPTR "\n"
+ ".LEFDE1:\n\n", (int)ctx->codesz - fcofs);
+#endif
+#if !LJ_NO_UNWIND
+#if (defined(__sun__) && defined(__svr4__))
+#if LJ_64
+ fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@unwind\n");
+#else
+ fprintf(ctx->fp, "\t.section .eh_frame,\"aw\",@progbits\n");
+#endif
+#else
+ fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@progbits\n");
+#endif
+ fprintf(ctx->fp,
+ ".Lframe1:\n"
+ "\t.long .LECIE1-.LSCIE1\n"
+ ".LSCIE1:\n"
+ "\t.long 0\n"
+ "\t.byte 0x1\n"
+ "\t.string \"zPR\"\n"
+ "\t.uleb128 0x1\n"
+ "\t.sleb128 -" SZPTR "\n"
+ "\t.byte " REG_RA "\n"
+ "\t.uleb128 6\n" /* augmentation length */
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.long lj_err_unwind_dwarf-.\n"
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n"
+ "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n"
+ "\t.align " SZPTR "\n"
+ ".LECIE1:\n\n");
+ fprintf(ctx->fp,
+ ".LSFDE2:\n"
+ "\t.long .LEFDE2-.LASFDE2\n"
+ ".LASFDE2:\n"
+ "\t.long .LASFDE2-.Lframe1\n"
+ "\t.long .Lbegin-.\n"
+ "\t.long %d\n"
+ "\t.uleb128 0\n" /* augmentation length */
+ "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
+#if LJ_64
+ "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
+ "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
+ "\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */
+ "\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */
+#else
+ "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
+ "\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */
+ "\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */
+ "\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */
+#endif
+ "\t.align " SZPTR "\n"
+ ".LEFDE2:\n\n", fcofs, CFRAME_SIZE);
+#if LJ_HASFFI
+ fprintf(ctx->fp,
+ ".Lframe2:\n"
+ "\t.long .LECIE2-.LSCIE2\n"
+ ".LSCIE2:\n"
+ "\t.long 0\n"
+ "\t.byte 0x1\n"
+ "\t.string \"zR\"\n"
+ "\t.uleb128 0x1\n"
+ "\t.sleb128 -" SZPTR "\n"
+ "\t.byte " REG_RA "\n"
+ "\t.uleb128 1\n" /* augmentation length */
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n"
+ "\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n"
+ "\t.align " SZPTR "\n"
+ ".LECIE2:\n\n");
+ fprintf(ctx->fp,
+ ".LSFDE3:\n"
+ "\t.long .LEFDE3-.LASFDE3\n"
+ ".LASFDE3:\n"
+ "\t.long .LASFDE3-.Lframe2\n"
+ "\t.long lj_vm_ffi_call-.\n"
+ "\t.long %d\n"
+ "\t.uleb128 0\n" /* augmentation length */
+#if LJ_64
+ "\t.byte 0xe\n\t.uleb128 16\n" /* def_cfa_offset */
+ "\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
+ "\t.byte 0xd\n\t.uleb128 0x6\n" /* def_cfa_register rbp */
+ "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
+#else
+ "\t.byte 0xe\n\t.uleb128 8\n" /* def_cfa_offset */
+ "\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
+ "\t.byte 0xd\n\t.uleb128 0x5\n" /* def_cfa_register ebp */
+ "\t.byte 0x83\n\t.uleb128 0x3\n" /* offset ebx */
+#endif
+ "\t.align " SZPTR "\n"
+ ".LEFDE3:\n\n", (int)ctx->codesz - fcofs);
+#endif
+#endif
+ break;
+#if !LJ_NO_UNWIND
+ /* Mental note: never let Apple design an assembler.
+ ** Or a linker. Or a plastic case. But I digress.
+ */
+ case BUILD_machasm: {
+#if LJ_HASFFI
+ int fcsize = 0;
+#endif
+ int i;
+ fprintf(ctx->fp, "\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\n");
+ fprintf(ctx->fp,
+ "EH_frame1:\n"
+ "\t.set L$set$x,LECIEX-LSCIEX\n"
+ "\t.long L$set$x\n"
+ "LSCIEX:\n"
+ "\t.long 0\n"
+ "\t.byte 0x1\n"
+ "\t.ascii \"zPR\\0\"\n"
+ "\t.byte 0x1\n"
+ "\t.byte 128-" SZPTR "\n"
+ "\t.byte " REG_RA "\n"
+ "\t.byte 6\n" /* augmentation length */
+ "\t.byte 0x9b\n" /* indirect|pcrel|sdata4 */
+#if LJ_64
+ "\t.long _lj_err_unwind_dwarf+4@GOTPCREL\n"
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.byte 0xc\n\t.byte " REG_SP "\n\t.byte " SZPTR "\n"
+#else
+ "\t.long L_lj_err_unwind_dwarf$non_lazy_ptr-.\n"
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.byte 0xc\n\t.byte 0x5\n\t.byte 0x4\n" /* esp=5 on 32 bit MACH-O. */
+#endif
+ "\t.byte 0x80+" REG_RA "\n\t.byte 0x1\n"
+ "\t.align " BSZPTR "\n"
+ "LECIEX:\n\n");
+ for (i = 0; i < ctx->nsym; i++) {
+ const char *name = ctx->sym[i].name;
+ int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs;
+ if (size == 0) continue;
+#if LJ_HASFFI
+ if (!strcmp(name, "_lj_vm_ffi_call")) { fcsize = size; continue; }
+#endif
+ fprintf(ctx->fp,
+ "%s.eh:\n"
+ "LSFDE%d:\n"
+ "\t.set L$set$%d,LEFDE%d-LASFDE%d\n"
+ "\t.long L$set$%d\n"
+ "LASFDE%d:\n"
+ "\t.long LASFDE%d-EH_frame1\n"
+ "\t.long %s-.\n"
+ "\t.long %d\n"
+ "\t.byte 0\n" /* augmentation length */
+ "\t.byte 0xe\n\t.byte %d\n" /* def_cfa_offset */
+#if LJ_64
+ "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */
+ "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */
+ "\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */
+ "\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */
+#else
+ "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/
+ "\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */
+ "\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */
+ "\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */
+#endif
+ "\t.align " BSZPTR "\n"
+ "LEFDE%d:\n\n",
+ name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);
+ }
+#if LJ_HASFFI
+ if (fcsize) {
+ fprintf(ctx->fp,
+ "EH_frame2:\n"
+ "\t.set L$set$y,LECIEY-LSCIEY\n"
+ "\t.long L$set$y\n"
+ "LSCIEY:\n"
+ "\t.long 0\n"
+ "\t.byte 0x1\n"
+ "\t.ascii \"zR\\0\"\n"
+ "\t.byte 0x1\n"
+ "\t.byte 128-" SZPTR "\n"
+ "\t.byte " REG_RA "\n"
+ "\t.byte 1\n" /* augmentation length */
+#if LJ_64
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.byte 0xc\n\t.byte " REG_SP "\n\t.byte " SZPTR "\n"
+#else
+ "\t.byte 0x1b\n" /* pcrel|sdata4 */
+ "\t.byte 0xc\n\t.byte 0x5\n\t.byte 0x4\n" /* esp=5 on 32 bit MACH. */
+#endif
+ "\t.byte 0x80+" REG_RA "\n\t.byte 0x1\n"
+ "\t.align " BSZPTR "\n"
+ "LECIEY:\n\n");
+ fprintf(ctx->fp,
+ "_lj_vm_ffi_call.eh:\n"
+ "LSFDEY:\n"
+ "\t.set L$set$yy,LEFDEY-LASFDEY\n"
+ "\t.long L$set$yy\n"
+ "LASFDEY:\n"
+ "\t.long LASFDEY-EH_frame2\n"
+ "\t.long _lj_vm_ffi_call-.\n"
+ "\t.long %d\n"
+ "\t.byte 0\n" /* augmentation length */
+#if LJ_64
+ "\t.byte 0xe\n\t.byte 16\n" /* def_cfa_offset */
+ "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */
+ "\t.byte 0xd\n\t.byte 0x6\n" /* def_cfa_register rbp */
+ "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */
+#else
+ "\t.byte 0xe\n\t.byte 8\n" /* def_cfa_offset */
+ "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/
+ "\t.byte 0xd\n\t.byte 0x4\n" /* def_cfa_register ebp */
+ "\t.byte 0x83\n\t.byte 0x3\n" /* offset ebx */
+#endif
+ "\t.align " BSZPTR "\n"
+ "LEFDEY:\n\n", fcsize);
+ }
+#endif
+#if LJ_64
+ fprintf(ctx->fp, "\t.subsections_via_symbols\n");
+#else
+ fprintf(ctx->fp,
+ "\t.non_lazy_symbol_pointer\n"
+ "L_lj_err_unwind_dwarf$non_lazy_ptr:\n"
+ ".indirect_symbol _lj_err_unwind_dwarf\n"
+ ".long 0\n");
+#endif
+ }
+ break;
+#endif
+ default: /* Difficult for other modes. */
+ break;
+ }
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/vmdef.lua b/src/3rdparty/LuaJIT-2.0.5/src/vmdef.lua
new file mode 100644
index 0000000..cf85780
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/vmdef.lua
@@ -0,0 +1,331 @@
+-- This is a generated file. DO NOT EDIT!
+
+module(...)
+
+bcnames = "ISLT ISGE ISLE ISGT ISEQV ISNEV ISEQS ISNES ISEQN ISNEN ISEQP ISNEP ISTC ISFC IST ISF MOV NOT UNM LEN ADDVN SUBVN MULVN DIVVN MODVN ADDNV SUBNV MULNV DIVNV MODNV ADDVV SUBVV MULVV DIVVV MODVV POW CAT KSTR KCDATAKSHORTKNUM KPRI KNIL UGET USETV USETS USETN USETP UCLO FNEW TNEW TDUP GGET GSET TGETV TGETS TGETB TSETV TSETS TSETB TSETM CALLM CALL CALLMTCALLT ITERC ITERN VARG ISNEXTRETM RET RET0 RET1 FORI JFORI FORL IFORL JFORL ITERL IITERLJITERLLOOP ILOOP JLOOP JMP FUNCF IFUNCFJFUNCFFUNCV IFUNCVJFUNCVFUNCC FUNCCW"
+
+irnames = "LT GE LE GT ULT UGE ULE UGT EQ NE ABC RETF NOP BASE PVAL GCSTEPHIOP LOOP USE PHI RENAMEKPRI KINT KGC KPTR KKPTR KNULL KNUM KINT64KSLOT BNOT BSWAP BAND BOR BXOR BSHL BSHR BSAR BROL BROR ADD SUB MUL DIV MOD POW NEG ABS ATAN2 LDEXP MIN MAX FPMATHADDOV SUBOV MULOV AREF HREFK HREF NEWREFUREFO UREFC FREF STRREFALOAD HLOAD ULOAD FLOAD XLOAD SLOAD VLOAD ASTOREHSTOREUSTOREFSTOREXSTORESNEW XSNEW TNEW TDUP CNEW CNEWI TBAR OBAR XBAR CONV TOBIT TOSTR STRTO CALLN CALLL CALLS CALLXSCARG "
+
+irfpm = { [0]="floor", "ceil", "trunc", "sqrt", "exp", "exp2", "log", "log2", "log10", "sin", "cos", "tan", "other", }
+
+irfield = { [0]="str.len", "func.env", "func.pc", "tab.meta", "tab.array", "tab.node", "tab.asize", "tab.hmask", "tab.nomm", "udata.meta", "udata.udtype", "udata.file", "cdata.ctypeid", "cdata.ptr", "cdata.int", "cdata.int64", "cdata.int64_4", }
+
+ircall = {
+[0]="lj_str_cmp",
+"lj_str_new",
+"lj_strscan_num",
+"lj_str_fromint",
+"lj_str_fromnum",
+"lj_tab_new1",
+"lj_tab_dup",
+"lj_tab_newkey",
+"lj_tab_len",
+"lj_gc_step_jit",
+"lj_gc_barrieruv",
+"lj_mem_newgco",
+"lj_math_random_step",
+"lj_vm_modi",
+"sinh",
+"cosh",
+"tanh",
+"fputc",
+"fwrite",
+"fflush",
+"lj_vm_floor",
+"lj_vm_ceil",
+"lj_vm_trunc",
+"sqrt",
+"exp",
+"lj_vm_exp2",
+"log",
+"lj_vm_log2",
+"log10",
+"sin",
+"cos",
+"tan",
+"lj_vm_powi",
+"pow",
+"atan2",
+"ldexp",
+"lj_vm_tobit",
+"softfp_add",
+"softfp_sub",
+"softfp_mul",
+"softfp_div",
+"softfp_cmp",
+"softfp_i2d",
+"softfp_d2i",
+"softfp_ui2d",
+"softfp_f2d",
+"softfp_d2ui",
+"softfp_d2f",
+"softfp_i2f",
+"softfp_ui2f",
+"softfp_f2i",
+"softfp_f2ui",
+"fp64_l2d",
+"fp64_ul2d",
+"fp64_l2f",
+"fp64_ul2f",
+"fp64_d2l",
+"fp64_d2ul",
+"fp64_f2l",
+"fp64_f2ul",
+"lj_carith_divi64",
+"lj_carith_divu64",
+"lj_carith_modi64",
+"lj_carith_modu64",
+"lj_carith_powi64",
+"lj_carith_powu64",
+"lj_cdata_setfin",
+"strlen",
+"memcpy",
+"memset",
+"lj_vm_errno",
+"lj_carith_mul64",
+}
+
+traceerr = {
+[0]="error thrown or hook called during recording",
+"trace too long",
+"trace too deep",
+"too many snapshots",
+"blacklisted",
+"NYI: bytecode %d",
+"leaving loop in root trace",
+"inner loop in root trace",
+"loop unroll limit reached",
+"bad argument type",
+"JIT compilation disabled for function",
+"call unroll limit reached",
+"down-recursion, restarting",
+"NYI: C function %s",
+"NYI: FastFunc %s",
+"NYI: unsupported variant of FastFunc %s",
+"NYI: return to lower frame",
+"store with nil or NaN key",
+"missing metamethod",
+"looping index lookup",
+"NYI: mixed sparse/dense table",
+"symbol not in cache",
+"NYI: unsupported C type conversion",
+"NYI: unsupported C function type",
+"guard would always fail",
+"too many PHIs",
+"persistent type instability",
+"failed to allocate mcode memory",
+"machine code too long",
+"hit mcode limit (retrying)",
+"too many spill slots",
+"inconsistent register allocation",
+"NYI: cannot assemble IR instruction %d",
+"NYI: PHI shuffling too complex",
+"NYI: register coalescing too complex",
+}
+
+ffnames = {
+[0]="Lua",
+"C",
+"assert",
+"type",
+"next",
+"pairs",
+"ipairs_aux",
+"ipairs",
+"getmetatable",
+"setmetatable",
+"getfenv",
+"setfenv",
+"rawget",
+"rawset",
+"rawequal",
+"unpack",
+"select",
+"tonumber",
+"tostring",
+"error",
+"pcall",
+"xpcall",
+"loadfile",
+"load",
+"loadstring",
+"dofile",
+"gcinfo",
+"collectgarbage",
+"newproxy",
+"print",
+"coroutine.status",
+"coroutine.running",
+"coroutine.create",
+"coroutine.yield",
+"coroutine.resume",
+"coroutine.wrap_aux",
+"coroutine.wrap",
+"math.abs",
+"math.floor",
+"math.ceil",
+"math.sqrt",
+"math.log10",
+"math.exp",
+"math.sin",
+"math.cos",
+"math.tan",
+"math.asin",
+"math.acos",
+"math.atan",
+"math.sinh",
+"math.cosh",
+"math.tanh",
+"math.frexp",
+"math.modf",
+"math.deg",
+"math.rad",
+"math.log",
+"math.atan2",
+"math.pow",
+"math.fmod",
+"math.ldexp",
+"math.min",
+"math.max",
+"math.random",
+"math.randomseed",
+"bit.tobit",
+"bit.bnot",
+"bit.bswap",
+"bit.lshift",
+"bit.rshift",
+"bit.arshift",
+"bit.rol",
+"bit.ror",
+"bit.band",
+"bit.bor",
+"bit.bxor",
+"bit.tohex",
+"string.len",
+"string.byte",
+"string.char",
+"string.sub",
+"string.rep",
+"string.reverse",
+"string.lower",
+"string.upper",
+"string.dump",
+"string.find",
+"string.match",
+"string.gmatch_aux",
+"string.gmatch",
+"string.gsub",
+"string.format",
+"table.foreachi",
+"table.foreach",
+"table.getn",
+"table.maxn",
+"table.insert",
+"table.remove",
+"table.concat",
+"table.sort",
+"io.method.close",
+"io.method.read",
+"io.method.write",
+"io.method.flush",
+"io.method.seek",
+"io.method.setvbuf",
+"io.method.lines",
+"io.method.__gc",
+"io.method.__tostring",
+"io.open",
+"io.popen",
+"io.tmpfile",
+"io.close",
+"io.read",
+"io.write",
+"io.flush",
+"io.input",
+"io.output",
+"io.lines",
+"io.type",
+"os.execute",
+"os.remove",
+"os.rename",
+"os.tmpname",
+"os.getenv",
+"os.exit",
+"os.clock",
+"os.date",
+"os.time",
+"os.difftime",
+"os.setlocale",
+"debug.getregistry",
+"debug.getmetatable",
+"debug.setmetatable",
+"debug.getfenv",
+"debug.setfenv",
+"debug.getinfo",
+"debug.getlocal",
+"debug.setlocal",
+"debug.getupvalue",
+"debug.setupvalue",
+"debug.upvalueid",
+"debug.upvaluejoin",
+"debug.sethook",
+"debug.gethook",
+"debug.debug",
+"debug.traceback",
+"jit.on",
+"jit.off",
+"jit.flush",
+"jit.status",
+"jit.attach",
+"jit.util.funcinfo",
+"jit.util.funcbc",
+"jit.util.funck",
+"jit.util.funcuvname",
+"jit.util.traceinfo",
+"jit.util.traceir",
+"jit.util.tracek",
+"jit.util.tracesnap",
+"jit.util.tracemc",
+"jit.util.traceexitstub",
+"jit.util.ircalladdr",
+"jit.opt.start",
+"ffi.meta.__index",
+"ffi.meta.__newindex",
+"ffi.meta.__eq",
+"ffi.meta.__len",
+"ffi.meta.__lt",
+"ffi.meta.__le",
+"ffi.meta.__concat",
+"ffi.meta.__call",
+"ffi.meta.__add",
+"ffi.meta.__sub",
+"ffi.meta.__mul",
+"ffi.meta.__div",
+"ffi.meta.__mod",
+"ffi.meta.__pow",
+"ffi.meta.__unm",
+"ffi.meta.__tostring",
+"ffi.meta.__pairs",
+"ffi.meta.__ipairs",
+"ffi.clib.__index",
+"ffi.clib.__newindex",
+"ffi.clib.__gc",
+"ffi.callback.free",
+"ffi.callback.set",
+"ffi.cdef",
+"ffi.new",
+"ffi.cast",
+"ffi.typeof",
+"ffi.istype",
+"ffi.sizeof",
+"ffi.alignof",
+"ffi.offsetof",
+"ffi.errno",
+"ffi.string",
+"ffi.copy",
+"ffi.fill",
+"ffi.abi",
+"ffi.metatype",
+"ffi.gc",
+"ffi.load",
+}
+
diff --git a/src/3rdparty/LuaJIT-2.0.5/src/xedkbuild.bat b/src/3rdparty/LuaJIT-2.0.5/src/xedkbuild.bat
new file mode 100644
index 0000000..b4f236e
--- /dev/null
+++ b/src/3rdparty/LuaJIT-2.0.5/src/xedkbuild.bat
@@ -0,0 +1,92 @@
+@rem Script to build LuaJIT with the Xbox 360 SDK.
+@rem Donated to the public domain.
+@rem
+@rem Open a "Visual Studio .NET Command Prompt" (32 bit host compiler)
+@rem Then cd to this directory and run this script.
+
+@if not defined INCLUDE goto :FAIL
+@if not defined XEDK goto :FAIL
+
+@setlocal
+@rem ---- Host compiler ----
+@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE
+@set LJLINK=link /nologo
+@set LJMT=mt /nologo
+@set DASMDIR=..\dynasm
+@set DASM=%DASMDIR%\dynasm.lua
+@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c
+
+%LJCOMPILE% host\minilua.c
+@if errorlevel 1 goto :BAD
+%LJLINK% /out:minilua.exe minilua.obj
+@if errorlevel 1 goto :BAD
+if exist minilua.exe.manifest^
+ %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe
+
+@rem Error out for 64 bit host compiler
+@minilua
+@if errorlevel 8 goto :FAIL
+
+@set DASMFLAGS=-D GPR64 -D FRAME32 -D PPE -D SQRT -D DUALNUM
+minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_ppc.dasc
+@if errorlevel 1 goto :BAD
+
+%LJCOMPILE% /I "." /I %DASMDIR% /D_XBOX_VER=200 /DLUAJIT_TARGET=LUAJIT_ARCH_PPC host\buildvm*.c
+@if errorlevel 1 goto :BAD
+%LJLINK% /out:buildvm.exe buildvm*.obj
+@if errorlevel 1 goto :BAD
+if exist buildvm.exe.manifest^
+ %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe
+
+buildvm -m peobj -o lj_vm.obj
+@if errorlevel 1 goto :BAD
+buildvm -m bcdef -o lj_bcdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m ffdef -o lj_ffdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m libdef -o lj_libdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m recdef -o lj_recdef.h %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB%
+@if errorlevel 1 goto :BAD
+buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
+@if errorlevel 1 goto :BAD
+
+@rem ---- Cross compiler ----
+@set LJCOMPILE="%XEDK%\bin\win32\cl" /nologo /c /MT /O2 /W3 /GF /Gm- /GR- /GS- /Gy /openmp- /D_CRT_SECURE_NO_DEPRECATE /DNDEBUG /D_XBOX /D_LIB /DLUAJIT_USE_SYSMALLOC
+@set LJLIB="%XEDK%\bin\win32\lib" /nologo
+@set "INCLUDE=%XEDK%\include\xbox"
+
+@if "%1" neq "debug" goto :NODEBUG
+@shift
+@set "LJCOMPILE=%LJCOMPILE% /Zi"
+:NODEBUG
+@if "%1"=="amalg" goto :AMALG
+%LJCOMPILE% /DLUA_BUILD_AS_DLL lj_*.c lib_*.c
+@if errorlevel 1 goto :BAD
+%LJLIB% /OUT:luajit20.lib lj_*.obj lib_*.obj
+@if errorlevel 1 goto :BAD
+@goto :NOAMALG
+:AMALG
+%LJCOMPILE% /DLUA_BUILD_AS_DLL ljamalg.c
+@if errorlevel 1 goto :BAD
+%LJLIB% /OUT:luajit20.lib ljamalg.obj lj_vm.obj
+@if errorlevel 1 goto :BAD
+:NOAMALG
+
+@del *.obj *.manifest minilua.exe buildvm.exe
+@echo.
+@echo === Successfully built LuaJIT for Xbox 360 ===
+
+@goto :END
+:BAD
+@echo.
+@echo *******************************************************
+@echo *** Build FAILED -- Please check the error messages ***
+@echo *******************************************************
+@goto :END
+:FAIL
+@echo To run this script you must open a "Visual Studio .NET Command Prompt"
+@echo (32 bit host compiler). The Xbox 360 SDK must be installed, too.
+:END
diff --git a/src/3rdparty/SDL2/include/SDL.h b/src/3rdparty/SDL2/include/SDL.h
new file mode 100644
index 0000000..d48d9d4
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL.h
@@ -0,0 +1,133 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL.h
+ *
+ * Main include header for the SDL library
+ */
+
+
+#ifndef SDL_h_
+#define SDL_h_
+
+#include "SDL_main.h"
+#include "SDL_stdinc.h"
+#include "SDL_assert.h"
+#include "SDL_atomic.h"
+#include "SDL_audio.h"
+#include "SDL_clipboard.h"
+#include "SDL_cpuinfo.h"
+#include "SDL_endian.h"
+#include "SDL_error.h"
+#include "SDL_events.h"
+#include "SDL_filesystem.h"
+#include "SDL_gamecontroller.h"
+#include "SDL_haptic.h"
+#include "SDL_hints.h"
+#include "SDL_joystick.h"
+#include "SDL_loadso.h"
+#include "SDL_log.h"
+#include "SDL_messagebox.h"
+#include "SDL_mutex.h"
+#include "SDL_power.h"
+#include "SDL_render.h"
+#include "SDL_rwops.h"
+#include "SDL_shape.h"
+#include "SDL_system.h"
+#include "SDL_thread.h"
+#include "SDL_timer.h"
+#include "SDL_version.h"
+#include "SDL_video.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* As of version 0.5, SDL is loaded dynamically into the application */
+
+/**
+ * \name SDL_INIT_*
+ *
+ * These are the flags which may be passed to SDL_Init(). You should
+ * specify the subsystems which you will be using in your application.
+ */
+/* @{ */
+#define SDL_INIT_TIMER 0x00000001u
+#define SDL_INIT_AUDIO 0x00000010u
+#define SDL_INIT_VIDEO 0x00000020u /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
+#define SDL_INIT_JOYSTICK 0x00000200u /**< SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS */
+#define SDL_INIT_HAPTIC 0x00001000u
+#define SDL_INIT_GAMECONTROLLER 0x00002000u /**< SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK */
+#define SDL_INIT_EVENTS 0x00004000u
+#define SDL_INIT_NOPARACHUTE 0x00100000u /**< compatibility; this flag is ignored. */
+#define SDL_INIT_EVERYTHING ( \
+ SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | \
+ SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER \
+ )
+/* @} */
+
+/**
+ * This function initializes the subsystems specified by \c flags
+ */
+extern DECLSPEC int SDLCALL SDL_Init(Uint32 flags);
+
+/**
+ * This function initializes specific SDL subsystems
+ *
+ * Subsystem initialization is ref-counted, you must call
+ * SDL_QuitSubSystem() for each SDL_InitSubSystem() to correctly
+ * shutdown a subsystem manually (or call SDL_Quit() to force shutdown).
+ * If a subsystem is already loaded then this call will
+ * increase the ref-count and return.
+ */
+extern DECLSPEC int SDLCALL SDL_InitSubSystem(Uint32 flags);
+
+/**
+ * This function cleans up specific SDL subsystems
+ */
+extern DECLSPEC void SDLCALL SDL_QuitSubSystem(Uint32 flags);
+
+/**
+ * This function returns a mask of the specified subsystems which have
+ * previously been initialized.
+ *
+ * If \c flags is 0, it returns a mask of all initialized subsystems.
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_WasInit(Uint32 flags);
+
+/**
+ * This function cleans up all initialized subsystems. You should
+ * call it upon all exit conditions.
+ */
+extern DECLSPEC void SDLCALL SDL_Quit(void);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL.h b/src/3rdparty/SDL2/include/SDL2/SDL.h
new file mode 100644
index 0000000..d48d9d4
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL.h
@@ -0,0 +1,133 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL.h
+ *
+ * Main include header for the SDL library
+ */
+
+
+#ifndef SDL_h_
+#define SDL_h_
+
+#include "SDL_main.h"
+#include "SDL_stdinc.h"
+#include "SDL_assert.h"
+#include "SDL_atomic.h"
+#include "SDL_audio.h"
+#include "SDL_clipboard.h"
+#include "SDL_cpuinfo.h"
+#include "SDL_endian.h"
+#include "SDL_error.h"
+#include "SDL_events.h"
+#include "SDL_filesystem.h"
+#include "SDL_gamecontroller.h"
+#include "SDL_haptic.h"
+#include "SDL_hints.h"
+#include "SDL_joystick.h"
+#include "SDL_loadso.h"
+#include "SDL_log.h"
+#include "SDL_messagebox.h"
+#include "SDL_mutex.h"
+#include "SDL_power.h"
+#include "SDL_render.h"
+#include "SDL_rwops.h"
+#include "SDL_shape.h"
+#include "SDL_system.h"
+#include "SDL_thread.h"
+#include "SDL_timer.h"
+#include "SDL_version.h"
+#include "SDL_video.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* As of version 0.5, SDL is loaded dynamically into the application */
+
+/**
+ * \name SDL_INIT_*
+ *
+ * These are the flags which may be passed to SDL_Init(). You should
+ * specify the subsystems which you will be using in your application.
+ */
+/* @{ */
+#define SDL_INIT_TIMER 0x00000001u
+#define SDL_INIT_AUDIO 0x00000010u
+#define SDL_INIT_VIDEO 0x00000020u /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
+#define SDL_INIT_JOYSTICK 0x00000200u /**< SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS */
+#define SDL_INIT_HAPTIC 0x00001000u
+#define SDL_INIT_GAMECONTROLLER 0x00002000u /**< SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK */
+#define SDL_INIT_EVENTS 0x00004000u
+#define SDL_INIT_NOPARACHUTE 0x00100000u /**< compatibility; this flag is ignored. */
+#define SDL_INIT_EVERYTHING ( \
+ SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | \
+ SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER \
+ )
+/* @} */
+
+/**
+ * This function initializes the subsystems specified by \c flags
+ */
+extern DECLSPEC int SDLCALL SDL_Init(Uint32 flags);
+
+/**
+ * This function initializes specific SDL subsystems
+ *
+ * Subsystem initialization is ref-counted, you must call
+ * SDL_QuitSubSystem() for each SDL_InitSubSystem() to correctly
+ * shutdown a subsystem manually (or call SDL_Quit() to force shutdown).
+ * If a subsystem is already loaded then this call will
+ * increase the ref-count and return.
+ */
+extern DECLSPEC int SDLCALL SDL_InitSubSystem(Uint32 flags);
+
+/**
+ * This function cleans up specific SDL subsystems
+ */
+extern DECLSPEC void SDLCALL SDL_QuitSubSystem(Uint32 flags);
+
+/**
+ * This function returns a mask of the specified subsystems which have
+ * previously been initialized.
+ *
+ * If \c flags is 0, it returns a mask of all initialized subsystems.
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_WasInit(Uint32 flags);
+
+/**
+ * This function cleans up all initialized subsystems. You should
+ * call it upon all exit conditions.
+ */
+extern DECLSPEC void SDLCALL SDL_Quit(void);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_assert.h b/src/3rdparty/SDL2/include/SDL2/SDL_assert.h
new file mode 100644
index 0000000..b38f928
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_assert.h
@@ -0,0 +1,291 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_assert_h_
+#define SDL_assert_h_
+
+#include "SDL_config.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef SDL_ASSERT_LEVEL
+#ifdef SDL_DEFAULT_ASSERT_LEVEL
+#define SDL_ASSERT_LEVEL SDL_DEFAULT_ASSERT_LEVEL
+#elif defined(_DEBUG) || defined(DEBUG) || \
+ (defined(__GNUC__) && !defined(__OPTIMIZE__))
+#define SDL_ASSERT_LEVEL 2
+#else
+#define SDL_ASSERT_LEVEL 1
+#endif
+#endif /* SDL_ASSERT_LEVEL */
+
+/*
+These are macros and not first class functions so that the debugger breaks
+on the assertion line and not in some random guts of SDL, and so each
+assert can have unique static variables associated with it.
+*/
+
+#if defined(_MSC_VER)
+/* Don't include intrin.h here because it contains C++ code */
+ extern void __cdecl __debugbreak(void);
+ #define SDL_TriggerBreakpoint() __debugbreak()
+#elif ( (!defined(__NACL__)) && ((defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__))) )
+ #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "int $3\n\t" )
+#elif defined(__386__) && defined(__WATCOMC__)
+ #define SDL_TriggerBreakpoint() { _asm { int 0x03 } }
+#elif defined(HAVE_SIGNAL_H) && !defined(__WATCOMC__)
+ #include <signal.h>
+ #define SDL_TriggerBreakpoint() raise(SIGTRAP)
+#else
+ /* How do we trigger breakpoints on this platform? */
+ #define SDL_TriggerBreakpoint()
+#endif
+
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 supports __func__ as a standard. */
+# define SDL_FUNCTION __func__
+#elif ((__GNUC__ >= 2) || defined(_MSC_VER) || defined (__WATCOMC__))
+# define SDL_FUNCTION __FUNCTION__
+#else
+# define SDL_FUNCTION "???"
+#endif
+#define SDL_FILE __FILE__
+#define SDL_LINE __LINE__
+
+/*
+sizeof (x) makes the compiler still parse the expression even without
+assertions enabled, so the code is always checked at compile time, but
+doesn't actually generate code for it, so there are no side effects or
+expensive checks at run time, just the constant size of what x WOULD be,
+which presumably gets optimized out as unused.
+This also solves the problem of...
+
+ int somevalue = blah();
+ SDL_assert(somevalue == 1);
+
+...which would cause compiles to complain that somevalue is unused if we
+disable assertions.
+*/
+
+/* "while (0,0)" fools Microsoft's compiler's /W4 warning level into thinking
+ this condition isn't constant. And looks like an owl's face! */
+#ifdef _MSC_VER /* stupid /W4 warnings. */
+#define SDL_NULL_WHILE_LOOP_CONDITION (0,0)
+#else
+#define SDL_NULL_WHILE_LOOP_CONDITION (0)
+#endif
+
+#define SDL_disabled_assert(condition) \
+ do { (void) sizeof ((condition)); } while (SDL_NULL_WHILE_LOOP_CONDITION)
+
+typedef enum
+{
+ SDL_ASSERTION_RETRY, /**< Retry the assert immediately. */
+ SDL_ASSERTION_BREAK, /**< Make the debugger trigger a breakpoint. */
+ SDL_ASSERTION_ABORT, /**< Terminate the program. */
+ SDL_ASSERTION_IGNORE, /**< Ignore the assert. */
+ SDL_ASSERTION_ALWAYS_IGNORE /**< Ignore the assert from now on. */
+} SDL_AssertState;
+
+typedef struct SDL_AssertData
+{
+ int always_ignore;
+ unsigned int trigger_count;
+ const char *condition;
+ const char *filename;
+ int linenum;
+ const char *function;
+ const struct SDL_AssertData *next;
+} SDL_AssertData;
+
+#if (SDL_ASSERT_LEVEL > 0)
+
+/* Never call this directly. Use the SDL_assert* macros. */
+extern DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *,
+ const char *,
+ const char *, int)
+#if defined(__clang__)
+#if __has_feature(attribute_analyzer_noreturn)
+/* this tells Clang's static analysis that we're a custom assert function,
+ and that the analyzer should assume the condition was always true past this
+ SDL_assert test. */
+ __attribute__((analyzer_noreturn))
+#endif
+#endif
+;
+
+/* the do {} while(0) avoids dangling else problems:
+ if (x) SDL_assert(y); else blah();
+ ... without the do/while, the "else" could attach to this macro's "if".
+ We try to handle just the minimum we need here in a macro...the loop,
+ the static vars, and break points. The heavy lifting is handled in
+ SDL_ReportAssertion(), in SDL_assert.c.
+*/
+#define SDL_enabled_assert(condition) \
+ do { \
+ while ( !(condition) ) { \
+ static struct SDL_AssertData sdl_assert_data = { \
+ 0, 0, #condition, 0, 0, 0, 0 \
+ }; \
+ const SDL_AssertState sdl_assert_state = SDL_ReportAssertion(&sdl_assert_data, SDL_FUNCTION, SDL_FILE, SDL_LINE); \
+ if (sdl_assert_state == SDL_ASSERTION_RETRY) { \
+ continue; /* go again. */ \
+ } else if (sdl_assert_state == SDL_ASSERTION_BREAK) { \
+ SDL_TriggerBreakpoint(); \
+ } \
+ break; /* not retrying. */ \
+ } \
+ } while (SDL_NULL_WHILE_LOOP_CONDITION)
+
+#endif /* enabled assertions support code */
+
+/* Enable various levels of assertions. */
+#if SDL_ASSERT_LEVEL == 0 /* assertions disabled */
+# define SDL_assert(condition) SDL_disabled_assert(condition)
+# define SDL_assert_release(condition) SDL_disabled_assert(condition)
+# define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
+#elif SDL_ASSERT_LEVEL == 1 /* release settings. */
+# define SDL_assert(condition) SDL_disabled_assert(condition)
+# define SDL_assert_release(condition) SDL_enabled_assert(condition)
+# define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
+#elif SDL_ASSERT_LEVEL == 2 /* normal settings. */
+# define SDL_assert(condition) SDL_enabled_assert(condition)
+# define SDL_assert_release(condition) SDL_enabled_assert(condition)
+# define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
+#elif SDL_ASSERT_LEVEL == 3 /* paranoid settings. */
+# define SDL_assert(condition) SDL_enabled_assert(condition)
+# define SDL_assert_release(condition) SDL_enabled_assert(condition)
+# define SDL_assert_paranoid(condition) SDL_enabled_assert(condition)
+#else
+# error Unknown assertion level.
+#endif
+
+/* this assertion is never disabled at any level. */
+#define SDL_assert_always(condition) SDL_enabled_assert(condition)
+
+
+typedef SDL_AssertState (SDLCALL *SDL_AssertionHandler)(
+ const SDL_AssertData* data, void* userdata);
+
+/**
+ * \brief Set an application-defined assertion handler.
+ *
+ * This allows an app to show its own assertion UI and/or force the
+ * response to an assertion failure. If the app doesn't provide this, SDL
+ * will try to do the right thing, popping up a system-specific GUI dialog,
+ * and probably minimizing any fullscreen windows.
+ *
+ * This callback may fire from any thread, but it runs wrapped in a mutex, so
+ * it will only fire from one thread at a time.
+ *
+ * Setting the callback to NULL restores SDL's original internal handler.
+ *
+ * This callback is NOT reset to SDL's internal handler upon SDL_Quit()!
+ *
+ * Return SDL_AssertState value of how to handle the assertion failure.
+ *
+ * \param handler Callback function, called when an assertion fails.
+ * \param userdata A pointer passed to the callback as-is.
+ */
+extern DECLSPEC void SDLCALL SDL_SetAssertionHandler(
+ SDL_AssertionHandler handler,
+ void *userdata);
+
+/**
+ * \brief Get the default assertion handler.
+ *
+ * This returns the function pointer that is called by default when an
+ * assertion is triggered. This is an internal function provided by SDL,
+ * that is used for assertions when SDL_SetAssertionHandler() hasn't been
+ * used to provide a different function.
+ *
+ * \return The default SDL_AssertionHandler that is called when an assert triggers.
+ */
+extern DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetDefaultAssertionHandler(void);
+
+/**
+ * \brief Get the current assertion handler.
+ *
+ * This returns the function pointer that is called when an assertion is
+ * triggered. This is either the value last passed to
+ * SDL_SetAssertionHandler(), or if no application-specified function is
+ * set, is equivalent to calling SDL_GetDefaultAssertionHandler().
+ *
+ * \param puserdata Pointer to a void*, which will store the "userdata"
+ * pointer that was passed to SDL_SetAssertionHandler().
+ * This value will always be NULL for the default handler.
+ * If you don't care about this data, it is safe to pass
+ * a NULL pointer to this function to ignore it.
+ * \return The SDL_AssertionHandler that is called when an assert triggers.
+ */
+extern DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetAssertionHandler(void **puserdata);
+
+/**
+ * \brief Get a list of all assertion failures.
+ *
+ * Get all assertions triggered since last call to SDL_ResetAssertionReport(),
+ * or the start of the program.
+ *
+ * The proper way to examine this data looks something like this:
+ *
+ * <code>
+ * const SDL_AssertData *item = SDL_GetAssertionReport();
+ * while (item) {
+ * printf("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\\n",
+ * item->condition, item->function, item->filename,
+ * item->linenum, item->trigger_count,
+ * item->always_ignore ? "yes" : "no");
+ * item = item->next;
+ * }
+ * </code>
+ *
+ * \return List of all assertions.
+ * \sa SDL_ResetAssertionReport
+ */
+extern DECLSPEC const SDL_AssertData * SDLCALL SDL_GetAssertionReport(void);
+
+/**
+ * \brief Reset the list of all assertion failures.
+ *
+ * Reset list of all assertions triggered.
+ *
+ * \sa SDL_GetAssertionReport
+ */
+extern DECLSPEC void SDLCALL SDL_ResetAssertionReport(void);
+
+
+/* these had wrong naming conventions until 2.0.4. Please update your app! */
+#define SDL_assert_state SDL_AssertState
+#define SDL_assert_data SDL_AssertData
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_assert_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_atomic.h b/src/3rdparty/SDL2/include/SDL2/SDL_atomic.h
new file mode 100644
index 0000000..b228774
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_atomic.h
@@ -0,0 +1,277 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_atomic.h
+ *
+ * Atomic operations.
+ *
+ * IMPORTANT:
+ * If you are not an expert in concurrent lockless programming, you should
+ * only be using the atomic lock and reference counting functions in this
+ * file. In all other cases you should be protecting your data structures
+ * with full mutexes.
+ *
+ * The list of "safe" functions to use are:
+ * SDL_AtomicLock()
+ * SDL_AtomicUnlock()
+ * SDL_AtomicIncRef()
+ * SDL_AtomicDecRef()
+ *
+ * Seriously, here be dragons!
+ * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ *
+ * You can find out a little more about lockless programming and the
+ * subtle issues that can arise here:
+ * http://msdn.microsoft.com/en-us/library/ee418650%28v=vs.85%29.aspx
+ *
+ * There's also lots of good information here:
+ * http://www.1024cores.net/home/lock-free-algorithms
+ * http://preshing.com/
+ *
+ * These operations may or may not actually be implemented using
+ * processor specific atomic operations. When possible they are
+ * implemented as true processor specific atomic operations. When that
+ * is not possible the are implemented using locks that *do* use the
+ * available atomic operations.
+ *
+ * All of the atomic operations that modify memory are full memory barriers.
+ */
+
+#ifndef SDL_atomic_h_
+#define SDL_atomic_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_platform.h"
+
+#include "begin_code.h"
+
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \name SDL AtomicLock
+ *
+ * The atomic locks are efficient spinlocks using CPU instructions,
+ * but are vulnerable to starvation and can spin forever if a thread
+ * holding a lock has been terminated. For this reason you should
+ * minimize the code executed inside an atomic lock and never do
+ * expensive things like API or system calls while holding them.
+ *
+ * The atomic locks are not safe to lock recursively.
+ *
+ * Porting Note:
+ * The spin lock functions and type are required and can not be
+ * emulated because they are used in the atomic emulation code.
+ */
+/* @{ */
+
+typedef int SDL_SpinLock;
+
+/**
+ * \brief Try to lock a spin lock by setting it to a non-zero value.
+ *
+ * \param lock Points to the lock.
+ *
+ * \return SDL_TRUE if the lock succeeded, SDL_FALSE if the lock is already held.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTryLock(SDL_SpinLock *lock);
+
+/**
+ * \brief Lock a spin lock by setting it to a non-zero value.
+ *
+ * \param lock Points to the lock.
+ */
+extern DECLSPEC void SDLCALL SDL_AtomicLock(SDL_SpinLock *lock);
+
+/**
+ * \brief Unlock a spin lock by setting it to 0. Always returns immediately
+ *
+ * \param lock Points to the lock.
+ */
+extern DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock);
+
+/* @} *//* SDL AtomicLock */
+
+
+/**
+ * The compiler barrier prevents the compiler from reordering
+ * reads and writes to globally visible variables across the call.
+ */
+#if defined(_MSC_VER) && (_MSC_VER > 1200) && !defined(__clang__)
+void _ReadWriteBarrier(void);
+#pragma intrinsic(_ReadWriteBarrier)
+#define SDL_CompilerBarrier() _ReadWriteBarrier()
+#elif (defined(__GNUC__) && !defined(__EMSCRIPTEN__)) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5120))
+/* This is correct for all CPUs when using GCC or Solaris Studio 12.1+. */
+#define SDL_CompilerBarrier() __asm__ __volatile__ ("" : : : "memory")
+#elif defined(__WATCOMC__)
+extern _inline void SDL_CompilerBarrier (void);
+#pragma aux SDL_CompilerBarrier = "" parm [] modify exact [];
+#else
+#define SDL_CompilerBarrier() \
+{ SDL_SpinLock _tmp = 0; SDL_AtomicLock(&_tmp); SDL_AtomicUnlock(&_tmp); }
+#endif
+
+/**
+ * Memory barriers are designed to prevent reads and writes from being
+ * reordered by the compiler and being seen out of order on multi-core CPUs.
+ *
+ * A typical pattern would be for thread A to write some data and a flag,
+ * and for thread B to read the flag and get the data. In this case you
+ * would insert a release barrier between writing the data and the flag,
+ * guaranteeing that the data write completes no later than the flag is
+ * written, and you would insert an acquire barrier between reading the
+ * flag and reading the data, to ensure that all the reads associated
+ * with the flag have completed.
+ *
+ * In this pattern you should always see a release barrier paired with
+ * an acquire barrier and you should gate the data reads/writes with a
+ * single flag variable.
+ *
+ * For more information on these semantics, take a look at the blog post:
+ * http://preshing.com/20120913/acquire-and-release-semantics
+ */
+extern DECLSPEC void SDLCALL SDL_MemoryBarrierReleaseFunction(void);
+extern DECLSPEC void SDLCALL SDL_MemoryBarrierAcquireFunction(void);
+
+#if defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
+#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("lwsync" : : : "memory")
+#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("lwsync" : : : "memory")
+#elif defined(__GNUC__) && defined(__aarch64__)
+#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("dmb ish" : : : "memory")
+#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("dmb ish" : : : "memory")
+#elif defined(__GNUC__) && defined(__arm__)
+#if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__)
+#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("dmb ish" : : : "memory")
+#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("dmb ish" : : : "memory")
+#elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6T2__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_5TE__)
+#ifdef __thumb__
+/* The mcr instruction isn't available in thumb mode, use real functions */
+#define SDL_MemoryBarrierRelease() SDL_MemoryBarrierReleaseFunction()
+#define SDL_MemoryBarrierAcquire() SDL_MemoryBarrierAcquireFunction()
+#else
+#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" : : "r"(0) : "memory")
+#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" : : "r"(0) : "memory")
+#endif /* __thumb__ */
+#else
+#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("" : : : "memory")
+#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("" : : : "memory")
+#endif /* __GNUC__ && __arm__ */
+#else
+#if (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5120))
+/* This is correct for all CPUs on Solaris when using Solaris Studio 12.1+. */
+#include <mbarrier.h>
+#define SDL_MemoryBarrierRelease() __machine_rel_barrier()
+#define SDL_MemoryBarrierAcquire() __machine_acq_barrier()
+#else
+/* This is correct for the x86 and x64 CPUs, and we'll expand this over time. */
+#define SDL_MemoryBarrierRelease() SDL_CompilerBarrier()
+#define SDL_MemoryBarrierAcquire() SDL_CompilerBarrier()
+#endif
+#endif
+
+/**
+ * \brief A type representing an atomic integer value. It is a struct
+ * so people don't accidentally use numeric operations on it.
+ */
+typedef struct { int value; } SDL_atomic_t;
+
+/**
+ * \brief Set an atomic variable to a new value if it is currently an old value.
+ *
+ * \return SDL_TRUE if the atomic variable was set, SDL_FALSE otherwise.
+ *
+ * \note If you don't know what this function is for, you shouldn't use it!
+*/
+extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval);
+
+/**
+ * \brief Set an atomic variable to a value.
+ *
+ * \return The previous value of the atomic variable.
+ */
+extern DECLSPEC int SDLCALL SDL_AtomicSet(SDL_atomic_t *a, int v);
+
+/**
+ * \brief Get the value of an atomic variable
+ */
+extern DECLSPEC int SDLCALL SDL_AtomicGet(SDL_atomic_t *a);
+
+/**
+ * \brief Add to an atomic variable.
+ *
+ * \return The previous value of the atomic variable.
+ *
+ * \note This same style can be used for any number operation
+ */
+extern DECLSPEC int SDLCALL SDL_AtomicAdd(SDL_atomic_t *a, int v);
+
+/**
+ * \brief Increment an atomic variable used as a reference count.
+ */
+#ifndef SDL_AtomicIncRef
+#define SDL_AtomicIncRef(a) SDL_AtomicAdd(a, 1)
+#endif
+
+/**
+ * \brief Decrement an atomic variable used as a reference count.
+ *
+ * \return SDL_TRUE if the variable reached zero after decrementing,
+ * SDL_FALSE otherwise
+ */
+#ifndef SDL_AtomicDecRef
+#define SDL_AtomicDecRef(a) (SDL_AtomicAdd(a, -1) == 1)
+#endif
+
+/**
+ * \brief Set a pointer to a new value if it is currently an old value.
+ *
+ * \return SDL_TRUE if the pointer was set, SDL_FALSE otherwise.
+ *
+ * \note If you don't know what this function is for, you shouldn't use it!
+*/
+extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr(void **a, void *oldval, void *newval);
+
+/**
+ * \brief Set a pointer to a value atomically.
+ *
+ * \return The previous value of the pointer.
+ */
+extern DECLSPEC void* SDLCALL SDL_AtomicSetPtr(void **a, void* v);
+
+/**
+ * \brief Get the value of a pointer atomically.
+ */
+extern DECLSPEC void* SDLCALL SDL_AtomicGetPtr(void **a);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+
+#include "close_code.h"
+
+#endif /* SDL_atomic_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_audio.h b/src/3rdparty/SDL2/include/SDL2/SDL_audio.h
new file mode 100644
index 0000000..d6ea689
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_audio.h
@@ -0,0 +1,825 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_audio.h
+ *
+ * Access to the raw audio mixing buffer for the SDL library.
+ */
+
+#ifndef SDL_audio_h_
+#define SDL_audio_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_endian.h"
+#include "SDL_mutex.h"
+#include "SDL_thread.h"
+#include "SDL_rwops.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Audio format flags.
+ *
+ * These are what the 16 bits in SDL_AudioFormat currently mean...
+ * (Unspecified bits are always zero).
+ *
+ * \verbatim
+ ++-----------------------sample is signed if set
+ ||
+ || ++-----------sample is bigendian if set
+ || ||
+ || || ++---sample is float if set
+ || || ||
+ || || || +---sample bit size---+
+ || || || | |
+ 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
+ \endverbatim
+ *
+ * There are macros in SDL 2.0 and later to query these bits.
+ */
+typedef Uint16 SDL_AudioFormat;
+
+/**
+ * \name Audio flags
+ */
+/* @{ */
+
+#define SDL_AUDIO_MASK_BITSIZE (0xFF)
+#define SDL_AUDIO_MASK_DATATYPE (1<<8)
+#define SDL_AUDIO_MASK_ENDIAN (1<<12)
+#define SDL_AUDIO_MASK_SIGNED (1<<15)
+#define SDL_AUDIO_BITSIZE(x) (x & SDL_AUDIO_MASK_BITSIZE)
+#define SDL_AUDIO_ISFLOAT(x) (x & SDL_AUDIO_MASK_DATATYPE)
+#define SDL_AUDIO_ISBIGENDIAN(x) (x & SDL_AUDIO_MASK_ENDIAN)
+#define SDL_AUDIO_ISSIGNED(x) (x & SDL_AUDIO_MASK_SIGNED)
+#define SDL_AUDIO_ISINT(x) (!SDL_AUDIO_ISFLOAT(x))
+#define SDL_AUDIO_ISLITTLEENDIAN(x) (!SDL_AUDIO_ISBIGENDIAN(x))
+#define SDL_AUDIO_ISUNSIGNED(x) (!SDL_AUDIO_ISSIGNED(x))
+
+/**
+ * \name Audio format flags
+ *
+ * Defaults to LSB byte order.
+ */
+/* @{ */
+#define AUDIO_U8 0x0008 /**< Unsigned 8-bit samples */
+#define AUDIO_S8 0x8008 /**< Signed 8-bit samples */
+#define AUDIO_U16LSB 0x0010 /**< Unsigned 16-bit samples */
+#define AUDIO_S16LSB 0x8010 /**< Signed 16-bit samples */
+#define AUDIO_U16MSB 0x1010 /**< As above, but big-endian byte order */
+#define AUDIO_S16MSB 0x9010 /**< As above, but big-endian byte order */
+#define AUDIO_U16 AUDIO_U16LSB
+#define AUDIO_S16 AUDIO_S16LSB
+/* @} */
+
+/**
+ * \name int32 support
+ */
+/* @{ */
+#define AUDIO_S32LSB 0x8020 /**< 32-bit integer samples */
+#define AUDIO_S32MSB 0x9020 /**< As above, but big-endian byte order */
+#define AUDIO_S32 AUDIO_S32LSB
+/* @} */
+
+/**
+ * \name float32 support
+ */
+/* @{ */
+#define AUDIO_F32LSB 0x8120 /**< 32-bit floating point samples */
+#define AUDIO_F32MSB 0x9120 /**< As above, but big-endian byte order */
+#define AUDIO_F32 AUDIO_F32LSB
+/* @} */
+
+/**
+ * \name Native audio byte ordering
+ */
+/* @{ */
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+#define AUDIO_U16SYS AUDIO_U16LSB
+#define AUDIO_S16SYS AUDIO_S16LSB
+#define AUDIO_S32SYS AUDIO_S32LSB
+#define AUDIO_F32SYS AUDIO_F32LSB
+#else
+#define AUDIO_U16SYS AUDIO_U16MSB
+#define AUDIO_S16SYS AUDIO_S16MSB
+#define AUDIO_S32SYS AUDIO_S32MSB
+#define AUDIO_F32SYS AUDIO_F32MSB
+#endif
+/* @} */
+
+/**
+ * \name Allow change flags
+ *
+ * Which audio format changes are allowed when opening a device.
+ */
+/* @{ */
+#define SDL_AUDIO_ALLOW_FREQUENCY_CHANGE 0x00000001
+#define SDL_AUDIO_ALLOW_FORMAT_CHANGE 0x00000002
+#define SDL_AUDIO_ALLOW_CHANNELS_CHANGE 0x00000004
+#define SDL_AUDIO_ALLOW_ANY_CHANGE (SDL_AUDIO_ALLOW_FREQUENCY_CHANGE|SDL_AUDIO_ALLOW_FORMAT_CHANGE|SDL_AUDIO_ALLOW_CHANNELS_CHANGE)
+/* @} */
+
+/* @} *//* Audio flags */
+
+/**
+ * This function is called when the audio device needs more data.
+ *
+ * \param userdata An application-specific parameter saved in
+ * the SDL_AudioSpec structure
+ * \param stream A pointer to the audio data buffer.
+ * \param len The length of that buffer in bytes.
+ *
+ * Once the callback returns, the buffer will no longer be valid.
+ * Stereo samples are stored in a LRLRLR ordering.
+ *
+ * You can choose to avoid callbacks and use SDL_QueueAudio() instead, if
+ * you like. Just open your audio device with a NULL callback.
+ */
+typedef void (SDLCALL * SDL_AudioCallback) (void *userdata, Uint8 * stream,
+ int len);
+
+/**
+ * The calculated values in this structure are calculated by SDL_OpenAudio().
+ *
+ * For multi-channel audio, the default SDL channel mapping is:
+ * 2: FL FR (stereo)
+ * 3: FL FR LFE (2.1 surround)
+ * 4: FL FR BL BR (quad)
+ * 5: FL FR FC BL BR (quad + center)
+ * 6: FL FR FC LFE SL SR (5.1 surround - last two can also be BL BR)
+ * 7: FL FR FC LFE BC SL SR (6.1 surround)
+ * 8: FL FR FC LFE BL BR SL SR (7.1 surround)
+ */
+typedef struct SDL_AudioSpec
+{
+ int freq; /**< DSP frequency -- samples per second */
+ SDL_AudioFormat format; /**< Audio data format */
+ Uint8 channels; /**< Number of channels: 1 mono, 2 stereo */
+ Uint8 silence; /**< Audio buffer silence value (calculated) */
+ Uint16 samples; /**< Audio buffer size in sample FRAMES (total samples divided by channel count) */
+ Uint16 padding; /**< Necessary for some compile environments */
+ Uint32 size; /**< Audio buffer size in bytes (calculated) */
+ SDL_AudioCallback callback; /**< Callback that feeds the audio device (NULL to use SDL_QueueAudio()). */
+ void *userdata; /**< Userdata passed to callback (ignored for NULL callbacks). */
+} SDL_AudioSpec;
+
+
+struct SDL_AudioCVT;
+typedef void (SDLCALL * SDL_AudioFilter) (struct SDL_AudioCVT * cvt,
+ SDL_AudioFormat format);
+
+/**
+ * \brief Upper limit of filters in SDL_AudioCVT
+ *
+ * The maximum number of SDL_AudioFilter functions in SDL_AudioCVT is
+ * currently limited to 9. The SDL_AudioCVT.filters array has 10 pointers,
+ * one of which is the terminating NULL pointer.
+ */
+#define SDL_AUDIOCVT_MAX_FILTERS 9
+
+/**
+ * \struct SDL_AudioCVT
+ * \brief A structure to hold a set of audio conversion filters and buffers.
+ *
+ * Note that various parts of the conversion pipeline can take advantage
+ * of SIMD operations (like SSE2, for example). SDL_AudioCVT doesn't require
+ * you to pass it aligned data, but can possibly run much faster if you
+ * set both its (buf) field to a pointer that is aligned to 16 bytes, and its
+ * (len) field to something that's a multiple of 16, if possible.
+ */
+#ifdef __GNUC__
+/* This structure is 84 bytes on 32-bit architectures, make sure GCC doesn't
+ pad it out to 88 bytes to guarantee ABI compatibility between compilers.
+ vvv
+ The next time we rev the ABI, make sure to size the ints and add padding.
+*/
+#define SDL_AUDIOCVT_PACKED __attribute__((packed))
+#else
+#define SDL_AUDIOCVT_PACKED
+#endif
+/* */
+typedef struct SDL_AudioCVT
+{
+ int needed; /**< Set to 1 if conversion possible */
+ SDL_AudioFormat src_format; /**< Source audio format */
+ SDL_AudioFormat dst_format; /**< Target audio format */
+ double rate_incr; /**< Rate conversion increment */
+ Uint8 *buf; /**< Buffer to hold entire audio data */
+ int len; /**< Length of original audio buffer */
+ int len_cvt; /**< Length of converted audio buffer */
+ int len_mult; /**< buffer must be len*len_mult big */
+ double len_ratio; /**< Given len, final size is len*len_ratio */
+ SDL_AudioFilter filters[SDL_AUDIOCVT_MAX_FILTERS + 1]; /**< NULL-terminated list of filter functions */
+ int filter_index; /**< Current audio conversion function */
+} SDL_AUDIOCVT_PACKED SDL_AudioCVT;
+
+
+/* Function prototypes */
+
+/**
+ * \name Driver discovery functions
+ *
+ * These functions return the list of built in audio drivers, in the
+ * order that they are normally initialized by default.
+ */
+/* @{ */
+extern DECLSPEC int SDLCALL SDL_GetNumAudioDrivers(void);
+extern DECLSPEC const char *SDLCALL SDL_GetAudioDriver(int index);
+/* @} */
+
+/**
+ * \name Initialization and cleanup
+ *
+ * \internal These functions are used internally, and should not be used unless
+ * you have a specific need to specify the audio driver you want to
+ * use. You should normally use SDL_Init() or SDL_InitSubSystem().
+ */
+/* @{ */
+extern DECLSPEC int SDLCALL SDL_AudioInit(const char *driver_name);
+extern DECLSPEC void SDLCALL SDL_AudioQuit(void);
+/* @} */
+
+/**
+ * This function returns the name of the current audio driver, or NULL
+ * if no driver has been initialized.
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetCurrentAudioDriver(void);
+
+/**
+ * This function opens the audio device with the desired parameters, and
+ * returns 0 if successful, placing the actual hardware parameters in the
+ * structure pointed to by \c obtained. If \c obtained is NULL, the audio
+ * data passed to the callback function will be guaranteed to be in the
+ * requested format, and will be automatically converted to the hardware
+ * audio format if necessary. This function returns -1 if it failed
+ * to open the audio device, or couldn't set up the audio thread.
+ *
+ * When filling in the desired audio spec structure,
+ * - \c desired->freq should be the desired audio frequency in samples-per-
+ * second.
+ * - \c desired->format should be the desired audio format.
+ * - \c desired->samples is the desired size of the audio buffer, in
+ * samples. This number should be a power of two, and may be adjusted by
+ * the audio driver to a value more suitable for the hardware. Good values
+ * seem to range between 512 and 8096 inclusive, depending on the
+ * application and CPU speed. Smaller values yield faster response time,
+ * but can lead to underflow if the application is doing heavy processing
+ * and cannot fill the audio buffer in time. A stereo sample consists of
+ * both right and left channels in LR ordering.
+ * Note that the number of samples is directly related to time by the
+ * following formula: \code ms = (samples*1000)/freq \endcode
+ * - \c desired->size is the size in bytes of the audio buffer, and is
+ * calculated by SDL_OpenAudio().
+ * - \c desired->silence is the value used to set the buffer to silence,
+ * and is calculated by SDL_OpenAudio().
+ * - \c desired->callback should be set to a function that will be called
+ * when the audio device is ready for more data. It is passed a pointer
+ * to the audio buffer, and the length in bytes of the audio buffer.
+ * This function usually runs in a separate thread, and so you should
+ * protect data structures that it accesses by calling SDL_LockAudio()
+ * and SDL_UnlockAudio() in your code. Alternately, you may pass a NULL
+ * pointer here, and call SDL_QueueAudio() with some frequency, to queue
+ * more audio samples to be played (or for capture devices, call
+ * SDL_DequeueAudio() with some frequency, to obtain audio samples).
+ * - \c desired->userdata is passed as the first parameter to your callback
+ * function. If you passed a NULL callback, this value is ignored.
+ *
+ * The audio device starts out playing silence when it's opened, and should
+ * be enabled for playing by calling \c SDL_PauseAudio(0) when you are ready
+ * for your audio callback function to be called. Since the audio driver
+ * may modify the requested size of the audio buffer, you should allocate
+ * any local mixing buffers after you open the audio device.
+ */
+extern DECLSPEC int SDLCALL SDL_OpenAudio(SDL_AudioSpec * desired,
+ SDL_AudioSpec * obtained);
+
+/**
+ * SDL Audio Device IDs.
+ *
+ * A successful call to SDL_OpenAudio() is always device id 1, and legacy
+ * SDL audio APIs assume you want this device ID. SDL_OpenAudioDevice() calls
+ * always returns devices >= 2 on success. The legacy calls are good both
+ * for backwards compatibility and when you don't care about multiple,
+ * specific, or capture devices.
+ */
+typedef Uint32 SDL_AudioDeviceID;
+
+/**
+ * Get the number of available devices exposed by the current driver.
+ * Only valid after a successfully initializing the audio subsystem.
+ * Returns -1 if an explicit list of devices can't be determined; this is
+ * not an error. For example, if SDL is set up to talk to a remote audio
+ * server, it can't list every one available on the Internet, but it will
+ * still allow a specific host to be specified to SDL_OpenAudioDevice().
+ *
+ * In many common cases, when this function returns a value <= 0, it can still
+ * successfully open the default device (NULL for first argument of
+ * SDL_OpenAudioDevice()).
+ */
+extern DECLSPEC int SDLCALL SDL_GetNumAudioDevices(int iscapture);
+
+/**
+ * Get the human-readable name of a specific audio device.
+ * Must be a value between 0 and (number of audio devices-1).
+ * Only valid after a successfully initializing the audio subsystem.
+ * The values returned by this function reflect the latest call to
+ * SDL_GetNumAudioDevices(); recall that function to redetect available
+ * hardware.
+ *
+ * The string returned by this function is UTF-8 encoded, read-only, and
+ * managed internally. You are not to free it. If you need to keep the
+ * string for any length of time, you should make your own copy of it, as it
+ * will be invalid next time any of several other SDL functions is called.
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetAudioDeviceName(int index,
+ int iscapture);
+
+
+/**
+ * Open a specific audio device. Passing in a device name of NULL requests
+ * the most reasonable default (and is equivalent to calling SDL_OpenAudio()).
+ *
+ * The device name is a UTF-8 string reported by SDL_GetAudioDeviceName(), but
+ * some drivers allow arbitrary and driver-specific strings, such as a
+ * hostname/IP address for a remote audio server, or a filename in the
+ * diskaudio driver.
+ *
+ * \return 0 on error, a valid device ID that is >= 2 on success.
+ *
+ * SDL_OpenAudio(), unlike this function, always acts on device ID 1.
+ */
+extern DECLSPEC SDL_AudioDeviceID SDLCALL SDL_OpenAudioDevice(const char
+ *device,
+ int iscapture,
+ const
+ SDL_AudioSpec *
+ desired,
+ SDL_AudioSpec *
+ obtained,
+ int
+ allowed_changes);
+
+
+
+/**
+ * \name Audio state
+ *
+ * Get the current audio state.
+ */
+/* @{ */
+typedef enum
+{
+ SDL_AUDIO_STOPPED = 0,
+ SDL_AUDIO_PLAYING,
+ SDL_AUDIO_PAUSED
+} SDL_AudioStatus;
+extern DECLSPEC SDL_AudioStatus SDLCALL SDL_GetAudioStatus(void);
+
+extern DECLSPEC SDL_AudioStatus SDLCALL
+SDL_GetAudioDeviceStatus(SDL_AudioDeviceID dev);
+/* @} *//* Audio State */
+
+/**
+ * \name Pause audio functions
+ *
+ * These functions pause and unpause the audio callback processing.
+ * They should be called with a parameter of 0 after opening the audio
+ * device to start playing sound. This is so you can safely initialize
+ * data for your callback function after opening the audio device.
+ * Silence will be written to the audio device during the pause.
+ */
+/* @{ */
+extern DECLSPEC void SDLCALL SDL_PauseAudio(int pause_on);
+extern DECLSPEC void SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev,
+ int pause_on);
+/* @} *//* Pause audio functions */
+
+/**
+ * This function loads a WAVE from the data source, automatically freeing
+ * that source if \c freesrc is non-zero. For example, to load a WAVE file,
+ * you could do:
+ * \code
+ * SDL_LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, ...);
+ * \endcode
+ *
+ * If this function succeeds, it returns the given SDL_AudioSpec,
+ * filled with the audio data format of the wave data, and sets
+ * \c *audio_buf to a malloc()'d buffer containing the audio data,
+ * and sets \c *audio_len to the length of that audio buffer, in bytes.
+ * You need to free the audio buffer with SDL_FreeWAV() when you are
+ * done with it.
+ *
+ * This function returns NULL and sets the SDL error message if the
+ * wave file cannot be opened, uses an unknown data format, or is
+ * corrupt. Currently raw and MS-ADPCM WAVE files are supported.
+ */
+extern DECLSPEC SDL_AudioSpec *SDLCALL SDL_LoadWAV_RW(SDL_RWops * src,
+ int freesrc,
+ SDL_AudioSpec * spec,
+ Uint8 ** audio_buf,
+ Uint32 * audio_len);
+
+/**
+ * Loads a WAV from a file.
+ * Compatibility convenience function.
+ */
+#define SDL_LoadWAV(file, spec, audio_buf, audio_len) \
+ SDL_LoadWAV_RW(SDL_RWFromFile(file, "rb"),1, spec,audio_buf,audio_len)
+
+/**
+ * This function frees data previously allocated with SDL_LoadWAV_RW()
+ */
+extern DECLSPEC void SDLCALL SDL_FreeWAV(Uint8 * audio_buf);
+
+/**
+ * This function takes a source format and rate and a destination format
+ * and rate, and initializes the \c cvt structure with information needed
+ * by SDL_ConvertAudio() to convert a buffer of audio data from one format
+ * to the other. An unsupported format causes an error and -1 will be returned.
+ *
+ * \return 0 if no conversion is needed, 1 if the audio filter is set up,
+ * or -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_BuildAudioCVT(SDL_AudioCVT * cvt,
+ SDL_AudioFormat src_format,
+ Uint8 src_channels,
+ int src_rate,
+ SDL_AudioFormat dst_format,
+ Uint8 dst_channels,
+ int dst_rate);
+
+/**
+ * Once you have initialized the \c cvt structure using SDL_BuildAudioCVT(),
+ * created an audio buffer \c cvt->buf, and filled it with \c cvt->len bytes of
+ * audio data in the source format, this function will convert it in-place
+ * to the desired format.
+ *
+ * The data conversion may expand the size of the audio data, so the buffer
+ * \c cvt->buf should be allocated after the \c cvt structure is initialized by
+ * SDL_BuildAudioCVT(), and should be \c cvt->len*cvt->len_mult bytes long.
+ *
+ * \return 0 on success or -1 if \c cvt->buf is NULL.
+ */
+extern DECLSPEC int SDLCALL SDL_ConvertAudio(SDL_AudioCVT * cvt);
+
+/* SDL_AudioStream is a new audio conversion interface.
+ The benefits vs SDL_AudioCVT:
+ - it can handle resampling data in chunks without generating
+ artifacts, when it doesn't have the complete buffer available.
+ - it can handle incoming data in any variable size.
+ - You push data as you have it, and pull it when you need it
+ */
+/* this is opaque to the outside world. */
+struct _SDL_AudioStream;
+typedef struct _SDL_AudioStream SDL_AudioStream;
+
+/**
+ * Create a new audio stream
+ *
+ * \param src_format The format of the source audio
+ * \param src_channels The number of channels of the source audio
+ * \param src_rate The sampling rate of the source audio
+ * \param dst_format The format of the desired audio output
+ * \param dst_channels The number of channels of the desired audio output
+ * \param dst_rate The sampling rate of the desired audio output
+ * \return 0 on success, or -1 on error.
+ *
+ * \sa SDL_AudioStreamPut
+ * \sa SDL_AudioStreamGet
+ * \sa SDL_AudioStreamAvailable
+ * \sa SDL_AudioStreamFlush
+ * \sa SDL_AudioStreamClear
+ * \sa SDL_FreeAudioStream
+ */
+extern DECLSPEC SDL_AudioStream * SDLCALL SDL_NewAudioStream(const SDL_AudioFormat src_format,
+ const Uint8 src_channels,
+ const int src_rate,
+ const SDL_AudioFormat dst_format,
+ const Uint8 dst_channels,
+ const int dst_rate);
+
+/**
+ * Add data to be converted/resampled to the stream
+ *
+ * \param stream The stream the audio data is being added to
+ * \param buf A pointer to the audio data to add
+ * \param len The number of bytes to write to the stream
+ * \return 0 on success, or -1 on error.
+ *
+ * \sa SDL_NewAudioStream
+ * \sa SDL_AudioStreamGet
+ * \sa SDL_AudioStreamAvailable
+ * \sa SDL_AudioStreamFlush
+ * \sa SDL_AudioStreamClear
+ * \sa SDL_FreeAudioStream
+ */
+extern DECLSPEC int SDLCALL SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len);
+
+/**
+ * Get converted/resampled data from the stream
+ *
+ * \param stream The stream the audio is being requested from
+ * \param buf A buffer to fill with audio data
+ * \param len The maximum number of bytes to fill
+ * \return The number of bytes read from the stream, or -1 on error
+ *
+ * \sa SDL_NewAudioStream
+ * \sa SDL_AudioStreamPut
+ * \sa SDL_AudioStreamAvailable
+ * \sa SDL_AudioStreamFlush
+ * \sa SDL_AudioStreamClear
+ * \sa SDL_FreeAudioStream
+ */
+extern DECLSPEC int SDLCALL SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len);
+
+/**
+ * Get the number of converted/resampled bytes available. The stream may be
+ * buffering data behind the scenes until it has enough to resample
+ * correctly, so this number might be lower than what you expect, or even
+ * be zero. Add more data or flush the stream if you need the data now.
+ *
+ * \sa SDL_NewAudioStream
+ * \sa SDL_AudioStreamPut
+ * \sa SDL_AudioStreamGet
+ * \sa SDL_AudioStreamFlush
+ * \sa SDL_AudioStreamClear
+ * \sa SDL_FreeAudioStream
+ */
+extern DECLSPEC int SDLCALL SDL_AudioStreamAvailable(SDL_AudioStream *stream);
+
+/**
+ * Tell the stream that you're done sending data, and anything being buffered
+ * should be converted/resampled and made available immediately.
+ *
+ * It is legal to add more data to a stream after flushing, but there will
+ * be audio gaps in the output. Generally this is intended to signal the
+ * end of input, so the complete output becomes available.
+ *
+ * \sa SDL_NewAudioStream
+ * \sa SDL_AudioStreamPut
+ * \sa SDL_AudioStreamGet
+ * \sa SDL_AudioStreamAvailable
+ * \sa SDL_AudioStreamClear
+ * \sa SDL_FreeAudioStream
+ */
+extern DECLSPEC int SDLCALL SDL_AudioStreamFlush(SDL_AudioStream *stream);
+
+/**
+ * Clear any pending data in the stream without converting it
+ *
+ * \sa SDL_NewAudioStream
+ * \sa SDL_AudioStreamPut
+ * \sa SDL_AudioStreamGet
+ * \sa SDL_AudioStreamAvailable
+ * \sa SDL_AudioStreamFlush
+ * \sa SDL_FreeAudioStream
+ */
+extern DECLSPEC void SDLCALL SDL_AudioStreamClear(SDL_AudioStream *stream);
+
+/**
+ * Free an audio stream
+ *
+ * \sa SDL_NewAudioStream
+ * \sa SDL_AudioStreamPut
+ * \sa SDL_AudioStreamGet
+ * \sa SDL_AudioStreamAvailable
+ * \sa SDL_AudioStreamFlush
+ * \sa SDL_AudioStreamClear
+ */
+extern DECLSPEC void SDLCALL SDL_FreeAudioStream(SDL_AudioStream *stream);
+
+#define SDL_MIX_MAXVOLUME 128
+/**
+ * This takes two audio buffers of the playing audio format and mixes
+ * them, performing addition, volume adjustment, and overflow clipping.
+ * The volume ranges from 0 - 128, and should be set to ::SDL_MIX_MAXVOLUME
+ * for full audio volume. Note this does not change hardware volume.
+ * This is provided for convenience -- you can mix your own audio data.
+ */
+extern DECLSPEC void SDLCALL SDL_MixAudio(Uint8 * dst, const Uint8 * src,
+ Uint32 len, int volume);
+
+/**
+ * This works like SDL_MixAudio(), but you specify the audio format instead of
+ * using the format of audio device 1. Thus it can be used when no audio
+ * device is open at all.
+ */
+extern DECLSPEC void SDLCALL SDL_MixAudioFormat(Uint8 * dst,
+ const Uint8 * src,
+ SDL_AudioFormat format,
+ Uint32 len, int volume);
+
+/**
+ * Queue more audio on non-callback devices.
+ *
+ * (If you are looking to retrieve queued audio from a non-callback capture
+ * device, you want SDL_DequeueAudio() instead. This will return -1 to
+ * signify an error if you use it with capture devices.)
+ *
+ * SDL offers two ways to feed audio to the device: you can either supply a
+ * callback that SDL triggers with some frequency to obtain more audio
+ * (pull method), or you can supply no callback, and then SDL will expect
+ * you to supply data at regular intervals (push method) with this function.
+ *
+ * There are no limits on the amount of data you can queue, short of
+ * exhaustion of address space. Queued data will drain to the device as
+ * necessary without further intervention from you. If the device needs
+ * audio but there is not enough queued, it will play silence to make up
+ * the difference. This means you will have skips in your audio playback
+ * if you aren't routinely queueing sufficient data.
+ *
+ * This function copies the supplied data, so you are safe to free it when
+ * the function returns. This function is thread-safe, but queueing to the
+ * same device from two threads at once does not promise which buffer will
+ * be queued first.
+ *
+ * You may not queue audio on a device that is using an application-supplied
+ * callback; doing so returns an error. You have to use the audio callback
+ * or queue audio with this function, but not both.
+ *
+ * You should not call SDL_LockAudio() on the device before queueing; SDL
+ * handles locking internally for this function.
+ *
+ * \param dev The device ID to which we will queue audio.
+ * \param data The data to queue to the device for later playback.
+ * \param len The number of bytes (not samples!) to which (data) points.
+ * \return 0 on success, or -1 on error.
+ *
+ * \sa SDL_GetQueuedAudioSize
+ * \sa SDL_ClearQueuedAudio
+ */
+extern DECLSPEC int SDLCALL SDL_QueueAudio(SDL_AudioDeviceID dev, const void *data, Uint32 len);
+
+/**
+ * Dequeue more audio on non-callback devices.
+ *
+ * (If you are looking to queue audio for output on a non-callback playback
+ * device, you want SDL_QueueAudio() instead. This will always return 0
+ * if you use it with playback devices.)
+ *
+ * SDL offers two ways to retrieve audio from a capture device: you can
+ * either supply a callback that SDL triggers with some frequency as the
+ * device records more audio data, (push method), or you can supply no
+ * callback, and then SDL will expect you to retrieve data at regular
+ * intervals (pull method) with this function.
+ *
+ * There are no limits on the amount of data you can queue, short of
+ * exhaustion of address space. Data from the device will keep queuing as
+ * necessary without further intervention from you. This means you will
+ * eventually run out of memory if you aren't routinely dequeueing data.
+ *
+ * Capture devices will not queue data when paused; if you are expecting
+ * to not need captured audio for some length of time, use
+ * SDL_PauseAudioDevice() to stop the capture device from queueing more
+ * data. This can be useful during, say, level loading times. When
+ * unpaused, capture devices will start queueing data from that point,
+ * having flushed any capturable data available while paused.
+ *
+ * This function is thread-safe, but dequeueing from the same device from
+ * two threads at once does not promise which thread will dequeued data
+ * first.
+ *
+ * You may not dequeue audio from a device that is using an
+ * application-supplied callback; doing so returns an error. You have to use
+ * the audio callback, or dequeue audio with this function, but not both.
+ *
+ * You should not call SDL_LockAudio() on the device before queueing; SDL
+ * handles locking internally for this function.
+ *
+ * \param dev The device ID from which we will dequeue audio.
+ * \param data A pointer into where audio data should be copied.
+ * \param len The number of bytes (not samples!) to which (data) points.
+ * \return number of bytes dequeued, which could be less than requested.
+ *
+ * \sa SDL_GetQueuedAudioSize
+ * \sa SDL_ClearQueuedAudio
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_DequeueAudio(SDL_AudioDeviceID dev, void *data, Uint32 len);
+
+/**
+ * Get the number of bytes of still-queued audio.
+ *
+ * For playback device:
+ *
+ * This is the number of bytes that have been queued for playback with
+ * SDL_QueueAudio(), but have not yet been sent to the hardware. This
+ * number may shrink at any time, so this only informs of pending data.
+ *
+ * Once we've sent it to the hardware, this function can not decide the
+ * exact byte boundary of what has been played. It's possible that we just
+ * gave the hardware several kilobytes right before you called this
+ * function, but it hasn't played any of it yet, or maybe half of it, etc.
+ *
+ * For capture devices:
+ *
+ * This is the number of bytes that have been captured by the device and
+ * are waiting for you to dequeue. This number may grow at any time, so
+ * this only informs of the lower-bound of available data.
+ *
+ * You may not queue audio on a device that is using an application-supplied
+ * callback; calling this function on such a device always returns 0.
+ * You have to queue audio with SDL_QueueAudio()/SDL_DequeueAudio(), or use
+ * the audio callback, but not both.
+ *
+ * You should not call SDL_LockAudio() on the device before querying; SDL
+ * handles locking internally for this function.
+ *
+ * \param dev The device ID of which we will query queued audio size.
+ * \return Number of bytes (not samples!) of queued audio.
+ *
+ * \sa SDL_QueueAudio
+ * \sa SDL_ClearQueuedAudio
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_GetQueuedAudioSize(SDL_AudioDeviceID dev);
+
+/**
+ * Drop any queued audio data. For playback devices, this is any queued data
+ * still waiting to be submitted to the hardware. For capture devices, this
+ * is any data that was queued by the device that hasn't yet been dequeued by
+ * the application.
+ *
+ * Immediately after this call, SDL_GetQueuedAudioSize() will return 0. For
+ * playback devices, the hardware will start playing silence if more audio
+ * isn't queued. Unpaused capture devices will start filling the queue again
+ * as soon as they have more data available (which, depending on the state
+ * of the hardware and the thread, could be before this function call
+ * returns!).
+ *
+ * This will not prevent playback of queued audio that's already been sent
+ * to the hardware, as we can not undo that, so expect there to be some
+ * fraction of a second of audio that might still be heard. This can be
+ * useful if you want to, say, drop any pending music during a level change
+ * in your game.
+ *
+ * You may not queue audio on a device that is using an application-supplied
+ * callback; calling this function on such a device is always a no-op.
+ * You have to queue audio with SDL_QueueAudio()/SDL_DequeueAudio(), or use
+ * the audio callback, but not both.
+ *
+ * You should not call SDL_LockAudio() on the device before clearing the
+ * queue; SDL handles locking internally for this function.
+ *
+ * This function always succeeds and thus returns void.
+ *
+ * \param dev The device ID of which to clear the audio queue.
+ *
+ * \sa SDL_QueueAudio
+ * \sa SDL_GetQueuedAudioSize
+ */
+extern DECLSPEC void SDLCALL SDL_ClearQueuedAudio(SDL_AudioDeviceID dev);
+
+
+/**
+ * \name Audio lock functions
+ *
+ * The lock manipulated by these functions protects the callback function.
+ * During a SDL_LockAudio()/SDL_UnlockAudio() pair, you can be guaranteed that
+ * the callback function is not running. Do not call these from the callback
+ * function or you will cause deadlock.
+ */
+/* @{ */
+extern DECLSPEC void SDLCALL SDL_LockAudio(void);
+extern DECLSPEC void SDLCALL SDL_LockAudioDevice(SDL_AudioDeviceID dev);
+extern DECLSPEC void SDLCALL SDL_UnlockAudio(void);
+extern DECLSPEC void SDLCALL SDL_UnlockAudioDevice(SDL_AudioDeviceID dev);
+/* @} *//* Audio lock functions */
+
+/**
+ * This function shuts down audio processing and closes the audio device.
+ */
+extern DECLSPEC void SDLCALL SDL_CloseAudio(void);
+extern DECLSPEC void SDLCALL SDL_CloseAudioDevice(SDL_AudioDeviceID dev);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_audio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_bits.h b/src/3rdparty/SDL2/include/SDL2/SDL_bits.h
new file mode 100644
index 0000000..eb8322f
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_bits.h
@@ -0,0 +1,112 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_bits.h
+ *
+ * Functions for fiddling with bits and bitmasks.
+ */
+
+#ifndef SDL_bits_h_
+#define SDL_bits_h_
+
+#include "SDL_stdinc.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \file SDL_bits.h
+ */
+
+/**
+ * Get the index of the most significant bit. Result is undefined when called
+ * with 0. This operation can also be stated as "count leading zeroes" and
+ * "log base 2".
+ *
+ * \return Index of the most significant bit, or -1 if the value is 0.
+ */
+#if defined(__WATCOMC__) && defined(__386__)
+extern _inline int _SDL_clz_watcom (Uint32);
+#pragma aux _SDL_clz_watcom = \
+ "bsr eax, eax" \
+ "xor eax, 31" \
+ parm [eax] nomemory \
+ value [eax] \
+ modify exact [eax] nomemory;
+#endif
+
+SDL_FORCE_INLINE int
+SDL_MostSignificantBitIndex32(Uint32 x)
+{
+#if defined(__GNUC__) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+ /* Count Leading Zeroes builtin in GCC.
+ * http://gcc.gnu.org/onlinedocs/gcc-4.3.4/gcc/Other-Builtins.html
+ */
+ if (x == 0) {
+ return -1;
+ }
+ return 31 - __builtin_clz(x);
+#elif defined(__WATCOMC__) && defined(__386__)
+ if (x == 0) {
+ return -1;
+ }
+ return 31 - _SDL_clz_watcom(x);
+#else
+ /* Based off of Bit Twiddling Hacks by Sean Eron Anderson
+ * <seander@cs.stanford.edu>, released in the public domain.
+ * http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog
+ */
+ const Uint32 b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000};
+ const int S[] = {1, 2, 4, 8, 16};
+
+ int msbIndex = 0;
+ int i;
+
+ if (x == 0) {
+ return -1;
+ }
+
+ for (i = 4; i >= 0; i--)
+ {
+ if (x & b[i])
+ {
+ x >>= S[i];
+ msbIndex |= S[i];
+ }
+ }
+
+ return msbIndex;
+#endif
+}
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_bits_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_blendmode.h b/src/3rdparty/SDL2/include/SDL2/SDL_blendmode.h
new file mode 100644
index 0000000..36a5ea7
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_blendmode.h
@@ -0,0 +1,120 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_blendmode.h
+ *
+ * Header file declaring the SDL_BlendMode enumeration
+ */
+
+#ifndef SDL_blendmode_h_
+#define SDL_blendmode_h_
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The blend mode used in SDL_RenderCopy() and drawing operations.
+ */
+typedef enum
+{
+ SDL_BLENDMODE_NONE = 0x00000000, /**< no blending
+ dstRGBA = srcRGBA */
+ SDL_BLENDMODE_BLEND = 0x00000001, /**< alpha blending
+ dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
+ dstA = srcA + (dstA * (1-srcA)) */
+ SDL_BLENDMODE_ADD = 0x00000002, /**< additive blending
+ dstRGB = (srcRGB * srcA) + dstRGB
+ dstA = dstA */
+ SDL_BLENDMODE_MOD = 0x00000004, /**< color modulate
+ dstRGB = srcRGB * dstRGB
+ dstA = dstA */
+ SDL_BLENDMODE_INVALID = 0x7FFFFFFF
+
+ /* Additional custom blend modes can be returned by SDL_ComposeCustomBlendMode() */
+
+} SDL_BlendMode;
+
+/**
+ * \brief The blend operation used when combining source and destination pixel components
+ */
+typedef enum
+{
+ SDL_BLENDOPERATION_ADD = 0x1, /**< dst + src: supported by all renderers */
+ SDL_BLENDOPERATION_SUBTRACT = 0x2, /**< dst - src : supported by D3D9, D3D11, OpenGL, OpenGLES */
+ SDL_BLENDOPERATION_REV_SUBTRACT = 0x3, /**< src - dst : supported by D3D9, D3D11, OpenGL, OpenGLES */
+ SDL_BLENDOPERATION_MINIMUM = 0x4, /**< min(dst, src) : supported by D3D11 */
+ SDL_BLENDOPERATION_MAXIMUM = 0x5 /**< max(dst, src) : supported by D3D11 */
+
+} SDL_BlendOperation;
+
+/**
+ * \brief The normalized factor used to multiply pixel components
+ */
+typedef enum
+{
+ SDL_BLENDFACTOR_ZERO = 0x1, /**< 0, 0, 0, 0 */
+ SDL_BLENDFACTOR_ONE = 0x2, /**< 1, 1, 1, 1 */
+ SDL_BLENDFACTOR_SRC_COLOR = 0x3, /**< srcR, srcG, srcB, srcA */
+ SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR = 0x4, /**< 1-srcR, 1-srcG, 1-srcB, 1-srcA */
+ SDL_BLENDFACTOR_SRC_ALPHA = 0x5, /**< srcA, srcA, srcA, srcA */
+ SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA = 0x6, /**< 1-srcA, 1-srcA, 1-srcA, 1-srcA */
+ SDL_BLENDFACTOR_DST_COLOR = 0x7, /**< dstR, dstG, dstB, dstA */
+ SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR = 0x8, /**< 1-dstR, 1-dstG, 1-dstB, 1-dstA */
+ SDL_BLENDFACTOR_DST_ALPHA = 0x9, /**< dstA, dstA, dstA, dstA */
+ SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA = 0xA /**< 1-dstA, 1-dstA, 1-dstA, 1-dstA */
+
+} SDL_BlendFactor;
+
+/**
+ * \brief Create a custom blend mode, which may or may not be supported by a given renderer
+ *
+ * \param srcColorFactor
+ * \param dstColorFactor
+ * \param colorOperation
+ * \param srcAlphaFactor
+ * \param dstAlphaFactor
+ * \param alphaOperation
+ *
+ * The result of the blend mode operation will be:
+ * dstRGB = dstRGB * dstColorFactor colorOperation srcRGB * srcColorFactor
+ * and
+ * dstA = dstA * dstAlphaFactor alphaOperation srcA * srcAlphaFactor
+ */
+extern DECLSPEC SDL_BlendMode SDLCALL SDL_ComposeCustomBlendMode(SDL_BlendFactor srcColorFactor,
+ SDL_BlendFactor dstColorFactor,
+ SDL_BlendOperation colorOperation,
+ SDL_BlendFactor srcAlphaFactor,
+ SDL_BlendFactor dstAlphaFactor,
+ SDL_BlendOperation alphaOperation);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_blendmode_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_clipboard.h b/src/3rdparty/SDL2/include/SDL2/SDL_clipboard.h
new file mode 100644
index 0000000..f28751e
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_clipboard.h
@@ -0,0 +1,71 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_clipboard.h
+ *
+ * Include file for SDL clipboard handling
+ */
+
+#ifndef SDL_clipboard_h_
+#define SDL_clipboard_h_
+
+#include "SDL_stdinc.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Function prototypes */
+
+/**
+ * \brief Put UTF-8 text into the clipboard
+ *
+ * \sa SDL_GetClipboardText()
+ */
+extern DECLSPEC int SDLCALL SDL_SetClipboardText(const char *text);
+
+/**
+ * \brief Get UTF-8 text from the clipboard, which must be freed with SDL_free()
+ *
+ * \sa SDL_SetClipboardText()
+ */
+extern DECLSPEC char * SDLCALL SDL_GetClipboardText(void);
+
+/**
+ * \brief Returns a flag indicating whether the clipboard exists and contains a text string that is non-empty
+ *
+ * \sa SDL_GetClipboardText()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasClipboardText(void);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_clipboard_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_config.h b/src/3rdparty/SDL2/include/SDL2/SDL_config.h
new file mode 100644
index 0000000..7e0340c
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_config.h
@@ -0,0 +1,53 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_h_
+#define SDL_config_h_
+
+#include "SDL_platform.h"
+
+/**
+ * \file SDL_config.h
+ */
+
+/* Add any platform that doesn't build using the configure system. */
+#if defined(__WIN32__)
+#include "SDL_config_windows.h"
+#elif defined(__WINRT__)
+#include "SDL_config_winrt.h"
+#elif defined(__MACOSX__)
+#include "SDL_config_macosx.h"
+#elif defined(__IPHONEOS__)
+#include "SDL_config_iphoneos.h"
+#elif defined(__ANDROID__)
+#include "SDL_config_android.h"
+#elif defined(__PSP__)
+#include "SDL_config_psp.h"
+#else
+/* This is a minimal configuration just to get SDL running on new platforms */
+#include "SDL_config_minimal.h"
+#endif /* platform config */
+
+#ifdef USING_GENERATED_CONFIG_H
+#error Wrong SDL_config.h, check your include path?
+#endif
+
+#endif /* SDL_config_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_config_android.h b/src/3rdparty/SDL2/include/SDL2/SDL_config_android.h
new file mode 100644
index 0000000..4c4da37
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_config_android.h
@@ -0,0 +1,171 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_android_h_
+#define SDL_config_android_h_
+#define SDL_config_h_
+
+#include "SDL_platform.h"
+
+/**
+ * \file SDL_config_android.h
+ *
+ * This is a configuration that can be used to build SDL for Android
+ */
+
+#include <stdarg.h>
+
+#define HAVE_GCC_ATOMICS 1
+
+#define STDC_HEADERS 1
+#define HAVE_ALLOCA_H 1
+#define HAVE_CTYPE_H 1
+#define HAVE_INTTYPES_H 1
+#define HAVE_LIMITS_H 1
+#define HAVE_MATH_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDINT_H 1
+#define HAVE_STDIO_H 1
+#define HAVE_STRING_H 1
+#define HAVE_SYS_TYPES_H 1
+
+/* C library functions */
+#define HAVE_MALLOC 1
+#define HAVE_CALLOC 1
+#define HAVE_REALLOC 1
+#define HAVE_FREE 1
+#define HAVE_ALLOCA 1
+#define HAVE_GETENV 1
+#define HAVE_SETENV 1
+#define HAVE_PUTENV 1
+#define HAVE_SETENV 1
+#define HAVE_UNSETENV 1
+#define HAVE_QSORT 1
+#define HAVE_ABS 1
+#define HAVE_BCOPY 1
+#define HAVE_MEMSET 1
+#define HAVE_MEMCPY 1
+#define HAVE_MEMMOVE 1
+#define HAVE_MEMCMP 1
+#define HAVE_STRLEN 1
+#define HAVE_STRLCPY 1
+#define HAVE_STRLCAT 1
+#define HAVE_STRCHR 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRSTR 1
+#define HAVE_STRTOL 1
+#define HAVE_STRTOUL 1
+#define HAVE_STRTOLL 1
+#define HAVE_STRTOULL 1
+#define HAVE_STRTOD 1
+#define HAVE_ATOI 1
+#define HAVE_ATOF 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
+#define HAVE_STRCASECMP 1
+#define HAVE_STRNCASECMP 1
+#define HAVE_VSSCANF 1
+#define HAVE_VSNPRINTF 1
+#define HAVE_ACOS 1
+#define HAVE_ACOSF 1
+#define HAVE_ASIN 1
+#define HAVE_ASINF 1
+#define HAVE_ATAN 1
+#define HAVE_ATANF 1
+#define HAVE_ATAN2 1
+#define HAVE_ATAN2F 1
+#define HAVE_CEIL 1
+#define HAVE_CEILF 1
+#define HAVE_COPYSIGN 1
+#define HAVE_COPYSIGNF 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_FABS 1
+#define HAVE_FABSF 1
+#define HAVE_FLOOR 1
+#define HAVE_FLOORF 1
+#define HAVE_FMOD 1
+#define HAVE_FMODF 1
+#define HAVE_LOG 1
+#define HAVE_LOGF 1
+#define HAVE_LOG10 1
+#define HAVE_LOG10F 1
+#define HAVE_POW 1
+#define HAVE_POWF 1
+#define HAVE_SCALBN 1
+#define HAVE_SCALBNF 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
+#define HAVE_SQRTF 1
+#define HAVE_TAN 1
+#define HAVE_TANF 1
+#define HAVE_SIGACTION 1
+#define HAVE_SETJMP 1
+#define HAVE_NANOSLEEP 1
+#define HAVE_SYSCONF 1
+#define HAVE_CLOCK_GETTIME 1
+
+#define SIZEOF_VOIDP 4
+
+/* Enable various audio drivers */
+#define SDL_AUDIO_DRIVER_ANDROID 1
+#define SDL_AUDIO_DRIVER_DUMMY 1
+
+/* Enable various input drivers */
+#define SDL_JOYSTICK_ANDROID 1
+#define SDL_HAPTIC_ANDROID 1
+
+/* Enable various shared object loading systems */
+#define SDL_LOADSO_DLOPEN 1
+
+/* Enable various threading systems */
+#define SDL_THREAD_PTHREAD 1
+#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1
+
+/* Enable various timer systems */
+#define SDL_TIMER_UNIX 1
+
+/* Enable various video drivers */
+#define SDL_VIDEO_DRIVER_ANDROID 1
+
+/* Enable OpenGL ES */
+#define SDL_VIDEO_OPENGL_ES 1
+#define SDL_VIDEO_OPENGL_ES2 1
+#define SDL_VIDEO_OPENGL_EGL 1
+#define SDL_VIDEO_RENDER_OGL_ES 1
+#define SDL_VIDEO_RENDER_OGL_ES2 1
+
+/* Enable Vulkan support */
+/* Android does not support Vulkan in native code using the "armeabi" ABI. */
+#if defined(__ARM_ARCH) && __ARM_ARCH < 7
+#define SDL_VIDEO_VULKAN 0
+#else
+#define SDL_VIDEO_VULKAN 1
+#endif
+
+/* Enable system power support */
+#define SDL_POWER_ANDROID 1
+
+/* Enable the filesystem driver */
+#define SDL_FILESYSTEM_ANDROID 1
+
+#endif /* SDL_config_android_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_config_iphoneos.h b/src/3rdparty/SDL2/include/SDL2/SDL_config_iphoneos.h
new file mode 100644
index 0000000..7b0a6ca
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_config_iphoneos.h
@@ -0,0 +1,191 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_iphoneos_h_
+#define SDL_config_iphoneos_h_
+#define SDL_config_h_
+
+#include "SDL_platform.h"
+
+#ifdef __LP64__
+#define SIZEOF_VOIDP 8
+#else
+#define SIZEOF_VOIDP 4
+#endif
+
+#define HAVE_GCC_ATOMICS 1
+
+#define STDC_HEADERS 1
+#define HAVE_ALLOCA_H 1
+#define HAVE_CTYPE_H 1
+#define HAVE_INTTYPES_H 1
+#define HAVE_LIMITS_H 1
+#define HAVE_MATH_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDINT_H 1
+#define HAVE_STDIO_H 1
+#define HAVE_STRING_H 1
+#define HAVE_SYS_TYPES_H 1
+/* The libunwind functions are only available on x86 */
+/* #undef HAVE_LIBUNWIND_H */
+
+/* C library functions */
+#define HAVE_MALLOC 1
+#define HAVE_CALLOC 1
+#define HAVE_REALLOC 1
+#define HAVE_FREE 1
+#define HAVE_ALLOCA 1
+#define HAVE_GETENV 1
+#define HAVE_SETENV 1
+#define HAVE_PUTENV 1
+#define HAVE_SETENV 1
+#define HAVE_UNSETENV 1
+#define HAVE_QSORT 1
+#define HAVE_ABS 1
+#define HAVE_BCOPY 1
+#define HAVE_MEMSET 1
+#define HAVE_MEMCPY 1
+#define HAVE_MEMMOVE 1
+#define HAVE_MEMCMP 1
+#define HAVE_STRLEN 1
+#define HAVE_STRLCPY 1
+#define HAVE_STRLCAT 1
+#define HAVE_STRCHR 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRSTR 1
+#define HAVE_STRTOL 1
+#define HAVE_STRTOUL 1
+#define HAVE_STRTOLL 1
+#define HAVE_STRTOULL 1
+#define HAVE_STRTOD 1
+#define HAVE_ATOI 1
+#define HAVE_ATOF 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
+#define HAVE_STRCASECMP 1
+#define HAVE_STRNCASECMP 1
+#define HAVE_VSSCANF 1
+#define HAVE_VSNPRINTF 1
+#define HAVE_M_PI 1
+#define HAVE_ACOS 1
+#define HAVE_ACOSF 1
+#define HAVE_ASIN 1
+#define HAVE_ASINF 1
+#define HAVE_ATAN 1
+#define HAVE_ATANF 1
+#define HAVE_ATAN2 1
+#define HAVE_ATAN2F 1
+#define HAVE_CEIL 1
+#define HAVE_CEILF 1
+#define HAVE_COPYSIGN 1
+#define HAVE_COPYSIGNF 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_FABS 1
+#define HAVE_FABSF 1
+#define HAVE_FLOOR 1
+#define HAVE_FLOORF 1
+#define HAVE_FMOD 1
+#define HAVE_FMODF 1
+#define HAVE_LOG 1
+#define HAVE_LOGF 1
+#define HAVE_LOG10 1
+#define HAVE_LOG10F 1
+#define HAVE_POW 1
+#define HAVE_POWF 1
+#define HAVE_SCALBN 1
+#define HAVE_SCALBNF 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
+#define HAVE_SQRTF 1
+#define HAVE_TAN 1
+#define HAVE_TANF 1
+#define HAVE_SIGACTION 1
+#define HAVE_SETJMP 1
+#define HAVE_NANOSLEEP 1
+#define HAVE_SYSCONF 1
+#define HAVE_SYSCTLBYNAME 1
+
+/* enable iPhone version of Core Audio driver */
+#define SDL_AUDIO_DRIVER_COREAUDIO 1
+/* Enable the dummy audio driver (src/audio/dummy/\*.c) */
+#define SDL_AUDIO_DRIVER_DUMMY 1
+
+/* Enable the stub haptic driver (src/haptic/dummy/\*.c) */
+#define SDL_HAPTIC_DUMMY 1
+
+/* Enable MFi joystick support */
+#define SDL_JOYSTICK_MFI 1
+
+/* Enable Unix style SO loading */
+#define SDL_LOADSO_DLOPEN 1
+
+/* Enable various threading systems */
+#define SDL_THREAD_PTHREAD 1
+#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1
+
+/* Enable various timer systems */
+#define SDL_TIMER_UNIX 1
+
+/* Supported video drivers */
+#define SDL_VIDEO_DRIVER_UIKIT 1
+#define SDL_VIDEO_DRIVER_DUMMY 1
+
+/* Enable OpenGL ES */
+#define SDL_VIDEO_OPENGL_ES2 1
+#define SDL_VIDEO_OPENGL_ES 1
+#define SDL_VIDEO_RENDER_OGL_ES 1
+#define SDL_VIDEO_RENDER_OGL_ES2 1
+
+/* Metal supported on 64-bit devices running iOS 8.0 and tvOS 9.0 and newer */
+#if !TARGET_OS_SIMULATOR && !TARGET_CPU_ARM && ((__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 90000))
+#define SDL_PLATFORM_SUPPORTS_METAL 1
+#else
+#define SDL_PLATFORM_SUPPORTS_METAL 0
+#endif
+
+#if SDL_PLATFORM_SUPPORTS_METAL
+#define SDL_VIDEO_RENDER_METAL 1
+#endif
+
+#if SDL_PLATFORM_SUPPORTS_METAL
+#define SDL_VIDEO_VULKAN 1
+#endif
+
+/* Enable system power support */
+#define SDL_POWER_UIKIT 1
+
+/* enable iPhone keyboard support */
+#define SDL_IPHONE_KEYBOARD 1
+
+/* enable iOS extended launch screen */
+#define SDL_IPHONE_LAUNCHSCREEN 1
+
+/* Set max recognized G-force from accelerometer
+ See src/joystick/uikit/SDL_sysjoystick.m for notes on why this is needed
+ */
+#define SDL_IPHONE_MAX_GFORCE 5.0
+
+/* enable filesystem support */
+#define SDL_FILESYSTEM_COCOA 1
+
+#endif /* SDL_config_iphoneos_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_config_macosx.h b/src/3rdparty/SDL2/include/SDL2/SDL_config_macosx.h
new file mode 100644
index 0000000..29f583e
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_config_macosx.h
@@ -0,0 +1,234 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_macosx_h_
+#define SDL_config_macosx_h_
+#define SDL_config_h_
+
+#include "SDL_platform.h"
+
+/* This gets us MAC_OS_X_VERSION_MIN_REQUIRED... */
+#include <AvailabilityMacros.h>
+
+/* This is a set of defines to configure the SDL features */
+
+#ifdef __LP64__
+ #define SIZEOF_VOIDP 8
+#else
+ #define SIZEOF_VOIDP 4
+#endif
+
+/* Useful headers */
+#define STDC_HEADERS 1
+#define HAVE_ALLOCA_H 1
+#define HAVE_CTYPE_H 1
+#define HAVE_FLOAT_H 1
+#define HAVE_INTTYPES_H 1
+#define HAVE_LIMITS_H 1
+#define HAVE_MATH_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDINT_H 1
+#define HAVE_STDIO_H 1
+#define HAVE_STRING_H 1
+#define HAVE_SYS_TYPES_H 1
+#define HAVE_LIBUNWIND_H 1
+
+/* C library functions */
+#define HAVE_MALLOC 1
+#define HAVE_CALLOC 1
+#define HAVE_REALLOC 1
+#define HAVE_FREE 1
+#define HAVE_ALLOCA 1
+#define HAVE_GETENV 1
+#define HAVE_SETENV 1
+#define HAVE_PUTENV 1
+#define HAVE_UNSETENV 1
+#define HAVE_QSORT 1
+#define HAVE_ABS 1
+#define HAVE_BCOPY 1
+#define HAVE_MEMSET 1
+#define HAVE_MEMCPY 1
+#define HAVE_MEMMOVE 1
+#define HAVE_MEMCMP 1
+#define HAVE_STRLEN 1
+#define HAVE_STRLCPY 1
+#define HAVE_STRLCAT 1
+#define HAVE_STRCHR 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRSTR 1
+#define HAVE_STRTOL 1
+#define HAVE_STRTOUL 1
+#define HAVE_STRTOLL 1
+#define HAVE_STRTOULL 1
+#define HAVE_STRTOD 1
+#define HAVE_ATOI 1
+#define HAVE_ATOF 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
+#define HAVE_STRCASECMP 1
+#define HAVE_STRNCASECMP 1
+#define HAVE_VSSCANF 1
+#define HAVE_VSNPRINTF 1
+#define HAVE_M_PI 1
+#define HAVE_ACOS 1
+#define HAVE_ACOSF 1
+#define HAVE_ASIN 1
+#define HAVE_ASINF 1
+#define HAVE_ATAN 1
+#define HAVE_ATANF 1
+#define HAVE_ATAN2 1
+#define HAVE_ATAN2F 1
+#define HAVE_CEIL 1
+#define HAVE_CEILF 1
+#define HAVE_COPYSIGN 1
+#define HAVE_COPYSIGNF 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_FABS 1
+#define HAVE_FABSF 1
+#define HAVE_FLOOR 1
+#define HAVE_FLOORF 1
+#define HAVE_FMOD 1
+#define HAVE_FMODF 1
+#define HAVE_LOG 1
+#define HAVE_LOGF 1
+#define HAVE_LOG10 1
+#define HAVE_LOG10F 1
+#define HAVE_POW 1
+#define HAVE_POWF 1
+#define HAVE_SCALBN 1
+#define HAVE_SCALBNF 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
+#define HAVE_SQRTF 1
+#define HAVE_TAN 1
+#define HAVE_TANF 1
+#define HAVE_SIGACTION 1
+#define HAVE_SETJMP 1
+#define HAVE_NANOSLEEP 1
+#define HAVE_SYSCONF 1
+#define HAVE_SYSCTLBYNAME 1
+
+/* Enable various audio drivers */
+#define SDL_AUDIO_DRIVER_COREAUDIO 1
+#define SDL_AUDIO_DRIVER_DISK 1
+#define SDL_AUDIO_DRIVER_DUMMY 1
+
+/* Enable various input drivers */
+#define SDL_JOYSTICK_IOKIT 1
+#define SDL_HAPTIC_IOKIT 1
+
+/* Enable various shared object loading systems */
+#define SDL_LOADSO_DLOPEN 1
+
+/* Enable various threading systems */
+#define SDL_THREAD_PTHREAD 1
+#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1
+
+/* Enable various timer systems */
+#define SDL_TIMER_UNIX 1
+
+/* Enable various video drivers */
+#define SDL_VIDEO_DRIVER_COCOA 1
+#define SDL_VIDEO_DRIVER_DUMMY 1
+#undef SDL_VIDEO_DRIVER_X11
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC "/usr/X11R6/lib/libX11.6.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "/usr/X11R6/lib/libXext.6.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "/usr/X11R6/lib/libXinerama.1.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "/usr/X11R6/lib/libXi.6.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "/usr/X11R6/lib/libXrandr.2.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "/usr/X11R6/lib/libXss.1.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "/usr/X11R6/lib/libXxf86vm.1.dylib"
+#define SDL_VIDEO_DRIVER_X11_XDBE 1
+#define SDL_VIDEO_DRIVER_X11_XINERAMA 1
+#define SDL_VIDEO_DRIVER_X11_XRANDR 1
+#define SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1
+#define SDL_VIDEO_DRIVER_X11_XSHAPE 1
+#define SDL_VIDEO_DRIVER_X11_XVIDMODE 1
+#define SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM 1
+
+#ifdef MAC_OS_X_VERSION_10_8
+/*
+ * No matter the versions targeted, this is the 10.8 or later SDK, so you have
+ * to use the external Xquartz, which is a more modern Xlib. Previous SDKs
+ * used an older Xlib.
+ */
+#define SDL_VIDEO_DRIVER_X11_XINPUT2 1
+#define SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1
+#define SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1
+#endif
+
+#ifndef SDL_VIDEO_RENDER_OGL
+#define SDL_VIDEO_RENDER_OGL 1
+#endif
+
+#ifndef SDL_VIDEO_RENDER_OGL_ES2
+#define SDL_VIDEO_RENDER_OGL_ES2 1
+#endif
+
+#ifndef SDL_VIDEO_RENDER_METAL
+/* Metal only supported on 64-bit architectures with 10.11+ */
+#if TARGET_CPU_X86_64 && (MAC_OS_X_VERSION_MAX_ALLOWED >= 101100)
+#define SDL_VIDEO_RENDER_METAL 1
+#else
+#define SDL_VIDEO_RENDER_METAL 0
+#endif
+#endif
+
+/* Enable OpenGL support */
+#ifndef SDL_VIDEO_OPENGL
+#define SDL_VIDEO_OPENGL 1
+#endif
+#ifndef SDL_VIDEO_OPENGL_ES2
+#define SDL_VIDEO_OPENGL_ES2 1
+#endif
+#ifndef SDL_VIDEO_OPENGL_EGL
+#define SDL_VIDEO_OPENGL_EGL 1
+#endif
+#ifndef SDL_VIDEO_OPENGL_CGL
+#define SDL_VIDEO_OPENGL_CGL 1
+#endif
+#ifndef SDL_VIDEO_OPENGL_GLX
+#define SDL_VIDEO_OPENGL_GLX 1
+#endif
+
+/* Enable Vulkan support */
+/* Metal/MoltenVK/Vulkan only supported on 64-bit architectures with 10.11+ */
+#if TARGET_CPU_X86_64 && (MAC_OS_X_VERSION_MAX_ALLOWED >= 101100)
+#define SDL_VIDEO_VULKAN 1
+#else
+#define SDL_VIDEO_VULKAN 0
+#endif
+
+/* Enable system power support */
+#define SDL_POWER_MACOSX 1
+
+/* enable filesystem support */
+#define SDL_FILESYSTEM_COCOA 1
+
+/* Enable assembly routines */
+#define SDL_ASSEMBLY_ROUTINES 1
+#ifdef __ppc__
+#define SDL_ALTIVEC_BLITTERS 1
+#endif
+
+#endif /* SDL_config_macosx_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_config_minimal.h b/src/3rdparty/SDL2/include/SDL2/SDL_config_minimal.h
new file mode 100644
index 0000000..5b03d8b
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_config_minimal.h
@@ -0,0 +1,82 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_minimal_h_
+#define SDL_config_minimal_h_
+#define SDL_config_h_
+
+#include "SDL_platform.h"
+
+/**
+ * \file SDL_config_minimal.h
+ *
+ * This is the minimal configuration that can be used to build SDL.
+ */
+
+#define HAVE_STDARG_H 1
+#define HAVE_STDDEF_H 1
+
+/* Most everything except Visual Studio 2008 and earlier has stdint.h now */
+#if defined(_MSC_VER) && (_MSC_VER < 1600)
+/* Here are some reasonable defaults */
+typedef unsigned int size_t;
+typedef signed char int8_t;
+typedef unsigned char uint8_t;
+typedef signed short int16_t;
+typedef unsigned short uint16_t;
+typedef signed int int32_t;
+typedef unsigned int uint32_t;
+typedef signed long long int64_t;
+typedef unsigned long long uint64_t;
+typedef unsigned long uintptr_t;
+#else
+#define HAVE_STDINT_H 1
+#endif /* Visual Studio 2008 */
+
+#ifdef __GNUC__
+#define HAVE_GCC_SYNC_LOCK_TEST_AND_SET 1
+#endif
+
+/* Enable the dummy audio driver (src/audio/dummy/\*.c) */
+#define SDL_AUDIO_DRIVER_DUMMY 1
+
+/* Enable the stub joystick driver (src/joystick/dummy/\*.c) */
+#define SDL_JOYSTICK_DISABLED 1
+
+/* Enable the stub haptic driver (src/haptic/dummy/\*.c) */
+#define SDL_HAPTIC_DISABLED 1
+
+/* Enable the stub shared object loader (src/loadso/dummy/\*.c) */
+#define SDL_LOADSO_DISABLED 1
+
+/* Enable the stub thread support (src/thread/generic/\*.c) */
+#define SDL_THREADS_DISABLED 1
+
+/* Enable the stub timer support (src/timer/dummy/\*.c) */
+#define SDL_TIMERS_DISABLED 1
+
+/* Enable the dummy video driver (src/video/dummy/\*.c) */
+#define SDL_VIDEO_DRIVER_DUMMY 1
+
+/* Enable the dummy filesystem driver (src/filesystem/dummy/\*.c) */
+#define SDL_FILESYSTEM_DUMMY 1
+
+#endif /* SDL_config_minimal_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_config_pandora.h b/src/3rdparty/SDL2/include/SDL2/SDL_config_pandora.h
new file mode 100644
index 0000000..be5a85c
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_config_pandora.h
@@ -0,0 +1,130 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_pandora_h_
+#define SDL_config_pandora_h_
+#define SDL_config_h_
+
+/* This is a set of defines to configure the SDL features */
+
+/* General platform specific identifiers */
+#include "SDL_platform.h"
+
+#ifdef __LP64__
+#define SIZEOF_VOIDP 8
+#else
+#define SIZEOF_VOIDP 4
+#endif
+
+#define SDL_BYTEORDER 1234
+
+#define STDC_HEADERS 1
+#define HAVE_ALLOCA_H 1
+#define HAVE_CTYPE_H 1
+#define HAVE_ICONV_H 1
+#define HAVE_INTTYPES_H 1
+#define HAVE_LIMITS_H 1
+#define HAVE_MALLOC_H 1
+#define HAVE_MATH_H 1
+#define HAVE_MEMORY_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDARG_H 1
+#define HAVE_STDINT_H 1
+#define HAVE_STDIO_H 1
+#define HAVE_STDLIB_H 1
+#define HAVE_STRINGS_H 1
+#define HAVE_STRING_H 1
+#define HAVE_SYS_TYPES_H 1
+
+#define HAVE_MALLOC 1
+#define HAVE_CALLOC 1
+#define HAVE_REALLOC 1
+#define HAVE_FREE 1
+#define HAVE_ALLOCA 1
+#define HAVE_GETENV 1
+#define HAVE_SETENV 1
+#define HAVE_PUTENV 1
+#define HAVE_UNSETENV 1
+#define HAVE_QSORT 1
+#define HAVE_ABS 1
+#define HAVE_BCOPY 1
+#define HAVE_MEMSET 1
+#define HAVE_MEMCPY 1
+#define HAVE_MEMMOVE 1
+#define HAVE_STRLEN 1
+#define HAVE_STRCHR 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRSTR 1
+#define HAVE_STRTOL 1
+#define HAVE_STRTOUL 1
+#define HAVE_STRTOLL 1
+#define HAVE_STRTOULL 1
+#define HAVE_ATOI 1
+#define HAVE_ATOF 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
+#define HAVE_STRCASECMP 1
+#define HAVE_STRNCASECMP 1
+#define HAVE_VSSCANF 1
+#define HAVE_VSNPRINTF 1
+#define HAVE_M_PI 1
+#define HAVE_CEIL 1
+#define HAVE_COPYSIGN 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_FABS 1
+#define HAVE_FLOOR 1
+#define HAVE_LOG 1
+#define HAVE_LOG10 1
+#define HAVE_SCALBN 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
+#define HAVE_SQRTF 1
+#define HAVE_TAN 1
+#define HAVE_TANF 1
+#define HAVE_SIGACTION 1
+#define HAVE_SETJMP 1
+#define HAVE_NANOSLEEP 1
+
+#define SDL_AUDIO_DRIVER_DUMMY 1
+#define SDL_AUDIO_DRIVER_OSS 1
+
+#define SDL_INPUT_LINUXEV 1
+#define SDL_INPUT_TSLIB 1
+#define SDL_JOYSTICK_LINUX 1
+#define SDL_HAPTIC_LINUX 1
+
+#define SDL_LOADSO_DLOPEN 1
+
+#define SDL_THREAD_PTHREAD 1
+#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1
+
+#define SDL_TIMER_UNIX 1
+#define SDL_FILESYSTEM_UNIX 1
+
+#define SDL_VIDEO_DRIVER_DUMMY 1
+#define SDL_VIDEO_DRIVER_X11 1
+#define SDL_VIDEO_DRIVER_PANDORA 1
+#define SDL_VIDEO_RENDER_OGL_ES 1
+#define SDL_VIDEO_OPENGL_ES 1
+
+#endif /* SDL_config_pandora_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_config_psp.h b/src/3rdparty/SDL2/include/SDL2/SDL_config_psp.h
new file mode 100644
index 0000000..61c3349
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_config_psp.h
@@ -0,0 +1,159 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_psp_h_
+#define SDL_config_psp_h_
+#define SDL_config_h_
+
+#include "SDL_platform.h"
+
+
+
+#ifdef __GNUC__
+#define HAVE_GCC_SYNC_LOCK_TEST_AND_SET 1
+#endif
+
+#define HAVE_GCC_ATOMICS 1
+
+#define STDC_HEADERS 1
+#define HAVE_ALLOCA_H 1
+#define HAVE_CTYPE_H 1
+#define HAVE_INTTYPES_H 1
+#define HAVE_LIMITS_H 1
+#define HAVE_MATH_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDINT_H 1
+#define HAVE_STDIO_H 1
+#define HAVE_STRING_H 1
+#define HAVE_SYS_TYPES_H 1
+
+/* C library functions */
+#define HAVE_MALLOC 1
+#define HAVE_CALLOC 1
+#define HAVE_REALLOC 1
+#define HAVE_FREE 1
+#define HAVE_ALLOCA 1
+#define HAVE_GETENV 1
+#define HAVE_SETENV 1
+#define HAVE_PUTENV 1
+#define HAVE_SETENV 1
+#define HAVE_UNSETENV 1
+#define HAVE_QSORT 1
+#define HAVE_ABS 1
+#define HAVE_BCOPY 1
+#define HAVE_MEMSET 1
+#define HAVE_MEMCPY 1
+#define HAVE_MEMMOVE 1
+#define HAVE_MEMCMP 1
+#define HAVE_STRLEN 1
+#define HAVE_STRLCPY 1
+#define HAVE_STRLCAT 1
+#define HAVE_STRCHR 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRSTR 1
+#define HAVE_STRTOL 1
+#define HAVE_STRTOUL 1
+#define HAVE_STRTOLL 1
+#define HAVE_STRTOULL 1
+#define HAVE_STRTOD 1
+#define HAVE_ATOI 1
+#define HAVE_ATOF 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
+#define HAVE_STRCASECMP 1
+#define HAVE_STRNCASECMP 1
+#define HAVE_VSSCANF 1
+#define HAVE_VSNPRINTF 1
+#define HAVE_M_PI 1
+#define HAVE_ACOS 1
+#define HAVE_ACOSF 1
+#define HAVE_ASIN 1
+#define HAVE_ASINF 1
+#define HAVE_ATAN 1
+#define HAVE_ATANF 1
+#define HAVE_ATAN2 1
+#define HAVE_ATAN2F 1
+#define HAVE_CEIL 1
+#define HAVE_CEILF 1
+#define HAVE_COPYSIGN 1
+#define HAVE_COPYSIGNF 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_FABS 1
+#define HAVE_FABSF 1
+#define HAVE_FLOOR 1
+#define HAVE_FLOORF 1
+#define HAVE_FMOD 1
+#define HAVE_FMODF 1
+#define HAVE_LOG 1
+#define HAVE_LOGF 1
+#define HAVE_LOG10 1
+#define HAVE_LOG10F 1
+#define HAVE_POW 1
+#define HAVE_POWF 1
+#define HAVE_SCALBN 1
+#define HAVE_SCALBNF 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
+#define HAVE_SQRTF 1
+#define HAVE_TAN 1
+#define HAVE_TANF 1
+#define HAVE_SETJMP 1
+#define HAVE_NANOSLEEP 1
+/* #define HAVE_SYSCONF 1 */
+/* #define HAVE_SIGACTION 1 */
+
+
+/* PSP isn't that sophisticated */
+#define LACKS_SYS_MMAN_H 1
+
+/* Enable the stub thread support (src/thread/psp/\*.c) */
+#define SDL_THREAD_PSP 1
+
+/* Enable the stub timer support (src/timer/psp/\*.c) */
+#define SDL_TIMERS_PSP 1
+
+/* Enable the stub joystick driver (src/joystick/psp/\*.c) */
+#define SDL_JOYSTICK_PSP 1
+
+/* Enable the stub audio driver (src/audio/psp/\*.c) */
+#define SDL_AUDIO_DRIVER_PSP 1
+
+/* PSP video dirver */
+#define SDL_VIDEO_DRIVER_PSP 1
+
+/* PSP render dirver */
+#define SDL_VIDEO_RENDER_PSP 1
+
+#define SDL_POWER_PSP 1
+
+/* !!! FIXME: what does PSP do for filesystem stuff? */
+#define SDL_FILESYSTEM_DUMMY 1
+
+/* PSP doesn't have haptic device (src/haptic/dummy/\*.c) */
+#define SDL_HAPTIC_DISABLED 1
+
+/* PSP can't load shared object (src/loadso/dummy/\*.c) */
+#define SDL_LOADSO_DISABLED 1
+
+
+#endif /* SDL_config_psp_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_config_windows.h b/src/3rdparty/SDL2/include/SDL2/SDL_config_windows.h
new file mode 100644
index 0000000..52a9ece
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_config_windows.h
@@ -0,0 +1,248 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_windows_h_
+#define SDL_config_windows_h_
+#define SDL_config_h_
+
+#include "SDL_platform.h"
+
+/* This is a set of defines to configure the SDL features */
+
+#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H)
+#if defined(__GNUC__) || defined(__DMC__) || defined(__WATCOMC__)
+#define HAVE_STDINT_H 1
+#elif defined(_MSC_VER)
+typedef signed __int8 int8_t;
+typedef unsigned __int8 uint8_t;
+typedef signed __int16 int16_t;
+typedef unsigned __int16 uint16_t;
+typedef signed __int32 int32_t;
+typedef unsigned __int32 uint32_t;
+typedef signed __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+#ifndef _UINTPTR_T_DEFINED
+#ifdef _WIN64
+typedef unsigned __int64 uintptr_t;
+#else
+typedef unsigned int uintptr_t;
+#endif
+#define _UINTPTR_T_DEFINED
+#endif
+/* Older Visual C++ headers don't have the Win64-compatible typedefs... */
+#if ((_MSC_VER <= 1200) && (!defined(DWORD_PTR)))
+#define DWORD_PTR DWORD
+#endif
+#if ((_MSC_VER <= 1200) && (!defined(LONG_PTR)))
+#define LONG_PTR LONG
+#endif
+#else /* !__GNUC__ && !_MSC_VER */
+typedef signed char int8_t;
+typedef unsigned char uint8_t;
+typedef signed short int16_t;
+typedef unsigned short uint16_t;
+typedef signed int int32_t;
+typedef unsigned int uint32_t;
+typedef signed long long int64_t;
+typedef unsigned long long uint64_t;
+#ifndef _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED_
+typedef unsigned int size_t;
+#endif
+typedef unsigned int uintptr_t;
+#endif /* __GNUC__ || _MSC_VER */
+#endif /* !_STDINT_H_ && !HAVE_STDINT_H */
+
+#ifdef _WIN64
+# define SIZEOF_VOIDP 8
+#else
+# define SIZEOF_VOIDP 4
+#endif
+
+#define HAVE_DDRAW_H 1
+#define HAVE_DINPUT_H 1
+#define HAVE_DSOUND_H 1
+#define HAVE_DXGI_H 1
+#define HAVE_XINPUT_H 1
+
+/* This is disabled by default to avoid C runtime dependencies and manifest requirements */
+#ifdef HAVE_LIBC
+/* Useful headers */
+#define STDC_HEADERS 1
+#define HAVE_CTYPE_H 1
+#define HAVE_FLOAT_H 1
+#define HAVE_LIMITS_H 1
+#define HAVE_MATH_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDIO_H 1
+#define HAVE_STRING_H 1
+
+/* C library functions */
+#define HAVE_MALLOC 1
+#define HAVE_CALLOC 1
+#define HAVE_REALLOC 1
+#define HAVE_FREE 1
+#define HAVE_ALLOCA 1
+#define HAVE_QSORT 1
+#define HAVE_ABS 1
+#define HAVE_MEMSET 1
+#define HAVE_MEMCPY 1
+#define HAVE_MEMMOVE 1
+#define HAVE_MEMCMP 1
+#define HAVE_STRLEN 1
+#define HAVE__STRREV 1
+/* These functions have security warnings, so we won't use them */
+/* #undef HAVE__STRUPR */
+/* #undef HAVE__STRLWR */
+#define HAVE_STRCHR 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRSTR 1
+/* These functions have security warnings, so we won't use them */
+/* #undef HAVE__LTOA */
+/* #undef HAVE__ULTOA */
+#define HAVE_STRTOL 1
+#define HAVE_STRTOUL 1
+#define HAVE_STRTOD 1
+#define HAVE_ATOI 1
+#define HAVE_ATOF 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
+#define HAVE__STRICMP 1
+#define HAVE__STRNICMP 1
+#define HAVE_ACOS 1
+#define HAVE_ACOSF 1
+#define HAVE_ASIN 1
+#define HAVE_ASINF 1
+#define HAVE_ATAN 1
+#define HAVE_ATANF 1
+#define HAVE_ATAN2 1
+#define HAVE_ATAN2F 1
+#define HAVE_CEILF 1
+#define HAVE__COPYSIGN 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_FABS 1
+#define HAVE_FABSF 1
+#define HAVE_FLOOR 1
+#define HAVE_FLOORF 1
+#define HAVE_FMOD 1
+#define HAVE_FMODF 1
+#define HAVE_LOG 1
+#define HAVE_LOGF 1
+#define HAVE_LOG10 1
+#define HAVE_LOG10F 1
+#define HAVE_POW 1
+#define HAVE_POWF 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
+#define HAVE_SQRTF 1
+#define HAVE_TAN 1
+#define HAVE_TANF 1
+#if defined(_MSC_VER)
+/* These functions were added with the VC++ 2013 C runtime library */
+#if _MSC_VER >= 1800
+#define HAVE_STRTOLL 1
+#define HAVE_VSSCANF 1
+#define HAVE_SCALBN 1
+#define HAVE_SCALBNF 1
+#endif
+/* This function is available with at least the VC++ 2008 C runtime library */
+#if _MSC_VER >= 1400
+#define HAVE__FSEEKI64 1
+#endif
+#endif
+#if !defined(_MSC_VER) || defined(_USE_MATH_DEFINES)
+#define HAVE_M_PI 1
+#endif
+#else
+#define HAVE_STDARG_H 1
+#define HAVE_STDDEF_H 1
+#endif
+
+/* Enable various audio drivers */
+#define SDL_AUDIO_DRIVER_WASAPI 1
+#define SDL_AUDIO_DRIVER_DSOUND 1
+#define SDL_AUDIO_DRIVER_WINMM 1
+#define SDL_AUDIO_DRIVER_DISK 1
+#define SDL_AUDIO_DRIVER_DUMMY 1
+
+/* Enable various input drivers */
+#define SDL_JOYSTICK_DINPUT 1
+#define SDL_JOYSTICK_XINPUT 1
+#define SDL_HAPTIC_DINPUT 1
+#define SDL_HAPTIC_XINPUT 1
+
+/* Enable various shared object loading systems */
+#define SDL_LOADSO_WINDOWS 1
+
+/* Enable various threading systems */
+#define SDL_THREAD_WINDOWS 1
+
+/* Enable various timer systems */
+#define SDL_TIMER_WINDOWS 1
+
+/* Enable various video drivers */
+#define SDL_VIDEO_DRIVER_DUMMY 1
+#define SDL_VIDEO_DRIVER_WINDOWS 1
+
+#ifndef SDL_VIDEO_RENDER_D3D
+#define SDL_VIDEO_RENDER_D3D 1
+#endif
+#ifndef SDL_VIDEO_RENDER_D3D11
+#define SDL_VIDEO_RENDER_D3D11 0
+#endif
+
+/* Enable OpenGL support */
+#ifndef SDL_VIDEO_OPENGL
+#define SDL_VIDEO_OPENGL 1
+#endif
+#ifndef SDL_VIDEO_OPENGL_WGL
+#define SDL_VIDEO_OPENGL_WGL 1
+#endif
+#ifndef SDL_VIDEO_RENDER_OGL
+#define SDL_VIDEO_RENDER_OGL 1
+#endif
+#ifndef SDL_VIDEO_RENDER_OGL_ES2
+#define SDL_VIDEO_RENDER_OGL_ES2 1
+#endif
+#ifndef SDL_VIDEO_OPENGL_ES2
+#define SDL_VIDEO_OPENGL_ES2 1
+#endif
+#ifndef SDL_VIDEO_OPENGL_EGL
+#define SDL_VIDEO_OPENGL_EGL 1
+#endif
+
+/* Enable Vulkan support */
+#define SDL_VIDEO_VULKAN 1
+
+/* Enable system power support */
+#define SDL_POWER_WINDOWS 1
+
+/* Enable filesystem support */
+#define SDL_FILESYSTEM_WINDOWS 1
+
+/* Enable assembly routines (Win64 doesn't have inline asm) */
+#ifndef _WIN64
+#define SDL_ASSEMBLY_ROUTINES 1
+#endif
+
+#endif /* SDL_config_windows_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_config_winrt.h b/src/3rdparty/SDL2/include/SDL2/SDL_config_winrt.h
new file mode 100644
index 0000000..aac0e60
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_config_winrt.h
@@ -0,0 +1,230 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_winrt_h_
+#define SDL_config_winrt_h_
+#define SDL_config_h_
+
+#include "SDL_platform.h"
+
+/* Make sure the Windows SDK's NTDDI_VERSION macro gets defined. This is used
+ by SDL to determine which version of the Windows SDK is being used.
+*/
+#include <sdkddkver.h>
+
+/* Define possibly-undefined NTDDI values (used when compiling SDL against
+ older versions of the Windows SDK.
+*/
+#ifndef NTDDI_WINBLUE
+#define NTDDI_WINBLUE 0x06030000
+#endif
+#ifndef NTDDI_WIN10
+#define NTDDI_WIN10 0x0A000000
+#endif
+
+/* This is a set of defines to configure the SDL features */
+
+#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H)
+#if defined(__GNUC__) || defined(__DMC__) || defined(__WATCOMC__)
+#define HAVE_STDINT_H 1
+#elif defined(_MSC_VER)
+typedef signed __int8 int8_t;
+typedef unsigned __int8 uint8_t;
+typedef signed __int16 int16_t;
+typedef unsigned __int16 uint16_t;
+typedef signed __int32 int32_t;
+typedef unsigned __int32 uint32_t;
+typedef signed __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+#ifndef _UINTPTR_T_DEFINED
+#ifdef _WIN64
+typedef unsigned __int64 uintptr_t;
+#else
+typedef unsigned int uintptr_t;
+#endif
+#define _UINTPTR_T_DEFINED
+#endif
+/* Older Visual C++ headers don't have the Win64-compatible typedefs... */
+#if ((_MSC_VER <= 1200) && (!defined(DWORD_PTR)))
+#define DWORD_PTR DWORD
+#endif
+#if ((_MSC_VER <= 1200) && (!defined(LONG_PTR)))
+#define LONG_PTR LONG
+#endif
+#else /* !__GNUC__ && !_MSC_VER */
+typedef signed char int8_t;
+typedef unsigned char uint8_t;
+typedef signed short int16_t;
+typedef unsigned short uint16_t;
+typedef signed int int32_t;
+typedef unsigned int uint32_t;
+typedef signed long long int64_t;
+typedef unsigned long long uint64_t;
+#ifndef _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED_
+typedef unsigned int size_t;
+#endif
+typedef unsigned int uintptr_t;
+#endif /* __GNUC__ || _MSC_VER */
+#endif /* !_STDINT_H_ && !HAVE_STDINT_H */
+
+#ifdef _WIN64
+# define SIZEOF_VOIDP 8
+#else
+# define SIZEOF_VOIDP 4
+#endif
+
+/* Useful headers */
+#define HAVE_DXGI_H 1
+#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
+#define HAVE_XINPUT_H 1
+#endif
+#define HAVE_LIBC 1
+#define STDC_HEADERS 1
+#define HAVE_CTYPE_H 1
+#define HAVE_FLOAT_H 1
+#define HAVE_LIMITS_H 1
+#define HAVE_MATH_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDIO_H 1
+#define HAVE_STRING_H 1
+
+/* C library functions */
+#define HAVE_MALLOC 1
+#define HAVE_CALLOC 1
+#define HAVE_REALLOC 1
+#define HAVE_FREE 1
+#define HAVE_ALLOCA 1
+#define HAVE_QSORT 1
+#define HAVE_ABS 1
+#define HAVE_MEMSET 1
+#define HAVE_MEMCPY 1
+#define HAVE_MEMMOVE 1
+#define HAVE_MEMCMP 1
+#define HAVE_STRLEN 1
+#define HAVE__STRREV 1
+#define HAVE__STRUPR 1
+//#define HAVE__STRLWR 1 // TODO, WinRT: consider using _strlwr_s instead
+#define HAVE_STRCHR 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRSTR 1
+//#define HAVE_ITOA 1 // TODO, WinRT: consider using _itoa_s instead
+//#define HAVE__LTOA 1 // TODO, WinRT: consider using _ltoa_s instead
+//#define HAVE__ULTOA 1 // TODO, WinRT: consider using _ultoa_s instead
+#define HAVE_STRTOL 1
+#define HAVE_STRTOUL 1
+//#define HAVE_STRTOLL 1
+#define HAVE_STRTOD 1
+#define HAVE_ATOI 1
+#define HAVE_ATOF 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
+#define HAVE__STRICMP 1
+#define HAVE__STRNICMP 1
+#define HAVE_VSNPRINTF 1
+//#define HAVE_SSCANF 1 // TODO, WinRT: consider using sscanf_s instead
+#define HAVE_M_PI 1
+#define HAVE_ACOS 1
+#define HAVE_ACOSF 1
+#define HAVE_ASIN 1
+#define HAVE_ASINF 1
+#define HAVE_ATAN 1
+#define HAVE_ATANF 1
+#define HAVE_ATAN2 1
+#define HAVE_ATAN2F 1
+#define HAVE_CEIL 1
+#define HAVE_CEILF 1
+#define HAVE__COPYSIGN 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_FABS 1
+#define HAVE_FABSF 1
+#define HAVE_FLOOR 1
+#define HAVE_FLOORF 1
+#define HAVE_FMOD 1
+#define HAVE_FMODF 1
+#define HAVE_LOG 1
+#define HAVE_LOGF 1
+#define HAVE_LOG10 1
+#define HAVE_LOG10F 1
+#define HAVE_POW 1
+#define HAVE_POWF 1
+#define HAVE__SCALB 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
+#define HAVE_SQRTF 1
+#define HAVE_TAN 1
+#define HAVE_TANF 1
+#define HAVE__FSEEKI64 1
+
+/* Enable various audio drivers */
+#define SDL_AUDIO_DRIVER_WASAPI 1
+#define SDL_AUDIO_DRIVER_DISK 1
+#define SDL_AUDIO_DRIVER_DUMMY 1
+
+/* Enable various input drivers */
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+#define SDL_JOYSTICK_DISABLED 1
+#define SDL_HAPTIC_DISABLED 1
+#else
+#define SDL_JOYSTICK_XINPUT 1
+#define SDL_HAPTIC_XINPUT 1
+#endif
+
+/* Enable various shared object loading systems */
+#define SDL_LOADSO_WINDOWS 1
+
+/* Enable various threading systems */
+#if (NTDDI_VERSION >= NTDDI_WINBLUE)
+#define SDL_THREAD_WINDOWS 1
+#else
+/* WinRT on Windows 8.0 and Windows Phone 8.0 don't support CreateThread() */
+#define SDL_THREAD_STDCPP 1
+#endif
+
+/* Enable various timer systems */
+#define SDL_TIMER_WINDOWS 1
+
+/* Enable various video drivers */
+#define SDL_VIDEO_DRIVER_WINRT 1
+#define SDL_VIDEO_DRIVER_DUMMY 1
+
+/* Enable OpenGL ES 2.0 (via a modified ANGLE library) */
+#define SDL_VIDEO_OPENGL_ES2 1
+#define SDL_VIDEO_OPENGL_EGL 1
+
+/* Enable appropriate renderer(s) */
+#define SDL_VIDEO_RENDER_D3D11 1
+
+#if SDL_VIDEO_OPENGL_ES2
+#define SDL_VIDEO_RENDER_OGL_ES2 1
+#endif
+
+/* Enable system power support */
+#define SDL_POWER_WINRT 1
+
+/* Enable assembly routines (Win64 doesn't have inline asm) */
+#ifndef _WIN64
+#define SDL_ASSEMBLY_ROUTINES 1
+#endif
+
+#endif /* SDL_config_winrt_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_config_wiz.h b/src/3rdparty/SDL2/include/SDL2/SDL_config_wiz.h
new file mode 100644
index 0000000..fe86d5e
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_config_wiz.h
@@ -0,0 +1,142 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_wiz_h_
+#define SDL_config_wiz_h_
+#define SDL_config_h_
+
+/* This is a set of defines to configure the SDL features */
+
+/* General platform specific identifiers */
+#include "SDL_platform.h"
+
+#define SDL_BYTEORDER 1234
+
+#define STDC_HEADERS 1
+#define HAVE_ALLOCA_H 1
+#define HAVE_CTYPE_H 1
+#define HAVE_ICONV_H 1
+#define HAVE_INTTYPES_H 1
+#define HAVE_LIMITS_H 1
+#define HAVE_MALLOC_H 1
+#define HAVE_MATH_H 1
+#define HAVE_MEMORY_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDARG_H 1
+#define HAVE_STDINT_H 1
+#define HAVE_STDIO_H 1
+#define HAVE_STDLIB_H 1
+#define HAVE_STRINGS_H 1
+#define HAVE_STRING_H 1
+#define HAVE_SYS_TYPES_H 1
+
+#define HAVE_MALLOC 1
+#define HAVE_CALLOC 1
+#define HAVE_REALLOC 1
+#define HAVE_FREE 1
+#define HAVE_ALLOCA 1
+#define HAVE_GETENV 1
+#define HAVE_SETENV 1
+#define HAVE_PUTENV 1
+#define HAVE_UNSETENV 1
+#define HAVE_QSORT 1
+#define HAVE_ABS 1
+#define HAVE_BCOPY 1
+#define HAVE_MEMSET 1
+#define HAVE_MEMCPY 1
+#define HAVE_MEMMOVE 1
+#define HAVE_STRLEN 1
+#define HAVE_STRCHR 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRSTR 1
+#define HAVE_STRTOL 1
+#define HAVE_STRTOUL 1
+#define HAVE_STRTOLL 1
+#define HAVE_STRTOULL 1
+#define HAVE_ATOI 1
+#define HAVE_ATOF 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
+#define HAVE_STRCASECMP 1
+#define HAVE_STRNCASECMP 1
+#define HAVE_VSSCANF 1
+#define HAVE_VSNPRINTF 1
+#define HAVE_M_PI 1
+#define HAVE_ACOS 1
+#define HAVE_ACOSF 1
+#define HAVE_ASIN 1
+#define HAVE_ASINF 1
+#define HAVE_ATAN 1
+#define HAVE_ATANF 1
+#define HAVE_ATAN2 1
+#define HAVE_ATAN2F 1
+#define HAVE_CEIL 1
+#define HAVE_CEILF 1
+#define HAVE_COPYSIGN 1
+#define HAVE_COPYSIGNF 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_FABS 1
+#define HAVE_FABSF 1
+#define HAVE_FLOOR 1
+#define HAVE_FLOORF 1
+#define HAVE_FMOD 1
+#define HAVE_FMODF 1
+#define HAVE_LOG 1
+#define HAVE_LOGF 1
+#define HAVE_LOG10 1
+#define HAVE_LOG10F 1
+#define HAVE_POW 1
+#define HAVE_POWF 1
+#define HAVE_SCALBN 1
+#define HAVE_SCALBNF 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
+#define HAVE_SQRTF 1
+#define HAVE_TAN 1
+#define HAVE_TANF 1
+#define HAVE_SIGACTION 1
+#define HAVE_SETJMP 1
+#define HAVE_NANOSLEEP 1
+#define HAVE_POW 1
+
+#define SDL_AUDIO_DRIVER_DUMMY 1
+#define SDL_AUDIO_DRIVER_OSS 1
+
+#define SDL_INPUT_LINUXEV 1
+#define SDL_INPUT_TSLIB 1
+#define SDL_JOYSTICK_LINUX 1
+#define SDL_HAPTIC_LINUX 1
+
+#define SDL_LOADSO_DLOPEN 1
+
+#define SDL_THREAD_PTHREAD 1
+#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1
+
+#define SDL_TIMER_UNIX 1
+
+#define SDL_VIDEO_DRIVER_DUMMY 1
+#define SDL_VIDEO_DRIVER_PANDORA 1
+#define SDL_VIDEO_RENDER_OGL_ES 1
+#define SDL_VIDEO_OPENGL_ES 1
+
+#endif /* SDL_config_wiz_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_copying.h b/src/3rdparty/SDL2/include/SDL2/SDL_copying.h
new file mode 100644
index 0000000..15616ac
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_copying.h
@@ -0,0 +1,20 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_cpuinfo.h b/src/3rdparty/SDL2/include/SDL2/SDL_cpuinfo.h
new file mode 100644
index 0000000..0812705
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_cpuinfo.h
@@ -0,0 +1,181 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_cpuinfo.h
+ *
+ * CPU feature detection for SDL.
+ */
+
+#ifndef SDL_cpuinfo_h_
+#define SDL_cpuinfo_h_
+
+#include "SDL_stdinc.h"
+
+/* Need to do this here because intrin.h has C++ code in it */
+/* Visual Studio 2005 has a bug where intrin.h conflicts with winnt.h */
+#if defined(_MSC_VER) && (_MSC_VER >= 1500) && (defined(_M_IX86) || defined(_M_X64))
+#ifdef __clang__
+/* Many of the intrinsics SDL uses are not implemented by clang with Visual Studio */
+#undef __MMX__
+#undef __SSE__
+#undef __SSE2__
+#else
+#include <intrin.h>
+#ifndef _WIN64
+#define __MMX__
+#define __3dNOW__
+#endif
+#define __SSE__
+#define __SSE2__
+#endif /* __clang__ */
+#elif defined(__MINGW64_VERSION_MAJOR)
+#include <intrin.h>
+#else
+#ifdef __ALTIVEC__
+#if HAVE_ALTIVEC_H && !defined(__APPLE_ALTIVEC__) && !defined(SDL_DISABLE_ALTIVEC_H)
+#include <altivec.h>
+#undef pixel
+#undef bool
+#endif
+#endif
+#if defined(__3dNOW__) && !defined(SDL_DISABLE_MM3DNOW_H)
+#include <mm3dnow.h>
+#endif
+#if HAVE_IMMINTRIN_H && !defined(SDL_DISABLE_IMMINTRIN_H)
+#include <immintrin.h>
+#else
+#if defined(__MMX__) && !defined(SDL_DISABLE_MMINTRIN_H)
+#include <mmintrin.h>
+#endif
+#if defined(__SSE__) && !defined(SDL_DISABLE_XMMINTRIN_H)
+#include <xmmintrin.h>
+#endif
+#if defined(__SSE2__) && !defined(SDL_DISABLE_EMMINTRIN_H)
+#include <emmintrin.h>
+#endif
+#if defined(__SSE3__) && !defined(SDL_DISABLE_PMMINTRIN_H)
+#include <pmmintrin.h>
+#endif
+#endif /* HAVE_IMMINTRIN_H */
+#endif /* compiler version */
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* This is a guess for the cacheline size used for padding.
+ * Most x86 processors have a 64 byte cache line.
+ * The 64-bit PowerPC processors have a 128 byte cache line.
+ * We'll use the larger value to be generally safe.
+ */
+#define SDL_CACHELINE_SIZE 128
+
+/**
+ * This function returns the number of CPU cores available.
+ */
+extern DECLSPEC int SDLCALL SDL_GetCPUCount(void);
+
+/**
+ * This function returns the L1 cache line size of the CPU
+ *
+ * This is useful for determining multi-threaded structure padding
+ * or SIMD prefetch sizes.
+ */
+extern DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void);
+
+/**
+ * This function returns true if the CPU has the RDTSC instruction.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void);
+
+/**
+ * This function returns true if the CPU has AltiVec features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void);
+
+/**
+ * This function returns true if the CPU has MMX features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void);
+
+/**
+ * This function returns true if the CPU has 3DNow! features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void);
+
+/**
+ * This function returns true if the CPU has SSE features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void);
+
+/**
+ * This function returns true if the CPU has SSE2 features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void);
+
+/**
+ * This function returns true if the CPU has SSE3 features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void);
+
+/**
+ * This function returns true if the CPU has SSE4.1 features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void);
+
+/**
+ * This function returns true if the CPU has SSE4.2 features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void);
+
+/**
+ * This function returns true if the CPU has AVX features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX(void);
+
+/**
+ * This function returns true if the CPU has AVX2 features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX2(void);
+
+/**
+ * This function returns true if the CPU has NEON (ARM SIMD) features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasNEON(void);
+
+/**
+ * This function returns the amount of RAM configured in the system, in MB.
+ */
+extern DECLSPEC int SDLCALL SDL_GetSystemRAM(void);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_cpuinfo_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_egl.h b/src/3rdparty/SDL2/include/SDL2/SDL_egl.h
new file mode 100644
index 0000000..d65ed43
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_egl.h
@@ -0,0 +1,1673 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_egl.h
+ *
+ * This is a simple file to encapsulate the EGL API headers.
+ */
+#if !defined(_MSC_VER) && !defined(__ANDROID__)
+
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+#else /* _MSC_VER */
+
+/* EGL headers for Visual Studio */
+
+#ifndef __khrplatform_h_
+#define __khrplatform_h_
+
+/*
+** Copyright (c) 2008-2009 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+
+/* Khronos platform-specific types and definitions.
+*
+* $Revision: 23298 $ on $Date: 2013-09-30 17:07:13 -0700 (Mon, 30 Sep 2013) $
+*
+* Adopters may modify this file to suit their platform. Adopters are
+* encouraged to submit platform specific modifications to the Khronos
+* group so that they can be included in future versions of this file.
+* Please submit changes by sending them to the public Khronos Bugzilla
+* (http://khronos.org/bugzilla) by filing a bug against product
+* "Khronos (general)" component "Registry".
+*
+* A predefined template which fills in some of the bug fields can be
+* reached using http://tinyurl.com/khrplatform-h-bugreport, but you
+* must create a Bugzilla login first.
+*
+*
+* See the Implementer's Guidelines for information about where this file
+* should be located on your system and for more details of its use:
+* http://www.khronos.org/registry/implementers_guide.pdf
+*
+* This file should be included as
+* #include <KHR/khrplatform.h>
+* by Khronos client API header files that use its types and defines.
+*
+* The types in khrplatform.h should only be used to define API-specific types.
+*
+* Types defined in khrplatform.h:
+* khronos_int8_t signed 8 bit
+* khronos_uint8_t unsigned 8 bit
+* khronos_int16_t signed 16 bit
+* khronos_uint16_t unsigned 16 bit
+* khronos_int32_t signed 32 bit
+* khronos_uint32_t unsigned 32 bit
+* khronos_int64_t signed 64 bit
+* khronos_uint64_t unsigned 64 bit
+* khronos_intptr_t signed same number of bits as a pointer
+* khronos_uintptr_t unsigned same number of bits as a pointer
+* khronos_ssize_t signed size
+* khronos_usize_t unsigned size
+* khronos_float_t signed 32 bit floating point
+* khronos_time_ns_t unsigned 64 bit time in nanoseconds
+* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
+* nanoseconds
+* khronos_stime_nanoseconds_t signed time interval in nanoseconds
+* khronos_boolean_enum_t enumerated boolean type. This should
+* only be used as a base type when a client API's boolean type is
+* an enum. Client APIs which use an integer or other type for
+* booleans cannot use this as the base type for their boolean.
+*
+* Tokens defined in khrplatform.h:
+*
+* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
+*
+* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
+* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
+*
+* Calling convention macros defined in this file:
+* KHRONOS_APICALL
+* KHRONOS_APIENTRY
+* KHRONOS_APIATTRIBUTES
+*
+* These may be used in function prototypes as:
+*
+* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
+* int arg1,
+* int arg2) KHRONOS_APIATTRIBUTES;
+*/
+
+/*-------------------------------------------------------------------------
+* Definition of KHRONOS_APICALL
+*-------------------------------------------------------------------------
+* This precedes the return type of the function in the function prototype.
+*/
+#if defined(_WIN32) && !defined(__SCITECH_SNAP__) && !defined(SDL_VIDEO_STATIC_ANGLE)
+# define KHRONOS_APICALL __declspec(dllimport)
+#elif defined (__SYMBIAN32__)
+# define KHRONOS_APICALL IMPORT_C
+#else
+# define KHRONOS_APICALL
+#endif
+
+/*-------------------------------------------------------------------------
+* Definition of KHRONOS_APIENTRY
+*-------------------------------------------------------------------------
+* This follows the return type of the function and precedes the function
+* name in the function prototype.
+*/
+#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
+/* Win32 but not WinCE */
+# define KHRONOS_APIENTRY __stdcall
+#else
+# define KHRONOS_APIENTRY
+#endif
+
+/*-------------------------------------------------------------------------
+* Definition of KHRONOS_APIATTRIBUTES
+*-------------------------------------------------------------------------
+* This follows the closing parenthesis of the function prototype arguments.
+*/
+#if defined (__ARMCC_2__)
+#define KHRONOS_APIATTRIBUTES __softfp
+#else
+#define KHRONOS_APIATTRIBUTES
+#endif
+
+/*-------------------------------------------------------------------------
+* basic type definitions
+*-----------------------------------------------------------------------*/
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
+
+
+/*
+* Using <stdint.h>
+*/
+#include <stdint.h>
+typedef int32_t khronos_int32_t;
+typedef uint32_t khronos_uint32_t;
+typedef int64_t khronos_int64_t;
+typedef uint64_t khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif defined(__VMS ) || defined(__sgi)
+
+/*
+* Using <inttypes.h>
+*/
+#include <inttypes.h>
+typedef int32_t khronos_int32_t;
+typedef uint32_t khronos_uint32_t;
+typedef int64_t khronos_int64_t;
+typedef uint64_t khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
+
+/*
+* Win32
+*/
+typedef __int32 khronos_int32_t;
+typedef unsigned __int32 khronos_uint32_t;
+typedef __int64 khronos_int64_t;
+typedef unsigned __int64 khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif defined(__sun__) || defined(__digital__)
+
+/*
+* Sun or Digital
+*/
+typedef int khronos_int32_t;
+typedef unsigned int khronos_uint32_t;
+#if defined(__arch64__) || defined(_LP64)
+typedef long int khronos_int64_t;
+typedef unsigned long int khronos_uint64_t;
+#else
+typedef long long int khronos_int64_t;
+typedef unsigned long long int khronos_uint64_t;
+#endif /* __arch64__ */
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif 0
+
+/*
+* Hypothetical platform with no float or int64 support
+*/
+typedef int khronos_int32_t;
+typedef unsigned int khronos_uint32_t;
+#define KHRONOS_SUPPORT_INT64 0
+#define KHRONOS_SUPPORT_FLOAT 0
+
+#else
+
+/*
+* Generic fallback
+*/
+#include <stdint.h>
+typedef int32_t khronos_int32_t;
+typedef uint32_t khronos_uint32_t;
+typedef int64_t khronos_int64_t;
+typedef uint64_t khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#endif
+
+
+/*
+* Types that are (so far) the same on all platforms
+*/
+typedef signed char khronos_int8_t;
+typedef unsigned char khronos_uint8_t;
+typedef signed short int khronos_int16_t;
+typedef unsigned short int khronos_uint16_t;
+
+/*
+* Types that differ between LLP64 and LP64 architectures - in LLP64,
+* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
+* to be the only LLP64 architecture in current use.
+*/
+#ifdef _WIN64
+typedef signed long long int khronos_intptr_t;
+typedef unsigned long long int khronos_uintptr_t;
+typedef signed long long int khronos_ssize_t;
+typedef unsigned long long int khronos_usize_t;
+#else
+typedef signed long int khronos_intptr_t;
+typedef unsigned long int khronos_uintptr_t;
+typedef signed long int khronos_ssize_t;
+typedef unsigned long int khronos_usize_t;
+#endif
+
+#if KHRONOS_SUPPORT_FLOAT
+/*
+* Float type
+*/
+typedef float khronos_float_t;
+#endif
+
+#if KHRONOS_SUPPORT_INT64
+/* Time types
+*
+* These types can be used to represent a time interval in nanoseconds or
+* an absolute Unadjusted System Time. Unadjusted System Time is the number
+* of nanoseconds since some arbitrary system event (e.g. since the last
+* time the system booted). The Unadjusted System Time is an unsigned
+* 64 bit value that wraps back to 0 every 584 years. Time intervals
+* may be either signed or unsigned.
+*/
+typedef khronos_uint64_t khronos_utime_nanoseconds_t;
+typedef khronos_int64_t khronos_stime_nanoseconds_t;
+#endif
+
+/*
+* Dummy value used to pad enum types to 32 bits.
+*/
+#ifndef KHRONOS_MAX_ENUM
+#define KHRONOS_MAX_ENUM 0x7FFFFFFF
+#endif
+
+/*
+* Enumerated boolean type
+*
+* Values other than zero should be considered to be true. Therefore
+* comparisons should not be made against KHRONOS_TRUE.
+*/
+typedef enum {
+ KHRONOS_FALSE = 0,
+ KHRONOS_TRUE = 1,
+ KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
+} khronos_boolean_enum_t;
+
+#endif /* __khrplatform_h_ */
+
+
+#ifndef __eglplatform_h_
+#define __eglplatform_h_
+
+/*
+** Copyright (c) 2007-2009 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+
+/* Platform-specific types and definitions for egl.h
+* $Revision: 12306 $ on $Date: 2010-08-25 09:51:28 -0700 (Wed, 25 Aug 2010) $
+*
+* Adopters may modify khrplatform.h and this file to suit their platform.
+* You are encouraged to submit all modifications to the Khronos group so that
+* they can be included in future versions of this file. Please submit changes
+* by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla)
+* by filing a bug against product "EGL" component "Registry".
+*/
+
+/*#include <KHR/khrplatform.h>*/
+
+/* Macros used in EGL function prototype declarations.
+*
+* EGL functions should be prototyped as:
+*
+* EGLAPI return-type EGLAPIENTRY eglFunction(arguments);
+* typedef return-type (EXPAPIENTRYP PFNEGLFUNCTIONPROC) (arguments);
+*
+* KHRONOS_APICALL and KHRONOS_APIENTRY are defined in KHR/khrplatform.h
+*/
+
+#ifndef EGLAPI
+#define EGLAPI KHRONOS_APICALL
+#endif
+
+#ifndef EGLAPIENTRY
+#define EGLAPIENTRY KHRONOS_APIENTRY
+#endif
+#define EGLAPIENTRYP EGLAPIENTRY*
+
+/* The types NativeDisplayType, NativeWindowType, and NativePixmapType
+* are aliases of window-system-dependent types, such as X Display * or
+* Windows Device Context. They must be defined in platform-specific
+* code below. The EGL-prefixed versions of Native*Type are the same
+* types, renamed in EGL 1.3 so all types in the API start with "EGL".
+*
+* Khronos STRONGLY RECOMMENDS that you use the default definitions
+* provided below, since these changes affect both binary and source
+* portability of applications using EGL running on different EGL
+* implementations.
+*/
+
+#if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN 1
+#endif
+#include <windows.h>
+
+#if __WINRT__
+#include <Unknwn.h>
+typedef IUnknown * EGLNativeWindowType;
+typedef IUnknown * EGLNativePixmapType;
+typedef IUnknown * EGLNativeDisplayType;
+#else
+typedef HDC EGLNativeDisplayType;
+typedef HBITMAP EGLNativePixmapType;
+typedef HWND EGLNativeWindowType;
+#endif
+
+#elif defined(__WINSCW__) || defined(__SYMBIAN32__) /* Symbian */
+
+typedef int EGLNativeDisplayType;
+typedef void *EGLNativeWindowType;
+typedef void *EGLNativePixmapType;
+
+#elif defined(WL_EGL_PLATFORM)
+
+typedef struct wl_display *EGLNativeDisplayType;
+typedef struct wl_egl_pixmap *EGLNativePixmapType;
+typedef struct wl_egl_window *EGLNativeWindowType;
+
+#elif defined(__GBM__)
+
+typedef struct gbm_device *EGLNativeDisplayType;
+typedef struct gbm_bo *EGLNativePixmapType;
+typedef void *EGLNativeWindowType;
+
+#elif defined(__ANDROID__) /* Android */
+
+struct ANativeWindow;
+struct egl_native_pixmap_t;
+
+typedef struct ANativeWindow *EGLNativeWindowType;
+typedef struct egl_native_pixmap_t *EGLNativePixmapType;
+typedef void *EGLNativeDisplayType;
+
+#elif defined(MIR_EGL_PLATFORM)
+
+#include <mir_toolkit/mir_client_library.h>
+typedef MirEGLNativeDisplayType EGLNativeDisplayType;
+typedef void *EGLNativePixmapType;
+typedef MirEGLNativeWindowType EGLNativeWindowType;
+
+#elif defined(__unix__)
+
+#ifdef MESA_EGL_NO_X11_HEADERS
+
+typedef void *EGLNativeDisplayType;
+typedef khronos_uintptr_t EGLNativePixmapType;
+typedef khronos_uintptr_t EGLNativeWindowType;
+
+#else
+
+/* X11 (tentative) */
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+typedef Display *EGLNativeDisplayType;
+typedef Pixmap EGLNativePixmapType;
+typedef Window EGLNativeWindowType;
+
+#endif /* MESA_EGL_NO_X11_HEADERS */
+
+#else
+#error "Platform not recognized"
+#endif
+
+/* EGL 1.2 types, renamed for consistency in EGL 1.3 */
+typedef EGLNativeDisplayType NativeDisplayType;
+typedef EGLNativePixmapType NativePixmapType;
+typedef EGLNativeWindowType NativeWindowType;
+
+
+/* Define EGLint. This must be a signed integral type large enough to contain
+* all legal attribute names and values passed into and out of EGL, whether
+* their type is boolean, bitmask, enumerant (symbolic constant), integer,
+* handle, or other. While in general a 32-bit integer will suffice, if
+* handles are 64 bit types, then EGLint should be defined as a signed 64-bit
+* integer type.
+*/
+typedef khronos_int32_t EGLint;
+
+#endif /* __eglplatform_h */
+
+#ifndef __egl_h_
+#define __egl_h_ 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+** Copyright (c) 2013-2015 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+/*
+** This header is generated from the Khronos OpenGL / OpenGL ES XML
+** API Registry. The current version of the Registry, generator scripts
+** used to make the header, and the header can be found at
+** http://www.opengl.org/registry/
+**
+** Khronos $Revision: 31566 $ on $Date: 2015-06-23 08:48:48 -0700 (Tue, 23 Jun 2015) $
+*/
+
+/*#include <EGL/eglplatform.h>*/
+
+/* Generated on date 20150623 */
+
+/* Generated C header for:
+ * API: egl
+ * Versions considered: .*
+ * Versions emitted: .*
+ * Default extensions included: None
+ * Additional extensions included: _nomatch_^
+ * Extensions removed: _nomatch_^
+ */
+
+#ifndef EGL_VERSION_1_0
+#define EGL_VERSION_1_0 1
+typedef unsigned int EGLBoolean;
+typedef void *EGLDisplay;
+typedef void *EGLConfig;
+typedef void *EGLSurface;
+typedef void *EGLContext;
+typedef void (*__eglMustCastToProperFunctionPointerType)(void);
+#define EGL_ALPHA_SIZE 0x3021
+#define EGL_BAD_ACCESS 0x3002
+#define EGL_BAD_ALLOC 0x3003
+#define EGL_BAD_ATTRIBUTE 0x3004
+#define EGL_BAD_CONFIG 0x3005
+#define EGL_BAD_CONTEXT 0x3006
+#define EGL_BAD_CURRENT_SURFACE 0x3007
+#define EGL_BAD_DISPLAY 0x3008
+#define EGL_BAD_MATCH 0x3009
+#define EGL_BAD_NATIVE_PIXMAP 0x300A
+#define EGL_BAD_NATIVE_WINDOW 0x300B
+#define EGL_BAD_PARAMETER 0x300C
+#define EGL_BAD_SURFACE 0x300D
+#define EGL_BLUE_SIZE 0x3022
+#define EGL_BUFFER_SIZE 0x3020
+#define EGL_CONFIG_CAVEAT 0x3027
+#define EGL_CONFIG_ID 0x3028
+#define EGL_CORE_NATIVE_ENGINE 0x305B
+#define EGL_DEPTH_SIZE 0x3025
+#define EGL_DONT_CARE ((EGLint)-1)
+#define EGL_DRAW 0x3059
+#define EGL_EXTENSIONS 0x3055
+#define EGL_FALSE 0
+#define EGL_GREEN_SIZE 0x3023
+#define EGL_HEIGHT 0x3056
+#define EGL_LARGEST_PBUFFER 0x3058
+#define EGL_LEVEL 0x3029
+#define EGL_MAX_PBUFFER_HEIGHT 0x302A
+#define EGL_MAX_PBUFFER_PIXELS 0x302B
+#define EGL_MAX_PBUFFER_WIDTH 0x302C
+#define EGL_NATIVE_RENDERABLE 0x302D
+#define EGL_NATIVE_VISUAL_ID 0x302E
+#define EGL_NATIVE_VISUAL_TYPE 0x302F
+#define EGL_NONE 0x3038
+#define EGL_NON_CONFORMANT_CONFIG 0x3051
+#define EGL_NOT_INITIALIZED 0x3001
+#define EGL_NO_CONTEXT ((EGLContext)0)
+#define EGL_NO_DISPLAY ((EGLDisplay)0)
+#define EGL_NO_SURFACE ((EGLSurface)0)
+#define EGL_PBUFFER_BIT 0x0001
+#define EGL_PIXMAP_BIT 0x0002
+#define EGL_READ 0x305A
+#define EGL_RED_SIZE 0x3024
+#define EGL_SAMPLES 0x3031
+#define EGL_SAMPLE_BUFFERS 0x3032
+#define EGL_SLOW_CONFIG 0x3050
+#define EGL_STENCIL_SIZE 0x3026
+#define EGL_SUCCESS 0x3000
+#define EGL_SURFACE_TYPE 0x3033
+#define EGL_TRANSPARENT_BLUE_VALUE 0x3035
+#define EGL_TRANSPARENT_GREEN_VALUE 0x3036
+#define EGL_TRANSPARENT_RED_VALUE 0x3037
+#define EGL_TRANSPARENT_RGB 0x3052
+#define EGL_TRANSPARENT_TYPE 0x3034
+#define EGL_TRUE 1
+#define EGL_VENDOR 0x3053
+#define EGL_VERSION 0x3054
+#define EGL_WIDTH 0x3057
+#define EGL_WINDOW_BIT 0x0004
+EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig (EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
+EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers (EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target);
+EGLAPI EGLContext EGLAPIENTRY eglCreateContext (EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferSurface (EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurface (EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface (EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext (EGLDisplay dpy, EGLContext ctx);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface (EGLDisplay dpy, EGLSurface surface);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib (EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs (EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
+EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay (void);
+EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface (EGLint readdraw);
+EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay (EGLNativeDisplayType display_id);
+EGLAPI EGLint EGLAPIENTRY eglGetError (void);
+EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress (const char *procname);
+EGLAPI EGLBoolean EGLAPIENTRY eglInitialize (EGLDisplay dpy, EGLint *major, EGLint *minor);
+EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent (EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext (EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value);
+EGLAPI const char *EGLAPIENTRY eglQueryString (EGLDisplay dpy, EGLint name);
+EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers (EGLDisplay dpy, EGLSurface surface);
+EGLAPI EGLBoolean EGLAPIENTRY eglTerminate (EGLDisplay dpy);
+EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL (void);
+EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative (EGLint engine);
+#endif /* EGL_VERSION_1_0 */
+
+#ifndef EGL_VERSION_1_1
+#define EGL_VERSION_1_1 1
+#define EGL_BACK_BUFFER 0x3084
+#define EGL_BIND_TO_TEXTURE_RGB 0x3039
+#define EGL_BIND_TO_TEXTURE_RGBA 0x303A
+#define EGL_CONTEXT_LOST 0x300E
+#define EGL_MIN_SWAP_INTERVAL 0x303B
+#define EGL_MAX_SWAP_INTERVAL 0x303C
+#define EGL_MIPMAP_TEXTURE 0x3082
+#define EGL_MIPMAP_LEVEL 0x3083
+#define EGL_NO_TEXTURE 0x305C
+#define EGL_TEXTURE_2D 0x305F
+#define EGL_TEXTURE_FORMAT 0x3080
+#define EGL_TEXTURE_RGB 0x305D
+#define EGL_TEXTURE_RGBA 0x305E
+#define EGL_TEXTURE_TARGET 0x3081
+EGLAPI EGLBoolean EGLAPIENTRY eglBindTexImage (EGLDisplay dpy, EGLSurface surface, EGLint buffer);
+EGLAPI EGLBoolean EGLAPIENTRY eglReleaseTexImage (EGLDisplay dpy, EGLSurface surface, EGLint buffer);
+EGLAPI EGLBoolean EGLAPIENTRY eglSurfaceAttrib (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value);
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval (EGLDisplay dpy, EGLint interval);
+#endif /* EGL_VERSION_1_1 */
+
+#ifndef EGL_VERSION_1_2
+#define EGL_VERSION_1_2 1
+typedef unsigned int EGLenum;
+typedef void *EGLClientBuffer;
+#define EGL_ALPHA_FORMAT 0x3088
+#define EGL_ALPHA_FORMAT_NONPRE 0x308B
+#define EGL_ALPHA_FORMAT_PRE 0x308C
+#define EGL_ALPHA_MASK_SIZE 0x303E
+#define EGL_BUFFER_PRESERVED 0x3094
+#define EGL_BUFFER_DESTROYED 0x3095
+#define EGL_CLIENT_APIS 0x308D
+#define EGL_COLORSPACE 0x3087
+#define EGL_COLORSPACE_sRGB 0x3089
+#define EGL_COLORSPACE_LINEAR 0x308A
+#define EGL_COLOR_BUFFER_TYPE 0x303F
+#define EGL_CONTEXT_CLIENT_TYPE 0x3097
+#define EGL_DISPLAY_SCALING 10000
+#define EGL_HORIZONTAL_RESOLUTION 0x3090
+#define EGL_LUMINANCE_BUFFER 0x308F
+#define EGL_LUMINANCE_SIZE 0x303D
+#define EGL_OPENGL_ES_BIT 0x0001
+#define EGL_OPENVG_BIT 0x0002
+#define EGL_OPENGL_ES_API 0x30A0
+#define EGL_OPENVG_API 0x30A1
+#define EGL_OPENVG_IMAGE 0x3096
+#define EGL_PIXEL_ASPECT_RATIO 0x3092
+#define EGL_RENDERABLE_TYPE 0x3040
+#define EGL_RENDER_BUFFER 0x3086
+#define EGL_RGB_BUFFER 0x308E
+#define EGL_SINGLE_BUFFER 0x3085
+#define EGL_SWAP_BEHAVIOR 0x3093
+#define EGL_UNKNOWN ((EGLint)-1)
+#define EGL_VERTICAL_RESOLUTION 0x3091
+EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI (EGLenum api);
+EGLAPI EGLenum EGLAPIENTRY eglQueryAPI (void);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferFromClientBuffer (EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglReleaseThread (void);
+EGLAPI EGLBoolean EGLAPIENTRY eglWaitClient (void);
+#endif /* EGL_VERSION_1_2 */
+
+#ifndef EGL_VERSION_1_3
+#define EGL_VERSION_1_3 1
+#define EGL_CONFORMANT 0x3042
+#define EGL_CONTEXT_CLIENT_VERSION 0x3098
+#define EGL_MATCH_NATIVE_PIXMAP 0x3041
+#define EGL_OPENGL_ES2_BIT 0x0004
+#define EGL_VG_ALPHA_FORMAT 0x3088
+#define EGL_VG_ALPHA_FORMAT_NONPRE 0x308B
+#define EGL_VG_ALPHA_FORMAT_PRE 0x308C
+#define EGL_VG_ALPHA_FORMAT_PRE_BIT 0x0040
+#define EGL_VG_COLORSPACE 0x3087
+#define EGL_VG_COLORSPACE_sRGB 0x3089
+#define EGL_VG_COLORSPACE_LINEAR 0x308A
+#define EGL_VG_COLORSPACE_LINEAR_BIT 0x0020
+#endif /* EGL_VERSION_1_3 */
+
+#ifndef EGL_VERSION_1_4
+#define EGL_VERSION_1_4 1
+#define EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType)0)
+#define EGL_MULTISAMPLE_RESOLVE_BOX_BIT 0x0200
+#define EGL_MULTISAMPLE_RESOLVE 0x3099
+#define EGL_MULTISAMPLE_RESOLVE_DEFAULT 0x309A
+#define EGL_MULTISAMPLE_RESOLVE_BOX 0x309B
+#define EGL_OPENGL_API 0x30A2
+#define EGL_OPENGL_BIT 0x0008
+#define EGL_SWAP_BEHAVIOR_PRESERVED_BIT 0x0400
+EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext (void);
+#endif /* EGL_VERSION_1_4 */
+
+#ifndef EGL_VERSION_1_5
+#define EGL_VERSION_1_5 1
+typedef void *EGLSync;
+typedef intptr_t EGLAttrib;
+typedef khronos_utime_nanoseconds_t EGLTime;
+typedef void *EGLImage;
+#define EGL_CONTEXT_MAJOR_VERSION 0x3098
+#define EGL_CONTEXT_MINOR_VERSION 0x30FB
+#define EGL_CONTEXT_OPENGL_PROFILE_MASK 0x30FD
+#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY 0x31BD
+#define EGL_NO_RESET_NOTIFICATION 0x31BE
+#define EGL_LOSE_CONTEXT_ON_RESET 0x31BF
+#define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT 0x00000001
+#define EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT 0x00000002
+#define EGL_CONTEXT_OPENGL_DEBUG 0x31B0
+#define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE 0x31B1
+#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS 0x31B2
+#define EGL_OPENGL_ES3_BIT 0x00000040
+#define EGL_CL_EVENT_HANDLE 0x309C
+#define EGL_SYNC_CL_EVENT 0x30FE
+#define EGL_SYNC_CL_EVENT_COMPLETE 0x30FF
+#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE 0x30F0
+#define EGL_SYNC_TYPE 0x30F7
+#define EGL_SYNC_STATUS 0x30F1
+#define EGL_SYNC_CONDITION 0x30F8
+#define EGL_SIGNALED 0x30F2
+#define EGL_UNSIGNALED 0x30F3
+#define EGL_SYNC_FLUSH_COMMANDS_BIT 0x0001
+#define EGL_FOREVER 0xFFFFFFFFFFFFFFFFull
+#define EGL_TIMEOUT_EXPIRED 0x30F5
+#define EGL_CONDITION_SATISFIED 0x30F6
+#define EGL_NO_SYNC ((EGLSync)0)
+#define EGL_SYNC_FENCE 0x30F9
+#define EGL_GL_COLORSPACE 0x309D
+#define EGL_GL_COLORSPACE_SRGB 0x3089
+#define EGL_GL_COLORSPACE_LINEAR 0x308A
+#define EGL_GL_RENDERBUFFER 0x30B9
+#define EGL_GL_TEXTURE_2D 0x30B1
+#define EGL_GL_TEXTURE_LEVEL 0x30BC
+#define EGL_GL_TEXTURE_3D 0x30B2
+#define EGL_GL_TEXTURE_ZOFFSET 0x30BD
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x30B3
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x30B4
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x30B5
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x30B6
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x30B7
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x30B8
+#define EGL_IMAGE_PRESERVED 0x30D2
+#define EGL_NO_IMAGE ((EGLImage)0)
+EGLAPI EGLSync EGLAPIENTRY eglCreateSync (EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroySync (EGLDisplay dpy, EGLSync sync);
+EGLAPI EGLint EGLAPIENTRY eglClientWaitSync (EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttrib (EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value);
+EGLAPI EGLImage EGLAPIENTRY eglCreateImage (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImage (EGLDisplay dpy, EGLImage image);
+EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplay (EGLenum platform, void *native_display, const EGLAttrib *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformWindowSurface (EGLDisplay dpy, EGLConfig config, void *native_window, const EGLAttrib *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformPixmapSurface (EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLAttrib *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglWaitSync (EGLDisplay dpy, EGLSync sync, EGLint flags);
+#endif /* EGL_VERSION_1_5 */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __egl_h_ */
+
+
+
+#ifndef __eglext_h_
+#define __eglext_h_ 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+** Copyright (c) 2013-2015 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+/*
+** This header is generated from the Khronos OpenGL / OpenGL ES XML
+** API Registry. The current version of the Registry, generator scripts
+** used to make the header, and the header can be found at
+** http://www.opengl.org/registry/
+**
+** Khronos $Revision: 31566 $ on $Date: 2015-06-23 08:48:48 -0700 (Tue, 23 Jun 2015) $
+*/
+
+/*#include <EGL/eglplatform.h>*/
+
+#define EGL_EGLEXT_VERSION 20150623
+
+/* Generated C header for:
+ * API: egl
+ * Versions considered: .*
+ * Versions emitted: _nomatch_^
+ * Default extensions included: egl
+ * Additional extensions included: _nomatch_^
+ * Extensions removed: _nomatch_^
+ */
+
+#ifndef EGL_KHR_cl_event
+#define EGL_KHR_cl_event 1
+#define EGL_CL_EVENT_HANDLE_KHR 0x309C
+#define EGL_SYNC_CL_EVENT_KHR 0x30FE
+#define EGL_SYNC_CL_EVENT_COMPLETE_KHR 0x30FF
+#endif /* EGL_KHR_cl_event */
+
+#ifndef EGL_KHR_cl_event2
+#define EGL_KHR_cl_event2 1
+typedef void *EGLSyncKHR;
+typedef intptr_t EGLAttribKHR;
+typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESYNC64KHRPROC) (EGLDisplay dpy, EGLenum type, const EGLAttribKHR *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateSync64KHR (EGLDisplay dpy, EGLenum type, const EGLAttribKHR *attrib_list);
+#endif
+#endif /* EGL_KHR_cl_event2 */
+
+#ifndef EGL_KHR_client_get_all_proc_addresses
+#define EGL_KHR_client_get_all_proc_addresses 1
+#endif /* EGL_KHR_client_get_all_proc_addresses */
+
+#ifndef EGL_KHR_config_attribs
+#define EGL_KHR_config_attribs 1
+#define EGL_CONFORMANT_KHR 0x3042
+#define EGL_VG_COLORSPACE_LINEAR_BIT_KHR 0x0020
+#define EGL_VG_ALPHA_FORMAT_PRE_BIT_KHR 0x0040
+#endif /* EGL_KHR_config_attribs */
+
+#ifndef EGL_KHR_create_context
+#define EGL_KHR_create_context 1
+#define EGL_CONTEXT_MAJOR_VERSION_KHR 0x3098
+#define EGL_CONTEXT_MINOR_VERSION_KHR 0x30FB
+#define EGL_CONTEXT_FLAGS_KHR 0x30FC
+#define EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR 0x30FD
+#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR 0x31BD
+#define EGL_NO_RESET_NOTIFICATION_KHR 0x31BE
+#define EGL_LOSE_CONTEXT_ON_RESET_KHR 0x31BF
+#define EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR 0x00000001
+#define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR 0x00000002
+#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR 0x00000004
+#define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR 0x00000001
+#define EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR 0x00000002
+#define EGL_OPENGL_ES3_BIT_KHR 0x00000040
+#endif /* EGL_KHR_create_context */
+
+#ifndef EGL_KHR_create_context_no_error
+#define EGL_KHR_create_context_no_error 1
+#define EGL_CONTEXT_OPENGL_NO_ERROR_KHR 0x31B3
+#endif /* EGL_KHR_create_context_no_error */
+
+#ifndef EGL_KHR_fence_sync
+#define EGL_KHR_fence_sync 1
+typedef khronos_utime_nanoseconds_t EGLTimeKHR;
+#ifdef KHRONOS_SUPPORT_INT64
+#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR 0x30F0
+#define EGL_SYNC_CONDITION_KHR 0x30F8
+#define EGL_SYNC_FENCE_KHR 0x30F9
+typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESYNCKHRPROC) (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync);
+typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateSyncKHR (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncKHR (EGLDisplay dpy, EGLSyncKHR sync);
+EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncKHR (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribKHR (EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value);
+#endif
+#endif /* KHRONOS_SUPPORT_INT64 */
+#endif /* EGL_KHR_fence_sync */
+
+#ifndef EGL_KHR_get_all_proc_addresses
+#define EGL_KHR_get_all_proc_addresses 1
+#endif /* EGL_KHR_get_all_proc_addresses */
+
+#ifndef EGL_KHR_gl_colorspace
+#define EGL_KHR_gl_colorspace 1
+#define EGL_GL_COLORSPACE_KHR 0x309D
+#define EGL_GL_COLORSPACE_SRGB_KHR 0x3089
+#define EGL_GL_COLORSPACE_LINEAR_KHR 0x308A
+#endif /* EGL_KHR_gl_colorspace */
+
+#ifndef EGL_KHR_gl_renderbuffer_image
+#define EGL_KHR_gl_renderbuffer_image 1
+#define EGL_GL_RENDERBUFFER_KHR 0x30B9
+#endif /* EGL_KHR_gl_renderbuffer_image */
+
+#ifndef EGL_KHR_gl_texture_2D_image
+#define EGL_KHR_gl_texture_2D_image 1
+#define EGL_GL_TEXTURE_2D_KHR 0x30B1
+#define EGL_GL_TEXTURE_LEVEL_KHR 0x30BC
+#endif /* EGL_KHR_gl_texture_2D_image */
+
+#ifndef EGL_KHR_gl_texture_3D_image
+#define EGL_KHR_gl_texture_3D_image 1
+#define EGL_GL_TEXTURE_3D_KHR 0x30B2
+#define EGL_GL_TEXTURE_ZOFFSET_KHR 0x30BD
+#endif /* EGL_KHR_gl_texture_3D_image */
+
+#ifndef EGL_KHR_gl_texture_cubemap_image
+#define EGL_KHR_gl_texture_cubemap_image 1
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR 0x30B3
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR 0x30B4
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR 0x30B5
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR 0x30B6
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR 0x30B7
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR 0x30B8
+#endif /* EGL_KHR_gl_texture_cubemap_image */
+
+#ifndef EGL_KHR_image
+#define EGL_KHR_image 1
+typedef void *EGLImageKHR;
+#define EGL_NATIVE_PIXMAP_KHR 0x30B0
+#define EGL_NO_IMAGE_KHR ((EGLImageKHR)0)
+typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGLImageKHR image);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLImageKHR EGLAPIENTRY eglCreateImageKHR (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImageKHR (EGLDisplay dpy, EGLImageKHR image);
+#endif
+#endif /* EGL_KHR_image */
+
+#ifndef EGL_KHR_image_base
+#define EGL_KHR_image_base 1
+#define EGL_IMAGE_PRESERVED_KHR 0x30D2
+#endif /* EGL_KHR_image_base */
+
+#ifndef EGL_KHR_image_pixmap
+#define EGL_KHR_image_pixmap 1
+#endif /* EGL_KHR_image_pixmap */
+
+#ifndef EGL_KHR_lock_surface
+#define EGL_KHR_lock_surface 1
+#define EGL_READ_SURFACE_BIT_KHR 0x0001
+#define EGL_WRITE_SURFACE_BIT_KHR 0x0002
+#define EGL_LOCK_SURFACE_BIT_KHR 0x0080
+#define EGL_OPTIMAL_FORMAT_BIT_KHR 0x0100
+#define EGL_MATCH_FORMAT_KHR 0x3043
+#define EGL_FORMAT_RGB_565_EXACT_KHR 0x30C0
+#define EGL_FORMAT_RGB_565_KHR 0x30C1
+#define EGL_FORMAT_RGBA_8888_EXACT_KHR 0x30C2
+#define EGL_FORMAT_RGBA_8888_KHR 0x30C3
+#define EGL_MAP_PRESERVE_PIXELS_KHR 0x30C4
+#define EGL_LOCK_USAGE_HINT_KHR 0x30C5
+#define EGL_BITMAP_POINTER_KHR 0x30C6
+#define EGL_BITMAP_PITCH_KHR 0x30C7
+#define EGL_BITMAP_ORIGIN_KHR 0x30C8
+#define EGL_BITMAP_PIXEL_RED_OFFSET_KHR 0x30C9
+#define EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR 0x30CA
+#define EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR 0x30CB
+#define EGL_BITMAP_PIXEL_ALPHA_OFFSET_KHR 0x30CC
+#define EGL_BITMAP_PIXEL_LUMINANCE_OFFSET_KHR 0x30CD
+#define EGL_LOWER_LEFT_KHR 0x30CE
+#define EGL_UPPER_LEFT_KHR 0x30CF
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLLOCKSURFACEKHRPROC) (EGLDisplay dpy, EGLSurface surface, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLUNLOCKSURFACEKHRPROC) (EGLDisplay dpy, EGLSurface surface);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglLockSurfaceKHR (EGLDisplay dpy, EGLSurface surface, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglUnlockSurfaceKHR (EGLDisplay dpy, EGLSurface surface);
+#endif
+#endif /* EGL_KHR_lock_surface */
+
+#ifndef EGL_KHR_lock_surface2
+#define EGL_KHR_lock_surface2 1
+#define EGL_BITMAP_PIXEL_SIZE_KHR 0x3110
+#endif /* EGL_KHR_lock_surface2 */
+
+#ifndef EGL_KHR_lock_surface3
+#define EGL_KHR_lock_surface3 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSURFACE64KHRPROC) (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLAttribKHR *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface64KHR (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLAttribKHR *value);
+#endif
+#endif /* EGL_KHR_lock_surface3 */
+
+#ifndef EGL_KHR_partial_update
+#define EGL_KHR_partial_update 1
+#define EGL_BUFFER_AGE_KHR 0x313D
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSETDAMAGEREGIONKHRPROC) (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSetDamageRegionKHR (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
+#endif
+#endif /* EGL_KHR_partial_update */
+
+#ifndef EGL_KHR_platform_android
+#define EGL_KHR_platform_android 1
+#define EGL_PLATFORM_ANDROID_KHR 0x3141
+#endif /* EGL_KHR_platform_android */
+
+#ifndef EGL_KHR_platform_gbm
+#define EGL_KHR_platform_gbm 1
+#define EGL_PLATFORM_GBM_KHR 0x31D7
+#endif /* EGL_KHR_platform_gbm */
+
+#ifndef EGL_KHR_platform_wayland
+#define EGL_KHR_platform_wayland 1
+#define EGL_PLATFORM_WAYLAND_KHR 0x31D8
+#endif /* EGL_KHR_platform_wayland */
+
+#ifndef EGL_KHR_platform_x11
+#define EGL_KHR_platform_x11 1
+#define EGL_PLATFORM_X11_KHR 0x31D5
+#define EGL_PLATFORM_X11_SCREEN_KHR 0x31D6
+#endif /* EGL_KHR_platform_x11 */
+
+#ifndef EGL_KHR_reusable_sync
+#define EGL_KHR_reusable_sync 1
+#ifdef KHRONOS_SUPPORT_INT64
+#define EGL_SYNC_STATUS_KHR 0x30F1
+#define EGL_SIGNALED_KHR 0x30F2
+#define EGL_UNSIGNALED_KHR 0x30F3
+#define EGL_TIMEOUT_EXPIRED_KHR 0x30F5
+#define EGL_CONDITION_SATISFIED_KHR 0x30F6
+#define EGL_SYNC_TYPE_KHR 0x30F7
+#define EGL_SYNC_REUSABLE_KHR 0x30FA
+#define EGL_SYNC_FLUSH_COMMANDS_BIT_KHR 0x0001
+#define EGL_FOREVER_KHR 0xFFFFFFFFFFFFFFFFull
+#define EGL_NO_SYNC_KHR ((EGLSyncKHR)0)
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncKHR (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode);
+#endif
+#endif /* KHRONOS_SUPPORT_INT64 */
+#endif /* EGL_KHR_reusable_sync */
+
+#ifndef EGL_KHR_stream
+#define EGL_KHR_stream 1
+typedef void *EGLStreamKHR;
+typedef khronos_uint64_t EGLuint64KHR;
+#ifdef KHRONOS_SUPPORT_INT64
+#define EGL_NO_STREAM_KHR ((EGLStreamKHR)0)
+#define EGL_CONSUMER_LATENCY_USEC_KHR 0x3210
+#define EGL_PRODUCER_FRAME_KHR 0x3212
+#define EGL_CONSUMER_FRAME_KHR 0x3213
+#define EGL_STREAM_STATE_KHR 0x3214
+#define EGL_STREAM_STATE_CREATED_KHR 0x3215
+#define EGL_STREAM_STATE_CONNECTING_KHR 0x3216
+#define EGL_STREAM_STATE_EMPTY_KHR 0x3217
+#define EGL_STREAM_STATE_NEW_FRAME_AVAILABLE_KHR 0x3218
+#define EGL_STREAM_STATE_OLD_FRAME_AVAILABLE_KHR 0x3219
+#define EGL_STREAM_STATE_DISCONNECTED_KHR 0x321A
+#define EGL_BAD_STREAM_KHR 0x321B
+#define EGL_BAD_STATE_KHR 0x321C
+typedef EGLStreamKHR (EGLAPIENTRYP PFNEGLCREATESTREAMKHRPROC) (EGLDisplay dpy, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSTREAMKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMATTRIBKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint *value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMU64KHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLuint64KHR *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLStreamKHR EGLAPIENTRY eglCreateStreamKHR (EGLDisplay dpy, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroyStreamKHR (EGLDisplay dpy, EGLStreamKHR stream);
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamAttribKHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamKHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamu64KHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLuint64KHR *value);
+#endif
+#endif /* KHRONOS_SUPPORT_INT64 */
+#endif /* EGL_KHR_stream */
+
+#ifndef EGL_KHR_stream_consumer_gltexture
+#define EGL_KHR_stream_consumer_gltexture 1
+#ifdef EGL_KHR_stream
+#define EGL_CONSUMER_ACQUIRE_TIMEOUT_USEC_KHR 0x321E
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERGLTEXTUREEXTERNALKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERACQUIREKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERRELEASEKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerGLTextureExternalKHR (EGLDisplay dpy, EGLStreamKHR stream);
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerAcquireKHR (EGLDisplay dpy, EGLStreamKHR stream);
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerReleaseKHR (EGLDisplay dpy, EGLStreamKHR stream);
+#endif
+#endif /* EGL_KHR_stream */
+#endif /* EGL_KHR_stream_consumer_gltexture */
+
+#ifndef EGL_KHR_stream_cross_process_fd
+#define EGL_KHR_stream_cross_process_fd 1
+typedef int EGLNativeFileDescriptorKHR;
+#ifdef EGL_KHR_stream
+#define EGL_NO_FILE_DESCRIPTOR_KHR ((EGLNativeFileDescriptorKHR)(-1))
+typedef EGLNativeFileDescriptorKHR (EGLAPIENTRYP PFNEGLGETSTREAMFILEDESCRIPTORKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream);
+typedef EGLStreamKHR (EGLAPIENTRYP PFNEGLCREATESTREAMFROMFILEDESCRIPTORKHRPROC) (EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLNativeFileDescriptorKHR EGLAPIENTRY eglGetStreamFileDescriptorKHR (EGLDisplay dpy, EGLStreamKHR stream);
+EGLAPI EGLStreamKHR EGLAPIENTRY eglCreateStreamFromFileDescriptorKHR (EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor);
+#endif
+#endif /* EGL_KHR_stream */
+#endif /* EGL_KHR_stream_cross_process_fd */
+
+#ifndef EGL_KHR_stream_fifo
+#define EGL_KHR_stream_fifo 1
+#ifdef EGL_KHR_stream
+#define EGL_STREAM_FIFO_LENGTH_KHR 0x31FC
+#define EGL_STREAM_TIME_NOW_KHR 0x31FD
+#define EGL_STREAM_TIME_CONSUMER_KHR 0x31FE
+#define EGL_STREAM_TIME_PRODUCER_KHR 0x31FF
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMTIMEKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLTimeKHR *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamTimeKHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLTimeKHR *value);
+#endif
+#endif /* EGL_KHR_stream */
+#endif /* EGL_KHR_stream_fifo */
+
+#ifndef EGL_KHR_stream_producer_aldatalocator
+#define EGL_KHR_stream_producer_aldatalocator 1
+#ifdef EGL_KHR_stream
+#endif /* EGL_KHR_stream */
+#endif /* EGL_KHR_stream_producer_aldatalocator */
+
+#ifndef EGL_KHR_stream_producer_eglsurface
+#define EGL_KHR_stream_producer_eglsurface 1
+#ifdef EGL_KHR_stream
+#define EGL_STREAM_BIT_KHR 0x0800
+typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATESTREAMPRODUCERSURFACEKHRPROC) (EGLDisplay dpy, EGLConfig config, EGLStreamKHR stream, const EGLint *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSurface EGLAPIENTRY eglCreateStreamProducerSurfaceKHR (EGLDisplay dpy, EGLConfig config, EGLStreamKHR stream, const EGLint *attrib_list);
+#endif
+#endif /* EGL_KHR_stream */
+#endif /* EGL_KHR_stream_producer_eglsurface */
+
+#ifndef EGL_KHR_surfaceless_context
+#define EGL_KHR_surfaceless_context 1
+#endif /* EGL_KHR_surfaceless_context */
+
+#ifndef EGL_KHR_swap_buffers_with_damage
+#define EGL_KHR_swap_buffers_with_damage 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSWITHDAMAGEKHRPROC) (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffersWithDamageKHR (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
+#endif
+#endif /* EGL_KHR_swap_buffers_with_damage */
+
+#ifndef EGL_KHR_vg_parent_image
+#define EGL_KHR_vg_parent_image 1
+#define EGL_VG_PARENT_IMAGE_KHR 0x30BA
+#endif /* EGL_KHR_vg_parent_image */
+
+#ifndef EGL_KHR_wait_sync
+#define EGL_KHR_wait_sync 1
+typedef EGLint (EGLAPIENTRYP PFNEGLWAITSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLint EGLAPIENTRY eglWaitSyncKHR (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags);
+#endif
+#endif /* EGL_KHR_wait_sync */
+
+#ifndef EGL_ANDROID_blob_cache
+#define EGL_ANDROID_blob_cache 1
+typedef khronos_ssize_t EGLsizeiANDROID;
+typedef void (*EGLSetBlobFuncANDROID) (const void *key, EGLsizeiANDROID keySize, const void *value, EGLsizeiANDROID valueSize);
+typedef EGLsizeiANDROID (*EGLGetBlobFuncANDROID) (const void *key, EGLsizeiANDROID keySize, void *value, EGLsizeiANDROID valueSize);
+typedef void (EGLAPIENTRYP PFNEGLSETBLOBCACHEFUNCSANDROIDPROC) (EGLDisplay dpy, EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI void EGLAPIENTRY eglSetBlobCacheFuncsANDROID (EGLDisplay dpy, EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get);
+#endif
+#endif /* EGL_ANDROID_blob_cache */
+
+#ifndef EGL_ANDROID_framebuffer_target
+#define EGL_ANDROID_framebuffer_target 1
+#define EGL_FRAMEBUFFER_TARGET_ANDROID 0x3147
+#endif /* EGL_ANDROID_framebuffer_target */
+
+#ifndef EGL_ANDROID_image_native_buffer
+#define EGL_ANDROID_image_native_buffer 1
+#define EGL_NATIVE_BUFFER_ANDROID 0x3140
+#endif /* EGL_ANDROID_image_native_buffer */
+
+#ifndef EGL_ANDROID_native_fence_sync
+#define EGL_ANDROID_native_fence_sync 1
+#define EGL_SYNC_NATIVE_FENCE_ANDROID 0x3144
+#define EGL_SYNC_NATIVE_FENCE_FD_ANDROID 0x3145
+#define EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID 0x3146
+#define EGL_NO_NATIVE_FENCE_FD_ANDROID -1
+typedef EGLint (EGLAPIENTRYP PFNEGLDUPNATIVEFENCEFDANDROIDPROC) (EGLDisplay dpy, EGLSyncKHR sync);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLint EGLAPIENTRY eglDupNativeFenceFDANDROID (EGLDisplay dpy, EGLSyncKHR sync);
+#endif
+#endif /* EGL_ANDROID_native_fence_sync */
+
+#ifndef EGL_ANDROID_recordable
+#define EGL_ANDROID_recordable 1
+#define EGL_RECORDABLE_ANDROID 0x3142
+#endif /* EGL_ANDROID_recordable */
+
+#ifndef EGL_ANGLE_d3d_share_handle_client_buffer
+#define EGL_ANGLE_d3d_share_handle_client_buffer 1
+#define EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE 0x3200
+#endif /* EGL_ANGLE_d3d_share_handle_client_buffer */
+
+#ifndef EGL_ANGLE_device_d3d
+#define EGL_ANGLE_device_d3d 1
+#define EGL_D3D9_DEVICE_ANGLE 0x33A0
+#define EGL_D3D11_DEVICE_ANGLE 0x33A1
+#endif /* EGL_ANGLE_device_d3d */
+
+#ifndef EGL_ANGLE_query_surface_pointer
+#define EGL_ANGLE_query_surface_pointer 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSURFACEPOINTERANGLEPROC) (EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurfacePointerANGLE (EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value);
+#endif
+#endif /* EGL_ANGLE_query_surface_pointer */
+
+#ifndef EGL_ANGLE_surface_d3d_texture_2d_share_handle
+#define EGL_ANGLE_surface_d3d_texture_2d_share_handle 1
+#endif /* EGL_ANGLE_surface_d3d_texture_2d_share_handle */
+
+#ifndef EGL_ANGLE_window_fixed_size
+#define EGL_ANGLE_window_fixed_size 1
+#define EGL_FIXED_SIZE_ANGLE 0x3201
+#endif /* EGL_ANGLE_window_fixed_size */
+
+#ifndef EGL_ARM_pixmap_multisample_discard
+#define EGL_ARM_pixmap_multisample_discard 1
+#define EGL_DISCARD_SAMPLES_ARM 0x3286
+#endif /* EGL_ARM_pixmap_multisample_discard */
+
+#ifndef EGL_EXT_buffer_age
+#define EGL_EXT_buffer_age 1
+#define EGL_BUFFER_AGE_EXT 0x313D
+#endif /* EGL_EXT_buffer_age */
+
+#ifndef EGL_EXT_client_extensions
+#define EGL_EXT_client_extensions 1
+#endif /* EGL_EXT_client_extensions */
+
+#ifndef EGL_EXT_create_context_robustness
+#define EGL_EXT_create_context_robustness 1
+#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT 0x30BF
+#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT 0x3138
+#define EGL_NO_RESET_NOTIFICATION_EXT 0x31BE
+#define EGL_LOSE_CONTEXT_ON_RESET_EXT 0x31BF
+#endif /* EGL_EXT_create_context_robustness */
+
+#ifndef EGL_EXT_device_base
+#define EGL_EXT_device_base 1
+typedef void *EGLDeviceEXT;
+#define EGL_NO_DEVICE_EXT ((EGLDeviceEXT)(0))
+#define EGL_BAD_DEVICE_EXT 0x322B
+#define EGL_DEVICE_EXT 0x322C
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDEVICEATTRIBEXTPROC) (EGLDeviceEXT device, EGLint attribute, EGLAttrib *value);
+typedef const char *(EGLAPIENTRYP PFNEGLQUERYDEVICESTRINGEXTPROC) (EGLDeviceEXT device, EGLint name);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDEVICESEXTPROC) (EGLint max_devices, EGLDeviceEXT *devices, EGLint *num_devices);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDISPLAYATTRIBEXTPROC) (EGLDisplay dpy, EGLint attribute, EGLAttrib *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryDeviceAttribEXT (EGLDeviceEXT device, EGLint attribute, EGLAttrib *value);
+EGLAPI const char *EGLAPIENTRY eglQueryDeviceStringEXT (EGLDeviceEXT device, EGLint name);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryDevicesEXT (EGLint max_devices, EGLDeviceEXT *devices, EGLint *num_devices);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryDisplayAttribEXT (EGLDisplay dpy, EGLint attribute, EGLAttrib *value);
+#endif
+#endif /* EGL_EXT_device_base */
+
+#ifndef EGL_EXT_device_drm
+#define EGL_EXT_device_drm 1
+#define EGL_DRM_DEVICE_FILE_EXT 0x3233
+#endif /* EGL_EXT_device_drm */
+
+#ifndef EGL_EXT_device_enumeration
+#define EGL_EXT_device_enumeration 1
+#endif /* EGL_EXT_device_enumeration */
+
+#ifndef EGL_EXT_device_openwf
+#define EGL_EXT_device_openwf 1
+#define EGL_OPENWF_DEVICE_ID_EXT 0x3237
+#endif /* EGL_EXT_device_openwf */
+
+#ifndef EGL_EXT_device_query
+#define EGL_EXT_device_query 1
+#endif /* EGL_EXT_device_query */
+
+#ifndef EGL_EXT_image_dma_buf_import
+#define EGL_EXT_image_dma_buf_import 1
+#define EGL_LINUX_DMA_BUF_EXT 0x3270
+#define EGL_LINUX_DRM_FOURCC_EXT 0x3271
+#define EGL_DMA_BUF_PLANE0_FD_EXT 0x3272
+#define EGL_DMA_BUF_PLANE0_OFFSET_EXT 0x3273
+#define EGL_DMA_BUF_PLANE0_PITCH_EXT 0x3274
+#define EGL_DMA_BUF_PLANE1_FD_EXT 0x3275
+#define EGL_DMA_BUF_PLANE1_OFFSET_EXT 0x3276
+#define EGL_DMA_BUF_PLANE1_PITCH_EXT 0x3277
+#define EGL_DMA_BUF_PLANE2_FD_EXT 0x3278
+#define EGL_DMA_BUF_PLANE2_OFFSET_EXT 0x3279
+#define EGL_DMA_BUF_PLANE2_PITCH_EXT 0x327A
+#define EGL_YUV_COLOR_SPACE_HINT_EXT 0x327B
+#define EGL_SAMPLE_RANGE_HINT_EXT 0x327C
+#define EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT 0x327D
+#define EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT 0x327E
+#define EGL_ITU_REC601_EXT 0x327F
+#define EGL_ITU_REC709_EXT 0x3280
+#define EGL_ITU_REC2020_EXT 0x3281
+#define EGL_YUV_FULL_RANGE_EXT 0x3282
+#define EGL_YUV_NARROW_RANGE_EXT 0x3283
+#define EGL_YUV_CHROMA_SITING_0_EXT 0x3284
+#define EGL_YUV_CHROMA_SITING_0_5_EXT 0x3285
+#endif /* EGL_EXT_image_dma_buf_import */
+
+#ifndef EGL_EXT_multiview_window
+#define EGL_EXT_multiview_window 1
+#define EGL_MULTIVIEW_VIEW_COUNT_EXT 0x3134
+#endif /* EGL_EXT_multiview_window */
+
+#ifndef EGL_EXT_output_base
+#define EGL_EXT_output_base 1
+typedef void *EGLOutputLayerEXT;
+typedef void *EGLOutputPortEXT;
+#define EGL_NO_OUTPUT_LAYER_EXT ((EGLOutputLayerEXT)0)
+#define EGL_NO_OUTPUT_PORT_EXT ((EGLOutputPortEXT)0)
+#define EGL_BAD_OUTPUT_LAYER_EXT 0x322D
+#define EGL_BAD_OUTPUT_PORT_EXT 0x322E
+#define EGL_SWAP_INTERVAL_EXT 0x322F
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETOUTPUTLAYERSEXTPROC) (EGLDisplay dpy, const EGLAttrib *attrib_list, EGLOutputLayerEXT *layers, EGLint max_layers, EGLint *num_layers);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETOUTPUTPORTSEXTPROC) (EGLDisplay dpy, const EGLAttrib *attrib_list, EGLOutputPortEXT *ports, EGLint max_ports, EGLint *num_ports);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLOUTPUTLAYERATTRIBEXTPROC) (EGLDisplay dpy, EGLOutputLayerEXT layer, EGLint attribute, EGLAttrib value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYOUTPUTLAYERATTRIBEXTPROC) (EGLDisplay dpy, EGLOutputLayerEXT layer, EGLint attribute, EGLAttrib *value);
+typedef const char *(EGLAPIENTRYP PFNEGLQUERYOUTPUTLAYERSTRINGEXTPROC) (EGLDisplay dpy, EGLOutputLayerEXT layer, EGLint name);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLOUTPUTPORTATTRIBEXTPROC) (EGLDisplay dpy, EGLOutputPortEXT port, EGLint attribute, EGLAttrib value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYOUTPUTPORTATTRIBEXTPROC) (EGLDisplay dpy, EGLOutputPortEXT port, EGLint attribute, EGLAttrib *value);
+typedef const char *(EGLAPIENTRYP PFNEGLQUERYOUTPUTPORTSTRINGEXTPROC) (EGLDisplay dpy, EGLOutputPortEXT port, EGLint name);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglGetOutputLayersEXT (EGLDisplay dpy, const EGLAttrib *attrib_list, EGLOutputLayerEXT *layers, EGLint max_layers, EGLint *num_layers);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetOutputPortsEXT (EGLDisplay dpy, const EGLAttrib *attrib_list, EGLOutputPortEXT *ports, EGLint max_ports, EGLint *num_ports);
+EGLAPI EGLBoolean EGLAPIENTRY eglOutputLayerAttribEXT (EGLDisplay dpy, EGLOutputLayerEXT layer, EGLint attribute, EGLAttrib value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryOutputLayerAttribEXT (EGLDisplay dpy, EGLOutputLayerEXT layer, EGLint attribute, EGLAttrib *value);
+EGLAPI const char *EGLAPIENTRY eglQueryOutputLayerStringEXT (EGLDisplay dpy, EGLOutputLayerEXT layer, EGLint name);
+EGLAPI EGLBoolean EGLAPIENTRY eglOutputPortAttribEXT (EGLDisplay dpy, EGLOutputPortEXT port, EGLint attribute, EGLAttrib value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryOutputPortAttribEXT (EGLDisplay dpy, EGLOutputPortEXT port, EGLint attribute, EGLAttrib *value);
+EGLAPI const char *EGLAPIENTRY eglQueryOutputPortStringEXT (EGLDisplay dpy, EGLOutputPortEXT port, EGLint name);
+#endif
+#endif /* EGL_EXT_output_base */
+
+#ifndef EGL_EXT_output_drm
+#define EGL_EXT_output_drm 1
+#define EGL_DRM_CRTC_EXT 0x3234
+#define EGL_DRM_PLANE_EXT 0x3235
+#define EGL_DRM_CONNECTOR_EXT 0x3236
+#endif /* EGL_EXT_output_drm */
+
+#ifndef EGL_EXT_output_openwf
+#define EGL_EXT_output_openwf 1
+#define EGL_OPENWF_PIPELINE_ID_EXT 0x3238
+#define EGL_OPENWF_PORT_ID_EXT 0x3239
+#endif /* EGL_EXT_output_openwf */
+
+#ifndef EGL_EXT_platform_base
+#define EGL_EXT_platform_base 1
+typedef EGLDisplay (EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC) (EGLenum platform, void *native_display, const EGLint *attrib_list);
+typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC) (EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list);
+typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPLATFORMPIXMAPSURFACEEXTPROC) (EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLint *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplayEXT (EGLenum platform, void *native_display, const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformWindowSurfaceEXT (EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformPixmapSurfaceEXT (EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLint *attrib_list);
+#endif
+#endif /* EGL_EXT_platform_base */
+
+#ifndef EGL_EXT_platform_device
+#define EGL_EXT_platform_device 1
+#define EGL_PLATFORM_DEVICE_EXT 0x313F
+#endif /* EGL_EXT_platform_device */
+
+#ifndef EGL_EXT_platform_wayland
+#define EGL_EXT_platform_wayland 1
+#define EGL_PLATFORM_WAYLAND_EXT 0x31D8
+#endif /* EGL_EXT_platform_wayland */
+
+#ifndef EGL_EXT_platform_x11
+#define EGL_EXT_platform_x11 1
+#define EGL_PLATFORM_X11_EXT 0x31D5
+#define EGL_PLATFORM_X11_SCREEN_EXT 0x31D6
+#endif /* EGL_EXT_platform_x11 */
+
+#ifndef EGL_EXT_protected_surface
+#define EGL_EXT_protected_surface 1
+#define EGL_PROTECTED_CONTENT_EXT 0x32C0
+#endif /* EGL_EXT_protected_surface */
+
+#ifndef EGL_EXT_stream_consumer_egloutput
+#define EGL_EXT_stream_consumer_egloutput 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMEROUTPUTEXTPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLOutputLayerEXT layer);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerOutputEXT (EGLDisplay dpy, EGLStreamKHR stream, EGLOutputLayerEXT layer);
+#endif
+#endif /* EGL_EXT_stream_consumer_egloutput */
+
+#ifndef EGL_EXT_swap_buffers_with_damage
+#define EGL_EXT_swap_buffers_with_damage 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC) (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffersWithDamageEXT (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
+#endif
+#endif /* EGL_EXT_swap_buffers_with_damage */
+
+#ifndef EGL_EXT_yuv_surface
+#define EGL_EXT_yuv_surface 1
+#define EGL_YUV_ORDER_EXT 0x3301
+#define EGL_YUV_NUMBER_OF_PLANES_EXT 0x3311
+#define EGL_YUV_SUBSAMPLE_EXT 0x3312
+#define EGL_YUV_DEPTH_RANGE_EXT 0x3317
+#define EGL_YUV_CSC_STANDARD_EXT 0x330A
+#define EGL_YUV_PLANE_BPP_EXT 0x331A
+#define EGL_YUV_BUFFER_EXT 0x3300
+#define EGL_YUV_ORDER_YUV_EXT 0x3302
+#define EGL_YUV_ORDER_YVU_EXT 0x3303
+#define EGL_YUV_ORDER_YUYV_EXT 0x3304
+#define EGL_YUV_ORDER_UYVY_EXT 0x3305
+#define EGL_YUV_ORDER_YVYU_EXT 0x3306
+#define EGL_YUV_ORDER_VYUY_EXT 0x3307
+#define EGL_YUV_ORDER_AYUV_EXT 0x3308
+#define EGL_YUV_SUBSAMPLE_4_2_0_EXT 0x3313
+#define EGL_YUV_SUBSAMPLE_4_2_2_EXT 0x3314
+#define EGL_YUV_SUBSAMPLE_4_4_4_EXT 0x3315
+#define EGL_YUV_DEPTH_RANGE_LIMITED_EXT 0x3318
+#define EGL_YUV_DEPTH_RANGE_FULL_EXT 0x3319
+#define EGL_YUV_CSC_STANDARD_601_EXT 0x330B
+#define EGL_YUV_CSC_STANDARD_709_EXT 0x330C
+#define EGL_YUV_CSC_STANDARD_2020_EXT 0x330D
+#define EGL_YUV_PLANE_BPP_0_EXT 0x331B
+#define EGL_YUV_PLANE_BPP_8_EXT 0x331C
+#define EGL_YUV_PLANE_BPP_10_EXT 0x331D
+#endif /* EGL_EXT_yuv_surface */
+
+#ifndef EGL_HI_clientpixmap
+#define EGL_HI_clientpixmap 1
+struct EGLClientPixmapHI {
+ void *pData;
+ EGLint iWidth;
+ EGLint iHeight;
+ EGLint iStride;
+};
+#define EGL_CLIENT_PIXMAP_POINTER_HI 0x8F74
+typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPIXMAPSURFACEHIPROC) (EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI *pixmap);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurfaceHI (EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI *pixmap);
+#endif
+#endif /* EGL_HI_clientpixmap */
+
+#ifndef EGL_HI_colorformats
+#define EGL_HI_colorformats 1
+#define EGL_COLOR_FORMAT_HI 0x8F70
+#define EGL_COLOR_RGB_HI 0x8F71
+#define EGL_COLOR_RGBA_HI 0x8F72
+#define EGL_COLOR_ARGB_HI 0x8F73
+#endif /* EGL_HI_colorformats */
+
+#ifndef EGL_IMG_context_priority
+#define EGL_IMG_context_priority 1
+#define EGL_CONTEXT_PRIORITY_LEVEL_IMG 0x3100
+#define EGL_CONTEXT_PRIORITY_HIGH_IMG 0x3101
+#define EGL_CONTEXT_PRIORITY_MEDIUM_IMG 0x3102
+#define EGL_CONTEXT_PRIORITY_LOW_IMG 0x3103
+#endif /* EGL_IMG_context_priority */
+
+#ifndef EGL_MESA_drm_image
+#define EGL_MESA_drm_image 1
+#define EGL_DRM_BUFFER_FORMAT_MESA 0x31D0
+#define EGL_DRM_BUFFER_USE_MESA 0x31D1
+#define EGL_DRM_BUFFER_FORMAT_ARGB32_MESA 0x31D2
+#define EGL_DRM_BUFFER_MESA 0x31D3
+#define EGL_DRM_BUFFER_STRIDE_MESA 0x31D4
+#define EGL_DRM_BUFFER_USE_SCANOUT_MESA 0x00000001
+#define EGL_DRM_BUFFER_USE_SHARE_MESA 0x00000002
+typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEDRMIMAGEMESAPROC) (EGLDisplay dpy, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDRMIMAGEMESAPROC) (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLImageKHR EGLAPIENTRY eglCreateDRMImageMESA (EGLDisplay dpy, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglExportDRMImageMESA (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride);
+#endif
+#endif /* EGL_MESA_drm_image */
+
+#ifndef EGL_MESA_image_dma_buf_export
+#define EGL_MESA_image_dma_buf_export 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDMABUFIMAGEQUERYMESAPROC) (EGLDisplay dpy, EGLImageKHR image, int *fourcc, int *num_planes, EGLuint64KHR *modifiers);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDMABUFIMAGEMESAPROC) (EGLDisplay dpy, EGLImageKHR image, int *fds, EGLint *strides, EGLint *offsets);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglExportDMABUFImageQueryMESA (EGLDisplay dpy, EGLImageKHR image, int *fourcc, int *num_planes, EGLuint64KHR *modifiers);
+EGLAPI EGLBoolean EGLAPIENTRY eglExportDMABUFImageMESA (EGLDisplay dpy, EGLImageKHR image, int *fds, EGLint *strides, EGLint *offsets);
+#endif
+#endif /* EGL_MESA_image_dma_buf_export */
+
+#ifndef EGL_MESA_platform_gbm
+#define EGL_MESA_platform_gbm 1
+#define EGL_PLATFORM_GBM_MESA 0x31D7
+#endif /* EGL_MESA_platform_gbm */
+
+#ifndef EGL_NOK_swap_region
+#define EGL_NOK_swap_region 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSREGIONNOKPROC) (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint *rects);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffersRegionNOK (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint *rects);
+#endif
+#endif /* EGL_NOK_swap_region */
+
+#ifndef EGL_NOK_swap_region2
+#define EGL_NOK_swap_region2 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSREGION2NOKPROC) (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint *rects);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffersRegion2NOK (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint *rects);
+#endif
+#endif /* EGL_NOK_swap_region2 */
+
+#ifndef EGL_NOK_texture_from_pixmap
+#define EGL_NOK_texture_from_pixmap 1
+#define EGL_Y_INVERTED_NOK 0x307F
+#endif /* EGL_NOK_texture_from_pixmap */
+
+#ifndef EGL_NV_3dvision_surface
+#define EGL_NV_3dvision_surface 1
+#define EGL_AUTO_STEREO_NV 0x3136
+#endif /* EGL_NV_3dvision_surface */
+
+#ifndef EGL_NV_coverage_sample
+#define EGL_NV_coverage_sample 1
+#define EGL_COVERAGE_BUFFERS_NV 0x30E0
+#define EGL_COVERAGE_SAMPLES_NV 0x30E1
+#endif /* EGL_NV_coverage_sample */
+
+#ifndef EGL_NV_coverage_sample_resolve
+#define EGL_NV_coverage_sample_resolve 1
+#define EGL_COVERAGE_SAMPLE_RESOLVE_NV 0x3131
+#define EGL_COVERAGE_SAMPLE_RESOLVE_DEFAULT_NV 0x3132
+#define EGL_COVERAGE_SAMPLE_RESOLVE_NONE_NV 0x3133
+#endif /* EGL_NV_coverage_sample_resolve */
+
+#ifndef EGL_NV_cuda_event
+#define EGL_NV_cuda_event 1
+#define EGL_CUDA_EVENT_HANDLE_NV 0x323B
+#define EGL_SYNC_CUDA_EVENT_NV 0x323C
+#define EGL_SYNC_CUDA_EVENT_COMPLETE_NV 0x323D
+#endif /* EGL_NV_cuda_event */
+
+#ifndef EGL_NV_depth_nonlinear
+#define EGL_NV_depth_nonlinear 1
+#define EGL_DEPTH_ENCODING_NV 0x30E2
+#define EGL_DEPTH_ENCODING_NONE_NV 0
+#define EGL_DEPTH_ENCODING_NONLINEAR_NV 0x30E3
+#endif /* EGL_NV_depth_nonlinear */
+
+#ifndef EGL_NV_device_cuda
+#define EGL_NV_device_cuda 1
+#define EGL_CUDA_DEVICE_NV 0x323A
+#endif /* EGL_NV_device_cuda */
+
+#ifndef EGL_NV_native_query
+#define EGL_NV_native_query 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYNATIVEDISPLAYNVPROC) (EGLDisplay dpy, EGLNativeDisplayType *display_id);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYNATIVEWINDOWNVPROC) (EGLDisplay dpy, EGLSurface surf, EGLNativeWindowType *window);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYNATIVEPIXMAPNVPROC) (EGLDisplay dpy, EGLSurface surf, EGLNativePixmapType *pixmap);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryNativeDisplayNV (EGLDisplay dpy, EGLNativeDisplayType *display_id);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryNativeWindowNV (EGLDisplay dpy, EGLSurface surf, EGLNativeWindowType *window);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryNativePixmapNV (EGLDisplay dpy, EGLSurface surf, EGLNativePixmapType *pixmap);
+#endif
+#endif /* EGL_NV_native_query */
+
+#ifndef EGL_NV_post_convert_rounding
+#define EGL_NV_post_convert_rounding 1
+#endif /* EGL_NV_post_convert_rounding */
+
+#ifndef EGL_NV_post_sub_buffer
+#define EGL_NV_post_sub_buffer 1
+#define EGL_POST_SUB_BUFFER_SUPPORTED_NV 0x30BE
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLPOSTSUBBUFFERNVPROC) (EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, EGLint width, EGLint height);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglPostSubBufferNV (EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, EGLint width, EGLint height);
+#endif
+#endif /* EGL_NV_post_sub_buffer */
+
+#ifndef EGL_NV_stream_sync
+#define EGL_NV_stream_sync 1
+#define EGL_SYNC_NEW_FRAME_NV 0x321F
+typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESTREAMSYNCNVPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum type, const EGLint *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateStreamSyncNV (EGLDisplay dpy, EGLStreamKHR stream, EGLenum type, const EGLint *attrib_list);
+#endif
+#endif /* EGL_NV_stream_sync */
+
+#ifndef EGL_NV_sync
+#define EGL_NV_sync 1
+typedef void *EGLSyncNV;
+typedef khronos_utime_nanoseconds_t EGLTimeNV;
+#ifdef KHRONOS_SUPPORT_INT64
+#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_NV 0x30E6
+#define EGL_SYNC_STATUS_NV 0x30E7
+#define EGL_SIGNALED_NV 0x30E8
+#define EGL_UNSIGNALED_NV 0x30E9
+#define EGL_SYNC_FLUSH_COMMANDS_BIT_NV 0x0001
+#define EGL_FOREVER_NV 0xFFFFFFFFFFFFFFFFull
+#define EGL_ALREADY_SIGNALED_NV 0x30EA
+#define EGL_TIMEOUT_EXPIRED_NV 0x30EB
+#define EGL_CONDITION_SATISFIED_NV 0x30EC
+#define EGL_SYNC_TYPE_NV 0x30ED
+#define EGL_SYNC_CONDITION_NV 0x30EE
+#define EGL_SYNC_FENCE_NV 0x30EF
+#define EGL_NO_SYNC_NV ((EGLSyncNV)0)
+typedef EGLSyncNV (EGLAPIENTRYP PFNEGLCREATEFENCESYNCNVPROC) (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCNVPROC) (EGLSyncNV sync);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLFENCENVPROC) (EGLSyncNV sync);
+typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCNVPROC) (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCNVPROC) (EGLSyncNV sync, EGLenum mode);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBNVPROC) (EGLSyncNV sync, EGLint attribute, EGLint *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSyncNV EGLAPIENTRY eglCreateFenceSyncNV (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncNV (EGLSyncNV sync);
+EGLAPI EGLBoolean EGLAPIENTRY eglFenceNV (EGLSyncNV sync);
+EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncNV (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout);
+EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncNV (EGLSyncNV sync, EGLenum mode);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribNV (EGLSyncNV sync, EGLint attribute, EGLint *value);
+#endif
+#endif /* KHRONOS_SUPPORT_INT64 */
+#endif /* EGL_NV_sync */
+
+#ifndef EGL_NV_system_time
+#define EGL_NV_system_time 1
+typedef khronos_utime_nanoseconds_t EGLuint64NV;
+#ifdef KHRONOS_SUPPORT_INT64
+typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMEFREQUENCYNVPROC) (void);
+typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMENVPROC) (void);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLuint64NV EGLAPIENTRY eglGetSystemTimeFrequencyNV (void);
+EGLAPI EGLuint64NV EGLAPIENTRY eglGetSystemTimeNV (void);
+#endif
+#endif /* KHRONOS_SUPPORT_INT64 */
+#endif /* EGL_NV_system_time */
+
+#ifndef EGL_TIZEN_image_native_buffer
+#define EGL_TIZEN_image_native_buffer 1
+#define EGL_NATIVE_BUFFER_TIZEN 0x32A0
+#endif /* EGL_TIZEN_image_native_buffer */
+
+#ifndef EGL_TIZEN_image_native_surface
+#define EGL_TIZEN_image_native_surface 1
+#define EGL_NATIVE_SURFACE_TIZEN 0x32A1
+#endif /* EGL_TIZEN_image_native_surface */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __eglext_h_ */
+
+
+#endif /* _MSC_VER */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_endian.h b/src/3rdparty/SDL2/include/SDL2/SDL_endian.h
new file mode 100644
index 0000000..ed0bf5b
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_endian.h
@@ -0,0 +1,260 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_endian.h
+ *
+ * Functions for reading and writing endian-specific values
+ */
+
+#ifndef SDL_endian_h_
+#define SDL_endian_h_
+
+#include "SDL_stdinc.h"
+
+/**
+ * \name The two types of endianness
+ */
+/* @{ */
+#define SDL_LIL_ENDIAN 1234
+#define SDL_BIG_ENDIAN 4321
+/* @} */
+
+#ifndef SDL_BYTEORDER /* Not defined in SDL_config.h? */
+#ifdef __linux__
+#include <endian.h>
+#define SDL_BYTEORDER __BYTE_ORDER
+#else /* __linux__ */
+#if defined(__hppa__) || \
+ defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
+ (defined(__MIPS__) && defined(__MISPEB__)) || \
+ defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \
+ defined(__sparc__)
+#define SDL_BYTEORDER SDL_BIG_ENDIAN
+#else
+#define SDL_BYTEORDER SDL_LIL_ENDIAN
+#endif
+#endif /* __linux__ */
+#endif /* !SDL_BYTEORDER */
+
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \file SDL_endian.h
+ */
+#if defined(__GNUC__) && defined(__i386__) && \
+ !(__GNUC__ == 2 && __GNUC_MINOR__ == 95 /* broken gcc version */)
+SDL_FORCE_INLINE Uint16
+SDL_Swap16(Uint16 x)
+{
+ __asm__("xchgb %b0,%h0": "=q"(x):"0"(x));
+ return x;
+}
+#elif defined(__GNUC__) && defined(__x86_64__)
+SDL_FORCE_INLINE Uint16
+SDL_Swap16(Uint16 x)
+{
+ __asm__("xchgb %b0,%h0": "=Q"(x):"0"(x));
+ return x;
+}
+#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
+SDL_FORCE_INLINE Uint16
+SDL_Swap16(Uint16 x)
+{
+ int result;
+
+ __asm__("rlwimi %0,%2,8,16,23": "=&r"(result):"0"(x >> 8), "r"(x));
+ return (Uint16)result;
+}
+#elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__)) && !defined(__mcoldfire__)
+SDL_FORCE_INLINE Uint16
+SDL_Swap16(Uint16 x)
+{
+ __asm__("rorw #8,%0": "=d"(x): "0"(x):"cc");
+ return x;
+}
+#elif defined(__WATCOMC__) && defined(__386__)
+extern _inline Uint16 SDL_Swap16(Uint16);
+#pragma aux SDL_Swap16 = \
+ "xchg al, ah" \
+ parm [ax] \
+ modify [ax];
+#else
+SDL_FORCE_INLINE Uint16
+SDL_Swap16(Uint16 x)
+{
+ return SDL_static_cast(Uint16, ((x << 8) | (x >> 8)));
+}
+#endif
+
+#if defined(__GNUC__) && defined(__i386__)
+SDL_FORCE_INLINE Uint32
+SDL_Swap32(Uint32 x)
+{
+ __asm__("bswap %0": "=r"(x):"0"(x));
+ return x;
+}
+#elif defined(__GNUC__) && defined(__x86_64__)
+SDL_FORCE_INLINE Uint32
+SDL_Swap32(Uint32 x)
+{
+ __asm__("bswapl %0": "=r"(x):"0"(x));
+ return x;
+}
+#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
+SDL_FORCE_INLINE Uint32
+SDL_Swap32(Uint32 x)
+{
+ Uint32 result;
+
+ __asm__("rlwimi %0,%2,24,16,23": "=&r"(result):"0"(x >> 24), "r"(x));
+ __asm__("rlwimi %0,%2,8,8,15": "=&r"(result):"0"(result), "r"(x));
+ __asm__("rlwimi %0,%2,24,0,7": "=&r"(result):"0"(result), "r"(x));
+ return result;
+}
+#elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__)) && !defined(__mcoldfire__)
+SDL_FORCE_INLINE Uint32
+SDL_Swap32(Uint32 x)
+{
+ __asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0": "=d"(x): "0"(x):"cc");
+ return x;
+}
+#elif defined(__WATCOMC__) && defined(__386__)
+extern _inline Uint32 SDL_Swap32(Uint32);
+#ifndef __SW_3 /* 486+ */
+#pragma aux SDL_Swap32 = \
+ "bswap eax" \
+ parm [eax] \
+ modify [eax];
+#else /* 386-only */
+#pragma aux SDL_Swap32 = \
+ "xchg al, ah" \
+ "ror eax, 16" \
+ "xchg al, ah" \
+ parm [eax] \
+ modify [eax];
+#endif
+#else
+SDL_FORCE_INLINE Uint32
+SDL_Swap32(Uint32 x)
+{
+ return SDL_static_cast(Uint32, ((x << 24) | ((x << 8) & 0x00FF0000) |
+ ((x >> 8) & 0x0000FF00) | (x >> 24)));
+}
+#endif
+
+#if defined(__GNUC__) && defined(__i386__)
+SDL_FORCE_INLINE Uint64
+SDL_Swap64(Uint64 x)
+{
+ union
+ {
+ struct
+ {
+ Uint32 a, b;
+ } s;
+ Uint64 u;
+ } v;
+ v.u = x;
+ __asm__("bswapl %0 ; bswapl %1 ; xchgl %0,%1": "=r"(v.s.a), "=r"(v.s.b):"0"(v.s.a),
+ "1"(v.s.
+ b));
+ return v.u;
+}
+#elif defined(__GNUC__) && defined(__x86_64__)
+SDL_FORCE_INLINE Uint64
+SDL_Swap64(Uint64 x)
+{
+ __asm__("bswapq %0": "=r"(x):"0"(x));
+ return x;
+}
+#else
+SDL_FORCE_INLINE Uint64
+SDL_Swap64(Uint64 x)
+{
+ Uint32 hi, lo;
+
+ /* Separate into high and low 32-bit values and swap them */
+ lo = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
+ x >>= 32;
+ hi = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
+ x = SDL_Swap32(lo);
+ x <<= 32;
+ x |= SDL_Swap32(hi);
+ return (x);
+}
+#endif
+
+
+SDL_FORCE_INLINE float
+SDL_SwapFloat(float x)
+{
+ union
+ {
+ float f;
+ Uint32 ui32;
+ } swapper;
+ swapper.f = x;
+ swapper.ui32 = SDL_Swap32(swapper.ui32);
+ return swapper.f;
+}
+
+
+/**
+ * \name Swap to native
+ * Byteswap item from the specified endianness to the native endianness.
+ */
+/* @{ */
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+#define SDL_SwapLE16(X) (X)
+#define SDL_SwapLE32(X) (X)
+#define SDL_SwapLE64(X) (X)
+#define SDL_SwapFloatLE(X) (X)
+#define SDL_SwapBE16(X) SDL_Swap16(X)
+#define SDL_SwapBE32(X) SDL_Swap32(X)
+#define SDL_SwapBE64(X) SDL_Swap64(X)
+#define SDL_SwapFloatBE(X) SDL_SwapFloat(X)
+#else
+#define SDL_SwapLE16(X) SDL_Swap16(X)
+#define SDL_SwapLE32(X) SDL_Swap32(X)
+#define SDL_SwapLE64(X) SDL_Swap64(X)
+#define SDL_SwapFloatLE(X) SDL_SwapFloat(X)
+#define SDL_SwapBE16(X) (X)
+#define SDL_SwapBE32(X) (X)
+#define SDL_SwapBE64(X) (X)
+#define SDL_SwapFloatBE(X) (X)
+#endif
+/* @} *//* Swap to native */
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_endian_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_error.h b/src/3rdparty/SDL2/include/SDL2/SDL_error.h
new file mode 100644
index 0000000..c0e4629
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_error.h
@@ -0,0 +1,76 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_error.h
+ *
+ * Simple error message routines for SDL.
+ */
+
+#ifndef SDL_error_h_
+#define SDL_error_h_
+
+#include "SDL_stdinc.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Public functions */
+/* SDL_SetError() unconditionally returns -1. */
+extern DECLSPEC int SDLCALL SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
+extern DECLSPEC const char *SDLCALL SDL_GetError(void);
+extern DECLSPEC void SDLCALL SDL_ClearError(void);
+
+/**
+ * \name Internal error functions
+ *
+ * \internal
+ * Private error reporting function - used internally.
+ */
+/* @{ */
+#define SDL_OutOfMemory() SDL_Error(SDL_ENOMEM)
+#define SDL_Unsupported() SDL_Error(SDL_UNSUPPORTED)
+#define SDL_InvalidParamError(param) SDL_SetError("Parameter '%s' is invalid", (param))
+typedef enum
+{
+ SDL_ENOMEM,
+ SDL_EFREAD,
+ SDL_EFWRITE,
+ SDL_EFSEEK,
+ SDL_UNSUPPORTED,
+ SDL_LASTERROR
+} SDL_errorcode;
+/* SDL_Error() unconditionally returns -1. */
+extern DECLSPEC int SDLCALL SDL_Error(SDL_errorcode code);
+/* @} *//* Internal error functions */
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_error_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_events.h b/src/3rdparty/SDL2/include/SDL2/SDL_events.h
new file mode 100644
index 0000000..3d39e6a
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_events.h
@@ -0,0 +1,754 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_events.h
+ *
+ * Include file for SDL event handling.
+ */
+
+#ifndef SDL_events_h_
+#define SDL_events_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_video.h"
+#include "SDL_keyboard.h"
+#include "SDL_mouse.h"
+#include "SDL_joystick.h"
+#include "SDL_gamecontroller.h"
+#include "SDL_quit.h"
+#include "SDL_gesture.h"
+#include "SDL_touch.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* General keyboard/mouse state definitions */
+#define SDL_RELEASED 0
+#define SDL_PRESSED 1
+
+/**
+ * \brief The types of events that can be delivered.
+ */
+typedef enum
+{
+ SDL_FIRSTEVENT = 0, /**< Unused (do not remove) */
+
+ /* Application events */
+ SDL_QUIT = 0x100, /**< User-requested quit */
+
+ /* These application events have special meaning on iOS, see README-ios.md for details */
+ SDL_APP_TERMINATING, /**< The application is being terminated by the OS
+ Called on iOS in applicationWillTerminate()
+ Called on Android in onDestroy()
+ */
+ SDL_APP_LOWMEMORY, /**< The application is low on memory, free memory if possible.
+ Called on iOS in applicationDidReceiveMemoryWarning()
+ Called on Android in onLowMemory()
+ */
+ SDL_APP_WILLENTERBACKGROUND, /**< The application is about to enter the background
+ Called on iOS in applicationWillResignActive()
+ Called on Android in onPause()
+ */
+ SDL_APP_DIDENTERBACKGROUND, /**< The application did enter the background and may not get CPU for some time
+ Called on iOS in applicationDidEnterBackground()
+ Called on Android in onPause()
+ */
+ SDL_APP_WILLENTERFOREGROUND, /**< The application is about to enter the foreground
+ Called on iOS in applicationWillEnterForeground()
+ Called on Android in onResume()
+ */
+ SDL_APP_DIDENTERFOREGROUND, /**< The application is now interactive
+ Called on iOS in applicationDidBecomeActive()
+ Called on Android in onResume()
+ */
+
+ /* Window events */
+ SDL_WINDOWEVENT = 0x200, /**< Window state change */
+ SDL_SYSWMEVENT, /**< System specific event */
+
+ /* Keyboard events */
+ SDL_KEYDOWN = 0x300, /**< Key pressed */
+ SDL_KEYUP, /**< Key released */
+ SDL_TEXTEDITING, /**< Keyboard text editing (composition) */
+ SDL_TEXTINPUT, /**< Keyboard text input */
+ SDL_KEYMAPCHANGED, /**< Keymap changed due to a system event such as an
+ input language or keyboard layout change.
+ */
+
+ /* Mouse events */
+ SDL_MOUSEMOTION = 0x400, /**< Mouse moved */
+ SDL_MOUSEBUTTONDOWN, /**< Mouse button pressed */
+ SDL_MOUSEBUTTONUP, /**< Mouse button released */
+ SDL_MOUSEWHEEL, /**< Mouse wheel motion */
+
+ /* Joystick events */
+ SDL_JOYAXISMOTION = 0x600, /**< Joystick axis motion */
+ SDL_JOYBALLMOTION, /**< Joystick trackball motion */
+ SDL_JOYHATMOTION, /**< Joystick hat position change */
+ SDL_JOYBUTTONDOWN, /**< Joystick button pressed */
+ SDL_JOYBUTTONUP, /**< Joystick button released */
+ SDL_JOYDEVICEADDED, /**< A new joystick has been inserted into the system */
+ SDL_JOYDEVICEREMOVED, /**< An opened joystick has been removed */
+
+ /* Game controller events */
+ SDL_CONTROLLERAXISMOTION = 0x650, /**< Game controller axis motion */
+ SDL_CONTROLLERBUTTONDOWN, /**< Game controller button pressed */
+ SDL_CONTROLLERBUTTONUP, /**< Game controller button released */
+ SDL_CONTROLLERDEVICEADDED, /**< A new Game controller has been inserted into the system */
+ SDL_CONTROLLERDEVICEREMOVED, /**< An opened Game controller has been removed */
+ SDL_CONTROLLERDEVICEREMAPPED, /**< The controller mapping was updated */
+
+ /* Touch events */
+ SDL_FINGERDOWN = 0x700,
+ SDL_FINGERUP,
+ SDL_FINGERMOTION,
+
+ /* Gesture events */
+ SDL_DOLLARGESTURE = 0x800,
+ SDL_DOLLARRECORD,
+ SDL_MULTIGESTURE,
+
+ /* Clipboard events */
+ SDL_CLIPBOARDUPDATE = 0x900, /**< The clipboard changed */
+
+ /* Drag and drop events */
+ SDL_DROPFILE = 0x1000, /**< The system requests a file open */
+ SDL_DROPTEXT, /**< text/plain drag-and-drop event */
+ SDL_DROPBEGIN, /**< A new set of drops is beginning (NULL filename) */
+ SDL_DROPCOMPLETE, /**< Current set of drops is now complete (NULL filename) */
+
+ /* Audio hotplug events */
+ SDL_AUDIODEVICEADDED = 0x1100, /**< A new audio device is available */
+ SDL_AUDIODEVICEREMOVED, /**< An audio device has been removed. */
+
+ /* Render events */
+ SDL_RENDER_TARGETS_RESET = 0x2000, /**< The render targets have been reset and their contents need to be updated */
+ SDL_RENDER_DEVICE_RESET, /**< The device has been reset and all textures need to be recreated */
+
+ /** Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use,
+ * and should be allocated with SDL_RegisterEvents()
+ */
+ SDL_USEREVENT = 0x8000,
+
+ /**
+ * This last event is only for bounding internal arrays
+ */
+ SDL_LASTEVENT = 0xFFFF
+} SDL_EventType;
+
+/**
+ * \brief Fields shared by every event
+ */
+typedef struct SDL_CommonEvent
+{
+ Uint32 type;
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+} SDL_CommonEvent;
+
+/**
+ * \brief Window state change event data (event.window.*)
+ */
+typedef struct SDL_WindowEvent
+{
+ Uint32 type; /**< ::SDL_WINDOWEVENT */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Uint32 windowID; /**< The associated window */
+ Uint8 event; /**< ::SDL_WindowEventID */
+ Uint8 padding1;
+ Uint8 padding2;
+ Uint8 padding3;
+ Sint32 data1; /**< event dependent data */
+ Sint32 data2; /**< event dependent data */
+} SDL_WindowEvent;
+
+/**
+ * \brief Keyboard button event structure (event.key.*)
+ */
+typedef struct SDL_KeyboardEvent
+{
+ Uint32 type; /**< ::SDL_KEYDOWN or ::SDL_KEYUP */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Uint32 windowID; /**< The window with keyboard focus, if any */
+ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
+ Uint8 repeat; /**< Non-zero if this is a key repeat */
+ Uint8 padding2;
+ Uint8 padding3;
+ SDL_Keysym keysym; /**< The key that was pressed or released */
+} SDL_KeyboardEvent;
+
+#define SDL_TEXTEDITINGEVENT_TEXT_SIZE (32)
+/**
+ * \brief Keyboard text editing event structure (event.edit.*)
+ */
+typedef struct SDL_TextEditingEvent
+{
+ Uint32 type; /**< ::SDL_TEXTEDITING */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Uint32 windowID; /**< The window with keyboard focus, if any */
+ char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE]; /**< The editing text */
+ Sint32 start; /**< The start cursor of selected editing text */
+ Sint32 length; /**< The length of selected editing text */
+} SDL_TextEditingEvent;
+
+
+#define SDL_TEXTINPUTEVENT_TEXT_SIZE (32)
+/**
+ * \brief Keyboard text input event structure (event.text.*)
+ */
+typedef struct SDL_TextInputEvent
+{
+ Uint32 type; /**< ::SDL_TEXTINPUT */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Uint32 windowID; /**< The window with keyboard focus, if any */
+ char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; /**< The input text */
+} SDL_TextInputEvent;
+
+/**
+ * \brief Mouse motion event structure (event.motion.*)
+ */
+typedef struct SDL_MouseMotionEvent
+{
+ Uint32 type; /**< ::SDL_MOUSEMOTION */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Uint32 windowID; /**< The window with mouse focus, if any */
+ Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
+ Uint32 state; /**< The current button state */
+ Sint32 x; /**< X coordinate, relative to window */
+ Sint32 y; /**< Y coordinate, relative to window */
+ Sint32 xrel; /**< The relative motion in the X direction */
+ Sint32 yrel; /**< The relative motion in the Y direction */
+} SDL_MouseMotionEvent;
+
+/**
+ * \brief Mouse button event structure (event.button.*)
+ */
+typedef struct SDL_MouseButtonEvent
+{
+ Uint32 type; /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Uint32 windowID; /**< The window with mouse focus, if any */
+ Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
+ Uint8 button; /**< The mouse button index */
+ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
+ Uint8 clicks; /**< 1 for single-click, 2 for double-click, etc. */
+ Uint8 padding1;
+ Sint32 x; /**< X coordinate, relative to window */
+ Sint32 y; /**< Y coordinate, relative to window */
+} SDL_MouseButtonEvent;
+
+/**
+ * \brief Mouse wheel event structure (event.wheel.*)
+ */
+typedef struct SDL_MouseWheelEvent
+{
+ Uint32 type; /**< ::SDL_MOUSEWHEEL */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Uint32 windowID; /**< The window with mouse focus, if any */
+ Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
+ Sint32 x; /**< The amount scrolled horizontally, positive to the right and negative to the left */
+ Sint32 y; /**< The amount scrolled vertically, positive away from the user and negative toward the user */
+ Uint32 direction; /**< Set to one of the SDL_MOUSEWHEEL_* defines. When FLIPPED the values in X and Y will be opposite. Multiply by -1 to change them back */
+} SDL_MouseWheelEvent;
+
+/**
+ * \brief Joystick axis motion event structure (event.jaxis.*)
+ */
+typedef struct SDL_JoyAxisEvent
+{
+ Uint32 type; /**< ::SDL_JOYAXISMOTION */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_JoystickID which; /**< The joystick instance id */
+ Uint8 axis; /**< The joystick axis index */
+ Uint8 padding1;
+ Uint8 padding2;
+ Uint8 padding3;
+ Sint16 value; /**< The axis value (range: -32768 to 32767) */
+ Uint16 padding4;
+} SDL_JoyAxisEvent;
+
+/**
+ * \brief Joystick trackball motion event structure (event.jball.*)
+ */
+typedef struct SDL_JoyBallEvent
+{
+ Uint32 type; /**< ::SDL_JOYBALLMOTION */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_JoystickID which; /**< The joystick instance id */
+ Uint8 ball; /**< The joystick trackball index */
+ Uint8 padding1;
+ Uint8 padding2;
+ Uint8 padding3;
+ Sint16 xrel; /**< The relative motion in the X direction */
+ Sint16 yrel; /**< The relative motion in the Y direction */
+} SDL_JoyBallEvent;
+
+/**
+ * \brief Joystick hat position change event structure (event.jhat.*)
+ */
+typedef struct SDL_JoyHatEvent
+{
+ Uint32 type; /**< ::SDL_JOYHATMOTION */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_JoystickID which; /**< The joystick instance id */
+ Uint8 hat; /**< The joystick hat index */
+ Uint8 value; /**< The hat position value.
+ * \sa ::SDL_HAT_LEFTUP ::SDL_HAT_UP ::SDL_HAT_RIGHTUP
+ * \sa ::SDL_HAT_LEFT ::SDL_HAT_CENTERED ::SDL_HAT_RIGHT
+ * \sa ::SDL_HAT_LEFTDOWN ::SDL_HAT_DOWN ::SDL_HAT_RIGHTDOWN
+ *
+ * Note that zero means the POV is centered.
+ */
+ Uint8 padding1;
+ Uint8 padding2;
+} SDL_JoyHatEvent;
+
+/**
+ * \brief Joystick button event structure (event.jbutton.*)
+ */
+typedef struct SDL_JoyButtonEvent
+{
+ Uint32 type; /**< ::SDL_JOYBUTTONDOWN or ::SDL_JOYBUTTONUP */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_JoystickID which; /**< The joystick instance id */
+ Uint8 button; /**< The joystick button index */
+ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
+ Uint8 padding1;
+ Uint8 padding2;
+} SDL_JoyButtonEvent;
+
+/**
+ * \brief Joystick device event structure (event.jdevice.*)
+ */
+typedef struct SDL_JoyDeviceEvent
+{
+ Uint32 type; /**< ::SDL_JOYDEVICEADDED or ::SDL_JOYDEVICEREMOVED */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Sint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED event */
+} SDL_JoyDeviceEvent;
+
+
+/**
+ * \brief Game controller axis motion event structure (event.caxis.*)
+ */
+typedef struct SDL_ControllerAxisEvent
+{
+ Uint32 type; /**< ::SDL_CONTROLLERAXISMOTION */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_JoystickID which; /**< The joystick instance id */
+ Uint8 axis; /**< The controller axis (SDL_GameControllerAxis) */
+ Uint8 padding1;
+ Uint8 padding2;
+ Uint8 padding3;
+ Sint16 value; /**< The axis value (range: -32768 to 32767) */
+ Uint16 padding4;
+} SDL_ControllerAxisEvent;
+
+
+/**
+ * \brief Game controller button event structure (event.cbutton.*)
+ */
+typedef struct SDL_ControllerButtonEvent
+{
+ Uint32 type; /**< ::SDL_CONTROLLERBUTTONDOWN or ::SDL_CONTROLLERBUTTONUP */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_JoystickID which; /**< The joystick instance id */
+ Uint8 button; /**< The controller button (SDL_GameControllerButton) */
+ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
+ Uint8 padding1;
+ Uint8 padding2;
+} SDL_ControllerButtonEvent;
+
+
+/**
+ * \brief Controller device event structure (event.cdevice.*)
+ */
+typedef struct SDL_ControllerDeviceEvent
+{
+ Uint32 type; /**< ::SDL_CONTROLLERDEVICEADDED, ::SDL_CONTROLLERDEVICEREMOVED, or ::SDL_CONTROLLERDEVICEREMAPPED */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Sint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED or REMAPPED event */
+} SDL_ControllerDeviceEvent;
+
+/**
+ * \brief Audio device event structure (event.adevice.*)
+ */
+typedef struct SDL_AudioDeviceEvent
+{
+ Uint32 type; /**< ::SDL_AUDIODEVICEADDED, or ::SDL_AUDIODEVICEREMOVED */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Uint32 which; /**< The audio device index for the ADDED event (valid until next SDL_GetNumAudioDevices() call), SDL_AudioDeviceID for the REMOVED event */
+ Uint8 iscapture; /**< zero if an output device, non-zero if a capture device. */
+ Uint8 padding1;
+ Uint8 padding2;
+ Uint8 padding3;
+} SDL_AudioDeviceEvent;
+
+
+/**
+ * \brief Touch finger event structure (event.tfinger.*)
+ */
+typedef struct SDL_TouchFingerEvent
+{
+ Uint32 type; /**< ::SDL_FINGERMOTION or ::SDL_FINGERDOWN or ::SDL_FINGERUP */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_TouchID touchId; /**< The touch device id */
+ SDL_FingerID fingerId;
+ float x; /**< Normalized in the range 0...1 */
+ float y; /**< Normalized in the range 0...1 */
+ float dx; /**< Normalized in the range -1...1 */
+ float dy; /**< Normalized in the range -1...1 */
+ float pressure; /**< Normalized in the range 0...1 */
+} SDL_TouchFingerEvent;
+
+
+/**
+ * \brief Multiple Finger Gesture Event (event.mgesture.*)
+ */
+typedef struct SDL_MultiGestureEvent
+{
+ Uint32 type; /**< ::SDL_MULTIGESTURE */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_TouchID touchId; /**< The touch device id */
+ float dTheta;
+ float dDist;
+ float x;
+ float y;
+ Uint16 numFingers;
+ Uint16 padding;
+} SDL_MultiGestureEvent;
+
+
+/**
+ * \brief Dollar Gesture Event (event.dgesture.*)
+ */
+typedef struct SDL_DollarGestureEvent
+{
+ Uint32 type; /**< ::SDL_DOLLARGESTURE or ::SDL_DOLLARRECORD */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_TouchID touchId; /**< The touch device id */
+ SDL_GestureID gestureId;
+ Uint32 numFingers;
+ float error;
+ float x; /**< Normalized center of gesture */
+ float y; /**< Normalized center of gesture */
+} SDL_DollarGestureEvent;
+
+
+/**
+ * \brief An event used to request a file open by the system (event.drop.*)
+ * This event is enabled by default, you can disable it with SDL_EventState().
+ * \note If this event is enabled, you must free the filename in the event.
+ */
+typedef struct SDL_DropEvent
+{
+ Uint32 type; /**< ::SDL_DROPBEGIN or ::SDL_DROPFILE or ::SDL_DROPTEXT or ::SDL_DROPCOMPLETE */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ char *file; /**< The file name, which should be freed with SDL_free(), is NULL on begin/complete */
+ Uint32 windowID; /**< The window that was dropped on, if any */
+} SDL_DropEvent;
+
+
+/**
+ * \brief The "quit requested" event
+ */
+typedef struct SDL_QuitEvent
+{
+ Uint32 type; /**< ::SDL_QUIT */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+} SDL_QuitEvent;
+
+/**
+ * \brief OS Specific event
+ */
+typedef struct SDL_OSEvent
+{
+ Uint32 type; /**< ::SDL_QUIT */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+} SDL_OSEvent;
+
+/**
+ * \brief A user-defined event type (event.user.*)
+ */
+typedef struct SDL_UserEvent
+{
+ Uint32 type; /**< ::SDL_USEREVENT through ::SDL_LASTEVENT-1 */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Uint32 windowID; /**< The associated window if any */
+ Sint32 code; /**< User defined event code */
+ void *data1; /**< User defined data pointer */
+ void *data2; /**< User defined data pointer */
+} SDL_UserEvent;
+
+
+struct SDL_SysWMmsg;
+typedef struct SDL_SysWMmsg SDL_SysWMmsg;
+
+/**
+ * \brief A video driver dependent system event (event.syswm.*)
+ * This event is disabled by default, you can enable it with SDL_EventState()
+ *
+ * \note If you want to use this event, you should include SDL_syswm.h.
+ */
+typedef struct SDL_SysWMEvent
+{
+ Uint32 type; /**< ::SDL_SYSWMEVENT */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_SysWMmsg *msg; /**< driver dependent data, defined in SDL_syswm.h */
+} SDL_SysWMEvent;
+
+/**
+ * \brief General event structure
+ */
+typedef union SDL_Event
+{
+ Uint32 type; /**< Event type, shared with all events */
+ SDL_CommonEvent common; /**< Common event data */
+ SDL_WindowEvent window; /**< Window event data */
+ SDL_KeyboardEvent key; /**< Keyboard event data */
+ SDL_TextEditingEvent edit; /**< Text editing event data */
+ SDL_TextInputEvent text; /**< Text input event data */
+ SDL_MouseMotionEvent motion; /**< Mouse motion event data */
+ SDL_MouseButtonEvent button; /**< Mouse button event data */
+ SDL_MouseWheelEvent wheel; /**< Mouse wheel event data */
+ SDL_JoyAxisEvent jaxis; /**< Joystick axis event data */
+ SDL_JoyBallEvent jball; /**< Joystick ball event data */
+ SDL_JoyHatEvent jhat; /**< Joystick hat event data */
+ SDL_JoyButtonEvent jbutton; /**< Joystick button event data */
+ SDL_JoyDeviceEvent jdevice; /**< Joystick device change event data */
+ SDL_ControllerAxisEvent caxis; /**< Game Controller axis event data */
+ SDL_ControllerButtonEvent cbutton; /**< Game Controller button event data */
+ SDL_ControllerDeviceEvent cdevice; /**< Game Controller device event data */
+ SDL_AudioDeviceEvent adevice; /**< Audio device event data */
+ SDL_QuitEvent quit; /**< Quit request event data */
+ SDL_UserEvent user; /**< Custom event data */
+ SDL_SysWMEvent syswm; /**< System dependent window event data */
+ SDL_TouchFingerEvent tfinger; /**< Touch finger event data */
+ SDL_MultiGestureEvent mgesture; /**< Gesture event data */
+ SDL_DollarGestureEvent dgesture; /**< Gesture event data */
+ SDL_DropEvent drop; /**< Drag and drop event data */
+
+ /* This is necessary for ABI compatibility between Visual C++ and GCC
+ Visual C++ will respect the push pack pragma and use 52 bytes for
+ this structure, and GCC will use the alignment of the largest datatype
+ within the union, which is 8 bytes.
+
+ So... we'll add padding to force the size to be 56 bytes for both.
+ */
+ Uint8 padding[56];
+} SDL_Event;
+
+
+/* Function prototypes */
+
+/**
+ * Pumps the event loop, gathering events from the input devices.
+ *
+ * This function updates the event queue and internal input device state.
+ *
+ * This should only be run in the thread that sets the video mode.
+ */
+extern DECLSPEC void SDLCALL SDL_PumpEvents(void);
+
+/* @{ */
+typedef enum
+{
+ SDL_ADDEVENT,
+ SDL_PEEKEVENT,
+ SDL_GETEVENT
+} SDL_eventaction;
+
+/**
+ * Checks the event queue for messages and optionally returns them.
+ *
+ * If \c action is ::SDL_ADDEVENT, up to \c numevents events will be added to
+ * the back of the event queue.
+ *
+ * If \c action is ::SDL_PEEKEVENT, up to \c numevents events at the front
+ * of the event queue, within the specified minimum and maximum type,
+ * will be returned and will not be removed from the queue.
+ *
+ * If \c action is ::SDL_GETEVENT, up to \c numevents events at the front
+ * of the event queue, within the specified minimum and maximum type,
+ * will be returned and will be removed from the queue.
+ *
+ * \return The number of events actually stored, or -1 if there was an error.
+ *
+ * This function is thread-safe.
+ */
+extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event * events, int numevents,
+ SDL_eventaction action,
+ Uint32 minType, Uint32 maxType);
+/* @} */
+
+/**
+ * Checks to see if certain event types are in the event queue.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasEvent(Uint32 type);
+extern DECLSPEC SDL_bool SDLCALL SDL_HasEvents(Uint32 minType, Uint32 maxType);
+
+/**
+ * This function clears events from the event queue
+ * This function only affects currently queued events. If you want to make
+ * sure that all pending OS events are flushed, you can call SDL_PumpEvents()
+ * on the main thread immediately before the flush call.
+ */
+extern DECLSPEC void SDLCALL SDL_FlushEvent(Uint32 type);
+extern DECLSPEC void SDLCALL SDL_FlushEvents(Uint32 minType, Uint32 maxType);
+
+/**
+ * \brief Polls for currently pending events.
+ *
+ * \return 1 if there are any pending events, or 0 if there are none available.
+ *
+ * \param event If not NULL, the next event is removed from the queue and
+ * stored in that area.
+ */
+extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event * event);
+
+/**
+ * \brief Waits indefinitely for the next available event.
+ *
+ * \return 1, or 0 if there was an error while waiting for events.
+ *
+ * \param event If not NULL, the next event is removed from the queue and
+ * stored in that area.
+ */
+extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event * event);
+
+/**
+ * \brief Waits until the specified timeout (in milliseconds) for the next
+ * available event.
+ *
+ * \return 1, or 0 if there was an error while waiting for events.
+ *
+ * \param event If not NULL, the next event is removed from the queue and
+ * stored in that area.
+ * \param timeout The timeout (in milliseconds) to wait for next event.
+ */
+extern DECLSPEC int SDLCALL SDL_WaitEventTimeout(SDL_Event * event,
+ int timeout);
+
+/**
+ * \brief Add an event to the event queue.
+ *
+ * \return 1 on success, 0 if the event was filtered, or -1 if the event queue
+ * was full or there was some other error.
+ */
+extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event * event);
+
+typedef int (SDLCALL * SDL_EventFilter) (void *userdata, SDL_Event * event);
+
+/**
+ * Sets up a filter to process all events before they change internal state and
+ * are posted to the internal event queue.
+ *
+ * The filter is prototyped as:
+ * \code
+ * int SDL_EventFilter(void *userdata, SDL_Event * event);
+ * \endcode
+ *
+ * If the filter returns 1, then the event will be added to the internal queue.
+ * If it returns 0, then the event will be dropped from the queue, but the
+ * internal state will still be updated. This allows selective filtering of
+ * dynamically arriving events.
+ *
+ * \warning Be very careful of what you do in the event filter function, as
+ * it may run in a different thread!
+ *
+ * There is one caveat when dealing with the ::SDL_QuitEvent event type. The
+ * event filter is only called when the window manager desires to close the
+ * application window. If the event filter returns 1, then the window will
+ * be closed, otherwise the window will remain open if possible.
+ *
+ * If the quit event is generated by an interrupt signal, it will bypass the
+ * internal queue and be delivered to the application at the next event poll.
+ */
+extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter,
+ void *userdata);
+
+/**
+ * Return the current event filter - can be used to "chain" filters.
+ * If there is no event filter set, this function returns SDL_FALSE.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_GetEventFilter(SDL_EventFilter * filter,
+ void **userdata);
+
+/**
+ * Add a function which is called when an event is added to the queue.
+ */
+extern DECLSPEC void SDLCALL SDL_AddEventWatch(SDL_EventFilter filter,
+ void *userdata);
+
+/**
+ * Remove an event watch function added with SDL_AddEventWatch()
+ */
+extern DECLSPEC void SDLCALL SDL_DelEventWatch(SDL_EventFilter filter,
+ void *userdata);
+
+/**
+ * Run the filter function on the current event queue, removing any
+ * events for which the filter returns 0.
+ */
+extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter,
+ void *userdata);
+
+/* @{ */
+#define SDL_QUERY -1
+#define SDL_IGNORE 0
+#define SDL_DISABLE 0
+#define SDL_ENABLE 1
+
+/**
+ * This function allows you to set the state of processing certain events.
+ * - If \c state is set to ::SDL_IGNORE, that event will be automatically
+ * dropped from the event queue and will not be filtered.
+ * - If \c state is set to ::SDL_ENABLE, that event will be processed
+ * normally.
+ * - If \c state is set to ::SDL_QUERY, SDL_EventState() will return the
+ * current processing state of the specified event.
+ */
+extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint32 type, int state);
+/* @} */
+#define SDL_GetEventState(type) SDL_EventState(type, SDL_QUERY)
+
+/**
+ * This function allocates a set of user-defined events, and returns
+ * the beginning event number for that set of events.
+ *
+ * If there aren't enough user-defined events left, this function
+ * returns (Uint32)-1
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_events_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_filesystem.h b/src/3rdparty/SDL2/include/SDL2/SDL_filesystem.h
new file mode 100644
index 0000000..fa6a1fa
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_filesystem.h
@@ -0,0 +1,136 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_filesystem.h
+ *
+ * \brief Include file for filesystem SDL API functions
+ */
+
+#ifndef SDL_filesystem_h_
+#define SDL_filesystem_h_
+
+#include "SDL_stdinc.h"
+
+#include "begin_code.h"
+
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Get the path where the application resides.
+ *
+ * Get the "base path". This is the directory where the application was run
+ * from, which is probably the installation directory, and may or may not
+ * be the process's current working directory.
+ *
+ * This returns an absolute path in UTF-8 encoding, and is guaranteed to
+ * end with a path separator ('\\' on Windows, '/' most other places).
+ *
+ * The pointer returned by this function is owned by you. Please call
+ * SDL_free() on the pointer when you are done with it, or it will be a
+ * memory leak. This is not necessarily a fast call, though, so you should
+ * call this once near startup and save the string if you need it.
+ *
+ * Some platforms can't determine the application's path, and on other
+ * platforms, this might be meaningless. In such cases, this function will
+ * return NULL.
+ *
+ * \return String of base dir in UTF-8 encoding, or NULL on error.
+ *
+ * \sa SDL_GetPrefPath
+ */
+extern DECLSPEC char *SDLCALL SDL_GetBasePath(void);
+
+/**
+ * \brief Get the user-and-app-specific path where files can be written.
+ *
+ * Get the "pref dir". This is meant to be where users can write personal
+ * files (preferences and save games, etc) that are specific to your
+ * application. This directory is unique per user, per application.
+ *
+ * This function will decide the appropriate location in the native filesystem,
+ * create the directory if necessary, and return a string of the absolute
+ * path to the directory in UTF-8 encoding.
+ *
+ * On Windows, the string might look like:
+ * "C:\\Users\\bob\\AppData\\Roaming\\My Company\\My Program Name\\"
+ *
+ * On Linux, the string might look like:
+ * "/home/bob/.local/share/My Program Name/"
+ *
+ * On Mac OS X, the string might look like:
+ * "/Users/bob/Library/Application Support/My Program Name/"
+ *
+ * (etc.)
+ *
+ * You specify the name of your organization (if it's not a real organization,
+ * your name or an Internet domain you own might do) and the name of your
+ * application. These should be untranslated proper names.
+ *
+ * Both the org and app strings may become part of a directory name, so
+ * please follow these rules:
+ *
+ * - Try to use the same org string (including case-sensitivity) for
+ * all your applications that use this function.
+ * - Always use a unique app string for each one, and make sure it never
+ * changes for an app once you've decided on it.
+ * - Unicode characters are legal, as long as it's UTF-8 encoded, but...
+ * - ...only use letters, numbers, and spaces. Avoid punctuation like
+ * "Game Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient.
+ *
+ * This returns an absolute path in UTF-8 encoding, and is guaranteed to
+ * end with a path separator ('\\' on Windows, '/' most other places).
+ *
+ * The pointer returned by this function is owned by you. Please call
+ * SDL_free() on the pointer when you are done with it, or it will be a
+ * memory leak. This is not necessarily a fast call, though, so you should
+ * call this once near startup and save the string if you need it.
+ *
+ * You should assume the path returned by this function is the only safe
+ * place to write files (and that SDL_GetBasePath(), while it might be
+ * writable, or even the parent of the returned path, aren't where you
+ * should be writing things).
+ *
+ * Some platforms can't determine the pref path, and on other
+ * platforms, this might be meaningless. In such cases, this function will
+ * return NULL.
+ *
+ * \param org The name of your organization.
+ * \param app The name of your application.
+ * \return UTF-8 string of user dir in platform-dependent notation. NULL
+ * if there's a problem (creating directory failed, etc).
+ *
+ * \sa SDL_GetBasePath
+ */
+extern DECLSPEC char *SDLCALL SDL_GetPrefPath(const char *org, const char *app);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_filesystem_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_gamecontroller.h b/src/3rdparty/SDL2/include/SDL2/SDL_gamecontroller.h
new file mode 100644
index 0000000..2e024be
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_gamecontroller.h
@@ -0,0 +1,362 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_gamecontroller.h
+ *
+ * Include file for SDL game controller event handling
+ */
+
+#ifndef SDL_gamecontroller_h_
+#define SDL_gamecontroller_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_rwops.h"
+#include "SDL_joystick.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \file SDL_gamecontroller.h
+ *
+ * In order to use these functions, SDL_Init() must have been called
+ * with the ::SDL_INIT_GAMECONTROLLER flag. This causes SDL to scan the system
+ * for game controllers, and load appropriate drivers.
+ *
+ * If you would like to receive controller updates while the application
+ * is in the background, you should set the following hint before calling
+ * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
+ */
+
+/**
+ * The gamecontroller structure used to identify an SDL game controller
+ */
+struct _SDL_GameController;
+typedef struct _SDL_GameController SDL_GameController;
+
+
+typedef enum
+{
+ SDL_CONTROLLER_BINDTYPE_NONE = 0,
+ SDL_CONTROLLER_BINDTYPE_BUTTON,
+ SDL_CONTROLLER_BINDTYPE_AXIS,
+ SDL_CONTROLLER_BINDTYPE_HAT
+} SDL_GameControllerBindType;
+
+/**
+ * Get the SDL joystick layer binding for this controller button/axis mapping
+ */
+typedef struct SDL_GameControllerButtonBind
+{
+ SDL_GameControllerBindType bindType;
+ union
+ {
+ int button;
+ int axis;
+ struct {
+ int hat;
+ int hat_mask;
+ } hat;
+ } value;
+
+} SDL_GameControllerButtonBind;
+
+
+/**
+ * To count the number of game controllers in the system for the following:
+ * int nJoysticks = SDL_NumJoysticks();
+ * int nGameControllers = 0;
+ * for (int i = 0; i < nJoysticks; i++) {
+ * if (SDL_IsGameController(i)) {
+ * nGameControllers++;
+ * }
+ * }
+ *
+ * Using the SDL_HINT_GAMECONTROLLERCONFIG hint or the SDL_GameControllerAddMapping() you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is:
+ * guid,name,mappings
+ *
+ * Where GUID is the string value from SDL_JoystickGetGUIDString(), name is the human readable string for the device and mappings are controller mappings to joystick ones.
+ * Under Windows there is a reserved GUID of "xinput" that covers any XInput devices.
+ * The mapping format for joystick is:
+ * bX - a joystick button, index X
+ * hX.Y - hat X with value Y
+ * aX - axis X of the joystick
+ * Buttons can be used as a controller axis and vice versa.
+ *
+ * This string shows an example of a valid mapping for a controller
+ * "03000000341a00003608000000000000,PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7",
+ *
+ */
+
+/**
+ * Load a set of mappings from a seekable SDL data stream (memory or file), filtered by the current SDL_GetPlatform()
+ * A community sourced database of controllers is available at https://raw.github.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt
+ *
+ * If \c freerw is non-zero, the stream will be closed after being read.
+ *
+ * \return number of mappings added, -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_GameControllerAddMappingsFromRW(SDL_RWops * rw, int freerw);
+
+/**
+ * Load a set of mappings from a file, filtered by the current SDL_GetPlatform()
+ *
+ * Convenience macro.
+ */
+#define SDL_GameControllerAddMappingsFromFile(file) SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile(file, "rb"), 1)
+
+/**
+ * Add or update an existing mapping configuration
+ *
+ * \return 1 if mapping is added, 0 if updated, -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_GameControllerAddMapping(const char* mappingString);
+
+/**
+ * Get the number of mappings installed
+ *
+ * \return the number of mappings
+ */
+extern DECLSPEC int SDLCALL SDL_GameControllerNumMappings(void);
+
+/**
+ * Get the mapping at a particular index.
+ *
+ * \return the mapping string. Must be freed with SDL_free(). Returns NULL if the index is out of range.
+ */
+extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForIndex(int mapping_index);
+
+/**
+ * Get a mapping string for a GUID
+ *
+ * \return the mapping string. Must be freed with SDL_free(). Returns NULL if no mapping is available
+ */
+extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid);
+
+/**
+ * Get a mapping string for an open GameController
+ *
+ * \return the mapping string. Must be freed with SDL_free(). Returns NULL if no mapping is available
+ */
+extern DECLSPEC char * SDLCALL SDL_GameControllerMapping(SDL_GameController * gamecontroller);
+
+/**
+ * Is the joystick on this index supported by the game controller interface?
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_IsGameController(int joystick_index);
+
+/**
+ * Get the implementation dependent name of a game controller.
+ * This can be called before any controllers are opened.
+ * If no name can be found, this function returns NULL.
+ */
+extern DECLSPEC const char *SDLCALL SDL_GameControllerNameForIndex(int joystick_index);
+
+/**
+ * Open a game controller for use.
+ * The index passed as an argument refers to the N'th game controller on the system.
+ * This index is not the value which will identify this controller in future
+ * controller events. The joystick's instance id (::SDL_JoystickID) will be
+ * used there instead.
+ *
+ * \return A controller identifier, or NULL if an error occurred.
+ */
+extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerOpen(int joystick_index);
+
+/**
+ * Return the SDL_GameController associated with an instance id.
+ */
+extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromInstanceID(SDL_JoystickID joyid);
+
+/**
+ * Return the name for this currently opened controller
+ */
+extern DECLSPEC const char *SDLCALL SDL_GameControllerName(SDL_GameController *gamecontroller);
+
+/**
+ * Get the USB vendor ID of an opened controller, if available.
+ * If the vendor ID isn't available this function returns 0.
+ */
+extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetVendor(SDL_GameController * gamecontroller);
+
+/**
+ * Get the USB product ID of an opened controller, if available.
+ * If the product ID isn't available this function returns 0.
+ */
+extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProduct(SDL_GameController * gamecontroller);
+
+/**
+ * Get the product version of an opened controller, if available.
+ * If the product version isn't available this function returns 0.
+ */
+extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProductVersion(SDL_GameController * gamecontroller);
+
+/**
+ * Returns SDL_TRUE if the controller has been opened and currently connected,
+ * or SDL_FALSE if it has not.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerGetAttached(SDL_GameController *gamecontroller);
+
+/**
+ * Get the underlying joystick object used by a controller
+ */
+extern DECLSPEC SDL_Joystick *SDLCALL SDL_GameControllerGetJoystick(SDL_GameController *gamecontroller);
+
+/**
+ * Enable/disable controller event polling.
+ *
+ * If controller events are disabled, you must call SDL_GameControllerUpdate()
+ * yourself and check the state of the controller when you want controller
+ * information.
+ *
+ * The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE.
+ */
+extern DECLSPEC int SDLCALL SDL_GameControllerEventState(int state);
+
+/**
+ * Update the current state of the open game controllers.
+ *
+ * This is called automatically by the event loop if any game controller
+ * events are enabled.
+ */
+extern DECLSPEC void SDLCALL SDL_GameControllerUpdate(void);
+
+
+/**
+ * The list of axes available from a controller
+ *
+ * Thumbstick axis values range from SDL_JOYSTICK_AXIS_MIN to SDL_JOYSTICK_AXIS_MAX,
+ * and are centered within ~8000 of zero, though advanced UI will allow users to set
+ * or autodetect the dead zone, which varies between controllers.
+ *
+ * Trigger axis values range from 0 to SDL_JOYSTICK_AXIS_MAX.
+ */
+typedef enum
+{
+ SDL_CONTROLLER_AXIS_INVALID = -1,
+ SDL_CONTROLLER_AXIS_LEFTX,
+ SDL_CONTROLLER_AXIS_LEFTY,
+ SDL_CONTROLLER_AXIS_RIGHTX,
+ SDL_CONTROLLER_AXIS_RIGHTY,
+ SDL_CONTROLLER_AXIS_TRIGGERLEFT,
+ SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
+ SDL_CONTROLLER_AXIS_MAX
+} SDL_GameControllerAxis;
+
+/**
+ * turn this string into a axis mapping
+ */
+extern DECLSPEC SDL_GameControllerAxis SDLCALL SDL_GameControllerGetAxisFromString(const char *pchString);
+
+/**
+ * turn this axis enum into a string mapping
+ */
+extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis);
+
+/**
+ * Get the SDL joystick layer binding for this controller button mapping
+ */
+extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
+SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller,
+ SDL_GameControllerAxis axis);
+
+/**
+ * Get the current state of an axis control on a game controller.
+ *
+ * The state is a value ranging from -32768 to 32767 (except for the triggers,
+ * which range from 0 to 32767).
+ *
+ * The axis indices start at index 0.
+ */
+extern DECLSPEC Sint16 SDLCALL
+SDL_GameControllerGetAxis(SDL_GameController *gamecontroller,
+ SDL_GameControllerAxis axis);
+
+/**
+ * The list of buttons available from a controller
+ */
+typedef enum
+{
+ SDL_CONTROLLER_BUTTON_INVALID = -1,
+ SDL_CONTROLLER_BUTTON_A,
+ SDL_CONTROLLER_BUTTON_B,
+ SDL_CONTROLLER_BUTTON_X,
+ SDL_CONTROLLER_BUTTON_Y,
+ SDL_CONTROLLER_BUTTON_BACK,
+ SDL_CONTROLLER_BUTTON_GUIDE,
+ SDL_CONTROLLER_BUTTON_START,
+ SDL_CONTROLLER_BUTTON_LEFTSTICK,
+ SDL_CONTROLLER_BUTTON_RIGHTSTICK,
+ SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
+ SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
+ SDL_CONTROLLER_BUTTON_DPAD_UP,
+ SDL_CONTROLLER_BUTTON_DPAD_DOWN,
+ SDL_CONTROLLER_BUTTON_DPAD_LEFT,
+ SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
+ SDL_CONTROLLER_BUTTON_MAX
+} SDL_GameControllerButton;
+
+/**
+ * turn this string into a button mapping
+ */
+extern DECLSPEC SDL_GameControllerButton SDLCALL SDL_GameControllerGetButtonFromString(const char *pchString);
+
+/**
+ * turn this button enum into a string mapping
+ */
+extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForButton(SDL_GameControllerButton button);
+
+/**
+ * Get the SDL joystick layer binding for this controller button mapping
+ */
+extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
+SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller,
+ SDL_GameControllerButton button);
+
+
+/**
+ * Get the current state of a button on a game controller.
+ *
+ * The button indices start at index 0.
+ */
+extern DECLSPEC Uint8 SDLCALL SDL_GameControllerGetButton(SDL_GameController *gamecontroller,
+ SDL_GameControllerButton button);
+
+/**
+ * Close a controller previously opened with SDL_GameControllerOpen().
+ */
+extern DECLSPEC void SDLCALL SDL_GameControllerClose(SDL_GameController *gamecontroller);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_gamecontroller_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_gesture.h b/src/3rdparty/SDL2/include/SDL2/SDL_gesture.h
new file mode 100644
index 0000000..b223d80
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_gesture.h
@@ -0,0 +1,87 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_gesture.h
+ *
+ * Include file for SDL gesture event handling.
+ */
+
+#ifndef SDL_gesture_h_
+#define SDL_gesture_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_video.h"
+
+#include "SDL_touch.h"
+
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef Sint64 SDL_GestureID;
+
+/* Function prototypes */
+
+/**
+ * \brief Begin Recording a gesture on the specified touch, or all touches (-1)
+ *
+ *
+ */
+extern DECLSPEC int SDLCALL SDL_RecordGesture(SDL_TouchID touchId);
+
+
+/**
+ * \brief Save all currently loaded Dollar Gesture templates
+ *
+ *
+ */
+extern DECLSPEC int SDLCALL SDL_SaveAllDollarTemplates(SDL_RWops *dst);
+
+/**
+ * \brief Save a currently loaded Dollar Gesture template
+ *
+ *
+ */
+extern DECLSPEC int SDLCALL SDL_SaveDollarTemplate(SDL_GestureID gestureId,SDL_RWops *dst);
+
+
+/**
+ * \brief Load Dollar Gesture templates from a file
+ *
+ *
+ */
+extern DECLSPEC int SDLCALL SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_gesture_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_haptic.h b/src/3rdparty/SDL2/include/SDL2/SDL_haptic.h
new file mode 100644
index 0000000..e3a2bca
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_haptic.h
@@ -0,0 +1,1227 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_haptic.h
+ *
+ * \brief The SDL haptic subsystem allows you to control haptic (force feedback)
+ * devices.
+ *
+ * The basic usage is as follows:
+ * - Initialize the subsystem (::SDL_INIT_HAPTIC).
+ * - Open a haptic device.
+ * - SDL_HapticOpen() to open from index.
+ * - SDL_HapticOpenFromJoystick() to open from an existing joystick.
+ * - Create an effect (::SDL_HapticEffect).
+ * - Upload the effect with SDL_HapticNewEffect().
+ * - Run the effect with SDL_HapticRunEffect().
+ * - (optional) Free the effect with SDL_HapticDestroyEffect().
+ * - Close the haptic device with SDL_HapticClose().
+ *
+ * \par Simple rumble example:
+ * \code
+ * SDL_Haptic *haptic;
+ *
+ * // Open the device
+ * haptic = SDL_HapticOpen( 0 );
+ * if (haptic == NULL)
+ * return -1;
+ *
+ * // Initialize simple rumble
+ * if (SDL_HapticRumbleInit( haptic ) != 0)
+ * return -1;
+ *
+ * // Play effect at 50% strength for 2 seconds
+ * if (SDL_HapticRumblePlay( haptic, 0.5, 2000 ) != 0)
+ * return -1;
+ * SDL_Delay( 2000 );
+ *
+ * // Clean up
+ * SDL_HapticClose( haptic );
+ * \endcode
+ *
+ * \par Complete example:
+ * \code
+ * int test_haptic( SDL_Joystick * joystick ) {
+ * SDL_Haptic *haptic;
+ * SDL_HapticEffect effect;
+ * int effect_id;
+ *
+ * // Open the device
+ * haptic = SDL_HapticOpenFromJoystick( joystick );
+ * if (haptic == NULL) return -1; // Most likely joystick isn't haptic
+ *
+ * // See if it can do sine waves
+ * if ((SDL_HapticQuery(haptic) & SDL_HAPTIC_SINE)==0) {
+ * SDL_HapticClose(haptic); // No sine effect
+ * return -1;
+ * }
+ *
+ * // Create the effect
+ * memset( &effect, 0, sizeof(SDL_HapticEffect) ); // 0 is safe default
+ * effect.type = SDL_HAPTIC_SINE;
+ * effect.periodic.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates
+ * effect.periodic.direction.dir[0] = 18000; // Force comes from south
+ * effect.periodic.period = 1000; // 1000 ms
+ * effect.periodic.magnitude = 20000; // 20000/32767 strength
+ * effect.periodic.length = 5000; // 5 seconds long
+ * effect.periodic.attack_length = 1000; // Takes 1 second to get max strength
+ * effect.periodic.fade_length = 1000; // Takes 1 second to fade away
+ *
+ * // Upload the effect
+ * effect_id = SDL_HapticNewEffect( haptic, &effect );
+ *
+ * // Test the effect
+ * SDL_HapticRunEffect( haptic, effect_id, 1 );
+ * SDL_Delay( 5000); // Wait for the effect to finish
+ *
+ * // We destroy the effect, although closing the device also does this
+ * SDL_HapticDestroyEffect( haptic, effect_id );
+ *
+ * // Close the device
+ * SDL_HapticClose(haptic);
+ *
+ * return 0; // Success
+ * }
+ * \endcode
+ */
+
+#ifndef SDL_haptic_h_
+#define SDL_haptic_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_joystick.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * \typedef SDL_Haptic
+ *
+ * \brief The haptic structure used to identify an SDL haptic.
+ *
+ * \sa SDL_HapticOpen
+ * \sa SDL_HapticOpenFromJoystick
+ * \sa SDL_HapticClose
+ */
+struct _SDL_Haptic;
+typedef struct _SDL_Haptic SDL_Haptic;
+
+
+/**
+ * \name Haptic features
+ *
+ * Different haptic features a device can have.
+ */
+/* @{ */
+
+/**
+ * \name Haptic effects
+ */
+/* @{ */
+
+/**
+ * \brief Constant effect supported.
+ *
+ * Constant haptic effect.
+ *
+ * \sa SDL_HapticCondition
+ */
+#define SDL_HAPTIC_CONSTANT (1u<<0)
+
+/**
+ * \brief Sine wave effect supported.
+ *
+ * Periodic haptic effect that simulates sine waves.
+ *
+ * \sa SDL_HapticPeriodic
+ */
+#define SDL_HAPTIC_SINE (1u<<1)
+
+/**
+ * \brief Left/Right effect supported.
+ *
+ * Haptic effect for direct control over high/low frequency motors.
+ *
+ * \sa SDL_HapticLeftRight
+ * \warning this value was SDL_HAPTIC_SQUARE right before 2.0.0 shipped. Sorry,
+ * we ran out of bits, and this is important for XInput devices.
+ */
+#define SDL_HAPTIC_LEFTRIGHT (1u<<2)
+
+/* !!! FIXME: put this back when we have more bits in 2.1 */
+/* #define SDL_HAPTIC_SQUARE (1<<2) */
+
+/**
+ * \brief Triangle wave effect supported.
+ *
+ * Periodic haptic effect that simulates triangular waves.
+ *
+ * \sa SDL_HapticPeriodic
+ */
+#define SDL_HAPTIC_TRIANGLE (1u<<3)
+
+/**
+ * \brief Sawtoothup wave effect supported.
+ *
+ * Periodic haptic effect that simulates saw tooth up waves.
+ *
+ * \sa SDL_HapticPeriodic
+ */
+#define SDL_HAPTIC_SAWTOOTHUP (1u<<4)
+
+/**
+ * \brief Sawtoothdown wave effect supported.
+ *
+ * Periodic haptic effect that simulates saw tooth down waves.
+ *
+ * \sa SDL_HapticPeriodic
+ */
+#define SDL_HAPTIC_SAWTOOTHDOWN (1u<<5)
+
+/**
+ * \brief Ramp effect supported.
+ *
+ * Ramp haptic effect.
+ *
+ * \sa SDL_HapticRamp
+ */
+#define SDL_HAPTIC_RAMP (1u<<6)
+
+/**
+ * \brief Spring effect supported - uses axes position.
+ *
+ * Condition haptic effect that simulates a spring. Effect is based on the
+ * axes position.
+ *
+ * \sa SDL_HapticCondition
+ */
+#define SDL_HAPTIC_SPRING (1u<<7)
+
+/**
+ * \brief Damper effect supported - uses axes velocity.
+ *
+ * Condition haptic effect that simulates dampening. Effect is based on the
+ * axes velocity.
+ *
+ * \sa SDL_HapticCondition
+ */
+#define SDL_HAPTIC_DAMPER (1u<<8)
+
+/**
+ * \brief Inertia effect supported - uses axes acceleration.
+ *
+ * Condition haptic effect that simulates inertia. Effect is based on the axes
+ * acceleration.
+ *
+ * \sa SDL_HapticCondition
+ */
+#define SDL_HAPTIC_INERTIA (1u<<9)
+
+/**
+ * \brief Friction effect supported - uses axes movement.
+ *
+ * Condition haptic effect that simulates friction. Effect is based on the
+ * axes movement.
+ *
+ * \sa SDL_HapticCondition
+ */
+#define SDL_HAPTIC_FRICTION (1u<<10)
+
+/**
+ * \brief Custom effect is supported.
+ *
+ * User defined custom haptic effect.
+ */
+#define SDL_HAPTIC_CUSTOM (1u<<11)
+
+/* @} *//* Haptic effects */
+
+/* These last few are features the device has, not effects */
+
+/**
+ * \brief Device can set global gain.
+ *
+ * Device supports setting the global gain.
+ *
+ * \sa SDL_HapticSetGain
+ */
+#define SDL_HAPTIC_GAIN (1u<<12)
+
+/**
+ * \brief Device can set autocenter.
+ *
+ * Device supports setting autocenter.
+ *
+ * \sa SDL_HapticSetAutocenter
+ */
+#define SDL_HAPTIC_AUTOCENTER (1u<<13)
+
+/**
+ * \brief Device can be queried for effect status.
+ *
+ * Device supports querying effect status.
+ *
+ * \sa SDL_HapticGetEffectStatus
+ */
+#define SDL_HAPTIC_STATUS (1u<<14)
+
+/**
+ * \brief Device can be paused.
+ *
+ * Devices supports being paused.
+ *
+ * \sa SDL_HapticPause
+ * \sa SDL_HapticUnpause
+ */
+#define SDL_HAPTIC_PAUSE (1u<<15)
+
+
+/**
+ * \name Direction encodings
+ */
+/* @{ */
+
+/**
+ * \brief Uses polar coordinates for the direction.
+ *
+ * \sa SDL_HapticDirection
+ */
+#define SDL_HAPTIC_POLAR 0
+
+/**
+ * \brief Uses cartesian coordinates for the direction.
+ *
+ * \sa SDL_HapticDirection
+ */
+#define SDL_HAPTIC_CARTESIAN 1
+
+/**
+ * \brief Uses spherical coordinates for the direction.
+ *
+ * \sa SDL_HapticDirection
+ */
+#define SDL_HAPTIC_SPHERICAL 2
+
+/* @} *//* Direction encodings */
+
+/* @} *//* Haptic features */
+
+/*
+ * Misc defines.
+ */
+
+/**
+ * \brief Used to play a device an infinite number of times.
+ *
+ * \sa SDL_HapticRunEffect
+ */
+#define SDL_HAPTIC_INFINITY 4294967295U
+
+
+/**
+ * \brief Structure that represents a haptic direction.
+ *
+ * This is the direction where the force comes from,
+ * instead of the direction in which the force is exerted.
+ *
+ * Directions can be specified by:
+ * - ::SDL_HAPTIC_POLAR : Specified by polar coordinates.
+ * - ::SDL_HAPTIC_CARTESIAN : Specified by cartesian coordinates.
+ * - ::SDL_HAPTIC_SPHERICAL : Specified by spherical coordinates.
+ *
+ * Cardinal directions of the haptic device are relative to the positioning
+ * of the device. North is considered to be away from the user.
+ *
+ * The following diagram represents the cardinal directions:
+ * \verbatim
+ .--.
+ |__| .-------.
+ |=.| |.-----.|
+ |--| || ||
+ | | |'-----'|
+ |__|~')_____('
+ [ COMPUTER ]
+
+
+ North (0,-1)
+ ^
+ |
+ |
+ (-1,0) West <----[ HAPTIC ]----> East (1,0)
+ |
+ |
+ v
+ South (0,1)
+
+
+ [ USER ]
+ \|||/
+ (o o)
+ ---ooO-(_)-Ooo---
+ \endverbatim
+ *
+ * If type is ::SDL_HAPTIC_POLAR, direction is encoded by hundredths of a
+ * degree starting north and turning clockwise. ::SDL_HAPTIC_POLAR only uses
+ * the first \c dir parameter. The cardinal directions would be:
+ * - North: 0 (0 degrees)
+ * - East: 9000 (90 degrees)
+ * - South: 18000 (180 degrees)
+ * - West: 27000 (270 degrees)
+ *
+ * If type is ::SDL_HAPTIC_CARTESIAN, direction is encoded by three positions
+ * (X axis, Y axis and Z axis (with 3 axes)). ::SDL_HAPTIC_CARTESIAN uses
+ * the first three \c dir parameters. The cardinal directions would be:
+ * - North: 0,-1, 0
+ * - East: 1, 0, 0
+ * - South: 0, 1, 0
+ * - West: -1, 0, 0
+ *
+ * The Z axis represents the height of the effect if supported, otherwise
+ * it's unused. In cartesian encoding (1, 2) would be the same as (2, 4), you
+ * can use any multiple you want, only the direction matters.
+ *
+ * If type is ::SDL_HAPTIC_SPHERICAL, direction is encoded by two rotations.
+ * The first two \c dir parameters are used. The \c dir parameters are as
+ * follows (all values are in hundredths of degrees):
+ * - Degrees from (1, 0) rotated towards (0, 1).
+ * - Degrees towards (0, 0, 1) (device needs at least 3 axes).
+ *
+ *
+ * Example of force coming from the south with all encodings (force coming
+ * from the south means the user will have to pull the stick to counteract):
+ * \code
+ * SDL_HapticDirection direction;
+ *
+ * // Cartesian directions
+ * direction.type = SDL_HAPTIC_CARTESIAN; // Using cartesian direction encoding.
+ * direction.dir[0] = 0; // X position
+ * direction.dir[1] = 1; // Y position
+ * // Assuming the device has 2 axes, we don't need to specify third parameter.
+ *
+ * // Polar directions
+ * direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding.
+ * direction.dir[0] = 18000; // Polar only uses first parameter
+ *
+ * // Spherical coordinates
+ * direction.type = SDL_HAPTIC_SPHERICAL; // Spherical encoding
+ * direction.dir[0] = 9000; // Since we only have two axes we don't need more parameters.
+ * \endcode
+ *
+ * \sa SDL_HAPTIC_POLAR
+ * \sa SDL_HAPTIC_CARTESIAN
+ * \sa SDL_HAPTIC_SPHERICAL
+ * \sa SDL_HapticEffect
+ * \sa SDL_HapticNumAxes
+ */
+typedef struct SDL_HapticDirection
+{
+ Uint8 type; /**< The type of encoding. */
+ Sint32 dir[3]; /**< The encoded direction. */
+} SDL_HapticDirection;
+
+
+/**
+ * \brief A structure containing a template for a Constant effect.
+ *
+ * This struct is exclusively for the ::SDL_HAPTIC_CONSTANT effect.
+ *
+ * A constant effect applies a constant force in the specified direction
+ * to the joystick.
+ *
+ * \sa SDL_HAPTIC_CONSTANT
+ * \sa SDL_HapticEffect
+ */
+typedef struct SDL_HapticConstant
+{
+ /* Header */
+ Uint16 type; /**< ::SDL_HAPTIC_CONSTANT */
+ SDL_HapticDirection direction; /**< Direction of the effect. */
+
+ /* Replay */
+ Uint32 length; /**< Duration of the effect. */
+ Uint16 delay; /**< Delay before starting the effect. */
+
+ /* Trigger */
+ Uint16 button; /**< Button that triggers the effect. */
+ Uint16 interval; /**< How soon it can be triggered again after button. */
+
+ /* Constant */
+ Sint16 level; /**< Strength of the constant effect. */
+
+ /* Envelope */
+ Uint16 attack_length; /**< Duration of the attack. */
+ Uint16 attack_level; /**< Level at the start of the attack. */
+ Uint16 fade_length; /**< Duration of the fade. */
+ Uint16 fade_level; /**< Level at the end of the fade. */
+} SDL_HapticConstant;
+
+/**
+ * \brief A structure containing a template for a Periodic effect.
+ *
+ * The struct handles the following effects:
+ * - ::SDL_HAPTIC_SINE
+ * - ::SDL_HAPTIC_LEFTRIGHT
+ * - ::SDL_HAPTIC_TRIANGLE
+ * - ::SDL_HAPTIC_SAWTOOTHUP
+ * - ::SDL_HAPTIC_SAWTOOTHDOWN
+ *
+ * A periodic effect consists in a wave-shaped effect that repeats itself
+ * over time. The type determines the shape of the wave and the parameters
+ * determine the dimensions of the wave.
+ *
+ * Phase is given by hundredth of a degree meaning that giving the phase a value
+ * of 9000 will displace it 25% of its period. Here are sample values:
+ * - 0: No phase displacement.
+ * - 9000: Displaced 25% of its period.
+ * - 18000: Displaced 50% of its period.
+ * - 27000: Displaced 75% of its period.
+ * - 36000: Displaced 100% of its period, same as 0, but 0 is preferred.
+ *
+ * Examples:
+ * \verbatim
+ SDL_HAPTIC_SINE
+ __ __ __ __
+ / \ / \ / \ /
+ / \__/ \__/ \__/
+
+ SDL_HAPTIC_SQUARE
+ __ __ __ __ __
+ | | | | | | | | | |
+ | |__| |__| |__| |__| |
+
+ SDL_HAPTIC_TRIANGLE
+ /\ /\ /\ /\ /\
+ / \ / \ / \ / \ /
+ / \/ \/ \/ \/
+
+ SDL_HAPTIC_SAWTOOTHUP
+ /| /| /| /| /| /| /|
+ / | / | / | / | / | / | / |
+ / |/ |/ |/ |/ |/ |/ |
+
+ SDL_HAPTIC_SAWTOOTHDOWN
+ \ |\ |\ |\ |\ |\ |\ |
+ \ | \ | \ | \ | \ | \ | \ |
+ \| \| \| \| \| \| \|
+ \endverbatim
+ *
+ * \sa SDL_HAPTIC_SINE
+ * \sa SDL_HAPTIC_LEFTRIGHT
+ * \sa SDL_HAPTIC_TRIANGLE
+ * \sa SDL_HAPTIC_SAWTOOTHUP
+ * \sa SDL_HAPTIC_SAWTOOTHDOWN
+ * \sa SDL_HapticEffect
+ */
+typedef struct SDL_HapticPeriodic
+{
+ /* Header */
+ Uint16 type; /**< ::SDL_HAPTIC_SINE, ::SDL_HAPTIC_LEFTRIGHT,
+ ::SDL_HAPTIC_TRIANGLE, ::SDL_HAPTIC_SAWTOOTHUP or
+ ::SDL_HAPTIC_SAWTOOTHDOWN */
+ SDL_HapticDirection direction; /**< Direction of the effect. */
+
+ /* Replay */
+ Uint32 length; /**< Duration of the effect. */
+ Uint16 delay; /**< Delay before starting the effect. */
+
+ /* Trigger */
+ Uint16 button; /**< Button that triggers the effect. */
+ Uint16 interval; /**< How soon it can be triggered again after button. */
+
+ /* Periodic */
+ Uint16 period; /**< Period of the wave. */
+ Sint16 magnitude; /**< Peak value; if negative, equivalent to 180 degrees extra phase shift. */
+ Sint16 offset; /**< Mean value of the wave. */
+ Uint16 phase; /**< Positive phase shift given by hundredth of a degree. */
+
+ /* Envelope */
+ Uint16 attack_length; /**< Duration of the attack. */
+ Uint16 attack_level; /**< Level at the start of the attack. */
+ Uint16 fade_length; /**< Duration of the fade. */
+ Uint16 fade_level; /**< Level at the end of the fade. */
+} SDL_HapticPeriodic;
+
+/**
+ * \brief A structure containing a template for a Condition effect.
+ *
+ * The struct handles the following effects:
+ * - ::SDL_HAPTIC_SPRING: Effect based on axes position.
+ * - ::SDL_HAPTIC_DAMPER: Effect based on axes velocity.
+ * - ::SDL_HAPTIC_INERTIA: Effect based on axes acceleration.
+ * - ::SDL_HAPTIC_FRICTION: Effect based on axes movement.
+ *
+ * Direction is handled by condition internals instead of a direction member.
+ * The condition effect specific members have three parameters. The first
+ * refers to the X axis, the second refers to the Y axis and the third
+ * refers to the Z axis. The right terms refer to the positive side of the
+ * axis and the left terms refer to the negative side of the axis. Please
+ * refer to the ::SDL_HapticDirection diagram for which side is positive and
+ * which is negative.
+ *
+ * \sa SDL_HapticDirection
+ * \sa SDL_HAPTIC_SPRING
+ * \sa SDL_HAPTIC_DAMPER
+ * \sa SDL_HAPTIC_INERTIA
+ * \sa SDL_HAPTIC_FRICTION
+ * \sa SDL_HapticEffect
+ */
+typedef struct SDL_HapticCondition
+{
+ /* Header */
+ Uint16 type; /**< ::SDL_HAPTIC_SPRING, ::SDL_HAPTIC_DAMPER,
+ ::SDL_HAPTIC_INERTIA or ::SDL_HAPTIC_FRICTION */
+ SDL_HapticDirection direction; /**< Direction of the effect - Not used ATM. */
+
+ /* Replay */
+ Uint32 length; /**< Duration of the effect. */
+ Uint16 delay; /**< Delay before starting the effect. */
+
+ /* Trigger */
+ Uint16 button; /**< Button that triggers the effect. */
+ Uint16 interval; /**< How soon it can be triggered again after button. */
+
+ /* Condition */
+ Uint16 right_sat[3]; /**< Level when joystick is to the positive side; max 0xFFFF. */
+ Uint16 left_sat[3]; /**< Level when joystick is to the negative side; max 0xFFFF. */
+ Sint16 right_coeff[3]; /**< How fast to increase the force towards the positive side. */
+ Sint16 left_coeff[3]; /**< How fast to increase the force towards the negative side. */
+ Uint16 deadband[3]; /**< Size of the dead zone; max 0xFFFF: whole axis-range when 0-centered. */
+ Sint16 center[3]; /**< Position of the dead zone. */
+} SDL_HapticCondition;
+
+/**
+ * \brief A structure containing a template for a Ramp effect.
+ *
+ * This struct is exclusively for the ::SDL_HAPTIC_RAMP effect.
+ *
+ * The ramp effect starts at start strength and ends at end strength.
+ * It augments in linear fashion. If you use attack and fade with a ramp
+ * the effects get added to the ramp effect making the effect become
+ * quadratic instead of linear.
+ *
+ * \sa SDL_HAPTIC_RAMP
+ * \sa SDL_HapticEffect
+ */
+typedef struct SDL_HapticRamp
+{
+ /* Header */
+ Uint16 type; /**< ::SDL_HAPTIC_RAMP */
+ SDL_HapticDirection direction; /**< Direction of the effect. */
+
+ /* Replay */
+ Uint32 length; /**< Duration of the effect. */
+ Uint16 delay; /**< Delay before starting the effect. */
+
+ /* Trigger */
+ Uint16 button; /**< Button that triggers the effect. */
+ Uint16 interval; /**< How soon it can be triggered again after button. */
+
+ /* Ramp */
+ Sint16 start; /**< Beginning strength level. */
+ Sint16 end; /**< Ending strength level. */
+
+ /* Envelope */
+ Uint16 attack_length; /**< Duration of the attack. */
+ Uint16 attack_level; /**< Level at the start of the attack. */
+ Uint16 fade_length; /**< Duration of the fade. */
+ Uint16 fade_level; /**< Level at the end of the fade. */
+} SDL_HapticRamp;
+
+/**
+ * \brief A structure containing a template for a Left/Right effect.
+ *
+ * This struct is exclusively for the ::SDL_HAPTIC_LEFTRIGHT effect.
+ *
+ * The Left/Right effect is used to explicitly control the large and small
+ * motors, commonly found in modern game controllers. One motor is high
+ * frequency, the other is low frequency.
+ *
+ * \sa SDL_HAPTIC_LEFTRIGHT
+ * \sa SDL_HapticEffect
+ */
+typedef struct SDL_HapticLeftRight
+{
+ /* Header */
+ Uint16 type; /**< ::SDL_HAPTIC_LEFTRIGHT */
+
+ /* Replay */
+ Uint32 length; /**< Duration of the effect. */
+
+ /* Rumble */
+ Uint16 large_magnitude; /**< Control of the large controller motor. */
+ Uint16 small_magnitude; /**< Control of the small controller motor. */
+} SDL_HapticLeftRight;
+
+/**
+ * \brief A structure containing a template for the ::SDL_HAPTIC_CUSTOM effect.
+ *
+ * This struct is exclusively for the ::SDL_HAPTIC_CUSTOM effect.
+ *
+ * A custom force feedback effect is much like a periodic effect, where the
+ * application can define its exact shape. You will have to allocate the
+ * data yourself. Data should consist of channels * samples Uint16 samples.
+ *
+ * If channels is one, the effect is rotated using the defined direction.
+ * Otherwise it uses the samples in data for the different axes.
+ *
+ * \sa SDL_HAPTIC_CUSTOM
+ * \sa SDL_HapticEffect
+ */
+typedef struct SDL_HapticCustom
+{
+ /* Header */
+ Uint16 type; /**< ::SDL_HAPTIC_CUSTOM */
+ SDL_HapticDirection direction; /**< Direction of the effect. */
+
+ /* Replay */
+ Uint32 length; /**< Duration of the effect. */
+ Uint16 delay; /**< Delay before starting the effect. */
+
+ /* Trigger */
+ Uint16 button; /**< Button that triggers the effect. */
+ Uint16 interval; /**< How soon it can be triggered again after button. */
+
+ /* Custom */
+ Uint8 channels; /**< Axes to use, minimum of one. */
+ Uint16 period; /**< Sample periods. */
+ Uint16 samples; /**< Amount of samples. */
+ Uint16 *data; /**< Should contain channels*samples items. */
+
+ /* Envelope */
+ Uint16 attack_length; /**< Duration of the attack. */
+ Uint16 attack_level; /**< Level at the start of the attack. */
+ Uint16 fade_length; /**< Duration of the fade. */
+ Uint16 fade_level; /**< Level at the end of the fade. */
+} SDL_HapticCustom;
+
+/**
+ * \brief The generic template for any haptic effect.
+ *
+ * All values max at 32767 (0x7FFF). Signed values also can be negative.
+ * Time values unless specified otherwise are in milliseconds.
+ *
+ * You can also pass ::SDL_HAPTIC_INFINITY to length instead of a 0-32767
+ * value. Neither delay, interval, attack_length nor fade_length support
+ * ::SDL_HAPTIC_INFINITY. Fade will also not be used since effect never ends.
+ *
+ * Additionally, the ::SDL_HAPTIC_RAMP effect does not support a duration of
+ * ::SDL_HAPTIC_INFINITY.
+ *
+ * Button triggers may not be supported on all devices, it is advised to not
+ * use them if possible. Buttons start at index 1 instead of index 0 like
+ * the joystick.
+ *
+ * If both attack_length and fade_level are 0, the envelope is not used,
+ * otherwise both values are used.
+ *
+ * Common parts:
+ * \code
+ * // Replay - All effects have this
+ * Uint32 length; // Duration of effect (ms).
+ * Uint16 delay; // Delay before starting effect.
+ *
+ * // Trigger - All effects have this
+ * Uint16 button; // Button that triggers effect.
+ * Uint16 interval; // How soon before effect can be triggered again.
+ *
+ * // Envelope - All effects except condition effects have this
+ * Uint16 attack_length; // Duration of the attack (ms).
+ * Uint16 attack_level; // Level at the start of the attack.
+ * Uint16 fade_length; // Duration of the fade out (ms).
+ * Uint16 fade_level; // Level at the end of the fade.
+ * \endcode
+ *
+ *
+ * Here we have an example of a constant effect evolution in time:
+ * \verbatim
+ Strength
+ ^
+ |
+ | effect level --> _________________
+ | / \
+ | / \
+ | / \
+ | / \
+ | attack_level --> | \
+ | | | <--- fade_level
+ |
+ +--------------------------------------------------> Time
+ [--] [---]
+ attack_length fade_length
+
+ [------------------][-----------------------]
+ delay length
+ \endverbatim
+ *
+ * Note either the attack_level or the fade_level may be above the actual
+ * effect level.
+ *
+ * \sa SDL_HapticConstant
+ * \sa SDL_HapticPeriodic
+ * \sa SDL_HapticCondition
+ * \sa SDL_HapticRamp
+ * \sa SDL_HapticLeftRight
+ * \sa SDL_HapticCustom
+ */
+typedef union SDL_HapticEffect
+{
+ /* Common for all force feedback effects */
+ Uint16 type; /**< Effect type. */
+ SDL_HapticConstant constant; /**< Constant effect. */
+ SDL_HapticPeriodic periodic; /**< Periodic effect. */
+ SDL_HapticCondition condition; /**< Condition effect. */
+ SDL_HapticRamp ramp; /**< Ramp effect. */
+ SDL_HapticLeftRight leftright; /**< Left/Right effect. */
+ SDL_HapticCustom custom; /**< Custom effect. */
+} SDL_HapticEffect;
+
+
+/* Function prototypes */
+/**
+ * \brief Count the number of haptic devices attached to the system.
+ *
+ * \return Number of haptic devices detected on the system.
+ */
+extern DECLSPEC int SDLCALL SDL_NumHaptics(void);
+
+/**
+ * \brief Get the implementation dependent name of a haptic device.
+ *
+ * This can be called before any joysticks are opened.
+ * If no name can be found, this function returns NULL.
+ *
+ * \param device_index Index of the device to get its name.
+ * \return Name of the device or NULL on error.
+ *
+ * \sa SDL_NumHaptics
+ */
+extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);
+
+/**
+ * \brief Opens a haptic device for use.
+ *
+ * The index passed as an argument refers to the N'th haptic device on this
+ * system.
+ *
+ * When opening a haptic device, its gain will be set to maximum and
+ * autocenter will be disabled. To modify these values use
+ * SDL_HapticSetGain() and SDL_HapticSetAutocenter().
+ *
+ * \param device_index Index of the device to open.
+ * \return Device identifier or NULL on error.
+ *
+ * \sa SDL_HapticIndex
+ * \sa SDL_HapticOpenFromMouse
+ * \sa SDL_HapticOpenFromJoystick
+ * \sa SDL_HapticClose
+ * \sa SDL_HapticSetGain
+ * \sa SDL_HapticSetAutocenter
+ * \sa SDL_HapticPause
+ * \sa SDL_HapticStopAll
+ */
+extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpen(int device_index);
+
+/**
+ * \brief Checks if the haptic device at index has been opened.
+ *
+ * \param device_index Index to check to see if it has been opened.
+ * \return 1 if it has been opened or 0 if it hasn't.
+ *
+ * \sa SDL_HapticOpen
+ * \sa SDL_HapticIndex
+ */
+extern DECLSPEC int SDLCALL SDL_HapticOpened(int device_index);
+
+/**
+ * \brief Gets the index of a haptic device.
+ *
+ * \param haptic Haptic device to get the index of.
+ * \return The index of the haptic device or -1 on error.
+ *
+ * \sa SDL_HapticOpen
+ * \sa SDL_HapticOpened
+ */
+extern DECLSPEC int SDLCALL SDL_HapticIndex(SDL_Haptic * haptic);
+
+/**
+ * \brief Gets whether or not the current mouse has haptic capabilities.
+ *
+ * \return SDL_TRUE if the mouse is haptic, SDL_FALSE if it isn't.
+ *
+ * \sa SDL_HapticOpenFromMouse
+ */
+extern DECLSPEC int SDLCALL SDL_MouseIsHaptic(void);
+
+/**
+ * \brief Tries to open a haptic device from the current mouse.
+ *
+ * \return The haptic device identifier or NULL on error.
+ *
+ * \sa SDL_MouseIsHaptic
+ * \sa SDL_HapticOpen
+ */
+extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromMouse(void);
+
+/**
+ * \brief Checks to see if a joystick has haptic features.
+ *
+ * \param joystick Joystick to test for haptic capabilities.
+ * \return SDL_TRUE if the joystick is haptic, SDL_FALSE if it isn't
+ * or -1 if an error occurred.
+ *
+ * \sa SDL_HapticOpenFromJoystick
+ */
+extern DECLSPEC int SDLCALL SDL_JoystickIsHaptic(SDL_Joystick * joystick);
+
+/**
+ * \brief Opens a haptic device for use from a joystick device.
+ *
+ * You must still close the haptic device separately. It will not be closed
+ * with the joystick.
+ *
+ * When opening from a joystick you should first close the haptic device before
+ * closing the joystick device. If not, on some implementations the haptic
+ * device will also get unallocated and you'll be unable to use force feedback
+ * on that device.
+ *
+ * \param joystick Joystick to create a haptic device from.
+ * \return A valid haptic device identifier on success or NULL on error.
+ *
+ * \sa SDL_HapticOpen
+ * \sa SDL_HapticClose
+ */
+extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromJoystick(SDL_Joystick *
+ joystick);
+
+/**
+ * \brief Closes a haptic device previously opened with SDL_HapticOpen().
+ *
+ * \param haptic Haptic device to close.
+ */
+extern DECLSPEC void SDLCALL SDL_HapticClose(SDL_Haptic * haptic);
+
+/**
+ * \brief Returns the number of effects a haptic device can store.
+ *
+ * On some platforms this isn't fully supported, and therefore is an
+ * approximation. Always check to see if your created effect was actually
+ * created and do not rely solely on SDL_HapticNumEffects().
+ *
+ * \param haptic The haptic device to query effect max.
+ * \return The number of effects the haptic device can store or
+ * -1 on error.
+ *
+ * \sa SDL_HapticNumEffectsPlaying
+ * \sa SDL_HapticQuery
+ */
+extern DECLSPEC int SDLCALL SDL_HapticNumEffects(SDL_Haptic * haptic);
+
+/**
+ * \brief Returns the number of effects a haptic device can play at the same
+ * time.
+ *
+ * This is not supported on all platforms, but will always return a value.
+ * Added here for the sake of completeness.
+ *
+ * \param haptic The haptic device to query maximum playing effects.
+ * \return The number of effects the haptic device can play at the same time
+ * or -1 on error.
+ *
+ * \sa SDL_HapticNumEffects
+ * \sa SDL_HapticQuery
+ */
+extern DECLSPEC int SDLCALL SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic);
+
+/**
+ * \brief Gets the haptic device's supported features in bitwise manner.
+ *
+ * Example:
+ * \code
+ * if (SDL_HapticQuery(haptic) & SDL_HAPTIC_CONSTANT) {
+ * printf("We have constant haptic effect!\n");
+ * }
+ * \endcode
+ *
+ * \param haptic The haptic device to query.
+ * \return Haptic features in bitwise manner (OR'd).
+ *
+ * \sa SDL_HapticNumEffects
+ * \sa SDL_HapticEffectSupported
+ */
+extern DECLSPEC unsigned int SDLCALL SDL_HapticQuery(SDL_Haptic * haptic);
+
+
+/**
+ * \brief Gets the number of haptic axes the device has.
+ *
+ * \sa SDL_HapticDirection
+ */
+extern DECLSPEC int SDLCALL SDL_HapticNumAxes(SDL_Haptic * haptic);
+
+/**
+ * \brief Checks to see if effect is supported by haptic.
+ *
+ * \param haptic Haptic device to check on.
+ * \param effect Effect to check to see if it is supported.
+ * \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error.
+ *
+ * \sa SDL_HapticQuery
+ * \sa SDL_HapticNewEffect
+ */
+extern DECLSPEC int SDLCALL SDL_HapticEffectSupported(SDL_Haptic * haptic,
+ SDL_HapticEffect *
+ effect);
+
+/**
+ * \brief Creates a new haptic effect on the device.
+ *
+ * \param haptic Haptic device to create the effect on.
+ * \param effect Properties of the effect to create.
+ * \return The identifier of the effect on success or -1 on error.
+ *
+ * \sa SDL_HapticUpdateEffect
+ * \sa SDL_HapticRunEffect
+ * \sa SDL_HapticDestroyEffect
+ */
+extern DECLSPEC int SDLCALL SDL_HapticNewEffect(SDL_Haptic * haptic,
+ SDL_HapticEffect * effect);
+
+/**
+ * \brief Updates the properties of an effect.
+ *
+ * Can be used dynamically, although behavior when dynamically changing
+ * direction may be strange. Specifically the effect may reupload itself
+ * and start playing from the start. You cannot change the type either when
+ * running SDL_HapticUpdateEffect().
+ *
+ * \param haptic Haptic device that has the effect.
+ * \param effect Identifier of the effect to update.
+ * \param data New effect properties to use.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticNewEffect
+ * \sa SDL_HapticRunEffect
+ * \sa SDL_HapticDestroyEffect
+ */
+extern DECLSPEC int SDLCALL SDL_HapticUpdateEffect(SDL_Haptic * haptic,
+ int effect,
+ SDL_HapticEffect * data);
+
+/**
+ * \brief Runs the haptic effect on its associated haptic device.
+ *
+ * If iterations are ::SDL_HAPTIC_INFINITY, it'll run the effect over and over
+ * repeating the envelope (attack and fade) every time. If you only want the
+ * effect to last forever, set ::SDL_HAPTIC_INFINITY in the effect's length
+ * parameter.
+ *
+ * \param haptic Haptic device to run the effect on.
+ * \param effect Identifier of the haptic effect to run.
+ * \param iterations Number of iterations to run the effect. Use
+ * ::SDL_HAPTIC_INFINITY for infinity.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticStopEffect
+ * \sa SDL_HapticDestroyEffect
+ * \sa SDL_HapticGetEffectStatus
+ */
+extern DECLSPEC int SDLCALL SDL_HapticRunEffect(SDL_Haptic * haptic,
+ int effect,
+ Uint32 iterations);
+
+/**
+ * \brief Stops the haptic effect on its associated haptic device.
+ *
+ * \param haptic Haptic device to stop the effect on.
+ * \param effect Identifier of the effect to stop.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticRunEffect
+ * \sa SDL_HapticDestroyEffect
+ */
+extern DECLSPEC int SDLCALL SDL_HapticStopEffect(SDL_Haptic * haptic,
+ int effect);
+
+/**
+ * \brief Destroys a haptic effect on the device.
+ *
+ * This will stop the effect if it's running. Effects are automatically
+ * destroyed when the device is closed.
+ *
+ * \param haptic Device to destroy the effect on.
+ * \param effect Identifier of the effect to destroy.
+ *
+ * \sa SDL_HapticNewEffect
+ */
+extern DECLSPEC void SDLCALL SDL_HapticDestroyEffect(SDL_Haptic * haptic,
+ int effect);
+
+/**
+ * \brief Gets the status of the current effect on the haptic device.
+ *
+ * Device must support the ::SDL_HAPTIC_STATUS feature.
+ *
+ * \param haptic Haptic device to query the effect status on.
+ * \param effect Identifier of the effect to query its status.
+ * \return 0 if it isn't playing, 1 if it is playing or -1 on error.
+ *
+ * \sa SDL_HapticRunEffect
+ * \sa SDL_HapticStopEffect
+ */
+extern DECLSPEC int SDLCALL SDL_HapticGetEffectStatus(SDL_Haptic * haptic,
+ int effect);
+
+/**
+ * \brief Sets the global gain of the device.
+ *
+ * Device must support the ::SDL_HAPTIC_GAIN feature.
+ *
+ * The user may specify the maximum gain by setting the environment variable
+ * SDL_HAPTIC_GAIN_MAX which should be between 0 and 100. All calls to
+ * SDL_HapticSetGain() will scale linearly using SDL_HAPTIC_GAIN_MAX as the
+ * maximum.
+ *
+ * \param haptic Haptic device to set the gain on.
+ * \param gain Value to set the gain to, should be between 0 and 100.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticQuery
+ */
+extern DECLSPEC int SDLCALL SDL_HapticSetGain(SDL_Haptic * haptic, int gain);
+
+/**
+ * \brief Sets the global autocenter of the device.
+ *
+ * Autocenter should be between 0 and 100. Setting it to 0 will disable
+ * autocentering.
+ *
+ * Device must support the ::SDL_HAPTIC_AUTOCENTER feature.
+ *
+ * \param haptic Haptic device to set autocentering on.
+ * \param autocenter Value to set autocenter to, 0 disables autocentering.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticQuery
+ */
+extern DECLSPEC int SDLCALL SDL_HapticSetAutocenter(SDL_Haptic * haptic,
+ int autocenter);
+
+/**
+ * \brief Pauses a haptic device.
+ *
+ * Device must support the ::SDL_HAPTIC_PAUSE feature. Call
+ * SDL_HapticUnpause() to resume playback.
+ *
+ * Do not modify the effects nor add new ones while the device is paused.
+ * That can cause all sorts of weird errors.
+ *
+ * \param haptic Haptic device to pause.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticUnpause
+ */
+extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic);
+
+/**
+ * \brief Unpauses a haptic device.
+ *
+ * Call to unpause after SDL_HapticPause().
+ *
+ * \param haptic Haptic device to unpause.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticPause
+ */
+extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic);
+
+/**
+ * \brief Stops all the currently playing effects on a haptic device.
+ *
+ * \param haptic Haptic device to stop.
+ * \return 0 on success or -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic * haptic);
+
+/**
+ * \brief Checks to see if rumble is supported on a haptic device.
+ *
+ * \param haptic Haptic device to check to see if it supports rumble.
+ * \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error.
+ *
+ * \sa SDL_HapticRumbleInit
+ * \sa SDL_HapticRumblePlay
+ * \sa SDL_HapticRumbleStop
+ */
+extern DECLSPEC int SDLCALL SDL_HapticRumbleSupported(SDL_Haptic * haptic);
+
+/**
+ * \brief Initializes the haptic device for simple rumble playback.
+ *
+ * \param haptic Haptic device to initialize for simple rumble playback.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticOpen
+ * \sa SDL_HapticRumbleSupported
+ * \sa SDL_HapticRumblePlay
+ * \sa SDL_HapticRumbleStop
+ */
+extern DECLSPEC int SDLCALL SDL_HapticRumbleInit(SDL_Haptic * haptic);
+
+/**
+ * \brief Runs simple rumble on a haptic device
+ *
+ * \param haptic Haptic device to play rumble effect on.
+ * \param strength Strength of the rumble to play as a 0-1 float value.
+ * \param length Length of the rumble to play in milliseconds.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticRumbleSupported
+ * \sa SDL_HapticRumbleInit
+ * \sa SDL_HapticRumbleStop
+ */
+extern DECLSPEC int SDLCALL SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length );
+
+/**
+ * \brief Stops the simple rumble on a haptic device.
+ *
+ * \param haptic Haptic to stop the rumble on.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticRumbleSupported
+ * \sa SDL_HapticRumbleInit
+ * \sa SDL_HapticRumblePlay
+ */
+extern DECLSPEC int SDLCALL SDL_HapticRumbleStop(SDL_Haptic * haptic);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_haptic_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_hints.h b/src/3rdparty/SDL2/include/SDL2/SDL_hints.h
new file mode 100644
index 0000000..3834640
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_hints.h
@@ -0,0 +1,1022 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_hints.h
+ *
+ * Official documentation for SDL configuration variables
+ *
+ * This file contains functions to set and get configuration hints,
+ * as well as listing each of them alphabetically.
+ *
+ * The convention for naming hints is SDL_HINT_X, where "SDL_X" is
+ * the environment variable that can be used to override the default.
+ *
+ * In general these hints are just that - they may or may not be
+ * supported or applicable on any given platform, but they provide
+ * a way for an application or user to give the library a hint as
+ * to how they would like the library to work.
+ */
+
+#ifndef SDL_hints_h_
+#define SDL_hints_h_
+
+#include "SDL_stdinc.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief A variable controlling how 3D acceleration is used to accelerate the SDL screen surface.
+ *
+ * SDL can try to accelerate the SDL screen surface by using streaming
+ * textures with a 3D rendering engine. This variable controls whether and
+ * how this is done.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable 3D acceleration
+ * "1" - Enable 3D acceleration, using the default renderer.
+ * "X" - Enable 3D acceleration, using X where X is one of the valid rendering drivers. (e.g. "direct3d", "opengl", etc.)
+ *
+ * By default SDL tries to make a best guess for each platform whether
+ * to use acceleration or not.
+ */
+#define SDL_HINT_FRAMEBUFFER_ACCELERATION "SDL_FRAMEBUFFER_ACCELERATION"
+
+/**
+ * \brief A variable specifying which render driver to use.
+ *
+ * If the application doesn't pick a specific renderer to use, this variable
+ * specifies the name of the preferred renderer. If the preferred renderer
+ * can't be initialized, the normal default renderer is used.
+ *
+ * This variable is case insensitive and can be set to the following values:
+ * "direct3d"
+ * "opengl"
+ * "opengles2"
+ * "opengles"
+ * "metal"
+ * "software"
+ *
+ * The default varies by platform, but it's the first one in the list that
+ * is available on the current platform.
+ */
+#define SDL_HINT_RENDER_DRIVER "SDL_RENDER_DRIVER"
+
+/**
+ * \brief A variable controlling whether the OpenGL render driver uses shaders if they are available.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable shaders
+ * "1" - Enable shaders
+ *
+ * By default shaders are used if OpenGL supports them.
+ */
+#define SDL_HINT_RENDER_OPENGL_SHADERS "SDL_RENDER_OPENGL_SHADERS"
+
+/**
+ * \brief A variable controlling whether the Direct3D device is initialized for thread-safe operations.
+ *
+ * This variable can be set to the following values:
+ * "0" - Thread-safety is not enabled (faster)
+ * "1" - Thread-safety is enabled
+ *
+ * By default the Direct3D device is created with thread-safety disabled.
+ */
+#define SDL_HINT_RENDER_DIRECT3D_THREADSAFE "SDL_RENDER_DIRECT3D_THREADSAFE"
+
+/**
+ * \brief A variable controlling whether to enable Direct3D 11+'s Debug Layer.
+ *
+ * This variable does not have any effect on the Direct3D 9 based renderer.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable Debug Layer use
+ * "1" - Enable Debug Layer use
+ *
+ * By default, SDL does not use Direct3D Debug Layer.
+ */
+#define SDL_HINT_RENDER_DIRECT3D11_DEBUG "SDL_RENDER_DIRECT3D11_DEBUG"
+
+/**
+ * \brief A variable controlling the scaling policy for SDL_RenderSetLogicalSize.
+ *
+ * This variable can be set to the following values:
+ * "0" or "letterbox" - Uses letterbox/sidebars to fit the entire rendering on screen
+ * "1" or "overscan" - Will zoom the rendering so it fills the entire screen, allowing edges to be drawn offscreen
+ *
+ * By default letterbox is used
+ */
+#define SDL_HINT_RENDER_LOGICAL_SIZE_MODE "SDL_RENDER_LOGICAL_SIZE_MODE"
+
+/**
+ * \brief A variable controlling the scaling quality
+ *
+ * This variable can be set to the following values:
+ * "0" or "nearest" - Nearest pixel sampling
+ * "1" or "linear" - Linear filtering (supported by OpenGL and Direct3D)
+ * "2" or "best" - Currently this is the same as "linear"
+ *
+ * By default nearest pixel sampling is used
+ */
+#define SDL_HINT_RENDER_SCALE_QUALITY "SDL_RENDER_SCALE_QUALITY"
+
+/**
+ * \brief A variable controlling whether updates to the SDL screen surface should be synchronized with the vertical refresh, to avoid tearing.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable vsync
+ * "1" - Enable vsync
+ *
+ * By default SDL does not sync screen surface updates with vertical refresh.
+ */
+#define SDL_HINT_RENDER_VSYNC "SDL_RENDER_VSYNC"
+
+/**
+ * \brief A variable controlling whether the screensaver is enabled.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable screensaver
+ * "1" - Enable screensaver
+ *
+ * By default SDL will disable the screensaver.
+ */
+#define SDL_HINT_VIDEO_ALLOW_SCREENSAVER "SDL_VIDEO_ALLOW_SCREENSAVER"
+
+/**
+ * \brief A variable controlling whether the X11 VidMode extension should be used.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable XVidMode
+ * "1" - Enable XVidMode
+ *
+ * By default SDL will use XVidMode if it is available.
+ */
+#define SDL_HINT_VIDEO_X11_XVIDMODE "SDL_VIDEO_X11_XVIDMODE"
+
+/**
+ * \brief A variable controlling whether the X11 Xinerama extension should be used.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable Xinerama
+ * "1" - Enable Xinerama
+ *
+ * By default SDL will use Xinerama if it is available.
+ */
+#define SDL_HINT_VIDEO_X11_XINERAMA "SDL_VIDEO_X11_XINERAMA"
+
+/**
+ * \brief A variable controlling whether the X11 XRandR extension should be used.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable XRandR
+ * "1" - Enable XRandR
+ *
+ * By default SDL will not use XRandR because of window manager issues.
+ */
+#define SDL_HINT_VIDEO_X11_XRANDR "SDL_VIDEO_X11_XRANDR"
+
+/**
+ * \brief A variable controlling whether the X11 _NET_WM_PING protocol should be supported.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable _NET_WM_PING
+ * "1" - Enable _NET_WM_PING
+ *
+ * By default SDL will use _NET_WM_PING, but for applications that know they
+ * will not always be able to respond to ping requests in a timely manner they can
+ * turn it off to avoid the window manager thinking the app is hung.
+ * The hint is checked in CreateWindow.
+ */
+#define SDL_HINT_VIDEO_X11_NET_WM_PING "SDL_VIDEO_X11_NET_WM_PING"
+
+/**
+ * \brief A variable controlling whether the X11 _NET_WM_BYPASS_COMPOSITOR hint should be used.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable _NET_WM_BYPASS_COMPOSITOR
+ * "1" - Enable _NET_WM_BYPASS_COMPOSITOR
+ *
+ * By default SDL will use _NET_WM_BYPASS_COMPOSITOR
+ *
+ */
+#define SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR "SDL_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR"
+
+/**
+ * \brief A variable controlling whether the window frame and title bar are interactive when the cursor is hidden
+ *
+ * This variable can be set to the following values:
+ * "0" - The window frame is not interactive when the cursor is hidden (no move, resize, etc)
+ * "1" - The window frame is interactive when the cursor is hidden
+ *
+ * By default SDL will allow interaction with the window frame when the cursor is hidden
+ */
+#define SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN "SDL_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN"
+
+/**
+ * \brief A variable to specify custom icon resource id from RC file on Windows platform
+ */
+#define SDL_HINT_WINDOWS_INTRESOURCE_ICON "SDL_WINDOWS_INTRESOURCE_ICON"
+#define SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL "SDL_WINDOWS_INTRESOURCE_ICON_SMALL"
+
+/**
+ * \brief A variable controlling whether the windows message loop is processed by SDL
+ *
+ * This variable can be set to the following values:
+ * "0" - The window message loop is not run
+ * "1" - The window message loop is processed in SDL_PumpEvents()
+ *
+ * By default SDL will process the windows message loop
+ */
+#define SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP "SDL_WINDOWS_ENABLE_MESSAGELOOP"
+
+/**
+ * \brief A variable controlling whether grabbing input grabs the keyboard
+ *
+ * This variable can be set to the following values:
+ * "0" - Grab will affect only the mouse
+ * "1" - Grab will affect mouse and keyboard
+ *
+ * By default SDL will not grab the keyboard so system shortcuts still work.
+ */
+#define SDL_HINT_GRAB_KEYBOARD "SDL_GRAB_KEYBOARD"
+
+/**
+ * \brief A variable setting the speed scale for mouse motion, in floating point, when the mouse is not in relative mode
+ */
+#define SDL_HINT_MOUSE_NORMAL_SPEED_SCALE "SDL_MOUSE_NORMAL_SPEED_SCALE"
+
+/**
+ * \brief A variable setting the scale for mouse motion, in floating point, when the mouse is in relative mode
+ */
+#define SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE "SDL_MOUSE_RELATIVE_SPEED_SCALE"
+
+/**
+ * \brief A variable controlling whether relative mouse mode is implemented using mouse warping
+ *
+ * This variable can be set to the following values:
+ * "0" - Relative mouse mode uses raw input
+ * "1" - Relative mouse mode uses mouse warping
+ *
+ * By default SDL will use raw input for relative mouse mode
+ */
+#define SDL_HINT_MOUSE_RELATIVE_MODE_WARP "SDL_MOUSE_RELATIVE_MODE_WARP"
+
+/**
+ * \brief Allow mouse click events when clicking to focus an SDL window
+ *
+ * This variable can be set to the following values:
+ * "0" - Ignore mouse clicks that activate a window
+ * "1" - Generate events for mouse clicks that activate a window
+ *
+ * By default SDL will ignore mouse clicks that activate a window
+ */
+#define SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH "SDL_MOUSE_FOCUS_CLICKTHROUGH"
+
+/**
+ * \brief A variable controlling whether touch events should generate synthetic mouse events
+ *
+ * This variable can be set to the following values:
+ * "0" - Touch events will not generate mouse events
+ * "1" - Touch events will generate mouse events
+ *
+ * By default SDL will generate mouse events for touch events
+ */
+#define SDL_HINT_TOUCH_MOUSE_EVENTS "SDL_TOUCH_MOUSE_EVENTS"
+
+/**
+ * \brief Minimize your SDL_Window if it loses key focus when in fullscreen mode. Defaults to true.
+ *
+ */
+#define SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS"
+
+/**
+ * \brief A variable controlling whether the idle timer is disabled on iOS.
+ *
+ * When an iOS app does not receive touches for some time, the screen is
+ * dimmed automatically. For games where the accelerometer is the only input
+ * this is problematic. This functionality can be disabled by setting this
+ * hint.
+ *
+ * As of SDL 2.0.4, SDL_EnableScreenSaver() and SDL_DisableScreenSaver()
+ * accomplish the same thing on iOS. They should be preferred over this hint.
+ *
+ * This variable can be set to the following values:
+ * "0" - Enable idle timer
+ * "1" - Disable idle timer
+ */
+#define SDL_HINT_IDLE_TIMER_DISABLED "SDL_IOS_IDLE_TIMER_DISABLED"
+
+/**
+ * \brief A variable controlling which orientations are allowed on iOS.
+ *
+ * In some circumstances it is necessary to be able to explicitly control
+ * which UI orientations are allowed.
+ *
+ * This variable is a space delimited list of the following values:
+ * "LandscapeLeft", "LandscapeRight", "Portrait" "PortraitUpsideDown"
+ */
+#define SDL_HINT_ORIENTATIONS "SDL_IOS_ORIENTATIONS"
+
+/**
+ * \brief A variable controlling whether controllers used with the Apple TV
+ * generate UI events.
+ *
+ * When UI events are generated by controller input, the app will be
+ * backgrounded when the Apple TV remote's menu button is pressed, and when the
+ * pause or B buttons on gamepads are pressed.
+ *
+ * More information about properly making use of controllers for the Apple TV
+ * can be found here:
+ * https://developer.apple.com/tvos/human-interface-guidelines/remote-and-controllers/
+ *
+ * This variable can be set to the following values:
+ * "0" - Controller input does not generate UI events (the default).
+ * "1" - Controller input generates UI events.
+ */
+#define SDL_HINT_APPLE_TV_CONTROLLER_UI_EVENTS "SDL_APPLE_TV_CONTROLLER_UI_EVENTS"
+
+/**
+ * \brief A variable controlling whether the Apple TV remote's joystick axes
+ * will automatically match the rotation of the remote.
+ *
+ * This variable can be set to the following values:
+ * "0" - Remote orientation does not affect joystick axes (the default).
+ * "1" - Joystick axes are based on the orientation of the remote.
+ */
+#define SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION "SDL_APPLE_TV_REMOTE_ALLOW_ROTATION"
+
+/**
+ * \brief A variable controlling whether the home indicator bar on iPhone X
+ * should be hidden.
+ *
+ * This variable can be set to the following values:
+ * "0" - The indicator bar is not hidden (default for windowed applications)
+ * "1" - The indicator bar is hidden and is shown when the screen is touched (useful for movie playback applications)
+ * "2" - The indicator bar is dim and the first swipe makes it visible and the second swipe performs the "home" action (default for fullscreen applications)
+ */
+#define SDL_HINT_IOS_HIDE_HOME_INDICATOR "SDL_IOS_HIDE_HOME_INDICATOR"
+
+/**
+ * \brief A variable controlling whether the Android / iOS built-in
+ * accelerometer should be listed as a joystick device.
+ *
+ * This variable can be set to the following values:
+ * "0" - The accelerometer is not listed as a joystick
+ * "1" - The accelerometer is available as a 3 axis joystick (the default).
+ */
+#define SDL_HINT_ACCELEROMETER_AS_JOYSTICK "SDL_ACCELEROMETER_AS_JOYSTICK"
+
+/**
+ * \brief A variable controlling whether the Android / tvOS remotes
+ * should be listed as joystick devices, instead of sending keyboard events.
+ *
+ * This variable can be set to the following values:
+ * "0" - Remotes send enter/escape/arrow key events
+ * "1" - Remotes are available as 2 axis, 2 button joysticks (the default).
+ */
+#define SDL_HINT_TV_REMOTE_AS_JOYSTICK "SDL_TV_REMOTE_AS_JOYSTICK"
+
+/**
+ * \brief A variable that lets you disable the detection and use of Xinput gamepad devices
+ *
+ * The variable can be set to the following values:
+ * "0" - Disable XInput detection (only uses direct input)
+ * "1" - Enable XInput detection (the default)
+ */
+#define SDL_HINT_XINPUT_ENABLED "SDL_XINPUT_ENABLED"
+
+/**
+ * \brief A variable that causes SDL to use the old axis and button mapping for XInput devices.
+ *
+ * This hint is for backwards compatibility only and will be removed in SDL 2.1
+ *
+ * The default value is "0". This hint must be set before SDL_Init()
+ */
+#define SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING "SDL_XINPUT_USE_OLD_JOYSTICK_MAPPING"
+
+/**
+ * \brief A variable that lets you manually hint extra gamecontroller db entries.
+ *
+ * The variable should be newline delimited rows of gamecontroller config data, see SDL_gamecontroller.h
+ *
+ * This hint must be set before calling SDL_Init(SDL_INIT_GAMECONTROLLER)
+ * You can update mappings after the system is initialized with SDL_GameControllerMappingForGUID() and SDL_GameControllerAddMapping()
+ */
+#define SDL_HINT_GAMECONTROLLERCONFIG "SDL_GAMECONTROLLERCONFIG"
+
+/**
+ * \brief A variable containing a list of devices to skip when scanning for game controllers.
+ *
+ * The format of the string is a comma separated list of USB VID/PID pairs
+ * in hexadecimal form, e.g.
+ *
+ * 0xAAAA/0xBBBB,0xCCCC/0xDDDD
+ *
+ * The variable can also take the form of @file, in which case the named
+ * file will be loaded and interpreted as the value of the variable.
+ */
+#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES "SDL_GAMECONTROLLER_IGNORE_DEVICES"
+
+/**
+ * \brief If set, all devices will be skipped when scanning for game controllers except for the ones listed in this variable.
+ *
+ * The format of the string is a comma separated list of USB VID/PID pairs
+ * in hexadecimal form, e.g.
+ *
+ * 0xAAAA/0xBBBB,0xCCCC/0xDDDD
+ *
+ * The variable can also take the form of @file, in which case the named
+ * file will be loaded and interpreted as the value of the variable.
+ */
+#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT "SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT"
+
+/**
+ * \brief A variable that lets you enable joystick (and gamecontroller) events even when your app is in the background.
+ *
+ * The variable can be set to the following values:
+ * "0" - Disable joystick & gamecontroller input events when the
+ * application is in the background.
+ * "1" - Enable joystick & gamecontroller input events when the
+ * application is in the background.
+ *
+ * The default value is "0". This hint may be set at any time.
+ */
+#define SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS "SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS"
+
+/**
+ * \brief If set to "0" then never set the top most bit on a SDL Window, even if the video mode expects it.
+ * This is a debugging aid for developers and not expected to be used by end users. The default is "1"
+ *
+ * This variable can be set to the following values:
+ * "0" - don't allow topmost
+ * "1" - allow topmost
+ */
+#define SDL_HINT_ALLOW_TOPMOST "SDL_ALLOW_TOPMOST"
+
+/**
+ * \brief A variable that controls the timer resolution, in milliseconds.
+ *
+ * The higher resolution the timer, the more frequently the CPU services
+ * timer interrupts, and the more precise delays are, but this takes up
+ * power and CPU time. This hint is only used on Windows 7 and earlier.
+ *
+ * See this blog post for more information:
+ * http://randomascii.wordpress.com/2013/07/08/windows-timer-resolution-megawatts-wasted/
+ *
+ * If this variable is set to "0", the system timer resolution is not set.
+ *
+ * The default value is "1". This hint may be set at any time.
+ */
+#define SDL_HINT_TIMER_RESOLUTION "SDL_TIMER_RESOLUTION"
+
+
+/**
+ * \brief A variable describing the content orientation on QtWayland-based platforms.
+ *
+ * On QtWayland platforms, windows are rotated client-side to allow for custom
+ * transitions. In order to correctly position overlays (e.g. volume bar) and
+ * gestures (e.g. events view, close/minimize gestures), the system needs to
+ * know in which orientation the application is currently drawing its contents.
+ *
+ * This does not cause the window to be rotated or resized, the application
+ * needs to take care of drawing the content in the right orientation (the
+ * framebuffer is always in portrait mode).
+ *
+ * This variable can be one of the following values:
+ * "primary" (default), "portrait", "landscape", "inverted-portrait", "inverted-landscape"
+ */
+#define SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION "SDL_QTWAYLAND_CONTENT_ORIENTATION"
+
+/**
+ * \brief Flags to set on QtWayland windows to integrate with the native window manager.
+ *
+ * On QtWayland platforms, this hint controls the flags to set on the windows.
+ * For example, on Sailfish OS "OverridesSystemGestures" disables swipe gestures.
+ *
+ * This variable is a space-separated list of the following values (empty = no flags):
+ * "OverridesSystemGestures", "StaysOnTop", "BypassWindowManager"
+ */
+#define SDL_HINT_QTWAYLAND_WINDOW_FLAGS "SDL_QTWAYLAND_WINDOW_FLAGS"
+
+/**
+* \brief A string specifying SDL's threads stack size in bytes or "0" for the backend's default size
+*
+* Use this hint in case you need to set SDL's threads stack size to other than the default.
+* This is specially useful if you build SDL against a non glibc libc library (such as musl) which
+* provides a relatively small default thread stack size (a few kilobytes versus the default 8MB glibc uses).
+* Support for this hint is currently available only in the pthread, Windows, and PSP backend.
+*/
+#define SDL_HINT_THREAD_STACK_SIZE "SDL_THREAD_STACK_SIZE"
+
+/**
+ * \brief If set to 1, then do not allow high-DPI windows. ("Retina" on Mac and iOS)
+ */
+#define SDL_HINT_VIDEO_HIGHDPI_DISABLED "SDL_VIDEO_HIGHDPI_DISABLED"
+
+/**
+ * \brief A variable that determines whether ctrl+click should generate a right-click event on Mac
+ *
+ * If present, holding ctrl while left clicking will generate a right click
+ * event when on Mac.
+ */
+#define SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK "SDL_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK"
+
+/**
+* \brief A variable specifying which shader compiler to preload when using the Chrome ANGLE binaries
+*
+* SDL has EGL and OpenGL ES2 support on Windows via the ANGLE project. It
+* can use two different sets of binaries, those compiled by the user from source
+* or those provided by the Chrome browser. In the later case, these binaries require
+* that SDL loads a DLL providing the shader compiler.
+*
+* This variable can be set to the following values:
+* "d3dcompiler_46.dll" - default, best for Vista or later.
+* "d3dcompiler_43.dll" - for XP support.
+* "none" - do not load any library, useful if you compiled ANGLE from source and included the compiler in your binaries.
+*
+*/
+#define SDL_HINT_VIDEO_WIN_D3DCOMPILER "SDL_VIDEO_WIN_D3DCOMPILER"
+
+/**
+* \brief A variable that is the address of another SDL_Window* (as a hex string formatted with "%p").
+*
+* If this hint is set before SDL_CreateWindowFrom() and the SDL_Window* it is set to has
+* SDL_WINDOW_OPENGL set (and running on WGL only, currently), then two things will occur on the newly
+* created SDL_Window:
+*
+* 1. Its pixel format will be set to the same pixel format as this SDL_Window. This is
+* needed for example when sharing an OpenGL context across multiple windows.
+*
+* 2. The flag SDL_WINDOW_OPENGL will be set on the new window so it can be used for
+* OpenGL rendering.
+*
+* This variable can be set to the following values:
+* The address (as a string "%p") of the SDL_Window* that new windows created with SDL_CreateWindowFrom() should
+* share a pixel format with.
+*/
+#define SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT"
+
+/**
+ * \brief A URL to a WinRT app's privacy policy
+ *
+ * All network-enabled WinRT apps must make a privacy policy available to its
+ * users. On Windows 8, 8.1, and RT, Microsoft mandates that this policy be
+ * be available in the Windows Settings charm, as accessed from within the app.
+ * SDL provides code to add a URL-based link there, which can point to the app's
+ * privacy policy.
+ *
+ * To setup a URL to an app's privacy policy, set SDL_HINT_WINRT_PRIVACY_POLICY_URL
+ * before calling any SDL_Init() functions. The contents of the hint should
+ * be a valid URL. For example, "http://www.example.com".
+ *
+ * The default value is "", which will prevent SDL from adding a privacy policy
+ * link to the Settings charm. This hint should only be set during app init.
+ *
+ * The label text of an app's "Privacy Policy" link may be customized via another
+ * hint, SDL_HINT_WINRT_PRIVACY_POLICY_LABEL.
+ *
+ * Please note that on Windows Phone, Microsoft does not provide standard UI
+ * for displaying a privacy policy link, and as such, SDL_HINT_WINRT_PRIVACY_POLICY_URL
+ * will not get used on that platform. Network-enabled phone apps should display
+ * their privacy policy through some other, in-app means.
+ */
+#define SDL_HINT_WINRT_PRIVACY_POLICY_URL "SDL_WINRT_PRIVACY_POLICY_URL"
+
+/** \brief Label text for a WinRT app's privacy policy link
+ *
+ * Network-enabled WinRT apps must include a privacy policy. On Windows 8, 8.1, and RT,
+ * Microsoft mandates that this policy be available via the Windows Settings charm.
+ * SDL provides code to add a link there, with its label text being set via the
+ * optional hint, SDL_HINT_WINRT_PRIVACY_POLICY_LABEL.
+ *
+ * Please note that a privacy policy's contents are not set via this hint. A separate
+ * hint, SDL_HINT_WINRT_PRIVACY_POLICY_URL, is used to link to the actual text of the
+ * policy.
+ *
+ * The contents of this hint should be encoded as a UTF8 string.
+ *
+ * The default value is "Privacy Policy". This hint should only be set during app
+ * initialization, preferably before any calls to SDL_Init().
+ *
+ * For additional information on linking to a privacy policy, see the documentation for
+ * SDL_HINT_WINRT_PRIVACY_POLICY_URL.
+ */
+#define SDL_HINT_WINRT_PRIVACY_POLICY_LABEL "SDL_WINRT_PRIVACY_POLICY_LABEL"
+
+/** \brief Allows back-button-press events on Windows Phone to be marked as handled
+ *
+ * Windows Phone devices typically feature a Back button. When pressed,
+ * the OS will emit back-button-press events, which apps are expected to
+ * handle in an appropriate manner. If apps do not explicitly mark these
+ * events as 'Handled', then the OS will invoke its default behavior for
+ * unhandled back-button-press events, which on Windows Phone 8 and 8.1 is to
+ * terminate the app (and attempt to switch to the previous app, or to the
+ * device's home screen).
+ *
+ * Setting the SDL_HINT_WINRT_HANDLE_BACK_BUTTON hint to "1" will cause SDL
+ * to mark back-button-press events as Handled, if and when one is sent to
+ * the app.
+ *
+ * Internally, Windows Phone sends back button events as parameters to
+ * special back-button-press callback functions. Apps that need to respond
+ * to back-button-press events are expected to register one or more
+ * callback functions for such, shortly after being launched (during the
+ * app's initialization phase). After the back button is pressed, the OS
+ * will invoke these callbacks. If the app's callback(s) do not explicitly
+ * mark the event as handled by the time they return, or if the app never
+ * registers one of these callback, the OS will consider the event
+ * un-handled, and it will apply its default back button behavior (terminate
+ * the app).
+ *
+ * SDL registers its own back-button-press callback with the Windows Phone
+ * OS. This callback will emit a pair of SDL key-press events (SDL_KEYDOWN
+ * and SDL_KEYUP), each with a scancode of SDL_SCANCODE_AC_BACK, after which
+ * it will check the contents of the hint, SDL_HINT_WINRT_HANDLE_BACK_BUTTON.
+ * If the hint's value is set to "1", the back button event's Handled
+ * property will get set to 'true'. If the hint's value is set to something
+ * else, or if it is unset, SDL will leave the event's Handled property
+ * alone. (By default, the OS sets this property to 'false', to note.)
+ *
+ * SDL apps can either set SDL_HINT_WINRT_HANDLE_BACK_BUTTON well before a
+ * back button is pressed, or can set it in direct-response to a back button
+ * being pressed.
+ *
+ * In order to get notified when a back button is pressed, SDL apps should
+ * register a callback function with SDL_AddEventWatch(), and have it listen
+ * for SDL_KEYDOWN events that have a scancode of SDL_SCANCODE_AC_BACK.
+ * (Alternatively, SDL_KEYUP events can be listened-for. Listening for
+ * either event type is suitable.) Any value of SDL_HINT_WINRT_HANDLE_BACK_BUTTON
+ * set by such a callback, will be applied to the OS' current
+ * back-button-press event.
+ *
+ * More details on back button behavior in Windows Phone apps can be found
+ * at the following page, on Microsoft's developer site:
+ * http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj247550(v=vs.105).aspx
+ */
+#define SDL_HINT_WINRT_HANDLE_BACK_BUTTON "SDL_WINRT_HANDLE_BACK_BUTTON"
+
+/**
+ * \brief A variable that dictates policy for fullscreen Spaces on Mac OS X.
+ *
+ * This hint only applies to Mac OS X.
+ *
+ * The variable can be set to the following values:
+ * "0" - Disable Spaces support (FULLSCREEN_DESKTOP won't use them and
+ * SDL_WINDOW_RESIZABLE windows won't offer the "fullscreen"
+ * button on their titlebars).
+ * "1" - Enable Spaces support (FULLSCREEN_DESKTOP will use them and
+ * SDL_WINDOW_RESIZABLE windows will offer the "fullscreen"
+ * button on their titlebars).
+ *
+ * The default value is "1". Spaces are disabled regardless of this hint if
+ * the OS isn't at least Mac OS X Lion (10.7). This hint must be set before
+ * any windows are created.
+ */
+#define SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES "SDL_VIDEO_MAC_FULLSCREEN_SPACES"
+
+/**
+* \brief When set don't force the SDL app to become a foreground process
+*
+* This hint only applies to Mac OS X.
+*
+*/
+#define SDL_HINT_MAC_BACKGROUND_APP "SDL_MAC_BACKGROUND_APP"
+
+/**
+ * \brief Android APK expansion main file version. Should be a string number like "1", "2" etc.
+ *
+ * Must be set together with SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION.
+ *
+ * If both hints were set then SDL_RWFromFile() will look into expansion files
+ * after a given relative path was not found in the internal storage and assets.
+ *
+ * By default this hint is not set and the APK expansion files are not searched.
+ */
+#define SDL_HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION "SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION"
+
+/**
+ * \brief Android APK expansion patch file version. Should be a string number like "1", "2" etc.
+ *
+ * Must be set together with SDL_HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION.
+ *
+ * If both hints were set then SDL_RWFromFile() will look into expansion files
+ * after a given relative path was not found in the internal storage and assets.
+ *
+ * By default this hint is not set and the APK expansion files are not searched.
+ */
+#define SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION "SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION"
+
+/**
+ * \brief A variable to control whether certain IMEs should handle text editing internally instead of sending SDL_TEXTEDITING events.
+ *
+ * The variable can be set to the following values:
+ * "0" - SDL_TEXTEDITING events are sent, and it is the application's
+ * responsibility to render the text from these events and
+ * differentiate it somehow from committed text. (default)
+ * "1" - If supported by the IME then SDL_TEXTEDITING events are not sent,
+ * and text that is being composed will be rendered in its own UI.
+ */
+#define SDL_HINT_IME_INTERNAL_EDITING "SDL_IME_INTERNAL_EDITING"
+
+ /**
+ * \brief A variable to control whether mouse and touch events are to be treated together or separately
+ *
+ * The variable can be set to the following values:
+ * "0" - Mouse events will be handled as touch events, and touch will raise fake mouse
+ * events. This is the behaviour of SDL <= 2.0.3. (default)
+ * "1" - Mouse events will be handled separately from pure touch events.
+ *
+ * The value of this hint is used at runtime, so it can be changed at any time.
+ */
+#define SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH "SDL_ANDROID_SEPARATE_MOUSE_AND_TOUCH"
+
+ /**
+ * \brief A variable to control whether the return key on the soft keyboard
+ * should hide the soft keyboard on Android and iOS.
+ *
+ * The variable can be set to the following values:
+ * "0" - The return key will be handled as a key event. This is the behaviour of SDL <= 2.0.3. (default)
+ * "1" - The return key will hide the keyboard.
+ *
+ * The value of this hint is used at runtime, so it can be changed at any time.
+ */
+#define SDL_HINT_RETURN_KEY_HIDES_IME "SDL_RETURN_KEY_HIDES_IME"
+
+/**
+ * \brief override the binding element for keyboard inputs for Emscripten builds
+ *
+ * This hint only applies to the emscripten platform
+ *
+ * The variable can be one of
+ * "#window" - The javascript window object (this is the default)
+ * "#document" - The javascript document object
+ * "#screen" - the javascript window.screen object
+ * "#canvas" - the WebGL canvas element
+ * any other string without a leading # sign applies to the element on the page with that ID.
+ */
+#define SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT "SDL_EMSCRIPTEN_KEYBOARD_ELEMENT"
+
+/**
+ * \brief Tell SDL not to catch the SIGINT or SIGTERM signals.
+ *
+ * This hint only applies to Unix-like platforms.
+ *
+ * The variable can be set to the following values:
+ * "0" - SDL will install a SIGINT and SIGTERM handler, and when it
+ * catches a signal, convert it into an SDL_QUIT event.
+ * "1" - SDL will not install a signal handler at all.
+ */
+#define SDL_HINT_NO_SIGNAL_HANDLERS "SDL_NO_SIGNAL_HANDLERS"
+
+/**
+ * \brief Tell SDL not to generate window-close events for Alt+F4 on Windows.
+ *
+ * The variable can be set to the following values:
+ * "0" - SDL will generate a window-close event when it sees Alt+F4.
+ * "1" - SDL will only do normal key handling for Alt+F4.
+ */
+#define SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4 "SDL_WINDOWS_NO_CLOSE_ON_ALT_F4"
+
+/**
+ * \brief Prevent SDL from using version 4 of the bitmap header when saving BMPs.
+ *
+ * The bitmap header version 4 is required for proper alpha channel support and
+ * SDL will use it when required. Should this not be desired, this hint can
+ * force the use of the 40 byte header version which is supported everywhere.
+ *
+ * The variable can be set to the following values:
+ * "0" - Surfaces with a colorkey or an alpha channel are saved to a
+ * 32-bit BMP file with an alpha mask. SDL will use the bitmap
+ * header version 4 and set the alpha mask accordingly.
+ * "1" - Surfaces with a colorkey or an alpha channel are saved to a
+ * 32-bit BMP file without an alpha mask. The alpha channel data
+ * will be in the file, but applications are going to ignore it.
+ *
+ * The default value is "0".
+ */
+#define SDL_HINT_BMP_SAVE_LEGACY_FORMAT "SDL_BMP_SAVE_LEGACY_FORMAT"
+
+/**
+ * \brief Tell SDL not to name threads on Windows with the 0x406D1388 Exception.
+ * The 0x406D1388 Exception is a trick used to inform Visual Studio of a
+ * thread's name, but it tends to cause problems with other debuggers,
+ * and the .NET runtime. Note that SDL 2.0.6 and later will still use
+ * the (safer) SetThreadDescription API, introduced in the Windows 10
+ * Creators Update, if available.
+ *
+ * The variable can be set to the following values:
+ * "0" - SDL will raise the 0x406D1388 Exception to name threads.
+ * This is the default behavior of SDL <= 2.0.4.
+ * "1" - SDL will not raise this exception, and threads will be unnamed. (default)
+ * This is necessary with .NET languages or debuggers that aren't Visual Studio.
+ */
+#define SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING "SDL_WINDOWS_DISABLE_THREAD_NAMING"
+
+/**
+ * \brief Tell SDL which Dispmanx layer to use on a Raspberry PI
+ *
+ * Also known as Z-order. The variable can take a negative or positive value.
+ * The default is 10000.
+ */
+#define SDL_HINT_RPI_VIDEO_LAYER "SDL_RPI_VIDEO_LAYER"
+
+/**
+ * \brief Tell the video driver that we only want a double buffer.
+ *
+ * By default, most lowlevel 2D APIs will use a triple buffer scheme that
+ * wastes no CPU time on waiting for vsync after issuing a flip, but
+ * introduces a frame of latency. On the other hand, using a double buffer
+ * scheme instead is recommended for cases where low latency is an important
+ * factor because we save a whole frame of latency.
+ * We do so by waiting for vsync immediately after issuing a flip, usually just
+ * after eglSwapBuffers call in the backend's *_SwapWindow function.
+ *
+ * Since it's driver-specific, it's only supported where possible and
+ * implemented. Currently supported the following drivers:
+ * - KMSDRM (kmsdrm)
+ * - Raspberry Pi (raspberrypi)
+ */
+#define SDL_HINT_VIDEO_DOUBLE_BUFFER "SDL_VIDEO_DOUBLE_BUFFER"
+
+/**
+ * \brief A variable controlling what driver to use for OpenGL ES contexts.
+ *
+ * On some platforms, currently Windows and X11, OpenGL drivers may support
+ * creating contexts with an OpenGL ES profile. By default SDL uses these
+ * profiles, when available, otherwise it attempts to load an OpenGL ES
+ * library, e.g. that provided by the ANGLE project. This variable controls
+ * whether SDL follows this default behaviour or will always load an
+ * OpenGL ES library.
+ *
+ * Circumstances where this is useful include
+ * - Testing an app with a particular OpenGL ES implementation, e.g ANGLE,
+ * or emulator, e.g. those from ARM, Imagination or Qualcomm.
+ * - Resolving OpenGL ES function addresses at link time by linking with
+ * the OpenGL ES library instead of querying them at run time with
+ * SDL_GL_GetProcAddress().
+ *
+ * Caution: for an application to work with the default behaviour across
+ * different OpenGL drivers it must query the OpenGL ES function
+ * addresses at run time using SDL_GL_GetProcAddress().
+ *
+ * This variable is ignored on most platforms because OpenGL ES is native
+ * or not supported.
+ *
+ * This variable can be set to the following values:
+ * "0" - Use ES profile of OpenGL, if available. (Default when not set.)
+ * "1" - Load OpenGL ES library using the default library names.
+ *
+ */
+#define SDL_HINT_OPENGL_ES_DRIVER "SDL_OPENGL_ES_DRIVER"
+
+/**
+ * \brief A variable controlling speed/quality tradeoff of audio resampling.
+ *
+ * If available, SDL can use libsamplerate ( http://www.mega-nerd.com/SRC/ )
+ * to handle audio resampling. There are different resampling modes available
+ * that produce different levels of quality, using more CPU.
+ *
+ * If this hint isn't specified to a valid setting, or libsamplerate isn't
+ * available, SDL will use the default, internal resampling algorithm.
+ *
+ * Note that this is currently only applicable to resampling audio that is
+ * being written to a device for playback or audio being read from a device
+ * for capture. SDL_AudioCVT always uses the default resampler (although this
+ * might change for SDL 2.1).
+ *
+ * This hint is currently only checked at audio subsystem initialization.
+ *
+ * This variable can be set to the following values:
+ *
+ * "0" or "default" - Use SDL's internal resampling (Default when not set - low quality, fast)
+ * "1" or "fast" - Use fast, slightly higher quality resampling, if available
+ * "2" or "medium" - Use medium quality resampling, if available
+ * "3" or "best" - Use high quality resampling, if available
+ */
+#define SDL_HINT_AUDIO_RESAMPLING_MODE "SDL_AUDIO_RESAMPLING_MODE"
+
+/**
+ * \brief A variable controlling the audio category on iOS and Mac OS X
+ *
+ * This variable can be set to the following values:
+ *
+ * "ambient" - Use the AVAudioSessionCategoryAmbient audio category, will be muted by the phone mute switch (default)
+ * "playback" - Use the AVAudioSessionCategoryPlayback category
+ *
+ * For more information, see Apple's documentation:
+ * https://developer.apple.com/library/content/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioSessionCategoriesandModes/AudioSessionCategoriesandModes.html
+ */
+#define SDL_HINT_AUDIO_CATEGORY "SDL_AUDIO_CATEGORY"
+
+/**
+ * \brief An enumeration of hint priorities
+ */
+typedef enum
+{
+ SDL_HINT_DEFAULT,
+ SDL_HINT_NORMAL,
+ SDL_HINT_OVERRIDE
+} SDL_HintPriority;
+
+
+/**
+ * \brief Set a hint with a specific priority
+ *
+ * The priority controls the behavior when setting a hint that already
+ * has a value. Hints will replace existing hints of their priority and
+ * lower. Environment variables are considered to have override priority.
+ *
+ * \return SDL_TRUE if the hint was set, SDL_FALSE otherwise
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_SetHintWithPriority(const char *name,
+ const char *value,
+ SDL_HintPriority priority);
+
+/**
+ * \brief Set a hint with normal priority
+ *
+ * \return SDL_TRUE if the hint was set, SDL_FALSE otherwise
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_SetHint(const char *name,
+ const char *value);
+
+/**
+ * \brief Get a hint
+ *
+ * \return The string value of a hint variable.
+ */
+extern DECLSPEC const char * SDLCALL SDL_GetHint(const char *name);
+
+/**
+ * \brief Get a hint
+ *
+ * \return The boolean value of a hint variable.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_GetHintBoolean(const char *name, SDL_bool default_value);
+
+/**
+ * \brief type definition of the hint callback function.
+ */
+typedef void (SDLCALL *SDL_HintCallback)(void *userdata, const char *name, const char *oldValue, const char *newValue);
+
+/**
+ * \brief Add a function to watch a particular hint
+ *
+ * \param name The hint to watch
+ * \param callback The function to call when the hint value changes
+ * \param userdata A pointer to pass to the callback function
+ */
+extern DECLSPEC void SDLCALL SDL_AddHintCallback(const char *name,
+ SDL_HintCallback callback,
+ void *userdata);
+
+/**
+ * \brief Remove a function watching a particular hint
+ *
+ * \param name The hint being watched
+ * \param callback The function being called when the hint value changes
+ * \param userdata A pointer being passed to the callback function
+ */
+extern DECLSPEC void SDLCALL SDL_DelHintCallback(const char *name,
+ SDL_HintCallback callback,
+ void *userdata);
+
+/**
+ * \brief Clear all hints
+ *
+ * This function is called during SDL_Quit() to free stored hints.
+ */
+extern DECLSPEC void SDLCALL SDL_ClearHints(void);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_hints_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_joystick.h b/src/3rdparty/SDL2/include/SDL2/SDL_joystick.h
new file mode 100644
index 0000000..f67772d
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_joystick.h
@@ -0,0 +1,382 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_joystick.h
+ *
+ * Include file for SDL joystick event handling
+ *
+ * The term "device_index" identifies currently plugged in joystick devices between 0 and SDL_NumJoysticks(), with the exact joystick
+ * behind a device_index changing as joysticks are plugged and unplugged.
+ *
+ * The term "instance_id" is the current instantiation of a joystick device in the system, if the joystick is removed and then re-inserted
+ * then it will get a new instance_id, instance_id's are monotonically increasing identifiers of a joystick plugged in.
+ *
+ * The term JoystickGUID is a stable 128-bit identifier for a joystick device that does not change over time, it identifies class of
+ * the device (a X360 wired controller for example). This identifier is platform dependent.
+ *
+ *
+ */
+
+#ifndef SDL_joystick_h_
+#define SDL_joystick_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \file SDL_joystick.h
+ *
+ * In order to use these functions, SDL_Init() must have been called
+ * with the ::SDL_INIT_JOYSTICK flag. This causes SDL to scan the system
+ * for joysticks, and load appropriate drivers.
+ *
+ * If you would like to receive joystick updates while the application
+ * is in the background, you should set the following hint before calling
+ * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
+ */
+
+/**
+ * The joystick structure used to identify an SDL joystick
+ */
+struct _SDL_Joystick;
+typedef struct _SDL_Joystick SDL_Joystick;
+
+/* A structure that encodes the stable unique id for a joystick device */
+typedef struct {
+ Uint8 data[16];
+} SDL_JoystickGUID;
+
+/**
+ * This is a unique ID for a joystick for the time it is connected to the system,
+ * and is never reused for the lifetime of the application. If the joystick is
+ * disconnected and reconnected, it will get a new ID.
+ *
+ * The ID value starts at 0 and increments from there. The value -1 is an invalid ID.
+ */
+typedef Sint32 SDL_JoystickID;
+
+typedef enum
+{
+ SDL_JOYSTICK_TYPE_UNKNOWN,
+ SDL_JOYSTICK_TYPE_GAMECONTROLLER,
+ SDL_JOYSTICK_TYPE_WHEEL,
+ SDL_JOYSTICK_TYPE_ARCADE_STICK,
+ SDL_JOYSTICK_TYPE_FLIGHT_STICK,
+ SDL_JOYSTICK_TYPE_DANCE_PAD,
+ SDL_JOYSTICK_TYPE_GUITAR,
+ SDL_JOYSTICK_TYPE_DRUM_KIT,
+ SDL_JOYSTICK_TYPE_ARCADE_PAD,
+ SDL_JOYSTICK_TYPE_THROTTLE
+} SDL_JoystickType;
+
+typedef enum
+{
+ SDL_JOYSTICK_POWER_UNKNOWN = -1,
+ SDL_JOYSTICK_POWER_EMPTY,
+ SDL_JOYSTICK_POWER_LOW,
+ SDL_JOYSTICK_POWER_MEDIUM,
+ SDL_JOYSTICK_POWER_FULL,
+ SDL_JOYSTICK_POWER_WIRED,
+ SDL_JOYSTICK_POWER_MAX
+} SDL_JoystickPowerLevel;
+
+/* Function prototypes */
+
+/**
+ * Locking for multi-threaded access to the joystick API
+ *
+ * If you are using the joystick API or handling events from multiple threads
+ * you should use these locking functions to protect access to the joysticks.
+ *
+ * In particular, you are guaranteed that the joystick list won't change, so
+ * the API functions that take a joystick index will be valid, and joystick
+ * and game controller events will not be delivered.
+ */
+extern DECLSPEC void SDLCALL SDL_LockJoysticks(void);
+extern DECLSPEC void SDLCALL SDL_UnlockJoysticks(void);
+
+/**
+ * Count the number of joysticks attached to the system right now
+ */
+extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
+
+/**
+ * Get the implementation dependent name of a joystick.
+ * This can be called before any joysticks are opened.
+ * If no name can be found, this function returns NULL.
+ */
+extern DECLSPEC const char *SDLCALL SDL_JoystickNameForIndex(int device_index);
+
+/**
+ * Return the GUID for the joystick at this index
+ * This can be called before any joysticks are opened.
+ */
+extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);
+
+/**
+ * Get the USB vendor ID of a joystick, if available.
+ * This can be called before any joysticks are opened.
+ * If the vendor ID isn't available this function returns 0.
+ */
+extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceVendor(int device_index);
+
+/**
+ * Get the USB product ID of a joystick, if available.
+ * This can be called before any joysticks are opened.
+ * If the product ID isn't available this function returns 0.
+ */
+extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProduct(int device_index);
+
+/**
+ * Get the product version of a joystick, if available.
+ * This can be called before any joysticks are opened.
+ * If the product version isn't available this function returns 0.
+ */
+extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProductVersion(int device_index);
+
+/**
+ * Get the type of a joystick, if available.
+ * This can be called before any joysticks are opened.
+ */
+extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetDeviceType(int device_index);
+
+/**
+ * Get the instance ID of a joystick.
+ * This can be called before any joysticks are opened.
+ * If the index is out of range, this function will return -1.
+ */
+extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickGetDeviceInstanceID(int device_index);
+
+/**
+ * Open a joystick for use.
+ * The index passed as an argument refers to the N'th joystick on the system.
+ * This index is not the value which will identify this joystick in future
+ * joystick events. The joystick's instance id (::SDL_JoystickID) will be used
+ * there instead.
+ *
+ * \return A joystick identifier, or NULL if an error occurred.
+ */
+extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);
+
+/**
+ * Return the SDL_Joystick associated with an instance id.
+ */
+extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromInstanceID(SDL_JoystickID joyid);
+
+/**
+ * Return the name for this currently opened joystick.
+ * If no name can be found, this function returns NULL.
+ */
+extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick * joystick);
+
+/**
+ * Return the GUID for this opened joystick
+ */
+extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick);
+
+/**
+ * Get the USB vendor ID of an opened joystick, if available.
+ * If the vendor ID isn't available this function returns 0.
+ */
+extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetVendor(SDL_Joystick * joystick);
+
+/**
+ * Get the USB product ID of an opened joystick, if available.
+ * If the product ID isn't available this function returns 0.
+ */
+extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProduct(SDL_Joystick * joystick);
+
+/**
+ * Get the product version of an opened joystick, if available.
+ * If the product version isn't available this function returns 0.
+ */
+extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProductVersion(SDL_Joystick * joystick);
+
+/**
+ * Get the type of an opened joystick.
+ */
+extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetType(SDL_Joystick * joystick);
+
+/**
+ * Return a string representation for this guid. pszGUID must point to at least 33 bytes
+ * (32 for the string plus a NULL terminator).
+ */
+extern DECLSPEC void SDLCALL SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);
+
+/**
+ * Convert a string into a joystick guid
+ */
+extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
+
+/**
+ * Returns SDL_TRUE if the joystick has been opened and currently connected, or SDL_FALSE if it has not.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick * joystick);
+
+/**
+ * Get the instance ID of an opened joystick or -1 if the joystick is invalid.
+ */
+extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick * joystick);
+
+/**
+ * Get the number of general axis controls on a joystick.
+ */
+extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick);
+
+/**
+ * Get the number of trackballs on a joystick.
+ *
+ * Joystick trackballs have only relative motion events associated
+ * with them and their state cannot be polled.
+ */
+extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick * joystick);
+
+/**
+ * Get the number of POV hats on a joystick.
+ */
+extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick * joystick);
+
+/**
+ * Get the number of buttons on a joystick.
+ */
+extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick * joystick);
+
+/**
+ * Update the current state of the open joysticks.
+ *
+ * This is called automatically by the event loop if any joystick
+ * events are enabled.
+ */
+extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
+
+/**
+ * Enable/disable joystick event polling.
+ *
+ * If joystick events are disabled, you must call SDL_JoystickUpdate()
+ * yourself and check the state of the joystick when you want joystick
+ * information.
+ *
+ * The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE.
+ */
+extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
+
+#define SDL_JOYSTICK_AXIS_MAX 32767
+#define SDL_JOYSTICK_AXIS_MIN -32768
+/**
+ * Get the current state of an axis control on a joystick.
+ *
+ * The state is a value ranging from -32768 to 32767.
+ *
+ * The axis indices start at index 0.
+ */
+extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick * joystick,
+ int axis);
+
+/**
+ * Get the initial state of an axis control on a joystick.
+ *
+ * The state is a value ranging from -32768 to 32767.
+ *
+ * The axis indices start at index 0.
+ *
+ * \return SDL_TRUE if this axis has any initial value, or SDL_FALSE if not.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAxisInitialState(SDL_Joystick * joystick,
+ int axis, Sint16 *state);
+
+/**
+ * \name Hat positions
+ */
+/* @{ */
+#define SDL_HAT_CENTERED 0x00
+#define SDL_HAT_UP 0x01
+#define SDL_HAT_RIGHT 0x02
+#define SDL_HAT_DOWN 0x04
+#define SDL_HAT_LEFT 0x08
+#define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
+#define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
+#define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
+#define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
+/* @} */
+
+/**
+ * Get the current state of a POV hat on a joystick.
+ *
+ * The hat indices start at index 0.
+ *
+ * \return The return value is one of the following positions:
+ * - ::SDL_HAT_CENTERED
+ * - ::SDL_HAT_UP
+ * - ::SDL_HAT_RIGHT
+ * - ::SDL_HAT_DOWN
+ * - ::SDL_HAT_LEFT
+ * - ::SDL_HAT_RIGHTUP
+ * - ::SDL_HAT_RIGHTDOWN
+ * - ::SDL_HAT_LEFTUP
+ * - ::SDL_HAT_LEFTDOWN
+ */
+extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick * joystick,
+ int hat);
+
+/**
+ * Get the ball axis change since the last poll.
+ *
+ * \return 0, or -1 if you passed it invalid parameters.
+ *
+ * The ball indices start at index 0.
+ */
+extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick * joystick,
+ int ball, int *dx, int *dy);
+
+/**
+ * Get the current state of a button on a joystick.
+ *
+ * The button indices start at index 0.
+ */
+extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick,
+ int button);
+
+/**
+ * Close a joystick previously opened with SDL_JoystickOpen().
+ */
+extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick);
+
+/**
+ * Return the battery level of this joystick
+ */
+extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_joystick_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_keyboard.h b/src/3rdparty/SDL2/include/SDL2/SDL_keyboard.h
new file mode 100644
index 0000000..8748231
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_keyboard.h
@@ -0,0 +1,217 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_keyboard.h
+ *
+ * Include file for SDL keyboard event handling
+ */
+
+#ifndef SDL_keyboard_h_
+#define SDL_keyboard_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_keycode.h"
+#include "SDL_video.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The SDL keysym structure, used in key events.
+ *
+ * \note If you are looking for translated character input, see the ::SDL_TEXTINPUT event.
+ */
+typedef struct SDL_Keysym
+{
+ SDL_Scancode scancode; /**< SDL physical key code - see ::SDL_Scancode for details */
+ SDL_Keycode sym; /**< SDL virtual key code - see ::SDL_Keycode for details */
+ Uint16 mod; /**< current key modifiers */
+ Uint32 unused;
+} SDL_Keysym;
+
+/* Function prototypes */
+
+/**
+ * \brief Get the window which currently has keyboard focus.
+ */
+extern DECLSPEC SDL_Window * SDLCALL SDL_GetKeyboardFocus(void);
+
+/**
+ * \brief Get a snapshot of the current state of the keyboard.
+ *
+ * \param numkeys if non-NULL, receives the length of the returned array.
+ *
+ * \return An array of key states. Indexes into this array are obtained by using ::SDL_Scancode values.
+ *
+ * \b Example:
+ * \code
+ * const Uint8 *state = SDL_GetKeyboardState(NULL);
+ * if ( state[SDL_SCANCODE_RETURN] ) {
+ * printf("<RETURN> is pressed.\n");
+ * }
+ * \endcode
+ */
+extern DECLSPEC const Uint8 *SDLCALL SDL_GetKeyboardState(int *numkeys);
+
+/**
+ * \brief Get the current key modifier state for the keyboard.
+ */
+extern DECLSPEC SDL_Keymod SDLCALL SDL_GetModState(void);
+
+/**
+ * \brief Set the current key modifier state for the keyboard.
+ *
+ * \note This does not change the keyboard state, only the key modifier flags.
+ */
+extern DECLSPEC void SDLCALL SDL_SetModState(SDL_Keymod modstate);
+
+/**
+ * \brief Get the key code corresponding to the given scancode according
+ * to the current keyboard layout.
+ *
+ * See ::SDL_Keycode for details.
+ *
+ * \sa SDL_GetKeyName()
+ */
+extern DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromScancode(SDL_Scancode scancode);
+
+/**
+ * \brief Get the scancode corresponding to the given key code according to the
+ * current keyboard layout.
+ *
+ * See ::SDL_Scancode for details.
+ *
+ * \sa SDL_GetScancodeName()
+ */
+extern DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromKey(SDL_Keycode key);
+
+/**
+ * \brief Get a human-readable name for a scancode.
+ *
+ * \return A pointer to the name for the scancode.
+ * If the scancode doesn't have a name, this function returns
+ * an empty string ("").
+ *
+ * \sa SDL_Scancode
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_Scancode scancode);
+
+/**
+ * \brief Get a scancode from a human-readable name
+ *
+ * \return scancode, or SDL_SCANCODE_UNKNOWN if the name wasn't recognized
+ *
+ * \sa SDL_Scancode
+ */
+extern DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromName(const char *name);
+
+/**
+ * \brief Get a human-readable name for a key.
+ *
+ * \return A pointer to a UTF-8 string that stays valid at least until the next
+ * call to this function. If you need it around any longer, you must
+ * copy it. If the key doesn't have a name, this function returns an
+ * empty string ("").
+ *
+ * \sa SDL_Keycode
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDL_Keycode key);
+
+/**
+ * \brief Get a key code from a human-readable name
+ *
+ * \return key code, or SDLK_UNKNOWN if the name wasn't recognized
+ *
+ * \sa SDL_Keycode
+ */
+extern DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromName(const char *name);
+
+/**
+ * \brief Start accepting Unicode text input events.
+ * This function will show the on-screen keyboard if supported.
+ *
+ * \sa SDL_StopTextInput()
+ * \sa SDL_SetTextInputRect()
+ * \sa SDL_HasScreenKeyboardSupport()
+ */
+extern DECLSPEC void SDLCALL SDL_StartTextInput(void);
+
+/**
+ * \brief Return whether or not Unicode text input events are enabled.
+ *
+ * \sa SDL_StartTextInput()
+ * \sa SDL_StopTextInput()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_IsTextInputActive(void);
+
+/**
+ * \brief Stop receiving any text input events.
+ * This function will hide the on-screen keyboard if supported.
+ *
+ * \sa SDL_StartTextInput()
+ * \sa SDL_HasScreenKeyboardSupport()
+ */
+extern DECLSPEC void SDLCALL SDL_StopTextInput(void);
+
+/**
+ * \brief Set the rectangle used to type Unicode text inputs.
+ * This is used as a hint for IME and on-screen keyboard placement.
+ *
+ * \sa SDL_StartTextInput()
+ */
+extern DECLSPEC void SDLCALL SDL_SetTextInputRect(SDL_Rect *rect);
+
+/**
+ * \brief Returns whether the platform has some screen keyboard support.
+ *
+ * \return SDL_TRUE if some keyboard support is available else SDL_FALSE.
+ *
+ * \note Not all screen keyboard functions are supported on all platforms.
+ *
+ * \sa SDL_IsScreenKeyboardShown()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasScreenKeyboardSupport(void);
+
+/**
+ * \brief Returns whether the screen keyboard is shown for given window.
+ *
+ * \param window The window for which screen keyboard should be queried.
+ *
+ * \return SDL_TRUE if screen keyboard is shown else SDL_FALSE.
+ *
+ * \sa SDL_HasScreenKeyboardSupport()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_IsScreenKeyboardShown(SDL_Window *window);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_keyboard_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_keycode.h b/src/3rdparty/SDL2/include/SDL2/SDL_keycode.h
new file mode 100644
index 0000000..d7d5b1d
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_keycode.h
@@ -0,0 +1,349 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_keycode.h
+ *
+ * Defines constants which identify keyboard keys and modifiers.
+ */
+
+#ifndef SDL_keycode_h_
+#define SDL_keycode_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_scancode.h"
+
+/**
+ * \brief The SDL virtual key representation.
+ *
+ * Values of this type are used to represent keyboard keys using the current
+ * layout of the keyboard. These values include Unicode values representing
+ * the unmodified character that would be generated by pressing the key, or
+ * an SDLK_* constant for those keys that do not generate characters.
+ *
+ * A special exception is the number keys at the top of the keyboard which
+ * always map to SDLK_0...SDLK_9, regardless of layout.
+ */
+typedef Sint32 SDL_Keycode;
+
+#define SDLK_SCANCODE_MASK (1<<30)
+#define SDL_SCANCODE_TO_KEYCODE(X) (X | SDLK_SCANCODE_MASK)
+
+enum
+{
+ SDLK_UNKNOWN = 0,
+
+ SDLK_RETURN = '\r',
+ SDLK_ESCAPE = '\033',
+ SDLK_BACKSPACE = '\b',
+ SDLK_TAB = '\t',
+ SDLK_SPACE = ' ',
+ SDLK_EXCLAIM = '!',
+ SDLK_QUOTEDBL = '"',
+ SDLK_HASH = '#',
+ SDLK_PERCENT = '%',
+ SDLK_DOLLAR = '$',
+ SDLK_AMPERSAND = '&',
+ SDLK_QUOTE = '\'',
+ SDLK_LEFTPAREN = '(',
+ SDLK_RIGHTPAREN = ')',
+ SDLK_ASTERISK = '*',
+ SDLK_PLUS = '+',
+ SDLK_COMMA = ',',
+ SDLK_MINUS = '-',
+ SDLK_PERIOD = '.',
+ SDLK_SLASH = '/',
+ SDLK_0 = '0',
+ SDLK_1 = '1',
+ SDLK_2 = '2',
+ SDLK_3 = '3',
+ SDLK_4 = '4',
+ SDLK_5 = '5',
+ SDLK_6 = '6',
+ SDLK_7 = '7',
+ SDLK_8 = '8',
+ SDLK_9 = '9',
+ SDLK_COLON = ':',
+ SDLK_SEMICOLON = ';',
+ SDLK_LESS = '<',
+ SDLK_EQUALS = '=',
+ SDLK_GREATER = '>',
+ SDLK_QUESTION = '?',
+ SDLK_AT = '@',
+ /*
+ Skip uppercase letters
+ */
+ SDLK_LEFTBRACKET = '[',
+ SDLK_BACKSLASH = '\\',
+ SDLK_RIGHTBRACKET = ']',
+ SDLK_CARET = '^',
+ SDLK_UNDERSCORE = '_',
+ SDLK_BACKQUOTE = '`',
+ SDLK_a = 'a',
+ SDLK_b = 'b',
+ SDLK_c = 'c',
+ SDLK_d = 'd',
+ SDLK_e = 'e',
+ SDLK_f = 'f',
+ SDLK_g = 'g',
+ SDLK_h = 'h',
+ SDLK_i = 'i',
+ SDLK_j = 'j',
+ SDLK_k = 'k',
+ SDLK_l = 'l',
+ SDLK_m = 'm',
+ SDLK_n = 'n',
+ SDLK_o = 'o',
+ SDLK_p = 'p',
+ SDLK_q = 'q',
+ SDLK_r = 'r',
+ SDLK_s = 's',
+ SDLK_t = 't',
+ SDLK_u = 'u',
+ SDLK_v = 'v',
+ SDLK_w = 'w',
+ SDLK_x = 'x',
+ SDLK_y = 'y',
+ SDLK_z = 'z',
+
+ SDLK_CAPSLOCK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CAPSLOCK),
+
+ SDLK_F1 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F1),
+ SDLK_F2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F2),
+ SDLK_F3 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F3),
+ SDLK_F4 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F4),
+ SDLK_F5 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F5),
+ SDLK_F6 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F6),
+ SDLK_F7 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F7),
+ SDLK_F8 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F8),
+ SDLK_F9 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F9),
+ SDLK_F10 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F10),
+ SDLK_F11 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F11),
+ SDLK_F12 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F12),
+
+ SDLK_PRINTSCREEN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PRINTSCREEN),
+ SDLK_SCROLLLOCK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SCROLLLOCK),
+ SDLK_PAUSE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAUSE),
+ SDLK_INSERT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INSERT),
+ SDLK_HOME = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HOME),
+ SDLK_PAGEUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEUP),
+ SDLK_DELETE = '\177',
+ SDLK_END = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_END),
+ SDLK_PAGEDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEDOWN),
+ SDLK_RIGHT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RIGHT),
+ SDLK_LEFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LEFT),
+ SDLK_DOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DOWN),
+ SDLK_UP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_UP),
+
+ SDLK_NUMLOCKCLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_NUMLOCKCLEAR),
+ SDLK_KP_DIVIDE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DIVIDE),
+ SDLK_KP_MULTIPLY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MULTIPLY),
+ SDLK_KP_MINUS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MINUS),
+ SDLK_KP_PLUS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PLUS),
+ SDLK_KP_ENTER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_ENTER),
+ SDLK_KP_1 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_1),
+ SDLK_KP_2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_2),
+ SDLK_KP_3 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_3),
+ SDLK_KP_4 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_4),
+ SDLK_KP_5 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_5),
+ SDLK_KP_6 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_6),
+ SDLK_KP_7 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_7),
+ SDLK_KP_8 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_8),
+ SDLK_KP_9 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_9),
+ SDLK_KP_0 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_0),
+ SDLK_KP_PERIOD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PERIOD),
+
+ SDLK_APPLICATION = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_APPLICATION),
+ SDLK_POWER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_POWER),
+ SDLK_KP_EQUALS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EQUALS),
+ SDLK_F13 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F13),
+ SDLK_F14 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F14),
+ SDLK_F15 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F15),
+ SDLK_F16 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F16),
+ SDLK_F17 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F17),
+ SDLK_F18 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F18),
+ SDLK_F19 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F19),
+ SDLK_F20 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F20),
+ SDLK_F21 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F21),
+ SDLK_F22 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F22),
+ SDLK_F23 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F23),
+ SDLK_F24 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F24),
+ SDLK_EXECUTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EXECUTE),
+ SDLK_HELP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HELP),
+ SDLK_MENU = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MENU),
+ SDLK_SELECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SELECT),
+ SDLK_STOP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_STOP),
+ SDLK_AGAIN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AGAIN),
+ SDLK_UNDO = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_UNDO),
+ SDLK_CUT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CUT),
+ SDLK_COPY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_COPY),
+ SDLK_PASTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PASTE),
+ SDLK_FIND = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_FIND),
+ SDLK_MUTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MUTE),
+ SDLK_VOLUMEUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_VOLUMEUP),
+ SDLK_VOLUMEDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_VOLUMEDOWN),
+ SDLK_KP_COMMA = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_COMMA),
+ SDLK_KP_EQUALSAS400 =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EQUALSAS400),
+
+ SDLK_ALTERASE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_ALTERASE),
+ SDLK_SYSREQ = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SYSREQ),
+ SDLK_CANCEL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CANCEL),
+ SDLK_CLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CLEAR),
+ SDLK_PRIOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PRIOR),
+ SDLK_RETURN2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RETURN2),
+ SDLK_SEPARATOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SEPARATOR),
+ SDLK_OUT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_OUT),
+ SDLK_OPER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_OPER),
+ SDLK_CLEARAGAIN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CLEARAGAIN),
+ SDLK_CRSEL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CRSEL),
+ SDLK_EXSEL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EXSEL),
+
+ SDLK_KP_00 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_00),
+ SDLK_KP_000 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_000),
+ SDLK_THOUSANDSSEPARATOR =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_THOUSANDSSEPARATOR),
+ SDLK_DECIMALSEPARATOR =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DECIMALSEPARATOR),
+ SDLK_CURRENCYUNIT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CURRENCYUNIT),
+ SDLK_CURRENCYSUBUNIT =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CURRENCYSUBUNIT),
+ SDLK_KP_LEFTPAREN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LEFTPAREN),
+ SDLK_KP_RIGHTPAREN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_RIGHTPAREN),
+ SDLK_KP_LEFTBRACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LEFTBRACE),
+ SDLK_KP_RIGHTBRACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_RIGHTBRACE),
+ SDLK_KP_TAB = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_TAB),
+ SDLK_KP_BACKSPACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_BACKSPACE),
+ SDLK_KP_A = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_A),
+ SDLK_KP_B = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_B),
+ SDLK_KP_C = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_C),
+ SDLK_KP_D = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_D),
+ SDLK_KP_E = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_E),
+ SDLK_KP_F = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_F),
+ SDLK_KP_XOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_XOR),
+ SDLK_KP_POWER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_POWER),
+ SDLK_KP_PERCENT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PERCENT),
+ SDLK_KP_LESS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LESS),
+ SDLK_KP_GREATER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_GREATER),
+ SDLK_KP_AMPERSAND = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_AMPERSAND),
+ SDLK_KP_DBLAMPERSAND =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DBLAMPERSAND),
+ SDLK_KP_VERTICALBAR =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_VERTICALBAR),
+ SDLK_KP_DBLVERTICALBAR =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DBLVERTICALBAR),
+ SDLK_KP_COLON = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_COLON),
+ SDLK_KP_HASH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_HASH),
+ SDLK_KP_SPACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_SPACE),
+ SDLK_KP_AT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_AT),
+ SDLK_KP_EXCLAM = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EXCLAM),
+ SDLK_KP_MEMSTORE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMSTORE),
+ SDLK_KP_MEMRECALL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMRECALL),
+ SDLK_KP_MEMCLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMCLEAR),
+ SDLK_KP_MEMADD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMADD),
+ SDLK_KP_MEMSUBTRACT =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMSUBTRACT),
+ SDLK_KP_MEMMULTIPLY =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMMULTIPLY),
+ SDLK_KP_MEMDIVIDE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMDIVIDE),
+ SDLK_KP_PLUSMINUS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PLUSMINUS),
+ SDLK_KP_CLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_CLEAR),
+ SDLK_KP_CLEARENTRY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_CLEARENTRY),
+ SDLK_KP_BINARY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_BINARY),
+ SDLK_KP_OCTAL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_OCTAL),
+ SDLK_KP_DECIMAL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DECIMAL),
+ SDLK_KP_HEXADECIMAL =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_HEXADECIMAL),
+
+ SDLK_LCTRL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LCTRL),
+ SDLK_LSHIFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LSHIFT),
+ SDLK_LALT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LALT),
+ SDLK_LGUI = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LGUI),
+ SDLK_RCTRL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RCTRL),
+ SDLK_RSHIFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RSHIFT),
+ SDLK_RALT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RALT),
+ SDLK_RGUI = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RGUI),
+
+ SDLK_MODE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MODE),
+
+ SDLK_AUDIONEXT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIONEXT),
+ SDLK_AUDIOPREV = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOPREV),
+ SDLK_AUDIOSTOP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOSTOP),
+ SDLK_AUDIOPLAY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOPLAY),
+ SDLK_AUDIOMUTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOMUTE),
+ SDLK_MEDIASELECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIASELECT),
+ SDLK_WWW = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_WWW),
+ SDLK_MAIL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MAIL),
+ SDLK_CALCULATOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CALCULATOR),
+ SDLK_COMPUTER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_COMPUTER),
+ SDLK_AC_SEARCH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_SEARCH),
+ SDLK_AC_HOME = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_HOME),
+ SDLK_AC_BACK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_BACK),
+ SDLK_AC_FORWARD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_FORWARD),
+ SDLK_AC_STOP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_STOP),
+ SDLK_AC_REFRESH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_REFRESH),
+ SDLK_AC_BOOKMARKS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_BOOKMARKS),
+
+ SDLK_BRIGHTNESSDOWN =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_BRIGHTNESSDOWN),
+ SDLK_BRIGHTNESSUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_BRIGHTNESSUP),
+ SDLK_DISPLAYSWITCH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DISPLAYSWITCH),
+ SDLK_KBDILLUMTOGGLE =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMTOGGLE),
+ SDLK_KBDILLUMDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMDOWN),
+ SDLK_KBDILLUMUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMUP),
+ SDLK_EJECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EJECT),
+ SDLK_SLEEP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SLEEP),
+ SDLK_APP1 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_APP1),
+ SDLK_APP2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_APP2),
+
+ SDLK_AUDIOREWIND = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOREWIND),
+ SDLK_AUDIOFASTFORWARD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOFASTFORWARD)
+};
+
+/**
+ * \brief Enumeration of valid key mods (possibly OR'd together).
+ */
+typedef enum
+{
+ KMOD_NONE = 0x0000,
+ KMOD_LSHIFT = 0x0001,
+ KMOD_RSHIFT = 0x0002,
+ KMOD_LCTRL = 0x0040,
+ KMOD_RCTRL = 0x0080,
+ KMOD_LALT = 0x0100,
+ KMOD_RALT = 0x0200,
+ KMOD_LGUI = 0x0400,
+ KMOD_RGUI = 0x0800,
+ KMOD_NUM = 0x1000,
+ KMOD_CAPS = 0x2000,
+ KMOD_MODE = 0x4000,
+ KMOD_RESERVED = 0x8000
+} SDL_Keymod;
+
+#define KMOD_CTRL (KMOD_LCTRL|KMOD_RCTRL)
+#define KMOD_SHIFT (KMOD_LSHIFT|KMOD_RSHIFT)
+#define KMOD_ALT (KMOD_LALT|KMOD_RALT)
+#define KMOD_GUI (KMOD_LGUI|KMOD_RGUI)
+
+#endif /* SDL_keycode_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_loadso.h b/src/3rdparty/SDL2/include/SDL2/SDL_loadso.h
new file mode 100644
index 0000000..da56fb4
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_loadso.h
@@ -0,0 +1,81 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_loadso.h
+ *
+ * System dependent library loading routines
+ *
+ * Some things to keep in mind:
+ * \li These functions only work on C function names. Other languages may
+ * have name mangling and intrinsic language support that varies from
+ * compiler to compiler.
+ * \li Make sure you declare your function pointers with the same calling
+ * convention as the actual library function. Your code will crash
+ * mysteriously if you do not do this.
+ * \li Avoid namespace collisions. If you load a symbol from the library,
+ * it is not defined whether or not it goes into the global symbol
+ * namespace for the application. If it does and it conflicts with
+ * symbols in your code or other shared libraries, you will not get
+ * the results you expect. :)
+ */
+
+#ifndef SDL_loadso_h_
+#define SDL_loadso_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This function dynamically loads a shared object and returns a pointer
+ * to the object handle (or NULL if there was an error).
+ * The 'sofile' parameter is a system dependent name of the object file.
+ */
+extern DECLSPEC void *SDLCALL SDL_LoadObject(const char *sofile);
+
+/**
+ * Given an object handle, this function looks up the address of the
+ * named function in the shared object and returns it. This address
+ * is no longer valid after calling SDL_UnloadObject().
+ */
+extern DECLSPEC void *SDLCALL SDL_LoadFunction(void *handle,
+ const char *name);
+
+/**
+ * Unload a shared object from memory.
+ */
+extern DECLSPEC void SDLCALL SDL_UnloadObject(void *handle);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_loadso_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_log.h b/src/3rdparty/SDL2/include/SDL2/SDL_log.h
new file mode 100644
index 0000000..e12b658
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_log.h
@@ -0,0 +1,211 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_log.h
+ *
+ * Simple log messages with categories and priorities.
+ *
+ * By default logs are quiet, but if you're debugging SDL you might want:
+ *
+ * SDL_LogSetAllPriority(SDL_LOG_PRIORITY_WARN);
+ *
+ * Here's where the messages go on different platforms:
+ * Windows: debug output stream
+ * Android: log output
+ * Others: standard error output (stderr)
+ */
+
+#ifndef SDL_log_h_
+#define SDL_log_h_
+
+#include "SDL_stdinc.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * \brief The maximum size of a log message
+ *
+ * Messages longer than the maximum size will be truncated
+ */
+#define SDL_MAX_LOG_MESSAGE 4096
+
+/**
+ * \brief The predefined log categories
+ *
+ * By default the application category is enabled at the INFO level,
+ * the assert category is enabled at the WARN level, test is enabled
+ * at the VERBOSE level and all other categories are enabled at the
+ * CRITICAL level.
+ */
+enum
+{
+ SDL_LOG_CATEGORY_APPLICATION,
+ SDL_LOG_CATEGORY_ERROR,
+ SDL_LOG_CATEGORY_ASSERT,
+ SDL_LOG_CATEGORY_SYSTEM,
+ SDL_LOG_CATEGORY_AUDIO,
+ SDL_LOG_CATEGORY_VIDEO,
+ SDL_LOG_CATEGORY_RENDER,
+ SDL_LOG_CATEGORY_INPUT,
+ SDL_LOG_CATEGORY_TEST,
+
+ /* Reserved for future SDL library use */
+ SDL_LOG_CATEGORY_RESERVED1,
+ SDL_LOG_CATEGORY_RESERVED2,
+ SDL_LOG_CATEGORY_RESERVED3,
+ SDL_LOG_CATEGORY_RESERVED4,
+ SDL_LOG_CATEGORY_RESERVED5,
+ SDL_LOG_CATEGORY_RESERVED6,
+ SDL_LOG_CATEGORY_RESERVED7,
+ SDL_LOG_CATEGORY_RESERVED8,
+ SDL_LOG_CATEGORY_RESERVED9,
+ SDL_LOG_CATEGORY_RESERVED10,
+
+ /* Beyond this point is reserved for application use, e.g.
+ enum {
+ MYAPP_CATEGORY_AWESOME1 = SDL_LOG_CATEGORY_CUSTOM,
+ MYAPP_CATEGORY_AWESOME2,
+ MYAPP_CATEGORY_AWESOME3,
+ ...
+ };
+ */
+ SDL_LOG_CATEGORY_CUSTOM
+};
+
+/**
+ * \brief The predefined log priorities
+ */
+typedef enum
+{
+ SDL_LOG_PRIORITY_VERBOSE = 1,
+ SDL_LOG_PRIORITY_DEBUG,
+ SDL_LOG_PRIORITY_INFO,
+ SDL_LOG_PRIORITY_WARN,
+ SDL_LOG_PRIORITY_ERROR,
+ SDL_LOG_PRIORITY_CRITICAL,
+ SDL_NUM_LOG_PRIORITIES
+} SDL_LogPriority;
+
+
+/**
+ * \brief Set the priority of all log categories
+ */
+extern DECLSPEC void SDLCALL SDL_LogSetAllPriority(SDL_LogPriority priority);
+
+/**
+ * \brief Set the priority of a particular log category
+ */
+extern DECLSPEC void SDLCALL SDL_LogSetPriority(int category,
+ SDL_LogPriority priority);
+
+/**
+ * \brief Get the priority of a particular log category
+ */
+extern DECLSPEC SDL_LogPriority SDLCALL SDL_LogGetPriority(int category);
+
+/**
+ * \brief Reset all priorities to default.
+ *
+ * \note This is called in SDL_Quit().
+ */
+extern DECLSPEC void SDLCALL SDL_LogResetPriorities(void);
+
+/**
+ * \brief Log a message with SDL_LOG_CATEGORY_APPLICATION and SDL_LOG_PRIORITY_INFO
+ */
+extern DECLSPEC void SDLCALL SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
+
+/**
+ * \brief Log a message with SDL_LOG_PRIORITY_VERBOSE
+ */
+extern DECLSPEC void SDLCALL SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
+
+/**
+ * \brief Log a message with SDL_LOG_PRIORITY_DEBUG
+ */
+extern DECLSPEC void SDLCALL SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
+
+/**
+ * \brief Log a message with SDL_LOG_PRIORITY_INFO
+ */
+extern DECLSPEC void SDLCALL SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
+
+/**
+ * \brief Log a message with SDL_LOG_PRIORITY_WARN
+ */
+extern DECLSPEC void SDLCALL SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
+
+/**
+ * \brief Log a message with SDL_LOG_PRIORITY_ERROR
+ */
+extern DECLSPEC void SDLCALL SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
+
+/**
+ * \brief Log a message with SDL_LOG_PRIORITY_CRITICAL
+ */
+extern DECLSPEC void SDLCALL SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
+
+/**
+ * \brief Log a message with the specified category and priority.
+ */
+extern DECLSPEC void SDLCALL SDL_LogMessage(int category,
+ SDL_LogPriority priority,
+ SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(3);
+
+/**
+ * \brief Log a message with the specified category and priority.
+ */
+extern DECLSPEC void SDLCALL SDL_LogMessageV(int category,
+ SDL_LogPriority priority,
+ const char *fmt, va_list ap);
+
+/**
+ * \brief The prototype for the log output function
+ */
+typedef void (SDLCALL *SDL_LogOutputFunction)(void *userdata, int category, SDL_LogPriority priority, const char *message);
+
+/**
+ * \brief Get the current log output function.
+ */
+extern DECLSPEC void SDLCALL SDL_LogGetOutputFunction(SDL_LogOutputFunction *callback, void **userdata);
+
+/**
+ * \brief This function allows you to replace the default log output
+ * function with one of your own.
+ */
+extern DECLSPEC void SDLCALL SDL_LogSetOutputFunction(SDL_LogOutputFunction callback, void *userdata);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_log_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_main.h b/src/3rdparty/SDL2/include/SDL2/SDL_main.h
new file mode 100644
index 0000000..9855821
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_main.h
@@ -0,0 +1,168 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_main_h_
+#define SDL_main_h_
+
+#include "SDL_stdinc.h"
+
+/**
+ * \file SDL_main.h
+ *
+ * Redefine main() on some platforms so that it is called by SDL.
+ */
+
+#ifndef SDL_MAIN_HANDLED
+#if defined(__WIN32__)
+/* On Windows SDL provides WinMain(), which parses the command line and passes
+ the arguments to your main function.
+
+ If you provide your own WinMain(), you may define SDL_MAIN_HANDLED
+ */
+#define SDL_MAIN_AVAILABLE
+
+#elif defined(__WINRT__)
+/* On WinRT, SDL provides a main function that initializes CoreApplication,
+ creating an instance of IFrameworkView in the process.
+
+ Please note that #include'ing SDL_main.h is not enough to get a main()
+ function working. In non-XAML apps, the file,
+ src/main/winrt/SDL_WinRT_main_NonXAML.cpp, or a copy of it, must be compiled
+ into the app itself. In XAML apps, the function, SDL_WinRTRunApp must be
+ called, with a pointer to the Direct3D-hosted XAML control passed in.
+*/
+#define SDL_MAIN_NEEDED
+
+#elif defined(__IPHONEOS__)
+/* On iOS SDL provides a main function that creates an application delegate
+ and starts the iOS application run loop.
+
+ See src/video/uikit/SDL_uikitappdelegate.m for more details.
+ */
+#define SDL_MAIN_NEEDED
+
+#elif defined(__ANDROID__)
+/* On Android SDL provides a Java class in SDLActivity.java that is the
+ main activity entry point.
+
+ See docs/README-android.md for more details on extending that class.
+ */
+#define SDL_MAIN_NEEDED
+
+/* We need to export SDL_main so it can be launched from Java */
+#define SDLMAIN_DECLSPEC DECLSPEC
+
+#elif defined(__NACL__)
+/* On NACL we use ppapi_simple to set up the application helper code,
+ then wait for the first PSE_INSTANCE_DIDCHANGEVIEW event before
+ starting the user main function.
+ All user code is run in a separate thread by ppapi_simple, thus
+ allowing for blocking io to take place via nacl_io
+*/
+#define SDL_MAIN_NEEDED
+
+#endif
+#endif /* SDL_MAIN_HANDLED */
+
+#ifdef __cplusplus
+#define C_LINKAGE "C"
+#else
+#define C_LINKAGE
+#endif /* __cplusplus */
+
+#ifndef SDLMAIN_DECLSPEC
+#define SDLMAIN_DECLSPEC
+#endif
+
+/**
+ * \file SDL_main.h
+ *
+ * The application's main() function must be called with C linkage,
+ * and should be declared like this:
+ * \code
+ * #ifdef __cplusplus
+ * extern "C"
+ * #endif
+ * int main(int argc, char *argv[])
+ * {
+ * }
+ * \endcode
+ */
+
+#if defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE)
+#define main SDL_main
+#endif
+
+/**
+ * The prototype for the application's main() function
+ */
+extern C_LINKAGE SDLMAIN_DECLSPEC int SDL_main(int argc, char *argv[]);
+
+
+#include "begin_code.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This is called by the real SDL main function to let the rest of the
+ * library know that initialization was done properly.
+ *
+ * Calling this yourself without knowing what you're doing can cause
+ * crashes and hard to diagnose problems with your application.
+ */
+extern DECLSPEC void SDLCALL SDL_SetMainReady(void);
+
+#ifdef __WIN32__
+
+/**
+ * This can be called to set the application class at startup
+ */
+extern DECLSPEC int SDLCALL SDL_RegisterApp(char *name, Uint32 style,
+ void *hInst);
+extern DECLSPEC void SDLCALL SDL_UnregisterApp(void);
+
+#endif /* __WIN32__ */
+
+
+#ifdef __WINRT__
+
+/**
+ * \brief Initializes and launches an SDL/WinRT application.
+ *
+ * \param mainFunction The SDL app's C-style main().
+ * \param reserved Reserved for future use; should be NULL
+ * \return 0 on success, -1 on failure. On failure, use SDL_GetError to retrieve more
+ * information on the failure.
+ */
+extern DECLSPEC int SDLCALL SDL_WinRTRunApp(int (*mainFunction)(int, char **), void * reserved);
+
+#endif /* __WINRT__ */
+
+
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_main_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_messagebox.h b/src/3rdparty/SDL2/include/SDL2/SDL_messagebox.h
new file mode 100644
index 0000000..b7be59d
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_messagebox.h
@@ -0,0 +1,144 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_messagebox_h_
+#define SDL_messagebox_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_video.h" /* For SDL_Window */
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief SDL_MessageBox flags. If supported will display warning icon, etc.
+ */
+typedef enum
+{
+ SDL_MESSAGEBOX_ERROR = 0x00000010, /**< error dialog */
+ SDL_MESSAGEBOX_WARNING = 0x00000020, /**< warning dialog */
+ SDL_MESSAGEBOX_INFORMATION = 0x00000040 /**< informational dialog */
+} SDL_MessageBoxFlags;
+
+/**
+ * \brief Flags for SDL_MessageBoxButtonData.
+ */
+typedef enum
+{
+ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT = 0x00000001, /**< Marks the default button when return is hit */
+ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT = 0x00000002 /**< Marks the default button when escape is hit */
+} SDL_MessageBoxButtonFlags;
+
+/**
+ * \brief Individual button data.
+ */
+typedef struct
+{
+ Uint32 flags; /**< ::SDL_MessageBoxButtonFlags */
+ int buttonid; /**< User defined button id (value returned via SDL_ShowMessageBox) */
+ const char * text; /**< The UTF-8 button text */
+} SDL_MessageBoxButtonData;
+
+/**
+ * \brief RGB value used in a message box color scheme
+ */
+typedef struct
+{
+ Uint8 r, g, b;
+} SDL_MessageBoxColor;
+
+typedef enum
+{
+ SDL_MESSAGEBOX_COLOR_BACKGROUND,
+ SDL_MESSAGEBOX_COLOR_TEXT,
+ SDL_MESSAGEBOX_COLOR_BUTTON_BORDER,
+ SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND,
+ SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED,
+ SDL_MESSAGEBOX_COLOR_MAX
+} SDL_MessageBoxColorType;
+
+/**
+ * \brief A set of colors to use for message box dialogs
+ */
+typedef struct
+{
+ SDL_MessageBoxColor colors[SDL_MESSAGEBOX_COLOR_MAX];
+} SDL_MessageBoxColorScheme;
+
+/**
+ * \brief MessageBox structure containing title, text, window, etc.
+ */
+typedef struct
+{
+ Uint32 flags; /**< ::SDL_MessageBoxFlags */
+ SDL_Window *window; /**< Parent window, can be NULL */
+ const char *title; /**< UTF-8 title */
+ const char *message; /**< UTF-8 message text */
+
+ int numbuttons;
+ const SDL_MessageBoxButtonData *buttons;
+
+ const SDL_MessageBoxColorScheme *colorScheme; /**< ::SDL_MessageBoxColorScheme, can be NULL to use system settings */
+} SDL_MessageBoxData;
+
+/**
+ * \brief Create a modal message box.
+ *
+ * \param messageboxdata The SDL_MessageBoxData structure with title, text, etc.
+ * \param buttonid The pointer to which user id of hit button should be copied.
+ *
+ * \return -1 on error, otherwise 0 and buttonid contains user id of button
+ * hit or -1 if dialog was closed.
+ *
+ * \note This function should be called on the thread that created the parent
+ * window, or on the main thread if the messagebox has no parent. It will
+ * block execution of that thread until the user clicks a button or
+ * closes the messagebox.
+ */
+extern DECLSPEC int SDLCALL SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
+
+/**
+ * \brief Create a simple modal message box
+ *
+ * \param flags ::SDL_MessageBoxFlags
+ * \param title UTF-8 title text
+ * \param message UTF-8 message text
+ * \param window The parent window, or NULL for no parent
+ *
+ * \return 0 on success, -1 on error
+ *
+ * \sa SDL_ShowMessageBox
+ */
+extern DECLSPEC int SDLCALL SDL_ShowSimpleMessageBox(Uint32 flags, const char *title, const char *message, SDL_Window *window);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_messagebox_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_mouse.h b/src/3rdparty/SDL2/include/SDL2/SDL_mouse.h
new file mode 100644
index 0000000..d3c9f61
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_mouse.h
@@ -0,0 +1,302 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_mouse.h
+ *
+ * Include file for SDL mouse event handling.
+ */
+
+#ifndef SDL_mouse_h_
+#define SDL_mouse_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_video.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct SDL_Cursor SDL_Cursor; /**< Implementation dependent */
+
+/**
+ * \brief Cursor types for SDL_CreateSystemCursor().
+ */
+typedef enum
+{
+ SDL_SYSTEM_CURSOR_ARROW, /**< Arrow */
+ SDL_SYSTEM_CURSOR_IBEAM, /**< I-beam */
+ SDL_SYSTEM_CURSOR_WAIT, /**< Wait */
+ SDL_SYSTEM_CURSOR_CROSSHAIR, /**< Crosshair */
+ SDL_SYSTEM_CURSOR_WAITARROW, /**< Small wait cursor (or Wait if not available) */
+ SDL_SYSTEM_CURSOR_SIZENWSE, /**< Double arrow pointing northwest and southeast */
+ SDL_SYSTEM_CURSOR_SIZENESW, /**< Double arrow pointing northeast and southwest */
+ SDL_SYSTEM_CURSOR_SIZEWE, /**< Double arrow pointing west and east */
+ SDL_SYSTEM_CURSOR_SIZENS, /**< Double arrow pointing north and south */
+ SDL_SYSTEM_CURSOR_SIZEALL, /**< Four pointed arrow pointing north, south, east, and west */
+ SDL_SYSTEM_CURSOR_NO, /**< Slashed circle or crossbones */
+ SDL_SYSTEM_CURSOR_HAND, /**< Hand */
+ SDL_NUM_SYSTEM_CURSORS
+} SDL_SystemCursor;
+
+/**
+ * \brief Scroll direction types for the Scroll event
+ */
+typedef enum
+{
+ SDL_MOUSEWHEEL_NORMAL, /**< The scroll direction is normal */
+ SDL_MOUSEWHEEL_FLIPPED /**< The scroll direction is flipped / natural */
+} SDL_MouseWheelDirection;
+
+/* Function prototypes */
+
+/**
+ * \brief Get the window which currently has mouse focus.
+ */
+extern DECLSPEC SDL_Window * SDLCALL SDL_GetMouseFocus(void);
+
+/**
+ * \brief Retrieve the current state of the mouse.
+ *
+ * The current button state is returned as a button bitmask, which can
+ * be tested using the SDL_BUTTON(X) macros, and x and y are set to the
+ * mouse cursor position relative to the focus window for the currently
+ * selected mouse. You can pass NULL for either x or y.
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_GetMouseState(int *x, int *y);
+
+/**
+ * \brief Get the current state of the mouse, in relation to the desktop
+ *
+ * This works just like SDL_GetMouseState(), but the coordinates will be
+ * reported relative to the top-left of the desktop. This can be useful if
+ * you need to track the mouse outside of a specific window and
+ * SDL_CaptureMouse() doesn't fit your needs. For example, it could be
+ * useful if you need to track the mouse while dragging a window, where
+ * coordinates relative to a window might not be in sync at all times.
+ *
+ * \note SDL_GetMouseState() returns the mouse position as SDL understands
+ * it from the last pump of the event queue. This function, however,
+ * queries the OS for the current mouse position, and as such, might
+ * be a slightly less efficient function. Unless you know what you're
+ * doing and have a good reason to use this function, you probably want
+ * SDL_GetMouseState() instead.
+ *
+ * \param x Returns the current X coord, relative to the desktop. Can be NULL.
+ * \param y Returns the current Y coord, relative to the desktop. Can be NULL.
+ * \return The current button state as a bitmask, which can be tested using the SDL_BUTTON(X) macros.
+ *
+ * \sa SDL_GetMouseState
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_GetGlobalMouseState(int *x, int *y);
+
+/**
+ * \brief Retrieve the relative state of the mouse.
+ *
+ * The current button state is returned as a button bitmask, which can
+ * be tested using the SDL_BUTTON(X) macros, and x and y are set to the
+ * mouse deltas since the last call to SDL_GetRelativeMouseState().
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_GetRelativeMouseState(int *x, int *y);
+
+/**
+ * \brief Moves the mouse to the given position within the window.
+ *
+ * \param window The window to move the mouse into, or NULL for the current mouse focus
+ * \param x The x coordinate within the window
+ * \param y The y coordinate within the window
+ *
+ * \note This function generates a mouse motion event
+ */
+extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window * window,
+ int x, int y);
+
+/**
+ * \brief Moves the mouse to the given position in global screen space.
+ *
+ * \param x The x coordinate
+ * \param y The y coordinate
+ * \return 0 on success, -1 on error (usually: unsupported by a platform).
+ *
+ * \note This function generates a mouse motion event
+ */
+extern DECLSPEC int SDLCALL SDL_WarpMouseGlobal(int x, int y);
+
+/**
+ * \brief Set relative mouse mode.
+ *
+ * \param enabled Whether or not to enable relative mode
+ *
+ * \return 0 on success, or -1 if relative mode is not supported.
+ *
+ * While the mouse is in relative mode, the cursor is hidden, and the
+ * driver will try to report continuous motion in the current window.
+ * Only relative motion events will be delivered, the mouse position
+ * will not change.
+ *
+ * \note This function will flush any pending mouse motion.
+ *
+ * \sa SDL_GetRelativeMouseMode()
+ */
+extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled);
+
+/**
+ * \brief Capture the mouse, to track input outside an SDL window.
+ *
+ * \param enabled Whether or not to enable capturing
+ *
+ * Capturing enables your app to obtain mouse events globally, instead of
+ * just within your window. Not all video targets support this function.
+ * When capturing is enabled, the current window will get all mouse events,
+ * but unlike relative mode, no change is made to the cursor and it is
+ * not restrained to your window.
+ *
+ * This function may also deny mouse input to other windows--both those in
+ * your application and others on the system--so you should use this
+ * function sparingly, and in small bursts. For example, you might want to
+ * track the mouse while the user is dragging something, until the user
+ * releases a mouse button. It is not recommended that you capture the mouse
+ * for long periods of time, such as the entire time your app is running.
+ *
+ * While captured, mouse events still report coordinates relative to the
+ * current (foreground) window, but those coordinates may be outside the
+ * bounds of the window (including negative values). Capturing is only
+ * allowed for the foreground window. If the window loses focus while
+ * capturing, the capture will be disabled automatically.
+ *
+ * While capturing is enabled, the current window will have the
+ * SDL_WINDOW_MOUSE_CAPTURE flag set.
+ *
+ * \return 0 on success, or -1 if not supported.
+ */
+extern DECLSPEC int SDLCALL SDL_CaptureMouse(SDL_bool enabled);
+
+/**
+ * \brief Query whether relative mouse mode is enabled.
+ *
+ * \sa SDL_SetRelativeMouseMode()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(void);
+
+/**
+ * \brief Create a cursor, using the specified bitmap data and
+ * mask (in MSB format).
+ *
+ * The cursor width must be a multiple of 8 bits.
+ *
+ * The cursor is created in black and white according to the following:
+ * <table>
+ * <tr><td> data </td><td> mask </td><td> resulting pixel on screen </td></tr>
+ * <tr><td> 0 </td><td> 1 </td><td> White </td></tr>
+ * <tr><td> 1 </td><td> 1 </td><td> Black </td></tr>
+ * <tr><td> 0 </td><td> 0 </td><td> Transparent </td></tr>
+ * <tr><td> 1 </td><td> 0 </td><td> Inverted color if possible, black
+ * if not. </td></tr>
+ * </table>
+ *
+ * \sa SDL_FreeCursor()
+ */
+extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor(const Uint8 * data,
+ const Uint8 * mask,
+ int w, int h, int hot_x,
+ int hot_y);
+
+/**
+ * \brief Create a color cursor.
+ *
+ * \sa SDL_FreeCursor()
+ */
+extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateColorCursor(SDL_Surface *surface,
+ int hot_x,
+ int hot_y);
+
+/**
+ * \brief Create a system cursor.
+ *
+ * \sa SDL_FreeCursor()
+ */
+extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateSystemCursor(SDL_SystemCursor id);
+
+/**
+ * \brief Set the active cursor.
+ */
+extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor);
+
+/**
+ * \brief Return the active cursor.
+ */
+extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor(void);
+
+/**
+ * \brief Return the default cursor.
+ */
+extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetDefaultCursor(void);
+
+/**
+ * \brief Frees a cursor created with SDL_CreateCursor() or similar functions.
+ *
+ * \sa SDL_CreateCursor()
+ * \sa SDL_CreateColorCursor()
+ * \sa SDL_CreateSystemCursor()
+ */
+extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor);
+
+/**
+ * \brief Toggle whether or not the cursor is shown.
+ *
+ * \param toggle 1 to show the cursor, 0 to hide it, -1 to query the current
+ * state.
+ *
+ * \return 1 if the cursor is shown, or 0 if the cursor is hidden.
+ */
+extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
+
+/**
+ * Used as a mask when testing buttons in buttonstate.
+ * - Button 1: Left mouse button
+ * - Button 2: Middle mouse button
+ * - Button 3: Right mouse button
+ */
+#define SDL_BUTTON(X) (1 << ((X)-1))
+#define SDL_BUTTON_LEFT 1
+#define SDL_BUTTON_MIDDLE 2
+#define SDL_BUTTON_RIGHT 3
+#define SDL_BUTTON_X1 4
+#define SDL_BUTTON_X2 5
+#define SDL_BUTTON_LMASK SDL_BUTTON(SDL_BUTTON_LEFT)
+#define SDL_BUTTON_MMASK SDL_BUTTON(SDL_BUTTON_MIDDLE)
+#define SDL_BUTTON_RMASK SDL_BUTTON(SDL_BUTTON_RIGHT)
+#define SDL_BUTTON_X1MASK SDL_BUTTON(SDL_BUTTON_X1)
+#define SDL_BUTTON_X2MASK SDL_BUTTON(SDL_BUTTON_X2)
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_mouse_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_mutex.h b/src/3rdparty/SDL2/include/SDL2/SDL_mutex.h
new file mode 100644
index 0000000..ba4247c
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_mutex.h
@@ -0,0 +1,251 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_mutex_h_
+#define SDL_mutex_h_
+
+/**
+ * \file SDL_mutex.h
+ *
+ * Functions to provide thread synchronization primitives.
+ */
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Synchronization functions which can time out return this value
+ * if they time out.
+ */
+#define SDL_MUTEX_TIMEDOUT 1
+
+/**
+ * This is the timeout value which corresponds to never time out.
+ */
+#define SDL_MUTEX_MAXWAIT (~(Uint32)0)
+
+
+/**
+ * \name Mutex functions
+ */
+/* @{ */
+
+/* The SDL mutex structure, defined in SDL_sysmutex.c */
+struct SDL_mutex;
+typedef struct SDL_mutex SDL_mutex;
+
+/**
+ * Create a mutex, initialized unlocked.
+ */
+extern DECLSPEC SDL_mutex *SDLCALL SDL_CreateMutex(void);
+
+/**
+ * Lock the mutex.
+ *
+ * \return 0, or -1 on error.
+ */
+#define SDL_mutexP(m) SDL_LockMutex(m)
+extern DECLSPEC int SDLCALL SDL_LockMutex(SDL_mutex * mutex);
+
+/**
+ * Try to lock the mutex
+ *
+ * \return 0, SDL_MUTEX_TIMEDOUT, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_TryLockMutex(SDL_mutex * mutex);
+
+/**
+ * Unlock the mutex.
+ *
+ * \return 0, or -1 on error.
+ *
+ * \warning It is an error to unlock a mutex that has not been locked by
+ * the current thread, and doing so results in undefined behavior.
+ */
+#define SDL_mutexV(m) SDL_UnlockMutex(m)
+extern DECLSPEC int SDLCALL SDL_UnlockMutex(SDL_mutex * mutex);
+
+/**
+ * Destroy a mutex.
+ */
+extern DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_mutex * mutex);
+
+/* @} *//* Mutex functions */
+
+
+/**
+ * \name Semaphore functions
+ */
+/* @{ */
+
+/* The SDL semaphore structure, defined in SDL_syssem.c */
+struct SDL_semaphore;
+typedef struct SDL_semaphore SDL_sem;
+
+/**
+ * Create a semaphore, initialized with value, returns NULL on failure.
+ */
+extern DECLSPEC SDL_sem *SDLCALL SDL_CreateSemaphore(Uint32 initial_value);
+
+/**
+ * Destroy a semaphore.
+ */
+extern DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem * sem);
+
+/**
+ * This function suspends the calling thread until the semaphore pointed
+ * to by \c sem has a positive count. It then atomically decreases the
+ * semaphore count.
+ */
+extern DECLSPEC int SDLCALL SDL_SemWait(SDL_sem * sem);
+
+/**
+ * Non-blocking variant of SDL_SemWait().
+ *
+ * \return 0 if the wait succeeds, ::SDL_MUTEX_TIMEDOUT if the wait would
+ * block, and -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem * sem);
+
+/**
+ * Variant of SDL_SemWait() with a timeout in milliseconds.
+ *
+ * \return 0 if the wait succeeds, ::SDL_MUTEX_TIMEDOUT if the wait does not
+ * succeed in the allotted time, and -1 on error.
+ *
+ * \warning On some platforms this function is implemented by looping with a
+ * delay of 1 ms, and so should be avoided if possible.
+ */
+extern DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem * sem, Uint32 ms);
+
+/**
+ * Atomically increases the semaphore's count (not blocking).
+ *
+ * \return 0, or -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_SemPost(SDL_sem * sem);
+
+/**
+ * Returns the current count of the semaphore.
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_SemValue(SDL_sem * sem);
+
+/* @} *//* Semaphore functions */
+
+
+/**
+ * \name Condition variable functions
+ */
+/* @{ */
+
+/* The SDL condition variable structure, defined in SDL_syscond.c */
+struct SDL_cond;
+typedef struct SDL_cond SDL_cond;
+
+/**
+ * Create a condition variable.
+ *
+ * Typical use of condition variables:
+ *
+ * Thread A:
+ * SDL_LockMutex(lock);
+ * while ( ! condition ) {
+ * SDL_CondWait(cond, lock);
+ * }
+ * SDL_UnlockMutex(lock);
+ *
+ * Thread B:
+ * SDL_LockMutex(lock);
+ * ...
+ * condition = true;
+ * ...
+ * SDL_CondSignal(cond);
+ * SDL_UnlockMutex(lock);
+ *
+ * There is some discussion whether to signal the condition variable
+ * with the mutex locked or not. There is some potential performance
+ * benefit to unlocking first on some platforms, but there are some
+ * potential race conditions depending on how your code is structured.
+ *
+ * In general it's safer to signal the condition variable while the
+ * mutex is locked.
+ */
+extern DECLSPEC SDL_cond *SDLCALL SDL_CreateCond(void);
+
+/**
+ * Destroy a condition variable.
+ */
+extern DECLSPEC void SDLCALL SDL_DestroyCond(SDL_cond * cond);
+
+/**
+ * Restart one of the threads that are waiting on the condition variable.
+ *
+ * \return 0 or -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond * cond);
+
+/**
+ * Restart all threads that are waiting on the condition variable.
+ *
+ * \return 0 or -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond * cond);
+
+/**
+ * Wait on the condition variable, unlocking the provided mutex.
+ *
+ * \warning The mutex must be locked before entering this function!
+ *
+ * The mutex is re-locked once the condition variable is signaled.
+ *
+ * \return 0 when it is signaled, or -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex);
+
+/**
+ * Waits for at most \c ms milliseconds, and returns 0 if the condition
+ * variable is signaled, ::SDL_MUTEX_TIMEDOUT if the condition is not
+ * signaled in the allotted time, and -1 on error.
+ *
+ * \warning On some platforms this function is implemented by looping with a
+ * delay of 1 ms, and so should be avoided if possible.
+ */
+extern DECLSPEC int SDLCALL SDL_CondWaitTimeout(SDL_cond * cond,
+ SDL_mutex * mutex, Uint32 ms);
+
+/* @} *//* Condition variable functions */
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_mutex_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_name.h b/src/3rdparty/SDL2/include/SDL2/SDL_name.h
new file mode 100644
index 0000000..ecd863f
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_name.h
@@ -0,0 +1,33 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDLname_h_
+#define SDLname_h_
+
+#if defined(__STDC__) || defined(__cplusplus)
+#define NeedFunctionPrototypes 1
+#endif
+
+#define SDL_NAME(X) SDL_##X
+
+#endif /* SDLname_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_opengl.h b/src/3rdparty/SDL2/include/SDL2/SDL_opengl.h
new file mode 100644
index 0000000..253d9c9
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_opengl.h
@@ -0,0 +1,2183 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_opengl.h
+ *
+ * This is a simple file to encapsulate the OpenGL API headers.
+ */
+
+/**
+ * \def NO_SDL_GLEXT
+ *
+ * Define this if you have your own version of glext.h and want to disable the
+ * version included in SDL_opengl.h.
+ */
+
+#ifndef SDL_opengl_h_
+#define SDL_opengl_h_
+
+#include "SDL_config.h"
+
+#ifndef __IPHONEOS__ /* No OpenGL on iOS. */
+
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#ifndef __gl_h_
+#define __gl_h_
+
+#if defined(USE_MGL_NAMESPACE)
+#include "gl_mangle.h"
+#endif
+
+
+/**********************************************************************
+ * Begin system-specific stuff.
+ */
+
+#if defined(_WIN32) && !defined(__WIN32__) && !defined(__CYGWIN__)
+#define __WIN32__
+#endif
+
+#if defined(__WIN32__) && !defined(__CYGWIN__)
+# if (defined(_MSC_VER) || defined(__MINGW32__)) && defined(BUILD_GL32) /* tag specify we're building mesa as a DLL */
+# define GLAPI __declspec(dllexport)
+# elif (defined(_MSC_VER) || defined(__MINGW32__)) && defined(_DLL) /* tag specifying we're building for DLL runtime support */
+# define GLAPI __declspec(dllimport)
+# else /* for use with static link lib build of Win32 edition only */
+# define GLAPI extern
+# endif /* _STATIC_MESA support */
+# if defined(__MINGW32__) && defined(GL_NO_STDCALL) || defined(UNDER_CE) /* The generated DLLs by MingW with STDCALL are not compatible with the ones done by Microsoft's compilers */
+# define GLAPIENTRY
+# else
+# define GLAPIENTRY __stdcall
+# endif
+#elif defined(__CYGWIN__) && defined(USE_OPENGL32) /* use native windows opengl32 */
+# define GLAPI extern
+# define GLAPIENTRY __stdcall
+#elif defined(__OS2__) || defined(__EMX__) /* native os/2 opengl */
+# define GLAPI extern
+# define GLAPIENTRY _System
+# define APIENTRY _System
+# if defined(__GNUC__) && !defined(_System)
+# define _System
+# endif
+#elif (defined(__GNUC__) && __GNUC__ >= 4) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
+# define GLAPI __attribute__((visibility("default")))
+# define GLAPIENTRY
+#endif /* WIN32 && !CYGWIN */
+
+/*
+ * WINDOWS: Include windows.h here to define APIENTRY.
+ * It is also useful when applications include this file by
+ * including only glut.h, since glut.h depends on windows.h.
+ * Applications needing to include windows.h with parms other
+ * than "WIN32_LEAN_AND_MEAN" may include windows.h before
+ * glut.h or gl.h.
+ */
+#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__)
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN 1
+#endif
+#ifndef NOMINMAX /* don't define min() and max(). */
+#define NOMINMAX
+#endif
+#include <windows.h>
+#endif
+
+#ifndef GLAPI
+#define GLAPI extern
+#endif
+
+#ifndef GLAPIENTRY
+#define GLAPIENTRY
+#endif
+
+#ifndef APIENTRY
+#define APIENTRY GLAPIENTRY
+#endif
+
+/* "P" suffix to be used for a pointer to a function */
+#ifndef APIENTRYP
+#define APIENTRYP APIENTRY *
+#endif
+
+#ifndef GLAPIENTRYP
+#define GLAPIENTRYP GLAPIENTRY *
+#endif
+
+#if defined(PRAGMA_EXPORT_SUPPORTED)
+#pragma export on
+#endif
+
+/*
+ * End system-specific stuff.
+ **********************************************************************/
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+#define GL_VERSION_1_1 1
+#define GL_VERSION_1_2 1
+#define GL_VERSION_1_3 1
+#define GL_ARB_imaging 1
+
+
+/*
+ * Datatypes
+ */
+typedef unsigned int GLenum;
+typedef unsigned char GLboolean;
+typedef unsigned int GLbitfield;
+typedef void GLvoid;
+typedef signed char GLbyte; /* 1-byte signed */
+typedef short GLshort; /* 2-byte signed */
+typedef int GLint; /* 4-byte signed */
+typedef unsigned char GLubyte; /* 1-byte unsigned */
+typedef unsigned short GLushort; /* 2-byte unsigned */
+typedef unsigned int GLuint; /* 4-byte unsigned */
+typedef int GLsizei; /* 4-byte signed */
+typedef float GLfloat; /* single precision float */
+typedef float GLclampf; /* single precision float in [0,1] */
+typedef double GLdouble; /* double precision float */
+typedef double GLclampd; /* double precision float in [0,1] */
+
+
+
+/*
+ * Constants
+ */
+
+/* Boolean values */
+#define GL_FALSE 0
+#define GL_TRUE 1
+
+/* Data types */
+#define GL_BYTE 0x1400
+#define GL_UNSIGNED_BYTE 0x1401
+#define GL_SHORT 0x1402
+#define GL_UNSIGNED_SHORT 0x1403
+#define GL_INT 0x1404
+#define GL_UNSIGNED_INT 0x1405
+#define GL_FLOAT 0x1406
+#define GL_2_BYTES 0x1407
+#define GL_3_BYTES 0x1408
+#define GL_4_BYTES 0x1409
+#define GL_DOUBLE 0x140A
+
+/* Primitives */
+#define GL_POINTS 0x0000
+#define GL_LINES 0x0001
+#define GL_LINE_LOOP 0x0002
+#define GL_LINE_STRIP 0x0003
+#define GL_TRIANGLES 0x0004
+#define GL_TRIANGLE_STRIP 0x0005
+#define GL_TRIANGLE_FAN 0x0006
+#define GL_QUADS 0x0007
+#define GL_QUAD_STRIP 0x0008
+#define GL_POLYGON 0x0009
+
+/* Vertex Arrays */
+#define GL_VERTEX_ARRAY 0x8074
+#define GL_NORMAL_ARRAY 0x8075
+#define GL_COLOR_ARRAY 0x8076
+#define GL_INDEX_ARRAY 0x8077
+#define GL_TEXTURE_COORD_ARRAY 0x8078
+#define GL_EDGE_FLAG_ARRAY 0x8079
+#define GL_VERTEX_ARRAY_SIZE 0x807A
+#define GL_VERTEX_ARRAY_TYPE 0x807B
+#define GL_VERTEX_ARRAY_STRIDE 0x807C
+#define GL_NORMAL_ARRAY_TYPE 0x807E
+#define GL_NORMAL_ARRAY_STRIDE 0x807F
+#define GL_COLOR_ARRAY_SIZE 0x8081
+#define GL_COLOR_ARRAY_TYPE 0x8082
+#define GL_COLOR_ARRAY_STRIDE 0x8083
+#define GL_INDEX_ARRAY_TYPE 0x8085
+#define GL_INDEX_ARRAY_STRIDE 0x8086
+#define GL_TEXTURE_COORD_ARRAY_SIZE 0x8088
+#define GL_TEXTURE_COORD_ARRAY_TYPE 0x8089
+#define GL_TEXTURE_COORD_ARRAY_STRIDE 0x808A
+#define GL_EDGE_FLAG_ARRAY_STRIDE 0x808C
+#define GL_VERTEX_ARRAY_POINTER 0x808E
+#define GL_NORMAL_ARRAY_POINTER 0x808F
+#define GL_COLOR_ARRAY_POINTER 0x8090
+#define GL_INDEX_ARRAY_POINTER 0x8091
+#define GL_TEXTURE_COORD_ARRAY_POINTER 0x8092
+#define GL_EDGE_FLAG_ARRAY_POINTER 0x8093
+#define GL_V2F 0x2A20
+#define GL_V3F 0x2A21
+#define GL_C4UB_V2F 0x2A22
+#define GL_C4UB_V3F 0x2A23
+#define GL_C3F_V3F 0x2A24
+#define GL_N3F_V3F 0x2A25
+#define GL_C4F_N3F_V3F 0x2A26
+#define GL_T2F_V3F 0x2A27
+#define GL_T4F_V4F 0x2A28
+#define GL_T2F_C4UB_V3F 0x2A29
+#define GL_T2F_C3F_V3F 0x2A2A
+#define GL_T2F_N3F_V3F 0x2A2B
+#define GL_T2F_C4F_N3F_V3F 0x2A2C
+#define GL_T4F_C4F_N3F_V4F 0x2A2D
+
+/* Matrix Mode */
+#define GL_MATRIX_MODE 0x0BA0
+#define GL_MODELVIEW 0x1700
+#define GL_PROJECTION 0x1701
+#define GL_TEXTURE 0x1702
+
+/* Points */
+#define GL_POINT_SMOOTH 0x0B10
+#define GL_POINT_SIZE 0x0B11
+#define GL_POINT_SIZE_GRANULARITY 0x0B13
+#define GL_POINT_SIZE_RANGE 0x0B12
+
+/* Lines */
+#define GL_LINE_SMOOTH 0x0B20
+#define GL_LINE_STIPPLE 0x0B24
+#define GL_LINE_STIPPLE_PATTERN 0x0B25
+#define GL_LINE_STIPPLE_REPEAT 0x0B26
+#define GL_LINE_WIDTH 0x0B21
+#define GL_LINE_WIDTH_GRANULARITY 0x0B23
+#define GL_LINE_WIDTH_RANGE 0x0B22
+
+/* Polygons */
+#define GL_POINT 0x1B00
+#define GL_LINE 0x1B01
+#define GL_FILL 0x1B02
+#define GL_CW 0x0900
+#define GL_CCW 0x0901
+#define GL_FRONT 0x0404
+#define GL_BACK 0x0405
+#define GL_POLYGON_MODE 0x0B40
+#define GL_POLYGON_SMOOTH 0x0B41
+#define GL_POLYGON_STIPPLE 0x0B42
+#define GL_EDGE_FLAG 0x0B43
+#define GL_CULL_FACE 0x0B44
+#define GL_CULL_FACE_MODE 0x0B45
+#define GL_FRONT_FACE 0x0B46
+#define GL_POLYGON_OFFSET_FACTOR 0x8038
+#define GL_POLYGON_OFFSET_UNITS 0x2A00
+#define GL_POLYGON_OFFSET_POINT 0x2A01
+#define GL_POLYGON_OFFSET_LINE 0x2A02
+#define GL_POLYGON_OFFSET_FILL 0x8037
+
+/* Display Lists */
+#define GL_COMPILE 0x1300
+#define GL_COMPILE_AND_EXECUTE 0x1301
+#define GL_LIST_BASE 0x0B32
+#define GL_LIST_INDEX 0x0B33
+#define GL_LIST_MODE 0x0B30
+
+/* Depth buffer */
+#define GL_NEVER 0x0200
+#define GL_LESS 0x0201
+#define GL_EQUAL 0x0202
+#define GL_LEQUAL 0x0203
+#define GL_GREATER 0x0204
+#define GL_NOTEQUAL 0x0205
+#define GL_GEQUAL 0x0206
+#define GL_ALWAYS 0x0207
+#define GL_DEPTH_TEST 0x0B71
+#define GL_DEPTH_BITS 0x0D56
+#define GL_DEPTH_CLEAR_VALUE 0x0B73
+#define GL_DEPTH_FUNC 0x0B74
+#define GL_DEPTH_RANGE 0x0B70
+#define GL_DEPTH_WRITEMASK 0x0B72
+#define GL_DEPTH_COMPONENT 0x1902
+
+/* Lighting */
+#define GL_LIGHTING 0x0B50
+#define GL_LIGHT0 0x4000
+#define GL_LIGHT1 0x4001
+#define GL_LIGHT2 0x4002
+#define GL_LIGHT3 0x4003
+#define GL_LIGHT4 0x4004
+#define GL_LIGHT5 0x4005
+#define GL_LIGHT6 0x4006
+#define GL_LIGHT7 0x4007
+#define GL_SPOT_EXPONENT 0x1205
+#define GL_SPOT_CUTOFF 0x1206
+#define GL_CONSTANT_ATTENUATION 0x1207
+#define GL_LINEAR_ATTENUATION 0x1208
+#define GL_QUADRATIC_ATTENUATION 0x1209
+#define GL_AMBIENT 0x1200
+#define GL_DIFFUSE 0x1201
+#define GL_SPECULAR 0x1202
+#define GL_SHININESS 0x1601
+#define GL_EMISSION 0x1600
+#define GL_POSITION 0x1203
+#define GL_SPOT_DIRECTION 0x1204
+#define GL_AMBIENT_AND_DIFFUSE 0x1602
+#define GL_COLOR_INDEXES 0x1603
+#define GL_LIGHT_MODEL_TWO_SIDE 0x0B52
+#define GL_LIGHT_MODEL_LOCAL_VIEWER 0x0B51
+#define GL_LIGHT_MODEL_AMBIENT 0x0B53
+#define GL_FRONT_AND_BACK 0x0408
+#define GL_SHADE_MODEL 0x0B54
+#define GL_FLAT 0x1D00
+#define GL_SMOOTH 0x1D01
+#define GL_COLOR_MATERIAL 0x0B57
+#define GL_COLOR_MATERIAL_FACE 0x0B55
+#define GL_COLOR_MATERIAL_PARAMETER 0x0B56
+#define GL_NORMALIZE 0x0BA1
+
+/* User clipping planes */
+#define GL_CLIP_PLANE0 0x3000
+#define GL_CLIP_PLANE1 0x3001
+#define GL_CLIP_PLANE2 0x3002
+#define GL_CLIP_PLANE3 0x3003
+#define GL_CLIP_PLANE4 0x3004
+#define GL_CLIP_PLANE5 0x3005
+
+/* Accumulation buffer */
+#define GL_ACCUM_RED_BITS 0x0D58
+#define GL_ACCUM_GREEN_BITS 0x0D59
+#define GL_ACCUM_BLUE_BITS 0x0D5A
+#define GL_ACCUM_ALPHA_BITS 0x0D5B
+#define GL_ACCUM_CLEAR_VALUE 0x0B80
+#define GL_ACCUM 0x0100
+#define GL_ADD 0x0104
+#define GL_LOAD 0x0101
+#define GL_MULT 0x0103
+#define GL_RETURN 0x0102
+
+/* Alpha testing */
+#define GL_ALPHA_TEST 0x0BC0
+#define GL_ALPHA_TEST_REF 0x0BC2
+#define GL_ALPHA_TEST_FUNC 0x0BC1
+
+/* Blending */
+#define GL_BLEND 0x0BE2
+#define GL_BLEND_SRC 0x0BE1
+#define GL_BLEND_DST 0x0BE0
+#define GL_ZERO 0
+#define GL_ONE 1
+#define GL_SRC_COLOR 0x0300
+#define GL_ONE_MINUS_SRC_COLOR 0x0301
+#define GL_SRC_ALPHA 0x0302
+#define GL_ONE_MINUS_SRC_ALPHA 0x0303
+#define GL_DST_ALPHA 0x0304
+#define GL_ONE_MINUS_DST_ALPHA 0x0305
+#define GL_DST_COLOR 0x0306
+#define GL_ONE_MINUS_DST_COLOR 0x0307
+#define GL_SRC_ALPHA_SATURATE 0x0308
+
+/* Render Mode */
+#define GL_FEEDBACK 0x1C01
+#define GL_RENDER 0x1C00
+#define GL_SELECT 0x1C02
+
+/* Feedback */
+#define GL_2D 0x0600
+#define GL_3D 0x0601
+#define GL_3D_COLOR 0x0602
+#define GL_3D_COLOR_TEXTURE 0x0603
+#define GL_4D_COLOR_TEXTURE 0x0604
+#define GL_POINT_TOKEN 0x0701
+#define GL_LINE_TOKEN 0x0702
+#define GL_LINE_RESET_TOKEN 0x0707
+#define GL_POLYGON_TOKEN 0x0703
+#define GL_BITMAP_TOKEN 0x0704
+#define GL_DRAW_PIXEL_TOKEN 0x0705
+#define GL_COPY_PIXEL_TOKEN 0x0706
+#define GL_PASS_THROUGH_TOKEN 0x0700
+#define GL_FEEDBACK_BUFFER_POINTER 0x0DF0
+#define GL_FEEDBACK_BUFFER_SIZE 0x0DF1
+#define GL_FEEDBACK_BUFFER_TYPE 0x0DF2
+
+/* Selection */
+#define GL_SELECTION_BUFFER_POINTER 0x0DF3
+#define GL_SELECTION_BUFFER_SIZE 0x0DF4
+
+/* Fog */
+#define GL_FOG 0x0B60
+#define GL_FOG_MODE 0x0B65
+#define GL_FOG_DENSITY 0x0B62
+#define GL_FOG_COLOR 0x0B66
+#define GL_FOG_INDEX 0x0B61
+#define GL_FOG_START 0x0B63
+#define GL_FOG_END 0x0B64
+#define GL_LINEAR 0x2601
+#define GL_EXP 0x0800
+#define GL_EXP2 0x0801
+
+/* Logic Ops */
+#define GL_LOGIC_OP 0x0BF1
+#define GL_INDEX_LOGIC_OP 0x0BF1
+#define GL_COLOR_LOGIC_OP 0x0BF2
+#define GL_LOGIC_OP_MODE 0x0BF0
+#define GL_CLEAR 0x1500
+#define GL_SET 0x150F
+#define GL_COPY 0x1503
+#define GL_COPY_INVERTED 0x150C
+#define GL_NOOP 0x1505
+#define GL_INVERT 0x150A
+#define GL_AND 0x1501
+#define GL_NAND 0x150E
+#define GL_OR 0x1507
+#define GL_NOR 0x1508
+#define GL_XOR 0x1506
+#define GL_EQUIV 0x1509
+#define GL_AND_REVERSE 0x1502
+#define GL_AND_INVERTED 0x1504
+#define GL_OR_REVERSE 0x150B
+#define GL_OR_INVERTED 0x150D
+
+/* Stencil */
+#define GL_STENCIL_BITS 0x0D57
+#define GL_STENCIL_TEST 0x0B90
+#define GL_STENCIL_CLEAR_VALUE 0x0B91
+#define GL_STENCIL_FUNC 0x0B92
+#define GL_STENCIL_VALUE_MASK 0x0B93
+#define GL_STENCIL_FAIL 0x0B94
+#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95
+#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96
+#define GL_STENCIL_REF 0x0B97
+#define GL_STENCIL_WRITEMASK 0x0B98
+#define GL_STENCIL_INDEX 0x1901
+#define GL_KEEP 0x1E00
+#define GL_REPLACE 0x1E01
+#define GL_INCR 0x1E02
+#define GL_DECR 0x1E03
+
+/* Buffers, Pixel Drawing/Reading */
+#define GL_NONE 0
+#define GL_LEFT 0x0406
+#define GL_RIGHT 0x0407
+/*GL_FRONT 0x0404 */
+/*GL_BACK 0x0405 */
+/*GL_FRONT_AND_BACK 0x0408 */
+#define GL_FRONT_LEFT 0x0400
+#define GL_FRONT_RIGHT 0x0401
+#define GL_BACK_LEFT 0x0402
+#define GL_BACK_RIGHT 0x0403
+#define GL_AUX0 0x0409
+#define GL_AUX1 0x040A
+#define GL_AUX2 0x040B
+#define GL_AUX3 0x040C
+#define GL_COLOR_INDEX 0x1900
+#define GL_RED 0x1903
+#define GL_GREEN 0x1904
+#define GL_BLUE 0x1905
+#define GL_ALPHA 0x1906
+#define GL_LUMINANCE 0x1909
+#define GL_LUMINANCE_ALPHA 0x190A
+#define GL_ALPHA_BITS 0x0D55
+#define GL_RED_BITS 0x0D52
+#define GL_GREEN_BITS 0x0D53
+#define GL_BLUE_BITS 0x0D54
+#define GL_INDEX_BITS 0x0D51
+#define GL_SUBPIXEL_BITS 0x0D50
+#define GL_AUX_BUFFERS 0x0C00
+#define GL_READ_BUFFER 0x0C02
+#define GL_DRAW_BUFFER 0x0C01
+#define GL_DOUBLEBUFFER 0x0C32
+#define GL_STEREO 0x0C33
+#define GL_BITMAP 0x1A00
+#define GL_COLOR 0x1800
+#define GL_DEPTH 0x1801
+#define GL_STENCIL 0x1802
+#define GL_DITHER 0x0BD0
+#define GL_RGB 0x1907
+#define GL_RGBA 0x1908
+
+/* Implementation limits */
+#define GL_MAX_LIST_NESTING 0x0B31
+#define GL_MAX_EVAL_ORDER 0x0D30
+#define GL_MAX_LIGHTS 0x0D31
+#define GL_MAX_CLIP_PLANES 0x0D32
+#define GL_MAX_TEXTURE_SIZE 0x0D33
+#define GL_MAX_PIXEL_MAP_TABLE 0x0D34
+#define GL_MAX_ATTRIB_STACK_DEPTH 0x0D35
+#define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36
+#define GL_MAX_NAME_STACK_DEPTH 0x0D37
+#define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38
+#define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39
+#define GL_MAX_VIEWPORT_DIMS 0x0D3A
+#define GL_MAX_CLIENT_ATTRIB_STACK_DEPTH 0x0D3B
+
+/* Gets */
+#define GL_ATTRIB_STACK_DEPTH 0x0BB0
+#define GL_CLIENT_ATTRIB_STACK_DEPTH 0x0BB1
+#define GL_COLOR_CLEAR_VALUE 0x0C22
+#define GL_COLOR_WRITEMASK 0x0C23
+#define GL_CURRENT_INDEX 0x0B01
+#define GL_CURRENT_COLOR 0x0B00
+#define GL_CURRENT_NORMAL 0x0B02
+#define GL_CURRENT_RASTER_COLOR 0x0B04
+#define GL_CURRENT_RASTER_DISTANCE 0x0B09
+#define GL_CURRENT_RASTER_INDEX 0x0B05
+#define GL_CURRENT_RASTER_POSITION 0x0B07
+#define GL_CURRENT_RASTER_TEXTURE_COORDS 0x0B06
+#define GL_CURRENT_RASTER_POSITION_VALID 0x0B08
+#define GL_CURRENT_TEXTURE_COORDS 0x0B03
+#define GL_INDEX_CLEAR_VALUE 0x0C20
+#define GL_INDEX_MODE 0x0C30
+#define GL_INDEX_WRITEMASK 0x0C21
+#define GL_MODELVIEW_MATRIX 0x0BA6
+#define GL_MODELVIEW_STACK_DEPTH 0x0BA3
+#define GL_NAME_STACK_DEPTH 0x0D70
+#define GL_PROJECTION_MATRIX 0x0BA7
+#define GL_PROJECTION_STACK_DEPTH 0x0BA4
+#define GL_RENDER_MODE 0x0C40
+#define GL_RGBA_MODE 0x0C31
+#define GL_TEXTURE_MATRIX 0x0BA8
+#define GL_TEXTURE_STACK_DEPTH 0x0BA5
+#define GL_VIEWPORT 0x0BA2
+
+/* Evaluators */
+#define GL_AUTO_NORMAL 0x0D80
+#define GL_MAP1_COLOR_4 0x0D90
+#define GL_MAP1_INDEX 0x0D91
+#define GL_MAP1_NORMAL 0x0D92
+#define GL_MAP1_TEXTURE_COORD_1 0x0D93
+#define GL_MAP1_TEXTURE_COORD_2 0x0D94
+#define GL_MAP1_TEXTURE_COORD_3 0x0D95
+#define GL_MAP1_TEXTURE_COORD_4 0x0D96
+#define GL_MAP1_VERTEX_3 0x0D97
+#define GL_MAP1_VERTEX_4 0x0D98
+#define GL_MAP2_COLOR_4 0x0DB0
+#define GL_MAP2_INDEX 0x0DB1
+#define GL_MAP2_NORMAL 0x0DB2
+#define GL_MAP2_TEXTURE_COORD_1 0x0DB3
+#define GL_MAP2_TEXTURE_COORD_2 0x0DB4
+#define GL_MAP2_TEXTURE_COORD_3 0x0DB5
+#define GL_MAP2_TEXTURE_COORD_4 0x0DB6
+#define GL_MAP2_VERTEX_3 0x0DB7
+#define GL_MAP2_VERTEX_4 0x0DB8
+#define GL_MAP1_GRID_DOMAIN 0x0DD0
+#define GL_MAP1_GRID_SEGMENTS 0x0DD1
+#define GL_MAP2_GRID_DOMAIN 0x0DD2
+#define GL_MAP2_GRID_SEGMENTS 0x0DD3
+#define GL_COEFF 0x0A00
+#define GL_ORDER 0x0A01
+#define GL_DOMAIN 0x0A02
+
+/* Hints */
+#define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50
+#define GL_POINT_SMOOTH_HINT 0x0C51
+#define GL_LINE_SMOOTH_HINT 0x0C52
+#define GL_POLYGON_SMOOTH_HINT 0x0C53
+#define GL_FOG_HINT 0x0C54
+#define GL_DONT_CARE 0x1100
+#define GL_FASTEST 0x1101
+#define GL_NICEST 0x1102
+
+/* Scissor box */
+#define GL_SCISSOR_BOX 0x0C10
+#define GL_SCISSOR_TEST 0x0C11
+
+/* Pixel Mode / Transfer */
+#define GL_MAP_COLOR 0x0D10
+#define GL_MAP_STENCIL 0x0D11
+#define GL_INDEX_SHIFT 0x0D12
+#define GL_INDEX_OFFSET 0x0D13
+#define GL_RED_SCALE 0x0D14
+#define GL_RED_BIAS 0x0D15
+#define GL_GREEN_SCALE 0x0D18
+#define GL_GREEN_BIAS 0x0D19
+#define GL_BLUE_SCALE 0x0D1A
+#define GL_BLUE_BIAS 0x0D1B
+#define GL_ALPHA_SCALE 0x0D1C
+#define GL_ALPHA_BIAS 0x0D1D
+#define GL_DEPTH_SCALE 0x0D1E
+#define GL_DEPTH_BIAS 0x0D1F
+#define GL_PIXEL_MAP_S_TO_S_SIZE 0x0CB1
+#define GL_PIXEL_MAP_I_TO_I_SIZE 0x0CB0
+#define GL_PIXEL_MAP_I_TO_R_SIZE 0x0CB2
+#define GL_PIXEL_MAP_I_TO_G_SIZE 0x0CB3
+#define GL_PIXEL_MAP_I_TO_B_SIZE 0x0CB4
+#define GL_PIXEL_MAP_I_TO_A_SIZE 0x0CB5
+#define GL_PIXEL_MAP_R_TO_R_SIZE 0x0CB6
+#define GL_PIXEL_MAP_G_TO_G_SIZE 0x0CB7
+#define GL_PIXEL_MAP_B_TO_B_SIZE 0x0CB8
+#define GL_PIXEL_MAP_A_TO_A_SIZE 0x0CB9
+#define GL_PIXEL_MAP_S_TO_S 0x0C71
+#define GL_PIXEL_MAP_I_TO_I 0x0C70
+#define GL_PIXEL_MAP_I_TO_R 0x0C72
+#define GL_PIXEL_MAP_I_TO_G 0x0C73
+#define GL_PIXEL_MAP_I_TO_B 0x0C74
+#define GL_PIXEL_MAP_I_TO_A 0x0C75
+#define GL_PIXEL_MAP_R_TO_R 0x0C76
+#define GL_PIXEL_MAP_G_TO_G 0x0C77
+#define GL_PIXEL_MAP_B_TO_B 0x0C78
+#define GL_PIXEL_MAP_A_TO_A 0x0C79
+#define GL_PACK_ALIGNMENT 0x0D05
+#define GL_PACK_LSB_FIRST 0x0D01
+#define GL_PACK_ROW_LENGTH 0x0D02
+#define GL_PACK_SKIP_PIXELS 0x0D04
+#define GL_PACK_SKIP_ROWS 0x0D03
+#define GL_PACK_SWAP_BYTES 0x0D00
+#define GL_UNPACK_ALIGNMENT 0x0CF5
+#define GL_UNPACK_LSB_FIRST 0x0CF1
+#define GL_UNPACK_ROW_LENGTH 0x0CF2
+#define GL_UNPACK_SKIP_PIXELS 0x0CF4
+#define GL_UNPACK_SKIP_ROWS 0x0CF3
+#define GL_UNPACK_SWAP_BYTES 0x0CF0
+#define GL_ZOOM_X 0x0D16
+#define GL_ZOOM_Y 0x0D17
+
+/* Texture mapping */
+#define GL_TEXTURE_ENV 0x2300
+#define GL_TEXTURE_ENV_MODE 0x2200
+#define GL_TEXTURE_1D 0x0DE0
+#define GL_TEXTURE_2D 0x0DE1
+#define GL_TEXTURE_WRAP_S 0x2802
+#define GL_TEXTURE_WRAP_T 0x2803
+#define GL_TEXTURE_MAG_FILTER 0x2800
+#define GL_TEXTURE_MIN_FILTER 0x2801
+#define GL_TEXTURE_ENV_COLOR 0x2201
+#define GL_TEXTURE_GEN_S 0x0C60
+#define GL_TEXTURE_GEN_T 0x0C61
+#define GL_TEXTURE_GEN_R 0x0C62
+#define GL_TEXTURE_GEN_Q 0x0C63
+#define GL_TEXTURE_GEN_MODE 0x2500
+#define GL_TEXTURE_BORDER_COLOR 0x1004
+#define GL_TEXTURE_WIDTH 0x1000
+#define GL_TEXTURE_HEIGHT 0x1001
+#define GL_TEXTURE_BORDER 0x1005
+#define GL_TEXTURE_COMPONENTS 0x1003
+#define GL_TEXTURE_RED_SIZE 0x805C
+#define GL_TEXTURE_GREEN_SIZE 0x805D
+#define GL_TEXTURE_BLUE_SIZE 0x805E
+#define GL_TEXTURE_ALPHA_SIZE 0x805F
+#define GL_TEXTURE_LUMINANCE_SIZE 0x8060
+#define GL_TEXTURE_INTENSITY_SIZE 0x8061
+#define GL_NEAREST_MIPMAP_NEAREST 0x2700
+#define GL_NEAREST_MIPMAP_LINEAR 0x2702
+#define GL_LINEAR_MIPMAP_NEAREST 0x2701
+#define GL_LINEAR_MIPMAP_LINEAR 0x2703
+#define GL_OBJECT_LINEAR 0x2401
+#define GL_OBJECT_PLANE 0x2501
+#define GL_EYE_LINEAR 0x2400
+#define GL_EYE_PLANE 0x2502
+#define GL_SPHERE_MAP 0x2402
+#define GL_DECAL 0x2101
+#define GL_MODULATE 0x2100
+#define GL_NEAREST 0x2600
+#define GL_REPEAT 0x2901
+#define GL_CLAMP 0x2900
+#define GL_S 0x2000
+#define GL_T 0x2001
+#define GL_R 0x2002
+#define GL_Q 0x2003
+
+/* Utility */
+#define GL_VENDOR 0x1F00
+#define GL_RENDERER 0x1F01
+#define GL_VERSION 0x1F02
+#define GL_EXTENSIONS 0x1F03
+
+/* Errors */
+#define GL_NO_ERROR 0
+#define GL_INVALID_ENUM 0x0500
+#define GL_INVALID_VALUE 0x0501
+#define GL_INVALID_OPERATION 0x0502
+#define GL_STACK_OVERFLOW 0x0503
+#define GL_STACK_UNDERFLOW 0x0504
+#define GL_OUT_OF_MEMORY 0x0505
+
+/* glPush/PopAttrib bits */
+#define GL_CURRENT_BIT 0x00000001
+#define GL_POINT_BIT 0x00000002
+#define GL_LINE_BIT 0x00000004
+#define GL_POLYGON_BIT 0x00000008
+#define GL_POLYGON_STIPPLE_BIT 0x00000010
+#define GL_PIXEL_MODE_BIT 0x00000020
+#define GL_LIGHTING_BIT 0x00000040
+#define GL_FOG_BIT 0x00000080
+#define GL_DEPTH_BUFFER_BIT 0x00000100
+#define GL_ACCUM_BUFFER_BIT 0x00000200
+#define GL_STENCIL_BUFFER_BIT 0x00000400
+#define GL_VIEWPORT_BIT 0x00000800
+#define GL_TRANSFORM_BIT 0x00001000
+#define GL_ENABLE_BIT 0x00002000
+#define GL_COLOR_BUFFER_BIT 0x00004000
+#define GL_HINT_BIT 0x00008000
+#define GL_EVAL_BIT 0x00010000
+#define GL_LIST_BIT 0x00020000
+#define GL_TEXTURE_BIT 0x00040000
+#define GL_SCISSOR_BIT 0x00080000
+#define GL_ALL_ATTRIB_BITS 0x000FFFFF
+
+
+/* OpenGL 1.1 */
+#define GL_PROXY_TEXTURE_1D 0x8063
+#define GL_PROXY_TEXTURE_2D 0x8064
+#define GL_TEXTURE_PRIORITY 0x8066
+#define GL_TEXTURE_RESIDENT 0x8067
+#define GL_TEXTURE_BINDING_1D 0x8068
+#define GL_TEXTURE_BINDING_2D 0x8069
+#define GL_TEXTURE_INTERNAL_FORMAT 0x1003
+#define GL_ALPHA4 0x803B
+#define GL_ALPHA8 0x803C
+#define GL_ALPHA12 0x803D
+#define GL_ALPHA16 0x803E
+#define GL_LUMINANCE4 0x803F
+#define GL_LUMINANCE8 0x8040
+#define GL_LUMINANCE12 0x8041
+#define GL_LUMINANCE16 0x8042
+#define GL_LUMINANCE4_ALPHA4 0x8043
+#define GL_LUMINANCE6_ALPHA2 0x8044
+#define GL_LUMINANCE8_ALPHA8 0x8045
+#define GL_LUMINANCE12_ALPHA4 0x8046
+#define GL_LUMINANCE12_ALPHA12 0x8047
+#define GL_LUMINANCE16_ALPHA16 0x8048
+#define GL_INTENSITY 0x8049
+#define GL_INTENSITY4 0x804A
+#define GL_INTENSITY8 0x804B
+#define GL_INTENSITY12 0x804C
+#define GL_INTENSITY16 0x804D
+#define GL_R3_G3_B2 0x2A10
+#define GL_RGB4 0x804F
+#define GL_RGB5 0x8050
+#define GL_RGB8 0x8051
+#define GL_RGB10 0x8052
+#define GL_RGB12 0x8053
+#define GL_RGB16 0x8054
+#define GL_RGBA2 0x8055
+#define GL_RGBA4 0x8056
+#define GL_RGB5_A1 0x8057
+#define GL_RGBA8 0x8058
+#define GL_RGB10_A2 0x8059
+#define GL_RGBA12 0x805A
+#define GL_RGBA16 0x805B
+#define GL_CLIENT_PIXEL_STORE_BIT 0x00000001
+#define GL_CLIENT_VERTEX_ARRAY_BIT 0x00000002
+#define GL_ALL_CLIENT_ATTRIB_BITS 0xFFFFFFFF
+#define GL_CLIENT_ALL_ATTRIB_BITS 0xFFFFFFFF
+
+
+
+/*
+ * Miscellaneous
+ */
+
+GLAPI void GLAPIENTRY glClearIndex( GLfloat c );
+
+GLAPI void GLAPIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha );
+
+GLAPI void GLAPIENTRY glClear( GLbitfield mask );
+
+GLAPI void GLAPIENTRY glIndexMask( GLuint mask );
+
+GLAPI void GLAPIENTRY glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha );
+
+GLAPI void GLAPIENTRY glAlphaFunc( GLenum func, GLclampf ref );
+
+GLAPI void GLAPIENTRY glBlendFunc( GLenum sfactor, GLenum dfactor );
+
+GLAPI void GLAPIENTRY glLogicOp( GLenum opcode );
+
+GLAPI void GLAPIENTRY glCullFace( GLenum mode );
+
+GLAPI void GLAPIENTRY glFrontFace( GLenum mode );
+
+GLAPI void GLAPIENTRY glPointSize( GLfloat size );
+
+GLAPI void GLAPIENTRY glLineWidth( GLfloat width );
+
+GLAPI void GLAPIENTRY glLineStipple( GLint factor, GLushort pattern );
+
+GLAPI void GLAPIENTRY glPolygonMode( GLenum face, GLenum mode );
+
+GLAPI void GLAPIENTRY glPolygonOffset( GLfloat factor, GLfloat units );
+
+GLAPI void GLAPIENTRY glPolygonStipple( const GLubyte *mask );
+
+GLAPI void GLAPIENTRY glGetPolygonStipple( GLubyte *mask );
+
+GLAPI void GLAPIENTRY glEdgeFlag( GLboolean flag );
+
+GLAPI void GLAPIENTRY glEdgeFlagv( const GLboolean *flag );
+
+GLAPI void GLAPIENTRY glScissor( GLint x, GLint y, GLsizei width, GLsizei height);
+
+GLAPI void GLAPIENTRY glClipPlane( GLenum plane, const GLdouble *equation );
+
+GLAPI void GLAPIENTRY glGetClipPlane( GLenum plane, GLdouble *equation );
+
+GLAPI void GLAPIENTRY glDrawBuffer( GLenum mode );
+
+GLAPI void GLAPIENTRY glReadBuffer( GLenum mode );
+
+GLAPI void GLAPIENTRY glEnable( GLenum cap );
+
+GLAPI void GLAPIENTRY glDisable( GLenum cap );
+
+GLAPI GLboolean GLAPIENTRY glIsEnabled( GLenum cap );
+
+
+GLAPI void GLAPIENTRY glEnableClientState( GLenum cap ); /* 1.1 */
+
+GLAPI void GLAPIENTRY glDisableClientState( GLenum cap ); /* 1.1 */
+
+
+GLAPI void GLAPIENTRY glGetBooleanv( GLenum pname, GLboolean *params );
+
+GLAPI void GLAPIENTRY glGetDoublev( GLenum pname, GLdouble *params );
+
+GLAPI void GLAPIENTRY glGetFloatv( GLenum pname, GLfloat *params );
+
+GLAPI void GLAPIENTRY glGetIntegerv( GLenum pname, GLint *params );
+
+
+GLAPI void GLAPIENTRY glPushAttrib( GLbitfield mask );
+
+GLAPI void GLAPIENTRY glPopAttrib( void );
+
+
+GLAPI void GLAPIENTRY glPushClientAttrib( GLbitfield mask ); /* 1.1 */
+
+GLAPI void GLAPIENTRY glPopClientAttrib( void ); /* 1.1 */
+
+
+GLAPI GLint GLAPIENTRY glRenderMode( GLenum mode );
+
+GLAPI GLenum GLAPIENTRY glGetError( void );
+
+GLAPI const GLubyte * GLAPIENTRY glGetString( GLenum name );
+
+GLAPI void GLAPIENTRY glFinish( void );
+
+GLAPI void GLAPIENTRY glFlush( void );
+
+GLAPI void GLAPIENTRY glHint( GLenum target, GLenum mode );
+
+
+/*
+ * Depth Buffer
+ */
+
+GLAPI void GLAPIENTRY glClearDepth( GLclampd depth );
+
+GLAPI void GLAPIENTRY glDepthFunc( GLenum func );
+
+GLAPI void GLAPIENTRY glDepthMask( GLboolean flag );
+
+GLAPI void GLAPIENTRY glDepthRange( GLclampd near_val, GLclampd far_val );
+
+
+/*
+ * Accumulation Buffer
+ */
+
+GLAPI void GLAPIENTRY glClearAccum( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha );
+
+GLAPI void GLAPIENTRY glAccum( GLenum op, GLfloat value );
+
+
+/*
+ * Transformation
+ */
+
+GLAPI void GLAPIENTRY glMatrixMode( GLenum mode );
+
+GLAPI void GLAPIENTRY glOrtho( GLdouble left, GLdouble right,
+ GLdouble bottom, GLdouble top,
+ GLdouble near_val, GLdouble far_val );
+
+GLAPI void GLAPIENTRY glFrustum( GLdouble left, GLdouble right,
+ GLdouble bottom, GLdouble top,
+ GLdouble near_val, GLdouble far_val );
+
+GLAPI void GLAPIENTRY glViewport( GLint x, GLint y,
+ GLsizei width, GLsizei height );
+
+GLAPI void GLAPIENTRY glPushMatrix( void );
+
+GLAPI void GLAPIENTRY glPopMatrix( void );
+
+GLAPI void GLAPIENTRY glLoadIdentity( void );
+
+GLAPI void GLAPIENTRY glLoadMatrixd( const GLdouble *m );
+GLAPI void GLAPIENTRY glLoadMatrixf( const GLfloat *m );
+
+GLAPI void GLAPIENTRY glMultMatrixd( const GLdouble *m );
+GLAPI void GLAPIENTRY glMultMatrixf( const GLfloat *m );
+
+GLAPI void GLAPIENTRY glRotated( GLdouble angle,
+ GLdouble x, GLdouble y, GLdouble z );
+GLAPI void GLAPIENTRY glRotatef( GLfloat angle,
+ GLfloat x, GLfloat y, GLfloat z );
+
+GLAPI void GLAPIENTRY glScaled( GLdouble x, GLdouble y, GLdouble z );
+GLAPI void GLAPIENTRY glScalef( GLfloat x, GLfloat y, GLfloat z );
+
+GLAPI void GLAPIENTRY glTranslated( GLdouble x, GLdouble y, GLdouble z );
+GLAPI void GLAPIENTRY glTranslatef( GLfloat x, GLfloat y, GLfloat z );
+
+
+/*
+ * Display Lists
+ */
+
+GLAPI GLboolean GLAPIENTRY glIsList( GLuint list );
+
+GLAPI void GLAPIENTRY glDeleteLists( GLuint list, GLsizei range );
+
+GLAPI GLuint GLAPIENTRY glGenLists( GLsizei range );
+
+GLAPI void GLAPIENTRY glNewList( GLuint list, GLenum mode );
+
+GLAPI void GLAPIENTRY glEndList( void );
+
+GLAPI void GLAPIENTRY glCallList( GLuint list );
+
+GLAPI void GLAPIENTRY glCallLists( GLsizei n, GLenum type,
+ const GLvoid *lists );
+
+GLAPI void GLAPIENTRY glListBase( GLuint base );
+
+
+/*
+ * Drawing Functions
+ */
+
+GLAPI void GLAPIENTRY glBegin( GLenum mode );
+
+GLAPI void GLAPIENTRY glEnd( void );
+
+
+GLAPI void GLAPIENTRY glVertex2d( GLdouble x, GLdouble y );
+GLAPI void GLAPIENTRY glVertex2f( GLfloat x, GLfloat y );
+GLAPI void GLAPIENTRY glVertex2i( GLint x, GLint y );
+GLAPI void GLAPIENTRY glVertex2s( GLshort x, GLshort y );
+
+GLAPI void GLAPIENTRY glVertex3d( GLdouble x, GLdouble y, GLdouble z );
+GLAPI void GLAPIENTRY glVertex3f( GLfloat x, GLfloat y, GLfloat z );
+GLAPI void GLAPIENTRY glVertex3i( GLint x, GLint y, GLint z );
+GLAPI void GLAPIENTRY glVertex3s( GLshort x, GLshort y, GLshort z );
+
+GLAPI void GLAPIENTRY glVertex4d( GLdouble x, GLdouble y, GLdouble z, GLdouble w );
+GLAPI void GLAPIENTRY glVertex4f( GLfloat x, GLfloat y, GLfloat z, GLfloat w );
+GLAPI void GLAPIENTRY glVertex4i( GLint x, GLint y, GLint z, GLint w );
+GLAPI void GLAPIENTRY glVertex4s( GLshort x, GLshort y, GLshort z, GLshort w );
+
+GLAPI void GLAPIENTRY glVertex2dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glVertex2fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glVertex2iv( const GLint *v );
+GLAPI void GLAPIENTRY glVertex2sv( const GLshort *v );
+
+GLAPI void GLAPIENTRY glVertex3dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glVertex3fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glVertex3iv( const GLint *v );
+GLAPI void GLAPIENTRY glVertex3sv( const GLshort *v );
+
+GLAPI void GLAPIENTRY glVertex4dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glVertex4fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glVertex4iv( const GLint *v );
+GLAPI void GLAPIENTRY glVertex4sv( const GLshort *v );
+
+
+GLAPI void GLAPIENTRY glNormal3b( GLbyte nx, GLbyte ny, GLbyte nz );
+GLAPI void GLAPIENTRY glNormal3d( GLdouble nx, GLdouble ny, GLdouble nz );
+GLAPI void GLAPIENTRY glNormal3f( GLfloat nx, GLfloat ny, GLfloat nz );
+GLAPI void GLAPIENTRY glNormal3i( GLint nx, GLint ny, GLint nz );
+GLAPI void GLAPIENTRY glNormal3s( GLshort nx, GLshort ny, GLshort nz );
+
+GLAPI void GLAPIENTRY glNormal3bv( const GLbyte *v );
+GLAPI void GLAPIENTRY glNormal3dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glNormal3fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glNormal3iv( const GLint *v );
+GLAPI void GLAPIENTRY glNormal3sv( const GLshort *v );
+
+
+GLAPI void GLAPIENTRY glIndexd( GLdouble c );
+GLAPI void GLAPIENTRY glIndexf( GLfloat c );
+GLAPI void GLAPIENTRY glIndexi( GLint c );
+GLAPI void GLAPIENTRY glIndexs( GLshort c );
+GLAPI void GLAPIENTRY glIndexub( GLubyte c ); /* 1.1 */
+
+GLAPI void GLAPIENTRY glIndexdv( const GLdouble *c );
+GLAPI void GLAPIENTRY glIndexfv( const GLfloat *c );
+GLAPI void GLAPIENTRY glIndexiv( const GLint *c );
+GLAPI void GLAPIENTRY glIndexsv( const GLshort *c );
+GLAPI void GLAPIENTRY glIndexubv( const GLubyte *c ); /* 1.1 */
+
+GLAPI void GLAPIENTRY glColor3b( GLbyte red, GLbyte green, GLbyte blue );
+GLAPI void GLAPIENTRY glColor3d( GLdouble red, GLdouble green, GLdouble blue );
+GLAPI void GLAPIENTRY glColor3f( GLfloat red, GLfloat green, GLfloat blue );
+GLAPI void GLAPIENTRY glColor3i( GLint red, GLint green, GLint blue );
+GLAPI void GLAPIENTRY glColor3s( GLshort red, GLshort green, GLshort blue );
+GLAPI void GLAPIENTRY glColor3ub( GLubyte red, GLubyte green, GLubyte blue );
+GLAPI void GLAPIENTRY glColor3ui( GLuint red, GLuint green, GLuint blue );
+GLAPI void GLAPIENTRY glColor3us( GLushort red, GLushort green, GLushort blue );
+
+GLAPI void GLAPIENTRY glColor4b( GLbyte red, GLbyte green,
+ GLbyte blue, GLbyte alpha );
+GLAPI void GLAPIENTRY glColor4d( GLdouble red, GLdouble green,
+ GLdouble blue, GLdouble alpha );
+GLAPI void GLAPIENTRY glColor4f( GLfloat red, GLfloat green,
+ GLfloat blue, GLfloat alpha );
+GLAPI void GLAPIENTRY glColor4i( GLint red, GLint green,
+ GLint blue, GLint alpha );
+GLAPI void GLAPIENTRY glColor4s( GLshort red, GLshort green,
+ GLshort blue, GLshort alpha );
+GLAPI void GLAPIENTRY glColor4ub( GLubyte red, GLubyte green,
+ GLubyte blue, GLubyte alpha );
+GLAPI void GLAPIENTRY glColor4ui( GLuint red, GLuint green,
+ GLuint blue, GLuint alpha );
+GLAPI void GLAPIENTRY glColor4us( GLushort red, GLushort green,
+ GLushort blue, GLushort alpha );
+
+
+GLAPI void GLAPIENTRY glColor3bv( const GLbyte *v );
+GLAPI void GLAPIENTRY glColor3dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glColor3fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glColor3iv( const GLint *v );
+GLAPI void GLAPIENTRY glColor3sv( const GLshort *v );
+GLAPI void GLAPIENTRY glColor3ubv( const GLubyte *v );
+GLAPI void GLAPIENTRY glColor3uiv( const GLuint *v );
+GLAPI void GLAPIENTRY glColor3usv( const GLushort *v );
+
+GLAPI void GLAPIENTRY glColor4bv( const GLbyte *v );
+GLAPI void GLAPIENTRY glColor4dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glColor4fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glColor4iv( const GLint *v );
+GLAPI void GLAPIENTRY glColor4sv( const GLshort *v );
+GLAPI void GLAPIENTRY glColor4ubv( const GLubyte *v );
+GLAPI void GLAPIENTRY glColor4uiv( const GLuint *v );
+GLAPI void GLAPIENTRY glColor4usv( const GLushort *v );
+
+
+GLAPI void GLAPIENTRY glTexCoord1d( GLdouble s );
+GLAPI void GLAPIENTRY glTexCoord1f( GLfloat s );
+GLAPI void GLAPIENTRY glTexCoord1i( GLint s );
+GLAPI void GLAPIENTRY glTexCoord1s( GLshort s );
+
+GLAPI void GLAPIENTRY glTexCoord2d( GLdouble s, GLdouble t );
+GLAPI void GLAPIENTRY glTexCoord2f( GLfloat s, GLfloat t );
+GLAPI void GLAPIENTRY glTexCoord2i( GLint s, GLint t );
+GLAPI void GLAPIENTRY glTexCoord2s( GLshort s, GLshort t );
+
+GLAPI void GLAPIENTRY glTexCoord3d( GLdouble s, GLdouble t, GLdouble r );
+GLAPI void GLAPIENTRY glTexCoord3f( GLfloat s, GLfloat t, GLfloat r );
+GLAPI void GLAPIENTRY glTexCoord3i( GLint s, GLint t, GLint r );
+GLAPI void GLAPIENTRY glTexCoord3s( GLshort s, GLshort t, GLshort r );
+
+GLAPI void GLAPIENTRY glTexCoord4d( GLdouble s, GLdouble t, GLdouble r, GLdouble q );
+GLAPI void GLAPIENTRY glTexCoord4f( GLfloat s, GLfloat t, GLfloat r, GLfloat q );
+GLAPI void GLAPIENTRY glTexCoord4i( GLint s, GLint t, GLint r, GLint q );
+GLAPI void GLAPIENTRY glTexCoord4s( GLshort s, GLshort t, GLshort r, GLshort q );
+
+GLAPI void GLAPIENTRY glTexCoord1dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glTexCoord1fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glTexCoord1iv( const GLint *v );
+GLAPI void GLAPIENTRY glTexCoord1sv( const GLshort *v );
+
+GLAPI void GLAPIENTRY glTexCoord2dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glTexCoord2fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glTexCoord2iv( const GLint *v );
+GLAPI void GLAPIENTRY glTexCoord2sv( const GLshort *v );
+
+GLAPI void GLAPIENTRY glTexCoord3dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glTexCoord3fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glTexCoord3iv( const GLint *v );
+GLAPI void GLAPIENTRY glTexCoord3sv( const GLshort *v );
+
+GLAPI void GLAPIENTRY glTexCoord4dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glTexCoord4fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glTexCoord4iv( const GLint *v );
+GLAPI void GLAPIENTRY glTexCoord4sv( const GLshort *v );
+
+
+GLAPI void GLAPIENTRY glRasterPos2d( GLdouble x, GLdouble y );
+GLAPI void GLAPIENTRY glRasterPos2f( GLfloat x, GLfloat y );
+GLAPI void GLAPIENTRY glRasterPos2i( GLint x, GLint y );
+GLAPI void GLAPIENTRY glRasterPos2s( GLshort x, GLshort y );
+
+GLAPI void GLAPIENTRY glRasterPos3d( GLdouble x, GLdouble y, GLdouble z );
+GLAPI void GLAPIENTRY glRasterPos3f( GLfloat x, GLfloat y, GLfloat z );
+GLAPI void GLAPIENTRY glRasterPos3i( GLint x, GLint y, GLint z );
+GLAPI void GLAPIENTRY glRasterPos3s( GLshort x, GLshort y, GLshort z );
+
+GLAPI void GLAPIENTRY glRasterPos4d( GLdouble x, GLdouble y, GLdouble z, GLdouble w );
+GLAPI void GLAPIENTRY glRasterPos4f( GLfloat x, GLfloat y, GLfloat z, GLfloat w );
+GLAPI void GLAPIENTRY glRasterPos4i( GLint x, GLint y, GLint z, GLint w );
+GLAPI void GLAPIENTRY glRasterPos4s( GLshort x, GLshort y, GLshort z, GLshort w );
+
+GLAPI void GLAPIENTRY glRasterPos2dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glRasterPos2fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glRasterPos2iv( const GLint *v );
+GLAPI void GLAPIENTRY glRasterPos2sv( const GLshort *v );
+
+GLAPI void GLAPIENTRY glRasterPos3dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glRasterPos3fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glRasterPos3iv( const GLint *v );
+GLAPI void GLAPIENTRY glRasterPos3sv( const GLshort *v );
+
+GLAPI void GLAPIENTRY glRasterPos4dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glRasterPos4fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glRasterPos4iv( const GLint *v );
+GLAPI void GLAPIENTRY glRasterPos4sv( const GLshort *v );
+
+
+GLAPI void GLAPIENTRY glRectd( GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2 );
+GLAPI void GLAPIENTRY glRectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 );
+GLAPI void GLAPIENTRY glRecti( GLint x1, GLint y1, GLint x2, GLint y2 );
+GLAPI void GLAPIENTRY glRects( GLshort x1, GLshort y1, GLshort x2, GLshort y2 );
+
+
+GLAPI void GLAPIENTRY glRectdv( const GLdouble *v1, const GLdouble *v2 );
+GLAPI void GLAPIENTRY glRectfv( const GLfloat *v1, const GLfloat *v2 );
+GLAPI void GLAPIENTRY glRectiv( const GLint *v1, const GLint *v2 );
+GLAPI void GLAPIENTRY glRectsv( const GLshort *v1, const GLshort *v2 );
+
+
+/*
+ * Vertex Arrays (1.1)
+ */
+
+GLAPI void GLAPIENTRY glVertexPointer( GLint size, GLenum type,
+ GLsizei stride, const GLvoid *ptr );
+
+GLAPI void GLAPIENTRY glNormalPointer( GLenum type, GLsizei stride,
+ const GLvoid *ptr );
+
+GLAPI void GLAPIENTRY glColorPointer( GLint size, GLenum type,
+ GLsizei stride, const GLvoid *ptr );
+
+GLAPI void GLAPIENTRY glIndexPointer( GLenum type, GLsizei stride,
+ const GLvoid *ptr );
+
+GLAPI void GLAPIENTRY glTexCoordPointer( GLint size, GLenum type,
+ GLsizei stride, const GLvoid *ptr );
+
+GLAPI void GLAPIENTRY glEdgeFlagPointer( GLsizei stride, const GLvoid *ptr );
+
+GLAPI void GLAPIENTRY glGetPointerv( GLenum pname, GLvoid **params );
+
+GLAPI void GLAPIENTRY glArrayElement( GLint i );
+
+GLAPI void GLAPIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count );
+
+GLAPI void GLAPIENTRY glDrawElements( GLenum mode, GLsizei count,
+ GLenum type, const GLvoid *indices );
+
+GLAPI void GLAPIENTRY glInterleavedArrays( GLenum format, GLsizei stride,
+ const GLvoid *pointer );
+
+/*
+ * Lighting
+ */
+
+GLAPI void GLAPIENTRY glShadeModel( GLenum mode );
+
+GLAPI void GLAPIENTRY glLightf( GLenum light, GLenum pname, GLfloat param );
+GLAPI void GLAPIENTRY glLighti( GLenum light, GLenum pname, GLint param );
+GLAPI void GLAPIENTRY glLightfv( GLenum light, GLenum pname,
+ const GLfloat *params );
+GLAPI void GLAPIENTRY glLightiv( GLenum light, GLenum pname,
+ const GLint *params );
+
+GLAPI void GLAPIENTRY glGetLightfv( GLenum light, GLenum pname,
+ GLfloat *params );
+GLAPI void GLAPIENTRY glGetLightiv( GLenum light, GLenum pname,
+ GLint *params );
+
+GLAPI void GLAPIENTRY glLightModelf( GLenum pname, GLfloat param );
+GLAPI void GLAPIENTRY glLightModeli( GLenum pname, GLint param );
+GLAPI void GLAPIENTRY glLightModelfv( GLenum pname, const GLfloat *params );
+GLAPI void GLAPIENTRY glLightModeliv( GLenum pname, const GLint *params );
+
+GLAPI void GLAPIENTRY glMaterialf( GLenum face, GLenum pname, GLfloat param );
+GLAPI void GLAPIENTRY glMateriali( GLenum face, GLenum pname, GLint param );
+GLAPI void GLAPIENTRY glMaterialfv( GLenum face, GLenum pname, const GLfloat *params );
+GLAPI void GLAPIENTRY glMaterialiv( GLenum face, GLenum pname, const GLint *params );
+
+GLAPI void GLAPIENTRY glGetMaterialfv( GLenum face, GLenum pname, GLfloat *params );
+GLAPI void GLAPIENTRY glGetMaterialiv( GLenum face, GLenum pname, GLint *params );
+
+GLAPI void GLAPIENTRY glColorMaterial( GLenum face, GLenum mode );
+
+
+/*
+ * Raster functions
+ */
+
+GLAPI void GLAPIENTRY glPixelZoom( GLfloat xfactor, GLfloat yfactor );
+
+GLAPI void GLAPIENTRY glPixelStoref( GLenum pname, GLfloat param );
+GLAPI void GLAPIENTRY glPixelStorei( GLenum pname, GLint param );
+
+GLAPI void GLAPIENTRY glPixelTransferf( GLenum pname, GLfloat param );
+GLAPI void GLAPIENTRY glPixelTransferi( GLenum pname, GLint param );
+
+GLAPI void GLAPIENTRY glPixelMapfv( GLenum map, GLsizei mapsize,
+ const GLfloat *values );
+GLAPI void GLAPIENTRY glPixelMapuiv( GLenum map, GLsizei mapsize,
+ const GLuint *values );
+GLAPI void GLAPIENTRY glPixelMapusv( GLenum map, GLsizei mapsize,
+ const GLushort *values );
+
+GLAPI void GLAPIENTRY glGetPixelMapfv( GLenum map, GLfloat *values );
+GLAPI void GLAPIENTRY glGetPixelMapuiv( GLenum map, GLuint *values );
+GLAPI void GLAPIENTRY glGetPixelMapusv( GLenum map, GLushort *values );
+
+GLAPI void GLAPIENTRY glBitmap( GLsizei width, GLsizei height,
+ GLfloat xorig, GLfloat yorig,
+ GLfloat xmove, GLfloat ymove,
+ const GLubyte *bitmap );
+
+GLAPI void GLAPIENTRY glReadPixels( GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ GLvoid *pixels );
+
+GLAPI void GLAPIENTRY glDrawPixels( GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const GLvoid *pixels );
+
+GLAPI void GLAPIENTRY glCopyPixels( GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum type );
+
+/*
+ * Stenciling
+ */
+
+GLAPI void GLAPIENTRY glStencilFunc( GLenum func, GLint ref, GLuint mask );
+
+GLAPI void GLAPIENTRY glStencilMask( GLuint mask );
+
+GLAPI void GLAPIENTRY glStencilOp( GLenum fail, GLenum zfail, GLenum zpass );
+
+GLAPI void GLAPIENTRY glClearStencil( GLint s );
+
+
+
+/*
+ * Texture mapping
+ */
+
+GLAPI void GLAPIENTRY glTexGend( GLenum coord, GLenum pname, GLdouble param );
+GLAPI void GLAPIENTRY glTexGenf( GLenum coord, GLenum pname, GLfloat param );
+GLAPI void GLAPIENTRY glTexGeni( GLenum coord, GLenum pname, GLint param );
+
+GLAPI void GLAPIENTRY glTexGendv( GLenum coord, GLenum pname, const GLdouble *params );
+GLAPI void GLAPIENTRY glTexGenfv( GLenum coord, GLenum pname, const GLfloat *params );
+GLAPI void GLAPIENTRY glTexGeniv( GLenum coord, GLenum pname, const GLint *params );
+
+GLAPI void GLAPIENTRY glGetTexGendv( GLenum coord, GLenum pname, GLdouble *params );
+GLAPI void GLAPIENTRY glGetTexGenfv( GLenum coord, GLenum pname, GLfloat *params );
+GLAPI void GLAPIENTRY glGetTexGeniv( GLenum coord, GLenum pname, GLint *params );
+
+
+GLAPI void GLAPIENTRY glTexEnvf( GLenum target, GLenum pname, GLfloat param );
+GLAPI void GLAPIENTRY glTexEnvi( GLenum target, GLenum pname, GLint param );
+
+GLAPI void GLAPIENTRY glTexEnvfv( GLenum target, GLenum pname, const GLfloat *params );
+GLAPI void GLAPIENTRY glTexEnviv( GLenum target, GLenum pname, const GLint *params );
+
+GLAPI void GLAPIENTRY glGetTexEnvfv( GLenum target, GLenum pname, GLfloat *params );
+GLAPI void GLAPIENTRY glGetTexEnviv( GLenum target, GLenum pname, GLint *params );
+
+
+GLAPI void GLAPIENTRY glTexParameterf( GLenum target, GLenum pname, GLfloat param );
+GLAPI void GLAPIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param );
+
+GLAPI void GLAPIENTRY glTexParameterfv( GLenum target, GLenum pname,
+ const GLfloat *params );
+GLAPI void GLAPIENTRY glTexParameteriv( GLenum target, GLenum pname,
+ const GLint *params );
+
+GLAPI void GLAPIENTRY glGetTexParameterfv( GLenum target,
+ GLenum pname, GLfloat *params);
+GLAPI void GLAPIENTRY glGetTexParameteriv( GLenum target,
+ GLenum pname, GLint *params );
+
+GLAPI void GLAPIENTRY glGetTexLevelParameterfv( GLenum target, GLint level,
+ GLenum pname, GLfloat *params );
+GLAPI void GLAPIENTRY glGetTexLevelParameteriv( GLenum target, GLint level,
+ GLenum pname, GLint *params );
+
+
+GLAPI void GLAPIENTRY glTexImage1D( GLenum target, GLint level,
+ GLint internalFormat,
+ GLsizei width, GLint border,
+ GLenum format, GLenum type,
+ const GLvoid *pixels );
+
+GLAPI void GLAPIENTRY glTexImage2D( GLenum target, GLint level,
+ GLint internalFormat,
+ GLsizei width, GLsizei height,
+ GLint border, GLenum format, GLenum type,
+ const GLvoid *pixels );
+
+GLAPI void GLAPIENTRY glGetTexImage( GLenum target, GLint level,
+ GLenum format, GLenum type,
+ GLvoid *pixels );
+
+
+/* 1.1 functions */
+
+GLAPI void GLAPIENTRY glGenTextures( GLsizei n, GLuint *textures );
+
+GLAPI void GLAPIENTRY glDeleteTextures( GLsizei n, const GLuint *textures);
+
+GLAPI void GLAPIENTRY glBindTexture( GLenum target, GLuint texture );
+
+GLAPI void GLAPIENTRY glPrioritizeTextures( GLsizei n,
+ const GLuint *textures,
+ const GLclampf *priorities );
+
+GLAPI GLboolean GLAPIENTRY glAreTexturesResident( GLsizei n,
+ const GLuint *textures,
+ GLboolean *residences );
+
+GLAPI GLboolean GLAPIENTRY glIsTexture( GLuint texture );
+
+
+GLAPI void GLAPIENTRY glTexSubImage1D( GLenum target, GLint level,
+ GLint xoffset,
+ GLsizei width, GLenum format,
+ GLenum type, const GLvoid *pixels );
+
+
+GLAPI void GLAPIENTRY glTexSubImage2D( GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const GLvoid *pixels );
+
+
+GLAPI void GLAPIENTRY glCopyTexImage1D( GLenum target, GLint level,
+ GLenum internalformat,
+ GLint x, GLint y,
+ GLsizei width, GLint border );
+
+
+GLAPI void GLAPIENTRY glCopyTexImage2D( GLenum target, GLint level,
+ GLenum internalformat,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLint border );
+
+
+GLAPI void GLAPIENTRY glCopyTexSubImage1D( GLenum target, GLint level,
+ GLint xoffset, GLint x, GLint y,
+ GLsizei width );
+
+
+GLAPI void GLAPIENTRY glCopyTexSubImage2D( GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height );
+
+
+/*
+ * Evaluators
+ */
+
+GLAPI void GLAPIENTRY glMap1d( GLenum target, GLdouble u1, GLdouble u2,
+ GLint stride,
+ GLint order, const GLdouble *points );
+GLAPI void GLAPIENTRY glMap1f( GLenum target, GLfloat u1, GLfloat u2,
+ GLint stride,
+ GLint order, const GLfloat *points );
+
+GLAPI void GLAPIENTRY glMap2d( GLenum target,
+ GLdouble u1, GLdouble u2, GLint ustride, GLint uorder,
+ GLdouble v1, GLdouble v2, GLint vstride, GLint vorder,
+ const GLdouble *points );
+GLAPI void GLAPIENTRY glMap2f( GLenum target,
+ GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
+ GLfloat v1, GLfloat v2, GLint vstride, GLint vorder,
+ const GLfloat *points );
+
+GLAPI void GLAPIENTRY glGetMapdv( GLenum target, GLenum query, GLdouble *v );
+GLAPI void GLAPIENTRY glGetMapfv( GLenum target, GLenum query, GLfloat *v );
+GLAPI void GLAPIENTRY glGetMapiv( GLenum target, GLenum query, GLint *v );
+
+GLAPI void GLAPIENTRY glEvalCoord1d( GLdouble u );
+GLAPI void GLAPIENTRY glEvalCoord1f( GLfloat u );
+
+GLAPI void GLAPIENTRY glEvalCoord1dv( const GLdouble *u );
+GLAPI void GLAPIENTRY glEvalCoord1fv( const GLfloat *u );
+
+GLAPI void GLAPIENTRY glEvalCoord2d( GLdouble u, GLdouble v );
+GLAPI void GLAPIENTRY glEvalCoord2f( GLfloat u, GLfloat v );
+
+GLAPI void GLAPIENTRY glEvalCoord2dv( const GLdouble *u );
+GLAPI void GLAPIENTRY glEvalCoord2fv( const GLfloat *u );
+
+GLAPI void GLAPIENTRY glMapGrid1d( GLint un, GLdouble u1, GLdouble u2 );
+GLAPI void GLAPIENTRY glMapGrid1f( GLint un, GLfloat u1, GLfloat u2 );
+
+GLAPI void GLAPIENTRY glMapGrid2d( GLint un, GLdouble u1, GLdouble u2,
+ GLint vn, GLdouble v1, GLdouble v2 );
+GLAPI void GLAPIENTRY glMapGrid2f( GLint un, GLfloat u1, GLfloat u2,
+ GLint vn, GLfloat v1, GLfloat v2 );
+
+GLAPI void GLAPIENTRY glEvalPoint1( GLint i );
+
+GLAPI void GLAPIENTRY glEvalPoint2( GLint i, GLint j );
+
+GLAPI void GLAPIENTRY glEvalMesh1( GLenum mode, GLint i1, GLint i2 );
+
+GLAPI void GLAPIENTRY glEvalMesh2( GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2 );
+
+
+/*
+ * Fog
+ */
+
+GLAPI void GLAPIENTRY glFogf( GLenum pname, GLfloat param );
+
+GLAPI void GLAPIENTRY glFogi( GLenum pname, GLint param );
+
+GLAPI void GLAPIENTRY glFogfv( GLenum pname, const GLfloat *params );
+
+GLAPI void GLAPIENTRY glFogiv( GLenum pname, const GLint *params );
+
+
+/*
+ * Selection and Feedback
+ */
+
+GLAPI void GLAPIENTRY glFeedbackBuffer( GLsizei size, GLenum type, GLfloat *buffer );
+
+GLAPI void GLAPIENTRY glPassThrough( GLfloat token );
+
+GLAPI void GLAPIENTRY glSelectBuffer( GLsizei size, GLuint *buffer );
+
+GLAPI void GLAPIENTRY glInitNames( void );
+
+GLAPI void GLAPIENTRY glLoadName( GLuint name );
+
+GLAPI void GLAPIENTRY glPushName( GLuint name );
+
+GLAPI void GLAPIENTRY glPopName( void );
+
+
+
+/*
+ * OpenGL 1.2
+ */
+
+#define GL_RESCALE_NORMAL 0x803A
+#define GL_CLAMP_TO_EDGE 0x812F
+#define GL_MAX_ELEMENTS_VERTICES 0x80E8
+#define GL_MAX_ELEMENTS_INDICES 0x80E9
+#define GL_BGR 0x80E0
+#define GL_BGRA 0x80E1
+#define GL_UNSIGNED_BYTE_3_3_2 0x8032
+#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362
+#define GL_UNSIGNED_SHORT_5_6_5 0x8363
+#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
+#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
+#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
+#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
+#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
+#define GL_UNSIGNED_INT_8_8_8_8 0x8035
+#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
+#define GL_UNSIGNED_INT_10_10_10_2 0x8036
+#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
+#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8
+#define GL_SINGLE_COLOR 0x81F9
+#define GL_SEPARATE_SPECULAR_COLOR 0x81FA
+#define GL_TEXTURE_MIN_LOD 0x813A
+#define GL_TEXTURE_MAX_LOD 0x813B
+#define GL_TEXTURE_BASE_LEVEL 0x813C
+#define GL_TEXTURE_MAX_LEVEL 0x813D
+#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12
+#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13
+#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22
+#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23
+#define GL_ALIASED_POINT_SIZE_RANGE 0x846D
+#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E
+#define GL_PACK_SKIP_IMAGES 0x806B
+#define GL_PACK_IMAGE_HEIGHT 0x806C
+#define GL_UNPACK_SKIP_IMAGES 0x806D
+#define GL_UNPACK_IMAGE_HEIGHT 0x806E
+#define GL_TEXTURE_3D 0x806F
+#define GL_PROXY_TEXTURE_3D 0x8070
+#define GL_TEXTURE_DEPTH 0x8071
+#define GL_TEXTURE_WRAP_R 0x8072
+#define GL_MAX_3D_TEXTURE_SIZE 0x8073
+#define GL_TEXTURE_BINDING_3D 0x806A
+
+GLAPI void GLAPIENTRY glDrawRangeElements( GLenum mode, GLuint start,
+ GLuint end, GLsizei count, GLenum type, const GLvoid *indices );
+
+GLAPI void GLAPIENTRY glTexImage3D( GLenum target, GLint level,
+ GLint internalFormat,
+ GLsizei width, GLsizei height,
+ GLsizei depth, GLint border,
+ GLenum format, GLenum type,
+ const GLvoid *pixels );
+
+GLAPI void GLAPIENTRY glTexSubImage3D( GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLint zoffset, GLsizei width,
+ GLsizei height, GLsizei depth,
+ GLenum format,
+ GLenum type, const GLvoid *pixels);
+
+GLAPI void GLAPIENTRY glCopyTexSubImage3D( GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLint zoffset, GLint x,
+ GLint y, GLsizei width,
+ GLsizei height );
+
+typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
+typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
+typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels);
+typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+
+
+/*
+ * GL_ARB_imaging
+ */
+
+#define GL_CONSTANT_COLOR 0x8001
+#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002
+#define GL_CONSTANT_ALPHA 0x8003
+#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004
+#define GL_COLOR_TABLE 0x80D0
+#define GL_POST_CONVOLUTION_COLOR_TABLE 0x80D1
+#define GL_POST_COLOR_MATRIX_COLOR_TABLE 0x80D2
+#define GL_PROXY_COLOR_TABLE 0x80D3
+#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE 0x80D4
+#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE 0x80D5
+#define GL_COLOR_TABLE_SCALE 0x80D6
+#define GL_COLOR_TABLE_BIAS 0x80D7
+#define GL_COLOR_TABLE_FORMAT 0x80D8
+#define GL_COLOR_TABLE_WIDTH 0x80D9
+#define GL_COLOR_TABLE_RED_SIZE 0x80DA
+#define GL_COLOR_TABLE_GREEN_SIZE 0x80DB
+#define GL_COLOR_TABLE_BLUE_SIZE 0x80DC
+#define GL_COLOR_TABLE_ALPHA_SIZE 0x80DD
+#define GL_COLOR_TABLE_LUMINANCE_SIZE 0x80DE
+#define GL_COLOR_TABLE_INTENSITY_SIZE 0x80DF
+#define GL_CONVOLUTION_1D 0x8010
+#define GL_CONVOLUTION_2D 0x8011
+#define GL_SEPARABLE_2D 0x8012
+#define GL_CONVOLUTION_BORDER_MODE 0x8013
+#define GL_CONVOLUTION_FILTER_SCALE 0x8014
+#define GL_CONVOLUTION_FILTER_BIAS 0x8015
+#define GL_REDUCE 0x8016
+#define GL_CONVOLUTION_FORMAT 0x8017
+#define GL_CONVOLUTION_WIDTH 0x8018
+#define GL_CONVOLUTION_HEIGHT 0x8019
+#define GL_MAX_CONVOLUTION_WIDTH 0x801A
+#define GL_MAX_CONVOLUTION_HEIGHT 0x801B
+#define GL_POST_CONVOLUTION_RED_SCALE 0x801C
+#define GL_POST_CONVOLUTION_GREEN_SCALE 0x801D
+#define GL_POST_CONVOLUTION_BLUE_SCALE 0x801E
+#define GL_POST_CONVOLUTION_ALPHA_SCALE 0x801F
+#define GL_POST_CONVOLUTION_RED_BIAS 0x8020
+#define GL_POST_CONVOLUTION_GREEN_BIAS 0x8021
+#define GL_POST_CONVOLUTION_BLUE_BIAS 0x8022
+#define GL_POST_CONVOLUTION_ALPHA_BIAS 0x8023
+#define GL_CONSTANT_BORDER 0x8151
+#define GL_REPLICATE_BORDER 0x8153
+#define GL_CONVOLUTION_BORDER_COLOR 0x8154
+#define GL_COLOR_MATRIX 0x80B1
+#define GL_COLOR_MATRIX_STACK_DEPTH 0x80B2
+#define GL_MAX_COLOR_MATRIX_STACK_DEPTH 0x80B3
+#define GL_POST_COLOR_MATRIX_RED_SCALE 0x80B4
+#define GL_POST_COLOR_MATRIX_GREEN_SCALE 0x80B5
+#define GL_POST_COLOR_MATRIX_BLUE_SCALE 0x80B6
+#define GL_POST_COLOR_MATRIX_ALPHA_SCALE 0x80B7
+#define GL_POST_COLOR_MATRIX_RED_BIAS 0x80B8
+#define GL_POST_COLOR_MATRIX_GREEN_BIAS 0x80B9
+#define GL_POST_COLOR_MATRIX_BLUE_BIAS 0x80BA
+#define GL_POST_COLOR_MATRIX_ALPHA_BIAS 0x80BB
+#define GL_HISTOGRAM 0x8024
+#define GL_PROXY_HISTOGRAM 0x8025
+#define GL_HISTOGRAM_WIDTH 0x8026
+#define GL_HISTOGRAM_FORMAT 0x8027
+#define GL_HISTOGRAM_RED_SIZE 0x8028
+#define GL_HISTOGRAM_GREEN_SIZE 0x8029
+#define GL_HISTOGRAM_BLUE_SIZE 0x802A
+#define GL_HISTOGRAM_ALPHA_SIZE 0x802B
+#define GL_HISTOGRAM_LUMINANCE_SIZE 0x802C
+#define GL_HISTOGRAM_SINK 0x802D
+#define GL_MINMAX 0x802E
+#define GL_MINMAX_FORMAT 0x802F
+#define GL_MINMAX_SINK 0x8030
+#define GL_TABLE_TOO_LARGE 0x8031
+#define GL_BLEND_EQUATION 0x8009
+#define GL_MIN 0x8007
+#define GL_MAX 0x8008
+#define GL_FUNC_ADD 0x8006
+#define GL_FUNC_SUBTRACT 0x800A
+#define GL_FUNC_REVERSE_SUBTRACT 0x800B
+#define GL_BLEND_COLOR 0x8005
+
+
+GLAPI void GLAPIENTRY glColorTable( GLenum target, GLenum internalformat,
+ GLsizei width, GLenum format,
+ GLenum type, const GLvoid *table );
+
+GLAPI void GLAPIENTRY glColorSubTable( GLenum target,
+ GLsizei start, GLsizei count,
+ GLenum format, GLenum type,
+ const GLvoid *data );
+
+GLAPI void GLAPIENTRY glColorTableParameteriv(GLenum target, GLenum pname,
+ const GLint *params);
+
+GLAPI void GLAPIENTRY glColorTableParameterfv(GLenum target, GLenum pname,
+ const GLfloat *params);
+
+GLAPI void GLAPIENTRY glCopyColorSubTable( GLenum target, GLsizei start,
+ GLint x, GLint y, GLsizei width );
+
+GLAPI void GLAPIENTRY glCopyColorTable( GLenum target, GLenum internalformat,
+ GLint x, GLint y, GLsizei width );
+
+GLAPI void GLAPIENTRY glGetColorTable( GLenum target, GLenum format,
+ GLenum type, GLvoid *table );
+
+GLAPI void GLAPIENTRY glGetColorTableParameterfv( GLenum target, GLenum pname,
+ GLfloat *params );
+
+GLAPI void GLAPIENTRY glGetColorTableParameteriv( GLenum target, GLenum pname,
+ GLint *params );
+
+GLAPI void GLAPIENTRY glBlendEquation( GLenum mode );
+
+GLAPI void GLAPIENTRY glBlendColor( GLclampf red, GLclampf green,
+ GLclampf blue, GLclampf alpha );
+
+GLAPI void GLAPIENTRY glHistogram( GLenum target, GLsizei width,
+ GLenum internalformat, GLboolean sink );
+
+GLAPI void GLAPIENTRY glResetHistogram( GLenum target );
+
+GLAPI void GLAPIENTRY glGetHistogram( GLenum target, GLboolean reset,
+ GLenum format, GLenum type,
+ GLvoid *values );
+
+GLAPI void GLAPIENTRY glGetHistogramParameterfv( GLenum target, GLenum pname,
+ GLfloat *params );
+
+GLAPI void GLAPIENTRY glGetHistogramParameteriv( GLenum target, GLenum pname,
+ GLint *params );
+
+GLAPI void GLAPIENTRY glMinmax( GLenum target, GLenum internalformat,
+ GLboolean sink );
+
+GLAPI void GLAPIENTRY glResetMinmax( GLenum target );
+
+GLAPI void GLAPIENTRY glGetMinmax( GLenum target, GLboolean reset,
+ GLenum format, GLenum types,
+ GLvoid *values );
+
+GLAPI void GLAPIENTRY glGetMinmaxParameterfv( GLenum target, GLenum pname,
+ GLfloat *params );
+
+GLAPI void GLAPIENTRY glGetMinmaxParameteriv( GLenum target, GLenum pname,
+ GLint *params );
+
+GLAPI void GLAPIENTRY glConvolutionFilter1D( GLenum target,
+ GLenum internalformat, GLsizei width, GLenum format, GLenum type,
+ const GLvoid *image );
+
+GLAPI void GLAPIENTRY glConvolutionFilter2D( GLenum target,
+ GLenum internalformat, GLsizei width, GLsizei height, GLenum format,
+ GLenum type, const GLvoid *image );
+
+GLAPI void GLAPIENTRY glConvolutionParameterf( GLenum target, GLenum pname,
+ GLfloat params );
+
+GLAPI void GLAPIENTRY glConvolutionParameterfv( GLenum target, GLenum pname,
+ const GLfloat *params );
+
+GLAPI void GLAPIENTRY glConvolutionParameteri( GLenum target, GLenum pname,
+ GLint params );
+
+GLAPI void GLAPIENTRY glConvolutionParameteriv( GLenum target, GLenum pname,
+ const GLint *params );
+
+GLAPI void GLAPIENTRY glCopyConvolutionFilter1D( GLenum target,
+ GLenum internalformat, GLint x, GLint y, GLsizei width );
+
+GLAPI void GLAPIENTRY glCopyConvolutionFilter2D( GLenum target,
+ GLenum internalformat, GLint x, GLint y, GLsizei width,
+ GLsizei height);
+
+GLAPI void GLAPIENTRY glGetConvolutionFilter( GLenum target, GLenum format,
+ GLenum type, GLvoid *image );
+
+GLAPI void GLAPIENTRY glGetConvolutionParameterfv( GLenum target, GLenum pname,
+ GLfloat *params );
+
+GLAPI void GLAPIENTRY glGetConvolutionParameteriv( GLenum target, GLenum pname,
+ GLint *params );
+
+GLAPI void GLAPIENTRY glSeparableFilter2D( GLenum target,
+ GLenum internalformat, GLsizei width, GLsizei height, GLenum format,
+ GLenum type, const GLvoid *row, const GLvoid *column );
+
+GLAPI void GLAPIENTRY glGetSeparableFilter( GLenum target, GLenum format,
+ GLenum type, GLvoid *row, GLvoid *column, GLvoid *span );
+
+
+
+
+/*
+ * OpenGL 1.3
+ */
+
+/* multitexture */
+#define GL_TEXTURE0 0x84C0
+#define GL_TEXTURE1 0x84C1
+#define GL_TEXTURE2 0x84C2
+#define GL_TEXTURE3 0x84C3
+#define GL_TEXTURE4 0x84C4
+#define GL_TEXTURE5 0x84C5
+#define GL_TEXTURE6 0x84C6
+#define GL_TEXTURE7 0x84C7
+#define GL_TEXTURE8 0x84C8
+#define GL_TEXTURE9 0x84C9
+#define GL_TEXTURE10 0x84CA
+#define GL_TEXTURE11 0x84CB
+#define GL_TEXTURE12 0x84CC
+#define GL_TEXTURE13 0x84CD
+#define GL_TEXTURE14 0x84CE
+#define GL_TEXTURE15 0x84CF
+#define GL_TEXTURE16 0x84D0
+#define GL_TEXTURE17 0x84D1
+#define GL_TEXTURE18 0x84D2
+#define GL_TEXTURE19 0x84D3
+#define GL_TEXTURE20 0x84D4
+#define GL_TEXTURE21 0x84D5
+#define GL_TEXTURE22 0x84D6
+#define GL_TEXTURE23 0x84D7
+#define GL_TEXTURE24 0x84D8
+#define GL_TEXTURE25 0x84D9
+#define GL_TEXTURE26 0x84DA
+#define GL_TEXTURE27 0x84DB
+#define GL_TEXTURE28 0x84DC
+#define GL_TEXTURE29 0x84DD
+#define GL_TEXTURE30 0x84DE
+#define GL_TEXTURE31 0x84DF
+#define GL_ACTIVE_TEXTURE 0x84E0
+#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1
+#define GL_MAX_TEXTURE_UNITS 0x84E2
+/* texture_cube_map */
+#define GL_NORMAL_MAP 0x8511
+#define GL_REFLECTION_MAP 0x8512
+#define GL_TEXTURE_CUBE_MAP 0x8513
+#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
+#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B
+#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C
+/* texture_compression */
+#define GL_COMPRESSED_ALPHA 0x84E9
+#define GL_COMPRESSED_LUMINANCE 0x84EA
+#define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB
+#define GL_COMPRESSED_INTENSITY 0x84EC
+#define GL_COMPRESSED_RGB 0x84ED
+#define GL_COMPRESSED_RGBA 0x84EE
+#define GL_TEXTURE_COMPRESSION_HINT 0x84EF
+#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0
+#define GL_TEXTURE_COMPRESSED 0x86A1
+#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2
+#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3
+/* multisample */
+#define GL_MULTISAMPLE 0x809D
+#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E
+#define GL_SAMPLE_ALPHA_TO_ONE 0x809F
+#define GL_SAMPLE_COVERAGE 0x80A0
+#define GL_SAMPLE_BUFFERS 0x80A8
+#define GL_SAMPLES 0x80A9
+#define GL_SAMPLE_COVERAGE_VALUE 0x80AA
+#define GL_SAMPLE_COVERAGE_INVERT 0x80AB
+#define GL_MULTISAMPLE_BIT 0x20000000
+/* transpose_matrix */
+#define GL_TRANSPOSE_MODELVIEW_MATRIX 0x84E3
+#define GL_TRANSPOSE_PROJECTION_MATRIX 0x84E4
+#define GL_TRANSPOSE_TEXTURE_MATRIX 0x84E5
+#define GL_TRANSPOSE_COLOR_MATRIX 0x84E6
+/* texture_env_combine */
+#define GL_COMBINE 0x8570
+#define GL_COMBINE_RGB 0x8571
+#define GL_COMBINE_ALPHA 0x8572
+#define GL_SOURCE0_RGB 0x8580
+#define GL_SOURCE1_RGB 0x8581
+#define GL_SOURCE2_RGB 0x8582
+#define GL_SOURCE0_ALPHA 0x8588
+#define GL_SOURCE1_ALPHA 0x8589
+#define GL_SOURCE2_ALPHA 0x858A
+#define GL_OPERAND0_RGB 0x8590
+#define GL_OPERAND1_RGB 0x8591
+#define GL_OPERAND2_RGB 0x8592
+#define GL_OPERAND0_ALPHA 0x8598
+#define GL_OPERAND1_ALPHA 0x8599
+#define GL_OPERAND2_ALPHA 0x859A
+#define GL_RGB_SCALE 0x8573
+#define GL_ADD_SIGNED 0x8574
+#define GL_INTERPOLATE 0x8575
+#define GL_SUBTRACT 0x84E7
+#define GL_CONSTANT 0x8576
+#define GL_PRIMARY_COLOR 0x8577
+#define GL_PREVIOUS 0x8578
+/* texture_env_dot3 */
+#define GL_DOT3_RGB 0x86AE
+#define GL_DOT3_RGBA 0x86AF
+/* texture_border_clamp */
+#define GL_CLAMP_TO_BORDER 0x812D
+
+GLAPI void GLAPIENTRY glActiveTexture( GLenum texture );
+
+GLAPI void GLAPIENTRY glClientActiveTexture( GLenum texture );
+
+GLAPI void GLAPIENTRY glCompressedTexImage1D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data );
+
+GLAPI void GLAPIENTRY glCompressedTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data );
+
+GLAPI void GLAPIENTRY glCompressedTexImage3D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data );
+
+GLAPI void GLAPIENTRY glCompressedTexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data );
+
+GLAPI void GLAPIENTRY glCompressedTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data );
+
+GLAPI void GLAPIENTRY glCompressedTexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data );
+
+GLAPI void GLAPIENTRY glGetCompressedTexImage( GLenum target, GLint lod, GLvoid *img );
+
+GLAPI void GLAPIENTRY glMultiTexCoord1d( GLenum target, GLdouble s );
+
+GLAPI void GLAPIENTRY glMultiTexCoord1dv( GLenum target, const GLdouble *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord1f( GLenum target, GLfloat s );
+
+GLAPI void GLAPIENTRY glMultiTexCoord1fv( GLenum target, const GLfloat *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord1i( GLenum target, GLint s );
+
+GLAPI void GLAPIENTRY glMultiTexCoord1iv( GLenum target, const GLint *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord1s( GLenum target, GLshort s );
+
+GLAPI void GLAPIENTRY glMultiTexCoord1sv( GLenum target, const GLshort *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord2d( GLenum target, GLdouble s, GLdouble t );
+
+GLAPI void GLAPIENTRY glMultiTexCoord2dv( GLenum target, const GLdouble *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord2f( GLenum target, GLfloat s, GLfloat t );
+
+GLAPI void GLAPIENTRY glMultiTexCoord2fv( GLenum target, const GLfloat *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord2i( GLenum target, GLint s, GLint t );
+
+GLAPI void GLAPIENTRY glMultiTexCoord2iv( GLenum target, const GLint *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord2s( GLenum target, GLshort s, GLshort t );
+
+GLAPI void GLAPIENTRY glMultiTexCoord2sv( GLenum target, const GLshort *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord3d( GLenum target, GLdouble s, GLdouble t, GLdouble r );
+
+GLAPI void GLAPIENTRY glMultiTexCoord3dv( GLenum target, const GLdouble *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord3f( GLenum target, GLfloat s, GLfloat t, GLfloat r );
+
+GLAPI void GLAPIENTRY glMultiTexCoord3fv( GLenum target, const GLfloat *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord3i( GLenum target, GLint s, GLint t, GLint r );
+
+GLAPI void GLAPIENTRY glMultiTexCoord3iv( GLenum target, const GLint *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord3s( GLenum target, GLshort s, GLshort t, GLshort r );
+
+GLAPI void GLAPIENTRY glMultiTexCoord3sv( GLenum target, const GLshort *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord4d( GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q );
+
+GLAPI void GLAPIENTRY glMultiTexCoord4dv( GLenum target, const GLdouble *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord4f( GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q );
+
+GLAPI void GLAPIENTRY glMultiTexCoord4fv( GLenum target, const GLfloat *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord4i( GLenum target, GLint s, GLint t, GLint r, GLint q );
+
+GLAPI void GLAPIENTRY glMultiTexCoord4iv( GLenum target, const GLint *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord4s( GLenum target, GLshort s, GLshort t, GLshort r, GLshort q );
+
+GLAPI void GLAPIENTRY glMultiTexCoord4sv( GLenum target, const GLshort *v );
+
+
+GLAPI void GLAPIENTRY glLoadTransposeMatrixd( const GLdouble m[16] );
+
+GLAPI void GLAPIENTRY glLoadTransposeMatrixf( const GLfloat m[16] );
+
+GLAPI void GLAPIENTRY glMultTransposeMatrixd( const GLdouble m[16] );
+
+GLAPI void GLAPIENTRY glMultTransposeMatrixf( const GLfloat m[16] );
+
+GLAPI void GLAPIENTRY glSampleCoverage( GLclampf value, GLboolean invert );
+
+
+typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
+typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLclampf value, GLboolean invert);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data);
+typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, GLvoid *img);
+
+
+
+/*
+ * GL_ARB_multitexture (ARB extension 1 and OpenGL 1.2.1)
+ */
+#ifndef GL_ARB_multitexture
+#define GL_ARB_multitexture 1
+
+#define GL_TEXTURE0_ARB 0x84C0
+#define GL_TEXTURE1_ARB 0x84C1
+#define GL_TEXTURE2_ARB 0x84C2
+#define GL_TEXTURE3_ARB 0x84C3
+#define GL_TEXTURE4_ARB 0x84C4
+#define GL_TEXTURE5_ARB 0x84C5
+#define GL_TEXTURE6_ARB 0x84C6
+#define GL_TEXTURE7_ARB 0x84C7
+#define GL_TEXTURE8_ARB 0x84C8
+#define GL_TEXTURE9_ARB 0x84C9
+#define GL_TEXTURE10_ARB 0x84CA
+#define GL_TEXTURE11_ARB 0x84CB
+#define GL_TEXTURE12_ARB 0x84CC
+#define GL_TEXTURE13_ARB 0x84CD
+#define GL_TEXTURE14_ARB 0x84CE
+#define GL_TEXTURE15_ARB 0x84CF
+#define GL_TEXTURE16_ARB 0x84D0
+#define GL_TEXTURE17_ARB 0x84D1
+#define GL_TEXTURE18_ARB 0x84D2
+#define GL_TEXTURE19_ARB 0x84D3
+#define GL_TEXTURE20_ARB 0x84D4
+#define GL_TEXTURE21_ARB 0x84D5
+#define GL_TEXTURE22_ARB 0x84D6
+#define GL_TEXTURE23_ARB 0x84D7
+#define GL_TEXTURE24_ARB 0x84D8
+#define GL_TEXTURE25_ARB 0x84D9
+#define GL_TEXTURE26_ARB 0x84DA
+#define GL_TEXTURE27_ARB 0x84DB
+#define GL_TEXTURE28_ARB 0x84DC
+#define GL_TEXTURE29_ARB 0x84DD
+#define GL_TEXTURE30_ARB 0x84DE
+#define GL_TEXTURE31_ARB 0x84DF
+#define GL_ACTIVE_TEXTURE_ARB 0x84E0
+#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1
+#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2
+
+GLAPI void GLAPIENTRY glActiveTextureARB(GLenum texture);
+GLAPI void GLAPIENTRY glClientActiveTextureARB(GLenum texture);
+GLAPI void GLAPIENTRY glMultiTexCoord1dARB(GLenum target, GLdouble s);
+GLAPI void GLAPIENTRY glMultiTexCoord1dvARB(GLenum target, const GLdouble *v);
+GLAPI void GLAPIENTRY glMultiTexCoord1fARB(GLenum target, GLfloat s);
+GLAPI void GLAPIENTRY glMultiTexCoord1fvARB(GLenum target, const GLfloat *v);
+GLAPI void GLAPIENTRY glMultiTexCoord1iARB(GLenum target, GLint s);
+GLAPI void GLAPIENTRY glMultiTexCoord1ivARB(GLenum target, const GLint *v);
+GLAPI void GLAPIENTRY glMultiTexCoord1sARB(GLenum target, GLshort s);
+GLAPI void GLAPIENTRY glMultiTexCoord1svARB(GLenum target, const GLshort *v);
+GLAPI void GLAPIENTRY glMultiTexCoord2dARB(GLenum target, GLdouble s, GLdouble t);
+GLAPI void GLAPIENTRY glMultiTexCoord2dvARB(GLenum target, const GLdouble *v);
+GLAPI void GLAPIENTRY glMultiTexCoord2fARB(GLenum target, GLfloat s, GLfloat t);
+GLAPI void GLAPIENTRY glMultiTexCoord2fvARB(GLenum target, const GLfloat *v);
+GLAPI void GLAPIENTRY glMultiTexCoord2iARB(GLenum target, GLint s, GLint t);
+GLAPI void GLAPIENTRY glMultiTexCoord2ivARB(GLenum target, const GLint *v);
+GLAPI void GLAPIENTRY glMultiTexCoord2sARB(GLenum target, GLshort s, GLshort t);
+GLAPI void GLAPIENTRY glMultiTexCoord2svARB(GLenum target, const GLshort *v);
+GLAPI void GLAPIENTRY glMultiTexCoord3dARB(GLenum target, GLdouble s, GLdouble t, GLdouble r);
+GLAPI void GLAPIENTRY glMultiTexCoord3dvARB(GLenum target, const GLdouble *v);
+GLAPI void GLAPIENTRY glMultiTexCoord3fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r);
+GLAPI void GLAPIENTRY glMultiTexCoord3fvARB(GLenum target, const GLfloat *v);
+GLAPI void GLAPIENTRY glMultiTexCoord3iARB(GLenum target, GLint s, GLint t, GLint r);
+GLAPI void GLAPIENTRY glMultiTexCoord3ivARB(GLenum target, const GLint *v);
+GLAPI void GLAPIENTRY glMultiTexCoord3sARB(GLenum target, GLshort s, GLshort t, GLshort r);
+GLAPI void GLAPIENTRY glMultiTexCoord3svARB(GLenum target, const GLshort *v);
+GLAPI void GLAPIENTRY glMultiTexCoord4dARB(GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q);
+GLAPI void GLAPIENTRY glMultiTexCoord4dvARB(GLenum target, const GLdouble *v);
+GLAPI void GLAPIENTRY glMultiTexCoord4fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
+GLAPI void GLAPIENTRY glMultiTexCoord4fvARB(GLenum target, const GLfloat *v);
+GLAPI void GLAPIENTRY glMultiTexCoord4iARB(GLenum target, GLint s, GLint t, GLint r, GLint q);
+GLAPI void GLAPIENTRY glMultiTexCoord4ivARB(GLenum target, const GLint *v);
+GLAPI void GLAPIENTRY glMultiTexCoord4sARB(GLenum target, GLshort s, GLshort t, GLshort r, GLshort q);
+GLAPI void GLAPIENTRY glMultiTexCoord4svARB(GLenum target, const GLshort *v);
+
+typedef void (APIENTRYP PFNGLACTIVETEXTUREARBPROC) (GLenum texture);
+typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1DARBPROC) (GLenum target, GLdouble s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVARBPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1FARBPROC) (GLenum target, GLfloat s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVARBPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1IARBPROC) (GLenum target, GLint s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVARBPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1SARBPROC) (GLenum target, GLshort s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVARBPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2DARBPROC) (GLenum target, GLdouble s, GLdouble t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVARBPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2IARBPROC) (GLenum target, GLint s, GLint t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVARBPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2SARBPROC) (GLenum target, GLshort s, GLshort t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVARBPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVARBPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3IARBPROC) (GLenum target, GLint s, GLint t, GLint r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVARBPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVARBPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVARBPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4IARBPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVARBPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLshort *v);
+
+#endif /* GL_ARB_multitexture */
+
+
+
+/*
+ * Define this token if you want "old-style" header file behaviour (extensions
+ * defined in gl.h). Otherwise, extensions will be included from glext.h.
+ */
+#if !defined(NO_SDL_GLEXT) && !defined(GL_GLEXT_LEGACY)
+#include "SDL_opengl_glext.h"
+#endif /* GL_GLEXT_LEGACY */
+
+
+
+/*
+ * ???. GL_MESA_packed_depth_stencil
+ * XXX obsolete
+ */
+#ifndef GL_MESA_packed_depth_stencil
+#define GL_MESA_packed_depth_stencil 1
+
+#define GL_DEPTH_STENCIL_MESA 0x8750
+#define GL_UNSIGNED_INT_24_8_MESA 0x8751
+#define GL_UNSIGNED_INT_8_24_REV_MESA 0x8752
+#define GL_UNSIGNED_SHORT_15_1_MESA 0x8753
+#define GL_UNSIGNED_SHORT_1_15_REV_MESA 0x8754
+
+#endif /* GL_MESA_packed_depth_stencil */
+
+
+#ifndef GL_ATI_blend_equation_separate
+#define GL_ATI_blend_equation_separate 1
+
+#define GL_ALPHA_BLEND_EQUATION_ATI 0x883D
+
+GLAPI void GLAPIENTRY glBlendEquationSeparateATI( GLenum modeRGB, GLenum modeA );
+typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEATIPROC) (GLenum modeRGB, GLenum modeA);
+
+#endif /* GL_ATI_blend_equation_separate */
+
+
+/* GL_OES_EGL_image */
+#ifndef GL_OES_EGL_image
+typedef void* GLeglImageOES;
+#endif
+
+#ifndef GL_OES_EGL_image
+#define GL_OES_EGL_image 1
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image);
+GLAPI void APIENTRY glEGLImageTargetRenderbufferStorageOES (GLenum target, GLeglImageOES image);
+#endif
+typedef void (APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image);
+typedef void (APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image);
+#endif
+
+
+/**
+ ** NOTE!!!!! If you add new functions to this file, or update
+ ** glext.h be sure to regenerate the gl_mangle.h file. See comments
+ ** in that file for details.
+ **/
+
+
+
+/**********************************************************************
+ * Begin system-specific stuff
+ */
+#if defined(PRAGMA_EXPORT_SUPPORTED)
+#pragma export off
+#endif
+
+/*
+ * End system-specific stuff
+ **********************************************************************/
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __gl_h_ */
+
+#endif /* !__IPHONEOS__ */
+
+#endif /* SDL_opengl_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_opengl_glext.h b/src/3rdparty/SDL2/include/SDL2/SDL_opengl_glext.h
new file mode 100644
index 0000000..cd3869f
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_opengl_glext.h
@@ -0,0 +1,11177 @@
+#ifndef __glext_h_
+#define __glext_h_ 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+** Copyright (c) 2013-2014 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+/*
+** This header is generated from the Khronos OpenGL / OpenGL ES XML
+** API Registry. The current version of the Registry, generator scripts
+** used to make the header, and the header can be found at
+** http://www.opengl.org/registry/
+**
+** Khronos $Revision: 26745 $ on $Date: 2014-05-21 03:12:26 -0700 (Wed, 21 May 2014) $
+*/
+
+#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN 1
+#endif
+#include <windows.h>
+#endif
+
+#ifndef APIENTRY
+#define APIENTRY
+#endif
+#ifndef APIENTRYP
+#define APIENTRYP APIENTRY *
+#endif
+#ifndef GLAPI
+#define GLAPI extern
+#endif
+
+#define GL_GLEXT_VERSION 20140521
+
+/* Generated C header for:
+ * API: gl
+ * Profile: compatibility
+ * Versions considered: .*
+ * Versions emitted: 1\.[2-9]|[234]\.[0-9]
+ * Default extensions included: gl
+ * Additional extensions included: _nomatch_^
+ * Extensions removed: _nomatch_^
+ */
+
+#ifndef GL_VERSION_1_2
+#define GL_VERSION_1_2 1
+#define GL_UNSIGNED_BYTE_3_3_2 0x8032
+#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
+#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
+#define GL_UNSIGNED_INT_8_8_8_8 0x8035
+#define GL_UNSIGNED_INT_10_10_10_2 0x8036
+#define GL_TEXTURE_BINDING_3D 0x806A
+#define GL_PACK_SKIP_IMAGES 0x806B
+#define GL_PACK_IMAGE_HEIGHT 0x806C
+#define GL_UNPACK_SKIP_IMAGES 0x806D
+#define GL_UNPACK_IMAGE_HEIGHT 0x806E
+#define GL_TEXTURE_3D 0x806F
+#define GL_PROXY_TEXTURE_3D 0x8070
+#define GL_TEXTURE_DEPTH 0x8071
+#define GL_TEXTURE_WRAP_R 0x8072
+#define GL_MAX_3D_TEXTURE_SIZE 0x8073
+#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362
+#define GL_UNSIGNED_SHORT_5_6_5 0x8363
+#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
+#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
+#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
+#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
+#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
+#define GL_BGR 0x80E0
+#define GL_BGRA 0x80E1
+#define GL_MAX_ELEMENTS_VERTICES 0x80E8
+#define GL_MAX_ELEMENTS_INDICES 0x80E9
+#define GL_CLAMP_TO_EDGE 0x812F
+#define GL_TEXTURE_MIN_LOD 0x813A
+#define GL_TEXTURE_MAX_LOD 0x813B
+#define GL_TEXTURE_BASE_LEVEL 0x813C
+#define GL_TEXTURE_MAX_LEVEL 0x813D
+#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12
+#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13
+#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22
+#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23
+#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E
+#define GL_RESCALE_NORMAL 0x803A
+#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8
+#define GL_SINGLE_COLOR 0x81F9
+#define GL_SEPARATE_SPECULAR_COLOR 0x81FA
+#define GL_ALIASED_POINT_SIZE_RANGE 0x846D
+typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices);
+typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawRangeElements (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices);
+GLAPI void APIENTRY glTexImage3D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glCopyTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+#endif
+#endif /* GL_VERSION_1_2 */
+
+#ifndef GL_VERSION_1_3
+#define GL_VERSION_1_3 1
+#define GL_TEXTURE0 0x84C0
+#define GL_TEXTURE1 0x84C1
+#define GL_TEXTURE2 0x84C2
+#define GL_TEXTURE3 0x84C3
+#define GL_TEXTURE4 0x84C4
+#define GL_TEXTURE5 0x84C5
+#define GL_TEXTURE6 0x84C6
+#define GL_TEXTURE7 0x84C7
+#define GL_TEXTURE8 0x84C8
+#define GL_TEXTURE9 0x84C9
+#define GL_TEXTURE10 0x84CA
+#define GL_TEXTURE11 0x84CB
+#define GL_TEXTURE12 0x84CC
+#define GL_TEXTURE13 0x84CD
+#define GL_TEXTURE14 0x84CE
+#define GL_TEXTURE15 0x84CF
+#define GL_TEXTURE16 0x84D0
+#define GL_TEXTURE17 0x84D1
+#define GL_TEXTURE18 0x84D2
+#define GL_TEXTURE19 0x84D3
+#define GL_TEXTURE20 0x84D4
+#define GL_TEXTURE21 0x84D5
+#define GL_TEXTURE22 0x84D6
+#define GL_TEXTURE23 0x84D7
+#define GL_TEXTURE24 0x84D8
+#define GL_TEXTURE25 0x84D9
+#define GL_TEXTURE26 0x84DA
+#define GL_TEXTURE27 0x84DB
+#define GL_TEXTURE28 0x84DC
+#define GL_TEXTURE29 0x84DD
+#define GL_TEXTURE30 0x84DE
+#define GL_TEXTURE31 0x84DF
+#define GL_ACTIVE_TEXTURE 0x84E0
+#define GL_MULTISAMPLE 0x809D
+#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E
+#define GL_SAMPLE_ALPHA_TO_ONE 0x809F
+#define GL_SAMPLE_COVERAGE 0x80A0
+#define GL_SAMPLE_BUFFERS 0x80A8
+#define GL_SAMPLES 0x80A9
+#define GL_SAMPLE_COVERAGE_VALUE 0x80AA
+#define GL_SAMPLE_COVERAGE_INVERT 0x80AB
+#define GL_TEXTURE_CUBE_MAP 0x8513
+#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
+#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B
+#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C
+#define GL_COMPRESSED_RGB 0x84ED
+#define GL_COMPRESSED_RGBA 0x84EE
+#define GL_TEXTURE_COMPRESSION_HINT 0x84EF
+#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0
+#define GL_TEXTURE_COMPRESSED 0x86A1
+#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2
+#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3
+#define GL_CLAMP_TO_BORDER 0x812D
+#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1
+#define GL_MAX_TEXTURE_UNITS 0x84E2
+#define GL_TRANSPOSE_MODELVIEW_MATRIX 0x84E3
+#define GL_TRANSPOSE_PROJECTION_MATRIX 0x84E4
+#define GL_TRANSPOSE_TEXTURE_MATRIX 0x84E5
+#define GL_TRANSPOSE_COLOR_MATRIX 0x84E6
+#define GL_MULTISAMPLE_BIT 0x20000000
+#define GL_NORMAL_MAP 0x8511
+#define GL_REFLECTION_MAP 0x8512
+#define GL_COMPRESSED_ALPHA 0x84E9
+#define GL_COMPRESSED_LUMINANCE 0x84EA
+#define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB
+#define GL_COMPRESSED_INTENSITY 0x84EC
+#define GL_COMBINE 0x8570
+#define GL_COMBINE_RGB 0x8571
+#define GL_COMBINE_ALPHA 0x8572
+#define GL_SOURCE0_RGB 0x8580
+#define GL_SOURCE1_RGB 0x8581
+#define GL_SOURCE2_RGB 0x8582
+#define GL_SOURCE0_ALPHA 0x8588
+#define GL_SOURCE1_ALPHA 0x8589
+#define GL_SOURCE2_ALPHA 0x858A
+#define GL_OPERAND0_RGB 0x8590
+#define GL_OPERAND1_RGB 0x8591
+#define GL_OPERAND2_RGB 0x8592
+#define GL_OPERAND0_ALPHA 0x8598
+#define GL_OPERAND1_ALPHA 0x8599
+#define GL_OPERAND2_ALPHA 0x859A
+#define GL_RGB_SCALE 0x8573
+#define GL_ADD_SIGNED 0x8574
+#define GL_INTERPOLATE 0x8575
+#define GL_SUBTRACT 0x84E7
+#define GL_CONSTANT 0x8576
+#define GL_PRIMARY_COLOR 0x8577
+#define GL_PREVIOUS 0x8578
+#define GL_DOT3_RGB 0x86AE
+#define GL_DOT3_RGBA 0x86AF
+typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
+typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLfloat value, GLboolean invert);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, void *img);
+typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1DPROC) (GLenum target, GLdouble s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1FPROC) (GLenum target, GLfloat s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1IPROC) (GLenum target, GLint s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1SPROC) (GLenum target, GLshort s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2DPROC) (GLenum target, GLdouble s, GLdouble t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2FPROC) (GLenum target, GLfloat s, GLfloat t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2IPROC) (GLenum target, GLint s, GLint t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2SPROC) (GLenum target, GLshort s, GLshort t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3IPROC) (GLenum target, GLint s, GLint t, GLint r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3SPROC) (GLenum target, GLshort s, GLshort t, GLshort r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4IPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4SPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFPROC) (const GLfloat *m);
+typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDPROC) (const GLdouble *m);
+typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFPROC) (const GLfloat *m);
+typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDPROC) (const GLdouble *m);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glActiveTexture (GLenum texture);
+GLAPI void APIENTRY glSampleCoverage (GLfloat value, GLboolean invert);
+GLAPI void APIENTRY glCompressedTexImage3D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexImage1D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glGetCompressedTexImage (GLenum target, GLint level, void *img);
+GLAPI void APIENTRY glClientActiveTexture (GLenum texture);
+GLAPI void APIENTRY glMultiTexCoord1d (GLenum target, GLdouble s);
+GLAPI void APIENTRY glMultiTexCoord1dv (GLenum target, const GLdouble *v);
+GLAPI void APIENTRY glMultiTexCoord1f (GLenum target, GLfloat s);
+GLAPI void APIENTRY glMultiTexCoord1fv (GLenum target, const GLfloat *v);
+GLAPI void APIENTRY glMultiTexCoord1i (GLenum target, GLint s);
+GLAPI void APIENTRY glMultiTexCoord1iv (GLenum target, const GLint *v);
+GLAPI void APIENTRY glMultiTexCoord1s (GLenum target, GLshort s);
+GLAPI void APIENTRY glMultiTexCoord1sv (GLenum target, const GLshort *v);
+GLAPI void APIENTRY glMultiTexCoord2d (GLenum target, GLdouble s, GLdouble t);
+GLAPI void APIENTRY glMultiTexCoord2dv (GLenum target, const GLdouble *v);
+GLAPI void APIENTRY glMultiTexCoord2f (GLenum target, GLfloat s, GLfloat t);
+GLAPI void APIENTRY glMultiTexCoord2fv (GLenum target, const GLfloat *v);
+GLAPI void APIENTRY glMultiTexCoord2i (GLenum target, GLint s, GLint t);
+GLAPI void APIENTRY glMultiTexCoord2iv (GLenum target, const GLint *v);
+GLAPI void APIENTRY glMultiTexCoord2s (GLenum target, GLshort s, GLshort t);
+GLAPI void APIENTRY glMultiTexCoord2sv (GLenum target, const GLshort *v);
+GLAPI void APIENTRY glMultiTexCoord3d (GLenum target, GLdouble s, GLdouble t, GLdouble r);
+GLAPI void APIENTRY glMultiTexCoord3dv (GLenum target, const GLdouble *v);
+GLAPI void APIENTRY glMultiTexCoord3f (GLenum target, GLfloat s, GLfloat t, GLfloat r);
+GLAPI void APIENTRY glMultiTexCoord3fv (GLenum target, const GLfloat *v);
+GLAPI void APIENTRY glMultiTexCoord3i (GLenum target, GLint s, GLint t, GLint r);
+GLAPI void APIENTRY glMultiTexCoord3iv (GLenum target, const GLint *v);
+GLAPI void APIENTRY glMultiTexCoord3s (GLenum target, GLshort s, GLshort t, GLshort r);
+GLAPI void APIENTRY glMultiTexCoord3sv (GLenum target, const GLshort *v);
+GLAPI void APIENTRY glMultiTexCoord4d (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q);
+GLAPI void APIENTRY glMultiTexCoord4dv (GLenum target, const GLdouble *v);
+GLAPI void APIENTRY glMultiTexCoord4f (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
+GLAPI void APIENTRY glMultiTexCoord4fv (GLenum target, const GLfloat *v);
+GLAPI void APIENTRY glMultiTexCoord4i (GLenum target, GLint s, GLint t, GLint r, GLint q);
+GLAPI void APIENTRY glMultiTexCoord4iv (GLenum target, const GLint *v);
+GLAPI void APIENTRY glMultiTexCoord4s (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q);
+GLAPI void APIENTRY glMultiTexCoord4sv (GLenum target, const GLshort *v);
+GLAPI void APIENTRY glLoadTransposeMatrixf (const GLfloat *m);
+GLAPI void APIENTRY glLoadTransposeMatrixd (const GLdouble *m);
+GLAPI void APIENTRY glMultTransposeMatrixf (const GLfloat *m);
+GLAPI void APIENTRY glMultTransposeMatrixd (const GLdouble *m);
+#endif
+#endif /* GL_VERSION_1_3 */
+
+#ifndef GL_VERSION_1_4
+#define GL_VERSION_1_4 1
+#define GL_BLEND_DST_RGB 0x80C8
+#define GL_BLEND_SRC_RGB 0x80C9
+#define GL_BLEND_DST_ALPHA 0x80CA
+#define GL_BLEND_SRC_ALPHA 0x80CB
+#define GL_POINT_FADE_THRESHOLD_SIZE 0x8128
+#define GL_DEPTH_COMPONENT16 0x81A5
+#define GL_DEPTH_COMPONENT24 0x81A6
+#define GL_DEPTH_COMPONENT32 0x81A7
+#define GL_MIRRORED_REPEAT 0x8370
+#define GL_MAX_TEXTURE_LOD_BIAS 0x84FD
+#define GL_TEXTURE_LOD_BIAS 0x8501
+#define GL_INCR_WRAP 0x8507
+#define GL_DECR_WRAP 0x8508
+#define GL_TEXTURE_DEPTH_SIZE 0x884A
+#define GL_TEXTURE_COMPARE_MODE 0x884C
+#define GL_TEXTURE_COMPARE_FUNC 0x884D
+#define GL_POINT_SIZE_MIN 0x8126
+#define GL_POINT_SIZE_MAX 0x8127
+#define GL_POINT_DISTANCE_ATTENUATION 0x8129
+#define GL_GENERATE_MIPMAP 0x8191
+#define GL_GENERATE_MIPMAP_HINT 0x8192
+#define GL_FOG_COORDINATE_SOURCE 0x8450
+#define GL_FOG_COORDINATE 0x8451
+#define GL_FRAGMENT_DEPTH 0x8452
+#define GL_CURRENT_FOG_COORDINATE 0x8453
+#define GL_FOG_COORDINATE_ARRAY_TYPE 0x8454
+#define GL_FOG_COORDINATE_ARRAY_STRIDE 0x8455
+#define GL_FOG_COORDINATE_ARRAY_POINTER 0x8456
+#define GL_FOG_COORDINATE_ARRAY 0x8457
+#define GL_COLOR_SUM 0x8458
+#define GL_CURRENT_SECONDARY_COLOR 0x8459
+#define GL_SECONDARY_COLOR_ARRAY_SIZE 0x845A
+#define GL_SECONDARY_COLOR_ARRAY_TYPE 0x845B
+#define GL_SECONDARY_COLOR_ARRAY_STRIDE 0x845C
+#define GL_SECONDARY_COLOR_ARRAY_POINTER 0x845D
+#define GL_SECONDARY_COLOR_ARRAY 0x845E
+#define GL_TEXTURE_FILTER_CONTROL 0x8500
+#define GL_DEPTH_TEXTURE_MODE 0x884B
+#define GL_COMPARE_R_TO_TEXTURE 0x884E
+#define GL_FUNC_ADD 0x8006
+#define GL_FUNC_SUBTRACT 0x800A
+#define GL_FUNC_REVERSE_SUBTRACT 0x800B
+#define GL_MIN 0x8007
+#define GL_MAX 0x8008
+#define GL_CONSTANT_COLOR 0x8001
+#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002
+#define GL_CONSTANT_ALPHA 0x8003
+#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004
+typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
+typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount);
+typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei drawcount);
+typedef void (APIENTRYP PFNGLPOINTPARAMETERFPROC) (GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLPOINTPARAMETERFVPROC) (GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLPOINTPARAMETERIPROC) (GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLPOINTPARAMETERIVPROC) (GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLFOGCOORDFPROC) (GLfloat coord);
+typedef void (APIENTRYP PFNGLFOGCOORDFVPROC) (const GLfloat *coord);
+typedef void (APIENTRYP PFNGLFOGCOORDDPROC) (GLdouble coord);
+typedef void (APIENTRYP PFNGLFOGCOORDDVPROC) (const GLdouble *coord);
+typedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC) (GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BPROC) (GLbyte red, GLbyte green, GLbyte blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVPROC) (const GLbyte *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DPROC) (GLdouble red, GLdouble green, GLdouble blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FPROC) (GLfloat red, GLfloat green, GLfloat blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IPROC) (GLint red, GLint green, GLint blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SPROC) (GLshort red, GLshort green, GLshort blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVPROC) (const GLshort *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBPROC) (GLubyte red, GLubyte green, GLubyte blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVPROC) (const GLubyte *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIPROC) (GLuint red, GLuint green, GLuint blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVPROC) (const GLuint *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USPROC) (GLushort red, GLushort green, GLushort blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVPROC) (const GLushort *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERPROC) (GLint size, GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLWINDOWPOS2DPROC) (GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2DVPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS2FPROC) (GLfloat x, GLfloat y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2FVPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS2IPROC) (GLint x, GLint y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2IVPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS2SPROC) (GLshort x, GLshort y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2SVPROC) (const GLshort *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3DPROC) (GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3DVPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3FPROC) (GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3FVPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3IPROC) (GLint x, GLint y, GLint z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3IVPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3SPROC) (GLshort x, GLshort y, GLshort z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3SVPROC) (const GLshort *v);
+typedef void (APIENTRYP PFNGLBLENDCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
+typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
+GLAPI void APIENTRY glMultiDrawArrays (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount);
+GLAPI void APIENTRY glMultiDrawElements (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei drawcount);
+GLAPI void APIENTRY glPointParameterf (GLenum pname, GLfloat param);
+GLAPI void APIENTRY glPointParameterfv (GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glPointParameteri (GLenum pname, GLint param);
+GLAPI void APIENTRY glPointParameteriv (GLenum pname, const GLint *params);
+GLAPI void APIENTRY glFogCoordf (GLfloat coord);
+GLAPI void APIENTRY glFogCoordfv (const GLfloat *coord);
+GLAPI void APIENTRY glFogCoordd (GLdouble coord);
+GLAPI void APIENTRY glFogCoorddv (const GLdouble *coord);
+GLAPI void APIENTRY glFogCoordPointer (GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glSecondaryColor3b (GLbyte red, GLbyte green, GLbyte blue);
+GLAPI void APIENTRY glSecondaryColor3bv (const GLbyte *v);
+GLAPI void APIENTRY glSecondaryColor3d (GLdouble red, GLdouble green, GLdouble blue);
+GLAPI void APIENTRY glSecondaryColor3dv (const GLdouble *v);
+GLAPI void APIENTRY glSecondaryColor3f (GLfloat red, GLfloat green, GLfloat blue);
+GLAPI void APIENTRY glSecondaryColor3fv (const GLfloat *v);
+GLAPI void APIENTRY glSecondaryColor3i (GLint red, GLint green, GLint blue);
+GLAPI void APIENTRY glSecondaryColor3iv (const GLint *v);
+GLAPI void APIENTRY glSecondaryColor3s (GLshort red, GLshort green, GLshort blue);
+GLAPI void APIENTRY glSecondaryColor3sv (const GLshort *v);
+GLAPI void APIENTRY glSecondaryColor3ub (GLubyte red, GLubyte green, GLubyte blue);
+GLAPI void APIENTRY glSecondaryColor3ubv (const GLubyte *v);
+GLAPI void APIENTRY glSecondaryColor3ui (GLuint red, GLuint green, GLuint blue);
+GLAPI void APIENTRY glSecondaryColor3uiv (const GLuint *v);
+GLAPI void APIENTRY glSecondaryColor3us (GLushort red, GLushort green, GLushort blue);
+GLAPI void APIENTRY glSecondaryColor3usv (const GLushort *v);
+GLAPI void APIENTRY glSecondaryColorPointer (GLint size, GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glWindowPos2d (GLdouble x, GLdouble y);
+GLAPI void APIENTRY glWindowPos2dv (const GLdouble *v);
+GLAPI void APIENTRY glWindowPos2f (GLfloat x, GLfloat y);
+GLAPI void APIENTRY glWindowPos2fv (const GLfloat *v);
+GLAPI void APIENTRY glWindowPos2i (GLint x, GLint y);
+GLAPI void APIENTRY glWindowPos2iv (const GLint *v);
+GLAPI void APIENTRY glWindowPos2s (GLshort x, GLshort y);
+GLAPI void APIENTRY glWindowPos2sv (const GLshort *v);
+GLAPI void APIENTRY glWindowPos3d (GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glWindowPos3dv (const GLdouble *v);
+GLAPI void APIENTRY glWindowPos3f (GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glWindowPos3fv (const GLfloat *v);
+GLAPI void APIENTRY glWindowPos3i (GLint x, GLint y, GLint z);
+GLAPI void APIENTRY glWindowPos3iv (const GLint *v);
+GLAPI void APIENTRY glWindowPos3s (GLshort x, GLshort y, GLshort z);
+GLAPI void APIENTRY glWindowPos3sv (const GLshort *v);
+GLAPI void APIENTRY glBlendColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
+GLAPI void APIENTRY glBlendEquation (GLenum mode);
+#endif
+#endif /* GL_VERSION_1_4 */
+
+#ifndef GL_VERSION_1_5
+#define GL_VERSION_1_5 1
+#include <stddef.h>
+#ifdef __MACOSX__
+typedef long GLsizeiptr;
+typedef long GLintptr;
+#else
+typedef ptrdiff_t GLsizeiptr;
+typedef ptrdiff_t GLintptr;
+#endif
+#define GL_BUFFER_SIZE 0x8764
+#define GL_BUFFER_USAGE 0x8765
+#define GL_QUERY_COUNTER_BITS 0x8864
+#define GL_CURRENT_QUERY 0x8865
+#define GL_QUERY_RESULT 0x8866
+#define GL_QUERY_RESULT_AVAILABLE 0x8867
+#define GL_ARRAY_BUFFER 0x8892
+#define GL_ELEMENT_ARRAY_BUFFER 0x8893
+#define GL_ARRAY_BUFFER_BINDING 0x8894
+#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895
+#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F
+#define GL_READ_ONLY 0x88B8
+#define GL_WRITE_ONLY 0x88B9
+#define GL_READ_WRITE 0x88BA
+#define GL_BUFFER_ACCESS 0x88BB
+#define GL_BUFFER_MAPPED 0x88BC
+#define GL_BUFFER_MAP_POINTER 0x88BD
+#define GL_STREAM_DRAW 0x88E0
+#define GL_STREAM_READ 0x88E1
+#define GL_STREAM_COPY 0x88E2
+#define GL_STATIC_DRAW 0x88E4
+#define GL_STATIC_READ 0x88E5
+#define GL_STATIC_COPY 0x88E6
+#define GL_DYNAMIC_DRAW 0x88E8
+#define GL_DYNAMIC_READ 0x88E9
+#define GL_DYNAMIC_COPY 0x88EA
+#define GL_SAMPLES_PASSED 0x8914
+#define GL_SRC1_ALPHA 0x8589
+#define GL_VERTEX_ARRAY_BUFFER_BINDING 0x8896
+#define GL_NORMAL_ARRAY_BUFFER_BINDING 0x8897
+#define GL_COLOR_ARRAY_BUFFER_BINDING 0x8898
+#define GL_INDEX_ARRAY_BUFFER_BINDING 0x8899
+#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING 0x889A
+#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING 0x889B
+#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING 0x889C
+#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING 0x889D
+#define GL_WEIGHT_ARRAY_BUFFER_BINDING 0x889E
+#define GL_FOG_COORD_SRC 0x8450
+#define GL_FOG_COORD 0x8451
+#define GL_CURRENT_FOG_COORD 0x8453
+#define GL_FOG_COORD_ARRAY_TYPE 0x8454
+#define GL_FOG_COORD_ARRAY_STRIDE 0x8455
+#define GL_FOG_COORD_ARRAY_POINTER 0x8456
+#define GL_FOG_COORD_ARRAY 0x8457
+#define GL_FOG_COORD_ARRAY_BUFFER_BINDING 0x889D
+#define GL_SRC0_RGB 0x8580
+#define GL_SRC1_RGB 0x8581
+#define GL_SRC2_RGB 0x8582
+#define GL_SRC0_ALPHA 0x8588
+#define GL_SRC2_ALPHA 0x858A
+typedef void (APIENTRYP PFNGLGENQUERIESPROC) (GLsizei n, GLuint *ids);
+typedef void (APIENTRYP PFNGLDELETEQUERIESPROC) (GLsizei n, const GLuint *ids);
+typedef GLboolean (APIENTRYP PFNGLISQUERYPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLBEGINQUERYPROC) (GLenum target, GLuint id);
+typedef void (APIENTRYP PFNGLENDQUERYPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLGETQUERYIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVPROC) (GLuint id, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVPROC) (GLuint id, GLenum pname, GLuint *params);
+typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer);
+typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
+typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
+typedef GLboolean (APIENTRYP PFNGLISBUFFERPROC) (GLuint buffer);
+typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
+typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
+typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, void *data);
+typedef void *(APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, GLenum access);
+typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVPROC) (GLenum target, GLenum pname, void **params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGenQueries (GLsizei n, GLuint *ids);
+GLAPI void APIENTRY glDeleteQueries (GLsizei n, const GLuint *ids);
+GLAPI GLboolean APIENTRY glIsQuery (GLuint id);
+GLAPI void APIENTRY glBeginQuery (GLenum target, GLuint id);
+GLAPI void APIENTRY glEndQuery (GLenum target);
+GLAPI void APIENTRY glGetQueryiv (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetQueryObjectiv (GLuint id, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetQueryObjectuiv (GLuint id, GLenum pname, GLuint *params);
+GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer);
+GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers);
+GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers);
+GLAPI GLboolean APIENTRY glIsBuffer (GLuint buffer);
+GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
+GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
+GLAPI void APIENTRY glGetBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, void *data);
+GLAPI void *APIENTRY glMapBuffer (GLenum target, GLenum access);
+GLAPI GLboolean APIENTRY glUnmapBuffer (GLenum target);
+GLAPI void APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetBufferPointerv (GLenum target, GLenum pname, void **params);
+#endif
+#endif /* GL_VERSION_1_5 */
+
+#ifndef GL_VERSION_2_0
+#define GL_VERSION_2_0 1
+typedef char GLchar;
+#define GL_BLEND_EQUATION_RGB 0x8009
+#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
+#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
+#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624
+#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625
+#define GL_CURRENT_VERTEX_ATTRIB 0x8626
+#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642
+#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645
+#define GL_STENCIL_BACK_FUNC 0x8800
+#define GL_STENCIL_BACK_FAIL 0x8801
+#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802
+#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803
+#define GL_MAX_DRAW_BUFFERS 0x8824
+#define GL_DRAW_BUFFER0 0x8825
+#define GL_DRAW_BUFFER1 0x8826
+#define GL_DRAW_BUFFER2 0x8827
+#define GL_DRAW_BUFFER3 0x8828
+#define GL_DRAW_BUFFER4 0x8829
+#define GL_DRAW_BUFFER5 0x882A
+#define GL_DRAW_BUFFER6 0x882B
+#define GL_DRAW_BUFFER7 0x882C
+#define GL_DRAW_BUFFER8 0x882D
+#define GL_DRAW_BUFFER9 0x882E
+#define GL_DRAW_BUFFER10 0x882F
+#define GL_DRAW_BUFFER11 0x8830
+#define GL_DRAW_BUFFER12 0x8831
+#define GL_DRAW_BUFFER13 0x8832
+#define GL_DRAW_BUFFER14 0x8833
+#define GL_DRAW_BUFFER15 0x8834
+#define GL_BLEND_EQUATION_ALPHA 0x883D
+#define GL_MAX_VERTEX_ATTRIBS 0x8869
+#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A
+#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872
+#define GL_FRAGMENT_SHADER 0x8B30
+#define GL_VERTEX_SHADER 0x8B31
+#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49
+#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A
+#define GL_MAX_VARYING_FLOATS 0x8B4B
+#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C
+#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D
+#define GL_SHADER_TYPE 0x8B4F
+#define GL_FLOAT_VEC2 0x8B50
+#define GL_FLOAT_VEC3 0x8B51
+#define GL_FLOAT_VEC4 0x8B52
+#define GL_INT_VEC2 0x8B53
+#define GL_INT_VEC3 0x8B54
+#define GL_INT_VEC4 0x8B55
+#define GL_BOOL 0x8B56
+#define GL_BOOL_VEC2 0x8B57
+#define GL_BOOL_VEC3 0x8B58
+#define GL_BOOL_VEC4 0x8B59
+#define GL_FLOAT_MAT2 0x8B5A
+#define GL_FLOAT_MAT3 0x8B5B
+#define GL_FLOAT_MAT4 0x8B5C
+#define GL_SAMPLER_1D 0x8B5D
+#define GL_SAMPLER_2D 0x8B5E
+#define GL_SAMPLER_3D 0x8B5F
+#define GL_SAMPLER_CUBE 0x8B60
+#define GL_SAMPLER_1D_SHADOW 0x8B61
+#define GL_SAMPLER_2D_SHADOW 0x8B62
+#define GL_DELETE_STATUS 0x8B80
+#define GL_COMPILE_STATUS 0x8B81
+#define GL_LINK_STATUS 0x8B82
+#define GL_VALIDATE_STATUS 0x8B83
+#define GL_INFO_LOG_LENGTH 0x8B84
+#define GL_ATTACHED_SHADERS 0x8B85
+#define GL_ACTIVE_UNIFORMS 0x8B86
+#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87
+#define GL_SHADER_SOURCE_LENGTH 0x8B88
+#define GL_ACTIVE_ATTRIBUTES 0x8B89
+#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A
+#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B
+#define GL_SHADING_LANGUAGE_VERSION 0x8B8C
+#define GL_CURRENT_PROGRAM 0x8B8D
+#define GL_POINT_SPRITE_COORD_ORIGIN 0x8CA0
+#define GL_LOWER_LEFT 0x8CA1
+#define GL_UPPER_LEFT 0x8CA2
+#define GL_STENCIL_BACK_REF 0x8CA3
+#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4
+#define GL_STENCIL_BACK_WRITEMASK 0x8CA5
+#define GL_VERTEX_PROGRAM_TWO_SIDE 0x8643
+#define GL_POINT_SPRITE 0x8861
+#define GL_COORD_REPLACE 0x8862
+#define GL_MAX_TEXTURE_COORDS 0x8871
+typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha);
+typedef void (APIENTRYP PFNGLDRAWBUFFERSPROC) (GLsizei n, const GLenum *bufs);
+typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
+typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEPROC) (GLenum face, GLenum func, GLint ref, GLuint mask);
+typedef void (APIENTRYP PFNGLSTENCILMASKSEPARATEPROC) (GLenum face, GLuint mask);
+typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
+typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar *name);
+typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader);
+typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void);
+typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type);
+typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program);
+typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader);
+typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader);
+typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index);
+typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index);
+typedef void (APIENTRYP PFNGLGETACTIVEATTRIBPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
+typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
+typedef void (APIENTRYP PFNGLGETATTACHEDSHADERSPROC) (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders);
+typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name);
+typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+typedef void (APIENTRYP PFNGLGETSHADERSOURCEPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source);
+typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name);
+typedef void (APIENTRYP PFNGLGETUNIFORMFVPROC) (GLuint program, GLint location, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETUNIFORMIVPROC) (GLuint program, GLint location, GLint *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVPROC) (GLuint index, GLenum pname, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVPROC) (GLuint index, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, void **pointer);
+typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program);
+typedef GLboolean (APIENTRYP PFNGLISSHADERPROC) (GLuint shader);
+typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program);
+typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
+typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program);
+typedef void (APIENTRYP PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0);
+typedef void (APIENTRYP PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, GLfloat v1);
+typedef void (APIENTRYP PFNGLUNIFORM3FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+typedef void (APIENTRYP PFNGLUNIFORM4FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0);
+typedef void (APIENTRYP PFNGLUNIFORM2IPROC) (GLint location, GLint v0, GLint v1);
+typedef void (APIENTRYP PFNGLUNIFORM3IPROC) (GLint location, GLint v0, GLint v1, GLint v2);
+typedef void (APIENTRYP PFNGLUNIFORM4IPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+typedef void (APIENTRYP PFNGLUNIFORM1FVPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORM2FVPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORM3FVPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORM4FVPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORM1IVPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLUNIFORM2IVPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLUNIFORM3IVPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLUNIFORM4IVPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPROC) (GLuint program);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1DPROC) (GLuint index, GLdouble x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1FPROC) (GLuint index, GLfloat x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1SPROC) (GLuint index, GLshort x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2DPROC) (GLuint index, GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2FPROC) (GLuint index, GLfloat x, GLfloat y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2SPROC) (GLuint index, GLshort x, GLshort y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3SPROC) (GLuint index, GLshort x, GLshort y, GLshort z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVPROC) (GLuint index, const GLbyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVPROC) (GLuint index, const GLubyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVPROC) (GLuint index, const GLushort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVPROC) (GLuint index, const GLbyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4SPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVPROC) (GLuint index, const GLubyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVPROC) (GLuint index, const GLushort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha);
+GLAPI void APIENTRY glDrawBuffers (GLsizei n, const GLenum *bufs);
+GLAPI void APIENTRY glStencilOpSeparate (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
+GLAPI void APIENTRY glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask);
+GLAPI void APIENTRY glStencilMaskSeparate (GLenum face, GLuint mask);
+GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader);
+GLAPI void APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar *name);
+GLAPI void APIENTRY glCompileShader (GLuint shader);
+GLAPI GLuint APIENTRY glCreateProgram (void);
+GLAPI GLuint APIENTRY glCreateShader (GLenum type);
+GLAPI void APIENTRY glDeleteProgram (GLuint program);
+GLAPI void APIENTRY glDeleteShader (GLuint shader);
+GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader);
+GLAPI void APIENTRY glDisableVertexAttribArray (GLuint index);
+GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index);
+GLAPI void APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
+GLAPI void APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
+GLAPI void APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders);
+GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name);
+GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+GLAPI void APIENTRY glGetShaderSource (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source);
+GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name);
+GLAPI void APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat *params);
+GLAPI void APIENTRY glGetUniformiv (GLuint program, GLint location, GLint *params);
+GLAPI void APIENTRY glGetVertexAttribdv (GLuint index, GLenum pname, GLdouble *params);
+GLAPI void APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, void **pointer);
+GLAPI GLboolean APIENTRY glIsProgram (GLuint program);
+GLAPI GLboolean APIENTRY glIsShader (GLuint shader);
+GLAPI void APIENTRY glLinkProgram (GLuint program);
+GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
+GLAPI void APIENTRY glUseProgram (GLuint program);
+GLAPI void APIENTRY glUniform1f (GLint location, GLfloat v0);
+GLAPI void APIENTRY glUniform2f (GLint location, GLfloat v0, GLfloat v1);
+GLAPI void APIENTRY glUniform3f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+GLAPI void APIENTRY glUniform4f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+GLAPI void APIENTRY glUniform1i (GLint location, GLint v0);
+GLAPI void APIENTRY glUniform2i (GLint location, GLint v0, GLint v1);
+GLAPI void APIENTRY glUniform3i (GLint location, GLint v0, GLint v1, GLint v2);
+GLAPI void APIENTRY glUniform4i (GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+GLAPI void APIENTRY glUniform1fv (GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glUniform2fv (GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glUniform1iv (GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glValidateProgram (GLuint program);
+GLAPI void APIENTRY glVertexAttrib1d (GLuint index, GLdouble x);
+GLAPI void APIENTRY glVertexAttrib1dv (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib1f (GLuint index, GLfloat x);
+GLAPI void APIENTRY glVertexAttrib1fv (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib1s (GLuint index, GLshort x);
+GLAPI void APIENTRY glVertexAttrib1sv (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib2d (GLuint index, GLdouble x, GLdouble y);
+GLAPI void APIENTRY glVertexAttrib2dv (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib2f (GLuint index, GLfloat x, GLfloat y);
+GLAPI void APIENTRY glVertexAttrib2fv (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib2s (GLuint index, GLshort x, GLshort y);
+GLAPI void APIENTRY glVertexAttrib2sv (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib3d (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glVertexAttrib3dv (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib3f (GLuint index, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glVertexAttrib3fv (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib3s (GLuint index, GLshort x, GLshort y, GLshort z);
+GLAPI void APIENTRY glVertexAttrib3sv (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib4Nbv (GLuint index, const GLbyte *v);
+GLAPI void APIENTRY glVertexAttrib4Niv (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttrib4Nsv (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib4Nub (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w);
+GLAPI void APIENTRY glVertexAttrib4Nubv (GLuint index, const GLubyte *v);
+GLAPI void APIENTRY glVertexAttrib4Nuiv (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttrib4Nusv (GLuint index, const GLushort *v);
+GLAPI void APIENTRY glVertexAttrib4bv (GLuint index, const GLbyte *v);
+GLAPI void APIENTRY glVertexAttrib4d (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glVertexAttrib4dv (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib4f (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glVertexAttrib4fv (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib4iv (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttrib4s (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w);
+GLAPI void APIENTRY glVertexAttrib4sv (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib4ubv (GLuint index, const GLubyte *v);
+GLAPI void APIENTRY glVertexAttrib4uiv (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttrib4usv (GLuint index, const GLushort *v);
+GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
+#endif
+#endif /* GL_VERSION_2_0 */
+
+#ifndef GL_VERSION_2_1
+#define GL_VERSION_2_1 1
+#define GL_PIXEL_PACK_BUFFER 0x88EB
+#define GL_PIXEL_UNPACK_BUFFER 0x88EC
+#define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED
+#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF
+#define GL_FLOAT_MAT2x3 0x8B65
+#define GL_FLOAT_MAT2x4 0x8B66
+#define GL_FLOAT_MAT3x2 0x8B67
+#define GL_FLOAT_MAT3x4 0x8B68
+#define GL_FLOAT_MAT4x2 0x8B69
+#define GL_FLOAT_MAT4x3 0x8B6A
+#define GL_SRGB 0x8C40
+#define GL_SRGB8 0x8C41
+#define GL_SRGB_ALPHA 0x8C42
+#define GL_SRGB8_ALPHA8 0x8C43
+#define GL_COMPRESSED_SRGB 0x8C48
+#define GL_COMPRESSED_SRGB_ALPHA 0x8C49
+#define GL_CURRENT_RASTER_SECONDARY_COLOR 0x845F
+#define GL_SLUMINANCE_ALPHA 0x8C44
+#define GL_SLUMINANCE8_ALPHA8 0x8C45
+#define GL_SLUMINANCE 0x8C46
+#define GL_SLUMINANCE8 0x8C47
+#define GL_COMPRESSED_SLUMINANCE 0x8C4A
+#define GL_COMPRESSED_SLUMINANCE_ALPHA 0x8C4B
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glUniformMatrix2x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glUniformMatrix3x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glUniformMatrix2x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glUniformMatrix4x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glUniformMatrix3x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glUniformMatrix4x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+#endif
+#endif /* GL_VERSION_2_1 */
+
+#ifndef GL_VERSION_3_0
+#define GL_VERSION_3_0 1
+typedef unsigned short GLhalf;
+#define GL_COMPARE_REF_TO_TEXTURE 0x884E
+#define GL_CLIP_DISTANCE0 0x3000
+#define GL_CLIP_DISTANCE1 0x3001
+#define GL_CLIP_DISTANCE2 0x3002
+#define GL_CLIP_DISTANCE3 0x3003
+#define GL_CLIP_DISTANCE4 0x3004
+#define GL_CLIP_DISTANCE5 0x3005
+#define GL_CLIP_DISTANCE6 0x3006
+#define GL_CLIP_DISTANCE7 0x3007
+#define GL_MAX_CLIP_DISTANCES 0x0D32
+#define GL_MAJOR_VERSION 0x821B
+#define GL_MINOR_VERSION 0x821C
+#define GL_NUM_EXTENSIONS 0x821D
+#define GL_CONTEXT_FLAGS 0x821E
+#define GL_COMPRESSED_RED 0x8225
+#define GL_COMPRESSED_RG 0x8226
+#define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x00000001
+#define GL_RGBA32F 0x8814
+#define GL_RGB32F 0x8815
+#define GL_RGBA16F 0x881A
+#define GL_RGB16F 0x881B
+#define GL_VERTEX_ATTRIB_ARRAY_INTEGER 0x88FD
+#define GL_MAX_ARRAY_TEXTURE_LAYERS 0x88FF
+#define GL_MIN_PROGRAM_TEXEL_OFFSET 0x8904
+#define GL_MAX_PROGRAM_TEXEL_OFFSET 0x8905
+#define GL_CLAMP_READ_COLOR 0x891C
+#define GL_FIXED_ONLY 0x891D
+#define GL_MAX_VARYING_COMPONENTS 0x8B4B
+#define GL_TEXTURE_1D_ARRAY 0x8C18
+#define GL_PROXY_TEXTURE_1D_ARRAY 0x8C19
+#define GL_TEXTURE_2D_ARRAY 0x8C1A
+#define GL_PROXY_TEXTURE_2D_ARRAY 0x8C1B
+#define GL_TEXTURE_BINDING_1D_ARRAY 0x8C1C
+#define GL_TEXTURE_BINDING_2D_ARRAY 0x8C1D
+#define GL_R11F_G11F_B10F 0x8C3A
+#define GL_UNSIGNED_INT_10F_11F_11F_REV 0x8C3B
+#define GL_RGB9_E5 0x8C3D
+#define GL_UNSIGNED_INT_5_9_9_9_REV 0x8C3E
+#define GL_TEXTURE_SHARED_SIZE 0x8C3F
+#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH 0x8C76
+#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE 0x8C7F
+#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS 0x8C80
+#define GL_TRANSFORM_FEEDBACK_VARYINGS 0x8C83
+#define GL_TRANSFORM_FEEDBACK_BUFFER_START 0x8C84
+#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE 0x8C85
+#define GL_PRIMITIVES_GENERATED 0x8C87
+#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN 0x8C88
+#define GL_RASTERIZER_DISCARD 0x8C89
+#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS 0x8C8A
+#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS 0x8C8B
+#define GL_INTERLEAVED_ATTRIBS 0x8C8C
+#define GL_SEPARATE_ATTRIBS 0x8C8D
+#define GL_TRANSFORM_FEEDBACK_BUFFER 0x8C8E
+#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING 0x8C8F
+#define GL_RGBA32UI 0x8D70
+#define GL_RGB32UI 0x8D71
+#define GL_RGBA16UI 0x8D76
+#define GL_RGB16UI 0x8D77
+#define GL_RGBA8UI 0x8D7C
+#define GL_RGB8UI 0x8D7D
+#define GL_RGBA32I 0x8D82
+#define GL_RGB32I 0x8D83
+#define GL_RGBA16I 0x8D88
+#define GL_RGB16I 0x8D89
+#define GL_RGBA8I 0x8D8E
+#define GL_RGB8I 0x8D8F
+#define GL_RED_INTEGER 0x8D94
+#define GL_GREEN_INTEGER 0x8D95
+#define GL_BLUE_INTEGER 0x8D96
+#define GL_RGB_INTEGER 0x8D98
+#define GL_RGBA_INTEGER 0x8D99
+#define GL_BGR_INTEGER 0x8D9A
+#define GL_BGRA_INTEGER 0x8D9B
+#define GL_SAMPLER_1D_ARRAY 0x8DC0
+#define GL_SAMPLER_2D_ARRAY 0x8DC1
+#define GL_SAMPLER_1D_ARRAY_SHADOW 0x8DC3
+#define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4
+#define GL_SAMPLER_CUBE_SHADOW 0x8DC5
+#define GL_UNSIGNED_INT_VEC2 0x8DC6
+#define GL_UNSIGNED_INT_VEC3 0x8DC7
+#define GL_UNSIGNED_INT_VEC4 0x8DC8
+#define GL_INT_SAMPLER_1D 0x8DC9
+#define GL_INT_SAMPLER_2D 0x8DCA
+#define GL_INT_SAMPLER_3D 0x8DCB
+#define GL_INT_SAMPLER_CUBE 0x8DCC
+#define GL_INT_SAMPLER_1D_ARRAY 0x8DCE
+#define GL_INT_SAMPLER_2D_ARRAY 0x8DCF
+#define GL_UNSIGNED_INT_SAMPLER_1D 0x8DD1
+#define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2
+#define GL_UNSIGNED_INT_SAMPLER_3D 0x8DD3
+#define GL_UNSIGNED_INT_SAMPLER_CUBE 0x8DD4
+#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY 0x8DD6
+#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7
+#define GL_QUERY_WAIT 0x8E13
+#define GL_QUERY_NO_WAIT 0x8E14
+#define GL_QUERY_BY_REGION_WAIT 0x8E15
+#define GL_QUERY_BY_REGION_NO_WAIT 0x8E16
+#define GL_BUFFER_ACCESS_FLAGS 0x911F
+#define GL_BUFFER_MAP_LENGTH 0x9120
+#define GL_BUFFER_MAP_OFFSET 0x9121
+#define GL_DEPTH_COMPONENT32F 0x8CAC
+#define GL_DEPTH32F_STENCIL8 0x8CAD
+#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD
+#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506
+#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING 0x8210
+#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE 0x8211
+#define GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE 0x8212
+#define GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE 0x8213
+#define GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE 0x8214
+#define GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE 0x8215
+#define GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE 0x8216
+#define GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE 0x8217
+#define GL_FRAMEBUFFER_DEFAULT 0x8218
+#define GL_FRAMEBUFFER_UNDEFINED 0x8219
+#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A
+#define GL_MAX_RENDERBUFFER_SIZE 0x84E8
+#define GL_DEPTH_STENCIL 0x84F9
+#define GL_UNSIGNED_INT_24_8 0x84FA
+#define GL_DEPTH24_STENCIL8 0x88F0
+#define GL_TEXTURE_STENCIL_SIZE 0x88F1
+#define GL_TEXTURE_RED_TYPE 0x8C10
+#define GL_TEXTURE_GREEN_TYPE 0x8C11
+#define GL_TEXTURE_BLUE_TYPE 0x8C12
+#define GL_TEXTURE_ALPHA_TYPE 0x8C13
+#define GL_TEXTURE_DEPTH_TYPE 0x8C16
+#define GL_UNSIGNED_NORMALIZED 0x8C17
+#define GL_FRAMEBUFFER_BINDING 0x8CA6
+#define GL_DRAW_FRAMEBUFFER_BINDING 0x8CA6
+#define GL_RENDERBUFFER_BINDING 0x8CA7
+#define GL_READ_FRAMEBUFFER 0x8CA8
+#define GL_DRAW_FRAMEBUFFER 0x8CA9
+#define GL_READ_FRAMEBUFFER_BINDING 0x8CAA
+#define GL_RENDERBUFFER_SAMPLES 0x8CAB
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER 0x8CD4
+#define GL_FRAMEBUFFER_COMPLETE 0x8CD5
+#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6
+#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7
+#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB
+#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC
+#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD
+#define GL_MAX_COLOR_ATTACHMENTS 0x8CDF
+#define GL_COLOR_ATTACHMENT0 0x8CE0
+#define GL_COLOR_ATTACHMENT1 0x8CE1
+#define GL_COLOR_ATTACHMENT2 0x8CE2
+#define GL_COLOR_ATTACHMENT3 0x8CE3
+#define GL_COLOR_ATTACHMENT4 0x8CE4
+#define GL_COLOR_ATTACHMENT5 0x8CE5
+#define GL_COLOR_ATTACHMENT6 0x8CE6
+#define GL_COLOR_ATTACHMENT7 0x8CE7
+#define GL_COLOR_ATTACHMENT8 0x8CE8
+#define GL_COLOR_ATTACHMENT9 0x8CE9
+#define GL_COLOR_ATTACHMENT10 0x8CEA
+#define GL_COLOR_ATTACHMENT11 0x8CEB
+#define GL_COLOR_ATTACHMENT12 0x8CEC
+#define GL_COLOR_ATTACHMENT13 0x8CED
+#define GL_COLOR_ATTACHMENT14 0x8CEE
+#define GL_COLOR_ATTACHMENT15 0x8CEF
+#define GL_DEPTH_ATTACHMENT 0x8D00
+#define GL_STENCIL_ATTACHMENT 0x8D20
+#define GL_FRAMEBUFFER 0x8D40
+#define GL_RENDERBUFFER 0x8D41
+#define GL_RENDERBUFFER_WIDTH 0x8D42
+#define GL_RENDERBUFFER_HEIGHT 0x8D43
+#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44
+#define GL_STENCIL_INDEX1 0x8D46
+#define GL_STENCIL_INDEX4 0x8D47
+#define GL_STENCIL_INDEX8 0x8D48
+#define GL_STENCIL_INDEX16 0x8D49
+#define GL_RENDERBUFFER_RED_SIZE 0x8D50
+#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51
+#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52
+#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53
+#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54
+#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56
+#define GL_MAX_SAMPLES 0x8D57
+#define GL_INDEX 0x8222
+#define GL_TEXTURE_LUMINANCE_TYPE 0x8C14
+#define GL_TEXTURE_INTENSITY_TYPE 0x8C15
+#define GL_FRAMEBUFFER_SRGB 0x8DB9
+#define GL_HALF_FLOAT 0x140B
+#define GL_MAP_READ_BIT 0x0001
+#define GL_MAP_WRITE_BIT 0x0002
+#define GL_MAP_INVALIDATE_RANGE_BIT 0x0004
+#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008
+#define GL_MAP_FLUSH_EXPLICIT_BIT 0x0010
+#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020
+#define GL_COMPRESSED_RED_RGTC1 0x8DBB
+#define GL_COMPRESSED_SIGNED_RED_RGTC1 0x8DBC
+#define GL_COMPRESSED_RG_RGTC2 0x8DBD
+#define GL_COMPRESSED_SIGNED_RG_RGTC2 0x8DBE
+#define GL_RG 0x8227
+#define GL_RG_INTEGER 0x8228
+#define GL_R8 0x8229
+#define GL_R16 0x822A
+#define GL_RG8 0x822B
+#define GL_RG16 0x822C
+#define GL_R16F 0x822D
+#define GL_R32F 0x822E
+#define GL_RG16F 0x822F
+#define GL_RG32F 0x8230
+#define GL_R8I 0x8231
+#define GL_R8UI 0x8232
+#define GL_R16I 0x8233
+#define GL_R16UI 0x8234
+#define GL_R32I 0x8235
+#define GL_R32UI 0x8236
+#define GL_RG8I 0x8237
+#define GL_RG8UI 0x8238
+#define GL_RG16I 0x8239
+#define GL_RG16UI 0x823A
+#define GL_RG32I 0x823B
+#define GL_RG32UI 0x823C
+#define GL_VERTEX_ARRAY_BINDING 0x85B5
+#define GL_CLAMP_VERTEX_COLOR 0x891A
+#define GL_CLAMP_FRAGMENT_COLOR 0x891B
+#define GL_ALPHA_INTEGER 0x8D97
+typedef void (APIENTRYP PFNGLCOLORMASKIPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a);
+typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data);
+typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data);
+typedef void (APIENTRYP PFNGLENABLEIPROC) (GLenum target, GLuint index);
+typedef void (APIENTRYP PFNGLDISABLEIPROC) (GLenum target, GLuint index);
+typedef GLboolean (APIENTRYP PFNGLISENABLEDIPROC) (GLenum target, GLuint index);
+typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKPROC) (GLenum primitiveMode);
+typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKPROC) (void);
+typedef void (APIENTRYP PFNGLBINDBUFFERRANGEPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size);
+typedef void (APIENTRYP PFNGLBINDBUFFERBASEPROC) (GLenum target, GLuint index, GLuint buffer);
+typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSPROC) (GLuint program, GLsizei count, const GLchar *const*varyings, GLenum bufferMode);
+typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name);
+typedef void (APIENTRYP PFNGLCLAMPCOLORPROC) (GLenum target, GLenum clamp);
+typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERPROC) (GLuint id, GLenum mode);
+typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERPROC) (void);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVPROC) (GLuint index, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVPROC) (GLuint index, GLenum pname, GLuint *params);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IPROC) (GLuint index, GLint x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IPROC) (GLuint index, GLint x, GLint y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IPROC) (GLuint index, GLint x, GLint y, GLint z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IPROC) (GLuint index, GLint x, GLint y, GLint z, GLint w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIPROC) (GLuint index, GLuint x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIPROC) (GLuint index, GLuint x, GLuint y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVPROC) (GLuint index, const GLbyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVPROC) (GLuint index, const GLubyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVPROC) (GLuint index, const GLushort *v);
+typedef void (APIENTRYP PFNGLGETUNIFORMUIVPROC) (GLuint program, GLint location, GLuint *params);
+typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONPROC) (GLuint program, GLuint color, const GLchar *name);
+typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONPROC) (GLuint program, const GLchar *name);
+typedef void (APIENTRYP PFNGLUNIFORM1UIPROC) (GLint location, GLuint v0);
+typedef void (APIENTRYP PFNGLUNIFORM2UIPROC) (GLint location, GLuint v0, GLuint v1);
+typedef void (APIENTRYP PFNGLUNIFORM3UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2);
+typedef void (APIENTRYP PFNGLUNIFORM4UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+typedef void (APIENTRYP PFNGLUNIFORM1UIVPROC) (GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLUNIFORM2UIVPROC) (GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLUNIFORM3UIVPROC) (GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLUNIFORM4UIVPROC) (GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, const GLuint *params);
+typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, GLuint *params);
+typedef void (APIENTRYP PFNGLCLEARBUFFERIVPROC) (GLenum buffer, GLint drawbuffer, const GLint *value);
+typedef void (APIENTRYP PFNGLCLEARBUFFERUIVPROC) (GLenum buffer, GLint drawbuffer, const GLuint *value);
+typedef void (APIENTRYP PFNGLCLEARBUFFERFVPROC) (GLenum buffer, GLint drawbuffer, const GLfloat *value);
+typedef void (APIENTRYP PFNGLCLEARBUFFERFIPROC) (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil);
+typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index);
+typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFERPROC) (GLuint renderbuffer);
+typedef void (APIENTRYP PFNGLBINDRENDERBUFFERPROC) (GLenum target, GLuint renderbuffer);
+typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSPROC) (GLsizei n, const GLuint *renderbuffers);
+typedef void (APIENTRYP PFNGLGENRENDERBUFFERSPROC) (GLsizei n, GLuint *renderbuffers);
+typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFERPROC) (GLuint framebuffer);
+typedef void (APIENTRYP PFNGLBINDFRAMEBUFFERPROC) (GLenum target, GLuint framebuffer);
+typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSPROC) (GLsizei n, const GLuint *framebuffers);
+typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSPROC) (GLsizei n, GLuint *framebuffers);
+typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFERPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
+typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGENERATEMIPMAPPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLBLITFRAMEBUFFERPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer);
+typedef void *(APIENTRYP PFNGLMAPBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access);
+typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length);
+typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array);
+typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays);
+typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays);
+typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYPROC) (GLuint array);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glColorMaski (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a);
+GLAPI void APIENTRY glGetBooleani_v (GLenum target, GLuint index, GLboolean *data);
+GLAPI void APIENTRY glGetIntegeri_v (GLenum target, GLuint index, GLint *data);
+GLAPI void APIENTRY glEnablei (GLenum target, GLuint index);
+GLAPI void APIENTRY glDisablei (GLenum target, GLuint index);
+GLAPI GLboolean APIENTRY glIsEnabledi (GLenum target, GLuint index);
+GLAPI void APIENTRY glBeginTransformFeedback (GLenum primitiveMode);
+GLAPI void APIENTRY glEndTransformFeedback (void);
+GLAPI void APIENTRY glBindBufferRange (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size);
+GLAPI void APIENTRY glBindBufferBase (GLenum target, GLuint index, GLuint buffer);
+GLAPI void APIENTRY glTransformFeedbackVaryings (GLuint program, GLsizei count, const GLchar *const*varyings, GLenum bufferMode);
+GLAPI void APIENTRY glGetTransformFeedbackVarying (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name);
+GLAPI void APIENTRY glClampColor (GLenum target, GLenum clamp);
+GLAPI void APIENTRY glBeginConditionalRender (GLuint id, GLenum mode);
+GLAPI void APIENTRY glEndConditionalRender (void);
+GLAPI void APIENTRY glVertexAttribIPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glGetVertexAttribIiv (GLuint index, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetVertexAttribIuiv (GLuint index, GLenum pname, GLuint *params);
+GLAPI void APIENTRY glVertexAttribI1i (GLuint index, GLint x);
+GLAPI void APIENTRY glVertexAttribI2i (GLuint index, GLint x, GLint y);
+GLAPI void APIENTRY glVertexAttribI3i (GLuint index, GLint x, GLint y, GLint z);
+GLAPI void APIENTRY glVertexAttribI4i (GLuint index, GLint x, GLint y, GLint z, GLint w);
+GLAPI void APIENTRY glVertexAttribI1ui (GLuint index, GLuint x);
+GLAPI void APIENTRY glVertexAttribI2ui (GLuint index, GLuint x, GLuint y);
+GLAPI void APIENTRY glVertexAttribI3ui (GLuint index, GLuint x, GLuint y, GLuint z);
+GLAPI void APIENTRY glVertexAttribI4ui (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+GLAPI void APIENTRY glVertexAttribI1iv (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttribI2iv (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttribI3iv (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttribI4iv (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttribI1uiv (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttribI2uiv (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttribI3uiv (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttribI4uiv (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttribI4bv (GLuint index, const GLbyte *v);
+GLAPI void APIENTRY glVertexAttribI4sv (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttribI4ubv (GLuint index, const GLubyte *v);
+GLAPI void APIENTRY glVertexAttribI4usv (GLuint index, const GLushort *v);
+GLAPI void APIENTRY glGetUniformuiv (GLuint program, GLint location, GLuint *params);
+GLAPI void APIENTRY glBindFragDataLocation (GLuint program, GLuint color, const GLchar *name);
+GLAPI GLint APIENTRY glGetFragDataLocation (GLuint program, const GLchar *name);
+GLAPI void APIENTRY glUniform1ui (GLint location, GLuint v0);
+GLAPI void APIENTRY glUniform2ui (GLint location, GLuint v0, GLuint v1);
+GLAPI void APIENTRY glUniform3ui (GLint location, GLuint v0, GLuint v1, GLuint v2);
+GLAPI void APIENTRY glUniform4ui (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+GLAPI void APIENTRY glUniform1uiv (GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glUniform2uiv (GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glUniform3uiv (GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glUniform4uiv (GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glTexParameterIiv (GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glTexParameterIuiv (GLenum target, GLenum pname, const GLuint *params);
+GLAPI void APIENTRY glGetTexParameterIiv (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetTexParameterIuiv (GLenum target, GLenum pname, GLuint *params);
+GLAPI void APIENTRY glClearBufferiv (GLenum buffer, GLint drawbuffer, const GLint *value);
+GLAPI void APIENTRY glClearBufferuiv (GLenum buffer, GLint drawbuffer, const GLuint *value);
+GLAPI void APIENTRY glClearBufferfv (GLenum buffer, GLint drawbuffer, const GLfloat *value);
+GLAPI void APIENTRY glClearBufferfi (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil);
+GLAPI const GLubyte *APIENTRY glGetStringi (GLenum name, GLuint index);
+GLAPI GLboolean APIENTRY glIsRenderbuffer (GLuint renderbuffer);
+GLAPI void APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer);
+GLAPI void APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint *renderbuffers);
+GLAPI void APIENTRY glGenRenderbuffers (GLsizei n, GLuint *renderbuffers);
+GLAPI void APIENTRY glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint *params);
+GLAPI GLboolean APIENTRY glIsFramebuffer (GLuint framebuffer);
+GLAPI void APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer);
+GLAPI void APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint *framebuffers);
+GLAPI void APIENTRY glGenFramebuffers (GLsizei n, GLuint *framebuffers);
+GLAPI GLenum APIENTRY glCheckFramebufferStatus (GLenum target);
+GLAPI void APIENTRY glFramebufferTexture1D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+GLAPI void APIENTRY glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+GLAPI void APIENTRY glFramebufferTexture3D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+GLAPI void APIENTRY glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
+GLAPI void APIENTRY glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGenerateMipmap (GLenum target);
+GLAPI void APIENTRY glBlitFramebuffer (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+GLAPI void APIENTRY glRenderbufferStorageMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glFramebufferTextureLayer (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer);
+GLAPI void *APIENTRY glMapBufferRange (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access);
+GLAPI void APIENTRY glFlushMappedBufferRange (GLenum target, GLintptr offset, GLsizeiptr length);
+GLAPI void APIENTRY glBindVertexArray (GLuint array);
+GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays);
+GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays);
+GLAPI GLboolean APIENTRY glIsVertexArray (GLuint array);
+#endif
+#endif /* GL_VERSION_3_0 */
+
+#ifndef GL_VERSION_3_1
+#define GL_VERSION_3_1 1
+#define GL_SAMPLER_2D_RECT 0x8B63
+#define GL_SAMPLER_2D_RECT_SHADOW 0x8B64
+#define GL_SAMPLER_BUFFER 0x8DC2
+#define GL_INT_SAMPLER_2D_RECT 0x8DCD
+#define GL_INT_SAMPLER_BUFFER 0x8DD0
+#define GL_UNSIGNED_INT_SAMPLER_2D_RECT 0x8DD5
+#define GL_UNSIGNED_INT_SAMPLER_BUFFER 0x8DD8
+#define GL_TEXTURE_BUFFER 0x8C2A
+#define GL_MAX_TEXTURE_BUFFER_SIZE 0x8C2B
+#define GL_TEXTURE_BINDING_BUFFER 0x8C2C
+#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING 0x8C2D
+#define GL_TEXTURE_RECTANGLE 0x84F5
+#define GL_TEXTURE_BINDING_RECTANGLE 0x84F6
+#define GL_PROXY_TEXTURE_RECTANGLE 0x84F7
+#define GL_MAX_RECTANGLE_TEXTURE_SIZE 0x84F8
+#define GL_R8_SNORM 0x8F94
+#define GL_RG8_SNORM 0x8F95
+#define GL_RGB8_SNORM 0x8F96
+#define GL_RGBA8_SNORM 0x8F97
+#define GL_R16_SNORM 0x8F98
+#define GL_RG16_SNORM 0x8F99
+#define GL_RGB16_SNORM 0x8F9A
+#define GL_RGBA16_SNORM 0x8F9B
+#define GL_SIGNED_NORMALIZED 0x8F9C
+#define GL_PRIMITIVE_RESTART 0x8F9D
+#define GL_PRIMITIVE_RESTART_INDEX 0x8F9E
+#define GL_COPY_READ_BUFFER 0x8F36
+#define GL_COPY_WRITE_BUFFER 0x8F37
+#define GL_UNIFORM_BUFFER 0x8A11
+#define GL_UNIFORM_BUFFER_BINDING 0x8A28
+#define GL_UNIFORM_BUFFER_START 0x8A29
+#define GL_UNIFORM_BUFFER_SIZE 0x8A2A
+#define GL_MAX_VERTEX_UNIFORM_BLOCKS 0x8A2B
+#define GL_MAX_FRAGMENT_UNIFORM_BLOCKS 0x8A2D
+#define GL_MAX_COMBINED_UNIFORM_BLOCKS 0x8A2E
+#define GL_MAX_UNIFORM_BUFFER_BINDINGS 0x8A2F
+#define GL_MAX_UNIFORM_BLOCK_SIZE 0x8A30
+#define GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS 0x8A31
+#define GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS 0x8A33
+#define GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT 0x8A34
+#define GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH 0x8A35
+#define GL_ACTIVE_UNIFORM_BLOCKS 0x8A36
+#define GL_UNIFORM_TYPE 0x8A37
+#define GL_UNIFORM_SIZE 0x8A38
+#define GL_UNIFORM_NAME_LENGTH 0x8A39
+#define GL_UNIFORM_BLOCK_INDEX 0x8A3A
+#define GL_UNIFORM_OFFSET 0x8A3B
+#define GL_UNIFORM_ARRAY_STRIDE 0x8A3C
+#define GL_UNIFORM_MATRIX_STRIDE 0x8A3D
+#define GL_UNIFORM_IS_ROW_MAJOR 0x8A3E
+#define GL_UNIFORM_BLOCK_BINDING 0x8A3F
+#define GL_UNIFORM_BLOCK_DATA_SIZE 0x8A40
+#define GL_UNIFORM_BLOCK_NAME_LENGTH 0x8A41
+#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS 0x8A42
+#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES 0x8A43
+#define GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER 0x8A44
+#define GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER 0x8A46
+#define GL_INVALID_INDEX 0xFFFFFFFFu
+typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount);
+typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount);
+typedef void (APIENTRYP PFNGLTEXBUFFERPROC) (GLenum target, GLenum internalformat, GLuint buffer);
+typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXPROC) (GLuint index);
+typedef void (APIENTRYP PFNGLCOPYBUFFERSUBDATAPROC) (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
+typedef void (APIENTRYP PFNGLGETUNIFORMINDICESPROC) (GLuint program, GLsizei uniformCount, const GLchar *const*uniformNames, GLuint *uniformIndices);
+typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMSIVPROC) (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMNAMEPROC) (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName);
+typedef GLuint (APIENTRYP PFNGLGETUNIFORMBLOCKINDEXPROC) (GLuint program, const GLchar *uniformBlockName);
+typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKIVPROC) (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC) (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName);
+typedef void (APIENTRYP PFNGLUNIFORMBLOCKBINDINGPROC) (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawArraysInstanced (GLenum mode, GLint first, GLsizei count, GLsizei instancecount);
+GLAPI void APIENTRY glDrawElementsInstanced (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount);
+GLAPI void APIENTRY glTexBuffer (GLenum target, GLenum internalformat, GLuint buffer);
+GLAPI void APIENTRY glPrimitiveRestartIndex (GLuint index);
+GLAPI void APIENTRY glCopyBufferSubData (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
+GLAPI void APIENTRY glGetUniformIndices (GLuint program, GLsizei uniformCount, const GLchar *const*uniformNames, GLuint *uniformIndices);
+GLAPI void APIENTRY glGetActiveUniformsiv (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetActiveUniformName (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName);
+GLAPI GLuint APIENTRY glGetUniformBlockIndex (GLuint program, const GLchar *uniformBlockName);
+GLAPI void APIENTRY glGetActiveUniformBlockiv (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetActiveUniformBlockName (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName);
+GLAPI void APIENTRY glUniformBlockBinding (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding);
+#endif
+#endif /* GL_VERSION_3_1 */
+
+#ifndef GL_VERSION_3_2
+#define GL_VERSION_3_2 1
+typedef struct __GLsync *GLsync;
+#ifndef GLEXT_64_TYPES_DEFINED
+/* This code block is duplicated in glxext.h, so must be protected */
+#define GLEXT_64_TYPES_DEFINED
+/* Define int32_t, int64_t, and uint64_t types for UST/MSC */
+/* (as used in the GL_EXT_timer_query extension). */
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+#include <inttypes.h>
+#elif defined(__sun__) || defined(__digital__)
+#include <inttypes.h>
+#if defined(__STDC__)
+#if defined(__arch64__) || defined(_LP64)
+typedef long int int64_t;
+typedef unsigned long int uint64_t;
+#else
+typedef long long int int64_t;
+typedef unsigned long long int uint64_t;
+#endif /* __arch64__ */
+#endif /* __STDC__ */
+#elif defined( __VMS ) || defined(__sgi)
+#include <inttypes.h>
+#elif defined(__SCO__) || defined(__USLC__)
+#include <stdint.h>
+#elif defined(__UNIXOS2__) || defined(__SOL64__)
+typedef long int int32_t;
+typedef long long int int64_t;
+typedef unsigned long long int uint64_t;
+#elif defined(_WIN32) && defined(__GNUC__)
+#include <stdint.h>
+#elif defined(_WIN32)
+typedef __int32 int32_t;
+typedef __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+#else
+/* Fallback if nothing above works */
+#include <inttypes.h>
+#endif
+#endif
+typedef uint64_t GLuint64;
+typedef int64_t GLint64;
+#define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001
+#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
+#define GL_LINES_ADJACENCY 0x000A
+#define GL_LINE_STRIP_ADJACENCY 0x000B
+#define GL_TRIANGLES_ADJACENCY 0x000C
+#define GL_TRIANGLE_STRIP_ADJACENCY 0x000D
+#define GL_PROGRAM_POINT_SIZE 0x8642
+#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS 0x8C29
+#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED 0x8DA7
+#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS 0x8DA8
+#define GL_GEOMETRY_SHADER 0x8DD9
+#define GL_GEOMETRY_VERTICES_OUT 0x8916
+#define GL_GEOMETRY_INPUT_TYPE 0x8917
+#define GL_GEOMETRY_OUTPUT_TYPE 0x8918
+#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS 0x8DDF
+#define GL_MAX_GEOMETRY_OUTPUT_VERTICES 0x8DE0
+#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS 0x8DE1
+#define GL_MAX_VERTEX_OUTPUT_COMPONENTS 0x9122
+#define GL_MAX_GEOMETRY_INPUT_COMPONENTS 0x9123
+#define GL_MAX_GEOMETRY_OUTPUT_COMPONENTS 0x9124
+#define GL_MAX_FRAGMENT_INPUT_COMPONENTS 0x9125
+#define GL_CONTEXT_PROFILE_MASK 0x9126
+#define GL_DEPTH_CLAMP 0x864F
+#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION 0x8E4C
+#define GL_FIRST_VERTEX_CONVENTION 0x8E4D
+#define GL_LAST_VERTEX_CONVENTION 0x8E4E
+#define GL_PROVOKING_VERTEX 0x8E4F
+#define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F
+#define GL_MAX_SERVER_WAIT_TIMEOUT 0x9111
+#define GL_OBJECT_TYPE 0x9112
+#define GL_SYNC_CONDITION 0x9113
+#define GL_SYNC_STATUS 0x9114
+#define GL_SYNC_FLAGS 0x9115
+#define GL_SYNC_FENCE 0x9116
+#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117
+#define GL_UNSIGNALED 0x9118
+#define GL_SIGNALED 0x9119
+#define GL_ALREADY_SIGNALED 0x911A
+#define GL_TIMEOUT_EXPIRED 0x911B
+#define GL_CONDITION_SATISFIED 0x911C
+#define GL_WAIT_FAILED 0x911D
+#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull
+#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001
+#define GL_SAMPLE_POSITION 0x8E50
+#define GL_SAMPLE_MASK 0x8E51
+#define GL_SAMPLE_MASK_VALUE 0x8E52
+#define GL_MAX_SAMPLE_MASK_WORDS 0x8E59
+#define GL_TEXTURE_2D_MULTISAMPLE 0x9100
+#define GL_PROXY_TEXTURE_2D_MULTISAMPLE 0x9101
+#define GL_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9102
+#define GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9103
+#define GL_TEXTURE_BINDING_2D_MULTISAMPLE 0x9104
+#define GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY 0x9105
+#define GL_TEXTURE_SAMPLES 0x9106
+#define GL_TEXTURE_FIXED_SAMPLE_LOCATIONS 0x9107
+#define GL_SAMPLER_2D_MULTISAMPLE 0x9108
+#define GL_INT_SAMPLER_2D_MULTISAMPLE 0x9109
+#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE 0x910A
+#define GL_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910B
+#define GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910C
+#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910D
+#define GL_MAX_COLOR_TEXTURE_SAMPLES 0x910E
+#define GL_MAX_DEPTH_TEXTURE_SAMPLES 0x910F
+#define GL_MAX_INTEGER_SAMPLES 0x9110
+typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
+typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLint basevertex);
+typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex);
+typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei drawcount, const GLint *basevertex);
+typedef void (APIENTRYP PFNGLPROVOKINGVERTEXPROC) (GLenum mode);
+typedef GLsync (APIENTRYP PFNGLFENCESYNCPROC) (GLenum condition, GLbitfield flags);
+typedef GLboolean (APIENTRYP PFNGLISSYNCPROC) (GLsync sync);
+typedef void (APIENTRYP PFNGLDELETESYNCPROC) (GLsync sync);
+typedef GLenum (APIENTRYP PFNGLCLIENTWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout);
+typedef void (APIENTRYP PFNGLWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout);
+typedef void (APIENTRYP PFNGLGETINTEGER64VPROC) (GLenum pname, GLint64 *data);
+typedef void (APIENTRYP PFNGLGETSYNCIVPROC) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values);
+typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data);
+typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERI64VPROC) (GLenum target, GLenum pname, GLint64 *params);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLTEXIMAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
+typedef void (APIENTRYP PFNGLTEXIMAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations);
+typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVPROC) (GLenum pname, GLuint index, GLfloat *val);
+typedef void (APIENTRYP PFNGLSAMPLEMASKIPROC) (GLuint maskNumber, GLbitfield mask);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
+GLAPI void APIENTRY glDrawRangeElementsBaseVertex (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLint basevertex);
+GLAPI void APIENTRY glDrawElementsInstancedBaseVertex (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex);
+GLAPI void APIENTRY glMultiDrawElementsBaseVertex (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei drawcount, const GLint *basevertex);
+GLAPI void APIENTRY glProvokingVertex (GLenum mode);
+GLAPI GLsync APIENTRY glFenceSync (GLenum condition, GLbitfield flags);
+GLAPI GLboolean APIENTRY glIsSync (GLsync sync);
+GLAPI void APIENTRY glDeleteSync (GLsync sync);
+GLAPI GLenum APIENTRY glClientWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout);
+GLAPI void APIENTRY glWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout);
+GLAPI void APIENTRY glGetInteger64v (GLenum pname, GLint64 *data);
+GLAPI void APIENTRY glGetSynciv (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values);
+GLAPI void APIENTRY glGetInteger64i_v (GLenum target, GLuint index, GLint64 *data);
+GLAPI void APIENTRY glGetBufferParameteri64v (GLenum target, GLenum pname, GLint64 *params);
+GLAPI void APIENTRY glFramebufferTexture (GLenum target, GLenum attachment, GLuint texture, GLint level);
+GLAPI void APIENTRY glTexImage2DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
+GLAPI void APIENTRY glTexImage3DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations);
+GLAPI void APIENTRY glGetMultisamplefv (GLenum pname, GLuint index, GLfloat *val);
+GLAPI void APIENTRY glSampleMaski (GLuint maskNumber, GLbitfield mask);
+#endif
+#endif /* GL_VERSION_3_2 */
+
+#ifndef GL_VERSION_3_3
+#define GL_VERSION_3_3 1
+#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR 0x88FE
+#define GL_SRC1_COLOR 0x88F9
+#define GL_ONE_MINUS_SRC1_COLOR 0x88FA
+#define GL_ONE_MINUS_SRC1_ALPHA 0x88FB
+#define GL_MAX_DUAL_SOURCE_DRAW_BUFFERS 0x88FC
+#define GL_ANY_SAMPLES_PASSED 0x8C2F
+#define GL_SAMPLER_BINDING 0x8919
+#define GL_RGB10_A2UI 0x906F
+#define GL_TEXTURE_SWIZZLE_R 0x8E42
+#define GL_TEXTURE_SWIZZLE_G 0x8E43
+#define GL_TEXTURE_SWIZZLE_B 0x8E44
+#define GL_TEXTURE_SWIZZLE_A 0x8E45
+#define GL_TEXTURE_SWIZZLE_RGBA 0x8E46
+#define GL_TIME_ELAPSED 0x88BF
+#define GL_TIMESTAMP 0x8E28
+#define GL_INT_2_10_10_10_REV 0x8D9F
+typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONINDEXEDPROC) (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name);
+typedef GLint (APIENTRYP PFNGLGETFRAGDATAINDEXPROC) (GLuint program, const GLchar *name);
+typedef void (APIENTRYP PFNGLGENSAMPLERSPROC) (GLsizei count, GLuint *samplers);
+typedef void (APIENTRYP PFNGLDELETESAMPLERSPROC) (GLsizei count, const GLuint *samplers);
+typedef GLboolean (APIENTRYP PFNGLISSAMPLERPROC) (GLuint sampler);
+typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler);
+typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIPROC) (GLuint sampler, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pname, const GLint *param);
+typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFPROC) (GLuint sampler, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, const GLfloat *param);
+typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIIVPROC) (GLuint sampler, GLenum pname, const GLint *param);
+typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenum pname, const GLuint *param);
+typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIIVPROC) (GLuint sampler, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenum pname, GLuint *params);
+typedef void (APIENTRYP PFNGLQUERYCOUNTERPROC) (GLuint id, GLenum target);
+typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VPROC) (GLuint id, GLenum pname, GLint64 *params);
+typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VPROC) (GLuint id, GLenum pname, GLuint64 *params);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORPROC) (GLuint index, GLuint divisor);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value);
+typedef void (APIENTRYP PFNGLVERTEXP2UIPROC) (GLenum type, GLuint value);
+typedef void (APIENTRYP PFNGLVERTEXP2UIVPROC) (GLenum type, const GLuint *value);
+typedef void (APIENTRYP PFNGLVERTEXP3UIPROC) (GLenum type, GLuint value);
+typedef void (APIENTRYP PFNGLVERTEXP3UIVPROC) (GLenum type, const GLuint *value);
+typedef void (APIENTRYP PFNGLVERTEXP4UIPROC) (GLenum type, GLuint value);
+typedef void (APIENTRYP PFNGLVERTEXP4UIVPROC) (GLenum type, const GLuint *value);
+typedef void (APIENTRYP PFNGLTEXCOORDP1UIPROC) (GLenum type, GLuint coords);
+typedef void (APIENTRYP PFNGLTEXCOORDP1UIVPROC) (GLenum type, const GLuint *coords);
+typedef void (APIENTRYP PFNGLTEXCOORDP2UIPROC) (GLenum type, GLuint coords);
+typedef void (APIENTRYP PFNGLTEXCOORDP2UIVPROC) (GLenum type, const GLuint *coords);
+typedef void (APIENTRYP PFNGLTEXCOORDP3UIPROC) (GLenum type, GLuint coords);
+typedef void (APIENTRYP PFNGLTEXCOORDP3UIVPROC) (GLenum type, const GLuint *coords);
+typedef void (APIENTRYP PFNGLTEXCOORDP4UIPROC) (GLenum type, GLuint coords);
+typedef void (APIENTRYP PFNGLTEXCOORDP4UIVPROC) (GLenum type, const GLuint *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIPROC) (GLenum texture, GLenum type, GLuint coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIVPROC) (GLenum texture, GLenum type, const GLuint *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIPROC) (GLenum texture, GLenum type, GLuint coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIVPROC) (GLenum texture, GLenum type, const GLuint *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIPROC) (GLenum texture, GLenum type, GLuint coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIVPROC) (GLenum texture, GLenum type, const GLuint *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIPROC) (GLenum texture, GLenum type, GLuint coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIVPROC) (GLenum texture, GLenum type, const GLuint *coords);
+typedef void (APIENTRYP PFNGLNORMALP3UIPROC) (GLenum type, GLuint coords);
+typedef void (APIENTRYP PFNGLNORMALP3UIVPROC) (GLenum type, const GLuint *coords);
+typedef void (APIENTRYP PFNGLCOLORP3UIPROC) (GLenum type, GLuint color);
+typedef void (APIENTRYP PFNGLCOLORP3UIVPROC) (GLenum type, const GLuint *color);
+typedef void (APIENTRYP PFNGLCOLORP4UIPROC) (GLenum type, GLuint color);
+typedef void (APIENTRYP PFNGLCOLORP4UIVPROC) (GLenum type, const GLuint *color);
+typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIPROC) (GLenum type, GLuint color);
+typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIVPROC) (GLenum type, const GLuint *color);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBindFragDataLocationIndexed (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name);
+GLAPI GLint APIENTRY glGetFragDataIndex (GLuint program, const GLchar *name);
+GLAPI void APIENTRY glGenSamplers (GLsizei count, GLuint *samplers);
+GLAPI void APIENTRY glDeleteSamplers (GLsizei count, const GLuint *samplers);
+GLAPI GLboolean APIENTRY glIsSampler (GLuint sampler);
+GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler);
+GLAPI void APIENTRY glSamplerParameteri (GLuint sampler, GLenum pname, GLint param);
+GLAPI void APIENTRY glSamplerParameteriv (GLuint sampler, GLenum pname, const GLint *param);
+GLAPI void APIENTRY glSamplerParameterf (GLuint sampler, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glSamplerParameterfv (GLuint sampler, GLenum pname, const GLfloat *param);
+GLAPI void APIENTRY glSamplerParameterIiv (GLuint sampler, GLenum pname, const GLint *param);
+GLAPI void APIENTRY glSamplerParameterIuiv (GLuint sampler, GLenum pname, const GLuint *param);
+GLAPI void APIENTRY glGetSamplerParameteriv (GLuint sampler, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetSamplerParameterIiv (GLuint sampler, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetSamplerParameterfv (GLuint sampler, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetSamplerParameterIuiv (GLuint sampler, GLenum pname, GLuint *params);
+GLAPI void APIENTRY glQueryCounter (GLuint id, GLenum target);
+GLAPI void APIENTRY glGetQueryObjecti64v (GLuint id, GLenum pname, GLint64 *params);
+GLAPI void APIENTRY glGetQueryObjectui64v (GLuint id, GLenum pname, GLuint64 *params);
+GLAPI void APIENTRY glVertexAttribDivisor (GLuint index, GLuint divisor);
+GLAPI void APIENTRY glVertexAttribP1ui (GLuint index, GLenum type, GLboolean normalized, GLuint value);
+GLAPI void APIENTRY glVertexAttribP1uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value);
+GLAPI void APIENTRY glVertexAttribP2ui (GLuint index, GLenum type, GLboolean normalized, GLuint value);
+GLAPI void APIENTRY glVertexAttribP2uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value);
+GLAPI void APIENTRY glVertexAttribP3ui (GLuint index, GLenum type, GLboolean normalized, GLuint value);
+GLAPI void APIENTRY glVertexAttribP3uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value);
+GLAPI void APIENTRY glVertexAttribP4ui (GLuint index, GLenum type, GLboolean normalized, GLuint value);
+GLAPI void APIENTRY glVertexAttribP4uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value);
+GLAPI void APIENTRY glVertexP2ui (GLenum type, GLuint value);
+GLAPI void APIENTRY glVertexP2uiv (GLenum type, const GLuint *value);
+GLAPI void APIENTRY glVertexP3ui (GLenum type, GLuint value);
+GLAPI void APIENTRY glVertexP3uiv (GLenum type, const GLuint *value);
+GLAPI void APIENTRY glVertexP4ui (GLenum type, GLuint value);
+GLAPI void APIENTRY glVertexP4uiv (GLenum type, const GLuint *value);
+GLAPI void APIENTRY glTexCoordP1ui (GLenum type, GLuint coords);
+GLAPI void APIENTRY glTexCoordP1uiv (GLenum type, const GLuint *coords);
+GLAPI void APIENTRY glTexCoordP2ui (GLenum type, GLuint coords);
+GLAPI void APIENTRY glTexCoordP2uiv (GLenum type, const GLuint *coords);
+GLAPI void APIENTRY glTexCoordP3ui (GLenum type, GLuint coords);
+GLAPI void APIENTRY glTexCoordP3uiv (GLenum type, const GLuint *coords);
+GLAPI void APIENTRY glTexCoordP4ui (GLenum type, GLuint coords);
+GLAPI void APIENTRY glTexCoordP4uiv (GLenum type, const GLuint *coords);
+GLAPI void APIENTRY glMultiTexCoordP1ui (GLenum texture, GLenum type, GLuint coords);
+GLAPI void APIENTRY glMultiTexCoordP1uiv (GLenum texture, GLenum type, const GLuint *coords);
+GLAPI void APIENTRY glMultiTexCoordP2ui (GLenum texture, GLenum type, GLuint coords);
+GLAPI void APIENTRY glMultiTexCoordP2uiv (GLenum texture, GLenum type, const GLuint *coords);
+GLAPI void APIENTRY glMultiTexCoordP3ui (GLenum texture, GLenum type, GLuint coords);
+GLAPI void APIENTRY glMultiTexCoordP3uiv (GLenum texture, GLenum type, const GLuint *coords);
+GLAPI void APIENTRY glMultiTexCoordP4ui (GLenum texture, GLenum type, GLuint coords);
+GLAPI void APIENTRY glMultiTexCoordP4uiv (GLenum texture, GLenum type, const GLuint *coords);
+GLAPI void APIENTRY glNormalP3ui (GLenum type, GLuint coords);
+GLAPI void APIENTRY glNormalP3uiv (GLenum type, const GLuint *coords);
+GLAPI void APIENTRY glColorP3ui (GLenum type, GLuint color);
+GLAPI void APIENTRY glColorP3uiv (GLenum type, const GLuint *color);
+GLAPI void APIENTRY glColorP4ui (GLenum type, GLuint color);
+GLAPI void APIENTRY glColorP4uiv (GLenum type, const GLuint *color);
+GLAPI void APIENTRY glSecondaryColorP3ui (GLenum type, GLuint color);
+GLAPI void APIENTRY glSecondaryColorP3uiv (GLenum type, const GLuint *color);
+#endif
+#endif /* GL_VERSION_3_3 */
+
+#ifndef GL_VERSION_4_0
+#define GL_VERSION_4_0 1
+#define GL_SAMPLE_SHADING 0x8C36
+#define GL_MIN_SAMPLE_SHADING_VALUE 0x8C37
+#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5E
+#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5F
+#define GL_TEXTURE_CUBE_MAP_ARRAY 0x9009
+#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY 0x900A
+#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY 0x900B
+#define GL_SAMPLER_CUBE_MAP_ARRAY 0x900C
+#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW 0x900D
+#define GL_INT_SAMPLER_CUBE_MAP_ARRAY 0x900E
+#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY 0x900F
+#define GL_DRAW_INDIRECT_BUFFER 0x8F3F
+#define GL_DRAW_INDIRECT_BUFFER_BINDING 0x8F43
+#define GL_GEOMETRY_SHADER_INVOCATIONS 0x887F
+#define GL_MAX_GEOMETRY_SHADER_INVOCATIONS 0x8E5A
+#define GL_MIN_FRAGMENT_INTERPOLATION_OFFSET 0x8E5B
+#define GL_MAX_FRAGMENT_INTERPOLATION_OFFSET 0x8E5C
+#define GL_FRAGMENT_INTERPOLATION_OFFSET_BITS 0x8E5D
+#define GL_MAX_VERTEX_STREAMS 0x8E71
+#define GL_DOUBLE_VEC2 0x8FFC
+#define GL_DOUBLE_VEC3 0x8FFD
+#define GL_DOUBLE_VEC4 0x8FFE
+#define GL_DOUBLE_MAT2 0x8F46
+#define GL_DOUBLE_MAT3 0x8F47
+#define GL_DOUBLE_MAT4 0x8F48
+#define GL_DOUBLE_MAT2x3 0x8F49
+#define GL_DOUBLE_MAT2x4 0x8F4A
+#define GL_DOUBLE_MAT3x2 0x8F4B
+#define GL_DOUBLE_MAT3x4 0x8F4C
+#define GL_DOUBLE_MAT4x2 0x8F4D
+#define GL_DOUBLE_MAT4x3 0x8F4E
+#define GL_ACTIVE_SUBROUTINES 0x8DE5
+#define GL_ACTIVE_SUBROUTINE_UNIFORMS 0x8DE6
+#define GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS 0x8E47
+#define GL_ACTIVE_SUBROUTINE_MAX_LENGTH 0x8E48
+#define GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH 0x8E49
+#define GL_MAX_SUBROUTINES 0x8DE7
+#define GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS 0x8DE8
+#define GL_NUM_COMPATIBLE_SUBROUTINES 0x8E4A
+#define GL_COMPATIBLE_SUBROUTINES 0x8E4B
+#define GL_PATCHES 0x000E
+#define GL_PATCH_VERTICES 0x8E72
+#define GL_PATCH_DEFAULT_INNER_LEVEL 0x8E73
+#define GL_PATCH_DEFAULT_OUTER_LEVEL 0x8E74
+#define GL_TESS_CONTROL_OUTPUT_VERTICES 0x8E75
+#define GL_TESS_GEN_MODE 0x8E76
+#define GL_TESS_GEN_SPACING 0x8E77
+#define GL_TESS_GEN_VERTEX_ORDER 0x8E78
+#define GL_TESS_GEN_POINT_MODE 0x8E79
+#define GL_ISOLINES 0x8E7A
+#define GL_FRACTIONAL_ODD 0x8E7B
+#define GL_FRACTIONAL_EVEN 0x8E7C
+#define GL_MAX_PATCH_VERTICES 0x8E7D
+#define GL_MAX_TESS_GEN_LEVEL 0x8E7E
+#define GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS 0x8E7F
+#define GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS 0x8E80
+#define GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS 0x8E81
+#define GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS 0x8E82
+#define GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS 0x8E83
+#define GL_MAX_TESS_PATCH_COMPONENTS 0x8E84
+#define GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS 0x8E85
+#define GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS 0x8E86
+#define GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS 0x8E89
+#define GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS 0x8E8A
+#define GL_MAX_TESS_CONTROL_INPUT_COMPONENTS 0x886C
+#define GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS 0x886D
+#define GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS 0x8E1E
+#define GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS 0x8E1F
+#define GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER 0x84F0
+#define GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER 0x84F1
+#define GL_TESS_EVALUATION_SHADER 0x8E87
+#define GL_TESS_CONTROL_SHADER 0x8E88
+#define GL_TRANSFORM_FEEDBACK 0x8E22
+#define GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED 0x8E23
+#define GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE 0x8E24
+#define GL_TRANSFORM_FEEDBACK_BINDING 0x8E25
+#define GL_MAX_TRANSFORM_FEEDBACK_BUFFERS 0x8E70
+typedef void (APIENTRYP PFNGLMINSAMPLESHADINGPROC) (GLfloat value);
+typedef void (APIENTRYP PFNGLBLENDEQUATIONIPROC) (GLuint buf, GLenum mode);
+typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha);
+typedef void (APIENTRYP PFNGLBLENDFUNCIPROC) (GLuint buf, GLenum src, GLenum dst);
+typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+typedef void (APIENTRYP PFNGLDRAWARRAYSINDIRECTPROC) (GLenum mode, const void *indirect);
+typedef void (APIENTRYP PFNGLDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const void *indirect);
+typedef void (APIENTRYP PFNGLUNIFORM1DPROC) (GLint location, GLdouble x);
+typedef void (APIENTRYP PFNGLUNIFORM2DPROC) (GLint location, GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLUNIFORM3DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLUNIFORM4DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLUNIFORM1DVPROC) (GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORM2DVPROC) (GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORM3DVPROC) (GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORM4DVPROC) (GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLGETUNIFORMDVPROC) (GLuint program, GLint location, GLdouble *params);
+typedef GLint (APIENTRYP PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC) (GLuint program, GLenum shadertype, const GLchar *name);
+typedef GLuint (APIENTRYP PFNGLGETSUBROUTINEINDEXPROC) (GLuint program, GLenum shadertype, const GLchar *name);
+typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC) (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values);
+typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name);
+typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINENAMEPROC) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name);
+typedef void (APIENTRYP PFNGLUNIFORMSUBROUTINESUIVPROC) (GLenum shadertype, GLsizei count, const GLuint *indices);
+typedef void (APIENTRYP PFNGLGETUNIFORMSUBROUTINEUIVPROC) (GLenum shadertype, GLint location, GLuint *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMSTAGEIVPROC) (GLuint program, GLenum shadertype, GLenum pname, GLint *values);
+typedef void (APIENTRYP PFNGLPATCHPARAMETERIPROC) (GLenum pname, GLint value);
+typedef void (APIENTRYP PFNGLPATCHPARAMETERFVPROC) (GLenum pname, const GLfloat *values);
+typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKPROC) (GLenum target, GLuint id);
+typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSPROC) (GLsizei n, const GLuint *ids);
+typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSPROC) (GLsizei n, GLuint *ids);
+typedef GLboolean (APIENTRYP PFNGLISTRANSFORMFEEDBACKPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLPAUSETRANSFORMFEEDBACKPROC) (void);
+typedef void (APIENTRYP PFNGLRESUMETRANSFORMFEEDBACKPROC) (void);
+typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKPROC) (GLenum mode, GLuint id);
+typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC) (GLenum mode, GLuint id, GLuint stream);
+typedef void (APIENTRYP PFNGLBEGINQUERYINDEXEDPROC) (GLenum target, GLuint index, GLuint id);
+typedef void (APIENTRYP PFNGLENDQUERYINDEXEDPROC) (GLenum target, GLuint index);
+typedef void (APIENTRYP PFNGLGETQUERYINDEXEDIVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMinSampleShading (GLfloat value);
+GLAPI void APIENTRY glBlendEquationi (GLuint buf, GLenum mode);
+GLAPI void APIENTRY glBlendEquationSeparatei (GLuint buf, GLenum modeRGB, GLenum modeAlpha);
+GLAPI void APIENTRY glBlendFunci (GLuint buf, GLenum src, GLenum dst);
+GLAPI void APIENTRY glBlendFuncSeparatei (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+GLAPI void APIENTRY glDrawArraysIndirect (GLenum mode, const void *indirect);
+GLAPI void APIENTRY glDrawElementsIndirect (GLenum mode, GLenum type, const void *indirect);
+GLAPI void APIENTRY glUniform1d (GLint location, GLdouble x);
+GLAPI void APIENTRY glUniform2d (GLint location, GLdouble x, GLdouble y);
+GLAPI void APIENTRY glUniform3d (GLint location, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glUniform4d (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glUniform1dv (GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glUniform2dv (GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glUniform3dv (GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glUniform4dv (GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glUniformMatrix2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glUniformMatrix3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glUniformMatrix4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glUniformMatrix2x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glUniformMatrix2x4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glUniformMatrix3x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glUniformMatrix3x4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glUniformMatrix4x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glUniformMatrix4x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glGetUniformdv (GLuint program, GLint location, GLdouble *params);
+GLAPI GLint APIENTRY glGetSubroutineUniformLocation (GLuint program, GLenum shadertype, const GLchar *name);
+GLAPI GLuint APIENTRY glGetSubroutineIndex (GLuint program, GLenum shadertype, const GLchar *name);
+GLAPI void APIENTRY glGetActiveSubroutineUniformiv (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values);
+GLAPI void APIENTRY glGetActiveSubroutineUniformName (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name);
+GLAPI void APIENTRY glGetActiveSubroutineName (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name);
+GLAPI void APIENTRY glUniformSubroutinesuiv (GLenum shadertype, GLsizei count, const GLuint *indices);
+GLAPI void APIENTRY glGetUniformSubroutineuiv (GLenum shadertype, GLint location, GLuint *params);
+GLAPI void APIENTRY glGetProgramStageiv (GLuint program, GLenum shadertype, GLenum pname, GLint *values);
+GLAPI void APIENTRY glPatchParameteri (GLenum pname, GLint value);
+GLAPI void APIENTRY glPatchParameterfv (GLenum pname, const GLfloat *values);
+GLAPI void APIENTRY glBindTransformFeedback (GLenum target, GLuint id);
+GLAPI void APIENTRY glDeleteTransformFeedbacks (GLsizei n, const GLuint *ids);
+GLAPI void APIENTRY glGenTransformFeedbacks (GLsizei n, GLuint *ids);
+GLAPI GLboolean APIENTRY glIsTransformFeedback (GLuint id);
+GLAPI void APIENTRY glPauseTransformFeedback (void);
+GLAPI void APIENTRY glResumeTransformFeedback (void);
+GLAPI void APIENTRY glDrawTransformFeedback (GLenum mode, GLuint id);
+GLAPI void APIENTRY glDrawTransformFeedbackStream (GLenum mode, GLuint id, GLuint stream);
+GLAPI void APIENTRY glBeginQueryIndexed (GLenum target, GLuint index, GLuint id);
+GLAPI void APIENTRY glEndQueryIndexed (GLenum target, GLuint index);
+GLAPI void APIENTRY glGetQueryIndexediv (GLenum target, GLuint index, GLenum pname, GLint *params);
+#endif
+#endif /* GL_VERSION_4_0 */
+
+#ifndef GL_VERSION_4_1
+#define GL_VERSION_4_1 1
+#define GL_FIXED 0x140C
+#define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A
+#define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B
+#define GL_LOW_FLOAT 0x8DF0
+#define GL_MEDIUM_FLOAT 0x8DF1
+#define GL_HIGH_FLOAT 0x8DF2
+#define GL_LOW_INT 0x8DF3
+#define GL_MEDIUM_INT 0x8DF4
+#define GL_HIGH_INT 0x8DF5
+#define GL_SHADER_COMPILER 0x8DFA
+#define GL_SHADER_BINARY_FORMATS 0x8DF8
+#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9
+#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB
+#define GL_MAX_VARYING_VECTORS 0x8DFC
+#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD
+#define GL_RGB565 0x8D62
+#define GL_PROGRAM_BINARY_RETRIEVABLE_HINT 0x8257
+#define GL_PROGRAM_BINARY_LENGTH 0x8741
+#define GL_NUM_PROGRAM_BINARY_FORMATS 0x87FE
+#define GL_PROGRAM_BINARY_FORMATS 0x87FF
+#define GL_VERTEX_SHADER_BIT 0x00000001
+#define GL_FRAGMENT_SHADER_BIT 0x00000002
+#define GL_GEOMETRY_SHADER_BIT 0x00000004
+#define GL_TESS_CONTROL_SHADER_BIT 0x00000008
+#define GL_TESS_EVALUATION_SHADER_BIT 0x00000010
+#define GL_ALL_SHADER_BITS 0xFFFFFFFF
+#define GL_PROGRAM_SEPARABLE 0x8258
+#define GL_ACTIVE_PROGRAM 0x8259
+#define GL_PROGRAM_PIPELINE_BINDING 0x825A
+#define GL_MAX_VIEWPORTS 0x825B
+#define GL_VIEWPORT_SUBPIXEL_BITS 0x825C
+#define GL_VIEWPORT_BOUNDS_RANGE 0x825D
+#define GL_LAYER_PROVOKING_VERTEX 0x825E
+#define GL_VIEWPORT_INDEX_PROVOKING_VERTEX 0x825F
+#define GL_UNDEFINED_VERTEX 0x8260
+typedef void (APIENTRYP PFNGLRELEASESHADERCOMPILERPROC) (void);
+typedef void (APIENTRYP PFNGLSHADERBINARYPROC) (GLsizei count, const GLuint *shaders, GLenum binaryformat, const void *binary, GLsizei length);
+typedef void (APIENTRYP PFNGLGETSHADERPRECISIONFORMATPROC) (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision);
+typedef void (APIENTRYP PFNGLDEPTHRANGEFPROC) (GLfloat n, GLfloat f);
+typedef void (APIENTRYP PFNGLCLEARDEPTHFPROC) (GLfloat d);
+typedef void (APIENTRYP PFNGLGETPROGRAMBINARYPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, void *binary);
+typedef void (APIENTRYP PFNGLPROGRAMBINARYPROC) (GLuint program, GLenum binaryFormat, const void *binary, GLsizei length);
+typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIPROC) (GLuint program, GLenum pname, GLint value);
+typedef void (APIENTRYP PFNGLUSEPROGRAMSTAGESPROC) (GLuint pipeline, GLbitfield stages, GLuint program);
+typedef void (APIENTRYP PFNGLACTIVESHADERPROGRAMPROC) (GLuint pipeline, GLuint program);
+typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMVPROC) (GLenum type, GLsizei count, const GLchar *const*strings);
+typedef void (APIENTRYP PFNGLBINDPROGRAMPIPELINEPROC) (GLuint pipeline);
+typedef void (APIENTRYP PFNGLDELETEPROGRAMPIPELINESPROC) (GLsizei n, const GLuint *pipelines);
+typedef void (APIENTRYP PFNGLGENPROGRAMPIPELINESPROC) (GLsizei n, GLuint *pipelines);
+typedef GLboolean (APIENTRYP PFNGLISPROGRAMPIPELINEPROC) (GLuint pipeline);
+typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEIVPROC) (GLuint pipeline, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IPROC) (GLuint program, GLint location, GLint v0);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FPROC) (GLuint program, GLint location, GLfloat v0);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DPROC) (GLuint program, GLint location, GLdouble v0);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIPROC) (GLuint program, GLint location, GLuint v0);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IPROC) (GLuint program, GLint location, GLint v0, GLint v1);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPIPELINEPROC) (GLuint pipeline);
+typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEINFOLOGPROC) (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DPROC) (GLuint index, GLdouble x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DPROC) (GLuint index, GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLDVPROC) (GLuint index, GLenum pname, GLdouble *params);
+typedef void (APIENTRYP PFNGLVIEWPORTARRAYVPROC) (GLuint first, GLsizei count, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h);
+typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFVPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLSCISSORARRAYVPROC) (GLuint first, GLsizei count, const GLint *v);
+typedef void (APIENTRYP PFNGLSCISSORINDEXEDPROC) (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLSCISSORINDEXEDVPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLDEPTHRANGEARRAYVPROC) (GLuint first, GLsizei count, const GLdouble *v);
+typedef void (APIENTRYP PFNGLDEPTHRANGEINDEXEDPROC) (GLuint index, GLdouble n, GLdouble f);
+typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data);
+typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glReleaseShaderCompiler (void);
+GLAPI void APIENTRY glShaderBinary (GLsizei count, const GLuint *shaders, GLenum binaryformat, const void *binary, GLsizei length);
+GLAPI void APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision);
+GLAPI void APIENTRY glDepthRangef (GLfloat n, GLfloat f);
+GLAPI void APIENTRY glClearDepthf (GLfloat d);
+GLAPI void APIENTRY glGetProgramBinary (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, void *binary);
+GLAPI void APIENTRY glProgramBinary (GLuint program, GLenum binaryFormat, const void *binary, GLsizei length);
+GLAPI void APIENTRY glProgramParameteri (GLuint program, GLenum pname, GLint value);
+GLAPI void APIENTRY glUseProgramStages (GLuint pipeline, GLbitfield stages, GLuint program);
+GLAPI void APIENTRY glActiveShaderProgram (GLuint pipeline, GLuint program);
+GLAPI GLuint APIENTRY glCreateShaderProgramv (GLenum type, GLsizei count, const GLchar *const*strings);
+GLAPI void APIENTRY glBindProgramPipeline (GLuint pipeline);
+GLAPI void APIENTRY glDeleteProgramPipelines (GLsizei n, const GLuint *pipelines);
+GLAPI void APIENTRY glGenProgramPipelines (GLsizei n, GLuint *pipelines);
+GLAPI GLboolean APIENTRY glIsProgramPipeline (GLuint pipeline);
+GLAPI void APIENTRY glGetProgramPipelineiv (GLuint pipeline, GLenum pname, GLint *params);
+GLAPI void APIENTRY glProgramUniform1i (GLuint program, GLint location, GLint v0);
+GLAPI void APIENTRY glProgramUniform1iv (GLuint program, GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glProgramUniform1f (GLuint program, GLint location, GLfloat v0);
+GLAPI void APIENTRY glProgramUniform1fv (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniform1d (GLuint program, GLint location, GLdouble v0);
+GLAPI void APIENTRY glProgramUniform1dv (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniform1ui (GLuint program, GLint location, GLuint v0);
+GLAPI void APIENTRY glProgramUniform1uiv (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glProgramUniform2i (GLuint program, GLint location, GLint v0, GLint v1);
+GLAPI void APIENTRY glProgramUniform2iv (GLuint program, GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glProgramUniform2f (GLuint program, GLint location, GLfloat v0, GLfloat v1);
+GLAPI void APIENTRY glProgramUniform2fv (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniform2d (GLuint program, GLint location, GLdouble v0, GLdouble v1);
+GLAPI void APIENTRY glProgramUniform2dv (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniform2ui (GLuint program, GLint location, GLuint v0, GLuint v1);
+GLAPI void APIENTRY glProgramUniform2uiv (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glProgramUniform3i (GLuint program, GLint location, GLint v0, GLint v1, GLint v2);
+GLAPI void APIENTRY glProgramUniform3iv (GLuint program, GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glProgramUniform3f (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+GLAPI void APIENTRY glProgramUniform3fv (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniform3d (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2);
+GLAPI void APIENTRY glProgramUniform3dv (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniform3ui (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2);
+GLAPI void APIENTRY glProgramUniform3uiv (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glProgramUniform4i (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+GLAPI void APIENTRY glProgramUniform4iv (GLuint program, GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glProgramUniform4f (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+GLAPI void APIENTRY glProgramUniform4fv (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniform4d (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3);
+GLAPI void APIENTRY glProgramUniform4dv (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniform4ui (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+GLAPI void APIENTRY glProgramUniform4uiv (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glProgramUniformMatrix2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix2x3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix3x2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix2x4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix4x2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix3x4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix4x3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix2x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix3x2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix2x4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix4x2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix3x4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix4x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glValidateProgramPipeline (GLuint pipeline);
+GLAPI void APIENTRY glGetProgramPipelineInfoLog (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+GLAPI void APIENTRY glVertexAttribL1d (GLuint index, GLdouble x);
+GLAPI void APIENTRY glVertexAttribL2d (GLuint index, GLdouble x, GLdouble y);
+GLAPI void APIENTRY glVertexAttribL3d (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glVertexAttribL4d (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glVertexAttribL1dv (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribL2dv (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribL3dv (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribL4dv (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribLPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glGetVertexAttribLdv (GLuint index, GLenum pname, GLdouble *params);
+GLAPI void APIENTRY glViewportArrayv (GLuint first, GLsizei count, const GLfloat *v);
+GLAPI void APIENTRY glViewportIndexedf (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h);
+GLAPI void APIENTRY glViewportIndexedfv (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glScissorArrayv (GLuint first, GLsizei count, const GLint *v);
+GLAPI void APIENTRY glScissorIndexed (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glScissorIndexedv (GLuint index, const GLint *v);
+GLAPI void APIENTRY glDepthRangeArrayv (GLuint first, GLsizei count, const GLdouble *v);
+GLAPI void APIENTRY glDepthRangeIndexed (GLuint index, GLdouble n, GLdouble f);
+GLAPI void APIENTRY glGetFloati_v (GLenum target, GLuint index, GLfloat *data);
+GLAPI void APIENTRY glGetDoublei_v (GLenum target, GLuint index, GLdouble *data);
+#endif
+#endif /* GL_VERSION_4_1 */
+
+#ifndef GL_VERSION_4_2
+#define GL_VERSION_4_2 1
+#define GL_UNPACK_COMPRESSED_BLOCK_WIDTH 0x9127
+#define GL_UNPACK_COMPRESSED_BLOCK_HEIGHT 0x9128
+#define GL_UNPACK_COMPRESSED_BLOCK_DEPTH 0x9129
+#define GL_UNPACK_COMPRESSED_BLOCK_SIZE 0x912A
+#define GL_PACK_COMPRESSED_BLOCK_WIDTH 0x912B
+#define GL_PACK_COMPRESSED_BLOCK_HEIGHT 0x912C
+#define GL_PACK_COMPRESSED_BLOCK_DEPTH 0x912D
+#define GL_PACK_COMPRESSED_BLOCK_SIZE 0x912E
+#define GL_NUM_SAMPLE_COUNTS 0x9380
+#define GL_MIN_MAP_BUFFER_ALIGNMENT 0x90BC
+#define GL_ATOMIC_COUNTER_BUFFER 0x92C0
+#define GL_ATOMIC_COUNTER_BUFFER_BINDING 0x92C1
+#define GL_ATOMIC_COUNTER_BUFFER_START 0x92C2
+#define GL_ATOMIC_COUNTER_BUFFER_SIZE 0x92C3
+#define GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE 0x92C4
+#define GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS 0x92C5
+#define GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES 0x92C6
+#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER 0x92C7
+#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER 0x92C8
+#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER 0x92C9
+#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER 0x92CA
+#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER 0x92CB
+#define GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS 0x92CC
+#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS 0x92CD
+#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS 0x92CE
+#define GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS 0x92CF
+#define GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS 0x92D0
+#define GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS 0x92D1
+#define GL_MAX_VERTEX_ATOMIC_COUNTERS 0x92D2
+#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS 0x92D3
+#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS 0x92D4
+#define GL_MAX_GEOMETRY_ATOMIC_COUNTERS 0x92D5
+#define GL_MAX_FRAGMENT_ATOMIC_COUNTERS 0x92D6
+#define GL_MAX_COMBINED_ATOMIC_COUNTERS 0x92D7
+#define GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE 0x92D8
+#define GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS 0x92DC
+#define GL_ACTIVE_ATOMIC_COUNTER_BUFFERS 0x92D9
+#define GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX 0x92DA
+#define GL_UNSIGNED_INT_ATOMIC_COUNTER 0x92DB
+#define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT 0x00000001
+#define GL_ELEMENT_ARRAY_BARRIER_BIT 0x00000002
+#define GL_UNIFORM_BARRIER_BIT 0x00000004
+#define GL_TEXTURE_FETCH_BARRIER_BIT 0x00000008
+#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT 0x00000020
+#define GL_COMMAND_BARRIER_BIT 0x00000040
+#define GL_PIXEL_BUFFER_BARRIER_BIT 0x00000080
+#define GL_TEXTURE_UPDATE_BARRIER_BIT 0x00000100
+#define GL_BUFFER_UPDATE_BARRIER_BIT 0x00000200
+#define GL_FRAMEBUFFER_BARRIER_BIT 0x00000400
+#define GL_TRANSFORM_FEEDBACK_BARRIER_BIT 0x00000800
+#define GL_ATOMIC_COUNTER_BARRIER_BIT 0x00001000
+#define GL_ALL_BARRIER_BITS 0xFFFFFFFF
+#define GL_MAX_IMAGE_UNITS 0x8F38
+#define GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS 0x8F39
+#define GL_IMAGE_BINDING_NAME 0x8F3A
+#define GL_IMAGE_BINDING_LEVEL 0x8F3B
+#define GL_IMAGE_BINDING_LAYERED 0x8F3C
+#define GL_IMAGE_BINDING_LAYER 0x8F3D
+#define GL_IMAGE_BINDING_ACCESS 0x8F3E
+#define GL_IMAGE_1D 0x904C
+#define GL_IMAGE_2D 0x904D
+#define GL_IMAGE_3D 0x904E
+#define GL_IMAGE_2D_RECT 0x904F
+#define GL_IMAGE_CUBE 0x9050
+#define GL_IMAGE_BUFFER 0x9051
+#define GL_IMAGE_1D_ARRAY 0x9052
+#define GL_IMAGE_2D_ARRAY 0x9053
+#define GL_IMAGE_CUBE_MAP_ARRAY 0x9054
+#define GL_IMAGE_2D_MULTISAMPLE 0x9055
+#define GL_IMAGE_2D_MULTISAMPLE_ARRAY 0x9056
+#define GL_INT_IMAGE_1D 0x9057
+#define GL_INT_IMAGE_2D 0x9058
+#define GL_INT_IMAGE_3D 0x9059
+#define GL_INT_IMAGE_2D_RECT 0x905A
+#define GL_INT_IMAGE_CUBE 0x905B
+#define GL_INT_IMAGE_BUFFER 0x905C
+#define GL_INT_IMAGE_1D_ARRAY 0x905D
+#define GL_INT_IMAGE_2D_ARRAY 0x905E
+#define GL_INT_IMAGE_CUBE_MAP_ARRAY 0x905F
+#define GL_INT_IMAGE_2D_MULTISAMPLE 0x9060
+#define GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x9061
+#define GL_UNSIGNED_INT_IMAGE_1D 0x9062
+#define GL_UNSIGNED_INT_IMAGE_2D 0x9063
+#define GL_UNSIGNED_INT_IMAGE_3D 0x9064
+#define GL_UNSIGNED_INT_IMAGE_2D_RECT 0x9065
+#define GL_UNSIGNED_INT_IMAGE_CUBE 0x9066
+#define GL_UNSIGNED_INT_IMAGE_BUFFER 0x9067
+#define GL_UNSIGNED_INT_IMAGE_1D_ARRAY 0x9068
+#define GL_UNSIGNED_INT_IMAGE_2D_ARRAY 0x9069
+#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY 0x906A
+#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE 0x906B
+#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x906C
+#define GL_MAX_IMAGE_SAMPLES 0x906D
+#define GL_IMAGE_BINDING_FORMAT 0x906E
+#define GL_IMAGE_FORMAT_COMPATIBILITY_TYPE 0x90C7
+#define GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE 0x90C8
+#define GL_IMAGE_FORMAT_COMPATIBILITY_BY_CLASS 0x90C9
+#define GL_MAX_VERTEX_IMAGE_UNIFORMS 0x90CA
+#define GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS 0x90CB
+#define GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS 0x90CC
+#define GL_MAX_GEOMETRY_IMAGE_UNIFORMS 0x90CD
+#define GL_MAX_FRAGMENT_IMAGE_UNIFORMS 0x90CE
+#define GL_MAX_COMBINED_IMAGE_UNIFORMS 0x90CF
+#define GL_COMPRESSED_RGBA_BPTC_UNORM 0x8E8C
+#define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM 0x8E8D
+#define GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT 0x8E8E
+#define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT 0x8E8F
+#define GL_TEXTURE_IMMUTABLE_FORMAT 0x912F
+typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance);
+typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance);
+typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance);
+typedef void (APIENTRYP PFNGLGETINTERNALFORMATIVPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint *params);
+typedef void (APIENTRYP PFNGLGETACTIVEATOMICCOUNTERBUFFERIVPROC) (GLuint program, GLuint bufferIndex, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLBINDIMAGETEXTUREPROC) (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format);
+typedef void (APIENTRYP PFNGLMEMORYBARRIERPROC) (GLbitfield barriers);
+typedef void (APIENTRYP PFNGLTEXSTORAGE1DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+typedef void (APIENTRYP PFNGLTEXSTORAGE2DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLTEXSTORAGE3DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDPROC) (GLenum mode, GLuint id, GLsizei instancecount);
+typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC) (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawArraysInstancedBaseInstance (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance);
+GLAPI void APIENTRY glDrawElementsInstancedBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance);
+GLAPI void APIENTRY glDrawElementsInstancedBaseVertexBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance);
+GLAPI void APIENTRY glGetInternalformativ (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint *params);
+GLAPI void APIENTRY glGetActiveAtomicCounterBufferiv (GLuint program, GLuint bufferIndex, GLenum pname, GLint *params);
+GLAPI void APIENTRY glBindImageTexture (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format);
+GLAPI void APIENTRY glMemoryBarrier (GLbitfield barriers);
+GLAPI void APIENTRY glTexStorage1D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+GLAPI void APIENTRY glTexStorage2D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glTexStorage3D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+GLAPI void APIENTRY glDrawTransformFeedbackInstanced (GLenum mode, GLuint id, GLsizei instancecount);
+GLAPI void APIENTRY glDrawTransformFeedbackStreamInstanced (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount);
+#endif
+#endif /* GL_VERSION_4_2 */
+
+#ifndef GL_VERSION_4_3
+#define GL_VERSION_4_3 1
+typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
+#define GL_NUM_SHADING_LANGUAGE_VERSIONS 0x82E9
+#define GL_VERTEX_ATTRIB_ARRAY_LONG 0x874E
+#define GL_COMPRESSED_RGB8_ETC2 0x9274
+#define GL_COMPRESSED_SRGB8_ETC2 0x9275
+#define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276
+#define GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9277
+#define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278
+#define GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279
+#define GL_COMPRESSED_R11_EAC 0x9270
+#define GL_COMPRESSED_SIGNED_R11_EAC 0x9271
+#define GL_COMPRESSED_RG11_EAC 0x9272
+#define GL_COMPRESSED_SIGNED_RG11_EAC 0x9273
+#define GL_PRIMITIVE_RESTART_FIXED_INDEX 0x8D69
+#define GL_ANY_SAMPLES_PASSED_CONSERVATIVE 0x8D6A
+#define GL_MAX_ELEMENT_INDEX 0x8D6B
+#define GL_COMPUTE_SHADER 0x91B9
+#define GL_MAX_COMPUTE_UNIFORM_BLOCKS 0x91BB
+#define GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS 0x91BC
+#define GL_MAX_COMPUTE_IMAGE_UNIFORMS 0x91BD
+#define GL_MAX_COMPUTE_SHARED_MEMORY_SIZE 0x8262
+#define GL_MAX_COMPUTE_UNIFORM_COMPONENTS 0x8263
+#define GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS 0x8264
+#define GL_MAX_COMPUTE_ATOMIC_COUNTERS 0x8265
+#define GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS 0x8266
+#define GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS 0x90EB
+#define GL_MAX_COMPUTE_WORK_GROUP_COUNT 0x91BE
+#define GL_MAX_COMPUTE_WORK_GROUP_SIZE 0x91BF
+#define GL_COMPUTE_WORK_GROUP_SIZE 0x8267
+#define GL_UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER 0x90EC
+#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_COMPUTE_SHADER 0x90ED
+#define GL_DISPATCH_INDIRECT_BUFFER 0x90EE
+#define GL_DISPATCH_INDIRECT_BUFFER_BINDING 0x90EF
+#define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242
+#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH 0x8243
+#define GL_DEBUG_CALLBACK_FUNCTION 0x8244
+#define GL_DEBUG_CALLBACK_USER_PARAM 0x8245
+#define GL_DEBUG_SOURCE_API 0x8246
+#define GL_DEBUG_SOURCE_WINDOW_SYSTEM 0x8247
+#define GL_DEBUG_SOURCE_SHADER_COMPILER 0x8248
+#define GL_DEBUG_SOURCE_THIRD_PARTY 0x8249
+#define GL_DEBUG_SOURCE_APPLICATION 0x824A
+#define GL_DEBUG_SOURCE_OTHER 0x824B
+#define GL_DEBUG_TYPE_ERROR 0x824C
+#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR 0x824D
+#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR 0x824E
+#define GL_DEBUG_TYPE_PORTABILITY 0x824F
+#define GL_DEBUG_TYPE_PERFORMANCE 0x8250
+#define GL_DEBUG_TYPE_OTHER 0x8251
+#define GL_MAX_DEBUG_MESSAGE_LENGTH 0x9143
+#define GL_MAX_DEBUG_LOGGED_MESSAGES 0x9144
+#define GL_DEBUG_LOGGED_MESSAGES 0x9145
+#define GL_DEBUG_SEVERITY_HIGH 0x9146
+#define GL_DEBUG_SEVERITY_MEDIUM 0x9147
+#define GL_DEBUG_SEVERITY_LOW 0x9148
+#define GL_DEBUG_TYPE_MARKER 0x8268
+#define GL_DEBUG_TYPE_PUSH_GROUP 0x8269
+#define GL_DEBUG_TYPE_POP_GROUP 0x826A
+#define GL_DEBUG_SEVERITY_NOTIFICATION 0x826B
+#define GL_MAX_DEBUG_GROUP_STACK_DEPTH 0x826C
+#define GL_DEBUG_GROUP_STACK_DEPTH 0x826D
+#define GL_BUFFER 0x82E0
+#define GL_SHADER 0x82E1
+#define GL_PROGRAM 0x82E2
+#define GL_QUERY 0x82E3
+#define GL_PROGRAM_PIPELINE 0x82E4
+#define GL_SAMPLER 0x82E6
+#define GL_MAX_LABEL_LENGTH 0x82E8
+#define GL_DEBUG_OUTPUT 0x92E0
+#define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002
+#define GL_MAX_UNIFORM_LOCATIONS 0x826E
+#define GL_FRAMEBUFFER_DEFAULT_WIDTH 0x9310
+#define GL_FRAMEBUFFER_DEFAULT_HEIGHT 0x9311
+#define GL_FRAMEBUFFER_DEFAULT_LAYERS 0x9312
+#define GL_FRAMEBUFFER_DEFAULT_SAMPLES 0x9313
+#define GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS 0x9314
+#define GL_MAX_FRAMEBUFFER_WIDTH 0x9315
+#define GL_MAX_FRAMEBUFFER_HEIGHT 0x9316
+#define GL_MAX_FRAMEBUFFER_LAYERS 0x9317
+#define GL_MAX_FRAMEBUFFER_SAMPLES 0x9318
+#define GL_INTERNALFORMAT_SUPPORTED 0x826F
+#define GL_INTERNALFORMAT_PREFERRED 0x8270
+#define GL_INTERNALFORMAT_RED_SIZE 0x8271
+#define GL_INTERNALFORMAT_GREEN_SIZE 0x8272
+#define GL_INTERNALFORMAT_BLUE_SIZE 0x8273
+#define GL_INTERNALFORMAT_ALPHA_SIZE 0x8274
+#define GL_INTERNALFORMAT_DEPTH_SIZE 0x8275
+#define GL_INTERNALFORMAT_STENCIL_SIZE 0x8276
+#define GL_INTERNALFORMAT_SHARED_SIZE 0x8277
+#define GL_INTERNALFORMAT_RED_TYPE 0x8278
+#define GL_INTERNALFORMAT_GREEN_TYPE 0x8279
+#define GL_INTERNALFORMAT_BLUE_TYPE 0x827A
+#define GL_INTERNALFORMAT_ALPHA_TYPE 0x827B
+#define GL_INTERNALFORMAT_DEPTH_TYPE 0x827C
+#define GL_INTERNALFORMAT_STENCIL_TYPE 0x827D
+#define GL_MAX_WIDTH 0x827E
+#define GL_MAX_HEIGHT 0x827F
+#define GL_MAX_DEPTH 0x8280
+#define GL_MAX_LAYERS 0x8281
+#define GL_MAX_COMBINED_DIMENSIONS 0x8282
+#define GL_COLOR_COMPONENTS 0x8283
+#define GL_DEPTH_COMPONENTS 0x8284
+#define GL_STENCIL_COMPONENTS 0x8285
+#define GL_COLOR_RENDERABLE 0x8286
+#define GL_DEPTH_RENDERABLE 0x8287
+#define GL_STENCIL_RENDERABLE 0x8288
+#define GL_FRAMEBUFFER_RENDERABLE 0x8289
+#define GL_FRAMEBUFFER_RENDERABLE_LAYERED 0x828A
+#define GL_FRAMEBUFFER_BLEND 0x828B
+#define GL_READ_PIXELS 0x828C
+#define GL_READ_PIXELS_FORMAT 0x828D
+#define GL_READ_PIXELS_TYPE 0x828E
+#define GL_TEXTURE_IMAGE_FORMAT 0x828F
+#define GL_TEXTURE_IMAGE_TYPE 0x8290
+#define GL_GET_TEXTURE_IMAGE_FORMAT 0x8291
+#define GL_GET_TEXTURE_IMAGE_TYPE 0x8292
+#define GL_MIPMAP 0x8293
+#define GL_MANUAL_GENERATE_MIPMAP 0x8294
+#define GL_AUTO_GENERATE_MIPMAP 0x8295
+#define GL_COLOR_ENCODING 0x8296
+#define GL_SRGB_READ 0x8297
+#define GL_SRGB_WRITE 0x8298
+#define GL_FILTER 0x829A
+#define GL_VERTEX_TEXTURE 0x829B
+#define GL_TESS_CONTROL_TEXTURE 0x829C
+#define GL_TESS_EVALUATION_TEXTURE 0x829D
+#define GL_GEOMETRY_TEXTURE 0x829E
+#define GL_FRAGMENT_TEXTURE 0x829F
+#define GL_COMPUTE_TEXTURE 0x82A0
+#define GL_TEXTURE_SHADOW 0x82A1
+#define GL_TEXTURE_GATHER 0x82A2
+#define GL_TEXTURE_GATHER_SHADOW 0x82A3
+#define GL_SHADER_IMAGE_LOAD 0x82A4
+#define GL_SHADER_IMAGE_STORE 0x82A5
+#define GL_SHADER_IMAGE_ATOMIC 0x82A6
+#define GL_IMAGE_TEXEL_SIZE 0x82A7
+#define GL_IMAGE_COMPATIBILITY_CLASS 0x82A8
+#define GL_IMAGE_PIXEL_FORMAT 0x82A9
+#define GL_IMAGE_PIXEL_TYPE 0x82AA
+#define GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST 0x82AC
+#define GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST 0x82AD
+#define GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE 0x82AE
+#define GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE 0x82AF
+#define GL_TEXTURE_COMPRESSED_BLOCK_WIDTH 0x82B1
+#define GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT 0x82B2
+#define GL_TEXTURE_COMPRESSED_BLOCK_SIZE 0x82B3
+#define GL_CLEAR_BUFFER 0x82B4
+#define GL_TEXTURE_VIEW 0x82B5
+#define GL_VIEW_COMPATIBILITY_CLASS 0x82B6
+#define GL_FULL_SUPPORT 0x82B7
+#define GL_CAVEAT_SUPPORT 0x82B8
+#define GL_IMAGE_CLASS_4_X_32 0x82B9
+#define GL_IMAGE_CLASS_2_X_32 0x82BA
+#define GL_IMAGE_CLASS_1_X_32 0x82BB
+#define GL_IMAGE_CLASS_4_X_16 0x82BC
+#define GL_IMAGE_CLASS_2_X_16 0x82BD
+#define GL_IMAGE_CLASS_1_X_16 0x82BE
+#define GL_IMAGE_CLASS_4_X_8 0x82BF
+#define GL_IMAGE_CLASS_2_X_8 0x82C0
+#define GL_IMAGE_CLASS_1_X_8 0x82C1
+#define GL_IMAGE_CLASS_11_11_10 0x82C2
+#define GL_IMAGE_CLASS_10_10_10_2 0x82C3
+#define GL_VIEW_CLASS_128_BITS 0x82C4
+#define GL_VIEW_CLASS_96_BITS 0x82C5
+#define GL_VIEW_CLASS_64_BITS 0x82C6
+#define GL_VIEW_CLASS_48_BITS 0x82C7
+#define GL_VIEW_CLASS_32_BITS 0x82C8
+#define GL_VIEW_CLASS_24_BITS 0x82C9
+#define GL_VIEW_CLASS_16_BITS 0x82CA
+#define GL_VIEW_CLASS_8_BITS 0x82CB
+#define GL_VIEW_CLASS_S3TC_DXT1_RGB 0x82CC
+#define GL_VIEW_CLASS_S3TC_DXT1_RGBA 0x82CD
+#define GL_VIEW_CLASS_S3TC_DXT3_RGBA 0x82CE
+#define GL_VIEW_CLASS_S3TC_DXT5_RGBA 0x82CF
+#define GL_VIEW_CLASS_RGTC1_RED 0x82D0
+#define GL_VIEW_CLASS_RGTC2_RG 0x82D1
+#define GL_VIEW_CLASS_BPTC_UNORM 0x82D2
+#define GL_VIEW_CLASS_BPTC_FLOAT 0x82D3
+#define GL_UNIFORM 0x92E1
+#define GL_UNIFORM_BLOCK 0x92E2
+#define GL_PROGRAM_INPUT 0x92E3
+#define GL_PROGRAM_OUTPUT 0x92E4
+#define GL_BUFFER_VARIABLE 0x92E5
+#define GL_SHADER_STORAGE_BLOCK 0x92E6
+#define GL_VERTEX_SUBROUTINE 0x92E8
+#define GL_TESS_CONTROL_SUBROUTINE 0x92E9
+#define GL_TESS_EVALUATION_SUBROUTINE 0x92EA
+#define GL_GEOMETRY_SUBROUTINE 0x92EB
+#define GL_FRAGMENT_SUBROUTINE 0x92EC
+#define GL_COMPUTE_SUBROUTINE 0x92ED
+#define GL_VERTEX_SUBROUTINE_UNIFORM 0x92EE
+#define GL_TESS_CONTROL_SUBROUTINE_UNIFORM 0x92EF
+#define GL_TESS_EVALUATION_SUBROUTINE_UNIFORM 0x92F0
+#define GL_GEOMETRY_SUBROUTINE_UNIFORM 0x92F1
+#define GL_FRAGMENT_SUBROUTINE_UNIFORM 0x92F2
+#define GL_COMPUTE_SUBROUTINE_UNIFORM 0x92F3
+#define GL_TRANSFORM_FEEDBACK_VARYING 0x92F4
+#define GL_ACTIVE_RESOURCES 0x92F5
+#define GL_MAX_NAME_LENGTH 0x92F6
+#define GL_MAX_NUM_ACTIVE_VARIABLES 0x92F7
+#define GL_MAX_NUM_COMPATIBLE_SUBROUTINES 0x92F8
+#define GL_NAME_LENGTH 0x92F9
+#define GL_TYPE 0x92FA
+#define GL_ARRAY_SIZE 0x92FB
+#define GL_OFFSET 0x92FC
+#define GL_BLOCK_INDEX 0x92FD
+#define GL_ARRAY_STRIDE 0x92FE
+#define GL_MATRIX_STRIDE 0x92FF
+#define GL_IS_ROW_MAJOR 0x9300
+#define GL_ATOMIC_COUNTER_BUFFER_INDEX 0x9301
+#define GL_BUFFER_BINDING 0x9302
+#define GL_BUFFER_DATA_SIZE 0x9303
+#define GL_NUM_ACTIVE_VARIABLES 0x9304
+#define GL_ACTIVE_VARIABLES 0x9305
+#define GL_REFERENCED_BY_VERTEX_SHADER 0x9306
+#define GL_REFERENCED_BY_TESS_CONTROL_SHADER 0x9307
+#define GL_REFERENCED_BY_TESS_EVALUATION_SHADER 0x9308
+#define GL_REFERENCED_BY_GEOMETRY_SHADER 0x9309
+#define GL_REFERENCED_BY_FRAGMENT_SHADER 0x930A
+#define GL_REFERENCED_BY_COMPUTE_SHADER 0x930B
+#define GL_TOP_LEVEL_ARRAY_SIZE 0x930C
+#define GL_TOP_LEVEL_ARRAY_STRIDE 0x930D
+#define GL_LOCATION 0x930E
+#define GL_LOCATION_INDEX 0x930F
+#define GL_IS_PER_PATCH 0x92E7
+#define GL_SHADER_STORAGE_BUFFER 0x90D2
+#define GL_SHADER_STORAGE_BUFFER_BINDING 0x90D3
+#define GL_SHADER_STORAGE_BUFFER_START 0x90D4
+#define GL_SHADER_STORAGE_BUFFER_SIZE 0x90D5
+#define GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS 0x90D6
+#define GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS 0x90D7
+#define GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS 0x90D8
+#define GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS 0x90D9
+#define GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS 0x90DA
+#define GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS 0x90DB
+#define GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS 0x90DC
+#define GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS 0x90DD
+#define GL_MAX_SHADER_STORAGE_BLOCK_SIZE 0x90DE
+#define GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT 0x90DF
+#define GL_SHADER_STORAGE_BARRIER_BIT 0x00002000
+#define GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES 0x8F39
+#define GL_DEPTH_STENCIL_TEXTURE_MODE 0x90EA
+#define GL_TEXTURE_BUFFER_OFFSET 0x919D
+#define GL_TEXTURE_BUFFER_SIZE 0x919E
+#define GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT 0x919F
+#define GL_TEXTURE_VIEW_MIN_LEVEL 0x82DB
+#define GL_TEXTURE_VIEW_NUM_LEVELS 0x82DC
+#define GL_TEXTURE_VIEW_MIN_LAYER 0x82DD
+#define GL_TEXTURE_VIEW_NUM_LAYERS 0x82DE
+#define GL_TEXTURE_IMMUTABLE_LEVELS 0x82DF
+#define GL_VERTEX_ATTRIB_BINDING 0x82D4
+#define GL_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D5
+#define GL_VERTEX_BINDING_DIVISOR 0x82D6
+#define GL_VERTEX_BINDING_OFFSET 0x82D7
+#define GL_VERTEX_BINDING_STRIDE 0x82D8
+#define GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D9
+#define GL_MAX_VERTEX_ATTRIB_BINDINGS 0x82DA
+#define GL_VERTEX_BINDING_BUFFER 0x8F4F
+#define GL_DISPLAY_LIST 0x82E7
+typedef void (APIENTRYP PFNGLCLEARBUFFERDATAPROC) (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void *data);
+typedef void (APIENTRYP PFNGLCLEARBUFFERSUBDATAPROC) (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data);
+typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEPROC) (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z);
+typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEINDIRECTPROC) (GLintptr indirect);
+typedef void (APIENTRYP PFNGLCOPYIMAGESUBDATAPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETINTERNALFORMATI64VPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64 *params);
+typedef void (APIENTRYP PFNGLINVALIDATETEXSUBIMAGEPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth);
+typedef void (APIENTRYP PFNGLINVALIDATETEXIMAGEPROC) (GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLINVALIDATEBUFFERSUBDATAPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length);
+typedef void (APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC) (GLuint buffer);
+typedef void (APIENTRYP PFNGLINVALIDATEFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments);
+typedef void (APIENTRYP PFNGLINVALIDATESUBFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTPROC) (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride);
+typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride);
+typedef void (APIENTRYP PFNGLGETPROGRAMINTERFACEIVPROC) (GLuint program, GLenum programInterface, GLenum pname, GLint *params);
+typedef GLuint (APIENTRYP PFNGLGETPROGRAMRESOURCEINDEXPROC) (GLuint program, GLenum programInterface, const GLchar *name);
+typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCENAMEPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name);
+typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCEIVPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLint *params);
+typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONPROC) (GLuint program, GLenum programInterface, const GLchar *name);
+typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONINDEXPROC) (GLuint program, GLenum programInterface, const GLchar *name);
+typedef void (APIENTRYP PFNGLSHADERSTORAGEBLOCKBINDINGPROC) (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding);
+typedef void (APIENTRYP PFNGLTEXBUFFERRANGEPROC) (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size);
+typedef void (APIENTRYP PFNGLTEXSTORAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
+typedef void (APIENTRYP PFNGLTEXSTORAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations);
+typedef void (APIENTRYP PFNGLTEXTUREVIEWPROC) (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers);
+typedef void (APIENTRYP PFNGLBINDVERTEXBUFFERPROC) (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBIFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBLFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBBINDINGPROC) (GLuint attribindex, GLuint bindingindex);
+typedef void (APIENTRYP PFNGLVERTEXBINDINGDIVISORPROC) (GLuint bindingindex, GLuint divisor);
+typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
+typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf);
+typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKPROC) (GLDEBUGPROC callback, const void *userParam);
+typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGPROC) (GLuint count, GLsizei bufSize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog);
+typedef void (APIENTRYP PFNGLPUSHDEBUGGROUPPROC) (GLenum source, GLuint id, GLsizei length, const GLchar *message);
+typedef void (APIENTRYP PFNGLPOPDEBUGGROUPPROC) (void);
+typedef void (APIENTRYP PFNGLOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei length, const GLchar *label);
+typedef void (APIENTRYP PFNGLGETOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label);
+typedef void (APIENTRYP PFNGLOBJECTPTRLABELPROC) (const void *ptr, GLsizei length, const GLchar *label);
+typedef void (APIENTRYP PFNGLGETOBJECTPTRLABELPROC) (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glClearBufferData (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void *data);
+GLAPI void APIENTRY glClearBufferSubData (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data);
+GLAPI void APIENTRY glDispatchCompute (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z);
+GLAPI void APIENTRY glDispatchComputeIndirect (GLintptr indirect);
+GLAPI void APIENTRY glCopyImageSubData (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth);
+GLAPI void APIENTRY glFramebufferParameteri (GLenum target, GLenum pname, GLint param);
+GLAPI void APIENTRY glGetFramebufferParameteriv (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetInternalformati64v (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64 *params);
+GLAPI void APIENTRY glInvalidateTexSubImage (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth);
+GLAPI void APIENTRY glInvalidateTexImage (GLuint texture, GLint level);
+GLAPI void APIENTRY glInvalidateBufferSubData (GLuint buffer, GLintptr offset, GLsizeiptr length);
+GLAPI void APIENTRY glInvalidateBufferData (GLuint buffer);
+GLAPI void APIENTRY glInvalidateFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments);
+GLAPI void APIENTRY glInvalidateSubFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glMultiDrawArraysIndirect (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride);
+GLAPI void APIENTRY glMultiDrawElementsIndirect (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride);
+GLAPI void APIENTRY glGetProgramInterfaceiv (GLuint program, GLenum programInterface, GLenum pname, GLint *params);
+GLAPI GLuint APIENTRY glGetProgramResourceIndex (GLuint program, GLenum programInterface, const GLchar *name);
+GLAPI void APIENTRY glGetProgramResourceName (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name);
+GLAPI void APIENTRY glGetProgramResourceiv (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLint *params);
+GLAPI GLint APIENTRY glGetProgramResourceLocation (GLuint program, GLenum programInterface, const GLchar *name);
+GLAPI GLint APIENTRY glGetProgramResourceLocationIndex (GLuint program, GLenum programInterface, const GLchar *name);
+GLAPI void APIENTRY glShaderStorageBlockBinding (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding);
+GLAPI void APIENTRY glTexBufferRange (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size);
+GLAPI void APIENTRY glTexStorage2DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
+GLAPI void APIENTRY glTexStorage3DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations);
+GLAPI void APIENTRY glTextureView (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers);
+GLAPI void APIENTRY glBindVertexBuffer (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride);
+GLAPI void APIENTRY glVertexAttribFormat (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset);
+GLAPI void APIENTRY glVertexAttribIFormat (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
+GLAPI void APIENTRY glVertexAttribLFormat (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
+GLAPI void APIENTRY glVertexAttribBinding (GLuint attribindex, GLuint bindingindex);
+GLAPI void APIENTRY glVertexBindingDivisor (GLuint bindingindex, GLuint divisor);
+GLAPI void APIENTRY glDebugMessageControl (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
+GLAPI void APIENTRY glDebugMessageInsert (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf);
+GLAPI void APIENTRY glDebugMessageCallback (GLDEBUGPROC callback, const void *userParam);
+GLAPI GLuint APIENTRY glGetDebugMessageLog (GLuint count, GLsizei bufSize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog);
+GLAPI void APIENTRY glPushDebugGroup (GLenum source, GLuint id, GLsizei length, const GLchar *message);
+GLAPI void APIENTRY glPopDebugGroup (void);
+GLAPI void APIENTRY glObjectLabel (GLenum identifier, GLuint name, GLsizei length, const GLchar *label);
+GLAPI void APIENTRY glGetObjectLabel (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label);
+GLAPI void APIENTRY glObjectPtrLabel (const void *ptr, GLsizei length, const GLchar *label);
+GLAPI void APIENTRY glGetObjectPtrLabel (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label);
+#endif
+#endif /* GL_VERSION_4_3 */
+
+#ifndef GL_VERSION_4_4
+#define GL_VERSION_4_4 1
+#define GL_MAX_VERTEX_ATTRIB_STRIDE 0x82E5
+#define GL_PRIMITIVE_RESTART_FOR_PATCHES_SUPPORTED 0x8221
+#define GL_TEXTURE_BUFFER_BINDING 0x8C2A
+#define GL_MAP_PERSISTENT_BIT 0x0040
+#define GL_MAP_COHERENT_BIT 0x0080
+#define GL_DYNAMIC_STORAGE_BIT 0x0100
+#define GL_CLIENT_STORAGE_BIT 0x0200
+#define GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT 0x00004000
+#define GL_BUFFER_IMMUTABLE_STORAGE 0x821F
+#define GL_BUFFER_STORAGE_FLAGS 0x8220
+#define GL_CLEAR_TEXTURE 0x9365
+#define GL_LOCATION_COMPONENT 0x934A
+#define GL_TRANSFORM_FEEDBACK_BUFFER_INDEX 0x934B
+#define GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE 0x934C
+#define GL_QUERY_BUFFER 0x9192
+#define GL_QUERY_BUFFER_BARRIER_BIT 0x00008000
+#define GL_QUERY_BUFFER_BINDING 0x9193
+#define GL_QUERY_RESULT_NO_WAIT 0x9194
+#define GL_MIRROR_CLAMP_TO_EDGE 0x8743
+typedef void (APIENTRYP PFNGLBUFFERSTORAGEPROC) (GLenum target, GLsizeiptr size, const void *data, GLbitfield flags);
+typedef void (APIENTRYP PFNGLCLEARTEXIMAGEPROC) (GLuint texture, GLint level, GLenum format, GLenum type, const void *data);
+typedef void (APIENTRYP PFNGLCLEARTEXSUBIMAGEPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *data);
+typedef void (APIENTRYP PFNGLBINDBUFFERSBASEPROC) (GLenum target, GLuint first, GLsizei count, const GLuint *buffers);
+typedef void (APIENTRYP PFNGLBINDBUFFERSRANGEPROC) (GLenum target, GLuint first, GLsizei count, const GLuint *buffers, const GLintptr *offsets, const GLsizeiptr *sizes);
+typedef void (APIENTRYP PFNGLBINDTEXTURESPROC) (GLuint first, GLsizei count, const GLuint *textures);
+typedef void (APIENTRYP PFNGLBINDSAMPLERSPROC) (GLuint first, GLsizei count, const GLuint *samplers);
+typedef void (APIENTRYP PFNGLBINDIMAGETEXTURESPROC) (GLuint first, GLsizei count, const GLuint *textures);
+typedef void (APIENTRYP PFNGLBINDVERTEXBUFFERSPROC) (GLuint first, GLsizei count, const GLuint *buffers, const GLintptr *offsets, const GLsizei *strides);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBufferStorage (GLenum target, GLsizeiptr size, const void *data, GLbitfield flags);
+GLAPI void APIENTRY glClearTexImage (GLuint texture, GLint level, GLenum format, GLenum type, const void *data);
+GLAPI void APIENTRY glClearTexSubImage (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *data);
+GLAPI void APIENTRY glBindBuffersBase (GLenum target, GLuint first, GLsizei count, const GLuint *buffers);
+GLAPI void APIENTRY glBindBuffersRange (GLenum target, GLuint first, GLsizei count, const GLuint *buffers, const GLintptr *offsets, const GLsizeiptr *sizes);
+GLAPI void APIENTRY glBindTextures (GLuint first, GLsizei count, const GLuint *textures);
+GLAPI void APIENTRY glBindSamplers (GLuint first, GLsizei count, const GLuint *samplers);
+GLAPI void APIENTRY glBindImageTextures (GLuint first, GLsizei count, const GLuint *textures);
+GLAPI void APIENTRY glBindVertexBuffers (GLuint first, GLsizei count, const GLuint *buffers, const GLintptr *offsets, const GLsizei *strides);
+#endif
+#endif /* GL_VERSION_4_4 */
+
+#ifndef GL_ARB_ES2_compatibility
+#define GL_ARB_ES2_compatibility 1
+#endif /* GL_ARB_ES2_compatibility */
+
+#ifndef GL_ARB_ES3_compatibility
+#define GL_ARB_ES3_compatibility 1
+#endif /* GL_ARB_ES3_compatibility */
+
+#ifndef GL_ARB_arrays_of_arrays
+#define GL_ARB_arrays_of_arrays 1
+#endif /* GL_ARB_arrays_of_arrays */
+
+#ifndef GL_ARB_base_instance
+#define GL_ARB_base_instance 1
+#endif /* GL_ARB_base_instance */
+
+#ifndef GL_ARB_bindless_texture
+#define GL_ARB_bindless_texture 1
+typedef uint64_t GLuint64EXT;
+#define GL_UNSIGNED_INT64_ARB 0x140F
+typedef GLuint64 (APIENTRYP PFNGLGETTEXTUREHANDLEARBPROC) (GLuint texture);
+typedef GLuint64 (APIENTRYP PFNGLGETTEXTURESAMPLERHANDLEARBPROC) (GLuint texture, GLuint sampler);
+typedef void (APIENTRYP PFNGLMAKETEXTUREHANDLERESIDENTARBPROC) (GLuint64 handle);
+typedef void (APIENTRYP PFNGLMAKETEXTUREHANDLENONRESIDENTARBPROC) (GLuint64 handle);
+typedef GLuint64 (APIENTRYP PFNGLGETIMAGEHANDLEARBPROC) (GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format);
+typedef void (APIENTRYP PFNGLMAKEIMAGEHANDLERESIDENTARBPROC) (GLuint64 handle, GLenum access);
+typedef void (APIENTRYP PFNGLMAKEIMAGEHANDLENONRESIDENTARBPROC) (GLuint64 handle);
+typedef void (APIENTRYP PFNGLUNIFORMHANDLEUI64ARBPROC) (GLint location, GLuint64 value);
+typedef void (APIENTRYP PFNGLUNIFORMHANDLEUI64VARBPROC) (GLint location, GLsizei count, const GLuint64 *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64ARBPROC) (GLuint program, GLint location, GLuint64 value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64VARBPROC) (GLuint program, GLint location, GLsizei count, const GLuint64 *values);
+typedef GLboolean (APIENTRYP PFNGLISTEXTUREHANDLERESIDENTARBPROC) (GLuint64 handle);
+typedef GLboolean (APIENTRYP PFNGLISIMAGEHANDLERESIDENTARBPROC) (GLuint64 handle);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64ARBPROC) (GLuint index, GLuint64EXT x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64VARBPROC) (GLuint index, const GLuint64EXT *v);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLUI64VARBPROC) (GLuint index, GLenum pname, GLuint64EXT *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLuint64 APIENTRY glGetTextureHandleARB (GLuint texture);
+GLAPI GLuint64 APIENTRY glGetTextureSamplerHandleARB (GLuint texture, GLuint sampler);
+GLAPI void APIENTRY glMakeTextureHandleResidentARB (GLuint64 handle);
+GLAPI void APIENTRY glMakeTextureHandleNonResidentARB (GLuint64 handle);
+GLAPI GLuint64 APIENTRY glGetImageHandleARB (GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format);
+GLAPI void APIENTRY glMakeImageHandleResidentARB (GLuint64 handle, GLenum access);
+GLAPI void APIENTRY glMakeImageHandleNonResidentARB (GLuint64 handle);
+GLAPI void APIENTRY glUniformHandleui64ARB (GLint location, GLuint64 value);
+GLAPI void APIENTRY glUniformHandleui64vARB (GLint location, GLsizei count, const GLuint64 *value);
+GLAPI void APIENTRY glProgramUniformHandleui64ARB (GLuint program, GLint location, GLuint64 value);
+GLAPI void APIENTRY glProgramUniformHandleui64vARB (GLuint program, GLint location, GLsizei count, const GLuint64 *values);
+GLAPI GLboolean APIENTRY glIsTextureHandleResidentARB (GLuint64 handle);
+GLAPI GLboolean APIENTRY glIsImageHandleResidentARB (GLuint64 handle);
+GLAPI void APIENTRY glVertexAttribL1ui64ARB (GLuint index, GLuint64EXT x);
+GLAPI void APIENTRY glVertexAttribL1ui64vARB (GLuint index, const GLuint64EXT *v);
+GLAPI void APIENTRY glGetVertexAttribLui64vARB (GLuint index, GLenum pname, GLuint64EXT *params);
+#endif
+#endif /* GL_ARB_bindless_texture */
+
+#ifndef GL_ARB_blend_func_extended
+#define GL_ARB_blend_func_extended 1
+#endif /* GL_ARB_blend_func_extended */
+
+#ifndef GL_ARB_buffer_storage
+#define GL_ARB_buffer_storage 1
+#endif /* GL_ARB_buffer_storage */
+
+#ifndef GL_ARB_cl_event
+#define GL_ARB_cl_event 1
+struct _cl_context;
+struct _cl_event;
+#define GL_SYNC_CL_EVENT_ARB 0x8240
+#define GL_SYNC_CL_EVENT_COMPLETE_ARB 0x8241
+typedef GLsync (APIENTRYP PFNGLCREATESYNCFROMCLEVENTARBPROC) (struct _cl_context *context, struct _cl_event *event, GLbitfield flags);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLsync APIENTRY glCreateSyncFromCLeventARB (struct _cl_context *context, struct _cl_event *event, GLbitfield flags);
+#endif
+#endif /* GL_ARB_cl_event */
+
+#ifndef GL_ARB_clear_buffer_object
+#define GL_ARB_clear_buffer_object 1
+#endif /* GL_ARB_clear_buffer_object */
+
+#ifndef GL_ARB_clear_texture
+#define GL_ARB_clear_texture 1
+#endif /* GL_ARB_clear_texture */
+
+#ifndef GL_ARB_color_buffer_float
+#define GL_ARB_color_buffer_float 1
+#define GL_RGBA_FLOAT_MODE_ARB 0x8820
+#define GL_CLAMP_VERTEX_COLOR_ARB 0x891A
+#define GL_CLAMP_FRAGMENT_COLOR_ARB 0x891B
+#define GL_CLAMP_READ_COLOR_ARB 0x891C
+#define GL_FIXED_ONLY_ARB 0x891D
+typedef void (APIENTRYP PFNGLCLAMPCOLORARBPROC) (GLenum target, GLenum clamp);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glClampColorARB (GLenum target, GLenum clamp);
+#endif
+#endif /* GL_ARB_color_buffer_float */
+
+#ifndef GL_ARB_compatibility
+#define GL_ARB_compatibility 1
+#endif /* GL_ARB_compatibility */
+
+#ifndef GL_ARB_compressed_texture_pixel_storage
+#define GL_ARB_compressed_texture_pixel_storage 1
+#endif /* GL_ARB_compressed_texture_pixel_storage */
+
+#ifndef GL_ARB_compute_shader
+#define GL_ARB_compute_shader 1
+#define GL_COMPUTE_SHADER_BIT 0x00000020
+#endif /* GL_ARB_compute_shader */
+
+#ifndef GL_ARB_compute_variable_group_size
+#define GL_ARB_compute_variable_group_size 1
+#define GL_MAX_COMPUTE_VARIABLE_GROUP_INVOCATIONS_ARB 0x9344
+#define GL_MAX_COMPUTE_FIXED_GROUP_INVOCATIONS_ARB 0x90EB
+#define GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB 0x9345
+#define GL_MAX_COMPUTE_FIXED_GROUP_SIZE_ARB 0x91BF
+typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEGROUPSIZEARBPROC) (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z, GLuint group_size_x, GLuint group_size_y, GLuint group_size_z);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDispatchComputeGroupSizeARB (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z, GLuint group_size_x, GLuint group_size_y, GLuint group_size_z);
+#endif
+#endif /* GL_ARB_compute_variable_group_size */
+
+#ifndef GL_ARB_conservative_depth
+#define GL_ARB_conservative_depth 1
+#endif /* GL_ARB_conservative_depth */
+
+#ifndef GL_ARB_copy_buffer
+#define GL_ARB_copy_buffer 1
+#define GL_COPY_READ_BUFFER_BINDING 0x8F36
+#define GL_COPY_WRITE_BUFFER_BINDING 0x8F37
+#endif /* GL_ARB_copy_buffer */
+
+#ifndef GL_ARB_copy_image
+#define GL_ARB_copy_image 1
+#endif /* GL_ARB_copy_image */
+
+#ifndef GL_ARB_debug_output
+#define GL_ARB_debug_output 1
+typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
+#define GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB 0x8242
+#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_ARB 0x8243
+#define GL_DEBUG_CALLBACK_FUNCTION_ARB 0x8244
+#define GL_DEBUG_CALLBACK_USER_PARAM_ARB 0x8245
+#define GL_DEBUG_SOURCE_API_ARB 0x8246
+#define GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB 0x8247
+#define GL_DEBUG_SOURCE_SHADER_COMPILER_ARB 0x8248
+#define GL_DEBUG_SOURCE_THIRD_PARTY_ARB 0x8249
+#define GL_DEBUG_SOURCE_APPLICATION_ARB 0x824A
+#define GL_DEBUG_SOURCE_OTHER_ARB 0x824B
+#define GL_DEBUG_TYPE_ERROR_ARB 0x824C
+#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB 0x824D
+#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB 0x824E
+#define GL_DEBUG_TYPE_PORTABILITY_ARB 0x824F
+#define GL_DEBUG_TYPE_PERFORMANCE_ARB 0x8250
+#define GL_DEBUG_TYPE_OTHER_ARB 0x8251
+#define GL_MAX_DEBUG_MESSAGE_LENGTH_ARB 0x9143
+#define GL_MAX_DEBUG_LOGGED_MESSAGES_ARB 0x9144
+#define GL_DEBUG_LOGGED_MESSAGES_ARB 0x9145
+#define GL_DEBUG_SEVERITY_HIGH_ARB 0x9146
+#define GL_DEBUG_SEVERITY_MEDIUM_ARB 0x9147
+#define GL_DEBUG_SEVERITY_LOW_ARB 0x9148
+typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLARBPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
+typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTARBPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf);
+typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKARBPROC) (GLDEBUGPROCARB callback, const void *userParam);
+typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGARBPROC) (GLuint count, GLsizei bufSize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDebugMessageControlARB (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
+GLAPI void APIENTRY glDebugMessageInsertARB (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf);
+GLAPI void APIENTRY glDebugMessageCallbackARB (GLDEBUGPROCARB callback, const void *userParam);
+GLAPI GLuint APIENTRY glGetDebugMessageLogARB (GLuint count, GLsizei bufSize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog);
+#endif
+#endif /* GL_ARB_debug_output */
+
+#ifndef GL_ARB_depth_buffer_float
+#define GL_ARB_depth_buffer_float 1
+#endif /* GL_ARB_depth_buffer_float */
+
+#ifndef GL_ARB_depth_clamp
+#define GL_ARB_depth_clamp 1
+#endif /* GL_ARB_depth_clamp */
+
+#ifndef GL_ARB_depth_texture
+#define GL_ARB_depth_texture 1
+#define GL_DEPTH_COMPONENT16_ARB 0x81A5
+#define GL_DEPTH_COMPONENT24_ARB 0x81A6
+#define GL_DEPTH_COMPONENT32_ARB 0x81A7
+#define GL_TEXTURE_DEPTH_SIZE_ARB 0x884A
+#define GL_DEPTH_TEXTURE_MODE_ARB 0x884B
+#endif /* GL_ARB_depth_texture */
+
+#ifndef GL_ARB_draw_buffers
+#define GL_ARB_draw_buffers 1
+#define GL_MAX_DRAW_BUFFERS_ARB 0x8824
+#define GL_DRAW_BUFFER0_ARB 0x8825
+#define GL_DRAW_BUFFER1_ARB 0x8826
+#define GL_DRAW_BUFFER2_ARB 0x8827
+#define GL_DRAW_BUFFER3_ARB 0x8828
+#define GL_DRAW_BUFFER4_ARB 0x8829
+#define GL_DRAW_BUFFER5_ARB 0x882A
+#define GL_DRAW_BUFFER6_ARB 0x882B
+#define GL_DRAW_BUFFER7_ARB 0x882C
+#define GL_DRAW_BUFFER8_ARB 0x882D
+#define GL_DRAW_BUFFER9_ARB 0x882E
+#define GL_DRAW_BUFFER10_ARB 0x882F
+#define GL_DRAW_BUFFER11_ARB 0x8830
+#define GL_DRAW_BUFFER12_ARB 0x8831
+#define GL_DRAW_BUFFER13_ARB 0x8832
+#define GL_DRAW_BUFFER14_ARB 0x8833
+#define GL_DRAW_BUFFER15_ARB 0x8834
+typedef void (APIENTRYP PFNGLDRAWBUFFERSARBPROC) (GLsizei n, const GLenum *bufs);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawBuffersARB (GLsizei n, const GLenum *bufs);
+#endif
+#endif /* GL_ARB_draw_buffers */
+
+#ifndef GL_ARB_draw_buffers_blend
+#define GL_ARB_draw_buffers_blend 1
+typedef void (APIENTRYP PFNGLBLENDEQUATIONIARBPROC) (GLuint buf, GLenum mode);
+typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIARBPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha);
+typedef void (APIENTRYP PFNGLBLENDFUNCIARBPROC) (GLuint buf, GLenum src, GLenum dst);
+typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIARBPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendEquationiARB (GLuint buf, GLenum mode);
+GLAPI void APIENTRY glBlendEquationSeparateiARB (GLuint buf, GLenum modeRGB, GLenum modeAlpha);
+GLAPI void APIENTRY glBlendFunciARB (GLuint buf, GLenum src, GLenum dst);
+GLAPI void APIENTRY glBlendFuncSeparateiARB (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+#endif
+#endif /* GL_ARB_draw_buffers_blend */
+
+#ifndef GL_ARB_draw_elements_base_vertex
+#define GL_ARB_draw_elements_base_vertex 1
+#endif /* GL_ARB_draw_elements_base_vertex */
+
+#ifndef GL_ARB_draw_indirect
+#define GL_ARB_draw_indirect 1
+#endif /* GL_ARB_draw_indirect */
+
+#ifndef GL_ARB_draw_instanced
+#define GL_ARB_draw_instanced 1
+typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDARBPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount);
+typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDARBPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawArraysInstancedARB (GLenum mode, GLint first, GLsizei count, GLsizei primcount);
+GLAPI void APIENTRY glDrawElementsInstancedARB (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
+#endif
+#endif /* GL_ARB_draw_instanced */
+
+#ifndef GL_ARB_enhanced_layouts
+#define GL_ARB_enhanced_layouts 1
+#endif /* GL_ARB_enhanced_layouts */
+
+#ifndef GL_ARB_explicit_attrib_location
+#define GL_ARB_explicit_attrib_location 1
+#endif /* GL_ARB_explicit_attrib_location */
+
+#ifndef GL_ARB_explicit_uniform_location
+#define GL_ARB_explicit_uniform_location 1
+#endif /* GL_ARB_explicit_uniform_location */
+
+#ifndef GL_ARB_fragment_coord_conventions
+#define GL_ARB_fragment_coord_conventions 1
+#endif /* GL_ARB_fragment_coord_conventions */
+
+#ifndef GL_ARB_fragment_layer_viewport
+#define GL_ARB_fragment_layer_viewport 1
+#endif /* GL_ARB_fragment_layer_viewport */
+
+#ifndef GL_ARB_fragment_program
+#define GL_ARB_fragment_program 1
+#define GL_FRAGMENT_PROGRAM_ARB 0x8804
+#define GL_PROGRAM_FORMAT_ASCII_ARB 0x8875
+#define GL_PROGRAM_LENGTH_ARB 0x8627
+#define GL_PROGRAM_FORMAT_ARB 0x8876
+#define GL_PROGRAM_BINDING_ARB 0x8677
+#define GL_PROGRAM_INSTRUCTIONS_ARB 0x88A0
+#define GL_MAX_PROGRAM_INSTRUCTIONS_ARB 0x88A1
+#define GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A2
+#define GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A3
+#define GL_PROGRAM_TEMPORARIES_ARB 0x88A4
+#define GL_MAX_PROGRAM_TEMPORARIES_ARB 0x88A5
+#define GL_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A6
+#define GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A7
+#define GL_PROGRAM_PARAMETERS_ARB 0x88A8
+#define GL_MAX_PROGRAM_PARAMETERS_ARB 0x88A9
+#define GL_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AA
+#define GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AB
+#define GL_PROGRAM_ATTRIBS_ARB 0x88AC
+#define GL_MAX_PROGRAM_ATTRIBS_ARB 0x88AD
+#define GL_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AE
+#define GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AF
+#define GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB 0x88B4
+#define GL_MAX_PROGRAM_ENV_PARAMETERS_ARB 0x88B5
+#define GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB 0x88B6
+#define GL_PROGRAM_ALU_INSTRUCTIONS_ARB 0x8805
+#define GL_PROGRAM_TEX_INSTRUCTIONS_ARB 0x8806
+#define GL_PROGRAM_TEX_INDIRECTIONS_ARB 0x8807
+#define GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x8808
+#define GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x8809
+#define GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x880A
+#define GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB 0x880B
+#define GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB 0x880C
+#define GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB 0x880D
+#define GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x880E
+#define GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x880F
+#define GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x8810
+#define GL_PROGRAM_STRING_ARB 0x8628
+#define GL_PROGRAM_ERROR_POSITION_ARB 0x864B
+#define GL_CURRENT_MATRIX_ARB 0x8641
+#define GL_TRANSPOSE_CURRENT_MATRIX_ARB 0x88B7
+#define GL_CURRENT_MATRIX_STACK_DEPTH_ARB 0x8640
+#define GL_MAX_PROGRAM_MATRICES_ARB 0x862F
+#define GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB 0x862E
+#define GL_MAX_TEXTURE_COORDS_ARB 0x8871
+#define GL_MAX_TEXTURE_IMAGE_UNITS_ARB 0x8872
+#define GL_PROGRAM_ERROR_STRING_ARB 0x8874
+#define GL_MATRIX0_ARB 0x88C0
+#define GL_MATRIX1_ARB 0x88C1
+#define GL_MATRIX2_ARB 0x88C2
+#define GL_MATRIX3_ARB 0x88C3
+#define GL_MATRIX4_ARB 0x88C4
+#define GL_MATRIX5_ARB 0x88C5
+#define GL_MATRIX6_ARB 0x88C6
+#define GL_MATRIX7_ARB 0x88C7
+#define GL_MATRIX8_ARB 0x88C8
+#define GL_MATRIX9_ARB 0x88C9
+#define GL_MATRIX10_ARB 0x88CA
+#define GL_MATRIX11_ARB 0x88CB
+#define GL_MATRIX12_ARB 0x88CC
+#define GL_MATRIX13_ARB 0x88CD
+#define GL_MATRIX14_ARB 0x88CE
+#define GL_MATRIX15_ARB 0x88CF
+#define GL_MATRIX16_ARB 0x88D0
+#define GL_MATRIX17_ARB 0x88D1
+#define GL_MATRIX18_ARB 0x88D2
+#define GL_MATRIX19_ARB 0x88D3
+#define GL_MATRIX20_ARB 0x88D4
+#define GL_MATRIX21_ARB 0x88D5
+#define GL_MATRIX22_ARB 0x88D6
+#define GL_MATRIX23_ARB 0x88D7
+#define GL_MATRIX24_ARB 0x88D8
+#define GL_MATRIX25_ARB 0x88D9
+#define GL_MATRIX26_ARB 0x88DA
+#define GL_MATRIX27_ARB 0x88DB
+#define GL_MATRIX28_ARB 0x88DC
+#define GL_MATRIX29_ARB 0x88DD
+#define GL_MATRIX30_ARB 0x88DE
+#define GL_MATRIX31_ARB 0x88DF
+typedef void (APIENTRYP PFNGLPROGRAMSTRINGARBPROC) (GLenum target, GLenum format, GLsizei len, const void *string);
+typedef void (APIENTRYP PFNGLBINDPROGRAMARBPROC) (GLenum target, GLuint program);
+typedef void (APIENTRYP PFNGLDELETEPROGRAMSARBPROC) (GLsizei n, const GLuint *programs);
+typedef void (APIENTRYP PFNGLGENPROGRAMSARBPROC) (GLsizei n, GLuint *programs);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGARBPROC) (GLenum target, GLenum pname, void *string);
+typedef GLboolean (APIENTRYP PFNGLISPROGRAMARBPROC) (GLuint program);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProgramStringARB (GLenum target, GLenum format, GLsizei len, const void *string);
+GLAPI void APIENTRY glBindProgramARB (GLenum target, GLuint program);
+GLAPI void APIENTRY glDeleteProgramsARB (GLsizei n, const GLuint *programs);
+GLAPI void APIENTRY glGenProgramsARB (GLsizei n, GLuint *programs);
+GLAPI void APIENTRY glProgramEnvParameter4dARB (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glProgramEnvParameter4dvARB (GLenum target, GLuint index, const GLdouble *params);
+GLAPI void APIENTRY glProgramEnvParameter4fARB (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glProgramEnvParameter4fvARB (GLenum target, GLuint index, const GLfloat *params);
+GLAPI void APIENTRY glProgramLocalParameter4dARB (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glProgramLocalParameter4dvARB (GLenum target, GLuint index, const GLdouble *params);
+GLAPI void APIENTRY glProgramLocalParameter4fARB (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glProgramLocalParameter4fvARB (GLenum target, GLuint index, const GLfloat *params);
+GLAPI void APIENTRY glGetProgramEnvParameterdvARB (GLenum target, GLuint index, GLdouble *params);
+GLAPI void APIENTRY glGetProgramEnvParameterfvARB (GLenum target, GLuint index, GLfloat *params);
+GLAPI void APIENTRY glGetProgramLocalParameterdvARB (GLenum target, GLuint index, GLdouble *params);
+GLAPI void APIENTRY glGetProgramLocalParameterfvARB (GLenum target, GLuint index, GLfloat *params);
+GLAPI void APIENTRY glGetProgramivARB (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetProgramStringARB (GLenum target, GLenum pname, void *string);
+GLAPI GLboolean APIENTRY glIsProgramARB (GLuint program);
+#endif
+#endif /* GL_ARB_fragment_program */
+
+#ifndef GL_ARB_fragment_program_shadow
+#define GL_ARB_fragment_program_shadow 1
+#endif /* GL_ARB_fragment_program_shadow */
+
+#ifndef GL_ARB_fragment_shader
+#define GL_ARB_fragment_shader 1
+#define GL_FRAGMENT_SHADER_ARB 0x8B30
+#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB 0x8B49
+#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB 0x8B8B
+#endif /* GL_ARB_fragment_shader */
+
+#ifndef GL_ARB_framebuffer_no_attachments
+#define GL_ARB_framebuffer_no_attachments 1
+#endif /* GL_ARB_framebuffer_no_attachments */
+
+#ifndef GL_ARB_framebuffer_object
+#define GL_ARB_framebuffer_object 1
+#endif /* GL_ARB_framebuffer_object */
+
+#ifndef GL_ARB_framebuffer_sRGB
+#define GL_ARB_framebuffer_sRGB 1
+#endif /* GL_ARB_framebuffer_sRGB */
+
+#ifndef GL_KHR_context_flush_control
+#define GL_CONTEXT_RELEASE_BEHAVIOR 0x82FB
+#define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH 0x82FC
+#endif /* GL_KHR_context_flush_control */
+
+#ifndef GL_ARB_geometry_shader4
+#define GL_ARB_geometry_shader4 1
+#define GL_LINES_ADJACENCY_ARB 0x000A
+#define GL_LINE_STRIP_ADJACENCY_ARB 0x000B
+#define GL_TRIANGLES_ADJACENCY_ARB 0x000C
+#define GL_TRIANGLE_STRIP_ADJACENCY_ARB 0x000D
+#define GL_PROGRAM_POINT_SIZE_ARB 0x8642
+#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_ARB 0x8C29
+#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED_ARB 0x8DA7
+#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_ARB 0x8DA8
+#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB 0x8DA9
+#define GL_GEOMETRY_SHADER_ARB 0x8DD9
+#define GL_GEOMETRY_VERTICES_OUT_ARB 0x8DDA
+#define GL_GEOMETRY_INPUT_TYPE_ARB 0x8DDB
+#define GL_GEOMETRY_OUTPUT_TYPE_ARB 0x8DDC
+#define GL_MAX_GEOMETRY_VARYING_COMPONENTS_ARB 0x8DDD
+#define GL_MAX_VERTEX_VARYING_COMPONENTS_ARB 0x8DDE
+#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_ARB 0x8DDF
+#define GL_MAX_GEOMETRY_OUTPUT_VERTICES_ARB 0x8DE0
+#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_ARB 0x8DE1
+typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIARBPROC) (GLuint program, GLenum pname, GLint value);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREFACEARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProgramParameteriARB (GLuint program, GLenum pname, GLint value);
+GLAPI void APIENTRY glFramebufferTextureARB (GLenum target, GLenum attachment, GLuint texture, GLint level);
+GLAPI void APIENTRY glFramebufferTextureLayerARB (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer);
+GLAPI void APIENTRY glFramebufferTextureFaceARB (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face);
+#endif
+#endif /* GL_ARB_geometry_shader4 */
+
+#ifndef GL_ARB_get_program_binary
+#define GL_ARB_get_program_binary 1
+#endif /* GL_ARB_get_program_binary */
+
+#ifndef GL_ARB_gpu_shader5
+#define GL_ARB_gpu_shader5 1
+#endif /* GL_ARB_gpu_shader5 */
+
+#ifndef GL_ARB_gpu_shader_fp64
+#define GL_ARB_gpu_shader_fp64 1
+#endif /* GL_ARB_gpu_shader_fp64 */
+
+#ifndef GL_ARB_half_float_pixel
+#define GL_ARB_half_float_pixel 1
+typedef unsigned short GLhalfARB;
+#define GL_HALF_FLOAT_ARB 0x140B
+#endif /* GL_ARB_half_float_pixel */
+
+#ifndef GL_ARB_half_float_vertex
+#define GL_ARB_half_float_vertex 1
+#endif /* GL_ARB_half_float_vertex */
+
+#ifndef GL_ARB_imaging
+#define GL_ARB_imaging 1
+#define GL_BLEND_COLOR 0x8005
+#define GL_BLEND_EQUATION 0x8009
+#define GL_CONVOLUTION_1D 0x8010
+#define GL_CONVOLUTION_2D 0x8011
+#define GL_SEPARABLE_2D 0x8012
+#define GL_CONVOLUTION_BORDER_MODE 0x8013
+#define GL_CONVOLUTION_FILTER_SCALE 0x8014
+#define GL_CONVOLUTION_FILTER_BIAS 0x8015
+#define GL_REDUCE 0x8016
+#define GL_CONVOLUTION_FORMAT 0x8017
+#define GL_CONVOLUTION_WIDTH 0x8018
+#define GL_CONVOLUTION_HEIGHT 0x8019
+#define GL_MAX_CONVOLUTION_WIDTH 0x801A
+#define GL_MAX_CONVOLUTION_HEIGHT 0x801B
+#define GL_POST_CONVOLUTION_RED_SCALE 0x801C
+#define GL_POST_CONVOLUTION_GREEN_SCALE 0x801D
+#define GL_POST_CONVOLUTION_BLUE_SCALE 0x801E
+#define GL_POST_CONVOLUTION_ALPHA_SCALE 0x801F
+#define GL_POST_CONVOLUTION_RED_BIAS 0x8020
+#define GL_POST_CONVOLUTION_GREEN_BIAS 0x8021
+#define GL_POST_CONVOLUTION_BLUE_BIAS 0x8022
+#define GL_POST_CONVOLUTION_ALPHA_BIAS 0x8023
+#define GL_HISTOGRAM 0x8024
+#define GL_PROXY_HISTOGRAM 0x8025
+#define GL_HISTOGRAM_WIDTH 0x8026
+#define GL_HISTOGRAM_FORMAT 0x8027
+#define GL_HISTOGRAM_RED_SIZE 0x8028
+#define GL_HISTOGRAM_GREEN_SIZE 0x8029
+#define GL_HISTOGRAM_BLUE_SIZE 0x802A
+#define GL_HISTOGRAM_ALPHA_SIZE 0x802B
+#define GL_HISTOGRAM_LUMINANCE_SIZE 0x802C
+#define GL_HISTOGRAM_SINK 0x802D
+#define GL_MINMAX 0x802E
+#define GL_MINMAX_FORMAT 0x802F
+#define GL_MINMAX_SINK 0x8030
+#define GL_TABLE_TOO_LARGE 0x8031
+#define GL_COLOR_MATRIX 0x80B1
+#define GL_COLOR_MATRIX_STACK_DEPTH 0x80B2
+#define GL_MAX_COLOR_MATRIX_STACK_DEPTH 0x80B3
+#define GL_POST_COLOR_MATRIX_RED_SCALE 0x80B4
+#define GL_POST_COLOR_MATRIX_GREEN_SCALE 0x80B5
+#define GL_POST_COLOR_MATRIX_BLUE_SCALE 0x80B6
+#define GL_POST_COLOR_MATRIX_ALPHA_SCALE 0x80B7
+#define GL_POST_COLOR_MATRIX_RED_BIAS 0x80B8
+#define GL_POST_COLOR_MATRIX_GREEN_BIAS 0x80B9
+#define GL_POST_COLOR_MATRIX_BLUE_BIAS 0x80BA
+#define GL_POST_COLOR_MATRIX_ALPHA_BIAS 0x80BB
+#define GL_COLOR_TABLE 0x80D0
+#define GL_POST_CONVOLUTION_COLOR_TABLE 0x80D1
+#define GL_POST_COLOR_MATRIX_COLOR_TABLE 0x80D2
+#define GL_PROXY_COLOR_TABLE 0x80D3
+#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE 0x80D4
+#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE 0x80D5
+#define GL_COLOR_TABLE_SCALE 0x80D6
+#define GL_COLOR_TABLE_BIAS 0x80D7
+#define GL_COLOR_TABLE_FORMAT 0x80D8
+#define GL_COLOR_TABLE_WIDTH 0x80D9
+#define GL_COLOR_TABLE_RED_SIZE 0x80DA
+#define GL_COLOR_TABLE_GREEN_SIZE 0x80DB
+#define GL_COLOR_TABLE_BLUE_SIZE 0x80DC
+#define GL_COLOR_TABLE_ALPHA_SIZE 0x80DD
+#define GL_COLOR_TABLE_LUMINANCE_SIZE 0x80DE
+#define GL_COLOR_TABLE_INTENSITY_SIZE 0x80DF
+#define GL_CONSTANT_BORDER 0x8151
+#define GL_REPLICATE_BORDER 0x8153
+#define GL_CONVOLUTION_BORDER_COLOR 0x8154
+typedef void (APIENTRYP PFNGLCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *table);
+typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLCOPYCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width);
+typedef void (APIENTRYP PFNGLGETCOLORTABLEPROC) (GLenum target, GLenum format, GLenum type, void *table);
+typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const void *data);
+typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width);
+typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *image);
+typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *image);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat params);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIPROC) (GLenum target, GLenum pname, GLint params);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width);
+typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTERPROC) (GLenum target, GLenum format, GLenum type, void *image);
+typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETSEPARABLEFILTERPROC) (GLenum target, GLenum format, GLenum type, void *row, void *column, void *span);
+typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *row, const void *column);
+typedef void (APIENTRYP PFNGLGETHISTOGRAMPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values);
+typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETMINMAXPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values);
+typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLHISTOGRAMPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink);
+typedef void (APIENTRYP PFNGLMINMAXPROC) (GLenum target, GLenum internalformat, GLboolean sink);
+typedef void (APIENTRYP PFNGLRESETHISTOGRAMPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLRESETMINMAXPROC) (GLenum target);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glColorTable (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *table);
+GLAPI void APIENTRY glColorTableParameterfv (GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glColorTableParameteriv (GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glCopyColorTable (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width);
+GLAPI void APIENTRY glGetColorTable (GLenum target, GLenum format, GLenum type, void *table);
+GLAPI void APIENTRY glGetColorTableParameterfv (GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetColorTableParameteriv (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glColorSubTable (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const void *data);
+GLAPI void APIENTRY glCopyColorSubTable (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width);
+GLAPI void APIENTRY glConvolutionFilter1D (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *image);
+GLAPI void APIENTRY glConvolutionFilter2D (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *image);
+GLAPI void APIENTRY glConvolutionParameterf (GLenum target, GLenum pname, GLfloat params);
+GLAPI void APIENTRY glConvolutionParameterfv (GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glConvolutionParameteri (GLenum target, GLenum pname, GLint params);
+GLAPI void APIENTRY glConvolutionParameteriv (GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glCopyConvolutionFilter1D (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width);
+GLAPI void APIENTRY glCopyConvolutionFilter2D (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glGetConvolutionFilter (GLenum target, GLenum format, GLenum type, void *image);
+GLAPI void APIENTRY glGetConvolutionParameterfv (GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetConvolutionParameteriv (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetSeparableFilter (GLenum target, GLenum format, GLenum type, void *row, void *column, void *span);
+GLAPI void APIENTRY glSeparableFilter2D (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *row, const void *column);
+GLAPI void APIENTRY glGetHistogram (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values);
+GLAPI void APIENTRY glGetHistogramParameterfv (GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetHistogramParameteriv (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetMinmax (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values);
+GLAPI void APIENTRY glGetMinmaxParameterfv (GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetMinmaxParameteriv (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glHistogram (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink);
+GLAPI void APIENTRY glMinmax (GLenum target, GLenum internalformat, GLboolean sink);
+GLAPI void APIENTRY glResetHistogram (GLenum target);
+GLAPI void APIENTRY glResetMinmax (GLenum target);
+#endif
+#endif /* GL_ARB_imaging */
+
+#ifndef GL_ARB_indirect_parameters
+#define GL_ARB_indirect_parameters 1
+#define GL_PARAMETER_BUFFER_ARB 0x80EE
+#define GL_PARAMETER_BUFFER_BINDING_ARB 0x80EF
+typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTCOUNTARBPROC) (GLenum mode, GLintptr indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride);
+typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTCOUNTARBPROC) (GLenum mode, GLenum type, GLintptr indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMultiDrawArraysIndirectCountARB (GLenum mode, GLintptr indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride);
+GLAPI void APIENTRY glMultiDrawElementsIndirectCountARB (GLenum mode, GLenum type, GLintptr indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride);
+#endif
+#endif /* GL_ARB_indirect_parameters */
+
+#ifndef GL_ARB_instanced_arrays
+#define GL_ARB_instanced_arrays 1
+#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB 0x88FE
+typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORARBPROC) (GLuint index, GLuint divisor);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexAttribDivisorARB (GLuint index, GLuint divisor);
+#endif
+#endif /* GL_ARB_instanced_arrays */
+
+#ifndef GL_ARB_internalformat_query
+#define GL_ARB_internalformat_query 1
+#endif /* GL_ARB_internalformat_query */
+
+#ifndef GL_ARB_internalformat_query2
+#define GL_ARB_internalformat_query2 1
+#define GL_SRGB_DECODE_ARB 0x8299
+#endif /* GL_ARB_internalformat_query2 */
+
+#ifndef GL_ARB_invalidate_subdata
+#define GL_ARB_invalidate_subdata 1
+#endif /* GL_ARB_invalidate_subdata */
+
+#ifndef GL_ARB_map_buffer_alignment
+#define GL_ARB_map_buffer_alignment 1
+#endif /* GL_ARB_map_buffer_alignment */
+
+#ifndef GL_ARB_map_buffer_range
+#define GL_ARB_map_buffer_range 1
+#endif /* GL_ARB_map_buffer_range */
+
+#ifndef GL_ARB_matrix_palette
+#define GL_ARB_matrix_palette 1
+#define GL_MATRIX_PALETTE_ARB 0x8840
+#define GL_MAX_MATRIX_PALETTE_STACK_DEPTH_ARB 0x8841
+#define GL_MAX_PALETTE_MATRICES_ARB 0x8842
+#define GL_CURRENT_PALETTE_MATRIX_ARB 0x8843
+#define GL_MATRIX_INDEX_ARRAY_ARB 0x8844
+#define GL_CURRENT_MATRIX_INDEX_ARB 0x8845
+#define GL_MATRIX_INDEX_ARRAY_SIZE_ARB 0x8846
+#define GL_MATRIX_INDEX_ARRAY_TYPE_ARB 0x8847
+#define GL_MATRIX_INDEX_ARRAY_STRIDE_ARB 0x8848
+#define GL_MATRIX_INDEX_ARRAY_POINTER_ARB 0x8849
+typedef void (APIENTRYP PFNGLCURRENTPALETTEMATRIXARBPROC) (GLint index);
+typedef void (APIENTRYP PFNGLMATRIXINDEXUBVARBPROC) (GLint size, const GLubyte *indices);
+typedef void (APIENTRYP PFNGLMATRIXINDEXUSVARBPROC) (GLint size, const GLushort *indices);
+typedef void (APIENTRYP PFNGLMATRIXINDEXUIVARBPROC) (GLint size, const GLuint *indices);
+typedef void (APIENTRYP PFNGLMATRIXINDEXPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const void *pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glCurrentPaletteMatrixARB (GLint index);
+GLAPI void APIENTRY glMatrixIndexubvARB (GLint size, const GLubyte *indices);
+GLAPI void APIENTRY glMatrixIndexusvARB (GLint size, const GLushort *indices);
+GLAPI void APIENTRY glMatrixIndexuivARB (GLint size, const GLuint *indices);
+GLAPI void APIENTRY glMatrixIndexPointerARB (GLint size, GLenum type, GLsizei stride, const void *pointer);
+#endif
+#endif /* GL_ARB_matrix_palette */
+
+#ifndef GL_ARB_multi_bind
+#define GL_ARB_multi_bind 1
+#endif /* GL_ARB_multi_bind */
+
+#ifndef GL_ARB_multi_draw_indirect
+#define GL_ARB_multi_draw_indirect 1
+#endif /* GL_ARB_multi_draw_indirect */
+
+#ifndef GL_ARB_multisample
+#define GL_ARB_multisample 1
+#define GL_MULTISAMPLE_ARB 0x809D
+#define GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 0x809E
+#define GL_SAMPLE_ALPHA_TO_ONE_ARB 0x809F
+#define GL_SAMPLE_COVERAGE_ARB 0x80A0
+#define GL_SAMPLE_BUFFERS_ARB 0x80A8
+#define GL_SAMPLES_ARB 0x80A9
+#define GL_SAMPLE_COVERAGE_VALUE_ARB 0x80AA
+#define GL_SAMPLE_COVERAGE_INVERT_ARB 0x80AB
+#define GL_MULTISAMPLE_BIT_ARB 0x20000000
+typedef void (APIENTRYP PFNGLSAMPLECOVERAGEARBPROC) (GLfloat value, GLboolean invert);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glSampleCoverageARB (GLfloat value, GLboolean invert);
+#endif
+#endif /* GL_ARB_multisample */
+
+#ifndef GL_ARB_multitexture
+#define GL_ARB_multitexture 1
+#define GL_TEXTURE0_ARB 0x84C0
+#define GL_TEXTURE1_ARB 0x84C1
+#define GL_TEXTURE2_ARB 0x84C2
+#define GL_TEXTURE3_ARB 0x84C3
+#define GL_TEXTURE4_ARB 0x84C4
+#define GL_TEXTURE5_ARB 0x84C5
+#define GL_TEXTURE6_ARB 0x84C6
+#define GL_TEXTURE7_ARB 0x84C7
+#define GL_TEXTURE8_ARB 0x84C8
+#define GL_TEXTURE9_ARB 0x84C9
+#define GL_TEXTURE10_ARB 0x84CA
+#define GL_TEXTURE11_ARB 0x84CB
+#define GL_TEXTURE12_ARB 0x84CC
+#define GL_TEXTURE13_ARB 0x84CD
+#define GL_TEXTURE14_ARB 0x84CE
+#define GL_TEXTURE15_ARB 0x84CF
+#define GL_TEXTURE16_ARB 0x84D0
+#define GL_TEXTURE17_ARB 0x84D1
+#define GL_TEXTURE18_ARB 0x84D2
+#define GL_TEXTURE19_ARB 0x84D3
+#define GL_TEXTURE20_ARB 0x84D4
+#define GL_TEXTURE21_ARB 0x84D5
+#define GL_TEXTURE22_ARB 0x84D6
+#define GL_TEXTURE23_ARB 0x84D7
+#define GL_TEXTURE24_ARB 0x84D8
+#define GL_TEXTURE25_ARB 0x84D9
+#define GL_TEXTURE26_ARB 0x84DA
+#define GL_TEXTURE27_ARB 0x84DB
+#define GL_TEXTURE28_ARB 0x84DC
+#define GL_TEXTURE29_ARB 0x84DD
+#define GL_TEXTURE30_ARB 0x84DE
+#define GL_TEXTURE31_ARB 0x84DF
+#define GL_ACTIVE_TEXTURE_ARB 0x84E0
+#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1
+#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2
+typedef void (APIENTRYP PFNGLACTIVETEXTUREARBPROC) (GLenum texture);
+typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1DARBPROC) (GLenum target, GLdouble s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVARBPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1FARBPROC) (GLenum target, GLfloat s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVARBPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1IARBPROC) (GLenum target, GLint s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVARBPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1SARBPROC) (GLenum target, GLshort s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVARBPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2DARBPROC) (GLenum target, GLdouble s, GLdouble t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVARBPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2IARBPROC) (GLenum target, GLint s, GLint t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVARBPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2SARBPROC) (GLenum target, GLshort s, GLshort t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVARBPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVARBPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3IARBPROC) (GLenum target, GLint s, GLint t, GLint r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVARBPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVARBPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVARBPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4IARBPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVARBPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLshort *v);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glActiveTextureARB (GLenum texture);
+GLAPI void APIENTRY glClientActiveTextureARB (GLenum texture);
+GLAPI void APIENTRY glMultiTexCoord1dARB (GLenum target, GLdouble s);
+GLAPI void APIENTRY glMultiTexCoord1dvARB (GLenum target, const GLdouble *v);
+GLAPI void APIENTRY glMultiTexCoord1fARB (GLenum target, GLfloat s);
+GLAPI void APIENTRY glMultiTexCoord1fvARB (GLenum target, const GLfloat *v);
+GLAPI void APIENTRY glMultiTexCoord1iARB (GLenum target, GLint s);
+GLAPI void APIENTRY glMultiTexCoord1ivARB (GLenum target, const GLint *v);
+GLAPI void APIENTRY glMultiTexCoord1sARB (GLenum target, GLshort s);
+GLAPI void APIENTRY glMultiTexCoord1svARB (GLenum target, const GLshort *v);
+GLAPI void APIENTRY glMultiTexCoord2dARB (GLenum target, GLdouble s, GLdouble t);
+GLAPI void APIENTRY glMultiTexCoord2dvARB (GLenum target, const GLdouble *v);
+GLAPI void APIENTRY glMultiTexCoord2fARB (GLenum target, GLfloat s, GLfloat t);
+GLAPI void APIENTRY glMultiTexCoord2fvARB (GLenum target, const GLfloat *v);
+GLAPI void APIENTRY glMultiTexCoord2iARB (GLenum target, GLint s, GLint t);
+GLAPI void APIENTRY glMultiTexCoord2ivARB (GLenum target, const GLint *v);
+GLAPI void APIENTRY glMultiTexCoord2sARB (GLenum target, GLshort s, GLshort t);
+GLAPI void APIENTRY glMultiTexCoord2svARB (GLenum target, const GLshort *v);
+GLAPI void APIENTRY glMultiTexCoord3dARB (GLenum target, GLdouble s, GLdouble t, GLdouble r);
+GLAPI void APIENTRY glMultiTexCoord3dvARB (GLenum target, const GLdouble *v);
+GLAPI void APIENTRY glMultiTexCoord3fARB (GLenum target, GLfloat s, GLfloat t, GLfloat r);
+GLAPI void APIENTRY glMultiTexCoord3fvARB (GLenum target, const GLfloat *v);
+GLAPI void APIENTRY glMultiTexCoord3iARB (GLenum target, GLint s, GLint t, GLint r);
+GLAPI void APIENTRY glMultiTexCoord3ivARB (GLenum target, const GLint *v);
+GLAPI void APIENTRY glMultiTexCoord3sARB (GLenum target, GLshort s, GLshort t, GLshort r);
+GLAPI void APIENTRY glMultiTexCoord3svARB (GLenum target, const GLshort *v);
+GLAPI void APIENTRY glMultiTexCoord4dARB (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q);
+GLAPI void APIENTRY glMultiTexCoord4dvARB (GLenum target, const GLdouble *v);
+GLAPI void APIENTRY glMultiTexCoord4fARB (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
+GLAPI void APIENTRY glMultiTexCoord4fvARB (GLenum target, const GLfloat *v);
+GLAPI void APIENTRY glMultiTexCoord4iARB (GLenum target, GLint s, GLint t, GLint r, GLint q);
+GLAPI void APIENTRY glMultiTexCoord4ivARB (GLenum target, const GLint *v);
+GLAPI void APIENTRY glMultiTexCoord4sARB (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q);
+GLAPI void APIENTRY glMultiTexCoord4svARB (GLenum target, const GLshort *v);
+#endif
+#endif /* GL_ARB_multitexture */
+
+#ifndef GL_ARB_occlusion_query
+#define GL_ARB_occlusion_query 1
+#define GL_QUERY_COUNTER_BITS_ARB 0x8864
+#define GL_CURRENT_QUERY_ARB 0x8865
+#define GL_QUERY_RESULT_ARB 0x8866
+#define GL_QUERY_RESULT_AVAILABLE_ARB 0x8867
+#define GL_SAMPLES_PASSED_ARB 0x8914
+typedef void (APIENTRYP PFNGLGENQUERIESARBPROC) (GLsizei n, GLuint *ids);
+typedef void (APIENTRYP PFNGLDELETEQUERIESARBPROC) (GLsizei n, const GLuint *ids);
+typedef GLboolean (APIENTRYP PFNGLISQUERYARBPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLBEGINQUERYARBPROC) (GLenum target, GLuint id);
+typedef void (APIENTRYP PFNGLENDQUERYARBPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLGETQUERYIVARBPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVARBPROC) (GLuint id, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVARBPROC) (GLuint id, GLenum pname, GLuint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGenQueriesARB (GLsizei n, GLuint *ids);
+GLAPI void APIENTRY glDeleteQueriesARB (GLsizei n, const GLuint *ids);
+GLAPI GLboolean APIENTRY glIsQueryARB (GLuint id);
+GLAPI void APIENTRY glBeginQueryARB (GLenum target, GLuint id);
+GLAPI void APIENTRY glEndQueryARB (GLenum target);
+GLAPI void APIENTRY glGetQueryivARB (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetQueryObjectivARB (GLuint id, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetQueryObjectuivARB (GLuint id, GLenum pname, GLuint *params);
+#endif
+#endif /* GL_ARB_occlusion_query */
+
+#ifndef GL_ARB_occlusion_query2
+#define GL_ARB_occlusion_query2 1
+#endif /* GL_ARB_occlusion_query2 */
+
+#ifndef GL_ARB_pixel_buffer_object
+#define GL_ARB_pixel_buffer_object 1
+#define GL_PIXEL_PACK_BUFFER_ARB 0x88EB
+#define GL_PIXEL_UNPACK_BUFFER_ARB 0x88EC
+#define GL_PIXEL_PACK_BUFFER_BINDING_ARB 0x88ED
+#define GL_PIXEL_UNPACK_BUFFER_BINDING_ARB 0x88EF
+#endif /* GL_ARB_pixel_buffer_object */
+
+#ifndef GL_ARB_point_parameters
+#define GL_ARB_point_parameters 1
+#define GL_POINT_SIZE_MIN_ARB 0x8126
+#define GL_POINT_SIZE_MAX_ARB 0x8127
+#define GL_POINT_FADE_THRESHOLD_SIZE_ARB 0x8128
+#define GL_POINT_DISTANCE_ATTENUATION_ARB 0x8129
+typedef void (APIENTRYP PFNGLPOINTPARAMETERFARBPROC) (GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLPOINTPARAMETERFVARBPROC) (GLenum pname, const GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPointParameterfARB (GLenum pname, GLfloat param);
+GLAPI void APIENTRY glPointParameterfvARB (GLenum pname, const GLfloat *params);
+#endif
+#endif /* GL_ARB_point_parameters */
+
+#ifndef GL_ARB_point_sprite
+#define GL_ARB_point_sprite 1
+#define GL_POINT_SPRITE_ARB 0x8861
+#define GL_COORD_REPLACE_ARB 0x8862
+#endif /* GL_ARB_point_sprite */
+
+#ifndef GL_ARB_program_interface_query
+#define GL_ARB_program_interface_query 1
+#endif /* GL_ARB_program_interface_query */
+
+#ifndef GL_ARB_provoking_vertex
+#define GL_ARB_provoking_vertex 1
+#endif /* GL_ARB_provoking_vertex */
+
+#ifndef GL_ARB_query_buffer_object
+#define GL_ARB_query_buffer_object 1
+#endif /* GL_ARB_query_buffer_object */
+
+#ifndef GL_ARB_robust_buffer_access_behavior
+#define GL_ARB_robust_buffer_access_behavior 1
+#endif /* GL_ARB_robust_buffer_access_behavior */
+
+#ifndef GL_ARB_robustness
+#define GL_ARB_robustness 1
+#define GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB 0x00000004
+#define GL_LOSE_CONTEXT_ON_RESET_ARB 0x8252
+#define GL_GUILTY_CONTEXT_RESET_ARB 0x8253
+#define GL_INNOCENT_CONTEXT_RESET_ARB 0x8254
+#define GL_UNKNOWN_CONTEXT_RESET_ARB 0x8255
+#define GL_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
+#define GL_NO_RESET_NOTIFICATION_ARB 0x8261
+typedef GLenum (APIENTRYP PFNGLGETGRAPHICSRESETSTATUSARBPROC) (void);
+typedef void (APIENTRYP PFNGLGETNTEXIMAGEARBPROC) (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, void *img);
+typedef void (APIENTRYP PFNGLREADNPIXELSARBPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void *data);
+typedef void (APIENTRYP PFNGLGETNCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint lod, GLsizei bufSize, void *img);
+typedef void (APIENTRYP PFNGLGETNUNIFORMFVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETNUNIFORMIVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLint *params);
+typedef void (APIENTRYP PFNGLGETNUNIFORMUIVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLuint *params);
+typedef void (APIENTRYP PFNGLGETNUNIFORMDVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETNMAPDVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v);
+typedef void (APIENTRYP PFNGLGETNMAPFVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v);
+typedef void (APIENTRYP PFNGLGETNMAPIVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLint *v);
+typedef void (APIENTRYP PFNGLGETNPIXELMAPFVARBPROC) (GLenum map, GLsizei bufSize, GLfloat *values);
+typedef void (APIENTRYP PFNGLGETNPIXELMAPUIVARBPROC) (GLenum map, GLsizei bufSize, GLuint *values);
+typedef void (APIENTRYP PFNGLGETNPIXELMAPUSVARBPROC) (GLenum map, GLsizei bufSize, GLushort *values);
+typedef void (APIENTRYP PFNGLGETNPOLYGONSTIPPLEARBPROC) (GLsizei bufSize, GLubyte *pattern);
+typedef void (APIENTRYP PFNGLGETNCOLORTABLEARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei bufSize, void *table);
+typedef void (APIENTRYP PFNGLGETNCONVOLUTIONFILTERARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei bufSize, void *image);
+typedef void (APIENTRYP PFNGLGETNSEPARABLEFILTERARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei rowBufSize, void *row, GLsizei columnBufSize, void *column, void *span);
+typedef void (APIENTRYP PFNGLGETNHISTOGRAMARBPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, void *values);
+typedef void (APIENTRYP PFNGLGETNMINMAXARBPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, void *values);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLenum APIENTRY glGetGraphicsResetStatusARB (void);
+GLAPI void APIENTRY glGetnTexImageARB (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, void *img);
+GLAPI void APIENTRY glReadnPixelsARB (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void *data);
+GLAPI void APIENTRY glGetnCompressedTexImageARB (GLenum target, GLint lod, GLsizei bufSize, void *img);
+GLAPI void APIENTRY glGetnUniformfvARB (GLuint program, GLint location, GLsizei bufSize, GLfloat *params);
+GLAPI void APIENTRY glGetnUniformivARB (GLuint program, GLint location, GLsizei bufSize, GLint *params);
+GLAPI void APIENTRY glGetnUniformuivARB (GLuint program, GLint location, GLsizei bufSize, GLuint *params);
+GLAPI void APIENTRY glGetnUniformdvARB (GLuint program, GLint location, GLsizei bufSize, GLdouble *params);
+GLAPI void APIENTRY glGetnMapdvARB (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v);
+GLAPI void APIENTRY glGetnMapfvARB (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v);
+GLAPI void APIENTRY glGetnMapivARB (GLenum target, GLenum query, GLsizei bufSize, GLint *v);
+GLAPI void APIENTRY glGetnPixelMapfvARB (GLenum map, GLsizei bufSize, GLfloat *values);
+GLAPI void APIENTRY glGetnPixelMapuivARB (GLenum map, GLsizei bufSize, GLuint *values);
+GLAPI void APIENTRY glGetnPixelMapusvARB (GLenum map, GLsizei bufSize, GLushort *values);
+GLAPI void APIENTRY glGetnPolygonStippleARB (GLsizei bufSize, GLubyte *pattern);
+GLAPI void APIENTRY glGetnColorTableARB (GLenum target, GLenum format, GLenum type, GLsizei bufSize, void *table);
+GLAPI void APIENTRY glGetnConvolutionFilterARB (GLenum target, GLenum format, GLenum type, GLsizei bufSize, void *image);
+GLAPI void APIENTRY glGetnSeparableFilterARB (GLenum target, GLenum format, GLenum type, GLsizei rowBufSize, void *row, GLsizei columnBufSize, void *column, void *span);
+GLAPI void APIENTRY glGetnHistogramARB (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, void *values);
+GLAPI void APIENTRY glGetnMinmaxARB (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, void *values);
+#endif
+#endif /* GL_ARB_robustness */
+
+#ifndef GL_ARB_robustness_isolation
+#define GL_ARB_robustness_isolation 1
+#endif /* GL_ARB_robustness_isolation */
+
+#ifndef GL_ARB_sample_shading
+#define GL_ARB_sample_shading 1
+#define GL_SAMPLE_SHADING_ARB 0x8C36
+#define GL_MIN_SAMPLE_SHADING_VALUE_ARB 0x8C37
+typedef void (APIENTRYP PFNGLMINSAMPLESHADINGARBPROC) (GLfloat value);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMinSampleShadingARB (GLfloat value);
+#endif
+#endif /* GL_ARB_sample_shading */
+
+#ifndef GL_ARB_sampler_objects
+#define GL_ARB_sampler_objects 1
+#endif /* GL_ARB_sampler_objects */
+
+#ifndef GL_ARB_seamless_cube_map
+#define GL_ARB_seamless_cube_map 1
+#endif /* GL_ARB_seamless_cube_map */
+
+#ifndef GL_ARB_seamless_cubemap_per_texture
+#define GL_ARB_seamless_cubemap_per_texture 1
+#endif /* GL_ARB_seamless_cubemap_per_texture */
+
+#ifndef GL_ARB_separate_shader_objects
+#define GL_ARB_separate_shader_objects 1
+#endif /* GL_ARB_separate_shader_objects */
+
+#ifndef GL_ARB_shader_atomic_counters
+#define GL_ARB_shader_atomic_counters 1
+#endif /* GL_ARB_shader_atomic_counters */
+
+#ifndef GL_ARB_shader_bit_encoding
+#define GL_ARB_shader_bit_encoding 1
+#endif /* GL_ARB_shader_bit_encoding */
+
+#ifndef GL_ARB_shader_draw_parameters
+#define GL_ARB_shader_draw_parameters 1
+#endif /* GL_ARB_shader_draw_parameters */
+
+#ifndef GL_ARB_shader_group_vote
+#define GL_ARB_shader_group_vote 1
+#endif /* GL_ARB_shader_group_vote */
+
+#ifndef GL_ARB_shader_image_load_store
+#define GL_ARB_shader_image_load_store 1
+#endif /* GL_ARB_shader_image_load_store */
+
+#ifndef GL_ARB_shader_image_size
+#define GL_ARB_shader_image_size 1
+#endif /* GL_ARB_shader_image_size */
+
+#ifndef GL_ARB_shader_objects
+#define GL_ARB_shader_objects 1
+#ifdef __APPLE__
+typedef void *GLhandleARB;
+#else
+typedef unsigned int GLhandleARB;
+#endif
+typedef char GLcharARB;
+#define GL_PROGRAM_OBJECT_ARB 0x8B40
+#define GL_SHADER_OBJECT_ARB 0x8B48
+#define GL_OBJECT_TYPE_ARB 0x8B4E
+#define GL_OBJECT_SUBTYPE_ARB 0x8B4F
+#define GL_FLOAT_VEC2_ARB 0x8B50
+#define GL_FLOAT_VEC3_ARB 0x8B51
+#define GL_FLOAT_VEC4_ARB 0x8B52
+#define GL_INT_VEC2_ARB 0x8B53
+#define GL_INT_VEC3_ARB 0x8B54
+#define GL_INT_VEC4_ARB 0x8B55
+#define GL_BOOL_ARB 0x8B56
+#define GL_BOOL_VEC2_ARB 0x8B57
+#define GL_BOOL_VEC3_ARB 0x8B58
+#define GL_BOOL_VEC4_ARB 0x8B59
+#define GL_FLOAT_MAT2_ARB 0x8B5A
+#define GL_FLOAT_MAT3_ARB 0x8B5B
+#define GL_FLOAT_MAT4_ARB 0x8B5C
+#define GL_SAMPLER_1D_ARB 0x8B5D
+#define GL_SAMPLER_2D_ARB 0x8B5E
+#define GL_SAMPLER_3D_ARB 0x8B5F
+#define GL_SAMPLER_CUBE_ARB 0x8B60
+#define GL_SAMPLER_1D_SHADOW_ARB 0x8B61
+#define GL_SAMPLER_2D_SHADOW_ARB 0x8B62
+#define GL_SAMPLER_2D_RECT_ARB 0x8B63
+#define GL_SAMPLER_2D_RECT_SHADOW_ARB 0x8B64
+#define GL_OBJECT_DELETE_STATUS_ARB 0x8B80
+#define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81
+#define GL_OBJECT_LINK_STATUS_ARB 0x8B82
+#define GL_OBJECT_VALIDATE_STATUS_ARB 0x8B83
+#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84
+#define GL_OBJECT_ATTACHED_OBJECTS_ARB 0x8B85
+#define GL_OBJECT_ACTIVE_UNIFORMS_ARB 0x8B86
+#define GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB 0x8B87
+#define GL_OBJECT_SHADER_SOURCE_LENGTH_ARB 0x8B88
+typedef void (APIENTRYP PFNGLDELETEOBJECTARBPROC) (GLhandleARB obj);
+typedef GLhandleARB (APIENTRYP PFNGLGETHANDLEARBPROC) (GLenum pname);
+typedef void (APIENTRYP PFNGLDETACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB attachedObj);
+typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum shaderType);
+typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, GLsizei count, const GLcharARB **string, const GLint *length);
+typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB shaderObj);
+typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void);
+typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj);
+typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj);
+typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB programObj);
+typedef void (APIENTRYP PFNGLVALIDATEPROGRAMARBPROC) (GLhandleARB programObj);
+typedef void (APIENTRYP PFNGLUNIFORM1FARBPROC) (GLint location, GLfloat v0);
+typedef void (APIENTRYP PFNGLUNIFORM2FARBPROC) (GLint location, GLfloat v0, GLfloat v1);
+typedef void (APIENTRYP PFNGLUNIFORM3FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+typedef void (APIENTRYP PFNGLUNIFORM4FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+typedef void (APIENTRYP PFNGLUNIFORM1IARBPROC) (GLint location, GLint v0);
+typedef void (APIENTRYP PFNGLUNIFORM2IARBPROC) (GLint location, GLint v0, GLint v1);
+typedef void (APIENTRYP PFNGLUNIFORM3IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2);
+typedef void (APIENTRYP PFNGLUNIFORM4IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+typedef void (APIENTRYP PFNGLUNIFORM1FVARBPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORM2FVARBPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORM3FVARBPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORM4FVARBPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORM1IVARBPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLUNIFORM2IVARBPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLUNIFORM3IVARBPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLUNIFORM4IVARBPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERFVARBPROC) (GLhandleARB obj, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVARBPROC) (GLhandleARB obj, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETINFOLOGARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog);
+typedef void (APIENTRYP PFNGLGETATTACHEDOBJECTSARBPROC) (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj);
+typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name);
+typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name);
+typedef void (APIENTRYP PFNGLGETUNIFORMFVARBPROC) (GLhandleARB programObj, GLint location, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETUNIFORMIVARBPROC) (GLhandleARB programObj, GLint location, GLint *params);
+typedef void (APIENTRYP PFNGLGETSHADERSOURCEARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDeleteObjectARB (GLhandleARB obj);
+GLAPI GLhandleARB APIENTRY glGetHandleARB (GLenum pname);
+GLAPI void APIENTRY glDetachObjectARB (GLhandleARB containerObj, GLhandleARB attachedObj);
+GLAPI GLhandleARB APIENTRY glCreateShaderObjectARB (GLenum shaderType);
+GLAPI void APIENTRY glShaderSourceARB (GLhandleARB shaderObj, GLsizei count, const GLcharARB **string, const GLint *length);
+GLAPI void APIENTRY glCompileShaderARB (GLhandleARB shaderObj);
+GLAPI GLhandleARB APIENTRY glCreateProgramObjectARB (void);
+GLAPI void APIENTRY glAttachObjectARB (GLhandleARB containerObj, GLhandleARB obj);
+GLAPI void APIENTRY glLinkProgramARB (GLhandleARB programObj);
+GLAPI void APIENTRY glUseProgramObjectARB (GLhandleARB programObj);
+GLAPI void APIENTRY glValidateProgramARB (GLhandleARB programObj);
+GLAPI void APIENTRY glUniform1fARB (GLint location, GLfloat v0);
+GLAPI void APIENTRY glUniform2fARB (GLint location, GLfloat v0, GLfloat v1);
+GLAPI void APIENTRY glUniform3fARB (GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+GLAPI void APIENTRY glUniform4fARB (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+GLAPI void APIENTRY glUniform1iARB (GLint location, GLint v0);
+GLAPI void APIENTRY glUniform2iARB (GLint location, GLint v0, GLint v1);
+GLAPI void APIENTRY glUniform3iARB (GLint location, GLint v0, GLint v1, GLint v2);
+GLAPI void APIENTRY glUniform4iARB (GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+GLAPI void APIENTRY glUniform1fvARB (GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glUniform2fvARB (GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glUniform3fvARB (GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glUniform4fvARB (GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glUniform1ivARB (GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glUniform2ivARB (GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glUniform3ivARB (GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glUniform4ivARB (GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glUniformMatrix2fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glUniformMatrix3fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glUniformMatrix4fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glGetObjectParameterfvARB (GLhandleARB obj, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetObjectParameterivARB (GLhandleARB obj, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetInfoLogARB (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog);
+GLAPI void APIENTRY glGetAttachedObjectsARB (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj);
+GLAPI GLint APIENTRY glGetUniformLocationARB (GLhandleARB programObj, const GLcharARB *name);
+GLAPI void APIENTRY glGetActiveUniformARB (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name);
+GLAPI void APIENTRY glGetUniformfvARB (GLhandleARB programObj, GLint location, GLfloat *params);
+GLAPI void APIENTRY glGetUniformivARB (GLhandleARB programObj, GLint location, GLint *params);
+GLAPI void APIENTRY glGetShaderSourceARB (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source);
+#endif
+#endif /* GL_ARB_shader_objects */
+
+#ifndef GL_ARB_shader_precision
+#define GL_ARB_shader_precision 1
+#endif /* GL_ARB_shader_precision */
+
+#ifndef GL_ARB_shader_stencil_export
+#define GL_ARB_shader_stencil_export 1
+#endif /* GL_ARB_shader_stencil_export */
+
+#ifndef GL_ARB_shader_storage_buffer_object
+#define GL_ARB_shader_storage_buffer_object 1
+#endif /* GL_ARB_shader_storage_buffer_object */
+
+#ifndef GL_ARB_shader_subroutine
+#define GL_ARB_shader_subroutine 1
+#endif /* GL_ARB_shader_subroutine */
+
+#ifndef GL_ARB_shader_texture_lod
+#define GL_ARB_shader_texture_lod 1
+#endif /* GL_ARB_shader_texture_lod */
+
+#ifndef GL_ARB_shading_language_100
+#define GL_ARB_shading_language_100 1
+#define GL_SHADING_LANGUAGE_VERSION_ARB 0x8B8C
+#endif /* GL_ARB_shading_language_100 */
+
+#ifndef GL_ARB_shading_language_420pack
+#define GL_ARB_shading_language_420pack 1
+#endif /* GL_ARB_shading_language_420pack */
+
+#ifndef GL_ARB_shading_language_include
+#define GL_ARB_shading_language_include 1
+#define GL_SHADER_INCLUDE_ARB 0x8DAE
+#define GL_NAMED_STRING_LENGTH_ARB 0x8DE9
+#define GL_NAMED_STRING_TYPE_ARB 0x8DEA
+typedef void (APIENTRYP PFNGLNAMEDSTRINGARBPROC) (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string);
+typedef void (APIENTRYP PFNGLDELETENAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name);
+typedef void (APIENTRYP PFNGLCOMPILESHADERINCLUDEARBPROC) (GLuint shader, GLsizei count, const GLchar *const*path, const GLint *length);
+typedef GLboolean (APIENTRYP PFNGLISNAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name);
+typedef void (APIENTRYP PFNGLGETNAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string);
+typedef void (APIENTRYP PFNGLGETNAMEDSTRINGIVARBPROC) (GLint namelen, const GLchar *name, GLenum pname, GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glNamedStringARB (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string);
+GLAPI void APIENTRY glDeleteNamedStringARB (GLint namelen, const GLchar *name);
+GLAPI void APIENTRY glCompileShaderIncludeARB (GLuint shader, GLsizei count, const GLchar *const*path, const GLint *length);
+GLAPI GLboolean APIENTRY glIsNamedStringARB (GLint namelen, const GLchar *name);
+GLAPI void APIENTRY glGetNamedStringARB (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string);
+GLAPI void APIENTRY glGetNamedStringivARB (GLint namelen, const GLchar *name, GLenum pname, GLint *params);
+#endif
+#endif /* GL_ARB_shading_language_include */
+
+#ifndef GL_ARB_shading_language_packing
+#define GL_ARB_shading_language_packing 1
+#endif /* GL_ARB_shading_language_packing */
+
+#ifndef GL_ARB_shadow
+#define GL_ARB_shadow 1
+#define GL_TEXTURE_COMPARE_MODE_ARB 0x884C
+#define GL_TEXTURE_COMPARE_FUNC_ARB 0x884D
+#define GL_COMPARE_R_TO_TEXTURE_ARB 0x884E
+#endif /* GL_ARB_shadow */
+
+#ifndef GL_ARB_shadow_ambient
+#define GL_ARB_shadow_ambient 1
+#define GL_TEXTURE_COMPARE_FAIL_VALUE_ARB 0x80BF
+#endif /* GL_ARB_shadow_ambient */
+
+#ifndef GL_ARB_sparse_texture
+#define GL_ARB_sparse_texture 1
+#define GL_TEXTURE_SPARSE_ARB 0x91A6
+#define GL_VIRTUAL_PAGE_SIZE_INDEX_ARB 0x91A7
+#define GL_MIN_SPARSE_LEVEL_ARB 0x919B
+#define GL_NUM_VIRTUAL_PAGE_SIZES_ARB 0x91A8
+#define GL_VIRTUAL_PAGE_SIZE_X_ARB 0x9195
+#define GL_VIRTUAL_PAGE_SIZE_Y_ARB 0x9196
+#define GL_VIRTUAL_PAGE_SIZE_Z_ARB 0x9197
+#define GL_MAX_SPARSE_TEXTURE_SIZE_ARB 0x9198
+#define GL_MAX_SPARSE_3D_TEXTURE_SIZE_ARB 0x9199
+#define GL_MAX_SPARSE_ARRAY_TEXTURE_LAYERS_ARB 0x919A
+#define GL_SPARSE_TEXTURE_FULL_ARRAY_CUBE_MIPMAPS_ARB 0x91A9
+typedef void (APIENTRYP PFNGLTEXPAGECOMMITMENTARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLboolean resident);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexPageCommitmentARB (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLboolean resident);
+#endif
+#endif /* GL_ARB_sparse_texture */
+
+#ifndef GL_ARB_stencil_texturing
+#define GL_ARB_stencil_texturing 1
+#endif /* GL_ARB_stencil_texturing */
+
+#ifndef GL_ARB_sync
+#define GL_ARB_sync 1
+#endif /* GL_ARB_sync */
+
+#ifndef GL_ARB_tessellation_shader
+#define GL_ARB_tessellation_shader 1
+#endif /* GL_ARB_tessellation_shader */
+
+#ifndef GL_ARB_texture_border_clamp
+#define GL_ARB_texture_border_clamp 1
+#define GL_CLAMP_TO_BORDER_ARB 0x812D
+#endif /* GL_ARB_texture_border_clamp */
+
+#ifndef GL_ARB_texture_buffer_object
+#define GL_ARB_texture_buffer_object 1
+#define GL_TEXTURE_BUFFER_ARB 0x8C2A
+#define GL_MAX_TEXTURE_BUFFER_SIZE_ARB 0x8C2B
+#define GL_TEXTURE_BINDING_BUFFER_ARB 0x8C2C
+#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB 0x8C2D
+#define GL_TEXTURE_BUFFER_FORMAT_ARB 0x8C2E
+typedef void (APIENTRYP PFNGLTEXBUFFERARBPROC) (GLenum target, GLenum internalformat, GLuint buffer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexBufferARB (GLenum target, GLenum internalformat, GLuint buffer);
+#endif
+#endif /* GL_ARB_texture_buffer_object */
+
+#ifndef GL_ARB_texture_buffer_object_rgb32
+#define GL_ARB_texture_buffer_object_rgb32 1
+#endif /* GL_ARB_texture_buffer_object_rgb32 */
+
+#ifndef GL_ARB_texture_buffer_range
+#define GL_ARB_texture_buffer_range 1
+#endif /* GL_ARB_texture_buffer_range */
+
+#ifndef GL_ARB_texture_compression
+#define GL_ARB_texture_compression 1
+#define GL_COMPRESSED_ALPHA_ARB 0x84E9
+#define GL_COMPRESSED_LUMINANCE_ARB 0x84EA
+#define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB
+#define GL_COMPRESSED_INTENSITY_ARB 0x84EC
+#define GL_COMPRESSED_RGB_ARB 0x84ED
+#define GL_COMPRESSED_RGBA_ARB 0x84EE
+#define GL_TEXTURE_COMPRESSION_HINT_ARB 0x84EF
+#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB 0x86A0
+#define GL_TEXTURE_COMPRESSED_ARB 0x86A1
+#define GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A2
+#define GL_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A3
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint level, void *img);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glCompressedTexImage3DARB (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexImage2DARB (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexImage1DARB (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexSubImage3DARB (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexSubImage2DARB (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexSubImage1DARB (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glGetCompressedTexImageARB (GLenum target, GLint level, void *img);
+#endif
+#endif /* GL_ARB_texture_compression */
+
+#ifndef GL_ARB_texture_compression_bptc
+#define GL_ARB_texture_compression_bptc 1
+#define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB 0x8E8C
+#define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB 0x8E8D
+#define GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB 0x8E8E
+#define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB 0x8E8F
+#endif /* GL_ARB_texture_compression_bptc */
+
+#ifndef GL_ARB_texture_compression_rgtc
+#define GL_ARB_texture_compression_rgtc 1
+#endif /* GL_ARB_texture_compression_rgtc */
+
+#ifndef GL_ARB_texture_cube_map
+#define GL_ARB_texture_cube_map 1
+#define GL_NORMAL_MAP_ARB 0x8511
+#define GL_REFLECTION_MAP_ARB 0x8512
+#define GL_TEXTURE_CUBE_MAP_ARB 0x8513
+#define GL_TEXTURE_BINDING_CUBE_MAP_ARB 0x8514
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x8515
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x8516
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x8517
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x8518
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x8519
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x851A
+#define GL_PROXY_TEXTURE_CUBE_MAP_ARB 0x851B
+#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB 0x851C
+#endif /* GL_ARB_texture_cube_map */
+
+#ifndef GL_ARB_texture_cube_map_array
+#define GL_ARB_texture_cube_map_array 1
+#define GL_TEXTURE_CUBE_MAP_ARRAY_ARB 0x9009
+#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY_ARB 0x900A
+#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB 0x900B
+#define GL_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900C
+#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_ARB 0x900D
+#define GL_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900E
+#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900F
+#endif /* GL_ARB_texture_cube_map_array */
+
+#ifndef GL_ARB_texture_env_add
+#define GL_ARB_texture_env_add 1
+#endif /* GL_ARB_texture_env_add */
+
+#ifndef GL_ARB_texture_env_combine
+#define GL_ARB_texture_env_combine 1
+#define GL_COMBINE_ARB 0x8570
+#define GL_COMBINE_RGB_ARB 0x8571
+#define GL_COMBINE_ALPHA_ARB 0x8572
+#define GL_SOURCE0_RGB_ARB 0x8580
+#define GL_SOURCE1_RGB_ARB 0x8581
+#define GL_SOURCE2_RGB_ARB 0x8582
+#define GL_SOURCE0_ALPHA_ARB 0x8588
+#define GL_SOURCE1_ALPHA_ARB 0x8589
+#define GL_SOURCE2_ALPHA_ARB 0x858A
+#define GL_OPERAND0_RGB_ARB 0x8590
+#define GL_OPERAND1_RGB_ARB 0x8591
+#define GL_OPERAND2_RGB_ARB 0x8592
+#define GL_OPERAND0_ALPHA_ARB 0x8598
+#define GL_OPERAND1_ALPHA_ARB 0x8599
+#define GL_OPERAND2_ALPHA_ARB 0x859A
+#define GL_RGB_SCALE_ARB 0x8573
+#define GL_ADD_SIGNED_ARB 0x8574
+#define GL_INTERPOLATE_ARB 0x8575
+#define GL_SUBTRACT_ARB 0x84E7
+#define GL_CONSTANT_ARB 0x8576
+#define GL_PRIMARY_COLOR_ARB 0x8577
+#define GL_PREVIOUS_ARB 0x8578
+#endif /* GL_ARB_texture_env_combine */
+
+#ifndef GL_ARB_texture_env_crossbar
+#define GL_ARB_texture_env_crossbar 1
+#endif /* GL_ARB_texture_env_crossbar */
+
+#ifndef GL_ARB_texture_env_dot3
+#define GL_ARB_texture_env_dot3 1
+#define GL_DOT3_RGB_ARB 0x86AE
+#define GL_DOT3_RGBA_ARB 0x86AF
+#endif /* GL_ARB_texture_env_dot3 */
+
+#ifndef GL_ARB_texture_float
+#define GL_ARB_texture_float 1
+#define GL_TEXTURE_RED_TYPE_ARB 0x8C10
+#define GL_TEXTURE_GREEN_TYPE_ARB 0x8C11
+#define GL_TEXTURE_BLUE_TYPE_ARB 0x8C12
+#define GL_TEXTURE_ALPHA_TYPE_ARB 0x8C13
+#define GL_TEXTURE_LUMINANCE_TYPE_ARB 0x8C14
+#define GL_TEXTURE_INTENSITY_TYPE_ARB 0x8C15
+#define GL_TEXTURE_DEPTH_TYPE_ARB 0x8C16
+#define GL_UNSIGNED_NORMALIZED_ARB 0x8C17
+#define GL_RGBA32F_ARB 0x8814
+#define GL_RGB32F_ARB 0x8815
+#define GL_ALPHA32F_ARB 0x8816
+#define GL_INTENSITY32F_ARB 0x8817
+#define GL_LUMINANCE32F_ARB 0x8818
+#define GL_LUMINANCE_ALPHA32F_ARB 0x8819
+#define GL_RGBA16F_ARB 0x881A
+#define GL_RGB16F_ARB 0x881B
+#define GL_ALPHA16F_ARB 0x881C
+#define GL_INTENSITY16F_ARB 0x881D
+#define GL_LUMINANCE16F_ARB 0x881E
+#define GL_LUMINANCE_ALPHA16F_ARB 0x881F
+#endif /* GL_ARB_texture_float */
+
+#ifndef GL_ARB_texture_gather
+#define GL_ARB_texture_gather 1
+#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET_ARB 0x8E5E
+#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET_ARB 0x8E5F
+#define GL_MAX_PROGRAM_TEXTURE_GATHER_COMPONENTS_ARB 0x8F9F
+#endif /* GL_ARB_texture_gather */
+
+#ifndef GL_ARB_texture_mirror_clamp_to_edge
+#define GL_ARB_texture_mirror_clamp_to_edge 1
+#endif /* GL_ARB_texture_mirror_clamp_to_edge */
+
+#ifndef GL_ARB_texture_mirrored_repeat
+#define GL_ARB_texture_mirrored_repeat 1
+#define GL_MIRRORED_REPEAT_ARB 0x8370
+#endif /* GL_ARB_texture_mirrored_repeat */
+
+#ifndef GL_ARB_texture_multisample
+#define GL_ARB_texture_multisample 1
+#endif /* GL_ARB_texture_multisample */
+
+#ifndef GL_ARB_texture_non_power_of_two
+#define GL_ARB_texture_non_power_of_two 1
+#endif /* GL_ARB_texture_non_power_of_two */
+
+#ifndef GL_ARB_texture_query_levels
+#define GL_ARB_texture_query_levels 1
+#endif /* GL_ARB_texture_query_levels */
+
+#ifndef GL_ARB_texture_query_lod
+#define GL_ARB_texture_query_lod 1
+#endif /* GL_ARB_texture_query_lod */
+
+#ifndef GL_ARB_texture_rectangle
+#define GL_ARB_texture_rectangle 1
+#define GL_TEXTURE_RECTANGLE_ARB 0x84F5
+#define GL_TEXTURE_BINDING_RECTANGLE_ARB 0x84F6
+#define GL_PROXY_TEXTURE_RECTANGLE_ARB 0x84F7
+#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8
+#endif /* GL_ARB_texture_rectangle */
+
+#ifndef GL_ARB_texture_rg
+#define GL_ARB_texture_rg 1
+#endif /* GL_ARB_texture_rg */
+
+#ifndef GL_ARB_texture_rgb10_a2ui
+#define GL_ARB_texture_rgb10_a2ui 1
+#endif /* GL_ARB_texture_rgb10_a2ui */
+
+#ifndef GL_ARB_texture_stencil8
+#define GL_ARB_texture_stencil8 1
+#endif /* GL_ARB_texture_stencil8 */
+
+#ifndef GL_ARB_texture_storage
+#define GL_ARB_texture_storage 1
+#endif /* GL_ARB_texture_storage */
+
+#ifndef GL_ARB_texture_storage_multisample
+#define GL_ARB_texture_storage_multisample 1
+#endif /* GL_ARB_texture_storage_multisample */
+
+#ifndef GL_ARB_texture_swizzle
+#define GL_ARB_texture_swizzle 1
+#endif /* GL_ARB_texture_swizzle */
+
+#ifndef GL_ARB_texture_view
+#define GL_ARB_texture_view 1
+#endif /* GL_ARB_texture_view */
+
+#ifndef GL_ARB_timer_query
+#define GL_ARB_timer_query 1
+#endif /* GL_ARB_timer_query */
+
+#ifndef GL_ARB_transform_feedback2
+#define GL_ARB_transform_feedback2 1
+#define GL_TRANSFORM_FEEDBACK_PAUSED 0x8E23
+#define GL_TRANSFORM_FEEDBACK_ACTIVE 0x8E24
+#endif /* GL_ARB_transform_feedback2 */
+
+#ifndef GL_ARB_transform_feedback3
+#define GL_ARB_transform_feedback3 1
+#endif /* GL_ARB_transform_feedback3 */
+
+#ifndef GL_ARB_transform_feedback_instanced
+#define GL_ARB_transform_feedback_instanced 1
+#endif /* GL_ARB_transform_feedback_instanced */
+
+#ifndef GL_ARB_transpose_matrix
+#define GL_ARB_transpose_matrix 1
+#define GL_TRANSPOSE_MODELVIEW_MATRIX_ARB 0x84E3
+#define GL_TRANSPOSE_PROJECTION_MATRIX_ARB 0x84E4
+#define GL_TRANSPOSE_TEXTURE_MATRIX_ARB 0x84E5
+#define GL_TRANSPOSE_COLOR_MATRIX_ARB 0x84E6
+typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFARBPROC) (const GLfloat *m);
+typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDARBPROC) (const GLdouble *m);
+typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFARBPROC) (const GLfloat *m);
+typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDARBPROC) (const GLdouble *m);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glLoadTransposeMatrixfARB (const GLfloat *m);
+GLAPI void APIENTRY glLoadTransposeMatrixdARB (const GLdouble *m);
+GLAPI void APIENTRY glMultTransposeMatrixfARB (const GLfloat *m);
+GLAPI void APIENTRY glMultTransposeMatrixdARB (const GLdouble *m);
+#endif
+#endif /* GL_ARB_transpose_matrix */
+
+#ifndef GL_ARB_uniform_buffer_object
+#define GL_ARB_uniform_buffer_object 1
+#define GL_MAX_GEOMETRY_UNIFORM_BLOCKS 0x8A2C
+#define GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS 0x8A32
+#define GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER 0x8A45
+#endif /* GL_ARB_uniform_buffer_object */
+
+#ifndef GL_ARB_vertex_array_bgra
+#define GL_ARB_vertex_array_bgra 1
+#endif /* GL_ARB_vertex_array_bgra */
+
+#ifndef GL_ARB_vertex_array_object
+#define GL_ARB_vertex_array_object 1
+#endif /* GL_ARB_vertex_array_object */
+
+#ifndef GL_ARB_vertex_attrib_64bit
+#define GL_ARB_vertex_attrib_64bit 1
+#endif /* GL_ARB_vertex_attrib_64bit */
+
+#ifndef GL_ARB_vertex_attrib_binding
+#define GL_ARB_vertex_attrib_binding 1
+#endif /* GL_ARB_vertex_attrib_binding */
+
+#ifndef GL_ARB_vertex_blend
+#define GL_ARB_vertex_blend 1
+#define GL_MAX_VERTEX_UNITS_ARB 0x86A4
+#define GL_ACTIVE_VERTEX_UNITS_ARB 0x86A5
+#define GL_WEIGHT_SUM_UNITY_ARB 0x86A6
+#define GL_VERTEX_BLEND_ARB 0x86A7
+#define GL_CURRENT_WEIGHT_ARB 0x86A8
+#define GL_WEIGHT_ARRAY_TYPE_ARB 0x86A9
+#define GL_WEIGHT_ARRAY_STRIDE_ARB 0x86AA
+#define GL_WEIGHT_ARRAY_SIZE_ARB 0x86AB
+#define GL_WEIGHT_ARRAY_POINTER_ARB 0x86AC
+#define GL_WEIGHT_ARRAY_ARB 0x86AD
+#define GL_MODELVIEW0_ARB 0x1700
+#define GL_MODELVIEW1_ARB 0x850A
+#define GL_MODELVIEW2_ARB 0x8722
+#define GL_MODELVIEW3_ARB 0x8723
+#define GL_MODELVIEW4_ARB 0x8724
+#define GL_MODELVIEW5_ARB 0x8725
+#define GL_MODELVIEW6_ARB 0x8726
+#define GL_MODELVIEW7_ARB 0x8727
+#define GL_MODELVIEW8_ARB 0x8728
+#define GL_MODELVIEW9_ARB 0x8729
+#define GL_MODELVIEW10_ARB 0x872A
+#define GL_MODELVIEW11_ARB 0x872B
+#define GL_MODELVIEW12_ARB 0x872C
+#define GL_MODELVIEW13_ARB 0x872D
+#define GL_MODELVIEW14_ARB 0x872E
+#define GL_MODELVIEW15_ARB 0x872F
+#define GL_MODELVIEW16_ARB 0x8730
+#define GL_MODELVIEW17_ARB 0x8731
+#define GL_MODELVIEW18_ARB 0x8732
+#define GL_MODELVIEW19_ARB 0x8733
+#define GL_MODELVIEW20_ARB 0x8734
+#define GL_MODELVIEW21_ARB 0x8735
+#define GL_MODELVIEW22_ARB 0x8736
+#define GL_MODELVIEW23_ARB 0x8737
+#define GL_MODELVIEW24_ARB 0x8738
+#define GL_MODELVIEW25_ARB 0x8739
+#define GL_MODELVIEW26_ARB 0x873A
+#define GL_MODELVIEW27_ARB 0x873B
+#define GL_MODELVIEW28_ARB 0x873C
+#define GL_MODELVIEW29_ARB 0x873D
+#define GL_MODELVIEW30_ARB 0x873E
+#define GL_MODELVIEW31_ARB 0x873F
+typedef void (APIENTRYP PFNGLWEIGHTBVARBPROC) (GLint size, const GLbyte *weights);
+typedef void (APIENTRYP PFNGLWEIGHTSVARBPROC) (GLint size, const GLshort *weights);
+typedef void (APIENTRYP PFNGLWEIGHTIVARBPROC) (GLint size, const GLint *weights);
+typedef void (APIENTRYP PFNGLWEIGHTFVARBPROC) (GLint size, const GLfloat *weights);
+typedef void (APIENTRYP PFNGLWEIGHTDVARBPROC) (GLint size, const GLdouble *weights);
+typedef void (APIENTRYP PFNGLWEIGHTUBVARBPROC) (GLint size, const GLubyte *weights);
+typedef void (APIENTRYP PFNGLWEIGHTUSVARBPROC) (GLint size, const GLushort *weights);
+typedef void (APIENTRYP PFNGLWEIGHTUIVARBPROC) (GLint size, const GLuint *weights);
+typedef void (APIENTRYP PFNGLWEIGHTPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLVERTEXBLENDARBPROC) (GLint count);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glWeightbvARB (GLint size, const GLbyte *weights);
+GLAPI void APIENTRY glWeightsvARB (GLint size, const GLshort *weights);
+GLAPI void APIENTRY glWeightivARB (GLint size, const GLint *weights);
+GLAPI void APIENTRY glWeightfvARB (GLint size, const GLfloat *weights);
+GLAPI void APIENTRY glWeightdvARB (GLint size, const GLdouble *weights);
+GLAPI void APIENTRY glWeightubvARB (GLint size, const GLubyte *weights);
+GLAPI void APIENTRY glWeightusvARB (GLint size, const GLushort *weights);
+GLAPI void APIENTRY glWeightuivARB (GLint size, const GLuint *weights);
+GLAPI void APIENTRY glWeightPointerARB (GLint size, GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glVertexBlendARB (GLint count);
+#endif
+#endif /* GL_ARB_vertex_blend */
+
+#ifndef GL_ARB_vertex_buffer_object
+#define GL_ARB_vertex_buffer_object 1
+#ifdef __MACOSX__ /* The OS X headers haven't caught up with Khronos yet */
+typedef long GLsizeiptrARB;
+typedef long GLintptrARB;
+#else
+typedef ptrdiff_t GLsizeiptrARB;
+typedef ptrdiff_t GLintptrARB;
+#endif
+#define GL_BUFFER_SIZE_ARB 0x8764
+#define GL_BUFFER_USAGE_ARB 0x8765
+#define GL_ARRAY_BUFFER_ARB 0x8892
+#define GL_ELEMENT_ARRAY_BUFFER_ARB 0x8893
+#define GL_ARRAY_BUFFER_BINDING_ARB 0x8894
+#define GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB 0x8895
+#define GL_VERTEX_ARRAY_BUFFER_BINDING_ARB 0x8896
+#define GL_NORMAL_ARRAY_BUFFER_BINDING_ARB 0x8897
+#define GL_COLOR_ARRAY_BUFFER_BINDING_ARB 0x8898
+#define GL_INDEX_ARRAY_BUFFER_BINDING_ARB 0x8899
+#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB 0x889A
+#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB 0x889B
+#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB 0x889C
+#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB 0x889D
+#define GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB 0x889E
+#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB 0x889F
+#define GL_READ_ONLY_ARB 0x88B8
+#define GL_WRITE_ONLY_ARB 0x88B9
+#define GL_READ_WRITE_ARB 0x88BA
+#define GL_BUFFER_ACCESS_ARB 0x88BB
+#define GL_BUFFER_MAPPED_ARB 0x88BC
+#define GL_BUFFER_MAP_POINTER_ARB 0x88BD
+#define GL_STREAM_DRAW_ARB 0x88E0
+#define GL_STREAM_READ_ARB 0x88E1
+#define GL_STREAM_COPY_ARB 0x88E2
+#define GL_STATIC_DRAW_ARB 0x88E4
+#define GL_STATIC_READ_ARB 0x88E5
+#define GL_STATIC_COPY_ARB 0x88E6
+#define GL_DYNAMIC_DRAW_ARB 0x88E8
+#define GL_DYNAMIC_READ_ARB 0x88E9
+#define GL_DYNAMIC_COPY_ARB 0x88EA
+typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
+typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
+typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
+typedef GLboolean (APIENTRYP PFNGLISBUFFERARBPROC) (GLuint buffer);
+typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const void *data, GLenum usage);
+typedef void (APIENTRYP PFNGLBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const void *data);
+typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, void *data);
+typedef void *(APIENTRYP PFNGLMAPBUFFERARBPROC) (GLenum target, GLenum access);
+typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERARBPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVARBPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVARBPROC) (GLenum target, GLenum pname, void **params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBindBufferARB (GLenum target, GLuint buffer);
+GLAPI void APIENTRY glDeleteBuffersARB (GLsizei n, const GLuint *buffers);
+GLAPI void APIENTRY glGenBuffersARB (GLsizei n, GLuint *buffers);
+GLAPI GLboolean APIENTRY glIsBufferARB (GLuint buffer);
+GLAPI void APIENTRY glBufferDataARB (GLenum target, GLsizeiptrARB size, const void *data, GLenum usage);
+GLAPI void APIENTRY glBufferSubDataARB (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const void *data);
+GLAPI void APIENTRY glGetBufferSubDataARB (GLenum target, GLintptrARB offset, GLsizeiptrARB size, void *data);
+GLAPI void *APIENTRY glMapBufferARB (GLenum target, GLenum access);
+GLAPI GLboolean APIENTRY glUnmapBufferARB (GLenum target);
+GLAPI void APIENTRY glGetBufferParameterivARB (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetBufferPointervARB (GLenum target, GLenum pname, void **params);
+#endif
+#endif /* GL_ARB_vertex_buffer_object */
+
+#ifndef GL_ARB_vertex_program
+#define GL_ARB_vertex_program 1
+#define GL_COLOR_SUM_ARB 0x8458
+#define GL_VERTEX_PROGRAM_ARB 0x8620
+#define GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB 0x8622
+#define GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB 0x8623
+#define GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB 0x8624
+#define GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB 0x8625
+#define GL_CURRENT_VERTEX_ATTRIB_ARB 0x8626
+#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642
+#define GL_VERTEX_PROGRAM_TWO_SIDE_ARB 0x8643
+#define GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB 0x8645
+#define GL_MAX_VERTEX_ATTRIBS_ARB 0x8869
+#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB 0x886A
+#define GL_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B0
+#define GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B1
+#define GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B2
+#define GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B3
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1DARBPROC) (GLuint index, GLdouble x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVARBPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1FARBPROC) (GLuint index, GLfloat x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVARBPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1SARBPROC) (GLuint index, GLshort x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVARBPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2DARBPROC) (GLuint index, GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVARBPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2FARBPROC) (GLuint index, GLfloat x, GLfloat y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVARBPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2SARBPROC) (GLuint index, GLshort x, GLshort y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVARBPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVARBPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVARBPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVARBPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVARBPROC) (GLuint index, const GLbyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVARBPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVARBPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBARBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVARBPROC) (GLuint index, const GLubyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVARBPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVARBPROC) (GLuint index, const GLushort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVARBPROC) (GLuint index, const GLbyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVARBPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVARBPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVARBPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVARBPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVARBPROC) (GLuint index, const GLubyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVARBPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVARBPROC) (GLuint index, const GLushort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERARBPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYARBPROC) (GLuint index);
+typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) (GLuint index);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVARBPROC) (GLuint index, GLenum pname, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVARBPROC) (GLuint index, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVARBPROC) (GLuint index, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVARBPROC) (GLuint index, GLenum pname, void **pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexAttrib1dARB (GLuint index, GLdouble x);
+GLAPI void APIENTRY glVertexAttrib1dvARB (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib1fARB (GLuint index, GLfloat x);
+GLAPI void APIENTRY glVertexAttrib1fvARB (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib1sARB (GLuint index, GLshort x);
+GLAPI void APIENTRY glVertexAttrib1svARB (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib2dARB (GLuint index, GLdouble x, GLdouble y);
+GLAPI void APIENTRY glVertexAttrib2dvARB (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib2fARB (GLuint index, GLfloat x, GLfloat y);
+GLAPI void APIENTRY glVertexAttrib2fvARB (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib2sARB (GLuint index, GLshort x, GLshort y);
+GLAPI void APIENTRY glVertexAttrib2svARB (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib3dARB (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glVertexAttrib3dvARB (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib3fARB (GLuint index, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glVertexAttrib3fvARB (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib3sARB (GLuint index, GLshort x, GLshort y, GLshort z);
+GLAPI void APIENTRY glVertexAttrib3svARB (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib4NbvARB (GLuint index, const GLbyte *v);
+GLAPI void APIENTRY glVertexAttrib4NivARB (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttrib4NsvARB (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib4NubARB (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w);
+GLAPI void APIENTRY glVertexAttrib4NubvARB (GLuint index, const GLubyte *v);
+GLAPI void APIENTRY glVertexAttrib4NuivARB (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttrib4NusvARB (GLuint index, const GLushort *v);
+GLAPI void APIENTRY glVertexAttrib4bvARB (GLuint index, const GLbyte *v);
+GLAPI void APIENTRY glVertexAttrib4dARB (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glVertexAttrib4dvARB (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib4fARB (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glVertexAttrib4fvARB (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib4ivARB (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttrib4sARB (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w);
+GLAPI void APIENTRY glVertexAttrib4svARB (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib4ubvARB (GLuint index, const GLubyte *v);
+GLAPI void APIENTRY glVertexAttrib4uivARB (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttrib4usvARB (GLuint index, const GLushort *v);
+GLAPI void APIENTRY glVertexAttribPointerARB (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glEnableVertexAttribArrayARB (GLuint index);
+GLAPI void APIENTRY glDisableVertexAttribArrayARB (GLuint index);
+GLAPI void APIENTRY glGetVertexAttribdvARB (GLuint index, GLenum pname, GLdouble *params);
+GLAPI void APIENTRY glGetVertexAttribfvARB (GLuint index, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetVertexAttribivARB (GLuint index, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetVertexAttribPointervARB (GLuint index, GLenum pname, void **pointer);
+#endif
+#endif /* GL_ARB_vertex_program */
+
+#ifndef GL_ARB_vertex_shader
+#define GL_ARB_vertex_shader 1
+#define GL_VERTEX_SHADER_ARB 0x8B31
+#define GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB 0x8B4A
+#define GL_MAX_VARYING_FLOATS_ARB 0x8B4B
+#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB 0x8B4C
+#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB 0x8B4D
+#define GL_OBJECT_ACTIVE_ATTRIBUTES_ARB 0x8B89
+#define GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB 0x8B8A
+typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONARBPROC) (GLhandleARB programObj, GLuint index, const GLcharARB *name);
+typedef void (APIENTRYP PFNGLGETACTIVEATTRIBARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name);
+typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBindAttribLocationARB (GLhandleARB programObj, GLuint index, const GLcharARB *name);
+GLAPI void APIENTRY glGetActiveAttribARB (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name);
+GLAPI GLint APIENTRY glGetAttribLocationARB (GLhandleARB programObj, const GLcharARB *name);
+#endif
+#endif /* GL_ARB_vertex_shader */
+
+#ifndef GL_ARB_vertex_type_10f_11f_11f_rev
+#define GL_ARB_vertex_type_10f_11f_11f_rev 1
+#endif /* GL_ARB_vertex_type_10f_11f_11f_rev */
+
+#ifndef GL_ARB_vertex_type_2_10_10_10_rev
+#define GL_ARB_vertex_type_2_10_10_10_rev 1
+#endif /* GL_ARB_vertex_type_2_10_10_10_rev */
+
+#ifndef GL_ARB_viewport_array
+#define GL_ARB_viewport_array 1
+#endif /* GL_ARB_viewport_array */
+
+#ifndef GL_ARB_window_pos
+#define GL_ARB_window_pos 1
+typedef void (APIENTRYP PFNGLWINDOWPOS2DARBPROC) (GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2DVARBPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS2FARBPROC) (GLfloat x, GLfloat y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2FVARBPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS2IARBPROC) (GLint x, GLint y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2IVARBPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS2SARBPROC) (GLshort x, GLshort y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2SVARBPROC) (const GLshort *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3DARBPROC) (GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3DVARBPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3FARBPROC) (GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3FVARBPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3IARBPROC) (GLint x, GLint y, GLint z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3IVARBPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3SARBPROC) (GLshort x, GLshort y, GLshort z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3SVARBPROC) (const GLshort *v);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glWindowPos2dARB (GLdouble x, GLdouble y);
+GLAPI void APIENTRY glWindowPos2dvARB (const GLdouble *v);
+GLAPI void APIENTRY glWindowPos2fARB (GLfloat x, GLfloat y);
+GLAPI void APIENTRY glWindowPos2fvARB (const GLfloat *v);
+GLAPI void APIENTRY glWindowPos2iARB (GLint x, GLint y);
+GLAPI void APIENTRY glWindowPos2ivARB (const GLint *v);
+GLAPI void APIENTRY glWindowPos2sARB (GLshort x, GLshort y);
+GLAPI void APIENTRY glWindowPos2svARB (const GLshort *v);
+GLAPI void APIENTRY glWindowPos3dARB (GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glWindowPos3dvARB (const GLdouble *v);
+GLAPI void APIENTRY glWindowPos3fARB (GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glWindowPos3fvARB (const GLfloat *v);
+GLAPI void APIENTRY glWindowPos3iARB (GLint x, GLint y, GLint z);
+GLAPI void APIENTRY glWindowPos3ivARB (const GLint *v);
+GLAPI void APIENTRY glWindowPos3sARB (GLshort x, GLshort y, GLshort z);
+GLAPI void APIENTRY glWindowPos3svARB (const GLshort *v);
+#endif
+#endif /* GL_ARB_window_pos */
+
+#ifndef GL_KHR_debug
+#define GL_KHR_debug 1
+#endif /* GL_KHR_debug */
+
+#ifndef GL_KHR_texture_compression_astc_hdr
+#define GL_KHR_texture_compression_astc_hdr 1
+#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0
+#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1
+#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2
+#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3
+#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4
+#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5
+#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6
+#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7
+#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8
+#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9
+#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA
+#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB
+#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC
+#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD
+#endif /* GL_KHR_texture_compression_astc_hdr */
+
+#ifndef GL_KHR_texture_compression_astc_ldr
+#define GL_KHR_texture_compression_astc_ldr 1
+#endif /* GL_KHR_texture_compression_astc_ldr */
+
+#ifndef GL_OES_byte_coordinates
+#define GL_OES_byte_coordinates 1
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1BOESPROC) (GLenum texture, GLbyte s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1BVOESPROC) (GLenum texture, const GLbyte *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2BOESPROC) (GLenum texture, GLbyte s, GLbyte t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2BVOESPROC) (GLenum texture, const GLbyte *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3BOESPROC) (GLenum texture, GLbyte s, GLbyte t, GLbyte r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3BVOESPROC) (GLenum texture, const GLbyte *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4BOESPROC) (GLenum texture, GLbyte s, GLbyte t, GLbyte r, GLbyte q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4BVOESPROC) (GLenum texture, const GLbyte *coords);
+typedef void (APIENTRYP PFNGLTEXCOORD1BOESPROC) (GLbyte s);
+typedef void (APIENTRYP PFNGLTEXCOORD1BVOESPROC) (const GLbyte *coords);
+typedef void (APIENTRYP PFNGLTEXCOORD2BOESPROC) (GLbyte s, GLbyte t);
+typedef void (APIENTRYP PFNGLTEXCOORD2BVOESPROC) (const GLbyte *coords);
+typedef void (APIENTRYP PFNGLTEXCOORD3BOESPROC) (GLbyte s, GLbyte t, GLbyte r);
+typedef void (APIENTRYP PFNGLTEXCOORD3BVOESPROC) (const GLbyte *coords);
+typedef void (APIENTRYP PFNGLTEXCOORD4BOESPROC) (GLbyte s, GLbyte t, GLbyte r, GLbyte q);
+typedef void (APIENTRYP PFNGLTEXCOORD4BVOESPROC) (const GLbyte *coords);
+typedef void (APIENTRYP PFNGLVERTEX2BOESPROC) (GLbyte x);
+typedef void (APIENTRYP PFNGLVERTEX2BVOESPROC) (const GLbyte *coords);
+typedef void (APIENTRYP PFNGLVERTEX3BOESPROC) (GLbyte x, GLbyte y);
+typedef void (APIENTRYP PFNGLVERTEX3BVOESPROC) (const GLbyte *coords);
+typedef void (APIENTRYP PFNGLVERTEX4BOESPROC) (GLbyte x, GLbyte y, GLbyte z);
+typedef void (APIENTRYP PFNGLVERTEX4BVOESPROC) (const GLbyte *coords);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMultiTexCoord1bOES (GLenum texture, GLbyte s);
+GLAPI void APIENTRY glMultiTexCoord1bvOES (GLenum texture, const GLbyte *coords);
+GLAPI void APIENTRY glMultiTexCoord2bOES (GLenum texture, GLbyte s, GLbyte t);
+GLAPI void APIENTRY glMultiTexCoord2bvOES (GLenum texture, const GLbyte *coords);
+GLAPI void APIENTRY glMultiTexCoord3bOES (GLenum texture, GLbyte s, GLbyte t, GLbyte r);
+GLAPI void APIENTRY glMultiTexCoord3bvOES (GLenum texture, const GLbyte *coords);
+GLAPI void APIENTRY glMultiTexCoord4bOES (GLenum texture, GLbyte s, GLbyte t, GLbyte r, GLbyte q);
+GLAPI void APIENTRY glMultiTexCoord4bvOES (GLenum texture, const GLbyte *coords);
+GLAPI void APIENTRY glTexCoord1bOES (GLbyte s);
+GLAPI void APIENTRY glTexCoord1bvOES (const GLbyte *coords);
+GLAPI void APIENTRY glTexCoord2bOES (GLbyte s, GLbyte t);
+GLAPI void APIENTRY glTexCoord2bvOES (const GLbyte *coords);
+GLAPI void APIENTRY glTexCoord3bOES (GLbyte s, GLbyte t, GLbyte r);
+GLAPI void APIENTRY glTexCoord3bvOES (const GLbyte *coords);
+GLAPI void APIENTRY glTexCoord4bOES (GLbyte s, GLbyte t, GLbyte r, GLbyte q);
+GLAPI void APIENTRY glTexCoord4bvOES (const GLbyte *coords);
+GLAPI void APIENTRY glVertex2bOES (GLbyte x);
+GLAPI void APIENTRY glVertex2bvOES (const GLbyte *coords);
+GLAPI void APIENTRY glVertex3bOES (GLbyte x, GLbyte y);
+GLAPI void APIENTRY glVertex3bvOES (const GLbyte *coords);
+GLAPI void APIENTRY glVertex4bOES (GLbyte x, GLbyte y, GLbyte z);
+GLAPI void APIENTRY glVertex4bvOES (const GLbyte *coords);
+#endif
+#endif /* GL_OES_byte_coordinates */
+
+#ifndef GL_OES_compressed_paletted_texture
+#define GL_OES_compressed_paletted_texture 1
+#define GL_PALETTE4_RGB8_OES 0x8B90
+#define GL_PALETTE4_RGBA8_OES 0x8B91
+#define GL_PALETTE4_R5_G6_B5_OES 0x8B92
+#define GL_PALETTE4_RGBA4_OES 0x8B93
+#define GL_PALETTE4_RGB5_A1_OES 0x8B94
+#define GL_PALETTE8_RGB8_OES 0x8B95
+#define GL_PALETTE8_RGBA8_OES 0x8B96
+#define GL_PALETTE8_R5_G6_B5_OES 0x8B97
+#define GL_PALETTE8_RGBA4_OES 0x8B98
+#define GL_PALETTE8_RGB5_A1_OES 0x8B99
+#endif /* GL_OES_compressed_paletted_texture */
+
+#ifndef GL_OES_fixed_point
+#define GL_OES_fixed_point 1
+typedef GLint GLfixed;
+#define GL_FIXED_OES 0x140C
+typedef void (APIENTRYP PFNGLALPHAFUNCXOESPROC) (GLenum func, GLfixed ref);
+typedef void (APIENTRYP PFNGLCLEARCOLORXOESPROC) (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha);
+typedef void (APIENTRYP PFNGLCLEARDEPTHXOESPROC) (GLfixed depth);
+typedef void (APIENTRYP PFNGLCLIPPLANEXOESPROC) (GLenum plane, const GLfixed *equation);
+typedef void (APIENTRYP PFNGLCOLOR4XOESPROC) (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha);
+typedef void (APIENTRYP PFNGLDEPTHRANGEXOESPROC) (GLfixed n, GLfixed f);
+typedef void (APIENTRYP PFNGLFOGXOESPROC) (GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLFOGXVOESPROC) (GLenum pname, const GLfixed *param);
+typedef void (APIENTRYP PFNGLFRUSTUMXOESPROC) (GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f);
+typedef void (APIENTRYP PFNGLGETCLIPPLANEXOESPROC) (GLenum plane, GLfixed *equation);
+typedef void (APIENTRYP PFNGLGETFIXEDVOESPROC) (GLenum pname, GLfixed *params);
+typedef void (APIENTRYP PFNGLGETTEXENVXVOESPROC) (GLenum target, GLenum pname, GLfixed *params);
+typedef void (APIENTRYP PFNGLGETTEXPARAMETERXVOESPROC) (GLenum target, GLenum pname, GLfixed *params);
+typedef void (APIENTRYP PFNGLLIGHTMODELXOESPROC) (GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLLIGHTMODELXVOESPROC) (GLenum pname, const GLfixed *param);
+typedef void (APIENTRYP PFNGLLIGHTXOESPROC) (GLenum light, GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLLIGHTXVOESPROC) (GLenum light, GLenum pname, const GLfixed *params);
+typedef void (APIENTRYP PFNGLLINEWIDTHXOESPROC) (GLfixed width);
+typedef void (APIENTRYP PFNGLLOADMATRIXXOESPROC) (const GLfixed *m);
+typedef void (APIENTRYP PFNGLMATERIALXOESPROC) (GLenum face, GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLMATERIALXVOESPROC) (GLenum face, GLenum pname, const GLfixed *param);
+typedef void (APIENTRYP PFNGLMULTMATRIXXOESPROC) (const GLfixed *m);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4XOESPROC) (GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q);
+typedef void (APIENTRYP PFNGLNORMAL3XOESPROC) (GLfixed nx, GLfixed ny, GLfixed nz);
+typedef void (APIENTRYP PFNGLORTHOXOESPROC) (GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f);
+typedef void (APIENTRYP PFNGLPOINTPARAMETERXVOESPROC) (GLenum pname, const GLfixed *params);
+typedef void (APIENTRYP PFNGLPOINTSIZEXOESPROC) (GLfixed size);
+typedef void (APIENTRYP PFNGLPOLYGONOFFSETXOESPROC) (GLfixed factor, GLfixed units);
+typedef void (APIENTRYP PFNGLROTATEXOESPROC) (GLfixed angle, GLfixed x, GLfixed y, GLfixed z);
+typedef void (APIENTRYP PFNGLSAMPLECOVERAGEOESPROC) (GLfixed value, GLboolean invert);
+typedef void (APIENTRYP PFNGLSCALEXOESPROC) (GLfixed x, GLfixed y, GLfixed z);
+typedef void (APIENTRYP PFNGLTEXENVXOESPROC) (GLenum target, GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLTEXENVXVOESPROC) (GLenum target, GLenum pname, const GLfixed *params);
+typedef void (APIENTRYP PFNGLTEXPARAMETERXOESPROC) (GLenum target, GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLTEXPARAMETERXVOESPROC) (GLenum target, GLenum pname, const GLfixed *params);
+typedef void (APIENTRYP PFNGLTRANSLATEXOESPROC) (GLfixed x, GLfixed y, GLfixed z);
+typedef void (APIENTRYP PFNGLACCUMXOESPROC) (GLenum op, GLfixed value);
+typedef void (APIENTRYP PFNGLBITMAPXOESPROC) (GLsizei width, GLsizei height, GLfixed xorig, GLfixed yorig, GLfixed xmove, GLfixed ymove, const GLubyte *bitmap);
+typedef void (APIENTRYP PFNGLBLENDCOLORXOESPROC) (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha);
+typedef void (APIENTRYP PFNGLCLEARACCUMXOESPROC) (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha);
+typedef void (APIENTRYP PFNGLCOLOR3XOESPROC) (GLfixed red, GLfixed green, GLfixed blue);
+typedef void (APIENTRYP PFNGLCOLOR3XVOESPROC) (const GLfixed *components);
+typedef void (APIENTRYP PFNGLCOLOR4XVOESPROC) (const GLfixed *components);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERXOESPROC) (GLenum target, GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERXVOESPROC) (GLenum target, GLenum pname, const GLfixed *params);
+typedef void (APIENTRYP PFNGLEVALCOORD1XOESPROC) (GLfixed u);
+typedef void (APIENTRYP PFNGLEVALCOORD1XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLEVALCOORD2XOESPROC) (GLfixed u, GLfixed v);
+typedef void (APIENTRYP PFNGLEVALCOORD2XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLFEEDBACKBUFFERXOESPROC) (GLsizei n, GLenum type, const GLfixed *buffer);
+typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERXVOESPROC) (GLenum target, GLenum pname, GLfixed *params);
+typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERXVOESPROC) (GLenum target, GLenum pname, GLfixed *params);
+typedef void (APIENTRYP PFNGLGETLIGHTXOESPROC) (GLenum light, GLenum pname, GLfixed *params);
+typedef void (APIENTRYP PFNGLGETMAPXVOESPROC) (GLenum target, GLenum query, GLfixed *v);
+typedef void (APIENTRYP PFNGLGETMATERIALXOESPROC) (GLenum face, GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLGETPIXELMAPXVPROC) (GLenum map, GLint size, GLfixed *values);
+typedef void (APIENTRYP PFNGLGETTEXGENXVOESPROC) (GLenum coord, GLenum pname, GLfixed *params);
+typedef void (APIENTRYP PFNGLGETTEXLEVELPARAMETERXVOESPROC) (GLenum target, GLint level, GLenum pname, GLfixed *params);
+typedef void (APIENTRYP PFNGLINDEXXOESPROC) (GLfixed component);
+typedef void (APIENTRYP PFNGLINDEXXVOESPROC) (const GLfixed *component);
+typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXXOESPROC) (const GLfixed *m);
+typedef void (APIENTRYP PFNGLMAP1XOESPROC) (GLenum target, GLfixed u1, GLfixed u2, GLint stride, GLint order, GLfixed points);
+typedef void (APIENTRYP PFNGLMAP2XOESPROC) (GLenum target, GLfixed u1, GLfixed u2, GLint ustride, GLint uorder, GLfixed v1, GLfixed v2, GLint vstride, GLint vorder, GLfixed points);
+typedef void (APIENTRYP PFNGLMAPGRID1XOESPROC) (GLint n, GLfixed u1, GLfixed u2);
+typedef void (APIENTRYP PFNGLMAPGRID2XOESPROC) (GLint n, GLfixed u1, GLfixed u2, GLfixed v1, GLfixed v2);
+typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXXOESPROC) (const GLfixed *m);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1XOESPROC) (GLenum texture, GLfixed s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1XVOESPROC) (GLenum texture, const GLfixed *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2XOESPROC) (GLenum texture, GLfixed s, GLfixed t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2XVOESPROC) (GLenum texture, const GLfixed *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3XOESPROC) (GLenum texture, GLfixed s, GLfixed t, GLfixed r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3XVOESPROC) (GLenum texture, const GLfixed *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4XVOESPROC) (GLenum texture, const GLfixed *coords);
+typedef void (APIENTRYP PFNGLNORMAL3XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLPASSTHROUGHXOESPROC) (GLfixed token);
+typedef void (APIENTRYP PFNGLPIXELMAPXPROC) (GLenum map, GLint size, const GLfixed *values);
+typedef void (APIENTRYP PFNGLPIXELSTOREXPROC) (GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLPIXELTRANSFERXOESPROC) (GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLPIXELZOOMXOESPROC) (GLfixed xfactor, GLfixed yfactor);
+typedef void (APIENTRYP PFNGLPRIORITIZETEXTURESXOESPROC) (GLsizei n, const GLuint *textures, const GLfixed *priorities);
+typedef void (APIENTRYP PFNGLRASTERPOS2XOESPROC) (GLfixed x, GLfixed y);
+typedef void (APIENTRYP PFNGLRASTERPOS2XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLRASTERPOS3XOESPROC) (GLfixed x, GLfixed y, GLfixed z);
+typedef void (APIENTRYP PFNGLRASTERPOS3XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLRASTERPOS4XOESPROC) (GLfixed x, GLfixed y, GLfixed z, GLfixed w);
+typedef void (APIENTRYP PFNGLRASTERPOS4XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLRECTXOESPROC) (GLfixed x1, GLfixed y1, GLfixed x2, GLfixed y2);
+typedef void (APIENTRYP PFNGLRECTXVOESPROC) (const GLfixed *v1, const GLfixed *v2);
+typedef void (APIENTRYP PFNGLTEXCOORD1XOESPROC) (GLfixed s);
+typedef void (APIENTRYP PFNGLTEXCOORD1XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLTEXCOORD2XOESPROC) (GLfixed s, GLfixed t);
+typedef void (APIENTRYP PFNGLTEXCOORD2XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLTEXCOORD3XOESPROC) (GLfixed s, GLfixed t, GLfixed r);
+typedef void (APIENTRYP PFNGLTEXCOORD3XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLTEXCOORD4XOESPROC) (GLfixed s, GLfixed t, GLfixed r, GLfixed q);
+typedef void (APIENTRYP PFNGLTEXCOORD4XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLTEXGENXOESPROC) (GLenum coord, GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLTEXGENXVOESPROC) (GLenum coord, GLenum pname, const GLfixed *params);
+typedef void (APIENTRYP PFNGLVERTEX2XOESPROC) (GLfixed x);
+typedef void (APIENTRYP PFNGLVERTEX2XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLVERTEX3XOESPROC) (GLfixed x, GLfixed y);
+typedef void (APIENTRYP PFNGLVERTEX3XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLVERTEX4XOESPROC) (GLfixed x, GLfixed y, GLfixed z);
+typedef void (APIENTRYP PFNGLVERTEX4XVOESPROC) (const GLfixed *coords);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glAlphaFuncxOES (GLenum func, GLfixed ref);
+GLAPI void APIENTRY glClearColorxOES (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha);
+GLAPI void APIENTRY glClearDepthxOES (GLfixed depth);
+GLAPI void APIENTRY glClipPlanexOES (GLenum plane, const GLfixed *equation);
+GLAPI void APIENTRY glColor4xOES (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha);
+GLAPI void APIENTRY glDepthRangexOES (GLfixed n, GLfixed f);
+GLAPI void APIENTRY glFogxOES (GLenum pname, GLfixed param);
+GLAPI void APIENTRY glFogxvOES (GLenum pname, const GLfixed *param);
+GLAPI void APIENTRY glFrustumxOES (GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f);
+GLAPI void APIENTRY glGetClipPlanexOES (GLenum plane, GLfixed *equation);
+GLAPI void APIENTRY glGetFixedvOES (GLenum pname, GLfixed *params);
+GLAPI void APIENTRY glGetTexEnvxvOES (GLenum target, GLenum pname, GLfixed *params);
+GLAPI void APIENTRY glGetTexParameterxvOES (GLenum target, GLenum pname, GLfixed *params);
+GLAPI void APIENTRY glLightModelxOES (GLenum pname, GLfixed param);
+GLAPI void APIENTRY glLightModelxvOES (GLenum pname, const GLfixed *param);
+GLAPI void APIENTRY glLightxOES (GLenum light, GLenum pname, GLfixed param);
+GLAPI void APIENTRY glLightxvOES (GLenum light, GLenum pname, const GLfixed *params);
+GLAPI void APIENTRY glLineWidthxOES (GLfixed width);
+GLAPI void APIENTRY glLoadMatrixxOES (const GLfixed *m);
+GLAPI void APIENTRY glMaterialxOES (GLenum face, GLenum pname, GLfixed param);
+GLAPI void APIENTRY glMaterialxvOES (GLenum face, GLenum pname, const GLfixed *param);
+GLAPI void APIENTRY glMultMatrixxOES (const GLfixed *m);
+GLAPI void APIENTRY glMultiTexCoord4xOES (GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q);
+GLAPI void APIENTRY glNormal3xOES (GLfixed nx, GLfixed ny, GLfixed nz);
+GLAPI void APIENTRY glOrthoxOES (GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f);
+GLAPI void APIENTRY glPointParameterxvOES (GLenum pname, const GLfixed *params);
+GLAPI void APIENTRY glPointSizexOES (GLfixed size);
+GLAPI void APIENTRY glPolygonOffsetxOES (GLfixed factor, GLfixed units);
+GLAPI void APIENTRY glRotatexOES (GLfixed angle, GLfixed x, GLfixed y, GLfixed z);
+GLAPI void APIENTRY glSampleCoverageOES (GLfixed value, GLboolean invert);
+GLAPI void APIENTRY glScalexOES (GLfixed x, GLfixed y, GLfixed z);
+GLAPI void APIENTRY glTexEnvxOES (GLenum target, GLenum pname, GLfixed param);
+GLAPI void APIENTRY glTexEnvxvOES (GLenum target, GLenum pname, const GLfixed *params);
+GLAPI void APIENTRY glTexParameterxOES (GLenum target, GLenum pname, GLfixed param);
+GLAPI void APIENTRY glTexParameterxvOES (GLenum target, GLenum pname, const GLfixed *params);
+GLAPI void APIENTRY glTranslatexOES (GLfixed x, GLfixed y, GLfixed z);
+GLAPI void APIENTRY glAccumxOES (GLenum op, GLfixed value);
+GLAPI void APIENTRY glBitmapxOES (GLsizei width, GLsizei height, GLfixed xorig, GLfixed yorig, GLfixed xmove, GLfixed ymove, const GLubyte *bitmap);
+GLAPI void APIENTRY glBlendColorxOES (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha);
+GLAPI void APIENTRY glClearAccumxOES (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha);
+GLAPI void APIENTRY glColor3xOES (GLfixed red, GLfixed green, GLfixed blue);
+GLAPI void APIENTRY glColor3xvOES (const GLfixed *components);
+GLAPI void APIENTRY glColor4xvOES (const GLfixed *components);
+GLAPI void APIENTRY glConvolutionParameterxOES (GLenum target, GLenum pname, GLfixed param);
+GLAPI void APIENTRY glConvolutionParameterxvOES (GLenum target, GLenum pname, const GLfixed *params);
+GLAPI void APIENTRY glEvalCoord1xOES (GLfixed u);
+GLAPI void APIENTRY glEvalCoord1xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glEvalCoord2xOES (GLfixed u, GLfixed v);
+GLAPI void APIENTRY glEvalCoord2xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glFeedbackBufferxOES (GLsizei n, GLenum type, const GLfixed *buffer);
+GLAPI void APIENTRY glGetConvolutionParameterxvOES (GLenum target, GLenum pname, GLfixed *params);
+GLAPI void APIENTRY glGetHistogramParameterxvOES (GLenum target, GLenum pname, GLfixed *params);
+GLAPI void APIENTRY glGetLightxOES (GLenum light, GLenum pname, GLfixed *params);
+GLAPI void APIENTRY glGetMapxvOES (GLenum target, GLenum query, GLfixed *v);
+GLAPI void APIENTRY glGetMaterialxOES (GLenum face, GLenum pname, GLfixed param);
+GLAPI void APIENTRY glGetPixelMapxv (GLenum map, GLint size, GLfixed *values);
+GLAPI void APIENTRY glGetTexGenxvOES (GLenum coord, GLenum pname, GLfixed *params);
+GLAPI void APIENTRY glGetTexLevelParameterxvOES (GLenum target, GLint level, GLenum pname, GLfixed *params);
+GLAPI void APIENTRY glIndexxOES (GLfixed component);
+GLAPI void APIENTRY glIndexxvOES (const GLfixed *component);
+GLAPI void APIENTRY glLoadTransposeMatrixxOES (const GLfixed *m);
+GLAPI void APIENTRY glMap1xOES (GLenum target, GLfixed u1, GLfixed u2, GLint stride, GLint order, GLfixed points);
+GLAPI void APIENTRY glMap2xOES (GLenum target, GLfixed u1, GLfixed u2, GLint ustride, GLint uorder, GLfixed v1, GLfixed v2, GLint vstride, GLint vorder, GLfixed points);
+GLAPI void APIENTRY glMapGrid1xOES (GLint n, GLfixed u1, GLfixed u2);
+GLAPI void APIENTRY glMapGrid2xOES (GLint n, GLfixed u1, GLfixed u2, GLfixed v1, GLfixed v2);
+GLAPI void APIENTRY glMultTransposeMatrixxOES (const GLfixed *m);
+GLAPI void APIENTRY glMultiTexCoord1xOES (GLenum texture, GLfixed s);
+GLAPI void APIENTRY glMultiTexCoord1xvOES (GLenum texture, const GLfixed *coords);
+GLAPI void APIENTRY glMultiTexCoord2xOES (GLenum texture, GLfixed s, GLfixed t);
+GLAPI void APIENTRY glMultiTexCoord2xvOES (GLenum texture, const GLfixed *coords);
+GLAPI void APIENTRY glMultiTexCoord3xOES (GLenum texture, GLfixed s, GLfixed t, GLfixed r);
+GLAPI void APIENTRY glMultiTexCoord3xvOES (GLenum texture, const GLfixed *coords);
+GLAPI void APIENTRY glMultiTexCoord4xvOES (GLenum texture, const GLfixed *coords);
+GLAPI void APIENTRY glNormal3xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glPassThroughxOES (GLfixed token);
+GLAPI void APIENTRY glPixelMapx (GLenum map, GLint size, const GLfixed *values);
+GLAPI void APIENTRY glPixelStorex (GLenum pname, GLfixed param);
+GLAPI void APIENTRY glPixelTransferxOES (GLenum pname, GLfixed param);
+GLAPI void APIENTRY glPixelZoomxOES (GLfixed xfactor, GLfixed yfactor);
+GLAPI void APIENTRY glPrioritizeTexturesxOES (GLsizei n, const GLuint *textures, const GLfixed *priorities);
+GLAPI void APIENTRY glRasterPos2xOES (GLfixed x, GLfixed y);
+GLAPI void APIENTRY glRasterPos2xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glRasterPos3xOES (GLfixed x, GLfixed y, GLfixed z);
+GLAPI void APIENTRY glRasterPos3xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glRasterPos4xOES (GLfixed x, GLfixed y, GLfixed z, GLfixed w);
+GLAPI void APIENTRY glRasterPos4xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glRectxOES (GLfixed x1, GLfixed y1, GLfixed x2, GLfixed y2);
+GLAPI void APIENTRY glRectxvOES (const GLfixed *v1, const GLfixed *v2);
+GLAPI void APIENTRY glTexCoord1xOES (GLfixed s);
+GLAPI void APIENTRY glTexCoord1xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glTexCoord2xOES (GLfixed s, GLfixed t);
+GLAPI void APIENTRY glTexCoord2xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glTexCoord3xOES (GLfixed s, GLfixed t, GLfixed r);
+GLAPI void APIENTRY glTexCoord3xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glTexCoord4xOES (GLfixed s, GLfixed t, GLfixed r, GLfixed q);
+GLAPI void APIENTRY glTexCoord4xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glTexGenxOES (GLenum coord, GLenum pname, GLfixed param);
+GLAPI void APIENTRY glTexGenxvOES (GLenum coord, GLenum pname, const GLfixed *params);
+GLAPI void APIENTRY glVertex2xOES (GLfixed x);
+GLAPI void APIENTRY glVertex2xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glVertex3xOES (GLfixed x, GLfixed y);
+GLAPI void APIENTRY glVertex3xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glVertex4xOES (GLfixed x, GLfixed y, GLfixed z);
+GLAPI void APIENTRY glVertex4xvOES (const GLfixed *coords);
+#endif
+#endif /* GL_OES_fixed_point */
+
+#ifndef GL_OES_query_matrix
+#define GL_OES_query_matrix 1
+typedef GLbitfield (APIENTRYP PFNGLQUERYMATRIXXOESPROC) (GLfixed *mantissa, GLint *exponent);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLbitfield APIENTRY glQueryMatrixxOES (GLfixed *mantissa, GLint *exponent);
+#endif
+#endif /* GL_OES_query_matrix */
+
+#ifndef GL_OES_read_format
+#define GL_OES_read_format 1
+#define GL_IMPLEMENTATION_COLOR_READ_TYPE_OES 0x8B9A
+#define GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES 0x8B9B
+#endif /* GL_OES_read_format */
+
+#ifndef GL_OES_single_precision
+#define GL_OES_single_precision 1
+typedef void (APIENTRYP PFNGLCLEARDEPTHFOESPROC) (GLclampf depth);
+typedef void (APIENTRYP PFNGLCLIPPLANEFOESPROC) (GLenum plane, const GLfloat *equation);
+typedef void (APIENTRYP PFNGLDEPTHRANGEFOESPROC) (GLclampf n, GLclampf f);
+typedef void (APIENTRYP PFNGLFRUSTUMFOESPROC) (GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f);
+typedef void (APIENTRYP PFNGLGETCLIPPLANEFOESPROC) (GLenum plane, GLfloat *equation);
+typedef void (APIENTRYP PFNGLORTHOFOESPROC) (GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glClearDepthfOES (GLclampf depth);
+GLAPI void APIENTRY glClipPlanefOES (GLenum plane, const GLfloat *equation);
+GLAPI void APIENTRY glDepthRangefOES (GLclampf n, GLclampf f);
+GLAPI void APIENTRY glFrustumfOES (GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f);
+GLAPI void APIENTRY glGetClipPlanefOES (GLenum plane, GLfloat *equation);
+GLAPI void APIENTRY glOrthofOES (GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f);
+#endif
+#endif /* GL_OES_single_precision */
+
+#ifndef GL_3DFX_multisample
+#define GL_3DFX_multisample 1
+#define GL_MULTISAMPLE_3DFX 0x86B2
+#define GL_SAMPLE_BUFFERS_3DFX 0x86B3
+#define GL_SAMPLES_3DFX 0x86B4
+#define GL_MULTISAMPLE_BIT_3DFX 0x20000000
+#endif /* GL_3DFX_multisample */
+
+#ifndef GL_3DFX_tbuffer
+#define GL_3DFX_tbuffer 1
+typedef void (APIENTRYP PFNGLTBUFFERMASK3DFXPROC) (GLuint mask);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTbufferMask3DFX (GLuint mask);
+#endif
+#endif /* GL_3DFX_tbuffer */
+
+#ifndef GL_3DFX_texture_compression_FXT1
+#define GL_3DFX_texture_compression_FXT1 1
+#define GL_COMPRESSED_RGB_FXT1_3DFX 0x86B0
+#define GL_COMPRESSED_RGBA_FXT1_3DFX 0x86B1
+#endif /* GL_3DFX_texture_compression_FXT1 */
+
+#ifndef GL_AMD_blend_minmax_factor
+#define GL_AMD_blend_minmax_factor 1
+#define GL_FACTOR_MIN_AMD 0x901C
+#define GL_FACTOR_MAX_AMD 0x901D
+#endif /* GL_AMD_blend_minmax_factor */
+
+#ifndef GL_AMD_conservative_depth
+#define GL_AMD_conservative_depth 1
+#endif /* GL_AMD_conservative_depth */
+
+#ifndef GL_AMD_debug_output
+#define GL_AMD_debug_output 1
+typedef void (APIENTRY *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,void *userParam);
+#define GL_MAX_DEBUG_MESSAGE_LENGTH_AMD 0x9143
+#define GL_MAX_DEBUG_LOGGED_MESSAGES_AMD 0x9144
+#define GL_DEBUG_LOGGED_MESSAGES_AMD 0x9145
+#define GL_DEBUG_SEVERITY_HIGH_AMD 0x9146
+#define GL_DEBUG_SEVERITY_MEDIUM_AMD 0x9147
+#define GL_DEBUG_SEVERITY_LOW_AMD 0x9148
+#define GL_DEBUG_CATEGORY_API_ERROR_AMD 0x9149
+#define GL_DEBUG_CATEGORY_WINDOW_SYSTEM_AMD 0x914A
+#define GL_DEBUG_CATEGORY_DEPRECATION_AMD 0x914B
+#define GL_DEBUG_CATEGORY_UNDEFINED_BEHAVIOR_AMD 0x914C
+#define GL_DEBUG_CATEGORY_PERFORMANCE_AMD 0x914D
+#define GL_DEBUG_CATEGORY_SHADER_COMPILER_AMD 0x914E
+#define GL_DEBUG_CATEGORY_APPLICATION_AMD 0x914F
+#define GL_DEBUG_CATEGORY_OTHER_AMD 0x9150
+typedef void (APIENTRYP PFNGLDEBUGMESSAGEENABLEAMDPROC) (GLenum category, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
+typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTAMDPROC) (GLenum category, GLenum severity, GLuint id, GLsizei length, const GLchar *buf);
+typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKAMDPROC) (GLDEBUGPROCAMD callback, void *userParam);
+typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGAMDPROC) (GLuint count, GLsizei bufsize, GLenum *categories, GLuint *severities, GLuint *ids, GLsizei *lengths, GLchar *message);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDebugMessageEnableAMD (GLenum category, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
+GLAPI void APIENTRY glDebugMessageInsertAMD (GLenum category, GLenum severity, GLuint id, GLsizei length, const GLchar *buf);
+GLAPI void APIENTRY glDebugMessageCallbackAMD (GLDEBUGPROCAMD callback, void *userParam);
+GLAPI GLuint APIENTRY glGetDebugMessageLogAMD (GLuint count, GLsizei bufsize, GLenum *categories, GLuint *severities, GLuint *ids, GLsizei *lengths, GLchar *message);
+#endif
+#endif /* GL_AMD_debug_output */
+
+#ifndef GL_AMD_depth_clamp_separate
+#define GL_AMD_depth_clamp_separate 1
+#define GL_DEPTH_CLAMP_NEAR_AMD 0x901E
+#define GL_DEPTH_CLAMP_FAR_AMD 0x901F
+#endif /* GL_AMD_depth_clamp_separate */
+
+#ifndef GL_AMD_draw_buffers_blend
+#define GL_AMD_draw_buffers_blend 1
+typedef void (APIENTRYP PFNGLBLENDFUNCINDEXEDAMDPROC) (GLuint buf, GLenum src, GLenum dst);
+typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINDEXEDAMDPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+typedef void (APIENTRYP PFNGLBLENDEQUATIONINDEXEDAMDPROC) (GLuint buf, GLenum mode);
+typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEINDEXEDAMDPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendFuncIndexedAMD (GLuint buf, GLenum src, GLenum dst);
+GLAPI void APIENTRY glBlendFuncSeparateIndexedAMD (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+GLAPI void APIENTRY glBlendEquationIndexedAMD (GLuint buf, GLenum mode);
+GLAPI void APIENTRY glBlendEquationSeparateIndexedAMD (GLuint buf, GLenum modeRGB, GLenum modeAlpha);
+#endif
+#endif /* GL_AMD_draw_buffers_blend */
+
+#ifndef GL_AMD_gcn_shader
+#define GL_AMD_gcn_shader 1
+#endif /* GL_AMD_gcn_shader */
+
+#ifndef GL_AMD_gpu_shader_int64
+#define GL_AMD_gpu_shader_int64 1
+typedef int64_t GLint64EXT;
+#define GL_INT64_NV 0x140E
+#define GL_UNSIGNED_INT64_NV 0x140F
+#define GL_INT8_NV 0x8FE0
+#define GL_INT8_VEC2_NV 0x8FE1
+#define GL_INT8_VEC3_NV 0x8FE2
+#define GL_INT8_VEC4_NV 0x8FE3
+#define GL_INT16_NV 0x8FE4
+#define GL_INT16_VEC2_NV 0x8FE5
+#define GL_INT16_VEC3_NV 0x8FE6
+#define GL_INT16_VEC4_NV 0x8FE7
+#define GL_INT64_VEC2_NV 0x8FE9
+#define GL_INT64_VEC3_NV 0x8FEA
+#define GL_INT64_VEC4_NV 0x8FEB
+#define GL_UNSIGNED_INT8_NV 0x8FEC
+#define GL_UNSIGNED_INT8_VEC2_NV 0x8FED
+#define GL_UNSIGNED_INT8_VEC3_NV 0x8FEE
+#define GL_UNSIGNED_INT8_VEC4_NV 0x8FEF
+#define GL_UNSIGNED_INT16_NV 0x8FF0
+#define GL_UNSIGNED_INT16_VEC2_NV 0x8FF1
+#define GL_UNSIGNED_INT16_VEC3_NV 0x8FF2
+#define GL_UNSIGNED_INT16_VEC4_NV 0x8FF3
+#define GL_UNSIGNED_INT64_VEC2_NV 0x8FF5
+#define GL_UNSIGNED_INT64_VEC3_NV 0x8FF6
+#define GL_UNSIGNED_INT64_VEC4_NV 0x8FF7
+#define GL_FLOAT16_NV 0x8FF8
+#define GL_FLOAT16_VEC2_NV 0x8FF9
+#define GL_FLOAT16_VEC3_NV 0x8FFA
+#define GL_FLOAT16_VEC4_NV 0x8FFB
+typedef void (APIENTRYP PFNGLUNIFORM1I64NVPROC) (GLint location, GLint64EXT x);
+typedef void (APIENTRYP PFNGLUNIFORM2I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y);
+typedef void (APIENTRYP PFNGLUNIFORM3I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z);
+typedef void (APIENTRYP PFNGLUNIFORM4I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
+typedef void (APIENTRYP PFNGLUNIFORM1I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (APIENTRYP PFNGLUNIFORM2I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (APIENTRYP PFNGLUNIFORM3I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (APIENTRYP PFNGLUNIFORM4I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (APIENTRYP PFNGLUNIFORM1UI64NVPROC) (GLint location, GLuint64EXT x);
+typedef void (APIENTRYP PFNGLUNIFORM2UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y);
+typedef void (APIENTRYP PFNGLUNIFORM3UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
+typedef void (APIENTRYP PFNGLUNIFORM4UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
+typedef void (APIENTRYP PFNGLUNIFORM1UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (APIENTRYP PFNGLUNIFORM2UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (APIENTRYP PFNGLUNIFORM3UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (APIENTRYP PFNGLUNIFORM4UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (APIENTRYP PFNGLGETUNIFORMI64VNVPROC) (GLuint program, GLint location, GLint64EXT *params);
+typedef void (APIENTRYP PFNGLGETUNIFORMUI64VNVPROC) (GLuint program, GLint location, GLuint64EXT *params);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1I64NVPROC) (GLuint program, GLint location, GLint64EXT x);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glUniform1i64NV (GLint location, GLint64EXT x);
+GLAPI void APIENTRY glUniform2i64NV (GLint location, GLint64EXT x, GLint64EXT y);
+GLAPI void APIENTRY glUniform3i64NV (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z);
+GLAPI void APIENTRY glUniform4i64NV (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
+GLAPI void APIENTRY glUniform1i64vNV (GLint location, GLsizei count, const GLint64EXT *value);
+GLAPI void APIENTRY glUniform2i64vNV (GLint location, GLsizei count, const GLint64EXT *value);
+GLAPI void APIENTRY glUniform3i64vNV (GLint location, GLsizei count, const GLint64EXT *value);
+GLAPI void APIENTRY glUniform4i64vNV (GLint location, GLsizei count, const GLint64EXT *value);
+GLAPI void APIENTRY glUniform1ui64NV (GLint location, GLuint64EXT x);
+GLAPI void APIENTRY glUniform2ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y);
+GLAPI void APIENTRY glUniform3ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
+GLAPI void APIENTRY glUniform4ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
+GLAPI void APIENTRY glUniform1ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value);
+GLAPI void APIENTRY glUniform2ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value);
+GLAPI void APIENTRY glUniform3ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value);
+GLAPI void APIENTRY glUniform4ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value);
+GLAPI void APIENTRY glGetUniformi64vNV (GLuint program, GLint location, GLint64EXT *params);
+GLAPI void APIENTRY glGetUniformui64vNV (GLuint program, GLint location, GLuint64EXT *params);
+GLAPI void APIENTRY glProgramUniform1i64NV (GLuint program, GLint location, GLint64EXT x);
+GLAPI void APIENTRY glProgramUniform2i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y);
+GLAPI void APIENTRY glProgramUniform3i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z);
+GLAPI void APIENTRY glProgramUniform4i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
+GLAPI void APIENTRY glProgramUniform1i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+GLAPI void APIENTRY glProgramUniform2i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+GLAPI void APIENTRY glProgramUniform3i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+GLAPI void APIENTRY glProgramUniform4i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+GLAPI void APIENTRY glProgramUniform1ui64NV (GLuint program, GLint location, GLuint64EXT x);
+GLAPI void APIENTRY glProgramUniform2ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y);
+GLAPI void APIENTRY glProgramUniform3ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
+GLAPI void APIENTRY glProgramUniform4ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
+GLAPI void APIENTRY glProgramUniform1ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+GLAPI void APIENTRY glProgramUniform2ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+GLAPI void APIENTRY glProgramUniform3ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+GLAPI void APIENTRY glProgramUniform4ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+#endif
+#endif /* GL_AMD_gpu_shader_int64 */
+
+#ifndef GL_AMD_interleaved_elements
+#define GL_AMD_interleaved_elements 1
+#define GL_VERTEX_ELEMENT_SWIZZLE_AMD 0x91A4
+#define GL_VERTEX_ID_SWIZZLE_AMD 0x91A5
+typedef void (APIENTRYP PFNGLVERTEXATTRIBPARAMETERIAMDPROC) (GLuint index, GLenum pname, GLint param);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexAttribParameteriAMD (GLuint index, GLenum pname, GLint param);
+#endif
+#endif /* GL_AMD_interleaved_elements */
+
+#ifndef GL_AMD_multi_draw_indirect
+#define GL_AMD_multi_draw_indirect 1
+typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTAMDPROC) (GLenum mode, const void *indirect, GLsizei primcount, GLsizei stride);
+typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTAMDPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei primcount, GLsizei stride);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMultiDrawArraysIndirectAMD (GLenum mode, const void *indirect, GLsizei primcount, GLsizei stride);
+GLAPI void APIENTRY glMultiDrawElementsIndirectAMD (GLenum mode, GLenum type, const void *indirect, GLsizei primcount, GLsizei stride);
+#endif
+#endif /* GL_AMD_multi_draw_indirect */
+
+#ifndef GL_AMD_name_gen_delete
+#define GL_AMD_name_gen_delete 1
+#define GL_DATA_BUFFER_AMD 0x9151
+#define GL_PERFORMANCE_MONITOR_AMD 0x9152
+#define GL_QUERY_OBJECT_AMD 0x9153
+#define GL_VERTEX_ARRAY_OBJECT_AMD 0x9154
+#define GL_SAMPLER_OBJECT_AMD 0x9155
+typedef void (APIENTRYP PFNGLGENNAMESAMDPROC) (GLenum identifier, GLuint num, GLuint *names);
+typedef void (APIENTRYP PFNGLDELETENAMESAMDPROC) (GLenum identifier, GLuint num, const GLuint *names);
+typedef GLboolean (APIENTRYP PFNGLISNAMEAMDPROC) (GLenum identifier, GLuint name);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGenNamesAMD (GLenum identifier, GLuint num, GLuint *names);
+GLAPI void APIENTRY glDeleteNamesAMD (GLenum identifier, GLuint num, const GLuint *names);
+GLAPI GLboolean APIENTRY glIsNameAMD (GLenum identifier, GLuint name);
+#endif
+#endif /* GL_AMD_name_gen_delete */
+
+#ifndef GL_AMD_occlusion_query_event
+#define GL_AMD_occlusion_query_event 1
+#define GL_OCCLUSION_QUERY_EVENT_MASK_AMD 0x874F
+#define GL_QUERY_DEPTH_PASS_EVENT_BIT_AMD 0x00000001
+#define GL_QUERY_DEPTH_FAIL_EVENT_BIT_AMD 0x00000002
+#define GL_QUERY_STENCIL_FAIL_EVENT_BIT_AMD 0x00000004
+#define GL_QUERY_DEPTH_BOUNDS_FAIL_EVENT_BIT_AMD 0x00000008
+#define GL_QUERY_ALL_EVENT_BITS_AMD 0xFFFFFFFF
+typedef void (APIENTRYP PFNGLQUERYOBJECTPARAMETERUIAMDPROC) (GLenum target, GLuint id, GLenum pname, GLuint param);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glQueryObjectParameteruiAMD (GLenum target, GLuint id, GLenum pname, GLuint param);
+#endif
+#endif /* GL_AMD_occlusion_query_event */
+
+#ifndef GL_AMD_performance_monitor
+#define GL_AMD_performance_monitor 1
+#define GL_COUNTER_TYPE_AMD 0x8BC0
+#define GL_COUNTER_RANGE_AMD 0x8BC1
+#define GL_UNSIGNED_INT64_AMD 0x8BC2
+#define GL_PERCENTAGE_AMD 0x8BC3
+#define GL_PERFMON_RESULT_AVAILABLE_AMD 0x8BC4
+#define GL_PERFMON_RESULT_SIZE_AMD 0x8BC5
+#define GL_PERFMON_RESULT_AMD 0x8BC6
+typedef void (APIENTRYP PFNGLGETPERFMONITORGROUPSAMDPROC) (GLint *numGroups, GLsizei groupsSize, GLuint *groups);
+typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERSAMDPROC) (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters);
+typedef void (APIENTRYP PFNGLGETPERFMONITORGROUPSTRINGAMDPROC) (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString);
+typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERSTRINGAMDPROC) (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString);
+typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERINFOAMDPROC) (GLuint group, GLuint counter, GLenum pname, void *data);
+typedef void (APIENTRYP PFNGLGENPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors);
+typedef void (APIENTRYP PFNGLDELETEPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors);
+typedef void (APIENTRYP PFNGLSELECTPERFMONITORCOUNTERSAMDPROC) (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *counterList);
+typedef void (APIENTRYP PFNGLBEGINPERFMONITORAMDPROC) (GLuint monitor);
+typedef void (APIENTRYP PFNGLENDPERFMONITORAMDPROC) (GLuint monitor);
+typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERDATAAMDPROC) (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGetPerfMonitorGroupsAMD (GLint *numGroups, GLsizei groupsSize, GLuint *groups);
+GLAPI void APIENTRY glGetPerfMonitorCountersAMD (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters);
+GLAPI void APIENTRY glGetPerfMonitorGroupStringAMD (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString);
+GLAPI void APIENTRY glGetPerfMonitorCounterStringAMD (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString);
+GLAPI void APIENTRY glGetPerfMonitorCounterInfoAMD (GLuint group, GLuint counter, GLenum pname, void *data);
+GLAPI void APIENTRY glGenPerfMonitorsAMD (GLsizei n, GLuint *monitors);
+GLAPI void APIENTRY glDeletePerfMonitorsAMD (GLsizei n, GLuint *monitors);
+GLAPI void APIENTRY glSelectPerfMonitorCountersAMD (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *counterList);
+GLAPI void APIENTRY glBeginPerfMonitorAMD (GLuint monitor);
+GLAPI void APIENTRY glEndPerfMonitorAMD (GLuint monitor);
+GLAPI void APIENTRY glGetPerfMonitorCounterDataAMD (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten);
+#endif
+#endif /* GL_AMD_performance_monitor */
+
+#ifndef GL_AMD_pinned_memory
+#define GL_AMD_pinned_memory 1
+#define GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD 0x9160
+#endif /* GL_AMD_pinned_memory */
+
+#ifndef GL_AMD_query_buffer_object
+#define GL_AMD_query_buffer_object 1
+#define GL_QUERY_BUFFER_AMD 0x9192
+#define GL_QUERY_BUFFER_BINDING_AMD 0x9193
+#define GL_QUERY_RESULT_NO_WAIT_AMD 0x9194
+#endif /* GL_AMD_query_buffer_object */
+
+#ifndef GL_AMD_sample_positions
+#define GL_AMD_sample_positions 1
+#define GL_SUBSAMPLE_DISTANCE_AMD 0x883F
+typedef void (APIENTRYP PFNGLSETMULTISAMPLEFVAMDPROC) (GLenum pname, GLuint index, const GLfloat *val);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glSetMultisamplefvAMD (GLenum pname, GLuint index, const GLfloat *val);
+#endif
+#endif /* GL_AMD_sample_positions */
+
+#ifndef GL_AMD_seamless_cubemap_per_texture
+#define GL_AMD_seamless_cubemap_per_texture 1
+#endif /* GL_AMD_seamless_cubemap_per_texture */
+
+#ifndef GL_AMD_shader_atomic_counter_ops
+#define GL_AMD_shader_atomic_counter_ops 1
+#endif /* GL_AMD_shader_atomic_counter_ops */
+
+#ifndef GL_AMD_shader_stencil_export
+#define GL_AMD_shader_stencil_export 1
+#endif /* GL_AMD_shader_stencil_export */
+
+#ifndef GL_AMD_shader_trinary_minmax
+#define GL_AMD_shader_trinary_minmax 1
+#endif /* GL_AMD_shader_trinary_minmax */
+
+#ifndef GL_AMD_sparse_texture
+#define GL_AMD_sparse_texture 1
+#define GL_VIRTUAL_PAGE_SIZE_X_AMD 0x9195
+#define GL_VIRTUAL_PAGE_SIZE_Y_AMD 0x9196
+#define GL_VIRTUAL_PAGE_SIZE_Z_AMD 0x9197
+#define GL_MAX_SPARSE_TEXTURE_SIZE_AMD 0x9198
+#define GL_MAX_SPARSE_3D_TEXTURE_SIZE_AMD 0x9199
+#define GL_MAX_SPARSE_ARRAY_TEXTURE_LAYERS 0x919A
+#define GL_MIN_SPARSE_LEVEL_AMD 0x919B
+#define GL_MIN_LOD_WARNING_AMD 0x919C
+#define GL_TEXTURE_STORAGE_SPARSE_BIT_AMD 0x00000001
+typedef void (APIENTRYP PFNGLTEXSTORAGESPARSEAMDPROC) (GLenum target, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei layers, GLbitfield flags);
+typedef void (APIENTRYP PFNGLTEXTURESTORAGESPARSEAMDPROC) (GLuint texture, GLenum target, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei layers, GLbitfield flags);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexStorageSparseAMD (GLenum target, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei layers, GLbitfield flags);
+GLAPI void APIENTRY glTextureStorageSparseAMD (GLuint texture, GLenum target, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei layers, GLbitfield flags);
+#endif
+#endif /* GL_AMD_sparse_texture */
+
+#ifndef GL_AMD_stencil_operation_extended
+#define GL_AMD_stencil_operation_extended 1
+#define GL_SET_AMD 0x874A
+#define GL_REPLACE_VALUE_AMD 0x874B
+#define GL_STENCIL_OP_VALUE_AMD 0x874C
+#define GL_STENCIL_BACK_OP_VALUE_AMD 0x874D
+typedef void (APIENTRYP PFNGLSTENCILOPVALUEAMDPROC) (GLenum face, GLuint value);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glStencilOpValueAMD (GLenum face, GLuint value);
+#endif
+#endif /* GL_AMD_stencil_operation_extended */
+
+#ifndef GL_AMD_texture_texture4
+#define GL_AMD_texture_texture4 1
+#endif /* GL_AMD_texture_texture4 */
+
+#ifndef GL_AMD_transform_feedback3_lines_triangles
+#define GL_AMD_transform_feedback3_lines_triangles 1
+#endif /* GL_AMD_transform_feedback3_lines_triangles */
+
+#ifndef GL_AMD_transform_feedback4
+#define GL_AMD_transform_feedback4 1
+#define GL_STREAM_RASTERIZATION_AMD 0x91A0
+#endif /* GL_AMD_transform_feedback4 */
+
+#ifndef GL_AMD_vertex_shader_layer
+#define GL_AMD_vertex_shader_layer 1
+#endif /* GL_AMD_vertex_shader_layer */
+
+#ifndef GL_AMD_vertex_shader_tessellator
+#define GL_AMD_vertex_shader_tessellator 1
+#define GL_SAMPLER_BUFFER_AMD 0x9001
+#define GL_INT_SAMPLER_BUFFER_AMD 0x9002
+#define GL_UNSIGNED_INT_SAMPLER_BUFFER_AMD 0x9003
+#define GL_TESSELLATION_MODE_AMD 0x9004
+#define GL_TESSELLATION_FACTOR_AMD 0x9005
+#define GL_DISCRETE_AMD 0x9006
+#define GL_CONTINUOUS_AMD 0x9007
+typedef void (APIENTRYP PFNGLTESSELLATIONFACTORAMDPROC) (GLfloat factor);
+typedef void (APIENTRYP PFNGLTESSELLATIONMODEAMDPROC) (GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTessellationFactorAMD (GLfloat factor);
+GLAPI void APIENTRY glTessellationModeAMD (GLenum mode);
+#endif
+#endif /* GL_AMD_vertex_shader_tessellator */
+
+#ifndef GL_AMD_vertex_shader_viewport_index
+#define GL_AMD_vertex_shader_viewport_index 1
+#endif /* GL_AMD_vertex_shader_viewport_index */
+
+#ifndef GL_APPLE_aux_depth_stencil
+#define GL_APPLE_aux_depth_stencil 1
+#define GL_AUX_DEPTH_STENCIL_APPLE 0x8A14
+#endif /* GL_APPLE_aux_depth_stencil */
+
+#ifndef GL_APPLE_client_storage
+#define GL_APPLE_client_storage 1
+#define GL_UNPACK_CLIENT_STORAGE_APPLE 0x85B2
+#endif /* GL_APPLE_client_storage */
+
+#ifndef GL_APPLE_element_array
+#define GL_APPLE_element_array 1
+#define GL_ELEMENT_ARRAY_APPLE 0x8A0C
+#define GL_ELEMENT_ARRAY_TYPE_APPLE 0x8A0D
+#define GL_ELEMENT_ARRAY_POINTER_APPLE 0x8A0E
+typedef void (APIENTRYP PFNGLELEMENTPOINTERAPPLEPROC) (GLenum type, const void *pointer);
+typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, GLint first, GLsizei count);
+typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, GLint first, GLsizei count);
+typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount);
+typedef void (APIENTRYP PFNGLMULTIDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, const GLint *first, const GLsizei *count, GLsizei primcount);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glElementPointerAPPLE (GLenum type, const void *pointer);
+GLAPI void APIENTRY glDrawElementArrayAPPLE (GLenum mode, GLint first, GLsizei count);
+GLAPI void APIENTRY glDrawRangeElementArrayAPPLE (GLenum mode, GLuint start, GLuint end, GLint first, GLsizei count);
+GLAPI void APIENTRY glMultiDrawElementArrayAPPLE (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount);
+GLAPI void APIENTRY glMultiDrawRangeElementArrayAPPLE (GLenum mode, GLuint start, GLuint end, const GLint *first, const GLsizei *count, GLsizei primcount);
+#endif
+#endif /* GL_APPLE_element_array */
+
+#ifndef GL_APPLE_fence
+#define GL_APPLE_fence 1
+#define GL_DRAW_PIXELS_APPLE 0x8A0A
+#define GL_FENCE_APPLE 0x8A0B
+typedef void (APIENTRYP PFNGLGENFENCESAPPLEPROC) (GLsizei n, GLuint *fences);
+typedef void (APIENTRYP PFNGLDELETEFENCESAPPLEPROC) (GLsizei n, const GLuint *fences);
+typedef void (APIENTRYP PFNGLSETFENCEAPPLEPROC) (GLuint fence);
+typedef GLboolean (APIENTRYP PFNGLISFENCEAPPLEPROC) (GLuint fence);
+typedef GLboolean (APIENTRYP PFNGLTESTFENCEAPPLEPROC) (GLuint fence);
+typedef void (APIENTRYP PFNGLFINISHFENCEAPPLEPROC) (GLuint fence);
+typedef GLboolean (APIENTRYP PFNGLTESTOBJECTAPPLEPROC) (GLenum object, GLuint name);
+typedef void (APIENTRYP PFNGLFINISHOBJECTAPPLEPROC) (GLenum object, GLint name);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGenFencesAPPLE (GLsizei n, GLuint *fences);
+GLAPI void APIENTRY glDeleteFencesAPPLE (GLsizei n, const GLuint *fences);
+GLAPI void APIENTRY glSetFenceAPPLE (GLuint fence);
+GLAPI GLboolean APIENTRY glIsFenceAPPLE (GLuint fence);
+GLAPI GLboolean APIENTRY glTestFenceAPPLE (GLuint fence);
+GLAPI void APIENTRY glFinishFenceAPPLE (GLuint fence);
+GLAPI GLboolean APIENTRY glTestObjectAPPLE (GLenum object, GLuint name);
+GLAPI void APIENTRY glFinishObjectAPPLE (GLenum object, GLint name);
+#endif
+#endif /* GL_APPLE_fence */
+
+#ifndef GL_APPLE_float_pixels
+#define GL_APPLE_float_pixels 1
+#define GL_HALF_APPLE 0x140B
+#define GL_RGBA_FLOAT32_APPLE 0x8814
+#define GL_RGB_FLOAT32_APPLE 0x8815
+#define GL_ALPHA_FLOAT32_APPLE 0x8816
+#define GL_INTENSITY_FLOAT32_APPLE 0x8817
+#define GL_LUMINANCE_FLOAT32_APPLE 0x8818
+#define GL_LUMINANCE_ALPHA_FLOAT32_APPLE 0x8819
+#define GL_RGBA_FLOAT16_APPLE 0x881A
+#define GL_RGB_FLOAT16_APPLE 0x881B
+#define GL_ALPHA_FLOAT16_APPLE 0x881C
+#define GL_INTENSITY_FLOAT16_APPLE 0x881D
+#define GL_LUMINANCE_FLOAT16_APPLE 0x881E
+#define GL_LUMINANCE_ALPHA_FLOAT16_APPLE 0x881F
+#define GL_COLOR_FLOAT_APPLE 0x8A0F
+#endif /* GL_APPLE_float_pixels */
+
+#ifndef GL_APPLE_flush_buffer_range
+#define GL_APPLE_flush_buffer_range 1
+#define GL_BUFFER_SERIALIZED_MODIFY_APPLE 0x8A12
+#define GL_BUFFER_FLUSHING_UNMAP_APPLE 0x8A13
+typedef void (APIENTRYP PFNGLBUFFERPARAMETERIAPPLEPROC) (GLenum target, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEAPPLEPROC) (GLenum target, GLintptr offset, GLsizeiptr size);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBufferParameteriAPPLE (GLenum target, GLenum pname, GLint param);
+GLAPI void APIENTRY glFlushMappedBufferRangeAPPLE (GLenum target, GLintptr offset, GLsizeiptr size);
+#endif
+#endif /* GL_APPLE_flush_buffer_range */
+
+#ifndef GL_APPLE_object_purgeable
+#define GL_APPLE_object_purgeable 1
+#define GL_BUFFER_OBJECT_APPLE 0x85B3
+#define GL_RELEASED_APPLE 0x8A19
+#define GL_VOLATILE_APPLE 0x8A1A
+#define GL_RETAINED_APPLE 0x8A1B
+#define GL_UNDEFINED_APPLE 0x8A1C
+#define GL_PURGEABLE_APPLE 0x8A1D
+typedef GLenum (APIENTRYP PFNGLOBJECTPURGEABLEAPPLEPROC) (GLenum objectType, GLuint name, GLenum option);
+typedef GLenum (APIENTRYP PFNGLOBJECTUNPURGEABLEAPPLEPROC) (GLenum objectType, GLuint name, GLenum option);
+typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVAPPLEPROC) (GLenum objectType, GLuint name, GLenum pname, GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLenum APIENTRY glObjectPurgeableAPPLE (GLenum objectType, GLuint name, GLenum option);
+GLAPI GLenum APIENTRY glObjectUnpurgeableAPPLE (GLenum objectType, GLuint name, GLenum option);
+GLAPI void APIENTRY glGetObjectParameterivAPPLE (GLenum objectType, GLuint name, GLenum pname, GLint *params);
+#endif
+#endif /* GL_APPLE_object_purgeable */
+
+#ifndef GL_APPLE_rgb_422
+#define GL_APPLE_rgb_422 1
+#define GL_RGB_422_APPLE 0x8A1F
+#define GL_UNSIGNED_SHORT_8_8_APPLE 0x85BA
+#define GL_UNSIGNED_SHORT_8_8_REV_APPLE 0x85BB
+#define GL_RGB_RAW_422_APPLE 0x8A51
+#endif /* GL_APPLE_rgb_422 */
+
+#ifndef GL_APPLE_row_bytes
+#define GL_APPLE_row_bytes 1
+#define GL_PACK_ROW_BYTES_APPLE 0x8A15
+#define GL_UNPACK_ROW_BYTES_APPLE 0x8A16
+#endif /* GL_APPLE_row_bytes */
+
+#ifndef GL_APPLE_specular_vector
+#define GL_APPLE_specular_vector 1
+#define GL_LIGHT_MODEL_SPECULAR_VECTOR_APPLE 0x85B0
+#endif /* GL_APPLE_specular_vector */
+
+#ifndef GL_APPLE_texture_range
+#define GL_APPLE_texture_range 1
+#define GL_TEXTURE_RANGE_LENGTH_APPLE 0x85B7
+#define GL_TEXTURE_RANGE_POINTER_APPLE 0x85B8
+#define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC
+#define GL_STORAGE_PRIVATE_APPLE 0x85BD
+#define GL_STORAGE_CACHED_APPLE 0x85BE
+#define GL_STORAGE_SHARED_APPLE 0x85BF
+typedef void (APIENTRYP PFNGLTEXTURERANGEAPPLEPROC) (GLenum target, GLsizei length, const void *pointer);
+typedef void (APIENTRYP PFNGLGETTEXPARAMETERPOINTERVAPPLEPROC) (GLenum target, GLenum pname, void **params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTextureRangeAPPLE (GLenum target, GLsizei length, const void *pointer);
+GLAPI void APIENTRY glGetTexParameterPointervAPPLE (GLenum target, GLenum pname, void **params);
+#endif
+#endif /* GL_APPLE_texture_range */
+
+#ifndef GL_APPLE_transform_hint
+#define GL_APPLE_transform_hint 1
+#define GL_TRANSFORM_HINT_APPLE 0x85B1
+#endif /* GL_APPLE_transform_hint */
+
+#ifndef GL_APPLE_vertex_array_object
+#define GL_APPLE_vertex_array_object 1
+#define GL_VERTEX_ARRAY_BINDING_APPLE 0x85B5
+typedef void (APIENTRYP PFNGLBINDVERTEXARRAYAPPLEPROC) (GLuint array);
+typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSAPPLEPROC) (GLsizei n, const GLuint *arrays);
+typedef void (APIENTRYP PFNGLGENVERTEXARRAYSAPPLEPROC) (GLsizei n, GLuint *arrays);
+typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYAPPLEPROC) (GLuint array);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBindVertexArrayAPPLE (GLuint array);
+GLAPI void APIENTRY glDeleteVertexArraysAPPLE (GLsizei n, const GLuint *arrays);
+GLAPI void APIENTRY glGenVertexArraysAPPLE (GLsizei n, GLuint *arrays);
+GLAPI GLboolean APIENTRY glIsVertexArrayAPPLE (GLuint array);
+#endif
+#endif /* GL_APPLE_vertex_array_object */
+
+#ifndef GL_APPLE_vertex_array_range
+#define GL_APPLE_vertex_array_range 1
+#define GL_VERTEX_ARRAY_RANGE_APPLE 0x851D
+#define GL_VERTEX_ARRAY_RANGE_LENGTH_APPLE 0x851E
+#define GL_VERTEX_ARRAY_STORAGE_HINT_APPLE 0x851F
+#define GL_VERTEX_ARRAY_RANGE_POINTER_APPLE 0x8521
+#define GL_STORAGE_CLIENT_APPLE 0x85B4
+typedef void (APIENTRYP PFNGLVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, void *pointer);
+typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, void *pointer);
+typedef void (APIENTRYP PFNGLVERTEXARRAYPARAMETERIAPPLEPROC) (GLenum pname, GLint param);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexArrayRangeAPPLE (GLsizei length, void *pointer);
+GLAPI void APIENTRY glFlushVertexArrayRangeAPPLE (GLsizei length, void *pointer);
+GLAPI void APIENTRY glVertexArrayParameteriAPPLE (GLenum pname, GLint param);
+#endif
+#endif /* GL_APPLE_vertex_array_range */
+
+#ifndef GL_APPLE_vertex_program_evaluators
+#define GL_APPLE_vertex_program_evaluators 1
+#define GL_VERTEX_ATTRIB_MAP1_APPLE 0x8A00
+#define GL_VERTEX_ATTRIB_MAP2_APPLE 0x8A01
+#define GL_VERTEX_ATTRIB_MAP1_SIZE_APPLE 0x8A02
+#define GL_VERTEX_ATTRIB_MAP1_COEFF_APPLE 0x8A03
+#define GL_VERTEX_ATTRIB_MAP1_ORDER_APPLE 0x8A04
+#define GL_VERTEX_ATTRIB_MAP1_DOMAIN_APPLE 0x8A05
+#define GL_VERTEX_ATTRIB_MAP2_SIZE_APPLE 0x8A06
+#define GL_VERTEX_ATTRIB_MAP2_COEFF_APPLE 0x8A07
+#define GL_VERTEX_ATTRIB_MAP2_ORDER_APPLE 0x8A08
+#define GL_VERTEX_ATTRIB_MAP2_DOMAIN_APPLE 0x8A09
+typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBAPPLEPROC) (GLuint index, GLenum pname);
+typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBAPPLEPROC) (GLuint index, GLenum pname);
+typedef GLboolean (APIENTRYP PFNGLISVERTEXATTRIBENABLEDAPPLEPROC) (GLuint index, GLenum pname);
+typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB1DAPPLEPROC) (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points);
+typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB1FAPPLEPROC) (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points);
+typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB2DAPPLEPROC) (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points);
+typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB2FAPPLEPROC) (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glEnableVertexAttribAPPLE (GLuint index, GLenum pname);
+GLAPI void APIENTRY glDisableVertexAttribAPPLE (GLuint index, GLenum pname);
+GLAPI GLboolean APIENTRY glIsVertexAttribEnabledAPPLE (GLuint index, GLenum pname);
+GLAPI void APIENTRY glMapVertexAttrib1dAPPLE (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points);
+GLAPI void APIENTRY glMapVertexAttrib1fAPPLE (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points);
+GLAPI void APIENTRY glMapVertexAttrib2dAPPLE (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points);
+GLAPI void APIENTRY glMapVertexAttrib2fAPPLE (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points);
+#endif
+#endif /* GL_APPLE_vertex_program_evaluators */
+
+#ifndef GL_APPLE_ycbcr_422
+#define GL_APPLE_ycbcr_422 1
+#define GL_YCBCR_422_APPLE 0x85B9
+#endif /* GL_APPLE_ycbcr_422 */
+
+#ifndef GL_ATI_draw_buffers
+#define GL_ATI_draw_buffers 1
+#define GL_MAX_DRAW_BUFFERS_ATI 0x8824
+#define GL_DRAW_BUFFER0_ATI 0x8825
+#define GL_DRAW_BUFFER1_ATI 0x8826
+#define GL_DRAW_BUFFER2_ATI 0x8827
+#define GL_DRAW_BUFFER3_ATI 0x8828
+#define GL_DRAW_BUFFER4_ATI 0x8829
+#define GL_DRAW_BUFFER5_ATI 0x882A
+#define GL_DRAW_BUFFER6_ATI 0x882B
+#define GL_DRAW_BUFFER7_ATI 0x882C
+#define GL_DRAW_BUFFER8_ATI 0x882D
+#define GL_DRAW_BUFFER9_ATI 0x882E
+#define GL_DRAW_BUFFER10_ATI 0x882F
+#define GL_DRAW_BUFFER11_ATI 0x8830
+#define GL_DRAW_BUFFER12_ATI 0x8831
+#define GL_DRAW_BUFFER13_ATI 0x8832
+#define GL_DRAW_BUFFER14_ATI 0x8833
+#define GL_DRAW_BUFFER15_ATI 0x8834
+typedef void (APIENTRYP PFNGLDRAWBUFFERSATIPROC) (GLsizei n, const GLenum *bufs);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawBuffersATI (GLsizei n, const GLenum *bufs);
+#endif
+#endif /* GL_ATI_draw_buffers */
+
+#ifndef GL_ATI_element_array
+#define GL_ATI_element_array 1
+#define GL_ELEMENT_ARRAY_ATI 0x8768
+#define GL_ELEMENT_ARRAY_TYPE_ATI 0x8769
+#define GL_ELEMENT_ARRAY_POINTER_ATI 0x876A
+typedef void (APIENTRYP PFNGLELEMENTPOINTERATIPROC) (GLenum type, const void *pointer);
+typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYATIPROC) (GLenum mode, GLsizei count);
+typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYATIPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glElementPointerATI (GLenum type, const void *pointer);
+GLAPI void APIENTRY glDrawElementArrayATI (GLenum mode, GLsizei count);
+GLAPI void APIENTRY glDrawRangeElementArrayATI (GLenum mode, GLuint start, GLuint end, GLsizei count);
+#endif
+#endif /* GL_ATI_element_array */
+
+#ifndef GL_ATI_envmap_bumpmap
+#define GL_ATI_envmap_bumpmap 1
+#define GL_BUMP_ROT_MATRIX_ATI 0x8775
+#define GL_BUMP_ROT_MATRIX_SIZE_ATI 0x8776
+#define GL_BUMP_NUM_TEX_UNITS_ATI 0x8777
+#define GL_BUMP_TEX_UNITS_ATI 0x8778
+#define GL_DUDV_ATI 0x8779
+#define GL_DU8DV8_ATI 0x877A
+#define GL_BUMP_ENVMAP_ATI 0x877B
+#define GL_BUMP_TARGET_ATI 0x877C
+typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERIVATIPROC) (GLenum pname, const GLint *param);
+typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERFVATIPROC) (GLenum pname, const GLfloat *param);
+typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERIVATIPROC) (GLenum pname, GLint *param);
+typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERFVATIPROC) (GLenum pname, GLfloat *param);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexBumpParameterivATI (GLenum pname, const GLint *param);
+GLAPI void APIENTRY glTexBumpParameterfvATI (GLenum pname, const GLfloat *param);
+GLAPI void APIENTRY glGetTexBumpParameterivATI (GLenum pname, GLint *param);
+GLAPI void APIENTRY glGetTexBumpParameterfvATI (GLenum pname, GLfloat *param);
+#endif
+#endif /* GL_ATI_envmap_bumpmap */
+
+#ifndef GL_ATI_fragment_shader
+#define GL_ATI_fragment_shader 1
+#define GL_FRAGMENT_SHADER_ATI 0x8920
+#define GL_REG_0_ATI 0x8921
+#define GL_REG_1_ATI 0x8922
+#define GL_REG_2_ATI 0x8923
+#define GL_REG_3_ATI 0x8924
+#define GL_REG_4_ATI 0x8925
+#define GL_REG_5_ATI 0x8926
+#define GL_REG_6_ATI 0x8927
+#define GL_REG_7_ATI 0x8928
+#define GL_REG_8_ATI 0x8929
+#define GL_REG_9_ATI 0x892A
+#define GL_REG_10_ATI 0x892B
+#define GL_REG_11_ATI 0x892C
+#define GL_REG_12_ATI 0x892D
+#define GL_REG_13_ATI 0x892E
+#define GL_REG_14_ATI 0x892F
+#define GL_REG_15_ATI 0x8930
+#define GL_REG_16_ATI 0x8931
+#define GL_REG_17_ATI 0x8932
+#define GL_REG_18_ATI 0x8933
+#define GL_REG_19_ATI 0x8934
+#define GL_REG_20_ATI 0x8935
+#define GL_REG_21_ATI 0x8936
+#define GL_REG_22_ATI 0x8937
+#define GL_REG_23_ATI 0x8938
+#define GL_REG_24_ATI 0x8939
+#define GL_REG_25_ATI 0x893A
+#define GL_REG_26_ATI 0x893B
+#define GL_REG_27_ATI 0x893C
+#define GL_REG_28_ATI 0x893D
+#define GL_REG_29_ATI 0x893E
+#define GL_REG_30_ATI 0x893F
+#define GL_REG_31_ATI 0x8940
+#define GL_CON_0_ATI 0x8941
+#define GL_CON_1_ATI 0x8942
+#define GL_CON_2_ATI 0x8943
+#define GL_CON_3_ATI 0x8944
+#define GL_CON_4_ATI 0x8945
+#define GL_CON_5_ATI 0x8946
+#define GL_CON_6_ATI 0x8947
+#define GL_CON_7_ATI 0x8948
+#define GL_CON_8_ATI 0x8949
+#define GL_CON_9_ATI 0x894A
+#define GL_CON_10_ATI 0x894B
+#define GL_CON_11_ATI 0x894C
+#define GL_CON_12_ATI 0x894D
+#define GL_CON_13_ATI 0x894E
+#define GL_CON_14_ATI 0x894F
+#define GL_CON_15_ATI 0x8950
+#define GL_CON_16_ATI 0x8951
+#define GL_CON_17_ATI 0x8952
+#define GL_CON_18_ATI 0x8953
+#define GL_CON_19_ATI 0x8954
+#define GL_CON_20_ATI 0x8955
+#define GL_CON_21_ATI 0x8956
+#define GL_CON_22_ATI 0x8957
+#define GL_CON_23_ATI 0x8958
+#define GL_CON_24_ATI 0x8959
+#define GL_CON_25_ATI 0x895A
+#define GL_CON_26_ATI 0x895B
+#define GL_CON_27_ATI 0x895C
+#define GL_CON_28_ATI 0x895D
+#define GL_CON_29_ATI 0x895E
+#define GL_CON_30_ATI 0x895F
+#define GL_CON_31_ATI 0x8960
+#define GL_MOV_ATI 0x8961
+#define GL_ADD_ATI 0x8963
+#define GL_MUL_ATI 0x8964
+#define GL_SUB_ATI 0x8965
+#define GL_DOT3_ATI 0x8966
+#define GL_DOT4_ATI 0x8967
+#define GL_MAD_ATI 0x8968
+#define GL_LERP_ATI 0x8969
+#define GL_CND_ATI 0x896A
+#define GL_CND0_ATI 0x896B
+#define GL_DOT2_ADD_ATI 0x896C
+#define GL_SECONDARY_INTERPOLATOR_ATI 0x896D
+#define GL_NUM_FRAGMENT_REGISTERS_ATI 0x896E
+#define GL_NUM_FRAGMENT_CONSTANTS_ATI 0x896F
+#define GL_NUM_PASSES_ATI 0x8970
+#define GL_NUM_INSTRUCTIONS_PER_PASS_ATI 0x8971
+#define GL_NUM_INSTRUCTIONS_TOTAL_ATI 0x8972
+#define GL_NUM_INPUT_INTERPOLATOR_COMPONENTS_ATI 0x8973
+#define GL_NUM_LOOPBACK_COMPONENTS_ATI 0x8974
+#define GL_COLOR_ALPHA_PAIRING_ATI 0x8975
+#define GL_SWIZZLE_STR_ATI 0x8976
+#define GL_SWIZZLE_STQ_ATI 0x8977
+#define GL_SWIZZLE_STR_DR_ATI 0x8978
+#define GL_SWIZZLE_STQ_DQ_ATI 0x8979
+#define GL_SWIZZLE_STRQ_ATI 0x897A
+#define GL_SWIZZLE_STRQ_DQ_ATI 0x897B
+#define GL_RED_BIT_ATI 0x00000001
+#define GL_GREEN_BIT_ATI 0x00000002
+#define GL_BLUE_BIT_ATI 0x00000004
+#define GL_2X_BIT_ATI 0x00000001
+#define GL_4X_BIT_ATI 0x00000002
+#define GL_8X_BIT_ATI 0x00000004
+#define GL_HALF_BIT_ATI 0x00000008
+#define GL_QUARTER_BIT_ATI 0x00000010
+#define GL_EIGHTH_BIT_ATI 0x00000020
+#define GL_SATURATE_BIT_ATI 0x00000040
+#define GL_COMP_BIT_ATI 0x00000002
+#define GL_NEGATE_BIT_ATI 0x00000004
+#define GL_BIAS_BIT_ATI 0x00000008
+typedef GLuint (APIENTRYP PFNGLGENFRAGMENTSHADERSATIPROC) (GLuint range);
+typedef void (APIENTRYP PFNGLBINDFRAGMENTSHADERATIPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLDELETEFRAGMENTSHADERATIPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLBEGINFRAGMENTSHADERATIPROC) (void);
+typedef void (APIENTRYP PFNGLENDFRAGMENTSHADERATIPROC) (void);
+typedef void (APIENTRYP PFNGLPASSTEXCOORDATIPROC) (GLuint dst, GLuint coord, GLenum swizzle);
+typedef void (APIENTRYP PFNGLSAMPLEMAPATIPROC) (GLuint dst, GLuint interp, GLenum swizzle);
+typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod);
+typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod);
+typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod);
+typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod);
+typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod);
+typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod);
+typedef void (APIENTRYP PFNGLSETFRAGMENTSHADERCONSTANTATIPROC) (GLuint dst, const GLfloat *value);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLuint APIENTRY glGenFragmentShadersATI (GLuint range);
+GLAPI void APIENTRY glBindFragmentShaderATI (GLuint id);
+GLAPI void APIENTRY glDeleteFragmentShaderATI (GLuint id);
+GLAPI void APIENTRY glBeginFragmentShaderATI (void);
+GLAPI void APIENTRY glEndFragmentShaderATI (void);
+GLAPI void APIENTRY glPassTexCoordATI (GLuint dst, GLuint coord, GLenum swizzle);
+GLAPI void APIENTRY glSampleMapATI (GLuint dst, GLuint interp, GLenum swizzle);
+GLAPI void APIENTRY glColorFragmentOp1ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod);
+GLAPI void APIENTRY glColorFragmentOp2ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod);
+GLAPI void APIENTRY glColorFragmentOp3ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod);
+GLAPI void APIENTRY glAlphaFragmentOp1ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod);
+GLAPI void APIENTRY glAlphaFragmentOp2ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod);
+GLAPI void APIENTRY glAlphaFragmentOp3ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod);
+GLAPI void APIENTRY glSetFragmentShaderConstantATI (GLuint dst, const GLfloat *value);
+#endif
+#endif /* GL_ATI_fragment_shader */
+
+#ifndef GL_ATI_map_object_buffer
+#define GL_ATI_map_object_buffer 1
+typedef void *(APIENTRYP PFNGLMAPOBJECTBUFFERATIPROC) (GLuint buffer);
+typedef void (APIENTRYP PFNGLUNMAPOBJECTBUFFERATIPROC) (GLuint buffer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void *APIENTRY glMapObjectBufferATI (GLuint buffer);
+GLAPI void APIENTRY glUnmapObjectBufferATI (GLuint buffer);
+#endif
+#endif /* GL_ATI_map_object_buffer */
+
+#ifndef GL_ATI_meminfo
+#define GL_ATI_meminfo 1
+#define GL_VBO_FREE_MEMORY_ATI 0x87FB
+#define GL_TEXTURE_FREE_MEMORY_ATI 0x87FC
+#define GL_RENDERBUFFER_FREE_MEMORY_ATI 0x87FD
+#endif /* GL_ATI_meminfo */
+
+#ifndef GL_ATI_pixel_format_float
+#define GL_ATI_pixel_format_float 1
+#define GL_RGBA_FLOAT_MODE_ATI 0x8820
+#define GL_COLOR_CLEAR_UNCLAMPED_VALUE_ATI 0x8835
+#endif /* GL_ATI_pixel_format_float */
+
+#ifndef GL_ATI_pn_triangles
+#define GL_ATI_pn_triangles 1
+#define GL_PN_TRIANGLES_ATI 0x87F0
+#define GL_MAX_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F1
+#define GL_PN_TRIANGLES_POINT_MODE_ATI 0x87F2
+#define GL_PN_TRIANGLES_NORMAL_MODE_ATI 0x87F3
+#define GL_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F4
+#define GL_PN_TRIANGLES_POINT_MODE_LINEAR_ATI 0x87F5
+#define GL_PN_TRIANGLES_POINT_MODE_CUBIC_ATI 0x87F6
+#define GL_PN_TRIANGLES_NORMAL_MODE_LINEAR_ATI 0x87F7
+#define GL_PN_TRIANGLES_NORMAL_MODE_QUADRATIC_ATI 0x87F8
+typedef void (APIENTRYP PFNGLPNTRIANGLESIATIPROC) (GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLPNTRIANGLESFATIPROC) (GLenum pname, GLfloat param);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPNTrianglesiATI (GLenum pname, GLint param);
+GLAPI void APIENTRY glPNTrianglesfATI (GLenum pname, GLfloat param);
+#endif
+#endif /* GL_ATI_pn_triangles */
+
+#ifndef GL_ATI_separate_stencil
+#define GL_ATI_separate_stencil 1
+#define GL_STENCIL_BACK_FUNC_ATI 0x8800
+#define GL_STENCIL_BACK_FAIL_ATI 0x8801
+#define GL_STENCIL_BACK_PASS_DEPTH_FAIL_ATI 0x8802
+#define GL_STENCIL_BACK_PASS_DEPTH_PASS_ATI 0x8803
+typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEATIPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
+typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEATIPROC) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glStencilOpSeparateATI (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
+GLAPI void APIENTRY glStencilFuncSeparateATI (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask);
+#endif
+#endif /* GL_ATI_separate_stencil */
+
+#ifndef GL_ATI_text_fragment_shader
+#define GL_ATI_text_fragment_shader 1
+#define GL_TEXT_FRAGMENT_SHADER_ATI 0x8200
+#endif /* GL_ATI_text_fragment_shader */
+
+#ifndef GL_ATI_texture_env_combine3
+#define GL_ATI_texture_env_combine3 1
+#define GL_MODULATE_ADD_ATI 0x8744
+#define GL_MODULATE_SIGNED_ADD_ATI 0x8745
+#define GL_MODULATE_SUBTRACT_ATI 0x8746
+#endif /* GL_ATI_texture_env_combine3 */
+
+#ifndef GL_ATI_texture_float
+#define GL_ATI_texture_float 1
+#define GL_RGBA_FLOAT32_ATI 0x8814
+#define GL_RGB_FLOAT32_ATI 0x8815
+#define GL_ALPHA_FLOAT32_ATI 0x8816
+#define GL_INTENSITY_FLOAT32_ATI 0x8817
+#define GL_LUMINANCE_FLOAT32_ATI 0x8818
+#define GL_LUMINANCE_ALPHA_FLOAT32_ATI 0x8819
+#define GL_RGBA_FLOAT16_ATI 0x881A
+#define GL_RGB_FLOAT16_ATI 0x881B
+#define GL_ALPHA_FLOAT16_ATI 0x881C
+#define GL_INTENSITY_FLOAT16_ATI 0x881D
+#define GL_LUMINANCE_FLOAT16_ATI 0x881E
+#define GL_LUMINANCE_ALPHA_FLOAT16_ATI 0x881F
+#endif /* GL_ATI_texture_float */
+
+#ifndef GL_ATI_texture_mirror_once
+#define GL_ATI_texture_mirror_once 1
+#define GL_MIRROR_CLAMP_ATI 0x8742
+#define GL_MIRROR_CLAMP_TO_EDGE_ATI 0x8743
+#endif /* GL_ATI_texture_mirror_once */
+
+#ifndef GL_ATI_vertex_array_object
+#define GL_ATI_vertex_array_object 1
+#define GL_STATIC_ATI 0x8760
+#define GL_DYNAMIC_ATI 0x8761
+#define GL_PRESERVE_ATI 0x8762
+#define GL_DISCARD_ATI 0x8763
+#define GL_OBJECT_BUFFER_SIZE_ATI 0x8764
+#define GL_OBJECT_BUFFER_USAGE_ATI 0x8765
+#define GL_ARRAY_OBJECT_BUFFER_ATI 0x8766
+#define GL_ARRAY_OBJECT_OFFSET_ATI 0x8767
+typedef GLuint (APIENTRYP PFNGLNEWOBJECTBUFFERATIPROC) (GLsizei size, const void *pointer, GLenum usage);
+typedef GLboolean (APIENTRYP PFNGLISOBJECTBUFFERATIPROC) (GLuint buffer);
+typedef void (APIENTRYP PFNGLUPDATEOBJECTBUFFERATIPROC) (GLuint buffer, GLuint offset, GLsizei size, const void *pointer, GLenum preserve);
+typedef void (APIENTRYP PFNGLGETOBJECTBUFFERFVATIPROC) (GLuint buffer, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETOBJECTBUFFERIVATIPROC) (GLuint buffer, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLFREEOBJECTBUFFERATIPROC) (GLuint buffer);
+typedef void (APIENTRYP PFNGLARRAYOBJECTATIPROC) (GLenum array, GLint size, GLenum type, GLsizei stride, GLuint buffer, GLuint offset);
+typedef void (APIENTRYP PFNGLGETARRAYOBJECTFVATIPROC) (GLenum array, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETARRAYOBJECTIVATIPROC) (GLenum array, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLVARIANTARRAYOBJECTATIPROC) (GLuint id, GLenum type, GLsizei stride, GLuint buffer, GLuint offset);
+typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTFVATIPROC) (GLuint id, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTIVATIPROC) (GLuint id, GLenum pname, GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLuint APIENTRY glNewObjectBufferATI (GLsizei size, const void *pointer, GLenum usage);
+GLAPI GLboolean APIENTRY glIsObjectBufferATI (GLuint buffer);
+GLAPI void APIENTRY glUpdateObjectBufferATI (GLuint buffer, GLuint offset, GLsizei size, const void *pointer, GLenum preserve);
+GLAPI void APIENTRY glGetObjectBufferfvATI (GLuint buffer, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetObjectBufferivATI (GLuint buffer, GLenum pname, GLint *params);
+GLAPI void APIENTRY glFreeObjectBufferATI (GLuint buffer);
+GLAPI void APIENTRY glArrayObjectATI (GLenum array, GLint size, GLenum type, GLsizei stride, GLuint buffer, GLuint offset);
+GLAPI void APIENTRY glGetArrayObjectfvATI (GLenum array, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetArrayObjectivATI (GLenum array, GLenum pname, GLint *params);
+GLAPI void APIENTRY glVariantArrayObjectATI (GLuint id, GLenum type, GLsizei stride, GLuint buffer, GLuint offset);
+GLAPI void APIENTRY glGetVariantArrayObjectfvATI (GLuint id, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetVariantArrayObjectivATI (GLuint id, GLenum pname, GLint *params);
+#endif
+#endif /* GL_ATI_vertex_array_object */
+
+#ifndef GL_ATI_vertex_attrib_array_object
+#define GL_ATI_vertex_attrib_array_object 1
+typedef void (APIENTRYP PFNGLVERTEXATTRIBARRAYOBJECTATIPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLuint buffer, GLuint offset);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTFVATIPROC) (GLuint index, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTIVATIPROC) (GLuint index, GLenum pname, GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexAttribArrayObjectATI (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLuint buffer, GLuint offset);
+GLAPI void APIENTRY glGetVertexAttribArrayObjectfvATI (GLuint index, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetVertexAttribArrayObjectivATI (GLuint index, GLenum pname, GLint *params);
+#endif
+#endif /* GL_ATI_vertex_attrib_array_object */
+
+#ifndef GL_ATI_vertex_streams
+#define GL_ATI_vertex_streams 1
+#define GL_MAX_VERTEX_STREAMS_ATI 0x876B
+#define GL_VERTEX_STREAM0_ATI 0x876C
+#define GL_VERTEX_STREAM1_ATI 0x876D
+#define GL_VERTEX_STREAM2_ATI 0x876E
+#define GL_VERTEX_STREAM3_ATI 0x876F
+#define GL_VERTEX_STREAM4_ATI 0x8770
+#define GL_VERTEX_STREAM5_ATI 0x8771
+#define GL_VERTEX_STREAM6_ATI 0x8772
+#define GL_VERTEX_STREAM7_ATI 0x8773
+#define GL_VERTEX_SOURCE_ATI 0x8774
+typedef void (APIENTRYP PFNGLVERTEXSTREAM1SATIPROC) (GLenum stream, GLshort x);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM1SVATIPROC) (GLenum stream, const GLshort *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM1IATIPROC) (GLenum stream, GLint x);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM1IVATIPROC) (GLenum stream, const GLint *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM1FATIPROC) (GLenum stream, GLfloat x);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM1FVATIPROC) (GLenum stream, const GLfloat *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM1DATIPROC) (GLenum stream, GLdouble x);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM1DVATIPROC) (GLenum stream, const GLdouble *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM2SATIPROC) (GLenum stream, GLshort x, GLshort y);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM2SVATIPROC) (GLenum stream, const GLshort *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM2IATIPROC) (GLenum stream, GLint x, GLint y);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM2IVATIPROC) (GLenum stream, const GLint *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM2FATIPROC) (GLenum stream, GLfloat x, GLfloat y);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM2FVATIPROC) (GLenum stream, const GLfloat *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM2DATIPROC) (GLenum stream, GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM2DVATIPROC) (GLenum stream, const GLdouble *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM3SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM3IATIPROC) (GLenum stream, GLint x, GLint y, GLint z);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM3IVATIPROC) (GLenum stream, const GLint *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM3FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM3DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM4SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z, GLshort w);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM4SVATIPROC) (GLenum stream, const GLshort *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM4IATIPROC) (GLenum stream, GLint x, GLint y, GLint z, GLint w);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM4IVATIPROC) (GLenum stream, const GLint *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM4FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM4FVATIPROC) (GLenum stream, const GLfloat *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM4DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM4DVATIPROC) (GLenum stream, const GLdouble *coords);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3BATIPROC) (GLenum stream, GLbyte nx, GLbyte ny, GLbyte nz);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3BVATIPROC) (GLenum stream, const GLbyte *coords);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3SATIPROC) (GLenum stream, GLshort nx, GLshort ny, GLshort nz);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3IATIPROC) (GLenum stream, GLint nx, GLint ny, GLint nz);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3IVATIPROC) (GLenum stream, const GLint *coords);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3FATIPROC) (GLenum stream, GLfloat nx, GLfloat ny, GLfloat nz);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3DATIPROC) (GLenum stream, GLdouble nx, GLdouble ny, GLdouble nz);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords);
+typedef void (APIENTRYP PFNGLCLIENTACTIVEVERTEXSTREAMATIPROC) (GLenum stream);
+typedef void (APIENTRYP PFNGLVERTEXBLENDENVIATIPROC) (GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLVERTEXBLENDENVFATIPROC) (GLenum pname, GLfloat param);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexStream1sATI (GLenum stream, GLshort x);
+GLAPI void APIENTRY glVertexStream1svATI (GLenum stream, const GLshort *coords);
+GLAPI void APIENTRY glVertexStream1iATI (GLenum stream, GLint x);
+GLAPI void APIENTRY glVertexStream1ivATI (GLenum stream, const GLint *coords);
+GLAPI void APIENTRY glVertexStream1fATI (GLenum stream, GLfloat x);
+GLAPI void APIENTRY glVertexStream1fvATI (GLenum stream, const GLfloat *coords);
+GLAPI void APIENTRY glVertexStream1dATI (GLenum stream, GLdouble x);
+GLAPI void APIENTRY glVertexStream1dvATI (GLenum stream, const GLdouble *coords);
+GLAPI void APIENTRY glVertexStream2sATI (GLenum stream, GLshort x, GLshort y);
+GLAPI void APIENTRY glVertexStream2svATI (GLenum stream, const GLshort *coords);
+GLAPI void APIENTRY glVertexStream2iATI (GLenum stream, GLint x, GLint y);
+GLAPI void APIENTRY glVertexStream2ivATI (GLenum stream, const GLint *coords);
+GLAPI void APIENTRY glVertexStream2fATI (GLenum stream, GLfloat x, GLfloat y);
+GLAPI void APIENTRY glVertexStream2fvATI (GLenum stream, const GLfloat *coords);
+GLAPI void APIENTRY glVertexStream2dATI (GLenum stream, GLdouble x, GLdouble y);
+GLAPI void APIENTRY glVertexStream2dvATI (GLenum stream, const GLdouble *coords);
+GLAPI void APIENTRY glVertexStream3sATI (GLenum stream, GLshort x, GLshort y, GLshort z);
+GLAPI void APIENTRY glVertexStream3svATI (GLenum stream, const GLshort *coords);
+GLAPI void APIENTRY glVertexStream3iATI (GLenum stream, GLint x, GLint y, GLint z);
+GLAPI void APIENTRY glVertexStream3ivATI (GLenum stream, const GLint *coords);
+GLAPI void APIENTRY glVertexStream3fATI (GLenum stream, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glVertexStream3fvATI (GLenum stream, const GLfloat *coords);
+GLAPI void APIENTRY glVertexStream3dATI (GLenum stream, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glVertexStream3dvATI (GLenum stream, const GLdouble *coords);
+GLAPI void APIENTRY glVertexStream4sATI (GLenum stream, GLshort x, GLshort y, GLshort z, GLshort w);
+GLAPI void APIENTRY glVertexStream4svATI (GLenum stream, const GLshort *coords);
+GLAPI void APIENTRY glVertexStream4iATI (GLenum stream, GLint x, GLint y, GLint z, GLint w);
+GLAPI void APIENTRY glVertexStream4ivATI (GLenum stream, const GLint *coords);
+GLAPI void APIENTRY glVertexStream4fATI (GLenum stream, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glVertexStream4fvATI (GLenum stream, const GLfloat *coords);
+GLAPI void APIENTRY glVertexStream4dATI (GLenum stream, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glVertexStream4dvATI (GLenum stream, const GLdouble *coords);
+GLAPI void APIENTRY glNormalStream3bATI (GLenum stream, GLbyte nx, GLbyte ny, GLbyte nz);
+GLAPI void APIENTRY glNormalStream3bvATI (GLenum stream, const GLbyte *coords);
+GLAPI void APIENTRY glNormalStream3sATI (GLenum stream, GLshort nx, GLshort ny, GLshort nz);
+GLAPI void APIENTRY glNormalStream3svATI (GLenum stream, const GLshort *coords);
+GLAPI void APIENTRY glNormalStream3iATI (GLenum stream, GLint nx, GLint ny, GLint nz);
+GLAPI void APIENTRY glNormalStream3ivATI (GLenum stream, const GLint *coords);
+GLAPI void APIENTRY glNormalStream3fATI (GLenum stream, GLfloat nx, GLfloat ny, GLfloat nz);
+GLAPI void APIENTRY glNormalStream3fvATI (GLenum stream, const GLfloat *coords);
+GLAPI void APIENTRY glNormalStream3dATI (GLenum stream, GLdouble nx, GLdouble ny, GLdouble nz);
+GLAPI void APIENTRY glNormalStream3dvATI (GLenum stream, const GLdouble *coords);
+GLAPI void APIENTRY glClientActiveVertexStreamATI (GLenum stream);
+GLAPI void APIENTRY glVertexBlendEnviATI (GLenum pname, GLint param);
+GLAPI void APIENTRY glVertexBlendEnvfATI (GLenum pname, GLfloat param);
+#endif
+#endif /* GL_ATI_vertex_streams */
+
+#ifndef GL_EXT_422_pixels
+#define GL_EXT_422_pixels 1
+#define GL_422_EXT 0x80CC
+#define GL_422_REV_EXT 0x80CD
+#define GL_422_AVERAGE_EXT 0x80CE
+#define GL_422_REV_AVERAGE_EXT 0x80CF
+#endif /* GL_EXT_422_pixels */
+
+#ifndef GL_EXT_abgr
+#define GL_EXT_abgr 1
+#define GL_ABGR_EXT 0x8000
+#endif /* GL_EXT_abgr */
+
+#ifndef GL_EXT_bgra
+#define GL_EXT_bgra 1
+#define GL_BGR_EXT 0x80E0
+#define GL_BGRA_EXT 0x80E1
+#endif /* GL_EXT_bgra */
+
+#ifndef GL_EXT_bindable_uniform
+#define GL_EXT_bindable_uniform 1
+#define GL_MAX_VERTEX_BINDABLE_UNIFORMS_EXT 0x8DE2
+#define GL_MAX_FRAGMENT_BINDABLE_UNIFORMS_EXT 0x8DE3
+#define GL_MAX_GEOMETRY_BINDABLE_UNIFORMS_EXT 0x8DE4
+#define GL_MAX_BINDABLE_UNIFORM_SIZE_EXT 0x8DED
+#define GL_UNIFORM_BUFFER_EXT 0x8DEE
+#define GL_UNIFORM_BUFFER_BINDING_EXT 0x8DEF
+typedef void (APIENTRYP PFNGLUNIFORMBUFFEREXTPROC) (GLuint program, GLint location, GLuint buffer);
+typedef GLint (APIENTRYP PFNGLGETUNIFORMBUFFERSIZEEXTPROC) (GLuint program, GLint location);
+typedef GLintptr (APIENTRYP PFNGLGETUNIFORMOFFSETEXTPROC) (GLuint program, GLint location);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glUniformBufferEXT (GLuint program, GLint location, GLuint buffer);
+GLAPI GLint APIENTRY glGetUniformBufferSizeEXT (GLuint program, GLint location);
+GLAPI GLintptr APIENTRY glGetUniformOffsetEXT (GLuint program, GLint location);
+#endif
+#endif /* GL_EXT_bindable_uniform */
+
+#ifndef GL_EXT_blend_color
+#define GL_EXT_blend_color 1
+#define GL_CONSTANT_COLOR_EXT 0x8001
+#define GL_ONE_MINUS_CONSTANT_COLOR_EXT 0x8002
+#define GL_CONSTANT_ALPHA_EXT 0x8003
+#define GL_ONE_MINUS_CONSTANT_ALPHA_EXT 0x8004
+#define GL_BLEND_COLOR_EXT 0x8005
+typedef void (APIENTRYP PFNGLBLENDCOLOREXTPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendColorEXT (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
+#endif
+#endif /* GL_EXT_blend_color */
+
+#ifndef GL_EXT_blend_equation_separate
+#define GL_EXT_blend_equation_separate 1
+#define GL_BLEND_EQUATION_RGB_EXT 0x8009
+#define GL_BLEND_EQUATION_ALPHA_EXT 0x883D
+typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEEXTPROC) (GLenum modeRGB, GLenum modeAlpha);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendEquationSeparateEXT (GLenum modeRGB, GLenum modeAlpha);
+#endif
+#endif /* GL_EXT_blend_equation_separate */
+
+#ifndef GL_EXT_blend_func_separate
+#define GL_EXT_blend_func_separate 1
+#define GL_BLEND_DST_RGB_EXT 0x80C8
+#define GL_BLEND_SRC_RGB_EXT 0x80C9
+#define GL_BLEND_DST_ALPHA_EXT 0x80CA
+#define GL_BLEND_SRC_ALPHA_EXT 0x80CB
+typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEEXTPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendFuncSeparateEXT (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
+#endif
+#endif /* GL_EXT_blend_func_separate */
+
+#ifndef GL_EXT_blend_logic_op
+#define GL_EXT_blend_logic_op 1
+#endif /* GL_EXT_blend_logic_op */
+
+#ifndef GL_EXT_blend_minmax
+#define GL_EXT_blend_minmax 1
+#define GL_MIN_EXT 0x8007
+#define GL_MAX_EXT 0x8008
+#define GL_FUNC_ADD_EXT 0x8006
+#define GL_BLEND_EQUATION_EXT 0x8009
+typedef void (APIENTRYP PFNGLBLENDEQUATIONEXTPROC) (GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendEquationEXT (GLenum mode);
+#endif
+#endif /* GL_EXT_blend_minmax */
+
+#ifndef GL_EXT_blend_subtract
+#define GL_EXT_blend_subtract 1
+#define GL_FUNC_SUBTRACT_EXT 0x800A
+#define GL_FUNC_REVERSE_SUBTRACT_EXT 0x800B
+#endif /* GL_EXT_blend_subtract */
+
+#ifndef GL_EXT_clip_volume_hint
+#define GL_EXT_clip_volume_hint 1
+#define GL_CLIP_VOLUME_CLIPPING_HINT_EXT 0x80F0
+#endif /* GL_EXT_clip_volume_hint */
+
+#ifndef GL_EXT_cmyka
+#define GL_EXT_cmyka 1
+#define GL_CMYK_EXT 0x800C
+#define GL_CMYKA_EXT 0x800D
+#define GL_PACK_CMYK_HINT_EXT 0x800E
+#define GL_UNPACK_CMYK_HINT_EXT 0x800F
+#endif /* GL_EXT_cmyka */
+
+#ifndef GL_EXT_color_subtable
+#define GL_EXT_color_subtable 1
+typedef void (APIENTRYP PFNGLCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const void *data);
+typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glColorSubTableEXT (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const void *data);
+GLAPI void APIENTRY glCopyColorSubTableEXT (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width);
+#endif
+#endif /* GL_EXT_color_subtable */
+
+#ifndef GL_EXT_compiled_vertex_array
+#define GL_EXT_compiled_vertex_array 1
+#define GL_ARRAY_ELEMENT_LOCK_FIRST_EXT 0x81A8
+#define GL_ARRAY_ELEMENT_LOCK_COUNT_EXT 0x81A9
+typedef void (APIENTRYP PFNGLLOCKARRAYSEXTPROC) (GLint first, GLsizei count);
+typedef void (APIENTRYP PFNGLUNLOCKARRAYSEXTPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glLockArraysEXT (GLint first, GLsizei count);
+GLAPI void APIENTRY glUnlockArraysEXT (void);
+#endif
+#endif /* GL_EXT_compiled_vertex_array */
+
+#ifndef GL_EXT_convolution
+#define GL_EXT_convolution 1
+#define GL_CONVOLUTION_1D_EXT 0x8010
+#define GL_CONVOLUTION_2D_EXT 0x8011
+#define GL_SEPARABLE_2D_EXT 0x8012
+#define GL_CONVOLUTION_BORDER_MODE_EXT 0x8013
+#define GL_CONVOLUTION_FILTER_SCALE_EXT 0x8014
+#define GL_CONVOLUTION_FILTER_BIAS_EXT 0x8015
+#define GL_REDUCE_EXT 0x8016
+#define GL_CONVOLUTION_FORMAT_EXT 0x8017
+#define GL_CONVOLUTION_WIDTH_EXT 0x8018
+#define GL_CONVOLUTION_HEIGHT_EXT 0x8019
+#define GL_MAX_CONVOLUTION_WIDTH_EXT 0x801A
+#define GL_MAX_CONVOLUTION_HEIGHT_EXT 0x801B
+#define GL_POST_CONVOLUTION_RED_SCALE_EXT 0x801C
+#define GL_POST_CONVOLUTION_GREEN_SCALE_EXT 0x801D
+#define GL_POST_CONVOLUTION_BLUE_SCALE_EXT 0x801E
+#define GL_POST_CONVOLUTION_ALPHA_SCALE_EXT 0x801F
+#define GL_POST_CONVOLUTION_RED_BIAS_EXT 0x8020
+#define GL_POST_CONVOLUTION_GREEN_BIAS_EXT 0x8021
+#define GL_POST_CONVOLUTION_BLUE_BIAS_EXT 0x8022
+#define GL_POST_CONVOLUTION_ALPHA_BIAS_EXT 0x8023
+typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *image);
+typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *image);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat params);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint params);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width);
+typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, void *image);
+typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETSEPARABLEFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, void *row, void *column, void *span);
+typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *row, const void *column);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glConvolutionFilter1DEXT (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *image);
+GLAPI void APIENTRY glConvolutionFilter2DEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *image);
+GLAPI void APIENTRY glConvolutionParameterfEXT (GLenum target, GLenum pname, GLfloat params);
+GLAPI void APIENTRY glConvolutionParameterfvEXT (GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glConvolutionParameteriEXT (GLenum target, GLenum pname, GLint params);
+GLAPI void APIENTRY glConvolutionParameterivEXT (GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glCopyConvolutionFilter1DEXT (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width);
+GLAPI void APIENTRY glCopyConvolutionFilter2DEXT (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glGetConvolutionFilterEXT (GLenum target, GLenum format, GLenum type, void *image);
+GLAPI void APIENTRY glGetConvolutionParameterfvEXT (GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetConvolutionParameterivEXT (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetSeparableFilterEXT (GLenum target, GLenum format, GLenum type, void *row, void *column, void *span);
+GLAPI void APIENTRY glSeparableFilter2DEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *row, const void *column);
+#endif
+#endif /* GL_EXT_convolution */
+
+#ifndef GL_EXT_coordinate_frame
+#define GL_EXT_coordinate_frame 1
+#define GL_TANGENT_ARRAY_EXT 0x8439
+#define GL_BINORMAL_ARRAY_EXT 0x843A
+#define GL_CURRENT_TANGENT_EXT 0x843B
+#define GL_CURRENT_BINORMAL_EXT 0x843C
+#define GL_TANGENT_ARRAY_TYPE_EXT 0x843E
+#define GL_TANGENT_ARRAY_STRIDE_EXT 0x843F
+#define GL_BINORMAL_ARRAY_TYPE_EXT 0x8440
+#define GL_BINORMAL_ARRAY_STRIDE_EXT 0x8441
+#define GL_TANGENT_ARRAY_POINTER_EXT 0x8442
+#define GL_BINORMAL_ARRAY_POINTER_EXT 0x8443
+#define GL_MAP1_TANGENT_EXT 0x8444
+#define GL_MAP2_TANGENT_EXT 0x8445
+#define GL_MAP1_BINORMAL_EXT 0x8446
+#define GL_MAP2_BINORMAL_EXT 0x8447
+typedef void (APIENTRYP PFNGLTANGENT3BEXTPROC) (GLbyte tx, GLbyte ty, GLbyte tz);
+typedef void (APIENTRYP PFNGLTANGENT3BVEXTPROC) (const GLbyte *v);
+typedef void (APIENTRYP PFNGLTANGENT3DEXTPROC) (GLdouble tx, GLdouble ty, GLdouble tz);
+typedef void (APIENTRYP PFNGLTANGENT3DVEXTPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLTANGENT3FEXTPROC) (GLfloat tx, GLfloat ty, GLfloat tz);
+typedef void (APIENTRYP PFNGLTANGENT3FVEXTPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLTANGENT3IEXTPROC) (GLint tx, GLint ty, GLint tz);
+typedef void (APIENTRYP PFNGLTANGENT3IVEXTPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLTANGENT3SEXTPROC) (GLshort tx, GLshort ty, GLshort tz);
+typedef void (APIENTRYP PFNGLTANGENT3SVEXTPROC) (const GLshort *v);
+typedef void (APIENTRYP PFNGLBINORMAL3BEXTPROC) (GLbyte bx, GLbyte by, GLbyte bz);
+typedef void (APIENTRYP PFNGLBINORMAL3BVEXTPROC) (const GLbyte *v);
+typedef void (APIENTRYP PFNGLBINORMAL3DEXTPROC) (GLdouble bx, GLdouble by, GLdouble bz);
+typedef void (APIENTRYP PFNGLBINORMAL3DVEXTPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLBINORMAL3FEXTPROC) (GLfloat bx, GLfloat by, GLfloat bz);
+typedef void (APIENTRYP PFNGLBINORMAL3FVEXTPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLBINORMAL3IEXTPROC) (GLint bx, GLint by, GLint bz);
+typedef void (APIENTRYP PFNGLBINORMAL3IVEXTPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLBINORMAL3SEXTPROC) (GLshort bx, GLshort by, GLshort bz);
+typedef void (APIENTRYP PFNGLBINORMAL3SVEXTPROC) (const GLshort *v);
+typedef void (APIENTRYP PFNGLTANGENTPOINTEREXTPROC) (GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLBINORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, const void *pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTangent3bEXT (GLbyte tx, GLbyte ty, GLbyte tz);
+GLAPI void APIENTRY glTangent3bvEXT (const GLbyte *v);
+GLAPI void APIENTRY glTangent3dEXT (GLdouble tx, GLdouble ty, GLdouble tz);
+GLAPI void APIENTRY glTangent3dvEXT (const GLdouble *v);
+GLAPI void APIENTRY glTangent3fEXT (GLfloat tx, GLfloat ty, GLfloat tz);
+GLAPI void APIENTRY glTangent3fvEXT (const GLfloat *v);
+GLAPI void APIENTRY glTangent3iEXT (GLint tx, GLint ty, GLint tz);
+GLAPI void APIENTRY glTangent3ivEXT (const GLint *v);
+GLAPI void APIENTRY glTangent3sEXT (GLshort tx, GLshort ty, GLshort tz);
+GLAPI void APIENTRY glTangent3svEXT (const GLshort *v);
+GLAPI void APIENTRY glBinormal3bEXT (GLbyte bx, GLbyte by, GLbyte bz);
+GLAPI void APIENTRY glBinormal3bvEXT (const GLbyte *v);
+GLAPI void APIENTRY glBinormal3dEXT (GLdouble bx, GLdouble by, GLdouble bz);
+GLAPI void APIENTRY glBinormal3dvEXT (const GLdouble *v);
+GLAPI void APIENTRY glBinormal3fEXT (GLfloat bx, GLfloat by, GLfloat bz);
+GLAPI void APIENTRY glBinormal3fvEXT (const GLfloat *v);
+GLAPI void APIENTRY glBinormal3iEXT (GLint bx, GLint by, GLint bz);
+GLAPI void APIENTRY glBinormal3ivEXT (const GLint *v);
+GLAPI void APIENTRY glBinormal3sEXT (GLshort bx, GLshort by, GLshort bz);
+GLAPI void APIENTRY glBinormal3svEXT (const GLshort *v);
+GLAPI void APIENTRY glTangentPointerEXT (GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glBinormalPointerEXT (GLenum type, GLsizei stride, const void *pointer);
+#endif
+#endif /* GL_EXT_coordinate_frame */
+
+#ifndef GL_EXT_copy_texture
+#define GL_EXT_copy_texture 1
+typedef void (APIENTRYP PFNGLCOPYTEXIMAGE1DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
+typedef void (APIENTRYP PFNGLCOPYTEXIMAGE2DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
+typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glCopyTexImage1DEXT (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
+GLAPI void APIENTRY glCopyTexImage2DEXT (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+GLAPI void APIENTRY glCopyTexSubImage1DEXT (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
+GLAPI void APIENTRY glCopyTexSubImage2DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glCopyTexSubImage3DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+#endif
+#endif /* GL_EXT_copy_texture */
+
+#ifndef GL_EXT_cull_vertex
+#define GL_EXT_cull_vertex 1
+#define GL_CULL_VERTEX_EXT 0x81AA
+#define GL_CULL_VERTEX_EYE_POSITION_EXT 0x81AB
+#define GL_CULL_VERTEX_OBJECT_POSITION_EXT 0x81AC
+typedef void (APIENTRYP PFNGLCULLPARAMETERDVEXTPROC) (GLenum pname, GLdouble *params);
+typedef void (APIENTRYP PFNGLCULLPARAMETERFVEXTPROC) (GLenum pname, GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glCullParameterdvEXT (GLenum pname, GLdouble *params);
+GLAPI void APIENTRY glCullParameterfvEXT (GLenum pname, GLfloat *params);
+#endif
+#endif /* GL_EXT_cull_vertex */
+
+#ifndef GL_EXT_debug_label
+#define GL_EXT_debug_label 1
+#define GL_PROGRAM_PIPELINE_OBJECT_EXT 0x8A4F
+#define GL_PROGRAM_OBJECT_EXT 0x8B40
+#define GL_SHADER_OBJECT_EXT 0x8B48
+#define GL_BUFFER_OBJECT_EXT 0x9151
+#define GL_QUERY_OBJECT_EXT 0x9153
+#define GL_VERTEX_ARRAY_OBJECT_EXT 0x9154
+typedef void (APIENTRYP PFNGLLABELOBJECTEXTPROC) (GLenum type, GLuint object, GLsizei length, const GLchar *label);
+typedef void (APIENTRYP PFNGLGETOBJECTLABELEXTPROC) (GLenum type, GLuint object, GLsizei bufSize, GLsizei *length, GLchar *label);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glLabelObjectEXT (GLenum type, GLuint object, GLsizei length, const GLchar *label);
+GLAPI void APIENTRY glGetObjectLabelEXT (GLenum type, GLuint object, GLsizei bufSize, GLsizei *length, GLchar *label);
+#endif
+#endif /* GL_EXT_debug_label */
+
+#ifndef GL_EXT_debug_marker
+#define GL_EXT_debug_marker 1
+typedef void (APIENTRYP PFNGLINSERTEVENTMARKEREXTPROC) (GLsizei length, const GLchar *marker);
+typedef void (APIENTRYP PFNGLPUSHGROUPMARKEREXTPROC) (GLsizei length, const GLchar *marker);
+typedef void (APIENTRYP PFNGLPOPGROUPMARKEREXTPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glInsertEventMarkerEXT (GLsizei length, const GLchar *marker);
+GLAPI void APIENTRY glPushGroupMarkerEXT (GLsizei length, const GLchar *marker);
+GLAPI void APIENTRY glPopGroupMarkerEXT (void);
+#endif
+#endif /* GL_EXT_debug_marker */
+
+#ifndef GL_EXT_depth_bounds_test
+#define GL_EXT_depth_bounds_test 1
+#define GL_DEPTH_BOUNDS_TEST_EXT 0x8890
+#define GL_DEPTH_BOUNDS_EXT 0x8891
+typedef void (APIENTRYP PFNGLDEPTHBOUNDSEXTPROC) (GLclampd zmin, GLclampd zmax);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDepthBoundsEXT (GLclampd zmin, GLclampd zmax);
+#endif
+#endif /* GL_EXT_depth_bounds_test */
+
+#ifndef GL_EXT_direct_state_access
+#define GL_EXT_direct_state_access 1
+#define GL_PROGRAM_MATRIX_EXT 0x8E2D
+#define GL_TRANSPOSE_PROGRAM_MATRIX_EXT 0x8E2E
+#define GL_PROGRAM_MATRIX_STACK_DEPTH_EXT 0x8E2F
+typedef void (APIENTRYP PFNGLMATRIXLOADFEXTPROC) (GLenum mode, const GLfloat *m);
+typedef void (APIENTRYP PFNGLMATRIXLOADDEXTPROC) (GLenum mode, const GLdouble *m);
+typedef void (APIENTRYP PFNGLMATRIXMULTFEXTPROC) (GLenum mode, const GLfloat *m);
+typedef void (APIENTRYP PFNGLMATRIXMULTDEXTPROC) (GLenum mode, const GLdouble *m);
+typedef void (APIENTRYP PFNGLMATRIXLOADIDENTITYEXTPROC) (GLenum mode);
+typedef void (APIENTRYP PFNGLMATRIXROTATEFEXTPROC) (GLenum mode, GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLMATRIXROTATEDEXTPROC) (GLenum mode, GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLMATRIXSCALEFEXTPROC) (GLenum mode, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLMATRIXSCALEDEXTPROC) (GLenum mode, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLMATRIXTRANSLATEFEXTPROC) (GLenum mode, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLMATRIXTRANSLATEDEXTPROC) (GLenum mode, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLMATRIXFRUSTUMEXTPROC) (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
+typedef void (APIENTRYP PFNGLMATRIXORTHOEXTPROC) (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
+typedef void (APIENTRYP PFNGLMATRIXPOPEXTPROC) (GLenum mode);
+typedef void (APIENTRYP PFNGLMATRIXPUSHEXTPROC) (GLenum mode);
+typedef void (APIENTRYP PFNGLCLIENTATTRIBDEFAULTEXTPROC) (GLbitfield mask);
+typedef void (APIENTRYP PFNGLPUSHCLIENTATTRIBDEFAULTEXTPROC) (GLbitfield mask);
+typedef void (APIENTRYP PFNGLTEXTUREPARAMETERFEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLTEXTUREPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLCOPYTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
+typedef void (APIENTRYP PFNGLCOPYTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
+typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLGETTEXTUREIMAGEEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, void *pixels);
+typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETTEXTURELEVELPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETTEXTURELEVELPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLTEXTUREIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLBINDMULTITEXTUREEXTPROC) (GLenum texunit, GLenum target, GLuint texture);
+typedef void (APIENTRYP PFNGLMULTITEXCOORDPOINTEREXTPROC) (GLenum texunit, GLint size, GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLMULTITEXENVFEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLMULTITEXENVFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLMULTITEXENVIEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLMULTITEXENVIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLMULTITEXGENDEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLdouble param);
+typedef void (APIENTRYP PFNGLMULTITEXGENDVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLdouble *params);
+typedef void (APIENTRYP PFNGLMULTITEXGENFEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLMULTITEXGENFVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLMULTITEXGENIEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLMULTITEXGENIVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXENVFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXENVIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXGENDVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXGENFVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXGENIVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLMULTITEXPARAMETERFEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLMULTITEXPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLCOPYMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
+typedef void (APIENTRYP PFNGLCOPYMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
+typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLGETMULTITEXIMAGEEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum format, GLenum type, void *pixels);
+typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXLEVELPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXLEVELPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLMULTITEXIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLENABLECLIENTSTATEINDEXEDEXTPROC) (GLenum array, GLuint index);
+typedef void (APIENTRYP PFNGLDISABLECLIENTSTATEINDEXEDEXTPROC) (GLenum array, GLuint index);
+typedef void (APIENTRYP PFNGLGETFLOATINDEXEDVEXTPROC) (GLenum target, GLuint index, GLfloat *data);
+typedef void (APIENTRYP PFNGLGETDOUBLEINDEXEDVEXTPROC) (GLenum target, GLuint index, GLdouble *data);
+typedef void (APIENTRYP PFNGLGETPOINTERINDEXEDVEXTPROC) (GLenum target, GLuint index, void **data);
+typedef void (APIENTRYP PFNGLENABLEINDEXEDEXTPROC) (GLenum target, GLuint index);
+typedef void (APIENTRYP PFNGLDISABLEINDEXEDEXTPROC) (GLenum target, GLuint index);
+typedef GLboolean (APIENTRYP PFNGLISENABLEDINDEXEDEXTPROC) (GLenum target, GLuint index);
+typedef void (APIENTRYP PFNGLGETINTEGERINDEXEDVEXTPROC) (GLenum target, GLuint index, GLint *data);
+typedef void (APIENTRYP PFNGLGETBOOLEANINDEXEDVEXTPROC) (GLenum target, GLuint index, GLboolean *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXTUREIMAGEEXTPROC) (GLuint texture, GLenum target, GLint lod, void *img);
+typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLGETCOMPRESSEDMULTITEXIMAGEEXTPROC) (GLenum texunit, GLenum target, GLint lod, void *img);
+typedef void (APIENTRYP PFNGLMATRIXLOADTRANSPOSEFEXTPROC) (GLenum mode, const GLfloat *m);
+typedef void (APIENTRYP PFNGLMATRIXLOADTRANSPOSEDEXTPROC) (GLenum mode, const GLdouble *m);
+typedef void (APIENTRYP PFNGLMATRIXMULTTRANSPOSEFEXTPROC) (GLenum mode, const GLfloat *m);
+typedef void (APIENTRYP PFNGLMATRIXMULTTRANSPOSEDEXTPROC) (GLenum mode, const GLdouble *m);
+typedef void (APIENTRYP PFNGLNAMEDBUFFERDATAEXTPROC) (GLuint buffer, GLsizeiptr size, const void *data, GLenum usage);
+typedef void (APIENTRYP PFNGLNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data);
+typedef void *(APIENTRYP PFNGLMAPNAMEDBUFFEREXTPROC) (GLuint buffer, GLenum access);
+typedef GLboolean (APIENTRYP PFNGLUNMAPNAMEDBUFFEREXTPROC) (GLuint buffer);
+typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPARAMETERIVEXTPROC) (GLuint buffer, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPOINTERVEXTPROC) (GLuint buffer, GLenum pname, void **params);
+typedef void (APIENTRYP PFNGLGETNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, void *data);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FEXTPROC) (GLuint program, GLint location, GLfloat v0);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IEXTPROC) (GLuint program, GLint location, GLint v0);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLTEXTUREBUFFEREXTPROC) (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer);
+typedef void (APIENTRYP PFNGLMULTITEXBUFFEREXTPROC) (GLenum texunit, GLenum target, GLenum internalformat, GLuint buffer);
+typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIUIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLuint *params);
+typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIUIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLuint *params);
+typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIUIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLuint *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIUIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLuint *params);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIEXTPROC) (GLuint program, GLint location, GLuint v0);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERS4FVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLfloat *params);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4IEXTPROC) (GLuint program, GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4IVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLint *params);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERSI4IVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLint *params);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4UIEXTPROC) (GLuint program, GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4UIVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLuint *params);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERSI4UIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLuint *params);
+typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERIIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLint *params);
+typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERIUIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLuint *params);
+typedef void (APIENTRYP PFNGLENABLECLIENTSTATEIEXTPROC) (GLenum array, GLuint index);
+typedef void (APIENTRYP PFNGLDISABLECLIENTSTATEIEXTPROC) (GLenum array, GLuint index);
+typedef void (APIENTRYP PFNGLGETFLOATI_VEXTPROC) (GLenum pname, GLuint index, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETDOUBLEI_VEXTPROC) (GLenum pname, GLuint index, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETPOINTERI_VEXTPROC) (GLenum pname, GLuint index, void **params);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMSTRINGEXTPROC) (GLuint program, GLenum target, GLenum format, GLsizei len, const void *string);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4DEXTPROC) (GLuint program, GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4DVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLdouble *params);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4FEXTPROC) (GLuint program, GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4FVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLfloat *params);
+typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERDVEXTPROC) (GLuint program, GLenum target, GLuint index, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERFVEXTPROC) (GLuint program, GLenum target, GLuint index, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMIVEXTPROC) (GLuint program, GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMSTRINGEXTPROC) (GLuint program, GLenum target, GLenum pname, void *string);
+typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEEXTPROC) (GLuint renderbuffer, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLGETNAMEDRENDERBUFFERPARAMETERIVEXTPROC) (GLuint renderbuffer, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLuint renderbuffer, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLECOVERAGEEXTPROC) (GLuint renderbuffer, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height);
+typedef GLenum (APIENTRYP PFNGLCHECKNAMEDFRAMEBUFFERSTATUSEXTPROC) (GLuint framebuffer, GLenum target);
+typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE1DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE2DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE3DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERRENDERBUFFEREXTPROC) (GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
+typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGENERATETEXTUREMIPMAPEXTPROC) (GLuint texture, GLenum target);
+typedef void (APIENTRYP PFNGLGENERATEMULTITEXMIPMAPEXTPROC) (GLenum texunit, GLenum target);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERDRAWBUFFEREXTPROC) (GLuint framebuffer, GLenum mode);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERDRAWBUFFERSEXTPROC) (GLuint framebuffer, GLsizei n, const GLenum *bufs);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERREADBUFFEREXTPROC) (GLuint framebuffer, GLenum mode);
+typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLNAMEDCOPYBUFFERSUBDATAEXTPROC) (GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
+typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTUREEXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURELAYEREXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLint layer);
+typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTUREFACEEXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLenum face);
+typedef void (APIENTRYP PFNGLTEXTURERENDERBUFFEREXTPROC) (GLuint texture, GLenum target, GLuint renderbuffer);
+typedef void (APIENTRYP PFNGLMULTITEXRENDERBUFFEREXTPROC) (GLenum texunit, GLenum target, GLuint renderbuffer);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYCOLOROFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYEDGEFLAGOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYINDEXOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYNORMALOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYTEXCOORDOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYMULTITEXCOORDOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLenum texunit, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYFOGCOORDOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYSECONDARYCOLOROFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBIOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLENABLEVERTEXARRAYEXTPROC) (GLuint vaobj, GLenum array);
+typedef void (APIENTRYP PFNGLDISABLEVERTEXARRAYEXTPROC) (GLuint vaobj, GLenum array);
+typedef void (APIENTRYP PFNGLENABLEVERTEXARRAYATTRIBEXTPROC) (GLuint vaobj, GLuint index);
+typedef void (APIENTRYP PFNGLDISABLEVERTEXARRAYATTRIBEXTPROC) (GLuint vaobj, GLuint index);
+typedef void (APIENTRYP PFNGLGETVERTEXARRAYINTEGERVEXTPROC) (GLuint vaobj, GLenum pname, GLint *param);
+typedef void (APIENTRYP PFNGLGETVERTEXARRAYPOINTERVEXTPROC) (GLuint vaobj, GLenum pname, void **param);
+typedef void (APIENTRYP PFNGLGETVERTEXARRAYINTEGERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, GLint *param);
+typedef void (APIENTRYP PFNGLGETVERTEXARRAYPOINTERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, void **param);
+typedef void *(APIENTRYP PFNGLMAPNAMEDBUFFERRANGEEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access);
+typedef void (APIENTRYP PFNGLFLUSHMAPPEDNAMEDBUFFERRANGEEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length);
+typedef void (APIENTRYP PFNGLNAMEDBUFFERSTORAGEEXTPROC) (GLuint buffer, GLsizeiptr size, const void *data, GLbitfield flags);
+typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERDATAEXTPROC) (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data);
+typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLenum internalformat, GLsizeiptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data);
+typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERPARAMETERIEXTPROC) (GLuint framebuffer, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DEXTPROC) (GLuint program, GLint location, GLdouble x);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DEXTPROC) (GLuint program, GLint location, GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DEXTPROC) (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DEXTPROC) (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLTEXTUREBUFFERRANGEEXTPROC) (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size);
+typedef void (APIENTRYP PFNGLTEXTURESTORAGE1DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DMULTISAMPLEEXTPROC) (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
+typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DMULTISAMPLEEXTPROC) (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations);
+typedef void (APIENTRYP PFNGLVERTEXARRAYBINDVERTEXBUFFEREXTPROC) (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBIFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBLFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBBINDINGEXTPROC) (GLuint vaobj, GLuint attribindex, GLuint bindingindex);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXBINDINGDIVISOREXTPROC) (GLuint vaobj, GLuint bindingindex, GLuint divisor);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBLOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLTEXTUREPAGECOMMITMENTEXTPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLboolean resident);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBDIVISOREXTPROC) (GLuint vaobj, GLuint index, GLuint divisor);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMatrixLoadfEXT (GLenum mode, const GLfloat *m);
+GLAPI void APIENTRY glMatrixLoaddEXT (GLenum mode, const GLdouble *m);
+GLAPI void APIENTRY glMatrixMultfEXT (GLenum mode, const GLfloat *m);
+GLAPI void APIENTRY glMatrixMultdEXT (GLenum mode, const GLdouble *m);
+GLAPI void APIENTRY glMatrixLoadIdentityEXT (GLenum mode);
+GLAPI void APIENTRY glMatrixRotatefEXT (GLenum mode, GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glMatrixRotatedEXT (GLenum mode, GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glMatrixScalefEXT (GLenum mode, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glMatrixScaledEXT (GLenum mode, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glMatrixTranslatefEXT (GLenum mode, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glMatrixTranslatedEXT (GLenum mode, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glMatrixFrustumEXT (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
+GLAPI void APIENTRY glMatrixOrthoEXT (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
+GLAPI void APIENTRY glMatrixPopEXT (GLenum mode);
+GLAPI void APIENTRY glMatrixPushEXT (GLenum mode);
+GLAPI void APIENTRY glClientAttribDefaultEXT (GLbitfield mask);
+GLAPI void APIENTRY glPushClientAttribDefaultEXT (GLbitfield mask);
+GLAPI void APIENTRY glTextureParameterfEXT (GLuint texture, GLenum target, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glTextureParameterfvEXT (GLuint texture, GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glTextureParameteriEXT (GLuint texture, GLenum target, GLenum pname, GLint param);
+GLAPI void APIENTRY glTextureParameterivEXT (GLuint texture, GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glTextureImage1DEXT (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glTextureImage2DEXT (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glTextureSubImage1DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glTextureSubImage2DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glCopyTextureImage1DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
+GLAPI void APIENTRY glCopyTextureImage2DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+GLAPI void APIENTRY glCopyTextureSubImage1DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
+GLAPI void APIENTRY glCopyTextureSubImage2DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glGetTextureImageEXT (GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, void *pixels);
+GLAPI void APIENTRY glGetTextureParameterfvEXT (GLuint texture, GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetTextureParameterivEXT (GLuint texture, GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetTextureLevelParameterfvEXT (GLuint texture, GLenum target, GLint level, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetTextureLevelParameterivEXT (GLuint texture, GLenum target, GLint level, GLenum pname, GLint *params);
+GLAPI void APIENTRY glTextureImage3DEXT (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glTextureSubImage3DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glCopyTextureSubImage3DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glBindMultiTextureEXT (GLenum texunit, GLenum target, GLuint texture);
+GLAPI void APIENTRY glMultiTexCoordPointerEXT (GLenum texunit, GLint size, GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glMultiTexEnvfEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glMultiTexEnvfvEXT (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glMultiTexEnviEXT (GLenum texunit, GLenum target, GLenum pname, GLint param);
+GLAPI void APIENTRY glMultiTexEnvivEXT (GLenum texunit, GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glMultiTexGendEXT (GLenum texunit, GLenum coord, GLenum pname, GLdouble param);
+GLAPI void APIENTRY glMultiTexGendvEXT (GLenum texunit, GLenum coord, GLenum pname, const GLdouble *params);
+GLAPI void APIENTRY glMultiTexGenfEXT (GLenum texunit, GLenum coord, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glMultiTexGenfvEXT (GLenum texunit, GLenum coord, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glMultiTexGeniEXT (GLenum texunit, GLenum coord, GLenum pname, GLint param);
+GLAPI void APIENTRY glMultiTexGenivEXT (GLenum texunit, GLenum coord, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glGetMultiTexEnvfvEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetMultiTexEnvivEXT (GLenum texunit, GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetMultiTexGendvEXT (GLenum texunit, GLenum coord, GLenum pname, GLdouble *params);
+GLAPI void APIENTRY glGetMultiTexGenfvEXT (GLenum texunit, GLenum coord, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetMultiTexGenivEXT (GLenum texunit, GLenum coord, GLenum pname, GLint *params);
+GLAPI void APIENTRY glMultiTexParameteriEXT (GLenum texunit, GLenum target, GLenum pname, GLint param);
+GLAPI void APIENTRY glMultiTexParameterivEXT (GLenum texunit, GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glMultiTexParameterfEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glMultiTexParameterfvEXT (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glMultiTexImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glMultiTexImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glMultiTexSubImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glMultiTexSubImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glCopyMultiTexImage1DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
+GLAPI void APIENTRY glCopyMultiTexImage2DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+GLAPI void APIENTRY glCopyMultiTexSubImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
+GLAPI void APIENTRY glCopyMultiTexSubImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glGetMultiTexImageEXT (GLenum texunit, GLenum target, GLint level, GLenum format, GLenum type, void *pixels);
+GLAPI void APIENTRY glGetMultiTexParameterfvEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetMultiTexParameterivEXT (GLenum texunit, GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetMultiTexLevelParameterfvEXT (GLenum texunit, GLenum target, GLint level, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetMultiTexLevelParameterivEXT (GLenum texunit, GLenum target, GLint level, GLenum pname, GLint *params);
+GLAPI void APIENTRY glMultiTexImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glMultiTexSubImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glCopyMultiTexSubImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glEnableClientStateIndexedEXT (GLenum array, GLuint index);
+GLAPI void APIENTRY glDisableClientStateIndexedEXT (GLenum array, GLuint index);
+GLAPI void APIENTRY glGetFloatIndexedvEXT (GLenum target, GLuint index, GLfloat *data);
+GLAPI void APIENTRY glGetDoubleIndexedvEXT (GLenum target, GLuint index, GLdouble *data);
+GLAPI void APIENTRY glGetPointerIndexedvEXT (GLenum target, GLuint index, void **data);
+GLAPI void APIENTRY glEnableIndexedEXT (GLenum target, GLuint index);
+GLAPI void APIENTRY glDisableIndexedEXT (GLenum target, GLuint index);
+GLAPI GLboolean APIENTRY glIsEnabledIndexedEXT (GLenum target, GLuint index);
+GLAPI void APIENTRY glGetIntegerIndexedvEXT (GLenum target, GLuint index, GLint *data);
+GLAPI void APIENTRY glGetBooleanIndexedvEXT (GLenum target, GLuint index, GLboolean *data);
+GLAPI void APIENTRY glCompressedTextureImage3DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedTextureImage2DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedTextureImage1DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedTextureSubImage3DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedTextureSubImage2DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedTextureSubImage1DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glGetCompressedTextureImageEXT (GLuint texture, GLenum target, GLint lod, void *img);
+GLAPI void APIENTRY glCompressedMultiTexImage3DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedMultiTexImage2DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedMultiTexImage1DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedMultiTexSubImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedMultiTexSubImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedMultiTexSubImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glGetCompressedMultiTexImageEXT (GLenum texunit, GLenum target, GLint lod, void *img);
+GLAPI void APIENTRY glMatrixLoadTransposefEXT (GLenum mode, const GLfloat *m);
+GLAPI void APIENTRY glMatrixLoadTransposedEXT (GLenum mode, const GLdouble *m);
+GLAPI void APIENTRY glMatrixMultTransposefEXT (GLenum mode, const GLfloat *m);
+GLAPI void APIENTRY glMatrixMultTransposedEXT (GLenum mode, const GLdouble *m);
+GLAPI void APIENTRY glNamedBufferDataEXT (GLuint buffer, GLsizeiptr size, const void *data, GLenum usage);
+GLAPI void APIENTRY glNamedBufferSubDataEXT (GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data);
+GLAPI void *APIENTRY glMapNamedBufferEXT (GLuint buffer, GLenum access);
+GLAPI GLboolean APIENTRY glUnmapNamedBufferEXT (GLuint buffer);
+GLAPI void APIENTRY glGetNamedBufferParameterivEXT (GLuint buffer, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetNamedBufferPointervEXT (GLuint buffer, GLenum pname, void **params);
+GLAPI void APIENTRY glGetNamedBufferSubDataEXT (GLuint buffer, GLintptr offset, GLsizeiptr size, void *data);
+GLAPI void APIENTRY glProgramUniform1fEXT (GLuint program, GLint location, GLfloat v0);
+GLAPI void APIENTRY glProgramUniform2fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1);
+GLAPI void APIENTRY glProgramUniform3fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+GLAPI void APIENTRY glProgramUniform4fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+GLAPI void APIENTRY glProgramUniform1iEXT (GLuint program, GLint location, GLint v0);
+GLAPI void APIENTRY glProgramUniform2iEXT (GLuint program, GLint location, GLint v0, GLint v1);
+GLAPI void APIENTRY glProgramUniform3iEXT (GLuint program, GLint location, GLint v0, GLint v1, GLint v2);
+GLAPI void APIENTRY glProgramUniform4iEXT (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+GLAPI void APIENTRY glProgramUniform1fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniform2fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniform3fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniform4fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniform1ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glProgramUniform2ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glProgramUniform3ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glProgramUniform4ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glProgramUniformMatrix2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix2x3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix3x2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix2x4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix4x2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix3x4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix4x3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glTextureBufferEXT (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer);
+GLAPI void APIENTRY glMultiTexBufferEXT (GLenum texunit, GLenum target, GLenum internalformat, GLuint buffer);
+GLAPI void APIENTRY glTextureParameterIivEXT (GLuint texture, GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glTextureParameterIuivEXT (GLuint texture, GLenum target, GLenum pname, const GLuint *params);
+GLAPI void APIENTRY glGetTextureParameterIivEXT (GLuint texture, GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetTextureParameterIuivEXT (GLuint texture, GLenum target, GLenum pname, GLuint *params);
+GLAPI void APIENTRY glMultiTexParameterIivEXT (GLenum texunit, GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glMultiTexParameterIuivEXT (GLenum texunit, GLenum target, GLenum pname, const GLuint *params);
+GLAPI void APIENTRY glGetMultiTexParameterIivEXT (GLenum texunit, GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetMultiTexParameterIuivEXT (GLenum texunit, GLenum target, GLenum pname, GLuint *params);
+GLAPI void APIENTRY glProgramUniform1uiEXT (GLuint program, GLint location, GLuint v0);
+GLAPI void APIENTRY glProgramUniform2uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1);
+GLAPI void APIENTRY glProgramUniform3uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2);
+GLAPI void APIENTRY glProgramUniform4uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+GLAPI void APIENTRY glProgramUniform1uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glProgramUniform2uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glProgramUniform3uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glProgramUniform4uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glNamedProgramLocalParameters4fvEXT (GLuint program, GLenum target, GLuint index, GLsizei count, const GLfloat *params);
+GLAPI void APIENTRY glNamedProgramLocalParameterI4iEXT (GLuint program, GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w);
+GLAPI void APIENTRY glNamedProgramLocalParameterI4ivEXT (GLuint program, GLenum target, GLuint index, const GLint *params);
+GLAPI void APIENTRY glNamedProgramLocalParametersI4ivEXT (GLuint program, GLenum target, GLuint index, GLsizei count, const GLint *params);
+GLAPI void APIENTRY glNamedProgramLocalParameterI4uiEXT (GLuint program, GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+GLAPI void APIENTRY glNamedProgramLocalParameterI4uivEXT (GLuint program, GLenum target, GLuint index, const GLuint *params);
+GLAPI void APIENTRY glNamedProgramLocalParametersI4uivEXT (GLuint program, GLenum target, GLuint index, GLsizei count, const GLuint *params);
+GLAPI void APIENTRY glGetNamedProgramLocalParameterIivEXT (GLuint program, GLenum target, GLuint index, GLint *params);
+GLAPI void APIENTRY glGetNamedProgramLocalParameterIuivEXT (GLuint program, GLenum target, GLuint index, GLuint *params);
+GLAPI void APIENTRY glEnableClientStateiEXT (GLenum array, GLuint index);
+GLAPI void APIENTRY glDisableClientStateiEXT (GLenum array, GLuint index);
+GLAPI void APIENTRY glGetFloati_vEXT (GLenum pname, GLuint index, GLfloat *params);
+GLAPI void APIENTRY glGetDoublei_vEXT (GLenum pname, GLuint index, GLdouble *params);
+GLAPI void APIENTRY glGetPointeri_vEXT (GLenum pname, GLuint index, void **params);
+GLAPI void APIENTRY glNamedProgramStringEXT (GLuint program, GLenum target, GLenum format, GLsizei len, const void *string);
+GLAPI void APIENTRY glNamedProgramLocalParameter4dEXT (GLuint program, GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glNamedProgramLocalParameter4dvEXT (GLuint program, GLenum target, GLuint index, const GLdouble *params);
+GLAPI void APIENTRY glNamedProgramLocalParameter4fEXT (GLuint program, GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glNamedProgramLocalParameter4fvEXT (GLuint program, GLenum target, GLuint index, const GLfloat *params);
+GLAPI void APIENTRY glGetNamedProgramLocalParameterdvEXT (GLuint program, GLenum target, GLuint index, GLdouble *params);
+GLAPI void APIENTRY glGetNamedProgramLocalParameterfvEXT (GLuint program, GLenum target, GLuint index, GLfloat *params);
+GLAPI void APIENTRY glGetNamedProgramivEXT (GLuint program, GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetNamedProgramStringEXT (GLuint program, GLenum target, GLenum pname, void *string);
+GLAPI void APIENTRY glNamedRenderbufferStorageEXT (GLuint renderbuffer, GLenum internalformat, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glGetNamedRenderbufferParameterivEXT (GLuint renderbuffer, GLenum pname, GLint *params);
+GLAPI void APIENTRY glNamedRenderbufferStorageMultisampleEXT (GLuint renderbuffer, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glNamedRenderbufferStorageMultisampleCoverageEXT (GLuint renderbuffer, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height);
+GLAPI GLenum APIENTRY glCheckNamedFramebufferStatusEXT (GLuint framebuffer, GLenum target);
+GLAPI void APIENTRY glNamedFramebufferTexture1DEXT (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+GLAPI void APIENTRY glNamedFramebufferTexture2DEXT (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+GLAPI void APIENTRY glNamedFramebufferTexture3DEXT (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+GLAPI void APIENTRY glNamedFramebufferRenderbufferEXT (GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
+GLAPI void APIENTRY glGetNamedFramebufferAttachmentParameterivEXT (GLuint framebuffer, GLenum attachment, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGenerateTextureMipmapEXT (GLuint texture, GLenum target);
+GLAPI void APIENTRY glGenerateMultiTexMipmapEXT (GLenum texunit, GLenum target);
+GLAPI void APIENTRY glFramebufferDrawBufferEXT (GLuint framebuffer, GLenum mode);
+GLAPI void APIENTRY glFramebufferDrawBuffersEXT (GLuint framebuffer, GLsizei n, const GLenum *bufs);
+GLAPI void APIENTRY glFramebufferReadBufferEXT (GLuint framebuffer, GLenum mode);
+GLAPI void APIENTRY glGetFramebufferParameterivEXT (GLuint framebuffer, GLenum pname, GLint *params);
+GLAPI void APIENTRY glNamedCopyBufferSubDataEXT (GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
+GLAPI void APIENTRY glNamedFramebufferTextureEXT (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level);
+GLAPI void APIENTRY glNamedFramebufferTextureLayerEXT (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLint layer);
+GLAPI void APIENTRY glNamedFramebufferTextureFaceEXT (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLenum face);
+GLAPI void APIENTRY glTextureRenderbufferEXT (GLuint texture, GLenum target, GLuint renderbuffer);
+GLAPI void APIENTRY glMultiTexRenderbufferEXT (GLenum texunit, GLenum target, GLuint renderbuffer);
+GLAPI void APIENTRY glVertexArrayVertexOffsetEXT (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArrayColorOffsetEXT (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArrayEdgeFlagOffsetEXT (GLuint vaobj, GLuint buffer, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArrayIndexOffsetEXT (GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArrayNormalOffsetEXT (GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArrayTexCoordOffsetEXT (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArrayMultiTexCoordOffsetEXT (GLuint vaobj, GLuint buffer, GLenum texunit, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArrayFogCoordOffsetEXT (GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArraySecondaryColorOffsetEXT (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArrayVertexAttribOffsetEXT (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArrayVertexAttribIOffsetEXT (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glEnableVertexArrayEXT (GLuint vaobj, GLenum array);
+GLAPI void APIENTRY glDisableVertexArrayEXT (GLuint vaobj, GLenum array);
+GLAPI void APIENTRY glEnableVertexArrayAttribEXT (GLuint vaobj, GLuint index);
+GLAPI void APIENTRY glDisableVertexArrayAttribEXT (GLuint vaobj, GLuint index);
+GLAPI void APIENTRY glGetVertexArrayIntegervEXT (GLuint vaobj, GLenum pname, GLint *param);
+GLAPI void APIENTRY glGetVertexArrayPointervEXT (GLuint vaobj, GLenum pname, void **param);
+GLAPI void APIENTRY glGetVertexArrayIntegeri_vEXT (GLuint vaobj, GLuint index, GLenum pname, GLint *param);
+GLAPI void APIENTRY glGetVertexArrayPointeri_vEXT (GLuint vaobj, GLuint index, GLenum pname, void **param);
+GLAPI void *APIENTRY glMapNamedBufferRangeEXT (GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access);
+GLAPI void APIENTRY glFlushMappedNamedBufferRangeEXT (GLuint buffer, GLintptr offset, GLsizeiptr length);
+GLAPI void APIENTRY glNamedBufferStorageEXT (GLuint buffer, GLsizeiptr size, const void *data, GLbitfield flags);
+GLAPI void APIENTRY glClearNamedBufferDataEXT (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data);
+GLAPI void APIENTRY glClearNamedBufferSubDataEXT (GLuint buffer, GLenum internalformat, GLsizeiptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data);
+GLAPI void APIENTRY glNamedFramebufferParameteriEXT (GLuint framebuffer, GLenum pname, GLint param);
+GLAPI void APIENTRY glGetNamedFramebufferParameterivEXT (GLuint framebuffer, GLenum pname, GLint *params);
+GLAPI void APIENTRY glProgramUniform1dEXT (GLuint program, GLint location, GLdouble x);
+GLAPI void APIENTRY glProgramUniform2dEXT (GLuint program, GLint location, GLdouble x, GLdouble y);
+GLAPI void APIENTRY glProgramUniform3dEXT (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glProgramUniform4dEXT (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glProgramUniform1dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniform2dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniform3dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniform4dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix2dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix3dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix4dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix2x3dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix2x4dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix3x2dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix3x4dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix4x2dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix4x3dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glTextureBufferRangeEXT (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size);
+GLAPI void APIENTRY glTextureStorage1DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+GLAPI void APIENTRY glTextureStorage2DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glTextureStorage3DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+GLAPI void APIENTRY glTextureStorage2DMultisampleEXT (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
+GLAPI void APIENTRY glTextureStorage3DMultisampleEXT (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations);
+GLAPI void APIENTRY glVertexArrayBindVertexBufferEXT (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride);
+GLAPI void APIENTRY glVertexArrayVertexAttribFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset);
+GLAPI void APIENTRY glVertexArrayVertexAttribIFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
+GLAPI void APIENTRY glVertexArrayVertexAttribLFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
+GLAPI void APIENTRY glVertexArrayVertexAttribBindingEXT (GLuint vaobj, GLuint attribindex, GLuint bindingindex);
+GLAPI void APIENTRY glVertexArrayVertexBindingDivisorEXT (GLuint vaobj, GLuint bindingindex, GLuint divisor);
+GLAPI void APIENTRY glVertexArrayVertexAttribLOffsetEXT (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glTexturePageCommitmentEXT (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLboolean resident);
+GLAPI void APIENTRY glVertexArrayVertexAttribDivisorEXT (GLuint vaobj, GLuint index, GLuint divisor);
+#endif
+#endif /* GL_EXT_direct_state_access */
+
+#ifndef GL_EXT_draw_buffers2
+#define GL_EXT_draw_buffers2 1
+typedef void (APIENTRYP PFNGLCOLORMASKINDEXEDEXTPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glColorMaskIndexedEXT (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a);
+#endif
+#endif /* GL_EXT_draw_buffers2 */
+
+#ifndef GL_EXT_draw_instanced
+#define GL_EXT_draw_instanced 1
+typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDEXTPROC) (GLenum mode, GLint start, GLsizei count, GLsizei primcount);
+typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDEXTPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawArraysInstancedEXT (GLenum mode, GLint start, GLsizei count, GLsizei primcount);
+GLAPI void APIENTRY glDrawElementsInstancedEXT (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
+#endif
+#endif /* GL_EXT_draw_instanced */
+
+#ifndef GL_EXT_draw_range_elements
+#define GL_EXT_draw_range_elements 1
+#define GL_MAX_ELEMENTS_VERTICES_EXT 0x80E8
+#define GL_MAX_ELEMENTS_INDICES_EXT 0x80E9
+typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSEXTPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawRangeElementsEXT (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices);
+#endif
+#endif /* GL_EXT_draw_range_elements */
+
+#ifndef GL_EXT_fog_coord
+#define GL_EXT_fog_coord 1
+#define GL_FOG_COORDINATE_SOURCE_EXT 0x8450
+#define GL_FOG_COORDINATE_EXT 0x8451
+#define GL_FRAGMENT_DEPTH_EXT 0x8452
+#define GL_CURRENT_FOG_COORDINATE_EXT 0x8453
+#define GL_FOG_COORDINATE_ARRAY_TYPE_EXT 0x8454
+#define GL_FOG_COORDINATE_ARRAY_STRIDE_EXT 0x8455
+#define GL_FOG_COORDINATE_ARRAY_POINTER_EXT 0x8456
+#define GL_FOG_COORDINATE_ARRAY_EXT 0x8457
+typedef void (APIENTRYP PFNGLFOGCOORDFEXTPROC) (GLfloat coord);
+typedef void (APIENTRYP PFNGLFOGCOORDFVEXTPROC) (const GLfloat *coord);
+typedef void (APIENTRYP PFNGLFOGCOORDDEXTPROC) (GLdouble coord);
+typedef void (APIENTRYP PFNGLFOGCOORDDVEXTPROC) (const GLdouble *coord);
+typedef void (APIENTRYP PFNGLFOGCOORDPOINTEREXTPROC) (GLenum type, GLsizei stride, const void *pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glFogCoordfEXT (GLfloat coord);
+GLAPI void APIENTRY glFogCoordfvEXT (const GLfloat *coord);
+GLAPI void APIENTRY glFogCoorddEXT (GLdouble coord);
+GLAPI void APIENTRY glFogCoorddvEXT (const GLdouble *coord);
+GLAPI void APIENTRY glFogCoordPointerEXT (GLenum type, GLsizei stride, const void *pointer);
+#endif
+#endif /* GL_EXT_fog_coord */
+
+#ifndef GL_EXT_framebuffer_blit
+#define GL_EXT_framebuffer_blit 1
+#define GL_READ_FRAMEBUFFER_EXT 0x8CA8
+#define GL_DRAW_FRAMEBUFFER_EXT 0x8CA9
+#define GL_DRAW_FRAMEBUFFER_BINDING_EXT 0x8CA6
+#define GL_READ_FRAMEBUFFER_BINDING_EXT 0x8CAA
+typedef void (APIENTRYP PFNGLBLITFRAMEBUFFEREXTPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlitFramebufferEXT (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+#endif
+#endif /* GL_EXT_framebuffer_blit */
+
+#ifndef GL_EXT_framebuffer_multisample
+#define GL_EXT_framebuffer_multisample 1
+#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56
+#define GL_MAX_SAMPLES_EXT 0x8D57
+typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glRenderbufferStorageMultisampleEXT (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+#endif
+#endif /* GL_EXT_framebuffer_multisample */
+
+#ifndef GL_EXT_framebuffer_multisample_blit_scaled
+#define GL_EXT_framebuffer_multisample_blit_scaled 1
+#define GL_SCALED_RESOLVE_FASTEST_EXT 0x90BA
+#define GL_SCALED_RESOLVE_NICEST_EXT 0x90BB
+#endif /* GL_EXT_framebuffer_multisample_blit_scaled */
+
+#ifndef GL_EXT_framebuffer_object
+#define GL_EXT_framebuffer_object 1
+#define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506
+#define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8
+#define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6
+#define GL_RENDERBUFFER_BINDING_EXT 0x8CA7
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4
+#define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5
+#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6
+#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7
+#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9
+#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA
+#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB
+#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC
+#define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD
+#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF
+#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
+#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1
+#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2
+#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3
+#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4
+#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5
+#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6
+#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7
+#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8
+#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9
+#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA
+#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB
+#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC
+#define GL_COLOR_ATTACHMENT13_EXT 0x8CED
+#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE
+#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF
+#define GL_DEPTH_ATTACHMENT_EXT 0x8D00
+#define GL_STENCIL_ATTACHMENT_EXT 0x8D20
+#define GL_FRAMEBUFFER_EXT 0x8D40
+#define GL_RENDERBUFFER_EXT 0x8D41
+#define GL_RENDERBUFFER_WIDTH_EXT 0x8D42
+#define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43
+#define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44
+#define GL_STENCIL_INDEX1_EXT 0x8D46
+#define GL_STENCIL_INDEX4_EXT 0x8D47
+#define GL_STENCIL_INDEX8_EXT 0x8D48
+#define GL_STENCIL_INDEX16_EXT 0x8D49
+#define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50
+#define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51
+#define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52
+#define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53
+#define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54
+#define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55
+typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFEREXTPROC) (GLuint renderbuffer);
+typedef void (APIENTRYP PFNGLBINDRENDERBUFFEREXTPROC) (GLenum target, GLuint renderbuffer);
+typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSEXTPROC) (GLsizei n, const GLuint *renderbuffers);
+typedef void (APIENTRYP PFNGLGENRENDERBUFFERSEXTPROC) (GLsizei n, GLuint *renderbuffers);
+typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params);
+typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFEREXTPROC) (GLuint framebuffer);
+typedef void (APIENTRYP PFNGLBINDFRAMEBUFFEREXTPROC) (GLenum target, GLuint framebuffer);
+typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSEXTPROC) (GLsizei n, const GLuint *framebuffers);
+typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSEXTPROC) (GLsizei n, GLuint *framebuffers);
+typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
+typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGENERATEMIPMAPEXTPROC) (GLenum target);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLboolean APIENTRY glIsRenderbufferEXT (GLuint renderbuffer);
+GLAPI void APIENTRY glBindRenderbufferEXT (GLenum target, GLuint renderbuffer);
+GLAPI void APIENTRY glDeleteRenderbuffersEXT (GLsizei n, const GLuint *renderbuffers);
+GLAPI void APIENTRY glGenRenderbuffersEXT (GLsizei n, GLuint *renderbuffers);
+GLAPI void APIENTRY glRenderbufferStorageEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glGetRenderbufferParameterivEXT (GLenum target, GLenum pname, GLint *params);
+GLAPI GLboolean APIENTRY glIsFramebufferEXT (GLuint framebuffer);
+GLAPI void APIENTRY glBindFramebufferEXT (GLenum target, GLuint framebuffer);
+GLAPI void APIENTRY glDeleteFramebuffersEXT (GLsizei n, const GLuint *framebuffers);
+GLAPI void APIENTRY glGenFramebuffersEXT (GLsizei n, GLuint *framebuffers);
+GLAPI GLenum APIENTRY glCheckFramebufferStatusEXT (GLenum target);
+GLAPI void APIENTRY glFramebufferTexture1DEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+GLAPI void APIENTRY glFramebufferTexture2DEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+GLAPI void APIENTRY glFramebufferTexture3DEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+GLAPI void APIENTRY glFramebufferRenderbufferEXT (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
+GLAPI void APIENTRY glGetFramebufferAttachmentParameterivEXT (GLenum target, GLenum attachment, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGenerateMipmapEXT (GLenum target);
+#endif
+#endif /* GL_EXT_framebuffer_object */
+
+#ifndef GL_EXT_framebuffer_sRGB
+#define GL_EXT_framebuffer_sRGB 1
+#define GL_FRAMEBUFFER_SRGB_EXT 0x8DB9
+#define GL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x8DBA
+#endif /* GL_EXT_framebuffer_sRGB */
+
+#ifndef GL_EXT_geometry_shader4
+#define GL_EXT_geometry_shader4 1
+#define GL_GEOMETRY_SHADER_EXT 0x8DD9
+#define GL_GEOMETRY_VERTICES_OUT_EXT 0x8DDA
+#define GL_GEOMETRY_INPUT_TYPE_EXT 0x8DDB
+#define GL_GEOMETRY_OUTPUT_TYPE_EXT 0x8DDC
+#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT 0x8C29
+#define GL_MAX_GEOMETRY_VARYING_COMPONENTS_EXT 0x8DDD
+#define GL_MAX_VERTEX_VARYING_COMPONENTS_EXT 0x8DDE
+#define GL_MAX_VARYING_COMPONENTS_EXT 0x8B4B
+#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT 0x8DDF
+#define GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT 0x8DE0
+#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT 0x8DE1
+#define GL_LINES_ADJACENCY_EXT 0x000A
+#define GL_LINE_STRIP_ADJACENCY_EXT 0x000B
+#define GL_TRIANGLES_ADJACENCY_EXT 0x000C
+#define GL_TRIANGLE_STRIP_ADJACENCY_EXT 0x000D
+#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT 0x8DA8
+#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_EXT 0x8DA9
+#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT 0x8DA7
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT 0x8CD4
+#define GL_PROGRAM_POINT_SIZE_EXT 0x8642
+typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIEXTPROC) (GLuint program, GLenum pname, GLint value);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProgramParameteriEXT (GLuint program, GLenum pname, GLint value);
+#endif
+#endif /* GL_EXT_geometry_shader4 */
+
+#ifndef GL_EXT_gpu_program_parameters
+#define GL_EXT_gpu_program_parameters 1
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERS4FVEXTPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *params);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERS4FVEXTPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProgramEnvParameters4fvEXT (GLenum target, GLuint index, GLsizei count, const GLfloat *params);
+GLAPI void APIENTRY glProgramLocalParameters4fvEXT (GLenum target, GLuint index, GLsizei count, const GLfloat *params);
+#endif
+#endif /* GL_EXT_gpu_program_parameters */
+
+#ifndef GL_EXT_gpu_shader4
+#define GL_EXT_gpu_shader4 1
+#define GL_VERTEX_ATTRIB_ARRAY_INTEGER_EXT 0x88FD
+#define GL_SAMPLER_1D_ARRAY_EXT 0x8DC0
+#define GL_SAMPLER_2D_ARRAY_EXT 0x8DC1
+#define GL_SAMPLER_BUFFER_EXT 0x8DC2
+#define GL_SAMPLER_1D_ARRAY_SHADOW_EXT 0x8DC3
+#define GL_SAMPLER_2D_ARRAY_SHADOW_EXT 0x8DC4
+#define GL_SAMPLER_CUBE_SHADOW_EXT 0x8DC5
+#define GL_UNSIGNED_INT_VEC2_EXT 0x8DC6
+#define GL_UNSIGNED_INT_VEC3_EXT 0x8DC7
+#define GL_UNSIGNED_INT_VEC4_EXT 0x8DC8
+#define GL_INT_SAMPLER_1D_EXT 0x8DC9
+#define GL_INT_SAMPLER_2D_EXT 0x8DCA
+#define GL_INT_SAMPLER_3D_EXT 0x8DCB
+#define GL_INT_SAMPLER_CUBE_EXT 0x8DCC
+#define GL_INT_SAMPLER_2D_RECT_EXT 0x8DCD
+#define GL_INT_SAMPLER_1D_ARRAY_EXT 0x8DCE
+#define GL_INT_SAMPLER_2D_ARRAY_EXT 0x8DCF
+#define GL_INT_SAMPLER_BUFFER_EXT 0x8DD0
+#define GL_UNSIGNED_INT_SAMPLER_1D_EXT 0x8DD1
+#define GL_UNSIGNED_INT_SAMPLER_2D_EXT 0x8DD2
+#define GL_UNSIGNED_INT_SAMPLER_3D_EXT 0x8DD3
+#define GL_UNSIGNED_INT_SAMPLER_CUBE_EXT 0x8DD4
+#define GL_UNSIGNED_INT_SAMPLER_2D_RECT_EXT 0x8DD5
+#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY_EXT 0x8DD6
+#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY_EXT 0x8DD7
+#define GL_UNSIGNED_INT_SAMPLER_BUFFER_EXT 0x8DD8
+#define GL_MIN_PROGRAM_TEXEL_OFFSET_EXT 0x8904
+#define GL_MAX_PROGRAM_TEXEL_OFFSET_EXT 0x8905
+typedef void (APIENTRYP PFNGLGETUNIFORMUIVEXTPROC) (GLuint program, GLint location, GLuint *params);
+typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONEXTPROC) (GLuint program, GLuint color, const GLchar *name);
+typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONEXTPROC) (GLuint program, const GLchar *name);
+typedef void (APIENTRYP PFNGLUNIFORM1UIEXTPROC) (GLint location, GLuint v0);
+typedef void (APIENTRYP PFNGLUNIFORM2UIEXTPROC) (GLint location, GLuint v0, GLuint v1);
+typedef void (APIENTRYP PFNGLUNIFORM3UIEXTPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2);
+typedef void (APIENTRYP PFNGLUNIFORM4UIEXTPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+typedef void (APIENTRYP PFNGLUNIFORM1UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLUNIFORM2UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLUNIFORM3UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLUNIFORM4UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGetUniformuivEXT (GLuint program, GLint location, GLuint *params);
+GLAPI void APIENTRY glBindFragDataLocationEXT (GLuint program, GLuint color, const GLchar *name);
+GLAPI GLint APIENTRY glGetFragDataLocationEXT (GLuint program, const GLchar *name);
+GLAPI void APIENTRY glUniform1uiEXT (GLint location, GLuint v0);
+GLAPI void APIENTRY glUniform2uiEXT (GLint location, GLuint v0, GLuint v1);
+GLAPI void APIENTRY glUniform3uiEXT (GLint location, GLuint v0, GLuint v1, GLuint v2);
+GLAPI void APIENTRY glUniform4uiEXT (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+GLAPI void APIENTRY glUniform1uivEXT (GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glUniform2uivEXT (GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glUniform3uivEXT (GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glUniform4uivEXT (GLint location, GLsizei count, const GLuint *value);
+#endif
+#endif /* GL_EXT_gpu_shader4 */
+
+#ifndef GL_EXT_histogram
+#define GL_EXT_histogram 1
+#define GL_HISTOGRAM_EXT 0x8024
+#define GL_PROXY_HISTOGRAM_EXT 0x8025
+#define GL_HISTOGRAM_WIDTH_EXT 0x8026
+#define GL_HISTOGRAM_FORMAT_EXT 0x8027
+#define GL_HISTOGRAM_RED_SIZE_EXT 0x8028
+#define GL_HISTOGRAM_GREEN_SIZE_EXT 0x8029
+#define GL_HISTOGRAM_BLUE_SIZE_EXT 0x802A
+#define GL_HISTOGRAM_ALPHA_SIZE_EXT 0x802B
+#define GL_HISTOGRAM_LUMINANCE_SIZE_EXT 0x802C
+#define GL_HISTOGRAM_SINK_EXT 0x802D
+#define GL_MINMAX_EXT 0x802E
+#define GL_MINMAX_FORMAT_EXT 0x802F
+#define GL_MINMAX_SINK_EXT 0x8030
+#define GL_TABLE_TOO_LARGE_EXT 0x8031
+typedef void (APIENTRYP PFNGLGETHISTOGRAMEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values);
+typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETMINMAXEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values);
+typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLHISTOGRAMEXTPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink);
+typedef void (APIENTRYP PFNGLMINMAXEXTPROC) (GLenum target, GLenum internalformat, GLboolean sink);
+typedef void (APIENTRYP PFNGLRESETHISTOGRAMEXTPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLRESETMINMAXEXTPROC) (GLenum target);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGetHistogramEXT (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values);
+GLAPI void APIENTRY glGetHistogramParameterfvEXT (GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetHistogramParameterivEXT (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetMinmaxEXT (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values);
+GLAPI void APIENTRY glGetMinmaxParameterfvEXT (GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetMinmaxParameterivEXT (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glHistogramEXT (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink);
+GLAPI void APIENTRY glMinmaxEXT (GLenum target, GLenum internalformat, GLboolean sink);
+GLAPI void APIENTRY glResetHistogramEXT (GLenum target);
+GLAPI void APIENTRY glResetMinmaxEXT (GLenum target);
+#endif
+#endif /* GL_EXT_histogram */
+
+#ifndef GL_EXT_index_array_formats
+#define GL_EXT_index_array_formats 1
+#define GL_IUI_V2F_EXT 0x81AD
+#define GL_IUI_V3F_EXT 0x81AE
+#define GL_IUI_N3F_V2F_EXT 0x81AF
+#define GL_IUI_N3F_V3F_EXT 0x81B0
+#define GL_T2F_IUI_V2F_EXT 0x81B1
+#define GL_T2F_IUI_V3F_EXT 0x81B2
+#define GL_T2F_IUI_N3F_V2F_EXT 0x81B3
+#define GL_T2F_IUI_N3F_V3F_EXT 0x81B4
+#endif /* GL_EXT_index_array_formats */
+
+#ifndef GL_EXT_index_func
+#define GL_EXT_index_func 1
+#define GL_INDEX_TEST_EXT 0x81B5
+#define GL_INDEX_TEST_FUNC_EXT 0x81B6
+#define GL_INDEX_TEST_REF_EXT 0x81B7
+typedef void (APIENTRYP PFNGLINDEXFUNCEXTPROC) (GLenum func, GLclampf ref);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glIndexFuncEXT (GLenum func, GLclampf ref);
+#endif
+#endif /* GL_EXT_index_func */
+
+#ifndef GL_EXT_index_material
+#define GL_EXT_index_material 1
+#define GL_INDEX_MATERIAL_EXT 0x81B8
+#define GL_INDEX_MATERIAL_PARAMETER_EXT 0x81B9
+#define GL_INDEX_MATERIAL_FACE_EXT 0x81BA
+typedef void (APIENTRYP PFNGLINDEXMATERIALEXTPROC) (GLenum face, GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glIndexMaterialEXT (GLenum face, GLenum mode);
+#endif
+#endif /* GL_EXT_index_material */
+
+#ifndef GL_EXT_index_texture
+#define GL_EXT_index_texture 1
+#endif /* GL_EXT_index_texture */
+
+#ifndef GL_EXT_light_texture
+#define GL_EXT_light_texture 1
+#define GL_FRAGMENT_MATERIAL_EXT 0x8349
+#define GL_FRAGMENT_NORMAL_EXT 0x834A
+#define GL_FRAGMENT_COLOR_EXT 0x834C
+#define GL_ATTENUATION_EXT 0x834D
+#define GL_SHADOW_ATTENUATION_EXT 0x834E
+#define GL_TEXTURE_APPLICATION_MODE_EXT 0x834F
+#define GL_TEXTURE_LIGHT_EXT 0x8350
+#define GL_TEXTURE_MATERIAL_FACE_EXT 0x8351
+#define GL_TEXTURE_MATERIAL_PARAMETER_EXT 0x8352
+typedef void (APIENTRYP PFNGLAPPLYTEXTUREEXTPROC) (GLenum mode);
+typedef void (APIENTRYP PFNGLTEXTURELIGHTEXTPROC) (GLenum pname);
+typedef void (APIENTRYP PFNGLTEXTUREMATERIALEXTPROC) (GLenum face, GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glApplyTextureEXT (GLenum mode);
+GLAPI void APIENTRY glTextureLightEXT (GLenum pname);
+GLAPI void APIENTRY glTextureMaterialEXT (GLenum face, GLenum mode);
+#endif
+#endif /* GL_EXT_light_texture */
+
+#ifndef GL_EXT_misc_attribute
+#define GL_EXT_misc_attribute 1
+#endif /* GL_EXT_misc_attribute */
+
+#ifndef GL_EXT_multi_draw_arrays
+#define GL_EXT_multi_draw_arrays 1
+typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount);
+typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei primcount);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMultiDrawArraysEXT (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount);
+GLAPI void APIENTRY glMultiDrawElementsEXT (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei primcount);
+#endif
+#endif /* GL_EXT_multi_draw_arrays */
+
+#ifndef GL_EXT_multisample
+#define GL_EXT_multisample 1
+#define GL_MULTISAMPLE_EXT 0x809D
+#define GL_SAMPLE_ALPHA_TO_MASK_EXT 0x809E
+#define GL_SAMPLE_ALPHA_TO_ONE_EXT 0x809F
+#define GL_SAMPLE_MASK_EXT 0x80A0
+#define GL_1PASS_EXT 0x80A1
+#define GL_2PASS_0_EXT 0x80A2
+#define GL_2PASS_1_EXT 0x80A3
+#define GL_4PASS_0_EXT 0x80A4
+#define GL_4PASS_1_EXT 0x80A5
+#define GL_4PASS_2_EXT 0x80A6
+#define GL_4PASS_3_EXT 0x80A7
+#define GL_SAMPLE_BUFFERS_EXT 0x80A8
+#define GL_SAMPLES_EXT 0x80A9
+#define GL_SAMPLE_MASK_VALUE_EXT 0x80AA
+#define GL_SAMPLE_MASK_INVERT_EXT 0x80AB
+#define GL_SAMPLE_PATTERN_EXT 0x80AC
+#define GL_MULTISAMPLE_BIT_EXT 0x20000000
+typedef void (APIENTRYP PFNGLSAMPLEMASKEXTPROC) (GLclampf value, GLboolean invert);
+typedef void (APIENTRYP PFNGLSAMPLEPATTERNEXTPROC) (GLenum pattern);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glSampleMaskEXT (GLclampf value, GLboolean invert);
+GLAPI void APIENTRY glSamplePatternEXT (GLenum pattern);
+#endif
+#endif /* GL_EXT_multisample */
+
+#ifndef GL_EXT_packed_depth_stencil
+#define GL_EXT_packed_depth_stencil 1
+#define GL_DEPTH_STENCIL_EXT 0x84F9
+#define GL_UNSIGNED_INT_24_8_EXT 0x84FA
+#define GL_DEPTH24_STENCIL8_EXT 0x88F0
+#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1
+#endif /* GL_EXT_packed_depth_stencil */
+
+#ifndef GL_EXT_packed_float
+#define GL_EXT_packed_float 1
+#define GL_R11F_G11F_B10F_EXT 0x8C3A
+#define GL_UNSIGNED_INT_10F_11F_11F_REV_EXT 0x8C3B
+#define GL_RGBA_SIGNED_COMPONENTS_EXT 0x8C3C
+#endif /* GL_EXT_packed_float */
+
+#ifndef GL_EXT_packed_pixels
+#define GL_EXT_packed_pixels 1
+#define GL_UNSIGNED_BYTE_3_3_2_EXT 0x8032
+#define GL_UNSIGNED_SHORT_4_4_4_4_EXT 0x8033
+#define GL_UNSIGNED_SHORT_5_5_5_1_EXT 0x8034
+#define GL_UNSIGNED_INT_8_8_8_8_EXT 0x8035
+#define GL_UNSIGNED_INT_10_10_10_2_EXT 0x8036
+#endif /* GL_EXT_packed_pixels */
+
+#ifndef GL_EXT_paletted_texture
+#define GL_EXT_paletted_texture 1
+#define GL_COLOR_INDEX1_EXT 0x80E2
+#define GL_COLOR_INDEX2_EXT 0x80E3
+#define GL_COLOR_INDEX4_EXT 0x80E4
+#define GL_COLOR_INDEX8_EXT 0x80E5
+#define GL_COLOR_INDEX12_EXT 0x80E6
+#define GL_COLOR_INDEX16_EXT 0x80E7
+#define GL_TEXTURE_INDEX_SIZE_EXT 0x80ED
+typedef void (APIENTRYP PFNGLCOLORTABLEEXTPROC) (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const void *table);
+typedef void (APIENTRYP PFNGLGETCOLORTABLEEXTPROC) (GLenum target, GLenum format, GLenum type, void *data);
+typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glColorTableEXT (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const void *table);
+GLAPI void APIENTRY glGetColorTableEXT (GLenum target, GLenum format, GLenum type, void *data);
+GLAPI void APIENTRY glGetColorTableParameterivEXT (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetColorTableParameterfvEXT (GLenum target, GLenum pname, GLfloat *params);
+#endif
+#endif /* GL_EXT_paletted_texture */
+
+#ifndef GL_EXT_pixel_buffer_object
+#define GL_EXT_pixel_buffer_object 1
+#define GL_PIXEL_PACK_BUFFER_EXT 0x88EB
+#define GL_PIXEL_UNPACK_BUFFER_EXT 0x88EC
+#define GL_PIXEL_PACK_BUFFER_BINDING_EXT 0x88ED
+#define GL_PIXEL_UNPACK_BUFFER_BINDING_EXT 0x88EF
+#endif /* GL_EXT_pixel_buffer_object */
+
+#ifndef GL_EXT_pixel_transform
+#define GL_EXT_pixel_transform 1
+#define GL_PIXEL_TRANSFORM_2D_EXT 0x8330
+#define GL_PIXEL_MAG_FILTER_EXT 0x8331
+#define GL_PIXEL_MIN_FILTER_EXT 0x8332
+#define GL_PIXEL_CUBIC_WEIGHT_EXT 0x8333
+#define GL_CUBIC_EXT 0x8334
+#define GL_AVERAGE_EXT 0x8335
+#define GL_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8336
+#define GL_MAX_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8337
+#define GL_PIXEL_TRANSFORM_2D_MATRIX_EXT 0x8338
+typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLGETPIXELTRANSFORMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETPIXELTRANSFORMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPixelTransformParameteriEXT (GLenum target, GLenum pname, GLint param);
+GLAPI void APIENTRY glPixelTransformParameterfEXT (GLenum target, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glPixelTransformParameterivEXT (GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glPixelTransformParameterfvEXT (GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glGetPixelTransformParameterivEXT (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetPixelTransformParameterfvEXT (GLenum target, GLenum pname, GLfloat *params);
+#endif
+#endif /* GL_EXT_pixel_transform */
+
+#ifndef GL_EXT_pixel_transform_color_table
+#define GL_EXT_pixel_transform_color_table 1
+#endif /* GL_EXT_pixel_transform_color_table */
+
+#ifndef GL_EXT_point_parameters
+#define GL_EXT_point_parameters 1
+#define GL_POINT_SIZE_MIN_EXT 0x8126
+#define GL_POINT_SIZE_MAX_EXT 0x8127
+#define GL_POINT_FADE_THRESHOLD_SIZE_EXT 0x8128
+#define GL_DISTANCE_ATTENUATION_EXT 0x8129
+typedef void (APIENTRYP PFNGLPOINTPARAMETERFEXTPROC) (GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLPOINTPARAMETERFVEXTPROC) (GLenum pname, const GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPointParameterfEXT (GLenum pname, GLfloat param);
+GLAPI void APIENTRY glPointParameterfvEXT (GLenum pname, const GLfloat *params);
+#endif
+#endif /* GL_EXT_point_parameters */
+
+#ifndef GL_EXT_polygon_offset
+#define GL_EXT_polygon_offset 1
+#define GL_POLYGON_OFFSET_EXT 0x8037
+#define GL_POLYGON_OFFSET_FACTOR_EXT 0x8038
+#define GL_POLYGON_OFFSET_BIAS_EXT 0x8039
+typedef void (APIENTRYP PFNGLPOLYGONOFFSETEXTPROC) (GLfloat factor, GLfloat bias);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPolygonOffsetEXT (GLfloat factor, GLfloat bias);
+#endif
+#endif /* GL_EXT_polygon_offset */
+
+#ifndef GL_EXT_provoking_vertex
+#define GL_EXT_provoking_vertex 1
+#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION_EXT 0x8E4C
+#define GL_FIRST_VERTEX_CONVENTION_EXT 0x8E4D
+#define GL_LAST_VERTEX_CONVENTION_EXT 0x8E4E
+#define GL_PROVOKING_VERTEX_EXT 0x8E4F
+typedef void (APIENTRYP PFNGLPROVOKINGVERTEXEXTPROC) (GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProvokingVertexEXT (GLenum mode);
+#endif
+#endif /* GL_EXT_provoking_vertex */
+
+#ifndef GL_EXT_rescale_normal
+#define GL_EXT_rescale_normal 1
+#define GL_RESCALE_NORMAL_EXT 0x803A
+#endif /* GL_EXT_rescale_normal */
+
+#ifndef GL_EXT_secondary_color
+#define GL_EXT_secondary_color 1
+#define GL_COLOR_SUM_EXT 0x8458
+#define GL_CURRENT_SECONDARY_COLOR_EXT 0x8459
+#define GL_SECONDARY_COLOR_ARRAY_SIZE_EXT 0x845A
+#define GL_SECONDARY_COLOR_ARRAY_TYPE_EXT 0x845B
+#define GL_SECONDARY_COLOR_ARRAY_STRIDE_EXT 0x845C
+#define GL_SECONDARY_COLOR_ARRAY_POINTER_EXT 0x845D
+#define GL_SECONDARY_COLOR_ARRAY_EXT 0x845E
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BEXTPROC) (GLbyte red, GLbyte green, GLbyte blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVEXTPROC) (const GLbyte *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DEXTPROC) (GLdouble red, GLdouble green, GLdouble blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVEXTPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FEXTPROC) (GLfloat red, GLfloat green, GLfloat blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVEXTPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IEXTPROC) (GLint red, GLint green, GLint blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVEXTPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SEXTPROC) (GLshort red, GLshort green, GLshort blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVEXTPROC) (const GLshort *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBEXTPROC) (GLubyte red, GLubyte green, GLubyte blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVEXTPROC) (const GLubyte *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIEXTPROC) (GLuint red, GLuint green, GLuint blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVEXTPROC) (const GLuint *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USEXTPROC) (GLushort red, GLushort green, GLushort blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVEXTPROC) (const GLushort *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, const void *pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glSecondaryColor3bEXT (GLbyte red, GLbyte green, GLbyte blue);
+GLAPI void APIENTRY glSecondaryColor3bvEXT (const GLbyte *v);
+GLAPI void APIENTRY glSecondaryColor3dEXT (GLdouble red, GLdouble green, GLdouble blue);
+GLAPI void APIENTRY glSecondaryColor3dvEXT (const GLdouble *v);
+GLAPI void APIENTRY glSecondaryColor3fEXT (GLfloat red, GLfloat green, GLfloat blue);
+GLAPI void APIENTRY glSecondaryColor3fvEXT (const GLfloat *v);
+GLAPI void APIENTRY glSecondaryColor3iEXT (GLint red, GLint green, GLint blue);
+GLAPI void APIENTRY glSecondaryColor3ivEXT (const GLint *v);
+GLAPI void APIENTRY glSecondaryColor3sEXT (GLshort red, GLshort green, GLshort blue);
+GLAPI void APIENTRY glSecondaryColor3svEXT (const GLshort *v);
+GLAPI void APIENTRY glSecondaryColor3ubEXT (GLubyte red, GLubyte green, GLubyte blue);
+GLAPI void APIENTRY glSecondaryColor3ubvEXT (const GLubyte *v);
+GLAPI void APIENTRY glSecondaryColor3uiEXT (GLuint red, GLuint green, GLuint blue);
+GLAPI void APIENTRY glSecondaryColor3uivEXT (const GLuint *v);
+GLAPI void APIENTRY glSecondaryColor3usEXT (GLushort red, GLushort green, GLushort blue);
+GLAPI void APIENTRY glSecondaryColor3usvEXT (const GLushort *v);
+GLAPI void APIENTRY glSecondaryColorPointerEXT (GLint size, GLenum type, GLsizei stride, const void *pointer);
+#endif
+#endif /* GL_EXT_secondary_color */
+
+#ifndef GL_EXT_separate_shader_objects
+#define GL_EXT_separate_shader_objects 1
+#define GL_ACTIVE_PROGRAM_EXT 0x8B8D
+typedef void (APIENTRYP PFNGLUSESHADERPROGRAMEXTPROC) (GLenum type, GLuint program);
+typedef void (APIENTRYP PFNGLACTIVEPROGRAMEXTPROC) (GLuint program);
+typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMEXTPROC) (GLenum type, const GLchar *string);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glUseShaderProgramEXT (GLenum type, GLuint program);
+GLAPI void APIENTRY glActiveProgramEXT (GLuint program);
+GLAPI GLuint APIENTRY glCreateShaderProgramEXT (GLenum type, const GLchar *string);
+#endif
+#endif /* GL_EXT_separate_shader_objects */
+
+#ifndef GL_EXT_separate_specular_color
+#define GL_EXT_separate_specular_color 1
+#define GL_LIGHT_MODEL_COLOR_CONTROL_EXT 0x81F8
+#define GL_SINGLE_COLOR_EXT 0x81F9
+#define GL_SEPARATE_SPECULAR_COLOR_EXT 0x81FA
+#endif /* GL_EXT_separate_specular_color */
+
+#ifndef GL_EXT_shader_image_load_formatted
+#define GL_EXT_shader_image_load_formatted 1
+#endif /* GL_EXT_shader_image_load_formatted */
+
+#ifndef GL_EXT_shader_image_load_store
+#define GL_EXT_shader_image_load_store 1
+#define GL_MAX_IMAGE_UNITS_EXT 0x8F38
+#define GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS_EXT 0x8F39
+#define GL_IMAGE_BINDING_NAME_EXT 0x8F3A
+#define GL_IMAGE_BINDING_LEVEL_EXT 0x8F3B
+#define GL_IMAGE_BINDING_LAYERED_EXT 0x8F3C
+#define GL_IMAGE_BINDING_LAYER_EXT 0x8F3D
+#define GL_IMAGE_BINDING_ACCESS_EXT 0x8F3E
+#define GL_IMAGE_1D_EXT 0x904C
+#define GL_IMAGE_2D_EXT 0x904D
+#define GL_IMAGE_3D_EXT 0x904E
+#define GL_IMAGE_2D_RECT_EXT 0x904F
+#define GL_IMAGE_CUBE_EXT 0x9050
+#define GL_IMAGE_BUFFER_EXT 0x9051
+#define GL_IMAGE_1D_ARRAY_EXT 0x9052
+#define GL_IMAGE_2D_ARRAY_EXT 0x9053
+#define GL_IMAGE_CUBE_MAP_ARRAY_EXT 0x9054
+#define GL_IMAGE_2D_MULTISAMPLE_EXT 0x9055
+#define GL_IMAGE_2D_MULTISAMPLE_ARRAY_EXT 0x9056
+#define GL_INT_IMAGE_1D_EXT 0x9057
+#define GL_INT_IMAGE_2D_EXT 0x9058
+#define GL_INT_IMAGE_3D_EXT 0x9059
+#define GL_INT_IMAGE_2D_RECT_EXT 0x905A
+#define GL_INT_IMAGE_CUBE_EXT 0x905B
+#define GL_INT_IMAGE_BUFFER_EXT 0x905C
+#define GL_INT_IMAGE_1D_ARRAY_EXT 0x905D
+#define GL_INT_IMAGE_2D_ARRAY_EXT 0x905E
+#define GL_INT_IMAGE_CUBE_MAP_ARRAY_EXT 0x905F
+#define GL_INT_IMAGE_2D_MULTISAMPLE_EXT 0x9060
+#define GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY_EXT 0x9061
+#define GL_UNSIGNED_INT_IMAGE_1D_EXT 0x9062
+#define GL_UNSIGNED_INT_IMAGE_2D_EXT 0x9063
+#define GL_UNSIGNED_INT_IMAGE_3D_EXT 0x9064
+#define GL_UNSIGNED_INT_IMAGE_2D_RECT_EXT 0x9065
+#define GL_UNSIGNED_INT_IMAGE_CUBE_EXT 0x9066
+#define GL_UNSIGNED_INT_IMAGE_BUFFER_EXT 0x9067
+#define GL_UNSIGNED_INT_IMAGE_1D_ARRAY_EXT 0x9068
+#define GL_UNSIGNED_INT_IMAGE_2D_ARRAY_EXT 0x9069
+#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY_EXT 0x906A
+#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_EXT 0x906B
+#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY_EXT 0x906C
+#define GL_MAX_IMAGE_SAMPLES_EXT 0x906D
+#define GL_IMAGE_BINDING_FORMAT_EXT 0x906E
+#define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT_EXT 0x00000001
+#define GL_ELEMENT_ARRAY_BARRIER_BIT_EXT 0x00000002
+#define GL_UNIFORM_BARRIER_BIT_EXT 0x00000004
+#define GL_TEXTURE_FETCH_BARRIER_BIT_EXT 0x00000008
+#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT_EXT 0x00000020
+#define GL_COMMAND_BARRIER_BIT_EXT 0x00000040
+#define GL_PIXEL_BUFFER_BARRIER_BIT_EXT 0x00000080
+#define GL_TEXTURE_UPDATE_BARRIER_BIT_EXT 0x00000100
+#define GL_BUFFER_UPDATE_BARRIER_BIT_EXT 0x00000200
+#define GL_FRAMEBUFFER_BARRIER_BIT_EXT 0x00000400
+#define GL_TRANSFORM_FEEDBACK_BARRIER_BIT_EXT 0x00000800
+#define GL_ATOMIC_COUNTER_BARRIER_BIT_EXT 0x00001000
+#define GL_ALL_BARRIER_BITS_EXT 0xFFFFFFFF
+typedef void (APIENTRYP PFNGLBINDIMAGETEXTUREEXTPROC) (GLuint index, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLint format);
+typedef void (APIENTRYP PFNGLMEMORYBARRIEREXTPROC) (GLbitfield barriers);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBindImageTextureEXT (GLuint index, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLint format);
+GLAPI void APIENTRY glMemoryBarrierEXT (GLbitfield barriers);
+#endif
+#endif /* GL_EXT_shader_image_load_store */
+
+#ifndef GL_EXT_shader_integer_mix
+#define GL_EXT_shader_integer_mix 1
+#endif /* GL_EXT_shader_integer_mix */
+
+#ifndef GL_EXT_shadow_funcs
+#define GL_EXT_shadow_funcs 1
+#endif /* GL_EXT_shadow_funcs */
+
+#ifndef GL_EXT_shared_texture_palette
+#define GL_EXT_shared_texture_palette 1
+#define GL_SHARED_TEXTURE_PALETTE_EXT 0x81FB
+#endif /* GL_EXT_shared_texture_palette */
+
+#ifndef GL_EXT_stencil_clear_tag
+#define GL_EXT_stencil_clear_tag 1
+#define GL_STENCIL_TAG_BITS_EXT 0x88F2
+#define GL_STENCIL_CLEAR_TAG_VALUE_EXT 0x88F3
+typedef void (APIENTRYP PFNGLSTENCILCLEARTAGEXTPROC) (GLsizei stencilTagBits, GLuint stencilClearTag);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glStencilClearTagEXT (GLsizei stencilTagBits, GLuint stencilClearTag);
+#endif
+#endif /* GL_EXT_stencil_clear_tag */
+
+#ifndef GL_EXT_stencil_two_side
+#define GL_EXT_stencil_two_side 1
+#define GL_STENCIL_TEST_TWO_SIDE_EXT 0x8910
+#define GL_ACTIVE_STENCIL_FACE_EXT 0x8911
+typedef void (APIENTRYP PFNGLACTIVESTENCILFACEEXTPROC) (GLenum face);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glActiveStencilFaceEXT (GLenum face);
+#endif
+#endif /* GL_EXT_stencil_two_side */
+
+#ifndef GL_EXT_stencil_wrap
+#define GL_EXT_stencil_wrap 1
+#define GL_INCR_WRAP_EXT 0x8507
+#define GL_DECR_WRAP_EXT 0x8508
+#endif /* GL_EXT_stencil_wrap */
+
+#ifndef GL_EXT_subtexture
+#define GL_EXT_subtexture 1
+typedef void (APIENTRYP PFNGLTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexSubImage1DEXT (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glTexSubImage2DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
+#endif
+#endif /* GL_EXT_subtexture */
+
+#ifndef GL_EXT_texture
+#define GL_EXT_texture 1
+#define GL_ALPHA4_EXT 0x803B
+#define GL_ALPHA8_EXT 0x803C
+#define GL_ALPHA12_EXT 0x803D
+#define GL_ALPHA16_EXT 0x803E
+#define GL_LUMINANCE4_EXT 0x803F
+#define GL_LUMINANCE8_EXT 0x8040
+#define GL_LUMINANCE12_EXT 0x8041
+#define GL_LUMINANCE16_EXT 0x8042
+#define GL_LUMINANCE4_ALPHA4_EXT 0x8043
+#define GL_LUMINANCE6_ALPHA2_EXT 0x8044
+#define GL_LUMINANCE8_ALPHA8_EXT 0x8045
+#define GL_LUMINANCE12_ALPHA4_EXT 0x8046
+#define GL_LUMINANCE12_ALPHA12_EXT 0x8047
+#define GL_LUMINANCE16_ALPHA16_EXT 0x8048
+#define GL_INTENSITY_EXT 0x8049
+#define GL_INTENSITY4_EXT 0x804A
+#define GL_INTENSITY8_EXT 0x804B
+#define GL_INTENSITY12_EXT 0x804C
+#define GL_INTENSITY16_EXT 0x804D
+#define GL_RGB2_EXT 0x804E
+#define GL_RGB4_EXT 0x804F
+#define GL_RGB5_EXT 0x8050
+#define GL_RGB8_EXT 0x8051
+#define GL_RGB10_EXT 0x8052
+#define GL_RGB12_EXT 0x8053
+#define GL_RGB16_EXT 0x8054
+#define GL_RGBA2_EXT 0x8055
+#define GL_RGBA4_EXT 0x8056
+#define GL_RGB5_A1_EXT 0x8057
+#define GL_RGBA8_EXT 0x8058
+#define GL_RGB10_A2_EXT 0x8059
+#define GL_RGBA12_EXT 0x805A
+#define GL_RGBA16_EXT 0x805B
+#define GL_TEXTURE_RED_SIZE_EXT 0x805C
+#define GL_TEXTURE_GREEN_SIZE_EXT 0x805D
+#define GL_TEXTURE_BLUE_SIZE_EXT 0x805E
+#define GL_TEXTURE_ALPHA_SIZE_EXT 0x805F
+#define GL_TEXTURE_LUMINANCE_SIZE_EXT 0x8060
+#define GL_TEXTURE_INTENSITY_SIZE_EXT 0x8061
+#define GL_REPLACE_EXT 0x8062
+#define GL_PROXY_TEXTURE_1D_EXT 0x8063
+#define GL_PROXY_TEXTURE_2D_EXT 0x8064
+#define GL_TEXTURE_TOO_LARGE_EXT 0x8065
+#endif /* GL_EXT_texture */
+
+#ifndef GL_EXT_texture3D
+#define GL_EXT_texture3D 1
+#define GL_PACK_SKIP_IMAGES_EXT 0x806B
+#define GL_PACK_IMAGE_HEIGHT_EXT 0x806C
+#define GL_UNPACK_SKIP_IMAGES_EXT 0x806D
+#define GL_UNPACK_IMAGE_HEIGHT_EXT 0x806E
+#define GL_TEXTURE_3D_EXT 0x806F
+#define GL_PROXY_TEXTURE_3D_EXT 0x8070
+#define GL_TEXTURE_DEPTH_EXT 0x8071
+#define GL_TEXTURE_WRAP_R_EXT 0x8072
+#define GL_MAX_3D_TEXTURE_SIZE_EXT 0x8073
+typedef void (APIENTRYP PFNGLTEXIMAGE3DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexImage3DEXT (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glTexSubImage3DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
+#endif
+#endif /* GL_EXT_texture3D */
+
+#ifndef GL_EXT_texture_array
+#define GL_EXT_texture_array 1
+#define GL_TEXTURE_1D_ARRAY_EXT 0x8C18
+#define GL_PROXY_TEXTURE_1D_ARRAY_EXT 0x8C19
+#define GL_TEXTURE_2D_ARRAY_EXT 0x8C1A
+#define GL_PROXY_TEXTURE_2D_ARRAY_EXT 0x8C1B
+#define GL_TEXTURE_BINDING_1D_ARRAY_EXT 0x8C1C
+#define GL_TEXTURE_BINDING_2D_ARRAY_EXT 0x8C1D
+#define GL_MAX_ARRAY_TEXTURE_LAYERS_EXT 0x88FF
+#define GL_COMPARE_REF_DEPTH_TO_TEXTURE_EXT 0x884E
+#endif /* GL_EXT_texture_array */
+
+#ifndef GL_EXT_texture_buffer_object
+#define GL_EXT_texture_buffer_object 1
+#define GL_TEXTURE_BUFFER_EXT 0x8C2A
+#define GL_MAX_TEXTURE_BUFFER_SIZE_EXT 0x8C2B
+#define GL_TEXTURE_BINDING_BUFFER_EXT 0x8C2C
+#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING_EXT 0x8C2D
+#define GL_TEXTURE_BUFFER_FORMAT_EXT 0x8C2E
+typedef void (APIENTRYP PFNGLTEXBUFFEREXTPROC) (GLenum target, GLenum internalformat, GLuint buffer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexBufferEXT (GLenum target, GLenum internalformat, GLuint buffer);
+#endif
+#endif /* GL_EXT_texture_buffer_object */
+
+#ifndef GL_EXT_texture_compression_latc
+#define GL_EXT_texture_compression_latc 1
+#define GL_COMPRESSED_LUMINANCE_LATC1_EXT 0x8C70
+#define GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT 0x8C71
+#define GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT 0x8C72
+#define GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT 0x8C73
+#endif /* GL_EXT_texture_compression_latc */
+
+#ifndef GL_EXT_texture_compression_rgtc
+#define GL_EXT_texture_compression_rgtc 1
+#define GL_COMPRESSED_RED_RGTC1_EXT 0x8DBB
+#define GL_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC
+#define GL_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD
+#define GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE
+#endif /* GL_EXT_texture_compression_rgtc */
+
+#ifndef GL_EXT_texture_compression_s3tc
+#define GL_EXT_texture_compression_s3tc 1
+#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
+#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
+#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
+#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
+#endif /* GL_EXT_texture_compression_s3tc */
+
+#ifndef GL_EXT_texture_cube_map
+#define GL_EXT_texture_cube_map 1
+#define GL_NORMAL_MAP_EXT 0x8511
+#define GL_REFLECTION_MAP_EXT 0x8512
+#define GL_TEXTURE_CUBE_MAP_EXT 0x8513
+#define GL_TEXTURE_BINDING_CUBE_MAP_EXT 0x8514
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT 0x8515
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT 0x8516
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT 0x8517
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT 0x8518
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT 0x8519
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT 0x851A
+#define GL_PROXY_TEXTURE_CUBE_MAP_EXT 0x851B
+#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_EXT 0x851C
+#endif /* GL_EXT_texture_cube_map */
+
+#ifndef GL_EXT_texture_env_add
+#define GL_EXT_texture_env_add 1
+#endif /* GL_EXT_texture_env_add */
+
+#ifndef GL_EXT_texture_env_combine
+#define GL_EXT_texture_env_combine 1
+#define GL_COMBINE_EXT 0x8570
+#define GL_COMBINE_RGB_EXT 0x8571
+#define GL_COMBINE_ALPHA_EXT 0x8572
+#define GL_RGB_SCALE_EXT 0x8573
+#define GL_ADD_SIGNED_EXT 0x8574
+#define GL_INTERPOLATE_EXT 0x8575
+#define GL_CONSTANT_EXT 0x8576
+#define GL_PRIMARY_COLOR_EXT 0x8577
+#define GL_PREVIOUS_EXT 0x8578
+#define GL_SOURCE0_RGB_EXT 0x8580
+#define GL_SOURCE1_RGB_EXT 0x8581
+#define GL_SOURCE2_RGB_EXT 0x8582
+#define GL_SOURCE0_ALPHA_EXT 0x8588
+#define GL_SOURCE1_ALPHA_EXT 0x8589
+#define GL_SOURCE2_ALPHA_EXT 0x858A
+#define GL_OPERAND0_RGB_EXT 0x8590
+#define GL_OPERAND1_RGB_EXT 0x8591
+#define GL_OPERAND2_RGB_EXT 0x8592
+#define GL_OPERAND0_ALPHA_EXT 0x8598
+#define GL_OPERAND1_ALPHA_EXT 0x8599
+#define GL_OPERAND2_ALPHA_EXT 0x859A
+#endif /* GL_EXT_texture_env_combine */
+
+#ifndef GL_EXT_texture_env_dot3
+#define GL_EXT_texture_env_dot3 1
+#define GL_DOT3_RGB_EXT 0x8740
+#define GL_DOT3_RGBA_EXT 0x8741
+#endif /* GL_EXT_texture_env_dot3 */
+
+#ifndef GL_EXT_texture_filter_anisotropic
+#define GL_EXT_texture_filter_anisotropic 1
+#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
+#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
+#endif /* GL_EXT_texture_filter_anisotropic */
+
+#ifndef GL_EXT_texture_integer
+#define GL_EXT_texture_integer 1
+#define GL_RGBA32UI_EXT 0x8D70
+#define GL_RGB32UI_EXT 0x8D71
+#define GL_ALPHA32UI_EXT 0x8D72
+#define GL_INTENSITY32UI_EXT 0x8D73
+#define GL_LUMINANCE32UI_EXT 0x8D74
+#define GL_LUMINANCE_ALPHA32UI_EXT 0x8D75
+#define GL_RGBA16UI_EXT 0x8D76
+#define GL_RGB16UI_EXT 0x8D77
+#define GL_ALPHA16UI_EXT 0x8D78
+#define GL_INTENSITY16UI_EXT 0x8D79
+#define GL_LUMINANCE16UI_EXT 0x8D7A
+#define GL_LUMINANCE_ALPHA16UI_EXT 0x8D7B
+#define GL_RGBA8UI_EXT 0x8D7C
+#define GL_RGB8UI_EXT 0x8D7D
+#define GL_ALPHA8UI_EXT 0x8D7E
+#define GL_INTENSITY8UI_EXT 0x8D7F
+#define GL_LUMINANCE8UI_EXT 0x8D80
+#define GL_LUMINANCE_ALPHA8UI_EXT 0x8D81
+#define GL_RGBA32I_EXT 0x8D82
+#define GL_RGB32I_EXT 0x8D83
+#define GL_ALPHA32I_EXT 0x8D84
+#define GL_INTENSITY32I_EXT 0x8D85
+#define GL_LUMINANCE32I_EXT 0x8D86
+#define GL_LUMINANCE_ALPHA32I_EXT 0x8D87
+#define GL_RGBA16I_EXT 0x8D88
+#define GL_RGB16I_EXT 0x8D89
+#define GL_ALPHA16I_EXT 0x8D8A
+#define GL_INTENSITY16I_EXT 0x8D8B
+#define GL_LUMINANCE16I_EXT 0x8D8C
+#define GL_LUMINANCE_ALPHA16I_EXT 0x8D8D
+#define GL_RGBA8I_EXT 0x8D8E
+#define GL_RGB8I_EXT 0x8D8F
+#define GL_ALPHA8I_EXT 0x8D90
+#define GL_INTENSITY8I_EXT 0x8D91
+#define GL_LUMINANCE8I_EXT 0x8D92
+#define GL_LUMINANCE_ALPHA8I_EXT 0x8D93
+#define GL_RED_INTEGER_EXT 0x8D94
+#define GL_GREEN_INTEGER_EXT 0x8D95
+#define GL_BLUE_INTEGER_EXT 0x8D96
+#define GL_ALPHA_INTEGER_EXT 0x8D97
+#define GL_RGB_INTEGER_EXT 0x8D98
+#define GL_RGBA_INTEGER_EXT 0x8D99
+#define GL_BGR_INTEGER_EXT 0x8D9A
+#define GL_BGRA_INTEGER_EXT 0x8D9B
+#define GL_LUMINANCE_INTEGER_EXT 0x8D9C
+#define GL_LUMINANCE_ALPHA_INTEGER_EXT 0x8D9D
+#define GL_RGBA_INTEGER_MODE_EXT 0x8D9E
+typedef void (APIENTRYP PFNGLTEXPARAMETERIIVEXTPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVEXTPROC) (GLenum target, GLenum pname, const GLuint *params);
+typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVEXTPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVEXTPROC) (GLenum target, GLenum pname, GLuint *params);
+typedef void (APIENTRYP PFNGLCLEARCOLORIIEXTPROC) (GLint red, GLint green, GLint blue, GLint alpha);
+typedef void (APIENTRYP PFNGLCLEARCOLORIUIEXTPROC) (GLuint red, GLuint green, GLuint blue, GLuint alpha);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexParameterIivEXT (GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glTexParameterIuivEXT (GLenum target, GLenum pname, const GLuint *params);
+GLAPI void APIENTRY glGetTexParameterIivEXT (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetTexParameterIuivEXT (GLenum target, GLenum pname, GLuint *params);
+GLAPI void APIENTRY glClearColorIiEXT (GLint red, GLint green, GLint blue, GLint alpha);
+GLAPI void APIENTRY glClearColorIuiEXT (GLuint red, GLuint green, GLuint blue, GLuint alpha);
+#endif
+#endif /* GL_EXT_texture_integer */
+
+#ifndef GL_EXT_texture_lod_bias
+#define GL_EXT_texture_lod_bias 1
+#define GL_MAX_TEXTURE_LOD_BIAS_EXT 0x84FD
+#define GL_TEXTURE_FILTER_CONTROL_EXT 0x8500
+#define GL_TEXTURE_LOD_BIAS_EXT 0x8501
+#endif /* GL_EXT_texture_lod_bias */
+
+#ifndef GL_EXT_texture_mirror_clamp
+#define GL_EXT_texture_mirror_clamp 1
+#define GL_MIRROR_CLAMP_EXT 0x8742
+#define GL_MIRROR_CLAMP_TO_EDGE_EXT 0x8743
+#define GL_MIRROR_CLAMP_TO_BORDER_EXT 0x8912
+#endif /* GL_EXT_texture_mirror_clamp */
+
+#ifndef GL_EXT_texture_object
+#define GL_EXT_texture_object 1
+#define GL_TEXTURE_PRIORITY_EXT 0x8066
+#define GL_TEXTURE_RESIDENT_EXT 0x8067
+#define GL_TEXTURE_1D_BINDING_EXT 0x8068
+#define GL_TEXTURE_2D_BINDING_EXT 0x8069
+#define GL_TEXTURE_3D_BINDING_EXT 0x806A
+typedef GLboolean (APIENTRYP PFNGLARETEXTURESRESIDENTEXTPROC) (GLsizei n, const GLuint *textures, GLboolean *residences);
+typedef void (APIENTRYP PFNGLBINDTEXTUREEXTPROC) (GLenum target, GLuint texture);
+typedef void (APIENTRYP PFNGLDELETETEXTURESEXTPROC) (GLsizei n, const GLuint *textures);
+typedef void (APIENTRYP PFNGLGENTEXTURESEXTPROC) (GLsizei n, GLuint *textures);
+typedef GLboolean (APIENTRYP PFNGLISTEXTUREEXTPROC) (GLuint texture);
+typedef void (APIENTRYP PFNGLPRIORITIZETEXTURESEXTPROC) (GLsizei n, const GLuint *textures, const GLclampf *priorities);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLboolean APIENTRY glAreTexturesResidentEXT (GLsizei n, const GLuint *textures, GLboolean *residences);
+GLAPI void APIENTRY glBindTextureEXT (GLenum target, GLuint texture);
+GLAPI void APIENTRY glDeleteTexturesEXT (GLsizei n, const GLuint *textures);
+GLAPI void APIENTRY glGenTexturesEXT (GLsizei n, GLuint *textures);
+GLAPI GLboolean APIENTRY glIsTextureEXT (GLuint texture);
+GLAPI void APIENTRY glPrioritizeTexturesEXT (GLsizei n, const GLuint *textures, const GLclampf *priorities);
+#endif
+#endif /* GL_EXT_texture_object */
+
+#ifndef GL_EXT_texture_perturb_normal
+#define GL_EXT_texture_perturb_normal 1
+#define GL_PERTURB_EXT 0x85AE
+#define GL_TEXTURE_NORMAL_EXT 0x85AF
+typedef void (APIENTRYP PFNGLTEXTURENORMALEXTPROC) (GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTextureNormalEXT (GLenum mode);
+#endif
+#endif /* GL_EXT_texture_perturb_normal */
+
+#ifndef GL_EXT_texture_sRGB
+#define GL_EXT_texture_sRGB 1
+#define GL_SRGB_EXT 0x8C40
+#define GL_SRGB8_EXT 0x8C41
+#define GL_SRGB_ALPHA_EXT 0x8C42
+#define GL_SRGB8_ALPHA8_EXT 0x8C43
+#define GL_SLUMINANCE_ALPHA_EXT 0x8C44
+#define GL_SLUMINANCE8_ALPHA8_EXT 0x8C45
+#define GL_SLUMINANCE_EXT 0x8C46
+#define GL_SLUMINANCE8_EXT 0x8C47
+#define GL_COMPRESSED_SRGB_EXT 0x8C48
+#define GL_COMPRESSED_SRGB_ALPHA_EXT 0x8C49
+#define GL_COMPRESSED_SLUMINANCE_EXT 0x8C4A
+#define GL_COMPRESSED_SLUMINANCE_ALPHA_EXT 0x8C4B
+#define GL_COMPRESSED_SRGB_S3TC_DXT1_EXT 0x8C4C
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT 0x8C4E
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F
+#endif /* GL_EXT_texture_sRGB */
+
+#ifndef GL_EXT_texture_sRGB_decode
+#define GL_EXT_texture_sRGB_decode 1
+#define GL_TEXTURE_SRGB_DECODE_EXT 0x8A48
+#define GL_DECODE_EXT 0x8A49
+#define GL_SKIP_DECODE_EXT 0x8A4A
+#endif /* GL_EXT_texture_sRGB_decode */
+
+#ifndef GL_EXT_texture_shared_exponent
+#define GL_EXT_texture_shared_exponent 1
+#define GL_RGB9_E5_EXT 0x8C3D
+#define GL_UNSIGNED_INT_5_9_9_9_REV_EXT 0x8C3E
+#define GL_TEXTURE_SHARED_SIZE_EXT 0x8C3F
+#endif /* GL_EXT_texture_shared_exponent */
+
+#ifndef GL_EXT_texture_snorm
+#define GL_EXT_texture_snorm 1
+#define GL_ALPHA_SNORM 0x9010
+#define GL_LUMINANCE_SNORM 0x9011
+#define GL_LUMINANCE_ALPHA_SNORM 0x9012
+#define GL_INTENSITY_SNORM 0x9013
+#define GL_ALPHA8_SNORM 0x9014
+#define GL_LUMINANCE8_SNORM 0x9015
+#define GL_LUMINANCE8_ALPHA8_SNORM 0x9016
+#define GL_INTENSITY8_SNORM 0x9017
+#define GL_ALPHA16_SNORM 0x9018
+#define GL_LUMINANCE16_SNORM 0x9019
+#define GL_LUMINANCE16_ALPHA16_SNORM 0x901A
+#define GL_INTENSITY16_SNORM 0x901B
+#define GL_RED_SNORM 0x8F90
+#define GL_RG_SNORM 0x8F91
+#define GL_RGB_SNORM 0x8F92
+#define GL_RGBA_SNORM 0x8F93
+#endif /* GL_EXT_texture_snorm */
+
+#ifndef GL_EXT_texture_swizzle
+#define GL_EXT_texture_swizzle 1
+#define GL_TEXTURE_SWIZZLE_R_EXT 0x8E42
+#define GL_TEXTURE_SWIZZLE_G_EXT 0x8E43
+#define GL_TEXTURE_SWIZZLE_B_EXT 0x8E44
+#define GL_TEXTURE_SWIZZLE_A_EXT 0x8E45
+#define GL_TEXTURE_SWIZZLE_RGBA_EXT 0x8E46
+#endif /* GL_EXT_texture_swizzle */
+
+#ifndef GL_EXT_timer_query
+#define GL_EXT_timer_query 1
+#define GL_TIME_ELAPSED_EXT 0x88BF
+typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VEXTPROC) (GLuint id, GLenum pname, GLint64 *params);
+typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VEXTPROC) (GLuint id, GLenum pname, GLuint64 *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGetQueryObjecti64vEXT (GLuint id, GLenum pname, GLint64 *params);
+GLAPI void APIENTRY glGetQueryObjectui64vEXT (GLuint id, GLenum pname, GLuint64 *params);
+#endif
+#endif /* GL_EXT_timer_query */
+
+#ifndef GL_EXT_transform_feedback
+#define GL_EXT_transform_feedback 1
+#define GL_TRANSFORM_FEEDBACK_BUFFER_EXT 0x8C8E
+#define GL_TRANSFORM_FEEDBACK_BUFFER_START_EXT 0x8C84
+#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE_EXT 0x8C85
+#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING_EXT 0x8C8F
+#define GL_INTERLEAVED_ATTRIBS_EXT 0x8C8C
+#define GL_SEPARATE_ATTRIBS_EXT 0x8C8D
+#define GL_PRIMITIVES_GENERATED_EXT 0x8C87
+#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_EXT 0x8C88
+#define GL_RASTERIZER_DISCARD_EXT 0x8C89
+#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_EXT 0x8C8A
+#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_EXT 0x8C8B
+#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_EXT 0x8C80
+#define GL_TRANSFORM_FEEDBACK_VARYINGS_EXT 0x8C83
+#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE_EXT 0x8C7F
+#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH_EXT 0x8C76
+typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKEXTPROC) (GLenum primitiveMode);
+typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKEXTPROC) (void);
+typedef void (APIENTRYP PFNGLBINDBUFFERRANGEEXTPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size);
+typedef void (APIENTRYP PFNGLBINDBUFFEROFFSETEXTPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset);
+typedef void (APIENTRYP PFNGLBINDBUFFERBASEEXTPROC) (GLenum target, GLuint index, GLuint buffer);
+typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSEXTPROC) (GLuint program, GLsizei count, const GLchar *const*varyings, GLenum bufferMode);
+typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGEXTPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBeginTransformFeedbackEXT (GLenum primitiveMode);
+GLAPI void APIENTRY glEndTransformFeedbackEXT (void);
+GLAPI void APIENTRY glBindBufferRangeEXT (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size);
+GLAPI void APIENTRY glBindBufferOffsetEXT (GLenum target, GLuint index, GLuint buffer, GLintptr offset);
+GLAPI void APIENTRY glBindBufferBaseEXT (GLenum target, GLuint index, GLuint buffer);
+GLAPI void APIENTRY glTransformFeedbackVaryingsEXT (GLuint program, GLsizei count, const GLchar *const*varyings, GLenum bufferMode);
+GLAPI void APIENTRY glGetTransformFeedbackVaryingEXT (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name);
+#endif
+#endif /* GL_EXT_transform_feedback */
+
+#ifndef GL_EXT_vertex_array
+#define GL_EXT_vertex_array 1
+#define GL_VERTEX_ARRAY_EXT 0x8074
+#define GL_NORMAL_ARRAY_EXT 0x8075
+#define GL_COLOR_ARRAY_EXT 0x8076
+#define GL_INDEX_ARRAY_EXT 0x8077
+#define GL_TEXTURE_COORD_ARRAY_EXT 0x8078
+#define GL_EDGE_FLAG_ARRAY_EXT 0x8079
+#define GL_VERTEX_ARRAY_SIZE_EXT 0x807A
+#define GL_VERTEX_ARRAY_TYPE_EXT 0x807B
+#define GL_VERTEX_ARRAY_STRIDE_EXT 0x807C
+#define GL_VERTEX_ARRAY_COUNT_EXT 0x807D
+#define GL_NORMAL_ARRAY_TYPE_EXT 0x807E
+#define GL_NORMAL_ARRAY_STRIDE_EXT 0x807F
+#define GL_NORMAL_ARRAY_COUNT_EXT 0x8080
+#define GL_COLOR_ARRAY_SIZE_EXT 0x8081
+#define GL_COLOR_ARRAY_TYPE_EXT 0x8082
+#define GL_COLOR_ARRAY_STRIDE_EXT 0x8083
+#define GL_COLOR_ARRAY_COUNT_EXT 0x8084
+#define GL_INDEX_ARRAY_TYPE_EXT 0x8085
+#define GL_INDEX_ARRAY_STRIDE_EXT 0x8086
+#define GL_INDEX_ARRAY_COUNT_EXT 0x8087
+#define GL_TEXTURE_COORD_ARRAY_SIZE_EXT 0x8088
+#define GL_TEXTURE_COORD_ARRAY_TYPE_EXT 0x8089
+#define GL_TEXTURE_COORD_ARRAY_STRIDE_EXT 0x808A
+#define GL_TEXTURE_COORD_ARRAY_COUNT_EXT 0x808B
+#define GL_EDGE_FLAG_ARRAY_STRIDE_EXT 0x808C
+#define GL_EDGE_FLAG_ARRAY_COUNT_EXT 0x808D
+#define GL_VERTEX_ARRAY_POINTER_EXT 0x808E
+#define GL_NORMAL_ARRAY_POINTER_EXT 0x808F
+#define GL_COLOR_ARRAY_POINTER_EXT 0x8090
+#define GL_INDEX_ARRAY_POINTER_EXT 0x8091
+#define GL_TEXTURE_COORD_ARRAY_POINTER_EXT 0x8092
+#define GL_EDGE_FLAG_ARRAY_POINTER_EXT 0x8093
+typedef void (APIENTRYP PFNGLARRAYELEMENTEXTPROC) (GLint i);
+typedef void (APIENTRYP PFNGLCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+typedef void (APIENTRYP PFNGLDRAWARRAYSEXTPROC) (GLenum mode, GLint first, GLsizei count);
+typedef void (APIENTRYP PFNGLEDGEFLAGPOINTEREXTPROC) (GLsizei stride, GLsizei count, const GLboolean *pointer);
+typedef void (APIENTRYP PFNGLGETPOINTERVEXTPROC) (GLenum pname, void **params);
+typedef void (APIENTRYP PFNGLINDEXPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+typedef void (APIENTRYP PFNGLNORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+typedef void (APIENTRYP PFNGLTEXCOORDPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+typedef void (APIENTRYP PFNGLVERTEXPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glArrayElementEXT (GLint i);
+GLAPI void APIENTRY glColorPointerEXT (GLint size, GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+GLAPI void APIENTRY glDrawArraysEXT (GLenum mode, GLint first, GLsizei count);
+GLAPI void APIENTRY glEdgeFlagPointerEXT (GLsizei stride, GLsizei count, const GLboolean *pointer);
+GLAPI void APIENTRY glGetPointervEXT (GLenum pname, void **params);
+GLAPI void APIENTRY glIndexPointerEXT (GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+GLAPI void APIENTRY glNormalPointerEXT (GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+GLAPI void APIENTRY glTexCoordPointerEXT (GLint size, GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+GLAPI void APIENTRY glVertexPointerEXT (GLint size, GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+#endif
+#endif /* GL_EXT_vertex_array */
+
+#ifndef GL_EXT_vertex_array_bgra
+#define GL_EXT_vertex_array_bgra 1
+#endif /* GL_EXT_vertex_array_bgra */
+
+#ifndef GL_EXT_vertex_attrib_64bit
+#define GL_EXT_vertex_attrib_64bit 1
+#define GL_DOUBLE_VEC2_EXT 0x8FFC
+#define GL_DOUBLE_VEC3_EXT 0x8FFD
+#define GL_DOUBLE_VEC4_EXT 0x8FFE
+#define GL_DOUBLE_MAT2_EXT 0x8F46
+#define GL_DOUBLE_MAT3_EXT 0x8F47
+#define GL_DOUBLE_MAT4_EXT 0x8F48
+#define GL_DOUBLE_MAT2x3_EXT 0x8F49
+#define GL_DOUBLE_MAT2x4_EXT 0x8F4A
+#define GL_DOUBLE_MAT3x2_EXT 0x8F4B
+#define GL_DOUBLE_MAT3x4_EXT 0x8F4C
+#define GL_DOUBLE_MAT4x2_EXT 0x8F4D
+#define GL_DOUBLE_MAT4x3_EXT 0x8F4E
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DEXTPROC) (GLuint index, GLdouble x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DEXTPROC) (GLuint index, GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DEXTPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DEXTPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DVEXTPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DVEXTPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DVEXTPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DVEXTPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTEREXTPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLDVEXTPROC) (GLuint index, GLenum pname, GLdouble *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexAttribL1dEXT (GLuint index, GLdouble x);
+GLAPI void APIENTRY glVertexAttribL2dEXT (GLuint index, GLdouble x, GLdouble y);
+GLAPI void APIENTRY glVertexAttribL3dEXT (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glVertexAttribL4dEXT (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glVertexAttribL1dvEXT (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribL2dvEXT (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribL3dvEXT (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribL4dvEXT (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribLPointerEXT (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glGetVertexAttribLdvEXT (GLuint index, GLenum pname, GLdouble *params);
+#endif
+#endif /* GL_EXT_vertex_attrib_64bit */
+
+#ifndef GL_EXT_vertex_shader
+#define GL_EXT_vertex_shader 1
+#define GL_VERTEX_SHADER_EXT 0x8780
+#define GL_VERTEX_SHADER_BINDING_EXT 0x8781
+#define GL_OP_INDEX_EXT 0x8782
+#define GL_OP_NEGATE_EXT 0x8783
+#define GL_OP_DOT3_EXT 0x8784
+#define GL_OP_DOT4_EXT 0x8785
+#define GL_OP_MUL_EXT 0x8786
+#define GL_OP_ADD_EXT 0x8787
+#define GL_OP_MADD_EXT 0x8788
+#define GL_OP_FRAC_EXT 0x8789
+#define GL_OP_MAX_EXT 0x878A
+#define GL_OP_MIN_EXT 0x878B
+#define GL_OP_SET_GE_EXT 0x878C
+#define GL_OP_SET_LT_EXT 0x878D
+#define GL_OP_CLAMP_EXT 0x878E
+#define GL_OP_FLOOR_EXT 0x878F
+#define GL_OP_ROUND_EXT 0x8790
+#define GL_OP_EXP_BASE_2_EXT 0x8791
+#define GL_OP_LOG_BASE_2_EXT 0x8792
+#define GL_OP_POWER_EXT 0x8793
+#define GL_OP_RECIP_EXT 0x8794
+#define GL_OP_RECIP_SQRT_EXT 0x8795
+#define GL_OP_SUB_EXT 0x8796
+#define GL_OP_CROSS_PRODUCT_EXT 0x8797
+#define GL_OP_MULTIPLY_MATRIX_EXT 0x8798
+#define GL_OP_MOV_EXT 0x8799
+#define GL_OUTPUT_VERTEX_EXT 0x879A
+#define GL_OUTPUT_COLOR0_EXT 0x879B
+#define GL_OUTPUT_COLOR1_EXT 0x879C
+#define GL_OUTPUT_TEXTURE_COORD0_EXT 0x879D
+#define GL_OUTPUT_TEXTURE_COORD1_EXT 0x879E
+#define GL_OUTPUT_TEXTURE_COORD2_EXT 0x879F
+#define GL_OUTPUT_TEXTURE_COORD3_EXT 0x87A0
+#define GL_OUTPUT_TEXTURE_COORD4_EXT 0x87A1
+#define GL_OUTPUT_TEXTURE_COORD5_EXT 0x87A2
+#define GL_OUTPUT_TEXTURE_COORD6_EXT 0x87A3
+#define GL_OUTPUT_TEXTURE_COORD7_EXT 0x87A4
+#define GL_OUTPUT_TEXTURE_COORD8_EXT 0x87A5
+#define GL_OUTPUT_TEXTURE_COORD9_EXT 0x87A6
+#define GL_OUTPUT_TEXTURE_COORD10_EXT 0x87A7
+#define GL_OUTPUT_TEXTURE_COORD11_EXT 0x87A8
+#define GL_OUTPUT_TEXTURE_COORD12_EXT 0x87A9
+#define GL_OUTPUT_TEXTURE_COORD13_EXT 0x87AA
+#define GL_OUTPUT_TEXTURE_COORD14_EXT 0x87AB
+#define GL_OUTPUT_TEXTURE_COORD15_EXT 0x87AC
+#define GL_OUTPUT_TEXTURE_COORD16_EXT 0x87AD
+#define GL_OUTPUT_TEXTURE_COORD17_EXT 0x87AE
+#define GL_OUTPUT_TEXTURE_COORD18_EXT 0x87AF
+#define GL_OUTPUT_TEXTURE_COORD19_EXT 0x87B0
+#define GL_OUTPUT_TEXTURE_COORD20_EXT 0x87B1
+#define GL_OUTPUT_TEXTURE_COORD21_EXT 0x87B2
+#define GL_OUTPUT_TEXTURE_COORD22_EXT 0x87B3
+#define GL_OUTPUT_TEXTURE_COORD23_EXT 0x87B4
+#define GL_OUTPUT_TEXTURE_COORD24_EXT 0x87B5
+#define GL_OUTPUT_TEXTURE_COORD25_EXT 0x87B6
+#define GL_OUTPUT_TEXTURE_COORD26_EXT 0x87B7
+#define GL_OUTPUT_TEXTURE_COORD27_EXT 0x87B8
+#define GL_OUTPUT_TEXTURE_COORD28_EXT 0x87B9
+#define GL_OUTPUT_TEXTURE_COORD29_EXT 0x87BA
+#define GL_OUTPUT_TEXTURE_COORD30_EXT 0x87BB
+#define GL_OUTPUT_TEXTURE_COORD31_EXT 0x87BC
+#define GL_OUTPUT_FOG_EXT 0x87BD
+#define GL_SCALAR_EXT 0x87BE
+#define GL_VECTOR_EXT 0x87BF
+#define GL_MATRIX_EXT 0x87C0
+#define GL_VARIANT_EXT 0x87C1
+#define GL_INVARIANT_EXT 0x87C2
+#define GL_LOCAL_CONSTANT_EXT 0x87C3
+#define GL_LOCAL_EXT 0x87C4
+#define GL_MAX_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87C5
+#define GL_MAX_VERTEX_SHADER_VARIANTS_EXT 0x87C6
+#define GL_MAX_VERTEX_SHADER_INVARIANTS_EXT 0x87C7
+#define GL_MAX_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87C8
+#define GL_MAX_VERTEX_SHADER_LOCALS_EXT 0x87C9
+#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CA
+#define GL_MAX_OPTIMIZED_VERTEX_SHADER_VARIANTS_EXT 0x87CB
+#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87CC
+#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INVARIANTS_EXT 0x87CD
+#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCALS_EXT 0x87CE
+#define GL_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CF
+#define GL_VERTEX_SHADER_VARIANTS_EXT 0x87D0
+#define GL_VERTEX_SHADER_INVARIANTS_EXT 0x87D1
+#define GL_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87D2
+#define GL_VERTEX_SHADER_LOCALS_EXT 0x87D3
+#define GL_VERTEX_SHADER_OPTIMIZED_EXT 0x87D4
+#define GL_X_EXT 0x87D5
+#define GL_Y_EXT 0x87D6
+#define GL_Z_EXT 0x87D7
+#define GL_W_EXT 0x87D8
+#define GL_NEGATIVE_X_EXT 0x87D9
+#define GL_NEGATIVE_Y_EXT 0x87DA
+#define GL_NEGATIVE_Z_EXT 0x87DB
+#define GL_NEGATIVE_W_EXT 0x87DC
+#define GL_ZERO_EXT 0x87DD
+#define GL_ONE_EXT 0x87DE
+#define GL_NEGATIVE_ONE_EXT 0x87DF
+#define GL_NORMALIZED_RANGE_EXT 0x87E0
+#define GL_FULL_RANGE_EXT 0x87E1
+#define GL_CURRENT_VERTEX_EXT 0x87E2
+#define GL_MVP_MATRIX_EXT 0x87E3
+#define GL_VARIANT_VALUE_EXT 0x87E4
+#define GL_VARIANT_DATATYPE_EXT 0x87E5
+#define GL_VARIANT_ARRAY_STRIDE_EXT 0x87E6
+#define GL_VARIANT_ARRAY_TYPE_EXT 0x87E7
+#define GL_VARIANT_ARRAY_EXT 0x87E8
+#define GL_VARIANT_ARRAY_POINTER_EXT 0x87E9
+#define GL_INVARIANT_VALUE_EXT 0x87EA
+#define GL_INVARIANT_DATATYPE_EXT 0x87EB
+#define GL_LOCAL_CONSTANT_VALUE_EXT 0x87EC
+#define GL_LOCAL_CONSTANT_DATATYPE_EXT 0x87ED
+typedef void (APIENTRYP PFNGLBEGINVERTEXSHADEREXTPROC) (void);
+typedef void (APIENTRYP PFNGLENDVERTEXSHADEREXTPROC) (void);
+typedef void (APIENTRYP PFNGLBINDVERTEXSHADEREXTPROC) (GLuint id);
+typedef GLuint (APIENTRYP PFNGLGENVERTEXSHADERSEXTPROC) (GLuint range);
+typedef void (APIENTRYP PFNGLDELETEVERTEXSHADEREXTPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLSHADEROP1EXTPROC) (GLenum op, GLuint res, GLuint arg1);
+typedef void (APIENTRYP PFNGLSHADEROP2EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2);
+typedef void (APIENTRYP PFNGLSHADEROP3EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2, GLuint arg3);
+typedef void (APIENTRYP PFNGLSWIZZLEEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW);
+typedef void (APIENTRYP PFNGLWRITEMASKEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW);
+typedef void (APIENTRYP PFNGLINSERTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num);
+typedef void (APIENTRYP PFNGLEXTRACTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num);
+typedef GLuint (APIENTRYP PFNGLGENSYMBOLSEXTPROC) (GLenum datatype, GLenum storagetype, GLenum range, GLuint components);
+typedef void (APIENTRYP PFNGLSETINVARIANTEXTPROC) (GLuint id, GLenum type, const void *addr);
+typedef void (APIENTRYP PFNGLSETLOCALCONSTANTEXTPROC) (GLuint id, GLenum type, const void *addr);
+typedef void (APIENTRYP PFNGLVARIANTBVEXTPROC) (GLuint id, const GLbyte *addr);
+typedef void (APIENTRYP PFNGLVARIANTSVEXTPROC) (GLuint id, const GLshort *addr);
+typedef void (APIENTRYP PFNGLVARIANTIVEXTPROC) (GLuint id, const GLint *addr);
+typedef void (APIENTRYP PFNGLVARIANTFVEXTPROC) (GLuint id, const GLfloat *addr);
+typedef void (APIENTRYP PFNGLVARIANTDVEXTPROC) (GLuint id, const GLdouble *addr);
+typedef void (APIENTRYP PFNGLVARIANTUBVEXTPROC) (GLuint id, const GLubyte *addr);
+typedef void (APIENTRYP PFNGLVARIANTUSVEXTPROC) (GLuint id, const GLushort *addr);
+typedef void (APIENTRYP PFNGLVARIANTUIVEXTPROC) (GLuint id, const GLuint *addr);
+typedef void (APIENTRYP PFNGLVARIANTPOINTEREXTPROC) (GLuint id, GLenum type, GLuint stride, const void *addr);
+typedef void (APIENTRYP PFNGLENABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLDISABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id);
+typedef GLuint (APIENTRYP PFNGLBINDLIGHTPARAMETEREXTPROC) (GLenum light, GLenum value);
+typedef GLuint (APIENTRYP PFNGLBINDMATERIALPARAMETEREXTPROC) (GLenum face, GLenum value);
+typedef GLuint (APIENTRYP PFNGLBINDTEXGENPARAMETEREXTPROC) (GLenum unit, GLenum coord, GLenum value);
+typedef GLuint (APIENTRYP PFNGLBINDTEXTUREUNITPARAMETEREXTPROC) (GLenum unit, GLenum value);
+typedef GLuint (APIENTRYP PFNGLBINDPARAMETEREXTPROC) (GLenum value);
+typedef GLboolean (APIENTRYP PFNGLISVARIANTENABLEDEXTPROC) (GLuint id, GLenum cap);
+typedef void (APIENTRYP PFNGLGETVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data);
+typedef void (APIENTRYP PFNGLGETVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data);
+typedef void (APIENTRYP PFNGLGETVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data);
+typedef void (APIENTRYP PFNGLGETVARIANTPOINTERVEXTPROC) (GLuint id, GLenum value, void **data);
+typedef void (APIENTRYP PFNGLGETINVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data);
+typedef void (APIENTRYP PFNGLGETINVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data);
+typedef void (APIENTRYP PFNGLGETINVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data);
+typedef void (APIENTRYP PFNGLGETLOCALCONSTANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data);
+typedef void (APIENTRYP PFNGLGETLOCALCONSTANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data);
+typedef void (APIENTRYP PFNGLGETLOCALCONSTANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBeginVertexShaderEXT (void);
+GLAPI void APIENTRY glEndVertexShaderEXT (void);
+GLAPI void APIENTRY glBindVertexShaderEXT (GLuint id);
+GLAPI GLuint APIENTRY glGenVertexShadersEXT (GLuint range);
+GLAPI void APIENTRY glDeleteVertexShaderEXT (GLuint id);
+GLAPI void APIENTRY glShaderOp1EXT (GLenum op, GLuint res, GLuint arg1);
+GLAPI void APIENTRY glShaderOp2EXT (GLenum op, GLuint res, GLuint arg1, GLuint arg2);
+GLAPI void APIENTRY glShaderOp3EXT (GLenum op, GLuint res, GLuint arg1, GLuint arg2, GLuint arg3);
+GLAPI void APIENTRY glSwizzleEXT (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW);
+GLAPI void APIENTRY glWriteMaskEXT (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW);
+GLAPI void APIENTRY glInsertComponentEXT (GLuint res, GLuint src, GLuint num);
+GLAPI void APIENTRY glExtractComponentEXT (GLuint res, GLuint src, GLuint num);
+GLAPI GLuint APIENTRY glGenSymbolsEXT (GLenum datatype, GLenum storagetype, GLenum range, GLuint components);
+GLAPI void APIENTRY glSetInvariantEXT (GLuint id, GLenum type, const void *addr);
+GLAPI void APIENTRY glSetLocalConstantEXT (GLuint id, GLenum type, const void *addr);
+GLAPI void APIENTRY glVariantbvEXT (GLuint id, const GLbyte *addr);
+GLAPI void APIENTRY glVariantsvEXT (GLuint id, const GLshort *addr);
+GLAPI void APIENTRY glVariantivEXT (GLuint id, const GLint *addr);
+GLAPI void APIENTRY glVariantfvEXT (GLuint id, const GLfloat *addr);
+GLAPI void APIENTRY glVariantdvEXT (GLuint id, const GLdouble *addr);
+GLAPI void APIENTRY glVariantubvEXT (GLuint id, const GLubyte *addr);
+GLAPI void APIENTRY glVariantusvEXT (GLuint id, const GLushort *addr);
+GLAPI void APIENTRY glVariantuivEXT (GLuint id, const GLuint *addr);
+GLAPI void APIENTRY glVariantPointerEXT (GLuint id, GLenum type, GLuint stride, const void *addr);
+GLAPI void APIENTRY glEnableVariantClientStateEXT (GLuint id);
+GLAPI void APIENTRY glDisableVariantClientStateEXT (GLuint id);
+GLAPI GLuint APIENTRY glBindLightParameterEXT (GLenum light, GLenum value);
+GLAPI GLuint APIENTRY glBindMaterialParameterEXT (GLenum face, GLenum value);
+GLAPI GLuint APIENTRY glBindTexGenParameterEXT (GLenum unit, GLenum coord, GLenum value);
+GLAPI GLuint APIENTRY glBindTextureUnitParameterEXT (GLenum unit, GLenum value);
+GLAPI GLuint APIENTRY glBindParameterEXT (GLenum value);
+GLAPI GLboolean APIENTRY glIsVariantEnabledEXT (GLuint id, GLenum cap);
+GLAPI void APIENTRY glGetVariantBooleanvEXT (GLuint id, GLenum value, GLboolean *data);
+GLAPI void APIENTRY glGetVariantIntegervEXT (GLuint id, GLenum value, GLint *data);
+GLAPI void APIENTRY glGetVariantFloatvEXT (GLuint id, GLenum value, GLfloat *data);
+GLAPI void APIENTRY glGetVariantPointervEXT (GLuint id, GLenum value, void **data);
+GLAPI void APIENTRY glGetInvariantBooleanvEXT (GLuint id, GLenum value, GLboolean *data);
+GLAPI void APIENTRY glGetInvariantIntegervEXT (GLuint id, GLenum value, GLint *data);
+GLAPI void APIENTRY glGetInvariantFloatvEXT (GLuint id, GLenum value, GLfloat *data);
+GLAPI void APIENTRY glGetLocalConstantBooleanvEXT (GLuint id, GLenum value, GLboolean *data);
+GLAPI void APIENTRY glGetLocalConstantIntegervEXT (GLuint id, GLenum value, GLint *data);
+GLAPI void APIENTRY glGetLocalConstantFloatvEXT (GLuint id, GLenum value, GLfloat *data);
+#endif
+#endif /* GL_EXT_vertex_shader */
+
+#ifndef GL_EXT_vertex_weighting
+#define GL_EXT_vertex_weighting 1
+#define GL_MODELVIEW0_STACK_DEPTH_EXT 0x0BA3
+#define GL_MODELVIEW1_STACK_DEPTH_EXT 0x8502
+#define GL_MODELVIEW0_MATRIX_EXT 0x0BA6
+#define GL_MODELVIEW1_MATRIX_EXT 0x8506
+#define GL_VERTEX_WEIGHTING_EXT 0x8509
+#define GL_MODELVIEW0_EXT 0x1700
+#define GL_MODELVIEW1_EXT 0x850A
+#define GL_CURRENT_VERTEX_WEIGHT_EXT 0x850B
+#define GL_VERTEX_WEIGHT_ARRAY_EXT 0x850C
+#define GL_VERTEX_WEIGHT_ARRAY_SIZE_EXT 0x850D
+#define GL_VERTEX_WEIGHT_ARRAY_TYPE_EXT 0x850E
+#define GL_VERTEX_WEIGHT_ARRAY_STRIDE_EXT 0x850F
+#define GL_VERTEX_WEIGHT_ARRAY_POINTER_EXT 0x8510
+typedef void (APIENTRYP PFNGLVERTEXWEIGHTFEXTPROC) (GLfloat weight);
+typedef void (APIENTRYP PFNGLVERTEXWEIGHTFVEXTPROC) (const GLfloat *weight);
+typedef void (APIENTRYP PFNGLVERTEXWEIGHTPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, const void *pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexWeightfEXT (GLfloat weight);
+GLAPI void APIENTRY glVertexWeightfvEXT (const GLfloat *weight);
+GLAPI void APIENTRY glVertexWeightPointerEXT (GLint size, GLenum type, GLsizei stride, const void *pointer);
+#endif
+#endif /* GL_EXT_vertex_weighting */
+
+#ifndef GL_EXT_x11_sync_object
+#define GL_EXT_x11_sync_object 1
+#define GL_SYNC_X11_FENCE_EXT 0x90E1
+typedef GLsync (APIENTRYP PFNGLIMPORTSYNCEXTPROC) (GLenum external_sync_type, GLintptr external_sync, GLbitfield flags);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLsync APIENTRY glImportSyncEXT (GLenum external_sync_type, GLintptr external_sync, GLbitfield flags);
+#endif
+#endif /* GL_EXT_x11_sync_object */
+
+#ifndef GL_GREMEDY_frame_terminator
+#define GL_GREMEDY_frame_terminator 1
+typedef void (APIENTRYP PFNGLFRAMETERMINATORGREMEDYPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glFrameTerminatorGREMEDY (void);
+#endif
+#endif /* GL_GREMEDY_frame_terminator */
+
+#ifndef GL_GREMEDY_string_marker
+#define GL_GREMEDY_string_marker 1
+typedef void (APIENTRYP PFNGLSTRINGMARKERGREMEDYPROC) (GLsizei len, const void *string);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glStringMarkerGREMEDY (GLsizei len, const void *string);
+#endif
+#endif /* GL_GREMEDY_string_marker */
+
+#ifndef GL_HP_convolution_border_modes
+#define GL_HP_convolution_border_modes 1
+#define GL_IGNORE_BORDER_HP 0x8150
+#define GL_CONSTANT_BORDER_HP 0x8151
+#define GL_REPLICATE_BORDER_HP 0x8153
+#define GL_CONVOLUTION_BORDER_COLOR_HP 0x8154
+#endif /* GL_HP_convolution_border_modes */
+
+#ifndef GL_HP_image_transform
+#define GL_HP_image_transform 1
+#define GL_IMAGE_SCALE_X_HP 0x8155
+#define GL_IMAGE_SCALE_Y_HP 0x8156
+#define GL_IMAGE_TRANSLATE_X_HP 0x8157
+#define GL_IMAGE_TRANSLATE_Y_HP 0x8158
+#define GL_IMAGE_ROTATE_ANGLE_HP 0x8159
+#define GL_IMAGE_ROTATE_ORIGIN_X_HP 0x815A
+#define GL_IMAGE_ROTATE_ORIGIN_Y_HP 0x815B
+#define GL_IMAGE_MAG_FILTER_HP 0x815C
+#define GL_IMAGE_MIN_FILTER_HP 0x815D
+#define GL_IMAGE_CUBIC_WEIGHT_HP 0x815E
+#define GL_CUBIC_HP 0x815F
+#define GL_AVERAGE_HP 0x8160
+#define GL_IMAGE_TRANSFORM_2D_HP 0x8161
+#define GL_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP 0x8162
+#define GL_PROXY_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP 0x8163
+typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIHPPROC) (GLenum target, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFHPPROC) (GLenum target, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glImageTransformParameteriHP (GLenum target, GLenum pname, GLint param);
+GLAPI void APIENTRY glImageTransformParameterfHP (GLenum target, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glImageTransformParameterivHP (GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glImageTransformParameterfvHP (GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glGetImageTransformParameterivHP (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetImageTransformParameterfvHP (GLenum target, GLenum pname, GLfloat *params);
+#endif
+#endif /* GL_HP_image_transform */
+
+#ifndef GL_HP_occlusion_test
+#define GL_HP_occlusion_test 1
+#define GL_OCCLUSION_TEST_HP 0x8165
+#define GL_OCCLUSION_TEST_RESULT_HP 0x8166
+#endif /* GL_HP_occlusion_test */
+
+#ifndef GL_HP_texture_lighting
+#define GL_HP_texture_lighting 1
+#define GL_TEXTURE_LIGHTING_MODE_HP 0x8167
+#define GL_TEXTURE_POST_SPECULAR_HP 0x8168
+#define GL_TEXTURE_PRE_SPECULAR_HP 0x8169
+#endif /* GL_HP_texture_lighting */
+
+#ifndef GL_IBM_cull_vertex
+#define GL_IBM_cull_vertex 1
+#define GL_CULL_VERTEX_IBM 103050
+#endif /* GL_IBM_cull_vertex */
+
+#ifndef GL_IBM_multimode_draw_arrays
+#define GL_IBM_multimode_draw_arrays 1
+typedef void (APIENTRYP PFNGLMULTIMODEDRAWARRAYSIBMPROC) (const GLenum *mode, const GLint *first, const GLsizei *count, GLsizei primcount, GLint modestride);
+typedef void (APIENTRYP PFNGLMULTIMODEDRAWELEMENTSIBMPROC) (const GLenum *mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei primcount, GLint modestride);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMultiModeDrawArraysIBM (const GLenum *mode, const GLint *first, const GLsizei *count, GLsizei primcount, GLint modestride);
+GLAPI void APIENTRY glMultiModeDrawElementsIBM (const GLenum *mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei primcount, GLint modestride);
+#endif
+#endif /* GL_IBM_multimode_draw_arrays */
+
+#ifndef GL_IBM_rasterpos_clip
+#define GL_IBM_rasterpos_clip 1
+#define GL_RASTER_POSITION_UNCLIPPED_IBM 0x19262
+#endif /* GL_IBM_rasterpos_clip */
+
+#ifndef GL_IBM_static_data
+#define GL_IBM_static_data 1
+#define GL_ALL_STATIC_DATA_IBM 103060
+#define GL_STATIC_VERTEX_ARRAY_IBM 103061
+typedef void (APIENTRYP PFNGLFLUSHSTATICDATAIBMPROC) (GLenum target);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glFlushStaticDataIBM (GLenum target);
+#endif
+#endif /* GL_IBM_static_data */
+
+#ifndef GL_IBM_texture_mirrored_repeat
+#define GL_IBM_texture_mirrored_repeat 1
+#define GL_MIRRORED_REPEAT_IBM 0x8370
+#endif /* GL_IBM_texture_mirrored_repeat */
+
+#ifndef GL_IBM_vertex_array_lists
+#define GL_IBM_vertex_array_lists 1
+#define GL_VERTEX_ARRAY_LIST_IBM 103070
+#define GL_NORMAL_ARRAY_LIST_IBM 103071
+#define GL_COLOR_ARRAY_LIST_IBM 103072
+#define GL_INDEX_ARRAY_LIST_IBM 103073
+#define GL_TEXTURE_COORD_ARRAY_LIST_IBM 103074
+#define GL_EDGE_FLAG_ARRAY_LIST_IBM 103075
+#define GL_FOG_COORDINATE_ARRAY_LIST_IBM 103076
+#define GL_SECONDARY_COLOR_ARRAY_LIST_IBM 103077
+#define GL_VERTEX_ARRAY_LIST_STRIDE_IBM 103080
+#define GL_NORMAL_ARRAY_LIST_STRIDE_IBM 103081
+#define GL_COLOR_ARRAY_LIST_STRIDE_IBM 103082
+#define GL_INDEX_ARRAY_LIST_STRIDE_IBM 103083
+#define GL_TEXTURE_COORD_ARRAY_LIST_STRIDE_IBM 103084
+#define GL_EDGE_FLAG_ARRAY_LIST_STRIDE_IBM 103085
+#define GL_FOG_COORDINATE_ARRAY_LIST_STRIDE_IBM 103086
+#define GL_SECONDARY_COLOR_ARRAY_LIST_STRIDE_IBM 103087
+typedef void (APIENTRYP PFNGLCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+typedef void (APIENTRYP PFNGLEDGEFLAGPOINTERLISTIBMPROC) (GLint stride, const GLboolean **pointer, GLint ptrstride);
+typedef void (APIENTRYP PFNGLFOGCOORDPOINTERLISTIBMPROC) (GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+typedef void (APIENTRYP PFNGLINDEXPOINTERLISTIBMPROC) (GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+typedef void (APIENTRYP PFNGLNORMALPOINTERLISTIBMPROC) (GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+typedef void (APIENTRYP PFNGLTEXCOORDPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+typedef void (APIENTRYP PFNGLVERTEXPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glColorPointerListIBM (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+GLAPI void APIENTRY glSecondaryColorPointerListIBM (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+GLAPI void APIENTRY glEdgeFlagPointerListIBM (GLint stride, const GLboolean **pointer, GLint ptrstride);
+GLAPI void APIENTRY glFogCoordPointerListIBM (GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+GLAPI void APIENTRY glIndexPointerListIBM (GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+GLAPI void APIENTRY glNormalPointerListIBM (GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+GLAPI void APIENTRY glTexCoordPointerListIBM (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+GLAPI void APIENTRY glVertexPointerListIBM (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+#endif
+#endif /* GL_IBM_vertex_array_lists */
+
+#ifndef GL_INGR_blend_func_separate
+#define GL_INGR_blend_func_separate 1
+typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINGRPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendFuncSeparateINGR (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
+#endif
+#endif /* GL_INGR_blend_func_separate */
+
+#ifndef GL_INGR_color_clamp
+#define GL_INGR_color_clamp 1
+#define GL_RED_MIN_CLAMP_INGR 0x8560
+#define GL_GREEN_MIN_CLAMP_INGR 0x8561
+#define GL_BLUE_MIN_CLAMP_INGR 0x8562
+#define GL_ALPHA_MIN_CLAMP_INGR 0x8563
+#define GL_RED_MAX_CLAMP_INGR 0x8564
+#define GL_GREEN_MAX_CLAMP_INGR 0x8565
+#define GL_BLUE_MAX_CLAMP_INGR 0x8566
+#define GL_ALPHA_MAX_CLAMP_INGR 0x8567
+#endif /* GL_INGR_color_clamp */
+
+#ifndef GL_INGR_interlace_read
+#define GL_INGR_interlace_read 1
+#define GL_INTERLACE_READ_INGR 0x8568
+#endif /* GL_INGR_interlace_read */
+
+#ifndef GL_INTEL_fragment_shader_ordering
+#define GL_INTEL_fragment_shader_ordering 1
+#endif /* GL_INTEL_fragment_shader_ordering */
+
+#ifndef GL_INTEL_map_texture
+#define GL_INTEL_map_texture 1
+#define GL_TEXTURE_MEMORY_LAYOUT_INTEL 0x83FF
+#define GL_LAYOUT_DEFAULT_INTEL 0
+#define GL_LAYOUT_LINEAR_INTEL 1
+#define GL_LAYOUT_LINEAR_CPU_CACHED_INTEL 2
+typedef void (APIENTRYP PFNGLSYNCTEXTUREINTELPROC) (GLuint texture);
+typedef void (APIENTRYP PFNGLUNMAPTEXTURE2DINTELPROC) (GLuint texture, GLint level);
+typedef void *(APIENTRYP PFNGLMAPTEXTURE2DINTELPROC) (GLuint texture, GLint level, GLbitfield access, GLint *stride, GLenum *layout);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glSyncTextureINTEL (GLuint texture);
+GLAPI void APIENTRY glUnmapTexture2DINTEL (GLuint texture, GLint level);
+GLAPI void *APIENTRY glMapTexture2DINTEL (GLuint texture, GLint level, GLbitfield access, GLint *stride, GLenum *layout);
+#endif
+#endif /* GL_INTEL_map_texture */
+
+#ifndef GL_INTEL_parallel_arrays
+#define GL_INTEL_parallel_arrays 1
+#define GL_PARALLEL_ARRAYS_INTEL 0x83F4
+#define GL_VERTEX_ARRAY_PARALLEL_POINTERS_INTEL 0x83F5
+#define GL_NORMAL_ARRAY_PARALLEL_POINTERS_INTEL 0x83F6
+#define GL_COLOR_ARRAY_PARALLEL_POINTERS_INTEL 0x83F7
+#define GL_TEXTURE_COORD_ARRAY_PARALLEL_POINTERS_INTEL 0x83F8
+typedef void (APIENTRYP PFNGLVERTEXPOINTERVINTELPROC) (GLint size, GLenum type, const void **pointer);
+typedef void (APIENTRYP PFNGLNORMALPOINTERVINTELPROC) (GLenum type, const void **pointer);
+typedef void (APIENTRYP PFNGLCOLORPOINTERVINTELPROC) (GLint size, GLenum type, const void **pointer);
+typedef void (APIENTRYP PFNGLTEXCOORDPOINTERVINTELPROC) (GLint size, GLenum type, const void **pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexPointervINTEL (GLint size, GLenum type, const void **pointer);
+GLAPI void APIENTRY glNormalPointervINTEL (GLenum type, const void **pointer);
+GLAPI void APIENTRY glColorPointervINTEL (GLint size, GLenum type, const void **pointer);
+GLAPI void APIENTRY glTexCoordPointervINTEL (GLint size, GLenum type, const void **pointer);
+#endif
+#endif /* GL_INTEL_parallel_arrays */
+
+#ifndef GL_INTEL_performance_query
+#define GL_INTEL_performance_query 1
+#define GL_PERFQUERY_SINGLE_CONTEXT_INTEL 0x00000000
+#define GL_PERFQUERY_GLOBAL_CONTEXT_INTEL 0x00000001
+#define GL_PERFQUERY_WAIT_INTEL 0x83FB
+#define GL_PERFQUERY_FLUSH_INTEL 0x83FA
+#define GL_PERFQUERY_DONOT_FLUSH_INTEL 0x83F9
+#define GL_PERFQUERY_COUNTER_EVENT_INTEL 0x94F0
+#define GL_PERFQUERY_COUNTER_DURATION_NORM_INTEL 0x94F1
+#define GL_PERFQUERY_COUNTER_DURATION_RAW_INTEL 0x94F2
+#define GL_PERFQUERY_COUNTER_THROUGHPUT_INTEL 0x94F3
+#define GL_PERFQUERY_COUNTER_RAW_INTEL 0x94F4
+#define GL_PERFQUERY_COUNTER_TIMESTAMP_INTEL 0x94F5
+#define GL_PERFQUERY_COUNTER_DATA_UINT32_INTEL 0x94F8
+#define GL_PERFQUERY_COUNTER_DATA_UINT64_INTEL 0x94F9
+#define GL_PERFQUERY_COUNTER_DATA_FLOAT_INTEL 0x94FA
+#define GL_PERFQUERY_COUNTER_DATA_DOUBLE_INTEL 0x94FB
+#define GL_PERFQUERY_COUNTER_DATA_BOOL32_INTEL 0x94FC
+#define GL_PERFQUERY_QUERY_NAME_LENGTH_MAX_INTEL 0x94FD
+#define GL_PERFQUERY_COUNTER_NAME_LENGTH_MAX_INTEL 0x94FE
+#define GL_PERFQUERY_COUNTER_DESC_LENGTH_MAX_INTEL 0x94FF
+#define GL_PERFQUERY_GPA_EXTENDED_COUNTERS_INTEL 0x9500
+typedef void (APIENTRYP PFNGLBEGINPERFQUERYINTELPROC) (GLuint queryHandle);
+typedef void (APIENTRYP PFNGLCREATEPERFQUERYINTELPROC) (GLuint queryId, GLuint *queryHandle);
+typedef void (APIENTRYP PFNGLDELETEPERFQUERYINTELPROC) (GLuint queryHandle);
+typedef void (APIENTRYP PFNGLENDPERFQUERYINTELPROC) (GLuint queryHandle);
+typedef void (APIENTRYP PFNGLGETFIRSTPERFQUERYIDINTELPROC) (GLuint *queryId);
+typedef void (APIENTRYP PFNGLGETNEXTPERFQUERYIDINTELPROC) (GLuint queryId, GLuint *nextQueryId);
+typedef void (APIENTRYP PFNGLGETPERFCOUNTERINFOINTELPROC) (GLuint queryId, GLuint counterId, GLuint counterNameLength, GLchar *counterName, GLuint counterDescLength, GLchar *counterDesc, GLuint *counterOffset, GLuint *counterDataSize, GLuint *counterTypeEnum, GLuint *counterDataTypeEnum, GLuint64 *rawCounterMaxValue);
+typedef void (APIENTRYP PFNGLGETPERFQUERYDATAINTELPROC) (GLuint queryHandle, GLuint flags, GLsizei dataSize, GLvoid *data, GLuint *bytesWritten);
+typedef void (APIENTRYP PFNGLGETPERFQUERYIDBYNAMEINTELPROC) (GLchar *queryName, GLuint *queryId);
+typedef void (APIENTRYP PFNGLGETPERFQUERYINFOINTELPROC) (GLuint queryId, GLuint queryNameLength, GLchar *queryName, GLuint *dataSize, GLuint *noCounters, GLuint *noInstances, GLuint *capsMask);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBeginPerfQueryINTEL (GLuint queryHandle);
+GLAPI void APIENTRY glCreatePerfQueryINTEL (GLuint queryId, GLuint *queryHandle);
+GLAPI void APIENTRY glDeletePerfQueryINTEL (GLuint queryHandle);
+GLAPI void APIENTRY glEndPerfQueryINTEL (GLuint queryHandle);
+GLAPI void APIENTRY glGetFirstPerfQueryIdINTEL (GLuint *queryId);
+GLAPI void APIENTRY glGetNextPerfQueryIdINTEL (GLuint queryId, GLuint *nextQueryId);
+GLAPI void APIENTRY glGetPerfCounterInfoINTEL (GLuint queryId, GLuint counterId, GLuint counterNameLength, GLchar *counterName, GLuint counterDescLength, GLchar *counterDesc, GLuint *counterOffset, GLuint *counterDataSize, GLuint *counterTypeEnum, GLuint *counterDataTypeEnum, GLuint64 *rawCounterMaxValue);
+GLAPI void APIENTRY glGetPerfQueryDataINTEL (GLuint queryHandle, GLuint flags, GLsizei dataSize, GLvoid *data, GLuint *bytesWritten);
+GLAPI void APIENTRY glGetPerfQueryIdByNameINTEL (GLchar *queryName, GLuint *queryId);
+GLAPI void APIENTRY glGetPerfQueryInfoINTEL (GLuint queryId, GLuint queryNameLength, GLchar *queryName, GLuint *dataSize, GLuint *noCounters, GLuint *noInstances, GLuint *capsMask);
+#endif
+#endif /* GL_INTEL_performance_query */
+
+#ifndef GL_MESAX_texture_stack
+#define GL_MESAX_texture_stack 1
+#define GL_TEXTURE_1D_STACK_MESAX 0x8759
+#define GL_TEXTURE_2D_STACK_MESAX 0x875A
+#define GL_PROXY_TEXTURE_1D_STACK_MESAX 0x875B
+#define GL_PROXY_TEXTURE_2D_STACK_MESAX 0x875C
+#define GL_TEXTURE_1D_STACK_BINDING_MESAX 0x875D
+#define GL_TEXTURE_2D_STACK_BINDING_MESAX 0x875E
+#endif /* GL_MESAX_texture_stack */
+
+#ifndef GL_MESA_pack_invert
+#define GL_MESA_pack_invert 1
+#define GL_PACK_INVERT_MESA 0x8758
+#endif /* GL_MESA_pack_invert */
+
+#ifndef GL_MESA_resize_buffers
+#define GL_MESA_resize_buffers 1
+typedef void (APIENTRYP PFNGLRESIZEBUFFERSMESAPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glResizeBuffersMESA (void);
+#endif
+#endif /* GL_MESA_resize_buffers */
+
+#ifndef GL_MESA_window_pos
+#define GL_MESA_window_pos 1
+typedef void (APIENTRYP PFNGLWINDOWPOS2DMESAPROC) (GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2DVMESAPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS2FMESAPROC) (GLfloat x, GLfloat y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2FVMESAPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS2IMESAPROC) (GLint x, GLint y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2IVMESAPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS2SMESAPROC) (GLshort x, GLshort y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2SVMESAPROC) (const GLshort *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3DMESAPROC) (GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3DVMESAPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3FMESAPROC) (GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3FVMESAPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3IMESAPROC) (GLint x, GLint y, GLint z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3IVMESAPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3SMESAPROC) (GLshort x, GLshort y, GLshort z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3SVMESAPROC) (const GLshort *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS4DMESAPROC) (GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLWINDOWPOS4DVMESAPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS4FMESAPROC) (GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLWINDOWPOS4FVMESAPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS4IMESAPROC) (GLint x, GLint y, GLint z, GLint w);
+typedef void (APIENTRYP PFNGLWINDOWPOS4IVMESAPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS4SMESAPROC) (GLshort x, GLshort y, GLshort z, GLshort w);
+typedef void (APIENTRYP PFNGLWINDOWPOS4SVMESAPROC) (const GLshort *v);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glWindowPos2dMESA (GLdouble x, GLdouble y);
+GLAPI void APIENTRY glWindowPos2dvMESA (const GLdouble *v);
+GLAPI void APIENTRY glWindowPos2fMESA (GLfloat x, GLfloat y);
+GLAPI void APIENTRY glWindowPos2fvMESA (const GLfloat *v);
+GLAPI void APIENTRY glWindowPos2iMESA (GLint x, GLint y);
+GLAPI void APIENTRY glWindowPos2ivMESA (const GLint *v);
+GLAPI void APIENTRY glWindowPos2sMESA (GLshort x, GLshort y);
+GLAPI void APIENTRY glWindowPos2svMESA (const GLshort *v);
+GLAPI void APIENTRY glWindowPos3dMESA (GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glWindowPos3dvMESA (const GLdouble *v);
+GLAPI void APIENTRY glWindowPos3fMESA (GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glWindowPos3fvMESA (const GLfloat *v);
+GLAPI void APIENTRY glWindowPos3iMESA (GLint x, GLint y, GLint z);
+GLAPI void APIENTRY glWindowPos3ivMESA (const GLint *v);
+GLAPI void APIENTRY glWindowPos3sMESA (GLshort x, GLshort y, GLshort z);
+GLAPI void APIENTRY glWindowPos3svMESA (const GLshort *v);
+GLAPI void APIENTRY glWindowPos4dMESA (GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glWindowPos4dvMESA (const GLdouble *v);
+GLAPI void APIENTRY glWindowPos4fMESA (GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glWindowPos4fvMESA (const GLfloat *v);
+GLAPI void APIENTRY glWindowPos4iMESA (GLint x, GLint y, GLint z, GLint w);
+GLAPI void APIENTRY glWindowPos4ivMESA (const GLint *v);
+GLAPI void APIENTRY glWindowPos4sMESA (GLshort x, GLshort y, GLshort z, GLshort w);
+GLAPI void APIENTRY glWindowPos4svMESA (const GLshort *v);
+#endif
+#endif /* GL_MESA_window_pos */
+
+#ifndef GL_MESA_ycbcr_texture
+#define GL_MESA_ycbcr_texture 1
+#define GL_UNSIGNED_SHORT_8_8_MESA 0x85BA
+#define GL_UNSIGNED_SHORT_8_8_REV_MESA 0x85BB
+#define GL_YCBCR_MESA 0x8757
+#endif /* GL_MESA_ycbcr_texture */
+
+#ifndef GL_NVX_conditional_render
+#define GL_NVX_conditional_render 1
+typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERNVXPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERNVXPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBeginConditionalRenderNVX (GLuint id);
+GLAPI void APIENTRY glEndConditionalRenderNVX (void);
+#endif
+#endif /* GL_NVX_conditional_render */
+
+#ifndef GL_NVX_gpu_memory_info
+#define GL_NVX_gpu_memory_info 1
+#define GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX 0x9047
+#define GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX 0x9048
+#define GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049
+#define GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX 0x904A
+#define GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX 0x904B
+#endif /* GL_NVX_gpu_memory_info */
+
+#ifndef GL_NV_bindless_multi_draw_indirect
+#define GL_NV_bindless_multi_draw_indirect 1
+typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTBINDLESSNVPROC) (GLenum mode, const void *indirect, GLsizei drawCount, GLsizei stride, GLint vertexBufferCount);
+typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTBINDLESSNVPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei drawCount, GLsizei stride, GLint vertexBufferCount);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMultiDrawArraysIndirectBindlessNV (GLenum mode, const void *indirect, GLsizei drawCount, GLsizei stride, GLint vertexBufferCount);
+GLAPI void APIENTRY glMultiDrawElementsIndirectBindlessNV (GLenum mode, GLenum type, const void *indirect, GLsizei drawCount, GLsizei stride, GLint vertexBufferCount);
+#endif
+#endif /* GL_NV_bindless_multi_draw_indirect */
+
+#ifndef GL_NV_bindless_texture
+#define GL_NV_bindless_texture 1
+typedef GLuint64 (APIENTRYP PFNGLGETTEXTUREHANDLENVPROC) (GLuint texture);
+typedef GLuint64 (APIENTRYP PFNGLGETTEXTURESAMPLERHANDLENVPROC) (GLuint texture, GLuint sampler);
+typedef void (APIENTRYP PFNGLMAKETEXTUREHANDLERESIDENTNVPROC) (GLuint64 handle);
+typedef void (APIENTRYP PFNGLMAKETEXTUREHANDLENONRESIDENTNVPROC) (GLuint64 handle);
+typedef GLuint64 (APIENTRYP PFNGLGETIMAGEHANDLENVPROC) (GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format);
+typedef void (APIENTRYP PFNGLMAKEIMAGEHANDLERESIDENTNVPROC) (GLuint64 handle, GLenum access);
+typedef void (APIENTRYP PFNGLMAKEIMAGEHANDLENONRESIDENTNVPROC) (GLuint64 handle);
+typedef void (APIENTRYP PFNGLUNIFORMHANDLEUI64NVPROC) (GLint location, GLuint64 value);
+typedef void (APIENTRYP PFNGLUNIFORMHANDLEUI64VNVPROC) (GLint location, GLsizei count, const GLuint64 *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64NVPROC) (GLuint program, GLint location, GLuint64 value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64 *values);
+typedef GLboolean (APIENTRYP PFNGLISTEXTUREHANDLERESIDENTNVPROC) (GLuint64 handle);
+typedef GLboolean (APIENTRYP PFNGLISIMAGEHANDLERESIDENTNVPROC) (GLuint64 handle);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLuint64 APIENTRY glGetTextureHandleNV (GLuint texture);
+GLAPI GLuint64 APIENTRY glGetTextureSamplerHandleNV (GLuint texture, GLuint sampler);
+GLAPI void APIENTRY glMakeTextureHandleResidentNV (GLuint64 handle);
+GLAPI void APIENTRY glMakeTextureHandleNonResidentNV (GLuint64 handle);
+GLAPI GLuint64 APIENTRY glGetImageHandleNV (GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format);
+GLAPI void APIENTRY glMakeImageHandleResidentNV (GLuint64 handle, GLenum access);
+GLAPI void APIENTRY glMakeImageHandleNonResidentNV (GLuint64 handle);
+GLAPI void APIENTRY glUniformHandleui64NV (GLint location, GLuint64 value);
+GLAPI void APIENTRY glUniformHandleui64vNV (GLint location, GLsizei count, const GLuint64 *value);
+GLAPI void APIENTRY glProgramUniformHandleui64NV (GLuint program, GLint location, GLuint64 value);
+GLAPI void APIENTRY glProgramUniformHandleui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64 *values);
+GLAPI GLboolean APIENTRY glIsTextureHandleResidentNV (GLuint64 handle);
+GLAPI GLboolean APIENTRY glIsImageHandleResidentNV (GLuint64 handle);
+#endif
+#endif /* GL_NV_bindless_texture */
+
+#ifndef GL_NV_blend_equation_advanced
+#define GL_NV_blend_equation_advanced 1
+#define GL_BLEND_OVERLAP_NV 0x9281
+#define GL_BLEND_PREMULTIPLIED_SRC_NV 0x9280
+#define GL_BLUE_NV 0x1905
+#define GL_COLORBURN_NV 0x929A
+#define GL_COLORDODGE_NV 0x9299
+#define GL_CONJOINT_NV 0x9284
+#define GL_CONTRAST_NV 0x92A1
+#define GL_DARKEN_NV 0x9297
+#define GL_DIFFERENCE_NV 0x929E
+#define GL_DISJOINT_NV 0x9283
+#define GL_DST_ATOP_NV 0x928F
+#define GL_DST_IN_NV 0x928B
+#define GL_DST_NV 0x9287
+#define GL_DST_OUT_NV 0x928D
+#define GL_DST_OVER_NV 0x9289
+#define GL_EXCLUSION_NV 0x92A0
+#define GL_GREEN_NV 0x1904
+#define GL_HARDLIGHT_NV 0x929B
+#define GL_HARDMIX_NV 0x92A9
+#define GL_HSL_COLOR_NV 0x92AF
+#define GL_HSL_HUE_NV 0x92AD
+#define GL_HSL_LUMINOSITY_NV 0x92B0
+#define GL_HSL_SATURATION_NV 0x92AE
+#define GL_INVERT_OVG_NV 0x92B4
+#define GL_INVERT_RGB_NV 0x92A3
+#define GL_LIGHTEN_NV 0x9298
+#define GL_LINEARBURN_NV 0x92A5
+#define GL_LINEARDODGE_NV 0x92A4
+#define GL_LINEARLIGHT_NV 0x92A7
+#define GL_MINUS_CLAMPED_NV 0x92B3
+#define GL_MINUS_NV 0x929F
+#define GL_MULTIPLY_NV 0x9294
+#define GL_OVERLAY_NV 0x9296
+#define GL_PINLIGHT_NV 0x92A8
+#define GL_PLUS_CLAMPED_ALPHA_NV 0x92B2
+#define GL_PLUS_CLAMPED_NV 0x92B1
+#define GL_PLUS_DARKER_NV 0x9292
+#define GL_PLUS_NV 0x9291
+#define GL_RED_NV 0x1903
+#define GL_SCREEN_NV 0x9295
+#define GL_SOFTLIGHT_NV 0x929C
+#define GL_SRC_ATOP_NV 0x928E
+#define GL_SRC_IN_NV 0x928A
+#define GL_SRC_NV 0x9286
+#define GL_SRC_OUT_NV 0x928C
+#define GL_SRC_OVER_NV 0x9288
+#define GL_UNCORRELATED_NV 0x9282
+#define GL_VIVIDLIGHT_NV 0x92A6
+#define GL_XOR_NV 0x1506
+typedef void (APIENTRYP PFNGLBLENDPARAMETERINVPROC) (GLenum pname, GLint value);
+typedef void (APIENTRYP PFNGLBLENDBARRIERNVPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendParameteriNV (GLenum pname, GLint value);
+GLAPI void APIENTRY glBlendBarrierNV (void);
+#endif
+#endif /* GL_NV_blend_equation_advanced */
+
+#ifndef GL_NV_blend_equation_advanced_coherent
+#define GL_NV_blend_equation_advanced_coherent 1
+#define GL_BLEND_ADVANCED_COHERENT_NV 0x9285
+#endif /* GL_NV_blend_equation_advanced_coherent */
+
+#ifndef GL_NV_blend_square
+#define GL_NV_blend_square 1
+#endif /* GL_NV_blend_square */
+
+#ifndef GL_NV_compute_program5
+#define GL_NV_compute_program5 1
+#define GL_COMPUTE_PROGRAM_NV 0x90FB
+#define GL_COMPUTE_PROGRAM_PARAMETER_BUFFER_NV 0x90FC
+#endif /* GL_NV_compute_program5 */
+
+#ifndef GL_NV_conditional_render
+#define GL_NV_conditional_render 1
+#define GL_QUERY_WAIT_NV 0x8E13
+#define GL_QUERY_NO_WAIT_NV 0x8E14
+#define GL_QUERY_BY_REGION_WAIT_NV 0x8E15
+#define GL_QUERY_BY_REGION_NO_WAIT_NV 0x8E16
+typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERNVPROC) (GLuint id, GLenum mode);
+typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERNVPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBeginConditionalRenderNV (GLuint id, GLenum mode);
+GLAPI void APIENTRY glEndConditionalRenderNV (void);
+#endif
+#endif /* GL_NV_conditional_render */
+
+#ifndef GL_NV_copy_depth_to_color
+#define GL_NV_copy_depth_to_color 1
+#define GL_DEPTH_STENCIL_TO_RGBA_NV 0x886E
+#define GL_DEPTH_STENCIL_TO_BGRA_NV 0x886F
+#endif /* GL_NV_copy_depth_to_color */
+
+#ifndef GL_NV_copy_image
+#define GL_NV_copy_image 1
+typedef void (APIENTRYP PFNGLCOPYIMAGESUBDATANVPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glCopyImageSubDataNV (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth);
+#endif
+#endif /* GL_NV_copy_image */
+
+#ifndef GL_NV_deep_texture3D
+#define GL_NV_deep_texture3D 1
+#define GL_MAX_DEEP_3D_TEXTURE_WIDTH_HEIGHT_NV 0x90D0
+#define GL_MAX_DEEP_3D_TEXTURE_DEPTH_NV 0x90D1
+#endif /* GL_NV_deep_texture3D */
+
+#ifndef GL_NV_depth_buffer_float
+#define GL_NV_depth_buffer_float 1
+#define GL_DEPTH_COMPONENT32F_NV 0x8DAB
+#define GL_DEPTH32F_STENCIL8_NV 0x8DAC
+#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV_NV 0x8DAD
+#define GL_DEPTH_BUFFER_FLOAT_MODE_NV 0x8DAF
+typedef void (APIENTRYP PFNGLDEPTHRANGEDNVPROC) (GLdouble zNear, GLdouble zFar);
+typedef void (APIENTRYP PFNGLCLEARDEPTHDNVPROC) (GLdouble depth);
+typedef void (APIENTRYP PFNGLDEPTHBOUNDSDNVPROC) (GLdouble zmin, GLdouble zmax);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDepthRangedNV (GLdouble zNear, GLdouble zFar);
+GLAPI void APIENTRY glClearDepthdNV (GLdouble depth);
+GLAPI void APIENTRY glDepthBoundsdNV (GLdouble zmin, GLdouble zmax);
+#endif
+#endif /* GL_NV_depth_buffer_float */
+
+#ifndef GL_NV_depth_clamp
+#define GL_NV_depth_clamp 1
+#define GL_DEPTH_CLAMP_NV 0x864F
+#endif /* GL_NV_depth_clamp */
+
+#ifndef GL_NV_draw_texture
+#define GL_NV_draw_texture 1
+typedef void (APIENTRYP PFNGLDRAWTEXTURENVPROC) (GLuint texture, GLuint sampler, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1, GLfloat z, GLfloat s0, GLfloat t0, GLfloat s1, GLfloat t1);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawTextureNV (GLuint texture, GLuint sampler, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1, GLfloat z, GLfloat s0, GLfloat t0, GLfloat s1, GLfloat t1);
+#endif
+#endif /* GL_NV_draw_texture */
+
+#ifndef GL_NV_evaluators
+#define GL_NV_evaluators 1
+#define GL_EVAL_2D_NV 0x86C0
+#define GL_EVAL_TRIANGULAR_2D_NV 0x86C1
+#define GL_MAP_TESSELLATION_NV 0x86C2
+#define GL_MAP_ATTRIB_U_ORDER_NV 0x86C3
+#define GL_MAP_ATTRIB_V_ORDER_NV 0x86C4
+#define GL_EVAL_FRACTIONAL_TESSELLATION_NV 0x86C5
+#define GL_EVAL_VERTEX_ATTRIB0_NV 0x86C6
+#define GL_EVAL_VERTEX_ATTRIB1_NV 0x86C7
+#define GL_EVAL_VERTEX_ATTRIB2_NV 0x86C8
+#define GL_EVAL_VERTEX_ATTRIB3_NV 0x86C9
+#define GL_EVAL_VERTEX_ATTRIB4_NV 0x86CA
+#define GL_EVAL_VERTEX_ATTRIB5_NV 0x86CB
+#define GL_EVAL_VERTEX_ATTRIB6_NV 0x86CC
+#define GL_EVAL_VERTEX_ATTRIB7_NV 0x86CD
+#define GL_EVAL_VERTEX_ATTRIB8_NV 0x86CE
+#define GL_EVAL_VERTEX_ATTRIB9_NV 0x86CF
+#define GL_EVAL_VERTEX_ATTRIB10_NV 0x86D0
+#define GL_EVAL_VERTEX_ATTRIB11_NV 0x86D1
+#define GL_EVAL_VERTEX_ATTRIB12_NV 0x86D2
+#define GL_EVAL_VERTEX_ATTRIB13_NV 0x86D3
+#define GL_EVAL_VERTEX_ATTRIB14_NV 0x86D4
+#define GL_EVAL_VERTEX_ATTRIB15_NV 0x86D5
+#define GL_MAX_MAP_TESSELLATION_NV 0x86D6
+#define GL_MAX_RATIONAL_EVAL_ORDER_NV 0x86D7
+typedef void (APIENTRYP PFNGLMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLint uorder, GLint vorder, GLboolean packed, const void *points);
+typedef void (APIENTRYP PFNGLMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLGETMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLboolean packed, void *points);
+typedef void (APIENTRYP PFNGLGETMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERIVNVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLEVALMAPSNVPROC) (GLenum target, GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMapControlPointsNV (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLint uorder, GLint vorder, GLboolean packed, const void *points);
+GLAPI void APIENTRY glMapParameterivNV (GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glMapParameterfvNV (GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glGetMapControlPointsNV (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLboolean packed, void *points);
+GLAPI void APIENTRY glGetMapParameterivNV (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetMapParameterfvNV (GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetMapAttribParameterivNV (GLenum target, GLuint index, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetMapAttribParameterfvNV (GLenum target, GLuint index, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glEvalMapsNV (GLenum target, GLenum mode);
+#endif
+#endif /* GL_NV_evaluators */
+
+#ifndef GL_NV_explicit_multisample
+#define GL_NV_explicit_multisample 1
+#define GL_SAMPLE_POSITION_NV 0x8E50
+#define GL_SAMPLE_MASK_NV 0x8E51
+#define GL_SAMPLE_MASK_VALUE_NV 0x8E52
+#define GL_TEXTURE_BINDING_RENDERBUFFER_NV 0x8E53
+#define GL_TEXTURE_RENDERBUFFER_DATA_STORE_BINDING_NV 0x8E54
+#define GL_TEXTURE_RENDERBUFFER_NV 0x8E55
+#define GL_SAMPLER_RENDERBUFFER_NV 0x8E56
+#define GL_INT_SAMPLER_RENDERBUFFER_NV 0x8E57
+#define GL_UNSIGNED_INT_SAMPLER_RENDERBUFFER_NV 0x8E58
+#define GL_MAX_SAMPLE_MASK_WORDS_NV 0x8E59
+typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVNVPROC) (GLenum pname, GLuint index, GLfloat *val);
+typedef void (APIENTRYP PFNGLSAMPLEMASKINDEXEDNVPROC) (GLuint index, GLbitfield mask);
+typedef void (APIENTRYP PFNGLTEXRENDERBUFFERNVPROC) (GLenum target, GLuint renderbuffer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGetMultisamplefvNV (GLenum pname, GLuint index, GLfloat *val);
+GLAPI void APIENTRY glSampleMaskIndexedNV (GLuint index, GLbitfield mask);
+GLAPI void APIENTRY glTexRenderbufferNV (GLenum target, GLuint renderbuffer);
+#endif
+#endif /* GL_NV_explicit_multisample */
+
+#ifndef GL_NV_fence
+#define GL_NV_fence 1
+#define GL_ALL_COMPLETED_NV 0x84F2
+#define GL_FENCE_STATUS_NV 0x84F3
+#define GL_FENCE_CONDITION_NV 0x84F4
+typedef void (APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences);
+typedef void (APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences);
+typedef GLboolean (APIENTRYP PFNGLISFENCENVPROC) (GLuint fence);
+typedef GLboolean (APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence);
+typedef void (APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence);
+typedef void (APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDeleteFencesNV (GLsizei n, const GLuint *fences);
+GLAPI void APIENTRY glGenFencesNV (GLsizei n, GLuint *fences);
+GLAPI GLboolean APIENTRY glIsFenceNV (GLuint fence);
+GLAPI GLboolean APIENTRY glTestFenceNV (GLuint fence);
+GLAPI void APIENTRY glGetFenceivNV (GLuint fence, GLenum pname, GLint *params);
+GLAPI void APIENTRY glFinishFenceNV (GLuint fence);
+GLAPI void APIENTRY glSetFenceNV (GLuint fence, GLenum condition);
+#endif
+#endif /* GL_NV_fence */
+
+#ifndef GL_NV_float_buffer
+#define GL_NV_float_buffer 1
+#define GL_FLOAT_R_NV 0x8880
+#define GL_FLOAT_RG_NV 0x8881
+#define GL_FLOAT_RGB_NV 0x8882
+#define GL_FLOAT_RGBA_NV 0x8883
+#define GL_FLOAT_R16_NV 0x8884
+#define GL_FLOAT_R32_NV 0x8885
+#define GL_FLOAT_RG16_NV 0x8886
+#define GL_FLOAT_RG32_NV 0x8887
+#define GL_FLOAT_RGB16_NV 0x8888
+#define GL_FLOAT_RGB32_NV 0x8889
+#define GL_FLOAT_RGBA16_NV 0x888A
+#define GL_FLOAT_RGBA32_NV 0x888B
+#define GL_TEXTURE_FLOAT_COMPONENTS_NV 0x888C
+#define GL_FLOAT_CLEAR_COLOR_VALUE_NV 0x888D
+#define GL_FLOAT_RGBA_MODE_NV 0x888E
+#endif /* GL_NV_float_buffer */
+
+#ifndef GL_NV_fog_distance
+#define GL_NV_fog_distance 1
+#define GL_FOG_DISTANCE_MODE_NV 0x855A
+#define GL_EYE_RADIAL_NV 0x855B
+#define GL_EYE_PLANE_ABSOLUTE_NV 0x855C
+#endif /* GL_NV_fog_distance */
+
+#ifndef GL_NV_fragment_program
+#define GL_NV_fragment_program 1
+#define GL_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMETERS_NV 0x8868
+#define GL_FRAGMENT_PROGRAM_NV 0x8870
+#define GL_MAX_TEXTURE_COORDS_NV 0x8871
+#define GL_MAX_TEXTURE_IMAGE_UNITS_NV 0x8872
+#define GL_FRAGMENT_PROGRAM_BINDING_NV 0x8873
+#define GL_PROGRAM_ERROR_STRING_NV 0x8874
+typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLfloat *v);
+typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLdouble *v);
+typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERFVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERDVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProgramNamedParameter4fNV (GLuint id, GLsizei len, const GLubyte *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glProgramNamedParameter4fvNV (GLuint id, GLsizei len, const GLubyte *name, const GLfloat *v);
+GLAPI void APIENTRY glProgramNamedParameter4dNV (GLuint id, GLsizei len, const GLubyte *name, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glProgramNamedParameter4dvNV (GLuint id, GLsizei len, const GLubyte *name, const GLdouble *v);
+GLAPI void APIENTRY glGetProgramNamedParameterfvNV (GLuint id, GLsizei len, const GLubyte *name, GLfloat *params);
+GLAPI void APIENTRY glGetProgramNamedParameterdvNV (GLuint id, GLsizei len, const GLubyte *name, GLdouble *params);
+#endif
+#endif /* GL_NV_fragment_program */
+
+#ifndef GL_NV_fragment_program2
+#define GL_NV_fragment_program2 1
+#define GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV 0x88F4
+#define GL_MAX_PROGRAM_CALL_DEPTH_NV 0x88F5
+#define GL_MAX_PROGRAM_IF_DEPTH_NV 0x88F6
+#define GL_MAX_PROGRAM_LOOP_DEPTH_NV 0x88F7
+#define GL_MAX_PROGRAM_LOOP_COUNT_NV 0x88F8
+#endif /* GL_NV_fragment_program2 */
+
+#ifndef GL_NV_fragment_program4
+#define GL_NV_fragment_program4 1
+#endif /* GL_NV_fragment_program4 */
+
+#ifndef GL_NV_fragment_program_option
+#define GL_NV_fragment_program_option 1
+#endif /* GL_NV_fragment_program_option */
+
+#ifndef GL_NV_framebuffer_multisample_coverage
+#define GL_NV_framebuffer_multisample_coverage 1
+#define GL_RENDERBUFFER_COVERAGE_SAMPLES_NV 0x8CAB
+#define GL_RENDERBUFFER_COLOR_SAMPLES_NV 0x8E10
+#define GL_MAX_MULTISAMPLE_COVERAGE_MODES_NV 0x8E11
+#define GL_MULTISAMPLE_COVERAGE_MODES_NV 0x8E12
+typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLECOVERAGENVPROC) (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glRenderbufferStorageMultisampleCoverageNV (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height);
+#endif
+#endif /* GL_NV_framebuffer_multisample_coverage */
+
+#ifndef GL_NV_geometry_program4
+#define GL_NV_geometry_program4 1
+#define GL_GEOMETRY_PROGRAM_NV 0x8C26
+#define GL_MAX_PROGRAM_OUTPUT_VERTICES_NV 0x8C27
+#define GL_MAX_PROGRAM_TOTAL_OUTPUT_COMPONENTS_NV 0x8C28
+typedef void (APIENTRYP PFNGLPROGRAMVERTEXLIMITNVPROC) (GLenum target, GLint limit);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREEXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYEREXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREFACEEXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProgramVertexLimitNV (GLenum target, GLint limit);
+GLAPI void APIENTRY glFramebufferTextureEXT (GLenum target, GLenum attachment, GLuint texture, GLint level);
+GLAPI void APIENTRY glFramebufferTextureLayerEXT (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer);
+GLAPI void APIENTRY glFramebufferTextureFaceEXT (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face);
+#endif
+#endif /* GL_NV_geometry_program4 */
+
+#ifndef GL_NV_geometry_shader4
+#define GL_NV_geometry_shader4 1
+#endif /* GL_NV_geometry_shader4 */
+
+#ifndef GL_NV_gpu_program4
+#define GL_NV_gpu_program4 1
+#define GL_MIN_PROGRAM_TEXEL_OFFSET_NV 0x8904
+#define GL_MAX_PROGRAM_TEXEL_OFFSET_NV 0x8905
+#define GL_PROGRAM_ATTRIB_COMPONENTS_NV 0x8906
+#define GL_PROGRAM_RESULT_COMPONENTS_NV 0x8907
+#define GL_MAX_PROGRAM_ATTRIB_COMPONENTS_NV 0x8908
+#define GL_MAX_PROGRAM_RESULT_COMPONENTS_NV 0x8909
+#define GL_MAX_PROGRAM_GENERIC_ATTRIBS_NV 0x8DA5
+#define GL_MAX_PROGRAM_GENERIC_RESULTS_NV 0x8DA6
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4INVPROC) (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4IVNVPROC) (GLenum target, GLuint index, const GLint *params);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERSI4IVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLint *params);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4UINVPROC) (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4UIVNVPROC) (GLenum target, GLuint index, const GLuint *params);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERSI4UIVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLuint *params);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4INVPROC) (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4IVNVPROC) (GLenum target, GLuint index, const GLint *params);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERSI4IVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLint *params);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4UINVPROC) (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4UIVNVPROC) (GLenum target, GLuint index, const GLuint *params);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERSI4UIVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLuint *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERIIVNVPROC) (GLenum target, GLuint index, GLint *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERIUIVNVPROC) (GLenum target, GLuint index, GLuint *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERIIVNVPROC) (GLenum target, GLuint index, GLint *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERIUIVNVPROC) (GLenum target, GLuint index, GLuint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProgramLocalParameterI4iNV (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w);
+GLAPI void APIENTRY glProgramLocalParameterI4ivNV (GLenum target, GLuint index, const GLint *params);
+GLAPI void APIENTRY glProgramLocalParametersI4ivNV (GLenum target, GLuint index, GLsizei count, const GLint *params);
+GLAPI void APIENTRY glProgramLocalParameterI4uiNV (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+GLAPI void APIENTRY glProgramLocalParameterI4uivNV (GLenum target, GLuint index, const GLuint *params);
+GLAPI void APIENTRY glProgramLocalParametersI4uivNV (GLenum target, GLuint index, GLsizei count, const GLuint *params);
+GLAPI void APIENTRY glProgramEnvParameterI4iNV (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w);
+GLAPI void APIENTRY glProgramEnvParameterI4ivNV (GLenum target, GLuint index, const GLint *params);
+GLAPI void APIENTRY glProgramEnvParametersI4ivNV (GLenum target, GLuint index, GLsizei count, const GLint *params);
+GLAPI void APIENTRY glProgramEnvParameterI4uiNV (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+GLAPI void APIENTRY glProgramEnvParameterI4uivNV (GLenum target, GLuint index, const GLuint *params);
+GLAPI void APIENTRY glProgramEnvParametersI4uivNV (GLenum target, GLuint index, GLsizei count, const GLuint *params);
+GLAPI void APIENTRY glGetProgramLocalParameterIivNV (GLenum target, GLuint index, GLint *params);
+GLAPI void APIENTRY glGetProgramLocalParameterIuivNV (GLenum target, GLuint index, GLuint *params);
+GLAPI void APIENTRY glGetProgramEnvParameterIivNV (GLenum target, GLuint index, GLint *params);
+GLAPI void APIENTRY glGetProgramEnvParameterIuivNV (GLenum target, GLuint index, GLuint *params);
+#endif
+#endif /* GL_NV_gpu_program4 */
+
+#ifndef GL_NV_gpu_program5
+#define GL_NV_gpu_program5 1
+#define GL_MAX_GEOMETRY_PROGRAM_INVOCATIONS_NV 0x8E5A
+#define GL_MIN_FRAGMENT_INTERPOLATION_OFFSET_NV 0x8E5B
+#define GL_MAX_FRAGMENT_INTERPOLATION_OFFSET_NV 0x8E5C
+#define GL_FRAGMENT_PROGRAM_INTERPOLATION_OFFSET_BITS_NV 0x8E5D
+#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET_NV 0x8E5E
+#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET_NV 0x8E5F
+#define GL_MAX_PROGRAM_SUBROUTINE_PARAMETERS_NV 0x8F44
+#define GL_MAX_PROGRAM_SUBROUTINE_NUM_NV 0x8F45
+typedef void (APIENTRYP PFNGLPROGRAMSUBROUTINEPARAMETERSUIVNVPROC) (GLenum target, GLsizei count, const GLuint *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMSUBROUTINEPARAMETERUIVNVPROC) (GLenum target, GLuint index, GLuint *param);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProgramSubroutineParametersuivNV (GLenum target, GLsizei count, const GLuint *params);
+GLAPI void APIENTRY glGetProgramSubroutineParameteruivNV (GLenum target, GLuint index, GLuint *param);
+#endif
+#endif /* GL_NV_gpu_program5 */
+
+#ifndef GL_NV_gpu_program5_mem_extended
+#define GL_NV_gpu_program5_mem_extended 1
+#endif /* GL_NV_gpu_program5_mem_extended */
+
+#ifndef GL_NV_gpu_shader5
+#define GL_NV_gpu_shader5 1
+#endif /* GL_NV_gpu_shader5 */
+
+#ifndef GL_NV_half_float
+#define GL_NV_half_float 1
+typedef unsigned short GLhalfNV;
+#define GL_HALF_FLOAT_NV 0x140B
+typedef void (APIENTRYP PFNGLVERTEX2HNVPROC) (GLhalfNV x, GLhalfNV y);
+typedef void (APIENTRYP PFNGLVERTEX2HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEX3HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z);
+typedef void (APIENTRYP PFNGLVERTEX3HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEX4HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w);
+typedef void (APIENTRYP PFNGLVERTEX4HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLNORMAL3HNVPROC) (GLhalfNV nx, GLhalfNV ny, GLhalfNV nz);
+typedef void (APIENTRYP PFNGLNORMAL3HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue);
+typedef void (APIENTRYP PFNGLCOLOR3HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLCOLOR4HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue, GLhalfNV alpha);
+typedef void (APIENTRYP PFNGLCOLOR4HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLTEXCOORD1HNVPROC) (GLhalfNV s);
+typedef void (APIENTRYP PFNGLTEXCOORD1HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLTEXCOORD2HNVPROC) (GLhalfNV s, GLhalfNV t);
+typedef void (APIENTRYP PFNGLTEXCOORD2HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLTEXCOORD3HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r);
+typedef void (APIENTRYP PFNGLTEXCOORD3HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLTEXCOORD4HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q);
+typedef void (APIENTRYP PFNGLTEXCOORD4HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1HNVPROC) (GLenum target, GLhalfNV s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1HVNVPROC) (GLenum target, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2HVNVPROC) (GLenum target, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3HVNVPROC) (GLenum target, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4HVNVPROC) (GLenum target, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLFOGCOORDHNVPROC) (GLhalfNV fog);
+typedef void (APIENTRYP PFNGLFOGCOORDHVNVPROC) (const GLhalfNV *fog);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEXWEIGHTHNVPROC) (GLhalfNV weight);
+typedef void (APIENTRYP PFNGLVERTEXWEIGHTHVNVPROC) (const GLhalfNV *weight);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1HNVPROC) (GLuint index, GLhalfNV x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1HVNVPROC) (GLuint index, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2HVNVPROC) (GLuint index, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3HVNVPROC) (GLuint index, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4HVNVPROC) (GLuint index, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS1HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS2HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS3HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS4HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertex2hNV (GLhalfNV x, GLhalfNV y);
+GLAPI void APIENTRY glVertex2hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glVertex3hNV (GLhalfNV x, GLhalfNV y, GLhalfNV z);
+GLAPI void APIENTRY glVertex3hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glVertex4hNV (GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w);
+GLAPI void APIENTRY glVertex4hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glNormal3hNV (GLhalfNV nx, GLhalfNV ny, GLhalfNV nz);
+GLAPI void APIENTRY glNormal3hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glColor3hNV (GLhalfNV red, GLhalfNV green, GLhalfNV blue);
+GLAPI void APIENTRY glColor3hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glColor4hNV (GLhalfNV red, GLhalfNV green, GLhalfNV blue, GLhalfNV alpha);
+GLAPI void APIENTRY glColor4hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glTexCoord1hNV (GLhalfNV s);
+GLAPI void APIENTRY glTexCoord1hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glTexCoord2hNV (GLhalfNV s, GLhalfNV t);
+GLAPI void APIENTRY glTexCoord2hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glTexCoord3hNV (GLhalfNV s, GLhalfNV t, GLhalfNV r);
+GLAPI void APIENTRY glTexCoord3hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glTexCoord4hNV (GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q);
+GLAPI void APIENTRY glTexCoord4hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glMultiTexCoord1hNV (GLenum target, GLhalfNV s);
+GLAPI void APIENTRY glMultiTexCoord1hvNV (GLenum target, const GLhalfNV *v);
+GLAPI void APIENTRY glMultiTexCoord2hNV (GLenum target, GLhalfNV s, GLhalfNV t);
+GLAPI void APIENTRY glMultiTexCoord2hvNV (GLenum target, const GLhalfNV *v);
+GLAPI void APIENTRY glMultiTexCoord3hNV (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r);
+GLAPI void APIENTRY glMultiTexCoord3hvNV (GLenum target, const GLhalfNV *v);
+GLAPI void APIENTRY glMultiTexCoord4hNV (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q);
+GLAPI void APIENTRY glMultiTexCoord4hvNV (GLenum target, const GLhalfNV *v);
+GLAPI void APIENTRY glFogCoordhNV (GLhalfNV fog);
+GLAPI void APIENTRY glFogCoordhvNV (const GLhalfNV *fog);
+GLAPI void APIENTRY glSecondaryColor3hNV (GLhalfNV red, GLhalfNV green, GLhalfNV blue);
+GLAPI void APIENTRY glSecondaryColor3hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glVertexWeighthNV (GLhalfNV weight);
+GLAPI void APIENTRY glVertexWeighthvNV (const GLhalfNV *weight);
+GLAPI void APIENTRY glVertexAttrib1hNV (GLuint index, GLhalfNV x);
+GLAPI void APIENTRY glVertexAttrib1hvNV (GLuint index, const GLhalfNV *v);
+GLAPI void APIENTRY glVertexAttrib2hNV (GLuint index, GLhalfNV x, GLhalfNV y);
+GLAPI void APIENTRY glVertexAttrib2hvNV (GLuint index, const GLhalfNV *v);
+GLAPI void APIENTRY glVertexAttrib3hNV (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z);
+GLAPI void APIENTRY glVertexAttrib3hvNV (GLuint index, const GLhalfNV *v);
+GLAPI void APIENTRY glVertexAttrib4hNV (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w);
+GLAPI void APIENTRY glVertexAttrib4hvNV (GLuint index, const GLhalfNV *v);
+GLAPI void APIENTRY glVertexAttribs1hvNV (GLuint index, GLsizei n, const GLhalfNV *v);
+GLAPI void APIENTRY glVertexAttribs2hvNV (GLuint index, GLsizei n, const GLhalfNV *v);
+GLAPI void APIENTRY glVertexAttribs3hvNV (GLuint index, GLsizei n, const GLhalfNV *v);
+GLAPI void APIENTRY glVertexAttribs4hvNV (GLuint index, GLsizei n, const GLhalfNV *v);
+#endif
+#endif /* GL_NV_half_float */
+
+#ifndef GL_NV_light_max_exponent
+#define GL_NV_light_max_exponent 1
+#define GL_MAX_SHININESS_NV 0x8504
+#define GL_MAX_SPOT_EXPONENT_NV 0x8505
+#endif /* GL_NV_light_max_exponent */
+
+#ifndef GL_NV_multisample_coverage
+#define GL_NV_multisample_coverage 1
+#define GL_COLOR_SAMPLES_NV 0x8E20
+#endif /* GL_NV_multisample_coverage */
+
+#ifndef GL_NV_multisample_filter_hint
+#define GL_NV_multisample_filter_hint 1
+#define GL_MULTISAMPLE_FILTER_HINT_NV 0x8534
+#endif /* GL_NV_multisample_filter_hint */
+
+#ifndef GL_NV_occlusion_query
+#define GL_NV_occlusion_query 1
+#define GL_PIXEL_COUNTER_BITS_NV 0x8864
+#define GL_CURRENT_OCCLUSION_QUERY_ID_NV 0x8865
+#define GL_PIXEL_COUNT_NV 0x8866
+#define GL_PIXEL_COUNT_AVAILABLE_NV 0x8867
+typedef void (APIENTRYP PFNGLGENOCCLUSIONQUERIESNVPROC) (GLsizei n, GLuint *ids);
+typedef void (APIENTRYP PFNGLDELETEOCCLUSIONQUERIESNVPROC) (GLsizei n, const GLuint *ids);
+typedef GLboolean (APIENTRYP PFNGLISOCCLUSIONQUERYNVPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLBEGINOCCLUSIONQUERYNVPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLENDOCCLUSIONQUERYNVPROC) (void);
+typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYIVNVPROC) (GLuint id, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYUIVNVPROC) (GLuint id, GLenum pname, GLuint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGenOcclusionQueriesNV (GLsizei n, GLuint *ids);
+GLAPI void APIENTRY glDeleteOcclusionQueriesNV (GLsizei n, const GLuint *ids);
+GLAPI GLboolean APIENTRY glIsOcclusionQueryNV (GLuint id);
+GLAPI void APIENTRY glBeginOcclusionQueryNV (GLuint id);
+GLAPI void APIENTRY glEndOcclusionQueryNV (void);
+GLAPI void APIENTRY glGetOcclusionQueryivNV (GLuint id, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetOcclusionQueryuivNV (GLuint id, GLenum pname, GLuint *params);
+#endif
+#endif /* GL_NV_occlusion_query */
+
+#ifndef GL_NV_packed_depth_stencil
+#define GL_NV_packed_depth_stencil 1
+#define GL_DEPTH_STENCIL_NV 0x84F9
+#define GL_UNSIGNED_INT_24_8_NV 0x84FA
+#endif /* GL_NV_packed_depth_stencil */
+
+#ifndef GL_NV_parameter_buffer_object
+#define GL_NV_parameter_buffer_object 1
+#define GL_MAX_PROGRAM_PARAMETER_BUFFER_BINDINGS_NV 0x8DA0
+#define GL_MAX_PROGRAM_PARAMETER_BUFFER_SIZE_NV 0x8DA1
+#define GL_VERTEX_PROGRAM_PARAMETER_BUFFER_NV 0x8DA2
+#define GL_GEOMETRY_PROGRAM_PARAMETER_BUFFER_NV 0x8DA3
+#define GL_FRAGMENT_PROGRAM_PARAMETER_BUFFER_NV 0x8DA4
+typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSFVNVPROC) (GLenum target, GLuint bindingIndex, GLuint wordIndex, GLsizei count, const GLfloat *params);
+typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSIIVNVPROC) (GLenum target, GLuint bindingIndex, GLuint wordIndex, GLsizei count, const GLint *params);
+typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSIUIVNVPROC) (GLenum target, GLuint bindingIndex, GLuint wordIndex, GLsizei count, const GLuint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProgramBufferParametersfvNV (GLenum target, GLuint bindingIndex, GLuint wordIndex, GLsizei count, const GLfloat *params);
+GLAPI void APIENTRY glProgramBufferParametersIivNV (GLenum target, GLuint bindingIndex, GLuint wordIndex, GLsizei count, const GLint *params);
+GLAPI void APIENTRY glProgramBufferParametersIuivNV (GLenum target, GLuint bindingIndex, GLuint wordIndex, GLsizei count, const GLuint *params);
+#endif
+#endif /* GL_NV_parameter_buffer_object */
+
+#ifndef GL_NV_parameter_buffer_object2
+#define GL_NV_parameter_buffer_object2 1
+#endif /* GL_NV_parameter_buffer_object2 */
+
+#ifndef GL_NV_path_rendering
+#define GL_NV_path_rendering 1
+#define GL_PATH_FORMAT_SVG_NV 0x9070
+#define GL_PATH_FORMAT_PS_NV 0x9071
+#define GL_STANDARD_FONT_NAME_NV 0x9072
+#define GL_SYSTEM_FONT_NAME_NV 0x9073
+#define GL_FILE_NAME_NV 0x9074
+#define GL_PATH_STROKE_WIDTH_NV 0x9075
+#define GL_PATH_END_CAPS_NV 0x9076
+#define GL_PATH_INITIAL_END_CAP_NV 0x9077
+#define GL_PATH_TERMINAL_END_CAP_NV 0x9078
+#define GL_PATH_JOIN_STYLE_NV 0x9079
+#define GL_PATH_MITER_LIMIT_NV 0x907A
+#define GL_PATH_DASH_CAPS_NV 0x907B
+#define GL_PATH_INITIAL_DASH_CAP_NV 0x907C
+#define GL_PATH_TERMINAL_DASH_CAP_NV 0x907D
+#define GL_PATH_DASH_OFFSET_NV 0x907E
+#define GL_PATH_CLIENT_LENGTH_NV 0x907F
+#define GL_PATH_FILL_MODE_NV 0x9080
+#define GL_PATH_FILL_MASK_NV 0x9081
+#define GL_PATH_FILL_COVER_MODE_NV 0x9082
+#define GL_PATH_STROKE_COVER_MODE_NV 0x9083
+#define GL_PATH_STROKE_MASK_NV 0x9084
+#define GL_COUNT_UP_NV 0x9088
+#define GL_COUNT_DOWN_NV 0x9089
+#define GL_PATH_OBJECT_BOUNDING_BOX_NV 0x908A
+#define GL_CONVEX_HULL_NV 0x908B
+#define GL_BOUNDING_BOX_NV 0x908D
+#define GL_TRANSLATE_X_NV 0x908E
+#define GL_TRANSLATE_Y_NV 0x908F
+#define GL_TRANSLATE_2D_NV 0x9090
+#define GL_TRANSLATE_3D_NV 0x9091
+#define GL_AFFINE_2D_NV 0x9092
+#define GL_AFFINE_3D_NV 0x9094
+#define GL_TRANSPOSE_AFFINE_2D_NV 0x9096
+#define GL_TRANSPOSE_AFFINE_3D_NV 0x9098
+#define GL_UTF8_NV 0x909A
+#define GL_UTF16_NV 0x909B
+#define GL_BOUNDING_BOX_OF_BOUNDING_BOXES_NV 0x909C
+#define GL_PATH_COMMAND_COUNT_NV 0x909D
+#define GL_PATH_COORD_COUNT_NV 0x909E
+#define GL_PATH_DASH_ARRAY_COUNT_NV 0x909F
+#define GL_PATH_COMPUTED_LENGTH_NV 0x90A0
+#define GL_PATH_FILL_BOUNDING_BOX_NV 0x90A1
+#define GL_PATH_STROKE_BOUNDING_BOX_NV 0x90A2
+#define GL_SQUARE_NV 0x90A3
+#define GL_ROUND_NV 0x90A4
+#define GL_TRIANGULAR_NV 0x90A5
+#define GL_BEVEL_NV 0x90A6
+#define GL_MITER_REVERT_NV 0x90A7
+#define GL_MITER_TRUNCATE_NV 0x90A8
+#define GL_SKIP_MISSING_GLYPH_NV 0x90A9
+#define GL_USE_MISSING_GLYPH_NV 0x90AA
+#define GL_PATH_ERROR_POSITION_NV 0x90AB
+#define GL_PATH_FOG_GEN_MODE_NV 0x90AC
+#define GL_ACCUM_ADJACENT_PAIRS_NV 0x90AD
+#define GL_ADJACENT_PAIRS_NV 0x90AE
+#define GL_FIRST_TO_REST_NV 0x90AF
+#define GL_PATH_GEN_MODE_NV 0x90B0
+#define GL_PATH_GEN_COEFF_NV 0x90B1
+#define GL_PATH_GEN_COLOR_FORMAT_NV 0x90B2
+#define GL_PATH_GEN_COMPONENTS_NV 0x90B3
+#define GL_PATH_STENCIL_FUNC_NV 0x90B7
+#define GL_PATH_STENCIL_REF_NV 0x90B8
+#define GL_PATH_STENCIL_VALUE_MASK_NV 0x90B9
+#define GL_PATH_STENCIL_DEPTH_OFFSET_FACTOR_NV 0x90BD
+#define GL_PATH_STENCIL_DEPTH_OFFSET_UNITS_NV 0x90BE
+#define GL_PATH_COVER_DEPTH_FUNC_NV 0x90BF
+#define GL_PATH_DASH_OFFSET_RESET_NV 0x90B4
+#define GL_MOVE_TO_RESETS_NV 0x90B5
+#define GL_MOVE_TO_CONTINUES_NV 0x90B6
+#define GL_CLOSE_PATH_NV 0x00
+#define GL_MOVE_TO_NV 0x02
+#define GL_RELATIVE_MOVE_TO_NV 0x03
+#define GL_LINE_TO_NV 0x04
+#define GL_RELATIVE_LINE_TO_NV 0x05
+#define GL_HORIZONTAL_LINE_TO_NV 0x06
+#define GL_RELATIVE_HORIZONTAL_LINE_TO_NV 0x07
+#define GL_VERTICAL_LINE_TO_NV 0x08
+#define GL_RELATIVE_VERTICAL_LINE_TO_NV 0x09
+#define GL_QUADRATIC_CURVE_TO_NV 0x0A
+#define GL_RELATIVE_QUADRATIC_CURVE_TO_NV 0x0B
+#define GL_CUBIC_CURVE_TO_NV 0x0C
+#define GL_RELATIVE_CUBIC_CURVE_TO_NV 0x0D
+#define GL_SMOOTH_QUADRATIC_CURVE_TO_NV 0x0E
+#define GL_RELATIVE_SMOOTH_QUADRATIC_CURVE_TO_NV 0x0F
+#define GL_SMOOTH_CUBIC_CURVE_TO_NV 0x10
+#define GL_RELATIVE_SMOOTH_CUBIC_CURVE_TO_NV 0x11
+#define GL_SMALL_CCW_ARC_TO_NV 0x12
+#define GL_RELATIVE_SMALL_CCW_ARC_TO_NV 0x13
+#define GL_SMALL_CW_ARC_TO_NV 0x14
+#define GL_RELATIVE_SMALL_CW_ARC_TO_NV 0x15
+#define GL_LARGE_CCW_ARC_TO_NV 0x16
+#define GL_RELATIVE_LARGE_CCW_ARC_TO_NV 0x17
+#define GL_LARGE_CW_ARC_TO_NV 0x18
+#define GL_RELATIVE_LARGE_CW_ARC_TO_NV 0x19
+#define GL_RESTART_PATH_NV 0xF0
+#define GL_DUP_FIRST_CUBIC_CURVE_TO_NV 0xF2
+#define GL_DUP_LAST_CUBIC_CURVE_TO_NV 0xF4
+#define GL_RECT_NV 0xF6
+#define GL_CIRCULAR_CCW_ARC_TO_NV 0xF8
+#define GL_CIRCULAR_CW_ARC_TO_NV 0xFA
+#define GL_CIRCULAR_TANGENT_ARC_TO_NV 0xFC
+#define GL_ARC_TO_NV 0xFE
+#define GL_RELATIVE_ARC_TO_NV 0xFF
+#define GL_BOLD_BIT_NV 0x01
+#define GL_ITALIC_BIT_NV 0x02
+#define GL_GLYPH_WIDTH_BIT_NV 0x01
+#define GL_GLYPH_HEIGHT_BIT_NV 0x02
+#define GL_GLYPH_HORIZONTAL_BEARING_X_BIT_NV 0x04
+#define GL_GLYPH_HORIZONTAL_BEARING_Y_BIT_NV 0x08
+#define GL_GLYPH_HORIZONTAL_BEARING_ADVANCE_BIT_NV 0x10
+#define GL_GLYPH_VERTICAL_BEARING_X_BIT_NV 0x20
+#define GL_GLYPH_VERTICAL_BEARING_Y_BIT_NV 0x40
+#define GL_GLYPH_VERTICAL_BEARING_ADVANCE_BIT_NV 0x80
+#define GL_GLYPH_HAS_KERNING_BIT_NV 0x100
+#define GL_FONT_X_MIN_BOUNDS_BIT_NV 0x00010000
+#define GL_FONT_Y_MIN_BOUNDS_BIT_NV 0x00020000
+#define GL_FONT_X_MAX_BOUNDS_BIT_NV 0x00040000
+#define GL_FONT_Y_MAX_BOUNDS_BIT_NV 0x00080000
+#define GL_FONT_UNITS_PER_EM_BIT_NV 0x00100000
+#define GL_FONT_ASCENDER_BIT_NV 0x00200000
+#define GL_FONT_DESCENDER_BIT_NV 0x00400000
+#define GL_FONT_HEIGHT_BIT_NV 0x00800000
+#define GL_FONT_MAX_ADVANCE_WIDTH_BIT_NV 0x01000000
+#define GL_FONT_MAX_ADVANCE_HEIGHT_BIT_NV 0x02000000
+#define GL_FONT_UNDERLINE_POSITION_BIT_NV 0x04000000
+#define GL_FONT_UNDERLINE_THICKNESS_BIT_NV 0x08000000
+#define GL_FONT_HAS_KERNING_BIT_NV 0x10000000
+#define GL_PRIMARY_COLOR_NV 0x852C
+#define GL_SECONDARY_COLOR_NV 0x852D
+typedef GLuint (APIENTRYP PFNGLGENPATHSNVPROC) (GLsizei range);
+typedef void (APIENTRYP PFNGLDELETEPATHSNVPROC) (GLuint path, GLsizei range);
+typedef GLboolean (APIENTRYP PFNGLISPATHNVPROC) (GLuint path);
+typedef void (APIENTRYP PFNGLPATHCOMMANDSNVPROC) (GLuint path, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const void *coords);
+typedef void (APIENTRYP PFNGLPATHCOORDSNVPROC) (GLuint path, GLsizei numCoords, GLenum coordType, const void *coords);
+typedef void (APIENTRYP PFNGLPATHSUBCOMMANDSNVPROC) (GLuint path, GLsizei commandStart, GLsizei commandsToDelete, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const void *coords);
+typedef void (APIENTRYP PFNGLPATHSUBCOORDSNVPROC) (GLuint path, GLsizei coordStart, GLsizei numCoords, GLenum coordType, const void *coords);
+typedef void (APIENTRYP PFNGLPATHSTRINGNVPROC) (GLuint path, GLenum format, GLsizei length, const void *pathString);
+typedef void (APIENTRYP PFNGLPATHGLYPHSNVPROC) (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLsizei numGlyphs, GLenum type, const void *charcodes, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale);
+typedef void (APIENTRYP PFNGLPATHGLYPHRANGENVPROC) (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLuint firstGlyph, GLsizei numGlyphs, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale);
+typedef void (APIENTRYP PFNGLWEIGHTPATHSNVPROC) (GLuint resultPath, GLsizei numPaths, const GLuint *paths, const GLfloat *weights);
+typedef void (APIENTRYP PFNGLCOPYPATHNVPROC) (GLuint resultPath, GLuint srcPath);
+typedef void (APIENTRYP PFNGLINTERPOLATEPATHSNVPROC) (GLuint resultPath, GLuint pathA, GLuint pathB, GLfloat weight);
+typedef void (APIENTRYP PFNGLTRANSFORMPATHNVPROC) (GLuint resultPath, GLuint srcPath, GLenum transformType, const GLfloat *transformValues);
+typedef void (APIENTRYP PFNGLPATHPARAMETERIVNVPROC) (GLuint path, GLenum pname, const GLint *value);
+typedef void (APIENTRYP PFNGLPATHPARAMETERINVPROC) (GLuint path, GLenum pname, GLint value);
+typedef void (APIENTRYP PFNGLPATHPARAMETERFVNVPROC) (GLuint path, GLenum pname, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPATHPARAMETERFNVPROC) (GLuint path, GLenum pname, GLfloat value);
+typedef void (APIENTRYP PFNGLPATHDASHARRAYNVPROC) (GLuint path, GLsizei dashCount, const GLfloat *dashArray);
+typedef void (APIENTRYP PFNGLPATHSTENCILFUNCNVPROC) (GLenum func, GLint ref, GLuint mask);
+typedef void (APIENTRYP PFNGLPATHSTENCILDEPTHOFFSETNVPROC) (GLfloat factor, GLfloat units);
+typedef void (APIENTRYP PFNGLSTENCILFILLPATHNVPROC) (GLuint path, GLenum fillMode, GLuint mask);
+typedef void (APIENTRYP PFNGLSTENCILSTROKEPATHNVPROC) (GLuint path, GLint reference, GLuint mask);
+typedef void (APIENTRYP PFNGLSTENCILFILLPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum fillMode, GLuint mask, GLenum transformType, const GLfloat *transformValues);
+typedef void (APIENTRYP PFNGLSTENCILSTROKEPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLint reference, GLuint mask, GLenum transformType, const GLfloat *transformValues);
+typedef void (APIENTRYP PFNGLPATHCOVERDEPTHFUNCNVPROC) (GLenum func);
+typedef void (APIENTRYP PFNGLPATHCOLORGENNVPROC) (GLenum color, GLenum genMode, GLenum colorFormat, const GLfloat *coeffs);
+typedef void (APIENTRYP PFNGLPATHTEXGENNVPROC) (GLenum texCoordSet, GLenum genMode, GLint components, const GLfloat *coeffs);
+typedef void (APIENTRYP PFNGLPATHFOGGENNVPROC) (GLenum genMode);
+typedef void (APIENTRYP PFNGLCOVERFILLPATHNVPROC) (GLuint path, GLenum coverMode);
+typedef void (APIENTRYP PFNGLCOVERSTROKEPATHNVPROC) (GLuint path, GLenum coverMode);
+typedef void (APIENTRYP PFNGLCOVERFILLPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues);
+typedef void (APIENTRYP PFNGLCOVERSTROKEPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues);
+typedef void (APIENTRYP PFNGLGETPATHPARAMETERIVNVPROC) (GLuint path, GLenum pname, GLint *value);
+typedef void (APIENTRYP PFNGLGETPATHPARAMETERFVNVPROC) (GLuint path, GLenum pname, GLfloat *value);
+typedef void (APIENTRYP PFNGLGETPATHCOMMANDSNVPROC) (GLuint path, GLubyte *commands);
+typedef void (APIENTRYP PFNGLGETPATHCOORDSNVPROC) (GLuint path, GLfloat *coords);
+typedef void (APIENTRYP PFNGLGETPATHDASHARRAYNVPROC) (GLuint path, GLfloat *dashArray);
+typedef void (APIENTRYP PFNGLGETPATHMETRICSNVPROC) (GLbitfield metricQueryMask, GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLsizei stride, GLfloat *metrics);
+typedef void (APIENTRYP PFNGLGETPATHMETRICRANGENVPROC) (GLbitfield metricQueryMask, GLuint firstPathName, GLsizei numPaths, GLsizei stride, GLfloat *metrics);
+typedef void (APIENTRYP PFNGLGETPATHSPACINGNVPROC) (GLenum pathListMode, GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLfloat advanceScale, GLfloat kerningScale, GLenum transformType, GLfloat *returnedSpacing);
+typedef void (APIENTRYP PFNGLGETPATHCOLORGENIVNVPROC) (GLenum color, GLenum pname, GLint *value);
+typedef void (APIENTRYP PFNGLGETPATHCOLORGENFVNVPROC) (GLenum color, GLenum pname, GLfloat *value);
+typedef void (APIENTRYP PFNGLGETPATHTEXGENIVNVPROC) (GLenum texCoordSet, GLenum pname, GLint *value);
+typedef void (APIENTRYP PFNGLGETPATHTEXGENFVNVPROC) (GLenum texCoordSet, GLenum pname, GLfloat *value);
+typedef GLboolean (APIENTRYP PFNGLISPOINTINFILLPATHNVPROC) (GLuint path, GLuint mask, GLfloat x, GLfloat y);
+typedef GLboolean (APIENTRYP PFNGLISPOINTINSTROKEPATHNVPROC) (GLuint path, GLfloat x, GLfloat y);
+typedef GLfloat (APIENTRYP PFNGLGETPATHLENGTHNVPROC) (GLuint path, GLsizei startSegment, GLsizei numSegments);
+typedef GLboolean (APIENTRYP PFNGLPOINTALONGPATHNVPROC) (GLuint path, GLsizei startSegment, GLsizei numSegments, GLfloat distance, GLfloat *x, GLfloat *y, GLfloat *tangentX, GLfloat *tangentY);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLuint APIENTRY glGenPathsNV (GLsizei range);
+GLAPI void APIENTRY glDeletePathsNV (GLuint path, GLsizei range);
+GLAPI GLboolean APIENTRY glIsPathNV (GLuint path);
+GLAPI void APIENTRY glPathCommandsNV (GLuint path, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const void *coords);
+GLAPI void APIENTRY glPathCoordsNV (GLuint path, GLsizei numCoords, GLenum coordType, const void *coords);
+GLAPI void APIENTRY glPathSubCommandsNV (GLuint path, GLsizei commandStart, GLsizei commandsToDelete, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const void *coords);
+GLAPI void APIENTRY glPathSubCoordsNV (GLuint path, GLsizei coordStart, GLsizei numCoords, GLenum coordType, const void *coords);
+GLAPI void APIENTRY glPathStringNV (GLuint path, GLenum format, GLsizei length, const void *pathString);
+GLAPI void APIENTRY glPathGlyphsNV (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLsizei numGlyphs, GLenum type, const void *charcodes, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale);
+GLAPI void APIENTRY glPathGlyphRangeNV (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLuint firstGlyph, GLsizei numGlyphs, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale);
+GLAPI void APIENTRY glWeightPathsNV (GLuint resultPath, GLsizei numPaths, const GLuint *paths, const GLfloat *weights);
+GLAPI void APIENTRY glCopyPathNV (GLuint resultPath, GLuint srcPath);
+GLAPI void APIENTRY glInterpolatePathsNV (GLuint resultPath, GLuint pathA, GLuint pathB, GLfloat weight);
+GLAPI void APIENTRY glTransformPathNV (GLuint resultPath, GLuint srcPath, GLenum transformType, const GLfloat *transformValues);
+GLAPI void APIENTRY glPathParameterivNV (GLuint path, GLenum pname, const GLint *value);
+GLAPI void APIENTRY glPathParameteriNV (GLuint path, GLenum pname, GLint value);
+GLAPI void APIENTRY glPathParameterfvNV (GLuint path, GLenum pname, const GLfloat *value);
+GLAPI void APIENTRY glPathParameterfNV (GLuint path, GLenum pname, GLfloat value);
+GLAPI void APIENTRY glPathDashArrayNV (GLuint path, GLsizei dashCount, const GLfloat *dashArray);
+GLAPI void APIENTRY glPathStencilFuncNV (GLenum func, GLint ref, GLuint mask);
+GLAPI void APIENTRY glPathStencilDepthOffsetNV (GLfloat factor, GLfloat units);
+GLAPI void APIENTRY glStencilFillPathNV (GLuint path, GLenum fillMode, GLuint mask);
+GLAPI void APIENTRY glStencilStrokePathNV (GLuint path, GLint reference, GLuint mask);
+GLAPI void APIENTRY glStencilFillPathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum fillMode, GLuint mask, GLenum transformType, const GLfloat *transformValues);
+GLAPI void APIENTRY glStencilStrokePathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLint reference, GLuint mask, GLenum transformType, const GLfloat *transformValues);
+GLAPI void APIENTRY glPathCoverDepthFuncNV (GLenum func);
+GLAPI void APIENTRY glPathColorGenNV (GLenum color, GLenum genMode, GLenum colorFormat, const GLfloat *coeffs);
+GLAPI void APIENTRY glPathTexGenNV (GLenum texCoordSet, GLenum genMode, GLint components, const GLfloat *coeffs);
+GLAPI void APIENTRY glPathFogGenNV (GLenum genMode);
+GLAPI void APIENTRY glCoverFillPathNV (GLuint path, GLenum coverMode);
+GLAPI void APIENTRY glCoverStrokePathNV (GLuint path, GLenum coverMode);
+GLAPI void APIENTRY glCoverFillPathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues);
+GLAPI void APIENTRY glCoverStrokePathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues);
+GLAPI void APIENTRY glGetPathParameterivNV (GLuint path, GLenum pname, GLint *value);
+GLAPI void APIENTRY glGetPathParameterfvNV (GLuint path, GLenum pname, GLfloat *value);
+GLAPI void APIENTRY glGetPathCommandsNV (GLuint path, GLubyte *commands);
+GLAPI void APIENTRY glGetPathCoordsNV (GLuint path, GLfloat *coords);
+GLAPI void APIENTRY glGetPathDashArrayNV (GLuint path, GLfloat *dashArray);
+GLAPI void APIENTRY glGetPathMetricsNV (GLbitfield metricQueryMask, GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLsizei stride, GLfloat *metrics);
+GLAPI void APIENTRY glGetPathMetricRangeNV (GLbitfield metricQueryMask, GLuint firstPathName, GLsizei numPaths, GLsizei stride, GLfloat *metrics);
+GLAPI void APIENTRY glGetPathSpacingNV (GLenum pathListMode, GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLfloat advanceScale, GLfloat kerningScale, GLenum transformType, GLfloat *returnedSpacing);
+GLAPI void APIENTRY glGetPathColorGenivNV (GLenum color, GLenum pname, GLint *value);
+GLAPI void APIENTRY glGetPathColorGenfvNV (GLenum color, GLenum pname, GLfloat *value);
+GLAPI void APIENTRY glGetPathTexGenivNV (GLenum texCoordSet, GLenum pname, GLint *value);
+GLAPI void APIENTRY glGetPathTexGenfvNV (GLenum texCoordSet, GLenum pname, GLfloat *value);
+GLAPI GLboolean APIENTRY glIsPointInFillPathNV (GLuint path, GLuint mask, GLfloat x, GLfloat y);
+GLAPI GLboolean APIENTRY glIsPointInStrokePathNV (GLuint path, GLfloat x, GLfloat y);
+GLAPI GLfloat APIENTRY glGetPathLengthNV (GLuint path, GLsizei startSegment, GLsizei numSegments);
+GLAPI GLboolean APIENTRY glPointAlongPathNV (GLuint path, GLsizei startSegment, GLsizei numSegments, GLfloat distance, GLfloat *x, GLfloat *y, GLfloat *tangentX, GLfloat *tangentY);
+#endif
+#endif /* GL_NV_path_rendering */
+
+#ifndef GL_NV_pixel_data_range
+#define GL_NV_pixel_data_range 1
+#define GL_WRITE_PIXEL_DATA_RANGE_NV 0x8878
+#define GL_READ_PIXEL_DATA_RANGE_NV 0x8879
+#define GL_WRITE_PIXEL_DATA_RANGE_LENGTH_NV 0x887A
+#define GL_READ_PIXEL_DATA_RANGE_LENGTH_NV 0x887B
+#define GL_WRITE_PIXEL_DATA_RANGE_POINTER_NV 0x887C
+#define GL_READ_PIXEL_DATA_RANGE_POINTER_NV 0x887D
+typedef void (APIENTRYP PFNGLPIXELDATARANGENVPROC) (GLenum target, GLsizei length, const void *pointer);
+typedef void (APIENTRYP PFNGLFLUSHPIXELDATARANGENVPROC) (GLenum target);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPixelDataRangeNV (GLenum target, GLsizei length, const void *pointer);
+GLAPI void APIENTRY glFlushPixelDataRangeNV (GLenum target);
+#endif
+#endif /* GL_NV_pixel_data_range */
+
+#ifndef GL_NV_point_sprite
+#define GL_NV_point_sprite 1
+#define GL_POINT_SPRITE_NV 0x8861
+#define GL_COORD_REPLACE_NV 0x8862
+#define GL_POINT_SPRITE_R_MODE_NV 0x8863
+typedef void (APIENTRYP PFNGLPOINTPARAMETERINVPROC) (GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLPOINTPARAMETERIVNVPROC) (GLenum pname, const GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPointParameteriNV (GLenum pname, GLint param);
+GLAPI void APIENTRY glPointParameterivNV (GLenum pname, const GLint *params);
+#endif
+#endif /* GL_NV_point_sprite */
+
+#ifndef GL_NV_present_video
+#define GL_NV_present_video 1
+#define GL_FRAME_NV 0x8E26
+#define GL_FIELDS_NV 0x8E27
+#define GL_CURRENT_TIME_NV 0x8E28
+#define GL_NUM_FILL_STREAMS_NV 0x8E29
+#define GL_PRESENT_TIME_NV 0x8E2A
+#define GL_PRESENT_DURATION_NV 0x8E2B
+typedef void (APIENTRYP PFNGLPRESENTFRAMEKEYEDNVPROC) (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLuint key0, GLenum target1, GLuint fill1, GLuint key1);
+typedef void (APIENTRYP PFNGLPRESENTFRAMEDUALFILLNVPROC) (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLenum target1, GLuint fill1, GLenum target2, GLuint fill2, GLenum target3, GLuint fill3);
+typedef void (APIENTRYP PFNGLGETVIDEOIVNVPROC) (GLuint video_slot, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETVIDEOUIVNVPROC) (GLuint video_slot, GLenum pname, GLuint *params);
+typedef void (APIENTRYP PFNGLGETVIDEOI64VNVPROC) (GLuint video_slot, GLenum pname, GLint64EXT *params);
+typedef void (APIENTRYP PFNGLGETVIDEOUI64VNVPROC) (GLuint video_slot, GLenum pname, GLuint64EXT *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPresentFrameKeyedNV (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLuint key0, GLenum target1, GLuint fill1, GLuint key1);
+GLAPI void APIENTRY glPresentFrameDualFillNV (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLenum target1, GLuint fill1, GLenum target2, GLuint fill2, GLenum target3, GLuint fill3);
+GLAPI void APIENTRY glGetVideoivNV (GLuint video_slot, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetVideouivNV (GLuint video_slot, GLenum pname, GLuint *params);
+GLAPI void APIENTRY glGetVideoi64vNV (GLuint video_slot, GLenum pname, GLint64EXT *params);
+GLAPI void APIENTRY glGetVideoui64vNV (GLuint video_slot, GLenum pname, GLuint64EXT *params);
+#endif
+#endif /* GL_NV_present_video */
+
+#ifndef GL_NV_primitive_restart
+#define GL_NV_primitive_restart 1
+#define GL_PRIMITIVE_RESTART_NV 0x8558
+#define GL_PRIMITIVE_RESTART_INDEX_NV 0x8559
+typedef void (APIENTRYP PFNGLPRIMITIVERESTARTNVPROC) (void);
+typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXNVPROC) (GLuint index);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPrimitiveRestartNV (void);
+GLAPI void APIENTRY glPrimitiveRestartIndexNV (GLuint index);
+#endif
+#endif /* GL_NV_primitive_restart */
+
+#ifndef GL_NV_register_combiners
+#define GL_NV_register_combiners 1
+#define GL_REGISTER_COMBINERS_NV 0x8522
+#define GL_VARIABLE_A_NV 0x8523
+#define GL_VARIABLE_B_NV 0x8524
+#define GL_VARIABLE_C_NV 0x8525
+#define GL_VARIABLE_D_NV 0x8526
+#define GL_VARIABLE_E_NV 0x8527
+#define GL_VARIABLE_F_NV 0x8528
+#define GL_VARIABLE_G_NV 0x8529
+#define GL_CONSTANT_COLOR0_NV 0x852A
+#define GL_CONSTANT_COLOR1_NV 0x852B
+#define GL_SPARE0_NV 0x852E
+#define GL_SPARE1_NV 0x852F
+#define GL_DISCARD_NV 0x8530
+#define GL_E_TIMES_F_NV 0x8531
+#define GL_SPARE0_PLUS_SECONDARY_COLOR_NV 0x8532
+#define GL_UNSIGNED_IDENTITY_NV 0x8536
+#define GL_UNSIGNED_INVERT_NV 0x8537
+#define GL_EXPAND_NORMAL_NV 0x8538
+#define GL_EXPAND_NEGATE_NV 0x8539
+#define GL_HALF_BIAS_NORMAL_NV 0x853A
+#define GL_HALF_BIAS_NEGATE_NV 0x853B
+#define GL_SIGNED_IDENTITY_NV 0x853C
+#define GL_SIGNED_NEGATE_NV 0x853D
+#define GL_SCALE_BY_TWO_NV 0x853E
+#define GL_SCALE_BY_FOUR_NV 0x853F
+#define GL_SCALE_BY_ONE_HALF_NV 0x8540
+#define GL_BIAS_BY_NEGATIVE_ONE_HALF_NV 0x8541
+#define GL_COMBINER_INPUT_NV 0x8542
+#define GL_COMBINER_MAPPING_NV 0x8543
+#define GL_COMBINER_COMPONENT_USAGE_NV 0x8544
+#define GL_COMBINER_AB_DOT_PRODUCT_NV 0x8545
+#define GL_COMBINER_CD_DOT_PRODUCT_NV 0x8546
+#define GL_COMBINER_MUX_SUM_NV 0x8547
+#define GL_COMBINER_SCALE_NV 0x8548
+#define GL_COMBINER_BIAS_NV 0x8549
+#define GL_COMBINER_AB_OUTPUT_NV 0x854A
+#define GL_COMBINER_CD_OUTPUT_NV 0x854B
+#define GL_COMBINER_SUM_OUTPUT_NV 0x854C
+#define GL_MAX_GENERAL_COMBINERS_NV 0x854D
+#define GL_NUM_GENERAL_COMBINERS_NV 0x854E
+#define GL_COLOR_SUM_CLAMP_NV 0x854F
+#define GL_COMBINER0_NV 0x8550
+#define GL_COMBINER1_NV 0x8551
+#define GL_COMBINER2_NV 0x8552
+#define GL_COMBINER3_NV 0x8553
+#define GL_COMBINER4_NV 0x8554
+#define GL_COMBINER5_NV 0x8555
+#define GL_COMBINER6_NV 0x8556
+#define GL_COMBINER7_NV 0x8557
+typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFVNVPROC) (GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFNVPROC) (GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLCOMBINERPARAMETERIVNVPROC) (GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLCOMBINERPARAMETERINVPROC) (GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLCOMBINERINPUTNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage);
+typedef void (APIENTRYP PFNGLCOMBINEROUTPUTNVPROC) (GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum);
+typedef void (APIENTRYP PFNGLFINALCOMBINERINPUTNVPROC) (GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage);
+typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERFVNVPROC) (GLenum variable, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERIVNVPROC) (GLenum variable, GLenum pname, GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glCombinerParameterfvNV (GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glCombinerParameterfNV (GLenum pname, GLfloat param);
+GLAPI void APIENTRY glCombinerParameterivNV (GLenum pname, const GLint *params);
+GLAPI void APIENTRY glCombinerParameteriNV (GLenum pname, GLint param);
+GLAPI void APIENTRY glCombinerInputNV (GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage);
+GLAPI void APIENTRY glCombinerOutputNV (GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum);
+GLAPI void APIENTRY glFinalCombinerInputNV (GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage);
+GLAPI void APIENTRY glGetCombinerInputParameterfvNV (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetCombinerInputParameterivNV (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetCombinerOutputParameterfvNV (GLenum stage, GLenum portion, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetCombinerOutputParameterivNV (GLenum stage, GLenum portion, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetFinalCombinerInputParameterfvNV (GLenum variable, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetFinalCombinerInputParameterivNV (GLenum variable, GLenum pname, GLint *params);
+#endif
+#endif /* GL_NV_register_combiners */
+
+#ifndef GL_NV_register_combiners2
+#define GL_NV_register_combiners2 1
+#define GL_PER_STAGE_CONSTANTS_NV 0x8535
+typedef void (APIENTRYP PFNGLCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLGETCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glCombinerStageParameterfvNV (GLenum stage, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glGetCombinerStageParameterfvNV (GLenum stage, GLenum pname, GLfloat *params);
+#endif
+#endif /* GL_NV_register_combiners2 */
+
+#ifndef GL_NV_shader_atomic_counters
+#define GL_NV_shader_atomic_counters 1
+#endif /* GL_NV_shader_atomic_counters */
+
+#ifndef GL_NV_shader_atomic_float
+#define GL_NV_shader_atomic_float 1
+#endif /* GL_NV_shader_atomic_float */
+
+#ifndef GL_NV_shader_buffer_load
+#define GL_NV_shader_buffer_load 1
+#define GL_BUFFER_GPU_ADDRESS_NV 0x8F1D
+#define GL_GPU_ADDRESS_NV 0x8F34
+#define GL_MAX_SHADER_BUFFER_ADDRESS_NV 0x8F35
+typedef void (APIENTRYP PFNGLMAKEBUFFERRESIDENTNVPROC) (GLenum target, GLenum access);
+typedef void (APIENTRYP PFNGLMAKEBUFFERNONRESIDENTNVPROC) (GLenum target);
+typedef GLboolean (APIENTRYP PFNGLISBUFFERRESIDENTNVPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLMAKENAMEDBUFFERRESIDENTNVPROC) (GLuint buffer, GLenum access);
+typedef void (APIENTRYP PFNGLMAKENAMEDBUFFERNONRESIDENTNVPROC) (GLuint buffer);
+typedef GLboolean (APIENTRYP PFNGLISNAMEDBUFFERRESIDENTNVPROC) (GLuint buffer);
+typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERUI64VNVPROC) (GLenum target, GLenum pname, GLuint64EXT *params);
+typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPARAMETERUI64VNVPROC) (GLuint buffer, GLenum pname, GLuint64EXT *params);
+typedef void (APIENTRYP PFNGLGETINTEGERUI64VNVPROC) (GLenum value, GLuint64EXT *result);
+typedef void (APIENTRYP PFNGLUNIFORMUI64NVPROC) (GLint location, GLuint64EXT value);
+typedef void (APIENTRYP PFNGLUNIFORMUI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMUI64NVPROC) (GLuint program, GLint location, GLuint64EXT value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMUI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMakeBufferResidentNV (GLenum target, GLenum access);
+GLAPI void APIENTRY glMakeBufferNonResidentNV (GLenum target);
+GLAPI GLboolean APIENTRY glIsBufferResidentNV (GLenum target);
+GLAPI void APIENTRY glMakeNamedBufferResidentNV (GLuint buffer, GLenum access);
+GLAPI void APIENTRY glMakeNamedBufferNonResidentNV (GLuint buffer);
+GLAPI GLboolean APIENTRY glIsNamedBufferResidentNV (GLuint buffer);
+GLAPI void APIENTRY glGetBufferParameterui64vNV (GLenum target, GLenum pname, GLuint64EXT *params);
+GLAPI void APIENTRY glGetNamedBufferParameterui64vNV (GLuint buffer, GLenum pname, GLuint64EXT *params);
+GLAPI void APIENTRY glGetIntegerui64vNV (GLenum value, GLuint64EXT *result);
+GLAPI void APIENTRY glUniformui64NV (GLint location, GLuint64EXT value);
+GLAPI void APIENTRY glUniformui64vNV (GLint location, GLsizei count, const GLuint64EXT *value);
+GLAPI void APIENTRY glProgramUniformui64NV (GLuint program, GLint location, GLuint64EXT value);
+GLAPI void APIENTRY glProgramUniformui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+#endif
+#endif /* GL_NV_shader_buffer_load */
+
+#ifndef GL_NV_shader_buffer_store
+#define GL_NV_shader_buffer_store 1
+#define GL_SHADER_GLOBAL_ACCESS_BARRIER_BIT_NV 0x00000010
+#endif /* GL_NV_shader_buffer_store */
+
+#ifndef GL_NV_shader_storage_buffer_object
+#define GL_NV_shader_storage_buffer_object 1
+#endif /* GL_NV_shader_storage_buffer_object */
+
+#ifndef GL_NV_shader_thread_group
+#define GL_NV_shader_thread_group 1
+#define GL_WARP_SIZE_NV 0x9339
+#define GL_WARPS_PER_SM_NV 0x933A
+#define GL_SM_COUNT_NV 0x933B
+#endif /* GL_NV_shader_thread_group */
+
+#ifndef GL_NV_shader_thread_shuffle
+#define GL_NV_shader_thread_shuffle 1
+#endif /* GL_NV_shader_thread_shuffle */
+
+#ifndef GL_NV_tessellation_program5
+#define GL_NV_tessellation_program5 1
+#define GL_MAX_PROGRAM_PATCH_ATTRIBS_NV 0x86D8
+#define GL_TESS_CONTROL_PROGRAM_NV 0x891E
+#define GL_TESS_EVALUATION_PROGRAM_NV 0x891F
+#define GL_TESS_CONTROL_PROGRAM_PARAMETER_BUFFER_NV 0x8C74
+#define GL_TESS_EVALUATION_PROGRAM_PARAMETER_BUFFER_NV 0x8C75
+#endif /* GL_NV_tessellation_program5 */
+
+#ifndef GL_NV_texgen_emboss
+#define GL_NV_texgen_emboss 1
+#define GL_EMBOSS_LIGHT_NV 0x855D
+#define GL_EMBOSS_CONSTANT_NV 0x855E
+#define GL_EMBOSS_MAP_NV 0x855F
+#endif /* GL_NV_texgen_emboss */
+
+#ifndef GL_NV_texgen_reflection
+#define GL_NV_texgen_reflection 1
+#define GL_NORMAL_MAP_NV 0x8511
+#define GL_REFLECTION_MAP_NV 0x8512
+#endif /* GL_NV_texgen_reflection */
+
+#ifndef GL_NV_texture_barrier
+#define GL_NV_texture_barrier 1
+typedef void (APIENTRYP PFNGLTEXTUREBARRIERNVPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTextureBarrierNV (void);
+#endif
+#endif /* GL_NV_texture_barrier */
+
+#ifndef GL_NV_texture_compression_vtc
+#define GL_NV_texture_compression_vtc 1
+#endif /* GL_NV_texture_compression_vtc */
+
+#ifndef GL_NV_texture_env_combine4
+#define GL_NV_texture_env_combine4 1
+#define GL_COMBINE4_NV 0x8503
+#define GL_SOURCE3_RGB_NV 0x8583
+#define GL_SOURCE3_ALPHA_NV 0x858B
+#define GL_OPERAND3_RGB_NV 0x8593
+#define GL_OPERAND3_ALPHA_NV 0x859B
+#endif /* GL_NV_texture_env_combine4 */
+
+#ifndef GL_NV_texture_expand_normal
+#define GL_NV_texture_expand_normal 1
+#define GL_TEXTURE_UNSIGNED_REMAP_MODE_NV 0x888F
+#endif /* GL_NV_texture_expand_normal */
+
+#ifndef GL_NV_texture_multisample
+#define GL_NV_texture_multisample 1
+#define GL_TEXTURE_COVERAGE_SAMPLES_NV 0x9045
+#define GL_TEXTURE_COLOR_SAMPLES_NV 0x9046
+typedef void (APIENTRYP PFNGLTEXIMAGE2DMULTISAMPLECOVERAGENVPROC) (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations);
+typedef void (APIENTRYP PFNGLTEXIMAGE3DMULTISAMPLECOVERAGENVPROC) (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations);
+typedef void (APIENTRYP PFNGLTEXTUREIMAGE2DMULTISAMPLENVPROC) (GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations);
+typedef void (APIENTRYP PFNGLTEXTUREIMAGE3DMULTISAMPLENVPROC) (GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations);
+typedef void (APIENTRYP PFNGLTEXTUREIMAGE2DMULTISAMPLECOVERAGENVPROC) (GLuint texture, GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations);
+typedef void (APIENTRYP PFNGLTEXTUREIMAGE3DMULTISAMPLECOVERAGENVPROC) (GLuint texture, GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexImage2DMultisampleCoverageNV (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations);
+GLAPI void APIENTRY glTexImage3DMultisampleCoverageNV (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations);
+GLAPI void APIENTRY glTextureImage2DMultisampleNV (GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations);
+GLAPI void APIENTRY glTextureImage3DMultisampleNV (GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations);
+GLAPI void APIENTRY glTextureImage2DMultisampleCoverageNV (GLuint texture, GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations);
+GLAPI void APIENTRY glTextureImage3DMultisampleCoverageNV (GLuint texture, GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations);
+#endif
+#endif /* GL_NV_texture_multisample */
+
+#ifndef GL_NV_texture_rectangle
+#define GL_NV_texture_rectangle 1
+#define GL_TEXTURE_RECTANGLE_NV 0x84F5
+#define GL_TEXTURE_BINDING_RECTANGLE_NV 0x84F6
+#define GL_PROXY_TEXTURE_RECTANGLE_NV 0x84F7
+#define GL_MAX_RECTANGLE_TEXTURE_SIZE_NV 0x84F8
+#endif /* GL_NV_texture_rectangle */
+
+#ifndef GL_NV_texture_shader
+#define GL_NV_texture_shader 1
+#define GL_OFFSET_TEXTURE_RECTANGLE_NV 0x864C
+#define GL_OFFSET_TEXTURE_RECTANGLE_SCALE_NV 0x864D
+#define GL_DOT_PRODUCT_TEXTURE_RECTANGLE_NV 0x864E
+#define GL_RGBA_UNSIGNED_DOT_PRODUCT_MAPPING_NV 0x86D9
+#define GL_UNSIGNED_INT_S8_S8_8_8_NV 0x86DA
+#define GL_UNSIGNED_INT_8_8_S8_S8_REV_NV 0x86DB
+#define GL_DSDT_MAG_INTENSITY_NV 0x86DC
+#define GL_SHADER_CONSISTENT_NV 0x86DD
+#define GL_TEXTURE_SHADER_NV 0x86DE
+#define GL_SHADER_OPERATION_NV 0x86DF
+#define GL_CULL_MODES_NV 0x86E0
+#define GL_OFFSET_TEXTURE_MATRIX_NV 0x86E1
+#define GL_OFFSET_TEXTURE_SCALE_NV 0x86E2
+#define GL_OFFSET_TEXTURE_BIAS_NV 0x86E3
+#define GL_OFFSET_TEXTURE_2D_MATRIX_NV 0x86E1
+#define GL_OFFSET_TEXTURE_2D_SCALE_NV 0x86E2
+#define GL_OFFSET_TEXTURE_2D_BIAS_NV 0x86E3
+#define GL_PREVIOUS_TEXTURE_INPUT_NV 0x86E4
+#define GL_CONST_EYE_NV 0x86E5
+#define GL_PASS_THROUGH_NV 0x86E6
+#define GL_CULL_FRAGMENT_NV 0x86E7
+#define GL_OFFSET_TEXTURE_2D_NV 0x86E8
+#define GL_DEPENDENT_AR_TEXTURE_2D_NV 0x86E9
+#define GL_DEPENDENT_GB_TEXTURE_2D_NV 0x86EA
+#define GL_DOT_PRODUCT_NV 0x86EC
+#define GL_DOT_PRODUCT_DEPTH_REPLACE_NV 0x86ED
+#define GL_DOT_PRODUCT_TEXTURE_2D_NV 0x86EE
+#define GL_DOT_PRODUCT_TEXTURE_CUBE_MAP_NV 0x86F0
+#define GL_DOT_PRODUCT_DIFFUSE_CUBE_MAP_NV 0x86F1
+#define GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV 0x86F2
+#define GL_DOT_PRODUCT_CONST_EYE_REFLECT_CUBE_MAP_NV 0x86F3
+#define GL_HILO_NV 0x86F4
+#define GL_DSDT_NV 0x86F5
+#define GL_DSDT_MAG_NV 0x86F6
+#define GL_DSDT_MAG_VIB_NV 0x86F7
+#define GL_HILO16_NV 0x86F8
+#define GL_SIGNED_HILO_NV 0x86F9
+#define GL_SIGNED_HILO16_NV 0x86FA
+#define GL_SIGNED_RGBA_NV 0x86FB
+#define GL_SIGNED_RGBA8_NV 0x86FC
+#define GL_SIGNED_RGB_NV 0x86FE
+#define GL_SIGNED_RGB8_NV 0x86FF
+#define GL_SIGNED_LUMINANCE_NV 0x8701
+#define GL_SIGNED_LUMINANCE8_NV 0x8702
+#define GL_SIGNED_LUMINANCE_ALPHA_NV 0x8703
+#define GL_SIGNED_LUMINANCE8_ALPHA8_NV 0x8704
+#define GL_SIGNED_ALPHA_NV 0x8705
+#define GL_SIGNED_ALPHA8_NV 0x8706
+#define GL_SIGNED_INTENSITY_NV 0x8707
+#define GL_SIGNED_INTENSITY8_NV 0x8708
+#define GL_DSDT8_NV 0x8709
+#define GL_DSDT8_MAG8_NV 0x870A
+#define GL_DSDT8_MAG8_INTENSITY8_NV 0x870B
+#define GL_SIGNED_RGB_UNSIGNED_ALPHA_NV 0x870C
+#define GL_SIGNED_RGB8_UNSIGNED_ALPHA8_NV 0x870D
+#define GL_HI_SCALE_NV 0x870E
+#define GL_LO_SCALE_NV 0x870F
+#define GL_DS_SCALE_NV 0x8710
+#define GL_DT_SCALE_NV 0x8711
+#define GL_MAGNITUDE_SCALE_NV 0x8712
+#define GL_VIBRANCE_SCALE_NV 0x8713
+#define GL_HI_BIAS_NV 0x8714
+#define GL_LO_BIAS_NV 0x8715
+#define GL_DS_BIAS_NV 0x8716
+#define GL_DT_BIAS_NV 0x8717
+#define GL_MAGNITUDE_BIAS_NV 0x8718
+#define GL_VIBRANCE_BIAS_NV 0x8719
+#define GL_TEXTURE_BORDER_VALUES_NV 0x871A
+#define GL_TEXTURE_HI_SIZE_NV 0x871B
+#define GL_TEXTURE_LO_SIZE_NV 0x871C
+#define GL_TEXTURE_DS_SIZE_NV 0x871D
+#define GL_TEXTURE_DT_SIZE_NV 0x871E
+#define GL_TEXTURE_MAG_SIZE_NV 0x871F
+#endif /* GL_NV_texture_shader */
+
+#ifndef GL_NV_texture_shader2
+#define GL_NV_texture_shader2 1
+#define GL_DOT_PRODUCT_TEXTURE_3D_NV 0x86EF
+#endif /* GL_NV_texture_shader2 */
+
+#ifndef GL_NV_texture_shader3
+#define GL_NV_texture_shader3 1
+#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_NV 0x8850
+#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_SCALE_NV 0x8851
+#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8852
+#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_SCALE_NV 0x8853
+#define GL_OFFSET_HILO_TEXTURE_2D_NV 0x8854
+#define GL_OFFSET_HILO_TEXTURE_RECTANGLE_NV 0x8855
+#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_2D_NV 0x8856
+#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8857
+#define GL_DEPENDENT_HILO_TEXTURE_2D_NV 0x8858
+#define GL_DEPENDENT_RGB_TEXTURE_3D_NV 0x8859
+#define GL_DEPENDENT_RGB_TEXTURE_CUBE_MAP_NV 0x885A
+#define GL_DOT_PRODUCT_PASS_THROUGH_NV 0x885B
+#define GL_DOT_PRODUCT_TEXTURE_1D_NV 0x885C
+#define GL_DOT_PRODUCT_AFFINE_DEPTH_REPLACE_NV 0x885D
+#define GL_HILO8_NV 0x885E
+#define GL_SIGNED_HILO8_NV 0x885F
+#define GL_FORCE_BLUE_TO_ONE_NV 0x8860
+#endif /* GL_NV_texture_shader3 */
+
+#ifndef GL_NV_transform_feedback
+#define GL_NV_transform_feedback 1
+#define GL_BACK_PRIMARY_COLOR_NV 0x8C77
+#define GL_BACK_SECONDARY_COLOR_NV 0x8C78
+#define GL_TEXTURE_COORD_NV 0x8C79
+#define GL_CLIP_DISTANCE_NV 0x8C7A
+#define GL_VERTEX_ID_NV 0x8C7B
+#define GL_PRIMITIVE_ID_NV 0x8C7C
+#define GL_GENERIC_ATTRIB_NV 0x8C7D
+#define GL_TRANSFORM_FEEDBACK_ATTRIBS_NV 0x8C7E
+#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE_NV 0x8C7F
+#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_NV 0x8C80
+#define GL_ACTIVE_VARYINGS_NV 0x8C81
+#define GL_ACTIVE_VARYING_MAX_LENGTH_NV 0x8C82
+#define GL_TRANSFORM_FEEDBACK_VARYINGS_NV 0x8C83
+#define GL_TRANSFORM_FEEDBACK_BUFFER_START_NV 0x8C84
+#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE_NV 0x8C85
+#define GL_TRANSFORM_FEEDBACK_RECORD_NV 0x8C86
+#define GL_PRIMITIVES_GENERATED_NV 0x8C87
+#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_NV 0x8C88
+#define GL_RASTERIZER_DISCARD_NV 0x8C89
+#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_NV 0x8C8A
+#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_NV 0x8C8B
+#define GL_INTERLEAVED_ATTRIBS_NV 0x8C8C
+#define GL_SEPARATE_ATTRIBS_NV 0x8C8D
+#define GL_TRANSFORM_FEEDBACK_BUFFER_NV 0x8C8E
+#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING_NV 0x8C8F
+#define GL_LAYER_NV 0x8DAA
+#define GL_NEXT_BUFFER_NV -2
+#define GL_SKIP_COMPONENTS4_NV -3
+#define GL_SKIP_COMPONENTS3_NV -4
+#define GL_SKIP_COMPONENTS2_NV -5
+#define GL_SKIP_COMPONENTS1_NV -6
+typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKNVPROC) (GLenum primitiveMode);
+typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKNVPROC) (void);
+typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKATTRIBSNVPROC) (GLuint count, const GLint *attribs, GLenum bufferMode);
+typedef void (APIENTRYP PFNGLBINDBUFFERRANGENVPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size);
+typedef void (APIENTRYP PFNGLBINDBUFFEROFFSETNVPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset);
+typedef void (APIENTRYP PFNGLBINDBUFFERBASENVPROC) (GLenum target, GLuint index, GLuint buffer);
+typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSNVPROC) (GLuint program, GLsizei count, const GLint *locations, GLenum bufferMode);
+typedef void (APIENTRYP PFNGLACTIVEVARYINGNVPROC) (GLuint program, const GLchar *name);
+typedef GLint (APIENTRYP PFNGLGETVARYINGLOCATIONNVPROC) (GLuint program, const GLchar *name);
+typedef void (APIENTRYP PFNGLGETACTIVEVARYINGNVPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name);
+typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGNVPROC) (GLuint program, GLuint index, GLint *location);
+typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKSTREAMATTRIBSNVPROC) (GLsizei count, const GLint *attribs, GLsizei nbuffers, const GLint *bufstreams, GLenum bufferMode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBeginTransformFeedbackNV (GLenum primitiveMode);
+GLAPI void APIENTRY glEndTransformFeedbackNV (void);
+GLAPI void APIENTRY glTransformFeedbackAttribsNV (GLuint count, const GLint *attribs, GLenum bufferMode);
+GLAPI void APIENTRY glBindBufferRangeNV (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size);
+GLAPI void APIENTRY glBindBufferOffsetNV (GLenum target, GLuint index, GLuint buffer, GLintptr offset);
+GLAPI void APIENTRY glBindBufferBaseNV (GLenum target, GLuint index, GLuint buffer);
+GLAPI void APIENTRY glTransformFeedbackVaryingsNV (GLuint program, GLsizei count, const GLint *locations, GLenum bufferMode);
+GLAPI void APIENTRY glActiveVaryingNV (GLuint program, const GLchar *name);
+GLAPI GLint APIENTRY glGetVaryingLocationNV (GLuint program, const GLchar *name);
+GLAPI void APIENTRY glGetActiveVaryingNV (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name);
+GLAPI void APIENTRY glGetTransformFeedbackVaryingNV (GLuint program, GLuint index, GLint *location);
+GLAPI void APIENTRY glTransformFeedbackStreamAttribsNV (GLsizei count, const GLint *attribs, GLsizei nbuffers, const GLint *bufstreams, GLenum bufferMode);
+#endif
+#endif /* GL_NV_transform_feedback */
+
+#ifndef GL_NV_transform_feedback2
+#define GL_NV_transform_feedback2 1
+#define GL_TRANSFORM_FEEDBACK_NV 0x8E22
+#define GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED_NV 0x8E23
+#define GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE_NV 0x8E24
+#define GL_TRANSFORM_FEEDBACK_BINDING_NV 0x8E25
+typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKNVPROC) (GLenum target, GLuint id);
+typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSNVPROC) (GLsizei n, const GLuint *ids);
+typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSNVPROC) (GLsizei n, GLuint *ids);
+typedef GLboolean (APIENTRYP PFNGLISTRANSFORMFEEDBACKNVPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLPAUSETRANSFORMFEEDBACKNVPROC) (void);
+typedef void (APIENTRYP PFNGLRESUMETRANSFORMFEEDBACKNVPROC) (void);
+typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKNVPROC) (GLenum mode, GLuint id);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBindTransformFeedbackNV (GLenum target, GLuint id);
+GLAPI void APIENTRY glDeleteTransformFeedbacksNV (GLsizei n, const GLuint *ids);
+GLAPI void APIENTRY glGenTransformFeedbacksNV (GLsizei n, GLuint *ids);
+GLAPI GLboolean APIENTRY glIsTransformFeedbackNV (GLuint id);
+GLAPI void APIENTRY glPauseTransformFeedbackNV (void);
+GLAPI void APIENTRY glResumeTransformFeedbackNV (void);
+GLAPI void APIENTRY glDrawTransformFeedbackNV (GLenum mode, GLuint id);
+#endif
+#endif /* GL_NV_transform_feedback2 */
+
+#ifndef GL_NV_vdpau_interop
+#define GL_NV_vdpau_interop 1
+typedef GLintptr GLvdpauSurfaceNV;
+#define GL_SURFACE_STATE_NV 0x86EB
+#define GL_SURFACE_REGISTERED_NV 0x86FD
+#define GL_SURFACE_MAPPED_NV 0x8700
+#define GL_WRITE_DISCARD_NV 0x88BE
+typedef void (APIENTRYP PFNGLVDPAUINITNVPROC) (const void *vdpDevice, const void *getProcAddress);
+typedef void (APIENTRYP PFNGLVDPAUFININVPROC) (void);
+typedef GLvdpauSurfaceNV (APIENTRYP PFNGLVDPAUREGISTERVIDEOSURFACENVPROC) (const void *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames);
+typedef GLvdpauSurfaceNV (APIENTRYP PFNGLVDPAUREGISTEROUTPUTSURFACENVPROC) (const void *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames);
+typedef GLboolean (APIENTRYP PFNGLVDPAUISSURFACENVPROC) (GLvdpauSurfaceNV surface);
+typedef void (APIENTRYP PFNGLVDPAUUNREGISTERSURFACENVPROC) (GLvdpauSurfaceNV surface);
+typedef void (APIENTRYP PFNGLVDPAUGETSURFACEIVNVPROC) (GLvdpauSurfaceNV surface, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values);
+typedef void (APIENTRYP PFNGLVDPAUSURFACEACCESSNVPROC) (GLvdpauSurfaceNV surface, GLenum access);
+typedef void (APIENTRYP PFNGLVDPAUMAPSURFACESNVPROC) (GLsizei numSurfaces, const GLvdpauSurfaceNV *surfaces);
+typedef void (APIENTRYP PFNGLVDPAUUNMAPSURFACESNVPROC) (GLsizei numSurface, const GLvdpauSurfaceNV *surfaces);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVDPAUInitNV (const void *vdpDevice, const void *getProcAddress);
+GLAPI void APIENTRY glVDPAUFiniNV (void);
+GLAPI GLvdpauSurfaceNV APIENTRY glVDPAURegisterVideoSurfaceNV (const void *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames);
+GLAPI GLvdpauSurfaceNV APIENTRY glVDPAURegisterOutputSurfaceNV (const void *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames);
+GLAPI GLboolean APIENTRY glVDPAUIsSurfaceNV (GLvdpauSurfaceNV surface);
+GLAPI void APIENTRY glVDPAUUnregisterSurfaceNV (GLvdpauSurfaceNV surface);
+GLAPI void APIENTRY glVDPAUGetSurfaceivNV (GLvdpauSurfaceNV surface, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values);
+GLAPI void APIENTRY glVDPAUSurfaceAccessNV (GLvdpauSurfaceNV surface, GLenum access);
+GLAPI void APIENTRY glVDPAUMapSurfacesNV (GLsizei numSurfaces, const GLvdpauSurfaceNV *surfaces);
+GLAPI void APIENTRY glVDPAUUnmapSurfacesNV (GLsizei numSurface, const GLvdpauSurfaceNV *surfaces);
+#endif
+#endif /* GL_NV_vdpau_interop */
+
+#ifndef GL_NV_vertex_array_range
+#define GL_NV_vertex_array_range 1
+#define GL_VERTEX_ARRAY_RANGE_NV 0x851D
+#define GL_VERTEX_ARRAY_RANGE_LENGTH_NV 0x851E
+#define GL_VERTEX_ARRAY_RANGE_VALID_NV 0x851F
+#define GL_MAX_VERTEX_ARRAY_RANGE_ELEMENT_NV 0x8520
+#define GL_VERTEX_ARRAY_RANGE_POINTER_NV 0x8521
+typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGENVPROC) (void);
+typedef void (APIENTRYP PFNGLVERTEXARRAYRANGENVPROC) (GLsizei length, const void *pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glFlushVertexArrayRangeNV (void);
+GLAPI void APIENTRY glVertexArrayRangeNV (GLsizei length, const void *pointer);
+#endif
+#endif /* GL_NV_vertex_array_range */
+
+#ifndef GL_NV_vertex_array_range2
+#define GL_NV_vertex_array_range2 1
+#define GL_VERTEX_ARRAY_RANGE_WITHOUT_FLUSH_NV 0x8533
+#endif /* GL_NV_vertex_array_range2 */
+
+#ifndef GL_NV_vertex_attrib_integer_64bit
+#define GL_NV_vertex_attrib_integer_64bit 1
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1I64NVPROC) (GLuint index, GLint64EXT x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL2I64NVPROC) (GLuint index, GLint64EXT x, GLint64EXT y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL3I64NVPROC) (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL4I64NVPROC) (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1I64VNVPROC) (GLuint index, const GLint64EXT *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL2I64VNVPROC) (GLuint index, const GLint64EXT *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL3I64VNVPROC) (GLuint index, const GLint64EXT *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL4I64VNVPROC) (GLuint index, const GLint64EXT *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64NVPROC) (GLuint index, GLuint64EXT x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL2UI64NVPROC) (GLuint index, GLuint64EXT x, GLuint64EXT y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL3UI64NVPROC) (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL4UI64NVPROC) (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64VNVPROC) (GLuint index, const GLuint64EXT *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL2UI64VNVPROC) (GLuint index, const GLuint64EXT *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL3UI64VNVPROC) (GLuint index, const GLuint64EXT *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL4UI64VNVPROC) (GLuint index, const GLuint64EXT *v);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLI64VNVPROC) (GLuint index, GLenum pname, GLint64EXT *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLUI64VNVPROC) (GLuint index, GLenum pname, GLuint64EXT *params);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBLFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLsizei stride);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexAttribL1i64NV (GLuint index, GLint64EXT x);
+GLAPI void APIENTRY glVertexAttribL2i64NV (GLuint index, GLint64EXT x, GLint64EXT y);
+GLAPI void APIENTRY glVertexAttribL3i64NV (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z);
+GLAPI void APIENTRY glVertexAttribL4i64NV (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
+GLAPI void APIENTRY glVertexAttribL1i64vNV (GLuint index, const GLint64EXT *v);
+GLAPI void APIENTRY glVertexAttribL2i64vNV (GLuint index, const GLint64EXT *v);
+GLAPI void APIENTRY glVertexAttribL3i64vNV (GLuint index, const GLint64EXT *v);
+GLAPI void APIENTRY glVertexAttribL4i64vNV (GLuint index, const GLint64EXT *v);
+GLAPI void APIENTRY glVertexAttribL1ui64NV (GLuint index, GLuint64EXT x);
+GLAPI void APIENTRY glVertexAttribL2ui64NV (GLuint index, GLuint64EXT x, GLuint64EXT y);
+GLAPI void APIENTRY glVertexAttribL3ui64NV (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
+GLAPI void APIENTRY glVertexAttribL4ui64NV (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
+GLAPI void APIENTRY glVertexAttribL1ui64vNV (GLuint index, const GLuint64EXT *v);
+GLAPI void APIENTRY glVertexAttribL2ui64vNV (GLuint index, const GLuint64EXT *v);
+GLAPI void APIENTRY glVertexAttribL3ui64vNV (GLuint index, const GLuint64EXT *v);
+GLAPI void APIENTRY glVertexAttribL4ui64vNV (GLuint index, const GLuint64EXT *v);
+GLAPI void APIENTRY glGetVertexAttribLi64vNV (GLuint index, GLenum pname, GLint64EXT *params);
+GLAPI void APIENTRY glGetVertexAttribLui64vNV (GLuint index, GLenum pname, GLuint64EXT *params);
+GLAPI void APIENTRY glVertexAttribLFormatNV (GLuint index, GLint size, GLenum type, GLsizei stride);
+#endif
+#endif /* GL_NV_vertex_attrib_integer_64bit */
+
+#ifndef GL_NV_vertex_buffer_unified_memory
+#define GL_NV_vertex_buffer_unified_memory 1
+#define GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV 0x8F1E
+#define GL_ELEMENT_ARRAY_UNIFIED_NV 0x8F1F
+#define GL_VERTEX_ATTRIB_ARRAY_ADDRESS_NV 0x8F20
+#define GL_VERTEX_ARRAY_ADDRESS_NV 0x8F21
+#define GL_NORMAL_ARRAY_ADDRESS_NV 0x8F22
+#define GL_COLOR_ARRAY_ADDRESS_NV 0x8F23
+#define GL_INDEX_ARRAY_ADDRESS_NV 0x8F24
+#define GL_TEXTURE_COORD_ARRAY_ADDRESS_NV 0x8F25
+#define GL_EDGE_FLAG_ARRAY_ADDRESS_NV 0x8F26
+#define GL_SECONDARY_COLOR_ARRAY_ADDRESS_NV 0x8F27
+#define GL_FOG_COORD_ARRAY_ADDRESS_NV 0x8F28
+#define GL_ELEMENT_ARRAY_ADDRESS_NV 0x8F29
+#define GL_VERTEX_ATTRIB_ARRAY_LENGTH_NV 0x8F2A
+#define GL_VERTEX_ARRAY_LENGTH_NV 0x8F2B
+#define GL_NORMAL_ARRAY_LENGTH_NV 0x8F2C
+#define GL_COLOR_ARRAY_LENGTH_NV 0x8F2D
+#define GL_INDEX_ARRAY_LENGTH_NV 0x8F2E
+#define GL_TEXTURE_COORD_ARRAY_LENGTH_NV 0x8F2F
+#define GL_EDGE_FLAG_ARRAY_LENGTH_NV 0x8F30
+#define GL_SECONDARY_COLOR_ARRAY_LENGTH_NV 0x8F31
+#define GL_FOG_COORD_ARRAY_LENGTH_NV 0x8F32
+#define GL_ELEMENT_ARRAY_LENGTH_NV 0x8F33
+#define GL_DRAW_INDIRECT_UNIFIED_NV 0x8F40
+#define GL_DRAW_INDIRECT_ADDRESS_NV 0x8F41
+#define GL_DRAW_INDIRECT_LENGTH_NV 0x8F42
+typedef void (APIENTRYP PFNGLBUFFERADDRESSRANGENVPROC) (GLenum pname, GLuint index, GLuint64EXT address, GLsizeiptr length);
+typedef void (APIENTRYP PFNGLVERTEXFORMATNVPROC) (GLint size, GLenum type, GLsizei stride);
+typedef void (APIENTRYP PFNGLNORMALFORMATNVPROC) (GLenum type, GLsizei stride);
+typedef void (APIENTRYP PFNGLCOLORFORMATNVPROC) (GLint size, GLenum type, GLsizei stride);
+typedef void (APIENTRYP PFNGLINDEXFORMATNVPROC) (GLenum type, GLsizei stride);
+typedef void (APIENTRYP PFNGLTEXCOORDFORMATNVPROC) (GLint size, GLenum type, GLsizei stride);
+typedef void (APIENTRYP PFNGLEDGEFLAGFORMATNVPROC) (GLsizei stride);
+typedef void (APIENTRYP PFNGLSECONDARYCOLORFORMATNVPROC) (GLint size, GLenum type, GLsizei stride);
+typedef void (APIENTRYP PFNGLFOGCOORDFORMATNVPROC) (GLenum type, GLsizei stride);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBIFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLsizei stride);
+typedef void (APIENTRYP PFNGLGETINTEGERUI64I_VNVPROC) (GLenum value, GLuint index, GLuint64EXT *result);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBufferAddressRangeNV (GLenum pname, GLuint index, GLuint64EXT address, GLsizeiptr length);
+GLAPI void APIENTRY glVertexFormatNV (GLint size, GLenum type, GLsizei stride);
+GLAPI void APIENTRY glNormalFormatNV (GLenum type, GLsizei stride);
+GLAPI void APIENTRY glColorFormatNV (GLint size, GLenum type, GLsizei stride);
+GLAPI void APIENTRY glIndexFormatNV (GLenum type, GLsizei stride);
+GLAPI void APIENTRY glTexCoordFormatNV (GLint size, GLenum type, GLsizei stride);
+GLAPI void APIENTRY glEdgeFlagFormatNV (GLsizei stride);
+GLAPI void APIENTRY glSecondaryColorFormatNV (GLint size, GLenum type, GLsizei stride);
+GLAPI void APIENTRY glFogCoordFormatNV (GLenum type, GLsizei stride);
+GLAPI void APIENTRY glVertexAttribFormatNV (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride);
+GLAPI void APIENTRY glVertexAttribIFormatNV (GLuint index, GLint size, GLenum type, GLsizei stride);
+GLAPI void APIENTRY glGetIntegerui64i_vNV (GLenum value, GLuint index, GLuint64EXT *result);
+#endif
+#endif /* GL_NV_vertex_buffer_unified_memory */
+
+#ifndef GL_NV_vertex_program
+#define GL_NV_vertex_program 1
+#define GL_VERTEX_PROGRAM_NV 0x8620
+#define GL_VERTEX_STATE_PROGRAM_NV 0x8621
+#define GL_ATTRIB_ARRAY_SIZE_NV 0x8623
+#define GL_ATTRIB_ARRAY_STRIDE_NV 0x8624
+#define GL_ATTRIB_ARRAY_TYPE_NV 0x8625
+#define GL_CURRENT_ATTRIB_NV 0x8626
+#define GL_PROGRAM_LENGTH_NV 0x8627
+#define GL_PROGRAM_STRING_NV 0x8628
+#define GL_MODELVIEW_PROJECTION_NV 0x8629
+#define GL_IDENTITY_NV 0x862A
+#define GL_INVERSE_NV 0x862B
+#define GL_TRANSPOSE_NV 0x862C
+#define GL_INVERSE_TRANSPOSE_NV 0x862D
+#define GL_MAX_TRACK_MATRIX_STACK_DEPTH_NV 0x862E
+#define GL_MAX_TRACK_MATRICES_NV 0x862F
+#define GL_MATRIX0_NV 0x8630
+#define GL_MATRIX1_NV 0x8631
+#define GL_MATRIX2_NV 0x8632
+#define GL_MATRIX3_NV 0x8633
+#define GL_MATRIX4_NV 0x8634
+#define GL_MATRIX5_NV 0x8635
+#define GL_MATRIX6_NV 0x8636
+#define GL_MATRIX7_NV 0x8637
+#define GL_CURRENT_MATRIX_STACK_DEPTH_NV 0x8640
+#define GL_CURRENT_MATRIX_NV 0x8641
+#define GL_VERTEX_PROGRAM_POINT_SIZE_NV 0x8642
+#define GL_VERTEX_PROGRAM_TWO_SIDE_NV 0x8643
+#define GL_PROGRAM_PARAMETER_NV 0x8644
+#define GL_ATTRIB_ARRAY_POINTER_NV 0x8645
+#define GL_PROGRAM_TARGET_NV 0x8646
+#define GL_PROGRAM_RESIDENT_NV 0x8647
+#define GL_TRACK_MATRIX_NV 0x8648
+#define GL_TRACK_MATRIX_TRANSFORM_NV 0x8649
+#define GL_VERTEX_PROGRAM_BINDING_NV 0x864A
+#define GL_PROGRAM_ERROR_POSITION_NV 0x864B
+#define GL_VERTEX_ATTRIB_ARRAY0_NV 0x8650
+#define GL_VERTEX_ATTRIB_ARRAY1_NV 0x8651
+#define GL_VERTEX_ATTRIB_ARRAY2_NV 0x8652
+#define GL_VERTEX_ATTRIB_ARRAY3_NV 0x8653
+#define GL_VERTEX_ATTRIB_ARRAY4_NV 0x8654
+#define GL_VERTEX_ATTRIB_ARRAY5_NV 0x8655
+#define GL_VERTEX_ATTRIB_ARRAY6_NV 0x8656
+#define GL_VERTEX_ATTRIB_ARRAY7_NV 0x8657
+#define GL_VERTEX_ATTRIB_ARRAY8_NV 0x8658
+#define GL_VERTEX_ATTRIB_ARRAY9_NV 0x8659
+#define GL_VERTEX_ATTRIB_ARRAY10_NV 0x865A
+#define GL_VERTEX_ATTRIB_ARRAY11_NV 0x865B
+#define GL_VERTEX_ATTRIB_ARRAY12_NV 0x865C
+#define GL_VERTEX_ATTRIB_ARRAY13_NV 0x865D
+#define GL_VERTEX_ATTRIB_ARRAY14_NV 0x865E
+#define GL_VERTEX_ATTRIB_ARRAY15_NV 0x865F
+#define GL_MAP1_VERTEX_ATTRIB0_4_NV 0x8660
+#define GL_MAP1_VERTEX_ATTRIB1_4_NV 0x8661
+#define GL_MAP1_VERTEX_ATTRIB2_4_NV 0x8662
+#define GL_MAP1_VERTEX_ATTRIB3_4_NV 0x8663
+#define GL_MAP1_VERTEX_ATTRIB4_4_NV 0x8664
+#define GL_MAP1_VERTEX_ATTRIB5_4_NV 0x8665
+#define GL_MAP1_VERTEX_ATTRIB6_4_NV 0x8666
+#define GL_MAP1_VERTEX_ATTRIB7_4_NV 0x8667
+#define GL_MAP1_VERTEX_ATTRIB8_4_NV 0x8668
+#define GL_MAP1_VERTEX_ATTRIB9_4_NV 0x8669
+#define GL_MAP1_VERTEX_ATTRIB10_4_NV 0x866A
+#define GL_MAP1_VERTEX_ATTRIB11_4_NV 0x866B
+#define GL_MAP1_VERTEX_ATTRIB12_4_NV 0x866C
+#define GL_MAP1_VERTEX_ATTRIB13_4_NV 0x866D
+#define GL_MAP1_VERTEX_ATTRIB14_4_NV 0x866E
+#define GL_MAP1_VERTEX_ATTRIB15_4_NV 0x866F
+#define GL_MAP2_VERTEX_ATTRIB0_4_NV 0x8670
+#define GL_MAP2_VERTEX_ATTRIB1_4_NV 0x8671
+#define GL_MAP2_VERTEX_ATTRIB2_4_NV 0x8672
+#define GL_MAP2_VERTEX_ATTRIB3_4_NV 0x8673
+#define GL_MAP2_VERTEX_ATTRIB4_4_NV 0x8674
+#define GL_MAP2_VERTEX_ATTRIB5_4_NV 0x8675
+#define GL_MAP2_VERTEX_ATTRIB6_4_NV 0x8676
+#define GL_MAP2_VERTEX_ATTRIB7_4_NV 0x8677
+#define GL_MAP2_VERTEX_ATTRIB8_4_NV 0x8678
+#define GL_MAP2_VERTEX_ATTRIB9_4_NV 0x8679
+#define GL_MAP2_VERTEX_ATTRIB10_4_NV 0x867A
+#define GL_MAP2_VERTEX_ATTRIB11_4_NV 0x867B
+#define GL_MAP2_VERTEX_ATTRIB12_4_NV 0x867C
+#define GL_MAP2_VERTEX_ATTRIB13_4_NV 0x867D
+#define GL_MAP2_VERTEX_ATTRIB14_4_NV 0x867E
+#define GL_MAP2_VERTEX_ATTRIB15_4_NV 0x867F
+typedef GLboolean (APIENTRYP PFNGLAREPROGRAMSRESIDENTNVPROC) (GLsizei n, const GLuint *programs, GLboolean *residences);
+typedef void (APIENTRYP PFNGLBINDPROGRAMNVPROC) (GLenum target, GLuint id);
+typedef void (APIENTRYP PFNGLDELETEPROGRAMSNVPROC) (GLsizei n, const GLuint *programs);
+typedef void (APIENTRYP PFNGLEXECUTEPROGRAMNVPROC) (GLenum target, GLuint id, const GLfloat *params);
+typedef void (APIENTRYP PFNGLGENPROGRAMSNVPROC) (GLsizei n, GLuint *programs);
+typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERDVNVPROC) (GLenum target, GLuint index, GLenum pname, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMIVNVPROC) (GLuint id, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGNVPROC) (GLuint id, GLenum pname, GLubyte *program);
+typedef void (APIENTRYP PFNGLGETTRACKMATRIXIVNVPROC) (GLenum target, GLuint address, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVNVPROC) (GLuint index, GLenum pname, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVNVPROC) (GLuint index, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVNVPROC) (GLuint index, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVNVPROC) (GLuint index, GLenum pname, void **pointer);
+typedef GLboolean (APIENTRYP PFNGLISPROGRAMNVPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLLOADPROGRAMNVPROC) (GLenum target, GLuint id, GLsizei len, const GLubyte *program);
+typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DNVPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DVNVPROC) (GLenum target, GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FNVPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FVNVPROC) (GLenum target, GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4DVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLdouble *v);
+typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4FVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *v);
+typedef void (APIENTRYP PFNGLREQUESTRESIDENTPROGRAMSNVPROC) (GLsizei n, const GLuint *programs);
+typedef void (APIENTRYP PFNGLTRACKMATRIXNVPROC) (GLenum target, GLuint address, GLenum matrix, GLenum transform);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERNVPROC) (GLuint index, GLint fsize, GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1DNVPROC) (GLuint index, GLdouble x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVNVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1FNVPROC) (GLuint index, GLfloat x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVNVPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1SNVPROC) (GLuint index, GLshort x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVNVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2DNVPROC) (GLuint index, GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVNVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2FNVPROC) (GLuint index, GLfloat x, GLfloat y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVNVPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2SNVPROC) (GLuint index, GLshort x, GLshort y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVNVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVNVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVNVPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVNVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVNVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVNVPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVNVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBNVPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVNVPROC) (GLuint index, const GLubyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS1DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS1FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS1SVNVPROC) (GLuint index, GLsizei count, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS2DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS2FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS2SVNVPROC) (GLuint index, GLsizei count, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS3DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS3FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS3SVNVPROC) (GLuint index, GLsizei count, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS4DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS4FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS4SVNVPROC) (GLuint index, GLsizei count, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS4UBVNVPROC) (GLuint index, GLsizei count, const GLubyte *v);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLboolean APIENTRY glAreProgramsResidentNV (GLsizei n, const GLuint *programs, GLboolean *residences);
+GLAPI void APIENTRY glBindProgramNV (GLenum target, GLuint id);
+GLAPI void APIENTRY glDeleteProgramsNV (GLsizei n, const GLuint *programs);
+GLAPI void APIENTRY glExecuteProgramNV (GLenum target, GLuint id, const GLfloat *params);
+GLAPI void APIENTRY glGenProgramsNV (GLsizei n, GLuint *programs);
+GLAPI void APIENTRY glGetProgramParameterdvNV (GLenum target, GLuint index, GLenum pname, GLdouble *params);
+GLAPI void APIENTRY glGetProgramParameterfvNV (GLenum target, GLuint index, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetProgramivNV (GLuint id, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetProgramStringNV (GLuint id, GLenum pname, GLubyte *program);
+GLAPI void APIENTRY glGetTrackMatrixivNV (GLenum target, GLuint address, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetVertexAttribdvNV (GLuint index, GLenum pname, GLdouble *params);
+GLAPI void APIENTRY glGetVertexAttribfvNV (GLuint index, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetVertexAttribivNV (GLuint index, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetVertexAttribPointervNV (GLuint index, GLenum pname, void **pointer);
+GLAPI GLboolean APIENTRY glIsProgramNV (GLuint id);
+GLAPI void APIENTRY glLoadProgramNV (GLenum target, GLuint id, GLsizei len, const GLubyte *program);
+GLAPI void APIENTRY glProgramParameter4dNV (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glProgramParameter4dvNV (GLenum target, GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glProgramParameter4fNV (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glProgramParameter4fvNV (GLenum target, GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glProgramParameters4dvNV (GLenum target, GLuint index, GLsizei count, const GLdouble *v);
+GLAPI void APIENTRY glProgramParameters4fvNV (GLenum target, GLuint index, GLsizei count, const GLfloat *v);
+GLAPI void APIENTRY glRequestResidentProgramsNV (GLsizei n, const GLuint *programs);
+GLAPI void APIENTRY glTrackMatrixNV (GLenum target, GLuint address, GLenum matrix, GLenum transform);
+GLAPI void APIENTRY glVertexAttribPointerNV (GLuint index, GLint fsize, GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glVertexAttrib1dNV (GLuint index, GLdouble x);
+GLAPI void APIENTRY glVertexAttrib1dvNV (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib1fNV (GLuint index, GLfloat x);
+GLAPI void APIENTRY glVertexAttrib1fvNV (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib1sNV (GLuint index, GLshort x);
+GLAPI void APIENTRY glVertexAttrib1svNV (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib2dNV (GLuint index, GLdouble x, GLdouble y);
+GLAPI void APIENTRY glVertexAttrib2dvNV (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib2fNV (GLuint index, GLfloat x, GLfloat y);
+GLAPI void APIENTRY glVertexAttrib2fvNV (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib2sNV (GLuint index, GLshort x, GLshort y);
+GLAPI void APIENTRY glVertexAttrib2svNV (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib3dNV (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glVertexAttrib3dvNV (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib3fNV (GLuint index, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glVertexAttrib3fvNV (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib3sNV (GLuint index, GLshort x, GLshort y, GLshort z);
+GLAPI void APIENTRY glVertexAttrib3svNV (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib4dNV (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glVertexAttrib4dvNV (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib4fNV (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glVertexAttrib4fvNV (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib4sNV (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w);
+GLAPI void APIENTRY glVertexAttrib4svNV (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib4ubNV (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w);
+GLAPI void APIENTRY glVertexAttrib4ubvNV (GLuint index, const GLubyte *v);
+GLAPI void APIENTRY glVertexAttribs1dvNV (GLuint index, GLsizei count, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribs1fvNV (GLuint index, GLsizei count, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttribs1svNV (GLuint index, GLsizei count, const GLshort *v);
+GLAPI void APIENTRY glVertexAttribs2dvNV (GLuint index, GLsizei count, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribs2fvNV (GLuint index, GLsizei count, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttribs2svNV (GLuint index, GLsizei count, const GLshort *v);
+GLAPI void APIENTRY glVertexAttribs3dvNV (GLuint index, GLsizei count, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribs3fvNV (GLuint index, GLsizei count, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttribs3svNV (GLuint index, GLsizei count, const GLshort *v);
+GLAPI void APIENTRY glVertexAttribs4dvNV (GLuint index, GLsizei count, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribs4fvNV (GLuint index, GLsizei count, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttribs4svNV (GLuint index, GLsizei count, const GLshort *v);
+GLAPI void APIENTRY glVertexAttribs4ubvNV (GLuint index, GLsizei count, const GLubyte *v);
+#endif
+#endif /* GL_NV_vertex_program */
+
+#ifndef GL_NV_vertex_program1_1
+#define GL_NV_vertex_program1_1 1
+#endif /* GL_NV_vertex_program1_1 */
+
+#ifndef GL_NV_vertex_program2
+#define GL_NV_vertex_program2 1
+#endif /* GL_NV_vertex_program2 */
+
+#ifndef GL_NV_vertex_program2_option
+#define GL_NV_vertex_program2_option 1
+#endif /* GL_NV_vertex_program2_option */
+
+#ifndef GL_NV_vertex_program3
+#define GL_NV_vertex_program3 1
+#endif /* GL_NV_vertex_program3 */
+
+#ifndef GL_NV_vertex_program4
+#define GL_NV_vertex_program4 1
+#define GL_VERTEX_ATTRIB_ARRAY_INTEGER_NV 0x88FD
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IEXTPROC) (GLuint index, GLint x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IEXTPROC) (GLuint index, GLint x, GLint y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IEXTPROC) (GLuint index, GLint x, GLint y, GLint z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IEXTPROC) (GLuint index, GLint x, GLint y, GLint z, GLint w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIEXTPROC) (GLuint index, GLuint x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIEXTPROC) (GLuint index, GLuint x, GLuint y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIEXTPROC) (GLuint index, GLuint x, GLuint y, GLuint z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIEXTPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVEXTPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVEXTPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVEXTPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVEXTPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVEXTPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVEXTPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVEXTPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVEXTPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVEXTPROC) (GLuint index, const GLbyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVEXTPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVEXTPROC) (GLuint index, const GLubyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVEXTPROC) (GLuint index, const GLushort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTEREXTPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVEXTPROC) (GLuint index, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVEXTPROC) (GLuint index, GLenum pname, GLuint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexAttribI1iEXT (GLuint index, GLint x);
+GLAPI void APIENTRY glVertexAttribI2iEXT (GLuint index, GLint x, GLint y);
+GLAPI void APIENTRY glVertexAttribI3iEXT (GLuint index, GLint x, GLint y, GLint z);
+GLAPI void APIENTRY glVertexAttribI4iEXT (GLuint index, GLint x, GLint y, GLint z, GLint w);
+GLAPI void APIENTRY glVertexAttribI1uiEXT (GLuint index, GLuint x);
+GLAPI void APIENTRY glVertexAttribI2uiEXT (GLuint index, GLuint x, GLuint y);
+GLAPI void APIENTRY glVertexAttribI3uiEXT (GLuint index, GLuint x, GLuint y, GLuint z);
+GLAPI void APIENTRY glVertexAttribI4uiEXT (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+GLAPI void APIENTRY glVertexAttribI1ivEXT (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttribI2ivEXT (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttribI3ivEXT (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttribI4ivEXT (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttribI1uivEXT (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttribI2uivEXT (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttribI3uivEXT (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttribI4uivEXT (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttribI4bvEXT (GLuint index, const GLbyte *v);
+GLAPI void APIENTRY glVertexAttribI4svEXT (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttribI4ubvEXT (GLuint index, const GLubyte *v);
+GLAPI void APIENTRY glVertexAttribI4usvEXT (GLuint index, const GLushort *v);
+GLAPI void APIENTRY glVertexAttribIPointerEXT (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glGetVertexAttribIivEXT (GLuint index, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetVertexAttribIuivEXT (GLuint index, GLenum pname, GLuint *params);
+#endif
+#endif /* GL_NV_vertex_program4 */
+
+#ifndef GL_NV_video_capture
+#define GL_NV_video_capture 1
+#define GL_VIDEO_BUFFER_NV 0x9020
+#define GL_VIDEO_BUFFER_BINDING_NV 0x9021
+#define GL_FIELD_UPPER_NV 0x9022
+#define GL_FIELD_LOWER_NV 0x9023
+#define GL_NUM_VIDEO_CAPTURE_STREAMS_NV 0x9024
+#define GL_NEXT_VIDEO_CAPTURE_BUFFER_STATUS_NV 0x9025
+#define GL_VIDEO_CAPTURE_TO_422_SUPPORTED_NV 0x9026
+#define GL_LAST_VIDEO_CAPTURE_STATUS_NV 0x9027
+#define GL_VIDEO_BUFFER_PITCH_NV 0x9028
+#define GL_VIDEO_COLOR_CONVERSION_MATRIX_NV 0x9029
+#define GL_VIDEO_COLOR_CONVERSION_MAX_NV 0x902A
+#define GL_VIDEO_COLOR_CONVERSION_MIN_NV 0x902B
+#define GL_VIDEO_COLOR_CONVERSION_OFFSET_NV 0x902C
+#define GL_VIDEO_BUFFER_INTERNAL_FORMAT_NV 0x902D
+#define GL_PARTIAL_SUCCESS_NV 0x902E
+#define GL_SUCCESS_NV 0x902F
+#define GL_FAILURE_NV 0x9030
+#define GL_YCBYCR8_422_NV 0x9031
+#define GL_YCBAYCR8A_4224_NV 0x9032
+#define GL_Z6Y10Z6CB10Z6Y10Z6CR10_422_NV 0x9033
+#define GL_Z6Y10Z6CB10Z6A10Z6Y10Z6CR10Z6A10_4224_NV 0x9034
+#define GL_Z4Y12Z4CB12Z4Y12Z4CR12_422_NV 0x9035
+#define GL_Z4Y12Z4CB12Z4A12Z4Y12Z4CR12Z4A12_4224_NV 0x9036
+#define GL_Z4Y12Z4CB12Z4CR12_444_NV 0x9037
+#define GL_VIDEO_CAPTURE_FRAME_WIDTH_NV 0x9038
+#define GL_VIDEO_CAPTURE_FRAME_HEIGHT_NV 0x9039
+#define GL_VIDEO_CAPTURE_FIELD_UPPER_HEIGHT_NV 0x903A
+#define GL_VIDEO_CAPTURE_FIELD_LOWER_HEIGHT_NV 0x903B
+#define GL_VIDEO_CAPTURE_SURFACE_ORIGIN_NV 0x903C
+typedef void (APIENTRYP PFNGLBEGINVIDEOCAPTURENVPROC) (GLuint video_capture_slot);
+typedef void (APIENTRYP PFNGLBINDVIDEOCAPTURESTREAMBUFFERNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLintptrARB offset);
+typedef void (APIENTRYP PFNGLBINDVIDEOCAPTURESTREAMTEXTURENVPROC) (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLenum target, GLuint texture);
+typedef void (APIENTRYP PFNGLENDVIDEOCAPTURENVPROC) (GLuint video_capture_slot);
+typedef void (APIENTRYP PFNGLGETVIDEOCAPTUREIVNVPROC) (GLuint video_capture_slot, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMIVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMFVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMDVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLdouble *params);
+typedef GLenum (APIENTRYP PFNGLVIDEOCAPTURENVPROC) (GLuint video_capture_slot, GLuint *sequence_num, GLuint64EXT *capture_time);
+typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERIVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERFVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERDVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLdouble *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBeginVideoCaptureNV (GLuint video_capture_slot);
+GLAPI void APIENTRY glBindVideoCaptureStreamBufferNV (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLintptrARB offset);
+GLAPI void APIENTRY glBindVideoCaptureStreamTextureNV (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLenum target, GLuint texture);
+GLAPI void APIENTRY glEndVideoCaptureNV (GLuint video_capture_slot);
+GLAPI void APIENTRY glGetVideoCaptureivNV (GLuint video_capture_slot, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetVideoCaptureStreamivNV (GLuint video_capture_slot, GLuint stream, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetVideoCaptureStreamfvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetVideoCaptureStreamdvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, GLdouble *params);
+GLAPI GLenum APIENTRY glVideoCaptureNV (GLuint video_capture_slot, GLuint *sequence_num, GLuint64EXT *capture_time);
+GLAPI void APIENTRY glVideoCaptureStreamParameterivNV (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glVideoCaptureStreamParameterfvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glVideoCaptureStreamParameterdvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLdouble *params);
+#endif
+#endif /* GL_NV_video_capture */
+
+#ifndef GL_OML_interlace
+#define GL_OML_interlace 1
+#define GL_INTERLACE_OML 0x8980
+#define GL_INTERLACE_READ_OML 0x8981
+#endif /* GL_OML_interlace */
+
+#ifndef GL_OML_resample
+#define GL_OML_resample 1
+#define GL_PACK_RESAMPLE_OML 0x8984
+#define GL_UNPACK_RESAMPLE_OML 0x8985
+#define GL_RESAMPLE_REPLICATE_OML 0x8986
+#define GL_RESAMPLE_ZERO_FILL_OML 0x8987
+#define GL_RESAMPLE_AVERAGE_OML 0x8988
+#define GL_RESAMPLE_DECIMATE_OML 0x8989
+#endif /* GL_OML_resample */
+
+#ifndef GL_OML_subsample
+#define GL_OML_subsample 1
+#define GL_FORMAT_SUBSAMPLE_24_24_OML 0x8982
+#define GL_FORMAT_SUBSAMPLE_244_244_OML 0x8983
+#endif /* GL_OML_subsample */
+
+#ifndef GL_PGI_misc_hints
+#define GL_PGI_misc_hints 1
+#define GL_PREFER_DOUBLEBUFFER_HINT_PGI 0x1A1F8
+#define GL_CONSERVE_MEMORY_HINT_PGI 0x1A1FD
+#define GL_RECLAIM_MEMORY_HINT_PGI 0x1A1FE
+#define GL_NATIVE_GRAPHICS_HANDLE_PGI 0x1A202
+#define GL_NATIVE_GRAPHICS_BEGIN_HINT_PGI 0x1A203
+#define GL_NATIVE_GRAPHICS_END_HINT_PGI 0x1A204
+#define GL_ALWAYS_FAST_HINT_PGI 0x1A20C
+#define GL_ALWAYS_SOFT_HINT_PGI 0x1A20D
+#define GL_ALLOW_DRAW_OBJ_HINT_PGI 0x1A20E
+#define GL_ALLOW_DRAW_WIN_HINT_PGI 0x1A20F
+#define GL_ALLOW_DRAW_FRG_HINT_PGI 0x1A210
+#define GL_ALLOW_DRAW_MEM_HINT_PGI 0x1A211
+#define GL_STRICT_DEPTHFUNC_HINT_PGI 0x1A216
+#define GL_STRICT_LIGHTING_HINT_PGI 0x1A217
+#define GL_STRICT_SCISSOR_HINT_PGI 0x1A218
+#define GL_FULL_STIPPLE_HINT_PGI 0x1A219
+#define GL_CLIP_NEAR_HINT_PGI 0x1A220
+#define GL_CLIP_FAR_HINT_PGI 0x1A221
+#define GL_WIDE_LINE_HINT_PGI 0x1A222
+#define GL_BACK_NORMALS_HINT_PGI 0x1A223
+typedef void (APIENTRYP PFNGLHINTPGIPROC) (GLenum target, GLint mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glHintPGI (GLenum target, GLint mode);
+#endif
+#endif /* GL_PGI_misc_hints */
+
+#ifndef GL_PGI_vertex_hints
+#define GL_PGI_vertex_hints 1
+#define GL_VERTEX_DATA_HINT_PGI 0x1A22A
+#define GL_VERTEX_CONSISTENT_HINT_PGI 0x1A22B
+#define GL_MATERIAL_SIDE_HINT_PGI 0x1A22C
+#define GL_MAX_VERTEX_HINT_PGI 0x1A22D
+#define GL_COLOR3_BIT_PGI 0x00010000
+#define GL_COLOR4_BIT_PGI 0x00020000
+#define GL_EDGEFLAG_BIT_PGI 0x00040000
+#define GL_INDEX_BIT_PGI 0x00080000
+#define GL_MAT_AMBIENT_BIT_PGI 0x00100000
+#define GL_MAT_AMBIENT_AND_DIFFUSE_BIT_PGI 0x00200000
+#define GL_MAT_DIFFUSE_BIT_PGI 0x00400000
+#define GL_MAT_EMISSION_BIT_PGI 0x00800000
+#define GL_MAT_COLOR_INDEXES_BIT_PGI 0x01000000
+#define GL_MAT_SHININESS_BIT_PGI 0x02000000
+#define GL_MAT_SPECULAR_BIT_PGI 0x04000000
+#define GL_NORMAL_BIT_PGI 0x08000000
+#define GL_TEXCOORD1_BIT_PGI 0x10000000
+#define GL_TEXCOORD2_BIT_PGI 0x20000000
+#define GL_TEXCOORD3_BIT_PGI 0x40000000
+#define GL_TEXCOORD4_BIT_PGI 0x80000000
+#define GL_VERTEX23_BIT_PGI 0x00000004
+#define GL_VERTEX4_BIT_PGI 0x00000008
+#endif /* GL_PGI_vertex_hints */
+
+#ifndef GL_REND_screen_coordinates
+#define GL_REND_screen_coordinates 1
+#define GL_SCREEN_COORDINATES_REND 0x8490
+#define GL_INVERTED_SCREEN_W_REND 0x8491
+#endif /* GL_REND_screen_coordinates */
+
+#ifndef GL_S3_s3tc
+#define GL_S3_s3tc 1
+#define GL_RGB_S3TC 0x83A0
+#define GL_RGB4_S3TC 0x83A1
+#define GL_RGBA_S3TC 0x83A2
+#define GL_RGBA4_S3TC 0x83A3
+#define GL_RGBA_DXT5_S3TC 0x83A4
+#define GL_RGBA4_DXT5_S3TC 0x83A5
+#endif /* GL_S3_s3tc */
+
+#ifndef GL_SGIS_detail_texture
+#define GL_SGIS_detail_texture 1
+#define GL_DETAIL_TEXTURE_2D_SGIS 0x8095
+#define GL_DETAIL_TEXTURE_2D_BINDING_SGIS 0x8096
+#define GL_LINEAR_DETAIL_SGIS 0x8097
+#define GL_LINEAR_DETAIL_ALPHA_SGIS 0x8098
+#define GL_LINEAR_DETAIL_COLOR_SGIS 0x8099
+#define GL_DETAIL_TEXTURE_LEVEL_SGIS 0x809A
+#define GL_DETAIL_TEXTURE_MODE_SGIS 0x809B
+#define GL_DETAIL_TEXTURE_FUNC_POINTS_SGIS 0x809C
+typedef void (APIENTRYP PFNGLDETAILTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points);
+typedef void (APIENTRYP PFNGLGETDETAILTEXFUNCSGISPROC) (GLenum target, GLfloat *points);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDetailTexFuncSGIS (GLenum target, GLsizei n, const GLfloat *points);
+GLAPI void APIENTRY glGetDetailTexFuncSGIS (GLenum target, GLfloat *points);
+#endif
+#endif /* GL_SGIS_detail_texture */
+
+#ifndef GL_SGIS_fog_function
+#define GL_SGIS_fog_function 1
+#define GL_FOG_FUNC_SGIS 0x812A
+#define GL_FOG_FUNC_POINTS_SGIS 0x812B
+#define GL_MAX_FOG_FUNC_POINTS_SGIS 0x812C
+typedef void (APIENTRYP PFNGLFOGFUNCSGISPROC) (GLsizei n, const GLfloat *points);
+typedef void (APIENTRYP PFNGLGETFOGFUNCSGISPROC) (GLfloat *points);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glFogFuncSGIS (GLsizei n, const GLfloat *points);
+GLAPI void APIENTRY glGetFogFuncSGIS (GLfloat *points);
+#endif
+#endif /* GL_SGIS_fog_function */
+
+#ifndef GL_SGIS_generate_mipmap
+#define GL_SGIS_generate_mipmap 1
+#define GL_GENERATE_MIPMAP_SGIS 0x8191
+#define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192
+#endif /* GL_SGIS_generate_mipmap */
+
+#ifndef GL_SGIS_multisample
+#define GL_SGIS_multisample 1
+#define GL_MULTISAMPLE_SGIS 0x809D
+#define GL_SAMPLE_ALPHA_TO_MASK_SGIS 0x809E
+#define GL_SAMPLE_ALPHA_TO_ONE_SGIS 0x809F
+#define GL_SAMPLE_MASK_SGIS 0x80A0
+#define GL_1PASS_SGIS 0x80A1
+#define GL_2PASS_0_SGIS 0x80A2
+#define GL_2PASS_1_SGIS 0x80A3
+#define GL_4PASS_0_SGIS 0x80A4
+#define GL_4PASS_1_SGIS 0x80A5
+#define GL_4PASS_2_SGIS 0x80A6
+#define GL_4PASS_3_SGIS 0x80A7
+#define GL_SAMPLE_BUFFERS_SGIS 0x80A8
+#define GL_SAMPLES_SGIS 0x80A9
+#define GL_SAMPLE_MASK_VALUE_SGIS 0x80AA
+#define GL_SAMPLE_MASK_INVERT_SGIS 0x80AB
+#define GL_SAMPLE_PATTERN_SGIS 0x80AC
+typedef void (APIENTRYP PFNGLSAMPLEMASKSGISPROC) (GLclampf value, GLboolean invert);
+typedef void (APIENTRYP PFNGLSAMPLEPATTERNSGISPROC) (GLenum pattern);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glSampleMaskSGIS (GLclampf value, GLboolean invert);
+GLAPI void APIENTRY glSamplePatternSGIS (GLenum pattern);
+#endif
+#endif /* GL_SGIS_multisample */
+
+#ifndef GL_SGIS_pixel_texture
+#define GL_SGIS_pixel_texture 1
+#define GL_PIXEL_TEXTURE_SGIS 0x8353
+#define GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS 0x8354
+#define GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS 0x8355
+#define GL_PIXEL_GROUP_COLOR_SGIS 0x8356
+typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERISGISPROC) (GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFSGISPROC) (GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPixelTexGenParameteriSGIS (GLenum pname, GLint param);
+GLAPI void APIENTRY glPixelTexGenParameterivSGIS (GLenum pname, const GLint *params);
+GLAPI void APIENTRY glPixelTexGenParameterfSGIS (GLenum pname, GLfloat param);
+GLAPI void APIENTRY glPixelTexGenParameterfvSGIS (GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glGetPixelTexGenParameterivSGIS (GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetPixelTexGenParameterfvSGIS (GLenum pname, GLfloat *params);
+#endif
+#endif /* GL_SGIS_pixel_texture */
+
+#ifndef GL_SGIS_point_line_texgen
+#define GL_SGIS_point_line_texgen 1
+#define GL_EYE_DISTANCE_TO_POINT_SGIS 0x81F0
+#define GL_OBJECT_DISTANCE_TO_POINT_SGIS 0x81F1
+#define GL_EYE_DISTANCE_TO_LINE_SGIS 0x81F2
+#define GL_OBJECT_DISTANCE_TO_LINE_SGIS 0x81F3
+#define GL_EYE_POINT_SGIS 0x81F4
+#define GL_OBJECT_POINT_SGIS 0x81F5
+#define GL_EYE_LINE_SGIS 0x81F6
+#define GL_OBJECT_LINE_SGIS 0x81F7
+#endif /* GL_SGIS_point_line_texgen */
+
+#ifndef GL_SGIS_point_parameters
+#define GL_SGIS_point_parameters 1
+#define GL_POINT_SIZE_MIN_SGIS 0x8126
+#define GL_POINT_SIZE_MAX_SGIS 0x8127
+#define GL_POINT_FADE_THRESHOLD_SIZE_SGIS 0x8128
+#define GL_DISTANCE_ATTENUATION_SGIS 0x8129
+typedef void (APIENTRYP PFNGLPOINTPARAMETERFSGISPROC) (GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLPOINTPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPointParameterfSGIS (GLenum pname, GLfloat param);
+GLAPI void APIENTRY glPointParameterfvSGIS (GLenum pname, const GLfloat *params);
+#endif
+#endif /* GL_SGIS_point_parameters */
+
+#ifndef GL_SGIS_sharpen_texture
+#define GL_SGIS_sharpen_texture 1
+#define GL_LINEAR_SHARPEN_SGIS 0x80AD
+#define GL_LINEAR_SHARPEN_ALPHA_SGIS 0x80AE
+#define GL_LINEAR_SHARPEN_COLOR_SGIS 0x80AF
+#define GL_SHARPEN_TEXTURE_FUNC_POINTS_SGIS 0x80B0
+typedef void (APIENTRYP PFNGLSHARPENTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points);
+typedef void (APIENTRYP PFNGLGETSHARPENTEXFUNCSGISPROC) (GLenum target, GLfloat *points);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glSharpenTexFuncSGIS (GLenum target, GLsizei n, const GLfloat *points);
+GLAPI void APIENTRY glGetSharpenTexFuncSGIS (GLenum target, GLfloat *points);
+#endif
+#endif /* GL_SGIS_sharpen_texture */
+
+#ifndef GL_SGIS_texture4D
+#define GL_SGIS_texture4D 1
+#define GL_PACK_SKIP_VOLUMES_SGIS 0x8130
+#define GL_PACK_IMAGE_DEPTH_SGIS 0x8131
+#define GL_UNPACK_SKIP_VOLUMES_SGIS 0x8132
+#define GL_UNPACK_IMAGE_DEPTH_SGIS 0x8133
+#define GL_TEXTURE_4D_SGIS 0x8134
+#define GL_PROXY_TEXTURE_4D_SGIS 0x8135
+#define GL_TEXTURE_4DSIZE_SGIS 0x8136
+#define GL_TEXTURE_WRAP_Q_SGIS 0x8137
+#define GL_MAX_4D_TEXTURE_SIZE_SGIS 0x8138
+#define GL_TEXTURE_4D_BINDING_SGIS 0x814F
+typedef void (APIENTRYP PFNGLTEXIMAGE4DSGISPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLTEXSUBIMAGE4DSGISPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint woffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLenum format, GLenum type, const void *pixels);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexImage4DSGIS (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLint border, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glTexSubImage4DSGIS (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint woffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLenum format, GLenum type, const void *pixels);
+#endif
+#endif /* GL_SGIS_texture4D */
+
+#ifndef GL_SGIS_texture_border_clamp
+#define GL_SGIS_texture_border_clamp 1
+#define GL_CLAMP_TO_BORDER_SGIS 0x812D
+#endif /* GL_SGIS_texture_border_clamp */
+
+#ifndef GL_SGIS_texture_color_mask
+#define GL_SGIS_texture_color_mask 1
+#define GL_TEXTURE_COLOR_WRITEMASK_SGIS 0x81EF
+typedef void (APIENTRYP PFNGLTEXTURECOLORMASKSGISPROC) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTextureColorMaskSGIS (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
+#endif
+#endif /* GL_SGIS_texture_color_mask */
+
+#ifndef GL_SGIS_texture_edge_clamp
+#define GL_SGIS_texture_edge_clamp 1
+#define GL_CLAMP_TO_EDGE_SGIS 0x812F
+#endif /* GL_SGIS_texture_edge_clamp */
+
+#ifndef GL_SGIS_texture_filter4
+#define GL_SGIS_texture_filter4 1
+#define GL_FILTER4_SGIS 0x8146
+#define GL_TEXTURE_FILTER4_SIZE_SGIS 0x8147
+typedef void (APIENTRYP PFNGLGETTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLfloat *weights);
+typedef void (APIENTRYP PFNGLTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLsizei n, const GLfloat *weights);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGetTexFilterFuncSGIS (GLenum target, GLenum filter, GLfloat *weights);
+GLAPI void APIENTRY glTexFilterFuncSGIS (GLenum target, GLenum filter, GLsizei n, const GLfloat *weights);
+#endif
+#endif /* GL_SGIS_texture_filter4 */
+
+#ifndef GL_SGIS_texture_lod
+#define GL_SGIS_texture_lod 1
+#define GL_TEXTURE_MIN_LOD_SGIS 0x813A
+#define GL_TEXTURE_MAX_LOD_SGIS 0x813B
+#define GL_TEXTURE_BASE_LEVEL_SGIS 0x813C
+#define GL_TEXTURE_MAX_LEVEL_SGIS 0x813D
+#endif /* GL_SGIS_texture_lod */
+
+#ifndef GL_SGIS_texture_select
+#define GL_SGIS_texture_select 1
+#define GL_DUAL_ALPHA4_SGIS 0x8110
+#define GL_DUAL_ALPHA8_SGIS 0x8111
+#define GL_DUAL_ALPHA12_SGIS 0x8112
+#define GL_DUAL_ALPHA16_SGIS 0x8113
+#define GL_DUAL_LUMINANCE4_SGIS 0x8114
+#define GL_DUAL_LUMINANCE8_SGIS 0x8115
+#define GL_DUAL_LUMINANCE12_SGIS 0x8116
+#define GL_DUAL_LUMINANCE16_SGIS 0x8117
+#define GL_DUAL_INTENSITY4_SGIS 0x8118
+#define GL_DUAL_INTENSITY8_SGIS 0x8119
+#define GL_DUAL_INTENSITY12_SGIS 0x811A
+#define GL_DUAL_INTENSITY16_SGIS 0x811B
+#define GL_DUAL_LUMINANCE_ALPHA4_SGIS 0x811C
+#define GL_DUAL_LUMINANCE_ALPHA8_SGIS 0x811D
+#define GL_QUAD_ALPHA4_SGIS 0x811E
+#define GL_QUAD_ALPHA8_SGIS 0x811F
+#define GL_QUAD_LUMINANCE4_SGIS 0x8120
+#define GL_QUAD_LUMINANCE8_SGIS 0x8121
+#define GL_QUAD_INTENSITY4_SGIS 0x8122
+#define GL_QUAD_INTENSITY8_SGIS 0x8123
+#define GL_DUAL_TEXTURE_SELECT_SGIS 0x8124
+#define GL_QUAD_TEXTURE_SELECT_SGIS 0x8125
+#endif /* GL_SGIS_texture_select */
+
+#ifndef GL_SGIX_async
+#define GL_SGIX_async 1
+#define GL_ASYNC_MARKER_SGIX 0x8329
+typedef void (APIENTRYP PFNGLASYNCMARKERSGIXPROC) (GLuint marker);
+typedef GLint (APIENTRYP PFNGLFINISHASYNCSGIXPROC) (GLuint *markerp);
+typedef GLint (APIENTRYP PFNGLPOLLASYNCSGIXPROC) (GLuint *markerp);
+typedef GLuint (APIENTRYP PFNGLGENASYNCMARKERSSGIXPROC) (GLsizei range);
+typedef void (APIENTRYP PFNGLDELETEASYNCMARKERSSGIXPROC) (GLuint marker, GLsizei range);
+typedef GLboolean (APIENTRYP PFNGLISASYNCMARKERSGIXPROC) (GLuint marker);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glAsyncMarkerSGIX (GLuint marker);
+GLAPI GLint APIENTRY glFinishAsyncSGIX (GLuint *markerp);
+GLAPI GLint APIENTRY glPollAsyncSGIX (GLuint *markerp);
+GLAPI GLuint APIENTRY glGenAsyncMarkersSGIX (GLsizei range);
+GLAPI void APIENTRY glDeleteAsyncMarkersSGIX (GLuint marker, GLsizei range);
+GLAPI GLboolean APIENTRY glIsAsyncMarkerSGIX (GLuint marker);
+#endif
+#endif /* GL_SGIX_async */
+
+#ifndef GL_SGIX_async_histogram
+#define GL_SGIX_async_histogram 1
+#define GL_ASYNC_HISTOGRAM_SGIX 0x832C
+#define GL_MAX_ASYNC_HISTOGRAM_SGIX 0x832D
+#endif /* GL_SGIX_async_histogram */
+
+#ifndef GL_SGIX_async_pixel
+#define GL_SGIX_async_pixel 1
+#define GL_ASYNC_TEX_IMAGE_SGIX 0x835C
+#define GL_ASYNC_DRAW_PIXELS_SGIX 0x835D
+#define GL_ASYNC_READ_PIXELS_SGIX 0x835E
+#define GL_MAX_ASYNC_TEX_IMAGE_SGIX 0x835F
+#define GL_MAX_ASYNC_DRAW_PIXELS_SGIX 0x8360
+#define GL_MAX_ASYNC_READ_PIXELS_SGIX 0x8361
+#endif /* GL_SGIX_async_pixel */
+
+#ifndef GL_SGIX_blend_alpha_minmax
+#define GL_SGIX_blend_alpha_minmax 1
+#define GL_ALPHA_MIN_SGIX 0x8320
+#define GL_ALPHA_MAX_SGIX 0x8321
+#endif /* GL_SGIX_blend_alpha_minmax */
+
+#ifndef GL_SGIX_calligraphic_fragment
+#define GL_SGIX_calligraphic_fragment 1
+#define GL_CALLIGRAPHIC_FRAGMENT_SGIX 0x8183
+#endif /* GL_SGIX_calligraphic_fragment */
+
+#ifndef GL_SGIX_clipmap
+#define GL_SGIX_clipmap 1
+#define GL_LINEAR_CLIPMAP_LINEAR_SGIX 0x8170
+#define GL_TEXTURE_CLIPMAP_CENTER_SGIX 0x8171
+#define GL_TEXTURE_CLIPMAP_FRAME_SGIX 0x8172
+#define GL_TEXTURE_CLIPMAP_OFFSET_SGIX 0x8173
+#define GL_TEXTURE_CLIPMAP_VIRTUAL_DEPTH_SGIX 0x8174
+#define GL_TEXTURE_CLIPMAP_LOD_OFFSET_SGIX 0x8175
+#define GL_TEXTURE_CLIPMAP_DEPTH_SGIX 0x8176
+#define GL_MAX_CLIPMAP_DEPTH_SGIX 0x8177
+#define GL_MAX_CLIPMAP_VIRTUAL_DEPTH_SGIX 0x8178
+#define GL_NEAREST_CLIPMAP_NEAREST_SGIX 0x844D
+#define GL_NEAREST_CLIPMAP_LINEAR_SGIX 0x844E
+#define GL_LINEAR_CLIPMAP_NEAREST_SGIX 0x844F
+#endif /* GL_SGIX_clipmap */
+
+#ifndef GL_SGIX_convolution_accuracy
+#define GL_SGIX_convolution_accuracy 1
+#define GL_CONVOLUTION_HINT_SGIX 0x8316
+#endif /* GL_SGIX_convolution_accuracy */
+
+#ifndef GL_SGIX_depth_pass_instrument
+#define GL_SGIX_depth_pass_instrument 1
+#endif /* GL_SGIX_depth_pass_instrument */
+
+#ifndef GL_SGIX_depth_texture
+#define GL_SGIX_depth_texture 1
+#define GL_DEPTH_COMPONENT16_SGIX 0x81A5
+#define GL_DEPTH_COMPONENT24_SGIX 0x81A6
+#define GL_DEPTH_COMPONENT32_SGIX 0x81A7
+#endif /* GL_SGIX_depth_texture */
+
+#ifndef GL_SGIX_flush_raster
+#define GL_SGIX_flush_raster 1
+typedef void (APIENTRYP PFNGLFLUSHRASTERSGIXPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glFlushRasterSGIX (void);
+#endif
+#endif /* GL_SGIX_flush_raster */
+
+#ifndef GL_SGIX_fog_offset
+#define GL_SGIX_fog_offset 1
+#define GL_FOG_OFFSET_SGIX 0x8198
+#define GL_FOG_OFFSET_VALUE_SGIX 0x8199
+#endif /* GL_SGIX_fog_offset */
+
+#ifndef GL_SGIX_fragment_lighting
+#define GL_SGIX_fragment_lighting 1
+#define GL_FRAGMENT_LIGHTING_SGIX 0x8400
+#define GL_FRAGMENT_COLOR_MATERIAL_SGIX 0x8401
+#define GL_FRAGMENT_COLOR_MATERIAL_FACE_SGIX 0x8402
+#define GL_FRAGMENT_COLOR_MATERIAL_PARAMETER_SGIX 0x8403
+#define GL_MAX_FRAGMENT_LIGHTS_SGIX 0x8404
+#define GL_MAX_ACTIVE_LIGHTS_SGIX 0x8405
+#define GL_CURRENT_RASTER_NORMAL_SGIX 0x8406
+#define GL_LIGHT_ENV_MODE_SGIX 0x8407
+#define GL_FRAGMENT_LIGHT_MODEL_LOCAL_VIEWER_SGIX 0x8408
+#define GL_FRAGMENT_LIGHT_MODEL_TWO_SIDE_SGIX 0x8409
+#define GL_FRAGMENT_LIGHT_MODEL_AMBIENT_SGIX 0x840A
+#define GL_FRAGMENT_LIGHT_MODEL_NORMAL_INTERPOLATION_SGIX 0x840B
+#define GL_FRAGMENT_LIGHT0_SGIX 0x840C
+#define GL_FRAGMENT_LIGHT1_SGIX 0x840D
+#define GL_FRAGMENT_LIGHT2_SGIX 0x840E
+#define GL_FRAGMENT_LIGHT3_SGIX 0x840F
+#define GL_FRAGMENT_LIGHT4_SGIX 0x8410
+#define GL_FRAGMENT_LIGHT5_SGIX 0x8411
+#define GL_FRAGMENT_LIGHT6_SGIX 0x8412
+#define GL_FRAGMENT_LIGHT7_SGIX 0x8413
+typedef void (APIENTRYP PFNGLFRAGMENTCOLORMATERIALSGIXPROC) (GLenum face, GLenum mode);
+typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFSGIXPROC) (GLenum light, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLFRAGMENTLIGHTISGIXPROC) (GLenum light, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFSGIXPROC) (GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFVSGIXPROC) (GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELISGIXPROC) (GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELIVSGIXPROC) (GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFSGIXPROC) (GLenum face, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLFRAGMENTMATERIALISGIXPROC) (GLenum face, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLLIGHTENVISGIXPROC) (GLenum pname, GLint param);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glFragmentColorMaterialSGIX (GLenum face, GLenum mode);
+GLAPI void APIENTRY glFragmentLightfSGIX (GLenum light, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glFragmentLightfvSGIX (GLenum light, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glFragmentLightiSGIX (GLenum light, GLenum pname, GLint param);
+GLAPI void APIENTRY glFragmentLightivSGIX (GLenum light, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glFragmentLightModelfSGIX (GLenum pname, GLfloat param);
+GLAPI void APIENTRY glFragmentLightModelfvSGIX (GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glFragmentLightModeliSGIX (GLenum pname, GLint param);
+GLAPI void APIENTRY glFragmentLightModelivSGIX (GLenum pname, const GLint *params);
+GLAPI void APIENTRY glFragmentMaterialfSGIX (GLenum face, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glFragmentMaterialfvSGIX (GLenum face, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glFragmentMaterialiSGIX (GLenum face, GLenum pname, GLint param);
+GLAPI void APIENTRY glFragmentMaterialivSGIX (GLenum face, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glGetFragmentLightfvSGIX (GLenum light, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetFragmentLightivSGIX (GLenum light, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetFragmentMaterialfvSGIX (GLenum face, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetFragmentMaterialivSGIX (GLenum face, GLenum pname, GLint *params);
+GLAPI void APIENTRY glLightEnviSGIX (GLenum pname, GLint param);
+#endif
+#endif /* GL_SGIX_fragment_lighting */
+
+#ifndef GL_SGIX_framezoom
+#define GL_SGIX_framezoom 1
+#define GL_FRAMEZOOM_SGIX 0x818B
+#define GL_FRAMEZOOM_FACTOR_SGIX 0x818C
+#define GL_MAX_FRAMEZOOM_FACTOR_SGIX 0x818D
+typedef void (APIENTRYP PFNGLFRAMEZOOMSGIXPROC) (GLint factor);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glFrameZoomSGIX (GLint factor);
+#endif
+#endif /* GL_SGIX_framezoom */
+
+#ifndef GL_SGIX_igloo_interface
+#define GL_SGIX_igloo_interface 1
+typedef void (APIENTRYP PFNGLIGLOOINTERFACESGIXPROC) (GLenum pname, const void *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glIglooInterfaceSGIX (GLenum pname, const void *params);
+#endif
+#endif /* GL_SGIX_igloo_interface */
+
+#ifndef GL_SGIX_instruments
+#define GL_SGIX_instruments 1
+#define GL_INSTRUMENT_BUFFER_POINTER_SGIX 0x8180
+#define GL_INSTRUMENT_MEASUREMENTS_SGIX 0x8181
+typedef GLint (APIENTRYP PFNGLGETINSTRUMENTSSGIXPROC) (void);
+typedef void (APIENTRYP PFNGLINSTRUMENTSBUFFERSGIXPROC) (GLsizei size, GLint *buffer);
+typedef GLint (APIENTRYP PFNGLPOLLINSTRUMENTSSGIXPROC) (GLint *marker_p);
+typedef void (APIENTRYP PFNGLREADINSTRUMENTSSGIXPROC) (GLint marker);
+typedef void (APIENTRYP PFNGLSTARTINSTRUMENTSSGIXPROC) (void);
+typedef void (APIENTRYP PFNGLSTOPINSTRUMENTSSGIXPROC) (GLint marker);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLint APIENTRY glGetInstrumentsSGIX (void);
+GLAPI void APIENTRY glInstrumentsBufferSGIX (GLsizei size, GLint *buffer);
+GLAPI GLint APIENTRY glPollInstrumentsSGIX (GLint *marker_p);
+GLAPI void APIENTRY glReadInstrumentsSGIX (GLint marker);
+GLAPI void APIENTRY glStartInstrumentsSGIX (void);
+GLAPI void APIENTRY glStopInstrumentsSGIX (GLint marker);
+#endif
+#endif /* GL_SGIX_instruments */
+
+#ifndef GL_SGIX_interlace
+#define GL_SGIX_interlace 1
+#define GL_INTERLACE_SGIX 0x8094
+#endif /* GL_SGIX_interlace */
+
+#ifndef GL_SGIX_ir_instrument1
+#define GL_SGIX_ir_instrument1 1
+#define GL_IR_INSTRUMENT1_SGIX 0x817F
+#endif /* GL_SGIX_ir_instrument1 */
+
+#ifndef GL_SGIX_list_priority
+#define GL_SGIX_list_priority 1
+#define GL_LIST_PRIORITY_SGIX 0x8182
+typedef void (APIENTRYP PFNGLGETLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLLISTPARAMETERFSGIXPROC) (GLuint list, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLLISTPARAMETERISGIXPROC) (GLuint list, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, const GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGetListParameterfvSGIX (GLuint list, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetListParameterivSGIX (GLuint list, GLenum pname, GLint *params);
+GLAPI void APIENTRY glListParameterfSGIX (GLuint list, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glListParameterfvSGIX (GLuint list, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glListParameteriSGIX (GLuint list, GLenum pname, GLint param);
+GLAPI void APIENTRY glListParameterivSGIX (GLuint list, GLenum pname, const GLint *params);
+#endif
+#endif /* GL_SGIX_list_priority */
+
+#ifndef GL_SGIX_pixel_texture
+#define GL_SGIX_pixel_texture 1
+#define GL_PIXEL_TEX_GEN_SGIX 0x8139
+#define GL_PIXEL_TEX_GEN_MODE_SGIX 0x832B
+typedef void (APIENTRYP PFNGLPIXELTEXGENSGIXPROC) (GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPixelTexGenSGIX (GLenum mode);
+#endif
+#endif /* GL_SGIX_pixel_texture */
+
+#ifndef GL_SGIX_pixel_tiles
+#define GL_SGIX_pixel_tiles 1
+#define GL_PIXEL_TILE_BEST_ALIGNMENT_SGIX 0x813E
+#define GL_PIXEL_TILE_CACHE_INCREMENT_SGIX 0x813F
+#define GL_PIXEL_TILE_WIDTH_SGIX 0x8140
+#define GL_PIXEL_TILE_HEIGHT_SGIX 0x8141
+#define GL_PIXEL_TILE_GRID_WIDTH_SGIX 0x8142
+#define GL_PIXEL_TILE_GRID_HEIGHT_SGIX 0x8143
+#define GL_PIXEL_TILE_GRID_DEPTH_SGIX 0x8144
+#define GL_PIXEL_TILE_CACHE_SIZE_SGIX 0x8145
+#endif /* GL_SGIX_pixel_tiles */
+
+#ifndef GL_SGIX_polynomial_ffd
+#define GL_SGIX_polynomial_ffd 1
+#define GL_TEXTURE_DEFORMATION_BIT_SGIX 0x00000001
+#define GL_GEOMETRY_DEFORMATION_BIT_SGIX 0x00000002
+#define GL_GEOMETRY_DEFORMATION_SGIX 0x8194
+#define GL_TEXTURE_DEFORMATION_SGIX 0x8195
+#define GL_DEFORMATIONS_MASK_SGIX 0x8196
+#define GL_MAX_DEFORMATION_ORDER_SGIX 0x8197
+typedef void (APIENTRYP PFNGLDEFORMATIONMAP3DSGIXPROC) (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble w1, GLdouble w2, GLint wstride, GLint worder, const GLdouble *points);
+typedef void (APIENTRYP PFNGLDEFORMATIONMAP3FSGIXPROC) (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat w1, GLfloat w2, GLint wstride, GLint worder, const GLfloat *points);
+typedef void (APIENTRYP PFNGLDEFORMSGIXPROC) (GLbitfield mask);
+typedef void (APIENTRYP PFNGLLOADIDENTITYDEFORMATIONMAPSGIXPROC) (GLbitfield mask);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDeformationMap3dSGIX (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble w1, GLdouble w2, GLint wstride, GLint worder, const GLdouble *points);
+GLAPI void APIENTRY glDeformationMap3fSGIX (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat w1, GLfloat w2, GLint wstride, GLint worder, const GLfloat *points);
+GLAPI void APIENTRY glDeformSGIX (GLbitfield mask);
+GLAPI void APIENTRY glLoadIdentityDeformationMapSGIX (GLbitfield mask);
+#endif
+#endif /* GL_SGIX_polynomial_ffd */
+
+#ifndef GL_SGIX_reference_plane
+#define GL_SGIX_reference_plane 1
+#define GL_REFERENCE_PLANE_SGIX 0x817D
+#define GL_REFERENCE_PLANE_EQUATION_SGIX 0x817E
+typedef void (APIENTRYP PFNGLREFERENCEPLANESGIXPROC) (const GLdouble *equation);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glReferencePlaneSGIX (const GLdouble *equation);
+#endif
+#endif /* GL_SGIX_reference_plane */
+
+#ifndef GL_SGIX_resample
+#define GL_SGIX_resample 1
+#define GL_PACK_RESAMPLE_SGIX 0x842C
+#define GL_UNPACK_RESAMPLE_SGIX 0x842D
+#define GL_RESAMPLE_REPLICATE_SGIX 0x842E
+#define GL_RESAMPLE_ZERO_FILL_SGIX 0x842F
+#define GL_RESAMPLE_DECIMATE_SGIX 0x8430
+#endif /* GL_SGIX_resample */
+
+#ifndef GL_SGIX_scalebias_hint
+#define GL_SGIX_scalebias_hint 1
+#define GL_SCALEBIAS_HINT_SGIX 0x8322
+#endif /* GL_SGIX_scalebias_hint */
+
+#ifndef GL_SGIX_shadow
+#define GL_SGIX_shadow 1
+#define GL_TEXTURE_COMPARE_SGIX 0x819A
+#define GL_TEXTURE_COMPARE_OPERATOR_SGIX 0x819B
+#define GL_TEXTURE_LEQUAL_R_SGIX 0x819C
+#define GL_TEXTURE_GEQUAL_R_SGIX 0x819D
+#endif /* GL_SGIX_shadow */
+
+#ifndef GL_SGIX_shadow_ambient
+#define GL_SGIX_shadow_ambient 1
+#define GL_SHADOW_AMBIENT_SGIX 0x80BF
+#endif /* GL_SGIX_shadow_ambient */
+
+#ifndef GL_SGIX_sprite
+#define GL_SGIX_sprite 1
+#define GL_SPRITE_SGIX 0x8148
+#define GL_SPRITE_MODE_SGIX 0x8149
+#define GL_SPRITE_AXIS_SGIX 0x814A
+#define GL_SPRITE_TRANSLATION_SGIX 0x814B
+#define GL_SPRITE_AXIAL_SGIX 0x814C
+#define GL_SPRITE_OBJECT_ALIGNED_SGIX 0x814D
+#define GL_SPRITE_EYE_ALIGNED_SGIX 0x814E
+typedef void (APIENTRYP PFNGLSPRITEPARAMETERFSGIXPROC) (GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLSPRITEPARAMETERFVSGIXPROC) (GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLSPRITEPARAMETERISGIXPROC) (GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLSPRITEPARAMETERIVSGIXPROC) (GLenum pname, const GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glSpriteParameterfSGIX (GLenum pname, GLfloat param);
+GLAPI void APIENTRY glSpriteParameterfvSGIX (GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glSpriteParameteriSGIX (GLenum pname, GLint param);
+GLAPI void APIENTRY glSpriteParameterivSGIX (GLenum pname, const GLint *params);
+#endif
+#endif /* GL_SGIX_sprite */
+
+#ifndef GL_SGIX_subsample
+#define GL_SGIX_subsample 1
+#define GL_PACK_SUBSAMPLE_RATE_SGIX 0x85A0
+#define GL_UNPACK_SUBSAMPLE_RATE_SGIX 0x85A1
+#define GL_PIXEL_SUBSAMPLE_4444_SGIX 0x85A2
+#define GL_PIXEL_SUBSAMPLE_2424_SGIX 0x85A3
+#define GL_PIXEL_SUBSAMPLE_4242_SGIX 0x85A4
+#endif /* GL_SGIX_subsample */
+
+#ifndef GL_SGIX_tag_sample_buffer
+#define GL_SGIX_tag_sample_buffer 1
+typedef void (APIENTRYP PFNGLTAGSAMPLEBUFFERSGIXPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTagSampleBufferSGIX (void);
+#endif
+#endif /* GL_SGIX_tag_sample_buffer */
+
+#ifndef GL_SGIX_texture_add_env
+#define GL_SGIX_texture_add_env 1
+#define GL_TEXTURE_ENV_BIAS_SGIX 0x80BE
+#endif /* GL_SGIX_texture_add_env */
+
+#ifndef GL_SGIX_texture_coordinate_clamp
+#define GL_SGIX_texture_coordinate_clamp 1
+#define GL_TEXTURE_MAX_CLAMP_S_SGIX 0x8369
+#define GL_TEXTURE_MAX_CLAMP_T_SGIX 0x836A
+#define GL_TEXTURE_MAX_CLAMP_R_SGIX 0x836B
+#endif /* GL_SGIX_texture_coordinate_clamp */
+
+#ifndef GL_SGIX_texture_lod_bias
+#define GL_SGIX_texture_lod_bias 1
+#define GL_TEXTURE_LOD_BIAS_S_SGIX 0x818E
+#define GL_TEXTURE_LOD_BIAS_T_SGIX 0x818F
+#define GL_TEXTURE_LOD_BIAS_R_SGIX 0x8190
+#endif /* GL_SGIX_texture_lod_bias */
+
+#ifndef GL_SGIX_texture_multi_buffer
+#define GL_SGIX_texture_multi_buffer 1
+#define GL_TEXTURE_MULTI_BUFFER_HINT_SGIX 0x812E
+#endif /* GL_SGIX_texture_multi_buffer */
+
+#ifndef GL_SGIX_texture_scale_bias
+#define GL_SGIX_texture_scale_bias 1
+#define GL_POST_TEXTURE_FILTER_BIAS_SGIX 0x8179
+#define GL_POST_TEXTURE_FILTER_SCALE_SGIX 0x817A
+#define GL_POST_TEXTURE_FILTER_BIAS_RANGE_SGIX 0x817B
+#define GL_POST_TEXTURE_FILTER_SCALE_RANGE_SGIX 0x817C
+#endif /* GL_SGIX_texture_scale_bias */
+
+#ifndef GL_SGIX_vertex_preclip
+#define GL_SGIX_vertex_preclip 1
+#define GL_VERTEX_PRECLIP_SGIX 0x83EE
+#define GL_VERTEX_PRECLIP_HINT_SGIX 0x83EF
+#endif /* GL_SGIX_vertex_preclip */
+
+#ifndef GL_SGIX_ycrcb
+#define GL_SGIX_ycrcb 1
+#define GL_YCRCB_422_SGIX 0x81BB
+#define GL_YCRCB_444_SGIX 0x81BC
+#endif /* GL_SGIX_ycrcb */
+
+#ifndef GL_SGIX_ycrcb_subsample
+#define GL_SGIX_ycrcb_subsample 1
+#endif /* GL_SGIX_ycrcb_subsample */
+
+#ifndef GL_SGIX_ycrcba
+#define GL_SGIX_ycrcba 1
+#define GL_YCRCB_SGIX 0x8318
+#define GL_YCRCBA_SGIX 0x8319
+#endif /* GL_SGIX_ycrcba */
+
+#ifndef GL_SGI_color_matrix
+#define GL_SGI_color_matrix 1
+#define GL_COLOR_MATRIX_SGI 0x80B1
+#define GL_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B2
+#define GL_MAX_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B3
+#define GL_POST_COLOR_MATRIX_RED_SCALE_SGI 0x80B4
+#define GL_POST_COLOR_MATRIX_GREEN_SCALE_SGI 0x80B5
+#define GL_POST_COLOR_MATRIX_BLUE_SCALE_SGI 0x80B6
+#define GL_POST_COLOR_MATRIX_ALPHA_SCALE_SGI 0x80B7
+#define GL_POST_COLOR_MATRIX_RED_BIAS_SGI 0x80B8
+#define GL_POST_COLOR_MATRIX_GREEN_BIAS_SGI 0x80B9
+#define GL_POST_COLOR_MATRIX_BLUE_BIAS_SGI 0x80BA
+#define GL_POST_COLOR_MATRIX_ALPHA_BIAS_SGI 0x80BB
+#endif /* GL_SGI_color_matrix */
+
+#ifndef GL_SGI_color_table
+#define GL_SGI_color_table 1
+#define GL_COLOR_TABLE_SGI 0x80D0
+#define GL_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D1
+#define GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D2
+#define GL_PROXY_COLOR_TABLE_SGI 0x80D3
+#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D4
+#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D5
+#define GL_COLOR_TABLE_SCALE_SGI 0x80D6
+#define GL_COLOR_TABLE_BIAS_SGI 0x80D7
+#define GL_COLOR_TABLE_FORMAT_SGI 0x80D8
+#define GL_COLOR_TABLE_WIDTH_SGI 0x80D9
+#define GL_COLOR_TABLE_RED_SIZE_SGI 0x80DA
+#define GL_COLOR_TABLE_GREEN_SIZE_SGI 0x80DB
+#define GL_COLOR_TABLE_BLUE_SIZE_SGI 0x80DC
+#define GL_COLOR_TABLE_ALPHA_SIZE_SGI 0x80DD
+#define GL_COLOR_TABLE_LUMINANCE_SIZE_SGI 0x80DE
+#define GL_COLOR_TABLE_INTENSITY_SIZE_SGI 0x80DF
+typedef void (APIENTRYP PFNGLCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *table);
+typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLCOPYCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width);
+typedef void (APIENTRYP PFNGLGETCOLORTABLESGIPROC) (GLenum target, GLenum format, GLenum type, void *table);
+typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glColorTableSGI (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *table);
+GLAPI void APIENTRY glColorTableParameterfvSGI (GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glColorTableParameterivSGI (GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glCopyColorTableSGI (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width);
+GLAPI void APIENTRY glGetColorTableSGI (GLenum target, GLenum format, GLenum type, void *table);
+GLAPI void APIENTRY glGetColorTableParameterfvSGI (GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetColorTableParameterivSGI (GLenum target, GLenum pname, GLint *params);
+#endif
+#endif /* GL_SGI_color_table */
+
+#ifndef GL_SGI_texture_color_table
+#define GL_SGI_texture_color_table 1
+#define GL_TEXTURE_COLOR_TABLE_SGI 0x80BC
+#define GL_PROXY_TEXTURE_COLOR_TABLE_SGI 0x80BD
+#endif /* GL_SGI_texture_color_table */
+
+#ifndef GL_SUNX_constant_data
+#define GL_SUNX_constant_data 1
+#define GL_UNPACK_CONSTANT_DATA_SUNX 0x81D5
+#define GL_TEXTURE_CONSTANT_DATA_SUNX 0x81D6
+typedef void (APIENTRYP PFNGLFINISHTEXTURESUNXPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glFinishTextureSUNX (void);
+#endif
+#endif /* GL_SUNX_constant_data */
+
+#ifndef GL_SUN_convolution_border_modes
+#define GL_SUN_convolution_border_modes 1
+#define GL_WRAP_BORDER_SUN 0x81D4
+#endif /* GL_SUN_convolution_border_modes */
+
+#ifndef GL_SUN_global_alpha
+#define GL_SUN_global_alpha 1
+#define GL_GLOBAL_ALPHA_SUN 0x81D9
+#define GL_GLOBAL_ALPHA_FACTOR_SUN 0x81DA
+typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORBSUNPROC) (GLbyte factor);
+typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORSSUNPROC) (GLshort factor);
+typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORISUNPROC) (GLint factor);
+typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORFSUNPROC) (GLfloat factor);
+typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORDSUNPROC) (GLdouble factor);
+typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUBSUNPROC) (GLubyte factor);
+typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUSSUNPROC) (GLushort factor);
+typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUISUNPROC) (GLuint factor);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGlobalAlphaFactorbSUN (GLbyte factor);
+GLAPI void APIENTRY glGlobalAlphaFactorsSUN (GLshort factor);
+GLAPI void APIENTRY glGlobalAlphaFactoriSUN (GLint factor);
+GLAPI void APIENTRY glGlobalAlphaFactorfSUN (GLfloat factor);
+GLAPI void APIENTRY glGlobalAlphaFactordSUN (GLdouble factor);
+GLAPI void APIENTRY glGlobalAlphaFactorubSUN (GLubyte factor);
+GLAPI void APIENTRY glGlobalAlphaFactorusSUN (GLushort factor);
+GLAPI void APIENTRY glGlobalAlphaFactoruiSUN (GLuint factor);
+#endif
+#endif /* GL_SUN_global_alpha */
+
+#ifndef GL_SUN_mesh_array
+#define GL_SUN_mesh_array 1
+#define GL_QUAD_MESH_SUN 0x8614
+#define GL_TRIANGLE_MESH_SUN 0x8615
+typedef void (APIENTRYP PFNGLDRAWMESHARRAYSSUNPROC) (GLenum mode, GLint first, GLsizei count, GLsizei width);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawMeshArraysSUN (GLenum mode, GLint first, GLsizei count, GLsizei width);
+#endif
+#endif /* GL_SUN_mesh_array */
+
+#ifndef GL_SUN_slice_accum
+#define GL_SUN_slice_accum 1
+#define GL_SLICE_ACCUM_SUN 0x85CC
+#endif /* GL_SUN_slice_accum */
+
+#ifndef GL_SUN_triangle_list
+#define GL_SUN_triangle_list 1
+#define GL_RESTART_SUN 0x0001
+#define GL_REPLACE_MIDDLE_SUN 0x0002
+#define GL_REPLACE_OLDEST_SUN 0x0003
+#define GL_TRIANGLE_LIST_SUN 0x81D7
+#define GL_REPLACEMENT_CODE_SUN 0x81D8
+#define GL_REPLACEMENT_CODE_ARRAY_SUN 0x85C0
+#define GL_REPLACEMENT_CODE_ARRAY_TYPE_SUN 0x85C1
+#define GL_REPLACEMENT_CODE_ARRAY_STRIDE_SUN 0x85C2
+#define GL_REPLACEMENT_CODE_ARRAY_POINTER_SUN 0x85C3
+#define GL_R1UI_V3F_SUN 0x85C4
+#define GL_R1UI_C4UB_V3F_SUN 0x85C5
+#define GL_R1UI_C3F_V3F_SUN 0x85C6
+#define GL_R1UI_N3F_V3F_SUN 0x85C7
+#define GL_R1UI_C4F_N3F_V3F_SUN 0x85C8
+#define GL_R1UI_T2F_V3F_SUN 0x85C9
+#define GL_R1UI_T2F_N3F_V3F_SUN 0x85CA
+#define GL_R1UI_T2F_C4F_N3F_V3F_SUN 0x85CB
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUISUNPROC) (GLuint code);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSSUNPROC) (GLushort code);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBSUNPROC) (GLubyte code);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVSUNPROC) (const GLuint *code);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSVSUNPROC) (const GLushort *code);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBVSUNPROC) (const GLubyte *code);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEPOINTERSUNPROC) (GLenum type, GLsizei stride, const void **pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glReplacementCodeuiSUN (GLuint code);
+GLAPI void APIENTRY glReplacementCodeusSUN (GLushort code);
+GLAPI void APIENTRY glReplacementCodeubSUN (GLubyte code);
+GLAPI void APIENTRY glReplacementCodeuivSUN (const GLuint *code);
+GLAPI void APIENTRY glReplacementCodeusvSUN (const GLushort *code);
+GLAPI void APIENTRY glReplacementCodeubvSUN (const GLubyte *code);
+GLAPI void APIENTRY glReplacementCodePointerSUN (GLenum type, GLsizei stride, const void **pointer);
+#endif
+#endif /* GL_SUN_triangle_list */
+
+#ifndef GL_SUN_vertex
+#define GL_SUN_vertex 1
+typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y);
+typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FVSUNPROC) (const GLubyte *c, const GLfloat *v);
+typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FVSUNPROC) (const GLubyte *c, const GLfloat *v);
+typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *v);
+typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FSUNPROC) (GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *n, const GLfloat *v);
+typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *n, const GLfloat *v);
+typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *v);
+typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *v);
+typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FVSUNPROC) (const GLfloat *tc, const GLubyte *c, const GLfloat *v);
+typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *v);
+typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *n, const GLfloat *v);
+typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v);
+typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FSUNPROC) (GLuint rc, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *v);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FSUNPROC) (GLuint rc, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FVSUNPROC) (const GLuint *rc, const GLubyte *c, const GLfloat *v);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *v);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *n, const GLfloat *v);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *n, const GLfloat *v);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *v);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *n, const GLfloat *v);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glColor4ubVertex2fSUN (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y);
+GLAPI void APIENTRY glColor4ubVertex2fvSUN (const GLubyte *c, const GLfloat *v);
+GLAPI void APIENTRY glColor4ubVertex3fSUN (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glColor4ubVertex3fvSUN (const GLubyte *c, const GLfloat *v);
+GLAPI void APIENTRY glColor3fVertex3fSUN (GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glColor3fVertex3fvSUN (const GLfloat *c, const GLfloat *v);
+GLAPI void APIENTRY glNormal3fVertex3fSUN (GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glNormal3fVertex3fvSUN (const GLfloat *n, const GLfloat *v);
+GLAPI void APIENTRY glColor4fNormal3fVertex3fSUN (GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glColor4fNormal3fVertex3fvSUN (const GLfloat *c, const GLfloat *n, const GLfloat *v);
+GLAPI void APIENTRY glTexCoord2fVertex3fSUN (GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glTexCoord2fVertex3fvSUN (const GLfloat *tc, const GLfloat *v);
+GLAPI void APIENTRY glTexCoord4fVertex4fSUN (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glTexCoord4fVertex4fvSUN (const GLfloat *tc, const GLfloat *v);
+GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fSUN (GLfloat s, GLfloat t, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fvSUN (const GLfloat *tc, const GLubyte *c, const GLfloat *v);
+GLAPI void APIENTRY glTexCoord2fColor3fVertex3fSUN (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glTexCoord2fColor3fVertex3fvSUN (const GLfloat *tc, const GLfloat *c, const GLfloat *v);
+GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fSUN (GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fvSUN (const GLfloat *tc, const GLfloat *n, const GLfloat *v);
+GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fSUN (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fvSUN (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v);
+GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fSUN (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fvSUN (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v);
+GLAPI void APIENTRY glReplacementCodeuiVertex3fSUN (GLuint rc, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glReplacementCodeuiVertex3fvSUN (const GLuint *rc, const GLfloat *v);
+GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fSUN (GLuint rc, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fvSUN (const GLuint *rc, const GLubyte *c, const GLfloat *v);
+GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fSUN (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fvSUN (const GLuint *rc, const GLfloat *c, const GLfloat *v);
+GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fSUN (GLuint rc, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *n, const GLfloat *v);
+GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fSUN (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *c, const GLfloat *n, const GLfloat *v);
+GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fSUN (GLuint rc, GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fvSUN (const GLuint *rc, const GLfloat *tc, const GLfloat *v);
+GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fSUN (GLuint rc, GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *tc, const GLfloat *n, const GLfloat *v);
+GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN (GLuint rc, GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v);
+#endif
+#endif /* GL_SUN_vertex */
+
+#ifndef GL_WIN_phong_shading
+#define GL_WIN_phong_shading 1
+#define GL_PHONG_WIN 0x80EA
+#define GL_PHONG_HINT_WIN 0x80EB
+#endif /* GL_WIN_phong_shading */
+
+#ifndef GL_WIN_specular_fog
+#define GL_WIN_specular_fog 1
+#define GL_FOG_SPECULAR_TEXTURE_WIN 0x80EC
+#endif /* GL_WIN_specular_fog */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_opengles.h b/src/3rdparty/SDL2/include/SDL2/SDL_opengles.h
new file mode 100644
index 0000000..18dd984
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_opengles.h
@@ -0,0 +1,39 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_opengles.h
+ *
+ * This is a simple file to encapsulate the OpenGL ES 1.X API headers.
+ */
+#include "SDL_config.h"
+
+#ifdef __IPHONEOS__
+#include <OpenGLES/ES1/gl.h>
+#include <OpenGLES/ES1/glext.h>
+#else
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#endif
+
+#ifndef APIENTRY
+#define APIENTRY
+#endif
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_opengles2.h b/src/3rdparty/SDL2/include/SDL2/SDL_opengles2.h
new file mode 100644
index 0000000..6ccecf2
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_opengles2.h
@@ -0,0 +1,52 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_opengles2.h
+ *
+ * This is a simple file to encapsulate the OpenGL ES 2.0 API headers.
+ */
+#include "SDL_config.h"
+
+#ifndef _MSC_VER
+
+#ifdef __IPHONEOS__
+#include <OpenGLES/ES2/gl.h>
+#include <OpenGLES/ES2/glext.h>
+#else
+#include <GLES2/gl2platform.h>
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#endif
+
+#else /* _MSC_VER */
+
+/* OpenGL ES2 headers for Visual Studio */
+#include "SDL_opengles2_khrplatform.h"
+#include "SDL_opengles2_gl2platform.h"
+#include "SDL_opengles2_gl2.h"
+#include "SDL_opengles2_gl2ext.h"
+
+#endif /* _MSC_VER */
+
+#ifndef APIENTRY
+#define APIENTRY GL_APIENTRY
+#endif
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_opengles2_gl2.h b/src/3rdparty/SDL2/include/SDL2/SDL_opengles2_gl2.h
new file mode 100644
index 0000000..c62fb0a
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_opengles2_gl2.h
@@ -0,0 +1,621 @@
+#ifndef __gl2_h_
+#define __gl2_h_
+
+/* $Revision: 20555 $ on $Date:: 2013-02-12 14:32:47 -0800 #$ */
+
+/*#include <GLES2/gl2platform.h>*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This document is licensed under the SGI Free Software B License Version
+ * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ .
+ */
+
+/*-------------------------------------------------------------------------
+ * Data type definitions
+ *-----------------------------------------------------------------------*/
+
+typedef void GLvoid;
+typedef char GLchar;
+typedef unsigned int GLenum;
+typedef unsigned char GLboolean;
+typedef unsigned int GLbitfield;
+typedef khronos_int8_t GLbyte;
+typedef short GLshort;
+typedef int GLint;
+typedef int GLsizei;
+typedef khronos_uint8_t GLubyte;
+typedef unsigned short GLushort;
+typedef unsigned int GLuint;
+typedef khronos_float_t GLfloat;
+typedef khronos_float_t GLclampf;
+typedef khronos_int32_t GLfixed;
+
+/* GL types for handling large vertex buffer objects */
+typedef khronos_intptr_t GLintptr;
+typedef khronos_ssize_t GLsizeiptr;
+
+/* OpenGL ES core versions */
+#define GL_ES_VERSION_2_0 1
+
+/* ClearBufferMask */
+#define GL_DEPTH_BUFFER_BIT 0x00000100
+#define GL_STENCIL_BUFFER_BIT 0x00000400
+#define GL_COLOR_BUFFER_BIT 0x00004000
+
+/* Boolean */
+#define GL_FALSE 0
+#define GL_TRUE 1
+
+/* BeginMode */
+#define GL_POINTS 0x0000
+#define GL_LINES 0x0001
+#define GL_LINE_LOOP 0x0002
+#define GL_LINE_STRIP 0x0003
+#define GL_TRIANGLES 0x0004
+#define GL_TRIANGLE_STRIP 0x0005
+#define GL_TRIANGLE_FAN 0x0006
+
+/* AlphaFunction (not supported in ES20) */
+/* GL_NEVER */
+/* GL_LESS */
+/* GL_EQUAL */
+/* GL_LEQUAL */
+/* GL_GREATER */
+/* GL_NOTEQUAL */
+/* GL_GEQUAL */
+/* GL_ALWAYS */
+
+/* BlendingFactorDest */
+#define GL_ZERO 0
+#define GL_ONE 1
+#define GL_SRC_COLOR 0x0300
+#define GL_ONE_MINUS_SRC_COLOR 0x0301
+#define GL_SRC_ALPHA 0x0302
+#define GL_ONE_MINUS_SRC_ALPHA 0x0303
+#define GL_DST_ALPHA 0x0304
+#define GL_ONE_MINUS_DST_ALPHA 0x0305
+
+/* BlendingFactorSrc */
+/* GL_ZERO */
+/* GL_ONE */
+#define GL_DST_COLOR 0x0306
+#define GL_ONE_MINUS_DST_COLOR 0x0307
+#define GL_SRC_ALPHA_SATURATE 0x0308
+/* GL_SRC_ALPHA */
+/* GL_ONE_MINUS_SRC_ALPHA */
+/* GL_DST_ALPHA */
+/* GL_ONE_MINUS_DST_ALPHA */
+
+/* BlendEquationSeparate */
+#define GL_FUNC_ADD 0x8006
+#define GL_BLEND_EQUATION 0x8009
+#define GL_BLEND_EQUATION_RGB 0x8009 /* same as BLEND_EQUATION */
+#define GL_BLEND_EQUATION_ALPHA 0x883D
+
+/* BlendSubtract */
+#define GL_FUNC_SUBTRACT 0x800A
+#define GL_FUNC_REVERSE_SUBTRACT 0x800B
+
+/* Separate Blend Functions */
+#define GL_BLEND_DST_RGB 0x80C8
+#define GL_BLEND_SRC_RGB 0x80C9
+#define GL_BLEND_DST_ALPHA 0x80CA
+#define GL_BLEND_SRC_ALPHA 0x80CB
+#define GL_CONSTANT_COLOR 0x8001
+#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002
+#define GL_CONSTANT_ALPHA 0x8003
+#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004
+#define GL_BLEND_COLOR 0x8005
+
+/* Buffer Objects */
+#define GL_ARRAY_BUFFER 0x8892
+#define GL_ELEMENT_ARRAY_BUFFER 0x8893
+#define GL_ARRAY_BUFFER_BINDING 0x8894
+#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895
+
+#define GL_STREAM_DRAW 0x88E0
+#define GL_STATIC_DRAW 0x88E4
+#define GL_DYNAMIC_DRAW 0x88E8
+
+#define GL_BUFFER_SIZE 0x8764
+#define GL_BUFFER_USAGE 0x8765
+
+#define GL_CURRENT_VERTEX_ATTRIB 0x8626
+
+/* CullFaceMode */
+#define GL_FRONT 0x0404
+#define GL_BACK 0x0405
+#define GL_FRONT_AND_BACK 0x0408
+
+/* DepthFunction */
+/* GL_NEVER */
+/* GL_LESS */
+/* GL_EQUAL */
+/* GL_LEQUAL */
+/* GL_GREATER */
+/* GL_NOTEQUAL */
+/* GL_GEQUAL */
+/* GL_ALWAYS */
+
+/* EnableCap */
+#define GL_TEXTURE_2D 0x0DE1
+#define GL_CULL_FACE 0x0B44
+#define GL_BLEND 0x0BE2
+#define GL_DITHER 0x0BD0
+#define GL_STENCIL_TEST 0x0B90
+#define GL_DEPTH_TEST 0x0B71
+#define GL_SCISSOR_TEST 0x0C11
+#define GL_POLYGON_OFFSET_FILL 0x8037
+#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E
+#define GL_SAMPLE_COVERAGE 0x80A0
+
+/* ErrorCode */
+#define GL_NO_ERROR 0
+#define GL_INVALID_ENUM 0x0500
+#define GL_INVALID_VALUE 0x0501
+#define GL_INVALID_OPERATION 0x0502
+#define GL_OUT_OF_MEMORY 0x0505
+
+/* FrontFaceDirection */
+#define GL_CW 0x0900
+#define GL_CCW 0x0901
+
+/* GetPName */
+#define GL_LINE_WIDTH 0x0B21
+#define GL_ALIASED_POINT_SIZE_RANGE 0x846D
+#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E
+#define GL_CULL_FACE_MODE 0x0B45
+#define GL_FRONT_FACE 0x0B46
+#define GL_DEPTH_RANGE 0x0B70
+#define GL_DEPTH_WRITEMASK 0x0B72
+#define GL_DEPTH_CLEAR_VALUE 0x0B73
+#define GL_DEPTH_FUNC 0x0B74
+#define GL_STENCIL_CLEAR_VALUE 0x0B91
+#define GL_STENCIL_FUNC 0x0B92
+#define GL_STENCIL_FAIL 0x0B94
+#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95
+#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96
+#define GL_STENCIL_REF 0x0B97
+#define GL_STENCIL_VALUE_MASK 0x0B93
+#define GL_STENCIL_WRITEMASK 0x0B98
+#define GL_STENCIL_BACK_FUNC 0x8800
+#define GL_STENCIL_BACK_FAIL 0x8801
+#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802
+#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803
+#define GL_STENCIL_BACK_REF 0x8CA3
+#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4
+#define GL_STENCIL_BACK_WRITEMASK 0x8CA5
+#define GL_VIEWPORT 0x0BA2
+#define GL_SCISSOR_BOX 0x0C10
+/* GL_SCISSOR_TEST */
+#define GL_COLOR_CLEAR_VALUE 0x0C22
+#define GL_COLOR_WRITEMASK 0x0C23
+#define GL_UNPACK_ALIGNMENT 0x0CF5
+#define GL_PACK_ALIGNMENT 0x0D05
+#define GL_MAX_TEXTURE_SIZE 0x0D33
+#define GL_MAX_VIEWPORT_DIMS 0x0D3A
+#define GL_SUBPIXEL_BITS 0x0D50
+#define GL_RED_BITS 0x0D52
+#define GL_GREEN_BITS 0x0D53
+#define GL_BLUE_BITS 0x0D54
+#define GL_ALPHA_BITS 0x0D55
+#define GL_DEPTH_BITS 0x0D56
+#define GL_STENCIL_BITS 0x0D57
+#define GL_POLYGON_OFFSET_UNITS 0x2A00
+/* GL_POLYGON_OFFSET_FILL */
+#define GL_POLYGON_OFFSET_FACTOR 0x8038
+#define GL_TEXTURE_BINDING_2D 0x8069
+#define GL_SAMPLE_BUFFERS 0x80A8
+#define GL_SAMPLES 0x80A9
+#define GL_SAMPLE_COVERAGE_VALUE 0x80AA
+#define GL_SAMPLE_COVERAGE_INVERT 0x80AB
+
+/* GetTextureParameter */
+/* GL_TEXTURE_MAG_FILTER */
+/* GL_TEXTURE_MIN_FILTER */
+/* GL_TEXTURE_WRAP_S */
+/* GL_TEXTURE_WRAP_T */
+
+#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2
+#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3
+
+/* HintMode */
+#define GL_DONT_CARE 0x1100
+#define GL_FASTEST 0x1101
+#define GL_NICEST 0x1102
+
+/* HintTarget */
+#define GL_GENERATE_MIPMAP_HINT 0x8192
+
+/* DataType */
+#define GL_BYTE 0x1400
+#define GL_UNSIGNED_BYTE 0x1401
+#define GL_SHORT 0x1402
+#define GL_UNSIGNED_SHORT 0x1403
+#define GL_INT 0x1404
+#define GL_UNSIGNED_INT 0x1405
+#define GL_FLOAT 0x1406
+#define GL_FIXED 0x140C
+
+/* PixelFormat */
+#define GL_DEPTH_COMPONENT 0x1902
+#define GL_ALPHA 0x1906
+#define GL_RGB 0x1907
+#define GL_RGBA 0x1908
+#define GL_LUMINANCE 0x1909
+#define GL_LUMINANCE_ALPHA 0x190A
+
+/* PixelType */
+/* GL_UNSIGNED_BYTE */
+#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
+#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
+#define GL_UNSIGNED_SHORT_5_6_5 0x8363
+
+/* Shaders */
+#define GL_FRAGMENT_SHADER 0x8B30
+#define GL_VERTEX_SHADER 0x8B31
+#define GL_MAX_VERTEX_ATTRIBS 0x8869
+#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB
+#define GL_MAX_VARYING_VECTORS 0x8DFC
+#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D
+#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C
+#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872
+#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD
+#define GL_SHADER_TYPE 0x8B4F
+#define GL_DELETE_STATUS 0x8B80
+#define GL_LINK_STATUS 0x8B82
+#define GL_VALIDATE_STATUS 0x8B83
+#define GL_ATTACHED_SHADERS 0x8B85
+#define GL_ACTIVE_UNIFORMS 0x8B86
+#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87
+#define GL_ACTIVE_ATTRIBUTES 0x8B89
+#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A
+#define GL_SHADING_LANGUAGE_VERSION 0x8B8C
+#define GL_CURRENT_PROGRAM 0x8B8D
+
+/* StencilFunction */
+#define GL_NEVER 0x0200
+#define GL_LESS 0x0201
+#define GL_EQUAL 0x0202
+#define GL_LEQUAL 0x0203
+#define GL_GREATER 0x0204
+#define GL_NOTEQUAL 0x0205
+#define GL_GEQUAL 0x0206
+#define GL_ALWAYS 0x0207
+
+/* StencilOp */
+/* GL_ZERO */
+#define GL_KEEP 0x1E00
+#define GL_REPLACE 0x1E01
+#define GL_INCR 0x1E02
+#define GL_DECR 0x1E03
+#define GL_INVERT 0x150A
+#define GL_INCR_WRAP 0x8507
+#define GL_DECR_WRAP 0x8508
+
+/* StringName */
+#define GL_VENDOR 0x1F00
+#define GL_RENDERER 0x1F01
+#define GL_VERSION 0x1F02
+#define GL_EXTENSIONS 0x1F03
+
+/* TextureMagFilter */
+#define GL_NEAREST 0x2600
+#define GL_LINEAR 0x2601
+
+/* TextureMinFilter */
+/* GL_NEAREST */
+/* GL_LINEAR */
+#define GL_NEAREST_MIPMAP_NEAREST 0x2700
+#define GL_LINEAR_MIPMAP_NEAREST 0x2701
+#define GL_NEAREST_MIPMAP_LINEAR 0x2702
+#define GL_LINEAR_MIPMAP_LINEAR 0x2703
+
+/* TextureParameterName */
+#define GL_TEXTURE_MAG_FILTER 0x2800
+#define GL_TEXTURE_MIN_FILTER 0x2801
+#define GL_TEXTURE_WRAP_S 0x2802
+#define GL_TEXTURE_WRAP_T 0x2803
+
+/* TextureTarget */
+/* GL_TEXTURE_2D */
+#define GL_TEXTURE 0x1702
+
+#define GL_TEXTURE_CUBE_MAP 0x8513
+#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
+#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C
+
+/* TextureUnit */
+#define GL_TEXTURE0 0x84C0
+#define GL_TEXTURE1 0x84C1
+#define GL_TEXTURE2 0x84C2
+#define GL_TEXTURE3 0x84C3
+#define GL_TEXTURE4 0x84C4
+#define GL_TEXTURE5 0x84C5
+#define GL_TEXTURE6 0x84C6
+#define GL_TEXTURE7 0x84C7
+#define GL_TEXTURE8 0x84C8
+#define GL_TEXTURE9 0x84C9
+#define GL_TEXTURE10 0x84CA
+#define GL_TEXTURE11 0x84CB
+#define GL_TEXTURE12 0x84CC
+#define GL_TEXTURE13 0x84CD
+#define GL_TEXTURE14 0x84CE
+#define GL_TEXTURE15 0x84CF
+#define GL_TEXTURE16 0x84D0
+#define GL_TEXTURE17 0x84D1
+#define GL_TEXTURE18 0x84D2
+#define GL_TEXTURE19 0x84D3
+#define GL_TEXTURE20 0x84D4
+#define GL_TEXTURE21 0x84D5
+#define GL_TEXTURE22 0x84D6
+#define GL_TEXTURE23 0x84D7
+#define GL_TEXTURE24 0x84D8
+#define GL_TEXTURE25 0x84D9
+#define GL_TEXTURE26 0x84DA
+#define GL_TEXTURE27 0x84DB
+#define GL_TEXTURE28 0x84DC
+#define GL_TEXTURE29 0x84DD
+#define GL_TEXTURE30 0x84DE
+#define GL_TEXTURE31 0x84DF
+#define GL_ACTIVE_TEXTURE 0x84E0
+
+/* TextureWrapMode */
+#define GL_REPEAT 0x2901
+#define GL_CLAMP_TO_EDGE 0x812F
+#define GL_MIRRORED_REPEAT 0x8370
+
+/* Uniform Types */
+#define GL_FLOAT_VEC2 0x8B50
+#define GL_FLOAT_VEC3 0x8B51
+#define GL_FLOAT_VEC4 0x8B52
+#define GL_INT_VEC2 0x8B53
+#define GL_INT_VEC3 0x8B54
+#define GL_INT_VEC4 0x8B55
+#define GL_BOOL 0x8B56
+#define GL_BOOL_VEC2 0x8B57
+#define GL_BOOL_VEC3 0x8B58
+#define GL_BOOL_VEC4 0x8B59
+#define GL_FLOAT_MAT2 0x8B5A
+#define GL_FLOAT_MAT3 0x8B5B
+#define GL_FLOAT_MAT4 0x8B5C
+#define GL_SAMPLER_2D 0x8B5E
+#define GL_SAMPLER_CUBE 0x8B60
+
+/* Vertex Arrays */
+#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
+#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
+#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624
+#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625
+#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A
+#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645
+#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F
+
+/* Read Format */
+#define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A
+#define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B
+
+/* Shader Source */
+#define GL_COMPILE_STATUS 0x8B81
+#define GL_INFO_LOG_LENGTH 0x8B84
+#define GL_SHADER_SOURCE_LENGTH 0x8B88
+#define GL_SHADER_COMPILER 0x8DFA
+
+/* Shader Binary */
+#define GL_SHADER_BINARY_FORMATS 0x8DF8
+#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9
+
+/* Shader Precision-Specified Types */
+#define GL_LOW_FLOAT 0x8DF0
+#define GL_MEDIUM_FLOAT 0x8DF1
+#define GL_HIGH_FLOAT 0x8DF2
+#define GL_LOW_INT 0x8DF3
+#define GL_MEDIUM_INT 0x8DF4
+#define GL_HIGH_INT 0x8DF5
+
+/* Framebuffer Object. */
+#define GL_FRAMEBUFFER 0x8D40
+#define GL_RENDERBUFFER 0x8D41
+
+#define GL_RGBA4 0x8056
+#define GL_RGB5_A1 0x8057
+#define GL_RGB565 0x8D62
+#define GL_DEPTH_COMPONENT16 0x81A5
+#define GL_STENCIL_INDEX8 0x8D48
+
+#define GL_RENDERBUFFER_WIDTH 0x8D42
+#define GL_RENDERBUFFER_HEIGHT 0x8D43
+#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44
+#define GL_RENDERBUFFER_RED_SIZE 0x8D50
+#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51
+#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52
+#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53
+#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54
+#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55
+
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3
+
+#define GL_COLOR_ATTACHMENT0 0x8CE0
+#define GL_DEPTH_ATTACHMENT 0x8D00
+#define GL_STENCIL_ATTACHMENT 0x8D20
+
+#define GL_NONE 0
+
+#define GL_FRAMEBUFFER_COMPLETE 0x8CD5
+#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6
+#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7
+#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9
+#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD
+
+#define GL_FRAMEBUFFER_BINDING 0x8CA6
+#define GL_RENDERBUFFER_BINDING 0x8CA7
+#define GL_MAX_RENDERBUFFER_SIZE 0x84E8
+
+#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506
+
+/*-------------------------------------------------------------------------
+ * GL core functions.
+ *-----------------------------------------------------------------------*/
+
+GL_APICALL void GL_APIENTRY glActiveTexture (GLenum texture);
+GL_APICALL void GL_APIENTRY glAttachShader (GLuint program, GLuint shader);
+GL_APICALL void GL_APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar* name);
+GL_APICALL void GL_APIENTRY glBindBuffer (GLenum target, GLuint buffer);
+GL_APICALL void GL_APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer);
+GL_APICALL void GL_APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer);
+GL_APICALL void GL_APIENTRY glBindTexture (GLenum target, GLuint texture);
+GL_APICALL void GL_APIENTRY glBlendColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
+GL_APICALL void GL_APIENTRY glBlendEquation ( GLenum mode );
+GL_APICALL void GL_APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha);
+GL_APICALL void GL_APIENTRY glBlendFunc (GLenum sfactor, GLenum dfactor);
+GL_APICALL void GL_APIENTRY glBlendFuncSeparate (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+GL_APICALL void GL_APIENTRY glBufferData (GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage);
+GL_APICALL void GL_APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data);
+GL_APICALL GLenum GL_APIENTRY glCheckFramebufferStatus (GLenum target);
+GL_APICALL void GL_APIENTRY glClear (GLbitfield mask);
+GL_APICALL void GL_APIENTRY glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
+GL_APICALL void GL_APIENTRY glClearDepthf (GLclampf depth);
+GL_APICALL void GL_APIENTRY glClearStencil (GLint s);
+GL_APICALL void GL_APIENTRY glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
+GL_APICALL void GL_APIENTRY glCompileShader (GLuint shader);
+GL_APICALL void GL_APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid* data);
+GL_APICALL void GL_APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data);
+GL_APICALL void GL_APIENTRY glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+GL_APICALL void GL_APIENTRY glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+GL_APICALL GLuint GL_APIENTRY glCreateProgram (void);
+GL_APICALL GLuint GL_APIENTRY glCreateShader (GLenum type);
+GL_APICALL void GL_APIENTRY glCullFace (GLenum mode);
+GL_APICALL void GL_APIENTRY glDeleteBuffers (GLsizei n, const GLuint* buffers);
+GL_APICALL void GL_APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint* framebuffers);
+GL_APICALL void GL_APIENTRY glDeleteProgram (GLuint program);
+GL_APICALL void GL_APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint* renderbuffers);
+GL_APICALL void GL_APIENTRY glDeleteShader (GLuint shader);
+GL_APICALL void GL_APIENTRY glDeleteTextures (GLsizei n, const GLuint* textures);
+GL_APICALL void GL_APIENTRY glDepthFunc (GLenum func);
+GL_APICALL void GL_APIENTRY glDepthMask (GLboolean flag);
+GL_APICALL void GL_APIENTRY glDepthRangef (GLclampf zNear, GLclampf zFar);
+GL_APICALL void GL_APIENTRY glDetachShader (GLuint program, GLuint shader);
+GL_APICALL void GL_APIENTRY glDisable (GLenum cap);
+GL_APICALL void GL_APIENTRY glDisableVertexAttribArray (GLuint index);
+GL_APICALL void GL_APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count);
+GL_APICALL void GL_APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid* indices);
+GL_APICALL void GL_APIENTRY glEnable (GLenum cap);
+GL_APICALL void GL_APIENTRY glEnableVertexAttribArray (GLuint index);
+GL_APICALL void GL_APIENTRY glFinish (void);
+GL_APICALL void GL_APIENTRY glFlush (void);
+GL_APICALL void GL_APIENTRY glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
+GL_APICALL void GL_APIENTRY glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+GL_APICALL void GL_APIENTRY glFrontFace (GLenum mode);
+GL_APICALL void GL_APIENTRY glGenBuffers (GLsizei n, GLuint* buffers);
+GL_APICALL void GL_APIENTRY glGenerateMipmap (GLenum target);
+GL_APICALL void GL_APIENTRY glGenFramebuffers (GLsizei n, GLuint* framebuffers);
+GL_APICALL void GL_APIENTRY glGenRenderbuffers (GLsizei n, GLuint* renderbuffers);
+GL_APICALL void GL_APIENTRY glGenTextures (GLsizei n, GLuint* textures);
+GL_APICALL void GL_APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name);
+GL_APICALL void GL_APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name);
+GL_APICALL void GL_APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders);
+GL_APICALL GLint GL_APIENTRY glGetAttribLocation (GLuint program, const GLchar* name);
+GL_APICALL void GL_APIENTRY glGetBooleanv (GLenum pname, GLboolean* params);
+GL_APICALL void GL_APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint* params);
+GL_APICALL GLenum GL_APIENTRY glGetError (void);
+GL_APICALL void GL_APIENTRY glGetFloatv (GLenum pname, GLfloat* params);
+GL_APICALL void GL_APIENTRY glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint* params);
+GL_APICALL void GL_APIENTRY glGetIntegerv (GLenum pname, GLint* params);
+GL_APICALL void GL_APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint* params);
+GL_APICALL void GL_APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog);
+GL_APICALL void GL_APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint* params);
+GL_APICALL void GL_APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint* params);
+GL_APICALL void GL_APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog);
+GL_APICALL void GL_APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision);
+GL_APICALL void GL_APIENTRY glGetShaderSource (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source);
+GL_APICALL const GLubyte* GL_APIENTRY glGetString (GLenum name);
+GL_APICALL void GL_APIENTRY glGetTexParameterfv (GLenum target, GLenum pname, GLfloat* params);
+GL_APICALL void GL_APIENTRY glGetTexParameteriv (GLenum target, GLenum pname, GLint* params);
+GL_APICALL void GL_APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat* params);
+GL_APICALL void GL_APIENTRY glGetUniformiv (GLuint program, GLint location, GLint* params);
+GL_APICALL GLint GL_APIENTRY glGetUniformLocation (GLuint program, const GLchar* name);
+GL_APICALL void GL_APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat* params);
+GL_APICALL void GL_APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint* params);
+GL_APICALL void GL_APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, GLvoid** pointer);
+GL_APICALL void GL_APIENTRY glHint (GLenum target, GLenum mode);
+GL_APICALL GLboolean GL_APIENTRY glIsBuffer (GLuint buffer);
+GL_APICALL GLboolean GL_APIENTRY glIsEnabled (GLenum cap);
+GL_APICALL GLboolean GL_APIENTRY glIsFramebuffer (GLuint framebuffer);
+GL_APICALL GLboolean GL_APIENTRY glIsProgram (GLuint program);
+GL_APICALL GLboolean GL_APIENTRY glIsRenderbuffer (GLuint renderbuffer);
+GL_APICALL GLboolean GL_APIENTRY glIsShader (GLuint shader);
+GL_APICALL GLboolean GL_APIENTRY glIsTexture (GLuint texture);
+GL_APICALL void GL_APIENTRY glLineWidth (GLfloat width);
+GL_APICALL void GL_APIENTRY glLinkProgram (GLuint program);
+GL_APICALL void GL_APIENTRY glPixelStorei (GLenum pname, GLint param);
+GL_APICALL void GL_APIENTRY glPolygonOffset (GLfloat factor, GLfloat units);
+GL_APICALL void GL_APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels);
+GL_APICALL void GL_APIENTRY glReleaseShaderCompiler (void);
+GL_APICALL void GL_APIENTRY glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glSampleCoverage (GLclampf value, GLboolean invert);
+GL_APICALL void GL_APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glShaderBinary (GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length);
+GL_APICALL void GL_APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length);
+GL_APICALL void GL_APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask);
+GL_APICALL void GL_APIENTRY glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask);
+GL_APICALL void GL_APIENTRY glStencilMask (GLuint mask);
+GL_APICALL void GL_APIENTRY glStencilMaskSeparate (GLenum face, GLuint mask);
+GL_APICALL void GL_APIENTRY glStencilOp (GLenum fail, GLenum zfail, GLenum zpass);
+GL_APICALL void GL_APIENTRY glStencilOpSeparate (GLenum face, GLenum fail, GLenum zfail, GLenum zpass);
+GL_APICALL void GL_APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels);
+GL_APICALL void GL_APIENTRY glTexParameterf (GLenum target, GLenum pname, GLfloat param);
+GL_APICALL void GL_APIENTRY glTexParameterfv (GLenum target, GLenum pname, const GLfloat* params);
+GL_APICALL void GL_APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param);
+GL_APICALL void GL_APIENTRY glTexParameteriv (GLenum target, GLenum pname, const GLint* params);
+GL_APICALL void GL_APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels);
+GL_APICALL void GL_APIENTRY glUniform1f (GLint location, GLfloat x);
+GL_APICALL void GL_APIENTRY glUniform1fv (GLint location, GLsizei count, const GLfloat* v);
+GL_APICALL void GL_APIENTRY glUniform1i (GLint location, GLint x);
+GL_APICALL void GL_APIENTRY glUniform1iv (GLint location, GLsizei count, const GLint* v);
+GL_APICALL void GL_APIENTRY glUniform2f (GLint location, GLfloat x, GLfloat y);
+GL_APICALL void GL_APIENTRY glUniform2fv (GLint location, GLsizei count, const GLfloat* v);
+GL_APICALL void GL_APIENTRY glUniform2i (GLint location, GLint x, GLint y);
+GL_APICALL void GL_APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint* v);
+GL_APICALL void GL_APIENTRY glUniform3f (GLint location, GLfloat x, GLfloat y, GLfloat z);
+GL_APICALL void GL_APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat* v);
+GL_APICALL void GL_APIENTRY glUniform3i (GLint location, GLint x, GLint y, GLint z);
+GL_APICALL void GL_APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint* v);
+GL_APICALL void GL_APIENTRY glUniform4f (GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GL_APICALL void GL_APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat* v);
+GL_APICALL void GL_APIENTRY glUniform4i (GLint location, GLint x, GLint y, GLint z, GLint w);
+GL_APICALL void GL_APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint* v);
+GL_APICALL void GL_APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
+GL_APICALL void GL_APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
+GL_APICALL void GL_APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
+GL_APICALL void GL_APIENTRY glUseProgram (GLuint program);
+GL_APICALL void GL_APIENTRY glValidateProgram (GLuint program);
+GL_APICALL void GL_APIENTRY glVertexAttrib1f (GLuint indx, GLfloat x);
+GL_APICALL void GL_APIENTRY glVertexAttrib1fv (GLuint indx, const GLfloat* values);
+GL_APICALL void GL_APIENTRY glVertexAttrib2f (GLuint indx, GLfloat x, GLfloat y);
+GL_APICALL void GL_APIENTRY glVertexAttrib2fv (GLuint indx, const GLfloat* values);
+GL_APICALL void GL_APIENTRY glVertexAttrib3f (GLuint indx, GLfloat x, GLfloat y, GLfloat z);
+GL_APICALL void GL_APIENTRY glVertexAttrib3fv (GLuint indx, const GLfloat* values);
+GL_APICALL void GL_APIENTRY glVertexAttrib4f (GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GL_APICALL void GL_APIENTRY glVertexAttrib4fv (GLuint indx, const GLfloat* values);
+GL_APICALL void GL_APIENTRY glVertexAttribPointer (GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr);
+GL_APICALL void GL_APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __gl2_h_ */
+
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_opengles2_gl2ext.h b/src/3rdparty/SDL2/include/SDL2/SDL_opengles2_gl2ext.h
new file mode 100644
index 0000000..e8ca8b1
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_opengles2_gl2ext.h
@@ -0,0 +1,2050 @@
+#ifndef __gl2ext_h_
+#define __gl2ext_h_
+
+/* $Revision: 22801 $ on $Date:: 2013-08-21 03:20:48 -0700 #$ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This document is licensed under the SGI Free Software B License Version
+ * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ .
+ */
+
+#ifndef GL_APIENTRYP
+# define GL_APIENTRYP GL_APIENTRY*
+#endif
+
+/* New types shared by several extensions */
+
+#ifndef __gl3_h_
+/* These are defined with respect to <inttypes.h> in the
+ * Apple extension spec, but they are also used by non-APPLE
+ * extensions, and in the Khronos header we use the Khronos
+ * portable types in khrplatform.h, which must be defined.
+ */
+typedef khronos_int64_t GLint64;
+typedef khronos_uint64_t GLuint64;
+typedef struct __GLsync *GLsync;
+#endif
+
+
+/*------------------------------------------------------------------------*
+ * OES extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_OES_compressed_ETC1_RGB8_texture */
+#ifndef GL_OES_compressed_ETC1_RGB8_texture
+#define GL_ETC1_RGB8_OES 0x8D64
+#endif
+
+/* GL_OES_compressed_paletted_texture */
+#ifndef GL_OES_compressed_paletted_texture
+#define GL_PALETTE4_RGB8_OES 0x8B90
+#define GL_PALETTE4_RGBA8_OES 0x8B91
+#define GL_PALETTE4_R5_G6_B5_OES 0x8B92
+#define GL_PALETTE4_RGBA4_OES 0x8B93
+#define GL_PALETTE4_RGB5_A1_OES 0x8B94
+#define GL_PALETTE8_RGB8_OES 0x8B95
+#define GL_PALETTE8_RGBA8_OES 0x8B96
+#define GL_PALETTE8_R5_G6_B5_OES 0x8B97
+#define GL_PALETTE8_RGBA4_OES 0x8B98
+#define GL_PALETTE8_RGB5_A1_OES 0x8B99
+#endif
+
+/* GL_OES_depth24 */
+#ifndef GL_OES_depth24
+#define GL_DEPTH_COMPONENT24_OES 0x81A6
+#endif
+
+/* GL_OES_depth32 */
+#ifndef GL_OES_depth32
+#define GL_DEPTH_COMPONENT32_OES 0x81A7
+#endif
+
+/* GL_OES_depth_texture */
+/* No new tokens introduced by this extension. */
+
+/* GL_OES_EGL_image */
+#ifndef GL_OES_EGL_image
+typedef void* GLeglImageOES;
+#endif
+
+/* GL_OES_EGL_image_external */
+#ifndef GL_OES_EGL_image_external
+/* GLeglImageOES defined in GL_OES_EGL_image already. */
+#define GL_TEXTURE_EXTERNAL_OES 0x8D65
+#define GL_SAMPLER_EXTERNAL_OES 0x8D66
+#define GL_TEXTURE_BINDING_EXTERNAL_OES 0x8D67
+#define GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES 0x8D68
+#endif
+
+/* GL_OES_element_index_uint */
+#ifndef GL_OES_element_index_uint
+#define GL_UNSIGNED_INT 0x1405
+#endif
+
+/* GL_OES_get_program_binary */
+#ifndef GL_OES_get_program_binary
+#define GL_PROGRAM_BINARY_LENGTH_OES 0x8741
+#define GL_NUM_PROGRAM_BINARY_FORMATS_OES 0x87FE
+#define GL_PROGRAM_BINARY_FORMATS_OES 0x87FF
+#endif
+
+/* GL_OES_mapbuffer */
+#ifndef GL_OES_mapbuffer
+#define GL_WRITE_ONLY_OES 0x88B9
+#define GL_BUFFER_ACCESS_OES 0x88BB
+#define GL_BUFFER_MAPPED_OES 0x88BC
+#define GL_BUFFER_MAP_POINTER_OES 0x88BD
+#endif
+
+/* GL_OES_packed_depth_stencil */
+#ifndef GL_OES_packed_depth_stencil
+#define GL_DEPTH_STENCIL_OES 0x84F9
+#define GL_UNSIGNED_INT_24_8_OES 0x84FA
+#define GL_DEPTH24_STENCIL8_OES 0x88F0
+#endif
+
+/* GL_OES_required_internalformat */
+#ifndef GL_OES_required_internalformat
+#define GL_ALPHA8_OES 0x803C
+#define GL_DEPTH_COMPONENT16_OES 0x81A5
+/* reuse GL_DEPTH_COMPONENT24_OES */
+/* reuse GL_DEPTH24_STENCIL8_OES */
+/* reuse GL_DEPTH_COMPONENT32_OES */
+#define GL_LUMINANCE4_ALPHA4_OES 0x8043
+#define GL_LUMINANCE8_ALPHA8_OES 0x8045
+#define GL_LUMINANCE8_OES 0x8040
+#define GL_RGBA4_OES 0x8056
+#define GL_RGB5_A1_OES 0x8057
+#define GL_RGB565_OES 0x8D62
+/* reuse GL_RGB8_OES */
+/* reuse GL_RGBA8_OES */
+/* reuse GL_RGB10_EXT */
+/* reuse GL_RGB10_A2_EXT */
+#endif
+
+/* GL_OES_rgb8_rgba8 */
+#ifndef GL_OES_rgb8_rgba8
+#define GL_RGB8_OES 0x8051
+#define GL_RGBA8_OES 0x8058
+#endif
+
+/* GL_OES_standard_derivatives */
+#ifndef GL_OES_standard_derivatives
+#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES 0x8B8B
+#endif
+
+/* GL_OES_stencil1 */
+#ifndef GL_OES_stencil1
+#define GL_STENCIL_INDEX1_OES 0x8D46
+#endif
+
+/* GL_OES_stencil4 */
+#ifndef GL_OES_stencil4
+#define GL_STENCIL_INDEX4_OES 0x8D47
+#endif
+
+#ifndef GL_OES_surfaceless_context
+#define GL_FRAMEBUFFER_UNDEFINED_OES 0x8219
+#endif
+
+/* GL_OES_texture_3D */
+#ifndef GL_OES_texture_3D
+#define GL_TEXTURE_WRAP_R_OES 0x8072
+#define GL_TEXTURE_3D_OES 0x806F
+#define GL_TEXTURE_BINDING_3D_OES 0x806A
+#define GL_MAX_3D_TEXTURE_SIZE_OES 0x8073
+#define GL_SAMPLER_3D_OES 0x8B5F
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_OES 0x8CD4
+#endif
+
+/* GL_OES_texture_float */
+/* No new tokens introduced by this extension. */
+
+/* GL_OES_texture_float_linear */
+/* No new tokens introduced by this extension. */
+
+/* GL_OES_texture_half_float */
+#ifndef GL_OES_texture_half_float
+#define GL_HALF_FLOAT_OES 0x8D61
+#endif
+
+/* GL_OES_texture_half_float_linear */
+/* No new tokens introduced by this extension. */
+
+/* GL_OES_texture_npot */
+/* No new tokens introduced by this extension. */
+
+/* GL_OES_vertex_array_object */
+#ifndef GL_OES_vertex_array_object
+#define GL_VERTEX_ARRAY_BINDING_OES 0x85B5
+#endif
+
+/* GL_OES_vertex_half_float */
+/* GL_HALF_FLOAT_OES defined in GL_OES_texture_half_float already. */
+
+/* GL_OES_vertex_type_10_10_10_2 */
+#ifndef GL_OES_vertex_type_10_10_10_2
+#define GL_UNSIGNED_INT_10_10_10_2_OES 0x8DF6
+#define GL_INT_10_10_10_2_OES 0x8DF7
+#endif
+
+/*------------------------------------------------------------------------*
+ * KHR extension tokens
+ *------------------------------------------------------------------------*/
+
+#ifndef GL_KHR_debug
+typedef void (GL_APIENTRYP GLDEBUGPROCKHR)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
+#define GL_DEBUG_OUTPUT_SYNCHRONOUS_KHR 0x8242
+#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_KHR 0x8243
+#define GL_DEBUG_CALLBACK_FUNCTION_KHR 0x8244
+#define GL_DEBUG_CALLBACK_USER_PARAM_KHR 0x8245
+#define GL_DEBUG_SOURCE_API_KHR 0x8246
+#define GL_DEBUG_SOURCE_WINDOW_SYSTEM_KHR 0x8247
+#define GL_DEBUG_SOURCE_SHADER_COMPILER_KHR 0x8248
+#define GL_DEBUG_SOURCE_THIRD_PARTY_KHR 0x8249
+#define GL_DEBUG_SOURCE_APPLICATION_KHR 0x824A
+#define GL_DEBUG_SOURCE_OTHER_KHR 0x824B
+#define GL_DEBUG_TYPE_ERROR_KHR 0x824C
+#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_KHR 0x824D
+#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_KHR 0x824E
+#define GL_DEBUG_TYPE_PORTABILITY_KHR 0x824F
+#define GL_DEBUG_TYPE_PERFORMANCE_KHR 0x8250
+#define GL_DEBUG_TYPE_OTHER_KHR 0x8251
+#define GL_DEBUG_TYPE_MARKER_KHR 0x8268
+#define GL_DEBUG_TYPE_PUSH_GROUP_KHR 0x8269
+#define GL_DEBUG_TYPE_POP_GROUP_KHR 0x826A
+#define GL_DEBUG_SEVERITY_NOTIFICATION_KHR 0x826B
+#define GL_MAX_DEBUG_GROUP_STACK_DEPTH_KHR 0x826C
+#define GL_DEBUG_GROUP_STACK_DEPTH_KHR 0x826D
+#define GL_BUFFER_KHR 0x82E0
+#define GL_SHADER_KHR 0x82E1
+#define GL_PROGRAM_KHR 0x82E2
+#define GL_QUERY_KHR 0x82E3
+/* PROGRAM_PIPELINE only in GL */
+#define GL_SAMPLER_KHR 0x82E6
+/* DISPLAY_LIST only in GL */
+#define GL_MAX_LABEL_LENGTH_KHR 0x82E8
+#define GL_MAX_DEBUG_MESSAGE_LENGTH_KHR 0x9143
+#define GL_MAX_DEBUG_LOGGED_MESSAGES_KHR 0x9144
+#define GL_DEBUG_LOGGED_MESSAGES_KHR 0x9145
+#define GL_DEBUG_SEVERITY_HIGH_KHR 0x9146
+#define GL_DEBUG_SEVERITY_MEDIUM_KHR 0x9147
+#define GL_DEBUG_SEVERITY_LOW_KHR 0x9148
+#define GL_DEBUG_OUTPUT_KHR 0x92E0
+#define GL_CONTEXT_FLAG_DEBUG_BIT_KHR 0x00000002
+#define GL_STACK_OVERFLOW_KHR 0x0503
+#define GL_STACK_UNDERFLOW_KHR 0x0504
+#endif
+
+#ifndef GL_KHR_texture_compression_astc_ldr
+#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0
+#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1
+#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2
+#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3
+#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4
+#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5
+#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6
+#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7
+#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8
+#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9
+#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA
+#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB
+#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC
+#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD
+#endif
+
+/*------------------------------------------------------------------------*
+ * AMD extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_AMD_compressed_3DC_texture */
+#ifndef GL_AMD_compressed_3DC_texture
+#define GL_3DC_X_AMD 0x87F9
+#define GL_3DC_XY_AMD 0x87FA
+#endif
+
+/* GL_AMD_compressed_ATC_texture */
+#ifndef GL_AMD_compressed_ATC_texture
+#define GL_ATC_RGB_AMD 0x8C92
+#define GL_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93
+#define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE
+#endif
+
+/* GL_AMD_performance_monitor */
+#ifndef GL_AMD_performance_monitor
+#define GL_COUNTER_TYPE_AMD 0x8BC0
+#define GL_COUNTER_RANGE_AMD 0x8BC1
+#define GL_UNSIGNED_INT64_AMD 0x8BC2
+#define GL_PERCENTAGE_AMD 0x8BC3
+#define GL_PERFMON_RESULT_AVAILABLE_AMD 0x8BC4
+#define GL_PERFMON_RESULT_SIZE_AMD 0x8BC5
+#define GL_PERFMON_RESULT_AMD 0x8BC6
+#endif
+
+/* GL_AMD_program_binary_Z400 */
+#ifndef GL_AMD_program_binary_Z400
+#define GL_Z400_BINARY_AMD 0x8740
+#endif
+
+/*------------------------------------------------------------------------*
+ * ANGLE extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_ANGLE_depth_texture */
+#ifndef GL_ANGLE_depth_texture
+#define GL_DEPTH_COMPONENT 0x1902
+#define GL_DEPTH_STENCIL_OES 0x84F9
+#define GL_UNSIGNED_SHORT 0x1403
+#define GL_UNSIGNED_INT 0x1405
+#define GL_UNSIGNED_INT_24_8_OES 0x84FA
+#define GL_DEPTH_COMPONENT16 0x81A5
+#define GL_DEPTH_COMPONENT32_OES 0x81A7
+#define GL_DEPTH24_STENCIL8_OES 0x88F0
+#endif
+
+/* GL_ANGLE_framebuffer_blit */
+#ifndef GL_ANGLE_framebuffer_blit
+#define GL_READ_FRAMEBUFFER_ANGLE 0x8CA8
+#define GL_DRAW_FRAMEBUFFER_ANGLE 0x8CA9
+#define GL_DRAW_FRAMEBUFFER_BINDING_ANGLE 0x8CA6
+#define GL_READ_FRAMEBUFFER_BINDING_ANGLE 0x8CAA
+#endif
+
+/* GL_ANGLE_framebuffer_multisample */
+#ifndef GL_ANGLE_framebuffer_multisample
+#define GL_RENDERBUFFER_SAMPLES_ANGLE 0x8CAB
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE 0x8D56
+#define GL_MAX_SAMPLES_ANGLE 0x8D57
+#endif
+
+/* GL_ANGLE_instanced_arrays */
+#ifndef GL_ANGLE_instanced_arrays
+#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE 0x88FE
+#endif
+
+/* GL_ANGLE_pack_reverse_row_order */
+#ifndef GL_ANGLE_pack_reverse_row_order
+#define GL_PACK_REVERSE_ROW_ORDER_ANGLE 0x93A4
+#endif
+
+/* GL_ANGLE_program_binary */
+#ifndef GL_ANGLE_program_binary
+#define GL_PROGRAM_BINARY_ANGLE 0x93A6
+#endif
+
+/* GL_ANGLE_texture_compression_dxt3 */
+#ifndef GL_ANGLE_texture_compression_dxt3
+#define GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE 0x83F2
+#endif
+
+/* GL_ANGLE_texture_compression_dxt5 */
+#ifndef GL_ANGLE_texture_compression_dxt5
+#define GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE 0x83F3
+#endif
+
+/* GL_ANGLE_texture_usage */
+#ifndef GL_ANGLE_texture_usage
+#define GL_TEXTURE_USAGE_ANGLE 0x93A2
+#define GL_FRAMEBUFFER_ATTACHMENT_ANGLE 0x93A3
+#endif
+
+/* GL_ANGLE_translated_shader_source */
+#ifndef GL_ANGLE_translated_shader_source
+#define GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE 0x93A0
+#endif
+
+/*------------------------------------------------------------------------*
+ * APPLE extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_APPLE_copy_texture_levels */
+/* No new tokens introduced by this extension. */
+
+/* GL_APPLE_framebuffer_multisample */
+#ifndef GL_APPLE_framebuffer_multisample
+#define GL_RENDERBUFFER_SAMPLES_APPLE 0x8CAB
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_APPLE 0x8D56
+#define GL_MAX_SAMPLES_APPLE 0x8D57
+#define GL_READ_FRAMEBUFFER_APPLE 0x8CA8
+#define GL_DRAW_FRAMEBUFFER_APPLE 0x8CA9
+#define GL_DRAW_FRAMEBUFFER_BINDING_APPLE 0x8CA6
+#define GL_READ_FRAMEBUFFER_BINDING_APPLE 0x8CAA
+#endif
+
+/* GL_APPLE_rgb_422 */
+#ifndef GL_APPLE_rgb_422
+#define GL_RGB_422_APPLE 0x8A1F
+#define GL_UNSIGNED_SHORT_8_8_APPLE 0x85BA
+#define GL_UNSIGNED_SHORT_8_8_REV_APPLE 0x85BB
+#endif
+
+/* GL_APPLE_sync */
+#ifndef GL_APPLE_sync
+
+#define GL_SYNC_OBJECT_APPLE 0x8A53
+#define GL_MAX_SERVER_WAIT_TIMEOUT_APPLE 0x9111
+#define GL_OBJECT_TYPE_APPLE 0x9112
+#define GL_SYNC_CONDITION_APPLE 0x9113
+#define GL_SYNC_STATUS_APPLE 0x9114
+#define GL_SYNC_FLAGS_APPLE 0x9115
+#define GL_SYNC_FENCE_APPLE 0x9116
+#define GL_SYNC_GPU_COMMANDS_COMPLETE_APPLE 0x9117
+#define GL_UNSIGNALED_APPLE 0x9118
+#define GL_SIGNALED_APPLE 0x9119
+#define GL_ALREADY_SIGNALED_APPLE 0x911A
+#define GL_TIMEOUT_EXPIRED_APPLE 0x911B
+#define GL_CONDITION_SATISFIED_APPLE 0x911C
+#define GL_WAIT_FAILED_APPLE 0x911D
+#define GL_SYNC_FLUSH_COMMANDS_BIT_APPLE 0x00000001
+#define GL_TIMEOUT_IGNORED_APPLE 0xFFFFFFFFFFFFFFFFull
+#endif
+
+/* GL_APPLE_texture_format_BGRA8888 */
+#ifndef GL_APPLE_texture_format_BGRA8888
+#define GL_BGRA_EXT 0x80E1
+#endif
+
+/* GL_APPLE_texture_max_level */
+#ifndef GL_APPLE_texture_max_level
+#define GL_TEXTURE_MAX_LEVEL_APPLE 0x813D
+#endif
+
+/*------------------------------------------------------------------------*
+ * ARM extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_ARM_mali_program_binary */
+#ifndef GL_ARM_mali_program_binary
+#define GL_MALI_PROGRAM_BINARY_ARM 0x8F61
+#endif
+
+/* GL_ARM_mali_shader_binary */
+#ifndef GL_ARM_mali_shader_binary
+#define GL_MALI_SHADER_BINARY_ARM 0x8F60
+#endif
+
+/* GL_ARM_rgba8 */
+/* No new tokens introduced by this extension. */
+
+/*------------------------------------------------------------------------*
+ * EXT extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_EXT_blend_minmax */
+#ifndef GL_EXT_blend_minmax
+#define GL_MIN_EXT 0x8007
+#define GL_MAX_EXT 0x8008
+#endif
+
+/* GL_EXT_color_buffer_half_float */
+#ifndef GL_EXT_color_buffer_half_float
+#define GL_RGBA16F_EXT 0x881A
+#define GL_RGB16F_EXT 0x881B
+#define GL_RG16F_EXT 0x822F
+#define GL_R16F_EXT 0x822D
+#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT 0x8211
+#define GL_UNSIGNED_NORMALIZED_EXT 0x8C17
+#endif
+
+/* GL_EXT_debug_label */
+#ifndef GL_EXT_debug_label
+#define GL_PROGRAM_PIPELINE_OBJECT_EXT 0x8A4F
+#define GL_PROGRAM_OBJECT_EXT 0x8B40
+#define GL_SHADER_OBJECT_EXT 0x8B48
+#define GL_BUFFER_OBJECT_EXT 0x9151
+#define GL_QUERY_OBJECT_EXT 0x9153
+#define GL_VERTEX_ARRAY_OBJECT_EXT 0x9154
+#endif
+
+/* GL_EXT_debug_marker */
+/* No new tokens introduced by this extension. */
+
+/* GL_EXT_discard_framebuffer */
+#ifndef GL_EXT_discard_framebuffer
+#define GL_COLOR_EXT 0x1800
+#define GL_DEPTH_EXT 0x1801
+#define GL_STENCIL_EXT 0x1802
+#endif
+
+#ifndef GL_EXT_disjoint_timer_query
+#define GL_QUERY_COUNTER_BITS_EXT 0x8864
+#define GL_CURRENT_QUERY_EXT 0x8865
+#define GL_QUERY_RESULT_EXT 0x8866
+#define GL_QUERY_RESULT_AVAILABLE_EXT 0x8867
+#define GL_TIME_ELAPSED_EXT 0x88BF
+#define GL_TIMESTAMP_EXT 0x8E28
+#define GL_GPU_DISJOINT_EXT 0x8FBB
+#endif
+
+#ifndef GL_EXT_draw_buffers
+#define GL_EXT_draw_buffers 1
+#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF
+#define GL_MAX_DRAW_BUFFERS_EXT 0x8824
+#define GL_DRAW_BUFFER0_EXT 0x8825
+#define GL_DRAW_BUFFER1_EXT 0x8826
+#define GL_DRAW_BUFFER2_EXT 0x8827
+#define GL_DRAW_BUFFER3_EXT 0x8828
+#define GL_DRAW_BUFFER4_EXT 0x8829
+#define GL_DRAW_BUFFER5_EXT 0x882A
+#define GL_DRAW_BUFFER6_EXT 0x882B
+#define GL_DRAW_BUFFER7_EXT 0x882C
+#define GL_DRAW_BUFFER8_EXT 0x882D
+#define GL_DRAW_BUFFER9_EXT 0x882E
+#define GL_DRAW_BUFFER10_EXT 0x882F
+#define GL_DRAW_BUFFER11_EXT 0x8830
+#define GL_DRAW_BUFFER12_EXT 0x8831
+#define GL_DRAW_BUFFER13_EXT 0x8832
+#define GL_DRAW_BUFFER14_EXT 0x8833
+#define GL_DRAW_BUFFER15_EXT 0x8834
+#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
+#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1
+#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2
+#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3
+#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4
+#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5
+#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6
+#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7
+#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8
+#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9
+#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA
+#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB
+#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC
+#define GL_COLOR_ATTACHMENT13_EXT 0x8CED
+#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE
+#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF
+#endif
+
+/* GL_EXT_map_buffer_range */
+#ifndef GL_EXT_map_buffer_range
+#define GL_MAP_READ_BIT_EXT 0x0001
+#define GL_MAP_WRITE_BIT_EXT 0x0002
+#define GL_MAP_INVALIDATE_RANGE_BIT_EXT 0x0004
+#define GL_MAP_INVALIDATE_BUFFER_BIT_EXT 0x0008
+#define GL_MAP_FLUSH_EXPLICIT_BIT_EXT 0x0010
+#define GL_MAP_UNSYNCHRONIZED_BIT_EXT 0x0020
+#endif
+
+/* GL_EXT_multisampled_render_to_texture */
+#ifndef GL_EXT_multisampled_render_to_texture
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT 0x8D6C
+/* reuse values from GL_EXT_framebuffer_multisample (desktop extension) */
+#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56
+#define GL_MAX_SAMPLES_EXT 0x8D57
+#endif
+
+/* GL_EXT_multiview_draw_buffers */
+#ifndef GL_EXT_multiview_draw_buffers
+#define GL_COLOR_ATTACHMENT_EXT 0x90F0
+#define GL_MULTIVIEW_EXT 0x90F1
+#define GL_DRAW_BUFFER_EXT 0x0C01
+#define GL_READ_BUFFER_EXT 0x0C02
+#define GL_MAX_MULTIVIEW_BUFFERS_EXT 0x90F2
+#endif
+
+/* GL_EXT_multi_draw_arrays */
+/* No new tokens introduced by this extension. */
+
+/* GL_EXT_occlusion_query_boolean */
+#ifndef GL_EXT_occlusion_query_boolean
+#define GL_ANY_SAMPLES_PASSED_EXT 0x8C2F
+#define GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT 0x8D6A
+#define GL_CURRENT_QUERY_EXT 0x8865
+#define GL_QUERY_RESULT_EXT 0x8866
+#define GL_QUERY_RESULT_AVAILABLE_EXT 0x8867
+#endif
+
+/* GL_EXT_read_format_bgra */
+#ifndef GL_EXT_read_format_bgra
+#define GL_BGRA_EXT 0x80E1
+#define GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT 0x8365
+#define GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT 0x8366
+#endif
+
+/* GL_EXT_robustness */
+#ifndef GL_EXT_robustness
+/* reuse GL_NO_ERROR */
+#define GL_GUILTY_CONTEXT_RESET_EXT 0x8253
+#define GL_INNOCENT_CONTEXT_RESET_EXT 0x8254
+#define GL_UNKNOWN_CONTEXT_RESET_EXT 0x8255
+#define GL_CONTEXT_ROBUST_ACCESS_EXT 0x90F3
+#define GL_RESET_NOTIFICATION_STRATEGY_EXT 0x8256
+#define GL_LOSE_CONTEXT_ON_RESET_EXT 0x8252
+#define GL_NO_RESET_NOTIFICATION_EXT 0x8261
+#endif
+
+/* GL_EXT_separate_shader_objects */
+#ifndef GL_EXT_separate_shader_objects
+#define GL_VERTEX_SHADER_BIT_EXT 0x00000001
+#define GL_FRAGMENT_SHADER_BIT_EXT 0x00000002
+#define GL_ALL_SHADER_BITS_EXT 0xFFFFFFFF
+#define GL_PROGRAM_SEPARABLE_EXT 0x8258
+#define GL_ACTIVE_PROGRAM_EXT 0x8259
+#define GL_PROGRAM_PIPELINE_BINDING_EXT 0x825A
+#endif
+
+/* GL_EXT_shader_framebuffer_fetch */
+#ifndef GL_EXT_shader_framebuffer_fetch
+#define GL_FRAGMENT_SHADER_DISCARDS_SAMPLES_EXT 0x8A52
+#endif
+
+/* GL_EXT_shader_texture_lod */
+/* No new tokens introduced by this extension. */
+
+/* GL_EXT_shadow_samplers */
+#ifndef GL_EXT_shadow_samplers
+#define GL_TEXTURE_COMPARE_MODE_EXT 0x884C
+#define GL_TEXTURE_COMPARE_FUNC_EXT 0x884D
+#define GL_COMPARE_REF_TO_TEXTURE_EXT 0x884E
+#define GL_SAMPLER_2D_SHADOW_EXT 0x8B62
+#endif
+
+/* GL_EXT_sRGB */
+#ifndef GL_EXT_sRGB
+#define GL_SRGB_EXT 0x8C40
+#define GL_SRGB_ALPHA_EXT 0x8C42
+#define GL_SRGB8_ALPHA8_EXT 0x8C43
+#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT 0x8210
+#endif
+
+/* GL_EXT_sRGB_write_control */
+#ifndef GL_EXT_sRGB_write_control
+#define GL_EXT_sRGB_write_control 1
+#define GL_FRAMEBUFFER_SRGB_EXT 0x8DB9
+#endif
+
+/* GL_EXT_texture_compression_dxt1 */
+#ifndef GL_EXT_texture_compression_dxt1
+#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
+#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
+#endif
+
+/* GL_EXT_texture_filter_anisotropic */
+#ifndef GL_EXT_texture_filter_anisotropic
+#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
+#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
+#endif
+
+/* GL_EXT_texture_format_BGRA8888 */
+#ifndef GL_EXT_texture_format_BGRA8888
+#define GL_BGRA_EXT 0x80E1
+#endif
+
+/* GL_EXT_texture_rg */
+#ifndef GL_EXT_texture_rg
+#define GL_RED_EXT 0x1903
+#define GL_RG_EXT 0x8227
+#define GL_R8_EXT 0x8229
+#define GL_RG8_EXT 0x822B
+#endif
+
+/* GL_EXT_texture_sRGB_decode */
+#ifndef GL_EXT_texture_sRGB_decode
+#define GL_EXT_texture_sRGB_decode 1
+#define GL_TEXTURE_SRGB_DECODE_EXT 0x8A48
+#define GL_DECODE_EXT 0x8A49
+#define GL_SKIP_DECODE_EXT 0x8A4A
+#endif
+
+/* GL_EXT_texture_storage */
+#ifndef GL_EXT_texture_storage
+#define GL_TEXTURE_IMMUTABLE_FORMAT_EXT 0x912F
+#define GL_ALPHA8_EXT 0x803C
+#define GL_LUMINANCE8_EXT 0x8040
+#define GL_LUMINANCE8_ALPHA8_EXT 0x8045
+#define GL_RGBA32F_EXT 0x8814
+#define GL_RGB32F_EXT 0x8815
+#define GL_ALPHA32F_EXT 0x8816
+#define GL_LUMINANCE32F_EXT 0x8818
+#define GL_LUMINANCE_ALPHA32F_EXT 0x8819
+/* reuse GL_RGBA16F_EXT */
+/* reuse GL_RGB16F_EXT */
+#define GL_ALPHA16F_EXT 0x881C
+#define GL_LUMINANCE16F_EXT 0x881E
+#define GL_LUMINANCE_ALPHA16F_EXT 0x881F
+#define GL_RGB10_A2_EXT 0x8059
+#define GL_RGB10_EXT 0x8052
+#define GL_BGRA8_EXT 0x93A1
+#define GL_R8_EXT 0x8229
+#define GL_RG8_EXT 0x822B
+#define GL_R32F_EXT 0x822E
+#define GL_RG32F_EXT 0x8230
+#define GL_R16F_EXT 0x822D
+#define GL_RG16F_EXT 0x822F
+#endif
+
+/* GL_EXT_texture_type_2_10_10_10_REV */
+#ifndef GL_EXT_texture_type_2_10_10_10_REV
+#define GL_UNSIGNED_INT_2_10_10_10_REV_EXT 0x8368
+#endif
+
+/* GL_EXT_unpack_subimage */
+#ifndef GL_EXT_unpack_subimage
+#define GL_UNPACK_ROW_LENGTH_EXT 0x0CF2
+#define GL_UNPACK_SKIP_ROWS_EXT 0x0CF3
+#define GL_UNPACK_SKIP_PIXELS_EXT 0x0CF4
+#endif
+
+/*------------------------------------------------------------------------*
+ * DMP extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_DMP_shader_binary */
+#ifndef GL_DMP_shader_binary
+#define GL_SHADER_BINARY_DMP 0x9250
+#endif
+
+/*------------------------------------------------------------------------*
+ * FJ extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_FJ_shader_binary_GCCSO */
+#ifndef GL_FJ_shader_binary_GCCSO
+#define GL_GCCSO_SHADER_BINARY_FJ 0x9260
+#endif
+
+/*------------------------------------------------------------------------*
+ * IMG extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_IMG_program_binary */
+#ifndef GL_IMG_program_binary
+#define GL_SGX_PROGRAM_BINARY_IMG 0x9130
+#endif
+
+/* GL_IMG_read_format */
+#ifndef GL_IMG_read_format
+#define GL_BGRA_IMG 0x80E1
+#define GL_UNSIGNED_SHORT_4_4_4_4_REV_IMG 0x8365
+#endif
+
+/* GL_IMG_shader_binary */
+#ifndef GL_IMG_shader_binary
+#define GL_SGX_BINARY_IMG 0x8C0A
+#endif
+
+/* GL_IMG_texture_compression_pvrtc */
+#ifndef GL_IMG_texture_compression_pvrtc
+#define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
+#define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01
+#define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
+#define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03
+#endif
+
+/* GL_IMG_texture_compression_pvrtc2 */
+#ifndef GL_IMG_texture_compression_pvrtc2
+#define GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG 0x9137
+#define GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG 0x9138
+#endif
+
+/* GL_IMG_multisampled_render_to_texture */
+#ifndef GL_IMG_multisampled_render_to_texture
+#define GL_RENDERBUFFER_SAMPLES_IMG 0x9133
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_IMG 0x9134
+#define GL_MAX_SAMPLES_IMG 0x9135
+#define GL_TEXTURE_SAMPLES_IMG 0x9136
+#endif
+
+/*------------------------------------------------------------------------*
+ * NV extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_NV_coverage_sample */
+#ifndef GL_NV_coverage_sample
+#define GL_COVERAGE_COMPONENT_NV 0x8ED0
+#define GL_COVERAGE_COMPONENT4_NV 0x8ED1
+#define GL_COVERAGE_ATTACHMENT_NV 0x8ED2
+#define GL_COVERAGE_BUFFERS_NV 0x8ED3
+#define GL_COVERAGE_SAMPLES_NV 0x8ED4
+#define GL_COVERAGE_ALL_FRAGMENTS_NV 0x8ED5
+#define GL_COVERAGE_EDGE_FRAGMENTS_NV 0x8ED6
+#define GL_COVERAGE_AUTOMATIC_NV 0x8ED7
+#define GL_COVERAGE_BUFFER_BIT_NV 0x00008000
+#endif
+
+/* GL_NV_depth_nonlinear */
+#ifndef GL_NV_depth_nonlinear
+#define GL_DEPTH_COMPONENT16_NONLINEAR_NV 0x8E2C
+#endif
+
+/* GL_NV_draw_buffers */
+#ifndef GL_NV_draw_buffers
+#define GL_MAX_DRAW_BUFFERS_NV 0x8824
+#define GL_DRAW_BUFFER0_NV 0x8825
+#define GL_DRAW_BUFFER1_NV 0x8826
+#define GL_DRAW_BUFFER2_NV 0x8827
+#define GL_DRAW_BUFFER3_NV 0x8828
+#define GL_DRAW_BUFFER4_NV 0x8829
+#define GL_DRAW_BUFFER5_NV 0x882A
+#define GL_DRAW_BUFFER6_NV 0x882B
+#define GL_DRAW_BUFFER7_NV 0x882C
+#define GL_DRAW_BUFFER8_NV 0x882D
+#define GL_DRAW_BUFFER9_NV 0x882E
+#define GL_DRAW_BUFFER10_NV 0x882F
+#define GL_DRAW_BUFFER11_NV 0x8830
+#define GL_DRAW_BUFFER12_NV 0x8831
+#define GL_DRAW_BUFFER13_NV 0x8832
+#define GL_DRAW_BUFFER14_NV 0x8833
+#define GL_DRAW_BUFFER15_NV 0x8834
+#define GL_COLOR_ATTACHMENT0_NV 0x8CE0
+#define GL_COLOR_ATTACHMENT1_NV 0x8CE1
+#define GL_COLOR_ATTACHMENT2_NV 0x8CE2
+#define GL_COLOR_ATTACHMENT3_NV 0x8CE3
+#define GL_COLOR_ATTACHMENT4_NV 0x8CE4
+#define GL_COLOR_ATTACHMENT5_NV 0x8CE5
+#define GL_COLOR_ATTACHMENT6_NV 0x8CE6
+#define GL_COLOR_ATTACHMENT7_NV 0x8CE7
+#define GL_COLOR_ATTACHMENT8_NV 0x8CE8
+#define GL_COLOR_ATTACHMENT9_NV 0x8CE9
+#define GL_COLOR_ATTACHMENT10_NV 0x8CEA
+#define GL_COLOR_ATTACHMENT11_NV 0x8CEB
+#define GL_COLOR_ATTACHMENT12_NV 0x8CEC
+#define GL_COLOR_ATTACHMENT13_NV 0x8CED
+#define GL_COLOR_ATTACHMENT14_NV 0x8CEE
+#define GL_COLOR_ATTACHMENT15_NV 0x8CEF
+#endif
+
+/* GL_NV_draw_instanced */
+/* No new tokens introduced by this extension. */
+
+/* GL_NV_fbo_color_attachments */
+#ifndef GL_NV_fbo_color_attachments
+#define GL_MAX_COLOR_ATTACHMENTS_NV 0x8CDF
+/* GL_COLOR_ATTACHMENT{0-15}_NV defined in GL_NV_draw_buffers already. */
+#endif
+
+/* GL_NV_fence */
+#ifndef GL_NV_fence
+#define GL_ALL_COMPLETED_NV 0x84F2
+#define GL_FENCE_STATUS_NV 0x84F3
+#define GL_FENCE_CONDITION_NV 0x84F4
+#endif
+
+/* GL_NV_framebuffer_blit */
+#ifndef GL_NV_framebuffer_blit
+#define GL_READ_FRAMEBUFFER_NV 0x8CA8
+#define GL_DRAW_FRAMEBUFFER_NV 0x8CA9
+#define GL_DRAW_FRAMEBUFFER_BINDING_NV 0x8CA6
+#define GL_READ_FRAMEBUFFER_BINDING_NV 0x8CAA
+#endif
+
+/* GL_NV_framebuffer_multisample */
+#ifndef GL_NV_framebuffer_multisample
+#define GL_RENDERBUFFER_SAMPLES_NV 0x8CAB
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_NV 0x8D56
+#define GL_MAX_SAMPLES_NV 0x8D57
+#endif
+
+/* GL_NV_generate_mipmap_sRGB */
+/* No new tokens introduced by this extension. */
+
+/* GL_NV_instanced_arrays */
+#ifndef GL_NV_instanced_arrays
+#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_NV 0x88FE
+#endif
+
+/* GL_NV_read_buffer */
+#ifndef GL_NV_read_buffer
+#define GL_READ_BUFFER_NV 0x0C02
+#endif
+
+/* GL_NV_read_buffer_front */
+/* No new tokens introduced by this extension. */
+
+/* GL_NV_read_depth */
+/* No new tokens introduced by this extension. */
+
+/* GL_NV_read_depth_stencil */
+/* No new tokens introduced by this extension. */
+
+/* GL_NV_read_stencil */
+/* No new tokens introduced by this extension. */
+
+/* GL_NV_shadow_samplers_array */
+#ifndef GL_NV_shadow_samplers_array
+#define GL_SAMPLER_2D_ARRAY_SHADOW_NV 0x8DC4
+#endif
+
+/* GL_NV_shadow_samplers_cube */
+#ifndef GL_NV_shadow_samplers_cube
+#define GL_SAMPLER_CUBE_SHADOW_NV 0x8DC5
+#endif
+
+/* GL_NV_sRGB_formats */
+#ifndef GL_NV_sRGB_formats
+#define GL_SLUMINANCE_NV 0x8C46
+#define GL_SLUMINANCE_ALPHA_NV 0x8C44
+#define GL_SRGB8_NV 0x8C41
+#define GL_SLUMINANCE8_NV 0x8C47
+#define GL_SLUMINANCE8_ALPHA8_NV 0x8C45
+#define GL_COMPRESSED_SRGB_S3TC_DXT1_NV 0x8C4C
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV 0x8C4D
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV 0x8C4E
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV 0x8C4F
+#define GL_ETC1_SRGB8_NV 0x88EE
+#endif
+
+/* GL_NV_texture_border_clamp */
+#ifndef GL_NV_texture_border_clamp
+#define GL_TEXTURE_BORDER_COLOR_NV 0x1004
+#define GL_CLAMP_TO_BORDER_NV 0x812D
+#endif
+
+/* GL_NV_texture_compression_s3tc_update */
+/* No new tokens introduced by this extension. */
+
+/* GL_NV_texture_npot_2D_mipmap */
+/* No new tokens introduced by this extension. */
+
+/*------------------------------------------------------------------------*
+ * QCOM extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_QCOM_alpha_test */
+#ifndef GL_QCOM_alpha_test
+#define GL_ALPHA_TEST_QCOM 0x0BC0
+#define GL_ALPHA_TEST_FUNC_QCOM 0x0BC1
+#define GL_ALPHA_TEST_REF_QCOM 0x0BC2
+#endif
+
+/* GL_QCOM_binning_control */
+#ifndef GL_QCOM_binning_control
+#define GL_BINNING_CONTROL_HINT_QCOM 0x8FB0
+#define GL_CPU_OPTIMIZED_QCOM 0x8FB1
+#define GL_GPU_OPTIMIZED_QCOM 0x8FB2
+#define GL_RENDER_DIRECT_TO_FRAMEBUFFER_QCOM 0x8FB3
+#endif
+
+/* GL_QCOM_driver_control */
+/* No new tokens introduced by this extension. */
+
+/* GL_QCOM_extended_get */
+#ifndef GL_QCOM_extended_get
+#define GL_TEXTURE_WIDTH_QCOM 0x8BD2
+#define GL_TEXTURE_HEIGHT_QCOM 0x8BD3
+#define GL_TEXTURE_DEPTH_QCOM 0x8BD4
+#define GL_TEXTURE_INTERNAL_FORMAT_QCOM 0x8BD5
+#define GL_TEXTURE_FORMAT_QCOM 0x8BD6
+#define GL_TEXTURE_TYPE_QCOM 0x8BD7
+#define GL_TEXTURE_IMAGE_VALID_QCOM 0x8BD8
+#define GL_TEXTURE_NUM_LEVELS_QCOM 0x8BD9
+#define GL_TEXTURE_TARGET_QCOM 0x8BDA
+#define GL_TEXTURE_OBJECT_VALID_QCOM 0x8BDB
+#define GL_STATE_RESTORE 0x8BDC
+#endif
+
+/* GL_QCOM_extended_get2 */
+/* No new tokens introduced by this extension. */
+
+/* GL_QCOM_perfmon_global_mode */
+#ifndef GL_QCOM_perfmon_global_mode
+#define GL_PERFMON_GLOBAL_MODE_QCOM 0x8FA0
+#endif
+
+/* GL_QCOM_writeonly_rendering */
+#ifndef GL_QCOM_writeonly_rendering
+#define GL_WRITEONLY_RENDERING_QCOM 0x8823
+#endif
+
+/* GL_QCOM_tiled_rendering */
+#ifndef GL_QCOM_tiled_rendering
+#define GL_COLOR_BUFFER_BIT0_QCOM 0x00000001
+#define GL_COLOR_BUFFER_BIT1_QCOM 0x00000002
+#define GL_COLOR_BUFFER_BIT2_QCOM 0x00000004
+#define GL_COLOR_BUFFER_BIT3_QCOM 0x00000008
+#define GL_COLOR_BUFFER_BIT4_QCOM 0x00000010
+#define GL_COLOR_BUFFER_BIT5_QCOM 0x00000020
+#define GL_COLOR_BUFFER_BIT6_QCOM 0x00000040
+#define GL_COLOR_BUFFER_BIT7_QCOM 0x00000080
+#define GL_DEPTH_BUFFER_BIT0_QCOM 0x00000100
+#define GL_DEPTH_BUFFER_BIT1_QCOM 0x00000200
+#define GL_DEPTH_BUFFER_BIT2_QCOM 0x00000400
+#define GL_DEPTH_BUFFER_BIT3_QCOM 0x00000800
+#define GL_DEPTH_BUFFER_BIT4_QCOM 0x00001000
+#define GL_DEPTH_BUFFER_BIT5_QCOM 0x00002000
+#define GL_DEPTH_BUFFER_BIT6_QCOM 0x00004000
+#define GL_DEPTH_BUFFER_BIT7_QCOM 0x00008000
+#define GL_STENCIL_BUFFER_BIT0_QCOM 0x00010000
+#define GL_STENCIL_BUFFER_BIT1_QCOM 0x00020000
+#define GL_STENCIL_BUFFER_BIT2_QCOM 0x00040000
+#define GL_STENCIL_BUFFER_BIT3_QCOM 0x00080000
+#define GL_STENCIL_BUFFER_BIT4_QCOM 0x00100000
+#define GL_STENCIL_BUFFER_BIT5_QCOM 0x00200000
+#define GL_STENCIL_BUFFER_BIT6_QCOM 0x00400000
+#define GL_STENCIL_BUFFER_BIT7_QCOM 0x00800000
+#define GL_MULTISAMPLE_BUFFER_BIT0_QCOM 0x01000000
+#define GL_MULTISAMPLE_BUFFER_BIT1_QCOM 0x02000000
+#define GL_MULTISAMPLE_BUFFER_BIT2_QCOM 0x04000000
+#define GL_MULTISAMPLE_BUFFER_BIT3_QCOM 0x08000000
+#define GL_MULTISAMPLE_BUFFER_BIT4_QCOM 0x10000000
+#define GL_MULTISAMPLE_BUFFER_BIT5_QCOM 0x20000000
+#define GL_MULTISAMPLE_BUFFER_BIT6_QCOM 0x40000000
+#define GL_MULTISAMPLE_BUFFER_BIT7_QCOM 0x80000000
+#endif
+
+/*------------------------------------------------------------------------*
+ * VIV extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_VIV_shader_binary */
+#ifndef GL_VIV_shader_binary
+#define GL_SHADER_BINARY_VIV 0x8FC4
+#endif
+
+/*------------------------------------------------------------------------*
+ * End of extension tokens, start of corresponding extension functions
+ *------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------*
+ * OES extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_OES_compressed_ETC1_RGB8_texture */
+#ifndef GL_OES_compressed_ETC1_RGB8_texture
+#define GL_OES_compressed_ETC1_RGB8_texture 1
+#endif
+
+/* GL_OES_compressed_paletted_texture */
+#ifndef GL_OES_compressed_paletted_texture
+#define GL_OES_compressed_paletted_texture 1
+#endif
+
+/* GL_OES_depth24 */
+#ifndef GL_OES_depth24
+#define GL_OES_depth24 1
+#endif
+
+/* GL_OES_depth32 */
+#ifndef GL_OES_depth32
+#define GL_OES_depth32 1
+#endif
+
+/* GL_OES_depth_texture */
+#ifndef GL_OES_depth_texture
+#define GL_OES_depth_texture 1
+#endif
+
+/* GL_OES_EGL_image */
+#ifndef GL_OES_EGL_image
+#define GL_OES_EGL_image 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image);
+GL_APICALL void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES (GLenum target, GLeglImageOES image);
+#endif
+typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image);
+typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image);
+#endif
+
+/* GL_OES_EGL_image_external */
+#ifndef GL_OES_EGL_image_external
+#define GL_OES_EGL_image_external 1
+/* glEGLImageTargetTexture2DOES defined in GL_OES_EGL_image already. */
+#endif
+
+/* GL_OES_element_index_uint */
+#ifndef GL_OES_element_index_uint
+#define GL_OES_element_index_uint 1
+#endif
+
+/* GL_OES_fbo_render_mipmap */
+#ifndef GL_OES_fbo_render_mipmap
+#define GL_OES_fbo_render_mipmap 1
+#endif
+
+/* GL_OES_fragment_precision_high */
+#ifndef GL_OES_fragment_precision_high
+#define GL_OES_fragment_precision_high 1
+#endif
+
+/* GL_OES_get_program_binary */
+#ifndef GL_OES_get_program_binary
+#define GL_OES_get_program_binary 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glGetProgramBinaryOES (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary);
+GL_APICALL void GL_APIENTRY glProgramBinaryOES (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length);
+#endif
+typedef void (GL_APIENTRYP PFNGLGETPROGRAMBINARYOESPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary);
+typedef void (GL_APIENTRYP PFNGLPROGRAMBINARYOESPROC) (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length);
+#endif
+
+/* GL_OES_mapbuffer */
+#ifndef GL_OES_mapbuffer
+#define GL_OES_mapbuffer 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void* GL_APIENTRY glMapBufferOES (GLenum target, GLenum access);
+GL_APICALL GLboolean GL_APIENTRY glUnmapBufferOES (GLenum target);
+GL_APICALL void GL_APIENTRY glGetBufferPointervOES (GLenum target, GLenum pname, GLvoid **params);
+#endif
+typedef void* (GL_APIENTRYP PFNGLMAPBUFFEROESPROC) (GLenum target, GLenum access);
+typedef GLboolean (GL_APIENTRYP PFNGLUNMAPBUFFEROESPROC) (GLenum target);
+typedef void (GL_APIENTRYP PFNGLGETBUFFERPOINTERVOESPROC) (GLenum target, GLenum pname, GLvoid **params);
+#endif
+
+/* GL_OES_packed_depth_stencil */
+#ifndef GL_OES_packed_depth_stencil
+#define GL_OES_packed_depth_stencil 1
+#endif
+
+/* GL_OES_required_internalformat */
+#ifndef GL_OES_required_internalformat
+#define GL_OES_required_internalformat 1
+#endif
+
+/* GL_OES_rgb8_rgba8 */
+#ifndef GL_OES_rgb8_rgba8
+#define GL_OES_rgb8_rgba8 1
+#endif
+
+/* GL_OES_standard_derivatives */
+#ifndef GL_OES_standard_derivatives
+#define GL_OES_standard_derivatives 1
+#endif
+
+/* GL_OES_stencil1 */
+#ifndef GL_OES_stencil1
+#define GL_OES_stencil1 1
+#endif
+
+/* GL_OES_stencil4 */
+#ifndef GL_OES_stencil4
+#define GL_OES_stencil4 1
+#endif
+
+#ifndef GL_OES_surfaceless_context
+#define GL_OES_surfaceless_context 1
+#endif
+
+/* GL_OES_texture_3D */
+#ifndef GL_OES_texture_3D
+#define GL_OES_texture_3D 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glTexImage3DOES (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels);
+GL_APICALL void GL_APIENTRY glTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels);
+GL_APICALL void GL_APIENTRY glCopyTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glCompressedTexImage3DOES (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data);
+GL_APICALL void GL_APIENTRY glCompressedTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data);
+GL_APICALL void GL_APIENTRY glFramebufferTexture3DOES (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+#endif
+typedef void (GL_APIENTRYP PFNGLTEXIMAGE3DOESPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels);
+typedef void (GL_APIENTRYP PFNGLTEXSUBIMAGE3DOESPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels);
+typedef void (GL_APIENTRYP PFNGLCOPYTEXSUBIMAGE3DOESPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DOESPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data);
+typedef void (GL_APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DOESPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data);
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DOESPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+#endif
+
+/* GL_OES_texture_float */
+#ifndef GL_OES_texture_float
+#define GL_OES_texture_float 1
+#endif
+
+/* GL_OES_texture_float_linear */
+#ifndef GL_OES_texture_float_linear
+#define GL_OES_texture_float_linear 1
+#endif
+
+/* GL_OES_texture_half_float */
+#ifndef GL_OES_texture_half_float
+#define GL_OES_texture_half_float 1
+#endif
+
+/* GL_OES_texture_half_float_linear */
+#ifndef GL_OES_texture_half_float_linear
+#define GL_OES_texture_half_float_linear 1
+#endif
+
+/* GL_OES_texture_npot */
+#ifndef GL_OES_texture_npot
+#define GL_OES_texture_npot 1
+#endif
+
+/* GL_OES_vertex_array_object */
+#ifndef GL_OES_vertex_array_object
+#define GL_OES_vertex_array_object 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glBindVertexArrayOES (GLuint array);
+GL_APICALL void GL_APIENTRY glDeleteVertexArraysOES (GLsizei n, const GLuint *arrays);
+GL_APICALL void GL_APIENTRY glGenVertexArraysOES (GLsizei n, GLuint *arrays);
+GL_APICALL GLboolean GL_APIENTRY glIsVertexArrayOES (GLuint array);
+#endif
+typedef void (GL_APIENTRYP PFNGLBINDVERTEXARRAYOESPROC) (GLuint array);
+typedef void (GL_APIENTRYP PFNGLDELETEVERTEXARRAYSOESPROC) (GLsizei n, const GLuint *arrays);
+typedef void (GL_APIENTRYP PFNGLGENVERTEXARRAYSOESPROC) (GLsizei n, GLuint *arrays);
+typedef GLboolean (GL_APIENTRYP PFNGLISVERTEXARRAYOESPROC) (GLuint array);
+#endif
+
+/* GL_OES_vertex_half_float */
+#ifndef GL_OES_vertex_half_float
+#define GL_OES_vertex_half_float 1
+#endif
+
+/* GL_OES_vertex_type_10_10_10_2 */
+#ifndef GL_OES_vertex_type_10_10_10_2
+#define GL_OES_vertex_type_10_10_10_2 1
+#endif
+
+/*------------------------------------------------------------------------*
+ * KHR extension functions
+ *------------------------------------------------------------------------*/
+
+#ifndef GL_KHR_debug
+#define GL_KHR_debug 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDebugMessageControlKHR (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
+GL_APICALL void GL_APIENTRY glDebugMessageInsertKHR (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf);
+GL_APICALL void GL_APIENTRY glDebugMessageCallbackKHR (GLDEBUGPROCKHR callback, const void *userParam);
+GL_APICALL GLuint GL_APIENTRY glGetDebugMessageLogKHR (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog);
+GL_APICALL void GL_APIENTRY glPushDebugGroupKHR (GLenum source, GLuint id, GLsizei length, const GLchar *message);
+GL_APICALL void GL_APIENTRY glPopDebugGroupKHR (void);
+GL_APICALL void GL_APIENTRY glObjectLabelKHR (GLenum identifier, GLuint name, GLsizei length, const GLchar *label);
+GL_APICALL void GL_APIENTRY glGetObjectLabelKHR (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label);
+GL_APICALL void GL_APIENTRY glObjectPtrLabelKHR (const void *ptr, GLsizei length, const GLchar *label);
+GL_APICALL void GL_APIENTRY glGetObjectPtrLabelKHR (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label);
+GL_APICALL void GL_APIENTRY glGetPointervKHR (GLenum pname, GLvoid **params);
+#endif
+typedef void (GL_APIENTRYP PFNGLDEBUGMESSAGECONTROLKHRPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
+typedef void (GL_APIENTRYP PFNGLDEBUGMESSAGEINSERTKHRPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf);
+typedef void (GL_APIENTRYP PFNGLDEBUGMESSAGECALLBACKKHRPROC) (GLDEBUGPROCKHR callback, const void *userParam);
+typedef GLuint (GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC) (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog);
+typedef void (GL_APIENTRYP PFNGLPUSHDEBUGGROUPKHRPROC) (GLenum source, GLuint id, GLsizei length, const GLchar *message);
+typedef void (GL_APIENTRYP PFNGLPOPDEBUGGROUPKHRPROC) (void);
+typedef void (GL_APIENTRYP PFNGLOBJECTLABELKHRPROC) (GLenum identifier, GLuint name, GLsizei length, const GLchar *label);
+typedef void (GL_APIENTRYP PFNGLGETOBJECTLABELKHRPROC) (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label);
+typedef void (GL_APIENTRYP PFNGLOBJECTPTRLABELKHRPROC) (const void *ptr, GLsizei length, const GLchar *label);
+typedef void (GL_APIENTRYP PFNGLGETOBJECTPTRLABELKHRPROC) (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label);
+typedef void (GL_APIENTRYP PFNGLGETPOINTERVKHRPROC) (GLenum pname, GLvoid **params);
+#endif
+
+#ifndef GL_KHR_texture_compression_astc_ldr
+#define GL_KHR_texture_compression_astc_ldr 1
+#endif
+
+
+/*------------------------------------------------------------------------*
+ * AMD extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_AMD_compressed_3DC_texture */
+#ifndef GL_AMD_compressed_3DC_texture
+#define GL_AMD_compressed_3DC_texture 1
+#endif
+
+/* GL_AMD_compressed_ATC_texture */
+#ifndef GL_AMD_compressed_ATC_texture
+#define GL_AMD_compressed_ATC_texture 1
+#endif
+
+/* AMD_performance_monitor */
+#ifndef GL_AMD_performance_monitor
+#define GL_AMD_performance_monitor 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glGetPerfMonitorGroupsAMD (GLint *numGroups, GLsizei groupsSize, GLuint *groups);
+GL_APICALL void GL_APIENTRY glGetPerfMonitorCountersAMD (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters);
+GL_APICALL void GL_APIENTRY glGetPerfMonitorGroupStringAMD (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString);
+GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterStringAMD (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString);
+GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterInfoAMD (GLuint group, GLuint counter, GLenum pname, GLvoid *data);
+GL_APICALL void GL_APIENTRY glGenPerfMonitorsAMD (GLsizei n, GLuint *monitors);
+GL_APICALL void GL_APIENTRY glDeletePerfMonitorsAMD (GLsizei n, GLuint *monitors);
+GL_APICALL void GL_APIENTRY glSelectPerfMonitorCountersAMD (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *countersList);
+GL_APICALL void GL_APIENTRY glBeginPerfMonitorAMD (GLuint monitor);
+GL_APICALL void GL_APIENTRY glEndPerfMonitorAMD (GLuint monitor);
+GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterDataAMD (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten);
+#endif
+typedef void (GL_APIENTRYP PFNGLGETPERFMONITORGROUPSAMDPROC) (GLint *numGroups, GLsizei groupsSize, GLuint *groups);
+typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERSAMDPROC) (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters);
+typedef void (GL_APIENTRYP PFNGLGETPERFMONITORGROUPSTRINGAMDPROC) (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString);
+typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERSTRINGAMDPROC) (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString);
+typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERINFOAMDPROC) (GLuint group, GLuint counter, GLenum pname, GLvoid *data);
+typedef void (GL_APIENTRYP PFNGLGENPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors);
+typedef void (GL_APIENTRYP PFNGLDELETEPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors);
+typedef void (GL_APIENTRYP PFNGLSELECTPERFMONITORCOUNTERSAMDPROC) (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *countersList);
+typedef void (GL_APIENTRYP PFNGLBEGINPERFMONITORAMDPROC) (GLuint monitor);
+typedef void (GL_APIENTRYP PFNGLENDPERFMONITORAMDPROC) (GLuint monitor);
+typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERDATAAMDPROC) (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten);
+#endif
+
+/* GL_AMD_program_binary_Z400 */
+#ifndef GL_AMD_program_binary_Z400
+#define GL_AMD_program_binary_Z400 1
+#endif
+
+/*------------------------------------------------------------------------*
+ * ANGLE extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_ANGLE_depth_texture */
+#ifndef GL_ANGLE_depth_texture
+#define GL_ANGLE_depth_texture 1
+#endif
+
+/* GL_ANGLE_framebuffer_blit */
+#ifndef GL_ANGLE_framebuffer_blit
+#define GL_ANGLE_framebuffer_blit 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glBlitFramebufferANGLE (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+#endif
+typedef void (GL_APIENTRYP PFNGLBLITFRAMEBUFFERANGLEPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+#endif
+
+/* GL_ANGLE_framebuffer_multisample */
+#ifndef GL_ANGLE_framebuffer_multisample
+#define GL_ANGLE_framebuffer_multisample 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleANGLE (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+#endif
+typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEANGLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+#endif
+
+#ifndef GL_ANGLE_instanced_arrays
+#define GL_ANGLE_instanced_arrays 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDrawArraysInstancedANGLE (GLenum mode, GLint first, GLsizei count, GLsizei primcount);
+GL_APICALL void GL_APIENTRY glDrawElementsInstancedANGLE (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
+GL_APICALL void GL_APIENTRY glVertexAttribDivisorANGLE (GLuint index, GLuint divisor);
+#endif
+typedef void (GL_APIENTRYP PFNGLDRAWARRAYSINSTANCEDANGLEPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount);
+typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSINSTANCEDANGLEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
+typedef void (GL_APIENTRYP PFNGLVERTEXATTRIBDIVISORANGLEPROC) (GLuint index, GLuint divisor);
+#endif
+
+/* GL_ANGLE_pack_reverse_row_order */
+#ifndef GL_ANGLE_pack_reverse_row_order
+#define GL_ANGLE_pack_reverse_row_order 1
+#endif
+
+/* GL_ANGLE_program_binary */
+#ifndef GL_ANGLE_program_binary
+#define GL_ANGLE_program_binary 1
+#endif
+
+/* GL_ANGLE_texture_compression_dxt3 */
+#ifndef GL_ANGLE_texture_compression_dxt3
+#define GL_ANGLE_texture_compression_dxt3 1
+#endif
+
+/* GL_ANGLE_texture_compression_dxt5 */
+#ifndef GL_ANGLE_texture_compression_dxt5
+#define GL_ANGLE_texture_compression_dxt5 1
+#endif
+
+/* GL_ANGLE_texture_usage */
+#ifndef GL_ANGLE_texture_usage
+#define GL_ANGLE_texture_usage 1
+#endif
+
+#ifndef GL_ANGLE_translated_shader_source
+#define GL_ANGLE_translated_shader_source 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glGetTranslatedShaderSourceANGLE (GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source);
+#endif
+typedef void (GL_APIENTRYP PFNGLGETTRANSLATEDSHADERSOURCEANGLEPROC) (GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source);
+#endif
+
+/*------------------------------------------------------------------------*
+ * APPLE extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_APPLE_copy_texture_levels */
+#ifndef GL_APPLE_copy_texture_levels
+#define GL_APPLE_copy_texture_levels 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glCopyTextureLevelsAPPLE (GLuint destinationTexture, GLuint sourceTexture, GLint sourceBaseLevel, GLsizei sourceLevelCount);
+#endif
+typedef void (GL_APIENTRYP PFNGLCOPYTEXTURELEVELSAPPLEPROC) (GLuint destinationTexture, GLuint sourceTexture, GLint sourceBaseLevel, GLsizei sourceLevelCount);
+#endif
+
+/* GL_APPLE_framebuffer_multisample */
+#ifndef GL_APPLE_framebuffer_multisample
+#define GL_APPLE_framebuffer_multisample 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleAPPLE (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glResolveMultisampleFramebufferAPPLE (void);
+#endif /* GL_GLEXT_PROTOTYPES */
+typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEAPPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLRESOLVEMULTISAMPLEFRAMEBUFFERAPPLEPROC) (void);
+#endif
+
+/* GL_APPLE_rgb_422 */
+#ifndef GL_APPLE_rgb_422
+#define GL_APPLE_rgb_422 1
+#endif
+
+/* GL_APPLE_sync */
+#ifndef GL_APPLE_sync
+#define GL_APPLE_sync 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL GLsync GL_APIENTRY glFenceSyncAPPLE (GLenum condition, GLbitfield flags);
+GL_APICALL GLboolean GL_APIENTRY glIsSyncAPPLE (GLsync sync);
+GL_APICALL void GL_APIENTRY glDeleteSyncAPPLE (GLsync sync);
+GL_APICALL GLenum GL_APIENTRY glClientWaitSyncAPPLE (GLsync sync, GLbitfield flags, GLuint64 timeout);
+GL_APICALL void GL_APIENTRY glWaitSyncAPPLE (GLsync sync, GLbitfield flags, GLuint64 timeout);
+GL_APICALL void GL_APIENTRY glGetInteger64vAPPLE (GLenum pname, GLint64 *params);
+GL_APICALL void GL_APIENTRY glGetSyncivAPPLE (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values);
+#endif
+typedef GLsync (GL_APIENTRYP PFNGLFENCESYNCAPPLEPROC) (GLenum condition, GLbitfield flags);
+typedef GLboolean (GL_APIENTRYP PFNGLISSYNCAPPLEPROC) (GLsync sync);
+typedef void (GL_APIENTRYP PFNGLDELETESYNCAPPLEPROC) (GLsync sync);
+typedef GLenum (GL_APIENTRYP PFNGLCLIENTWAITSYNCAPPLEPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout);
+typedef void (GL_APIENTRYP PFNGLWAITSYNCAPPLEPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout);
+typedef void (GL_APIENTRYP PFNGLGETINTEGER64VAPPLEPROC) (GLenum pname, GLint64 *params);
+typedef void (GL_APIENTRYP PFNGLGETSYNCIVAPPLEPROC) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values);
+#endif
+
+/* GL_APPLE_texture_format_BGRA8888 */
+#ifndef GL_APPLE_texture_format_BGRA8888
+#define GL_APPLE_texture_format_BGRA8888 1
+#endif
+
+/* GL_APPLE_texture_max_level */
+#ifndef GL_APPLE_texture_max_level
+#define GL_APPLE_texture_max_level 1
+#endif
+
+/*------------------------------------------------------------------------*
+ * ARM extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_ARM_mali_program_binary */
+#ifndef GL_ARM_mali_program_binary
+#define GL_ARM_mali_program_binary 1
+#endif
+
+/* GL_ARM_mali_shader_binary */
+#ifndef GL_ARM_mali_shader_binary
+#define GL_ARM_mali_shader_binary 1
+#endif
+
+/* GL_ARM_rgba8 */
+#ifndef GL_ARM_rgba8
+#define GL_ARM_rgba8 1
+#endif
+
+/*------------------------------------------------------------------------*
+ * EXT extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_EXT_blend_minmax */
+#ifndef GL_EXT_blend_minmax
+#define GL_EXT_blend_minmax 1
+#endif
+
+/* GL_EXT_color_buffer_half_float */
+#ifndef GL_EXT_color_buffer_half_float
+#define GL_EXT_color_buffer_half_float 1
+#endif
+
+/* GL_EXT_debug_label */
+#ifndef GL_EXT_debug_label
+#define GL_EXT_debug_label 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glLabelObjectEXT (GLenum type, GLuint object, GLsizei length, const GLchar *label);
+GL_APICALL void GL_APIENTRY glGetObjectLabelEXT (GLenum type, GLuint object, GLsizei bufSize, GLsizei *length, GLchar *label);
+#endif
+typedef void (GL_APIENTRYP PFNGLLABELOBJECTEXTPROC) (GLenum type, GLuint object, GLsizei length, const GLchar *label);
+typedef void (GL_APIENTRYP PFNGLGETOBJECTLABELEXTPROC) (GLenum type, GLuint object, GLsizei bufSize, GLsizei *length, GLchar *label);
+#endif
+
+/* GL_EXT_debug_marker */
+#ifndef GL_EXT_debug_marker
+#define GL_EXT_debug_marker 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glInsertEventMarkerEXT (GLsizei length, const GLchar *marker);
+GL_APICALL void GL_APIENTRY glPushGroupMarkerEXT (GLsizei length, const GLchar *marker);
+GL_APICALL void GL_APIENTRY glPopGroupMarkerEXT (void);
+#endif
+typedef void (GL_APIENTRYP PFNGLINSERTEVENTMARKEREXTPROC) (GLsizei length, const GLchar *marker);
+typedef void (GL_APIENTRYP PFNGLPUSHGROUPMARKEREXTPROC) (GLsizei length, const GLchar *marker);
+typedef void (GL_APIENTRYP PFNGLPOPGROUPMARKEREXTPROC) (void);
+#endif
+
+/* GL_EXT_discard_framebuffer */
+#ifndef GL_EXT_discard_framebuffer
+#define GL_EXT_discard_framebuffer 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDiscardFramebufferEXT (GLenum target, GLsizei numAttachments, const GLenum *attachments);
+#endif
+typedef void (GL_APIENTRYP PFNGLDISCARDFRAMEBUFFEREXTPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments);
+#endif
+
+#ifndef GL_EXT_disjoint_timer_query
+#define GL_EXT_disjoint_timer_query 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glGenQueriesEXT (GLsizei n, GLuint *ids);
+GL_APICALL void GL_APIENTRY glDeleteQueriesEXT (GLsizei n, const GLuint *ids);
+GL_APICALL GLboolean GL_APIENTRY glIsQueryEXT (GLuint id);
+GL_APICALL void GL_APIENTRY glBeginQueryEXT (GLenum target, GLuint id);
+GL_APICALL void GL_APIENTRY glEndQueryEXT (GLenum target);
+GL_APICALL void GL_APIENTRY glQueryCounterEXT (GLuint id, GLenum target);
+GL_APICALL void GL_APIENTRY glGetQueryivEXT (GLenum target, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glGetQueryObjectivEXT (GLuint id, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glGetQueryObjectuivEXT (GLuint id, GLenum pname, GLuint *params);
+GL_APICALL void GL_APIENTRY glGetQueryObjecti64vEXT (GLuint id, GLenum pname, GLint64 *params);
+GL_APICALL void GL_APIENTRY glGetQueryObjectui64vEXT (GLuint id, GLenum pname, GLuint64 *params);
+#endif
+typedef void (GL_APIENTRYP PFNGLGENQUERIESEXTPROC) (GLsizei n, GLuint *ids);
+typedef void (GL_APIENTRYP PFNGLDELETEQUERIESEXTPROC) (GLsizei n, const GLuint *ids);
+typedef GLboolean (GL_APIENTRYP PFNGLISQUERYEXTPROC) (GLuint id);
+typedef void (GL_APIENTRYP PFNGLBEGINQUERYEXTPROC) (GLenum target, GLuint id);
+typedef void (GL_APIENTRYP PFNGLENDQUERYEXTPROC) (GLenum target);
+typedef void (GL_APIENTRYP PFNGLQUERYCOUNTEREXTPROC) (GLuint id, GLenum target);
+typedef void (GL_APIENTRYP PFNGLGETQUERYIVEXTPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLGETQUERYOBJECTIVEXTPROC) (GLuint id, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLGETQUERYOBJECTUIVEXTPROC) (GLuint id, GLenum pname, GLuint *params);
+typedef void (GL_APIENTRYP PFNGLGETQUERYOBJECTI64VEXTPROC) (GLuint id, GLenum pname, GLint64 *params);
+typedef void (GL_APIENTRYP PFNGLGETQUERYOBJECTUI64VEXTPROC) (GLuint id, GLenum pname, GLuint64 *params);
+#endif /* GL_EXT_disjoint_timer_query */
+
+#ifndef GL_EXT_draw_buffers
+#define GL_EXT_draw_buffers 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDrawBuffersEXT (GLsizei n, const GLenum *bufs);
+#endif
+typedef void (GL_APIENTRYP PFNGLDRAWBUFFERSEXTPROC) (GLsizei n, const GLenum *bufs);
+#endif /* GL_EXT_draw_buffers */
+
+/* GL_EXT_map_buffer_range */
+#ifndef GL_EXT_map_buffer_range
+#define GL_EXT_map_buffer_range 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void* GL_APIENTRY glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access);
+GL_APICALL void GL_APIENTRY glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length);
+#endif
+typedef void* (GL_APIENTRYP PFNGLMAPBUFFERRANGEEXTPROC) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access);
+typedef void (GL_APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEEXTPROC) (GLenum target, GLintptr offset, GLsizeiptr length);
+#endif
+
+/* GL_EXT_multisampled_render_to_texture */
+#ifndef GL_EXT_multisampled_render_to_texture
+#define GL_EXT_multisampled_render_to_texture 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleEXT (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glFramebufferTexture2DMultisampleEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples);
+#endif
+typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples);
+#endif
+
+/* GL_EXT_multiview_draw_buffers */
+#ifndef GL_EXT_multiview_draw_buffers
+#define GL_EXT_multiview_draw_buffers 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glReadBufferIndexedEXT (GLenum src, GLint index);
+GL_APICALL void GL_APIENTRY glDrawBuffersIndexedEXT (GLint n, const GLenum *location, const GLint *indices);
+GL_APICALL void GL_APIENTRY glGetIntegeri_vEXT (GLenum target, GLuint index, GLint *data);
+#endif
+typedef void (GL_APIENTRYP PFNGLREADBUFFERINDEXEDEXTPROC) (GLenum src, GLint index);
+typedef void (GL_APIENTRYP PFNGLDRAWBUFFERSINDEXEDEXTPROC) (GLint n, const GLenum *location, const GLint *indices);
+typedef void (GL_APIENTRYP PFNGLGETINTEGERI_VEXTPROC) (GLenum target, GLuint index, GLint *data);
+#endif
+
+#ifndef GL_EXT_multi_draw_arrays
+#define GL_EXT_multi_draw_arrays 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glMultiDrawArraysEXT (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount);
+GL_APICALL void GL_APIENTRY glMultiDrawElementsEXT (GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount);
+#endif /* GL_GLEXT_PROTOTYPES */
+typedef void (GL_APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount);
+typedef void (GL_APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount);
+#endif
+
+/* GL_EXT_occlusion_query_boolean */
+#ifndef GL_EXT_occlusion_query_boolean
+#define GL_EXT_occlusion_query_boolean 1
+/* All entry points also exist in GL_EXT_disjoint_timer_query */
+#endif
+
+/* GL_EXT_read_format_bgra */
+#ifndef GL_EXT_read_format_bgra
+#define GL_EXT_read_format_bgra 1
+#endif
+
+/* GL_EXT_robustness */
+#ifndef GL_EXT_robustness
+#define GL_EXT_robustness 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL GLenum GL_APIENTRY glGetGraphicsResetStatusEXT (void);
+GL_APICALL void GL_APIENTRY glReadnPixelsEXT (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid *data);
+GL_APICALL void GL_APIENTRY glGetnUniformfvEXT (GLuint program, GLint location, GLsizei bufSize, GLfloat *params);
+GL_APICALL void GL_APIENTRY glGetnUniformivEXT (GLuint program, GLint location, GLsizei bufSize, GLint *params);
+#endif
+typedef GLenum (GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSEXTPROC) (void);
+typedef void (GL_APIENTRYP PFNGLREADNPIXELSEXTPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid *data);
+typedef void (GL_APIENTRYP PFNGLGETNUNIFORMFVEXTPROC) (GLuint program, GLint location, GLsizei bufSize, GLfloat *params);
+typedef void (GL_APIENTRYP PFNGLGETNUNIFORMIVEXTPROC) (GLuint program, GLint location, GLsizei bufSize, GLint *params);
+#endif
+
+/* GL_EXT_separate_shader_objects */
+#ifndef GL_EXT_separate_shader_objects
+#define GL_EXT_separate_shader_objects 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glUseProgramStagesEXT (GLuint pipeline, GLbitfield stages, GLuint program);
+GL_APICALL void GL_APIENTRY glActiveShaderProgramEXT (GLuint pipeline, GLuint program);
+GL_APICALL GLuint GL_APIENTRY glCreateShaderProgramvEXT (GLenum type, GLsizei count, const GLchar **strings);
+GL_APICALL void GL_APIENTRY glBindProgramPipelineEXT (GLuint pipeline);
+GL_APICALL void GL_APIENTRY glDeleteProgramPipelinesEXT (GLsizei n, const GLuint *pipelines);
+GL_APICALL void GL_APIENTRY glGenProgramPipelinesEXT (GLsizei n, GLuint *pipelines);
+GL_APICALL GLboolean GL_APIENTRY glIsProgramPipelineEXT (GLuint pipeline);
+GL_APICALL void GL_APIENTRY glProgramParameteriEXT (GLuint program, GLenum pname, GLint value);
+GL_APICALL void GL_APIENTRY glGetProgramPipelineivEXT (GLuint pipeline, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glProgramUniform1iEXT (GLuint program, GLint location, GLint x);
+GL_APICALL void GL_APIENTRY glProgramUniform2iEXT (GLuint program, GLint location, GLint x, GLint y);
+GL_APICALL void GL_APIENTRY glProgramUniform3iEXT (GLuint program, GLint location, GLint x, GLint y, GLint z);
+GL_APICALL void GL_APIENTRY glProgramUniform4iEXT (GLuint program, GLint location, GLint x, GLint y, GLint z, GLint w);
+GL_APICALL void GL_APIENTRY glProgramUniform1fEXT (GLuint program, GLint location, GLfloat x);
+GL_APICALL void GL_APIENTRY glProgramUniform2fEXT (GLuint program, GLint location, GLfloat x, GLfloat y);
+GL_APICALL void GL_APIENTRY glProgramUniform3fEXT (GLuint program, GLint location, GLfloat x, GLfloat y, GLfloat z);
+GL_APICALL void GL_APIENTRY glProgramUniform4fEXT (GLuint program, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GL_APICALL void GL_APIENTRY glProgramUniform1ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GL_APICALL void GL_APIENTRY glProgramUniform2ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GL_APICALL void GL_APIENTRY glProgramUniform3ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GL_APICALL void GL_APIENTRY glProgramUniform4ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GL_APICALL void GL_APIENTRY glProgramUniform1fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniform2fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniform3fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniform4fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniformMatrix2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniformMatrix3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniformMatrix4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glValidateProgramPipelineEXT (GLuint pipeline);
+GL_APICALL void GL_APIENTRY glGetProgramPipelineInfoLogEXT (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+#endif
+typedef void (GL_APIENTRYP PFNGLUSEPROGRAMSTAGESEXTPROC) (GLuint pipeline, GLbitfield stages, GLuint program);
+typedef void (GL_APIENTRYP PFNGLACTIVESHADERPROGRAMEXTPROC) (GLuint pipeline, GLuint program);
+typedef GLuint (GL_APIENTRYP PFNGLCREATESHADERPROGRAMVEXTPROC) (GLenum type, GLsizei count, const GLchar **strings);
+typedef void (GL_APIENTRYP PFNGLBINDPROGRAMPIPELINEEXTPROC) (GLuint pipeline);
+typedef void (GL_APIENTRYP PFNGLDELETEPROGRAMPIPELINESEXTPROC) (GLsizei n, const GLuint *pipelines);
+typedef void (GL_APIENTRYP PFNGLGENPROGRAMPIPELINESEXTPROC) (GLsizei n, GLuint *pipelines);
+typedef GLboolean (GL_APIENTRYP PFNGLISPROGRAMPIPELINEEXTPROC) (GLuint pipeline);
+typedef void (GL_APIENTRYP PFNGLPROGRAMPARAMETERIEXTPROC) (GLuint program, GLenum pname, GLint value);
+typedef void (GL_APIENTRYP PFNGLGETPROGRAMPIPELINEIVEXTPROC) (GLuint pipeline, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1IEXTPROC) (GLuint program, GLint location, GLint x);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2IEXTPROC) (GLuint program, GLint location, GLint x, GLint y);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3IEXTPROC) (GLuint program, GLint location, GLint x, GLint y, GLint z);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4IEXTPROC) (GLuint program, GLint location, GLint x, GLint y, GLint z, GLint w);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1FEXTPROC) (GLuint program, GLint location, GLfloat x);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2FEXTPROC) (GLuint program, GLint location, GLfloat x, GLfloat y);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3FEXTPROC) (GLuint program, GLint location, GLfloat x, GLfloat y, GLfloat z);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4FEXTPROC) (GLuint program, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLVALIDATEPROGRAMPIPELINEEXTPROC) (GLuint pipeline);
+typedef void (GL_APIENTRYP PFNGLGETPROGRAMPIPELINEINFOLOGEXTPROC) (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+#endif
+
+/* GL_EXT_shader_framebuffer_fetch */
+#ifndef GL_EXT_shader_framebuffer_fetch
+#define GL_EXT_shader_framebuffer_fetch 1
+#endif
+
+/* GL_EXT_shader_texture_lod */
+#ifndef GL_EXT_shader_texture_lod
+#define GL_EXT_shader_texture_lod 1
+#endif
+
+/* GL_EXT_shadow_samplers */
+#ifndef GL_EXT_shadow_samplers
+#define GL_EXT_shadow_samplers 1
+#endif
+
+/* GL_EXT_sRGB */
+#ifndef GL_EXT_sRGB
+#define GL_EXT_sRGB 1
+#endif
+
+/* GL_EXT_texture_compression_dxt1 */
+#ifndef GL_EXT_texture_compression_dxt1
+#define GL_EXT_texture_compression_dxt1 1
+#endif
+
+/* GL_EXT_texture_filter_anisotropic */
+#ifndef GL_EXT_texture_filter_anisotropic
+#define GL_EXT_texture_filter_anisotropic 1
+#endif
+
+/* GL_EXT_texture_format_BGRA8888 */
+#ifndef GL_EXT_texture_format_BGRA8888
+#define GL_EXT_texture_format_BGRA8888 1
+#endif
+
+/* GL_EXT_texture_rg */
+#ifndef GL_EXT_texture_rg
+#define GL_EXT_texture_rg 1
+#endif
+
+/* GL_EXT_texture_storage */
+#ifndef GL_EXT_texture_storage
+#define GL_EXT_texture_storage 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glTexStorage1DEXT (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+GL_APICALL void GL_APIENTRY glTexStorage2DEXT (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glTexStorage3DEXT (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+GL_APICALL void GL_APIENTRY glTextureStorage1DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+GL_APICALL void GL_APIENTRY glTextureStorage2DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glTextureStorage3DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+#endif
+typedef void (GL_APIENTRYP PFNGLTEXSTORAGE1DEXTPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+typedef void (GL_APIENTRYP PFNGLTEXSTORAGE2DEXTPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLTEXSTORAGE3DEXTPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGE1DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGE2DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGE3DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+#endif
+
+/* GL_EXT_texture_type_2_10_10_10_REV */
+#ifndef GL_EXT_texture_type_2_10_10_10_REV
+#define GL_EXT_texture_type_2_10_10_10_REV 1
+#endif
+
+/* GL_EXT_unpack_subimage */
+#ifndef GL_EXT_unpack_subimage
+#define GL_EXT_unpack_subimage 1
+#endif
+
+/*------------------------------------------------------------------------*
+ * DMP extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_DMP_shader_binary */
+#ifndef GL_DMP_shader_binary
+#define GL_DMP_shader_binary 1
+#endif
+
+/*------------------------------------------------------------------------*
+ * FJ extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_FJ_shader_binary_GCCSO */
+#ifndef GL_FJ_shader_binary_GCCSO
+#define GL_FJ_shader_binary_GCCSO 1
+#endif
+
+/*------------------------------------------------------------------------*
+ * IMG extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_IMG_program_binary */
+#ifndef GL_IMG_program_binary
+#define GL_IMG_program_binary 1
+#endif
+
+/* GL_IMG_read_format */
+#ifndef GL_IMG_read_format
+#define GL_IMG_read_format 1
+#endif
+
+/* GL_IMG_shader_binary */
+#ifndef GL_IMG_shader_binary
+#define GL_IMG_shader_binary 1
+#endif
+
+/* GL_IMG_texture_compression_pvrtc */
+#ifndef GL_IMG_texture_compression_pvrtc
+#define GL_IMG_texture_compression_pvrtc 1
+#endif
+
+/* GL_IMG_texture_compression_pvrtc2 */
+#ifndef GL_IMG_texture_compression_pvrtc2
+#define GL_IMG_texture_compression_pvrtc2 1
+#endif
+
+/* GL_IMG_multisampled_render_to_texture */
+#ifndef GL_IMG_multisampled_render_to_texture
+#define GL_IMG_multisampled_render_to_texture 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleIMG (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glFramebufferTexture2DMultisampleIMG (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples);
+#endif
+typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMGPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMGPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples);
+#endif
+
+/*------------------------------------------------------------------------*
+ * NV extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_NV_coverage_sample */
+#ifndef GL_NV_coverage_sample
+#define GL_NV_coverage_sample 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glCoverageMaskNV (GLboolean mask);
+GL_APICALL void GL_APIENTRY glCoverageOperationNV (GLenum operation);
+#endif
+typedef void (GL_APIENTRYP PFNGLCOVERAGEMASKNVPROC) (GLboolean mask);
+typedef void (GL_APIENTRYP PFNGLCOVERAGEOPERATIONNVPROC) (GLenum operation);
+#endif
+
+/* GL_NV_depth_nonlinear */
+#ifndef GL_NV_depth_nonlinear
+#define GL_NV_depth_nonlinear 1
+#endif
+
+/* GL_NV_draw_buffers */
+#ifndef GL_NV_draw_buffers
+#define GL_NV_draw_buffers 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDrawBuffersNV (GLsizei n, const GLenum *bufs);
+#endif
+typedef void (GL_APIENTRYP PFNGLDRAWBUFFERSNVPROC) (GLsizei n, const GLenum *bufs);
+#endif
+
+/* GL_NV_draw_instanced */
+#ifndef GL_NV_draw_instanced
+#define GL_NV_draw_instanced 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDrawArraysInstancedNV (GLenum mode, GLint first, GLsizei count, GLsizei primcount);
+GL_APICALL void GL_APIENTRY glDrawElementsInstancedNV (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount);
+#endif
+typedef void (GL_APIENTRYP PFNGLDRAWARRAYSINSTANCEDNVPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount);
+typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSINSTANCEDNVPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount);
+#endif
+
+/* GL_NV_fbo_color_attachments */
+#ifndef GL_NV_fbo_color_attachments
+#define GL_NV_fbo_color_attachments 1
+#endif
+
+/* GL_NV_fence */
+#ifndef GL_NV_fence
+#define GL_NV_fence 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDeleteFencesNV (GLsizei n, const GLuint *fences);
+GL_APICALL void GL_APIENTRY glGenFencesNV (GLsizei n, GLuint *fences);
+GL_APICALL GLboolean GL_APIENTRY glIsFenceNV (GLuint fence);
+GL_APICALL GLboolean GL_APIENTRY glTestFenceNV (GLuint fence);
+GL_APICALL void GL_APIENTRY glGetFenceivNV (GLuint fence, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glFinishFenceNV (GLuint fence);
+GL_APICALL void GL_APIENTRY glSetFenceNV (GLuint fence, GLenum condition);
+#endif
+typedef void (GL_APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences);
+typedef void (GL_APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences);
+typedef GLboolean (GL_APIENTRYP PFNGLISFENCENVPROC) (GLuint fence);
+typedef GLboolean (GL_APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence);
+typedef void (GL_APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence);
+typedef void (GL_APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition);
+#endif
+
+/* GL_NV_framebuffer_blit */
+#ifndef GL_NV_framebuffer_blit
+#define GL_NV_framebuffer_blit 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glBlitFramebufferNV (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+#endif
+typedef void (GL_APIENTRYP PFNGLBLITFRAMEBUFFERNVPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+#endif
+
+/* GL_NV_framebuffer_multisample */
+#ifndef GL_NV_framebuffer_multisample
+#define GL_NV_framebuffer_multisample 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleNV ( GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+#endif
+typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLENVPROC) ( GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+#endif
+
+/* GL_NV_generate_mipmap_sRGB */
+#ifndef GL_NV_generate_mipmap_sRGB
+#define GL_NV_generate_mipmap_sRGB 1
+#endif
+
+/* GL_NV_instanced_arrays */
+#ifndef GL_NV_instanced_arrays
+#define GL_NV_instanced_arrays 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glVertexAttribDivisorNV (GLuint index, GLuint divisor);
+#endif
+typedef void (GL_APIENTRYP PFNGLVERTEXATTRIBDIVISORNVPROC) (GLuint index, GLuint divisor);
+#endif
+
+/* GL_NV_read_buffer */
+#ifndef GL_NV_read_buffer
+#define GL_NV_read_buffer 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glReadBufferNV (GLenum mode);
+#endif
+typedef void (GL_APIENTRYP PFNGLREADBUFFERNVPROC) (GLenum mode);
+#endif
+
+/* GL_NV_read_buffer_front */
+#ifndef GL_NV_read_buffer_front
+#define GL_NV_read_buffer_front 1
+#endif
+
+/* GL_NV_read_depth */
+#ifndef GL_NV_read_depth
+#define GL_NV_read_depth 1
+#endif
+
+/* GL_NV_read_depth_stencil */
+#ifndef GL_NV_read_depth_stencil
+#define GL_NV_read_depth_stencil 1
+#endif
+
+/* GL_NV_read_stencil */
+#ifndef GL_NV_read_stencil
+#define GL_NV_read_stencil 1
+#endif
+
+/* GL_NV_shadow_samplers_array */
+#ifndef GL_NV_shadow_samplers_array
+#define GL_NV_shadow_samplers_array 1
+#endif
+
+/* GL_NV_shadow_samplers_cube */
+#ifndef GL_NV_shadow_samplers_cube
+#define GL_NV_shadow_samplers_cube 1
+#endif
+
+/* GL_NV_sRGB_formats */
+#ifndef GL_NV_sRGB_formats
+#define GL_NV_sRGB_formats 1
+#endif
+
+/* GL_NV_texture_border_clamp */
+#ifndef GL_NV_texture_border_clamp
+#define GL_NV_texture_border_clamp 1
+#endif
+
+/* GL_NV_texture_compression_s3tc_update */
+#ifndef GL_NV_texture_compression_s3tc_update
+#define GL_NV_texture_compression_s3tc_update 1
+#endif
+
+/* GL_NV_texture_npot_2D_mipmap */
+#ifndef GL_NV_texture_npot_2D_mipmap
+#define GL_NV_texture_npot_2D_mipmap 1
+#endif
+
+/*------------------------------------------------------------------------*
+ * QCOM extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_QCOM_alpha_test */
+#ifndef GL_QCOM_alpha_test
+#define GL_QCOM_alpha_test 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glAlphaFuncQCOM (GLenum func, GLclampf ref);
+#endif
+typedef void (GL_APIENTRYP PFNGLALPHAFUNCQCOMPROC) (GLenum func, GLclampf ref);
+#endif
+
+/* GL_QCOM_binning_control */
+#ifndef GL_QCOM_binning_control
+#define GL_QCOM_binning_control 1
+#endif
+
+/* GL_QCOM_driver_control */
+#ifndef GL_QCOM_driver_control
+#define GL_QCOM_driver_control 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glGetDriverControlsQCOM (GLint *num, GLsizei size, GLuint *driverControls);
+GL_APICALL void GL_APIENTRY glGetDriverControlStringQCOM (GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString);
+GL_APICALL void GL_APIENTRY glEnableDriverControlQCOM (GLuint driverControl);
+GL_APICALL void GL_APIENTRY glDisableDriverControlQCOM (GLuint driverControl);
+#endif
+typedef void (GL_APIENTRYP PFNGLGETDRIVERCONTROLSQCOMPROC) (GLint *num, GLsizei size, GLuint *driverControls);
+typedef void (GL_APIENTRYP PFNGLGETDRIVERCONTROLSTRINGQCOMPROC) (GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString);
+typedef void (GL_APIENTRYP PFNGLENABLEDRIVERCONTROLQCOMPROC) (GLuint driverControl);
+typedef void (GL_APIENTRYP PFNGLDISABLEDRIVERCONTROLQCOMPROC) (GLuint driverControl);
+#endif
+
+/* GL_QCOM_extended_get */
+#ifndef GL_QCOM_extended_get
+#define GL_QCOM_extended_get 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glExtGetTexturesQCOM (GLuint *textures, GLint maxTextures, GLint *numTextures);
+GL_APICALL void GL_APIENTRY glExtGetBuffersQCOM (GLuint *buffers, GLint maxBuffers, GLint *numBuffers);
+GL_APICALL void GL_APIENTRY glExtGetRenderbuffersQCOM (GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers);
+GL_APICALL void GL_APIENTRY glExtGetFramebuffersQCOM (GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers);
+GL_APICALL void GL_APIENTRY glExtGetTexLevelParameterivQCOM (GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glExtTexObjectStateOverrideiQCOM (GLenum target, GLenum pname, GLint param);
+GL_APICALL void GL_APIENTRY glExtGetTexSubImageQCOM (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels);
+GL_APICALL void GL_APIENTRY glExtGetBufferPointervQCOM (GLenum target, GLvoid **params);
+#endif
+typedef void (GL_APIENTRYP PFNGLEXTGETTEXTURESQCOMPROC) (GLuint *textures, GLint maxTextures, GLint *numTextures);
+typedef void (GL_APIENTRYP PFNGLEXTGETBUFFERSQCOMPROC) (GLuint *buffers, GLint maxBuffers, GLint *numBuffers);
+typedef void (GL_APIENTRYP PFNGLEXTGETRENDERBUFFERSQCOMPROC) (GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers);
+typedef void (GL_APIENTRYP PFNGLEXTGETFRAMEBUFFERSQCOMPROC) (GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers);
+typedef void (GL_APIENTRYP PFNGLEXTGETTEXLEVELPARAMETERIVQCOMPROC) (GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLEXTTEXOBJECTSTATEOVERRIDEIQCOMPROC) (GLenum target, GLenum pname, GLint param);
+typedef void (GL_APIENTRYP PFNGLEXTGETTEXSUBIMAGEQCOMPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels);
+typedef void (GL_APIENTRYP PFNGLEXTGETBUFFERPOINTERVQCOMPROC) (GLenum target, GLvoid **params);
+#endif
+
+/* GL_QCOM_extended_get2 */
+#ifndef GL_QCOM_extended_get2
+#define GL_QCOM_extended_get2 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glExtGetShadersQCOM (GLuint *shaders, GLint maxShaders, GLint *numShaders);
+GL_APICALL void GL_APIENTRY glExtGetProgramsQCOM (GLuint *programs, GLint maxPrograms, GLint *numPrograms);
+GL_APICALL GLboolean GL_APIENTRY glExtIsProgramBinaryQCOM (GLuint program);
+GL_APICALL void GL_APIENTRY glExtGetProgramBinarySourceQCOM (GLuint program, GLenum shadertype, GLchar *source, GLint *length);
+#endif
+typedef void (GL_APIENTRYP PFNGLEXTGETSHADERSQCOMPROC) (GLuint *shaders, GLint maxShaders, GLint *numShaders);
+typedef void (GL_APIENTRYP PFNGLEXTGETPROGRAMSQCOMPROC) (GLuint *programs, GLint maxPrograms, GLint *numPrograms);
+typedef GLboolean (GL_APIENTRYP PFNGLEXTISPROGRAMBINARYQCOMPROC) (GLuint program);
+typedef void (GL_APIENTRYP PFNGLEXTGETPROGRAMBINARYSOURCEQCOMPROC) (GLuint program, GLenum shadertype, GLchar *source, GLint *length);
+#endif
+
+/* GL_QCOM_perfmon_global_mode */
+#ifndef GL_QCOM_perfmon_global_mode
+#define GL_QCOM_perfmon_global_mode 1
+#endif
+
+/* GL_QCOM_writeonly_rendering */
+#ifndef GL_QCOM_writeonly_rendering
+#define GL_QCOM_writeonly_rendering 1
+#endif
+
+/* GL_QCOM_tiled_rendering */
+#ifndef GL_QCOM_tiled_rendering
+#define GL_QCOM_tiled_rendering 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glStartTilingQCOM (GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask);
+GL_APICALL void GL_APIENTRY glEndTilingQCOM (GLbitfield preserveMask);
+#endif
+typedef void (GL_APIENTRYP PFNGLSTARTTILINGQCOMPROC) (GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask);
+typedef void (GL_APIENTRYP PFNGLENDTILINGQCOMPROC) (GLbitfield preserveMask);
+#endif
+
+/*------------------------------------------------------------------------*
+ * VIV extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_VIV_shader_binary */
+#ifndef GL_VIV_shader_binary
+#define GL_VIV_shader_binary 1
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __gl2ext_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_opengles2_gl2platform.h b/src/3rdparty/SDL2/include/SDL2/SDL_opengles2_gl2platform.h
new file mode 100644
index 0000000..c325686
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_opengles2_gl2platform.h
@@ -0,0 +1,30 @@
+#ifndef __gl2platform_h_
+#define __gl2platform_h_
+
+/* $Revision: 10602 $ on $Date:: 2010-03-04 22:35:34 -0800 #$ */
+
+/*
+ * This document is licensed under the SGI Free Software B License Version
+ * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ .
+ */
+
+/* Platform-specific types and definitions for OpenGL ES 2.X gl2.h
+ *
+ * Adopters may modify khrplatform.h and this file to suit their platform.
+ * You are encouraged to submit all modifications to the Khronos group so that
+ * they can be included in future versions of this file. Please submit changes
+ * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla)
+ * by filing a bug against product "OpenGL-ES" component "Registry".
+ */
+
+/*#include <KHR/khrplatform.h>*/
+
+#ifndef GL_APICALL
+#define GL_APICALL KHRONOS_APICALL
+#endif
+
+#ifndef GL_APIENTRY
+#define GL_APIENTRY KHRONOS_APIENTRY
+#endif
+
+#endif /* __gl2platform_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_opengles2_khrplatform.h b/src/3rdparty/SDL2/include/SDL2/SDL_opengles2_khrplatform.h
new file mode 100644
index 0000000..c9e6f17
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_opengles2_khrplatform.h
@@ -0,0 +1,282 @@
+#ifndef __khrplatform_h_
+#define __khrplatform_h_
+
+/*
+** Copyright (c) 2008-2009 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+
+/* Khronos platform-specific types and definitions.
+ *
+ * $Revision: 23298 $ on $Date: 2013-09-30 17:07:13 -0700 (Mon, 30 Sep 2013) $
+ *
+ * Adopters may modify this file to suit their platform. Adopters are
+ * encouraged to submit platform specific modifications to the Khronos
+ * group so that they can be included in future versions of this file.
+ * Please submit changes by sending them to the public Khronos Bugzilla
+ * (http://khronos.org/bugzilla) by filing a bug against product
+ * "Khronos (general)" component "Registry".
+ *
+ * A predefined template which fills in some of the bug fields can be
+ * reached using http://tinyurl.com/khrplatform-h-bugreport, but you
+ * must create a Bugzilla login first.
+ *
+ *
+ * See the Implementer's Guidelines for information about where this file
+ * should be located on your system and for more details of its use:
+ * http://www.khronos.org/registry/implementers_guide.pdf
+ *
+ * This file should be included as
+ * #include <KHR/khrplatform.h>
+ * by Khronos client API header files that use its types and defines.
+ *
+ * The types in khrplatform.h should only be used to define API-specific types.
+ *
+ * Types defined in khrplatform.h:
+ * khronos_int8_t signed 8 bit
+ * khronos_uint8_t unsigned 8 bit
+ * khronos_int16_t signed 16 bit
+ * khronos_uint16_t unsigned 16 bit
+ * khronos_int32_t signed 32 bit
+ * khronos_uint32_t unsigned 32 bit
+ * khronos_int64_t signed 64 bit
+ * khronos_uint64_t unsigned 64 bit
+ * khronos_intptr_t signed same number of bits as a pointer
+ * khronos_uintptr_t unsigned same number of bits as a pointer
+ * khronos_ssize_t signed size
+ * khronos_usize_t unsigned size
+ * khronos_float_t signed 32 bit floating point
+ * khronos_time_ns_t unsigned 64 bit time in nanoseconds
+ * khronos_utime_nanoseconds_t unsigned time interval or absolute time in
+ * nanoseconds
+ * khronos_stime_nanoseconds_t signed time interval in nanoseconds
+ * khronos_boolean_enum_t enumerated boolean type. This should
+ * only be used as a base type when a client API's boolean type is
+ * an enum. Client APIs which use an integer or other type for
+ * booleans cannot use this as the base type for their boolean.
+ *
+ * Tokens defined in khrplatform.h:
+ *
+ * KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
+ *
+ * KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
+ * KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
+ *
+ * Calling convention macros defined in this file:
+ * KHRONOS_APICALL
+ * KHRONOS_APIENTRY
+ * KHRONOS_APIATTRIBUTES
+ *
+ * These may be used in function prototypes as:
+ *
+ * KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
+ * int arg1,
+ * int arg2) KHRONOS_APIATTRIBUTES;
+ */
+
+/*-------------------------------------------------------------------------
+ * Definition of KHRONOS_APICALL
+ *-------------------------------------------------------------------------
+ * This precedes the return type of the function in the function prototype.
+ */
+#if defined(_WIN32) && !defined(__SCITECH_SNAP__)
+# define KHRONOS_APICALL __declspec(dllimport)
+#elif defined (__SYMBIAN32__)
+# define KHRONOS_APICALL IMPORT_C
+#else
+# define KHRONOS_APICALL
+#endif
+
+/*-------------------------------------------------------------------------
+ * Definition of KHRONOS_APIENTRY
+ *-------------------------------------------------------------------------
+ * This follows the return type of the function and precedes the function
+ * name in the function prototype.
+ */
+#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
+ /* Win32 but not WinCE */
+# define KHRONOS_APIENTRY __stdcall
+#else
+# define KHRONOS_APIENTRY
+#endif
+
+/*-------------------------------------------------------------------------
+ * Definition of KHRONOS_APIATTRIBUTES
+ *-------------------------------------------------------------------------
+ * This follows the closing parenthesis of the function prototype arguments.
+ */
+#if defined (__ARMCC_2__)
+#define KHRONOS_APIATTRIBUTES __softfp
+#else
+#define KHRONOS_APIATTRIBUTES
+#endif
+
+/*-------------------------------------------------------------------------
+ * basic type definitions
+ *-----------------------------------------------------------------------*/
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
+
+
+/*
+ * Using <stdint.h>
+ */
+#include <stdint.h>
+typedef int32_t khronos_int32_t;
+typedef uint32_t khronos_uint32_t;
+typedef int64_t khronos_int64_t;
+typedef uint64_t khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif defined(__VMS ) || defined(__sgi)
+
+/*
+ * Using <inttypes.h>
+ */
+#include <inttypes.h>
+typedef int32_t khronos_int32_t;
+typedef uint32_t khronos_uint32_t;
+typedef int64_t khronos_int64_t;
+typedef uint64_t khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
+
+/*
+ * Win32
+ */
+typedef __int32 khronos_int32_t;
+typedef unsigned __int32 khronos_uint32_t;
+typedef __int64 khronos_int64_t;
+typedef unsigned __int64 khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif defined(__sun__) || defined(__digital__)
+
+/*
+ * Sun or Digital
+ */
+typedef int khronos_int32_t;
+typedef unsigned int khronos_uint32_t;
+#if defined(__arch64__) || defined(_LP64)
+typedef long int khronos_int64_t;
+typedef unsigned long int khronos_uint64_t;
+#else
+typedef long long int khronos_int64_t;
+typedef unsigned long long int khronos_uint64_t;
+#endif /* __arch64__ */
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif 0
+
+/*
+ * Hypothetical platform with no float or int64 support
+ */
+typedef int khronos_int32_t;
+typedef unsigned int khronos_uint32_t;
+#define KHRONOS_SUPPORT_INT64 0
+#define KHRONOS_SUPPORT_FLOAT 0
+
+#else
+
+/*
+ * Generic fallback
+ */
+#include <stdint.h>
+typedef int32_t khronos_int32_t;
+typedef uint32_t khronos_uint32_t;
+typedef int64_t khronos_int64_t;
+typedef uint64_t khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#endif
+
+
+/*
+ * Types that are (so far) the same on all platforms
+ */
+typedef signed char khronos_int8_t;
+typedef unsigned char khronos_uint8_t;
+typedef signed short int khronos_int16_t;
+typedef unsigned short int khronos_uint16_t;
+
+/*
+ * Types that differ between LLP64 and LP64 architectures - in LLP64,
+ * pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
+ * to be the only LLP64 architecture in current use.
+ */
+#ifdef _WIN64
+typedef signed long long int khronos_intptr_t;
+typedef unsigned long long int khronos_uintptr_t;
+typedef signed long long int khronos_ssize_t;
+typedef unsigned long long int khronos_usize_t;
+#else
+typedef signed long int khronos_intptr_t;
+typedef unsigned long int khronos_uintptr_t;
+typedef signed long int khronos_ssize_t;
+typedef unsigned long int khronos_usize_t;
+#endif
+
+#if KHRONOS_SUPPORT_FLOAT
+/*
+ * Float type
+ */
+typedef float khronos_float_t;
+#endif
+
+#if KHRONOS_SUPPORT_INT64
+/* Time types
+ *
+ * These types can be used to represent a time interval in nanoseconds or
+ * an absolute Unadjusted System Time. Unadjusted System Time is the number
+ * of nanoseconds since some arbitrary system event (e.g. since the last
+ * time the system booted). The Unadjusted System Time is an unsigned
+ * 64 bit value that wraps back to 0 every 584 years. Time intervals
+ * may be either signed or unsigned.
+ */
+typedef khronos_uint64_t khronos_utime_nanoseconds_t;
+typedef khronos_int64_t khronos_stime_nanoseconds_t;
+#endif
+
+/*
+ * Dummy value used to pad enum types to 32 bits.
+ */
+#ifndef KHRONOS_MAX_ENUM
+#define KHRONOS_MAX_ENUM 0x7FFFFFFF
+#endif
+
+/*
+ * Enumerated boolean type
+ *
+ * Values other than zero should be considered to be true. Therefore
+ * comparisons should not be made against KHRONOS_TRUE.
+ */
+typedef enum {
+ KHRONOS_FALSE = 0,
+ KHRONOS_TRUE = 1,
+ KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
+} khronos_boolean_enum_t;
+
+#endif /* __khrplatform_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_pixels.h b/src/3rdparty/SDL2/include/SDL2/SDL_pixels.h
new file mode 100644
index 0000000..0b4364b
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_pixels.h
@@ -0,0 +1,470 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_pixels.h
+ *
+ * Header for the enumerated pixel format definitions.
+ */
+
+#ifndef SDL_pixels_h_
+#define SDL_pixels_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_endian.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \name Transparency definitions
+ *
+ * These define alpha as the opacity of a surface.
+ */
+/* @{ */
+#define SDL_ALPHA_OPAQUE 255
+#define SDL_ALPHA_TRANSPARENT 0
+/* @} */
+
+/** Pixel type. */
+enum
+{
+ SDL_PIXELTYPE_UNKNOWN,
+ SDL_PIXELTYPE_INDEX1,
+ SDL_PIXELTYPE_INDEX4,
+ SDL_PIXELTYPE_INDEX8,
+ SDL_PIXELTYPE_PACKED8,
+ SDL_PIXELTYPE_PACKED16,
+ SDL_PIXELTYPE_PACKED32,
+ SDL_PIXELTYPE_ARRAYU8,
+ SDL_PIXELTYPE_ARRAYU16,
+ SDL_PIXELTYPE_ARRAYU32,
+ SDL_PIXELTYPE_ARRAYF16,
+ SDL_PIXELTYPE_ARRAYF32
+};
+
+/** Bitmap pixel order, high bit -> low bit. */
+enum
+{
+ SDL_BITMAPORDER_NONE,
+ SDL_BITMAPORDER_4321,
+ SDL_BITMAPORDER_1234
+};
+
+/** Packed component order, high bit -> low bit. */
+enum
+{
+ SDL_PACKEDORDER_NONE,
+ SDL_PACKEDORDER_XRGB,
+ SDL_PACKEDORDER_RGBX,
+ SDL_PACKEDORDER_ARGB,
+ SDL_PACKEDORDER_RGBA,
+ SDL_PACKEDORDER_XBGR,
+ SDL_PACKEDORDER_BGRX,
+ SDL_PACKEDORDER_ABGR,
+ SDL_PACKEDORDER_BGRA
+};
+
+/** Array component order, low byte -> high byte. */
+/* !!! FIXME: in 2.1, make these not overlap differently with
+ !!! FIXME: SDL_PACKEDORDER_*, so we can simplify SDL_ISPIXELFORMAT_ALPHA */
+enum
+{
+ SDL_ARRAYORDER_NONE,
+ SDL_ARRAYORDER_RGB,
+ SDL_ARRAYORDER_RGBA,
+ SDL_ARRAYORDER_ARGB,
+ SDL_ARRAYORDER_BGR,
+ SDL_ARRAYORDER_BGRA,
+ SDL_ARRAYORDER_ABGR
+};
+
+/** Packed component layout. */
+enum
+{
+ SDL_PACKEDLAYOUT_NONE,
+ SDL_PACKEDLAYOUT_332,
+ SDL_PACKEDLAYOUT_4444,
+ SDL_PACKEDLAYOUT_1555,
+ SDL_PACKEDLAYOUT_5551,
+ SDL_PACKEDLAYOUT_565,
+ SDL_PACKEDLAYOUT_8888,
+ SDL_PACKEDLAYOUT_2101010,
+ SDL_PACKEDLAYOUT_1010102
+};
+
+#define SDL_DEFINE_PIXELFOURCC(A, B, C, D) SDL_FOURCC(A, B, C, D)
+
+#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
+ ((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
+ ((bits) << 8) | ((bytes) << 0))
+
+#define SDL_PIXELFLAG(X) (((X) >> 28) & 0x0F)
+#define SDL_PIXELTYPE(X) (((X) >> 24) & 0x0F)
+#define SDL_PIXELORDER(X) (((X) >> 20) & 0x0F)
+#define SDL_PIXELLAYOUT(X) (((X) >> 16) & 0x0F)
+#define SDL_BITSPERPIXEL(X) (((X) >> 8) & 0xFF)
+#define SDL_BYTESPERPIXEL(X) \
+ (SDL_ISPIXELFORMAT_FOURCC(X) ? \
+ ((((X) == SDL_PIXELFORMAT_YUY2) || \
+ ((X) == SDL_PIXELFORMAT_UYVY) || \
+ ((X) == SDL_PIXELFORMAT_YVYU)) ? 2 : 1) : (((X) >> 0) & 0xFF))
+
+#define SDL_ISPIXELFORMAT_INDEXED(format) \
+ (!SDL_ISPIXELFORMAT_FOURCC(format) && \
+ ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) || \
+ (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \
+ (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)))
+
+#define SDL_ISPIXELFORMAT_PACKED(format) \
+ (!SDL_ISPIXELFORMAT_FOURCC(format) && \
+ ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED8) || \
+ (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED16) || \
+ (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32)))
+
+#define SDL_ISPIXELFORMAT_ARRAY(format) \
+ (!SDL_ISPIXELFORMAT_FOURCC(format) && \
+ ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU8) || \
+ (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU16) || \
+ (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU32) || \
+ (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF16) || \
+ (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF32)))
+
+#define SDL_ISPIXELFORMAT_ALPHA(format) \
+ ((SDL_ISPIXELFORMAT_PACKED(format) && \
+ ((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \
+ (SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || \
+ (SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || \
+ (SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA))) || \
+ (SDL_ISPIXELFORMAT_ARRAY(format) && \
+ ((SDL_PIXELORDER(format) == SDL_ARRAYORDER_ARGB) || \
+ (SDL_PIXELORDER(format) == SDL_ARRAYORDER_RGBA) || \
+ (SDL_PIXELORDER(format) == SDL_ARRAYORDER_ABGR) || \
+ (SDL_PIXELORDER(format) == SDL_ARRAYORDER_BGRA))))
+
+/* The flag is set to 1 because 0x1? is not in the printable ASCII range */
+#define SDL_ISPIXELFORMAT_FOURCC(format) \
+ ((format) && (SDL_PIXELFLAG(format) != 1))
+
+/* Note: If you modify this list, update SDL_GetPixelFormatName() */
+enum
+{
+ SDL_PIXELFORMAT_UNKNOWN,
+ SDL_PIXELFORMAT_INDEX1LSB =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_4321, 0,
+ 1, 0),
+ SDL_PIXELFORMAT_INDEX1MSB =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_1234, 0,
+ 1, 0),
+ SDL_PIXELFORMAT_INDEX4LSB =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_4321, 0,
+ 4, 0),
+ SDL_PIXELFORMAT_INDEX4MSB =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_1234, 0,
+ 4, 0),
+ SDL_PIXELFORMAT_INDEX8 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1),
+ SDL_PIXELFORMAT_RGB332 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED8, SDL_PACKEDORDER_XRGB,
+ SDL_PACKEDLAYOUT_332, 8, 1),
+ SDL_PIXELFORMAT_RGB444 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
+ SDL_PACKEDLAYOUT_4444, 12, 2),
+ SDL_PIXELFORMAT_RGB555 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
+ SDL_PACKEDLAYOUT_1555, 15, 2),
+ SDL_PIXELFORMAT_BGR555 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
+ SDL_PACKEDLAYOUT_1555, 15, 2),
+ SDL_PIXELFORMAT_ARGB4444 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
+ SDL_PACKEDLAYOUT_4444, 16, 2),
+ SDL_PIXELFORMAT_RGBA4444 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA,
+ SDL_PACKEDLAYOUT_4444, 16, 2),
+ SDL_PIXELFORMAT_ABGR4444 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
+ SDL_PACKEDLAYOUT_4444, 16, 2),
+ SDL_PIXELFORMAT_BGRA4444 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA,
+ SDL_PACKEDLAYOUT_4444, 16, 2),
+ SDL_PIXELFORMAT_ARGB1555 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
+ SDL_PACKEDLAYOUT_1555, 16, 2),
+ SDL_PIXELFORMAT_RGBA5551 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA,
+ SDL_PACKEDLAYOUT_5551, 16, 2),
+ SDL_PIXELFORMAT_ABGR1555 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
+ SDL_PACKEDLAYOUT_1555, 16, 2),
+ SDL_PIXELFORMAT_BGRA5551 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA,
+ SDL_PACKEDLAYOUT_5551, 16, 2),
+ SDL_PIXELFORMAT_RGB565 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
+ SDL_PACKEDLAYOUT_565, 16, 2),
+ SDL_PIXELFORMAT_BGR565 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
+ SDL_PACKEDLAYOUT_565, 16, 2),
+ SDL_PIXELFORMAT_RGB24 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_RGB, 0,
+ 24, 3),
+ SDL_PIXELFORMAT_BGR24 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_BGR, 0,
+ 24, 3),
+ SDL_PIXELFORMAT_RGB888 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XRGB,
+ SDL_PACKEDLAYOUT_8888, 24, 4),
+ SDL_PIXELFORMAT_RGBX8888 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBX,
+ SDL_PACKEDLAYOUT_8888, 24, 4),
+ SDL_PIXELFORMAT_BGR888 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XBGR,
+ SDL_PACKEDLAYOUT_8888, 24, 4),
+ SDL_PIXELFORMAT_BGRX8888 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_BGRX,
+ SDL_PACKEDLAYOUT_8888, 24, 4),
+ SDL_PIXELFORMAT_ARGB8888 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
+ SDL_PACKEDLAYOUT_8888, 32, 4),
+ SDL_PIXELFORMAT_RGBA8888 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBA,
+ SDL_PACKEDLAYOUT_8888, 32, 4),
+ SDL_PIXELFORMAT_ABGR8888 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ABGR,
+ SDL_PACKEDLAYOUT_8888, 32, 4),
+ SDL_PIXELFORMAT_BGRA8888 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_BGRA,
+ SDL_PACKEDLAYOUT_8888, 32, 4),
+ SDL_PIXELFORMAT_ARGB2101010 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
+ SDL_PACKEDLAYOUT_2101010, 32, 4),
+
+ /* Aliases for RGBA byte arrays of color data, for the current platform */
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_RGBA8888,
+ SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_ARGB8888,
+ SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_BGRA8888,
+ SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_ABGR8888,
+#else
+ SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_ABGR8888,
+ SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_BGRA8888,
+ SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_ARGB8888,
+ SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_RGBA8888,
+#endif
+
+ SDL_PIXELFORMAT_YV12 = /**< Planar mode: Y + V + U (3 planes) */
+ SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
+ SDL_PIXELFORMAT_IYUV = /**< Planar mode: Y + U + V (3 planes) */
+ SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'),
+ SDL_PIXELFORMAT_YUY2 = /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
+ SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'),
+ SDL_PIXELFORMAT_UYVY = /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
+ SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'),
+ SDL_PIXELFORMAT_YVYU = /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
+ SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U'),
+ SDL_PIXELFORMAT_NV12 = /**< Planar mode: Y + U/V interleaved (2 planes) */
+ SDL_DEFINE_PIXELFOURCC('N', 'V', '1', '2'),
+ SDL_PIXELFORMAT_NV21 = /**< Planar mode: Y + V/U interleaved (2 planes) */
+ SDL_DEFINE_PIXELFOURCC('N', 'V', '2', '1'),
+ SDL_PIXELFORMAT_EXTERNAL_OES = /**< Android video texture format */
+ SDL_DEFINE_PIXELFOURCC('O', 'E', 'S', ' ')
+};
+
+typedef struct SDL_Color
+{
+ Uint8 r;
+ Uint8 g;
+ Uint8 b;
+ Uint8 a;
+} SDL_Color;
+#define SDL_Colour SDL_Color
+
+typedef struct SDL_Palette
+{
+ int ncolors;
+ SDL_Color *colors;
+ Uint32 version;
+ int refcount;
+} SDL_Palette;
+
+/**
+ * \note Everything in the pixel format structure is read-only.
+ */
+typedef struct SDL_PixelFormat
+{
+ Uint32 format;
+ SDL_Palette *palette;
+ Uint8 BitsPerPixel;
+ Uint8 BytesPerPixel;
+ Uint8 padding[2];
+ Uint32 Rmask;
+ Uint32 Gmask;
+ Uint32 Bmask;
+ Uint32 Amask;
+ Uint8 Rloss;
+ Uint8 Gloss;
+ Uint8 Bloss;
+ Uint8 Aloss;
+ Uint8 Rshift;
+ Uint8 Gshift;
+ Uint8 Bshift;
+ Uint8 Ashift;
+ int refcount;
+ struct SDL_PixelFormat *next;
+} SDL_PixelFormat;
+
+/**
+ * \brief Get the human readable name of a pixel format
+ */
+extern DECLSPEC const char* SDLCALL SDL_GetPixelFormatName(Uint32 format);
+
+/**
+ * \brief Convert one of the enumerated pixel formats to a bpp and RGBA masks.
+ *
+ * \return SDL_TRUE, or SDL_FALSE if the conversion wasn't possible.
+ *
+ * \sa SDL_MasksToPixelFormatEnum()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_PixelFormatEnumToMasks(Uint32 format,
+ int *bpp,
+ Uint32 * Rmask,
+ Uint32 * Gmask,
+ Uint32 * Bmask,
+ Uint32 * Amask);
+
+/**
+ * \brief Convert a bpp and RGBA masks to an enumerated pixel format.
+ *
+ * \return The pixel format, or ::SDL_PIXELFORMAT_UNKNOWN if the conversion
+ * wasn't possible.
+ *
+ * \sa SDL_PixelFormatEnumToMasks()
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_MasksToPixelFormatEnum(int bpp,
+ Uint32 Rmask,
+ Uint32 Gmask,
+ Uint32 Bmask,
+ Uint32 Amask);
+
+/**
+ * \brief Create an SDL_PixelFormat structure from a pixel format enum.
+ */
+extern DECLSPEC SDL_PixelFormat * SDLCALL SDL_AllocFormat(Uint32 pixel_format);
+
+/**
+ * \brief Free an SDL_PixelFormat structure.
+ */
+extern DECLSPEC void SDLCALL SDL_FreeFormat(SDL_PixelFormat *format);
+
+/**
+ * \brief Create a palette structure with the specified number of color
+ * entries.
+ *
+ * \return A new palette, or NULL if there wasn't enough memory.
+ *
+ * \note The palette entries are initialized to white.
+ *
+ * \sa SDL_FreePalette()
+ */
+extern DECLSPEC SDL_Palette *SDLCALL SDL_AllocPalette(int ncolors);
+
+/**
+ * \brief Set the palette for a pixel format structure.
+ */
+extern DECLSPEC int SDLCALL SDL_SetPixelFormatPalette(SDL_PixelFormat * format,
+ SDL_Palette *palette);
+
+/**
+ * \brief Set a range of colors in a palette.
+ *
+ * \param palette The palette to modify.
+ * \param colors An array of colors to copy into the palette.
+ * \param firstcolor The index of the first palette entry to modify.
+ * \param ncolors The number of entries to modify.
+ *
+ * \return 0 on success, or -1 if not all of the colors could be set.
+ */
+extern DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette,
+ const SDL_Color * colors,
+ int firstcolor, int ncolors);
+
+/**
+ * \brief Free a palette created with SDL_AllocPalette().
+ *
+ * \sa SDL_AllocPalette()
+ */
+extern DECLSPEC void SDLCALL SDL_FreePalette(SDL_Palette * palette);
+
+/**
+ * \brief Maps an RGB triple to an opaque pixel value for a given pixel format.
+ *
+ * \sa SDL_MapRGBA
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormat * format,
+ Uint8 r, Uint8 g, Uint8 b);
+
+/**
+ * \brief Maps an RGBA quadruple to a pixel value for a given pixel format.
+ *
+ * \sa SDL_MapRGB
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormat * format,
+ Uint8 r, Uint8 g, Uint8 b,
+ Uint8 a);
+
+/**
+ * \brief Get the RGB components from a pixel of the specified format.
+ *
+ * \sa SDL_GetRGBA
+ */
+extern DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel,
+ const SDL_PixelFormat * format,
+ Uint8 * r, Uint8 * g, Uint8 * b);
+
+/**
+ * \brief Get the RGBA components from a pixel of the specified format.
+ *
+ * \sa SDL_GetRGB
+ */
+extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel,
+ const SDL_PixelFormat * format,
+ Uint8 * r, Uint8 * g, Uint8 * b,
+ Uint8 * a);
+
+/**
+ * \brief Calculate a 256 entry gamma ramp for a gamma value.
+ */
+extern DECLSPEC void SDLCALL SDL_CalculateGammaRamp(float gamma, Uint16 * ramp);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_pixels_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_platform.h b/src/3rdparty/SDL2/include/SDL2/SDL_platform.h
new file mode 100644
index 0000000..7dea4ce
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_platform.h
@@ -0,0 +1,198 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_platform.h
+ *
+ * Try to get a standard set of platform defines.
+ */
+
+#ifndef SDL_platform_h_
+#define SDL_platform_h_
+
+#if defined(_AIX)
+#undef __AIX__
+#define __AIX__ 1
+#endif
+#if defined(__HAIKU__)
+#undef __HAIKU__
+#define __HAIKU__ 1
+#endif
+#if defined(bsdi) || defined(__bsdi) || defined(__bsdi__)
+#undef __BSDI__
+#define __BSDI__ 1
+#endif
+#if defined(_arch_dreamcast)
+#undef __DREAMCAST__
+#define __DREAMCAST__ 1
+#endif
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
+#undef __FREEBSD__
+#define __FREEBSD__ 1
+#endif
+#if defined(hpux) || defined(__hpux) || defined(__hpux__)
+#undef __HPUX__
+#define __HPUX__ 1
+#endif
+#if defined(sgi) || defined(__sgi) || defined(__sgi__) || defined(_SGI_SOURCE)
+#undef __IRIX__
+#define __IRIX__ 1
+#endif
+#if (defined(linux) || defined(__linux) || defined(__linux__))
+#undef __LINUX__
+#define __LINUX__ 1
+#endif
+#if defined(ANDROID) || defined(__ANDROID__)
+#undef __ANDROID__
+#undef __LINUX__ /* do we need to do this? */
+#define __ANDROID__ 1
+#endif
+
+#if defined(__APPLE__)
+/* lets us know what version of Mac OS X we're compiling on */
+#include "AvailabilityMacros.h"
+#include "TargetConditionals.h"
+#if TARGET_OS_TV
+#undef __TVOS__
+#define __TVOS__ 1
+#endif
+#if TARGET_OS_IPHONE
+/* if compiling for iOS */
+#undef __IPHONEOS__
+#define __IPHONEOS__ 1
+#undef __MACOSX__
+#else
+/* if not compiling for iOS */
+#undef __MACOSX__
+#define __MACOSX__ 1
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
+# error SDL for Mac OS X only supports deploying on 10.6 and above.
+#endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1060 */
+#endif /* TARGET_OS_IPHONE */
+#endif /* defined(__APPLE__) */
+
+#if defined(__NetBSD__)
+#undef __NETBSD__
+#define __NETBSD__ 1
+#endif
+#if defined(__OpenBSD__)
+#undef __OPENBSD__
+#define __OPENBSD__ 1
+#endif
+#if defined(__OS2__) || defined(__EMX__)
+#undef __OS2__
+#define __OS2__ 1
+#endif
+#if defined(osf) || defined(__osf) || defined(__osf__) || defined(_OSF_SOURCE)
+#undef __OSF__
+#define __OSF__ 1
+#endif
+#if defined(__QNXNTO__)
+#undef __QNXNTO__
+#define __QNXNTO__ 1
+#endif
+#if defined(riscos) || defined(__riscos) || defined(__riscos__)
+#undef __RISCOS__
+#define __RISCOS__ 1
+#endif
+#if defined(__sun) && defined(__SVR4)
+#undef __SOLARIS__
+#define __SOLARIS__ 1
+#endif
+
+#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
+/* Try to find out if we're compiling for WinRT or non-WinRT */
+#if defined(_MSC_VER) && defined(__has_include)
+#if __has_include(<winapifamily.h>)
+#define HAVE_WINAPIFAMILY_H 1
+#else
+#define HAVE_WINAPIFAMILY_H 0
+#endif
+
+/* If _USING_V110_SDK71_ is defined it means we are using the Windows XP toolset. */
+#elif defined(_MSC_VER) && (_MSC_VER >= 1700 && !_USING_V110_SDK71_) /* _MSC_VER == 1700 for Visual Studio 2012 */
+#define HAVE_WINAPIFAMILY_H 1
+#else
+#define HAVE_WINAPIFAMILY_H 0
+#endif
+
+#if HAVE_WINAPIFAMILY_H
+#include <winapifamily.h>
+#define WINAPI_FAMILY_WINRT (!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP))
+#else
+#define WINAPI_FAMILY_WINRT 0
+#endif /* HAVE_WINAPIFAMILY_H */
+
+#if WINAPI_FAMILY_WINRT
+#undef __WINRT__
+#define __WINRT__ 1
+#else
+#undef __WINDOWS__
+#define __WINDOWS__ 1
+#endif
+#endif /* defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) */
+
+#if defined(__WINDOWS__)
+#undef __WIN32__
+#define __WIN32__ 1
+#endif
+#if defined(__PSP__)
+#undef __PSP__
+#define __PSP__ 1
+#endif
+
+/* The NACL compiler defines __native_client__ and __pnacl__
+ * Ref: http://www.chromium.org/nativeclient/pnacl/stability-of-the-pnacl-bitcode-abi
+ */
+#if defined(__native_client__)
+#undef __LINUX__
+#undef __NACL__
+#define __NACL__ 1
+#endif
+#if defined(__pnacl__)
+#undef __LINUX__
+#undef __PNACL__
+#define __PNACL__ 1
+/* PNACL with newlib supports static linking only */
+#define __SDL_NOGETPROCADDR__
+#endif
+
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Gets the name of the platform.
+ */
+extern DECLSPEC const char * SDLCALL SDL_GetPlatform (void);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_platform_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_power.h b/src/3rdparty/SDL2/include/SDL2/SDL_power.h
new file mode 100644
index 0000000..a4fe8a9
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_power.h
@@ -0,0 +1,75 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_power_h_
+#define SDL_power_h_
+
+/**
+ * \file SDL_power.h
+ *
+ * Header for the SDL power management routines.
+ */
+
+#include "SDL_stdinc.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The basic state for the system's power supply.
+ */
+typedef enum
+{
+ SDL_POWERSTATE_UNKNOWN, /**< cannot determine power status */
+ SDL_POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */
+ SDL_POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */
+ SDL_POWERSTATE_CHARGING, /**< Plugged in, charging battery */
+ SDL_POWERSTATE_CHARGED /**< Plugged in, battery charged */
+} SDL_PowerState;
+
+
+/**
+ * \brief Get the current power supply details.
+ *
+ * \param secs Seconds of battery life left. You can pass a NULL here if
+ * you don't care. Will return -1 if we can't determine a
+ * value, or we're not running on a battery.
+ *
+ * \param pct Percentage of battery life left, between 0 and 100. You can
+ * pass a NULL here if you don't care. Will return -1 if we
+ * can't determine a value, or we're not running on a battery.
+ *
+ * \return The state of the battery (if any).
+ */
+extern DECLSPEC SDL_PowerState SDLCALL SDL_GetPowerInfo(int *secs, int *pct);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_power_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_quit.h b/src/3rdparty/SDL2/include/SDL2/SDL_quit.h
new file mode 100644
index 0000000..fea56a8
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_quit.h
@@ -0,0 +1,58 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_quit.h
+ *
+ * Include file for SDL quit event handling.
+ */
+
+#ifndef SDL_quit_h_
+#define SDL_quit_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+
+/**
+ * \file SDL_quit.h
+ *
+ * An ::SDL_QUIT event is generated when the user tries to close the application
+ * window. If it is ignored or filtered out, the window will remain open.
+ * If it is not ignored or filtered, it is queued normally and the window
+ * is allowed to close. When the window is closed, screen updates will
+ * complete, but have no effect.
+ *
+ * SDL_Init() installs signal handlers for SIGINT (keyboard interrupt)
+ * and SIGTERM (system termination request), if handlers do not already
+ * exist, that generate ::SDL_QUIT events as well. There is no way
+ * to determine the cause of an ::SDL_QUIT event, but setting a signal
+ * handler in your application will override the default generation of
+ * quit events for that signal.
+ *
+ * \sa SDL_Quit()
+ */
+
+/* There are no functions directly affecting the quit event */
+
+#define SDL_QuitRequested() \
+ (SDL_PumpEvents(), (SDL_PeepEvents(NULL,0,SDL_PEEKEVENT,SDL_QUIT,SDL_QUIT) > 0))
+
+#endif /* SDL_quit_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_rect.h b/src/3rdparty/SDL2/include/SDL2/SDL_rect.h
new file mode 100644
index 0000000..543bb61
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_rect.h
@@ -0,0 +1,148 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_rect.h
+ *
+ * Header file for SDL_rect definition and management functions.
+ */
+
+#ifndef SDL_rect_h_
+#define SDL_rect_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_pixels.h"
+#include "SDL_rwops.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The structure that defines a point
+ *
+ * \sa SDL_EnclosePoints
+ * \sa SDL_PointInRect
+ */
+typedef struct SDL_Point
+{
+ int x;
+ int y;
+} SDL_Point;
+
+/**
+ * \brief A rectangle, with the origin at the upper left.
+ *
+ * \sa SDL_RectEmpty
+ * \sa SDL_RectEquals
+ * \sa SDL_HasIntersection
+ * \sa SDL_IntersectRect
+ * \sa SDL_UnionRect
+ * \sa SDL_EnclosePoints
+ */
+typedef struct SDL_Rect
+{
+ int x, y;
+ int w, h;
+} SDL_Rect;
+
+/**
+ * \brief Returns true if point resides inside a rectangle.
+ */
+SDL_FORCE_INLINE SDL_bool SDL_PointInRect(const SDL_Point *p, const SDL_Rect *r)
+{
+ return ( (p->x >= r->x) && (p->x < (r->x + r->w)) &&
+ (p->y >= r->y) && (p->y < (r->y + r->h)) ) ? SDL_TRUE : SDL_FALSE;
+}
+
+/**
+ * \brief Returns true if the rectangle has no area.
+ */
+SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
+{
+ return ((!r) || (r->w <= 0) || (r->h <= 0)) ? SDL_TRUE : SDL_FALSE;
+}
+
+/**
+ * \brief Returns true if the two rectangles are equal.
+ */
+SDL_FORCE_INLINE SDL_bool SDL_RectEquals(const SDL_Rect *a, const SDL_Rect *b)
+{
+ return (a && b && (a->x == b->x) && (a->y == b->y) &&
+ (a->w == b->w) && (a->h == b->h)) ? SDL_TRUE : SDL_FALSE;
+}
+
+/**
+ * \brief Determine whether two rectangles intersect.
+ *
+ * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasIntersection(const SDL_Rect * A,
+ const SDL_Rect * B);
+
+/**
+ * \brief Calculate the intersection of two rectangles.
+ *
+ * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRect(const SDL_Rect * A,
+ const SDL_Rect * B,
+ SDL_Rect * result);
+
+/**
+ * \brief Calculate the union of two rectangles.
+ */
+extern DECLSPEC void SDLCALL SDL_UnionRect(const SDL_Rect * A,
+ const SDL_Rect * B,
+ SDL_Rect * result);
+
+/**
+ * \brief Calculate a minimal rectangle enclosing a set of points
+ *
+ * \return SDL_TRUE if any points were within the clipping rect
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_EnclosePoints(const SDL_Point * points,
+ int count,
+ const SDL_Rect * clip,
+ SDL_Rect * result);
+
+/**
+ * \brief Calculate the intersection of a rectangle and line segment.
+ *
+ * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRectAndLine(const SDL_Rect *
+ rect, int *X1,
+ int *Y1, int *X2,
+ int *Y2);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_rect_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_render.h b/src/3rdparty/SDL2/include/SDL2/SDL_render.h
new file mode 100644
index 0000000..d336192
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_render.h
@@ -0,0 +1,931 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_render.h
+ *
+ * Header file for SDL 2D rendering functions.
+ *
+ * This API supports the following features:
+ * * single pixel points
+ * * single pixel lines
+ * * filled rectangles
+ * * texture images
+ *
+ * The primitives may be drawn in opaque, blended, or additive modes.
+ *
+ * The texture images may be drawn in opaque, blended, or additive modes.
+ * They can have an additional color tint or alpha modulation applied to
+ * them, and may also be stretched with linear interpolation.
+ *
+ * This API is designed to accelerate simple 2D operations. You may
+ * want more functionality such as polygons and particle effects and
+ * in that case you should use SDL's OpenGL/Direct3D support or one
+ * of the many good 3D engines.
+ *
+ * These functions must be called from the main thread.
+ * See this bug for details: http://bugzilla.libsdl.org/show_bug.cgi?id=1995
+ */
+
+#ifndef SDL_render_h_
+#define SDL_render_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_rect.h"
+#include "SDL_video.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Flags used when creating a rendering context
+ */
+typedef enum
+{
+ SDL_RENDERER_SOFTWARE = 0x00000001, /**< The renderer is a software fallback */
+ SDL_RENDERER_ACCELERATED = 0x00000002, /**< The renderer uses hardware
+ acceleration */
+ SDL_RENDERER_PRESENTVSYNC = 0x00000004, /**< Present is synchronized
+ with the refresh rate */
+ SDL_RENDERER_TARGETTEXTURE = 0x00000008 /**< The renderer supports
+ rendering to texture */
+} SDL_RendererFlags;
+
+/**
+ * \brief Information on the capabilities of a render driver or context.
+ */
+typedef struct SDL_RendererInfo
+{
+ const char *name; /**< The name of the renderer */
+ Uint32 flags; /**< Supported ::SDL_RendererFlags */
+ Uint32 num_texture_formats; /**< The number of available texture formats */
+ Uint32 texture_formats[16]; /**< The available texture formats */
+ int max_texture_width; /**< The maximum texture width */
+ int max_texture_height; /**< The maximum texture height */
+} SDL_RendererInfo;
+
+/**
+ * \brief The access pattern allowed for a texture.
+ */
+typedef enum
+{
+ SDL_TEXTUREACCESS_STATIC, /**< Changes rarely, not lockable */
+ SDL_TEXTUREACCESS_STREAMING, /**< Changes frequently, lockable */
+ SDL_TEXTUREACCESS_TARGET /**< Texture can be used as a render target */
+} SDL_TextureAccess;
+
+/**
+ * \brief The texture channel modulation used in SDL_RenderCopy().
+ */
+typedef enum
+{
+ SDL_TEXTUREMODULATE_NONE = 0x00000000, /**< No modulation */
+ SDL_TEXTUREMODULATE_COLOR = 0x00000001, /**< srcC = srcC * color */
+ SDL_TEXTUREMODULATE_ALPHA = 0x00000002 /**< srcA = srcA * alpha */
+} SDL_TextureModulate;
+
+/**
+ * \brief Flip constants for SDL_RenderCopyEx
+ */
+typedef enum
+{
+ SDL_FLIP_NONE = 0x00000000, /**< Do not flip */
+ SDL_FLIP_HORIZONTAL = 0x00000001, /**< flip horizontally */
+ SDL_FLIP_VERTICAL = 0x00000002 /**< flip vertically */
+} SDL_RendererFlip;
+
+/**
+ * \brief A structure representing rendering state
+ */
+struct SDL_Renderer;
+typedef struct SDL_Renderer SDL_Renderer;
+
+/**
+ * \brief An efficient driver-specific representation of pixel data
+ */
+struct SDL_Texture;
+typedef struct SDL_Texture SDL_Texture;
+
+
+/* Function prototypes */
+
+/**
+ * \brief Get the number of 2D rendering drivers available for the current
+ * display.
+ *
+ * A render driver is a set of code that handles rendering and texture
+ * management on a particular display. Normally there is only one, but
+ * some drivers may have several available with different capabilities.
+ *
+ * \sa SDL_GetRenderDriverInfo()
+ * \sa SDL_CreateRenderer()
+ */
+extern DECLSPEC int SDLCALL SDL_GetNumRenderDrivers(void);
+
+/**
+ * \brief Get information about a specific 2D rendering driver for the current
+ * display.
+ *
+ * \param index The index of the driver to query information about.
+ * \param info A pointer to an SDL_RendererInfo struct to be filled with
+ * information on the rendering driver.
+ *
+ * \return 0 on success, -1 if the index was out of range.
+ *
+ * \sa SDL_CreateRenderer()
+ */
+extern DECLSPEC int SDLCALL SDL_GetRenderDriverInfo(int index,
+ SDL_RendererInfo * info);
+
+/**
+ * \brief Create a window and default renderer
+ *
+ * \param width The width of the window
+ * \param height The height of the window
+ * \param window_flags The flags used to create the window
+ * \param window A pointer filled with the window, or NULL on error
+ * \param renderer A pointer filled with the renderer, or NULL on error
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_CreateWindowAndRenderer(
+ int width, int height, Uint32 window_flags,
+ SDL_Window **window, SDL_Renderer **renderer);
+
+
+/**
+ * \brief Create a 2D rendering context for a window.
+ *
+ * \param window The window where rendering is displayed.
+ * \param index The index of the rendering driver to initialize, or -1 to
+ * initialize the first one supporting the requested flags.
+ * \param flags ::SDL_RendererFlags.
+ *
+ * \return A valid rendering context or NULL if there was an error.
+ *
+ * \sa SDL_CreateSoftwareRenderer()
+ * \sa SDL_GetRendererInfo()
+ * \sa SDL_DestroyRenderer()
+ */
+extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window * window,
+ int index, Uint32 flags);
+
+/**
+ * \brief Create a 2D software rendering context for a surface.
+ *
+ * \param surface The surface where rendering is done.
+ *
+ * \return A valid rendering context or NULL if there was an error.
+ *
+ * \sa SDL_CreateRenderer()
+ * \sa SDL_DestroyRenderer()
+ */
+extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateSoftwareRenderer(SDL_Surface * surface);
+
+/**
+ * \brief Get the renderer associated with a window.
+ */
+extern DECLSPEC SDL_Renderer * SDLCALL SDL_GetRenderer(SDL_Window * window);
+
+/**
+ * \brief Get information about a rendering context.
+ */
+extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_Renderer * renderer,
+ SDL_RendererInfo * info);
+
+/**
+ * \brief Get the output size in pixels of a rendering context.
+ */
+extern DECLSPEC int SDLCALL SDL_GetRendererOutputSize(SDL_Renderer * renderer,
+ int *w, int *h);
+
+/**
+ * \brief Create a texture for a rendering context.
+ *
+ * \param renderer The renderer.
+ * \param format The format of the texture.
+ * \param access One of the enumerated values in ::SDL_TextureAccess.
+ * \param w The width of the texture in pixels.
+ * \param h The height of the texture in pixels.
+ *
+ * \return The created texture is returned, or NULL if no rendering context was
+ * active, the format was unsupported, or the width or height were out
+ * of range.
+ *
+ * \note The contents of the texture are not defined at creation.
+ *
+ * \sa SDL_QueryTexture()
+ * \sa SDL_UpdateTexture()
+ * \sa SDL_DestroyTexture()
+ */
+extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(SDL_Renderer * renderer,
+ Uint32 format,
+ int access, int w,
+ int h);
+
+/**
+ * \brief Create a texture from an existing surface.
+ *
+ * \param renderer The renderer.
+ * \param surface The surface containing pixel data used to fill the texture.
+ *
+ * \return The created texture is returned, or NULL on error.
+ *
+ * \note The surface is not modified or freed by this function.
+ *
+ * \sa SDL_QueryTexture()
+ * \sa SDL_DestroyTexture()
+ */
+extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface);
+
+/**
+ * \brief Query the attributes of a texture
+ *
+ * \param texture A texture to be queried.
+ * \param format A pointer filled in with the raw format of the texture. The
+ * actual format may differ, but pixel transfers will use this
+ * format.
+ * \param access A pointer filled in with the actual access to the texture.
+ * \param w A pointer filled in with the width of the texture in pixels.
+ * \param h A pointer filled in with the height of the texture in pixels.
+ *
+ * \return 0 on success, or -1 if the texture is not valid.
+ */
+extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture * texture,
+ Uint32 * format, int *access,
+ int *w, int *h);
+
+/**
+ * \brief Set an additional color value used in render copy operations.
+ *
+ * \param texture The texture to update.
+ * \param r The red color value multiplied into copy operations.
+ * \param g The green color value multiplied into copy operations.
+ * \param b The blue color value multiplied into copy operations.
+ *
+ * \return 0 on success, or -1 if the texture is not valid or color modulation
+ * is not supported.
+ *
+ * \sa SDL_GetTextureColorMod()
+ */
+extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture * texture,
+ Uint8 r, Uint8 g, Uint8 b);
+
+
+/**
+ * \brief Get the additional color value used in render copy operations.
+ *
+ * \param texture The texture to query.
+ * \param r A pointer filled in with the current red color value.
+ * \param g A pointer filled in with the current green color value.
+ * \param b A pointer filled in with the current blue color value.
+ *
+ * \return 0 on success, or -1 if the texture is not valid.
+ *
+ * \sa SDL_SetTextureColorMod()
+ */
+extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture * texture,
+ Uint8 * r, Uint8 * g,
+ Uint8 * b);
+
+/**
+ * \brief Set an additional alpha value used in render copy operations.
+ *
+ * \param texture The texture to update.
+ * \param alpha The alpha value multiplied into copy operations.
+ *
+ * \return 0 on success, or -1 if the texture is not valid or alpha modulation
+ * is not supported.
+ *
+ * \sa SDL_GetTextureAlphaMod()
+ */
+extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture * texture,
+ Uint8 alpha);
+
+/**
+ * \brief Get the additional alpha value used in render copy operations.
+ *
+ * \param texture The texture to query.
+ * \param alpha A pointer filled in with the current alpha value.
+ *
+ * \return 0 on success, or -1 if the texture is not valid.
+ *
+ * \sa SDL_SetTextureAlphaMod()
+ */
+extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture * texture,
+ Uint8 * alpha);
+
+/**
+ * \brief Set the blend mode used for texture copy operations.
+ *
+ * \param texture The texture to update.
+ * \param blendMode ::SDL_BlendMode to use for texture blending.
+ *
+ * \return 0 on success, or -1 if the texture is not valid or the blend mode is
+ * not supported.
+ *
+ * \note If the blend mode is not supported, the closest supported mode is
+ * chosen.
+ *
+ * \sa SDL_GetTextureBlendMode()
+ */
+extern DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture * texture,
+ SDL_BlendMode blendMode);
+
+/**
+ * \brief Get the blend mode used for texture copy operations.
+ *
+ * \param texture The texture to query.
+ * \param blendMode A pointer filled in with the current blend mode.
+ *
+ * \return 0 on success, or -1 if the texture is not valid.
+ *
+ * \sa SDL_SetTextureBlendMode()
+ */
+extern DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture * texture,
+ SDL_BlendMode *blendMode);
+
+/**
+ * \brief Update the given texture rectangle with new pixel data.
+ *
+ * \param texture The texture to update
+ * \param rect A pointer to the rectangle of pixels to update, or NULL to
+ * update the entire texture.
+ * \param pixels The raw pixel data in the format of the texture.
+ * \param pitch The number of bytes in a row of pixel data, including padding between lines.
+ *
+ * The pixel data must be in the format of the texture. The pixel format can be
+ * queried with SDL_QueryTexture.
+ *
+ * \return 0 on success, or -1 if the texture is not valid.
+ *
+ * \note This is a fairly slow function.
+ */
+extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture * texture,
+ const SDL_Rect * rect,
+ const void *pixels, int pitch);
+
+/**
+ * \brief Update a rectangle within a planar YV12 or IYUV texture with new pixel data.
+ *
+ * \param texture The texture to update
+ * \param rect A pointer to the rectangle of pixels to update, or NULL to
+ * update the entire texture.
+ * \param Yplane The raw pixel data for the Y plane.
+ * \param Ypitch The number of bytes between rows of pixel data for the Y plane.
+ * \param Uplane The raw pixel data for the U plane.
+ * \param Upitch The number of bytes between rows of pixel data for the U plane.
+ * \param Vplane The raw pixel data for the V plane.
+ * \param Vpitch The number of bytes between rows of pixel data for the V plane.
+ *
+ * \return 0 on success, or -1 if the texture is not valid.
+ *
+ * \note You can use SDL_UpdateTexture() as long as your pixel data is
+ * a contiguous block of Y and U/V planes in the proper order, but
+ * this function is available if your pixel data is not contiguous.
+ */
+extern DECLSPEC int SDLCALL SDL_UpdateYUVTexture(SDL_Texture * texture,
+ const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch);
+
+/**
+ * \brief Lock a portion of the texture for write-only pixel access.
+ *
+ * \param texture The texture to lock for access, which was created with
+ * ::SDL_TEXTUREACCESS_STREAMING.
+ * \param rect A pointer to the rectangle to lock for access. If the rect
+ * is NULL, the entire texture will be locked.
+ * \param pixels This is filled in with a pointer to the locked pixels,
+ * appropriately offset by the locked area.
+ * \param pitch This is filled in with the pitch of the locked pixels.
+ *
+ * \return 0 on success, or -1 if the texture is not valid or was not created with ::SDL_TEXTUREACCESS_STREAMING.
+ *
+ * \sa SDL_UnlockTexture()
+ */
+extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture * texture,
+ const SDL_Rect * rect,
+ void **pixels, int *pitch);
+
+/**
+ * \brief Unlock a texture, uploading the changes to video memory, if needed.
+ *
+ * \sa SDL_LockTexture()
+ */
+extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture * texture);
+
+/**
+ * \brief Determines whether a window supports the use of render targets
+ *
+ * \param renderer The renderer that will be checked
+ *
+ * \return SDL_TRUE if supported, SDL_FALSE if not.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_RenderTargetSupported(SDL_Renderer *renderer);
+
+/**
+ * \brief Set a texture as the current rendering target.
+ *
+ * \param renderer The renderer.
+ * \param texture The targeted texture, which must be created with the SDL_TEXTUREACCESS_TARGET flag, or NULL for the default render target
+ *
+ * \return 0 on success, or -1 on error
+ *
+ * \sa SDL_GetRenderTarget()
+ */
+extern DECLSPEC int SDLCALL SDL_SetRenderTarget(SDL_Renderer *renderer,
+ SDL_Texture *texture);
+
+/**
+ * \brief Get the current render target or NULL for the default render target.
+ *
+ * \return The current render target
+ *
+ * \sa SDL_SetRenderTarget()
+ */
+extern DECLSPEC SDL_Texture * SDLCALL SDL_GetRenderTarget(SDL_Renderer *renderer);
+
+/**
+ * \brief Set device independent resolution for rendering
+ *
+ * \param renderer The renderer for which resolution should be set.
+ * \param w The width of the logical resolution
+ * \param h The height of the logical resolution
+ *
+ * This function uses the viewport and scaling functionality to allow a fixed logical
+ * resolution for rendering, regardless of the actual output resolution. If the actual
+ * output resolution doesn't have the same aspect ratio the output rendering will be
+ * centered within the output display.
+ *
+ * If the output display is a window, mouse events in the window will be filtered
+ * and scaled so they seem to arrive within the logical resolution.
+ *
+ * \note If this function results in scaling or subpixel drawing by the
+ * rendering backend, it will be handled using the appropriate
+ * quality hints.
+ *
+ * \sa SDL_RenderGetLogicalSize()
+ * \sa SDL_RenderSetScale()
+ * \sa SDL_RenderSetViewport()
+ */
+extern DECLSPEC int SDLCALL SDL_RenderSetLogicalSize(SDL_Renderer * renderer, int w, int h);
+
+/**
+ * \brief Get device independent resolution for rendering
+ *
+ * \param renderer The renderer from which resolution should be queried.
+ * \param w A pointer filled with the width of the logical resolution
+ * \param h A pointer filled with the height of the logical resolution
+ *
+ * \sa SDL_RenderSetLogicalSize()
+ */
+extern DECLSPEC void SDLCALL SDL_RenderGetLogicalSize(SDL_Renderer * renderer, int *w, int *h);
+
+/**
+ * \brief Set whether to force integer scales for resolution-independent rendering
+ *
+ * \param renderer The renderer for which integer scaling should be set.
+ * \param enable Enable or disable integer scaling
+ *
+ * This function restricts the logical viewport to integer values - that is, when
+ * a resolution is between two multiples of a logical size, the viewport size is
+ * rounded down to the lower multiple.
+ *
+ * \sa SDL_RenderSetLogicalSize()
+ */
+extern DECLSPEC int SDLCALL SDL_RenderSetIntegerScale(SDL_Renderer * renderer,
+ SDL_bool enable);
+
+/**
+ * \brief Get whether integer scales are forced for resolution-independent rendering
+ *
+ * \param renderer The renderer from which integer scaling should be queried.
+ *
+ * \sa SDL_RenderSetIntegerScale()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_RenderGetIntegerScale(SDL_Renderer * renderer);
+
+/**
+ * \brief Set the drawing area for rendering on the current target.
+ *
+ * \param renderer The renderer for which the drawing area should be set.
+ * \param rect The rectangle representing the drawing area, or NULL to set the viewport to the entire target.
+ *
+ * The x,y of the viewport rect represents the origin for rendering.
+ *
+ * \return 0 on success, or -1 on error
+ *
+ * \note If the window associated with the renderer is resized, the viewport is automatically reset.
+ *
+ * \sa SDL_RenderGetViewport()
+ * \sa SDL_RenderSetLogicalSize()
+ */
+extern DECLSPEC int SDLCALL SDL_RenderSetViewport(SDL_Renderer * renderer,
+ const SDL_Rect * rect);
+
+/**
+ * \brief Get the drawing area for the current target.
+ *
+ * \sa SDL_RenderSetViewport()
+ */
+extern DECLSPEC void SDLCALL SDL_RenderGetViewport(SDL_Renderer * renderer,
+ SDL_Rect * rect);
+
+/**
+ * \brief Set the clip rectangle for the current target.
+ *
+ * \param renderer The renderer for which clip rectangle should be set.
+ * \param rect A pointer to the rectangle to set as the clip rectangle, or
+ * NULL to disable clipping.
+ *
+ * \return 0 on success, or -1 on error
+ *
+ * \sa SDL_RenderGetClipRect()
+ */
+extern DECLSPEC int SDLCALL SDL_RenderSetClipRect(SDL_Renderer * renderer,
+ const SDL_Rect * rect);
+
+/**
+ * \brief Get the clip rectangle for the current target.
+ *
+ * \param renderer The renderer from which clip rectangle should be queried.
+ * \param rect A pointer filled in with the current clip rectangle, or
+ * an empty rectangle if clipping is disabled.
+ *
+ * \sa SDL_RenderSetClipRect()
+ */
+extern DECLSPEC void SDLCALL SDL_RenderGetClipRect(SDL_Renderer * renderer,
+ SDL_Rect * rect);
+
+/**
+ * \brief Get whether clipping is enabled on the given renderer.
+ *
+ * \param renderer The renderer from which clip state should be queried.
+ *
+ * \sa SDL_RenderGetClipRect()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_RenderIsClipEnabled(SDL_Renderer * renderer);
+
+
+/**
+ * \brief Set the drawing scale for rendering on the current target.
+ *
+ * \param renderer The renderer for which the drawing scale should be set.
+ * \param scaleX The horizontal scaling factor
+ * \param scaleY The vertical scaling factor
+ *
+ * The drawing coordinates are scaled by the x/y scaling factors
+ * before they are used by the renderer. This allows resolution
+ * independent drawing with a single coordinate system.
+ *
+ * \note If this results in scaling or subpixel drawing by the
+ * rendering backend, it will be handled using the appropriate
+ * quality hints. For best results use integer scaling factors.
+ *
+ * \sa SDL_RenderGetScale()
+ * \sa SDL_RenderSetLogicalSize()
+ */
+extern DECLSPEC int SDLCALL SDL_RenderSetScale(SDL_Renderer * renderer,
+ float scaleX, float scaleY);
+
+/**
+ * \brief Get the drawing scale for the current target.
+ *
+ * \param renderer The renderer from which drawing scale should be queried.
+ * \param scaleX A pointer filled in with the horizontal scaling factor
+ * \param scaleY A pointer filled in with the vertical scaling factor
+ *
+ * \sa SDL_RenderSetScale()
+ */
+extern DECLSPEC void SDLCALL SDL_RenderGetScale(SDL_Renderer * renderer,
+ float *scaleX, float *scaleY);
+
+/**
+ * \brief Set the color used for drawing operations (Rect, Line and Clear).
+ *
+ * \param renderer The renderer for which drawing color should be set.
+ * \param r The red value used to draw on the rendering target.
+ * \param g The green value used to draw on the rendering target.
+ * \param b The blue value used to draw on the rendering target.
+ * \param a The alpha value used to draw on the rendering target, usually
+ * ::SDL_ALPHA_OPAQUE (255).
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_SetRenderDrawColor(SDL_Renderer * renderer,
+ Uint8 r, Uint8 g, Uint8 b,
+ Uint8 a);
+
+/**
+ * \brief Get the color used for drawing operations (Rect, Line and Clear).
+ *
+ * \param renderer The renderer from which drawing color should be queried.
+ * \param r A pointer to the red value used to draw on the rendering target.
+ * \param g A pointer to the green value used to draw on the rendering target.
+ * \param b A pointer to the blue value used to draw on the rendering target.
+ * \param a A pointer to the alpha value used to draw on the rendering target,
+ * usually ::SDL_ALPHA_OPAQUE (255).
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_GetRenderDrawColor(SDL_Renderer * renderer,
+ Uint8 * r, Uint8 * g, Uint8 * b,
+ Uint8 * a);
+
+/**
+ * \brief Set the blend mode used for drawing operations (Fill and Line).
+ *
+ * \param renderer The renderer for which blend mode should be set.
+ * \param blendMode ::SDL_BlendMode to use for blending.
+ *
+ * \return 0 on success, or -1 on error
+ *
+ * \note If the blend mode is not supported, the closest supported mode is
+ * chosen.
+ *
+ * \sa SDL_GetRenderDrawBlendMode()
+ */
+extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer * renderer,
+ SDL_BlendMode blendMode);
+
+/**
+ * \brief Get the blend mode used for drawing operations.
+ *
+ * \param renderer The renderer from which blend mode should be queried.
+ * \param blendMode A pointer filled in with the current blend mode.
+ *
+ * \return 0 on success, or -1 on error
+ *
+ * \sa SDL_SetRenderDrawBlendMode()
+ */
+extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer,
+ SDL_BlendMode *blendMode);
+
+/**
+ * \brief Clear the current rendering target with the drawing color
+ *
+ * This function clears the entire rendering target, ignoring the viewport and
+ * the clip rectangle.
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer * renderer);
+
+/**
+ * \brief Draw a point on the current rendering target.
+ *
+ * \param renderer The renderer which should draw a point.
+ * \param x The x coordinate of the point.
+ * \param y The y coordinate of the point.
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(SDL_Renderer * renderer,
+ int x, int y);
+
+/**
+ * \brief Draw multiple points on the current rendering target.
+ *
+ * \param renderer The renderer which should draw multiple points.
+ * \param points The points to draw
+ * \param count The number of points to draw
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(SDL_Renderer * renderer,
+ const SDL_Point * points,
+ int count);
+
+/**
+ * \brief Draw a line on the current rendering target.
+ *
+ * \param renderer The renderer which should draw a line.
+ * \param x1 The x coordinate of the start point.
+ * \param y1 The y coordinate of the start point.
+ * \param x2 The x coordinate of the end point.
+ * \param y2 The y coordinate of the end point.
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderDrawLine(SDL_Renderer * renderer,
+ int x1, int y1, int x2, int y2);
+
+/**
+ * \brief Draw a series of connected lines on the current rendering target.
+ *
+ * \param renderer The renderer which should draw multiple lines.
+ * \param points The points along the lines
+ * \param count The number of points, drawing count-1 lines
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderDrawLines(SDL_Renderer * renderer,
+ const SDL_Point * points,
+ int count);
+
+/**
+ * \brief Draw a rectangle on the current rendering target.
+ *
+ * \param renderer The renderer which should draw a rectangle.
+ * \param rect A pointer to the destination rectangle, or NULL to outline the entire rendering target.
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderDrawRect(SDL_Renderer * renderer,
+ const SDL_Rect * rect);
+
+/**
+ * \brief Draw some number of rectangles on the current rendering target.
+ *
+ * \param renderer The renderer which should draw multiple rectangles.
+ * \param rects A pointer to an array of destination rectangles.
+ * \param count The number of rectangles.
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderDrawRects(SDL_Renderer * renderer,
+ const SDL_Rect * rects,
+ int count);
+
+/**
+ * \brief Fill a rectangle on the current rendering target with the drawing color.
+ *
+ * \param renderer The renderer which should fill a rectangle.
+ * \param rect A pointer to the destination rectangle, or NULL for the entire
+ * rendering target.
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderFillRect(SDL_Renderer * renderer,
+ const SDL_Rect * rect);
+
+/**
+ * \brief Fill some number of rectangles on the current rendering target with the drawing color.
+ *
+ * \param renderer The renderer which should fill multiple rectangles.
+ * \param rects A pointer to an array of destination rectangles.
+ * \param count The number of rectangles.
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer * renderer,
+ const SDL_Rect * rects,
+ int count);
+
+/**
+ * \brief Copy a portion of the texture to the current rendering target.
+ *
+ * \param renderer The renderer which should copy parts of a texture.
+ * \param texture The source texture.
+ * \param srcrect A pointer to the source rectangle, or NULL for the entire
+ * texture.
+ * \param dstrect A pointer to the destination rectangle, or NULL for the
+ * entire rendering target.
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Renderer * renderer,
+ SDL_Texture * texture,
+ const SDL_Rect * srcrect,
+ const SDL_Rect * dstrect);
+
+/**
+ * \brief Copy a portion of the source texture to the current rendering target, rotating it by angle around the given center
+ *
+ * \param renderer The renderer which should copy parts of a texture.
+ * \param texture The source texture.
+ * \param srcrect A pointer to the source rectangle, or NULL for the entire
+ * texture.
+ * \param dstrect A pointer to the destination rectangle, or NULL for the
+ * entire rendering target.
+ * \param angle An angle in degrees that indicates the rotation that will be applied to dstrect, rotating it in a clockwise direction
+ * \param center A pointer to a point indicating the point around which dstrect will be rotated (if NULL, rotation will be done around dstrect.w/2, dstrect.h/2).
+ * \param flip An SDL_RendererFlip value stating which flipping actions should be performed on the texture
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderCopyEx(SDL_Renderer * renderer,
+ SDL_Texture * texture,
+ const SDL_Rect * srcrect,
+ const SDL_Rect * dstrect,
+ const double angle,
+ const SDL_Point *center,
+ const SDL_RendererFlip flip);
+
+/**
+ * \brief Read pixels from the current rendering target.
+ *
+ * \param renderer The renderer from which pixels should be read.
+ * \param rect A pointer to the rectangle to read, or NULL for the entire
+ * render target.
+ * \param format The desired format of the pixel data, or 0 to use the format
+ * of the rendering target
+ * \param pixels A pointer to be filled in with the pixel data
+ * \param pitch The pitch of the pixels parameter.
+ *
+ * \return 0 on success, or -1 if pixel reading is not supported.
+ *
+ * \warning This is a very slow operation, and should not be used frequently.
+ */
+extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Renderer * renderer,
+ const SDL_Rect * rect,
+ Uint32 format,
+ void *pixels, int pitch);
+
+/**
+ * \brief Update the screen with rendering performed.
+ */
+extern DECLSPEC void SDLCALL SDL_RenderPresent(SDL_Renderer * renderer);
+
+/**
+ * \brief Destroy the specified texture.
+ *
+ * \sa SDL_CreateTexture()
+ * \sa SDL_CreateTextureFromSurface()
+ */
+extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture);
+
+/**
+ * \brief Destroy the rendering context for a window and free associated
+ * textures.
+ *
+ * \sa SDL_CreateRenderer()
+ */
+extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer * renderer);
+
+
+/**
+ * \brief Bind the texture to the current OpenGL/ES/ES2 context for use with
+ * OpenGL instructions.
+ *
+ * \param texture The SDL texture to bind
+ * \param texw A pointer to a float that will be filled with the texture width
+ * \param texh A pointer to a float that will be filled with the texture height
+ *
+ * \return 0 on success, or -1 if the operation is not supported
+ */
+extern DECLSPEC int SDLCALL SDL_GL_BindTexture(SDL_Texture *texture, float *texw, float *texh);
+
+/**
+ * \brief Unbind a texture from the current OpenGL/ES/ES2 context.
+ *
+ * \param texture The SDL texture to unbind
+ *
+ * \return 0 on success, or -1 if the operation is not supported
+ */
+extern DECLSPEC int SDLCALL SDL_GL_UnbindTexture(SDL_Texture *texture);
+
+/**
+ * \brief Get the CAMetalLayer associated with the given Metal renderer
+ *
+ * \param renderer The renderer to query
+ *
+ * \return CAMetalLayer* on success, or NULL if the renderer isn't a Metal renderer
+ *
+ * \sa SDL_RenderGetMetalCommandEncoder()
+ */
+extern DECLSPEC void *SDLCALL SDL_RenderGetMetalLayer(SDL_Renderer * renderer);
+
+/**
+ * \brief Get the Metal command encoder for the current frame
+ *
+ * \param renderer The renderer to query
+ *
+ * \return id<MTLRenderCommandEncoder> on success, or NULL if the renderer isn't a Metal renderer
+ *
+ * \sa SDL_RenderGetMetalLayer()
+ */
+extern DECLSPEC void *SDLCALL SDL_RenderGetMetalCommandEncoder(SDL_Renderer * renderer);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_render_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_revision.h b/src/3rdparty/SDL2/include/SDL2/SDL_revision.h
new file mode 100644
index 0000000..dbe9b97
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_revision.h
@@ -0,0 +1,2 @@
+#define SDL_REVISION "hg-11914:f1084c419f33"
+#define SDL_REVISION_NUMBER 11914
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_rwops.h b/src/3rdparty/SDL2/include/SDL2/SDL_rwops.h
new file mode 100644
index 0000000..0960699
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_rwops.h
@@ -0,0 +1,254 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_rwops.h
+ *
+ * This file provides a general interface for SDL to read and write
+ * data streams. It can easily be extended to files, memory, etc.
+ */
+
+#ifndef SDL_rwops_h_
+#define SDL_rwops_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* RWops Types */
+#define SDL_RWOPS_UNKNOWN 0U /**< Unknown stream type */
+#define SDL_RWOPS_WINFILE 1U /**< Win32 file */
+#define SDL_RWOPS_STDFILE 2U /**< Stdio file */
+#define SDL_RWOPS_JNIFILE 3U /**< Android asset */
+#define SDL_RWOPS_MEMORY 4U /**< Memory stream */
+#define SDL_RWOPS_MEMORY_RO 5U /**< Read-Only memory stream */
+
+/**
+ * This is the read/write operation structure -- very basic.
+ */
+typedef struct SDL_RWops
+{
+ /**
+ * Return the size of the file in this rwops, or -1 if unknown
+ */
+ Sint64 (SDLCALL * size) (struct SDL_RWops * context);
+
+ /**
+ * Seek to \c offset relative to \c whence, one of stdio's whence values:
+ * RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
+ *
+ * \return the final offset in the data stream, or -1 on error.
+ */
+ Sint64 (SDLCALL * seek) (struct SDL_RWops * context, Sint64 offset,
+ int whence);
+
+ /**
+ * Read up to \c maxnum objects each of size \c size from the data
+ * stream to the area pointed at by \c ptr.
+ *
+ * \return the number of objects read, or 0 at error or end of file.
+ */
+ size_t (SDLCALL * read) (struct SDL_RWops * context, void *ptr,
+ size_t size, size_t maxnum);
+
+ /**
+ * Write exactly \c num objects each of size \c size from the area
+ * pointed at by \c ptr to data stream.
+ *
+ * \return the number of objects written, or 0 at error or end of file.
+ */
+ size_t (SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
+ size_t size, size_t num);
+
+ /**
+ * Close and free an allocated SDL_RWops structure.
+ *
+ * \return 0 if successful or -1 on write error when flushing data.
+ */
+ int (SDLCALL * close) (struct SDL_RWops * context);
+
+ Uint32 type;
+ union
+ {
+#if defined(__ANDROID__)
+ struct
+ {
+ void *fileNameRef;
+ void *inputStreamRef;
+ void *readableByteChannelRef;
+ void *readMethod;
+ void *assetFileDescriptorRef;
+ long position;
+ long size;
+ long offset;
+ int fd;
+ } androidio;
+#elif defined(__WIN32__)
+ struct
+ {
+ SDL_bool append;
+ void *h;
+ struct
+ {
+ void *data;
+ size_t size;
+ size_t left;
+ } buffer;
+ } windowsio;
+#endif
+
+#ifdef HAVE_STDIO_H
+ struct
+ {
+ SDL_bool autoclose;
+ FILE *fp;
+ } stdio;
+#endif
+ struct
+ {
+ Uint8 *base;
+ Uint8 *here;
+ Uint8 *stop;
+ } mem;
+ struct
+ {
+ void *data1;
+ void *data2;
+ } unknown;
+ } hidden;
+
+} SDL_RWops;
+
+
+/**
+ * \name RWFrom functions
+ *
+ * Functions to create SDL_RWops structures from various data streams.
+ */
+/* @{ */
+
+extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file,
+ const char *mode);
+
+#ifdef HAVE_STDIO_H
+extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp,
+ SDL_bool autoclose);
+#else
+extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(void * fp,
+ SDL_bool autoclose);
+#endif
+
+extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, int size);
+extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem(const void *mem,
+ int size);
+
+/* @} *//* RWFrom functions */
+
+
+extern DECLSPEC SDL_RWops *SDLCALL SDL_AllocRW(void);
+extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops * area);
+
+#define RW_SEEK_SET 0 /**< Seek from the beginning of data */
+#define RW_SEEK_CUR 1 /**< Seek relative to current read point */
+#define RW_SEEK_END 2 /**< Seek relative to the end of data */
+
+/**
+ * \name Read/write macros
+ *
+ * Macros to easily read and write from an SDL_RWops structure.
+ */
+/* @{ */
+#define SDL_RWsize(ctx) (ctx)->size(ctx)
+#define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence)
+#define SDL_RWtell(ctx) (ctx)->seek(ctx, 0, RW_SEEK_CUR)
+#define SDL_RWread(ctx, ptr, size, n) (ctx)->read(ctx, ptr, size, n)
+#define SDL_RWwrite(ctx, ptr, size, n) (ctx)->write(ctx, ptr, size, n)
+#define SDL_RWclose(ctx) (ctx)->close(ctx)
+/* @} *//* Read/write macros */
+
+
+/**
+ * Load all the data from an SDL data stream.
+ *
+ * The data is allocated with a zero byte at the end (null terminated)
+ *
+ * If \c datasize is not NULL, it is filled with the size of the data read.
+ *
+ * If \c freesrc is non-zero, the stream will be closed after being read.
+ *
+ * The data should be freed with SDL_free().
+ *
+ * \return the data, or NULL if there was an error.
+ */
+extern DECLSPEC void *SDLCALL SDL_LoadFile_RW(SDL_RWops * src, size_t *datasize,
+ int freesrc);
+
+/**
+ * Load an entire file.
+ *
+ * Convenience macro.
+ */
+#define SDL_LoadFile(file, datasize) SDL_LoadFile_RW(SDL_RWFromFile(file, "rb"), datasize, 1)
+
+/**
+ * \name Read endian functions
+ *
+ * Read an item of the specified endianness and return in native format.
+ */
+/* @{ */
+extern DECLSPEC Uint8 SDLCALL SDL_ReadU8(SDL_RWops * src);
+extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops * src);
+extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops * src);
+extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops * src);
+extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops * src);
+extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops * src);
+extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops * src);
+/* @} *//* Read endian functions */
+
+/**
+ * \name Write endian functions
+ *
+ * Write an item of native format to the specified endianness.
+ */
+/* @{ */
+extern DECLSPEC size_t SDLCALL SDL_WriteU8(SDL_RWops * dst, Uint8 value);
+extern DECLSPEC size_t SDLCALL SDL_WriteLE16(SDL_RWops * dst, Uint16 value);
+extern DECLSPEC size_t SDLCALL SDL_WriteBE16(SDL_RWops * dst, Uint16 value);
+extern DECLSPEC size_t SDLCALL SDL_WriteLE32(SDL_RWops * dst, Uint32 value);
+extern DECLSPEC size_t SDLCALL SDL_WriteBE32(SDL_RWops * dst, Uint32 value);
+extern DECLSPEC size_t SDLCALL SDL_WriteLE64(SDL_RWops * dst, Uint64 value);
+extern DECLSPEC size_t SDLCALL SDL_WriteBE64(SDL_RWops * dst, Uint64 value);
+/* @} *//* Write endian functions */
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_rwops_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_scancode.h b/src/3rdparty/SDL2/include/SDL2/SDL_scancode.h
new file mode 100644
index 0000000..63871aa
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_scancode.h
@@ -0,0 +1,413 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_scancode.h
+ *
+ * Defines keyboard scancodes.
+ */
+
+#ifndef SDL_scancode_h_
+#define SDL_scancode_h_
+
+#include "SDL_stdinc.h"
+
+/**
+ * \brief The SDL keyboard scancode representation.
+ *
+ * Values of this type are used to represent keyboard keys, among other places
+ * in the \link SDL_Keysym::scancode key.keysym.scancode \endlink field of the
+ * SDL_Event structure.
+ *
+ * The values in this enumeration are based on the USB usage page standard:
+ * http://www.usb.org/developers/hidpage/Hut1_12v2.pdf
+ */
+typedef enum
+{
+ SDL_SCANCODE_UNKNOWN = 0,
+
+ /**
+ * \name Usage page 0x07
+ *
+ * These values are from usage page 0x07 (USB keyboard page).
+ */
+ /* @{ */
+
+ SDL_SCANCODE_A = 4,
+ SDL_SCANCODE_B = 5,
+ SDL_SCANCODE_C = 6,
+ SDL_SCANCODE_D = 7,
+ SDL_SCANCODE_E = 8,
+ SDL_SCANCODE_F = 9,
+ SDL_SCANCODE_G = 10,
+ SDL_SCANCODE_H = 11,
+ SDL_SCANCODE_I = 12,
+ SDL_SCANCODE_J = 13,
+ SDL_SCANCODE_K = 14,
+ SDL_SCANCODE_L = 15,
+ SDL_SCANCODE_M = 16,
+ SDL_SCANCODE_N = 17,
+ SDL_SCANCODE_O = 18,
+ SDL_SCANCODE_P = 19,
+ SDL_SCANCODE_Q = 20,
+ SDL_SCANCODE_R = 21,
+ SDL_SCANCODE_S = 22,
+ SDL_SCANCODE_T = 23,
+ SDL_SCANCODE_U = 24,
+ SDL_SCANCODE_V = 25,
+ SDL_SCANCODE_W = 26,
+ SDL_SCANCODE_X = 27,
+ SDL_SCANCODE_Y = 28,
+ SDL_SCANCODE_Z = 29,
+
+ SDL_SCANCODE_1 = 30,
+ SDL_SCANCODE_2 = 31,
+ SDL_SCANCODE_3 = 32,
+ SDL_SCANCODE_4 = 33,
+ SDL_SCANCODE_5 = 34,
+ SDL_SCANCODE_6 = 35,
+ SDL_SCANCODE_7 = 36,
+ SDL_SCANCODE_8 = 37,
+ SDL_SCANCODE_9 = 38,
+ SDL_SCANCODE_0 = 39,
+
+ SDL_SCANCODE_RETURN = 40,
+ SDL_SCANCODE_ESCAPE = 41,
+ SDL_SCANCODE_BACKSPACE = 42,
+ SDL_SCANCODE_TAB = 43,
+ SDL_SCANCODE_SPACE = 44,
+
+ SDL_SCANCODE_MINUS = 45,
+ SDL_SCANCODE_EQUALS = 46,
+ SDL_SCANCODE_LEFTBRACKET = 47,
+ SDL_SCANCODE_RIGHTBRACKET = 48,
+ SDL_SCANCODE_BACKSLASH = 49, /**< Located at the lower left of the return
+ * key on ISO keyboards and at the right end
+ * of the QWERTY row on ANSI keyboards.
+ * Produces REVERSE SOLIDUS (backslash) and
+ * VERTICAL LINE in a US layout, REVERSE
+ * SOLIDUS and VERTICAL LINE in a UK Mac
+ * layout, NUMBER SIGN and TILDE in a UK
+ * Windows layout, DOLLAR SIGN and POUND SIGN
+ * in a Swiss German layout, NUMBER SIGN and
+ * APOSTROPHE in a German layout, GRAVE
+ * ACCENT and POUND SIGN in a French Mac
+ * layout, and ASTERISK and MICRO SIGN in a
+ * French Windows layout.
+ */
+ SDL_SCANCODE_NONUSHASH = 50, /**< ISO USB keyboards actually use this code
+ * instead of 49 for the same key, but all
+ * OSes I've seen treat the two codes
+ * identically. So, as an implementor, unless
+ * your keyboard generates both of those
+ * codes and your OS treats them differently,
+ * you should generate SDL_SCANCODE_BACKSLASH
+ * instead of this code. As a user, you
+ * should not rely on this code because SDL
+ * will never generate it with most (all?)
+ * keyboards.
+ */
+ SDL_SCANCODE_SEMICOLON = 51,
+ SDL_SCANCODE_APOSTROPHE = 52,
+ SDL_SCANCODE_GRAVE = 53, /**< Located in the top left corner (on both ANSI
+ * and ISO keyboards). Produces GRAVE ACCENT and
+ * TILDE in a US Windows layout and in US and UK
+ * Mac layouts on ANSI keyboards, GRAVE ACCENT
+ * and NOT SIGN in a UK Windows layout, SECTION
+ * SIGN and PLUS-MINUS SIGN in US and UK Mac
+ * layouts on ISO keyboards, SECTION SIGN and
+ * DEGREE SIGN in a Swiss German layout (Mac:
+ * only on ISO keyboards), CIRCUMFLEX ACCENT and
+ * DEGREE SIGN in a German layout (Mac: only on
+ * ISO keyboards), SUPERSCRIPT TWO and TILDE in a
+ * French Windows layout, COMMERCIAL AT and
+ * NUMBER SIGN in a French Mac layout on ISO
+ * keyboards, and LESS-THAN SIGN and GREATER-THAN
+ * SIGN in a Swiss German, German, or French Mac
+ * layout on ANSI keyboards.
+ */
+ SDL_SCANCODE_COMMA = 54,
+ SDL_SCANCODE_PERIOD = 55,
+ SDL_SCANCODE_SLASH = 56,
+
+ SDL_SCANCODE_CAPSLOCK = 57,
+
+ SDL_SCANCODE_F1 = 58,
+ SDL_SCANCODE_F2 = 59,
+ SDL_SCANCODE_F3 = 60,
+ SDL_SCANCODE_F4 = 61,
+ SDL_SCANCODE_F5 = 62,
+ SDL_SCANCODE_F6 = 63,
+ SDL_SCANCODE_F7 = 64,
+ SDL_SCANCODE_F8 = 65,
+ SDL_SCANCODE_F9 = 66,
+ SDL_SCANCODE_F10 = 67,
+ SDL_SCANCODE_F11 = 68,
+ SDL_SCANCODE_F12 = 69,
+
+ SDL_SCANCODE_PRINTSCREEN = 70,
+ SDL_SCANCODE_SCROLLLOCK = 71,
+ SDL_SCANCODE_PAUSE = 72,
+ SDL_SCANCODE_INSERT = 73, /**< insert on PC, help on some Mac keyboards (but
+ does send code 73, not 117) */
+ SDL_SCANCODE_HOME = 74,
+ SDL_SCANCODE_PAGEUP = 75,
+ SDL_SCANCODE_DELETE = 76,
+ SDL_SCANCODE_END = 77,
+ SDL_SCANCODE_PAGEDOWN = 78,
+ SDL_SCANCODE_RIGHT = 79,
+ SDL_SCANCODE_LEFT = 80,
+ SDL_SCANCODE_DOWN = 81,
+ SDL_SCANCODE_UP = 82,
+
+ SDL_SCANCODE_NUMLOCKCLEAR = 83, /**< num lock on PC, clear on Mac keyboards
+ */
+ SDL_SCANCODE_KP_DIVIDE = 84,
+ SDL_SCANCODE_KP_MULTIPLY = 85,
+ SDL_SCANCODE_KP_MINUS = 86,
+ SDL_SCANCODE_KP_PLUS = 87,
+ SDL_SCANCODE_KP_ENTER = 88,
+ SDL_SCANCODE_KP_1 = 89,
+ SDL_SCANCODE_KP_2 = 90,
+ SDL_SCANCODE_KP_3 = 91,
+ SDL_SCANCODE_KP_4 = 92,
+ SDL_SCANCODE_KP_5 = 93,
+ SDL_SCANCODE_KP_6 = 94,
+ SDL_SCANCODE_KP_7 = 95,
+ SDL_SCANCODE_KP_8 = 96,
+ SDL_SCANCODE_KP_9 = 97,
+ SDL_SCANCODE_KP_0 = 98,
+ SDL_SCANCODE_KP_PERIOD = 99,
+
+ SDL_SCANCODE_NONUSBACKSLASH = 100, /**< This is the additional key that ISO
+ * keyboards have over ANSI ones,
+ * located between left shift and Y.
+ * Produces GRAVE ACCENT and TILDE in a
+ * US or UK Mac layout, REVERSE SOLIDUS
+ * (backslash) and VERTICAL LINE in a
+ * US or UK Windows layout, and
+ * LESS-THAN SIGN and GREATER-THAN SIGN
+ * in a Swiss German, German, or French
+ * layout. */
+ SDL_SCANCODE_APPLICATION = 101, /**< windows contextual menu, compose */
+ SDL_SCANCODE_POWER = 102, /**< The USB document says this is a status flag,
+ * not a physical key - but some Mac keyboards
+ * do have a power key. */
+ SDL_SCANCODE_KP_EQUALS = 103,
+ SDL_SCANCODE_F13 = 104,
+ SDL_SCANCODE_F14 = 105,
+ SDL_SCANCODE_F15 = 106,
+ SDL_SCANCODE_F16 = 107,
+ SDL_SCANCODE_F17 = 108,
+ SDL_SCANCODE_F18 = 109,
+ SDL_SCANCODE_F19 = 110,
+ SDL_SCANCODE_F20 = 111,
+ SDL_SCANCODE_F21 = 112,
+ SDL_SCANCODE_F22 = 113,
+ SDL_SCANCODE_F23 = 114,
+ SDL_SCANCODE_F24 = 115,
+ SDL_SCANCODE_EXECUTE = 116,
+ SDL_SCANCODE_HELP = 117,
+ SDL_SCANCODE_MENU = 118,
+ SDL_SCANCODE_SELECT = 119,
+ SDL_SCANCODE_STOP = 120,
+ SDL_SCANCODE_AGAIN = 121, /**< redo */
+ SDL_SCANCODE_UNDO = 122,
+ SDL_SCANCODE_CUT = 123,
+ SDL_SCANCODE_COPY = 124,
+ SDL_SCANCODE_PASTE = 125,
+ SDL_SCANCODE_FIND = 126,
+ SDL_SCANCODE_MUTE = 127,
+ SDL_SCANCODE_VOLUMEUP = 128,
+ SDL_SCANCODE_VOLUMEDOWN = 129,
+/* not sure whether there's a reason to enable these */
+/* SDL_SCANCODE_LOCKINGCAPSLOCK = 130, */
+/* SDL_SCANCODE_LOCKINGNUMLOCK = 131, */
+/* SDL_SCANCODE_LOCKINGSCROLLLOCK = 132, */
+ SDL_SCANCODE_KP_COMMA = 133,
+ SDL_SCANCODE_KP_EQUALSAS400 = 134,
+
+ SDL_SCANCODE_INTERNATIONAL1 = 135, /**< used on Asian keyboards, see
+ footnotes in USB doc */
+ SDL_SCANCODE_INTERNATIONAL2 = 136,
+ SDL_SCANCODE_INTERNATIONAL3 = 137, /**< Yen */
+ SDL_SCANCODE_INTERNATIONAL4 = 138,
+ SDL_SCANCODE_INTERNATIONAL5 = 139,
+ SDL_SCANCODE_INTERNATIONAL6 = 140,
+ SDL_SCANCODE_INTERNATIONAL7 = 141,
+ SDL_SCANCODE_INTERNATIONAL8 = 142,
+ SDL_SCANCODE_INTERNATIONAL9 = 143,
+ SDL_SCANCODE_LANG1 = 144, /**< Hangul/English toggle */
+ SDL_SCANCODE_LANG2 = 145, /**< Hanja conversion */
+ SDL_SCANCODE_LANG3 = 146, /**< Katakana */
+ SDL_SCANCODE_LANG4 = 147, /**< Hiragana */
+ SDL_SCANCODE_LANG5 = 148, /**< Zenkaku/Hankaku */
+ SDL_SCANCODE_LANG6 = 149, /**< reserved */
+ SDL_SCANCODE_LANG7 = 150, /**< reserved */
+ SDL_SCANCODE_LANG8 = 151, /**< reserved */
+ SDL_SCANCODE_LANG9 = 152, /**< reserved */
+
+ SDL_SCANCODE_ALTERASE = 153, /**< Erase-Eaze */
+ SDL_SCANCODE_SYSREQ = 154,
+ SDL_SCANCODE_CANCEL = 155,
+ SDL_SCANCODE_CLEAR = 156,
+ SDL_SCANCODE_PRIOR = 157,
+ SDL_SCANCODE_RETURN2 = 158,
+ SDL_SCANCODE_SEPARATOR = 159,
+ SDL_SCANCODE_OUT = 160,
+ SDL_SCANCODE_OPER = 161,
+ SDL_SCANCODE_CLEARAGAIN = 162,
+ SDL_SCANCODE_CRSEL = 163,
+ SDL_SCANCODE_EXSEL = 164,
+
+ SDL_SCANCODE_KP_00 = 176,
+ SDL_SCANCODE_KP_000 = 177,
+ SDL_SCANCODE_THOUSANDSSEPARATOR = 178,
+ SDL_SCANCODE_DECIMALSEPARATOR = 179,
+ SDL_SCANCODE_CURRENCYUNIT = 180,
+ SDL_SCANCODE_CURRENCYSUBUNIT = 181,
+ SDL_SCANCODE_KP_LEFTPAREN = 182,
+ SDL_SCANCODE_KP_RIGHTPAREN = 183,
+ SDL_SCANCODE_KP_LEFTBRACE = 184,
+ SDL_SCANCODE_KP_RIGHTBRACE = 185,
+ SDL_SCANCODE_KP_TAB = 186,
+ SDL_SCANCODE_KP_BACKSPACE = 187,
+ SDL_SCANCODE_KP_A = 188,
+ SDL_SCANCODE_KP_B = 189,
+ SDL_SCANCODE_KP_C = 190,
+ SDL_SCANCODE_KP_D = 191,
+ SDL_SCANCODE_KP_E = 192,
+ SDL_SCANCODE_KP_F = 193,
+ SDL_SCANCODE_KP_XOR = 194,
+ SDL_SCANCODE_KP_POWER = 195,
+ SDL_SCANCODE_KP_PERCENT = 196,
+ SDL_SCANCODE_KP_LESS = 197,
+ SDL_SCANCODE_KP_GREATER = 198,
+ SDL_SCANCODE_KP_AMPERSAND = 199,
+ SDL_SCANCODE_KP_DBLAMPERSAND = 200,
+ SDL_SCANCODE_KP_VERTICALBAR = 201,
+ SDL_SCANCODE_KP_DBLVERTICALBAR = 202,
+ SDL_SCANCODE_KP_COLON = 203,
+ SDL_SCANCODE_KP_HASH = 204,
+ SDL_SCANCODE_KP_SPACE = 205,
+ SDL_SCANCODE_KP_AT = 206,
+ SDL_SCANCODE_KP_EXCLAM = 207,
+ SDL_SCANCODE_KP_MEMSTORE = 208,
+ SDL_SCANCODE_KP_MEMRECALL = 209,
+ SDL_SCANCODE_KP_MEMCLEAR = 210,
+ SDL_SCANCODE_KP_MEMADD = 211,
+ SDL_SCANCODE_KP_MEMSUBTRACT = 212,
+ SDL_SCANCODE_KP_MEMMULTIPLY = 213,
+ SDL_SCANCODE_KP_MEMDIVIDE = 214,
+ SDL_SCANCODE_KP_PLUSMINUS = 215,
+ SDL_SCANCODE_KP_CLEAR = 216,
+ SDL_SCANCODE_KP_CLEARENTRY = 217,
+ SDL_SCANCODE_KP_BINARY = 218,
+ SDL_SCANCODE_KP_OCTAL = 219,
+ SDL_SCANCODE_KP_DECIMAL = 220,
+ SDL_SCANCODE_KP_HEXADECIMAL = 221,
+
+ SDL_SCANCODE_LCTRL = 224,
+ SDL_SCANCODE_LSHIFT = 225,
+ SDL_SCANCODE_LALT = 226, /**< alt, option */
+ SDL_SCANCODE_LGUI = 227, /**< windows, command (apple), meta */
+ SDL_SCANCODE_RCTRL = 228,
+ SDL_SCANCODE_RSHIFT = 229,
+ SDL_SCANCODE_RALT = 230, /**< alt gr, option */
+ SDL_SCANCODE_RGUI = 231, /**< windows, command (apple), meta */
+
+ SDL_SCANCODE_MODE = 257, /**< I'm not sure if this is really not covered
+ * by any of the above, but since there's a
+ * special KMOD_MODE for it I'm adding it here
+ */
+
+ /* @} *//* Usage page 0x07 */
+
+ /**
+ * \name Usage page 0x0C
+ *
+ * These values are mapped from usage page 0x0C (USB consumer page).
+ */
+ /* @{ */
+
+ SDL_SCANCODE_AUDIONEXT = 258,
+ SDL_SCANCODE_AUDIOPREV = 259,
+ SDL_SCANCODE_AUDIOSTOP = 260,
+ SDL_SCANCODE_AUDIOPLAY = 261,
+ SDL_SCANCODE_AUDIOMUTE = 262,
+ SDL_SCANCODE_MEDIASELECT = 263,
+ SDL_SCANCODE_WWW = 264,
+ SDL_SCANCODE_MAIL = 265,
+ SDL_SCANCODE_CALCULATOR = 266,
+ SDL_SCANCODE_COMPUTER = 267,
+ SDL_SCANCODE_AC_SEARCH = 268,
+ SDL_SCANCODE_AC_HOME = 269,
+ SDL_SCANCODE_AC_BACK = 270,
+ SDL_SCANCODE_AC_FORWARD = 271,
+ SDL_SCANCODE_AC_STOP = 272,
+ SDL_SCANCODE_AC_REFRESH = 273,
+ SDL_SCANCODE_AC_BOOKMARKS = 274,
+
+ /* @} *//* Usage page 0x0C */
+
+ /**
+ * \name Walther keys
+ *
+ * These are values that Christian Walther added (for mac keyboard?).
+ */
+ /* @{ */
+
+ SDL_SCANCODE_BRIGHTNESSDOWN = 275,
+ SDL_SCANCODE_BRIGHTNESSUP = 276,
+ SDL_SCANCODE_DISPLAYSWITCH = 277, /**< display mirroring/dual display
+ switch, video mode switch */
+ SDL_SCANCODE_KBDILLUMTOGGLE = 278,
+ SDL_SCANCODE_KBDILLUMDOWN = 279,
+ SDL_SCANCODE_KBDILLUMUP = 280,
+ SDL_SCANCODE_EJECT = 281,
+ SDL_SCANCODE_SLEEP = 282,
+
+ SDL_SCANCODE_APP1 = 283,
+ SDL_SCANCODE_APP2 = 284,
+
+ /* @} *//* Walther keys */
+
+ /**
+ * \name Usage page 0x0C (additional media keys)
+ *
+ * These values are mapped from usage page 0x0C (USB consumer page).
+ */
+ /* @{ */
+
+ SDL_SCANCODE_AUDIOREWIND = 285,
+ SDL_SCANCODE_AUDIOFASTFORWARD = 286,
+
+ /* @} *//* Usage page 0x0C (additional media keys) */
+
+ /* Add any other keys here. */
+
+ SDL_NUM_SCANCODES = 512 /**< not a key, just marks the number of scancodes
+ for array bounds */
+} SDL_Scancode;
+
+#endif /* SDL_scancode_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_shape.h b/src/3rdparty/SDL2/include/SDL2/SDL_shape.h
new file mode 100644
index 0000000..40a6baa
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_shape.h
@@ -0,0 +1,144 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_shape_h_
+#define SDL_shape_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_pixels.h"
+#include "SDL_rect.h"
+#include "SDL_surface.h"
+#include "SDL_video.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** \file SDL_shape.h
+ *
+ * Header file for the shaped window API.
+ */
+
+#define SDL_NONSHAPEABLE_WINDOW -1
+#define SDL_INVALID_SHAPE_ARGUMENT -2
+#define SDL_WINDOW_LACKS_SHAPE -3
+
+/**
+ * \brief Create a window that can be shaped with the specified position, dimensions, and flags.
+ *
+ * \param title The title of the window, in UTF-8 encoding.
+ * \param x The x position of the window, ::SDL_WINDOWPOS_CENTERED, or
+ * ::SDL_WINDOWPOS_UNDEFINED.
+ * \param y The y position of the window, ::SDL_WINDOWPOS_CENTERED, or
+ * ::SDL_WINDOWPOS_UNDEFINED.
+ * \param w The width of the window.
+ * \param h The height of the window.
+ * \param flags The flags for the window, a mask of SDL_WINDOW_BORDERLESS with any of the following:
+ * ::SDL_WINDOW_OPENGL, ::SDL_WINDOW_INPUT_GRABBED,
+ * ::SDL_WINDOW_HIDDEN, ::SDL_WINDOW_RESIZABLE,
+ * ::SDL_WINDOW_MAXIMIZED, ::SDL_WINDOW_MINIMIZED,
+ * ::SDL_WINDOW_BORDERLESS is always set, and ::SDL_WINDOW_FULLSCREEN is always unset.
+ *
+ * \return The window created, or NULL if window creation failed.
+ *
+ * \sa SDL_DestroyWindow()
+ */
+extern DECLSPEC SDL_Window * SDLCALL SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags);
+
+/**
+ * \brief Return whether the given window is a shaped window.
+ *
+ * \param window The window to query for being shaped.
+ *
+ * \return SDL_TRUE if the window is a window that can be shaped, SDL_FALSE if the window is unshaped or NULL.
+ *
+ * \sa SDL_CreateShapedWindow
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_IsShapedWindow(const SDL_Window *window);
+
+/** \brief An enum denoting the specific type of contents present in an SDL_WindowShapeParams union. */
+typedef enum {
+ /** \brief The default mode, a binarized alpha cutoff of 1. */
+ ShapeModeDefault,
+ /** \brief A binarized alpha cutoff with a given integer value. */
+ ShapeModeBinarizeAlpha,
+ /** \brief A binarized alpha cutoff with a given integer value, but with the opposite comparison. */
+ ShapeModeReverseBinarizeAlpha,
+ /** \brief A color key is applied. */
+ ShapeModeColorKey
+} WindowShapeMode;
+
+#define SDL_SHAPEMODEALPHA(mode) (mode == ShapeModeDefault || mode == ShapeModeBinarizeAlpha || mode == ShapeModeReverseBinarizeAlpha)
+
+/** \brief A union containing parameters for shaped windows. */
+typedef union {
+ /** \brief A cutoff alpha value for binarization of the window shape's alpha channel. */
+ Uint8 binarizationCutoff;
+ SDL_Color colorKey;
+} SDL_WindowShapeParams;
+
+/** \brief A struct that tags the SDL_WindowShapeParams union with an enum describing the type of its contents. */
+typedef struct SDL_WindowShapeMode {
+ /** \brief The mode of these window-shape parameters. */
+ WindowShapeMode mode;
+ /** \brief Window-shape parameters. */
+ SDL_WindowShapeParams parameters;
+} SDL_WindowShapeMode;
+
+/**
+ * \brief Set the shape and parameters of a shaped window.
+ *
+ * \param window The shaped window whose parameters should be set.
+ * \param shape A surface encoding the desired shape for the window.
+ * \param shape_mode The parameters to set for the shaped window.
+ *
+ * \return 0 on success, SDL_INVALID_SHAPE_ARGUMENT on an invalid shape argument, or SDL_NONSHAPEABLE_WINDOW
+ * if the SDL_Window given does not reference a valid shaped window.
+ *
+ * \sa SDL_WindowShapeMode
+ * \sa SDL_GetShapedWindowMode.
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
+
+/**
+ * \brief Get the shape parameters of a shaped window.
+ *
+ * \param window The shaped window whose parameters should be retrieved.
+ * \param shape_mode An empty shape-mode structure to fill, or NULL to check whether the window has a shape.
+ *
+ * \return 0 if the window has a shape and, provided shape_mode was not NULL, shape_mode has been filled with the mode
+ * data, SDL_NONSHAPEABLE_WINDOW if the SDL_Window given is not a shaped window, or SDL_WINDOW_LACKS_SHAPE if
+ * the SDL_Window given is a shapeable window currently lacking a shape.
+ *
+ * \sa SDL_WindowShapeMode
+ * \sa SDL_SetWindowShape
+ */
+extern DECLSPEC int SDLCALL SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shape_mode);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_shape_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_stdinc.h b/src/3rdparty/SDL2/include/SDL2/SDL_stdinc.h
new file mode 100644
index 0000000..111a064
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_stdinc.h
@@ -0,0 +1,605 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_stdinc.h
+ *
+ * This is a general header that includes C language support.
+ */
+
+#ifndef SDL_stdinc_h_
+#define SDL_stdinc_h_
+
+#include "SDL_config.h"
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_STDIO_H
+#include <stdio.h>
+#endif
+#if defined(STDC_HEADERS)
+# include <stdlib.h>
+# include <stddef.h>
+# include <stdarg.h>
+#else
+# if defined(HAVE_STDLIB_H)
+# include <stdlib.h>
+# elif defined(HAVE_MALLOC_H)
+# include <malloc.h>
+# endif
+# if defined(HAVE_STDDEF_H)
+# include <stddef.h>
+# endif
+# if defined(HAVE_STDARG_H)
+# include <stdarg.h>
+# endif
+#endif
+#ifdef HAVE_STRING_H
+# if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
+# include <memory.h>
+# endif
+# include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#ifdef HAVE_WCHAR_H
+# include <wchar.h>
+#endif
+#if defined(HAVE_INTTYPES_H)
+# include <inttypes.h>
+#elif defined(HAVE_STDINT_H)
+# include <stdint.h>
+#endif
+#ifdef HAVE_CTYPE_H
+# include <ctype.h>
+#endif
+#ifdef HAVE_MATH_H
+# if defined(__WINRT__)
+/* Defining _USE_MATH_DEFINES is required to get M_PI to be defined on
+ WinRT. See http://msdn.microsoft.com/en-us/library/4hwaceh6.aspx
+ for more information.
+*/
+# define _USE_MATH_DEFINES
+# endif
+# include <math.h>
+#endif
+#ifdef HAVE_FLOAT_H
+# include <float.h>
+#endif
+
+/**
+ * The number of elements in an array.
+ */
+#define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
+#define SDL_TABLESIZE(table) SDL_arraysize(table)
+
+/**
+ * Macro useful for building other macros with strings in them
+ *
+ * e.g. #define LOG_ERROR(X) OutputDebugString(SDL_STRINGIFY_ARG(__FUNCTION__) ": " X "\n")
+ */
+#define SDL_STRINGIFY_ARG(arg) #arg
+
+/**
+ * \name Cast operators
+ *
+ * Use proper C++ casts when compiled as C++ to be compatible with the option
+ * -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
+ */
+/* @{ */
+#ifdef __cplusplus
+#define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
+#define SDL_static_cast(type, expression) static_cast<type>(expression)
+#define SDL_const_cast(type, expression) const_cast<type>(expression)
+#else
+#define SDL_reinterpret_cast(type, expression) ((type)(expression))
+#define SDL_static_cast(type, expression) ((type)(expression))
+#define SDL_const_cast(type, expression) ((type)(expression))
+#endif
+/* @} *//* Cast operators */
+
+/* Define a four character code as a Uint32 */
+#define SDL_FOURCC(A, B, C, D) \
+ ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
+ (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
+ (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
+ (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
+
+/**
+ * \name Basic data types
+ */
+/* @{ */
+
+#ifdef __CC_ARM
+/* ARM's compiler throws warnings if we use an enum: like "SDL_bool x = a < b;" */
+#define SDL_FALSE 0
+#define SDL_TRUE 1
+typedef int SDL_bool;
+#else
+typedef enum
+{
+ SDL_FALSE = 0,
+ SDL_TRUE = 1
+} SDL_bool;
+#endif
+
+/**
+ * \brief A signed 8-bit integer type.
+ */
+#define SDL_MAX_SINT8 ((Sint8)0x7F) /* 127 */
+#define SDL_MIN_SINT8 ((Sint8)(~0x7F)) /* -128 */
+typedef int8_t Sint8;
+/**
+ * \brief An unsigned 8-bit integer type.
+ */
+#define SDL_MAX_UINT8 ((Uint8)0xFF) /* 255 */
+#define SDL_MIN_UINT8 ((Uint8)0x00) /* 0 */
+typedef uint8_t Uint8;
+/**
+ * \brief A signed 16-bit integer type.
+ */
+#define SDL_MAX_SINT16 ((Sint16)0x7FFF) /* 32767 */
+#define SDL_MIN_SINT16 ((Sint16)(~0x7FFF)) /* -32768 */
+typedef int16_t Sint16;
+/**
+ * \brief An unsigned 16-bit integer type.
+ */
+#define SDL_MAX_UINT16 ((Uint16)0xFFFF) /* 65535 */
+#define SDL_MIN_UINT16 ((Uint16)0x0000) /* 0 */
+typedef uint16_t Uint16;
+/**
+ * \brief A signed 32-bit integer type.
+ */
+#define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */
+#define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
+typedef int32_t Sint32;
+/**
+ * \brief An unsigned 32-bit integer type.
+ */
+#define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu) /* 4294967295 */
+#define SDL_MIN_UINT32 ((Uint32)0x00000000) /* 0 */
+typedef uint32_t Uint32;
+
+/**
+ * \brief A signed 64-bit integer type.
+ */
+#define SDL_MAX_SINT64 ((Sint64)0x7FFFFFFFFFFFFFFFll) /* 9223372036854775807 */
+#define SDL_MIN_SINT64 ((Sint64)(~0x7FFFFFFFFFFFFFFFll)) /* -9223372036854775808 */
+typedef int64_t Sint64;
+/**
+ * \brief An unsigned 64-bit integer type.
+ */
+#define SDL_MAX_UINT64 ((Uint64)0xFFFFFFFFFFFFFFFFull) /* 18446744073709551615 */
+#define SDL_MIN_UINT64 ((Uint64)(0x0000000000000000ull)) /* 0 */
+typedef uint64_t Uint64;
+
+/* @} *//* Basic data types */
+
+/* Make sure we have macros for printing 64 bit values.
+ * <stdint.h> should define these but this is not true all platforms.
+ * (for example win32) */
+#ifndef SDL_PRIs64
+#ifdef PRIs64
+#define SDL_PRIs64 PRIs64
+#elif defined(__WIN32__)
+#define SDL_PRIs64 "I64d"
+#elif defined(__LINUX__) && defined(__LP64__)
+#define SDL_PRIs64 "ld"
+#else
+#define SDL_PRIs64 "lld"
+#endif
+#endif
+#ifndef SDL_PRIu64
+#ifdef PRIu64
+#define SDL_PRIu64 PRIu64
+#elif defined(__WIN32__)
+#define SDL_PRIu64 "I64u"
+#elif defined(__LINUX__) && defined(__LP64__)
+#define SDL_PRIu64 "lu"
+#else
+#define SDL_PRIu64 "llu"
+#endif
+#endif
+#ifndef SDL_PRIx64
+#ifdef PRIx64
+#define SDL_PRIx64 PRIx64
+#elif defined(__WIN32__)
+#define SDL_PRIx64 "I64x"
+#elif defined(__LINUX__) && defined(__LP64__)
+#define SDL_PRIx64 "lx"
+#else
+#define SDL_PRIx64 "llx"
+#endif
+#endif
+#ifndef SDL_PRIX64
+#ifdef PRIX64
+#define SDL_PRIX64 PRIX64
+#elif defined(__WIN32__)
+#define SDL_PRIX64 "I64X"
+#elif defined(__LINUX__) && defined(__LP64__)
+#define SDL_PRIX64 "lX"
+#else
+#define SDL_PRIX64 "llX"
+#endif
+#endif
+
+/* Annotations to help code analysis tools */
+#ifdef SDL_DISABLE_ANALYZE_MACROS
+#define SDL_IN_BYTECAP(x)
+#define SDL_INOUT_Z_CAP(x)
+#define SDL_OUT_Z_CAP(x)
+#define SDL_OUT_CAP(x)
+#define SDL_OUT_BYTECAP(x)
+#define SDL_OUT_Z_BYTECAP(x)
+#define SDL_PRINTF_FORMAT_STRING
+#define SDL_SCANF_FORMAT_STRING
+#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
+#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
+#else
+#if defined(_MSC_VER) && (_MSC_VER >= 1600) /* VS 2010 and above */
+#include <sal.h>
+
+#define SDL_IN_BYTECAP(x) _In_bytecount_(x)
+#define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
+#define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
+#define SDL_OUT_CAP(x) _Out_cap_(x)
+#define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
+#define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
+
+#define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
+#define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
+#else
+#define SDL_IN_BYTECAP(x)
+#define SDL_INOUT_Z_CAP(x)
+#define SDL_OUT_Z_CAP(x)
+#define SDL_OUT_CAP(x)
+#define SDL_OUT_BYTECAP(x)
+#define SDL_OUT_Z_BYTECAP(x)
+#define SDL_PRINTF_FORMAT_STRING
+#define SDL_SCANF_FORMAT_STRING
+#endif
+#if defined(__GNUC__)
+#define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
+#define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
+#else
+#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
+#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
+#endif
+#endif /* SDL_DISABLE_ANALYZE_MACROS */
+
+#define SDL_COMPILE_TIME_ASSERT(name, x) \
+ typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
+/** \cond */
+#ifndef DOXYGEN_SHOULD_IGNORE_THIS
+SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
+SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
+SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
+SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
+SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
+SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
+SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
+SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
+#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
+/** \endcond */
+
+/* Check to make sure enums are the size of ints, for structure packing.
+ For both Watcom C/C++ and Borland C/C++ the compiler option that makes
+ enums having the size of an int must be enabled.
+ This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
+*/
+
+/** \cond */
+#ifndef DOXYGEN_SHOULD_IGNORE_THIS
+#if !defined(__ANDROID__)
+ /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
+typedef enum
+{
+ DUMMY_ENUM_VALUE
+} SDL_DUMMY_ENUM;
+
+SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
+#endif
+#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
+/** \endcond */
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(HAVE_ALLOCA) && !defined(alloca)
+# if defined(HAVE_ALLOCA_H)
+# include <alloca.h>
+# elif defined(__GNUC__)
+# define alloca __builtin_alloca
+# elif defined(_MSC_VER)
+# include <malloc.h>
+# define alloca _alloca
+# elif defined(__WATCOMC__)
+# include <malloc.h>
+# elif defined(__BORLANDC__)
+# include <malloc.h>
+# elif defined(__DMC__)
+# include <stdlib.h>
+# elif defined(__AIX__)
+#pragma alloca
+# elif defined(__MRC__)
+void *alloca(unsigned);
+# else
+char *alloca();
+# endif
+#endif
+#ifdef HAVE_ALLOCA
+#define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
+#define SDL_stack_free(data)
+#else
+#define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
+#define SDL_stack_free(data) SDL_free(data)
+#endif
+
+extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
+extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
+extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
+extern DECLSPEC void SDLCALL SDL_free(void *mem);
+
+typedef void *(SDLCALL *SDL_malloc_func)(size_t size);
+typedef void *(SDLCALL *SDL_calloc_func)(size_t nmemb, size_t size);
+typedef void *(SDLCALL *SDL_realloc_func)(void *mem, size_t size);
+typedef void (SDLCALL *SDL_free_func)(void *mem);
+
+/**
+ * \brief Get the current set of SDL memory functions
+ */
+extern DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
+ SDL_calloc_func *calloc_func,
+ SDL_realloc_func *realloc_func,
+ SDL_free_func *free_func);
+
+/**
+ * \brief Replace SDL's memory allocation functions with a custom set
+ *
+ * \note If you are replacing SDL's memory functions, you should call
+ * SDL_GetNumAllocations() and be very careful if it returns non-zero.
+ * That means that your free function will be called with memory
+ * allocated by the previous memory allocation functions.
+ */
+extern DECLSPEC int SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
+ SDL_calloc_func calloc_func,
+ SDL_realloc_func realloc_func,
+ SDL_free_func free_func);
+
+/**
+ * \brief Get the number of outstanding (unfreed) allocations
+ */
+extern DECLSPEC int SDLCALL SDL_GetNumAllocations(void);
+
+extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
+extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
+
+extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));
+
+extern DECLSPEC int SDLCALL SDL_abs(int x);
+
+/* !!! FIXME: these have side effects. You probably shouldn't use them. */
+/* !!! FIXME: Maybe we do forceinline functions of SDL_mini, SDL_minf, etc? */
+#define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
+#define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
+
+extern DECLSPEC int SDLCALL SDL_isdigit(int x);
+extern DECLSPEC int SDLCALL SDL_isspace(int x);
+extern DECLSPEC int SDLCALL SDL_toupper(int x);
+extern DECLSPEC int SDLCALL SDL_tolower(int x);
+
+extern DECLSPEC void *SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
+
+#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
+#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
+
+/* Note that memset() is a byte assignment and this is a 32-bit assignment, so they're not directly equivalent. */
+SDL_FORCE_INLINE void SDL_memset4(void *dst, Uint32 val, size_t dwords)
+{
+#if defined(__GNUC__) && defined(i386)
+ int u0, u1, u2;
+ __asm__ __volatile__ (
+ "cld \n\t"
+ "rep ; stosl \n\t"
+ : "=&D" (u0), "=&a" (u1), "=&c" (u2)
+ : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, dwords))
+ : "memory"
+ );
+#else
+ size_t _n = (dwords + 3) / 4;
+ Uint32 *_p = SDL_static_cast(Uint32 *, dst);
+ Uint32 _val = (val);
+ if (dwords == 0)
+ return;
+ switch (dwords % 4)
+ {
+ case 0: do { *_p++ = _val; /* fallthrough */
+ case 3: *_p++ = _val; /* fallthrough */
+ case 2: *_p++ = _val; /* fallthrough */
+ case 1: *_p++ = _val; /* fallthrough */
+ } while ( --_n );
+ }
+#endif
+}
+
+
+extern DECLSPEC void *SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
+
+extern DECLSPEC void *SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
+extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
+
+extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
+extern DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
+extern DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
+extern DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
+
+extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
+extern DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
+extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
+extern DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
+extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
+extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
+extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
+extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);
+extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
+extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
+extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
+extern DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
+
+extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
+extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
+extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
+extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
+extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
+extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
+
+extern DECLSPEC int SDLCALL SDL_atoi(const char *str);
+extern DECLSPEC double SDLCALL SDL_atof(const char *str);
+extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
+extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
+extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
+extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
+extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
+
+extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
+extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
+extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
+extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
+
+extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
+extern DECLSPEC int SDLCALL SDL_vsscanf(const char *text, const char *fmt, va_list ap);
+extern DECLSPEC int SDLCALL SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ... ) SDL_PRINTF_VARARG_FUNC(3);
+extern DECLSPEC int SDLCALL SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap);
+
+#ifndef HAVE_M_PI
+#ifndef M_PI
+#define M_PI 3.14159265358979323846264338327950288 /**< pi */
+#endif
+#endif
+
+extern DECLSPEC double SDLCALL SDL_acos(double x);
+extern DECLSPEC float SDLCALL SDL_acosf(float x);
+extern DECLSPEC double SDLCALL SDL_asin(double x);
+extern DECLSPEC float SDLCALL SDL_asinf(float x);
+extern DECLSPEC double SDLCALL SDL_atan(double x);
+extern DECLSPEC float SDLCALL SDL_atanf(float x);
+extern DECLSPEC double SDLCALL SDL_atan2(double x, double y);
+extern DECLSPEC float SDLCALL SDL_atan2f(float x, float y);
+extern DECLSPEC double SDLCALL SDL_ceil(double x);
+extern DECLSPEC float SDLCALL SDL_ceilf(float x);
+extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
+extern DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
+extern DECLSPEC double SDLCALL SDL_cos(double x);
+extern DECLSPEC float SDLCALL SDL_cosf(float x);
+extern DECLSPEC double SDLCALL SDL_fabs(double x);
+extern DECLSPEC float SDLCALL SDL_fabsf(float x);
+extern DECLSPEC double SDLCALL SDL_floor(double x);
+extern DECLSPEC float SDLCALL SDL_floorf(float x);
+extern DECLSPEC double SDLCALL SDL_fmod(double x, double y);
+extern DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
+extern DECLSPEC double SDLCALL SDL_log(double x);
+extern DECLSPEC float SDLCALL SDL_logf(float x);
+extern DECLSPEC double SDLCALL SDL_log10(double x);
+extern DECLSPEC float SDLCALL SDL_log10f(float x);
+extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
+extern DECLSPEC float SDLCALL SDL_powf(float x, float y);
+extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
+extern DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
+extern DECLSPEC double SDLCALL SDL_sin(double x);
+extern DECLSPEC float SDLCALL SDL_sinf(float x);
+extern DECLSPEC double SDLCALL SDL_sqrt(double x);
+extern DECLSPEC float SDLCALL SDL_sqrtf(float x);
+extern DECLSPEC double SDLCALL SDL_tan(double x);
+extern DECLSPEC float SDLCALL SDL_tanf(float x);
+
+/* The SDL implementation of iconv() returns these error codes */
+#define SDL_ICONV_ERROR (size_t)-1
+#define SDL_ICONV_E2BIG (size_t)-2
+#define SDL_ICONV_EILSEQ (size_t)-3
+#define SDL_ICONV_EINVAL (size_t)-4
+
+/* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
+typedef struct _SDL_iconv_t *SDL_iconv_t;
+extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
+ const char *fromcode);
+extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
+extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
+ size_t * inbytesleft, char **outbuf,
+ size_t * outbytesleft);
+/**
+ * This function converts a string between encodings in one pass, returning a
+ * string that must be freed with SDL_free() or NULL on error.
+ */
+extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
+ const char *fromcode,
+ const char *inbuf,
+ size_t inbytesleft);
+#define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
+#define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
+#define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
+
+/* force builds using Clang's static analysis tools to use literal C runtime
+ here, since there are possibly tests that are ineffective otherwise. */
+#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
+#define SDL_malloc malloc
+#define SDL_calloc calloc
+#define SDL_realloc realloc
+#define SDL_free free
+#define SDL_memset memset
+#define SDL_memcpy memcpy
+#define SDL_memmove memmove
+#define SDL_memcmp memcmp
+#define SDL_strlen strlen
+#define SDL_strlcpy strlcpy
+#define SDL_strlcat strlcat
+#define SDL_strdup strdup
+#define SDL_strchr strchr
+#define SDL_strrchr strrchr
+#define SDL_strstr strstr
+#define SDL_strcmp strcmp
+#define SDL_strncmp strncmp
+#define SDL_strcasecmp strcasecmp
+#define SDL_strncasecmp strncasecmp
+#define SDL_sscanf sscanf
+#define SDL_vsscanf vsscanf
+#define SDL_snprintf snprintf
+#define SDL_vsnprintf vsnprintf
+#endif
+
+SDL_FORCE_INLINE void *SDL_memcpy4(SDL_OUT_BYTECAP(dwords*4) void *dst, SDL_IN_BYTECAP(dwords*4) const void *src, size_t dwords)
+{
+ return SDL_memcpy(dst, src, dwords * 4);
+}
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_stdinc_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_surface.h b/src/3rdparty/SDL2/include/SDL2/SDL_surface.h
new file mode 100644
index 0000000..45e5366
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_surface.h
@@ -0,0 +1,546 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_surface.h
+ *
+ * Header file for ::SDL_Surface definition and management functions.
+ */
+
+#ifndef SDL_surface_h_
+#define SDL_surface_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_pixels.h"
+#include "SDL_rect.h"
+#include "SDL_blendmode.h"
+#include "SDL_rwops.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \name Surface flags
+ *
+ * These are the currently supported flags for the ::SDL_Surface.
+ *
+ * \internal
+ * Used internally (read-only).
+ */
+/* @{ */
+#define SDL_SWSURFACE 0 /**< Just here for compatibility */
+#define SDL_PREALLOC 0x00000001 /**< Surface uses preallocated memory */
+#define SDL_RLEACCEL 0x00000002 /**< Surface is RLE encoded */
+#define SDL_DONTFREE 0x00000004 /**< Surface is referenced internally */
+/* @} *//* Surface flags */
+
+/**
+ * Evaluates to true if the surface needs to be locked before access.
+ */
+#define SDL_MUSTLOCK(S) (((S)->flags & SDL_RLEACCEL) != 0)
+
+/**
+ * \brief A collection of pixels used in software blitting.
+ *
+ * \note This structure should be treated as read-only, except for \c pixels,
+ * which, if not NULL, contains the raw pixel data for the surface.
+ */
+typedef struct SDL_Surface
+{
+ Uint32 flags; /**< Read-only */
+ SDL_PixelFormat *format; /**< Read-only */
+ int w, h; /**< Read-only */
+ int pitch; /**< Read-only */
+ void *pixels; /**< Read-write */
+
+ /** Application data associated with the surface */
+ void *userdata; /**< Read-write */
+
+ /** information needed for surfaces requiring locks */
+ int locked; /**< Read-only */
+ void *lock_data; /**< Read-only */
+
+ /** clipping information */
+ SDL_Rect clip_rect; /**< Read-only */
+
+ /** info for fast blit mapping to other surfaces */
+ struct SDL_BlitMap *map; /**< Private */
+
+ /** Reference count -- used when freeing surface */
+ int refcount; /**< Read-mostly */
+} SDL_Surface;
+
+/**
+ * \brief The type of function used for surface blitting functions.
+ */
+typedef int (SDLCALL *SDL_blit) (struct SDL_Surface * src, SDL_Rect * srcrect,
+ struct SDL_Surface * dst, SDL_Rect * dstrect);
+
+/**
+ * \brief The formula used for converting between YUV and RGB
+ */
+typedef enum
+{
+ SDL_YUV_CONVERSION_JPEG, /**< Full range JPEG */
+ SDL_YUV_CONVERSION_BT601, /**< BT.601 (the default) */
+ SDL_YUV_CONVERSION_BT709, /**< BT.709 */
+ SDL_YUV_CONVERSION_AUTOMATIC /**< BT.601 for SD content, BT.709 for HD content */
+} SDL_YUV_CONVERSION_MODE;
+
+/**
+ * Allocate and free an RGB surface.
+ *
+ * If the depth is 4 or 8 bits, an empty palette is allocated for the surface.
+ * If the depth is greater than 8 bits, the pixel format is set using the
+ * flags '[RGB]mask'.
+ *
+ * If the function runs out of memory, it will return NULL.
+ *
+ * \param flags The \c flags are obsolete and should be set to 0.
+ * \param width The width in pixels of the surface to create.
+ * \param height The height in pixels of the surface to create.
+ * \param depth The depth in bits of the surface to create.
+ * \param Rmask The red mask of the surface to create.
+ * \param Gmask The green mask of the surface to create.
+ * \param Bmask The blue mask of the surface to create.
+ * \param Amask The alpha mask of the surface to create.
+ */
+extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface
+ (Uint32 flags, int width, int height, int depth,
+ Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
+
+/* !!! FIXME for 2.1: why does this ask for depth? Format provides that. */
+extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormat
+ (Uint32 flags, int width, int height, int depth, Uint32 format);
+
+extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels,
+ int width,
+ int height,
+ int depth,
+ int pitch,
+ Uint32 Rmask,
+ Uint32 Gmask,
+ Uint32 Bmask,
+ Uint32 Amask);
+extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormatFrom
+ (void *pixels, int width, int height, int depth, int pitch, Uint32 format);
+extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface * surface);
+
+/**
+ * \brief Set the palette used by a surface.
+ *
+ * \return 0, or -1 if the surface format doesn't use a palette.
+ *
+ * \note A single palette can be shared with many surfaces.
+ */
+extern DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface * surface,
+ SDL_Palette * palette);
+
+/**
+ * \brief Sets up a surface for directly accessing the pixels.
+ *
+ * Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write
+ * to and read from \c surface->pixels, using the pixel format stored in
+ * \c surface->format. Once you are done accessing the surface, you should
+ * use SDL_UnlockSurface() to release it.
+ *
+ * Not all surfaces require locking. If SDL_MUSTLOCK(surface) evaluates
+ * to 0, then you can read and write to the surface at any time, and the
+ * pixel format of the surface will not change.
+ *
+ * No operating system or library calls should be made between lock/unlock
+ * pairs, as critical system locks may be held during this time.
+ *
+ * SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked.
+ *
+ * \sa SDL_UnlockSurface()
+ */
+extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface * surface);
+/** \sa SDL_LockSurface() */
+extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface * surface);
+
+/**
+ * Load a surface from a seekable SDL data stream (memory or file).
+ *
+ * If \c freesrc is non-zero, the stream will be closed after being read.
+ *
+ * The new surface should be freed with SDL_FreeSurface().
+ *
+ * \return the new surface, or NULL if there was an error.
+ */
+extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops * src,
+ int freesrc);
+
+/**
+ * Load a surface from a file.
+ *
+ * Convenience macro.
+ */
+#define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
+
+/**
+ * Save a surface to a seekable SDL data stream (memory or file).
+ *
+ * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
+ * BMP directly. Other RGB formats with 8-bit or higher get converted to a
+ * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
+ * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
+ * not supported.
+ *
+ * If \c freedst is non-zero, the stream will be closed after being written.
+ *
+ * \return 0 if successful or -1 if there was an error.
+ */
+extern DECLSPEC int SDLCALL SDL_SaveBMP_RW
+ (SDL_Surface * surface, SDL_RWops * dst, int freedst);
+
+/**
+ * Save a surface to a file.
+ *
+ * Convenience macro.
+ */
+#define SDL_SaveBMP(surface, file) \
+ SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
+
+/**
+ * \brief Sets the RLE acceleration hint for a surface.
+ *
+ * \return 0 on success, or -1 if the surface is not valid
+ *
+ * \note If RLE is enabled, colorkey and alpha blending blits are much faster,
+ * but the surface must be locked before directly accessing the pixels.
+ */
+extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface * surface,
+ int flag);
+
+/**
+ * \brief Sets the color key (transparent pixel) in a blittable surface.
+ *
+ * \param surface The surface to update
+ * \param flag Non-zero to enable colorkey and 0 to disable colorkey
+ * \param key The transparent pixel in the native surface format
+ *
+ * \return 0 on success, or -1 if the surface is not valid
+ *
+ * You can pass SDL_RLEACCEL to enable RLE accelerated blits.
+ */
+extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface * surface,
+ int flag, Uint32 key);
+
+/**
+ * \brief Gets the color key (transparent pixel) in a blittable surface.
+ *
+ * \param surface The surface to update
+ * \param key A pointer filled in with the transparent pixel in the native
+ * surface format
+ *
+ * \return 0 on success, or -1 if the surface is not valid or colorkey is not
+ * enabled.
+ */
+extern DECLSPEC int SDLCALL SDL_GetColorKey(SDL_Surface * surface,
+ Uint32 * key);
+
+/**
+ * \brief Set an additional color value used in blit operations.
+ *
+ * \param surface The surface to update.
+ * \param r The red color value multiplied into blit operations.
+ * \param g The green color value multiplied into blit operations.
+ * \param b The blue color value multiplied into blit operations.
+ *
+ * \return 0 on success, or -1 if the surface is not valid.
+ *
+ * \sa SDL_GetSurfaceColorMod()
+ */
+extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface * surface,
+ Uint8 r, Uint8 g, Uint8 b);
+
+
+/**
+ * \brief Get the additional color value used in blit operations.
+ *
+ * \param surface The surface to query.
+ * \param r A pointer filled in with the current red color value.
+ * \param g A pointer filled in with the current green color value.
+ * \param b A pointer filled in with the current blue color value.
+ *
+ * \return 0 on success, or -1 if the surface is not valid.
+ *
+ * \sa SDL_SetSurfaceColorMod()
+ */
+extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface * surface,
+ Uint8 * r, Uint8 * g,
+ Uint8 * b);
+
+/**
+ * \brief Set an additional alpha value used in blit operations.
+ *
+ * \param surface The surface to update.
+ * \param alpha The alpha value multiplied into blit operations.
+ *
+ * \return 0 on success, or -1 if the surface is not valid.
+ *
+ * \sa SDL_GetSurfaceAlphaMod()
+ */
+extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface * surface,
+ Uint8 alpha);
+
+/**
+ * \brief Get the additional alpha value used in blit operations.
+ *
+ * \param surface The surface to query.
+ * \param alpha A pointer filled in with the current alpha value.
+ *
+ * \return 0 on success, or -1 if the surface is not valid.
+ *
+ * \sa SDL_SetSurfaceAlphaMod()
+ */
+extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface * surface,
+ Uint8 * alpha);
+
+/**
+ * \brief Set the blend mode used for blit operations.
+ *
+ * \param surface The surface to update.
+ * \param blendMode ::SDL_BlendMode to use for blit blending.
+ *
+ * \return 0 on success, or -1 if the parameters are not valid.
+ *
+ * \sa SDL_GetSurfaceBlendMode()
+ */
+extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface * surface,
+ SDL_BlendMode blendMode);
+
+/**
+ * \brief Get the blend mode used for blit operations.
+ *
+ * \param surface The surface to query.
+ * \param blendMode A pointer filled in with the current blend mode.
+ *
+ * \return 0 on success, or -1 if the surface is not valid.
+ *
+ * \sa SDL_SetSurfaceBlendMode()
+ */
+extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface * surface,
+ SDL_BlendMode *blendMode);
+
+/**
+ * Sets the clipping rectangle for the destination surface in a blit.
+ *
+ * If the clip rectangle is NULL, clipping will be disabled.
+ *
+ * If the clip rectangle doesn't intersect the surface, the function will
+ * return SDL_FALSE and blits will be completely clipped. Otherwise the
+ * function returns SDL_TRUE and blits to the surface will be clipped to
+ * the intersection of the surface area and the clipping rectangle.
+ *
+ * Note that blits are automatically clipped to the edges of the source
+ * and destination surfaces.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_SetClipRect(SDL_Surface * surface,
+ const SDL_Rect * rect);
+
+/**
+ * Gets the clipping rectangle for the destination surface in a blit.
+ *
+ * \c rect must be a pointer to a valid rectangle which will be filled
+ * with the correct values.
+ */
+extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface * surface,
+ SDL_Rect * rect);
+
+/*
+ * Creates a new surface identical to the existing surface
+ */
+extern DECLSPEC SDL_Surface *SDLCALL SDL_DuplicateSurface(SDL_Surface * surface);
+
+/**
+ * Creates a new surface of the specified format, and then copies and maps
+ * the given surface to it so the blit of the converted surface will be as
+ * fast as possible. If this function fails, it returns NULL.
+ *
+ * The \c flags parameter is passed to SDL_CreateRGBSurface() and has those
+ * semantics. You can also pass ::SDL_RLEACCEL in the flags parameter and
+ * SDL will try to RLE accelerate colorkey and alpha blits in the resulting
+ * surface.
+ */
+extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface
+ (SDL_Surface * src, const SDL_PixelFormat * fmt, Uint32 flags);
+extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat
+ (SDL_Surface * src, Uint32 pixel_format, Uint32 flags);
+
+/**
+ * \brief Copy a block of pixels of one format to another format
+ *
+ * \return 0 on success, or -1 if there was an error
+ */
+extern DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height,
+ Uint32 src_format,
+ const void * src, int src_pitch,
+ Uint32 dst_format,
+ void * dst, int dst_pitch);
+
+/**
+ * Performs a fast fill of the given rectangle with \c color.
+ *
+ * If \c rect is NULL, the whole surface will be filled with \c color.
+ *
+ * The color should be a pixel of the format used by the surface, and
+ * can be generated by the SDL_MapRGB() function.
+ *
+ * \return 0 on success, or -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_FillRect
+ (SDL_Surface * dst, const SDL_Rect * rect, Uint32 color);
+extern DECLSPEC int SDLCALL SDL_FillRects
+ (SDL_Surface * dst, const SDL_Rect * rects, int count, Uint32 color);
+
+/**
+ * Performs a fast blit from the source surface to the destination surface.
+ *
+ * This assumes that the source and destination rectangles are
+ * the same size. If either \c srcrect or \c dstrect are NULL, the entire
+ * surface (\c src or \c dst) is copied. The final blit rectangles are saved
+ * in \c srcrect and \c dstrect after all clipping is performed.
+ *
+ * \return If the blit is successful, it returns 0, otherwise it returns -1.
+ *
+ * The blit function should not be called on a locked surface.
+ *
+ * The blit semantics for surfaces with and without blending and colorkey
+ * are defined as follows:
+ * \verbatim
+ RGBA->RGB:
+ Source surface blend mode set to SDL_BLENDMODE_BLEND:
+ alpha-blend (using the source alpha-channel and per-surface alpha)
+ SDL_SRCCOLORKEY ignored.
+ Source surface blend mode set to SDL_BLENDMODE_NONE:
+ copy RGB.
+ if SDL_SRCCOLORKEY set, only copy the pixels matching the
+ RGB values of the source color key, ignoring alpha in the
+ comparison.
+
+ RGB->RGBA:
+ Source surface blend mode set to SDL_BLENDMODE_BLEND:
+ alpha-blend (using the source per-surface alpha)
+ Source surface blend mode set to SDL_BLENDMODE_NONE:
+ copy RGB, set destination alpha to source per-surface alpha value.
+ both:
+ if SDL_SRCCOLORKEY set, only copy the pixels matching the
+ source color key.
+
+ RGBA->RGBA:
+ Source surface blend mode set to SDL_BLENDMODE_BLEND:
+ alpha-blend (using the source alpha-channel and per-surface alpha)
+ SDL_SRCCOLORKEY ignored.
+ Source surface blend mode set to SDL_BLENDMODE_NONE:
+ copy all of RGBA to the destination.
+ if SDL_SRCCOLORKEY set, only copy the pixels matching the
+ RGB values of the source color key, ignoring alpha in the
+ comparison.
+
+ RGB->RGB:
+ Source surface blend mode set to SDL_BLENDMODE_BLEND:
+ alpha-blend (using the source per-surface alpha)
+ Source surface blend mode set to SDL_BLENDMODE_NONE:
+ copy RGB.
+ both:
+ if SDL_SRCCOLORKEY set, only copy the pixels matching the
+ source color key.
+ \endverbatim
+ *
+ * You should call SDL_BlitSurface() unless you know exactly how SDL
+ * blitting works internally and how to use the other blit functions.
+ */
+#define SDL_BlitSurface SDL_UpperBlit
+
+/**
+ * This is the public blit function, SDL_BlitSurface(), and it performs
+ * rectangle validation and clipping before passing it to SDL_LowerBlit()
+ */
+extern DECLSPEC int SDLCALL SDL_UpperBlit
+ (SDL_Surface * src, const SDL_Rect * srcrect,
+ SDL_Surface * dst, SDL_Rect * dstrect);
+
+/**
+ * This is a semi-private blit function and it performs low-level surface
+ * blitting only.
+ */
+extern DECLSPEC int SDLCALL SDL_LowerBlit
+ (SDL_Surface * src, SDL_Rect * srcrect,
+ SDL_Surface * dst, SDL_Rect * dstrect);
+
+/**
+ * \brief Perform a fast, low quality, stretch blit between two surfaces of the
+ * same pixel format.
+ *
+ * \note This function uses a static buffer, and is not thread-safe.
+ */
+extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src,
+ const SDL_Rect * srcrect,
+ SDL_Surface * dst,
+ const SDL_Rect * dstrect);
+
+#define SDL_BlitScaled SDL_UpperBlitScaled
+
+/**
+ * This is the public scaled blit function, SDL_BlitScaled(), and it performs
+ * rectangle validation and clipping before passing it to SDL_LowerBlitScaled()
+ */
+extern DECLSPEC int SDLCALL SDL_UpperBlitScaled
+ (SDL_Surface * src, const SDL_Rect * srcrect,
+ SDL_Surface * dst, SDL_Rect * dstrect);
+
+/**
+ * This is a semi-private blit function and it performs low-level surface
+ * scaled blitting only.
+ */
+extern DECLSPEC int SDLCALL SDL_LowerBlitScaled
+ (SDL_Surface * src, SDL_Rect * srcrect,
+ SDL_Surface * dst, SDL_Rect * dstrect);
+
+/**
+ * \brief Set the YUV conversion mode
+ */
+extern DECLSPEC void SDLCALL SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_MODE mode);
+
+/**
+ * \brief Get the YUV conversion mode
+ */
+extern DECLSPEC SDL_YUV_CONVERSION_MODE SDLCALL SDL_GetYUVConversionMode(void);
+
+/**
+ * \brief Get the YUV conversion mode, returning the correct mode for the resolution when the current conversion mode is SDL_YUV_CONVERSION_AUTOMATIC
+ */
+extern DECLSPEC SDL_YUV_CONVERSION_MODE SDLCALL SDL_GetYUVConversionModeForResolution(int width, int height);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_surface_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_system.h b/src/3rdparty/SDL2/include/SDL2/SDL_system.h
new file mode 100644
index 0000000..7b776fd
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_system.h
@@ -0,0 +1,247 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_system.h
+ *
+ * Include file for platform specific SDL API functions
+ */
+
+#ifndef SDL_system_h_
+#define SDL_system_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_keyboard.h"
+#include "SDL_render.h"
+#include "SDL_video.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Platform specific functions for Windows */
+#ifdef __WIN32__
+
+/**
+ \brief Set a function that is called for every windows message, before TranslateMessage()
+*/
+typedef void (SDLCALL * SDL_WindowsMessageHook)(void *userdata, void *hWnd, unsigned int message, Uint64 wParam, Sint64 lParam);
+extern DECLSPEC void SDLCALL SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback, void *userdata);
+
+/**
+ \brief Returns the D3D9 adapter index that matches the specified display index.
+
+ This adapter index can be passed to IDirect3D9::CreateDevice and controls
+ on which monitor a full screen application will appear.
+*/
+extern DECLSPEC int SDLCALL SDL_Direct3D9GetAdapterIndex( int displayIndex );
+
+typedef struct IDirect3DDevice9 IDirect3DDevice9;
+/**
+ \brief Returns the D3D device associated with a renderer, or NULL if it's not a D3D renderer.
+
+ Once you are done using the device, you should release it to avoid a resource leak.
+ */
+extern DECLSPEC IDirect3DDevice9* SDLCALL SDL_RenderGetD3D9Device(SDL_Renderer * renderer);
+
+/**
+ \brief Returns the DXGI Adapter and Output indices for the specified display index.
+
+ These can be passed to EnumAdapters and EnumOutputs respectively to get the objects
+ required to create a DX10 or DX11 device and swap chain.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex );
+
+#endif /* __WIN32__ */
+
+
+/* Platform specific functions for iOS */
+#if defined(__IPHONEOS__) && __IPHONEOS__
+
+#define SDL_iOSSetAnimationCallback(window, interval, callback, callbackParam) SDL_iPhoneSetAnimationCallback(window, interval, callback, callbackParam)
+extern DECLSPEC int SDLCALL SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam);
+
+#define SDL_iOSSetEventPump(enabled) SDL_iPhoneSetEventPump(enabled)
+extern DECLSPEC void SDLCALL SDL_iPhoneSetEventPump(SDL_bool enabled);
+
+#endif /* __IPHONEOS__ */
+
+
+/* Platform specific functions for Android */
+#if defined(__ANDROID__) && __ANDROID__
+
+/**
+ \brief Get the JNI environment for the current thread
+
+ This returns JNIEnv*, but the prototype is void* so we don't need jni.h
+ */
+extern DECLSPEC void * SDLCALL SDL_AndroidGetJNIEnv(void);
+
+/**
+ \brief Get the SDL Activity object for the application
+
+ This returns jobject, but the prototype is void* so we don't need jni.h
+ The jobject returned by SDL_AndroidGetActivity is a local reference.
+ It is the caller's responsibility to properly release it
+ (using env->Push/PopLocalFrame or manually with env->DeleteLocalRef)
+ */
+extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity(void);
+
+/**
+ \brief Return true if the application is running on Android TV
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_IsAndroidTV(void);
+
+/**
+ See the official Android developer guide for more information:
+ http://developer.android.com/guide/topics/data/data-storage.html
+*/
+#define SDL_ANDROID_EXTERNAL_STORAGE_READ 0x01
+#define SDL_ANDROID_EXTERNAL_STORAGE_WRITE 0x02
+
+/**
+ \brief Get the path used for internal storage for this application.
+
+ This path is unique to your application and cannot be written to
+ by other applications.
+ */
+extern DECLSPEC const char * SDLCALL SDL_AndroidGetInternalStoragePath(void);
+
+/**
+ \brief Get the current state of external storage, a bitmask of these values:
+ SDL_ANDROID_EXTERNAL_STORAGE_READ
+ SDL_ANDROID_EXTERNAL_STORAGE_WRITE
+
+ If external storage is currently unavailable, this will return 0.
+*/
+extern DECLSPEC int SDLCALL SDL_AndroidGetExternalStorageState(void);
+
+/**
+ \brief Get the path used for external storage for this application.
+
+ This path is unique to your application, but is public and can be
+ written to by other applications.
+ */
+extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath(void);
+
+#endif /* __ANDROID__ */
+
+/* Platform specific functions for WinRT */
+#if defined(__WINRT__) && __WINRT__
+
+/**
+ * \brief WinRT / Windows Phone path types
+ */
+typedef enum
+{
+ /** \brief The installed app's root directory.
+ Files here are likely to be read-only. */
+ SDL_WINRT_PATH_INSTALLED_LOCATION,
+
+ /** \brief The app's local data store. Files may be written here */
+ SDL_WINRT_PATH_LOCAL_FOLDER,
+
+ /** \brief The app's roaming data store. Unsupported on Windows Phone.
+ Files written here may be copied to other machines via a network
+ connection.
+ */
+ SDL_WINRT_PATH_ROAMING_FOLDER,
+
+ /** \brief The app's temporary data store. Unsupported on Windows Phone.
+ Files written here may be deleted at any time. */
+ SDL_WINRT_PATH_TEMP_FOLDER
+} SDL_WinRT_Path;
+
+
+/**
+ * \brief WinRT Device Family
+ */
+typedef enum
+{
+ /** \brief Unknown family */
+ SDL_WINRT_DEVICEFAMILY_UNKNOWN,
+
+ /** \brief Desktop family*/
+ SDL_WINRT_DEVICEFAMILY_DESKTOP,
+
+ /** \brief Mobile family (for example smartphone) */
+ SDL_WINRT_DEVICEFAMILY_MOBILE,
+
+ /** \brief XBox family */
+ SDL_WINRT_DEVICEFAMILY_XBOX,
+} SDL_WinRT_DeviceFamily;
+
+
+/**
+ * \brief Retrieves a WinRT defined path on the local file system
+ *
+ * \note Documentation on most app-specific path types on WinRT
+ * can be found on MSDN, at the URL:
+ * http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
+ *
+ * \param pathType The type of path to retrieve.
+ * \return A UCS-2 string (16-bit, wide-char) containing the path, or NULL
+ * if the path is not available for any reason. Not all paths are
+ * available on all versions of Windows. This is especially true on
+ * Windows Phone. Check the documentation for the given
+ * SDL_WinRT_Path for more information on which path types are
+ * supported where.
+ */
+extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType);
+
+/**
+ * \brief Retrieves a WinRT defined path on the local file system
+ *
+ * \note Documentation on most app-specific path types on WinRT
+ * can be found on MSDN, at the URL:
+ * http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
+ *
+ * \param pathType The type of path to retrieve.
+ * \return A UTF-8 string (8-bit, multi-byte) containing the path, or NULL
+ * if the path is not available for any reason. Not all paths are
+ * available on all versions of Windows. This is especially true on
+ * Windows Phone. Check the documentation for the given
+ * SDL_WinRT_Path for more information on which path types are
+ * supported where.
+ */
+extern DECLSPEC const char * SDLCALL SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType);
+
+/**
+ * \brief Detects the device family of WinRT plattform on runtime
+ *
+ * \return Device family
+ */
+extern DECLSPEC SDL_WinRT_DeviceFamily SDLCALL SDL_WinRTGetDeviceFamily();
+
+#endif /* __WINRT__ */
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_system_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_syswm.h b/src/3rdparty/SDL2/include/SDL2/SDL_syswm.h
new file mode 100644
index 0000000..8aa4a39
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_syswm.h
@@ -0,0 +1,324 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_syswm.h
+ *
+ * Include file for SDL custom system window manager hooks.
+ */
+
+#ifndef SDL_syswm_h_
+#define SDL_syswm_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_video.h"
+#include "SDL_version.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \file SDL_syswm.h
+ *
+ * Your application has access to a special type of event ::SDL_SYSWMEVENT,
+ * which contains window-manager specific information and arrives whenever
+ * an unhandled window event occurs. This event is ignored by default, but
+ * you can enable it with SDL_EventState().
+ */
+#ifdef SDL_PROTOTYPES_ONLY
+struct SDL_SysWMinfo;
+#else
+
+#if defined(SDL_VIDEO_DRIVER_WINDOWS)
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#include <windows.h>
+#endif
+
+#if defined(SDL_VIDEO_DRIVER_WINRT)
+#include <Inspectable.h>
+#endif
+
+/* This is the structure for custom window manager events */
+#if defined(SDL_VIDEO_DRIVER_X11)
+#if defined(__APPLE__) && defined(__MACH__)
+/* conflicts with Quickdraw.h */
+#define Cursor X11Cursor
+#endif
+
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+
+#if defined(__APPLE__) && defined(__MACH__)
+/* matches the re-define above */
+#undef Cursor
+#endif
+
+#endif /* defined(SDL_VIDEO_DRIVER_X11) */
+
+#if defined(SDL_VIDEO_DRIVER_DIRECTFB)
+#include <directfb.h>
+#endif
+
+#if defined(SDL_VIDEO_DRIVER_COCOA)
+#ifdef __OBJC__
+@class NSWindow;
+#else
+typedef struct _NSWindow NSWindow;
+#endif
+#endif
+
+#if defined(SDL_VIDEO_DRIVER_UIKIT)
+#ifdef __OBJC__
+#include <UIKit/UIKit.h>
+#else
+typedef struct _UIWindow UIWindow;
+typedef struct _UIViewController UIViewController;
+#endif
+typedef Uint32 GLuint;
+#endif
+
+#if defined(SDL_VIDEO_DRIVER_ANDROID)
+typedef struct ANativeWindow ANativeWindow;
+typedef void *EGLSurface;
+#endif
+
+#if defined(SDL_VIDEO_DRIVER_VIVANTE)
+#include "SDL_egl.h"
+#endif
+
+/**
+ * These are the various supported windowing subsystems
+ */
+typedef enum
+{
+ SDL_SYSWM_UNKNOWN,
+ SDL_SYSWM_WINDOWS,
+ SDL_SYSWM_X11,
+ SDL_SYSWM_DIRECTFB,
+ SDL_SYSWM_COCOA,
+ SDL_SYSWM_UIKIT,
+ SDL_SYSWM_WAYLAND,
+ SDL_SYSWM_MIR,
+ SDL_SYSWM_WINRT,
+ SDL_SYSWM_ANDROID,
+ SDL_SYSWM_VIVANTE,
+ SDL_SYSWM_OS2
+} SDL_SYSWM_TYPE;
+
+/**
+ * The custom event structure.
+ */
+struct SDL_SysWMmsg
+{
+ SDL_version version;
+ SDL_SYSWM_TYPE subsystem;
+ union
+ {
+#if defined(SDL_VIDEO_DRIVER_WINDOWS)
+ struct {
+ HWND hwnd; /**< The window for the message */
+ UINT msg; /**< The type of message */
+ WPARAM wParam; /**< WORD message parameter */
+ LPARAM lParam; /**< LONG message parameter */
+ } win;
+#endif
+#if defined(SDL_VIDEO_DRIVER_X11)
+ struct {
+ XEvent event;
+ } x11;
+#endif
+#if defined(SDL_VIDEO_DRIVER_DIRECTFB)
+ struct {
+ DFBEvent event;
+ } dfb;
+#endif
+#if defined(SDL_VIDEO_DRIVER_COCOA)
+ struct
+ {
+ /* Latest version of Xcode clang complains about empty structs in C v. C++:
+ error: empty struct has size 0 in C, size 1 in C++
+ */
+ int dummy;
+ /* No Cocoa window events yet */
+ } cocoa;
+#endif
+#if defined(SDL_VIDEO_DRIVER_UIKIT)
+ struct
+ {
+ int dummy;
+ /* No UIKit window events yet */
+ } uikit;
+#endif
+#if defined(SDL_VIDEO_DRIVER_VIVANTE)
+ struct
+ {
+ int dummy;
+ /* No Vivante window events yet */
+ } vivante;
+#endif
+ /* Can't have an empty union */
+ int dummy;
+ } msg;
+};
+
+/**
+ * The custom window manager information structure.
+ *
+ * When this structure is returned, it holds information about which
+ * low level system it is using, and will be one of SDL_SYSWM_TYPE.
+ */
+struct SDL_SysWMinfo
+{
+ SDL_version version;
+ SDL_SYSWM_TYPE subsystem;
+ union
+ {
+#if defined(SDL_VIDEO_DRIVER_WINDOWS)
+ struct
+ {
+ HWND window; /**< The window handle */
+ HDC hdc; /**< The window device context */
+ HINSTANCE hinstance; /**< The instance handle */
+ } win;
+#endif
+#if defined(SDL_VIDEO_DRIVER_WINRT)
+ struct
+ {
+ IInspectable * window; /**< The WinRT CoreWindow */
+ } winrt;
+#endif
+#if defined(SDL_VIDEO_DRIVER_X11)
+ struct
+ {
+ Display *display; /**< The X11 display */
+ Window window; /**< The X11 window */
+ } x11;
+#endif
+#if defined(SDL_VIDEO_DRIVER_DIRECTFB)
+ struct
+ {
+ IDirectFB *dfb; /**< The directfb main interface */
+ IDirectFBWindow *window; /**< The directfb window handle */
+ IDirectFBSurface *surface; /**< The directfb client surface */
+ } dfb;
+#endif
+#if defined(SDL_VIDEO_DRIVER_COCOA)
+ struct
+ {
+#if defined(__OBJC__) && defined(__has_feature) && __has_feature(objc_arc)
+ NSWindow __unsafe_unretained *window; /**< The Cocoa window */
+#else
+ NSWindow *window; /**< The Cocoa window */
+#endif
+ } cocoa;
+#endif
+#if defined(SDL_VIDEO_DRIVER_UIKIT)
+ struct
+ {
+#if defined(__OBJC__) && defined(__has_feature) && __has_feature(objc_arc)
+ UIWindow __unsafe_unretained *window; /**< The UIKit window */
+#else
+ UIWindow *window; /**< The UIKit window */
+#endif
+ GLuint framebuffer; /**< The GL view's Framebuffer Object. It must be bound when rendering to the screen using GL. */
+ GLuint colorbuffer; /**< The GL view's color Renderbuffer Object. It must be bound when SDL_GL_SwapWindow is called. */
+ GLuint resolveFramebuffer; /**< The Framebuffer Object which holds the resolve color Renderbuffer, when MSAA is used. */
+ } uikit;
+#endif
+#if defined(SDL_VIDEO_DRIVER_WAYLAND)
+ struct
+ {
+ struct wl_display *display; /**< Wayland display */
+ struct wl_surface *surface; /**< Wayland surface */
+ struct wl_shell_surface *shell_surface; /**< Wayland shell_surface (window manager handle) */
+ } wl;
+#endif
+#if defined(SDL_VIDEO_DRIVER_MIR)
+ struct
+ {
+ struct MirConnection *connection; /**< Mir display server connection */
+ struct MirSurface *surface; /**< Mir surface */
+ } mir;
+#endif
+
+#if defined(SDL_VIDEO_DRIVER_ANDROID)
+ struct
+ {
+ ANativeWindow *window;
+ EGLSurface surface;
+ } android;
+#endif
+
+#if defined(SDL_VIDEO_DRIVER_VIVANTE)
+ struct
+ {
+ EGLNativeDisplayType display;
+ EGLNativeWindowType window;
+ } vivante;
+#endif
+
+ /* Make sure this union is always 64 bytes (8 64-bit pointers). */
+ /* Be careful not to overflow this if you add a new target! */
+ Uint8 dummy[64];
+ } info;
+};
+
+#endif /* SDL_PROTOTYPES_ONLY */
+
+typedef struct SDL_SysWMinfo SDL_SysWMinfo;
+
+/* Function prototypes */
+/**
+ * \brief This function allows access to driver-dependent window information.
+ *
+ * \param window The window about which information is being requested
+ * \param info This structure must be initialized with the SDL version, and is
+ * then filled in with information about the given window.
+ *
+ * \return SDL_TRUE if the function is implemented and the version member of
+ * the \c info struct is valid, SDL_FALSE otherwise.
+ *
+ * You typically use this function like this:
+ * \code
+ * SDL_SysWMinfo info;
+ * SDL_VERSION(&info.version);
+ * if ( SDL_GetWindowWMInfo(window, &info) ) { ... }
+ * \endcode
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo(SDL_Window * window,
+ SDL_SysWMinfo * info);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_syswm_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_test.h b/src/3rdparty/SDL2/include/SDL2/SDL_test.h
new file mode 100644
index 0000000..6cc373b
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_test.h
@@ -0,0 +1,69 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+#ifndef SDL_test_h_
+#define SDL_test_h_
+
+#include "SDL.h"
+#include "SDL_test_assert.h"
+#include "SDL_test_common.h"
+#include "SDL_test_compare.h"
+#include "SDL_test_crc32.h"
+#include "SDL_test_font.h"
+#include "SDL_test_fuzzer.h"
+#include "SDL_test_harness.h"
+#include "SDL_test_images.h"
+#include "SDL_test_log.h"
+#include "SDL_test_md5.h"
+#include "SDL_test_memory.h"
+#include "SDL_test_random.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Global definitions */
+
+/*
+ * Note: Maximum size of SDLTest log message is less than SDL's limit
+ * to ensure we can fit additional information such as the timestamp.
+ */
+#define SDLTEST_MAX_LOGMESSAGE_LENGTH 3584
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_test_assert.h b/src/3rdparty/SDL2/include/SDL2/SDL_test_assert.h
new file mode 100644
index 0000000..1788d7a
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_test_assert.h
@@ -0,0 +1,105 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_assert.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/*
+ *
+ * Assert API for test code and test cases
+ *
+ */
+
+#ifndef SDL_test_assert_h_
+#define SDL_test_assert_h_
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Fails the assert.
+ */
+#define ASSERT_FAIL 0
+
+/**
+ * \brief Passes the assert.
+ */
+#define ASSERT_PASS 1
+
+/**
+ * \brief Assert that logs and break execution flow on failures.
+ *
+ * \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0).
+ * \param assertDescription Message to log with the assert describing it.
+ */
+void SDLTest_Assert(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(2);
+
+/**
+ * \brief Assert for test cases that logs but does not break execution flow on failures. Updates assertion counters.
+ *
+ * \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0).
+ * \param assertDescription Message to log with the assert describing it.
+ *
+ * \returns Returns the assertCondition so it can be used to externally to break execution flow if desired.
+ */
+int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(2);
+
+/**
+ * \brief Explicitly pass without checking an assertion condition. Updates assertion counter.
+ *
+ * \param assertDescription Message to log with the assert describing it.
+ */
+void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(1);
+
+/**
+ * \brief Resets the assert summary counters to zero.
+ */
+void SDLTest_ResetAssertSummary(void);
+
+/**
+ * \brief Logs summary of all assertions (total, pass, fail) since last reset as INFO or ERROR.
+ */
+void SDLTest_LogAssertSummary(void);
+
+
+/**
+ * \brief Converts the current assert summary state to a test result.
+ *
+ * \returns TEST_RESULT_PASSED, TEST_RESULT_FAILED, or TEST_RESULT_NO_ASSERT
+ */
+int SDLTest_AssertSummaryToTestResult(void);
+
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_assert_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_test_common.h b/src/3rdparty/SDL2/include/SDL2/SDL_test_common.h
new file mode 100644
index 0000000..be2e6b2
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_test_common.h
@@ -0,0 +1,188 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_common.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/* Ported from original test\common.h file. */
+
+#ifndef SDL_test_common_h_
+#define SDL_test_common_h_
+
+#include "SDL.h"
+
+#if defined(__PSP__)
+#define DEFAULT_WINDOW_WIDTH 480
+#define DEFAULT_WINDOW_HEIGHT 272
+#else
+#define DEFAULT_WINDOW_WIDTH 640
+#define DEFAULT_WINDOW_HEIGHT 480
+#endif
+
+#define VERBOSE_VIDEO 0x00000001
+#define VERBOSE_MODES 0x00000002
+#define VERBOSE_RENDER 0x00000004
+#define VERBOSE_EVENT 0x00000008
+#define VERBOSE_AUDIO 0x00000010
+
+typedef struct
+{
+ /* SDL init flags */
+ char **argv;
+ Uint32 flags;
+ Uint32 verbose;
+
+ /* Video info */
+ const char *videodriver;
+ int display;
+ const char *window_title;
+ const char *window_icon;
+ Uint32 window_flags;
+ int window_x;
+ int window_y;
+ int window_w;
+ int window_h;
+ int window_minW;
+ int window_minH;
+ int window_maxW;
+ int window_maxH;
+ int logical_w;
+ int logical_h;
+ float scale;
+ int depth;
+ int refresh_rate;
+ int num_windows;
+ SDL_Window **windows;
+
+ /* Renderer info */
+ const char *renderdriver;
+ Uint32 render_flags;
+ SDL_bool skip_renderer;
+ SDL_Renderer **renderers;
+ SDL_Texture **targets;
+
+ /* Audio info */
+ const char *audiodriver;
+ SDL_AudioSpec audiospec;
+
+ /* GL settings */
+ int gl_red_size;
+ int gl_green_size;
+ int gl_blue_size;
+ int gl_alpha_size;
+ int gl_buffer_size;
+ int gl_depth_size;
+ int gl_stencil_size;
+ int gl_double_buffer;
+ int gl_accum_red_size;
+ int gl_accum_green_size;
+ int gl_accum_blue_size;
+ int gl_accum_alpha_size;
+ int gl_stereo;
+ int gl_multisamplebuffers;
+ int gl_multisamplesamples;
+ int gl_retained_backing;
+ int gl_accelerated;
+ int gl_major_version;
+ int gl_minor_version;
+ int gl_debug;
+ int gl_profile_mask;
+} SDLTest_CommonState;
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Function prototypes */
+
+/**
+ * \brief Parse command line parameters and create common state.
+ *
+ * \param argv Array of command line parameters
+ * \param flags Flags indicating which subsystem to initialize (i.e. SDL_INIT_VIDEO | SDL_INIT_AUDIO)
+ *
+ * \returns Returns a newly allocated common state object.
+ */
+SDLTest_CommonState *SDLTest_CommonCreateState(char **argv, Uint32 flags);
+
+/**
+ * \brief Process one common argument.
+ *
+ * \param state The common state describing the test window to create.
+ * \param index The index of the argument to process in argv[].
+ *
+ * \returns The number of arguments processed (i.e. 1 for --fullscreen, 2 for --video [videodriver], or -1 on error.
+ */
+int SDLTest_CommonArg(SDLTest_CommonState * state, int index);
+
+/**
+ * \brief Returns common usage information
+ *
+ * \param state The common state describing the test window to create.
+ *
+ * \returns String with usage information
+ */
+const char *SDLTest_CommonUsage(SDLTest_CommonState * state);
+
+/**
+ * \brief Open test window.
+ *
+ * \param state The common state describing the test window to create.
+ *
+ * \returns True if initialization succeeded, false otherwise
+ */
+SDL_bool SDLTest_CommonInit(SDLTest_CommonState * state);
+
+/**
+ * \brief Common event handler for test windows.
+ *
+ * \param state The common state used to create test window.
+ * \param event The event to handle.
+ * \param done Flag indicating we are done.
+ *
+ */
+void SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done);
+
+/**
+ * \brief Close test window.
+ *
+ * \param state The common state used to create test window.
+ *
+ */
+void SDLTest_CommonQuit(SDLTest_CommonState * state);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_common_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_test_compare.h b/src/3rdparty/SDL2/include/SDL2/SDL_test_compare.h
new file mode 100644
index 0000000..c22e447
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_test_compare.h
@@ -0,0 +1,69 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_compare.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/*
+
+ Defines comparison functions (i.e. for surfaces).
+
+*/
+
+#ifndef SDL_test_compare_h_
+#define SDL_test_compare_h_
+
+#include "SDL.h"
+
+#include "SDL_test_images.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Compares a surface and with reference image data for equality
+ *
+ * \param surface Surface used in comparison
+ * \param referenceSurface Test Surface used in comparison
+ * \param allowable_error Allowable difference (=sum of squared difference for each RGB component) in blending accuracy.
+ *
+ * \returns 0 if comparison succeeded, >0 (=number of pixels for which the comparison failed) if comparison failed, -1 if any of the surfaces were NULL, -2 if the surface sizes differ.
+ */
+int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_compare_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_test_crc32.h b/src/3rdparty/SDL2/include/SDL2/SDL_test_crc32.h
new file mode 100644
index 0000000..3d235d0
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_test_crc32.h
@@ -0,0 +1,124 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_crc32.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/*
+
+ Implements CRC32 calculations (default output is Perl String::CRC32 compatible).
+
+*/
+
+#ifndef SDL_test_crc32_h_
+#define SDL_test_crc32_h_
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* ------------ Definitions --------- */
+
+/* Definition shared by all CRC routines */
+
+#ifndef CrcUint32
+ #define CrcUint32 unsigned int
+#endif
+#ifndef CrcUint8
+ #define CrcUint8 unsigned char
+#endif
+
+#ifdef ORIGINAL_METHOD
+ #define CRC32_POLY 0x04c11db7 /* AUTODIN II, Ethernet, & FDDI */
+#else
+ #define CRC32_POLY 0xEDB88320 /* Perl String::CRC32 compatible */
+#endif
+
+/**
+ * Data structure for CRC32 (checksum) computation
+ */
+ typedef struct {
+ CrcUint32 crc32_table[256]; /* CRC table */
+ } SDLTest_Crc32Context;
+
+/* ---------- Function Prototypes ------------- */
+
+/**
+ * \brief Initialize the CRC context
+ *
+ * Note: The function initializes the crc table required for all crc calculations.
+ *
+ * \param crcContext pointer to context variable
+ *
+ * \returns 0 for OK, -1 on error
+ *
+ */
+ int SDLTest_Crc32Init(SDLTest_Crc32Context * crcContext);
+
+
+/**
+ * \brief calculate a crc32 from a data block
+ *
+ * \param crcContext pointer to context variable
+ * \param inBuf input buffer to checksum
+ * \param inLen length of input buffer
+ * \param crc32 pointer to Uint32 to store the final CRC into
+ *
+ * \returns 0 for OK, -1 on error
+ *
+ */
+int SDLTest_Crc32Calc(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);
+
+/* Same routine broken down into three steps */
+int SDLTest_Crc32CalcStart(SDLTest_Crc32Context * crcContext, CrcUint32 *crc32);
+int SDLTest_Crc32CalcEnd(SDLTest_Crc32Context * crcContext, CrcUint32 *crc32);
+int SDLTest_Crc32CalcBuffer(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);
+
+
+/**
+ * \brief clean up CRC context
+ *
+ * \param crcContext pointer to context variable
+ *
+ * \returns 0 for OK, -1 on error
+ *
+*/
+
+int SDLTest_Crc32Done(SDLTest_Crc32Context * crcContext);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_crc32_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_test_font.h b/src/3rdparty/SDL2/include/SDL2/SDL_test_font.h
new file mode 100644
index 0000000..59cbdca
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_test_font.h
@@ -0,0 +1,81 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_font.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+#ifndef SDL_test_font_h_
+#define SDL_test_font_h_
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Function prototypes */
+
+#define FONT_CHARACTER_SIZE 8
+
+/**
+ * \brief Draw a string in the currently set font.
+ *
+ * \param renderer The renderer to draw on.
+ * \param x The X coordinate of the upper left corner of the character.
+ * \param y The Y coordinate of the upper left corner of the character.
+ * \param c The character to draw.
+ *
+ * \returns Returns 0 on success, -1 on failure.
+ */
+int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, char c);
+
+/**
+ * \brief Draw a string in the currently set font.
+ *
+ * \param renderer The renderer to draw on.
+ * \param x The X coordinate of the upper left corner of the string.
+ * \param y The Y coordinate of the upper left corner of the string.
+ * \param s The string to draw.
+ *
+ * \returns Returns 0 on success, -1 on failure.
+ */
+int SDLTest_DrawString(SDL_Renderer *renderer, int x, int y, const char *s);
+
+
+/**
+ * \brief Cleanup textures used by font drawing functions.
+ */
+void SDLTest_CleanupTextDrawing(void);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_font_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_test_fuzzer.h b/src/3rdparty/SDL2/include/SDL2/SDL_test_fuzzer.h
new file mode 100644
index 0000000..8fcb9eb
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_test_fuzzer.h
@@ -0,0 +1,384 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_fuzzer.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/*
+
+ Data generators for fuzzing test data in a reproducible way.
+
+*/
+
+#ifndef SDL_test_fuzzer_h_
+#define SDL_test_fuzzer_h_
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/*
+ Based on GSOC code by Markus Kauppila <markus.kauppila@gmail.com>
+*/
+
+
+/**
+ * \file
+ * Note: The fuzzer implementation uses a static instance of random context
+ * internally which makes it thread-UNsafe.
+ */
+
+/**
+ * Initializes the fuzzer for a test
+ *
+ * \param execKey Execution "Key" that initializes the random number generator uniquely for the test.
+ *
+ */
+void SDLTest_FuzzerInit(Uint64 execKey);
+
+
+/**
+ * Returns a random Uint8
+ *
+ * \returns Generated integer
+ */
+Uint8 SDLTest_RandomUint8(void);
+
+/**
+ * Returns a random Sint8
+ *
+ * \returns Generated signed integer
+ */
+Sint8 SDLTest_RandomSint8(void);
+
+
+/**
+ * Returns a random Uint16
+ *
+ * \returns Generated integer
+ */
+Uint16 SDLTest_RandomUint16(void);
+
+/**
+ * Returns a random Sint16
+ *
+ * \returns Generated signed integer
+ */
+Sint16 SDLTest_RandomSint16(void);
+
+
+/**
+ * Returns a random integer
+ *
+ * \returns Generated integer
+ */
+Sint32 SDLTest_RandomSint32(void);
+
+
+/**
+ * Returns a random positive integer
+ *
+ * \returns Generated integer
+ */
+Uint32 SDLTest_RandomUint32(void);
+
+/**
+ * Returns random Uint64.
+ *
+ * \returns Generated integer
+ */
+Uint64 SDLTest_RandomUint64(void);
+
+
+/**
+ * Returns random Sint64.
+ *
+ * \returns Generated signed integer
+ */
+Sint64 SDLTest_RandomSint64(void);
+
+/**
+ * \returns random float in range [0.0 - 1.0[
+ */
+float SDLTest_RandomUnitFloat(void);
+
+/**
+ * \returns random double in range [0.0 - 1.0[
+ */
+double SDLTest_RandomUnitDouble(void);
+
+/**
+ * \returns random float.
+ *
+ */
+float SDLTest_RandomFloat(void);
+
+/**
+ * \returns random double.
+ *
+ */
+double SDLTest_RandomDouble(void);
+
+/**
+ * Returns a random boundary value for Uint8 within the given boundaries.
+ * Boundaries are inclusive, see the usage examples below. If validDomain
+ * is true, the function will only return valid boundaries, otherwise non-valid
+ * boundaries are also possible.
+ * If boundary1 > boundary2, the values are swapped
+ *
+ * Usage examples:
+ * RandomUint8BoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20
+ * RandomUint8BoundaryValue(1, 20, SDL_FALSE) returns 0 or 21
+ * RandomUint8BoundaryValue(0, 99, SDL_FALSE) returns 100
+ * RandomUint8BoundaryValue(0, 255, SDL_FALSE) returns 0 (error set)
+ *
+ * \param boundary1 Lower boundary limit
+ * \param boundary2 Upper boundary limit
+ * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
+ *
+ * \returns Random boundary value for the given range and domain or 0 with error set
+ */
+Uint8 SDLTest_RandomUint8BoundaryValue(Uint8 boundary1, Uint8 boundary2, SDL_bool validDomain);
+
+/**
+ * Returns a random boundary value for Uint16 within the given boundaries.
+ * Boundaries are inclusive, see the usage examples below. If validDomain
+ * is true, the function will only return valid boundaries, otherwise non-valid
+ * boundaries are also possible.
+ * If boundary1 > boundary2, the values are swapped
+ *
+ * Usage examples:
+ * RandomUint16BoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20
+ * RandomUint16BoundaryValue(1, 20, SDL_FALSE) returns 0 or 21
+ * RandomUint16BoundaryValue(0, 99, SDL_FALSE) returns 100
+ * RandomUint16BoundaryValue(0, 0xFFFF, SDL_FALSE) returns 0 (error set)
+ *
+ * \param boundary1 Lower boundary limit
+ * \param boundary2 Upper boundary limit
+ * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
+ *
+ * \returns Random boundary value for the given range and domain or 0 with error set
+ */
+Uint16 SDLTest_RandomUint16BoundaryValue(Uint16 boundary1, Uint16 boundary2, SDL_bool validDomain);
+
+/**
+ * Returns a random boundary value for Uint32 within the given boundaries.
+ * Boundaries are inclusive, see the usage examples below. If validDomain
+ * is true, the function will only return valid boundaries, otherwise non-valid
+ * boundaries are also possible.
+ * If boundary1 > boundary2, the values are swapped
+ *
+ * Usage examples:
+ * RandomUint32BoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20
+ * RandomUint32BoundaryValue(1, 20, SDL_FALSE) returns 0 or 21
+ * RandomUint32BoundaryValue(0, 99, SDL_FALSE) returns 100
+ * RandomUint32BoundaryValue(0, 0xFFFFFFFF, SDL_FALSE) returns 0 (with error set)
+ *
+ * \param boundary1 Lower boundary limit
+ * \param boundary2 Upper boundary limit
+ * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
+ *
+ * \returns Random boundary value for the given range and domain or 0 with error set
+ */
+Uint32 SDLTest_RandomUint32BoundaryValue(Uint32 boundary1, Uint32 boundary2, SDL_bool validDomain);
+
+/**
+ * Returns a random boundary value for Uint64 within the given boundaries.
+ * Boundaries are inclusive, see the usage examples below. If validDomain
+ * is true, the function will only return valid boundaries, otherwise non-valid
+ * boundaries are also possible.
+ * If boundary1 > boundary2, the values are swapped
+ *
+ * Usage examples:
+ * RandomUint64BoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20
+ * RandomUint64BoundaryValue(1, 20, SDL_FALSE) returns 0 or 21
+ * RandomUint64BoundaryValue(0, 99, SDL_FALSE) returns 100
+ * RandomUint64BoundaryValue(0, 0xFFFFFFFFFFFFFFFF, SDL_FALSE) returns 0 (with error set)
+ *
+ * \param boundary1 Lower boundary limit
+ * \param boundary2 Upper boundary limit
+ * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
+ *
+ * \returns Random boundary value for the given range and domain or 0 with error set
+ */
+Uint64 SDLTest_RandomUint64BoundaryValue(Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain);
+
+/**
+ * Returns a random boundary value for Sint8 within the given boundaries.
+ * Boundaries are inclusive, see the usage examples below. If validDomain
+ * is true, the function will only return valid boundaries, otherwise non-valid
+ * boundaries are also possible.
+ * If boundary1 > boundary2, the values are swapped
+ *
+ * Usage examples:
+ * RandomSint8BoundaryValue(-10, 20, SDL_TRUE) returns -11, -10, 19 or 20
+ * RandomSint8BoundaryValue(-100, -10, SDL_FALSE) returns -101 or -9
+ * RandomSint8BoundaryValue(SINT8_MIN, 99, SDL_FALSE) returns 100
+ * RandomSint8BoundaryValue(SINT8_MIN, SINT8_MAX, SDL_FALSE) returns SINT8_MIN (== error value) with error set
+ *
+ * \param boundary1 Lower boundary limit
+ * \param boundary2 Upper boundary limit
+ * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
+ *
+ * \returns Random boundary value for the given range and domain or SINT8_MIN with error set
+ */
+Sint8 SDLTest_RandomSint8BoundaryValue(Sint8 boundary1, Sint8 boundary2, SDL_bool validDomain);
+
+
+/**
+ * Returns a random boundary value for Sint16 within the given boundaries.
+ * Boundaries are inclusive, see the usage examples below. If validDomain
+ * is true, the function will only return valid boundaries, otherwise non-valid
+ * boundaries are also possible.
+ * If boundary1 > boundary2, the values are swapped
+ *
+ * Usage examples:
+ * RandomSint16BoundaryValue(-10, 20, SDL_TRUE) returns -11, -10, 19 or 20
+ * RandomSint16BoundaryValue(-100, -10, SDL_FALSE) returns -101 or -9
+ * RandomSint16BoundaryValue(SINT16_MIN, 99, SDL_FALSE) returns 100
+ * RandomSint16BoundaryValue(SINT16_MIN, SINT16_MAX, SDL_FALSE) returns SINT16_MIN (== error value) with error set
+ *
+ * \param boundary1 Lower boundary limit
+ * \param boundary2 Upper boundary limit
+ * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
+ *
+ * \returns Random boundary value for the given range and domain or SINT16_MIN with error set
+ */
+Sint16 SDLTest_RandomSint16BoundaryValue(Sint16 boundary1, Sint16 boundary2, SDL_bool validDomain);
+
+/**
+ * Returns a random boundary value for Sint32 within the given boundaries.
+ * Boundaries are inclusive, see the usage examples below. If validDomain
+ * is true, the function will only return valid boundaries, otherwise non-valid
+ * boundaries are also possible.
+ * If boundary1 > boundary2, the values are swapped
+ *
+ * Usage examples:
+ * RandomSint32BoundaryValue(-10, 20, SDL_TRUE) returns -11, -10, 19 or 20
+ * RandomSint32BoundaryValue(-100, -10, SDL_FALSE) returns -101 or -9
+ * RandomSint32BoundaryValue(SINT32_MIN, 99, SDL_FALSE) returns 100
+ * RandomSint32BoundaryValue(SINT32_MIN, SINT32_MAX, SDL_FALSE) returns SINT32_MIN (== error value)
+ *
+ * \param boundary1 Lower boundary limit
+ * \param boundary2 Upper boundary limit
+ * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
+ *
+ * \returns Random boundary value for the given range and domain or SINT32_MIN with error set
+ */
+Sint32 SDLTest_RandomSint32BoundaryValue(Sint32 boundary1, Sint32 boundary2, SDL_bool validDomain);
+
+/**
+ * Returns a random boundary value for Sint64 within the given boundaries.
+ * Boundaries are inclusive, see the usage examples below. If validDomain
+ * is true, the function will only return valid boundaries, otherwise non-valid
+ * boundaries are also possible.
+ * If boundary1 > boundary2, the values are swapped
+ *
+ * Usage examples:
+ * RandomSint64BoundaryValue(-10, 20, SDL_TRUE) returns -11, -10, 19 or 20
+ * RandomSint64BoundaryValue(-100, -10, SDL_FALSE) returns -101 or -9
+ * RandomSint64BoundaryValue(SINT64_MIN, 99, SDL_FALSE) returns 100
+ * RandomSint64BoundaryValue(SINT64_MIN, SINT64_MAX, SDL_FALSE) returns SINT64_MIN (== error value) and error set
+ *
+ * \param boundary1 Lower boundary limit
+ * \param boundary2 Upper boundary limit
+ * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
+ *
+ * \returns Random boundary value for the given range and domain or SINT64_MIN with error set
+ */
+Sint64 SDLTest_RandomSint64BoundaryValue(Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain);
+
+
+/**
+ * Returns integer in range [min, max] (inclusive).
+ * Min and max values can be negative values.
+ * If Max in smaller than min, then the values are swapped.
+ * Min and max are the same value, that value will be returned.
+ *
+ * \param min Minimum inclusive value of returned random number
+ * \param max Maximum inclusive value of returned random number
+ *
+ * \returns Generated random integer in range
+ */
+Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max);
+
+
+/**
+ * Generates random null-terminated string. The minimum length for
+ * the string is 1 character, maximum length for the string is 255
+ * characters and it can contain ASCII characters from 32 to 126.
+ *
+ * Note: Returned string needs to be deallocated.
+ *
+ * \returns Newly allocated random string; or NULL if length was invalid or string could not be allocated.
+ */
+char * SDLTest_RandomAsciiString(void);
+
+
+/**
+ * Generates random null-terminated string. The maximum length for
+ * the string is defined by the maxLength parameter.
+ * String can contain ASCII characters from 32 to 126.
+ *
+ * Note: Returned string needs to be deallocated.
+ *
+ * \param maxLength The maximum length of the generated string.
+ *
+ * \returns Newly allocated random string; or NULL if maxLength was invalid or string could not be allocated.
+ */
+char * SDLTest_RandomAsciiStringWithMaximumLength(int maxLength);
+
+
+/**
+ * Generates random null-terminated string. The length for
+ * the string is defined by the size parameter.
+ * String can contain ASCII characters from 32 to 126.
+ *
+ * Note: Returned string needs to be deallocated.
+ *
+ * \param size The length of the generated string
+ *
+ * \returns Newly allocated random string; or NULL if size was invalid or string could not be allocated.
+ */
+char * SDLTest_RandomAsciiStringOfSize(int size);
+
+/**
+ * Returns the invocation count for the fuzzer since last ...FuzzerInit.
+ */
+int SDLTest_GetFuzzerInvocationCount(void);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_fuzzer_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_test_harness.h b/src/3rdparty/SDL2/include/SDL2/SDL_test_harness.h
new file mode 100644
index 0000000..8641e0a
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_test_harness.h
@@ -0,0 +1,134 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_harness.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/*
+ Defines types for test case definitions and the test execution harness API.
+
+ Based on original GSOC code by Markus Kauppila <markus.kauppila@gmail.com>
+*/
+
+#ifndef SDL_test_h_arness_h
+#define SDL_test_h_arness_h
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* ! Definitions for test case structures */
+#define TEST_ENABLED 1
+#define TEST_DISABLED 0
+
+/* ! Definition of all the possible test return values of the test case method */
+#define TEST_ABORTED -1
+#define TEST_STARTED 0
+#define TEST_COMPLETED 1
+#define TEST_SKIPPED 2
+
+/* ! Definition of all the possible test results for the harness */
+#define TEST_RESULT_PASSED 0
+#define TEST_RESULT_FAILED 1
+#define TEST_RESULT_NO_ASSERT 2
+#define TEST_RESULT_SKIPPED 3
+#define TEST_RESULT_SETUP_FAILURE 4
+
+/* !< Function pointer to a test case setup function (run before every test) */
+typedef void (*SDLTest_TestCaseSetUpFp)(void *arg);
+
+/* !< Function pointer to a test case function */
+typedef int (*SDLTest_TestCaseFp)(void *arg);
+
+/* !< Function pointer to a test case teardown function (run after every test) */
+typedef void (*SDLTest_TestCaseTearDownFp)(void *arg);
+
+/**
+ * Holds information about a single test case.
+ */
+typedef struct SDLTest_TestCaseReference {
+ /* !< Func2Stress */
+ SDLTest_TestCaseFp testCase;
+ /* !< Short name (or function name) "Func2Stress" */
+ char *name;
+ /* !< Long name or full description "This test pushes func2() to the limit." */
+ char *description;
+ /* !< Set to TEST_ENABLED or TEST_DISABLED (test won't be run) */
+ int enabled;
+} SDLTest_TestCaseReference;
+
+/**
+ * Holds information about a test suite (multiple test cases).
+ */
+typedef struct SDLTest_TestSuiteReference {
+ /* !< "PlatformSuite" */
+ char *name;
+ /* !< The function that is run before each test. NULL skips. */
+ SDLTest_TestCaseSetUpFp testSetUp;
+ /* !< The test cases that are run as part of the suite. Last item should be NULL. */
+ const SDLTest_TestCaseReference **testCases;
+ /* !< The function that is run after each test. NULL skips. */
+ SDLTest_TestCaseTearDownFp testTearDown;
+} SDLTest_TestSuiteReference;
+
+
+/**
+ * \brief Generates a random run seed string for the harness. The generated seed will contain alphanumeric characters (0-9A-Z).
+ *
+ * Note: The returned string needs to be deallocated by the caller.
+ *
+ * \param length The length of the seed string to generate
+ *
+ * \returns The generated seed string
+ */
+char *SDLTest_GenerateRunSeed(const int length);
+
+/**
+ * \brief Execute a test suite using the given run seed and execution key.
+ *
+ * \param testSuites Suites containing the test case.
+ * \param userRunSeed Custom run seed provided by user, or NULL to autogenerate one.
+ * \param userExecKey Custom execution key provided by user, or 0 to autogenerate one.
+ * \param filter Filter specification. NULL disables. Case sensitive.
+ * \param testIterations Number of iterations to run each test case.
+ *
+ * \returns Test run result; 0 when all tests passed, 1 if any tests failed.
+ */
+int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *userRunSeed, Uint64 userExecKey, const char *filter, int testIterations);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_h_arness_h */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_test_images.h b/src/3rdparty/SDL2/include/SDL2/SDL_test_images.h
new file mode 100644
index 0000000..9c4dd5b
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_test_images.h
@@ -0,0 +1,78 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_images.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/*
+
+ Defines some images for tests.
+
+*/
+
+#ifndef SDL_test_images_h_
+#define SDL_test_images_h_
+
+#include "SDL.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ *Type for test images.
+ */
+typedef struct SDLTest_SurfaceImage_s {
+ int width;
+ int height;
+ unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */
+ const char *pixel_data;
+} SDLTest_SurfaceImage_t;
+
+/* Test images */
+SDL_Surface *SDLTest_ImageBlit(void);
+SDL_Surface *SDLTest_ImageBlitColor(void);
+SDL_Surface *SDLTest_ImageBlitAlpha(void);
+SDL_Surface *SDLTest_ImageBlitBlendAdd(void);
+SDL_Surface *SDLTest_ImageBlitBlend(void);
+SDL_Surface *SDLTest_ImageBlitBlendMod(void);
+SDL_Surface *SDLTest_ImageBlitBlendNone(void);
+SDL_Surface *SDLTest_ImageBlitBlendAll(void);
+SDL_Surface *SDLTest_ImageFace(void);
+SDL_Surface *SDLTest_ImagePrimitives(void);
+SDL_Surface *SDLTest_ImagePrimitivesBlend(void);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_images_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_test_log.h b/src/3rdparty/SDL2/include/SDL2/SDL_test_log.h
new file mode 100644
index 0000000..ebd44fb
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_test_log.h
@@ -0,0 +1,67 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_log.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/*
+ *
+ * Wrapper to log in the TEST category
+ *
+ */
+
+#ifndef SDL_test_log_h_
+#define SDL_test_log_h_
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Prints given message with a timestamp in the TEST category and INFO priority.
+ *
+ * \param fmt Message to be logged
+ */
+void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
+
+/**
+ * \brief Prints given message with a timestamp in the TEST category and the ERROR priority.
+ *
+ * \param fmt Message to be logged
+ */
+void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_log_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_test_md5.h b/src/3rdparty/SDL2/include/SDL2/SDL_test_md5.h
new file mode 100644
index 0000000..0e41057
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_test_md5.h
@@ -0,0 +1,129 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_md5.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/*
+ ***********************************************************************
+ ** Header file for implementation of MD5 **
+ ** RSA Data Security, Inc. MD5 Message-Digest Algorithm **
+ ** Created: 2/17/90 RLR **
+ ** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version **
+ ** Revised (for MD5): RLR 4/27/91 **
+ ** -- G modified to have y&~z instead of y&z **
+ ** -- FF, GG, HH modified to add in last register done **
+ ** -- Access pattern: round 2 works mod 5, round 3 works mod 3 **
+ ** -- distinct additive constant for each step **
+ ** -- round 4 added, working mod 7 **
+ ***********************************************************************
+*/
+
+/*
+ ***********************************************************************
+ ** Message-digest routines: **
+ ** To form the message digest for a message M **
+ ** (1) Initialize a context buffer mdContext using MD5Init **
+ ** (2) Call MD5Update on mdContext and M **
+ ** (3) Call MD5Final on mdContext **
+ ** The message digest is now in mdContext->digest[0...15] **
+ ***********************************************************************
+*/
+
+#ifndef SDL_test_md5_h_
+#define SDL_test_md5_h_
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* ------------ Definitions --------- */
+
+/* typedef a 32-bit type */
+ typedef unsigned long int MD5UINT4;
+
+/* Data structure for MD5 (Message-Digest) computation */
+ typedef struct {
+ MD5UINT4 i[2]; /* number of _bits_ handled mod 2^64 */
+ MD5UINT4 buf[4]; /* scratch buffer */
+ unsigned char in[64]; /* input buffer */
+ unsigned char digest[16]; /* actual digest after Md5Final call */
+ } SDLTest_Md5Context;
+
+/* ---------- Function Prototypes ------------- */
+
+/**
+ * \brief initialize the context
+ *
+ * \param mdContext pointer to context variable
+ *
+ * Note: The function initializes the message-digest context
+ * mdContext. Call before each new use of the context -
+ * all fields are set to zero.
+ */
+ void SDLTest_Md5Init(SDLTest_Md5Context * mdContext);
+
+
+/**
+ * \brief update digest from variable length data
+ *
+ * \param mdContext pointer to context variable
+ * \param inBuf pointer to data array/string
+ * \param inLen length of data array/string
+ *
+ * Note: The function updates the message-digest context to account
+ * for the presence of each of the characters inBuf[0..inLen-1]
+ * in the message whose digest is being computed.
+*/
+
+ void SDLTest_Md5Update(SDLTest_Md5Context * mdContext, unsigned char *inBuf,
+ unsigned int inLen);
+
+
+/**
+ * \brief complete digest computation
+ *
+ * \param mdContext pointer to context variable
+ *
+ * Note: The function terminates the message-digest computation and
+ * ends with the desired message digest in mdContext.digest[0..15].
+ * Always call before using the digest[] variable.
+*/
+
+ void SDLTest_Md5Final(SDLTest_Md5Context * mdContext);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_md5_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_test_memory.h b/src/3rdparty/SDL2/include/SDL2/SDL_test_memory.h
new file mode 100644
index 0000000..4827ae6
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_test_memory.h
@@ -0,0 +1,63 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_memory.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+#ifndef SDL_test_memory_h_
+#define SDL_test_memory_h_
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * \brief Start tracking SDL memory allocations
+ *
+ * \note This should be called before any other SDL functions for complete tracking coverage
+ */
+int SDLTest_TrackAllocations();
+
+/**
+ * \brief Print a log of any outstanding allocations
+ *
+ * \note This can be called after SDL_Quit()
+ */
+void SDLTest_LogAllocations();
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_memory_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_test_random.h b/src/3rdparty/SDL2/include/SDL2/SDL_test_random.h
new file mode 100644
index 0000000..0eb414f
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_test_random.h
@@ -0,0 +1,115 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_random.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/*
+
+ A "32-bit Multiply with carry random number generator. Very fast.
+ Includes a list of recommended multipliers.
+
+ multiply-with-carry generator: x(n) = a*x(n-1) + carry mod 2^32.
+ period: (a*2^31)-1
+
+*/
+
+#ifndef SDL_test_random_h_
+#define SDL_test_random_h_
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* --- Definitions */
+
+/*
+ * Macros that return a random number in a specific format.
+ */
+#define SDLTest_RandomInt(c) ((int)SDLTest_Random(c))
+
+/*
+ * Context structure for the random number generator state.
+ */
+ typedef struct {
+ unsigned int a;
+ unsigned int x;
+ unsigned int c;
+ unsigned int ah;
+ unsigned int al;
+ } SDLTest_RandomContext;
+
+
+/* --- Function prototypes */
+
+/**
+ * \brief Initialize random number generator with two integers.
+ *
+ * Note: The random sequence of numbers returned by ...Random() is the
+ * same for the same two integers and has a period of 2^31.
+ *
+ * \param rndContext pointer to context structure
+ * \param xi integer that defines the random sequence
+ * \param ci integer that defines the random sequence
+ *
+ */
+ void SDLTest_RandomInit(SDLTest_RandomContext * rndContext, unsigned int xi,
+ unsigned int ci);
+
+/**
+ * \brief Initialize random number generator based on current system time.
+ *
+ * \param rndContext pointer to context structure
+ *
+ */
+ void SDLTest_RandomInitTime(SDLTest_RandomContext *rndContext);
+
+
+/**
+ * \brief Initialize random number generator based on current system time.
+ *
+ * Note: ...RandomInit() or ...RandomInitTime() must have been called
+ * before using this function.
+ *
+ * \param rndContext pointer to context structure
+ *
+ * \returns A random number (32bit unsigned integer)
+ *
+ */
+ unsigned int SDLTest_Random(SDLTest_RandomContext *rndContext);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_random_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_thread.h b/src/3rdparty/SDL2/include/SDL2/SDL_thread.h
new file mode 100644
index 0000000..82a43fc
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_thread.h
@@ -0,0 +1,308 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_thread_h_
+#define SDL_thread_h_
+
+/**
+ * \file SDL_thread.h
+ *
+ * Header for the SDL thread management routines.
+ */
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+
+/* Thread synchronization primitives */
+#include "SDL_atomic.h"
+#include "SDL_mutex.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* The SDL thread structure, defined in SDL_thread.c */
+struct SDL_Thread;
+typedef struct SDL_Thread SDL_Thread;
+
+/* The SDL thread ID */
+typedef unsigned long SDL_threadID;
+
+/* Thread local storage ID, 0 is the invalid ID */
+typedef unsigned int SDL_TLSID;
+
+/**
+ * The SDL thread priority.
+ *
+ * \note On many systems you require special privileges to set high priority.
+ */
+typedef enum {
+ SDL_THREAD_PRIORITY_LOW,
+ SDL_THREAD_PRIORITY_NORMAL,
+ SDL_THREAD_PRIORITY_HIGH
+} SDL_ThreadPriority;
+
+/**
+ * The function passed to SDL_CreateThread().
+ * It is passed a void* user context parameter and returns an int.
+ */
+typedef int (SDLCALL * SDL_ThreadFunction) (void *data);
+
+#if defined(__WIN32__) && !defined(HAVE_LIBC)
+/**
+ * \file SDL_thread.h
+ *
+ * We compile SDL into a DLL. This means, that it's the DLL which
+ * creates a new thread for the calling process with the SDL_CreateThread()
+ * API. There is a problem with this, that only the RTL of the SDL2.DLL will
+ * be initialized for those threads, and not the RTL of the calling
+ * application!
+ *
+ * To solve this, we make a little hack here.
+ *
+ * We'll always use the caller's _beginthread() and _endthread() APIs to
+ * start a new thread. This way, if it's the SDL2.DLL which uses this API,
+ * then the RTL of SDL2.DLL will be used to create the new thread, and if it's
+ * the application, then the RTL of the application will be used.
+ *
+ * So, in short:
+ * Always use the _beginthread() and _endthread() of the calling runtime
+ * library!
+ */
+#define SDL_PASSED_BEGINTHREAD_ENDTHREAD
+#include <process.h> /* _beginthreadex() and _endthreadex() */
+
+typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread)
+ (void *, unsigned, unsigned (__stdcall *func)(void *),
+ void * /*arg*/, unsigned, unsigned * /* threadID */);
+typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
+
+/**
+ * Create a thread.
+ */
+extern DECLSPEC SDL_Thread *SDLCALL
+SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
+ pfnSDL_CurrentBeginThread pfnBeginThread,
+ pfnSDL_CurrentEndThread pfnEndThread);
+
+/**
+ * Create a thread.
+ */
+#if defined(SDL_CreateThread) && SDL_DYNAMIC_API
+#undef SDL_CreateThread
+#define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
+#else
+#define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
+#endif
+
+#elif defined(__OS2__)
+/*
+ * just like the windows case above: We compile SDL2
+ * into a dll with Watcom's runtime statically linked.
+ */
+#define SDL_PASSED_BEGINTHREAD_ENDTHREAD
+#ifndef __EMX__
+#include <process.h>
+#else
+#include <stdlib.h>
+#endif
+typedef int (*pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void * /*arg*/);
+typedef void (*pfnSDL_CurrentEndThread)(void);
+extern DECLSPEC SDL_Thread *SDLCALL
+SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
+ pfnSDL_CurrentBeginThread pfnBeginThread,
+ pfnSDL_CurrentEndThread pfnEndThread);
+#if defined(SDL_CreateThread) && SDL_DYNAMIC_API
+#undef SDL_CreateThread
+#define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread)
+#else
+#define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread)
+#endif
+
+#else
+
+/**
+ * Create a thread.
+ *
+ * Thread naming is a little complicated: Most systems have very small
+ * limits for the string length (Haiku has 32 bytes, Linux currently has 16,
+ * Visual C++ 6.0 has nine!), and possibly other arbitrary rules. You'll
+ * have to see what happens with your system's debugger. The name should be
+ * UTF-8 (but using the naming limits of C identifiers is a better bet).
+ * There are no requirements for thread naming conventions, so long as the
+ * string is null-terminated UTF-8, but these guidelines are helpful in
+ * choosing a name:
+ *
+ * http://stackoverflow.com/questions/149932/naming-conventions-for-threads
+ *
+ * If a system imposes requirements, SDL will try to munge the string for
+ * it (truncate, etc), but the original string contents will be available
+ * from SDL_GetThreadName().
+ */
+extern DECLSPEC SDL_Thread *SDLCALL
+SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data);
+
+#endif
+
+/**
+ * Get the thread name, as it was specified in SDL_CreateThread().
+ * This function returns a pointer to a UTF-8 string that names the
+ * specified thread, or NULL if it doesn't have a name. This is internal
+ * memory, not to be free()'d by the caller, and remains valid until the
+ * specified thread is cleaned up by SDL_WaitThread().
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetThreadName(SDL_Thread *thread);
+
+/**
+ * Get the thread identifier for the current thread.
+ */
+extern DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void);
+
+/**
+ * Get the thread identifier for the specified thread.
+ *
+ * Equivalent to SDL_ThreadID() if the specified thread is NULL.
+ */
+extern DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread * thread);
+
+/**
+ * Set the priority for the current thread
+ */
+extern DECLSPEC int SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority);
+
+/**
+ * Wait for a thread to finish. Threads that haven't been detached will
+ * remain (as a "zombie") until this function cleans them up. Not doing so
+ * is a resource leak.
+ *
+ * Once a thread has been cleaned up through this function, the SDL_Thread
+ * that references it becomes invalid and should not be referenced again.
+ * As such, only one thread may call SDL_WaitThread() on another.
+ *
+ * The return code for the thread function is placed in the area
+ * pointed to by \c status, if \c status is not NULL.
+ *
+ * You may not wait on a thread that has been used in a call to
+ * SDL_DetachThread(). Use either that function or this one, but not
+ * both, or behavior is undefined.
+ *
+ * It is safe to pass NULL to this function; it is a no-op.
+ */
+extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread * thread, int *status);
+
+/**
+ * A thread may be "detached" to signify that it should not remain until
+ * another thread has called SDL_WaitThread() on it. Detaching a thread
+ * is useful for long-running threads that nothing needs to synchronize
+ * with or further manage. When a detached thread is done, it simply
+ * goes away.
+ *
+ * There is no way to recover the return code of a detached thread. If you
+ * need this, don't detach the thread and instead use SDL_WaitThread().
+ *
+ * Once a thread is detached, you should usually assume the SDL_Thread isn't
+ * safe to reference again, as it will become invalid immediately upon
+ * the detached thread's exit, instead of remaining until someone has called
+ * SDL_WaitThread() to finally clean it up. As such, don't detach the same
+ * thread more than once.
+ *
+ * If a thread has already exited when passed to SDL_DetachThread(), it will
+ * stop waiting for a call to SDL_WaitThread() and clean up immediately.
+ * It is not safe to detach a thread that might be used with SDL_WaitThread().
+ *
+ * You may not call SDL_WaitThread() on a thread that has been detached.
+ * Use either that function or this one, but not both, or behavior is
+ * undefined.
+ *
+ * It is safe to pass NULL to this function; it is a no-op.
+ */
+extern DECLSPEC void SDLCALL SDL_DetachThread(SDL_Thread * thread);
+
+/**
+ * \brief Create an identifier that is globally visible to all threads but refers to data that is thread-specific.
+ *
+ * \return The newly created thread local storage identifier, or 0 on error
+ *
+ * \code
+ * static SDL_SpinLock tls_lock;
+ * static SDL_TLSID thread_local_storage;
+ *
+ * void SetMyThreadData(void *value)
+ * {
+ * if (!thread_local_storage) {
+ * SDL_AtomicLock(&tls_lock);
+ * if (!thread_local_storage) {
+ * thread_local_storage = SDL_TLSCreate();
+ * }
+ * SDL_AtomicUnlock(&tls_lock);
+ * }
+ * SDL_TLSSet(thread_local_storage, value, 0);
+ * }
+ *
+ * void *GetMyThreadData(void)
+ * {
+ * return SDL_TLSGet(thread_local_storage);
+ * }
+ * \endcode
+ *
+ * \sa SDL_TLSGet()
+ * \sa SDL_TLSSet()
+ */
+extern DECLSPEC SDL_TLSID SDLCALL SDL_TLSCreate(void);
+
+/**
+ * \brief Get the value associated with a thread local storage ID for the current thread.
+ *
+ * \param id The thread local storage ID
+ *
+ * \return The value associated with the ID for the current thread, or NULL if no value has been set.
+ *
+ * \sa SDL_TLSCreate()
+ * \sa SDL_TLSSet()
+ */
+extern DECLSPEC void * SDLCALL SDL_TLSGet(SDL_TLSID id);
+
+/**
+ * \brief Set the value associated with a thread local storage ID for the current thread.
+ *
+ * \param id The thread local storage ID
+ * \param value The value to associate with the ID for the current thread
+ * \param destructor A function called when the thread exits, to free the value.
+ *
+ * \return 0 on success, -1 on error
+ *
+ * \sa SDL_TLSCreate()
+ * \sa SDL_TLSGet()
+ */
+extern DECLSPEC int SDLCALL SDL_TLSSet(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void*));
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_thread_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_timer.h b/src/3rdparty/SDL2/include/SDL2/SDL_timer.h
new file mode 100644
index 0000000..5600618
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_timer.h
@@ -0,0 +1,115 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_timer_h_
+#define SDL_timer_h_
+
+/**
+ * \file SDL_timer.h
+ *
+ * Header for the SDL time management routines.
+ */
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Get the number of milliseconds since the SDL library initialization.
+ *
+ * \note This value wraps if the program runs for more than ~49 days.
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void);
+
+/**
+ * \brief Compare SDL ticks values, and return true if A has passed B
+ *
+ * e.g. if you want to wait 100 ms, you could do this:
+ * Uint32 timeout = SDL_GetTicks() + 100;
+ * while (!SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) {
+ * ... do work until timeout has elapsed
+ * }
+ */
+#define SDL_TICKS_PASSED(A, B) ((Sint32)((B) - (A)) <= 0)
+
+/**
+ * \brief Get the current value of the high resolution counter
+ */
+extern DECLSPEC Uint64 SDLCALL SDL_GetPerformanceCounter(void);
+
+/**
+ * \brief Get the count per second of the high resolution counter
+ */
+extern DECLSPEC Uint64 SDLCALL SDL_GetPerformanceFrequency(void);
+
+/**
+ * \brief Wait a specified number of milliseconds before returning.
+ */
+extern DECLSPEC void SDLCALL SDL_Delay(Uint32 ms);
+
+/**
+ * Function prototype for the timer callback function.
+ *
+ * The callback function is passed the current timer interval and returns
+ * the next timer interval. If the returned value is the same as the one
+ * passed in, the periodic alarm continues, otherwise a new alarm is
+ * scheduled. If the callback returns 0, the periodic alarm is cancelled.
+ */
+typedef Uint32 (SDLCALL * SDL_TimerCallback) (Uint32 interval, void *param);
+
+/**
+ * Definition of the timer ID type.
+ */
+typedef int SDL_TimerID;
+
+/**
+ * \brief Add a new timer to the pool of timers already running.
+ *
+ * \return A timer ID, or 0 when an error occurs.
+ */
+extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval,
+ SDL_TimerCallback callback,
+ void *param);
+
+/**
+ * \brief Remove a timer knowing its ID.
+ *
+ * \return A boolean value indicating success or failure.
+ *
+ * \warning It is not safe to remove a timer multiple times.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID id);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_timer_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_touch.h b/src/3rdparty/SDL2/include/SDL2/SDL_touch.h
new file mode 100644
index 0000000..f4075e7
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_touch.h
@@ -0,0 +1,86 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_touch.h
+ *
+ * Include file for SDL touch event handling.
+ */
+
+#ifndef SDL_touch_h_
+#define SDL_touch_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_video.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef Sint64 SDL_TouchID;
+typedef Sint64 SDL_FingerID;
+
+typedef struct SDL_Finger
+{
+ SDL_FingerID id;
+ float x;
+ float y;
+ float pressure;
+} SDL_Finger;
+
+/* Used as the device ID for mouse events simulated with touch input */
+#define SDL_TOUCH_MOUSEID ((Uint32)-1)
+
+
+/* Function prototypes */
+
+/**
+ * \brief Get the number of registered touch devices.
+ */
+extern DECLSPEC int SDLCALL SDL_GetNumTouchDevices(void);
+
+/**
+ * \brief Get the touch ID with the given index, or 0 if the index is invalid.
+ */
+extern DECLSPEC SDL_TouchID SDLCALL SDL_GetTouchDevice(int index);
+
+/**
+ * \brief Get the number of active fingers for a given touch device.
+ */
+extern DECLSPEC int SDLCALL SDL_GetNumTouchFingers(SDL_TouchID touchID);
+
+/**
+ * \brief Get the finger object of the given touch, with the given index.
+ */
+extern DECLSPEC SDL_Finger * SDLCALL SDL_GetTouchFinger(SDL_TouchID touchID, int index);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_touch_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_types.h b/src/3rdparty/SDL2/include/SDL2/SDL_types.h
new file mode 100644
index 0000000..4ac248c
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_types.h
@@ -0,0 +1,29 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_types.h
+ *
+ * \deprecated
+ */
+
+/* DEPRECATED */
+#include "SDL_stdinc.h"
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_version.h b/src/3rdparty/SDL2/include/SDL2/SDL_version.h
new file mode 100644
index 0000000..584b48c
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_version.h
@@ -0,0 +1,162 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_version.h
+ *
+ * This header defines the current SDL version.
+ */
+
+#ifndef SDL_version_h_
+#define SDL_version_h_
+
+#include "SDL_stdinc.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Information the version of SDL in use.
+ *
+ * Represents the library's version as three levels: major revision
+ * (increments with massive changes, additions, and enhancements),
+ * minor revision (increments with backwards-compatible changes to the
+ * major revision), and patchlevel (increments with fixes to the minor
+ * revision).
+ *
+ * \sa SDL_VERSION
+ * \sa SDL_GetVersion
+ */
+typedef struct SDL_version
+{
+ Uint8 major; /**< major version */
+ Uint8 minor; /**< minor version */
+ Uint8 patch; /**< update version */
+} SDL_version;
+
+/* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
+*/
+#define SDL_MAJOR_VERSION 2
+#define SDL_MINOR_VERSION 0
+#define SDL_PATCHLEVEL 8
+
+/**
+ * \brief Macro to determine SDL version program was compiled against.
+ *
+ * This macro fills in a SDL_version structure with the version of the
+ * library you compiled against. This is determined by what header the
+ * compiler uses. Note that if you dynamically linked the library, you might
+ * have a slightly newer or older version at runtime. That version can be
+ * determined with SDL_GetVersion(), which, unlike SDL_VERSION(),
+ * is not a macro.
+ *
+ * \param x A pointer to a SDL_version struct to initialize.
+ *
+ * \sa SDL_version
+ * \sa SDL_GetVersion
+ */
+#define SDL_VERSION(x) \
+{ \
+ (x)->major = SDL_MAJOR_VERSION; \
+ (x)->minor = SDL_MINOR_VERSION; \
+ (x)->patch = SDL_PATCHLEVEL; \
+}
+
+/**
+ * This macro turns the version numbers into a numeric value:
+ * \verbatim
+ (1,2,3) -> (1203)
+ \endverbatim
+ *
+ * This assumes that there will never be more than 100 patchlevels.
+ */
+#define SDL_VERSIONNUM(X, Y, Z) \
+ ((X)*1000 + (Y)*100 + (Z))
+
+/**
+ * This is the version number macro for the current SDL version.
+ */
+#define SDL_COMPILEDVERSION \
+ SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL)
+
+/**
+ * This macro will evaluate to true if compiled with SDL at least X.Y.Z.
+ */
+#define SDL_VERSION_ATLEAST(X, Y, Z) \
+ (SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z))
+
+/**
+ * \brief Get the version of SDL that is linked against your program.
+ *
+ * If you are linking to SDL dynamically, then it is possible that the
+ * current version will be different than the version you compiled against.
+ * This function returns the current version, while SDL_VERSION() is a
+ * macro that tells you what version you compiled with.
+ *
+ * \code
+ * SDL_version compiled;
+ * SDL_version linked;
+ *
+ * SDL_VERSION(&compiled);
+ * SDL_GetVersion(&linked);
+ * printf("We compiled against SDL version %d.%d.%d ...\n",
+ * compiled.major, compiled.minor, compiled.patch);
+ * printf("But we linked against SDL version %d.%d.%d.\n",
+ * linked.major, linked.minor, linked.patch);
+ * \endcode
+ *
+ * This function may be called safely at any time, even before SDL_Init().
+ *
+ * \sa SDL_VERSION
+ */
+extern DECLSPEC void SDLCALL SDL_GetVersion(SDL_version * ver);
+
+/**
+ * \brief Get the code revision of SDL that is linked against your program.
+ *
+ * Returns an arbitrary string (a hash value) uniquely identifying the
+ * exact revision of the SDL library in use, and is only useful in comparing
+ * against other revisions. It is NOT an incrementing number.
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetRevision(void);
+
+/**
+ * \brief Get the revision number of SDL that is linked against your program.
+ *
+ * Returns a number uniquely identifying the exact revision of the SDL
+ * library in use. It is an incrementing number based on commits to
+ * hg.libsdl.org.
+ */
+extern DECLSPEC int SDLCALL SDL_GetRevisionNumber(void);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_version_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_video.h b/src/3rdparty/SDL2/include/SDL2/SDL_video.h
new file mode 100644
index 0000000..83f49fa
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_video.h
@@ -0,0 +1,1249 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_video.h
+ *
+ * Header file for SDL video functions.
+ */
+
+#ifndef SDL_video_h_
+#define SDL_video_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_pixels.h"
+#include "SDL_rect.h"
+#include "SDL_surface.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The structure that defines a display mode
+ *
+ * \sa SDL_GetNumDisplayModes()
+ * \sa SDL_GetDisplayMode()
+ * \sa SDL_GetDesktopDisplayMode()
+ * \sa SDL_GetCurrentDisplayMode()
+ * \sa SDL_GetClosestDisplayMode()
+ * \sa SDL_SetWindowDisplayMode()
+ * \sa SDL_GetWindowDisplayMode()
+ */
+typedef struct
+{
+ Uint32 format; /**< pixel format */
+ int w; /**< width, in screen coordinates */
+ int h; /**< height, in screen coordinates */
+ int refresh_rate; /**< refresh rate (or zero for unspecified) */
+ void *driverdata; /**< driver-specific data, initialize to 0 */
+} SDL_DisplayMode;
+
+/**
+ * \brief The type used to identify a window
+ *
+ * \sa SDL_CreateWindow()
+ * \sa SDL_CreateWindowFrom()
+ * \sa SDL_DestroyWindow()
+ * \sa SDL_GetWindowData()
+ * \sa SDL_GetWindowFlags()
+ * \sa SDL_GetWindowGrab()
+ * \sa SDL_GetWindowPosition()
+ * \sa SDL_GetWindowSize()
+ * \sa SDL_GetWindowTitle()
+ * \sa SDL_HideWindow()
+ * \sa SDL_MaximizeWindow()
+ * \sa SDL_MinimizeWindow()
+ * \sa SDL_RaiseWindow()
+ * \sa SDL_RestoreWindow()
+ * \sa SDL_SetWindowData()
+ * \sa SDL_SetWindowFullscreen()
+ * \sa SDL_SetWindowGrab()
+ * \sa SDL_SetWindowIcon()
+ * \sa SDL_SetWindowPosition()
+ * \sa SDL_SetWindowSize()
+ * \sa SDL_SetWindowBordered()
+ * \sa SDL_SetWindowResizable()
+ * \sa SDL_SetWindowTitle()
+ * \sa SDL_ShowWindow()
+ */
+typedef struct SDL_Window SDL_Window;
+
+/**
+ * \brief The flags on a window
+ *
+ * \sa SDL_GetWindowFlags()
+ */
+typedef enum
+{
+ /* !!! FIXME: change this to name = (1<<x). */
+ SDL_WINDOW_FULLSCREEN = 0x00000001, /**< fullscreen window */
+ SDL_WINDOW_OPENGL = 0x00000002, /**< window usable with OpenGL context */
+ SDL_WINDOW_SHOWN = 0x00000004, /**< window is visible */
+ SDL_WINDOW_HIDDEN = 0x00000008, /**< window is not visible */
+ SDL_WINDOW_BORDERLESS = 0x00000010, /**< no window decoration */
+ SDL_WINDOW_RESIZABLE = 0x00000020, /**< window can be resized */
+ SDL_WINDOW_MINIMIZED = 0x00000040, /**< window is minimized */
+ SDL_WINDOW_MAXIMIZED = 0x00000080, /**< window is maximized */
+ SDL_WINDOW_INPUT_GRABBED = 0x00000100, /**< window has grabbed input focus */
+ SDL_WINDOW_INPUT_FOCUS = 0x00000200, /**< window has input focus */
+ SDL_WINDOW_MOUSE_FOCUS = 0x00000400, /**< window has mouse focus */
+ SDL_WINDOW_FULLSCREEN_DESKTOP = ( SDL_WINDOW_FULLSCREEN | 0x00001000 ),
+ SDL_WINDOW_FOREIGN = 0x00000800, /**< window not created by SDL */
+ SDL_WINDOW_ALLOW_HIGHDPI = 0x00002000, /**< window should be created in high-DPI mode if supported.
+ On macOS NSHighResolutionCapable must be set true in the
+ application's Info.plist for this to have any effect. */
+ SDL_WINDOW_MOUSE_CAPTURE = 0x00004000, /**< window has mouse captured (unrelated to INPUT_GRABBED) */
+ SDL_WINDOW_ALWAYS_ON_TOP = 0x00008000, /**< window should always be above others */
+ SDL_WINDOW_SKIP_TASKBAR = 0x00010000, /**< window should not be added to the taskbar */
+ SDL_WINDOW_UTILITY = 0x00020000, /**< window should be treated as a utility window */
+ SDL_WINDOW_TOOLTIP = 0x00040000, /**< window should be treated as a tooltip */
+ SDL_WINDOW_POPUP_MENU = 0x00080000, /**< window should be treated as a popup menu */
+ SDL_WINDOW_VULKAN = 0x10000000 /**< window usable for Vulkan surface */
+} SDL_WindowFlags;
+
+/**
+ * \brief Used to indicate that you don't care what the window position is.
+ */
+#define SDL_WINDOWPOS_UNDEFINED_MASK 0x1FFF0000u
+#define SDL_WINDOWPOS_UNDEFINED_DISPLAY(X) (SDL_WINDOWPOS_UNDEFINED_MASK|(X))
+#define SDL_WINDOWPOS_UNDEFINED SDL_WINDOWPOS_UNDEFINED_DISPLAY(0)
+#define SDL_WINDOWPOS_ISUNDEFINED(X) \
+ (((X)&0xFFFF0000) == SDL_WINDOWPOS_UNDEFINED_MASK)
+
+/**
+ * \brief Used to indicate that the window position should be centered.
+ */
+#define SDL_WINDOWPOS_CENTERED_MASK 0x2FFF0000u
+#define SDL_WINDOWPOS_CENTERED_DISPLAY(X) (SDL_WINDOWPOS_CENTERED_MASK|(X))
+#define SDL_WINDOWPOS_CENTERED SDL_WINDOWPOS_CENTERED_DISPLAY(0)
+#define SDL_WINDOWPOS_ISCENTERED(X) \
+ (((X)&0xFFFF0000) == SDL_WINDOWPOS_CENTERED_MASK)
+
+/**
+ * \brief Event subtype for window events
+ */
+typedef enum
+{
+ SDL_WINDOWEVENT_NONE, /**< Never used */
+ SDL_WINDOWEVENT_SHOWN, /**< Window has been shown */
+ SDL_WINDOWEVENT_HIDDEN, /**< Window has been hidden */
+ SDL_WINDOWEVENT_EXPOSED, /**< Window has been exposed and should be
+ redrawn */
+ SDL_WINDOWEVENT_MOVED, /**< Window has been moved to data1, data2
+ */
+ SDL_WINDOWEVENT_RESIZED, /**< Window has been resized to data1xdata2 */
+ SDL_WINDOWEVENT_SIZE_CHANGED, /**< The window size has changed, either as
+ a result of an API call or through the
+ system or user changing the window size. */
+ SDL_WINDOWEVENT_MINIMIZED, /**< Window has been minimized */
+ SDL_WINDOWEVENT_MAXIMIZED, /**< Window has been maximized */
+ SDL_WINDOWEVENT_RESTORED, /**< Window has been restored to normal size
+ and position */
+ SDL_WINDOWEVENT_ENTER, /**< Window has gained mouse focus */
+ SDL_WINDOWEVENT_LEAVE, /**< Window has lost mouse focus */
+ SDL_WINDOWEVENT_FOCUS_GAINED, /**< Window has gained keyboard focus */
+ SDL_WINDOWEVENT_FOCUS_LOST, /**< Window has lost keyboard focus */
+ SDL_WINDOWEVENT_CLOSE, /**< The window manager requests that the window be closed */
+ SDL_WINDOWEVENT_TAKE_FOCUS, /**< Window is being offered a focus (should SetWindowInputFocus() on itself or a subwindow, or ignore) */
+ SDL_WINDOWEVENT_HIT_TEST /**< Window had a hit test that wasn't SDL_HITTEST_NORMAL. */
+} SDL_WindowEventID;
+
+/**
+ * \brief An opaque handle to an OpenGL context.
+ */
+typedef void *SDL_GLContext;
+
+/**
+ * \brief OpenGL configuration attributes
+ */
+typedef enum
+{
+ SDL_GL_RED_SIZE,
+ SDL_GL_GREEN_SIZE,
+ SDL_GL_BLUE_SIZE,
+ SDL_GL_ALPHA_SIZE,
+ SDL_GL_BUFFER_SIZE,
+ SDL_GL_DOUBLEBUFFER,
+ SDL_GL_DEPTH_SIZE,
+ SDL_GL_STENCIL_SIZE,
+ SDL_GL_ACCUM_RED_SIZE,
+ SDL_GL_ACCUM_GREEN_SIZE,
+ SDL_GL_ACCUM_BLUE_SIZE,
+ SDL_GL_ACCUM_ALPHA_SIZE,
+ SDL_GL_STEREO,
+ SDL_GL_MULTISAMPLEBUFFERS,
+ SDL_GL_MULTISAMPLESAMPLES,
+ SDL_GL_ACCELERATED_VISUAL,
+ SDL_GL_RETAINED_BACKING,
+ SDL_GL_CONTEXT_MAJOR_VERSION,
+ SDL_GL_CONTEXT_MINOR_VERSION,
+ SDL_GL_CONTEXT_EGL,
+ SDL_GL_CONTEXT_FLAGS,
+ SDL_GL_CONTEXT_PROFILE_MASK,
+ SDL_GL_SHARE_WITH_CURRENT_CONTEXT,
+ SDL_GL_FRAMEBUFFER_SRGB_CAPABLE,
+ SDL_GL_CONTEXT_RELEASE_BEHAVIOR,
+ SDL_GL_CONTEXT_RESET_NOTIFICATION,
+ SDL_GL_CONTEXT_NO_ERROR
+} SDL_GLattr;
+
+typedef enum
+{
+ SDL_GL_CONTEXT_PROFILE_CORE = 0x0001,
+ SDL_GL_CONTEXT_PROFILE_COMPATIBILITY = 0x0002,
+ SDL_GL_CONTEXT_PROFILE_ES = 0x0004 /**< GLX_CONTEXT_ES2_PROFILE_BIT_EXT */
+} SDL_GLprofile;
+
+typedef enum
+{
+ SDL_GL_CONTEXT_DEBUG_FLAG = 0x0001,
+ SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG = 0x0002,
+ SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG = 0x0004,
+ SDL_GL_CONTEXT_RESET_ISOLATION_FLAG = 0x0008
+} SDL_GLcontextFlag;
+
+typedef enum
+{
+ SDL_GL_CONTEXT_RELEASE_BEHAVIOR_NONE = 0x0000,
+ SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH = 0x0001
+} SDL_GLcontextReleaseFlag;
+
+typedef enum
+{
+ SDL_GL_CONTEXT_RESET_NO_NOTIFICATION = 0x0000,
+ SDL_GL_CONTEXT_RESET_LOSE_CONTEXT = 0x0001
+} SDL_GLContextResetNotification;
+
+/* Function prototypes */
+
+/**
+ * \brief Get the number of video drivers compiled into SDL
+ *
+ * \sa SDL_GetVideoDriver()
+ */
+extern DECLSPEC int SDLCALL SDL_GetNumVideoDrivers(void);
+
+/**
+ * \brief Get the name of a built in video driver.
+ *
+ * \note The video drivers are presented in the order in which they are
+ * normally checked during initialization.
+ *
+ * \sa SDL_GetNumVideoDrivers()
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetVideoDriver(int index);
+
+/**
+ * \brief Initialize the video subsystem, optionally specifying a video driver.
+ *
+ * \param driver_name Initialize a specific driver by name, or NULL for the
+ * default video driver.
+ *
+ * \return 0 on success, -1 on error
+ *
+ * This function initializes the video subsystem; setting up a connection
+ * to the window manager, etc, and determines the available display modes
+ * and pixel formats, but does not initialize a window or graphics mode.
+ *
+ * \sa SDL_VideoQuit()
+ */
+extern DECLSPEC int SDLCALL SDL_VideoInit(const char *driver_name);
+
+/**
+ * \brief Shuts down the video subsystem.
+ *
+ * This function closes all windows, and restores the original video mode.
+ *
+ * \sa SDL_VideoInit()
+ */
+extern DECLSPEC void SDLCALL SDL_VideoQuit(void);
+
+/**
+ * \brief Returns the name of the currently initialized video driver.
+ *
+ * \return The name of the current video driver or NULL if no driver
+ * has been initialized
+ *
+ * \sa SDL_GetNumVideoDrivers()
+ * \sa SDL_GetVideoDriver()
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetCurrentVideoDriver(void);
+
+/**
+ * \brief Returns the number of available video displays.
+ *
+ * \sa SDL_GetDisplayBounds()
+ */
+extern DECLSPEC int SDLCALL SDL_GetNumVideoDisplays(void);
+
+/**
+ * \brief Get the name of a display in UTF-8 encoding
+ *
+ * \return The name of a display, or NULL for an invalid display index.
+ *
+ * \sa SDL_GetNumVideoDisplays()
+ */
+extern DECLSPEC const char * SDLCALL SDL_GetDisplayName(int displayIndex);
+
+/**
+ * \brief Get the desktop area represented by a display, with the primary
+ * display located at 0,0
+ *
+ * \return 0 on success, or -1 if the index is out of range.
+ *
+ * \sa SDL_GetNumVideoDisplays()
+ */
+extern DECLSPEC int SDLCALL SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect);
+
+/**
+ * \brief Get the dots/pixels-per-inch for a display
+ *
+ * \note Diagonal, horizontal and vertical DPI can all be optionally
+ * returned if the parameter is non-NULL.
+ *
+ * \return 0 on success, or -1 if no DPI information is available or the index is out of range.
+ *
+ * \sa SDL_GetNumVideoDisplays()
+ */
+extern DECLSPEC int SDLCALL SDL_GetDisplayDPI(int displayIndex, float * ddpi, float * hdpi, float * vdpi);
+
+/**
+ * \brief Get the usable desktop area represented by a display, with the
+ * primary display located at 0,0
+ *
+ * This is the same area as SDL_GetDisplayBounds() reports, but with portions
+ * reserved by the system removed. For example, on Mac OS X, this subtracts
+ * the area occupied by the menu bar and dock.
+ *
+ * Setting a window to be fullscreen generally bypasses these unusable areas,
+ * so these are good guidelines for the maximum space available to a
+ * non-fullscreen window.
+ *
+ * \return 0 on success, or -1 if the index is out of range.
+ *
+ * \sa SDL_GetDisplayBounds()
+ * \sa SDL_GetNumVideoDisplays()
+ */
+extern DECLSPEC int SDLCALL SDL_GetDisplayUsableBounds(int displayIndex, SDL_Rect * rect);
+
+/**
+ * \brief Returns the number of available display modes.
+ *
+ * \sa SDL_GetDisplayMode()
+ */
+extern DECLSPEC int SDLCALL SDL_GetNumDisplayModes(int displayIndex);
+
+/**
+ * \brief Fill in information about a specific display mode.
+ *
+ * \note The display modes are sorted in this priority:
+ * \li bits per pixel -> more colors to fewer colors
+ * \li width -> largest to smallest
+ * \li height -> largest to smallest
+ * \li refresh rate -> highest to lowest
+ *
+ * \sa SDL_GetNumDisplayModes()
+ */
+extern DECLSPEC int SDLCALL SDL_GetDisplayMode(int displayIndex, int modeIndex,
+ SDL_DisplayMode * mode);
+
+/**
+ * \brief Fill in information about the desktop display mode.
+ */
+extern DECLSPEC int SDLCALL SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode * mode);
+
+/**
+ * \brief Fill in information about the current display mode.
+ */
+extern DECLSPEC int SDLCALL SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode * mode);
+
+
+/**
+ * \brief Get the closest match to the requested display mode.
+ *
+ * \param displayIndex The index of display from which mode should be queried.
+ * \param mode The desired display mode
+ * \param closest A pointer to a display mode to be filled in with the closest
+ * match of the available display modes.
+ *
+ * \return The passed in value \c closest, or NULL if no matching video mode
+ * was available.
+ *
+ * The available display modes are scanned, and \c closest is filled in with the
+ * closest mode matching the requested mode and returned. The mode format and
+ * refresh_rate default to the desktop mode if they are 0. The modes are
+ * scanned with size being first priority, format being second priority, and
+ * finally checking the refresh_rate. If all the available modes are too
+ * small, then NULL is returned.
+ *
+ * \sa SDL_GetNumDisplayModes()
+ * \sa SDL_GetDisplayMode()
+ */
+extern DECLSPEC SDL_DisplayMode * SDLCALL SDL_GetClosestDisplayMode(int displayIndex, const SDL_DisplayMode * mode, SDL_DisplayMode * closest);
+
+/**
+ * \brief Get the display index associated with a window.
+ *
+ * \return the display index of the display containing the center of the
+ * window, or -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_GetWindowDisplayIndex(SDL_Window * window);
+
+/**
+ * \brief Set the display mode used when a fullscreen window is visible.
+ *
+ * By default the window's dimensions and the desktop format and refresh rate
+ * are used.
+ *
+ * \param window The window for which the display mode should be set.
+ * \param mode The mode to use, or NULL for the default mode.
+ *
+ * \return 0 on success, or -1 if setting the display mode failed.
+ *
+ * \sa SDL_GetWindowDisplayMode()
+ * \sa SDL_SetWindowFullscreen()
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowDisplayMode(SDL_Window * window,
+ const SDL_DisplayMode
+ * mode);
+
+/**
+ * \brief Fill in information about the display mode used when a fullscreen
+ * window is visible.
+ *
+ * \sa SDL_SetWindowDisplayMode()
+ * \sa SDL_SetWindowFullscreen()
+ */
+extern DECLSPEC int SDLCALL SDL_GetWindowDisplayMode(SDL_Window * window,
+ SDL_DisplayMode * mode);
+
+/**
+ * \brief Get the pixel format associated with the window.
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_GetWindowPixelFormat(SDL_Window * window);
+
+/**
+ * \brief Create a window with the specified position, dimensions, and flags.
+ *
+ * \param title The title of the window, in UTF-8 encoding.
+ * \param x The x position of the window, ::SDL_WINDOWPOS_CENTERED, or
+ * ::SDL_WINDOWPOS_UNDEFINED.
+ * \param y The y position of the window, ::SDL_WINDOWPOS_CENTERED, or
+ * ::SDL_WINDOWPOS_UNDEFINED.
+ * \param w The width of the window, in screen coordinates.
+ * \param h The height of the window, in screen coordinates.
+ * \param flags The flags for the window, a mask of any of the following:
+ * ::SDL_WINDOW_FULLSCREEN, ::SDL_WINDOW_OPENGL,
+ * ::SDL_WINDOW_HIDDEN, ::SDL_WINDOW_BORDERLESS,
+ * ::SDL_WINDOW_RESIZABLE, ::SDL_WINDOW_MAXIMIZED,
+ * ::SDL_WINDOW_MINIMIZED, ::SDL_WINDOW_INPUT_GRABBED,
+ * ::SDL_WINDOW_ALLOW_HIGHDPI, ::SDL_WINDOW_VULKAN.
+ *
+ * \return The created window, or NULL if window creation failed.
+ *
+ * If the window is created with the SDL_WINDOW_ALLOW_HIGHDPI flag, its size
+ * in pixels may differ from its size in screen coordinates on platforms with
+ * high-DPI support (e.g. iOS and Mac OS X). Use SDL_GetWindowSize() to query
+ * the client area's size in screen coordinates, and SDL_GL_GetDrawableSize(),
+ * SDL_Vulkan_GetDrawableSize(), or SDL_GetRendererOutputSize() to query the
+ * drawable size in pixels.
+ *
+ * If the window is created with any of the SDL_WINDOW_OPENGL or
+ * SDL_WINDOW_VULKAN flags, then the corresponding LoadLibrary function
+ * (SDL_GL_LoadLibrary or SDL_Vulkan_LoadLibrary) is called and the
+ * corresponding UnloadLibrary function is called by SDL_DestroyWindow().
+ *
+ * If SDL_WINDOW_VULKAN is specified and there isn't a working Vulkan driver,
+ * SDL_CreateWindow() will fail because SDL_Vulkan_LoadLibrary() will fail.
+ *
+ * \note On non-Apple devices, SDL requires you to either not link to the
+ * Vulkan loader or link to a dynamic library version. This limitation
+ * may be removed in a future version of SDL.
+ *
+ * \sa SDL_DestroyWindow()
+ * \sa SDL_GL_LoadLibrary()
+ * \sa SDL_Vulkan_LoadLibrary()
+ */
+extern DECLSPEC SDL_Window * SDLCALL SDL_CreateWindow(const char *title,
+ int x, int y, int w,
+ int h, Uint32 flags);
+
+/**
+ * \brief Create an SDL window from an existing native window.
+ *
+ * \param data A pointer to driver-dependent window creation data
+ *
+ * \return The created window, or NULL if window creation failed.
+ *
+ * \sa SDL_DestroyWindow()
+ */
+extern DECLSPEC SDL_Window * SDLCALL SDL_CreateWindowFrom(const void *data);
+
+/**
+ * \brief Get the numeric ID of a window, for logging purposes.
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_GetWindowID(SDL_Window * window);
+
+/**
+ * \brief Get a window from a stored ID, or NULL if it doesn't exist.
+ */
+extern DECLSPEC SDL_Window * SDLCALL SDL_GetWindowFromID(Uint32 id);
+
+/**
+ * \brief Get the window flags.
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_GetWindowFlags(SDL_Window * window);
+
+/**
+ * \brief Set the title of a window, in UTF-8 format.
+ *
+ * \sa SDL_GetWindowTitle()
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowTitle(SDL_Window * window,
+ const char *title);
+
+/**
+ * \brief Get the title of a window, in UTF-8 format.
+ *
+ * \sa SDL_SetWindowTitle()
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetWindowTitle(SDL_Window * window);
+
+/**
+ * \brief Set the icon for a window.
+ *
+ * \param window The window for which the icon should be set.
+ * \param icon The icon for the window.
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowIcon(SDL_Window * window,
+ SDL_Surface * icon);
+
+/**
+ * \brief Associate an arbitrary named pointer with a window.
+ *
+ * \param window The window to associate with the pointer.
+ * \param name The name of the pointer.
+ * \param userdata The associated pointer.
+ *
+ * \return The previous value associated with 'name'
+ *
+ * \note The name is case-sensitive.
+ *
+ * \sa SDL_GetWindowData()
+ */
+extern DECLSPEC void* SDLCALL SDL_SetWindowData(SDL_Window * window,
+ const char *name,
+ void *userdata);
+
+/**
+ * \brief Retrieve the data pointer associated with a window.
+ *
+ * \param window The window to query.
+ * \param name The name of the pointer.
+ *
+ * \return The value associated with 'name'
+ *
+ * \sa SDL_SetWindowData()
+ */
+extern DECLSPEC void *SDLCALL SDL_GetWindowData(SDL_Window * window,
+ const char *name);
+
+/**
+ * \brief Set the position of a window.
+ *
+ * \param window The window to reposition.
+ * \param x The x coordinate of the window in screen coordinates, or
+ * ::SDL_WINDOWPOS_CENTERED or ::SDL_WINDOWPOS_UNDEFINED.
+ * \param y The y coordinate of the window in screen coordinates, or
+ * ::SDL_WINDOWPOS_CENTERED or ::SDL_WINDOWPOS_UNDEFINED.
+ *
+ * \note The window coordinate origin is the upper left of the display.
+ *
+ * \sa SDL_GetWindowPosition()
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowPosition(SDL_Window * window,
+ int x, int y);
+
+/**
+ * \brief Get the position of a window.
+ *
+ * \param window The window to query.
+ * \param x Pointer to variable for storing the x position, in screen
+ * coordinates. May be NULL.
+ * \param y Pointer to variable for storing the y position, in screen
+ * coordinates. May be NULL.
+ *
+ * \sa SDL_SetWindowPosition()
+ */
+extern DECLSPEC void SDLCALL SDL_GetWindowPosition(SDL_Window * window,
+ int *x, int *y);
+
+/**
+ * \brief Set the size of a window's client area.
+ *
+ * \param window The window to resize.
+ * \param w The width of the window, in screen coordinates. Must be >0.
+ * \param h The height of the window, in screen coordinates. Must be >0.
+ *
+ * \note Fullscreen windows automatically match the size of the display mode,
+ * and you should use SDL_SetWindowDisplayMode() to change their size.
+ *
+ * The window size in screen coordinates may differ from the size in pixels, if
+ * the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a platform with
+ * high-dpi support (e.g. iOS or OS X). Use SDL_GL_GetDrawableSize() or
+ * SDL_GetRendererOutputSize() to get the real client area size in pixels.
+ *
+ * \sa SDL_GetWindowSize()
+ * \sa SDL_SetWindowDisplayMode()
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowSize(SDL_Window * window, int w,
+ int h);
+
+/**
+ * \brief Get the size of a window's client area.
+ *
+ * \param window The window to query.
+ * \param w Pointer to variable for storing the width, in screen
+ * coordinates. May be NULL.
+ * \param h Pointer to variable for storing the height, in screen
+ * coordinates. May be NULL.
+ *
+ * The window size in screen coordinates may differ from the size in pixels, if
+ * the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a platform with
+ * high-dpi support (e.g. iOS or OS X). Use SDL_GL_GetDrawableSize() or
+ * SDL_GetRendererOutputSize() to get the real client area size in pixels.
+ *
+ * \sa SDL_SetWindowSize()
+ */
+extern DECLSPEC void SDLCALL SDL_GetWindowSize(SDL_Window * window, int *w,
+ int *h);
+
+/**
+ * \brief Get the size of a window's borders (decorations) around the client area.
+ *
+ * \param window The window to query.
+ * \param top Pointer to variable for storing the size of the top border. NULL is permitted.
+ * \param left Pointer to variable for storing the size of the left border. NULL is permitted.
+ * \param bottom Pointer to variable for storing the size of the bottom border. NULL is permitted.
+ * \param right Pointer to variable for storing the size of the right border. NULL is permitted.
+ *
+ * \return 0 on success, or -1 if getting this information is not supported.
+ *
+ * \note if this function fails (returns -1), the size values will be
+ * initialized to 0, 0, 0, 0 (if a non-NULL pointer is provided), as
+ * if the window in question was borderless.
+ */
+extern DECLSPEC int SDLCALL SDL_GetWindowBordersSize(SDL_Window * window,
+ int *top, int *left,
+ int *bottom, int *right);
+
+/**
+ * \brief Set the minimum size of a window's client area.
+ *
+ * \param window The window to set a new minimum size.
+ * \param min_w The minimum width of the window, must be >0
+ * \param min_h The minimum height of the window, must be >0
+ *
+ * \note You can't change the minimum size of a fullscreen window, it
+ * automatically matches the size of the display mode.
+ *
+ * \sa SDL_GetWindowMinimumSize()
+ * \sa SDL_SetWindowMaximumSize()
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowMinimumSize(SDL_Window * window,
+ int min_w, int min_h);
+
+/**
+ * \brief Get the minimum size of a window's client area.
+ *
+ * \param window The window to query.
+ * \param w Pointer to variable for storing the minimum width, may be NULL
+ * \param h Pointer to variable for storing the minimum height, may be NULL
+ *
+ * \sa SDL_GetWindowMaximumSize()
+ * \sa SDL_SetWindowMinimumSize()
+ */
+extern DECLSPEC void SDLCALL SDL_GetWindowMinimumSize(SDL_Window * window,
+ int *w, int *h);
+
+/**
+ * \brief Set the maximum size of a window's client area.
+ *
+ * \param window The window to set a new maximum size.
+ * \param max_w The maximum width of the window, must be >0
+ * \param max_h The maximum height of the window, must be >0
+ *
+ * \note You can't change the maximum size of a fullscreen window, it
+ * automatically matches the size of the display mode.
+ *
+ * \sa SDL_GetWindowMaximumSize()
+ * \sa SDL_SetWindowMinimumSize()
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowMaximumSize(SDL_Window * window,
+ int max_w, int max_h);
+
+/**
+ * \brief Get the maximum size of a window's client area.
+ *
+ * \param window The window to query.
+ * \param w Pointer to variable for storing the maximum width, may be NULL
+ * \param h Pointer to variable for storing the maximum height, may be NULL
+ *
+ * \sa SDL_GetWindowMinimumSize()
+ * \sa SDL_SetWindowMaximumSize()
+ */
+extern DECLSPEC void SDLCALL SDL_GetWindowMaximumSize(SDL_Window * window,
+ int *w, int *h);
+
+/**
+ * \brief Set the border state of a window.
+ *
+ * This will add or remove the window's SDL_WINDOW_BORDERLESS flag and
+ * add or remove the border from the actual window. This is a no-op if the
+ * window's border already matches the requested state.
+ *
+ * \param window The window of which to change the border state.
+ * \param bordered SDL_FALSE to remove border, SDL_TRUE to add border.
+ *
+ * \note You can't change the border state of a fullscreen window.
+ *
+ * \sa SDL_GetWindowFlags()
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowBordered(SDL_Window * window,
+ SDL_bool bordered);
+
+/**
+ * \brief Set the user-resizable state of a window.
+ *
+ * This will add or remove the window's SDL_WINDOW_RESIZABLE flag and
+ * allow/disallow user resizing of the window. This is a no-op if the
+ * window's resizable state already matches the requested state.
+ *
+ * \param window The window of which to change the resizable state.
+ * \param resizable SDL_TRUE to allow resizing, SDL_FALSE to disallow.
+ *
+ * \note You can't change the resizable state of a fullscreen window.
+ *
+ * \sa SDL_GetWindowFlags()
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowResizable(SDL_Window * window,
+ SDL_bool resizable);
+
+/**
+ * \brief Show a window.
+ *
+ * \sa SDL_HideWindow()
+ */
+extern DECLSPEC void SDLCALL SDL_ShowWindow(SDL_Window * window);
+
+/**
+ * \brief Hide a window.
+ *
+ * \sa SDL_ShowWindow()
+ */
+extern DECLSPEC void SDLCALL SDL_HideWindow(SDL_Window * window);
+
+/**
+ * \brief Raise a window above other windows and set the input focus.
+ */
+extern DECLSPEC void SDLCALL SDL_RaiseWindow(SDL_Window * window);
+
+/**
+ * \brief Make a window as large as possible.
+ *
+ * \sa SDL_RestoreWindow()
+ */
+extern DECLSPEC void SDLCALL SDL_MaximizeWindow(SDL_Window * window);
+
+/**
+ * \brief Minimize a window to an iconic representation.
+ *
+ * \sa SDL_RestoreWindow()
+ */
+extern DECLSPEC void SDLCALL SDL_MinimizeWindow(SDL_Window * window);
+
+/**
+ * \brief Restore the size and position of a minimized or maximized window.
+ *
+ * \sa SDL_MaximizeWindow()
+ * \sa SDL_MinimizeWindow()
+ */
+extern DECLSPEC void SDLCALL SDL_RestoreWindow(SDL_Window * window);
+
+/**
+ * \brief Set a window's fullscreen state.
+ *
+ * \return 0 on success, or -1 if setting the display mode failed.
+ *
+ * \sa SDL_SetWindowDisplayMode()
+ * \sa SDL_GetWindowDisplayMode()
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowFullscreen(SDL_Window * window,
+ Uint32 flags);
+
+/**
+ * \brief Get the SDL surface associated with the window.
+ *
+ * \return The window's framebuffer surface, or NULL on error.
+ *
+ * A new surface will be created with the optimal format for the window,
+ * if necessary. This surface will be freed when the window is destroyed.
+ *
+ * \note You may not combine this with 3D or the rendering API on this window.
+ *
+ * \sa SDL_UpdateWindowSurface()
+ * \sa SDL_UpdateWindowSurfaceRects()
+ */
+extern DECLSPEC SDL_Surface * SDLCALL SDL_GetWindowSurface(SDL_Window * window);
+
+/**
+ * \brief Copy the window surface to the screen.
+ *
+ * \return 0 on success, or -1 on error.
+ *
+ * \sa SDL_GetWindowSurface()
+ * \sa SDL_UpdateWindowSurfaceRects()
+ */
+extern DECLSPEC int SDLCALL SDL_UpdateWindowSurface(SDL_Window * window);
+
+/**
+ * \brief Copy a number of rectangles on the window surface to the screen.
+ *
+ * \return 0 on success, or -1 on error.
+ *
+ * \sa SDL_GetWindowSurface()
+ * \sa SDL_UpdateWindowSurface()
+ */
+extern DECLSPEC int SDLCALL SDL_UpdateWindowSurfaceRects(SDL_Window * window,
+ const SDL_Rect * rects,
+ int numrects);
+
+/**
+ * \brief Set a window's input grab mode.
+ *
+ * \param window The window for which the input grab mode should be set.
+ * \param grabbed This is SDL_TRUE to grab input, and SDL_FALSE to release input.
+ *
+ * If the caller enables a grab while another window is currently grabbed,
+ * the other window loses its grab in favor of the caller's window.
+ *
+ * \sa SDL_GetWindowGrab()
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowGrab(SDL_Window * window,
+ SDL_bool grabbed);
+
+/**
+ * \brief Get a window's input grab mode.
+ *
+ * \return This returns SDL_TRUE if input is grabbed, and SDL_FALSE otherwise.
+ *
+ * \sa SDL_SetWindowGrab()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_GetWindowGrab(SDL_Window * window);
+
+/**
+ * \brief Get the window that currently has an input grab enabled.
+ *
+ * \return This returns the window if input is grabbed, and NULL otherwise.
+ *
+ * \sa SDL_SetWindowGrab()
+ */
+extern DECLSPEC SDL_Window * SDLCALL SDL_GetGrabbedWindow(void);
+
+/**
+ * \brief Set the brightness (gamma correction) for a window.
+ *
+ * \return 0 on success, or -1 if setting the brightness isn't supported.
+ *
+ * \sa SDL_GetWindowBrightness()
+ * \sa SDL_SetWindowGammaRamp()
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowBrightness(SDL_Window * window, float brightness);
+
+/**
+ * \brief Get the brightness (gamma correction) for a window.
+ *
+ * \return The last brightness value passed to SDL_SetWindowBrightness()
+ *
+ * \sa SDL_SetWindowBrightness()
+ */
+extern DECLSPEC float SDLCALL SDL_GetWindowBrightness(SDL_Window * window);
+
+/**
+ * \brief Set the opacity for a window
+ *
+ * \param window The window which will be made transparent or opaque
+ * \param opacity Opacity (0.0f - transparent, 1.0f - opaque) This will be
+ * clamped internally between 0.0f and 1.0f.
+ *
+ * \return 0 on success, or -1 if setting the opacity isn't supported.
+ *
+ * \sa SDL_GetWindowOpacity()
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowOpacity(SDL_Window * window, float opacity);
+
+/**
+ * \brief Get the opacity of a window.
+ *
+ * If transparency isn't supported on this platform, opacity will be reported
+ * as 1.0f without error.
+ *
+ * \param window The window in question.
+ * \param out_opacity Opacity (0.0f - transparent, 1.0f - opaque)
+ *
+ * \return 0 on success, or -1 on error (invalid window, etc).
+ *
+ * \sa SDL_SetWindowOpacity()
+ */
+extern DECLSPEC int SDLCALL SDL_GetWindowOpacity(SDL_Window * window, float * out_opacity);
+
+/**
+ * \brief Sets the window as a modal for another window (TODO: reconsider this function and/or its name)
+ *
+ * \param modal_window The window that should be modal
+ * \param parent_window The parent window
+ *
+ * \return 0 on success, or -1 otherwise.
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowModalFor(SDL_Window * modal_window, SDL_Window * parent_window);
+
+/**
+ * \brief Explicitly sets input focus to the window.
+ *
+ * You almost certainly want SDL_RaiseWindow() instead of this function. Use
+ * this with caution, as you might give focus to a window that's completely
+ * obscured by other windows.
+ *
+ * \param window The window that should get the input focus
+ *
+ * \return 0 on success, or -1 otherwise.
+ * \sa SDL_RaiseWindow()
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowInputFocus(SDL_Window * window);
+
+/**
+ * \brief Set the gamma ramp for a window.
+ *
+ * \param window The window for which the gamma ramp should be set.
+ * \param red The translation table for the red channel, or NULL.
+ * \param green The translation table for the green channel, or NULL.
+ * \param blue The translation table for the blue channel, or NULL.
+ *
+ * \return 0 on success, or -1 if gamma ramps are unsupported.
+ *
+ * Set the gamma translation table for the red, green, and blue channels
+ * of the video hardware. Each table is an array of 256 16-bit quantities,
+ * representing a mapping between the input and output for that channel.
+ * The input is the index into the array, and the output is the 16-bit
+ * gamma value at that index, scaled to the output color precision.
+ *
+ * \sa SDL_GetWindowGammaRamp()
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowGammaRamp(SDL_Window * window,
+ const Uint16 * red,
+ const Uint16 * green,
+ const Uint16 * blue);
+
+/**
+ * \brief Get the gamma ramp for a window.
+ *
+ * \param window The window from which the gamma ramp should be queried.
+ * \param red A pointer to a 256 element array of 16-bit quantities to hold
+ * the translation table for the red channel, or NULL.
+ * \param green A pointer to a 256 element array of 16-bit quantities to hold
+ * the translation table for the green channel, or NULL.
+ * \param blue A pointer to a 256 element array of 16-bit quantities to hold
+ * the translation table for the blue channel, or NULL.
+ *
+ * \return 0 on success, or -1 if gamma ramps are unsupported.
+ *
+ * \sa SDL_SetWindowGammaRamp()
+ */
+extern DECLSPEC int SDLCALL SDL_GetWindowGammaRamp(SDL_Window * window,
+ Uint16 * red,
+ Uint16 * green,
+ Uint16 * blue);
+
+/**
+ * \brief Possible return values from the SDL_HitTest callback.
+ *
+ * \sa SDL_HitTest
+ */
+typedef enum
+{
+ SDL_HITTEST_NORMAL, /**< Region is normal. No special properties. */
+ SDL_HITTEST_DRAGGABLE, /**< Region can drag entire window. */
+ SDL_HITTEST_RESIZE_TOPLEFT,
+ SDL_HITTEST_RESIZE_TOP,
+ SDL_HITTEST_RESIZE_TOPRIGHT,
+ SDL_HITTEST_RESIZE_RIGHT,
+ SDL_HITTEST_RESIZE_BOTTOMRIGHT,
+ SDL_HITTEST_RESIZE_BOTTOM,
+ SDL_HITTEST_RESIZE_BOTTOMLEFT,
+ SDL_HITTEST_RESIZE_LEFT
+} SDL_HitTestResult;
+
+/**
+ * \brief Callback used for hit-testing.
+ *
+ * \sa SDL_SetWindowHitTest
+ */
+typedef SDL_HitTestResult (SDLCALL *SDL_HitTest)(SDL_Window *win,
+ const SDL_Point *area,
+ void *data);
+
+/**
+ * \brief Provide a callback that decides if a window region has special properties.
+ *
+ * Normally windows are dragged and resized by decorations provided by the
+ * system window manager (a title bar, borders, etc), but for some apps, it
+ * makes sense to drag them from somewhere else inside the window itself; for
+ * example, one might have a borderless window that wants to be draggable
+ * from any part, or simulate its own title bar, etc.
+ *
+ * This function lets the app provide a callback that designates pieces of
+ * a given window as special. This callback is run during event processing
+ * if we need to tell the OS to treat a region of the window specially; the
+ * use of this callback is known as "hit testing."
+ *
+ * Mouse input may not be delivered to your application if it is within
+ * a special area; the OS will often apply that input to moving the window or
+ * resizing the window and not deliver it to the application.
+ *
+ * Specifying NULL for a callback disables hit-testing. Hit-testing is
+ * disabled by default.
+ *
+ * Platforms that don't support this functionality will return -1
+ * unconditionally, even if you're attempting to disable hit-testing.
+ *
+ * Your callback may fire at any time, and its firing does not indicate any
+ * specific behavior (for example, on Windows, this certainly might fire
+ * when the OS is deciding whether to drag your window, but it fires for lots
+ * of other reasons, too, some unrelated to anything you probably care about
+ * _and when the mouse isn't actually at the location it is testing_).
+ * Since this can fire at any time, you should try to keep your callback
+ * efficient, devoid of allocations, etc.
+ *
+ * \param window The window to set hit-testing on.
+ * \param callback The callback to call when doing a hit-test.
+ * \param callback_data An app-defined void pointer passed to the callback.
+ * \return 0 on success, -1 on error (including unsupported).
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowHitTest(SDL_Window * window,
+ SDL_HitTest callback,
+ void *callback_data);
+
+/**
+ * \brief Destroy a window.
+ */
+extern DECLSPEC void SDLCALL SDL_DestroyWindow(SDL_Window * window);
+
+
+/**
+ * \brief Returns whether the screensaver is currently enabled (default off).
+ *
+ * \sa SDL_EnableScreenSaver()
+ * \sa SDL_DisableScreenSaver()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_IsScreenSaverEnabled(void);
+
+/**
+ * \brief Allow the screen to be blanked by a screensaver
+ *
+ * \sa SDL_IsScreenSaverEnabled()
+ * \sa SDL_DisableScreenSaver()
+ */
+extern DECLSPEC void SDLCALL SDL_EnableScreenSaver(void);
+
+/**
+ * \brief Prevent the screen from being blanked by a screensaver
+ *
+ * \sa SDL_IsScreenSaverEnabled()
+ * \sa SDL_EnableScreenSaver()
+ */
+extern DECLSPEC void SDLCALL SDL_DisableScreenSaver(void);
+
+
+/**
+ * \name OpenGL support functions
+ */
+/* @{ */
+
+/**
+ * \brief Dynamically load an OpenGL library.
+ *
+ * \param path The platform dependent OpenGL library name, or NULL to open the
+ * default OpenGL library.
+ *
+ * \return 0 on success, or -1 if the library couldn't be loaded.
+ *
+ * This should be done after initializing the video driver, but before
+ * creating any OpenGL windows. If no OpenGL library is loaded, the default
+ * library will be loaded upon creation of the first OpenGL window.
+ *
+ * \note If you do this, you need to retrieve all of the GL functions used in
+ * your program from the dynamic library using SDL_GL_GetProcAddress().
+ *
+ * \sa SDL_GL_GetProcAddress()
+ * \sa SDL_GL_UnloadLibrary()
+ */
+extern DECLSPEC int SDLCALL SDL_GL_LoadLibrary(const char *path);
+
+/**
+ * \brief Get the address of an OpenGL function.
+ */
+extern DECLSPEC void *SDLCALL SDL_GL_GetProcAddress(const char *proc);
+
+/**
+ * \brief Unload the OpenGL library previously loaded by SDL_GL_LoadLibrary().
+ *
+ * \sa SDL_GL_LoadLibrary()
+ */
+extern DECLSPEC void SDLCALL SDL_GL_UnloadLibrary(void);
+
+/**
+ * \brief Return true if an OpenGL extension is supported for the current
+ * context.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_GL_ExtensionSupported(const char
+ *extension);
+
+/**
+ * \brief Reset all previously set OpenGL context attributes to their default values
+ */
+extern DECLSPEC void SDLCALL SDL_GL_ResetAttributes(void);
+
+/**
+ * \brief Set an OpenGL window attribute before window creation.
+ *
+ * \return 0 on success, or -1 if the attribute could not be set.
+ */
+extern DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value);
+
+/**
+ * \brief Get the actual value for an attribute from the current context.
+ *
+ * \return 0 on success, or -1 if the attribute could not be retrieved.
+ * The integer at \c value will be modified in either case.
+ */
+extern DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int *value);
+
+/**
+ * \brief Create an OpenGL context for use with an OpenGL window, and make it
+ * current.
+ *
+ * \sa SDL_GL_DeleteContext()
+ */
+extern DECLSPEC SDL_GLContext SDLCALL SDL_GL_CreateContext(SDL_Window *
+ window);
+
+/**
+ * \brief Set up an OpenGL context for rendering into an OpenGL window.
+ *
+ * \note The context must have been created with a compatible window.
+ */
+extern DECLSPEC int SDLCALL SDL_GL_MakeCurrent(SDL_Window * window,
+ SDL_GLContext context);
+
+/**
+ * \brief Get the currently active OpenGL window.
+ */
+extern DECLSPEC SDL_Window* SDLCALL SDL_GL_GetCurrentWindow(void);
+
+/**
+ * \brief Get the currently active OpenGL context.
+ */
+extern DECLSPEC SDL_GLContext SDLCALL SDL_GL_GetCurrentContext(void);
+
+/**
+ * \brief Get the size of a window's underlying drawable in pixels (for use
+ * with glViewport).
+ *
+ * \param window Window from which the drawable size should be queried
+ * \param w Pointer to variable for storing the width in pixels, may be NULL
+ * \param h Pointer to variable for storing the height in pixels, may be NULL
+ *
+ * This may differ from SDL_GetWindowSize() if we're rendering to a high-DPI
+ * drawable, i.e. the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a
+ * platform with high-DPI support (Apple calls this "Retina"), and not disabled
+ * by the SDL_HINT_VIDEO_HIGHDPI_DISABLED hint.
+ *
+ * \sa SDL_GetWindowSize()
+ * \sa SDL_CreateWindow()
+ */
+extern DECLSPEC void SDLCALL SDL_GL_GetDrawableSize(SDL_Window * window, int *w,
+ int *h);
+
+/**
+ * \brief Set the swap interval for the current OpenGL context.
+ *
+ * \param interval 0 for immediate updates, 1 for updates synchronized with the
+ * vertical retrace. If the system supports it, you may
+ * specify -1 to allow late swaps to happen immediately
+ * instead of waiting for the next retrace.
+ *
+ * \return 0 on success, or -1 if setting the swap interval is not supported.
+ *
+ * \sa SDL_GL_GetSwapInterval()
+ */
+extern DECLSPEC int SDLCALL SDL_GL_SetSwapInterval(int interval);
+
+/**
+ * \brief Get the swap interval for the current OpenGL context.
+ *
+ * \return 0 if there is no vertical retrace synchronization, 1 if the buffer
+ * swap is synchronized with the vertical retrace, and -1 if late
+ * swaps happen immediately instead of waiting for the next retrace.
+ * If the system can't determine the swap interval, or there isn't a
+ * valid current context, this will return 0 as a safe default.
+ *
+ * \sa SDL_GL_SetSwapInterval()
+ */
+extern DECLSPEC int SDLCALL SDL_GL_GetSwapInterval(void);
+
+/**
+ * \brief Swap the OpenGL buffers for a window, if double-buffering is
+ * supported.
+ */
+extern DECLSPEC void SDLCALL SDL_GL_SwapWindow(SDL_Window * window);
+
+/**
+ * \brief Delete an OpenGL context.
+ *
+ * \sa SDL_GL_CreateContext()
+ */
+extern DECLSPEC void SDLCALL SDL_GL_DeleteContext(SDL_GLContext context);
+
+/* @} *//* OpenGL support functions */
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_video_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL2/SDL_vulkan.h b/src/3rdparty/SDL2/include/SDL2/SDL_vulkan.h
new file mode 100644
index 0000000..f04c21a
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/SDL_vulkan.h
@@ -0,0 +1,273 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 2017, Mark Callow
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_vulkan.h
+ *
+ * Header file for functions to creating Vulkan surfaces on SDL windows.
+ */
+
+#ifndef SDL_vulkan_h_
+#define SDL_vulkan_h_
+
+#include "SDL_video.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Avoid including vulkan.h, don't define VkInstance if it's already included */
+#ifdef VULKAN_H_
+#define NO_SDL_VULKAN_TYPEDEFS
+#endif
+#ifndef NO_SDL_VULKAN_TYPEDEFS
+#define VK_DEFINE_HANDLE(object) typedef struct object##_T* object;
+
+#if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
+#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object;
+#else
+#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
+#endif
+
+VK_DEFINE_HANDLE(VkInstance)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSurfaceKHR)
+
+#endif /* !NO_SDL_VULKAN_TYPEDEFS */
+
+typedef VkInstance SDL_vulkanInstance;
+typedef VkSurfaceKHR SDL_vulkanSurface; /* for compatibility with Tizen */
+
+/**
+ * \name Vulkan support functions
+ *
+ * \note SDL_Vulkan_GetInstanceExtensions & SDL_Vulkan_CreateSurface API
+ * is compatable with Tizen's implementation of Vulkan in SDL.
+ */
+/* @{ */
+
+/**
+ * \brief Dynamically load a Vulkan loader library.
+ *
+ * \param [in] path The platform dependent Vulkan loader library name, or
+ * \c NULL.
+ *
+ * \return \c 0 on success, or \c -1 if the library couldn't be loaded.
+ *
+ * If \a path is NULL SDL will use the value of the environment variable
+ * \c SDL_VULKAN_LIBRARY, if set, otherwise it loads the default Vulkan
+ * loader library.
+ *
+ * This should be called after initializing the video driver, but before
+ * creating any Vulkan windows. If no Vulkan loader library is loaded, the
+ * default library will be loaded upon creation of the first Vulkan window.
+ *
+ * \note It is fairly common for Vulkan applications to link with \a libvulkan
+ * instead of explicitly loading it at run time. This will work with
+ * SDL provided the application links to a dynamic library and both it
+ * and SDL use the same search path.
+ *
+ * \note If you specify a non-NULL \c path, an application should retrieve all
+ * of the Vulkan functions it uses from the dynamic library using
+ * \c SDL_Vulkan_GetVkGetInstanceProcAddr() unless you can guarantee
+ * \c path points to the same vulkan loader library the application
+ * linked to.
+ *
+ * \note On Apple devices, if \a path is NULL, SDL will attempt to find
+ * the vkGetInstanceProcAddr address within all the mach-o images of
+ * the current process. This is because it is fairly common for Vulkan
+ * applications to link with libvulkan (and historically MoltenVK was
+ * provided as a static library). If it is not found then, on macOS, SDL
+ * will attempt to load \c vulkan.framework/vulkan, \c libvulkan.1.dylib,
+ * \c MoltenVK.framework/MoltenVK and \c libMoltenVK.dylib in that order.
+ * On iOS SDL will attempt to load \c libMoltenVK.dylib. Applications
+ * using a dynamic framework or .dylib must ensure it is included in its
+ * application bundle.
+ *
+ * \note On non-Apple devices, application linking with a static libvulkan is
+ * not supported. Either do not link to the Vulkan loader or link to a
+ * dynamic library version.
+ *
+ * \note This function will fail if there are no working Vulkan drivers
+ * installed.
+ *
+ * \sa SDL_Vulkan_GetVkGetInstanceProcAddr()
+ * \sa SDL_Vulkan_UnloadLibrary()
+ */
+extern DECLSPEC int SDLCALL SDL_Vulkan_LoadLibrary(const char *path);
+
+/**
+ * \brief Get the address of the \c vkGetInstanceProcAddr function.
+ *
+ * \note This should be called after either calling SDL_Vulkan_LoadLibrary
+ * or creating an SDL_Window with the SDL_WINDOW_VULKAN flag.
+ */
+extern DECLSPEC void *SDLCALL SDL_Vulkan_GetVkGetInstanceProcAddr(void);
+
+/**
+ * \brief Unload the Vulkan loader library previously loaded by
+ * \c SDL_Vulkan_LoadLibrary().
+ *
+ * \sa SDL_Vulkan_LoadLibrary()
+ */
+extern DECLSPEC void SDLCALL SDL_Vulkan_UnloadLibrary(void);
+
+/**
+ * \brief Get the names of the Vulkan instance extensions needed to create
+ * a surface with \c SDL_Vulkan_CreateSurface().
+ *
+ * \param [in] window Window for which the required Vulkan instance
+ * extensions should be retrieved
+ * \param [in,out] count pointer to an \c unsigned related to the number of
+ * required Vulkan instance extensions
+ * \param [out] names \c NULL or a pointer to an array to be filled with the
+ * required Vulkan instance extensions
+ *
+ * \return \c SDL_TRUE on success, \c SDL_FALSE on error.
+ *
+ * If \a pNames is \c NULL, then the number of required Vulkan instance
+ * extensions is returned in pCount. Otherwise, \a pCount must point to a
+ * variable set to the number of elements in the \a pNames array, and on
+ * return the variable is overwritten with the number of names actually
+ * written to \a pNames. If \a pCount is less than the number of required
+ * extensions, at most \a pCount structures will be written. If \a pCount
+ * is smaller than the number of required extensions, \c SDL_FALSE will be
+ * returned instead of \c SDL_TRUE, to indicate that not all the required
+ * extensions were returned.
+ *
+ * \note The returned list of extensions will contain \c VK_KHR_surface
+ * and zero or more platform specific extensions
+ *
+ * \note The extension names queried here must be enabled when calling
+ * VkCreateInstance, otherwise surface creation will fail.
+ *
+ * \note \c window should have been created with the \c SDL_WINDOW_VULKAN flag.
+ *
+ * \code
+ * unsigned int count;
+ * // get count of required extensions
+ * if(!SDL_Vulkan_GetInstanceExtensions(window, &count, NULL))
+ * handle_error();
+ *
+ * static const char *const additionalExtensions[] =
+ * {
+ * VK_EXT_DEBUG_REPORT_EXTENSION_NAME, // example additional extension
+ * };
+ * size_t additionalExtensionsCount = sizeof(additionalExtensions) / sizeof(additionalExtensions[0]);
+ * size_t extensionCount = count + additionalExtensionsCount;
+ * const char **names = malloc(sizeof(const char *) * extensionCount);
+ * if(!names)
+ * handle_error();
+ *
+ * // get names of required extensions
+ * if(!SDL_Vulkan_GetInstanceExtensions(window, &count, names))
+ * handle_error();
+ *
+ * // copy additional extensions after required extensions
+ * for(size_t i = 0; i < additionalExtensionsCount; i++)
+ * names[i + count] = additionalExtensions[i];
+ *
+ * VkInstanceCreateInfo instanceCreateInfo = {};
+ * instanceCreateInfo.enabledExtensionCount = extensionCount;
+ * instanceCreateInfo.ppEnabledExtensionNames = names;
+ * // fill in rest of instanceCreateInfo
+ *
+ * VkInstance instance;
+ * // create the Vulkan instance
+ * VkResult result = vkCreateInstance(&instanceCreateInfo, NULL, &instance);
+ * free(names);
+ * \endcode
+ *
+ * \sa SDL_Vulkan_CreateSurface()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_Vulkan_GetInstanceExtensions(
+ SDL_Window *window,
+ unsigned int *pCount,
+ const char **pNames);
+
+/**
+ * \brief Create a Vulkan rendering surface for a window.
+ *
+ * \param [in] window SDL_Window to which to attach the rendering surface.
+ * \param [in] instance handle to the Vulkan instance to use.
+ * \param [out] surface pointer to a VkSurfaceKHR handle to receive the
+ * handle of the newly created surface.
+ *
+ * \return \c SDL_TRUE on success, \c SDL_FALSE on error.
+ *
+ * \code
+ * VkInstance instance;
+ * SDL_Window *window;
+ *
+ * // create instance and window
+ *
+ * // create the Vulkan surface
+ * VkSurfaceKHR surface;
+ * if(!SDL_Vulkan_CreateSurface(window, instance, &surface))
+ * handle_error();
+ * \endcode
+ *
+ * \note \a window should have been created with the \c SDL_WINDOW_VULKAN flag.
+ *
+ * \note \a instance should have been created with the extensions returned
+ * by \c SDL_Vulkan_CreateSurface() enabled.
+ *
+ * \sa SDL_Vulkan_GetInstanceExtensions()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_Vulkan_CreateSurface(
+ SDL_Window *window,
+ VkInstance instance,
+ VkSurfaceKHR* surface);
+
+/**
+ * \brief Get the size of a window's underlying drawable in pixels (for use
+ * with setting viewport, scissor & etc).
+ *
+ * \param window SDL_Window from which the drawable size should be queried
+ * \param w Pointer to variable for storing the width in pixels,
+ * may be NULL
+ * \param h Pointer to variable for storing the height in pixels,
+ * may be NULL
+ *
+ * This may differ from SDL_GetWindowSize() if we're rendering to a high-DPI
+ * drawable, i.e. the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a
+ * platform with high-DPI support (Apple calls this "Retina"), and not disabled
+ * by the \c SDL_HINT_VIDEO_HIGHDPI_DISABLED hint.
+ *
+ * \note On macOS high-DPI support must be enabled for an application by
+ * setting NSHighResolutionCapable to true in its Info.plist.
+ *
+ * \sa SDL_GetWindowSize()
+ * \sa SDL_CreateWindow()
+ */
+extern DECLSPEC void SDLCALL SDL_Vulkan_GetDrawableSize(SDL_Window * window,
+ int *w, int *h);
+
+/* @} *//* Vulkan support functions */
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_vulkan_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL2/begin_code.h b/src/3rdparty/SDL2/include/SDL2/begin_code.h
new file mode 100644
index 0000000..6c21062
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/begin_code.h
@@ -0,0 +1,167 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file begin_code.h
+ *
+ * This file sets things up for C dynamic library function definitions,
+ * static inlined functions, and structures aligned at 4-byte alignment.
+ * If you don't like ugly C preprocessor code, don't look at this file. :)
+ */
+
+/* This shouldn't be nested -- included it around code only. */
+#ifdef _begin_code_h
+#error Nested inclusion of begin_code.h
+#endif
+#define _begin_code_h
+
+#ifndef SDL_DEPRECATED
+# if (__GNUC__ >= 4) /* technically, this arrived in gcc 3.1, but oh well. */
+# define SDL_DEPRECATED __attribute__((deprecated))
+# else
+# define SDL_DEPRECATED
+# endif
+#endif
+
+#ifndef SDL_UNUSED
+# ifdef __GNUC__
+# define SDL_UNUSED __attribute__((unused))
+# else
+# define SDL_UNUSED
+# endif
+#endif
+
+/* Some compilers use a special export keyword */
+#ifndef DECLSPEC
+# if defined(__WIN32__) || defined(__WINRT__)
+# ifdef __BORLANDC__
+# ifdef BUILD_SDL
+# define DECLSPEC
+# else
+# define DECLSPEC __declspec(dllimport)
+# endif
+# else
+# define DECLSPEC __declspec(dllexport)
+# endif
+# elif defined(__OS2__)
+# ifdef BUILD_SDL
+# define DECLSPEC __declspec(dllexport)
+# else
+# define DECLSPEC
+# endif
+# else
+# if defined(__GNUC__) && __GNUC__ >= 4
+# define DECLSPEC __attribute__ ((visibility("default")))
+# else
+# define DECLSPEC
+# endif
+# endif
+#endif
+
+/* By default SDL uses the C calling convention */
+#ifndef SDLCALL
+#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
+#define SDLCALL __cdecl
+#elif defined(__OS2__) || defined(__EMX__)
+#define SDLCALL _System
+# if defined (__GNUC__) && !defined(_System)
+# define _System /* for old EMX/GCC compat. */
+# endif
+#else
+#define SDLCALL
+#endif
+#endif /* SDLCALL */
+
+/* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */
+#ifdef __SYMBIAN32__
+#undef DECLSPEC
+#define DECLSPEC
+#endif /* __SYMBIAN32__ */
+
+/* Force structure packing at 4 byte alignment.
+ This is necessary if the header is included in code which has structure
+ packing set to an alternate value, say for loading structures from disk.
+ The packing is reset to the previous value in close_code.h
+ */
+#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
+#ifdef _MSC_VER
+#pragma warning(disable: 4103)
+#endif
+#ifdef __BORLANDC__
+#pragma nopackwarning
+#endif
+#ifdef _M_X64
+/* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */
+#pragma pack(push,8)
+#else
+#pragma pack(push,4)
+#endif
+#endif /* Compiler needs structure packing set */
+
+#ifndef SDL_INLINE
+#if defined(__GNUC__)
+#define SDL_INLINE __inline__
+#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
+ defined(__DMC__) || defined(__SC__) || \
+ defined(__WATCOMC__) || defined(__LCC__) || \
+ defined(__DECC) || defined(__CC_ARM)
+#define SDL_INLINE __inline
+#ifndef __inline__
+#define __inline__ __inline
+#endif
+#else
+#define SDL_INLINE inline
+#ifndef __inline__
+#define __inline__ inline
+#endif
+#endif
+#endif /* SDL_INLINE not defined */
+
+#ifndef SDL_FORCE_INLINE
+#if defined(_MSC_VER)
+#define SDL_FORCE_INLINE __forceinline
+#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
+#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
+#else
+#define SDL_FORCE_INLINE static SDL_INLINE
+#endif
+#endif /* SDL_FORCE_INLINE not defined */
+
+#ifndef SDL_NORETURN
+#if defined(__GNUC__)
+#define SDL_NORETURN __attribute__((noreturn))
+#elif defined(_MSC_VER)
+#define SDL_NORETURN __declspec(noreturn)
+#else
+#define SDL_NORETURN
+#endif
+#endif /* SDL_NORETURN not defined */
+
+/* Apparently this is needed by several Windows compilers */
+#if !defined(__MACH__)
+#ifndef NULL
+#ifdef __cplusplus
+#define NULL 0
+#else
+#define NULL ((void *)0)
+#endif
+#endif /* NULL */
+#endif /* ! Mac OS X - breaks precompiled headers */
diff --git a/src/3rdparty/SDL2/include/SDL2/close_code.h b/src/3rdparty/SDL2/include/SDL2/close_code.h
new file mode 100644
index 0000000..b3b70a4
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL2/close_code.h
@@ -0,0 +1,37 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file close_code.h
+ *
+ * This file reverses the effects of begin_code.h and should be included
+ * after you finish any function and structure declarations in your headers
+ */
+
+#undef _begin_code_h
+
+/* Reset structure packing at previous byte alignment */
+#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
+#ifdef __BORLANDC__
+#pragma nopackwarning
+#endif
+#pragma pack(pop)
+#endif /* Compiler needs structure packing set */
diff --git a/src/3rdparty/SDL2/include/SDL_assert.h b/src/3rdparty/SDL2/include/SDL_assert.h
new file mode 100644
index 0000000..b38f928
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_assert.h
@@ -0,0 +1,291 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_assert_h_
+#define SDL_assert_h_
+
+#include "SDL_config.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef SDL_ASSERT_LEVEL
+#ifdef SDL_DEFAULT_ASSERT_LEVEL
+#define SDL_ASSERT_LEVEL SDL_DEFAULT_ASSERT_LEVEL
+#elif defined(_DEBUG) || defined(DEBUG) || \
+ (defined(__GNUC__) && !defined(__OPTIMIZE__))
+#define SDL_ASSERT_LEVEL 2
+#else
+#define SDL_ASSERT_LEVEL 1
+#endif
+#endif /* SDL_ASSERT_LEVEL */
+
+/*
+These are macros and not first class functions so that the debugger breaks
+on the assertion line and not in some random guts of SDL, and so each
+assert can have unique static variables associated with it.
+*/
+
+#if defined(_MSC_VER)
+/* Don't include intrin.h here because it contains C++ code */
+ extern void __cdecl __debugbreak(void);
+ #define SDL_TriggerBreakpoint() __debugbreak()
+#elif ( (!defined(__NACL__)) && ((defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__))) )
+ #define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "int $3\n\t" )
+#elif defined(__386__) && defined(__WATCOMC__)
+ #define SDL_TriggerBreakpoint() { _asm { int 0x03 } }
+#elif defined(HAVE_SIGNAL_H) && !defined(__WATCOMC__)
+ #include <signal.h>
+ #define SDL_TriggerBreakpoint() raise(SIGTRAP)
+#else
+ /* How do we trigger breakpoints on this platform? */
+ #define SDL_TriggerBreakpoint()
+#endif
+
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 supports __func__ as a standard. */
+# define SDL_FUNCTION __func__
+#elif ((__GNUC__ >= 2) || defined(_MSC_VER) || defined (__WATCOMC__))
+# define SDL_FUNCTION __FUNCTION__
+#else
+# define SDL_FUNCTION "???"
+#endif
+#define SDL_FILE __FILE__
+#define SDL_LINE __LINE__
+
+/*
+sizeof (x) makes the compiler still parse the expression even without
+assertions enabled, so the code is always checked at compile time, but
+doesn't actually generate code for it, so there are no side effects or
+expensive checks at run time, just the constant size of what x WOULD be,
+which presumably gets optimized out as unused.
+This also solves the problem of...
+
+ int somevalue = blah();
+ SDL_assert(somevalue == 1);
+
+...which would cause compiles to complain that somevalue is unused if we
+disable assertions.
+*/
+
+/* "while (0,0)" fools Microsoft's compiler's /W4 warning level into thinking
+ this condition isn't constant. And looks like an owl's face! */
+#ifdef _MSC_VER /* stupid /W4 warnings. */
+#define SDL_NULL_WHILE_LOOP_CONDITION (0,0)
+#else
+#define SDL_NULL_WHILE_LOOP_CONDITION (0)
+#endif
+
+#define SDL_disabled_assert(condition) \
+ do { (void) sizeof ((condition)); } while (SDL_NULL_WHILE_LOOP_CONDITION)
+
+typedef enum
+{
+ SDL_ASSERTION_RETRY, /**< Retry the assert immediately. */
+ SDL_ASSERTION_BREAK, /**< Make the debugger trigger a breakpoint. */
+ SDL_ASSERTION_ABORT, /**< Terminate the program. */
+ SDL_ASSERTION_IGNORE, /**< Ignore the assert. */
+ SDL_ASSERTION_ALWAYS_IGNORE /**< Ignore the assert from now on. */
+} SDL_AssertState;
+
+typedef struct SDL_AssertData
+{
+ int always_ignore;
+ unsigned int trigger_count;
+ const char *condition;
+ const char *filename;
+ int linenum;
+ const char *function;
+ const struct SDL_AssertData *next;
+} SDL_AssertData;
+
+#if (SDL_ASSERT_LEVEL > 0)
+
+/* Never call this directly. Use the SDL_assert* macros. */
+extern DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *,
+ const char *,
+ const char *, int)
+#if defined(__clang__)
+#if __has_feature(attribute_analyzer_noreturn)
+/* this tells Clang's static analysis that we're a custom assert function,
+ and that the analyzer should assume the condition was always true past this
+ SDL_assert test. */
+ __attribute__((analyzer_noreturn))
+#endif
+#endif
+;
+
+/* the do {} while(0) avoids dangling else problems:
+ if (x) SDL_assert(y); else blah();
+ ... without the do/while, the "else" could attach to this macro's "if".
+ We try to handle just the minimum we need here in a macro...the loop,
+ the static vars, and break points. The heavy lifting is handled in
+ SDL_ReportAssertion(), in SDL_assert.c.
+*/
+#define SDL_enabled_assert(condition) \
+ do { \
+ while ( !(condition) ) { \
+ static struct SDL_AssertData sdl_assert_data = { \
+ 0, 0, #condition, 0, 0, 0, 0 \
+ }; \
+ const SDL_AssertState sdl_assert_state = SDL_ReportAssertion(&sdl_assert_data, SDL_FUNCTION, SDL_FILE, SDL_LINE); \
+ if (sdl_assert_state == SDL_ASSERTION_RETRY) { \
+ continue; /* go again. */ \
+ } else if (sdl_assert_state == SDL_ASSERTION_BREAK) { \
+ SDL_TriggerBreakpoint(); \
+ } \
+ break; /* not retrying. */ \
+ } \
+ } while (SDL_NULL_WHILE_LOOP_CONDITION)
+
+#endif /* enabled assertions support code */
+
+/* Enable various levels of assertions. */
+#if SDL_ASSERT_LEVEL == 0 /* assertions disabled */
+# define SDL_assert(condition) SDL_disabled_assert(condition)
+# define SDL_assert_release(condition) SDL_disabled_assert(condition)
+# define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
+#elif SDL_ASSERT_LEVEL == 1 /* release settings. */
+# define SDL_assert(condition) SDL_disabled_assert(condition)
+# define SDL_assert_release(condition) SDL_enabled_assert(condition)
+# define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
+#elif SDL_ASSERT_LEVEL == 2 /* normal settings. */
+# define SDL_assert(condition) SDL_enabled_assert(condition)
+# define SDL_assert_release(condition) SDL_enabled_assert(condition)
+# define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
+#elif SDL_ASSERT_LEVEL == 3 /* paranoid settings. */
+# define SDL_assert(condition) SDL_enabled_assert(condition)
+# define SDL_assert_release(condition) SDL_enabled_assert(condition)
+# define SDL_assert_paranoid(condition) SDL_enabled_assert(condition)
+#else
+# error Unknown assertion level.
+#endif
+
+/* this assertion is never disabled at any level. */
+#define SDL_assert_always(condition) SDL_enabled_assert(condition)
+
+
+typedef SDL_AssertState (SDLCALL *SDL_AssertionHandler)(
+ const SDL_AssertData* data, void* userdata);
+
+/**
+ * \brief Set an application-defined assertion handler.
+ *
+ * This allows an app to show its own assertion UI and/or force the
+ * response to an assertion failure. If the app doesn't provide this, SDL
+ * will try to do the right thing, popping up a system-specific GUI dialog,
+ * and probably minimizing any fullscreen windows.
+ *
+ * This callback may fire from any thread, but it runs wrapped in a mutex, so
+ * it will only fire from one thread at a time.
+ *
+ * Setting the callback to NULL restores SDL's original internal handler.
+ *
+ * This callback is NOT reset to SDL's internal handler upon SDL_Quit()!
+ *
+ * Return SDL_AssertState value of how to handle the assertion failure.
+ *
+ * \param handler Callback function, called when an assertion fails.
+ * \param userdata A pointer passed to the callback as-is.
+ */
+extern DECLSPEC void SDLCALL SDL_SetAssertionHandler(
+ SDL_AssertionHandler handler,
+ void *userdata);
+
+/**
+ * \brief Get the default assertion handler.
+ *
+ * This returns the function pointer that is called by default when an
+ * assertion is triggered. This is an internal function provided by SDL,
+ * that is used for assertions when SDL_SetAssertionHandler() hasn't been
+ * used to provide a different function.
+ *
+ * \return The default SDL_AssertionHandler that is called when an assert triggers.
+ */
+extern DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetDefaultAssertionHandler(void);
+
+/**
+ * \brief Get the current assertion handler.
+ *
+ * This returns the function pointer that is called when an assertion is
+ * triggered. This is either the value last passed to
+ * SDL_SetAssertionHandler(), or if no application-specified function is
+ * set, is equivalent to calling SDL_GetDefaultAssertionHandler().
+ *
+ * \param puserdata Pointer to a void*, which will store the "userdata"
+ * pointer that was passed to SDL_SetAssertionHandler().
+ * This value will always be NULL for the default handler.
+ * If you don't care about this data, it is safe to pass
+ * a NULL pointer to this function to ignore it.
+ * \return The SDL_AssertionHandler that is called when an assert triggers.
+ */
+extern DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetAssertionHandler(void **puserdata);
+
+/**
+ * \brief Get a list of all assertion failures.
+ *
+ * Get all assertions triggered since last call to SDL_ResetAssertionReport(),
+ * or the start of the program.
+ *
+ * The proper way to examine this data looks something like this:
+ *
+ * <code>
+ * const SDL_AssertData *item = SDL_GetAssertionReport();
+ * while (item) {
+ * printf("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\\n",
+ * item->condition, item->function, item->filename,
+ * item->linenum, item->trigger_count,
+ * item->always_ignore ? "yes" : "no");
+ * item = item->next;
+ * }
+ * </code>
+ *
+ * \return List of all assertions.
+ * \sa SDL_ResetAssertionReport
+ */
+extern DECLSPEC const SDL_AssertData * SDLCALL SDL_GetAssertionReport(void);
+
+/**
+ * \brief Reset the list of all assertion failures.
+ *
+ * Reset list of all assertions triggered.
+ *
+ * \sa SDL_GetAssertionReport
+ */
+extern DECLSPEC void SDLCALL SDL_ResetAssertionReport(void);
+
+
+/* these had wrong naming conventions until 2.0.4. Please update your app! */
+#define SDL_assert_state SDL_AssertState
+#define SDL_assert_data SDL_AssertData
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_assert_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_atomic.h b/src/3rdparty/SDL2/include/SDL_atomic.h
new file mode 100644
index 0000000..b228774
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_atomic.h
@@ -0,0 +1,277 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_atomic.h
+ *
+ * Atomic operations.
+ *
+ * IMPORTANT:
+ * If you are not an expert in concurrent lockless programming, you should
+ * only be using the atomic lock and reference counting functions in this
+ * file. In all other cases you should be protecting your data structures
+ * with full mutexes.
+ *
+ * The list of "safe" functions to use are:
+ * SDL_AtomicLock()
+ * SDL_AtomicUnlock()
+ * SDL_AtomicIncRef()
+ * SDL_AtomicDecRef()
+ *
+ * Seriously, here be dragons!
+ * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ *
+ * You can find out a little more about lockless programming and the
+ * subtle issues that can arise here:
+ * http://msdn.microsoft.com/en-us/library/ee418650%28v=vs.85%29.aspx
+ *
+ * There's also lots of good information here:
+ * http://www.1024cores.net/home/lock-free-algorithms
+ * http://preshing.com/
+ *
+ * These operations may or may not actually be implemented using
+ * processor specific atomic operations. When possible they are
+ * implemented as true processor specific atomic operations. When that
+ * is not possible the are implemented using locks that *do* use the
+ * available atomic operations.
+ *
+ * All of the atomic operations that modify memory are full memory barriers.
+ */
+
+#ifndef SDL_atomic_h_
+#define SDL_atomic_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_platform.h"
+
+#include "begin_code.h"
+
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \name SDL AtomicLock
+ *
+ * The atomic locks are efficient spinlocks using CPU instructions,
+ * but are vulnerable to starvation and can spin forever if a thread
+ * holding a lock has been terminated. For this reason you should
+ * minimize the code executed inside an atomic lock and never do
+ * expensive things like API or system calls while holding them.
+ *
+ * The atomic locks are not safe to lock recursively.
+ *
+ * Porting Note:
+ * The spin lock functions and type are required and can not be
+ * emulated because they are used in the atomic emulation code.
+ */
+/* @{ */
+
+typedef int SDL_SpinLock;
+
+/**
+ * \brief Try to lock a spin lock by setting it to a non-zero value.
+ *
+ * \param lock Points to the lock.
+ *
+ * \return SDL_TRUE if the lock succeeded, SDL_FALSE if the lock is already held.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTryLock(SDL_SpinLock *lock);
+
+/**
+ * \brief Lock a spin lock by setting it to a non-zero value.
+ *
+ * \param lock Points to the lock.
+ */
+extern DECLSPEC void SDLCALL SDL_AtomicLock(SDL_SpinLock *lock);
+
+/**
+ * \brief Unlock a spin lock by setting it to 0. Always returns immediately
+ *
+ * \param lock Points to the lock.
+ */
+extern DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock);
+
+/* @} *//* SDL AtomicLock */
+
+
+/**
+ * The compiler barrier prevents the compiler from reordering
+ * reads and writes to globally visible variables across the call.
+ */
+#if defined(_MSC_VER) && (_MSC_VER > 1200) && !defined(__clang__)
+void _ReadWriteBarrier(void);
+#pragma intrinsic(_ReadWriteBarrier)
+#define SDL_CompilerBarrier() _ReadWriteBarrier()
+#elif (defined(__GNUC__) && !defined(__EMSCRIPTEN__)) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5120))
+/* This is correct for all CPUs when using GCC or Solaris Studio 12.1+. */
+#define SDL_CompilerBarrier() __asm__ __volatile__ ("" : : : "memory")
+#elif defined(__WATCOMC__)
+extern _inline void SDL_CompilerBarrier (void);
+#pragma aux SDL_CompilerBarrier = "" parm [] modify exact [];
+#else
+#define SDL_CompilerBarrier() \
+{ SDL_SpinLock _tmp = 0; SDL_AtomicLock(&_tmp); SDL_AtomicUnlock(&_tmp); }
+#endif
+
+/**
+ * Memory barriers are designed to prevent reads and writes from being
+ * reordered by the compiler and being seen out of order on multi-core CPUs.
+ *
+ * A typical pattern would be for thread A to write some data and a flag,
+ * and for thread B to read the flag and get the data. In this case you
+ * would insert a release barrier between writing the data and the flag,
+ * guaranteeing that the data write completes no later than the flag is
+ * written, and you would insert an acquire barrier between reading the
+ * flag and reading the data, to ensure that all the reads associated
+ * with the flag have completed.
+ *
+ * In this pattern you should always see a release barrier paired with
+ * an acquire barrier and you should gate the data reads/writes with a
+ * single flag variable.
+ *
+ * For more information on these semantics, take a look at the blog post:
+ * http://preshing.com/20120913/acquire-and-release-semantics
+ */
+extern DECLSPEC void SDLCALL SDL_MemoryBarrierReleaseFunction(void);
+extern DECLSPEC void SDLCALL SDL_MemoryBarrierAcquireFunction(void);
+
+#if defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
+#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("lwsync" : : : "memory")
+#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("lwsync" : : : "memory")
+#elif defined(__GNUC__) && defined(__aarch64__)
+#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("dmb ish" : : : "memory")
+#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("dmb ish" : : : "memory")
+#elif defined(__GNUC__) && defined(__arm__)
+#if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__)
+#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("dmb ish" : : : "memory")
+#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("dmb ish" : : : "memory")
+#elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6T2__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_5TE__)
+#ifdef __thumb__
+/* The mcr instruction isn't available in thumb mode, use real functions */
+#define SDL_MemoryBarrierRelease() SDL_MemoryBarrierReleaseFunction()
+#define SDL_MemoryBarrierAcquire() SDL_MemoryBarrierAcquireFunction()
+#else
+#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" : : "r"(0) : "memory")
+#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" : : "r"(0) : "memory")
+#endif /* __thumb__ */
+#else
+#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("" : : : "memory")
+#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("" : : : "memory")
+#endif /* __GNUC__ && __arm__ */
+#else
+#if (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5120))
+/* This is correct for all CPUs on Solaris when using Solaris Studio 12.1+. */
+#include <mbarrier.h>
+#define SDL_MemoryBarrierRelease() __machine_rel_barrier()
+#define SDL_MemoryBarrierAcquire() __machine_acq_barrier()
+#else
+/* This is correct for the x86 and x64 CPUs, and we'll expand this over time. */
+#define SDL_MemoryBarrierRelease() SDL_CompilerBarrier()
+#define SDL_MemoryBarrierAcquire() SDL_CompilerBarrier()
+#endif
+#endif
+
+/**
+ * \brief A type representing an atomic integer value. It is a struct
+ * so people don't accidentally use numeric operations on it.
+ */
+typedef struct { int value; } SDL_atomic_t;
+
+/**
+ * \brief Set an atomic variable to a new value if it is currently an old value.
+ *
+ * \return SDL_TRUE if the atomic variable was set, SDL_FALSE otherwise.
+ *
+ * \note If you don't know what this function is for, you shouldn't use it!
+*/
+extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval);
+
+/**
+ * \brief Set an atomic variable to a value.
+ *
+ * \return The previous value of the atomic variable.
+ */
+extern DECLSPEC int SDLCALL SDL_AtomicSet(SDL_atomic_t *a, int v);
+
+/**
+ * \brief Get the value of an atomic variable
+ */
+extern DECLSPEC int SDLCALL SDL_AtomicGet(SDL_atomic_t *a);
+
+/**
+ * \brief Add to an atomic variable.
+ *
+ * \return The previous value of the atomic variable.
+ *
+ * \note This same style can be used for any number operation
+ */
+extern DECLSPEC int SDLCALL SDL_AtomicAdd(SDL_atomic_t *a, int v);
+
+/**
+ * \brief Increment an atomic variable used as a reference count.
+ */
+#ifndef SDL_AtomicIncRef
+#define SDL_AtomicIncRef(a) SDL_AtomicAdd(a, 1)
+#endif
+
+/**
+ * \brief Decrement an atomic variable used as a reference count.
+ *
+ * \return SDL_TRUE if the variable reached zero after decrementing,
+ * SDL_FALSE otherwise
+ */
+#ifndef SDL_AtomicDecRef
+#define SDL_AtomicDecRef(a) (SDL_AtomicAdd(a, -1) == 1)
+#endif
+
+/**
+ * \brief Set a pointer to a new value if it is currently an old value.
+ *
+ * \return SDL_TRUE if the pointer was set, SDL_FALSE otherwise.
+ *
+ * \note If you don't know what this function is for, you shouldn't use it!
+*/
+extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr(void **a, void *oldval, void *newval);
+
+/**
+ * \brief Set a pointer to a value atomically.
+ *
+ * \return The previous value of the pointer.
+ */
+extern DECLSPEC void* SDLCALL SDL_AtomicSetPtr(void **a, void* v);
+
+/**
+ * \brief Get the value of a pointer atomically.
+ */
+extern DECLSPEC void* SDLCALL SDL_AtomicGetPtr(void **a);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+
+#include "close_code.h"
+
+#endif /* SDL_atomic_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_audio.h b/src/3rdparty/SDL2/include/SDL_audio.h
new file mode 100644
index 0000000..d6ea689
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_audio.h
@@ -0,0 +1,825 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_audio.h
+ *
+ * Access to the raw audio mixing buffer for the SDL library.
+ */
+
+#ifndef SDL_audio_h_
+#define SDL_audio_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_endian.h"
+#include "SDL_mutex.h"
+#include "SDL_thread.h"
+#include "SDL_rwops.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Audio format flags.
+ *
+ * These are what the 16 bits in SDL_AudioFormat currently mean...
+ * (Unspecified bits are always zero).
+ *
+ * \verbatim
+ ++-----------------------sample is signed if set
+ ||
+ || ++-----------sample is bigendian if set
+ || ||
+ || || ++---sample is float if set
+ || || ||
+ || || || +---sample bit size---+
+ || || || | |
+ 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
+ \endverbatim
+ *
+ * There are macros in SDL 2.0 and later to query these bits.
+ */
+typedef Uint16 SDL_AudioFormat;
+
+/**
+ * \name Audio flags
+ */
+/* @{ */
+
+#define SDL_AUDIO_MASK_BITSIZE (0xFF)
+#define SDL_AUDIO_MASK_DATATYPE (1<<8)
+#define SDL_AUDIO_MASK_ENDIAN (1<<12)
+#define SDL_AUDIO_MASK_SIGNED (1<<15)
+#define SDL_AUDIO_BITSIZE(x) (x & SDL_AUDIO_MASK_BITSIZE)
+#define SDL_AUDIO_ISFLOAT(x) (x & SDL_AUDIO_MASK_DATATYPE)
+#define SDL_AUDIO_ISBIGENDIAN(x) (x & SDL_AUDIO_MASK_ENDIAN)
+#define SDL_AUDIO_ISSIGNED(x) (x & SDL_AUDIO_MASK_SIGNED)
+#define SDL_AUDIO_ISINT(x) (!SDL_AUDIO_ISFLOAT(x))
+#define SDL_AUDIO_ISLITTLEENDIAN(x) (!SDL_AUDIO_ISBIGENDIAN(x))
+#define SDL_AUDIO_ISUNSIGNED(x) (!SDL_AUDIO_ISSIGNED(x))
+
+/**
+ * \name Audio format flags
+ *
+ * Defaults to LSB byte order.
+ */
+/* @{ */
+#define AUDIO_U8 0x0008 /**< Unsigned 8-bit samples */
+#define AUDIO_S8 0x8008 /**< Signed 8-bit samples */
+#define AUDIO_U16LSB 0x0010 /**< Unsigned 16-bit samples */
+#define AUDIO_S16LSB 0x8010 /**< Signed 16-bit samples */
+#define AUDIO_U16MSB 0x1010 /**< As above, but big-endian byte order */
+#define AUDIO_S16MSB 0x9010 /**< As above, but big-endian byte order */
+#define AUDIO_U16 AUDIO_U16LSB
+#define AUDIO_S16 AUDIO_S16LSB
+/* @} */
+
+/**
+ * \name int32 support
+ */
+/* @{ */
+#define AUDIO_S32LSB 0x8020 /**< 32-bit integer samples */
+#define AUDIO_S32MSB 0x9020 /**< As above, but big-endian byte order */
+#define AUDIO_S32 AUDIO_S32LSB
+/* @} */
+
+/**
+ * \name float32 support
+ */
+/* @{ */
+#define AUDIO_F32LSB 0x8120 /**< 32-bit floating point samples */
+#define AUDIO_F32MSB 0x9120 /**< As above, but big-endian byte order */
+#define AUDIO_F32 AUDIO_F32LSB
+/* @} */
+
+/**
+ * \name Native audio byte ordering
+ */
+/* @{ */
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+#define AUDIO_U16SYS AUDIO_U16LSB
+#define AUDIO_S16SYS AUDIO_S16LSB
+#define AUDIO_S32SYS AUDIO_S32LSB
+#define AUDIO_F32SYS AUDIO_F32LSB
+#else
+#define AUDIO_U16SYS AUDIO_U16MSB
+#define AUDIO_S16SYS AUDIO_S16MSB
+#define AUDIO_S32SYS AUDIO_S32MSB
+#define AUDIO_F32SYS AUDIO_F32MSB
+#endif
+/* @} */
+
+/**
+ * \name Allow change flags
+ *
+ * Which audio format changes are allowed when opening a device.
+ */
+/* @{ */
+#define SDL_AUDIO_ALLOW_FREQUENCY_CHANGE 0x00000001
+#define SDL_AUDIO_ALLOW_FORMAT_CHANGE 0x00000002
+#define SDL_AUDIO_ALLOW_CHANNELS_CHANGE 0x00000004
+#define SDL_AUDIO_ALLOW_ANY_CHANGE (SDL_AUDIO_ALLOW_FREQUENCY_CHANGE|SDL_AUDIO_ALLOW_FORMAT_CHANGE|SDL_AUDIO_ALLOW_CHANNELS_CHANGE)
+/* @} */
+
+/* @} *//* Audio flags */
+
+/**
+ * This function is called when the audio device needs more data.
+ *
+ * \param userdata An application-specific parameter saved in
+ * the SDL_AudioSpec structure
+ * \param stream A pointer to the audio data buffer.
+ * \param len The length of that buffer in bytes.
+ *
+ * Once the callback returns, the buffer will no longer be valid.
+ * Stereo samples are stored in a LRLRLR ordering.
+ *
+ * You can choose to avoid callbacks and use SDL_QueueAudio() instead, if
+ * you like. Just open your audio device with a NULL callback.
+ */
+typedef void (SDLCALL * SDL_AudioCallback) (void *userdata, Uint8 * stream,
+ int len);
+
+/**
+ * The calculated values in this structure are calculated by SDL_OpenAudio().
+ *
+ * For multi-channel audio, the default SDL channel mapping is:
+ * 2: FL FR (stereo)
+ * 3: FL FR LFE (2.1 surround)
+ * 4: FL FR BL BR (quad)
+ * 5: FL FR FC BL BR (quad + center)
+ * 6: FL FR FC LFE SL SR (5.1 surround - last two can also be BL BR)
+ * 7: FL FR FC LFE BC SL SR (6.1 surround)
+ * 8: FL FR FC LFE BL BR SL SR (7.1 surround)
+ */
+typedef struct SDL_AudioSpec
+{
+ int freq; /**< DSP frequency -- samples per second */
+ SDL_AudioFormat format; /**< Audio data format */
+ Uint8 channels; /**< Number of channels: 1 mono, 2 stereo */
+ Uint8 silence; /**< Audio buffer silence value (calculated) */
+ Uint16 samples; /**< Audio buffer size in sample FRAMES (total samples divided by channel count) */
+ Uint16 padding; /**< Necessary for some compile environments */
+ Uint32 size; /**< Audio buffer size in bytes (calculated) */
+ SDL_AudioCallback callback; /**< Callback that feeds the audio device (NULL to use SDL_QueueAudio()). */
+ void *userdata; /**< Userdata passed to callback (ignored for NULL callbacks). */
+} SDL_AudioSpec;
+
+
+struct SDL_AudioCVT;
+typedef void (SDLCALL * SDL_AudioFilter) (struct SDL_AudioCVT * cvt,
+ SDL_AudioFormat format);
+
+/**
+ * \brief Upper limit of filters in SDL_AudioCVT
+ *
+ * The maximum number of SDL_AudioFilter functions in SDL_AudioCVT is
+ * currently limited to 9. The SDL_AudioCVT.filters array has 10 pointers,
+ * one of which is the terminating NULL pointer.
+ */
+#define SDL_AUDIOCVT_MAX_FILTERS 9
+
+/**
+ * \struct SDL_AudioCVT
+ * \brief A structure to hold a set of audio conversion filters and buffers.
+ *
+ * Note that various parts of the conversion pipeline can take advantage
+ * of SIMD operations (like SSE2, for example). SDL_AudioCVT doesn't require
+ * you to pass it aligned data, but can possibly run much faster if you
+ * set both its (buf) field to a pointer that is aligned to 16 bytes, and its
+ * (len) field to something that's a multiple of 16, if possible.
+ */
+#ifdef __GNUC__
+/* This structure is 84 bytes on 32-bit architectures, make sure GCC doesn't
+ pad it out to 88 bytes to guarantee ABI compatibility between compilers.
+ vvv
+ The next time we rev the ABI, make sure to size the ints and add padding.
+*/
+#define SDL_AUDIOCVT_PACKED __attribute__((packed))
+#else
+#define SDL_AUDIOCVT_PACKED
+#endif
+/* */
+typedef struct SDL_AudioCVT
+{
+ int needed; /**< Set to 1 if conversion possible */
+ SDL_AudioFormat src_format; /**< Source audio format */
+ SDL_AudioFormat dst_format; /**< Target audio format */
+ double rate_incr; /**< Rate conversion increment */
+ Uint8 *buf; /**< Buffer to hold entire audio data */
+ int len; /**< Length of original audio buffer */
+ int len_cvt; /**< Length of converted audio buffer */
+ int len_mult; /**< buffer must be len*len_mult big */
+ double len_ratio; /**< Given len, final size is len*len_ratio */
+ SDL_AudioFilter filters[SDL_AUDIOCVT_MAX_FILTERS + 1]; /**< NULL-terminated list of filter functions */
+ int filter_index; /**< Current audio conversion function */
+} SDL_AUDIOCVT_PACKED SDL_AudioCVT;
+
+
+/* Function prototypes */
+
+/**
+ * \name Driver discovery functions
+ *
+ * These functions return the list of built in audio drivers, in the
+ * order that they are normally initialized by default.
+ */
+/* @{ */
+extern DECLSPEC int SDLCALL SDL_GetNumAudioDrivers(void);
+extern DECLSPEC const char *SDLCALL SDL_GetAudioDriver(int index);
+/* @} */
+
+/**
+ * \name Initialization and cleanup
+ *
+ * \internal These functions are used internally, and should not be used unless
+ * you have a specific need to specify the audio driver you want to
+ * use. You should normally use SDL_Init() or SDL_InitSubSystem().
+ */
+/* @{ */
+extern DECLSPEC int SDLCALL SDL_AudioInit(const char *driver_name);
+extern DECLSPEC void SDLCALL SDL_AudioQuit(void);
+/* @} */
+
+/**
+ * This function returns the name of the current audio driver, or NULL
+ * if no driver has been initialized.
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetCurrentAudioDriver(void);
+
+/**
+ * This function opens the audio device with the desired parameters, and
+ * returns 0 if successful, placing the actual hardware parameters in the
+ * structure pointed to by \c obtained. If \c obtained is NULL, the audio
+ * data passed to the callback function will be guaranteed to be in the
+ * requested format, and will be automatically converted to the hardware
+ * audio format if necessary. This function returns -1 if it failed
+ * to open the audio device, or couldn't set up the audio thread.
+ *
+ * When filling in the desired audio spec structure,
+ * - \c desired->freq should be the desired audio frequency in samples-per-
+ * second.
+ * - \c desired->format should be the desired audio format.
+ * - \c desired->samples is the desired size of the audio buffer, in
+ * samples. This number should be a power of two, and may be adjusted by
+ * the audio driver to a value more suitable for the hardware. Good values
+ * seem to range between 512 and 8096 inclusive, depending on the
+ * application and CPU speed. Smaller values yield faster response time,
+ * but can lead to underflow if the application is doing heavy processing
+ * and cannot fill the audio buffer in time. A stereo sample consists of
+ * both right and left channels in LR ordering.
+ * Note that the number of samples is directly related to time by the
+ * following formula: \code ms = (samples*1000)/freq \endcode
+ * - \c desired->size is the size in bytes of the audio buffer, and is
+ * calculated by SDL_OpenAudio().
+ * - \c desired->silence is the value used to set the buffer to silence,
+ * and is calculated by SDL_OpenAudio().
+ * - \c desired->callback should be set to a function that will be called
+ * when the audio device is ready for more data. It is passed a pointer
+ * to the audio buffer, and the length in bytes of the audio buffer.
+ * This function usually runs in a separate thread, and so you should
+ * protect data structures that it accesses by calling SDL_LockAudio()
+ * and SDL_UnlockAudio() in your code. Alternately, you may pass a NULL
+ * pointer here, and call SDL_QueueAudio() with some frequency, to queue
+ * more audio samples to be played (or for capture devices, call
+ * SDL_DequeueAudio() with some frequency, to obtain audio samples).
+ * - \c desired->userdata is passed as the first parameter to your callback
+ * function. If you passed a NULL callback, this value is ignored.
+ *
+ * The audio device starts out playing silence when it's opened, and should
+ * be enabled for playing by calling \c SDL_PauseAudio(0) when you are ready
+ * for your audio callback function to be called. Since the audio driver
+ * may modify the requested size of the audio buffer, you should allocate
+ * any local mixing buffers after you open the audio device.
+ */
+extern DECLSPEC int SDLCALL SDL_OpenAudio(SDL_AudioSpec * desired,
+ SDL_AudioSpec * obtained);
+
+/**
+ * SDL Audio Device IDs.
+ *
+ * A successful call to SDL_OpenAudio() is always device id 1, and legacy
+ * SDL audio APIs assume you want this device ID. SDL_OpenAudioDevice() calls
+ * always returns devices >= 2 on success. The legacy calls are good both
+ * for backwards compatibility and when you don't care about multiple,
+ * specific, or capture devices.
+ */
+typedef Uint32 SDL_AudioDeviceID;
+
+/**
+ * Get the number of available devices exposed by the current driver.
+ * Only valid after a successfully initializing the audio subsystem.
+ * Returns -1 if an explicit list of devices can't be determined; this is
+ * not an error. For example, if SDL is set up to talk to a remote audio
+ * server, it can't list every one available on the Internet, but it will
+ * still allow a specific host to be specified to SDL_OpenAudioDevice().
+ *
+ * In many common cases, when this function returns a value <= 0, it can still
+ * successfully open the default device (NULL for first argument of
+ * SDL_OpenAudioDevice()).
+ */
+extern DECLSPEC int SDLCALL SDL_GetNumAudioDevices(int iscapture);
+
+/**
+ * Get the human-readable name of a specific audio device.
+ * Must be a value between 0 and (number of audio devices-1).
+ * Only valid after a successfully initializing the audio subsystem.
+ * The values returned by this function reflect the latest call to
+ * SDL_GetNumAudioDevices(); recall that function to redetect available
+ * hardware.
+ *
+ * The string returned by this function is UTF-8 encoded, read-only, and
+ * managed internally. You are not to free it. If you need to keep the
+ * string for any length of time, you should make your own copy of it, as it
+ * will be invalid next time any of several other SDL functions is called.
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetAudioDeviceName(int index,
+ int iscapture);
+
+
+/**
+ * Open a specific audio device. Passing in a device name of NULL requests
+ * the most reasonable default (and is equivalent to calling SDL_OpenAudio()).
+ *
+ * The device name is a UTF-8 string reported by SDL_GetAudioDeviceName(), but
+ * some drivers allow arbitrary and driver-specific strings, such as a
+ * hostname/IP address for a remote audio server, or a filename in the
+ * diskaudio driver.
+ *
+ * \return 0 on error, a valid device ID that is >= 2 on success.
+ *
+ * SDL_OpenAudio(), unlike this function, always acts on device ID 1.
+ */
+extern DECLSPEC SDL_AudioDeviceID SDLCALL SDL_OpenAudioDevice(const char
+ *device,
+ int iscapture,
+ const
+ SDL_AudioSpec *
+ desired,
+ SDL_AudioSpec *
+ obtained,
+ int
+ allowed_changes);
+
+
+
+/**
+ * \name Audio state
+ *
+ * Get the current audio state.
+ */
+/* @{ */
+typedef enum
+{
+ SDL_AUDIO_STOPPED = 0,
+ SDL_AUDIO_PLAYING,
+ SDL_AUDIO_PAUSED
+} SDL_AudioStatus;
+extern DECLSPEC SDL_AudioStatus SDLCALL SDL_GetAudioStatus(void);
+
+extern DECLSPEC SDL_AudioStatus SDLCALL
+SDL_GetAudioDeviceStatus(SDL_AudioDeviceID dev);
+/* @} *//* Audio State */
+
+/**
+ * \name Pause audio functions
+ *
+ * These functions pause and unpause the audio callback processing.
+ * They should be called with a parameter of 0 after opening the audio
+ * device to start playing sound. This is so you can safely initialize
+ * data for your callback function after opening the audio device.
+ * Silence will be written to the audio device during the pause.
+ */
+/* @{ */
+extern DECLSPEC void SDLCALL SDL_PauseAudio(int pause_on);
+extern DECLSPEC void SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev,
+ int pause_on);
+/* @} *//* Pause audio functions */
+
+/**
+ * This function loads a WAVE from the data source, automatically freeing
+ * that source if \c freesrc is non-zero. For example, to load a WAVE file,
+ * you could do:
+ * \code
+ * SDL_LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, ...);
+ * \endcode
+ *
+ * If this function succeeds, it returns the given SDL_AudioSpec,
+ * filled with the audio data format of the wave data, and sets
+ * \c *audio_buf to a malloc()'d buffer containing the audio data,
+ * and sets \c *audio_len to the length of that audio buffer, in bytes.
+ * You need to free the audio buffer with SDL_FreeWAV() when you are
+ * done with it.
+ *
+ * This function returns NULL and sets the SDL error message if the
+ * wave file cannot be opened, uses an unknown data format, or is
+ * corrupt. Currently raw and MS-ADPCM WAVE files are supported.
+ */
+extern DECLSPEC SDL_AudioSpec *SDLCALL SDL_LoadWAV_RW(SDL_RWops * src,
+ int freesrc,
+ SDL_AudioSpec * spec,
+ Uint8 ** audio_buf,
+ Uint32 * audio_len);
+
+/**
+ * Loads a WAV from a file.
+ * Compatibility convenience function.
+ */
+#define SDL_LoadWAV(file, spec, audio_buf, audio_len) \
+ SDL_LoadWAV_RW(SDL_RWFromFile(file, "rb"),1, spec,audio_buf,audio_len)
+
+/**
+ * This function frees data previously allocated with SDL_LoadWAV_RW()
+ */
+extern DECLSPEC void SDLCALL SDL_FreeWAV(Uint8 * audio_buf);
+
+/**
+ * This function takes a source format and rate and a destination format
+ * and rate, and initializes the \c cvt structure with information needed
+ * by SDL_ConvertAudio() to convert a buffer of audio data from one format
+ * to the other. An unsupported format causes an error and -1 will be returned.
+ *
+ * \return 0 if no conversion is needed, 1 if the audio filter is set up,
+ * or -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_BuildAudioCVT(SDL_AudioCVT * cvt,
+ SDL_AudioFormat src_format,
+ Uint8 src_channels,
+ int src_rate,
+ SDL_AudioFormat dst_format,
+ Uint8 dst_channels,
+ int dst_rate);
+
+/**
+ * Once you have initialized the \c cvt structure using SDL_BuildAudioCVT(),
+ * created an audio buffer \c cvt->buf, and filled it with \c cvt->len bytes of
+ * audio data in the source format, this function will convert it in-place
+ * to the desired format.
+ *
+ * The data conversion may expand the size of the audio data, so the buffer
+ * \c cvt->buf should be allocated after the \c cvt structure is initialized by
+ * SDL_BuildAudioCVT(), and should be \c cvt->len*cvt->len_mult bytes long.
+ *
+ * \return 0 on success or -1 if \c cvt->buf is NULL.
+ */
+extern DECLSPEC int SDLCALL SDL_ConvertAudio(SDL_AudioCVT * cvt);
+
+/* SDL_AudioStream is a new audio conversion interface.
+ The benefits vs SDL_AudioCVT:
+ - it can handle resampling data in chunks without generating
+ artifacts, when it doesn't have the complete buffer available.
+ - it can handle incoming data in any variable size.
+ - You push data as you have it, and pull it when you need it
+ */
+/* this is opaque to the outside world. */
+struct _SDL_AudioStream;
+typedef struct _SDL_AudioStream SDL_AudioStream;
+
+/**
+ * Create a new audio stream
+ *
+ * \param src_format The format of the source audio
+ * \param src_channels The number of channels of the source audio
+ * \param src_rate The sampling rate of the source audio
+ * \param dst_format The format of the desired audio output
+ * \param dst_channels The number of channels of the desired audio output
+ * \param dst_rate The sampling rate of the desired audio output
+ * \return 0 on success, or -1 on error.
+ *
+ * \sa SDL_AudioStreamPut
+ * \sa SDL_AudioStreamGet
+ * \sa SDL_AudioStreamAvailable
+ * \sa SDL_AudioStreamFlush
+ * \sa SDL_AudioStreamClear
+ * \sa SDL_FreeAudioStream
+ */
+extern DECLSPEC SDL_AudioStream * SDLCALL SDL_NewAudioStream(const SDL_AudioFormat src_format,
+ const Uint8 src_channels,
+ const int src_rate,
+ const SDL_AudioFormat dst_format,
+ const Uint8 dst_channels,
+ const int dst_rate);
+
+/**
+ * Add data to be converted/resampled to the stream
+ *
+ * \param stream The stream the audio data is being added to
+ * \param buf A pointer to the audio data to add
+ * \param len The number of bytes to write to the stream
+ * \return 0 on success, or -1 on error.
+ *
+ * \sa SDL_NewAudioStream
+ * \sa SDL_AudioStreamGet
+ * \sa SDL_AudioStreamAvailable
+ * \sa SDL_AudioStreamFlush
+ * \sa SDL_AudioStreamClear
+ * \sa SDL_FreeAudioStream
+ */
+extern DECLSPEC int SDLCALL SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len);
+
+/**
+ * Get converted/resampled data from the stream
+ *
+ * \param stream The stream the audio is being requested from
+ * \param buf A buffer to fill with audio data
+ * \param len The maximum number of bytes to fill
+ * \return The number of bytes read from the stream, or -1 on error
+ *
+ * \sa SDL_NewAudioStream
+ * \sa SDL_AudioStreamPut
+ * \sa SDL_AudioStreamAvailable
+ * \sa SDL_AudioStreamFlush
+ * \sa SDL_AudioStreamClear
+ * \sa SDL_FreeAudioStream
+ */
+extern DECLSPEC int SDLCALL SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len);
+
+/**
+ * Get the number of converted/resampled bytes available. The stream may be
+ * buffering data behind the scenes until it has enough to resample
+ * correctly, so this number might be lower than what you expect, or even
+ * be zero. Add more data or flush the stream if you need the data now.
+ *
+ * \sa SDL_NewAudioStream
+ * \sa SDL_AudioStreamPut
+ * \sa SDL_AudioStreamGet
+ * \sa SDL_AudioStreamFlush
+ * \sa SDL_AudioStreamClear
+ * \sa SDL_FreeAudioStream
+ */
+extern DECLSPEC int SDLCALL SDL_AudioStreamAvailable(SDL_AudioStream *stream);
+
+/**
+ * Tell the stream that you're done sending data, and anything being buffered
+ * should be converted/resampled and made available immediately.
+ *
+ * It is legal to add more data to a stream after flushing, but there will
+ * be audio gaps in the output. Generally this is intended to signal the
+ * end of input, so the complete output becomes available.
+ *
+ * \sa SDL_NewAudioStream
+ * \sa SDL_AudioStreamPut
+ * \sa SDL_AudioStreamGet
+ * \sa SDL_AudioStreamAvailable
+ * \sa SDL_AudioStreamClear
+ * \sa SDL_FreeAudioStream
+ */
+extern DECLSPEC int SDLCALL SDL_AudioStreamFlush(SDL_AudioStream *stream);
+
+/**
+ * Clear any pending data in the stream without converting it
+ *
+ * \sa SDL_NewAudioStream
+ * \sa SDL_AudioStreamPut
+ * \sa SDL_AudioStreamGet
+ * \sa SDL_AudioStreamAvailable
+ * \sa SDL_AudioStreamFlush
+ * \sa SDL_FreeAudioStream
+ */
+extern DECLSPEC void SDLCALL SDL_AudioStreamClear(SDL_AudioStream *stream);
+
+/**
+ * Free an audio stream
+ *
+ * \sa SDL_NewAudioStream
+ * \sa SDL_AudioStreamPut
+ * \sa SDL_AudioStreamGet
+ * \sa SDL_AudioStreamAvailable
+ * \sa SDL_AudioStreamFlush
+ * \sa SDL_AudioStreamClear
+ */
+extern DECLSPEC void SDLCALL SDL_FreeAudioStream(SDL_AudioStream *stream);
+
+#define SDL_MIX_MAXVOLUME 128
+/**
+ * This takes two audio buffers of the playing audio format and mixes
+ * them, performing addition, volume adjustment, and overflow clipping.
+ * The volume ranges from 0 - 128, and should be set to ::SDL_MIX_MAXVOLUME
+ * for full audio volume. Note this does not change hardware volume.
+ * This is provided for convenience -- you can mix your own audio data.
+ */
+extern DECLSPEC void SDLCALL SDL_MixAudio(Uint8 * dst, const Uint8 * src,
+ Uint32 len, int volume);
+
+/**
+ * This works like SDL_MixAudio(), but you specify the audio format instead of
+ * using the format of audio device 1. Thus it can be used when no audio
+ * device is open at all.
+ */
+extern DECLSPEC void SDLCALL SDL_MixAudioFormat(Uint8 * dst,
+ const Uint8 * src,
+ SDL_AudioFormat format,
+ Uint32 len, int volume);
+
+/**
+ * Queue more audio on non-callback devices.
+ *
+ * (If you are looking to retrieve queued audio from a non-callback capture
+ * device, you want SDL_DequeueAudio() instead. This will return -1 to
+ * signify an error if you use it with capture devices.)
+ *
+ * SDL offers two ways to feed audio to the device: you can either supply a
+ * callback that SDL triggers with some frequency to obtain more audio
+ * (pull method), or you can supply no callback, and then SDL will expect
+ * you to supply data at regular intervals (push method) with this function.
+ *
+ * There are no limits on the amount of data you can queue, short of
+ * exhaustion of address space. Queued data will drain to the device as
+ * necessary without further intervention from you. If the device needs
+ * audio but there is not enough queued, it will play silence to make up
+ * the difference. This means you will have skips in your audio playback
+ * if you aren't routinely queueing sufficient data.
+ *
+ * This function copies the supplied data, so you are safe to free it when
+ * the function returns. This function is thread-safe, but queueing to the
+ * same device from two threads at once does not promise which buffer will
+ * be queued first.
+ *
+ * You may not queue audio on a device that is using an application-supplied
+ * callback; doing so returns an error. You have to use the audio callback
+ * or queue audio with this function, but not both.
+ *
+ * You should not call SDL_LockAudio() on the device before queueing; SDL
+ * handles locking internally for this function.
+ *
+ * \param dev The device ID to which we will queue audio.
+ * \param data The data to queue to the device for later playback.
+ * \param len The number of bytes (not samples!) to which (data) points.
+ * \return 0 on success, or -1 on error.
+ *
+ * \sa SDL_GetQueuedAudioSize
+ * \sa SDL_ClearQueuedAudio
+ */
+extern DECLSPEC int SDLCALL SDL_QueueAudio(SDL_AudioDeviceID dev, const void *data, Uint32 len);
+
+/**
+ * Dequeue more audio on non-callback devices.
+ *
+ * (If you are looking to queue audio for output on a non-callback playback
+ * device, you want SDL_QueueAudio() instead. This will always return 0
+ * if you use it with playback devices.)
+ *
+ * SDL offers two ways to retrieve audio from a capture device: you can
+ * either supply a callback that SDL triggers with some frequency as the
+ * device records more audio data, (push method), or you can supply no
+ * callback, and then SDL will expect you to retrieve data at regular
+ * intervals (pull method) with this function.
+ *
+ * There are no limits on the amount of data you can queue, short of
+ * exhaustion of address space. Data from the device will keep queuing as
+ * necessary without further intervention from you. This means you will
+ * eventually run out of memory if you aren't routinely dequeueing data.
+ *
+ * Capture devices will not queue data when paused; if you are expecting
+ * to not need captured audio for some length of time, use
+ * SDL_PauseAudioDevice() to stop the capture device from queueing more
+ * data. This can be useful during, say, level loading times. When
+ * unpaused, capture devices will start queueing data from that point,
+ * having flushed any capturable data available while paused.
+ *
+ * This function is thread-safe, but dequeueing from the same device from
+ * two threads at once does not promise which thread will dequeued data
+ * first.
+ *
+ * You may not dequeue audio from a device that is using an
+ * application-supplied callback; doing so returns an error. You have to use
+ * the audio callback, or dequeue audio with this function, but not both.
+ *
+ * You should not call SDL_LockAudio() on the device before queueing; SDL
+ * handles locking internally for this function.
+ *
+ * \param dev The device ID from which we will dequeue audio.
+ * \param data A pointer into where audio data should be copied.
+ * \param len The number of bytes (not samples!) to which (data) points.
+ * \return number of bytes dequeued, which could be less than requested.
+ *
+ * \sa SDL_GetQueuedAudioSize
+ * \sa SDL_ClearQueuedAudio
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_DequeueAudio(SDL_AudioDeviceID dev, void *data, Uint32 len);
+
+/**
+ * Get the number of bytes of still-queued audio.
+ *
+ * For playback device:
+ *
+ * This is the number of bytes that have been queued for playback with
+ * SDL_QueueAudio(), but have not yet been sent to the hardware. This
+ * number may shrink at any time, so this only informs of pending data.
+ *
+ * Once we've sent it to the hardware, this function can not decide the
+ * exact byte boundary of what has been played. It's possible that we just
+ * gave the hardware several kilobytes right before you called this
+ * function, but it hasn't played any of it yet, or maybe half of it, etc.
+ *
+ * For capture devices:
+ *
+ * This is the number of bytes that have been captured by the device and
+ * are waiting for you to dequeue. This number may grow at any time, so
+ * this only informs of the lower-bound of available data.
+ *
+ * You may not queue audio on a device that is using an application-supplied
+ * callback; calling this function on such a device always returns 0.
+ * You have to queue audio with SDL_QueueAudio()/SDL_DequeueAudio(), or use
+ * the audio callback, but not both.
+ *
+ * You should not call SDL_LockAudio() on the device before querying; SDL
+ * handles locking internally for this function.
+ *
+ * \param dev The device ID of which we will query queued audio size.
+ * \return Number of bytes (not samples!) of queued audio.
+ *
+ * \sa SDL_QueueAudio
+ * \sa SDL_ClearQueuedAudio
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_GetQueuedAudioSize(SDL_AudioDeviceID dev);
+
+/**
+ * Drop any queued audio data. For playback devices, this is any queued data
+ * still waiting to be submitted to the hardware. For capture devices, this
+ * is any data that was queued by the device that hasn't yet been dequeued by
+ * the application.
+ *
+ * Immediately after this call, SDL_GetQueuedAudioSize() will return 0. For
+ * playback devices, the hardware will start playing silence if more audio
+ * isn't queued. Unpaused capture devices will start filling the queue again
+ * as soon as they have more data available (which, depending on the state
+ * of the hardware and the thread, could be before this function call
+ * returns!).
+ *
+ * This will not prevent playback of queued audio that's already been sent
+ * to the hardware, as we can not undo that, so expect there to be some
+ * fraction of a second of audio that might still be heard. This can be
+ * useful if you want to, say, drop any pending music during a level change
+ * in your game.
+ *
+ * You may not queue audio on a device that is using an application-supplied
+ * callback; calling this function on such a device is always a no-op.
+ * You have to queue audio with SDL_QueueAudio()/SDL_DequeueAudio(), or use
+ * the audio callback, but not both.
+ *
+ * You should not call SDL_LockAudio() on the device before clearing the
+ * queue; SDL handles locking internally for this function.
+ *
+ * This function always succeeds and thus returns void.
+ *
+ * \param dev The device ID of which to clear the audio queue.
+ *
+ * \sa SDL_QueueAudio
+ * \sa SDL_GetQueuedAudioSize
+ */
+extern DECLSPEC void SDLCALL SDL_ClearQueuedAudio(SDL_AudioDeviceID dev);
+
+
+/**
+ * \name Audio lock functions
+ *
+ * The lock manipulated by these functions protects the callback function.
+ * During a SDL_LockAudio()/SDL_UnlockAudio() pair, you can be guaranteed that
+ * the callback function is not running. Do not call these from the callback
+ * function or you will cause deadlock.
+ */
+/* @{ */
+extern DECLSPEC void SDLCALL SDL_LockAudio(void);
+extern DECLSPEC void SDLCALL SDL_LockAudioDevice(SDL_AudioDeviceID dev);
+extern DECLSPEC void SDLCALL SDL_UnlockAudio(void);
+extern DECLSPEC void SDLCALL SDL_UnlockAudioDevice(SDL_AudioDeviceID dev);
+/* @} *//* Audio lock functions */
+
+/**
+ * This function shuts down audio processing and closes the audio device.
+ */
+extern DECLSPEC void SDLCALL SDL_CloseAudio(void);
+extern DECLSPEC void SDLCALL SDL_CloseAudioDevice(SDL_AudioDeviceID dev);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_audio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_bits.h b/src/3rdparty/SDL2/include/SDL_bits.h
new file mode 100644
index 0000000..eb8322f
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_bits.h
@@ -0,0 +1,112 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_bits.h
+ *
+ * Functions for fiddling with bits and bitmasks.
+ */
+
+#ifndef SDL_bits_h_
+#define SDL_bits_h_
+
+#include "SDL_stdinc.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \file SDL_bits.h
+ */
+
+/**
+ * Get the index of the most significant bit. Result is undefined when called
+ * with 0. This operation can also be stated as "count leading zeroes" and
+ * "log base 2".
+ *
+ * \return Index of the most significant bit, or -1 if the value is 0.
+ */
+#if defined(__WATCOMC__) && defined(__386__)
+extern _inline int _SDL_clz_watcom (Uint32);
+#pragma aux _SDL_clz_watcom = \
+ "bsr eax, eax" \
+ "xor eax, 31" \
+ parm [eax] nomemory \
+ value [eax] \
+ modify exact [eax] nomemory;
+#endif
+
+SDL_FORCE_INLINE int
+SDL_MostSignificantBitIndex32(Uint32 x)
+{
+#if defined(__GNUC__) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+ /* Count Leading Zeroes builtin in GCC.
+ * http://gcc.gnu.org/onlinedocs/gcc-4.3.4/gcc/Other-Builtins.html
+ */
+ if (x == 0) {
+ return -1;
+ }
+ return 31 - __builtin_clz(x);
+#elif defined(__WATCOMC__) && defined(__386__)
+ if (x == 0) {
+ return -1;
+ }
+ return 31 - _SDL_clz_watcom(x);
+#else
+ /* Based off of Bit Twiddling Hacks by Sean Eron Anderson
+ * <seander@cs.stanford.edu>, released in the public domain.
+ * http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog
+ */
+ const Uint32 b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000};
+ const int S[] = {1, 2, 4, 8, 16};
+
+ int msbIndex = 0;
+ int i;
+
+ if (x == 0) {
+ return -1;
+ }
+
+ for (i = 4; i >= 0; i--)
+ {
+ if (x & b[i])
+ {
+ x >>= S[i];
+ msbIndex |= S[i];
+ }
+ }
+
+ return msbIndex;
+#endif
+}
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_bits_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_blendmode.h b/src/3rdparty/SDL2/include/SDL_blendmode.h
new file mode 100644
index 0000000..36a5ea7
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_blendmode.h
@@ -0,0 +1,120 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_blendmode.h
+ *
+ * Header file declaring the SDL_BlendMode enumeration
+ */
+
+#ifndef SDL_blendmode_h_
+#define SDL_blendmode_h_
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The blend mode used in SDL_RenderCopy() and drawing operations.
+ */
+typedef enum
+{
+ SDL_BLENDMODE_NONE = 0x00000000, /**< no blending
+ dstRGBA = srcRGBA */
+ SDL_BLENDMODE_BLEND = 0x00000001, /**< alpha blending
+ dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA))
+ dstA = srcA + (dstA * (1-srcA)) */
+ SDL_BLENDMODE_ADD = 0x00000002, /**< additive blending
+ dstRGB = (srcRGB * srcA) + dstRGB
+ dstA = dstA */
+ SDL_BLENDMODE_MOD = 0x00000004, /**< color modulate
+ dstRGB = srcRGB * dstRGB
+ dstA = dstA */
+ SDL_BLENDMODE_INVALID = 0x7FFFFFFF
+
+ /* Additional custom blend modes can be returned by SDL_ComposeCustomBlendMode() */
+
+} SDL_BlendMode;
+
+/**
+ * \brief The blend operation used when combining source and destination pixel components
+ */
+typedef enum
+{
+ SDL_BLENDOPERATION_ADD = 0x1, /**< dst + src: supported by all renderers */
+ SDL_BLENDOPERATION_SUBTRACT = 0x2, /**< dst - src : supported by D3D9, D3D11, OpenGL, OpenGLES */
+ SDL_BLENDOPERATION_REV_SUBTRACT = 0x3, /**< src - dst : supported by D3D9, D3D11, OpenGL, OpenGLES */
+ SDL_BLENDOPERATION_MINIMUM = 0x4, /**< min(dst, src) : supported by D3D11 */
+ SDL_BLENDOPERATION_MAXIMUM = 0x5 /**< max(dst, src) : supported by D3D11 */
+
+} SDL_BlendOperation;
+
+/**
+ * \brief The normalized factor used to multiply pixel components
+ */
+typedef enum
+{
+ SDL_BLENDFACTOR_ZERO = 0x1, /**< 0, 0, 0, 0 */
+ SDL_BLENDFACTOR_ONE = 0x2, /**< 1, 1, 1, 1 */
+ SDL_BLENDFACTOR_SRC_COLOR = 0x3, /**< srcR, srcG, srcB, srcA */
+ SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR = 0x4, /**< 1-srcR, 1-srcG, 1-srcB, 1-srcA */
+ SDL_BLENDFACTOR_SRC_ALPHA = 0x5, /**< srcA, srcA, srcA, srcA */
+ SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA = 0x6, /**< 1-srcA, 1-srcA, 1-srcA, 1-srcA */
+ SDL_BLENDFACTOR_DST_COLOR = 0x7, /**< dstR, dstG, dstB, dstA */
+ SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR = 0x8, /**< 1-dstR, 1-dstG, 1-dstB, 1-dstA */
+ SDL_BLENDFACTOR_DST_ALPHA = 0x9, /**< dstA, dstA, dstA, dstA */
+ SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA = 0xA /**< 1-dstA, 1-dstA, 1-dstA, 1-dstA */
+
+} SDL_BlendFactor;
+
+/**
+ * \brief Create a custom blend mode, which may or may not be supported by a given renderer
+ *
+ * \param srcColorFactor
+ * \param dstColorFactor
+ * \param colorOperation
+ * \param srcAlphaFactor
+ * \param dstAlphaFactor
+ * \param alphaOperation
+ *
+ * The result of the blend mode operation will be:
+ * dstRGB = dstRGB * dstColorFactor colorOperation srcRGB * srcColorFactor
+ * and
+ * dstA = dstA * dstAlphaFactor alphaOperation srcA * srcAlphaFactor
+ */
+extern DECLSPEC SDL_BlendMode SDLCALL SDL_ComposeCustomBlendMode(SDL_BlendFactor srcColorFactor,
+ SDL_BlendFactor dstColorFactor,
+ SDL_BlendOperation colorOperation,
+ SDL_BlendFactor srcAlphaFactor,
+ SDL_BlendFactor dstAlphaFactor,
+ SDL_BlendOperation alphaOperation);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_blendmode_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_clipboard.h b/src/3rdparty/SDL2/include/SDL_clipboard.h
new file mode 100644
index 0000000..f28751e
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_clipboard.h
@@ -0,0 +1,71 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_clipboard.h
+ *
+ * Include file for SDL clipboard handling
+ */
+
+#ifndef SDL_clipboard_h_
+#define SDL_clipboard_h_
+
+#include "SDL_stdinc.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Function prototypes */
+
+/**
+ * \brief Put UTF-8 text into the clipboard
+ *
+ * \sa SDL_GetClipboardText()
+ */
+extern DECLSPEC int SDLCALL SDL_SetClipboardText(const char *text);
+
+/**
+ * \brief Get UTF-8 text from the clipboard, which must be freed with SDL_free()
+ *
+ * \sa SDL_SetClipboardText()
+ */
+extern DECLSPEC char * SDLCALL SDL_GetClipboardText(void);
+
+/**
+ * \brief Returns a flag indicating whether the clipboard exists and contains a text string that is non-empty
+ *
+ * \sa SDL_GetClipboardText()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasClipboardText(void);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_clipboard_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_config.h b/src/3rdparty/SDL2/include/SDL_config.h
new file mode 100644
index 0000000..7e0340c
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_config.h
@@ -0,0 +1,53 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_h_
+#define SDL_config_h_
+
+#include "SDL_platform.h"
+
+/**
+ * \file SDL_config.h
+ */
+
+/* Add any platform that doesn't build using the configure system. */
+#if defined(__WIN32__)
+#include "SDL_config_windows.h"
+#elif defined(__WINRT__)
+#include "SDL_config_winrt.h"
+#elif defined(__MACOSX__)
+#include "SDL_config_macosx.h"
+#elif defined(__IPHONEOS__)
+#include "SDL_config_iphoneos.h"
+#elif defined(__ANDROID__)
+#include "SDL_config_android.h"
+#elif defined(__PSP__)
+#include "SDL_config_psp.h"
+#else
+/* This is a minimal configuration just to get SDL running on new platforms */
+#include "SDL_config_minimal.h"
+#endif /* platform config */
+
+#ifdef USING_GENERATED_CONFIG_H
+#error Wrong SDL_config.h, check your include path?
+#endif
+
+#endif /* SDL_config_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL_config_android.h b/src/3rdparty/SDL2/include/SDL_config_android.h
new file mode 100644
index 0000000..4c4da37
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_config_android.h
@@ -0,0 +1,171 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_android_h_
+#define SDL_config_android_h_
+#define SDL_config_h_
+
+#include "SDL_platform.h"
+
+/**
+ * \file SDL_config_android.h
+ *
+ * This is a configuration that can be used to build SDL for Android
+ */
+
+#include <stdarg.h>
+
+#define HAVE_GCC_ATOMICS 1
+
+#define STDC_HEADERS 1
+#define HAVE_ALLOCA_H 1
+#define HAVE_CTYPE_H 1
+#define HAVE_INTTYPES_H 1
+#define HAVE_LIMITS_H 1
+#define HAVE_MATH_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDINT_H 1
+#define HAVE_STDIO_H 1
+#define HAVE_STRING_H 1
+#define HAVE_SYS_TYPES_H 1
+
+/* C library functions */
+#define HAVE_MALLOC 1
+#define HAVE_CALLOC 1
+#define HAVE_REALLOC 1
+#define HAVE_FREE 1
+#define HAVE_ALLOCA 1
+#define HAVE_GETENV 1
+#define HAVE_SETENV 1
+#define HAVE_PUTENV 1
+#define HAVE_SETENV 1
+#define HAVE_UNSETENV 1
+#define HAVE_QSORT 1
+#define HAVE_ABS 1
+#define HAVE_BCOPY 1
+#define HAVE_MEMSET 1
+#define HAVE_MEMCPY 1
+#define HAVE_MEMMOVE 1
+#define HAVE_MEMCMP 1
+#define HAVE_STRLEN 1
+#define HAVE_STRLCPY 1
+#define HAVE_STRLCAT 1
+#define HAVE_STRCHR 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRSTR 1
+#define HAVE_STRTOL 1
+#define HAVE_STRTOUL 1
+#define HAVE_STRTOLL 1
+#define HAVE_STRTOULL 1
+#define HAVE_STRTOD 1
+#define HAVE_ATOI 1
+#define HAVE_ATOF 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
+#define HAVE_STRCASECMP 1
+#define HAVE_STRNCASECMP 1
+#define HAVE_VSSCANF 1
+#define HAVE_VSNPRINTF 1
+#define HAVE_ACOS 1
+#define HAVE_ACOSF 1
+#define HAVE_ASIN 1
+#define HAVE_ASINF 1
+#define HAVE_ATAN 1
+#define HAVE_ATANF 1
+#define HAVE_ATAN2 1
+#define HAVE_ATAN2F 1
+#define HAVE_CEIL 1
+#define HAVE_CEILF 1
+#define HAVE_COPYSIGN 1
+#define HAVE_COPYSIGNF 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_FABS 1
+#define HAVE_FABSF 1
+#define HAVE_FLOOR 1
+#define HAVE_FLOORF 1
+#define HAVE_FMOD 1
+#define HAVE_FMODF 1
+#define HAVE_LOG 1
+#define HAVE_LOGF 1
+#define HAVE_LOG10 1
+#define HAVE_LOG10F 1
+#define HAVE_POW 1
+#define HAVE_POWF 1
+#define HAVE_SCALBN 1
+#define HAVE_SCALBNF 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
+#define HAVE_SQRTF 1
+#define HAVE_TAN 1
+#define HAVE_TANF 1
+#define HAVE_SIGACTION 1
+#define HAVE_SETJMP 1
+#define HAVE_NANOSLEEP 1
+#define HAVE_SYSCONF 1
+#define HAVE_CLOCK_GETTIME 1
+
+#define SIZEOF_VOIDP 4
+
+/* Enable various audio drivers */
+#define SDL_AUDIO_DRIVER_ANDROID 1
+#define SDL_AUDIO_DRIVER_DUMMY 1
+
+/* Enable various input drivers */
+#define SDL_JOYSTICK_ANDROID 1
+#define SDL_HAPTIC_ANDROID 1
+
+/* Enable various shared object loading systems */
+#define SDL_LOADSO_DLOPEN 1
+
+/* Enable various threading systems */
+#define SDL_THREAD_PTHREAD 1
+#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1
+
+/* Enable various timer systems */
+#define SDL_TIMER_UNIX 1
+
+/* Enable various video drivers */
+#define SDL_VIDEO_DRIVER_ANDROID 1
+
+/* Enable OpenGL ES */
+#define SDL_VIDEO_OPENGL_ES 1
+#define SDL_VIDEO_OPENGL_ES2 1
+#define SDL_VIDEO_OPENGL_EGL 1
+#define SDL_VIDEO_RENDER_OGL_ES 1
+#define SDL_VIDEO_RENDER_OGL_ES2 1
+
+/* Enable Vulkan support */
+/* Android does not support Vulkan in native code using the "armeabi" ABI. */
+#if defined(__ARM_ARCH) && __ARM_ARCH < 7
+#define SDL_VIDEO_VULKAN 0
+#else
+#define SDL_VIDEO_VULKAN 1
+#endif
+
+/* Enable system power support */
+#define SDL_POWER_ANDROID 1
+
+/* Enable the filesystem driver */
+#define SDL_FILESYSTEM_ANDROID 1
+
+#endif /* SDL_config_android_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL_config_iphoneos.h b/src/3rdparty/SDL2/include/SDL_config_iphoneos.h
new file mode 100644
index 0000000..7b0a6ca
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_config_iphoneos.h
@@ -0,0 +1,191 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_iphoneos_h_
+#define SDL_config_iphoneos_h_
+#define SDL_config_h_
+
+#include "SDL_platform.h"
+
+#ifdef __LP64__
+#define SIZEOF_VOIDP 8
+#else
+#define SIZEOF_VOIDP 4
+#endif
+
+#define HAVE_GCC_ATOMICS 1
+
+#define STDC_HEADERS 1
+#define HAVE_ALLOCA_H 1
+#define HAVE_CTYPE_H 1
+#define HAVE_INTTYPES_H 1
+#define HAVE_LIMITS_H 1
+#define HAVE_MATH_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDINT_H 1
+#define HAVE_STDIO_H 1
+#define HAVE_STRING_H 1
+#define HAVE_SYS_TYPES_H 1
+/* The libunwind functions are only available on x86 */
+/* #undef HAVE_LIBUNWIND_H */
+
+/* C library functions */
+#define HAVE_MALLOC 1
+#define HAVE_CALLOC 1
+#define HAVE_REALLOC 1
+#define HAVE_FREE 1
+#define HAVE_ALLOCA 1
+#define HAVE_GETENV 1
+#define HAVE_SETENV 1
+#define HAVE_PUTENV 1
+#define HAVE_SETENV 1
+#define HAVE_UNSETENV 1
+#define HAVE_QSORT 1
+#define HAVE_ABS 1
+#define HAVE_BCOPY 1
+#define HAVE_MEMSET 1
+#define HAVE_MEMCPY 1
+#define HAVE_MEMMOVE 1
+#define HAVE_MEMCMP 1
+#define HAVE_STRLEN 1
+#define HAVE_STRLCPY 1
+#define HAVE_STRLCAT 1
+#define HAVE_STRCHR 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRSTR 1
+#define HAVE_STRTOL 1
+#define HAVE_STRTOUL 1
+#define HAVE_STRTOLL 1
+#define HAVE_STRTOULL 1
+#define HAVE_STRTOD 1
+#define HAVE_ATOI 1
+#define HAVE_ATOF 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
+#define HAVE_STRCASECMP 1
+#define HAVE_STRNCASECMP 1
+#define HAVE_VSSCANF 1
+#define HAVE_VSNPRINTF 1
+#define HAVE_M_PI 1
+#define HAVE_ACOS 1
+#define HAVE_ACOSF 1
+#define HAVE_ASIN 1
+#define HAVE_ASINF 1
+#define HAVE_ATAN 1
+#define HAVE_ATANF 1
+#define HAVE_ATAN2 1
+#define HAVE_ATAN2F 1
+#define HAVE_CEIL 1
+#define HAVE_CEILF 1
+#define HAVE_COPYSIGN 1
+#define HAVE_COPYSIGNF 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_FABS 1
+#define HAVE_FABSF 1
+#define HAVE_FLOOR 1
+#define HAVE_FLOORF 1
+#define HAVE_FMOD 1
+#define HAVE_FMODF 1
+#define HAVE_LOG 1
+#define HAVE_LOGF 1
+#define HAVE_LOG10 1
+#define HAVE_LOG10F 1
+#define HAVE_POW 1
+#define HAVE_POWF 1
+#define HAVE_SCALBN 1
+#define HAVE_SCALBNF 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
+#define HAVE_SQRTF 1
+#define HAVE_TAN 1
+#define HAVE_TANF 1
+#define HAVE_SIGACTION 1
+#define HAVE_SETJMP 1
+#define HAVE_NANOSLEEP 1
+#define HAVE_SYSCONF 1
+#define HAVE_SYSCTLBYNAME 1
+
+/* enable iPhone version of Core Audio driver */
+#define SDL_AUDIO_DRIVER_COREAUDIO 1
+/* Enable the dummy audio driver (src/audio/dummy/\*.c) */
+#define SDL_AUDIO_DRIVER_DUMMY 1
+
+/* Enable the stub haptic driver (src/haptic/dummy/\*.c) */
+#define SDL_HAPTIC_DUMMY 1
+
+/* Enable MFi joystick support */
+#define SDL_JOYSTICK_MFI 1
+
+/* Enable Unix style SO loading */
+#define SDL_LOADSO_DLOPEN 1
+
+/* Enable various threading systems */
+#define SDL_THREAD_PTHREAD 1
+#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1
+
+/* Enable various timer systems */
+#define SDL_TIMER_UNIX 1
+
+/* Supported video drivers */
+#define SDL_VIDEO_DRIVER_UIKIT 1
+#define SDL_VIDEO_DRIVER_DUMMY 1
+
+/* Enable OpenGL ES */
+#define SDL_VIDEO_OPENGL_ES2 1
+#define SDL_VIDEO_OPENGL_ES 1
+#define SDL_VIDEO_RENDER_OGL_ES 1
+#define SDL_VIDEO_RENDER_OGL_ES2 1
+
+/* Metal supported on 64-bit devices running iOS 8.0 and tvOS 9.0 and newer */
+#if !TARGET_OS_SIMULATOR && !TARGET_CPU_ARM && ((__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 90000))
+#define SDL_PLATFORM_SUPPORTS_METAL 1
+#else
+#define SDL_PLATFORM_SUPPORTS_METAL 0
+#endif
+
+#if SDL_PLATFORM_SUPPORTS_METAL
+#define SDL_VIDEO_RENDER_METAL 1
+#endif
+
+#if SDL_PLATFORM_SUPPORTS_METAL
+#define SDL_VIDEO_VULKAN 1
+#endif
+
+/* Enable system power support */
+#define SDL_POWER_UIKIT 1
+
+/* enable iPhone keyboard support */
+#define SDL_IPHONE_KEYBOARD 1
+
+/* enable iOS extended launch screen */
+#define SDL_IPHONE_LAUNCHSCREEN 1
+
+/* Set max recognized G-force from accelerometer
+ See src/joystick/uikit/SDL_sysjoystick.m for notes on why this is needed
+ */
+#define SDL_IPHONE_MAX_GFORCE 5.0
+
+/* enable filesystem support */
+#define SDL_FILESYSTEM_COCOA 1
+
+#endif /* SDL_config_iphoneos_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL_config_macosx.h b/src/3rdparty/SDL2/include/SDL_config_macosx.h
new file mode 100644
index 0000000..29f583e
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_config_macosx.h
@@ -0,0 +1,234 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_macosx_h_
+#define SDL_config_macosx_h_
+#define SDL_config_h_
+
+#include "SDL_platform.h"
+
+/* This gets us MAC_OS_X_VERSION_MIN_REQUIRED... */
+#include <AvailabilityMacros.h>
+
+/* This is a set of defines to configure the SDL features */
+
+#ifdef __LP64__
+ #define SIZEOF_VOIDP 8
+#else
+ #define SIZEOF_VOIDP 4
+#endif
+
+/* Useful headers */
+#define STDC_HEADERS 1
+#define HAVE_ALLOCA_H 1
+#define HAVE_CTYPE_H 1
+#define HAVE_FLOAT_H 1
+#define HAVE_INTTYPES_H 1
+#define HAVE_LIMITS_H 1
+#define HAVE_MATH_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDINT_H 1
+#define HAVE_STDIO_H 1
+#define HAVE_STRING_H 1
+#define HAVE_SYS_TYPES_H 1
+#define HAVE_LIBUNWIND_H 1
+
+/* C library functions */
+#define HAVE_MALLOC 1
+#define HAVE_CALLOC 1
+#define HAVE_REALLOC 1
+#define HAVE_FREE 1
+#define HAVE_ALLOCA 1
+#define HAVE_GETENV 1
+#define HAVE_SETENV 1
+#define HAVE_PUTENV 1
+#define HAVE_UNSETENV 1
+#define HAVE_QSORT 1
+#define HAVE_ABS 1
+#define HAVE_BCOPY 1
+#define HAVE_MEMSET 1
+#define HAVE_MEMCPY 1
+#define HAVE_MEMMOVE 1
+#define HAVE_MEMCMP 1
+#define HAVE_STRLEN 1
+#define HAVE_STRLCPY 1
+#define HAVE_STRLCAT 1
+#define HAVE_STRCHR 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRSTR 1
+#define HAVE_STRTOL 1
+#define HAVE_STRTOUL 1
+#define HAVE_STRTOLL 1
+#define HAVE_STRTOULL 1
+#define HAVE_STRTOD 1
+#define HAVE_ATOI 1
+#define HAVE_ATOF 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
+#define HAVE_STRCASECMP 1
+#define HAVE_STRNCASECMP 1
+#define HAVE_VSSCANF 1
+#define HAVE_VSNPRINTF 1
+#define HAVE_M_PI 1
+#define HAVE_ACOS 1
+#define HAVE_ACOSF 1
+#define HAVE_ASIN 1
+#define HAVE_ASINF 1
+#define HAVE_ATAN 1
+#define HAVE_ATANF 1
+#define HAVE_ATAN2 1
+#define HAVE_ATAN2F 1
+#define HAVE_CEIL 1
+#define HAVE_CEILF 1
+#define HAVE_COPYSIGN 1
+#define HAVE_COPYSIGNF 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_FABS 1
+#define HAVE_FABSF 1
+#define HAVE_FLOOR 1
+#define HAVE_FLOORF 1
+#define HAVE_FMOD 1
+#define HAVE_FMODF 1
+#define HAVE_LOG 1
+#define HAVE_LOGF 1
+#define HAVE_LOG10 1
+#define HAVE_LOG10F 1
+#define HAVE_POW 1
+#define HAVE_POWF 1
+#define HAVE_SCALBN 1
+#define HAVE_SCALBNF 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
+#define HAVE_SQRTF 1
+#define HAVE_TAN 1
+#define HAVE_TANF 1
+#define HAVE_SIGACTION 1
+#define HAVE_SETJMP 1
+#define HAVE_NANOSLEEP 1
+#define HAVE_SYSCONF 1
+#define HAVE_SYSCTLBYNAME 1
+
+/* Enable various audio drivers */
+#define SDL_AUDIO_DRIVER_COREAUDIO 1
+#define SDL_AUDIO_DRIVER_DISK 1
+#define SDL_AUDIO_DRIVER_DUMMY 1
+
+/* Enable various input drivers */
+#define SDL_JOYSTICK_IOKIT 1
+#define SDL_HAPTIC_IOKIT 1
+
+/* Enable various shared object loading systems */
+#define SDL_LOADSO_DLOPEN 1
+
+/* Enable various threading systems */
+#define SDL_THREAD_PTHREAD 1
+#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1
+
+/* Enable various timer systems */
+#define SDL_TIMER_UNIX 1
+
+/* Enable various video drivers */
+#define SDL_VIDEO_DRIVER_COCOA 1
+#define SDL_VIDEO_DRIVER_DUMMY 1
+#undef SDL_VIDEO_DRIVER_X11
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC "/usr/X11R6/lib/libX11.6.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "/usr/X11R6/lib/libXext.6.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "/usr/X11R6/lib/libXinerama.1.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "/usr/X11R6/lib/libXi.6.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "/usr/X11R6/lib/libXrandr.2.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "/usr/X11R6/lib/libXss.1.dylib"
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "/usr/X11R6/lib/libXxf86vm.1.dylib"
+#define SDL_VIDEO_DRIVER_X11_XDBE 1
+#define SDL_VIDEO_DRIVER_X11_XINERAMA 1
+#define SDL_VIDEO_DRIVER_X11_XRANDR 1
+#define SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1
+#define SDL_VIDEO_DRIVER_X11_XSHAPE 1
+#define SDL_VIDEO_DRIVER_X11_XVIDMODE 1
+#define SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM 1
+
+#ifdef MAC_OS_X_VERSION_10_8
+/*
+ * No matter the versions targeted, this is the 10.8 or later SDK, so you have
+ * to use the external Xquartz, which is a more modern Xlib. Previous SDKs
+ * used an older Xlib.
+ */
+#define SDL_VIDEO_DRIVER_X11_XINPUT2 1
+#define SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1
+#define SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1
+#endif
+
+#ifndef SDL_VIDEO_RENDER_OGL
+#define SDL_VIDEO_RENDER_OGL 1
+#endif
+
+#ifndef SDL_VIDEO_RENDER_OGL_ES2
+#define SDL_VIDEO_RENDER_OGL_ES2 1
+#endif
+
+#ifndef SDL_VIDEO_RENDER_METAL
+/* Metal only supported on 64-bit architectures with 10.11+ */
+#if TARGET_CPU_X86_64 && (MAC_OS_X_VERSION_MAX_ALLOWED >= 101100)
+#define SDL_VIDEO_RENDER_METAL 1
+#else
+#define SDL_VIDEO_RENDER_METAL 0
+#endif
+#endif
+
+/* Enable OpenGL support */
+#ifndef SDL_VIDEO_OPENGL
+#define SDL_VIDEO_OPENGL 1
+#endif
+#ifndef SDL_VIDEO_OPENGL_ES2
+#define SDL_VIDEO_OPENGL_ES2 1
+#endif
+#ifndef SDL_VIDEO_OPENGL_EGL
+#define SDL_VIDEO_OPENGL_EGL 1
+#endif
+#ifndef SDL_VIDEO_OPENGL_CGL
+#define SDL_VIDEO_OPENGL_CGL 1
+#endif
+#ifndef SDL_VIDEO_OPENGL_GLX
+#define SDL_VIDEO_OPENGL_GLX 1
+#endif
+
+/* Enable Vulkan support */
+/* Metal/MoltenVK/Vulkan only supported on 64-bit architectures with 10.11+ */
+#if TARGET_CPU_X86_64 && (MAC_OS_X_VERSION_MAX_ALLOWED >= 101100)
+#define SDL_VIDEO_VULKAN 1
+#else
+#define SDL_VIDEO_VULKAN 0
+#endif
+
+/* Enable system power support */
+#define SDL_POWER_MACOSX 1
+
+/* enable filesystem support */
+#define SDL_FILESYSTEM_COCOA 1
+
+/* Enable assembly routines */
+#define SDL_ASSEMBLY_ROUTINES 1
+#ifdef __ppc__
+#define SDL_ALTIVEC_BLITTERS 1
+#endif
+
+#endif /* SDL_config_macosx_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL_config_minimal.h b/src/3rdparty/SDL2/include/SDL_config_minimal.h
new file mode 100644
index 0000000..5b03d8b
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_config_minimal.h
@@ -0,0 +1,82 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_minimal_h_
+#define SDL_config_minimal_h_
+#define SDL_config_h_
+
+#include "SDL_platform.h"
+
+/**
+ * \file SDL_config_minimal.h
+ *
+ * This is the minimal configuration that can be used to build SDL.
+ */
+
+#define HAVE_STDARG_H 1
+#define HAVE_STDDEF_H 1
+
+/* Most everything except Visual Studio 2008 and earlier has stdint.h now */
+#if defined(_MSC_VER) && (_MSC_VER < 1600)
+/* Here are some reasonable defaults */
+typedef unsigned int size_t;
+typedef signed char int8_t;
+typedef unsigned char uint8_t;
+typedef signed short int16_t;
+typedef unsigned short uint16_t;
+typedef signed int int32_t;
+typedef unsigned int uint32_t;
+typedef signed long long int64_t;
+typedef unsigned long long uint64_t;
+typedef unsigned long uintptr_t;
+#else
+#define HAVE_STDINT_H 1
+#endif /* Visual Studio 2008 */
+
+#ifdef __GNUC__
+#define HAVE_GCC_SYNC_LOCK_TEST_AND_SET 1
+#endif
+
+/* Enable the dummy audio driver (src/audio/dummy/\*.c) */
+#define SDL_AUDIO_DRIVER_DUMMY 1
+
+/* Enable the stub joystick driver (src/joystick/dummy/\*.c) */
+#define SDL_JOYSTICK_DISABLED 1
+
+/* Enable the stub haptic driver (src/haptic/dummy/\*.c) */
+#define SDL_HAPTIC_DISABLED 1
+
+/* Enable the stub shared object loader (src/loadso/dummy/\*.c) */
+#define SDL_LOADSO_DISABLED 1
+
+/* Enable the stub thread support (src/thread/generic/\*.c) */
+#define SDL_THREADS_DISABLED 1
+
+/* Enable the stub timer support (src/timer/dummy/\*.c) */
+#define SDL_TIMERS_DISABLED 1
+
+/* Enable the dummy video driver (src/video/dummy/\*.c) */
+#define SDL_VIDEO_DRIVER_DUMMY 1
+
+/* Enable the dummy filesystem driver (src/filesystem/dummy/\*.c) */
+#define SDL_FILESYSTEM_DUMMY 1
+
+#endif /* SDL_config_minimal_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL_config_pandora.h b/src/3rdparty/SDL2/include/SDL_config_pandora.h
new file mode 100644
index 0000000..be5a85c
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_config_pandora.h
@@ -0,0 +1,130 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_pandora_h_
+#define SDL_config_pandora_h_
+#define SDL_config_h_
+
+/* This is a set of defines to configure the SDL features */
+
+/* General platform specific identifiers */
+#include "SDL_platform.h"
+
+#ifdef __LP64__
+#define SIZEOF_VOIDP 8
+#else
+#define SIZEOF_VOIDP 4
+#endif
+
+#define SDL_BYTEORDER 1234
+
+#define STDC_HEADERS 1
+#define HAVE_ALLOCA_H 1
+#define HAVE_CTYPE_H 1
+#define HAVE_ICONV_H 1
+#define HAVE_INTTYPES_H 1
+#define HAVE_LIMITS_H 1
+#define HAVE_MALLOC_H 1
+#define HAVE_MATH_H 1
+#define HAVE_MEMORY_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDARG_H 1
+#define HAVE_STDINT_H 1
+#define HAVE_STDIO_H 1
+#define HAVE_STDLIB_H 1
+#define HAVE_STRINGS_H 1
+#define HAVE_STRING_H 1
+#define HAVE_SYS_TYPES_H 1
+
+#define HAVE_MALLOC 1
+#define HAVE_CALLOC 1
+#define HAVE_REALLOC 1
+#define HAVE_FREE 1
+#define HAVE_ALLOCA 1
+#define HAVE_GETENV 1
+#define HAVE_SETENV 1
+#define HAVE_PUTENV 1
+#define HAVE_UNSETENV 1
+#define HAVE_QSORT 1
+#define HAVE_ABS 1
+#define HAVE_BCOPY 1
+#define HAVE_MEMSET 1
+#define HAVE_MEMCPY 1
+#define HAVE_MEMMOVE 1
+#define HAVE_STRLEN 1
+#define HAVE_STRCHR 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRSTR 1
+#define HAVE_STRTOL 1
+#define HAVE_STRTOUL 1
+#define HAVE_STRTOLL 1
+#define HAVE_STRTOULL 1
+#define HAVE_ATOI 1
+#define HAVE_ATOF 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
+#define HAVE_STRCASECMP 1
+#define HAVE_STRNCASECMP 1
+#define HAVE_VSSCANF 1
+#define HAVE_VSNPRINTF 1
+#define HAVE_M_PI 1
+#define HAVE_CEIL 1
+#define HAVE_COPYSIGN 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_FABS 1
+#define HAVE_FLOOR 1
+#define HAVE_LOG 1
+#define HAVE_LOG10 1
+#define HAVE_SCALBN 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
+#define HAVE_SQRTF 1
+#define HAVE_TAN 1
+#define HAVE_TANF 1
+#define HAVE_SIGACTION 1
+#define HAVE_SETJMP 1
+#define HAVE_NANOSLEEP 1
+
+#define SDL_AUDIO_DRIVER_DUMMY 1
+#define SDL_AUDIO_DRIVER_OSS 1
+
+#define SDL_INPUT_LINUXEV 1
+#define SDL_INPUT_TSLIB 1
+#define SDL_JOYSTICK_LINUX 1
+#define SDL_HAPTIC_LINUX 1
+
+#define SDL_LOADSO_DLOPEN 1
+
+#define SDL_THREAD_PTHREAD 1
+#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1
+
+#define SDL_TIMER_UNIX 1
+#define SDL_FILESYSTEM_UNIX 1
+
+#define SDL_VIDEO_DRIVER_DUMMY 1
+#define SDL_VIDEO_DRIVER_X11 1
+#define SDL_VIDEO_DRIVER_PANDORA 1
+#define SDL_VIDEO_RENDER_OGL_ES 1
+#define SDL_VIDEO_OPENGL_ES 1
+
+#endif /* SDL_config_pandora_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL_config_psp.h b/src/3rdparty/SDL2/include/SDL_config_psp.h
new file mode 100644
index 0000000..61c3349
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_config_psp.h
@@ -0,0 +1,159 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_psp_h_
+#define SDL_config_psp_h_
+#define SDL_config_h_
+
+#include "SDL_platform.h"
+
+
+
+#ifdef __GNUC__
+#define HAVE_GCC_SYNC_LOCK_TEST_AND_SET 1
+#endif
+
+#define HAVE_GCC_ATOMICS 1
+
+#define STDC_HEADERS 1
+#define HAVE_ALLOCA_H 1
+#define HAVE_CTYPE_H 1
+#define HAVE_INTTYPES_H 1
+#define HAVE_LIMITS_H 1
+#define HAVE_MATH_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDINT_H 1
+#define HAVE_STDIO_H 1
+#define HAVE_STRING_H 1
+#define HAVE_SYS_TYPES_H 1
+
+/* C library functions */
+#define HAVE_MALLOC 1
+#define HAVE_CALLOC 1
+#define HAVE_REALLOC 1
+#define HAVE_FREE 1
+#define HAVE_ALLOCA 1
+#define HAVE_GETENV 1
+#define HAVE_SETENV 1
+#define HAVE_PUTENV 1
+#define HAVE_SETENV 1
+#define HAVE_UNSETENV 1
+#define HAVE_QSORT 1
+#define HAVE_ABS 1
+#define HAVE_BCOPY 1
+#define HAVE_MEMSET 1
+#define HAVE_MEMCPY 1
+#define HAVE_MEMMOVE 1
+#define HAVE_MEMCMP 1
+#define HAVE_STRLEN 1
+#define HAVE_STRLCPY 1
+#define HAVE_STRLCAT 1
+#define HAVE_STRCHR 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRSTR 1
+#define HAVE_STRTOL 1
+#define HAVE_STRTOUL 1
+#define HAVE_STRTOLL 1
+#define HAVE_STRTOULL 1
+#define HAVE_STRTOD 1
+#define HAVE_ATOI 1
+#define HAVE_ATOF 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
+#define HAVE_STRCASECMP 1
+#define HAVE_STRNCASECMP 1
+#define HAVE_VSSCANF 1
+#define HAVE_VSNPRINTF 1
+#define HAVE_M_PI 1
+#define HAVE_ACOS 1
+#define HAVE_ACOSF 1
+#define HAVE_ASIN 1
+#define HAVE_ASINF 1
+#define HAVE_ATAN 1
+#define HAVE_ATANF 1
+#define HAVE_ATAN2 1
+#define HAVE_ATAN2F 1
+#define HAVE_CEIL 1
+#define HAVE_CEILF 1
+#define HAVE_COPYSIGN 1
+#define HAVE_COPYSIGNF 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_FABS 1
+#define HAVE_FABSF 1
+#define HAVE_FLOOR 1
+#define HAVE_FLOORF 1
+#define HAVE_FMOD 1
+#define HAVE_FMODF 1
+#define HAVE_LOG 1
+#define HAVE_LOGF 1
+#define HAVE_LOG10 1
+#define HAVE_LOG10F 1
+#define HAVE_POW 1
+#define HAVE_POWF 1
+#define HAVE_SCALBN 1
+#define HAVE_SCALBNF 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
+#define HAVE_SQRTF 1
+#define HAVE_TAN 1
+#define HAVE_TANF 1
+#define HAVE_SETJMP 1
+#define HAVE_NANOSLEEP 1
+/* #define HAVE_SYSCONF 1 */
+/* #define HAVE_SIGACTION 1 */
+
+
+/* PSP isn't that sophisticated */
+#define LACKS_SYS_MMAN_H 1
+
+/* Enable the stub thread support (src/thread/psp/\*.c) */
+#define SDL_THREAD_PSP 1
+
+/* Enable the stub timer support (src/timer/psp/\*.c) */
+#define SDL_TIMERS_PSP 1
+
+/* Enable the stub joystick driver (src/joystick/psp/\*.c) */
+#define SDL_JOYSTICK_PSP 1
+
+/* Enable the stub audio driver (src/audio/psp/\*.c) */
+#define SDL_AUDIO_DRIVER_PSP 1
+
+/* PSP video dirver */
+#define SDL_VIDEO_DRIVER_PSP 1
+
+/* PSP render dirver */
+#define SDL_VIDEO_RENDER_PSP 1
+
+#define SDL_POWER_PSP 1
+
+/* !!! FIXME: what does PSP do for filesystem stuff? */
+#define SDL_FILESYSTEM_DUMMY 1
+
+/* PSP doesn't have haptic device (src/haptic/dummy/\*.c) */
+#define SDL_HAPTIC_DISABLED 1
+
+/* PSP can't load shared object (src/loadso/dummy/\*.c) */
+#define SDL_LOADSO_DISABLED 1
+
+
+#endif /* SDL_config_psp_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL_config_windows.h b/src/3rdparty/SDL2/include/SDL_config_windows.h
new file mode 100644
index 0000000..52a9ece
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_config_windows.h
@@ -0,0 +1,248 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_windows_h_
+#define SDL_config_windows_h_
+#define SDL_config_h_
+
+#include "SDL_platform.h"
+
+/* This is a set of defines to configure the SDL features */
+
+#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H)
+#if defined(__GNUC__) || defined(__DMC__) || defined(__WATCOMC__)
+#define HAVE_STDINT_H 1
+#elif defined(_MSC_VER)
+typedef signed __int8 int8_t;
+typedef unsigned __int8 uint8_t;
+typedef signed __int16 int16_t;
+typedef unsigned __int16 uint16_t;
+typedef signed __int32 int32_t;
+typedef unsigned __int32 uint32_t;
+typedef signed __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+#ifndef _UINTPTR_T_DEFINED
+#ifdef _WIN64
+typedef unsigned __int64 uintptr_t;
+#else
+typedef unsigned int uintptr_t;
+#endif
+#define _UINTPTR_T_DEFINED
+#endif
+/* Older Visual C++ headers don't have the Win64-compatible typedefs... */
+#if ((_MSC_VER <= 1200) && (!defined(DWORD_PTR)))
+#define DWORD_PTR DWORD
+#endif
+#if ((_MSC_VER <= 1200) && (!defined(LONG_PTR)))
+#define LONG_PTR LONG
+#endif
+#else /* !__GNUC__ && !_MSC_VER */
+typedef signed char int8_t;
+typedef unsigned char uint8_t;
+typedef signed short int16_t;
+typedef unsigned short uint16_t;
+typedef signed int int32_t;
+typedef unsigned int uint32_t;
+typedef signed long long int64_t;
+typedef unsigned long long uint64_t;
+#ifndef _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED_
+typedef unsigned int size_t;
+#endif
+typedef unsigned int uintptr_t;
+#endif /* __GNUC__ || _MSC_VER */
+#endif /* !_STDINT_H_ && !HAVE_STDINT_H */
+
+#ifdef _WIN64
+# define SIZEOF_VOIDP 8
+#else
+# define SIZEOF_VOIDP 4
+#endif
+
+#define HAVE_DDRAW_H 1
+#define HAVE_DINPUT_H 1
+#define HAVE_DSOUND_H 1
+#define HAVE_DXGI_H 1
+#define HAVE_XINPUT_H 1
+
+/* This is disabled by default to avoid C runtime dependencies and manifest requirements */
+#ifdef HAVE_LIBC
+/* Useful headers */
+#define STDC_HEADERS 1
+#define HAVE_CTYPE_H 1
+#define HAVE_FLOAT_H 1
+#define HAVE_LIMITS_H 1
+#define HAVE_MATH_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDIO_H 1
+#define HAVE_STRING_H 1
+
+/* C library functions */
+#define HAVE_MALLOC 1
+#define HAVE_CALLOC 1
+#define HAVE_REALLOC 1
+#define HAVE_FREE 1
+#define HAVE_ALLOCA 1
+#define HAVE_QSORT 1
+#define HAVE_ABS 1
+#define HAVE_MEMSET 1
+#define HAVE_MEMCPY 1
+#define HAVE_MEMMOVE 1
+#define HAVE_MEMCMP 1
+#define HAVE_STRLEN 1
+#define HAVE__STRREV 1
+/* These functions have security warnings, so we won't use them */
+/* #undef HAVE__STRUPR */
+/* #undef HAVE__STRLWR */
+#define HAVE_STRCHR 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRSTR 1
+/* These functions have security warnings, so we won't use them */
+/* #undef HAVE__LTOA */
+/* #undef HAVE__ULTOA */
+#define HAVE_STRTOL 1
+#define HAVE_STRTOUL 1
+#define HAVE_STRTOD 1
+#define HAVE_ATOI 1
+#define HAVE_ATOF 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
+#define HAVE__STRICMP 1
+#define HAVE__STRNICMP 1
+#define HAVE_ACOS 1
+#define HAVE_ACOSF 1
+#define HAVE_ASIN 1
+#define HAVE_ASINF 1
+#define HAVE_ATAN 1
+#define HAVE_ATANF 1
+#define HAVE_ATAN2 1
+#define HAVE_ATAN2F 1
+#define HAVE_CEILF 1
+#define HAVE__COPYSIGN 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_FABS 1
+#define HAVE_FABSF 1
+#define HAVE_FLOOR 1
+#define HAVE_FLOORF 1
+#define HAVE_FMOD 1
+#define HAVE_FMODF 1
+#define HAVE_LOG 1
+#define HAVE_LOGF 1
+#define HAVE_LOG10 1
+#define HAVE_LOG10F 1
+#define HAVE_POW 1
+#define HAVE_POWF 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
+#define HAVE_SQRTF 1
+#define HAVE_TAN 1
+#define HAVE_TANF 1
+#if defined(_MSC_VER)
+/* These functions were added with the VC++ 2013 C runtime library */
+#if _MSC_VER >= 1800
+#define HAVE_STRTOLL 1
+#define HAVE_VSSCANF 1
+#define HAVE_SCALBN 1
+#define HAVE_SCALBNF 1
+#endif
+/* This function is available with at least the VC++ 2008 C runtime library */
+#if _MSC_VER >= 1400
+#define HAVE__FSEEKI64 1
+#endif
+#endif
+#if !defined(_MSC_VER) || defined(_USE_MATH_DEFINES)
+#define HAVE_M_PI 1
+#endif
+#else
+#define HAVE_STDARG_H 1
+#define HAVE_STDDEF_H 1
+#endif
+
+/* Enable various audio drivers */
+#define SDL_AUDIO_DRIVER_WASAPI 1
+#define SDL_AUDIO_DRIVER_DSOUND 1
+#define SDL_AUDIO_DRIVER_WINMM 1
+#define SDL_AUDIO_DRIVER_DISK 1
+#define SDL_AUDIO_DRIVER_DUMMY 1
+
+/* Enable various input drivers */
+#define SDL_JOYSTICK_DINPUT 1
+#define SDL_JOYSTICK_XINPUT 1
+#define SDL_HAPTIC_DINPUT 1
+#define SDL_HAPTIC_XINPUT 1
+
+/* Enable various shared object loading systems */
+#define SDL_LOADSO_WINDOWS 1
+
+/* Enable various threading systems */
+#define SDL_THREAD_WINDOWS 1
+
+/* Enable various timer systems */
+#define SDL_TIMER_WINDOWS 1
+
+/* Enable various video drivers */
+#define SDL_VIDEO_DRIVER_DUMMY 1
+#define SDL_VIDEO_DRIVER_WINDOWS 1
+
+#ifndef SDL_VIDEO_RENDER_D3D
+#define SDL_VIDEO_RENDER_D3D 1
+#endif
+#ifndef SDL_VIDEO_RENDER_D3D11
+#define SDL_VIDEO_RENDER_D3D11 0
+#endif
+
+/* Enable OpenGL support */
+#ifndef SDL_VIDEO_OPENGL
+#define SDL_VIDEO_OPENGL 1
+#endif
+#ifndef SDL_VIDEO_OPENGL_WGL
+#define SDL_VIDEO_OPENGL_WGL 1
+#endif
+#ifndef SDL_VIDEO_RENDER_OGL
+#define SDL_VIDEO_RENDER_OGL 1
+#endif
+#ifndef SDL_VIDEO_RENDER_OGL_ES2
+#define SDL_VIDEO_RENDER_OGL_ES2 1
+#endif
+#ifndef SDL_VIDEO_OPENGL_ES2
+#define SDL_VIDEO_OPENGL_ES2 1
+#endif
+#ifndef SDL_VIDEO_OPENGL_EGL
+#define SDL_VIDEO_OPENGL_EGL 1
+#endif
+
+/* Enable Vulkan support */
+#define SDL_VIDEO_VULKAN 1
+
+/* Enable system power support */
+#define SDL_POWER_WINDOWS 1
+
+/* Enable filesystem support */
+#define SDL_FILESYSTEM_WINDOWS 1
+
+/* Enable assembly routines (Win64 doesn't have inline asm) */
+#ifndef _WIN64
+#define SDL_ASSEMBLY_ROUTINES 1
+#endif
+
+#endif /* SDL_config_windows_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL_config_winrt.h b/src/3rdparty/SDL2/include/SDL_config_winrt.h
new file mode 100644
index 0000000..aac0e60
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_config_winrt.h
@@ -0,0 +1,230 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_winrt_h_
+#define SDL_config_winrt_h_
+#define SDL_config_h_
+
+#include "SDL_platform.h"
+
+/* Make sure the Windows SDK's NTDDI_VERSION macro gets defined. This is used
+ by SDL to determine which version of the Windows SDK is being used.
+*/
+#include <sdkddkver.h>
+
+/* Define possibly-undefined NTDDI values (used when compiling SDL against
+ older versions of the Windows SDK.
+*/
+#ifndef NTDDI_WINBLUE
+#define NTDDI_WINBLUE 0x06030000
+#endif
+#ifndef NTDDI_WIN10
+#define NTDDI_WIN10 0x0A000000
+#endif
+
+/* This is a set of defines to configure the SDL features */
+
+#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H)
+#if defined(__GNUC__) || defined(__DMC__) || defined(__WATCOMC__)
+#define HAVE_STDINT_H 1
+#elif defined(_MSC_VER)
+typedef signed __int8 int8_t;
+typedef unsigned __int8 uint8_t;
+typedef signed __int16 int16_t;
+typedef unsigned __int16 uint16_t;
+typedef signed __int32 int32_t;
+typedef unsigned __int32 uint32_t;
+typedef signed __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+#ifndef _UINTPTR_T_DEFINED
+#ifdef _WIN64
+typedef unsigned __int64 uintptr_t;
+#else
+typedef unsigned int uintptr_t;
+#endif
+#define _UINTPTR_T_DEFINED
+#endif
+/* Older Visual C++ headers don't have the Win64-compatible typedefs... */
+#if ((_MSC_VER <= 1200) && (!defined(DWORD_PTR)))
+#define DWORD_PTR DWORD
+#endif
+#if ((_MSC_VER <= 1200) && (!defined(LONG_PTR)))
+#define LONG_PTR LONG
+#endif
+#else /* !__GNUC__ && !_MSC_VER */
+typedef signed char int8_t;
+typedef unsigned char uint8_t;
+typedef signed short int16_t;
+typedef unsigned short uint16_t;
+typedef signed int int32_t;
+typedef unsigned int uint32_t;
+typedef signed long long int64_t;
+typedef unsigned long long uint64_t;
+#ifndef _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED_
+typedef unsigned int size_t;
+#endif
+typedef unsigned int uintptr_t;
+#endif /* __GNUC__ || _MSC_VER */
+#endif /* !_STDINT_H_ && !HAVE_STDINT_H */
+
+#ifdef _WIN64
+# define SIZEOF_VOIDP 8
+#else
+# define SIZEOF_VOIDP 4
+#endif
+
+/* Useful headers */
+#define HAVE_DXGI_H 1
+#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
+#define HAVE_XINPUT_H 1
+#endif
+#define HAVE_LIBC 1
+#define STDC_HEADERS 1
+#define HAVE_CTYPE_H 1
+#define HAVE_FLOAT_H 1
+#define HAVE_LIMITS_H 1
+#define HAVE_MATH_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDIO_H 1
+#define HAVE_STRING_H 1
+
+/* C library functions */
+#define HAVE_MALLOC 1
+#define HAVE_CALLOC 1
+#define HAVE_REALLOC 1
+#define HAVE_FREE 1
+#define HAVE_ALLOCA 1
+#define HAVE_QSORT 1
+#define HAVE_ABS 1
+#define HAVE_MEMSET 1
+#define HAVE_MEMCPY 1
+#define HAVE_MEMMOVE 1
+#define HAVE_MEMCMP 1
+#define HAVE_STRLEN 1
+#define HAVE__STRREV 1
+#define HAVE__STRUPR 1
+//#define HAVE__STRLWR 1 // TODO, WinRT: consider using _strlwr_s instead
+#define HAVE_STRCHR 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRSTR 1
+//#define HAVE_ITOA 1 // TODO, WinRT: consider using _itoa_s instead
+//#define HAVE__LTOA 1 // TODO, WinRT: consider using _ltoa_s instead
+//#define HAVE__ULTOA 1 // TODO, WinRT: consider using _ultoa_s instead
+#define HAVE_STRTOL 1
+#define HAVE_STRTOUL 1
+//#define HAVE_STRTOLL 1
+#define HAVE_STRTOD 1
+#define HAVE_ATOI 1
+#define HAVE_ATOF 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
+#define HAVE__STRICMP 1
+#define HAVE__STRNICMP 1
+#define HAVE_VSNPRINTF 1
+//#define HAVE_SSCANF 1 // TODO, WinRT: consider using sscanf_s instead
+#define HAVE_M_PI 1
+#define HAVE_ACOS 1
+#define HAVE_ACOSF 1
+#define HAVE_ASIN 1
+#define HAVE_ASINF 1
+#define HAVE_ATAN 1
+#define HAVE_ATANF 1
+#define HAVE_ATAN2 1
+#define HAVE_ATAN2F 1
+#define HAVE_CEIL 1
+#define HAVE_CEILF 1
+#define HAVE__COPYSIGN 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_FABS 1
+#define HAVE_FABSF 1
+#define HAVE_FLOOR 1
+#define HAVE_FLOORF 1
+#define HAVE_FMOD 1
+#define HAVE_FMODF 1
+#define HAVE_LOG 1
+#define HAVE_LOGF 1
+#define HAVE_LOG10 1
+#define HAVE_LOG10F 1
+#define HAVE_POW 1
+#define HAVE_POWF 1
+#define HAVE__SCALB 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
+#define HAVE_SQRTF 1
+#define HAVE_TAN 1
+#define HAVE_TANF 1
+#define HAVE__FSEEKI64 1
+
+/* Enable various audio drivers */
+#define SDL_AUDIO_DRIVER_WASAPI 1
+#define SDL_AUDIO_DRIVER_DISK 1
+#define SDL_AUDIO_DRIVER_DUMMY 1
+
+/* Enable various input drivers */
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+#define SDL_JOYSTICK_DISABLED 1
+#define SDL_HAPTIC_DISABLED 1
+#else
+#define SDL_JOYSTICK_XINPUT 1
+#define SDL_HAPTIC_XINPUT 1
+#endif
+
+/* Enable various shared object loading systems */
+#define SDL_LOADSO_WINDOWS 1
+
+/* Enable various threading systems */
+#if (NTDDI_VERSION >= NTDDI_WINBLUE)
+#define SDL_THREAD_WINDOWS 1
+#else
+/* WinRT on Windows 8.0 and Windows Phone 8.0 don't support CreateThread() */
+#define SDL_THREAD_STDCPP 1
+#endif
+
+/* Enable various timer systems */
+#define SDL_TIMER_WINDOWS 1
+
+/* Enable various video drivers */
+#define SDL_VIDEO_DRIVER_WINRT 1
+#define SDL_VIDEO_DRIVER_DUMMY 1
+
+/* Enable OpenGL ES 2.0 (via a modified ANGLE library) */
+#define SDL_VIDEO_OPENGL_ES2 1
+#define SDL_VIDEO_OPENGL_EGL 1
+
+/* Enable appropriate renderer(s) */
+#define SDL_VIDEO_RENDER_D3D11 1
+
+#if SDL_VIDEO_OPENGL_ES2
+#define SDL_VIDEO_RENDER_OGL_ES2 1
+#endif
+
+/* Enable system power support */
+#define SDL_POWER_WINRT 1
+
+/* Enable assembly routines (Win64 doesn't have inline asm) */
+#ifndef _WIN64
+#define SDL_ASSEMBLY_ROUTINES 1
+#endif
+
+#endif /* SDL_config_winrt_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL_config_wiz.h b/src/3rdparty/SDL2/include/SDL_config_wiz.h
new file mode 100644
index 0000000..fe86d5e
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_config_wiz.h
@@ -0,0 +1,142 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_config_wiz_h_
+#define SDL_config_wiz_h_
+#define SDL_config_h_
+
+/* This is a set of defines to configure the SDL features */
+
+/* General platform specific identifiers */
+#include "SDL_platform.h"
+
+#define SDL_BYTEORDER 1234
+
+#define STDC_HEADERS 1
+#define HAVE_ALLOCA_H 1
+#define HAVE_CTYPE_H 1
+#define HAVE_ICONV_H 1
+#define HAVE_INTTYPES_H 1
+#define HAVE_LIMITS_H 1
+#define HAVE_MALLOC_H 1
+#define HAVE_MATH_H 1
+#define HAVE_MEMORY_H 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_STDARG_H 1
+#define HAVE_STDINT_H 1
+#define HAVE_STDIO_H 1
+#define HAVE_STDLIB_H 1
+#define HAVE_STRINGS_H 1
+#define HAVE_STRING_H 1
+#define HAVE_SYS_TYPES_H 1
+
+#define HAVE_MALLOC 1
+#define HAVE_CALLOC 1
+#define HAVE_REALLOC 1
+#define HAVE_FREE 1
+#define HAVE_ALLOCA 1
+#define HAVE_GETENV 1
+#define HAVE_SETENV 1
+#define HAVE_PUTENV 1
+#define HAVE_UNSETENV 1
+#define HAVE_QSORT 1
+#define HAVE_ABS 1
+#define HAVE_BCOPY 1
+#define HAVE_MEMSET 1
+#define HAVE_MEMCPY 1
+#define HAVE_MEMMOVE 1
+#define HAVE_STRLEN 1
+#define HAVE_STRCHR 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRSTR 1
+#define HAVE_STRTOL 1
+#define HAVE_STRTOUL 1
+#define HAVE_STRTOLL 1
+#define HAVE_STRTOULL 1
+#define HAVE_ATOI 1
+#define HAVE_ATOF 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
+#define HAVE_STRCASECMP 1
+#define HAVE_STRNCASECMP 1
+#define HAVE_VSSCANF 1
+#define HAVE_VSNPRINTF 1
+#define HAVE_M_PI 1
+#define HAVE_ACOS 1
+#define HAVE_ACOSF 1
+#define HAVE_ASIN 1
+#define HAVE_ASINF 1
+#define HAVE_ATAN 1
+#define HAVE_ATANF 1
+#define HAVE_ATAN2 1
+#define HAVE_ATAN2F 1
+#define HAVE_CEIL 1
+#define HAVE_CEILF 1
+#define HAVE_COPYSIGN 1
+#define HAVE_COPYSIGNF 1
+#define HAVE_COS 1
+#define HAVE_COSF 1
+#define HAVE_FABS 1
+#define HAVE_FABSF 1
+#define HAVE_FLOOR 1
+#define HAVE_FLOORF 1
+#define HAVE_FMOD 1
+#define HAVE_FMODF 1
+#define HAVE_LOG 1
+#define HAVE_LOGF 1
+#define HAVE_LOG10 1
+#define HAVE_LOG10F 1
+#define HAVE_POW 1
+#define HAVE_POWF 1
+#define HAVE_SCALBN 1
+#define HAVE_SCALBNF 1
+#define HAVE_SIN 1
+#define HAVE_SINF 1
+#define HAVE_SQRT 1
+#define HAVE_SQRTF 1
+#define HAVE_TAN 1
+#define HAVE_TANF 1
+#define HAVE_SIGACTION 1
+#define HAVE_SETJMP 1
+#define HAVE_NANOSLEEP 1
+#define HAVE_POW 1
+
+#define SDL_AUDIO_DRIVER_DUMMY 1
+#define SDL_AUDIO_DRIVER_OSS 1
+
+#define SDL_INPUT_LINUXEV 1
+#define SDL_INPUT_TSLIB 1
+#define SDL_JOYSTICK_LINUX 1
+#define SDL_HAPTIC_LINUX 1
+
+#define SDL_LOADSO_DLOPEN 1
+
+#define SDL_THREAD_PTHREAD 1
+#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1
+
+#define SDL_TIMER_UNIX 1
+
+#define SDL_VIDEO_DRIVER_DUMMY 1
+#define SDL_VIDEO_DRIVER_PANDORA 1
+#define SDL_VIDEO_RENDER_OGL_ES 1
+#define SDL_VIDEO_OPENGL_ES 1
+
+#endif /* SDL_config_wiz_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL_copying.h b/src/3rdparty/SDL2/include/SDL_copying.h
new file mode 100644
index 0000000..15616ac
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_copying.h
@@ -0,0 +1,20 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
diff --git a/src/3rdparty/SDL2/include/SDL_cpuinfo.h b/src/3rdparty/SDL2/include/SDL_cpuinfo.h
new file mode 100644
index 0000000..0812705
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_cpuinfo.h
@@ -0,0 +1,181 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_cpuinfo.h
+ *
+ * CPU feature detection for SDL.
+ */
+
+#ifndef SDL_cpuinfo_h_
+#define SDL_cpuinfo_h_
+
+#include "SDL_stdinc.h"
+
+/* Need to do this here because intrin.h has C++ code in it */
+/* Visual Studio 2005 has a bug where intrin.h conflicts with winnt.h */
+#if defined(_MSC_VER) && (_MSC_VER >= 1500) && (defined(_M_IX86) || defined(_M_X64))
+#ifdef __clang__
+/* Many of the intrinsics SDL uses are not implemented by clang with Visual Studio */
+#undef __MMX__
+#undef __SSE__
+#undef __SSE2__
+#else
+#include <intrin.h>
+#ifndef _WIN64
+#define __MMX__
+#define __3dNOW__
+#endif
+#define __SSE__
+#define __SSE2__
+#endif /* __clang__ */
+#elif defined(__MINGW64_VERSION_MAJOR)
+#include <intrin.h>
+#else
+#ifdef __ALTIVEC__
+#if HAVE_ALTIVEC_H && !defined(__APPLE_ALTIVEC__) && !defined(SDL_DISABLE_ALTIVEC_H)
+#include <altivec.h>
+#undef pixel
+#undef bool
+#endif
+#endif
+#if defined(__3dNOW__) && !defined(SDL_DISABLE_MM3DNOW_H)
+#include <mm3dnow.h>
+#endif
+#if HAVE_IMMINTRIN_H && !defined(SDL_DISABLE_IMMINTRIN_H)
+#include <immintrin.h>
+#else
+#if defined(__MMX__) && !defined(SDL_DISABLE_MMINTRIN_H)
+#include <mmintrin.h>
+#endif
+#if defined(__SSE__) && !defined(SDL_DISABLE_XMMINTRIN_H)
+#include <xmmintrin.h>
+#endif
+#if defined(__SSE2__) && !defined(SDL_DISABLE_EMMINTRIN_H)
+#include <emmintrin.h>
+#endif
+#if defined(__SSE3__) && !defined(SDL_DISABLE_PMMINTRIN_H)
+#include <pmmintrin.h>
+#endif
+#endif /* HAVE_IMMINTRIN_H */
+#endif /* compiler version */
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* This is a guess for the cacheline size used for padding.
+ * Most x86 processors have a 64 byte cache line.
+ * The 64-bit PowerPC processors have a 128 byte cache line.
+ * We'll use the larger value to be generally safe.
+ */
+#define SDL_CACHELINE_SIZE 128
+
+/**
+ * This function returns the number of CPU cores available.
+ */
+extern DECLSPEC int SDLCALL SDL_GetCPUCount(void);
+
+/**
+ * This function returns the L1 cache line size of the CPU
+ *
+ * This is useful for determining multi-threaded structure padding
+ * or SIMD prefetch sizes.
+ */
+extern DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void);
+
+/**
+ * This function returns true if the CPU has the RDTSC instruction.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void);
+
+/**
+ * This function returns true if the CPU has AltiVec features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void);
+
+/**
+ * This function returns true if the CPU has MMX features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void);
+
+/**
+ * This function returns true if the CPU has 3DNow! features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void);
+
+/**
+ * This function returns true if the CPU has SSE features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void);
+
+/**
+ * This function returns true if the CPU has SSE2 features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void);
+
+/**
+ * This function returns true if the CPU has SSE3 features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void);
+
+/**
+ * This function returns true if the CPU has SSE4.1 features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void);
+
+/**
+ * This function returns true if the CPU has SSE4.2 features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void);
+
+/**
+ * This function returns true if the CPU has AVX features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX(void);
+
+/**
+ * This function returns true if the CPU has AVX2 features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX2(void);
+
+/**
+ * This function returns true if the CPU has NEON (ARM SIMD) features.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasNEON(void);
+
+/**
+ * This function returns the amount of RAM configured in the system, in MB.
+ */
+extern DECLSPEC int SDLCALL SDL_GetSystemRAM(void);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_cpuinfo_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_egl.h b/src/3rdparty/SDL2/include/SDL_egl.h
new file mode 100644
index 0000000..d65ed43
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_egl.h
@@ -0,0 +1,1673 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_egl.h
+ *
+ * This is a simple file to encapsulate the EGL API headers.
+ */
+#if !defined(_MSC_VER) && !defined(__ANDROID__)
+
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+#else /* _MSC_VER */
+
+/* EGL headers for Visual Studio */
+
+#ifndef __khrplatform_h_
+#define __khrplatform_h_
+
+/*
+** Copyright (c) 2008-2009 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+
+/* Khronos platform-specific types and definitions.
+*
+* $Revision: 23298 $ on $Date: 2013-09-30 17:07:13 -0700 (Mon, 30 Sep 2013) $
+*
+* Adopters may modify this file to suit their platform. Adopters are
+* encouraged to submit platform specific modifications to the Khronos
+* group so that they can be included in future versions of this file.
+* Please submit changes by sending them to the public Khronos Bugzilla
+* (http://khronos.org/bugzilla) by filing a bug against product
+* "Khronos (general)" component "Registry".
+*
+* A predefined template which fills in some of the bug fields can be
+* reached using http://tinyurl.com/khrplatform-h-bugreport, but you
+* must create a Bugzilla login first.
+*
+*
+* See the Implementer's Guidelines for information about where this file
+* should be located on your system and for more details of its use:
+* http://www.khronos.org/registry/implementers_guide.pdf
+*
+* This file should be included as
+* #include <KHR/khrplatform.h>
+* by Khronos client API header files that use its types and defines.
+*
+* The types in khrplatform.h should only be used to define API-specific types.
+*
+* Types defined in khrplatform.h:
+* khronos_int8_t signed 8 bit
+* khronos_uint8_t unsigned 8 bit
+* khronos_int16_t signed 16 bit
+* khronos_uint16_t unsigned 16 bit
+* khronos_int32_t signed 32 bit
+* khronos_uint32_t unsigned 32 bit
+* khronos_int64_t signed 64 bit
+* khronos_uint64_t unsigned 64 bit
+* khronos_intptr_t signed same number of bits as a pointer
+* khronos_uintptr_t unsigned same number of bits as a pointer
+* khronos_ssize_t signed size
+* khronos_usize_t unsigned size
+* khronos_float_t signed 32 bit floating point
+* khronos_time_ns_t unsigned 64 bit time in nanoseconds
+* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
+* nanoseconds
+* khronos_stime_nanoseconds_t signed time interval in nanoseconds
+* khronos_boolean_enum_t enumerated boolean type. This should
+* only be used as a base type when a client API's boolean type is
+* an enum. Client APIs which use an integer or other type for
+* booleans cannot use this as the base type for their boolean.
+*
+* Tokens defined in khrplatform.h:
+*
+* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
+*
+* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
+* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
+*
+* Calling convention macros defined in this file:
+* KHRONOS_APICALL
+* KHRONOS_APIENTRY
+* KHRONOS_APIATTRIBUTES
+*
+* These may be used in function prototypes as:
+*
+* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
+* int arg1,
+* int arg2) KHRONOS_APIATTRIBUTES;
+*/
+
+/*-------------------------------------------------------------------------
+* Definition of KHRONOS_APICALL
+*-------------------------------------------------------------------------
+* This precedes the return type of the function in the function prototype.
+*/
+#if defined(_WIN32) && !defined(__SCITECH_SNAP__) && !defined(SDL_VIDEO_STATIC_ANGLE)
+# define KHRONOS_APICALL __declspec(dllimport)
+#elif defined (__SYMBIAN32__)
+# define KHRONOS_APICALL IMPORT_C
+#else
+# define KHRONOS_APICALL
+#endif
+
+/*-------------------------------------------------------------------------
+* Definition of KHRONOS_APIENTRY
+*-------------------------------------------------------------------------
+* This follows the return type of the function and precedes the function
+* name in the function prototype.
+*/
+#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
+/* Win32 but not WinCE */
+# define KHRONOS_APIENTRY __stdcall
+#else
+# define KHRONOS_APIENTRY
+#endif
+
+/*-------------------------------------------------------------------------
+* Definition of KHRONOS_APIATTRIBUTES
+*-------------------------------------------------------------------------
+* This follows the closing parenthesis of the function prototype arguments.
+*/
+#if defined (__ARMCC_2__)
+#define KHRONOS_APIATTRIBUTES __softfp
+#else
+#define KHRONOS_APIATTRIBUTES
+#endif
+
+/*-------------------------------------------------------------------------
+* basic type definitions
+*-----------------------------------------------------------------------*/
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
+
+
+/*
+* Using <stdint.h>
+*/
+#include <stdint.h>
+typedef int32_t khronos_int32_t;
+typedef uint32_t khronos_uint32_t;
+typedef int64_t khronos_int64_t;
+typedef uint64_t khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif defined(__VMS ) || defined(__sgi)
+
+/*
+* Using <inttypes.h>
+*/
+#include <inttypes.h>
+typedef int32_t khronos_int32_t;
+typedef uint32_t khronos_uint32_t;
+typedef int64_t khronos_int64_t;
+typedef uint64_t khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
+
+/*
+* Win32
+*/
+typedef __int32 khronos_int32_t;
+typedef unsigned __int32 khronos_uint32_t;
+typedef __int64 khronos_int64_t;
+typedef unsigned __int64 khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif defined(__sun__) || defined(__digital__)
+
+/*
+* Sun or Digital
+*/
+typedef int khronos_int32_t;
+typedef unsigned int khronos_uint32_t;
+#if defined(__arch64__) || defined(_LP64)
+typedef long int khronos_int64_t;
+typedef unsigned long int khronos_uint64_t;
+#else
+typedef long long int khronos_int64_t;
+typedef unsigned long long int khronos_uint64_t;
+#endif /* __arch64__ */
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif 0
+
+/*
+* Hypothetical platform with no float or int64 support
+*/
+typedef int khronos_int32_t;
+typedef unsigned int khronos_uint32_t;
+#define KHRONOS_SUPPORT_INT64 0
+#define KHRONOS_SUPPORT_FLOAT 0
+
+#else
+
+/*
+* Generic fallback
+*/
+#include <stdint.h>
+typedef int32_t khronos_int32_t;
+typedef uint32_t khronos_uint32_t;
+typedef int64_t khronos_int64_t;
+typedef uint64_t khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#endif
+
+
+/*
+* Types that are (so far) the same on all platforms
+*/
+typedef signed char khronos_int8_t;
+typedef unsigned char khronos_uint8_t;
+typedef signed short int khronos_int16_t;
+typedef unsigned short int khronos_uint16_t;
+
+/*
+* Types that differ between LLP64 and LP64 architectures - in LLP64,
+* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
+* to be the only LLP64 architecture in current use.
+*/
+#ifdef _WIN64
+typedef signed long long int khronos_intptr_t;
+typedef unsigned long long int khronos_uintptr_t;
+typedef signed long long int khronos_ssize_t;
+typedef unsigned long long int khronos_usize_t;
+#else
+typedef signed long int khronos_intptr_t;
+typedef unsigned long int khronos_uintptr_t;
+typedef signed long int khronos_ssize_t;
+typedef unsigned long int khronos_usize_t;
+#endif
+
+#if KHRONOS_SUPPORT_FLOAT
+/*
+* Float type
+*/
+typedef float khronos_float_t;
+#endif
+
+#if KHRONOS_SUPPORT_INT64
+/* Time types
+*
+* These types can be used to represent a time interval in nanoseconds or
+* an absolute Unadjusted System Time. Unadjusted System Time is the number
+* of nanoseconds since some arbitrary system event (e.g. since the last
+* time the system booted). The Unadjusted System Time is an unsigned
+* 64 bit value that wraps back to 0 every 584 years. Time intervals
+* may be either signed or unsigned.
+*/
+typedef khronos_uint64_t khronos_utime_nanoseconds_t;
+typedef khronos_int64_t khronos_stime_nanoseconds_t;
+#endif
+
+/*
+* Dummy value used to pad enum types to 32 bits.
+*/
+#ifndef KHRONOS_MAX_ENUM
+#define KHRONOS_MAX_ENUM 0x7FFFFFFF
+#endif
+
+/*
+* Enumerated boolean type
+*
+* Values other than zero should be considered to be true. Therefore
+* comparisons should not be made against KHRONOS_TRUE.
+*/
+typedef enum {
+ KHRONOS_FALSE = 0,
+ KHRONOS_TRUE = 1,
+ KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
+} khronos_boolean_enum_t;
+
+#endif /* __khrplatform_h_ */
+
+
+#ifndef __eglplatform_h_
+#define __eglplatform_h_
+
+/*
+** Copyright (c) 2007-2009 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+
+/* Platform-specific types and definitions for egl.h
+* $Revision: 12306 $ on $Date: 2010-08-25 09:51:28 -0700 (Wed, 25 Aug 2010) $
+*
+* Adopters may modify khrplatform.h and this file to suit their platform.
+* You are encouraged to submit all modifications to the Khronos group so that
+* they can be included in future versions of this file. Please submit changes
+* by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla)
+* by filing a bug against product "EGL" component "Registry".
+*/
+
+/*#include <KHR/khrplatform.h>*/
+
+/* Macros used in EGL function prototype declarations.
+*
+* EGL functions should be prototyped as:
+*
+* EGLAPI return-type EGLAPIENTRY eglFunction(arguments);
+* typedef return-type (EXPAPIENTRYP PFNEGLFUNCTIONPROC) (arguments);
+*
+* KHRONOS_APICALL and KHRONOS_APIENTRY are defined in KHR/khrplatform.h
+*/
+
+#ifndef EGLAPI
+#define EGLAPI KHRONOS_APICALL
+#endif
+
+#ifndef EGLAPIENTRY
+#define EGLAPIENTRY KHRONOS_APIENTRY
+#endif
+#define EGLAPIENTRYP EGLAPIENTRY*
+
+/* The types NativeDisplayType, NativeWindowType, and NativePixmapType
+* are aliases of window-system-dependent types, such as X Display * or
+* Windows Device Context. They must be defined in platform-specific
+* code below. The EGL-prefixed versions of Native*Type are the same
+* types, renamed in EGL 1.3 so all types in the API start with "EGL".
+*
+* Khronos STRONGLY RECOMMENDS that you use the default definitions
+* provided below, since these changes affect both binary and source
+* portability of applications using EGL running on different EGL
+* implementations.
+*/
+
+#if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN 1
+#endif
+#include <windows.h>
+
+#if __WINRT__
+#include <Unknwn.h>
+typedef IUnknown * EGLNativeWindowType;
+typedef IUnknown * EGLNativePixmapType;
+typedef IUnknown * EGLNativeDisplayType;
+#else
+typedef HDC EGLNativeDisplayType;
+typedef HBITMAP EGLNativePixmapType;
+typedef HWND EGLNativeWindowType;
+#endif
+
+#elif defined(__WINSCW__) || defined(__SYMBIAN32__) /* Symbian */
+
+typedef int EGLNativeDisplayType;
+typedef void *EGLNativeWindowType;
+typedef void *EGLNativePixmapType;
+
+#elif defined(WL_EGL_PLATFORM)
+
+typedef struct wl_display *EGLNativeDisplayType;
+typedef struct wl_egl_pixmap *EGLNativePixmapType;
+typedef struct wl_egl_window *EGLNativeWindowType;
+
+#elif defined(__GBM__)
+
+typedef struct gbm_device *EGLNativeDisplayType;
+typedef struct gbm_bo *EGLNativePixmapType;
+typedef void *EGLNativeWindowType;
+
+#elif defined(__ANDROID__) /* Android */
+
+struct ANativeWindow;
+struct egl_native_pixmap_t;
+
+typedef struct ANativeWindow *EGLNativeWindowType;
+typedef struct egl_native_pixmap_t *EGLNativePixmapType;
+typedef void *EGLNativeDisplayType;
+
+#elif defined(MIR_EGL_PLATFORM)
+
+#include <mir_toolkit/mir_client_library.h>
+typedef MirEGLNativeDisplayType EGLNativeDisplayType;
+typedef void *EGLNativePixmapType;
+typedef MirEGLNativeWindowType EGLNativeWindowType;
+
+#elif defined(__unix__)
+
+#ifdef MESA_EGL_NO_X11_HEADERS
+
+typedef void *EGLNativeDisplayType;
+typedef khronos_uintptr_t EGLNativePixmapType;
+typedef khronos_uintptr_t EGLNativeWindowType;
+
+#else
+
+/* X11 (tentative) */
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+typedef Display *EGLNativeDisplayType;
+typedef Pixmap EGLNativePixmapType;
+typedef Window EGLNativeWindowType;
+
+#endif /* MESA_EGL_NO_X11_HEADERS */
+
+#else
+#error "Platform not recognized"
+#endif
+
+/* EGL 1.2 types, renamed for consistency in EGL 1.3 */
+typedef EGLNativeDisplayType NativeDisplayType;
+typedef EGLNativePixmapType NativePixmapType;
+typedef EGLNativeWindowType NativeWindowType;
+
+
+/* Define EGLint. This must be a signed integral type large enough to contain
+* all legal attribute names and values passed into and out of EGL, whether
+* their type is boolean, bitmask, enumerant (symbolic constant), integer,
+* handle, or other. While in general a 32-bit integer will suffice, if
+* handles are 64 bit types, then EGLint should be defined as a signed 64-bit
+* integer type.
+*/
+typedef khronos_int32_t EGLint;
+
+#endif /* __eglplatform_h */
+
+#ifndef __egl_h_
+#define __egl_h_ 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+** Copyright (c) 2013-2015 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+/*
+** This header is generated from the Khronos OpenGL / OpenGL ES XML
+** API Registry. The current version of the Registry, generator scripts
+** used to make the header, and the header can be found at
+** http://www.opengl.org/registry/
+**
+** Khronos $Revision: 31566 $ on $Date: 2015-06-23 08:48:48 -0700 (Tue, 23 Jun 2015) $
+*/
+
+/*#include <EGL/eglplatform.h>*/
+
+/* Generated on date 20150623 */
+
+/* Generated C header for:
+ * API: egl
+ * Versions considered: .*
+ * Versions emitted: .*
+ * Default extensions included: None
+ * Additional extensions included: _nomatch_^
+ * Extensions removed: _nomatch_^
+ */
+
+#ifndef EGL_VERSION_1_0
+#define EGL_VERSION_1_0 1
+typedef unsigned int EGLBoolean;
+typedef void *EGLDisplay;
+typedef void *EGLConfig;
+typedef void *EGLSurface;
+typedef void *EGLContext;
+typedef void (*__eglMustCastToProperFunctionPointerType)(void);
+#define EGL_ALPHA_SIZE 0x3021
+#define EGL_BAD_ACCESS 0x3002
+#define EGL_BAD_ALLOC 0x3003
+#define EGL_BAD_ATTRIBUTE 0x3004
+#define EGL_BAD_CONFIG 0x3005
+#define EGL_BAD_CONTEXT 0x3006
+#define EGL_BAD_CURRENT_SURFACE 0x3007
+#define EGL_BAD_DISPLAY 0x3008
+#define EGL_BAD_MATCH 0x3009
+#define EGL_BAD_NATIVE_PIXMAP 0x300A
+#define EGL_BAD_NATIVE_WINDOW 0x300B
+#define EGL_BAD_PARAMETER 0x300C
+#define EGL_BAD_SURFACE 0x300D
+#define EGL_BLUE_SIZE 0x3022
+#define EGL_BUFFER_SIZE 0x3020
+#define EGL_CONFIG_CAVEAT 0x3027
+#define EGL_CONFIG_ID 0x3028
+#define EGL_CORE_NATIVE_ENGINE 0x305B
+#define EGL_DEPTH_SIZE 0x3025
+#define EGL_DONT_CARE ((EGLint)-1)
+#define EGL_DRAW 0x3059
+#define EGL_EXTENSIONS 0x3055
+#define EGL_FALSE 0
+#define EGL_GREEN_SIZE 0x3023
+#define EGL_HEIGHT 0x3056
+#define EGL_LARGEST_PBUFFER 0x3058
+#define EGL_LEVEL 0x3029
+#define EGL_MAX_PBUFFER_HEIGHT 0x302A
+#define EGL_MAX_PBUFFER_PIXELS 0x302B
+#define EGL_MAX_PBUFFER_WIDTH 0x302C
+#define EGL_NATIVE_RENDERABLE 0x302D
+#define EGL_NATIVE_VISUAL_ID 0x302E
+#define EGL_NATIVE_VISUAL_TYPE 0x302F
+#define EGL_NONE 0x3038
+#define EGL_NON_CONFORMANT_CONFIG 0x3051
+#define EGL_NOT_INITIALIZED 0x3001
+#define EGL_NO_CONTEXT ((EGLContext)0)
+#define EGL_NO_DISPLAY ((EGLDisplay)0)
+#define EGL_NO_SURFACE ((EGLSurface)0)
+#define EGL_PBUFFER_BIT 0x0001
+#define EGL_PIXMAP_BIT 0x0002
+#define EGL_READ 0x305A
+#define EGL_RED_SIZE 0x3024
+#define EGL_SAMPLES 0x3031
+#define EGL_SAMPLE_BUFFERS 0x3032
+#define EGL_SLOW_CONFIG 0x3050
+#define EGL_STENCIL_SIZE 0x3026
+#define EGL_SUCCESS 0x3000
+#define EGL_SURFACE_TYPE 0x3033
+#define EGL_TRANSPARENT_BLUE_VALUE 0x3035
+#define EGL_TRANSPARENT_GREEN_VALUE 0x3036
+#define EGL_TRANSPARENT_RED_VALUE 0x3037
+#define EGL_TRANSPARENT_RGB 0x3052
+#define EGL_TRANSPARENT_TYPE 0x3034
+#define EGL_TRUE 1
+#define EGL_VENDOR 0x3053
+#define EGL_VERSION 0x3054
+#define EGL_WIDTH 0x3057
+#define EGL_WINDOW_BIT 0x0004
+EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig (EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
+EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers (EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target);
+EGLAPI EGLContext EGLAPIENTRY eglCreateContext (EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferSurface (EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurface (EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface (EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext (EGLDisplay dpy, EGLContext ctx);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface (EGLDisplay dpy, EGLSurface surface);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib (EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs (EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
+EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay (void);
+EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface (EGLint readdraw);
+EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay (EGLNativeDisplayType display_id);
+EGLAPI EGLint EGLAPIENTRY eglGetError (void);
+EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress (const char *procname);
+EGLAPI EGLBoolean EGLAPIENTRY eglInitialize (EGLDisplay dpy, EGLint *major, EGLint *minor);
+EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent (EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext (EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value);
+EGLAPI const char *EGLAPIENTRY eglQueryString (EGLDisplay dpy, EGLint name);
+EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers (EGLDisplay dpy, EGLSurface surface);
+EGLAPI EGLBoolean EGLAPIENTRY eglTerminate (EGLDisplay dpy);
+EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL (void);
+EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative (EGLint engine);
+#endif /* EGL_VERSION_1_0 */
+
+#ifndef EGL_VERSION_1_1
+#define EGL_VERSION_1_1 1
+#define EGL_BACK_BUFFER 0x3084
+#define EGL_BIND_TO_TEXTURE_RGB 0x3039
+#define EGL_BIND_TO_TEXTURE_RGBA 0x303A
+#define EGL_CONTEXT_LOST 0x300E
+#define EGL_MIN_SWAP_INTERVAL 0x303B
+#define EGL_MAX_SWAP_INTERVAL 0x303C
+#define EGL_MIPMAP_TEXTURE 0x3082
+#define EGL_MIPMAP_LEVEL 0x3083
+#define EGL_NO_TEXTURE 0x305C
+#define EGL_TEXTURE_2D 0x305F
+#define EGL_TEXTURE_FORMAT 0x3080
+#define EGL_TEXTURE_RGB 0x305D
+#define EGL_TEXTURE_RGBA 0x305E
+#define EGL_TEXTURE_TARGET 0x3081
+EGLAPI EGLBoolean EGLAPIENTRY eglBindTexImage (EGLDisplay dpy, EGLSurface surface, EGLint buffer);
+EGLAPI EGLBoolean EGLAPIENTRY eglReleaseTexImage (EGLDisplay dpy, EGLSurface surface, EGLint buffer);
+EGLAPI EGLBoolean EGLAPIENTRY eglSurfaceAttrib (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value);
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval (EGLDisplay dpy, EGLint interval);
+#endif /* EGL_VERSION_1_1 */
+
+#ifndef EGL_VERSION_1_2
+#define EGL_VERSION_1_2 1
+typedef unsigned int EGLenum;
+typedef void *EGLClientBuffer;
+#define EGL_ALPHA_FORMAT 0x3088
+#define EGL_ALPHA_FORMAT_NONPRE 0x308B
+#define EGL_ALPHA_FORMAT_PRE 0x308C
+#define EGL_ALPHA_MASK_SIZE 0x303E
+#define EGL_BUFFER_PRESERVED 0x3094
+#define EGL_BUFFER_DESTROYED 0x3095
+#define EGL_CLIENT_APIS 0x308D
+#define EGL_COLORSPACE 0x3087
+#define EGL_COLORSPACE_sRGB 0x3089
+#define EGL_COLORSPACE_LINEAR 0x308A
+#define EGL_COLOR_BUFFER_TYPE 0x303F
+#define EGL_CONTEXT_CLIENT_TYPE 0x3097
+#define EGL_DISPLAY_SCALING 10000
+#define EGL_HORIZONTAL_RESOLUTION 0x3090
+#define EGL_LUMINANCE_BUFFER 0x308F
+#define EGL_LUMINANCE_SIZE 0x303D
+#define EGL_OPENGL_ES_BIT 0x0001
+#define EGL_OPENVG_BIT 0x0002
+#define EGL_OPENGL_ES_API 0x30A0
+#define EGL_OPENVG_API 0x30A1
+#define EGL_OPENVG_IMAGE 0x3096
+#define EGL_PIXEL_ASPECT_RATIO 0x3092
+#define EGL_RENDERABLE_TYPE 0x3040
+#define EGL_RENDER_BUFFER 0x3086
+#define EGL_RGB_BUFFER 0x308E
+#define EGL_SINGLE_BUFFER 0x3085
+#define EGL_SWAP_BEHAVIOR 0x3093
+#define EGL_UNKNOWN ((EGLint)-1)
+#define EGL_VERTICAL_RESOLUTION 0x3091
+EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI (EGLenum api);
+EGLAPI EGLenum EGLAPIENTRY eglQueryAPI (void);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferFromClientBuffer (EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglReleaseThread (void);
+EGLAPI EGLBoolean EGLAPIENTRY eglWaitClient (void);
+#endif /* EGL_VERSION_1_2 */
+
+#ifndef EGL_VERSION_1_3
+#define EGL_VERSION_1_3 1
+#define EGL_CONFORMANT 0x3042
+#define EGL_CONTEXT_CLIENT_VERSION 0x3098
+#define EGL_MATCH_NATIVE_PIXMAP 0x3041
+#define EGL_OPENGL_ES2_BIT 0x0004
+#define EGL_VG_ALPHA_FORMAT 0x3088
+#define EGL_VG_ALPHA_FORMAT_NONPRE 0x308B
+#define EGL_VG_ALPHA_FORMAT_PRE 0x308C
+#define EGL_VG_ALPHA_FORMAT_PRE_BIT 0x0040
+#define EGL_VG_COLORSPACE 0x3087
+#define EGL_VG_COLORSPACE_sRGB 0x3089
+#define EGL_VG_COLORSPACE_LINEAR 0x308A
+#define EGL_VG_COLORSPACE_LINEAR_BIT 0x0020
+#endif /* EGL_VERSION_1_3 */
+
+#ifndef EGL_VERSION_1_4
+#define EGL_VERSION_1_4 1
+#define EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType)0)
+#define EGL_MULTISAMPLE_RESOLVE_BOX_BIT 0x0200
+#define EGL_MULTISAMPLE_RESOLVE 0x3099
+#define EGL_MULTISAMPLE_RESOLVE_DEFAULT 0x309A
+#define EGL_MULTISAMPLE_RESOLVE_BOX 0x309B
+#define EGL_OPENGL_API 0x30A2
+#define EGL_OPENGL_BIT 0x0008
+#define EGL_SWAP_BEHAVIOR_PRESERVED_BIT 0x0400
+EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext (void);
+#endif /* EGL_VERSION_1_4 */
+
+#ifndef EGL_VERSION_1_5
+#define EGL_VERSION_1_5 1
+typedef void *EGLSync;
+typedef intptr_t EGLAttrib;
+typedef khronos_utime_nanoseconds_t EGLTime;
+typedef void *EGLImage;
+#define EGL_CONTEXT_MAJOR_VERSION 0x3098
+#define EGL_CONTEXT_MINOR_VERSION 0x30FB
+#define EGL_CONTEXT_OPENGL_PROFILE_MASK 0x30FD
+#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY 0x31BD
+#define EGL_NO_RESET_NOTIFICATION 0x31BE
+#define EGL_LOSE_CONTEXT_ON_RESET 0x31BF
+#define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT 0x00000001
+#define EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT 0x00000002
+#define EGL_CONTEXT_OPENGL_DEBUG 0x31B0
+#define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE 0x31B1
+#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS 0x31B2
+#define EGL_OPENGL_ES3_BIT 0x00000040
+#define EGL_CL_EVENT_HANDLE 0x309C
+#define EGL_SYNC_CL_EVENT 0x30FE
+#define EGL_SYNC_CL_EVENT_COMPLETE 0x30FF
+#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE 0x30F0
+#define EGL_SYNC_TYPE 0x30F7
+#define EGL_SYNC_STATUS 0x30F1
+#define EGL_SYNC_CONDITION 0x30F8
+#define EGL_SIGNALED 0x30F2
+#define EGL_UNSIGNALED 0x30F3
+#define EGL_SYNC_FLUSH_COMMANDS_BIT 0x0001
+#define EGL_FOREVER 0xFFFFFFFFFFFFFFFFull
+#define EGL_TIMEOUT_EXPIRED 0x30F5
+#define EGL_CONDITION_SATISFIED 0x30F6
+#define EGL_NO_SYNC ((EGLSync)0)
+#define EGL_SYNC_FENCE 0x30F9
+#define EGL_GL_COLORSPACE 0x309D
+#define EGL_GL_COLORSPACE_SRGB 0x3089
+#define EGL_GL_COLORSPACE_LINEAR 0x308A
+#define EGL_GL_RENDERBUFFER 0x30B9
+#define EGL_GL_TEXTURE_2D 0x30B1
+#define EGL_GL_TEXTURE_LEVEL 0x30BC
+#define EGL_GL_TEXTURE_3D 0x30B2
+#define EGL_GL_TEXTURE_ZOFFSET 0x30BD
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x30B3
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x30B4
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x30B5
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x30B6
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x30B7
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x30B8
+#define EGL_IMAGE_PRESERVED 0x30D2
+#define EGL_NO_IMAGE ((EGLImage)0)
+EGLAPI EGLSync EGLAPIENTRY eglCreateSync (EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroySync (EGLDisplay dpy, EGLSync sync);
+EGLAPI EGLint EGLAPIENTRY eglClientWaitSync (EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttrib (EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value);
+EGLAPI EGLImage EGLAPIENTRY eglCreateImage (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImage (EGLDisplay dpy, EGLImage image);
+EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplay (EGLenum platform, void *native_display, const EGLAttrib *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformWindowSurface (EGLDisplay dpy, EGLConfig config, void *native_window, const EGLAttrib *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformPixmapSurface (EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLAttrib *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglWaitSync (EGLDisplay dpy, EGLSync sync, EGLint flags);
+#endif /* EGL_VERSION_1_5 */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __egl_h_ */
+
+
+
+#ifndef __eglext_h_
+#define __eglext_h_ 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+** Copyright (c) 2013-2015 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+/*
+** This header is generated from the Khronos OpenGL / OpenGL ES XML
+** API Registry. The current version of the Registry, generator scripts
+** used to make the header, and the header can be found at
+** http://www.opengl.org/registry/
+**
+** Khronos $Revision: 31566 $ on $Date: 2015-06-23 08:48:48 -0700 (Tue, 23 Jun 2015) $
+*/
+
+/*#include <EGL/eglplatform.h>*/
+
+#define EGL_EGLEXT_VERSION 20150623
+
+/* Generated C header for:
+ * API: egl
+ * Versions considered: .*
+ * Versions emitted: _nomatch_^
+ * Default extensions included: egl
+ * Additional extensions included: _nomatch_^
+ * Extensions removed: _nomatch_^
+ */
+
+#ifndef EGL_KHR_cl_event
+#define EGL_KHR_cl_event 1
+#define EGL_CL_EVENT_HANDLE_KHR 0x309C
+#define EGL_SYNC_CL_EVENT_KHR 0x30FE
+#define EGL_SYNC_CL_EVENT_COMPLETE_KHR 0x30FF
+#endif /* EGL_KHR_cl_event */
+
+#ifndef EGL_KHR_cl_event2
+#define EGL_KHR_cl_event2 1
+typedef void *EGLSyncKHR;
+typedef intptr_t EGLAttribKHR;
+typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESYNC64KHRPROC) (EGLDisplay dpy, EGLenum type, const EGLAttribKHR *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateSync64KHR (EGLDisplay dpy, EGLenum type, const EGLAttribKHR *attrib_list);
+#endif
+#endif /* EGL_KHR_cl_event2 */
+
+#ifndef EGL_KHR_client_get_all_proc_addresses
+#define EGL_KHR_client_get_all_proc_addresses 1
+#endif /* EGL_KHR_client_get_all_proc_addresses */
+
+#ifndef EGL_KHR_config_attribs
+#define EGL_KHR_config_attribs 1
+#define EGL_CONFORMANT_KHR 0x3042
+#define EGL_VG_COLORSPACE_LINEAR_BIT_KHR 0x0020
+#define EGL_VG_ALPHA_FORMAT_PRE_BIT_KHR 0x0040
+#endif /* EGL_KHR_config_attribs */
+
+#ifndef EGL_KHR_create_context
+#define EGL_KHR_create_context 1
+#define EGL_CONTEXT_MAJOR_VERSION_KHR 0x3098
+#define EGL_CONTEXT_MINOR_VERSION_KHR 0x30FB
+#define EGL_CONTEXT_FLAGS_KHR 0x30FC
+#define EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR 0x30FD
+#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR 0x31BD
+#define EGL_NO_RESET_NOTIFICATION_KHR 0x31BE
+#define EGL_LOSE_CONTEXT_ON_RESET_KHR 0x31BF
+#define EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR 0x00000001
+#define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR 0x00000002
+#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR 0x00000004
+#define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR 0x00000001
+#define EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR 0x00000002
+#define EGL_OPENGL_ES3_BIT_KHR 0x00000040
+#endif /* EGL_KHR_create_context */
+
+#ifndef EGL_KHR_create_context_no_error
+#define EGL_KHR_create_context_no_error 1
+#define EGL_CONTEXT_OPENGL_NO_ERROR_KHR 0x31B3
+#endif /* EGL_KHR_create_context_no_error */
+
+#ifndef EGL_KHR_fence_sync
+#define EGL_KHR_fence_sync 1
+typedef khronos_utime_nanoseconds_t EGLTimeKHR;
+#ifdef KHRONOS_SUPPORT_INT64
+#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR 0x30F0
+#define EGL_SYNC_CONDITION_KHR 0x30F8
+#define EGL_SYNC_FENCE_KHR 0x30F9
+typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESYNCKHRPROC) (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync);
+typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateSyncKHR (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncKHR (EGLDisplay dpy, EGLSyncKHR sync);
+EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncKHR (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribKHR (EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value);
+#endif
+#endif /* KHRONOS_SUPPORT_INT64 */
+#endif /* EGL_KHR_fence_sync */
+
+#ifndef EGL_KHR_get_all_proc_addresses
+#define EGL_KHR_get_all_proc_addresses 1
+#endif /* EGL_KHR_get_all_proc_addresses */
+
+#ifndef EGL_KHR_gl_colorspace
+#define EGL_KHR_gl_colorspace 1
+#define EGL_GL_COLORSPACE_KHR 0x309D
+#define EGL_GL_COLORSPACE_SRGB_KHR 0x3089
+#define EGL_GL_COLORSPACE_LINEAR_KHR 0x308A
+#endif /* EGL_KHR_gl_colorspace */
+
+#ifndef EGL_KHR_gl_renderbuffer_image
+#define EGL_KHR_gl_renderbuffer_image 1
+#define EGL_GL_RENDERBUFFER_KHR 0x30B9
+#endif /* EGL_KHR_gl_renderbuffer_image */
+
+#ifndef EGL_KHR_gl_texture_2D_image
+#define EGL_KHR_gl_texture_2D_image 1
+#define EGL_GL_TEXTURE_2D_KHR 0x30B1
+#define EGL_GL_TEXTURE_LEVEL_KHR 0x30BC
+#endif /* EGL_KHR_gl_texture_2D_image */
+
+#ifndef EGL_KHR_gl_texture_3D_image
+#define EGL_KHR_gl_texture_3D_image 1
+#define EGL_GL_TEXTURE_3D_KHR 0x30B2
+#define EGL_GL_TEXTURE_ZOFFSET_KHR 0x30BD
+#endif /* EGL_KHR_gl_texture_3D_image */
+
+#ifndef EGL_KHR_gl_texture_cubemap_image
+#define EGL_KHR_gl_texture_cubemap_image 1
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR 0x30B3
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR 0x30B4
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR 0x30B5
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR 0x30B6
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR 0x30B7
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR 0x30B8
+#endif /* EGL_KHR_gl_texture_cubemap_image */
+
+#ifndef EGL_KHR_image
+#define EGL_KHR_image 1
+typedef void *EGLImageKHR;
+#define EGL_NATIVE_PIXMAP_KHR 0x30B0
+#define EGL_NO_IMAGE_KHR ((EGLImageKHR)0)
+typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGLImageKHR image);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLImageKHR EGLAPIENTRY eglCreateImageKHR (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImageKHR (EGLDisplay dpy, EGLImageKHR image);
+#endif
+#endif /* EGL_KHR_image */
+
+#ifndef EGL_KHR_image_base
+#define EGL_KHR_image_base 1
+#define EGL_IMAGE_PRESERVED_KHR 0x30D2
+#endif /* EGL_KHR_image_base */
+
+#ifndef EGL_KHR_image_pixmap
+#define EGL_KHR_image_pixmap 1
+#endif /* EGL_KHR_image_pixmap */
+
+#ifndef EGL_KHR_lock_surface
+#define EGL_KHR_lock_surface 1
+#define EGL_READ_SURFACE_BIT_KHR 0x0001
+#define EGL_WRITE_SURFACE_BIT_KHR 0x0002
+#define EGL_LOCK_SURFACE_BIT_KHR 0x0080
+#define EGL_OPTIMAL_FORMAT_BIT_KHR 0x0100
+#define EGL_MATCH_FORMAT_KHR 0x3043
+#define EGL_FORMAT_RGB_565_EXACT_KHR 0x30C0
+#define EGL_FORMAT_RGB_565_KHR 0x30C1
+#define EGL_FORMAT_RGBA_8888_EXACT_KHR 0x30C2
+#define EGL_FORMAT_RGBA_8888_KHR 0x30C3
+#define EGL_MAP_PRESERVE_PIXELS_KHR 0x30C4
+#define EGL_LOCK_USAGE_HINT_KHR 0x30C5
+#define EGL_BITMAP_POINTER_KHR 0x30C6
+#define EGL_BITMAP_PITCH_KHR 0x30C7
+#define EGL_BITMAP_ORIGIN_KHR 0x30C8
+#define EGL_BITMAP_PIXEL_RED_OFFSET_KHR 0x30C9
+#define EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR 0x30CA
+#define EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR 0x30CB
+#define EGL_BITMAP_PIXEL_ALPHA_OFFSET_KHR 0x30CC
+#define EGL_BITMAP_PIXEL_LUMINANCE_OFFSET_KHR 0x30CD
+#define EGL_LOWER_LEFT_KHR 0x30CE
+#define EGL_UPPER_LEFT_KHR 0x30CF
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLLOCKSURFACEKHRPROC) (EGLDisplay dpy, EGLSurface surface, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLUNLOCKSURFACEKHRPROC) (EGLDisplay dpy, EGLSurface surface);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglLockSurfaceKHR (EGLDisplay dpy, EGLSurface surface, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglUnlockSurfaceKHR (EGLDisplay dpy, EGLSurface surface);
+#endif
+#endif /* EGL_KHR_lock_surface */
+
+#ifndef EGL_KHR_lock_surface2
+#define EGL_KHR_lock_surface2 1
+#define EGL_BITMAP_PIXEL_SIZE_KHR 0x3110
+#endif /* EGL_KHR_lock_surface2 */
+
+#ifndef EGL_KHR_lock_surface3
+#define EGL_KHR_lock_surface3 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSURFACE64KHRPROC) (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLAttribKHR *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface64KHR (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLAttribKHR *value);
+#endif
+#endif /* EGL_KHR_lock_surface3 */
+
+#ifndef EGL_KHR_partial_update
+#define EGL_KHR_partial_update 1
+#define EGL_BUFFER_AGE_KHR 0x313D
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSETDAMAGEREGIONKHRPROC) (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSetDamageRegionKHR (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
+#endif
+#endif /* EGL_KHR_partial_update */
+
+#ifndef EGL_KHR_platform_android
+#define EGL_KHR_platform_android 1
+#define EGL_PLATFORM_ANDROID_KHR 0x3141
+#endif /* EGL_KHR_platform_android */
+
+#ifndef EGL_KHR_platform_gbm
+#define EGL_KHR_platform_gbm 1
+#define EGL_PLATFORM_GBM_KHR 0x31D7
+#endif /* EGL_KHR_platform_gbm */
+
+#ifndef EGL_KHR_platform_wayland
+#define EGL_KHR_platform_wayland 1
+#define EGL_PLATFORM_WAYLAND_KHR 0x31D8
+#endif /* EGL_KHR_platform_wayland */
+
+#ifndef EGL_KHR_platform_x11
+#define EGL_KHR_platform_x11 1
+#define EGL_PLATFORM_X11_KHR 0x31D5
+#define EGL_PLATFORM_X11_SCREEN_KHR 0x31D6
+#endif /* EGL_KHR_platform_x11 */
+
+#ifndef EGL_KHR_reusable_sync
+#define EGL_KHR_reusable_sync 1
+#ifdef KHRONOS_SUPPORT_INT64
+#define EGL_SYNC_STATUS_KHR 0x30F1
+#define EGL_SIGNALED_KHR 0x30F2
+#define EGL_UNSIGNALED_KHR 0x30F3
+#define EGL_TIMEOUT_EXPIRED_KHR 0x30F5
+#define EGL_CONDITION_SATISFIED_KHR 0x30F6
+#define EGL_SYNC_TYPE_KHR 0x30F7
+#define EGL_SYNC_REUSABLE_KHR 0x30FA
+#define EGL_SYNC_FLUSH_COMMANDS_BIT_KHR 0x0001
+#define EGL_FOREVER_KHR 0xFFFFFFFFFFFFFFFFull
+#define EGL_NO_SYNC_KHR ((EGLSyncKHR)0)
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncKHR (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode);
+#endif
+#endif /* KHRONOS_SUPPORT_INT64 */
+#endif /* EGL_KHR_reusable_sync */
+
+#ifndef EGL_KHR_stream
+#define EGL_KHR_stream 1
+typedef void *EGLStreamKHR;
+typedef khronos_uint64_t EGLuint64KHR;
+#ifdef KHRONOS_SUPPORT_INT64
+#define EGL_NO_STREAM_KHR ((EGLStreamKHR)0)
+#define EGL_CONSUMER_LATENCY_USEC_KHR 0x3210
+#define EGL_PRODUCER_FRAME_KHR 0x3212
+#define EGL_CONSUMER_FRAME_KHR 0x3213
+#define EGL_STREAM_STATE_KHR 0x3214
+#define EGL_STREAM_STATE_CREATED_KHR 0x3215
+#define EGL_STREAM_STATE_CONNECTING_KHR 0x3216
+#define EGL_STREAM_STATE_EMPTY_KHR 0x3217
+#define EGL_STREAM_STATE_NEW_FRAME_AVAILABLE_KHR 0x3218
+#define EGL_STREAM_STATE_OLD_FRAME_AVAILABLE_KHR 0x3219
+#define EGL_STREAM_STATE_DISCONNECTED_KHR 0x321A
+#define EGL_BAD_STREAM_KHR 0x321B
+#define EGL_BAD_STATE_KHR 0x321C
+typedef EGLStreamKHR (EGLAPIENTRYP PFNEGLCREATESTREAMKHRPROC) (EGLDisplay dpy, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSTREAMKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMATTRIBKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint *value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMU64KHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLuint64KHR *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLStreamKHR EGLAPIENTRY eglCreateStreamKHR (EGLDisplay dpy, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroyStreamKHR (EGLDisplay dpy, EGLStreamKHR stream);
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamAttribKHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamKHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamu64KHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLuint64KHR *value);
+#endif
+#endif /* KHRONOS_SUPPORT_INT64 */
+#endif /* EGL_KHR_stream */
+
+#ifndef EGL_KHR_stream_consumer_gltexture
+#define EGL_KHR_stream_consumer_gltexture 1
+#ifdef EGL_KHR_stream
+#define EGL_CONSUMER_ACQUIRE_TIMEOUT_USEC_KHR 0x321E
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERGLTEXTUREEXTERNALKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERACQUIREKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERRELEASEKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerGLTextureExternalKHR (EGLDisplay dpy, EGLStreamKHR stream);
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerAcquireKHR (EGLDisplay dpy, EGLStreamKHR stream);
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerReleaseKHR (EGLDisplay dpy, EGLStreamKHR stream);
+#endif
+#endif /* EGL_KHR_stream */
+#endif /* EGL_KHR_stream_consumer_gltexture */
+
+#ifndef EGL_KHR_stream_cross_process_fd
+#define EGL_KHR_stream_cross_process_fd 1
+typedef int EGLNativeFileDescriptorKHR;
+#ifdef EGL_KHR_stream
+#define EGL_NO_FILE_DESCRIPTOR_KHR ((EGLNativeFileDescriptorKHR)(-1))
+typedef EGLNativeFileDescriptorKHR (EGLAPIENTRYP PFNEGLGETSTREAMFILEDESCRIPTORKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream);
+typedef EGLStreamKHR (EGLAPIENTRYP PFNEGLCREATESTREAMFROMFILEDESCRIPTORKHRPROC) (EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLNativeFileDescriptorKHR EGLAPIENTRY eglGetStreamFileDescriptorKHR (EGLDisplay dpy, EGLStreamKHR stream);
+EGLAPI EGLStreamKHR EGLAPIENTRY eglCreateStreamFromFileDescriptorKHR (EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor);
+#endif
+#endif /* EGL_KHR_stream */
+#endif /* EGL_KHR_stream_cross_process_fd */
+
+#ifndef EGL_KHR_stream_fifo
+#define EGL_KHR_stream_fifo 1
+#ifdef EGL_KHR_stream
+#define EGL_STREAM_FIFO_LENGTH_KHR 0x31FC
+#define EGL_STREAM_TIME_NOW_KHR 0x31FD
+#define EGL_STREAM_TIME_CONSUMER_KHR 0x31FE
+#define EGL_STREAM_TIME_PRODUCER_KHR 0x31FF
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMTIMEKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLTimeKHR *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamTimeKHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLTimeKHR *value);
+#endif
+#endif /* EGL_KHR_stream */
+#endif /* EGL_KHR_stream_fifo */
+
+#ifndef EGL_KHR_stream_producer_aldatalocator
+#define EGL_KHR_stream_producer_aldatalocator 1
+#ifdef EGL_KHR_stream
+#endif /* EGL_KHR_stream */
+#endif /* EGL_KHR_stream_producer_aldatalocator */
+
+#ifndef EGL_KHR_stream_producer_eglsurface
+#define EGL_KHR_stream_producer_eglsurface 1
+#ifdef EGL_KHR_stream
+#define EGL_STREAM_BIT_KHR 0x0800
+typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATESTREAMPRODUCERSURFACEKHRPROC) (EGLDisplay dpy, EGLConfig config, EGLStreamKHR stream, const EGLint *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSurface EGLAPIENTRY eglCreateStreamProducerSurfaceKHR (EGLDisplay dpy, EGLConfig config, EGLStreamKHR stream, const EGLint *attrib_list);
+#endif
+#endif /* EGL_KHR_stream */
+#endif /* EGL_KHR_stream_producer_eglsurface */
+
+#ifndef EGL_KHR_surfaceless_context
+#define EGL_KHR_surfaceless_context 1
+#endif /* EGL_KHR_surfaceless_context */
+
+#ifndef EGL_KHR_swap_buffers_with_damage
+#define EGL_KHR_swap_buffers_with_damage 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSWITHDAMAGEKHRPROC) (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffersWithDamageKHR (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
+#endif
+#endif /* EGL_KHR_swap_buffers_with_damage */
+
+#ifndef EGL_KHR_vg_parent_image
+#define EGL_KHR_vg_parent_image 1
+#define EGL_VG_PARENT_IMAGE_KHR 0x30BA
+#endif /* EGL_KHR_vg_parent_image */
+
+#ifndef EGL_KHR_wait_sync
+#define EGL_KHR_wait_sync 1
+typedef EGLint (EGLAPIENTRYP PFNEGLWAITSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLint EGLAPIENTRY eglWaitSyncKHR (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags);
+#endif
+#endif /* EGL_KHR_wait_sync */
+
+#ifndef EGL_ANDROID_blob_cache
+#define EGL_ANDROID_blob_cache 1
+typedef khronos_ssize_t EGLsizeiANDROID;
+typedef void (*EGLSetBlobFuncANDROID) (const void *key, EGLsizeiANDROID keySize, const void *value, EGLsizeiANDROID valueSize);
+typedef EGLsizeiANDROID (*EGLGetBlobFuncANDROID) (const void *key, EGLsizeiANDROID keySize, void *value, EGLsizeiANDROID valueSize);
+typedef void (EGLAPIENTRYP PFNEGLSETBLOBCACHEFUNCSANDROIDPROC) (EGLDisplay dpy, EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI void EGLAPIENTRY eglSetBlobCacheFuncsANDROID (EGLDisplay dpy, EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get);
+#endif
+#endif /* EGL_ANDROID_blob_cache */
+
+#ifndef EGL_ANDROID_framebuffer_target
+#define EGL_ANDROID_framebuffer_target 1
+#define EGL_FRAMEBUFFER_TARGET_ANDROID 0x3147
+#endif /* EGL_ANDROID_framebuffer_target */
+
+#ifndef EGL_ANDROID_image_native_buffer
+#define EGL_ANDROID_image_native_buffer 1
+#define EGL_NATIVE_BUFFER_ANDROID 0x3140
+#endif /* EGL_ANDROID_image_native_buffer */
+
+#ifndef EGL_ANDROID_native_fence_sync
+#define EGL_ANDROID_native_fence_sync 1
+#define EGL_SYNC_NATIVE_FENCE_ANDROID 0x3144
+#define EGL_SYNC_NATIVE_FENCE_FD_ANDROID 0x3145
+#define EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID 0x3146
+#define EGL_NO_NATIVE_FENCE_FD_ANDROID -1
+typedef EGLint (EGLAPIENTRYP PFNEGLDUPNATIVEFENCEFDANDROIDPROC) (EGLDisplay dpy, EGLSyncKHR sync);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLint EGLAPIENTRY eglDupNativeFenceFDANDROID (EGLDisplay dpy, EGLSyncKHR sync);
+#endif
+#endif /* EGL_ANDROID_native_fence_sync */
+
+#ifndef EGL_ANDROID_recordable
+#define EGL_ANDROID_recordable 1
+#define EGL_RECORDABLE_ANDROID 0x3142
+#endif /* EGL_ANDROID_recordable */
+
+#ifndef EGL_ANGLE_d3d_share_handle_client_buffer
+#define EGL_ANGLE_d3d_share_handle_client_buffer 1
+#define EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE 0x3200
+#endif /* EGL_ANGLE_d3d_share_handle_client_buffer */
+
+#ifndef EGL_ANGLE_device_d3d
+#define EGL_ANGLE_device_d3d 1
+#define EGL_D3D9_DEVICE_ANGLE 0x33A0
+#define EGL_D3D11_DEVICE_ANGLE 0x33A1
+#endif /* EGL_ANGLE_device_d3d */
+
+#ifndef EGL_ANGLE_query_surface_pointer
+#define EGL_ANGLE_query_surface_pointer 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSURFACEPOINTERANGLEPROC) (EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurfacePointerANGLE (EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value);
+#endif
+#endif /* EGL_ANGLE_query_surface_pointer */
+
+#ifndef EGL_ANGLE_surface_d3d_texture_2d_share_handle
+#define EGL_ANGLE_surface_d3d_texture_2d_share_handle 1
+#endif /* EGL_ANGLE_surface_d3d_texture_2d_share_handle */
+
+#ifndef EGL_ANGLE_window_fixed_size
+#define EGL_ANGLE_window_fixed_size 1
+#define EGL_FIXED_SIZE_ANGLE 0x3201
+#endif /* EGL_ANGLE_window_fixed_size */
+
+#ifndef EGL_ARM_pixmap_multisample_discard
+#define EGL_ARM_pixmap_multisample_discard 1
+#define EGL_DISCARD_SAMPLES_ARM 0x3286
+#endif /* EGL_ARM_pixmap_multisample_discard */
+
+#ifndef EGL_EXT_buffer_age
+#define EGL_EXT_buffer_age 1
+#define EGL_BUFFER_AGE_EXT 0x313D
+#endif /* EGL_EXT_buffer_age */
+
+#ifndef EGL_EXT_client_extensions
+#define EGL_EXT_client_extensions 1
+#endif /* EGL_EXT_client_extensions */
+
+#ifndef EGL_EXT_create_context_robustness
+#define EGL_EXT_create_context_robustness 1
+#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT 0x30BF
+#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT 0x3138
+#define EGL_NO_RESET_NOTIFICATION_EXT 0x31BE
+#define EGL_LOSE_CONTEXT_ON_RESET_EXT 0x31BF
+#endif /* EGL_EXT_create_context_robustness */
+
+#ifndef EGL_EXT_device_base
+#define EGL_EXT_device_base 1
+typedef void *EGLDeviceEXT;
+#define EGL_NO_DEVICE_EXT ((EGLDeviceEXT)(0))
+#define EGL_BAD_DEVICE_EXT 0x322B
+#define EGL_DEVICE_EXT 0x322C
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDEVICEATTRIBEXTPROC) (EGLDeviceEXT device, EGLint attribute, EGLAttrib *value);
+typedef const char *(EGLAPIENTRYP PFNEGLQUERYDEVICESTRINGEXTPROC) (EGLDeviceEXT device, EGLint name);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDEVICESEXTPROC) (EGLint max_devices, EGLDeviceEXT *devices, EGLint *num_devices);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDISPLAYATTRIBEXTPROC) (EGLDisplay dpy, EGLint attribute, EGLAttrib *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryDeviceAttribEXT (EGLDeviceEXT device, EGLint attribute, EGLAttrib *value);
+EGLAPI const char *EGLAPIENTRY eglQueryDeviceStringEXT (EGLDeviceEXT device, EGLint name);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryDevicesEXT (EGLint max_devices, EGLDeviceEXT *devices, EGLint *num_devices);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryDisplayAttribEXT (EGLDisplay dpy, EGLint attribute, EGLAttrib *value);
+#endif
+#endif /* EGL_EXT_device_base */
+
+#ifndef EGL_EXT_device_drm
+#define EGL_EXT_device_drm 1
+#define EGL_DRM_DEVICE_FILE_EXT 0x3233
+#endif /* EGL_EXT_device_drm */
+
+#ifndef EGL_EXT_device_enumeration
+#define EGL_EXT_device_enumeration 1
+#endif /* EGL_EXT_device_enumeration */
+
+#ifndef EGL_EXT_device_openwf
+#define EGL_EXT_device_openwf 1
+#define EGL_OPENWF_DEVICE_ID_EXT 0x3237
+#endif /* EGL_EXT_device_openwf */
+
+#ifndef EGL_EXT_device_query
+#define EGL_EXT_device_query 1
+#endif /* EGL_EXT_device_query */
+
+#ifndef EGL_EXT_image_dma_buf_import
+#define EGL_EXT_image_dma_buf_import 1
+#define EGL_LINUX_DMA_BUF_EXT 0x3270
+#define EGL_LINUX_DRM_FOURCC_EXT 0x3271
+#define EGL_DMA_BUF_PLANE0_FD_EXT 0x3272
+#define EGL_DMA_BUF_PLANE0_OFFSET_EXT 0x3273
+#define EGL_DMA_BUF_PLANE0_PITCH_EXT 0x3274
+#define EGL_DMA_BUF_PLANE1_FD_EXT 0x3275
+#define EGL_DMA_BUF_PLANE1_OFFSET_EXT 0x3276
+#define EGL_DMA_BUF_PLANE1_PITCH_EXT 0x3277
+#define EGL_DMA_BUF_PLANE2_FD_EXT 0x3278
+#define EGL_DMA_BUF_PLANE2_OFFSET_EXT 0x3279
+#define EGL_DMA_BUF_PLANE2_PITCH_EXT 0x327A
+#define EGL_YUV_COLOR_SPACE_HINT_EXT 0x327B
+#define EGL_SAMPLE_RANGE_HINT_EXT 0x327C
+#define EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT 0x327D
+#define EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT 0x327E
+#define EGL_ITU_REC601_EXT 0x327F
+#define EGL_ITU_REC709_EXT 0x3280
+#define EGL_ITU_REC2020_EXT 0x3281
+#define EGL_YUV_FULL_RANGE_EXT 0x3282
+#define EGL_YUV_NARROW_RANGE_EXT 0x3283
+#define EGL_YUV_CHROMA_SITING_0_EXT 0x3284
+#define EGL_YUV_CHROMA_SITING_0_5_EXT 0x3285
+#endif /* EGL_EXT_image_dma_buf_import */
+
+#ifndef EGL_EXT_multiview_window
+#define EGL_EXT_multiview_window 1
+#define EGL_MULTIVIEW_VIEW_COUNT_EXT 0x3134
+#endif /* EGL_EXT_multiview_window */
+
+#ifndef EGL_EXT_output_base
+#define EGL_EXT_output_base 1
+typedef void *EGLOutputLayerEXT;
+typedef void *EGLOutputPortEXT;
+#define EGL_NO_OUTPUT_LAYER_EXT ((EGLOutputLayerEXT)0)
+#define EGL_NO_OUTPUT_PORT_EXT ((EGLOutputPortEXT)0)
+#define EGL_BAD_OUTPUT_LAYER_EXT 0x322D
+#define EGL_BAD_OUTPUT_PORT_EXT 0x322E
+#define EGL_SWAP_INTERVAL_EXT 0x322F
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETOUTPUTLAYERSEXTPROC) (EGLDisplay dpy, const EGLAttrib *attrib_list, EGLOutputLayerEXT *layers, EGLint max_layers, EGLint *num_layers);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETOUTPUTPORTSEXTPROC) (EGLDisplay dpy, const EGLAttrib *attrib_list, EGLOutputPortEXT *ports, EGLint max_ports, EGLint *num_ports);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLOUTPUTLAYERATTRIBEXTPROC) (EGLDisplay dpy, EGLOutputLayerEXT layer, EGLint attribute, EGLAttrib value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYOUTPUTLAYERATTRIBEXTPROC) (EGLDisplay dpy, EGLOutputLayerEXT layer, EGLint attribute, EGLAttrib *value);
+typedef const char *(EGLAPIENTRYP PFNEGLQUERYOUTPUTLAYERSTRINGEXTPROC) (EGLDisplay dpy, EGLOutputLayerEXT layer, EGLint name);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLOUTPUTPORTATTRIBEXTPROC) (EGLDisplay dpy, EGLOutputPortEXT port, EGLint attribute, EGLAttrib value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYOUTPUTPORTATTRIBEXTPROC) (EGLDisplay dpy, EGLOutputPortEXT port, EGLint attribute, EGLAttrib *value);
+typedef const char *(EGLAPIENTRYP PFNEGLQUERYOUTPUTPORTSTRINGEXTPROC) (EGLDisplay dpy, EGLOutputPortEXT port, EGLint name);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglGetOutputLayersEXT (EGLDisplay dpy, const EGLAttrib *attrib_list, EGLOutputLayerEXT *layers, EGLint max_layers, EGLint *num_layers);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetOutputPortsEXT (EGLDisplay dpy, const EGLAttrib *attrib_list, EGLOutputPortEXT *ports, EGLint max_ports, EGLint *num_ports);
+EGLAPI EGLBoolean EGLAPIENTRY eglOutputLayerAttribEXT (EGLDisplay dpy, EGLOutputLayerEXT layer, EGLint attribute, EGLAttrib value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryOutputLayerAttribEXT (EGLDisplay dpy, EGLOutputLayerEXT layer, EGLint attribute, EGLAttrib *value);
+EGLAPI const char *EGLAPIENTRY eglQueryOutputLayerStringEXT (EGLDisplay dpy, EGLOutputLayerEXT layer, EGLint name);
+EGLAPI EGLBoolean EGLAPIENTRY eglOutputPortAttribEXT (EGLDisplay dpy, EGLOutputPortEXT port, EGLint attribute, EGLAttrib value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryOutputPortAttribEXT (EGLDisplay dpy, EGLOutputPortEXT port, EGLint attribute, EGLAttrib *value);
+EGLAPI const char *EGLAPIENTRY eglQueryOutputPortStringEXT (EGLDisplay dpy, EGLOutputPortEXT port, EGLint name);
+#endif
+#endif /* EGL_EXT_output_base */
+
+#ifndef EGL_EXT_output_drm
+#define EGL_EXT_output_drm 1
+#define EGL_DRM_CRTC_EXT 0x3234
+#define EGL_DRM_PLANE_EXT 0x3235
+#define EGL_DRM_CONNECTOR_EXT 0x3236
+#endif /* EGL_EXT_output_drm */
+
+#ifndef EGL_EXT_output_openwf
+#define EGL_EXT_output_openwf 1
+#define EGL_OPENWF_PIPELINE_ID_EXT 0x3238
+#define EGL_OPENWF_PORT_ID_EXT 0x3239
+#endif /* EGL_EXT_output_openwf */
+
+#ifndef EGL_EXT_platform_base
+#define EGL_EXT_platform_base 1
+typedef EGLDisplay (EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC) (EGLenum platform, void *native_display, const EGLint *attrib_list);
+typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC) (EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list);
+typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPLATFORMPIXMAPSURFACEEXTPROC) (EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLint *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplayEXT (EGLenum platform, void *native_display, const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformWindowSurfaceEXT (EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformPixmapSurfaceEXT (EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLint *attrib_list);
+#endif
+#endif /* EGL_EXT_platform_base */
+
+#ifndef EGL_EXT_platform_device
+#define EGL_EXT_platform_device 1
+#define EGL_PLATFORM_DEVICE_EXT 0x313F
+#endif /* EGL_EXT_platform_device */
+
+#ifndef EGL_EXT_platform_wayland
+#define EGL_EXT_platform_wayland 1
+#define EGL_PLATFORM_WAYLAND_EXT 0x31D8
+#endif /* EGL_EXT_platform_wayland */
+
+#ifndef EGL_EXT_platform_x11
+#define EGL_EXT_platform_x11 1
+#define EGL_PLATFORM_X11_EXT 0x31D5
+#define EGL_PLATFORM_X11_SCREEN_EXT 0x31D6
+#endif /* EGL_EXT_platform_x11 */
+
+#ifndef EGL_EXT_protected_surface
+#define EGL_EXT_protected_surface 1
+#define EGL_PROTECTED_CONTENT_EXT 0x32C0
+#endif /* EGL_EXT_protected_surface */
+
+#ifndef EGL_EXT_stream_consumer_egloutput
+#define EGL_EXT_stream_consumer_egloutput 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMEROUTPUTEXTPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLOutputLayerEXT layer);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerOutputEXT (EGLDisplay dpy, EGLStreamKHR stream, EGLOutputLayerEXT layer);
+#endif
+#endif /* EGL_EXT_stream_consumer_egloutput */
+
+#ifndef EGL_EXT_swap_buffers_with_damage
+#define EGL_EXT_swap_buffers_with_damage 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC) (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffersWithDamageEXT (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
+#endif
+#endif /* EGL_EXT_swap_buffers_with_damage */
+
+#ifndef EGL_EXT_yuv_surface
+#define EGL_EXT_yuv_surface 1
+#define EGL_YUV_ORDER_EXT 0x3301
+#define EGL_YUV_NUMBER_OF_PLANES_EXT 0x3311
+#define EGL_YUV_SUBSAMPLE_EXT 0x3312
+#define EGL_YUV_DEPTH_RANGE_EXT 0x3317
+#define EGL_YUV_CSC_STANDARD_EXT 0x330A
+#define EGL_YUV_PLANE_BPP_EXT 0x331A
+#define EGL_YUV_BUFFER_EXT 0x3300
+#define EGL_YUV_ORDER_YUV_EXT 0x3302
+#define EGL_YUV_ORDER_YVU_EXT 0x3303
+#define EGL_YUV_ORDER_YUYV_EXT 0x3304
+#define EGL_YUV_ORDER_UYVY_EXT 0x3305
+#define EGL_YUV_ORDER_YVYU_EXT 0x3306
+#define EGL_YUV_ORDER_VYUY_EXT 0x3307
+#define EGL_YUV_ORDER_AYUV_EXT 0x3308
+#define EGL_YUV_SUBSAMPLE_4_2_0_EXT 0x3313
+#define EGL_YUV_SUBSAMPLE_4_2_2_EXT 0x3314
+#define EGL_YUV_SUBSAMPLE_4_4_4_EXT 0x3315
+#define EGL_YUV_DEPTH_RANGE_LIMITED_EXT 0x3318
+#define EGL_YUV_DEPTH_RANGE_FULL_EXT 0x3319
+#define EGL_YUV_CSC_STANDARD_601_EXT 0x330B
+#define EGL_YUV_CSC_STANDARD_709_EXT 0x330C
+#define EGL_YUV_CSC_STANDARD_2020_EXT 0x330D
+#define EGL_YUV_PLANE_BPP_0_EXT 0x331B
+#define EGL_YUV_PLANE_BPP_8_EXT 0x331C
+#define EGL_YUV_PLANE_BPP_10_EXT 0x331D
+#endif /* EGL_EXT_yuv_surface */
+
+#ifndef EGL_HI_clientpixmap
+#define EGL_HI_clientpixmap 1
+struct EGLClientPixmapHI {
+ void *pData;
+ EGLint iWidth;
+ EGLint iHeight;
+ EGLint iStride;
+};
+#define EGL_CLIENT_PIXMAP_POINTER_HI 0x8F74
+typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPIXMAPSURFACEHIPROC) (EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI *pixmap);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurfaceHI (EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI *pixmap);
+#endif
+#endif /* EGL_HI_clientpixmap */
+
+#ifndef EGL_HI_colorformats
+#define EGL_HI_colorformats 1
+#define EGL_COLOR_FORMAT_HI 0x8F70
+#define EGL_COLOR_RGB_HI 0x8F71
+#define EGL_COLOR_RGBA_HI 0x8F72
+#define EGL_COLOR_ARGB_HI 0x8F73
+#endif /* EGL_HI_colorformats */
+
+#ifndef EGL_IMG_context_priority
+#define EGL_IMG_context_priority 1
+#define EGL_CONTEXT_PRIORITY_LEVEL_IMG 0x3100
+#define EGL_CONTEXT_PRIORITY_HIGH_IMG 0x3101
+#define EGL_CONTEXT_PRIORITY_MEDIUM_IMG 0x3102
+#define EGL_CONTEXT_PRIORITY_LOW_IMG 0x3103
+#endif /* EGL_IMG_context_priority */
+
+#ifndef EGL_MESA_drm_image
+#define EGL_MESA_drm_image 1
+#define EGL_DRM_BUFFER_FORMAT_MESA 0x31D0
+#define EGL_DRM_BUFFER_USE_MESA 0x31D1
+#define EGL_DRM_BUFFER_FORMAT_ARGB32_MESA 0x31D2
+#define EGL_DRM_BUFFER_MESA 0x31D3
+#define EGL_DRM_BUFFER_STRIDE_MESA 0x31D4
+#define EGL_DRM_BUFFER_USE_SCANOUT_MESA 0x00000001
+#define EGL_DRM_BUFFER_USE_SHARE_MESA 0x00000002
+typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEDRMIMAGEMESAPROC) (EGLDisplay dpy, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDRMIMAGEMESAPROC) (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLImageKHR EGLAPIENTRY eglCreateDRMImageMESA (EGLDisplay dpy, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglExportDRMImageMESA (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride);
+#endif
+#endif /* EGL_MESA_drm_image */
+
+#ifndef EGL_MESA_image_dma_buf_export
+#define EGL_MESA_image_dma_buf_export 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDMABUFIMAGEQUERYMESAPROC) (EGLDisplay dpy, EGLImageKHR image, int *fourcc, int *num_planes, EGLuint64KHR *modifiers);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDMABUFIMAGEMESAPROC) (EGLDisplay dpy, EGLImageKHR image, int *fds, EGLint *strides, EGLint *offsets);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglExportDMABUFImageQueryMESA (EGLDisplay dpy, EGLImageKHR image, int *fourcc, int *num_planes, EGLuint64KHR *modifiers);
+EGLAPI EGLBoolean EGLAPIENTRY eglExportDMABUFImageMESA (EGLDisplay dpy, EGLImageKHR image, int *fds, EGLint *strides, EGLint *offsets);
+#endif
+#endif /* EGL_MESA_image_dma_buf_export */
+
+#ifndef EGL_MESA_platform_gbm
+#define EGL_MESA_platform_gbm 1
+#define EGL_PLATFORM_GBM_MESA 0x31D7
+#endif /* EGL_MESA_platform_gbm */
+
+#ifndef EGL_NOK_swap_region
+#define EGL_NOK_swap_region 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSREGIONNOKPROC) (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint *rects);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffersRegionNOK (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint *rects);
+#endif
+#endif /* EGL_NOK_swap_region */
+
+#ifndef EGL_NOK_swap_region2
+#define EGL_NOK_swap_region2 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSREGION2NOKPROC) (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint *rects);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffersRegion2NOK (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint *rects);
+#endif
+#endif /* EGL_NOK_swap_region2 */
+
+#ifndef EGL_NOK_texture_from_pixmap
+#define EGL_NOK_texture_from_pixmap 1
+#define EGL_Y_INVERTED_NOK 0x307F
+#endif /* EGL_NOK_texture_from_pixmap */
+
+#ifndef EGL_NV_3dvision_surface
+#define EGL_NV_3dvision_surface 1
+#define EGL_AUTO_STEREO_NV 0x3136
+#endif /* EGL_NV_3dvision_surface */
+
+#ifndef EGL_NV_coverage_sample
+#define EGL_NV_coverage_sample 1
+#define EGL_COVERAGE_BUFFERS_NV 0x30E0
+#define EGL_COVERAGE_SAMPLES_NV 0x30E1
+#endif /* EGL_NV_coverage_sample */
+
+#ifndef EGL_NV_coverage_sample_resolve
+#define EGL_NV_coverage_sample_resolve 1
+#define EGL_COVERAGE_SAMPLE_RESOLVE_NV 0x3131
+#define EGL_COVERAGE_SAMPLE_RESOLVE_DEFAULT_NV 0x3132
+#define EGL_COVERAGE_SAMPLE_RESOLVE_NONE_NV 0x3133
+#endif /* EGL_NV_coverage_sample_resolve */
+
+#ifndef EGL_NV_cuda_event
+#define EGL_NV_cuda_event 1
+#define EGL_CUDA_EVENT_HANDLE_NV 0x323B
+#define EGL_SYNC_CUDA_EVENT_NV 0x323C
+#define EGL_SYNC_CUDA_EVENT_COMPLETE_NV 0x323D
+#endif /* EGL_NV_cuda_event */
+
+#ifndef EGL_NV_depth_nonlinear
+#define EGL_NV_depth_nonlinear 1
+#define EGL_DEPTH_ENCODING_NV 0x30E2
+#define EGL_DEPTH_ENCODING_NONE_NV 0
+#define EGL_DEPTH_ENCODING_NONLINEAR_NV 0x30E3
+#endif /* EGL_NV_depth_nonlinear */
+
+#ifndef EGL_NV_device_cuda
+#define EGL_NV_device_cuda 1
+#define EGL_CUDA_DEVICE_NV 0x323A
+#endif /* EGL_NV_device_cuda */
+
+#ifndef EGL_NV_native_query
+#define EGL_NV_native_query 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYNATIVEDISPLAYNVPROC) (EGLDisplay dpy, EGLNativeDisplayType *display_id);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYNATIVEWINDOWNVPROC) (EGLDisplay dpy, EGLSurface surf, EGLNativeWindowType *window);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYNATIVEPIXMAPNVPROC) (EGLDisplay dpy, EGLSurface surf, EGLNativePixmapType *pixmap);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryNativeDisplayNV (EGLDisplay dpy, EGLNativeDisplayType *display_id);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryNativeWindowNV (EGLDisplay dpy, EGLSurface surf, EGLNativeWindowType *window);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryNativePixmapNV (EGLDisplay dpy, EGLSurface surf, EGLNativePixmapType *pixmap);
+#endif
+#endif /* EGL_NV_native_query */
+
+#ifndef EGL_NV_post_convert_rounding
+#define EGL_NV_post_convert_rounding 1
+#endif /* EGL_NV_post_convert_rounding */
+
+#ifndef EGL_NV_post_sub_buffer
+#define EGL_NV_post_sub_buffer 1
+#define EGL_POST_SUB_BUFFER_SUPPORTED_NV 0x30BE
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLPOSTSUBBUFFERNVPROC) (EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, EGLint width, EGLint height);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglPostSubBufferNV (EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, EGLint width, EGLint height);
+#endif
+#endif /* EGL_NV_post_sub_buffer */
+
+#ifndef EGL_NV_stream_sync
+#define EGL_NV_stream_sync 1
+#define EGL_SYNC_NEW_FRAME_NV 0x321F
+typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESTREAMSYNCNVPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum type, const EGLint *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateStreamSyncNV (EGLDisplay dpy, EGLStreamKHR stream, EGLenum type, const EGLint *attrib_list);
+#endif
+#endif /* EGL_NV_stream_sync */
+
+#ifndef EGL_NV_sync
+#define EGL_NV_sync 1
+typedef void *EGLSyncNV;
+typedef khronos_utime_nanoseconds_t EGLTimeNV;
+#ifdef KHRONOS_SUPPORT_INT64
+#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_NV 0x30E6
+#define EGL_SYNC_STATUS_NV 0x30E7
+#define EGL_SIGNALED_NV 0x30E8
+#define EGL_UNSIGNALED_NV 0x30E9
+#define EGL_SYNC_FLUSH_COMMANDS_BIT_NV 0x0001
+#define EGL_FOREVER_NV 0xFFFFFFFFFFFFFFFFull
+#define EGL_ALREADY_SIGNALED_NV 0x30EA
+#define EGL_TIMEOUT_EXPIRED_NV 0x30EB
+#define EGL_CONDITION_SATISFIED_NV 0x30EC
+#define EGL_SYNC_TYPE_NV 0x30ED
+#define EGL_SYNC_CONDITION_NV 0x30EE
+#define EGL_SYNC_FENCE_NV 0x30EF
+#define EGL_NO_SYNC_NV ((EGLSyncNV)0)
+typedef EGLSyncNV (EGLAPIENTRYP PFNEGLCREATEFENCESYNCNVPROC) (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCNVPROC) (EGLSyncNV sync);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLFENCENVPROC) (EGLSyncNV sync);
+typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCNVPROC) (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCNVPROC) (EGLSyncNV sync, EGLenum mode);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBNVPROC) (EGLSyncNV sync, EGLint attribute, EGLint *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSyncNV EGLAPIENTRY eglCreateFenceSyncNV (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncNV (EGLSyncNV sync);
+EGLAPI EGLBoolean EGLAPIENTRY eglFenceNV (EGLSyncNV sync);
+EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncNV (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout);
+EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncNV (EGLSyncNV sync, EGLenum mode);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribNV (EGLSyncNV sync, EGLint attribute, EGLint *value);
+#endif
+#endif /* KHRONOS_SUPPORT_INT64 */
+#endif /* EGL_NV_sync */
+
+#ifndef EGL_NV_system_time
+#define EGL_NV_system_time 1
+typedef khronos_utime_nanoseconds_t EGLuint64NV;
+#ifdef KHRONOS_SUPPORT_INT64
+typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMEFREQUENCYNVPROC) (void);
+typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMENVPROC) (void);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLuint64NV EGLAPIENTRY eglGetSystemTimeFrequencyNV (void);
+EGLAPI EGLuint64NV EGLAPIENTRY eglGetSystemTimeNV (void);
+#endif
+#endif /* KHRONOS_SUPPORT_INT64 */
+#endif /* EGL_NV_system_time */
+
+#ifndef EGL_TIZEN_image_native_buffer
+#define EGL_TIZEN_image_native_buffer 1
+#define EGL_NATIVE_BUFFER_TIZEN 0x32A0
+#endif /* EGL_TIZEN_image_native_buffer */
+
+#ifndef EGL_TIZEN_image_native_surface
+#define EGL_TIZEN_image_native_surface 1
+#define EGL_NATIVE_SURFACE_TIZEN 0x32A1
+#endif /* EGL_TIZEN_image_native_surface */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __eglext_h_ */
+
+
+#endif /* _MSC_VER */
diff --git a/src/3rdparty/SDL2/include/SDL_endian.h b/src/3rdparty/SDL2/include/SDL_endian.h
new file mode 100644
index 0000000..ed0bf5b
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_endian.h
@@ -0,0 +1,260 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_endian.h
+ *
+ * Functions for reading and writing endian-specific values
+ */
+
+#ifndef SDL_endian_h_
+#define SDL_endian_h_
+
+#include "SDL_stdinc.h"
+
+/**
+ * \name The two types of endianness
+ */
+/* @{ */
+#define SDL_LIL_ENDIAN 1234
+#define SDL_BIG_ENDIAN 4321
+/* @} */
+
+#ifndef SDL_BYTEORDER /* Not defined in SDL_config.h? */
+#ifdef __linux__
+#include <endian.h>
+#define SDL_BYTEORDER __BYTE_ORDER
+#else /* __linux__ */
+#if defined(__hppa__) || \
+ defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
+ (defined(__MIPS__) && defined(__MISPEB__)) || \
+ defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \
+ defined(__sparc__)
+#define SDL_BYTEORDER SDL_BIG_ENDIAN
+#else
+#define SDL_BYTEORDER SDL_LIL_ENDIAN
+#endif
+#endif /* __linux__ */
+#endif /* !SDL_BYTEORDER */
+
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \file SDL_endian.h
+ */
+#if defined(__GNUC__) && defined(__i386__) && \
+ !(__GNUC__ == 2 && __GNUC_MINOR__ == 95 /* broken gcc version */)
+SDL_FORCE_INLINE Uint16
+SDL_Swap16(Uint16 x)
+{
+ __asm__("xchgb %b0,%h0": "=q"(x):"0"(x));
+ return x;
+}
+#elif defined(__GNUC__) && defined(__x86_64__)
+SDL_FORCE_INLINE Uint16
+SDL_Swap16(Uint16 x)
+{
+ __asm__("xchgb %b0,%h0": "=Q"(x):"0"(x));
+ return x;
+}
+#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
+SDL_FORCE_INLINE Uint16
+SDL_Swap16(Uint16 x)
+{
+ int result;
+
+ __asm__("rlwimi %0,%2,8,16,23": "=&r"(result):"0"(x >> 8), "r"(x));
+ return (Uint16)result;
+}
+#elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__)) && !defined(__mcoldfire__)
+SDL_FORCE_INLINE Uint16
+SDL_Swap16(Uint16 x)
+{
+ __asm__("rorw #8,%0": "=d"(x): "0"(x):"cc");
+ return x;
+}
+#elif defined(__WATCOMC__) && defined(__386__)
+extern _inline Uint16 SDL_Swap16(Uint16);
+#pragma aux SDL_Swap16 = \
+ "xchg al, ah" \
+ parm [ax] \
+ modify [ax];
+#else
+SDL_FORCE_INLINE Uint16
+SDL_Swap16(Uint16 x)
+{
+ return SDL_static_cast(Uint16, ((x << 8) | (x >> 8)));
+}
+#endif
+
+#if defined(__GNUC__) && defined(__i386__)
+SDL_FORCE_INLINE Uint32
+SDL_Swap32(Uint32 x)
+{
+ __asm__("bswap %0": "=r"(x):"0"(x));
+ return x;
+}
+#elif defined(__GNUC__) && defined(__x86_64__)
+SDL_FORCE_INLINE Uint32
+SDL_Swap32(Uint32 x)
+{
+ __asm__("bswapl %0": "=r"(x):"0"(x));
+ return x;
+}
+#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
+SDL_FORCE_INLINE Uint32
+SDL_Swap32(Uint32 x)
+{
+ Uint32 result;
+
+ __asm__("rlwimi %0,%2,24,16,23": "=&r"(result):"0"(x >> 24), "r"(x));
+ __asm__("rlwimi %0,%2,8,8,15": "=&r"(result):"0"(result), "r"(x));
+ __asm__("rlwimi %0,%2,24,0,7": "=&r"(result):"0"(result), "r"(x));
+ return result;
+}
+#elif defined(__GNUC__) && (defined(__M68000__) || defined(__M68020__)) && !defined(__mcoldfire__)
+SDL_FORCE_INLINE Uint32
+SDL_Swap32(Uint32 x)
+{
+ __asm__("rorw #8,%0\n\tswap %0\n\trorw #8,%0": "=d"(x): "0"(x):"cc");
+ return x;
+}
+#elif defined(__WATCOMC__) && defined(__386__)
+extern _inline Uint32 SDL_Swap32(Uint32);
+#ifndef __SW_3 /* 486+ */
+#pragma aux SDL_Swap32 = \
+ "bswap eax" \
+ parm [eax] \
+ modify [eax];
+#else /* 386-only */
+#pragma aux SDL_Swap32 = \
+ "xchg al, ah" \
+ "ror eax, 16" \
+ "xchg al, ah" \
+ parm [eax] \
+ modify [eax];
+#endif
+#else
+SDL_FORCE_INLINE Uint32
+SDL_Swap32(Uint32 x)
+{
+ return SDL_static_cast(Uint32, ((x << 24) | ((x << 8) & 0x00FF0000) |
+ ((x >> 8) & 0x0000FF00) | (x >> 24)));
+}
+#endif
+
+#if defined(__GNUC__) && defined(__i386__)
+SDL_FORCE_INLINE Uint64
+SDL_Swap64(Uint64 x)
+{
+ union
+ {
+ struct
+ {
+ Uint32 a, b;
+ } s;
+ Uint64 u;
+ } v;
+ v.u = x;
+ __asm__("bswapl %0 ; bswapl %1 ; xchgl %0,%1": "=r"(v.s.a), "=r"(v.s.b):"0"(v.s.a),
+ "1"(v.s.
+ b));
+ return v.u;
+}
+#elif defined(__GNUC__) && defined(__x86_64__)
+SDL_FORCE_INLINE Uint64
+SDL_Swap64(Uint64 x)
+{
+ __asm__("bswapq %0": "=r"(x):"0"(x));
+ return x;
+}
+#else
+SDL_FORCE_INLINE Uint64
+SDL_Swap64(Uint64 x)
+{
+ Uint32 hi, lo;
+
+ /* Separate into high and low 32-bit values and swap them */
+ lo = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
+ x >>= 32;
+ hi = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
+ x = SDL_Swap32(lo);
+ x <<= 32;
+ x |= SDL_Swap32(hi);
+ return (x);
+}
+#endif
+
+
+SDL_FORCE_INLINE float
+SDL_SwapFloat(float x)
+{
+ union
+ {
+ float f;
+ Uint32 ui32;
+ } swapper;
+ swapper.f = x;
+ swapper.ui32 = SDL_Swap32(swapper.ui32);
+ return swapper.f;
+}
+
+
+/**
+ * \name Swap to native
+ * Byteswap item from the specified endianness to the native endianness.
+ */
+/* @{ */
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+#define SDL_SwapLE16(X) (X)
+#define SDL_SwapLE32(X) (X)
+#define SDL_SwapLE64(X) (X)
+#define SDL_SwapFloatLE(X) (X)
+#define SDL_SwapBE16(X) SDL_Swap16(X)
+#define SDL_SwapBE32(X) SDL_Swap32(X)
+#define SDL_SwapBE64(X) SDL_Swap64(X)
+#define SDL_SwapFloatBE(X) SDL_SwapFloat(X)
+#else
+#define SDL_SwapLE16(X) SDL_Swap16(X)
+#define SDL_SwapLE32(X) SDL_Swap32(X)
+#define SDL_SwapLE64(X) SDL_Swap64(X)
+#define SDL_SwapFloatLE(X) SDL_SwapFloat(X)
+#define SDL_SwapBE16(X) (X)
+#define SDL_SwapBE32(X) (X)
+#define SDL_SwapBE64(X) (X)
+#define SDL_SwapFloatBE(X) (X)
+#endif
+/* @} *//* Swap to native */
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_endian_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_error.h b/src/3rdparty/SDL2/include/SDL_error.h
new file mode 100644
index 0000000..c0e4629
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_error.h
@@ -0,0 +1,76 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_error.h
+ *
+ * Simple error message routines for SDL.
+ */
+
+#ifndef SDL_error_h_
+#define SDL_error_h_
+
+#include "SDL_stdinc.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Public functions */
+/* SDL_SetError() unconditionally returns -1. */
+extern DECLSPEC int SDLCALL SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
+extern DECLSPEC const char *SDLCALL SDL_GetError(void);
+extern DECLSPEC void SDLCALL SDL_ClearError(void);
+
+/**
+ * \name Internal error functions
+ *
+ * \internal
+ * Private error reporting function - used internally.
+ */
+/* @{ */
+#define SDL_OutOfMemory() SDL_Error(SDL_ENOMEM)
+#define SDL_Unsupported() SDL_Error(SDL_UNSUPPORTED)
+#define SDL_InvalidParamError(param) SDL_SetError("Parameter '%s' is invalid", (param))
+typedef enum
+{
+ SDL_ENOMEM,
+ SDL_EFREAD,
+ SDL_EFWRITE,
+ SDL_EFSEEK,
+ SDL_UNSUPPORTED,
+ SDL_LASTERROR
+} SDL_errorcode;
+/* SDL_Error() unconditionally returns -1. */
+extern DECLSPEC int SDLCALL SDL_Error(SDL_errorcode code);
+/* @} *//* Internal error functions */
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_error_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_events.h b/src/3rdparty/SDL2/include/SDL_events.h
new file mode 100644
index 0000000..3d39e6a
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_events.h
@@ -0,0 +1,754 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_events.h
+ *
+ * Include file for SDL event handling.
+ */
+
+#ifndef SDL_events_h_
+#define SDL_events_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_video.h"
+#include "SDL_keyboard.h"
+#include "SDL_mouse.h"
+#include "SDL_joystick.h"
+#include "SDL_gamecontroller.h"
+#include "SDL_quit.h"
+#include "SDL_gesture.h"
+#include "SDL_touch.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* General keyboard/mouse state definitions */
+#define SDL_RELEASED 0
+#define SDL_PRESSED 1
+
+/**
+ * \brief The types of events that can be delivered.
+ */
+typedef enum
+{
+ SDL_FIRSTEVENT = 0, /**< Unused (do not remove) */
+
+ /* Application events */
+ SDL_QUIT = 0x100, /**< User-requested quit */
+
+ /* These application events have special meaning on iOS, see README-ios.md for details */
+ SDL_APP_TERMINATING, /**< The application is being terminated by the OS
+ Called on iOS in applicationWillTerminate()
+ Called on Android in onDestroy()
+ */
+ SDL_APP_LOWMEMORY, /**< The application is low on memory, free memory if possible.
+ Called on iOS in applicationDidReceiveMemoryWarning()
+ Called on Android in onLowMemory()
+ */
+ SDL_APP_WILLENTERBACKGROUND, /**< The application is about to enter the background
+ Called on iOS in applicationWillResignActive()
+ Called on Android in onPause()
+ */
+ SDL_APP_DIDENTERBACKGROUND, /**< The application did enter the background and may not get CPU for some time
+ Called on iOS in applicationDidEnterBackground()
+ Called on Android in onPause()
+ */
+ SDL_APP_WILLENTERFOREGROUND, /**< The application is about to enter the foreground
+ Called on iOS in applicationWillEnterForeground()
+ Called on Android in onResume()
+ */
+ SDL_APP_DIDENTERFOREGROUND, /**< The application is now interactive
+ Called on iOS in applicationDidBecomeActive()
+ Called on Android in onResume()
+ */
+
+ /* Window events */
+ SDL_WINDOWEVENT = 0x200, /**< Window state change */
+ SDL_SYSWMEVENT, /**< System specific event */
+
+ /* Keyboard events */
+ SDL_KEYDOWN = 0x300, /**< Key pressed */
+ SDL_KEYUP, /**< Key released */
+ SDL_TEXTEDITING, /**< Keyboard text editing (composition) */
+ SDL_TEXTINPUT, /**< Keyboard text input */
+ SDL_KEYMAPCHANGED, /**< Keymap changed due to a system event such as an
+ input language or keyboard layout change.
+ */
+
+ /* Mouse events */
+ SDL_MOUSEMOTION = 0x400, /**< Mouse moved */
+ SDL_MOUSEBUTTONDOWN, /**< Mouse button pressed */
+ SDL_MOUSEBUTTONUP, /**< Mouse button released */
+ SDL_MOUSEWHEEL, /**< Mouse wheel motion */
+
+ /* Joystick events */
+ SDL_JOYAXISMOTION = 0x600, /**< Joystick axis motion */
+ SDL_JOYBALLMOTION, /**< Joystick trackball motion */
+ SDL_JOYHATMOTION, /**< Joystick hat position change */
+ SDL_JOYBUTTONDOWN, /**< Joystick button pressed */
+ SDL_JOYBUTTONUP, /**< Joystick button released */
+ SDL_JOYDEVICEADDED, /**< A new joystick has been inserted into the system */
+ SDL_JOYDEVICEREMOVED, /**< An opened joystick has been removed */
+
+ /* Game controller events */
+ SDL_CONTROLLERAXISMOTION = 0x650, /**< Game controller axis motion */
+ SDL_CONTROLLERBUTTONDOWN, /**< Game controller button pressed */
+ SDL_CONTROLLERBUTTONUP, /**< Game controller button released */
+ SDL_CONTROLLERDEVICEADDED, /**< A new Game controller has been inserted into the system */
+ SDL_CONTROLLERDEVICEREMOVED, /**< An opened Game controller has been removed */
+ SDL_CONTROLLERDEVICEREMAPPED, /**< The controller mapping was updated */
+
+ /* Touch events */
+ SDL_FINGERDOWN = 0x700,
+ SDL_FINGERUP,
+ SDL_FINGERMOTION,
+
+ /* Gesture events */
+ SDL_DOLLARGESTURE = 0x800,
+ SDL_DOLLARRECORD,
+ SDL_MULTIGESTURE,
+
+ /* Clipboard events */
+ SDL_CLIPBOARDUPDATE = 0x900, /**< The clipboard changed */
+
+ /* Drag and drop events */
+ SDL_DROPFILE = 0x1000, /**< The system requests a file open */
+ SDL_DROPTEXT, /**< text/plain drag-and-drop event */
+ SDL_DROPBEGIN, /**< A new set of drops is beginning (NULL filename) */
+ SDL_DROPCOMPLETE, /**< Current set of drops is now complete (NULL filename) */
+
+ /* Audio hotplug events */
+ SDL_AUDIODEVICEADDED = 0x1100, /**< A new audio device is available */
+ SDL_AUDIODEVICEREMOVED, /**< An audio device has been removed. */
+
+ /* Render events */
+ SDL_RENDER_TARGETS_RESET = 0x2000, /**< The render targets have been reset and their contents need to be updated */
+ SDL_RENDER_DEVICE_RESET, /**< The device has been reset and all textures need to be recreated */
+
+ /** Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use,
+ * and should be allocated with SDL_RegisterEvents()
+ */
+ SDL_USEREVENT = 0x8000,
+
+ /**
+ * This last event is only for bounding internal arrays
+ */
+ SDL_LASTEVENT = 0xFFFF
+} SDL_EventType;
+
+/**
+ * \brief Fields shared by every event
+ */
+typedef struct SDL_CommonEvent
+{
+ Uint32 type;
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+} SDL_CommonEvent;
+
+/**
+ * \brief Window state change event data (event.window.*)
+ */
+typedef struct SDL_WindowEvent
+{
+ Uint32 type; /**< ::SDL_WINDOWEVENT */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Uint32 windowID; /**< The associated window */
+ Uint8 event; /**< ::SDL_WindowEventID */
+ Uint8 padding1;
+ Uint8 padding2;
+ Uint8 padding3;
+ Sint32 data1; /**< event dependent data */
+ Sint32 data2; /**< event dependent data */
+} SDL_WindowEvent;
+
+/**
+ * \brief Keyboard button event structure (event.key.*)
+ */
+typedef struct SDL_KeyboardEvent
+{
+ Uint32 type; /**< ::SDL_KEYDOWN or ::SDL_KEYUP */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Uint32 windowID; /**< The window with keyboard focus, if any */
+ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
+ Uint8 repeat; /**< Non-zero if this is a key repeat */
+ Uint8 padding2;
+ Uint8 padding3;
+ SDL_Keysym keysym; /**< The key that was pressed or released */
+} SDL_KeyboardEvent;
+
+#define SDL_TEXTEDITINGEVENT_TEXT_SIZE (32)
+/**
+ * \brief Keyboard text editing event structure (event.edit.*)
+ */
+typedef struct SDL_TextEditingEvent
+{
+ Uint32 type; /**< ::SDL_TEXTEDITING */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Uint32 windowID; /**< The window with keyboard focus, if any */
+ char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE]; /**< The editing text */
+ Sint32 start; /**< The start cursor of selected editing text */
+ Sint32 length; /**< The length of selected editing text */
+} SDL_TextEditingEvent;
+
+
+#define SDL_TEXTINPUTEVENT_TEXT_SIZE (32)
+/**
+ * \brief Keyboard text input event structure (event.text.*)
+ */
+typedef struct SDL_TextInputEvent
+{
+ Uint32 type; /**< ::SDL_TEXTINPUT */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Uint32 windowID; /**< The window with keyboard focus, if any */
+ char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; /**< The input text */
+} SDL_TextInputEvent;
+
+/**
+ * \brief Mouse motion event structure (event.motion.*)
+ */
+typedef struct SDL_MouseMotionEvent
+{
+ Uint32 type; /**< ::SDL_MOUSEMOTION */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Uint32 windowID; /**< The window with mouse focus, if any */
+ Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
+ Uint32 state; /**< The current button state */
+ Sint32 x; /**< X coordinate, relative to window */
+ Sint32 y; /**< Y coordinate, relative to window */
+ Sint32 xrel; /**< The relative motion in the X direction */
+ Sint32 yrel; /**< The relative motion in the Y direction */
+} SDL_MouseMotionEvent;
+
+/**
+ * \brief Mouse button event structure (event.button.*)
+ */
+typedef struct SDL_MouseButtonEvent
+{
+ Uint32 type; /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Uint32 windowID; /**< The window with mouse focus, if any */
+ Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
+ Uint8 button; /**< The mouse button index */
+ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
+ Uint8 clicks; /**< 1 for single-click, 2 for double-click, etc. */
+ Uint8 padding1;
+ Sint32 x; /**< X coordinate, relative to window */
+ Sint32 y; /**< Y coordinate, relative to window */
+} SDL_MouseButtonEvent;
+
+/**
+ * \brief Mouse wheel event structure (event.wheel.*)
+ */
+typedef struct SDL_MouseWheelEvent
+{
+ Uint32 type; /**< ::SDL_MOUSEWHEEL */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Uint32 windowID; /**< The window with mouse focus, if any */
+ Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
+ Sint32 x; /**< The amount scrolled horizontally, positive to the right and negative to the left */
+ Sint32 y; /**< The amount scrolled vertically, positive away from the user and negative toward the user */
+ Uint32 direction; /**< Set to one of the SDL_MOUSEWHEEL_* defines. When FLIPPED the values in X and Y will be opposite. Multiply by -1 to change them back */
+} SDL_MouseWheelEvent;
+
+/**
+ * \brief Joystick axis motion event structure (event.jaxis.*)
+ */
+typedef struct SDL_JoyAxisEvent
+{
+ Uint32 type; /**< ::SDL_JOYAXISMOTION */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_JoystickID which; /**< The joystick instance id */
+ Uint8 axis; /**< The joystick axis index */
+ Uint8 padding1;
+ Uint8 padding2;
+ Uint8 padding3;
+ Sint16 value; /**< The axis value (range: -32768 to 32767) */
+ Uint16 padding4;
+} SDL_JoyAxisEvent;
+
+/**
+ * \brief Joystick trackball motion event structure (event.jball.*)
+ */
+typedef struct SDL_JoyBallEvent
+{
+ Uint32 type; /**< ::SDL_JOYBALLMOTION */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_JoystickID which; /**< The joystick instance id */
+ Uint8 ball; /**< The joystick trackball index */
+ Uint8 padding1;
+ Uint8 padding2;
+ Uint8 padding3;
+ Sint16 xrel; /**< The relative motion in the X direction */
+ Sint16 yrel; /**< The relative motion in the Y direction */
+} SDL_JoyBallEvent;
+
+/**
+ * \brief Joystick hat position change event structure (event.jhat.*)
+ */
+typedef struct SDL_JoyHatEvent
+{
+ Uint32 type; /**< ::SDL_JOYHATMOTION */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_JoystickID which; /**< The joystick instance id */
+ Uint8 hat; /**< The joystick hat index */
+ Uint8 value; /**< The hat position value.
+ * \sa ::SDL_HAT_LEFTUP ::SDL_HAT_UP ::SDL_HAT_RIGHTUP
+ * \sa ::SDL_HAT_LEFT ::SDL_HAT_CENTERED ::SDL_HAT_RIGHT
+ * \sa ::SDL_HAT_LEFTDOWN ::SDL_HAT_DOWN ::SDL_HAT_RIGHTDOWN
+ *
+ * Note that zero means the POV is centered.
+ */
+ Uint8 padding1;
+ Uint8 padding2;
+} SDL_JoyHatEvent;
+
+/**
+ * \brief Joystick button event structure (event.jbutton.*)
+ */
+typedef struct SDL_JoyButtonEvent
+{
+ Uint32 type; /**< ::SDL_JOYBUTTONDOWN or ::SDL_JOYBUTTONUP */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_JoystickID which; /**< The joystick instance id */
+ Uint8 button; /**< The joystick button index */
+ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
+ Uint8 padding1;
+ Uint8 padding2;
+} SDL_JoyButtonEvent;
+
+/**
+ * \brief Joystick device event structure (event.jdevice.*)
+ */
+typedef struct SDL_JoyDeviceEvent
+{
+ Uint32 type; /**< ::SDL_JOYDEVICEADDED or ::SDL_JOYDEVICEREMOVED */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Sint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED event */
+} SDL_JoyDeviceEvent;
+
+
+/**
+ * \brief Game controller axis motion event structure (event.caxis.*)
+ */
+typedef struct SDL_ControllerAxisEvent
+{
+ Uint32 type; /**< ::SDL_CONTROLLERAXISMOTION */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_JoystickID which; /**< The joystick instance id */
+ Uint8 axis; /**< The controller axis (SDL_GameControllerAxis) */
+ Uint8 padding1;
+ Uint8 padding2;
+ Uint8 padding3;
+ Sint16 value; /**< The axis value (range: -32768 to 32767) */
+ Uint16 padding4;
+} SDL_ControllerAxisEvent;
+
+
+/**
+ * \brief Game controller button event structure (event.cbutton.*)
+ */
+typedef struct SDL_ControllerButtonEvent
+{
+ Uint32 type; /**< ::SDL_CONTROLLERBUTTONDOWN or ::SDL_CONTROLLERBUTTONUP */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_JoystickID which; /**< The joystick instance id */
+ Uint8 button; /**< The controller button (SDL_GameControllerButton) */
+ Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
+ Uint8 padding1;
+ Uint8 padding2;
+} SDL_ControllerButtonEvent;
+
+
+/**
+ * \brief Controller device event structure (event.cdevice.*)
+ */
+typedef struct SDL_ControllerDeviceEvent
+{
+ Uint32 type; /**< ::SDL_CONTROLLERDEVICEADDED, ::SDL_CONTROLLERDEVICEREMOVED, or ::SDL_CONTROLLERDEVICEREMAPPED */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Sint32 which; /**< The joystick device index for the ADDED event, instance id for the REMOVED or REMAPPED event */
+} SDL_ControllerDeviceEvent;
+
+/**
+ * \brief Audio device event structure (event.adevice.*)
+ */
+typedef struct SDL_AudioDeviceEvent
+{
+ Uint32 type; /**< ::SDL_AUDIODEVICEADDED, or ::SDL_AUDIODEVICEREMOVED */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Uint32 which; /**< The audio device index for the ADDED event (valid until next SDL_GetNumAudioDevices() call), SDL_AudioDeviceID for the REMOVED event */
+ Uint8 iscapture; /**< zero if an output device, non-zero if a capture device. */
+ Uint8 padding1;
+ Uint8 padding2;
+ Uint8 padding3;
+} SDL_AudioDeviceEvent;
+
+
+/**
+ * \brief Touch finger event structure (event.tfinger.*)
+ */
+typedef struct SDL_TouchFingerEvent
+{
+ Uint32 type; /**< ::SDL_FINGERMOTION or ::SDL_FINGERDOWN or ::SDL_FINGERUP */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_TouchID touchId; /**< The touch device id */
+ SDL_FingerID fingerId;
+ float x; /**< Normalized in the range 0...1 */
+ float y; /**< Normalized in the range 0...1 */
+ float dx; /**< Normalized in the range -1...1 */
+ float dy; /**< Normalized in the range -1...1 */
+ float pressure; /**< Normalized in the range 0...1 */
+} SDL_TouchFingerEvent;
+
+
+/**
+ * \brief Multiple Finger Gesture Event (event.mgesture.*)
+ */
+typedef struct SDL_MultiGestureEvent
+{
+ Uint32 type; /**< ::SDL_MULTIGESTURE */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_TouchID touchId; /**< The touch device id */
+ float dTheta;
+ float dDist;
+ float x;
+ float y;
+ Uint16 numFingers;
+ Uint16 padding;
+} SDL_MultiGestureEvent;
+
+
+/**
+ * \brief Dollar Gesture Event (event.dgesture.*)
+ */
+typedef struct SDL_DollarGestureEvent
+{
+ Uint32 type; /**< ::SDL_DOLLARGESTURE or ::SDL_DOLLARRECORD */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_TouchID touchId; /**< The touch device id */
+ SDL_GestureID gestureId;
+ Uint32 numFingers;
+ float error;
+ float x; /**< Normalized center of gesture */
+ float y; /**< Normalized center of gesture */
+} SDL_DollarGestureEvent;
+
+
+/**
+ * \brief An event used to request a file open by the system (event.drop.*)
+ * This event is enabled by default, you can disable it with SDL_EventState().
+ * \note If this event is enabled, you must free the filename in the event.
+ */
+typedef struct SDL_DropEvent
+{
+ Uint32 type; /**< ::SDL_DROPBEGIN or ::SDL_DROPFILE or ::SDL_DROPTEXT or ::SDL_DROPCOMPLETE */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ char *file; /**< The file name, which should be freed with SDL_free(), is NULL on begin/complete */
+ Uint32 windowID; /**< The window that was dropped on, if any */
+} SDL_DropEvent;
+
+
+/**
+ * \brief The "quit requested" event
+ */
+typedef struct SDL_QuitEvent
+{
+ Uint32 type; /**< ::SDL_QUIT */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+} SDL_QuitEvent;
+
+/**
+ * \brief OS Specific event
+ */
+typedef struct SDL_OSEvent
+{
+ Uint32 type; /**< ::SDL_QUIT */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+} SDL_OSEvent;
+
+/**
+ * \brief A user-defined event type (event.user.*)
+ */
+typedef struct SDL_UserEvent
+{
+ Uint32 type; /**< ::SDL_USEREVENT through ::SDL_LASTEVENT-1 */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ Uint32 windowID; /**< The associated window if any */
+ Sint32 code; /**< User defined event code */
+ void *data1; /**< User defined data pointer */
+ void *data2; /**< User defined data pointer */
+} SDL_UserEvent;
+
+
+struct SDL_SysWMmsg;
+typedef struct SDL_SysWMmsg SDL_SysWMmsg;
+
+/**
+ * \brief A video driver dependent system event (event.syswm.*)
+ * This event is disabled by default, you can enable it with SDL_EventState()
+ *
+ * \note If you want to use this event, you should include SDL_syswm.h.
+ */
+typedef struct SDL_SysWMEvent
+{
+ Uint32 type; /**< ::SDL_SYSWMEVENT */
+ Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
+ SDL_SysWMmsg *msg; /**< driver dependent data, defined in SDL_syswm.h */
+} SDL_SysWMEvent;
+
+/**
+ * \brief General event structure
+ */
+typedef union SDL_Event
+{
+ Uint32 type; /**< Event type, shared with all events */
+ SDL_CommonEvent common; /**< Common event data */
+ SDL_WindowEvent window; /**< Window event data */
+ SDL_KeyboardEvent key; /**< Keyboard event data */
+ SDL_TextEditingEvent edit; /**< Text editing event data */
+ SDL_TextInputEvent text; /**< Text input event data */
+ SDL_MouseMotionEvent motion; /**< Mouse motion event data */
+ SDL_MouseButtonEvent button; /**< Mouse button event data */
+ SDL_MouseWheelEvent wheel; /**< Mouse wheel event data */
+ SDL_JoyAxisEvent jaxis; /**< Joystick axis event data */
+ SDL_JoyBallEvent jball; /**< Joystick ball event data */
+ SDL_JoyHatEvent jhat; /**< Joystick hat event data */
+ SDL_JoyButtonEvent jbutton; /**< Joystick button event data */
+ SDL_JoyDeviceEvent jdevice; /**< Joystick device change event data */
+ SDL_ControllerAxisEvent caxis; /**< Game Controller axis event data */
+ SDL_ControllerButtonEvent cbutton; /**< Game Controller button event data */
+ SDL_ControllerDeviceEvent cdevice; /**< Game Controller device event data */
+ SDL_AudioDeviceEvent adevice; /**< Audio device event data */
+ SDL_QuitEvent quit; /**< Quit request event data */
+ SDL_UserEvent user; /**< Custom event data */
+ SDL_SysWMEvent syswm; /**< System dependent window event data */
+ SDL_TouchFingerEvent tfinger; /**< Touch finger event data */
+ SDL_MultiGestureEvent mgesture; /**< Gesture event data */
+ SDL_DollarGestureEvent dgesture; /**< Gesture event data */
+ SDL_DropEvent drop; /**< Drag and drop event data */
+
+ /* This is necessary for ABI compatibility between Visual C++ and GCC
+ Visual C++ will respect the push pack pragma and use 52 bytes for
+ this structure, and GCC will use the alignment of the largest datatype
+ within the union, which is 8 bytes.
+
+ So... we'll add padding to force the size to be 56 bytes for both.
+ */
+ Uint8 padding[56];
+} SDL_Event;
+
+
+/* Function prototypes */
+
+/**
+ * Pumps the event loop, gathering events from the input devices.
+ *
+ * This function updates the event queue and internal input device state.
+ *
+ * This should only be run in the thread that sets the video mode.
+ */
+extern DECLSPEC void SDLCALL SDL_PumpEvents(void);
+
+/* @{ */
+typedef enum
+{
+ SDL_ADDEVENT,
+ SDL_PEEKEVENT,
+ SDL_GETEVENT
+} SDL_eventaction;
+
+/**
+ * Checks the event queue for messages and optionally returns them.
+ *
+ * If \c action is ::SDL_ADDEVENT, up to \c numevents events will be added to
+ * the back of the event queue.
+ *
+ * If \c action is ::SDL_PEEKEVENT, up to \c numevents events at the front
+ * of the event queue, within the specified minimum and maximum type,
+ * will be returned and will not be removed from the queue.
+ *
+ * If \c action is ::SDL_GETEVENT, up to \c numevents events at the front
+ * of the event queue, within the specified minimum and maximum type,
+ * will be returned and will be removed from the queue.
+ *
+ * \return The number of events actually stored, or -1 if there was an error.
+ *
+ * This function is thread-safe.
+ */
+extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event * events, int numevents,
+ SDL_eventaction action,
+ Uint32 minType, Uint32 maxType);
+/* @} */
+
+/**
+ * Checks to see if certain event types are in the event queue.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasEvent(Uint32 type);
+extern DECLSPEC SDL_bool SDLCALL SDL_HasEvents(Uint32 minType, Uint32 maxType);
+
+/**
+ * This function clears events from the event queue
+ * This function only affects currently queued events. If you want to make
+ * sure that all pending OS events are flushed, you can call SDL_PumpEvents()
+ * on the main thread immediately before the flush call.
+ */
+extern DECLSPEC void SDLCALL SDL_FlushEvent(Uint32 type);
+extern DECLSPEC void SDLCALL SDL_FlushEvents(Uint32 minType, Uint32 maxType);
+
+/**
+ * \brief Polls for currently pending events.
+ *
+ * \return 1 if there are any pending events, or 0 if there are none available.
+ *
+ * \param event If not NULL, the next event is removed from the queue and
+ * stored in that area.
+ */
+extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event * event);
+
+/**
+ * \brief Waits indefinitely for the next available event.
+ *
+ * \return 1, or 0 if there was an error while waiting for events.
+ *
+ * \param event If not NULL, the next event is removed from the queue and
+ * stored in that area.
+ */
+extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event * event);
+
+/**
+ * \brief Waits until the specified timeout (in milliseconds) for the next
+ * available event.
+ *
+ * \return 1, or 0 if there was an error while waiting for events.
+ *
+ * \param event If not NULL, the next event is removed from the queue and
+ * stored in that area.
+ * \param timeout The timeout (in milliseconds) to wait for next event.
+ */
+extern DECLSPEC int SDLCALL SDL_WaitEventTimeout(SDL_Event * event,
+ int timeout);
+
+/**
+ * \brief Add an event to the event queue.
+ *
+ * \return 1 on success, 0 if the event was filtered, or -1 if the event queue
+ * was full or there was some other error.
+ */
+extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event * event);
+
+typedef int (SDLCALL * SDL_EventFilter) (void *userdata, SDL_Event * event);
+
+/**
+ * Sets up a filter to process all events before they change internal state and
+ * are posted to the internal event queue.
+ *
+ * The filter is prototyped as:
+ * \code
+ * int SDL_EventFilter(void *userdata, SDL_Event * event);
+ * \endcode
+ *
+ * If the filter returns 1, then the event will be added to the internal queue.
+ * If it returns 0, then the event will be dropped from the queue, but the
+ * internal state will still be updated. This allows selective filtering of
+ * dynamically arriving events.
+ *
+ * \warning Be very careful of what you do in the event filter function, as
+ * it may run in a different thread!
+ *
+ * There is one caveat when dealing with the ::SDL_QuitEvent event type. The
+ * event filter is only called when the window manager desires to close the
+ * application window. If the event filter returns 1, then the window will
+ * be closed, otherwise the window will remain open if possible.
+ *
+ * If the quit event is generated by an interrupt signal, it will bypass the
+ * internal queue and be delivered to the application at the next event poll.
+ */
+extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter,
+ void *userdata);
+
+/**
+ * Return the current event filter - can be used to "chain" filters.
+ * If there is no event filter set, this function returns SDL_FALSE.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_GetEventFilter(SDL_EventFilter * filter,
+ void **userdata);
+
+/**
+ * Add a function which is called when an event is added to the queue.
+ */
+extern DECLSPEC void SDLCALL SDL_AddEventWatch(SDL_EventFilter filter,
+ void *userdata);
+
+/**
+ * Remove an event watch function added with SDL_AddEventWatch()
+ */
+extern DECLSPEC void SDLCALL SDL_DelEventWatch(SDL_EventFilter filter,
+ void *userdata);
+
+/**
+ * Run the filter function on the current event queue, removing any
+ * events for which the filter returns 0.
+ */
+extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter,
+ void *userdata);
+
+/* @{ */
+#define SDL_QUERY -1
+#define SDL_IGNORE 0
+#define SDL_DISABLE 0
+#define SDL_ENABLE 1
+
+/**
+ * This function allows you to set the state of processing certain events.
+ * - If \c state is set to ::SDL_IGNORE, that event will be automatically
+ * dropped from the event queue and will not be filtered.
+ * - If \c state is set to ::SDL_ENABLE, that event will be processed
+ * normally.
+ * - If \c state is set to ::SDL_QUERY, SDL_EventState() will return the
+ * current processing state of the specified event.
+ */
+extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint32 type, int state);
+/* @} */
+#define SDL_GetEventState(type) SDL_EventState(type, SDL_QUERY)
+
+/**
+ * This function allocates a set of user-defined events, and returns
+ * the beginning event number for that set of events.
+ *
+ * If there aren't enough user-defined events left, this function
+ * returns (Uint32)-1
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_events_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_filesystem.h b/src/3rdparty/SDL2/include/SDL_filesystem.h
new file mode 100644
index 0000000..fa6a1fa
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_filesystem.h
@@ -0,0 +1,136 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_filesystem.h
+ *
+ * \brief Include file for filesystem SDL API functions
+ */
+
+#ifndef SDL_filesystem_h_
+#define SDL_filesystem_h_
+
+#include "SDL_stdinc.h"
+
+#include "begin_code.h"
+
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Get the path where the application resides.
+ *
+ * Get the "base path". This is the directory where the application was run
+ * from, which is probably the installation directory, and may or may not
+ * be the process's current working directory.
+ *
+ * This returns an absolute path in UTF-8 encoding, and is guaranteed to
+ * end with a path separator ('\\' on Windows, '/' most other places).
+ *
+ * The pointer returned by this function is owned by you. Please call
+ * SDL_free() on the pointer when you are done with it, or it will be a
+ * memory leak. This is not necessarily a fast call, though, so you should
+ * call this once near startup and save the string if you need it.
+ *
+ * Some platforms can't determine the application's path, and on other
+ * platforms, this might be meaningless. In such cases, this function will
+ * return NULL.
+ *
+ * \return String of base dir in UTF-8 encoding, or NULL on error.
+ *
+ * \sa SDL_GetPrefPath
+ */
+extern DECLSPEC char *SDLCALL SDL_GetBasePath(void);
+
+/**
+ * \brief Get the user-and-app-specific path where files can be written.
+ *
+ * Get the "pref dir". This is meant to be where users can write personal
+ * files (preferences and save games, etc) that are specific to your
+ * application. This directory is unique per user, per application.
+ *
+ * This function will decide the appropriate location in the native filesystem,
+ * create the directory if necessary, and return a string of the absolute
+ * path to the directory in UTF-8 encoding.
+ *
+ * On Windows, the string might look like:
+ * "C:\\Users\\bob\\AppData\\Roaming\\My Company\\My Program Name\\"
+ *
+ * On Linux, the string might look like:
+ * "/home/bob/.local/share/My Program Name/"
+ *
+ * On Mac OS X, the string might look like:
+ * "/Users/bob/Library/Application Support/My Program Name/"
+ *
+ * (etc.)
+ *
+ * You specify the name of your organization (if it's not a real organization,
+ * your name or an Internet domain you own might do) and the name of your
+ * application. These should be untranslated proper names.
+ *
+ * Both the org and app strings may become part of a directory name, so
+ * please follow these rules:
+ *
+ * - Try to use the same org string (including case-sensitivity) for
+ * all your applications that use this function.
+ * - Always use a unique app string for each one, and make sure it never
+ * changes for an app once you've decided on it.
+ * - Unicode characters are legal, as long as it's UTF-8 encoded, but...
+ * - ...only use letters, numbers, and spaces. Avoid punctuation like
+ * "Game Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient.
+ *
+ * This returns an absolute path in UTF-8 encoding, and is guaranteed to
+ * end with a path separator ('\\' on Windows, '/' most other places).
+ *
+ * The pointer returned by this function is owned by you. Please call
+ * SDL_free() on the pointer when you are done with it, or it will be a
+ * memory leak. This is not necessarily a fast call, though, so you should
+ * call this once near startup and save the string if you need it.
+ *
+ * You should assume the path returned by this function is the only safe
+ * place to write files (and that SDL_GetBasePath(), while it might be
+ * writable, or even the parent of the returned path, aren't where you
+ * should be writing things).
+ *
+ * Some platforms can't determine the pref path, and on other
+ * platforms, this might be meaningless. In such cases, this function will
+ * return NULL.
+ *
+ * \param org The name of your organization.
+ * \param app The name of your application.
+ * \return UTF-8 string of user dir in platform-dependent notation. NULL
+ * if there's a problem (creating directory failed, etc).
+ *
+ * \sa SDL_GetBasePath
+ */
+extern DECLSPEC char *SDLCALL SDL_GetPrefPath(const char *org, const char *app);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_filesystem_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_gamecontroller.h b/src/3rdparty/SDL2/include/SDL_gamecontroller.h
new file mode 100644
index 0000000..2e024be
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_gamecontroller.h
@@ -0,0 +1,362 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_gamecontroller.h
+ *
+ * Include file for SDL game controller event handling
+ */
+
+#ifndef SDL_gamecontroller_h_
+#define SDL_gamecontroller_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_rwops.h"
+#include "SDL_joystick.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \file SDL_gamecontroller.h
+ *
+ * In order to use these functions, SDL_Init() must have been called
+ * with the ::SDL_INIT_GAMECONTROLLER flag. This causes SDL to scan the system
+ * for game controllers, and load appropriate drivers.
+ *
+ * If you would like to receive controller updates while the application
+ * is in the background, you should set the following hint before calling
+ * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
+ */
+
+/**
+ * The gamecontroller structure used to identify an SDL game controller
+ */
+struct _SDL_GameController;
+typedef struct _SDL_GameController SDL_GameController;
+
+
+typedef enum
+{
+ SDL_CONTROLLER_BINDTYPE_NONE = 0,
+ SDL_CONTROLLER_BINDTYPE_BUTTON,
+ SDL_CONTROLLER_BINDTYPE_AXIS,
+ SDL_CONTROLLER_BINDTYPE_HAT
+} SDL_GameControllerBindType;
+
+/**
+ * Get the SDL joystick layer binding for this controller button/axis mapping
+ */
+typedef struct SDL_GameControllerButtonBind
+{
+ SDL_GameControllerBindType bindType;
+ union
+ {
+ int button;
+ int axis;
+ struct {
+ int hat;
+ int hat_mask;
+ } hat;
+ } value;
+
+} SDL_GameControllerButtonBind;
+
+
+/**
+ * To count the number of game controllers in the system for the following:
+ * int nJoysticks = SDL_NumJoysticks();
+ * int nGameControllers = 0;
+ * for (int i = 0; i < nJoysticks; i++) {
+ * if (SDL_IsGameController(i)) {
+ * nGameControllers++;
+ * }
+ * }
+ *
+ * Using the SDL_HINT_GAMECONTROLLERCONFIG hint or the SDL_GameControllerAddMapping() you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is:
+ * guid,name,mappings
+ *
+ * Where GUID is the string value from SDL_JoystickGetGUIDString(), name is the human readable string for the device and mappings are controller mappings to joystick ones.
+ * Under Windows there is a reserved GUID of "xinput" that covers any XInput devices.
+ * The mapping format for joystick is:
+ * bX - a joystick button, index X
+ * hX.Y - hat X with value Y
+ * aX - axis X of the joystick
+ * Buttons can be used as a controller axis and vice versa.
+ *
+ * This string shows an example of a valid mapping for a controller
+ * "03000000341a00003608000000000000,PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7",
+ *
+ */
+
+/**
+ * Load a set of mappings from a seekable SDL data stream (memory or file), filtered by the current SDL_GetPlatform()
+ * A community sourced database of controllers is available at https://raw.github.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt
+ *
+ * If \c freerw is non-zero, the stream will be closed after being read.
+ *
+ * \return number of mappings added, -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_GameControllerAddMappingsFromRW(SDL_RWops * rw, int freerw);
+
+/**
+ * Load a set of mappings from a file, filtered by the current SDL_GetPlatform()
+ *
+ * Convenience macro.
+ */
+#define SDL_GameControllerAddMappingsFromFile(file) SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile(file, "rb"), 1)
+
+/**
+ * Add or update an existing mapping configuration
+ *
+ * \return 1 if mapping is added, 0 if updated, -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_GameControllerAddMapping(const char* mappingString);
+
+/**
+ * Get the number of mappings installed
+ *
+ * \return the number of mappings
+ */
+extern DECLSPEC int SDLCALL SDL_GameControllerNumMappings(void);
+
+/**
+ * Get the mapping at a particular index.
+ *
+ * \return the mapping string. Must be freed with SDL_free(). Returns NULL if the index is out of range.
+ */
+extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForIndex(int mapping_index);
+
+/**
+ * Get a mapping string for a GUID
+ *
+ * \return the mapping string. Must be freed with SDL_free(). Returns NULL if no mapping is available
+ */
+extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid);
+
+/**
+ * Get a mapping string for an open GameController
+ *
+ * \return the mapping string. Must be freed with SDL_free(). Returns NULL if no mapping is available
+ */
+extern DECLSPEC char * SDLCALL SDL_GameControllerMapping(SDL_GameController * gamecontroller);
+
+/**
+ * Is the joystick on this index supported by the game controller interface?
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_IsGameController(int joystick_index);
+
+/**
+ * Get the implementation dependent name of a game controller.
+ * This can be called before any controllers are opened.
+ * If no name can be found, this function returns NULL.
+ */
+extern DECLSPEC const char *SDLCALL SDL_GameControllerNameForIndex(int joystick_index);
+
+/**
+ * Open a game controller for use.
+ * The index passed as an argument refers to the N'th game controller on the system.
+ * This index is not the value which will identify this controller in future
+ * controller events. The joystick's instance id (::SDL_JoystickID) will be
+ * used there instead.
+ *
+ * \return A controller identifier, or NULL if an error occurred.
+ */
+extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerOpen(int joystick_index);
+
+/**
+ * Return the SDL_GameController associated with an instance id.
+ */
+extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromInstanceID(SDL_JoystickID joyid);
+
+/**
+ * Return the name for this currently opened controller
+ */
+extern DECLSPEC const char *SDLCALL SDL_GameControllerName(SDL_GameController *gamecontroller);
+
+/**
+ * Get the USB vendor ID of an opened controller, if available.
+ * If the vendor ID isn't available this function returns 0.
+ */
+extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetVendor(SDL_GameController * gamecontroller);
+
+/**
+ * Get the USB product ID of an opened controller, if available.
+ * If the product ID isn't available this function returns 0.
+ */
+extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProduct(SDL_GameController * gamecontroller);
+
+/**
+ * Get the product version of an opened controller, if available.
+ * If the product version isn't available this function returns 0.
+ */
+extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProductVersion(SDL_GameController * gamecontroller);
+
+/**
+ * Returns SDL_TRUE if the controller has been opened and currently connected,
+ * or SDL_FALSE if it has not.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerGetAttached(SDL_GameController *gamecontroller);
+
+/**
+ * Get the underlying joystick object used by a controller
+ */
+extern DECLSPEC SDL_Joystick *SDLCALL SDL_GameControllerGetJoystick(SDL_GameController *gamecontroller);
+
+/**
+ * Enable/disable controller event polling.
+ *
+ * If controller events are disabled, you must call SDL_GameControllerUpdate()
+ * yourself and check the state of the controller when you want controller
+ * information.
+ *
+ * The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE.
+ */
+extern DECLSPEC int SDLCALL SDL_GameControllerEventState(int state);
+
+/**
+ * Update the current state of the open game controllers.
+ *
+ * This is called automatically by the event loop if any game controller
+ * events are enabled.
+ */
+extern DECLSPEC void SDLCALL SDL_GameControllerUpdate(void);
+
+
+/**
+ * The list of axes available from a controller
+ *
+ * Thumbstick axis values range from SDL_JOYSTICK_AXIS_MIN to SDL_JOYSTICK_AXIS_MAX,
+ * and are centered within ~8000 of zero, though advanced UI will allow users to set
+ * or autodetect the dead zone, which varies between controllers.
+ *
+ * Trigger axis values range from 0 to SDL_JOYSTICK_AXIS_MAX.
+ */
+typedef enum
+{
+ SDL_CONTROLLER_AXIS_INVALID = -1,
+ SDL_CONTROLLER_AXIS_LEFTX,
+ SDL_CONTROLLER_AXIS_LEFTY,
+ SDL_CONTROLLER_AXIS_RIGHTX,
+ SDL_CONTROLLER_AXIS_RIGHTY,
+ SDL_CONTROLLER_AXIS_TRIGGERLEFT,
+ SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
+ SDL_CONTROLLER_AXIS_MAX
+} SDL_GameControllerAxis;
+
+/**
+ * turn this string into a axis mapping
+ */
+extern DECLSPEC SDL_GameControllerAxis SDLCALL SDL_GameControllerGetAxisFromString(const char *pchString);
+
+/**
+ * turn this axis enum into a string mapping
+ */
+extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis);
+
+/**
+ * Get the SDL joystick layer binding for this controller button mapping
+ */
+extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
+SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller,
+ SDL_GameControllerAxis axis);
+
+/**
+ * Get the current state of an axis control on a game controller.
+ *
+ * The state is a value ranging from -32768 to 32767 (except for the triggers,
+ * which range from 0 to 32767).
+ *
+ * The axis indices start at index 0.
+ */
+extern DECLSPEC Sint16 SDLCALL
+SDL_GameControllerGetAxis(SDL_GameController *gamecontroller,
+ SDL_GameControllerAxis axis);
+
+/**
+ * The list of buttons available from a controller
+ */
+typedef enum
+{
+ SDL_CONTROLLER_BUTTON_INVALID = -1,
+ SDL_CONTROLLER_BUTTON_A,
+ SDL_CONTROLLER_BUTTON_B,
+ SDL_CONTROLLER_BUTTON_X,
+ SDL_CONTROLLER_BUTTON_Y,
+ SDL_CONTROLLER_BUTTON_BACK,
+ SDL_CONTROLLER_BUTTON_GUIDE,
+ SDL_CONTROLLER_BUTTON_START,
+ SDL_CONTROLLER_BUTTON_LEFTSTICK,
+ SDL_CONTROLLER_BUTTON_RIGHTSTICK,
+ SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
+ SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
+ SDL_CONTROLLER_BUTTON_DPAD_UP,
+ SDL_CONTROLLER_BUTTON_DPAD_DOWN,
+ SDL_CONTROLLER_BUTTON_DPAD_LEFT,
+ SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
+ SDL_CONTROLLER_BUTTON_MAX
+} SDL_GameControllerButton;
+
+/**
+ * turn this string into a button mapping
+ */
+extern DECLSPEC SDL_GameControllerButton SDLCALL SDL_GameControllerGetButtonFromString(const char *pchString);
+
+/**
+ * turn this button enum into a string mapping
+ */
+extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForButton(SDL_GameControllerButton button);
+
+/**
+ * Get the SDL joystick layer binding for this controller button mapping
+ */
+extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
+SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller,
+ SDL_GameControllerButton button);
+
+
+/**
+ * Get the current state of a button on a game controller.
+ *
+ * The button indices start at index 0.
+ */
+extern DECLSPEC Uint8 SDLCALL SDL_GameControllerGetButton(SDL_GameController *gamecontroller,
+ SDL_GameControllerButton button);
+
+/**
+ * Close a controller previously opened with SDL_GameControllerOpen().
+ */
+extern DECLSPEC void SDLCALL SDL_GameControllerClose(SDL_GameController *gamecontroller);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_gamecontroller_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_gesture.h b/src/3rdparty/SDL2/include/SDL_gesture.h
new file mode 100644
index 0000000..b223d80
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_gesture.h
@@ -0,0 +1,87 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_gesture.h
+ *
+ * Include file for SDL gesture event handling.
+ */
+
+#ifndef SDL_gesture_h_
+#define SDL_gesture_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_video.h"
+
+#include "SDL_touch.h"
+
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef Sint64 SDL_GestureID;
+
+/* Function prototypes */
+
+/**
+ * \brief Begin Recording a gesture on the specified touch, or all touches (-1)
+ *
+ *
+ */
+extern DECLSPEC int SDLCALL SDL_RecordGesture(SDL_TouchID touchId);
+
+
+/**
+ * \brief Save all currently loaded Dollar Gesture templates
+ *
+ *
+ */
+extern DECLSPEC int SDLCALL SDL_SaveAllDollarTemplates(SDL_RWops *dst);
+
+/**
+ * \brief Save a currently loaded Dollar Gesture template
+ *
+ *
+ */
+extern DECLSPEC int SDLCALL SDL_SaveDollarTemplate(SDL_GestureID gestureId,SDL_RWops *dst);
+
+
+/**
+ * \brief Load Dollar Gesture templates from a file
+ *
+ *
+ */
+extern DECLSPEC int SDLCALL SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_gesture_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_haptic.h b/src/3rdparty/SDL2/include/SDL_haptic.h
new file mode 100644
index 0000000..e3a2bca
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_haptic.h
@@ -0,0 +1,1227 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_haptic.h
+ *
+ * \brief The SDL haptic subsystem allows you to control haptic (force feedback)
+ * devices.
+ *
+ * The basic usage is as follows:
+ * - Initialize the subsystem (::SDL_INIT_HAPTIC).
+ * - Open a haptic device.
+ * - SDL_HapticOpen() to open from index.
+ * - SDL_HapticOpenFromJoystick() to open from an existing joystick.
+ * - Create an effect (::SDL_HapticEffect).
+ * - Upload the effect with SDL_HapticNewEffect().
+ * - Run the effect with SDL_HapticRunEffect().
+ * - (optional) Free the effect with SDL_HapticDestroyEffect().
+ * - Close the haptic device with SDL_HapticClose().
+ *
+ * \par Simple rumble example:
+ * \code
+ * SDL_Haptic *haptic;
+ *
+ * // Open the device
+ * haptic = SDL_HapticOpen( 0 );
+ * if (haptic == NULL)
+ * return -1;
+ *
+ * // Initialize simple rumble
+ * if (SDL_HapticRumbleInit( haptic ) != 0)
+ * return -1;
+ *
+ * // Play effect at 50% strength for 2 seconds
+ * if (SDL_HapticRumblePlay( haptic, 0.5, 2000 ) != 0)
+ * return -1;
+ * SDL_Delay( 2000 );
+ *
+ * // Clean up
+ * SDL_HapticClose( haptic );
+ * \endcode
+ *
+ * \par Complete example:
+ * \code
+ * int test_haptic( SDL_Joystick * joystick ) {
+ * SDL_Haptic *haptic;
+ * SDL_HapticEffect effect;
+ * int effect_id;
+ *
+ * // Open the device
+ * haptic = SDL_HapticOpenFromJoystick( joystick );
+ * if (haptic == NULL) return -1; // Most likely joystick isn't haptic
+ *
+ * // See if it can do sine waves
+ * if ((SDL_HapticQuery(haptic) & SDL_HAPTIC_SINE)==0) {
+ * SDL_HapticClose(haptic); // No sine effect
+ * return -1;
+ * }
+ *
+ * // Create the effect
+ * memset( &effect, 0, sizeof(SDL_HapticEffect) ); // 0 is safe default
+ * effect.type = SDL_HAPTIC_SINE;
+ * effect.periodic.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates
+ * effect.periodic.direction.dir[0] = 18000; // Force comes from south
+ * effect.periodic.period = 1000; // 1000 ms
+ * effect.periodic.magnitude = 20000; // 20000/32767 strength
+ * effect.periodic.length = 5000; // 5 seconds long
+ * effect.periodic.attack_length = 1000; // Takes 1 second to get max strength
+ * effect.periodic.fade_length = 1000; // Takes 1 second to fade away
+ *
+ * // Upload the effect
+ * effect_id = SDL_HapticNewEffect( haptic, &effect );
+ *
+ * // Test the effect
+ * SDL_HapticRunEffect( haptic, effect_id, 1 );
+ * SDL_Delay( 5000); // Wait for the effect to finish
+ *
+ * // We destroy the effect, although closing the device also does this
+ * SDL_HapticDestroyEffect( haptic, effect_id );
+ *
+ * // Close the device
+ * SDL_HapticClose(haptic);
+ *
+ * return 0; // Success
+ * }
+ * \endcode
+ */
+
+#ifndef SDL_haptic_h_
+#define SDL_haptic_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_joystick.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * \typedef SDL_Haptic
+ *
+ * \brief The haptic structure used to identify an SDL haptic.
+ *
+ * \sa SDL_HapticOpen
+ * \sa SDL_HapticOpenFromJoystick
+ * \sa SDL_HapticClose
+ */
+struct _SDL_Haptic;
+typedef struct _SDL_Haptic SDL_Haptic;
+
+
+/**
+ * \name Haptic features
+ *
+ * Different haptic features a device can have.
+ */
+/* @{ */
+
+/**
+ * \name Haptic effects
+ */
+/* @{ */
+
+/**
+ * \brief Constant effect supported.
+ *
+ * Constant haptic effect.
+ *
+ * \sa SDL_HapticCondition
+ */
+#define SDL_HAPTIC_CONSTANT (1u<<0)
+
+/**
+ * \brief Sine wave effect supported.
+ *
+ * Periodic haptic effect that simulates sine waves.
+ *
+ * \sa SDL_HapticPeriodic
+ */
+#define SDL_HAPTIC_SINE (1u<<1)
+
+/**
+ * \brief Left/Right effect supported.
+ *
+ * Haptic effect for direct control over high/low frequency motors.
+ *
+ * \sa SDL_HapticLeftRight
+ * \warning this value was SDL_HAPTIC_SQUARE right before 2.0.0 shipped. Sorry,
+ * we ran out of bits, and this is important for XInput devices.
+ */
+#define SDL_HAPTIC_LEFTRIGHT (1u<<2)
+
+/* !!! FIXME: put this back when we have more bits in 2.1 */
+/* #define SDL_HAPTIC_SQUARE (1<<2) */
+
+/**
+ * \brief Triangle wave effect supported.
+ *
+ * Periodic haptic effect that simulates triangular waves.
+ *
+ * \sa SDL_HapticPeriodic
+ */
+#define SDL_HAPTIC_TRIANGLE (1u<<3)
+
+/**
+ * \brief Sawtoothup wave effect supported.
+ *
+ * Periodic haptic effect that simulates saw tooth up waves.
+ *
+ * \sa SDL_HapticPeriodic
+ */
+#define SDL_HAPTIC_SAWTOOTHUP (1u<<4)
+
+/**
+ * \brief Sawtoothdown wave effect supported.
+ *
+ * Periodic haptic effect that simulates saw tooth down waves.
+ *
+ * \sa SDL_HapticPeriodic
+ */
+#define SDL_HAPTIC_SAWTOOTHDOWN (1u<<5)
+
+/**
+ * \brief Ramp effect supported.
+ *
+ * Ramp haptic effect.
+ *
+ * \sa SDL_HapticRamp
+ */
+#define SDL_HAPTIC_RAMP (1u<<6)
+
+/**
+ * \brief Spring effect supported - uses axes position.
+ *
+ * Condition haptic effect that simulates a spring. Effect is based on the
+ * axes position.
+ *
+ * \sa SDL_HapticCondition
+ */
+#define SDL_HAPTIC_SPRING (1u<<7)
+
+/**
+ * \brief Damper effect supported - uses axes velocity.
+ *
+ * Condition haptic effect that simulates dampening. Effect is based on the
+ * axes velocity.
+ *
+ * \sa SDL_HapticCondition
+ */
+#define SDL_HAPTIC_DAMPER (1u<<8)
+
+/**
+ * \brief Inertia effect supported - uses axes acceleration.
+ *
+ * Condition haptic effect that simulates inertia. Effect is based on the axes
+ * acceleration.
+ *
+ * \sa SDL_HapticCondition
+ */
+#define SDL_HAPTIC_INERTIA (1u<<9)
+
+/**
+ * \brief Friction effect supported - uses axes movement.
+ *
+ * Condition haptic effect that simulates friction. Effect is based on the
+ * axes movement.
+ *
+ * \sa SDL_HapticCondition
+ */
+#define SDL_HAPTIC_FRICTION (1u<<10)
+
+/**
+ * \brief Custom effect is supported.
+ *
+ * User defined custom haptic effect.
+ */
+#define SDL_HAPTIC_CUSTOM (1u<<11)
+
+/* @} *//* Haptic effects */
+
+/* These last few are features the device has, not effects */
+
+/**
+ * \brief Device can set global gain.
+ *
+ * Device supports setting the global gain.
+ *
+ * \sa SDL_HapticSetGain
+ */
+#define SDL_HAPTIC_GAIN (1u<<12)
+
+/**
+ * \brief Device can set autocenter.
+ *
+ * Device supports setting autocenter.
+ *
+ * \sa SDL_HapticSetAutocenter
+ */
+#define SDL_HAPTIC_AUTOCENTER (1u<<13)
+
+/**
+ * \brief Device can be queried for effect status.
+ *
+ * Device supports querying effect status.
+ *
+ * \sa SDL_HapticGetEffectStatus
+ */
+#define SDL_HAPTIC_STATUS (1u<<14)
+
+/**
+ * \brief Device can be paused.
+ *
+ * Devices supports being paused.
+ *
+ * \sa SDL_HapticPause
+ * \sa SDL_HapticUnpause
+ */
+#define SDL_HAPTIC_PAUSE (1u<<15)
+
+
+/**
+ * \name Direction encodings
+ */
+/* @{ */
+
+/**
+ * \brief Uses polar coordinates for the direction.
+ *
+ * \sa SDL_HapticDirection
+ */
+#define SDL_HAPTIC_POLAR 0
+
+/**
+ * \brief Uses cartesian coordinates for the direction.
+ *
+ * \sa SDL_HapticDirection
+ */
+#define SDL_HAPTIC_CARTESIAN 1
+
+/**
+ * \brief Uses spherical coordinates for the direction.
+ *
+ * \sa SDL_HapticDirection
+ */
+#define SDL_HAPTIC_SPHERICAL 2
+
+/* @} *//* Direction encodings */
+
+/* @} *//* Haptic features */
+
+/*
+ * Misc defines.
+ */
+
+/**
+ * \brief Used to play a device an infinite number of times.
+ *
+ * \sa SDL_HapticRunEffect
+ */
+#define SDL_HAPTIC_INFINITY 4294967295U
+
+
+/**
+ * \brief Structure that represents a haptic direction.
+ *
+ * This is the direction where the force comes from,
+ * instead of the direction in which the force is exerted.
+ *
+ * Directions can be specified by:
+ * - ::SDL_HAPTIC_POLAR : Specified by polar coordinates.
+ * - ::SDL_HAPTIC_CARTESIAN : Specified by cartesian coordinates.
+ * - ::SDL_HAPTIC_SPHERICAL : Specified by spherical coordinates.
+ *
+ * Cardinal directions of the haptic device are relative to the positioning
+ * of the device. North is considered to be away from the user.
+ *
+ * The following diagram represents the cardinal directions:
+ * \verbatim
+ .--.
+ |__| .-------.
+ |=.| |.-----.|
+ |--| || ||
+ | | |'-----'|
+ |__|~')_____('
+ [ COMPUTER ]
+
+
+ North (0,-1)
+ ^
+ |
+ |
+ (-1,0) West <----[ HAPTIC ]----> East (1,0)
+ |
+ |
+ v
+ South (0,1)
+
+
+ [ USER ]
+ \|||/
+ (o o)
+ ---ooO-(_)-Ooo---
+ \endverbatim
+ *
+ * If type is ::SDL_HAPTIC_POLAR, direction is encoded by hundredths of a
+ * degree starting north and turning clockwise. ::SDL_HAPTIC_POLAR only uses
+ * the first \c dir parameter. The cardinal directions would be:
+ * - North: 0 (0 degrees)
+ * - East: 9000 (90 degrees)
+ * - South: 18000 (180 degrees)
+ * - West: 27000 (270 degrees)
+ *
+ * If type is ::SDL_HAPTIC_CARTESIAN, direction is encoded by three positions
+ * (X axis, Y axis and Z axis (with 3 axes)). ::SDL_HAPTIC_CARTESIAN uses
+ * the first three \c dir parameters. The cardinal directions would be:
+ * - North: 0,-1, 0
+ * - East: 1, 0, 0
+ * - South: 0, 1, 0
+ * - West: -1, 0, 0
+ *
+ * The Z axis represents the height of the effect if supported, otherwise
+ * it's unused. In cartesian encoding (1, 2) would be the same as (2, 4), you
+ * can use any multiple you want, only the direction matters.
+ *
+ * If type is ::SDL_HAPTIC_SPHERICAL, direction is encoded by two rotations.
+ * The first two \c dir parameters are used. The \c dir parameters are as
+ * follows (all values are in hundredths of degrees):
+ * - Degrees from (1, 0) rotated towards (0, 1).
+ * - Degrees towards (0, 0, 1) (device needs at least 3 axes).
+ *
+ *
+ * Example of force coming from the south with all encodings (force coming
+ * from the south means the user will have to pull the stick to counteract):
+ * \code
+ * SDL_HapticDirection direction;
+ *
+ * // Cartesian directions
+ * direction.type = SDL_HAPTIC_CARTESIAN; // Using cartesian direction encoding.
+ * direction.dir[0] = 0; // X position
+ * direction.dir[1] = 1; // Y position
+ * // Assuming the device has 2 axes, we don't need to specify third parameter.
+ *
+ * // Polar directions
+ * direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding.
+ * direction.dir[0] = 18000; // Polar only uses first parameter
+ *
+ * // Spherical coordinates
+ * direction.type = SDL_HAPTIC_SPHERICAL; // Spherical encoding
+ * direction.dir[0] = 9000; // Since we only have two axes we don't need more parameters.
+ * \endcode
+ *
+ * \sa SDL_HAPTIC_POLAR
+ * \sa SDL_HAPTIC_CARTESIAN
+ * \sa SDL_HAPTIC_SPHERICAL
+ * \sa SDL_HapticEffect
+ * \sa SDL_HapticNumAxes
+ */
+typedef struct SDL_HapticDirection
+{
+ Uint8 type; /**< The type of encoding. */
+ Sint32 dir[3]; /**< The encoded direction. */
+} SDL_HapticDirection;
+
+
+/**
+ * \brief A structure containing a template for a Constant effect.
+ *
+ * This struct is exclusively for the ::SDL_HAPTIC_CONSTANT effect.
+ *
+ * A constant effect applies a constant force in the specified direction
+ * to the joystick.
+ *
+ * \sa SDL_HAPTIC_CONSTANT
+ * \sa SDL_HapticEffect
+ */
+typedef struct SDL_HapticConstant
+{
+ /* Header */
+ Uint16 type; /**< ::SDL_HAPTIC_CONSTANT */
+ SDL_HapticDirection direction; /**< Direction of the effect. */
+
+ /* Replay */
+ Uint32 length; /**< Duration of the effect. */
+ Uint16 delay; /**< Delay before starting the effect. */
+
+ /* Trigger */
+ Uint16 button; /**< Button that triggers the effect. */
+ Uint16 interval; /**< How soon it can be triggered again after button. */
+
+ /* Constant */
+ Sint16 level; /**< Strength of the constant effect. */
+
+ /* Envelope */
+ Uint16 attack_length; /**< Duration of the attack. */
+ Uint16 attack_level; /**< Level at the start of the attack. */
+ Uint16 fade_length; /**< Duration of the fade. */
+ Uint16 fade_level; /**< Level at the end of the fade. */
+} SDL_HapticConstant;
+
+/**
+ * \brief A structure containing a template for a Periodic effect.
+ *
+ * The struct handles the following effects:
+ * - ::SDL_HAPTIC_SINE
+ * - ::SDL_HAPTIC_LEFTRIGHT
+ * - ::SDL_HAPTIC_TRIANGLE
+ * - ::SDL_HAPTIC_SAWTOOTHUP
+ * - ::SDL_HAPTIC_SAWTOOTHDOWN
+ *
+ * A periodic effect consists in a wave-shaped effect that repeats itself
+ * over time. The type determines the shape of the wave and the parameters
+ * determine the dimensions of the wave.
+ *
+ * Phase is given by hundredth of a degree meaning that giving the phase a value
+ * of 9000 will displace it 25% of its period. Here are sample values:
+ * - 0: No phase displacement.
+ * - 9000: Displaced 25% of its period.
+ * - 18000: Displaced 50% of its period.
+ * - 27000: Displaced 75% of its period.
+ * - 36000: Displaced 100% of its period, same as 0, but 0 is preferred.
+ *
+ * Examples:
+ * \verbatim
+ SDL_HAPTIC_SINE
+ __ __ __ __
+ / \ / \ / \ /
+ / \__/ \__/ \__/
+
+ SDL_HAPTIC_SQUARE
+ __ __ __ __ __
+ | | | | | | | | | |
+ | |__| |__| |__| |__| |
+
+ SDL_HAPTIC_TRIANGLE
+ /\ /\ /\ /\ /\
+ / \ / \ / \ / \ /
+ / \/ \/ \/ \/
+
+ SDL_HAPTIC_SAWTOOTHUP
+ /| /| /| /| /| /| /|
+ / | / | / | / | / | / | / |
+ / |/ |/ |/ |/ |/ |/ |
+
+ SDL_HAPTIC_SAWTOOTHDOWN
+ \ |\ |\ |\ |\ |\ |\ |
+ \ | \ | \ | \ | \ | \ | \ |
+ \| \| \| \| \| \| \|
+ \endverbatim
+ *
+ * \sa SDL_HAPTIC_SINE
+ * \sa SDL_HAPTIC_LEFTRIGHT
+ * \sa SDL_HAPTIC_TRIANGLE
+ * \sa SDL_HAPTIC_SAWTOOTHUP
+ * \sa SDL_HAPTIC_SAWTOOTHDOWN
+ * \sa SDL_HapticEffect
+ */
+typedef struct SDL_HapticPeriodic
+{
+ /* Header */
+ Uint16 type; /**< ::SDL_HAPTIC_SINE, ::SDL_HAPTIC_LEFTRIGHT,
+ ::SDL_HAPTIC_TRIANGLE, ::SDL_HAPTIC_SAWTOOTHUP or
+ ::SDL_HAPTIC_SAWTOOTHDOWN */
+ SDL_HapticDirection direction; /**< Direction of the effect. */
+
+ /* Replay */
+ Uint32 length; /**< Duration of the effect. */
+ Uint16 delay; /**< Delay before starting the effect. */
+
+ /* Trigger */
+ Uint16 button; /**< Button that triggers the effect. */
+ Uint16 interval; /**< How soon it can be triggered again after button. */
+
+ /* Periodic */
+ Uint16 period; /**< Period of the wave. */
+ Sint16 magnitude; /**< Peak value; if negative, equivalent to 180 degrees extra phase shift. */
+ Sint16 offset; /**< Mean value of the wave. */
+ Uint16 phase; /**< Positive phase shift given by hundredth of a degree. */
+
+ /* Envelope */
+ Uint16 attack_length; /**< Duration of the attack. */
+ Uint16 attack_level; /**< Level at the start of the attack. */
+ Uint16 fade_length; /**< Duration of the fade. */
+ Uint16 fade_level; /**< Level at the end of the fade. */
+} SDL_HapticPeriodic;
+
+/**
+ * \brief A structure containing a template for a Condition effect.
+ *
+ * The struct handles the following effects:
+ * - ::SDL_HAPTIC_SPRING: Effect based on axes position.
+ * - ::SDL_HAPTIC_DAMPER: Effect based on axes velocity.
+ * - ::SDL_HAPTIC_INERTIA: Effect based on axes acceleration.
+ * - ::SDL_HAPTIC_FRICTION: Effect based on axes movement.
+ *
+ * Direction is handled by condition internals instead of a direction member.
+ * The condition effect specific members have three parameters. The first
+ * refers to the X axis, the second refers to the Y axis and the third
+ * refers to the Z axis. The right terms refer to the positive side of the
+ * axis and the left terms refer to the negative side of the axis. Please
+ * refer to the ::SDL_HapticDirection diagram for which side is positive and
+ * which is negative.
+ *
+ * \sa SDL_HapticDirection
+ * \sa SDL_HAPTIC_SPRING
+ * \sa SDL_HAPTIC_DAMPER
+ * \sa SDL_HAPTIC_INERTIA
+ * \sa SDL_HAPTIC_FRICTION
+ * \sa SDL_HapticEffect
+ */
+typedef struct SDL_HapticCondition
+{
+ /* Header */
+ Uint16 type; /**< ::SDL_HAPTIC_SPRING, ::SDL_HAPTIC_DAMPER,
+ ::SDL_HAPTIC_INERTIA or ::SDL_HAPTIC_FRICTION */
+ SDL_HapticDirection direction; /**< Direction of the effect - Not used ATM. */
+
+ /* Replay */
+ Uint32 length; /**< Duration of the effect. */
+ Uint16 delay; /**< Delay before starting the effect. */
+
+ /* Trigger */
+ Uint16 button; /**< Button that triggers the effect. */
+ Uint16 interval; /**< How soon it can be triggered again after button. */
+
+ /* Condition */
+ Uint16 right_sat[3]; /**< Level when joystick is to the positive side; max 0xFFFF. */
+ Uint16 left_sat[3]; /**< Level when joystick is to the negative side; max 0xFFFF. */
+ Sint16 right_coeff[3]; /**< How fast to increase the force towards the positive side. */
+ Sint16 left_coeff[3]; /**< How fast to increase the force towards the negative side. */
+ Uint16 deadband[3]; /**< Size of the dead zone; max 0xFFFF: whole axis-range when 0-centered. */
+ Sint16 center[3]; /**< Position of the dead zone. */
+} SDL_HapticCondition;
+
+/**
+ * \brief A structure containing a template for a Ramp effect.
+ *
+ * This struct is exclusively for the ::SDL_HAPTIC_RAMP effect.
+ *
+ * The ramp effect starts at start strength and ends at end strength.
+ * It augments in linear fashion. If you use attack and fade with a ramp
+ * the effects get added to the ramp effect making the effect become
+ * quadratic instead of linear.
+ *
+ * \sa SDL_HAPTIC_RAMP
+ * \sa SDL_HapticEffect
+ */
+typedef struct SDL_HapticRamp
+{
+ /* Header */
+ Uint16 type; /**< ::SDL_HAPTIC_RAMP */
+ SDL_HapticDirection direction; /**< Direction of the effect. */
+
+ /* Replay */
+ Uint32 length; /**< Duration of the effect. */
+ Uint16 delay; /**< Delay before starting the effect. */
+
+ /* Trigger */
+ Uint16 button; /**< Button that triggers the effect. */
+ Uint16 interval; /**< How soon it can be triggered again after button. */
+
+ /* Ramp */
+ Sint16 start; /**< Beginning strength level. */
+ Sint16 end; /**< Ending strength level. */
+
+ /* Envelope */
+ Uint16 attack_length; /**< Duration of the attack. */
+ Uint16 attack_level; /**< Level at the start of the attack. */
+ Uint16 fade_length; /**< Duration of the fade. */
+ Uint16 fade_level; /**< Level at the end of the fade. */
+} SDL_HapticRamp;
+
+/**
+ * \brief A structure containing a template for a Left/Right effect.
+ *
+ * This struct is exclusively for the ::SDL_HAPTIC_LEFTRIGHT effect.
+ *
+ * The Left/Right effect is used to explicitly control the large and small
+ * motors, commonly found in modern game controllers. One motor is high
+ * frequency, the other is low frequency.
+ *
+ * \sa SDL_HAPTIC_LEFTRIGHT
+ * \sa SDL_HapticEffect
+ */
+typedef struct SDL_HapticLeftRight
+{
+ /* Header */
+ Uint16 type; /**< ::SDL_HAPTIC_LEFTRIGHT */
+
+ /* Replay */
+ Uint32 length; /**< Duration of the effect. */
+
+ /* Rumble */
+ Uint16 large_magnitude; /**< Control of the large controller motor. */
+ Uint16 small_magnitude; /**< Control of the small controller motor. */
+} SDL_HapticLeftRight;
+
+/**
+ * \brief A structure containing a template for the ::SDL_HAPTIC_CUSTOM effect.
+ *
+ * This struct is exclusively for the ::SDL_HAPTIC_CUSTOM effect.
+ *
+ * A custom force feedback effect is much like a periodic effect, where the
+ * application can define its exact shape. You will have to allocate the
+ * data yourself. Data should consist of channels * samples Uint16 samples.
+ *
+ * If channels is one, the effect is rotated using the defined direction.
+ * Otherwise it uses the samples in data for the different axes.
+ *
+ * \sa SDL_HAPTIC_CUSTOM
+ * \sa SDL_HapticEffect
+ */
+typedef struct SDL_HapticCustom
+{
+ /* Header */
+ Uint16 type; /**< ::SDL_HAPTIC_CUSTOM */
+ SDL_HapticDirection direction; /**< Direction of the effect. */
+
+ /* Replay */
+ Uint32 length; /**< Duration of the effect. */
+ Uint16 delay; /**< Delay before starting the effect. */
+
+ /* Trigger */
+ Uint16 button; /**< Button that triggers the effect. */
+ Uint16 interval; /**< How soon it can be triggered again after button. */
+
+ /* Custom */
+ Uint8 channels; /**< Axes to use, minimum of one. */
+ Uint16 period; /**< Sample periods. */
+ Uint16 samples; /**< Amount of samples. */
+ Uint16 *data; /**< Should contain channels*samples items. */
+
+ /* Envelope */
+ Uint16 attack_length; /**< Duration of the attack. */
+ Uint16 attack_level; /**< Level at the start of the attack. */
+ Uint16 fade_length; /**< Duration of the fade. */
+ Uint16 fade_level; /**< Level at the end of the fade. */
+} SDL_HapticCustom;
+
+/**
+ * \brief The generic template for any haptic effect.
+ *
+ * All values max at 32767 (0x7FFF). Signed values also can be negative.
+ * Time values unless specified otherwise are in milliseconds.
+ *
+ * You can also pass ::SDL_HAPTIC_INFINITY to length instead of a 0-32767
+ * value. Neither delay, interval, attack_length nor fade_length support
+ * ::SDL_HAPTIC_INFINITY. Fade will also not be used since effect never ends.
+ *
+ * Additionally, the ::SDL_HAPTIC_RAMP effect does not support a duration of
+ * ::SDL_HAPTIC_INFINITY.
+ *
+ * Button triggers may not be supported on all devices, it is advised to not
+ * use them if possible. Buttons start at index 1 instead of index 0 like
+ * the joystick.
+ *
+ * If both attack_length and fade_level are 0, the envelope is not used,
+ * otherwise both values are used.
+ *
+ * Common parts:
+ * \code
+ * // Replay - All effects have this
+ * Uint32 length; // Duration of effect (ms).
+ * Uint16 delay; // Delay before starting effect.
+ *
+ * // Trigger - All effects have this
+ * Uint16 button; // Button that triggers effect.
+ * Uint16 interval; // How soon before effect can be triggered again.
+ *
+ * // Envelope - All effects except condition effects have this
+ * Uint16 attack_length; // Duration of the attack (ms).
+ * Uint16 attack_level; // Level at the start of the attack.
+ * Uint16 fade_length; // Duration of the fade out (ms).
+ * Uint16 fade_level; // Level at the end of the fade.
+ * \endcode
+ *
+ *
+ * Here we have an example of a constant effect evolution in time:
+ * \verbatim
+ Strength
+ ^
+ |
+ | effect level --> _________________
+ | / \
+ | / \
+ | / \
+ | / \
+ | attack_level --> | \
+ | | | <--- fade_level
+ |
+ +--------------------------------------------------> Time
+ [--] [---]
+ attack_length fade_length
+
+ [------------------][-----------------------]
+ delay length
+ \endverbatim
+ *
+ * Note either the attack_level or the fade_level may be above the actual
+ * effect level.
+ *
+ * \sa SDL_HapticConstant
+ * \sa SDL_HapticPeriodic
+ * \sa SDL_HapticCondition
+ * \sa SDL_HapticRamp
+ * \sa SDL_HapticLeftRight
+ * \sa SDL_HapticCustom
+ */
+typedef union SDL_HapticEffect
+{
+ /* Common for all force feedback effects */
+ Uint16 type; /**< Effect type. */
+ SDL_HapticConstant constant; /**< Constant effect. */
+ SDL_HapticPeriodic periodic; /**< Periodic effect. */
+ SDL_HapticCondition condition; /**< Condition effect. */
+ SDL_HapticRamp ramp; /**< Ramp effect. */
+ SDL_HapticLeftRight leftright; /**< Left/Right effect. */
+ SDL_HapticCustom custom; /**< Custom effect. */
+} SDL_HapticEffect;
+
+
+/* Function prototypes */
+/**
+ * \brief Count the number of haptic devices attached to the system.
+ *
+ * \return Number of haptic devices detected on the system.
+ */
+extern DECLSPEC int SDLCALL SDL_NumHaptics(void);
+
+/**
+ * \brief Get the implementation dependent name of a haptic device.
+ *
+ * This can be called before any joysticks are opened.
+ * If no name can be found, this function returns NULL.
+ *
+ * \param device_index Index of the device to get its name.
+ * \return Name of the device or NULL on error.
+ *
+ * \sa SDL_NumHaptics
+ */
+extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);
+
+/**
+ * \brief Opens a haptic device for use.
+ *
+ * The index passed as an argument refers to the N'th haptic device on this
+ * system.
+ *
+ * When opening a haptic device, its gain will be set to maximum and
+ * autocenter will be disabled. To modify these values use
+ * SDL_HapticSetGain() and SDL_HapticSetAutocenter().
+ *
+ * \param device_index Index of the device to open.
+ * \return Device identifier or NULL on error.
+ *
+ * \sa SDL_HapticIndex
+ * \sa SDL_HapticOpenFromMouse
+ * \sa SDL_HapticOpenFromJoystick
+ * \sa SDL_HapticClose
+ * \sa SDL_HapticSetGain
+ * \sa SDL_HapticSetAutocenter
+ * \sa SDL_HapticPause
+ * \sa SDL_HapticStopAll
+ */
+extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpen(int device_index);
+
+/**
+ * \brief Checks if the haptic device at index has been opened.
+ *
+ * \param device_index Index to check to see if it has been opened.
+ * \return 1 if it has been opened or 0 if it hasn't.
+ *
+ * \sa SDL_HapticOpen
+ * \sa SDL_HapticIndex
+ */
+extern DECLSPEC int SDLCALL SDL_HapticOpened(int device_index);
+
+/**
+ * \brief Gets the index of a haptic device.
+ *
+ * \param haptic Haptic device to get the index of.
+ * \return The index of the haptic device or -1 on error.
+ *
+ * \sa SDL_HapticOpen
+ * \sa SDL_HapticOpened
+ */
+extern DECLSPEC int SDLCALL SDL_HapticIndex(SDL_Haptic * haptic);
+
+/**
+ * \brief Gets whether or not the current mouse has haptic capabilities.
+ *
+ * \return SDL_TRUE if the mouse is haptic, SDL_FALSE if it isn't.
+ *
+ * \sa SDL_HapticOpenFromMouse
+ */
+extern DECLSPEC int SDLCALL SDL_MouseIsHaptic(void);
+
+/**
+ * \brief Tries to open a haptic device from the current mouse.
+ *
+ * \return The haptic device identifier or NULL on error.
+ *
+ * \sa SDL_MouseIsHaptic
+ * \sa SDL_HapticOpen
+ */
+extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromMouse(void);
+
+/**
+ * \brief Checks to see if a joystick has haptic features.
+ *
+ * \param joystick Joystick to test for haptic capabilities.
+ * \return SDL_TRUE if the joystick is haptic, SDL_FALSE if it isn't
+ * or -1 if an error occurred.
+ *
+ * \sa SDL_HapticOpenFromJoystick
+ */
+extern DECLSPEC int SDLCALL SDL_JoystickIsHaptic(SDL_Joystick * joystick);
+
+/**
+ * \brief Opens a haptic device for use from a joystick device.
+ *
+ * You must still close the haptic device separately. It will not be closed
+ * with the joystick.
+ *
+ * When opening from a joystick you should first close the haptic device before
+ * closing the joystick device. If not, on some implementations the haptic
+ * device will also get unallocated and you'll be unable to use force feedback
+ * on that device.
+ *
+ * \param joystick Joystick to create a haptic device from.
+ * \return A valid haptic device identifier on success or NULL on error.
+ *
+ * \sa SDL_HapticOpen
+ * \sa SDL_HapticClose
+ */
+extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromJoystick(SDL_Joystick *
+ joystick);
+
+/**
+ * \brief Closes a haptic device previously opened with SDL_HapticOpen().
+ *
+ * \param haptic Haptic device to close.
+ */
+extern DECLSPEC void SDLCALL SDL_HapticClose(SDL_Haptic * haptic);
+
+/**
+ * \brief Returns the number of effects a haptic device can store.
+ *
+ * On some platforms this isn't fully supported, and therefore is an
+ * approximation. Always check to see if your created effect was actually
+ * created and do not rely solely on SDL_HapticNumEffects().
+ *
+ * \param haptic The haptic device to query effect max.
+ * \return The number of effects the haptic device can store or
+ * -1 on error.
+ *
+ * \sa SDL_HapticNumEffectsPlaying
+ * \sa SDL_HapticQuery
+ */
+extern DECLSPEC int SDLCALL SDL_HapticNumEffects(SDL_Haptic * haptic);
+
+/**
+ * \brief Returns the number of effects a haptic device can play at the same
+ * time.
+ *
+ * This is not supported on all platforms, but will always return a value.
+ * Added here for the sake of completeness.
+ *
+ * \param haptic The haptic device to query maximum playing effects.
+ * \return The number of effects the haptic device can play at the same time
+ * or -1 on error.
+ *
+ * \sa SDL_HapticNumEffects
+ * \sa SDL_HapticQuery
+ */
+extern DECLSPEC int SDLCALL SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic);
+
+/**
+ * \brief Gets the haptic device's supported features in bitwise manner.
+ *
+ * Example:
+ * \code
+ * if (SDL_HapticQuery(haptic) & SDL_HAPTIC_CONSTANT) {
+ * printf("We have constant haptic effect!\n");
+ * }
+ * \endcode
+ *
+ * \param haptic The haptic device to query.
+ * \return Haptic features in bitwise manner (OR'd).
+ *
+ * \sa SDL_HapticNumEffects
+ * \sa SDL_HapticEffectSupported
+ */
+extern DECLSPEC unsigned int SDLCALL SDL_HapticQuery(SDL_Haptic * haptic);
+
+
+/**
+ * \brief Gets the number of haptic axes the device has.
+ *
+ * \sa SDL_HapticDirection
+ */
+extern DECLSPEC int SDLCALL SDL_HapticNumAxes(SDL_Haptic * haptic);
+
+/**
+ * \brief Checks to see if effect is supported by haptic.
+ *
+ * \param haptic Haptic device to check on.
+ * \param effect Effect to check to see if it is supported.
+ * \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error.
+ *
+ * \sa SDL_HapticQuery
+ * \sa SDL_HapticNewEffect
+ */
+extern DECLSPEC int SDLCALL SDL_HapticEffectSupported(SDL_Haptic * haptic,
+ SDL_HapticEffect *
+ effect);
+
+/**
+ * \brief Creates a new haptic effect on the device.
+ *
+ * \param haptic Haptic device to create the effect on.
+ * \param effect Properties of the effect to create.
+ * \return The identifier of the effect on success or -1 on error.
+ *
+ * \sa SDL_HapticUpdateEffect
+ * \sa SDL_HapticRunEffect
+ * \sa SDL_HapticDestroyEffect
+ */
+extern DECLSPEC int SDLCALL SDL_HapticNewEffect(SDL_Haptic * haptic,
+ SDL_HapticEffect * effect);
+
+/**
+ * \brief Updates the properties of an effect.
+ *
+ * Can be used dynamically, although behavior when dynamically changing
+ * direction may be strange. Specifically the effect may reupload itself
+ * and start playing from the start. You cannot change the type either when
+ * running SDL_HapticUpdateEffect().
+ *
+ * \param haptic Haptic device that has the effect.
+ * \param effect Identifier of the effect to update.
+ * \param data New effect properties to use.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticNewEffect
+ * \sa SDL_HapticRunEffect
+ * \sa SDL_HapticDestroyEffect
+ */
+extern DECLSPEC int SDLCALL SDL_HapticUpdateEffect(SDL_Haptic * haptic,
+ int effect,
+ SDL_HapticEffect * data);
+
+/**
+ * \brief Runs the haptic effect on its associated haptic device.
+ *
+ * If iterations are ::SDL_HAPTIC_INFINITY, it'll run the effect over and over
+ * repeating the envelope (attack and fade) every time. If you only want the
+ * effect to last forever, set ::SDL_HAPTIC_INFINITY in the effect's length
+ * parameter.
+ *
+ * \param haptic Haptic device to run the effect on.
+ * \param effect Identifier of the haptic effect to run.
+ * \param iterations Number of iterations to run the effect. Use
+ * ::SDL_HAPTIC_INFINITY for infinity.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticStopEffect
+ * \sa SDL_HapticDestroyEffect
+ * \sa SDL_HapticGetEffectStatus
+ */
+extern DECLSPEC int SDLCALL SDL_HapticRunEffect(SDL_Haptic * haptic,
+ int effect,
+ Uint32 iterations);
+
+/**
+ * \brief Stops the haptic effect on its associated haptic device.
+ *
+ * \param haptic Haptic device to stop the effect on.
+ * \param effect Identifier of the effect to stop.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticRunEffect
+ * \sa SDL_HapticDestroyEffect
+ */
+extern DECLSPEC int SDLCALL SDL_HapticStopEffect(SDL_Haptic * haptic,
+ int effect);
+
+/**
+ * \brief Destroys a haptic effect on the device.
+ *
+ * This will stop the effect if it's running. Effects are automatically
+ * destroyed when the device is closed.
+ *
+ * \param haptic Device to destroy the effect on.
+ * \param effect Identifier of the effect to destroy.
+ *
+ * \sa SDL_HapticNewEffect
+ */
+extern DECLSPEC void SDLCALL SDL_HapticDestroyEffect(SDL_Haptic * haptic,
+ int effect);
+
+/**
+ * \brief Gets the status of the current effect on the haptic device.
+ *
+ * Device must support the ::SDL_HAPTIC_STATUS feature.
+ *
+ * \param haptic Haptic device to query the effect status on.
+ * \param effect Identifier of the effect to query its status.
+ * \return 0 if it isn't playing, 1 if it is playing or -1 on error.
+ *
+ * \sa SDL_HapticRunEffect
+ * \sa SDL_HapticStopEffect
+ */
+extern DECLSPEC int SDLCALL SDL_HapticGetEffectStatus(SDL_Haptic * haptic,
+ int effect);
+
+/**
+ * \brief Sets the global gain of the device.
+ *
+ * Device must support the ::SDL_HAPTIC_GAIN feature.
+ *
+ * The user may specify the maximum gain by setting the environment variable
+ * SDL_HAPTIC_GAIN_MAX which should be between 0 and 100. All calls to
+ * SDL_HapticSetGain() will scale linearly using SDL_HAPTIC_GAIN_MAX as the
+ * maximum.
+ *
+ * \param haptic Haptic device to set the gain on.
+ * \param gain Value to set the gain to, should be between 0 and 100.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticQuery
+ */
+extern DECLSPEC int SDLCALL SDL_HapticSetGain(SDL_Haptic * haptic, int gain);
+
+/**
+ * \brief Sets the global autocenter of the device.
+ *
+ * Autocenter should be between 0 and 100. Setting it to 0 will disable
+ * autocentering.
+ *
+ * Device must support the ::SDL_HAPTIC_AUTOCENTER feature.
+ *
+ * \param haptic Haptic device to set autocentering on.
+ * \param autocenter Value to set autocenter to, 0 disables autocentering.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticQuery
+ */
+extern DECLSPEC int SDLCALL SDL_HapticSetAutocenter(SDL_Haptic * haptic,
+ int autocenter);
+
+/**
+ * \brief Pauses a haptic device.
+ *
+ * Device must support the ::SDL_HAPTIC_PAUSE feature. Call
+ * SDL_HapticUnpause() to resume playback.
+ *
+ * Do not modify the effects nor add new ones while the device is paused.
+ * That can cause all sorts of weird errors.
+ *
+ * \param haptic Haptic device to pause.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticUnpause
+ */
+extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic);
+
+/**
+ * \brief Unpauses a haptic device.
+ *
+ * Call to unpause after SDL_HapticPause().
+ *
+ * \param haptic Haptic device to unpause.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticPause
+ */
+extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic);
+
+/**
+ * \brief Stops all the currently playing effects on a haptic device.
+ *
+ * \param haptic Haptic device to stop.
+ * \return 0 on success or -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic * haptic);
+
+/**
+ * \brief Checks to see if rumble is supported on a haptic device.
+ *
+ * \param haptic Haptic device to check to see if it supports rumble.
+ * \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error.
+ *
+ * \sa SDL_HapticRumbleInit
+ * \sa SDL_HapticRumblePlay
+ * \sa SDL_HapticRumbleStop
+ */
+extern DECLSPEC int SDLCALL SDL_HapticRumbleSupported(SDL_Haptic * haptic);
+
+/**
+ * \brief Initializes the haptic device for simple rumble playback.
+ *
+ * \param haptic Haptic device to initialize for simple rumble playback.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticOpen
+ * \sa SDL_HapticRumbleSupported
+ * \sa SDL_HapticRumblePlay
+ * \sa SDL_HapticRumbleStop
+ */
+extern DECLSPEC int SDLCALL SDL_HapticRumbleInit(SDL_Haptic * haptic);
+
+/**
+ * \brief Runs simple rumble on a haptic device
+ *
+ * \param haptic Haptic device to play rumble effect on.
+ * \param strength Strength of the rumble to play as a 0-1 float value.
+ * \param length Length of the rumble to play in milliseconds.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticRumbleSupported
+ * \sa SDL_HapticRumbleInit
+ * \sa SDL_HapticRumbleStop
+ */
+extern DECLSPEC int SDLCALL SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length );
+
+/**
+ * \brief Stops the simple rumble on a haptic device.
+ *
+ * \param haptic Haptic to stop the rumble on.
+ * \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticRumbleSupported
+ * \sa SDL_HapticRumbleInit
+ * \sa SDL_HapticRumblePlay
+ */
+extern DECLSPEC int SDLCALL SDL_HapticRumbleStop(SDL_Haptic * haptic);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_haptic_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_hints.h b/src/3rdparty/SDL2/include/SDL_hints.h
new file mode 100644
index 0000000..3834640
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_hints.h
@@ -0,0 +1,1022 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_hints.h
+ *
+ * Official documentation for SDL configuration variables
+ *
+ * This file contains functions to set and get configuration hints,
+ * as well as listing each of them alphabetically.
+ *
+ * The convention for naming hints is SDL_HINT_X, where "SDL_X" is
+ * the environment variable that can be used to override the default.
+ *
+ * In general these hints are just that - they may or may not be
+ * supported or applicable on any given platform, but they provide
+ * a way for an application or user to give the library a hint as
+ * to how they would like the library to work.
+ */
+
+#ifndef SDL_hints_h_
+#define SDL_hints_h_
+
+#include "SDL_stdinc.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief A variable controlling how 3D acceleration is used to accelerate the SDL screen surface.
+ *
+ * SDL can try to accelerate the SDL screen surface by using streaming
+ * textures with a 3D rendering engine. This variable controls whether and
+ * how this is done.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable 3D acceleration
+ * "1" - Enable 3D acceleration, using the default renderer.
+ * "X" - Enable 3D acceleration, using X where X is one of the valid rendering drivers. (e.g. "direct3d", "opengl", etc.)
+ *
+ * By default SDL tries to make a best guess for each platform whether
+ * to use acceleration or not.
+ */
+#define SDL_HINT_FRAMEBUFFER_ACCELERATION "SDL_FRAMEBUFFER_ACCELERATION"
+
+/**
+ * \brief A variable specifying which render driver to use.
+ *
+ * If the application doesn't pick a specific renderer to use, this variable
+ * specifies the name of the preferred renderer. If the preferred renderer
+ * can't be initialized, the normal default renderer is used.
+ *
+ * This variable is case insensitive and can be set to the following values:
+ * "direct3d"
+ * "opengl"
+ * "opengles2"
+ * "opengles"
+ * "metal"
+ * "software"
+ *
+ * The default varies by platform, but it's the first one in the list that
+ * is available on the current platform.
+ */
+#define SDL_HINT_RENDER_DRIVER "SDL_RENDER_DRIVER"
+
+/**
+ * \brief A variable controlling whether the OpenGL render driver uses shaders if they are available.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable shaders
+ * "1" - Enable shaders
+ *
+ * By default shaders are used if OpenGL supports them.
+ */
+#define SDL_HINT_RENDER_OPENGL_SHADERS "SDL_RENDER_OPENGL_SHADERS"
+
+/**
+ * \brief A variable controlling whether the Direct3D device is initialized for thread-safe operations.
+ *
+ * This variable can be set to the following values:
+ * "0" - Thread-safety is not enabled (faster)
+ * "1" - Thread-safety is enabled
+ *
+ * By default the Direct3D device is created with thread-safety disabled.
+ */
+#define SDL_HINT_RENDER_DIRECT3D_THREADSAFE "SDL_RENDER_DIRECT3D_THREADSAFE"
+
+/**
+ * \brief A variable controlling whether to enable Direct3D 11+'s Debug Layer.
+ *
+ * This variable does not have any effect on the Direct3D 9 based renderer.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable Debug Layer use
+ * "1" - Enable Debug Layer use
+ *
+ * By default, SDL does not use Direct3D Debug Layer.
+ */
+#define SDL_HINT_RENDER_DIRECT3D11_DEBUG "SDL_RENDER_DIRECT3D11_DEBUG"
+
+/**
+ * \brief A variable controlling the scaling policy for SDL_RenderSetLogicalSize.
+ *
+ * This variable can be set to the following values:
+ * "0" or "letterbox" - Uses letterbox/sidebars to fit the entire rendering on screen
+ * "1" or "overscan" - Will zoom the rendering so it fills the entire screen, allowing edges to be drawn offscreen
+ *
+ * By default letterbox is used
+ */
+#define SDL_HINT_RENDER_LOGICAL_SIZE_MODE "SDL_RENDER_LOGICAL_SIZE_MODE"
+
+/**
+ * \brief A variable controlling the scaling quality
+ *
+ * This variable can be set to the following values:
+ * "0" or "nearest" - Nearest pixel sampling
+ * "1" or "linear" - Linear filtering (supported by OpenGL and Direct3D)
+ * "2" or "best" - Currently this is the same as "linear"
+ *
+ * By default nearest pixel sampling is used
+ */
+#define SDL_HINT_RENDER_SCALE_QUALITY "SDL_RENDER_SCALE_QUALITY"
+
+/**
+ * \brief A variable controlling whether updates to the SDL screen surface should be synchronized with the vertical refresh, to avoid tearing.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable vsync
+ * "1" - Enable vsync
+ *
+ * By default SDL does not sync screen surface updates with vertical refresh.
+ */
+#define SDL_HINT_RENDER_VSYNC "SDL_RENDER_VSYNC"
+
+/**
+ * \brief A variable controlling whether the screensaver is enabled.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable screensaver
+ * "1" - Enable screensaver
+ *
+ * By default SDL will disable the screensaver.
+ */
+#define SDL_HINT_VIDEO_ALLOW_SCREENSAVER "SDL_VIDEO_ALLOW_SCREENSAVER"
+
+/**
+ * \brief A variable controlling whether the X11 VidMode extension should be used.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable XVidMode
+ * "1" - Enable XVidMode
+ *
+ * By default SDL will use XVidMode if it is available.
+ */
+#define SDL_HINT_VIDEO_X11_XVIDMODE "SDL_VIDEO_X11_XVIDMODE"
+
+/**
+ * \brief A variable controlling whether the X11 Xinerama extension should be used.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable Xinerama
+ * "1" - Enable Xinerama
+ *
+ * By default SDL will use Xinerama if it is available.
+ */
+#define SDL_HINT_VIDEO_X11_XINERAMA "SDL_VIDEO_X11_XINERAMA"
+
+/**
+ * \brief A variable controlling whether the X11 XRandR extension should be used.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable XRandR
+ * "1" - Enable XRandR
+ *
+ * By default SDL will not use XRandR because of window manager issues.
+ */
+#define SDL_HINT_VIDEO_X11_XRANDR "SDL_VIDEO_X11_XRANDR"
+
+/**
+ * \brief A variable controlling whether the X11 _NET_WM_PING protocol should be supported.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable _NET_WM_PING
+ * "1" - Enable _NET_WM_PING
+ *
+ * By default SDL will use _NET_WM_PING, but for applications that know they
+ * will not always be able to respond to ping requests in a timely manner they can
+ * turn it off to avoid the window manager thinking the app is hung.
+ * The hint is checked in CreateWindow.
+ */
+#define SDL_HINT_VIDEO_X11_NET_WM_PING "SDL_VIDEO_X11_NET_WM_PING"
+
+/**
+ * \brief A variable controlling whether the X11 _NET_WM_BYPASS_COMPOSITOR hint should be used.
+ *
+ * This variable can be set to the following values:
+ * "0" - Disable _NET_WM_BYPASS_COMPOSITOR
+ * "1" - Enable _NET_WM_BYPASS_COMPOSITOR
+ *
+ * By default SDL will use _NET_WM_BYPASS_COMPOSITOR
+ *
+ */
+#define SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR "SDL_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR"
+
+/**
+ * \brief A variable controlling whether the window frame and title bar are interactive when the cursor is hidden
+ *
+ * This variable can be set to the following values:
+ * "0" - The window frame is not interactive when the cursor is hidden (no move, resize, etc)
+ * "1" - The window frame is interactive when the cursor is hidden
+ *
+ * By default SDL will allow interaction with the window frame when the cursor is hidden
+ */
+#define SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN "SDL_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN"
+
+/**
+ * \brief A variable to specify custom icon resource id from RC file on Windows platform
+ */
+#define SDL_HINT_WINDOWS_INTRESOURCE_ICON "SDL_WINDOWS_INTRESOURCE_ICON"
+#define SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL "SDL_WINDOWS_INTRESOURCE_ICON_SMALL"
+
+/**
+ * \brief A variable controlling whether the windows message loop is processed by SDL
+ *
+ * This variable can be set to the following values:
+ * "0" - The window message loop is not run
+ * "1" - The window message loop is processed in SDL_PumpEvents()
+ *
+ * By default SDL will process the windows message loop
+ */
+#define SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP "SDL_WINDOWS_ENABLE_MESSAGELOOP"
+
+/**
+ * \brief A variable controlling whether grabbing input grabs the keyboard
+ *
+ * This variable can be set to the following values:
+ * "0" - Grab will affect only the mouse
+ * "1" - Grab will affect mouse and keyboard
+ *
+ * By default SDL will not grab the keyboard so system shortcuts still work.
+ */
+#define SDL_HINT_GRAB_KEYBOARD "SDL_GRAB_KEYBOARD"
+
+/**
+ * \brief A variable setting the speed scale for mouse motion, in floating point, when the mouse is not in relative mode
+ */
+#define SDL_HINT_MOUSE_NORMAL_SPEED_SCALE "SDL_MOUSE_NORMAL_SPEED_SCALE"
+
+/**
+ * \brief A variable setting the scale for mouse motion, in floating point, when the mouse is in relative mode
+ */
+#define SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE "SDL_MOUSE_RELATIVE_SPEED_SCALE"
+
+/**
+ * \brief A variable controlling whether relative mouse mode is implemented using mouse warping
+ *
+ * This variable can be set to the following values:
+ * "0" - Relative mouse mode uses raw input
+ * "1" - Relative mouse mode uses mouse warping
+ *
+ * By default SDL will use raw input for relative mouse mode
+ */
+#define SDL_HINT_MOUSE_RELATIVE_MODE_WARP "SDL_MOUSE_RELATIVE_MODE_WARP"
+
+/**
+ * \brief Allow mouse click events when clicking to focus an SDL window
+ *
+ * This variable can be set to the following values:
+ * "0" - Ignore mouse clicks that activate a window
+ * "1" - Generate events for mouse clicks that activate a window
+ *
+ * By default SDL will ignore mouse clicks that activate a window
+ */
+#define SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH "SDL_MOUSE_FOCUS_CLICKTHROUGH"
+
+/**
+ * \brief A variable controlling whether touch events should generate synthetic mouse events
+ *
+ * This variable can be set to the following values:
+ * "0" - Touch events will not generate mouse events
+ * "1" - Touch events will generate mouse events
+ *
+ * By default SDL will generate mouse events for touch events
+ */
+#define SDL_HINT_TOUCH_MOUSE_EVENTS "SDL_TOUCH_MOUSE_EVENTS"
+
+/**
+ * \brief Minimize your SDL_Window if it loses key focus when in fullscreen mode. Defaults to true.
+ *
+ */
+#define SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS"
+
+/**
+ * \brief A variable controlling whether the idle timer is disabled on iOS.
+ *
+ * When an iOS app does not receive touches for some time, the screen is
+ * dimmed automatically. For games where the accelerometer is the only input
+ * this is problematic. This functionality can be disabled by setting this
+ * hint.
+ *
+ * As of SDL 2.0.4, SDL_EnableScreenSaver() and SDL_DisableScreenSaver()
+ * accomplish the same thing on iOS. They should be preferred over this hint.
+ *
+ * This variable can be set to the following values:
+ * "0" - Enable idle timer
+ * "1" - Disable idle timer
+ */
+#define SDL_HINT_IDLE_TIMER_DISABLED "SDL_IOS_IDLE_TIMER_DISABLED"
+
+/**
+ * \brief A variable controlling which orientations are allowed on iOS.
+ *
+ * In some circumstances it is necessary to be able to explicitly control
+ * which UI orientations are allowed.
+ *
+ * This variable is a space delimited list of the following values:
+ * "LandscapeLeft", "LandscapeRight", "Portrait" "PortraitUpsideDown"
+ */
+#define SDL_HINT_ORIENTATIONS "SDL_IOS_ORIENTATIONS"
+
+/**
+ * \brief A variable controlling whether controllers used with the Apple TV
+ * generate UI events.
+ *
+ * When UI events are generated by controller input, the app will be
+ * backgrounded when the Apple TV remote's menu button is pressed, and when the
+ * pause or B buttons on gamepads are pressed.
+ *
+ * More information about properly making use of controllers for the Apple TV
+ * can be found here:
+ * https://developer.apple.com/tvos/human-interface-guidelines/remote-and-controllers/
+ *
+ * This variable can be set to the following values:
+ * "0" - Controller input does not generate UI events (the default).
+ * "1" - Controller input generates UI events.
+ */
+#define SDL_HINT_APPLE_TV_CONTROLLER_UI_EVENTS "SDL_APPLE_TV_CONTROLLER_UI_EVENTS"
+
+/**
+ * \brief A variable controlling whether the Apple TV remote's joystick axes
+ * will automatically match the rotation of the remote.
+ *
+ * This variable can be set to the following values:
+ * "0" - Remote orientation does not affect joystick axes (the default).
+ * "1" - Joystick axes are based on the orientation of the remote.
+ */
+#define SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION "SDL_APPLE_TV_REMOTE_ALLOW_ROTATION"
+
+/**
+ * \brief A variable controlling whether the home indicator bar on iPhone X
+ * should be hidden.
+ *
+ * This variable can be set to the following values:
+ * "0" - The indicator bar is not hidden (default for windowed applications)
+ * "1" - The indicator bar is hidden and is shown when the screen is touched (useful for movie playback applications)
+ * "2" - The indicator bar is dim and the first swipe makes it visible and the second swipe performs the "home" action (default for fullscreen applications)
+ */
+#define SDL_HINT_IOS_HIDE_HOME_INDICATOR "SDL_IOS_HIDE_HOME_INDICATOR"
+
+/**
+ * \brief A variable controlling whether the Android / iOS built-in
+ * accelerometer should be listed as a joystick device.
+ *
+ * This variable can be set to the following values:
+ * "0" - The accelerometer is not listed as a joystick
+ * "1" - The accelerometer is available as a 3 axis joystick (the default).
+ */
+#define SDL_HINT_ACCELEROMETER_AS_JOYSTICK "SDL_ACCELEROMETER_AS_JOYSTICK"
+
+/**
+ * \brief A variable controlling whether the Android / tvOS remotes
+ * should be listed as joystick devices, instead of sending keyboard events.
+ *
+ * This variable can be set to the following values:
+ * "0" - Remotes send enter/escape/arrow key events
+ * "1" - Remotes are available as 2 axis, 2 button joysticks (the default).
+ */
+#define SDL_HINT_TV_REMOTE_AS_JOYSTICK "SDL_TV_REMOTE_AS_JOYSTICK"
+
+/**
+ * \brief A variable that lets you disable the detection and use of Xinput gamepad devices
+ *
+ * The variable can be set to the following values:
+ * "0" - Disable XInput detection (only uses direct input)
+ * "1" - Enable XInput detection (the default)
+ */
+#define SDL_HINT_XINPUT_ENABLED "SDL_XINPUT_ENABLED"
+
+/**
+ * \brief A variable that causes SDL to use the old axis and button mapping for XInput devices.
+ *
+ * This hint is for backwards compatibility only and will be removed in SDL 2.1
+ *
+ * The default value is "0". This hint must be set before SDL_Init()
+ */
+#define SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING "SDL_XINPUT_USE_OLD_JOYSTICK_MAPPING"
+
+/**
+ * \brief A variable that lets you manually hint extra gamecontroller db entries.
+ *
+ * The variable should be newline delimited rows of gamecontroller config data, see SDL_gamecontroller.h
+ *
+ * This hint must be set before calling SDL_Init(SDL_INIT_GAMECONTROLLER)
+ * You can update mappings after the system is initialized with SDL_GameControllerMappingForGUID() and SDL_GameControllerAddMapping()
+ */
+#define SDL_HINT_GAMECONTROLLERCONFIG "SDL_GAMECONTROLLERCONFIG"
+
+/**
+ * \brief A variable containing a list of devices to skip when scanning for game controllers.
+ *
+ * The format of the string is a comma separated list of USB VID/PID pairs
+ * in hexadecimal form, e.g.
+ *
+ * 0xAAAA/0xBBBB,0xCCCC/0xDDDD
+ *
+ * The variable can also take the form of @file, in which case the named
+ * file will be loaded and interpreted as the value of the variable.
+ */
+#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES "SDL_GAMECONTROLLER_IGNORE_DEVICES"
+
+/**
+ * \brief If set, all devices will be skipped when scanning for game controllers except for the ones listed in this variable.
+ *
+ * The format of the string is a comma separated list of USB VID/PID pairs
+ * in hexadecimal form, e.g.
+ *
+ * 0xAAAA/0xBBBB,0xCCCC/0xDDDD
+ *
+ * The variable can also take the form of @file, in which case the named
+ * file will be loaded and interpreted as the value of the variable.
+ */
+#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT "SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT"
+
+/**
+ * \brief A variable that lets you enable joystick (and gamecontroller) events even when your app is in the background.
+ *
+ * The variable can be set to the following values:
+ * "0" - Disable joystick & gamecontroller input events when the
+ * application is in the background.
+ * "1" - Enable joystick & gamecontroller input events when the
+ * application is in the background.
+ *
+ * The default value is "0". This hint may be set at any time.
+ */
+#define SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS "SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS"
+
+/**
+ * \brief If set to "0" then never set the top most bit on a SDL Window, even if the video mode expects it.
+ * This is a debugging aid for developers and not expected to be used by end users. The default is "1"
+ *
+ * This variable can be set to the following values:
+ * "0" - don't allow topmost
+ * "1" - allow topmost
+ */
+#define SDL_HINT_ALLOW_TOPMOST "SDL_ALLOW_TOPMOST"
+
+/**
+ * \brief A variable that controls the timer resolution, in milliseconds.
+ *
+ * The higher resolution the timer, the more frequently the CPU services
+ * timer interrupts, and the more precise delays are, but this takes up
+ * power and CPU time. This hint is only used on Windows 7 and earlier.
+ *
+ * See this blog post for more information:
+ * http://randomascii.wordpress.com/2013/07/08/windows-timer-resolution-megawatts-wasted/
+ *
+ * If this variable is set to "0", the system timer resolution is not set.
+ *
+ * The default value is "1". This hint may be set at any time.
+ */
+#define SDL_HINT_TIMER_RESOLUTION "SDL_TIMER_RESOLUTION"
+
+
+/**
+ * \brief A variable describing the content orientation on QtWayland-based platforms.
+ *
+ * On QtWayland platforms, windows are rotated client-side to allow for custom
+ * transitions. In order to correctly position overlays (e.g. volume bar) and
+ * gestures (e.g. events view, close/minimize gestures), the system needs to
+ * know in which orientation the application is currently drawing its contents.
+ *
+ * This does not cause the window to be rotated or resized, the application
+ * needs to take care of drawing the content in the right orientation (the
+ * framebuffer is always in portrait mode).
+ *
+ * This variable can be one of the following values:
+ * "primary" (default), "portrait", "landscape", "inverted-portrait", "inverted-landscape"
+ */
+#define SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION "SDL_QTWAYLAND_CONTENT_ORIENTATION"
+
+/**
+ * \brief Flags to set on QtWayland windows to integrate with the native window manager.
+ *
+ * On QtWayland platforms, this hint controls the flags to set on the windows.
+ * For example, on Sailfish OS "OverridesSystemGestures" disables swipe gestures.
+ *
+ * This variable is a space-separated list of the following values (empty = no flags):
+ * "OverridesSystemGestures", "StaysOnTop", "BypassWindowManager"
+ */
+#define SDL_HINT_QTWAYLAND_WINDOW_FLAGS "SDL_QTWAYLAND_WINDOW_FLAGS"
+
+/**
+* \brief A string specifying SDL's threads stack size in bytes or "0" for the backend's default size
+*
+* Use this hint in case you need to set SDL's threads stack size to other than the default.
+* This is specially useful if you build SDL against a non glibc libc library (such as musl) which
+* provides a relatively small default thread stack size (a few kilobytes versus the default 8MB glibc uses).
+* Support for this hint is currently available only in the pthread, Windows, and PSP backend.
+*/
+#define SDL_HINT_THREAD_STACK_SIZE "SDL_THREAD_STACK_SIZE"
+
+/**
+ * \brief If set to 1, then do not allow high-DPI windows. ("Retina" on Mac and iOS)
+ */
+#define SDL_HINT_VIDEO_HIGHDPI_DISABLED "SDL_VIDEO_HIGHDPI_DISABLED"
+
+/**
+ * \brief A variable that determines whether ctrl+click should generate a right-click event on Mac
+ *
+ * If present, holding ctrl while left clicking will generate a right click
+ * event when on Mac.
+ */
+#define SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK "SDL_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK"
+
+/**
+* \brief A variable specifying which shader compiler to preload when using the Chrome ANGLE binaries
+*
+* SDL has EGL and OpenGL ES2 support on Windows via the ANGLE project. It
+* can use two different sets of binaries, those compiled by the user from source
+* or those provided by the Chrome browser. In the later case, these binaries require
+* that SDL loads a DLL providing the shader compiler.
+*
+* This variable can be set to the following values:
+* "d3dcompiler_46.dll" - default, best for Vista or later.
+* "d3dcompiler_43.dll" - for XP support.
+* "none" - do not load any library, useful if you compiled ANGLE from source and included the compiler in your binaries.
+*
+*/
+#define SDL_HINT_VIDEO_WIN_D3DCOMPILER "SDL_VIDEO_WIN_D3DCOMPILER"
+
+/**
+* \brief A variable that is the address of another SDL_Window* (as a hex string formatted with "%p").
+*
+* If this hint is set before SDL_CreateWindowFrom() and the SDL_Window* it is set to has
+* SDL_WINDOW_OPENGL set (and running on WGL only, currently), then two things will occur on the newly
+* created SDL_Window:
+*
+* 1. Its pixel format will be set to the same pixel format as this SDL_Window. This is
+* needed for example when sharing an OpenGL context across multiple windows.
+*
+* 2. The flag SDL_WINDOW_OPENGL will be set on the new window so it can be used for
+* OpenGL rendering.
+*
+* This variable can be set to the following values:
+* The address (as a string "%p") of the SDL_Window* that new windows created with SDL_CreateWindowFrom() should
+* share a pixel format with.
+*/
+#define SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT"
+
+/**
+ * \brief A URL to a WinRT app's privacy policy
+ *
+ * All network-enabled WinRT apps must make a privacy policy available to its
+ * users. On Windows 8, 8.1, and RT, Microsoft mandates that this policy be
+ * be available in the Windows Settings charm, as accessed from within the app.
+ * SDL provides code to add a URL-based link there, which can point to the app's
+ * privacy policy.
+ *
+ * To setup a URL to an app's privacy policy, set SDL_HINT_WINRT_PRIVACY_POLICY_URL
+ * before calling any SDL_Init() functions. The contents of the hint should
+ * be a valid URL. For example, "http://www.example.com".
+ *
+ * The default value is "", which will prevent SDL from adding a privacy policy
+ * link to the Settings charm. This hint should only be set during app init.
+ *
+ * The label text of an app's "Privacy Policy" link may be customized via another
+ * hint, SDL_HINT_WINRT_PRIVACY_POLICY_LABEL.
+ *
+ * Please note that on Windows Phone, Microsoft does not provide standard UI
+ * for displaying a privacy policy link, and as such, SDL_HINT_WINRT_PRIVACY_POLICY_URL
+ * will not get used on that platform. Network-enabled phone apps should display
+ * their privacy policy through some other, in-app means.
+ */
+#define SDL_HINT_WINRT_PRIVACY_POLICY_URL "SDL_WINRT_PRIVACY_POLICY_URL"
+
+/** \brief Label text for a WinRT app's privacy policy link
+ *
+ * Network-enabled WinRT apps must include a privacy policy. On Windows 8, 8.1, and RT,
+ * Microsoft mandates that this policy be available via the Windows Settings charm.
+ * SDL provides code to add a link there, with its label text being set via the
+ * optional hint, SDL_HINT_WINRT_PRIVACY_POLICY_LABEL.
+ *
+ * Please note that a privacy policy's contents are not set via this hint. A separate
+ * hint, SDL_HINT_WINRT_PRIVACY_POLICY_URL, is used to link to the actual text of the
+ * policy.
+ *
+ * The contents of this hint should be encoded as a UTF8 string.
+ *
+ * The default value is "Privacy Policy". This hint should only be set during app
+ * initialization, preferably before any calls to SDL_Init().
+ *
+ * For additional information on linking to a privacy policy, see the documentation for
+ * SDL_HINT_WINRT_PRIVACY_POLICY_URL.
+ */
+#define SDL_HINT_WINRT_PRIVACY_POLICY_LABEL "SDL_WINRT_PRIVACY_POLICY_LABEL"
+
+/** \brief Allows back-button-press events on Windows Phone to be marked as handled
+ *
+ * Windows Phone devices typically feature a Back button. When pressed,
+ * the OS will emit back-button-press events, which apps are expected to
+ * handle in an appropriate manner. If apps do not explicitly mark these
+ * events as 'Handled', then the OS will invoke its default behavior for
+ * unhandled back-button-press events, which on Windows Phone 8 and 8.1 is to
+ * terminate the app (and attempt to switch to the previous app, or to the
+ * device's home screen).
+ *
+ * Setting the SDL_HINT_WINRT_HANDLE_BACK_BUTTON hint to "1" will cause SDL
+ * to mark back-button-press events as Handled, if and when one is sent to
+ * the app.
+ *
+ * Internally, Windows Phone sends back button events as parameters to
+ * special back-button-press callback functions. Apps that need to respond
+ * to back-button-press events are expected to register one or more
+ * callback functions for such, shortly after being launched (during the
+ * app's initialization phase). After the back button is pressed, the OS
+ * will invoke these callbacks. If the app's callback(s) do not explicitly
+ * mark the event as handled by the time they return, or if the app never
+ * registers one of these callback, the OS will consider the event
+ * un-handled, and it will apply its default back button behavior (terminate
+ * the app).
+ *
+ * SDL registers its own back-button-press callback with the Windows Phone
+ * OS. This callback will emit a pair of SDL key-press events (SDL_KEYDOWN
+ * and SDL_KEYUP), each with a scancode of SDL_SCANCODE_AC_BACK, after which
+ * it will check the contents of the hint, SDL_HINT_WINRT_HANDLE_BACK_BUTTON.
+ * If the hint's value is set to "1", the back button event's Handled
+ * property will get set to 'true'. If the hint's value is set to something
+ * else, or if it is unset, SDL will leave the event's Handled property
+ * alone. (By default, the OS sets this property to 'false', to note.)
+ *
+ * SDL apps can either set SDL_HINT_WINRT_HANDLE_BACK_BUTTON well before a
+ * back button is pressed, or can set it in direct-response to a back button
+ * being pressed.
+ *
+ * In order to get notified when a back button is pressed, SDL apps should
+ * register a callback function with SDL_AddEventWatch(), and have it listen
+ * for SDL_KEYDOWN events that have a scancode of SDL_SCANCODE_AC_BACK.
+ * (Alternatively, SDL_KEYUP events can be listened-for. Listening for
+ * either event type is suitable.) Any value of SDL_HINT_WINRT_HANDLE_BACK_BUTTON
+ * set by such a callback, will be applied to the OS' current
+ * back-button-press event.
+ *
+ * More details on back button behavior in Windows Phone apps can be found
+ * at the following page, on Microsoft's developer site:
+ * http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj247550(v=vs.105).aspx
+ */
+#define SDL_HINT_WINRT_HANDLE_BACK_BUTTON "SDL_WINRT_HANDLE_BACK_BUTTON"
+
+/**
+ * \brief A variable that dictates policy for fullscreen Spaces on Mac OS X.
+ *
+ * This hint only applies to Mac OS X.
+ *
+ * The variable can be set to the following values:
+ * "0" - Disable Spaces support (FULLSCREEN_DESKTOP won't use them and
+ * SDL_WINDOW_RESIZABLE windows won't offer the "fullscreen"
+ * button on their titlebars).
+ * "1" - Enable Spaces support (FULLSCREEN_DESKTOP will use them and
+ * SDL_WINDOW_RESIZABLE windows will offer the "fullscreen"
+ * button on their titlebars).
+ *
+ * The default value is "1". Spaces are disabled regardless of this hint if
+ * the OS isn't at least Mac OS X Lion (10.7). This hint must be set before
+ * any windows are created.
+ */
+#define SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES "SDL_VIDEO_MAC_FULLSCREEN_SPACES"
+
+/**
+* \brief When set don't force the SDL app to become a foreground process
+*
+* This hint only applies to Mac OS X.
+*
+*/
+#define SDL_HINT_MAC_BACKGROUND_APP "SDL_MAC_BACKGROUND_APP"
+
+/**
+ * \brief Android APK expansion main file version. Should be a string number like "1", "2" etc.
+ *
+ * Must be set together with SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION.
+ *
+ * If both hints were set then SDL_RWFromFile() will look into expansion files
+ * after a given relative path was not found in the internal storage and assets.
+ *
+ * By default this hint is not set and the APK expansion files are not searched.
+ */
+#define SDL_HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION "SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION"
+
+/**
+ * \brief Android APK expansion patch file version. Should be a string number like "1", "2" etc.
+ *
+ * Must be set together with SDL_HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION.
+ *
+ * If both hints were set then SDL_RWFromFile() will look into expansion files
+ * after a given relative path was not found in the internal storage and assets.
+ *
+ * By default this hint is not set and the APK expansion files are not searched.
+ */
+#define SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION "SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION"
+
+/**
+ * \brief A variable to control whether certain IMEs should handle text editing internally instead of sending SDL_TEXTEDITING events.
+ *
+ * The variable can be set to the following values:
+ * "0" - SDL_TEXTEDITING events are sent, and it is the application's
+ * responsibility to render the text from these events and
+ * differentiate it somehow from committed text. (default)
+ * "1" - If supported by the IME then SDL_TEXTEDITING events are not sent,
+ * and text that is being composed will be rendered in its own UI.
+ */
+#define SDL_HINT_IME_INTERNAL_EDITING "SDL_IME_INTERNAL_EDITING"
+
+ /**
+ * \brief A variable to control whether mouse and touch events are to be treated together or separately
+ *
+ * The variable can be set to the following values:
+ * "0" - Mouse events will be handled as touch events, and touch will raise fake mouse
+ * events. This is the behaviour of SDL <= 2.0.3. (default)
+ * "1" - Mouse events will be handled separately from pure touch events.
+ *
+ * The value of this hint is used at runtime, so it can be changed at any time.
+ */
+#define SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH "SDL_ANDROID_SEPARATE_MOUSE_AND_TOUCH"
+
+ /**
+ * \brief A variable to control whether the return key on the soft keyboard
+ * should hide the soft keyboard on Android and iOS.
+ *
+ * The variable can be set to the following values:
+ * "0" - The return key will be handled as a key event. This is the behaviour of SDL <= 2.0.3. (default)
+ * "1" - The return key will hide the keyboard.
+ *
+ * The value of this hint is used at runtime, so it can be changed at any time.
+ */
+#define SDL_HINT_RETURN_KEY_HIDES_IME "SDL_RETURN_KEY_HIDES_IME"
+
+/**
+ * \brief override the binding element for keyboard inputs for Emscripten builds
+ *
+ * This hint only applies to the emscripten platform
+ *
+ * The variable can be one of
+ * "#window" - The javascript window object (this is the default)
+ * "#document" - The javascript document object
+ * "#screen" - the javascript window.screen object
+ * "#canvas" - the WebGL canvas element
+ * any other string without a leading # sign applies to the element on the page with that ID.
+ */
+#define SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT "SDL_EMSCRIPTEN_KEYBOARD_ELEMENT"
+
+/**
+ * \brief Tell SDL not to catch the SIGINT or SIGTERM signals.
+ *
+ * This hint only applies to Unix-like platforms.
+ *
+ * The variable can be set to the following values:
+ * "0" - SDL will install a SIGINT and SIGTERM handler, and when it
+ * catches a signal, convert it into an SDL_QUIT event.
+ * "1" - SDL will not install a signal handler at all.
+ */
+#define SDL_HINT_NO_SIGNAL_HANDLERS "SDL_NO_SIGNAL_HANDLERS"
+
+/**
+ * \brief Tell SDL not to generate window-close events for Alt+F4 on Windows.
+ *
+ * The variable can be set to the following values:
+ * "0" - SDL will generate a window-close event when it sees Alt+F4.
+ * "1" - SDL will only do normal key handling for Alt+F4.
+ */
+#define SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4 "SDL_WINDOWS_NO_CLOSE_ON_ALT_F4"
+
+/**
+ * \brief Prevent SDL from using version 4 of the bitmap header when saving BMPs.
+ *
+ * The bitmap header version 4 is required for proper alpha channel support and
+ * SDL will use it when required. Should this not be desired, this hint can
+ * force the use of the 40 byte header version which is supported everywhere.
+ *
+ * The variable can be set to the following values:
+ * "0" - Surfaces with a colorkey or an alpha channel are saved to a
+ * 32-bit BMP file with an alpha mask. SDL will use the bitmap
+ * header version 4 and set the alpha mask accordingly.
+ * "1" - Surfaces with a colorkey or an alpha channel are saved to a
+ * 32-bit BMP file without an alpha mask. The alpha channel data
+ * will be in the file, but applications are going to ignore it.
+ *
+ * The default value is "0".
+ */
+#define SDL_HINT_BMP_SAVE_LEGACY_FORMAT "SDL_BMP_SAVE_LEGACY_FORMAT"
+
+/**
+ * \brief Tell SDL not to name threads on Windows with the 0x406D1388 Exception.
+ * The 0x406D1388 Exception is a trick used to inform Visual Studio of a
+ * thread's name, but it tends to cause problems with other debuggers,
+ * and the .NET runtime. Note that SDL 2.0.6 and later will still use
+ * the (safer) SetThreadDescription API, introduced in the Windows 10
+ * Creators Update, if available.
+ *
+ * The variable can be set to the following values:
+ * "0" - SDL will raise the 0x406D1388 Exception to name threads.
+ * This is the default behavior of SDL <= 2.0.4.
+ * "1" - SDL will not raise this exception, and threads will be unnamed. (default)
+ * This is necessary with .NET languages or debuggers that aren't Visual Studio.
+ */
+#define SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING "SDL_WINDOWS_DISABLE_THREAD_NAMING"
+
+/**
+ * \brief Tell SDL which Dispmanx layer to use on a Raspberry PI
+ *
+ * Also known as Z-order. The variable can take a negative or positive value.
+ * The default is 10000.
+ */
+#define SDL_HINT_RPI_VIDEO_LAYER "SDL_RPI_VIDEO_LAYER"
+
+/**
+ * \brief Tell the video driver that we only want a double buffer.
+ *
+ * By default, most lowlevel 2D APIs will use a triple buffer scheme that
+ * wastes no CPU time on waiting for vsync after issuing a flip, but
+ * introduces a frame of latency. On the other hand, using a double buffer
+ * scheme instead is recommended for cases where low latency is an important
+ * factor because we save a whole frame of latency.
+ * We do so by waiting for vsync immediately after issuing a flip, usually just
+ * after eglSwapBuffers call in the backend's *_SwapWindow function.
+ *
+ * Since it's driver-specific, it's only supported where possible and
+ * implemented. Currently supported the following drivers:
+ * - KMSDRM (kmsdrm)
+ * - Raspberry Pi (raspberrypi)
+ */
+#define SDL_HINT_VIDEO_DOUBLE_BUFFER "SDL_VIDEO_DOUBLE_BUFFER"
+
+/**
+ * \brief A variable controlling what driver to use for OpenGL ES contexts.
+ *
+ * On some platforms, currently Windows and X11, OpenGL drivers may support
+ * creating contexts with an OpenGL ES profile. By default SDL uses these
+ * profiles, when available, otherwise it attempts to load an OpenGL ES
+ * library, e.g. that provided by the ANGLE project. This variable controls
+ * whether SDL follows this default behaviour or will always load an
+ * OpenGL ES library.
+ *
+ * Circumstances where this is useful include
+ * - Testing an app with a particular OpenGL ES implementation, e.g ANGLE,
+ * or emulator, e.g. those from ARM, Imagination or Qualcomm.
+ * - Resolving OpenGL ES function addresses at link time by linking with
+ * the OpenGL ES library instead of querying them at run time with
+ * SDL_GL_GetProcAddress().
+ *
+ * Caution: for an application to work with the default behaviour across
+ * different OpenGL drivers it must query the OpenGL ES function
+ * addresses at run time using SDL_GL_GetProcAddress().
+ *
+ * This variable is ignored on most platforms because OpenGL ES is native
+ * or not supported.
+ *
+ * This variable can be set to the following values:
+ * "0" - Use ES profile of OpenGL, if available. (Default when not set.)
+ * "1" - Load OpenGL ES library using the default library names.
+ *
+ */
+#define SDL_HINT_OPENGL_ES_DRIVER "SDL_OPENGL_ES_DRIVER"
+
+/**
+ * \brief A variable controlling speed/quality tradeoff of audio resampling.
+ *
+ * If available, SDL can use libsamplerate ( http://www.mega-nerd.com/SRC/ )
+ * to handle audio resampling. There are different resampling modes available
+ * that produce different levels of quality, using more CPU.
+ *
+ * If this hint isn't specified to a valid setting, or libsamplerate isn't
+ * available, SDL will use the default, internal resampling algorithm.
+ *
+ * Note that this is currently only applicable to resampling audio that is
+ * being written to a device for playback or audio being read from a device
+ * for capture. SDL_AudioCVT always uses the default resampler (although this
+ * might change for SDL 2.1).
+ *
+ * This hint is currently only checked at audio subsystem initialization.
+ *
+ * This variable can be set to the following values:
+ *
+ * "0" or "default" - Use SDL's internal resampling (Default when not set - low quality, fast)
+ * "1" or "fast" - Use fast, slightly higher quality resampling, if available
+ * "2" or "medium" - Use medium quality resampling, if available
+ * "3" or "best" - Use high quality resampling, if available
+ */
+#define SDL_HINT_AUDIO_RESAMPLING_MODE "SDL_AUDIO_RESAMPLING_MODE"
+
+/**
+ * \brief A variable controlling the audio category on iOS and Mac OS X
+ *
+ * This variable can be set to the following values:
+ *
+ * "ambient" - Use the AVAudioSessionCategoryAmbient audio category, will be muted by the phone mute switch (default)
+ * "playback" - Use the AVAudioSessionCategoryPlayback category
+ *
+ * For more information, see Apple's documentation:
+ * https://developer.apple.com/library/content/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioSessionCategoriesandModes/AudioSessionCategoriesandModes.html
+ */
+#define SDL_HINT_AUDIO_CATEGORY "SDL_AUDIO_CATEGORY"
+
+/**
+ * \brief An enumeration of hint priorities
+ */
+typedef enum
+{
+ SDL_HINT_DEFAULT,
+ SDL_HINT_NORMAL,
+ SDL_HINT_OVERRIDE
+} SDL_HintPriority;
+
+
+/**
+ * \brief Set a hint with a specific priority
+ *
+ * The priority controls the behavior when setting a hint that already
+ * has a value. Hints will replace existing hints of their priority and
+ * lower. Environment variables are considered to have override priority.
+ *
+ * \return SDL_TRUE if the hint was set, SDL_FALSE otherwise
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_SetHintWithPriority(const char *name,
+ const char *value,
+ SDL_HintPriority priority);
+
+/**
+ * \brief Set a hint with normal priority
+ *
+ * \return SDL_TRUE if the hint was set, SDL_FALSE otherwise
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_SetHint(const char *name,
+ const char *value);
+
+/**
+ * \brief Get a hint
+ *
+ * \return The string value of a hint variable.
+ */
+extern DECLSPEC const char * SDLCALL SDL_GetHint(const char *name);
+
+/**
+ * \brief Get a hint
+ *
+ * \return The boolean value of a hint variable.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_GetHintBoolean(const char *name, SDL_bool default_value);
+
+/**
+ * \brief type definition of the hint callback function.
+ */
+typedef void (SDLCALL *SDL_HintCallback)(void *userdata, const char *name, const char *oldValue, const char *newValue);
+
+/**
+ * \brief Add a function to watch a particular hint
+ *
+ * \param name The hint to watch
+ * \param callback The function to call when the hint value changes
+ * \param userdata A pointer to pass to the callback function
+ */
+extern DECLSPEC void SDLCALL SDL_AddHintCallback(const char *name,
+ SDL_HintCallback callback,
+ void *userdata);
+
+/**
+ * \brief Remove a function watching a particular hint
+ *
+ * \param name The hint being watched
+ * \param callback The function being called when the hint value changes
+ * \param userdata A pointer being passed to the callback function
+ */
+extern DECLSPEC void SDLCALL SDL_DelHintCallback(const char *name,
+ SDL_HintCallback callback,
+ void *userdata);
+
+/**
+ * \brief Clear all hints
+ *
+ * This function is called during SDL_Quit() to free stored hints.
+ */
+extern DECLSPEC void SDLCALL SDL_ClearHints(void);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_hints_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_joystick.h b/src/3rdparty/SDL2/include/SDL_joystick.h
new file mode 100644
index 0000000..f67772d
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_joystick.h
@@ -0,0 +1,382 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_joystick.h
+ *
+ * Include file for SDL joystick event handling
+ *
+ * The term "device_index" identifies currently plugged in joystick devices between 0 and SDL_NumJoysticks(), with the exact joystick
+ * behind a device_index changing as joysticks are plugged and unplugged.
+ *
+ * The term "instance_id" is the current instantiation of a joystick device in the system, if the joystick is removed and then re-inserted
+ * then it will get a new instance_id, instance_id's are monotonically increasing identifiers of a joystick plugged in.
+ *
+ * The term JoystickGUID is a stable 128-bit identifier for a joystick device that does not change over time, it identifies class of
+ * the device (a X360 wired controller for example). This identifier is platform dependent.
+ *
+ *
+ */
+
+#ifndef SDL_joystick_h_
+#define SDL_joystick_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \file SDL_joystick.h
+ *
+ * In order to use these functions, SDL_Init() must have been called
+ * with the ::SDL_INIT_JOYSTICK flag. This causes SDL to scan the system
+ * for joysticks, and load appropriate drivers.
+ *
+ * If you would like to receive joystick updates while the application
+ * is in the background, you should set the following hint before calling
+ * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
+ */
+
+/**
+ * The joystick structure used to identify an SDL joystick
+ */
+struct _SDL_Joystick;
+typedef struct _SDL_Joystick SDL_Joystick;
+
+/* A structure that encodes the stable unique id for a joystick device */
+typedef struct {
+ Uint8 data[16];
+} SDL_JoystickGUID;
+
+/**
+ * This is a unique ID for a joystick for the time it is connected to the system,
+ * and is never reused for the lifetime of the application. If the joystick is
+ * disconnected and reconnected, it will get a new ID.
+ *
+ * The ID value starts at 0 and increments from there. The value -1 is an invalid ID.
+ */
+typedef Sint32 SDL_JoystickID;
+
+typedef enum
+{
+ SDL_JOYSTICK_TYPE_UNKNOWN,
+ SDL_JOYSTICK_TYPE_GAMECONTROLLER,
+ SDL_JOYSTICK_TYPE_WHEEL,
+ SDL_JOYSTICK_TYPE_ARCADE_STICK,
+ SDL_JOYSTICK_TYPE_FLIGHT_STICK,
+ SDL_JOYSTICK_TYPE_DANCE_PAD,
+ SDL_JOYSTICK_TYPE_GUITAR,
+ SDL_JOYSTICK_TYPE_DRUM_KIT,
+ SDL_JOYSTICK_TYPE_ARCADE_PAD,
+ SDL_JOYSTICK_TYPE_THROTTLE
+} SDL_JoystickType;
+
+typedef enum
+{
+ SDL_JOYSTICK_POWER_UNKNOWN = -1,
+ SDL_JOYSTICK_POWER_EMPTY,
+ SDL_JOYSTICK_POWER_LOW,
+ SDL_JOYSTICK_POWER_MEDIUM,
+ SDL_JOYSTICK_POWER_FULL,
+ SDL_JOYSTICK_POWER_WIRED,
+ SDL_JOYSTICK_POWER_MAX
+} SDL_JoystickPowerLevel;
+
+/* Function prototypes */
+
+/**
+ * Locking for multi-threaded access to the joystick API
+ *
+ * If you are using the joystick API or handling events from multiple threads
+ * you should use these locking functions to protect access to the joysticks.
+ *
+ * In particular, you are guaranteed that the joystick list won't change, so
+ * the API functions that take a joystick index will be valid, and joystick
+ * and game controller events will not be delivered.
+ */
+extern DECLSPEC void SDLCALL SDL_LockJoysticks(void);
+extern DECLSPEC void SDLCALL SDL_UnlockJoysticks(void);
+
+/**
+ * Count the number of joysticks attached to the system right now
+ */
+extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
+
+/**
+ * Get the implementation dependent name of a joystick.
+ * This can be called before any joysticks are opened.
+ * If no name can be found, this function returns NULL.
+ */
+extern DECLSPEC const char *SDLCALL SDL_JoystickNameForIndex(int device_index);
+
+/**
+ * Return the GUID for the joystick at this index
+ * This can be called before any joysticks are opened.
+ */
+extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);
+
+/**
+ * Get the USB vendor ID of a joystick, if available.
+ * This can be called before any joysticks are opened.
+ * If the vendor ID isn't available this function returns 0.
+ */
+extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceVendor(int device_index);
+
+/**
+ * Get the USB product ID of a joystick, if available.
+ * This can be called before any joysticks are opened.
+ * If the product ID isn't available this function returns 0.
+ */
+extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProduct(int device_index);
+
+/**
+ * Get the product version of a joystick, if available.
+ * This can be called before any joysticks are opened.
+ * If the product version isn't available this function returns 0.
+ */
+extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProductVersion(int device_index);
+
+/**
+ * Get the type of a joystick, if available.
+ * This can be called before any joysticks are opened.
+ */
+extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetDeviceType(int device_index);
+
+/**
+ * Get the instance ID of a joystick.
+ * This can be called before any joysticks are opened.
+ * If the index is out of range, this function will return -1.
+ */
+extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickGetDeviceInstanceID(int device_index);
+
+/**
+ * Open a joystick for use.
+ * The index passed as an argument refers to the N'th joystick on the system.
+ * This index is not the value which will identify this joystick in future
+ * joystick events. The joystick's instance id (::SDL_JoystickID) will be used
+ * there instead.
+ *
+ * \return A joystick identifier, or NULL if an error occurred.
+ */
+extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);
+
+/**
+ * Return the SDL_Joystick associated with an instance id.
+ */
+extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromInstanceID(SDL_JoystickID joyid);
+
+/**
+ * Return the name for this currently opened joystick.
+ * If no name can be found, this function returns NULL.
+ */
+extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick * joystick);
+
+/**
+ * Return the GUID for this opened joystick
+ */
+extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick);
+
+/**
+ * Get the USB vendor ID of an opened joystick, if available.
+ * If the vendor ID isn't available this function returns 0.
+ */
+extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetVendor(SDL_Joystick * joystick);
+
+/**
+ * Get the USB product ID of an opened joystick, if available.
+ * If the product ID isn't available this function returns 0.
+ */
+extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProduct(SDL_Joystick * joystick);
+
+/**
+ * Get the product version of an opened joystick, if available.
+ * If the product version isn't available this function returns 0.
+ */
+extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProductVersion(SDL_Joystick * joystick);
+
+/**
+ * Get the type of an opened joystick.
+ */
+extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetType(SDL_Joystick * joystick);
+
+/**
+ * Return a string representation for this guid. pszGUID must point to at least 33 bytes
+ * (32 for the string plus a NULL terminator).
+ */
+extern DECLSPEC void SDLCALL SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);
+
+/**
+ * Convert a string into a joystick guid
+ */
+extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
+
+/**
+ * Returns SDL_TRUE if the joystick has been opened and currently connected, or SDL_FALSE if it has not.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick * joystick);
+
+/**
+ * Get the instance ID of an opened joystick or -1 if the joystick is invalid.
+ */
+extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick * joystick);
+
+/**
+ * Get the number of general axis controls on a joystick.
+ */
+extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick);
+
+/**
+ * Get the number of trackballs on a joystick.
+ *
+ * Joystick trackballs have only relative motion events associated
+ * with them and their state cannot be polled.
+ */
+extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick * joystick);
+
+/**
+ * Get the number of POV hats on a joystick.
+ */
+extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick * joystick);
+
+/**
+ * Get the number of buttons on a joystick.
+ */
+extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick * joystick);
+
+/**
+ * Update the current state of the open joysticks.
+ *
+ * This is called automatically by the event loop if any joystick
+ * events are enabled.
+ */
+extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
+
+/**
+ * Enable/disable joystick event polling.
+ *
+ * If joystick events are disabled, you must call SDL_JoystickUpdate()
+ * yourself and check the state of the joystick when you want joystick
+ * information.
+ *
+ * The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE.
+ */
+extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
+
+#define SDL_JOYSTICK_AXIS_MAX 32767
+#define SDL_JOYSTICK_AXIS_MIN -32768
+/**
+ * Get the current state of an axis control on a joystick.
+ *
+ * The state is a value ranging from -32768 to 32767.
+ *
+ * The axis indices start at index 0.
+ */
+extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick * joystick,
+ int axis);
+
+/**
+ * Get the initial state of an axis control on a joystick.
+ *
+ * The state is a value ranging from -32768 to 32767.
+ *
+ * The axis indices start at index 0.
+ *
+ * \return SDL_TRUE if this axis has any initial value, or SDL_FALSE if not.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAxisInitialState(SDL_Joystick * joystick,
+ int axis, Sint16 *state);
+
+/**
+ * \name Hat positions
+ */
+/* @{ */
+#define SDL_HAT_CENTERED 0x00
+#define SDL_HAT_UP 0x01
+#define SDL_HAT_RIGHT 0x02
+#define SDL_HAT_DOWN 0x04
+#define SDL_HAT_LEFT 0x08
+#define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
+#define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
+#define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
+#define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
+/* @} */
+
+/**
+ * Get the current state of a POV hat on a joystick.
+ *
+ * The hat indices start at index 0.
+ *
+ * \return The return value is one of the following positions:
+ * - ::SDL_HAT_CENTERED
+ * - ::SDL_HAT_UP
+ * - ::SDL_HAT_RIGHT
+ * - ::SDL_HAT_DOWN
+ * - ::SDL_HAT_LEFT
+ * - ::SDL_HAT_RIGHTUP
+ * - ::SDL_HAT_RIGHTDOWN
+ * - ::SDL_HAT_LEFTUP
+ * - ::SDL_HAT_LEFTDOWN
+ */
+extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick * joystick,
+ int hat);
+
+/**
+ * Get the ball axis change since the last poll.
+ *
+ * \return 0, or -1 if you passed it invalid parameters.
+ *
+ * The ball indices start at index 0.
+ */
+extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick * joystick,
+ int ball, int *dx, int *dy);
+
+/**
+ * Get the current state of a button on a joystick.
+ *
+ * The button indices start at index 0.
+ */
+extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick,
+ int button);
+
+/**
+ * Close a joystick previously opened with SDL_JoystickOpen().
+ */
+extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick);
+
+/**
+ * Return the battery level of this joystick
+ */
+extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_joystick_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_keyboard.h b/src/3rdparty/SDL2/include/SDL_keyboard.h
new file mode 100644
index 0000000..8748231
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_keyboard.h
@@ -0,0 +1,217 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_keyboard.h
+ *
+ * Include file for SDL keyboard event handling
+ */
+
+#ifndef SDL_keyboard_h_
+#define SDL_keyboard_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_keycode.h"
+#include "SDL_video.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The SDL keysym structure, used in key events.
+ *
+ * \note If you are looking for translated character input, see the ::SDL_TEXTINPUT event.
+ */
+typedef struct SDL_Keysym
+{
+ SDL_Scancode scancode; /**< SDL physical key code - see ::SDL_Scancode for details */
+ SDL_Keycode sym; /**< SDL virtual key code - see ::SDL_Keycode for details */
+ Uint16 mod; /**< current key modifiers */
+ Uint32 unused;
+} SDL_Keysym;
+
+/* Function prototypes */
+
+/**
+ * \brief Get the window which currently has keyboard focus.
+ */
+extern DECLSPEC SDL_Window * SDLCALL SDL_GetKeyboardFocus(void);
+
+/**
+ * \brief Get a snapshot of the current state of the keyboard.
+ *
+ * \param numkeys if non-NULL, receives the length of the returned array.
+ *
+ * \return An array of key states. Indexes into this array are obtained by using ::SDL_Scancode values.
+ *
+ * \b Example:
+ * \code
+ * const Uint8 *state = SDL_GetKeyboardState(NULL);
+ * if ( state[SDL_SCANCODE_RETURN] ) {
+ * printf("<RETURN> is pressed.\n");
+ * }
+ * \endcode
+ */
+extern DECLSPEC const Uint8 *SDLCALL SDL_GetKeyboardState(int *numkeys);
+
+/**
+ * \brief Get the current key modifier state for the keyboard.
+ */
+extern DECLSPEC SDL_Keymod SDLCALL SDL_GetModState(void);
+
+/**
+ * \brief Set the current key modifier state for the keyboard.
+ *
+ * \note This does not change the keyboard state, only the key modifier flags.
+ */
+extern DECLSPEC void SDLCALL SDL_SetModState(SDL_Keymod modstate);
+
+/**
+ * \brief Get the key code corresponding to the given scancode according
+ * to the current keyboard layout.
+ *
+ * See ::SDL_Keycode for details.
+ *
+ * \sa SDL_GetKeyName()
+ */
+extern DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromScancode(SDL_Scancode scancode);
+
+/**
+ * \brief Get the scancode corresponding to the given key code according to the
+ * current keyboard layout.
+ *
+ * See ::SDL_Scancode for details.
+ *
+ * \sa SDL_GetScancodeName()
+ */
+extern DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromKey(SDL_Keycode key);
+
+/**
+ * \brief Get a human-readable name for a scancode.
+ *
+ * \return A pointer to the name for the scancode.
+ * If the scancode doesn't have a name, this function returns
+ * an empty string ("").
+ *
+ * \sa SDL_Scancode
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_Scancode scancode);
+
+/**
+ * \brief Get a scancode from a human-readable name
+ *
+ * \return scancode, or SDL_SCANCODE_UNKNOWN if the name wasn't recognized
+ *
+ * \sa SDL_Scancode
+ */
+extern DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromName(const char *name);
+
+/**
+ * \brief Get a human-readable name for a key.
+ *
+ * \return A pointer to a UTF-8 string that stays valid at least until the next
+ * call to this function. If you need it around any longer, you must
+ * copy it. If the key doesn't have a name, this function returns an
+ * empty string ("").
+ *
+ * \sa SDL_Keycode
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDL_Keycode key);
+
+/**
+ * \brief Get a key code from a human-readable name
+ *
+ * \return key code, or SDLK_UNKNOWN if the name wasn't recognized
+ *
+ * \sa SDL_Keycode
+ */
+extern DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromName(const char *name);
+
+/**
+ * \brief Start accepting Unicode text input events.
+ * This function will show the on-screen keyboard if supported.
+ *
+ * \sa SDL_StopTextInput()
+ * \sa SDL_SetTextInputRect()
+ * \sa SDL_HasScreenKeyboardSupport()
+ */
+extern DECLSPEC void SDLCALL SDL_StartTextInput(void);
+
+/**
+ * \brief Return whether or not Unicode text input events are enabled.
+ *
+ * \sa SDL_StartTextInput()
+ * \sa SDL_StopTextInput()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_IsTextInputActive(void);
+
+/**
+ * \brief Stop receiving any text input events.
+ * This function will hide the on-screen keyboard if supported.
+ *
+ * \sa SDL_StartTextInput()
+ * \sa SDL_HasScreenKeyboardSupport()
+ */
+extern DECLSPEC void SDLCALL SDL_StopTextInput(void);
+
+/**
+ * \brief Set the rectangle used to type Unicode text inputs.
+ * This is used as a hint for IME and on-screen keyboard placement.
+ *
+ * \sa SDL_StartTextInput()
+ */
+extern DECLSPEC void SDLCALL SDL_SetTextInputRect(SDL_Rect *rect);
+
+/**
+ * \brief Returns whether the platform has some screen keyboard support.
+ *
+ * \return SDL_TRUE if some keyboard support is available else SDL_FALSE.
+ *
+ * \note Not all screen keyboard functions are supported on all platforms.
+ *
+ * \sa SDL_IsScreenKeyboardShown()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasScreenKeyboardSupport(void);
+
+/**
+ * \brief Returns whether the screen keyboard is shown for given window.
+ *
+ * \param window The window for which screen keyboard should be queried.
+ *
+ * \return SDL_TRUE if screen keyboard is shown else SDL_FALSE.
+ *
+ * \sa SDL_HasScreenKeyboardSupport()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_IsScreenKeyboardShown(SDL_Window *window);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_keyboard_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_keycode.h b/src/3rdparty/SDL2/include/SDL_keycode.h
new file mode 100644
index 0000000..d7d5b1d
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_keycode.h
@@ -0,0 +1,349 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_keycode.h
+ *
+ * Defines constants which identify keyboard keys and modifiers.
+ */
+
+#ifndef SDL_keycode_h_
+#define SDL_keycode_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_scancode.h"
+
+/**
+ * \brief The SDL virtual key representation.
+ *
+ * Values of this type are used to represent keyboard keys using the current
+ * layout of the keyboard. These values include Unicode values representing
+ * the unmodified character that would be generated by pressing the key, or
+ * an SDLK_* constant for those keys that do not generate characters.
+ *
+ * A special exception is the number keys at the top of the keyboard which
+ * always map to SDLK_0...SDLK_9, regardless of layout.
+ */
+typedef Sint32 SDL_Keycode;
+
+#define SDLK_SCANCODE_MASK (1<<30)
+#define SDL_SCANCODE_TO_KEYCODE(X) (X | SDLK_SCANCODE_MASK)
+
+enum
+{
+ SDLK_UNKNOWN = 0,
+
+ SDLK_RETURN = '\r',
+ SDLK_ESCAPE = '\033',
+ SDLK_BACKSPACE = '\b',
+ SDLK_TAB = '\t',
+ SDLK_SPACE = ' ',
+ SDLK_EXCLAIM = '!',
+ SDLK_QUOTEDBL = '"',
+ SDLK_HASH = '#',
+ SDLK_PERCENT = '%',
+ SDLK_DOLLAR = '$',
+ SDLK_AMPERSAND = '&',
+ SDLK_QUOTE = '\'',
+ SDLK_LEFTPAREN = '(',
+ SDLK_RIGHTPAREN = ')',
+ SDLK_ASTERISK = '*',
+ SDLK_PLUS = '+',
+ SDLK_COMMA = ',',
+ SDLK_MINUS = '-',
+ SDLK_PERIOD = '.',
+ SDLK_SLASH = '/',
+ SDLK_0 = '0',
+ SDLK_1 = '1',
+ SDLK_2 = '2',
+ SDLK_3 = '3',
+ SDLK_4 = '4',
+ SDLK_5 = '5',
+ SDLK_6 = '6',
+ SDLK_7 = '7',
+ SDLK_8 = '8',
+ SDLK_9 = '9',
+ SDLK_COLON = ':',
+ SDLK_SEMICOLON = ';',
+ SDLK_LESS = '<',
+ SDLK_EQUALS = '=',
+ SDLK_GREATER = '>',
+ SDLK_QUESTION = '?',
+ SDLK_AT = '@',
+ /*
+ Skip uppercase letters
+ */
+ SDLK_LEFTBRACKET = '[',
+ SDLK_BACKSLASH = '\\',
+ SDLK_RIGHTBRACKET = ']',
+ SDLK_CARET = '^',
+ SDLK_UNDERSCORE = '_',
+ SDLK_BACKQUOTE = '`',
+ SDLK_a = 'a',
+ SDLK_b = 'b',
+ SDLK_c = 'c',
+ SDLK_d = 'd',
+ SDLK_e = 'e',
+ SDLK_f = 'f',
+ SDLK_g = 'g',
+ SDLK_h = 'h',
+ SDLK_i = 'i',
+ SDLK_j = 'j',
+ SDLK_k = 'k',
+ SDLK_l = 'l',
+ SDLK_m = 'm',
+ SDLK_n = 'n',
+ SDLK_o = 'o',
+ SDLK_p = 'p',
+ SDLK_q = 'q',
+ SDLK_r = 'r',
+ SDLK_s = 's',
+ SDLK_t = 't',
+ SDLK_u = 'u',
+ SDLK_v = 'v',
+ SDLK_w = 'w',
+ SDLK_x = 'x',
+ SDLK_y = 'y',
+ SDLK_z = 'z',
+
+ SDLK_CAPSLOCK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CAPSLOCK),
+
+ SDLK_F1 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F1),
+ SDLK_F2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F2),
+ SDLK_F3 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F3),
+ SDLK_F4 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F4),
+ SDLK_F5 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F5),
+ SDLK_F6 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F6),
+ SDLK_F7 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F7),
+ SDLK_F8 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F8),
+ SDLK_F9 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F9),
+ SDLK_F10 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F10),
+ SDLK_F11 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F11),
+ SDLK_F12 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F12),
+
+ SDLK_PRINTSCREEN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PRINTSCREEN),
+ SDLK_SCROLLLOCK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SCROLLLOCK),
+ SDLK_PAUSE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAUSE),
+ SDLK_INSERT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INSERT),
+ SDLK_HOME = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HOME),
+ SDLK_PAGEUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEUP),
+ SDLK_DELETE = '\177',
+ SDLK_END = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_END),
+ SDLK_PAGEDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEDOWN),
+ SDLK_RIGHT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RIGHT),
+ SDLK_LEFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LEFT),
+ SDLK_DOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DOWN),
+ SDLK_UP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_UP),
+
+ SDLK_NUMLOCKCLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_NUMLOCKCLEAR),
+ SDLK_KP_DIVIDE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DIVIDE),
+ SDLK_KP_MULTIPLY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MULTIPLY),
+ SDLK_KP_MINUS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MINUS),
+ SDLK_KP_PLUS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PLUS),
+ SDLK_KP_ENTER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_ENTER),
+ SDLK_KP_1 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_1),
+ SDLK_KP_2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_2),
+ SDLK_KP_3 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_3),
+ SDLK_KP_4 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_4),
+ SDLK_KP_5 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_5),
+ SDLK_KP_6 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_6),
+ SDLK_KP_7 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_7),
+ SDLK_KP_8 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_8),
+ SDLK_KP_9 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_9),
+ SDLK_KP_0 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_0),
+ SDLK_KP_PERIOD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PERIOD),
+
+ SDLK_APPLICATION = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_APPLICATION),
+ SDLK_POWER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_POWER),
+ SDLK_KP_EQUALS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EQUALS),
+ SDLK_F13 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F13),
+ SDLK_F14 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F14),
+ SDLK_F15 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F15),
+ SDLK_F16 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F16),
+ SDLK_F17 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F17),
+ SDLK_F18 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F18),
+ SDLK_F19 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F19),
+ SDLK_F20 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F20),
+ SDLK_F21 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F21),
+ SDLK_F22 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F22),
+ SDLK_F23 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F23),
+ SDLK_F24 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F24),
+ SDLK_EXECUTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EXECUTE),
+ SDLK_HELP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HELP),
+ SDLK_MENU = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MENU),
+ SDLK_SELECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SELECT),
+ SDLK_STOP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_STOP),
+ SDLK_AGAIN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AGAIN),
+ SDLK_UNDO = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_UNDO),
+ SDLK_CUT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CUT),
+ SDLK_COPY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_COPY),
+ SDLK_PASTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PASTE),
+ SDLK_FIND = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_FIND),
+ SDLK_MUTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MUTE),
+ SDLK_VOLUMEUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_VOLUMEUP),
+ SDLK_VOLUMEDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_VOLUMEDOWN),
+ SDLK_KP_COMMA = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_COMMA),
+ SDLK_KP_EQUALSAS400 =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EQUALSAS400),
+
+ SDLK_ALTERASE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_ALTERASE),
+ SDLK_SYSREQ = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SYSREQ),
+ SDLK_CANCEL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CANCEL),
+ SDLK_CLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CLEAR),
+ SDLK_PRIOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PRIOR),
+ SDLK_RETURN2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RETURN2),
+ SDLK_SEPARATOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SEPARATOR),
+ SDLK_OUT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_OUT),
+ SDLK_OPER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_OPER),
+ SDLK_CLEARAGAIN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CLEARAGAIN),
+ SDLK_CRSEL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CRSEL),
+ SDLK_EXSEL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EXSEL),
+
+ SDLK_KP_00 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_00),
+ SDLK_KP_000 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_000),
+ SDLK_THOUSANDSSEPARATOR =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_THOUSANDSSEPARATOR),
+ SDLK_DECIMALSEPARATOR =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DECIMALSEPARATOR),
+ SDLK_CURRENCYUNIT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CURRENCYUNIT),
+ SDLK_CURRENCYSUBUNIT =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CURRENCYSUBUNIT),
+ SDLK_KP_LEFTPAREN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LEFTPAREN),
+ SDLK_KP_RIGHTPAREN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_RIGHTPAREN),
+ SDLK_KP_LEFTBRACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LEFTBRACE),
+ SDLK_KP_RIGHTBRACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_RIGHTBRACE),
+ SDLK_KP_TAB = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_TAB),
+ SDLK_KP_BACKSPACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_BACKSPACE),
+ SDLK_KP_A = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_A),
+ SDLK_KP_B = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_B),
+ SDLK_KP_C = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_C),
+ SDLK_KP_D = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_D),
+ SDLK_KP_E = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_E),
+ SDLK_KP_F = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_F),
+ SDLK_KP_XOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_XOR),
+ SDLK_KP_POWER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_POWER),
+ SDLK_KP_PERCENT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PERCENT),
+ SDLK_KP_LESS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LESS),
+ SDLK_KP_GREATER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_GREATER),
+ SDLK_KP_AMPERSAND = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_AMPERSAND),
+ SDLK_KP_DBLAMPERSAND =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DBLAMPERSAND),
+ SDLK_KP_VERTICALBAR =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_VERTICALBAR),
+ SDLK_KP_DBLVERTICALBAR =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DBLVERTICALBAR),
+ SDLK_KP_COLON = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_COLON),
+ SDLK_KP_HASH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_HASH),
+ SDLK_KP_SPACE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_SPACE),
+ SDLK_KP_AT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_AT),
+ SDLK_KP_EXCLAM = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EXCLAM),
+ SDLK_KP_MEMSTORE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMSTORE),
+ SDLK_KP_MEMRECALL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMRECALL),
+ SDLK_KP_MEMCLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMCLEAR),
+ SDLK_KP_MEMADD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMADD),
+ SDLK_KP_MEMSUBTRACT =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMSUBTRACT),
+ SDLK_KP_MEMMULTIPLY =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMMULTIPLY),
+ SDLK_KP_MEMDIVIDE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMDIVIDE),
+ SDLK_KP_PLUSMINUS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PLUSMINUS),
+ SDLK_KP_CLEAR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_CLEAR),
+ SDLK_KP_CLEARENTRY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_CLEARENTRY),
+ SDLK_KP_BINARY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_BINARY),
+ SDLK_KP_OCTAL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_OCTAL),
+ SDLK_KP_DECIMAL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DECIMAL),
+ SDLK_KP_HEXADECIMAL =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_HEXADECIMAL),
+
+ SDLK_LCTRL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LCTRL),
+ SDLK_LSHIFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LSHIFT),
+ SDLK_LALT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LALT),
+ SDLK_LGUI = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_LGUI),
+ SDLK_RCTRL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RCTRL),
+ SDLK_RSHIFT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RSHIFT),
+ SDLK_RALT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RALT),
+ SDLK_RGUI = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RGUI),
+
+ SDLK_MODE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MODE),
+
+ SDLK_AUDIONEXT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIONEXT),
+ SDLK_AUDIOPREV = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOPREV),
+ SDLK_AUDIOSTOP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOSTOP),
+ SDLK_AUDIOPLAY = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOPLAY),
+ SDLK_AUDIOMUTE = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOMUTE),
+ SDLK_MEDIASELECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MEDIASELECT),
+ SDLK_WWW = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_WWW),
+ SDLK_MAIL = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MAIL),
+ SDLK_CALCULATOR = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CALCULATOR),
+ SDLK_COMPUTER = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_COMPUTER),
+ SDLK_AC_SEARCH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_SEARCH),
+ SDLK_AC_HOME = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_HOME),
+ SDLK_AC_BACK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_BACK),
+ SDLK_AC_FORWARD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_FORWARD),
+ SDLK_AC_STOP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_STOP),
+ SDLK_AC_REFRESH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_REFRESH),
+ SDLK_AC_BOOKMARKS = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AC_BOOKMARKS),
+
+ SDLK_BRIGHTNESSDOWN =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_BRIGHTNESSDOWN),
+ SDLK_BRIGHTNESSUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_BRIGHTNESSUP),
+ SDLK_DISPLAYSWITCH = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DISPLAYSWITCH),
+ SDLK_KBDILLUMTOGGLE =
+ SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMTOGGLE),
+ SDLK_KBDILLUMDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMDOWN),
+ SDLK_KBDILLUMUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KBDILLUMUP),
+ SDLK_EJECT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_EJECT),
+ SDLK_SLEEP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SLEEP),
+ SDLK_APP1 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_APP1),
+ SDLK_APP2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_APP2),
+
+ SDLK_AUDIOREWIND = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOREWIND),
+ SDLK_AUDIOFASTFORWARD = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_AUDIOFASTFORWARD)
+};
+
+/**
+ * \brief Enumeration of valid key mods (possibly OR'd together).
+ */
+typedef enum
+{
+ KMOD_NONE = 0x0000,
+ KMOD_LSHIFT = 0x0001,
+ KMOD_RSHIFT = 0x0002,
+ KMOD_LCTRL = 0x0040,
+ KMOD_RCTRL = 0x0080,
+ KMOD_LALT = 0x0100,
+ KMOD_RALT = 0x0200,
+ KMOD_LGUI = 0x0400,
+ KMOD_RGUI = 0x0800,
+ KMOD_NUM = 0x1000,
+ KMOD_CAPS = 0x2000,
+ KMOD_MODE = 0x4000,
+ KMOD_RESERVED = 0x8000
+} SDL_Keymod;
+
+#define KMOD_CTRL (KMOD_LCTRL|KMOD_RCTRL)
+#define KMOD_SHIFT (KMOD_LSHIFT|KMOD_RSHIFT)
+#define KMOD_ALT (KMOD_LALT|KMOD_RALT)
+#define KMOD_GUI (KMOD_LGUI|KMOD_RGUI)
+
+#endif /* SDL_keycode_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_loadso.h b/src/3rdparty/SDL2/include/SDL_loadso.h
new file mode 100644
index 0000000..da56fb4
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_loadso.h
@@ -0,0 +1,81 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_loadso.h
+ *
+ * System dependent library loading routines
+ *
+ * Some things to keep in mind:
+ * \li These functions only work on C function names. Other languages may
+ * have name mangling and intrinsic language support that varies from
+ * compiler to compiler.
+ * \li Make sure you declare your function pointers with the same calling
+ * convention as the actual library function. Your code will crash
+ * mysteriously if you do not do this.
+ * \li Avoid namespace collisions. If you load a symbol from the library,
+ * it is not defined whether or not it goes into the global symbol
+ * namespace for the application. If it does and it conflicts with
+ * symbols in your code or other shared libraries, you will not get
+ * the results you expect. :)
+ */
+
+#ifndef SDL_loadso_h_
+#define SDL_loadso_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This function dynamically loads a shared object and returns a pointer
+ * to the object handle (or NULL if there was an error).
+ * The 'sofile' parameter is a system dependent name of the object file.
+ */
+extern DECLSPEC void *SDLCALL SDL_LoadObject(const char *sofile);
+
+/**
+ * Given an object handle, this function looks up the address of the
+ * named function in the shared object and returns it. This address
+ * is no longer valid after calling SDL_UnloadObject().
+ */
+extern DECLSPEC void *SDLCALL SDL_LoadFunction(void *handle,
+ const char *name);
+
+/**
+ * Unload a shared object from memory.
+ */
+extern DECLSPEC void SDLCALL SDL_UnloadObject(void *handle);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_loadso_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_log.h b/src/3rdparty/SDL2/include/SDL_log.h
new file mode 100644
index 0000000..e12b658
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_log.h
@@ -0,0 +1,211 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_log.h
+ *
+ * Simple log messages with categories and priorities.
+ *
+ * By default logs are quiet, but if you're debugging SDL you might want:
+ *
+ * SDL_LogSetAllPriority(SDL_LOG_PRIORITY_WARN);
+ *
+ * Here's where the messages go on different platforms:
+ * Windows: debug output stream
+ * Android: log output
+ * Others: standard error output (stderr)
+ */
+
+#ifndef SDL_log_h_
+#define SDL_log_h_
+
+#include "SDL_stdinc.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * \brief The maximum size of a log message
+ *
+ * Messages longer than the maximum size will be truncated
+ */
+#define SDL_MAX_LOG_MESSAGE 4096
+
+/**
+ * \brief The predefined log categories
+ *
+ * By default the application category is enabled at the INFO level,
+ * the assert category is enabled at the WARN level, test is enabled
+ * at the VERBOSE level and all other categories are enabled at the
+ * CRITICAL level.
+ */
+enum
+{
+ SDL_LOG_CATEGORY_APPLICATION,
+ SDL_LOG_CATEGORY_ERROR,
+ SDL_LOG_CATEGORY_ASSERT,
+ SDL_LOG_CATEGORY_SYSTEM,
+ SDL_LOG_CATEGORY_AUDIO,
+ SDL_LOG_CATEGORY_VIDEO,
+ SDL_LOG_CATEGORY_RENDER,
+ SDL_LOG_CATEGORY_INPUT,
+ SDL_LOG_CATEGORY_TEST,
+
+ /* Reserved for future SDL library use */
+ SDL_LOG_CATEGORY_RESERVED1,
+ SDL_LOG_CATEGORY_RESERVED2,
+ SDL_LOG_CATEGORY_RESERVED3,
+ SDL_LOG_CATEGORY_RESERVED4,
+ SDL_LOG_CATEGORY_RESERVED5,
+ SDL_LOG_CATEGORY_RESERVED6,
+ SDL_LOG_CATEGORY_RESERVED7,
+ SDL_LOG_CATEGORY_RESERVED8,
+ SDL_LOG_CATEGORY_RESERVED9,
+ SDL_LOG_CATEGORY_RESERVED10,
+
+ /* Beyond this point is reserved for application use, e.g.
+ enum {
+ MYAPP_CATEGORY_AWESOME1 = SDL_LOG_CATEGORY_CUSTOM,
+ MYAPP_CATEGORY_AWESOME2,
+ MYAPP_CATEGORY_AWESOME3,
+ ...
+ };
+ */
+ SDL_LOG_CATEGORY_CUSTOM
+};
+
+/**
+ * \brief The predefined log priorities
+ */
+typedef enum
+{
+ SDL_LOG_PRIORITY_VERBOSE = 1,
+ SDL_LOG_PRIORITY_DEBUG,
+ SDL_LOG_PRIORITY_INFO,
+ SDL_LOG_PRIORITY_WARN,
+ SDL_LOG_PRIORITY_ERROR,
+ SDL_LOG_PRIORITY_CRITICAL,
+ SDL_NUM_LOG_PRIORITIES
+} SDL_LogPriority;
+
+
+/**
+ * \brief Set the priority of all log categories
+ */
+extern DECLSPEC void SDLCALL SDL_LogSetAllPriority(SDL_LogPriority priority);
+
+/**
+ * \brief Set the priority of a particular log category
+ */
+extern DECLSPEC void SDLCALL SDL_LogSetPriority(int category,
+ SDL_LogPriority priority);
+
+/**
+ * \brief Get the priority of a particular log category
+ */
+extern DECLSPEC SDL_LogPriority SDLCALL SDL_LogGetPriority(int category);
+
+/**
+ * \brief Reset all priorities to default.
+ *
+ * \note This is called in SDL_Quit().
+ */
+extern DECLSPEC void SDLCALL SDL_LogResetPriorities(void);
+
+/**
+ * \brief Log a message with SDL_LOG_CATEGORY_APPLICATION and SDL_LOG_PRIORITY_INFO
+ */
+extern DECLSPEC void SDLCALL SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
+
+/**
+ * \brief Log a message with SDL_LOG_PRIORITY_VERBOSE
+ */
+extern DECLSPEC void SDLCALL SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
+
+/**
+ * \brief Log a message with SDL_LOG_PRIORITY_DEBUG
+ */
+extern DECLSPEC void SDLCALL SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
+
+/**
+ * \brief Log a message with SDL_LOG_PRIORITY_INFO
+ */
+extern DECLSPEC void SDLCALL SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
+
+/**
+ * \brief Log a message with SDL_LOG_PRIORITY_WARN
+ */
+extern DECLSPEC void SDLCALL SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
+
+/**
+ * \brief Log a message with SDL_LOG_PRIORITY_ERROR
+ */
+extern DECLSPEC void SDLCALL SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
+
+/**
+ * \brief Log a message with SDL_LOG_PRIORITY_CRITICAL
+ */
+extern DECLSPEC void SDLCALL SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
+
+/**
+ * \brief Log a message with the specified category and priority.
+ */
+extern DECLSPEC void SDLCALL SDL_LogMessage(int category,
+ SDL_LogPriority priority,
+ SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(3);
+
+/**
+ * \brief Log a message with the specified category and priority.
+ */
+extern DECLSPEC void SDLCALL SDL_LogMessageV(int category,
+ SDL_LogPriority priority,
+ const char *fmt, va_list ap);
+
+/**
+ * \brief The prototype for the log output function
+ */
+typedef void (SDLCALL *SDL_LogOutputFunction)(void *userdata, int category, SDL_LogPriority priority, const char *message);
+
+/**
+ * \brief Get the current log output function.
+ */
+extern DECLSPEC void SDLCALL SDL_LogGetOutputFunction(SDL_LogOutputFunction *callback, void **userdata);
+
+/**
+ * \brief This function allows you to replace the default log output
+ * function with one of your own.
+ */
+extern DECLSPEC void SDLCALL SDL_LogSetOutputFunction(SDL_LogOutputFunction callback, void *userdata);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_log_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_main.h b/src/3rdparty/SDL2/include/SDL_main.h
new file mode 100644
index 0000000..9855821
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_main.h
@@ -0,0 +1,168 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_main_h_
+#define SDL_main_h_
+
+#include "SDL_stdinc.h"
+
+/**
+ * \file SDL_main.h
+ *
+ * Redefine main() on some platforms so that it is called by SDL.
+ */
+
+#ifndef SDL_MAIN_HANDLED
+#if defined(__WIN32__)
+/* On Windows SDL provides WinMain(), which parses the command line and passes
+ the arguments to your main function.
+
+ If you provide your own WinMain(), you may define SDL_MAIN_HANDLED
+ */
+#define SDL_MAIN_AVAILABLE
+
+#elif defined(__WINRT__)
+/* On WinRT, SDL provides a main function that initializes CoreApplication,
+ creating an instance of IFrameworkView in the process.
+
+ Please note that #include'ing SDL_main.h is not enough to get a main()
+ function working. In non-XAML apps, the file,
+ src/main/winrt/SDL_WinRT_main_NonXAML.cpp, or a copy of it, must be compiled
+ into the app itself. In XAML apps, the function, SDL_WinRTRunApp must be
+ called, with a pointer to the Direct3D-hosted XAML control passed in.
+*/
+#define SDL_MAIN_NEEDED
+
+#elif defined(__IPHONEOS__)
+/* On iOS SDL provides a main function that creates an application delegate
+ and starts the iOS application run loop.
+
+ See src/video/uikit/SDL_uikitappdelegate.m for more details.
+ */
+#define SDL_MAIN_NEEDED
+
+#elif defined(__ANDROID__)
+/* On Android SDL provides a Java class in SDLActivity.java that is the
+ main activity entry point.
+
+ See docs/README-android.md for more details on extending that class.
+ */
+#define SDL_MAIN_NEEDED
+
+/* We need to export SDL_main so it can be launched from Java */
+#define SDLMAIN_DECLSPEC DECLSPEC
+
+#elif defined(__NACL__)
+/* On NACL we use ppapi_simple to set up the application helper code,
+ then wait for the first PSE_INSTANCE_DIDCHANGEVIEW event before
+ starting the user main function.
+ All user code is run in a separate thread by ppapi_simple, thus
+ allowing for blocking io to take place via nacl_io
+*/
+#define SDL_MAIN_NEEDED
+
+#endif
+#endif /* SDL_MAIN_HANDLED */
+
+#ifdef __cplusplus
+#define C_LINKAGE "C"
+#else
+#define C_LINKAGE
+#endif /* __cplusplus */
+
+#ifndef SDLMAIN_DECLSPEC
+#define SDLMAIN_DECLSPEC
+#endif
+
+/**
+ * \file SDL_main.h
+ *
+ * The application's main() function must be called with C linkage,
+ * and should be declared like this:
+ * \code
+ * #ifdef __cplusplus
+ * extern "C"
+ * #endif
+ * int main(int argc, char *argv[])
+ * {
+ * }
+ * \endcode
+ */
+
+#if defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE)
+#define main SDL_main
+#endif
+
+/**
+ * The prototype for the application's main() function
+ */
+extern C_LINKAGE SDLMAIN_DECLSPEC int SDL_main(int argc, char *argv[]);
+
+
+#include "begin_code.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This is called by the real SDL main function to let the rest of the
+ * library know that initialization was done properly.
+ *
+ * Calling this yourself without knowing what you're doing can cause
+ * crashes and hard to diagnose problems with your application.
+ */
+extern DECLSPEC void SDLCALL SDL_SetMainReady(void);
+
+#ifdef __WIN32__
+
+/**
+ * This can be called to set the application class at startup
+ */
+extern DECLSPEC int SDLCALL SDL_RegisterApp(char *name, Uint32 style,
+ void *hInst);
+extern DECLSPEC void SDLCALL SDL_UnregisterApp(void);
+
+#endif /* __WIN32__ */
+
+
+#ifdef __WINRT__
+
+/**
+ * \brief Initializes and launches an SDL/WinRT application.
+ *
+ * \param mainFunction The SDL app's C-style main().
+ * \param reserved Reserved for future use; should be NULL
+ * \return 0 on success, -1 on failure. On failure, use SDL_GetError to retrieve more
+ * information on the failure.
+ */
+extern DECLSPEC int SDLCALL SDL_WinRTRunApp(int (*mainFunction)(int, char **), void * reserved);
+
+#endif /* __WINRT__ */
+
+
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_main_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_messagebox.h b/src/3rdparty/SDL2/include/SDL_messagebox.h
new file mode 100644
index 0000000..b7be59d
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_messagebox.h
@@ -0,0 +1,144 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_messagebox_h_
+#define SDL_messagebox_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_video.h" /* For SDL_Window */
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief SDL_MessageBox flags. If supported will display warning icon, etc.
+ */
+typedef enum
+{
+ SDL_MESSAGEBOX_ERROR = 0x00000010, /**< error dialog */
+ SDL_MESSAGEBOX_WARNING = 0x00000020, /**< warning dialog */
+ SDL_MESSAGEBOX_INFORMATION = 0x00000040 /**< informational dialog */
+} SDL_MessageBoxFlags;
+
+/**
+ * \brief Flags for SDL_MessageBoxButtonData.
+ */
+typedef enum
+{
+ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT = 0x00000001, /**< Marks the default button when return is hit */
+ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT = 0x00000002 /**< Marks the default button when escape is hit */
+} SDL_MessageBoxButtonFlags;
+
+/**
+ * \brief Individual button data.
+ */
+typedef struct
+{
+ Uint32 flags; /**< ::SDL_MessageBoxButtonFlags */
+ int buttonid; /**< User defined button id (value returned via SDL_ShowMessageBox) */
+ const char * text; /**< The UTF-8 button text */
+} SDL_MessageBoxButtonData;
+
+/**
+ * \brief RGB value used in a message box color scheme
+ */
+typedef struct
+{
+ Uint8 r, g, b;
+} SDL_MessageBoxColor;
+
+typedef enum
+{
+ SDL_MESSAGEBOX_COLOR_BACKGROUND,
+ SDL_MESSAGEBOX_COLOR_TEXT,
+ SDL_MESSAGEBOX_COLOR_BUTTON_BORDER,
+ SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND,
+ SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED,
+ SDL_MESSAGEBOX_COLOR_MAX
+} SDL_MessageBoxColorType;
+
+/**
+ * \brief A set of colors to use for message box dialogs
+ */
+typedef struct
+{
+ SDL_MessageBoxColor colors[SDL_MESSAGEBOX_COLOR_MAX];
+} SDL_MessageBoxColorScheme;
+
+/**
+ * \brief MessageBox structure containing title, text, window, etc.
+ */
+typedef struct
+{
+ Uint32 flags; /**< ::SDL_MessageBoxFlags */
+ SDL_Window *window; /**< Parent window, can be NULL */
+ const char *title; /**< UTF-8 title */
+ const char *message; /**< UTF-8 message text */
+
+ int numbuttons;
+ const SDL_MessageBoxButtonData *buttons;
+
+ const SDL_MessageBoxColorScheme *colorScheme; /**< ::SDL_MessageBoxColorScheme, can be NULL to use system settings */
+} SDL_MessageBoxData;
+
+/**
+ * \brief Create a modal message box.
+ *
+ * \param messageboxdata The SDL_MessageBoxData structure with title, text, etc.
+ * \param buttonid The pointer to which user id of hit button should be copied.
+ *
+ * \return -1 on error, otherwise 0 and buttonid contains user id of button
+ * hit or -1 if dialog was closed.
+ *
+ * \note This function should be called on the thread that created the parent
+ * window, or on the main thread if the messagebox has no parent. It will
+ * block execution of that thread until the user clicks a button or
+ * closes the messagebox.
+ */
+extern DECLSPEC int SDLCALL SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
+
+/**
+ * \brief Create a simple modal message box
+ *
+ * \param flags ::SDL_MessageBoxFlags
+ * \param title UTF-8 title text
+ * \param message UTF-8 message text
+ * \param window The parent window, or NULL for no parent
+ *
+ * \return 0 on success, -1 on error
+ *
+ * \sa SDL_ShowMessageBox
+ */
+extern DECLSPEC int SDLCALL SDL_ShowSimpleMessageBox(Uint32 flags, const char *title, const char *message, SDL_Window *window);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_messagebox_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_mouse.h b/src/3rdparty/SDL2/include/SDL_mouse.h
new file mode 100644
index 0000000..d3c9f61
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_mouse.h
@@ -0,0 +1,302 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_mouse.h
+ *
+ * Include file for SDL mouse event handling.
+ */
+
+#ifndef SDL_mouse_h_
+#define SDL_mouse_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_video.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct SDL_Cursor SDL_Cursor; /**< Implementation dependent */
+
+/**
+ * \brief Cursor types for SDL_CreateSystemCursor().
+ */
+typedef enum
+{
+ SDL_SYSTEM_CURSOR_ARROW, /**< Arrow */
+ SDL_SYSTEM_CURSOR_IBEAM, /**< I-beam */
+ SDL_SYSTEM_CURSOR_WAIT, /**< Wait */
+ SDL_SYSTEM_CURSOR_CROSSHAIR, /**< Crosshair */
+ SDL_SYSTEM_CURSOR_WAITARROW, /**< Small wait cursor (or Wait if not available) */
+ SDL_SYSTEM_CURSOR_SIZENWSE, /**< Double arrow pointing northwest and southeast */
+ SDL_SYSTEM_CURSOR_SIZENESW, /**< Double arrow pointing northeast and southwest */
+ SDL_SYSTEM_CURSOR_SIZEWE, /**< Double arrow pointing west and east */
+ SDL_SYSTEM_CURSOR_SIZENS, /**< Double arrow pointing north and south */
+ SDL_SYSTEM_CURSOR_SIZEALL, /**< Four pointed arrow pointing north, south, east, and west */
+ SDL_SYSTEM_CURSOR_NO, /**< Slashed circle or crossbones */
+ SDL_SYSTEM_CURSOR_HAND, /**< Hand */
+ SDL_NUM_SYSTEM_CURSORS
+} SDL_SystemCursor;
+
+/**
+ * \brief Scroll direction types for the Scroll event
+ */
+typedef enum
+{
+ SDL_MOUSEWHEEL_NORMAL, /**< The scroll direction is normal */
+ SDL_MOUSEWHEEL_FLIPPED /**< The scroll direction is flipped / natural */
+} SDL_MouseWheelDirection;
+
+/* Function prototypes */
+
+/**
+ * \brief Get the window which currently has mouse focus.
+ */
+extern DECLSPEC SDL_Window * SDLCALL SDL_GetMouseFocus(void);
+
+/**
+ * \brief Retrieve the current state of the mouse.
+ *
+ * The current button state is returned as a button bitmask, which can
+ * be tested using the SDL_BUTTON(X) macros, and x and y are set to the
+ * mouse cursor position relative to the focus window for the currently
+ * selected mouse. You can pass NULL for either x or y.
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_GetMouseState(int *x, int *y);
+
+/**
+ * \brief Get the current state of the mouse, in relation to the desktop
+ *
+ * This works just like SDL_GetMouseState(), but the coordinates will be
+ * reported relative to the top-left of the desktop. This can be useful if
+ * you need to track the mouse outside of a specific window and
+ * SDL_CaptureMouse() doesn't fit your needs. For example, it could be
+ * useful if you need to track the mouse while dragging a window, where
+ * coordinates relative to a window might not be in sync at all times.
+ *
+ * \note SDL_GetMouseState() returns the mouse position as SDL understands
+ * it from the last pump of the event queue. This function, however,
+ * queries the OS for the current mouse position, and as such, might
+ * be a slightly less efficient function. Unless you know what you're
+ * doing and have a good reason to use this function, you probably want
+ * SDL_GetMouseState() instead.
+ *
+ * \param x Returns the current X coord, relative to the desktop. Can be NULL.
+ * \param y Returns the current Y coord, relative to the desktop. Can be NULL.
+ * \return The current button state as a bitmask, which can be tested using the SDL_BUTTON(X) macros.
+ *
+ * \sa SDL_GetMouseState
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_GetGlobalMouseState(int *x, int *y);
+
+/**
+ * \brief Retrieve the relative state of the mouse.
+ *
+ * The current button state is returned as a button bitmask, which can
+ * be tested using the SDL_BUTTON(X) macros, and x and y are set to the
+ * mouse deltas since the last call to SDL_GetRelativeMouseState().
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_GetRelativeMouseState(int *x, int *y);
+
+/**
+ * \brief Moves the mouse to the given position within the window.
+ *
+ * \param window The window to move the mouse into, or NULL for the current mouse focus
+ * \param x The x coordinate within the window
+ * \param y The y coordinate within the window
+ *
+ * \note This function generates a mouse motion event
+ */
+extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window * window,
+ int x, int y);
+
+/**
+ * \brief Moves the mouse to the given position in global screen space.
+ *
+ * \param x The x coordinate
+ * \param y The y coordinate
+ * \return 0 on success, -1 on error (usually: unsupported by a platform).
+ *
+ * \note This function generates a mouse motion event
+ */
+extern DECLSPEC int SDLCALL SDL_WarpMouseGlobal(int x, int y);
+
+/**
+ * \brief Set relative mouse mode.
+ *
+ * \param enabled Whether or not to enable relative mode
+ *
+ * \return 0 on success, or -1 if relative mode is not supported.
+ *
+ * While the mouse is in relative mode, the cursor is hidden, and the
+ * driver will try to report continuous motion in the current window.
+ * Only relative motion events will be delivered, the mouse position
+ * will not change.
+ *
+ * \note This function will flush any pending mouse motion.
+ *
+ * \sa SDL_GetRelativeMouseMode()
+ */
+extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled);
+
+/**
+ * \brief Capture the mouse, to track input outside an SDL window.
+ *
+ * \param enabled Whether or not to enable capturing
+ *
+ * Capturing enables your app to obtain mouse events globally, instead of
+ * just within your window. Not all video targets support this function.
+ * When capturing is enabled, the current window will get all mouse events,
+ * but unlike relative mode, no change is made to the cursor and it is
+ * not restrained to your window.
+ *
+ * This function may also deny mouse input to other windows--both those in
+ * your application and others on the system--so you should use this
+ * function sparingly, and in small bursts. For example, you might want to
+ * track the mouse while the user is dragging something, until the user
+ * releases a mouse button. It is not recommended that you capture the mouse
+ * for long periods of time, such as the entire time your app is running.
+ *
+ * While captured, mouse events still report coordinates relative to the
+ * current (foreground) window, but those coordinates may be outside the
+ * bounds of the window (including negative values). Capturing is only
+ * allowed for the foreground window. If the window loses focus while
+ * capturing, the capture will be disabled automatically.
+ *
+ * While capturing is enabled, the current window will have the
+ * SDL_WINDOW_MOUSE_CAPTURE flag set.
+ *
+ * \return 0 on success, or -1 if not supported.
+ */
+extern DECLSPEC int SDLCALL SDL_CaptureMouse(SDL_bool enabled);
+
+/**
+ * \brief Query whether relative mouse mode is enabled.
+ *
+ * \sa SDL_SetRelativeMouseMode()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(void);
+
+/**
+ * \brief Create a cursor, using the specified bitmap data and
+ * mask (in MSB format).
+ *
+ * The cursor width must be a multiple of 8 bits.
+ *
+ * The cursor is created in black and white according to the following:
+ * <table>
+ * <tr><td> data </td><td> mask </td><td> resulting pixel on screen </td></tr>
+ * <tr><td> 0 </td><td> 1 </td><td> White </td></tr>
+ * <tr><td> 1 </td><td> 1 </td><td> Black </td></tr>
+ * <tr><td> 0 </td><td> 0 </td><td> Transparent </td></tr>
+ * <tr><td> 1 </td><td> 0 </td><td> Inverted color if possible, black
+ * if not. </td></tr>
+ * </table>
+ *
+ * \sa SDL_FreeCursor()
+ */
+extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateCursor(const Uint8 * data,
+ const Uint8 * mask,
+ int w, int h, int hot_x,
+ int hot_y);
+
+/**
+ * \brief Create a color cursor.
+ *
+ * \sa SDL_FreeCursor()
+ */
+extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateColorCursor(SDL_Surface *surface,
+ int hot_x,
+ int hot_y);
+
+/**
+ * \brief Create a system cursor.
+ *
+ * \sa SDL_FreeCursor()
+ */
+extern DECLSPEC SDL_Cursor *SDLCALL SDL_CreateSystemCursor(SDL_SystemCursor id);
+
+/**
+ * \brief Set the active cursor.
+ */
+extern DECLSPEC void SDLCALL SDL_SetCursor(SDL_Cursor * cursor);
+
+/**
+ * \brief Return the active cursor.
+ */
+extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetCursor(void);
+
+/**
+ * \brief Return the default cursor.
+ */
+extern DECLSPEC SDL_Cursor *SDLCALL SDL_GetDefaultCursor(void);
+
+/**
+ * \brief Frees a cursor created with SDL_CreateCursor() or similar functions.
+ *
+ * \sa SDL_CreateCursor()
+ * \sa SDL_CreateColorCursor()
+ * \sa SDL_CreateSystemCursor()
+ */
+extern DECLSPEC void SDLCALL SDL_FreeCursor(SDL_Cursor * cursor);
+
+/**
+ * \brief Toggle whether or not the cursor is shown.
+ *
+ * \param toggle 1 to show the cursor, 0 to hide it, -1 to query the current
+ * state.
+ *
+ * \return 1 if the cursor is shown, or 0 if the cursor is hidden.
+ */
+extern DECLSPEC int SDLCALL SDL_ShowCursor(int toggle);
+
+/**
+ * Used as a mask when testing buttons in buttonstate.
+ * - Button 1: Left mouse button
+ * - Button 2: Middle mouse button
+ * - Button 3: Right mouse button
+ */
+#define SDL_BUTTON(X) (1 << ((X)-1))
+#define SDL_BUTTON_LEFT 1
+#define SDL_BUTTON_MIDDLE 2
+#define SDL_BUTTON_RIGHT 3
+#define SDL_BUTTON_X1 4
+#define SDL_BUTTON_X2 5
+#define SDL_BUTTON_LMASK SDL_BUTTON(SDL_BUTTON_LEFT)
+#define SDL_BUTTON_MMASK SDL_BUTTON(SDL_BUTTON_MIDDLE)
+#define SDL_BUTTON_RMASK SDL_BUTTON(SDL_BUTTON_RIGHT)
+#define SDL_BUTTON_X1MASK SDL_BUTTON(SDL_BUTTON_X1)
+#define SDL_BUTTON_X2MASK SDL_BUTTON(SDL_BUTTON_X2)
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_mouse_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_mutex.h b/src/3rdparty/SDL2/include/SDL_mutex.h
new file mode 100644
index 0000000..ba4247c
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_mutex.h
@@ -0,0 +1,251 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_mutex_h_
+#define SDL_mutex_h_
+
+/**
+ * \file SDL_mutex.h
+ *
+ * Functions to provide thread synchronization primitives.
+ */
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Synchronization functions which can time out return this value
+ * if they time out.
+ */
+#define SDL_MUTEX_TIMEDOUT 1
+
+/**
+ * This is the timeout value which corresponds to never time out.
+ */
+#define SDL_MUTEX_MAXWAIT (~(Uint32)0)
+
+
+/**
+ * \name Mutex functions
+ */
+/* @{ */
+
+/* The SDL mutex structure, defined in SDL_sysmutex.c */
+struct SDL_mutex;
+typedef struct SDL_mutex SDL_mutex;
+
+/**
+ * Create a mutex, initialized unlocked.
+ */
+extern DECLSPEC SDL_mutex *SDLCALL SDL_CreateMutex(void);
+
+/**
+ * Lock the mutex.
+ *
+ * \return 0, or -1 on error.
+ */
+#define SDL_mutexP(m) SDL_LockMutex(m)
+extern DECLSPEC int SDLCALL SDL_LockMutex(SDL_mutex * mutex);
+
+/**
+ * Try to lock the mutex
+ *
+ * \return 0, SDL_MUTEX_TIMEDOUT, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_TryLockMutex(SDL_mutex * mutex);
+
+/**
+ * Unlock the mutex.
+ *
+ * \return 0, or -1 on error.
+ *
+ * \warning It is an error to unlock a mutex that has not been locked by
+ * the current thread, and doing so results in undefined behavior.
+ */
+#define SDL_mutexV(m) SDL_UnlockMutex(m)
+extern DECLSPEC int SDLCALL SDL_UnlockMutex(SDL_mutex * mutex);
+
+/**
+ * Destroy a mutex.
+ */
+extern DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_mutex * mutex);
+
+/* @} *//* Mutex functions */
+
+
+/**
+ * \name Semaphore functions
+ */
+/* @{ */
+
+/* The SDL semaphore structure, defined in SDL_syssem.c */
+struct SDL_semaphore;
+typedef struct SDL_semaphore SDL_sem;
+
+/**
+ * Create a semaphore, initialized with value, returns NULL on failure.
+ */
+extern DECLSPEC SDL_sem *SDLCALL SDL_CreateSemaphore(Uint32 initial_value);
+
+/**
+ * Destroy a semaphore.
+ */
+extern DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem * sem);
+
+/**
+ * This function suspends the calling thread until the semaphore pointed
+ * to by \c sem has a positive count. It then atomically decreases the
+ * semaphore count.
+ */
+extern DECLSPEC int SDLCALL SDL_SemWait(SDL_sem * sem);
+
+/**
+ * Non-blocking variant of SDL_SemWait().
+ *
+ * \return 0 if the wait succeeds, ::SDL_MUTEX_TIMEDOUT if the wait would
+ * block, and -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem * sem);
+
+/**
+ * Variant of SDL_SemWait() with a timeout in milliseconds.
+ *
+ * \return 0 if the wait succeeds, ::SDL_MUTEX_TIMEDOUT if the wait does not
+ * succeed in the allotted time, and -1 on error.
+ *
+ * \warning On some platforms this function is implemented by looping with a
+ * delay of 1 ms, and so should be avoided if possible.
+ */
+extern DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem * sem, Uint32 ms);
+
+/**
+ * Atomically increases the semaphore's count (not blocking).
+ *
+ * \return 0, or -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_SemPost(SDL_sem * sem);
+
+/**
+ * Returns the current count of the semaphore.
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_SemValue(SDL_sem * sem);
+
+/* @} *//* Semaphore functions */
+
+
+/**
+ * \name Condition variable functions
+ */
+/* @{ */
+
+/* The SDL condition variable structure, defined in SDL_syscond.c */
+struct SDL_cond;
+typedef struct SDL_cond SDL_cond;
+
+/**
+ * Create a condition variable.
+ *
+ * Typical use of condition variables:
+ *
+ * Thread A:
+ * SDL_LockMutex(lock);
+ * while ( ! condition ) {
+ * SDL_CondWait(cond, lock);
+ * }
+ * SDL_UnlockMutex(lock);
+ *
+ * Thread B:
+ * SDL_LockMutex(lock);
+ * ...
+ * condition = true;
+ * ...
+ * SDL_CondSignal(cond);
+ * SDL_UnlockMutex(lock);
+ *
+ * There is some discussion whether to signal the condition variable
+ * with the mutex locked or not. There is some potential performance
+ * benefit to unlocking first on some platforms, but there are some
+ * potential race conditions depending on how your code is structured.
+ *
+ * In general it's safer to signal the condition variable while the
+ * mutex is locked.
+ */
+extern DECLSPEC SDL_cond *SDLCALL SDL_CreateCond(void);
+
+/**
+ * Destroy a condition variable.
+ */
+extern DECLSPEC void SDLCALL SDL_DestroyCond(SDL_cond * cond);
+
+/**
+ * Restart one of the threads that are waiting on the condition variable.
+ *
+ * \return 0 or -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond * cond);
+
+/**
+ * Restart all threads that are waiting on the condition variable.
+ *
+ * \return 0 or -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond * cond);
+
+/**
+ * Wait on the condition variable, unlocking the provided mutex.
+ *
+ * \warning The mutex must be locked before entering this function!
+ *
+ * The mutex is re-locked once the condition variable is signaled.
+ *
+ * \return 0 when it is signaled, or -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex);
+
+/**
+ * Waits for at most \c ms milliseconds, and returns 0 if the condition
+ * variable is signaled, ::SDL_MUTEX_TIMEDOUT if the condition is not
+ * signaled in the allotted time, and -1 on error.
+ *
+ * \warning On some platforms this function is implemented by looping with a
+ * delay of 1 ms, and so should be avoided if possible.
+ */
+extern DECLSPEC int SDLCALL SDL_CondWaitTimeout(SDL_cond * cond,
+ SDL_mutex * mutex, Uint32 ms);
+
+/* @} *//* Condition variable functions */
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_mutex_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_name.h b/src/3rdparty/SDL2/include/SDL_name.h
new file mode 100644
index 0000000..ecd863f
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_name.h
@@ -0,0 +1,33 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDLname_h_
+#define SDLname_h_
+
+#if defined(__STDC__) || defined(__cplusplus)
+#define NeedFunctionPrototypes 1
+#endif
+
+#define SDL_NAME(X) SDL_##X
+
+#endif /* SDLname_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_opengl.h b/src/3rdparty/SDL2/include/SDL_opengl.h
new file mode 100644
index 0000000..253d9c9
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_opengl.h
@@ -0,0 +1,2183 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_opengl.h
+ *
+ * This is a simple file to encapsulate the OpenGL API headers.
+ */
+
+/**
+ * \def NO_SDL_GLEXT
+ *
+ * Define this if you have your own version of glext.h and want to disable the
+ * version included in SDL_opengl.h.
+ */
+
+#ifndef SDL_opengl_h_
+#define SDL_opengl_h_
+
+#include "SDL_config.h"
+
+#ifndef __IPHONEOS__ /* No OpenGL on iOS. */
+
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#ifndef __gl_h_
+#define __gl_h_
+
+#if defined(USE_MGL_NAMESPACE)
+#include "gl_mangle.h"
+#endif
+
+
+/**********************************************************************
+ * Begin system-specific stuff.
+ */
+
+#if defined(_WIN32) && !defined(__WIN32__) && !defined(__CYGWIN__)
+#define __WIN32__
+#endif
+
+#if defined(__WIN32__) && !defined(__CYGWIN__)
+# if (defined(_MSC_VER) || defined(__MINGW32__)) && defined(BUILD_GL32) /* tag specify we're building mesa as a DLL */
+# define GLAPI __declspec(dllexport)
+# elif (defined(_MSC_VER) || defined(__MINGW32__)) && defined(_DLL) /* tag specifying we're building for DLL runtime support */
+# define GLAPI __declspec(dllimport)
+# else /* for use with static link lib build of Win32 edition only */
+# define GLAPI extern
+# endif /* _STATIC_MESA support */
+# if defined(__MINGW32__) && defined(GL_NO_STDCALL) || defined(UNDER_CE) /* The generated DLLs by MingW with STDCALL are not compatible with the ones done by Microsoft's compilers */
+# define GLAPIENTRY
+# else
+# define GLAPIENTRY __stdcall
+# endif
+#elif defined(__CYGWIN__) && defined(USE_OPENGL32) /* use native windows opengl32 */
+# define GLAPI extern
+# define GLAPIENTRY __stdcall
+#elif defined(__OS2__) || defined(__EMX__) /* native os/2 opengl */
+# define GLAPI extern
+# define GLAPIENTRY _System
+# define APIENTRY _System
+# if defined(__GNUC__) && !defined(_System)
+# define _System
+# endif
+#elif (defined(__GNUC__) && __GNUC__ >= 4) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
+# define GLAPI __attribute__((visibility("default")))
+# define GLAPIENTRY
+#endif /* WIN32 && !CYGWIN */
+
+/*
+ * WINDOWS: Include windows.h here to define APIENTRY.
+ * It is also useful when applications include this file by
+ * including only glut.h, since glut.h depends on windows.h.
+ * Applications needing to include windows.h with parms other
+ * than "WIN32_LEAN_AND_MEAN" may include windows.h before
+ * glut.h or gl.h.
+ */
+#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__)
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN 1
+#endif
+#ifndef NOMINMAX /* don't define min() and max(). */
+#define NOMINMAX
+#endif
+#include <windows.h>
+#endif
+
+#ifndef GLAPI
+#define GLAPI extern
+#endif
+
+#ifndef GLAPIENTRY
+#define GLAPIENTRY
+#endif
+
+#ifndef APIENTRY
+#define APIENTRY GLAPIENTRY
+#endif
+
+/* "P" suffix to be used for a pointer to a function */
+#ifndef APIENTRYP
+#define APIENTRYP APIENTRY *
+#endif
+
+#ifndef GLAPIENTRYP
+#define GLAPIENTRYP GLAPIENTRY *
+#endif
+
+#if defined(PRAGMA_EXPORT_SUPPORTED)
+#pragma export on
+#endif
+
+/*
+ * End system-specific stuff.
+ **********************************************************************/
+
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+#define GL_VERSION_1_1 1
+#define GL_VERSION_1_2 1
+#define GL_VERSION_1_3 1
+#define GL_ARB_imaging 1
+
+
+/*
+ * Datatypes
+ */
+typedef unsigned int GLenum;
+typedef unsigned char GLboolean;
+typedef unsigned int GLbitfield;
+typedef void GLvoid;
+typedef signed char GLbyte; /* 1-byte signed */
+typedef short GLshort; /* 2-byte signed */
+typedef int GLint; /* 4-byte signed */
+typedef unsigned char GLubyte; /* 1-byte unsigned */
+typedef unsigned short GLushort; /* 2-byte unsigned */
+typedef unsigned int GLuint; /* 4-byte unsigned */
+typedef int GLsizei; /* 4-byte signed */
+typedef float GLfloat; /* single precision float */
+typedef float GLclampf; /* single precision float in [0,1] */
+typedef double GLdouble; /* double precision float */
+typedef double GLclampd; /* double precision float in [0,1] */
+
+
+
+/*
+ * Constants
+ */
+
+/* Boolean values */
+#define GL_FALSE 0
+#define GL_TRUE 1
+
+/* Data types */
+#define GL_BYTE 0x1400
+#define GL_UNSIGNED_BYTE 0x1401
+#define GL_SHORT 0x1402
+#define GL_UNSIGNED_SHORT 0x1403
+#define GL_INT 0x1404
+#define GL_UNSIGNED_INT 0x1405
+#define GL_FLOAT 0x1406
+#define GL_2_BYTES 0x1407
+#define GL_3_BYTES 0x1408
+#define GL_4_BYTES 0x1409
+#define GL_DOUBLE 0x140A
+
+/* Primitives */
+#define GL_POINTS 0x0000
+#define GL_LINES 0x0001
+#define GL_LINE_LOOP 0x0002
+#define GL_LINE_STRIP 0x0003
+#define GL_TRIANGLES 0x0004
+#define GL_TRIANGLE_STRIP 0x0005
+#define GL_TRIANGLE_FAN 0x0006
+#define GL_QUADS 0x0007
+#define GL_QUAD_STRIP 0x0008
+#define GL_POLYGON 0x0009
+
+/* Vertex Arrays */
+#define GL_VERTEX_ARRAY 0x8074
+#define GL_NORMAL_ARRAY 0x8075
+#define GL_COLOR_ARRAY 0x8076
+#define GL_INDEX_ARRAY 0x8077
+#define GL_TEXTURE_COORD_ARRAY 0x8078
+#define GL_EDGE_FLAG_ARRAY 0x8079
+#define GL_VERTEX_ARRAY_SIZE 0x807A
+#define GL_VERTEX_ARRAY_TYPE 0x807B
+#define GL_VERTEX_ARRAY_STRIDE 0x807C
+#define GL_NORMAL_ARRAY_TYPE 0x807E
+#define GL_NORMAL_ARRAY_STRIDE 0x807F
+#define GL_COLOR_ARRAY_SIZE 0x8081
+#define GL_COLOR_ARRAY_TYPE 0x8082
+#define GL_COLOR_ARRAY_STRIDE 0x8083
+#define GL_INDEX_ARRAY_TYPE 0x8085
+#define GL_INDEX_ARRAY_STRIDE 0x8086
+#define GL_TEXTURE_COORD_ARRAY_SIZE 0x8088
+#define GL_TEXTURE_COORD_ARRAY_TYPE 0x8089
+#define GL_TEXTURE_COORD_ARRAY_STRIDE 0x808A
+#define GL_EDGE_FLAG_ARRAY_STRIDE 0x808C
+#define GL_VERTEX_ARRAY_POINTER 0x808E
+#define GL_NORMAL_ARRAY_POINTER 0x808F
+#define GL_COLOR_ARRAY_POINTER 0x8090
+#define GL_INDEX_ARRAY_POINTER 0x8091
+#define GL_TEXTURE_COORD_ARRAY_POINTER 0x8092
+#define GL_EDGE_FLAG_ARRAY_POINTER 0x8093
+#define GL_V2F 0x2A20
+#define GL_V3F 0x2A21
+#define GL_C4UB_V2F 0x2A22
+#define GL_C4UB_V3F 0x2A23
+#define GL_C3F_V3F 0x2A24
+#define GL_N3F_V3F 0x2A25
+#define GL_C4F_N3F_V3F 0x2A26
+#define GL_T2F_V3F 0x2A27
+#define GL_T4F_V4F 0x2A28
+#define GL_T2F_C4UB_V3F 0x2A29
+#define GL_T2F_C3F_V3F 0x2A2A
+#define GL_T2F_N3F_V3F 0x2A2B
+#define GL_T2F_C4F_N3F_V3F 0x2A2C
+#define GL_T4F_C4F_N3F_V4F 0x2A2D
+
+/* Matrix Mode */
+#define GL_MATRIX_MODE 0x0BA0
+#define GL_MODELVIEW 0x1700
+#define GL_PROJECTION 0x1701
+#define GL_TEXTURE 0x1702
+
+/* Points */
+#define GL_POINT_SMOOTH 0x0B10
+#define GL_POINT_SIZE 0x0B11
+#define GL_POINT_SIZE_GRANULARITY 0x0B13
+#define GL_POINT_SIZE_RANGE 0x0B12
+
+/* Lines */
+#define GL_LINE_SMOOTH 0x0B20
+#define GL_LINE_STIPPLE 0x0B24
+#define GL_LINE_STIPPLE_PATTERN 0x0B25
+#define GL_LINE_STIPPLE_REPEAT 0x0B26
+#define GL_LINE_WIDTH 0x0B21
+#define GL_LINE_WIDTH_GRANULARITY 0x0B23
+#define GL_LINE_WIDTH_RANGE 0x0B22
+
+/* Polygons */
+#define GL_POINT 0x1B00
+#define GL_LINE 0x1B01
+#define GL_FILL 0x1B02
+#define GL_CW 0x0900
+#define GL_CCW 0x0901
+#define GL_FRONT 0x0404
+#define GL_BACK 0x0405
+#define GL_POLYGON_MODE 0x0B40
+#define GL_POLYGON_SMOOTH 0x0B41
+#define GL_POLYGON_STIPPLE 0x0B42
+#define GL_EDGE_FLAG 0x0B43
+#define GL_CULL_FACE 0x0B44
+#define GL_CULL_FACE_MODE 0x0B45
+#define GL_FRONT_FACE 0x0B46
+#define GL_POLYGON_OFFSET_FACTOR 0x8038
+#define GL_POLYGON_OFFSET_UNITS 0x2A00
+#define GL_POLYGON_OFFSET_POINT 0x2A01
+#define GL_POLYGON_OFFSET_LINE 0x2A02
+#define GL_POLYGON_OFFSET_FILL 0x8037
+
+/* Display Lists */
+#define GL_COMPILE 0x1300
+#define GL_COMPILE_AND_EXECUTE 0x1301
+#define GL_LIST_BASE 0x0B32
+#define GL_LIST_INDEX 0x0B33
+#define GL_LIST_MODE 0x0B30
+
+/* Depth buffer */
+#define GL_NEVER 0x0200
+#define GL_LESS 0x0201
+#define GL_EQUAL 0x0202
+#define GL_LEQUAL 0x0203
+#define GL_GREATER 0x0204
+#define GL_NOTEQUAL 0x0205
+#define GL_GEQUAL 0x0206
+#define GL_ALWAYS 0x0207
+#define GL_DEPTH_TEST 0x0B71
+#define GL_DEPTH_BITS 0x0D56
+#define GL_DEPTH_CLEAR_VALUE 0x0B73
+#define GL_DEPTH_FUNC 0x0B74
+#define GL_DEPTH_RANGE 0x0B70
+#define GL_DEPTH_WRITEMASK 0x0B72
+#define GL_DEPTH_COMPONENT 0x1902
+
+/* Lighting */
+#define GL_LIGHTING 0x0B50
+#define GL_LIGHT0 0x4000
+#define GL_LIGHT1 0x4001
+#define GL_LIGHT2 0x4002
+#define GL_LIGHT3 0x4003
+#define GL_LIGHT4 0x4004
+#define GL_LIGHT5 0x4005
+#define GL_LIGHT6 0x4006
+#define GL_LIGHT7 0x4007
+#define GL_SPOT_EXPONENT 0x1205
+#define GL_SPOT_CUTOFF 0x1206
+#define GL_CONSTANT_ATTENUATION 0x1207
+#define GL_LINEAR_ATTENUATION 0x1208
+#define GL_QUADRATIC_ATTENUATION 0x1209
+#define GL_AMBIENT 0x1200
+#define GL_DIFFUSE 0x1201
+#define GL_SPECULAR 0x1202
+#define GL_SHININESS 0x1601
+#define GL_EMISSION 0x1600
+#define GL_POSITION 0x1203
+#define GL_SPOT_DIRECTION 0x1204
+#define GL_AMBIENT_AND_DIFFUSE 0x1602
+#define GL_COLOR_INDEXES 0x1603
+#define GL_LIGHT_MODEL_TWO_SIDE 0x0B52
+#define GL_LIGHT_MODEL_LOCAL_VIEWER 0x0B51
+#define GL_LIGHT_MODEL_AMBIENT 0x0B53
+#define GL_FRONT_AND_BACK 0x0408
+#define GL_SHADE_MODEL 0x0B54
+#define GL_FLAT 0x1D00
+#define GL_SMOOTH 0x1D01
+#define GL_COLOR_MATERIAL 0x0B57
+#define GL_COLOR_MATERIAL_FACE 0x0B55
+#define GL_COLOR_MATERIAL_PARAMETER 0x0B56
+#define GL_NORMALIZE 0x0BA1
+
+/* User clipping planes */
+#define GL_CLIP_PLANE0 0x3000
+#define GL_CLIP_PLANE1 0x3001
+#define GL_CLIP_PLANE2 0x3002
+#define GL_CLIP_PLANE3 0x3003
+#define GL_CLIP_PLANE4 0x3004
+#define GL_CLIP_PLANE5 0x3005
+
+/* Accumulation buffer */
+#define GL_ACCUM_RED_BITS 0x0D58
+#define GL_ACCUM_GREEN_BITS 0x0D59
+#define GL_ACCUM_BLUE_BITS 0x0D5A
+#define GL_ACCUM_ALPHA_BITS 0x0D5B
+#define GL_ACCUM_CLEAR_VALUE 0x0B80
+#define GL_ACCUM 0x0100
+#define GL_ADD 0x0104
+#define GL_LOAD 0x0101
+#define GL_MULT 0x0103
+#define GL_RETURN 0x0102
+
+/* Alpha testing */
+#define GL_ALPHA_TEST 0x0BC0
+#define GL_ALPHA_TEST_REF 0x0BC2
+#define GL_ALPHA_TEST_FUNC 0x0BC1
+
+/* Blending */
+#define GL_BLEND 0x0BE2
+#define GL_BLEND_SRC 0x0BE1
+#define GL_BLEND_DST 0x0BE0
+#define GL_ZERO 0
+#define GL_ONE 1
+#define GL_SRC_COLOR 0x0300
+#define GL_ONE_MINUS_SRC_COLOR 0x0301
+#define GL_SRC_ALPHA 0x0302
+#define GL_ONE_MINUS_SRC_ALPHA 0x0303
+#define GL_DST_ALPHA 0x0304
+#define GL_ONE_MINUS_DST_ALPHA 0x0305
+#define GL_DST_COLOR 0x0306
+#define GL_ONE_MINUS_DST_COLOR 0x0307
+#define GL_SRC_ALPHA_SATURATE 0x0308
+
+/* Render Mode */
+#define GL_FEEDBACK 0x1C01
+#define GL_RENDER 0x1C00
+#define GL_SELECT 0x1C02
+
+/* Feedback */
+#define GL_2D 0x0600
+#define GL_3D 0x0601
+#define GL_3D_COLOR 0x0602
+#define GL_3D_COLOR_TEXTURE 0x0603
+#define GL_4D_COLOR_TEXTURE 0x0604
+#define GL_POINT_TOKEN 0x0701
+#define GL_LINE_TOKEN 0x0702
+#define GL_LINE_RESET_TOKEN 0x0707
+#define GL_POLYGON_TOKEN 0x0703
+#define GL_BITMAP_TOKEN 0x0704
+#define GL_DRAW_PIXEL_TOKEN 0x0705
+#define GL_COPY_PIXEL_TOKEN 0x0706
+#define GL_PASS_THROUGH_TOKEN 0x0700
+#define GL_FEEDBACK_BUFFER_POINTER 0x0DF0
+#define GL_FEEDBACK_BUFFER_SIZE 0x0DF1
+#define GL_FEEDBACK_BUFFER_TYPE 0x0DF2
+
+/* Selection */
+#define GL_SELECTION_BUFFER_POINTER 0x0DF3
+#define GL_SELECTION_BUFFER_SIZE 0x0DF4
+
+/* Fog */
+#define GL_FOG 0x0B60
+#define GL_FOG_MODE 0x0B65
+#define GL_FOG_DENSITY 0x0B62
+#define GL_FOG_COLOR 0x0B66
+#define GL_FOG_INDEX 0x0B61
+#define GL_FOG_START 0x0B63
+#define GL_FOG_END 0x0B64
+#define GL_LINEAR 0x2601
+#define GL_EXP 0x0800
+#define GL_EXP2 0x0801
+
+/* Logic Ops */
+#define GL_LOGIC_OP 0x0BF1
+#define GL_INDEX_LOGIC_OP 0x0BF1
+#define GL_COLOR_LOGIC_OP 0x0BF2
+#define GL_LOGIC_OP_MODE 0x0BF0
+#define GL_CLEAR 0x1500
+#define GL_SET 0x150F
+#define GL_COPY 0x1503
+#define GL_COPY_INVERTED 0x150C
+#define GL_NOOP 0x1505
+#define GL_INVERT 0x150A
+#define GL_AND 0x1501
+#define GL_NAND 0x150E
+#define GL_OR 0x1507
+#define GL_NOR 0x1508
+#define GL_XOR 0x1506
+#define GL_EQUIV 0x1509
+#define GL_AND_REVERSE 0x1502
+#define GL_AND_INVERTED 0x1504
+#define GL_OR_REVERSE 0x150B
+#define GL_OR_INVERTED 0x150D
+
+/* Stencil */
+#define GL_STENCIL_BITS 0x0D57
+#define GL_STENCIL_TEST 0x0B90
+#define GL_STENCIL_CLEAR_VALUE 0x0B91
+#define GL_STENCIL_FUNC 0x0B92
+#define GL_STENCIL_VALUE_MASK 0x0B93
+#define GL_STENCIL_FAIL 0x0B94
+#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95
+#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96
+#define GL_STENCIL_REF 0x0B97
+#define GL_STENCIL_WRITEMASK 0x0B98
+#define GL_STENCIL_INDEX 0x1901
+#define GL_KEEP 0x1E00
+#define GL_REPLACE 0x1E01
+#define GL_INCR 0x1E02
+#define GL_DECR 0x1E03
+
+/* Buffers, Pixel Drawing/Reading */
+#define GL_NONE 0
+#define GL_LEFT 0x0406
+#define GL_RIGHT 0x0407
+/*GL_FRONT 0x0404 */
+/*GL_BACK 0x0405 */
+/*GL_FRONT_AND_BACK 0x0408 */
+#define GL_FRONT_LEFT 0x0400
+#define GL_FRONT_RIGHT 0x0401
+#define GL_BACK_LEFT 0x0402
+#define GL_BACK_RIGHT 0x0403
+#define GL_AUX0 0x0409
+#define GL_AUX1 0x040A
+#define GL_AUX2 0x040B
+#define GL_AUX3 0x040C
+#define GL_COLOR_INDEX 0x1900
+#define GL_RED 0x1903
+#define GL_GREEN 0x1904
+#define GL_BLUE 0x1905
+#define GL_ALPHA 0x1906
+#define GL_LUMINANCE 0x1909
+#define GL_LUMINANCE_ALPHA 0x190A
+#define GL_ALPHA_BITS 0x0D55
+#define GL_RED_BITS 0x0D52
+#define GL_GREEN_BITS 0x0D53
+#define GL_BLUE_BITS 0x0D54
+#define GL_INDEX_BITS 0x0D51
+#define GL_SUBPIXEL_BITS 0x0D50
+#define GL_AUX_BUFFERS 0x0C00
+#define GL_READ_BUFFER 0x0C02
+#define GL_DRAW_BUFFER 0x0C01
+#define GL_DOUBLEBUFFER 0x0C32
+#define GL_STEREO 0x0C33
+#define GL_BITMAP 0x1A00
+#define GL_COLOR 0x1800
+#define GL_DEPTH 0x1801
+#define GL_STENCIL 0x1802
+#define GL_DITHER 0x0BD0
+#define GL_RGB 0x1907
+#define GL_RGBA 0x1908
+
+/* Implementation limits */
+#define GL_MAX_LIST_NESTING 0x0B31
+#define GL_MAX_EVAL_ORDER 0x0D30
+#define GL_MAX_LIGHTS 0x0D31
+#define GL_MAX_CLIP_PLANES 0x0D32
+#define GL_MAX_TEXTURE_SIZE 0x0D33
+#define GL_MAX_PIXEL_MAP_TABLE 0x0D34
+#define GL_MAX_ATTRIB_STACK_DEPTH 0x0D35
+#define GL_MAX_MODELVIEW_STACK_DEPTH 0x0D36
+#define GL_MAX_NAME_STACK_DEPTH 0x0D37
+#define GL_MAX_PROJECTION_STACK_DEPTH 0x0D38
+#define GL_MAX_TEXTURE_STACK_DEPTH 0x0D39
+#define GL_MAX_VIEWPORT_DIMS 0x0D3A
+#define GL_MAX_CLIENT_ATTRIB_STACK_DEPTH 0x0D3B
+
+/* Gets */
+#define GL_ATTRIB_STACK_DEPTH 0x0BB0
+#define GL_CLIENT_ATTRIB_STACK_DEPTH 0x0BB1
+#define GL_COLOR_CLEAR_VALUE 0x0C22
+#define GL_COLOR_WRITEMASK 0x0C23
+#define GL_CURRENT_INDEX 0x0B01
+#define GL_CURRENT_COLOR 0x0B00
+#define GL_CURRENT_NORMAL 0x0B02
+#define GL_CURRENT_RASTER_COLOR 0x0B04
+#define GL_CURRENT_RASTER_DISTANCE 0x0B09
+#define GL_CURRENT_RASTER_INDEX 0x0B05
+#define GL_CURRENT_RASTER_POSITION 0x0B07
+#define GL_CURRENT_RASTER_TEXTURE_COORDS 0x0B06
+#define GL_CURRENT_RASTER_POSITION_VALID 0x0B08
+#define GL_CURRENT_TEXTURE_COORDS 0x0B03
+#define GL_INDEX_CLEAR_VALUE 0x0C20
+#define GL_INDEX_MODE 0x0C30
+#define GL_INDEX_WRITEMASK 0x0C21
+#define GL_MODELVIEW_MATRIX 0x0BA6
+#define GL_MODELVIEW_STACK_DEPTH 0x0BA3
+#define GL_NAME_STACK_DEPTH 0x0D70
+#define GL_PROJECTION_MATRIX 0x0BA7
+#define GL_PROJECTION_STACK_DEPTH 0x0BA4
+#define GL_RENDER_MODE 0x0C40
+#define GL_RGBA_MODE 0x0C31
+#define GL_TEXTURE_MATRIX 0x0BA8
+#define GL_TEXTURE_STACK_DEPTH 0x0BA5
+#define GL_VIEWPORT 0x0BA2
+
+/* Evaluators */
+#define GL_AUTO_NORMAL 0x0D80
+#define GL_MAP1_COLOR_4 0x0D90
+#define GL_MAP1_INDEX 0x0D91
+#define GL_MAP1_NORMAL 0x0D92
+#define GL_MAP1_TEXTURE_COORD_1 0x0D93
+#define GL_MAP1_TEXTURE_COORD_2 0x0D94
+#define GL_MAP1_TEXTURE_COORD_3 0x0D95
+#define GL_MAP1_TEXTURE_COORD_4 0x0D96
+#define GL_MAP1_VERTEX_3 0x0D97
+#define GL_MAP1_VERTEX_4 0x0D98
+#define GL_MAP2_COLOR_4 0x0DB0
+#define GL_MAP2_INDEX 0x0DB1
+#define GL_MAP2_NORMAL 0x0DB2
+#define GL_MAP2_TEXTURE_COORD_1 0x0DB3
+#define GL_MAP2_TEXTURE_COORD_2 0x0DB4
+#define GL_MAP2_TEXTURE_COORD_3 0x0DB5
+#define GL_MAP2_TEXTURE_COORD_4 0x0DB6
+#define GL_MAP2_VERTEX_3 0x0DB7
+#define GL_MAP2_VERTEX_4 0x0DB8
+#define GL_MAP1_GRID_DOMAIN 0x0DD0
+#define GL_MAP1_GRID_SEGMENTS 0x0DD1
+#define GL_MAP2_GRID_DOMAIN 0x0DD2
+#define GL_MAP2_GRID_SEGMENTS 0x0DD3
+#define GL_COEFF 0x0A00
+#define GL_ORDER 0x0A01
+#define GL_DOMAIN 0x0A02
+
+/* Hints */
+#define GL_PERSPECTIVE_CORRECTION_HINT 0x0C50
+#define GL_POINT_SMOOTH_HINT 0x0C51
+#define GL_LINE_SMOOTH_HINT 0x0C52
+#define GL_POLYGON_SMOOTH_HINT 0x0C53
+#define GL_FOG_HINT 0x0C54
+#define GL_DONT_CARE 0x1100
+#define GL_FASTEST 0x1101
+#define GL_NICEST 0x1102
+
+/* Scissor box */
+#define GL_SCISSOR_BOX 0x0C10
+#define GL_SCISSOR_TEST 0x0C11
+
+/* Pixel Mode / Transfer */
+#define GL_MAP_COLOR 0x0D10
+#define GL_MAP_STENCIL 0x0D11
+#define GL_INDEX_SHIFT 0x0D12
+#define GL_INDEX_OFFSET 0x0D13
+#define GL_RED_SCALE 0x0D14
+#define GL_RED_BIAS 0x0D15
+#define GL_GREEN_SCALE 0x0D18
+#define GL_GREEN_BIAS 0x0D19
+#define GL_BLUE_SCALE 0x0D1A
+#define GL_BLUE_BIAS 0x0D1B
+#define GL_ALPHA_SCALE 0x0D1C
+#define GL_ALPHA_BIAS 0x0D1D
+#define GL_DEPTH_SCALE 0x0D1E
+#define GL_DEPTH_BIAS 0x0D1F
+#define GL_PIXEL_MAP_S_TO_S_SIZE 0x0CB1
+#define GL_PIXEL_MAP_I_TO_I_SIZE 0x0CB0
+#define GL_PIXEL_MAP_I_TO_R_SIZE 0x0CB2
+#define GL_PIXEL_MAP_I_TO_G_SIZE 0x0CB3
+#define GL_PIXEL_MAP_I_TO_B_SIZE 0x0CB4
+#define GL_PIXEL_MAP_I_TO_A_SIZE 0x0CB5
+#define GL_PIXEL_MAP_R_TO_R_SIZE 0x0CB6
+#define GL_PIXEL_MAP_G_TO_G_SIZE 0x0CB7
+#define GL_PIXEL_MAP_B_TO_B_SIZE 0x0CB8
+#define GL_PIXEL_MAP_A_TO_A_SIZE 0x0CB9
+#define GL_PIXEL_MAP_S_TO_S 0x0C71
+#define GL_PIXEL_MAP_I_TO_I 0x0C70
+#define GL_PIXEL_MAP_I_TO_R 0x0C72
+#define GL_PIXEL_MAP_I_TO_G 0x0C73
+#define GL_PIXEL_MAP_I_TO_B 0x0C74
+#define GL_PIXEL_MAP_I_TO_A 0x0C75
+#define GL_PIXEL_MAP_R_TO_R 0x0C76
+#define GL_PIXEL_MAP_G_TO_G 0x0C77
+#define GL_PIXEL_MAP_B_TO_B 0x0C78
+#define GL_PIXEL_MAP_A_TO_A 0x0C79
+#define GL_PACK_ALIGNMENT 0x0D05
+#define GL_PACK_LSB_FIRST 0x0D01
+#define GL_PACK_ROW_LENGTH 0x0D02
+#define GL_PACK_SKIP_PIXELS 0x0D04
+#define GL_PACK_SKIP_ROWS 0x0D03
+#define GL_PACK_SWAP_BYTES 0x0D00
+#define GL_UNPACK_ALIGNMENT 0x0CF5
+#define GL_UNPACK_LSB_FIRST 0x0CF1
+#define GL_UNPACK_ROW_LENGTH 0x0CF2
+#define GL_UNPACK_SKIP_PIXELS 0x0CF4
+#define GL_UNPACK_SKIP_ROWS 0x0CF3
+#define GL_UNPACK_SWAP_BYTES 0x0CF0
+#define GL_ZOOM_X 0x0D16
+#define GL_ZOOM_Y 0x0D17
+
+/* Texture mapping */
+#define GL_TEXTURE_ENV 0x2300
+#define GL_TEXTURE_ENV_MODE 0x2200
+#define GL_TEXTURE_1D 0x0DE0
+#define GL_TEXTURE_2D 0x0DE1
+#define GL_TEXTURE_WRAP_S 0x2802
+#define GL_TEXTURE_WRAP_T 0x2803
+#define GL_TEXTURE_MAG_FILTER 0x2800
+#define GL_TEXTURE_MIN_FILTER 0x2801
+#define GL_TEXTURE_ENV_COLOR 0x2201
+#define GL_TEXTURE_GEN_S 0x0C60
+#define GL_TEXTURE_GEN_T 0x0C61
+#define GL_TEXTURE_GEN_R 0x0C62
+#define GL_TEXTURE_GEN_Q 0x0C63
+#define GL_TEXTURE_GEN_MODE 0x2500
+#define GL_TEXTURE_BORDER_COLOR 0x1004
+#define GL_TEXTURE_WIDTH 0x1000
+#define GL_TEXTURE_HEIGHT 0x1001
+#define GL_TEXTURE_BORDER 0x1005
+#define GL_TEXTURE_COMPONENTS 0x1003
+#define GL_TEXTURE_RED_SIZE 0x805C
+#define GL_TEXTURE_GREEN_SIZE 0x805D
+#define GL_TEXTURE_BLUE_SIZE 0x805E
+#define GL_TEXTURE_ALPHA_SIZE 0x805F
+#define GL_TEXTURE_LUMINANCE_SIZE 0x8060
+#define GL_TEXTURE_INTENSITY_SIZE 0x8061
+#define GL_NEAREST_MIPMAP_NEAREST 0x2700
+#define GL_NEAREST_MIPMAP_LINEAR 0x2702
+#define GL_LINEAR_MIPMAP_NEAREST 0x2701
+#define GL_LINEAR_MIPMAP_LINEAR 0x2703
+#define GL_OBJECT_LINEAR 0x2401
+#define GL_OBJECT_PLANE 0x2501
+#define GL_EYE_LINEAR 0x2400
+#define GL_EYE_PLANE 0x2502
+#define GL_SPHERE_MAP 0x2402
+#define GL_DECAL 0x2101
+#define GL_MODULATE 0x2100
+#define GL_NEAREST 0x2600
+#define GL_REPEAT 0x2901
+#define GL_CLAMP 0x2900
+#define GL_S 0x2000
+#define GL_T 0x2001
+#define GL_R 0x2002
+#define GL_Q 0x2003
+
+/* Utility */
+#define GL_VENDOR 0x1F00
+#define GL_RENDERER 0x1F01
+#define GL_VERSION 0x1F02
+#define GL_EXTENSIONS 0x1F03
+
+/* Errors */
+#define GL_NO_ERROR 0
+#define GL_INVALID_ENUM 0x0500
+#define GL_INVALID_VALUE 0x0501
+#define GL_INVALID_OPERATION 0x0502
+#define GL_STACK_OVERFLOW 0x0503
+#define GL_STACK_UNDERFLOW 0x0504
+#define GL_OUT_OF_MEMORY 0x0505
+
+/* glPush/PopAttrib bits */
+#define GL_CURRENT_BIT 0x00000001
+#define GL_POINT_BIT 0x00000002
+#define GL_LINE_BIT 0x00000004
+#define GL_POLYGON_BIT 0x00000008
+#define GL_POLYGON_STIPPLE_BIT 0x00000010
+#define GL_PIXEL_MODE_BIT 0x00000020
+#define GL_LIGHTING_BIT 0x00000040
+#define GL_FOG_BIT 0x00000080
+#define GL_DEPTH_BUFFER_BIT 0x00000100
+#define GL_ACCUM_BUFFER_BIT 0x00000200
+#define GL_STENCIL_BUFFER_BIT 0x00000400
+#define GL_VIEWPORT_BIT 0x00000800
+#define GL_TRANSFORM_BIT 0x00001000
+#define GL_ENABLE_BIT 0x00002000
+#define GL_COLOR_BUFFER_BIT 0x00004000
+#define GL_HINT_BIT 0x00008000
+#define GL_EVAL_BIT 0x00010000
+#define GL_LIST_BIT 0x00020000
+#define GL_TEXTURE_BIT 0x00040000
+#define GL_SCISSOR_BIT 0x00080000
+#define GL_ALL_ATTRIB_BITS 0x000FFFFF
+
+
+/* OpenGL 1.1 */
+#define GL_PROXY_TEXTURE_1D 0x8063
+#define GL_PROXY_TEXTURE_2D 0x8064
+#define GL_TEXTURE_PRIORITY 0x8066
+#define GL_TEXTURE_RESIDENT 0x8067
+#define GL_TEXTURE_BINDING_1D 0x8068
+#define GL_TEXTURE_BINDING_2D 0x8069
+#define GL_TEXTURE_INTERNAL_FORMAT 0x1003
+#define GL_ALPHA4 0x803B
+#define GL_ALPHA8 0x803C
+#define GL_ALPHA12 0x803D
+#define GL_ALPHA16 0x803E
+#define GL_LUMINANCE4 0x803F
+#define GL_LUMINANCE8 0x8040
+#define GL_LUMINANCE12 0x8041
+#define GL_LUMINANCE16 0x8042
+#define GL_LUMINANCE4_ALPHA4 0x8043
+#define GL_LUMINANCE6_ALPHA2 0x8044
+#define GL_LUMINANCE8_ALPHA8 0x8045
+#define GL_LUMINANCE12_ALPHA4 0x8046
+#define GL_LUMINANCE12_ALPHA12 0x8047
+#define GL_LUMINANCE16_ALPHA16 0x8048
+#define GL_INTENSITY 0x8049
+#define GL_INTENSITY4 0x804A
+#define GL_INTENSITY8 0x804B
+#define GL_INTENSITY12 0x804C
+#define GL_INTENSITY16 0x804D
+#define GL_R3_G3_B2 0x2A10
+#define GL_RGB4 0x804F
+#define GL_RGB5 0x8050
+#define GL_RGB8 0x8051
+#define GL_RGB10 0x8052
+#define GL_RGB12 0x8053
+#define GL_RGB16 0x8054
+#define GL_RGBA2 0x8055
+#define GL_RGBA4 0x8056
+#define GL_RGB5_A1 0x8057
+#define GL_RGBA8 0x8058
+#define GL_RGB10_A2 0x8059
+#define GL_RGBA12 0x805A
+#define GL_RGBA16 0x805B
+#define GL_CLIENT_PIXEL_STORE_BIT 0x00000001
+#define GL_CLIENT_VERTEX_ARRAY_BIT 0x00000002
+#define GL_ALL_CLIENT_ATTRIB_BITS 0xFFFFFFFF
+#define GL_CLIENT_ALL_ATTRIB_BITS 0xFFFFFFFF
+
+
+
+/*
+ * Miscellaneous
+ */
+
+GLAPI void GLAPIENTRY glClearIndex( GLfloat c );
+
+GLAPI void GLAPIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha );
+
+GLAPI void GLAPIENTRY glClear( GLbitfield mask );
+
+GLAPI void GLAPIENTRY glIndexMask( GLuint mask );
+
+GLAPI void GLAPIENTRY glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha );
+
+GLAPI void GLAPIENTRY glAlphaFunc( GLenum func, GLclampf ref );
+
+GLAPI void GLAPIENTRY glBlendFunc( GLenum sfactor, GLenum dfactor );
+
+GLAPI void GLAPIENTRY glLogicOp( GLenum opcode );
+
+GLAPI void GLAPIENTRY glCullFace( GLenum mode );
+
+GLAPI void GLAPIENTRY glFrontFace( GLenum mode );
+
+GLAPI void GLAPIENTRY glPointSize( GLfloat size );
+
+GLAPI void GLAPIENTRY glLineWidth( GLfloat width );
+
+GLAPI void GLAPIENTRY glLineStipple( GLint factor, GLushort pattern );
+
+GLAPI void GLAPIENTRY glPolygonMode( GLenum face, GLenum mode );
+
+GLAPI void GLAPIENTRY glPolygonOffset( GLfloat factor, GLfloat units );
+
+GLAPI void GLAPIENTRY glPolygonStipple( const GLubyte *mask );
+
+GLAPI void GLAPIENTRY glGetPolygonStipple( GLubyte *mask );
+
+GLAPI void GLAPIENTRY glEdgeFlag( GLboolean flag );
+
+GLAPI void GLAPIENTRY glEdgeFlagv( const GLboolean *flag );
+
+GLAPI void GLAPIENTRY glScissor( GLint x, GLint y, GLsizei width, GLsizei height);
+
+GLAPI void GLAPIENTRY glClipPlane( GLenum plane, const GLdouble *equation );
+
+GLAPI void GLAPIENTRY glGetClipPlane( GLenum plane, GLdouble *equation );
+
+GLAPI void GLAPIENTRY glDrawBuffer( GLenum mode );
+
+GLAPI void GLAPIENTRY glReadBuffer( GLenum mode );
+
+GLAPI void GLAPIENTRY glEnable( GLenum cap );
+
+GLAPI void GLAPIENTRY glDisable( GLenum cap );
+
+GLAPI GLboolean GLAPIENTRY glIsEnabled( GLenum cap );
+
+
+GLAPI void GLAPIENTRY glEnableClientState( GLenum cap ); /* 1.1 */
+
+GLAPI void GLAPIENTRY glDisableClientState( GLenum cap ); /* 1.1 */
+
+
+GLAPI void GLAPIENTRY glGetBooleanv( GLenum pname, GLboolean *params );
+
+GLAPI void GLAPIENTRY glGetDoublev( GLenum pname, GLdouble *params );
+
+GLAPI void GLAPIENTRY glGetFloatv( GLenum pname, GLfloat *params );
+
+GLAPI void GLAPIENTRY glGetIntegerv( GLenum pname, GLint *params );
+
+
+GLAPI void GLAPIENTRY glPushAttrib( GLbitfield mask );
+
+GLAPI void GLAPIENTRY glPopAttrib( void );
+
+
+GLAPI void GLAPIENTRY glPushClientAttrib( GLbitfield mask ); /* 1.1 */
+
+GLAPI void GLAPIENTRY glPopClientAttrib( void ); /* 1.1 */
+
+
+GLAPI GLint GLAPIENTRY glRenderMode( GLenum mode );
+
+GLAPI GLenum GLAPIENTRY glGetError( void );
+
+GLAPI const GLubyte * GLAPIENTRY glGetString( GLenum name );
+
+GLAPI void GLAPIENTRY glFinish( void );
+
+GLAPI void GLAPIENTRY glFlush( void );
+
+GLAPI void GLAPIENTRY glHint( GLenum target, GLenum mode );
+
+
+/*
+ * Depth Buffer
+ */
+
+GLAPI void GLAPIENTRY glClearDepth( GLclampd depth );
+
+GLAPI void GLAPIENTRY glDepthFunc( GLenum func );
+
+GLAPI void GLAPIENTRY glDepthMask( GLboolean flag );
+
+GLAPI void GLAPIENTRY glDepthRange( GLclampd near_val, GLclampd far_val );
+
+
+/*
+ * Accumulation Buffer
+ */
+
+GLAPI void GLAPIENTRY glClearAccum( GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha );
+
+GLAPI void GLAPIENTRY glAccum( GLenum op, GLfloat value );
+
+
+/*
+ * Transformation
+ */
+
+GLAPI void GLAPIENTRY glMatrixMode( GLenum mode );
+
+GLAPI void GLAPIENTRY glOrtho( GLdouble left, GLdouble right,
+ GLdouble bottom, GLdouble top,
+ GLdouble near_val, GLdouble far_val );
+
+GLAPI void GLAPIENTRY glFrustum( GLdouble left, GLdouble right,
+ GLdouble bottom, GLdouble top,
+ GLdouble near_val, GLdouble far_val );
+
+GLAPI void GLAPIENTRY glViewport( GLint x, GLint y,
+ GLsizei width, GLsizei height );
+
+GLAPI void GLAPIENTRY glPushMatrix( void );
+
+GLAPI void GLAPIENTRY glPopMatrix( void );
+
+GLAPI void GLAPIENTRY glLoadIdentity( void );
+
+GLAPI void GLAPIENTRY glLoadMatrixd( const GLdouble *m );
+GLAPI void GLAPIENTRY glLoadMatrixf( const GLfloat *m );
+
+GLAPI void GLAPIENTRY glMultMatrixd( const GLdouble *m );
+GLAPI void GLAPIENTRY glMultMatrixf( const GLfloat *m );
+
+GLAPI void GLAPIENTRY glRotated( GLdouble angle,
+ GLdouble x, GLdouble y, GLdouble z );
+GLAPI void GLAPIENTRY glRotatef( GLfloat angle,
+ GLfloat x, GLfloat y, GLfloat z );
+
+GLAPI void GLAPIENTRY glScaled( GLdouble x, GLdouble y, GLdouble z );
+GLAPI void GLAPIENTRY glScalef( GLfloat x, GLfloat y, GLfloat z );
+
+GLAPI void GLAPIENTRY glTranslated( GLdouble x, GLdouble y, GLdouble z );
+GLAPI void GLAPIENTRY glTranslatef( GLfloat x, GLfloat y, GLfloat z );
+
+
+/*
+ * Display Lists
+ */
+
+GLAPI GLboolean GLAPIENTRY glIsList( GLuint list );
+
+GLAPI void GLAPIENTRY glDeleteLists( GLuint list, GLsizei range );
+
+GLAPI GLuint GLAPIENTRY glGenLists( GLsizei range );
+
+GLAPI void GLAPIENTRY glNewList( GLuint list, GLenum mode );
+
+GLAPI void GLAPIENTRY glEndList( void );
+
+GLAPI void GLAPIENTRY glCallList( GLuint list );
+
+GLAPI void GLAPIENTRY glCallLists( GLsizei n, GLenum type,
+ const GLvoid *lists );
+
+GLAPI void GLAPIENTRY glListBase( GLuint base );
+
+
+/*
+ * Drawing Functions
+ */
+
+GLAPI void GLAPIENTRY glBegin( GLenum mode );
+
+GLAPI void GLAPIENTRY glEnd( void );
+
+
+GLAPI void GLAPIENTRY glVertex2d( GLdouble x, GLdouble y );
+GLAPI void GLAPIENTRY glVertex2f( GLfloat x, GLfloat y );
+GLAPI void GLAPIENTRY glVertex2i( GLint x, GLint y );
+GLAPI void GLAPIENTRY glVertex2s( GLshort x, GLshort y );
+
+GLAPI void GLAPIENTRY glVertex3d( GLdouble x, GLdouble y, GLdouble z );
+GLAPI void GLAPIENTRY glVertex3f( GLfloat x, GLfloat y, GLfloat z );
+GLAPI void GLAPIENTRY glVertex3i( GLint x, GLint y, GLint z );
+GLAPI void GLAPIENTRY glVertex3s( GLshort x, GLshort y, GLshort z );
+
+GLAPI void GLAPIENTRY glVertex4d( GLdouble x, GLdouble y, GLdouble z, GLdouble w );
+GLAPI void GLAPIENTRY glVertex4f( GLfloat x, GLfloat y, GLfloat z, GLfloat w );
+GLAPI void GLAPIENTRY glVertex4i( GLint x, GLint y, GLint z, GLint w );
+GLAPI void GLAPIENTRY glVertex4s( GLshort x, GLshort y, GLshort z, GLshort w );
+
+GLAPI void GLAPIENTRY glVertex2dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glVertex2fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glVertex2iv( const GLint *v );
+GLAPI void GLAPIENTRY glVertex2sv( const GLshort *v );
+
+GLAPI void GLAPIENTRY glVertex3dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glVertex3fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glVertex3iv( const GLint *v );
+GLAPI void GLAPIENTRY glVertex3sv( const GLshort *v );
+
+GLAPI void GLAPIENTRY glVertex4dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glVertex4fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glVertex4iv( const GLint *v );
+GLAPI void GLAPIENTRY glVertex4sv( const GLshort *v );
+
+
+GLAPI void GLAPIENTRY glNormal3b( GLbyte nx, GLbyte ny, GLbyte nz );
+GLAPI void GLAPIENTRY glNormal3d( GLdouble nx, GLdouble ny, GLdouble nz );
+GLAPI void GLAPIENTRY glNormal3f( GLfloat nx, GLfloat ny, GLfloat nz );
+GLAPI void GLAPIENTRY glNormal3i( GLint nx, GLint ny, GLint nz );
+GLAPI void GLAPIENTRY glNormal3s( GLshort nx, GLshort ny, GLshort nz );
+
+GLAPI void GLAPIENTRY glNormal3bv( const GLbyte *v );
+GLAPI void GLAPIENTRY glNormal3dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glNormal3fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glNormal3iv( const GLint *v );
+GLAPI void GLAPIENTRY glNormal3sv( const GLshort *v );
+
+
+GLAPI void GLAPIENTRY glIndexd( GLdouble c );
+GLAPI void GLAPIENTRY glIndexf( GLfloat c );
+GLAPI void GLAPIENTRY glIndexi( GLint c );
+GLAPI void GLAPIENTRY glIndexs( GLshort c );
+GLAPI void GLAPIENTRY glIndexub( GLubyte c ); /* 1.1 */
+
+GLAPI void GLAPIENTRY glIndexdv( const GLdouble *c );
+GLAPI void GLAPIENTRY glIndexfv( const GLfloat *c );
+GLAPI void GLAPIENTRY glIndexiv( const GLint *c );
+GLAPI void GLAPIENTRY glIndexsv( const GLshort *c );
+GLAPI void GLAPIENTRY glIndexubv( const GLubyte *c ); /* 1.1 */
+
+GLAPI void GLAPIENTRY glColor3b( GLbyte red, GLbyte green, GLbyte blue );
+GLAPI void GLAPIENTRY glColor3d( GLdouble red, GLdouble green, GLdouble blue );
+GLAPI void GLAPIENTRY glColor3f( GLfloat red, GLfloat green, GLfloat blue );
+GLAPI void GLAPIENTRY glColor3i( GLint red, GLint green, GLint blue );
+GLAPI void GLAPIENTRY glColor3s( GLshort red, GLshort green, GLshort blue );
+GLAPI void GLAPIENTRY glColor3ub( GLubyte red, GLubyte green, GLubyte blue );
+GLAPI void GLAPIENTRY glColor3ui( GLuint red, GLuint green, GLuint blue );
+GLAPI void GLAPIENTRY glColor3us( GLushort red, GLushort green, GLushort blue );
+
+GLAPI void GLAPIENTRY glColor4b( GLbyte red, GLbyte green,
+ GLbyte blue, GLbyte alpha );
+GLAPI void GLAPIENTRY glColor4d( GLdouble red, GLdouble green,
+ GLdouble blue, GLdouble alpha );
+GLAPI void GLAPIENTRY glColor4f( GLfloat red, GLfloat green,
+ GLfloat blue, GLfloat alpha );
+GLAPI void GLAPIENTRY glColor4i( GLint red, GLint green,
+ GLint blue, GLint alpha );
+GLAPI void GLAPIENTRY glColor4s( GLshort red, GLshort green,
+ GLshort blue, GLshort alpha );
+GLAPI void GLAPIENTRY glColor4ub( GLubyte red, GLubyte green,
+ GLubyte blue, GLubyte alpha );
+GLAPI void GLAPIENTRY glColor4ui( GLuint red, GLuint green,
+ GLuint blue, GLuint alpha );
+GLAPI void GLAPIENTRY glColor4us( GLushort red, GLushort green,
+ GLushort blue, GLushort alpha );
+
+
+GLAPI void GLAPIENTRY glColor3bv( const GLbyte *v );
+GLAPI void GLAPIENTRY glColor3dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glColor3fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glColor3iv( const GLint *v );
+GLAPI void GLAPIENTRY glColor3sv( const GLshort *v );
+GLAPI void GLAPIENTRY glColor3ubv( const GLubyte *v );
+GLAPI void GLAPIENTRY glColor3uiv( const GLuint *v );
+GLAPI void GLAPIENTRY glColor3usv( const GLushort *v );
+
+GLAPI void GLAPIENTRY glColor4bv( const GLbyte *v );
+GLAPI void GLAPIENTRY glColor4dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glColor4fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glColor4iv( const GLint *v );
+GLAPI void GLAPIENTRY glColor4sv( const GLshort *v );
+GLAPI void GLAPIENTRY glColor4ubv( const GLubyte *v );
+GLAPI void GLAPIENTRY glColor4uiv( const GLuint *v );
+GLAPI void GLAPIENTRY glColor4usv( const GLushort *v );
+
+
+GLAPI void GLAPIENTRY glTexCoord1d( GLdouble s );
+GLAPI void GLAPIENTRY glTexCoord1f( GLfloat s );
+GLAPI void GLAPIENTRY glTexCoord1i( GLint s );
+GLAPI void GLAPIENTRY glTexCoord1s( GLshort s );
+
+GLAPI void GLAPIENTRY glTexCoord2d( GLdouble s, GLdouble t );
+GLAPI void GLAPIENTRY glTexCoord2f( GLfloat s, GLfloat t );
+GLAPI void GLAPIENTRY glTexCoord2i( GLint s, GLint t );
+GLAPI void GLAPIENTRY glTexCoord2s( GLshort s, GLshort t );
+
+GLAPI void GLAPIENTRY glTexCoord3d( GLdouble s, GLdouble t, GLdouble r );
+GLAPI void GLAPIENTRY glTexCoord3f( GLfloat s, GLfloat t, GLfloat r );
+GLAPI void GLAPIENTRY glTexCoord3i( GLint s, GLint t, GLint r );
+GLAPI void GLAPIENTRY glTexCoord3s( GLshort s, GLshort t, GLshort r );
+
+GLAPI void GLAPIENTRY glTexCoord4d( GLdouble s, GLdouble t, GLdouble r, GLdouble q );
+GLAPI void GLAPIENTRY glTexCoord4f( GLfloat s, GLfloat t, GLfloat r, GLfloat q );
+GLAPI void GLAPIENTRY glTexCoord4i( GLint s, GLint t, GLint r, GLint q );
+GLAPI void GLAPIENTRY glTexCoord4s( GLshort s, GLshort t, GLshort r, GLshort q );
+
+GLAPI void GLAPIENTRY glTexCoord1dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glTexCoord1fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glTexCoord1iv( const GLint *v );
+GLAPI void GLAPIENTRY glTexCoord1sv( const GLshort *v );
+
+GLAPI void GLAPIENTRY glTexCoord2dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glTexCoord2fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glTexCoord2iv( const GLint *v );
+GLAPI void GLAPIENTRY glTexCoord2sv( const GLshort *v );
+
+GLAPI void GLAPIENTRY glTexCoord3dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glTexCoord3fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glTexCoord3iv( const GLint *v );
+GLAPI void GLAPIENTRY glTexCoord3sv( const GLshort *v );
+
+GLAPI void GLAPIENTRY glTexCoord4dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glTexCoord4fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glTexCoord4iv( const GLint *v );
+GLAPI void GLAPIENTRY glTexCoord4sv( const GLshort *v );
+
+
+GLAPI void GLAPIENTRY glRasterPos2d( GLdouble x, GLdouble y );
+GLAPI void GLAPIENTRY glRasterPos2f( GLfloat x, GLfloat y );
+GLAPI void GLAPIENTRY glRasterPos2i( GLint x, GLint y );
+GLAPI void GLAPIENTRY glRasterPos2s( GLshort x, GLshort y );
+
+GLAPI void GLAPIENTRY glRasterPos3d( GLdouble x, GLdouble y, GLdouble z );
+GLAPI void GLAPIENTRY glRasterPos3f( GLfloat x, GLfloat y, GLfloat z );
+GLAPI void GLAPIENTRY glRasterPos3i( GLint x, GLint y, GLint z );
+GLAPI void GLAPIENTRY glRasterPos3s( GLshort x, GLshort y, GLshort z );
+
+GLAPI void GLAPIENTRY glRasterPos4d( GLdouble x, GLdouble y, GLdouble z, GLdouble w );
+GLAPI void GLAPIENTRY glRasterPos4f( GLfloat x, GLfloat y, GLfloat z, GLfloat w );
+GLAPI void GLAPIENTRY glRasterPos4i( GLint x, GLint y, GLint z, GLint w );
+GLAPI void GLAPIENTRY glRasterPos4s( GLshort x, GLshort y, GLshort z, GLshort w );
+
+GLAPI void GLAPIENTRY glRasterPos2dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glRasterPos2fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glRasterPos2iv( const GLint *v );
+GLAPI void GLAPIENTRY glRasterPos2sv( const GLshort *v );
+
+GLAPI void GLAPIENTRY glRasterPos3dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glRasterPos3fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glRasterPos3iv( const GLint *v );
+GLAPI void GLAPIENTRY glRasterPos3sv( const GLshort *v );
+
+GLAPI void GLAPIENTRY glRasterPos4dv( const GLdouble *v );
+GLAPI void GLAPIENTRY glRasterPos4fv( const GLfloat *v );
+GLAPI void GLAPIENTRY glRasterPos4iv( const GLint *v );
+GLAPI void GLAPIENTRY glRasterPos4sv( const GLshort *v );
+
+
+GLAPI void GLAPIENTRY glRectd( GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2 );
+GLAPI void GLAPIENTRY glRectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 );
+GLAPI void GLAPIENTRY glRecti( GLint x1, GLint y1, GLint x2, GLint y2 );
+GLAPI void GLAPIENTRY glRects( GLshort x1, GLshort y1, GLshort x2, GLshort y2 );
+
+
+GLAPI void GLAPIENTRY glRectdv( const GLdouble *v1, const GLdouble *v2 );
+GLAPI void GLAPIENTRY glRectfv( const GLfloat *v1, const GLfloat *v2 );
+GLAPI void GLAPIENTRY glRectiv( const GLint *v1, const GLint *v2 );
+GLAPI void GLAPIENTRY glRectsv( const GLshort *v1, const GLshort *v2 );
+
+
+/*
+ * Vertex Arrays (1.1)
+ */
+
+GLAPI void GLAPIENTRY glVertexPointer( GLint size, GLenum type,
+ GLsizei stride, const GLvoid *ptr );
+
+GLAPI void GLAPIENTRY glNormalPointer( GLenum type, GLsizei stride,
+ const GLvoid *ptr );
+
+GLAPI void GLAPIENTRY glColorPointer( GLint size, GLenum type,
+ GLsizei stride, const GLvoid *ptr );
+
+GLAPI void GLAPIENTRY glIndexPointer( GLenum type, GLsizei stride,
+ const GLvoid *ptr );
+
+GLAPI void GLAPIENTRY glTexCoordPointer( GLint size, GLenum type,
+ GLsizei stride, const GLvoid *ptr );
+
+GLAPI void GLAPIENTRY glEdgeFlagPointer( GLsizei stride, const GLvoid *ptr );
+
+GLAPI void GLAPIENTRY glGetPointerv( GLenum pname, GLvoid **params );
+
+GLAPI void GLAPIENTRY glArrayElement( GLint i );
+
+GLAPI void GLAPIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count );
+
+GLAPI void GLAPIENTRY glDrawElements( GLenum mode, GLsizei count,
+ GLenum type, const GLvoid *indices );
+
+GLAPI void GLAPIENTRY glInterleavedArrays( GLenum format, GLsizei stride,
+ const GLvoid *pointer );
+
+/*
+ * Lighting
+ */
+
+GLAPI void GLAPIENTRY glShadeModel( GLenum mode );
+
+GLAPI void GLAPIENTRY glLightf( GLenum light, GLenum pname, GLfloat param );
+GLAPI void GLAPIENTRY glLighti( GLenum light, GLenum pname, GLint param );
+GLAPI void GLAPIENTRY glLightfv( GLenum light, GLenum pname,
+ const GLfloat *params );
+GLAPI void GLAPIENTRY glLightiv( GLenum light, GLenum pname,
+ const GLint *params );
+
+GLAPI void GLAPIENTRY glGetLightfv( GLenum light, GLenum pname,
+ GLfloat *params );
+GLAPI void GLAPIENTRY glGetLightiv( GLenum light, GLenum pname,
+ GLint *params );
+
+GLAPI void GLAPIENTRY glLightModelf( GLenum pname, GLfloat param );
+GLAPI void GLAPIENTRY glLightModeli( GLenum pname, GLint param );
+GLAPI void GLAPIENTRY glLightModelfv( GLenum pname, const GLfloat *params );
+GLAPI void GLAPIENTRY glLightModeliv( GLenum pname, const GLint *params );
+
+GLAPI void GLAPIENTRY glMaterialf( GLenum face, GLenum pname, GLfloat param );
+GLAPI void GLAPIENTRY glMateriali( GLenum face, GLenum pname, GLint param );
+GLAPI void GLAPIENTRY glMaterialfv( GLenum face, GLenum pname, const GLfloat *params );
+GLAPI void GLAPIENTRY glMaterialiv( GLenum face, GLenum pname, const GLint *params );
+
+GLAPI void GLAPIENTRY glGetMaterialfv( GLenum face, GLenum pname, GLfloat *params );
+GLAPI void GLAPIENTRY glGetMaterialiv( GLenum face, GLenum pname, GLint *params );
+
+GLAPI void GLAPIENTRY glColorMaterial( GLenum face, GLenum mode );
+
+
+/*
+ * Raster functions
+ */
+
+GLAPI void GLAPIENTRY glPixelZoom( GLfloat xfactor, GLfloat yfactor );
+
+GLAPI void GLAPIENTRY glPixelStoref( GLenum pname, GLfloat param );
+GLAPI void GLAPIENTRY glPixelStorei( GLenum pname, GLint param );
+
+GLAPI void GLAPIENTRY glPixelTransferf( GLenum pname, GLfloat param );
+GLAPI void GLAPIENTRY glPixelTransferi( GLenum pname, GLint param );
+
+GLAPI void GLAPIENTRY glPixelMapfv( GLenum map, GLsizei mapsize,
+ const GLfloat *values );
+GLAPI void GLAPIENTRY glPixelMapuiv( GLenum map, GLsizei mapsize,
+ const GLuint *values );
+GLAPI void GLAPIENTRY glPixelMapusv( GLenum map, GLsizei mapsize,
+ const GLushort *values );
+
+GLAPI void GLAPIENTRY glGetPixelMapfv( GLenum map, GLfloat *values );
+GLAPI void GLAPIENTRY glGetPixelMapuiv( GLenum map, GLuint *values );
+GLAPI void GLAPIENTRY glGetPixelMapusv( GLenum map, GLushort *values );
+
+GLAPI void GLAPIENTRY glBitmap( GLsizei width, GLsizei height,
+ GLfloat xorig, GLfloat yorig,
+ GLfloat xmove, GLfloat ymove,
+ const GLubyte *bitmap );
+
+GLAPI void GLAPIENTRY glReadPixels( GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ GLvoid *pixels );
+
+GLAPI void GLAPIENTRY glDrawPixels( GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const GLvoid *pixels );
+
+GLAPI void GLAPIENTRY glCopyPixels( GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLenum type );
+
+/*
+ * Stenciling
+ */
+
+GLAPI void GLAPIENTRY glStencilFunc( GLenum func, GLint ref, GLuint mask );
+
+GLAPI void GLAPIENTRY glStencilMask( GLuint mask );
+
+GLAPI void GLAPIENTRY glStencilOp( GLenum fail, GLenum zfail, GLenum zpass );
+
+GLAPI void GLAPIENTRY glClearStencil( GLint s );
+
+
+
+/*
+ * Texture mapping
+ */
+
+GLAPI void GLAPIENTRY glTexGend( GLenum coord, GLenum pname, GLdouble param );
+GLAPI void GLAPIENTRY glTexGenf( GLenum coord, GLenum pname, GLfloat param );
+GLAPI void GLAPIENTRY glTexGeni( GLenum coord, GLenum pname, GLint param );
+
+GLAPI void GLAPIENTRY glTexGendv( GLenum coord, GLenum pname, const GLdouble *params );
+GLAPI void GLAPIENTRY glTexGenfv( GLenum coord, GLenum pname, const GLfloat *params );
+GLAPI void GLAPIENTRY glTexGeniv( GLenum coord, GLenum pname, const GLint *params );
+
+GLAPI void GLAPIENTRY glGetTexGendv( GLenum coord, GLenum pname, GLdouble *params );
+GLAPI void GLAPIENTRY glGetTexGenfv( GLenum coord, GLenum pname, GLfloat *params );
+GLAPI void GLAPIENTRY glGetTexGeniv( GLenum coord, GLenum pname, GLint *params );
+
+
+GLAPI void GLAPIENTRY glTexEnvf( GLenum target, GLenum pname, GLfloat param );
+GLAPI void GLAPIENTRY glTexEnvi( GLenum target, GLenum pname, GLint param );
+
+GLAPI void GLAPIENTRY glTexEnvfv( GLenum target, GLenum pname, const GLfloat *params );
+GLAPI void GLAPIENTRY glTexEnviv( GLenum target, GLenum pname, const GLint *params );
+
+GLAPI void GLAPIENTRY glGetTexEnvfv( GLenum target, GLenum pname, GLfloat *params );
+GLAPI void GLAPIENTRY glGetTexEnviv( GLenum target, GLenum pname, GLint *params );
+
+
+GLAPI void GLAPIENTRY glTexParameterf( GLenum target, GLenum pname, GLfloat param );
+GLAPI void GLAPIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param );
+
+GLAPI void GLAPIENTRY glTexParameterfv( GLenum target, GLenum pname,
+ const GLfloat *params );
+GLAPI void GLAPIENTRY glTexParameteriv( GLenum target, GLenum pname,
+ const GLint *params );
+
+GLAPI void GLAPIENTRY glGetTexParameterfv( GLenum target,
+ GLenum pname, GLfloat *params);
+GLAPI void GLAPIENTRY glGetTexParameteriv( GLenum target,
+ GLenum pname, GLint *params );
+
+GLAPI void GLAPIENTRY glGetTexLevelParameterfv( GLenum target, GLint level,
+ GLenum pname, GLfloat *params );
+GLAPI void GLAPIENTRY glGetTexLevelParameteriv( GLenum target, GLint level,
+ GLenum pname, GLint *params );
+
+
+GLAPI void GLAPIENTRY glTexImage1D( GLenum target, GLint level,
+ GLint internalFormat,
+ GLsizei width, GLint border,
+ GLenum format, GLenum type,
+ const GLvoid *pixels );
+
+GLAPI void GLAPIENTRY glTexImage2D( GLenum target, GLint level,
+ GLint internalFormat,
+ GLsizei width, GLsizei height,
+ GLint border, GLenum format, GLenum type,
+ const GLvoid *pixels );
+
+GLAPI void GLAPIENTRY glGetTexImage( GLenum target, GLint level,
+ GLenum format, GLenum type,
+ GLvoid *pixels );
+
+
+/* 1.1 functions */
+
+GLAPI void GLAPIENTRY glGenTextures( GLsizei n, GLuint *textures );
+
+GLAPI void GLAPIENTRY glDeleteTextures( GLsizei n, const GLuint *textures);
+
+GLAPI void GLAPIENTRY glBindTexture( GLenum target, GLuint texture );
+
+GLAPI void GLAPIENTRY glPrioritizeTextures( GLsizei n,
+ const GLuint *textures,
+ const GLclampf *priorities );
+
+GLAPI GLboolean GLAPIENTRY glAreTexturesResident( GLsizei n,
+ const GLuint *textures,
+ GLboolean *residences );
+
+GLAPI GLboolean GLAPIENTRY glIsTexture( GLuint texture );
+
+
+GLAPI void GLAPIENTRY glTexSubImage1D( GLenum target, GLint level,
+ GLint xoffset,
+ GLsizei width, GLenum format,
+ GLenum type, const GLvoid *pixels );
+
+
+GLAPI void GLAPIENTRY glTexSubImage2D( GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLsizei width, GLsizei height,
+ GLenum format, GLenum type,
+ const GLvoid *pixels );
+
+
+GLAPI void GLAPIENTRY glCopyTexImage1D( GLenum target, GLint level,
+ GLenum internalformat,
+ GLint x, GLint y,
+ GLsizei width, GLint border );
+
+
+GLAPI void GLAPIENTRY glCopyTexImage2D( GLenum target, GLint level,
+ GLenum internalformat,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height,
+ GLint border );
+
+
+GLAPI void GLAPIENTRY glCopyTexSubImage1D( GLenum target, GLint level,
+ GLint xoffset, GLint x, GLint y,
+ GLsizei width );
+
+
+GLAPI void GLAPIENTRY glCopyTexSubImage2D( GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLint x, GLint y,
+ GLsizei width, GLsizei height );
+
+
+/*
+ * Evaluators
+ */
+
+GLAPI void GLAPIENTRY glMap1d( GLenum target, GLdouble u1, GLdouble u2,
+ GLint stride,
+ GLint order, const GLdouble *points );
+GLAPI void GLAPIENTRY glMap1f( GLenum target, GLfloat u1, GLfloat u2,
+ GLint stride,
+ GLint order, const GLfloat *points );
+
+GLAPI void GLAPIENTRY glMap2d( GLenum target,
+ GLdouble u1, GLdouble u2, GLint ustride, GLint uorder,
+ GLdouble v1, GLdouble v2, GLint vstride, GLint vorder,
+ const GLdouble *points );
+GLAPI void GLAPIENTRY glMap2f( GLenum target,
+ GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
+ GLfloat v1, GLfloat v2, GLint vstride, GLint vorder,
+ const GLfloat *points );
+
+GLAPI void GLAPIENTRY glGetMapdv( GLenum target, GLenum query, GLdouble *v );
+GLAPI void GLAPIENTRY glGetMapfv( GLenum target, GLenum query, GLfloat *v );
+GLAPI void GLAPIENTRY glGetMapiv( GLenum target, GLenum query, GLint *v );
+
+GLAPI void GLAPIENTRY glEvalCoord1d( GLdouble u );
+GLAPI void GLAPIENTRY glEvalCoord1f( GLfloat u );
+
+GLAPI void GLAPIENTRY glEvalCoord1dv( const GLdouble *u );
+GLAPI void GLAPIENTRY glEvalCoord1fv( const GLfloat *u );
+
+GLAPI void GLAPIENTRY glEvalCoord2d( GLdouble u, GLdouble v );
+GLAPI void GLAPIENTRY glEvalCoord2f( GLfloat u, GLfloat v );
+
+GLAPI void GLAPIENTRY glEvalCoord2dv( const GLdouble *u );
+GLAPI void GLAPIENTRY glEvalCoord2fv( const GLfloat *u );
+
+GLAPI void GLAPIENTRY glMapGrid1d( GLint un, GLdouble u1, GLdouble u2 );
+GLAPI void GLAPIENTRY glMapGrid1f( GLint un, GLfloat u1, GLfloat u2 );
+
+GLAPI void GLAPIENTRY glMapGrid2d( GLint un, GLdouble u1, GLdouble u2,
+ GLint vn, GLdouble v1, GLdouble v2 );
+GLAPI void GLAPIENTRY glMapGrid2f( GLint un, GLfloat u1, GLfloat u2,
+ GLint vn, GLfloat v1, GLfloat v2 );
+
+GLAPI void GLAPIENTRY glEvalPoint1( GLint i );
+
+GLAPI void GLAPIENTRY glEvalPoint2( GLint i, GLint j );
+
+GLAPI void GLAPIENTRY glEvalMesh1( GLenum mode, GLint i1, GLint i2 );
+
+GLAPI void GLAPIENTRY glEvalMesh2( GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2 );
+
+
+/*
+ * Fog
+ */
+
+GLAPI void GLAPIENTRY glFogf( GLenum pname, GLfloat param );
+
+GLAPI void GLAPIENTRY glFogi( GLenum pname, GLint param );
+
+GLAPI void GLAPIENTRY glFogfv( GLenum pname, const GLfloat *params );
+
+GLAPI void GLAPIENTRY glFogiv( GLenum pname, const GLint *params );
+
+
+/*
+ * Selection and Feedback
+ */
+
+GLAPI void GLAPIENTRY glFeedbackBuffer( GLsizei size, GLenum type, GLfloat *buffer );
+
+GLAPI void GLAPIENTRY glPassThrough( GLfloat token );
+
+GLAPI void GLAPIENTRY glSelectBuffer( GLsizei size, GLuint *buffer );
+
+GLAPI void GLAPIENTRY glInitNames( void );
+
+GLAPI void GLAPIENTRY glLoadName( GLuint name );
+
+GLAPI void GLAPIENTRY glPushName( GLuint name );
+
+GLAPI void GLAPIENTRY glPopName( void );
+
+
+
+/*
+ * OpenGL 1.2
+ */
+
+#define GL_RESCALE_NORMAL 0x803A
+#define GL_CLAMP_TO_EDGE 0x812F
+#define GL_MAX_ELEMENTS_VERTICES 0x80E8
+#define GL_MAX_ELEMENTS_INDICES 0x80E9
+#define GL_BGR 0x80E0
+#define GL_BGRA 0x80E1
+#define GL_UNSIGNED_BYTE_3_3_2 0x8032
+#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362
+#define GL_UNSIGNED_SHORT_5_6_5 0x8363
+#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
+#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
+#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
+#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
+#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
+#define GL_UNSIGNED_INT_8_8_8_8 0x8035
+#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
+#define GL_UNSIGNED_INT_10_10_10_2 0x8036
+#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
+#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8
+#define GL_SINGLE_COLOR 0x81F9
+#define GL_SEPARATE_SPECULAR_COLOR 0x81FA
+#define GL_TEXTURE_MIN_LOD 0x813A
+#define GL_TEXTURE_MAX_LOD 0x813B
+#define GL_TEXTURE_BASE_LEVEL 0x813C
+#define GL_TEXTURE_MAX_LEVEL 0x813D
+#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12
+#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13
+#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22
+#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23
+#define GL_ALIASED_POINT_SIZE_RANGE 0x846D
+#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E
+#define GL_PACK_SKIP_IMAGES 0x806B
+#define GL_PACK_IMAGE_HEIGHT 0x806C
+#define GL_UNPACK_SKIP_IMAGES 0x806D
+#define GL_UNPACK_IMAGE_HEIGHT 0x806E
+#define GL_TEXTURE_3D 0x806F
+#define GL_PROXY_TEXTURE_3D 0x8070
+#define GL_TEXTURE_DEPTH 0x8071
+#define GL_TEXTURE_WRAP_R 0x8072
+#define GL_MAX_3D_TEXTURE_SIZE 0x8073
+#define GL_TEXTURE_BINDING_3D 0x806A
+
+GLAPI void GLAPIENTRY glDrawRangeElements( GLenum mode, GLuint start,
+ GLuint end, GLsizei count, GLenum type, const GLvoid *indices );
+
+GLAPI void GLAPIENTRY glTexImage3D( GLenum target, GLint level,
+ GLint internalFormat,
+ GLsizei width, GLsizei height,
+ GLsizei depth, GLint border,
+ GLenum format, GLenum type,
+ const GLvoid *pixels );
+
+GLAPI void GLAPIENTRY glTexSubImage3D( GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLint zoffset, GLsizei width,
+ GLsizei height, GLsizei depth,
+ GLenum format,
+ GLenum type, const GLvoid *pixels);
+
+GLAPI void GLAPIENTRY glCopyTexSubImage3D( GLenum target, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLint zoffset, GLint x,
+ GLint y, GLsizei width,
+ GLsizei height );
+
+typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
+typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
+typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels);
+typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+
+
+/*
+ * GL_ARB_imaging
+ */
+
+#define GL_CONSTANT_COLOR 0x8001
+#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002
+#define GL_CONSTANT_ALPHA 0x8003
+#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004
+#define GL_COLOR_TABLE 0x80D0
+#define GL_POST_CONVOLUTION_COLOR_TABLE 0x80D1
+#define GL_POST_COLOR_MATRIX_COLOR_TABLE 0x80D2
+#define GL_PROXY_COLOR_TABLE 0x80D3
+#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE 0x80D4
+#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE 0x80D5
+#define GL_COLOR_TABLE_SCALE 0x80D6
+#define GL_COLOR_TABLE_BIAS 0x80D7
+#define GL_COLOR_TABLE_FORMAT 0x80D8
+#define GL_COLOR_TABLE_WIDTH 0x80D9
+#define GL_COLOR_TABLE_RED_SIZE 0x80DA
+#define GL_COLOR_TABLE_GREEN_SIZE 0x80DB
+#define GL_COLOR_TABLE_BLUE_SIZE 0x80DC
+#define GL_COLOR_TABLE_ALPHA_SIZE 0x80DD
+#define GL_COLOR_TABLE_LUMINANCE_SIZE 0x80DE
+#define GL_COLOR_TABLE_INTENSITY_SIZE 0x80DF
+#define GL_CONVOLUTION_1D 0x8010
+#define GL_CONVOLUTION_2D 0x8011
+#define GL_SEPARABLE_2D 0x8012
+#define GL_CONVOLUTION_BORDER_MODE 0x8013
+#define GL_CONVOLUTION_FILTER_SCALE 0x8014
+#define GL_CONVOLUTION_FILTER_BIAS 0x8015
+#define GL_REDUCE 0x8016
+#define GL_CONVOLUTION_FORMAT 0x8017
+#define GL_CONVOLUTION_WIDTH 0x8018
+#define GL_CONVOLUTION_HEIGHT 0x8019
+#define GL_MAX_CONVOLUTION_WIDTH 0x801A
+#define GL_MAX_CONVOLUTION_HEIGHT 0x801B
+#define GL_POST_CONVOLUTION_RED_SCALE 0x801C
+#define GL_POST_CONVOLUTION_GREEN_SCALE 0x801D
+#define GL_POST_CONVOLUTION_BLUE_SCALE 0x801E
+#define GL_POST_CONVOLUTION_ALPHA_SCALE 0x801F
+#define GL_POST_CONVOLUTION_RED_BIAS 0x8020
+#define GL_POST_CONVOLUTION_GREEN_BIAS 0x8021
+#define GL_POST_CONVOLUTION_BLUE_BIAS 0x8022
+#define GL_POST_CONVOLUTION_ALPHA_BIAS 0x8023
+#define GL_CONSTANT_BORDER 0x8151
+#define GL_REPLICATE_BORDER 0x8153
+#define GL_CONVOLUTION_BORDER_COLOR 0x8154
+#define GL_COLOR_MATRIX 0x80B1
+#define GL_COLOR_MATRIX_STACK_DEPTH 0x80B2
+#define GL_MAX_COLOR_MATRIX_STACK_DEPTH 0x80B3
+#define GL_POST_COLOR_MATRIX_RED_SCALE 0x80B4
+#define GL_POST_COLOR_MATRIX_GREEN_SCALE 0x80B5
+#define GL_POST_COLOR_MATRIX_BLUE_SCALE 0x80B6
+#define GL_POST_COLOR_MATRIX_ALPHA_SCALE 0x80B7
+#define GL_POST_COLOR_MATRIX_RED_BIAS 0x80B8
+#define GL_POST_COLOR_MATRIX_GREEN_BIAS 0x80B9
+#define GL_POST_COLOR_MATRIX_BLUE_BIAS 0x80BA
+#define GL_POST_COLOR_MATRIX_ALPHA_BIAS 0x80BB
+#define GL_HISTOGRAM 0x8024
+#define GL_PROXY_HISTOGRAM 0x8025
+#define GL_HISTOGRAM_WIDTH 0x8026
+#define GL_HISTOGRAM_FORMAT 0x8027
+#define GL_HISTOGRAM_RED_SIZE 0x8028
+#define GL_HISTOGRAM_GREEN_SIZE 0x8029
+#define GL_HISTOGRAM_BLUE_SIZE 0x802A
+#define GL_HISTOGRAM_ALPHA_SIZE 0x802B
+#define GL_HISTOGRAM_LUMINANCE_SIZE 0x802C
+#define GL_HISTOGRAM_SINK 0x802D
+#define GL_MINMAX 0x802E
+#define GL_MINMAX_FORMAT 0x802F
+#define GL_MINMAX_SINK 0x8030
+#define GL_TABLE_TOO_LARGE 0x8031
+#define GL_BLEND_EQUATION 0x8009
+#define GL_MIN 0x8007
+#define GL_MAX 0x8008
+#define GL_FUNC_ADD 0x8006
+#define GL_FUNC_SUBTRACT 0x800A
+#define GL_FUNC_REVERSE_SUBTRACT 0x800B
+#define GL_BLEND_COLOR 0x8005
+
+
+GLAPI void GLAPIENTRY glColorTable( GLenum target, GLenum internalformat,
+ GLsizei width, GLenum format,
+ GLenum type, const GLvoid *table );
+
+GLAPI void GLAPIENTRY glColorSubTable( GLenum target,
+ GLsizei start, GLsizei count,
+ GLenum format, GLenum type,
+ const GLvoid *data );
+
+GLAPI void GLAPIENTRY glColorTableParameteriv(GLenum target, GLenum pname,
+ const GLint *params);
+
+GLAPI void GLAPIENTRY glColorTableParameterfv(GLenum target, GLenum pname,
+ const GLfloat *params);
+
+GLAPI void GLAPIENTRY glCopyColorSubTable( GLenum target, GLsizei start,
+ GLint x, GLint y, GLsizei width );
+
+GLAPI void GLAPIENTRY glCopyColorTable( GLenum target, GLenum internalformat,
+ GLint x, GLint y, GLsizei width );
+
+GLAPI void GLAPIENTRY glGetColorTable( GLenum target, GLenum format,
+ GLenum type, GLvoid *table );
+
+GLAPI void GLAPIENTRY glGetColorTableParameterfv( GLenum target, GLenum pname,
+ GLfloat *params );
+
+GLAPI void GLAPIENTRY glGetColorTableParameteriv( GLenum target, GLenum pname,
+ GLint *params );
+
+GLAPI void GLAPIENTRY glBlendEquation( GLenum mode );
+
+GLAPI void GLAPIENTRY glBlendColor( GLclampf red, GLclampf green,
+ GLclampf blue, GLclampf alpha );
+
+GLAPI void GLAPIENTRY glHistogram( GLenum target, GLsizei width,
+ GLenum internalformat, GLboolean sink );
+
+GLAPI void GLAPIENTRY glResetHistogram( GLenum target );
+
+GLAPI void GLAPIENTRY glGetHistogram( GLenum target, GLboolean reset,
+ GLenum format, GLenum type,
+ GLvoid *values );
+
+GLAPI void GLAPIENTRY glGetHistogramParameterfv( GLenum target, GLenum pname,
+ GLfloat *params );
+
+GLAPI void GLAPIENTRY glGetHistogramParameteriv( GLenum target, GLenum pname,
+ GLint *params );
+
+GLAPI void GLAPIENTRY glMinmax( GLenum target, GLenum internalformat,
+ GLboolean sink );
+
+GLAPI void GLAPIENTRY glResetMinmax( GLenum target );
+
+GLAPI void GLAPIENTRY glGetMinmax( GLenum target, GLboolean reset,
+ GLenum format, GLenum types,
+ GLvoid *values );
+
+GLAPI void GLAPIENTRY glGetMinmaxParameterfv( GLenum target, GLenum pname,
+ GLfloat *params );
+
+GLAPI void GLAPIENTRY glGetMinmaxParameteriv( GLenum target, GLenum pname,
+ GLint *params );
+
+GLAPI void GLAPIENTRY glConvolutionFilter1D( GLenum target,
+ GLenum internalformat, GLsizei width, GLenum format, GLenum type,
+ const GLvoid *image );
+
+GLAPI void GLAPIENTRY glConvolutionFilter2D( GLenum target,
+ GLenum internalformat, GLsizei width, GLsizei height, GLenum format,
+ GLenum type, const GLvoid *image );
+
+GLAPI void GLAPIENTRY glConvolutionParameterf( GLenum target, GLenum pname,
+ GLfloat params );
+
+GLAPI void GLAPIENTRY glConvolutionParameterfv( GLenum target, GLenum pname,
+ const GLfloat *params );
+
+GLAPI void GLAPIENTRY glConvolutionParameteri( GLenum target, GLenum pname,
+ GLint params );
+
+GLAPI void GLAPIENTRY glConvolutionParameteriv( GLenum target, GLenum pname,
+ const GLint *params );
+
+GLAPI void GLAPIENTRY glCopyConvolutionFilter1D( GLenum target,
+ GLenum internalformat, GLint x, GLint y, GLsizei width );
+
+GLAPI void GLAPIENTRY glCopyConvolutionFilter2D( GLenum target,
+ GLenum internalformat, GLint x, GLint y, GLsizei width,
+ GLsizei height);
+
+GLAPI void GLAPIENTRY glGetConvolutionFilter( GLenum target, GLenum format,
+ GLenum type, GLvoid *image );
+
+GLAPI void GLAPIENTRY glGetConvolutionParameterfv( GLenum target, GLenum pname,
+ GLfloat *params );
+
+GLAPI void GLAPIENTRY glGetConvolutionParameteriv( GLenum target, GLenum pname,
+ GLint *params );
+
+GLAPI void GLAPIENTRY glSeparableFilter2D( GLenum target,
+ GLenum internalformat, GLsizei width, GLsizei height, GLenum format,
+ GLenum type, const GLvoid *row, const GLvoid *column );
+
+GLAPI void GLAPIENTRY glGetSeparableFilter( GLenum target, GLenum format,
+ GLenum type, GLvoid *row, GLvoid *column, GLvoid *span );
+
+
+
+
+/*
+ * OpenGL 1.3
+ */
+
+/* multitexture */
+#define GL_TEXTURE0 0x84C0
+#define GL_TEXTURE1 0x84C1
+#define GL_TEXTURE2 0x84C2
+#define GL_TEXTURE3 0x84C3
+#define GL_TEXTURE4 0x84C4
+#define GL_TEXTURE5 0x84C5
+#define GL_TEXTURE6 0x84C6
+#define GL_TEXTURE7 0x84C7
+#define GL_TEXTURE8 0x84C8
+#define GL_TEXTURE9 0x84C9
+#define GL_TEXTURE10 0x84CA
+#define GL_TEXTURE11 0x84CB
+#define GL_TEXTURE12 0x84CC
+#define GL_TEXTURE13 0x84CD
+#define GL_TEXTURE14 0x84CE
+#define GL_TEXTURE15 0x84CF
+#define GL_TEXTURE16 0x84D0
+#define GL_TEXTURE17 0x84D1
+#define GL_TEXTURE18 0x84D2
+#define GL_TEXTURE19 0x84D3
+#define GL_TEXTURE20 0x84D4
+#define GL_TEXTURE21 0x84D5
+#define GL_TEXTURE22 0x84D6
+#define GL_TEXTURE23 0x84D7
+#define GL_TEXTURE24 0x84D8
+#define GL_TEXTURE25 0x84D9
+#define GL_TEXTURE26 0x84DA
+#define GL_TEXTURE27 0x84DB
+#define GL_TEXTURE28 0x84DC
+#define GL_TEXTURE29 0x84DD
+#define GL_TEXTURE30 0x84DE
+#define GL_TEXTURE31 0x84DF
+#define GL_ACTIVE_TEXTURE 0x84E0
+#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1
+#define GL_MAX_TEXTURE_UNITS 0x84E2
+/* texture_cube_map */
+#define GL_NORMAL_MAP 0x8511
+#define GL_REFLECTION_MAP 0x8512
+#define GL_TEXTURE_CUBE_MAP 0x8513
+#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
+#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B
+#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C
+/* texture_compression */
+#define GL_COMPRESSED_ALPHA 0x84E9
+#define GL_COMPRESSED_LUMINANCE 0x84EA
+#define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB
+#define GL_COMPRESSED_INTENSITY 0x84EC
+#define GL_COMPRESSED_RGB 0x84ED
+#define GL_COMPRESSED_RGBA 0x84EE
+#define GL_TEXTURE_COMPRESSION_HINT 0x84EF
+#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0
+#define GL_TEXTURE_COMPRESSED 0x86A1
+#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2
+#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3
+/* multisample */
+#define GL_MULTISAMPLE 0x809D
+#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E
+#define GL_SAMPLE_ALPHA_TO_ONE 0x809F
+#define GL_SAMPLE_COVERAGE 0x80A0
+#define GL_SAMPLE_BUFFERS 0x80A8
+#define GL_SAMPLES 0x80A9
+#define GL_SAMPLE_COVERAGE_VALUE 0x80AA
+#define GL_SAMPLE_COVERAGE_INVERT 0x80AB
+#define GL_MULTISAMPLE_BIT 0x20000000
+/* transpose_matrix */
+#define GL_TRANSPOSE_MODELVIEW_MATRIX 0x84E3
+#define GL_TRANSPOSE_PROJECTION_MATRIX 0x84E4
+#define GL_TRANSPOSE_TEXTURE_MATRIX 0x84E5
+#define GL_TRANSPOSE_COLOR_MATRIX 0x84E6
+/* texture_env_combine */
+#define GL_COMBINE 0x8570
+#define GL_COMBINE_RGB 0x8571
+#define GL_COMBINE_ALPHA 0x8572
+#define GL_SOURCE0_RGB 0x8580
+#define GL_SOURCE1_RGB 0x8581
+#define GL_SOURCE2_RGB 0x8582
+#define GL_SOURCE0_ALPHA 0x8588
+#define GL_SOURCE1_ALPHA 0x8589
+#define GL_SOURCE2_ALPHA 0x858A
+#define GL_OPERAND0_RGB 0x8590
+#define GL_OPERAND1_RGB 0x8591
+#define GL_OPERAND2_RGB 0x8592
+#define GL_OPERAND0_ALPHA 0x8598
+#define GL_OPERAND1_ALPHA 0x8599
+#define GL_OPERAND2_ALPHA 0x859A
+#define GL_RGB_SCALE 0x8573
+#define GL_ADD_SIGNED 0x8574
+#define GL_INTERPOLATE 0x8575
+#define GL_SUBTRACT 0x84E7
+#define GL_CONSTANT 0x8576
+#define GL_PRIMARY_COLOR 0x8577
+#define GL_PREVIOUS 0x8578
+/* texture_env_dot3 */
+#define GL_DOT3_RGB 0x86AE
+#define GL_DOT3_RGBA 0x86AF
+/* texture_border_clamp */
+#define GL_CLAMP_TO_BORDER 0x812D
+
+GLAPI void GLAPIENTRY glActiveTexture( GLenum texture );
+
+GLAPI void GLAPIENTRY glClientActiveTexture( GLenum texture );
+
+GLAPI void GLAPIENTRY glCompressedTexImage1D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data );
+
+GLAPI void GLAPIENTRY glCompressedTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data );
+
+GLAPI void GLAPIENTRY glCompressedTexImage3D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data );
+
+GLAPI void GLAPIENTRY glCompressedTexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data );
+
+GLAPI void GLAPIENTRY glCompressedTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data );
+
+GLAPI void GLAPIENTRY glCompressedTexSubImage3D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data );
+
+GLAPI void GLAPIENTRY glGetCompressedTexImage( GLenum target, GLint lod, GLvoid *img );
+
+GLAPI void GLAPIENTRY glMultiTexCoord1d( GLenum target, GLdouble s );
+
+GLAPI void GLAPIENTRY glMultiTexCoord1dv( GLenum target, const GLdouble *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord1f( GLenum target, GLfloat s );
+
+GLAPI void GLAPIENTRY glMultiTexCoord1fv( GLenum target, const GLfloat *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord1i( GLenum target, GLint s );
+
+GLAPI void GLAPIENTRY glMultiTexCoord1iv( GLenum target, const GLint *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord1s( GLenum target, GLshort s );
+
+GLAPI void GLAPIENTRY glMultiTexCoord1sv( GLenum target, const GLshort *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord2d( GLenum target, GLdouble s, GLdouble t );
+
+GLAPI void GLAPIENTRY glMultiTexCoord2dv( GLenum target, const GLdouble *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord2f( GLenum target, GLfloat s, GLfloat t );
+
+GLAPI void GLAPIENTRY glMultiTexCoord2fv( GLenum target, const GLfloat *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord2i( GLenum target, GLint s, GLint t );
+
+GLAPI void GLAPIENTRY glMultiTexCoord2iv( GLenum target, const GLint *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord2s( GLenum target, GLshort s, GLshort t );
+
+GLAPI void GLAPIENTRY glMultiTexCoord2sv( GLenum target, const GLshort *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord3d( GLenum target, GLdouble s, GLdouble t, GLdouble r );
+
+GLAPI void GLAPIENTRY glMultiTexCoord3dv( GLenum target, const GLdouble *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord3f( GLenum target, GLfloat s, GLfloat t, GLfloat r );
+
+GLAPI void GLAPIENTRY glMultiTexCoord3fv( GLenum target, const GLfloat *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord3i( GLenum target, GLint s, GLint t, GLint r );
+
+GLAPI void GLAPIENTRY glMultiTexCoord3iv( GLenum target, const GLint *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord3s( GLenum target, GLshort s, GLshort t, GLshort r );
+
+GLAPI void GLAPIENTRY glMultiTexCoord3sv( GLenum target, const GLshort *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord4d( GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q );
+
+GLAPI void GLAPIENTRY glMultiTexCoord4dv( GLenum target, const GLdouble *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord4f( GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q );
+
+GLAPI void GLAPIENTRY glMultiTexCoord4fv( GLenum target, const GLfloat *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord4i( GLenum target, GLint s, GLint t, GLint r, GLint q );
+
+GLAPI void GLAPIENTRY glMultiTexCoord4iv( GLenum target, const GLint *v );
+
+GLAPI void GLAPIENTRY glMultiTexCoord4s( GLenum target, GLshort s, GLshort t, GLshort r, GLshort q );
+
+GLAPI void GLAPIENTRY glMultiTexCoord4sv( GLenum target, const GLshort *v );
+
+
+GLAPI void GLAPIENTRY glLoadTransposeMatrixd( const GLdouble m[16] );
+
+GLAPI void GLAPIENTRY glLoadTransposeMatrixf( const GLfloat m[16] );
+
+GLAPI void GLAPIENTRY glMultTransposeMatrixd( const GLdouble m[16] );
+
+GLAPI void GLAPIENTRY glMultTransposeMatrixf( const GLfloat m[16] );
+
+GLAPI void GLAPIENTRY glSampleCoverage( GLclampf value, GLboolean invert );
+
+
+typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
+typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLclampf value, GLboolean invert);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const GLvoid *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data);
+typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, GLvoid *img);
+
+
+
+/*
+ * GL_ARB_multitexture (ARB extension 1 and OpenGL 1.2.1)
+ */
+#ifndef GL_ARB_multitexture
+#define GL_ARB_multitexture 1
+
+#define GL_TEXTURE0_ARB 0x84C0
+#define GL_TEXTURE1_ARB 0x84C1
+#define GL_TEXTURE2_ARB 0x84C2
+#define GL_TEXTURE3_ARB 0x84C3
+#define GL_TEXTURE4_ARB 0x84C4
+#define GL_TEXTURE5_ARB 0x84C5
+#define GL_TEXTURE6_ARB 0x84C6
+#define GL_TEXTURE7_ARB 0x84C7
+#define GL_TEXTURE8_ARB 0x84C8
+#define GL_TEXTURE9_ARB 0x84C9
+#define GL_TEXTURE10_ARB 0x84CA
+#define GL_TEXTURE11_ARB 0x84CB
+#define GL_TEXTURE12_ARB 0x84CC
+#define GL_TEXTURE13_ARB 0x84CD
+#define GL_TEXTURE14_ARB 0x84CE
+#define GL_TEXTURE15_ARB 0x84CF
+#define GL_TEXTURE16_ARB 0x84D0
+#define GL_TEXTURE17_ARB 0x84D1
+#define GL_TEXTURE18_ARB 0x84D2
+#define GL_TEXTURE19_ARB 0x84D3
+#define GL_TEXTURE20_ARB 0x84D4
+#define GL_TEXTURE21_ARB 0x84D5
+#define GL_TEXTURE22_ARB 0x84D6
+#define GL_TEXTURE23_ARB 0x84D7
+#define GL_TEXTURE24_ARB 0x84D8
+#define GL_TEXTURE25_ARB 0x84D9
+#define GL_TEXTURE26_ARB 0x84DA
+#define GL_TEXTURE27_ARB 0x84DB
+#define GL_TEXTURE28_ARB 0x84DC
+#define GL_TEXTURE29_ARB 0x84DD
+#define GL_TEXTURE30_ARB 0x84DE
+#define GL_TEXTURE31_ARB 0x84DF
+#define GL_ACTIVE_TEXTURE_ARB 0x84E0
+#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1
+#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2
+
+GLAPI void GLAPIENTRY glActiveTextureARB(GLenum texture);
+GLAPI void GLAPIENTRY glClientActiveTextureARB(GLenum texture);
+GLAPI void GLAPIENTRY glMultiTexCoord1dARB(GLenum target, GLdouble s);
+GLAPI void GLAPIENTRY glMultiTexCoord1dvARB(GLenum target, const GLdouble *v);
+GLAPI void GLAPIENTRY glMultiTexCoord1fARB(GLenum target, GLfloat s);
+GLAPI void GLAPIENTRY glMultiTexCoord1fvARB(GLenum target, const GLfloat *v);
+GLAPI void GLAPIENTRY glMultiTexCoord1iARB(GLenum target, GLint s);
+GLAPI void GLAPIENTRY glMultiTexCoord1ivARB(GLenum target, const GLint *v);
+GLAPI void GLAPIENTRY glMultiTexCoord1sARB(GLenum target, GLshort s);
+GLAPI void GLAPIENTRY glMultiTexCoord1svARB(GLenum target, const GLshort *v);
+GLAPI void GLAPIENTRY glMultiTexCoord2dARB(GLenum target, GLdouble s, GLdouble t);
+GLAPI void GLAPIENTRY glMultiTexCoord2dvARB(GLenum target, const GLdouble *v);
+GLAPI void GLAPIENTRY glMultiTexCoord2fARB(GLenum target, GLfloat s, GLfloat t);
+GLAPI void GLAPIENTRY glMultiTexCoord2fvARB(GLenum target, const GLfloat *v);
+GLAPI void GLAPIENTRY glMultiTexCoord2iARB(GLenum target, GLint s, GLint t);
+GLAPI void GLAPIENTRY glMultiTexCoord2ivARB(GLenum target, const GLint *v);
+GLAPI void GLAPIENTRY glMultiTexCoord2sARB(GLenum target, GLshort s, GLshort t);
+GLAPI void GLAPIENTRY glMultiTexCoord2svARB(GLenum target, const GLshort *v);
+GLAPI void GLAPIENTRY glMultiTexCoord3dARB(GLenum target, GLdouble s, GLdouble t, GLdouble r);
+GLAPI void GLAPIENTRY glMultiTexCoord3dvARB(GLenum target, const GLdouble *v);
+GLAPI void GLAPIENTRY glMultiTexCoord3fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r);
+GLAPI void GLAPIENTRY glMultiTexCoord3fvARB(GLenum target, const GLfloat *v);
+GLAPI void GLAPIENTRY glMultiTexCoord3iARB(GLenum target, GLint s, GLint t, GLint r);
+GLAPI void GLAPIENTRY glMultiTexCoord3ivARB(GLenum target, const GLint *v);
+GLAPI void GLAPIENTRY glMultiTexCoord3sARB(GLenum target, GLshort s, GLshort t, GLshort r);
+GLAPI void GLAPIENTRY glMultiTexCoord3svARB(GLenum target, const GLshort *v);
+GLAPI void GLAPIENTRY glMultiTexCoord4dARB(GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q);
+GLAPI void GLAPIENTRY glMultiTexCoord4dvARB(GLenum target, const GLdouble *v);
+GLAPI void GLAPIENTRY glMultiTexCoord4fARB(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
+GLAPI void GLAPIENTRY glMultiTexCoord4fvARB(GLenum target, const GLfloat *v);
+GLAPI void GLAPIENTRY glMultiTexCoord4iARB(GLenum target, GLint s, GLint t, GLint r, GLint q);
+GLAPI void GLAPIENTRY glMultiTexCoord4ivARB(GLenum target, const GLint *v);
+GLAPI void GLAPIENTRY glMultiTexCoord4sARB(GLenum target, GLshort s, GLshort t, GLshort r, GLshort q);
+GLAPI void GLAPIENTRY glMultiTexCoord4svARB(GLenum target, const GLshort *v);
+
+typedef void (APIENTRYP PFNGLACTIVETEXTUREARBPROC) (GLenum texture);
+typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1DARBPROC) (GLenum target, GLdouble s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVARBPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1FARBPROC) (GLenum target, GLfloat s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVARBPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1IARBPROC) (GLenum target, GLint s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVARBPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1SARBPROC) (GLenum target, GLshort s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVARBPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2DARBPROC) (GLenum target, GLdouble s, GLdouble t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVARBPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2IARBPROC) (GLenum target, GLint s, GLint t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVARBPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2SARBPROC) (GLenum target, GLshort s, GLshort t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVARBPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVARBPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3IARBPROC) (GLenum target, GLint s, GLint t, GLint r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVARBPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVARBPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVARBPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4IARBPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVARBPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLshort *v);
+
+#endif /* GL_ARB_multitexture */
+
+
+
+/*
+ * Define this token if you want "old-style" header file behaviour (extensions
+ * defined in gl.h). Otherwise, extensions will be included from glext.h.
+ */
+#if !defined(NO_SDL_GLEXT) && !defined(GL_GLEXT_LEGACY)
+#include "SDL_opengl_glext.h"
+#endif /* GL_GLEXT_LEGACY */
+
+
+
+/*
+ * ???. GL_MESA_packed_depth_stencil
+ * XXX obsolete
+ */
+#ifndef GL_MESA_packed_depth_stencil
+#define GL_MESA_packed_depth_stencil 1
+
+#define GL_DEPTH_STENCIL_MESA 0x8750
+#define GL_UNSIGNED_INT_24_8_MESA 0x8751
+#define GL_UNSIGNED_INT_8_24_REV_MESA 0x8752
+#define GL_UNSIGNED_SHORT_15_1_MESA 0x8753
+#define GL_UNSIGNED_SHORT_1_15_REV_MESA 0x8754
+
+#endif /* GL_MESA_packed_depth_stencil */
+
+
+#ifndef GL_ATI_blend_equation_separate
+#define GL_ATI_blend_equation_separate 1
+
+#define GL_ALPHA_BLEND_EQUATION_ATI 0x883D
+
+GLAPI void GLAPIENTRY glBlendEquationSeparateATI( GLenum modeRGB, GLenum modeA );
+typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEATIPROC) (GLenum modeRGB, GLenum modeA);
+
+#endif /* GL_ATI_blend_equation_separate */
+
+
+/* GL_OES_EGL_image */
+#ifndef GL_OES_EGL_image
+typedef void* GLeglImageOES;
+#endif
+
+#ifndef GL_OES_EGL_image
+#define GL_OES_EGL_image 1
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image);
+GLAPI void APIENTRY glEGLImageTargetRenderbufferStorageOES (GLenum target, GLeglImageOES image);
+#endif
+typedef void (APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image);
+typedef void (APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image);
+#endif
+
+
+/**
+ ** NOTE!!!!! If you add new functions to this file, or update
+ ** glext.h be sure to regenerate the gl_mangle.h file. See comments
+ ** in that file for details.
+ **/
+
+
+
+/**********************************************************************
+ * Begin system-specific stuff
+ */
+#if defined(PRAGMA_EXPORT_SUPPORTED)
+#pragma export off
+#endif
+
+/*
+ * End system-specific stuff
+ **********************************************************************/
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __gl_h_ */
+
+#endif /* !__IPHONEOS__ */
+
+#endif /* SDL_opengl_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_opengl_glext.h b/src/3rdparty/SDL2/include/SDL_opengl_glext.h
new file mode 100644
index 0000000..cd3869f
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_opengl_glext.h
@@ -0,0 +1,11177 @@
+#ifndef __glext_h_
+#define __glext_h_ 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+** Copyright (c) 2013-2014 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+/*
+** This header is generated from the Khronos OpenGL / OpenGL ES XML
+** API Registry. The current version of the Registry, generator scripts
+** used to make the header, and the header can be found at
+** http://www.opengl.org/registry/
+**
+** Khronos $Revision: 26745 $ on $Date: 2014-05-21 03:12:26 -0700 (Wed, 21 May 2014) $
+*/
+
+#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN 1
+#endif
+#include <windows.h>
+#endif
+
+#ifndef APIENTRY
+#define APIENTRY
+#endif
+#ifndef APIENTRYP
+#define APIENTRYP APIENTRY *
+#endif
+#ifndef GLAPI
+#define GLAPI extern
+#endif
+
+#define GL_GLEXT_VERSION 20140521
+
+/* Generated C header for:
+ * API: gl
+ * Profile: compatibility
+ * Versions considered: .*
+ * Versions emitted: 1\.[2-9]|[234]\.[0-9]
+ * Default extensions included: gl
+ * Additional extensions included: _nomatch_^
+ * Extensions removed: _nomatch_^
+ */
+
+#ifndef GL_VERSION_1_2
+#define GL_VERSION_1_2 1
+#define GL_UNSIGNED_BYTE_3_3_2 0x8032
+#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
+#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
+#define GL_UNSIGNED_INT_8_8_8_8 0x8035
+#define GL_UNSIGNED_INT_10_10_10_2 0x8036
+#define GL_TEXTURE_BINDING_3D 0x806A
+#define GL_PACK_SKIP_IMAGES 0x806B
+#define GL_PACK_IMAGE_HEIGHT 0x806C
+#define GL_UNPACK_SKIP_IMAGES 0x806D
+#define GL_UNPACK_IMAGE_HEIGHT 0x806E
+#define GL_TEXTURE_3D 0x806F
+#define GL_PROXY_TEXTURE_3D 0x8070
+#define GL_TEXTURE_DEPTH 0x8071
+#define GL_TEXTURE_WRAP_R 0x8072
+#define GL_MAX_3D_TEXTURE_SIZE 0x8073
+#define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362
+#define GL_UNSIGNED_SHORT_5_6_5 0x8363
+#define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
+#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
+#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
+#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
+#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
+#define GL_BGR 0x80E0
+#define GL_BGRA 0x80E1
+#define GL_MAX_ELEMENTS_VERTICES 0x80E8
+#define GL_MAX_ELEMENTS_INDICES 0x80E9
+#define GL_CLAMP_TO_EDGE 0x812F
+#define GL_TEXTURE_MIN_LOD 0x813A
+#define GL_TEXTURE_MAX_LOD 0x813B
+#define GL_TEXTURE_BASE_LEVEL 0x813C
+#define GL_TEXTURE_MAX_LEVEL 0x813D
+#define GL_SMOOTH_POINT_SIZE_RANGE 0x0B12
+#define GL_SMOOTH_POINT_SIZE_GRANULARITY 0x0B13
+#define GL_SMOOTH_LINE_WIDTH_RANGE 0x0B22
+#define GL_SMOOTH_LINE_WIDTH_GRANULARITY 0x0B23
+#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E
+#define GL_RESCALE_NORMAL 0x803A
+#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8
+#define GL_SINGLE_COLOR 0x81F9
+#define GL_SEPARATE_SPECULAR_COLOR 0x81FA
+#define GL_ALIASED_POINT_SIZE_RANGE 0x846D
+typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices);
+typedef void (APIENTRYP PFNGLTEXIMAGE3DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawRangeElements (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices);
+GLAPI void APIENTRY glTexImage3D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glCopyTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+#endif
+#endif /* GL_VERSION_1_2 */
+
+#ifndef GL_VERSION_1_3
+#define GL_VERSION_1_3 1
+#define GL_TEXTURE0 0x84C0
+#define GL_TEXTURE1 0x84C1
+#define GL_TEXTURE2 0x84C2
+#define GL_TEXTURE3 0x84C3
+#define GL_TEXTURE4 0x84C4
+#define GL_TEXTURE5 0x84C5
+#define GL_TEXTURE6 0x84C6
+#define GL_TEXTURE7 0x84C7
+#define GL_TEXTURE8 0x84C8
+#define GL_TEXTURE9 0x84C9
+#define GL_TEXTURE10 0x84CA
+#define GL_TEXTURE11 0x84CB
+#define GL_TEXTURE12 0x84CC
+#define GL_TEXTURE13 0x84CD
+#define GL_TEXTURE14 0x84CE
+#define GL_TEXTURE15 0x84CF
+#define GL_TEXTURE16 0x84D0
+#define GL_TEXTURE17 0x84D1
+#define GL_TEXTURE18 0x84D2
+#define GL_TEXTURE19 0x84D3
+#define GL_TEXTURE20 0x84D4
+#define GL_TEXTURE21 0x84D5
+#define GL_TEXTURE22 0x84D6
+#define GL_TEXTURE23 0x84D7
+#define GL_TEXTURE24 0x84D8
+#define GL_TEXTURE25 0x84D9
+#define GL_TEXTURE26 0x84DA
+#define GL_TEXTURE27 0x84DB
+#define GL_TEXTURE28 0x84DC
+#define GL_TEXTURE29 0x84DD
+#define GL_TEXTURE30 0x84DE
+#define GL_TEXTURE31 0x84DF
+#define GL_ACTIVE_TEXTURE 0x84E0
+#define GL_MULTISAMPLE 0x809D
+#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E
+#define GL_SAMPLE_ALPHA_TO_ONE 0x809F
+#define GL_SAMPLE_COVERAGE 0x80A0
+#define GL_SAMPLE_BUFFERS 0x80A8
+#define GL_SAMPLES 0x80A9
+#define GL_SAMPLE_COVERAGE_VALUE 0x80AA
+#define GL_SAMPLE_COVERAGE_INVERT 0x80AB
+#define GL_TEXTURE_CUBE_MAP 0x8513
+#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
+#define GL_PROXY_TEXTURE_CUBE_MAP 0x851B
+#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C
+#define GL_COMPRESSED_RGB 0x84ED
+#define GL_COMPRESSED_RGBA 0x84EE
+#define GL_TEXTURE_COMPRESSION_HINT 0x84EF
+#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE 0x86A0
+#define GL_TEXTURE_COMPRESSED 0x86A1
+#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2
+#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3
+#define GL_CLAMP_TO_BORDER 0x812D
+#define GL_CLIENT_ACTIVE_TEXTURE 0x84E1
+#define GL_MAX_TEXTURE_UNITS 0x84E2
+#define GL_TRANSPOSE_MODELVIEW_MATRIX 0x84E3
+#define GL_TRANSPOSE_PROJECTION_MATRIX 0x84E4
+#define GL_TRANSPOSE_TEXTURE_MATRIX 0x84E5
+#define GL_TRANSPOSE_COLOR_MATRIX 0x84E6
+#define GL_MULTISAMPLE_BIT 0x20000000
+#define GL_NORMAL_MAP 0x8511
+#define GL_REFLECTION_MAP 0x8512
+#define GL_COMPRESSED_ALPHA 0x84E9
+#define GL_COMPRESSED_LUMINANCE 0x84EA
+#define GL_COMPRESSED_LUMINANCE_ALPHA 0x84EB
+#define GL_COMPRESSED_INTENSITY 0x84EC
+#define GL_COMBINE 0x8570
+#define GL_COMBINE_RGB 0x8571
+#define GL_COMBINE_ALPHA 0x8572
+#define GL_SOURCE0_RGB 0x8580
+#define GL_SOURCE1_RGB 0x8581
+#define GL_SOURCE2_RGB 0x8582
+#define GL_SOURCE0_ALPHA 0x8588
+#define GL_SOURCE1_ALPHA 0x8589
+#define GL_SOURCE2_ALPHA 0x858A
+#define GL_OPERAND0_RGB 0x8590
+#define GL_OPERAND1_RGB 0x8591
+#define GL_OPERAND2_RGB 0x8592
+#define GL_OPERAND0_ALPHA 0x8598
+#define GL_OPERAND1_ALPHA 0x8599
+#define GL_OPERAND2_ALPHA 0x859A
+#define GL_RGB_SCALE 0x8573
+#define GL_ADD_SIGNED 0x8574
+#define GL_INTERPOLATE 0x8575
+#define GL_SUBTRACT 0x84E7
+#define GL_CONSTANT 0x8576
+#define GL_PRIMARY_COLOR 0x8577
+#define GL_PREVIOUS 0x8578
+#define GL_DOT3_RGB 0x86AE
+#define GL_DOT3_RGBA 0x86AF
+typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
+typedef void (APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLfloat value, GLboolean invert);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEPROC) (GLenum target, GLint level, void *img);
+typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREPROC) (GLenum texture);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1DPROC) (GLenum target, GLdouble s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1FPROC) (GLenum target, GLfloat s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1IPROC) (GLenum target, GLint s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1SPROC) (GLenum target, GLshort s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2DPROC) (GLenum target, GLdouble s, GLdouble t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2FPROC) (GLenum target, GLfloat s, GLfloat t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2IPROC) (GLenum target, GLint s, GLint t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2SPROC) (GLenum target, GLshort s, GLshort t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3IPROC) (GLenum target, GLint s, GLint t, GLint r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3SPROC) (GLenum target, GLshort s, GLshort t, GLshort r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4DPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4FPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4IPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4SPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFPROC) (const GLfloat *m);
+typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDPROC) (const GLdouble *m);
+typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFPROC) (const GLfloat *m);
+typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDPROC) (const GLdouble *m);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glActiveTexture (GLenum texture);
+GLAPI void APIENTRY glSampleCoverage (GLfloat value, GLboolean invert);
+GLAPI void APIENTRY glCompressedTexImage3D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexImage1D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexSubImage3D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexSubImage1D (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glGetCompressedTexImage (GLenum target, GLint level, void *img);
+GLAPI void APIENTRY glClientActiveTexture (GLenum texture);
+GLAPI void APIENTRY glMultiTexCoord1d (GLenum target, GLdouble s);
+GLAPI void APIENTRY glMultiTexCoord1dv (GLenum target, const GLdouble *v);
+GLAPI void APIENTRY glMultiTexCoord1f (GLenum target, GLfloat s);
+GLAPI void APIENTRY glMultiTexCoord1fv (GLenum target, const GLfloat *v);
+GLAPI void APIENTRY glMultiTexCoord1i (GLenum target, GLint s);
+GLAPI void APIENTRY glMultiTexCoord1iv (GLenum target, const GLint *v);
+GLAPI void APIENTRY glMultiTexCoord1s (GLenum target, GLshort s);
+GLAPI void APIENTRY glMultiTexCoord1sv (GLenum target, const GLshort *v);
+GLAPI void APIENTRY glMultiTexCoord2d (GLenum target, GLdouble s, GLdouble t);
+GLAPI void APIENTRY glMultiTexCoord2dv (GLenum target, const GLdouble *v);
+GLAPI void APIENTRY glMultiTexCoord2f (GLenum target, GLfloat s, GLfloat t);
+GLAPI void APIENTRY glMultiTexCoord2fv (GLenum target, const GLfloat *v);
+GLAPI void APIENTRY glMultiTexCoord2i (GLenum target, GLint s, GLint t);
+GLAPI void APIENTRY glMultiTexCoord2iv (GLenum target, const GLint *v);
+GLAPI void APIENTRY glMultiTexCoord2s (GLenum target, GLshort s, GLshort t);
+GLAPI void APIENTRY glMultiTexCoord2sv (GLenum target, const GLshort *v);
+GLAPI void APIENTRY glMultiTexCoord3d (GLenum target, GLdouble s, GLdouble t, GLdouble r);
+GLAPI void APIENTRY glMultiTexCoord3dv (GLenum target, const GLdouble *v);
+GLAPI void APIENTRY glMultiTexCoord3f (GLenum target, GLfloat s, GLfloat t, GLfloat r);
+GLAPI void APIENTRY glMultiTexCoord3fv (GLenum target, const GLfloat *v);
+GLAPI void APIENTRY glMultiTexCoord3i (GLenum target, GLint s, GLint t, GLint r);
+GLAPI void APIENTRY glMultiTexCoord3iv (GLenum target, const GLint *v);
+GLAPI void APIENTRY glMultiTexCoord3s (GLenum target, GLshort s, GLshort t, GLshort r);
+GLAPI void APIENTRY glMultiTexCoord3sv (GLenum target, const GLshort *v);
+GLAPI void APIENTRY glMultiTexCoord4d (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q);
+GLAPI void APIENTRY glMultiTexCoord4dv (GLenum target, const GLdouble *v);
+GLAPI void APIENTRY glMultiTexCoord4f (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
+GLAPI void APIENTRY glMultiTexCoord4fv (GLenum target, const GLfloat *v);
+GLAPI void APIENTRY glMultiTexCoord4i (GLenum target, GLint s, GLint t, GLint r, GLint q);
+GLAPI void APIENTRY glMultiTexCoord4iv (GLenum target, const GLint *v);
+GLAPI void APIENTRY glMultiTexCoord4s (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q);
+GLAPI void APIENTRY glMultiTexCoord4sv (GLenum target, const GLshort *v);
+GLAPI void APIENTRY glLoadTransposeMatrixf (const GLfloat *m);
+GLAPI void APIENTRY glLoadTransposeMatrixd (const GLdouble *m);
+GLAPI void APIENTRY glMultTransposeMatrixf (const GLfloat *m);
+GLAPI void APIENTRY glMultTransposeMatrixd (const GLdouble *m);
+#endif
+#endif /* GL_VERSION_1_3 */
+
+#ifndef GL_VERSION_1_4
+#define GL_VERSION_1_4 1
+#define GL_BLEND_DST_RGB 0x80C8
+#define GL_BLEND_SRC_RGB 0x80C9
+#define GL_BLEND_DST_ALPHA 0x80CA
+#define GL_BLEND_SRC_ALPHA 0x80CB
+#define GL_POINT_FADE_THRESHOLD_SIZE 0x8128
+#define GL_DEPTH_COMPONENT16 0x81A5
+#define GL_DEPTH_COMPONENT24 0x81A6
+#define GL_DEPTH_COMPONENT32 0x81A7
+#define GL_MIRRORED_REPEAT 0x8370
+#define GL_MAX_TEXTURE_LOD_BIAS 0x84FD
+#define GL_TEXTURE_LOD_BIAS 0x8501
+#define GL_INCR_WRAP 0x8507
+#define GL_DECR_WRAP 0x8508
+#define GL_TEXTURE_DEPTH_SIZE 0x884A
+#define GL_TEXTURE_COMPARE_MODE 0x884C
+#define GL_TEXTURE_COMPARE_FUNC 0x884D
+#define GL_POINT_SIZE_MIN 0x8126
+#define GL_POINT_SIZE_MAX 0x8127
+#define GL_POINT_DISTANCE_ATTENUATION 0x8129
+#define GL_GENERATE_MIPMAP 0x8191
+#define GL_GENERATE_MIPMAP_HINT 0x8192
+#define GL_FOG_COORDINATE_SOURCE 0x8450
+#define GL_FOG_COORDINATE 0x8451
+#define GL_FRAGMENT_DEPTH 0x8452
+#define GL_CURRENT_FOG_COORDINATE 0x8453
+#define GL_FOG_COORDINATE_ARRAY_TYPE 0x8454
+#define GL_FOG_COORDINATE_ARRAY_STRIDE 0x8455
+#define GL_FOG_COORDINATE_ARRAY_POINTER 0x8456
+#define GL_FOG_COORDINATE_ARRAY 0x8457
+#define GL_COLOR_SUM 0x8458
+#define GL_CURRENT_SECONDARY_COLOR 0x8459
+#define GL_SECONDARY_COLOR_ARRAY_SIZE 0x845A
+#define GL_SECONDARY_COLOR_ARRAY_TYPE 0x845B
+#define GL_SECONDARY_COLOR_ARRAY_STRIDE 0x845C
+#define GL_SECONDARY_COLOR_ARRAY_POINTER 0x845D
+#define GL_SECONDARY_COLOR_ARRAY 0x845E
+#define GL_TEXTURE_FILTER_CONTROL 0x8500
+#define GL_DEPTH_TEXTURE_MODE 0x884B
+#define GL_COMPARE_R_TO_TEXTURE 0x884E
+#define GL_FUNC_ADD 0x8006
+#define GL_FUNC_SUBTRACT 0x800A
+#define GL_FUNC_REVERSE_SUBTRACT 0x800B
+#define GL_MIN 0x8007
+#define GL_MAX 0x8008
+#define GL_CONSTANT_COLOR 0x8001
+#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002
+#define GL_CONSTANT_ALPHA 0x8003
+#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004
+typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
+typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount);
+typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei drawcount);
+typedef void (APIENTRYP PFNGLPOINTPARAMETERFPROC) (GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLPOINTPARAMETERFVPROC) (GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLPOINTPARAMETERIPROC) (GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLPOINTPARAMETERIVPROC) (GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLFOGCOORDFPROC) (GLfloat coord);
+typedef void (APIENTRYP PFNGLFOGCOORDFVPROC) (const GLfloat *coord);
+typedef void (APIENTRYP PFNGLFOGCOORDDPROC) (GLdouble coord);
+typedef void (APIENTRYP PFNGLFOGCOORDDVPROC) (const GLdouble *coord);
+typedef void (APIENTRYP PFNGLFOGCOORDPOINTERPROC) (GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BPROC) (GLbyte red, GLbyte green, GLbyte blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVPROC) (const GLbyte *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DPROC) (GLdouble red, GLdouble green, GLdouble blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FPROC) (GLfloat red, GLfloat green, GLfloat blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IPROC) (GLint red, GLint green, GLint blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SPROC) (GLshort red, GLshort green, GLshort blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVPROC) (const GLshort *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBPROC) (GLubyte red, GLubyte green, GLubyte blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVPROC) (const GLubyte *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIPROC) (GLuint red, GLuint green, GLuint blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVPROC) (const GLuint *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USPROC) (GLushort red, GLushort green, GLushort blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVPROC) (const GLushort *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERPROC) (GLint size, GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLWINDOWPOS2DPROC) (GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2DVPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS2FPROC) (GLfloat x, GLfloat y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2FVPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS2IPROC) (GLint x, GLint y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2IVPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS2SPROC) (GLshort x, GLshort y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2SVPROC) (const GLshort *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3DPROC) (GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3DVPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3FPROC) (GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3FVPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3IPROC) (GLint x, GLint y, GLint z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3IVPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3SPROC) (GLshort x, GLshort y, GLshort z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3SVPROC) (const GLshort *v);
+typedef void (APIENTRYP PFNGLBLENDCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
+typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
+GLAPI void APIENTRY glMultiDrawArrays (GLenum mode, const GLint *first, const GLsizei *count, GLsizei drawcount);
+GLAPI void APIENTRY glMultiDrawElements (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei drawcount);
+GLAPI void APIENTRY glPointParameterf (GLenum pname, GLfloat param);
+GLAPI void APIENTRY glPointParameterfv (GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glPointParameteri (GLenum pname, GLint param);
+GLAPI void APIENTRY glPointParameteriv (GLenum pname, const GLint *params);
+GLAPI void APIENTRY glFogCoordf (GLfloat coord);
+GLAPI void APIENTRY glFogCoordfv (const GLfloat *coord);
+GLAPI void APIENTRY glFogCoordd (GLdouble coord);
+GLAPI void APIENTRY glFogCoorddv (const GLdouble *coord);
+GLAPI void APIENTRY glFogCoordPointer (GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glSecondaryColor3b (GLbyte red, GLbyte green, GLbyte blue);
+GLAPI void APIENTRY glSecondaryColor3bv (const GLbyte *v);
+GLAPI void APIENTRY glSecondaryColor3d (GLdouble red, GLdouble green, GLdouble blue);
+GLAPI void APIENTRY glSecondaryColor3dv (const GLdouble *v);
+GLAPI void APIENTRY glSecondaryColor3f (GLfloat red, GLfloat green, GLfloat blue);
+GLAPI void APIENTRY glSecondaryColor3fv (const GLfloat *v);
+GLAPI void APIENTRY glSecondaryColor3i (GLint red, GLint green, GLint blue);
+GLAPI void APIENTRY glSecondaryColor3iv (const GLint *v);
+GLAPI void APIENTRY glSecondaryColor3s (GLshort red, GLshort green, GLshort blue);
+GLAPI void APIENTRY glSecondaryColor3sv (const GLshort *v);
+GLAPI void APIENTRY glSecondaryColor3ub (GLubyte red, GLubyte green, GLubyte blue);
+GLAPI void APIENTRY glSecondaryColor3ubv (const GLubyte *v);
+GLAPI void APIENTRY glSecondaryColor3ui (GLuint red, GLuint green, GLuint blue);
+GLAPI void APIENTRY glSecondaryColor3uiv (const GLuint *v);
+GLAPI void APIENTRY glSecondaryColor3us (GLushort red, GLushort green, GLushort blue);
+GLAPI void APIENTRY glSecondaryColor3usv (const GLushort *v);
+GLAPI void APIENTRY glSecondaryColorPointer (GLint size, GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glWindowPos2d (GLdouble x, GLdouble y);
+GLAPI void APIENTRY glWindowPos2dv (const GLdouble *v);
+GLAPI void APIENTRY glWindowPos2f (GLfloat x, GLfloat y);
+GLAPI void APIENTRY glWindowPos2fv (const GLfloat *v);
+GLAPI void APIENTRY glWindowPos2i (GLint x, GLint y);
+GLAPI void APIENTRY glWindowPos2iv (const GLint *v);
+GLAPI void APIENTRY glWindowPos2s (GLshort x, GLshort y);
+GLAPI void APIENTRY glWindowPos2sv (const GLshort *v);
+GLAPI void APIENTRY glWindowPos3d (GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glWindowPos3dv (const GLdouble *v);
+GLAPI void APIENTRY glWindowPos3f (GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glWindowPos3fv (const GLfloat *v);
+GLAPI void APIENTRY glWindowPos3i (GLint x, GLint y, GLint z);
+GLAPI void APIENTRY glWindowPos3iv (const GLint *v);
+GLAPI void APIENTRY glWindowPos3s (GLshort x, GLshort y, GLshort z);
+GLAPI void APIENTRY glWindowPos3sv (const GLshort *v);
+GLAPI void APIENTRY glBlendColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
+GLAPI void APIENTRY glBlendEquation (GLenum mode);
+#endif
+#endif /* GL_VERSION_1_4 */
+
+#ifndef GL_VERSION_1_5
+#define GL_VERSION_1_5 1
+#include <stddef.h>
+#ifdef __MACOSX__
+typedef long GLsizeiptr;
+typedef long GLintptr;
+#else
+typedef ptrdiff_t GLsizeiptr;
+typedef ptrdiff_t GLintptr;
+#endif
+#define GL_BUFFER_SIZE 0x8764
+#define GL_BUFFER_USAGE 0x8765
+#define GL_QUERY_COUNTER_BITS 0x8864
+#define GL_CURRENT_QUERY 0x8865
+#define GL_QUERY_RESULT 0x8866
+#define GL_QUERY_RESULT_AVAILABLE 0x8867
+#define GL_ARRAY_BUFFER 0x8892
+#define GL_ELEMENT_ARRAY_BUFFER 0x8893
+#define GL_ARRAY_BUFFER_BINDING 0x8894
+#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895
+#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F
+#define GL_READ_ONLY 0x88B8
+#define GL_WRITE_ONLY 0x88B9
+#define GL_READ_WRITE 0x88BA
+#define GL_BUFFER_ACCESS 0x88BB
+#define GL_BUFFER_MAPPED 0x88BC
+#define GL_BUFFER_MAP_POINTER 0x88BD
+#define GL_STREAM_DRAW 0x88E0
+#define GL_STREAM_READ 0x88E1
+#define GL_STREAM_COPY 0x88E2
+#define GL_STATIC_DRAW 0x88E4
+#define GL_STATIC_READ 0x88E5
+#define GL_STATIC_COPY 0x88E6
+#define GL_DYNAMIC_DRAW 0x88E8
+#define GL_DYNAMIC_READ 0x88E9
+#define GL_DYNAMIC_COPY 0x88EA
+#define GL_SAMPLES_PASSED 0x8914
+#define GL_SRC1_ALPHA 0x8589
+#define GL_VERTEX_ARRAY_BUFFER_BINDING 0x8896
+#define GL_NORMAL_ARRAY_BUFFER_BINDING 0x8897
+#define GL_COLOR_ARRAY_BUFFER_BINDING 0x8898
+#define GL_INDEX_ARRAY_BUFFER_BINDING 0x8899
+#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING 0x889A
+#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING 0x889B
+#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING 0x889C
+#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING 0x889D
+#define GL_WEIGHT_ARRAY_BUFFER_BINDING 0x889E
+#define GL_FOG_COORD_SRC 0x8450
+#define GL_FOG_COORD 0x8451
+#define GL_CURRENT_FOG_COORD 0x8453
+#define GL_FOG_COORD_ARRAY_TYPE 0x8454
+#define GL_FOG_COORD_ARRAY_STRIDE 0x8455
+#define GL_FOG_COORD_ARRAY_POINTER 0x8456
+#define GL_FOG_COORD_ARRAY 0x8457
+#define GL_FOG_COORD_ARRAY_BUFFER_BINDING 0x889D
+#define GL_SRC0_RGB 0x8580
+#define GL_SRC1_RGB 0x8581
+#define GL_SRC2_RGB 0x8582
+#define GL_SRC0_ALPHA 0x8588
+#define GL_SRC2_ALPHA 0x858A
+typedef void (APIENTRYP PFNGLGENQUERIESPROC) (GLsizei n, GLuint *ids);
+typedef void (APIENTRYP PFNGLDELETEQUERIESPROC) (GLsizei n, const GLuint *ids);
+typedef GLboolean (APIENTRYP PFNGLISQUERYPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLBEGINQUERYPROC) (GLenum target, GLuint id);
+typedef void (APIENTRYP PFNGLENDQUERYPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLGETQUERYIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVPROC) (GLuint id, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVPROC) (GLuint id, GLenum pname, GLuint *params);
+typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer);
+typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
+typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
+typedef GLboolean (APIENTRYP PFNGLISBUFFERPROC) (GLuint buffer);
+typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
+typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
+typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, void *data);
+typedef void *(APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, GLenum access);
+typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVPROC) (GLenum target, GLenum pname, void **params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGenQueries (GLsizei n, GLuint *ids);
+GLAPI void APIENTRY glDeleteQueries (GLsizei n, const GLuint *ids);
+GLAPI GLboolean APIENTRY glIsQuery (GLuint id);
+GLAPI void APIENTRY glBeginQuery (GLenum target, GLuint id);
+GLAPI void APIENTRY glEndQuery (GLenum target);
+GLAPI void APIENTRY glGetQueryiv (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetQueryObjectiv (GLuint id, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetQueryObjectuiv (GLuint id, GLenum pname, GLuint *params);
+GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer);
+GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers);
+GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers);
+GLAPI GLboolean APIENTRY glIsBuffer (GLuint buffer);
+GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
+GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
+GLAPI void APIENTRY glGetBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, void *data);
+GLAPI void *APIENTRY glMapBuffer (GLenum target, GLenum access);
+GLAPI GLboolean APIENTRY glUnmapBuffer (GLenum target);
+GLAPI void APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetBufferPointerv (GLenum target, GLenum pname, void **params);
+#endif
+#endif /* GL_VERSION_1_5 */
+
+#ifndef GL_VERSION_2_0
+#define GL_VERSION_2_0 1
+typedef char GLchar;
+#define GL_BLEND_EQUATION_RGB 0x8009
+#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
+#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
+#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624
+#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625
+#define GL_CURRENT_VERTEX_ATTRIB 0x8626
+#define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642
+#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645
+#define GL_STENCIL_BACK_FUNC 0x8800
+#define GL_STENCIL_BACK_FAIL 0x8801
+#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802
+#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803
+#define GL_MAX_DRAW_BUFFERS 0x8824
+#define GL_DRAW_BUFFER0 0x8825
+#define GL_DRAW_BUFFER1 0x8826
+#define GL_DRAW_BUFFER2 0x8827
+#define GL_DRAW_BUFFER3 0x8828
+#define GL_DRAW_BUFFER4 0x8829
+#define GL_DRAW_BUFFER5 0x882A
+#define GL_DRAW_BUFFER6 0x882B
+#define GL_DRAW_BUFFER7 0x882C
+#define GL_DRAW_BUFFER8 0x882D
+#define GL_DRAW_BUFFER9 0x882E
+#define GL_DRAW_BUFFER10 0x882F
+#define GL_DRAW_BUFFER11 0x8830
+#define GL_DRAW_BUFFER12 0x8831
+#define GL_DRAW_BUFFER13 0x8832
+#define GL_DRAW_BUFFER14 0x8833
+#define GL_DRAW_BUFFER15 0x8834
+#define GL_BLEND_EQUATION_ALPHA 0x883D
+#define GL_MAX_VERTEX_ATTRIBS 0x8869
+#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A
+#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872
+#define GL_FRAGMENT_SHADER 0x8B30
+#define GL_VERTEX_SHADER 0x8B31
+#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49
+#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A
+#define GL_MAX_VARYING_FLOATS 0x8B4B
+#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C
+#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D
+#define GL_SHADER_TYPE 0x8B4F
+#define GL_FLOAT_VEC2 0x8B50
+#define GL_FLOAT_VEC3 0x8B51
+#define GL_FLOAT_VEC4 0x8B52
+#define GL_INT_VEC2 0x8B53
+#define GL_INT_VEC3 0x8B54
+#define GL_INT_VEC4 0x8B55
+#define GL_BOOL 0x8B56
+#define GL_BOOL_VEC2 0x8B57
+#define GL_BOOL_VEC3 0x8B58
+#define GL_BOOL_VEC4 0x8B59
+#define GL_FLOAT_MAT2 0x8B5A
+#define GL_FLOAT_MAT3 0x8B5B
+#define GL_FLOAT_MAT4 0x8B5C
+#define GL_SAMPLER_1D 0x8B5D
+#define GL_SAMPLER_2D 0x8B5E
+#define GL_SAMPLER_3D 0x8B5F
+#define GL_SAMPLER_CUBE 0x8B60
+#define GL_SAMPLER_1D_SHADOW 0x8B61
+#define GL_SAMPLER_2D_SHADOW 0x8B62
+#define GL_DELETE_STATUS 0x8B80
+#define GL_COMPILE_STATUS 0x8B81
+#define GL_LINK_STATUS 0x8B82
+#define GL_VALIDATE_STATUS 0x8B83
+#define GL_INFO_LOG_LENGTH 0x8B84
+#define GL_ATTACHED_SHADERS 0x8B85
+#define GL_ACTIVE_UNIFORMS 0x8B86
+#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87
+#define GL_SHADER_SOURCE_LENGTH 0x8B88
+#define GL_ACTIVE_ATTRIBUTES 0x8B89
+#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A
+#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B
+#define GL_SHADING_LANGUAGE_VERSION 0x8B8C
+#define GL_CURRENT_PROGRAM 0x8B8D
+#define GL_POINT_SPRITE_COORD_ORIGIN 0x8CA0
+#define GL_LOWER_LEFT 0x8CA1
+#define GL_UPPER_LEFT 0x8CA2
+#define GL_STENCIL_BACK_REF 0x8CA3
+#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4
+#define GL_STENCIL_BACK_WRITEMASK 0x8CA5
+#define GL_VERTEX_PROGRAM_TWO_SIDE 0x8643
+#define GL_POINT_SPRITE 0x8861
+#define GL_COORD_REPLACE 0x8862
+#define GL_MAX_TEXTURE_COORDS 0x8871
+typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha);
+typedef void (APIENTRYP PFNGLDRAWBUFFERSPROC) (GLsizei n, const GLenum *bufs);
+typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
+typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEPROC) (GLenum face, GLenum func, GLint ref, GLuint mask);
+typedef void (APIENTRYP PFNGLSTENCILMASKSEPARATEPROC) (GLenum face, GLuint mask);
+typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
+typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar *name);
+typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader);
+typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void);
+typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type);
+typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program);
+typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader);
+typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader);
+typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index);
+typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index);
+typedef void (APIENTRYP PFNGLGETACTIVEATTRIBPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
+typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
+typedef void (APIENTRYP PFNGLGETATTACHEDSHADERSPROC) (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders);
+typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name);
+typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+typedef void (APIENTRYP PFNGLGETSHADERSOURCEPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source);
+typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name);
+typedef void (APIENTRYP PFNGLGETUNIFORMFVPROC) (GLuint program, GLint location, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETUNIFORMIVPROC) (GLuint program, GLint location, GLint *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVPROC) (GLuint index, GLenum pname, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVPROC) (GLuint index, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, void **pointer);
+typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program);
+typedef GLboolean (APIENTRYP PFNGLISSHADERPROC) (GLuint shader);
+typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program);
+typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
+typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program);
+typedef void (APIENTRYP PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0);
+typedef void (APIENTRYP PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, GLfloat v1);
+typedef void (APIENTRYP PFNGLUNIFORM3FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+typedef void (APIENTRYP PFNGLUNIFORM4FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0);
+typedef void (APIENTRYP PFNGLUNIFORM2IPROC) (GLint location, GLint v0, GLint v1);
+typedef void (APIENTRYP PFNGLUNIFORM3IPROC) (GLint location, GLint v0, GLint v1, GLint v2);
+typedef void (APIENTRYP PFNGLUNIFORM4IPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+typedef void (APIENTRYP PFNGLUNIFORM1FVPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORM2FVPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORM3FVPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORM4FVPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORM1IVPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLUNIFORM2IVPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLUNIFORM3IVPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLUNIFORM4IVPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPROC) (GLuint program);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1DPROC) (GLuint index, GLdouble x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1FPROC) (GLuint index, GLfloat x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1SPROC) (GLuint index, GLshort x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2DPROC) (GLuint index, GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2FPROC) (GLuint index, GLfloat x, GLfloat y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2SPROC) (GLuint index, GLshort x, GLshort y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3SPROC) (GLuint index, GLshort x, GLshort y, GLshort z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVPROC) (GLuint index, const GLbyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVPROC) (GLuint index, const GLubyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVPROC) (GLuint index, const GLushort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVPROC) (GLuint index, const GLbyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4SPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVPROC) (GLuint index, const GLubyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVPROC) (GLuint index, const GLushort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha);
+GLAPI void APIENTRY glDrawBuffers (GLsizei n, const GLenum *bufs);
+GLAPI void APIENTRY glStencilOpSeparate (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
+GLAPI void APIENTRY glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask);
+GLAPI void APIENTRY glStencilMaskSeparate (GLenum face, GLuint mask);
+GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader);
+GLAPI void APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar *name);
+GLAPI void APIENTRY glCompileShader (GLuint shader);
+GLAPI GLuint APIENTRY glCreateProgram (void);
+GLAPI GLuint APIENTRY glCreateShader (GLenum type);
+GLAPI void APIENTRY glDeleteProgram (GLuint program);
+GLAPI void APIENTRY glDeleteShader (GLuint shader);
+GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader);
+GLAPI void APIENTRY glDisableVertexAttribArray (GLuint index);
+GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index);
+GLAPI void APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
+GLAPI void APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
+GLAPI void APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders);
+GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name);
+GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+GLAPI void APIENTRY glGetShaderSource (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source);
+GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name);
+GLAPI void APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat *params);
+GLAPI void APIENTRY glGetUniformiv (GLuint program, GLint location, GLint *params);
+GLAPI void APIENTRY glGetVertexAttribdv (GLuint index, GLenum pname, GLdouble *params);
+GLAPI void APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, void **pointer);
+GLAPI GLboolean APIENTRY glIsProgram (GLuint program);
+GLAPI GLboolean APIENTRY glIsShader (GLuint shader);
+GLAPI void APIENTRY glLinkProgram (GLuint program);
+GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
+GLAPI void APIENTRY glUseProgram (GLuint program);
+GLAPI void APIENTRY glUniform1f (GLint location, GLfloat v0);
+GLAPI void APIENTRY glUniform2f (GLint location, GLfloat v0, GLfloat v1);
+GLAPI void APIENTRY glUniform3f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+GLAPI void APIENTRY glUniform4f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+GLAPI void APIENTRY glUniform1i (GLint location, GLint v0);
+GLAPI void APIENTRY glUniform2i (GLint location, GLint v0, GLint v1);
+GLAPI void APIENTRY glUniform3i (GLint location, GLint v0, GLint v1, GLint v2);
+GLAPI void APIENTRY glUniform4i (GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+GLAPI void APIENTRY glUniform1fv (GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glUniform2fv (GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glUniform1iv (GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glValidateProgram (GLuint program);
+GLAPI void APIENTRY glVertexAttrib1d (GLuint index, GLdouble x);
+GLAPI void APIENTRY glVertexAttrib1dv (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib1f (GLuint index, GLfloat x);
+GLAPI void APIENTRY glVertexAttrib1fv (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib1s (GLuint index, GLshort x);
+GLAPI void APIENTRY glVertexAttrib1sv (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib2d (GLuint index, GLdouble x, GLdouble y);
+GLAPI void APIENTRY glVertexAttrib2dv (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib2f (GLuint index, GLfloat x, GLfloat y);
+GLAPI void APIENTRY glVertexAttrib2fv (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib2s (GLuint index, GLshort x, GLshort y);
+GLAPI void APIENTRY glVertexAttrib2sv (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib3d (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glVertexAttrib3dv (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib3f (GLuint index, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glVertexAttrib3fv (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib3s (GLuint index, GLshort x, GLshort y, GLshort z);
+GLAPI void APIENTRY glVertexAttrib3sv (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib4Nbv (GLuint index, const GLbyte *v);
+GLAPI void APIENTRY glVertexAttrib4Niv (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttrib4Nsv (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib4Nub (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w);
+GLAPI void APIENTRY glVertexAttrib4Nubv (GLuint index, const GLubyte *v);
+GLAPI void APIENTRY glVertexAttrib4Nuiv (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttrib4Nusv (GLuint index, const GLushort *v);
+GLAPI void APIENTRY glVertexAttrib4bv (GLuint index, const GLbyte *v);
+GLAPI void APIENTRY glVertexAttrib4d (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glVertexAttrib4dv (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib4f (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glVertexAttrib4fv (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib4iv (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttrib4s (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w);
+GLAPI void APIENTRY glVertexAttrib4sv (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib4ubv (GLuint index, const GLubyte *v);
+GLAPI void APIENTRY glVertexAttrib4uiv (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttrib4usv (GLuint index, const GLushort *v);
+GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
+#endif
+#endif /* GL_VERSION_2_0 */
+
+#ifndef GL_VERSION_2_1
+#define GL_VERSION_2_1 1
+#define GL_PIXEL_PACK_BUFFER 0x88EB
+#define GL_PIXEL_UNPACK_BUFFER 0x88EC
+#define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED
+#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF
+#define GL_FLOAT_MAT2x3 0x8B65
+#define GL_FLOAT_MAT2x4 0x8B66
+#define GL_FLOAT_MAT3x2 0x8B67
+#define GL_FLOAT_MAT3x4 0x8B68
+#define GL_FLOAT_MAT4x2 0x8B69
+#define GL_FLOAT_MAT4x3 0x8B6A
+#define GL_SRGB 0x8C40
+#define GL_SRGB8 0x8C41
+#define GL_SRGB_ALPHA 0x8C42
+#define GL_SRGB8_ALPHA8 0x8C43
+#define GL_COMPRESSED_SRGB 0x8C48
+#define GL_COMPRESSED_SRGB_ALPHA 0x8C49
+#define GL_CURRENT_RASTER_SECONDARY_COLOR 0x845F
+#define GL_SLUMINANCE_ALPHA 0x8C44
+#define GL_SLUMINANCE8_ALPHA8 0x8C45
+#define GL_SLUMINANCE 0x8C46
+#define GL_SLUMINANCE8 0x8C47
+#define GL_COMPRESSED_SLUMINANCE 0x8C4A
+#define GL_COMPRESSED_SLUMINANCE_ALPHA 0x8C4B
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glUniformMatrix2x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glUniformMatrix3x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glUniformMatrix2x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glUniformMatrix4x2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glUniformMatrix3x4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glUniformMatrix4x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+#endif
+#endif /* GL_VERSION_2_1 */
+
+#ifndef GL_VERSION_3_0
+#define GL_VERSION_3_0 1
+typedef unsigned short GLhalf;
+#define GL_COMPARE_REF_TO_TEXTURE 0x884E
+#define GL_CLIP_DISTANCE0 0x3000
+#define GL_CLIP_DISTANCE1 0x3001
+#define GL_CLIP_DISTANCE2 0x3002
+#define GL_CLIP_DISTANCE3 0x3003
+#define GL_CLIP_DISTANCE4 0x3004
+#define GL_CLIP_DISTANCE5 0x3005
+#define GL_CLIP_DISTANCE6 0x3006
+#define GL_CLIP_DISTANCE7 0x3007
+#define GL_MAX_CLIP_DISTANCES 0x0D32
+#define GL_MAJOR_VERSION 0x821B
+#define GL_MINOR_VERSION 0x821C
+#define GL_NUM_EXTENSIONS 0x821D
+#define GL_CONTEXT_FLAGS 0x821E
+#define GL_COMPRESSED_RED 0x8225
+#define GL_COMPRESSED_RG 0x8226
+#define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x00000001
+#define GL_RGBA32F 0x8814
+#define GL_RGB32F 0x8815
+#define GL_RGBA16F 0x881A
+#define GL_RGB16F 0x881B
+#define GL_VERTEX_ATTRIB_ARRAY_INTEGER 0x88FD
+#define GL_MAX_ARRAY_TEXTURE_LAYERS 0x88FF
+#define GL_MIN_PROGRAM_TEXEL_OFFSET 0x8904
+#define GL_MAX_PROGRAM_TEXEL_OFFSET 0x8905
+#define GL_CLAMP_READ_COLOR 0x891C
+#define GL_FIXED_ONLY 0x891D
+#define GL_MAX_VARYING_COMPONENTS 0x8B4B
+#define GL_TEXTURE_1D_ARRAY 0x8C18
+#define GL_PROXY_TEXTURE_1D_ARRAY 0x8C19
+#define GL_TEXTURE_2D_ARRAY 0x8C1A
+#define GL_PROXY_TEXTURE_2D_ARRAY 0x8C1B
+#define GL_TEXTURE_BINDING_1D_ARRAY 0x8C1C
+#define GL_TEXTURE_BINDING_2D_ARRAY 0x8C1D
+#define GL_R11F_G11F_B10F 0x8C3A
+#define GL_UNSIGNED_INT_10F_11F_11F_REV 0x8C3B
+#define GL_RGB9_E5 0x8C3D
+#define GL_UNSIGNED_INT_5_9_9_9_REV 0x8C3E
+#define GL_TEXTURE_SHARED_SIZE 0x8C3F
+#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH 0x8C76
+#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE 0x8C7F
+#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS 0x8C80
+#define GL_TRANSFORM_FEEDBACK_VARYINGS 0x8C83
+#define GL_TRANSFORM_FEEDBACK_BUFFER_START 0x8C84
+#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE 0x8C85
+#define GL_PRIMITIVES_GENERATED 0x8C87
+#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN 0x8C88
+#define GL_RASTERIZER_DISCARD 0x8C89
+#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS 0x8C8A
+#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS 0x8C8B
+#define GL_INTERLEAVED_ATTRIBS 0x8C8C
+#define GL_SEPARATE_ATTRIBS 0x8C8D
+#define GL_TRANSFORM_FEEDBACK_BUFFER 0x8C8E
+#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING 0x8C8F
+#define GL_RGBA32UI 0x8D70
+#define GL_RGB32UI 0x8D71
+#define GL_RGBA16UI 0x8D76
+#define GL_RGB16UI 0x8D77
+#define GL_RGBA8UI 0x8D7C
+#define GL_RGB8UI 0x8D7D
+#define GL_RGBA32I 0x8D82
+#define GL_RGB32I 0x8D83
+#define GL_RGBA16I 0x8D88
+#define GL_RGB16I 0x8D89
+#define GL_RGBA8I 0x8D8E
+#define GL_RGB8I 0x8D8F
+#define GL_RED_INTEGER 0x8D94
+#define GL_GREEN_INTEGER 0x8D95
+#define GL_BLUE_INTEGER 0x8D96
+#define GL_RGB_INTEGER 0x8D98
+#define GL_RGBA_INTEGER 0x8D99
+#define GL_BGR_INTEGER 0x8D9A
+#define GL_BGRA_INTEGER 0x8D9B
+#define GL_SAMPLER_1D_ARRAY 0x8DC0
+#define GL_SAMPLER_2D_ARRAY 0x8DC1
+#define GL_SAMPLER_1D_ARRAY_SHADOW 0x8DC3
+#define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4
+#define GL_SAMPLER_CUBE_SHADOW 0x8DC5
+#define GL_UNSIGNED_INT_VEC2 0x8DC6
+#define GL_UNSIGNED_INT_VEC3 0x8DC7
+#define GL_UNSIGNED_INT_VEC4 0x8DC8
+#define GL_INT_SAMPLER_1D 0x8DC9
+#define GL_INT_SAMPLER_2D 0x8DCA
+#define GL_INT_SAMPLER_3D 0x8DCB
+#define GL_INT_SAMPLER_CUBE 0x8DCC
+#define GL_INT_SAMPLER_1D_ARRAY 0x8DCE
+#define GL_INT_SAMPLER_2D_ARRAY 0x8DCF
+#define GL_UNSIGNED_INT_SAMPLER_1D 0x8DD1
+#define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2
+#define GL_UNSIGNED_INT_SAMPLER_3D 0x8DD3
+#define GL_UNSIGNED_INT_SAMPLER_CUBE 0x8DD4
+#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY 0x8DD6
+#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7
+#define GL_QUERY_WAIT 0x8E13
+#define GL_QUERY_NO_WAIT 0x8E14
+#define GL_QUERY_BY_REGION_WAIT 0x8E15
+#define GL_QUERY_BY_REGION_NO_WAIT 0x8E16
+#define GL_BUFFER_ACCESS_FLAGS 0x911F
+#define GL_BUFFER_MAP_LENGTH 0x9120
+#define GL_BUFFER_MAP_OFFSET 0x9121
+#define GL_DEPTH_COMPONENT32F 0x8CAC
+#define GL_DEPTH32F_STENCIL8 0x8CAD
+#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD
+#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506
+#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING 0x8210
+#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE 0x8211
+#define GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE 0x8212
+#define GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE 0x8213
+#define GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE 0x8214
+#define GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE 0x8215
+#define GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE 0x8216
+#define GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE 0x8217
+#define GL_FRAMEBUFFER_DEFAULT 0x8218
+#define GL_FRAMEBUFFER_UNDEFINED 0x8219
+#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A
+#define GL_MAX_RENDERBUFFER_SIZE 0x84E8
+#define GL_DEPTH_STENCIL 0x84F9
+#define GL_UNSIGNED_INT_24_8 0x84FA
+#define GL_DEPTH24_STENCIL8 0x88F0
+#define GL_TEXTURE_STENCIL_SIZE 0x88F1
+#define GL_TEXTURE_RED_TYPE 0x8C10
+#define GL_TEXTURE_GREEN_TYPE 0x8C11
+#define GL_TEXTURE_BLUE_TYPE 0x8C12
+#define GL_TEXTURE_ALPHA_TYPE 0x8C13
+#define GL_TEXTURE_DEPTH_TYPE 0x8C16
+#define GL_UNSIGNED_NORMALIZED 0x8C17
+#define GL_FRAMEBUFFER_BINDING 0x8CA6
+#define GL_DRAW_FRAMEBUFFER_BINDING 0x8CA6
+#define GL_RENDERBUFFER_BINDING 0x8CA7
+#define GL_READ_FRAMEBUFFER 0x8CA8
+#define GL_DRAW_FRAMEBUFFER 0x8CA9
+#define GL_READ_FRAMEBUFFER_BINDING 0x8CAA
+#define GL_RENDERBUFFER_SAMPLES 0x8CAB
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER 0x8CD4
+#define GL_FRAMEBUFFER_COMPLETE 0x8CD5
+#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6
+#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7
+#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB
+#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC
+#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD
+#define GL_MAX_COLOR_ATTACHMENTS 0x8CDF
+#define GL_COLOR_ATTACHMENT0 0x8CE0
+#define GL_COLOR_ATTACHMENT1 0x8CE1
+#define GL_COLOR_ATTACHMENT2 0x8CE2
+#define GL_COLOR_ATTACHMENT3 0x8CE3
+#define GL_COLOR_ATTACHMENT4 0x8CE4
+#define GL_COLOR_ATTACHMENT5 0x8CE5
+#define GL_COLOR_ATTACHMENT6 0x8CE6
+#define GL_COLOR_ATTACHMENT7 0x8CE7
+#define GL_COLOR_ATTACHMENT8 0x8CE8
+#define GL_COLOR_ATTACHMENT9 0x8CE9
+#define GL_COLOR_ATTACHMENT10 0x8CEA
+#define GL_COLOR_ATTACHMENT11 0x8CEB
+#define GL_COLOR_ATTACHMENT12 0x8CEC
+#define GL_COLOR_ATTACHMENT13 0x8CED
+#define GL_COLOR_ATTACHMENT14 0x8CEE
+#define GL_COLOR_ATTACHMENT15 0x8CEF
+#define GL_DEPTH_ATTACHMENT 0x8D00
+#define GL_STENCIL_ATTACHMENT 0x8D20
+#define GL_FRAMEBUFFER 0x8D40
+#define GL_RENDERBUFFER 0x8D41
+#define GL_RENDERBUFFER_WIDTH 0x8D42
+#define GL_RENDERBUFFER_HEIGHT 0x8D43
+#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44
+#define GL_STENCIL_INDEX1 0x8D46
+#define GL_STENCIL_INDEX4 0x8D47
+#define GL_STENCIL_INDEX8 0x8D48
+#define GL_STENCIL_INDEX16 0x8D49
+#define GL_RENDERBUFFER_RED_SIZE 0x8D50
+#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51
+#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52
+#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53
+#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54
+#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56
+#define GL_MAX_SAMPLES 0x8D57
+#define GL_INDEX 0x8222
+#define GL_TEXTURE_LUMINANCE_TYPE 0x8C14
+#define GL_TEXTURE_INTENSITY_TYPE 0x8C15
+#define GL_FRAMEBUFFER_SRGB 0x8DB9
+#define GL_HALF_FLOAT 0x140B
+#define GL_MAP_READ_BIT 0x0001
+#define GL_MAP_WRITE_BIT 0x0002
+#define GL_MAP_INVALIDATE_RANGE_BIT 0x0004
+#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008
+#define GL_MAP_FLUSH_EXPLICIT_BIT 0x0010
+#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020
+#define GL_COMPRESSED_RED_RGTC1 0x8DBB
+#define GL_COMPRESSED_SIGNED_RED_RGTC1 0x8DBC
+#define GL_COMPRESSED_RG_RGTC2 0x8DBD
+#define GL_COMPRESSED_SIGNED_RG_RGTC2 0x8DBE
+#define GL_RG 0x8227
+#define GL_RG_INTEGER 0x8228
+#define GL_R8 0x8229
+#define GL_R16 0x822A
+#define GL_RG8 0x822B
+#define GL_RG16 0x822C
+#define GL_R16F 0x822D
+#define GL_R32F 0x822E
+#define GL_RG16F 0x822F
+#define GL_RG32F 0x8230
+#define GL_R8I 0x8231
+#define GL_R8UI 0x8232
+#define GL_R16I 0x8233
+#define GL_R16UI 0x8234
+#define GL_R32I 0x8235
+#define GL_R32UI 0x8236
+#define GL_RG8I 0x8237
+#define GL_RG8UI 0x8238
+#define GL_RG16I 0x8239
+#define GL_RG16UI 0x823A
+#define GL_RG32I 0x823B
+#define GL_RG32UI 0x823C
+#define GL_VERTEX_ARRAY_BINDING 0x85B5
+#define GL_CLAMP_VERTEX_COLOR 0x891A
+#define GL_CLAMP_FRAGMENT_COLOR 0x891B
+#define GL_ALPHA_INTEGER 0x8D97
+typedef void (APIENTRYP PFNGLCOLORMASKIPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a);
+typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data);
+typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data);
+typedef void (APIENTRYP PFNGLENABLEIPROC) (GLenum target, GLuint index);
+typedef void (APIENTRYP PFNGLDISABLEIPROC) (GLenum target, GLuint index);
+typedef GLboolean (APIENTRYP PFNGLISENABLEDIPROC) (GLenum target, GLuint index);
+typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKPROC) (GLenum primitiveMode);
+typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKPROC) (void);
+typedef void (APIENTRYP PFNGLBINDBUFFERRANGEPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size);
+typedef void (APIENTRYP PFNGLBINDBUFFERBASEPROC) (GLenum target, GLuint index, GLuint buffer);
+typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSPROC) (GLuint program, GLsizei count, const GLchar *const*varyings, GLenum bufferMode);
+typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name);
+typedef void (APIENTRYP PFNGLCLAMPCOLORPROC) (GLenum target, GLenum clamp);
+typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERPROC) (GLuint id, GLenum mode);
+typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERPROC) (void);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVPROC) (GLuint index, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVPROC) (GLuint index, GLenum pname, GLuint *params);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IPROC) (GLuint index, GLint x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IPROC) (GLuint index, GLint x, GLint y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IPROC) (GLuint index, GLint x, GLint y, GLint z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IPROC) (GLuint index, GLint x, GLint y, GLint z, GLint w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIPROC) (GLuint index, GLuint x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIPROC) (GLuint index, GLuint x, GLuint y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVPROC) (GLuint index, const GLbyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVPROC) (GLuint index, const GLubyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVPROC) (GLuint index, const GLushort *v);
+typedef void (APIENTRYP PFNGLGETUNIFORMUIVPROC) (GLuint program, GLint location, GLuint *params);
+typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONPROC) (GLuint program, GLuint color, const GLchar *name);
+typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONPROC) (GLuint program, const GLchar *name);
+typedef void (APIENTRYP PFNGLUNIFORM1UIPROC) (GLint location, GLuint v0);
+typedef void (APIENTRYP PFNGLUNIFORM2UIPROC) (GLint location, GLuint v0, GLuint v1);
+typedef void (APIENTRYP PFNGLUNIFORM3UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2);
+typedef void (APIENTRYP PFNGLUNIFORM4UIPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+typedef void (APIENTRYP PFNGLUNIFORM1UIVPROC) (GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLUNIFORM2UIVPROC) (GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLUNIFORM3UIVPROC) (GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLUNIFORM4UIVPROC) (GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, const GLuint *params);
+typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVPROC) (GLenum target, GLenum pname, GLuint *params);
+typedef void (APIENTRYP PFNGLCLEARBUFFERIVPROC) (GLenum buffer, GLint drawbuffer, const GLint *value);
+typedef void (APIENTRYP PFNGLCLEARBUFFERUIVPROC) (GLenum buffer, GLint drawbuffer, const GLuint *value);
+typedef void (APIENTRYP PFNGLCLEARBUFFERFVPROC) (GLenum buffer, GLint drawbuffer, const GLfloat *value);
+typedef void (APIENTRYP PFNGLCLEARBUFFERFIPROC) (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil);
+typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index);
+typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFERPROC) (GLuint renderbuffer);
+typedef void (APIENTRYP PFNGLBINDRENDERBUFFERPROC) (GLenum target, GLuint renderbuffer);
+typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSPROC) (GLsizei n, const GLuint *renderbuffers);
+typedef void (APIENTRYP PFNGLGENRENDERBUFFERSPROC) (GLsizei n, GLuint *renderbuffers);
+typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFERPROC) (GLuint framebuffer);
+typedef void (APIENTRYP PFNGLBINDFRAMEBUFFERPROC) (GLenum target, GLuint framebuffer);
+typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSPROC) (GLsizei n, const GLuint *framebuffers);
+typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSPROC) (GLsizei n, GLuint *framebuffers);
+typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFERPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
+typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGENERATEMIPMAPPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLBLITFRAMEBUFFERPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer);
+typedef void *(APIENTRYP PFNGLMAPBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access);
+typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEPROC) (GLenum target, GLintptr offset, GLsizeiptr length);
+typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array);
+typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays);
+typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays);
+typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYPROC) (GLuint array);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glColorMaski (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a);
+GLAPI void APIENTRY glGetBooleani_v (GLenum target, GLuint index, GLboolean *data);
+GLAPI void APIENTRY glGetIntegeri_v (GLenum target, GLuint index, GLint *data);
+GLAPI void APIENTRY glEnablei (GLenum target, GLuint index);
+GLAPI void APIENTRY glDisablei (GLenum target, GLuint index);
+GLAPI GLboolean APIENTRY glIsEnabledi (GLenum target, GLuint index);
+GLAPI void APIENTRY glBeginTransformFeedback (GLenum primitiveMode);
+GLAPI void APIENTRY glEndTransformFeedback (void);
+GLAPI void APIENTRY glBindBufferRange (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size);
+GLAPI void APIENTRY glBindBufferBase (GLenum target, GLuint index, GLuint buffer);
+GLAPI void APIENTRY glTransformFeedbackVaryings (GLuint program, GLsizei count, const GLchar *const*varyings, GLenum bufferMode);
+GLAPI void APIENTRY glGetTransformFeedbackVarying (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name);
+GLAPI void APIENTRY glClampColor (GLenum target, GLenum clamp);
+GLAPI void APIENTRY glBeginConditionalRender (GLuint id, GLenum mode);
+GLAPI void APIENTRY glEndConditionalRender (void);
+GLAPI void APIENTRY glVertexAttribIPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glGetVertexAttribIiv (GLuint index, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetVertexAttribIuiv (GLuint index, GLenum pname, GLuint *params);
+GLAPI void APIENTRY glVertexAttribI1i (GLuint index, GLint x);
+GLAPI void APIENTRY glVertexAttribI2i (GLuint index, GLint x, GLint y);
+GLAPI void APIENTRY glVertexAttribI3i (GLuint index, GLint x, GLint y, GLint z);
+GLAPI void APIENTRY glVertexAttribI4i (GLuint index, GLint x, GLint y, GLint z, GLint w);
+GLAPI void APIENTRY glVertexAttribI1ui (GLuint index, GLuint x);
+GLAPI void APIENTRY glVertexAttribI2ui (GLuint index, GLuint x, GLuint y);
+GLAPI void APIENTRY glVertexAttribI3ui (GLuint index, GLuint x, GLuint y, GLuint z);
+GLAPI void APIENTRY glVertexAttribI4ui (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+GLAPI void APIENTRY glVertexAttribI1iv (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttribI2iv (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttribI3iv (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttribI4iv (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttribI1uiv (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttribI2uiv (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttribI3uiv (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttribI4uiv (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttribI4bv (GLuint index, const GLbyte *v);
+GLAPI void APIENTRY glVertexAttribI4sv (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttribI4ubv (GLuint index, const GLubyte *v);
+GLAPI void APIENTRY glVertexAttribI4usv (GLuint index, const GLushort *v);
+GLAPI void APIENTRY glGetUniformuiv (GLuint program, GLint location, GLuint *params);
+GLAPI void APIENTRY glBindFragDataLocation (GLuint program, GLuint color, const GLchar *name);
+GLAPI GLint APIENTRY glGetFragDataLocation (GLuint program, const GLchar *name);
+GLAPI void APIENTRY glUniform1ui (GLint location, GLuint v0);
+GLAPI void APIENTRY glUniform2ui (GLint location, GLuint v0, GLuint v1);
+GLAPI void APIENTRY glUniform3ui (GLint location, GLuint v0, GLuint v1, GLuint v2);
+GLAPI void APIENTRY glUniform4ui (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+GLAPI void APIENTRY glUniform1uiv (GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glUniform2uiv (GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glUniform3uiv (GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glUniform4uiv (GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glTexParameterIiv (GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glTexParameterIuiv (GLenum target, GLenum pname, const GLuint *params);
+GLAPI void APIENTRY glGetTexParameterIiv (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetTexParameterIuiv (GLenum target, GLenum pname, GLuint *params);
+GLAPI void APIENTRY glClearBufferiv (GLenum buffer, GLint drawbuffer, const GLint *value);
+GLAPI void APIENTRY glClearBufferuiv (GLenum buffer, GLint drawbuffer, const GLuint *value);
+GLAPI void APIENTRY glClearBufferfv (GLenum buffer, GLint drawbuffer, const GLfloat *value);
+GLAPI void APIENTRY glClearBufferfi (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil);
+GLAPI const GLubyte *APIENTRY glGetStringi (GLenum name, GLuint index);
+GLAPI GLboolean APIENTRY glIsRenderbuffer (GLuint renderbuffer);
+GLAPI void APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer);
+GLAPI void APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint *renderbuffers);
+GLAPI void APIENTRY glGenRenderbuffers (GLsizei n, GLuint *renderbuffers);
+GLAPI void APIENTRY glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint *params);
+GLAPI GLboolean APIENTRY glIsFramebuffer (GLuint framebuffer);
+GLAPI void APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer);
+GLAPI void APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint *framebuffers);
+GLAPI void APIENTRY glGenFramebuffers (GLsizei n, GLuint *framebuffers);
+GLAPI GLenum APIENTRY glCheckFramebufferStatus (GLenum target);
+GLAPI void APIENTRY glFramebufferTexture1D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+GLAPI void APIENTRY glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+GLAPI void APIENTRY glFramebufferTexture3D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+GLAPI void APIENTRY glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
+GLAPI void APIENTRY glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGenerateMipmap (GLenum target);
+GLAPI void APIENTRY glBlitFramebuffer (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+GLAPI void APIENTRY glRenderbufferStorageMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glFramebufferTextureLayer (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer);
+GLAPI void *APIENTRY glMapBufferRange (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access);
+GLAPI void APIENTRY glFlushMappedBufferRange (GLenum target, GLintptr offset, GLsizeiptr length);
+GLAPI void APIENTRY glBindVertexArray (GLuint array);
+GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays);
+GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays);
+GLAPI GLboolean APIENTRY glIsVertexArray (GLuint array);
+#endif
+#endif /* GL_VERSION_3_0 */
+
+#ifndef GL_VERSION_3_1
+#define GL_VERSION_3_1 1
+#define GL_SAMPLER_2D_RECT 0x8B63
+#define GL_SAMPLER_2D_RECT_SHADOW 0x8B64
+#define GL_SAMPLER_BUFFER 0x8DC2
+#define GL_INT_SAMPLER_2D_RECT 0x8DCD
+#define GL_INT_SAMPLER_BUFFER 0x8DD0
+#define GL_UNSIGNED_INT_SAMPLER_2D_RECT 0x8DD5
+#define GL_UNSIGNED_INT_SAMPLER_BUFFER 0x8DD8
+#define GL_TEXTURE_BUFFER 0x8C2A
+#define GL_MAX_TEXTURE_BUFFER_SIZE 0x8C2B
+#define GL_TEXTURE_BINDING_BUFFER 0x8C2C
+#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING 0x8C2D
+#define GL_TEXTURE_RECTANGLE 0x84F5
+#define GL_TEXTURE_BINDING_RECTANGLE 0x84F6
+#define GL_PROXY_TEXTURE_RECTANGLE 0x84F7
+#define GL_MAX_RECTANGLE_TEXTURE_SIZE 0x84F8
+#define GL_R8_SNORM 0x8F94
+#define GL_RG8_SNORM 0x8F95
+#define GL_RGB8_SNORM 0x8F96
+#define GL_RGBA8_SNORM 0x8F97
+#define GL_R16_SNORM 0x8F98
+#define GL_RG16_SNORM 0x8F99
+#define GL_RGB16_SNORM 0x8F9A
+#define GL_RGBA16_SNORM 0x8F9B
+#define GL_SIGNED_NORMALIZED 0x8F9C
+#define GL_PRIMITIVE_RESTART 0x8F9D
+#define GL_PRIMITIVE_RESTART_INDEX 0x8F9E
+#define GL_COPY_READ_BUFFER 0x8F36
+#define GL_COPY_WRITE_BUFFER 0x8F37
+#define GL_UNIFORM_BUFFER 0x8A11
+#define GL_UNIFORM_BUFFER_BINDING 0x8A28
+#define GL_UNIFORM_BUFFER_START 0x8A29
+#define GL_UNIFORM_BUFFER_SIZE 0x8A2A
+#define GL_MAX_VERTEX_UNIFORM_BLOCKS 0x8A2B
+#define GL_MAX_FRAGMENT_UNIFORM_BLOCKS 0x8A2D
+#define GL_MAX_COMBINED_UNIFORM_BLOCKS 0x8A2E
+#define GL_MAX_UNIFORM_BUFFER_BINDINGS 0x8A2F
+#define GL_MAX_UNIFORM_BLOCK_SIZE 0x8A30
+#define GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS 0x8A31
+#define GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS 0x8A33
+#define GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT 0x8A34
+#define GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH 0x8A35
+#define GL_ACTIVE_UNIFORM_BLOCKS 0x8A36
+#define GL_UNIFORM_TYPE 0x8A37
+#define GL_UNIFORM_SIZE 0x8A38
+#define GL_UNIFORM_NAME_LENGTH 0x8A39
+#define GL_UNIFORM_BLOCK_INDEX 0x8A3A
+#define GL_UNIFORM_OFFSET 0x8A3B
+#define GL_UNIFORM_ARRAY_STRIDE 0x8A3C
+#define GL_UNIFORM_MATRIX_STRIDE 0x8A3D
+#define GL_UNIFORM_IS_ROW_MAJOR 0x8A3E
+#define GL_UNIFORM_BLOCK_BINDING 0x8A3F
+#define GL_UNIFORM_BLOCK_DATA_SIZE 0x8A40
+#define GL_UNIFORM_BLOCK_NAME_LENGTH 0x8A41
+#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS 0x8A42
+#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES 0x8A43
+#define GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER 0x8A44
+#define GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER 0x8A46
+#define GL_INVALID_INDEX 0xFFFFFFFFu
+typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount);
+typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount);
+typedef void (APIENTRYP PFNGLTEXBUFFERPROC) (GLenum target, GLenum internalformat, GLuint buffer);
+typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXPROC) (GLuint index);
+typedef void (APIENTRYP PFNGLCOPYBUFFERSUBDATAPROC) (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
+typedef void (APIENTRYP PFNGLGETUNIFORMINDICESPROC) (GLuint program, GLsizei uniformCount, const GLchar *const*uniformNames, GLuint *uniformIndices);
+typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMSIVPROC) (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMNAMEPROC) (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName);
+typedef GLuint (APIENTRYP PFNGLGETUNIFORMBLOCKINDEXPROC) (GLuint program, const GLchar *uniformBlockName);
+typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKIVPROC) (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC) (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName);
+typedef void (APIENTRYP PFNGLUNIFORMBLOCKBINDINGPROC) (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawArraysInstanced (GLenum mode, GLint first, GLsizei count, GLsizei instancecount);
+GLAPI void APIENTRY glDrawElementsInstanced (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount);
+GLAPI void APIENTRY glTexBuffer (GLenum target, GLenum internalformat, GLuint buffer);
+GLAPI void APIENTRY glPrimitiveRestartIndex (GLuint index);
+GLAPI void APIENTRY glCopyBufferSubData (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
+GLAPI void APIENTRY glGetUniformIndices (GLuint program, GLsizei uniformCount, const GLchar *const*uniformNames, GLuint *uniformIndices);
+GLAPI void APIENTRY glGetActiveUniformsiv (GLuint program, GLsizei uniformCount, const GLuint *uniformIndices, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetActiveUniformName (GLuint program, GLuint uniformIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformName);
+GLAPI GLuint APIENTRY glGetUniformBlockIndex (GLuint program, const GLchar *uniformBlockName);
+GLAPI void APIENTRY glGetActiveUniformBlockiv (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetActiveUniformBlockName (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName);
+GLAPI void APIENTRY glUniformBlockBinding (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding);
+#endif
+#endif /* GL_VERSION_3_1 */
+
+#ifndef GL_VERSION_3_2
+#define GL_VERSION_3_2 1
+typedef struct __GLsync *GLsync;
+#ifndef GLEXT_64_TYPES_DEFINED
+/* This code block is duplicated in glxext.h, so must be protected */
+#define GLEXT_64_TYPES_DEFINED
+/* Define int32_t, int64_t, and uint64_t types for UST/MSC */
+/* (as used in the GL_EXT_timer_query extension). */
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+#include <inttypes.h>
+#elif defined(__sun__) || defined(__digital__)
+#include <inttypes.h>
+#if defined(__STDC__)
+#if defined(__arch64__) || defined(_LP64)
+typedef long int int64_t;
+typedef unsigned long int uint64_t;
+#else
+typedef long long int int64_t;
+typedef unsigned long long int uint64_t;
+#endif /* __arch64__ */
+#endif /* __STDC__ */
+#elif defined( __VMS ) || defined(__sgi)
+#include <inttypes.h>
+#elif defined(__SCO__) || defined(__USLC__)
+#include <stdint.h>
+#elif defined(__UNIXOS2__) || defined(__SOL64__)
+typedef long int int32_t;
+typedef long long int int64_t;
+typedef unsigned long long int uint64_t;
+#elif defined(_WIN32) && defined(__GNUC__)
+#include <stdint.h>
+#elif defined(_WIN32)
+typedef __int32 int32_t;
+typedef __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+#else
+/* Fallback if nothing above works */
+#include <inttypes.h>
+#endif
+#endif
+typedef uint64_t GLuint64;
+typedef int64_t GLint64;
+#define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001
+#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
+#define GL_LINES_ADJACENCY 0x000A
+#define GL_LINE_STRIP_ADJACENCY 0x000B
+#define GL_TRIANGLES_ADJACENCY 0x000C
+#define GL_TRIANGLE_STRIP_ADJACENCY 0x000D
+#define GL_PROGRAM_POINT_SIZE 0x8642
+#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS 0x8C29
+#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED 0x8DA7
+#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS 0x8DA8
+#define GL_GEOMETRY_SHADER 0x8DD9
+#define GL_GEOMETRY_VERTICES_OUT 0x8916
+#define GL_GEOMETRY_INPUT_TYPE 0x8917
+#define GL_GEOMETRY_OUTPUT_TYPE 0x8918
+#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS 0x8DDF
+#define GL_MAX_GEOMETRY_OUTPUT_VERTICES 0x8DE0
+#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS 0x8DE1
+#define GL_MAX_VERTEX_OUTPUT_COMPONENTS 0x9122
+#define GL_MAX_GEOMETRY_INPUT_COMPONENTS 0x9123
+#define GL_MAX_GEOMETRY_OUTPUT_COMPONENTS 0x9124
+#define GL_MAX_FRAGMENT_INPUT_COMPONENTS 0x9125
+#define GL_CONTEXT_PROFILE_MASK 0x9126
+#define GL_DEPTH_CLAMP 0x864F
+#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION 0x8E4C
+#define GL_FIRST_VERTEX_CONVENTION 0x8E4D
+#define GL_LAST_VERTEX_CONVENTION 0x8E4E
+#define GL_PROVOKING_VERTEX 0x8E4F
+#define GL_TEXTURE_CUBE_MAP_SEAMLESS 0x884F
+#define GL_MAX_SERVER_WAIT_TIMEOUT 0x9111
+#define GL_OBJECT_TYPE 0x9112
+#define GL_SYNC_CONDITION 0x9113
+#define GL_SYNC_STATUS 0x9114
+#define GL_SYNC_FLAGS 0x9115
+#define GL_SYNC_FENCE 0x9116
+#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117
+#define GL_UNSIGNALED 0x9118
+#define GL_SIGNALED 0x9119
+#define GL_ALREADY_SIGNALED 0x911A
+#define GL_TIMEOUT_EXPIRED 0x911B
+#define GL_CONDITION_SATISFIED 0x911C
+#define GL_WAIT_FAILED 0x911D
+#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull
+#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001
+#define GL_SAMPLE_POSITION 0x8E50
+#define GL_SAMPLE_MASK 0x8E51
+#define GL_SAMPLE_MASK_VALUE 0x8E52
+#define GL_MAX_SAMPLE_MASK_WORDS 0x8E59
+#define GL_TEXTURE_2D_MULTISAMPLE 0x9100
+#define GL_PROXY_TEXTURE_2D_MULTISAMPLE 0x9101
+#define GL_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9102
+#define GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9103
+#define GL_TEXTURE_BINDING_2D_MULTISAMPLE 0x9104
+#define GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY 0x9105
+#define GL_TEXTURE_SAMPLES 0x9106
+#define GL_TEXTURE_FIXED_SAMPLE_LOCATIONS 0x9107
+#define GL_SAMPLER_2D_MULTISAMPLE 0x9108
+#define GL_INT_SAMPLER_2D_MULTISAMPLE 0x9109
+#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE 0x910A
+#define GL_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910B
+#define GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910C
+#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY 0x910D
+#define GL_MAX_COLOR_TEXTURE_SAMPLES 0x910E
+#define GL_MAX_DEPTH_TEXTURE_SAMPLES 0x910F
+#define GL_MAX_INTEGER_SAMPLES 0x9110
+typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
+typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSBASEVERTEXPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLint basevertex);
+typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex);
+typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei drawcount, const GLint *basevertex);
+typedef void (APIENTRYP PFNGLPROVOKINGVERTEXPROC) (GLenum mode);
+typedef GLsync (APIENTRYP PFNGLFENCESYNCPROC) (GLenum condition, GLbitfield flags);
+typedef GLboolean (APIENTRYP PFNGLISSYNCPROC) (GLsync sync);
+typedef void (APIENTRYP PFNGLDELETESYNCPROC) (GLsync sync);
+typedef GLenum (APIENTRYP PFNGLCLIENTWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout);
+typedef void (APIENTRYP PFNGLWAITSYNCPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout);
+typedef void (APIENTRYP PFNGLGETINTEGER64VPROC) (GLenum pname, GLint64 *data);
+typedef void (APIENTRYP PFNGLGETSYNCIVPROC) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values);
+typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data);
+typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERI64VPROC) (GLenum target, GLenum pname, GLint64 *params);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLTEXIMAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
+typedef void (APIENTRYP PFNGLTEXIMAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations);
+typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVPROC) (GLenum pname, GLuint index, GLfloat *val);
+typedef void (APIENTRYP PFNGLSAMPLEMASKIPROC) (GLuint maskNumber, GLbitfield mask);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
+GLAPI void APIENTRY glDrawRangeElementsBaseVertex (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLint basevertex);
+GLAPI void APIENTRY glDrawElementsInstancedBaseVertex (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex);
+GLAPI void APIENTRY glMultiDrawElementsBaseVertex (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei drawcount, const GLint *basevertex);
+GLAPI void APIENTRY glProvokingVertex (GLenum mode);
+GLAPI GLsync APIENTRY glFenceSync (GLenum condition, GLbitfield flags);
+GLAPI GLboolean APIENTRY glIsSync (GLsync sync);
+GLAPI void APIENTRY glDeleteSync (GLsync sync);
+GLAPI GLenum APIENTRY glClientWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout);
+GLAPI void APIENTRY glWaitSync (GLsync sync, GLbitfield flags, GLuint64 timeout);
+GLAPI void APIENTRY glGetInteger64v (GLenum pname, GLint64 *data);
+GLAPI void APIENTRY glGetSynciv (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values);
+GLAPI void APIENTRY glGetInteger64i_v (GLenum target, GLuint index, GLint64 *data);
+GLAPI void APIENTRY glGetBufferParameteri64v (GLenum target, GLenum pname, GLint64 *params);
+GLAPI void APIENTRY glFramebufferTexture (GLenum target, GLenum attachment, GLuint texture, GLint level);
+GLAPI void APIENTRY glTexImage2DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
+GLAPI void APIENTRY glTexImage3DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations);
+GLAPI void APIENTRY glGetMultisamplefv (GLenum pname, GLuint index, GLfloat *val);
+GLAPI void APIENTRY glSampleMaski (GLuint maskNumber, GLbitfield mask);
+#endif
+#endif /* GL_VERSION_3_2 */
+
+#ifndef GL_VERSION_3_3
+#define GL_VERSION_3_3 1
+#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR 0x88FE
+#define GL_SRC1_COLOR 0x88F9
+#define GL_ONE_MINUS_SRC1_COLOR 0x88FA
+#define GL_ONE_MINUS_SRC1_ALPHA 0x88FB
+#define GL_MAX_DUAL_SOURCE_DRAW_BUFFERS 0x88FC
+#define GL_ANY_SAMPLES_PASSED 0x8C2F
+#define GL_SAMPLER_BINDING 0x8919
+#define GL_RGB10_A2UI 0x906F
+#define GL_TEXTURE_SWIZZLE_R 0x8E42
+#define GL_TEXTURE_SWIZZLE_G 0x8E43
+#define GL_TEXTURE_SWIZZLE_B 0x8E44
+#define GL_TEXTURE_SWIZZLE_A 0x8E45
+#define GL_TEXTURE_SWIZZLE_RGBA 0x8E46
+#define GL_TIME_ELAPSED 0x88BF
+#define GL_TIMESTAMP 0x8E28
+#define GL_INT_2_10_10_10_REV 0x8D9F
+typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONINDEXEDPROC) (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name);
+typedef GLint (APIENTRYP PFNGLGETFRAGDATAINDEXPROC) (GLuint program, const GLchar *name);
+typedef void (APIENTRYP PFNGLGENSAMPLERSPROC) (GLsizei count, GLuint *samplers);
+typedef void (APIENTRYP PFNGLDELETESAMPLERSPROC) (GLsizei count, const GLuint *samplers);
+typedef GLboolean (APIENTRYP PFNGLISSAMPLERPROC) (GLuint sampler);
+typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler);
+typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIPROC) (GLuint sampler, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pname, const GLint *param);
+typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFPROC) (GLuint sampler, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, const GLfloat *param);
+typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIIVPROC) (GLuint sampler, GLenum pname, const GLint *param);
+typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenum pname, const GLuint *param);
+typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIIVPROC) (GLuint sampler, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETSAMPLERPARAMETERIUIVPROC) (GLuint sampler, GLenum pname, GLuint *params);
+typedef void (APIENTRYP PFNGLQUERYCOUNTERPROC) (GLuint id, GLenum target);
+typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VPROC) (GLuint id, GLenum pname, GLint64 *params);
+typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VPROC) (GLuint id, GLenum pname, GLuint64 *params);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORPROC) (GLuint index, GLuint divisor);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBP1UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBP2UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBP3UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIPROC) (GLuint index, GLenum type, GLboolean normalized, GLuint value);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBP4UIVPROC) (GLuint index, GLenum type, GLboolean normalized, const GLuint *value);
+typedef void (APIENTRYP PFNGLVERTEXP2UIPROC) (GLenum type, GLuint value);
+typedef void (APIENTRYP PFNGLVERTEXP2UIVPROC) (GLenum type, const GLuint *value);
+typedef void (APIENTRYP PFNGLVERTEXP3UIPROC) (GLenum type, GLuint value);
+typedef void (APIENTRYP PFNGLVERTEXP3UIVPROC) (GLenum type, const GLuint *value);
+typedef void (APIENTRYP PFNGLVERTEXP4UIPROC) (GLenum type, GLuint value);
+typedef void (APIENTRYP PFNGLVERTEXP4UIVPROC) (GLenum type, const GLuint *value);
+typedef void (APIENTRYP PFNGLTEXCOORDP1UIPROC) (GLenum type, GLuint coords);
+typedef void (APIENTRYP PFNGLTEXCOORDP1UIVPROC) (GLenum type, const GLuint *coords);
+typedef void (APIENTRYP PFNGLTEXCOORDP2UIPROC) (GLenum type, GLuint coords);
+typedef void (APIENTRYP PFNGLTEXCOORDP2UIVPROC) (GLenum type, const GLuint *coords);
+typedef void (APIENTRYP PFNGLTEXCOORDP3UIPROC) (GLenum type, GLuint coords);
+typedef void (APIENTRYP PFNGLTEXCOORDP3UIVPROC) (GLenum type, const GLuint *coords);
+typedef void (APIENTRYP PFNGLTEXCOORDP4UIPROC) (GLenum type, GLuint coords);
+typedef void (APIENTRYP PFNGLTEXCOORDP4UIVPROC) (GLenum type, const GLuint *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIPROC) (GLenum texture, GLenum type, GLuint coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORDP1UIVPROC) (GLenum texture, GLenum type, const GLuint *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIPROC) (GLenum texture, GLenum type, GLuint coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORDP2UIVPROC) (GLenum texture, GLenum type, const GLuint *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIPROC) (GLenum texture, GLenum type, GLuint coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORDP3UIVPROC) (GLenum texture, GLenum type, const GLuint *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIPROC) (GLenum texture, GLenum type, GLuint coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORDP4UIVPROC) (GLenum texture, GLenum type, const GLuint *coords);
+typedef void (APIENTRYP PFNGLNORMALP3UIPROC) (GLenum type, GLuint coords);
+typedef void (APIENTRYP PFNGLNORMALP3UIVPROC) (GLenum type, const GLuint *coords);
+typedef void (APIENTRYP PFNGLCOLORP3UIPROC) (GLenum type, GLuint color);
+typedef void (APIENTRYP PFNGLCOLORP3UIVPROC) (GLenum type, const GLuint *color);
+typedef void (APIENTRYP PFNGLCOLORP4UIPROC) (GLenum type, GLuint color);
+typedef void (APIENTRYP PFNGLCOLORP4UIVPROC) (GLenum type, const GLuint *color);
+typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIPROC) (GLenum type, GLuint color);
+typedef void (APIENTRYP PFNGLSECONDARYCOLORP3UIVPROC) (GLenum type, const GLuint *color);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBindFragDataLocationIndexed (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name);
+GLAPI GLint APIENTRY glGetFragDataIndex (GLuint program, const GLchar *name);
+GLAPI void APIENTRY glGenSamplers (GLsizei count, GLuint *samplers);
+GLAPI void APIENTRY glDeleteSamplers (GLsizei count, const GLuint *samplers);
+GLAPI GLboolean APIENTRY glIsSampler (GLuint sampler);
+GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler);
+GLAPI void APIENTRY glSamplerParameteri (GLuint sampler, GLenum pname, GLint param);
+GLAPI void APIENTRY glSamplerParameteriv (GLuint sampler, GLenum pname, const GLint *param);
+GLAPI void APIENTRY glSamplerParameterf (GLuint sampler, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glSamplerParameterfv (GLuint sampler, GLenum pname, const GLfloat *param);
+GLAPI void APIENTRY glSamplerParameterIiv (GLuint sampler, GLenum pname, const GLint *param);
+GLAPI void APIENTRY glSamplerParameterIuiv (GLuint sampler, GLenum pname, const GLuint *param);
+GLAPI void APIENTRY glGetSamplerParameteriv (GLuint sampler, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetSamplerParameterIiv (GLuint sampler, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetSamplerParameterfv (GLuint sampler, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetSamplerParameterIuiv (GLuint sampler, GLenum pname, GLuint *params);
+GLAPI void APIENTRY glQueryCounter (GLuint id, GLenum target);
+GLAPI void APIENTRY glGetQueryObjecti64v (GLuint id, GLenum pname, GLint64 *params);
+GLAPI void APIENTRY glGetQueryObjectui64v (GLuint id, GLenum pname, GLuint64 *params);
+GLAPI void APIENTRY glVertexAttribDivisor (GLuint index, GLuint divisor);
+GLAPI void APIENTRY glVertexAttribP1ui (GLuint index, GLenum type, GLboolean normalized, GLuint value);
+GLAPI void APIENTRY glVertexAttribP1uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value);
+GLAPI void APIENTRY glVertexAttribP2ui (GLuint index, GLenum type, GLboolean normalized, GLuint value);
+GLAPI void APIENTRY glVertexAttribP2uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value);
+GLAPI void APIENTRY glVertexAttribP3ui (GLuint index, GLenum type, GLboolean normalized, GLuint value);
+GLAPI void APIENTRY glVertexAttribP3uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value);
+GLAPI void APIENTRY glVertexAttribP4ui (GLuint index, GLenum type, GLboolean normalized, GLuint value);
+GLAPI void APIENTRY glVertexAttribP4uiv (GLuint index, GLenum type, GLboolean normalized, const GLuint *value);
+GLAPI void APIENTRY glVertexP2ui (GLenum type, GLuint value);
+GLAPI void APIENTRY glVertexP2uiv (GLenum type, const GLuint *value);
+GLAPI void APIENTRY glVertexP3ui (GLenum type, GLuint value);
+GLAPI void APIENTRY glVertexP3uiv (GLenum type, const GLuint *value);
+GLAPI void APIENTRY glVertexP4ui (GLenum type, GLuint value);
+GLAPI void APIENTRY glVertexP4uiv (GLenum type, const GLuint *value);
+GLAPI void APIENTRY glTexCoordP1ui (GLenum type, GLuint coords);
+GLAPI void APIENTRY glTexCoordP1uiv (GLenum type, const GLuint *coords);
+GLAPI void APIENTRY glTexCoordP2ui (GLenum type, GLuint coords);
+GLAPI void APIENTRY glTexCoordP2uiv (GLenum type, const GLuint *coords);
+GLAPI void APIENTRY glTexCoordP3ui (GLenum type, GLuint coords);
+GLAPI void APIENTRY glTexCoordP3uiv (GLenum type, const GLuint *coords);
+GLAPI void APIENTRY glTexCoordP4ui (GLenum type, GLuint coords);
+GLAPI void APIENTRY glTexCoordP4uiv (GLenum type, const GLuint *coords);
+GLAPI void APIENTRY glMultiTexCoordP1ui (GLenum texture, GLenum type, GLuint coords);
+GLAPI void APIENTRY glMultiTexCoordP1uiv (GLenum texture, GLenum type, const GLuint *coords);
+GLAPI void APIENTRY glMultiTexCoordP2ui (GLenum texture, GLenum type, GLuint coords);
+GLAPI void APIENTRY glMultiTexCoordP2uiv (GLenum texture, GLenum type, const GLuint *coords);
+GLAPI void APIENTRY glMultiTexCoordP3ui (GLenum texture, GLenum type, GLuint coords);
+GLAPI void APIENTRY glMultiTexCoordP3uiv (GLenum texture, GLenum type, const GLuint *coords);
+GLAPI void APIENTRY glMultiTexCoordP4ui (GLenum texture, GLenum type, GLuint coords);
+GLAPI void APIENTRY glMultiTexCoordP4uiv (GLenum texture, GLenum type, const GLuint *coords);
+GLAPI void APIENTRY glNormalP3ui (GLenum type, GLuint coords);
+GLAPI void APIENTRY glNormalP3uiv (GLenum type, const GLuint *coords);
+GLAPI void APIENTRY glColorP3ui (GLenum type, GLuint color);
+GLAPI void APIENTRY glColorP3uiv (GLenum type, const GLuint *color);
+GLAPI void APIENTRY glColorP4ui (GLenum type, GLuint color);
+GLAPI void APIENTRY glColorP4uiv (GLenum type, const GLuint *color);
+GLAPI void APIENTRY glSecondaryColorP3ui (GLenum type, GLuint color);
+GLAPI void APIENTRY glSecondaryColorP3uiv (GLenum type, const GLuint *color);
+#endif
+#endif /* GL_VERSION_3_3 */
+
+#ifndef GL_VERSION_4_0
+#define GL_VERSION_4_0 1
+#define GL_SAMPLE_SHADING 0x8C36
+#define GL_MIN_SAMPLE_SHADING_VALUE 0x8C37
+#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5E
+#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET 0x8E5F
+#define GL_TEXTURE_CUBE_MAP_ARRAY 0x9009
+#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY 0x900A
+#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY 0x900B
+#define GL_SAMPLER_CUBE_MAP_ARRAY 0x900C
+#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW 0x900D
+#define GL_INT_SAMPLER_CUBE_MAP_ARRAY 0x900E
+#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY 0x900F
+#define GL_DRAW_INDIRECT_BUFFER 0x8F3F
+#define GL_DRAW_INDIRECT_BUFFER_BINDING 0x8F43
+#define GL_GEOMETRY_SHADER_INVOCATIONS 0x887F
+#define GL_MAX_GEOMETRY_SHADER_INVOCATIONS 0x8E5A
+#define GL_MIN_FRAGMENT_INTERPOLATION_OFFSET 0x8E5B
+#define GL_MAX_FRAGMENT_INTERPOLATION_OFFSET 0x8E5C
+#define GL_FRAGMENT_INTERPOLATION_OFFSET_BITS 0x8E5D
+#define GL_MAX_VERTEX_STREAMS 0x8E71
+#define GL_DOUBLE_VEC2 0x8FFC
+#define GL_DOUBLE_VEC3 0x8FFD
+#define GL_DOUBLE_VEC4 0x8FFE
+#define GL_DOUBLE_MAT2 0x8F46
+#define GL_DOUBLE_MAT3 0x8F47
+#define GL_DOUBLE_MAT4 0x8F48
+#define GL_DOUBLE_MAT2x3 0x8F49
+#define GL_DOUBLE_MAT2x4 0x8F4A
+#define GL_DOUBLE_MAT3x2 0x8F4B
+#define GL_DOUBLE_MAT3x4 0x8F4C
+#define GL_DOUBLE_MAT4x2 0x8F4D
+#define GL_DOUBLE_MAT4x3 0x8F4E
+#define GL_ACTIVE_SUBROUTINES 0x8DE5
+#define GL_ACTIVE_SUBROUTINE_UNIFORMS 0x8DE6
+#define GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS 0x8E47
+#define GL_ACTIVE_SUBROUTINE_MAX_LENGTH 0x8E48
+#define GL_ACTIVE_SUBROUTINE_UNIFORM_MAX_LENGTH 0x8E49
+#define GL_MAX_SUBROUTINES 0x8DE7
+#define GL_MAX_SUBROUTINE_UNIFORM_LOCATIONS 0x8DE8
+#define GL_NUM_COMPATIBLE_SUBROUTINES 0x8E4A
+#define GL_COMPATIBLE_SUBROUTINES 0x8E4B
+#define GL_PATCHES 0x000E
+#define GL_PATCH_VERTICES 0x8E72
+#define GL_PATCH_DEFAULT_INNER_LEVEL 0x8E73
+#define GL_PATCH_DEFAULT_OUTER_LEVEL 0x8E74
+#define GL_TESS_CONTROL_OUTPUT_VERTICES 0x8E75
+#define GL_TESS_GEN_MODE 0x8E76
+#define GL_TESS_GEN_SPACING 0x8E77
+#define GL_TESS_GEN_VERTEX_ORDER 0x8E78
+#define GL_TESS_GEN_POINT_MODE 0x8E79
+#define GL_ISOLINES 0x8E7A
+#define GL_FRACTIONAL_ODD 0x8E7B
+#define GL_FRACTIONAL_EVEN 0x8E7C
+#define GL_MAX_PATCH_VERTICES 0x8E7D
+#define GL_MAX_TESS_GEN_LEVEL 0x8E7E
+#define GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS 0x8E7F
+#define GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS 0x8E80
+#define GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS 0x8E81
+#define GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS 0x8E82
+#define GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS 0x8E83
+#define GL_MAX_TESS_PATCH_COMPONENTS 0x8E84
+#define GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS 0x8E85
+#define GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS 0x8E86
+#define GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS 0x8E89
+#define GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS 0x8E8A
+#define GL_MAX_TESS_CONTROL_INPUT_COMPONENTS 0x886C
+#define GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS 0x886D
+#define GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS 0x8E1E
+#define GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS 0x8E1F
+#define GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER 0x84F0
+#define GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER 0x84F1
+#define GL_TESS_EVALUATION_SHADER 0x8E87
+#define GL_TESS_CONTROL_SHADER 0x8E88
+#define GL_TRANSFORM_FEEDBACK 0x8E22
+#define GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED 0x8E23
+#define GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE 0x8E24
+#define GL_TRANSFORM_FEEDBACK_BINDING 0x8E25
+#define GL_MAX_TRANSFORM_FEEDBACK_BUFFERS 0x8E70
+typedef void (APIENTRYP PFNGLMINSAMPLESHADINGPROC) (GLfloat value);
+typedef void (APIENTRYP PFNGLBLENDEQUATIONIPROC) (GLuint buf, GLenum mode);
+typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha);
+typedef void (APIENTRYP PFNGLBLENDFUNCIPROC) (GLuint buf, GLenum src, GLenum dst);
+typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+typedef void (APIENTRYP PFNGLDRAWARRAYSINDIRECTPROC) (GLenum mode, const void *indirect);
+typedef void (APIENTRYP PFNGLDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const void *indirect);
+typedef void (APIENTRYP PFNGLUNIFORM1DPROC) (GLint location, GLdouble x);
+typedef void (APIENTRYP PFNGLUNIFORM2DPROC) (GLint location, GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLUNIFORM3DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLUNIFORM4DPROC) (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLUNIFORM1DVPROC) (GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORM2DVPROC) (GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORM3DVPROC) (GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORM4DVPROC) (GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX2X4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX3X4DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X2DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX4X3DVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLGETUNIFORMDVPROC) (GLuint program, GLint location, GLdouble *params);
+typedef GLint (APIENTRYP PFNGLGETSUBROUTINEUNIFORMLOCATIONPROC) (GLuint program, GLenum shadertype, const GLchar *name);
+typedef GLuint (APIENTRYP PFNGLGETSUBROUTINEINDEXPROC) (GLuint program, GLenum shadertype, const GLchar *name);
+typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMIVPROC) (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values);
+typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINEUNIFORMNAMEPROC) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name);
+typedef void (APIENTRYP PFNGLGETACTIVESUBROUTINENAMEPROC) (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name);
+typedef void (APIENTRYP PFNGLUNIFORMSUBROUTINESUIVPROC) (GLenum shadertype, GLsizei count, const GLuint *indices);
+typedef void (APIENTRYP PFNGLGETUNIFORMSUBROUTINEUIVPROC) (GLenum shadertype, GLint location, GLuint *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMSTAGEIVPROC) (GLuint program, GLenum shadertype, GLenum pname, GLint *values);
+typedef void (APIENTRYP PFNGLPATCHPARAMETERIPROC) (GLenum pname, GLint value);
+typedef void (APIENTRYP PFNGLPATCHPARAMETERFVPROC) (GLenum pname, const GLfloat *values);
+typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKPROC) (GLenum target, GLuint id);
+typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSPROC) (GLsizei n, const GLuint *ids);
+typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSPROC) (GLsizei n, GLuint *ids);
+typedef GLboolean (APIENTRYP PFNGLISTRANSFORMFEEDBACKPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLPAUSETRANSFORMFEEDBACKPROC) (void);
+typedef void (APIENTRYP PFNGLRESUMETRANSFORMFEEDBACKPROC) (void);
+typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKPROC) (GLenum mode, GLuint id);
+typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC) (GLenum mode, GLuint id, GLuint stream);
+typedef void (APIENTRYP PFNGLBEGINQUERYINDEXEDPROC) (GLenum target, GLuint index, GLuint id);
+typedef void (APIENTRYP PFNGLENDQUERYINDEXEDPROC) (GLenum target, GLuint index);
+typedef void (APIENTRYP PFNGLGETQUERYINDEXEDIVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMinSampleShading (GLfloat value);
+GLAPI void APIENTRY glBlendEquationi (GLuint buf, GLenum mode);
+GLAPI void APIENTRY glBlendEquationSeparatei (GLuint buf, GLenum modeRGB, GLenum modeAlpha);
+GLAPI void APIENTRY glBlendFunci (GLuint buf, GLenum src, GLenum dst);
+GLAPI void APIENTRY glBlendFuncSeparatei (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+GLAPI void APIENTRY glDrawArraysIndirect (GLenum mode, const void *indirect);
+GLAPI void APIENTRY glDrawElementsIndirect (GLenum mode, GLenum type, const void *indirect);
+GLAPI void APIENTRY glUniform1d (GLint location, GLdouble x);
+GLAPI void APIENTRY glUniform2d (GLint location, GLdouble x, GLdouble y);
+GLAPI void APIENTRY glUniform3d (GLint location, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glUniform4d (GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glUniform1dv (GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glUniform2dv (GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glUniform3dv (GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glUniform4dv (GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glUniformMatrix2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glUniformMatrix3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glUniformMatrix4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glUniformMatrix2x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glUniformMatrix2x4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glUniformMatrix3x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glUniformMatrix3x4dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glUniformMatrix4x2dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glUniformMatrix4x3dv (GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glGetUniformdv (GLuint program, GLint location, GLdouble *params);
+GLAPI GLint APIENTRY glGetSubroutineUniformLocation (GLuint program, GLenum shadertype, const GLchar *name);
+GLAPI GLuint APIENTRY glGetSubroutineIndex (GLuint program, GLenum shadertype, const GLchar *name);
+GLAPI void APIENTRY glGetActiveSubroutineUniformiv (GLuint program, GLenum shadertype, GLuint index, GLenum pname, GLint *values);
+GLAPI void APIENTRY glGetActiveSubroutineUniformName (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name);
+GLAPI void APIENTRY glGetActiveSubroutineName (GLuint program, GLenum shadertype, GLuint index, GLsizei bufsize, GLsizei *length, GLchar *name);
+GLAPI void APIENTRY glUniformSubroutinesuiv (GLenum shadertype, GLsizei count, const GLuint *indices);
+GLAPI void APIENTRY glGetUniformSubroutineuiv (GLenum shadertype, GLint location, GLuint *params);
+GLAPI void APIENTRY glGetProgramStageiv (GLuint program, GLenum shadertype, GLenum pname, GLint *values);
+GLAPI void APIENTRY glPatchParameteri (GLenum pname, GLint value);
+GLAPI void APIENTRY glPatchParameterfv (GLenum pname, const GLfloat *values);
+GLAPI void APIENTRY glBindTransformFeedback (GLenum target, GLuint id);
+GLAPI void APIENTRY glDeleteTransformFeedbacks (GLsizei n, const GLuint *ids);
+GLAPI void APIENTRY glGenTransformFeedbacks (GLsizei n, GLuint *ids);
+GLAPI GLboolean APIENTRY glIsTransformFeedback (GLuint id);
+GLAPI void APIENTRY glPauseTransformFeedback (void);
+GLAPI void APIENTRY glResumeTransformFeedback (void);
+GLAPI void APIENTRY glDrawTransformFeedback (GLenum mode, GLuint id);
+GLAPI void APIENTRY glDrawTransformFeedbackStream (GLenum mode, GLuint id, GLuint stream);
+GLAPI void APIENTRY glBeginQueryIndexed (GLenum target, GLuint index, GLuint id);
+GLAPI void APIENTRY glEndQueryIndexed (GLenum target, GLuint index);
+GLAPI void APIENTRY glGetQueryIndexediv (GLenum target, GLuint index, GLenum pname, GLint *params);
+#endif
+#endif /* GL_VERSION_4_0 */
+
+#ifndef GL_VERSION_4_1
+#define GL_VERSION_4_1 1
+#define GL_FIXED 0x140C
+#define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A
+#define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B
+#define GL_LOW_FLOAT 0x8DF0
+#define GL_MEDIUM_FLOAT 0x8DF1
+#define GL_HIGH_FLOAT 0x8DF2
+#define GL_LOW_INT 0x8DF3
+#define GL_MEDIUM_INT 0x8DF4
+#define GL_HIGH_INT 0x8DF5
+#define GL_SHADER_COMPILER 0x8DFA
+#define GL_SHADER_BINARY_FORMATS 0x8DF8
+#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9
+#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB
+#define GL_MAX_VARYING_VECTORS 0x8DFC
+#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD
+#define GL_RGB565 0x8D62
+#define GL_PROGRAM_BINARY_RETRIEVABLE_HINT 0x8257
+#define GL_PROGRAM_BINARY_LENGTH 0x8741
+#define GL_NUM_PROGRAM_BINARY_FORMATS 0x87FE
+#define GL_PROGRAM_BINARY_FORMATS 0x87FF
+#define GL_VERTEX_SHADER_BIT 0x00000001
+#define GL_FRAGMENT_SHADER_BIT 0x00000002
+#define GL_GEOMETRY_SHADER_BIT 0x00000004
+#define GL_TESS_CONTROL_SHADER_BIT 0x00000008
+#define GL_TESS_EVALUATION_SHADER_BIT 0x00000010
+#define GL_ALL_SHADER_BITS 0xFFFFFFFF
+#define GL_PROGRAM_SEPARABLE 0x8258
+#define GL_ACTIVE_PROGRAM 0x8259
+#define GL_PROGRAM_PIPELINE_BINDING 0x825A
+#define GL_MAX_VIEWPORTS 0x825B
+#define GL_VIEWPORT_SUBPIXEL_BITS 0x825C
+#define GL_VIEWPORT_BOUNDS_RANGE 0x825D
+#define GL_LAYER_PROVOKING_VERTEX 0x825E
+#define GL_VIEWPORT_INDEX_PROVOKING_VERTEX 0x825F
+#define GL_UNDEFINED_VERTEX 0x8260
+typedef void (APIENTRYP PFNGLRELEASESHADERCOMPILERPROC) (void);
+typedef void (APIENTRYP PFNGLSHADERBINARYPROC) (GLsizei count, const GLuint *shaders, GLenum binaryformat, const void *binary, GLsizei length);
+typedef void (APIENTRYP PFNGLGETSHADERPRECISIONFORMATPROC) (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision);
+typedef void (APIENTRYP PFNGLDEPTHRANGEFPROC) (GLfloat n, GLfloat f);
+typedef void (APIENTRYP PFNGLCLEARDEPTHFPROC) (GLfloat d);
+typedef void (APIENTRYP PFNGLGETPROGRAMBINARYPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, void *binary);
+typedef void (APIENTRYP PFNGLPROGRAMBINARYPROC) (GLuint program, GLenum binaryFormat, const void *binary, GLsizei length);
+typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIPROC) (GLuint program, GLenum pname, GLint value);
+typedef void (APIENTRYP PFNGLUSEPROGRAMSTAGESPROC) (GLuint pipeline, GLbitfield stages, GLuint program);
+typedef void (APIENTRYP PFNGLACTIVESHADERPROGRAMPROC) (GLuint pipeline, GLuint program);
+typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMVPROC) (GLenum type, GLsizei count, const GLchar *const*strings);
+typedef void (APIENTRYP PFNGLBINDPROGRAMPIPELINEPROC) (GLuint pipeline);
+typedef void (APIENTRYP PFNGLDELETEPROGRAMPIPELINESPROC) (GLsizei n, const GLuint *pipelines);
+typedef void (APIENTRYP PFNGLGENPROGRAMPIPELINESPROC) (GLsizei n, GLuint *pipelines);
+typedef GLboolean (APIENTRYP PFNGLISPROGRAMPIPELINEPROC) (GLuint pipeline);
+typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEIVPROC) (GLuint pipeline, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IPROC) (GLuint program, GLint location, GLint v0);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FPROC) (GLuint program, GLint location, GLfloat v0);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DPROC) (GLuint program, GLint location, GLdouble v0);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIPROC) (GLuint program, GLint location, GLuint v0);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IPROC) (GLuint program, GLint location, GLint v0, GLint v1);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IVPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FVPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DPROC) (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DVPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIVPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3DVPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLVALIDATEPROGRAMPIPELINEPROC) (GLuint pipeline);
+typedef void (APIENTRYP PFNGLGETPROGRAMPIPELINEINFOLOGPROC) (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DPROC) (GLuint index, GLdouble x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DPROC) (GLuint index, GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLDVPROC) (GLuint index, GLenum pname, GLdouble *params);
+typedef void (APIENTRYP PFNGLVIEWPORTARRAYVPROC) (GLuint first, GLsizei count, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h);
+typedef void (APIENTRYP PFNGLVIEWPORTINDEXEDFVPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLSCISSORARRAYVPROC) (GLuint first, GLsizei count, const GLint *v);
+typedef void (APIENTRYP PFNGLSCISSORINDEXEDPROC) (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLSCISSORINDEXEDVPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLDEPTHRANGEARRAYVPROC) (GLuint first, GLsizei count, const GLdouble *v);
+typedef void (APIENTRYP PFNGLDEPTHRANGEINDEXEDPROC) (GLuint index, GLdouble n, GLdouble f);
+typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data);
+typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glReleaseShaderCompiler (void);
+GLAPI void APIENTRY glShaderBinary (GLsizei count, const GLuint *shaders, GLenum binaryformat, const void *binary, GLsizei length);
+GLAPI void APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision);
+GLAPI void APIENTRY glDepthRangef (GLfloat n, GLfloat f);
+GLAPI void APIENTRY glClearDepthf (GLfloat d);
+GLAPI void APIENTRY glGetProgramBinary (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, void *binary);
+GLAPI void APIENTRY glProgramBinary (GLuint program, GLenum binaryFormat, const void *binary, GLsizei length);
+GLAPI void APIENTRY glProgramParameteri (GLuint program, GLenum pname, GLint value);
+GLAPI void APIENTRY glUseProgramStages (GLuint pipeline, GLbitfield stages, GLuint program);
+GLAPI void APIENTRY glActiveShaderProgram (GLuint pipeline, GLuint program);
+GLAPI GLuint APIENTRY glCreateShaderProgramv (GLenum type, GLsizei count, const GLchar *const*strings);
+GLAPI void APIENTRY glBindProgramPipeline (GLuint pipeline);
+GLAPI void APIENTRY glDeleteProgramPipelines (GLsizei n, const GLuint *pipelines);
+GLAPI void APIENTRY glGenProgramPipelines (GLsizei n, GLuint *pipelines);
+GLAPI GLboolean APIENTRY glIsProgramPipeline (GLuint pipeline);
+GLAPI void APIENTRY glGetProgramPipelineiv (GLuint pipeline, GLenum pname, GLint *params);
+GLAPI void APIENTRY glProgramUniform1i (GLuint program, GLint location, GLint v0);
+GLAPI void APIENTRY glProgramUniform1iv (GLuint program, GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glProgramUniform1f (GLuint program, GLint location, GLfloat v0);
+GLAPI void APIENTRY glProgramUniform1fv (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniform1d (GLuint program, GLint location, GLdouble v0);
+GLAPI void APIENTRY glProgramUniform1dv (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniform1ui (GLuint program, GLint location, GLuint v0);
+GLAPI void APIENTRY glProgramUniform1uiv (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glProgramUniform2i (GLuint program, GLint location, GLint v0, GLint v1);
+GLAPI void APIENTRY glProgramUniform2iv (GLuint program, GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glProgramUniform2f (GLuint program, GLint location, GLfloat v0, GLfloat v1);
+GLAPI void APIENTRY glProgramUniform2fv (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniform2d (GLuint program, GLint location, GLdouble v0, GLdouble v1);
+GLAPI void APIENTRY glProgramUniform2dv (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniform2ui (GLuint program, GLint location, GLuint v0, GLuint v1);
+GLAPI void APIENTRY glProgramUniform2uiv (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glProgramUniform3i (GLuint program, GLint location, GLint v0, GLint v1, GLint v2);
+GLAPI void APIENTRY glProgramUniform3iv (GLuint program, GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glProgramUniform3f (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+GLAPI void APIENTRY glProgramUniform3fv (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniform3d (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2);
+GLAPI void APIENTRY glProgramUniform3dv (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniform3ui (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2);
+GLAPI void APIENTRY glProgramUniform3uiv (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glProgramUniform4i (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+GLAPI void APIENTRY glProgramUniform4iv (GLuint program, GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glProgramUniform4f (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+GLAPI void APIENTRY glProgramUniform4fv (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniform4d (GLuint program, GLint location, GLdouble v0, GLdouble v1, GLdouble v2, GLdouble v3);
+GLAPI void APIENTRY glProgramUniform4dv (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniform4ui (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+GLAPI void APIENTRY glProgramUniform4uiv (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glProgramUniformMatrix2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix2x3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix3x2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix2x4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix4x2fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix3x4fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix4x3fv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix2x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix3x2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix2x4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix4x2dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix3x4dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix4x3dv (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glValidateProgramPipeline (GLuint pipeline);
+GLAPI void APIENTRY glGetProgramPipelineInfoLog (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+GLAPI void APIENTRY glVertexAttribL1d (GLuint index, GLdouble x);
+GLAPI void APIENTRY glVertexAttribL2d (GLuint index, GLdouble x, GLdouble y);
+GLAPI void APIENTRY glVertexAttribL3d (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glVertexAttribL4d (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glVertexAttribL1dv (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribL2dv (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribL3dv (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribL4dv (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribLPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glGetVertexAttribLdv (GLuint index, GLenum pname, GLdouble *params);
+GLAPI void APIENTRY glViewportArrayv (GLuint first, GLsizei count, const GLfloat *v);
+GLAPI void APIENTRY glViewportIndexedf (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h);
+GLAPI void APIENTRY glViewportIndexedfv (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glScissorArrayv (GLuint first, GLsizei count, const GLint *v);
+GLAPI void APIENTRY glScissorIndexed (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glScissorIndexedv (GLuint index, const GLint *v);
+GLAPI void APIENTRY glDepthRangeArrayv (GLuint first, GLsizei count, const GLdouble *v);
+GLAPI void APIENTRY glDepthRangeIndexed (GLuint index, GLdouble n, GLdouble f);
+GLAPI void APIENTRY glGetFloati_v (GLenum target, GLuint index, GLfloat *data);
+GLAPI void APIENTRY glGetDoublei_v (GLenum target, GLuint index, GLdouble *data);
+#endif
+#endif /* GL_VERSION_4_1 */
+
+#ifndef GL_VERSION_4_2
+#define GL_VERSION_4_2 1
+#define GL_UNPACK_COMPRESSED_BLOCK_WIDTH 0x9127
+#define GL_UNPACK_COMPRESSED_BLOCK_HEIGHT 0x9128
+#define GL_UNPACK_COMPRESSED_BLOCK_DEPTH 0x9129
+#define GL_UNPACK_COMPRESSED_BLOCK_SIZE 0x912A
+#define GL_PACK_COMPRESSED_BLOCK_WIDTH 0x912B
+#define GL_PACK_COMPRESSED_BLOCK_HEIGHT 0x912C
+#define GL_PACK_COMPRESSED_BLOCK_DEPTH 0x912D
+#define GL_PACK_COMPRESSED_BLOCK_SIZE 0x912E
+#define GL_NUM_SAMPLE_COUNTS 0x9380
+#define GL_MIN_MAP_BUFFER_ALIGNMENT 0x90BC
+#define GL_ATOMIC_COUNTER_BUFFER 0x92C0
+#define GL_ATOMIC_COUNTER_BUFFER_BINDING 0x92C1
+#define GL_ATOMIC_COUNTER_BUFFER_START 0x92C2
+#define GL_ATOMIC_COUNTER_BUFFER_SIZE 0x92C3
+#define GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE 0x92C4
+#define GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS 0x92C5
+#define GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES 0x92C6
+#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER 0x92C7
+#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER 0x92C8
+#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER 0x92C9
+#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER 0x92CA
+#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER 0x92CB
+#define GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS 0x92CC
+#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS 0x92CD
+#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS 0x92CE
+#define GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS 0x92CF
+#define GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS 0x92D0
+#define GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS 0x92D1
+#define GL_MAX_VERTEX_ATOMIC_COUNTERS 0x92D2
+#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS 0x92D3
+#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS 0x92D4
+#define GL_MAX_GEOMETRY_ATOMIC_COUNTERS 0x92D5
+#define GL_MAX_FRAGMENT_ATOMIC_COUNTERS 0x92D6
+#define GL_MAX_COMBINED_ATOMIC_COUNTERS 0x92D7
+#define GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE 0x92D8
+#define GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS 0x92DC
+#define GL_ACTIVE_ATOMIC_COUNTER_BUFFERS 0x92D9
+#define GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX 0x92DA
+#define GL_UNSIGNED_INT_ATOMIC_COUNTER 0x92DB
+#define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT 0x00000001
+#define GL_ELEMENT_ARRAY_BARRIER_BIT 0x00000002
+#define GL_UNIFORM_BARRIER_BIT 0x00000004
+#define GL_TEXTURE_FETCH_BARRIER_BIT 0x00000008
+#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT 0x00000020
+#define GL_COMMAND_BARRIER_BIT 0x00000040
+#define GL_PIXEL_BUFFER_BARRIER_BIT 0x00000080
+#define GL_TEXTURE_UPDATE_BARRIER_BIT 0x00000100
+#define GL_BUFFER_UPDATE_BARRIER_BIT 0x00000200
+#define GL_FRAMEBUFFER_BARRIER_BIT 0x00000400
+#define GL_TRANSFORM_FEEDBACK_BARRIER_BIT 0x00000800
+#define GL_ATOMIC_COUNTER_BARRIER_BIT 0x00001000
+#define GL_ALL_BARRIER_BITS 0xFFFFFFFF
+#define GL_MAX_IMAGE_UNITS 0x8F38
+#define GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS 0x8F39
+#define GL_IMAGE_BINDING_NAME 0x8F3A
+#define GL_IMAGE_BINDING_LEVEL 0x8F3B
+#define GL_IMAGE_BINDING_LAYERED 0x8F3C
+#define GL_IMAGE_BINDING_LAYER 0x8F3D
+#define GL_IMAGE_BINDING_ACCESS 0x8F3E
+#define GL_IMAGE_1D 0x904C
+#define GL_IMAGE_2D 0x904D
+#define GL_IMAGE_3D 0x904E
+#define GL_IMAGE_2D_RECT 0x904F
+#define GL_IMAGE_CUBE 0x9050
+#define GL_IMAGE_BUFFER 0x9051
+#define GL_IMAGE_1D_ARRAY 0x9052
+#define GL_IMAGE_2D_ARRAY 0x9053
+#define GL_IMAGE_CUBE_MAP_ARRAY 0x9054
+#define GL_IMAGE_2D_MULTISAMPLE 0x9055
+#define GL_IMAGE_2D_MULTISAMPLE_ARRAY 0x9056
+#define GL_INT_IMAGE_1D 0x9057
+#define GL_INT_IMAGE_2D 0x9058
+#define GL_INT_IMAGE_3D 0x9059
+#define GL_INT_IMAGE_2D_RECT 0x905A
+#define GL_INT_IMAGE_CUBE 0x905B
+#define GL_INT_IMAGE_BUFFER 0x905C
+#define GL_INT_IMAGE_1D_ARRAY 0x905D
+#define GL_INT_IMAGE_2D_ARRAY 0x905E
+#define GL_INT_IMAGE_CUBE_MAP_ARRAY 0x905F
+#define GL_INT_IMAGE_2D_MULTISAMPLE 0x9060
+#define GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x9061
+#define GL_UNSIGNED_INT_IMAGE_1D 0x9062
+#define GL_UNSIGNED_INT_IMAGE_2D 0x9063
+#define GL_UNSIGNED_INT_IMAGE_3D 0x9064
+#define GL_UNSIGNED_INT_IMAGE_2D_RECT 0x9065
+#define GL_UNSIGNED_INT_IMAGE_CUBE 0x9066
+#define GL_UNSIGNED_INT_IMAGE_BUFFER 0x9067
+#define GL_UNSIGNED_INT_IMAGE_1D_ARRAY 0x9068
+#define GL_UNSIGNED_INT_IMAGE_2D_ARRAY 0x9069
+#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY 0x906A
+#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE 0x906B
+#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY 0x906C
+#define GL_MAX_IMAGE_SAMPLES 0x906D
+#define GL_IMAGE_BINDING_FORMAT 0x906E
+#define GL_IMAGE_FORMAT_COMPATIBILITY_TYPE 0x90C7
+#define GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE 0x90C8
+#define GL_IMAGE_FORMAT_COMPATIBILITY_BY_CLASS 0x90C9
+#define GL_MAX_VERTEX_IMAGE_UNIFORMS 0x90CA
+#define GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS 0x90CB
+#define GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS 0x90CC
+#define GL_MAX_GEOMETRY_IMAGE_UNIFORMS 0x90CD
+#define GL_MAX_FRAGMENT_IMAGE_UNIFORMS 0x90CE
+#define GL_MAX_COMBINED_IMAGE_UNIFORMS 0x90CF
+#define GL_COMPRESSED_RGBA_BPTC_UNORM 0x8E8C
+#define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM 0x8E8D
+#define GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT 0x8E8E
+#define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT 0x8E8F
+#define GL_TEXTURE_IMMUTABLE_FORMAT 0x912F
+typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance);
+typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance);
+typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance);
+typedef void (APIENTRYP PFNGLGETINTERNALFORMATIVPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint *params);
+typedef void (APIENTRYP PFNGLGETACTIVEATOMICCOUNTERBUFFERIVPROC) (GLuint program, GLuint bufferIndex, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLBINDIMAGETEXTUREPROC) (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format);
+typedef void (APIENTRYP PFNGLMEMORYBARRIERPROC) (GLbitfield barriers);
+typedef void (APIENTRYP PFNGLTEXSTORAGE1DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+typedef void (APIENTRYP PFNGLTEXSTORAGE2DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLTEXSTORAGE3DPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDPROC) (GLenum mode, GLuint id, GLsizei instancecount);
+typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC) (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawArraysInstancedBaseInstance (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance);
+GLAPI void APIENTRY glDrawElementsInstancedBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance);
+GLAPI void APIENTRY glDrawElementsInstancedBaseVertexBaseInstance (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance);
+GLAPI void APIENTRY glGetInternalformativ (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint *params);
+GLAPI void APIENTRY glGetActiveAtomicCounterBufferiv (GLuint program, GLuint bufferIndex, GLenum pname, GLint *params);
+GLAPI void APIENTRY glBindImageTexture (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format);
+GLAPI void APIENTRY glMemoryBarrier (GLbitfield barriers);
+GLAPI void APIENTRY glTexStorage1D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+GLAPI void APIENTRY glTexStorage2D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glTexStorage3D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+GLAPI void APIENTRY glDrawTransformFeedbackInstanced (GLenum mode, GLuint id, GLsizei instancecount);
+GLAPI void APIENTRY glDrawTransformFeedbackStreamInstanced (GLenum mode, GLuint id, GLuint stream, GLsizei instancecount);
+#endif
+#endif /* GL_VERSION_4_2 */
+
+#ifndef GL_VERSION_4_3
+#define GL_VERSION_4_3 1
+typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
+#define GL_NUM_SHADING_LANGUAGE_VERSIONS 0x82E9
+#define GL_VERTEX_ATTRIB_ARRAY_LONG 0x874E
+#define GL_COMPRESSED_RGB8_ETC2 0x9274
+#define GL_COMPRESSED_SRGB8_ETC2 0x9275
+#define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276
+#define GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9277
+#define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278
+#define GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279
+#define GL_COMPRESSED_R11_EAC 0x9270
+#define GL_COMPRESSED_SIGNED_R11_EAC 0x9271
+#define GL_COMPRESSED_RG11_EAC 0x9272
+#define GL_COMPRESSED_SIGNED_RG11_EAC 0x9273
+#define GL_PRIMITIVE_RESTART_FIXED_INDEX 0x8D69
+#define GL_ANY_SAMPLES_PASSED_CONSERVATIVE 0x8D6A
+#define GL_MAX_ELEMENT_INDEX 0x8D6B
+#define GL_COMPUTE_SHADER 0x91B9
+#define GL_MAX_COMPUTE_UNIFORM_BLOCKS 0x91BB
+#define GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS 0x91BC
+#define GL_MAX_COMPUTE_IMAGE_UNIFORMS 0x91BD
+#define GL_MAX_COMPUTE_SHARED_MEMORY_SIZE 0x8262
+#define GL_MAX_COMPUTE_UNIFORM_COMPONENTS 0x8263
+#define GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS 0x8264
+#define GL_MAX_COMPUTE_ATOMIC_COUNTERS 0x8265
+#define GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS 0x8266
+#define GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS 0x90EB
+#define GL_MAX_COMPUTE_WORK_GROUP_COUNT 0x91BE
+#define GL_MAX_COMPUTE_WORK_GROUP_SIZE 0x91BF
+#define GL_COMPUTE_WORK_GROUP_SIZE 0x8267
+#define GL_UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER 0x90EC
+#define GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_COMPUTE_SHADER 0x90ED
+#define GL_DISPATCH_INDIRECT_BUFFER 0x90EE
+#define GL_DISPATCH_INDIRECT_BUFFER_BINDING 0x90EF
+#define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242
+#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH 0x8243
+#define GL_DEBUG_CALLBACK_FUNCTION 0x8244
+#define GL_DEBUG_CALLBACK_USER_PARAM 0x8245
+#define GL_DEBUG_SOURCE_API 0x8246
+#define GL_DEBUG_SOURCE_WINDOW_SYSTEM 0x8247
+#define GL_DEBUG_SOURCE_SHADER_COMPILER 0x8248
+#define GL_DEBUG_SOURCE_THIRD_PARTY 0x8249
+#define GL_DEBUG_SOURCE_APPLICATION 0x824A
+#define GL_DEBUG_SOURCE_OTHER 0x824B
+#define GL_DEBUG_TYPE_ERROR 0x824C
+#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR 0x824D
+#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR 0x824E
+#define GL_DEBUG_TYPE_PORTABILITY 0x824F
+#define GL_DEBUG_TYPE_PERFORMANCE 0x8250
+#define GL_DEBUG_TYPE_OTHER 0x8251
+#define GL_MAX_DEBUG_MESSAGE_LENGTH 0x9143
+#define GL_MAX_DEBUG_LOGGED_MESSAGES 0x9144
+#define GL_DEBUG_LOGGED_MESSAGES 0x9145
+#define GL_DEBUG_SEVERITY_HIGH 0x9146
+#define GL_DEBUG_SEVERITY_MEDIUM 0x9147
+#define GL_DEBUG_SEVERITY_LOW 0x9148
+#define GL_DEBUG_TYPE_MARKER 0x8268
+#define GL_DEBUG_TYPE_PUSH_GROUP 0x8269
+#define GL_DEBUG_TYPE_POP_GROUP 0x826A
+#define GL_DEBUG_SEVERITY_NOTIFICATION 0x826B
+#define GL_MAX_DEBUG_GROUP_STACK_DEPTH 0x826C
+#define GL_DEBUG_GROUP_STACK_DEPTH 0x826D
+#define GL_BUFFER 0x82E0
+#define GL_SHADER 0x82E1
+#define GL_PROGRAM 0x82E2
+#define GL_QUERY 0x82E3
+#define GL_PROGRAM_PIPELINE 0x82E4
+#define GL_SAMPLER 0x82E6
+#define GL_MAX_LABEL_LENGTH 0x82E8
+#define GL_DEBUG_OUTPUT 0x92E0
+#define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002
+#define GL_MAX_UNIFORM_LOCATIONS 0x826E
+#define GL_FRAMEBUFFER_DEFAULT_WIDTH 0x9310
+#define GL_FRAMEBUFFER_DEFAULT_HEIGHT 0x9311
+#define GL_FRAMEBUFFER_DEFAULT_LAYERS 0x9312
+#define GL_FRAMEBUFFER_DEFAULT_SAMPLES 0x9313
+#define GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS 0x9314
+#define GL_MAX_FRAMEBUFFER_WIDTH 0x9315
+#define GL_MAX_FRAMEBUFFER_HEIGHT 0x9316
+#define GL_MAX_FRAMEBUFFER_LAYERS 0x9317
+#define GL_MAX_FRAMEBUFFER_SAMPLES 0x9318
+#define GL_INTERNALFORMAT_SUPPORTED 0x826F
+#define GL_INTERNALFORMAT_PREFERRED 0x8270
+#define GL_INTERNALFORMAT_RED_SIZE 0x8271
+#define GL_INTERNALFORMAT_GREEN_SIZE 0x8272
+#define GL_INTERNALFORMAT_BLUE_SIZE 0x8273
+#define GL_INTERNALFORMAT_ALPHA_SIZE 0x8274
+#define GL_INTERNALFORMAT_DEPTH_SIZE 0x8275
+#define GL_INTERNALFORMAT_STENCIL_SIZE 0x8276
+#define GL_INTERNALFORMAT_SHARED_SIZE 0x8277
+#define GL_INTERNALFORMAT_RED_TYPE 0x8278
+#define GL_INTERNALFORMAT_GREEN_TYPE 0x8279
+#define GL_INTERNALFORMAT_BLUE_TYPE 0x827A
+#define GL_INTERNALFORMAT_ALPHA_TYPE 0x827B
+#define GL_INTERNALFORMAT_DEPTH_TYPE 0x827C
+#define GL_INTERNALFORMAT_STENCIL_TYPE 0x827D
+#define GL_MAX_WIDTH 0x827E
+#define GL_MAX_HEIGHT 0x827F
+#define GL_MAX_DEPTH 0x8280
+#define GL_MAX_LAYERS 0x8281
+#define GL_MAX_COMBINED_DIMENSIONS 0x8282
+#define GL_COLOR_COMPONENTS 0x8283
+#define GL_DEPTH_COMPONENTS 0x8284
+#define GL_STENCIL_COMPONENTS 0x8285
+#define GL_COLOR_RENDERABLE 0x8286
+#define GL_DEPTH_RENDERABLE 0x8287
+#define GL_STENCIL_RENDERABLE 0x8288
+#define GL_FRAMEBUFFER_RENDERABLE 0x8289
+#define GL_FRAMEBUFFER_RENDERABLE_LAYERED 0x828A
+#define GL_FRAMEBUFFER_BLEND 0x828B
+#define GL_READ_PIXELS 0x828C
+#define GL_READ_PIXELS_FORMAT 0x828D
+#define GL_READ_PIXELS_TYPE 0x828E
+#define GL_TEXTURE_IMAGE_FORMAT 0x828F
+#define GL_TEXTURE_IMAGE_TYPE 0x8290
+#define GL_GET_TEXTURE_IMAGE_FORMAT 0x8291
+#define GL_GET_TEXTURE_IMAGE_TYPE 0x8292
+#define GL_MIPMAP 0x8293
+#define GL_MANUAL_GENERATE_MIPMAP 0x8294
+#define GL_AUTO_GENERATE_MIPMAP 0x8295
+#define GL_COLOR_ENCODING 0x8296
+#define GL_SRGB_READ 0x8297
+#define GL_SRGB_WRITE 0x8298
+#define GL_FILTER 0x829A
+#define GL_VERTEX_TEXTURE 0x829B
+#define GL_TESS_CONTROL_TEXTURE 0x829C
+#define GL_TESS_EVALUATION_TEXTURE 0x829D
+#define GL_GEOMETRY_TEXTURE 0x829E
+#define GL_FRAGMENT_TEXTURE 0x829F
+#define GL_COMPUTE_TEXTURE 0x82A0
+#define GL_TEXTURE_SHADOW 0x82A1
+#define GL_TEXTURE_GATHER 0x82A2
+#define GL_TEXTURE_GATHER_SHADOW 0x82A3
+#define GL_SHADER_IMAGE_LOAD 0x82A4
+#define GL_SHADER_IMAGE_STORE 0x82A5
+#define GL_SHADER_IMAGE_ATOMIC 0x82A6
+#define GL_IMAGE_TEXEL_SIZE 0x82A7
+#define GL_IMAGE_COMPATIBILITY_CLASS 0x82A8
+#define GL_IMAGE_PIXEL_FORMAT 0x82A9
+#define GL_IMAGE_PIXEL_TYPE 0x82AA
+#define GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST 0x82AC
+#define GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST 0x82AD
+#define GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE 0x82AE
+#define GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE 0x82AF
+#define GL_TEXTURE_COMPRESSED_BLOCK_WIDTH 0x82B1
+#define GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT 0x82B2
+#define GL_TEXTURE_COMPRESSED_BLOCK_SIZE 0x82B3
+#define GL_CLEAR_BUFFER 0x82B4
+#define GL_TEXTURE_VIEW 0x82B5
+#define GL_VIEW_COMPATIBILITY_CLASS 0x82B6
+#define GL_FULL_SUPPORT 0x82B7
+#define GL_CAVEAT_SUPPORT 0x82B8
+#define GL_IMAGE_CLASS_4_X_32 0x82B9
+#define GL_IMAGE_CLASS_2_X_32 0x82BA
+#define GL_IMAGE_CLASS_1_X_32 0x82BB
+#define GL_IMAGE_CLASS_4_X_16 0x82BC
+#define GL_IMAGE_CLASS_2_X_16 0x82BD
+#define GL_IMAGE_CLASS_1_X_16 0x82BE
+#define GL_IMAGE_CLASS_4_X_8 0x82BF
+#define GL_IMAGE_CLASS_2_X_8 0x82C0
+#define GL_IMAGE_CLASS_1_X_8 0x82C1
+#define GL_IMAGE_CLASS_11_11_10 0x82C2
+#define GL_IMAGE_CLASS_10_10_10_2 0x82C3
+#define GL_VIEW_CLASS_128_BITS 0x82C4
+#define GL_VIEW_CLASS_96_BITS 0x82C5
+#define GL_VIEW_CLASS_64_BITS 0x82C6
+#define GL_VIEW_CLASS_48_BITS 0x82C7
+#define GL_VIEW_CLASS_32_BITS 0x82C8
+#define GL_VIEW_CLASS_24_BITS 0x82C9
+#define GL_VIEW_CLASS_16_BITS 0x82CA
+#define GL_VIEW_CLASS_8_BITS 0x82CB
+#define GL_VIEW_CLASS_S3TC_DXT1_RGB 0x82CC
+#define GL_VIEW_CLASS_S3TC_DXT1_RGBA 0x82CD
+#define GL_VIEW_CLASS_S3TC_DXT3_RGBA 0x82CE
+#define GL_VIEW_CLASS_S3TC_DXT5_RGBA 0x82CF
+#define GL_VIEW_CLASS_RGTC1_RED 0x82D0
+#define GL_VIEW_CLASS_RGTC2_RG 0x82D1
+#define GL_VIEW_CLASS_BPTC_UNORM 0x82D2
+#define GL_VIEW_CLASS_BPTC_FLOAT 0x82D3
+#define GL_UNIFORM 0x92E1
+#define GL_UNIFORM_BLOCK 0x92E2
+#define GL_PROGRAM_INPUT 0x92E3
+#define GL_PROGRAM_OUTPUT 0x92E4
+#define GL_BUFFER_VARIABLE 0x92E5
+#define GL_SHADER_STORAGE_BLOCK 0x92E6
+#define GL_VERTEX_SUBROUTINE 0x92E8
+#define GL_TESS_CONTROL_SUBROUTINE 0x92E9
+#define GL_TESS_EVALUATION_SUBROUTINE 0x92EA
+#define GL_GEOMETRY_SUBROUTINE 0x92EB
+#define GL_FRAGMENT_SUBROUTINE 0x92EC
+#define GL_COMPUTE_SUBROUTINE 0x92ED
+#define GL_VERTEX_SUBROUTINE_UNIFORM 0x92EE
+#define GL_TESS_CONTROL_SUBROUTINE_UNIFORM 0x92EF
+#define GL_TESS_EVALUATION_SUBROUTINE_UNIFORM 0x92F0
+#define GL_GEOMETRY_SUBROUTINE_UNIFORM 0x92F1
+#define GL_FRAGMENT_SUBROUTINE_UNIFORM 0x92F2
+#define GL_COMPUTE_SUBROUTINE_UNIFORM 0x92F3
+#define GL_TRANSFORM_FEEDBACK_VARYING 0x92F4
+#define GL_ACTIVE_RESOURCES 0x92F5
+#define GL_MAX_NAME_LENGTH 0x92F6
+#define GL_MAX_NUM_ACTIVE_VARIABLES 0x92F7
+#define GL_MAX_NUM_COMPATIBLE_SUBROUTINES 0x92F8
+#define GL_NAME_LENGTH 0x92F9
+#define GL_TYPE 0x92FA
+#define GL_ARRAY_SIZE 0x92FB
+#define GL_OFFSET 0x92FC
+#define GL_BLOCK_INDEX 0x92FD
+#define GL_ARRAY_STRIDE 0x92FE
+#define GL_MATRIX_STRIDE 0x92FF
+#define GL_IS_ROW_MAJOR 0x9300
+#define GL_ATOMIC_COUNTER_BUFFER_INDEX 0x9301
+#define GL_BUFFER_BINDING 0x9302
+#define GL_BUFFER_DATA_SIZE 0x9303
+#define GL_NUM_ACTIVE_VARIABLES 0x9304
+#define GL_ACTIVE_VARIABLES 0x9305
+#define GL_REFERENCED_BY_VERTEX_SHADER 0x9306
+#define GL_REFERENCED_BY_TESS_CONTROL_SHADER 0x9307
+#define GL_REFERENCED_BY_TESS_EVALUATION_SHADER 0x9308
+#define GL_REFERENCED_BY_GEOMETRY_SHADER 0x9309
+#define GL_REFERENCED_BY_FRAGMENT_SHADER 0x930A
+#define GL_REFERENCED_BY_COMPUTE_SHADER 0x930B
+#define GL_TOP_LEVEL_ARRAY_SIZE 0x930C
+#define GL_TOP_LEVEL_ARRAY_STRIDE 0x930D
+#define GL_LOCATION 0x930E
+#define GL_LOCATION_INDEX 0x930F
+#define GL_IS_PER_PATCH 0x92E7
+#define GL_SHADER_STORAGE_BUFFER 0x90D2
+#define GL_SHADER_STORAGE_BUFFER_BINDING 0x90D3
+#define GL_SHADER_STORAGE_BUFFER_START 0x90D4
+#define GL_SHADER_STORAGE_BUFFER_SIZE 0x90D5
+#define GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS 0x90D6
+#define GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS 0x90D7
+#define GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS 0x90D8
+#define GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS 0x90D9
+#define GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS 0x90DA
+#define GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS 0x90DB
+#define GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS 0x90DC
+#define GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS 0x90DD
+#define GL_MAX_SHADER_STORAGE_BLOCK_SIZE 0x90DE
+#define GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT 0x90DF
+#define GL_SHADER_STORAGE_BARRIER_BIT 0x00002000
+#define GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES 0x8F39
+#define GL_DEPTH_STENCIL_TEXTURE_MODE 0x90EA
+#define GL_TEXTURE_BUFFER_OFFSET 0x919D
+#define GL_TEXTURE_BUFFER_SIZE 0x919E
+#define GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT 0x919F
+#define GL_TEXTURE_VIEW_MIN_LEVEL 0x82DB
+#define GL_TEXTURE_VIEW_NUM_LEVELS 0x82DC
+#define GL_TEXTURE_VIEW_MIN_LAYER 0x82DD
+#define GL_TEXTURE_VIEW_NUM_LAYERS 0x82DE
+#define GL_TEXTURE_IMMUTABLE_LEVELS 0x82DF
+#define GL_VERTEX_ATTRIB_BINDING 0x82D4
+#define GL_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D5
+#define GL_VERTEX_BINDING_DIVISOR 0x82D6
+#define GL_VERTEX_BINDING_OFFSET 0x82D7
+#define GL_VERTEX_BINDING_STRIDE 0x82D8
+#define GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET 0x82D9
+#define GL_MAX_VERTEX_ATTRIB_BINDINGS 0x82DA
+#define GL_VERTEX_BINDING_BUFFER 0x8F4F
+#define GL_DISPLAY_LIST 0x82E7
+typedef void (APIENTRYP PFNGLCLEARBUFFERDATAPROC) (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void *data);
+typedef void (APIENTRYP PFNGLCLEARBUFFERSUBDATAPROC) (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data);
+typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEPROC) (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z);
+typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEINDIRECTPROC) (GLintptr indirect);
+typedef void (APIENTRYP PFNGLCOPYIMAGESUBDATAPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETINTERNALFORMATI64VPROC) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64 *params);
+typedef void (APIENTRYP PFNGLINVALIDATETEXSUBIMAGEPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth);
+typedef void (APIENTRYP PFNGLINVALIDATETEXIMAGEPROC) (GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLINVALIDATEBUFFERSUBDATAPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length);
+typedef void (APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC) (GLuint buffer);
+typedef void (APIENTRYP PFNGLINVALIDATEFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments);
+typedef void (APIENTRYP PFNGLINVALIDATESUBFRAMEBUFFERPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTPROC) (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride);
+typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride);
+typedef void (APIENTRYP PFNGLGETPROGRAMINTERFACEIVPROC) (GLuint program, GLenum programInterface, GLenum pname, GLint *params);
+typedef GLuint (APIENTRYP PFNGLGETPROGRAMRESOURCEINDEXPROC) (GLuint program, GLenum programInterface, const GLchar *name);
+typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCENAMEPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name);
+typedef void (APIENTRYP PFNGLGETPROGRAMRESOURCEIVPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLint *params);
+typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONPROC) (GLuint program, GLenum programInterface, const GLchar *name);
+typedef GLint (APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONINDEXPROC) (GLuint program, GLenum programInterface, const GLchar *name);
+typedef void (APIENTRYP PFNGLSHADERSTORAGEBLOCKBINDINGPROC) (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding);
+typedef void (APIENTRYP PFNGLTEXBUFFERRANGEPROC) (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size);
+typedef void (APIENTRYP PFNGLTEXSTORAGE2DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
+typedef void (APIENTRYP PFNGLTEXSTORAGE3DMULTISAMPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations);
+typedef void (APIENTRYP PFNGLTEXTUREVIEWPROC) (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers);
+typedef void (APIENTRYP PFNGLBINDVERTEXBUFFERPROC) (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBIFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBLFORMATPROC) (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBBINDINGPROC) (GLuint attribindex, GLuint bindingindex);
+typedef void (APIENTRYP PFNGLVERTEXBINDINGDIVISORPROC) (GLuint bindingindex, GLuint divisor);
+typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
+typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf);
+typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKPROC) (GLDEBUGPROC callback, const void *userParam);
+typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGPROC) (GLuint count, GLsizei bufSize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog);
+typedef void (APIENTRYP PFNGLPUSHDEBUGGROUPPROC) (GLenum source, GLuint id, GLsizei length, const GLchar *message);
+typedef void (APIENTRYP PFNGLPOPDEBUGGROUPPROC) (void);
+typedef void (APIENTRYP PFNGLOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei length, const GLchar *label);
+typedef void (APIENTRYP PFNGLGETOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label);
+typedef void (APIENTRYP PFNGLOBJECTPTRLABELPROC) (const void *ptr, GLsizei length, const GLchar *label);
+typedef void (APIENTRYP PFNGLGETOBJECTPTRLABELPROC) (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glClearBufferData (GLenum target, GLenum internalformat, GLenum format, GLenum type, const void *data);
+GLAPI void APIENTRY glClearBufferSubData (GLenum target, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data);
+GLAPI void APIENTRY glDispatchCompute (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z);
+GLAPI void APIENTRY glDispatchComputeIndirect (GLintptr indirect);
+GLAPI void APIENTRY glCopyImageSubData (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth);
+GLAPI void APIENTRY glFramebufferParameteri (GLenum target, GLenum pname, GLint param);
+GLAPI void APIENTRY glGetFramebufferParameteriv (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetInternalformati64v (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64 *params);
+GLAPI void APIENTRY glInvalidateTexSubImage (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth);
+GLAPI void APIENTRY glInvalidateTexImage (GLuint texture, GLint level);
+GLAPI void APIENTRY glInvalidateBufferSubData (GLuint buffer, GLintptr offset, GLsizeiptr length);
+GLAPI void APIENTRY glInvalidateBufferData (GLuint buffer);
+GLAPI void APIENTRY glInvalidateFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments);
+GLAPI void APIENTRY glInvalidateSubFramebuffer (GLenum target, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glMultiDrawArraysIndirect (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride);
+GLAPI void APIENTRY glMultiDrawElementsIndirect (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride);
+GLAPI void APIENTRY glGetProgramInterfaceiv (GLuint program, GLenum programInterface, GLenum pname, GLint *params);
+GLAPI GLuint APIENTRY glGetProgramResourceIndex (GLuint program, GLenum programInterface, const GLchar *name);
+GLAPI void APIENTRY glGetProgramResourceName (GLuint program, GLenum programInterface, GLuint index, GLsizei bufSize, GLsizei *length, GLchar *name);
+GLAPI void APIENTRY glGetProgramResourceiv (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLint *params);
+GLAPI GLint APIENTRY glGetProgramResourceLocation (GLuint program, GLenum programInterface, const GLchar *name);
+GLAPI GLint APIENTRY glGetProgramResourceLocationIndex (GLuint program, GLenum programInterface, const GLchar *name);
+GLAPI void APIENTRY glShaderStorageBlockBinding (GLuint program, GLuint storageBlockIndex, GLuint storageBlockBinding);
+GLAPI void APIENTRY glTexBufferRange (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size);
+GLAPI void APIENTRY glTexStorage2DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
+GLAPI void APIENTRY glTexStorage3DMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations);
+GLAPI void APIENTRY glTextureView (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers);
+GLAPI void APIENTRY glBindVertexBuffer (GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride);
+GLAPI void APIENTRY glVertexAttribFormat (GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset);
+GLAPI void APIENTRY glVertexAttribIFormat (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
+GLAPI void APIENTRY glVertexAttribLFormat (GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
+GLAPI void APIENTRY glVertexAttribBinding (GLuint attribindex, GLuint bindingindex);
+GLAPI void APIENTRY glVertexBindingDivisor (GLuint bindingindex, GLuint divisor);
+GLAPI void APIENTRY glDebugMessageControl (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
+GLAPI void APIENTRY glDebugMessageInsert (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf);
+GLAPI void APIENTRY glDebugMessageCallback (GLDEBUGPROC callback, const void *userParam);
+GLAPI GLuint APIENTRY glGetDebugMessageLog (GLuint count, GLsizei bufSize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog);
+GLAPI void APIENTRY glPushDebugGroup (GLenum source, GLuint id, GLsizei length, const GLchar *message);
+GLAPI void APIENTRY glPopDebugGroup (void);
+GLAPI void APIENTRY glObjectLabel (GLenum identifier, GLuint name, GLsizei length, const GLchar *label);
+GLAPI void APIENTRY glGetObjectLabel (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label);
+GLAPI void APIENTRY glObjectPtrLabel (const void *ptr, GLsizei length, const GLchar *label);
+GLAPI void APIENTRY glGetObjectPtrLabel (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label);
+#endif
+#endif /* GL_VERSION_4_3 */
+
+#ifndef GL_VERSION_4_4
+#define GL_VERSION_4_4 1
+#define GL_MAX_VERTEX_ATTRIB_STRIDE 0x82E5
+#define GL_PRIMITIVE_RESTART_FOR_PATCHES_SUPPORTED 0x8221
+#define GL_TEXTURE_BUFFER_BINDING 0x8C2A
+#define GL_MAP_PERSISTENT_BIT 0x0040
+#define GL_MAP_COHERENT_BIT 0x0080
+#define GL_DYNAMIC_STORAGE_BIT 0x0100
+#define GL_CLIENT_STORAGE_BIT 0x0200
+#define GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT 0x00004000
+#define GL_BUFFER_IMMUTABLE_STORAGE 0x821F
+#define GL_BUFFER_STORAGE_FLAGS 0x8220
+#define GL_CLEAR_TEXTURE 0x9365
+#define GL_LOCATION_COMPONENT 0x934A
+#define GL_TRANSFORM_FEEDBACK_BUFFER_INDEX 0x934B
+#define GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE 0x934C
+#define GL_QUERY_BUFFER 0x9192
+#define GL_QUERY_BUFFER_BARRIER_BIT 0x00008000
+#define GL_QUERY_BUFFER_BINDING 0x9193
+#define GL_QUERY_RESULT_NO_WAIT 0x9194
+#define GL_MIRROR_CLAMP_TO_EDGE 0x8743
+typedef void (APIENTRYP PFNGLBUFFERSTORAGEPROC) (GLenum target, GLsizeiptr size, const void *data, GLbitfield flags);
+typedef void (APIENTRYP PFNGLCLEARTEXIMAGEPROC) (GLuint texture, GLint level, GLenum format, GLenum type, const void *data);
+typedef void (APIENTRYP PFNGLCLEARTEXSUBIMAGEPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *data);
+typedef void (APIENTRYP PFNGLBINDBUFFERSBASEPROC) (GLenum target, GLuint first, GLsizei count, const GLuint *buffers);
+typedef void (APIENTRYP PFNGLBINDBUFFERSRANGEPROC) (GLenum target, GLuint first, GLsizei count, const GLuint *buffers, const GLintptr *offsets, const GLsizeiptr *sizes);
+typedef void (APIENTRYP PFNGLBINDTEXTURESPROC) (GLuint first, GLsizei count, const GLuint *textures);
+typedef void (APIENTRYP PFNGLBINDSAMPLERSPROC) (GLuint first, GLsizei count, const GLuint *samplers);
+typedef void (APIENTRYP PFNGLBINDIMAGETEXTURESPROC) (GLuint first, GLsizei count, const GLuint *textures);
+typedef void (APIENTRYP PFNGLBINDVERTEXBUFFERSPROC) (GLuint first, GLsizei count, const GLuint *buffers, const GLintptr *offsets, const GLsizei *strides);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBufferStorage (GLenum target, GLsizeiptr size, const void *data, GLbitfield flags);
+GLAPI void APIENTRY glClearTexImage (GLuint texture, GLint level, GLenum format, GLenum type, const void *data);
+GLAPI void APIENTRY glClearTexSubImage (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *data);
+GLAPI void APIENTRY glBindBuffersBase (GLenum target, GLuint first, GLsizei count, const GLuint *buffers);
+GLAPI void APIENTRY glBindBuffersRange (GLenum target, GLuint first, GLsizei count, const GLuint *buffers, const GLintptr *offsets, const GLsizeiptr *sizes);
+GLAPI void APIENTRY glBindTextures (GLuint first, GLsizei count, const GLuint *textures);
+GLAPI void APIENTRY glBindSamplers (GLuint first, GLsizei count, const GLuint *samplers);
+GLAPI void APIENTRY glBindImageTextures (GLuint first, GLsizei count, const GLuint *textures);
+GLAPI void APIENTRY glBindVertexBuffers (GLuint first, GLsizei count, const GLuint *buffers, const GLintptr *offsets, const GLsizei *strides);
+#endif
+#endif /* GL_VERSION_4_4 */
+
+#ifndef GL_ARB_ES2_compatibility
+#define GL_ARB_ES2_compatibility 1
+#endif /* GL_ARB_ES2_compatibility */
+
+#ifndef GL_ARB_ES3_compatibility
+#define GL_ARB_ES3_compatibility 1
+#endif /* GL_ARB_ES3_compatibility */
+
+#ifndef GL_ARB_arrays_of_arrays
+#define GL_ARB_arrays_of_arrays 1
+#endif /* GL_ARB_arrays_of_arrays */
+
+#ifndef GL_ARB_base_instance
+#define GL_ARB_base_instance 1
+#endif /* GL_ARB_base_instance */
+
+#ifndef GL_ARB_bindless_texture
+#define GL_ARB_bindless_texture 1
+typedef uint64_t GLuint64EXT;
+#define GL_UNSIGNED_INT64_ARB 0x140F
+typedef GLuint64 (APIENTRYP PFNGLGETTEXTUREHANDLEARBPROC) (GLuint texture);
+typedef GLuint64 (APIENTRYP PFNGLGETTEXTURESAMPLERHANDLEARBPROC) (GLuint texture, GLuint sampler);
+typedef void (APIENTRYP PFNGLMAKETEXTUREHANDLERESIDENTARBPROC) (GLuint64 handle);
+typedef void (APIENTRYP PFNGLMAKETEXTUREHANDLENONRESIDENTARBPROC) (GLuint64 handle);
+typedef GLuint64 (APIENTRYP PFNGLGETIMAGEHANDLEARBPROC) (GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format);
+typedef void (APIENTRYP PFNGLMAKEIMAGEHANDLERESIDENTARBPROC) (GLuint64 handle, GLenum access);
+typedef void (APIENTRYP PFNGLMAKEIMAGEHANDLENONRESIDENTARBPROC) (GLuint64 handle);
+typedef void (APIENTRYP PFNGLUNIFORMHANDLEUI64ARBPROC) (GLint location, GLuint64 value);
+typedef void (APIENTRYP PFNGLUNIFORMHANDLEUI64VARBPROC) (GLint location, GLsizei count, const GLuint64 *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64ARBPROC) (GLuint program, GLint location, GLuint64 value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64VARBPROC) (GLuint program, GLint location, GLsizei count, const GLuint64 *values);
+typedef GLboolean (APIENTRYP PFNGLISTEXTUREHANDLERESIDENTARBPROC) (GLuint64 handle);
+typedef GLboolean (APIENTRYP PFNGLISIMAGEHANDLERESIDENTARBPROC) (GLuint64 handle);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64ARBPROC) (GLuint index, GLuint64EXT x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64VARBPROC) (GLuint index, const GLuint64EXT *v);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLUI64VARBPROC) (GLuint index, GLenum pname, GLuint64EXT *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLuint64 APIENTRY glGetTextureHandleARB (GLuint texture);
+GLAPI GLuint64 APIENTRY glGetTextureSamplerHandleARB (GLuint texture, GLuint sampler);
+GLAPI void APIENTRY glMakeTextureHandleResidentARB (GLuint64 handle);
+GLAPI void APIENTRY glMakeTextureHandleNonResidentARB (GLuint64 handle);
+GLAPI GLuint64 APIENTRY glGetImageHandleARB (GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format);
+GLAPI void APIENTRY glMakeImageHandleResidentARB (GLuint64 handle, GLenum access);
+GLAPI void APIENTRY glMakeImageHandleNonResidentARB (GLuint64 handle);
+GLAPI void APIENTRY glUniformHandleui64ARB (GLint location, GLuint64 value);
+GLAPI void APIENTRY glUniformHandleui64vARB (GLint location, GLsizei count, const GLuint64 *value);
+GLAPI void APIENTRY glProgramUniformHandleui64ARB (GLuint program, GLint location, GLuint64 value);
+GLAPI void APIENTRY glProgramUniformHandleui64vARB (GLuint program, GLint location, GLsizei count, const GLuint64 *values);
+GLAPI GLboolean APIENTRY glIsTextureHandleResidentARB (GLuint64 handle);
+GLAPI GLboolean APIENTRY glIsImageHandleResidentARB (GLuint64 handle);
+GLAPI void APIENTRY glVertexAttribL1ui64ARB (GLuint index, GLuint64EXT x);
+GLAPI void APIENTRY glVertexAttribL1ui64vARB (GLuint index, const GLuint64EXT *v);
+GLAPI void APIENTRY glGetVertexAttribLui64vARB (GLuint index, GLenum pname, GLuint64EXT *params);
+#endif
+#endif /* GL_ARB_bindless_texture */
+
+#ifndef GL_ARB_blend_func_extended
+#define GL_ARB_blend_func_extended 1
+#endif /* GL_ARB_blend_func_extended */
+
+#ifndef GL_ARB_buffer_storage
+#define GL_ARB_buffer_storage 1
+#endif /* GL_ARB_buffer_storage */
+
+#ifndef GL_ARB_cl_event
+#define GL_ARB_cl_event 1
+struct _cl_context;
+struct _cl_event;
+#define GL_SYNC_CL_EVENT_ARB 0x8240
+#define GL_SYNC_CL_EVENT_COMPLETE_ARB 0x8241
+typedef GLsync (APIENTRYP PFNGLCREATESYNCFROMCLEVENTARBPROC) (struct _cl_context *context, struct _cl_event *event, GLbitfield flags);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLsync APIENTRY glCreateSyncFromCLeventARB (struct _cl_context *context, struct _cl_event *event, GLbitfield flags);
+#endif
+#endif /* GL_ARB_cl_event */
+
+#ifndef GL_ARB_clear_buffer_object
+#define GL_ARB_clear_buffer_object 1
+#endif /* GL_ARB_clear_buffer_object */
+
+#ifndef GL_ARB_clear_texture
+#define GL_ARB_clear_texture 1
+#endif /* GL_ARB_clear_texture */
+
+#ifndef GL_ARB_color_buffer_float
+#define GL_ARB_color_buffer_float 1
+#define GL_RGBA_FLOAT_MODE_ARB 0x8820
+#define GL_CLAMP_VERTEX_COLOR_ARB 0x891A
+#define GL_CLAMP_FRAGMENT_COLOR_ARB 0x891B
+#define GL_CLAMP_READ_COLOR_ARB 0x891C
+#define GL_FIXED_ONLY_ARB 0x891D
+typedef void (APIENTRYP PFNGLCLAMPCOLORARBPROC) (GLenum target, GLenum clamp);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glClampColorARB (GLenum target, GLenum clamp);
+#endif
+#endif /* GL_ARB_color_buffer_float */
+
+#ifndef GL_ARB_compatibility
+#define GL_ARB_compatibility 1
+#endif /* GL_ARB_compatibility */
+
+#ifndef GL_ARB_compressed_texture_pixel_storage
+#define GL_ARB_compressed_texture_pixel_storage 1
+#endif /* GL_ARB_compressed_texture_pixel_storage */
+
+#ifndef GL_ARB_compute_shader
+#define GL_ARB_compute_shader 1
+#define GL_COMPUTE_SHADER_BIT 0x00000020
+#endif /* GL_ARB_compute_shader */
+
+#ifndef GL_ARB_compute_variable_group_size
+#define GL_ARB_compute_variable_group_size 1
+#define GL_MAX_COMPUTE_VARIABLE_GROUP_INVOCATIONS_ARB 0x9344
+#define GL_MAX_COMPUTE_FIXED_GROUP_INVOCATIONS_ARB 0x90EB
+#define GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB 0x9345
+#define GL_MAX_COMPUTE_FIXED_GROUP_SIZE_ARB 0x91BF
+typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEGROUPSIZEARBPROC) (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z, GLuint group_size_x, GLuint group_size_y, GLuint group_size_z);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDispatchComputeGroupSizeARB (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z, GLuint group_size_x, GLuint group_size_y, GLuint group_size_z);
+#endif
+#endif /* GL_ARB_compute_variable_group_size */
+
+#ifndef GL_ARB_conservative_depth
+#define GL_ARB_conservative_depth 1
+#endif /* GL_ARB_conservative_depth */
+
+#ifndef GL_ARB_copy_buffer
+#define GL_ARB_copy_buffer 1
+#define GL_COPY_READ_BUFFER_BINDING 0x8F36
+#define GL_COPY_WRITE_BUFFER_BINDING 0x8F37
+#endif /* GL_ARB_copy_buffer */
+
+#ifndef GL_ARB_copy_image
+#define GL_ARB_copy_image 1
+#endif /* GL_ARB_copy_image */
+
+#ifndef GL_ARB_debug_output
+#define GL_ARB_debug_output 1
+typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
+#define GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB 0x8242
+#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_ARB 0x8243
+#define GL_DEBUG_CALLBACK_FUNCTION_ARB 0x8244
+#define GL_DEBUG_CALLBACK_USER_PARAM_ARB 0x8245
+#define GL_DEBUG_SOURCE_API_ARB 0x8246
+#define GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB 0x8247
+#define GL_DEBUG_SOURCE_SHADER_COMPILER_ARB 0x8248
+#define GL_DEBUG_SOURCE_THIRD_PARTY_ARB 0x8249
+#define GL_DEBUG_SOURCE_APPLICATION_ARB 0x824A
+#define GL_DEBUG_SOURCE_OTHER_ARB 0x824B
+#define GL_DEBUG_TYPE_ERROR_ARB 0x824C
+#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB 0x824D
+#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB 0x824E
+#define GL_DEBUG_TYPE_PORTABILITY_ARB 0x824F
+#define GL_DEBUG_TYPE_PERFORMANCE_ARB 0x8250
+#define GL_DEBUG_TYPE_OTHER_ARB 0x8251
+#define GL_MAX_DEBUG_MESSAGE_LENGTH_ARB 0x9143
+#define GL_MAX_DEBUG_LOGGED_MESSAGES_ARB 0x9144
+#define GL_DEBUG_LOGGED_MESSAGES_ARB 0x9145
+#define GL_DEBUG_SEVERITY_HIGH_ARB 0x9146
+#define GL_DEBUG_SEVERITY_MEDIUM_ARB 0x9147
+#define GL_DEBUG_SEVERITY_LOW_ARB 0x9148
+typedef void (APIENTRYP PFNGLDEBUGMESSAGECONTROLARBPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
+typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTARBPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf);
+typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKARBPROC) (GLDEBUGPROCARB callback, const void *userParam);
+typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGARBPROC) (GLuint count, GLsizei bufSize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDebugMessageControlARB (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
+GLAPI void APIENTRY glDebugMessageInsertARB (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf);
+GLAPI void APIENTRY glDebugMessageCallbackARB (GLDEBUGPROCARB callback, const void *userParam);
+GLAPI GLuint APIENTRY glGetDebugMessageLogARB (GLuint count, GLsizei bufSize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog);
+#endif
+#endif /* GL_ARB_debug_output */
+
+#ifndef GL_ARB_depth_buffer_float
+#define GL_ARB_depth_buffer_float 1
+#endif /* GL_ARB_depth_buffer_float */
+
+#ifndef GL_ARB_depth_clamp
+#define GL_ARB_depth_clamp 1
+#endif /* GL_ARB_depth_clamp */
+
+#ifndef GL_ARB_depth_texture
+#define GL_ARB_depth_texture 1
+#define GL_DEPTH_COMPONENT16_ARB 0x81A5
+#define GL_DEPTH_COMPONENT24_ARB 0x81A6
+#define GL_DEPTH_COMPONENT32_ARB 0x81A7
+#define GL_TEXTURE_DEPTH_SIZE_ARB 0x884A
+#define GL_DEPTH_TEXTURE_MODE_ARB 0x884B
+#endif /* GL_ARB_depth_texture */
+
+#ifndef GL_ARB_draw_buffers
+#define GL_ARB_draw_buffers 1
+#define GL_MAX_DRAW_BUFFERS_ARB 0x8824
+#define GL_DRAW_BUFFER0_ARB 0x8825
+#define GL_DRAW_BUFFER1_ARB 0x8826
+#define GL_DRAW_BUFFER2_ARB 0x8827
+#define GL_DRAW_BUFFER3_ARB 0x8828
+#define GL_DRAW_BUFFER4_ARB 0x8829
+#define GL_DRAW_BUFFER5_ARB 0x882A
+#define GL_DRAW_BUFFER6_ARB 0x882B
+#define GL_DRAW_BUFFER7_ARB 0x882C
+#define GL_DRAW_BUFFER8_ARB 0x882D
+#define GL_DRAW_BUFFER9_ARB 0x882E
+#define GL_DRAW_BUFFER10_ARB 0x882F
+#define GL_DRAW_BUFFER11_ARB 0x8830
+#define GL_DRAW_BUFFER12_ARB 0x8831
+#define GL_DRAW_BUFFER13_ARB 0x8832
+#define GL_DRAW_BUFFER14_ARB 0x8833
+#define GL_DRAW_BUFFER15_ARB 0x8834
+typedef void (APIENTRYP PFNGLDRAWBUFFERSARBPROC) (GLsizei n, const GLenum *bufs);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawBuffersARB (GLsizei n, const GLenum *bufs);
+#endif
+#endif /* GL_ARB_draw_buffers */
+
+#ifndef GL_ARB_draw_buffers_blend
+#define GL_ARB_draw_buffers_blend 1
+typedef void (APIENTRYP PFNGLBLENDEQUATIONIARBPROC) (GLuint buf, GLenum mode);
+typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEIARBPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha);
+typedef void (APIENTRYP PFNGLBLENDFUNCIARBPROC) (GLuint buf, GLenum src, GLenum dst);
+typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEIARBPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendEquationiARB (GLuint buf, GLenum mode);
+GLAPI void APIENTRY glBlendEquationSeparateiARB (GLuint buf, GLenum modeRGB, GLenum modeAlpha);
+GLAPI void APIENTRY glBlendFunciARB (GLuint buf, GLenum src, GLenum dst);
+GLAPI void APIENTRY glBlendFuncSeparateiARB (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+#endif
+#endif /* GL_ARB_draw_buffers_blend */
+
+#ifndef GL_ARB_draw_elements_base_vertex
+#define GL_ARB_draw_elements_base_vertex 1
+#endif /* GL_ARB_draw_elements_base_vertex */
+
+#ifndef GL_ARB_draw_indirect
+#define GL_ARB_draw_indirect 1
+#endif /* GL_ARB_draw_indirect */
+
+#ifndef GL_ARB_draw_instanced
+#define GL_ARB_draw_instanced 1
+typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDARBPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount);
+typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDARBPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawArraysInstancedARB (GLenum mode, GLint first, GLsizei count, GLsizei primcount);
+GLAPI void APIENTRY glDrawElementsInstancedARB (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
+#endif
+#endif /* GL_ARB_draw_instanced */
+
+#ifndef GL_ARB_enhanced_layouts
+#define GL_ARB_enhanced_layouts 1
+#endif /* GL_ARB_enhanced_layouts */
+
+#ifndef GL_ARB_explicit_attrib_location
+#define GL_ARB_explicit_attrib_location 1
+#endif /* GL_ARB_explicit_attrib_location */
+
+#ifndef GL_ARB_explicit_uniform_location
+#define GL_ARB_explicit_uniform_location 1
+#endif /* GL_ARB_explicit_uniform_location */
+
+#ifndef GL_ARB_fragment_coord_conventions
+#define GL_ARB_fragment_coord_conventions 1
+#endif /* GL_ARB_fragment_coord_conventions */
+
+#ifndef GL_ARB_fragment_layer_viewport
+#define GL_ARB_fragment_layer_viewport 1
+#endif /* GL_ARB_fragment_layer_viewport */
+
+#ifndef GL_ARB_fragment_program
+#define GL_ARB_fragment_program 1
+#define GL_FRAGMENT_PROGRAM_ARB 0x8804
+#define GL_PROGRAM_FORMAT_ASCII_ARB 0x8875
+#define GL_PROGRAM_LENGTH_ARB 0x8627
+#define GL_PROGRAM_FORMAT_ARB 0x8876
+#define GL_PROGRAM_BINDING_ARB 0x8677
+#define GL_PROGRAM_INSTRUCTIONS_ARB 0x88A0
+#define GL_MAX_PROGRAM_INSTRUCTIONS_ARB 0x88A1
+#define GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A2
+#define GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB 0x88A3
+#define GL_PROGRAM_TEMPORARIES_ARB 0x88A4
+#define GL_MAX_PROGRAM_TEMPORARIES_ARB 0x88A5
+#define GL_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A6
+#define GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB 0x88A7
+#define GL_PROGRAM_PARAMETERS_ARB 0x88A8
+#define GL_MAX_PROGRAM_PARAMETERS_ARB 0x88A9
+#define GL_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AA
+#define GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB 0x88AB
+#define GL_PROGRAM_ATTRIBS_ARB 0x88AC
+#define GL_MAX_PROGRAM_ATTRIBS_ARB 0x88AD
+#define GL_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AE
+#define GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB 0x88AF
+#define GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB 0x88B4
+#define GL_MAX_PROGRAM_ENV_PARAMETERS_ARB 0x88B5
+#define GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB 0x88B6
+#define GL_PROGRAM_ALU_INSTRUCTIONS_ARB 0x8805
+#define GL_PROGRAM_TEX_INSTRUCTIONS_ARB 0x8806
+#define GL_PROGRAM_TEX_INDIRECTIONS_ARB 0x8807
+#define GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x8808
+#define GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x8809
+#define GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x880A
+#define GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB 0x880B
+#define GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB 0x880C
+#define GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB 0x880D
+#define GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB 0x880E
+#define GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB 0x880F
+#define GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB 0x8810
+#define GL_PROGRAM_STRING_ARB 0x8628
+#define GL_PROGRAM_ERROR_POSITION_ARB 0x864B
+#define GL_CURRENT_MATRIX_ARB 0x8641
+#define GL_TRANSPOSE_CURRENT_MATRIX_ARB 0x88B7
+#define GL_CURRENT_MATRIX_STACK_DEPTH_ARB 0x8640
+#define GL_MAX_PROGRAM_MATRICES_ARB 0x862F
+#define GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB 0x862E
+#define GL_MAX_TEXTURE_COORDS_ARB 0x8871
+#define GL_MAX_TEXTURE_IMAGE_UNITS_ARB 0x8872
+#define GL_PROGRAM_ERROR_STRING_ARB 0x8874
+#define GL_MATRIX0_ARB 0x88C0
+#define GL_MATRIX1_ARB 0x88C1
+#define GL_MATRIX2_ARB 0x88C2
+#define GL_MATRIX3_ARB 0x88C3
+#define GL_MATRIX4_ARB 0x88C4
+#define GL_MATRIX5_ARB 0x88C5
+#define GL_MATRIX6_ARB 0x88C6
+#define GL_MATRIX7_ARB 0x88C7
+#define GL_MATRIX8_ARB 0x88C8
+#define GL_MATRIX9_ARB 0x88C9
+#define GL_MATRIX10_ARB 0x88CA
+#define GL_MATRIX11_ARB 0x88CB
+#define GL_MATRIX12_ARB 0x88CC
+#define GL_MATRIX13_ARB 0x88CD
+#define GL_MATRIX14_ARB 0x88CE
+#define GL_MATRIX15_ARB 0x88CF
+#define GL_MATRIX16_ARB 0x88D0
+#define GL_MATRIX17_ARB 0x88D1
+#define GL_MATRIX18_ARB 0x88D2
+#define GL_MATRIX19_ARB 0x88D3
+#define GL_MATRIX20_ARB 0x88D4
+#define GL_MATRIX21_ARB 0x88D5
+#define GL_MATRIX22_ARB 0x88D6
+#define GL_MATRIX23_ARB 0x88D7
+#define GL_MATRIX24_ARB 0x88D8
+#define GL_MATRIX25_ARB 0x88D9
+#define GL_MATRIX26_ARB 0x88DA
+#define GL_MATRIX27_ARB 0x88DB
+#define GL_MATRIX28_ARB 0x88DC
+#define GL_MATRIX29_ARB 0x88DD
+#define GL_MATRIX30_ARB 0x88DE
+#define GL_MATRIX31_ARB 0x88DF
+typedef void (APIENTRYP PFNGLPROGRAMSTRINGARBPROC) (GLenum target, GLenum format, GLsizei len, const void *string);
+typedef void (APIENTRYP PFNGLBINDPROGRAMARBPROC) (GLenum target, GLuint program);
+typedef void (APIENTRYP PFNGLDELETEPROGRAMSARBPROC) (GLsizei n, const GLuint *programs);
+typedef void (APIENTRYP PFNGLGENPROGRAMSARBPROC) (GLsizei n, GLuint *programs);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DARBPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4DVARBPROC) (GLenum target, GLuint index, const GLdouble *params);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FARBPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) (GLenum target, GLuint index, const GLfloat *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) (GLenum target, GLuint index, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC) (GLenum target, GLuint index, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGARBPROC) (GLenum target, GLenum pname, void *string);
+typedef GLboolean (APIENTRYP PFNGLISPROGRAMARBPROC) (GLuint program);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProgramStringARB (GLenum target, GLenum format, GLsizei len, const void *string);
+GLAPI void APIENTRY glBindProgramARB (GLenum target, GLuint program);
+GLAPI void APIENTRY glDeleteProgramsARB (GLsizei n, const GLuint *programs);
+GLAPI void APIENTRY glGenProgramsARB (GLsizei n, GLuint *programs);
+GLAPI void APIENTRY glProgramEnvParameter4dARB (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glProgramEnvParameter4dvARB (GLenum target, GLuint index, const GLdouble *params);
+GLAPI void APIENTRY glProgramEnvParameter4fARB (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glProgramEnvParameter4fvARB (GLenum target, GLuint index, const GLfloat *params);
+GLAPI void APIENTRY glProgramLocalParameter4dARB (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glProgramLocalParameter4dvARB (GLenum target, GLuint index, const GLdouble *params);
+GLAPI void APIENTRY glProgramLocalParameter4fARB (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glProgramLocalParameter4fvARB (GLenum target, GLuint index, const GLfloat *params);
+GLAPI void APIENTRY glGetProgramEnvParameterdvARB (GLenum target, GLuint index, GLdouble *params);
+GLAPI void APIENTRY glGetProgramEnvParameterfvARB (GLenum target, GLuint index, GLfloat *params);
+GLAPI void APIENTRY glGetProgramLocalParameterdvARB (GLenum target, GLuint index, GLdouble *params);
+GLAPI void APIENTRY glGetProgramLocalParameterfvARB (GLenum target, GLuint index, GLfloat *params);
+GLAPI void APIENTRY glGetProgramivARB (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetProgramStringARB (GLenum target, GLenum pname, void *string);
+GLAPI GLboolean APIENTRY glIsProgramARB (GLuint program);
+#endif
+#endif /* GL_ARB_fragment_program */
+
+#ifndef GL_ARB_fragment_program_shadow
+#define GL_ARB_fragment_program_shadow 1
+#endif /* GL_ARB_fragment_program_shadow */
+
+#ifndef GL_ARB_fragment_shader
+#define GL_ARB_fragment_shader 1
+#define GL_FRAGMENT_SHADER_ARB 0x8B30
+#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB 0x8B49
+#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB 0x8B8B
+#endif /* GL_ARB_fragment_shader */
+
+#ifndef GL_ARB_framebuffer_no_attachments
+#define GL_ARB_framebuffer_no_attachments 1
+#endif /* GL_ARB_framebuffer_no_attachments */
+
+#ifndef GL_ARB_framebuffer_object
+#define GL_ARB_framebuffer_object 1
+#endif /* GL_ARB_framebuffer_object */
+
+#ifndef GL_ARB_framebuffer_sRGB
+#define GL_ARB_framebuffer_sRGB 1
+#endif /* GL_ARB_framebuffer_sRGB */
+
+#ifndef GL_KHR_context_flush_control
+#define GL_CONTEXT_RELEASE_BEHAVIOR 0x82FB
+#define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH 0x82FC
+#endif /* GL_KHR_context_flush_control */
+
+#ifndef GL_ARB_geometry_shader4
+#define GL_ARB_geometry_shader4 1
+#define GL_LINES_ADJACENCY_ARB 0x000A
+#define GL_LINE_STRIP_ADJACENCY_ARB 0x000B
+#define GL_TRIANGLES_ADJACENCY_ARB 0x000C
+#define GL_TRIANGLE_STRIP_ADJACENCY_ARB 0x000D
+#define GL_PROGRAM_POINT_SIZE_ARB 0x8642
+#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_ARB 0x8C29
+#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED_ARB 0x8DA7
+#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_ARB 0x8DA8
+#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB 0x8DA9
+#define GL_GEOMETRY_SHADER_ARB 0x8DD9
+#define GL_GEOMETRY_VERTICES_OUT_ARB 0x8DDA
+#define GL_GEOMETRY_INPUT_TYPE_ARB 0x8DDB
+#define GL_GEOMETRY_OUTPUT_TYPE_ARB 0x8DDC
+#define GL_MAX_GEOMETRY_VARYING_COMPONENTS_ARB 0x8DDD
+#define GL_MAX_VERTEX_VARYING_COMPONENTS_ARB 0x8DDE
+#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_ARB 0x8DDF
+#define GL_MAX_GEOMETRY_OUTPUT_VERTICES_ARB 0x8DE0
+#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_ARB 0x8DE1
+typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIARBPROC) (GLuint program, GLenum pname, GLint value);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREFACEARBPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProgramParameteriARB (GLuint program, GLenum pname, GLint value);
+GLAPI void APIENTRY glFramebufferTextureARB (GLenum target, GLenum attachment, GLuint texture, GLint level);
+GLAPI void APIENTRY glFramebufferTextureLayerARB (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer);
+GLAPI void APIENTRY glFramebufferTextureFaceARB (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face);
+#endif
+#endif /* GL_ARB_geometry_shader4 */
+
+#ifndef GL_ARB_get_program_binary
+#define GL_ARB_get_program_binary 1
+#endif /* GL_ARB_get_program_binary */
+
+#ifndef GL_ARB_gpu_shader5
+#define GL_ARB_gpu_shader5 1
+#endif /* GL_ARB_gpu_shader5 */
+
+#ifndef GL_ARB_gpu_shader_fp64
+#define GL_ARB_gpu_shader_fp64 1
+#endif /* GL_ARB_gpu_shader_fp64 */
+
+#ifndef GL_ARB_half_float_pixel
+#define GL_ARB_half_float_pixel 1
+typedef unsigned short GLhalfARB;
+#define GL_HALF_FLOAT_ARB 0x140B
+#endif /* GL_ARB_half_float_pixel */
+
+#ifndef GL_ARB_half_float_vertex
+#define GL_ARB_half_float_vertex 1
+#endif /* GL_ARB_half_float_vertex */
+
+#ifndef GL_ARB_imaging
+#define GL_ARB_imaging 1
+#define GL_BLEND_COLOR 0x8005
+#define GL_BLEND_EQUATION 0x8009
+#define GL_CONVOLUTION_1D 0x8010
+#define GL_CONVOLUTION_2D 0x8011
+#define GL_SEPARABLE_2D 0x8012
+#define GL_CONVOLUTION_BORDER_MODE 0x8013
+#define GL_CONVOLUTION_FILTER_SCALE 0x8014
+#define GL_CONVOLUTION_FILTER_BIAS 0x8015
+#define GL_REDUCE 0x8016
+#define GL_CONVOLUTION_FORMAT 0x8017
+#define GL_CONVOLUTION_WIDTH 0x8018
+#define GL_CONVOLUTION_HEIGHT 0x8019
+#define GL_MAX_CONVOLUTION_WIDTH 0x801A
+#define GL_MAX_CONVOLUTION_HEIGHT 0x801B
+#define GL_POST_CONVOLUTION_RED_SCALE 0x801C
+#define GL_POST_CONVOLUTION_GREEN_SCALE 0x801D
+#define GL_POST_CONVOLUTION_BLUE_SCALE 0x801E
+#define GL_POST_CONVOLUTION_ALPHA_SCALE 0x801F
+#define GL_POST_CONVOLUTION_RED_BIAS 0x8020
+#define GL_POST_CONVOLUTION_GREEN_BIAS 0x8021
+#define GL_POST_CONVOLUTION_BLUE_BIAS 0x8022
+#define GL_POST_CONVOLUTION_ALPHA_BIAS 0x8023
+#define GL_HISTOGRAM 0x8024
+#define GL_PROXY_HISTOGRAM 0x8025
+#define GL_HISTOGRAM_WIDTH 0x8026
+#define GL_HISTOGRAM_FORMAT 0x8027
+#define GL_HISTOGRAM_RED_SIZE 0x8028
+#define GL_HISTOGRAM_GREEN_SIZE 0x8029
+#define GL_HISTOGRAM_BLUE_SIZE 0x802A
+#define GL_HISTOGRAM_ALPHA_SIZE 0x802B
+#define GL_HISTOGRAM_LUMINANCE_SIZE 0x802C
+#define GL_HISTOGRAM_SINK 0x802D
+#define GL_MINMAX 0x802E
+#define GL_MINMAX_FORMAT 0x802F
+#define GL_MINMAX_SINK 0x8030
+#define GL_TABLE_TOO_LARGE 0x8031
+#define GL_COLOR_MATRIX 0x80B1
+#define GL_COLOR_MATRIX_STACK_DEPTH 0x80B2
+#define GL_MAX_COLOR_MATRIX_STACK_DEPTH 0x80B3
+#define GL_POST_COLOR_MATRIX_RED_SCALE 0x80B4
+#define GL_POST_COLOR_MATRIX_GREEN_SCALE 0x80B5
+#define GL_POST_COLOR_MATRIX_BLUE_SCALE 0x80B6
+#define GL_POST_COLOR_MATRIX_ALPHA_SCALE 0x80B7
+#define GL_POST_COLOR_MATRIX_RED_BIAS 0x80B8
+#define GL_POST_COLOR_MATRIX_GREEN_BIAS 0x80B9
+#define GL_POST_COLOR_MATRIX_BLUE_BIAS 0x80BA
+#define GL_POST_COLOR_MATRIX_ALPHA_BIAS 0x80BB
+#define GL_COLOR_TABLE 0x80D0
+#define GL_POST_CONVOLUTION_COLOR_TABLE 0x80D1
+#define GL_POST_COLOR_MATRIX_COLOR_TABLE 0x80D2
+#define GL_PROXY_COLOR_TABLE 0x80D3
+#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE 0x80D4
+#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE 0x80D5
+#define GL_COLOR_TABLE_SCALE 0x80D6
+#define GL_COLOR_TABLE_BIAS 0x80D7
+#define GL_COLOR_TABLE_FORMAT 0x80D8
+#define GL_COLOR_TABLE_WIDTH 0x80D9
+#define GL_COLOR_TABLE_RED_SIZE 0x80DA
+#define GL_COLOR_TABLE_GREEN_SIZE 0x80DB
+#define GL_COLOR_TABLE_BLUE_SIZE 0x80DC
+#define GL_COLOR_TABLE_ALPHA_SIZE 0x80DD
+#define GL_COLOR_TABLE_LUMINANCE_SIZE 0x80DE
+#define GL_COLOR_TABLE_INTENSITY_SIZE 0x80DF
+#define GL_CONSTANT_BORDER 0x8151
+#define GL_REPLICATE_BORDER 0x8153
+#define GL_CONVOLUTION_BORDER_COLOR 0x8154
+typedef void (APIENTRYP PFNGLCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *table);
+typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLCOPYCOLORTABLEPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width);
+typedef void (APIENTRYP PFNGLGETCOLORTABLEPROC) (GLenum target, GLenum format, GLenum type, void *table);
+typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const void *data);
+typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width);
+typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *image);
+typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *image);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat params);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIPROC) (GLenum target, GLenum pname, GLint params);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width);
+typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTERPROC) (GLenum target, GLenum format, GLenum type, void *image);
+typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETSEPARABLEFILTERPROC) (GLenum target, GLenum format, GLenum type, void *row, void *column, void *span);
+typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *row, const void *column);
+typedef void (APIENTRYP PFNGLGETHISTOGRAMPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values);
+typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETMINMAXPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values);
+typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLHISTOGRAMPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink);
+typedef void (APIENTRYP PFNGLMINMAXPROC) (GLenum target, GLenum internalformat, GLboolean sink);
+typedef void (APIENTRYP PFNGLRESETHISTOGRAMPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLRESETMINMAXPROC) (GLenum target);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glColorTable (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *table);
+GLAPI void APIENTRY glColorTableParameterfv (GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glColorTableParameteriv (GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glCopyColorTable (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width);
+GLAPI void APIENTRY glGetColorTable (GLenum target, GLenum format, GLenum type, void *table);
+GLAPI void APIENTRY glGetColorTableParameterfv (GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetColorTableParameteriv (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glColorSubTable (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const void *data);
+GLAPI void APIENTRY glCopyColorSubTable (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width);
+GLAPI void APIENTRY glConvolutionFilter1D (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *image);
+GLAPI void APIENTRY glConvolutionFilter2D (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *image);
+GLAPI void APIENTRY glConvolutionParameterf (GLenum target, GLenum pname, GLfloat params);
+GLAPI void APIENTRY glConvolutionParameterfv (GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glConvolutionParameteri (GLenum target, GLenum pname, GLint params);
+GLAPI void APIENTRY glConvolutionParameteriv (GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glCopyConvolutionFilter1D (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width);
+GLAPI void APIENTRY glCopyConvolutionFilter2D (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glGetConvolutionFilter (GLenum target, GLenum format, GLenum type, void *image);
+GLAPI void APIENTRY glGetConvolutionParameterfv (GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetConvolutionParameteriv (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetSeparableFilter (GLenum target, GLenum format, GLenum type, void *row, void *column, void *span);
+GLAPI void APIENTRY glSeparableFilter2D (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *row, const void *column);
+GLAPI void APIENTRY glGetHistogram (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values);
+GLAPI void APIENTRY glGetHistogramParameterfv (GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetHistogramParameteriv (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetMinmax (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values);
+GLAPI void APIENTRY glGetMinmaxParameterfv (GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetMinmaxParameteriv (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glHistogram (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink);
+GLAPI void APIENTRY glMinmax (GLenum target, GLenum internalformat, GLboolean sink);
+GLAPI void APIENTRY glResetHistogram (GLenum target);
+GLAPI void APIENTRY glResetMinmax (GLenum target);
+#endif
+#endif /* GL_ARB_imaging */
+
+#ifndef GL_ARB_indirect_parameters
+#define GL_ARB_indirect_parameters 1
+#define GL_PARAMETER_BUFFER_ARB 0x80EE
+#define GL_PARAMETER_BUFFER_BINDING_ARB 0x80EF
+typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTCOUNTARBPROC) (GLenum mode, GLintptr indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride);
+typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTCOUNTARBPROC) (GLenum mode, GLenum type, GLintptr indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMultiDrawArraysIndirectCountARB (GLenum mode, GLintptr indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride);
+GLAPI void APIENTRY glMultiDrawElementsIndirectCountARB (GLenum mode, GLenum type, GLintptr indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride);
+#endif
+#endif /* GL_ARB_indirect_parameters */
+
+#ifndef GL_ARB_instanced_arrays
+#define GL_ARB_instanced_arrays 1
+#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB 0x88FE
+typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORARBPROC) (GLuint index, GLuint divisor);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexAttribDivisorARB (GLuint index, GLuint divisor);
+#endif
+#endif /* GL_ARB_instanced_arrays */
+
+#ifndef GL_ARB_internalformat_query
+#define GL_ARB_internalformat_query 1
+#endif /* GL_ARB_internalformat_query */
+
+#ifndef GL_ARB_internalformat_query2
+#define GL_ARB_internalformat_query2 1
+#define GL_SRGB_DECODE_ARB 0x8299
+#endif /* GL_ARB_internalformat_query2 */
+
+#ifndef GL_ARB_invalidate_subdata
+#define GL_ARB_invalidate_subdata 1
+#endif /* GL_ARB_invalidate_subdata */
+
+#ifndef GL_ARB_map_buffer_alignment
+#define GL_ARB_map_buffer_alignment 1
+#endif /* GL_ARB_map_buffer_alignment */
+
+#ifndef GL_ARB_map_buffer_range
+#define GL_ARB_map_buffer_range 1
+#endif /* GL_ARB_map_buffer_range */
+
+#ifndef GL_ARB_matrix_palette
+#define GL_ARB_matrix_palette 1
+#define GL_MATRIX_PALETTE_ARB 0x8840
+#define GL_MAX_MATRIX_PALETTE_STACK_DEPTH_ARB 0x8841
+#define GL_MAX_PALETTE_MATRICES_ARB 0x8842
+#define GL_CURRENT_PALETTE_MATRIX_ARB 0x8843
+#define GL_MATRIX_INDEX_ARRAY_ARB 0x8844
+#define GL_CURRENT_MATRIX_INDEX_ARB 0x8845
+#define GL_MATRIX_INDEX_ARRAY_SIZE_ARB 0x8846
+#define GL_MATRIX_INDEX_ARRAY_TYPE_ARB 0x8847
+#define GL_MATRIX_INDEX_ARRAY_STRIDE_ARB 0x8848
+#define GL_MATRIX_INDEX_ARRAY_POINTER_ARB 0x8849
+typedef void (APIENTRYP PFNGLCURRENTPALETTEMATRIXARBPROC) (GLint index);
+typedef void (APIENTRYP PFNGLMATRIXINDEXUBVARBPROC) (GLint size, const GLubyte *indices);
+typedef void (APIENTRYP PFNGLMATRIXINDEXUSVARBPROC) (GLint size, const GLushort *indices);
+typedef void (APIENTRYP PFNGLMATRIXINDEXUIVARBPROC) (GLint size, const GLuint *indices);
+typedef void (APIENTRYP PFNGLMATRIXINDEXPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const void *pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glCurrentPaletteMatrixARB (GLint index);
+GLAPI void APIENTRY glMatrixIndexubvARB (GLint size, const GLubyte *indices);
+GLAPI void APIENTRY glMatrixIndexusvARB (GLint size, const GLushort *indices);
+GLAPI void APIENTRY glMatrixIndexuivARB (GLint size, const GLuint *indices);
+GLAPI void APIENTRY glMatrixIndexPointerARB (GLint size, GLenum type, GLsizei stride, const void *pointer);
+#endif
+#endif /* GL_ARB_matrix_palette */
+
+#ifndef GL_ARB_multi_bind
+#define GL_ARB_multi_bind 1
+#endif /* GL_ARB_multi_bind */
+
+#ifndef GL_ARB_multi_draw_indirect
+#define GL_ARB_multi_draw_indirect 1
+#endif /* GL_ARB_multi_draw_indirect */
+
+#ifndef GL_ARB_multisample
+#define GL_ARB_multisample 1
+#define GL_MULTISAMPLE_ARB 0x809D
+#define GL_SAMPLE_ALPHA_TO_COVERAGE_ARB 0x809E
+#define GL_SAMPLE_ALPHA_TO_ONE_ARB 0x809F
+#define GL_SAMPLE_COVERAGE_ARB 0x80A0
+#define GL_SAMPLE_BUFFERS_ARB 0x80A8
+#define GL_SAMPLES_ARB 0x80A9
+#define GL_SAMPLE_COVERAGE_VALUE_ARB 0x80AA
+#define GL_SAMPLE_COVERAGE_INVERT_ARB 0x80AB
+#define GL_MULTISAMPLE_BIT_ARB 0x20000000
+typedef void (APIENTRYP PFNGLSAMPLECOVERAGEARBPROC) (GLfloat value, GLboolean invert);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glSampleCoverageARB (GLfloat value, GLboolean invert);
+#endif
+#endif /* GL_ARB_multisample */
+
+#ifndef GL_ARB_multitexture
+#define GL_ARB_multitexture 1
+#define GL_TEXTURE0_ARB 0x84C0
+#define GL_TEXTURE1_ARB 0x84C1
+#define GL_TEXTURE2_ARB 0x84C2
+#define GL_TEXTURE3_ARB 0x84C3
+#define GL_TEXTURE4_ARB 0x84C4
+#define GL_TEXTURE5_ARB 0x84C5
+#define GL_TEXTURE6_ARB 0x84C6
+#define GL_TEXTURE7_ARB 0x84C7
+#define GL_TEXTURE8_ARB 0x84C8
+#define GL_TEXTURE9_ARB 0x84C9
+#define GL_TEXTURE10_ARB 0x84CA
+#define GL_TEXTURE11_ARB 0x84CB
+#define GL_TEXTURE12_ARB 0x84CC
+#define GL_TEXTURE13_ARB 0x84CD
+#define GL_TEXTURE14_ARB 0x84CE
+#define GL_TEXTURE15_ARB 0x84CF
+#define GL_TEXTURE16_ARB 0x84D0
+#define GL_TEXTURE17_ARB 0x84D1
+#define GL_TEXTURE18_ARB 0x84D2
+#define GL_TEXTURE19_ARB 0x84D3
+#define GL_TEXTURE20_ARB 0x84D4
+#define GL_TEXTURE21_ARB 0x84D5
+#define GL_TEXTURE22_ARB 0x84D6
+#define GL_TEXTURE23_ARB 0x84D7
+#define GL_TEXTURE24_ARB 0x84D8
+#define GL_TEXTURE25_ARB 0x84D9
+#define GL_TEXTURE26_ARB 0x84DA
+#define GL_TEXTURE27_ARB 0x84DB
+#define GL_TEXTURE28_ARB 0x84DC
+#define GL_TEXTURE29_ARB 0x84DD
+#define GL_TEXTURE30_ARB 0x84DE
+#define GL_TEXTURE31_ARB 0x84DF
+#define GL_ACTIVE_TEXTURE_ARB 0x84E0
+#define GL_CLIENT_ACTIVE_TEXTURE_ARB 0x84E1
+#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2
+typedef void (APIENTRYP PFNGLACTIVETEXTUREARBPROC) (GLenum texture);
+typedef void (APIENTRYP PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum texture);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1DARBPROC) (GLenum target, GLdouble s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1DVARBPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1FARBPROC) (GLenum target, GLfloat s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1FVARBPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1IARBPROC) (GLenum target, GLint s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1IVARBPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1SARBPROC) (GLenum target, GLshort s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1SVARBPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2DARBPROC) (GLenum target, GLdouble s, GLdouble t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2DVARBPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2FVARBPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2IARBPROC) (GLenum target, GLint s, GLint t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2IVARBPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2SARBPROC) (GLenum target, GLshort s, GLshort t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2SVARBPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3DVARBPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3FVARBPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3IARBPROC) (GLenum target, GLint s, GLint t, GLint r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3IVARBPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3SVARBPROC) (GLenum target, const GLshort *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4DARBPROC) (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4DVARBPROC) (GLenum target, const GLdouble *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4FARBPROC) (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4FVARBPROC) (GLenum target, const GLfloat *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4IARBPROC) (GLenum target, GLint s, GLint t, GLint r, GLint q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4IVARBPROC) (GLenum target, const GLint *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4SARBPROC) (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4SVARBPROC) (GLenum target, const GLshort *v);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glActiveTextureARB (GLenum texture);
+GLAPI void APIENTRY glClientActiveTextureARB (GLenum texture);
+GLAPI void APIENTRY glMultiTexCoord1dARB (GLenum target, GLdouble s);
+GLAPI void APIENTRY glMultiTexCoord1dvARB (GLenum target, const GLdouble *v);
+GLAPI void APIENTRY glMultiTexCoord1fARB (GLenum target, GLfloat s);
+GLAPI void APIENTRY glMultiTexCoord1fvARB (GLenum target, const GLfloat *v);
+GLAPI void APIENTRY glMultiTexCoord1iARB (GLenum target, GLint s);
+GLAPI void APIENTRY glMultiTexCoord1ivARB (GLenum target, const GLint *v);
+GLAPI void APIENTRY glMultiTexCoord1sARB (GLenum target, GLshort s);
+GLAPI void APIENTRY glMultiTexCoord1svARB (GLenum target, const GLshort *v);
+GLAPI void APIENTRY glMultiTexCoord2dARB (GLenum target, GLdouble s, GLdouble t);
+GLAPI void APIENTRY glMultiTexCoord2dvARB (GLenum target, const GLdouble *v);
+GLAPI void APIENTRY glMultiTexCoord2fARB (GLenum target, GLfloat s, GLfloat t);
+GLAPI void APIENTRY glMultiTexCoord2fvARB (GLenum target, const GLfloat *v);
+GLAPI void APIENTRY glMultiTexCoord2iARB (GLenum target, GLint s, GLint t);
+GLAPI void APIENTRY glMultiTexCoord2ivARB (GLenum target, const GLint *v);
+GLAPI void APIENTRY glMultiTexCoord2sARB (GLenum target, GLshort s, GLshort t);
+GLAPI void APIENTRY glMultiTexCoord2svARB (GLenum target, const GLshort *v);
+GLAPI void APIENTRY glMultiTexCoord3dARB (GLenum target, GLdouble s, GLdouble t, GLdouble r);
+GLAPI void APIENTRY glMultiTexCoord3dvARB (GLenum target, const GLdouble *v);
+GLAPI void APIENTRY glMultiTexCoord3fARB (GLenum target, GLfloat s, GLfloat t, GLfloat r);
+GLAPI void APIENTRY glMultiTexCoord3fvARB (GLenum target, const GLfloat *v);
+GLAPI void APIENTRY glMultiTexCoord3iARB (GLenum target, GLint s, GLint t, GLint r);
+GLAPI void APIENTRY glMultiTexCoord3ivARB (GLenum target, const GLint *v);
+GLAPI void APIENTRY glMultiTexCoord3sARB (GLenum target, GLshort s, GLshort t, GLshort r);
+GLAPI void APIENTRY glMultiTexCoord3svARB (GLenum target, const GLshort *v);
+GLAPI void APIENTRY glMultiTexCoord4dARB (GLenum target, GLdouble s, GLdouble t, GLdouble r, GLdouble q);
+GLAPI void APIENTRY glMultiTexCoord4dvARB (GLenum target, const GLdouble *v);
+GLAPI void APIENTRY glMultiTexCoord4fARB (GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
+GLAPI void APIENTRY glMultiTexCoord4fvARB (GLenum target, const GLfloat *v);
+GLAPI void APIENTRY glMultiTexCoord4iARB (GLenum target, GLint s, GLint t, GLint r, GLint q);
+GLAPI void APIENTRY glMultiTexCoord4ivARB (GLenum target, const GLint *v);
+GLAPI void APIENTRY glMultiTexCoord4sARB (GLenum target, GLshort s, GLshort t, GLshort r, GLshort q);
+GLAPI void APIENTRY glMultiTexCoord4svARB (GLenum target, const GLshort *v);
+#endif
+#endif /* GL_ARB_multitexture */
+
+#ifndef GL_ARB_occlusion_query
+#define GL_ARB_occlusion_query 1
+#define GL_QUERY_COUNTER_BITS_ARB 0x8864
+#define GL_CURRENT_QUERY_ARB 0x8865
+#define GL_QUERY_RESULT_ARB 0x8866
+#define GL_QUERY_RESULT_AVAILABLE_ARB 0x8867
+#define GL_SAMPLES_PASSED_ARB 0x8914
+typedef void (APIENTRYP PFNGLGENQUERIESARBPROC) (GLsizei n, GLuint *ids);
+typedef void (APIENTRYP PFNGLDELETEQUERIESARBPROC) (GLsizei n, const GLuint *ids);
+typedef GLboolean (APIENTRYP PFNGLISQUERYARBPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLBEGINQUERYARBPROC) (GLenum target, GLuint id);
+typedef void (APIENTRYP PFNGLENDQUERYARBPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLGETQUERYIVARBPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETQUERYOBJECTIVARBPROC) (GLuint id, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETQUERYOBJECTUIVARBPROC) (GLuint id, GLenum pname, GLuint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGenQueriesARB (GLsizei n, GLuint *ids);
+GLAPI void APIENTRY glDeleteQueriesARB (GLsizei n, const GLuint *ids);
+GLAPI GLboolean APIENTRY glIsQueryARB (GLuint id);
+GLAPI void APIENTRY glBeginQueryARB (GLenum target, GLuint id);
+GLAPI void APIENTRY glEndQueryARB (GLenum target);
+GLAPI void APIENTRY glGetQueryivARB (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetQueryObjectivARB (GLuint id, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetQueryObjectuivARB (GLuint id, GLenum pname, GLuint *params);
+#endif
+#endif /* GL_ARB_occlusion_query */
+
+#ifndef GL_ARB_occlusion_query2
+#define GL_ARB_occlusion_query2 1
+#endif /* GL_ARB_occlusion_query2 */
+
+#ifndef GL_ARB_pixel_buffer_object
+#define GL_ARB_pixel_buffer_object 1
+#define GL_PIXEL_PACK_BUFFER_ARB 0x88EB
+#define GL_PIXEL_UNPACK_BUFFER_ARB 0x88EC
+#define GL_PIXEL_PACK_BUFFER_BINDING_ARB 0x88ED
+#define GL_PIXEL_UNPACK_BUFFER_BINDING_ARB 0x88EF
+#endif /* GL_ARB_pixel_buffer_object */
+
+#ifndef GL_ARB_point_parameters
+#define GL_ARB_point_parameters 1
+#define GL_POINT_SIZE_MIN_ARB 0x8126
+#define GL_POINT_SIZE_MAX_ARB 0x8127
+#define GL_POINT_FADE_THRESHOLD_SIZE_ARB 0x8128
+#define GL_POINT_DISTANCE_ATTENUATION_ARB 0x8129
+typedef void (APIENTRYP PFNGLPOINTPARAMETERFARBPROC) (GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLPOINTPARAMETERFVARBPROC) (GLenum pname, const GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPointParameterfARB (GLenum pname, GLfloat param);
+GLAPI void APIENTRY glPointParameterfvARB (GLenum pname, const GLfloat *params);
+#endif
+#endif /* GL_ARB_point_parameters */
+
+#ifndef GL_ARB_point_sprite
+#define GL_ARB_point_sprite 1
+#define GL_POINT_SPRITE_ARB 0x8861
+#define GL_COORD_REPLACE_ARB 0x8862
+#endif /* GL_ARB_point_sprite */
+
+#ifndef GL_ARB_program_interface_query
+#define GL_ARB_program_interface_query 1
+#endif /* GL_ARB_program_interface_query */
+
+#ifndef GL_ARB_provoking_vertex
+#define GL_ARB_provoking_vertex 1
+#endif /* GL_ARB_provoking_vertex */
+
+#ifndef GL_ARB_query_buffer_object
+#define GL_ARB_query_buffer_object 1
+#endif /* GL_ARB_query_buffer_object */
+
+#ifndef GL_ARB_robust_buffer_access_behavior
+#define GL_ARB_robust_buffer_access_behavior 1
+#endif /* GL_ARB_robust_buffer_access_behavior */
+
+#ifndef GL_ARB_robustness
+#define GL_ARB_robustness 1
+#define GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB 0x00000004
+#define GL_LOSE_CONTEXT_ON_RESET_ARB 0x8252
+#define GL_GUILTY_CONTEXT_RESET_ARB 0x8253
+#define GL_INNOCENT_CONTEXT_RESET_ARB 0x8254
+#define GL_UNKNOWN_CONTEXT_RESET_ARB 0x8255
+#define GL_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
+#define GL_NO_RESET_NOTIFICATION_ARB 0x8261
+typedef GLenum (APIENTRYP PFNGLGETGRAPHICSRESETSTATUSARBPROC) (void);
+typedef void (APIENTRYP PFNGLGETNTEXIMAGEARBPROC) (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, void *img);
+typedef void (APIENTRYP PFNGLREADNPIXELSARBPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void *data);
+typedef void (APIENTRYP PFNGLGETNCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint lod, GLsizei bufSize, void *img);
+typedef void (APIENTRYP PFNGLGETNUNIFORMFVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETNUNIFORMIVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLint *params);
+typedef void (APIENTRYP PFNGLGETNUNIFORMUIVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLuint *params);
+typedef void (APIENTRYP PFNGLGETNUNIFORMDVARBPROC) (GLuint program, GLint location, GLsizei bufSize, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETNMAPDVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v);
+typedef void (APIENTRYP PFNGLGETNMAPFVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v);
+typedef void (APIENTRYP PFNGLGETNMAPIVARBPROC) (GLenum target, GLenum query, GLsizei bufSize, GLint *v);
+typedef void (APIENTRYP PFNGLGETNPIXELMAPFVARBPROC) (GLenum map, GLsizei bufSize, GLfloat *values);
+typedef void (APIENTRYP PFNGLGETNPIXELMAPUIVARBPROC) (GLenum map, GLsizei bufSize, GLuint *values);
+typedef void (APIENTRYP PFNGLGETNPIXELMAPUSVARBPROC) (GLenum map, GLsizei bufSize, GLushort *values);
+typedef void (APIENTRYP PFNGLGETNPOLYGONSTIPPLEARBPROC) (GLsizei bufSize, GLubyte *pattern);
+typedef void (APIENTRYP PFNGLGETNCOLORTABLEARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei bufSize, void *table);
+typedef void (APIENTRYP PFNGLGETNCONVOLUTIONFILTERARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei bufSize, void *image);
+typedef void (APIENTRYP PFNGLGETNSEPARABLEFILTERARBPROC) (GLenum target, GLenum format, GLenum type, GLsizei rowBufSize, void *row, GLsizei columnBufSize, void *column, void *span);
+typedef void (APIENTRYP PFNGLGETNHISTOGRAMARBPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, void *values);
+typedef void (APIENTRYP PFNGLGETNMINMAXARBPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, void *values);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLenum APIENTRY glGetGraphicsResetStatusARB (void);
+GLAPI void APIENTRY glGetnTexImageARB (GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSize, void *img);
+GLAPI void APIENTRY glReadnPixelsARB (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void *data);
+GLAPI void APIENTRY glGetnCompressedTexImageARB (GLenum target, GLint lod, GLsizei bufSize, void *img);
+GLAPI void APIENTRY glGetnUniformfvARB (GLuint program, GLint location, GLsizei bufSize, GLfloat *params);
+GLAPI void APIENTRY glGetnUniformivARB (GLuint program, GLint location, GLsizei bufSize, GLint *params);
+GLAPI void APIENTRY glGetnUniformuivARB (GLuint program, GLint location, GLsizei bufSize, GLuint *params);
+GLAPI void APIENTRY glGetnUniformdvARB (GLuint program, GLint location, GLsizei bufSize, GLdouble *params);
+GLAPI void APIENTRY glGetnMapdvARB (GLenum target, GLenum query, GLsizei bufSize, GLdouble *v);
+GLAPI void APIENTRY glGetnMapfvARB (GLenum target, GLenum query, GLsizei bufSize, GLfloat *v);
+GLAPI void APIENTRY glGetnMapivARB (GLenum target, GLenum query, GLsizei bufSize, GLint *v);
+GLAPI void APIENTRY glGetnPixelMapfvARB (GLenum map, GLsizei bufSize, GLfloat *values);
+GLAPI void APIENTRY glGetnPixelMapuivARB (GLenum map, GLsizei bufSize, GLuint *values);
+GLAPI void APIENTRY glGetnPixelMapusvARB (GLenum map, GLsizei bufSize, GLushort *values);
+GLAPI void APIENTRY glGetnPolygonStippleARB (GLsizei bufSize, GLubyte *pattern);
+GLAPI void APIENTRY glGetnColorTableARB (GLenum target, GLenum format, GLenum type, GLsizei bufSize, void *table);
+GLAPI void APIENTRY glGetnConvolutionFilterARB (GLenum target, GLenum format, GLenum type, GLsizei bufSize, void *image);
+GLAPI void APIENTRY glGetnSeparableFilterARB (GLenum target, GLenum format, GLenum type, GLsizei rowBufSize, void *row, GLsizei columnBufSize, void *column, void *span);
+GLAPI void APIENTRY glGetnHistogramARB (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, void *values);
+GLAPI void APIENTRY glGetnMinmaxARB (GLenum target, GLboolean reset, GLenum format, GLenum type, GLsizei bufSize, void *values);
+#endif
+#endif /* GL_ARB_robustness */
+
+#ifndef GL_ARB_robustness_isolation
+#define GL_ARB_robustness_isolation 1
+#endif /* GL_ARB_robustness_isolation */
+
+#ifndef GL_ARB_sample_shading
+#define GL_ARB_sample_shading 1
+#define GL_SAMPLE_SHADING_ARB 0x8C36
+#define GL_MIN_SAMPLE_SHADING_VALUE_ARB 0x8C37
+typedef void (APIENTRYP PFNGLMINSAMPLESHADINGARBPROC) (GLfloat value);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMinSampleShadingARB (GLfloat value);
+#endif
+#endif /* GL_ARB_sample_shading */
+
+#ifndef GL_ARB_sampler_objects
+#define GL_ARB_sampler_objects 1
+#endif /* GL_ARB_sampler_objects */
+
+#ifndef GL_ARB_seamless_cube_map
+#define GL_ARB_seamless_cube_map 1
+#endif /* GL_ARB_seamless_cube_map */
+
+#ifndef GL_ARB_seamless_cubemap_per_texture
+#define GL_ARB_seamless_cubemap_per_texture 1
+#endif /* GL_ARB_seamless_cubemap_per_texture */
+
+#ifndef GL_ARB_separate_shader_objects
+#define GL_ARB_separate_shader_objects 1
+#endif /* GL_ARB_separate_shader_objects */
+
+#ifndef GL_ARB_shader_atomic_counters
+#define GL_ARB_shader_atomic_counters 1
+#endif /* GL_ARB_shader_atomic_counters */
+
+#ifndef GL_ARB_shader_bit_encoding
+#define GL_ARB_shader_bit_encoding 1
+#endif /* GL_ARB_shader_bit_encoding */
+
+#ifndef GL_ARB_shader_draw_parameters
+#define GL_ARB_shader_draw_parameters 1
+#endif /* GL_ARB_shader_draw_parameters */
+
+#ifndef GL_ARB_shader_group_vote
+#define GL_ARB_shader_group_vote 1
+#endif /* GL_ARB_shader_group_vote */
+
+#ifndef GL_ARB_shader_image_load_store
+#define GL_ARB_shader_image_load_store 1
+#endif /* GL_ARB_shader_image_load_store */
+
+#ifndef GL_ARB_shader_image_size
+#define GL_ARB_shader_image_size 1
+#endif /* GL_ARB_shader_image_size */
+
+#ifndef GL_ARB_shader_objects
+#define GL_ARB_shader_objects 1
+#ifdef __APPLE__
+typedef void *GLhandleARB;
+#else
+typedef unsigned int GLhandleARB;
+#endif
+typedef char GLcharARB;
+#define GL_PROGRAM_OBJECT_ARB 0x8B40
+#define GL_SHADER_OBJECT_ARB 0x8B48
+#define GL_OBJECT_TYPE_ARB 0x8B4E
+#define GL_OBJECT_SUBTYPE_ARB 0x8B4F
+#define GL_FLOAT_VEC2_ARB 0x8B50
+#define GL_FLOAT_VEC3_ARB 0x8B51
+#define GL_FLOAT_VEC4_ARB 0x8B52
+#define GL_INT_VEC2_ARB 0x8B53
+#define GL_INT_VEC3_ARB 0x8B54
+#define GL_INT_VEC4_ARB 0x8B55
+#define GL_BOOL_ARB 0x8B56
+#define GL_BOOL_VEC2_ARB 0x8B57
+#define GL_BOOL_VEC3_ARB 0x8B58
+#define GL_BOOL_VEC4_ARB 0x8B59
+#define GL_FLOAT_MAT2_ARB 0x8B5A
+#define GL_FLOAT_MAT3_ARB 0x8B5B
+#define GL_FLOAT_MAT4_ARB 0x8B5C
+#define GL_SAMPLER_1D_ARB 0x8B5D
+#define GL_SAMPLER_2D_ARB 0x8B5E
+#define GL_SAMPLER_3D_ARB 0x8B5F
+#define GL_SAMPLER_CUBE_ARB 0x8B60
+#define GL_SAMPLER_1D_SHADOW_ARB 0x8B61
+#define GL_SAMPLER_2D_SHADOW_ARB 0x8B62
+#define GL_SAMPLER_2D_RECT_ARB 0x8B63
+#define GL_SAMPLER_2D_RECT_SHADOW_ARB 0x8B64
+#define GL_OBJECT_DELETE_STATUS_ARB 0x8B80
+#define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81
+#define GL_OBJECT_LINK_STATUS_ARB 0x8B82
+#define GL_OBJECT_VALIDATE_STATUS_ARB 0x8B83
+#define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84
+#define GL_OBJECT_ATTACHED_OBJECTS_ARB 0x8B85
+#define GL_OBJECT_ACTIVE_UNIFORMS_ARB 0x8B86
+#define GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB 0x8B87
+#define GL_OBJECT_SHADER_SOURCE_LENGTH_ARB 0x8B88
+typedef void (APIENTRYP PFNGLDELETEOBJECTARBPROC) (GLhandleARB obj);
+typedef GLhandleARB (APIENTRYP PFNGLGETHANDLEARBPROC) (GLenum pname);
+typedef void (APIENTRYP PFNGLDETACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB attachedObj);
+typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum shaderType);
+typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, GLsizei count, const GLcharARB **string, const GLint *length);
+typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB shaderObj);
+typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void);
+typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj);
+typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj);
+typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB programObj);
+typedef void (APIENTRYP PFNGLVALIDATEPROGRAMARBPROC) (GLhandleARB programObj);
+typedef void (APIENTRYP PFNGLUNIFORM1FARBPROC) (GLint location, GLfloat v0);
+typedef void (APIENTRYP PFNGLUNIFORM2FARBPROC) (GLint location, GLfloat v0, GLfloat v1);
+typedef void (APIENTRYP PFNGLUNIFORM3FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+typedef void (APIENTRYP PFNGLUNIFORM4FARBPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+typedef void (APIENTRYP PFNGLUNIFORM1IARBPROC) (GLint location, GLint v0);
+typedef void (APIENTRYP PFNGLUNIFORM2IARBPROC) (GLint location, GLint v0, GLint v1);
+typedef void (APIENTRYP PFNGLUNIFORM3IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2);
+typedef void (APIENTRYP PFNGLUNIFORM4IARBPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+typedef void (APIENTRYP PFNGLUNIFORM1FVARBPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORM2FVARBPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORM3FVARBPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORM4FVARBPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORM1IVARBPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLUNIFORM2IVARBPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLUNIFORM3IVARBPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLUNIFORM4IVARBPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX2FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX3FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERFVARBPROC) (GLhandleARB obj, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVARBPROC) (GLhandleARB obj, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETINFOLOGARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog);
+typedef void (APIENTRYP PFNGLGETATTACHEDOBJECTSARBPROC) (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj);
+typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name);
+typedef void (APIENTRYP PFNGLGETACTIVEUNIFORMARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name);
+typedef void (APIENTRYP PFNGLGETUNIFORMFVARBPROC) (GLhandleARB programObj, GLint location, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETUNIFORMIVARBPROC) (GLhandleARB programObj, GLint location, GLint *params);
+typedef void (APIENTRYP PFNGLGETSHADERSOURCEARBPROC) (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDeleteObjectARB (GLhandleARB obj);
+GLAPI GLhandleARB APIENTRY glGetHandleARB (GLenum pname);
+GLAPI void APIENTRY glDetachObjectARB (GLhandleARB containerObj, GLhandleARB attachedObj);
+GLAPI GLhandleARB APIENTRY glCreateShaderObjectARB (GLenum shaderType);
+GLAPI void APIENTRY glShaderSourceARB (GLhandleARB shaderObj, GLsizei count, const GLcharARB **string, const GLint *length);
+GLAPI void APIENTRY glCompileShaderARB (GLhandleARB shaderObj);
+GLAPI GLhandleARB APIENTRY glCreateProgramObjectARB (void);
+GLAPI void APIENTRY glAttachObjectARB (GLhandleARB containerObj, GLhandleARB obj);
+GLAPI void APIENTRY glLinkProgramARB (GLhandleARB programObj);
+GLAPI void APIENTRY glUseProgramObjectARB (GLhandleARB programObj);
+GLAPI void APIENTRY glValidateProgramARB (GLhandleARB programObj);
+GLAPI void APIENTRY glUniform1fARB (GLint location, GLfloat v0);
+GLAPI void APIENTRY glUniform2fARB (GLint location, GLfloat v0, GLfloat v1);
+GLAPI void APIENTRY glUniform3fARB (GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+GLAPI void APIENTRY glUniform4fARB (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+GLAPI void APIENTRY glUniform1iARB (GLint location, GLint v0);
+GLAPI void APIENTRY glUniform2iARB (GLint location, GLint v0, GLint v1);
+GLAPI void APIENTRY glUniform3iARB (GLint location, GLint v0, GLint v1, GLint v2);
+GLAPI void APIENTRY glUniform4iARB (GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+GLAPI void APIENTRY glUniform1fvARB (GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glUniform2fvARB (GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glUniform3fvARB (GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glUniform4fvARB (GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glUniform1ivARB (GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glUniform2ivARB (GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glUniform3ivARB (GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glUniform4ivARB (GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glUniformMatrix2fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glUniformMatrix3fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glUniformMatrix4fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glGetObjectParameterfvARB (GLhandleARB obj, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetObjectParameterivARB (GLhandleARB obj, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetInfoLogARB (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog);
+GLAPI void APIENTRY glGetAttachedObjectsARB (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj);
+GLAPI GLint APIENTRY glGetUniformLocationARB (GLhandleARB programObj, const GLcharARB *name);
+GLAPI void APIENTRY glGetActiveUniformARB (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name);
+GLAPI void APIENTRY glGetUniformfvARB (GLhandleARB programObj, GLint location, GLfloat *params);
+GLAPI void APIENTRY glGetUniformivARB (GLhandleARB programObj, GLint location, GLint *params);
+GLAPI void APIENTRY glGetShaderSourceARB (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source);
+#endif
+#endif /* GL_ARB_shader_objects */
+
+#ifndef GL_ARB_shader_precision
+#define GL_ARB_shader_precision 1
+#endif /* GL_ARB_shader_precision */
+
+#ifndef GL_ARB_shader_stencil_export
+#define GL_ARB_shader_stencil_export 1
+#endif /* GL_ARB_shader_stencil_export */
+
+#ifndef GL_ARB_shader_storage_buffer_object
+#define GL_ARB_shader_storage_buffer_object 1
+#endif /* GL_ARB_shader_storage_buffer_object */
+
+#ifndef GL_ARB_shader_subroutine
+#define GL_ARB_shader_subroutine 1
+#endif /* GL_ARB_shader_subroutine */
+
+#ifndef GL_ARB_shader_texture_lod
+#define GL_ARB_shader_texture_lod 1
+#endif /* GL_ARB_shader_texture_lod */
+
+#ifndef GL_ARB_shading_language_100
+#define GL_ARB_shading_language_100 1
+#define GL_SHADING_LANGUAGE_VERSION_ARB 0x8B8C
+#endif /* GL_ARB_shading_language_100 */
+
+#ifndef GL_ARB_shading_language_420pack
+#define GL_ARB_shading_language_420pack 1
+#endif /* GL_ARB_shading_language_420pack */
+
+#ifndef GL_ARB_shading_language_include
+#define GL_ARB_shading_language_include 1
+#define GL_SHADER_INCLUDE_ARB 0x8DAE
+#define GL_NAMED_STRING_LENGTH_ARB 0x8DE9
+#define GL_NAMED_STRING_TYPE_ARB 0x8DEA
+typedef void (APIENTRYP PFNGLNAMEDSTRINGARBPROC) (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string);
+typedef void (APIENTRYP PFNGLDELETENAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name);
+typedef void (APIENTRYP PFNGLCOMPILESHADERINCLUDEARBPROC) (GLuint shader, GLsizei count, const GLchar *const*path, const GLint *length);
+typedef GLboolean (APIENTRYP PFNGLISNAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name);
+typedef void (APIENTRYP PFNGLGETNAMEDSTRINGARBPROC) (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string);
+typedef void (APIENTRYP PFNGLGETNAMEDSTRINGIVARBPROC) (GLint namelen, const GLchar *name, GLenum pname, GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glNamedStringARB (GLenum type, GLint namelen, const GLchar *name, GLint stringlen, const GLchar *string);
+GLAPI void APIENTRY glDeleteNamedStringARB (GLint namelen, const GLchar *name);
+GLAPI void APIENTRY glCompileShaderIncludeARB (GLuint shader, GLsizei count, const GLchar *const*path, const GLint *length);
+GLAPI GLboolean APIENTRY glIsNamedStringARB (GLint namelen, const GLchar *name);
+GLAPI void APIENTRY glGetNamedStringARB (GLint namelen, const GLchar *name, GLsizei bufSize, GLint *stringlen, GLchar *string);
+GLAPI void APIENTRY glGetNamedStringivARB (GLint namelen, const GLchar *name, GLenum pname, GLint *params);
+#endif
+#endif /* GL_ARB_shading_language_include */
+
+#ifndef GL_ARB_shading_language_packing
+#define GL_ARB_shading_language_packing 1
+#endif /* GL_ARB_shading_language_packing */
+
+#ifndef GL_ARB_shadow
+#define GL_ARB_shadow 1
+#define GL_TEXTURE_COMPARE_MODE_ARB 0x884C
+#define GL_TEXTURE_COMPARE_FUNC_ARB 0x884D
+#define GL_COMPARE_R_TO_TEXTURE_ARB 0x884E
+#endif /* GL_ARB_shadow */
+
+#ifndef GL_ARB_shadow_ambient
+#define GL_ARB_shadow_ambient 1
+#define GL_TEXTURE_COMPARE_FAIL_VALUE_ARB 0x80BF
+#endif /* GL_ARB_shadow_ambient */
+
+#ifndef GL_ARB_sparse_texture
+#define GL_ARB_sparse_texture 1
+#define GL_TEXTURE_SPARSE_ARB 0x91A6
+#define GL_VIRTUAL_PAGE_SIZE_INDEX_ARB 0x91A7
+#define GL_MIN_SPARSE_LEVEL_ARB 0x919B
+#define GL_NUM_VIRTUAL_PAGE_SIZES_ARB 0x91A8
+#define GL_VIRTUAL_PAGE_SIZE_X_ARB 0x9195
+#define GL_VIRTUAL_PAGE_SIZE_Y_ARB 0x9196
+#define GL_VIRTUAL_PAGE_SIZE_Z_ARB 0x9197
+#define GL_MAX_SPARSE_TEXTURE_SIZE_ARB 0x9198
+#define GL_MAX_SPARSE_3D_TEXTURE_SIZE_ARB 0x9199
+#define GL_MAX_SPARSE_ARRAY_TEXTURE_LAYERS_ARB 0x919A
+#define GL_SPARSE_TEXTURE_FULL_ARRAY_CUBE_MIPMAPS_ARB 0x91A9
+typedef void (APIENTRYP PFNGLTEXPAGECOMMITMENTARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLboolean resident);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexPageCommitmentARB (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLboolean resident);
+#endif
+#endif /* GL_ARB_sparse_texture */
+
+#ifndef GL_ARB_stencil_texturing
+#define GL_ARB_stencil_texturing 1
+#endif /* GL_ARB_stencil_texturing */
+
+#ifndef GL_ARB_sync
+#define GL_ARB_sync 1
+#endif /* GL_ARB_sync */
+
+#ifndef GL_ARB_tessellation_shader
+#define GL_ARB_tessellation_shader 1
+#endif /* GL_ARB_tessellation_shader */
+
+#ifndef GL_ARB_texture_border_clamp
+#define GL_ARB_texture_border_clamp 1
+#define GL_CLAMP_TO_BORDER_ARB 0x812D
+#endif /* GL_ARB_texture_border_clamp */
+
+#ifndef GL_ARB_texture_buffer_object
+#define GL_ARB_texture_buffer_object 1
+#define GL_TEXTURE_BUFFER_ARB 0x8C2A
+#define GL_MAX_TEXTURE_BUFFER_SIZE_ARB 0x8C2B
+#define GL_TEXTURE_BINDING_BUFFER_ARB 0x8C2C
+#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB 0x8C2D
+#define GL_TEXTURE_BUFFER_FORMAT_ARB 0x8C2E
+typedef void (APIENTRYP PFNGLTEXBUFFERARBPROC) (GLenum target, GLenum internalformat, GLuint buffer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexBufferARB (GLenum target, GLenum internalformat, GLuint buffer);
+#endif
+#endif /* GL_ARB_texture_buffer_object */
+
+#ifndef GL_ARB_texture_buffer_object_rgb32
+#define GL_ARB_texture_buffer_object_rgb32 1
+#endif /* GL_ARB_texture_buffer_object_rgb32 */
+
+#ifndef GL_ARB_texture_buffer_range
+#define GL_ARB_texture_buffer_range 1
+#endif /* GL_ARB_texture_buffer_range */
+
+#ifndef GL_ARB_texture_compression
+#define GL_ARB_texture_compression 1
+#define GL_COMPRESSED_ALPHA_ARB 0x84E9
+#define GL_COMPRESSED_LUMINANCE_ARB 0x84EA
+#define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB
+#define GL_COMPRESSED_INTENSITY_ARB 0x84EC
+#define GL_COMPRESSED_RGB_ARB 0x84ED
+#define GL_COMPRESSED_RGBA_ARB 0x84EE
+#define GL_TEXTURE_COMPRESSION_HINT_ARB 0x84EF
+#define GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB 0x86A0
+#define GL_TEXTURE_COMPRESSED_ARB 0x86A1
+#define GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A2
+#define GL_COMPRESSED_TEXTURE_FORMATS_ARB 0x86A3
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXIMAGE1DARBPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data);
+typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXIMAGEARBPROC) (GLenum target, GLint level, void *img);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glCompressedTexImage3DARB (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexImage2DARB (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexImage1DARB (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexSubImage3DARB (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexSubImage2DARB (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glCompressedTexSubImage1DARB (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data);
+GLAPI void APIENTRY glGetCompressedTexImageARB (GLenum target, GLint level, void *img);
+#endif
+#endif /* GL_ARB_texture_compression */
+
+#ifndef GL_ARB_texture_compression_bptc
+#define GL_ARB_texture_compression_bptc 1
+#define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB 0x8E8C
+#define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB 0x8E8D
+#define GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB 0x8E8E
+#define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB 0x8E8F
+#endif /* GL_ARB_texture_compression_bptc */
+
+#ifndef GL_ARB_texture_compression_rgtc
+#define GL_ARB_texture_compression_rgtc 1
+#endif /* GL_ARB_texture_compression_rgtc */
+
+#ifndef GL_ARB_texture_cube_map
+#define GL_ARB_texture_cube_map 1
+#define GL_NORMAL_MAP_ARB 0x8511
+#define GL_REFLECTION_MAP_ARB 0x8512
+#define GL_TEXTURE_CUBE_MAP_ARB 0x8513
+#define GL_TEXTURE_BINDING_CUBE_MAP_ARB 0x8514
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x8515
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x8516
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x8517
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x8518
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x8519
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x851A
+#define GL_PROXY_TEXTURE_CUBE_MAP_ARB 0x851B
+#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB 0x851C
+#endif /* GL_ARB_texture_cube_map */
+
+#ifndef GL_ARB_texture_cube_map_array
+#define GL_ARB_texture_cube_map_array 1
+#define GL_TEXTURE_CUBE_MAP_ARRAY_ARB 0x9009
+#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY_ARB 0x900A
+#define GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB 0x900B
+#define GL_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900C
+#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_ARB 0x900D
+#define GL_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900E
+#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900F
+#endif /* GL_ARB_texture_cube_map_array */
+
+#ifndef GL_ARB_texture_env_add
+#define GL_ARB_texture_env_add 1
+#endif /* GL_ARB_texture_env_add */
+
+#ifndef GL_ARB_texture_env_combine
+#define GL_ARB_texture_env_combine 1
+#define GL_COMBINE_ARB 0x8570
+#define GL_COMBINE_RGB_ARB 0x8571
+#define GL_COMBINE_ALPHA_ARB 0x8572
+#define GL_SOURCE0_RGB_ARB 0x8580
+#define GL_SOURCE1_RGB_ARB 0x8581
+#define GL_SOURCE2_RGB_ARB 0x8582
+#define GL_SOURCE0_ALPHA_ARB 0x8588
+#define GL_SOURCE1_ALPHA_ARB 0x8589
+#define GL_SOURCE2_ALPHA_ARB 0x858A
+#define GL_OPERAND0_RGB_ARB 0x8590
+#define GL_OPERAND1_RGB_ARB 0x8591
+#define GL_OPERAND2_RGB_ARB 0x8592
+#define GL_OPERAND0_ALPHA_ARB 0x8598
+#define GL_OPERAND1_ALPHA_ARB 0x8599
+#define GL_OPERAND2_ALPHA_ARB 0x859A
+#define GL_RGB_SCALE_ARB 0x8573
+#define GL_ADD_SIGNED_ARB 0x8574
+#define GL_INTERPOLATE_ARB 0x8575
+#define GL_SUBTRACT_ARB 0x84E7
+#define GL_CONSTANT_ARB 0x8576
+#define GL_PRIMARY_COLOR_ARB 0x8577
+#define GL_PREVIOUS_ARB 0x8578
+#endif /* GL_ARB_texture_env_combine */
+
+#ifndef GL_ARB_texture_env_crossbar
+#define GL_ARB_texture_env_crossbar 1
+#endif /* GL_ARB_texture_env_crossbar */
+
+#ifndef GL_ARB_texture_env_dot3
+#define GL_ARB_texture_env_dot3 1
+#define GL_DOT3_RGB_ARB 0x86AE
+#define GL_DOT3_RGBA_ARB 0x86AF
+#endif /* GL_ARB_texture_env_dot3 */
+
+#ifndef GL_ARB_texture_float
+#define GL_ARB_texture_float 1
+#define GL_TEXTURE_RED_TYPE_ARB 0x8C10
+#define GL_TEXTURE_GREEN_TYPE_ARB 0x8C11
+#define GL_TEXTURE_BLUE_TYPE_ARB 0x8C12
+#define GL_TEXTURE_ALPHA_TYPE_ARB 0x8C13
+#define GL_TEXTURE_LUMINANCE_TYPE_ARB 0x8C14
+#define GL_TEXTURE_INTENSITY_TYPE_ARB 0x8C15
+#define GL_TEXTURE_DEPTH_TYPE_ARB 0x8C16
+#define GL_UNSIGNED_NORMALIZED_ARB 0x8C17
+#define GL_RGBA32F_ARB 0x8814
+#define GL_RGB32F_ARB 0x8815
+#define GL_ALPHA32F_ARB 0x8816
+#define GL_INTENSITY32F_ARB 0x8817
+#define GL_LUMINANCE32F_ARB 0x8818
+#define GL_LUMINANCE_ALPHA32F_ARB 0x8819
+#define GL_RGBA16F_ARB 0x881A
+#define GL_RGB16F_ARB 0x881B
+#define GL_ALPHA16F_ARB 0x881C
+#define GL_INTENSITY16F_ARB 0x881D
+#define GL_LUMINANCE16F_ARB 0x881E
+#define GL_LUMINANCE_ALPHA16F_ARB 0x881F
+#endif /* GL_ARB_texture_float */
+
+#ifndef GL_ARB_texture_gather
+#define GL_ARB_texture_gather 1
+#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET_ARB 0x8E5E
+#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET_ARB 0x8E5F
+#define GL_MAX_PROGRAM_TEXTURE_GATHER_COMPONENTS_ARB 0x8F9F
+#endif /* GL_ARB_texture_gather */
+
+#ifndef GL_ARB_texture_mirror_clamp_to_edge
+#define GL_ARB_texture_mirror_clamp_to_edge 1
+#endif /* GL_ARB_texture_mirror_clamp_to_edge */
+
+#ifndef GL_ARB_texture_mirrored_repeat
+#define GL_ARB_texture_mirrored_repeat 1
+#define GL_MIRRORED_REPEAT_ARB 0x8370
+#endif /* GL_ARB_texture_mirrored_repeat */
+
+#ifndef GL_ARB_texture_multisample
+#define GL_ARB_texture_multisample 1
+#endif /* GL_ARB_texture_multisample */
+
+#ifndef GL_ARB_texture_non_power_of_two
+#define GL_ARB_texture_non_power_of_two 1
+#endif /* GL_ARB_texture_non_power_of_two */
+
+#ifndef GL_ARB_texture_query_levels
+#define GL_ARB_texture_query_levels 1
+#endif /* GL_ARB_texture_query_levels */
+
+#ifndef GL_ARB_texture_query_lod
+#define GL_ARB_texture_query_lod 1
+#endif /* GL_ARB_texture_query_lod */
+
+#ifndef GL_ARB_texture_rectangle
+#define GL_ARB_texture_rectangle 1
+#define GL_TEXTURE_RECTANGLE_ARB 0x84F5
+#define GL_TEXTURE_BINDING_RECTANGLE_ARB 0x84F6
+#define GL_PROXY_TEXTURE_RECTANGLE_ARB 0x84F7
+#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8
+#endif /* GL_ARB_texture_rectangle */
+
+#ifndef GL_ARB_texture_rg
+#define GL_ARB_texture_rg 1
+#endif /* GL_ARB_texture_rg */
+
+#ifndef GL_ARB_texture_rgb10_a2ui
+#define GL_ARB_texture_rgb10_a2ui 1
+#endif /* GL_ARB_texture_rgb10_a2ui */
+
+#ifndef GL_ARB_texture_stencil8
+#define GL_ARB_texture_stencil8 1
+#endif /* GL_ARB_texture_stencil8 */
+
+#ifndef GL_ARB_texture_storage
+#define GL_ARB_texture_storage 1
+#endif /* GL_ARB_texture_storage */
+
+#ifndef GL_ARB_texture_storage_multisample
+#define GL_ARB_texture_storage_multisample 1
+#endif /* GL_ARB_texture_storage_multisample */
+
+#ifndef GL_ARB_texture_swizzle
+#define GL_ARB_texture_swizzle 1
+#endif /* GL_ARB_texture_swizzle */
+
+#ifndef GL_ARB_texture_view
+#define GL_ARB_texture_view 1
+#endif /* GL_ARB_texture_view */
+
+#ifndef GL_ARB_timer_query
+#define GL_ARB_timer_query 1
+#endif /* GL_ARB_timer_query */
+
+#ifndef GL_ARB_transform_feedback2
+#define GL_ARB_transform_feedback2 1
+#define GL_TRANSFORM_FEEDBACK_PAUSED 0x8E23
+#define GL_TRANSFORM_FEEDBACK_ACTIVE 0x8E24
+#endif /* GL_ARB_transform_feedback2 */
+
+#ifndef GL_ARB_transform_feedback3
+#define GL_ARB_transform_feedback3 1
+#endif /* GL_ARB_transform_feedback3 */
+
+#ifndef GL_ARB_transform_feedback_instanced
+#define GL_ARB_transform_feedback_instanced 1
+#endif /* GL_ARB_transform_feedback_instanced */
+
+#ifndef GL_ARB_transpose_matrix
+#define GL_ARB_transpose_matrix 1
+#define GL_TRANSPOSE_MODELVIEW_MATRIX_ARB 0x84E3
+#define GL_TRANSPOSE_PROJECTION_MATRIX_ARB 0x84E4
+#define GL_TRANSPOSE_TEXTURE_MATRIX_ARB 0x84E5
+#define GL_TRANSPOSE_COLOR_MATRIX_ARB 0x84E6
+typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXFARBPROC) (const GLfloat *m);
+typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXDARBPROC) (const GLdouble *m);
+typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXFARBPROC) (const GLfloat *m);
+typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXDARBPROC) (const GLdouble *m);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glLoadTransposeMatrixfARB (const GLfloat *m);
+GLAPI void APIENTRY glLoadTransposeMatrixdARB (const GLdouble *m);
+GLAPI void APIENTRY glMultTransposeMatrixfARB (const GLfloat *m);
+GLAPI void APIENTRY glMultTransposeMatrixdARB (const GLdouble *m);
+#endif
+#endif /* GL_ARB_transpose_matrix */
+
+#ifndef GL_ARB_uniform_buffer_object
+#define GL_ARB_uniform_buffer_object 1
+#define GL_MAX_GEOMETRY_UNIFORM_BLOCKS 0x8A2C
+#define GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS 0x8A32
+#define GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER 0x8A45
+#endif /* GL_ARB_uniform_buffer_object */
+
+#ifndef GL_ARB_vertex_array_bgra
+#define GL_ARB_vertex_array_bgra 1
+#endif /* GL_ARB_vertex_array_bgra */
+
+#ifndef GL_ARB_vertex_array_object
+#define GL_ARB_vertex_array_object 1
+#endif /* GL_ARB_vertex_array_object */
+
+#ifndef GL_ARB_vertex_attrib_64bit
+#define GL_ARB_vertex_attrib_64bit 1
+#endif /* GL_ARB_vertex_attrib_64bit */
+
+#ifndef GL_ARB_vertex_attrib_binding
+#define GL_ARB_vertex_attrib_binding 1
+#endif /* GL_ARB_vertex_attrib_binding */
+
+#ifndef GL_ARB_vertex_blend
+#define GL_ARB_vertex_blend 1
+#define GL_MAX_VERTEX_UNITS_ARB 0x86A4
+#define GL_ACTIVE_VERTEX_UNITS_ARB 0x86A5
+#define GL_WEIGHT_SUM_UNITY_ARB 0x86A6
+#define GL_VERTEX_BLEND_ARB 0x86A7
+#define GL_CURRENT_WEIGHT_ARB 0x86A8
+#define GL_WEIGHT_ARRAY_TYPE_ARB 0x86A9
+#define GL_WEIGHT_ARRAY_STRIDE_ARB 0x86AA
+#define GL_WEIGHT_ARRAY_SIZE_ARB 0x86AB
+#define GL_WEIGHT_ARRAY_POINTER_ARB 0x86AC
+#define GL_WEIGHT_ARRAY_ARB 0x86AD
+#define GL_MODELVIEW0_ARB 0x1700
+#define GL_MODELVIEW1_ARB 0x850A
+#define GL_MODELVIEW2_ARB 0x8722
+#define GL_MODELVIEW3_ARB 0x8723
+#define GL_MODELVIEW4_ARB 0x8724
+#define GL_MODELVIEW5_ARB 0x8725
+#define GL_MODELVIEW6_ARB 0x8726
+#define GL_MODELVIEW7_ARB 0x8727
+#define GL_MODELVIEW8_ARB 0x8728
+#define GL_MODELVIEW9_ARB 0x8729
+#define GL_MODELVIEW10_ARB 0x872A
+#define GL_MODELVIEW11_ARB 0x872B
+#define GL_MODELVIEW12_ARB 0x872C
+#define GL_MODELVIEW13_ARB 0x872D
+#define GL_MODELVIEW14_ARB 0x872E
+#define GL_MODELVIEW15_ARB 0x872F
+#define GL_MODELVIEW16_ARB 0x8730
+#define GL_MODELVIEW17_ARB 0x8731
+#define GL_MODELVIEW18_ARB 0x8732
+#define GL_MODELVIEW19_ARB 0x8733
+#define GL_MODELVIEW20_ARB 0x8734
+#define GL_MODELVIEW21_ARB 0x8735
+#define GL_MODELVIEW22_ARB 0x8736
+#define GL_MODELVIEW23_ARB 0x8737
+#define GL_MODELVIEW24_ARB 0x8738
+#define GL_MODELVIEW25_ARB 0x8739
+#define GL_MODELVIEW26_ARB 0x873A
+#define GL_MODELVIEW27_ARB 0x873B
+#define GL_MODELVIEW28_ARB 0x873C
+#define GL_MODELVIEW29_ARB 0x873D
+#define GL_MODELVIEW30_ARB 0x873E
+#define GL_MODELVIEW31_ARB 0x873F
+typedef void (APIENTRYP PFNGLWEIGHTBVARBPROC) (GLint size, const GLbyte *weights);
+typedef void (APIENTRYP PFNGLWEIGHTSVARBPROC) (GLint size, const GLshort *weights);
+typedef void (APIENTRYP PFNGLWEIGHTIVARBPROC) (GLint size, const GLint *weights);
+typedef void (APIENTRYP PFNGLWEIGHTFVARBPROC) (GLint size, const GLfloat *weights);
+typedef void (APIENTRYP PFNGLWEIGHTDVARBPROC) (GLint size, const GLdouble *weights);
+typedef void (APIENTRYP PFNGLWEIGHTUBVARBPROC) (GLint size, const GLubyte *weights);
+typedef void (APIENTRYP PFNGLWEIGHTUSVARBPROC) (GLint size, const GLushort *weights);
+typedef void (APIENTRYP PFNGLWEIGHTUIVARBPROC) (GLint size, const GLuint *weights);
+typedef void (APIENTRYP PFNGLWEIGHTPOINTERARBPROC) (GLint size, GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLVERTEXBLENDARBPROC) (GLint count);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glWeightbvARB (GLint size, const GLbyte *weights);
+GLAPI void APIENTRY glWeightsvARB (GLint size, const GLshort *weights);
+GLAPI void APIENTRY glWeightivARB (GLint size, const GLint *weights);
+GLAPI void APIENTRY glWeightfvARB (GLint size, const GLfloat *weights);
+GLAPI void APIENTRY glWeightdvARB (GLint size, const GLdouble *weights);
+GLAPI void APIENTRY glWeightubvARB (GLint size, const GLubyte *weights);
+GLAPI void APIENTRY glWeightusvARB (GLint size, const GLushort *weights);
+GLAPI void APIENTRY glWeightuivARB (GLint size, const GLuint *weights);
+GLAPI void APIENTRY glWeightPointerARB (GLint size, GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glVertexBlendARB (GLint count);
+#endif
+#endif /* GL_ARB_vertex_blend */
+
+#ifndef GL_ARB_vertex_buffer_object
+#define GL_ARB_vertex_buffer_object 1
+#ifdef __MACOSX__ /* The OS X headers haven't caught up with Khronos yet */
+typedef long GLsizeiptrARB;
+typedef long GLintptrARB;
+#else
+typedef ptrdiff_t GLsizeiptrARB;
+typedef ptrdiff_t GLintptrARB;
+#endif
+#define GL_BUFFER_SIZE_ARB 0x8764
+#define GL_BUFFER_USAGE_ARB 0x8765
+#define GL_ARRAY_BUFFER_ARB 0x8892
+#define GL_ELEMENT_ARRAY_BUFFER_ARB 0x8893
+#define GL_ARRAY_BUFFER_BINDING_ARB 0x8894
+#define GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB 0x8895
+#define GL_VERTEX_ARRAY_BUFFER_BINDING_ARB 0x8896
+#define GL_NORMAL_ARRAY_BUFFER_BINDING_ARB 0x8897
+#define GL_COLOR_ARRAY_BUFFER_BINDING_ARB 0x8898
+#define GL_INDEX_ARRAY_BUFFER_BINDING_ARB 0x8899
+#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB 0x889A
+#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB 0x889B
+#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB 0x889C
+#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB 0x889D
+#define GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB 0x889E
+#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB 0x889F
+#define GL_READ_ONLY_ARB 0x88B8
+#define GL_WRITE_ONLY_ARB 0x88B9
+#define GL_READ_WRITE_ARB 0x88BA
+#define GL_BUFFER_ACCESS_ARB 0x88BB
+#define GL_BUFFER_MAPPED_ARB 0x88BC
+#define GL_BUFFER_MAP_POINTER_ARB 0x88BD
+#define GL_STREAM_DRAW_ARB 0x88E0
+#define GL_STREAM_READ_ARB 0x88E1
+#define GL_STREAM_COPY_ARB 0x88E2
+#define GL_STATIC_DRAW_ARB 0x88E4
+#define GL_STATIC_READ_ARB 0x88E5
+#define GL_STATIC_COPY_ARB 0x88E6
+#define GL_DYNAMIC_DRAW_ARB 0x88E8
+#define GL_DYNAMIC_READ_ARB 0x88E9
+#define GL_DYNAMIC_COPY_ARB 0x88EA
+typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
+typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
+typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
+typedef GLboolean (APIENTRYP PFNGLISBUFFERARBPROC) (GLuint buffer);
+typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const void *data, GLenum usage);
+typedef void (APIENTRYP PFNGLBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const void *data);
+typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAARBPROC) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, void *data);
+typedef void *(APIENTRYP PFNGLMAPBUFFERARBPROC) (GLenum target, GLenum access);
+typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERARBPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERIVARBPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETBUFFERPOINTERVARBPROC) (GLenum target, GLenum pname, void **params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBindBufferARB (GLenum target, GLuint buffer);
+GLAPI void APIENTRY glDeleteBuffersARB (GLsizei n, const GLuint *buffers);
+GLAPI void APIENTRY glGenBuffersARB (GLsizei n, GLuint *buffers);
+GLAPI GLboolean APIENTRY glIsBufferARB (GLuint buffer);
+GLAPI void APIENTRY glBufferDataARB (GLenum target, GLsizeiptrARB size, const void *data, GLenum usage);
+GLAPI void APIENTRY glBufferSubDataARB (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const void *data);
+GLAPI void APIENTRY glGetBufferSubDataARB (GLenum target, GLintptrARB offset, GLsizeiptrARB size, void *data);
+GLAPI void *APIENTRY glMapBufferARB (GLenum target, GLenum access);
+GLAPI GLboolean APIENTRY glUnmapBufferARB (GLenum target);
+GLAPI void APIENTRY glGetBufferParameterivARB (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetBufferPointervARB (GLenum target, GLenum pname, void **params);
+#endif
+#endif /* GL_ARB_vertex_buffer_object */
+
+#ifndef GL_ARB_vertex_program
+#define GL_ARB_vertex_program 1
+#define GL_COLOR_SUM_ARB 0x8458
+#define GL_VERTEX_PROGRAM_ARB 0x8620
+#define GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB 0x8622
+#define GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB 0x8623
+#define GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB 0x8624
+#define GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB 0x8625
+#define GL_CURRENT_VERTEX_ATTRIB_ARB 0x8626
+#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642
+#define GL_VERTEX_PROGRAM_TWO_SIDE_ARB 0x8643
+#define GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB 0x8645
+#define GL_MAX_VERTEX_ATTRIBS_ARB 0x8869
+#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB 0x886A
+#define GL_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B0
+#define GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB 0x88B1
+#define GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B2
+#define GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB 0x88B3
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1DARBPROC) (GLuint index, GLdouble x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVARBPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1FARBPROC) (GLuint index, GLfloat x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVARBPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1SARBPROC) (GLuint index, GLshort x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVARBPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2DARBPROC) (GLuint index, GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVARBPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2FARBPROC) (GLuint index, GLfloat x, GLfloat y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVARBPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2SARBPROC) (GLuint index, GLshort x, GLshort y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVARBPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVARBPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVARBPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVARBPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NBVARBPROC) (GLuint index, const GLbyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NIVARBPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NSVARBPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBARBPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUBVARBPROC) (GLuint index, const GLubyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUIVARBPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4NUSVARBPROC) (GLuint index, const GLushort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4BVARBPROC) (GLuint index, const GLbyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4DARBPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVARBPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4FARBPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVARBPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4IVARBPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4SARBPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVARBPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVARBPROC) (GLuint index, const GLubyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4UIVARBPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4USVARBPROC) (GLuint index, const GLushort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERARBPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYARBPROC) (GLuint index);
+typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) (GLuint index);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVARBPROC) (GLuint index, GLenum pname, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVARBPROC) (GLuint index, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVARBPROC) (GLuint index, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVARBPROC) (GLuint index, GLenum pname, void **pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexAttrib1dARB (GLuint index, GLdouble x);
+GLAPI void APIENTRY glVertexAttrib1dvARB (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib1fARB (GLuint index, GLfloat x);
+GLAPI void APIENTRY glVertexAttrib1fvARB (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib1sARB (GLuint index, GLshort x);
+GLAPI void APIENTRY glVertexAttrib1svARB (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib2dARB (GLuint index, GLdouble x, GLdouble y);
+GLAPI void APIENTRY glVertexAttrib2dvARB (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib2fARB (GLuint index, GLfloat x, GLfloat y);
+GLAPI void APIENTRY glVertexAttrib2fvARB (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib2sARB (GLuint index, GLshort x, GLshort y);
+GLAPI void APIENTRY glVertexAttrib2svARB (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib3dARB (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glVertexAttrib3dvARB (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib3fARB (GLuint index, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glVertexAttrib3fvARB (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib3sARB (GLuint index, GLshort x, GLshort y, GLshort z);
+GLAPI void APIENTRY glVertexAttrib3svARB (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib4NbvARB (GLuint index, const GLbyte *v);
+GLAPI void APIENTRY glVertexAttrib4NivARB (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttrib4NsvARB (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib4NubARB (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w);
+GLAPI void APIENTRY glVertexAttrib4NubvARB (GLuint index, const GLubyte *v);
+GLAPI void APIENTRY glVertexAttrib4NuivARB (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttrib4NusvARB (GLuint index, const GLushort *v);
+GLAPI void APIENTRY glVertexAttrib4bvARB (GLuint index, const GLbyte *v);
+GLAPI void APIENTRY glVertexAttrib4dARB (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glVertexAttrib4dvARB (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib4fARB (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glVertexAttrib4fvARB (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib4ivARB (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttrib4sARB (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w);
+GLAPI void APIENTRY glVertexAttrib4svARB (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib4ubvARB (GLuint index, const GLubyte *v);
+GLAPI void APIENTRY glVertexAttrib4uivARB (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttrib4usvARB (GLuint index, const GLushort *v);
+GLAPI void APIENTRY glVertexAttribPointerARB (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glEnableVertexAttribArrayARB (GLuint index);
+GLAPI void APIENTRY glDisableVertexAttribArrayARB (GLuint index);
+GLAPI void APIENTRY glGetVertexAttribdvARB (GLuint index, GLenum pname, GLdouble *params);
+GLAPI void APIENTRY glGetVertexAttribfvARB (GLuint index, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetVertexAttribivARB (GLuint index, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetVertexAttribPointervARB (GLuint index, GLenum pname, void **pointer);
+#endif
+#endif /* GL_ARB_vertex_program */
+
+#ifndef GL_ARB_vertex_shader
+#define GL_ARB_vertex_shader 1
+#define GL_VERTEX_SHADER_ARB 0x8B31
+#define GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB 0x8B4A
+#define GL_MAX_VARYING_FLOATS_ARB 0x8B4B
+#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB 0x8B4C
+#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB 0x8B4D
+#define GL_OBJECT_ACTIVE_ATTRIBUTES_ARB 0x8B89
+#define GL_OBJECT_ACTIVE_ATTRIBUTE_MAX_LENGTH_ARB 0x8B8A
+typedef void (APIENTRYP PFNGLBINDATTRIBLOCATIONARBPROC) (GLhandleARB programObj, GLuint index, const GLcharARB *name);
+typedef void (APIENTRYP PFNGLGETACTIVEATTRIBARBPROC) (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name);
+typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBindAttribLocationARB (GLhandleARB programObj, GLuint index, const GLcharARB *name);
+GLAPI void APIENTRY glGetActiveAttribARB (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name);
+GLAPI GLint APIENTRY glGetAttribLocationARB (GLhandleARB programObj, const GLcharARB *name);
+#endif
+#endif /* GL_ARB_vertex_shader */
+
+#ifndef GL_ARB_vertex_type_10f_11f_11f_rev
+#define GL_ARB_vertex_type_10f_11f_11f_rev 1
+#endif /* GL_ARB_vertex_type_10f_11f_11f_rev */
+
+#ifndef GL_ARB_vertex_type_2_10_10_10_rev
+#define GL_ARB_vertex_type_2_10_10_10_rev 1
+#endif /* GL_ARB_vertex_type_2_10_10_10_rev */
+
+#ifndef GL_ARB_viewport_array
+#define GL_ARB_viewport_array 1
+#endif /* GL_ARB_viewport_array */
+
+#ifndef GL_ARB_window_pos
+#define GL_ARB_window_pos 1
+typedef void (APIENTRYP PFNGLWINDOWPOS2DARBPROC) (GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2DVARBPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS2FARBPROC) (GLfloat x, GLfloat y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2FVARBPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS2IARBPROC) (GLint x, GLint y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2IVARBPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS2SARBPROC) (GLshort x, GLshort y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2SVARBPROC) (const GLshort *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3DARBPROC) (GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3DVARBPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3FARBPROC) (GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3FVARBPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3IARBPROC) (GLint x, GLint y, GLint z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3IVARBPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3SARBPROC) (GLshort x, GLshort y, GLshort z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3SVARBPROC) (const GLshort *v);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glWindowPos2dARB (GLdouble x, GLdouble y);
+GLAPI void APIENTRY glWindowPos2dvARB (const GLdouble *v);
+GLAPI void APIENTRY glWindowPos2fARB (GLfloat x, GLfloat y);
+GLAPI void APIENTRY glWindowPos2fvARB (const GLfloat *v);
+GLAPI void APIENTRY glWindowPos2iARB (GLint x, GLint y);
+GLAPI void APIENTRY glWindowPos2ivARB (const GLint *v);
+GLAPI void APIENTRY glWindowPos2sARB (GLshort x, GLshort y);
+GLAPI void APIENTRY glWindowPos2svARB (const GLshort *v);
+GLAPI void APIENTRY glWindowPos3dARB (GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glWindowPos3dvARB (const GLdouble *v);
+GLAPI void APIENTRY glWindowPos3fARB (GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glWindowPos3fvARB (const GLfloat *v);
+GLAPI void APIENTRY glWindowPos3iARB (GLint x, GLint y, GLint z);
+GLAPI void APIENTRY glWindowPos3ivARB (const GLint *v);
+GLAPI void APIENTRY glWindowPos3sARB (GLshort x, GLshort y, GLshort z);
+GLAPI void APIENTRY glWindowPos3svARB (const GLshort *v);
+#endif
+#endif /* GL_ARB_window_pos */
+
+#ifndef GL_KHR_debug
+#define GL_KHR_debug 1
+#endif /* GL_KHR_debug */
+
+#ifndef GL_KHR_texture_compression_astc_hdr
+#define GL_KHR_texture_compression_astc_hdr 1
+#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0
+#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1
+#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2
+#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3
+#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4
+#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5
+#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6
+#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7
+#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8
+#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9
+#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA
+#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB
+#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC
+#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD
+#endif /* GL_KHR_texture_compression_astc_hdr */
+
+#ifndef GL_KHR_texture_compression_astc_ldr
+#define GL_KHR_texture_compression_astc_ldr 1
+#endif /* GL_KHR_texture_compression_astc_ldr */
+
+#ifndef GL_OES_byte_coordinates
+#define GL_OES_byte_coordinates 1
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1BOESPROC) (GLenum texture, GLbyte s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1BVOESPROC) (GLenum texture, const GLbyte *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2BOESPROC) (GLenum texture, GLbyte s, GLbyte t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2BVOESPROC) (GLenum texture, const GLbyte *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3BOESPROC) (GLenum texture, GLbyte s, GLbyte t, GLbyte r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3BVOESPROC) (GLenum texture, const GLbyte *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4BOESPROC) (GLenum texture, GLbyte s, GLbyte t, GLbyte r, GLbyte q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4BVOESPROC) (GLenum texture, const GLbyte *coords);
+typedef void (APIENTRYP PFNGLTEXCOORD1BOESPROC) (GLbyte s);
+typedef void (APIENTRYP PFNGLTEXCOORD1BVOESPROC) (const GLbyte *coords);
+typedef void (APIENTRYP PFNGLTEXCOORD2BOESPROC) (GLbyte s, GLbyte t);
+typedef void (APIENTRYP PFNGLTEXCOORD2BVOESPROC) (const GLbyte *coords);
+typedef void (APIENTRYP PFNGLTEXCOORD3BOESPROC) (GLbyte s, GLbyte t, GLbyte r);
+typedef void (APIENTRYP PFNGLTEXCOORD3BVOESPROC) (const GLbyte *coords);
+typedef void (APIENTRYP PFNGLTEXCOORD4BOESPROC) (GLbyte s, GLbyte t, GLbyte r, GLbyte q);
+typedef void (APIENTRYP PFNGLTEXCOORD4BVOESPROC) (const GLbyte *coords);
+typedef void (APIENTRYP PFNGLVERTEX2BOESPROC) (GLbyte x);
+typedef void (APIENTRYP PFNGLVERTEX2BVOESPROC) (const GLbyte *coords);
+typedef void (APIENTRYP PFNGLVERTEX3BOESPROC) (GLbyte x, GLbyte y);
+typedef void (APIENTRYP PFNGLVERTEX3BVOESPROC) (const GLbyte *coords);
+typedef void (APIENTRYP PFNGLVERTEX4BOESPROC) (GLbyte x, GLbyte y, GLbyte z);
+typedef void (APIENTRYP PFNGLVERTEX4BVOESPROC) (const GLbyte *coords);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMultiTexCoord1bOES (GLenum texture, GLbyte s);
+GLAPI void APIENTRY glMultiTexCoord1bvOES (GLenum texture, const GLbyte *coords);
+GLAPI void APIENTRY glMultiTexCoord2bOES (GLenum texture, GLbyte s, GLbyte t);
+GLAPI void APIENTRY glMultiTexCoord2bvOES (GLenum texture, const GLbyte *coords);
+GLAPI void APIENTRY glMultiTexCoord3bOES (GLenum texture, GLbyte s, GLbyte t, GLbyte r);
+GLAPI void APIENTRY glMultiTexCoord3bvOES (GLenum texture, const GLbyte *coords);
+GLAPI void APIENTRY glMultiTexCoord4bOES (GLenum texture, GLbyte s, GLbyte t, GLbyte r, GLbyte q);
+GLAPI void APIENTRY glMultiTexCoord4bvOES (GLenum texture, const GLbyte *coords);
+GLAPI void APIENTRY glTexCoord1bOES (GLbyte s);
+GLAPI void APIENTRY glTexCoord1bvOES (const GLbyte *coords);
+GLAPI void APIENTRY glTexCoord2bOES (GLbyte s, GLbyte t);
+GLAPI void APIENTRY glTexCoord2bvOES (const GLbyte *coords);
+GLAPI void APIENTRY glTexCoord3bOES (GLbyte s, GLbyte t, GLbyte r);
+GLAPI void APIENTRY glTexCoord3bvOES (const GLbyte *coords);
+GLAPI void APIENTRY glTexCoord4bOES (GLbyte s, GLbyte t, GLbyte r, GLbyte q);
+GLAPI void APIENTRY glTexCoord4bvOES (const GLbyte *coords);
+GLAPI void APIENTRY glVertex2bOES (GLbyte x);
+GLAPI void APIENTRY glVertex2bvOES (const GLbyte *coords);
+GLAPI void APIENTRY glVertex3bOES (GLbyte x, GLbyte y);
+GLAPI void APIENTRY glVertex3bvOES (const GLbyte *coords);
+GLAPI void APIENTRY glVertex4bOES (GLbyte x, GLbyte y, GLbyte z);
+GLAPI void APIENTRY glVertex4bvOES (const GLbyte *coords);
+#endif
+#endif /* GL_OES_byte_coordinates */
+
+#ifndef GL_OES_compressed_paletted_texture
+#define GL_OES_compressed_paletted_texture 1
+#define GL_PALETTE4_RGB8_OES 0x8B90
+#define GL_PALETTE4_RGBA8_OES 0x8B91
+#define GL_PALETTE4_R5_G6_B5_OES 0x8B92
+#define GL_PALETTE4_RGBA4_OES 0x8B93
+#define GL_PALETTE4_RGB5_A1_OES 0x8B94
+#define GL_PALETTE8_RGB8_OES 0x8B95
+#define GL_PALETTE8_RGBA8_OES 0x8B96
+#define GL_PALETTE8_R5_G6_B5_OES 0x8B97
+#define GL_PALETTE8_RGBA4_OES 0x8B98
+#define GL_PALETTE8_RGB5_A1_OES 0x8B99
+#endif /* GL_OES_compressed_paletted_texture */
+
+#ifndef GL_OES_fixed_point
+#define GL_OES_fixed_point 1
+typedef GLint GLfixed;
+#define GL_FIXED_OES 0x140C
+typedef void (APIENTRYP PFNGLALPHAFUNCXOESPROC) (GLenum func, GLfixed ref);
+typedef void (APIENTRYP PFNGLCLEARCOLORXOESPROC) (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha);
+typedef void (APIENTRYP PFNGLCLEARDEPTHXOESPROC) (GLfixed depth);
+typedef void (APIENTRYP PFNGLCLIPPLANEXOESPROC) (GLenum plane, const GLfixed *equation);
+typedef void (APIENTRYP PFNGLCOLOR4XOESPROC) (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha);
+typedef void (APIENTRYP PFNGLDEPTHRANGEXOESPROC) (GLfixed n, GLfixed f);
+typedef void (APIENTRYP PFNGLFOGXOESPROC) (GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLFOGXVOESPROC) (GLenum pname, const GLfixed *param);
+typedef void (APIENTRYP PFNGLFRUSTUMXOESPROC) (GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f);
+typedef void (APIENTRYP PFNGLGETCLIPPLANEXOESPROC) (GLenum plane, GLfixed *equation);
+typedef void (APIENTRYP PFNGLGETFIXEDVOESPROC) (GLenum pname, GLfixed *params);
+typedef void (APIENTRYP PFNGLGETTEXENVXVOESPROC) (GLenum target, GLenum pname, GLfixed *params);
+typedef void (APIENTRYP PFNGLGETTEXPARAMETERXVOESPROC) (GLenum target, GLenum pname, GLfixed *params);
+typedef void (APIENTRYP PFNGLLIGHTMODELXOESPROC) (GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLLIGHTMODELXVOESPROC) (GLenum pname, const GLfixed *param);
+typedef void (APIENTRYP PFNGLLIGHTXOESPROC) (GLenum light, GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLLIGHTXVOESPROC) (GLenum light, GLenum pname, const GLfixed *params);
+typedef void (APIENTRYP PFNGLLINEWIDTHXOESPROC) (GLfixed width);
+typedef void (APIENTRYP PFNGLLOADMATRIXXOESPROC) (const GLfixed *m);
+typedef void (APIENTRYP PFNGLMATERIALXOESPROC) (GLenum face, GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLMATERIALXVOESPROC) (GLenum face, GLenum pname, const GLfixed *param);
+typedef void (APIENTRYP PFNGLMULTMATRIXXOESPROC) (const GLfixed *m);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4XOESPROC) (GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q);
+typedef void (APIENTRYP PFNGLNORMAL3XOESPROC) (GLfixed nx, GLfixed ny, GLfixed nz);
+typedef void (APIENTRYP PFNGLORTHOXOESPROC) (GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f);
+typedef void (APIENTRYP PFNGLPOINTPARAMETERXVOESPROC) (GLenum pname, const GLfixed *params);
+typedef void (APIENTRYP PFNGLPOINTSIZEXOESPROC) (GLfixed size);
+typedef void (APIENTRYP PFNGLPOLYGONOFFSETXOESPROC) (GLfixed factor, GLfixed units);
+typedef void (APIENTRYP PFNGLROTATEXOESPROC) (GLfixed angle, GLfixed x, GLfixed y, GLfixed z);
+typedef void (APIENTRYP PFNGLSAMPLECOVERAGEOESPROC) (GLfixed value, GLboolean invert);
+typedef void (APIENTRYP PFNGLSCALEXOESPROC) (GLfixed x, GLfixed y, GLfixed z);
+typedef void (APIENTRYP PFNGLTEXENVXOESPROC) (GLenum target, GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLTEXENVXVOESPROC) (GLenum target, GLenum pname, const GLfixed *params);
+typedef void (APIENTRYP PFNGLTEXPARAMETERXOESPROC) (GLenum target, GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLTEXPARAMETERXVOESPROC) (GLenum target, GLenum pname, const GLfixed *params);
+typedef void (APIENTRYP PFNGLTRANSLATEXOESPROC) (GLfixed x, GLfixed y, GLfixed z);
+typedef void (APIENTRYP PFNGLACCUMXOESPROC) (GLenum op, GLfixed value);
+typedef void (APIENTRYP PFNGLBITMAPXOESPROC) (GLsizei width, GLsizei height, GLfixed xorig, GLfixed yorig, GLfixed xmove, GLfixed ymove, const GLubyte *bitmap);
+typedef void (APIENTRYP PFNGLBLENDCOLORXOESPROC) (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha);
+typedef void (APIENTRYP PFNGLCLEARACCUMXOESPROC) (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha);
+typedef void (APIENTRYP PFNGLCOLOR3XOESPROC) (GLfixed red, GLfixed green, GLfixed blue);
+typedef void (APIENTRYP PFNGLCOLOR3XVOESPROC) (const GLfixed *components);
+typedef void (APIENTRYP PFNGLCOLOR4XVOESPROC) (const GLfixed *components);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERXOESPROC) (GLenum target, GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERXVOESPROC) (GLenum target, GLenum pname, const GLfixed *params);
+typedef void (APIENTRYP PFNGLEVALCOORD1XOESPROC) (GLfixed u);
+typedef void (APIENTRYP PFNGLEVALCOORD1XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLEVALCOORD2XOESPROC) (GLfixed u, GLfixed v);
+typedef void (APIENTRYP PFNGLEVALCOORD2XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLFEEDBACKBUFFERXOESPROC) (GLsizei n, GLenum type, const GLfixed *buffer);
+typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERXVOESPROC) (GLenum target, GLenum pname, GLfixed *params);
+typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERXVOESPROC) (GLenum target, GLenum pname, GLfixed *params);
+typedef void (APIENTRYP PFNGLGETLIGHTXOESPROC) (GLenum light, GLenum pname, GLfixed *params);
+typedef void (APIENTRYP PFNGLGETMAPXVOESPROC) (GLenum target, GLenum query, GLfixed *v);
+typedef void (APIENTRYP PFNGLGETMATERIALXOESPROC) (GLenum face, GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLGETPIXELMAPXVPROC) (GLenum map, GLint size, GLfixed *values);
+typedef void (APIENTRYP PFNGLGETTEXGENXVOESPROC) (GLenum coord, GLenum pname, GLfixed *params);
+typedef void (APIENTRYP PFNGLGETTEXLEVELPARAMETERXVOESPROC) (GLenum target, GLint level, GLenum pname, GLfixed *params);
+typedef void (APIENTRYP PFNGLINDEXXOESPROC) (GLfixed component);
+typedef void (APIENTRYP PFNGLINDEXXVOESPROC) (const GLfixed *component);
+typedef void (APIENTRYP PFNGLLOADTRANSPOSEMATRIXXOESPROC) (const GLfixed *m);
+typedef void (APIENTRYP PFNGLMAP1XOESPROC) (GLenum target, GLfixed u1, GLfixed u2, GLint stride, GLint order, GLfixed points);
+typedef void (APIENTRYP PFNGLMAP2XOESPROC) (GLenum target, GLfixed u1, GLfixed u2, GLint ustride, GLint uorder, GLfixed v1, GLfixed v2, GLint vstride, GLint vorder, GLfixed points);
+typedef void (APIENTRYP PFNGLMAPGRID1XOESPROC) (GLint n, GLfixed u1, GLfixed u2);
+typedef void (APIENTRYP PFNGLMAPGRID2XOESPROC) (GLint n, GLfixed u1, GLfixed u2, GLfixed v1, GLfixed v2);
+typedef void (APIENTRYP PFNGLMULTTRANSPOSEMATRIXXOESPROC) (const GLfixed *m);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1XOESPROC) (GLenum texture, GLfixed s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1XVOESPROC) (GLenum texture, const GLfixed *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2XOESPROC) (GLenum texture, GLfixed s, GLfixed t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2XVOESPROC) (GLenum texture, const GLfixed *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3XOESPROC) (GLenum texture, GLfixed s, GLfixed t, GLfixed r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3XVOESPROC) (GLenum texture, const GLfixed *coords);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4XVOESPROC) (GLenum texture, const GLfixed *coords);
+typedef void (APIENTRYP PFNGLNORMAL3XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLPASSTHROUGHXOESPROC) (GLfixed token);
+typedef void (APIENTRYP PFNGLPIXELMAPXPROC) (GLenum map, GLint size, const GLfixed *values);
+typedef void (APIENTRYP PFNGLPIXELSTOREXPROC) (GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLPIXELTRANSFERXOESPROC) (GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLPIXELZOOMXOESPROC) (GLfixed xfactor, GLfixed yfactor);
+typedef void (APIENTRYP PFNGLPRIORITIZETEXTURESXOESPROC) (GLsizei n, const GLuint *textures, const GLfixed *priorities);
+typedef void (APIENTRYP PFNGLRASTERPOS2XOESPROC) (GLfixed x, GLfixed y);
+typedef void (APIENTRYP PFNGLRASTERPOS2XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLRASTERPOS3XOESPROC) (GLfixed x, GLfixed y, GLfixed z);
+typedef void (APIENTRYP PFNGLRASTERPOS3XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLRASTERPOS4XOESPROC) (GLfixed x, GLfixed y, GLfixed z, GLfixed w);
+typedef void (APIENTRYP PFNGLRASTERPOS4XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLRECTXOESPROC) (GLfixed x1, GLfixed y1, GLfixed x2, GLfixed y2);
+typedef void (APIENTRYP PFNGLRECTXVOESPROC) (const GLfixed *v1, const GLfixed *v2);
+typedef void (APIENTRYP PFNGLTEXCOORD1XOESPROC) (GLfixed s);
+typedef void (APIENTRYP PFNGLTEXCOORD1XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLTEXCOORD2XOESPROC) (GLfixed s, GLfixed t);
+typedef void (APIENTRYP PFNGLTEXCOORD2XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLTEXCOORD3XOESPROC) (GLfixed s, GLfixed t, GLfixed r);
+typedef void (APIENTRYP PFNGLTEXCOORD3XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLTEXCOORD4XOESPROC) (GLfixed s, GLfixed t, GLfixed r, GLfixed q);
+typedef void (APIENTRYP PFNGLTEXCOORD4XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLTEXGENXOESPROC) (GLenum coord, GLenum pname, GLfixed param);
+typedef void (APIENTRYP PFNGLTEXGENXVOESPROC) (GLenum coord, GLenum pname, const GLfixed *params);
+typedef void (APIENTRYP PFNGLVERTEX2XOESPROC) (GLfixed x);
+typedef void (APIENTRYP PFNGLVERTEX2XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLVERTEX3XOESPROC) (GLfixed x, GLfixed y);
+typedef void (APIENTRYP PFNGLVERTEX3XVOESPROC) (const GLfixed *coords);
+typedef void (APIENTRYP PFNGLVERTEX4XOESPROC) (GLfixed x, GLfixed y, GLfixed z);
+typedef void (APIENTRYP PFNGLVERTEX4XVOESPROC) (const GLfixed *coords);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glAlphaFuncxOES (GLenum func, GLfixed ref);
+GLAPI void APIENTRY glClearColorxOES (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha);
+GLAPI void APIENTRY glClearDepthxOES (GLfixed depth);
+GLAPI void APIENTRY glClipPlanexOES (GLenum plane, const GLfixed *equation);
+GLAPI void APIENTRY glColor4xOES (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha);
+GLAPI void APIENTRY glDepthRangexOES (GLfixed n, GLfixed f);
+GLAPI void APIENTRY glFogxOES (GLenum pname, GLfixed param);
+GLAPI void APIENTRY glFogxvOES (GLenum pname, const GLfixed *param);
+GLAPI void APIENTRY glFrustumxOES (GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f);
+GLAPI void APIENTRY glGetClipPlanexOES (GLenum plane, GLfixed *equation);
+GLAPI void APIENTRY glGetFixedvOES (GLenum pname, GLfixed *params);
+GLAPI void APIENTRY glGetTexEnvxvOES (GLenum target, GLenum pname, GLfixed *params);
+GLAPI void APIENTRY glGetTexParameterxvOES (GLenum target, GLenum pname, GLfixed *params);
+GLAPI void APIENTRY glLightModelxOES (GLenum pname, GLfixed param);
+GLAPI void APIENTRY glLightModelxvOES (GLenum pname, const GLfixed *param);
+GLAPI void APIENTRY glLightxOES (GLenum light, GLenum pname, GLfixed param);
+GLAPI void APIENTRY glLightxvOES (GLenum light, GLenum pname, const GLfixed *params);
+GLAPI void APIENTRY glLineWidthxOES (GLfixed width);
+GLAPI void APIENTRY glLoadMatrixxOES (const GLfixed *m);
+GLAPI void APIENTRY glMaterialxOES (GLenum face, GLenum pname, GLfixed param);
+GLAPI void APIENTRY glMaterialxvOES (GLenum face, GLenum pname, const GLfixed *param);
+GLAPI void APIENTRY glMultMatrixxOES (const GLfixed *m);
+GLAPI void APIENTRY glMultiTexCoord4xOES (GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q);
+GLAPI void APIENTRY glNormal3xOES (GLfixed nx, GLfixed ny, GLfixed nz);
+GLAPI void APIENTRY glOrthoxOES (GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f);
+GLAPI void APIENTRY glPointParameterxvOES (GLenum pname, const GLfixed *params);
+GLAPI void APIENTRY glPointSizexOES (GLfixed size);
+GLAPI void APIENTRY glPolygonOffsetxOES (GLfixed factor, GLfixed units);
+GLAPI void APIENTRY glRotatexOES (GLfixed angle, GLfixed x, GLfixed y, GLfixed z);
+GLAPI void APIENTRY glSampleCoverageOES (GLfixed value, GLboolean invert);
+GLAPI void APIENTRY glScalexOES (GLfixed x, GLfixed y, GLfixed z);
+GLAPI void APIENTRY glTexEnvxOES (GLenum target, GLenum pname, GLfixed param);
+GLAPI void APIENTRY glTexEnvxvOES (GLenum target, GLenum pname, const GLfixed *params);
+GLAPI void APIENTRY glTexParameterxOES (GLenum target, GLenum pname, GLfixed param);
+GLAPI void APIENTRY glTexParameterxvOES (GLenum target, GLenum pname, const GLfixed *params);
+GLAPI void APIENTRY glTranslatexOES (GLfixed x, GLfixed y, GLfixed z);
+GLAPI void APIENTRY glAccumxOES (GLenum op, GLfixed value);
+GLAPI void APIENTRY glBitmapxOES (GLsizei width, GLsizei height, GLfixed xorig, GLfixed yorig, GLfixed xmove, GLfixed ymove, const GLubyte *bitmap);
+GLAPI void APIENTRY glBlendColorxOES (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha);
+GLAPI void APIENTRY glClearAccumxOES (GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha);
+GLAPI void APIENTRY glColor3xOES (GLfixed red, GLfixed green, GLfixed blue);
+GLAPI void APIENTRY glColor3xvOES (const GLfixed *components);
+GLAPI void APIENTRY glColor4xvOES (const GLfixed *components);
+GLAPI void APIENTRY glConvolutionParameterxOES (GLenum target, GLenum pname, GLfixed param);
+GLAPI void APIENTRY glConvolutionParameterxvOES (GLenum target, GLenum pname, const GLfixed *params);
+GLAPI void APIENTRY glEvalCoord1xOES (GLfixed u);
+GLAPI void APIENTRY glEvalCoord1xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glEvalCoord2xOES (GLfixed u, GLfixed v);
+GLAPI void APIENTRY glEvalCoord2xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glFeedbackBufferxOES (GLsizei n, GLenum type, const GLfixed *buffer);
+GLAPI void APIENTRY glGetConvolutionParameterxvOES (GLenum target, GLenum pname, GLfixed *params);
+GLAPI void APIENTRY glGetHistogramParameterxvOES (GLenum target, GLenum pname, GLfixed *params);
+GLAPI void APIENTRY glGetLightxOES (GLenum light, GLenum pname, GLfixed *params);
+GLAPI void APIENTRY glGetMapxvOES (GLenum target, GLenum query, GLfixed *v);
+GLAPI void APIENTRY glGetMaterialxOES (GLenum face, GLenum pname, GLfixed param);
+GLAPI void APIENTRY glGetPixelMapxv (GLenum map, GLint size, GLfixed *values);
+GLAPI void APIENTRY glGetTexGenxvOES (GLenum coord, GLenum pname, GLfixed *params);
+GLAPI void APIENTRY glGetTexLevelParameterxvOES (GLenum target, GLint level, GLenum pname, GLfixed *params);
+GLAPI void APIENTRY glIndexxOES (GLfixed component);
+GLAPI void APIENTRY glIndexxvOES (const GLfixed *component);
+GLAPI void APIENTRY glLoadTransposeMatrixxOES (const GLfixed *m);
+GLAPI void APIENTRY glMap1xOES (GLenum target, GLfixed u1, GLfixed u2, GLint stride, GLint order, GLfixed points);
+GLAPI void APIENTRY glMap2xOES (GLenum target, GLfixed u1, GLfixed u2, GLint ustride, GLint uorder, GLfixed v1, GLfixed v2, GLint vstride, GLint vorder, GLfixed points);
+GLAPI void APIENTRY glMapGrid1xOES (GLint n, GLfixed u1, GLfixed u2);
+GLAPI void APIENTRY glMapGrid2xOES (GLint n, GLfixed u1, GLfixed u2, GLfixed v1, GLfixed v2);
+GLAPI void APIENTRY glMultTransposeMatrixxOES (const GLfixed *m);
+GLAPI void APIENTRY glMultiTexCoord1xOES (GLenum texture, GLfixed s);
+GLAPI void APIENTRY glMultiTexCoord1xvOES (GLenum texture, const GLfixed *coords);
+GLAPI void APIENTRY glMultiTexCoord2xOES (GLenum texture, GLfixed s, GLfixed t);
+GLAPI void APIENTRY glMultiTexCoord2xvOES (GLenum texture, const GLfixed *coords);
+GLAPI void APIENTRY glMultiTexCoord3xOES (GLenum texture, GLfixed s, GLfixed t, GLfixed r);
+GLAPI void APIENTRY glMultiTexCoord3xvOES (GLenum texture, const GLfixed *coords);
+GLAPI void APIENTRY glMultiTexCoord4xvOES (GLenum texture, const GLfixed *coords);
+GLAPI void APIENTRY glNormal3xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glPassThroughxOES (GLfixed token);
+GLAPI void APIENTRY glPixelMapx (GLenum map, GLint size, const GLfixed *values);
+GLAPI void APIENTRY glPixelStorex (GLenum pname, GLfixed param);
+GLAPI void APIENTRY glPixelTransferxOES (GLenum pname, GLfixed param);
+GLAPI void APIENTRY glPixelZoomxOES (GLfixed xfactor, GLfixed yfactor);
+GLAPI void APIENTRY glPrioritizeTexturesxOES (GLsizei n, const GLuint *textures, const GLfixed *priorities);
+GLAPI void APIENTRY glRasterPos2xOES (GLfixed x, GLfixed y);
+GLAPI void APIENTRY glRasterPos2xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glRasterPos3xOES (GLfixed x, GLfixed y, GLfixed z);
+GLAPI void APIENTRY glRasterPos3xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glRasterPos4xOES (GLfixed x, GLfixed y, GLfixed z, GLfixed w);
+GLAPI void APIENTRY glRasterPos4xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glRectxOES (GLfixed x1, GLfixed y1, GLfixed x2, GLfixed y2);
+GLAPI void APIENTRY glRectxvOES (const GLfixed *v1, const GLfixed *v2);
+GLAPI void APIENTRY glTexCoord1xOES (GLfixed s);
+GLAPI void APIENTRY glTexCoord1xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glTexCoord2xOES (GLfixed s, GLfixed t);
+GLAPI void APIENTRY glTexCoord2xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glTexCoord3xOES (GLfixed s, GLfixed t, GLfixed r);
+GLAPI void APIENTRY glTexCoord3xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glTexCoord4xOES (GLfixed s, GLfixed t, GLfixed r, GLfixed q);
+GLAPI void APIENTRY glTexCoord4xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glTexGenxOES (GLenum coord, GLenum pname, GLfixed param);
+GLAPI void APIENTRY glTexGenxvOES (GLenum coord, GLenum pname, const GLfixed *params);
+GLAPI void APIENTRY glVertex2xOES (GLfixed x);
+GLAPI void APIENTRY glVertex2xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glVertex3xOES (GLfixed x, GLfixed y);
+GLAPI void APIENTRY glVertex3xvOES (const GLfixed *coords);
+GLAPI void APIENTRY glVertex4xOES (GLfixed x, GLfixed y, GLfixed z);
+GLAPI void APIENTRY glVertex4xvOES (const GLfixed *coords);
+#endif
+#endif /* GL_OES_fixed_point */
+
+#ifndef GL_OES_query_matrix
+#define GL_OES_query_matrix 1
+typedef GLbitfield (APIENTRYP PFNGLQUERYMATRIXXOESPROC) (GLfixed *mantissa, GLint *exponent);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLbitfield APIENTRY glQueryMatrixxOES (GLfixed *mantissa, GLint *exponent);
+#endif
+#endif /* GL_OES_query_matrix */
+
+#ifndef GL_OES_read_format
+#define GL_OES_read_format 1
+#define GL_IMPLEMENTATION_COLOR_READ_TYPE_OES 0x8B9A
+#define GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES 0x8B9B
+#endif /* GL_OES_read_format */
+
+#ifndef GL_OES_single_precision
+#define GL_OES_single_precision 1
+typedef void (APIENTRYP PFNGLCLEARDEPTHFOESPROC) (GLclampf depth);
+typedef void (APIENTRYP PFNGLCLIPPLANEFOESPROC) (GLenum plane, const GLfloat *equation);
+typedef void (APIENTRYP PFNGLDEPTHRANGEFOESPROC) (GLclampf n, GLclampf f);
+typedef void (APIENTRYP PFNGLFRUSTUMFOESPROC) (GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f);
+typedef void (APIENTRYP PFNGLGETCLIPPLANEFOESPROC) (GLenum plane, GLfloat *equation);
+typedef void (APIENTRYP PFNGLORTHOFOESPROC) (GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glClearDepthfOES (GLclampf depth);
+GLAPI void APIENTRY glClipPlanefOES (GLenum plane, const GLfloat *equation);
+GLAPI void APIENTRY glDepthRangefOES (GLclampf n, GLclampf f);
+GLAPI void APIENTRY glFrustumfOES (GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f);
+GLAPI void APIENTRY glGetClipPlanefOES (GLenum plane, GLfloat *equation);
+GLAPI void APIENTRY glOrthofOES (GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f);
+#endif
+#endif /* GL_OES_single_precision */
+
+#ifndef GL_3DFX_multisample
+#define GL_3DFX_multisample 1
+#define GL_MULTISAMPLE_3DFX 0x86B2
+#define GL_SAMPLE_BUFFERS_3DFX 0x86B3
+#define GL_SAMPLES_3DFX 0x86B4
+#define GL_MULTISAMPLE_BIT_3DFX 0x20000000
+#endif /* GL_3DFX_multisample */
+
+#ifndef GL_3DFX_tbuffer
+#define GL_3DFX_tbuffer 1
+typedef void (APIENTRYP PFNGLTBUFFERMASK3DFXPROC) (GLuint mask);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTbufferMask3DFX (GLuint mask);
+#endif
+#endif /* GL_3DFX_tbuffer */
+
+#ifndef GL_3DFX_texture_compression_FXT1
+#define GL_3DFX_texture_compression_FXT1 1
+#define GL_COMPRESSED_RGB_FXT1_3DFX 0x86B0
+#define GL_COMPRESSED_RGBA_FXT1_3DFX 0x86B1
+#endif /* GL_3DFX_texture_compression_FXT1 */
+
+#ifndef GL_AMD_blend_minmax_factor
+#define GL_AMD_blend_minmax_factor 1
+#define GL_FACTOR_MIN_AMD 0x901C
+#define GL_FACTOR_MAX_AMD 0x901D
+#endif /* GL_AMD_blend_minmax_factor */
+
+#ifndef GL_AMD_conservative_depth
+#define GL_AMD_conservative_depth 1
+#endif /* GL_AMD_conservative_depth */
+
+#ifndef GL_AMD_debug_output
+#define GL_AMD_debug_output 1
+typedef void (APIENTRY *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,void *userParam);
+#define GL_MAX_DEBUG_MESSAGE_LENGTH_AMD 0x9143
+#define GL_MAX_DEBUG_LOGGED_MESSAGES_AMD 0x9144
+#define GL_DEBUG_LOGGED_MESSAGES_AMD 0x9145
+#define GL_DEBUG_SEVERITY_HIGH_AMD 0x9146
+#define GL_DEBUG_SEVERITY_MEDIUM_AMD 0x9147
+#define GL_DEBUG_SEVERITY_LOW_AMD 0x9148
+#define GL_DEBUG_CATEGORY_API_ERROR_AMD 0x9149
+#define GL_DEBUG_CATEGORY_WINDOW_SYSTEM_AMD 0x914A
+#define GL_DEBUG_CATEGORY_DEPRECATION_AMD 0x914B
+#define GL_DEBUG_CATEGORY_UNDEFINED_BEHAVIOR_AMD 0x914C
+#define GL_DEBUG_CATEGORY_PERFORMANCE_AMD 0x914D
+#define GL_DEBUG_CATEGORY_SHADER_COMPILER_AMD 0x914E
+#define GL_DEBUG_CATEGORY_APPLICATION_AMD 0x914F
+#define GL_DEBUG_CATEGORY_OTHER_AMD 0x9150
+typedef void (APIENTRYP PFNGLDEBUGMESSAGEENABLEAMDPROC) (GLenum category, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
+typedef void (APIENTRYP PFNGLDEBUGMESSAGEINSERTAMDPROC) (GLenum category, GLenum severity, GLuint id, GLsizei length, const GLchar *buf);
+typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKAMDPROC) (GLDEBUGPROCAMD callback, void *userParam);
+typedef GLuint (APIENTRYP PFNGLGETDEBUGMESSAGELOGAMDPROC) (GLuint count, GLsizei bufsize, GLenum *categories, GLuint *severities, GLuint *ids, GLsizei *lengths, GLchar *message);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDebugMessageEnableAMD (GLenum category, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
+GLAPI void APIENTRY glDebugMessageInsertAMD (GLenum category, GLenum severity, GLuint id, GLsizei length, const GLchar *buf);
+GLAPI void APIENTRY glDebugMessageCallbackAMD (GLDEBUGPROCAMD callback, void *userParam);
+GLAPI GLuint APIENTRY glGetDebugMessageLogAMD (GLuint count, GLsizei bufsize, GLenum *categories, GLuint *severities, GLuint *ids, GLsizei *lengths, GLchar *message);
+#endif
+#endif /* GL_AMD_debug_output */
+
+#ifndef GL_AMD_depth_clamp_separate
+#define GL_AMD_depth_clamp_separate 1
+#define GL_DEPTH_CLAMP_NEAR_AMD 0x901E
+#define GL_DEPTH_CLAMP_FAR_AMD 0x901F
+#endif /* GL_AMD_depth_clamp_separate */
+
+#ifndef GL_AMD_draw_buffers_blend
+#define GL_AMD_draw_buffers_blend 1
+typedef void (APIENTRYP PFNGLBLENDFUNCINDEXEDAMDPROC) (GLuint buf, GLenum src, GLenum dst);
+typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINDEXEDAMDPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+typedef void (APIENTRYP PFNGLBLENDEQUATIONINDEXEDAMDPROC) (GLuint buf, GLenum mode);
+typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEINDEXEDAMDPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendFuncIndexedAMD (GLuint buf, GLenum src, GLenum dst);
+GLAPI void APIENTRY glBlendFuncSeparateIndexedAMD (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+GLAPI void APIENTRY glBlendEquationIndexedAMD (GLuint buf, GLenum mode);
+GLAPI void APIENTRY glBlendEquationSeparateIndexedAMD (GLuint buf, GLenum modeRGB, GLenum modeAlpha);
+#endif
+#endif /* GL_AMD_draw_buffers_blend */
+
+#ifndef GL_AMD_gcn_shader
+#define GL_AMD_gcn_shader 1
+#endif /* GL_AMD_gcn_shader */
+
+#ifndef GL_AMD_gpu_shader_int64
+#define GL_AMD_gpu_shader_int64 1
+typedef int64_t GLint64EXT;
+#define GL_INT64_NV 0x140E
+#define GL_UNSIGNED_INT64_NV 0x140F
+#define GL_INT8_NV 0x8FE0
+#define GL_INT8_VEC2_NV 0x8FE1
+#define GL_INT8_VEC3_NV 0x8FE2
+#define GL_INT8_VEC4_NV 0x8FE3
+#define GL_INT16_NV 0x8FE4
+#define GL_INT16_VEC2_NV 0x8FE5
+#define GL_INT16_VEC3_NV 0x8FE6
+#define GL_INT16_VEC4_NV 0x8FE7
+#define GL_INT64_VEC2_NV 0x8FE9
+#define GL_INT64_VEC3_NV 0x8FEA
+#define GL_INT64_VEC4_NV 0x8FEB
+#define GL_UNSIGNED_INT8_NV 0x8FEC
+#define GL_UNSIGNED_INT8_VEC2_NV 0x8FED
+#define GL_UNSIGNED_INT8_VEC3_NV 0x8FEE
+#define GL_UNSIGNED_INT8_VEC4_NV 0x8FEF
+#define GL_UNSIGNED_INT16_NV 0x8FF0
+#define GL_UNSIGNED_INT16_VEC2_NV 0x8FF1
+#define GL_UNSIGNED_INT16_VEC3_NV 0x8FF2
+#define GL_UNSIGNED_INT16_VEC4_NV 0x8FF3
+#define GL_UNSIGNED_INT64_VEC2_NV 0x8FF5
+#define GL_UNSIGNED_INT64_VEC3_NV 0x8FF6
+#define GL_UNSIGNED_INT64_VEC4_NV 0x8FF7
+#define GL_FLOAT16_NV 0x8FF8
+#define GL_FLOAT16_VEC2_NV 0x8FF9
+#define GL_FLOAT16_VEC3_NV 0x8FFA
+#define GL_FLOAT16_VEC4_NV 0x8FFB
+typedef void (APIENTRYP PFNGLUNIFORM1I64NVPROC) (GLint location, GLint64EXT x);
+typedef void (APIENTRYP PFNGLUNIFORM2I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y);
+typedef void (APIENTRYP PFNGLUNIFORM3I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z);
+typedef void (APIENTRYP PFNGLUNIFORM4I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
+typedef void (APIENTRYP PFNGLUNIFORM1I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (APIENTRYP PFNGLUNIFORM2I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (APIENTRYP PFNGLUNIFORM3I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (APIENTRYP PFNGLUNIFORM4I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (APIENTRYP PFNGLUNIFORM1UI64NVPROC) (GLint location, GLuint64EXT x);
+typedef void (APIENTRYP PFNGLUNIFORM2UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y);
+typedef void (APIENTRYP PFNGLUNIFORM3UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
+typedef void (APIENTRYP PFNGLUNIFORM4UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
+typedef void (APIENTRYP PFNGLUNIFORM1UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (APIENTRYP PFNGLUNIFORM2UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (APIENTRYP PFNGLUNIFORM3UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (APIENTRYP PFNGLUNIFORM4UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (APIENTRYP PFNGLGETUNIFORMI64VNVPROC) (GLuint program, GLint location, GLint64EXT *params);
+typedef void (APIENTRYP PFNGLGETUNIFORMUI64VNVPROC) (GLuint program, GLint location, GLuint64EXT *params);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1I64NVPROC) (GLuint program, GLint location, GLint64EXT x);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glUniform1i64NV (GLint location, GLint64EXT x);
+GLAPI void APIENTRY glUniform2i64NV (GLint location, GLint64EXT x, GLint64EXT y);
+GLAPI void APIENTRY glUniform3i64NV (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z);
+GLAPI void APIENTRY glUniform4i64NV (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
+GLAPI void APIENTRY glUniform1i64vNV (GLint location, GLsizei count, const GLint64EXT *value);
+GLAPI void APIENTRY glUniform2i64vNV (GLint location, GLsizei count, const GLint64EXT *value);
+GLAPI void APIENTRY glUniform3i64vNV (GLint location, GLsizei count, const GLint64EXT *value);
+GLAPI void APIENTRY glUniform4i64vNV (GLint location, GLsizei count, const GLint64EXT *value);
+GLAPI void APIENTRY glUniform1ui64NV (GLint location, GLuint64EXT x);
+GLAPI void APIENTRY glUniform2ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y);
+GLAPI void APIENTRY glUniform3ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
+GLAPI void APIENTRY glUniform4ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
+GLAPI void APIENTRY glUniform1ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value);
+GLAPI void APIENTRY glUniform2ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value);
+GLAPI void APIENTRY glUniform3ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value);
+GLAPI void APIENTRY glUniform4ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value);
+GLAPI void APIENTRY glGetUniformi64vNV (GLuint program, GLint location, GLint64EXT *params);
+GLAPI void APIENTRY glGetUniformui64vNV (GLuint program, GLint location, GLuint64EXT *params);
+GLAPI void APIENTRY glProgramUniform1i64NV (GLuint program, GLint location, GLint64EXT x);
+GLAPI void APIENTRY glProgramUniform2i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y);
+GLAPI void APIENTRY glProgramUniform3i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z);
+GLAPI void APIENTRY glProgramUniform4i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
+GLAPI void APIENTRY glProgramUniform1i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+GLAPI void APIENTRY glProgramUniform2i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+GLAPI void APIENTRY glProgramUniform3i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+GLAPI void APIENTRY glProgramUniform4i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+GLAPI void APIENTRY glProgramUniform1ui64NV (GLuint program, GLint location, GLuint64EXT x);
+GLAPI void APIENTRY glProgramUniform2ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y);
+GLAPI void APIENTRY glProgramUniform3ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
+GLAPI void APIENTRY glProgramUniform4ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
+GLAPI void APIENTRY glProgramUniform1ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+GLAPI void APIENTRY glProgramUniform2ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+GLAPI void APIENTRY glProgramUniform3ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+GLAPI void APIENTRY glProgramUniform4ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+#endif
+#endif /* GL_AMD_gpu_shader_int64 */
+
+#ifndef GL_AMD_interleaved_elements
+#define GL_AMD_interleaved_elements 1
+#define GL_VERTEX_ELEMENT_SWIZZLE_AMD 0x91A4
+#define GL_VERTEX_ID_SWIZZLE_AMD 0x91A5
+typedef void (APIENTRYP PFNGLVERTEXATTRIBPARAMETERIAMDPROC) (GLuint index, GLenum pname, GLint param);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexAttribParameteriAMD (GLuint index, GLenum pname, GLint param);
+#endif
+#endif /* GL_AMD_interleaved_elements */
+
+#ifndef GL_AMD_multi_draw_indirect
+#define GL_AMD_multi_draw_indirect 1
+typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTAMDPROC) (GLenum mode, const void *indirect, GLsizei primcount, GLsizei stride);
+typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTAMDPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei primcount, GLsizei stride);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMultiDrawArraysIndirectAMD (GLenum mode, const void *indirect, GLsizei primcount, GLsizei stride);
+GLAPI void APIENTRY glMultiDrawElementsIndirectAMD (GLenum mode, GLenum type, const void *indirect, GLsizei primcount, GLsizei stride);
+#endif
+#endif /* GL_AMD_multi_draw_indirect */
+
+#ifndef GL_AMD_name_gen_delete
+#define GL_AMD_name_gen_delete 1
+#define GL_DATA_BUFFER_AMD 0x9151
+#define GL_PERFORMANCE_MONITOR_AMD 0x9152
+#define GL_QUERY_OBJECT_AMD 0x9153
+#define GL_VERTEX_ARRAY_OBJECT_AMD 0x9154
+#define GL_SAMPLER_OBJECT_AMD 0x9155
+typedef void (APIENTRYP PFNGLGENNAMESAMDPROC) (GLenum identifier, GLuint num, GLuint *names);
+typedef void (APIENTRYP PFNGLDELETENAMESAMDPROC) (GLenum identifier, GLuint num, const GLuint *names);
+typedef GLboolean (APIENTRYP PFNGLISNAMEAMDPROC) (GLenum identifier, GLuint name);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGenNamesAMD (GLenum identifier, GLuint num, GLuint *names);
+GLAPI void APIENTRY glDeleteNamesAMD (GLenum identifier, GLuint num, const GLuint *names);
+GLAPI GLboolean APIENTRY glIsNameAMD (GLenum identifier, GLuint name);
+#endif
+#endif /* GL_AMD_name_gen_delete */
+
+#ifndef GL_AMD_occlusion_query_event
+#define GL_AMD_occlusion_query_event 1
+#define GL_OCCLUSION_QUERY_EVENT_MASK_AMD 0x874F
+#define GL_QUERY_DEPTH_PASS_EVENT_BIT_AMD 0x00000001
+#define GL_QUERY_DEPTH_FAIL_EVENT_BIT_AMD 0x00000002
+#define GL_QUERY_STENCIL_FAIL_EVENT_BIT_AMD 0x00000004
+#define GL_QUERY_DEPTH_BOUNDS_FAIL_EVENT_BIT_AMD 0x00000008
+#define GL_QUERY_ALL_EVENT_BITS_AMD 0xFFFFFFFF
+typedef void (APIENTRYP PFNGLQUERYOBJECTPARAMETERUIAMDPROC) (GLenum target, GLuint id, GLenum pname, GLuint param);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glQueryObjectParameteruiAMD (GLenum target, GLuint id, GLenum pname, GLuint param);
+#endif
+#endif /* GL_AMD_occlusion_query_event */
+
+#ifndef GL_AMD_performance_monitor
+#define GL_AMD_performance_monitor 1
+#define GL_COUNTER_TYPE_AMD 0x8BC0
+#define GL_COUNTER_RANGE_AMD 0x8BC1
+#define GL_UNSIGNED_INT64_AMD 0x8BC2
+#define GL_PERCENTAGE_AMD 0x8BC3
+#define GL_PERFMON_RESULT_AVAILABLE_AMD 0x8BC4
+#define GL_PERFMON_RESULT_SIZE_AMD 0x8BC5
+#define GL_PERFMON_RESULT_AMD 0x8BC6
+typedef void (APIENTRYP PFNGLGETPERFMONITORGROUPSAMDPROC) (GLint *numGroups, GLsizei groupsSize, GLuint *groups);
+typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERSAMDPROC) (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters);
+typedef void (APIENTRYP PFNGLGETPERFMONITORGROUPSTRINGAMDPROC) (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString);
+typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERSTRINGAMDPROC) (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString);
+typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERINFOAMDPROC) (GLuint group, GLuint counter, GLenum pname, void *data);
+typedef void (APIENTRYP PFNGLGENPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors);
+typedef void (APIENTRYP PFNGLDELETEPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors);
+typedef void (APIENTRYP PFNGLSELECTPERFMONITORCOUNTERSAMDPROC) (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *counterList);
+typedef void (APIENTRYP PFNGLBEGINPERFMONITORAMDPROC) (GLuint monitor);
+typedef void (APIENTRYP PFNGLENDPERFMONITORAMDPROC) (GLuint monitor);
+typedef void (APIENTRYP PFNGLGETPERFMONITORCOUNTERDATAAMDPROC) (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGetPerfMonitorGroupsAMD (GLint *numGroups, GLsizei groupsSize, GLuint *groups);
+GLAPI void APIENTRY glGetPerfMonitorCountersAMD (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters);
+GLAPI void APIENTRY glGetPerfMonitorGroupStringAMD (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString);
+GLAPI void APIENTRY glGetPerfMonitorCounterStringAMD (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString);
+GLAPI void APIENTRY glGetPerfMonitorCounterInfoAMD (GLuint group, GLuint counter, GLenum pname, void *data);
+GLAPI void APIENTRY glGenPerfMonitorsAMD (GLsizei n, GLuint *monitors);
+GLAPI void APIENTRY glDeletePerfMonitorsAMD (GLsizei n, GLuint *monitors);
+GLAPI void APIENTRY glSelectPerfMonitorCountersAMD (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *counterList);
+GLAPI void APIENTRY glBeginPerfMonitorAMD (GLuint monitor);
+GLAPI void APIENTRY glEndPerfMonitorAMD (GLuint monitor);
+GLAPI void APIENTRY glGetPerfMonitorCounterDataAMD (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten);
+#endif
+#endif /* GL_AMD_performance_monitor */
+
+#ifndef GL_AMD_pinned_memory
+#define GL_AMD_pinned_memory 1
+#define GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD 0x9160
+#endif /* GL_AMD_pinned_memory */
+
+#ifndef GL_AMD_query_buffer_object
+#define GL_AMD_query_buffer_object 1
+#define GL_QUERY_BUFFER_AMD 0x9192
+#define GL_QUERY_BUFFER_BINDING_AMD 0x9193
+#define GL_QUERY_RESULT_NO_WAIT_AMD 0x9194
+#endif /* GL_AMD_query_buffer_object */
+
+#ifndef GL_AMD_sample_positions
+#define GL_AMD_sample_positions 1
+#define GL_SUBSAMPLE_DISTANCE_AMD 0x883F
+typedef void (APIENTRYP PFNGLSETMULTISAMPLEFVAMDPROC) (GLenum pname, GLuint index, const GLfloat *val);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glSetMultisamplefvAMD (GLenum pname, GLuint index, const GLfloat *val);
+#endif
+#endif /* GL_AMD_sample_positions */
+
+#ifndef GL_AMD_seamless_cubemap_per_texture
+#define GL_AMD_seamless_cubemap_per_texture 1
+#endif /* GL_AMD_seamless_cubemap_per_texture */
+
+#ifndef GL_AMD_shader_atomic_counter_ops
+#define GL_AMD_shader_atomic_counter_ops 1
+#endif /* GL_AMD_shader_atomic_counter_ops */
+
+#ifndef GL_AMD_shader_stencil_export
+#define GL_AMD_shader_stencil_export 1
+#endif /* GL_AMD_shader_stencil_export */
+
+#ifndef GL_AMD_shader_trinary_minmax
+#define GL_AMD_shader_trinary_minmax 1
+#endif /* GL_AMD_shader_trinary_minmax */
+
+#ifndef GL_AMD_sparse_texture
+#define GL_AMD_sparse_texture 1
+#define GL_VIRTUAL_PAGE_SIZE_X_AMD 0x9195
+#define GL_VIRTUAL_PAGE_SIZE_Y_AMD 0x9196
+#define GL_VIRTUAL_PAGE_SIZE_Z_AMD 0x9197
+#define GL_MAX_SPARSE_TEXTURE_SIZE_AMD 0x9198
+#define GL_MAX_SPARSE_3D_TEXTURE_SIZE_AMD 0x9199
+#define GL_MAX_SPARSE_ARRAY_TEXTURE_LAYERS 0x919A
+#define GL_MIN_SPARSE_LEVEL_AMD 0x919B
+#define GL_MIN_LOD_WARNING_AMD 0x919C
+#define GL_TEXTURE_STORAGE_SPARSE_BIT_AMD 0x00000001
+typedef void (APIENTRYP PFNGLTEXSTORAGESPARSEAMDPROC) (GLenum target, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei layers, GLbitfield flags);
+typedef void (APIENTRYP PFNGLTEXTURESTORAGESPARSEAMDPROC) (GLuint texture, GLenum target, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei layers, GLbitfield flags);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexStorageSparseAMD (GLenum target, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei layers, GLbitfield flags);
+GLAPI void APIENTRY glTextureStorageSparseAMD (GLuint texture, GLenum target, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLsizei layers, GLbitfield flags);
+#endif
+#endif /* GL_AMD_sparse_texture */
+
+#ifndef GL_AMD_stencil_operation_extended
+#define GL_AMD_stencil_operation_extended 1
+#define GL_SET_AMD 0x874A
+#define GL_REPLACE_VALUE_AMD 0x874B
+#define GL_STENCIL_OP_VALUE_AMD 0x874C
+#define GL_STENCIL_BACK_OP_VALUE_AMD 0x874D
+typedef void (APIENTRYP PFNGLSTENCILOPVALUEAMDPROC) (GLenum face, GLuint value);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glStencilOpValueAMD (GLenum face, GLuint value);
+#endif
+#endif /* GL_AMD_stencil_operation_extended */
+
+#ifndef GL_AMD_texture_texture4
+#define GL_AMD_texture_texture4 1
+#endif /* GL_AMD_texture_texture4 */
+
+#ifndef GL_AMD_transform_feedback3_lines_triangles
+#define GL_AMD_transform_feedback3_lines_triangles 1
+#endif /* GL_AMD_transform_feedback3_lines_triangles */
+
+#ifndef GL_AMD_transform_feedback4
+#define GL_AMD_transform_feedback4 1
+#define GL_STREAM_RASTERIZATION_AMD 0x91A0
+#endif /* GL_AMD_transform_feedback4 */
+
+#ifndef GL_AMD_vertex_shader_layer
+#define GL_AMD_vertex_shader_layer 1
+#endif /* GL_AMD_vertex_shader_layer */
+
+#ifndef GL_AMD_vertex_shader_tessellator
+#define GL_AMD_vertex_shader_tessellator 1
+#define GL_SAMPLER_BUFFER_AMD 0x9001
+#define GL_INT_SAMPLER_BUFFER_AMD 0x9002
+#define GL_UNSIGNED_INT_SAMPLER_BUFFER_AMD 0x9003
+#define GL_TESSELLATION_MODE_AMD 0x9004
+#define GL_TESSELLATION_FACTOR_AMD 0x9005
+#define GL_DISCRETE_AMD 0x9006
+#define GL_CONTINUOUS_AMD 0x9007
+typedef void (APIENTRYP PFNGLTESSELLATIONFACTORAMDPROC) (GLfloat factor);
+typedef void (APIENTRYP PFNGLTESSELLATIONMODEAMDPROC) (GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTessellationFactorAMD (GLfloat factor);
+GLAPI void APIENTRY glTessellationModeAMD (GLenum mode);
+#endif
+#endif /* GL_AMD_vertex_shader_tessellator */
+
+#ifndef GL_AMD_vertex_shader_viewport_index
+#define GL_AMD_vertex_shader_viewport_index 1
+#endif /* GL_AMD_vertex_shader_viewport_index */
+
+#ifndef GL_APPLE_aux_depth_stencil
+#define GL_APPLE_aux_depth_stencil 1
+#define GL_AUX_DEPTH_STENCIL_APPLE 0x8A14
+#endif /* GL_APPLE_aux_depth_stencil */
+
+#ifndef GL_APPLE_client_storage
+#define GL_APPLE_client_storage 1
+#define GL_UNPACK_CLIENT_STORAGE_APPLE 0x85B2
+#endif /* GL_APPLE_client_storage */
+
+#ifndef GL_APPLE_element_array
+#define GL_APPLE_element_array 1
+#define GL_ELEMENT_ARRAY_APPLE 0x8A0C
+#define GL_ELEMENT_ARRAY_TYPE_APPLE 0x8A0D
+#define GL_ELEMENT_ARRAY_POINTER_APPLE 0x8A0E
+typedef void (APIENTRYP PFNGLELEMENTPOINTERAPPLEPROC) (GLenum type, const void *pointer);
+typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, GLint first, GLsizei count);
+typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, GLint first, GLsizei count);
+typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTARRAYAPPLEPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount);
+typedef void (APIENTRYP PFNGLMULTIDRAWRANGEELEMENTARRAYAPPLEPROC) (GLenum mode, GLuint start, GLuint end, const GLint *first, const GLsizei *count, GLsizei primcount);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glElementPointerAPPLE (GLenum type, const void *pointer);
+GLAPI void APIENTRY glDrawElementArrayAPPLE (GLenum mode, GLint first, GLsizei count);
+GLAPI void APIENTRY glDrawRangeElementArrayAPPLE (GLenum mode, GLuint start, GLuint end, GLint first, GLsizei count);
+GLAPI void APIENTRY glMultiDrawElementArrayAPPLE (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount);
+GLAPI void APIENTRY glMultiDrawRangeElementArrayAPPLE (GLenum mode, GLuint start, GLuint end, const GLint *first, const GLsizei *count, GLsizei primcount);
+#endif
+#endif /* GL_APPLE_element_array */
+
+#ifndef GL_APPLE_fence
+#define GL_APPLE_fence 1
+#define GL_DRAW_PIXELS_APPLE 0x8A0A
+#define GL_FENCE_APPLE 0x8A0B
+typedef void (APIENTRYP PFNGLGENFENCESAPPLEPROC) (GLsizei n, GLuint *fences);
+typedef void (APIENTRYP PFNGLDELETEFENCESAPPLEPROC) (GLsizei n, const GLuint *fences);
+typedef void (APIENTRYP PFNGLSETFENCEAPPLEPROC) (GLuint fence);
+typedef GLboolean (APIENTRYP PFNGLISFENCEAPPLEPROC) (GLuint fence);
+typedef GLboolean (APIENTRYP PFNGLTESTFENCEAPPLEPROC) (GLuint fence);
+typedef void (APIENTRYP PFNGLFINISHFENCEAPPLEPROC) (GLuint fence);
+typedef GLboolean (APIENTRYP PFNGLTESTOBJECTAPPLEPROC) (GLenum object, GLuint name);
+typedef void (APIENTRYP PFNGLFINISHOBJECTAPPLEPROC) (GLenum object, GLint name);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGenFencesAPPLE (GLsizei n, GLuint *fences);
+GLAPI void APIENTRY glDeleteFencesAPPLE (GLsizei n, const GLuint *fences);
+GLAPI void APIENTRY glSetFenceAPPLE (GLuint fence);
+GLAPI GLboolean APIENTRY glIsFenceAPPLE (GLuint fence);
+GLAPI GLboolean APIENTRY glTestFenceAPPLE (GLuint fence);
+GLAPI void APIENTRY glFinishFenceAPPLE (GLuint fence);
+GLAPI GLboolean APIENTRY glTestObjectAPPLE (GLenum object, GLuint name);
+GLAPI void APIENTRY glFinishObjectAPPLE (GLenum object, GLint name);
+#endif
+#endif /* GL_APPLE_fence */
+
+#ifndef GL_APPLE_float_pixels
+#define GL_APPLE_float_pixels 1
+#define GL_HALF_APPLE 0x140B
+#define GL_RGBA_FLOAT32_APPLE 0x8814
+#define GL_RGB_FLOAT32_APPLE 0x8815
+#define GL_ALPHA_FLOAT32_APPLE 0x8816
+#define GL_INTENSITY_FLOAT32_APPLE 0x8817
+#define GL_LUMINANCE_FLOAT32_APPLE 0x8818
+#define GL_LUMINANCE_ALPHA_FLOAT32_APPLE 0x8819
+#define GL_RGBA_FLOAT16_APPLE 0x881A
+#define GL_RGB_FLOAT16_APPLE 0x881B
+#define GL_ALPHA_FLOAT16_APPLE 0x881C
+#define GL_INTENSITY_FLOAT16_APPLE 0x881D
+#define GL_LUMINANCE_FLOAT16_APPLE 0x881E
+#define GL_LUMINANCE_ALPHA_FLOAT16_APPLE 0x881F
+#define GL_COLOR_FLOAT_APPLE 0x8A0F
+#endif /* GL_APPLE_float_pixels */
+
+#ifndef GL_APPLE_flush_buffer_range
+#define GL_APPLE_flush_buffer_range 1
+#define GL_BUFFER_SERIALIZED_MODIFY_APPLE 0x8A12
+#define GL_BUFFER_FLUSHING_UNMAP_APPLE 0x8A13
+typedef void (APIENTRYP PFNGLBUFFERPARAMETERIAPPLEPROC) (GLenum target, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEAPPLEPROC) (GLenum target, GLintptr offset, GLsizeiptr size);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBufferParameteriAPPLE (GLenum target, GLenum pname, GLint param);
+GLAPI void APIENTRY glFlushMappedBufferRangeAPPLE (GLenum target, GLintptr offset, GLsizeiptr size);
+#endif
+#endif /* GL_APPLE_flush_buffer_range */
+
+#ifndef GL_APPLE_object_purgeable
+#define GL_APPLE_object_purgeable 1
+#define GL_BUFFER_OBJECT_APPLE 0x85B3
+#define GL_RELEASED_APPLE 0x8A19
+#define GL_VOLATILE_APPLE 0x8A1A
+#define GL_RETAINED_APPLE 0x8A1B
+#define GL_UNDEFINED_APPLE 0x8A1C
+#define GL_PURGEABLE_APPLE 0x8A1D
+typedef GLenum (APIENTRYP PFNGLOBJECTPURGEABLEAPPLEPROC) (GLenum objectType, GLuint name, GLenum option);
+typedef GLenum (APIENTRYP PFNGLOBJECTUNPURGEABLEAPPLEPROC) (GLenum objectType, GLuint name, GLenum option);
+typedef void (APIENTRYP PFNGLGETOBJECTPARAMETERIVAPPLEPROC) (GLenum objectType, GLuint name, GLenum pname, GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLenum APIENTRY glObjectPurgeableAPPLE (GLenum objectType, GLuint name, GLenum option);
+GLAPI GLenum APIENTRY glObjectUnpurgeableAPPLE (GLenum objectType, GLuint name, GLenum option);
+GLAPI void APIENTRY glGetObjectParameterivAPPLE (GLenum objectType, GLuint name, GLenum pname, GLint *params);
+#endif
+#endif /* GL_APPLE_object_purgeable */
+
+#ifndef GL_APPLE_rgb_422
+#define GL_APPLE_rgb_422 1
+#define GL_RGB_422_APPLE 0x8A1F
+#define GL_UNSIGNED_SHORT_8_8_APPLE 0x85BA
+#define GL_UNSIGNED_SHORT_8_8_REV_APPLE 0x85BB
+#define GL_RGB_RAW_422_APPLE 0x8A51
+#endif /* GL_APPLE_rgb_422 */
+
+#ifndef GL_APPLE_row_bytes
+#define GL_APPLE_row_bytes 1
+#define GL_PACK_ROW_BYTES_APPLE 0x8A15
+#define GL_UNPACK_ROW_BYTES_APPLE 0x8A16
+#endif /* GL_APPLE_row_bytes */
+
+#ifndef GL_APPLE_specular_vector
+#define GL_APPLE_specular_vector 1
+#define GL_LIGHT_MODEL_SPECULAR_VECTOR_APPLE 0x85B0
+#endif /* GL_APPLE_specular_vector */
+
+#ifndef GL_APPLE_texture_range
+#define GL_APPLE_texture_range 1
+#define GL_TEXTURE_RANGE_LENGTH_APPLE 0x85B7
+#define GL_TEXTURE_RANGE_POINTER_APPLE 0x85B8
+#define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC
+#define GL_STORAGE_PRIVATE_APPLE 0x85BD
+#define GL_STORAGE_CACHED_APPLE 0x85BE
+#define GL_STORAGE_SHARED_APPLE 0x85BF
+typedef void (APIENTRYP PFNGLTEXTURERANGEAPPLEPROC) (GLenum target, GLsizei length, const void *pointer);
+typedef void (APIENTRYP PFNGLGETTEXPARAMETERPOINTERVAPPLEPROC) (GLenum target, GLenum pname, void **params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTextureRangeAPPLE (GLenum target, GLsizei length, const void *pointer);
+GLAPI void APIENTRY glGetTexParameterPointervAPPLE (GLenum target, GLenum pname, void **params);
+#endif
+#endif /* GL_APPLE_texture_range */
+
+#ifndef GL_APPLE_transform_hint
+#define GL_APPLE_transform_hint 1
+#define GL_TRANSFORM_HINT_APPLE 0x85B1
+#endif /* GL_APPLE_transform_hint */
+
+#ifndef GL_APPLE_vertex_array_object
+#define GL_APPLE_vertex_array_object 1
+#define GL_VERTEX_ARRAY_BINDING_APPLE 0x85B5
+typedef void (APIENTRYP PFNGLBINDVERTEXARRAYAPPLEPROC) (GLuint array);
+typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSAPPLEPROC) (GLsizei n, const GLuint *arrays);
+typedef void (APIENTRYP PFNGLGENVERTEXARRAYSAPPLEPROC) (GLsizei n, GLuint *arrays);
+typedef GLboolean (APIENTRYP PFNGLISVERTEXARRAYAPPLEPROC) (GLuint array);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBindVertexArrayAPPLE (GLuint array);
+GLAPI void APIENTRY glDeleteVertexArraysAPPLE (GLsizei n, const GLuint *arrays);
+GLAPI void APIENTRY glGenVertexArraysAPPLE (GLsizei n, GLuint *arrays);
+GLAPI GLboolean APIENTRY glIsVertexArrayAPPLE (GLuint array);
+#endif
+#endif /* GL_APPLE_vertex_array_object */
+
+#ifndef GL_APPLE_vertex_array_range
+#define GL_APPLE_vertex_array_range 1
+#define GL_VERTEX_ARRAY_RANGE_APPLE 0x851D
+#define GL_VERTEX_ARRAY_RANGE_LENGTH_APPLE 0x851E
+#define GL_VERTEX_ARRAY_STORAGE_HINT_APPLE 0x851F
+#define GL_VERTEX_ARRAY_RANGE_POINTER_APPLE 0x8521
+#define GL_STORAGE_CLIENT_APPLE 0x85B4
+typedef void (APIENTRYP PFNGLVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, void *pointer);
+typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGEAPPLEPROC) (GLsizei length, void *pointer);
+typedef void (APIENTRYP PFNGLVERTEXARRAYPARAMETERIAPPLEPROC) (GLenum pname, GLint param);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexArrayRangeAPPLE (GLsizei length, void *pointer);
+GLAPI void APIENTRY glFlushVertexArrayRangeAPPLE (GLsizei length, void *pointer);
+GLAPI void APIENTRY glVertexArrayParameteriAPPLE (GLenum pname, GLint param);
+#endif
+#endif /* GL_APPLE_vertex_array_range */
+
+#ifndef GL_APPLE_vertex_program_evaluators
+#define GL_APPLE_vertex_program_evaluators 1
+#define GL_VERTEX_ATTRIB_MAP1_APPLE 0x8A00
+#define GL_VERTEX_ATTRIB_MAP2_APPLE 0x8A01
+#define GL_VERTEX_ATTRIB_MAP1_SIZE_APPLE 0x8A02
+#define GL_VERTEX_ATTRIB_MAP1_COEFF_APPLE 0x8A03
+#define GL_VERTEX_ATTRIB_MAP1_ORDER_APPLE 0x8A04
+#define GL_VERTEX_ATTRIB_MAP1_DOMAIN_APPLE 0x8A05
+#define GL_VERTEX_ATTRIB_MAP2_SIZE_APPLE 0x8A06
+#define GL_VERTEX_ATTRIB_MAP2_COEFF_APPLE 0x8A07
+#define GL_VERTEX_ATTRIB_MAP2_ORDER_APPLE 0x8A08
+#define GL_VERTEX_ATTRIB_MAP2_DOMAIN_APPLE 0x8A09
+typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBAPPLEPROC) (GLuint index, GLenum pname);
+typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBAPPLEPROC) (GLuint index, GLenum pname);
+typedef GLboolean (APIENTRYP PFNGLISVERTEXATTRIBENABLEDAPPLEPROC) (GLuint index, GLenum pname);
+typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB1DAPPLEPROC) (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points);
+typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB1FAPPLEPROC) (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points);
+typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB2DAPPLEPROC) (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points);
+typedef void (APIENTRYP PFNGLMAPVERTEXATTRIB2FAPPLEPROC) (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glEnableVertexAttribAPPLE (GLuint index, GLenum pname);
+GLAPI void APIENTRY glDisableVertexAttribAPPLE (GLuint index, GLenum pname);
+GLAPI GLboolean APIENTRY glIsVertexAttribEnabledAPPLE (GLuint index, GLenum pname);
+GLAPI void APIENTRY glMapVertexAttrib1dAPPLE (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points);
+GLAPI void APIENTRY glMapVertexAttrib1fAPPLE (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points);
+GLAPI void APIENTRY glMapVertexAttrib2dAPPLE (GLuint index, GLuint size, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points);
+GLAPI void APIENTRY glMapVertexAttrib2fAPPLE (GLuint index, GLuint size, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points);
+#endif
+#endif /* GL_APPLE_vertex_program_evaluators */
+
+#ifndef GL_APPLE_ycbcr_422
+#define GL_APPLE_ycbcr_422 1
+#define GL_YCBCR_422_APPLE 0x85B9
+#endif /* GL_APPLE_ycbcr_422 */
+
+#ifndef GL_ATI_draw_buffers
+#define GL_ATI_draw_buffers 1
+#define GL_MAX_DRAW_BUFFERS_ATI 0x8824
+#define GL_DRAW_BUFFER0_ATI 0x8825
+#define GL_DRAW_BUFFER1_ATI 0x8826
+#define GL_DRAW_BUFFER2_ATI 0x8827
+#define GL_DRAW_BUFFER3_ATI 0x8828
+#define GL_DRAW_BUFFER4_ATI 0x8829
+#define GL_DRAW_BUFFER5_ATI 0x882A
+#define GL_DRAW_BUFFER6_ATI 0x882B
+#define GL_DRAW_BUFFER7_ATI 0x882C
+#define GL_DRAW_BUFFER8_ATI 0x882D
+#define GL_DRAW_BUFFER9_ATI 0x882E
+#define GL_DRAW_BUFFER10_ATI 0x882F
+#define GL_DRAW_BUFFER11_ATI 0x8830
+#define GL_DRAW_BUFFER12_ATI 0x8831
+#define GL_DRAW_BUFFER13_ATI 0x8832
+#define GL_DRAW_BUFFER14_ATI 0x8833
+#define GL_DRAW_BUFFER15_ATI 0x8834
+typedef void (APIENTRYP PFNGLDRAWBUFFERSATIPROC) (GLsizei n, const GLenum *bufs);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawBuffersATI (GLsizei n, const GLenum *bufs);
+#endif
+#endif /* GL_ATI_draw_buffers */
+
+#ifndef GL_ATI_element_array
+#define GL_ATI_element_array 1
+#define GL_ELEMENT_ARRAY_ATI 0x8768
+#define GL_ELEMENT_ARRAY_TYPE_ATI 0x8769
+#define GL_ELEMENT_ARRAY_POINTER_ATI 0x876A
+typedef void (APIENTRYP PFNGLELEMENTPOINTERATIPROC) (GLenum type, const void *pointer);
+typedef void (APIENTRYP PFNGLDRAWELEMENTARRAYATIPROC) (GLenum mode, GLsizei count);
+typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTARRAYATIPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glElementPointerATI (GLenum type, const void *pointer);
+GLAPI void APIENTRY glDrawElementArrayATI (GLenum mode, GLsizei count);
+GLAPI void APIENTRY glDrawRangeElementArrayATI (GLenum mode, GLuint start, GLuint end, GLsizei count);
+#endif
+#endif /* GL_ATI_element_array */
+
+#ifndef GL_ATI_envmap_bumpmap
+#define GL_ATI_envmap_bumpmap 1
+#define GL_BUMP_ROT_MATRIX_ATI 0x8775
+#define GL_BUMP_ROT_MATRIX_SIZE_ATI 0x8776
+#define GL_BUMP_NUM_TEX_UNITS_ATI 0x8777
+#define GL_BUMP_TEX_UNITS_ATI 0x8778
+#define GL_DUDV_ATI 0x8779
+#define GL_DU8DV8_ATI 0x877A
+#define GL_BUMP_ENVMAP_ATI 0x877B
+#define GL_BUMP_TARGET_ATI 0x877C
+typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERIVATIPROC) (GLenum pname, const GLint *param);
+typedef void (APIENTRYP PFNGLTEXBUMPPARAMETERFVATIPROC) (GLenum pname, const GLfloat *param);
+typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERIVATIPROC) (GLenum pname, GLint *param);
+typedef void (APIENTRYP PFNGLGETTEXBUMPPARAMETERFVATIPROC) (GLenum pname, GLfloat *param);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexBumpParameterivATI (GLenum pname, const GLint *param);
+GLAPI void APIENTRY glTexBumpParameterfvATI (GLenum pname, const GLfloat *param);
+GLAPI void APIENTRY glGetTexBumpParameterivATI (GLenum pname, GLint *param);
+GLAPI void APIENTRY glGetTexBumpParameterfvATI (GLenum pname, GLfloat *param);
+#endif
+#endif /* GL_ATI_envmap_bumpmap */
+
+#ifndef GL_ATI_fragment_shader
+#define GL_ATI_fragment_shader 1
+#define GL_FRAGMENT_SHADER_ATI 0x8920
+#define GL_REG_0_ATI 0x8921
+#define GL_REG_1_ATI 0x8922
+#define GL_REG_2_ATI 0x8923
+#define GL_REG_3_ATI 0x8924
+#define GL_REG_4_ATI 0x8925
+#define GL_REG_5_ATI 0x8926
+#define GL_REG_6_ATI 0x8927
+#define GL_REG_7_ATI 0x8928
+#define GL_REG_8_ATI 0x8929
+#define GL_REG_9_ATI 0x892A
+#define GL_REG_10_ATI 0x892B
+#define GL_REG_11_ATI 0x892C
+#define GL_REG_12_ATI 0x892D
+#define GL_REG_13_ATI 0x892E
+#define GL_REG_14_ATI 0x892F
+#define GL_REG_15_ATI 0x8930
+#define GL_REG_16_ATI 0x8931
+#define GL_REG_17_ATI 0x8932
+#define GL_REG_18_ATI 0x8933
+#define GL_REG_19_ATI 0x8934
+#define GL_REG_20_ATI 0x8935
+#define GL_REG_21_ATI 0x8936
+#define GL_REG_22_ATI 0x8937
+#define GL_REG_23_ATI 0x8938
+#define GL_REG_24_ATI 0x8939
+#define GL_REG_25_ATI 0x893A
+#define GL_REG_26_ATI 0x893B
+#define GL_REG_27_ATI 0x893C
+#define GL_REG_28_ATI 0x893D
+#define GL_REG_29_ATI 0x893E
+#define GL_REG_30_ATI 0x893F
+#define GL_REG_31_ATI 0x8940
+#define GL_CON_0_ATI 0x8941
+#define GL_CON_1_ATI 0x8942
+#define GL_CON_2_ATI 0x8943
+#define GL_CON_3_ATI 0x8944
+#define GL_CON_4_ATI 0x8945
+#define GL_CON_5_ATI 0x8946
+#define GL_CON_6_ATI 0x8947
+#define GL_CON_7_ATI 0x8948
+#define GL_CON_8_ATI 0x8949
+#define GL_CON_9_ATI 0x894A
+#define GL_CON_10_ATI 0x894B
+#define GL_CON_11_ATI 0x894C
+#define GL_CON_12_ATI 0x894D
+#define GL_CON_13_ATI 0x894E
+#define GL_CON_14_ATI 0x894F
+#define GL_CON_15_ATI 0x8950
+#define GL_CON_16_ATI 0x8951
+#define GL_CON_17_ATI 0x8952
+#define GL_CON_18_ATI 0x8953
+#define GL_CON_19_ATI 0x8954
+#define GL_CON_20_ATI 0x8955
+#define GL_CON_21_ATI 0x8956
+#define GL_CON_22_ATI 0x8957
+#define GL_CON_23_ATI 0x8958
+#define GL_CON_24_ATI 0x8959
+#define GL_CON_25_ATI 0x895A
+#define GL_CON_26_ATI 0x895B
+#define GL_CON_27_ATI 0x895C
+#define GL_CON_28_ATI 0x895D
+#define GL_CON_29_ATI 0x895E
+#define GL_CON_30_ATI 0x895F
+#define GL_CON_31_ATI 0x8960
+#define GL_MOV_ATI 0x8961
+#define GL_ADD_ATI 0x8963
+#define GL_MUL_ATI 0x8964
+#define GL_SUB_ATI 0x8965
+#define GL_DOT3_ATI 0x8966
+#define GL_DOT4_ATI 0x8967
+#define GL_MAD_ATI 0x8968
+#define GL_LERP_ATI 0x8969
+#define GL_CND_ATI 0x896A
+#define GL_CND0_ATI 0x896B
+#define GL_DOT2_ADD_ATI 0x896C
+#define GL_SECONDARY_INTERPOLATOR_ATI 0x896D
+#define GL_NUM_FRAGMENT_REGISTERS_ATI 0x896E
+#define GL_NUM_FRAGMENT_CONSTANTS_ATI 0x896F
+#define GL_NUM_PASSES_ATI 0x8970
+#define GL_NUM_INSTRUCTIONS_PER_PASS_ATI 0x8971
+#define GL_NUM_INSTRUCTIONS_TOTAL_ATI 0x8972
+#define GL_NUM_INPUT_INTERPOLATOR_COMPONENTS_ATI 0x8973
+#define GL_NUM_LOOPBACK_COMPONENTS_ATI 0x8974
+#define GL_COLOR_ALPHA_PAIRING_ATI 0x8975
+#define GL_SWIZZLE_STR_ATI 0x8976
+#define GL_SWIZZLE_STQ_ATI 0x8977
+#define GL_SWIZZLE_STR_DR_ATI 0x8978
+#define GL_SWIZZLE_STQ_DQ_ATI 0x8979
+#define GL_SWIZZLE_STRQ_ATI 0x897A
+#define GL_SWIZZLE_STRQ_DQ_ATI 0x897B
+#define GL_RED_BIT_ATI 0x00000001
+#define GL_GREEN_BIT_ATI 0x00000002
+#define GL_BLUE_BIT_ATI 0x00000004
+#define GL_2X_BIT_ATI 0x00000001
+#define GL_4X_BIT_ATI 0x00000002
+#define GL_8X_BIT_ATI 0x00000004
+#define GL_HALF_BIT_ATI 0x00000008
+#define GL_QUARTER_BIT_ATI 0x00000010
+#define GL_EIGHTH_BIT_ATI 0x00000020
+#define GL_SATURATE_BIT_ATI 0x00000040
+#define GL_COMP_BIT_ATI 0x00000002
+#define GL_NEGATE_BIT_ATI 0x00000004
+#define GL_BIAS_BIT_ATI 0x00000008
+typedef GLuint (APIENTRYP PFNGLGENFRAGMENTSHADERSATIPROC) (GLuint range);
+typedef void (APIENTRYP PFNGLBINDFRAGMENTSHADERATIPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLDELETEFRAGMENTSHADERATIPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLBEGINFRAGMENTSHADERATIPROC) (void);
+typedef void (APIENTRYP PFNGLENDFRAGMENTSHADERATIPROC) (void);
+typedef void (APIENTRYP PFNGLPASSTEXCOORDATIPROC) (GLuint dst, GLuint coord, GLenum swizzle);
+typedef void (APIENTRYP PFNGLSAMPLEMAPATIPROC) (GLuint dst, GLuint interp, GLenum swizzle);
+typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod);
+typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod);
+typedef void (APIENTRYP PFNGLCOLORFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod);
+typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP1ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod);
+typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP2ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod);
+typedef void (APIENTRYP PFNGLALPHAFRAGMENTOP3ATIPROC) (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod);
+typedef void (APIENTRYP PFNGLSETFRAGMENTSHADERCONSTANTATIPROC) (GLuint dst, const GLfloat *value);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLuint APIENTRY glGenFragmentShadersATI (GLuint range);
+GLAPI void APIENTRY glBindFragmentShaderATI (GLuint id);
+GLAPI void APIENTRY glDeleteFragmentShaderATI (GLuint id);
+GLAPI void APIENTRY glBeginFragmentShaderATI (void);
+GLAPI void APIENTRY glEndFragmentShaderATI (void);
+GLAPI void APIENTRY glPassTexCoordATI (GLuint dst, GLuint coord, GLenum swizzle);
+GLAPI void APIENTRY glSampleMapATI (GLuint dst, GLuint interp, GLenum swizzle);
+GLAPI void APIENTRY glColorFragmentOp1ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod);
+GLAPI void APIENTRY glColorFragmentOp2ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod);
+GLAPI void APIENTRY glColorFragmentOp3ATI (GLenum op, GLuint dst, GLuint dstMask, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod);
+GLAPI void APIENTRY glAlphaFragmentOp1ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod);
+GLAPI void APIENTRY glAlphaFragmentOp2ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod);
+GLAPI void APIENTRY glAlphaFragmentOp3ATI (GLenum op, GLuint dst, GLuint dstMod, GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod, GLuint arg3, GLuint arg3Rep, GLuint arg3Mod);
+GLAPI void APIENTRY glSetFragmentShaderConstantATI (GLuint dst, const GLfloat *value);
+#endif
+#endif /* GL_ATI_fragment_shader */
+
+#ifndef GL_ATI_map_object_buffer
+#define GL_ATI_map_object_buffer 1
+typedef void *(APIENTRYP PFNGLMAPOBJECTBUFFERATIPROC) (GLuint buffer);
+typedef void (APIENTRYP PFNGLUNMAPOBJECTBUFFERATIPROC) (GLuint buffer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void *APIENTRY glMapObjectBufferATI (GLuint buffer);
+GLAPI void APIENTRY glUnmapObjectBufferATI (GLuint buffer);
+#endif
+#endif /* GL_ATI_map_object_buffer */
+
+#ifndef GL_ATI_meminfo
+#define GL_ATI_meminfo 1
+#define GL_VBO_FREE_MEMORY_ATI 0x87FB
+#define GL_TEXTURE_FREE_MEMORY_ATI 0x87FC
+#define GL_RENDERBUFFER_FREE_MEMORY_ATI 0x87FD
+#endif /* GL_ATI_meminfo */
+
+#ifndef GL_ATI_pixel_format_float
+#define GL_ATI_pixel_format_float 1
+#define GL_RGBA_FLOAT_MODE_ATI 0x8820
+#define GL_COLOR_CLEAR_UNCLAMPED_VALUE_ATI 0x8835
+#endif /* GL_ATI_pixel_format_float */
+
+#ifndef GL_ATI_pn_triangles
+#define GL_ATI_pn_triangles 1
+#define GL_PN_TRIANGLES_ATI 0x87F0
+#define GL_MAX_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F1
+#define GL_PN_TRIANGLES_POINT_MODE_ATI 0x87F2
+#define GL_PN_TRIANGLES_NORMAL_MODE_ATI 0x87F3
+#define GL_PN_TRIANGLES_TESSELATION_LEVEL_ATI 0x87F4
+#define GL_PN_TRIANGLES_POINT_MODE_LINEAR_ATI 0x87F5
+#define GL_PN_TRIANGLES_POINT_MODE_CUBIC_ATI 0x87F6
+#define GL_PN_TRIANGLES_NORMAL_MODE_LINEAR_ATI 0x87F7
+#define GL_PN_TRIANGLES_NORMAL_MODE_QUADRATIC_ATI 0x87F8
+typedef void (APIENTRYP PFNGLPNTRIANGLESIATIPROC) (GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLPNTRIANGLESFATIPROC) (GLenum pname, GLfloat param);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPNTrianglesiATI (GLenum pname, GLint param);
+GLAPI void APIENTRY glPNTrianglesfATI (GLenum pname, GLfloat param);
+#endif
+#endif /* GL_ATI_pn_triangles */
+
+#ifndef GL_ATI_separate_stencil
+#define GL_ATI_separate_stencil 1
+#define GL_STENCIL_BACK_FUNC_ATI 0x8800
+#define GL_STENCIL_BACK_FAIL_ATI 0x8801
+#define GL_STENCIL_BACK_PASS_DEPTH_FAIL_ATI 0x8802
+#define GL_STENCIL_BACK_PASS_DEPTH_PASS_ATI 0x8803
+typedef void (APIENTRYP PFNGLSTENCILOPSEPARATEATIPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
+typedef void (APIENTRYP PFNGLSTENCILFUNCSEPARATEATIPROC) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glStencilOpSeparateATI (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
+GLAPI void APIENTRY glStencilFuncSeparateATI (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask);
+#endif
+#endif /* GL_ATI_separate_stencil */
+
+#ifndef GL_ATI_text_fragment_shader
+#define GL_ATI_text_fragment_shader 1
+#define GL_TEXT_FRAGMENT_SHADER_ATI 0x8200
+#endif /* GL_ATI_text_fragment_shader */
+
+#ifndef GL_ATI_texture_env_combine3
+#define GL_ATI_texture_env_combine3 1
+#define GL_MODULATE_ADD_ATI 0x8744
+#define GL_MODULATE_SIGNED_ADD_ATI 0x8745
+#define GL_MODULATE_SUBTRACT_ATI 0x8746
+#endif /* GL_ATI_texture_env_combine3 */
+
+#ifndef GL_ATI_texture_float
+#define GL_ATI_texture_float 1
+#define GL_RGBA_FLOAT32_ATI 0x8814
+#define GL_RGB_FLOAT32_ATI 0x8815
+#define GL_ALPHA_FLOAT32_ATI 0x8816
+#define GL_INTENSITY_FLOAT32_ATI 0x8817
+#define GL_LUMINANCE_FLOAT32_ATI 0x8818
+#define GL_LUMINANCE_ALPHA_FLOAT32_ATI 0x8819
+#define GL_RGBA_FLOAT16_ATI 0x881A
+#define GL_RGB_FLOAT16_ATI 0x881B
+#define GL_ALPHA_FLOAT16_ATI 0x881C
+#define GL_INTENSITY_FLOAT16_ATI 0x881D
+#define GL_LUMINANCE_FLOAT16_ATI 0x881E
+#define GL_LUMINANCE_ALPHA_FLOAT16_ATI 0x881F
+#endif /* GL_ATI_texture_float */
+
+#ifndef GL_ATI_texture_mirror_once
+#define GL_ATI_texture_mirror_once 1
+#define GL_MIRROR_CLAMP_ATI 0x8742
+#define GL_MIRROR_CLAMP_TO_EDGE_ATI 0x8743
+#endif /* GL_ATI_texture_mirror_once */
+
+#ifndef GL_ATI_vertex_array_object
+#define GL_ATI_vertex_array_object 1
+#define GL_STATIC_ATI 0x8760
+#define GL_DYNAMIC_ATI 0x8761
+#define GL_PRESERVE_ATI 0x8762
+#define GL_DISCARD_ATI 0x8763
+#define GL_OBJECT_BUFFER_SIZE_ATI 0x8764
+#define GL_OBJECT_BUFFER_USAGE_ATI 0x8765
+#define GL_ARRAY_OBJECT_BUFFER_ATI 0x8766
+#define GL_ARRAY_OBJECT_OFFSET_ATI 0x8767
+typedef GLuint (APIENTRYP PFNGLNEWOBJECTBUFFERATIPROC) (GLsizei size, const void *pointer, GLenum usage);
+typedef GLboolean (APIENTRYP PFNGLISOBJECTBUFFERATIPROC) (GLuint buffer);
+typedef void (APIENTRYP PFNGLUPDATEOBJECTBUFFERATIPROC) (GLuint buffer, GLuint offset, GLsizei size, const void *pointer, GLenum preserve);
+typedef void (APIENTRYP PFNGLGETOBJECTBUFFERFVATIPROC) (GLuint buffer, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETOBJECTBUFFERIVATIPROC) (GLuint buffer, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLFREEOBJECTBUFFERATIPROC) (GLuint buffer);
+typedef void (APIENTRYP PFNGLARRAYOBJECTATIPROC) (GLenum array, GLint size, GLenum type, GLsizei stride, GLuint buffer, GLuint offset);
+typedef void (APIENTRYP PFNGLGETARRAYOBJECTFVATIPROC) (GLenum array, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETARRAYOBJECTIVATIPROC) (GLenum array, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLVARIANTARRAYOBJECTATIPROC) (GLuint id, GLenum type, GLsizei stride, GLuint buffer, GLuint offset);
+typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTFVATIPROC) (GLuint id, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETVARIANTARRAYOBJECTIVATIPROC) (GLuint id, GLenum pname, GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLuint APIENTRY glNewObjectBufferATI (GLsizei size, const void *pointer, GLenum usage);
+GLAPI GLboolean APIENTRY glIsObjectBufferATI (GLuint buffer);
+GLAPI void APIENTRY glUpdateObjectBufferATI (GLuint buffer, GLuint offset, GLsizei size, const void *pointer, GLenum preserve);
+GLAPI void APIENTRY glGetObjectBufferfvATI (GLuint buffer, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetObjectBufferivATI (GLuint buffer, GLenum pname, GLint *params);
+GLAPI void APIENTRY glFreeObjectBufferATI (GLuint buffer);
+GLAPI void APIENTRY glArrayObjectATI (GLenum array, GLint size, GLenum type, GLsizei stride, GLuint buffer, GLuint offset);
+GLAPI void APIENTRY glGetArrayObjectfvATI (GLenum array, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetArrayObjectivATI (GLenum array, GLenum pname, GLint *params);
+GLAPI void APIENTRY glVariantArrayObjectATI (GLuint id, GLenum type, GLsizei stride, GLuint buffer, GLuint offset);
+GLAPI void APIENTRY glGetVariantArrayObjectfvATI (GLuint id, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetVariantArrayObjectivATI (GLuint id, GLenum pname, GLint *params);
+#endif
+#endif /* GL_ATI_vertex_array_object */
+
+#ifndef GL_ATI_vertex_attrib_array_object
+#define GL_ATI_vertex_attrib_array_object 1
+typedef void (APIENTRYP PFNGLVERTEXATTRIBARRAYOBJECTATIPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLuint buffer, GLuint offset);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTFVATIPROC) (GLuint index, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBARRAYOBJECTIVATIPROC) (GLuint index, GLenum pname, GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexAttribArrayObjectATI (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLuint buffer, GLuint offset);
+GLAPI void APIENTRY glGetVertexAttribArrayObjectfvATI (GLuint index, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetVertexAttribArrayObjectivATI (GLuint index, GLenum pname, GLint *params);
+#endif
+#endif /* GL_ATI_vertex_attrib_array_object */
+
+#ifndef GL_ATI_vertex_streams
+#define GL_ATI_vertex_streams 1
+#define GL_MAX_VERTEX_STREAMS_ATI 0x876B
+#define GL_VERTEX_STREAM0_ATI 0x876C
+#define GL_VERTEX_STREAM1_ATI 0x876D
+#define GL_VERTEX_STREAM2_ATI 0x876E
+#define GL_VERTEX_STREAM3_ATI 0x876F
+#define GL_VERTEX_STREAM4_ATI 0x8770
+#define GL_VERTEX_STREAM5_ATI 0x8771
+#define GL_VERTEX_STREAM6_ATI 0x8772
+#define GL_VERTEX_STREAM7_ATI 0x8773
+#define GL_VERTEX_SOURCE_ATI 0x8774
+typedef void (APIENTRYP PFNGLVERTEXSTREAM1SATIPROC) (GLenum stream, GLshort x);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM1SVATIPROC) (GLenum stream, const GLshort *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM1IATIPROC) (GLenum stream, GLint x);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM1IVATIPROC) (GLenum stream, const GLint *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM1FATIPROC) (GLenum stream, GLfloat x);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM1FVATIPROC) (GLenum stream, const GLfloat *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM1DATIPROC) (GLenum stream, GLdouble x);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM1DVATIPROC) (GLenum stream, const GLdouble *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM2SATIPROC) (GLenum stream, GLshort x, GLshort y);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM2SVATIPROC) (GLenum stream, const GLshort *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM2IATIPROC) (GLenum stream, GLint x, GLint y);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM2IVATIPROC) (GLenum stream, const GLint *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM2FATIPROC) (GLenum stream, GLfloat x, GLfloat y);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM2FVATIPROC) (GLenum stream, const GLfloat *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM2DATIPROC) (GLenum stream, GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM2DVATIPROC) (GLenum stream, const GLdouble *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM3SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM3IATIPROC) (GLenum stream, GLint x, GLint y, GLint z);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM3IVATIPROC) (GLenum stream, const GLint *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM3FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM3DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM4SATIPROC) (GLenum stream, GLshort x, GLshort y, GLshort z, GLshort w);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM4SVATIPROC) (GLenum stream, const GLshort *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM4IATIPROC) (GLenum stream, GLint x, GLint y, GLint z, GLint w);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM4IVATIPROC) (GLenum stream, const GLint *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM4FATIPROC) (GLenum stream, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM4FVATIPROC) (GLenum stream, const GLfloat *coords);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM4DATIPROC) (GLenum stream, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLVERTEXSTREAM4DVATIPROC) (GLenum stream, const GLdouble *coords);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3BATIPROC) (GLenum stream, GLbyte nx, GLbyte ny, GLbyte nz);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3BVATIPROC) (GLenum stream, const GLbyte *coords);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3SATIPROC) (GLenum stream, GLshort nx, GLshort ny, GLshort nz);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3SVATIPROC) (GLenum stream, const GLshort *coords);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3IATIPROC) (GLenum stream, GLint nx, GLint ny, GLint nz);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3IVATIPROC) (GLenum stream, const GLint *coords);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3FATIPROC) (GLenum stream, GLfloat nx, GLfloat ny, GLfloat nz);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3FVATIPROC) (GLenum stream, const GLfloat *coords);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3DATIPROC) (GLenum stream, GLdouble nx, GLdouble ny, GLdouble nz);
+typedef void (APIENTRYP PFNGLNORMALSTREAM3DVATIPROC) (GLenum stream, const GLdouble *coords);
+typedef void (APIENTRYP PFNGLCLIENTACTIVEVERTEXSTREAMATIPROC) (GLenum stream);
+typedef void (APIENTRYP PFNGLVERTEXBLENDENVIATIPROC) (GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLVERTEXBLENDENVFATIPROC) (GLenum pname, GLfloat param);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexStream1sATI (GLenum stream, GLshort x);
+GLAPI void APIENTRY glVertexStream1svATI (GLenum stream, const GLshort *coords);
+GLAPI void APIENTRY glVertexStream1iATI (GLenum stream, GLint x);
+GLAPI void APIENTRY glVertexStream1ivATI (GLenum stream, const GLint *coords);
+GLAPI void APIENTRY glVertexStream1fATI (GLenum stream, GLfloat x);
+GLAPI void APIENTRY glVertexStream1fvATI (GLenum stream, const GLfloat *coords);
+GLAPI void APIENTRY glVertexStream1dATI (GLenum stream, GLdouble x);
+GLAPI void APIENTRY glVertexStream1dvATI (GLenum stream, const GLdouble *coords);
+GLAPI void APIENTRY glVertexStream2sATI (GLenum stream, GLshort x, GLshort y);
+GLAPI void APIENTRY glVertexStream2svATI (GLenum stream, const GLshort *coords);
+GLAPI void APIENTRY glVertexStream2iATI (GLenum stream, GLint x, GLint y);
+GLAPI void APIENTRY glVertexStream2ivATI (GLenum stream, const GLint *coords);
+GLAPI void APIENTRY glVertexStream2fATI (GLenum stream, GLfloat x, GLfloat y);
+GLAPI void APIENTRY glVertexStream2fvATI (GLenum stream, const GLfloat *coords);
+GLAPI void APIENTRY glVertexStream2dATI (GLenum stream, GLdouble x, GLdouble y);
+GLAPI void APIENTRY glVertexStream2dvATI (GLenum stream, const GLdouble *coords);
+GLAPI void APIENTRY glVertexStream3sATI (GLenum stream, GLshort x, GLshort y, GLshort z);
+GLAPI void APIENTRY glVertexStream3svATI (GLenum stream, const GLshort *coords);
+GLAPI void APIENTRY glVertexStream3iATI (GLenum stream, GLint x, GLint y, GLint z);
+GLAPI void APIENTRY glVertexStream3ivATI (GLenum stream, const GLint *coords);
+GLAPI void APIENTRY glVertexStream3fATI (GLenum stream, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glVertexStream3fvATI (GLenum stream, const GLfloat *coords);
+GLAPI void APIENTRY glVertexStream3dATI (GLenum stream, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glVertexStream3dvATI (GLenum stream, const GLdouble *coords);
+GLAPI void APIENTRY glVertexStream4sATI (GLenum stream, GLshort x, GLshort y, GLshort z, GLshort w);
+GLAPI void APIENTRY glVertexStream4svATI (GLenum stream, const GLshort *coords);
+GLAPI void APIENTRY glVertexStream4iATI (GLenum stream, GLint x, GLint y, GLint z, GLint w);
+GLAPI void APIENTRY glVertexStream4ivATI (GLenum stream, const GLint *coords);
+GLAPI void APIENTRY glVertexStream4fATI (GLenum stream, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glVertexStream4fvATI (GLenum stream, const GLfloat *coords);
+GLAPI void APIENTRY glVertexStream4dATI (GLenum stream, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glVertexStream4dvATI (GLenum stream, const GLdouble *coords);
+GLAPI void APIENTRY glNormalStream3bATI (GLenum stream, GLbyte nx, GLbyte ny, GLbyte nz);
+GLAPI void APIENTRY glNormalStream3bvATI (GLenum stream, const GLbyte *coords);
+GLAPI void APIENTRY glNormalStream3sATI (GLenum stream, GLshort nx, GLshort ny, GLshort nz);
+GLAPI void APIENTRY glNormalStream3svATI (GLenum stream, const GLshort *coords);
+GLAPI void APIENTRY glNormalStream3iATI (GLenum stream, GLint nx, GLint ny, GLint nz);
+GLAPI void APIENTRY glNormalStream3ivATI (GLenum stream, const GLint *coords);
+GLAPI void APIENTRY glNormalStream3fATI (GLenum stream, GLfloat nx, GLfloat ny, GLfloat nz);
+GLAPI void APIENTRY glNormalStream3fvATI (GLenum stream, const GLfloat *coords);
+GLAPI void APIENTRY glNormalStream3dATI (GLenum stream, GLdouble nx, GLdouble ny, GLdouble nz);
+GLAPI void APIENTRY glNormalStream3dvATI (GLenum stream, const GLdouble *coords);
+GLAPI void APIENTRY glClientActiveVertexStreamATI (GLenum stream);
+GLAPI void APIENTRY glVertexBlendEnviATI (GLenum pname, GLint param);
+GLAPI void APIENTRY glVertexBlendEnvfATI (GLenum pname, GLfloat param);
+#endif
+#endif /* GL_ATI_vertex_streams */
+
+#ifndef GL_EXT_422_pixels
+#define GL_EXT_422_pixels 1
+#define GL_422_EXT 0x80CC
+#define GL_422_REV_EXT 0x80CD
+#define GL_422_AVERAGE_EXT 0x80CE
+#define GL_422_REV_AVERAGE_EXT 0x80CF
+#endif /* GL_EXT_422_pixels */
+
+#ifndef GL_EXT_abgr
+#define GL_EXT_abgr 1
+#define GL_ABGR_EXT 0x8000
+#endif /* GL_EXT_abgr */
+
+#ifndef GL_EXT_bgra
+#define GL_EXT_bgra 1
+#define GL_BGR_EXT 0x80E0
+#define GL_BGRA_EXT 0x80E1
+#endif /* GL_EXT_bgra */
+
+#ifndef GL_EXT_bindable_uniform
+#define GL_EXT_bindable_uniform 1
+#define GL_MAX_VERTEX_BINDABLE_UNIFORMS_EXT 0x8DE2
+#define GL_MAX_FRAGMENT_BINDABLE_UNIFORMS_EXT 0x8DE3
+#define GL_MAX_GEOMETRY_BINDABLE_UNIFORMS_EXT 0x8DE4
+#define GL_MAX_BINDABLE_UNIFORM_SIZE_EXT 0x8DED
+#define GL_UNIFORM_BUFFER_EXT 0x8DEE
+#define GL_UNIFORM_BUFFER_BINDING_EXT 0x8DEF
+typedef void (APIENTRYP PFNGLUNIFORMBUFFEREXTPROC) (GLuint program, GLint location, GLuint buffer);
+typedef GLint (APIENTRYP PFNGLGETUNIFORMBUFFERSIZEEXTPROC) (GLuint program, GLint location);
+typedef GLintptr (APIENTRYP PFNGLGETUNIFORMOFFSETEXTPROC) (GLuint program, GLint location);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glUniformBufferEXT (GLuint program, GLint location, GLuint buffer);
+GLAPI GLint APIENTRY glGetUniformBufferSizeEXT (GLuint program, GLint location);
+GLAPI GLintptr APIENTRY glGetUniformOffsetEXT (GLuint program, GLint location);
+#endif
+#endif /* GL_EXT_bindable_uniform */
+
+#ifndef GL_EXT_blend_color
+#define GL_EXT_blend_color 1
+#define GL_CONSTANT_COLOR_EXT 0x8001
+#define GL_ONE_MINUS_CONSTANT_COLOR_EXT 0x8002
+#define GL_CONSTANT_ALPHA_EXT 0x8003
+#define GL_ONE_MINUS_CONSTANT_ALPHA_EXT 0x8004
+#define GL_BLEND_COLOR_EXT 0x8005
+typedef void (APIENTRYP PFNGLBLENDCOLOREXTPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendColorEXT (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
+#endif
+#endif /* GL_EXT_blend_color */
+
+#ifndef GL_EXT_blend_equation_separate
+#define GL_EXT_blend_equation_separate 1
+#define GL_BLEND_EQUATION_RGB_EXT 0x8009
+#define GL_BLEND_EQUATION_ALPHA_EXT 0x883D
+typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEEXTPROC) (GLenum modeRGB, GLenum modeAlpha);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendEquationSeparateEXT (GLenum modeRGB, GLenum modeAlpha);
+#endif
+#endif /* GL_EXT_blend_equation_separate */
+
+#ifndef GL_EXT_blend_func_separate
+#define GL_EXT_blend_func_separate 1
+#define GL_BLEND_DST_RGB_EXT 0x80C8
+#define GL_BLEND_SRC_RGB_EXT 0x80C9
+#define GL_BLEND_DST_ALPHA_EXT 0x80CA
+#define GL_BLEND_SRC_ALPHA_EXT 0x80CB
+typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEEXTPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendFuncSeparateEXT (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
+#endif
+#endif /* GL_EXT_blend_func_separate */
+
+#ifndef GL_EXT_blend_logic_op
+#define GL_EXT_blend_logic_op 1
+#endif /* GL_EXT_blend_logic_op */
+
+#ifndef GL_EXT_blend_minmax
+#define GL_EXT_blend_minmax 1
+#define GL_MIN_EXT 0x8007
+#define GL_MAX_EXT 0x8008
+#define GL_FUNC_ADD_EXT 0x8006
+#define GL_BLEND_EQUATION_EXT 0x8009
+typedef void (APIENTRYP PFNGLBLENDEQUATIONEXTPROC) (GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendEquationEXT (GLenum mode);
+#endif
+#endif /* GL_EXT_blend_minmax */
+
+#ifndef GL_EXT_blend_subtract
+#define GL_EXT_blend_subtract 1
+#define GL_FUNC_SUBTRACT_EXT 0x800A
+#define GL_FUNC_REVERSE_SUBTRACT_EXT 0x800B
+#endif /* GL_EXT_blend_subtract */
+
+#ifndef GL_EXT_clip_volume_hint
+#define GL_EXT_clip_volume_hint 1
+#define GL_CLIP_VOLUME_CLIPPING_HINT_EXT 0x80F0
+#endif /* GL_EXT_clip_volume_hint */
+
+#ifndef GL_EXT_cmyka
+#define GL_EXT_cmyka 1
+#define GL_CMYK_EXT 0x800C
+#define GL_CMYKA_EXT 0x800D
+#define GL_PACK_CMYK_HINT_EXT 0x800E
+#define GL_UNPACK_CMYK_HINT_EXT 0x800F
+#endif /* GL_EXT_cmyka */
+
+#ifndef GL_EXT_color_subtable
+#define GL_EXT_color_subtable 1
+typedef void (APIENTRYP PFNGLCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const void *data);
+typedef void (APIENTRYP PFNGLCOPYCOLORSUBTABLEEXTPROC) (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glColorSubTableEXT (GLenum target, GLsizei start, GLsizei count, GLenum format, GLenum type, const void *data);
+GLAPI void APIENTRY glCopyColorSubTableEXT (GLenum target, GLsizei start, GLint x, GLint y, GLsizei width);
+#endif
+#endif /* GL_EXT_color_subtable */
+
+#ifndef GL_EXT_compiled_vertex_array
+#define GL_EXT_compiled_vertex_array 1
+#define GL_ARRAY_ELEMENT_LOCK_FIRST_EXT 0x81A8
+#define GL_ARRAY_ELEMENT_LOCK_COUNT_EXT 0x81A9
+typedef void (APIENTRYP PFNGLLOCKARRAYSEXTPROC) (GLint first, GLsizei count);
+typedef void (APIENTRYP PFNGLUNLOCKARRAYSEXTPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glLockArraysEXT (GLint first, GLsizei count);
+GLAPI void APIENTRY glUnlockArraysEXT (void);
+#endif
+#endif /* GL_EXT_compiled_vertex_array */
+
+#ifndef GL_EXT_convolution
+#define GL_EXT_convolution 1
+#define GL_CONVOLUTION_1D_EXT 0x8010
+#define GL_CONVOLUTION_2D_EXT 0x8011
+#define GL_SEPARABLE_2D_EXT 0x8012
+#define GL_CONVOLUTION_BORDER_MODE_EXT 0x8013
+#define GL_CONVOLUTION_FILTER_SCALE_EXT 0x8014
+#define GL_CONVOLUTION_FILTER_BIAS_EXT 0x8015
+#define GL_REDUCE_EXT 0x8016
+#define GL_CONVOLUTION_FORMAT_EXT 0x8017
+#define GL_CONVOLUTION_WIDTH_EXT 0x8018
+#define GL_CONVOLUTION_HEIGHT_EXT 0x8019
+#define GL_MAX_CONVOLUTION_WIDTH_EXT 0x801A
+#define GL_MAX_CONVOLUTION_HEIGHT_EXT 0x801B
+#define GL_POST_CONVOLUTION_RED_SCALE_EXT 0x801C
+#define GL_POST_CONVOLUTION_GREEN_SCALE_EXT 0x801D
+#define GL_POST_CONVOLUTION_BLUE_SCALE_EXT 0x801E
+#define GL_POST_CONVOLUTION_ALPHA_SCALE_EXT 0x801F
+#define GL_POST_CONVOLUTION_RED_BIAS_EXT 0x8020
+#define GL_POST_CONVOLUTION_GREEN_BIAS_EXT 0x8021
+#define GL_POST_CONVOLUTION_BLUE_BIAS_EXT 0x8022
+#define GL_POST_CONVOLUTION_ALPHA_BIAS_EXT 0x8023
+typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *image);
+typedef void (APIENTRYP PFNGLCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *image);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat params);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint params);
+typedef void (APIENTRYP PFNGLCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER1DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width);
+typedef void (APIENTRYP PFNGLCOPYCONVOLUTIONFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLGETCONVOLUTIONFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, void *image);
+typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETSEPARABLEFILTEREXTPROC) (GLenum target, GLenum format, GLenum type, void *row, void *column, void *span);
+typedef void (APIENTRYP PFNGLSEPARABLEFILTER2DEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *row, const void *column);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glConvolutionFilter1DEXT (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *image);
+GLAPI void APIENTRY glConvolutionFilter2DEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *image);
+GLAPI void APIENTRY glConvolutionParameterfEXT (GLenum target, GLenum pname, GLfloat params);
+GLAPI void APIENTRY glConvolutionParameterfvEXT (GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glConvolutionParameteriEXT (GLenum target, GLenum pname, GLint params);
+GLAPI void APIENTRY glConvolutionParameterivEXT (GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glCopyConvolutionFilter1DEXT (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width);
+GLAPI void APIENTRY glCopyConvolutionFilter2DEXT (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glGetConvolutionFilterEXT (GLenum target, GLenum format, GLenum type, void *image);
+GLAPI void APIENTRY glGetConvolutionParameterfvEXT (GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetConvolutionParameterivEXT (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetSeparableFilterEXT (GLenum target, GLenum format, GLenum type, void *row, void *column, void *span);
+GLAPI void APIENTRY glSeparableFilter2DEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *row, const void *column);
+#endif
+#endif /* GL_EXT_convolution */
+
+#ifndef GL_EXT_coordinate_frame
+#define GL_EXT_coordinate_frame 1
+#define GL_TANGENT_ARRAY_EXT 0x8439
+#define GL_BINORMAL_ARRAY_EXT 0x843A
+#define GL_CURRENT_TANGENT_EXT 0x843B
+#define GL_CURRENT_BINORMAL_EXT 0x843C
+#define GL_TANGENT_ARRAY_TYPE_EXT 0x843E
+#define GL_TANGENT_ARRAY_STRIDE_EXT 0x843F
+#define GL_BINORMAL_ARRAY_TYPE_EXT 0x8440
+#define GL_BINORMAL_ARRAY_STRIDE_EXT 0x8441
+#define GL_TANGENT_ARRAY_POINTER_EXT 0x8442
+#define GL_BINORMAL_ARRAY_POINTER_EXT 0x8443
+#define GL_MAP1_TANGENT_EXT 0x8444
+#define GL_MAP2_TANGENT_EXT 0x8445
+#define GL_MAP1_BINORMAL_EXT 0x8446
+#define GL_MAP2_BINORMAL_EXT 0x8447
+typedef void (APIENTRYP PFNGLTANGENT3BEXTPROC) (GLbyte tx, GLbyte ty, GLbyte tz);
+typedef void (APIENTRYP PFNGLTANGENT3BVEXTPROC) (const GLbyte *v);
+typedef void (APIENTRYP PFNGLTANGENT3DEXTPROC) (GLdouble tx, GLdouble ty, GLdouble tz);
+typedef void (APIENTRYP PFNGLTANGENT3DVEXTPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLTANGENT3FEXTPROC) (GLfloat tx, GLfloat ty, GLfloat tz);
+typedef void (APIENTRYP PFNGLTANGENT3FVEXTPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLTANGENT3IEXTPROC) (GLint tx, GLint ty, GLint tz);
+typedef void (APIENTRYP PFNGLTANGENT3IVEXTPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLTANGENT3SEXTPROC) (GLshort tx, GLshort ty, GLshort tz);
+typedef void (APIENTRYP PFNGLTANGENT3SVEXTPROC) (const GLshort *v);
+typedef void (APIENTRYP PFNGLBINORMAL3BEXTPROC) (GLbyte bx, GLbyte by, GLbyte bz);
+typedef void (APIENTRYP PFNGLBINORMAL3BVEXTPROC) (const GLbyte *v);
+typedef void (APIENTRYP PFNGLBINORMAL3DEXTPROC) (GLdouble bx, GLdouble by, GLdouble bz);
+typedef void (APIENTRYP PFNGLBINORMAL3DVEXTPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLBINORMAL3FEXTPROC) (GLfloat bx, GLfloat by, GLfloat bz);
+typedef void (APIENTRYP PFNGLBINORMAL3FVEXTPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLBINORMAL3IEXTPROC) (GLint bx, GLint by, GLint bz);
+typedef void (APIENTRYP PFNGLBINORMAL3IVEXTPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLBINORMAL3SEXTPROC) (GLshort bx, GLshort by, GLshort bz);
+typedef void (APIENTRYP PFNGLBINORMAL3SVEXTPROC) (const GLshort *v);
+typedef void (APIENTRYP PFNGLTANGENTPOINTEREXTPROC) (GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLBINORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, const void *pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTangent3bEXT (GLbyte tx, GLbyte ty, GLbyte tz);
+GLAPI void APIENTRY glTangent3bvEXT (const GLbyte *v);
+GLAPI void APIENTRY glTangent3dEXT (GLdouble tx, GLdouble ty, GLdouble tz);
+GLAPI void APIENTRY glTangent3dvEXT (const GLdouble *v);
+GLAPI void APIENTRY glTangent3fEXT (GLfloat tx, GLfloat ty, GLfloat tz);
+GLAPI void APIENTRY glTangent3fvEXT (const GLfloat *v);
+GLAPI void APIENTRY glTangent3iEXT (GLint tx, GLint ty, GLint tz);
+GLAPI void APIENTRY glTangent3ivEXT (const GLint *v);
+GLAPI void APIENTRY glTangent3sEXT (GLshort tx, GLshort ty, GLshort tz);
+GLAPI void APIENTRY glTangent3svEXT (const GLshort *v);
+GLAPI void APIENTRY glBinormal3bEXT (GLbyte bx, GLbyte by, GLbyte bz);
+GLAPI void APIENTRY glBinormal3bvEXT (const GLbyte *v);
+GLAPI void APIENTRY glBinormal3dEXT (GLdouble bx, GLdouble by, GLdouble bz);
+GLAPI void APIENTRY glBinormal3dvEXT (const GLdouble *v);
+GLAPI void APIENTRY glBinormal3fEXT (GLfloat bx, GLfloat by, GLfloat bz);
+GLAPI void APIENTRY glBinormal3fvEXT (const GLfloat *v);
+GLAPI void APIENTRY glBinormal3iEXT (GLint bx, GLint by, GLint bz);
+GLAPI void APIENTRY glBinormal3ivEXT (const GLint *v);
+GLAPI void APIENTRY glBinormal3sEXT (GLshort bx, GLshort by, GLshort bz);
+GLAPI void APIENTRY glBinormal3svEXT (const GLshort *v);
+GLAPI void APIENTRY glTangentPointerEXT (GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glBinormalPointerEXT (GLenum type, GLsizei stride, const void *pointer);
+#endif
+#endif /* GL_EXT_coordinate_frame */
+
+#ifndef GL_EXT_copy_texture
+#define GL_EXT_copy_texture 1
+typedef void (APIENTRYP PFNGLCOPYTEXIMAGE1DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
+typedef void (APIENTRYP PFNGLCOPYTEXIMAGE2DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
+typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLCOPYTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glCopyTexImage1DEXT (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
+GLAPI void APIENTRY glCopyTexImage2DEXT (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+GLAPI void APIENTRY glCopyTexSubImage1DEXT (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
+GLAPI void APIENTRY glCopyTexSubImage2DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glCopyTexSubImage3DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+#endif
+#endif /* GL_EXT_copy_texture */
+
+#ifndef GL_EXT_cull_vertex
+#define GL_EXT_cull_vertex 1
+#define GL_CULL_VERTEX_EXT 0x81AA
+#define GL_CULL_VERTEX_EYE_POSITION_EXT 0x81AB
+#define GL_CULL_VERTEX_OBJECT_POSITION_EXT 0x81AC
+typedef void (APIENTRYP PFNGLCULLPARAMETERDVEXTPROC) (GLenum pname, GLdouble *params);
+typedef void (APIENTRYP PFNGLCULLPARAMETERFVEXTPROC) (GLenum pname, GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glCullParameterdvEXT (GLenum pname, GLdouble *params);
+GLAPI void APIENTRY glCullParameterfvEXT (GLenum pname, GLfloat *params);
+#endif
+#endif /* GL_EXT_cull_vertex */
+
+#ifndef GL_EXT_debug_label
+#define GL_EXT_debug_label 1
+#define GL_PROGRAM_PIPELINE_OBJECT_EXT 0x8A4F
+#define GL_PROGRAM_OBJECT_EXT 0x8B40
+#define GL_SHADER_OBJECT_EXT 0x8B48
+#define GL_BUFFER_OBJECT_EXT 0x9151
+#define GL_QUERY_OBJECT_EXT 0x9153
+#define GL_VERTEX_ARRAY_OBJECT_EXT 0x9154
+typedef void (APIENTRYP PFNGLLABELOBJECTEXTPROC) (GLenum type, GLuint object, GLsizei length, const GLchar *label);
+typedef void (APIENTRYP PFNGLGETOBJECTLABELEXTPROC) (GLenum type, GLuint object, GLsizei bufSize, GLsizei *length, GLchar *label);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glLabelObjectEXT (GLenum type, GLuint object, GLsizei length, const GLchar *label);
+GLAPI void APIENTRY glGetObjectLabelEXT (GLenum type, GLuint object, GLsizei bufSize, GLsizei *length, GLchar *label);
+#endif
+#endif /* GL_EXT_debug_label */
+
+#ifndef GL_EXT_debug_marker
+#define GL_EXT_debug_marker 1
+typedef void (APIENTRYP PFNGLINSERTEVENTMARKEREXTPROC) (GLsizei length, const GLchar *marker);
+typedef void (APIENTRYP PFNGLPUSHGROUPMARKEREXTPROC) (GLsizei length, const GLchar *marker);
+typedef void (APIENTRYP PFNGLPOPGROUPMARKEREXTPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glInsertEventMarkerEXT (GLsizei length, const GLchar *marker);
+GLAPI void APIENTRY glPushGroupMarkerEXT (GLsizei length, const GLchar *marker);
+GLAPI void APIENTRY glPopGroupMarkerEXT (void);
+#endif
+#endif /* GL_EXT_debug_marker */
+
+#ifndef GL_EXT_depth_bounds_test
+#define GL_EXT_depth_bounds_test 1
+#define GL_DEPTH_BOUNDS_TEST_EXT 0x8890
+#define GL_DEPTH_BOUNDS_EXT 0x8891
+typedef void (APIENTRYP PFNGLDEPTHBOUNDSEXTPROC) (GLclampd zmin, GLclampd zmax);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDepthBoundsEXT (GLclampd zmin, GLclampd zmax);
+#endif
+#endif /* GL_EXT_depth_bounds_test */
+
+#ifndef GL_EXT_direct_state_access
+#define GL_EXT_direct_state_access 1
+#define GL_PROGRAM_MATRIX_EXT 0x8E2D
+#define GL_TRANSPOSE_PROGRAM_MATRIX_EXT 0x8E2E
+#define GL_PROGRAM_MATRIX_STACK_DEPTH_EXT 0x8E2F
+typedef void (APIENTRYP PFNGLMATRIXLOADFEXTPROC) (GLenum mode, const GLfloat *m);
+typedef void (APIENTRYP PFNGLMATRIXLOADDEXTPROC) (GLenum mode, const GLdouble *m);
+typedef void (APIENTRYP PFNGLMATRIXMULTFEXTPROC) (GLenum mode, const GLfloat *m);
+typedef void (APIENTRYP PFNGLMATRIXMULTDEXTPROC) (GLenum mode, const GLdouble *m);
+typedef void (APIENTRYP PFNGLMATRIXLOADIDENTITYEXTPROC) (GLenum mode);
+typedef void (APIENTRYP PFNGLMATRIXROTATEFEXTPROC) (GLenum mode, GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLMATRIXROTATEDEXTPROC) (GLenum mode, GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLMATRIXSCALEFEXTPROC) (GLenum mode, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLMATRIXSCALEDEXTPROC) (GLenum mode, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLMATRIXTRANSLATEFEXTPROC) (GLenum mode, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLMATRIXTRANSLATEDEXTPROC) (GLenum mode, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLMATRIXFRUSTUMEXTPROC) (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
+typedef void (APIENTRYP PFNGLMATRIXORTHOEXTPROC) (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
+typedef void (APIENTRYP PFNGLMATRIXPOPEXTPROC) (GLenum mode);
+typedef void (APIENTRYP PFNGLMATRIXPUSHEXTPROC) (GLenum mode);
+typedef void (APIENTRYP PFNGLCLIENTATTRIBDEFAULTEXTPROC) (GLbitfield mask);
+typedef void (APIENTRYP PFNGLPUSHCLIENTATTRIBDEFAULTEXTPROC) (GLbitfield mask);
+typedef void (APIENTRYP PFNGLTEXTUREPARAMETERFEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLTEXTUREPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLCOPYTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
+typedef void (APIENTRYP PFNGLCOPYTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
+typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLGETTEXTUREIMAGEEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, void *pixels);
+typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETTEXTURELEVELPARAMETERFVEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETTEXTURELEVELPARAMETERIVEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLTEXTUREIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLCOPYTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLBINDMULTITEXTUREEXTPROC) (GLenum texunit, GLenum target, GLuint texture);
+typedef void (APIENTRYP PFNGLMULTITEXCOORDPOINTEREXTPROC) (GLenum texunit, GLint size, GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLMULTITEXENVFEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLMULTITEXENVFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLMULTITEXENVIEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLMULTITEXENVIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLMULTITEXGENDEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLdouble param);
+typedef void (APIENTRYP PFNGLMULTITEXGENDVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLdouble *params);
+typedef void (APIENTRYP PFNGLMULTITEXGENFEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLMULTITEXGENFVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLMULTITEXGENIEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLMULTITEXGENIVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXENVFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXENVIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXGENDVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXGENFVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXGENIVEXTPROC) (GLenum texunit, GLenum coord, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLMULTITEXPARAMETERFEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLMULTITEXPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLCOPYMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
+typedef void (APIENTRYP PFNGLCOPYMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
+typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLGETMULTITEXIMAGEEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum format, GLenum type, void *pixels);
+typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXLEVELPARAMETERFVEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXLEVELPARAMETERIVEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLMULTITEXIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLCOPYMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLENABLECLIENTSTATEINDEXEDEXTPROC) (GLenum array, GLuint index);
+typedef void (APIENTRYP PFNGLDISABLECLIENTSTATEINDEXEDEXTPROC) (GLenum array, GLuint index);
+typedef void (APIENTRYP PFNGLGETFLOATINDEXEDVEXTPROC) (GLenum target, GLuint index, GLfloat *data);
+typedef void (APIENTRYP PFNGLGETDOUBLEINDEXEDVEXTPROC) (GLenum target, GLuint index, GLdouble *data);
+typedef void (APIENTRYP PFNGLGETPOINTERINDEXEDVEXTPROC) (GLenum target, GLuint index, void **data);
+typedef void (APIENTRYP PFNGLENABLEINDEXEDEXTPROC) (GLenum target, GLuint index);
+typedef void (APIENTRYP PFNGLDISABLEINDEXEDEXTPROC) (GLenum target, GLuint index);
+typedef GLboolean (APIENTRYP PFNGLISENABLEDINDEXEDEXTPROC) (GLenum target, GLuint index);
+typedef void (APIENTRYP PFNGLGETINTEGERINDEXEDVEXTPROC) (GLenum target, GLuint index, GLint *data);
+typedef void (APIENTRYP PFNGLGETBOOLEANINDEXEDVEXTPROC) (GLenum target, GLuint index, GLboolean *data);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTUREIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE3DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE2DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDTEXTURESUBIMAGE1DEXTPROC) (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLGETCOMPRESSEDTEXTUREIMAGEEXTPROC) (GLuint texture, GLenum target, GLint lod, void *img);
+typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE3DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE2DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLCOMPRESSEDMULTITEXSUBIMAGE1DEXTPROC) (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *bits);
+typedef void (APIENTRYP PFNGLGETCOMPRESSEDMULTITEXIMAGEEXTPROC) (GLenum texunit, GLenum target, GLint lod, void *img);
+typedef void (APIENTRYP PFNGLMATRIXLOADTRANSPOSEFEXTPROC) (GLenum mode, const GLfloat *m);
+typedef void (APIENTRYP PFNGLMATRIXLOADTRANSPOSEDEXTPROC) (GLenum mode, const GLdouble *m);
+typedef void (APIENTRYP PFNGLMATRIXMULTTRANSPOSEFEXTPROC) (GLenum mode, const GLfloat *m);
+typedef void (APIENTRYP PFNGLMATRIXMULTTRANSPOSEDEXTPROC) (GLenum mode, const GLdouble *m);
+typedef void (APIENTRYP PFNGLNAMEDBUFFERDATAEXTPROC) (GLuint buffer, GLsizeiptr size, const void *data, GLenum usage);
+typedef void (APIENTRYP PFNGLNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data);
+typedef void *(APIENTRYP PFNGLMAPNAMEDBUFFEREXTPROC) (GLuint buffer, GLenum access);
+typedef GLboolean (APIENTRYP PFNGLUNMAPNAMEDBUFFEREXTPROC) (GLuint buffer);
+typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPARAMETERIVEXTPROC) (GLuint buffer, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPOINTERVEXTPROC) (GLuint buffer, GLenum pname, void **params);
+typedef void (APIENTRYP PFNGLGETNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, void *data);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FEXTPROC) (GLuint program, GLint location, GLfloat v0);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IEXTPROC) (GLuint program, GLint location, GLint v0);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (APIENTRYP PFNGLTEXTUREBUFFEREXTPROC) (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer);
+typedef void (APIENTRYP PFNGLMULTITEXBUFFEREXTPROC) (GLenum texunit, GLenum target, GLenum internalformat, GLuint buffer);
+typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLTEXTUREPARAMETERIUIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, const GLuint *params);
+typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETTEXTUREPARAMETERIUIVEXTPROC) (GLuint texture, GLenum target, GLenum pname, GLuint *params);
+typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLMULTITEXPARAMETERIUIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, const GLuint *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETMULTITEXPARAMETERIUIVEXTPROC) (GLenum texunit, GLenum target, GLenum pname, GLuint *params);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIEXTPROC) (GLuint program, GLint location, GLuint v0);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERS4FVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLfloat *params);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4IEXTPROC) (GLuint program, GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4IVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLint *params);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERSI4IVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLint *params);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4UIEXTPROC) (GLuint program, GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERI4UIVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLuint *params);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETERSI4UIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLsizei count, const GLuint *params);
+typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERIIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLint *params);
+typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERIUIVEXTPROC) (GLuint program, GLenum target, GLuint index, GLuint *params);
+typedef void (APIENTRYP PFNGLENABLECLIENTSTATEIEXTPROC) (GLenum array, GLuint index);
+typedef void (APIENTRYP PFNGLDISABLECLIENTSTATEIEXTPROC) (GLenum array, GLuint index);
+typedef void (APIENTRYP PFNGLGETFLOATI_VEXTPROC) (GLenum pname, GLuint index, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETDOUBLEI_VEXTPROC) (GLenum pname, GLuint index, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETPOINTERI_VEXTPROC) (GLenum pname, GLuint index, void **params);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMSTRINGEXTPROC) (GLuint program, GLenum target, GLenum format, GLsizei len, const void *string);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4DEXTPROC) (GLuint program, GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4DVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLdouble *params);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4FEXTPROC) (GLuint program, GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLNAMEDPROGRAMLOCALPARAMETER4FVEXTPROC) (GLuint program, GLenum target, GLuint index, const GLfloat *params);
+typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERDVEXTPROC) (GLuint program, GLenum target, GLuint index, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMLOCALPARAMETERFVEXTPROC) (GLuint program, GLenum target, GLuint index, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMIVEXTPROC) (GLuint program, GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETNAMEDPROGRAMSTRINGEXTPROC) (GLuint program, GLenum target, GLenum pname, void *string);
+typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEEXTPROC) (GLuint renderbuffer, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLGETNAMEDRENDERBUFFERPARAMETERIVEXTPROC) (GLuint renderbuffer, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLuint renderbuffer, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLNAMEDRENDERBUFFERSTORAGEMULTISAMPLECOVERAGEEXTPROC) (GLuint renderbuffer, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height);
+typedef GLenum (APIENTRYP PFNGLCHECKNAMEDFRAMEBUFFERSTATUSEXTPROC) (GLuint framebuffer, GLenum target);
+typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE1DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE2DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURE3DEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERRENDERBUFFEREXTPROC) (GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
+typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum attachment, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGENERATETEXTUREMIPMAPEXTPROC) (GLuint texture, GLenum target);
+typedef void (APIENTRYP PFNGLGENERATEMULTITEXMIPMAPEXTPROC) (GLenum texunit, GLenum target);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERDRAWBUFFEREXTPROC) (GLuint framebuffer, GLenum mode);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERDRAWBUFFERSEXTPROC) (GLuint framebuffer, GLsizei n, const GLenum *bufs);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERREADBUFFEREXTPROC) (GLuint framebuffer, GLenum mode);
+typedef void (APIENTRYP PFNGLGETFRAMEBUFFERPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLNAMEDCOPYBUFFERSUBDATAEXTPROC) (GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
+typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTUREEXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTURELAYEREXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLint layer);
+typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERTEXTUREFACEEXTPROC) (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLenum face);
+typedef void (APIENTRYP PFNGLTEXTURERENDERBUFFEREXTPROC) (GLuint texture, GLenum target, GLuint renderbuffer);
+typedef void (APIENTRYP PFNGLMULTITEXRENDERBUFFEREXTPROC) (GLenum texunit, GLenum target, GLuint renderbuffer);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYCOLOROFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYEDGEFLAGOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYINDEXOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYNORMALOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYTEXCOORDOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYMULTITEXCOORDOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLenum texunit, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYFOGCOORDOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYSECONDARYCOLOROFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBIOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLENABLEVERTEXARRAYEXTPROC) (GLuint vaobj, GLenum array);
+typedef void (APIENTRYP PFNGLDISABLEVERTEXARRAYEXTPROC) (GLuint vaobj, GLenum array);
+typedef void (APIENTRYP PFNGLENABLEVERTEXARRAYATTRIBEXTPROC) (GLuint vaobj, GLuint index);
+typedef void (APIENTRYP PFNGLDISABLEVERTEXARRAYATTRIBEXTPROC) (GLuint vaobj, GLuint index);
+typedef void (APIENTRYP PFNGLGETVERTEXARRAYINTEGERVEXTPROC) (GLuint vaobj, GLenum pname, GLint *param);
+typedef void (APIENTRYP PFNGLGETVERTEXARRAYPOINTERVEXTPROC) (GLuint vaobj, GLenum pname, void **param);
+typedef void (APIENTRYP PFNGLGETVERTEXARRAYINTEGERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, GLint *param);
+typedef void (APIENTRYP PFNGLGETVERTEXARRAYPOINTERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, void **param);
+typedef void *(APIENTRYP PFNGLMAPNAMEDBUFFERRANGEEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access);
+typedef void (APIENTRYP PFNGLFLUSHMAPPEDNAMEDBUFFERRANGEEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr length);
+typedef void (APIENTRYP PFNGLNAMEDBUFFERSTORAGEEXTPROC) (GLuint buffer, GLsizeiptr size, const void *data, GLbitfield flags);
+typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERDATAEXTPROC) (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data);
+typedef void (APIENTRYP PFNGLCLEARNAMEDBUFFERSUBDATAEXTPROC) (GLuint buffer, GLenum internalformat, GLsizeiptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data);
+typedef void (APIENTRYP PFNGLNAMEDFRAMEBUFFERPARAMETERIEXTPROC) (GLuint framebuffer, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLGETNAMEDFRAMEBUFFERPARAMETERIVEXTPROC) (GLuint framebuffer, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DEXTPROC) (GLuint program, GLint location, GLdouble x);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DEXTPROC) (GLuint program, GLint location, GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DEXTPROC) (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DEXTPROC) (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM1DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM2DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM3DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORM4DVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3DVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+typedef void (APIENTRYP PFNGLTEXTUREBUFFERRANGEEXTPROC) (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size);
+typedef void (APIENTRYP PFNGLTEXTURESTORAGE1DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+typedef void (APIENTRYP PFNGLTEXTURESTORAGE2DMULTISAMPLEEXTPROC) (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
+typedef void (APIENTRYP PFNGLTEXTURESTORAGE3DMULTISAMPLEEXTPROC) (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations);
+typedef void (APIENTRYP PFNGLVERTEXARRAYBINDVERTEXBUFFEREXTPROC) (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBIFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBLFORMATEXTPROC) (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBBINDINGEXTPROC) (GLuint vaobj, GLuint attribindex, GLuint bindingindex);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXBINDINGDIVISOREXTPROC) (GLuint vaobj, GLuint bindingindex, GLuint divisor);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBLOFFSETEXTPROC) (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+typedef void (APIENTRYP PFNGLTEXTUREPAGECOMMITMENTEXTPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLboolean resident);
+typedef void (APIENTRYP PFNGLVERTEXARRAYVERTEXATTRIBDIVISOREXTPROC) (GLuint vaobj, GLuint index, GLuint divisor);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMatrixLoadfEXT (GLenum mode, const GLfloat *m);
+GLAPI void APIENTRY glMatrixLoaddEXT (GLenum mode, const GLdouble *m);
+GLAPI void APIENTRY glMatrixMultfEXT (GLenum mode, const GLfloat *m);
+GLAPI void APIENTRY glMatrixMultdEXT (GLenum mode, const GLdouble *m);
+GLAPI void APIENTRY glMatrixLoadIdentityEXT (GLenum mode);
+GLAPI void APIENTRY glMatrixRotatefEXT (GLenum mode, GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glMatrixRotatedEXT (GLenum mode, GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glMatrixScalefEXT (GLenum mode, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glMatrixScaledEXT (GLenum mode, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glMatrixTranslatefEXT (GLenum mode, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glMatrixTranslatedEXT (GLenum mode, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glMatrixFrustumEXT (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
+GLAPI void APIENTRY glMatrixOrthoEXT (GLenum mode, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
+GLAPI void APIENTRY glMatrixPopEXT (GLenum mode);
+GLAPI void APIENTRY glMatrixPushEXT (GLenum mode);
+GLAPI void APIENTRY glClientAttribDefaultEXT (GLbitfield mask);
+GLAPI void APIENTRY glPushClientAttribDefaultEXT (GLbitfield mask);
+GLAPI void APIENTRY glTextureParameterfEXT (GLuint texture, GLenum target, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glTextureParameterfvEXT (GLuint texture, GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glTextureParameteriEXT (GLuint texture, GLenum target, GLenum pname, GLint param);
+GLAPI void APIENTRY glTextureParameterivEXT (GLuint texture, GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glTextureImage1DEXT (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glTextureImage2DEXT (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glTextureSubImage1DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glTextureSubImage2DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glCopyTextureImage1DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
+GLAPI void APIENTRY glCopyTextureImage2DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+GLAPI void APIENTRY glCopyTextureSubImage1DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
+GLAPI void APIENTRY glCopyTextureSubImage2DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glGetTextureImageEXT (GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, void *pixels);
+GLAPI void APIENTRY glGetTextureParameterfvEXT (GLuint texture, GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetTextureParameterivEXT (GLuint texture, GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetTextureLevelParameterfvEXT (GLuint texture, GLenum target, GLint level, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetTextureLevelParameterivEXT (GLuint texture, GLenum target, GLint level, GLenum pname, GLint *params);
+GLAPI void APIENTRY glTextureImage3DEXT (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glTextureSubImage3DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glCopyTextureSubImage3DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glBindMultiTextureEXT (GLenum texunit, GLenum target, GLuint texture);
+GLAPI void APIENTRY glMultiTexCoordPointerEXT (GLenum texunit, GLint size, GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glMultiTexEnvfEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glMultiTexEnvfvEXT (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glMultiTexEnviEXT (GLenum texunit, GLenum target, GLenum pname, GLint param);
+GLAPI void APIENTRY glMultiTexEnvivEXT (GLenum texunit, GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glMultiTexGendEXT (GLenum texunit, GLenum coord, GLenum pname, GLdouble param);
+GLAPI void APIENTRY glMultiTexGendvEXT (GLenum texunit, GLenum coord, GLenum pname, const GLdouble *params);
+GLAPI void APIENTRY glMultiTexGenfEXT (GLenum texunit, GLenum coord, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glMultiTexGenfvEXT (GLenum texunit, GLenum coord, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glMultiTexGeniEXT (GLenum texunit, GLenum coord, GLenum pname, GLint param);
+GLAPI void APIENTRY glMultiTexGenivEXT (GLenum texunit, GLenum coord, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glGetMultiTexEnvfvEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetMultiTexEnvivEXT (GLenum texunit, GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetMultiTexGendvEXT (GLenum texunit, GLenum coord, GLenum pname, GLdouble *params);
+GLAPI void APIENTRY glGetMultiTexGenfvEXT (GLenum texunit, GLenum coord, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetMultiTexGenivEXT (GLenum texunit, GLenum coord, GLenum pname, GLint *params);
+GLAPI void APIENTRY glMultiTexParameteriEXT (GLenum texunit, GLenum target, GLenum pname, GLint param);
+GLAPI void APIENTRY glMultiTexParameterivEXT (GLenum texunit, GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glMultiTexParameterfEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glMultiTexParameterfvEXT (GLenum texunit, GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glMultiTexImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glMultiTexImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glMultiTexSubImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glMultiTexSubImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glCopyMultiTexImage1DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
+GLAPI void APIENTRY glCopyMultiTexImage2DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+GLAPI void APIENTRY glCopyMultiTexSubImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
+GLAPI void APIENTRY glCopyMultiTexSubImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glGetMultiTexImageEXT (GLenum texunit, GLenum target, GLint level, GLenum format, GLenum type, void *pixels);
+GLAPI void APIENTRY glGetMultiTexParameterfvEXT (GLenum texunit, GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetMultiTexParameterivEXT (GLenum texunit, GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetMultiTexLevelParameterfvEXT (GLenum texunit, GLenum target, GLint level, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetMultiTexLevelParameterivEXT (GLenum texunit, GLenum target, GLint level, GLenum pname, GLint *params);
+GLAPI void APIENTRY glMultiTexImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glMultiTexSubImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glCopyMultiTexSubImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glEnableClientStateIndexedEXT (GLenum array, GLuint index);
+GLAPI void APIENTRY glDisableClientStateIndexedEXT (GLenum array, GLuint index);
+GLAPI void APIENTRY glGetFloatIndexedvEXT (GLenum target, GLuint index, GLfloat *data);
+GLAPI void APIENTRY glGetDoubleIndexedvEXT (GLenum target, GLuint index, GLdouble *data);
+GLAPI void APIENTRY glGetPointerIndexedvEXT (GLenum target, GLuint index, void **data);
+GLAPI void APIENTRY glEnableIndexedEXT (GLenum target, GLuint index);
+GLAPI void APIENTRY glDisableIndexedEXT (GLenum target, GLuint index);
+GLAPI GLboolean APIENTRY glIsEnabledIndexedEXT (GLenum target, GLuint index);
+GLAPI void APIENTRY glGetIntegerIndexedvEXT (GLenum target, GLuint index, GLint *data);
+GLAPI void APIENTRY glGetBooleanIndexedvEXT (GLenum target, GLuint index, GLboolean *data);
+GLAPI void APIENTRY glCompressedTextureImage3DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedTextureImage2DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedTextureImage1DEXT (GLuint texture, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedTextureSubImage3DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedTextureSubImage2DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedTextureSubImage1DEXT (GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glGetCompressedTextureImageEXT (GLuint texture, GLenum target, GLint lod, void *img);
+GLAPI void APIENTRY glCompressedMultiTexImage3DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedMultiTexImage2DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedMultiTexImage1DEXT (GLenum texunit, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedMultiTexSubImage3DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedMultiTexSubImage2DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glCompressedMultiTexSubImage1DEXT (GLenum texunit, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *bits);
+GLAPI void APIENTRY glGetCompressedMultiTexImageEXT (GLenum texunit, GLenum target, GLint lod, void *img);
+GLAPI void APIENTRY glMatrixLoadTransposefEXT (GLenum mode, const GLfloat *m);
+GLAPI void APIENTRY glMatrixLoadTransposedEXT (GLenum mode, const GLdouble *m);
+GLAPI void APIENTRY glMatrixMultTransposefEXT (GLenum mode, const GLfloat *m);
+GLAPI void APIENTRY glMatrixMultTransposedEXT (GLenum mode, const GLdouble *m);
+GLAPI void APIENTRY glNamedBufferDataEXT (GLuint buffer, GLsizeiptr size, const void *data, GLenum usage);
+GLAPI void APIENTRY glNamedBufferSubDataEXT (GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data);
+GLAPI void *APIENTRY glMapNamedBufferEXT (GLuint buffer, GLenum access);
+GLAPI GLboolean APIENTRY glUnmapNamedBufferEXT (GLuint buffer);
+GLAPI void APIENTRY glGetNamedBufferParameterivEXT (GLuint buffer, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetNamedBufferPointervEXT (GLuint buffer, GLenum pname, void **params);
+GLAPI void APIENTRY glGetNamedBufferSubDataEXT (GLuint buffer, GLintptr offset, GLsizeiptr size, void *data);
+GLAPI void APIENTRY glProgramUniform1fEXT (GLuint program, GLint location, GLfloat v0);
+GLAPI void APIENTRY glProgramUniform2fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1);
+GLAPI void APIENTRY glProgramUniform3fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+GLAPI void APIENTRY glProgramUniform4fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+GLAPI void APIENTRY glProgramUniform1iEXT (GLuint program, GLint location, GLint v0);
+GLAPI void APIENTRY glProgramUniform2iEXT (GLuint program, GLint location, GLint v0, GLint v1);
+GLAPI void APIENTRY glProgramUniform3iEXT (GLuint program, GLint location, GLint v0, GLint v1, GLint v2);
+GLAPI void APIENTRY glProgramUniform4iEXT (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+GLAPI void APIENTRY glProgramUniform1fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniform2fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniform3fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniform4fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniform1ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glProgramUniform2ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glProgramUniform3ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glProgramUniform4ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GLAPI void APIENTRY glProgramUniformMatrix2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix2x3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix3x2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix2x4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix4x2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix3x4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glProgramUniformMatrix4x3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GLAPI void APIENTRY glTextureBufferEXT (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer);
+GLAPI void APIENTRY glMultiTexBufferEXT (GLenum texunit, GLenum target, GLenum internalformat, GLuint buffer);
+GLAPI void APIENTRY glTextureParameterIivEXT (GLuint texture, GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glTextureParameterIuivEXT (GLuint texture, GLenum target, GLenum pname, const GLuint *params);
+GLAPI void APIENTRY glGetTextureParameterIivEXT (GLuint texture, GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetTextureParameterIuivEXT (GLuint texture, GLenum target, GLenum pname, GLuint *params);
+GLAPI void APIENTRY glMultiTexParameterIivEXT (GLenum texunit, GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glMultiTexParameterIuivEXT (GLenum texunit, GLenum target, GLenum pname, const GLuint *params);
+GLAPI void APIENTRY glGetMultiTexParameterIivEXT (GLenum texunit, GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetMultiTexParameterIuivEXT (GLenum texunit, GLenum target, GLenum pname, GLuint *params);
+GLAPI void APIENTRY glProgramUniform1uiEXT (GLuint program, GLint location, GLuint v0);
+GLAPI void APIENTRY glProgramUniform2uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1);
+GLAPI void APIENTRY glProgramUniform3uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2);
+GLAPI void APIENTRY glProgramUniform4uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+GLAPI void APIENTRY glProgramUniform1uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glProgramUniform2uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glProgramUniform3uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glProgramUniform4uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glNamedProgramLocalParameters4fvEXT (GLuint program, GLenum target, GLuint index, GLsizei count, const GLfloat *params);
+GLAPI void APIENTRY glNamedProgramLocalParameterI4iEXT (GLuint program, GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w);
+GLAPI void APIENTRY glNamedProgramLocalParameterI4ivEXT (GLuint program, GLenum target, GLuint index, const GLint *params);
+GLAPI void APIENTRY glNamedProgramLocalParametersI4ivEXT (GLuint program, GLenum target, GLuint index, GLsizei count, const GLint *params);
+GLAPI void APIENTRY glNamedProgramLocalParameterI4uiEXT (GLuint program, GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+GLAPI void APIENTRY glNamedProgramLocalParameterI4uivEXT (GLuint program, GLenum target, GLuint index, const GLuint *params);
+GLAPI void APIENTRY glNamedProgramLocalParametersI4uivEXT (GLuint program, GLenum target, GLuint index, GLsizei count, const GLuint *params);
+GLAPI void APIENTRY glGetNamedProgramLocalParameterIivEXT (GLuint program, GLenum target, GLuint index, GLint *params);
+GLAPI void APIENTRY glGetNamedProgramLocalParameterIuivEXT (GLuint program, GLenum target, GLuint index, GLuint *params);
+GLAPI void APIENTRY glEnableClientStateiEXT (GLenum array, GLuint index);
+GLAPI void APIENTRY glDisableClientStateiEXT (GLenum array, GLuint index);
+GLAPI void APIENTRY glGetFloati_vEXT (GLenum pname, GLuint index, GLfloat *params);
+GLAPI void APIENTRY glGetDoublei_vEXT (GLenum pname, GLuint index, GLdouble *params);
+GLAPI void APIENTRY glGetPointeri_vEXT (GLenum pname, GLuint index, void **params);
+GLAPI void APIENTRY glNamedProgramStringEXT (GLuint program, GLenum target, GLenum format, GLsizei len, const void *string);
+GLAPI void APIENTRY glNamedProgramLocalParameter4dEXT (GLuint program, GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glNamedProgramLocalParameter4dvEXT (GLuint program, GLenum target, GLuint index, const GLdouble *params);
+GLAPI void APIENTRY glNamedProgramLocalParameter4fEXT (GLuint program, GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glNamedProgramLocalParameter4fvEXT (GLuint program, GLenum target, GLuint index, const GLfloat *params);
+GLAPI void APIENTRY glGetNamedProgramLocalParameterdvEXT (GLuint program, GLenum target, GLuint index, GLdouble *params);
+GLAPI void APIENTRY glGetNamedProgramLocalParameterfvEXT (GLuint program, GLenum target, GLuint index, GLfloat *params);
+GLAPI void APIENTRY glGetNamedProgramivEXT (GLuint program, GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetNamedProgramStringEXT (GLuint program, GLenum target, GLenum pname, void *string);
+GLAPI void APIENTRY glNamedRenderbufferStorageEXT (GLuint renderbuffer, GLenum internalformat, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glGetNamedRenderbufferParameterivEXT (GLuint renderbuffer, GLenum pname, GLint *params);
+GLAPI void APIENTRY glNamedRenderbufferStorageMultisampleEXT (GLuint renderbuffer, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glNamedRenderbufferStorageMultisampleCoverageEXT (GLuint renderbuffer, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height);
+GLAPI GLenum APIENTRY glCheckNamedFramebufferStatusEXT (GLuint framebuffer, GLenum target);
+GLAPI void APIENTRY glNamedFramebufferTexture1DEXT (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+GLAPI void APIENTRY glNamedFramebufferTexture2DEXT (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+GLAPI void APIENTRY glNamedFramebufferTexture3DEXT (GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+GLAPI void APIENTRY glNamedFramebufferRenderbufferEXT (GLuint framebuffer, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
+GLAPI void APIENTRY glGetNamedFramebufferAttachmentParameterivEXT (GLuint framebuffer, GLenum attachment, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGenerateTextureMipmapEXT (GLuint texture, GLenum target);
+GLAPI void APIENTRY glGenerateMultiTexMipmapEXT (GLenum texunit, GLenum target);
+GLAPI void APIENTRY glFramebufferDrawBufferEXT (GLuint framebuffer, GLenum mode);
+GLAPI void APIENTRY glFramebufferDrawBuffersEXT (GLuint framebuffer, GLsizei n, const GLenum *bufs);
+GLAPI void APIENTRY glFramebufferReadBufferEXT (GLuint framebuffer, GLenum mode);
+GLAPI void APIENTRY glGetFramebufferParameterivEXT (GLuint framebuffer, GLenum pname, GLint *params);
+GLAPI void APIENTRY glNamedCopyBufferSubDataEXT (GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
+GLAPI void APIENTRY glNamedFramebufferTextureEXT (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level);
+GLAPI void APIENTRY glNamedFramebufferTextureLayerEXT (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLint layer);
+GLAPI void APIENTRY glNamedFramebufferTextureFaceEXT (GLuint framebuffer, GLenum attachment, GLuint texture, GLint level, GLenum face);
+GLAPI void APIENTRY glTextureRenderbufferEXT (GLuint texture, GLenum target, GLuint renderbuffer);
+GLAPI void APIENTRY glMultiTexRenderbufferEXT (GLenum texunit, GLenum target, GLuint renderbuffer);
+GLAPI void APIENTRY glVertexArrayVertexOffsetEXT (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArrayColorOffsetEXT (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArrayEdgeFlagOffsetEXT (GLuint vaobj, GLuint buffer, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArrayIndexOffsetEXT (GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArrayNormalOffsetEXT (GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArrayTexCoordOffsetEXT (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArrayMultiTexCoordOffsetEXT (GLuint vaobj, GLuint buffer, GLenum texunit, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArrayFogCoordOffsetEXT (GLuint vaobj, GLuint buffer, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArraySecondaryColorOffsetEXT (GLuint vaobj, GLuint buffer, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArrayVertexAttribOffsetEXT (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glVertexArrayVertexAttribIOffsetEXT (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glEnableVertexArrayEXT (GLuint vaobj, GLenum array);
+GLAPI void APIENTRY glDisableVertexArrayEXT (GLuint vaobj, GLenum array);
+GLAPI void APIENTRY glEnableVertexArrayAttribEXT (GLuint vaobj, GLuint index);
+GLAPI void APIENTRY glDisableVertexArrayAttribEXT (GLuint vaobj, GLuint index);
+GLAPI void APIENTRY glGetVertexArrayIntegervEXT (GLuint vaobj, GLenum pname, GLint *param);
+GLAPI void APIENTRY glGetVertexArrayPointervEXT (GLuint vaobj, GLenum pname, void **param);
+GLAPI void APIENTRY glGetVertexArrayIntegeri_vEXT (GLuint vaobj, GLuint index, GLenum pname, GLint *param);
+GLAPI void APIENTRY glGetVertexArrayPointeri_vEXT (GLuint vaobj, GLuint index, GLenum pname, void **param);
+GLAPI void *APIENTRY glMapNamedBufferRangeEXT (GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access);
+GLAPI void APIENTRY glFlushMappedNamedBufferRangeEXT (GLuint buffer, GLintptr offset, GLsizeiptr length);
+GLAPI void APIENTRY glNamedBufferStorageEXT (GLuint buffer, GLsizeiptr size, const void *data, GLbitfield flags);
+GLAPI void APIENTRY glClearNamedBufferDataEXT (GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data);
+GLAPI void APIENTRY glClearNamedBufferSubDataEXT (GLuint buffer, GLenum internalformat, GLsizeiptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data);
+GLAPI void APIENTRY glNamedFramebufferParameteriEXT (GLuint framebuffer, GLenum pname, GLint param);
+GLAPI void APIENTRY glGetNamedFramebufferParameterivEXT (GLuint framebuffer, GLenum pname, GLint *params);
+GLAPI void APIENTRY glProgramUniform1dEXT (GLuint program, GLint location, GLdouble x);
+GLAPI void APIENTRY glProgramUniform2dEXT (GLuint program, GLint location, GLdouble x, GLdouble y);
+GLAPI void APIENTRY glProgramUniform3dEXT (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glProgramUniform4dEXT (GLuint program, GLint location, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glProgramUniform1dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniform2dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniform3dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniform4dvEXT (GLuint program, GLint location, GLsizei count, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix2dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix3dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix4dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix2x3dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix2x4dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix3x2dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix3x4dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix4x2dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glProgramUniformMatrix4x3dvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLdouble *value);
+GLAPI void APIENTRY glTextureBufferRangeEXT (GLuint texture, GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size);
+GLAPI void APIENTRY glTextureStorage1DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+GLAPI void APIENTRY glTextureStorage2DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glTextureStorage3DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+GLAPI void APIENTRY glTextureStorage2DMultisampleEXT (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
+GLAPI void APIENTRY glTextureStorage3DMultisampleEXT (GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations);
+GLAPI void APIENTRY glVertexArrayBindVertexBufferEXT (GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride);
+GLAPI void APIENTRY glVertexArrayVertexAttribFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset);
+GLAPI void APIENTRY glVertexArrayVertexAttribIFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
+GLAPI void APIENTRY glVertexArrayVertexAttribLFormatEXT (GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset);
+GLAPI void APIENTRY glVertexArrayVertexAttribBindingEXT (GLuint vaobj, GLuint attribindex, GLuint bindingindex);
+GLAPI void APIENTRY glVertexArrayVertexBindingDivisorEXT (GLuint vaobj, GLuint bindingindex, GLuint divisor);
+GLAPI void APIENTRY glVertexArrayVertexAttribLOffsetEXT (GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset);
+GLAPI void APIENTRY glTexturePageCommitmentEXT (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLboolean resident);
+GLAPI void APIENTRY glVertexArrayVertexAttribDivisorEXT (GLuint vaobj, GLuint index, GLuint divisor);
+#endif
+#endif /* GL_EXT_direct_state_access */
+
+#ifndef GL_EXT_draw_buffers2
+#define GL_EXT_draw_buffers2 1
+typedef void (APIENTRYP PFNGLCOLORMASKINDEXEDEXTPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glColorMaskIndexedEXT (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a);
+#endif
+#endif /* GL_EXT_draw_buffers2 */
+
+#ifndef GL_EXT_draw_instanced
+#define GL_EXT_draw_instanced 1
+typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDEXTPROC) (GLenum mode, GLint start, GLsizei count, GLsizei primcount);
+typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDEXTPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawArraysInstancedEXT (GLenum mode, GLint start, GLsizei count, GLsizei primcount);
+GLAPI void APIENTRY glDrawElementsInstancedEXT (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
+#endif
+#endif /* GL_EXT_draw_instanced */
+
+#ifndef GL_EXT_draw_range_elements
+#define GL_EXT_draw_range_elements 1
+#define GL_MAX_ELEMENTS_VERTICES_EXT 0x80E8
+#define GL_MAX_ELEMENTS_INDICES_EXT 0x80E9
+typedef void (APIENTRYP PFNGLDRAWRANGEELEMENTSEXTPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawRangeElementsEXT (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices);
+#endif
+#endif /* GL_EXT_draw_range_elements */
+
+#ifndef GL_EXT_fog_coord
+#define GL_EXT_fog_coord 1
+#define GL_FOG_COORDINATE_SOURCE_EXT 0x8450
+#define GL_FOG_COORDINATE_EXT 0x8451
+#define GL_FRAGMENT_DEPTH_EXT 0x8452
+#define GL_CURRENT_FOG_COORDINATE_EXT 0x8453
+#define GL_FOG_COORDINATE_ARRAY_TYPE_EXT 0x8454
+#define GL_FOG_COORDINATE_ARRAY_STRIDE_EXT 0x8455
+#define GL_FOG_COORDINATE_ARRAY_POINTER_EXT 0x8456
+#define GL_FOG_COORDINATE_ARRAY_EXT 0x8457
+typedef void (APIENTRYP PFNGLFOGCOORDFEXTPROC) (GLfloat coord);
+typedef void (APIENTRYP PFNGLFOGCOORDFVEXTPROC) (const GLfloat *coord);
+typedef void (APIENTRYP PFNGLFOGCOORDDEXTPROC) (GLdouble coord);
+typedef void (APIENTRYP PFNGLFOGCOORDDVEXTPROC) (const GLdouble *coord);
+typedef void (APIENTRYP PFNGLFOGCOORDPOINTEREXTPROC) (GLenum type, GLsizei stride, const void *pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glFogCoordfEXT (GLfloat coord);
+GLAPI void APIENTRY glFogCoordfvEXT (const GLfloat *coord);
+GLAPI void APIENTRY glFogCoorddEXT (GLdouble coord);
+GLAPI void APIENTRY glFogCoorddvEXT (const GLdouble *coord);
+GLAPI void APIENTRY glFogCoordPointerEXT (GLenum type, GLsizei stride, const void *pointer);
+#endif
+#endif /* GL_EXT_fog_coord */
+
+#ifndef GL_EXT_framebuffer_blit
+#define GL_EXT_framebuffer_blit 1
+#define GL_READ_FRAMEBUFFER_EXT 0x8CA8
+#define GL_DRAW_FRAMEBUFFER_EXT 0x8CA9
+#define GL_DRAW_FRAMEBUFFER_BINDING_EXT 0x8CA6
+#define GL_READ_FRAMEBUFFER_BINDING_EXT 0x8CAA
+typedef void (APIENTRYP PFNGLBLITFRAMEBUFFEREXTPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlitFramebufferEXT (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+#endif
+#endif /* GL_EXT_framebuffer_blit */
+
+#ifndef GL_EXT_framebuffer_multisample
+#define GL_EXT_framebuffer_multisample 1
+#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56
+#define GL_MAX_SAMPLES_EXT 0x8D57
+typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glRenderbufferStorageMultisampleEXT (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+#endif
+#endif /* GL_EXT_framebuffer_multisample */
+
+#ifndef GL_EXT_framebuffer_multisample_blit_scaled
+#define GL_EXT_framebuffer_multisample_blit_scaled 1
+#define GL_SCALED_RESOLVE_FASTEST_EXT 0x90BA
+#define GL_SCALED_RESOLVE_NICEST_EXT 0x90BB
+#endif /* GL_EXT_framebuffer_multisample_blit_scaled */
+
+#ifndef GL_EXT_framebuffer_object
+#define GL_EXT_framebuffer_object 1
+#define GL_INVALID_FRAMEBUFFER_OPERATION_EXT 0x0506
+#define GL_MAX_RENDERBUFFER_SIZE_EXT 0x84E8
+#define GL_FRAMEBUFFER_BINDING_EXT 0x8CA6
+#define GL_RENDERBUFFER_BINDING_EXT 0x8CA7
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT 0x8CD0
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_EXT 0x8CD1
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_EXT 0x8CD2
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE_EXT 0x8CD3
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT 0x8CD4
+#define GL_FRAMEBUFFER_COMPLETE_EXT 0x8CD5
+#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT 0x8CD6
+#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT 0x8CD7
+#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT 0x8CD9
+#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT 0x8CDA
+#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT 0x8CDB
+#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT 0x8CDC
+#define GL_FRAMEBUFFER_UNSUPPORTED_EXT 0x8CDD
+#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF
+#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
+#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1
+#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2
+#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3
+#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4
+#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5
+#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6
+#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7
+#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8
+#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9
+#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA
+#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB
+#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC
+#define GL_COLOR_ATTACHMENT13_EXT 0x8CED
+#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE
+#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF
+#define GL_DEPTH_ATTACHMENT_EXT 0x8D00
+#define GL_STENCIL_ATTACHMENT_EXT 0x8D20
+#define GL_FRAMEBUFFER_EXT 0x8D40
+#define GL_RENDERBUFFER_EXT 0x8D41
+#define GL_RENDERBUFFER_WIDTH_EXT 0x8D42
+#define GL_RENDERBUFFER_HEIGHT_EXT 0x8D43
+#define GL_RENDERBUFFER_INTERNAL_FORMAT_EXT 0x8D44
+#define GL_STENCIL_INDEX1_EXT 0x8D46
+#define GL_STENCIL_INDEX4_EXT 0x8D47
+#define GL_STENCIL_INDEX8_EXT 0x8D48
+#define GL_STENCIL_INDEX16_EXT 0x8D49
+#define GL_RENDERBUFFER_RED_SIZE_EXT 0x8D50
+#define GL_RENDERBUFFER_GREEN_SIZE_EXT 0x8D51
+#define GL_RENDERBUFFER_BLUE_SIZE_EXT 0x8D52
+#define GL_RENDERBUFFER_ALPHA_SIZE_EXT 0x8D53
+#define GL_RENDERBUFFER_DEPTH_SIZE_EXT 0x8D54
+#define GL_RENDERBUFFER_STENCIL_SIZE_EXT 0x8D55
+typedef GLboolean (APIENTRYP PFNGLISRENDERBUFFEREXTPROC) (GLuint renderbuffer);
+typedef void (APIENTRYP PFNGLBINDRENDERBUFFEREXTPROC) (GLenum target, GLuint renderbuffer);
+typedef void (APIENTRYP PFNGLDELETERENDERBUFFERSEXTPROC) (GLsizei n, const GLuint *renderbuffers);
+typedef void (APIENTRYP PFNGLGENRENDERBUFFERSEXTPROC) (GLsizei n, GLuint *renderbuffers);
+typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEEXTPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params);
+typedef GLboolean (APIENTRYP PFNGLISFRAMEBUFFEREXTPROC) (GLuint framebuffer);
+typedef void (APIENTRYP PFNGLBINDFRAMEBUFFEREXTPROC) (GLenum target, GLuint framebuffer);
+typedef void (APIENTRYP PFNGLDELETEFRAMEBUFFERSEXTPROC) (GLsizei n, const GLuint *framebuffers);
+typedef void (APIENTRYP PFNGLGENFRAMEBUFFERSEXTPROC) (GLsizei n, GLuint *framebuffers);
+typedef GLenum (APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
+typedef void (APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGENERATEMIPMAPEXTPROC) (GLenum target);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLboolean APIENTRY glIsRenderbufferEXT (GLuint renderbuffer);
+GLAPI void APIENTRY glBindRenderbufferEXT (GLenum target, GLuint renderbuffer);
+GLAPI void APIENTRY glDeleteRenderbuffersEXT (GLsizei n, const GLuint *renderbuffers);
+GLAPI void APIENTRY glGenRenderbuffersEXT (GLsizei n, GLuint *renderbuffers);
+GLAPI void APIENTRY glRenderbufferStorageEXT (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
+GLAPI void APIENTRY glGetRenderbufferParameterivEXT (GLenum target, GLenum pname, GLint *params);
+GLAPI GLboolean APIENTRY glIsFramebufferEXT (GLuint framebuffer);
+GLAPI void APIENTRY glBindFramebufferEXT (GLenum target, GLuint framebuffer);
+GLAPI void APIENTRY glDeleteFramebuffersEXT (GLsizei n, const GLuint *framebuffers);
+GLAPI void APIENTRY glGenFramebuffersEXT (GLsizei n, GLuint *framebuffers);
+GLAPI GLenum APIENTRY glCheckFramebufferStatusEXT (GLenum target);
+GLAPI void APIENTRY glFramebufferTexture1DEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+GLAPI void APIENTRY glFramebufferTexture2DEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+GLAPI void APIENTRY glFramebufferTexture3DEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+GLAPI void APIENTRY glFramebufferRenderbufferEXT (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
+GLAPI void APIENTRY glGetFramebufferAttachmentParameterivEXT (GLenum target, GLenum attachment, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGenerateMipmapEXT (GLenum target);
+#endif
+#endif /* GL_EXT_framebuffer_object */
+
+#ifndef GL_EXT_framebuffer_sRGB
+#define GL_EXT_framebuffer_sRGB 1
+#define GL_FRAMEBUFFER_SRGB_EXT 0x8DB9
+#define GL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x8DBA
+#endif /* GL_EXT_framebuffer_sRGB */
+
+#ifndef GL_EXT_geometry_shader4
+#define GL_EXT_geometry_shader4 1
+#define GL_GEOMETRY_SHADER_EXT 0x8DD9
+#define GL_GEOMETRY_VERTICES_OUT_EXT 0x8DDA
+#define GL_GEOMETRY_INPUT_TYPE_EXT 0x8DDB
+#define GL_GEOMETRY_OUTPUT_TYPE_EXT 0x8DDC
+#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT 0x8C29
+#define GL_MAX_GEOMETRY_VARYING_COMPONENTS_EXT 0x8DDD
+#define GL_MAX_VERTEX_VARYING_COMPONENTS_EXT 0x8DDE
+#define GL_MAX_VARYING_COMPONENTS_EXT 0x8B4B
+#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT 0x8DDF
+#define GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT 0x8DE0
+#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT 0x8DE1
+#define GL_LINES_ADJACENCY_EXT 0x000A
+#define GL_LINE_STRIP_ADJACENCY_EXT 0x000B
+#define GL_TRIANGLES_ADJACENCY_EXT 0x000C
+#define GL_TRIANGLE_STRIP_ADJACENCY_EXT 0x000D
+#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT 0x8DA8
+#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_EXT 0x8DA9
+#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT 0x8DA7
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER_EXT 0x8CD4
+#define GL_PROGRAM_POINT_SIZE_EXT 0x8642
+typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIEXTPROC) (GLuint program, GLenum pname, GLint value);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProgramParameteriEXT (GLuint program, GLenum pname, GLint value);
+#endif
+#endif /* GL_EXT_geometry_shader4 */
+
+#ifndef GL_EXT_gpu_program_parameters
+#define GL_EXT_gpu_program_parameters 1
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERS4FVEXTPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *params);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERS4FVEXTPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProgramEnvParameters4fvEXT (GLenum target, GLuint index, GLsizei count, const GLfloat *params);
+GLAPI void APIENTRY glProgramLocalParameters4fvEXT (GLenum target, GLuint index, GLsizei count, const GLfloat *params);
+#endif
+#endif /* GL_EXT_gpu_program_parameters */
+
+#ifndef GL_EXT_gpu_shader4
+#define GL_EXT_gpu_shader4 1
+#define GL_VERTEX_ATTRIB_ARRAY_INTEGER_EXT 0x88FD
+#define GL_SAMPLER_1D_ARRAY_EXT 0x8DC0
+#define GL_SAMPLER_2D_ARRAY_EXT 0x8DC1
+#define GL_SAMPLER_BUFFER_EXT 0x8DC2
+#define GL_SAMPLER_1D_ARRAY_SHADOW_EXT 0x8DC3
+#define GL_SAMPLER_2D_ARRAY_SHADOW_EXT 0x8DC4
+#define GL_SAMPLER_CUBE_SHADOW_EXT 0x8DC5
+#define GL_UNSIGNED_INT_VEC2_EXT 0x8DC6
+#define GL_UNSIGNED_INT_VEC3_EXT 0x8DC7
+#define GL_UNSIGNED_INT_VEC4_EXT 0x8DC8
+#define GL_INT_SAMPLER_1D_EXT 0x8DC9
+#define GL_INT_SAMPLER_2D_EXT 0x8DCA
+#define GL_INT_SAMPLER_3D_EXT 0x8DCB
+#define GL_INT_SAMPLER_CUBE_EXT 0x8DCC
+#define GL_INT_SAMPLER_2D_RECT_EXT 0x8DCD
+#define GL_INT_SAMPLER_1D_ARRAY_EXT 0x8DCE
+#define GL_INT_SAMPLER_2D_ARRAY_EXT 0x8DCF
+#define GL_INT_SAMPLER_BUFFER_EXT 0x8DD0
+#define GL_UNSIGNED_INT_SAMPLER_1D_EXT 0x8DD1
+#define GL_UNSIGNED_INT_SAMPLER_2D_EXT 0x8DD2
+#define GL_UNSIGNED_INT_SAMPLER_3D_EXT 0x8DD3
+#define GL_UNSIGNED_INT_SAMPLER_CUBE_EXT 0x8DD4
+#define GL_UNSIGNED_INT_SAMPLER_2D_RECT_EXT 0x8DD5
+#define GL_UNSIGNED_INT_SAMPLER_1D_ARRAY_EXT 0x8DD6
+#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY_EXT 0x8DD7
+#define GL_UNSIGNED_INT_SAMPLER_BUFFER_EXT 0x8DD8
+#define GL_MIN_PROGRAM_TEXEL_OFFSET_EXT 0x8904
+#define GL_MAX_PROGRAM_TEXEL_OFFSET_EXT 0x8905
+typedef void (APIENTRYP PFNGLGETUNIFORMUIVEXTPROC) (GLuint program, GLint location, GLuint *params);
+typedef void (APIENTRYP PFNGLBINDFRAGDATALOCATIONEXTPROC) (GLuint program, GLuint color, const GLchar *name);
+typedef GLint (APIENTRYP PFNGLGETFRAGDATALOCATIONEXTPROC) (GLuint program, const GLchar *name);
+typedef void (APIENTRYP PFNGLUNIFORM1UIEXTPROC) (GLint location, GLuint v0);
+typedef void (APIENTRYP PFNGLUNIFORM2UIEXTPROC) (GLint location, GLuint v0, GLuint v1);
+typedef void (APIENTRYP PFNGLUNIFORM3UIEXTPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2);
+typedef void (APIENTRYP PFNGLUNIFORM4UIEXTPROC) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+typedef void (APIENTRYP PFNGLUNIFORM1UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLUNIFORM2UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLUNIFORM3UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value);
+typedef void (APIENTRYP PFNGLUNIFORM4UIVEXTPROC) (GLint location, GLsizei count, const GLuint *value);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGetUniformuivEXT (GLuint program, GLint location, GLuint *params);
+GLAPI void APIENTRY glBindFragDataLocationEXT (GLuint program, GLuint color, const GLchar *name);
+GLAPI GLint APIENTRY glGetFragDataLocationEXT (GLuint program, const GLchar *name);
+GLAPI void APIENTRY glUniform1uiEXT (GLint location, GLuint v0);
+GLAPI void APIENTRY glUniform2uiEXT (GLint location, GLuint v0, GLuint v1);
+GLAPI void APIENTRY glUniform3uiEXT (GLint location, GLuint v0, GLuint v1, GLuint v2);
+GLAPI void APIENTRY glUniform4uiEXT (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+GLAPI void APIENTRY glUniform1uivEXT (GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glUniform2uivEXT (GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glUniform3uivEXT (GLint location, GLsizei count, const GLuint *value);
+GLAPI void APIENTRY glUniform4uivEXT (GLint location, GLsizei count, const GLuint *value);
+#endif
+#endif /* GL_EXT_gpu_shader4 */
+
+#ifndef GL_EXT_histogram
+#define GL_EXT_histogram 1
+#define GL_HISTOGRAM_EXT 0x8024
+#define GL_PROXY_HISTOGRAM_EXT 0x8025
+#define GL_HISTOGRAM_WIDTH_EXT 0x8026
+#define GL_HISTOGRAM_FORMAT_EXT 0x8027
+#define GL_HISTOGRAM_RED_SIZE_EXT 0x8028
+#define GL_HISTOGRAM_GREEN_SIZE_EXT 0x8029
+#define GL_HISTOGRAM_BLUE_SIZE_EXT 0x802A
+#define GL_HISTOGRAM_ALPHA_SIZE_EXT 0x802B
+#define GL_HISTOGRAM_LUMINANCE_SIZE_EXT 0x802C
+#define GL_HISTOGRAM_SINK_EXT 0x802D
+#define GL_MINMAX_EXT 0x802E
+#define GL_MINMAX_FORMAT_EXT 0x802F
+#define GL_MINMAX_SINK_EXT 0x8030
+#define GL_TABLE_TOO_LARGE_EXT 0x8031
+typedef void (APIENTRYP PFNGLGETHISTOGRAMEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values);
+typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETHISTOGRAMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETMINMAXEXTPROC) (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values);
+typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETMINMAXPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLHISTOGRAMEXTPROC) (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink);
+typedef void (APIENTRYP PFNGLMINMAXEXTPROC) (GLenum target, GLenum internalformat, GLboolean sink);
+typedef void (APIENTRYP PFNGLRESETHISTOGRAMEXTPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLRESETMINMAXEXTPROC) (GLenum target);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGetHistogramEXT (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values);
+GLAPI void APIENTRY glGetHistogramParameterfvEXT (GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetHistogramParameterivEXT (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetMinmaxEXT (GLenum target, GLboolean reset, GLenum format, GLenum type, void *values);
+GLAPI void APIENTRY glGetMinmaxParameterfvEXT (GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetMinmaxParameterivEXT (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glHistogramEXT (GLenum target, GLsizei width, GLenum internalformat, GLboolean sink);
+GLAPI void APIENTRY glMinmaxEXT (GLenum target, GLenum internalformat, GLboolean sink);
+GLAPI void APIENTRY glResetHistogramEXT (GLenum target);
+GLAPI void APIENTRY glResetMinmaxEXT (GLenum target);
+#endif
+#endif /* GL_EXT_histogram */
+
+#ifndef GL_EXT_index_array_formats
+#define GL_EXT_index_array_formats 1
+#define GL_IUI_V2F_EXT 0x81AD
+#define GL_IUI_V3F_EXT 0x81AE
+#define GL_IUI_N3F_V2F_EXT 0x81AF
+#define GL_IUI_N3F_V3F_EXT 0x81B0
+#define GL_T2F_IUI_V2F_EXT 0x81B1
+#define GL_T2F_IUI_V3F_EXT 0x81B2
+#define GL_T2F_IUI_N3F_V2F_EXT 0x81B3
+#define GL_T2F_IUI_N3F_V3F_EXT 0x81B4
+#endif /* GL_EXT_index_array_formats */
+
+#ifndef GL_EXT_index_func
+#define GL_EXT_index_func 1
+#define GL_INDEX_TEST_EXT 0x81B5
+#define GL_INDEX_TEST_FUNC_EXT 0x81B6
+#define GL_INDEX_TEST_REF_EXT 0x81B7
+typedef void (APIENTRYP PFNGLINDEXFUNCEXTPROC) (GLenum func, GLclampf ref);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glIndexFuncEXT (GLenum func, GLclampf ref);
+#endif
+#endif /* GL_EXT_index_func */
+
+#ifndef GL_EXT_index_material
+#define GL_EXT_index_material 1
+#define GL_INDEX_MATERIAL_EXT 0x81B8
+#define GL_INDEX_MATERIAL_PARAMETER_EXT 0x81B9
+#define GL_INDEX_MATERIAL_FACE_EXT 0x81BA
+typedef void (APIENTRYP PFNGLINDEXMATERIALEXTPROC) (GLenum face, GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glIndexMaterialEXT (GLenum face, GLenum mode);
+#endif
+#endif /* GL_EXT_index_material */
+
+#ifndef GL_EXT_index_texture
+#define GL_EXT_index_texture 1
+#endif /* GL_EXT_index_texture */
+
+#ifndef GL_EXT_light_texture
+#define GL_EXT_light_texture 1
+#define GL_FRAGMENT_MATERIAL_EXT 0x8349
+#define GL_FRAGMENT_NORMAL_EXT 0x834A
+#define GL_FRAGMENT_COLOR_EXT 0x834C
+#define GL_ATTENUATION_EXT 0x834D
+#define GL_SHADOW_ATTENUATION_EXT 0x834E
+#define GL_TEXTURE_APPLICATION_MODE_EXT 0x834F
+#define GL_TEXTURE_LIGHT_EXT 0x8350
+#define GL_TEXTURE_MATERIAL_FACE_EXT 0x8351
+#define GL_TEXTURE_MATERIAL_PARAMETER_EXT 0x8352
+typedef void (APIENTRYP PFNGLAPPLYTEXTUREEXTPROC) (GLenum mode);
+typedef void (APIENTRYP PFNGLTEXTURELIGHTEXTPROC) (GLenum pname);
+typedef void (APIENTRYP PFNGLTEXTUREMATERIALEXTPROC) (GLenum face, GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glApplyTextureEXT (GLenum mode);
+GLAPI void APIENTRY glTextureLightEXT (GLenum pname);
+GLAPI void APIENTRY glTextureMaterialEXT (GLenum face, GLenum mode);
+#endif
+#endif /* GL_EXT_light_texture */
+
+#ifndef GL_EXT_misc_attribute
+#define GL_EXT_misc_attribute 1
+#endif /* GL_EXT_misc_attribute */
+
+#ifndef GL_EXT_multi_draw_arrays
+#define GL_EXT_multi_draw_arrays 1
+typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount);
+typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei primcount);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMultiDrawArraysEXT (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount);
+GLAPI void APIENTRY glMultiDrawElementsEXT (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei primcount);
+#endif
+#endif /* GL_EXT_multi_draw_arrays */
+
+#ifndef GL_EXT_multisample
+#define GL_EXT_multisample 1
+#define GL_MULTISAMPLE_EXT 0x809D
+#define GL_SAMPLE_ALPHA_TO_MASK_EXT 0x809E
+#define GL_SAMPLE_ALPHA_TO_ONE_EXT 0x809F
+#define GL_SAMPLE_MASK_EXT 0x80A0
+#define GL_1PASS_EXT 0x80A1
+#define GL_2PASS_0_EXT 0x80A2
+#define GL_2PASS_1_EXT 0x80A3
+#define GL_4PASS_0_EXT 0x80A4
+#define GL_4PASS_1_EXT 0x80A5
+#define GL_4PASS_2_EXT 0x80A6
+#define GL_4PASS_3_EXT 0x80A7
+#define GL_SAMPLE_BUFFERS_EXT 0x80A8
+#define GL_SAMPLES_EXT 0x80A9
+#define GL_SAMPLE_MASK_VALUE_EXT 0x80AA
+#define GL_SAMPLE_MASK_INVERT_EXT 0x80AB
+#define GL_SAMPLE_PATTERN_EXT 0x80AC
+#define GL_MULTISAMPLE_BIT_EXT 0x20000000
+typedef void (APIENTRYP PFNGLSAMPLEMASKEXTPROC) (GLclampf value, GLboolean invert);
+typedef void (APIENTRYP PFNGLSAMPLEPATTERNEXTPROC) (GLenum pattern);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glSampleMaskEXT (GLclampf value, GLboolean invert);
+GLAPI void APIENTRY glSamplePatternEXT (GLenum pattern);
+#endif
+#endif /* GL_EXT_multisample */
+
+#ifndef GL_EXT_packed_depth_stencil
+#define GL_EXT_packed_depth_stencil 1
+#define GL_DEPTH_STENCIL_EXT 0x84F9
+#define GL_UNSIGNED_INT_24_8_EXT 0x84FA
+#define GL_DEPTH24_STENCIL8_EXT 0x88F0
+#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1
+#endif /* GL_EXT_packed_depth_stencil */
+
+#ifndef GL_EXT_packed_float
+#define GL_EXT_packed_float 1
+#define GL_R11F_G11F_B10F_EXT 0x8C3A
+#define GL_UNSIGNED_INT_10F_11F_11F_REV_EXT 0x8C3B
+#define GL_RGBA_SIGNED_COMPONENTS_EXT 0x8C3C
+#endif /* GL_EXT_packed_float */
+
+#ifndef GL_EXT_packed_pixels
+#define GL_EXT_packed_pixels 1
+#define GL_UNSIGNED_BYTE_3_3_2_EXT 0x8032
+#define GL_UNSIGNED_SHORT_4_4_4_4_EXT 0x8033
+#define GL_UNSIGNED_SHORT_5_5_5_1_EXT 0x8034
+#define GL_UNSIGNED_INT_8_8_8_8_EXT 0x8035
+#define GL_UNSIGNED_INT_10_10_10_2_EXT 0x8036
+#endif /* GL_EXT_packed_pixels */
+
+#ifndef GL_EXT_paletted_texture
+#define GL_EXT_paletted_texture 1
+#define GL_COLOR_INDEX1_EXT 0x80E2
+#define GL_COLOR_INDEX2_EXT 0x80E3
+#define GL_COLOR_INDEX4_EXT 0x80E4
+#define GL_COLOR_INDEX8_EXT 0x80E5
+#define GL_COLOR_INDEX12_EXT 0x80E6
+#define GL_COLOR_INDEX16_EXT 0x80E7
+#define GL_TEXTURE_INDEX_SIZE_EXT 0x80ED
+typedef void (APIENTRYP PFNGLCOLORTABLEEXTPROC) (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const void *table);
+typedef void (APIENTRYP PFNGLGETCOLORTABLEEXTPROC) (GLenum target, GLenum format, GLenum type, void *data);
+typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glColorTableEXT (GLenum target, GLenum internalFormat, GLsizei width, GLenum format, GLenum type, const void *table);
+GLAPI void APIENTRY glGetColorTableEXT (GLenum target, GLenum format, GLenum type, void *data);
+GLAPI void APIENTRY glGetColorTableParameterivEXT (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetColorTableParameterfvEXT (GLenum target, GLenum pname, GLfloat *params);
+#endif
+#endif /* GL_EXT_paletted_texture */
+
+#ifndef GL_EXT_pixel_buffer_object
+#define GL_EXT_pixel_buffer_object 1
+#define GL_PIXEL_PACK_BUFFER_EXT 0x88EB
+#define GL_PIXEL_UNPACK_BUFFER_EXT 0x88EC
+#define GL_PIXEL_PACK_BUFFER_BINDING_EXT 0x88ED
+#define GL_PIXEL_UNPACK_BUFFER_BINDING_EXT 0x88EF
+#endif /* GL_EXT_pixel_buffer_object */
+
+#ifndef GL_EXT_pixel_transform
+#define GL_EXT_pixel_transform 1
+#define GL_PIXEL_TRANSFORM_2D_EXT 0x8330
+#define GL_PIXEL_MAG_FILTER_EXT 0x8331
+#define GL_PIXEL_MIN_FILTER_EXT 0x8332
+#define GL_PIXEL_CUBIC_WEIGHT_EXT 0x8333
+#define GL_CUBIC_EXT 0x8334
+#define GL_AVERAGE_EXT 0x8335
+#define GL_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8336
+#define GL_MAX_PIXEL_TRANSFORM_2D_STACK_DEPTH_EXT 0x8337
+#define GL_PIXEL_TRANSFORM_2D_MATRIX_EXT 0x8338
+typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIEXTPROC) (GLenum target, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFEXTPROC) (GLenum target, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLPIXELTRANSFORMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLGETPIXELTRANSFORMPARAMETERIVEXTPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETPIXELTRANSFORMPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPixelTransformParameteriEXT (GLenum target, GLenum pname, GLint param);
+GLAPI void APIENTRY glPixelTransformParameterfEXT (GLenum target, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glPixelTransformParameterivEXT (GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glPixelTransformParameterfvEXT (GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glGetPixelTransformParameterivEXT (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetPixelTransformParameterfvEXT (GLenum target, GLenum pname, GLfloat *params);
+#endif
+#endif /* GL_EXT_pixel_transform */
+
+#ifndef GL_EXT_pixel_transform_color_table
+#define GL_EXT_pixel_transform_color_table 1
+#endif /* GL_EXT_pixel_transform_color_table */
+
+#ifndef GL_EXT_point_parameters
+#define GL_EXT_point_parameters 1
+#define GL_POINT_SIZE_MIN_EXT 0x8126
+#define GL_POINT_SIZE_MAX_EXT 0x8127
+#define GL_POINT_FADE_THRESHOLD_SIZE_EXT 0x8128
+#define GL_DISTANCE_ATTENUATION_EXT 0x8129
+typedef void (APIENTRYP PFNGLPOINTPARAMETERFEXTPROC) (GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLPOINTPARAMETERFVEXTPROC) (GLenum pname, const GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPointParameterfEXT (GLenum pname, GLfloat param);
+GLAPI void APIENTRY glPointParameterfvEXT (GLenum pname, const GLfloat *params);
+#endif
+#endif /* GL_EXT_point_parameters */
+
+#ifndef GL_EXT_polygon_offset
+#define GL_EXT_polygon_offset 1
+#define GL_POLYGON_OFFSET_EXT 0x8037
+#define GL_POLYGON_OFFSET_FACTOR_EXT 0x8038
+#define GL_POLYGON_OFFSET_BIAS_EXT 0x8039
+typedef void (APIENTRYP PFNGLPOLYGONOFFSETEXTPROC) (GLfloat factor, GLfloat bias);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPolygonOffsetEXT (GLfloat factor, GLfloat bias);
+#endif
+#endif /* GL_EXT_polygon_offset */
+
+#ifndef GL_EXT_provoking_vertex
+#define GL_EXT_provoking_vertex 1
+#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION_EXT 0x8E4C
+#define GL_FIRST_VERTEX_CONVENTION_EXT 0x8E4D
+#define GL_LAST_VERTEX_CONVENTION_EXT 0x8E4E
+#define GL_PROVOKING_VERTEX_EXT 0x8E4F
+typedef void (APIENTRYP PFNGLPROVOKINGVERTEXEXTPROC) (GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProvokingVertexEXT (GLenum mode);
+#endif
+#endif /* GL_EXT_provoking_vertex */
+
+#ifndef GL_EXT_rescale_normal
+#define GL_EXT_rescale_normal 1
+#define GL_RESCALE_NORMAL_EXT 0x803A
+#endif /* GL_EXT_rescale_normal */
+
+#ifndef GL_EXT_secondary_color
+#define GL_EXT_secondary_color 1
+#define GL_COLOR_SUM_EXT 0x8458
+#define GL_CURRENT_SECONDARY_COLOR_EXT 0x8459
+#define GL_SECONDARY_COLOR_ARRAY_SIZE_EXT 0x845A
+#define GL_SECONDARY_COLOR_ARRAY_TYPE_EXT 0x845B
+#define GL_SECONDARY_COLOR_ARRAY_STRIDE_EXT 0x845C
+#define GL_SECONDARY_COLOR_ARRAY_POINTER_EXT 0x845D
+#define GL_SECONDARY_COLOR_ARRAY_EXT 0x845E
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BEXTPROC) (GLbyte red, GLbyte green, GLbyte blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3BVEXTPROC) (const GLbyte *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DEXTPROC) (GLdouble red, GLdouble green, GLdouble blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3DVEXTPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FEXTPROC) (GLfloat red, GLfloat green, GLfloat blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3FVEXTPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IEXTPROC) (GLint red, GLint green, GLint blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3IVEXTPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SEXTPROC) (GLshort red, GLshort green, GLshort blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3SVEXTPROC) (const GLshort *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBEXTPROC) (GLubyte red, GLubyte green, GLubyte blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UBVEXTPROC) (const GLubyte *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIEXTPROC) (GLuint red, GLuint green, GLuint blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3UIVEXTPROC) (const GLuint *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USEXTPROC) (GLushort red, GLushort green, GLushort blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3USVEXTPROC) (const GLushort *v);
+typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, const void *pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glSecondaryColor3bEXT (GLbyte red, GLbyte green, GLbyte blue);
+GLAPI void APIENTRY glSecondaryColor3bvEXT (const GLbyte *v);
+GLAPI void APIENTRY glSecondaryColor3dEXT (GLdouble red, GLdouble green, GLdouble blue);
+GLAPI void APIENTRY glSecondaryColor3dvEXT (const GLdouble *v);
+GLAPI void APIENTRY glSecondaryColor3fEXT (GLfloat red, GLfloat green, GLfloat blue);
+GLAPI void APIENTRY glSecondaryColor3fvEXT (const GLfloat *v);
+GLAPI void APIENTRY glSecondaryColor3iEXT (GLint red, GLint green, GLint blue);
+GLAPI void APIENTRY glSecondaryColor3ivEXT (const GLint *v);
+GLAPI void APIENTRY glSecondaryColor3sEXT (GLshort red, GLshort green, GLshort blue);
+GLAPI void APIENTRY glSecondaryColor3svEXT (const GLshort *v);
+GLAPI void APIENTRY glSecondaryColor3ubEXT (GLubyte red, GLubyte green, GLubyte blue);
+GLAPI void APIENTRY glSecondaryColor3ubvEXT (const GLubyte *v);
+GLAPI void APIENTRY glSecondaryColor3uiEXT (GLuint red, GLuint green, GLuint blue);
+GLAPI void APIENTRY glSecondaryColor3uivEXT (const GLuint *v);
+GLAPI void APIENTRY glSecondaryColor3usEXT (GLushort red, GLushort green, GLushort blue);
+GLAPI void APIENTRY glSecondaryColor3usvEXT (const GLushort *v);
+GLAPI void APIENTRY glSecondaryColorPointerEXT (GLint size, GLenum type, GLsizei stride, const void *pointer);
+#endif
+#endif /* GL_EXT_secondary_color */
+
+#ifndef GL_EXT_separate_shader_objects
+#define GL_EXT_separate_shader_objects 1
+#define GL_ACTIVE_PROGRAM_EXT 0x8B8D
+typedef void (APIENTRYP PFNGLUSESHADERPROGRAMEXTPROC) (GLenum type, GLuint program);
+typedef void (APIENTRYP PFNGLACTIVEPROGRAMEXTPROC) (GLuint program);
+typedef GLuint (APIENTRYP PFNGLCREATESHADERPROGRAMEXTPROC) (GLenum type, const GLchar *string);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glUseShaderProgramEXT (GLenum type, GLuint program);
+GLAPI void APIENTRY glActiveProgramEXT (GLuint program);
+GLAPI GLuint APIENTRY glCreateShaderProgramEXT (GLenum type, const GLchar *string);
+#endif
+#endif /* GL_EXT_separate_shader_objects */
+
+#ifndef GL_EXT_separate_specular_color
+#define GL_EXT_separate_specular_color 1
+#define GL_LIGHT_MODEL_COLOR_CONTROL_EXT 0x81F8
+#define GL_SINGLE_COLOR_EXT 0x81F9
+#define GL_SEPARATE_SPECULAR_COLOR_EXT 0x81FA
+#endif /* GL_EXT_separate_specular_color */
+
+#ifndef GL_EXT_shader_image_load_formatted
+#define GL_EXT_shader_image_load_formatted 1
+#endif /* GL_EXT_shader_image_load_formatted */
+
+#ifndef GL_EXT_shader_image_load_store
+#define GL_EXT_shader_image_load_store 1
+#define GL_MAX_IMAGE_UNITS_EXT 0x8F38
+#define GL_MAX_COMBINED_IMAGE_UNITS_AND_FRAGMENT_OUTPUTS_EXT 0x8F39
+#define GL_IMAGE_BINDING_NAME_EXT 0x8F3A
+#define GL_IMAGE_BINDING_LEVEL_EXT 0x8F3B
+#define GL_IMAGE_BINDING_LAYERED_EXT 0x8F3C
+#define GL_IMAGE_BINDING_LAYER_EXT 0x8F3D
+#define GL_IMAGE_BINDING_ACCESS_EXT 0x8F3E
+#define GL_IMAGE_1D_EXT 0x904C
+#define GL_IMAGE_2D_EXT 0x904D
+#define GL_IMAGE_3D_EXT 0x904E
+#define GL_IMAGE_2D_RECT_EXT 0x904F
+#define GL_IMAGE_CUBE_EXT 0x9050
+#define GL_IMAGE_BUFFER_EXT 0x9051
+#define GL_IMAGE_1D_ARRAY_EXT 0x9052
+#define GL_IMAGE_2D_ARRAY_EXT 0x9053
+#define GL_IMAGE_CUBE_MAP_ARRAY_EXT 0x9054
+#define GL_IMAGE_2D_MULTISAMPLE_EXT 0x9055
+#define GL_IMAGE_2D_MULTISAMPLE_ARRAY_EXT 0x9056
+#define GL_INT_IMAGE_1D_EXT 0x9057
+#define GL_INT_IMAGE_2D_EXT 0x9058
+#define GL_INT_IMAGE_3D_EXT 0x9059
+#define GL_INT_IMAGE_2D_RECT_EXT 0x905A
+#define GL_INT_IMAGE_CUBE_EXT 0x905B
+#define GL_INT_IMAGE_BUFFER_EXT 0x905C
+#define GL_INT_IMAGE_1D_ARRAY_EXT 0x905D
+#define GL_INT_IMAGE_2D_ARRAY_EXT 0x905E
+#define GL_INT_IMAGE_CUBE_MAP_ARRAY_EXT 0x905F
+#define GL_INT_IMAGE_2D_MULTISAMPLE_EXT 0x9060
+#define GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY_EXT 0x9061
+#define GL_UNSIGNED_INT_IMAGE_1D_EXT 0x9062
+#define GL_UNSIGNED_INT_IMAGE_2D_EXT 0x9063
+#define GL_UNSIGNED_INT_IMAGE_3D_EXT 0x9064
+#define GL_UNSIGNED_INT_IMAGE_2D_RECT_EXT 0x9065
+#define GL_UNSIGNED_INT_IMAGE_CUBE_EXT 0x9066
+#define GL_UNSIGNED_INT_IMAGE_BUFFER_EXT 0x9067
+#define GL_UNSIGNED_INT_IMAGE_1D_ARRAY_EXT 0x9068
+#define GL_UNSIGNED_INT_IMAGE_2D_ARRAY_EXT 0x9069
+#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY_EXT 0x906A
+#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_EXT 0x906B
+#define GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY_EXT 0x906C
+#define GL_MAX_IMAGE_SAMPLES_EXT 0x906D
+#define GL_IMAGE_BINDING_FORMAT_EXT 0x906E
+#define GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT_EXT 0x00000001
+#define GL_ELEMENT_ARRAY_BARRIER_BIT_EXT 0x00000002
+#define GL_UNIFORM_BARRIER_BIT_EXT 0x00000004
+#define GL_TEXTURE_FETCH_BARRIER_BIT_EXT 0x00000008
+#define GL_SHADER_IMAGE_ACCESS_BARRIER_BIT_EXT 0x00000020
+#define GL_COMMAND_BARRIER_BIT_EXT 0x00000040
+#define GL_PIXEL_BUFFER_BARRIER_BIT_EXT 0x00000080
+#define GL_TEXTURE_UPDATE_BARRIER_BIT_EXT 0x00000100
+#define GL_BUFFER_UPDATE_BARRIER_BIT_EXT 0x00000200
+#define GL_FRAMEBUFFER_BARRIER_BIT_EXT 0x00000400
+#define GL_TRANSFORM_FEEDBACK_BARRIER_BIT_EXT 0x00000800
+#define GL_ATOMIC_COUNTER_BARRIER_BIT_EXT 0x00001000
+#define GL_ALL_BARRIER_BITS_EXT 0xFFFFFFFF
+typedef void (APIENTRYP PFNGLBINDIMAGETEXTUREEXTPROC) (GLuint index, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLint format);
+typedef void (APIENTRYP PFNGLMEMORYBARRIEREXTPROC) (GLbitfield barriers);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBindImageTextureEXT (GLuint index, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLint format);
+GLAPI void APIENTRY glMemoryBarrierEXT (GLbitfield barriers);
+#endif
+#endif /* GL_EXT_shader_image_load_store */
+
+#ifndef GL_EXT_shader_integer_mix
+#define GL_EXT_shader_integer_mix 1
+#endif /* GL_EXT_shader_integer_mix */
+
+#ifndef GL_EXT_shadow_funcs
+#define GL_EXT_shadow_funcs 1
+#endif /* GL_EXT_shadow_funcs */
+
+#ifndef GL_EXT_shared_texture_palette
+#define GL_EXT_shared_texture_palette 1
+#define GL_SHARED_TEXTURE_PALETTE_EXT 0x81FB
+#endif /* GL_EXT_shared_texture_palette */
+
+#ifndef GL_EXT_stencil_clear_tag
+#define GL_EXT_stencil_clear_tag 1
+#define GL_STENCIL_TAG_BITS_EXT 0x88F2
+#define GL_STENCIL_CLEAR_TAG_VALUE_EXT 0x88F3
+typedef void (APIENTRYP PFNGLSTENCILCLEARTAGEXTPROC) (GLsizei stencilTagBits, GLuint stencilClearTag);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glStencilClearTagEXT (GLsizei stencilTagBits, GLuint stencilClearTag);
+#endif
+#endif /* GL_EXT_stencil_clear_tag */
+
+#ifndef GL_EXT_stencil_two_side
+#define GL_EXT_stencil_two_side 1
+#define GL_STENCIL_TEST_TWO_SIDE_EXT 0x8910
+#define GL_ACTIVE_STENCIL_FACE_EXT 0x8911
+typedef void (APIENTRYP PFNGLACTIVESTENCILFACEEXTPROC) (GLenum face);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glActiveStencilFaceEXT (GLenum face);
+#endif
+#endif /* GL_EXT_stencil_two_side */
+
+#ifndef GL_EXT_stencil_wrap
+#define GL_EXT_stencil_wrap 1
+#define GL_INCR_WRAP_EXT 0x8507
+#define GL_DECR_WRAP_EXT 0x8508
+#endif /* GL_EXT_stencil_wrap */
+
+#ifndef GL_EXT_subtexture
+#define GL_EXT_subtexture 1
+typedef void (APIENTRYP PFNGLTEXSUBIMAGE1DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexSubImage1DEXT (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glTexSubImage2DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
+#endif
+#endif /* GL_EXT_subtexture */
+
+#ifndef GL_EXT_texture
+#define GL_EXT_texture 1
+#define GL_ALPHA4_EXT 0x803B
+#define GL_ALPHA8_EXT 0x803C
+#define GL_ALPHA12_EXT 0x803D
+#define GL_ALPHA16_EXT 0x803E
+#define GL_LUMINANCE4_EXT 0x803F
+#define GL_LUMINANCE8_EXT 0x8040
+#define GL_LUMINANCE12_EXT 0x8041
+#define GL_LUMINANCE16_EXT 0x8042
+#define GL_LUMINANCE4_ALPHA4_EXT 0x8043
+#define GL_LUMINANCE6_ALPHA2_EXT 0x8044
+#define GL_LUMINANCE8_ALPHA8_EXT 0x8045
+#define GL_LUMINANCE12_ALPHA4_EXT 0x8046
+#define GL_LUMINANCE12_ALPHA12_EXT 0x8047
+#define GL_LUMINANCE16_ALPHA16_EXT 0x8048
+#define GL_INTENSITY_EXT 0x8049
+#define GL_INTENSITY4_EXT 0x804A
+#define GL_INTENSITY8_EXT 0x804B
+#define GL_INTENSITY12_EXT 0x804C
+#define GL_INTENSITY16_EXT 0x804D
+#define GL_RGB2_EXT 0x804E
+#define GL_RGB4_EXT 0x804F
+#define GL_RGB5_EXT 0x8050
+#define GL_RGB8_EXT 0x8051
+#define GL_RGB10_EXT 0x8052
+#define GL_RGB12_EXT 0x8053
+#define GL_RGB16_EXT 0x8054
+#define GL_RGBA2_EXT 0x8055
+#define GL_RGBA4_EXT 0x8056
+#define GL_RGB5_A1_EXT 0x8057
+#define GL_RGBA8_EXT 0x8058
+#define GL_RGB10_A2_EXT 0x8059
+#define GL_RGBA12_EXT 0x805A
+#define GL_RGBA16_EXT 0x805B
+#define GL_TEXTURE_RED_SIZE_EXT 0x805C
+#define GL_TEXTURE_GREEN_SIZE_EXT 0x805D
+#define GL_TEXTURE_BLUE_SIZE_EXT 0x805E
+#define GL_TEXTURE_ALPHA_SIZE_EXT 0x805F
+#define GL_TEXTURE_LUMINANCE_SIZE_EXT 0x8060
+#define GL_TEXTURE_INTENSITY_SIZE_EXT 0x8061
+#define GL_REPLACE_EXT 0x8062
+#define GL_PROXY_TEXTURE_1D_EXT 0x8063
+#define GL_PROXY_TEXTURE_2D_EXT 0x8064
+#define GL_TEXTURE_TOO_LARGE_EXT 0x8065
+#endif /* GL_EXT_texture */
+
+#ifndef GL_EXT_texture3D
+#define GL_EXT_texture3D 1
+#define GL_PACK_SKIP_IMAGES_EXT 0x806B
+#define GL_PACK_IMAGE_HEIGHT_EXT 0x806C
+#define GL_UNPACK_SKIP_IMAGES_EXT 0x806D
+#define GL_UNPACK_IMAGE_HEIGHT_EXT 0x806E
+#define GL_TEXTURE_3D_EXT 0x806F
+#define GL_PROXY_TEXTURE_3D_EXT 0x8070
+#define GL_TEXTURE_DEPTH_EXT 0x8071
+#define GL_TEXTURE_WRAP_R_EXT 0x8072
+#define GL_MAX_3D_TEXTURE_SIZE_EXT 0x8073
+typedef void (APIENTRYP PFNGLTEXIMAGE3DEXTPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLTEXSUBIMAGE3DEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexImage3DEXT (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glTexSubImage3DEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
+#endif
+#endif /* GL_EXT_texture3D */
+
+#ifndef GL_EXT_texture_array
+#define GL_EXT_texture_array 1
+#define GL_TEXTURE_1D_ARRAY_EXT 0x8C18
+#define GL_PROXY_TEXTURE_1D_ARRAY_EXT 0x8C19
+#define GL_TEXTURE_2D_ARRAY_EXT 0x8C1A
+#define GL_PROXY_TEXTURE_2D_ARRAY_EXT 0x8C1B
+#define GL_TEXTURE_BINDING_1D_ARRAY_EXT 0x8C1C
+#define GL_TEXTURE_BINDING_2D_ARRAY_EXT 0x8C1D
+#define GL_MAX_ARRAY_TEXTURE_LAYERS_EXT 0x88FF
+#define GL_COMPARE_REF_DEPTH_TO_TEXTURE_EXT 0x884E
+#endif /* GL_EXT_texture_array */
+
+#ifndef GL_EXT_texture_buffer_object
+#define GL_EXT_texture_buffer_object 1
+#define GL_TEXTURE_BUFFER_EXT 0x8C2A
+#define GL_MAX_TEXTURE_BUFFER_SIZE_EXT 0x8C2B
+#define GL_TEXTURE_BINDING_BUFFER_EXT 0x8C2C
+#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING_EXT 0x8C2D
+#define GL_TEXTURE_BUFFER_FORMAT_EXT 0x8C2E
+typedef void (APIENTRYP PFNGLTEXBUFFEREXTPROC) (GLenum target, GLenum internalformat, GLuint buffer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexBufferEXT (GLenum target, GLenum internalformat, GLuint buffer);
+#endif
+#endif /* GL_EXT_texture_buffer_object */
+
+#ifndef GL_EXT_texture_compression_latc
+#define GL_EXT_texture_compression_latc 1
+#define GL_COMPRESSED_LUMINANCE_LATC1_EXT 0x8C70
+#define GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT 0x8C71
+#define GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT 0x8C72
+#define GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT 0x8C73
+#endif /* GL_EXT_texture_compression_latc */
+
+#ifndef GL_EXT_texture_compression_rgtc
+#define GL_EXT_texture_compression_rgtc 1
+#define GL_COMPRESSED_RED_RGTC1_EXT 0x8DBB
+#define GL_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC
+#define GL_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD
+#define GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE
+#endif /* GL_EXT_texture_compression_rgtc */
+
+#ifndef GL_EXT_texture_compression_s3tc
+#define GL_EXT_texture_compression_s3tc 1
+#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
+#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
+#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
+#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
+#endif /* GL_EXT_texture_compression_s3tc */
+
+#ifndef GL_EXT_texture_cube_map
+#define GL_EXT_texture_cube_map 1
+#define GL_NORMAL_MAP_EXT 0x8511
+#define GL_REFLECTION_MAP_EXT 0x8512
+#define GL_TEXTURE_CUBE_MAP_EXT 0x8513
+#define GL_TEXTURE_BINDING_CUBE_MAP_EXT 0x8514
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT 0x8515
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT 0x8516
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT 0x8517
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT 0x8518
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT 0x8519
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT 0x851A
+#define GL_PROXY_TEXTURE_CUBE_MAP_EXT 0x851B
+#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_EXT 0x851C
+#endif /* GL_EXT_texture_cube_map */
+
+#ifndef GL_EXT_texture_env_add
+#define GL_EXT_texture_env_add 1
+#endif /* GL_EXT_texture_env_add */
+
+#ifndef GL_EXT_texture_env_combine
+#define GL_EXT_texture_env_combine 1
+#define GL_COMBINE_EXT 0x8570
+#define GL_COMBINE_RGB_EXT 0x8571
+#define GL_COMBINE_ALPHA_EXT 0x8572
+#define GL_RGB_SCALE_EXT 0x8573
+#define GL_ADD_SIGNED_EXT 0x8574
+#define GL_INTERPOLATE_EXT 0x8575
+#define GL_CONSTANT_EXT 0x8576
+#define GL_PRIMARY_COLOR_EXT 0x8577
+#define GL_PREVIOUS_EXT 0x8578
+#define GL_SOURCE0_RGB_EXT 0x8580
+#define GL_SOURCE1_RGB_EXT 0x8581
+#define GL_SOURCE2_RGB_EXT 0x8582
+#define GL_SOURCE0_ALPHA_EXT 0x8588
+#define GL_SOURCE1_ALPHA_EXT 0x8589
+#define GL_SOURCE2_ALPHA_EXT 0x858A
+#define GL_OPERAND0_RGB_EXT 0x8590
+#define GL_OPERAND1_RGB_EXT 0x8591
+#define GL_OPERAND2_RGB_EXT 0x8592
+#define GL_OPERAND0_ALPHA_EXT 0x8598
+#define GL_OPERAND1_ALPHA_EXT 0x8599
+#define GL_OPERAND2_ALPHA_EXT 0x859A
+#endif /* GL_EXT_texture_env_combine */
+
+#ifndef GL_EXT_texture_env_dot3
+#define GL_EXT_texture_env_dot3 1
+#define GL_DOT3_RGB_EXT 0x8740
+#define GL_DOT3_RGBA_EXT 0x8741
+#endif /* GL_EXT_texture_env_dot3 */
+
+#ifndef GL_EXT_texture_filter_anisotropic
+#define GL_EXT_texture_filter_anisotropic 1
+#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
+#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
+#endif /* GL_EXT_texture_filter_anisotropic */
+
+#ifndef GL_EXT_texture_integer
+#define GL_EXT_texture_integer 1
+#define GL_RGBA32UI_EXT 0x8D70
+#define GL_RGB32UI_EXT 0x8D71
+#define GL_ALPHA32UI_EXT 0x8D72
+#define GL_INTENSITY32UI_EXT 0x8D73
+#define GL_LUMINANCE32UI_EXT 0x8D74
+#define GL_LUMINANCE_ALPHA32UI_EXT 0x8D75
+#define GL_RGBA16UI_EXT 0x8D76
+#define GL_RGB16UI_EXT 0x8D77
+#define GL_ALPHA16UI_EXT 0x8D78
+#define GL_INTENSITY16UI_EXT 0x8D79
+#define GL_LUMINANCE16UI_EXT 0x8D7A
+#define GL_LUMINANCE_ALPHA16UI_EXT 0x8D7B
+#define GL_RGBA8UI_EXT 0x8D7C
+#define GL_RGB8UI_EXT 0x8D7D
+#define GL_ALPHA8UI_EXT 0x8D7E
+#define GL_INTENSITY8UI_EXT 0x8D7F
+#define GL_LUMINANCE8UI_EXT 0x8D80
+#define GL_LUMINANCE_ALPHA8UI_EXT 0x8D81
+#define GL_RGBA32I_EXT 0x8D82
+#define GL_RGB32I_EXT 0x8D83
+#define GL_ALPHA32I_EXT 0x8D84
+#define GL_INTENSITY32I_EXT 0x8D85
+#define GL_LUMINANCE32I_EXT 0x8D86
+#define GL_LUMINANCE_ALPHA32I_EXT 0x8D87
+#define GL_RGBA16I_EXT 0x8D88
+#define GL_RGB16I_EXT 0x8D89
+#define GL_ALPHA16I_EXT 0x8D8A
+#define GL_INTENSITY16I_EXT 0x8D8B
+#define GL_LUMINANCE16I_EXT 0x8D8C
+#define GL_LUMINANCE_ALPHA16I_EXT 0x8D8D
+#define GL_RGBA8I_EXT 0x8D8E
+#define GL_RGB8I_EXT 0x8D8F
+#define GL_ALPHA8I_EXT 0x8D90
+#define GL_INTENSITY8I_EXT 0x8D91
+#define GL_LUMINANCE8I_EXT 0x8D92
+#define GL_LUMINANCE_ALPHA8I_EXT 0x8D93
+#define GL_RED_INTEGER_EXT 0x8D94
+#define GL_GREEN_INTEGER_EXT 0x8D95
+#define GL_BLUE_INTEGER_EXT 0x8D96
+#define GL_ALPHA_INTEGER_EXT 0x8D97
+#define GL_RGB_INTEGER_EXT 0x8D98
+#define GL_RGBA_INTEGER_EXT 0x8D99
+#define GL_BGR_INTEGER_EXT 0x8D9A
+#define GL_BGRA_INTEGER_EXT 0x8D9B
+#define GL_LUMINANCE_INTEGER_EXT 0x8D9C
+#define GL_LUMINANCE_ALPHA_INTEGER_EXT 0x8D9D
+#define GL_RGBA_INTEGER_MODE_EXT 0x8D9E
+typedef void (APIENTRYP PFNGLTEXPARAMETERIIVEXTPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLTEXPARAMETERIUIVEXTPROC) (GLenum target, GLenum pname, const GLuint *params);
+typedef void (APIENTRYP PFNGLGETTEXPARAMETERIIVEXTPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETTEXPARAMETERIUIVEXTPROC) (GLenum target, GLenum pname, GLuint *params);
+typedef void (APIENTRYP PFNGLCLEARCOLORIIEXTPROC) (GLint red, GLint green, GLint blue, GLint alpha);
+typedef void (APIENTRYP PFNGLCLEARCOLORIUIEXTPROC) (GLuint red, GLuint green, GLuint blue, GLuint alpha);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexParameterIivEXT (GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glTexParameterIuivEXT (GLenum target, GLenum pname, const GLuint *params);
+GLAPI void APIENTRY glGetTexParameterIivEXT (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetTexParameterIuivEXT (GLenum target, GLenum pname, GLuint *params);
+GLAPI void APIENTRY glClearColorIiEXT (GLint red, GLint green, GLint blue, GLint alpha);
+GLAPI void APIENTRY glClearColorIuiEXT (GLuint red, GLuint green, GLuint blue, GLuint alpha);
+#endif
+#endif /* GL_EXT_texture_integer */
+
+#ifndef GL_EXT_texture_lod_bias
+#define GL_EXT_texture_lod_bias 1
+#define GL_MAX_TEXTURE_LOD_BIAS_EXT 0x84FD
+#define GL_TEXTURE_FILTER_CONTROL_EXT 0x8500
+#define GL_TEXTURE_LOD_BIAS_EXT 0x8501
+#endif /* GL_EXT_texture_lod_bias */
+
+#ifndef GL_EXT_texture_mirror_clamp
+#define GL_EXT_texture_mirror_clamp 1
+#define GL_MIRROR_CLAMP_EXT 0x8742
+#define GL_MIRROR_CLAMP_TO_EDGE_EXT 0x8743
+#define GL_MIRROR_CLAMP_TO_BORDER_EXT 0x8912
+#endif /* GL_EXT_texture_mirror_clamp */
+
+#ifndef GL_EXT_texture_object
+#define GL_EXT_texture_object 1
+#define GL_TEXTURE_PRIORITY_EXT 0x8066
+#define GL_TEXTURE_RESIDENT_EXT 0x8067
+#define GL_TEXTURE_1D_BINDING_EXT 0x8068
+#define GL_TEXTURE_2D_BINDING_EXT 0x8069
+#define GL_TEXTURE_3D_BINDING_EXT 0x806A
+typedef GLboolean (APIENTRYP PFNGLARETEXTURESRESIDENTEXTPROC) (GLsizei n, const GLuint *textures, GLboolean *residences);
+typedef void (APIENTRYP PFNGLBINDTEXTUREEXTPROC) (GLenum target, GLuint texture);
+typedef void (APIENTRYP PFNGLDELETETEXTURESEXTPROC) (GLsizei n, const GLuint *textures);
+typedef void (APIENTRYP PFNGLGENTEXTURESEXTPROC) (GLsizei n, GLuint *textures);
+typedef GLboolean (APIENTRYP PFNGLISTEXTUREEXTPROC) (GLuint texture);
+typedef void (APIENTRYP PFNGLPRIORITIZETEXTURESEXTPROC) (GLsizei n, const GLuint *textures, const GLclampf *priorities);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLboolean APIENTRY glAreTexturesResidentEXT (GLsizei n, const GLuint *textures, GLboolean *residences);
+GLAPI void APIENTRY glBindTextureEXT (GLenum target, GLuint texture);
+GLAPI void APIENTRY glDeleteTexturesEXT (GLsizei n, const GLuint *textures);
+GLAPI void APIENTRY glGenTexturesEXT (GLsizei n, GLuint *textures);
+GLAPI GLboolean APIENTRY glIsTextureEXT (GLuint texture);
+GLAPI void APIENTRY glPrioritizeTexturesEXT (GLsizei n, const GLuint *textures, const GLclampf *priorities);
+#endif
+#endif /* GL_EXT_texture_object */
+
+#ifndef GL_EXT_texture_perturb_normal
+#define GL_EXT_texture_perturb_normal 1
+#define GL_PERTURB_EXT 0x85AE
+#define GL_TEXTURE_NORMAL_EXT 0x85AF
+typedef void (APIENTRYP PFNGLTEXTURENORMALEXTPROC) (GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTextureNormalEXT (GLenum mode);
+#endif
+#endif /* GL_EXT_texture_perturb_normal */
+
+#ifndef GL_EXT_texture_sRGB
+#define GL_EXT_texture_sRGB 1
+#define GL_SRGB_EXT 0x8C40
+#define GL_SRGB8_EXT 0x8C41
+#define GL_SRGB_ALPHA_EXT 0x8C42
+#define GL_SRGB8_ALPHA8_EXT 0x8C43
+#define GL_SLUMINANCE_ALPHA_EXT 0x8C44
+#define GL_SLUMINANCE8_ALPHA8_EXT 0x8C45
+#define GL_SLUMINANCE_EXT 0x8C46
+#define GL_SLUMINANCE8_EXT 0x8C47
+#define GL_COMPRESSED_SRGB_EXT 0x8C48
+#define GL_COMPRESSED_SRGB_ALPHA_EXT 0x8C49
+#define GL_COMPRESSED_SLUMINANCE_EXT 0x8C4A
+#define GL_COMPRESSED_SLUMINANCE_ALPHA_EXT 0x8C4B
+#define GL_COMPRESSED_SRGB_S3TC_DXT1_EXT 0x8C4C
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT 0x8C4E
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F
+#endif /* GL_EXT_texture_sRGB */
+
+#ifndef GL_EXT_texture_sRGB_decode
+#define GL_EXT_texture_sRGB_decode 1
+#define GL_TEXTURE_SRGB_DECODE_EXT 0x8A48
+#define GL_DECODE_EXT 0x8A49
+#define GL_SKIP_DECODE_EXT 0x8A4A
+#endif /* GL_EXT_texture_sRGB_decode */
+
+#ifndef GL_EXT_texture_shared_exponent
+#define GL_EXT_texture_shared_exponent 1
+#define GL_RGB9_E5_EXT 0x8C3D
+#define GL_UNSIGNED_INT_5_9_9_9_REV_EXT 0x8C3E
+#define GL_TEXTURE_SHARED_SIZE_EXT 0x8C3F
+#endif /* GL_EXT_texture_shared_exponent */
+
+#ifndef GL_EXT_texture_snorm
+#define GL_EXT_texture_snorm 1
+#define GL_ALPHA_SNORM 0x9010
+#define GL_LUMINANCE_SNORM 0x9011
+#define GL_LUMINANCE_ALPHA_SNORM 0x9012
+#define GL_INTENSITY_SNORM 0x9013
+#define GL_ALPHA8_SNORM 0x9014
+#define GL_LUMINANCE8_SNORM 0x9015
+#define GL_LUMINANCE8_ALPHA8_SNORM 0x9016
+#define GL_INTENSITY8_SNORM 0x9017
+#define GL_ALPHA16_SNORM 0x9018
+#define GL_LUMINANCE16_SNORM 0x9019
+#define GL_LUMINANCE16_ALPHA16_SNORM 0x901A
+#define GL_INTENSITY16_SNORM 0x901B
+#define GL_RED_SNORM 0x8F90
+#define GL_RG_SNORM 0x8F91
+#define GL_RGB_SNORM 0x8F92
+#define GL_RGBA_SNORM 0x8F93
+#endif /* GL_EXT_texture_snorm */
+
+#ifndef GL_EXT_texture_swizzle
+#define GL_EXT_texture_swizzle 1
+#define GL_TEXTURE_SWIZZLE_R_EXT 0x8E42
+#define GL_TEXTURE_SWIZZLE_G_EXT 0x8E43
+#define GL_TEXTURE_SWIZZLE_B_EXT 0x8E44
+#define GL_TEXTURE_SWIZZLE_A_EXT 0x8E45
+#define GL_TEXTURE_SWIZZLE_RGBA_EXT 0x8E46
+#endif /* GL_EXT_texture_swizzle */
+
+#ifndef GL_EXT_timer_query
+#define GL_EXT_timer_query 1
+#define GL_TIME_ELAPSED_EXT 0x88BF
+typedef void (APIENTRYP PFNGLGETQUERYOBJECTI64VEXTPROC) (GLuint id, GLenum pname, GLint64 *params);
+typedef void (APIENTRYP PFNGLGETQUERYOBJECTUI64VEXTPROC) (GLuint id, GLenum pname, GLuint64 *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGetQueryObjecti64vEXT (GLuint id, GLenum pname, GLint64 *params);
+GLAPI void APIENTRY glGetQueryObjectui64vEXT (GLuint id, GLenum pname, GLuint64 *params);
+#endif
+#endif /* GL_EXT_timer_query */
+
+#ifndef GL_EXT_transform_feedback
+#define GL_EXT_transform_feedback 1
+#define GL_TRANSFORM_FEEDBACK_BUFFER_EXT 0x8C8E
+#define GL_TRANSFORM_FEEDBACK_BUFFER_START_EXT 0x8C84
+#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE_EXT 0x8C85
+#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING_EXT 0x8C8F
+#define GL_INTERLEAVED_ATTRIBS_EXT 0x8C8C
+#define GL_SEPARATE_ATTRIBS_EXT 0x8C8D
+#define GL_PRIMITIVES_GENERATED_EXT 0x8C87
+#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_EXT 0x8C88
+#define GL_RASTERIZER_DISCARD_EXT 0x8C89
+#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_EXT 0x8C8A
+#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_EXT 0x8C8B
+#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_EXT 0x8C80
+#define GL_TRANSFORM_FEEDBACK_VARYINGS_EXT 0x8C83
+#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE_EXT 0x8C7F
+#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH_EXT 0x8C76
+typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKEXTPROC) (GLenum primitiveMode);
+typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKEXTPROC) (void);
+typedef void (APIENTRYP PFNGLBINDBUFFERRANGEEXTPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size);
+typedef void (APIENTRYP PFNGLBINDBUFFEROFFSETEXTPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset);
+typedef void (APIENTRYP PFNGLBINDBUFFERBASEEXTPROC) (GLenum target, GLuint index, GLuint buffer);
+typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSEXTPROC) (GLuint program, GLsizei count, const GLchar *const*varyings, GLenum bufferMode);
+typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGEXTPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBeginTransformFeedbackEXT (GLenum primitiveMode);
+GLAPI void APIENTRY glEndTransformFeedbackEXT (void);
+GLAPI void APIENTRY glBindBufferRangeEXT (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size);
+GLAPI void APIENTRY glBindBufferOffsetEXT (GLenum target, GLuint index, GLuint buffer, GLintptr offset);
+GLAPI void APIENTRY glBindBufferBaseEXT (GLenum target, GLuint index, GLuint buffer);
+GLAPI void APIENTRY glTransformFeedbackVaryingsEXT (GLuint program, GLsizei count, const GLchar *const*varyings, GLenum bufferMode);
+GLAPI void APIENTRY glGetTransformFeedbackVaryingEXT (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name);
+#endif
+#endif /* GL_EXT_transform_feedback */
+
+#ifndef GL_EXT_vertex_array
+#define GL_EXT_vertex_array 1
+#define GL_VERTEX_ARRAY_EXT 0x8074
+#define GL_NORMAL_ARRAY_EXT 0x8075
+#define GL_COLOR_ARRAY_EXT 0x8076
+#define GL_INDEX_ARRAY_EXT 0x8077
+#define GL_TEXTURE_COORD_ARRAY_EXT 0x8078
+#define GL_EDGE_FLAG_ARRAY_EXT 0x8079
+#define GL_VERTEX_ARRAY_SIZE_EXT 0x807A
+#define GL_VERTEX_ARRAY_TYPE_EXT 0x807B
+#define GL_VERTEX_ARRAY_STRIDE_EXT 0x807C
+#define GL_VERTEX_ARRAY_COUNT_EXT 0x807D
+#define GL_NORMAL_ARRAY_TYPE_EXT 0x807E
+#define GL_NORMAL_ARRAY_STRIDE_EXT 0x807F
+#define GL_NORMAL_ARRAY_COUNT_EXT 0x8080
+#define GL_COLOR_ARRAY_SIZE_EXT 0x8081
+#define GL_COLOR_ARRAY_TYPE_EXT 0x8082
+#define GL_COLOR_ARRAY_STRIDE_EXT 0x8083
+#define GL_COLOR_ARRAY_COUNT_EXT 0x8084
+#define GL_INDEX_ARRAY_TYPE_EXT 0x8085
+#define GL_INDEX_ARRAY_STRIDE_EXT 0x8086
+#define GL_INDEX_ARRAY_COUNT_EXT 0x8087
+#define GL_TEXTURE_COORD_ARRAY_SIZE_EXT 0x8088
+#define GL_TEXTURE_COORD_ARRAY_TYPE_EXT 0x8089
+#define GL_TEXTURE_COORD_ARRAY_STRIDE_EXT 0x808A
+#define GL_TEXTURE_COORD_ARRAY_COUNT_EXT 0x808B
+#define GL_EDGE_FLAG_ARRAY_STRIDE_EXT 0x808C
+#define GL_EDGE_FLAG_ARRAY_COUNT_EXT 0x808D
+#define GL_VERTEX_ARRAY_POINTER_EXT 0x808E
+#define GL_NORMAL_ARRAY_POINTER_EXT 0x808F
+#define GL_COLOR_ARRAY_POINTER_EXT 0x8090
+#define GL_INDEX_ARRAY_POINTER_EXT 0x8091
+#define GL_TEXTURE_COORD_ARRAY_POINTER_EXT 0x8092
+#define GL_EDGE_FLAG_ARRAY_POINTER_EXT 0x8093
+typedef void (APIENTRYP PFNGLARRAYELEMENTEXTPROC) (GLint i);
+typedef void (APIENTRYP PFNGLCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+typedef void (APIENTRYP PFNGLDRAWARRAYSEXTPROC) (GLenum mode, GLint first, GLsizei count);
+typedef void (APIENTRYP PFNGLEDGEFLAGPOINTEREXTPROC) (GLsizei stride, GLsizei count, const GLboolean *pointer);
+typedef void (APIENTRYP PFNGLGETPOINTERVEXTPROC) (GLenum pname, void **params);
+typedef void (APIENTRYP PFNGLINDEXPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+typedef void (APIENTRYP PFNGLNORMALPOINTEREXTPROC) (GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+typedef void (APIENTRYP PFNGLTEXCOORDPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+typedef void (APIENTRYP PFNGLVERTEXPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glArrayElementEXT (GLint i);
+GLAPI void APIENTRY glColorPointerEXT (GLint size, GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+GLAPI void APIENTRY glDrawArraysEXT (GLenum mode, GLint first, GLsizei count);
+GLAPI void APIENTRY glEdgeFlagPointerEXT (GLsizei stride, GLsizei count, const GLboolean *pointer);
+GLAPI void APIENTRY glGetPointervEXT (GLenum pname, void **params);
+GLAPI void APIENTRY glIndexPointerEXT (GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+GLAPI void APIENTRY glNormalPointerEXT (GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+GLAPI void APIENTRY glTexCoordPointerEXT (GLint size, GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+GLAPI void APIENTRY glVertexPointerEXT (GLint size, GLenum type, GLsizei stride, GLsizei count, const void *pointer);
+#endif
+#endif /* GL_EXT_vertex_array */
+
+#ifndef GL_EXT_vertex_array_bgra
+#define GL_EXT_vertex_array_bgra 1
+#endif /* GL_EXT_vertex_array_bgra */
+
+#ifndef GL_EXT_vertex_attrib_64bit
+#define GL_EXT_vertex_attrib_64bit 1
+#define GL_DOUBLE_VEC2_EXT 0x8FFC
+#define GL_DOUBLE_VEC3_EXT 0x8FFD
+#define GL_DOUBLE_VEC4_EXT 0x8FFE
+#define GL_DOUBLE_MAT2_EXT 0x8F46
+#define GL_DOUBLE_MAT3_EXT 0x8F47
+#define GL_DOUBLE_MAT4_EXT 0x8F48
+#define GL_DOUBLE_MAT2x3_EXT 0x8F49
+#define GL_DOUBLE_MAT2x4_EXT 0x8F4A
+#define GL_DOUBLE_MAT3x2_EXT 0x8F4B
+#define GL_DOUBLE_MAT3x4_EXT 0x8F4C
+#define GL_DOUBLE_MAT4x2_EXT 0x8F4D
+#define GL_DOUBLE_MAT4x3_EXT 0x8F4E
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DEXTPROC) (GLuint index, GLdouble x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DEXTPROC) (GLuint index, GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DEXTPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DEXTPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1DVEXTPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL2DVEXTPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL3DVEXTPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL4DVEXTPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTEREXTPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLDVEXTPROC) (GLuint index, GLenum pname, GLdouble *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexAttribL1dEXT (GLuint index, GLdouble x);
+GLAPI void APIENTRY glVertexAttribL2dEXT (GLuint index, GLdouble x, GLdouble y);
+GLAPI void APIENTRY glVertexAttribL3dEXT (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glVertexAttribL4dEXT (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glVertexAttribL1dvEXT (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribL2dvEXT (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribL3dvEXT (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribL4dvEXT (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribLPointerEXT (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glGetVertexAttribLdvEXT (GLuint index, GLenum pname, GLdouble *params);
+#endif
+#endif /* GL_EXT_vertex_attrib_64bit */
+
+#ifndef GL_EXT_vertex_shader
+#define GL_EXT_vertex_shader 1
+#define GL_VERTEX_SHADER_EXT 0x8780
+#define GL_VERTEX_SHADER_BINDING_EXT 0x8781
+#define GL_OP_INDEX_EXT 0x8782
+#define GL_OP_NEGATE_EXT 0x8783
+#define GL_OP_DOT3_EXT 0x8784
+#define GL_OP_DOT4_EXT 0x8785
+#define GL_OP_MUL_EXT 0x8786
+#define GL_OP_ADD_EXT 0x8787
+#define GL_OP_MADD_EXT 0x8788
+#define GL_OP_FRAC_EXT 0x8789
+#define GL_OP_MAX_EXT 0x878A
+#define GL_OP_MIN_EXT 0x878B
+#define GL_OP_SET_GE_EXT 0x878C
+#define GL_OP_SET_LT_EXT 0x878D
+#define GL_OP_CLAMP_EXT 0x878E
+#define GL_OP_FLOOR_EXT 0x878F
+#define GL_OP_ROUND_EXT 0x8790
+#define GL_OP_EXP_BASE_2_EXT 0x8791
+#define GL_OP_LOG_BASE_2_EXT 0x8792
+#define GL_OP_POWER_EXT 0x8793
+#define GL_OP_RECIP_EXT 0x8794
+#define GL_OP_RECIP_SQRT_EXT 0x8795
+#define GL_OP_SUB_EXT 0x8796
+#define GL_OP_CROSS_PRODUCT_EXT 0x8797
+#define GL_OP_MULTIPLY_MATRIX_EXT 0x8798
+#define GL_OP_MOV_EXT 0x8799
+#define GL_OUTPUT_VERTEX_EXT 0x879A
+#define GL_OUTPUT_COLOR0_EXT 0x879B
+#define GL_OUTPUT_COLOR1_EXT 0x879C
+#define GL_OUTPUT_TEXTURE_COORD0_EXT 0x879D
+#define GL_OUTPUT_TEXTURE_COORD1_EXT 0x879E
+#define GL_OUTPUT_TEXTURE_COORD2_EXT 0x879F
+#define GL_OUTPUT_TEXTURE_COORD3_EXT 0x87A0
+#define GL_OUTPUT_TEXTURE_COORD4_EXT 0x87A1
+#define GL_OUTPUT_TEXTURE_COORD5_EXT 0x87A2
+#define GL_OUTPUT_TEXTURE_COORD6_EXT 0x87A3
+#define GL_OUTPUT_TEXTURE_COORD7_EXT 0x87A4
+#define GL_OUTPUT_TEXTURE_COORD8_EXT 0x87A5
+#define GL_OUTPUT_TEXTURE_COORD9_EXT 0x87A6
+#define GL_OUTPUT_TEXTURE_COORD10_EXT 0x87A7
+#define GL_OUTPUT_TEXTURE_COORD11_EXT 0x87A8
+#define GL_OUTPUT_TEXTURE_COORD12_EXT 0x87A9
+#define GL_OUTPUT_TEXTURE_COORD13_EXT 0x87AA
+#define GL_OUTPUT_TEXTURE_COORD14_EXT 0x87AB
+#define GL_OUTPUT_TEXTURE_COORD15_EXT 0x87AC
+#define GL_OUTPUT_TEXTURE_COORD16_EXT 0x87AD
+#define GL_OUTPUT_TEXTURE_COORD17_EXT 0x87AE
+#define GL_OUTPUT_TEXTURE_COORD18_EXT 0x87AF
+#define GL_OUTPUT_TEXTURE_COORD19_EXT 0x87B0
+#define GL_OUTPUT_TEXTURE_COORD20_EXT 0x87B1
+#define GL_OUTPUT_TEXTURE_COORD21_EXT 0x87B2
+#define GL_OUTPUT_TEXTURE_COORD22_EXT 0x87B3
+#define GL_OUTPUT_TEXTURE_COORD23_EXT 0x87B4
+#define GL_OUTPUT_TEXTURE_COORD24_EXT 0x87B5
+#define GL_OUTPUT_TEXTURE_COORD25_EXT 0x87B6
+#define GL_OUTPUT_TEXTURE_COORD26_EXT 0x87B7
+#define GL_OUTPUT_TEXTURE_COORD27_EXT 0x87B8
+#define GL_OUTPUT_TEXTURE_COORD28_EXT 0x87B9
+#define GL_OUTPUT_TEXTURE_COORD29_EXT 0x87BA
+#define GL_OUTPUT_TEXTURE_COORD30_EXT 0x87BB
+#define GL_OUTPUT_TEXTURE_COORD31_EXT 0x87BC
+#define GL_OUTPUT_FOG_EXT 0x87BD
+#define GL_SCALAR_EXT 0x87BE
+#define GL_VECTOR_EXT 0x87BF
+#define GL_MATRIX_EXT 0x87C0
+#define GL_VARIANT_EXT 0x87C1
+#define GL_INVARIANT_EXT 0x87C2
+#define GL_LOCAL_CONSTANT_EXT 0x87C3
+#define GL_LOCAL_EXT 0x87C4
+#define GL_MAX_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87C5
+#define GL_MAX_VERTEX_SHADER_VARIANTS_EXT 0x87C6
+#define GL_MAX_VERTEX_SHADER_INVARIANTS_EXT 0x87C7
+#define GL_MAX_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87C8
+#define GL_MAX_VERTEX_SHADER_LOCALS_EXT 0x87C9
+#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CA
+#define GL_MAX_OPTIMIZED_VERTEX_SHADER_VARIANTS_EXT 0x87CB
+#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87CC
+#define GL_MAX_OPTIMIZED_VERTEX_SHADER_INVARIANTS_EXT 0x87CD
+#define GL_MAX_OPTIMIZED_VERTEX_SHADER_LOCALS_EXT 0x87CE
+#define GL_VERTEX_SHADER_INSTRUCTIONS_EXT 0x87CF
+#define GL_VERTEX_SHADER_VARIANTS_EXT 0x87D0
+#define GL_VERTEX_SHADER_INVARIANTS_EXT 0x87D1
+#define GL_VERTEX_SHADER_LOCAL_CONSTANTS_EXT 0x87D2
+#define GL_VERTEX_SHADER_LOCALS_EXT 0x87D3
+#define GL_VERTEX_SHADER_OPTIMIZED_EXT 0x87D4
+#define GL_X_EXT 0x87D5
+#define GL_Y_EXT 0x87D6
+#define GL_Z_EXT 0x87D7
+#define GL_W_EXT 0x87D8
+#define GL_NEGATIVE_X_EXT 0x87D9
+#define GL_NEGATIVE_Y_EXT 0x87DA
+#define GL_NEGATIVE_Z_EXT 0x87DB
+#define GL_NEGATIVE_W_EXT 0x87DC
+#define GL_ZERO_EXT 0x87DD
+#define GL_ONE_EXT 0x87DE
+#define GL_NEGATIVE_ONE_EXT 0x87DF
+#define GL_NORMALIZED_RANGE_EXT 0x87E0
+#define GL_FULL_RANGE_EXT 0x87E1
+#define GL_CURRENT_VERTEX_EXT 0x87E2
+#define GL_MVP_MATRIX_EXT 0x87E3
+#define GL_VARIANT_VALUE_EXT 0x87E4
+#define GL_VARIANT_DATATYPE_EXT 0x87E5
+#define GL_VARIANT_ARRAY_STRIDE_EXT 0x87E6
+#define GL_VARIANT_ARRAY_TYPE_EXT 0x87E7
+#define GL_VARIANT_ARRAY_EXT 0x87E8
+#define GL_VARIANT_ARRAY_POINTER_EXT 0x87E9
+#define GL_INVARIANT_VALUE_EXT 0x87EA
+#define GL_INVARIANT_DATATYPE_EXT 0x87EB
+#define GL_LOCAL_CONSTANT_VALUE_EXT 0x87EC
+#define GL_LOCAL_CONSTANT_DATATYPE_EXT 0x87ED
+typedef void (APIENTRYP PFNGLBEGINVERTEXSHADEREXTPROC) (void);
+typedef void (APIENTRYP PFNGLENDVERTEXSHADEREXTPROC) (void);
+typedef void (APIENTRYP PFNGLBINDVERTEXSHADEREXTPROC) (GLuint id);
+typedef GLuint (APIENTRYP PFNGLGENVERTEXSHADERSEXTPROC) (GLuint range);
+typedef void (APIENTRYP PFNGLDELETEVERTEXSHADEREXTPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLSHADEROP1EXTPROC) (GLenum op, GLuint res, GLuint arg1);
+typedef void (APIENTRYP PFNGLSHADEROP2EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2);
+typedef void (APIENTRYP PFNGLSHADEROP3EXTPROC) (GLenum op, GLuint res, GLuint arg1, GLuint arg2, GLuint arg3);
+typedef void (APIENTRYP PFNGLSWIZZLEEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW);
+typedef void (APIENTRYP PFNGLWRITEMASKEXTPROC) (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW);
+typedef void (APIENTRYP PFNGLINSERTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num);
+typedef void (APIENTRYP PFNGLEXTRACTCOMPONENTEXTPROC) (GLuint res, GLuint src, GLuint num);
+typedef GLuint (APIENTRYP PFNGLGENSYMBOLSEXTPROC) (GLenum datatype, GLenum storagetype, GLenum range, GLuint components);
+typedef void (APIENTRYP PFNGLSETINVARIANTEXTPROC) (GLuint id, GLenum type, const void *addr);
+typedef void (APIENTRYP PFNGLSETLOCALCONSTANTEXTPROC) (GLuint id, GLenum type, const void *addr);
+typedef void (APIENTRYP PFNGLVARIANTBVEXTPROC) (GLuint id, const GLbyte *addr);
+typedef void (APIENTRYP PFNGLVARIANTSVEXTPROC) (GLuint id, const GLshort *addr);
+typedef void (APIENTRYP PFNGLVARIANTIVEXTPROC) (GLuint id, const GLint *addr);
+typedef void (APIENTRYP PFNGLVARIANTFVEXTPROC) (GLuint id, const GLfloat *addr);
+typedef void (APIENTRYP PFNGLVARIANTDVEXTPROC) (GLuint id, const GLdouble *addr);
+typedef void (APIENTRYP PFNGLVARIANTUBVEXTPROC) (GLuint id, const GLubyte *addr);
+typedef void (APIENTRYP PFNGLVARIANTUSVEXTPROC) (GLuint id, const GLushort *addr);
+typedef void (APIENTRYP PFNGLVARIANTUIVEXTPROC) (GLuint id, const GLuint *addr);
+typedef void (APIENTRYP PFNGLVARIANTPOINTEREXTPROC) (GLuint id, GLenum type, GLuint stride, const void *addr);
+typedef void (APIENTRYP PFNGLENABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLDISABLEVARIANTCLIENTSTATEEXTPROC) (GLuint id);
+typedef GLuint (APIENTRYP PFNGLBINDLIGHTPARAMETEREXTPROC) (GLenum light, GLenum value);
+typedef GLuint (APIENTRYP PFNGLBINDMATERIALPARAMETEREXTPROC) (GLenum face, GLenum value);
+typedef GLuint (APIENTRYP PFNGLBINDTEXGENPARAMETEREXTPROC) (GLenum unit, GLenum coord, GLenum value);
+typedef GLuint (APIENTRYP PFNGLBINDTEXTUREUNITPARAMETEREXTPROC) (GLenum unit, GLenum value);
+typedef GLuint (APIENTRYP PFNGLBINDPARAMETEREXTPROC) (GLenum value);
+typedef GLboolean (APIENTRYP PFNGLISVARIANTENABLEDEXTPROC) (GLuint id, GLenum cap);
+typedef void (APIENTRYP PFNGLGETVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data);
+typedef void (APIENTRYP PFNGLGETVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data);
+typedef void (APIENTRYP PFNGLGETVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data);
+typedef void (APIENTRYP PFNGLGETVARIANTPOINTERVEXTPROC) (GLuint id, GLenum value, void **data);
+typedef void (APIENTRYP PFNGLGETINVARIANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data);
+typedef void (APIENTRYP PFNGLGETINVARIANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data);
+typedef void (APIENTRYP PFNGLGETINVARIANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data);
+typedef void (APIENTRYP PFNGLGETLOCALCONSTANTBOOLEANVEXTPROC) (GLuint id, GLenum value, GLboolean *data);
+typedef void (APIENTRYP PFNGLGETLOCALCONSTANTINTEGERVEXTPROC) (GLuint id, GLenum value, GLint *data);
+typedef void (APIENTRYP PFNGLGETLOCALCONSTANTFLOATVEXTPROC) (GLuint id, GLenum value, GLfloat *data);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBeginVertexShaderEXT (void);
+GLAPI void APIENTRY glEndVertexShaderEXT (void);
+GLAPI void APIENTRY glBindVertexShaderEXT (GLuint id);
+GLAPI GLuint APIENTRY glGenVertexShadersEXT (GLuint range);
+GLAPI void APIENTRY glDeleteVertexShaderEXT (GLuint id);
+GLAPI void APIENTRY glShaderOp1EXT (GLenum op, GLuint res, GLuint arg1);
+GLAPI void APIENTRY glShaderOp2EXT (GLenum op, GLuint res, GLuint arg1, GLuint arg2);
+GLAPI void APIENTRY glShaderOp3EXT (GLenum op, GLuint res, GLuint arg1, GLuint arg2, GLuint arg3);
+GLAPI void APIENTRY glSwizzleEXT (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW);
+GLAPI void APIENTRY glWriteMaskEXT (GLuint res, GLuint in, GLenum outX, GLenum outY, GLenum outZ, GLenum outW);
+GLAPI void APIENTRY glInsertComponentEXT (GLuint res, GLuint src, GLuint num);
+GLAPI void APIENTRY glExtractComponentEXT (GLuint res, GLuint src, GLuint num);
+GLAPI GLuint APIENTRY glGenSymbolsEXT (GLenum datatype, GLenum storagetype, GLenum range, GLuint components);
+GLAPI void APIENTRY glSetInvariantEXT (GLuint id, GLenum type, const void *addr);
+GLAPI void APIENTRY glSetLocalConstantEXT (GLuint id, GLenum type, const void *addr);
+GLAPI void APIENTRY glVariantbvEXT (GLuint id, const GLbyte *addr);
+GLAPI void APIENTRY glVariantsvEXT (GLuint id, const GLshort *addr);
+GLAPI void APIENTRY glVariantivEXT (GLuint id, const GLint *addr);
+GLAPI void APIENTRY glVariantfvEXT (GLuint id, const GLfloat *addr);
+GLAPI void APIENTRY glVariantdvEXT (GLuint id, const GLdouble *addr);
+GLAPI void APIENTRY glVariantubvEXT (GLuint id, const GLubyte *addr);
+GLAPI void APIENTRY glVariantusvEXT (GLuint id, const GLushort *addr);
+GLAPI void APIENTRY glVariantuivEXT (GLuint id, const GLuint *addr);
+GLAPI void APIENTRY glVariantPointerEXT (GLuint id, GLenum type, GLuint stride, const void *addr);
+GLAPI void APIENTRY glEnableVariantClientStateEXT (GLuint id);
+GLAPI void APIENTRY glDisableVariantClientStateEXT (GLuint id);
+GLAPI GLuint APIENTRY glBindLightParameterEXT (GLenum light, GLenum value);
+GLAPI GLuint APIENTRY glBindMaterialParameterEXT (GLenum face, GLenum value);
+GLAPI GLuint APIENTRY glBindTexGenParameterEXT (GLenum unit, GLenum coord, GLenum value);
+GLAPI GLuint APIENTRY glBindTextureUnitParameterEXT (GLenum unit, GLenum value);
+GLAPI GLuint APIENTRY glBindParameterEXT (GLenum value);
+GLAPI GLboolean APIENTRY glIsVariantEnabledEXT (GLuint id, GLenum cap);
+GLAPI void APIENTRY glGetVariantBooleanvEXT (GLuint id, GLenum value, GLboolean *data);
+GLAPI void APIENTRY glGetVariantIntegervEXT (GLuint id, GLenum value, GLint *data);
+GLAPI void APIENTRY glGetVariantFloatvEXT (GLuint id, GLenum value, GLfloat *data);
+GLAPI void APIENTRY glGetVariantPointervEXT (GLuint id, GLenum value, void **data);
+GLAPI void APIENTRY glGetInvariantBooleanvEXT (GLuint id, GLenum value, GLboolean *data);
+GLAPI void APIENTRY glGetInvariantIntegervEXT (GLuint id, GLenum value, GLint *data);
+GLAPI void APIENTRY glGetInvariantFloatvEXT (GLuint id, GLenum value, GLfloat *data);
+GLAPI void APIENTRY glGetLocalConstantBooleanvEXT (GLuint id, GLenum value, GLboolean *data);
+GLAPI void APIENTRY glGetLocalConstantIntegervEXT (GLuint id, GLenum value, GLint *data);
+GLAPI void APIENTRY glGetLocalConstantFloatvEXT (GLuint id, GLenum value, GLfloat *data);
+#endif
+#endif /* GL_EXT_vertex_shader */
+
+#ifndef GL_EXT_vertex_weighting
+#define GL_EXT_vertex_weighting 1
+#define GL_MODELVIEW0_STACK_DEPTH_EXT 0x0BA3
+#define GL_MODELVIEW1_STACK_DEPTH_EXT 0x8502
+#define GL_MODELVIEW0_MATRIX_EXT 0x0BA6
+#define GL_MODELVIEW1_MATRIX_EXT 0x8506
+#define GL_VERTEX_WEIGHTING_EXT 0x8509
+#define GL_MODELVIEW0_EXT 0x1700
+#define GL_MODELVIEW1_EXT 0x850A
+#define GL_CURRENT_VERTEX_WEIGHT_EXT 0x850B
+#define GL_VERTEX_WEIGHT_ARRAY_EXT 0x850C
+#define GL_VERTEX_WEIGHT_ARRAY_SIZE_EXT 0x850D
+#define GL_VERTEX_WEIGHT_ARRAY_TYPE_EXT 0x850E
+#define GL_VERTEX_WEIGHT_ARRAY_STRIDE_EXT 0x850F
+#define GL_VERTEX_WEIGHT_ARRAY_POINTER_EXT 0x8510
+typedef void (APIENTRYP PFNGLVERTEXWEIGHTFEXTPROC) (GLfloat weight);
+typedef void (APIENTRYP PFNGLVERTEXWEIGHTFVEXTPROC) (const GLfloat *weight);
+typedef void (APIENTRYP PFNGLVERTEXWEIGHTPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, const void *pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexWeightfEXT (GLfloat weight);
+GLAPI void APIENTRY glVertexWeightfvEXT (const GLfloat *weight);
+GLAPI void APIENTRY glVertexWeightPointerEXT (GLint size, GLenum type, GLsizei stride, const void *pointer);
+#endif
+#endif /* GL_EXT_vertex_weighting */
+
+#ifndef GL_EXT_x11_sync_object
+#define GL_EXT_x11_sync_object 1
+#define GL_SYNC_X11_FENCE_EXT 0x90E1
+typedef GLsync (APIENTRYP PFNGLIMPORTSYNCEXTPROC) (GLenum external_sync_type, GLintptr external_sync, GLbitfield flags);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLsync APIENTRY glImportSyncEXT (GLenum external_sync_type, GLintptr external_sync, GLbitfield flags);
+#endif
+#endif /* GL_EXT_x11_sync_object */
+
+#ifndef GL_GREMEDY_frame_terminator
+#define GL_GREMEDY_frame_terminator 1
+typedef void (APIENTRYP PFNGLFRAMETERMINATORGREMEDYPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glFrameTerminatorGREMEDY (void);
+#endif
+#endif /* GL_GREMEDY_frame_terminator */
+
+#ifndef GL_GREMEDY_string_marker
+#define GL_GREMEDY_string_marker 1
+typedef void (APIENTRYP PFNGLSTRINGMARKERGREMEDYPROC) (GLsizei len, const void *string);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glStringMarkerGREMEDY (GLsizei len, const void *string);
+#endif
+#endif /* GL_GREMEDY_string_marker */
+
+#ifndef GL_HP_convolution_border_modes
+#define GL_HP_convolution_border_modes 1
+#define GL_IGNORE_BORDER_HP 0x8150
+#define GL_CONSTANT_BORDER_HP 0x8151
+#define GL_REPLICATE_BORDER_HP 0x8153
+#define GL_CONVOLUTION_BORDER_COLOR_HP 0x8154
+#endif /* GL_HP_convolution_border_modes */
+
+#ifndef GL_HP_image_transform
+#define GL_HP_image_transform 1
+#define GL_IMAGE_SCALE_X_HP 0x8155
+#define GL_IMAGE_SCALE_Y_HP 0x8156
+#define GL_IMAGE_TRANSLATE_X_HP 0x8157
+#define GL_IMAGE_TRANSLATE_Y_HP 0x8158
+#define GL_IMAGE_ROTATE_ANGLE_HP 0x8159
+#define GL_IMAGE_ROTATE_ORIGIN_X_HP 0x815A
+#define GL_IMAGE_ROTATE_ORIGIN_Y_HP 0x815B
+#define GL_IMAGE_MAG_FILTER_HP 0x815C
+#define GL_IMAGE_MIN_FILTER_HP 0x815D
+#define GL_IMAGE_CUBIC_WEIGHT_HP 0x815E
+#define GL_CUBIC_HP 0x815F
+#define GL_AVERAGE_HP 0x8160
+#define GL_IMAGE_TRANSFORM_2D_HP 0x8161
+#define GL_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP 0x8162
+#define GL_PROXY_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP 0x8163
+typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIHPPROC) (GLenum target, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFHPPROC) (GLenum target, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERIVHPPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETIMAGETRANSFORMPARAMETERFVHPPROC) (GLenum target, GLenum pname, GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glImageTransformParameteriHP (GLenum target, GLenum pname, GLint param);
+GLAPI void APIENTRY glImageTransformParameterfHP (GLenum target, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glImageTransformParameterivHP (GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glImageTransformParameterfvHP (GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glGetImageTransformParameterivHP (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetImageTransformParameterfvHP (GLenum target, GLenum pname, GLfloat *params);
+#endif
+#endif /* GL_HP_image_transform */
+
+#ifndef GL_HP_occlusion_test
+#define GL_HP_occlusion_test 1
+#define GL_OCCLUSION_TEST_HP 0x8165
+#define GL_OCCLUSION_TEST_RESULT_HP 0x8166
+#endif /* GL_HP_occlusion_test */
+
+#ifndef GL_HP_texture_lighting
+#define GL_HP_texture_lighting 1
+#define GL_TEXTURE_LIGHTING_MODE_HP 0x8167
+#define GL_TEXTURE_POST_SPECULAR_HP 0x8168
+#define GL_TEXTURE_PRE_SPECULAR_HP 0x8169
+#endif /* GL_HP_texture_lighting */
+
+#ifndef GL_IBM_cull_vertex
+#define GL_IBM_cull_vertex 1
+#define GL_CULL_VERTEX_IBM 103050
+#endif /* GL_IBM_cull_vertex */
+
+#ifndef GL_IBM_multimode_draw_arrays
+#define GL_IBM_multimode_draw_arrays 1
+typedef void (APIENTRYP PFNGLMULTIMODEDRAWARRAYSIBMPROC) (const GLenum *mode, const GLint *first, const GLsizei *count, GLsizei primcount, GLint modestride);
+typedef void (APIENTRYP PFNGLMULTIMODEDRAWELEMENTSIBMPROC) (const GLenum *mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei primcount, GLint modestride);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMultiModeDrawArraysIBM (const GLenum *mode, const GLint *first, const GLsizei *count, GLsizei primcount, GLint modestride);
+GLAPI void APIENTRY glMultiModeDrawElementsIBM (const GLenum *mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei primcount, GLint modestride);
+#endif
+#endif /* GL_IBM_multimode_draw_arrays */
+
+#ifndef GL_IBM_rasterpos_clip
+#define GL_IBM_rasterpos_clip 1
+#define GL_RASTER_POSITION_UNCLIPPED_IBM 0x19262
+#endif /* GL_IBM_rasterpos_clip */
+
+#ifndef GL_IBM_static_data
+#define GL_IBM_static_data 1
+#define GL_ALL_STATIC_DATA_IBM 103060
+#define GL_STATIC_VERTEX_ARRAY_IBM 103061
+typedef void (APIENTRYP PFNGLFLUSHSTATICDATAIBMPROC) (GLenum target);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glFlushStaticDataIBM (GLenum target);
+#endif
+#endif /* GL_IBM_static_data */
+
+#ifndef GL_IBM_texture_mirrored_repeat
+#define GL_IBM_texture_mirrored_repeat 1
+#define GL_MIRRORED_REPEAT_IBM 0x8370
+#endif /* GL_IBM_texture_mirrored_repeat */
+
+#ifndef GL_IBM_vertex_array_lists
+#define GL_IBM_vertex_array_lists 1
+#define GL_VERTEX_ARRAY_LIST_IBM 103070
+#define GL_NORMAL_ARRAY_LIST_IBM 103071
+#define GL_COLOR_ARRAY_LIST_IBM 103072
+#define GL_INDEX_ARRAY_LIST_IBM 103073
+#define GL_TEXTURE_COORD_ARRAY_LIST_IBM 103074
+#define GL_EDGE_FLAG_ARRAY_LIST_IBM 103075
+#define GL_FOG_COORDINATE_ARRAY_LIST_IBM 103076
+#define GL_SECONDARY_COLOR_ARRAY_LIST_IBM 103077
+#define GL_VERTEX_ARRAY_LIST_STRIDE_IBM 103080
+#define GL_NORMAL_ARRAY_LIST_STRIDE_IBM 103081
+#define GL_COLOR_ARRAY_LIST_STRIDE_IBM 103082
+#define GL_INDEX_ARRAY_LIST_STRIDE_IBM 103083
+#define GL_TEXTURE_COORD_ARRAY_LIST_STRIDE_IBM 103084
+#define GL_EDGE_FLAG_ARRAY_LIST_STRIDE_IBM 103085
+#define GL_FOG_COORDINATE_ARRAY_LIST_STRIDE_IBM 103086
+#define GL_SECONDARY_COLOR_ARRAY_LIST_STRIDE_IBM 103087
+typedef void (APIENTRYP PFNGLCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+typedef void (APIENTRYP PFNGLSECONDARYCOLORPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+typedef void (APIENTRYP PFNGLEDGEFLAGPOINTERLISTIBMPROC) (GLint stride, const GLboolean **pointer, GLint ptrstride);
+typedef void (APIENTRYP PFNGLFOGCOORDPOINTERLISTIBMPROC) (GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+typedef void (APIENTRYP PFNGLINDEXPOINTERLISTIBMPROC) (GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+typedef void (APIENTRYP PFNGLNORMALPOINTERLISTIBMPROC) (GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+typedef void (APIENTRYP PFNGLTEXCOORDPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+typedef void (APIENTRYP PFNGLVERTEXPOINTERLISTIBMPROC) (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glColorPointerListIBM (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+GLAPI void APIENTRY glSecondaryColorPointerListIBM (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+GLAPI void APIENTRY glEdgeFlagPointerListIBM (GLint stride, const GLboolean **pointer, GLint ptrstride);
+GLAPI void APIENTRY glFogCoordPointerListIBM (GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+GLAPI void APIENTRY glIndexPointerListIBM (GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+GLAPI void APIENTRY glNormalPointerListIBM (GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+GLAPI void APIENTRY glTexCoordPointerListIBM (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+GLAPI void APIENTRY glVertexPointerListIBM (GLint size, GLenum type, GLint stride, const void **pointer, GLint ptrstride);
+#endif
+#endif /* GL_IBM_vertex_array_lists */
+
+#ifndef GL_INGR_blend_func_separate
+#define GL_INGR_blend_func_separate 1
+typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEINGRPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendFuncSeparateINGR (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
+#endif
+#endif /* GL_INGR_blend_func_separate */
+
+#ifndef GL_INGR_color_clamp
+#define GL_INGR_color_clamp 1
+#define GL_RED_MIN_CLAMP_INGR 0x8560
+#define GL_GREEN_MIN_CLAMP_INGR 0x8561
+#define GL_BLUE_MIN_CLAMP_INGR 0x8562
+#define GL_ALPHA_MIN_CLAMP_INGR 0x8563
+#define GL_RED_MAX_CLAMP_INGR 0x8564
+#define GL_GREEN_MAX_CLAMP_INGR 0x8565
+#define GL_BLUE_MAX_CLAMP_INGR 0x8566
+#define GL_ALPHA_MAX_CLAMP_INGR 0x8567
+#endif /* GL_INGR_color_clamp */
+
+#ifndef GL_INGR_interlace_read
+#define GL_INGR_interlace_read 1
+#define GL_INTERLACE_READ_INGR 0x8568
+#endif /* GL_INGR_interlace_read */
+
+#ifndef GL_INTEL_fragment_shader_ordering
+#define GL_INTEL_fragment_shader_ordering 1
+#endif /* GL_INTEL_fragment_shader_ordering */
+
+#ifndef GL_INTEL_map_texture
+#define GL_INTEL_map_texture 1
+#define GL_TEXTURE_MEMORY_LAYOUT_INTEL 0x83FF
+#define GL_LAYOUT_DEFAULT_INTEL 0
+#define GL_LAYOUT_LINEAR_INTEL 1
+#define GL_LAYOUT_LINEAR_CPU_CACHED_INTEL 2
+typedef void (APIENTRYP PFNGLSYNCTEXTUREINTELPROC) (GLuint texture);
+typedef void (APIENTRYP PFNGLUNMAPTEXTURE2DINTELPROC) (GLuint texture, GLint level);
+typedef void *(APIENTRYP PFNGLMAPTEXTURE2DINTELPROC) (GLuint texture, GLint level, GLbitfield access, GLint *stride, GLenum *layout);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glSyncTextureINTEL (GLuint texture);
+GLAPI void APIENTRY glUnmapTexture2DINTEL (GLuint texture, GLint level);
+GLAPI void *APIENTRY glMapTexture2DINTEL (GLuint texture, GLint level, GLbitfield access, GLint *stride, GLenum *layout);
+#endif
+#endif /* GL_INTEL_map_texture */
+
+#ifndef GL_INTEL_parallel_arrays
+#define GL_INTEL_parallel_arrays 1
+#define GL_PARALLEL_ARRAYS_INTEL 0x83F4
+#define GL_VERTEX_ARRAY_PARALLEL_POINTERS_INTEL 0x83F5
+#define GL_NORMAL_ARRAY_PARALLEL_POINTERS_INTEL 0x83F6
+#define GL_COLOR_ARRAY_PARALLEL_POINTERS_INTEL 0x83F7
+#define GL_TEXTURE_COORD_ARRAY_PARALLEL_POINTERS_INTEL 0x83F8
+typedef void (APIENTRYP PFNGLVERTEXPOINTERVINTELPROC) (GLint size, GLenum type, const void **pointer);
+typedef void (APIENTRYP PFNGLNORMALPOINTERVINTELPROC) (GLenum type, const void **pointer);
+typedef void (APIENTRYP PFNGLCOLORPOINTERVINTELPROC) (GLint size, GLenum type, const void **pointer);
+typedef void (APIENTRYP PFNGLTEXCOORDPOINTERVINTELPROC) (GLint size, GLenum type, const void **pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexPointervINTEL (GLint size, GLenum type, const void **pointer);
+GLAPI void APIENTRY glNormalPointervINTEL (GLenum type, const void **pointer);
+GLAPI void APIENTRY glColorPointervINTEL (GLint size, GLenum type, const void **pointer);
+GLAPI void APIENTRY glTexCoordPointervINTEL (GLint size, GLenum type, const void **pointer);
+#endif
+#endif /* GL_INTEL_parallel_arrays */
+
+#ifndef GL_INTEL_performance_query
+#define GL_INTEL_performance_query 1
+#define GL_PERFQUERY_SINGLE_CONTEXT_INTEL 0x00000000
+#define GL_PERFQUERY_GLOBAL_CONTEXT_INTEL 0x00000001
+#define GL_PERFQUERY_WAIT_INTEL 0x83FB
+#define GL_PERFQUERY_FLUSH_INTEL 0x83FA
+#define GL_PERFQUERY_DONOT_FLUSH_INTEL 0x83F9
+#define GL_PERFQUERY_COUNTER_EVENT_INTEL 0x94F0
+#define GL_PERFQUERY_COUNTER_DURATION_NORM_INTEL 0x94F1
+#define GL_PERFQUERY_COUNTER_DURATION_RAW_INTEL 0x94F2
+#define GL_PERFQUERY_COUNTER_THROUGHPUT_INTEL 0x94F3
+#define GL_PERFQUERY_COUNTER_RAW_INTEL 0x94F4
+#define GL_PERFQUERY_COUNTER_TIMESTAMP_INTEL 0x94F5
+#define GL_PERFQUERY_COUNTER_DATA_UINT32_INTEL 0x94F8
+#define GL_PERFQUERY_COUNTER_DATA_UINT64_INTEL 0x94F9
+#define GL_PERFQUERY_COUNTER_DATA_FLOAT_INTEL 0x94FA
+#define GL_PERFQUERY_COUNTER_DATA_DOUBLE_INTEL 0x94FB
+#define GL_PERFQUERY_COUNTER_DATA_BOOL32_INTEL 0x94FC
+#define GL_PERFQUERY_QUERY_NAME_LENGTH_MAX_INTEL 0x94FD
+#define GL_PERFQUERY_COUNTER_NAME_LENGTH_MAX_INTEL 0x94FE
+#define GL_PERFQUERY_COUNTER_DESC_LENGTH_MAX_INTEL 0x94FF
+#define GL_PERFQUERY_GPA_EXTENDED_COUNTERS_INTEL 0x9500
+typedef void (APIENTRYP PFNGLBEGINPERFQUERYINTELPROC) (GLuint queryHandle);
+typedef void (APIENTRYP PFNGLCREATEPERFQUERYINTELPROC) (GLuint queryId, GLuint *queryHandle);
+typedef void (APIENTRYP PFNGLDELETEPERFQUERYINTELPROC) (GLuint queryHandle);
+typedef void (APIENTRYP PFNGLENDPERFQUERYINTELPROC) (GLuint queryHandle);
+typedef void (APIENTRYP PFNGLGETFIRSTPERFQUERYIDINTELPROC) (GLuint *queryId);
+typedef void (APIENTRYP PFNGLGETNEXTPERFQUERYIDINTELPROC) (GLuint queryId, GLuint *nextQueryId);
+typedef void (APIENTRYP PFNGLGETPERFCOUNTERINFOINTELPROC) (GLuint queryId, GLuint counterId, GLuint counterNameLength, GLchar *counterName, GLuint counterDescLength, GLchar *counterDesc, GLuint *counterOffset, GLuint *counterDataSize, GLuint *counterTypeEnum, GLuint *counterDataTypeEnum, GLuint64 *rawCounterMaxValue);
+typedef void (APIENTRYP PFNGLGETPERFQUERYDATAINTELPROC) (GLuint queryHandle, GLuint flags, GLsizei dataSize, GLvoid *data, GLuint *bytesWritten);
+typedef void (APIENTRYP PFNGLGETPERFQUERYIDBYNAMEINTELPROC) (GLchar *queryName, GLuint *queryId);
+typedef void (APIENTRYP PFNGLGETPERFQUERYINFOINTELPROC) (GLuint queryId, GLuint queryNameLength, GLchar *queryName, GLuint *dataSize, GLuint *noCounters, GLuint *noInstances, GLuint *capsMask);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBeginPerfQueryINTEL (GLuint queryHandle);
+GLAPI void APIENTRY glCreatePerfQueryINTEL (GLuint queryId, GLuint *queryHandle);
+GLAPI void APIENTRY glDeletePerfQueryINTEL (GLuint queryHandle);
+GLAPI void APIENTRY glEndPerfQueryINTEL (GLuint queryHandle);
+GLAPI void APIENTRY glGetFirstPerfQueryIdINTEL (GLuint *queryId);
+GLAPI void APIENTRY glGetNextPerfQueryIdINTEL (GLuint queryId, GLuint *nextQueryId);
+GLAPI void APIENTRY glGetPerfCounterInfoINTEL (GLuint queryId, GLuint counterId, GLuint counterNameLength, GLchar *counterName, GLuint counterDescLength, GLchar *counterDesc, GLuint *counterOffset, GLuint *counterDataSize, GLuint *counterTypeEnum, GLuint *counterDataTypeEnum, GLuint64 *rawCounterMaxValue);
+GLAPI void APIENTRY glGetPerfQueryDataINTEL (GLuint queryHandle, GLuint flags, GLsizei dataSize, GLvoid *data, GLuint *bytesWritten);
+GLAPI void APIENTRY glGetPerfQueryIdByNameINTEL (GLchar *queryName, GLuint *queryId);
+GLAPI void APIENTRY glGetPerfQueryInfoINTEL (GLuint queryId, GLuint queryNameLength, GLchar *queryName, GLuint *dataSize, GLuint *noCounters, GLuint *noInstances, GLuint *capsMask);
+#endif
+#endif /* GL_INTEL_performance_query */
+
+#ifndef GL_MESAX_texture_stack
+#define GL_MESAX_texture_stack 1
+#define GL_TEXTURE_1D_STACK_MESAX 0x8759
+#define GL_TEXTURE_2D_STACK_MESAX 0x875A
+#define GL_PROXY_TEXTURE_1D_STACK_MESAX 0x875B
+#define GL_PROXY_TEXTURE_2D_STACK_MESAX 0x875C
+#define GL_TEXTURE_1D_STACK_BINDING_MESAX 0x875D
+#define GL_TEXTURE_2D_STACK_BINDING_MESAX 0x875E
+#endif /* GL_MESAX_texture_stack */
+
+#ifndef GL_MESA_pack_invert
+#define GL_MESA_pack_invert 1
+#define GL_PACK_INVERT_MESA 0x8758
+#endif /* GL_MESA_pack_invert */
+
+#ifndef GL_MESA_resize_buffers
+#define GL_MESA_resize_buffers 1
+typedef void (APIENTRYP PFNGLRESIZEBUFFERSMESAPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glResizeBuffersMESA (void);
+#endif
+#endif /* GL_MESA_resize_buffers */
+
+#ifndef GL_MESA_window_pos
+#define GL_MESA_window_pos 1
+typedef void (APIENTRYP PFNGLWINDOWPOS2DMESAPROC) (GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2DVMESAPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS2FMESAPROC) (GLfloat x, GLfloat y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2FVMESAPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS2IMESAPROC) (GLint x, GLint y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2IVMESAPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS2SMESAPROC) (GLshort x, GLshort y);
+typedef void (APIENTRYP PFNGLWINDOWPOS2SVMESAPROC) (const GLshort *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3DMESAPROC) (GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3DVMESAPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3FMESAPROC) (GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3FVMESAPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3IMESAPROC) (GLint x, GLint y, GLint z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3IVMESAPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS3SMESAPROC) (GLshort x, GLshort y, GLshort z);
+typedef void (APIENTRYP PFNGLWINDOWPOS3SVMESAPROC) (const GLshort *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS4DMESAPROC) (GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLWINDOWPOS4DVMESAPROC) (const GLdouble *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS4FMESAPROC) (GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLWINDOWPOS4FVMESAPROC) (const GLfloat *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS4IMESAPROC) (GLint x, GLint y, GLint z, GLint w);
+typedef void (APIENTRYP PFNGLWINDOWPOS4IVMESAPROC) (const GLint *v);
+typedef void (APIENTRYP PFNGLWINDOWPOS4SMESAPROC) (GLshort x, GLshort y, GLshort z, GLshort w);
+typedef void (APIENTRYP PFNGLWINDOWPOS4SVMESAPROC) (const GLshort *v);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glWindowPos2dMESA (GLdouble x, GLdouble y);
+GLAPI void APIENTRY glWindowPos2dvMESA (const GLdouble *v);
+GLAPI void APIENTRY glWindowPos2fMESA (GLfloat x, GLfloat y);
+GLAPI void APIENTRY glWindowPos2fvMESA (const GLfloat *v);
+GLAPI void APIENTRY glWindowPos2iMESA (GLint x, GLint y);
+GLAPI void APIENTRY glWindowPos2ivMESA (const GLint *v);
+GLAPI void APIENTRY glWindowPos2sMESA (GLshort x, GLshort y);
+GLAPI void APIENTRY glWindowPos2svMESA (const GLshort *v);
+GLAPI void APIENTRY glWindowPos3dMESA (GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glWindowPos3dvMESA (const GLdouble *v);
+GLAPI void APIENTRY glWindowPos3fMESA (GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glWindowPos3fvMESA (const GLfloat *v);
+GLAPI void APIENTRY glWindowPos3iMESA (GLint x, GLint y, GLint z);
+GLAPI void APIENTRY glWindowPos3ivMESA (const GLint *v);
+GLAPI void APIENTRY glWindowPos3sMESA (GLshort x, GLshort y, GLshort z);
+GLAPI void APIENTRY glWindowPos3svMESA (const GLshort *v);
+GLAPI void APIENTRY glWindowPos4dMESA (GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glWindowPos4dvMESA (const GLdouble *v);
+GLAPI void APIENTRY glWindowPos4fMESA (GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glWindowPos4fvMESA (const GLfloat *v);
+GLAPI void APIENTRY glWindowPos4iMESA (GLint x, GLint y, GLint z, GLint w);
+GLAPI void APIENTRY glWindowPos4ivMESA (const GLint *v);
+GLAPI void APIENTRY glWindowPos4sMESA (GLshort x, GLshort y, GLshort z, GLshort w);
+GLAPI void APIENTRY glWindowPos4svMESA (const GLshort *v);
+#endif
+#endif /* GL_MESA_window_pos */
+
+#ifndef GL_MESA_ycbcr_texture
+#define GL_MESA_ycbcr_texture 1
+#define GL_UNSIGNED_SHORT_8_8_MESA 0x85BA
+#define GL_UNSIGNED_SHORT_8_8_REV_MESA 0x85BB
+#define GL_YCBCR_MESA 0x8757
+#endif /* GL_MESA_ycbcr_texture */
+
+#ifndef GL_NVX_conditional_render
+#define GL_NVX_conditional_render 1
+typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERNVXPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERNVXPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBeginConditionalRenderNVX (GLuint id);
+GLAPI void APIENTRY glEndConditionalRenderNVX (void);
+#endif
+#endif /* GL_NVX_conditional_render */
+
+#ifndef GL_NVX_gpu_memory_info
+#define GL_NVX_gpu_memory_info 1
+#define GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX 0x9047
+#define GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX 0x9048
+#define GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049
+#define GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX 0x904A
+#define GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX 0x904B
+#endif /* GL_NVX_gpu_memory_info */
+
+#ifndef GL_NV_bindless_multi_draw_indirect
+#define GL_NV_bindless_multi_draw_indirect 1
+typedef void (APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTBINDLESSNVPROC) (GLenum mode, const void *indirect, GLsizei drawCount, GLsizei stride, GLint vertexBufferCount);
+typedef void (APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTBINDLESSNVPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei drawCount, GLsizei stride, GLint vertexBufferCount);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMultiDrawArraysIndirectBindlessNV (GLenum mode, const void *indirect, GLsizei drawCount, GLsizei stride, GLint vertexBufferCount);
+GLAPI void APIENTRY glMultiDrawElementsIndirectBindlessNV (GLenum mode, GLenum type, const void *indirect, GLsizei drawCount, GLsizei stride, GLint vertexBufferCount);
+#endif
+#endif /* GL_NV_bindless_multi_draw_indirect */
+
+#ifndef GL_NV_bindless_texture
+#define GL_NV_bindless_texture 1
+typedef GLuint64 (APIENTRYP PFNGLGETTEXTUREHANDLENVPROC) (GLuint texture);
+typedef GLuint64 (APIENTRYP PFNGLGETTEXTURESAMPLERHANDLENVPROC) (GLuint texture, GLuint sampler);
+typedef void (APIENTRYP PFNGLMAKETEXTUREHANDLERESIDENTNVPROC) (GLuint64 handle);
+typedef void (APIENTRYP PFNGLMAKETEXTUREHANDLENONRESIDENTNVPROC) (GLuint64 handle);
+typedef GLuint64 (APIENTRYP PFNGLGETIMAGEHANDLENVPROC) (GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format);
+typedef void (APIENTRYP PFNGLMAKEIMAGEHANDLERESIDENTNVPROC) (GLuint64 handle, GLenum access);
+typedef void (APIENTRYP PFNGLMAKEIMAGEHANDLENONRESIDENTNVPROC) (GLuint64 handle);
+typedef void (APIENTRYP PFNGLUNIFORMHANDLEUI64NVPROC) (GLint location, GLuint64 value);
+typedef void (APIENTRYP PFNGLUNIFORMHANDLEUI64VNVPROC) (GLint location, GLsizei count, const GLuint64 *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64NVPROC) (GLuint program, GLint location, GLuint64 value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64 *values);
+typedef GLboolean (APIENTRYP PFNGLISTEXTUREHANDLERESIDENTNVPROC) (GLuint64 handle);
+typedef GLboolean (APIENTRYP PFNGLISIMAGEHANDLERESIDENTNVPROC) (GLuint64 handle);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLuint64 APIENTRY glGetTextureHandleNV (GLuint texture);
+GLAPI GLuint64 APIENTRY glGetTextureSamplerHandleNV (GLuint texture, GLuint sampler);
+GLAPI void APIENTRY glMakeTextureHandleResidentNV (GLuint64 handle);
+GLAPI void APIENTRY glMakeTextureHandleNonResidentNV (GLuint64 handle);
+GLAPI GLuint64 APIENTRY glGetImageHandleNV (GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format);
+GLAPI void APIENTRY glMakeImageHandleResidentNV (GLuint64 handle, GLenum access);
+GLAPI void APIENTRY glMakeImageHandleNonResidentNV (GLuint64 handle);
+GLAPI void APIENTRY glUniformHandleui64NV (GLint location, GLuint64 value);
+GLAPI void APIENTRY glUniformHandleui64vNV (GLint location, GLsizei count, const GLuint64 *value);
+GLAPI void APIENTRY glProgramUniformHandleui64NV (GLuint program, GLint location, GLuint64 value);
+GLAPI void APIENTRY glProgramUniformHandleui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64 *values);
+GLAPI GLboolean APIENTRY glIsTextureHandleResidentNV (GLuint64 handle);
+GLAPI GLboolean APIENTRY glIsImageHandleResidentNV (GLuint64 handle);
+#endif
+#endif /* GL_NV_bindless_texture */
+
+#ifndef GL_NV_blend_equation_advanced
+#define GL_NV_blend_equation_advanced 1
+#define GL_BLEND_OVERLAP_NV 0x9281
+#define GL_BLEND_PREMULTIPLIED_SRC_NV 0x9280
+#define GL_BLUE_NV 0x1905
+#define GL_COLORBURN_NV 0x929A
+#define GL_COLORDODGE_NV 0x9299
+#define GL_CONJOINT_NV 0x9284
+#define GL_CONTRAST_NV 0x92A1
+#define GL_DARKEN_NV 0x9297
+#define GL_DIFFERENCE_NV 0x929E
+#define GL_DISJOINT_NV 0x9283
+#define GL_DST_ATOP_NV 0x928F
+#define GL_DST_IN_NV 0x928B
+#define GL_DST_NV 0x9287
+#define GL_DST_OUT_NV 0x928D
+#define GL_DST_OVER_NV 0x9289
+#define GL_EXCLUSION_NV 0x92A0
+#define GL_GREEN_NV 0x1904
+#define GL_HARDLIGHT_NV 0x929B
+#define GL_HARDMIX_NV 0x92A9
+#define GL_HSL_COLOR_NV 0x92AF
+#define GL_HSL_HUE_NV 0x92AD
+#define GL_HSL_LUMINOSITY_NV 0x92B0
+#define GL_HSL_SATURATION_NV 0x92AE
+#define GL_INVERT_OVG_NV 0x92B4
+#define GL_INVERT_RGB_NV 0x92A3
+#define GL_LIGHTEN_NV 0x9298
+#define GL_LINEARBURN_NV 0x92A5
+#define GL_LINEARDODGE_NV 0x92A4
+#define GL_LINEARLIGHT_NV 0x92A7
+#define GL_MINUS_CLAMPED_NV 0x92B3
+#define GL_MINUS_NV 0x929F
+#define GL_MULTIPLY_NV 0x9294
+#define GL_OVERLAY_NV 0x9296
+#define GL_PINLIGHT_NV 0x92A8
+#define GL_PLUS_CLAMPED_ALPHA_NV 0x92B2
+#define GL_PLUS_CLAMPED_NV 0x92B1
+#define GL_PLUS_DARKER_NV 0x9292
+#define GL_PLUS_NV 0x9291
+#define GL_RED_NV 0x1903
+#define GL_SCREEN_NV 0x9295
+#define GL_SOFTLIGHT_NV 0x929C
+#define GL_SRC_ATOP_NV 0x928E
+#define GL_SRC_IN_NV 0x928A
+#define GL_SRC_NV 0x9286
+#define GL_SRC_OUT_NV 0x928C
+#define GL_SRC_OVER_NV 0x9288
+#define GL_UNCORRELATED_NV 0x9282
+#define GL_VIVIDLIGHT_NV 0x92A6
+#define GL_XOR_NV 0x1506
+typedef void (APIENTRYP PFNGLBLENDPARAMETERINVPROC) (GLenum pname, GLint value);
+typedef void (APIENTRYP PFNGLBLENDBARRIERNVPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBlendParameteriNV (GLenum pname, GLint value);
+GLAPI void APIENTRY glBlendBarrierNV (void);
+#endif
+#endif /* GL_NV_blend_equation_advanced */
+
+#ifndef GL_NV_blend_equation_advanced_coherent
+#define GL_NV_blend_equation_advanced_coherent 1
+#define GL_BLEND_ADVANCED_COHERENT_NV 0x9285
+#endif /* GL_NV_blend_equation_advanced_coherent */
+
+#ifndef GL_NV_blend_square
+#define GL_NV_blend_square 1
+#endif /* GL_NV_blend_square */
+
+#ifndef GL_NV_compute_program5
+#define GL_NV_compute_program5 1
+#define GL_COMPUTE_PROGRAM_NV 0x90FB
+#define GL_COMPUTE_PROGRAM_PARAMETER_BUFFER_NV 0x90FC
+#endif /* GL_NV_compute_program5 */
+
+#ifndef GL_NV_conditional_render
+#define GL_NV_conditional_render 1
+#define GL_QUERY_WAIT_NV 0x8E13
+#define GL_QUERY_NO_WAIT_NV 0x8E14
+#define GL_QUERY_BY_REGION_WAIT_NV 0x8E15
+#define GL_QUERY_BY_REGION_NO_WAIT_NV 0x8E16
+typedef void (APIENTRYP PFNGLBEGINCONDITIONALRENDERNVPROC) (GLuint id, GLenum mode);
+typedef void (APIENTRYP PFNGLENDCONDITIONALRENDERNVPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBeginConditionalRenderNV (GLuint id, GLenum mode);
+GLAPI void APIENTRY glEndConditionalRenderNV (void);
+#endif
+#endif /* GL_NV_conditional_render */
+
+#ifndef GL_NV_copy_depth_to_color
+#define GL_NV_copy_depth_to_color 1
+#define GL_DEPTH_STENCIL_TO_RGBA_NV 0x886E
+#define GL_DEPTH_STENCIL_TO_BGRA_NV 0x886F
+#endif /* GL_NV_copy_depth_to_color */
+
+#ifndef GL_NV_copy_image
+#define GL_NV_copy_image 1
+typedef void (APIENTRYP PFNGLCOPYIMAGESUBDATANVPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glCopyImageSubDataNV (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei width, GLsizei height, GLsizei depth);
+#endif
+#endif /* GL_NV_copy_image */
+
+#ifndef GL_NV_deep_texture3D
+#define GL_NV_deep_texture3D 1
+#define GL_MAX_DEEP_3D_TEXTURE_WIDTH_HEIGHT_NV 0x90D0
+#define GL_MAX_DEEP_3D_TEXTURE_DEPTH_NV 0x90D1
+#endif /* GL_NV_deep_texture3D */
+
+#ifndef GL_NV_depth_buffer_float
+#define GL_NV_depth_buffer_float 1
+#define GL_DEPTH_COMPONENT32F_NV 0x8DAB
+#define GL_DEPTH32F_STENCIL8_NV 0x8DAC
+#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV_NV 0x8DAD
+#define GL_DEPTH_BUFFER_FLOAT_MODE_NV 0x8DAF
+typedef void (APIENTRYP PFNGLDEPTHRANGEDNVPROC) (GLdouble zNear, GLdouble zFar);
+typedef void (APIENTRYP PFNGLCLEARDEPTHDNVPROC) (GLdouble depth);
+typedef void (APIENTRYP PFNGLDEPTHBOUNDSDNVPROC) (GLdouble zmin, GLdouble zmax);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDepthRangedNV (GLdouble zNear, GLdouble zFar);
+GLAPI void APIENTRY glClearDepthdNV (GLdouble depth);
+GLAPI void APIENTRY glDepthBoundsdNV (GLdouble zmin, GLdouble zmax);
+#endif
+#endif /* GL_NV_depth_buffer_float */
+
+#ifndef GL_NV_depth_clamp
+#define GL_NV_depth_clamp 1
+#define GL_DEPTH_CLAMP_NV 0x864F
+#endif /* GL_NV_depth_clamp */
+
+#ifndef GL_NV_draw_texture
+#define GL_NV_draw_texture 1
+typedef void (APIENTRYP PFNGLDRAWTEXTURENVPROC) (GLuint texture, GLuint sampler, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1, GLfloat z, GLfloat s0, GLfloat t0, GLfloat s1, GLfloat t1);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawTextureNV (GLuint texture, GLuint sampler, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1, GLfloat z, GLfloat s0, GLfloat t0, GLfloat s1, GLfloat t1);
+#endif
+#endif /* GL_NV_draw_texture */
+
+#ifndef GL_NV_evaluators
+#define GL_NV_evaluators 1
+#define GL_EVAL_2D_NV 0x86C0
+#define GL_EVAL_TRIANGULAR_2D_NV 0x86C1
+#define GL_MAP_TESSELLATION_NV 0x86C2
+#define GL_MAP_ATTRIB_U_ORDER_NV 0x86C3
+#define GL_MAP_ATTRIB_V_ORDER_NV 0x86C4
+#define GL_EVAL_FRACTIONAL_TESSELLATION_NV 0x86C5
+#define GL_EVAL_VERTEX_ATTRIB0_NV 0x86C6
+#define GL_EVAL_VERTEX_ATTRIB1_NV 0x86C7
+#define GL_EVAL_VERTEX_ATTRIB2_NV 0x86C8
+#define GL_EVAL_VERTEX_ATTRIB3_NV 0x86C9
+#define GL_EVAL_VERTEX_ATTRIB4_NV 0x86CA
+#define GL_EVAL_VERTEX_ATTRIB5_NV 0x86CB
+#define GL_EVAL_VERTEX_ATTRIB6_NV 0x86CC
+#define GL_EVAL_VERTEX_ATTRIB7_NV 0x86CD
+#define GL_EVAL_VERTEX_ATTRIB8_NV 0x86CE
+#define GL_EVAL_VERTEX_ATTRIB9_NV 0x86CF
+#define GL_EVAL_VERTEX_ATTRIB10_NV 0x86D0
+#define GL_EVAL_VERTEX_ATTRIB11_NV 0x86D1
+#define GL_EVAL_VERTEX_ATTRIB12_NV 0x86D2
+#define GL_EVAL_VERTEX_ATTRIB13_NV 0x86D3
+#define GL_EVAL_VERTEX_ATTRIB14_NV 0x86D4
+#define GL_EVAL_VERTEX_ATTRIB15_NV 0x86D5
+#define GL_MAX_MAP_TESSELLATION_NV 0x86D6
+#define GL_MAX_RATIONAL_EVAL_ORDER_NV 0x86D7
+typedef void (APIENTRYP PFNGLMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLint uorder, GLint vorder, GLboolean packed, const void *points);
+typedef void (APIENTRYP PFNGLMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLGETMAPCONTROLPOINTSNVPROC) (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLboolean packed, void *points);
+typedef void (APIENTRYP PFNGLGETMAPPARAMETERIVNVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETMAPPARAMETERFVNVPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERIVNVPROC) (GLenum target, GLuint index, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETMAPATTRIBPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLEVALMAPSNVPROC) (GLenum target, GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMapControlPointsNV (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLint uorder, GLint vorder, GLboolean packed, const void *points);
+GLAPI void APIENTRY glMapParameterivNV (GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glMapParameterfvNV (GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glGetMapControlPointsNV (GLenum target, GLuint index, GLenum type, GLsizei ustride, GLsizei vstride, GLboolean packed, void *points);
+GLAPI void APIENTRY glGetMapParameterivNV (GLenum target, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetMapParameterfvNV (GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetMapAttribParameterivNV (GLenum target, GLuint index, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetMapAttribParameterfvNV (GLenum target, GLuint index, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glEvalMapsNV (GLenum target, GLenum mode);
+#endif
+#endif /* GL_NV_evaluators */
+
+#ifndef GL_NV_explicit_multisample
+#define GL_NV_explicit_multisample 1
+#define GL_SAMPLE_POSITION_NV 0x8E50
+#define GL_SAMPLE_MASK_NV 0x8E51
+#define GL_SAMPLE_MASK_VALUE_NV 0x8E52
+#define GL_TEXTURE_BINDING_RENDERBUFFER_NV 0x8E53
+#define GL_TEXTURE_RENDERBUFFER_DATA_STORE_BINDING_NV 0x8E54
+#define GL_TEXTURE_RENDERBUFFER_NV 0x8E55
+#define GL_SAMPLER_RENDERBUFFER_NV 0x8E56
+#define GL_INT_SAMPLER_RENDERBUFFER_NV 0x8E57
+#define GL_UNSIGNED_INT_SAMPLER_RENDERBUFFER_NV 0x8E58
+#define GL_MAX_SAMPLE_MASK_WORDS_NV 0x8E59
+typedef void (APIENTRYP PFNGLGETMULTISAMPLEFVNVPROC) (GLenum pname, GLuint index, GLfloat *val);
+typedef void (APIENTRYP PFNGLSAMPLEMASKINDEXEDNVPROC) (GLuint index, GLbitfield mask);
+typedef void (APIENTRYP PFNGLTEXRENDERBUFFERNVPROC) (GLenum target, GLuint renderbuffer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGetMultisamplefvNV (GLenum pname, GLuint index, GLfloat *val);
+GLAPI void APIENTRY glSampleMaskIndexedNV (GLuint index, GLbitfield mask);
+GLAPI void APIENTRY glTexRenderbufferNV (GLenum target, GLuint renderbuffer);
+#endif
+#endif /* GL_NV_explicit_multisample */
+
+#ifndef GL_NV_fence
+#define GL_NV_fence 1
+#define GL_ALL_COMPLETED_NV 0x84F2
+#define GL_FENCE_STATUS_NV 0x84F3
+#define GL_FENCE_CONDITION_NV 0x84F4
+typedef void (APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences);
+typedef void (APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences);
+typedef GLboolean (APIENTRYP PFNGLISFENCENVPROC) (GLuint fence);
+typedef GLboolean (APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence);
+typedef void (APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence);
+typedef void (APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDeleteFencesNV (GLsizei n, const GLuint *fences);
+GLAPI void APIENTRY glGenFencesNV (GLsizei n, GLuint *fences);
+GLAPI GLboolean APIENTRY glIsFenceNV (GLuint fence);
+GLAPI GLboolean APIENTRY glTestFenceNV (GLuint fence);
+GLAPI void APIENTRY glGetFenceivNV (GLuint fence, GLenum pname, GLint *params);
+GLAPI void APIENTRY glFinishFenceNV (GLuint fence);
+GLAPI void APIENTRY glSetFenceNV (GLuint fence, GLenum condition);
+#endif
+#endif /* GL_NV_fence */
+
+#ifndef GL_NV_float_buffer
+#define GL_NV_float_buffer 1
+#define GL_FLOAT_R_NV 0x8880
+#define GL_FLOAT_RG_NV 0x8881
+#define GL_FLOAT_RGB_NV 0x8882
+#define GL_FLOAT_RGBA_NV 0x8883
+#define GL_FLOAT_R16_NV 0x8884
+#define GL_FLOAT_R32_NV 0x8885
+#define GL_FLOAT_RG16_NV 0x8886
+#define GL_FLOAT_RG32_NV 0x8887
+#define GL_FLOAT_RGB16_NV 0x8888
+#define GL_FLOAT_RGB32_NV 0x8889
+#define GL_FLOAT_RGBA16_NV 0x888A
+#define GL_FLOAT_RGBA32_NV 0x888B
+#define GL_TEXTURE_FLOAT_COMPONENTS_NV 0x888C
+#define GL_FLOAT_CLEAR_COLOR_VALUE_NV 0x888D
+#define GL_FLOAT_RGBA_MODE_NV 0x888E
+#endif /* GL_NV_float_buffer */
+
+#ifndef GL_NV_fog_distance
+#define GL_NV_fog_distance 1
+#define GL_FOG_DISTANCE_MODE_NV 0x855A
+#define GL_EYE_RADIAL_NV 0x855B
+#define GL_EYE_PLANE_ABSOLUTE_NV 0x855C
+#endif /* GL_NV_fog_distance */
+
+#ifndef GL_NV_fragment_program
+#define GL_NV_fragment_program 1
+#define GL_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMETERS_NV 0x8868
+#define GL_FRAGMENT_PROGRAM_NV 0x8870
+#define GL_MAX_TEXTURE_COORDS_NV 0x8871
+#define GL_MAX_TEXTURE_IMAGE_UNITS_NV 0x8872
+#define GL_FRAGMENT_PROGRAM_BINDING_NV 0x8873
+#define GL_PROGRAM_ERROR_STRING_NV 0x8874
+typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4FVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLfloat *v);
+typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLPROGRAMNAMEDPARAMETER4DVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, const GLdouble *v);
+typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERFVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMNAMEDPARAMETERDVNVPROC) (GLuint id, GLsizei len, const GLubyte *name, GLdouble *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProgramNamedParameter4fNV (GLuint id, GLsizei len, const GLubyte *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glProgramNamedParameter4fvNV (GLuint id, GLsizei len, const GLubyte *name, const GLfloat *v);
+GLAPI void APIENTRY glProgramNamedParameter4dNV (GLuint id, GLsizei len, const GLubyte *name, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glProgramNamedParameter4dvNV (GLuint id, GLsizei len, const GLubyte *name, const GLdouble *v);
+GLAPI void APIENTRY glGetProgramNamedParameterfvNV (GLuint id, GLsizei len, const GLubyte *name, GLfloat *params);
+GLAPI void APIENTRY glGetProgramNamedParameterdvNV (GLuint id, GLsizei len, const GLubyte *name, GLdouble *params);
+#endif
+#endif /* GL_NV_fragment_program */
+
+#ifndef GL_NV_fragment_program2
+#define GL_NV_fragment_program2 1
+#define GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV 0x88F4
+#define GL_MAX_PROGRAM_CALL_DEPTH_NV 0x88F5
+#define GL_MAX_PROGRAM_IF_DEPTH_NV 0x88F6
+#define GL_MAX_PROGRAM_LOOP_DEPTH_NV 0x88F7
+#define GL_MAX_PROGRAM_LOOP_COUNT_NV 0x88F8
+#endif /* GL_NV_fragment_program2 */
+
+#ifndef GL_NV_fragment_program4
+#define GL_NV_fragment_program4 1
+#endif /* GL_NV_fragment_program4 */
+
+#ifndef GL_NV_fragment_program_option
+#define GL_NV_fragment_program_option 1
+#endif /* GL_NV_fragment_program_option */
+
+#ifndef GL_NV_framebuffer_multisample_coverage
+#define GL_NV_framebuffer_multisample_coverage 1
+#define GL_RENDERBUFFER_COVERAGE_SAMPLES_NV 0x8CAB
+#define GL_RENDERBUFFER_COLOR_SAMPLES_NV 0x8E10
+#define GL_MAX_MULTISAMPLE_COVERAGE_MODES_NV 0x8E11
+#define GL_MULTISAMPLE_COVERAGE_MODES_NV 0x8E12
+typedef void (APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLECOVERAGENVPROC) (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glRenderbufferStorageMultisampleCoverageNV (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLenum internalformat, GLsizei width, GLsizei height);
+#endif
+#endif /* GL_NV_framebuffer_multisample_coverage */
+
+#ifndef GL_NV_geometry_program4
+#define GL_NV_geometry_program4 1
+#define GL_GEOMETRY_PROGRAM_NV 0x8C26
+#define GL_MAX_PROGRAM_OUTPUT_VERTICES_NV 0x8C27
+#define GL_MAX_PROGRAM_TOTAL_OUTPUT_COMPONENTS_NV 0x8C28
+typedef void (APIENTRYP PFNGLPROGRAMVERTEXLIMITNVPROC) (GLenum target, GLint limit);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREEXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYEREXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer);
+typedef void (APIENTRYP PFNGLFRAMEBUFFERTEXTUREFACEEXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProgramVertexLimitNV (GLenum target, GLint limit);
+GLAPI void APIENTRY glFramebufferTextureEXT (GLenum target, GLenum attachment, GLuint texture, GLint level);
+GLAPI void APIENTRY glFramebufferTextureLayerEXT (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer);
+GLAPI void APIENTRY glFramebufferTextureFaceEXT (GLenum target, GLenum attachment, GLuint texture, GLint level, GLenum face);
+#endif
+#endif /* GL_NV_geometry_program4 */
+
+#ifndef GL_NV_geometry_shader4
+#define GL_NV_geometry_shader4 1
+#endif /* GL_NV_geometry_shader4 */
+
+#ifndef GL_NV_gpu_program4
+#define GL_NV_gpu_program4 1
+#define GL_MIN_PROGRAM_TEXEL_OFFSET_NV 0x8904
+#define GL_MAX_PROGRAM_TEXEL_OFFSET_NV 0x8905
+#define GL_PROGRAM_ATTRIB_COMPONENTS_NV 0x8906
+#define GL_PROGRAM_RESULT_COMPONENTS_NV 0x8907
+#define GL_MAX_PROGRAM_ATTRIB_COMPONENTS_NV 0x8908
+#define GL_MAX_PROGRAM_RESULT_COMPONENTS_NV 0x8909
+#define GL_MAX_PROGRAM_GENERIC_ATTRIBS_NV 0x8DA5
+#define GL_MAX_PROGRAM_GENERIC_RESULTS_NV 0x8DA6
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4INVPROC) (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4IVNVPROC) (GLenum target, GLuint index, const GLint *params);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERSI4IVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLint *params);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4UINVPROC) (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERI4UIVNVPROC) (GLenum target, GLuint index, const GLuint *params);
+typedef void (APIENTRYP PFNGLPROGRAMLOCALPARAMETERSI4UIVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLuint *params);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4INVPROC) (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4IVNVPROC) (GLenum target, GLuint index, const GLint *params);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERSI4IVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLint *params);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4UINVPROC) (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERI4UIVNVPROC) (GLenum target, GLuint index, const GLuint *params);
+typedef void (APIENTRYP PFNGLPROGRAMENVPARAMETERSI4UIVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLuint *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERIIVNVPROC) (GLenum target, GLuint index, GLint *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMLOCALPARAMETERIUIVNVPROC) (GLenum target, GLuint index, GLuint *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERIIVNVPROC) (GLenum target, GLuint index, GLint *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMENVPARAMETERIUIVNVPROC) (GLenum target, GLuint index, GLuint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProgramLocalParameterI4iNV (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w);
+GLAPI void APIENTRY glProgramLocalParameterI4ivNV (GLenum target, GLuint index, const GLint *params);
+GLAPI void APIENTRY glProgramLocalParametersI4ivNV (GLenum target, GLuint index, GLsizei count, const GLint *params);
+GLAPI void APIENTRY glProgramLocalParameterI4uiNV (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+GLAPI void APIENTRY glProgramLocalParameterI4uivNV (GLenum target, GLuint index, const GLuint *params);
+GLAPI void APIENTRY glProgramLocalParametersI4uivNV (GLenum target, GLuint index, GLsizei count, const GLuint *params);
+GLAPI void APIENTRY glProgramEnvParameterI4iNV (GLenum target, GLuint index, GLint x, GLint y, GLint z, GLint w);
+GLAPI void APIENTRY glProgramEnvParameterI4ivNV (GLenum target, GLuint index, const GLint *params);
+GLAPI void APIENTRY glProgramEnvParametersI4ivNV (GLenum target, GLuint index, GLsizei count, const GLint *params);
+GLAPI void APIENTRY glProgramEnvParameterI4uiNV (GLenum target, GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+GLAPI void APIENTRY glProgramEnvParameterI4uivNV (GLenum target, GLuint index, const GLuint *params);
+GLAPI void APIENTRY glProgramEnvParametersI4uivNV (GLenum target, GLuint index, GLsizei count, const GLuint *params);
+GLAPI void APIENTRY glGetProgramLocalParameterIivNV (GLenum target, GLuint index, GLint *params);
+GLAPI void APIENTRY glGetProgramLocalParameterIuivNV (GLenum target, GLuint index, GLuint *params);
+GLAPI void APIENTRY glGetProgramEnvParameterIivNV (GLenum target, GLuint index, GLint *params);
+GLAPI void APIENTRY glGetProgramEnvParameterIuivNV (GLenum target, GLuint index, GLuint *params);
+#endif
+#endif /* GL_NV_gpu_program4 */
+
+#ifndef GL_NV_gpu_program5
+#define GL_NV_gpu_program5 1
+#define GL_MAX_GEOMETRY_PROGRAM_INVOCATIONS_NV 0x8E5A
+#define GL_MIN_FRAGMENT_INTERPOLATION_OFFSET_NV 0x8E5B
+#define GL_MAX_FRAGMENT_INTERPOLATION_OFFSET_NV 0x8E5C
+#define GL_FRAGMENT_PROGRAM_INTERPOLATION_OFFSET_BITS_NV 0x8E5D
+#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET_NV 0x8E5E
+#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET_NV 0x8E5F
+#define GL_MAX_PROGRAM_SUBROUTINE_PARAMETERS_NV 0x8F44
+#define GL_MAX_PROGRAM_SUBROUTINE_NUM_NV 0x8F45
+typedef void (APIENTRYP PFNGLPROGRAMSUBROUTINEPARAMETERSUIVNVPROC) (GLenum target, GLsizei count, const GLuint *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMSUBROUTINEPARAMETERUIVNVPROC) (GLenum target, GLuint index, GLuint *param);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProgramSubroutineParametersuivNV (GLenum target, GLsizei count, const GLuint *params);
+GLAPI void APIENTRY glGetProgramSubroutineParameteruivNV (GLenum target, GLuint index, GLuint *param);
+#endif
+#endif /* GL_NV_gpu_program5 */
+
+#ifndef GL_NV_gpu_program5_mem_extended
+#define GL_NV_gpu_program5_mem_extended 1
+#endif /* GL_NV_gpu_program5_mem_extended */
+
+#ifndef GL_NV_gpu_shader5
+#define GL_NV_gpu_shader5 1
+#endif /* GL_NV_gpu_shader5 */
+
+#ifndef GL_NV_half_float
+#define GL_NV_half_float 1
+typedef unsigned short GLhalfNV;
+#define GL_HALF_FLOAT_NV 0x140B
+typedef void (APIENTRYP PFNGLVERTEX2HNVPROC) (GLhalfNV x, GLhalfNV y);
+typedef void (APIENTRYP PFNGLVERTEX2HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEX3HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z);
+typedef void (APIENTRYP PFNGLVERTEX3HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEX4HNVPROC) (GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w);
+typedef void (APIENTRYP PFNGLVERTEX4HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLNORMAL3HNVPROC) (GLhalfNV nx, GLhalfNV ny, GLhalfNV nz);
+typedef void (APIENTRYP PFNGLNORMAL3HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue);
+typedef void (APIENTRYP PFNGLCOLOR3HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLCOLOR4HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue, GLhalfNV alpha);
+typedef void (APIENTRYP PFNGLCOLOR4HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLTEXCOORD1HNVPROC) (GLhalfNV s);
+typedef void (APIENTRYP PFNGLTEXCOORD1HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLTEXCOORD2HNVPROC) (GLhalfNV s, GLhalfNV t);
+typedef void (APIENTRYP PFNGLTEXCOORD2HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLTEXCOORD3HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r);
+typedef void (APIENTRYP PFNGLTEXCOORD3HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLTEXCOORD4HNVPROC) (GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q);
+typedef void (APIENTRYP PFNGLTEXCOORD4HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1HNVPROC) (GLenum target, GLhalfNV s);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD1HVNVPROC) (GLenum target, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD2HVNVPROC) (GLenum target, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD3HVNVPROC) (GLenum target, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4HNVPROC) (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q);
+typedef void (APIENTRYP PFNGLMULTITEXCOORD4HVNVPROC) (GLenum target, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLFOGCOORDHNVPROC) (GLhalfNV fog);
+typedef void (APIENTRYP PFNGLFOGCOORDHVNVPROC) (const GLhalfNV *fog);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HNVPROC) (GLhalfNV red, GLhalfNV green, GLhalfNV blue);
+typedef void (APIENTRYP PFNGLSECONDARYCOLOR3HVNVPROC) (const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEXWEIGHTHNVPROC) (GLhalfNV weight);
+typedef void (APIENTRYP PFNGLVERTEXWEIGHTHVNVPROC) (const GLhalfNV *weight);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1HNVPROC) (GLuint index, GLhalfNV x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1HVNVPROC) (GLuint index, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2HVNVPROC) (GLuint index, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3HVNVPROC) (GLuint index, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4HNVPROC) (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4HVNVPROC) (GLuint index, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS1HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS2HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS3HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS4HVNVPROC) (GLuint index, GLsizei n, const GLhalfNV *v);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertex2hNV (GLhalfNV x, GLhalfNV y);
+GLAPI void APIENTRY glVertex2hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glVertex3hNV (GLhalfNV x, GLhalfNV y, GLhalfNV z);
+GLAPI void APIENTRY glVertex3hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glVertex4hNV (GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w);
+GLAPI void APIENTRY glVertex4hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glNormal3hNV (GLhalfNV nx, GLhalfNV ny, GLhalfNV nz);
+GLAPI void APIENTRY glNormal3hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glColor3hNV (GLhalfNV red, GLhalfNV green, GLhalfNV blue);
+GLAPI void APIENTRY glColor3hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glColor4hNV (GLhalfNV red, GLhalfNV green, GLhalfNV blue, GLhalfNV alpha);
+GLAPI void APIENTRY glColor4hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glTexCoord1hNV (GLhalfNV s);
+GLAPI void APIENTRY glTexCoord1hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glTexCoord2hNV (GLhalfNV s, GLhalfNV t);
+GLAPI void APIENTRY glTexCoord2hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glTexCoord3hNV (GLhalfNV s, GLhalfNV t, GLhalfNV r);
+GLAPI void APIENTRY glTexCoord3hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glTexCoord4hNV (GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q);
+GLAPI void APIENTRY glTexCoord4hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glMultiTexCoord1hNV (GLenum target, GLhalfNV s);
+GLAPI void APIENTRY glMultiTexCoord1hvNV (GLenum target, const GLhalfNV *v);
+GLAPI void APIENTRY glMultiTexCoord2hNV (GLenum target, GLhalfNV s, GLhalfNV t);
+GLAPI void APIENTRY glMultiTexCoord2hvNV (GLenum target, const GLhalfNV *v);
+GLAPI void APIENTRY glMultiTexCoord3hNV (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r);
+GLAPI void APIENTRY glMultiTexCoord3hvNV (GLenum target, const GLhalfNV *v);
+GLAPI void APIENTRY glMultiTexCoord4hNV (GLenum target, GLhalfNV s, GLhalfNV t, GLhalfNV r, GLhalfNV q);
+GLAPI void APIENTRY glMultiTexCoord4hvNV (GLenum target, const GLhalfNV *v);
+GLAPI void APIENTRY glFogCoordhNV (GLhalfNV fog);
+GLAPI void APIENTRY glFogCoordhvNV (const GLhalfNV *fog);
+GLAPI void APIENTRY glSecondaryColor3hNV (GLhalfNV red, GLhalfNV green, GLhalfNV blue);
+GLAPI void APIENTRY glSecondaryColor3hvNV (const GLhalfNV *v);
+GLAPI void APIENTRY glVertexWeighthNV (GLhalfNV weight);
+GLAPI void APIENTRY glVertexWeighthvNV (const GLhalfNV *weight);
+GLAPI void APIENTRY glVertexAttrib1hNV (GLuint index, GLhalfNV x);
+GLAPI void APIENTRY glVertexAttrib1hvNV (GLuint index, const GLhalfNV *v);
+GLAPI void APIENTRY glVertexAttrib2hNV (GLuint index, GLhalfNV x, GLhalfNV y);
+GLAPI void APIENTRY glVertexAttrib2hvNV (GLuint index, const GLhalfNV *v);
+GLAPI void APIENTRY glVertexAttrib3hNV (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z);
+GLAPI void APIENTRY glVertexAttrib3hvNV (GLuint index, const GLhalfNV *v);
+GLAPI void APIENTRY glVertexAttrib4hNV (GLuint index, GLhalfNV x, GLhalfNV y, GLhalfNV z, GLhalfNV w);
+GLAPI void APIENTRY glVertexAttrib4hvNV (GLuint index, const GLhalfNV *v);
+GLAPI void APIENTRY glVertexAttribs1hvNV (GLuint index, GLsizei n, const GLhalfNV *v);
+GLAPI void APIENTRY glVertexAttribs2hvNV (GLuint index, GLsizei n, const GLhalfNV *v);
+GLAPI void APIENTRY glVertexAttribs3hvNV (GLuint index, GLsizei n, const GLhalfNV *v);
+GLAPI void APIENTRY glVertexAttribs4hvNV (GLuint index, GLsizei n, const GLhalfNV *v);
+#endif
+#endif /* GL_NV_half_float */
+
+#ifndef GL_NV_light_max_exponent
+#define GL_NV_light_max_exponent 1
+#define GL_MAX_SHININESS_NV 0x8504
+#define GL_MAX_SPOT_EXPONENT_NV 0x8505
+#endif /* GL_NV_light_max_exponent */
+
+#ifndef GL_NV_multisample_coverage
+#define GL_NV_multisample_coverage 1
+#define GL_COLOR_SAMPLES_NV 0x8E20
+#endif /* GL_NV_multisample_coverage */
+
+#ifndef GL_NV_multisample_filter_hint
+#define GL_NV_multisample_filter_hint 1
+#define GL_MULTISAMPLE_FILTER_HINT_NV 0x8534
+#endif /* GL_NV_multisample_filter_hint */
+
+#ifndef GL_NV_occlusion_query
+#define GL_NV_occlusion_query 1
+#define GL_PIXEL_COUNTER_BITS_NV 0x8864
+#define GL_CURRENT_OCCLUSION_QUERY_ID_NV 0x8865
+#define GL_PIXEL_COUNT_NV 0x8866
+#define GL_PIXEL_COUNT_AVAILABLE_NV 0x8867
+typedef void (APIENTRYP PFNGLGENOCCLUSIONQUERIESNVPROC) (GLsizei n, GLuint *ids);
+typedef void (APIENTRYP PFNGLDELETEOCCLUSIONQUERIESNVPROC) (GLsizei n, const GLuint *ids);
+typedef GLboolean (APIENTRYP PFNGLISOCCLUSIONQUERYNVPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLBEGINOCCLUSIONQUERYNVPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLENDOCCLUSIONQUERYNVPROC) (void);
+typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYIVNVPROC) (GLuint id, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETOCCLUSIONQUERYUIVNVPROC) (GLuint id, GLenum pname, GLuint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGenOcclusionQueriesNV (GLsizei n, GLuint *ids);
+GLAPI void APIENTRY glDeleteOcclusionQueriesNV (GLsizei n, const GLuint *ids);
+GLAPI GLboolean APIENTRY glIsOcclusionQueryNV (GLuint id);
+GLAPI void APIENTRY glBeginOcclusionQueryNV (GLuint id);
+GLAPI void APIENTRY glEndOcclusionQueryNV (void);
+GLAPI void APIENTRY glGetOcclusionQueryivNV (GLuint id, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetOcclusionQueryuivNV (GLuint id, GLenum pname, GLuint *params);
+#endif
+#endif /* GL_NV_occlusion_query */
+
+#ifndef GL_NV_packed_depth_stencil
+#define GL_NV_packed_depth_stencil 1
+#define GL_DEPTH_STENCIL_NV 0x84F9
+#define GL_UNSIGNED_INT_24_8_NV 0x84FA
+#endif /* GL_NV_packed_depth_stencil */
+
+#ifndef GL_NV_parameter_buffer_object
+#define GL_NV_parameter_buffer_object 1
+#define GL_MAX_PROGRAM_PARAMETER_BUFFER_BINDINGS_NV 0x8DA0
+#define GL_MAX_PROGRAM_PARAMETER_BUFFER_SIZE_NV 0x8DA1
+#define GL_VERTEX_PROGRAM_PARAMETER_BUFFER_NV 0x8DA2
+#define GL_GEOMETRY_PROGRAM_PARAMETER_BUFFER_NV 0x8DA3
+#define GL_FRAGMENT_PROGRAM_PARAMETER_BUFFER_NV 0x8DA4
+typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSFVNVPROC) (GLenum target, GLuint bindingIndex, GLuint wordIndex, GLsizei count, const GLfloat *params);
+typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSIIVNVPROC) (GLenum target, GLuint bindingIndex, GLuint wordIndex, GLsizei count, const GLint *params);
+typedef void (APIENTRYP PFNGLPROGRAMBUFFERPARAMETERSIUIVNVPROC) (GLenum target, GLuint bindingIndex, GLuint wordIndex, GLsizei count, const GLuint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glProgramBufferParametersfvNV (GLenum target, GLuint bindingIndex, GLuint wordIndex, GLsizei count, const GLfloat *params);
+GLAPI void APIENTRY glProgramBufferParametersIivNV (GLenum target, GLuint bindingIndex, GLuint wordIndex, GLsizei count, const GLint *params);
+GLAPI void APIENTRY glProgramBufferParametersIuivNV (GLenum target, GLuint bindingIndex, GLuint wordIndex, GLsizei count, const GLuint *params);
+#endif
+#endif /* GL_NV_parameter_buffer_object */
+
+#ifndef GL_NV_parameter_buffer_object2
+#define GL_NV_parameter_buffer_object2 1
+#endif /* GL_NV_parameter_buffer_object2 */
+
+#ifndef GL_NV_path_rendering
+#define GL_NV_path_rendering 1
+#define GL_PATH_FORMAT_SVG_NV 0x9070
+#define GL_PATH_FORMAT_PS_NV 0x9071
+#define GL_STANDARD_FONT_NAME_NV 0x9072
+#define GL_SYSTEM_FONT_NAME_NV 0x9073
+#define GL_FILE_NAME_NV 0x9074
+#define GL_PATH_STROKE_WIDTH_NV 0x9075
+#define GL_PATH_END_CAPS_NV 0x9076
+#define GL_PATH_INITIAL_END_CAP_NV 0x9077
+#define GL_PATH_TERMINAL_END_CAP_NV 0x9078
+#define GL_PATH_JOIN_STYLE_NV 0x9079
+#define GL_PATH_MITER_LIMIT_NV 0x907A
+#define GL_PATH_DASH_CAPS_NV 0x907B
+#define GL_PATH_INITIAL_DASH_CAP_NV 0x907C
+#define GL_PATH_TERMINAL_DASH_CAP_NV 0x907D
+#define GL_PATH_DASH_OFFSET_NV 0x907E
+#define GL_PATH_CLIENT_LENGTH_NV 0x907F
+#define GL_PATH_FILL_MODE_NV 0x9080
+#define GL_PATH_FILL_MASK_NV 0x9081
+#define GL_PATH_FILL_COVER_MODE_NV 0x9082
+#define GL_PATH_STROKE_COVER_MODE_NV 0x9083
+#define GL_PATH_STROKE_MASK_NV 0x9084
+#define GL_COUNT_UP_NV 0x9088
+#define GL_COUNT_DOWN_NV 0x9089
+#define GL_PATH_OBJECT_BOUNDING_BOX_NV 0x908A
+#define GL_CONVEX_HULL_NV 0x908B
+#define GL_BOUNDING_BOX_NV 0x908D
+#define GL_TRANSLATE_X_NV 0x908E
+#define GL_TRANSLATE_Y_NV 0x908F
+#define GL_TRANSLATE_2D_NV 0x9090
+#define GL_TRANSLATE_3D_NV 0x9091
+#define GL_AFFINE_2D_NV 0x9092
+#define GL_AFFINE_3D_NV 0x9094
+#define GL_TRANSPOSE_AFFINE_2D_NV 0x9096
+#define GL_TRANSPOSE_AFFINE_3D_NV 0x9098
+#define GL_UTF8_NV 0x909A
+#define GL_UTF16_NV 0x909B
+#define GL_BOUNDING_BOX_OF_BOUNDING_BOXES_NV 0x909C
+#define GL_PATH_COMMAND_COUNT_NV 0x909D
+#define GL_PATH_COORD_COUNT_NV 0x909E
+#define GL_PATH_DASH_ARRAY_COUNT_NV 0x909F
+#define GL_PATH_COMPUTED_LENGTH_NV 0x90A0
+#define GL_PATH_FILL_BOUNDING_BOX_NV 0x90A1
+#define GL_PATH_STROKE_BOUNDING_BOX_NV 0x90A2
+#define GL_SQUARE_NV 0x90A3
+#define GL_ROUND_NV 0x90A4
+#define GL_TRIANGULAR_NV 0x90A5
+#define GL_BEVEL_NV 0x90A6
+#define GL_MITER_REVERT_NV 0x90A7
+#define GL_MITER_TRUNCATE_NV 0x90A8
+#define GL_SKIP_MISSING_GLYPH_NV 0x90A9
+#define GL_USE_MISSING_GLYPH_NV 0x90AA
+#define GL_PATH_ERROR_POSITION_NV 0x90AB
+#define GL_PATH_FOG_GEN_MODE_NV 0x90AC
+#define GL_ACCUM_ADJACENT_PAIRS_NV 0x90AD
+#define GL_ADJACENT_PAIRS_NV 0x90AE
+#define GL_FIRST_TO_REST_NV 0x90AF
+#define GL_PATH_GEN_MODE_NV 0x90B0
+#define GL_PATH_GEN_COEFF_NV 0x90B1
+#define GL_PATH_GEN_COLOR_FORMAT_NV 0x90B2
+#define GL_PATH_GEN_COMPONENTS_NV 0x90B3
+#define GL_PATH_STENCIL_FUNC_NV 0x90B7
+#define GL_PATH_STENCIL_REF_NV 0x90B8
+#define GL_PATH_STENCIL_VALUE_MASK_NV 0x90B9
+#define GL_PATH_STENCIL_DEPTH_OFFSET_FACTOR_NV 0x90BD
+#define GL_PATH_STENCIL_DEPTH_OFFSET_UNITS_NV 0x90BE
+#define GL_PATH_COVER_DEPTH_FUNC_NV 0x90BF
+#define GL_PATH_DASH_OFFSET_RESET_NV 0x90B4
+#define GL_MOVE_TO_RESETS_NV 0x90B5
+#define GL_MOVE_TO_CONTINUES_NV 0x90B6
+#define GL_CLOSE_PATH_NV 0x00
+#define GL_MOVE_TO_NV 0x02
+#define GL_RELATIVE_MOVE_TO_NV 0x03
+#define GL_LINE_TO_NV 0x04
+#define GL_RELATIVE_LINE_TO_NV 0x05
+#define GL_HORIZONTAL_LINE_TO_NV 0x06
+#define GL_RELATIVE_HORIZONTAL_LINE_TO_NV 0x07
+#define GL_VERTICAL_LINE_TO_NV 0x08
+#define GL_RELATIVE_VERTICAL_LINE_TO_NV 0x09
+#define GL_QUADRATIC_CURVE_TO_NV 0x0A
+#define GL_RELATIVE_QUADRATIC_CURVE_TO_NV 0x0B
+#define GL_CUBIC_CURVE_TO_NV 0x0C
+#define GL_RELATIVE_CUBIC_CURVE_TO_NV 0x0D
+#define GL_SMOOTH_QUADRATIC_CURVE_TO_NV 0x0E
+#define GL_RELATIVE_SMOOTH_QUADRATIC_CURVE_TO_NV 0x0F
+#define GL_SMOOTH_CUBIC_CURVE_TO_NV 0x10
+#define GL_RELATIVE_SMOOTH_CUBIC_CURVE_TO_NV 0x11
+#define GL_SMALL_CCW_ARC_TO_NV 0x12
+#define GL_RELATIVE_SMALL_CCW_ARC_TO_NV 0x13
+#define GL_SMALL_CW_ARC_TO_NV 0x14
+#define GL_RELATIVE_SMALL_CW_ARC_TO_NV 0x15
+#define GL_LARGE_CCW_ARC_TO_NV 0x16
+#define GL_RELATIVE_LARGE_CCW_ARC_TO_NV 0x17
+#define GL_LARGE_CW_ARC_TO_NV 0x18
+#define GL_RELATIVE_LARGE_CW_ARC_TO_NV 0x19
+#define GL_RESTART_PATH_NV 0xF0
+#define GL_DUP_FIRST_CUBIC_CURVE_TO_NV 0xF2
+#define GL_DUP_LAST_CUBIC_CURVE_TO_NV 0xF4
+#define GL_RECT_NV 0xF6
+#define GL_CIRCULAR_CCW_ARC_TO_NV 0xF8
+#define GL_CIRCULAR_CW_ARC_TO_NV 0xFA
+#define GL_CIRCULAR_TANGENT_ARC_TO_NV 0xFC
+#define GL_ARC_TO_NV 0xFE
+#define GL_RELATIVE_ARC_TO_NV 0xFF
+#define GL_BOLD_BIT_NV 0x01
+#define GL_ITALIC_BIT_NV 0x02
+#define GL_GLYPH_WIDTH_BIT_NV 0x01
+#define GL_GLYPH_HEIGHT_BIT_NV 0x02
+#define GL_GLYPH_HORIZONTAL_BEARING_X_BIT_NV 0x04
+#define GL_GLYPH_HORIZONTAL_BEARING_Y_BIT_NV 0x08
+#define GL_GLYPH_HORIZONTAL_BEARING_ADVANCE_BIT_NV 0x10
+#define GL_GLYPH_VERTICAL_BEARING_X_BIT_NV 0x20
+#define GL_GLYPH_VERTICAL_BEARING_Y_BIT_NV 0x40
+#define GL_GLYPH_VERTICAL_BEARING_ADVANCE_BIT_NV 0x80
+#define GL_GLYPH_HAS_KERNING_BIT_NV 0x100
+#define GL_FONT_X_MIN_BOUNDS_BIT_NV 0x00010000
+#define GL_FONT_Y_MIN_BOUNDS_BIT_NV 0x00020000
+#define GL_FONT_X_MAX_BOUNDS_BIT_NV 0x00040000
+#define GL_FONT_Y_MAX_BOUNDS_BIT_NV 0x00080000
+#define GL_FONT_UNITS_PER_EM_BIT_NV 0x00100000
+#define GL_FONT_ASCENDER_BIT_NV 0x00200000
+#define GL_FONT_DESCENDER_BIT_NV 0x00400000
+#define GL_FONT_HEIGHT_BIT_NV 0x00800000
+#define GL_FONT_MAX_ADVANCE_WIDTH_BIT_NV 0x01000000
+#define GL_FONT_MAX_ADVANCE_HEIGHT_BIT_NV 0x02000000
+#define GL_FONT_UNDERLINE_POSITION_BIT_NV 0x04000000
+#define GL_FONT_UNDERLINE_THICKNESS_BIT_NV 0x08000000
+#define GL_FONT_HAS_KERNING_BIT_NV 0x10000000
+#define GL_PRIMARY_COLOR_NV 0x852C
+#define GL_SECONDARY_COLOR_NV 0x852D
+typedef GLuint (APIENTRYP PFNGLGENPATHSNVPROC) (GLsizei range);
+typedef void (APIENTRYP PFNGLDELETEPATHSNVPROC) (GLuint path, GLsizei range);
+typedef GLboolean (APIENTRYP PFNGLISPATHNVPROC) (GLuint path);
+typedef void (APIENTRYP PFNGLPATHCOMMANDSNVPROC) (GLuint path, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const void *coords);
+typedef void (APIENTRYP PFNGLPATHCOORDSNVPROC) (GLuint path, GLsizei numCoords, GLenum coordType, const void *coords);
+typedef void (APIENTRYP PFNGLPATHSUBCOMMANDSNVPROC) (GLuint path, GLsizei commandStart, GLsizei commandsToDelete, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const void *coords);
+typedef void (APIENTRYP PFNGLPATHSUBCOORDSNVPROC) (GLuint path, GLsizei coordStart, GLsizei numCoords, GLenum coordType, const void *coords);
+typedef void (APIENTRYP PFNGLPATHSTRINGNVPROC) (GLuint path, GLenum format, GLsizei length, const void *pathString);
+typedef void (APIENTRYP PFNGLPATHGLYPHSNVPROC) (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLsizei numGlyphs, GLenum type, const void *charcodes, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale);
+typedef void (APIENTRYP PFNGLPATHGLYPHRANGENVPROC) (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLuint firstGlyph, GLsizei numGlyphs, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale);
+typedef void (APIENTRYP PFNGLWEIGHTPATHSNVPROC) (GLuint resultPath, GLsizei numPaths, const GLuint *paths, const GLfloat *weights);
+typedef void (APIENTRYP PFNGLCOPYPATHNVPROC) (GLuint resultPath, GLuint srcPath);
+typedef void (APIENTRYP PFNGLINTERPOLATEPATHSNVPROC) (GLuint resultPath, GLuint pathA, GLuint pathB, GLfloat weight);
+typedef void (APIENTRYP PFNGLTRANSFORMPATHNVPROC) (GLuint resultPath, GLuint srcPath, GLenum transformType, const GLfloat *transformValues);
+typedef void (APIENTRYP PFNGLPATHPARAMETERIVNVPROC) (GLuint path, GLenum pname, const GLint *value);
+typedef void (APIENTRYP PFNGLPATHPARAMETERINVPROC) (GLuint path, GLenum pname, GLint value);
+typedef void (APIENTRYP PFNGLPATHPARAMETERFVNVPROC) (GLuint path, GLenum pname, const GLfloat *value);
+typedef void (APIENTRYP PFNGLPATHPARAMETERFNVPROC) (GLuint path, GLenum pname, GLfloat value);
+typedef void (APIENTRYP PFNGLPATHDASHARRAYNVPROC) (GLuint path, GLsizei dashCount, const GLfloat *dashArray);
+typedef void (APIENTRYP PFNGLPATHSTENCILFUNCNVPROC) (GLenum func, GLint ref, GLuint mask);
+typedef void (APIENTRYP PFNGLPATHSTENCILDEPTHOFFSETNVPROC) (GLfloat factor, GLfloat units);
+typedef void (APIENTRYP PFNGLSTENCILFILLPATHNVPROC) (GLuint path, GLenum fillMode, GLuint mask);
+typedef void (APIENTRYP PFNGLSTENCILSTROKEPATHNVPROC) (GLuint path, GLint reference, GLuint mask);
+typedef void (APIENTRYP PFNGLSTENCILFILLPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum fillMode, GLuint mask, GLenum transformType, const GLfloat *transformValues);
+typedef void (APIENTRYP PFNGLSTENCILSTROKEPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLint reference, GLuint mask, GLenum transformType, const GLfloat *transformValues);
+typedef void (APIENTRYP PFNGLPATHCOVERDEPTHFUNCNVPROC) (GLenum func);
+typedef void (APIENTRYP PFNGLPATHCOLORGENNVPROC) (GLenum color, GLenum genMode, GLenum colorFormat, const GLfloat *coeffs);
+typedef void (APIENTRYP PFNGLPATHTEXGENNVPROC) (GLenum texCoordSet, GLenum genMode, GLint components, const GLfloat *coeffs);
+typedef void (APIENTRYP PFNGLPATHFOGGENNVPROC) (GLenum genMode);
+typedef void (APIENTRYP PFNGLCOVERFILLPATHNVPROC) (GLuint path, GLenum coverMode);
+typedef void (APIENTRYP PFNGLCOVERSTROKEPATHNVPROC) (GLuint path, GLenum coverMode);
+typedef void (APIENTRYP PFNGLCOVERFILLPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues);
+typedef void (APIENTRYP PFNGLCOVERSTROKEPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues);
+typedef void (APIENTRYP PFNGLGETPATHPARAMETERIVNVPROC) (GLuint path, GLenum pname, GLint *value);
+typedef void (APIENTRYP PFNGLGETPATHPARAMETERFVNVPROC) (GLuint path, GLenum pname, GLfloat *value);
+typedef void (APIENTRYP PFNGLGETPATHCOMMANDSNVPROC) (GLuint path, GLubyte *commands);
+typedef void (APIENTRYP PFNGLGETPATHCOORDSNVPROC) (GLuint path, GLfloat *coords);
+typedef void (APIENTRYP PFNGLGETPATHDASHARRAYNVPROC) (GLuint path, GLfloat *dashArray);
+typedef void (APIENTRYP PFNGLGETPATHMETRICSNVPROC) (GLbitfield metricQueryMask, GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLsizei stride, GLfloat *metrics);
+typedef void (APIENTRYP PFNGLGETPATHMETRICRANGENVPROC) (GLbitfield metricQueryMask, GLuint firstPathName, GLsizei numPaths, GLsizei stride, GLfloat *metrics);
+typedef void (APIENTRYP PFNGLGETPATHSPACINGNVPROC) (GLenum pathListMode, GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLfloat advanceScale, GLfloat kerningScale, GLenum transformType, GLfloat *returnedSpacing);
+typedef void (APIENTRYP PFNGLGETPATHCOLORGENIVNVPROC) (GLenum color, GLenum pname, GLint *value);
+typedef void (APIENTRYP PFNGLGETPATHCOLORGENFVNVPROC) (GLenum color, GLenum pname, GLfloat *value);
+typedef void (APIENTRYP PFNGLGETPATHTEXGENIVNVPROC) (GLenum texCoordSet, GLenum pname, GLint *value);
+typedef void (APIENTRYP PFNGLGETPATHTEXGENFVNVPROC) (GLenum texCoordSet, GLenum pname, GLfloat *value);
+typedef GLboolean (APIENTRYP PFNGLISPOINTINFILLPATHNVPROC) (GLuint path, GLuint mask, GLfloat x, GLfloat y);
+typedef GLboolean (APIENTRYP PFNGLISPOINTINSTROKEPATHNVPROC) (GLuint path, GLfloat x, GLfloat y);
+typedef GLfloat (APIENTRYP PFNGLGETPATHLENGTHNVPROC) (GLuint path, GLsizei startSegment, GLsizei numSegments);
+typedef GLboolean (APIENTRYP PFNGLPOINTALONGPATHNVPROC) (GLuint path, GLsizei startSegment, GLsizei numSegments, GLfloat distance, GLfloat *x, GLfloat *y, GLfloat *tangentX, GLfloat *tangentY);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLuint APIENTRY glGenPathsNV (GLsizei range);
+GLAPI void APIENTRY glDeletePathsNV (GLuint path, GLsizei range);
+GLAPI GLboolean APIENTRY glIsPathNV (GLuint path);
+GLAPI void APIENTRY glPathCommandsNV (GLuint path, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const void *coords);
+GLAPI void APIENTRY glPathCoordsNV (GLuint path, GLsizei numCoords, GLenum coordType, const void *coords);
+GLAPI void APIENTRY glPathSubCommandsNV (GLuint path, GLsizei commandStart, GLsizei commandsToDelete, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const void *coords);
+GLAPI void APIENTRY glPathSubCoordsNV (GLuint path, GLsizei coordStart, GLsizei numCoords, GLenum coordType, const void *coords);
+GLAPI void APIENTRY glPathStringNV (GLuint path, GLenum format, GLsizei length, const void *pathString);
+GLAPI void APIENTRY glPathGlyphsNV (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLsizei numGlyphs, GLenum type, const void *charcodes, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale);
+GLAPI void APIENTRY glPathGlyphRangeNV (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLuint firstGlyph, GLsizei numGlyphs, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale);
+GLAPI void APIENTRY glWeightPathsNV (GLuint resultPath, GLsizei numPaths, const GLuint *paths, const GLfloat *weights);
+GLAPI void APIENTRY glCopyPathNV (GLuint resultPath, GLuint srcPath);
+GLAPI void APIENTRY glInterpolatePathsNV (GLuint resultPath, GLuint pathA, GLuint pathB, GLfloat weight);
+GLAPI void APIENTRY glTransformPathNV (GLuint resultPath, GLuint srcPath, GLenum transformType, const GLfloat *transformValues);
+GLAPI void APIENTRY glPathParameterivNV (GLuint path, GLenum pname, const GLint *value);
+GLAPI void APIENTRY glPathParameteriNV (GLuint path, GLenum pname, GLint value);
+GLAPI void APIENTRY glPathParameterfvNV (GLuint path, GLenum pname, const GLfloat *value);
+GLAPI void APIENTRY glPathParameterfNV (GLuint path, GLenum pname, GLfloat value);
+GLAPI void APIENTRY glPathDashArrayNV (GLuint path, GLsizei dashCount, const GLfloat *dashArray);
+GLAPI void APIENTRY glPathStencilFuncNV (GLenum func, GLint ref, GLuint mask);
+GLAPI void APIENTRY glPathStencilDepthOffsetNV (GLfloat factor, GLfloat units);
+GLAPI void APIENTRY glStencilFillPathNV (GLuint path, GLenum fillMode, GLuint mask);
+GLAPI void APIENTRY glStencilStrokePathNV (GLuint path, GLint reference, GLuint mask);
+GLAPI void APIENTRY glStencilFillPathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum fillMode, GLuint mask, GLenum transformType, const GLfloat *transformValues);
+GLAPI void APIENTRY glStencilStrokePathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLint reference, GLuint mask, GLenum transformType, const GLfloat *transformValues);
+GLAPI void APIENTRY glPathCoverDepthFuncNV (GLenum func);
+GLAPI void APIENTRY glPathColorGenNV (GLenum color, GLenum genMode, GLenum colorFormat, const GLfloat *coeffs);
+GLAPI void APIENTRY glPathTexGenNV (GLenum texCoordSet, GLenum genMode, GLint components, const GLfloat *coeffs);
+GLAPI void APIENTRY glPathFogGenNV (GLenum genMode);
+GLAPI void APIENTRY glCoverFillPathNV (GLuint path, GLenum coverMode);
+GLAPI void APIENTRY glCoverStrokePathNV (GLuint path, GLenum coverMode);
+GLAPI void APIENTRY glCoverFillPathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues);
+GLAPI void APIENTRY glCoverStrokePathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues);
+GLAPI void APIENTRY glGetPathParameterivNV (GLuint path, GLenum pname, GLint *value);
+GLAPI void APIENTRY glGetPathParameterfvNV (GLuint path, GLenum pname, GLfloat *value);
+GLAPI void APIENTRY glGetPathCommandsNV (GLuint path, GLubyte *commands);
+GLAPI void APIENTRY glGetPathCoordsNV (GLuint path, GLfloat *coords);
+GLAPI void APIENTRY glGetPathDashArrayNV (GLuint path, GLfloat *dashArray);
+GLAPI void APIENTRY glGetPathMetricsNV (GLbitfield metricQueryMask, GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLsizei stride, GLfloat *metrics);
+GLAPI void APIENTRY glGetPathMetricRangeNV (GLbitfield metricQueryMask, GLuint firstPathName, GLsizei numPaths, GLsizei stride, GLfloat *metrics);
+GLAPI void APIENTRY glGetPathSpacingNV (GLenum pathListMode, GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLfloat advanceScale, GLfloat kerningScale, GLenum transformType, GLfloat *returnedSpacing);
+GLAPI void APIENTRY glGetPathColorGenivNV (GLenum color, GLenum pname, GLint *value);
+GLAPI void APIENTRY glGetPathColorGenfvNV (GLenum color, GLenum pname, GLfloat *value);
+GLAPI void APIENTRY glGetPathTexGenivNV (GLenum texCoordSet, GLenum pname, GLint *value);
+GLAPI void APIENTRY glGetPathTexGenfvNV (GLenum texCoordSet, GLenum pname, GLfloat *value);
+GLAPI GLboolean APIENTRY glIsPointInFillPathNV (GLuint path, GLuint mask, GLfloat x, GLfloat y);
+GLAPI GLboolean APIENTRY glIsPointInStrokePathNV (GLuint path, GLfloat x, GLfloat y);
+GLAPI GLfloat APIENTRY glGetPathLengthNV (GLuint path, GLsizei startSegment, GLsizei numSegments);
+GLAPI GLboolean APIENTRY glPointAlongPathNV (GLuint path, GLsizei startSegment, GLsizei numSegments, GLfloat distance, GLfloat *x, GLfloat *y, GLfloat *tangentX, GLfloat *tangentY);
+#endif
+#endif /* GL_NV_path_rendering */
+
+#ifndef GL_NV_pixel_data_range
+#define GL_NV_pixel_data_range 1
+#define GL_WRITE_PIXEL_DATA_RANGE_NV 0x8878
+#define GL_READ_PIXEL_DATA_RANGE_NV 0x8879
+#define GL_WRITE_PIXEL_DATA_RANGE_LENGTH_NV 0x887A
+#define GL_READ_PIXEL_DATA_RANGE_LENGTH_NV 0x887B
+#define GL_WRITE_PIXEL_DATA_RANGE_POINTER_NV 0x887C
+#define GL_READ_PIXEL_DATA_RANGE_POINTER_NV 0x887D
+typedef void (APIENTRYP PFNGLPIXELDATARANGENVPROC) (GLenum target, GLsizei length, const void *pointer);
+typedef void (APIENTRYP PFNGLFLUSHPIXELDATARANGENVPROC) (GLenum target);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPixelDataRangeNV (GLenum target, GLsizei length, const void *pointer);
+GLAPI void APIENTRY glFlushPixelDataRangeNV (GLenum target);
+#endif
+#endif /* GL_NV_pixel_data_range */
+
+#ifndef GL_NV_point_sprite
+#define GL_NV_point_sprite 1
+#define GL_POINT_SPRITE_NV 0x8861
+#define GL_COORD_REPLACE_NV 0x8862
+#define GL_POINT_SPRITE_R_MODE_NV 0x8863
+typedef void (APIENTRYP PFNGLPOINTPARAMETERINVPROC) (GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLPOINTPARAMETERIVNVPROC) (GLenum pname, const GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPointParameteriNV (GLenum pname, GLint param);
+GLAPI void APIENTRY glPointParameterivNV (GLenum pname, const GLint *params);
+#endif
+#endif /* GL_NV_point_sprite */
+
+#ifndef GL_NV_present_video
+#define GL_NV_present_video 1
+#define GL_FRAME_NV 0x8E26
+#define GL_FIELDS_NV 0x8E27
+#define GL_CURRENT_TIME_NV 0x8E28
+#define GL_NUM_FILL_STREAMS_NV 0x8E29
+#define GL_PRESENT_TIME_NV 0x8E2A
+#define GL_PRESENT_DURATION_NV 0x8E2B
+typedef void (APIENTRYP PFNGLPRESENTFRAMEKEYEDNVPROC) (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLuint key0, GLenum target1, GLuint fill1, GLuint key1);
+typedef void (APIENTRYP PFNGLPRESENTFRAMEDUALFILLNVPROC) (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLenum target1, GLuint fill1, GLenum target2, GLuint fill2, GLenum target3, GLuint fill3);
+typedef void (APIENTRYP PFNGLGETVIDEOIVNVPROC) (GLuint video_slot, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETVIDEOUIVNVPROC) (GLuint video_slot, GLenum pname, GLuint *params);
+typedef void (APIENTRYP PFNGLGETVIDEOI64VNVPROC) (GLuint video_slot, GLenum pname, GLint64EXT *params);
+typedef void (APIENTRYP PFNGLGETVIDEOUI64VNVPROC) (GLuint video_slot, GLenum pname, GLuint64EXT *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPresentFrameKeyedNV (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLuint key0, GLenum target1, GLuint fill1, GLuint key1);
+GLAPI void APIENTRY glPresentFrameDualFillNV (GLuint video_slot, GLuint64EXT minPresentTime, GLuint beginPresentTimeId, GLuint presentDurationId, GLenum type, GLenum target0, GLuint fill0, GLenum target1, GLuint fill1, GLenum target2, GLuint fill2, GLenum target3, GLuint fill3);
+GLAPI void APIENTRY glGetVideoivNV (GLuint video_slot, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetVideouivNV (GLuint video_slot, GLenum pname, GLuint *params);
+GLAPI void APIENTRY glGetVideoi64vNV (GLuint video_slot, GLenum pname, GLint64EXT *params);
+GLAPI void APIENTRY glGetVideoui64vNV (GLuint video_slot, GLenum pname, GLuint64EXT *params);
+#endif
+#endif /* GL_NV_present_video */
+
+#ifndef GL_NV_primitive_restart
+#define GL_NV_primitive_restart 1
+#define GL_PRIMITIVE_RESTART_NV 0x8558
+#define GL_PRIMITIVE_RESTART_INDEX_NV 0x8559
+typedef void (APIENTRYP PFNGLPRIMITIVERESTARTNVPROC) (void);
+typedef void (APIENTRYP PFNGLPRIMITIVERESTARTINDEXNVPROC) (GLuint index);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPrimitiveRestartNV (void);
+GLAPI void APIENTRY glPrimitiveRestartIndexNV (GLuint index);
+#endif
+#endif /* GL_NV_primitive_restart */
+
+#ifndef GL_NV_register_combiners
+#define GL_NV_register_combiners 1
+#define GL_REGISTER_COMBINERS_NV 0x8522
+#define GL_VARIABLE_A_NV 0x8523
+#define GL_VARIABLE_B_NV 0x8524
+#define GL_VARIABLE_C_NV 0x8525
+#define GL_VARIABLE_D_NV 0x8526
+#define GL_VARIABLE_E_NV 0x8527
+#define GL_VARIABLE_F_NV 0x8528
+#define GL_VARIABLE_G_NV 0x8529
+#define GL_CONSTANT_COLOR0_NV 0x852A
+#define GL_CONSTANT_COLOR1_NV 0x852B
+#define GL_SPARE0_NV 0x852E
+#define GL_SPARE1_NV 0x852F
+#define GL_DISCARD_NV 0x8530
+#define GL_E_TIMES_F_NV 0x8531
+#define GL_SPARE0_PLUS_SECONDARY_COLOR_NV 0x8532
+#define GL_UNSIGNED_IDENTITY_NV 0x8536
+#define GL_UNSIGNED_INVERT_NV 0x8537
+#define GL_EXPAND_NORMAL_NV 0x8538
+#define GL_EXPAND_NEGATE_NV 0x8539
+#define GL_HALF_BIAS_NORMAL_NV 0x853A
+#define GL_HALF_BIAS_NEGATE_NV 0x853B
+#define GL_SIGNED_IDENTITY_NV 0x853C
+#define GL_SIGNED_NEGATE_NV 0x853D
+#define GL_SCALE_BY_TWO_NV 0x853E
+#define GL_SCALE_BY_FOUR_NV 0x853F
+#define GL_SCALE_BY_ONE_HALF_NV 0x8540
+#define GL_BIAS_BY_NEGATIVE_ONE_HALF_NV 0x8541
+#define GL_COMBINER_INPUT_NV 0x8542
+#define GL_COMBINER_MAPPING_NV 0x8543
+#define GL_COMBINER_COMPONENT_USAGE_NV 0x8544
+#define GL_COMBINER_AB_DOT_PRODUCT_NV 0x8545
+#define GL_COMBINER_CD_DOT_PRODUCT_NV 0x8546
+#define GL_COMBINER_MUX_SUM_NV 0x8547
+#define GL_COMBINER_SCALE_NV 0x8548
+#define GL_COMBINER_BIAS_NV 0x8549
+#define GL_COMBINER_AB_OUTPUT_NV 0x854A
+#define GL_COMBINER_CD_OUTPUT_NV 0x854B
+#define GL_COMBINER_SUM_OUTPUT_NV 0x854C
+#define GL_MAX_GENERAL_COMBINERS_NV 0x854D
+#define GL_NUM_GENERAL_COMBINERS_NV 0x854E
+#define GL_COLOR_SUM_CLAMP_NV 0x854F
+#define GL_COMBINER0_NV 0x8550
+#define GL_COMBINER1_NV 0x8551
+#define GL_COMBINER2_NV 0x8552
+#define GL_COMBINER3_NV 0x8553
+#define GL_COMBINER4_NV 0x8554
+#define GL_COMBINER5_NV 0x8555
+#define GL_COMBINER6_NV 0x8556
+#define GL_COMBINER7_NV 0x8557
+typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFVNVPROC) (GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLCOMBINERPARAMETERFNVPROC) (GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLCOMBINERPARAMETERIVNVPROC) (GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLCOMBINERPARAMETERINVPROC) (GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLCOMBINERINPUTNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage);
+typedef void (APIENTRYP PFNGLCOMBINEROUTPUTNVPROC) (GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum);
+typedef void (APIENTRYP PFNGLFINALCOMBINERINPUTNVPROC) (GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage);
+typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETCOMBINERINPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERFVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETCOMBINEROUTPUTPARAMETERIVNVPROC) (GLenum stage, GLenum portion, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERFVNVPROC) (GLenum variable, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETFINALCOMBINERINPUTPARAMETERIVNVPROC) (GLenum variable, GLenum pname, GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glCombinerParameterfvNV (GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glCombinerParameterfNV (GLenum pname, GLfloat param);
+GLAPI void APIENTRY glCombinerParameterivNV (GLenum pname, const GLint *params);
+GLAPI void APIENTRY glCombinerParameteriNV (GLenum pname, GLint param);
+GLAPI void APIENTRY glCombinerInputNV (GLenum stage, GLenum portion, GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage);
+GLAPI void APIENTRY glCombinerOutputNV (GLenum stage, GLenum portion, GLenum abOutput, GLenum cdOutput, GLenum sumOutput, GLenum scale, GLenum bias, GLboolean abDotProduct, GLboolean cdDotProduct, GLboolean muxSum);
+GLAPI void APIENTRY glFinalCombinerInputNV (GLenum variable, GLenum input, GLenum mapping, GLenum componentUsage);
+GLAPI void APIENTRY glGetCombinerInputParameterfvNV (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetCombinerInputParameterivNV (GLenum stage, GLenum portion, GLenum variable, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetCombinerOutputParameterfvNV (GLenum stage, GLenum portion, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetCombinerOutputParameterivNV (GLenum stage, GLenum portion, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetFinalCombinerInputParameterfvNV (GLenum variable, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetFinalCombinerInputParameterivNV (GLenum variable, GLenum pname, GLint *params);
+#endif
+#endif /* GL_NV_register_combiners */
+
+#ifndef GL_NV_register_combiners2
+#define GL_NV_register_combiners2 1
+#define GL_PER_STAGE_CONSTANTS_NV 0x8535
+typedef void (APIENTRYP PFNGLCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLGETCOMBINERSTAGEPARAMETERFVNVPROC) (GLenum stage, GLenum pname, GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glCombinerStageParameterfvNV (GLenum stage, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glGetCombinerStageParameterfvNV (GLenum stage, GLenum pname, GLfloat *params);
+#endif
+#endif /* GL_NV_register_combiners2 */
+
+#ifndef GL_NV_shader_atomic_counters
+#define GL_NV_shader_atomic_counters 1
+#endif /* GL_NV_shader_atomic_counters */
+
+#ifndef GL_NV_shader_atomic_float
+#define GL_NV_shader_atomic_float 1
+#endif /* GL_NV_shader_atomic_float */
+
+#ifndef GL_NV_shader_buffer_load
+#define GL_NV_shader_buffer_load 1
+#define GL_BUFFER_GPU_ADDRESS_NV 0x8F1D
+#define GL_GPU_ADDRESS_NV 0x8F34
+#define GL_MAX_SHADER_BUFFER_ADDRESS_NV 0x8F35
+typedef void (APIENTRYP PFNGLMAKEBUFFERRESIDENTNVPROC) (GLenum target, GLenum access);
+typedef void (APIENTRYP PFNGLMAKEBUFFERNONRESIDENTNVPROC) (GLenum target);
+typedef GLboolean (APIENTRYP PFNGLISBUFFERRESIDENTNVPROC) (GLenum target);
+typedef void (APIENTRYP PFNGLMAKENAMEDBUFFERRESIDENTNVPROC) (GLuint buffer, GLenum access);
+typedef void (APIENTRYP PFNGLMAKENAMEDBUFFERNONRESIDENTNVPROC) (GLuint buffer);
+typedef GLboolean (APIENTRYP PFNGLISNAMEDBUFFERRESIDENTNVPROC) (GLuint buffer);
+typedef void (APIENTRYP PFNGLGETBUFFERPARAMETERUI64VNVPROC) (GLenum target, GLenum pname, GLuint64EXT *params);
+typedef void (APIENTRYP PFNGLGETNAMEDBUFFERPARAMETERUI64VNVPROC) (GLuint buffer, GLenum pname, GLuint64EXT *params);
+typedef void (APIENTRYP PFNGLGETINTEGERUI64VNVPROC) (GLenum value, GLuint64EXT *result);
+typedef void (APIENTRYP PFNGLUNIFORMUI64NVPROC) (GLint location, GLuint64EXT value);
+typedef void (APIENTRYP PFNGLUNIFORMUI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMUI64NVPROC) (GLuint program, GLint location, GLuint64EXT value);
+typedef void (APIENTRYP PFNGLPROGRAMUNIFORMUI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glMakeBufferResidentNV (GLenum target, GLenum access);
+GLAPI void APIENTRY glMakeBufferNonResidentNV (GLenum target);
+GLAPI GLboolean APIENTRY glIsBufferResidentNV (GLenum target);
+GLAPI void APIENTRY glMakeNamedBufferResidentNV (GLuint buffer, GLenum access);
+GLAPI void APIENTRY glMakeNamedBufferNonResidentNV (GLuint buffer);
+GLAPI GLboolean APIENTRY glIsNamedBufferResidentNV (GLuint buffer);
+GLAPI void APIENTRY glGetBufferParameterui64vNV (GLenum target, GLenum pname, GLuint64EXT *params);
+GLAPI void APIENTRY glGetNamedBufferParameterui64vNV (GLuint buffer, GLenum pname, GLuint64EXT *params);
+GLAPI void APIENTRY glGetIntegerui64vNV (GLenum value, GLuint64EXT *result);
+GLAPI void APIENTRY glUniformui64NV (GLint location, GLuint64EXT value);
+GLAPI void APIENTRY glUniformui64vNV (GLint location, GLsizei count, const GLuint64EXT *value);
+GLAPI void APIENTRY glProgramUniformui64NV (GLuint program, GLint location, GLuint64EXT value);
+GLAPI void APIENTRY glProgramUniformui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+#endif
+#endif /* GL_NV_shader_buffer_load */
+
+#ifndef GL_NV_shader_buffer_store
+#define GL_NV_shader_buffer_store 1
+#define GL_SHADER_GLOBAL_ACCESS_BARRIER_BIT_NV 0x00000010
+#endif /* GL_NV_shader_buffer_store */
+
+#ifndef GL_NV_shader_storage_buffer_object
+#define GL_NV_shader_storage_buffer_object 1
+#endif /* GL_NV_shader_storage_buffer_object */
+
+#ifndef GL_NV_shader_thread_group
+#define GL_NV_shader_thread_group 1
+#define GL_WARP_SIZE_NV 0x9339
+#define GL_WARPS_PER_SM_NV 0x933A
+#define GL_SM_COUNT_NV 0x933B
+#endif /* GL_NV_shader_thread_group */
+
+#ifndef GL_NV_shader_thread_shuffle
+#define GL_NV_shader_thread_shuffle 1
+#endif /* GL_NV_shader_thread_shuffle */
+
+#ifndef GL_NV_tessellation_program5
+#define GL_NV_tessellation_program5 1
+#define GL_MAX_PROGRAM_PATCH_ATTRIBS_NV 0x86D8
+#define GL_TESS_CONTROL_PROGRAM_NV 0x891E
+#define GL_TESS_EVALUATION_PROGRAM_NV 0x891F
+#define GL_TESS_CONTROL_PROGRAM_PARAMETER_BUFFER_NV 0x8C74
+#define GL_TESS_EVALUATION_PROGRAM_PARAMETER_BUFFER_NV 0x8C75
+#endif /* GL_NV_tessellation_program5 */
+
+#ifndef GL_NV_texgen_emboss
+#define GL_NV_texgen_emboss 1
+#define GL_EMBOSS_LIGHT_NV 0x855D
+#define GL_EMBOSS_CONSTANT_NV 0x855E
+#define GL_EMBOSS_MAP_NV 0x855F
+#endif /* GL_NV_texgen_emboss */
+
+#ifndef GL_NV_texgen_reflection
+#define GL_NV_texgen_reflection 1
+#define GL_NORMAL_MAP_NV 0x8511
+#define GL_REFLECTION_MAP_NV 0x8512
+#endif /* GL_NV_texgen_reflection */
+
+#ifndef GL_NV_texture_barrier
+#define GL_NV_texture_barrier 1
+typedef void (APIENTRYP PFNGLTEXTUREBARRIERNVPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTextureBarrierNV (void);
+#endif
+#endif /* GL_NV_texture_barrier */
+
+#ifndef GL_NV_texture_compression_vtc
+#define GL_NV_texture_compression_vtc 1
+#endif /* GL_NV_texture_compression_vtc */
+
+#ifndef GL_NV_texture_env_combine4
+#define GL_NV_texture_env_combine4 1
+#define GL_COMBINE4_NV 0x8503
+#define GL_SOURCE3_RGB_NV 0x8583
+#define GL_SOURCE3_ALPHA_NV 0x858B
+#define GL_OPERAND3_RGB_NV 0x8593
+#define GL_OPERAND3_ALPHA_NV 0x859B
+#endif /* GL_NV_texture_env_combine4 */
+
+#ifndef GL_NV_texture_expand_normal
+#define GL_NV_texture_expand_normal 1
+#define GL_TEXTURE_UNSIGNED_REMAP_MODE_NV 0x888F
+#endif /* GL_NV_texture_expand_normal */
+
+#ifndef GL_NV_texture_multisample
+#define GL_NV_texture_multisample 1
+#define GL_TEXTURE_COVERAGE_SAMPLES_NV 0x9045
+#define GL_TEXTURE_COLOR_SAMPLES_NV 0x9046
+typedef void (APIENTRYP PFNGLTEXIMAGE2DMULTISAMPLECOVERAGENVPROC) (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations);
+typedef void (APIENTRYP PFNGLTEXIMAGE3DMULTISAMPLECOVERAGENVPROC) (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations);
+typedef void (APIENTRYP PFNGLTEXTUREIMAGE2DMULTISAMPLENVPROC) (GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations);
+typedef void (APIENTRYP PFNGLTEXTUREIMAGE3DMULTISAMPLENVPROC) (GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations);
+typedef void (APIENTRYP PFNGLTEXTUREIMAGE2DMULTISAMPLECOVERAGENVPROC) (GLuint texture, GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations);
+typedef void (APIENTRYP PFNGLTEXTUREIMAGE3DMULTISAMPLECOVERAGENVPROC) (GLuint texture, GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexImage2DMultisampleCoverageNV (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations);
+GLAPI void APIENTRY glTexImage3DMultisampleCoverageNV (GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations);
+GLAPI void APIENTRY glTextureImage2DMultisampleNV (GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations);
+GLAPI void APIENTRY glTextureImage3DMultisampleNV (GLuint texture, GLenum target, GLsizei samples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations);
+GLAPI void APIENTRY glTextureImage2DMultisampleCoverageNV (GLuint texture, GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations);
+GLAPI void APIENTRY glTextureImage3DMultisampleCoverageNV (GLuint texture, GLenum target, GLsizei coverageSamples, GLsizei colorSamples, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations);
+#endif
+#endif /* GL_NV_texture_multisample */
+
+#ifndef GL_NV_texture_rectangle
+#define GL_NV_texture_rectangle 1
+#define GL_TEXTURE_RECTANGLE_NV 0x84F5
+#define GL_TEXTURE_BINDING_RECTANGLE_NV 0x84F6
+#define GL_PROXY_TEXTURE_RECTANGLE_NV 0x84F7
+#define GL_MAX_RECTANGLE_TEXTURE_SIZE_NV 0x84F8
+#endif /* GL_NV_texture_rectangle */
+
+#ifndef GL_NV_texture_shader
+#define GL_NV_texture_shader 1
+#define GL_OFFSET_TEXTURE_RECTANGLE_NV 0x864C
+#define GL_OFFSET_TEXTURE_RECTANGLE_SCALE_NV 0x864D
+#define GL_DOT_PRODUCT_TEXTURE_RECTANGLE_NV 0x864E
+#define GL_RGBA_UNSIGNED_DOT_PRODUCT_MAPPING_NV 0x86D9
+#define GL_UNSIGNED_INT_S8_S8_8_8_NV 0x86DA
+#define GL_UNSIGNED_INT_8_8_S8_S8_REV_NV 0x86DB
+#define GL_DSDT_MAG_INTENSITY_NV 0x86DC
+#define GL_SHADER_CONSISTENT_NV 0x86DD
+#define GL_TEXTURE_SHADER_NV 0x86DE
+#define GL_SHADER_OPERATION_NV 0x86DF
+#define GL_CULL_MODES_NV 0x86E0
+#define GL_OFFSET_TEXTURE_MATRIX_NV 0x86E1
+#define GL_OFFSET_TEXTURE_SCALE_NV 0x86E2
+#define GL_OFFSET_TEXTURE_BIAS_NV 0x86E3
+#define GL_OFFSET_TEXTURE_2D_MATRIX_NV 0x86E1
+#define GL_OFFSET_TEXTURE_2D_SCALE_NV 0x86E2
+#define GL_OFFSET_TEXTURE_2D_BIAS_NV 0x86E3
+#define GL_PREVIOUS_TEXTURE_INPUT_NV 0x86E4
+#define GL_CONST_EYE_NV 0x86E5
+#define GL_PASS_THROUGH_NV 0x86E6
+#define GL_CULL_FRAGMENT_NV 0x86E7
+#define GL_OFFSET_TEXTURE_2D_NV 0x86E8
+#define GL_DEPENDENT_AR_TEXTURE_2D_NV 0x86E9
+#define GL_DEPENDENT_GB_TEXTURE_2D_NV 0x86EA
+#define GL_DOT_PRODUCT_NV 0x86EC
+#define GL_DOT_PRODUCT_DEPTH_REPLACE_NV 0x86ED
+#define GL_DOT_PRODUCT_TEXTURE_2D_NV 0x86EE
+#define GL_DOT_PRODUCT_TEXTURE_CUBE_MAP_NV 0x86F0
+#define GL_DOT_PRODUCT_DIFFUSE_CUBE_MAP_NV 0x86F1
+#define GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV 0x86F2
+#define GL_DOT_PRODUCT_CONST_EYE_REFLECT_CUBE_MAP_NV 0x86F3
+#define GL_HILO_NV 0x86F4
+#define GL_DSDT_NV 0x86F5
+#define GL_DSDT_MAG_NV 0x86F6
+#define GL_DSDT_MAG_VIB_NV 0x86F7
+#define GL_HILO16_NV 0x86F8
+#define GL_SIGNED_HILO_NV 0x86F9
+#define GL_SIGNED_HILO16_NV 0x86FA
+#define GL_SIGNED_RGBA_NV 0x86FB
+#define GL_SIGNED_RGBA8_NV 0x86FC
+#define GL_SIGNED_RGB_NV 0x86FE
+#define GL_SIGNED_RGB8_NV 0x86FF
+#define GL_SIGNED_LUMINANCE_NV 0x8701
+#define GL_SIGNED_LUMINANCE8_NV 0x8702
+#define GL_SIGNED_LUMINANCE_ALPHA_NV 0x8703
+#define GL_SIGNED_LUMINANCE8_ALPHA8_NV 0x8704
+#define GL_SIGNED_ALPHA_NV 0x8705
+#define GL_SIGNED_ALPHA8_NV 0x8706
+#define GL_SIGNED_INTENSITY_NV 0x8707
+#define GL_SIGNED_INTENSITY8_NV 0x8708
+#define GL_DSDT8_NV 0x8709
+#define GL_DSDT8_MAG8_NV 0x870A
+#define GL_DSDT8_MAG8_INTENSITY8_NV 0x870B
+#define GL_SIGNED_RGB_UNSIGNED_ALPHA_NV 0x870C
+#define GL_SIGNED_RGB8_UNSIGNED_ALPHA8_NV 0x870D
+#define GL_HI_SCALE_NV 0x870E
+#define GL_LO_SCALE_NV 0x870F
+#define GL_DS_SCALE_NV 0x8710
+#define GL_DT_SCALE_NV 0x8711
+#define GL_MAGNITUDE_SCALE_NV 0x8712
+#define GL_VIBRANCE_SCALE_NV 0x8713
+#define GL_HI_BIAS_NV 0x8714
+#define GL_LO_BIAS_NV 0x8715
+#define GL_DS_BIAS_NV 0x8716
+#define GL_DT_BIAS_NV 0x8717
+#define GL_MAGNITUDE_BIAS_NV 0x8718
+#define GL_VIBRANCE_BIAS_NV 0x8719
+#define GL_TEXTURE_BORDER_VALUES_NV 0x871A
+#define GL_TEXTURE_HI_SIZE_NV 0x871B
+#define GL_TEXTURE_LO_SIZE_NV 0x871C
+#define GL_TEXTURE_DS_SIZE_NV 0x871D
+#define GL_TEXTURE_DT_SIZE_NV 0x871E
+#define GL_TEXTURE_MAG_SIZE_NV 0x871F
+#endif /* GL_NV_texture_shader */
+
+#ifndef GL_NV_texture_shader2
+#define GL_NV_texture_shader2 1
+#define GL_DOT_PRODUCT_TEXTURE_3D_NV 0x86EF
+#endif /* GL_NV_texture_shader2 */
+
+#ifndef GL_NV_texture_shader3
+#define GL_NV_texture_shader3 1
+#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_NV 0x8850
+#define GL_OFFSET_PROJECTIVE_TEXTURE_2D_SCALE_NV 0x8851
+#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8852
+#define GL_OFFSET_PROJECTIVE_TEXTURE_RECTANGLE_SCALE_NV 0x8853
+#define GL_OFFSET_HILO_TEXTURE_2D_NV 0x8854
+#define GL_OFFSET_HILO_TEXTURE_RECTANGLE_NV 0x8855
+#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_2D_NV 0x8856
+#define GL_OFFSET_HILO_PROJECTIVE_TEXTURE_RECTANGLE_NV 0x8857
+#define GL_DEPENDENT_HILO_TEXTURE_2D_NV 0x8858
+#define GL_DEPENDENT_RGB_TEXTURE_3D_NV 0x8859
+#define GL_DEPENDENT_RGB_TEXTURE_CUBE_MAP_NV 0x885A
+#define GL_DOT_PRODUCT_PASS_THROUGH_NV 0x885B
+#define GL_DOT_PRODUCT_TEXTURE_1D_NV 0x885C
+#define GL_DOT_PRODUCT_AFFINE_DEPTH_REPLACE_NV 0x885D
+#define GL_HILO8_NV 0x885E
+#define GL_SIGNED_HILO8_NV 0x885F
+#define GL_FORCE_BLUE_TO_ONE_NV 0x8860
+#endif /* GL_NV_texture_shader3 */
+
+#ifndef GL_NV_transform_feedback
+#define GL_NV_transform_feedback 1
+#define GL_BACK_PRIMARY_COLOR_NV 0x8C77
+#define GL_BACK_SECONDARY_COLOR_NV 0x8C78
+#define GL_TEXTURE_COORD_NV 0x8C79
+#define GL_CLIP_DISTANCE_NV 0x8C7A
+#define GL_VERTEX_ID_NV 0x8C7B
+#define GL_PRIMITIVE_ID_NV 0x8C7C
+#define GL_GENERIC_ATTRIB_NV 0x8C7D
+#define GL_TRANSFORM_FEEDBACK_ATTRIBS_NV 0x8C7E
+#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE_NV 0x8C7F
+#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_NV 0x8C80
+#define GL_ACTIVE_VARYINGS_NV 0x8C81
+#define GL_ACTIVE_VARYING_MAX_LENGTH_NV 0x8C82
+#define GL_TRANSFORM_FEEDBACK_VARYINGS_NV 0x8C83
+#define GL_TRANSFORM_FEEDBACK_BUFFER_START_NV 0x8C84
+#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE_NV 0x8C85
+#define GL_TRANSFORM_FEEDBACK_RECORD_NV 0x8C86
+#define GL_PRIMITIVES_GENERATED_NV 0x8C87
+#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_NV 0x8C88
+#define GL_RASTERIZER_DISCARD_NV 0x8C89
+#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_NV 0x8C8A
+#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_NV 0x8C8B
+#define GL_INTERLEAVED_ATTRIBS_NV 0x8C8C
+#define GL_SEPARATE_ATTRIBS_NV 0x8C8D
+#define GL_TRANSFORM_FEEDBACK_BUFFER_NV 0x8C8E
+#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING_NV 0x8C8F
+#define GL_LAYER_NV 0x8DAA
+#define GL_NEXT_BUFFER_NV -2
+#define GL_SKIP_COMPONENTS4_NV -3
+#define GL_SKIP_COMPONENTS3_NV -4
+#define GL_SKIP_COMPONENTS2_NV -5
+#define GL_SKIP_COMPONENTS1_NV -6
+typedef void (APIENTRYP PFNGLBEGINTRANSFORMFEEDBACKNVPROC) (GLenum primitiveMode);
+typedef void (APIENTRYP PFNGLENDTRANSFORMFEEDBACKNVPROC) (void);
+typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKATTRIBSNVPROC) (GLuint count, const GLint *attribs, GLenum bufferMode);
+typedef void (APIENTRYP PFNGLBINDBUFFERRANGENVPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size);
+typedef void (APIENTRYP PFNGLBINDBUFFEROFFSETNVPROC) (GLenum target, GLuint index, GLuint buffer, GLintptr offset);
+typedef void (APIENTRYP PFNGLBINDBUFFERBASENVPROC) (GLenum target, GLuint index, GLuint buffer);
+typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKVARYINGSNVPROC) (GLuint program, GLsizei count, const GLint *locations, GLenum bufferMode);
+typedef void (APIENTRYP PFNGLACTIVEVARYINGNVPROC) (GLuint program, const GLchar *name);
+typedef GLint (APIENTRYP PFNGLGETVARYINGLOCATIONNVPROC) (GLuint program, const GLchar *name);
+typedef void (APIENTRYP PFNGLGETACTIVEVARYINGNVPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name);
+typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKVARYINGNVPROC) (GLuint program, GLuint index, GLint *location);
+typedef void (APIENTRYP PFNGLTRANSFORMFEEDBACKSTREAMATTRIBSNVPROC) (GLsizei count, const GLint *attribs, GLsizei nbuffers, const GLint *bufstreams, GLenum bufferMode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBeginTransformFeedbackNV (GLenum primitiveMode);
+GLAPI void APIENTRY glEndTransformFeedbackNV (void);
+GLAPI void APIENTRY glTransformFeedbackAttribsNV (GLuint count, const GLint *attribs, GLenum bufferMode);
+GLAPI void APIENTRY glBindBufferRangeNV (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size);
+GLAPI void APIENTRY glBindBufferOffsetNV (GLenum target, GLuint index, GLuint buffer, GLintptr offset);
+GLAPI void APIENTRY glBindBufferBaseNV (GLenum target, GLuint index, GLuint buffer);
+GLAPI void APIENTRY glTransformFeedbackVaryingsNV (GLuint program, GLsizei count, const GLint *locations, GLenum bufferMode);
+GLAPI void APIENTRY glActiveVaryingNV (GLuint program, const GLchar *name);
+GLAPI GLint APIENTRY glGetVaryingLocationNV (GLuint program, const GLchar *name);
+GLAPI void APIENTRY glGetActiveVaryingNV (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name);
+GLAPI void APIENTRY glGetTransformFeedbackVaryingNV (GLuint program, GLuint index, GLint *location);
+GLAPI void APIENTRY glTransformFeedbackStreamAttribsNV (GLsizei count, const GLint *attribs, GLsizei nbuffers, const GLint *bufstreams, GLenum bufferMode);
+#endif
+#endif /* GL_NV_transform_feedback */
+
+#ifndef GL_NV_transform_feedback2
+#define GL_NV_transform_feedback2 1
+#define GL_TRANSFORM_FEEDBACK_NV 0x8E22
+#define GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED_NV 0x8E23
+#define GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE_NV 0x8E24
+#define GL_TRANSFORM_FEEDBACK_BINDING_NV 0x8E25
+typedef void (APIENTRYP PFNGLBINDTRANSFORMFEEDBACKNVPROC) (GLenum target, GLuint id);
+typedef void (APIENTRYP PFNGLDELETETRANSFORMFEEDBACKSNVPROC) (GLsizei n, const GLuint *ids);
+typedef void (APIENTRYP PFNGLGENTRANSFORMFEEDBACKSNVPROC) (GLsizei n, GLuint *ids);
+typedef GLboolean (APIENTRYP PFNGLISTRANSFORMFEEDBACKNVPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLPAUSETRANSFORMFEEDBACKNVPROC) (void);
+typedef void (APIENTRYP PFNGLRESUMETRANSFORMFEEDBACKNVPROC) (void);
+typedef void (APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKNVPROC) (GLenum mode, GLuint id);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBindTransformFeedbackNV (GLenum target, GLuint id);
+GLAPI void APIENTRY glDeleteTransformFeedbacksNV (GLsizei n, const GLuint *ids);
+GLAPI void APIENTRY glGenTransformFeedbacksNV (GLsizei n, GLuint *ids);
+GLAPI GLboolean APIENTRY glIsTransformFeedbackNV (GLuint id);
+GLAPI void APIENTRY glPauseTransformFeedbackNV (void);
+GLAPI void APIENTRY glResumeTransformFeedbackNV (void);
+GLAPI void APIENTRY glDrawTransformFeedbackNV (GLenum mode, GLuint id);
+#endif
+#endif /* GL_NV_transform_feedback2 */
+
+#ifndef GL_NV_vdpau_interop
+#define GL_NV_vdpau_interop 1
+typedef GLintptr GLvdpauSurfaceNV;
+#define GL_SURFACE_STATE_NV 0x86EB
+#define GL_SURFACE_REGISTERED_NV 0x86FD
+#define GL_SURFACE_MAPPED_NV 0x8700
+#define GL_WRITE_DISCARD_NV 0x88BE
+typedef void (APIENTRYP PFNGLVDPAUINITNVPROC) (const void *vdpDevice, const void *getProcAddress);
+typedef void (APIENTRYP PFNGLVDPAUFININVPROC) (void);
+typedef GLvdpauSurfaceNV (APIENTRYP PFNGLVDPAUREGISTERVIDEOSURFACENVPROC) (const void *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames);
+typedef GLvdpauSurfaceNV (APIENTRYP PFNGLVDPAUREGISTEROUTPUTSURFACENVPROC) (const void *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames);
+typedef GLboolean (APIENTRYP PFNGLVDPAUISSURFACENVPROC) (GLvdpauSurfaceNV surface);
+typedef void (APIENTRYP PFNGLVDPAUUNREGISTERSURFACENVPROC) (GLvdpauSurfaceNV surface);
+typedef void (APIENTRYP PFNGLVDPAUGETSURFACEIVNVPROC) (GLvdpauSurfaceNV surface, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values);
+typedef void (APIENTRYP PFNGLVDPAUSURFACEACCESSNVPROC) (GLvdpauSurfaceNV surface, GLenum access);
+typedef void (APIENTRYP PFNGLVDPAUMAPSURFACESNVPROC) (GLsizei numSurfaces, const GLvdpauSurfaceNV *surfaces);
+typedef void (APIENTRYP PFNGLVDPAUUNMAPSURFACESNVPROC) (GLsizei numSurface, const GLvdpauSurfaceNV *surfaces);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVDPAUInitNV (const void *vdpDevice, const void *getProcAddress);
+GLAPI void APIENTRY glVDPAUFiniNV (void);
+GLAPI GLvdpauSurfaceNV APIENTRY glVDPAURegisterVideoSurfaceNV (const void *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames);
+GLAPI GLvdpauSurfaceNV APIENTRY glVDPAURegisterOutputSurfaceNV (const void *vdpSurface, GLenum target, GLsizei numTextureNames, const GLuint *textureNames);
+GLAPI GLboolean APIENTRY glVDPAUIsSurfaceNV (GLvdpauSurfaceNV surface);
+GLAPI void APIENTRY glVDPAUUnregisterSurfaceNV (GLvdpauSurfaceNV surface);
+GLAPI void APIENTRY glVDPAUGetSurfaceivNV (GLvdpauSurfaceNV surface, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values);
+GLAPI void APIENTRY glVDPAUSurfaceAccessNV (GLvdpauSurfaceNV surface, GLenum access);
+GLAPI void APIENTRY glVDPAUMapSurfacesNV (GLsizei numSurfaces, const GLvdpauSurfaceNV *surfaces);
+GLAPI void APIENTRY glVDPAUUnmapSurfacesNV (GLsizei numSurface, const GLvdpauSurfaceNV *surfaces);
+#endif
+#endif /* GL_NV_vdpau_interop */
+
+#ifndef GL_NV_vertex_array_range
+#define GL_NV_vertex_array_range 1
+#define GL_VERTEX_ARRAY_RANGE_NV 0x851D
+#define GL_VERTEX_ARRAY_RANGE_LENGTH_NV 0x851E
+#define GL_VERTEX_ARRAY_RANGE_VALID_NV 0x851F
+#define GL_MAX_VERTEX_ARRAY_RANGE_ELEMENT_NV 0x8520
+#define GL_VERTEX_ARRAY_RANGE_POINTER_NV 0x8521
+typedef void (APIENTRYP PFNGLFLUSHVERTEXARRAYRANGENVPROC) (void);
+typedef void (APIENTRYP PFNGLVERTEXARRAYRANGENVPROC) (GLsizei length, const void *pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glFlushVertexArrayRangeNV (void);
+GLAPI void APIENTRY glVertexArrayRangeNV (GLsizei length, const void *pointer);
+#endif
+#endif /* GL_NV_vertex_array_range */
+
+#ifndef GL_NV_vertex_array_range2
+#define GL_NV_vertex_array_range2 1
+#define GL_VERTEX_ARRAY_RANGE_WITHOUT_FLUSH_NV 0x8533
+#endif /* GL_NV_vertex_array_range2 */
+
+#ifndef GL_NV_vertex_attrib_integer_64bit
+#define GL_NV_vertex_attrib_integer_64bit 1
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1I64NVPROC) (GLuint index, GLint64EXT x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL2I64NVPROC) (GLuint index, GLint64EXT x, GLint64EXT y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL3I64NVPROC) (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL4I64NVPROC) (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1I64VNVPROC) (GLuint index, const GLint64EXT *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL2I64VNVPROC) (GLuint index, const GLint64EXT *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL3I64VNVPROC) (GLuint index, const GLint64EXT *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL4I64VNVPROC) (GLuint index, const GLint64EXT *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64NVPROC) (GLuint index, GLuint64EXT x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL2UI64NVPROC) (GLuint index, GLuint64EXT x, GLuint64EXT y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL3UI64NVPROC) (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL4UI64NVPROC) (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64VNVPROC) (GLuint index, const GLuint64EXT *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL2UI64VNVPROC) (GLuint index, const GLuint64EXT *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL3UI64VNVPROC) (GLuint index, const GLuint64EXT *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBL4UI64VNVPROC) (GLuint index, const GLuint64EXT *v);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLI64VNVPROC) (GLuint index, GLenum pname, GLint64EXT *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLUI64VNVPROC) (GLuint index, GLenum pname, GLuint64EXT *params);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBLFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLsizei stride);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexAttribL1i64NV (GLuint index, GLint64EXT x);
+GLAPI void APIENTRY glVertexAttribL2i64NV (GLuint index, GLint64EXT x, GLint64EXT y);
+GLAPI void APIENTRY glVertexAttribL3i64NV (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z);
+GLAPI void APIENTRY glVertexAttribL4i64NV (GLuint index, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
+GLAPI void APIENTRY glVertexAttribL1i64vNV (GLuint index, const GLint64EXT *v);
+GLAPI void APIENTRY glVertexAttribL2i64vNV (GLuint index, const GLint64EXT *v);
+GLAPI void APIENTRY glVertexAttribL3i64vNV (GLuint index, const GLint64EXT *v);
+GLAPI void APIENTRY glVertexAttribL4i64vNV (GLuint index, const GLint64EXT *v);
+GLAPI void APIENTRY glVertexAttribL1ui64NV (GLuint index, GLuint64EXT x);
+GLAPI void APIENTRY glVertexAttribL2ui64NV (GLuint index, GLuint64EXT x, GLuint64EXT y);
+GLAPI void APIENTRY glVertexAttribL3ui64NV (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
+GLAPI void APIENTRY glVertexAttribL4ui64NV (GLuint index, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
+GLAPI void APIENTRY glVertexAttribL1ui64vNV (GLuint index, const GLuint64EXT *v);
+GLAPI void APIENTRY glVertexAttribL2ui64vNV (GLuint index, const GLuint64EXT *v);
+GLAPI void APIENTRY glVertexAttribL3ui64vNV (GLuint index, const GLuint64EXT *v);
+GLAPI void APIENTRY glVertexAttribL4ui64vNV (GLuint index, const GLuint64EXT *v);
+GLAPI void APIENTRY glGetVertexAttribLi64vNV (GLuint index, GLenum pname, GLint64EXT *params);
+GLAPI void APIENTRY glGetVertexAttribLui64vNV (GLuint index, GLenum pname, GLuint64EXT *params);
+GLAPI void APIENTRY glVertexAttribLFormatNV (GLuint index, GLint size, GLenum type, GLsizei stride);
+#endif
+#endif /* GL_NV_vertex_attrib_integer_64bit */
+
+#ifndef GL_NV_vertex_buffer_unified_memory
+#define GL_NV_vertex_buffer_unified_memory 1
+#define GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV 0x8F1E
+#define GL_ELEMENT_ARRAY_UNIFIED_NV 0x8F1F
+#define GL_VERTEX_ATTRIB_ARRAY_ADDRESS_NV 0x8F20
+#define GL_VERTEX_ARRAY_ADDRESS_NV 0x8F21
+#define GL_NORMAL_ARRAY_ADDRESS_NV 0x8F22
+#define GL_COLOR_ARRAY_ADDRESS_NV 0x8F23
+#define GL_INDEX_ARRAY_ADDRESS_NV 0x8F24
+#define GL_TEXTURE_COORD_ARRAY_ADDRESS_NV 0x8F25
+#define GL_EDGE_FLAG_ARRAY_ADDRESS_NV 0x8F26
+#define GL_SECONDARY_COLOR_ARRAY_ADDRESS_NV 0x8F27
+#define GL_FOG_COORD_ARRAY_ADDRESS_NV 0x8F28
+#define GL_ELEMENT_ARRAY_ADDRESS_NV 0x8F29
+#define GL_VERTEX_ATTRIB_ARRAY_LENGTH_NV 0x8F2A
+#define GL_VERTEX_ARRAY_LENGTH_NV 0x8F2B
+#define GL_NORMAL_ARRAY_LENGTH_NV 0x8F2C
+#define GL_COLOR_ARRAY_LENGTH_NV 0x8F2D
+#define GL_INDEX_ARRAY_LENGTH_NV 0x8F2E
+#define GL_TEXTURE_COORD_ARRAY_LENGTH_NV 0x8F2F
+#define GL_EDGE_FLAG_ARRAY_LENGTH_NV 0x8F30
+#define GL_SECONDARY_COLOR_ARRAY_LENGTH_NV 0x8F31
+#define GL_FOG_COORD_ARRAY_LENGTH_NV 0x8F32
+#define GL_ELEMENT_ARRAY_LENGTH_NV 0x8F33
+#define GL_DRAW_INDIRECT_UNIFIED_NV 0x8F40
+#define GL_DRAW_INDIRECT_ADDRESS_NV 0x8F41
+#define GL_DRAW_INDIRECT_LENGTH_NV 0x8F42
+typedef void (APIENTRYP PFNGLBUFFERADDRESSRANGENVPROC) (GLenum pname, GLuint index, GLuint64EXT address, GLsizeiptr length);
+typedef void (APIENTRYP PFNGLVERTEXFORMATNVPROC) (GLint size, GLenum type, GLsizei stride);
+typedef void (APIENTRYP PFNGLNORMALFORMATNVPROC) (GLenum type, GLsizei stride);
+typedef void (APIENTRYP PFNGLCOLORFORMATNVPROC) (GLint size, GLenum type, GLsizei stride);
+typedef void (APIENTRYP PFNGLINDEXFORMATNVPROC) (GLenum type, GLsizei stride);
+typedef void (APIENTRYP PFNGLTEXCOORDFORMATNVPROC) (GLint size, GLenum type, GLsizei stride);
+typedef void (APIENTRYP PFNGLEDGEFLAGFORMATNVPROC) (GLsizei stride);
+typedef void (APIENTRYP PFNGLSECONDARYCOLORFORMATNVPROC) (GLint size, GLenum type, GLsizei stride);
+typedef void (APIENTRYP PFNGLFOGCOORDFORMATNVPROC) (GLenum type, GLsizei stride);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBIFORMATNVPROC) (GLuint index, GLint size, GLenum type, GLsizei stride);
+typedef void (APIENTRYP PFNGLGETINTEGERUI64I_VNVPROC) (GLenum value, GLuint index, GLuint64EXT *result);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBufferAddressRangeNV (GLenum pname, GLuint index, GLuint64EXT address, GLsizeiptr length);
+GLAPI void APIENTRY glVertexFormatNV (GLint size, GLenum type, GLsizei stride);
+GLAPI void APIENTRY glNormalFormatNV (GLenum type, GLsizei stride);
+GLAPI void APIENTRY glColorFormatNV (GLint size, GLenum type, GLsizei stride);
+GLAPI void APIENTRY glIndexFormatNV (GLenum type, GLsizei stride);
+GLAPI void APIENTRY glTexCoordFormatNV (GLint size, GLenum type, GLsizei stride);
+GLAPI void APIENTRY glEdgeFlagFormatNV (GLsizei stride);
+GLAPI void APIENTRY glSecondaryColorFormatNV (GLint size, GLenum type, GLsizei stride);
+GLAPI void APIENTRY glFogCoordFormatNV (GLenum type, GLsizei stride);
+GLAPI void APIENTRY glVertexAttribFormatNV (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride);
+GLAPI void APIENTRY glVertexAttribIFormatNV (GLuint index, GLint size, GLenum type, GLsizei stride);
+GLAPI void APIENTRY glGetIntegerui64i_vNV (GLenum value, GLuint index, GLuint64EXT *result);
+#endif
+#endif /* GL_NV_vertex_buffer_unified_memory */
+
+#ifndef GL_NV_vertex_program
+#define GL_NV_vertex_program 1
+#define GL_VERTEX_PROGRAM_NV 0x8620
+#define GL_VERTEX_STATE_PROGRAM_NV 0x8621
+#define GL_ATTRIB_ARRAY_SIZE_NV 0x8623
+#define GL_ATTRIB_ARRAY_STRIDE_NV 0x8624
+#define GL_ATTRIB_ARRAY_TYPE_NV 0x8625
+#define GL_CURRENT_ATTRIB_NV 0x8626
+#define GL_PROGRAM_LENGTH_NV 0x8627
+#define GL_PROGRAM_STRING_NV 0x8628
+#define GL_MODELVIEW_PROJECTION_NV 0x8629
+#define GL_IDENTITY_NV 0x862A
+#define GL_INVERSE_NV 0x862B
+#define GL_TRANSPOSE_NV 0x862C
+#define GL_INVERSE_TRANSPOSE_NV 0x862D
+#define GL_MAX_TRACK_MATRIX_STACK_DEPTH_NV 0x862E
+#define GL_MAX_TRACK_MATRICES_NV 0x862F
+#define GL_MATRIX0_NV 0x8630
+#define GL_MATRIX1_NV 0x8631
+#define GL_MATRIX2_NV 0x8632
+#define GL_MATRIX3_NV 0x8633
+#define GL_MATRIX4_NV 0x8634
+#define GL_MATRIX5_NV 0x8635
+#define GL_MATRIX6_NV 0x8636
+#define GL_MATRIX7_NV 0x8637
+#define GL_CURRENT_MATRIX_STACK_DEPTH_NV 0x8640
+#define GL_CURRENT_MATRIX_NV 0x8641
+#define GL_VERTEX_PROGRAM_POINT_SIZE_NV 0x8642
+#define GL_VERTEX_PROGRAM_TWO_SIDE_NV 0x8643
+#define GL_PROGRAM_PARAMETER_NV 0x8644
+#define GL_ATTRIB_ARRAY_POINTER_NV 0x8645
+#define GL_PROGRAM_TARGET_NV 0x8646
+#define GL_PROGRAM_RESIDENT_NV 0x8647
+#define GL_TRACK_MATRIX_NV 0x8648
+#define GL_TRACK_MATRIX_TRANSFORM_NV 0x8649
+#define GL_VERTEX_PROGRAM_BINDING_NV 0x864A
+#define GL_PROGRAM_ERROR_POSITION_NV 0x864B
+#define GL_VERTEX_ATTRIB_ARRAY0_NV 0x8650
+#define GL_VERTEX_ATTRIB_ARRAY1_NV 0x8651
+#define GL_VERTEX_ATTRIB_ARRAY2_NV 0x8652
+#define GL_VERTEX_ATTRIB_ARRAY3_NV 0x8653
+#define GL_VERTEX_ATTRIB_ARRAY4_NV 0x8654
+#define GL_VERTEX_ATTRIB_ARRAY5_NV 0x8655
+#define GL_VERTEX_ATTRIB_ARRAY6_NV 0x8656
+#define GL_VERTEX_ATTRIB_ARRAY7_NV 0x8657
+#define GL_VERTEX_ATTRIB_ARRAY8_NV 0x8658
+#define GL_VERTEX_ATTRIB_ARRAY9_NV 0x8659
+#define GL_VERTEX_ATTRIB_ARRAY10_NV 0x865A
+#define GL_VERTEX_ATTRIB_ARRAY11_NV 0x865B
+#define GL_VERTEX_ATTRIB_ARRAY12_NV 0x865C
+#define GL_VERTEX_ATTRIB_ARRAY13_NV 0x865D
+#define GL_VERTEX_ATTRIB_ARRAY14_NV 0x865E
+#define GL_VERTEX_ATTRIB_ARRAY15_NV 0x865F
+#define GL_MAP1_VERTEX_ATTRIB0_4_NV 0x8660
+#define GL_MAP1_VERTEX_ATTRIB1_4_NV 0x8661
+#define GL_MAP1_VERTEX_ATTRIB2_4_NV 0x8662
+#define GL_MAP1_VERTEX_ATTRIB3_4_NV 0x8663
+#define GL_MAP1_VERTEX_ATTRIB4_4_NV 0x8664
+#define GL_MAP1_VERTEX_ATTRIB5_4_NV 0x8665
+#define GL_MAP1_VERTEX_ATTRIB6_4_NV 0x8666
+#define GL_MAP1_VERTEX_ATTRIB7_4_NV 0x8667
+#define GL_MAP1_VERTEX_ATTRIB8_4_NV 0x8668
+#define GL_MAP1_VERTEX_ATTRIB9_4_NV 0x8669
+#define GL_MAP1_VERTEX_ATTRIB10_4_NV 0x866A
+#define GL_MAP1_VERTEX_ATTRIB11_4_NV 0x866B
+#define GL_MAP1_VERTEX_ATTRIB12_4_NV 0x866C
+#define GL_MAP1_VERTEX_ATTRIB13_4_NV 0x866D
+#define GL_MAP1_VERTEX_ATTRIB14_4_NV 0x866E
+#define GL_MAP1_VERTEX_ATTRIB15_4_NV 0x866F
+#define GL_MAP2_VERTEX_ATTRIB0_4_NV 0x8670
+#define GL_MAP2_VERTEX_ATTRIB1_4_NV 0x8671
+#define GL_MAP2_VERTEX_ATTRIB2_4_NV 0x8672
+#define GL_MAP2_VERTEX_ATTRIB3_4_NV 0x8673
+#define GL_MAP2_VERTEX_ATTRIB4_4_NV 0x8674
+#define GL_MAP2_VERTEX_ATTRIB5_4_NV 0x8675
+#define GL_MAP2_VERTEX_ATTRIB6_4_NV 0x8676
+#define GL_MAP2_VERTEX_ATTRIB7_4_NV 0x8677
+#define GL_MAP2_VERTEX_ATTRIB8_4_NV 0x8678
+#define GL_MAP2_VERTEX_ATTRIB9_4_NV 0x8679
+#define GL_MAP2_VERTEX_ATTRIB10_4_NV 0x867A
+#define GL_MAP2_VERTEX_ATTRIB11_4_NV 0x867B
+#define GL_MAP2_VERTEX_ATTRIB12_4_NV 0x867C
+#define GL_MAP2_VERTEX_ATTRIB13_4_NV 0x867D
+#define GL_MAP2_VERTEX_ATTRIB14_4_NV 0x867E
+#define GL_MAP2_VERTEX_ATTRIB15_4_NV 0x867F
+typedef GLboolean (APIENTRYP PFNGLAREPROGRAMSRESIDENTNVPROC) (GLsizei n, const GLuint *programs, GLboolean *residences);
+typedef void (APIENTRYP PFNGLBINDPROGRAMNVPROC) (GLenum target, GLuint id);
+typedef void (APIENTRYP PFNGLDELETEPROGRAMSNVPROC) (GLsizei n, const GLuint *programs);
+typedef void (APIENTRYP PFNGLEXECUTEPROGRAMNVPROC) (GLenum target, GLuint id, const GLfloat *params);
+typedef void (APIENTRYP PFNGLGENPROGRAMSNVPROC) (GLsizei n, GLuint *programs);
+typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERDVNVPROC) (GLenum target, GLuint index, GLenum pname, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMPARAMETERFVNVPROC) (GLenum target, GLuint index, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMIVNVPROC) (GLuint id, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETPROGRAMSTRINGNVPROC) (GLuint id, GLenum pname, GLubyte *program);
+typedef void (APIENTRYP PFNGLGETTRACKMATRIXIVNVPROC) (GLenum target, GLuint address, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBDVNVPROC) (GLuint index, GLenum pname, GLdouble *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBFVNVPROC) (GLuint index, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVNVPROC) (GLuint index, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVNVPROC) (GLuint index, GLenum pname, void **pointer);
+typedef GLboolean (APIENTRYP PFNGLISPROGRAMNVPROC) (GLuint id);
+typedef void (APIENTRYP PFNGLLOADPROGRAMNVPROC) (GLenum target, GLuint id, GLsizei len, const GLubyte *program);
+typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DNVPROC) (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DVNVPROC) (GLenum target, GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FNVPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FVNVPROC) (GLenum target, GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4DVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLdouble *v);
+typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4FVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *v);
+typedef void (APIENTRYP PFNGLREQUESTRESIDENTPROGRAMSNVPROC) (GLsizei n, const GLuint *programs);
+typedef void (APIENTRYP PFNGLTRACKMATRIXNVPROC) (GLenum target, GLuint address, GLenum matrix, GLenum transform);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERNVPROC) (GLuint index, GLint fsize, GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1DNVPROC) (GLuint index, GLdouble x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1DVNVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1FNVPROC) (GLuint index, GLfloat x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1FVNVPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1SNVPROC) (GLuint index, GLshort x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB1SVNVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2DNVPROC) (GLuint index, GLdouble x, GLdouble y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2DVNVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2FNVPROC) (GLuint index, GLfloat x, GLfloat y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2FVNVPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2SNVPROC) (GLuint index, GLshort x, GLshort y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB2SVNVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3DVNVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3FVNVPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB3SVNVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4DNVPROC) (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4DVNVPROC) (GLuint index, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4FNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4FVNVPROC) (GLuint index, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4SNVPROC) (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4SVNVPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBNVPROC) (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIB4UBVNVPROC) (GLuint index, const GLubyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS1DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS1FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS1SVNVPROC) (GLuint index, GLsizei count, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS2DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS2FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS2SVNVPROC) (GLuint index, GLsizei count, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS3DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS3FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS3SVNVPROC) (GLuint index, GLsizei count, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS4DVNVPROC) (GLuint index, GLsizei count, const GLdouble *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS4FVNVPROC) (GLuint index, GLsizei count, const GLfloat *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS4SVNVPROC) (GLuint index, GLsizei count, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBS4UBVNVPROC) (GLuint index, GLsizei count, const GLubyte *v);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLboolean APIENTRY glAreProgramsResidentNV (GLsizei n, const GLuint *programs, GLboolean *residences);
+GLAPI void APIENTRY glBindProgramNV (GLenum target, GLuint id);
+GLAPI void APIENTRY glDeleteProgramsNV (GLsizei n, const GLuint *programs);
+GLAPI void APIENTRY glExecuteProgramNV (GLenum target, GLuint id, const GLfloat *params);
+GLAPI void APIENTRY glGenProgramsNV (GLsizei n, GLuint *programs);
+GLAPI void APIENTRY glGetProgramParameterdvNV (GLenum target, GLuint index, GLenum pname, GLdouble *params);
+GLAPI void APIENTRY glGetProgramParameterfvNV (GLenum target, GLuint index, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetProgramivNV (GLuint id, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetProgramStringNV (GLuint id, GLenum pname, GLubyte *program);
+GLAPI void APIENTRY glGetTrackMatrixivNV (GLenum target, GLuint address, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetVertexAttribdvNV (GLuint index, GLenum pname, GLdouble *params);
+GLAPI void APIENTRY glGetVertexAttribfvNV (GLuint index, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetVertexAttribivNV (GLuint index, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetVertexAttribPointervNV (GLuint index, GLenum pname, void **pointer);
+GLAPI GLboolean APIENTRY glIsProgramNV (GLuint id);
+GLAPI void APIENTRY glLoadProgramNV (GLenum target, GLuint id, GLsizei len, const GLubyte *program);
+GLAPI void APIENTRY glProgramParameter4dNV (GLenum target, GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glProgramParameter4dvNV (GLenum target, GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glProgramParameter4fNV (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glProgramParameter4fvNV (GLenum target, GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glProgramParameters4dvNV (GLenum target, GLuint index, GLsizei count, const GLdouble *v);
+GLAPI void APIENTRY glProgramParameters4fvNV (GLenum target, GLuint index, GLsizei count, const GLfloat *v);
+GLAPI void APIENTRY glRequestResidentProgramsNV (GLsizei n, const GLuint *programs);
+GLAPI void APIENTRY glTrackMatrixNV (GLenum target, GLuint address, GLenum matrix, GLenum transform);
+GLAPI void APIENTRY glVertexAttribPointerNV (GLuint index, GLint fsize, GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glVertexAttrib1dNV (GLuint index, GLdouble x);
+GLAPI void APIENTRY glVertexAttrib1dvNV (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib1fNV (GLuint index, GLfloat x);
+GLAPI void APIENTRY glVertexAttrib1fvNV (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib1sNV (GLuint index, GLshort x);
+GLAPI void APIENTRY glVertexAttrib1svNV (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib2dNV (GLuint index, GLdouble x, GLdouble y);
+GLAPI void APIENTRY glVertexAttrib2dvNV (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib2fNV (GLuint index, GLfloat x, GLfloat y);
+GLAPI void APIENTRY glVertexAttrib2fvNV (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib2sNV (GLuint index, GLshort x, GLshort y);
+GLAPI void APIENTRY glVertexAttrib2svNV (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib3dNV (GLuint index, GLdouble x, GLdouble y, GLdouble z);
+GLAPI void APIENTRY glVertexAttrib3dvNV (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib3fNV (GLuint index, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glVertexAttrib3fvNV (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib3sNV (GLuint index, GLshort x, GLshort y, GLshort z);
+GLAPI void APIENTRY glVertexAttrib3svNV (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib4dNV (GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w);
+GLAPI void APIENTRY glVertexAttrib4dvNV (GLuint index, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttrib4fNV (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glVertexAttrib4fvNV (GLuint index, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttrib4sNV (GLuint index, GLshort x, GLshort y, GLshort z, GLshort w);
+GLAPI void APIENTRY glVertexAttrib4svNV (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttrib4ubNV (GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w);
+GLAPI void APIENTRY glVertexAttrib4ubvNV (GLuint index, const GLubyte *v);
+GLAPI void APIENTRY glVertexAttribs1dvNV (GLuint index, GLsizei count, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribs1fvNV (GLuint index, GLsizei count, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttribs1svNV (GLuint index, GLsizei count, const GLshort *v);
+GLAPI void APIENTRY glVertexAttribs2dvNV (GLuint index, GLsizei count, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribs2fvNV (GLuint index, GLsizei count, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttribs2svNV (GLuint index, GLsizei count, const GLshort *v);
+GLAPI void APIENTRY glVertexAttribs3dvNV (GLuint index, GLsizei count, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribs3fvNV (GLuint index, GLsizei count, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttribs3svNV (GLuint index, GLsizei count, const GLshort *v);
+GLAPI void APIENTRY glVertexAttribs4dvNV (GLuint index, GLsizei count, const GLdouble *v);
+GLAPI void APIENTRY glVertexAttribs4fvNV (GLuint index, GLsizei count, const GLfloat *v);
+GLAPI void APIENTRY glVertexAttribs4svNV (GLuint index, GLsizei count, const GLshort *v);
+GLAPI void APIENTRY glVertexAttribs4ubvNV (GLuint index, GLsizei count, const GLubyte *v);
+#endif
+#endif /* GL_NV_vertex_program */
+
+#ifndef GL_NV_vertex_program1_1
+#define GL_NV_vertex_program1_1 1
+#endif /* GL_NV_vertex_program1_1 */
+
+#ifndef GL_NV_vertex_program2
+#define GL_NV_vertex_program2 1
+#endif /* GL_NV_vertex_program2 */
+
+#ifndef GL_NV_vertex_program2_option
+#define GL_NV_vertex_program2_option 1
+#endif /* GL_NV_vertex_program2_option */
+
+#ifndef GL_NV_vertex_program3
+#define GL_NV_vertex_program3 1
+#endif /* GL_NV_vertex_program3 */
+
+#ifndef GL_NV_vertex_program4
+#define GL_NV_vertex_program4 1
+#define GL_VERTEX_ATTRIB_ARRAY_INTEGER_NV 0x88FD
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IEXTPROC) (GLuint index, GLint x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IEXTPROC) (GLuint index, GLint x, GLint y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IEXTPROC) (GLuint index, GLint x, GLint y, GLint z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IEXTPROC) (GLuint index, GLint x, GLint y, GLint z, GLint w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIEXTPROC) (GLuint index, GLuint x);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIEXTPROC) (GLuint index, GLuint x, GLuint y);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIEXTPROC) (GLuint index, GLuint x, GLuint y, GLuint z);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIEXTPROC) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI1IVEXTPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI2IVEXTPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI3IVEXTPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4IVEXTPROC) (GLuint index, const GLint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI1UIVEXTPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI2UIVEXTPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI3UIVEXTPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UIVEXTPROC) (GLuint index, const GLuint *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4BVEXTPROC) (GLuint index, const GLbyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4SVEXTPROC) (GLuint index, const GLshort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4UBVEXTPROC) (GLuint index, const GLubyte *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBI4USVEXTPROC) (GLuint index, const GLushort *v);
+typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTEREXTPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIIVEXTPROC) (GLuint index, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIUIVEXTPROC) (GLuint index, GLenum pname, GLuint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glVertexAttribI1iEXT (GLuint index, GLint x);
+GLAPI void APIENTRY glVertexAttribI2iEXT (GLuint index, GLint x, GLint y);
+GLAPI void APIENTRY glVertexAttribI3iEXT (GLuint index, GLint x, GLint y, GLint z);
+GLAPI void APIENTRY glVertexAttribI4iEXT (GLuint index, GLint x, GLint y, GLint z, GLint w);
+GLAPI void APIENTRY glVertexAttribI1uiEXT (GLuint index, GLuint x);
+GLAPI void APIENTRY glVertexAttribI2uiEXT (GLuint index, GLuint x, GLuint y);
+GLAPI void APIENTRY glVertexAttribI3uiEXT (GLuint index, GLuint x, GLuint y, GLuint z);
+GLAPI void APIENTRY glVertexAttribI4uiEXT (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w);
+GLAPI void APIENTRY glVertexAttribI1ivEXT (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttribI2ivEXT (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttribI3ivEXT (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttribI4ivEXT (GLuint index, const GLint *v);
+GLAPI void APIENTRY glVertexAttribI1uivEXT (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttribI2uivEXT (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttribI3uivEXT (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttribI4uivEXT (GLuint index, const GLuint *v);
+GLAPI void APIENTRY glVertexAttribI4bvEXT (GLuint index, const GLbyte *v);
+GLAPI void APIENTRY glVertexAttribI4svEXT (GLuint index, const GLshort *v);
+GLAPI void APIENTRY glVertexAttribI4ubvEXT (GLuint index, const GLubyte *v);
+GLAPI void APIENTRY glVertexAttribI4usvEXT (GLuint index, const GLushort *v);
+GLAPI void APIENTRY glVertexAttribIPointerEXT (GLuint index, GLint size, GLenum type, GLsizei stride, const void *pointer);
+GLAPI void APIENTRY glGetVertexAttribIivEXT (GLuint index, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetVertexAttribIuivEXT (GLuint index, GLenum pname, GLuint *params);
+#endif
+#endif /* GL_NV_vertex_program4 */
+
+#ifndef GL_NV_video_capture
+#define GL_NV_video_capture 1
+#define GL_VIDEO_BUFFER_NV 0x9020
+#define GL_VIDEO_BUFFER_BINDING_NV 0x9021
+#define GL_FIELD_UPPER_NV 0x9022
+#define GL_FIELD_LOWER_NV 0x9023
+#define GL_NUM_VIDEO_CAPTURE_STREAMS_NV 0x9024
+#define GL_NEXT_VIDEO_CAPTURE_BUFFER_STATUS_NV 0x9025
+#define GL_VIDEO_CAPTURE_TO_422_SUPPORTED_NV 0x9026
+#define GL_LAST_VIDEO_CAPTURE_STATUS_NV 0x9027
+#define GL_VIDEO_BUFFER_PITCH_NV 0x9028
+#define GL_VIDEO_COLOR_CONVERSION_MATRIX_NV 0x9029
+#define GL_VIDEO_COLOR_CONVERSION_MAX_NV 0x902A
+#define GL_VIDEO_COLOR_CONVERSION_MIN_NV 0x902B
+#define GL_VIDEO_COLOR_CONVERSION_OFFSET_NV 0x902C
+#define GL_VIDEO_BUFFER_INTERNAL_FORMAT_NV 0x902D
+#define GL_PARTIAL_SUCCESS_NV 0x902E
+#define GL_SUCCESS_NV 0x902F
+#define GL_FAILURE_NV 0x9030
+#define GL_YCBYCR8_422_NV 0x9031
+#define GL_YCBAYCR8A_4224_NV 0x9032
+#define GL_Z6Y10Z6CB10Z6Y10Z6CR10_422_NV 0x9033
+#define GL_Z6Y10Z6CB10Z6A10Z6Y10Z6CR10Z6A10_4224_NV 0x9034
+#define GL_Z4Y12Z4CB12Z4Y12Z4CR12_422_NV 0x9035
+#define GL_Z4Y12Z4CB12Z4A12Z4Y12Z4CR12Z4A12_4224_NV 0x9036
+#define GL_Z4Y12Z4CB12Z4CR12_444_NV 0x9037
+#define GL_VIDEO_CAPTURE_FRAME_WIDTH_NV 0x9038
+#define GL_VIDEO_CAPTURE_FRAME_HEIGHT_NV 0x9039
+#define GL_VIDEO_CAPTURE_FIELD_UPPER_HEIGHT_NV 0x903A
+#define GL_VIDEO_CAPTURE_FIELD_LOWER_HEIGHT_NV 0x903B
+#define GL_VIDEO_CAPTURE_SURFACE_ORIGIN_NV 0x903C
+typedef void (APIENTRYP PFNGLBEGINVIDEOCAPTURENVPROC) (GLuint video_capture_slot);
+typedef void (APIENTRYP PFNGLBINDVIDEOCAPTURESTREAMBUFFERNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLintptrARB offset);
+typedef void (APIENTRYP PFNGLBINDVIDEOCAPTURESTREAMTEXTURENVPROC) (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLenum target, GLuint texture);
+typedef void (APIENTRYP PFNGLENDVIDEOCAPTURENVPROC) (GLuint video_capture_slot);
+typedef void (APIENTRYP PFNGLGETVIDEOCAPTUREIVNVPROC) (GLuint video_capture_slot, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMIVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMFVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETVIDEOCAPTURESTREAMDVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, GLdouble *params);
+typedef GLenum (APIENTRYP PFNGLVIDEOCAPTURENVPROC) (GLuint video_capture_slot, GLuint *sequence_num, GLuint64EXT *capture_time);
+typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERIVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERFVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLVIDEOCAPTURESTREAMPARAMETERDVNVPROC) (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLdouble *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glBeginVideoCaptureNV (GLuint video_capture_slot);
+GLAPI void APIENTRY glBindVideoCaptureStreamBufferNV (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLintptrARB offset);
+GLAPI void APIENTRY glBindVideoCaptureStreamTextureNV (GLuint video_capture_slot, GLuint stream, GLenum frame_region, GLenum target, GLuint texture);
+GLAPI void APIENTRY glEndVideoCaptureNV (GLuint video_capture_slot);
+GLAPI void APIENTRY glGetVideoCaptureivNV (GLuint video_capture_slot, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetVideoCaptureStreamivNV (GLuint video_capture_slot, GLuint stream, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetVideoCaptureStreamfvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetVideoCaptureStreamdvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, GLdouble *params);
+GLAPI GLenum APIENTRY glVideoCaptureNV (GLuint video_capture_slot, GLuint *sequence_num, GLuint64EXT *capture_time);
+GLAPI void APIENTRY glVideoCaptureStreamParameterivNV (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glVideoCaptureStreamParameterfvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glVideoCaptureStreamParameterdvNV (GLuint video_capture_slot, GLuint stream, GLenum pname, const GLdouble *params);
+#endif
+#endif /* GL_NV_video_capture */
+
+#ifndef GL_OML_interlace
+#define GL_OML_interlace 1
+#define GL_INTERLACE_OML 0x8980
+#define GL_INTERLACE_READ_OML 0x8981
+#endif /* GL_OML_interlace */
+
+#ifndef GL_OML_resample
+#define GL_OML_resample 1
+#define GL_PACK_RESAMPLE_OML 0x8984
+#define GL_UNPACK_RESAMPLE_OML 0x8985
+#define GL_RESAMPLE_REPLICATE_OML 0x8986
+#define GL_RESAMPLE_ZERO_FILL_OML 0x8987
+#define GL_RESAMPLE_AVERAGE_OML 0x8988
+#define GL_RESAMPLE_DECIMATE_OML 0x8989
+#endif /* GL_OML_resample */
+
+#ifndef GL_OML_subsample
+#define GL_OML_subsample 1
+#define GL_FORMAT_SUBSAMPLE_24_24_OML 0x8982
+#define GL_FORMAT_SUBSAMPLE_244_244_OML 0x8983
+#endif /* GL_OML_subsample */
+
+#ifndef GL_PGI_misc_hints
+#define GL_PGI_misc_hints 1
+#define GL_PREFER_DOUBLEBUFFER_HINT_PGI 0x1A1F8
+#define GL_CONSERVE_MEMORY_HINT_PGI 0x1A1FD
+#define GL_RECLAIM_MEMORY_HINT_PGI 0x1A1FE
+#define GL_NATIVE_GRAPHICS_HANDLE_PGI 0x1A202
+#define GL_NATIVE_GRAPHICS_BEGIN_HINT_PGI 0x1A203
+#define GL_NATIVE_GRAPHICS_END_HINT_PGI 0x1A204
+#define GL_ALWAYS_FAST_HINT_PGI 0x1A20C
+#define GL_ALWAYS_SOFT_HINT_PGI 0x1A20D
+#define GL_ALLOW_DRAW_OBJ_HINT_PGI 0x1A20E
+#define GL_ALLOW_DRAW_WIN_HINT_PGI 0x1A20F
+#define GL_ALLOW_DRAW_FRG_HINT_PGI 0x1A210
+#define GL_ALLOW_DRAW_MEM_HINT_PGI 0x1A211
+#define GL_STRICT_DEPTHFUNC_HINT_PGI 0x1A216
+#define GL_STRICT_LIGHTING_HINT_PGI 0x1A217
+#define GL_STRICT_SCISSOR_HINT_PGI 0x1A218
+#define GL_FULL_STIPPLE_HINT_PGI 0x1A219
+#define GL_CLIP_NEAR_HINT_PGI 0x1A220
+#define GL_CLIP_FAR_HINT_PGI 0x1A221
+#define GL_WIDE_LINE_HINT_PGI 0x1A222
+#define GL_BACK_NORMALS_HINT_PGI 0x1A223
+typedef void (APIENTRYP PFNGLHINTPGIPROC) (GLenum target, GLint mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glHintPGI (GLenum target, GLint mode);
+#endif
+#endif /* GL_PGI_misc_hints */
+
+#ifndef GL_PGI_vertex_hints
+#define GL_PGI_vertex_hints 1
+#define GL_VERTEX_DATA_HINT_PGI 0x1A22A
+#define GL_VERTEX_CONSISTENT_HINT_PGI 0x1A22B
+#define GL_MATERIAL_SIDE_HINT_PGI 0x1A22C
+#define GL_MAX_VERTEX_HINT_PGI 0x1A22D
+#define GL_COLOR3_BIT_PGI 0x00010000
+#define GL_COLOR4_BIT_PGI 0x00020000
+#define GL_EDGEFLAG_BIT_PGI 0x00040000
+#define GL_INDEX_BIT_PGI 0x00080000
+#define GL_MAT_AMBIENT_BIT_PGI 0x00100000
+#define GL_MAT_AMBIENT_AND_DIFFUSE_BIT_PGI 0x00200000
+#define GL_MAT_DIFFUSE_BIT_PGI 0x00400000
+#define GL_MAT_EMISSION_BIT_PGI 0x00800000
+#define GL_MAT_COLOR_INDEXES_BIT_PGI 0x01000000
+#define GL_MAT_SHININESS_BIT_PGI 0x02000000
+#define GL_MAT_SPECULAR_BIT_PGI 0x04000000
+#define GL_NORMAL_BIT_PGI 0x08000000
+#define GL_TEXCOORD1_BIT_PGI 0x10000000
+#define GL_TEXCOORD2_BIT_PGI 0x20000000
+#define GL_TEXCOORD3_BIT_PGI 0x40000000
+#define GL_TEXCOORD4_BIT_PGI 0x80000000
+#define GL_VERTEX23_BIT_PGI 0x00000004
+#define GL_VERTEX4_BIT_PGI 0x00000008
+#endif /* GL_PGI_vertex_hints */
+
+#ifndef GL_REND_screen_coordinates
+#define GL_REND_screen_coordinates 1
+#define GL_SCREEN_COORDINATES_REND 0x8490
+#define GL_INVERTED_SCREEN_W_REND 0x8491
+#endif /* GL_REND_screen_coordinates */
+
+#ifndef GL_S3_s3tc
+#define GL_S3_s3tc 1
+#define GL_RGB_S3TC 0x83A0
+#define GL_RGB4_S3TC 0x83A1
+#define GL_RGBA_S3TC 0x83A2
+#define GL_RGBA4_S3TC 0x83A3
+#define GL_RGBA_DXT5_S3TC 0x83A4
+#define GL_RGBA4_DXT5_S3TC 0x83A5
+#endif /* GL_S3_s3tc */
+
+#ifndef GL_SGIS_detail_texture
+#define GL_SGIS_detail_texture 1
+#define GL_DETAIL_TEXTURE_2D_SGIS 0x8095
+#define GL_DETAIL_TEXTURE_2D_BINDING_SGIS 0x8096
+#define GL_LINEAR_DETAIL_SGIS 0x8097
+#define GL_LINEAR_DETAIL_ALPHA_SGIS 0x8098
+#define GL_LINEAR_DETAIL_COLOR_SGIS 0x8099
+#define GL_DETAIL_TEXTURE_LEVEL_SGIS 0x809A
+#define GL_DETAIL_TEXTURE_MODE_SGIS 0x809B
+#define GL_DETAIL_TEXTURE_FUNC_POINTS_SGIS 0x809C
+typedef void (APIENTRYP PFNGLDETAILTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points);
+typedef void (APIENTRYP PFNGLGETDETAILTEXFUNCSGISPROC) (GLenum target, GLfloat *points);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDetailTexFuncSGIS (GLenum target, GLsizei n, const GLfloat *points);
+GLAPI void APIENTRY glGetDetailTexFuncSGIS (GLenum target, GLfloat *points);
+#endif
+#endif /* GL_SGIS_detail_texture */
+
+#ifndef GL_SGIS_fog_function
+#define GL_SGIS_fog_function 1
+#define GL_FOG_FUNC_SGIS 0x812A
+#define GL_FOG_FUNC_POINTS_SGIS 0x812B
+#define GL_MAX_FOG_FUNC_POINTS_SGIS 0x812C
+typedef void (APIENTRYP PFNGLFOGFUNCSGISPROC) (GLsizei n, const GLfloat *points);
+typedef void (APIENTRYP PFNGLGETFOGFUNCSGISPROC) (GLfloat *points);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glFogFuncSGIS (GLsizei n, const GLfloat *points);
+GLAPI void APIENTRY glGetFogFuncSGIS (GLfloat *points);
+#endif
+#endif /* GL_SGIS_fog_function */
+
+#ifndef GL_SGIS_generate_mipmap
+#define GL_SGIS_generate_mipmap 1
+#define GL_GENERATE_MIPMAP_SGIS 0x8191
+#define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192
+#endif /* GL_SGIS_generate_mipmap */
+
+#ifndef GL_SGIS_multisample
+#define GL_SGIS_multisample 1
+#define GL_MULTISAMPLE_SGIS 0x809D
+#define GL_SAMPLE_ALPHA_TO_MASK_SGIS 0x809E
+#define GL_SAMPLE_ALPHA_TO_ONE_SGIS 0x809F
+#define GL_SAMPLE_MASK_SGIS 0x80A0
+#define GL_1PASS_SGIS 0x80A1
+#define GL_2PASS_0_SGIS 0x80A2
+#define GL_2PASS_1_SGIS 0x80A3
+#define GL_4PASS_0_SGIS 0x80A4
+#define GL_4PASS_1_SGIS 0x80A5
+#define GL_4PASS_2_SGIS 0x80A6
+#define GL_4PASS_3_SGIS 0x80A7
+#define GL_SAMPLE_BUFFERS_SGIS 0x80A8
+#define GL_SAMPLES_SGIS 0x80A9
+#define GL_SAMPLE_MASK_VALUE_SGIS 0x80AA
+#define GL_SAMPLE_MASK_INVERT_SGIS 0x80AB
+#define GL_SAMPLE_PATTERN_SGIS 0x80AC
+typedef void (APIENTRYP PFNGLSAMPLEMASKSGISPROC) (GLclampf value, GLboolean invert);
+typedef void (APIENTRYP PFNGLSAMPLEPATTERNSGISPROC) (GLenum pattern);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glSampleMaskSGIS (GLclampf value, GLboolean invert);
+GLAPI void APIENTRY glSamplePatternSGIS (GLenum pattern);
+#endif
+#endif /* GL_SGIS_multisample */
+
+#ifndef GL_SGIS_pixel_texture
+#define GL_SGIS_pixel_texture 1
+#define GL_PIXEL_TEXTURE_SGIS 0x8353
+#define GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS 0x8354
+#define GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS 0x8355
+#define GL_PIXEL_GROUP_COLOR_SGIS 0x8356
+typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERISGISPROC) (GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFSGISPROC) (GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERIVSGISPROC) (GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETPIXELTEXGENPARAMETERFVSGISPROC) (GLenum pname, GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPixelTexGenParameteriSGIS (GLenum pname, GLint param);
+GLAPI void APIENTRY glPixelTexGenParameterivSGIS (GLenum pname, const GLint *params);
+GLAPI void APIENTRY glPixelTexGenParameterfSGIS (GLenum pname, GLfloat param);
+GLAPI void APIENTRY glPixelTexGenParameterfvSGIS (GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glGetPixelTexGenParameterivSGIS (GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetPixelTexGenParameterfvSGIS (GLenum pname, GLfloat *params);
+#endif
+#endif /* GL_SGIS_pixel_texture */
+
+#ifndef GL_SGIS_point_line_texgen
+#define GL_SGIS_point_line_texgen 1
+#define GL_EYE_DISTANCE_TO_POINT_SGIS 0x81F0
+#define GL_OBJECT_DISTANCE_TO_POINT_SGIS 0x81F1
+#define GL_EYE_DISTANCE_TO_LINE_SGIS 0x81F2
+#define GL_OBJECT_DISTANCE_TO_LINE_SGIS 0x81F3
+#define GL_EYE_POINT_SGIS 0x81F4
+#define GL_OBJECT_POINT_SGIS 0x81F5
+#define GL_EYE_LINE_SGIS 0x81F6
+#define GL_OBJECT_LINE_SGIS 0x81F7
+#endif /* GL_SGIS_point_line_texgen */
+
+#ifndef GL_SGIS_point_parameters
+#define GL_SGIS_point_parameters 1
+#define GL_POINT_SIZE_MIN_SGIS 0x8126
+#define GL_POINT_SIZE_MAX_SGIS 0x8127
+#define GL_POINT_FADE_THRESHOLD_SIZE_SGIS 0x8128
+#define GL_DISTANCE_ATTENUATION_SGIS 0x8129
+typedef void (APIENTRYP PFNGLPOINTPARAMETERFSGISPROC) (GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLPOINTPARAMETERFVSGISPROC) (GLenum pname, const GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPointParameterfSGIS (GLenum pname, GLfloat param);
+GLAPI void APIENTRY glPointParameterfvSGIS (GLenum pname, const GLfloat *params);
+#endif
+#endif /* GL_SGIS_point_parameters */
+
+#ifndef GL_SGIS_sharpen_texture
+#define GL_SGIS_sharpen_texture 1
+#define GL_LINEAR_SHARPEN_SGIS 0x80AD
+#define GL_LINEAR_SHARPEN_ALPHA_SGIS 0x80AE
+#define GL_LINEAR_SHARPEN_COLOR_SGIS 0x80AF
+#define GL_SHARPEN_TEXTURE_FUNC_POINTS_SGIS 0x80B0
+typedef void (APIENTRYP PFNGLSHARPENTEXFUNCSGISPROC) (GLenum target, GLsizei n, const GLfloat *points);
+typedef void (APIENTRYP PFNGLGETSHARPENTEXFUNCSGISPROC) (GLenum target, GLfloat *points);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glSharpenTexFuncSGIS (GLenum target, GLsizei n, const GLfloat *points);
+GLAPI void APIENTRY glGetSharpenTexFuncSGIS (GLenum target, GLfloat *points);
+#endif
+#endif /* GL_SGIS_sharpen_texture */
+
+#ifndef GL_SGIS_texture4D
+#define GL_SGIS_texture4D 1
+#define GL_PACK_SKIP_VOLUMES_SGIS 0x8130
+#define GL_PACK_IMAGE_DEPTH_SGIS 0x8131
+#define GL_UNPACK_SKIP_VOLUMES_SGIS 0x8132
+#define GL_UNPACK_IMAGE_DEPTH_SGIS 0x8133
+#define GL_TEXTURE_4D_SGIS 0x8134
+#define GL_PROXY_TEXTURE_4D_SGIS 0x8135
+#define GL_TEXTURE_4DSIZE_SGIS 0x8136
+#define GL_TEXTURE_WRAP_Q_SGIS 0x8137
+#define GL_MAX_4D_TEXTURE_SIZE_SGIS 0x8138
+#define GL_TEXTURE_4D_BINDING_SGIS 0x814F
+typedef void (APIENTRYP PFNGLTEXIMAGE4DSGISPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (APIENTRYP PFNGLTEXSUBIMAGE4DSGISPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint woffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLenum format, GLenum type, const void *pixels);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTexImage4DSGIS (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLint border, GLenum format, GLenum type, const void *pixels);
+GLAPI void APIENTRY glTexSubImage4DSGIS (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint woffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei size4d, GLenum format, GLenum type, const void *pixels);
+#endif
+#endif /* GL_SGIS_texture4D */
+
+#ifndef GL_SGIS_texture_border_clamp
+#define GL_SGIS_texture_border_clamp 1
+#define GL_CLAMP_TO_BORDER_SGIS 0x812D
+#endif /* GL_SGIS_texture_border_clamp */
+
+#ifndef GL_SGIS_texture_color_mask
+#define GL_SGIS_texture_color_mask 1
+#define GL_TEXTURE_COLOR_WRITEMASK_SGIS 0x81EF
+typedef void (APIENTRYP PFNGLTEXTURECOLORMASKSGISPROC) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTextureColorMaskSGIS (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
+#endif
+#endif /* GL_SGIS_texture_color_mask */
+
+#ifndef GL_SGIS_texture_edge_clamp
+#define GL_SGIS_texture_edge_clamp 1
+#define GL_CLAMP_TO_EDGE_SGIS 0x812F
+#endif /* GL_SGIS_texture_edge_clamp */
+
+#ifndef GL_SGIS_texture_filter4
+#define GL_SGIS_texture_filter4 1
+#define GL_FILTER4_SGIS 0x8146
+#define GL_TEXTURE_FILTER4_SIZE_SGIS 0x8147
+typedef void (APIENTRYP PFNGLGETTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLfloat *weights);
+typedef void (APIENTRYP PFNGLTEXFILTERFUNCSGISPROC) (GLenum target, GLenum filter, GLsizei n, const GLfloat *weights);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGetTexFilterFuncSGIS (GLenum target, GLenum filter, GLfloat *weights);
+GLAPI void APIENTRY glTexFilterFuncSGIS (GLenum target, GLenum filter, GLsizei n, const GLfloat *weights);
+#endif
+#endif /* GL_SGIS_texture_filter4 */
+
+#ifndef GL_SGIS_texture_lod
+#define GL_SGIS_texture_lod 1
+#define GL_TEXTURE_MIN_LOD_SGIS 0x813A
+#define GL_TEXTURE_MAX_LOD_SGIS 0x813B
+#define GL_TEXTURE_BASE_LEVEL_SGIS 0x813C
+#define GL_TEXTURE_MAX_LEVEL_SGIS 0x813D
+#endif /* GL_SGIS_texture_lod */
+
+#ifndef GL_SGIS_texture_select
+#define GL_SGIS_texture_select 1
+#define GL_DUAL_ALPHA4_SGIS 0x8110
+#define GL_DUAL_ALPHA8_SGIS 0x8111
+#define GL_DUAL_ALPHA12_SGIS 0x8112
+#define GL_DUAL_ALPHA16_SGIS 0x8113
+#define GL_DUAL_LUMINANCE4_SGIS 0x8114
+#define GL_DUAL_LUMINANCE8_SGIS 0x8115
+#define GL_DUAL_LUMINANCE12_SGIS 0x8116
+#define GL_DUAL_LUMINANCE16_SGIS 0x8117
+#define GL_DUAL_INTENSITY4_SGIS 0x8118
+#define GL_DUAL_INTENSITY8_SGIS 0x8119
+#define GL_DUAL_INTENSITY12_SGIS 0x811A
+#define GL_DUAL_INTENSITY16_SGIS 0x811B
+#define GL_DUAL_LUMINANCE_ALPHA4_SGIS 0x811C
+#define GL_DUAL_LUMINANCE_ALPHA8_SGIS 0x811D
+#define GL_QUAD_ALPHA4_SGIS 0x811E
+#define GL_QUAD_ALPHA8_SGIS 0x811F
+#define GL_QUAD_LUMINANCE4_SGIS 0x8120
+#define GL_QUAD_LUMINANCE8_SGIS 0x8121
+#define GL_QUAD_INTENSITY4_SGIS 0x8122
+#define GL_QUAD_INTENSITY8_SGIS 0x8123
+#define GL_DUAL_TEXTURE_SELECT_SGIS 0x8124
+#define GL_QUAD_TEXTURE_SELECT_SGIS 0x8125
+#endif /* GL_SGIS_texture_select */
+
+#ifndef GL_SGIX_async
+#define GL_SGIX_async 1
+#define GL_ASYNC_MARKER_SGIX 0x8329
+typedef void (APIENTRYP PFNGLASYNCMARKERSGIXPROC) (GLuint marker);
+typedef GLint (APIENTRYP PFNGLFINISHASYNCSGIXPROC) (GLuint *markerp);
+typedef GLint (APIENTRYP PFNGLPOLLASYNCSGIXPROC) (GLuint *markerp);
+typedef GLuint (APIENTRYP PFNGLGENASYNCMARKERSSGIXPROC) (GLsizei range);
+typedef void (APIENTRYP PFNGLDELETEASYNCMARKERSSGIXPROC) (GLuint marker, GLsizei range);
+typedef GLboolean (APIENTRYP PFNGLISASYNCMARKERSGIXPROC) (GLuint marker);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glAsyncMarkerSGIX (GLuint marker);
+GLAPI GLint APIENTRY glFinishAsyncSGIX (GLuint *markerp);
+GLAPI GLint APIENTRY glPollAsyncSGIX (GLuint *markerp);
+GLAPI GLuint APIENTRY glGenAsyncMarkersSGIX (GLsizei range);
+GLAPI void APIENTRY glDeleteAsyncMarkersSGIX (GLuint marker, GLsizei range);
+GLAPI GLboolean APIENTRY glIsAsyncMarkerSGIX (GLuint marker);
+#endif
+#endif /* GL_SGIX_async */
+
+#ifndef GL_SGIX_async_histogram
+#define GL_SGIX_async_histogram 1
+#define GL_ASYNC_HISTOGRAM_SGIX 0x832C
+#define GL_MAX_ASYNC_HISTOGRAM_SGIX 0x832D
+#endif /* GL_SGIX_async_histogram */
+
+#ifndef GL_SGIX_async_pixel
+#define GL_SGIX_async_pixel 1
+#define GL_ASYNC_TEX_IMAGE_SGIX 0x835C
+#define GL_ASYNC_DRAW_PIXELS_SGIX 0x835D
+#define GL_ASYNC_READ_PIXELS_SGIX 0x835E
+#define GL_MAX_ASYNC_TEX_IMAGE_SGIX 0x835F
+#define GL_MAX_ASYNC_DRAW_PIXELS_SGIX 0x8360
+#define GL_MAX_ASYNC_READ_PIXELS_SGIX 0x8361
+#endif /* GL_SGIX_async_pixel */
+
+#ifndef GL_SGIX_blend_alpha_minmax
+#define GL_SGIX_blend_alpha_minmax 1
+#define GL_ALPHA_MIN_SGIX 0x8320
+#define GL_ALPHA_MAX_SGIX 0x8321
+#endif /* GL_SGIX_blend_alpha_minmax */
+
+#ifndef GL_SGIX_calligraphic_fragment
+#define GL_SGIX_calligraphic_fragment 1
+#define GL_CALLIGRAPHIC_FRAGMENT_SGIX 0x8183
+#endif /* GL_SGIX_calligraphic_fragment */
+
+#ifndef GL_SGIX_clipmap
+#define GL_SGIX_clipmap 1
+#define GL_LINEAR_CLIPMAP_LINEAR_SGIX 0x8170
+#define GL_TEXTURE_CLIPMAP_CENTER_SGIX 0x8171
+#define GL_TEXTURE_CLIPMAP_FRAME_SGIX 0x8172
+#define GL_TEXTURE_CLIPMAP_OFFSET_SGIX 0x8173
+#define GL_TEXTURE_CLIPMAP_VIRTUAL_DEPTH_SGIX 0x8174
+#define GL_TEXTURE_CLIPMAP_LOD_OFFSET_SGIX 0x8175
+#define GL_TEXTURE_CLIPMAP_DEPTH_SGIX 0x8176
+#define GL_MAX_CLIPMAP_DEPTH_SGIX 0x8177
+#define GL_MAX_CLIPMAP_VIRTUAL_DEPTH_SGIX 0x8178
+#define GL_NEAREST_CLIPMAP_NEAREST_SGIX 0x844D
+#define GL_NEAREST_CLIPMAP_LINEAR_SGIX 0x844E
+#define GL_LINEAR_CLIPMAP_NEAREST_SGIX 0x844F
+#endif /* GL_SGIX_clipmap */
+
+#ifndef GL_SGIX_convolution_accuracy
+#define GL_SGIX_convolution_accuracy 1
+#define GL_CONVOLUTION_HINT_SGIX 0x8316
+#endif /* GL_SGIX_convolution_accuracy */
+
+#ifndef GL_SGIX_depth_pass_instrument
+#define GL_SGIX_depth_pass_instrument 1
+#endif /* GL_SGIX_depth_pass_instrument */
+
+#ifndef GL_SGIX_depth_texture
+#define GL_SGIX_depth_texture 1
+#define GL_DEPTH_COMPONENT16_SGIX 0x81A5
+#define GL_DEPTH_COMPONENT24_SGIX 0x81A6
+#define GL_DEPTH_COMPONENT32_SGIX 0x81A7
+#endif /* GL_SGIX_depth_texture */
+
+#ifndef GL_SGIX_flush_raster
+#define GL_SGIX_flush_raster 1
+typedef void (APIENTRYP PFNGLFLUSHRASTERSGIXPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glFlushRasterSGIX (void);
+#endif
+#endif /* GL_SGIX_flush_raster */
+
+#ifndef GL_SGIX_fog_offset
+#define GL_SGIX_fog_offset 1
+#define GL_FOG_OFFSET_SGIX 0x8198
+#define GL_FOG_OFFSET_VALUE_SGIX 0x8199
+#endif /* GL_SGIX_fog_offset */
+
+#ifndef GL_SGIX_fragment_lighting
+#define GL_SGIX_fragment_lighting 1
+#define GL_FRAGMENT_LIGHTING_SGIX 0x8400
+#define GL_FRAGMENT_COLOR_MATERIAL_SGIX 0x8401
+#define GL_FRAGMENT_COLOR_MATERIAL_FACE_SGIX 0x8402
+#define GL_FRAGMENT_COLOR_MATERIAL_PARAMETER_SGIX 0x8403
+#define GL_MAX_FRAGMENT_LIGHTS_SGIX 0x8404
+#define GL_MAX_ACTIVE_LIGHTS_SGIX 0x8405
+#define GL_CURRENT_RASTER_NORMAL_SGIX 0x8406
+#define GL_LIGHT_ENV_MODE_SGIX 0x8407
+#define GL_FRAGMENT_LIGHT_MODEL_LOCAL_VIEWER_SGIX 0x8408
+#define GL_FRAGMENT_LIGHT_MODEL_TWO_SIDE_SGIX 0x8409
+#define GL_FRAGMENT_LIGHT_MODEL_AMBIENT_SGIX 0x840A
+#define GL_FRAGMENT_LIGHT_MODEL_NORMAL_INTERPOLATION_SGIX 0x840B
+#define GL_FRAGMENT_LIGHT0_SGIX 0x840C
+#define GL_FRAGMENT_LIGHT1_SGIX 0x840D
+#define GL_FRAGMENT_LIGHT2_SGIX 0x840E
+#define GL_FRAGMENT_LIGHT3_SGIX 0x840F
+#define GL_FRAGMENT_LIGHT4_SGIX 0x8410
+#define GL_FRAGMENT_LIGHT5_SGIX 0x8411
+#define GL_FRAGMENT_LIGHT6_SGIX 0x8412
+#define GL_FRAGMENT_LIGHT7_SGIX 0x8413
+typedef void (APIENTRYP PFNGLFRAGMENTCOLORMATERIALSGIXPROC) (GLenum face, GLenum mode);
+typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFSGIXPROC) (GLenum light, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLFRAGMENTLIGHTISGIXPROC) (GLenum light, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFSGIXPROC) (GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELFVSGIXPROC) (GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELISGIXPROC) (GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLFRAGMENTLIGHTMODELIVSGIXPROC) (GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFSGIXPROC) (GLenum face, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLFRAGMENTMATERIALISGIXPROC) (GLenum face, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTFVSGIXPROC) (GLenum light, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETFRAGMENTLIGHTIVSGIXPROC) (GLenum light, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALFVSGIXPROC) (GLenum face, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETFRAGMENTMATERIALIVSGIXPROC) (GLenum face, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLLIGHTENVISGIXPROC) (GLenum pname, GLint param);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glFragmentColorMaterialSGIX (GLenum face, GLenum mode);
+GLAPI void APIENTRY glFragmentLightfSGIX (GLenum light, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glFragmentLightfvSGIX (GLenum light, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glFragmentLightiSGIX (GLenum light, GLenum pname, GLint param);
+GLAPI void APIENTRY glFragmentLightivSGIX (GLenum light, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glFragmentLightModelfSGIX (GLenum pname, GLfloat param);
+GLAPI void APIENTRY glFragmentLightModelfvSGIX (GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glFragmentLightModeliSGIX (GLenum pname, GLint param);
+GLAPI void APIENTRY glFragmentLightModelivSGIX (GLenum pname, const GLint *params);
+GLAPI void APIENTRY glFragmentMaterialfSGIX (GLenum face, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glFragmentMaterialfvSGIX (GLenum face, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glFragmentMaterialiSGIX (GLenum face, GLenum pname, GLint param);
+GLAPI void APIENTRY glFragmentMaterialivSGIX (GLenum face, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glGetFragmentLightfvSGIX (GLenum light, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetFragmentLightivSGIX (GLenum light, GLenum pname, GLint *params);
+GLAPI void APIENTRY glGetFragmentMaterialfvSGIX (GLenum face, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetFragmentMaterialivSGIX (GLenum face, GLenum pname, GLint *params);
+GLAPI void APIENTRY glLightEnviSGIX (GLenum pname, GLint param);
+#endif
+#endif /* GL_SGIX_fragment_lighting */
+
+#ifndef GL_SGIX_framezoom
+#define GL_SGIX_framezoom 1
+#define GL_FRAMEZOOM_SGIX 0x818B
+#define GL_FRAMEZOOM_FACTOR_SGIX 0x818C
+#define GL_MAX_FRAMEZOOM_FACTOR_SGIX 0x818D
+typedef void (APIENTRYP PFNGLFRAMEZOOMSGIXPROC) (GLint factor);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glFrameZoomSGIX (GLint factor);
+#endif
+#endif /* GL_SGIX_framezoom */
+
+#ifndef GL_SGIX_igloo_interface
+#define GL_SGIX_igloo_interface 1
+typedef void (APIENTRYP PFNGLIGLOOINTERFACESGIXPROC) (GLenum pname, const void *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glIglooInterfaceSGIX (GLenum pname, const void *params);
+#endif
+#endif /* GL_SGIX_igloo_interface */
+
+#ifndef GL_SGIX_instruments
+#define GL_SGIX_instruments 1
+#define GL_INSTRUMENT_BUFFER_POINTER_SGIX 0x8180
+#define GL_INSTRUMENT_MEASUREMENTS_SGIX 0x8181
+typedef GLint (APIENTRYP PFNGLGETINSTRUMENTSSGIXPROC) (void);
+typedef void (APIENTRYP PFNGLINSTRUMENTSBUFFERSGIXPROC) (GLsizei size, GLint *buffer);
+typedef GLint (APIENTRYP PFNGLPOLLINSTRUMENTSSGIXPROC) (GLint *marker_p);
+typedef void (APIENTRYP PFNGLREADINSTRUMENTSSGIXPROC) (GLint marker);
+typedef void (APIENTRYP PFNGLSTARTINSTRUMENTSSGIXPROC) (void);
+typedef void (APIENTRYP PFNGLSTOPINSTRUMENTSSGIXPROC) (GLint marker);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI GLint APIENTRY glGetInstrumentsSGIX (void);
+GLAPI void APIENTRY glInstrumentsBufferSGIX (GLsizei size, GLint *buffer);
+GLAPI GLint APIENTRY glPollInstrumentsSGIX (GLint *marker_p);
+GLAPI void APIENTRY glReadInstrumentsSGIX (GLint marker);
+GLAPI void APIENTRY glStartInstrumentsSGIX (void);
+GLAPI void APIENTRY glStopInstrumentsSGIX (GLint marker);
+#endif
+#endif /* GL_SGIX_instruments */
+
+#ifndef GL_SGIX_interlace
+#define GL_SGIX_interlace 1
+#define GL_INTERLACE_SGIX 0x8094
+#endif /* GL_SGIX_interlace */
+
+#ifndef GL_SGIX_ir_instrument1
+#define GL_SGIX_ir_instrument1 1
+#define GL_IR_INSTRUMENT1_SGIX 0x817F
+#endif /* GL_SGIX_ir_instrument1 */
+
+#ifndef GL_SGIX_list_priority
+#define GL_SGIX_list_priority 1
+#define GL_LIST_PRIORITY_SGIX 0x8182
+typedef void (APIENTRYP PFNGLGETLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, GLint *params);
+typedef void (APIENTRYP PFNGLLISTPARAMETERFSGIXPROC) (GLuint list, GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLLISTPARAMETERFVSGIXPROC) (GLuint list, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLLISTPARAMETERISGIXPROC) (GLuint list, GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLLISTPARAMETERIVSGIXPROC) (GLuint list, GLenum pname, const GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGetListParameterfvSGIX (GLuint list, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetListParameterivSGIX (GLuint list, GLenum pname, GLint *params);
+GLAPI void APIENTRY glListParameterfSGIX (GLuint list, GLenum pname, GLfloat param);
+GLAPI void APIENTRY glListParameterfvSGIX (GLuint list, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glListParameteriSGIX (GLuint list, GLenum pname, GLint param);
+GLAPI void APIENTRY glListParameterivSGIX (GLuint list, GLenum pname, const GLint *params);
+#endif
+#endif /* GL_SGIX_list_priority */
+
+#ifndef GL_SGIX_pixel_texture
+#define GL_SGIX_pixel_texture 1
+#define GL_PIXEL_TEX_GEN_SGIX 0x8139
+#define GL_PIXEL_TEX_GEN_MODE_SGIX 0x832B
+typedef void (APIENTRYP PFNGLPIXELTEXGENSGIXPROC) (GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glPixelTexGenSGIX (GLenum mode);
+#endif
+#endif /* GL_SGIX_pixel_texture */
+
+#ifndef GL_SGIX_pixel_tiles
+#define GL_SGIX_pixel_tiles 1
+#define GL_PIXEL_TILE_BEST_ALIGNMENT_SGIX 0x813E
+#define GL_PIXEL_TILE_CACHE_INCREMENT_SGIX 0x813F
+#define GL_PIXEL_TILE_WIDTH_SGIX 0x8140
+#define GL_PIXEL_TILE_HEIGHT_SGIX 0x8141
+#define GL_PIXEL_TILE_GRID_WIDTH_SGIX 0x8142
+#define GL_PIXEL_TILE_GRID_HEIGHT_SGIX 0x8143
+#define GL_PIXEL_TILE_GRID_DEPTH_SGIX 0x8144
+#define GL_PIXEL_TILE_CACHE_SIZE_SGIX 0x8145
+#endif /* GL_SGIX_pixel_tiles */
+
+#ifndef GL_SGIX_polynomial_ffd
+#define GL_SGIX_polynomial_ffd 1
+#define GL_TEXTURE_DEFORMATION_BIT_SGIX 0x00000001
+#define GL_GEOMETRY_DEFORMATION_BIT_SGIX 0x00000002
+#define GL_GEOMETRY_DEFORMATION_SGIX 0x8194
+#define GL_TEXTURE_DEFORMATION_SGIX 0x8195
+#define GL_DEFORMATIONS_MASK_SGIX 0x8196
+#define GL_MAX_DEFORMATION_ORDER_SGIX 0x8197
+typedef void (APIENTRYP PFNGLDEFORMATIONMAP3DSGIXPROC) (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble w1, GLdouble w2, GLint wstride, GLint worder, const GLdouble *points);
+typedef void (APIENTRYP PFNGLDEFORMATIONMAP3FSGIXPROC) (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat w1, GLfloat w2, GLint wstride, GLint worder, const GLfloat *points);
+typedef void (APIENTRYP PFNGLDEFORMSGIXPROC) (GLbitfield mask);
+typedef void (APIENTRYP PFNGLLOADIDENTITYDEFORMATIONMAPSGIXPROC) (GLbitfield mask);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDeformationMap3dSGIX (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, GLdouble w1, GLdouble w2, GLint wstride, GLint worder, const GLdouble *points);
+GLAPI void APIENTRY glDeformationMap3fSGIX (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, GLfloat w1, GLfloat w2, GLint wstride, GLint worder, const GLfloat *points);
+GLAPI void APIENTRY glDeformSGIX (GLbitfield mask);
+GLAPI void APIENTRY glLoadIdentityDeformationMapSGIX (GLbitfield mask);
+#endif
+#endif /* GL_SGIX_polynomial_ffd */
+
+#ifndef GL_SGIX_reference_plane
+#define GL_SGIX_reference_plane 1
+#define GL_REFERENCE_PLANE_SGIX 0x817D
+#define GL_REFERENCE_PLANE_EQUATION_SGIX 0x817E
+typedef void (APIENTRYP PFNGLREFERENCEPLANESGIXPROC) (const GLdouble *equation);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glReferencePlaneSGIX (const GLdouble *equation);
+#endif
+#endif /* GL_SGIX_reference_plane */
+
+#ifndef GL_SGIX_resample
+#define GL_SGIX_resample 1
+#define GL_PACK_RESAMPLE_SGIX 0x842C
+#define GL_UNPACK_RESAMPLE_SGIX 0x842D
+#define GL_RESAMPLE_REPLICATE_SGIX 0x842E
+#define GL_RESAMPLE_ZERO_FILL_SGIX 0x842F
+#define GL_RESAMPLE_DECIMATE_SGIX 0x8430
+#endif /* GL_SGIX_resample */
+
+#ifndef GL_SGIX_scalebias_hint
+#define GL_SGIX_scalebias_hint 1
+#define GL_SCALEBIAS_HINT_SGIX 0x8322
+#endif /* GL_SGIX_scalebias_hint */
+
+#ifndef GL_SGIX_shadow
+#define GL_SGIX_shadow 1
+#define GL_TEXTURE_COMPARE_SGIX 0x819A
+#define GL_TEXTURE_COMPARE_OPERATOR_SGIX 0x819B
+#define GL_TEXTURE_LEQUAL_R_SGIX 0x819C
+#define GL_TEXTURE_GEQUAL_R_SGIX 0x819D
+#endif /* GL_SGIX_shadow */
+
+#ifndef GL_SGIX_shadow_ambient
+#define GL_SGIX_shadow_ambient 1
+#define GL_SHADOW_AMBIENT_SGIX 0x80BF
+#endif /* GL_SGIX_shadow_ambient */
+
+#ifndef GL_SGIX_sprite
+#define GL_SGIX_sprite 1
+#define GL_SPRITE_SGIX 0x8148
+#define GL_SPRITE_MODE_SGIX 0x8149
+#define GL_SPRITE_AXIS_SGIX 0x814A
+#define GL_SPRITE_TRANSLATION_SGIX 0x814B
+#define GL_SPRITE_AXIAL_SGIX 0x814C
+#define GL_SPRITE_OBJECT_ALIGNED_SGIX 0x814D
+#define GL_SPRITE_EYE_ALIGNED_SGIX 0x814E
+typedef void (APIENTRYP PFNGLSPRITEPARAMETERFSGIXPROC) (GLenum pname, GLfloat param);
+typedef void (APIENTRYP PFNGLSPRITEPARAMETERFVSGIXPROC) (GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLSPRITEPARAMETERISGIXPROC) (GLenum pname, GLint param);
+typedef void (APIENTRYP PFNGLSPRITEPARAMETERIVSGIXPROC) (GLenum pname, const GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glSpriteParameterfSGIX (GLenum pname, GLfloat param);
+GLAPI void APIENTRY glSpriteParameterfvSGIX (GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glSpriteParameteriSGIX (GLenum pname, GLint param);
+GLAPI void APIENTRY glSpriteParameterivSGIX (GLenum pname, const GLint *params);
+#endif
+#endif /* GL_SGIX_sprite */
+
+#ifndef GL_SGIX_subsample
+#define GL_SGIX_subsample 1
+#define GL_PACK_SUBSAMPLE_RATE_SGIX 0x85A0
+#define GL_UNPACK_SUBSAMPLE_RATE_SGIX 0x85A1
+#define GL_PIXEL_SUBSAMPLE_4444_SGIX 0x85A2
+#define GL_PIXEL_SUBSAMPLE_2424_SGIX 0x85A3
+#define GL_PIXEL_SUBSAMPLE_4242_SGIX 0x85A4
+#endif /* GL_SGIX_subsample */
+
+#ifndef GL_SGIX_tag_sample_buffer
+#define GL_SGIX_tag_sample_buffer 1
+typedef void (APIENTRYP PFNGLTAGSAMPLEBUFFERSGIXPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glTagSampleBufferSGIX (void);
+#endif
+#endif /* GL_SGIX_tag_sample_buffer */
+
+#ifndef GL_SGIX_texture_add_env
+#define GL_SGIX_texture_add_env 1
+#define GL_TEXTURE_ENV_BIAS_SGIX 0x80BE
+#endif /* GL_SGIX_texture_add_env */
+
+#ifndef GL_SGIX_texture_coordinate_clamp
+#define GL_SGIX_texture_coordinate_clamp 1
+#define GL_TEXTURE_MAX_CLAMP_S_SGIX 0x8369
+#define GL_TEXTURE_MAX_CLAMP_T_SGIX 0x836A
+#define GL_TEXTURE_MAX_CLAMP_R_SGIX 0x836B
+#endif /* GL_SGIX_texture_coordinate_clamp */
+
+#ifndef GL_SGIX_texture_lod_bias
+#define GL_SGIX_texture_lod_bias 1
+#define GL_TEXTURE_LOD_BIAS_S_SGIX 0x818E
+#define GL_TEXTURE_LOD_BIAS_T_SGIX 0x818F
+#define GL_TEXTURE_LOD_BIAS_R_SGIX 0x8190
+#endif /* GL_SGIX_texture_lod_bias */
+
+#ifndef GL_SGIX_texture_multi_buffer
+#define GL_SGIX_texture_multi_buffer 1
+#define GL_TEXTURE_MULTI_BUFFER_HINT_SGIX 0x812E
+#endif /* GL_SGIX_texture_multi_buffer */
+
+#ifndef GL_SGIX_texture_scale_bias
+#define GL_SGIX_texture_scale_bias 1
+#define GL_POST_TEXTURE_FILTER_BIAS_SGIX 0x8179
+#define GL_POST_TEXTURE_FILTER_SCALE_SGIX 0x817A
+#define GL_POST_TEXTURE_FILTER_BIAS_RANGE_SGIX 0x817B
+#define GL_POST_TEXTURE_FILTER_SCALE_RANGE_SGIX 0x817C
+#endif /* GL_SGIX_texture_scale_bias */
+
+#ifndef GL_SGIX_vertex_preclip
+#define GL_SGIX_vertex_preclip 1
+#define GL_VERTEX_PRECLIP_SGIX 0x83EE
+#define GL_VERTEX_PRECLIP_HINT_SGIX 0x83EF
+#endif /* GL_SGIX_vertex_preclip */
+
+#ifndef GL_SGIX_ycrcb
+#define GL_SGIX_ycrcb 1
+#define GL_YCRCB_422_SGIX 0x81BB
+#define GL_YCRCB_444_SGIX 0x81BC
+#endif /* GL_SGIX_ycrcb */
+
+#ifndef GL_SGIX_ycrcb_subsample
+#define GL_SGIX_ycrcb_subsample 1
+#endif /* GL_SGIX_ycrcb_subsample */
+
+#ifndef GL_SGIX_ycrcba
+#define GL_SGIX_ycrcba 1
+#define GL_YCRCB_SGIX 0x8318
+#define GL_YCRCBA_SGIX 0x8319
+#endif /* GL_SGIX_ycrcba */
+
+#ifndef GL_SGI_color_matrix
+#define GL_SGI_color_matrix 1
+#define GL_COLOR_MATRIX_SGI 0x80B1
+#define GL_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B2
+#define GL_MAX_COLOR_MATRIX_STACK_DEPTH_SGI 0x80B3
+#define GL_POST_COLOR_MATRIX_RED_SCALE_SGI 0x80B4
+#define GL_POST_COLOR_MATRIX_GREEN_SCALE_SGI 0x80B5
+#define GL_POST_COLOR_MATRIX_BLUE_SCALE_SGI 0x80B6
+#define GL_POST_COLOR_MATRIX_ALPHA_SCALE_SGI 0x80B7
+#define GL_POST_COLOR_MATRIX_RED_BIAS_SGI 0x80B8
+#define GL_POST_COLOR_MATRIX_GREEN_BIAS_SGI 0x80B9
+#define GL_POST_COLOR_MATRIX_BLUE_BIAS_SGI 0x80BA
+#define GL_POST_COLOR_MATRIX_ALPHA_BIAS_SGI 0x80BB
+#endif /* GL_SGI_color_matrix */
+
+#ifndef GL_SGI_color_table
+#define GL_SGI_color_table 1
+#define GL_COLOR_TABLE_SGI 0x80D0
+#define GL_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D1
+#define GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D2
+#define GL_PROXY_COLOR_TABLE_SGI 0x80D3
+#define GL_PROXY_POST_CONVOLUTION_COLOR_TABLE_SGI 0x80D4
+#define GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE_SGI 0x80D5
+#define GL_COLOR_TABLE_SCALE_SGI 0x80D6
+#define GL_COLOR_TABLE_BIAS_SGI 0x80D7
+#define GL_COLOR_TABLE_FORMAT_SGI 0x80D8
+#define GL_COLOR_TABLE_WIDTH_SGI 0x80D9
+#define GL_COLOR_TABLE_RED_SIZE_SGI 0x80DA
+#define GL_COLOR_TABLE_GREEN_SIZE_SGI 0x80DB
+#define GL_COLOR_TABLE_BLUE_SIZE_SGI 0x80DC
+#define GL_COLOR_TABLE_ALPHA_SIZE_SGI 0x80DD
+#define GL_COLOR_TABLE_LUMINANCE_SIZE_SGI 0x80DE
+#define GL_COLOR_TABLE_INTENSITY_SIZE_SGI 0x80DF
+typedef void (APIENTRYP PFNGLCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *table);
+typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, const GLfloat *params);
+typedef void (APIENTRYP PFNGLCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (APIENTRYP PFNGLCOPYCOLORTABLESGIPROC) (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width);
+typedef void (APIENTRYP PFNGLGETCOLORTABLESGIPROC) (GLenum target, GLenum format, GLenum type, void *table);
+typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERFVSGIPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (APIENTRYP PFNGLGETCOLORTABLEPARAMETERIVSGIPROC) (GLenum target, GLenum pname, GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glColorTableSGI (GLenum target, GLenum internalformat, GLsizei width, GLenum format, GLenum type, const void *table);
+GLAPI void APIENTRY glColorTableParameterfvSGI (GLenum target, GLenum pname, const GLfloat *params);
+GLAPI void APIENTRY glColorTableParameterivSGI (GLenum target, GLenum pname, const GLint *params);
+GLAPI void APIENTRY glCopyColorTableSGI (GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width);
+GLAPI void APIENTRY glGetColorTableSGI (GLenum target, GLenum format, GLenum type, void *table);
+GLAPI void APIENTRY glGetColorTableParameterfvSGI (GLenum target, GLenum pname, GLfloat *params);
+GLAPI void APIENTRY glGetColorTableParameterivSGI (GLenum target, GLenum pname, GLint *params);
+#endif
+#endif /* GL_SGI_color_table */
+
+#ifndef GL_SGI_texture_color_table
+#define GL_SGI_texture_color_table 1
+#define GL_TEXTURE_COLOR_TABLE_SGI 0x80BC
+#define GL_PROXY_TEXTURE_COLOR_TABLE_SGI 0x80BD
+#endif /* GL_SGI_texture_color_table */
+
+#ifndef GL_SUNX_constant_data
+#define GL_SUNX_constant_data 1
+#define GL_UNPACK_CONSTANT_DATA_SUNX 0x81D5
+#define GL_TEXTURE_CONSTANT_DATA_SUNX 0x81D6
+typedef void (APIENTRYP PFNGLFINISHTEXTURESUNXPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glFinishTextureSUNX (void);
+#endif
+#endif /* GL_SUNX_constant_data */
+
+#ifndef GL_SUN_convolution_border_modes
+#define GL_SUN_convolution_border_modes 1
+#define GL_WRAP_BORDER_SUN 0x81D4
+#endif /* GL_SUN_convolution_border_modes */
+
+#ifndef GL_SUN_global_alpha
+#define GL_SUN_global_alpha 1
+#define GL_GLOBAL_ALPHA_SUN 0x81D9
+#define GL_GLOBAL_ALPHA_FACTOR_SUN 0x81DA
+typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORBSUNPROC) (GLbyte factor);
+typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORSSUNPROC) (GLshort factor);
+typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORISUNPROC) (GLint factor);
+typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORFSUNPROC) (GLfloat factor);
+typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORDSUNPROC) (GLdouble factor);
+typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUBSUNPROC) (GLubyte factor);
+typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUSSUNPROC) (GLushort factor);
+typedef void (APIENTRYP PFNGLGLOBALALPHAFACTORUISUNPROC) (GLuint factor);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glGlobalAlphaFactorbSUN (GLbyte factor);
+GLAPI void APIENTRY glGlobalAlphaFactorsSUN (GLshort factor);
+GLAPI void APIENTRY glGlobalAlphaFactoriSUN (GLint factor);
+GLAPI void APIENTRY glGlobalAlphaFactorfSUN (GLfloat factor);
+GLAPI void APIENTRY glGlobalAlphaFactordSUN (GLdouble factor);
+GLAPI void APIENTRY glGlobalAlphaFactorubSUN (GLubyte factor);
+GLAPI void APIENTRY glGlobalAlphaFactorusSUN (GLushort factor);
+GLAPI void APIENTRY glGlobalAlphaFactoruiSUN (GLuint factor);
+#endif
+#endif /* GL_SUN_global_alpha */
+
+#ifndef GL_SUN_mesh_array
+#define GL_SUN_mesh_array 1
+#define GL_QUAD_MESH_SUN 0x8614
+#define GL_TRIANGLE_MESH_SUN 0x8615
+typedef void (APIENTRYP PFNGLDRAWMESHARRAYSSUNPROC) (GLenum mode, GLint first, GLsizei count, GLsizei width);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glDrawMeshArraysSUN (GLenum mode, GLint first, GLsizei count, GLsizei width);
+#endif
+#endif /* GL_SUN_mesh_array */
+
+#ifndef GL_SUN_slice_accum
+#define GL_SUN_slice_accum 1
+#define GL_SLICE_ACCUM_SUN 0x85CC
+#endif /* GL_SUN_slice_accum */
+
+#ifndef GL_SUN_triangle_list
+#define GL_SUN_triangle_list 1
+#define GL_RESTART_SUN 0x0001
+#define GL_REPLACE_MIDDLE_SUN 0x0002
+#define GL_REPLACE_OLDEST_SUN 0x0003
+#define GL_TRIANGLE_LIST_SUN 0x81D7
+#define GL_REPLACEMENT_CODE_SUN 0x81D8
+#define GL_REPLACEMENT_CODE_ARRAY_SUN 0x85C0
+#define GL_REPLACEMENT_CODE_ARRAY_TYPE_SUN 0x85C1
+#define GL_REPLACEMENT_CODE_ARRAY_STRIDE_SUN 0x85C2
+#define GL_REPLACEMENT_CODE_ARRAY_POINTER_SUN 0x85C3
+#define GL_R1UI_V3F_SUN 0x85C4
+#define GL_R1UI_C4UB_V3F_SUN 0x85C5
+#define GL_R1UI_C3F_V3F_SUN 0x85C6
+#define GL_R1UI_N3F_V3F_SUN 0x85C7
+#define GL_R1UI_C4F_N3F_V3F_SUN 0x85C8
+#define GL_R1UI_T2F_V3F_SUN 0x85C9
+#define GL_R1UI_T2F_N3F_V3F_SUN 0x85CA
+#define GL_R1UI_T2F_C4F_N3F_V3F_SUN 0x85CB
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUISUNPROC) (GLuint code);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSSUNPROC) (GLushort code);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBSUNPROC) (GLubyte code);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVSUNPROC) (const GLuint *code);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUSVSUNPROC) (const GLushort *code);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUBVSUNPROC) (const GLubyte *code);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEPOINTERSUNPROC) (GLenum type, GLsizei stride, const void **pointer);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glReplacementCodeuiSUN (GLuint code);
+GLAPI void APIENTRY glReplacementCodeusSUN (GLushort code);
+GLAPI void APIENTRY glReplacementCodeubSUN (GLubyte code);
+GLAPI void APIENTRY glReplacementCodeuivSUN (const GLuint *code);
+GLAPI void APIENTRY glReplacementCodeusvSUN (const GLushort *code);
+GLAPI void APIENTRY glReplacementCodeubvSUN (const GLubyte *code);
+GLAPI void APIENTRY glReplacementCodePointerSUN (GLenum type, GLsizei stride, const void **pointer);
+#endif
+#endif /* GL_SUN_triangle_list */
+
+#ifndef GL_SUN_vertex
+#define GL_SUN_vertex 1
+typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y);
+typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX2FVSUNPROC) (const GLubyte *c, const GLfloat *v);
+typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FSUNPROC) (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLCOLOR4UBVERTEX3FVSUNPROC) (const GLubyte *c, const GLfloat *v);
+typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *v);
+typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FSUNPROC) (GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *n, const GLfloat *v);
+typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *c, const GLfloat *n, const GLfloat *v);
+typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLTEXCOORD2FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *v);
+typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLTEXCOORD4FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *v);
+typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4UBVERTEX3FVSUNPROC) (const GLfloat *tc, const GLubyte *c, const GLfloat *v);
+typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *v);
+typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLTEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *n, const GLfloat *v);
+typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLTEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v);
+typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FSUNPROC) (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (APIENTRYP PFNGLTEXCOORD4FCOLOR4FNORMAL3FVERTEX4FVSUNPROC) (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FSUNPROC) (GLuint rc, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUIVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *v);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FSUNPROC) (GLuint rc, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4UBVERTEX3FVSUNPROC) (const GLuint *rc, const GLubyte *c, const GLfloat *v);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *v);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUINORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *n, const GLfloat *v);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUICOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *c, const GLfloat *n, const GLfloat *v);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *v);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *n, const GLfloat *v);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FSUNPROC) (GLuint rc, GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+typedef void (APIENTRYP PFNGLREPLACEMENTCODEUITEXCOORD2FCOLOR4FNORMAL3FVERTEX3FVSUNPROC) (const GLuint *rc, const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v);
+#ifdef GL_GLEXT_PROTOTYPES
+GLAPI void APIENTRY glColor4ubVertex2fSUN (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y);
+GLAPI void APIENTRY glColor4ubVertex2fvSUN (const GLubyte *c, const GLfloat *v);
+GLAPI void APIENTRY glColor4ubVertex3fSUN (GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glColor4ubVertex3fvSUN (const GLubyte *c, const GLfloat *v);
+GLAPI void APIENTRY glColor3fVertex3fSUN (GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glColor3fVertex3fvSUN (const GLfloat *c, const GLfloat *v);
+GLAPI void APIENTRY glNormal3fVertex3fSUN (GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glNormal3fVertex3fvSUN (const GLfloat *n, const GLfloat *v);
+GLAPI void APIENTRY glColor4fNormal3fVertex3fSUN (GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glColor4fNormal3fVertex3fvSUN (const GLfloat *c, const GLfloat *n, const GLfloat *v);
+GLAPI void APIENTRY glTexCoord2fVertex3fSUN (GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glTexCoord2fVertex3fvSUN (const GLfloat *tc, const GLfloat *v);
+GLAPI void APIENTRY glTexCoord4fVertex4fSUN (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glTexCoord4fVertex4fvSUN (const GLfloat *tc, const GLfloat *v);
+GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fSUN (GLfloat s, GLfloat t, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glTexCoord2fColor4ubVertex3fvSUN (const GLfloat *tc, const GLubyte *c, const GLfloat *v);
+GLAPI void APIENTRY glTexCoord2fColor3fVertex3fSUN (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glTexCoord2fColor3fVertex3fvSUN (const GLfloat *tc, const GLfloat *c, const GLfloat *v);
+GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fSUN (GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glTexCoord2fNormal3fVertex3fvSUN (const GLfloat *tc, const GLfloat *n, const GLfloat *v);
+GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fSUN (GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glTexCoord2fColor4fNormal3fVertex3fvSUN (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v);
+GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fSUN (GLfloat s, GLfloat t, GLfloat p, GLfloat q, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GLAPI void APIENTRY glTexCoord4fColor4fNormal3fVertex4fvSUN (const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v);
+GLAPI void APIENTRY glReplacementCodeuiVertex3fSUN (GLuint rc, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glReplacementCodeuiVertex3fvSUN (const GLuint *rc, const GLfloat *v);
+GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fSUN (GLuint rc, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glReplacementCodeuiColor4ubVertex3fvSUN (const GLuint *rc, const GLubyte *c, const GLfloat *v);
+GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fSUN (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glReplacementCodeuiColor3fVertex3fvSUN (const GLuint *rc, const GLfloat *c, const GLfloat *v);
+GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fSUN (GLuint rc, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glReplacementCodeuiNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *n, const GLfloat *v);
+GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fSUN (GLuint rc, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glReplacementCodeuiColor4fNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *c, const GLfloat *n, const GLfloat *v);
+GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fSUN (GLuint rc, GLfloat s, GLfloat t, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glReplacementCodeuiTexCoord2fVertex3fvSUN (const GLuint *rc, const GLfloat *tc, const GLfloat *v);
+GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fSUN (GLuint rc, GLfloat s, GLfloat t, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glReplacementCodeuiTexCoord2fNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *tc, const GLfloat *n, const GLfloat *v);
+GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN (GLuint rc, GLfloat s, GLfloat t, GLfloat r, GLfloat g, GLfloat b, GLfloat a, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat x, GLfloat y, GLfloat z);
+GLAPI void APIENTRY glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN (const GLuint *rc, const GLfloat *tc, const GLfloat *c, const GLfloat *n, const GLfloat *v);
+#endif
+#endif /* GL_SUN_vertex */
+
+#ifndef GL_WIN_phong_shading
+#define GL_WIN_phong_shading 1
+#define GL_PHONG_WIN 0x80EA
+#define GL_PHONG_HINT_WIN 0x80EB
+#endif /* GL_WIN_phong_shading */
+
+#ifndef GL_WIN_specular_fog
+#define GL_WIN_specular_fog 1
+#define GL_FOG_SPECULAR_TEXTURE_WIN 0x80EC
+#endif /* GL_WIN_specular_fog */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/3rdparty/SDL2/include/SDL_opengles.h b/src/3rdparty/SDL2/include/SDL_opengles.h
new file mode 100644
index 0000000..18dd984
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_opengles.h
@@ -0,0 +1,39 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_opengles.h
+ *
+ * This is a simple file to encapsulate the OpenGL ES 1.X API headers.
+ */
+#include "SDL_config.h"
+
+#ifdef __IPHONEOS__
+#include <OpenGLES/ES1/gl.h>
+#include <OpenGLES/ES1/glext.h>
+#else
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#endif
+
+#ifndef APIENTRY
+#define APIENTRY
+#endif
diff --git a/src/3rdparty/SDL2/include/SDL_opengles2.h b/src/3rdparty/SDL2/include/SDL_opengles2.h
new file mode 100644
index 0000000..6ccecf2
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_opengles2.h
@@ -0,0 +1,52 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_opengles2.h
+ *
+ * This is a simple file to encapsulate the OpenGL ES 2.0 API headers.
+ */
+#include "SDL_config.h"
+
+#ifndef _MSC_VER
+
+#ifdef __IPHONEOS__
+#include <OpenGLES/ES2/gl.h>
+#include <OpenGLES/ES2/glext.h>
+#else
+#include <GLES2/gl2platform.h>
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#endif
+
+#else /* _MSC_VER */
+
+/* OpenGL ES2 headers for Visual Studio */
+#include "SDL_opengles2_khrplatform.h"
+#include "SDL_opengles2_gl2platform.h"
+#include "SDL_opengles2_gl2.h"
+#include "SDL_opengles2_gl2ext.h"
+
+#endif /* _MSC_VER */
+
+#ifndef APIENTRY
+#define APIENTRY GL_APIENTRY
+#endif
diff --git a/src/3rdparty/SDL2/include/SDL_opengles2_gl2.h b/src/3rdparty/SDL2/include/SDL_opengles2_gl2.h
new file mode 100644
index 0000000..c62fb0a
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_opengles2_gl2.h
@@ -0,0 +1,621 @@
+#ifndef __gl2_h_
+#define __gl2_h_
+
+/* $Revision: 20555 $ on $Date:: 2013-02-12 14:32:47 -0800 #$ */
+
+/*#include <GLES2/gl2platform.h>*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This document is licensed under the SGI Free Software B License Version
+ * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ .
+ */
+
+/*-------------------------------------------------------------------------
+ * Data type definitions
+ *-----------------------------------------------------------------------*/
+
+typedef void GLvoid;
+typedef char GLchar;
+typedef unsigned int GLenum;
+typedef unsigned char GLboolean;
+typedef unsigned int GLbitfield;
+typedef khronos_int8_t GLbyte;
+typedef short GLshort;
+typedef int GLint;
+typedef int GLsizei;
+typedef khronos_uint8_t GLubyte;
+typedef unsigned short GLushort;
+typedef unsigned int GLuint;
+typedef khronos_float_t GLfloat;
+typedef khronos_float_t GLclampf;
+typedef khronos_int32_t GLfixed;
+
+/* GL types for handling large vertex buffer objects */
+typedef khronos_intptr_t GLintptr;
+typedef khronos_ssize_t GLsizeiptr;
+
+/* OpenGL ES core versions */
+#define GL_ES_VERSION_2_0 1
+
+/* ClearBufferMask */
+#define GL_DEPTH_BUFFER_BIT 0x00000100
+#define GL_STENCIL_BUFFER_BIT 0x00000400
+#define GL_COLOR_BUFFER_BIT 0x00004000
+
+/* Boolean */
+#define GL_FALSE 0
+#define GL_TRUE 1
+
+/* BeginMode */
+#define GL_POINTS 0x0000
+#define GL_LINES 0x0001
+#define GL_LINE_LOOP 0x0002
+#define GL_LINE_STRIP 0x0003
+#define GL_TRIANGLES 0x0004
+#define GL_TRIANGLE_STRIP 0x0005
+#define GL_TRIANGLE_FAN 0x0006
+
+/* AlphaFunction (not supported in ES20) */
+/* GL_NEVER */
+/* GL_LESS */
+/* GL_EQUAL */
+/* GL_LEQUAL */
+/* GL_GREATER */
+/* GL_NOTEQUAL */
+/* GL_GEQUAL */
+/* GL_ALWAYS */
+
+/* BlendingFactorDest */
+#define GL_ZERO 0
+#define GL_ONE 1
+#define GL_SRC_COLOR 0x0300
+#define GL_ONE_MINUS_SRC_COLOR 0x0301
+#define GL_SRC_ALPHA 0x0302
+#define GL_ONE_MINUS_SRC_ALPHA 0x0303
+#define GL_DST_ALPHA 0x0304
+#define GL_ONE_MINUS_DST_ALPHA 0x0305
+
+/* BlendingFactorSrc */
+/* GL_ZERO */
+/* GL_ONE */
+#define GL_DST_COLOR 0x0306
+#define GL_ONE_MINUS_DST_COLOR 0x0307
+#define GL_SRC_ALPHA_SATURATE 0x0308
+/* GL_SRC_ALPHA */
+/* GL_ONE_MINUS_SRC_ALPHA */
+/* GL_DST_ALPHA */
+/* GL_ONE_MINUS_DST_ALPHA */
+
+/* BlendEquationSeparate */
+#define GL_FUNC_ADD 0x8006
+#define GL_BLEND_EQUATION 0x8009
+#define GL_BLEND_EQUATION_RGB 0x8009 /* same as BLEND_EQUATION */
+#define GL_BLEND_EQUATION_ALPHA 0x883D
+
+/* BlendSubtract */
+#define GL_FUNC_SUBTRACT 0x800A
+#define GL_FUNC_REVERSE_SUBTRACT 0x800B
+
+/* Separate Blend Functions */
+#define GL_BLEND_DST_RGB 0x80C8
+#define GL_BLEND_SRC_RGB 0x80C9
+#define GL_BLEND_DST_ALPHA 0x80CA
+#define GL_BLEND_SRC_ALPHA 0x80CB
+#define GL_CONSTANT_COLOR 0x8001
+#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002
+#define GL_CONSTANT_ALPHA 0x8003
+#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004
+#define GL_BLEND_COLOR 0x8005
+
+/* Buffer Objects */
+#define GL_ARRAY_BUFFER 0x8892
+#define GL_ELEMENT_ARRAY_BUFFER 0x8893
+#define GL_ARRAY_BUFFER_BINDING 0x8894
+#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895
+
+#define GL_STREAM_DRAW 0x88E0
+#define GL_STATIC_DRAW 0x88E4
+#define GL_DYNAMIC_DRAW 0x88E8
+
+#define GL_BUFFER_SIZE 0x8764
+#define GL_BUFFER_USAGE 0x8765
+
+#define GL_CURRENT_VERTEX_ATTRIB 0x8626
+
+/* CullFaceMode */
+#define GL_FRONT 0x0404
+#define GL_BACK 0x0405
+#define GL_FRONT_AND_BACK 0x0408
+
+/* DepthFunction */
+/* GL_NEVER */
+/* GL_LESS */
+/* GL_EQUAL */
+/* GL_LEQUAL */
+/* GL_GREATER */
+/* GL_NOTEQUAL */
+/* GL_GEQUAL */
+/* GL_ALWAYS */
+
+/* EnableCap */
+#define GL_TEXTURE_2D 0x0DE1
+#define GL_CULL_FACE 0x0B44
+#define GL_BLEND 0x0BE2
+#define GL_DITHER 0x0BD0
+#define GL_STENCIL_TEST 0x0B90
+#define GL_DEPTH_TEST 0x0B71
+#define GL_SCISSOR_TEST 0x0C11
+#define GL_POLYGON_OFFSET_FILL 0x8037
+#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E
+#define GL_SAMPLE_COVERAGE 0x80A0
+
+/* ErrorCode */
+#define GL_NO_ERROR 0
+#define GL_INVALID_ENUM 0x0500
+#define GL_INVALID_VALUE 0x0501
+#define GL_INVALID_OPERATION 0x0502
+#define GL_OUT_OF_MEMORY 0x0505
+
+/* FrontFaceDirection */
+#define GL_CW 0x0900
+#define GL_CCW 0x0901
+
+/* GetPName */
+#define GL_LINE_WIDTH 0x0B21
+#define GL_ALIASED_POINT_SIZE_RANGE 0x846D
+#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E
+#define GL_CULL_FACE_MODE 0x0B45
+#define GL_FRONT_FACE 0x0B46
+#define GL_DEPTH_RANGE 0x0B70
+#define GL_DEPTH_WRITEMASK 0x0B72
+#define GL_DEPTH_CLEAR_VALUE 0x0B73
+#define GL_DEPTH_FUNC 0x0B74
+#define GL_STENCIL_CLEAR_VALUE 0x0B91
+#define GL_STENCIL_FUNC 0x0B92
+#define GL_STENCIL_FAIL 0x0B94
+#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95
+#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96
+#define GL_STENCIL_REF 0x0B97
+#define GL_STENCIL_VALUE_MASK 0x0B93
+#define GL_STENCIL_WRITEMASK 0x0B98
+#define GL_STENCIL_BACK_FUNC 0x8800
+#define GL_STENCIL_BACK_FAIL 0x8801
+#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802
+#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803
+#define GL_STENCIL_BACK_REF 0x8CA3
+#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4
+#define GL_STENCIL_BACK_WRITEMASK 0x8CA5
+#define GL_VIEWPORT 0x0BA2
+#define GL_SCISSOR_BOX 0x0C10
+/* GL_SCISSOR_TEST */
+#define GL_COLOR_CLEAR_VALUE 0x0C22
+#define GL_COLOR_WRITEMASK 0x0C23
+#define GL_UNPACK_ALIGNMENT 0x0CF5
+#define GL_PACK_ALIGNMENT 0x0D05
+#define GL_MAX_TEXTURE_SIZE 0x0D33
+#define GL_MAX_VIEWPORT_DIMS 0x0D3A
+#define GL_SUBPIXEL_BITS 0x0D50
+#define GL_RED_BITS 0x0D52
+#define GL_GREEN_BITS 0x0D53
+#define GL_BLUE_BITS 0x0D54
+#define GL_ALPHA_BITS 0x0D55
+#define GL_DEPTH_BITS 0x0D56
+#define GL_STENCIL_BITS 0x0D57
+#define GL_POLYGON_OFFSET_UNITS 0x2A00
+/* GL_POLYGON_OFFSET_FILL */
+#define GL_POLYGON_OFFSET_FACTOR 0x8038
+#define GL_TEXTURE_BINDING_2D 0x8069
+#define GL_SAMPLE_BUFFERS 0x80A8
+#define GL_SAMPLES 0x80A9
+#define GL_SAMPLE_COVERAGE_VALUE 0x80AA
+#define GL_SAMPLE_COVERAGE_INVERT 0x80AB
+
+/* GetTextureParameter */
+/* GL_TEXTURE_MAG_FILTER */
+/* GL_TEXTURE_MIN_FILTER */
+/* GL_TEXTURE_WRAP_S */
+/* GL_TEXTURE_WRAP_T */
+
+#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2
+#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3
+
+/* HintMode */
+#define GL_DONT_CARE 0x1100
+#define GL_FASTEST 0x1101
+#define GL_NICEST 0x1102
+
+/* HintTarget */
+#define GL_GENERATE_MIPMAP_HINT 0x8192
+
+/* DataType */
+#define GL_BYTE 0x1400
+#define GL_UNSIGNED_BYTE 0x1401
+#define GL_SHORT 0x1402
+#define GL_UNSIGNED_SHORT 0x1403
+#define GL_INT 0x1404
+#define GL_UNSIGNED_INT 0x1405
+#define GL_FLOAT 0x1406
+#define GL_FIXED 0x140C
+
+/* PixelFormat */
+#define GL_DEPTH_COMPONENT 0x1902
+#define GL_ALPHA 0x1906
+#define GL_RGB 0x1907
+#define GL_RGBA 0x1908
+#define GL_LUMINANCE 0x1909
+#define GL_LUMINANCE_ALPHA 0x190A
+
+/* PixelType */
+/* GL_UNSIGNED_BYTE */
+#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
+#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
+#define GL_UNSIGNED_SHORT_5_6_5 0x8363
+
+/* Shaders */
+#define GL_FRAGMENT_SHADER 0x8B30
+#define GL_VERTEX_SHADER 0x8B31
+#define GL_MAX_VERTEX_ATTRIBS 0x8869
+#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB
+#define GL_MAX_VARYING_VECTORS 0x8DFC
+#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D
+#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C
+#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872
+#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD
+#define GL_SHADER_TYPE 0x8B4F
+#define GL_DELETE_STATUS 0x8B80
+#define GL_LINK_STATUS 0x8B82
+#define GL_VALIDATE_STATUS 0x8B83
+#define GL_ATTACHED_SHADERS 0x8B85
+#define GL_ACTIVE_UNIFORMS 0x8B86
+#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87
+#define GL_ACTIVE_ATTRIBUTES 0x8B89
+#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A
+#define GL_SHADING_LANGUAGE_VERSION 0x8B8C
+#define GL_CURRENT_PROGRAM 0x8B8D
+
+/* StencilFunction */
+#define GL_NEVER 0x0200
+#define GL_LESS 0x0201
+#define GL_EQUAL 0x0202
+#define GL_LEQUAL 0x0203
+#define GL_GREATER 0x0204
+#define GL_NOTEQUAL 0x0205
+#define GL_GEQUAL 0x0206
+#define GL_ALWAYS 0x0207
+
+/* StencilOp */
+/* GL_ZERO */
+#define GL_KEEP 0x1E00
+#define GL_REPLACE 0x1E01
+#define GL_INCR 0x1E02
+#define GL_DECR 0x1E03
+#define GL_INVERT 0x150A
+#define GL_INCR_WRAP 0x8507
+#define GL_DECR_WRAP 0x8508
+
+/* StringName */
+#define GL_VENDOR 0x1F00
+#define GL_RENDERER 0x1F01
+#define GL_VERSION 0x1F02
+#define GL_EXTENSIONS 0x1F03
+
+/* TextureMagFilter */
+#define GL_NEAREST 0x2600
+#define GL_LINEAR 0x2601
+
+/* TextureMinFilter */
+/* GL_NEAREST */
+/* GL_LINEAR */
+#define GL_NEAREST_MIPMAP_NEAREST 0x2700
+#define GL_LINEAR_MIPMAP_NEAREST 0x2701
+#define GL_NEAREST_MIPMAP_LINEAR 0x2702
+#define GL_LINEAR_MIPMAP_LINEAR 0x2703
+
+/* TextureParameterName */
+#define GL_TEXTURE_MAG_FILTER 0x2800
+#define GL_TEXTURE_MIN_FILTER 0x2801
+#define GL_TEXTURE_WRAP_S 0x2802
+#define GL_TEXTURE_WRAP_T 0x2803
+
+/* TextureTarget */
+/* GL_TEXTURE_2D */
+#define GL_TEXTURE 0x1702
+
+#define GL_TEXTURE_CUBE_MAP 0x8513
+#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
+#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C
+
+/* TextureUnit */
+#define GL_TEXTURE0 0x84C0
+#define GL_TEXTURE1 0x84C1
+#define GL_TEXTURE2 0x84C2
+#define GL_TEXTURE3 0x84C3
+#define GL_TEXTURE4 0x84C4
+#define GL_TEXTURE5 0x84C5
+#define GL_TEXTURE6 0x84C6
+#define GL_TEXTURE7 0x84C7
+#define GL_TEXTURE8 0x84C8
+#define GL_TEXTURE9 0x84C9
+#define GL_TEXTURE10 0x84CA
+#define GL_TEXTURE11 0x84CB
+#define GL_TEXTURE12 0x84CC
+#define GL_TEXTURE13 0x84CD
+#define GL_TEXTURE14 0x84CE
+#define GL_TEXTURE15 0x84CF
+#define GL_TEXTURE16 0x84D0
+#define GL_TEXTURE17 0x84D1
+#define GL_TEXTURE18 0x84D2
+#define GL_TEXTURE19 0x84D3
+#define GL_TEXTURE20 0x84D4
+#define GL_TEXTURE21 0x84D5
+#define GL_TEXTURE22 0x84D6
+#define GL_TEXTURE23 0x84D7
+#define GL_TEXTURE24 0x84D8
+#define GL_TEXTURE25 0x84D9
+#define GL_TEXTURE26 0x84DA
+#define GL_TEXTURE27 0x84DB
+#define GL_TEXTURE28 0x84DC
+#define GL_TEXTURE29 0x84DD
+#define GL_TEXTURE30 0x84DE
+#define GL_TEXTURE31 0x84DF
+#define GL_ACTIVE_TEXTURE 0x84E0
+
+/* TextureWrapMode */
+#define GL_REPEAT 0x2901
+#define GL_CLAMP_TO_EDGE 0x812F
+#define GL_MIRRORED_REPEAT 0x8370
+
+/* Uniform Types */
+#define GL_FLOAT_VEC2 0x8B50
+#define GL_FLOAT_VEC3 0x8B51
+#define GL_FLOAT_VEC4 0x8B52
+#define GL_INT_VEC2 0x8B53
+#define GL_INT_VEC3 0x8B54
+#define GL_INT_VEC4 0x8B55
+#define GL_BOOL 0x8B56
+#define GL_BOOL_VEC2 0x8B57
+#define GL_BOOL_VEC3 0x8B58
+#define GL_BOOL_VEC4 0x8B59
+#define GL_FLOAT_MAT2 0x8B5A
+#define GL_FLOAT_MAT3 0x8B5B
+#define GL_FLOAT_MAT4 0x8B5C
+#define GL_SAMPLER_2D 0x8B5E
+#define GL_SAMPLER_CUBE 0x8B60
+
+/* Vertex Arrays */
+#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
+#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
+#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624
+#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625
+#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A
+#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645
+#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F
+
+/* Read Format */
+#define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A
+#define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B
+
+/* Shader Source */
+#define GL_COMPILE_STATUS 0x8B81
+#define GL_INFO_LOG_LENGTH 0x8B84
+#define GL_SHADER_SOURCE_LENGTH 0x8B88
+#define GL_SHADER_COMPILER 0x8DFA
+
+/* Shader Binary */
+#define GL_SHADER_BINARY_FORMATS 0x8DF8
+#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9
+
+/* Shader Precision-Specified Types */
+#define GL_LOW_FLOAT 0x8DF0
+#define GL_MEDIUM_FLOAT 0x8DF1
+#define GL_HIGH_FLOAT 0x8DF2
+#define GL_LOW_INT 0x8DF3
+#define GL_MEDIUM_INT 0x8DF4
+#define GL_HIGH_INT 0x8DF5
+
+/* Framebuffer Object. */
+#define GL_FRAMEBUFFER 0x8D40
+#define GL_RENDERBUFFER 0x8D41
+
+#define GL_RGBA4 0x8056
+#define GL_RGB5_A1 0x8057
+#define GL_RGB565 0x8D62
+#define GL_DEPTH_COMPONENT16 0x81A5
+#define GL_STENCIL_INDEX8 0x8D48
+
+#define GL_RENDERBUFFER_WIDTH 0x8D42
+#define GL_RENDERBUFFER_HEIGHT 0x8D43
+#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44
+#define GL_RENDERBUFFER_RED_SIZE 0x8D50
+#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51
+#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52
+#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53
+#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54
+#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55
+
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3
+
+#define GL_COLOR_ATTACHMENT0 0x8CE0
+#define GL_DEPTH_ATTACHMENT 0x8D00
+#define GL_STENCIL_ATTACHMENT 0x8D20
+
+#define GL_NONE 0
+
+#define GL_FRAMEBUFFER_COMPLETE 0x8CD5
+#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6
+#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7
+#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9
+#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD
+
+#define GL_FRAMEBUFFER_BINDING 0x8CA6
+#define GL_RENDERBUFFER_BINDING 0x8CA7
+#define GL_MAX_RENDERBUFFER_SIZE 0x84E8
+
+#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506
+
+/*-------------------------------------------------------------------------
+ * GL core functions.
+ *-----------------------------------------------------------------------*/
+
+GL_APICALL void GL_APIENTRY glActiveTexture (GLenum texture);
+GL_APICALL void GL_APIENTRY glAttachShader (GLuint program, GLuint shader);
+GL_APICALL void GL_APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar* name);
+GL_APICALL void GL_APIENTRY glBindBuffer (GLenum target, GLuint buffer);
+GL_APICALL void GL_APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer);
+GL_APICALL void GL_APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer);
+GL_APICALL void GL_APIENTRY glBindTexture (GLenum target, GLuint texture);
+GL_APICALL void GL_APIENTRY glBlendColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
+GL_APICALL void GL_APIENTRY glBlendEquation ( GLenum mode );
+GL_APICALL void GL_APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha);
+GL_APICALL void GL_APIENTRY glBlendFunc (GLenum sfactor, GLenum dfactor);
+GL_APICALL void GL_APIENTRY glBlendFuncSeparate (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+GL_APICALL void GL_APIENTRY glBufferData (GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage);
+GL_APICALL void GL_APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data);
+GL_APICALL GLenum GL_APIENTRY glCheckFramebufferStatus (GLenum target);
+GL_APICALL void GL_APIENTRY glClear (GLbitfield mask);
+GL_APICALL void GL_APIENTRY glClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
+GL_APICALL void GL_APIENTRY glClearDepthf (GLclampf depth);
+GL_APICALL void GL_APIENTRY glClearStencil (GLint s);
+GL_APICALL void GL_APIENTRY glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
+GL_APICALL void GL_APIENTRY glCompileShader (GLuint shader);
+GL_APICALL void GL_APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid* data);
+GL_APICALL void GL_APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data);
+GL_APICALL void GL_APIENTRY glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+GL_APICALL void GL_APIENTRY glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+GL_APICALL GLuint GL_APIENTRY glCreateProgram (void);
+GL_APICALL GLuint GL_APIENTRY glCreateShader (GLenum type);
+GL_APICALL void GL_APIENTRY glCullFace (GLenum mode);
+GL_APICALL void GL_APIENTRY glDeleteBuffers (GLsizei n, const GLuint* buffers);
+GL_APICALL void GL_APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint* framebuffers);
+GL_APICALL void GL_APIENTRY glDeleteProgram (GLuint program);
+GL_APICALL void GL_APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint* renderbuffers);
+GL_APICALL void GL_APIENTRY glDeleteShader (GLuint shader);
+GL_APICALL void GL_APIENTRY glDeleteTextures (GLsizei n, const GLuint* textures);
+GL_APICALL void GL_APIENTRY glDepthFunc (GLenum func);
+GL_APICALL void GL_APIENTRY glDepthMask (GLboolean flag);
+GL_APICALL void GL_APIENTRY glDepthRangef (GLclampf zNear, GLclampf zFar);
+GL_APICALL void GL_APIENTRY glDetachShader (GLuint program, GLuint shader);
+GL_APICALL void GL_APIENTRY glDisable (GLenum cap);
+GL_APICALL void GL_APIENTRY glDisableVertexAttribArray (GLuint index);
+GL_APICALL void GL_APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count);
+GL_APICALL void GL_APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid* indices);
+GL_APICALL void GL_APIENTRY glEnable (GLenum cap);
+GL_APICALL void GL_APIENTRY glEnableVertexAttribArray (GLuint index);
+GL_APICALL void GL_APIENTRY glFinish (void);
+GL_APICALL void GL_APIENTRY glFlush (void);
+GL_APICALL void GL_APIENTRY glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
+GL_APICALL void GL_APIENTRY glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+GL_APICALL void GL_APIENTRY glFrontFace (GLenum mode);
+GL_APICALL void GL_APIENTRY glGenBuffers (GLsizei n, GLuint* buffers);
+GL_APICALL void GL_APIENTRY glGenerateMipmap (GLenum target);
+GL_APICALL void GL_APIENTRY glGenFramebuffers (GLsizei n, GLuint* framebuffers);
+GL_APICALL void GL_APIENTRY glGenRenderbuffers (GLsizei n, GLuint* renderbuffers);
+GL_APICALL void GL_APIENTRY glGenTextures (GLsizei n, GLuint* textures);
+GL_APICALL void GL_APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name);
+GL_APICALL void GL_APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name);
+GL_APICALL void GL_APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders);
+GL_APICALL GLint GL_APIENTRY glGetAttribLocation (GLuint program, const GLchar* name);
+GL_APICALL void GL_APIENTRY glGetBooleanv (GLenum pname, GLboolean* params);
+GL_APICALL void GL_APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint* params);
+GL_APICALL GLenum GL_APIENTRY glGetError (void);
+GL_APICALL void GL_APIENTRY glGetFloatv (GLenum pname, GLfloat* params);
+GL_APICALL void GL_APIENTRY glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint* params);
+GL_APICALL void GL_APIENTRY glGetIntegerv (GLenum pname, GLint* params);
+GL_APICALL void GL_APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint* params);
+GL_APICALL void GL_APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog);
+GL_APICALL void GL_APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint* params);
+GL_APICALL void GL_APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint* params);
+GL_APICALL void GL_APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog);
+GL_APICALL void GL_APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision);
+GL_APICALL void GL_APIENTRY glGetShaderSource (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source);
+GL_APICALL const GLubyte* GL_APIENTRY glGetString (GLenum name);
+GL_APICALL void GL_APIENTRY glGetTexParameterfv (GLenum target, GLenum pname, GLfloat* params);
+GL_APICALL void GL_APIENTRY glGetTexParameteriv (GLenum target, GLenum pname, GLint* params);
+GL_APICALL void GL_APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat* params);
+GL_APICALL void GL_APIENTRY glGetUniformiv (GLuint program, GLint location, GLint* params);
+GL_APICALL GLint GL_APIENTRY glGetUniformLocation (GLuint program, const GLchar* name);
+GL_APICALL void GL_APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat* params);
+GL_APICALL void GL_APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint* params);
+GL_APICALL void GL_APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, GLvoid** pointer);
+GL_APICALL void GL_APIENTRY glHint (GLenum target, GLenum mode);
+GL_APICALL GLboolean GL_APIENTRY glIsBuffer (GLuint buffer);
+GL_APICALL GLboolean GL_APIENTRY glIsEnabled (GLenum cap);
+GL_APICALL GLboolean GL_APIENTRY glIsFramebuffer (GLuint framebuffer);
+GL_APICALL GLboolean GL_APIENTRY glIsProgram (GLuint program);
+GL_APICALL GLboolean GL_APIENTRY glIsRenderbuffer (GLuint renderbuffer);
+GL_APICALL GLboolean GL_APIENTRY glIsShader (GLuint shader);
+GL_APICALL GLboolean GL_APIENTRY glIsTexture (GLuint texture);
+GL_APICALL void GL_APIENTRY glLineWidth (GLfloat width);
+GL_APICALL void GL_APIENTRY glLinkProgram (GLuint program);
+GL_APICALL void GL_APIENTRY glPixelStorei (GLenum pname, GLint param);
+GL_APICALL void GL_APIENTRY glPolygonOffset (GLfloat factor, GLfloat units);
+GL_APICALL void GL_APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels);
+GL_APICALL void GL_APIENTRY glReleaseShaderCompiler (void);
+GL_APICALL void GL_APIENTRY glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glSampleCoverage (GLclampf value, GLboolean invert);
+GL_APICALL void GL_APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glShaderBinary (GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length);
+GL_APICALL void GL_APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length);
+GL_APICALL void GL_APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask);
+GL_APICALL void GL_APIENTRY glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask);
+GL_APICALL void GL_APIENTRY glStencilMask (GLuint mask);
+GL_APICALL void GL_APIENTRY glStencilMaskSeparate (GLenum face, GLuint mask);
+GL_APICALL void GL_APIENTRY glStencilOp (GLenum fail, GLenum zfail, GLenum zpass);
+GL_APICALL void GL_APIENTRY glStencilOpSeparate (GLenum face, GLenum fail, GLenum zfail, GLenum zpass);
+GL_APICALL void GL_APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels);
+GL_APICALL void GL_APIENTRY glTexParameterf (GLenum target, GLenum pname, GLfloat param);
+GL_APICALL void GL_APIENTRY glTexParameterfv (GLenum target, GLenum pname, const GLfloat* params);
+GL_APICALL void GL_APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param);
+GL_APICALL void GL_APIENTRY glTexParameteriv (GLenum target, GLenum pname, const GLint* params);
+GL_APICALL void GL_APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels);
+GL_APICALL void GL_APIENTRY glUniform1f (GLint location, GLfloat x);
+GL_APICALL void GL_APIENTRY glUniform1fv (GLint location, GLsizei count, const GLfloat* v);
+GL_APICALL void GL_APIENTRY glUniform1i (GLint location, GLint x);
+GL_APICALL void GL_APIENTRY glUniform1iv (GLint location, GLsizei count, const GLint* v);
+GL_APICALL void GL_APIENTRY glUniform2f (GLint location, GLfloat x, GLfloat y);
+GL_APICALL void GL_APIENTRY glUniform2fv (GLint location, GLsizei count, const GLfloat* v);
+GL_APICALL void GL_APIENTRY glUniform2i (GLint location, GLint x, GLint y);
+GL_APICALL void GL_APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint* v);
+GL_APICALL void GL_APIENTRY glUniform3f (GLint location, GLfloat x, GLfloat y, GLfloat z);
+GL_APICALL void GL_APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat* v);
+GL_APICALL void GL_APIENTRY glUniform3i (GLint location, GLint x, GLint y, GLint z);
+GL_APICALL void GL_APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint* v);
+GL_APICALL void GL_APIENTRY glUniform4f (GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GL_APICALL void GL_APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat* v);
+GL_APICALL void GL_APIENTRY glUniform4i (GLint location, GLint x, GLint y, GLint z, GLint w);
+GL_APICALL void GL_APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint* v);
+GL_APICALL void GL_APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
+GL_APICALL void GL_APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
+GL_APICALL void GL_APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
+GL_APICALL void GL_APIENTRY glUseProgram (GLuint program);
+GL_APICALL void GL_APIENTRY glValidateProgram (GLuint program);
+GL_APICALL void GL_APIENTRY glVertexAttrib1f (GLuint indx, GLfloat x);
+GL_APICALL void GL_APIENTRY glVertexAttrib1fv (GLuint indx, const GLfloat* values);
+GL_APICALL void GL_APIENTRY glVertexAttrib2f (GLuint indx, GLfloat x, GLfloat y);
+GL_APICALL void GL_APIENTRY glVertexAttrib2fv (GLuint indx, const GLfloat* values);
+GL_APICALL void GL_APIENTRY glVertexAttrib3f (GLuint indx, GLfloat x, GLfloat y, GLfloat z);
+GL_APICALL void GL_APIENTRY glVertexAttrib3fv (GLuint indx, const GLfloat* values);
+GL_APICALL void GL_APIENTRY glVertexAttrib4f (GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GL_APICALL void GL_APIENTRY glVertexAttrib4fv (GLuint indx, const GLfloat* values);
+GL_APICALL void GL_APIENTRY glVertexAttribPointer (GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr);
+GL_APICALL void GL_APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __gl2_h_ */
+
diff --git a/src/3rdparty/SDL2/include/SDL_opengles2_gl2ext.h b/src/3rdparty/SDL2/include/SDL_opengles2_gl2ext.h
new file mode 100644
index 0000000..e8ca8b1
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_opengles2_gl2ext.h
@@ -0,0 +1,2050 @@
+#ifndef __gl2ext_h_
+#define __gl2ext_h_
+
+/* $Revision: 22801 $ on $Date:: 2013-08-21 03:20:48 -0700 #$ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * This document is licensed under the SGI Free Software B License Version
+ * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ .
+ */
+
+#ifndef GL_APIENTRYP
+# define GL_APIENTRYP GL_APIENTRY*
+#endif
+
+/* New types shared by several extensions */
+
+#ifndef __gl3_h_
+/* These are defined with respect to <inttypes.h> in the
+ * Apple extension spec, but they are also used by non-APPLE
+ * extensions, and in the Khronos header we use the Khronos
+ * portable types in khrplatform.h, which must be defined.
+ */
+typedef khronos_int64_t GLint64;
+typedef khronos_uint64_t GLuint64;
+typedef struct __GLsync *GLsync;
+#endif
+
+
+/*------------------------------------------------------------------------*
+ * OES extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_OES_compressed_ETC1_RGB8_texture */
+#ifndef GL_OES_compressed_ETC1_RGB8_texture
+#define GL_ETC1_RGB8_OES 0x8D64
+#endif
+
+/* GL_OES_compressed_paletted_texture */
+#ifndef GL_OES_compressed_paletted_texture
+#define GL_PALETTE4_RGB8_OES 0x8B90
+#define GL_PALETTE4_RGBA8_OES 0x8B91
+#define GL_PALETTE4_R5_G6_B5_OES 0x8B92
+#define GL_PALETTE4_RGBA4_OES 0x8B93
+#define GL_PALETTE4_RGB5_A1_OES 0x8B94
+#define GL_PALETTE8_RGB8_OES 0x8B95
+#define GL_PALETTE8_RGBA8_OES 0x8B96
+#define GL_PALETTE8_R5_G6_B5_OES 0x8B97
+#define GL_PALETTE8_RGBA4_OES 0x8B98
+#define GL_PALETTE8_RGB5_A1_OES 0x8B99
+#endif
+
+/* GL_OES_depth24 */
+#ifndef GL_OES_depth24
+#define GL_DEPTH_COMPONENT24_OES 0x81A6
+#endif
+
+/* GL_OES_depth32 */
+#ifndef GL_OES_depth32
+#define GL_DEPTH_COMPONENT32_OES 0x81A7
+#endif
+
+/* GL_OES_depth_texture */
+/* No new tokens introduced by this extension. */
+
+/* GL_OES_EGL_image */
+#ifndef GL_OES_EGL_image
+typedef void* GLeglImageOES;
+#endif
+
+/* GL_OES_EGL_image_external */
+#ifndef GL_OES_EGL_image_external
+/* GLeglImageOES defined in GL_OES_EGL_image already. */
+#define GL_TEXTURE_EXTERNAL_OES 0x8D65
+#define GL_SAMPLER_EXTERNAL_OES 0x8D66
+#define GL_TEXTURE_BINDING_EXTERNAL_OES 0x8D67
+#define GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES 0x8D68
+#endif
+
+/* GL_OES_element_index_uint */
+#ifndef GL_OES_element_index_uint
+#define GL_UNSIGNED_INT 0x1405
+#endif
+
+/* GL_OES_get_program_binary */
+#ifndef GL_OES_get_program_binary
+#define GL_PROGRAM_BINARY_LENGTH_OES 0x8741
+#define GL_NUM_PROGRAM_BINARY_FORMATS_OES 0x87FE
+#define GL_PROGRAM_BINARY_FORMATS_OES 0x87FF
+#endif
+
+/* GL_OES_mapbuffer */
+#ifndef GL_OES_mapbuffer
+#define GL_WRITE_ONLY_OES 0x88B9
+#define GL_BUFFER_ACCESS_OES 0x88BB
+#define GL_BUFFER_MAPPED_OES 0x88BC
+#define GL_BUFFER_MAP_POINTER_OES 0x88BD
+#endif
+
+/* GL_OES_packed_depth_stencil */
+#ifndef GL_OES_packed_depth_stencil
+#define GL_DEPTH_STENCIL_OES 0x84F9
+#define GL_UNSIGNED_INT_24_8_OES 0x84FA
+#define GL_DEPTH24_STENCIL8_OES 0x88F0
+#endif
+
+/* GL_OES_required_internalformat */
+#ifndef GL_OES_required_internalformat
+#define GL_ALPHA8_OES 0x803C
+#define GL_DEPTH_COMPONENT16_OES 0x81A5
+/* reuse GL_DEPTH_COMPONENT24_OES */
+/* reuse GL_DEPTH24_STENCIL8_OES */
+/* reuse GL_DEPTH_COMPONENT32_OES */
+#define GL_LUMINANCE4_ALPHA4_OES 0x8043
+#define GL_LUMINANCE8_ALPHA8_OES 0x8045
+#define GL_LUMINANCE8_OES 0x8040
+#define GL_RGBA4_OES 0x8056
+#define GL_RGB5_A1_OES 0x8057
+#define GL_RGB565_OES 0x8D62
+/* reuse GL_RGB8_OES */
+/* reuse GL_RGBA8_OES */
+/* reuse GL_RGB10_EXT */
+/* reuse GL_RGB10_A2_EXT */
+#endif
+
+/* GL_OES_rgb8_rgba8 */
+#ifndef GL_OES_rgb8_rgba8
+#define GL_RGB8_OES 0x8051
+#define GL_RGBA8_OES 0x8058
+#endif
+
+/* GL_OES_standard_derivatives */
+#ifndef GL_OES_standard_derivatives
+#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES 0x8B8B
+#endif
+
+/* GL_OES_stencil1 */
+#ifndef GL_OES_stencil1
+#define GL_STENCIL_INDEX1_OES 0x8D46
+#endif
+
+/* GL_OES_stencil4 */
+#ifndef GL_OES_stencil4
+#define GL_STENCIL_INDEX4_OES 0x8D47
+#endif
+
+#ifndef GL_OES_surfaceless_context
+#define GL_FRAMEBUFFER_UNDEFINED_OES 0x8219
+#endif
+
+/* GL_OES_texture_3D */
+#ifndef GL_OES_texture_3D
+#define GL_TEXTURE_WRAP_R_OES 0x8072
+#define GL_TEXTURE_3D_OES 0x806F
+#define GL_TEXTURE_BINDING_3D_OES 0x806A
+#define GL_MAX_3D_TEXTURE_SIZE_OES 0x8073
+#define GL_SAMPLER_3D_OES 0x8B5F
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_OES 0x8CD4
+#endif
+
+/* GL_OES_texture_float */
+/* No new tokens introduced by this extension. */
+
+/* GL_OES_texture_float_linear */
+/* No new tokens introduced by this extension. */
+
+/* GL_OES_texture_half_float */
+#ifndef GL_OES_texture_half_float
+#define GL_HALF_FLOAT_OES 0x8D61
+#endif
+
+/* GL_OES_texture_half_float_linear */
+/* No new tokens introduced by this extension. */
+
+/* GL_OES_texture_npot */
+/* No new tokens introduced by this extension. */
+
+/* GL_OES_vertex_array_object */
+#ifndef GL_OES_vertex_array_object
+#define GL_VERTEX_ARRAY_BINDING_OES 0x85B5
+#endif
+
+/* GL_OES_vertex_half_float */
+/* GL_HALF_FLOAT_OES defined in GL_OES_texture_half_float already. */
+
+/* GL_OES_vertex_type_10_10_10_2 */
+#ifndef GL_OES_vertex_type_10_10_10_2
+#define GL_UNSIGNED_INT_10_10_10_2_OES 0x8DF6
+#define GL_INT_10_10_10_2_OES 0x8DF7
+#endif
+
+/*------------------------------------------------------------------------*
+ * KHR extension tokens
+ *------------------------------------------------------------------------*/
+
+#ifndef GL_KHR_debug
+typedef void (GL_APIENTRYP GLDEBUGPROCKHR)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
+#define GL_DEBUG_OUTPUT_SYNCHRONOUS_KHR 0x8242
+#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_KHR 0x8243
+#define GL_DEBUG_CALLBACK_FUNCTION_KHR 0x8244
+#define GL_DEBUG_CALLBACK_USER_PARAM_KHR 0x8245
+#define GL_DEBUG_SOURCE_API_KHR 0x8246
+#define GL_DEBUG_SOURCE_WINDOW_SYSTEM_KHR 0x8247
+#define GL_DEBUG_SOURCE_SHADER_COMPILER_KHR 0x8248
+#define GL_DEBUG_SOURCE_THIRD_PARTY_KHR 0x8249
+#define GL_DEBUG_SOURCE_APPLICATION_KHR 0x824A
+#define GL_DEBUG_SOURCE_OTHER_KHR 0x824B
+#define GL_DEBUG_TYPE_ERROR_KHR 0x824C
+#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_KHR 0x824D
+#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_KHR 0x824E
+#define GL_DEBUG_TYPE_PORTABILITY_KHR 0x824F
+#define GL_DEBUG_TYPE_PERFORMANCE_KHR 0x8250
+#define GL_DEBUG_TYPE_OTHER_KHR 0x8251
+#define GL_DEBUG_TYPE_MARKER_KHR 0x8268
+#define GL_DEBUG_TYPE_PUSH_GROUP_KHR 0x8269
+#define GL_DEBUG_TYPE_POP_GROUP_KHR 0x826A
+#define GL_DEBUG_SEVERITY_NOTIFICATION_KHR 0x826B
+#define GL_MAX_DEBUG_GROUP_STACK_DEPTH_KHR 0x826C
+#define GL_DEBUG_GROUP_STACK_DEPTH_KHR 0x826D
+#define GL_BUFFER_KHR 0x82E0
+#define GL_SHADER_KHR 0x82E1
+#define GL_PROGRAM_KHR 0x82E2
+#define GL_QUERY_KHR 0x82E3
+/* PROGRAM_PIPELINE only in GL */
+#define GL_SAMPLER_KHR 0x82E6
+/* DISPLAY_LIST only in GL */
+#define GL_MAX_LABEL_LENGTH_KHR 0x82E8
+#define GL_MAX_DEBUG_MESSAGE_LENGTH_KHR 0x9143
+#define GL_MAX_DEBUG_LOGGED_MESSAGES_KHR 0x9144
+#define GL_DEBUG_LOGGED_MESSAGES_KHR 0x9145
+#define GL_DEBUG_SEVERITY_HIGH_KHR 0x9146
+#define GL_DEBUG_SEVERITY_MEDIUM_KHR 0x9147
+#define GL_DEBUG_SEVERITY_LOW_KHR 0x9148
+#define GL_DEBUG_OUTPUT_KHR 0x92E0
+#define GL_CONTEXT_FLAG_DEBUG_BIT_KHR 0x00000002
+#define GL_STACK_OVERFLOW_KHR 0x0503
+#define GL_STACK_UNDERFLOW_KHR 0x0504
+#endif
+
+#ifndef GL_KHR_texture_compression_astc_ldr
+#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0
+#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1
+#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2
+#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3
+#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4
+#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5
+#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6
+#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7
+#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8
+#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9
+#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA
+#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB
+#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC
+#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD
+#endif
+
+/*------------------------------------------------------------------------*
+ * AMD extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_AMD_compressed_3DC_texture */
+#ifndef GL_AMD_compressed_3DC_texture
+#define GL_3DC_X_AMD 0x87F9
+#define GL_3DC_XY_AMD 0x87FA
+#endif
+
+/* GL_AMD_compressed_ATC_texture */
+#ifndef GL_AMD_compressed_ATC_texture
+#define GL_ATC_RGB_AMD 0x8C92
+#define GL_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93
+#define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE
+#endif
+
+/* GL_AMD_performance_monitor */
+#ifndef GL_AMD_performance_monitor
+#define GL_COUNTER_TYPE_AMD 0x8BC0
+#define GL_COUNTER_RANGE_AMD 0x8BC1
+#define GL_UNSIGNED_INT64_AMD 0x8BC2
+#define GL_PERCENTAGE_AMD 0x8BC3
+#define GL_PERFMON_RESULT_AVAILABLE_AMD 0x8BC4
+#define GL_PERFMON_RESULT_SIZE_AMD 0x8BC5
+#define GL_PERFMON_RESULT_AMD 0x8BC6
+#endif
+
+/* GL_AMD_program_binary_Z400 */
+#ifndef GL_AMD_program_binary_Z400
+#define GL_Z400_BINARY_AMD 0x8740
+#endif
+
+/*------------------------------------------------------------------------*
+ * ANGLE extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_ANGLE_depth_texture */
+#ifndef GL_ANGLE_depth_texture
+#define GL_DEPTH_COMPONENT 0x1902
+#define GL_DEPTH_STENCIL_OES 0x84F9
+#define GL_UNSIGNED_SHORT 0x1403
+#define GL_UNSIGNED_INT 0x1405
+#define GL_UNSIGNED_INT_24_8_OES 0x84FA
+#define GL_DEPTH_COMPONENT16 0x81A5
+#define GL_DEPTH_COMPONENT32_OES 0x81A7
+#define GL_DEPTH24_STENCIL8_OES 0x88F0
+#endif
+
+/* GL_ANGLE_framebuffer_blit */
+#ifndef GL_ANGLE_framebuffer_blit
+#define GL_READ_FRAMEBUFFER_ANGLE 0x8CA8
+#define GL_DRAW_FRAMEBUFFER_ANGLE 0x8CA9
+#define GL_DRAW_FRAMEBUFFER_BINDING_ANGLE 0x8CA6
+#define GL_READ_FRAMEBUFFER_BINDING_ANGLE 0x8CAA
+#endif
+
+/* GL_ANGLE_framebuffer_multisample */
+#ifndef GL_ANGLE_framebuffer_multisample
+#define GL_RENDERBUFFER_SAMPLES_ANGLE 0x8CAB
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE 0x8D56
+#define GL_MAX_SAMPLES_ANGLE 0x8D57
+#endif
+
+/* GL_ANGLE_instanced_arrays */
+#ifndef GL_ANGLE_instanced_arrays
+#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE 0x88FE
+#endif
+
+/* GL_ANGLE_pack_reverse_row_order */
+#ifndef GL_ANGLE_pack_reverse_row_order
+#define GL_PACK_REVERSE_ROW_ORDER_ANGLE 0x93A4
+#endif
+
+/* GL_ANGLE_program_binary */
+#ifndef GL_ANGLE_program_binary
+#define GL_PROGRAM_BINARY_ANGLE 0x93A6
+#endif
+
+/* GL_ANGLE_texture_compression_dxt3 */
+#ifndef GL_ANGLE_texture_compression_dxt3
+#define GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE 0x83F2
+#endif
+
+/* GL_ANGLE_texture_compression_dxt5 */
+#ifndef GL_ANGLE_texture_compression_dxt5
+#define GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE 0x83F3
+#endif
+
+/* GL_ANGLE_texture_usage */
+#ifndef GL_ANGLE_texture_usage
+#define GL_TEXTURE_USAGE_ANGLE 0x93A2
+#define GL_FRAMEBUFFER_ATTACHMENT_ANGLE 0x93A3
+#endif
+
+/* GL_ANGLE_translated_shader_source */
+#ifndef GL_ANGLE_translated_shader_source
+#define GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE 0x93A0
+#endif
+
+/*------------------------------------------------------------------------*
+ * APPLE extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_APPLE_copy_texture_levels */
+/* No new tokens introduced by this extension. */
+
+/* GL_APPLE_framebuffer_multisample */
+#ifndef GL_APPLE_framebuffer_multisample
+#define GL_RENDERBUFFER_SAMPLES_APPLE 0x8CAB
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_APPLE 0x8D56
+#define GL_MAX_SAMPLES_APPLE 0x8D57
+#define GL_READ_FRAMEBUFFER_APPLE 0x8CA8
+#define GL_DRAW_FRAMEBUFFER_APPLE 0x8CA9
+#define GL_DRAW_FRAMEBUFFER_BINDING_APPLE 0x8CA6
+#define GL_READ_FRAMEBUFFER_BINDING_APPLE 0x8CAA
+#endif
+
+/* GL_APPLE_rgb_422 */
+#ifndef GL_APPLE_rgb_422
+#define GL_RGB_422_APPLE 0x8A1F
+#define GL_UNSIGNED_SHORT_8_8_APPLE 0x85BA
+#define GL_UNSIGNED_SHORT_8_8_REV_APPLE 0x85BB
+#endif
+
+/* GL_APPLE_sync */
+#ifndef GL_APPLE_sync
+
+#define GL_SYNC_OBJECT_APPLE 0x8A53
+#define GL_MAX_SERVER_WAIT_TIMEOUT_APPLE 0x9111
+#define GL_OBJECT_TYPE_APPLE 0x9112
+#define GL_SYNC_CONDITION_APPLE 0x9113
+#define GL_SYNC_STATUS_APPLE 0x9114
+#define GL_SYNC_FLAGS_APPLE 0x9115
+#define GL_SYNC_FENCE_APPLE 0x9116
+#define GL_SYNC_GPU_COMMANDS_COMPLETE_APPLE 0x9117
+#define GL_UNSIGNALED_APPLE 0x9118
+#define GL_SIGNALED_APPLE 0x9119
+#define GL_ALREADY_SIGNALED_APPLE 0x911A
+#define GL_TIMEOUT_EXPIRED_APPLE 0x911B
+#define GL_CONDITION_SATISFIED_APPLE 0x911C
+#define GL_WAIT_FAILED_APPLE 0x911D
+#define GL_SYNC_FLUSH_COMMANDS_BIT_APPLE 0x00000001
+#define GL_TIMEOUT_IGNORED_APPLE 0xFFFFFFFFFFFFFFFFull
+#endif
+
+/* GL_APPLE_texture_format_BGRA8888 */
+#ifndef GL_APPLE_texture_format_BGRA8888
+#define GL_BGRA_EXT 0x80E1
+#endif
+
+/* GL_APPLE_texture_max_level */
+#ifndef GL_APPLE_texture_max_level
+#define GL_TEXTURE_MAX_LEVEL_APPLE 0x813D
+#endif
+
+/*------------------------------------------------------------------------*
+ * ARM extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_ARM_mali_program_binary */
+#ifndef GL_ARM_mali_program_binary
+#define GL_MALI_PROGRAM_BINARY_ARM 0x8F61
+#endif
+
+/* GL_ARM_mali_shader_binary */
+#ifndef GL_ARM_mali_shader_binary
+#define GL_MALI_SHADER_BINARY_ARM 0x8F60
+#endif
+
+/* GL_ARM_rgba8 */
+/* No new tokens introduced by this extension. */
+
+/*------------------------------------------------------------------------*
+ * EXT extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_EXT_blend_minmax */
+#ifndef GL_EXT_blend_minmax
+#define GL_MIN_EXT 0x8007
+#define GL_MAX_EXT 0x8008
+#endif
+
+/* GL_EXT_color_buffer_half_float */
+#ifndef GL_EXT_color_buffer_half_float
+#define GL_RGBA16F_EXT 0x881A
+#define GL_RGB16F_EXT 0x881B
+#define GL_RG16F_EXT 0x822F
+#define GL_R16F_EXT 0x822D
+#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT 0x8211
+#define GL_UNSIGNED_NORMALIZED_EXT 0x8C17
+#endif
+
+/* GL_EXT_debug_label */
+#ifndef GL_EXT_debug_label
+#define GL_PROGRAM_PIPELINE_OBJECT_EXT 0x8A4F
+#define GL_PROGRAM_OBJECT_EXT 0x8B40
+#define GL_SHADER_OBJECT_EXT 0x8B48
+#define GL_BUFFER_OBJECT_EXT 0x9151
+#define GL_QUERY_OBJECT_EXT 0x9153
+#define GL_VERTEX_ARRAY_OBJECT_EXT 0x9154
+#endif
+
+/* GL_EXT_debug_marker */
+/* No new tokens introduced by this extension. */
+
+/* GL_EXT_discard_framebuffer */
+#ifndef GL_EXT_discard_framebuffer
+#define GL_COLOR_EXT 0x1800
+#define GL_DEPTH_EXT 0x1801
+#define GL_STENCIL_EXT 0x1802
+#endif
+
+#ifndef GL_EXT_disjoint_timer_query
+#define GL_QUERY_COUNTER_BITS_EXT 0x8864
+#define GL_CURRENT_QUERY_EXT 0x8865
+#define GL_QUERY_RESULT_EXT 0x8866
+#define GL_QUERY_RESULT_AVAILABLE_EXT 0x8867
+#define GL_TIME_ELAPSED_EXT 0x88BF
+#define GL_TIMESTAMP_EXT 0x8E28
+#define GL_GPU_DISJOINT_EXT 0x8FBB
+#endif
+
+#ifndef GL_EXT_draw_buffers
+#define GL_EXT_draw_buffers 1
+#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF
+#define GL_MAX_DRAW_BUFFERS_EXT 0x8824
+#define GL_DRAW_BUFFER0_EXT 0x8825
+#define GL_DRAW_BUFFER1_EXT 0x8826
+#define GL_DRAW_BUFFER2_EXT 0x8827
+#define GL_DRAW_BUFFER3_EXT 0x8828
+#define GL_DRAW_BUFFER4_EXT 0x8829
+#define GL_DRAW_BUFFER5_EXT 0x882A
+#define GL_DRAW_BUFFER6_EXT 0x882B
+#define GL_DRAW_BUFFER7_EXT 0x882C
+#define GL_DRAW_BUFFER8_EXT 0x882D
+#define GL_DRAW_BUFFER9_EXT 0x882E
+#define GL_DRAW_BUFFER10_EXT 0x882F
+#define GL_DRAW_BUFFER11_EXT 0x8830
+#define GL_DRAW_BUFFER12_EXT 0x8831
+#define GL_DRAW_BUFFER13_EXT 0x8832
+#define GL_DRAW_BUFFER14_EXT 0x8833
+#define GL_DRAW_BUFFER15_EXT 0x8834
+#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
+#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1
+#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2
+#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3
+#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4
+#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5
+#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6
+#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7
+#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8
+#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9
+#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA
+#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB
+#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC
+#define GL_COLOR_ATTACHMENT13_EXT 0x8CED
+#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE
+#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF
+#endif
+
+/* GL_EXT_map_buffer_range */
+#ifndef GL_EXT_map_buffer_range
+#define GL_MAP_READ_BIT_EXT 0x0001
+#define GL_MAP_WRITE_BIT_EXT 0x0002
+#define GL_MAP_INVALIDATE_RANGE_BIT_EXT 0x0004
+#define GL_MAP_INVALIDATE_BUFFER_BIT_EXT 0x0008
+#define GL_MAP_FLUSH_EXPLICIT_BIT_EXT 0x0010
+#define GL_MAP_UNSYNCHRONIZED_BIT_EXT 0x0020
+#endif
+
+/* GL_EXT_multisampled_render_to_texture */
+#ifndef GL_EXT_multisampled_render_to_texture
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT 0x8D6C
+/* reuse values from GL_EXT_framebuffer_multisample (desktop extension) */
+#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56
+#define GL_MAX_SAMPLES_EXT 0x8D57
+#endif
+
+/* GL_EXT_multiview_draw_buffers */
+#ifndef GL_EXT_multiview_draw_buffers
+#define GL_COLOR_ATTACHMENT_EXT 0x90F0
+#define GL_MULTIVIEW_EXT 0x90F1
+#define GL_DRAW_BUFFER_EXT 0x0C01
+#define GL_READ_BUFFER_EXT 0x0C02
+#define GL_MAX_MULTIVIEW_BUFFERS_EXT 0x90F2
+#endif
+
+/* GL_EXT_multi_draw_arrays */
+/* No new tokens introduced by this extension. */
+
+/* GL_EXT_occlusion_query_boolean */
+#ifndef GL_EXT_occlusion_query_boolean
+#define GL_ANY_SAMPLES_PASSED_EXT 0x8C2F
+#define GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT 0x8D6A
+#define GL_CURRENT_QUERY_EXT 0x8865
+#define GL_QUERY_RESULT_EXT 0x8866
+#define GL_QUERY_RESULT_AVAILABLE_EXT 0x8867
+#endif
+
+/* GL_EXT_read_format_bgra */
+#ifndef GL_EXT_read_format_bgra
+#define GL_BGRA_EXT 0x80E1
+#define GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT 0x8365
+#define GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT 0x8366
+#endif
+
+/* GL_EXT_robustness */
+#ifndef GL_EXT_robustness
+/* reuse GL_NO_ERROR */
+#define GL_GUILTY_CONTEXT_RESET_EXT 0x8253
+#define GL_INNOCENT_CONTEXT_RESET_EXT 0x8254
+#define GL_UNKNOWN_CONTEXT_RESET_EXT 0x8255
+#define GL_CONTEXT_ROBUST_ACCESS_EXT 0x90F3
+#define GL_RESET_NOTIFICATION_STRATEGY_EXT 0x8256
+#define GL_LOSE_CONTEXT_ON_RESET_EXT 0x8252
+#define GL_NO_RESET_NOTIFICATION_EXT 0x8261
+#endif
+
+/* GL_EXT_separate_shader_objects */
+#ifndef GL_EXT_separate_shader_objects
+#define GL_VERTEX_SHADER_BIT_EXT 0x00000001
+#define GL_FRAGMENT_SHADER_BIT_EXT 0x00000002
+#define GL_ALL_SHADER_BITS_EXT 0xFFFFFFFF
+#define GL_PROGRAM_SEPARABLE_EXT 0x8258
+#define GL_ACTIVE_PROGRAM_EXT 0x8259
+#define GL_PROGRAM_PIPELINE_BINDING_EXT 0x825A
+#endif
+
+/* GL_EXT_shader_framebuffer_fetch */
+#ifndef GL_EXT_shader_framebuffer_fetch
+#define GL_FRAGMENT_SHADER_DISCARDS_SAMPLES_EXT 0x8A52
+#endif
+
+/* GL_EXT_shader_texture_lod */
+/* No new tokens introduced by this extension. */
+
+/* GL_EXT_shadow_samplers */
+#ifndef GL_EXT_shadow_samplers
+#define GL_TEXTURE_COMPARE_MODE_EXT 0x884C
+#define GL_TEXTURE_COMPARE_FUNC_EXT 0x884D
+#define GL_COMPARE_REF_TO_TEXTURE_EXT 0x884E
+#define GL_SAMPLER_2D_SHADOW_EXT 0x8B62
+#endif
+
+/* GL_EXT_sRGB */
+#ifndef GL_EXT_sRGB
+#define GL_SRGB_EXT 0x8C40
+#define GL_SRGB_ALPHA_EXT 0x8C42
+#define GL_SRGB8_ALPHA8_EXT 0x8C43
+#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT 0x8210
+#endif
+
+/* GL_EXT_sRGB_write_control */
+#ifndef GL_EXT_sRGB_write_control
+#define GL_EXT_sRGB_write_control 1
+#define GL_FRAMEBUFFER_SRGB_EXT 0x8DB9
+#endif
+
+/* GL_EXT_texture_compression_dxt1 */
+#ifndef GL_EXT_texture_compression_dxt1
+#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
+#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
+#endif
+
+/* GL_EXT_texture_filter_anisotropic */
+#ifndef GL_EXT_texture_filter_anisotropic
+#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
+#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
+#endif
+
+/* GL_EXT_texture_format_BGRA8888 */
+#ifndef GL_EXT_texture_format_BGRA8888
+#define GL_BGRA_EXT 0x80E1
+#endif
+
+/* GL_EXT_texture_rg */
+#ifndef GL_EXT_texture_rg
+#define GL_RED_EXT 0x1903
+#define GL_RG_EXT 0x8227
+#define GL_R8_EXT 0x8229
+#define GL_RG8_EXT 0x822B
+#endif
+
+/* GL_EXT_texture_sRGB_decode */
+#ifndef GL_EXT_texture_sRGB_decode
+#define GL_EXT_texture_sRGB_decode 1
+#define GL_TEXTURE_SRGB_DECODE_EXT 0x8A48
+#define GL_DECODE_EXT 0x8A49
+#define GL_SKIP_DECODE_EXT 0x8A4A
+#endif
+
+/* GL_EXT_texture_storage */
+#ifndef GL_EXT_texture_storage
+#define GL_TEXTURE_IMMUTABLE_FORMAT_EXT 0x912F
+#define GL_ALPHA8_EXT 0x803C
+#define GL_LUMINANCE8_EXT 0x8040
+#define GL_LUMINANCE8_ALPHA8_EXT 0x8045
+#define GL_RGBA32F_EXT 0x8814
+#define GL_RGB32F_EXT 0x8815
+#define GL_ALPHA32F_EXT 0x8816
+#define GL_LUMINANCE32F_EXT 0x8818
+#define GL_LUMINANCE_ALPHA32F_EXT 0x8819
+/* reuse GL_RGBA16F_EXT */
+/* reuse GL_RGB16F_EXT */
+#define GL_ALPHA16F_EXT 0x881C
+#define GL_LUMINANCE16F_EXT 0x881E
+#define GL_LUMINANCE_ALPHA16F_EXT 0x881F
+#define GL_RGB10_A2_EXT 0x8059
+#define GL_RGB10_EXT 0x8052
+#define GL_BGRA8_EXT 0x93A1
+#define GL_R8_EXT 0x8229
+#define GL_RG8_EXT 0x822B
+#define GL_R32F_EXT 0x822E
+#define GL_RG32F_EXT 0x8230
+#define GL_R16F_EXT 0x822D
+#define GL_RG16F_EXT 0x822F
+#endif
+
+/* GL_EXT_texture_type_2_10_10_10_REV */
+#ifndef GL_EXT_texture_type_2_10_10_10_REV
+#define GL_UNSIGNED_INT_2_10_10_10_REV_EXT 0x8368
+#endif
+
+/* GL_EXT_unpack_subimage */
+#ifndef GL_EXT_unpack_subimage
+#define GL_UNPACK_ROW_LENGTH_EXT 0x0CF2
+#define GL_UNPACK_SKIP_ROWS_EXT 0x0CF3
+#define GL_UNPACK_SKIP_PIXELS_EXT 0x0CF4
+#endif
+
+/*------------------------------------------------------------------------*
+ * DMP extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_DMP_shader_binary */
+#ifndef GL_DMP_shader_binary
+#define GL_SHADER_BINARY_DMP 0x9250
+#endif
+
+/*------------------------------------------------------------------------*
+ * FJ extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_FJ_shader_binary_GCCSO */
+#ifndef GL_FJ_shader_binary_GCCSO
+#define GL_GCCSO_SHADER_BINARY_FJ 0x9260
+#endif
+
+/*------------------------------------------------------------------------*
+ * IMG extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_IMG_program_binary */
+#ifndef GL_IMG_program_binary
+#define GL_SGX_PROGRAM_BINARY_IMG 0x9130
+#endif
+
+/* GL_IMG_read_format */
+#ifndef GL_IMG_read_format
+#define GL_BGRA_IMG 0x80E1
+#define GL_UNSIGNED_SHORT_4_4_4_4_REV_IMG 0x8365
+#endif
+
+/* GL_IMG_shader_binary */
+#ifndef GL_IMG_shader_binary
+#define GL_SGX_BINARY_IMG 0x8C0A
+#endif
+
+/* GL_IMG_texture_compression_pvrtc */
+#ifndef GL_IMG_texture_compression_pvrtc
+#define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
+#define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01
+#define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
+#define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03
+#endif
+
+/* GL_IMG_texture_compression_pvrtc2 */
+#ifndef GL_IMG_texture_compression_pvrtc2
+#define GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG 0x9137
+#define GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG 0x9138
+#endif
+
+/* GL_IMG_multisampled_render_to_texture */
+#ifndef GL_IMG_multisampled_render_to_texture
+#define GL_RENDERBUFFER_SAMPLES_IMG 0x9133
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_IMG 0x9134
+#define GL_MAX_SAMPLES_IMG 0x9135
+#define GL_TEXTURE_SAMPLES_IMG 0x9136
+#endif
+
+/*------------------------------------------------------------------------*
+ * NV extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_NV_coverage_sample */
+#ifndef GL_NV_coverage_sample
+#define GL_COVERAGE_COMPONENT_NV 0x8ED0
+#define GL_COVERAGE_COMPONENT4_NV 0x8ED1
+#define GL_COVERAGE_ATTACHMENT_NV 0x8ED2
+#define GL_COVERAGE_BUFFERS_NV 0x8ED3
+#define GL_COVERAGE_SAMPLES_NV 0x8ED4
+#define GL_COVERAGE_ALL_FRAGMENTS_NV 0x8ED5
+#define GL_COVERAGE_EDGE_FRAGMENTS_NV 0x8ED6
+#define GL_COVERAGE_AUTOMATIC_NV 0x8ED7
+#define GL_COVERAGE_BUFFER_BIT_NV 0x00008000
+#endif
+
+/* GL_NV_depth_nonlinear */
+#ifndef GL_NV_depth_nonlinear
+#define GL_DEPTH_COMPONENT16_NONLINEAR_NV 0x8E2C
+#endif
+
+/* GL_NV_draw_buffers */
+#ifndef GL_NV_draw_buffers
+#define GL_MAX_DRAW_BUFFERS_NV 0x8824
+#define GL_DRAW_BUFFER0_NV 0x8825
+#define GL_DRAW_BUFFER1_NV 0x8826
+#define GL_DRAW_BUFFER2_NV 0x8827
+#define GL_DRAW_BUFFER3_NV 0x8828
+#define GL_DRAW_BUFFER4_NV 0x8829
+#define GL_DRAW_BUFFER5_NV 0x882A
+#define GL_DRAW_BUFFER6_NV 0x882B
+#define GL_DRAW_BUFFER7_NV 0x882C
+#define GL_DRAW_BUFFER8_NV 0x882D
+#define GL_DRAW_BUFFER9_NV 0x882E
+#define GL_DRAW_BUFFER10_NV 0x882F
+#define GL_DRAW_BUFFER11_NV 0x8830
+#define GL_DRAW_BUFFER12_NV 0x8831
+#define GL_DRAW_BUFFER13_NV 0x8832
+#define GL_DRAW_BUFFER14_NV 0x8833
+#define GL_DRAW_BUFFER15_NV 0x8834
+#define GL_COLOR_ATTACHMENT0_NV 0x8CE0
+#define GL_COLOR_ATTACHMENT1_NV 0x8CE1
+#define GL_COLOR_ATTACHMENT2_NV 0x8CE2
+#define GL_COLOR_ATTACHMENT3_NV 0x8CE3
+#define GL_COLOR_ATTACHMENT4_NV 0x8CE4
+#define GL_COLOR_ATTACHMENT5_NV 0x8CE5
+#define GL_COLOR_ATTACHMENT6_NV 0x8CE6
+#define GL_COLOR_ATTACHMENT7_NV 0x8CE7
+#define GL_COLOR_ATTACHMENT8_NV 0x8CE8
+#define GL_COLOR_ATTACHMENT9_NV 0x8CE9
+#define GL_COLOR_ATTACHMENT10_NV 0x8CEA
+#define GL_COLOR_ATTACHMENT11_NV 0x8CEB
+#define GL_COLOR_ATTACHMENT12_NV 0x8CEC
+#define GL_COLOR_ATTACHMENT13_NV 0x8CED
+#define GL_COLOR_ATTACHMENT14_NV 0x8CEE
+#define GL_COLOR_ATTACHMENT15_NV 0x8CEF
+#endif
+
+/* GL_NV_draw_instanced */
+/* No new tokens introduced by this extension. */
+
+/* GL_NV_fbo_color_attachments */
+#ifndef GL_NV_fbo_color_attachments
+#define GL_MAX_COLOR_ATTACHMENTS_NV 0x8CDF
+/* GL_COLOR_ATTACHMENT{0-15}_NV defined in GL_NV_draw_buffers already. */
+#endif
+
+/* GL_NV_fence */
+#ifndef GL_NV_fence
+#define GL_ALL_COMPLETED_NV 0x84F2
+#define GL_FENCE_STATUS_NV 0x84F3
+#define GL_FENCE_CONDITION_NV 0x84F4
+#endif
+
+/* GL_NV_framebuffer_blit */
+#ifndef GL_NV_framebuffer_blit
+#define GL_READ_FRAMEBUFFER_NV 0x8CA8
+#define GL_DRAW_FRAMEBUFFER_NV 0x8CA9
+#define GL_DRAW_FRAMEBUFFER_BINDING_NV 0x8CA6
+#define GL_READ_FRAMEBUFFER_BINDING_NV 0x8CAA
+#endif
+
+/* GL_NV_framebuffer_multisample */
+#ifndef GL_NV_framebuffer_multisample
+#define GL_RENDERBUFFER_SAMPLES_NV 0x8CAB
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_NV 0x8D56
+#define GL_MAX_SAMPLES_NV 0x8D57
+#endif
+
+/* GL_NV_generate_mipmap_sRGB */
+/* No new tokens introduced by this extension. */
+
+/* GL_NV_instanced_arrays */
+#ifndef GL_NV_instanced_arrays
+#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_NV 0x88FE
+#endif
+
+/* GL_NV_read_buffer */
+#ifndef GL_NV_read_buffer
+#define GL_READ_BUFFER_NV 0x0C02
+#endif
+
+/* GL_NV_read_buffer_front */
+/* No new tokens introduced by this extension. */
+
+/* GL_NV_read_depth */
+/* No new tokens introduced by this extension. */
+
+/* GL_NV_read_depth_stencil */
+/* No new tokens introduced by this extension. */
+
+/* GL_NV_read_stencil */
+/* No new tokens introduced by this extension. */
+
+/* GL_NV_shadow_samplers_array */
+#ifndef GL_NV_shadow_samplers_array
+#define GL_SAMPLER_2D_ARRAY_SHADOW_NV 0x8DC4
+#endif
+
+/* GL_NV_shadow_samplers_cube */
+#ifndef GL_NV_shadow_samplers_cube
+#define GL_SAMPLER_CUBE_SHADOW_NV 0x8DC5
+#endif
+
+/* GL_NV_sRGB_formats */
+#ifndef GL_NV_sRGB_formats
+#define GL_SLUMINANCE_NV 0x8C46
+#define GL_SLUMINANCE_ALPHA_NV 0x8C44
+#define GL_SRGB8_NV 0x8C41
+#define GL_SLUMINANCE8_NV 0x8C47
+#define GL_SLUMINANCE8_ALPHA8_NV 0x8C45
+#define GL_COMPRESSED_SRGB_S3TC_DXT1_NV 0x8C4C
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV 0x8C4D
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV 0x8C4E
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV 0x8C4F
+#define GL_ETC1_SRGB8_NV 0x88EE
+#endif
+
+/* GL_NV_texture_border_clamp */
+#ifndef GL_NV_texture_border_clamp
+#define GL_TEXTURE_BORDER_COLOR_NV 0x1004
+#define GL_CLAMP_TO_BORDER_NV 0x812D
+#endif
+
+/* GL_NV_texture_compression_s3tc_update */
+/* No new tokens introduced by this extension. */
+
+/* GL_NV_texture_npot_2D_mipmap */
+/* No new tokens introduced by this extension. */
+
+/*------------------------------------------------------------------------*
+ * QCOM extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_QCOM_alpha_test */
+#ifndef GL_QCOM_alpha_test
+#define GL_ALPHA_TEST_QCOM 0x0BC0
+#define GL_ALPHA_TEST_FUNC_QCOM 0x0BC1
+#define GL_ALPHA_TEST_REF_QCOM 0x0BC2
+#endif
+
+/* GL_QCOM_binning_control */
+#ifndef GL_QCOM_binning_control
+#define GL_BINNING_CONTROL_HINT_QCOM 0x8FB0
+#define GL_CPU_OPTIMIZED_QCOM 0x8FB1
+#define GL_GPU_OPTIMIZED_QCOM 0x8FB2
+#define GL_RENDER_DIRECT_TO_FRAMEBUFFER_QCOM 0x8FB3
+#endif
+
+/* GL_QCOM_driver_control */
+/* No new tokens introduced by this extension. */
+
+/* GL_QCOM_extended_get */
+#ifndef GL_QCOM_extended_get
+#define GL_TEXTURE_WIDTH_QCOM 0x8BD2
+#define GL_TEXTURE_HEIGHT_QCOM 0x8BD3
+#define GL_TEXTURE_DEPTH_QCOM 0x8BD4
+#define GL_TEXTURE_INTERNAL_FORMAT_QCOM 0x8BD5
+#define GL_TEXTURE_FORMAT_QCOM 0x8BD6
+#define GL_TEXTURE_TYPE_QCOM 0x8BD7
+#define GL_TEXTURE_IMAGE_VALID_QCOM 0x8BD8
+#define GL_TEXTURE_NUM_LEVELS_QCOM 0x8BD9
+#define GL_TEXTURE_TARGET_QCOM 0x8BDA
+#define GL_TEXTURE_OBJECT_VALID_QCOM 0x8BDB
+#define GL_STATE_RESTORE 0x8BDC
+#endif
+
+/* GL_QCOM_extended_get2 */
+/* No new tokens introduced by this extension. */
+
+/* GL_QCOM_perfmon_global_mode */
+#ifndef GL_QCOM_perfmon_global_mode
+#define GL_PERFMON_GLOBAL_MODE_QCOM 0x8FA0
+#endif
+
+/* GL_QCOM_writeonly_rendering */
+#ifndef GL_QCOM_writeonly_rendering
+#define GL_WRITEONLY_RENDERING_QCOM 0x8823
+#endif
+
+/* GL_QCOM_tiled_rendering */
+#ifndef GL_QCOM_tiled_rendering
+#define GL_COLOR_BUFFER_BIT0_QCOM 0x00000001
+#define GL_COLOR_BUFFER_BIT1_QCOM 0x00000002
+#define GL_COLOR_BUFFER_BIT2_QCOM 0x00000004
+#define GL_COLOR_BUFFER_BIT3_QCOM 0x00000008
+#define GL_COLOR_BUFFER_BIT4_QCOM 0x00000010
+#define GL_COLOR_BUFFER_BIT5_QCOM 0x00000020
+#define GL_COLOR_BUFFER_BIT6_QCOM 0x00000040
+#define GL_COLOR_BUFFER_BIT7_QCOM 0x00000080
+#define GL_DEPTH_BUFFER_BIT0_QCOM 0x00000100
+#define GL_DEPTH_BUFFER_BIT1_QCOM 0x00000200
+#define GL_DEPTH_BUFFER_BIT2_QCOM 0x00000400
+#define GL_DEPTH_BUFFER_BIT3_QCOM 0x00000800
+#define GL_DEPTH_BUFFER_BIT4_QCOM 0x00001000
+#define GL_DEPTH_BUFFER_BIT5_QCOM 0x00002000
+#define GL_DEPTH_BUFFER_BIT6_QCOM 0x00004000
+#define GL_DEPTH_BUFFER_BIT7_QCOM 0x00008000
+#define GL_STENCIL_BUFFER_BIT0_QCOM 0x00010000
+#define GL_STENCIL_BUFFER_BIT1_QCOM 0x00020000
+#define GL_STENCIL_BUFFER_BIT2_QCOM 0x00040000
+#define GL_STENCIL_BUFFER_BIT3_QCOM 0x00080000
+#define GL_STENCIL_BUFFER_BIT4_QCOM 0x00100000
+#define GL_STENCIL_BUFFER_BIT5_QCOM 0x00200000
+#define GL_STENCIL_BUFFER_BIT6_QCOM 0x00400000
+#define GL_STENCIL_BUFFER_BIT7_QCOM 0x00800000
+#define GL_MULTISAMPLE_BUFFER_BIT0_QCOM 0x01000000
+#define GL_MULTISAMPLE_BUFFER_BIT1_QCOM 0x02000000
+#define GL_MULTISAMPLE_BUFFER_BIT2_QCOM 0x04000000
+#define GL_MULTISAMPLE_BUFFER_BIT3_QCOM 0x08000000
+#define GL_MULTISAMPLE_BUFFER_BIT4_QCOM 0x10000000
+#define GL_MULTISAMPLE_BUFFER_BIT5_QCOM 0x20000000
+#define GL_MULTISAMPLE_BUFFER_BIT6_QCOM 0x40000000
+#define GL_MULTISAMPLE_BUFFER_BIT7_QCOM 0x80000000
+#endif
+
+/*------------------------------------------------------------------------*
+ * VIV extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_VIV_shader_binary */
+#ifndef GL_VIV_shader_binary
+#define GL_SHADER_BINARY_VIV 0x8FC4
+#endif
+
+/*------------------------------------------------------------------------*
+ * End of extension tokens, start of corresponding extension functions
+ *------------------------------------------------------------------------*/
+
+/*------------------------------------------------------------------------*
+ * OES extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_OES_compressed_ETC1_RGB8_texture */
+#ifndef GL_OES_compressed_ETC1_RGB8_texture
+#define GL_OES_compressed_ETC1_RGB8_texture 1
+#endif
+
+/* GL_OES_compressed_paletted_texture */
+#ifndef GL_OES_compressed_paletted_texture
+#define GL_OES_compressed_paletted_texture 1
+#endif
+
+/* GL_OES_depth24 */
+#ifndef GL_OES_depth24
+#define GL_OES_depth24 1
+#endif
+
+/* GL_OES_depth32 */
+#ifndef GL_OES_depth32
+#define GL_OES_depth32 1
+#endif
+
+/* GL_OES_depth_texture */
+#ifndef GL_OES_depth_texture
+#define GL_OES_depth_texture 1
+#endif
+
+/* GL_OES_EGL_image */
+#ifndef GL_OES_EGL_image
+#define GL_OES_EGL_image 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image);
+GL_APICALL void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES (GLenum target, GLeglImageOES image);
+#endif
+typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image);
+typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image);
+#endif
+
+/* GL_OES_EGL_image_external */
+#ifndef GL_OES_EGL_image_external
+#define GL_OES_EGL_image_external 1
+/* glEGLImageTargetTexture2DOES defined in GL_OES_EGL_image already. */
+#endif
+
+/* GL_OES_element_index_uint */
+#ifndef GL_OES_element_index_uint
+#define GL_OES_element_index_uint 1
+#endif
+
+/* GL_OES_fbo_render_mipmap */
+#ifndef GL_OES_fbo_render_mipmap
+#define GL_OES_fbo_render_mipmap 1
+#endif
+
+/* GL_OES_fragment_precision_high */
+#ifndef GL_OES_fragment_precision_high
+#define GL_OES_fragment_precision_high 1
+#endif
+
+/* GL_OES_get_program_binary */
+#ifndef GL_OES_get_program_binary
+#define GL_OES_get_program_binary 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glGetProgramBinaryOES (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary);
+GL_APICALL void GL_APIENTRY glProgramBinaryOES (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length);
+#endif
+typedef void (GL_APIENTRYP PFNGLGETPROGRAMBINARYOESPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary);
+typedef void (GL_APIENTRYP PFNGLPROGRAMBINARYOESPROC) (GLuint program, GLenum binaryFormat, const GLvoid *binary, GLint length);
+#endif
+
+/* GL_OES_mapbuffer */
+#ifndef GL_OES_mapbuffer
+#define GL_OES_mapbuffer 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void* GL_APIENTRY glMapBufferOES (GLenum target, GLenum access);
+GL_APICALL GLboolean GL_APIENTRY glUnmapBufferOES (GLenum target);
+GL_APICALL void GL_APIENTRY glGetBufferPointervOES (GLenum target, GLenum pname, GLvoid **params);
+#endif
+typedef void* (GL_APIENTRYP PFNGLMAPBUFFEROESPROC) (GLenum target, GLenum access);
+typedef GLboolean (GL_APIENTRYP PFNGLUNMAPBUFFEROESPROC) (GLenum target);
+typedef void (GL_APIENTRYP PFNGLGETBUFFERPOINTERVOESPROC) (GLenum target, GLenum pname, GLvoid **params);
+#endif
+
+/* GL_OES_packed_depth_stencil */
+#ifndef GL_OES_packed_depth_stencil
+#define GL_OES_packed_depth_stencil 1
+#endif
+
+/* GL_OES_required_internalformat */
+#ifndef GL_OES_required_internalformat
+#define GL_OES_required_internalformat 1
+#endif
+
+/* GL_OES_rgb8_rgba8 */
+#ifndef GL_OES_rgb8_rgba8
+#define GL_OES_rgb8_rgba8 1
+#endif
+
+/* GL_OES_standard_derivatives */
+#ifndef GL_OES_standard_derivatives
+#define GL_OES_standard_derivatives 1
+#endif
+
+/* GL_OES_stencil1 */
+#ifndef GL_OES_stencil1
+#define GL_OES_stencil1 1
+#endif
+
+/* GL_OES_stencil4 */
+#ifndef GL_OES_stencil4
+#define GL_OES_stencil4 1
+#endif
+
+#ifndef GL_OES_surfaceless_context
+#define GL_OES_surfaceless_context 1
+#endif
+
+/* GL_OES_texture_3D */
+#ifndef GL_OES_texture_3D
+#define GL_OES_texture_3D 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glTexImage3DOES (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels);
+GL_APICALL void GL_APIENTRY glTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels);
+GL_APICALL void GL_APIENTRY glCopyTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glCompressedTexImage3DOES (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data);
+GL_APICALL void GL_APIENTRY glCompressedTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data);
+GL_APICALL void GL_APIENTRY glFramebufferTexture3DOES (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+#endif
+typedef void (GL_APIENTRYP PFNGLTEXIMAGE3DOESPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels);
+typedef void (GL_APIENTRYP PFNGLTEXSUBIMAGE3DOESPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels);
+typedef void (GL_APIENTRYP PFNGLCOPYTEXSUBIMAGE3DOESPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DOESPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data);
+typedef void (GL_APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DOESPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data);
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DOESPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+#endif
+
+/* GL_OES_texture_float */
+#ifndef GL_OES_texture_float
+#define GL_OES_texture_float 1
+#endif
+
+/* GL_OES_texture_float_linear */
+#ifndef GL_OES_texture_float_linear
+#define GL_OES_texture_float_linear 1
+#endif
+
+/* GL_OES_texture_half_float */
+#ifndef GL_OES_texture_half_float
+#define GL_OES_texture_half_float 1
+#endif
+
+/* GL_OES_texture_half_float_linear */
+#ifndef GL_OES_texture_half_float_linear
+#define GL_OES_texture_half_float_linear 1
+#endif
+
+/* GL_OES_texture_npot */
+#ifndef GL_OES_texture_npot
+#define GL_OES_texture_npot 1
+#endif
+
+/* GL_OES_vertex_array_object */
+#ifndef GL_OES_vertex_array_object
+#define GL_OES_vertex_array_object 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glBindVertexArrayOES (GLuint array);
+GL_APICALL void GL_APIENTRY glDeleteVertexArraysOES (GLsizei n, const GLuint *arrays);
+GL_APICALL void GL_APIENTRY glGenVertexArraysOES (GLsizei n, GLuint *arrays);
+GL_APICALL GLboolean GL_APIENTRY glIsVertexArrayOES (GLuint array);
+#endif
+typedef void (GL_APIENTRYP PFNGLBINDVERTEXARRAYOESPROC) (GLuint array);
+typedef void (GL_APIENTRYP PFNGLDELETEVERTEXARRAYSOESPROC) (GLsizei n, const GLuint *arrays);
+typedef void (GL_APIENTRYP PFNGLGENVERTEXARRAYSOESPROC) (GLsizei n, GLuint *arrays);
+typedef GLboolean (GL_APIENTRYP PFNGLISVERTEXARRAYOESPROC) (GLuint array);
+#endif
+
+/* GL_OES_vertex_half_float */
+#ifndef GL_OES_vertex_half_float
+#define GL_OES_vertex_half_float 1
+#endif
+
+/* GL_OES_vertex_type_10_10_10_2 */
+#ifndef GL_OES_vertex_type_10_10_10_2
+#define GL_OES_vertex_type_10_10_10_2 1
+#endif
+
+/*------------------------------------------------------------------------*
+ * KHR extension functions
+ *------------------------------------------------------------------------*/
+
+#ifndef GL_KHR_debug
+#define GL_KHR_debug 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDebugMessageControlKHR (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
+GL_APICALL void GL_APIENTRY glDebugMessageInsertKHR (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf);
+GL_APICALL void GL_APIENTRY glDebugMessageCallbackKHR (GLDEBUGPROCKHR callback, const void *userParam);
+GL_APICALL GLuint GL_APIENTRY glGetDebugMessageLogKHR (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog);
+GL_APICALL void GL_APIENTRY glPushDebugGroupKHR (GLenum source, GLuint id, GLsizei length, const GLchar *message);
+GL_APICALL void GL_APIENTRY glPopDebugGroupKHR (void);
+GL_APICALL void GL_APIENTRY glObjectLabelKHR (GLenum identifier, GLuint name, GLsizei length, const GLchar *label);
+GL_APICALL void GL_APIENTRY glGetObjectLabelKHR (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label);
+GL_APICALL void GL_APIENTRY glObjectPtrLabelKHR (const void *ptr, GLsizei length, const GLchar *label);
+GL_APICALL void GL_APIENTRY glGetObjectPtrLabelKHR (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label);
+GL_APICALL void GL_APIENTRY glGetPointervKHR (GLenum pname, GLvoid **params);
+#endif
+typedef void (GL_APIENTRYP PFNGLDEBUGMESSAGECONTROLKHRPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
+typedef void (GL_APIENTRYP PFNGLDEBUGMESSAGEINSERTKHRPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf);
+typedef void (GL_APIENTRYP PFNGLDEBUGMESSAGECALLBACKKHRPROC) (GLDEBUGPROCKHR callback, const void *userParam);
+typedef GLuint (GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC) (GLuint count, GLsizei bufsize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog);
+typedef void (GL_APIENTRYP PFNGLPUSHDEBUGGROUPKHRPROC) (GLenum source, GLuint id, GLsizei length, const GLchar *message);
+typedef void (GL_APIENTRYP PFNGLPOPDEBUGGROUPKHRPROC) (void);
+typedef void (GL_APIENTRYP PFNGLOBJECTLABELKHRPROC) (GLenum identifier, GLuint name, GLsizei length, const GLchar *label);
+typedef void (GL_APIENTRYP PFNGLGETOBJECTLABELKHRPROC) (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label);
+typedef void (GL_APIENTRYP PFNGLOBJECTPTRLABELKHRPROC) (const void *ptr, GLsizei length, const GLchar *label);
+typedef void (GL_APIENTRYP PFNGLGETOBJECTPTRLABELKHRPROC) (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label);
+typedef void (GL_APIENTRYP PFNGLGETPOINTERVKHRPROC) (GLenum pname, GLvoid **params);
+#endif
+
+#ifndef GL_KHR_texture_compression_astc_ldr
+#define GL_KHR_texture_compression_astc_ldr 1
+#endif
+
+
+/*------------------------------------------------------------------------*
+ * AMD extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_AMD_compressed_3DC_texture */
+#ifndef GL_AMD_compressed_3DC_texture
+#define GL_AMD_compressed_3DC_texture 1
+#endif
+
+/* GL_AMD_compressed_ATC_texture */
+#ifndef GL_AMD_compressed_ATC_texture
+#define GL_AMD_compressed_ATC_texture 1
+#endif
+
+/* AMD_performance_monitor */
+#ifndef GL_AMD_performance_monitor
+#define GL_AMD_performance_monitor 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glGetPerfMonitorGroupsAMD (GLint *numGroups, GLsizei groupsSize, GLuint *groups);
+GL_APICALL void GL_APIENTRY glGetPerfMonitorCountersAMD (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters);
+GL_APICALL void GL_APIENTRY glGetPerfMonitorGroupStringAMD (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString);
+GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterStringAMD (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString);
+GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterInfoAMD (GLuint group, GLuint counter, GLenum pname, GLvoid *data);
+GL_APICALL void GL_APIENTRY glGenPerfMonitorsAMD (GLsizei n, GLuint *monitors);
+GL_APICALL void GL_APIENTRY glDeletePerfMonitorsAMD (GLsizei n, GLuint *monitors);
+GL_APICALL void GL_APIENTRY glSelectPerfMonitorCountersAMD (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *countersList);
+GL_APICALL void GL_APIENTRY glBeginPerfMonitorAMD (GLuint monitor);
+GL_APICALL void GL_APIENTRY glEndPerfMonitorAMD (GLuint monitor);
+GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterDataAMD (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten);
+#endif
+typedef void (GL_APIENTRYP PFNGLGETPERFMONITORGROUPSAMDPROC) (GLint *numGroups, GLsizei groupsSize, GLuint *groups);
+typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERSAMDPROC) (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters);
+typedef void (GL_APIENTRYP PFNGLGETPERFMONITORGROUPSTRINGAMDPROC) (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString);
+typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERSTRINGAMDPROC) (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString);
+typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERINFOAMDPROC) (GLuint group, GLuint counter, GLenum pname, GLvoid *data);
+typedef void (GL_APIENTRYP PFNGLGENPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors);
+typedef void (GL_APIENTRYP PFNGLDELETEPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors);
+typedef void (GL_APIENTRYP PFNGLSELECTPERFMONITORCOUNTERSAMDPROC) (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *countersList);
+typedef void (GL_APIENTRYP PFNGLBEGINPERFMONITORAMDPROC) (GLuint monitor);
+typedef void (GL_APIENTRYP PFNGLENDPERFMONITORAMDPROC) (GLuint monitor);
+typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERDATAAMDPROC) (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten);
+#endif
+
+/* GL_AMD_program_binary_Z400 */
+#ifndef GL_AMD_program_binary_Z400
+#define GL_AMD_program_binary_Z400 1
+#endif
+
+/*------------------------------------------------------------------------*
+ * ANGLE extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_ANGLE_depth_texture */
+#ifndef GL_ANGLE_depth_texture
+#define GL_ANGLE_depth_texture 1
+#endif
+
+/* GL_ANGLE_framebuffer_blit */
+#ifndef GL_ANGLE_framebuffer_blit
+#define GL_ANGLE_framebuffer_blit 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glBlitFramebufferANGLE (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+#endif
+typedef void (GL_APIENTRYP PFNGLBLITFRAMEBUFFERANGLEPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+#endif
+
+/* GL_ANGLE_framebuffer_multisample */
+#ifndef GL_ANGLE_framebuffer_multisample
+#define GL_ANGLE_framebuffer_multisample 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleANGLE (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+#endif
+typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEANGLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+#endif
+
+#ifndef GL_ANGLE_instanced_arrays
+#define GL_ANGLE_instanced_arrays 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDrawArraysInstancedANGLE (GLenum mode, GLint first, GLsizei count, GLsizei primcount);
+GL_APICALL void GL_APIENTRY glDrawElementsInstancedANGLE (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
+GL_APICALL void GL_APIENTRY glVertexAttribDivisorANGLE (GLuint index, GLuint divisor);
+#endif
+typedef void (GL_APIENTRYP PFNGLDRAWARRAYSINSTANCEDANGLEPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount);
+typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSINSTANCEDANGLEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
+typedef void (GL_APIENTRYP PFNGLVERTEXATTRIBDIVISORANGLEPROC) (GLuint index, GLuint divisor);
+#endif
+
+/* GL_ANGLE_pack_reverse_row_order */
+#ifndef GL_ANGLE_pack_reverse_row_order
+#define GL_ANGLE_pack_reverse_row_order 1
+#endif
+
+/* GL_ANGLE_program_binary */
+#ifndef GL_ANGLE_program_binary
+#define GL_ANGLE_program_binary 1
+#endif
+
+/* GL_ANGLE_texture_compression_dxt3 */
+#ifndef GL_ANGLE_texture_compression_dxt3
+#define GL_ANGLE_texture_compression_dxt3 1
+#endif
+
+/* GL_ANGLE_texture_compression_dxt5 */
+#ifndef GL_ANGLE_texture_compression_dxt5
+#define GL_ANGLE_texture_compression_dxt5 1
+#endif
+
+/* GL_ANGLE_texture_usage */
+#ifndef GL_ANGLE_texture_usage
+#define GL_ANGLE_texture_usage 1
+#endif
+
+#ifndef GL_ANGLE_translated_shader_source
+#define GL_ANGLE_translated_shader_source 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glGetTranslatedShaderSourceANGLE (GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source);
+#endif
+typedef void (GL_APIENTRYP PFNGLGETTRANSLATEDSHADERSOURCEANGLEPROC) (GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source);
+#endif
+
+/*------------------------------------------------------------------------*
+ * APPLE extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_APPLE_copy_texture_levels */
+#ifndef GL_APPLE_copy_texture_levels
+#define GL_APPLE_copy_texture_levels 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glCopyTextureLevelsAPPLE (GLuint destinationTexture, GLuint sourceTexture, GLint sourceBaseLevel, GLsizei sourceLevelCount);
+#endif
+typedef void (GL_APIENTRYP PFNGLCOPYTEXTURELEVELSAPPLEPROC) (GLuint destinationTexture, GLuint sourceTexture, GLint sourceBaseLevel, GLsizei sourceLevelCount);
+#endif
+
+/* GL_APPLE_framebuffer_multisample */
+#ifndef GL_APPLE_framebuffer_multisample
+#define GL_APPLE_framebuffer_multisample 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleAPPLE (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glResolveMultisampleFramebufferAPPLE (void);
+#endif /* GL_GLEXT_PROTOTYPES */
+typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEAPPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLRESOLVEMULTISAMPLEFRAMEBUFFERAPPLEPROC) (void);
+#endif
+
+/* GL_APPLE_rgb_422 */
+#ifndef GL_APPLE_rgb_422
+#define GL_APPLE_rgb_422 1
+#endif
+
+/* GL_APPLE_sync */
+#ifndef GL_APPLE_sync
+#define GL_APPLE_sync 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL GLsync GL_APIENTRY glFenceSyncAPPLE (GLenum condition, GLbitfield flags);
+GL_APICALL GLboolean GL_APIENTRY glIsSyncAPPLE (GLsync sync);
+GL_APICALL void GL_APIENTRY glDeleteSyncAPPLE (GLsync sync);
+GL_APICALL GLenum GL_APIENTRY glClientWaitSyncAPPLE (GLsync sync, GLbitfield flags, GLuint64 timeout);
+GL_APICALL void GL_APIENTRY glWaitSyncAPPLE (GLsync sync, GLbitfield flags, GLuint64 timeout);
+GL_APICALL void GL_APIENTRY glGetInteger64vAPPLE (GLenum pname, GLint64 *params);
+GL_APICALL void GL_APIENTRY glGetSyncivAPPLE (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values);
+#endif
+typedef GLsync (GL_APIENTRYP PFNGLFENCESYNCAPPLEPROC) (GLenum condition, GLbitfield flags);
+typedef GLboolean (GL_APIENTRYP PFNGLISSYNCAPPLEPROC) (GLsync sync);
+typedef void (GL_APIENTRYP PFNGLDELETESYNCAPPLEPROC) (GLsync sync);
+typedef GLenum (GL_APIENTRYP PFNGLCLIENTWAITSYNCAPPLEPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout);
+typedef void (GL_APIENTRYP PFNGLWAITSYNCAPPLEPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout);
+typedef void (GL_APIENTRYP PFNGLGETINTEGER64VAPPLEPROC) (GLenum pname, GLint64 *params);
+typedef void (GL_APIENTRYP PFNGLGETSYNCIVAPPLEPROC) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values);
+#endif
+
+/* GL_APPLE_texture_format_BGRA8888 */
+#ifndef GL_APPLE_texture_format_BGRA8888
+#define GL_APPLE_texture_format_BGRA8888 1
+#endif
+
+/* GL_APPLE_texture_max_level */
+#ifndef GL_APPLE_texture_max_level
+#define GL_APPLE_texture_max_level 1
+#endif
+
+/*------------------------------------------------------------------------*
+ * ARM extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_ARM_mali_program_binary */
+#ifndef GL_ARM_mali_program_binary
+#define GL_ARM_mali_program_binary 1
+#endif
+
+/* GL_ARM_mali_shader_binary */
+#ifndef GL_ARM_mali_shader_binary
+#define GL_ARM_mali_shader_binary 1
+#endif
+
+/* GL_ARM_rgba8 */
+#ifndef GL_ARM_rgba8
+#define GL_ARM_rgba8 1
+#endif
+
+/*------------------------------------------------------------------------*
+ * EXT extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_EXT_blend_minmax */
+#ifndef GL_EXT_blend_minmax
+#define GL_EXT_blend_minmax 1
+#endif
+
+/* GL_EXT_color_buffer_half_float */
+#ifndef GL_EXT_color_buffer_half_float
+#define GL_EXT_color_buffer_half_float 1
+#endif
+
+/* GL_EXT_debug_label */
+#ifndef GL_EXT_debug_label
+#define GL_EXT_debug_label 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glLabelObjectEXT (GLenum type, GLuint object, GLsizei length, const GLchar *label);
+GL_APICALL void GL_APIENTRY glGetObjectLabelEXT (GLenum type, GLuint object, GLsizei bufSize, GLsizei *length, GLchar *label);
+#endif
+typedef void (GL_APIENTRYP PFNGLLABELOBJECTEXTPROC) (GLenum type, GLuint object, GLsizei length, const GLchar *label);
+typedef void (GL_APIENTRYP PFNGLGETOBJECTLABELEXTPROC) (GLenum type, GLuint object, GLsizei bufSize, GLsizei *length, GLchar *label);
+#endif
+
+/* GL_EXT_debug_marker */
+#ifndef GL_EXT_debug_marker
+#define GL_EXT_debug_marker 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glInsertEventMarkerEXT (GLsizei length, const GLchar *marker);
+GL_APICALL void GL_APIENTRY glPushGroupMarkerEXT (GLsizei length, const GLchar *marker);
+GL_APICALL void GL_APIENTRY glPopGroupMarkerEXT (void);
+#endif
+typedef void (GL_APIENTRYP PFNGLINSERTEVENTMARKEREXTPROC) (GLsizei length, const GLchar *marker);
+typedef void (GL_APIENTRYP PFNGLPUSHGROUPMARKEREXTPROC) (GLsizei length, const GLchar *marker);
+typedef void (GL_APIENTRYP PFNGLPOPGROUPMARKEREXTPROC) (void);
+#endif
+
+/* GL_EXT_discard_framebuffer */
+#ifndef GL_EXT_discard_framebuffer
+#define GL_EXT_discard_framebuffer 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDiscardFramebufferEXT (GLenum target, GLsizei numAttachments, const GLenum *attachments);
+#endif
+typedef void (GL_APIENTRYP PFNGLDISCARDFRAMEBUFFEREXTPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments);
+#endif
+
+#ifndef GL_EXT_disjoint_timer_query
+#define GL_EXT_disjoint_timer_query 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glGenQueriesEXT (GLsizei n, GLuint *ids);
+GL_APICALL void GL_APIENTRY glDeleteQueriesEXT (GLsizei n, const GLuint *ids);
+GL_APICALL GLboolean GL_APIENTRY glIsQueryEXT (GLuint id);
+GL_APICALL void GL_APIENTRY glBeginQueryEXT (GLenum target, GLuint id);
+GL_APICALL void GL_APIENTRY glEndQueryEXT (GLenum target);
+GL_APICALL void GL_APIENTRY glQueryCounterEXT (GLuint id, GLenum target);
+GL_APICALL void GL_APIENTRY glGetQueryivEXT (GLenum target, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glGetQueryObjectivEXT (GLuint id, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glGetQueryObjectuivEXT (GLuint id, GLenum pname, GLuint *params);
+GL_APICALL void GL_APIENTRY glGetQueryObjecti64vEXT (GLuint id, GLenum pname, GLint64 *params);
+GL_APICALL void GL_APIENTRY glGetQueryObjectui64vEXT (GLuint id, GLenum pname, GLuint64 *params);
+#endif
+typedef void (GL_APIENTRYP PFNGLGENQUERIESEXTPROC) (GLsizei n, GLuint *ids);
+typedef void (GL_APIENTRYP PFNGLDELETEQUERIESEXTPROC) (GLsizei n, const GLuint *ids);
+typedef GLboolean (GL_APIENTRYP PFNGLISQUERYEXTPROC) (GLuint id);
+typedef void (GL_APIENTRYP PFNGLBEGINQUERYEXTPROC) (GLenum target, GLuint id);
+typedef void (GL_APIENTRYP PFNGLENDQUERYEXTPROC) (GLenum target);
+typedef void (GL_APIENTRYP PFNGLQUERYCOUNTEREXTPROC) (GLuint id, GLenum target);
+typedef void (GL_APIENTRYP PFNGLGETQUERYIVEXTPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLGETQUERYOBJECTIVEXTPROC) (GLuint id, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLGETQUERYOBJECTUIVEXTPROC) (GLuint id, GLenum pname, GLuint *params);
+typedef void (GL_APIENTRYP PFNGLGETQUERYOBJECTI64VEXTPROC) (GLuint id, GLenum pname, GLint64 *params);
+typedef void (GL_APIENTRYP PFNGLGETQUERYOBJECTUI64VEXTPROC) (GLuint id, GLenum pname, GLuint64 *params);
+#endif /* GL_EXT_disjoint_timer_query */
+
+#ifndef GL_EXT_draw_buffers
+#define GL_EXT_draw_buffers 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDrawBuffersEXT (GLsizei n, const GLenum *bufs);
+#endif
+typedef void (GL_APIENTRYP PFNGLDRAWBUFFERSEXTPROC) (GLsizei n, const GLenum *bufs);
+#endif /* GL_EXT_draw_buffers */
+
+/* GL_EXT_map_buffer_range */
+#ifndef GL_EXT_map_buffer_range
+#define GL_EXT_map_buffer_range 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void* GL_APIENTRY glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access);
+GL_APICALL void GL_APIENTRY glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length);
+#endif
+typedef void* (GL_APIENTRYP PFNGLMAPBUFFERRANGEEXTPROC) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access);
+typedef void (GL_APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEEXTPROC) (GLenum target, GLintptr offset, GLsizeiptr length);
+#endif
+
+/* GL_EXT_multisampled_render_to_texture */
+#ifndef GL_EXT_multisampled_render_to_texture
+#define GL_EXT_multisampled_render_to_texture 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleEXT (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glFramebufferTexture2DMultisampleEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples);
+#endif
+typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples);
+#endif
+
+/* GL_EXT_multiview_draw_buffers */
+#ifndef GL_EXT_multiview_draw_buffers
+#define GL_EXT_multiview_draw_buffers 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glReadBufferIndexedEXT (GLenum src, GLint index);
+GL_APICALL void GL_APIENTRY glDrawBuffersIndexedEXT (GLint n, const GLenum *location, const GLint *indices);
+GL_APICALL void GL_APIENTRY glGetIntegeri_vEXT (GLenum target, GLuint index, GLint *data);
+#endif
+typedef void (GL_APIENTRYP PFNGLREADBUFFERINDEXEDEXTPROC) (GLenum src, GLint index);
+typedef void (GL_APIENTRYP PFNGLDRAWBUFFERSINDEXEDEXTPROC) (GLint n, const GLenum *location, const GLint *indices);
+typedef void (GL_APIENTRYP PFNGLGETINTEGERI_VEXTPROC) (GLenum target, GLuint index, GLint *data);
+#endif
+
+#ifndef GL_EXT_multi_draw_arrays
+#define GL_EXT_multi_draw_arrays 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glMultiDrawArraysEXT (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount);
+GL_APICALL void GL_APIENTRY glMultiDrawElementsEXT (GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount);
+#endif /* GL_GLEXT_PROTOTYPES */
+typedef void (GL_APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount);
+typedef void (GL_APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount);
+#endif
+
+/* GL_EXT_occlusion_query_boolean */
+#ifndef GL_EXT_occlusion_query_boolean
+#define GL_EXT_occlusion_query_boolean 1
+/* All entry points also exist in GL_EXT_disjoint_timer_query */
+#endif
+
+/* GL_EXT_read_format_bgra */
+#ifndef GL_EXT_read_format_bgra
+#define GL_EXT_read_format_bgra 1
+#endif
+
+/* GL_EXT_robustness */
+#ifndef GL_EXT_robustness
+#define GL_EXT_robustness 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL GLenum GL_APIENTRY glGetGraphicsResetStatusEXT (void);
+GL_APICALL void GL_APIENTRY glReadnPixelsEXT (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid *data);
+GL_APICALL void GL_APIENTRY glGetnUniformfvEXT (GLuint program, GLint location, GLsizei bufSize, GLfloat *params);
+GL_APICALL void GL_APIENTRY glGetnUniformivEXT (GLuint program, GLint location, GLsizei bufSize, GLint *params);
+#endif
+typedef GLenum (GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSEXTPROC) (void);
+typedef void (GL_APIENTRYP PFNGLREADNPIXELSEXTPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, GLvoid *data);
+typedef void (GL_APIENTRYP PFNGLGETNUNIFORMFVEXTPROC) (GLuint program, GLint location, GLsizei bufSize, GLfloat *params);
+typedef void (GL_APIENTRYP PFNGLGETNUNIFORMIVEXTPROC) (GLuint program, GLint location, GLsizei bufSize, GLint *params);
+#endif
+
+/* GL_EXT_separate_shader_objects */
+#ifndef GL_EXT_separate_shader_objects
+#define GL_EXT_separate_shader_objects 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glUseProgramStagesEXT (GLuint pipeline, GLbitfield stages, GLuint program);
+GL_APICALL void GL_APIENTRY glActiveShaderProgramEXT (GLuint pipeline, GLuint program);
+GL_APICALL GLuint GL_APIENTRY glCreateShaderProgramvEXT (GLenum type, GLsizei count, const GLchar **strings);
+GL_APICALL void GL_APIENTRY glBindProgramPipelineEXT (GLuint pipeline);
+GL_APICALL void GL_APIENTRY glDeleteProgramPipelinesEXT (GLsizei n, const GLuint *pipelines);
+GL_APICALL void GL_APIENTRY glGenProgramPipelinesEXT (GLsizei n, GLuint *pipelines);
+GL_APICALL GLboolean GL_APIENTRY glIsProgramPipelineEXT (GLuint pipeline);
+GL_APICALL void GL_APIENTRY glProgramParameteriEXT (GLuint program, GLenum pname, GLint value);
+GL_APICALL void GL_APIENTRY glGetProgramPipelineivEXT (GLuint pipeline, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glProgramUniform1iEXT (GLuint program, GLint location, GLint x);
+GL_APICALL void GL_APIENTRY glProgramUniform2iEXT (GLuint program, GLint location, GLint x, GLint y);
+GL_APICALL void GL_APIENTRY glProgramUniform3iEXT (GLuint program, GLint location, GLint x, GLint y, GLint z);
+GL_APICALL void GL_APIENTRY glProgramUniform4iEXT (GLuint program, GLint location, GLint x, GLint y, GLint z, GLint w);
+GL_APICALL void GL_APIENTRY glProgramUniform1fEXT (GLuint program, GLint location, GLfloat x);
+GL_APICALL void GL_APIENTRY glProgramUniform2fEXT (GLuint program, GLint location, GLfloat x, GLfloat y);
+GL_APICALL void GL_APIENTRY glProgramUniform3fEXT (GLuint program, GLint location, GLfloat x, GLfloat y, GLfloat z);
+GL_APICALL void GL_APIENTRY glProgramUniform4fEXT (GLuint program, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GL_APICALL void GL_APIENTRY glProgramUniform1ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GL_APICALL void GL_APIENTRY glProgramUniform2ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GL_APICALL void GL_APIENTRY glProgramUniform3ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GL_APICALL void GL_APIENTRY glProgramUniform4ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GL_APICALL void GL_APIENTRY glProgramUniform1fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniform2fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniform3fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniform4fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniformMatrix2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniformMatrix3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniformMatrix4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glValidateProgramPipelineEXT (GLuint pipeline);
+GL_APICALL void GL_APIENTRY glGetProgramPipelineInfoLogEXT (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+#endif
+typedef void (GL_APIENTRYP PFNGLUSEPROGRAMSTAGESEXTPROC) (GLuint pipeline, GLbitfield stages, GLuint program);
+typedef void (GL_APIENTRYP PFNGLACTIVESHADERPROGRAMEXTPROC) (GLuint pipeline, GLuint program);
+typedef GLuint (GL_APIENTRYP PFNGLCREATESHADERPROGRAMVEXTPROC) (GLenum type, GLsizei count, const GLchar **strings);
+typedef void (GL_APIENTRYP PFNGLBINDPROGRAMPIPELINEEXTPROC) (GLuint pipeline);
+typedef void (GL_APIENTRYP PFNGLDELETEPROGRAMPIPELINESEXTPROC) (GLsizei n, const GLuint *pipelines);
+typedef void (GL_APIENTRYP PFNGLGENPROGRAMPIPELINESEXTPROC) (GLsizei n, GLuint *pipelines);
+typedef GLboolean (GL_APIENTRYP PFNGLISPROGRAMPIPELINEEXTPROC) (GLuint pipeline);
+typedef void (GL_APIENTRYP PFNGLPROGRAMPARAMETERIEXTPROC) (GLuint program, GLenum pname, GLint value);
+typedef void (GL_APIENTRYP PFNGLGETPROGRAMPIPELINEIVEXTPROC) (GLuint pipeline, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1IEXTPROC) (GLuint program, GLint location, GLint x);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2IEXTPROC) (GLuint program, GLint location, GLint x, GLint y);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3IEXTPROC) (GLuint program, GLint location, GLint x, GLint y, GLint z);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4IEXTPROC) (GLuint program, GLint location, GLint x, GLint y, GLint z, GLint w);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1FEXTPROC) (GLuint program, GLint location, GLfloat x);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2FEXTPROC) (GLuint program, GLint location, GLfloat x, GLfloat y);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3FEXTPROC) (GLuint program, GLint location, GLfloat x, GLfloat y, GLfloat z);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4FEXTPROC) (GLuint program, GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLVALIDATEPROGRAMPIPELINEEXTPROC) (GLuint pipeline);
+typedef void (GL_APIENTRYP PFNGLGETPROGRAMPIPELINEINFOLOGEXTPROC) (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+#endif
+
+/* GL_EXT_shader_framebuffer_fetch */
+#ifndef GL_EXT_shader_framebuffer_fetch
+#define GL_EXT_shader_framebuffer_fetch 1
+#endif
+
+/* GL_EXT_shader_texture_lod */
+#ifndef GL_EXT_shader_texture_lod
+#define GL_EXT_shader_texture_lod 1
+#endif
+
+/* GL_EXT_shadow_samplers */
+#ifndef GL_EXT_shadow_samplers
+#define GL_EXT_shadow_samplers 1
+#endif
+
+/* GL_EXT_sRGB */
+#ifndef GL_EXT_sRGB
+#define GL_EXT_sRGB 1
+#endif
+
+/* GL_EXT_texture_compression_dxt1 */
+#ifndef GL_EXT_texture_compression_dxt1
+#define GL_EXT_texture_compression_dxt1 1
+#endif
+
+/* GL_EXT_texture_filter_anisotropic */
+#ifndef GL_EXT_texture_filter_anisotropic
+#define GL_EXT_texture_filter_anisotropic 1
+#endif
+
+/* GL_EXT_texture_format_BGRA8888 */
+#ifndef GL_EXT_texture_format_BGRA8888
+#define GL_EXT_texture_format_BGRA8888 1
+#endif
+
+/* GL_EXT_texture_rg */
+#ifndef GL_EXT_texture_rg
+#define GL_EXT_texture_rg 1
+#endif
+
+/* GL_EXT_texture_storage */
+#ifndef GL_EXT_texture_storage
+#define GL_EXT_texture_storage 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glTexStorage1DEXT (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+GL_APICALL void GL_APIENTRY glTexStorage2DEXT (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glTexStorage3DEXT (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+GL_APICALL void GL_APIENTRY glTextureStorage1DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+GL_APICALL void GL_APIENTRY glTextureStorage2DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glTextureStorage3DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+#endif
+typedef void (GL_APIENTRYP PFNGLTEXSTORAGE1DEXTPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+typedef void (GL_APIENTRYP PFNGLTEXSTORAGE2DEXTPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLTEXSTORAGE3DEXTPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGE1DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGE2DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGE3DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+#endif
+
+/* GL_EXT_texture_type_2_10_10_10_REV */
+#ifndef GL_EXT_texture_type_2_10_10_10_REV
+#define GL_EXT_texture_type_2_10_10_10_REV 1
+#endif
+
+/* GL_EXT_unpack_subimage */
+#ifndef GL_EXT_unpack_subimage
+#define GL_EXT_unpack_subimage 1
+#endif
+
+/*------------------------------------------------------------------------*
+ * DMP extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_DMP_shader_binary */
+#ifndef GL_DMP_shader_binary
+#define GL_DMP_shader_binary 1
+#endif
+
+/*------------------------------------------------------------------------*
+ * FJ extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_FJ_shader_binary_GCCSO */
+#ifndef GL_FJ_shader_binary_GCCSO
+#define GL_FJ_shader_binary_GCCSO 1
+#endif
+
+/*------------------------------------------------------------------------*
+ * IMG extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_IMG_program_binary */
+#ifndef GL_IMG_program_binary
+#define GL_IMG_program_binary 1
+#endif
+
+/* GL_IMG_read_format */
+#ifndef GL_IMG_read_format
+#define GL_IMG_read_format 1
+#endif
+
+/* GL_IMG_shader_binary */
+#ifndef GL_IMG_shader_binary
+#define GL_IMG_shader_binary 1
+#endif
+
+/* GL_IMG_texture_compression_pvrtc */
+#ifndef GL_IMG_texture_compression_pvrtc
+#define GL_IMG_texture_compression_pvrtc 1
+#endif
+
+/* GL_IMG_texture_compression_pvrtc2 */
+#ifndef GL_IMG_texture_compression_pvrtc2
+#define GL_IMG_texture_compression_pvrtc2 1
+#endif
+
+/* GL_IMG_multisampled_render_to_texture */
+#ifndef GL_IMG_multisampled_render_to_texture
+#define GL_IMG_multisampled_render_to_texture 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleIMG (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glFramebufferTexture2DMultisampleIMG (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples);
+#endif
+typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMGPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMGPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples);
+#endif
+
+/*------------------------------------------------------------------------*
+ * NV extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_NV_coverage_sample */
+#ifndef GL_NV_coverage_sample
+#define GL_NV_coverage_sample 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glCoverageMaskNV (GLboolean mask);
+GL_APICALL void GL_APIENTRY glCoverageOperationNV (GLenum operation);
+#endif
+typedef void (GL_APIENTRYP PFNGLCOVERAGEMASKNVPROC) (GLboolean mask);
+typedef void (GL_APIENTRYP PFNGLCOVERAGEOPERATIONNVPROC) (GLenum operation);
+#endif
+
+/* GL_NV_depth_nonlinear */
+#ifndef GL_NV_depth_nonlinear
+#define GL_NV_depth_nonlinear 1
+#endif
+
+/* GL_NV_draw_buffers */
+#ifndef GL_NV_draw_buffers
+#define GL_NV_draw_buffers 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDrawBuffersNV (GLsizei n, const GLenum *bufs);
+#endif
+typedef void (GL_APIENTRYP PFNGLDRAWBUFFERSNVPROC) (GLsizei n, const GLenum *bufs);
+#endif
+
+/* GL_NV_draw_instanced */
+#ifndef GL_NV_draw_instanced
+#define GL_NV_draw_instanced 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDrawArraysInstancedNV (GLenum mode, GLint first, GLsizei count, GLsizei primcount);
+GL_APICALL void GL_APIENTRY glDrawElementsInstancedNV (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount);
+#endif
+typedef void (GL_APIENTRYP PFNGLDRAWARRAYSINSTANCEDNVPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount);
+typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSINSTANCEDNVPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount);
+#endif
+
+/* GL_NV_fbo_color_attachments */
+#ifndef GL_NV_fbo_color_attachments
+#define GL_NV_fbo_color_attachments 1
+#endif
+
+/* GL_NV_fence */
+#ifndef GL_NV_fence
+#define GL_NV_fence 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDeleteFencesNV (GLsizei n, const GLuint *fences);
+GL_APICALL void GL_APIENTRY glGenFencesNV (GLsizei n, GLuint *fences);
+GL_APICALL GLboolean GL_APIENTRY glIsFenceNV (GLuint fence);
+GL_APICALL GLboolean GL_APIENTRY glTestFenceNV (GLuint fence);
+GL_APICALL void GL_APIENTRY glGetFenceivNV (GLuint fence, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glFinishFenceNV (GLuint fence);
+GL_APICALL void GL_APIENTRY glSetFenceNV (GLuint fence, GLenum condition);
+#endif
+typedef void (GL_APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences);
+typedef void (GL_APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences);
+typedef GLboolean (GL_APIENTRYP PFNGLISFENCENVPROC) (GLuint fence);
+typedef GLboolean (GL_APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence);
+typedef void (GL_APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence);
+typedef void (GL_APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition);
+#endif
+
+/* GL_NV_framebuffer_blit */
+#ifndef GL_NV_framebuffer_blit
+#define GL_NV_framebuffer_blit 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glBlitFramebufferNV (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+#endif
+typedef void (GL_APIENTRYP PFNGLBLITFRAMEBUFFERNVPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+#endif
+
+/* GL_NV_framebuffer_multisample */
+#ifndef GL_NV_framebuffer_multisample
+#define GL_NV_framebuffer_multisample 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleNV ( GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+#endif
+typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLENVPROC) ( GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+#endif
+
+/* GL_NV_generate_mipmap_sRGB */
+#ifndef GL_NV_generate_mipmap_sRGB
+#define GL_NV_generate_mipmap_sRGB 1
+#endif
+
+/* GL_NV_instanced_arrays */
+#ifndef GL_NV_instanced_arrays
+#define GL_NV_instanced_arrays 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glVertexAttribDivisorNV (GLuint index, GLuint divisor);
+#endif
+typedef void (GL_APIENTRYP PFNGLVERTEXATTRIBDIVISORNVPROC) (GLuint index, GLuint divisor);
+#endif
+
+/* GL_NV_read_buffer */
+#ifndef GL_NV_read_buffer
+#define GL_NV_read_buffer 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glReadBufferNV (GLenum mode);
+#endif
+typedef void (GL_APIENTRYP PFNGLREADBUFFERNVPROC) (GLenum mode);
+#endif
+
+/* GL_NV_read_buffer_front */
+#ifndef GL_NV_read_buffer_front
+#define GL_NV_read_buffer_front 1
+#endif
+
+/* GL_NV_read_depth */
+#ifndef GL_NV_read_depth
+#define GL_NV_read_depth 1
+#endif
+
+/* GL_NV_read_depth_stencil */
+#ifndef GL_NV_read_depth_stencil
+#define GL_NV_read_depth_stencil 1
+#endif
+
+/* GL_NV_read_stencil */
+#ifndef GL_NV_read_stencil
+#define GL_NV_read_stencil 1
+#endif
+
+/* GL_NV_shadow_samplers_array */
+#ifndef GL_NV_shadow_samplers_array
+#define GL_NV_shadow_samplers_array 1
+#endif
+
+/* GL_NV_shadow_samplers_cube */
+#ifndef GL_NV_shadow_samplers_cube
+#define GL_NV_shadow_samplers_cube 1
+#endif
+
+/* GL_NV_sRGB_formats */
+#ifndef GL_NV_sRGB_formats
+#define GL_NV_sRGB_formats 1
+#endif
+
+/* GL_NV_texture_border_clamp */
+#ifndef GL_NV_texture_border_clamp
+#define GL_NV_texture_border_clamp 1
+#endif
+
+/* GL_NV_texture_compression_s3tc_update */
+#ifndef GL_NV_texture_compression_s3tc_update
+#define GL_NV_texture_compression_s3tc_update 1
+#endif
+
+/* GL_NV_texture_npot_2D_mipmap */
+#ifndef GL_NV_texture_npot_2D_mipmap
+#define GL_NV_texture_npot_2D_mipmap 1
+#endif
+
+/*------------------------------------------------------------------------*
+ * QCOM extension functions
+ *------------------------------------------------------------------------*/
+
+/* GL_QCOM_alpha_test */
+#ifndef GL_QCOM_alpha_test
+#define GL_QCOM_alpha_test 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glAlphaFuncQCOM (GLenum func, GLclampf ref);
+#endif
+typedef void (GL_APIENTRYP PFNGLALPHAFUNCQCOMPROC) (GLenum func, GLclampf ref);
+#endif
+
+/* GL_QCOM_binning_control */
+#ifndef GL_QCOM_binning_control
+#define GL_QCOM_binning_control 1
+#endif
+
+/* GL_QCOM_driver_control */
+#ifndef GL_QCOM_driver_control
+#define GL_QCOM_driver_control 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glGetDriverControlsQCOM (GLint *num, GLsizei size, GLuint *driverControls);
+GL_APICALL void GL_APIENTRY glGetDriverControlStringQCOM (GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString);
+GL_APICALL void GL_APIENTRY glEnableDriverControlQCOM (GLuint driverControl);
+GL_APICALL void GL_APIENTRY glDisableDriverControlQCOM (GLuint driverControl);
+#endif
+typedef void (GL_APIENTRYP PFNGLGETDRIVERCONTROLSQCOMPROC) (GLint *num, GLsizei size, GLuint *driverControls);
+typedef void (GL_APIENTRYP PFNGLGETDRIVERCONTROLSTRINGQCOMPROC) (GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString);
+typedef void (GL_APIENTRYP PFNGLENABLEDRIVERCONTROLQCOMPROC) (GLuint driverControl);
+typedef void (GL_APIENTRYP PFNGLDISABLEDRIVERCONTROLQCOMPROC) (GLuint driverControl);
+#endif
+
+/* GL_QCOM_extended_get */
+#ifndef GL_QCOM_extended_get
+#define GL_QCOM_extended_get 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glExtGetTexturesQCOM (GLuint *textures, GLint maxTextures, GLint *numTextures);
+GL_APICALL void GL_APIENTRY glExtGetBuffersQCOM (GLuint *buffers, GLint maxBuffers, GLint *numBuffers);
+GL_APICALL void GL_APIENTRY glExtGetRenderbuffersQCOM (GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers);
+GL_APICALL void GL_APIENTRY glExtGetFramebuffersQCOM (GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers);
+GL_APICALL void GL_APIENTRY glExtGetTexLevelParameterivQCOM (GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glExtTexObjectStateOverrideiQCOM (GLenum target, GLenum pname, GLint param);
+GL_APICALL void GL_APIENTRY glExtGetTexSubImageQCOM (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels);
+GL_APICALL void GL_APIENTRY glExtGetBufferPointervQCOM (GLenum target, GLvoid **params);
+#endif
+typedef void (GL_APIENTRYP PFNGLEXTGETTEXTURESQCOMPROC) (GLuint *textures, GLint maxTextures, GLint *numTextures);
+typedef void (GL_APIENTRYP PFNGLEXTGETBUFFERSQCOMPROC) (GLuint *buffers, GLint maxBuffers, GLint *numBuffers);
+typedef void (GL_APIENTRYP PFNGLEXTGETRENDERBUFFERSQCOMPROC) (GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers);
+typedef void (GL_APIENTRYP PFNGLEXTGETFRAMEBUFFERSQCOMPROC) (GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers);
+typedef void (GL_APIENTRYP PFNGLEXTGETTEXLEVELPARAMETERIVQCOMPROC) (GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLEXTTEXOBJECTSTATEOVERRIDEIQCOMPROC) (GLenum target, GLenum pname, GLint param);
+typedef void (GL_APIENTRYP PFNGLEXTGETTEXSUBIMAGEQCOMPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLvoid *texels);
+typedef void (GL_APIENTRYP PFNGLEXTGETBUFFERPOINTERVQCOMPROC) (GLenum target, GLvoid **params);
+#endif
+
+/* GL_QCOM_extended_get2 */
+#ifndef GL_QCOM_extended_get2
+#define GL_QCOM_extended_get2 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glExtGetShadersQCOM (GLuint *shaders, GLint maxShaders, GLint *numShaders);
+GL_APICALL void GL_APIENTRY glExtGetProgramsQCOM (GLuint *programs, GLint maxPrograms, GLint *numPrograms);
+GL_APICALL GLboolean GL_APIENTRY glExtIsProgramBinaryQCOM (GLuint program);
+GL_APICALL void GL_APIENTRY glExtGetProgramBinarySourceQCOM (GLuint program, GLenum shadertype, GLchar *source, GLint *length);
+#endif
+typedef void (GL_APIENTRYP PFNGLEXTGETSHADERSQCOMPROC) (GLuint *shaders, GLint maxShaders, GLint *numShaders);
+typedef void (GL_APIENTRYP PFNGLEXTGETPROGRAMSQCOMPROC) (GLuint *programs, GLint maxPrograms, GLint *numPrograms);
+typedef GLboolean (GL_APIENTRYP PFNGLEXTISPROGRAMBINARYQCOMPROC) (GLuint program);
+typedef void (GL_APIENTRYP PFNGLEXTGETPROGRAMBINARYSOURCEQCOMPROC) (GLuint program, GLenum shadertype, GLchar *source, GLint *length);
+#endif
+
+/* GL_QCOM_perfmon_global_mode */
+#ifndef GL_QCOM_perfmon_global_mode
+#define GL_QCOM_perfmon_global_mode 1
+#endif
+
+/* GL_QCOM_writeonly_rendering */
+#ifndef GL_QCOM_writeonly_rendering
+#define GL_QCOM_writeonly_rendering 1
+#endif
+
+/* GL_QCOM_tiled_rendering */
+#ifndef GL_QCOM_tiled_rendering
+#define GL_QCOM_tiled_rendering 1
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glStartTilingQCOM (GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask);
+GL_APICALL void GL_APIENTRY glEndTilingQCOM (GLbitfield preserveMask);
+#endif
+typedef void (GL_APIENTRYP PFNGLSTARTTILINGQCOMPROC) (GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask);
+typedef void (GL_APIENTRYP PFNGLENDTILINGQCOMPROC) (GLbitfield preserveMask);
+#endif
+
+/*------------------------------------------------------------------------*
+ * VIV extension tokens
+ *------------------------------------------------------------------------*/
+
+/* GL_VIV_shader_binary */
+#ifndef GL_VIV_shader_binary
+#define GL_VIV_shader_binary 1
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __gl2ext_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL_opengles2_gl2platform.h b/src/3rdparty/SDL2/include/SDL_opengles2_gl2platform.h
new file mode 100644
index 0000000..c325686
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_opengles2_gl2platform.h
@@ -0,0 +1,30 @@
+#ifndef __gl2platform_h_
+#define __gl2platform_h_
+
+/* $Revision: 10602 $ on $Date:: 2010-03-04 22:35:34 -0800 #$ */
+
+/*
+ * This document is licensed under the SGI Free Software B License Version
+ * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ .
+ */
+
+/* Platform-specific types and definitions for OpenGL ES 2.X gl2.h
+ *
+ * Adopters may modify khrplatform.h and this file to suit their platform.
+ * You are encouraged to submit all modifications to the Khronos group so that
+ * they can be included in future versions of this file. Please submit changes
+ * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla)
+ * by filing a bug against product "OpenGL-ES" component "Registry".
+ */
+
+/*#include <KHR/khrplatform.h>*/
+
+#ifndef GL_APICALL
+#define GL_APICALL KHRONOS_APICALL
+#endif
+
+#ifndef GL_APIENTRY
+#define GL_APIENTRY KHRONOS_APIENTRY
+#endif
+
+#endif /* __gl2platform_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL_opengles2_khrplatform.h b/src/3rdparty/SDL2/include/SDL_opengles2_khrplatform.h
new file mode 100644
index 0000000..c9e6f17
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_opengles2_khrplatform.h
@@ -0,0 +1,282 @@
+#ifndef __khrplatform_h_
+#define __khrplatform_h_
+
+/*
+** Copyright (c) 2008-2009 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+
+/* Khronos platform-specific types and definitions.
+ *
+ * $Revision: 23298 $ on $Date: 2013-09-30 17:07:13 -0700 (Mon, 30 Sep 2013) $
+ *
+ * Adopters may modify this file to suit their platform. Adopters are
+ * encouraged to submit platform specific modifications to the Khronos
+ * group so that they can be included in future versions of this file.
+ * Please submit changes by sending them to the public Khronos Bugzilla
+ * (http://khronos.org/bugzilla) by filing a bug against product
+ * "Khronos (general)" component "Registry".
+ *
+ * A predefined template which fills in some of the bug fields can be
+ * reached using http://tinyurl.com/khrplatform-h-bugreport, but you
+ * must create a Bugzilla login first.
+ *
+ *
+ * See the Implementer's Guidelines for information about where this file
+ * should be located on your system and for more details of its use:
+ * http://www.khronos.org/registry/implementers_guide.pdf
+ *
+ * This file should be included as
+ * #include <KHR/khrplatform.h>
+ * by Khronos client API header files that use its types and defines.
+ *
+ * The types in khrplatform.h should only be used to define API-specific types.
+ *
+ * Types defined in khrplatform.h:
+ * khronos_int8_t signed 8 bit
+ * khronos_uint8_t unsigned 8 bit
+ * khronos_int16_t signed 16 bit
+ * khronos_uint16_t unsigned 16 bit
+ * khronos_int32_t signed 32 bit
+ * khronos_uint32_t unsigned 32 bit
+ * khronos_int64_t signed 64 bit
+ * khronos_uint64_t unsigned 64 bit
+ * khronos_intptr_t signed same number of bits as a pointer
+ * khronos_uintptr_t unsigned same number of bits as a pointer
+ * khronos_ssize_t signed size
+ * khronos_usize_t unsigned size
+ * khronos_float_t signed 32 bit floating point
+ * khronos_time_ns_t unsigned 64 bit time in nanoseconds
+ * khronos_utime_nanoseconds_t unsigned time interval or absolute time in
+ * nanoseconds
+ * khronos_stime_nanoseconds_t signed time interval in nanoseconds
+ * khronos_boolean_enum_t enumerated boolean type. This should
+ * only be used as a base type when a client API's boolean type is
+ * an enum. Client APIs which use an integer or other type for
+ * booleans cannot use this as the base type for their boolean.
+ *
+ * Tokens defined in khrplatform.h:
+ *
+ * KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
+ *
+ * KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
+ * KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
+ *
+ * Calling convention macros defined in this file:
+ * KHRONOS_APICALL
+ * KHRONOS_APIENTRY
+ * KHRONOS_APIATTRIBUTES
+ *
+ * These may be used in function prototypes as:
+ *
+ * KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
+ * int arg1,
+ * int arg2) KHRONOS_APIATTRIBUTES;
+ */
+
+/*-------------------------------------------------------------------------
+ * Definition of KHRONOS_APICALL
+ *-------------------------------------------------------------------------
+ * This precedes the return type of the function in the function prototype.
+ */
+#if defined(_WIN32) && !defined(__SCITECH_SNAP__)
+# define KHRONOS_APICALL __declspec(dllimport)
+#elif defined (__SYMBIAN32__)
+# define KHRONOS_APICALL IMPORT_C
+#else
+# define KHRONOS_APICALL
+#endif
+
+/*-------------------------------------------------------------------------
+ * Definition of KHRONOS_APIENTRY
+ *-------------------------------------------------------------------------
+ * This follows the return type of the function and precedes the function
+ * name in the function prototype.
+ */
+#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
+ /* Win32 but not WinCE */
+# define KHRONOS_APIENTRY __stdcall
+#else
+# define KHRONOS_APIENTRY
+#endif
+
+/*-------------------------------------------------------------------------
+ * Definition of KHRONOS_APIATTRIBUTES
+ *-------------------------------------------------------------------------
+ * This follows the closing parenthesis of the function prototype arguments.
+ */
+#if defined (__ARMCC_2__)
+#define KHRONOS_APIATTRIBUTES __softfp
+#else
+#define KHRONOS_APIATTRIBUTES
+#endif
+
+/*-------------------------------------------------------------------------
+ * basic type definitions
+ *-----------------------------------------------------------------------*/
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
+
+
+/*
+ * Using <stdint.h>
+ */
+#include <stdint.h>
+typedef int32_t khronos_int32_t;
+typedef uint32_t khronos_uint32_t;
+typedef int64_t khronos_int64_t;
+typedef uint64_t khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif defined(__VMS ) || defined(__sgi)
+
+/*
+ * Using <inttypes.h>
+ */
+#include <inttypes.h>
+typedef int32_t khronos_int32_t;
+typedef uint32_t khronos_uint32_t;
+typedef int64_t khronos_int64_t;
+typedef uint64_t khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
+
+/*
+ * Win32
+ */
+typedef __int32 khronos_int32_t;
+typedef unsigned __int32 khronos_uint32_t;
+typedef __int64 khronos_int64_t;
+typedef unsigned __int64 khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif defined(__sun__) || defined(__digital__)
+
+/*
+ * Sun or Digital
+ */
+typedef int khronos_int32_t;
+typedef unsigned int khronos_uint32_t;
+#if defined(__arch64__) || defined(_LP64)
+typedef long int khronos_int64_t;
+typedef unsigned long int khronos_uint64_t;
+#else
+typedef long long int khronos_int64_t;
+typedef unsigned long long int khronos_uint64_t;
+#endif /* __arch64__ */
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif 0
+
+/*
+ * Hypothetical platform with no float or int64 support
+ */
+typedef int khronos_int32_t;
+typedef unsigned int khronos_uint32_t;
+#define KHRONOS_SUPPORT_INT64 0
+#define KHRONOS_SUPPORT_FLOAT 0
+
+#else
+
+/*
+ * Generic fallback
+ */
+#include <stdint.h>
+typedef int32_t khronos_int32_t;
+typedef uint32_t khronos_uint32_t;
+typedef int64_t khronos_int64_t;
+typedef uint64_t khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#endif
+
+
+/*
+ * Types that are (so far) the same on all platforms
+ */
+typedef signed char khronos_int8_t;
+typedef unsigned char khronos_uint8_t;
+typedef signed short int khronos_int16_t;
+typedef unsigned short int khronos_uint16_t;
+
+/*
+ * Types that differ between LLP64 and LP64 architectures - in LLP64,
+ * pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
+ * to be the only LLP64 architecture in current use.
+ */
+#ifdef _WIN64
+typedef signed long long int khronos_intptr_t;
+typedef unsigned long long int khronos_uintptr_t;
+typedef signed long long int khronos_ssize_t;
+typedef unsigned long long int khronos_usize_t;
+#else
+typedef signed long int khronos_intptr_t;
+typedef unsigned long int khronos_uintptr_t;
+typedef signed long int khronos_ssize_t;
+typedef unsigned long int khronos_usize_t;
+#endif
+
+#if KHRONOS_SUPPORT_FLOAT
+/*
+ * Float type
+ */
+typedef float khronos_float_t;
+#endif
+
+#if KHRONOS_SUPPORT_INT64
+/* Time types
+ *
+ * These types can be used to represent a time interval in nanoseconds or
+ * an absolute Unadjusted System Time. Unadjusted System Time is the number
+ * of nanoseconds since some arbitrary system event (e.g. since the last
+ * time the system booted). The Unadjusted System Time is an unsigned
+ * 64 bit value that wraps back to 0 every 584 years. Time intervals
+ * may be either signed or unsigned.
+ */
+typedef khronos_uint64_t khronos_utime_nanoseconds_t;
+typedef khronos_int64_t khronos_stime_nanoseconds_t;
+#endif
+
+/*
+ * Dummy value used to pad enum types to 32 bits.
+ */
+#ifndef KHRONOS_MAX_ENUM
+#define KHRONOS_MAX_ENUM 0x7FFFFFFF
+#endif
+
+/*
+ * Enumerated boolean type
+ *
+ * Values other than zero should be considered to be true. Therefore
+ * comparisons should not be made against KHRONOS_TRUE.
+ */
+typedef enum {
+ KHRONOS_FALSE = 0,
+ KHRONOS_TRUE = 1,
+ KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
+} khronos_boolean_enum_t;
+
+#endif /* __khrplatform_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL_pixels.h b/src/3rdparty/SDL2/include/SDL_pixels.h
new file mode 100644
index 0000000..0b4364b
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_pixels.h
@@ -0,0 +1,470 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_pixels.h
+ *
+ * Header for the enumerated pixel format definitions.
+ */
+
+#ifndef SDL_pixels_h_
+#define SDL_pixels_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_endian.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \name Transparency definitions
+ *
+ * These define alpha as the opacity of a surface.
+ */
+/* @{ */
+#define SDL_ALPHA_OPAQUE 255
+#define SDL_ALPHA_TRANSPARENT 0
+/* @} */
+
+/** Pixel type. */
+enum
+{
+ SDL_PIXELTYPE_UNKNOWN,
+ SDL_PIXELTYPE_INDEX1,
+ SDL_PIXELTYPE_INDEX4,
+ SDL_PIXELTYPE_INDEX8,
+ SDL_PIXELTYPE_PACKED8,
+ SDL_PIXELTYPE_PACKED16,
+ SDL_PIXELTYPE_PACKED32,
+ SDL_PIXELTYPE_ARRAYU8,
+ SDL_PIXELTYPE_ARRAYU16,
+ SDL_PIXELTYPE_ARRAYU32,
+ SDL_PIXELTYPE_ARRAYF16,
+ SDL_PIXELTYPE_ARRAYF32
+};
+
+/** Bitmap pixel order, high bit -> low bit. */
+enum
+{
+ SDL_BITMAPORDER_NONE,
+ SDL_BITMAPORDER_4321,
+ SDL_BITMAPORDER_1234
+};
+
+/** Packed component order, high bit -> low bit. */
+enum
+{
+ SDL_PACKEDORDER_NONE,
+ SDL_PACKEDORDER_XRGB,
+ SDL_PACKEDORDER_RGBX,
+ SDL_PACKEDORDER_ARGB,
+ SDL_PACKEDORDER_RGBA,
+ SDL_PACKEDORDER_XBGR,
+ SDL_PACKEDORDER_BGRX,
+ SDL_PACKEDORDER_ABGR,
+ SDL_PACKEDORDER_BGRA
+};
+
+/** Array component order, low byte -> high byte. */
+/* !!! FIXME: in 2.1, make these not overlap differently with
+ !!! FIXME: SDL_PACKEDORDER_*, so we can simplify SDL_ISPIXELFORMAT_ALPHA */
+enum
+{
+ SDL_ARRAYORDER_NONE,
+ SDL_ARRAYORDER_RGB,
+ SDL_ARRAYORDER_RGBA,
+ SDL_ARRAYORDER_ARGB,
+ SDL_ARRAYORDER_BGR,
+ SDL_ARRAYORDER_BGRA,
+ SDL_ARRAYORDER_ABGR
+};
+
+/** Packed component layout. */
+enum
+{
+ SDL_PACKEDLAYOUT_NONE,
+ SDL_PACKEDLAYOUT_332,
+ SDL_PACKEDLAYOUT_4444,
+ SDL_PACKEDLAYOUT_1555,
+ SDL_PACKEDLAYOUT_5551,
+ SDL_PACKEDLAYOUT_565,
+ SDL_PACKEDLAYOUT_8888,
+ SDL_PACKEDLAYOUT_2101010,
+ SDL_PACKEDLAYOUT_1010102
+};
+
+#define SDL_DEFINE_PIXELFOURCC(A, B, C, D) SDL_FOURCC(A, B, C, D)
+
+#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
+ ((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
+ ((bits) << 8) | ((bytes) << 0))
+
+#define SDL_PIXELFLAG(X) (((X) >> 28) & 0x0F)
+#define SDL_PIXELTYPE(X) (((X) >> 24) & 0x0F)
+#define SDL_PIXELORDER(X) (((X) >> 20) & 0x0F)
+#define SDL_PIXELLAYOUT(X) (((X) >> 16) & 0x0F)
+#define SDL_BITSPERPIXEL(X) (((X) >> 8) & 0xFF)
+#define SDL_BYTESPERPIXEL(X) \
+ (SDL_ISPIXELFORMAT_FOURCC(X) ? \
+ ((((X) == SDL_PIXELFORMAT_YUY2) || \
+ ((X) == SDL_PIXELFORMAT_UYVY) || \
+ ((X) == SDL_PIXELFORMAT_YVYU)) ? 2 : 1) : (((X) >> 0) & 0xFF))
+
+#define SDL_ISPIXELFORMAT_INDEXED(format) \
+ (!SDL_ISPIXELFORMAT_FOURCC(format) && \
+ ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) || \
+ (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \
+ (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)))
+
+#define SDL_ISPIXELFORMAT_PACKED(format) \
+ (!SDL_ISPIXELFORMAT_FOURCC(format) && \
+ ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED8) || \
+ (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED16) || \
+ (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_PACKED32)))
+
+#define SDL_ISPIXELFORMAT_ARRAY(format) \
+ (!SDL_ISPIXELFORMAT_FOURCC(format) && \
+ ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU8) || \
+ (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU16) || \
+ (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYU32) || \
+ (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF16) || \
+ (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_ARRAYF32)))
+
+#define SDL_ISPIXELFORMAT_ALPHA(format) \
+ ((SDL_ISPIXELFORMAT_PACKED(format) && \
+ ((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \
+ (SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || \
+ (SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || \
+ (SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA))) || \
+ (SDL_ISPIXELFORMAT_ARRAY(format) && \
+ ((SDL_PIXELORDER(format) == SDL_ARRAYORDER_ARGB) || \
+ (SDL_PIXELORDER(format) == SDL_ARRAYORDER_RGBA) || \
+ (SDL_PIXELORDER(format) == SDL_ARRAYORDER_ABGR) || \
+ (SDL_PIXELORDER(format) == SDL_ARRAYORDER_BGRA))))
+
+/* The flag is set to 1 because 0x1? is not in the printable ASCII range */
+#define SDL_ISPIXELFORMAT_FOURCC(format) \
+ ((format) && (SDL_PIXELFLAG(format) != 1))
+
+/* Note: If you modify this list, update SDL_GetPixelFormatName() */
+enum
+{
+ SDL_PIXELFORMAT_UNKNOWN,
+ SDL_PIXELFORMAT_INDEX1LSB =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_4321, 0,
+ 1, 0),
+ SDL_PIXELFORMAT_INDEX1MSB =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_1234, 0,
+ 1, 0),
+ SDL_PIXELFORMAT_INDEX4LSB =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_4321, 0,
+ 4, 0),
+ SDL_PIXELFORMAT_INDEX4MSB =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_1234, 0,
+ 4, 0),
+ SDL_PIXELFORMAT_INDEX8 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1),
+ SDL_PIXELFORMAT_RGB332 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED8, SDL_PACKEDORDER_XRGB,
+ SDL_PACKEDLAYOUT_332, 8, 1),
+ SDL_PIXELFORMAT_RGB444 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
+ SDL_PACKEDLAYOUT_4444, 12, 2),
+ SDL_PIXELFORMAT_RGB555 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
+ SDL_PACKEDLAYOUT_1555, 15, 2),
+ SDL_PIXELFORMAT_BGR555 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
+ SDL_PACKEDLAYOUT_1555, 15, 2),
+ SDL_PIXELFORMAT_ARGB4444 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
+ SDL_PACKEDLAYOUT_4444, 16, 2),
+ SDL_PIXELFORMAT_RGBA4444 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA,
+ SDL_PACKEDLAYOUT_4444, 16, 2),
+ SDL_PIXELFORMAT_ABGR4444 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
+ SDL_PACKEDLAYOUT_4444, 16, 2),
+ SDL_PIXELFORMAT_BGRA4444 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA,
+ SDL_PACKEDLAYOUT_4444, 16, 2),
+ SDL_PIXELFORMAT_ARGB1555 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
+ SDL_PACKEDLAYOUT_1555, 16, 2),
+ SDL_PIXELFORMAT_RGBA5551 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA,
+ SDL_PACKEDLAYOUT_5551, 16, 2),
+ SDL_PIXELFORMAT_ABGR1555 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
+ SDL_PACKEDLAYOUT_1555, 16, 2),
+ SDL_PIXELFORMAT_BGRA5551 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA,
+ SDL_PACKEDLAYOUT_5551, 16, 2),
+ SDL_PIXELFORMAT_RGB565 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
+ SDL_PACKEDLAYOUT_565, 16, 2),
+ SDL_PIXELFORMAT_BGR565 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR,
+ SDL_PACKEDLAYOUT_565, 16, 2),
+ SDL_PIXELFORMAT_RGB24 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_RGB, 0,
+ 24, 3),
+ SDL_PIXELFORMAT_BGR24 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_BGR, 0,
+ 24, 3),
+ SDL_PIXELFORMAT_RGB888 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XRGB,
+ SDL_PACKEDLAYOUT_8888, 24, 4),
+ SDL_PIXELFORMAT_RGBX8888 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBX,
+ SDL_PACKEDLAYOUT_8888, 24, 4),
+ SDL_PIXELFORMAT_BGR888 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XBGR,
+ SDL_PACKEDLAYOUT_8888, 24, 4),
+ SDL_PIXELFORMAT_BGRX8888 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_BGRX,
+ SDL_PACKEDLAYOUT_8888, 24, 4),
+ SDL_PIXELFORMAT_ARGB8888 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
+ SDL_PACKEDLAYOUT_8888, 32, 4),
+ SDL_PIXELFORMAT_RGBA8888 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBA,
+ SDL_PACKEDLAYOUT_8888, 32, 4),
+ SDL_PIXELFORMAT_ABGR8888 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ABGR,
+ SDL_PACKEDLAYOUT_8888, 32, 4),
+ SDL_PIXELFORMAT_BGRA8888 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_BGRA,
+ SDL_PACKEDLAYOUT_8888, 32, 4),
+ SDL_PIXELFORMAT_ARGB2101010 =
+ SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB,
+ SDL_PACKEDLAYOUT_2101010, 32, 4),
+
+ /* Aliases for RGBA byte arrays of color data, for the current platform */
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_RGBA8888,
+ SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_ARGB8888,
+ SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_BGRA8888,
+ SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_ABGR8888,
+#else
+ SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_ABGR8888,
+ SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_BGRA8888,
+ SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_ARGB8888,
+ SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_RGBA8888,
+#endif
+
+ SDL_PIXELFORMAT_YV12 = /**< Planar mode: Y + V + U (3 planes) */
+ SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
+ SDL_PIXELFORMAT_IYUV = /**< Planar mode: Y + U + V (3 planes) */
+ SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'),
+ SDL_PIXELFORMAT_YUY2 = /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
+ SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'),
+ SDL_PIXELFORMAT_UYVY = /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
+ SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'),
+ SDL_PIXELFORMAT_YVYU = /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
+ SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U'),
+ SDL_PIXELFORMAT_NV12 = /**< Planar mode: Y + U/V interleaved (2 planes) */
+ SDL_DEFINE_PIXELFOURCC('N', 'V', '1', '2'),
+ SDL_PIXELFORMAT_NV21 = /**< Planar mode: Y + V/U interleaved (2 planes) */
+ SDL_DEFINE_PIXELFOURCC('N', 'V', '2', '1'),
+ SDL_PIXELFORMAT_EXTERNAL_OES = /**< Android video texture format */
+ SDL_DEFINE_PIXELFOURCC('O', 'E', 'S', ' ')
+};
+
+typedef struct SDL_Color
+{
+ Uint8 r;
+ Uint8 g;
+ Uint8 b;
+ Uint8 a;
+} SDL_Color;
+#define SDL_Colour SDL_Color
+
+typedef struct SDL_Palette
+{
+ int ncolors;
+ SDL_Color *colors;
+ Uint32 version;
+ int refcount;
+} SDL_Palette;
+
+/**
+ * \note Everything in the pixel format structure is read-only.
+ */
+typedef struct SDL_PixelFormat
+{
+ Uint32 format;
+ SDL_Palette *palette;
+ Uint8 BitsPerPixel;
+ Uint8 BytesPerPixel;
+ Uint8 padding[2];
+ Uint32 Rmask;
+ Uint32 Gmask;
+ Uint32 Bmask;
+ Uint32 Amask;
+ Uint8 Rloss;
+ Uint8 Gloss;
+ Uint8 Bloss;
+ Uint8 Aloss;
+ Uint8 Rshift;
+ Uint8 Gshift;
+ Uint8 Bshift;
+ Uint8 Ashift;
+ int refcount;
+ struct SDL_PixelFormat *next;
+} SDL_PixelFormat;
+
+/**
+ * \brief Get the human readable name of a pixel format
+ */
+extern DECLSPEC const char* SDLCALL SDL_GetPixelFormatName(Uint32 format);
+
+/**
+ * \brief Convert one of the enumerated pixel formats to a bpp and RGBA masks.
+ *
+ * \return SDL_TRUE, or SDL_FALSE if the conversion wasn't possible.
+ *
+ * \sa SDL_MasksToPixelFormatEnum()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_PixelFormatEnumToMasks(Uint32 format,
+ int *bpp,
+ Uint32 * Rmask,
+ Uint32 * Gmask,
+ Uint32 * Bmask,
+ Uint32 * Amask);
+
+/**
+ * \brief Convert a bpp and RGBA masks to an enumerated pixel format.
+ *
+ * \return The pixel format, or ::SDL_PIXELFORMAT_UNKNOWN if the conversion
+ * wasn't possible.
+ *
+ * \sa SDL_PixelFormatEnumToMasks()
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_MasksToPixelFormatEnum(int bpp,
+ Uint32 Rmask,
+ Uint32 Gmask,
+ Uint32 Bmask,
+ Uint32 Amask);
+
+/**
+ * \brief Create an SDL_PixelFormat structure from a pixel format enum.
+ */
+extern DECLSPEC SDL_PixelFormat * SDLCALL SDL_AllocFormat(Uint32 pixel_format);
+
+/**
+ * \brief Free an SDL_PixelFormat structure.
+ */
+extern DECLSPEC void SDLCALL SDL_FreeFormat(SDL_PixelFormat *format);
+
+/**
+ * \brief Create a palette structure with the specified number of color
+ * entries.
+ *
+ * \return A new palette, or NULL if there wasn't enough memory.
+ *
+ * \note The palette entries are initialized to white.
+ *
+ * \sa SDL_FreePalette()
+ */
+extern DECLSPEC SDL_Palette *SDLCALL SDL_AllocPalette(int ncolors);
+
+/**
+ * \brief Set the palette for a pixel format structure.
+ */
+extern DECLSPEC int SDLCALL SDL_SetPixelFormatPalette(SDL_PixelFormat * format,
+ SDL_Palette *palette);
+
+/**
+ * \brief Set a range of colors in a palette.
+ *
+ * \param palette The palette to modify.
+ * \param colors An array of colors to copy into the palette.
+ * \param firstcolor The index of the first palette entry to modify.
+ * \param ncolors The number of entries to modify.
+ *
+ * \return 0 on success, or -1 if not all of the colors could be set.
+ */
+extern DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette,
+ const SDL_Color * colors,
+ int firstcolor, int ncolors);
+
+/**
+ * \brief Free a palette created with SDL_AllocPalette().
+ *
+ * \sa SDL_AllocPalette()
+ */
+extern DECLSPEC void SDLCALL SDL_FreePalette(SDL_Palette * palette);
+
+/**
+ * \brief Maps an RGB triple to an opaque pixel value for a given pixel format.
+ *
+ * \sa SDL_MapRGBA
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormat * format,
+ Uint8 r, Uint8 g, Uint8 b);
+
+/**
+ * \brief Maps an RGBA quadruple to a pixel value for a given pixel format.
+ *
+ * \sa SDL_MapRGB
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormat * format,
+ Uint8 r, Uint8 g, Uint8 b,
+ Uint8 a);
+
+/**
+ * \brief Get the RGB components from a pixel of the specified format.
+ *
+ * \sa SDL_GetRGBA
+ */
+extern DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel,
+ const SDL_PixelFormat * format,
+ Uint8 * r, Uint8 * g, Uint8 * b);
+
+/**
+ * \brief Get the RGBA components from a pixel of the specified format.
+ *
+ * \sa SDL_GetRGB
+ */
+extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel,
+ const SDL_PixelFormat * format,
+ Uint8 * r, Uint8 * g, Uint8 * b,
+ Uint8 * a);
+
+/**
+ * \brief Calculate a 256 entry gamma ramp for a gamma value.
+ */
+extern DECLSPEC void SDLCALL SDL_CalculateGammaRamp(float gamma, Uint16 * ramp);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_pixels_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_platform.h b/src/3rdparty/SDL2/include/SDL_platform.h
new file mode 100644
index 0000000..7dea4ce
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_platform.h
@@ -0,0 +1,198 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_platform.h
+ *
+ * Try to get a standard set of platform defines.
+ */
+
+#ifndef SDL_platform_h_
+#define SDL_platform_h_
+
+#if defined(_AIX)
+#undef __AIX__
+#define __AIX__ 1
+#endif
+#if defined(__HAIKU__)
+#undef __HAIKU__
+#define __HAIKU__ 1
+#endif
+#if defined(bsdi) || defined(__bsdi) || defined(__bsdi__)
+#undef __BSDI__
+#define __BSDI__ 1
+#endif
+#if defined(_arch_dreamcast)
+#undef __DREAMCAST__
+#define __DREAMCAST__ 1
+#endif
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
+#undef __FREEBSD__
+#define __FREEBSD__ 1
+#endif
+#if defined(hpux) || defined(__hpux) || defined(__hpux__)
+#undef __HPUX__
+#define __HPUX__ 1
+#endif
+#if defined(sgi) || defined(__sgi) || defined(__sgi__) || defined(_SGI_SOURCE)
+#undef __IRIX__
+#define __IRIX__ 1
+#endif
+#if (defined(linux) || defined(__linux) || defined(__linux__))
+#undef __LINUX__
+#define __LINUX__ 1
+#endif
+#if defined(ANDROID) || defined(__ANDROID__)
+#undef __ANDROID__
+#undef __LINUX__ /* do we need to do this? */
+#define __ANDROID__ 1
+#endif
+
+#if defined(__APPLE__)
+/* lets us know what version of Mac OS X we're compiling on */
+#include "AvailabilityMacros.h"
+#include "TargetConditionals.h"
+#if TARGET_OS_TV
+#undef __TVOS__
+#define __TVOS__ 1
+#endif
+#if TARGET_OS_IPHONE
+/* if compiling for iOS */
+#undef __IPHONEOS__
+#define __IPHONEOS__ 1
+#undef __MACOSX__
+#else
+/* if not compiling for iOS */
+#undef __MACOSX__
+#define __MACOSX__ 1
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
+# error SDL for Mac OS X only supports deploying on 10.6 and above.
+#endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1060 */
+#endif /* TARGET_OS_IPHONE */
+#endif /* defined(__APPLE__) */
+
+#if defined(__NetBSD__)
+#undef __NETBSD__
+#define __NETBSD__ 1
+#endif
+#if defined(__OpenBSD__)
+#undef __OPENBSD__
+#define __OPENBSD__ 1
+#endif
+#if defined(__OS2__) || defined(__EMX__)
+#undef __OS2__
+#define __OS2__ 1
+#endif
+#if defined(osf) || defined(__osf) || defined(__osf__) || defined(_OSF_SOURCE)
+#undef __OSF__
+#define __OSF__ 1
+#endif
+#if defined(__QNXNTO__)
+#undef __QNXNTO__
+#define __QNXNTO__ 1
+#endif
+#if defined(riscos) || defined(__riscos) || defined(__riscos__)
+#undef __RISCOS__
+#define __RISCOS__ 1
+#endif
+#if defined(__sun) && defined(__SVR4)
+#undef __SOLARIS__
+#define __SOLARIS__ 1
+#endif
+
+#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
+/* Try to find out if we're compiling for WinRT or non-WinRT */
+#if defined(_MSC_VER) && defined(__has_include)
+#if __has_include(<winapifamily.h>)
+#define HAVE_WINAPIFAMILY_H 1
+#else
+#define HAVE_WINAPIFAMILY_H 0
+#endif
+
+/* If _USING_V110_SDK71_ is defined it means we are using the Windows XP toolset. */
+#elif defined(_MSC_VER) && (_MSC_VER >= 1700 && !_USING_V110_SDK71_) /* _MSC_VER == 1700 for Visual Studio 2012 */
+#define HAVE_WINAPIFAMILY_H 1
+#else
+#define HAVE_WINAPIFAMILY_H 0
+#endif
+
+#if HAVE_WINAPIFAMILY_H
+#include <winapifamily.h>
+#define WINAPI_FAMILY_WINRT (!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP))
+#else
+#define WINAPI_FAMILY_WINRT 0
+#endif /* HAVE_WINAPIFAMILY_H */
+
+#if WINAPI_FAMILY_WINRT
+#undef __WINRT__
+#define __WINRT__ 1
+#else
+#undef __WINDOWS__
+#define __WINDOWS__ 1
+#endif
+#endif /* defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) */
+
+#if defined(__WINDOWS__)
+#undef __WIN32__
+#define __WIN32__ 1
+#endif
+#if defined(__PSP__)
+#undef __PSP__
+#define __PSP__ 1
+#endif
+
+/* The NACL compiler defines __native_client__ and __pnacl__
+ * Ref: http://www.chromium.org/nativeclient/pnacl/stability-of-the-pnacl-bitcode-abi
+ */
+#if defined(__native_client__)
+#undef __LINUX__
+#undef __NACL__
+#define __NACL__ 1
+#endif
+#if defined(__pnacl__)
+#undef __LINUX__
+#undef __PNACL__
+#define __PNACL__ 1
+/* PNACL with newlib supports static linking only */
+#define __SDL_NOGETPROCADDR__
+#endif
+
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Gets the name of the platform.
+ */
+extern DECLSPEC const char * SDLCALL SDL_GetPlatform (void);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_platform_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_power.h b/src/3rdparty/SDL2/include/SDL_power.h
new file mode 100644
index 0000000..a4fe8a9
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_power.h
@@ -0,0 +1,75 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_power_h_
+#define SDL_power_h_
+
+/**
+ * \file SDL_power.h
+ *
+ * Header for the SDL power management routines.
+ */
+
+#include "SDL_stdinc.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The basic state for the system's power supply.
+ */
+typedef enum
+{
+ SDL_POWERSTATE_UNKNOWN, /**< cannot determine power status */
+ SDL_POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */
+ SDL_POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */
+ SDL_POWERSTATE_CHARGING, /**< Plugged in, charging battery */
+ SDL_POWERSTATE_CHARGED /**< Plugged in, battery charged */
+} SDL_PowerState;
+
+
+/**
+ * \brief Get the current power supply details.
+ *
+ * \param secs Seconds of battery life left. You can pass a NULL here if
+ * you don't care. Will return -1 if we can't determine a
+ * value, or we're not running on a battery.
+ *
+ * \param pct Percentage of battery life left, between 0 and 100. You can
+ * pass a NULL here if you don't care. Will return -1 if we
+ * can't determine a value, or we're not running on a battery.
+ *
+ * \return The state of the battery (if any).
+ */
+extern DECLSPEC SDL_PowerState SDLCALL SDL_GetPowerInfo(int *secs, int *pct);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_power_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_quit.h b/src/3rdparty/SDL2/include/SDL_quit.h
new file mode 100644
index 0000000..fea56a8
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_quit.h
@@ -0,0 +1,58 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_quit.h
+ *
+ * Include file for SDL quit event handling.
+ */
+
+#ifndef SDL_quit_h_
+#define SDL_quit_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+
+/**
+ * \file SDL_quit.h
+ *
+ * An ::SDL_QUIT event is generated when the user tries to close the application
+ * window. If it is ignored or filtered out, the window will remain open.
+ * If it is not ignored or filtered, it is queued normally and the window
+ * is allowed to close. When the window is closed, screen updates will
+ * complete, but have no effect.
+ *
+ * SDL_Init() installs signal handlers for SIGINT (keyboard interrupt)
+ * and SIGTERM (system termination request), if handlers do not already
+ * exist, that generate ::SDL_QUIT events as well. There is no way
+ * to determine the cause of an ::SDL_QUIT event, but setting a signal
+ * handler in your application will override the default generation of
+ * quit events for that signal.
+ *
+ * \sa SDL_Quit()
+ */
+
+/* There are no functions directly affecting the quit event */
+
+#define SDL_QuitRequested() \
+ (SDL_PumpEvents(), (SDL_PeepEvents(NULL,0,SDL_PEEKEVENT,SDL_QUIT,SDL_QUIT) > 0))
+
+#endif /* SDL_quit_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL_rect.h b/src/3rdparty/SDL2/include/SDL_rect.h
new file mode 100644
index 0000000..543bb61
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_rect.h
@@ -0,0 +1,148 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_rect.h
+ *
+ * Header file for SDL_rect definition and management functions.
+ */
+
+#ifndef SDL_rect_h_
+#define SDL_rect_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_pixels.h"
+#include "SDL_rwops.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The structure that defines a point
+ *
+ * \sa SDL_EnclosePoints
+ * \sa SDL_PointInRect
+ */
+typedef struct SDL_Point
+{
+ int x;
+ int y;
+} SDL_Point;
+
+/**
+ * \brief A rectangle, with the origin at the upper left.
+ *
+ * \sa SDL_RectEmpty
+ * \sa SDL_RectEquals
+ * \sa SDL_HasIntersection
+ * \sa SDL_IntersectRect
+ * \sa SDL_UnionRect
+ * \sa SDL_EnclosePoints
+ */
+typedef struct SDL_Rect
+{
+ int x, y;
+ int w, h;
+} SDL_Rect;
+
+/**
+ * \brief Returns true if point resides inside a rectangle.
+ */
+SDL_FORCE_INLINE SDL_bool SDL_PointInRect(const SDL_Point *p, const SDL_Rect *r)
+{
+ return ( (p->x >= r->x) && (p->x < (r->x + r->w)) &&
+ (p->y >= r->y) && (p->y < (r->y + r->h)) ) ? SDL_TRUE : SDL_FALSE;
+}
+
+/**
+ * \brief Returns true if the rectangle has no area.
+ */
+SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
+{
+ return ((!r) || (r->w <= 0) || (r->h <= 0)) ? SDL_TRUE : SDL_FALSE;
+}
+
+/**
+ * \brief Returns true if the two rectangles are equal.
+ */
+SDL_FORCE_INLINE SDL_bool SDL_RectEquals(const SDL_Rect *a, const SDL_Rect *b)
+{
+ return (a && b && (a->x == b->x) && (a->y == b->y) &&
+ (a->w == b->w) && (a->h == b->h)) ? SDL_TRUE : SDL_FALSE;
+}
+
+/**
+ * \brief Determine whether two rectangles intersect.
+ *
+ * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_HasIntersection(const SDL_Rect * A,
+ const SDL_Rect * B);
+
+/**
+ * \brief Calculate the intersection of two rectangles.
+ *
+ * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRect(const SDL_Rect * A,
+ const SDL_Rect * B,
+ SDL_Rect * result);
+
+/**
+ * \brief Calculate the union of two rectangles.
+ */
+extern DECLSPEC void SDLCALL SDL_UnionRect(const SDL_Rect * A,
+ const SDL_Rect * B,
+ SDL_Rect * result);
+
+/**
+ * \brief Calculate a minimal rectangle enclosing a set of points
+ *
+ * \return SDL_TRUE if any points were within the clipping rect
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_EnclosePoints(const SDL_Point * points,
+ int count,
+ const SDL_Rect * clip,
+ SDL_Rect * result);
+
+/**
+ * \brief Calculate the intersection of a rectangle and line segment.
+ *
+ * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRectAndLine(const SDL_Rect *
+ rect, int *X1,
+ int *Y1, int *X2,
+ int *Y2);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_rect_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_render.h b/src/3rdparty/SDL2/include/SDL_render.h
new file mode 100644
index 0000000..d336192
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_render.h
@@ -0,0 +1,931 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_render.h
+ *
+ * Header file for SDL 2D rendering functions.
+ *
+ * This API supports the following features:
+ * * single pixel points
+ * * single pixel lines
+ * * filled rectangles
+ * * texture images
+ *
+ * The primitives may be drawn in opaque, blended, or additive modes.
+ *
+ * The texture images may be drawn in opaque, blended, or additive modes.
+ * They can have an additional color tint or alpha modulation applied to
+ * them, and may also be stretched with linear interpolation.
+ *
+ * This API is designed to accelerate simple 2D operations. You may
+ * want more functionality such as polygons and particle effects and
+ * in that case you should use SDL's OpenGL/Direct3D support or one
+ * of the many good 3D engines.
+ *
+ * These functions must be called from the main thread.
+ * See this bug for details: http://bugzilla.libsdl.org/show_bug.cgi?id=1995
+ */
+
+#ifndef SDL_render_h_
+#define SDL_render_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_rect.h"
+#include "SDL_video.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Flags used when creating a rendering context
+ */
+typedef enum
+{
+ SDL_RENDERER_SOFTWARE = 0x00000001, /**< The renderer is a software fallback */
+ SDL_RENDERER_ACCELERATED = 0x00000002, /**< The renderer uses hardware
+ acceleration */
+ SDL_RENDERER_PRESENTVSYNC = 0x00000004, /**< Present is synchronized
+ with the refresh rate */
+ SDL_RENDERER_TARGETTEXTURE = 0x00000008 /**< The renderer supports
+ rendering to texture */
+} SDL_RendererFlags;
+
+/**
+ * \brief Information on the capabilities of a render driver or context.
+ */
+typedef struct SDL_RendererInfo
+{
+ const char *name; /**< The name of the renderer */
+ Uint32 flags; /**< Supported ::SDL_RendererFlags */
+ Uint32 num_texture_formats; /**< The number of available texture formats */
+ Uint32 texture_formats[16]; /**< The available texture formats */
+ int max_texture_width; /**< The maximum texture width */
+ int max_texture_height; /**< The maximum texture height */
+} SDL_RendererInfo;
+
+/**
+ * \brief The access pattern allowed for a texture.
+ */
+typedef enum
+{
+ SDL_TEXTUREACCESS_STATIC, /**< Changes rarely, not lockable */
+ SDL_TEXTUREACCESS_STREAMING, /**< Changes frequently, lockable */
+ SDL_TEXTUREACCESS_TARGET /**< Texture can be used as a render target */
+} SDL_TextureAccess;
+
+/**
+ * \brief The texture channel modulation used in SDL_RenderCopy().
+ */
+typedef enum
+{
+ SDL_TEXTUREMODULATE_NONE = 0x00000000, /**< No modulation */
+ SDL_TEXTUREMODULATE_COLOR = 0x00000001, /**< srcC = srcC * color */
+ SDL_TEXTUREMODULATE_ALPHA = 0x00000002 /**< srcA = srcA * alpha */
+} SDL_TextureModulate;
+
+/**
+ * \brief Flip constants for SDL_RenderCopyEx
+ */
+typedef enum
+{
+ SDL_FLIP_NONE = 0x00000000, /**< Do not flip */
+ SDL_FLIP_HORIZONTAL = 0x00000001, /**< flip horizontally */
+ SDL_FLIP_VERTICAL = 0x00000002 /**< flip vertically */
+} SDL_RendererFlip;
+
+/**
+ * \brief A structure representing rendering state
+ */
+struct SDL_Renderer;
+typedef struct SDL_Renderer SDL_Renderer;
+
+/**
+ * \brief An efficient driver-specific representation of pixel data
+ */
+struct SDL_Texture;
+typedef struct SDL_Texture SDL_Texture;
+
+
+/* Function prototypes */
+
+/**
+ * \brief Get the number of 2D rendering drivers available for the current
+ * display.
+ *
+ * A render driver is a set of code that handles rendering and texture
+ * management on a particular display. Normally there is only one, but
+ * some drivers may have several available with different capabilities.
+ *
+ * \sa SDL_GetRenderDriverInfo()
+ * \sa SDL_CreateRenderer()
+ */
+extern DECLSPEC int SDLCALL SDL_GetNumRenderDrivers(void);
+
+/**
+ * \brief Get information about a specific 2D rendering driver for the current
+ * display.
+ *
+ * \param index The index of the driver to query information about.
+ * \param info A pointer to an SDL_RendererInfo struct to be filled with
+ * information on the rendering driver.
+ *
+ * \return 0 on success, -1 if the index was out of range.
+ *
+ * \sa SDL_CreateRenderer()
+ */
+extern DECLSPEC int SDLCALL SDL_GetRenderDriverInfo(int index,
+ SDL_RendererInfo * info);
+
+/**
+ * \brief Create a window and default renderer
+ *
+ * \param width The width of the window
+ * \param height The height of the window
+ * \param window_flags The flags used to create the window
+ * \param window A pointer filled with the window, or NULL on error
+ * \param renderer A pointer filled with the renderer, or NULL on error
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_CreateWindowAndRenderer(
+ int width, int height, Uint32 window_flags,
+ SDL_Window **window, SDL_Renderer **renderer);
+
+
+/**
+ * \brief Create a 2D rendering context for a window.
+ *
+ * \param window The window where rendering is displayed.
+ * \param index The index of the rendering driver to initialize, or -1 to
+ * initialize the first one supporting the requested flags.
+ * \param flags ::SDL_RendererFlags.
+ *
+ * \return A valid rendering context or NULL if there was an error.
+ *
+ * \sa SDL_CreateSoftwareRenderer()
+ * \sa SDL_GetRendererInfo()
+ * \sa SDL_DestroyRenderer()
+ */
+extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window * window,
+ int index, Uint32 flags);
+
+/**
+ * \brief Create a 2D software rendering context for a surface.
+ *
+ * \param surface The surface where rendering is done.
+ *
+ * \return A valid rendering context or NULL if there was an error.
+ *
+ * \sa SDL_CreateRenderer()
+ * \sa SDL_DestroyRenderer()
+ */
+extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateSoftwareRenderer(SDL_Surface * surface);
+
+/**
+ * \brief Get the renderer associated with a window.
+ */
+extern DECLSPEC SDL_Renderer * SDLCALL SDL_GetRenderer(SDL_Window * window);
+
+/**
+ * \brief Get information about a rendering context.
+ */
+extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_Renderer * renderer,
+ SDL_RendererInfo * info);
+
+/**
+ * \brief Get the output size in pixels of a rendering context.
+ */
+extern DECLSPEC int SDLCALL SDL_GetRendererOutputSize(SDL_Renderer * renderer,
+ int *w, int *h);
+
+/**
+ * \brief Create a texture for a rendering context.
+ *
+ * \param renderer The renderer.
+ * \param format The format of the texture.
+ * \param access One of the enumerated values in ::SDL_TextureAccess.
+ * \param w The width of the texture in pixels.
+ * \param h The height of the texture in pixels.
+ *
+ * \return The created texture is returned, or NULL if no rendering context was
+ * active, the format was unsupported, or the width or height were out
+ * of range.
+ *
+ * \note The contents of the texture are not defined at creation.
+ *
+ * \sa SDL_QueryTexture()
+ * \sa SDL_UpdateTexture()
+ * \sa SDL_DestroyTexture()
+ */
+extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(SDL_Renderer * renderer,
+ Uint32 format,
+ int access, int w,
+ int h);
+
+/**
+ * \brief Create a texture from an existing surface.
+ *
+ * \param renderer The renderer.
+ * \param surface The surface containing pixel data used to fill the texture.
+ *
+ * \return The created texture is returned, or NULL on error.
+ *
+ * \note The surface is not modified or freed by this function.
+ *
+ * \sa SDL_QueryTexture()
+ * \sa SDL_DestroyTexture()
+ */
+extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface);
+
+/**
+ * \brief Query the attributes of a texture
+ *
+ * \param texture A texture to be queried.
+ * \param format A pointer filled in with the raw format of the texture. The
+ * actual format may differ, but pixel transfers will use this
+ * format.
+ * \param access A pointer filled in with the actual access to the texture.
+ * \param w A pointer filled in with the width of the texture in pixels.
+ * \param h A pointer filled in with the height of the texture in pixels.
+ *
+ * \return 0 on success, or -1 if the texture is not valid.
+ */
+extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture * texture,
+ Uint32 * format, int *access,
+ int *w, int *h);
+
+/**
+ * \brief Set an additional color value used in render copy operations.
+ *
+ * \param texture The texture to update.
+ * \param r The red color value multiplied into copy operations.
+ * \param g The green color value multiplied into copy operations.
+ * \param b The blue color value multiplied into copy operations.
+ *
+ * \return 0 on success, or -1 if the texture is not valid or color modulation
+ * is not supported.
+ *
+ * \sa SDL_GetTextureColorMod()
+ */
+extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture * texture,
+ Uint8 r, Uint8 g, Uint8 b);
+
+
+/**
+ * \brief Get the additional color value used in render copy operations.
+ *
+ * \param texture The texture to query.
+ * \param r A pointer filled in with the current red color value.
+ * \param g A pointer filled in with the current green color value.
+ * \param b A pointer filled in with the current blue color value.
+ *
+ * \return 0 on success, or -1 if the texture is not valid.
+ *
+ * \sa SDL_SetTextureColorMod()
+ */
+extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture * texture,
+ Uint8 * r, Uint8 * g,
+ Uint8 * b);
+
+/**
+ * \brief Set an additional alpha value used in render copy operations.
+ *
+ * \param texture The texture to update.
+ * \param alpha The alpha value multiplied into copy operations.
+ *
+ * \return 0 on success, or -1 if the texture is not valid or alpha modulation
+ * is not supported.
+ *
+ * \sa SDL_GetTextureAlphaMod()
+ */
+extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture * texture,
+ Uint8 alpha);
+
+/**
+ * \brief Get the additional alpha value used in render copy operations.
+ *
+ * \param texture The texture to query.
+ * \param alpha A pointer filled in with the current alpha value.
+ *
+ * \return 0 on success, or -1 if the texture is not valid.
+ *
+ * \sa SDL_SetTextureAlphaMod()
+ */
+extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture * texture,
+ Uint8 * alpha);
+
+/**
+ * \brief Set the blend mode used for texture copy operations.
+ *
+ * \param texture The texture to update.
+ * \param blendMode ::SDL_BlendMode to use for texture blending.
+ *
+ * \return 0 on success, or -1 if the texture is not valid or the blend mode is
+ * not supported.
+ *
+ * \note If the blend mode is not supported, the closest supported mode is
+ * chosen.
+ *
+ * \sa SDL_GetTextureBlendMode()
+ */
+extern DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture * texture,
+ SDL_BlendMode blendMode);
+
+/**
+ * \brief Get the blend mode used for texture copy operations.
+ *
+ * \param texture The texture to query.
+ * \param blendMode A pointer filled in with the current blend mode.
+ *
+ * \return 0 on success, or -1 if the texture is not valid.
+ *
+ * \sa SDL_SetTextureBlendMode()
+ */
+extern DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture * texture,
+ SDL_BlendMode *blendMode);
+
+/**
+ * \brief Update the given texture rectangle with new pixel data.
+ *
+ * \param texture The texture to update
+ * \param rect A pointer to the rectangle of pixels to update, or NULL to
+ * update the entire texture.
+ * \param pixels The raw pixel data in the format of the texture.
+ * \param pitch The number of bytes in a row of pixel data, including padding between lines.
+ *
+ * The pixel data must be in the format of the texture. The pixel format can be
+ * queried with SDL_QueryTexture.
+ *
+ * \return 0 on success, or -1 if the texture is not valid.
+ *
+ * \note This is a fairly slow function.
+ */
+extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture * texture,
+ const SDL_Rect * rect,
+ const void *pixels, int pitch);
+
+/**
+ * \brief Update a rectangle within a planar YV12 or IYUV texture with new pixel data.
+ *
+ * \param texture The texture to update
+ * \param rect A pointer to the rectangle of pixels to update, or NULL to
+ * update the entire texture.
+ * \param Yplane The raw pixel data for the Y plane.
+ * \param Ypitch The number of bytes between rows of pixel data for the Y plane.
+ * \param Uplane The raw pixel data for the U plane.
+ * \param Upitch The number of bytes between rows of pixel data for the U plane.
+ * \param Vplane The raw pixel data for the V plane.
+ * \param Vpitch The number of bytes between rows of pixel data for the V plane.
+ *
+ * \return 0 on success, or -1 if the texture is not valid.
+ *
+ * \note You can use SDL_UpdateTexture() as long as your pixel data is
+ * a contiguous block of Y and U/V planes in the proper order, but
+ * this function is available if your pixel data is not contiguous.
+ */
+extern DECLSPEC int SDLCALL SDL_UpdateYUVTexture(SDL_Texture * texture,
+ const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch);
+
+/**
+ * \brief Lock a portion of the texture for write-only pixel access.
+ *
+ * \param texture The texture to lock for access, which was created with
+ * ::SDL_TEXTUREACCESS_STREAMING.
+ * \param rect A pointer to the rectangle to lock for access. If the rect
+ * is NULL, the entire texture will be locked.
+ * \param pixels This is filled in with a pointer to the locked pixels,
+ * appropriately offset by the locked area.
+ * \param pitch This is filled in with the pitch of the locked pixels.
+ *
+ * \return 0 on success, or -1 if the texture is not valid or was not created with ::SDL_TEXTUREACCESS_STREAMING.
+ *
+ * \sa SDL_UnlockTexture()
+ */
+extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture * texture,
+ const SDL_Rect * rect,
+ void **pixels, int *pitch);
+
+/**
+ * \brief Unlock a texture, uploading the changes to video memory, if needed.
+ *
+ * \sa SDL_LockTexture()
+ */
+extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture * texture);
+
+/**
+ * \brief Determines whether a window supports the use of render targets
+ *
+ * \param renderer The renderer that will be checked
+ *
+ * \return SDL_TRUE if supported, SDL_FALSE if not.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_RenderTargetSupported(SDL_Renderer *renderer);
+
+/**
+ * \brief Set a texture as the current rendering target.
+ *
+ * \param renderer The renderer.
+ * \param texture The targeted texture, which must be created with the SDL_TEXTUREACCESS_TARGET flag, or NULL for the default render target
+ *
+ * \return 0 on success, or -1 on error
+ *
+ * \sa SDL_GetRenderTarget()
+ */
+extern DECLSPEC int SDLCALL SDL_SetRenderTarget(SDL_Renderer *renderer,
+ SDL_Texture *texture);
+
+/**
+ * \brief Get the current render target or NULL for the default render target.
+ *
+ * \return The current render target
+ *
+ * \sa SDL_SetRenderTarget()
+ */
+extern DECLSPEC SDL_Texture * SDLCALL SDL_GetRenderTarget(SDL_Renderer *renderer);
+
+/**
+ * \brief Set device independent resolution for rendering
+ *
+ * \param renderer The renderer for which resolution should be set.
+ * \param w The width of the logical resolution
+ * \param h The height of the logical resolution
+ *
+ * This function uses the viewport and scaling functionality to allow a fixed logical
+ * resolution for rendering, regardless of the actual output resolution. If the actual
+ * output resolution doesn't have the same aspect ratio the output rendering will be
+ * centered within the output display.
+ *
+ * If the output display is a window, mouse events in the window will be filtered
+ * and scaled so they seem to arrive within the logical resolution.
+ *
+ * \note If this function results in scaling or subpixel drawing by the
+ * rendering backend, it will be handled using the appropriate
+ * quality hints.
+ *
+ * \sa SDL_RenderGetLogicalSize()
+ * \sa SDL_RenderSetScale()
+ * \sa SDL_RenderSetViewport()
+ */
+extern DECLSPEC int SDLCALL SDL_RenderSetLogicalSize(SDL_Renderer * renderer, int w, int h);
+
+/**
+ * \brief Get device independent resolution for rendering
+ *
+ * \param renderer The renderer from which resolution should be queried.
+ * \param w A pointer filled with the width of the logical resolution
+ * \param h A pointer filled with the height of the logical resolution
+ *
+ * \sa SDL_RenderSetLogicalSize()
+ */
+extern DECLSPEC void SDLCALL SDL_RenderGetLogicalSize(SDL_Renderer * renderer, int *w, int *h);
+
+/**
+ * \brief Set whether to force integer scales for resolution-independent rendering
+ *
+ * \param renderer The renderer for which integer scaling should be set.
+ * \param enable Enable or disable integer scaling
+ *
+ * This function restricts the logical viewport to integer values - that is, when
+ * a resolution is between two multiples of a logical size, the viewport size is
+ * rounded down to the lower multiple.
+ *
+ * \sa SDL_RenderSetLogicalSize()
+ */
+extern DECLSPEC int SDLCALL SDL_RenderSetIntegerScale(SDL_Renderer * renderer,
+ SDL_bool enable);
+
+/**
+ * \brief Get whether integer scales are forced for resolution-independent rendering
+ *
+ * \param renderer The renderer from which integer scaling should be queried.
+ *
+ * \sa SDL_RenderSetIntegerScale()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_RenderGetIntegerScale(SDL_Renderer * renderer);
+
+/**
+ * \brief Set the drawing area for rendering on the current target.
+ *
+ * \param renderer The renderer for which the drawing area should be set.
+ * \param rect The rectangle representing the drawing area, or NULL to set the viewport to the entire target.
+ *
+ * The x,y of the viewport rect represents the origin for rendering.
+ *
+ * \return 0 on success, or -1 on error
+ *
+ * \note If the window associated with the renderer is resized, the viewport is automatically reset.
+ *
+ * \sa SDL_RenderGetViewport()
+ * \sa SDL_RenderSetLogicalSize()
+ */
+extern DECLSPEC int SDLCALL SDL_RenderSetViewport(SDL_Renderer * renderer,
+ const SDL_Rect * rect);
+
+/**
+ * \brief Get the drawing area for the current target.
+ *
+ * \sa SDL_RenderSetViewport()
+ */
+extern DECLSPEC void SDLCALL SDL_RenderGetViewport(SDL_Renderer * renderer,
+ SDL_Rect * rect);
+
+/**
+ * \brief Set the clip rectangle for the current target.
+ *
+ * \param renderer The renderer for which clip rectangle should be set.
+ * \param rect A pointer to the rectangle to set as the clip rectangle, or
+ * NULL to disable clipping.
+ *
+ * \return 0 on success, or -1 on error
+ *
+ * \sa SDL_RenderGetClipRect()
+ */
+extern DECLSPEC int SDLCALL SDL_RenderSetClipRect(SDL_Renderer * renderer,
+ const SDL_Rect * rect);
+
+/**
+ * \brief Get the clip rectangle for the current target.
+ *
+ * \param renderer The renderer from which clip rectangle should be queried.
+ * \param rect A pointer filled in with the current clip rectangle, or
+ * an empty rectangle if clipping is disabled.
+ *
+ * \sa SDL_RenderSetClipRect()
+ */
+extern DECLSPEC void SDLCALL SDL_RenderGetClipRect(SDL_Renderer * renderer,
+ SDL_Rect * rect);
+
+/**
+ * \brief Get whether clipping is enabled on the given renderer.
+ *
+ * \param renderer The renderer from which clip state should be queried.
+ *
+ * \sa SDL_RenderGetClipRect()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_RenderIsClipEnabled(SDL_Renderer * renderer);
+
+
+/**
+ * \brief Set the drawing scale for rendering on the current target.
+ *
+ * \param renderer The renderer for which the drawing scale should be set.
+ * \param scaleX The horizontal scaling factor
+ * \param scaleY The vertical scaling factor
+ *
+ * The drawing coordinates are scaled by the x/y scaling factors
+ * before they are used by the renderer. This allows resolution
+ * independent drawing with a single coordinate system.
+ *
+ * \note If this results in scaling or subpixel drawing by the
+ * rendering backend, it will be handled using the appropriate
+ * quality hints. For best results use integer scaling factors.
+ *
+ * \sa SDL_RenderGetScale()
+ * \sa SDL_RenderSetLogicalSize()
+ */
+extern DECLSPEC int SDLCALL SDL_RenderSetScale(SDL_Renderer * renderer,
+ float scaleX, float scaleY);
+
+/**
+ * \brief Get the drawing scale for the current target.
+ *
+ * \param renderer The renderer from which drawing scale should be queried.
+ * \param scaleX A pointer filled in with the horizontal scaling factor
+ * \param scaleY A pointer filled in with the vertical scaling factor
+ *
+ * \sa SDL_RenderSetScale()
+ */
+extern DECLSPEC void SDLCALL SDL_RenderGetScale(SDL_Renderer * renderer,
+ float *scaleX, float *scaleY);
+
+/**
+ * \brief Set the color used for drawing operations (Rect, Line and Clear).
+ *
+ * \param renderer The renderer for which drawing color should be set.
+ * \param r The red value used to draw on the rendering target.
+ * \param g The green value used to draw on the rendering target.
+ * \param b The blue value used to draw on the rendering target.
+ * \param a The alpha value used to draw on the rendering target, usually
+ * ::SDL_ALPHA_OPAQUE (255).
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_SetRenderDrawColor(SDL_Renderer * renderer,
+ Uint8 r, Uint8 g, Uint8 b,
+ Uint8 a);
+
+/**
+ * \brief Get the color used for drawing operations (Rect, Line and Clear).
+ *
+ * \param renderer The renderer from which drawing color should be queried.
+ * \param r A pointer to the red value used to draw on the rendering target.
+ * \param g A pointer to the green value used to draw on the rendering target.
+ * \param b A pointer to the blue value used to draw on the rendering target.
+ * \param a A pointer to the alpha value used to draw on the rendering target,
+ * usually ::SDL_ALPHA_OPAQUE (255).
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_GetRenderDrawColor(SDL_Renderer * renderer,
+ Uint8 * r, Uint8 * g, Uint8 * b,
+ Uint8 * a);
+
+/**
+ * \brief Set the blend mode used for drawing operations (Fill and Line).
+ *
+ * \param renderer The renderer for which blend mode should be set.
+ * \param blendMode ::SDL_BlendMode to use for blending.
+ *
+ * \return 0 on success, or -1 on error
+ *
+ * \note If the blend mode is not supported, the closest supported mode is
+ * chosen.
+ *
+ * \sa SDL_GetRenderDrawBlendMode()
+ */
+extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer * renderer,
+ SDL_BlendMode blendMode);
+
+/**
+ * \brief Get the blend mode used for drawing operations.
+ *
+ * \param renderer The renderer from which blend mode should be queried.
+ * \param blendMode A pointer filled in with the current blend mode.
+ *
+ * \return 0 on success, or -1 on error
+ *
+ * \sa SDL_SetRenderDrawBlendMode()
+ */
+extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer,
+ SDL_BlendMode *blendMode);
+
+/**
+ * \brief Clear the current rendering target with the drawing color
+ *
+ * This function clears the entire rendering target, ignoring the viewport and
+ * the clip rectangle.
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer * renderer);
+
+/**
+ * \brief Draw a point on the current rendering target.
+ *
+ * \param renderer The renderer which should draw a point.
+ * \param x The x coordinate of the point.
+ * \param y The y coordinate of the point.
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(SDL_Renderer * renderer,
+ int x, int y);
+
+/**
+ * \brief Draw multiple points on the current rendering target.
+ *
+ * \param renderer The renderer which should draw multiple points.
+ * \param points The points to draw
+ * \param count The number of points to draw
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(SDL_Renderer * renderer,
+ const SDL_Point * points,
+ int count);
+
+/**
+ * \brief Draw a line on the current rendering target.
+ *
+ * \param renderer The renderer which should draw a line.
+ * \param x1 The x coordinate of the start point.
+ * \param y1 The y coordinate of the start point.
+ * \param x2 The x coordinate of the end point.
+ * \param y2 The y coordinate of the end point.
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderDrawLine(SDL_Renderer * renderer,
+ int x1, int y1, int x2, int y2);
+
+/**
+ * \brief Draw a series of connected lines on the current rendering target.
+ *
+ * \param renderer The renderer which should draw multiple lines.
+ * \param points The points along the lines
+ * \param count The number of points, drawing count-1 lines
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderDrawLines(SDL_Renderer * renderer,
+ const SDL_Point * points,
+ int count);
+
+/**
+ * \brief Draw a rectangle on the current rendering target.
+ *
+ * \param renderer The renderer which should draw a rectangle.
+ * \param rect A pointer to the destination rectangle, or NULL to outline the entire rendering target.
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderDrawRect(SDL_Renderer * renderer,
+ const SDL_Rect * rect);
+
+/**
+ * \brief Draw some number of rectangles on the current rendering target.
+ *
+ * \param renderer The renderer which should draw multiple rectangles.
+ * \param rects A pointer to an array of destination rectangles.
+ * \param count The number of rectangles.
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderDrawRects(SDL_Renderer * renderer,
+ const SDL_Rect * rects,
+ int count);
+
+/**
+ * \brief Fill a rectangle on the current rendering target with the drawing color.
+ *
+ * \param renderer The renderer which should fill a rectangle.
+ * \param rect A pointer to the destination rectangle, or NULL for the entire
+ * rendering target.
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderFillRect(SDL_Renderer * renderer,
+ const SDL_Rect * rect);
+
+/**
+ * \brief Fill some number of rectangles on the current rendering target with the drawing color.
+ *
+ * \param renderer The renderer which should fill multiple rectangles.
+ * \param rects A pointer to an array of destination rectangles.
+ * \param count The number of rectangles.
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer * renderer,
+ const SDL_Rect * rects,
+ int count);
+
+/**
+ * \brief Copy a portion of the texture to the current rendering target.
+ *
+ * \param renderer The renderer which should copy parts of a texture.
+ * \param texture The source texture.
+ * \param srcrect A pointer to the source rectangle, or NULL for the entire
+ * texture.
+ * \param dstrect A pointer to the destination rectangle, or NULL for the
+ * entire rendering target.
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Renderer * renderer,
+ SDL_Texture * texture,
+ const SDL_Rect * srcrect,
+ const SDL_Rect * dstrect);
+
+/**
+ * \brief Copy a portion of the source texture to the current rendering target, rotating it by angle around the given center
+ *
+ * \param renderer The renderer which should copy parts of a texture.
+ * \param texture The source texture.
+ * \param srcrect A pointer to the source rectangle, or NULL for the entire
+ * texture.
+ * \param dstrect A pointer to the destination rectangle, or NULL for the
+ * entire rendering target.
+ * \param angle An angle in degrees that indicates the rotation that will be applied to dstrect, rotating it in a clockwise direction
+ * \param center A pointer to a point indicating the point around which dstrect will be rotated (if NULL, rotation will be done around dstrect.w/2, dstrect.h/2).
+ * \param flip An SDL_RendererFlip value stating which flipping actions should be performed on the texture
+ *
+ * \return 0 on success, or -1 on error
+ */
+extern DECLSPEC int SDLCALL SDL_RenderCopyEx(SDL_Renderer * renderer,
+ SDL_Texture * texture,
+ const SDL_Rect * srcrect,
+ const SDL_Rect * dstrect,
+ const double angle,
+ const SDL_Point *center,
+ const SDL_RendererFlip flip);
+
+/**
+ * \brief Read pixels from the current rendering target.
+ *
+ * \param renderer The renderer from which pixels should be read.
+ * \param rect A pointer to the rectangle to read, or NULL for the entire
+ * render target.
+ * \param format The desired format of the pixel data, or 0 to use the format
+ * of the rendering target
+ * \param pixels A pointer to be filled in with the pixel data
+ * \param pitch The pitch of the pixels parameter.
+ *
+ * \return 0 on success, or -1 if pixel reading is not supported.
+ *
+ * \warning This is a very slow operation, and should not be used frequently.
+ */
+extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Renderer * renderer,
+ const SDL_Rect * rect,
+ Uint32 format,
+ void *pixels, int pitch);
+
+/**
+ * \brief Update the screen with rendering performed.
+ */
+extern DECLSPEC void SDLCALL SDL_RenderPresent(SDL_Renderer * renderer);
+
+/**
+ * \brief Destroy the specified texture.
+ *
+ * \sa SDL_CreateTexture()
+ * \sa SDL_CreateTextureFromSurface()
+ */
+extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture);
+
+/**
+ * \brief Destroy the rendering context for a window and free associated
+ * textures.
+ *
+ * \sa SDL_CreateRenderer()
+ */
+extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer * renderer);
+
+
+/**
+ * \brief Bind the texture to the current OpenGL/ES/ES2 context for use with
+ * OpenGL instructions.
+ *
+ * \param texture The SDL texture to bind
+ * \param texw A pointer to a float that will be filled with the texture width
+ * \param texh A pointer to a float that will be filled with the texture height
+ *
+ * \return 0 on success, or -1 if the operation is not supported
+ */
+extern DECLSPEC int SDLCALL SDL_GL_BindTexture(SDL_Texture *texture, float *texw, float *texh);
+
+/**
+ * \brief Unbind a texture from the current OpenGL/ES/ES2 context.
+ *
+ * \param texture The SDL texture to unbind
+ *
+ * \return 0 on success, or -1 if the operation is not supported
+ */
+extern DECLSPEC int SDLCALL SDL_GL_UnbindTexture(SDL_Texture *texture);
+
+/**
+ * \brief Get the CAMetalLayer associated with the given Metal renderer
+ *
+ * \param renderer The renderer to query
+ *
+ * \return CAMetalLayer* on success, or NULL if the renderer isn't a Metal renderer
+ *
+ * \sa SDL_RenderGetMetalCommandEncoder()
+ */
+extern DECLSPEC void *SDLCALL SDL_RenderGetMetalLayer(SDL_Renderer * renderer);
+
+/**
+ * \brief Get the Metal command encoder for the current frame
+ *
+ * \param renderer The renderer to query
+ *
+ * \return id<MTLRenderCommandEncoder> on success, or NULL if the renderer isn't a Metal renderer
+ *
+ * \sa SDL_RenderGetMetalLayer()
+ */
+extern DECLSPEC void *SDLCALL SDL_RenderGetMetalCommandEncoder(SDL_Renderer * renderer);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_render_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_revision.h b/src/3rdparty/SDL2/include/SDL_revision.h
new file mode 100644
index 0000000..dbe9b97
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_revision.h
@@ -0,0 +1,2 @@
+#define SDL_REVISION "hg-11914:f1084c419f33"
+#define SDL_REVISION_NUMBER 11914
diff --git a/src/3rdparty/SDL2/include/SDL_rwops.h b/src/3rdparty/SDL2/include/SDL_rwops.h
new file mode 100644
index 0000000..0960699
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_rwops.h
@@ -0,0 +1,254 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_rwops.h
+ *
+ * This file provides a general interface for SDL to read and write
+ * data streams. It can easily be extended to files, memory, etc.
+ */
+
+#ifndef SDL_rwops_h_
+#define SDL_rwops_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* RWops Types */
+#define SDL_RWOPS_UNKNOWN 0U /**< Unknown stream type */
+#define SDL_RWOPS_WINFILE 1U /**< Win32 file */
+#define SDL_RWOPS_STDFILE 2U /**< Stdio file */
+#define SDL_RWOPS_JNIFILE 3U /**< Android asset */
+#define SDL_RWOPS_MEMORY 4U /**< Memory stream */
+#define SDL_RWOPS_MEMORY_RO 5U /**< Read-Only memory stream */
+
+/**
+ * This is the read/write operation structure -- very basic.
+ */
+typedef struct SDL_RWops
+{
+ /**
+ * Return the size of the file in this rwops, or -1 if unknown
+ */
+ Sint64 (SDLCALL * size) (struct SDL_RWops * context);
+
+ /**
+ * Seek to \c offset relative to \c whence, one of stdio's whence values:
+ * RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
+ *
+ * \return the final offset in the data stream, or -1 on error.
+ */
+ Sint64 (SDLCALL * seek) (struct SDL_RWops * context, Sint64 offset,
+ int whence);
+
+ /**
+ * Read up to \c maxnum objects each of size \c size from the data
+ * stream to the area pointed at by \c ptr.
+ *
+ * \return the number of objects read, or 0 at error or end of file.
+ */
+ size_t (SDLCALL * read) (struct SDL_RWops * context, void *ptr,
+ size_t size, size_t maxnum);
+
+ /**
+ * Write exactly \c num objects each of size \c size from the area
+ * pointed at by \c ptr to data stream.
+ *
+ * \return the number of objects written, or 0 at error or end of file.
+ */
+ size_t (SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
+ size_t size, size_t num);
+
+ /**
+ * Close and free an allocated SDL_RWops structure.
+ *
+ * \return 0 if successful or -1 on write error when flushing data.
+ */
+ int (SDLCALL * close) (struct SDL_RWops * context);
+
+ Uint32 type;
+ union
+ {
+#if defined(__ANDROID__)
+ struct
+ {
+ void *fileNameRef;
+ void *inputStreamRef;
+ void *readableByteChannelRef;
+ void *readMethod;
+ void *assetFileDescriptorRef;
+ long position;
+ long size;
+ long offset;
+ int fd;
+ } androidio;
+#elif defined(__WIN32__)
+ struct
+ {
+ SDL_bool append;
+ void *h;
+ struct
+ {
+ void *data;
+ size_t size;
+ size_t left;
+ } buffer;
+ } windowsio;
+#endif
+
+#ifdef HAVE_STDIO_H
+ struct
+ {
+ SDL_bool autoclose;
+ FILE *fp;
+ } stdio;
+#endif
+ struct
+ {
+ Uint8 *base;
+ Uint8 *here;
+ Uint8 *stop;
+ } mem;
+ struct
+ {
+ void *data1;
+ void *data2;
+ } unknown;
+ } hidden;
+
+} SDL_RWops;
+
+
+/**
+ * \name RWFrom functions
+ *
+ * Functions to create SDL_RWops structures from various data streams.
+ */
+/* @{ */
+
+extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file,
+ const char *mode);
+
+#ifdef HAVE_STDIO_H
+extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp,
+ SDL_bool autoclose);
+#else
+extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(void * fp,
+ SDL_bool autoclose);
+#endif
+
+extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, int size);
+extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem(const void *mem,
+ int size);
+
+/* @} *//* RWFrom functions */
+
+
+extern DECLSPEC SDL_RWops *SDLCALL SDL_AllocRW(void);
+extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops * area);
+
+#define RW_SEEK_SET 0 /**< Seek from the beginning of data */
+#define RW_SEEK_CUR 1 /**< Seek relative to current read point */
+#define RW_SEEK_END 2 /**< Seek relative to the end of data */
+
+/**
+ * \name Read/write macros
+ *
+ * Macros to easily read and write from an SDL_RWops structure.
+ */
+/* @{ */
+#define SDL_RWsize(ctx) (ctx)->size(ctx)
+#define SDL_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence)
+#define SDL_RWtell(ctx) (ctx)->seek(ctx, 0, RW_SEEK_CUR)
+#define SDL_RWread(ctx, ptr, size, n) (ctx)->read(ctx, ptr, size, n)
+#define SDL_RWwrite(ctx, ptr, size, n) (ctx)->write(ctx, ptr, size, n)
+#define SDL_RWclose(ctx) (ctx)->close(ctx)
+/* @} *//* Read/write macros */
+
+
+/**
+ * Load all the data from an SDL data stream.
+ *
+ * The data is allocated with a zero byte at the end (null terminated)
+ *
+ * If \c datasize is not NULL, it is filled with the size of the data read.
+ *
+ * If \c freesrc is non-zero, the stream will be closed after being read.
+ *
+ * The data should be freed with SDL_free().
+ *
+ * \return the data, or NULL if there was an error.
+ */
+extern DECLSPEC void *SDLCALL SDL_LoadFile_RW(SDL_RWops * src, size_t *datasize,
+ int freesrc);
+
+/**
+ * Load an entire file.
+ *
+ * Convenience macro.
+ */
+#define SDL_LoadFile(file, datasize) SDL_LoadFile_RW(SDL_RWFromFile(file, "rb"), datasize, 1)
+
+/**
+ * \name Read endian functions
+ *
+ * Read an item of the specified endianness and return in native format.
+ */
+/* @{ */
+extern DECLSPEC Uint8 SDLCALL SDL_ReadU8(SDL_RWops * src);
+extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops * src);
+extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops * src);
+extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops * src);
+extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops * src);
+extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops * src);
+extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops * src);
+/* @} *//* Read endian functions */
+
+/**
+ * \name Write endian functions
+ *
+ * Write an item of native format to the specified endianness.
+ */
+/* @{ */
+extern DECLSPEC size_t SDLCALL SDL_WriteU8(SDL_RWops * dst, Uint8 value);
+extern DECLSPEC size_t SDLCALL SDL_WriteLE16(SDL_RWops * dst, Uint16 value);
+extern DECLSPEC size_t SDLCALL SDL_WriteBE16(SDL_RWops * dst, Uint16 value);
+extern DECLSPEC size_t SDLCALL SDL_WriteLE32(SDL_RWops * dst, Uint32 value);
+extern DECLSPEC size_t SDLCALL SDL_WriteBE32(SDL_RWops * dst, Uint32 value);
+extern DECLSPEC size_t SDLCALL SDL_WriteLE64(SDL_RWops * dst, Uint64 value);
+extern DECLSPEC size_t SDLCALL SDL_WriteBE64(SDL_RWops * dst, Uint64 value);
+/* @} *//* Write endian functions */
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_rwops_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_scancode.h b/src/3rdparty/SDL2/include/SDL_scancode.h
new file mode 100644
index 0000000..63871aa
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_scancode.h
@@ -0,0 +1,413 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_scancode.h
+ *
+ * Defines keyboard scancodes.
+ */
+
+#ifndef SDL_scancode_h_
+#define SDL_scancode_h_
+
+#include "SDL_stdinc.h"
+
+/**
+ * \brief The SDL keyboard scancode representation.
+ *
+ * Values of this type are used to represent keyboard keys, among other places
+ * in the \link SDL_Keysym::scancode key.keysym.scancode \endlink field of the
+ * SDL_Event structure.
+ *
+ * The values in this enumeration are based on the USB usage page standard:
+ * http://www.usb.org/developers/hidpage/Hut1_12v2.pdf
+ */
+typedef enum
+{
+ SDL_SCANCODE_UNKNOWN = 0,
+
+ /**
+ * \name Usage page 0x07
+ *
+ * These values are from usage page 0x07 (USB keyboard page).
+ */
+ /* @{ */
+
+ SDL_SCANCODE_A = 4,
+ SDL_SCANCODE_B = 5,
+ SDL_SCANCODE_C = 6,
+ SDL_SCANCODE_D = 7,
+ SDL_SCANCODE_E = 8,
+ SDL_SCANCODE_F = 9,
+ SDL_SCANCODE_G = 10,
+ SDL_SCANCODE_H = 11,
+ SDL_SCANCODE_I = 12,
+ SDL_SCANCODE_J = 13,
+ SDL_SCANCODE_K = 14,
+ SDL_SCANCODE_L = 15,
+ SDL_SCANCODE_M = 16,
+ SDL_SCANCODE_N = 17,
+ SDL_SCANCODE_O = 18,
+ SDL_SCANCODE_P = 19,
+ SDL_SCANCODE_Q = 20,
+ SDL_SCANCODE_R = 21,
+ SDL_SCANCODE_S = 22,
+ SDL_SCANCODE_T = 23,
+ SDL_SCANCODE_U = 24,
+ SDL_SCANCODE_V = 25,
+ SDL_SCANCODE_W = 26,
+ SDL_SCANCODE_X = 27,
+ SDL_SCANCODE_Y = 28,
+ SDL_SCANCODE_Z = 29,
+
+ SDL_SCANCODE_1 = 30,
+ SDL_SCANCODE_2 = 31,
+ SDL_SCANCODE_3 = 32,
+ SDL_SCANCODE_4 = 33,
+ SDL_SCANCODE_5 = 34,
+ SDL_SCANCODE_6 = 35,
+ SDL_SCANCODE_7 = 36,
+ SDL_SCANCODE_8 = 37,
+ SDL_SCANCODE_9 = 38,
+ SDL_SCANCODE_0 = 39,
+
+ SDL_SCANCODE_RETURN = 40,
+ SDL_SCANCODE_ESCAPE = 41,
+ SDL_SCANCODE_BACKSPACE = 42,
+ SDL_SCANCODE_TAB = 43,
+ SDL_SCANCODE_SPACE = 44,
+
+ SDL_SCANCODE_MINUS = 45,
+ SDL_SCANCODE_EQUALS = 46,
+ SDL_SCANCODE_LEFTBRACKET = 47,
+ SDL_SCANCODE_RIGHTBRACKET = 48,
+ SDL_SCANCODE_BACKSLASH = 49, /**< Located at the lower left of the return
+ * key on ISO keyboards and at the right end
+ * of the QWERTY row on ANSI keyboards.
+ * Produces REVERSE SOLIDUS (backslash) and
+ * VERTICAL LINE in a US layout, REVERSE
+ * SOLIDUS and VERTICAL LINE in a UK Mac
+ * layout, NUMBER SIGN and TILDE in a UK
+ * Windows layout, DOLLAR SIGN and POUND SIGN
+ * in a Swiss German layout, NUMBER SIGN and
+ * APOSTROPHE in a German layout, GRAVE
+ * ACCENT and POUND SIGN in a French Mac
+ * layout, and ASTERISK and MICRO SIGN in a
+ * French Windows layout.
+ */
+ SDL_SCANCODE_NONUSHASH = 50, /**< ISO USB keyboards actually use this code
+ * instead of 49 for the same key, but all
+ * OSes I've seen treat the two codes
+ * identically. So, as an implementor, unless
+ * your keyboard generates both of those
+ * codes and your OS treats them differently,
+ * you should generate SDL_SCANCODE_BACKSLASH
+ * instead of this code. As a user, you
+ * should not rely on this code because SDL
+ * will never generate it with most (all?)
+ * keyboards.
+ */
+ SDL_SCANCODE_SEMICOLON = 51,
+ SDL_SCANCODE_APOSTROPHE = 52,
+ SDL_SCANCODE_GRAVE = 53, /**< Located in the top left corner (on both ANSI
+ * and ISO keyboards). Produces GRAVE ACCENT and
+ * TILDE in a US Windows layout and in US and UK
+ * Mac layouts on ANSI keyboards, GRAVE ACCENT
+ * and NOT SIGN in a UK Windows layout, SECTION
+ * SIGN and PLUS-MINUS SIGN in US and UK Mac
+ * layouts on ISO keyboards, SECTION SIGN and
+ * DEGREE SIGN in a Swiss German layout (Mac:
+ * only on ISO keyboards), CIRCUMFLEX ACCENT and
+ * DEGREE SIGN in a German layout (Mac: only on
+ * ISO keyboards), SUPERSCRIPT TWO and TILDE in a
+ * French Windows layout, COMMERCIAL AT and
+ * NUMBER SIGN in a French Mac layout on ISO
+ * keyboards, and LESS-THAN SIGN and GREATER-THAN
+ * SIGN in a Swiss German, German, or French Mac
+ * layout on ANSI keyboards.
+ */
+ SDL_SCANCODE_COMMA = 54,
+ SDL_SCANCODE_PERIOD = 55,
+ SDL_SCANCODE_SLASH = 56,
+
+ SDL_SCANCODE_CAPSLOCK = 57,
+
+ SDL_SCANCODE_F1 = 58,
+ SDL_SCANCODE_F2 = 59,
+ SDL_SCANCODE_F3 = 60,
+ SDL_SCANCODE_F4 = 61,
+ SDL_SCANCODE_F5 = 62,
+ SDL_SCANCODE_F6 = 63,
+ SDL_SCANCODE_F7 = 64,
+ SDL_SCANCODE_F8 = 65,
+ SDL_SCANCODE_F9 = 66,
+ SDL_SCANCODE_F10 = 67,
+ SDL_SCANCODE_F11 = 68,
+ SDL_SCANCODE_F12 = 69,
+
+ SDL_SCANCODE_PRINTSCREEN = 70,
+ SDL_SCANCODE_SCROLLLOCK = 71,
+ SDL_SCANCODE_PAUSE = 72,
+ SDL_SCANCODE_INSERT = 73, /**< insert on PC, help on some Mac keyboards (but
+ does send code 73, not 117) */
+ SDL_SCANCODE_HOME = 74,
+ SDL_SCANCODE_PAGEUP = 75,
+ SDL_SCANCODE_DELETE = 76,
+ SDL_SCANCODE_END = 77,
+ SDL_SCANCODE_PAGEDOWN = 78,
+ SDL_SCANCODE_RIGHT = 79,
+ SDL_SCANCODE_LEFT = 80,
+ SDL_SCANCODE_DOWN = 81,
+ SDL_SCANCODE_UP = 82,
+
+ SDL_SCANCODE_NUMLOCKCLEAR = 83, /**< num lock on PC, clear on Mac keyboards
+ */
+ SDL_SCANCODE_KP_DIVIDE = 84,
+ SDL_SCANCODE_KP_MULTIPLY = 85,
+ SDL_SCANCODE_KP_MINUS = 86,
+ SDL_SCANCODE_KP_PLUS = 87,
+ SDL_SCANCODE_KP_ENTER = 88,
+ SDL_SCANCODE_KP_1 = 89,
+ SDL_SCANCODE_KP_2 = 90,
+ SDL_SCANCODE_KP_3 = 91,
+ SDL_SCANCODE_KP_4 = 92,
+ SDL_SCANCODE_KP_5 = 93,
+ SDL_SCANCODE_KP_6 = 94,
+ SDL_SCANCODE_KP_7 = 95,
+ SDL_SCANCODE_KP_8 = 96,
+ SDL_SCANCODE_KP_9 = 97,
+ SDL_SCANCODE_KP_0 = 98,
+ SDL_SCANCODE_KP_PERIOD = 99,
+
+ SDL_SCANCODE_NONUSBACKSLASH = 100, /**< This is the additional key that ISO
+ * keyboards have over ANSI ones,
+ * located between left shift and Y.
+ * Produces GRAVE ACCENT and TILDE in a
+ * US or UK Mac layout, REVERSE SOLIDUS
+ * (backslash) and VERTICAL LINE in a
+ * US or UK Windows layout, and
+ * LESS-THAN SIGN and GREATER-THAN SIGN
+ * in a Swiss German, German, or French
+ * layout. */
+ SDL_SCANCODE_APPLICATION = 101, /**< windows contextual menu, compose */
+ SDL_SCANCODE_POWER = 102, /**< The USB document says this is a status flag,
+ * not a physical key - but some Mac keyboards
+ * do have a power key. */
+ SDL_SCANCODE_KP_EQUALS = 103,
+ SDL_SCANCODE_F13 = 104,
+ SDL_SCANCODE_F14 = 105,
+ SDL_SCANCODE_F15 = 106,
+ SDL_SCANCODE_F16 = 107,
+ SDL_SCANCODE_F17 = 108,
+ SDL_SCANCODE_F18 = 109,
+ SDL_SCANCODE_F19 = 110,
+ SDL_SCANCODE_F20 = 111,
+ SDL_SCANCODE_F21 = 112,
+ SDL_SCANCODE_F22 = 113,
+ SDL_SCANCODE_F23 = 114,
+ SDL_SCANCODE_F24 = 115,
+ SDL_SCANCODE_EXECUTE = 116,
+ SDL_SCANCODE_HELP = 117,
+ SDL_SCANCODE_MENU = 118,
+ SDL_SCANCODE_SELECT = 119,
+ SDL_SCANCODE_STOP = 120,
+ SDL_SCANCODE_AGAIN = 121, /**< redo */
+ SDL_SCANCODE_UNDO = 122,
+ SDL_SCANCODE_CUT = 123,
+ SDL_SCANCODE_COPY = 124,
+ SDL_SCANCODE_PASTE = 125,
+ SDL_SCANCODE_FIND = 126,
+ SDL_SCANCODE_MUTE = 127,
+ SDL_SCANCODE_VOLUMEUP = 128,
+ SDL_SCANCODE_VOLUMEDOWN = 129,
+/* not sure whether there's a reason to enable these */
+/* SDL_SCANCODE_LOCKINGCAPSLOCK = 130, */
+/* SDL_SCANCODE_LOCKINGNUMLOCK = 131, */
+/* SDL_SCANCODE_LOCKINGSCROLLLOCK = 132, */
+ SDL_SCANCODE_KP_COMMA = 133,
+ SDL_SCANCODE_KP_EQUALSAS400 = 134,
+
+ SDL_SCANCODE_INTERNATIONAL1 = 135, /**< used on Asian keyboards, see
+ footnotes in USB doc */
+ SDL_SCANCODE_INTERNATIONAL2 = 136,
+ SDL_SCANCODE_INTERNATIONAL3 = 137, /**< Yen */
+ SDL_SCANCODE_INTERNATIONAL4 = 138,
+ SDL_SCANCODE_INTERNATIONAL5 = 139,
+ SDL_SCANCODE_INTERNATIONAL6 = 140,
+ SDL_SCANCODE_INTERNATIONAL7 = 141,
+ SDL_SCANCODE_INTERNATIONAL8 = 142,
+ SDL_SCANCODE_INTERNATIONAL9 = 143,
+ SDL_SCANCODE_LANG1 = 144, /**< Hangul/English toggle */
+ SDL_SCANCODE_LANG2 = 145, /**< Hanja conversion */
+ SDL_SCANCODE_LANG3 = 146, /**< Katakana */
+ SDL_SCANCODE_LANG4 = 147, /**< Hiragana */
+ SDL_SCANCODE_LANG5 = 148, /**< Zenkaku/Hankaku */
+ SDL_SCANCODE_LANG6 = 149, /**< reserved */
+ SDL_SCANCODE_LANG7 = 150, /**< reserved */
+ SDL_SCANCODE_LANG8 = 151, /**< reserved */
+ SDL_SCANCODE_LANG9 = 152, /**< reserved */
+
+ SDL_SCANCODE_ALTERASE = 153, /**< Erase-Eaze */
+ SDL_SCANCODE_SYSREQ = 154,
+ SDL_SCANCODE_CANCEL = 155,
+ SDL_SCANCODE_CLEAR = 156,
+ SDL_SCANCODE_PRIOR = 157,
+ SDL_SCANCODE_RETURN2 = 158,
+ SDL_SCANCODE_SEPARATOR = 159,
+ SDL_SCANCODE_OUT = 160,
+ SDL_SCANCODE_OPER = 161,
+ SDL_SCANCODE_CLEARAGAIN = 162,
+ SDL_SCANCODE_CRSEL = 163,
+ SDL_SCANCODE_EXSEL = 164,
+
+ SDL_SCANCODE_KP_00 = 176,
+ SDL_SCANCODE_KP_000 = 177,
+ SDL_SCANCODE_THOUSANDSSEPARATOR = 178,
+ SDL_SCANCODE_DECIMALSEPARATOR = 179,
+ SDL_SCANCODE_CURRENCYUNIT = 180,
+ SDL_SCANCODE_CURRENCYSUBUNIT = 181,
+ SDL_SCANCODE_KP_LEFTPAREN = 182,
+ SDL_SCANCODE_KP_RIGHTPAREN = 183,
+ SDL_SCANCODE_KP_LEFTBRACE = 184,
+ SDL_SCANCODE_KP_RIGHTBRACE = 185,
+ SDL_SCANCODE_KP_TAB = 186,
+ SDL_SCANCODE_KP_BACKSPACE = 187,
+ SDL_SCANCODE_KP_A = 188,
+ SDL_SCANCODE_KP_B = 189,
+ SDL_SCANCODE_KP_C = 190,
+ SDL_SCANCODE_KP_D = 191,
+ SDL_SCANCODE_KP_E = 192,
+ SDL_SCANCODE_KP_F = 193,
+ SDL_SCANCODE_KP_XOR = 194,
+ SDL_SCANCODE_KP_POWER = 195,
+ SDL_SCANCODE_KP_PERCENT = 196,
+ SDL_SCANCODE_KP_LESS = 197,
+ SDL_SCANCODE_KP_GREATER = 198,
+ SDL_SCANCODE_KP_AMPERSAND = 199,
+ SDL_SCANCODE_KP_DBLAMPERSAND = 200,
+ SDL_SCANCODE_KP_VERTICALBAR = 201,
+ SDL_SCANCODE_KP_DBLVERTICALBAR = 202,
+ SDL_SCANCODE_KP_COLON = 203,
+ SDL_SCANCODE_KP_HASH = 204,
+ SDL_SCANCODE_KP_SPACE = 205,
+ SDL_SCANCODE_KP_AT = 206,
+ SDL_SCANCODE_KP_EXCLAM = 207,
+ SDL_SCANCODE_KP_MEMSTORE = 208,
+ SDL_SCANCODE_KP_MEMRECALL = 209,
+ SDL_SCANCODE_KP_MEMCLEAR = 210,
+ SDL_SCANCODE_KP_MEMADD = 211,
+ SDL_SCANCODE_KP_MEMSUBTRACT = 212,
+ SDL_SCANCODE_KP_MEMMULTIPLY = 213,
+ SDL_SCANCODE_KP_MEMDIVIDE = 214,
+ SDL_SCANCODE_KP_PLUSMINUS = 215,
+ SDL_SCANCODE_KP_CLEAR = 216,
+ SDL_SCANCODE_KP_CLEARENTRY = 217,
+ SDL_SCANCODE_KP_BINARY = 218,
+ SDL_SCANCODE_KP_OCTAL = 219,
+ SDL_SCANCODE_KP_DECIMAL = 220,
+ SDL_SCANCODE_KP_HEXADECIMAL = 221,
+
+ SDL_SCANCODE_LCTRL = 224,
+ SDL_SCANCODE_LSHIFT = 225,
+ SDL_SCANCODE_LALT = 226, /**< alt, option */
+ SDL_SCANCODE_LGUI = 227, /**< windows, command (apple), meta */
+ SDL_SCANCODE_RCTRL = 228,
+ SDL_SCANCODE_RSHIFT = 229,
+ SDL_SCANCODE_RALT = 230, /**< alt gr, option */
+ SDL_SCANCODE_RGUI = 231, /**< windows, command (apple), meta */
+
+ SDL_SCANCODE_MODE = 257, /**< I'm not sure if this is really not covered
+ * by any of the above, but since there's a
+ * special KMOD_MODE for it I'm adding it here
+ */
+
+ /* @} *//* Usage page 0x07 */
+
+ /**
+ * \name Usage page 0x0C
+ *
+ * These values are mapped from usage page 0x0C (USB consumer page).
+ */
+ /* @{ */
+
+ SDL_SCANCODE_AUDIONEXT = 258,
+ SDL_SCANCODE_AUDIOPREV = 259,
+ SDL_SCANCODE_AUDIOSTOP = 260,
+ SDL_SCANCODE_AUDIOPLAY = 261,
+ SDL_SCANCODE_AUDIOMUTE = 262,
+ SDL_SCANCODE_MEDIASELECT = 263,
+ SDL_SCANCODE_WWW = 264,
+ SDL_SCANCODE_MAIL = 265,
+ SDL_SCANCODE_CALCULATOR = 266,
+ SDL_SCANCODE_COMPUTER = 267,
+ SDL_SCANCODE_AC_SEARCH = 268,
+ SDL_SCANCODE_AC_HOME = 269,
+ SDL_SCANCODE_AC_BACK = 270,
+ SDL_SCANCODE_AC_FORWARD = 271,
+ SDL_SCANCODE_AC_STOP = 272,
+ SDL_SCANCODE_AC_REFRESH = 273,
+ SDL_SCANCODE_AC_BOOKMARKS = 274,
+
+ /* @} *//* Usage page 0x0C */
+
+ /**
+ * \name Walther keys
+ *
+ * These are values that Christian Walther added (for mac keyboard?).
+ */
+ /* @{ */
+
+ SDL_SCANCODE_BRIGHTNESSDOWN = 275,
+ SDL_SCANCODE_BRIGHTNESSUP = 276,
+ SDL_SCANCODE_DISPLAYSWITCH = 277, /**< display mirroring/dual display
+ switch, video mode switch */
+ SDL_SCANCODE_KBDILLUMTOGGLE = 278,
+ SDL_SCANCODE_KBDILLUMDOWN = 279,
+ SDL_SCANCODE_KBDILLUMUP = 280,
+ SDL_SCANCODE_EJECT = 281,
+ SDL_SCANCODE_SLEEP = 282,
+
+ SDL_SCANCODE_APP1 = 283,
+ SDL_SCANCODE_APP2 = 284,
+
+ /* @} *//* Walther keys */
+
+ /**
+ * \name Usage page 0x0C (additional media keys)
+ *
+ * These values are mapped from usage page 0x0C (USB consumer page).
+ */
+ /* @{ */
+
+ SDL_SCANCODE_AUDIOREWIND = 285,
+ SDL_SCANCODE_AUDIOFASTFORWARD = 286,
+
+ /* @} *//* Usage page 0x0C (additional media keys) */
+
+ /* Add any other keys here. */
+
+ SDL_NUM_SCANCODES = 512 /**< not a key, just marks the number of scancodes
+ for array bounds */
+} SDL_Scancode;
+
+#endif /* SDL_scancode_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_shape.h b/src/3rdparty/SDL2/include/SDL_shape.h
new file mode 100644
index 0000000..40a6baa
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_shape.h
@@ -0,0 +1,144 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_shape_h_
+#define SDL_shape_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_pixels.h"
+#include "SDL_rect.h"
+#include "SDL_surface.h"
+#include "SDL_video.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** \file SDL_shape.h
+ *
+ * Header file for the shaped window API.
+ */
+
+#define SDL_NONSHAPEABLE_WINDOW -1
+#define SDL_INVALID_SHAPE_ARGUMENT -2
+#define SDL_WINDOW_LACKS_SHAPE -3
+
+/**
+ * \brief Create a window that can be shaped with the specified position, dimensions, and flags.
+ *
+ * \param title The title of the window, in UTF-8 encoding.
+ * \param x The x position of the window, ::SDL_WINDOWPOS_CENTERED, or
+ * ::SDL_WINDOWPOS_UNDEFINED.
+ * \param y The y position of the window, ::SDL_WINDOWPOS_CENTERED, or
+ * ::SDL_WINDOWPOS_UNDEFINED.
+ * \param w The width of the window.
+ * \param h The height of the window.
+ * \param flags The flags for the window, a mask of SDL_WINDOW_BORDERLESS with any of the following:
+ * ::SDL_WINDOW_OPENGL, ::SDL_WINDOW_INPUT_GRABBED,
+ * ::SDL_WINDOW_HIDDEN, ::SDL_WINDOW_RESIZABLE,
+ * ::SDL_WINDOW_MAXIMIZED, ::SDL_WINDOW_MINIMIZED,
+ * ::SDL_WINDOW_BORDERLESS is always set, and ::SDL_WINDOW_FULLSCREEN is always unset.
+ *
+ * \return The window created, or NULL if window creation failed.
+ *
+ * \sa SDL_DestroyWindow()
+ */
+extern DECLSPEC SDL_Window * SDLCALL SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags);
+
+/**
+ * \brief Return whether the given window is a shaped window.
+ *
+ * \param window The window to query for being shaped.
+ *
+ * \return SDL_TRUE if the window is a window that can be shaped, SDL_FALSE if the window is unshaped or NULL.
+ *
+ * \sa SDL_CreateShapedWindow
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_IsShapedWindow(const SDL_Window *window);
+
+/** \brief An enum denoting the specific type of contents present in an SDL_WindowShapeParams union. */
+typedef enum {
+ /** \brief The default mode, a binarized alpha cutoff of 1. */
+ ShapeModeDefault,
+ /** \brief A binarized alpha cutoff with a given integer value. */
+ ShapeModeBinarizeAlpha,
+ /** \brief A binarized alpha cutoff with a given integer value, but with the opposite comparison. */
+ ShapeModeReverseBinarizeAlpha,
+ /** \brief A color key is applied. */
+ ShapeModeColorKey
+} WindowShapeMode;
+
+#define SDL_SHAPEMODEALPHA(mode) (mode == ShapeModeDefault || mode == ShapeModeBinarizeAlpha || mode == ShapeModeReverseBinarizeAlpha)
+
+/** \brief A union containing parameters for shaped windows. */
+typedef union {
+ /** \brief A cutoff alpha value for binarization of the window shape's alpha channel. */
+ Uint8 binarizationCutoff;
+ SDL_Color colorKey;
+} SDL_WindowShapeParams;
+
+/** \brief A struct that tags the SDL_WindowShapeParams union with an enum describing the type of its contents. */
+typedef struct SDL_WindowShapeMode {
+ /** \brief The mode of these window-shape parameters. */
+ WindowShapeMode mode;
+ /** \brief Window-shape parameters. */
+ SDL_WindowShapeParams parameters;
+} SDL_WindowShapeMode;
+
+/**
+ * \brief Set the shape and parameters of a shaped window.
+ *
+ * \param window The shaped window whose parameters should be set.
+ * \param shape A surface encoding the desired shape for the window.
+ * \param shape_mode The parameters to set for the shaped window.
+ *
+ * \return 0 on success, SDL_INVALID_SHAPE_ARGUMENT on an invalid shape argument, or SDL_NONSHAPEABLE_WINDOW
+ * if the SDL_Window given does not reference a valid shaped window.
+ *
+ * \sa SDL_WindowShapeMode
+ * \sa SDL_GetShapedWindowMode.
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
+
+/**
+ * \brief Get the shape parameters of a shaped window.
+ *
+ * \param window The shaped window whose parameters should be retrieved.
+ * \param shape_mode An empty shape-mode structure to fill, or NULL to check whether the window has a shape.
+ *
+ * \return 0 if the window has a shape and, provided shape_mode was not NULL, shape_mode has been filled with the mode
+ * data, SDL_NONSHAPEABLE_WINDOW if the SDL_Window given is not a shaped window, or SDL_WINDOW_LACKS_SHAPE if
+ * the SDL_Window given is a shapeable window currently lacking a shape.
+ *
+ * \sa SDL_WindowShapeMode
+ * \sa SDL_SetWindowShape
+ */
+extern DECLSPEC int SDLCALL SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shape_mode);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_shape_h_ */
diff --git a/src/3rdparty/SDL2/include/SDL_stdinc.h b/src/3rdparty/SDL2/include/SDL_stdinc.h
new file mode 100644
index 0000000..111a064
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_stdinc.h
@@ -0,0 +1,605 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_stdinc.h
+ *
+ * This is a general header that includes C language support.
+ */
+
+#ifndef SDL_stdinc_h_
+#define SDL_stdinc_h_
+
+#include "SDL_config.h"
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_STDIO_H
+#include <stdio.h>
+#endif
+#if defined(STDC_HEADERS)
+# include <stdlib.h>
+# include <stddef.h>
+# include <stdarg.h>
+#else
+# if defined(HAVE_STDLIB_H)
+# include <stdlib.h>
+# elif defined(HAVE_MALLOC_H)
+# include <malloc.h>
+# endif
+# if defined(HAVE_STDDEF_H)
+# include <stddef.h>
+# endif
+# if defined(HAVE_STDARG_H)
+# include <stdarg.h>
+# endif
+#endif
+#ifdef HAVE_STRING_H
+# if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
+# include <memory.h>
+# endif
+# include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#ifdef HAVE_WCHAR_H
+# include <wchar.h>
+#endif
+#if defined(HAVE_INTTYPES_H)
+# include <inttypes.h>
+#elif defined(HAVE_STDINT_H)
+# include <stdint.h>
+#endif
+#ifdef HAVE_CTYPE_H
+# include <ctype.h>
+#endif
+#ifdef HAVE_MATH_H
+# if defined(__WINRT__)
+/* Defining _USE_MATH_DEFINES is required to get M_PI to be defined on
+ WinRT. See http://msdn.microsoft.com/en-us/library/4hwaceh6.aspx
+ for more information.
+*/
+# define _USE_MATH_DEFINES
+# endif
+# include <math.h>
+#endif
+#ifdef HAVE_FLOAT_H
+# include <float.h>
+#endif
+
+/**
+ * The number of elements in an array.
+ */
+#define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
+#define SDL_TABLESIZE(table) SDL_arraysize(table)
+
+/**
+ * Macro useful for building other macros with strings in them
+ *
+ * e.g. #define LOG_ERROR(X) OutputDebugString(SDL_STRINGIFY_ARG(__FUNCTION__) ": " X "\n")
+ */
+#define SDL_STRINGIFY_ARG(arg) #arg
+
+/**
+ * \name Cast operators
+ *
+ * Use proper C++ casts when compiled as C++ to be compatible with the option
+ * -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
+ */
+/* @{ */
+#ifdef __cplusplus
+#define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
+#define SDL_static_cast(type, expression) static_cast<type>(expression)
+#define SDL_const_cast(type, expression) const_cast<type>(expression)
+#else
+#define SDL_reinterpret_cast(type, expression) ((type)(expression))
+#define SDL_static_cast(type, expression) ((type)(expression))
+#define SDL_const_cast(type, expression) ((type)(expression))
+#endif
+/* @} *//* Cast operators */
+
+/* Define a four character code as a Uint32 */
+#define SDL_FOURCC(A, B, C, D) \
+ ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
+ (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
+ (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
+ (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
+
+/**
+ * \name Basic data types
+ */
+/* @{ */
+
+#ifdef __CC_ARM
+/* ARM's compiler throws warnings if we use an enum: like "SDL_bool x = a < b;" */
+#define SDL_FALSE 0
+#define SDL_TRUE 1
+typedef int SDL_bool;
+#else
+typedef enum
+{
+ SDL_FALSE = 0,
+ SDL_TRUE = 1
+} SDL_bool;
+#endif
+
+/**
+ * \brief A signed 8-bit integer type.
+ */
+#define SDL_MAX_SINT8 ((Sint8)0x7F) /* 127 */
+#define SDL_MIN_SINT8 ((Sint8)(~0x7F)) /* -128 */
+typedef int8_t Sint8;
+/**
+ * \brief An unsigned 8-bit integer type.
+ */
+#define SDL_MAX_UINT8 ((Uint8)0xFF) /* 255 */
+#define SDL_MIN_UINT8 ((Uint8)0x00) /* 0 */
+typedef uint8_t Uint8;
+/**
+ * \brief A signed 16-bit integer type.
+ */
+#define SDL_MAX_SINT16 ((Sint16)0x7FFF) /* 32767 */
+#define SDL_MIN_SINT16 ((Sint16)(~0x7FFF)) /* -32768 */
+typedef int16_t Sint16;
+/**
+ * \brief An unsigned 16-bit integer type.
+ */
+#define SDL_MAX_UINT16 ((Uint16)0xFFFF) /* 65535 */
+#define SDL_MIN_UINT16 ((Uint16)0x0000) /* 0 */
+typedef uint16_t Uint16;
+/**
+ * \brief A signed 32-bit integer type.
+ */
+#define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */
+#define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
+typedef int32_t Sint32;
+/**
+ * \brief An unsigned 32-bit integer type.
+ */
+#define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu) /* 4294967295 */
+#define SDL_MIN_UINT32 ((Uint32)0x00000000) /* 0 */
+typedef uint32_t Uint32;
+
+/**
+ * \brief A signed 64-bit integer type.
+ */
+#define SDL_MAX_SINT64 ((Sint64)0x7FFFFFFFFFFFFFFFll) /* 9223372036854775807 */
+#define SDL_MIN_SINT64 ((Sint64)(~0x7FFFFFFFFFFFFFFFll)) /* -9223372036854775808 */
+typedef int64_t Sint64;
+/**
+ * \brief An unsigned 64-bit integer type.
+ */
+#define SDL_MAX_UINT64 ((Uint64)0xFFFFFFFFFFFFFFFFull) /* 18446744073709551615 */
+#define SDL_MIN_UINT64 ((Uint64)(0x0000000000000000ull)) /* 0 */
+typedef uint64_t Uint64;
+
+/* @} *//* Basic data types */
+
+/* Make sure we have macros for printing 64 bit values.
+ * <stdint.h> should define these but this is not true all platforms.
+ * (for example win32) */
+#ifndef SDL_PRIs64
+#ifdef PRIs64
+#define SDL_PRIs64 PRIs64
+#elif defined(__WIN32__)
+#define SDL_PRIs64 "I64d"
+#elif defined(__LINUX__) && defined(__LP64__)
+#define SDL_PRIs64 "ld"
+#else
+#define SDL_PRIs64 "lld"
+#endif
+#endif
+#ifndef SDL_PRIu64
+#ifdef PRIu64
+#define SDL_PRIu64 PRIu64
+#elif defined(__WIN32__)
+#define SDL_PRIu64 "I64u"
+#elif defined(__LINUX__) && defined(__LP64__)
+#define SDL_PRIu64 "lu"
+#else
+#define SDL_PRIu64 "llu"
+#endif
+#endif
+#ifndef SDL_PRIx64
+#ifdef PRIx64
+#define SDL_PRIx64 PRIx64
+#elif defined(__WIN32__)
+#define SDL_PRIx64 "I64x"
+#elif defined(__LINUX__) && defined(__LP64__)
+#define SDL_PRIx64 "lx"
+#else
+#define SDL_PRIx64 "llx"
+#endif
+#endif
+#ifndef SDL_PRIX64
+#ifdef PRIX64
+#define SDL_PRIX64 PRIX64
+#elif defined(__WIN32__)
+#define SDL_PRIX64 "I64X"
+#elif defined(__LINUX__) && defined(__LP64__)
+#define SDL_PRIX64 "lX"
+#else
+#define SDL_PRIX64 "llX"
+#endif
+#endif
+
+/* Annotations to help code analysis tools */
+#ifdef SDL_DISABLE_ANALYZE_MACROS
+#define SDL_IN_BYTECAP(x)
+#define SDL_INOUT_Z_CAP(x)
+#define SDL_OUT_Z_CAP(x)
+#define SDL_OUT_CAP(x)
+#define SDL_OUT_BYTECAP(x)
+#define SDL_OUT_Z_BYTECAP(x)
+#define SDL_PRINTF_FORMAT_STRING
+#define SDL_SCANF_FORMAT_STRING
+#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
+#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
+#else
+#if defined(_MSC_VER) && (_MSC_VER >= 1600) /* VS 2010 and above */
+#include <sal.h>
+
+#define SDL_IN_BYTECAP(x) _In_bytecount_(x)
+#define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
+#define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
+#define SDL_OUT_CAP(x) _Out_cap_(x)
+#define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
+#define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
+
+#define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
+#define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
+#else
+#define SDL_IN_BYTECAP(x)
+#define SDL_INOUT_Z_CAP(x)
+#define SDL_OUT_Z_CAP(x)
+#define SDL_OUT_CAP(x)
+#define SDL_OUT_BYTECAP(x)
+#define SDL_OUT_Z_BYTECAP(x)
+#define SDL_PRINTF_FORMAT_STRING
+#define SDL_SCANF_FORMAT_STRING
+#endif
+#if defined(__GNUC__)
+#define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
+#define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
+#else
+#define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
+#define SDL_SCANF_VARARG_FUNC( fmtargnumber )
+#endif
+#endif /* SDL_DISABLE_ANALYZE_MACROS */
+
+#define SDL_COMPILE_TIME_ASSERT(name, x) \
+ typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
+/** \cond */
+#ifndef DOXYGEN_SHOULD_IGNORE_THIS
+SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
+SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
+SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
+SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
+SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
+SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
+SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
+SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
+#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
+/** \endcond */
+
+/* Check to make sure enums are the size of ints, for structure packing.
+ For both Watcom C/C++ and Borland C/C++ the compiler option that makes
+ enums having the size of an int must be enabled.
+ This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
+*/
+
+/** \cond */
+#ifndef DOXYGEN_SHOULD_IGNORE_THIS
+#if !defined(__ANDROID__)
+ /* TODO: include/SDL_stdinc.h:174: error: size of array 'SDL_dummy_enum' is negative */
+typedef enum
+{
+ DUMMY_ENUM_VALUE
+} SDL_DUMMY_ENUM;
+
+SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
+#endif
+#endif /* DOXYGEN_SHOULD_IGNORE_THIS */
+/** \endcond */
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if defined(HAVE_ALLOCA) && !defined(alloca)
+# if defined(HAVE_ALLOCA_H)
+# include <alloca.h>
+# elif defined(__GNUC__)
+# define alloca __builtin_alloca
+# elif defined(_MSC_VER)
+# include <malloc.h>
+# define alloca _alloca
+# elif defined(__WATCOMC__)
+# include <malloc.h>
+# elif defined(__BORLANDC__)
+# include <malloc.h>
+# elif defined(__DMC__)
+# include <stdlib.h>
+# elif defined(__AIX__)
+#pragma alloca
+# elif defined(__MRC__)
+void *alloca(unsigned);
+# else
+char *alloca();
+# endif
+#endif
+#ifdef HAVE_ALLOCA
+#define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
+#define SDL_stack_free(data)
+#else
+#define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
+#define SDL_stack_free(data) SDL_free(data)
+#endif
+
+extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
+extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
+extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
+extern DECLSPEC void SDLCALL SDL_free(void *mem);
+
+typedef void *(SDLCALL *SDL_malloc_func)(size_t size);
+typedef void *(SDLCALL *SDL_calloc_func)(size_t nmemb, size_t size);
+typedef void *(SDLCALL *SDL_realloc_func)(void *mem, size_t size);
+typedef void (SDLCALL *SDL_free_func)(void *mem);
+
+/**
+ * \brief Get the current set of SDL memory functions
+ */
+extern DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
+ SDL_calloc_func *calloc_func,
+ SDL_realloc_func *realloc_func,
+ SDL_free_func *free_func);
+
+/**
+ * \brief Replace SDL's memory allocation functions with a custom set
+ *
+ * \note If you are replacing SDL's memory functions, you should call
+ * SDL_GetNumAllocations() and be very careful if it returns non-zero.
+ * That means that your free function will be called with memory
+ * allocated by the previous memory allocation functions.
+ */
+extern DECLSPEC int SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
+ SDL_calloc_func calloc_func,
+ SDL_realloc_func realloc_func,
+ SDL_free_func free_func);
+
+/**
+ * \brief Get the number of outstanding (unfreed) allocations
+ */
+extern DECLSPEC int SDLCALL SDL_GetNumAllocations(void);
+
+extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
+extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
+
+extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));
+
+extern DECLSPEC int SDLCALL SDL_abs(int x);
+
+/* !!! FIXME: these have side effects. You probably shouldn't use them. */
+/* !!! FIXME: Maybe we do forceinline functions of SDL_mini, SDL_minf, etc? */
+#define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
+#define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
+
+extern DECLSPEC int SDLCALL SDL_isdigit(int x);
+extern DECLSPEC int SDLCALL SDL_isspace(int x);
+extern DECLSPEC int SDLCALL SDL_toupper(int x);
+extern DECLSPEC int SDLCALL SDL_tolower(int x);
+
+extern DECLSPEC void *SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
+
+#define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
+#define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
+
+/* Note that memset() is a byte assignment and this is a 32-bit assignment, so they're not directly equivalent. */
+SDL_FORCE_INLINE void SDL_memset4(void *dst, Uint32 val, size_t dwords)
+{
+#if defined(__GNUC__) && defined(i386)
+ int u0, u1, u2;
+ __asm__ __volatile__ (
+ "cld \n\t"
+ "rep ; stosl \n\t"
+ : "=&D" (u0), "=&a" (u1), "=&c" (u2)
+ : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, dwords))
+ : "memory"
+ );
+#else
+ size_t _n = (dwords + 3) / 4;
+ Uint32 *_p = SDL_static_cast(Uint32 *, dst);
+ Uint32 _val = (val);
+ if (dwords == 0)
+ return;
+ switch (dwords % 4)
+ {
+ case 0: do { *_p++ = _val; /* fallthrough */
+ case 3: *_p++ = _val; /* fallthrough */
+ case 2: *_p++ = _val; /* fallthrough */
+ case 1: *_p++ = _val; /* fallthrough */
+ } while ( --_n );
+ }
+#endif
+}
+
+
+extern DECLSPEC void *SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
+
+extern DECLSPEC void *SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
+extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
+
+extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
+extern DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
+extern DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
+extern DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
+
+extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
+extern DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
+extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
+extern DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
+extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
+extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
+extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
+extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);
+extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
+extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
+extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
+extern DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
+
+extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
+extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
+extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
+extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
+extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
+extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
+
+extern DECLSPEC int SDLCALL SDL_atoi(const char *str);
+extern DECLSPEC double SDLCALL SDL_atof(const char *str);
+extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
+extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
+extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
+extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
+extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
+
+extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
+extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
+extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
+extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
+
+extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
+extern DECLSPEC int SDLCALL SDL_vsscanf(const char *text, const char *fmt, va_list ap);
+extern DECLSPEC int SDLCALL SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ... ) SDL_PRINTF_VARARG_FUNC(3);
+extern DECLSPEC int SDLCALL SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap);
+
+#ifndef HAVE_M_PI
+#ifndef M_PI
+#define M_PI 3.14159265358979323846264338327950288 /**< pi */
+#endif
+#endif
+
+extern DECLSPEC double SDLCALL SDL_acos(double x);
+extern DECLSPEC float SDLCALL SDL_acosf(float x);
+extern DECLSPEC double SDLCALL SDL_asin(double x);
+extern DECLSPEC float SDLCALL SDL_asinf(float x);
+extern DECLSPEC double SDLCALL SDL_atan(double x);
+extern DECLSPEC float SDLCALL SDL_atanf(float x);
+extern DECLSPEC double SDLCALL SDL_atan2(double x, double y);
+extern DECLSPEC float SDLCALL SDL_atan2f(float x, float y);
+extern DECLSPEC double SDLCALL SDL_ceil(double x);
+extern DECLSPEC float SDLCALL SDL_ceilf(float x);
+extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
+extern DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
+extern DECLSPEC double SDLCALL SDL_cos(double x);
+extern DECLSPEC float SDLCALL SDL_cosf(float x);
+extern DECLSPEC double SDLCALL SDL_fabs(double x);
+extern DECLSPEC float SDLCALL SDL_fabsf(float x);
+extern DECLSPEC double SDLCALL SDL_floor(double x);
+extern DECLSPEC float SDLCALL SDL_floorf(float x);
+extern DECLSPEC double SDLCALL SDL_fmod(double x, double y);
+extern DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
+extern DECLSPEC double SDLCALL SDL_log(double x);
+extern DECLSPEC float SDLCALL SDL_logf(float x);
+extern DECLSPEC double SDLCALL SDL_log10(double x);
+extern DECLSPEC float SDLCALL SDL_log10f(float x);
+extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
+extern DECLSPEC float SDLCALL SDL_powf(float x, float y);
+extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
+extern DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
+extern DECLSPEC double SDLCALL SDL_sin(double x);
+extern DECLSPEC float SDLCALL SDL_sinf(float x);
+extern DECLSPEC double SDLCALL SDL_sqrt(double x);
+extern DECLSPEC float SDLCALL SDL_sqrtf(float x);
+extern DECLSPEC double SDLCALL SDL_tan(double x);
+extern DECLSPEC float SDLCALL SDL_tanf(float x);
+
+/* The SDL implementation of iconv() returns these error codes */
+#define SDL_ICONV_ERROR (size_t)-1
+#define SDL_ICONV_E2BIG (size_t)-2
+#define SDL_ICONV_EILSEQ (size_t)-3
+#define SDL_ICONV_EINVAL (size_t)-4
+
+/* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
+typedef struct _SDL_iconv_t *SDL_iconv_t;
+extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
+ const char *fromcode);
+extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
+extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
+ size_t * inbytesleft, char **outbuf,
+ size_t * outbytesleft);
+/**
+ * This function converts a string between encodings in one pass, returning a
+ * string that must be freed with SDL_free() or NULL on error.
+ */
+extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
+ const char *fromcode,
+ const char *inbuf,
+ size_t inbytesleft);
+#define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
+#define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
+#define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
+
+/* force builds using Clang's static analysis tools to use literal C runtime
+ here, since there are possibly tests that are ineffective otherwise. */
+#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
+#define SDL_malloc malloc
+#define SDL_calloc calloc
+#define SDL_realloc realloc
+#define SDL_free free
+#define SDL_memset memset
+#define SDL_memcpy memcpy
+#define SDL_memmove memmove
+#define SDL_memcmp memcmp
+#define SDL_strlen strlen
+#define SDL_strlcpy strlcpy
+#define SDL_strlcat strlcat
+#define SDL_strdup strdup
+#define SDL_strchr strchr
+#define SDL_strrchr strrchr
+#define SDL_strstr strstr
+#define SDL_strcmp strcmp
+#define SDL_strncmp strncmp
+#define SDL_strcasecmp strcasecmp
+#define SDL_strncasecmp strncasecmp
+#define SDL_sscanf sscanf
+#define SDL_vsscanf vsscanf
+#define SDL_snprintf snprintf
+#define SDL_vsnprintf vsnprintf
+#endif
+
+SDL_FORCE_INLINE void *SDL_memcpy4(SDL_OUT_BYTECAP(dwords*4) void *dst, SDL_IN_BYTECAP(dwords*4) const void *src, size_t dwords)
+{
+ return SDL_memcpy(dst, src, dwords * 4);
+}
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_stdinc_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_surface.h b/src/3rdparty/SDL2/include/SDL_surface.h
new file mode 100644
index 0000000..45e5366
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_surface.h
@@ -0,0 +1,546 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_surface.h
+ *
+ * Header file for ::SDL_Surface definition and management functions.
+ */
+
+#ifndef SDL_surface_h_
+#define SDL_surface_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_pixels.h"
+#include "SDL_rect.h"
+#include "SDL_blendmode.h"
+#include "SDL_rwops.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \name Surface flags
+ *
+ * These are the currently supported flags for the ::SDL_Surface.
+ *
+ * \internal
+ * Used internally (read-only).
+ */
+/* @{ */
+#define SDL_SWSURFACE 0 /**< Just here for compatibility */
+#define SDL_PREALLOC 0x00000001 /**< Surface uses preallocated memory */
+#define SDL_RLEACCEL 0x00000002 /**< Surface is RLE encoded */
+#define SDL_DONTFREE 0x00000004 /**< Surface is referenced internally */
+/* @} *//* Surface flags */
+
+/**
+ * Evaluates to true if the surface needs to be locked before access.
+ */
+#define SDL_MUSTLOCK(S) (((S)->flags & SDL_RLEACCEL) != 0)
+
+/**
+ * \brief A collection of pixels used in software blitting.
+ *
+ * \note This structure should be treated as read-only, except for \c pixels,
+ * which, if not NULL, contains the raw pixel data for the surface.
+ */
+typedef struct SDL_Surface
+{
+ Uint32 flags; /**< Read-only */
+ SDL_PixelFormat *format; /**< Read-only */
+ int w, h; /**< Read-only */
+ int pitch; /**< Read-only */
+ void *pixels; /**< Read-write */
+
+ /** Application data associated with the surface */
+ void *userdata; /**< Read-write */
+
+ /** information needed for surfaces requiring locks */
+ int locked; /**< Read-only */
+ void *lock_data; /**< Read-only */
+
+ /** clipping information */
+ SDL_Rect clip_rect; /**< Read-only */
+
+ /** info for fast blit mapping to other surfaces */
+ struct SDL_BlitMap *map; /**< Private */
+
+ /** Reference count -- used when freeing surface */
+ int refcount; /**< Read-mostly */
+} SDL_Surface;
+
+/**
+ * \brief The type of function used for surface blitting functions.
+ */
+typedef int (SDLCALL *SDL_blit) (struct SDL_Surface * src, SDL_Rect * srcrect,
+ struct SDL_Surface * dst, SDL_Rect * dstrect);
+
+/**
+ * \brief The formula used for converting between YUV and RGB
+ */
+typedef enum
+{
+ SDL_YUV_CONVERSION_JPEG, /**< Full range JPEG */
+ SDL_YUV_CONVERSION_BT601, /**< BT.601 (the default) */
+ SDL_YUV_CONVERSION_BT709, /**< BT.709 */
+ SDL_YUV_CONVERSION_AUTOMATIC /**< BT.601 for SD content, BT.709 for HD content */
+} SDL_YUV_CONVERSION_MODE;
+
+/**
+ * Allocate and free an RGB surface.
+ *
+ * If the depth is 4 or 8 bits, an empty palette is allocated for the surface.
+ * If the depth is greater than 8 bits, the pixel format is set using the
+ * flags '[RGB]mask'.
+ *
+ * If the function runs out of memory, it will return NULL.
+ *
+ * \param flags The \c flags are obsolete and should be set to 0.
+ * \param width The width in pixels of the surface to create.
+ * \param height The height in pixels of the surface to create.
+ * \param depth The depth in bits of the surface to create.
+ * \param Rmask The red mask of the surface to create.
+ * \param Gmask The green mask of the surface to create.
+ * \param Bmask The blue mask of the surface to create.
+ * \param Amask The alpha mask of the surface to create.
+ */
+extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface
+ (Uint32 flags, int width, int height, int depth,
+ Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
+
+/* !!! FIXME for 2.1: why does this ask for depth? Format provides that. */
+extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormat
+ (Uint32 flags, int width, int height, int depth, Uint32 format);
+
+extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels,
+ int width,
+ int height,
+ int depth,
+ int pitch,
+ Uint32 Rmask,
+ Uint32 Gmask,
+ Uint32 Bmask,
+ Uint32 Amask);
+extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormatFrom
+ (void *pixels, int width, int height, int depth, int pitch, Uint32 format);
+extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface * surface);
+
+/**
+ * \brief Set the palette used by a surface.
+ *
+ * \return 0, or -1 if the surface format doesn't use a palette.
+ *
+ * \note A single palette can be shared with many surfaces.
+ */
+extern DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface * surface,
+ SDL_Palette * palette);
+
+/**
+ * \brief Sets up a surface for directly accessing the pixels.
+ *
+ * Between calls to SDL_LockSurface() / SDL_UnlockSurface(), you can write
+ * to and read from \c surface->pixels, using the pixel format stored in
+ * \c surface->format. Once you are done accessing the surface, you should
+ * use SDL_UnlockSurface() to release it.
+ *
+ * Not all surfaces require locking. If SDL_MUSTLOCK(surface) evaluates
+ * to 0, then you can read and write to the surface at any time, and the
+ * pixel format of the surface will not change.
+ *
+ * No operating system or library calls should be made between lock/unlock
+ * pairs, as critical system locks may be held during this time.
+ *
+ * SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked.
+ *
+ * \sa SDL_UnlockSurface()
+ */
+extern DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface * surface);
+/** \sa SDL_LockSurface() */
+extern DECLSPEC void SDLCALL SDL_UnlockSurface(SDL_Surface * surface);
+
+/**
+ * Load a surface from a seekable SDL data stream (memory or file).
+ *
+ * If \c freesrc is non-zero, the stream will be closed after being read.
+ *
+ * The new surface should be freed with SDL_FreeSurface().
+ *
+ * \return the new surface, or NULL if there was an error.
+ */
+extern DECLSPEC SDL_Surface *SDLCALL SDL_LoadBMP_RW(SDL_RWops * src,
+ int freesrc);
+
+/**
+ * Load a surface from a file.
+ *
+ * Convenience macro.
+ */
+#define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1)
+
+/**
+ * Save a surface to a seekable SDL data stream (memory or file).
+ *
+ * Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
+ * BMP directly. Other RGB formats with 8-bit or higher get converted to a
+ * 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
+ * surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
+ * not supported.
+ *
+ * If \c freedst is non-zero, the stream will be closed after being written.
+ *
+ * \return 0 if successful or -1 if there was an error.
+ */
+extern DECLSPEC int SDLCALL SDL_SaveBMP_RW
+ (SDL_Surface * surface, SDL_RWops * dst, int freedst);
+
+/**
+ * Save a surface to a file.
+ *
+ * Convenience macro.
+ */
+#define SDL_SaveBMP(surface, file) \
+ SDL_SaveBMP_RW(surface, SDL_RWFromFile(file, "wb"), 1)
+
+/**
+ * \brief Sets the RLE acceleration hint for a surface.
+ *
+ * \return 0 on success, or -1 if the surface is not valid
+ *
+ * \note If RLE is enabled, colorkey and alpha blending blits are much faster,
+ * but the surface must be locked before directly accessing the pixels.
+ */
+extern DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface * surface,
+ int flag);
+
+/**
+ * \brief Sets the color key (transparent pixel) in a blittable surface.
+ *
+ * \param surface The surface to update
+ * \param flag Non-zero to enable colorkey and 0 to disable colorkey
+ * \param key The transparent pixel in the native surface format
+ *
+ * \return 0 on success, or -1 if the surface is not valid
+ *
+ * You can pass SDL_RLEACCEL to enable RLE accelerated blits.
+ */
+extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface * surface,
+ int flag, Uint32 key);
+
+/**
+ * \brief Gets the color key (transparent pixel) in a blittable surface.
+ *
+ * \param surface The surface to update
+ * \param key A pointer filled in with the transparent pixel in the native
+ * surface format
+ *
+ * \return 0 on success, or -1 if the surface is not valid or colorkey is not
+ * enabled.
+ */
+extern DECLSPEC int SDLCALL SDL_GetColorKey(SDL_Surface * surface,
+ Uint32 * key);
+
+/**
+ * \brief Set an additional color value used in blit operations.
+ *
+ * \param surface The surface to update.
+ * \param r The red color value multiplied into blit operations.
+ * \param g The green color value multiplied into blit operations.
+ * \param b The blue color value multiplied into blit operations.
+ *
+ * \return 0 on success, or -1 if the surface is not valid.
+ *
+ * \sa SDL_GetSurfaceColorMod()
+ */
+extern DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface * surface,
+ Uint8 r, Uint8 g, Uint8 b);
+
+
+/**
+ * \brief Get the additional color value used in blit operations.
+ *
+ * \param surface The surface to query.
+ * \param r A pointer filled in with the current red color value.
+ * \param g A pointer filled in with the current green color value.
+ * \param b A pointer filled in with the current blue color value.
+ *
+ * \return 0 on success, or -1 if the surface is not valid.
+ *
+ * \sa SDL_SetSurfaceColorMod()
+ */
+extern DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface * surface,
+ Uint8 * r, Uint8 * g,
+ Uint8 * b);
+
+/**
+ * \brief Set an additional alpha value used in blit operations.
+ *
+ * \param surface The surface to update.
+ * \param alpha The alpha value multiplied into blit operations.
+ *
+ * \return 0 on success, or -1 if the surface is not valid.
+ *
+ * \sa SDL_GetSurfaceAlphaMod()
+ */
+extern DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface * surface,
+ Uint8 alpha);
+
+/**
+ * \brief Get the additional alpha value used in blit operations.
+ *
+ * \param surface The surface to query.
+ * \param alpha A pointer filled in with the current alpha value.
+ *
+ * \return 0 on success, or -1 if the surface is not valid.
+ *
+ * \sa SDL_SetSurfaceAlphaMod()
+ */
+extern DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface * surface,
+ Uint8 * alpha);
+
+/**
+ * \brief Set the blend mode used for blit operations.
+ *
+ * \param surface The surface to update.
+ * \param blendMode ::SDL_BlendMode to use for blit blending.
+ *
+ * \return 0 on success, or -1 if the parameters are not valid.
+ *
+ * \sa SDL_GetSurfaceBlendMode()
+ */
+extern DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface * surface,
+ SDL_BlendMode blendMode);
+
+/**
+ * \brief Get the blend mode used for blit operations.
+ *
+ * \param surface The surface to query.
+ * \param blendMode A pointer filled in with the current blend mode.
+ *
+ * \return 0 on success, or -1 if the surface is not valid.
+ *
+ * \sa SDL_SetSurfaceBlendMode()
+ */
+extern DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface * surface,
+ SDL_BlendMode *blendMode);
+
+/**
+ * Sets the clipping rectangle for the destination surface in a blit.
+ *
+ * If the clip rectangle is NULL, clipping will be disabled.
+ *
+ * If the clip rectangle doesn't intersect the surface, the function will
+ * return SDL_FALSE and blits will be completely clipped. Otherwise the
+ * function returns SDL_TRUE and blits to the surface will be clipped to
+ * the intersection of the surface area and the clipping rectangle.
+ *
+ * Note that blits are automatically clipped to the edges of the source
+ * and destination surfaces.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_SetClipRect(SDL_Surface * surface,
+ const SDL_Rect * rect);
+
+/**
+ * Gets the clipping rectangle for the destination surface in a blit.
+ *
+ * \c rect must be a pointer to a valid rectangle which will be filled
+ * with the correct values.
+ */
+extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface * surface,
+ SDL_Rect * rect);
+
+/*
+ * Creates a new surface identical to the existing surface
+ */
+extern DECLSPEC SDL_Surface *SDLCALL SDL_DuplicateSurface(SDL_Surface * surface);
+
+/**
+ * Creates a new surface of the specified format, and then copies and maps
+ * the given surface to it so the blit of the converted surface will be as
+ * fast as possible. If this function fails, it returns NULL.
+ *
+ * The \c flags parameter is passed to SDL_CreateRGBSurface() and has those
+ * semantics. You can also pass ::SDL_RLEACCEL in the flags parameter and
+ * SDL will try to RLE accelerate colorkey and alpha blits in the resulting
+ * surface.
+ */
+extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface
+ (SDL_Surface * src, const SDL_PixelFormat * fmt, Uint32 flags);
+extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat
+ (SDL_Surface * src, Uint32 pixel_format, Uint32 flags);
+
+/**
+ * \brief Copy a block of pixels of one format to another format
+ *
+ * \return 0 on success, or -1 if there was an error
+ */
+extern DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height,
+ Uint32 src_format,
+ const void * src, int src_pitch,
+ Uint32 dst_format,
+ void * dst, int dst_pitch);
+
+/**
+ * Performs a fast fill of the given rectangle with \c color.
+ *
+ * If \c rect is NULL, the whole surface will be filled with \c color.
+ *
+ * The color should be a pixel of the format used by the surface, and
+ * can be generated by the SDL_MapRGB() function.
+ *
+ * \return 0 on success, or -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_FillRect
+ (SDL_Surface * dst, const SDL_Rect * rect, Uint32 color);
+extern DECLSPEC int SDLCALL SDL_FillRects
+ (SDL_Surface * dst, const SDL_Rect * rects, int count, Uint32 color);
+
+/**
+ * Performs a fast blit from the source surface to the destination surface.
+ *
+ * This assumes that the source and destination rectangles are
+ * the same size. If either \c srcrect or \c dstrect are NULL, the entire
+ * surface (\c src or \c dst) is copied. The final blit rectangles are saved
+ * in \c srcrect and \c dstrect after all clipping is performed.
+ *
+ * \return If the blit is successful, it returns 0, otherwise it returns -1.
+ *
+ * The blit function should not be called on a locked surface.
+ *
+ * The blit semantics for surfaces with and without blending and colorkey
+ * are defined as follows:
+ * \verbatim
+ RGBA->RGB:
+ Source surface blend mode set to SDL_BLENDMODE_BLEND:
+ alpha-blend (using the source alpha-channel and per-surface alpha)
+ SDL_SRCCOLORKEY ignored.
+ Source surface blend mode set to SDL_BLENDMODE_NONE:
+ copy RGB.
+ if SDL_SRCCOLORKEY set, only copy the pixels matching the
+ RGB values of the source color key, ignoring alpha in the
+ comparison.
+
+ RGB->RGBA:
+ Source surface blend mode set to SDL_BLENDMODE_BLEND:
+ alpha-blend (using the source per-surface alpha)
+ Source surface blend mode set to SDL_BLENDMODE_NONE:
+ copy RGB, set destination alpha to source per-surface alpha value.
+ both:
+ if SDL_SRCCOLORKEY set, only copy the pixels matching the
+ source color key.
+
+ RGBA->RGBA:
+ Source surface blend mode set to SDL_BLENDMODE_BLEND:
+ alpha-blend (using the source alpha-channel and per-surface alpha)
+ SDL_SRCCOLORKEY ignored.
+ Source surface blend mode set to SDL_BLENDMODE_NONE:
+ copy all of RGBA to the destination.
+ if SDL_SRCCOLORKEY set, only copy the pixels matching the
+ RGB values of the source color key, ignoring alpha in the
+ comparison.
+
+ RGB->RGB:
+ Source surface blend mode set to SDL_BLENDMODE_BLEND:
+ alpha-blend (using the source per-surface alpha)
+ Source surface blend mode set to SDL_BLENDMODE_NONE:
+ copy RGB.
+ both:
+ if SDL_SRCCOLORKEY set, only copy the pixels matching the
+ source color key.
+ \endverbatim
+ *
+ * You should call SDL_BlitSurface() unless you know exactly how SDL
+ * blitting works internally and how to use the other blit functions.
+ */
+#define SDL_BlitSurface SDL_UpperBlit
+
+/**
+ * This is the public blit function, SDL_BlitSurface(), and it performs
+ * rectangle validation and clipping before passing it to SDL_LowerBlit()
+ */
+extern DECLSPEC int SDLCALL SDL_UpperBlit
+ (SDL_Surface * src, const SDL_Rect * srcrect,
+ SDL_Surface * dst, SDL_Rect * dstrect);
+
+/**
+ * This is a semi-private blit function and it performs low-level surface
+ * blitting only.
+ */
+extern DECLSPEC int SDLCALL SDL_LowerBlit
+ (SDL_Surface * src, SDL_Rect * srcrect,
+ SDL_Surface * dst, SDL_Rect * dstrect);
+
+/**
+ * \brief Perform a fast, low quality, stretch blit between two surfaces of the
+ * same pixel format.
+ *
+ * \note This function uses a static buffer, and is not thread-safe.
+ */
+extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src,
+ const SDL_Rect * srcrect,
+ SDL_Surface * dst,
+ const SDL_Rect * dstrect);
+
+#define SDL_BlitScaled SDL_UpperBlitScaled
+
+/**
+ * This is the public scaled blit function, SDL_BlitScaled(), and it performs
+ * rectangle validation and clipping before passing it to SDL_LowerBlitScaled()
+ */
+extern DECLSPEC int SDLCALL SDL_UpperBlitScaled
+ (SDL_Surface * src, const SDL_Rect * srcrect,
+ SDL_Surface * dst, SDL_Rect * dstrect);
+
+/**
+ * This is a semi-private blit function and it performs low-level surface
+ * scaled blitting only.
+ */
+extern DECLSPEC int SDLCALL SDL_LowerBlitScaled
+ (SDL_Surface * src, SDL_Rect * srcrect,
+ SDL_Surface * dst, SDL_Rect * dstrect);
+
+/**
+ * \brief Set the YUV conversion mode
+ */
+extern DECLSPEC void SDLCALL SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_MODE mode);
+
+/**
+ * \brief Get the YUV conversion mode
+ */
+extern DECLSPEC SDL_YUV_CONVERSION_MODE SDLCALL SDL_GetYUVConversionMode(void);
+
+/**
+ * \brief Get the YUV conversion mode, returning the correct mode for the resolution when the current conversion mode is SDL_YUV_CONVERSION_AUTOMATIC
+ */
+extern DECLSPEC SDL_YUV_CONVERSION_MODE SDLCALL SDL_GetYUVConversionModeForResolution(int width, int height);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_surface_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_system.h b/src/3rdparty/SDL2/include/SDL_system.h
new file mode 100644
index 0000000..7b776fd
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_system.h
@@ -0,0 +1,247 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_system.h
+ *
+ * Include file for platform specific SDL API functions
+ */
+
+#ifndef SDL_system_h_
+#define SDL_system_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_keyboard.h"
+#include "SDL_render.h"
+#include "SDL_video.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Platform specific functions for Windows */
+#ifdef __WIN32__
+
+/**
+ \brief Set a function that is called for every windows message, before TranslateMessage()
+*/
+typedef void (SDLCALL * SDL_WindowsMessageHook)(void *userdata, void *hWnd, unsigned int message, Uint64 wParam, Sint64 lParam);
+extern DECLSPEC void SDLCALL SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback, void *userdata);
+
+/**
+ \brief Returns the D3D9 adapter index that matches the specified display index.
+
+ This adapter index can be passed to IDirect3D9::CreateDevice and controls
+ on which monitor a full screen application will appear.
+*/
+extern DECLSPEC int SDLCALL SDL_Direct3D9GetAdapterIndex( int displayIndex );
+
+typedef struct IDirect3DDevice9 IDirect3DDevice9;
+/**
+ \brief Returns the D3D device associated with a renderer, or NULL if it's not a D3D renderer.
+
+ Once you are done using the device, you should release it to avoid a resource leak.
+ */
+extern DECLSPEC IDirect3DDevice9* SDLCALL SDL_RenderGetD3D9Device(SDL_Renderer * renderer);
+
+/**
+ \brief Returns the DXGI Adapter and Output indices for the specified display index.
+
+ These can be passed to EnumAdapters and EnumOutputs respectively to get the objects
+ required to create a DX10 or DX11 device and swap chain.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex );
+
+#endif /* __WIN32__ */
+
+
+/* Platform specific functions for iOS */
+#if defined(__IPHONEOS__) && __IPHONEOS__
+
+#define SDL_iOSSetAnimationCallback(window, interval, callback, callbackParam) SDL_iPhoneSetAnimationCallback(window, interval, callback, callbackParam)
+extern DECLSPEC int SDLCALL SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam);
+
+#define SDL_iOSSetEventPump(enabled) SDL_iPhoneSetEventPump(enabled)
+extern DECLSPEC void SDLCALL SDL_iPhoneSetEventPump(SDL_bool enabled);
+
+#endif /* __IPHONEOS__ */
+
+
+/* Platform specific functions for Android */
+#if defined(__ANDROID__) && __ANDROID__
+
+/**
+ \brief Get the JNI environment for the current thread
+
+ This returns JNIEnv*, but the prototype is void* so we don't need jni.h
+ */
+extern DECLSPEC void * SDLCALL SDL_AndroidGetJNIEnv(void);
+
+/**
+ \brief Get the SDL Activity object for the application
+
+ This returns jobject, but the prototype is void* so we don't need jni.h
+ The jobject returned by SDL_AndroidGetActivity is a local reference.
+ It is the caller's responsibility to properly release it
+ (using env->Push/PopLocalFrame or manually with env->DeleteLocalRef)
+ */
+extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity(void);
+
+/**
+ \brief Return true if the application is running on Android TV
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_IsAndroidTV(void);
+
+/**
+ See the official Android developer guide for more information:
+ http://developer.android.com/guide/topics/data/data-storage.html
+*/
+#define SDL_ANDROID_EXTERNAL_STORAGE_READ 0x01
+#define SDL_ANDROID_EXTERNAL_STORAGE_WRITE 0x02
+
+/**
+ \brief Get the path used for internal storage for this application.
+
+ This path is unique to your application and cannot be written to
+ by other applications.
+ */
+extern DECLSPEC const char * SDLCALL SDL_AndroidGetInternalStoragePath(void);
+
+/**
+ \brief Get the current state of external storage, a bitmask of these values:
+ SDL_ANDROID_EXTERNAL_STORAGE_READ
+ SDL_ANDROID_EXTERNAL_STORAGE_WRITE
+
+ If external storage is currently unavailable, this will return 0.
+*/
+extern DECLSPEC int SDLCALL SDL_AndroidGetExternalStorageState(void);
+
+/**
+ \brief Get the path used for external storage for this application.
+
+ This path is unique to your application, but is public and can be
+ written to by other applications.
+ */
+extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath(void);
+
+#endif /* __ANDROID__ */
+
+/* Platform specific functions for WinRT */
+#if defined(__WINRT__) && __WINRT__
+
+/**
+ * \brief WinRT / Windows Phone path types
+ */
+typedef enum
+{
+ /** \brief The installed app's root directory.
+ Files here are likely to be read-only. */
+ SDL_WINRT_PATH_INSTALLED_LOCATION,
+
+ /** \brief The app's local data store. Files may be written here */
+ SDL_WINRT_PATH_LOCAL_FOLDER,
+
+ /** \brief The app's roaming data store. Unsupported on Windows Phone.
+ Files written here may be copied to other machines via a network
+ connection.
+ */
+ SDL_WINRT_PATH_ROAMING_FOLDER,
+
+ /** \brief The app's temporary data store. Unsupported on Windows Phone.
+ Files written here may be deleted at any time. */
+ SDL_WINRT_PATH_TEMP_FOLDER
+} SDL_WinRT_Path;
+
+
+/**
+ * \brief WinRT Device Family
+ */
+typedef enum
+{
+ /** \brief Unknown family */
+ SDL_WINRT_DEVICEFAMILY_UNKNOWN,
+
+ /** \brief Desktop family*/
+ SDL_WINRT_DEVICEFAMILY_DESKTOP,
+
+ /** \brief Mobile family (for example smartphone) */
+ SDL_WINRT_DEVICEFAMILY_MOBILE,
+
+ /** \brief XBox family */
+ SDL_WINRT_DEVICEFAMILY_XBOX,
+} SDL_WinRT_DeviceFamily;
+
+
+/**
+ * \brief Retrieves a WinRT defined path on the local file system
+ *
+ * \note Documentation on most app-specific path types on WinRT
+ * can be found on MSDN, at the URL:
+ * http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
+ *
+ * \param pathType The type of path to retrieve.
+ * \return A UCS-2 string (16-bit, wide-char) containing the path, or NULL
+ * if the path is not available for any reason. Not all paths are
+ * available on all versions of Windows. This is especially true on
+ * Windows Phone. Check the documentation for the given
+ * SDL_WinRT_Path for more information on which path types are
+ * supported where.
+ */
+extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType);
+
+/**
+ * \brief Retrieves a WinRT defined path on the local file system
+ *
+ * \note Documentation on most app-specific path types on WinRT
+ * can be found on MSDN, at the URL:
+ * http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
+ *
+ * \param pathType The type of path to retrieve.
+ * \return A UTF-8 string (8-bit, multi-byte) containing the path, or NULL
+ * if the path is not available for any reason. Not all paths are
+ * available on all versions of Windows. This is especially true on
+ * Windows Phone. Check the documentation for the given
+ * SDL_WinRT_Path for more information on which path types are
+ * supported where.
+ */
+extern DECLSPEC const char * SDLCALL SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType);
+
+/**
+ * \brief Detects the device family of WinRT plattform on runtime
+ *
+ * \return Device family
+ */
+extern DECLSPEC SDL_WinRT_DeviceFamily SDLCALL SDL_WinRTGetDeviceFamily();
+
+#endif /* __WINRT__ */
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_system_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_syswm.h b/src/3rdparty/SDL2/include/SDL_syswm.h
new file mode 100644
index 0000000..8aa4a39
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_syswm.h
@@ -0,0 +1,324 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_syswm.h
+ *
+ * Include file for SDL custom system window manager hooks.
+ */
+
+#ifndef SDL_syswm_h_
+#define SDL_syswm_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_video.h"
+#include "SDL_version.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \file SDL_syswm.h
+ *
+ * Your application has access to a special type of event ::SDL_SYSWMEVENT,
+ * which contains window-manager specific information and arrives whenever
+ * an unhandled window event occurs. This event is ignored by default, but
+ * you can enable it with SDL_EventState().
+ */
+#ifdef SDL_PROTOTYPES_ONLY
+struct SDL_SysWMinfo;
+#else
+
+#if defined(SDL_VIDEO_DRIVER_WINDOWS)
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#include <windows.h>
+#endif
+
+#if defined(SDL_VIDEO_DRIVER_WINRT)
+#include <Inspectable.h>
+#endif
+
+/* This is the structure for custom window manager events */
+#if defined(SDL_VIDEO_DRIVER_X11)
+#if defined(__APPLE__) && defined(__MACH__)
+/* conflicts with Quickdraw.h */
+#define Cursor X11Cursor
+#endif
+
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+
+#if defined(__APPLE__) && defined(__MACH__)
+/* matches the re-define above */
+#undef Cursor
+#endif
+
+#endif /* defined(SDL_VIDEO_DRIVER_X11) */
+
+#if defined(SDL_VIDEO_DRIVER_DIRECTFB)
+#include <directfb.h>
+#endif
+
+#if defined(SDL_VIDEO_DRIVER_COCOA)
+#ifdef __OBJC__
+@class NSWindow;
+#else
+typedef struct _NSWindow NSWindow;
+#endif
+#endif
+
+#if defined(SDL_VIDEO_DRIVER_UIKIT)
+#ifdef __OBJC__
+#include <UIKit/UIKit.h>
+#else
+typedef struct _UIWindow UIWindow;
+typedef struct _UIViewController UIViewController;
+#endif
+typedef Uint32 GLuint;
+#endif
+
+#if defined(SDL_VIDEO_DRIVER_ANDROID)
+typedef struct ANativeWindow ANativeWindow;
+typedef void *EGLSurface;
+#endif
+
+#if defined(SDL_VIDEO_DRIVER_VIVANTE)
+#include "SDL_egl.h"
+#endif
+
+/**
+ * These are the various supported windowing subsystems
+ */
+typedef enum
+{
+ SDL_SYSWM_UNKNOWN,
+ SDL_SYSWM_WINDOWS,
+ SDL_SYSWM_X11,
+ SDL_SYSWM_DIRECTFB,
+ SDL_SYSWM_COCOA,
+ SDL_SYSWM_UIKIT,
+ SDL_SYSWM_WAYLAND,
+ SDL_SYSWM_MIR,
+ SDL_SYSWM_WINRT,
+ SDL_SYSWM_ANDROID,
+ SDL_SYSWM_VIVANTE,
+ SDL_SYSWM_OS2
+} SDL_SYSWM_TYPE;
+
+/**
+ * The custom event structure.
+ */
+struct SDL_SysWMmsg
+{
+ SDL_version version;
+ SDL_SYSWM_TYPE subsystem;
+ union
+ {
+#if defined(SDL_VIDEO_DRIVER_WINDOWS)
+ struct {
+ HWND hwnd; /**< The window for the message */
+ UINT msg; /**< The type of message */
+ WPARAM wParam; /**< WORD message parameter */
+ LPARAM lParam; /**< LONG message parameter */
+ } win;
+#endif
+#if defined(SDL_VIDEO_DRIVER_X11)
+ struct {
+ XEvent event;
+ } x11;
+#endif
+#if defined(SDL_VIDEO_DRIVER_DIRECTFB)
+ struct {
+ DFBEvent event;
+ } dfb;
+#endif
+#if defined(SDL_VIDEO_DRIVER_COCOA)
+ struct
+ {
+ /* Latest version of Xcode clang complains about empty structs in C v. C++:
+ error: empty struct has size 0 in C, size 1 in C++
+ */
+ int dummy;
+ /* No Cocoa window events yet */
+ } cocoa;
+#endif
+#if defined(SDL_VIDEO_DRIVER_UIKIT)
+ struct
+ {
+ int dummy;
+ /* No UIKit window events yet */
+ } uikit;
+#endif
+#if defined(SDL_VIDEO_DRIVER_VIVANTE)
+ struct
+ {
+ int dummy;
+ /* No Vivante window events yet */
+ } vivante;
+#endif
+ /* Can't have an empty union */
+ int dummy;
+ } msg;
+};
+
+/**
+ * The custom window manager information structure.
+ *
+ * When this structure is returned, it holds information about which
+ * low level system it is using, and will be one of SDL_SYSWM_TYPE.
+ */
+struct SDL_SysWMinfo
+{
+ SDL_version version;
+ SDL_SYSWM_TYPE subsystem;
+ union
+ {
+#if defined(SDL_VIDEO_DRIVER_WINDOWS)
+ struct
+ {
+ HWND window; /**< The window handle */
+ HDC hdc; /**< The window device context */
+ HINSTANCE hinstance; /**< The instance handle */
+ } win;
+#endif
+#if defined(SDL_VIDEO_DRIVER_WINRT)
+ struct
+ {
+ IInspectable * window; /**< The WinRT CoreWindow */
+ } winrt;
+#endif
+#if defined(SDL_VIDEO_DRIVER_X11)
+ struct
+ {
+ Display *display; /**< The X11 display */
+ Window window; /**< The X11 window */
+ } x11;
+#endif
+#if defined(SDL_VIDEO_DRIVER_DIRECTFB)
+ struct
+ {
+ IDirectFB *dfb; /**< The directfb main interface */
+ IDirectFBWindow *window; /**< The directfb window handle */
+ IDirectFBSurface *surface; /**< The directfb client surface */
+ } dfb;
+#endif
+#if defined(SDL_VIDEO_DRIVER_COCOA)
+ struct
+ {
+#if defined(__OBJC__) && defined(__has_feature) && __has_feature(objc_arc)
+ NSWindow __unsafe_unretained *window; /**< The Cocoa window */
+#else
+ NSWindow *window; /**< The Cocoa window */
+#endif
+ } cocoa;
+#endif
+#if defined(SDL_VIDEO_DRIVER_UIKIT)
+ struct
+ {
+#if defined(__OBJC__) && defined(__has_feature) && __has_feature(objc_arc)
+ UIWindow __unsafe_unretained *window; /**< The UIKit window */
+#else
+ UIWindow *window; /**< The UIKit window */
+#endif
+ GLuint framebuffer; /**< The GL view's Framebuffer Object. It must be bound when rendering to the screen using GL. */
+ GLuint colorbuffer; /**< The GL view's color Renderbuffer Object. It must be bound when SDL_GL_SwapWindow is called. */
+ GLuint resolveFramebuffer; /**< The Framebuffer Object which holds the resolve color Renderbuffer, when MSAA is used. */
+ } uikit;
+#endif
+#if defined(SDL_VIDEO_DRIVER_WAYLAND)
+ struct
+ {
+ struct wl_display *display; /**< Wayland display */
+ struct wl_surface *surface; /**< Wayland surface */
+ struct wl_shell_surface *shell_surface; /**< Wayland shell_surface (window manager handle) */
+ } wl;
+#endif
+#if defined(SDL_VIDEO_DRIVER_MIR)
+ struct
+ {
+ struct MirConnection *connection; /**< Mir display server connection */
+ struct MirSurface *surface; /**< Mir surface */
+ } mir;
+#endif
+
+#if defined(SDL_VIDEO_DRIVER_ANDROID)
+ struct
+ {
+ ANativeWindow *window;
+ EGLSurface surface;
+ } android;
+#endif
+
+#if defined(SDL_VIDEO_DRIVER_VIVANTE)
+ struct
+ {
+ EGLNativeDisplayType display;
+ EGLNativeWindowType window;
+ } vivante;
+#endif
+
+ /* Make sure this union is always 64 bytes (8 64-bit pointers). */
+ /* Be careful not to overflow this if you add a new target! */
+ Uint8 dummy[64];
+ } info;
+};
+
+#endif /* SDL_PROTOTYPES_ONLY */
+
+typedef struct SDL_SysWMinfo SDL_SysWMinfo;
+
+/* Function prototypes */
+/**
+ * \brief This function allows access to driver-dependent window information.
+ *
+ * \param window The window about which information is being requested
+ * \param info This structure must be initialized with the SDL version, and is
+ * then filled in with information about the given window.
+ *
+ * \return SDL_TRUE if the function is implemented and the version member of
+ * the \c info struct is valid, SDL_FALSE otherwise.
+ *
+ * You typically use this function like this:
+ * \code
+ * SDL_SysWMinfo info;
+ * SDL_VERSION(&info.version);
+ * if ( SDL_GetWindowWMInfo(window, &info) ) { ... }
+ * \endcode
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo(SDL_Window * window,
+ SDL_SysWMinfo * info);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_syswm_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_test.h b/src/3rdparty/SDL2/include/SDL_test.h
new file mode 100644
index 0000000..6cc373b
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_test.h
@@ -0,0 +1,69 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+#ifndef SDL_test_h_
+#define SDL_test_h_
+
+#include "SDL.h"
+#include "SDL_test_assert.h"
+#include "SDL_test_common.h"
+#include "SDL_test_compare.h"
+#include "SDL_test_crc32.h"
+#include "SDL_test_font.h"
+#include "SDL_test_fuzzer.h"
+#include "SDL_test_harness.h"
+#include "SDL_test_images.h"
+#include "SDL_test_log.h"
+#include "SDL_test_md5.h"
+#include "SDL_test_memory.h"
+#include "SDL_test_random.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Global definitions */
+
+/*
+ * Note: Maximum size of SDLTest log message is less than SDL's limit
+ * to ensure we can fit additional information such as the timestamp.
+ */
+#define SDLTEST_MAX_LOGMESSAGE_LENGTH 3584
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_test_assert.h b/src/3rdparty/SDL2/include/SDL_test_assert.h
new file mode 100644
index 0000000..1788d7a
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_test_assert.h
@@ -0,0 +1,105 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_assert.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/*
+ *
+ * Assert API for test code and test cases
+ *
+ */
+
+#ifndef SDL_test_assert_h_
+#define SDL_test_assert_h_
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Fails the assert.
+ */
+#define ASSERT_FAIL 0
+
+/**
+ * \brief Passes the assert.
+ */
+#define ASSERT_PASS 1
+
+/**
+ * \brief Assert that logs and break execution flow on failures.
+ *
+ * \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0).
+ * \param assertDescription Message to log with the assert describing it.
+ */
+void SDLTest_Assert(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(2);
+
+/**
+ * \brief Assert for test cases that logs but does not break execution flow on failures. Updates assertion counters.
+ *
+ * \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0).
+ * \param assertDescription Message to log with the assert describing it.
+ *
+ * \returns Returns the assertCondition so it can be used to externally to break execution flow if desired.
+ */
+int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(2);
+
+/**
+ * \brief Explicitly pass without checking an assertion condition. Updates assertion counter.
+ *
+ * \param assertDescription Message to log with the assert describing it.
+ */
+void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(1);
+
+/**
+ * \brief Resets the assert summary counters to zero.
+ */
+void SDLTest_ResetAssertSummary(void);
+
+/**
+ * \brief Logs summary of all assertions (total, pass, fail) since last reset as INFO or ERROR.
+ */
+void SDLTest_LogAssertSummary(void);
+
+
+/**
+ * \brief Converts the current assert summary state to a test result.
+ *
+ * \returns TEST_RESULT_PASSED, TEST_RESULT_FAILED, or TEST_RESULT_NO_ASSERT
+ */
+int SDLTest_AssertSummaryToTestResult(void);
+
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_assert_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_test_common.h b/src/3rdparty/SDL2/include/SDL_test_common.h
new file mode 100644
index 0000000..be2e6b2
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_test_common.h
@@ -0,0 +1,188 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_common.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/* Ported from original test\common.h file. */
+
+#ifndef SDL_test_common_h_
+#define SDL_test_common_h_
+
+#include "SDL.h"
+
+#if defined(__PSP__)
+#define DEFAULT_WINDOW_WIDTH 480
+#define DEFAULT_WINDOW_HEIGHT 272
+#else
+#define DEFAULT_WINDOW_WIDTH 640
+#define DEFAULT_WINDOW_HEIGHT 480
+#endif
+
+#define VERBOSE_VIDEO 0x00000001
+#define VERBOSE_MODES 0x00000002
+#define VERBOSE_RENDER 0x00000004
+#define VERBOSE_EVENT 0x00000008
+#define VERBOSE_AUDIO 0x00000010
+
+typedef struct
+{
+ /* SDL init flags */
+ char **argv;
+ Uint32 flags;
+ Uint32 verbose;
+
+ /* Video info */
+ const char *videodriver;
+ int display;
+ const char *window_title;
+ const char *window_icon;
+ Uint32 window_flags;
+ int window_x;
+ int window_y;
+ int window_w;
+ int window_h;
+ int window_minW;
+ int window_minH;
+ int window_maxW;
+ int window_maxH;
+ int logical_w;
+ int logical_h;
+ float scale;
+ int depth;
+ int refresh_rate;
+ int num_windows;
+ SDL_Window **windows;
+
+ /* Renderer info */
+ const char *renderdriver;
+ Uint32 render_flags;
+ SDL_bool skip_renderer;
+ SDL_Renderer **renderers;
+ SDL_Texture **targets;
+
+ /* Audio info */
+ const char *audiodriver;
+ SDL_AudioSpec audiospec;
+
+ /* GL settings */
+ int gl_red_size;
+ int gl_green_size;
+ int gl_blue_size;
+ int gl_alpha_size;
+ int gl_buffer_size;
+ int gl_depth_size;
+ int gl_stencil_size;
+ int gl_double_buffer;
+ int gl_accum_red_size;
+ int gl_accum_green_size;
+ int gl_accum_blue_size;
+ int gl_accum_alpha_size;
+ int gl_stereo;
+ int gl_multisamplebuffers;
+ int gl_multisamplesamples;
+ int gl_retained_backing;
+ int gl_accelerated;
+ int gl_major_version;
+ int gl_minor_version;
+ int gl_debug;
+ int gl_profile_mask;
+} SDLTest_CommonState;
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Function prototypes */
+
+/**
+ * \brief Parse command line parameters and create common state.
+ *
+ * \param argv Array of command line parameters
+ * \param flags Flags indicating which subsystem to initialize (i.e. SDL_INIT_VIDEO | SDL_INIT_AUDIO)
+ *
+ * \returns Returns a newly allocated common state object.
+ */
+SDLTest_CommonState *SDLTest_CommonCreateState(char **argv, Uint32 flags);
+
+/**
+ * \brief Process one common argument.
+ *
+ * \param state The common state describing the test window to create.
+ * \param index The index of the argument to process in argv[].
+ *
+ * \returns The number of arguments processed (i.e. 1 for --fullscreen, 2 for --video [videodriver], or -1 on error.
+ */
+int SDLTest_CommonArg(SDLTest_CommonState * state, int index);
+
+/**
+ * \brief Returns common usage information
+ *
+ * \param state The common state describing the test window to create.
+ *
+ * \returns String with usage information
+ */
+const char *SDLTest_CommonUsage(SDLTest_CommonState * state);
+
+/**
+ * \brief Open test window.
+ *
+ * \param state The common state describing the test window to create.
+ *
+ * \returns True if initialization succeeded, false otherwise
+ */
+SDL_bool SDLTest_CommonInit(SDLTest_CommonState * state);
+
+/**
+ * \brief Common event handler for test windows.
+ *
+ * \param state The common state used to create test window.
+ * \param event The event to handle.
+ * \param done Flag indicating we are done.
+ *
+ */
+void SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done);
+
+/**
+ * \brief Close test window.
+ *
+ * \param state The common state used to create test window.
+ *
+ */
+void SDLTest_CommonQuit(SDLTest_CommonState * state);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_common_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_test_compare.h b/src/3rdparty/SDL2/include/SDL_test_compare.h
new file mode 100644
index 0000000..c22e447
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_test_compare.h
@@ -0,0 +1,69 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_compare.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/*
+
+ Defines comparison functions (i.e. for surfaces).
+
+*/
+
+#ifndef SDL_test_compare_h_
+#define SDL_test_compare_h_
+
+#include "SDL.h"
+
+#include "SDL_test_images.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Compares a surface and with reference image data for equality
+ *
+ * \param surface Surface used in comparison
+ * \param referenceSurface Test Surface used in comparison
+ * \param allowable_error Allowable difference (=sum of squared difference for each RGB component) in blending accuracy.
+ *
+ * \returns 0 if comparison succeeded, >0 (=number of pixels for which the comparison failed) if comparison failed, -1 if any of the surfaces were NULL, -2 if the surface sizes differ.
+ */
+int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_compare_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_test_crc32.h b/src/3rdparty/SDL2/include/SDL_test_crc32.h
new file mode 100644
index 0000000..3d235d0
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_test_crc32.h
@@ -0,0 +1,124 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_crc32.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/*
+
+ Implements CRC32 calculations (default output is Perl String::CRC32 compatible).
+
+*/
+
+#ifndef SDL_test_crc32_h_
+#define SDL_test_crc32_h_
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* ------------ Definitions --------- */
+
+/* Definition shared by all CRC routines */
+
+#ifndef CrcUint32
+ #define CrcUint32 unsigned int
+#endif
+#ifndef CrcUint8
+ #define CrcUint8 unsigned char
+#endif
+
+#ifdef ORIGINAL_METHOD
+ #define CRC32_POLY 0x04c11db7 /* AUTODIN II, Ethernet, & FDDI */
+#else
+ #define CRC32_POLY 0xEDB88320 /* Perl String::CRC32 compatible */
+#endif
+
+/**
+ * Data structure for CRC32 (checksum) computation
+ */
+ typedef struct {
+ CrcUint32 crc32_table[256]; /* CRC table */
+ } SDLTest_Crc32Context;
+
+/* ---------- Function Prototypes ------------- */
+
+/**
+ * \brief Initialize the CRC context
+ *
+ * Note: The function initializes the crc table required for all crc calculations.
+ *
+ * \param crcContext pointer to context variable
+ *
+ * \returns 0 for OK, -1 on error
+ *
+ */
+ int SDLTest_Crc32Init(SDLTest_Crc32Context * crcContext);
+
+
+/**
+ * \brief calculate a crc32 from a data block
+ *
+ * \param crcContext pointer to context variable
+ * \param inBuf input buffer to checksum
+ * \param inLen length of input buffer
+ * \param crc32 pointer to Uint32 to store the final CRC into
+ *
+ * \returns 0 for OK, -1 on error
+ *
+ */
+int SDLTest_Crc32Calc(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);
+
+/* Same routine broken down into three steps */
+int SDLTest_Crc32CalcStart(SDLTest_Crc32Context * crcContext, CrcUint32 *crc32);
+int SDLTest_Crc32CalcEnd(SDLTest_Crc32Context * crcContext, CrcUint32 *crc32);
+int SDLTest_Crc32CalcBuffer(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);
+
+
+/**
+ * \brief clean up CRC context
+ *
+ * \param crcContext pointer to context variable
+ *
+ * \returns 0 for OK, -1 on error
+ *
+*/
+
+int SDLTest_Crc32Done(SDLTest_Crc32Context * crcContext);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_crc32_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_test_font.h b/src/3rdparty/SDL2/include/SDL_test_font.h
new file mode 100644
index 0000000..59cbdca
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_test_font.h
@@ -0,0 +1,81 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_font.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+#ifndef SDL_test_font_h_
+#define SDL_test_font_h_
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Function prototypes */
+
+#define FONT_CHARACTER_SIZE 8
+
+/**
+ * \brief Draw a string in the currently set font.
+ *
+ * \param renderer The renderer to draw on.
+ * \param x The X coordinate of the upper left corner of the character.
+ * \param y The Y coordinate of the upper left corner of the character.
+ * \param c The character to draw.
+ *
+ * \returns Returns 0 on success, -1 on failure.
+ */
+int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, char c);
+
+/**
+ * \brief Draw a string in the currently set font.
+ *
+ * \param renderer The renderer to draw on.
+ * \param x The X coordinate of the upper left corner of the string.
+ * \param y The Y coordinate of the upper left corner of the string.
+ * \param s The string to draw.
+ *
+ * \returns Returns 0 on success, -1 on failure.
+ */
+int SDLTest_DrawString(SDL_Renderer *renderer, int x, int y, const char *s);
+
+
+/**
+ * \brief Cleanup textures used by font drawing functions.
+ */
+void SDLTest_CleanupTextDrawing(void);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_font_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_test_fuzzer.h b/src/3rdparty/SDL2/include/SDL_test_fuzzer.h
new file mode 100644
index 0000000..8fcb9eb
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_test_fuzzer.h
@@ -0,0 +1,384 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_fuzzer.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/*
+
+ Data generators for fuzzing test data in a reproducible way.
+
+*/
+
+#ifndef SDL_test_fuzzer_h_
+#define SDL_test_fuzzer_h_
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/*
+ Based on GSOC code by Markus Kauppila <markus.kauppila@gmail.com>
+*/
+
+
+/**
+ * \file
+ * Note: The fuzzer implementation uses a static instance of random context
+ * internally which makes it thread-UNsafe.
+ */
+
+/**
+ * Initializes the fuzzer for a test
+ *
+ * \param execKey Execution "Key" that initializes the random number generator uniquely for the test.
+ *
+ */
+void SDLTest_FuzzerInit(Uint64 execKey);
+
+
+/**
+ * Returns a random Uint8
+ *
+ * \returns Generated integer
+ */
+Uint8 SDLTest_RandomUint8(void);
+
+/**
+ * Returns a random Sint8
+ *
+ * \returns Generated signed integer
+ */
+Sint8 SDLTest_RandomSint8(void);
+
+
+/**
+ * Returns a random Uint16
+ *
+ * \returns Generated integer
+ */
+Uint16 SDLTest_RandomUint16(void);
+
+/**
+ * Returns a random Sint16
+ *
+ * \returns Generated signed integer
+ */
+Sint16 SDLTest_RandomSint16(void);
+
+
+/**
+ * Returns a random integer
+ *
+ * \returns Generated integer
+ */
+Sint32 SDLTest_RandomSint32(void);
+
+
+/**
+ * Returns a random positive integer
+ *
+ * \returns Generated integer
+ */
+Uint32 SDLTest_RandomUint32(void);
+
+/**
+ * Returns random Uint64.
+ *
+ * \returns Generated integer
+ */
+Uint64 SDLTest_RandomUint64(void);
+
+
+/**
+ * Returns random Sint64.
+ *
+ * \returns Generated signed integer
+ */
+Sint64 SDLTest_RandomSint64(void);
+
+/**
+ * \returns random float in range [0.0 - 1.0[
+ */
+float SDLTest_RandomUnitFloat(void);
+
+/**
+ * \returns random double in range [0.0 - 1.0[
+ */
+double SDLTest_RandomUnitDouble(void);
+
+/**
+ * \returns random float.
+ *
+ */
+float SDLTest_RandomFloat(void);
+
+/**
+ * \returns random double.
+ *
+ */
+double SDLTest_RandomDouble(void);
+
+/**
+ * Returns a random boundary value for Uint8 within the given boundaries.
+ * Boundaries are inclusive, see the usage examples below. If validDomain
+ * is true, the function will only return valid boundaries, otherwise non-valid
+ * boundaries are also possible.
+ * If boundary1 > boundary2, the values are swapped
+ *
+ * Usage examples:
+ * RandomUint8BoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20
+ * RandomUint8BoundaryValue(1, 20, SDL_FALSE) returns 0 or 21
+ * RandomUint8BoundaryValue(0, 99, SDL_FALSE) returns 100
+ * RandomUint8BoundaryValue(0, 255, SDL_FALSE) returns 0 (error set)
+ *
+ * \param boundary1 Lower boundary limit
+ * \param boundary2 Upper boundary limit
+ * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
+ *
+ * \returns Random boundary value for the given range and domain or 0 with error set
+ */
+Uint8 SDLTest_RandomUint8BoundaryValue(Uint8 boundary1, Uint8 boundary2, SDL_bool validDomain);
+
+/**
+ * Returns a random boundary value for Uint16 within the given boundaries.
+ * Boundaries are inclusive, see the usage examples below. If validDomain
+ * is true, the function will only return valid boundaries, otherwise non-valid
+ * boundaries are also possible.
+ * If boundary1 > boundary2, the values are swapped
+ *
+ * Usage examples:
+ * RandomUint16BoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20
+ * RandomUint16BoundaryValue(1, 20, SDL_FALSE) returns 0 or 21
+ * RandomUint16BoundaryValue(0, 99, SDL_FALSE) returns 100
+ * RandomUint16BoundaryValue(0, 0xFFFF, SDL_FALSE) returns 0 (error set)
+ *
+ * \param boundary1 Lower boundary limit
+ * \param boundary2 Upper boundary limit
+ * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
+ *
+ * \returns Random boundary value for the given range and domain or 0 with error set
+ */
+Uint16 SDLTest_RandomUint16BoundaryValue(Uint16 boundary1, Uint16 boundary2, SDL_bool validDomain);
+
+/**
+ * Returns a random boundary value for Uint32 within the given boundaries.
+ * Boundaries are inclusive, see the usage examples below. If validDomain
+ * is true, the function will only return valid boundaries, otherwise non-valid
+ * boundaries are also possible.
+ * If boundary1 > boundary2, the values are swapped
+ *
+ * Usage examples:
+ * RandomUint32BoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20
+ * RandomUint32BoundaryValue(1, 20, SDL_FALSE) returns 0 or 21
+ * RandomUint32BoundaryValue(0, 99, SDL_FALSE) returns 100
+ * RandomUint32BoundaryValue(0, 0xFFFFFFFF, SDL_FALSE) returns 0 (with error set)
+ *
+ * \param boundary1 Lower boundary limit
+ * \param boundary2 Upper boundary limit
+ * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
+ *
+ * \returns Random boundary value for the given range and domain or 0 with error set
+ */
+Uint32 SDLTest_RandomUint32BoundaryValue(Uint32 boundary1, Uint32 boundary2, SDL_bool validDomain);
+
+/**
+ * Returns a random boundary value for Uint64 within the given boundaries.
+ * Boundaries are inclusive, see the usage examples below. If validDomain
+ * is true, the function will only return valid boundaries, otherwise non-valid
+ * boundaries are also possible.
+ * If boundary1 > boundary2, the values are swapped
+ *
+ * Usage examples:
+ * RandomUint64BoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20
+ * RandomUint64BoundaryValue(1, 20, SDL_FALSE) returns 0 or 21
+ * RandomUint64BoundaryValue(0, 99, SDL_FALSE) returns 100
+ * RandomUint64BoundaryValue(0, 0xFFFFFFFFFFFFFFFF, SDL_FALSE) returns 0 (with error set)
+ *
+ * \param boundary1 Lower boundary limit
+ * \param boundary2 Upper boundary limit
+ * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
+ *
+ * \returns Random boundary value for the given range and domain or 0 with error set
+ */
+Uint64 SDLTest_RandomUint64BoundaryValue(Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain);
+
+/**
+ * Returns a random boundary value for Sint8 within the given boundaries.
+ * Boundaries are inclusive, see the usage examples below. If validDomain
+ * is true, the function will only return valid boundaries, otherwise non-valid
+ * boundaries are also possible.
+ * If boundary1 > boundary2, the values are swapped
+ *
+ * Usage examples:
+ * RandomSint8BoundaryValue(-10, 20, SDL_TRUE) returns -11, -10, 19 or 20
+ * RandomSint8BoundaryValue(-100, -10, SDL_FALSE) returns -101 or -9
+ * RandomSint8BoundaryValue(SINT8_MIN, 99, SDL_FALSE) returns 100
+ * RandomSint8BoundaryValue(SINT8_MIN, SINT8_MAX, SDL_FALSE) returns SINT8_MIN (== error value) with error set
+ *
+ * \param boundary1 Lower boundary limit
+ * \param boundary2 Upper boundary limit
+ * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
+ *
+ * \returns Random boundary value for the given range and domain or SINT8_MIN with error set
+ */
+Sint8 SDLTest_RandomSint8BoundaryValue(Sint8 boundary1, Sint8 boundary2, SDL_bool validDomain);
+
+
+/**
+ * Returns a random boundary value for Sint16 within the given boundaries.
+ * Boundaries are inclusive, see the usage examples below. If validDomain
+ * is true, the function will only return valid boundaries, otherwise non-valid
+ * boundaries are also possible.
+ * If boundary1 > boundary2, the values are swapped
+ *
+ * Usage examples:
+ * RandomSint16BoundaryValue(-10, 20, SDL_TRUE) returns -11, -10, 19 or 20
+ * RandomSint16BoundaryValue(-100, -10, SDL_FALSE) returns -101 or -9
+ * RandomSint16BoundaryValue(SINT16_MIN, 99, SDL_FALSE) returns 100
+ * RandomSint16BoundaryValue(SINT16_MIN, SINT16_MAX, SDL_FALSE) returns SINT16_MIN (== error value) with error set
+ *
+ * \param boundary1 Lower boundary limit
+ * \param boundary2 Upper boundary limit
+ * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
+ *
+ * \returns Random boundary value for the given range and domain or SINT16_MIN with error set
+ */
+Sint16 SDLTest_RandomSint16BoundaryValue(Sint16 boundary1, Sint16 boundary2, SDL_bool validDomain);
+
+/**
+ * Returns a random boundary value for Sint32 within the given boundaries.
+ * Boundaries are inclusive, see the usage examples below. If validDomain
+ * is true, the function will only return valid boundaries, otherwise non-valid
+ * boundaries are also possible.
+ * If boundary1 > boundary2, the values are swapped
+ *
+ * Usage examples:
+ * RandomSint32BoundaryValue(-10, 20, SDL_TRUE) returns -11, -10, 19 or 20
+ * RandomSint32BoundaryValue(-100, -10, SDL_FALSE) returns -101 or -9
+ * RandomSint32BoundaryValue(SINT32_MIN, 99, SDL_FALSE) returns 100
+ * RandomSint32BoundaryValue(SINT32_MIN, SINT32_MAX, SDL_FALSE) returns SINT32_MIN (== error value)
+ *
+ * \param boundary1 Lower boundary limit
+ * \param boundary2 Upper boundary limit
+ * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
+ *
+ * \returns Random boundary value for the given range and domain or SINT32_MIN with error set
+ */
+Sint32 SDLTest_RandomSint32BoundaryValue(Sint32 boundary1, Sint32 boundary2, SDL_bool validDomain);
+
+/**
+ * Returns a random boundary value for Sint64 within the given boundaries.
+ * Boundaries are inclusive, see the usage examples below. If validDomain
+ * is true, the function will only return valid boundaries, otherwise non-valid
+ * boundaries are also possible.
+ * If boundary1 > boundary2, the values are swapped
+ *
+ * Usage examples:
+ * RandomSint64BoundaryValue(-10, 20, SDL_TRUE) returns -11, -10, 19 or 20
+ * RandomSint64BoundaryValue(-100, -10, SDL_FALSE) returns -101 or -9
+ * RandomSint64BoundaryValue(SINT64_MIN, 99, SDL_FALSE) returns 100
+ * RandomSint64BoundaryValue(SINT64_MIN, SINT64_MAX, SDL_FALSE) returns SINT64_MIN (== error value) and error set
+ *
+ * \param boundary1 Lower boundary limit
+ * \param boundary2 Upper boundary limit
+ * \param validDomain Should the generated boundary be valid (=within the bounds) or not?
+ *
+ * \returns Random boundary value for the given range and domain or SINT64_MIN with error set
+ */
+Sint64 SDLTest_RandomSint64BoundaryValue(Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain);
+
+
+/**
+ * Returns integer in range [min, max] (inclusive).
+ * Min and max values can be negative values.
+ * If Max in smaller than min, then the values are swapped.
+ * Min and max are the same value, that value will be returned.
+ *
+ * \param min Minimum inclusive value of returned random number
+ * \param max Maximum inclusive value of returned random number
+ *
+ * \returns Generated random integer in range
+ */
+Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max);
+
+
+/**
+ * Generates random null-terminated string. The minimum length for
+ * the string is 1 character, maximum length for the string is 255
+ * characters and it can contain ASCII characters from 32 to 126.
+ *
+ * Note: Returned string needs to be deallocated.
+ *
+ * \returns Newly allocated random string; or NULL if length was invalid or string could not be allocated.
+ */
+char * SDLTest_RandomAsciiString(void);
+
+
+/**
+ * Generates random null-terminated string. The maximum length for
+ * the string is defined by the maxLength parameter.
+ * String can contain ASCII characters from 32 to 126.
+ *
+ * Note: Returned string needs to be deallocated.
+ *
+ * \param maxLength The maximum length of the generated string.
+ *
+ * \returns Newly allocated random string; or NULL if maxLength was invalid or string could not be allocated.
+ */
+char * SDLTest_RandomAsciiStringWithMaximumLength(int maxLength);
+
+
+/**
+ * Generates random null-terminated string. The length for
+ * the string is defined by the size parameter.
+ * String can contain ASCII characters from 32 to 126.
+ *
+ * Note: Returned string needs to be deallocated.
+ *
+ * \param size The length of the generated string
+ *
+ * \returns Newly allocated random string; or NULL if size was invalid or string could not be allocated.
+ */
+char * SDLTest_RandomAsciiStringOfSize(int size);
+
+/**
+ * Returns the invocation count for the fuzzer since last ...FuzzerInit.
+ */
+int SDLTest_GetFuzzerInvocationCount(void);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_fuzzer_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_test_harness.h b/src/3rdparty/SDL2/include/SDL_test_harness.h
new file mode 100644
index 0000000..8641e0a
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_test_harness.h
@@ -0,0 +1,134 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_harness.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/*
+ Defines types for test case definitions and the test execution harness API.
+
+ Based on original GSOC code by Markus Kauppila <markus.kauppila@gmail.com>
+*/
+
+#ifndef SDL_test_h_arness_h
+#define SDL_test_h_arness_h
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* ! Definitions for test case structures */
+#define TEST_ENABLED 1
+#define TEST_DISABLED 0
+
+/* ! Definition of all the possible test return values of the test case method */
+#define TEST_ABORTED -1
+#define TEST_STARTED 0
+#define TEST_COMPLETED 1
+#define TEST_SKIPPED 2
+
+/* ! Definition of all the possible test results for the harness */
+#define TEST_RESULT_PASSED 0
+#define TEST_RESULT_FAILED 1
+#define TEST_RESULT_NO_ASSERT 2
+#define TEST_RESULT_SKIPPED 3
+#define TEST_RESULT_SETUP_FAILURE 4
+
+/* !< Function pointer to a test case setup function (run before every test) */
+typedef void (*SDLTest_TestCaseSetUpFp)(void *arg);
+
+/* !< Function pointer to a test case function */
+typedef int (*SDLTest_TestCaseFp)(void *arg);
+
+/* !< Function pointer to a test case teardown function (run after every test) */
+typedef void (*SDLTest_TestCaseTearDownFp)(void *arg);
+
+/**
+ * Holds information about a single test case.
+ */
+typedef struct SDLTest_TestCaseReference {
+ /* !< Func2Stress */
+ SDLTest_TestCaseFp testCase;
+ /* !< Short name (or function name) "Func2Stress" */
+ char *name;
+ /* !< Long name or full description "This test pushes func2() to the limit." */
+ char *description;
+ /* !< Set to TEST_ENABLED or TEST_DISABLED (test won't be run) */
+ int enabled;
+} SDLTest_TestCaseReference;
+
+/**
+ * Holds information about a test suite (multiple test cases).
+ */
+typedef struct SDLTest_TestSuiteReference {
+ /* !< "PlatformSuite" */
+ char *name;
+ /* !< The function that is run before each test. NULL skips. */
+ SDLTest_TestCaseSetUpFp testSetUp;
+ /* !< The test cases that are run as part of the suite. Last item should be NULL. */
+ const SDLTest_TestCaseReference **testCases;
+ /* !< The function that is run after each test. NULL skips. */
+ SDLTest_TestCaseTearDownFp testTearDown;
+} SDLTest_TestSuiteReference;
+
+
+/**
+ * \brief Generates a random run seed string for the harness. The generated seed will contain alphanumeric characters (0-9A-Z).
+ *
+ * Note: The returned string needs to be deallocated by the caller.
+ *
+ * \param length The length of the seed string to generate
+ *
+ * \returns The generated seed string
+ */
+char *SDLTest_GenerateRunSeed(const int length);
+
+/**
+ * \brief Execute a test suite using the given run seed and execution key.
+ *
+ * \param testSuites Suites containing the test case.
+ * \param userRunSeed Custom run seed provided by user, or NULL to autogenerate one.
+ * \param userExecKey Custom execution key provided by user, or 0 to autogenerate one.
+ * \param filter Filter specification. NULL disables. Case sensitive.
+ * \param testIterations Number of iterations to run each test case.
+ *
+ * \returns Test run result; 0 when all tests passed, 1 if any tests failed.
+ */
+int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *userRunSeed, Uint64 userExecKey, const char *filter, int testIterations);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_h_arness_h */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_test_images.h b/src/3rdparty/SDL2/include/SDL_test_images.h
new file mode 100644
index 0000000..9c4dd5b
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_test_images.h
@@ -0,0 +1,78 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_images.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/*
+
+ Defines some images for tests.
+
+*/
+
+#ifndef SDL_test_images_h_
+#define SDL_test_images_h_
+
+#include "SDL.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ *Type for test images.
+ */
+typedef struct SDLTest_SurfaceImage_s {
+ int width;
+ int height;
+ unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */
+ const char *pixel_data;
+} SDLTest_SurfaceImage_t;
+
+/* Test images */
+SDL_Surface *SDLTest_ImageBlit(void);
+SDL_Surface *SDLTest_ImageBlitColor(void);
+SDL_Surface *SDLTest_ImageBlitAlpha(void);
+SDL_Surface *SDLTest_ImageBlitBlendAdd(void);
+SDL_Surface *SDLTest_ImageBlitBlend(void);
+SDL_Surface *SDLTest_ImageBlitBlendMod(void);
+SDL_Surface *SDLTest_ImageBlitBlendNone(void);
+SDL_Surface *SDLTest_ImageBlitBlendAll(void);
+SDL_Surface *SDLTest_ImageFace(void);
+SDL_Surface *SDLTest_ImagePrimitives(void);
+SDL_Surface *SDLTest_ImagePrimitivesBlend(void);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_images_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_test_log.h b/src/3rdparty/SDL2/include/SDL_test_log.h
new file mode 100644
index 0000000..ebd44fb
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_test_log.h
@@ -0,0 +1,67 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_log.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/*
+ *
+ * Wrapper to log in the TEST category
+ *
+ */
+
+#ifndef SDL_test_log_h_
+#define SDL_test_log_h_
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Prints given message with a timestamp in the TEST category and INFO priority.
+ *
+ * \param fmt Message to be logged
+ */
+void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
+
+/**
+ * \brief Prints given message with a timestamp in the TEST category and the ERROR priority.
+ *
+ * \param fmt Message to be logged
+ */
+void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_log_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_test_md5.h b/src/3rdparty/SDL2/include/SDL_test_md5.h
new file mode 100644
index 0000000..0e41057
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_test_md5.h
@@ -0,0 +1,129 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_md5.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/*
+ ***********************************************************************
+ ** Header file for implementation of MD5 **
+ ** RSA Data Security, Inc. MD5 Message-Digest Algorithm **
+ ** Created: 2/17/90 RLR **
+ ** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version **
+ ** Revised (for MD5): RLR 4/27/91 **
+ ** -- G modified to have y&~z instead of y&z **
+ ** -- FF, GG, HH modified to add in last register done **
+ ** -- Access pattern: round 2 works mod 5, round 3 works mod 3 **
+ ** -- distinct additive constant for each step **
+ ** -- round 4 added, working mod 7 **
+ ***********************************************************************
+*/
+
+/*
+ ***********************************************************************
+ ** Message-digest routines: **
+ ** To form the message digest for a message M **
+ ** (1) Initialize a context buffer mdContext using MD5Init **
+ ** (2) Call MD5Update on mdContext and M **
+ ** (3) Call MD5Final on mdContext **
+ ** The message digest is now in mdContext->digest[0...15] **
+ ***********************************************************************
+*/
+
+#ifndef SDL_test_md5_h_
+#define SDL_test_md5_h_
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* ------------ Definitions --------- */
+
+/* typedef a 32-bit type */
+ typedef unsigned long int MD5UINT4;
+
+/* Data structure for MD5 (Message-Digest) computation */
+ typedef struct {
+ MD5UINT4 i[2]; /* number of _bits_ handled mod 2^64 */
+ MD5UINT4 buf[4]; /* scratch buffer */
+ unsigned char in[64]; /* input buffer */
+ unsigned char digest[16]; /* actual digest after Md5Final call */
+ } SDLTest_Md5Context;
+
+/* ---------- Function Prototypes ------------- */
+
+/**
+ * \brief initialize the context
+ *
+ * \param mdContext pointer to context variable
+ *
+ * Note: The function initializes the message-digest context
+ * mdContext. Call before each new use of the context -
+ * all fields are set to zero.
+ */
+ void SDLTest_Md5Init(SDLTest_Md5Context * mdContext);
+
+
+/**
+ * \brief update digest from variable length data
+ *
+ * \param mdContext pointer to context variable
+ * \param inBuf pointer to data array/string
+ * \param inLen length of data array/string
+ *
+ * Note: The function updates the message-digest context to account
+ * for the presence of each of the characters inBuf[0..inLen-1]
+ * in the message whose digest is being computed.
+*/
+
+ void SDLTest_Md5Update(SDLTest_Md5Context * mdContext, unsigned char *inBuf,
+ unsigned int inLen);
+
+
+/**
+ * \brief complete digest computation
+ *
+ * \param mdContext pointer to context variable
+ *
+ * Note: The function terminates the message-digest computation and
+ * ends with the desired message digest in mdContext.digest[0..15].
+ * Always call before using the digest[] variable.
+*/
+
+ void SDLTest_Md5Final(SDLTest_Md5Context * mdContext);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_md5_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_test_memory.h b/src/3rdparty/SDL2/include/SDL_test_memory.h
new file mode 100644
index 0000000..4827ae6
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_test_memory.h
@@ -0,0 +1,63 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_memory.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+#ifndef SDL_test_memory_h_
+#define SDL_test_memory_h_
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * \brief Start tracking SDL memory allocations
+ *
+ * \note This should be called before any other SDL functions for complete tracking coverage
+ */
+int SDLTest_TrackAllocations();
+
+/**
+ * \brief Print a log of any outstanding allocations
+ *
+ * \note This can be called after SDL_Quit()
+ */
+void SDLTest_LogAllocations();
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_memory_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_test_random.h b/src/3rdparty/SDL2/include/SDL_test_random.h
new file mode 100644
index 0000000..0eb414f
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_test_random.h
@@ -0,0 +1,115 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_test_random.h
+ *
+ * Include file for SDL test framework.
+ *
+ * This code is a part of the SDL2_test library, not the main SDL library.
+ */
+
+/*
+
+ A "32-bit Multiply with carry random number generator. Very fast.
+ Includes a list of recommended multipliers.
+
+ multiply-with-carry generator: x(n) = a*x(n-1) + carry mod 2^32.
+ period: (a*2^31)-1
+
+*/
+
+#ifndef SDL_test_random_h_
+#define SDL_test_random_h_
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* --- Definitions */
+
+/*
+ * Macros that return a random number in a specific format.
+ */
+#define SDLTest_RandomInt(c) ((int)SDLTest_Random(c))
+
+/*
+ * Context structure for the random number generator state.
+ */
+ typedef struct {
+ unsigned int a;
+ unsigned int x;
+ unsigned int c;
+ unsigned int ah;
+ unsigned int al;
+ } SDLTest_RandomContext;
+
+
+/* --- Function prototypes */
+
+/**
+ * \brief Initialize random number generator with two integers.
+ *
+ * Note: The random sequence of numbers returned by ...Random() is the
+ * same for the same two integers and has a period of 2^31.
+ *
+ * \param rndContext pointer to context structure
+ * \param xi integer that defines the random sequence
+ * \param ci integer that defines the random sequence
+ *
+ */
+ void SDLTest_RandomInit(SDLTest_RandomContext * rndContext, unsigned int xi,
+ unsigned int ci);
+
+/**
+ * \brief Initialize random number generator based on current system time.
+ *
+ * \param rndContext pointer to context structure
+ *
+ */
+ void SDLTest_RandomInitTime(SDLTest_RandomContext *rndContext);
+
+
+/**
+ * \brief Initialize random number generator based on current system time.
+ *
+ * Note: ...RandomInit() or ...RandomInitTime() must have been called
+ * before using this function.
+ *
+ * \param rndContext pointer to context structure
+ *
+ * \returns A random number (32bit unsigned integer)
+ *
+ */
+ unsigned int SDLTest_Random(SDLTest_RandomContext *rndContext);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_test_random_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_thread.h b/src/3rdparty/SDL2/include/SDL_thread.h
new file mode 100644
index 0000000..82a43fc
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_thread.h
@@ -0,0 +1,308 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_thread_h_
+#define SDL_thread_h_
+
+/**
+ * \file SDL_thread.h
+ *
+ * Header for the SDL thread management routines.
+ */
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+
+/* Thread synchronization primitives */
+#include "SDL_atomic.h"
+#include "SDL_mutex.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* The SDL thread structure, defined in SDL_thread.c */
+struct SDL_Thread;
+typedef struct SDL_Thread SDL_Thread;
+
+/* The SDL thread ID */
+typedef unsigned long SDL_threadID;
+
+/* Thread local storage ID, 0 is the invalid ID */
+typedef unsigned int SDL_TLSID;
+
+/**
+ * The SDL thread priority.
+ *
+ * \note On many systems you require special privileges to set high priority.
+ */
+typedef enum {
+ SDL_THREAD_PRIORITY_LOW,
+ SDL_THREAD_PRIORITY_NORMAL,
+ SDL_THREAD_PRIORITY_HIGH
+} SDL_ThreadPriority;
+
+/**
+ * The function passed to SDL_CreateThread().
+ * It is passed a void* user context parameter and returns an int.
+ */
+typedef int (SDLCALL * SDL_ThreadFunction) (void *data);
+
+#if defined(__WIN32__) && !defined(HAVE_LIBC)
+/**
+ * \file SDL_thread.h
+ *
+ * We compile SDL into a DLL. This means, that it's the DLL which
+ * creates a new thread for the calling process with the SDL_CreateThread()
+ * API. There is a problem with this, that only the RTL of the SDL2.DLL will
+ * be initialized for those threads, and not the RTL of the calling
+ * application!
+ *
+ * To solve this, we make a little hack here.
+ *
+ * We'll always use the caller's _beginthread() and _endthread() APIs to
+ * start a new thread. This way, if it's the SDL2.DLL which uses this API,
+ * then the RTL of SDL2.DLL will be used to create the new thread, and if it's
+ * the application, then the RTL of the application will be used.
+ *
+ * So, in short:
+ * Always use the _beginthread() and _endthread() of the calling runtime
+ * library!
+ */
+#define SDL_PASSED_BEGINTHREAD_ENDTHREAD
+#include <process.h> /* _beginthreadex() and _endthreadex() */
+
+typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread)
+ (void *, unsigned, unsigned (__stdcall *func)(void *),
+ void * /*arg*/, unsigned, unsigned * /* threadID */);
+typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
+
+/**
+ * Create a thread.
+ */
+extern DECLSPEC SDL_Thread *SDLCALL
+SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
+ pfnSDL_CurrentBeginThread pfnBeginThread,
+ pfnSDL_CurrentEndThread pfnEndThread);
+
+/**
+ * Create a thread.
+ */
+#if defined(SDL_CreateThread) && SDL_DYNAMIC_API
+#undef SDL_CreateThread
+#define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
+#else
+#define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthreadex, (pfnSDL_CurrentEndThread)_endthreadex)
+#endif
+
+#elif defined(__OS2__)
+/*
+ * just like the windows case above: We compile SDL2
+ * into a dll with Watcom's runtime statically linked.
+ */
+#define SDL_PASSED_BEGINTHREAD_ENDTHREAD
+#ifndef __EMX__
+#include <process.h>
+#else
+#include <stdlib.h>
+#endif
+typedef int (*pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void * /*arg*/);
+typedef void (*pfnSDL_CurrentEndThread)(void);
+extern DECLSPEC SDL_Thread *SDLCALL
+SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
+ pfnSDL_CurrentBeginThread pfnBeginThread,
+ pfnSDL_CurrentEndThread pfnEndThread);
+#if defined(SDL_CreateThread) && SDL_DYNAMIC_API
+#undef SDL_CreateThread
+#define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread)
+#else
+#define SDL_CreateThread(fn, name, data) SDL_CreateThread(fn, name, data, (pfnSDL_CurrentBeginThread)_beginthread, (pfnSDL_CurrentEndThread)_endthread)
+#endif
+
+#else
+
+/**
+ * Create a thread.
+ *
+ * Thread naming is a little complicated: Most systems have very small
+ * limits for the string length (Haiku has 32 bytes, Linux currently has 16,
+ * Visual C++ 6.0 has nine!), and possibly other arbitrary rules. You'll
+ * have to see what happens with your system's debugger. The name should be
+ * UTF-8 (but using the naming limits of C identifiers is a better bet).
+ * There are no requirements for thread naming conventions, so long as the
+ * string is null-terminated UTF-8, but these guidelines are helpful in
+ * choosing a name:
+ *
+ * http://stackoverflow.com/questions/149932/naming-conventions-for-threads
+ *
+ * If a system imposes requirements, SDL will try to munge the string for
+ * it (truncate, etc), but the original string contents will be available
+ * from SDL_GetThreadName().
+ */
+extern DECLSPEC SDL_Thread *SDLCALL
+SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data);
+
+#endif
+
+/**
+ * Get the thread name, as it was specified in SDL_CreateThread().
+ * This function returns a pointer to a UTF-8 string that names the
+ * specified thread, or NULL if it doesn't have a name. This is internal
+ * memory, not to be free()'d by the caller, and remains valid until the
+ * specified thread is cleaned up by SDL_WaitThread().
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetThreadName(SDL_Thread *thread);
+
+/**
+ * Get the thread identifier for the current thread.
+ */
+extern DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void);
+
+/**
+ * Get the thread identifier for the specified thread.
+ *
+ * Equivalent to SDL_ThreadID() if the specified thread is NULL.
+ */
+extern DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread * thread);
+
+/**
+ * Set the priority for the current thread
+ */
+extern DECLSPEC int SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority);
+
+/**
+ * Wait for a thread to finish. Threads that haven't been detached will
+ * remain (as a "zombie") until this function cleans them up. Not doing so
+ * is a resource leak.
+ *
+ * Once a thread has been cleaned up through this function, the SDL_Thread
+ * that references it becomes invalid and should not be referenced again.
+ * As such, only one thread may call SDL_WaitThread() on another.
+ *
+ * The return code for the thread function is placed in the area
+ * pointed to by \c status, if \c status is not NULL.
+ *
+ * You may not wait on a thread that has been used in a call to
+ * SDL_DetachThread(). Use either that function or this one, but not
+ * both, or behavior is undefined.
+ *
+ * It is safe to pass NULL to this function; it is a no-op.
+ */
+extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread * thread, int *status);
+
+/**
+ * A thread may be "detached" to signify that it should not remain until
+ * another thread has called SDL_WaitThread() on it. Detaching a thread
+ * is useful for long-running threads that nothing needs to synchronize
+ * with or further manage. When a detached thread is done, it simply
+ * goes away.
+ *
+ * There is no way to recover the return code of a detached thread. If you
+ * need this, don't detach the thread and instead use SDL_WaitThread().
+ *
+ * Once a thread is detached, you should usually assume the SDL_Thread isn't
+ * safe to reference again, as it will become invalid immediately upon
+ * the detached thread's exit, instead of remaining until someone has called
+ * SDL_WaitThread() to finally clean it up. As such, don't detach the same
+ * thread more than once.
+ *
+ * If a thread has already exited when passed to SDL_DetachThread(), it will
+ * stop waiting for a call to SDL_WaitThread() and clean up immediately.
+ * It is not safe to detach a thread that might be used with SDL_WaitThread().
+ *
+ * You may not call SDL_WaitThread() on a thread that has been detached.
+ * Use either that function or this one, but not both, or behavior is
+ * undefined.
+ *
+ * It is safe to pass NULL to this function; it is a no-op.
+ */
+extern DECLSPEC void SDLCALL SDL_DetachThread(SDL_Thread * thread);
+
+/**
+ * \brief Create an identifier that is globally visible to all threads but refers to data that is thread-specific.
+ *
+ * \return The newly created thread local storage identifier, or 0 on error
+ *
+ * \code
+ * static SDL_SpinLock tls_lock;
+ * static SDL_TLSID thread_local_storage;
+ *
+ * void SetMyThreadData(void *value)
+ * {
+ * if (!thread_local_storage) {
+ * SDL_AtomicLock(&tls_lock);
+ * if (!thread_local_storage) {
+ * thread_local_storage = SDL_TLSCreate();
+ * }
+ * SDL_AtomicUnlock(&tls_lock);
+ * }
+ * SDL_TLSSet(thread_local_storage, value, 0);
+ * }
+ *
+ * void *GetMyThreadData(void)
+ * {
+ * return SDL_TLSGet(thread_local_storage);
+ * }
+ * \endcode
+ *
+ * \sa SDL_TLSGet()
+ * \sa SDL_TLSSet()
+ */
+extern DECLSPEC SDL_TLSID SDLCALL SDL_TLSCreate(void);
+
+/**
+ * \brief Get the value associated with a thread local storage ID for the current thread.
+ *
+ * \param id The thread local storage ID
+ *
+ * \return The value associated with the ID for the current thread, or NULL if no value has been set.
+ *
+ * \sa SDL_TLSCreate()
+ * \sa SDL_TLSSet()
+ */
+extern DECLSPEC void * SDLCALL SDL_TLSGet(SDL_TLSID id);
+
+/**
+ * \brief Set the value associated with a thread local storage ID for the current thread.
+ *
+ * \param id The thread local storage ID
+ * \param value The value to associate with the ID for the current thread
+ * \param destructor A function called when the thread exits, to free the value.
+ *
+ * \return 0 on success, -1 on error
+ *
+ * \sa SDL_TLSCreate()
+ * \sa SDL_TLSGet()
+ */
+extern DECLSPEC int SDLCALL SDL_TLSSet(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void*));
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_thread_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_timer.h b/src/3rdparty/SDL2/include/SDL_timer.h
new file mode 100644
index 0000000..5600618
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_timer.h
@@ -0,0 +1,115 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_timer_h_
+#define SDL_timer_h_
+
+/**
+ * \file SDL_timer.h
+ *
+ * Header for the SDL time management routines.
+ */
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Get the number of milliseconds since the SDL library initialization.
+ *
+ * \note This value wraps if the program runs for more than ~49 days.
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void);
+
+/**
+ * \brief Compare SDL ticks values, and return true if A has passed B
+ *
+ * e.g. if you want to wait 100 ms, you could do this:
+ * Uint32 timeout = SDL_GetTicks() + 100;
+ * while (!SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) {
+ * ... do work until timeout has elapsed
+ * }
+ */
+#define SDL_TICKS_PASSED(A, B) ((Sint32)((B) - (A)) <= 0)
+
+/**
+ * \brief Get the current value of the high resolution counter
+ */
+extern DECLSPEC Uint64 SDLCALL SDL_GetPerformanceCounter(void);
+
+/**
+ * \brief Get the count per second of the high resolution counter
+ */
+extern DECLSPEC Uint64 SDLCALL SDL_GetPerformanceFrequency(void);
+
+/**
+ * \brief Wait a specified number of milliseconds before returning.
+ */
+extern DECLSPEC void SDLCALL SDL_Delay(Uint32 ms);
+
+/**
+ * Function prototype for the timer callback function.
+ *
+ * The callback function is passed the current timer interval and returns
+ * the next timer interval. If the returned value is the same as the one
+ * passed in, the periodic alarm continues, otherwise a new alarm is
+ * scheduled. If the callback returns 0, the periodic alarm is cancelled.
+ */
+typedef Uint32 (SDLCALL * SDL_TimerCallback) (Uint32 interval, void *param);
+
+/**
+ * Definition of the timer ID type.
+ */
+typedef int SDL_TimerID;
+
+/**
+ * \brief Add a new timer to the pool of timers already running.
+ *
+ * \return A timer ID, or 0 when an error occurs.
+ */
+extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval,
+ SDL_TimerCallback callback,
+ void *param);
+
+/**
+ * \brief Remove a timer knowing its ID.
+ *
+ * \return A boolean value indicating success or failure.
+ *
+ * \warning It is not safe to remove a timer multiple times.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID id);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_timer_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_touch.h b/src/3rdparty/SDL2/include/SDL_touch.h
new file mode 100644
index 0000000..f4075e7
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_touch.h
@@ -0,0 +1,86 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_touch.h
+ *
+ * Include file for SDL touch event handling.
+ */
+
+#ifndef SDL_touch_h_
+#define SDL_touch_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_video.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef Sint64 SDL_TouchID;
+typedef Sint64 SDL_FingerID;
+
+typedef struct SDL_Finger
+{
+ SDL_FingerID id;
+ float x;
+ float y;
+ float pressure;
+} SDL_Finger;
+
+/* Used as the device ID for mouse events simulated with touch input */
+#define SDL_TOUCH_MOUSEID ((Uint32)-1)
+
+
+/* Function prototypes */
+
+/**
+ * \brief Get the number of registered touch devices.
+ */
+extern DECLSPEC int SDLCALL SDL_GetNumTouchDevices(void);
+
+/**
+ * \brief Get the touch ID with the given index, or 0 if the index is invalid.
+ */
+extern DECLSPEC SDL_TouchID SDLCALL SDL_GetTouchDevice(int index);
+
+/**
+ * \brief Get the number of active fingers for a given touch device.
+ */
+extern DECLSPEC int SDLCALL SDL_GetNumTouchFingers(SDL_TouchID touchID);
+
+/**
+ * \brief Get the finger object of the given touch, with the given index.
+ */
+extern DECLSPEC SDL_Finger * SDLCALL SDL_GetTouchFinger(SDL_TouchID touchID, int index);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_touch_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_types.h b/src/3rdparty/SDL2/include/SDL_types.h
new file mode 100644
index 0000000..4ac248c
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_types.h
@@ -0,0 +1,29 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_types.h
+ *
+ * \deprecated
+ */
+
+/* DEPRECATED */
+#include "SDL_stdinc.h"
diff --git a/src/3rdparty/SDL2/include/SDL_version.h b/src/3rdparty/SDL2/include/SDL_version.h
new file mode 100644
index 0000000..584b48c
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_version.h
@@ -0,0 +1,162 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_version.h
+ *
+ * This header defines the current SDL version.
+ */
+
+#ifndef SDL_version_h_
+#define SDL_version_h_
+
+#include "SDL_stdinc.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Information the version of SDL in use.
+ *
+ * Represents the library's version as three levels: major revision
+ * (increments with massive changes, additions, and enhancements),
+ * minor revision (increments with backwards-compatible changes to the
+ * major revision), and patchlevel (increments with fixes to the minor
+ * revision).
+ *
+ * \sa SDL_VERSION
+ * \sa SDL_GetVersion
+ */
+typedef struct SDL_version
+{
+ Uint8 major; /**< major version */
+ Uint8 minor; /**< minor version */
+ Uint8 patch; /**< update version */
+} SDL_version;
+
+/* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
+*/
+#define SDL_MAJOR_VERSION 2
+#define SDL_MINOR_VERSION 0
+#define SDL_PATCHLEVEL 8
+
+/**
+ * \brief Macro to determine SDL version program was compiled against.
+ *
+ * This macro fills in a SDL_version structure with the version of the
+ * library you compiled against. This is determined by what header the
+ * compiler uses. Note that if you dynamically linked the library, you might
+ * have a slightly newer or older version at runtime. That version can be
+ * determined with SDL_GetVersion(), which, unlike SDL_VERSION(),
+ * is not a macro.
+ *
+ * \param x A pointer to a SDL_version struct to initialize.
+ *
+ * \sa SDL_version
+ * \sa SDL_GetVersion
+ */
+#define SDL_VERSION(x) \
+{ \
+ (x)->major = SDL_MAJOR_VERSION; \
+ (x)->minor = SDL_MINOR_VERSION; \
+ (x)->patch = SDL_PATCHLEVEL; \
+}
+
+/**
+ * This macro turns the version numbers into a numeric value:
+ * \verbatim
+ (1,2,3) -> (1203)
+ \endverbatim
+ *
+ * This assumes that there will never be more than 100 patchlevels.
+ */
+#define SDL_VERSIONNUM(X, Y, Z) \
+ ((X)*1000 + (Y)*100 + (Z))
+
+/**
+ * This is the version number macro for the current SDL version.
+ */
+#define SDL_COMPILEDVERSION \
+ SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL)
+
+/**
+ * This macro will evaluate to true if compiled with SDL at least X.Y.Z.
+ */
+#define SDL_VERSION_ATLEAST(X, Y, Z) \
+ (SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z))
+
+/**
+ * \brief Get the version of SDL that is linked against your program.
+ *
+ * If you are linking to SDL dynamically, then it is possible that the
+ * current version will be different than the version you compiled against.
+ * This function returns the current version, while SDL_VERSION() is a
+ * macro that tells you what version you compiled with.
+ *
+ * \code
+ * SDL_version compiled;
+ * SDL_version linked;
+ *
+ * SDL_VERSION(&compiled);
+ * SDL_GetVersion(&linked);
+ * printf("We compiled against SDL version %d.%d.%d ...\n",
+ * compiled.major, compiled.minor, compiled.patch);
+ * printf("But we linked against SDL version %d.%d.%d.\n",
+ * linked.major, linked.minor, linked.patch);
+ * \endcode
+ *
+ * This function may be called safely at any time, even before SDL_Init().
+ *
+ * \sa SDL_VERSION
+ */
+extern DECLSPEC void SDLCALL SDL_GetVersion(SDL_version * ver);
+
+/**
+ * \brief Get the code revision of SDL that is linked against your program.
+ *
+ * Returns an arbitrary string (a hash value) uniquely identifying the
+ * exact revision of the SDL library in use, and is only useful in comparing
+ * against other revisions. It is NOT an incrementing number.
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetRevision(void);
+
+/**
+ * \brief Get the revision number of SDL that is linked against your program.
+ *
+ * Returns a number uniquely identifying the exact revision of the SDL
+ * library in use. It is an incrementing number based on commits to
+ * hg.libsdl.org.
+ */
+extern DECLSPEC int SDLCALL SDL_GetRevisionNumber(void);
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_version_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_video.h b/src/3rdparty/SDL2/include/SDL_video.h
new file mode 100644
index 0000000..83f49fa
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_video.h
@@ -0,0 +1,1249 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_video.h
+ *
+ * Header file for SDL video functions.
+ */
+
+#ifndef SDL_video_h_
+#define SDL_video_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_pixels.h"
+#include "SDL_rect.h"
+#include "SDL_surface.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief The structure that defines a display mode
+ *
+ * \sa SDL_GetNumDisplayModes()
+ * \sa SDL_GetDisplayMode()
+ * \sa SDL_GetDesktopDisplayMode()
+ * \sa SDL_GetCurrentDisplayMode()
+ * \sa SDL_GetClosestDisplayMode()
+ * \sa SDL_SetWindowDisplayMode()
+ * \sa SDL_GetWindowDisplayMode()
+ */
+typedef struct
+{
+ Uint32 format; /**< pixel format */
+ int w; /**< width, in screen coordinates */
+ int h; /**< height, in screen coordinates */
+ int refresh_rate; /**< refresh rate (or zero for unspecified) */
+ void *driverdata; /**< driver-specific data, initialize to 0 */
+} SDL_DisplayMode;
+
+/**
+ * \brief The type used to identify a window
+ *
+ * \sa SDL_CreateWindow()
+ * \sa SDL_CreateWindowFrom()
+ * \sa SDL_DestroyWindow()
+ * \sa SDL_GetWindowData()
+ * \sa SDL_GetWindowFlags()
+ * \sa SDL_GetWindowGrab()
+ * \sa SDL_GetWindowPosition()
+ * \sa SDL_GetWindowSize()
+ * \sa SDL_GetWindowTitle()
+ * \sa SDL_HideWindow()
+ * \sa SDL_MaximizeWindow()
+ * \sa SDL_MinimizeWindow()
+ * \sa SDL_RaiseWindow()
+ * \sa SDL_RestoreWindow()
+ * \sa SDL_SetWindowData()
+ * \sa SDL_SetWindowFullscreen()
+ * \sa SDL_SetWindowGrab()
+ * \sa SDL_SetWindowIcon()
+ * \sa SDL_SetWindowPosition()
+ * \sa SDL_SetWindowSize()
+ * \sa SDL_SetWindowBordered()
+ * \sa SDL_SetWindowResizable()
+ * \sa SDL_SetWindowTitle()
+ * \sa SDL_ShowWindow()
+ */
+typedef struct SDL_Window SDL_Window;
+
+/**
+ * \brief The flags on a window
+ *
+ * \sa SDL_GetWindowFlags()
+ */
+typedef enum
+{
+ /* !!! FIXME: change this to name = (1<<x). */
+ SDL_WINDOW_FULLSCREEN = 0x00000001, /**< fullscreen window */
+ SDL_WINDOW_OPENGL = 0x00000002, /**< window usable with OpenGL context */
+ SDL_WINDOW_SHOWN = 0x00000004, /**< window is visible */
+ SDL_WINDOW_HIDDEN = 0x00000008, /**< window is not visible */
+ SDL_WINDOW_BORDERLESS = 0x00000010, /**< no window decoration */
+ SDL_WINDOW_RESIZABLE = 0x00000020, /**< window can be resized */
+ SDL_WINDOW_MINIMIZED = 0x00000040, /**< window is minimized */
+ SDL_WINDOW_MAXIMIZED = 0x00000080, /**< window is maximized */
+ SDL_WINDOW_INPUT_GRABBED = 0x00000100, /**< window has grabbed input focus */
+ SDL_WINDOW_INPUT_FOCUS = 0x00000200, /**< window has input focus */
+ SDL_WINDOW_MOUSE_FOCUS = 0x00000400, /**< window has mouse focus */
+ SDL_WINDOW_FULLSCREEN_DESKTOP = ( SDL_WINDOW_FULLSCREEN | 0x00001000 ),
+ SDL_WINDOW_FOREIGN = 0x00000800, /**< window not created by SDL */
+ SDL_WINDOW_ALLOW_HIGHDPI = 0x00002000, /**< window should be created in high-DPI mode if supported.
+ On macOS NSHighResolutionCapable must be set true in the
+ application's Info.plist for this to have any effect. */
+ SDL_WINDOW_MOUSE_CAPTURE = 0x00004000, /**< window has mouse captured (unrelated to INPUT_GRABBED) */
+ SDL_WINDOW_ALWAYS_ON_TOP = 0x00008000, /**< window should always be above others */
+ SDL_WINDOW_SKIP_TASKBAR = 0x00010000, /**< window should not be added to the taskbar */
+ SDL_WINDOW_UTILITY = 0x00020000, /**< window should be treated as a utility window */
+ SDL_WINDOW_TOOLTIP = 0x00040000, /**< window should be treated as a tooltip */
+ SDL_WINDOW_POPUP_MENU = 0x00080000, /**< window should be treated as a popup menu */
+ SDL_WINDOW_VULKAN = 0x10000000 /**< window usable for Vulkan surface */
+} SDL_WindowFlags;
+
+/**
+ * \brief Used to indicate that you don't care what the window position is.
+ */
+#define SDL_WINDOWPOS_UNDEFINED_MASK 0x1FFF0000u
+#define SDL_WINDOWPOS_UNDEFINED_DISPLAY(X) (SDL_WINDOWPOS_UNDEFINED_MASK|(X))
+#define SDL_WINDOWPOS_UNDEFINED SDL_WINDOWPOS_UNDEFINED_DISPLAY(0)
+#define SDL_WINDOWPOS_ISUNDEFINED(X) \
+ (((X)&0xFFFF0000) == SDL_WINDOWPOS_UNDEFINED_MASK)
+
+/**
+ * \brief Used to indicate that the window position should be centered.
+ */
+#define SDL_WINDOWPOS_CENTERED_MASK 0x2FFF0000u
+#define SDL_WINDOWPOS_CENTERED_DISPLAY(X) (SDL_WINDOWPOS_CENTERED_MASK|(X))
+#define SDL_WINDOWPOS_CENTERED SDL_WINDOWPOS_CENTERED_DISPLAY(0)
+#define SDL_WINDOWPOS_ISCENTERED(X) \
+ (((X)&0xFFFF0000) == SDL_WINDOWPOS_CENTERED_MASK)
+
+/**
+ * \brief Event subtype for window events
+ */
+typedef enum
+{
+ SDL_WINDOWEVENT_NONE, /**< Never used */
+ SDL_WINDOWEVENT_SHOWN, /**< Window has been shown */
+ SDL_WINDOWEVENT_HIDDEN, /**< Window has been hidden */
+ SDL_WINDOWEVENT_EXPOSED, /**< Window has been exposed and should be
+ redrawn */
+ SDL_WINDOWEVENT_MOVED, /**< Window has been moved to data1, data2
+ */
+ SDL_WINDOWEVENT_RESIZED, /**< Window has been resized to data1xdata2 */
+ SDL_WINDOWEVENT_SIZE_CHANGED, /**< The window size has changed, either as
+ a result of an API call or through the
+ system or user changing the window size. */
+ SDL_WINDOWEVENT_MINIMIZED, /**< Window has been minimized */
+ SDL_WINDOWEVENT_MAXIMIZED, /**< Window has been maximized */
+ SDL_WINDOWEVENT_RESTORED, /**< Window has been restored to normal size
+ and position */
+ SDL_WINDOWEVENT_ENTER, /**< Window has gained mouse focus */
+ SDL_WINDOWEVENT_LEAVE, /**< Window has lost mouse focus */
+ SDL_WINDOWEVENT_FOCUS_GAINED, /**< Window has gained keyboard focus */
+ SDL_WINDOWEVENT_FOCUS_LOST, /**< Window has lost keyboard focus */
+ SDL_WINDOWEVENT_CLOSE, /**< The window manager requests that the window be closed */
+ SDL_WINDOWEVENT_TAKE_FOCUS, /**< Window is being offered a focus (should SetWindowInputFocus() on itself or a subwindow, or ignore) */
+ SDL_WINDOWEVENT_HIT_TEST /**< Window had a hit test that wasn't SDL_HITTEST_NORMAL. */
+} SDL_WindowEventID;
+
+/**
+ * \brief An opaque handle to an OpenGL context.
+ */
+typedef void *SDL_GLContext;
+
+/**
+ * \brief OpenGL configuration attributes
+ */
+typedef enum
+{
+ SDL_GL_RED_SIZE,
+ SDL_GL_GREEN_SIZE,
+ SDL_GL_BLUE_SIZE,
+ SDL_GL_ALPHA_SIZE,
+ SDL_GL_BUFFER_SIZE,
+ SDL_GL_DOUBLEBUFFER,
+ SDL_GL_DEPTH_SIZE,
+ SDL_GL_STENCIL_SIZE,
+ SDL_GL_ACCUM_RED_SIZE,
+ SDL_GL_ACCUM_GREEN_SIZE,
+ SDL_GL_ACCUM_BLUE_SIZE,
+ SDL_GL_ACCUM_ALPHA_SIZE,
+ SDL_GL_STEREO,
+ SDL_GL_MULTISAMPLEBUFFERS,
+ SDL_GL_MULTISAMPLESAMPLES,
+ SDL_GL_ACCELERATED_VISUAL,
+ SDL_GL_RETAINED_BACKING,
+ SDL_GL_CONTEXT_MAJOR_VERSION,
+ SDL_GL_CONTEXT_MINOR_VERSION,
+ SDL_GL_CONTEXT_EGL,
+ SDL_GL_CONTEXT_FLAGS,
+ SDL_GL_CONTEXT_PROFILE_MASK,
+ SDL_GL_SHARE_WITH_CURRENT_CONTEXT,
+ SDL_GL_FRAMEBUFFER_SRGB_CAPABLE,
+ SDL_GL_CONTEXT_RELEASE_BEHAVIOR,
+ SDL_GL_CONTEXT_RESET_NOTIFICATION,
+ SDL_GL_CONTEXT_NO_ERROR
+} SDL_GLattr;
+
+typedef enum
+{
+ SDL_GL_CONTEXT_PROFILE_CORE = 0x0001,
+ SDL_GL_CONTEXT_PROFILE_COMPATIBILITY = 0x0002,
+ SDL_GL_CONTEXT_PROFILE_ES = 0x0004 /**< GLX_CONTEXT_ES2_PROFILE_BIT_EXT */
+} SDL_GLprofile;
+
+typedef enum
+{
+ SDL_GL_CONTEXT_DEBUG_FLAG = 0x0001,
+ SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG = 0x0002,
+ SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG = 0x0004,
+ SDL_GL_CONTEXT_RESET_ISOLATION_FLAG = 0x0008
+} SDL_GLcontextFlag;
+
+typedef enum
+{
+ SDL_GL_CONTEXT_RELEASE_BEHAVIOR_NONE = 0x0000,
+ SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH = 0x0001
+} SDL_GLcontextReleaseFlag;
+
+typedef enum
+{
+ SDL_GL_CONTEXT_RESET_NO_NOTIFICATION = 0x0000,
+ SDL_GL_CONTEXT_RESET_LOSE_CONTEXT = 0x0001
+} SDL_GLContextResetNotification;
+
+/* Function prototypes */
+
+/**
+ * \brief Get the number of video drivers compiled into SDL
+ *
+ * \sa SDL_GetVideoDriver()
+ */
+extern DECLSPEC int SDLCALL SDL_GetNumVideoDrivers(void);
+
+/**
+ * \brief Get the name of a built in video driver.
+ *
+ * \note The video drivers are presented in the order in which they are
+ * normally checked during initialization.
+ *
+ * \sa SDL_GetNumVideoDrivers()
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetVideoDriver(int index);
+
+/**
+ * \brief Initialize the video subsystem, optionally specifying a video driver.
+ *
+ * \param driver_name Initialize a specific driver by name, or NULL for the
+ * default video driver.
+ *
+ * \return 0 on success, -1 on error
+ *
+ * This function initializes the video subsystem; setting up a connection
+ * to the window manager, etc, and determines the available display modes
+ * and pixel formats, but does not initialize a window or graphics mode.
+ *
+ * \sa SDL_VideoQuit()
+ */
+extern DECLSPEC int SDLCALL SDL_VideoInit(const char *driver_name);
+
+/**
+ * \brief Shuts down the video subsystem.
+ *
+ * This function closes all windows, and restores the original video mode.
+ *
+ * \sa SDL_VideoInit()
+ */
+extern DECLSPEC void SDLCALL SDL_VideoQuit(void);
+
+/**
+ * \brief Returns the name of the currently initialized video driver.
+ *
+ * \return The name of the current video driver or NULL if no driver
+ * has been initialized
+ *
+ * \sa SDL_GetNumVideoDrivers()
+ * \sa SDL_GetVideoDriver()
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetCurrentVideoDriver(void);
+
+/**
+ * \brief Returns the number of available video displays.
+ *
+ * \sa SDL_GetDisplayBounds()
+ */
+extern DECLSPEC int SDLCALL SDL_GetNumVideoDisplays(void);
+
+/**
+ * \brief Get the name of a display in UTF-8 encoding
+ *
+ * \return The name of a display, or NULL for an invalid display index.
+ *
+ * \sa SDL_GetNumVideoDisplays()
+ */
+extern DECLSPEC const char * SDLCALL SDL_GetDisplayName(int displayIndex);
+
+/**
+ * \brief Get the desktop area represented by a display, with the primary
+ * display located at 0,0
+ *
+ * \return 0 on success, or -1 if the index is out of range.
+ *
+ * \sa SDL_GetNumVideoDisplays()
+ */
+extern DECLSPEC int SDLCALL SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect);
+
+/**
+ * \brief Get the dots/pixels-per-inch for a display
+ *
+ * \note Diagonal, horizontal and vertical DPI can all be optionally
+ * returned if the parameter is non-NULL.
+ *
+ * \return 0 on success, or -1 if no DPI information is available or the index is out of range.
+ *
+ * \sa SDL_GetNumVideoDisplays()
+ */
+extern DECLSPEC int SDLCALL SDL_GetDisplayDPI(int displayIndex, float * ddpi, float * hdpi, float * vdpi);
+
+/**
+ * \brief Get the usable desktop area represented by a display, with the
+ * primary display located at 0,0
+ *
+ * This is the same area as SDL_GetDisplayBounds() reports, but with portions
+ * reserved by the system removed. For example, on Mac OS X, this subtracts
+ * the area occupied by the menu bar and dock.
+ *
+ * Setting a window to be fullscreen generally bypasses these unusable areas,
+ * so these are good guidelines for the maximum space available to a
+ * non-fullscreen window.
+ *
+ * \return 0 on success, or -1 if the index is out of range.
+ *
+ * \sa SDL_GetDisplayBounds()
+ * \sa SDL_GetNumVideoDisplays()
+ */
+extern DECLSPEC int SDLCALL SDL_GetDisplayUsableBounds(int displayIndex, SDL_Rect * rect);
+
+/**
+ * \brief Returns the number of available display modes.
+ *
+ * \sa SDL_GetDisplayMode()
+ */
+extern DECLSPEC int SDLCALL SDL_GetNumDisplayModes(int displayIndex);
+
+/**
+ * \brief Fill in information about a specific display mode.
+ *
+ * \note The display modes are sorted in this priority:
+ * \li bits per pixel -> more colors to fewer colors
+ * \li width -> largest to smallest
+ * \li height -> largest to smallest
+ * \li refresh rate -> highest to lowest
+ *
+ * \sa SDL_GetNumDisplayModes()
+ */
+extern DECLSPEC int SDLCALL SDL_GetDisplayMode(int displayIndex, int modeIndex,
+ SDL_DisplayMode * mode);
+
+/**
+ * \brief Fill in information about the desktop display mode.
+ */
+extern DECLSPEC int SDLCALL SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode * mode);
+
+/**
+ * \brief Fill in information about the current display mode.
+ */
+extern DECLSPEC int SDLCALL SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode * mode);
+
+
+/**
+ * \brief Get the closest match to the requested display mode.
+ *
+ * \param displayIndex The index of display from which mode should be queried.
+ * \param mode The desired display mode
+ * \param closest A pointer to a display mode to be filled in with the closest
+ * match of the available display modes.
+ *
+ * \return The passed in value \c closest, or NULL if no matching video mode
+ * was available.
+ *
+ * The available display modes are scanned, and \c closest is filled in with the
+ * closest mode matching the requested mode and returned. The mode format and
+ * refresh_rate default to the desktop mode if they are 0. The modes are
+ * scanned with size being first priority, format being second priority, and
+ * finally checking the refresh_rate. If all the available modes are too
+ * small, then NULL is returned.
+ *
+ * \sa SDL_GetNumDisplayModes()
+ * \sa SDL_GetDisplayMode()
+ */
+extern DECLSPEC SDL_DisplayMode * SDLCALL SDL_GetClosestDisplayMode(int displayIndex, const SDL_DisplayMode * mode, SDL_DisplayMode * closest);
+
+/**
+ * \brief Get the display index associated with a window.
+ *
+ * \return the display index of the display containing the center of the
+ * window, or -1 on error.
+ */
+extern DECLSPEC int SDLCALL SDL_GetWindowDisplayIndex(SDL_Window * window);
+
+/**
+ * \brief Set the display mode used when a fullscreen window is visible.
+ *
+ * By default the window's dimensions and the desktop format and refresh rate
+ * are used.
+ *
+ * \param window The window for which the display mode should be set.
+ * \param mode The mode to use, or NULL for the default mode.
+ *
+ * \return 0 on success, or -1 if setting the display mode failed.
+ *
+ * \sa SDL_GetWindowDisplayMode()
+ * \sa SDL_SetWindowFullscreen()
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowDisplayMode(SDL_Window * window,
+ const SDL_DisplayMode
+ * mode);
+
+/**
+ * \brief Fill in information about the display mode used when a fullscreen
+ * window is visible.
+ *
+ * \sa SDL_SetWindowDisplayMode()
+ * \sa SDL_SetWindowFullscreen()
+ */
+extern DECLSPEC int SDLCALL SDL_GetWindowDisplayMode(SDL_Window * window,
+ SDL_DisplayMode * mode);
+
+/**
+ * \brief Get the pixel format associated with the window.
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_GetWindowPixelFormat(SDL_Window * window);
+
+/**
+ * \brief Create a window with the specified position, dimensions, and flags.
+ *
+ * \param title The title of the window, in UTF-8 encoding.
+ * \param x The x position of the window, ::SDL_WINDOWPOS_CENTERED, or
+ * ::SDL_WINDOWPOS_UNDEFINED.
+ * \param y The y position of the window, ::SDL_WINDOWPOS_CENTERED, or
+ * ::SDL_WINDOWPOS_UNDEFINED.
+ * \param w The width of the window, in screen coordinates.
+ * \param h The height of the window, in screen coordinates.
+ * \param flags The flags for the window, a mask of any of the following:
+ * ::SDL_WINDOW_FULLSCREEN, ::SDL_WINDOW_OPENGL,
+ * ::SDL_WINDOW_HIDDEN, ::SDL_WINDOW_BORDERLESS,
+ * ::SDL_WINDOW_RESIZABLE, ::SDL_WINDOW_MAXIMIZED,
+ * ::SDL_WINDOW_MINIMIZED, ::SDL_WINDOW_INPUT_GRABBED,
+ * ::SDL_WINDOW_ALLOW_HIGHDPI, ::SDL_WINDOW_VULKAN.
+ *
+ * \return The created window, or NULL if window creation failed.
+ *
+ * If the window is created with the SDL_WINDOW_ALLOW_HIGHDPI flag, its size
+ * in pixels may differ from its size in screen coordinates on platforms with
+ * high-DPI support (e.g. iOS and Mac OS X). Use SDL_GetWindowSize() to query
+ * the client area's size in screen coordinates, and SDL_GL_GetDrawableSize(),
+ * SDL_Vulkan_GetDrawableSize(), or SDL_GetRendererOutputSize() to query the
+ * drawable size in pixels.
+ *
+ * If the window is created with any of the SDL_WINDOW_OPENGL or
+ * SDL_WINDOW_VULKAN flags, then the corresponding LoadLibrary function
+ * (SDL_GL_LoadLibrary or SDL_Vulkan_LoadLibrary) is called and the
+ * corresponding UnloadLibrary function is called by SDL_DestroyWindow().
+ *
+ * If SDL_WINDOW_VULKAN is specified and there isn't a working Vulkan driver,
+ * SDL_CreateWindow() will fail because SDL_Vulkan_LoadLibrary() will fail.
+ *
+ * \note On non-Apple devices, SDL requires you to either not link to the
+ * Vulkan loader or link to a dynamic library version. This limitation
+ * may be removed in a future version of SDL.
+ *
+ * \sa SDL_DestroyWindow()
+ * \sa SDL_GL_LoadLibrary()
+ * \sa SDL_Vulkan_LoadLibrary()
+ */
+extern DECLSPEC SDL_Window * SDLCALL SDL_CreateWindow(const char *title,
+ int x, int y, int w,
+ int h, Uint32 flags);
+
+/**
+ * \brief Create an SDL window from an existing native window.
+ *
+ * \param data A pointer to driver-dependent window creation data
+ *
+ * \return The created window, or NULL if window creation failed.
+ *
+ * \sa SDL_DestroyWindow()
+ */
+extern DECLSPEC SDL_Window * SDLCALL SDL_CreateWindowFrom(const void *data);
+
+/**
+ * \brief Get the numeric ID of a window, for logging purposes.
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_GetWindowID(SDL_Window * window);
+
+/**
+ * \brief Get a window from a stored ID, or NULL if it doesn't exist.
+ */
+extern DECLSPEC SDL_Window * SDLCALL SDL_GetWindowFromID(Uint32 id);
+
+/**
+ * \brief Get the window flags.
+ */
+extern DECLSPEC Uint32 SDLCALL SDL_GetWindowFlags(SDL_Window * window);
+
+/**
+ * \brief Set the title of a window, in UTF-8 format.
+ *
+ * \sa SDL_GetWindowTitle()
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowTitle(SDL_Window * window,
+ const char *title);
+
+/**
+ * \brief Get the title of a window, in UTF-8 format.
+ *
+ * \sa SDL_SetWindowTitle()
+ */
+extern DECLSPEC const char *SDLCALL SDL_GetWindowTitle(SDL_Window * window);
+
+/**
+ * \brief Set the icon for a window.
+ *
+ * \param window The window for which the icon should be set.
+ * \param icon The icon for the window.
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowIcon(SDL_Window * window,
+ SDL_Surface * icon);
+
+/**
+ * \brief Associate an arbitrary named pointer with a window.
+ *
+ * \param window The window to associate with the pointer.
+ * \param name The name of the pointer.
+ * \param userdata The associated pointer.
+ *
+ * \return The previous value associated with 'name'
+ *
+ * \note The name is case-sensitive.
+ *
+ * \sa SDL_GetWindowData()
+ */
+extern DECLSPEC void* SDLCALL SDL_SetWindowData(SDL_Window * window,
+ const char *name,
+ void *userdata);
+
+/**
+ * \brief Retrieve the data pointer associated with a window.
+ *
+ * \param window The window to query.
+ * \param name The name of the pointer.
+ *
+ * \return The value associated with 'name'
+ *
+ * \sa SDL_SetWindowData()
+ */
+extern DECLSPEC void *SDLCALL SDL_GetWindowData(SDL_Window * window,
+ const char *name);
+
+/**
+ * \brief Set the position of a window.
+ *
+ * \param window The window to reposition.
+ * \param x The x coordinate of the window in screen coordinates, or
+ * ::SDL_WINDOWPOS_CENTERED or ::SDL_WINDOWPOS_UNDEFINED.
+ * \param y The y coordinate of the window in screen coordinates, or
+ * ::SDL_WINDOWPOS_CENTERED or ::SDL_WINDOWPOS_UNDEFINED.
+ *
+ * \note The window coordinate origin is the upper left of the display.
+ *
+ * \sa SDL_GetWindowPosition()
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowPosition(SDL_Window * window,
+ int x, int y);
+
+/**
+ * \brief Get the position of a window.
+ *
+ * \param window The window to query.
+ * \param x Pointer to variable for storing the x position, in screen
+ * coordinates. May be NULL.
+ * \param y Pointer to variable for storing the y position, in screen
+ * coordinates. May be NULL.
+ *
+ * \sa SDL_SetWindowPosition()
+ */
+extern DECLSPEC void SDLCALL SDL_GetWindowPosition(SDL_Window * window,
+ int *x, int *y);
+
+/**
+ * \brief Set the size of a window's client area.
+ *
+ * \param window The window to resize.
+ * \param w The width of the window, in screen coordinates. Must be >0.
+ * \param h The height of the window, in screen coordinates. Must be >0.
+ *
+ * \note Fullscreen windows automatically match the size of the display mode,
+ * and you should use SDL_SetWindowDisplayMode() to change their size.
+ *
+ * The window size in screen coordinates may differ from the size in pixels, if
+ * the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a platform with
+ * high-dpi support (e.g. iOS or OS X). Use SDL_GL_GetDrawableSize() or
+ * SDL_GetRendererOutputSize() to get the real client area size in pixels.
+ *
+ * \sa SDL_GetWindowSize()
+ * \sa SDL_SetWindowDisplayMode()
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowSize(SDL_Window * window, int w,
+ int h);
+
+/**
+ * \brief Get the size of a window's client area.
+ *
+ * \param window The window to query.
+ * \param w Pointer to variable for storing the width, in screen
+ * coordinates. May be NULL.
+ * \param h Pointer to variable for storing the height, in screen
+ * coordinates. May be NULL.
+ *
+ * The window size in screen coordinates may differ from the size in pixels, if
+ * the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a platform with
+ * high-dpi support (e.g. iOS or OS X). Use SDL_GL_GetDrawableSize() or
+ * SDL_GetRendererOutputSize() to get the real client area size in pixels.
+ *
+ * \sa SDL_SetWindowSize()
+ */
+extern DECLSPEC void SDLCALL SDL_GetWindowSize(SDL_Window * window, int *w,
+ int *h);
+
+/**
+ * \brief Get the size of a window's borders (decorations) around the client area.
+ *
+ * \param window The window to query.
+ * \param top Pointer to variable for storing the size of the top border. NULL is permitted.
+ * \param left Pointer to variable for storing the size of the left border. NULL is permitted.
+ * \param bottom Pointer to variable for storing the size of the bottom border. NULL is permitted.
+ * \param right Pointer to variable for storing the size of the right border. NULL is permitted.
+ *
+ * \return 0 on success, or -1 if getting this information is not supported.
+ *
+ * \note if this function fails (returns -1), the size values will be
+ * initialized to 0, 0, 0, 0 (if a non-NULL pointer is provided), as
+ * if the window in question was borderless.
+ */
+extern DECLSPEC int SDLCALL SDL_GetWindowBordersSize(SDL_Window * window,
+ int *top, int *left,
+ int *bottom, int *right);
+
+/**
+ * \brief Set the minimum size of a window's client area.
+ *
+ * \param window The window to set a new minimum size.
+ * \param min_w The minimum width of the window, must be >0
+ * \param min_h The minimum height of the window, must be >0
+ *
+ * \note You can't change the minimum size of a fullscreen window, it
+ * automatically matches the size of the display mode.
+ *
+ * \sa SDL_GetWindowMinimumSize()
+ * \sa SDL_SetWindowMaximumSize()
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowMinimumSize(SDL_Window * window,
+ int min_w, int min_h);
+
+/**
+ * \brief Get the minimum size of a window's client area.
+ *
+ * \param window The window to query.
+ * \param w Pointer to variable for storing the minimum width, may be NULL
+ * \param h Pointer to variable for storing the minimum height, may be NULL
+ *
+ * \sa SDL_GetWindowMaximumSize()
+ * \sa SDL_SetWindowMinimumSize()
+ */
+extern DECLSPEC void SDLCALL SDL_GetWindowMinimumSize(SDL_Window * window,
+ int *w, int *h);
+
+/**
+ * \brief Set the maximum size of a window's client area.
+ *
+ * \param window The window to set a new maximum size.
+ * \param max_w The maximum width of the window, must be >0
+ * \param max_h The maximum height of the window, must be >0
+ *
+ * \note You can't change the maximum size of a fullscreen window, it
+ * automatically matches the size of the display mode.
+ *
+ * \sa SDL_GetWindowMaximumSize()
+ * \sa SDL_SetWindowMinimumSize()
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowMaximumSize(SDL_Window * window,
+ int max_w, int max_h);
+
+/**
+ * \brief Get the maximum size of a window's client area.
+ *
+ * \param window The window to query.
+ * \param w Pointer to variable for storing the maximum width, may be NULL
+ * \param h Pointer to variable for storing the maximum height, may be NULL
+ *
+ * \sa SDL_GetWindowMinimumSize()
+ * \sa SDL_SetWindowMaximumSize()
+ */
+extern DECLSPEC void SDLCALL SDL_GetWindowMaximumSize(SDL_Window * window,
+ int *w, int *h);
+
+/**
+ * \brief Set the border state of a window.
+ *
+ * This will add or remove the window's SDL_WINDOW_BORDERLESS flag and
+ * add or remove the border from the actual window. This is a no-op if the
+ * window's border already matches the requested state.
+ *
+ * \param window The window of which to change the border state.
+ * \param bordered SDL_FALSE to remove border, SDL_TRUE to add border.
+ *
+ * \note You can't change the border state of a fullscreen window.
+ *
+ * \sa SDL_GetWindowFlags()
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowBordered(SDL_Window * window,
+ SDL_bool bordered);
+
+/**
+ * \brief Set the user-resizable state of a window.
+ *
+ * This will add or remove the window's SDL_WINDOW_RESIZABLE flag and
+ * allow/disallow user resizing of the window. This is a no-op if the
+ * window's resizable state already matches the requested state.
+ *
+ * \param window The window of which to change the resizable state.
+ * \param resizable SDL_TRUE to allow resizing, SDL_FALSE to disallow.
+ *
+ * \note You can't change the resizable state of a fullscreen window.
+ *
+ * \sa SDL_GetWindowFlags()
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowResizable(SDL_Window * window,
+ SDL_bool resizable);
+
+/**
+ * \brief Show a window.
+ *
+ * \sa SDL_HideWindow()
+ */
+extern DECLSPEC void SDLCALL SDL_ShowWindow(SDL_Window * window);
+
+/**
+ * \brief Hide a window.
+ *
+ * \sa SDL_ShowWindow()
+ */
+extern DECLSPEC void SDLCALL SDL_HideWindow(SDL_Window * window);
+
+/**
+ * \brief Raise a window above other windows and set the input focus.
+ */
+extern DECLSPEC void SDLCALL SDL_RaiseWindow(SDL_Window * window);
+
+/**
+ * \brief Make a window as large as possible.
+ *
+ * \sa SDL_RestoreWindow()
+ */
+extern DECLSPEC void SDLCALL SDL_MaximizeWindow(SDL_Window * window);
+
+/**
+ * \brief Minimize a window to an iconic representation.
+ *
+ * \sa SDL_RestoreWindow()
+ */
+extern DECLSPEC void SDLCALL SDL_MinimizeWindow(SDL_Window * window);
+
+/**
+ * \brief Restore the size and position of a minimized or maximized window.
+ *
+ * \sa SDL_MaximizeWindow()
+ * \sa SDL_MinimizeWindow()
+ */
+extern DECLSPEC void SDLCALL SDL_RestoreWindow(SDL_Window * window);
+
+/**
+ * \brief Set a window's fullscreen state.
+ *
+ * \return 0 on success, or -1 if setting the display mode failed.
+ *
+ * \sa SDL_SetWindowDisplayMode()
+ * \sa SDL_GetWindowDisplayMode()
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowFullscreen(SDL_Window * window,
+ Uint32 flags);
+
+/**
+ * \brief Get the SDL surface associated with the window.
+ *
+ * \return The window's framebuffer surface, or NULL on error.
+ *
+ * A new surface will be created with the optimal format for the window,
+ * if necessary. This surface will be freed when the window is destroyed.
+ *
+ * \note You may not combine this with 3D or the rendering API on this window.
+ *
+ * \sa SDL_UpdateWindowSurface()
+ * \sa SDL_UpdateWindowSurfaceRects()
+ */
+extern DECLSPEC SDL_Surface * SDLCALL SDL_GetWindowSurface(SDL_Window * window);
+
+/**
+ * \brief Copy the window surface to the screen.
+ *
+ * \return 0 on success, or -1 on error.
+ *
+ * \sa SDL_GetWindowSurface()
+ * \sa SDL_UpdateWindowSurfaceRects()
+ */
+extern DECLSPEC int SDLCALL SDL_UpdateWindowSurface(SDL_Window * window);
+
+/**
+ * \brief Copy a number of rectangles on the window surface to the screen.
+ *
+ * \return 0 on success, or -1 on error.
+ *
+ * \sa SDL_GetWindowSurface()
+ * \sa SDL_UpdateWindowSurface()
+ */
+extern DECLSPEC int SDLCALL SDL_UpdateWindowSurfaceRects(SDL_Window * window,
+ const SDL_Rect * rects,
+ int numrects);
+
+/**
+ * \brief Set a window's input grab mode.
+ *
+ * \param window The window for which the input grab mode should be set.
+ * \param grabbed This is SDL_TRUE to grab input, and SDL_FALSE to release input.
+ *
+ * If the caller enables a grab while another window is currently grabbed,
+ * the other window loses its grab in favor of the caller's window.
+ *
+ * \sa SDL_GetWindowGrab()
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowGrab(SDL_Window * window,
+ SDL_bool grabbed);
+
+/**
+ * \brief Get a window's input grab mode.
+ *
+ * \return This returns SDL_TRUE if input is grabbed, and SDL_FALSE otherwise.
+ *
+ * \sa SDL_SetWindowGrab()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_GetWindowGrab(SDL_Window * window);
+
+/**
+ * \brief Get the window that currently has an input grab enabled.
+ *
+ * \return This returns the window if input is grabbed, and NULL otherwise.
+ *
+ * \sa SDL_SetWindowGrab()
+ */
+extern DECLSPEC SDL_Window * SDLCALL SDL_GetGrabbedWindow(void);
+
+/**
+ * \brief Set the brightness (gamma correction) for a window.
+ *
+ * \return 0 on success, or -1 if setting the brightness isn't supported.
+ *
+ * \sa SDL_GetWindowBrightness()
+ * \sa SDL_SetWindowGammaRamp()
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowBrightness(SDL_Window * window, float brightness);
+
+/**
+ * \brief Get the brightness (gamma correction) for a window.
+ *
+ * \return The last brightness value passed to SDL_SetWindowBrightness()
+ *
+ * \sa SDL_SetWindowBrightness()
+ */
+extern DECLSPEC float SDLCALL SDL_GetWindowBrightness(SDL_Window * window);
+
+/**
+ * \brief Set the opacity for a window
+ *
+ * \param window The window which will be made transparent or opaque
+ * \param opacity Opacity (0.0f - transparent, 1.0f - opaque) This will be
+ * clamped internally between 0.0f and 1.0f.
+ *
+ * \return 0 on success, or -1 if setting the opacity isn't supported.
+ *
+ * \sa SDL_GetWindowOpacity()
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowOpacity(SDL_Window * window, float opacity);
+
+/**
+ * \brief Get the opacity of a window.
+ *
+ * If transparency isn't supported on this platform, opacity will be reported
+ * as 1.0f without error.
+ *
+ * \param window The window in question.
+ * \param out_opacity Opacity (0.0f - transparent, 1.0f - opaque)
+ *
+ * \return 0 on success, or -1 on error (invalid window, etc).
+ *
+ * \sa SDL_SetWindowOpacity()
+ */
+extern DECLSPEC int SDLCALL SDL_GetWindowOpacity(SDL_Window * window, float * out_opacity);
+
+/**
+ * \brief Sets the window as a modal for another window (TODO: reconsider this function and/or its name)
+ *
+ * \param modal_window The window that should be modal
+ * \param parent_window The parent window
+ *
+ * \return 0 on success, or -1 otherwise.
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowModalFor(SDL_Window * modal_window, SDL_Window * parent_window);
+
+/**
+ * \brief Explicitly sets input focus to the window.
+ *
+ * You almost certainly want SDL_RaiseWindow() instead of this function. Use
+ * this with caution, as you might give focus to a window that's completely
+ * obscured by other windows.
+ *
+ * \param window The window that should get the input focus
+ *
+ * \return 0 on success, or -1 otherwise.
+ * \sa SDL_RaiseWindow()
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowInputFocus(SDL_Window * window);
+
+/**
+ * \brief Set the gamma ramp for a window.
+ *
+ * \param window The window for which the gamma ramp should be set.
+ * \param red The translation table for the red channel, or NULL.
+ * \param green The translation table for the green channel, or NULL.
+ * \param blue The translation table for the blue channel, or NULL.
+ *
+ * \return 0 on success, or -1 if gamma ramps are unsupported.
+ *
+ * Set the gamma translation table for the red, green, and blue channels
+ * of the video hardware. Each table is an array of 256 16-bit quantities,
+ * representing a mapping between the input and output for that channel.
+ * The input is the index into the array, and the output is the 16-bit
+ * gamma value at that index, scaled to the output color precision.
+ *
+ * \sa SDL_GetWindowGammaRamp()
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowGammaRamp(SDL_Window * window,
+ const Uint16 * red,
+ const Uint16 * green,
+ const Uint16 * blue);
+
+/**
+ * \brief Get the gamma ramp for a window.
+ *
+ * \param window The window from which the gamma ramp should be queried.
+ * \param red A pointer to a 256 element array of 16-bit quantities to hold
+ * the translation table for the red channel, or NULL.
+ * \param green A pointer to a 256 element array of 16-bit quantities to hold
+ * the translation table for the green channel, or NULL.
+ * \param blue A pointer to a 256 element array of 16-bit quantities to hold
+ * the translation table for the blue channel, or NULL.
+ *
+ * \return 0 on success, or -1 if gamma ramps are unsupported.
+ *
+ * \sa SDL_SetWindowGammaRamp()
+ */
+extern DECLSPEC int SDLCALL SDL_GetWindowGammaRamp(SDL_Window * window,
+ Uint16 * red,
+ Uint16 * green,
+ Uint16 * blue);
+
+/**
+ * \brief Possible return values from the SDL_HitTest callback.
+ *
+ * \sa SDL_HitTest
+ */
+typedef enum
+{
+ SDL_HITTEST_NORMAL, /**< Region is normal. No special properties. */
+ SDL_HITTEST_DRAGGABLE, /**< Region can drag entire window. */
+ SDL_HITTEST_RESIZE_TOPLEFT,
+ SDL_HITTEST_RESIZE_TOP,
+ SDL_HITTEST_RESIZE_TOPRIGHT,
+ SDL_HITTEST_RESIZE_RIGHT,
+ SDL_HITTEST_RESIZE_BOTTOMRIGHT,
+ SDL_HITTEST_RESIZE_BOTTOM,
+ SDL_HITTEST_RESIZE_BOTTOMLEFT,
+ SDL_HITTEST_RESIZE_LEFT
+} SDL_HitTestResult;
+
+/**
+ * \brief Callback used for hit-testing.
+ *
+ * \sa SDL_SetWindowHitTest
+ */
+typedef SDL_HitTestResult (SDLCALL *SDL_HitTest)(SDL_Window *win,
+ const SDL_Point *area,
+ void *data);
+
+/**
+ * \brief Provide a callback that decides if a window region has special properties.
+ *
+ * Normally windows are dragged and resized by decorations provided by the
+ * system window manager (a title bar, borders, etc), but for some apps, it
+ * makes sense to drag them from somewhere else inside the window itself; for
+ * example, one might have a borderless window that wants to be draggable
+ * from any part, or simulate its own title bar, etc.
+ *
+ * This function lets the app provide a callback that designates pieces of
+ * a given window as special. This callback is run during event processing
+ * if we need to tell the OS to treat a region of the window specially; the
+ * use of this callback is known as "hit testing."
+ *
+ * Mouse input may not be delivered to your application if it is within
+ * a special area; the OS will often apply that input to moving the window or
+ * resizing the window and not deliver it to the application.
+ *
+ * Specifying NULL for a callback disables hit-testing. Hit-testing is
+ * disabled by default.
+ *
+ * Platforms that don't support this functionality will return -1
+ * unconditionally, even if you're attempting to disable hit-testing.
+ *
+ * Your callback may fire at any time, and its firing does not indicate any
+ * specific behavior (for example, on Windows, this certainly might fire
+ * when the OS is deciding whether to drag your window, but it fires for lots
+ * of other reasons, too, some unrelated to anything you probably care about
+ * _and when the mouse isn't actually at the location it is testing_).
+ * Since this can fire at any time, you should try to keep your callback
+ * efficient, devoid of allocations, etc.
+ *
+ * \param window The window to set hit-testing on.
+ * \param callback The callback to call when doing a hit-test.
+ * \param callback_data An app-defined void pointer passed to the callback.
+ * \return 0 on success, -1 on error (including unsupported).
+ */
+extern DECLSPEC int SDLCALL SDL_SetWindowHitTest(SDL_Window * window,
+ SDL_HitTest callback,
+ void *callback_data);
+
+/**
+ * \brief Destroy a window.
+ */
+extern DECLSPEC void SDLCALL SDL_DestroyWindow(SDL_Window * window);
+
+
+/**
+ * \brief Returns whether the screensaver is currently enabled (default off).
+ *
+ * \sa SDL_EnableScreenSaver()
+ * \sa SDL_DisableScreenSaver()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_IsScreenSaverEnabled(void);
+
+/**
+ * \brief Allow the screen to be blanked by a screensaver
+ *
+ * \sa SDL_IsScreenSaverEnabled()
+ * \sa SDL_DisableScreenSaver()
+ */
+extern DECLSPEC void SDLCALL SDL_EnableScreenSaver(void);
+
+/**
+ * \brief Prevent the screen from being blanked by a screensaver
+ *
+ * \sa SDL_IsScreenSaverEnabled()
+ * \sa SDL_EnableScreenSaver()
+ */
+extern DECLSPEC void SDLCALL SDL_DisableScreenSaver(void);
+
+
+/**
+ * \name OpenGL support functions
+ */
+/* @{ */
+
+/**
+ * \brief Dynamically load an OpenGL library.
+ *
+ * \param path The platform dependent OpenGL library name, or NULL to open the
+ * default OpenGL library.
+ *
+ * \return 0 on success, or -1 if the library couldn't be loaded.
+ *
+ * This should be done after initializing the video driver, but before
+ * creating any OpenGL windows. If no OpenGL library is loaded, the default
+ * library will be loaded upon creation of the first OpenGL window.
+ *
+ * \note If you do this, you need to retrieve all of the GL functions used in
+ * your program from the dynamic library using SDL_GL_GetProcAddress().
+ *
+ * \sa SDL_GL_GetProcAddress()
+ * \sa SDL_GL_UnloadLibrary()
+ */
+extern DECLSPEC int SDLCALL SDL_GL_LoadLibrary(const char *path);
+
+/**
+ * \brief Get the address of an OpenGL function.
+ */
+extern DECLSPEC void *SDLCALL SDL_GL_GetProcAddress(const char *proc);
+
+/**
+ * \brief Unload the OpenGL library previously loaded by SDL_GL_LoadLibrary().
+ *
+ * \sa SDL_GL_LoadLibrary()
+ */
+extern DECLSPEC void SDLCALL SDL_GL_UnloadLibrary(void);
+
+/**
+ * \brief Return true if an OpenGL extension is supported for the current
+ * context.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_GL_ExtensionSupported(const char
+ *extension);
+
+/**
+ * \brief Reset all previously set OpenGL context attributes to their default values
+ */
+extern DECLSPEC void SDLCALL SDL_GL_ResetAttributes(void);
+
+/**
+ * \brief Set an OpenGL window attribute before window creation.
+ *
+ * \return 0 on success, or -1 if the attribute could not be set.
+ */
+extern DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value);
+
+/**
+ * \brief Get the actual value for an attribute from the current context.
+ *
+ * \return 0 on success, or -1 if the attribute could not be retrieved.
+ * The integer at \c value will be modified in either case.
+ */
+extern DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int *value);
+
+/**
+ * \brief Create an OpenGL context for use with an OpenGL window, and make it
+ * current.
+ *
+ * \sa SDL_GL_DeleteContext()
+ */
+extern DECLSPEC SDL_GLContext SDLCALL SDL_GL_CreateContext(SDL_Window *
+ window);
+
+/**
+ * \brief Set up an OpenGL context for rendering into an OpenGL window.
+ *
+ * \note The context must have been created with a compatible window.
+ */
+extern DECLSPEC int SDLCALL SDL_GL_MakeCurrent(SDL_Window * window,
+ SDL_GLContext context);
+
+/**
+ * \brief Get the currently active OpenGL window.
+ */
+extern DECLSPEC SDL_Window* SDLCALL SDL_GL_GetCurrentWindow(void);
+
+/**
+ * \brief Get the currently active OpenGL context.
+ */
+extern DECLSPEC SDL_GLContext SDLCALL SDL_GL_GetCurrentContext(void);
+
+/**
+ * \brief Get the size of a window's underlying drawable in pixels (for use
+ * with glViewport).
+ *
+ * \param window Window from which the drawable size should be queried
+ * \param w Pointer to variable for storing the width in pixels, may be NULL
+ * \param h Pointer to variable for storing the height in pixels, may be NULL
+ *
+ * This may differ from SDL_GetWindowSize() if we're rendering to a high-DPI
+ * drawable, i.e. the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a
+ * platform with high-DPI support (Apple calls this "Retina"), and not disabled
+ * by the SDL_HINT_VIDEO_HIGHDPI_DISABLED hint.
+ *
+ * \sa SDL_GetWindowSize()
+ * \sa SDL_CreateWindow()
+ */
+extern DECLSPEC void SDLCALL SDL_GL_GetDrawableSize(SDL_Window * window, int *w,
+ int *h);
+
+/**
+ * \brief Set the swap interval for the current OpenGL context.
+ *
+ * \param interval 0 for immediate updates, 1 for updates synchronized with the
+ * vertical retrace. If the system supports it, you may
+ * specify -1 to allow late swaps to happen immediately
+ * instead of waiting for the next retrace.
+ *
+ * \return 0 on success, or -1 if setting the swap interval is not supported.
+ *
+ * \sa SDL_GL_GetSwapInterval()
+ */
+extern DECLSPEC int SDLCALL SDL_GL_SetSwapInterval(int interval);
+
+/**
+ * \brief Get the swap interval for the current OpenGL context.
+ *
+ * \return 0 if there is no vertical retrace synchronization, 1 if the buffer
+ * swap is synchronized with the vertical retrace, and -1 if late
+ * swaps happen immediately instead of waiting for the next retrace.
+ * If the system can't determine the swap interval, or there isn't a
+ * valid current context, this will return 0 as a safe default.
+ *
+ * \sa SDL_GL_SetSwapInterval()
+ */
+extern DECLSPEC int SDLCALL SDL_GL_GetSwapInterval(void);
+
+/**
+ * \brief Swap the OpenGL buffers for a window, if double-buffering is
+ * supported.
+ */
+extern DECLSPEC void SDLCALL SDL_GL_SwapWindow(SDL_Window * window);
+
+/**
+ * \brief Delete an OpenGL context.
+ *
+ * \sa SDL_GL_CreateContext()
+ */
+extern DECLSPEC void SDLCALL SDL_GL_DeleteContext(SDL_GLContext context);
+
+/* @} *//* OpenGL support functions */
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_video_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/include/SDL_vulkan.h b/src/3rdparty/SDL2/include/SDL_vulkan.h
new file mode 100644
index 0000000..f04c21a
--- /dev/null
+++ b/src/3rdparty/SDL2/include/SDL_vulkan.h
@@ -0,0 +1,273 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 2017, Mark Callow
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file SDL_vulkan.h
+ *
+ * Header file for functions to creating Vulkan surfaces on SDL windows.
+ */
+
+#ifndef SDL_vulkan_h_
+#define SDL_vulkan_h_
+
+#include "SDL_video.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Avoid including vulkan.h, don't define VkInstance if it's already included */
+#ifdef VULKAN_H_
+#define NO_SDL_VULKAN_TYPEDEFS
+#endif
+#ifndef NO_SDL_VULKAN_TYPEDEFS
+#define VK_DEFINE_HANDLE(object) typedef struct object##_T* object;
+
+#if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
+#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object;
+#else
+#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
+#endif
+
+VK_DEFINE_HANDLE(VkInstance)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSurfaceKHR)
+
+#endif /* !NO_SDL_VULKAN_TYPEDEFS */
+
+typedef VkInstance SDL_vulkanInstance;
+typedef VkSurfaceKHR SDL_vulkanSurface; /* for compatibility with Tizen */
+
+/**
+ * \name Vulkan support functions
+ *
+ * \note SDL_Vulkan_GetInstanceExtensions & SDL_Vulkan_CreateSurface API
+ * is compatable with Tizen's implementation of Vulkan in SDL.
+ */
+/* @{ */
+
+/**
+ * \brief Dynamically load a Vulkan loader library.
+ *
+ * \param [in] path The platform dependent Vulkan loader library name, or
+ * \c NULL.
+ *
+ * \return \c 0 on success, or \c -1 if the library couldn't be loaded.
+ *
+ * If \a path is NULL SDL will use the value of the environment variable
+ * \c SDL_VULKAN_LIBRARY, if set, otherwise it loads the default Vulkan
+ * loader library.
+ *
+ * This should be called after initializing the video driver, but before
+ * creating any Vulkan windows. If no Vulkan loader library is loaded, the
+ * default library will be loaded upon creation of the first Vulkan window.
+ *
+ * \note It is fairly common for Vulkan applications to link with \a libvulkan
+ * instead of explicitly loading it at run time. This will work with
+ * SDL provided the application links to a dynamic library and both it
+ * and SDL use the same search path.
+ *
+ * \note If you specify a non-NULL \c path, an application should retrieve all
+ * of the Vulkan functions it uses from the dynamic library using
+ * \c SDL_Vulkan_GetVkGetInstanceProcAddr() unless you can guarantee
+ * \c path points to the same vulkan loader library the application
+ * linked to.
+ *
+ * \note On Apple devices, if \a path is NULL, SDL will attempt to find
+ * the vkGetInstanceProcAddr address within all the mach-o images of
+ * the current process. This is because it is fairly common for Vulkan
+ * applications to link with libvulkan (and historically MoltenVK was
+ * provided as a static library). If it is not found then, on macOS, SDL
+ * will attempt to load \c vulkan.framework/vulkan, \c libvulkan.1.dylib,
+ * \c MoltenVK.framework/MoltenVK and \c libMoltenVK.dylib in that order.
+ * On iOS SDL will attempt to load \c libMoltenVK.dylib. Applications
+ * using a dynamic framework or .dylib must ensure it is included in its
+ * application bundle.
+ *
+ * \note On non-Apple devices, application linking with a static libvulkan is
+ * not supported. Either do not link to the Vulkan loader or link to a
+ * dynamic library version.
+ *
+ * \note This function will fail if there are no working Vulkan drivers
+ * installed.
+ *
+ * \sa SDL_Vulkan_GetVkGetInstanceProcAddr()
+ * \sa SDL_Vulkan_UnloadLibrary()
+ */
+extern DECLSPEC int SDLCALL SDL_Vulkan_LoadLibrary(const char *path);
+
+/**
+ * \brief Get the address of the \c vkGetInstanceProcAddr function.
+ *
+ * \note This should be called after either calling SDL_Vulkan_LoadLibrary
+ * or creating an SDL_Window with the SDL_WINDOW_VULKAN flag.
+ */
+extern DECLSPEC void *SDLCALL SDL_Vulkan_GetVkGetInstanceProcAddr(void);
+
+/**
+ * \brief Unload the Vulkan loader library previously loaded by
+ * \c SDL_Vulkan_LoadLibrary().
+ *
+ * \sa SDL_Vulkan_LoadLibrary()
+ */
+extern DECLSPEC void SDLCALL SDL_Vulkan_UnloadLibrary(void);
+
+/**
+ * \brief Get the names of the Vulkan instance extensions needed to create
+ * a surface with \c SDL_Vulkan_CreateSurface().
+ *
+ * \param [in] window Window for which the required Vulkan instance
+ * extensions should be retrieved
+ * \param [in,out] count pointer to an \c unsigned related to the number of
+ * required Vulkan instance extensions
+ * \param [out] names \c NULL or a pointer to an array to be filled with the
+ * required Vulkan instance extensions
+ *
+ * \return \c SDL_TRUE on success, \c SDL_FALSE on error.
+ *
+ * If \a pNames is \c NULL, then the number of required Vulkan instance
+ * extensions is returned in pCount. Otherwise, \a pCount must point to a
+ * variable set to the number of elements in the \a pNames array, and on
+ * return the variable is overwritten with the number of names actually
+ * written to \a pNames. If \a pCount is less than the number of required
+ * extensions, at most \a pCount structures will be written. If \a pCount
+ * is smaller than the number of required extensions, \c SDL_FALSE will be
+ * returned instead of \c SDL_TRUE, to indicate that not all the required
+ * extensions were returned.
+ *
+ * \note The returned list of extensions will contain \c VK_KHR_surface
+ * and zero or more platform specific extensions
+ *
+ * \note The extension names queried here must be enabled when calling
+ * VkCreateInstance, otherwise surface creation will fail.
+ *
+ * \note \c window should have been created with the \c SDL_WINDOW_VULKAN flag.
+ *
+ * \code
+ * unsigned int count;
+ * // get count of required extensions
+ * if(!SDL_Vulkan_GetInstanceExtensions(window, &count, NULL))
+ * handle_error();
+ *
+ * static const char *const additionalExtensions[] =
+ * {
+ * VK_EXT_DEBUG_REPORT_EXTENSION_NAME, // example additional extension
+ * };
+ * size_t additionalExtensionsCount = sizeof(additionalExtensions) / sizeof(additionalExtensions[0]);
+ * size_t extensionCount = count + additionalExtensionsCount;
+ * const char **names = malloc(sizeof(const char *) * extensionCount);
+ * if(!names)
+ * handle_error();
+ *
+ * // get names of required extensions
+ * if(!SDL_Vulkan_GetInstanceExtensions(window, &count, names))
+ * handle_error();
+ *
+ * // copy additional extensions after required extensions
+ * for(size_t i = 0; i < additionalExtensionsCount; i++)
+ * names[i + count] = additionalExtensions[i];
+ *
+ * VkInstanceCreateInfo instanceCreateInfo = {};
+ * instanceCreateInfo.enabledExtensionCount = extensionCount;
+ * instanceCreateInfo.ppEnabledExtensionNames = names;
+ * // fill in rest of instanceCreateInfo
+ *
+ * VkInstance instance;
+ * // create the Vulkan instance
+ * VkResult result = vkCreateInstance(&instanceCreateInfo, NULL, &instance);
+ * free(names);
+ * \endcode
+ *
+ * \sa SDL_Vulkan_CreateSurface()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_Vulkan_GetInstanceExtensions(
+ SDL_Window *window,
+ unsigned int *pCount,
+ const char **pNames);
+
+/**
+ * \brief Create a Vulkan rendering surface for a window.
+ *
+ * \param [in] window SDL_Window to which to attach the rendering surface.
+ * \param [in] instance handle to the Vulkan instance to use.
+ * \param [out] surface pointer to a VkSurfaceKHR handle to receive the
+ * handle of the newly created surface.
+ *
+ * \return \c SDL_TRUE on success, \c SDL_FALSE on error.
+ *
+ * \code
+ * VkInstance instance;
+ * SDL_Window *window;
+ *
+ * // create instance and window
+ *
+ * // create the Vulkan surface
+ * VkSurfaceKHR surface;
+ * if(!SDL_Vulkan_CreateSurface(window, instance, &surface))
+ * handle_error();
+ * \endcode
+ *
+ * \note \a window should have been created with the \c SDL_WINDOW_VULKAN flag.
+ *
+ * \note \a instance should have been created with the extensions returned
+ * by \c SDL_Vulkan_CreateSurface() enabled.
+ *
+ * \sa SDL_Vulkan_GetInstanceExtensions()
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_Vulkan_CreateSurface(
+ SDL_Window *window,
+ VkInstance instance,
+ VkSurfaceKHR* surface);
+
+/**
+ * \brief Get the size of a window's underlying drawable in pixels (for use
+ * with setting viewport, scissor & etc).
+ *
+ * \param window SDL_Window from which the drawable size should be queried
+ * \param w Pointer to variable for storing the width in pixels,
+ * may be NULL
+ * \param h Pointer to variable for storing the height in pixels,
+ * may be NULL
+ *
+ * This may differ from SDL_GetWindowSize() if we're rendering to a high-DPI
+ * drawable, i.e. the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a
+ * platform with high-DPI support (Apple calls this "Retina"), and not disabled
+ * by the \c SDL_HINT_VIDEO_HIGHDPI_DISABLED hint.
+ *
+ * \note On macOS high-DPI support must be enabled for an application by
+ * setting NSHighResolutionCapable to true in its Info.plist.
+ *
+ * \sa SDL_GetWindowSize()
+ * \sa SDL_CreateWindow()
+ */
+extern DECLSPEC void SDLCALL SDL_Vulkan_GetDrawableSize(SDL_Window * window,
+ int *w, int *h);
+
+/* @} *//* Vulkan support functions */
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+}
+#endif
+#include "close_code.h"
+
+#endif /* SDL_vulkan_h_ */
diff --git a/src/3rdparty/SDL2/include/begin_code.h b/src/3rdparty/SDL2/include/begin_code.h
new file mode 100644
index 0000000..6c21062
--- /dev/null
+++ b/src/3rdparty/SDL2/include/begin_code.h
@@ -0,0 +1,167 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file begin_code.h
+ *
+ * This file sets things up for C dynamic library function definitions,
+ * static inlined functions, and structures aligned at 4-byte alignment.
+ * If you don't like ugly C preprocessor code, don't look at this file. :)
+ */
+
+/* This shouldn't be nested -- included it around code only. */
+#ifdef _begin_code_h
+#error Nested inclusion of begin_code.h
+#endif
+#define _begin_code_h
+
+#ifndef SDL_DEPRECATED
+# if (__GNUC__ >= 4) /* technically, this arrived in gcc 3.1, but oh well. */
+# define SDL_DEPRECATED __attribute__((deprecated))
+# else
+# define SDL_DEPRECATED
+# endif
+#endif
+
+#ifndef SDL_UNUSED
+# ifdef __GNUC__
+# define SDL_UNUSED __attribute__((unused))
+# else
+# define SDL_UNUSED
+# endif
+#endif
+
+/* Some compilers use a special export keyword */
+#ifndef DECLSPEC
+# if defined(__WIN32__) || defined(__WINRT__)
+# ifdef __BORLANDC__
+# ifdef BUILD_SDL
+# define DECLSPEC
+# else
+# define DECLSPEC __declspec(dllimport)
+# endif
+# else
+# define DECLSPEC __declspec(dllexport)
+# endif
+# elif defined(__OS2__)
+# ifdef BUILD_SDL
+# define DECLSPEC __declspec(dllexport)
+# else
+# define DECLSPEC
+# endif
+# else
+# if defined(__GNUC__) && __GNUC__ >= 4
+# define DECLSPEC __attribute__ ((visibility("default")))
+# else
+# define DECLSPEC
+# endif
+# endif
+#endif
+
+/* By default SDL uses the C calling convention */
+#ifndef SDLCALL
+#if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__)
+#define SDLCALL __cdecl
+#elif defined(__OS2__) || defined(__EMX__)
+#define SDLCALL _System
+# if defined (__GNUC__) && !defined(_System)
+# define _System /* for old EMX/GCC compat. */
+# endif
+#else
+#define SDLCALL
+#endif
+#endif /* SDLCALL */
+
+/* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */
+#ifdef __SYMBIAN32__
+#undef DECLSPEC
+#define DECLSPEC
+#endif /* __SYMBIAN32__ */
+
+/* Force structure packing at 4 byte alignment.
+ This is necessary if the header is included in code which has structure
+ packing set to an alternate value, say for loading structures from disk.
+ The packing is reset to the previous value in close_code.h
+ */
+#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
+#ifdef _MSC_VER
+#pragma warning(disable: 4103)
+#endif
+#ifdef __BORLANDC__
+#pragma nopackwarning
+#endif
+#ifdef _M_X64
+/* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */
+#pragma pack(push,8)
+#else
+#pragma pack(push,4)
+#endif
+#endif /* Compiler needs structure packing set */
+
+#ifndef SDL_INLINE
+#if defined(__GNUC__)
+#define SDL_INLINE __inline__
+#elif defined(_MSC_VER) || defined(__BORLANDC__) || \
+ defined(__DMC__) || defined(__SC__) || \
+ defined(__WATCOMC__) || defined(__LCC__) || \
+ defined(__DECC) || defined(__CC_ARM)
+#define SDL_INLINE __inline
+#ifndef __inline__
+#define __inline__ __inline
+#endif
+#else
+#define SDL_INLINE inline
+#ifndef __inline__
+#define __inline__ inline
+#endif
+#endif
+#endif /* SDL_INLINE not defined */
+
+#ifndef SDL_FORCE_INLINE
+#if defined(_MSC_VER)
+#define SDL_FORCE_INLINE __forceinline
+#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
+#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
+#else
+#define SDL_FORCE_INLINE static SDL_INLINE
+#endif
+#endif /* SDL_FORCE_INLINE not defined */
+
+#ifndef SDL_NORETURN
+#if defined(__GNUC__)
+#define SDL_NORETURN __attribute__((noreturn))
+#elif defined(_MSC_VER)
+#define SDL_NORETURN __declspec(noreturn)
+#else
+#define SDL_NORETURN
+#endif
+#endif /* SDL_NORETURN not defined */
+
+/* Apparently this is needed by several Windows compilers */
+#if !defined(__MACH__)
+#ifndef NULL
+#ifdef __cplusplus
+#define NULL 0
+#else
+#define NULL ((void *)0)
+#endif
+#endif /* NULL */
+#endif /* ! Mac OS X - breaks precompiled headers */
diff --git a/src/3rdparty/SDL2/include/close_code.h b/src/3rdparty/SDL2/include/close_code.h
new file mode 100644
index 0000000..b3b70a4
--- /dev/null
+++ b/src/3rdparty/SDL2/include/close_code.h
@@ -0,0 +1,37 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/**
+ * \file close_code.h
+ *
+ * This file reverses the effects of begin_code.h and should be included
+ * after you finish any function and structure declarations in your headers
+ */
+
+#undef _begin_code_h
+
+/* Reset structure packing at previous byte alignment */
+#if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__)
+#ifdef __BORLANDC__
+#pragma nopackwarning
+#endif
+#pragma pack(pop)
+#endif /* Compiler needs structure packing set */
diff --git a/src/3rdparty/SDL2/src/SDL.c b/src/3rdparty/SDL2/src/SDL.c
new file mode 100644
index 0000000..0e55279
--- /dev/null
+++ b/src/3rdparty/SDL2/src/SDL.c
@@ -0,0 +1,476 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "./SDL_internal.h"
+
+#if defined(__WIN32__)
+#include "core/windows/SDL_windows.h"
+#endif
+
+/* Initialization code for SDL */
+
+#include "SDL.h"
+#include "SDL_bits.h"
+#include "SDL_revision.h"
+#include "SDL_assert_c.h"
+#include "events/SDL_events_c.h"
+#include "haptic/SDL_haptic_c.h"
+#include "joystick/SDL_joystick_c.h"
+
+/* Initialization/Cleanup routines */
+#if !SDL_TIMERS_DISABLED
+# include "timer/SDL_timer_c.h"
+#endif
+#if SDL_VIDEO_DRIVER_WINDOWS
+extern int SDL_HelperWindowCreate(void);
+extern int SDL_HelperWindowDestroy(void);
+#endif
+
+
+/* The initialized subsystems */
+#ifdef SDL_MAIN_NEEDED
+static SDL_bool SDL_MainIsReady = SDL_FALSE;
+#else
+static SDL_bool SDL_MainIsReady = SDL_TRUE;
+#endif
+static SDL_bool SDL_bInMainQuit = SDL_FALSE;
+static Uint8 SDL_SubsystemRefCount[ 32 ];
+
+/* Private helper to increment a subsystem's ref counter. */
+static void
+SDL_PrivateSubsystemRefCountIncr(Uint32 subsystem)
+{
+ int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
+ SDL_assert(SDL_SubsystemRefCount[subsystem_index] < 255);
+ ++SDL_SubsystemRefCount[subsystem_index];
+}
+
+/* Private helper to decrement a subsystem's ref counter. */
+static void
+SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem)
+{
+ int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
+ if (SDL_SubsystemRefCount[subsystem_index] > 0) {
+ --SDL_SubsystemRefCount[subsystem_index];
+ }
+}
+
+/* Private helper to check if a system needs init. */
+static SDL_bool
+SDL_PrivateShouldInitSubsystem(Uint32 subsystem)
+{
+ int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
+ SDL_assert(SDL_SubsystemRefCount[subsystem_index] < 255);
+ return (SDL_SubsystemRefCount[subsystem_index] == 0) ? SDL_TRUE : SDL_FALSE;
+}
+
+/* Private helper to check if a system needs to be quit. */
+static SDL_bool
+SDL_PrivateShouldQuitSubsystem(Uint32 subsystem) {
+ int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
+ if (SDL_SubsystemRefCount[subsystem_index] == 0) {
+ return SDL_FALSE;
+ }
+
+ /* If we're in SDL_Quit, we shut down every subsystem, even if refcount
+ * isn't zero.
+ */
+ return (SDL_SubsystemRefCount[subsystem_index] == 1 || SDL_bInMainQuit) ? SDL_TRUE : SDL_FALSE;
+}
+
+void
+SDL_SetMainReady(void)
+{
+ SDL_MainIsReady = SDL_TRUE;
+}
+
+int
+SDL_InitSubSystem(Uint32 flags)
+{
+ if (!SDL_MainIsReady) {
+ SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
+ return -1;
+ }
+
+ /* Clear the error message */
+ SDL_ClearError();
+
+ if ((flags & SDL_INIT_GAMECONTROLLER)) {
+ /* game controller implies joystick */
+ flags |= SDL_INIT_JOYSTICK;
+ }
+
+ if ((flags & (SDL_INIT_VIDEO|SDL_INIT_JOYSTICK))) {
+ /* video or joystick implies events */
+ flags |= SDL_INIT_EVENTS;
+ }
+
+#if SDL_VIDEO_DRIVER_WINDOWS
+ if ((flags & (SDL_INIT_HAPTIC|SDL_INIT_JOYSTICK))) {
+ if (SDL_HelperWindowCreate() < 0) {
+ return -1;
+ }
+ }
+#endif
+
+#if !SDL_TIMERS_DISABLED
+ SDL_TicksInit();
+#endif
+
+ /* Initialize the event subsystem */
+ if ((flags & SDL_INIT_EVENTS)) {
+#if !SDL_EVENTS_DISABLED
+ if (SDL_PrivateShouldInitSubsystem(SDL_INIT_EVENTS)) {
+ if (SDL_StartEventLoop() < 0) {
+ return (-1);
+ }
+ SDL_QuitInit();
+ }
+ SDL_PrivateSubsystemRefCountIncr(SDL_INIT_EVENTS);
+#else
+ return SDL_SetError("SDL not built with events support");
+#endif
+ }
+
+ /* Initialize the timer subsystem */
+ if ((flags & SDL_INIT_TIMER)){
+#if !SDL_TIMERS_DISABLED
+ if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
+ if (SDL_TimerInit() < 0) {
+ return (-1);
+ }
+ }
+ SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER);
+#else
+ return SDL_SetError("SDL not built with timer support");
+#endif
+ }
+
+ /* Initialize the video subsystem */
+ if ((flags & SDL_INIT_VIDEO)){
+#if !SDL_VIDEO_DISABLED
+ if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
+ if (SDL_VideoInit(NULL) < 0) {
+ return (-1);
+ }
+ }
+ SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO);
+#else
+ return SDL_SetError("SDL not built with video support");
+#endif
+ }
+
+ /* Initialize the audio subsystem */
+ if ((flags & SDL_INIT_AUDIO)){
+#if !SDL_AUDIO_DISABLED
+ if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
+ if (SDL_AudioInit(NULL) < 0) {
+ return (-1);
+ }
+ }
+ SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO);
+#else
+ return SDL_SetError("SDL not built with audio support");
+#endif
+ }
+
+ /* Initialize the joystick subsystem */
+ if ((flags & SDL_INIT_JOYSTICK)){
+#if !SDL_JOYSTICK_DISABLED
+ if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
+ if (SDL_JoystickInit() < 0) {
+ return (-1);
+ }
+ }
+ SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK);
+#else
+ return SDL_SetError("SDL not built with joystick support");
+#endif
+ }
+
+ if ((flags & SDL_INIT_GAMECONTROLLER)){
+#if !SDL_JOYSTICK_DISABLED
+ if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
+ if (SDL_GameControllerInit() < 0) {
+ return (-1);
+ }
+ }
+ SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER);
+#else
+ return SDL_SetError("SDL not built with joystick support");
+#endif
+ }
+
+ /* Initialize the haptic subsystem */
+ if ((flags & SDL_INIT_HAPTIC)){
+#if !SDL_HAPTIC_DISABLED
+ if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
+ if (SDL_HapticInit() < 0) {
+ return (-1);
+ }
+ }
+ SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC);
+#else
+ return SDL_SetError("SDL not built with haptic (force feedback) support");
+#endif
+ }
+
+ return (0);
+}
+
+int
+SDL_Init(Uint32 flags)
+{
+ return SDL_InitSubSystem(flags);
+}
+
+void
+SDL_QuitSubSystem(Uint32 flags)
+{
+ /* Shut down requested initialized subsystems */
+#if !SDL_JOYSTICK_DISABLED
+ if ((flags & SDL_INIT_GAMECONTROLLER)) {
+ /* game controller implies joystick */
+ flags |= SDL_INIT_JOYSTICK;
+
+ if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_GAMECONTROLLER)) {
+ SDL_GameControllerQuit();
+ }
+ SDL_PrivateSubsystemRefCountDecr(SDL_INIT_GAMECONTROLLER);
+ }
+
+ if ((flags & SDL_INIT_JOYSTICK)) {
+ /* joystick implies events */
+ flags |= SDL_INIT_EVENTS;
+
+ if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_JOYSTICK)) {
+ SDL_JoystickQuit();
+ }
+ SDL_PrivateSubsystemRefCountDecr(SDL_INIT_JOYSTICK);
+ }
+#endif
+
+#if !SDL_HAPTIC_DISABLED
+ if ((flags & SDL_INIT_HAPTIC)) {
+ if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_HAPTIC)) {
+ SDL_HapticQuit();
+ }
+ SDL_PrivateSubsystemRefCountDecr(SDL_INIT_HAPTIC);
+ }
+#endif
+
+#if !SDL_AUDIO_DISABLED
+ if ((flags & SDL_INIT_AUDIO)) {
+ if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_AUDIO)) {
+ SDL_AudioQuit();
+ }
+ SDL_PrivateSubsystemRefCountDecr(SDL_INIT_AUDIO);
+ }
+#endif
+
+#if !SDL_VIDEO_DISABLED
+ if ((flags & SDL_INIT_VIDEO)) {
+ /* video implies events */
+ flags |= SDL_INIT_EVENTS;
+
+ if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_VIDEO)) {
+ SDL_VideoQuit();
+ }
+ SDL_PrivateSubsystemRefCountDecr(SDL_INIT_VIDEO);
+ }
+#endif
+
+#if !SDL_TIMERS_DISABLED
+ if ((flags & SDL_INIT_TIMER)) {
+ if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_TIMER)) {
+ SDL_TimerQuit();
+ }
+ SDL_PrivateSubsystemRefCountDecr(SDL_INIT_TIMER);
+ }
+#endif
+
+#if !SDL_EVENTS_DISABLED
+ if ((flags & SDL_INIT_EVENTS)) {
+ if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_EVENTS)) {
+ SDL_QuitQuit();
+ SDL_StopEventLoop();
+ }
+ SDL_PrivateSubsystemRefCountDecr(SDL_INIT_EVENTS);
+ }
+#endif
+}
+
+Uint32
+SDL_WasInit(Uint32 flags)
+{
+ int i;
+ int num_subsystems = SDL_arraysize(SDL_SubsystemRefCount);
+ Uint32 initialized = 0;
+
+ if (!flags) {
+ flags = SDL_INIT_EVERYTHING;
+ }
+
+ num_subsystems = SDL_min(num_subsystems, SDL_MostSignificantBitIndex32(flags) + 1);
+
+ /* Iterate over each bit in flags, and check the matching subsystem. */
+ for (i = 0; i < num_subsystems; ++i) {
+ if ((flags & 1) && SDL_SubsystemRefCount[i] > 0) {
+ initialized |= (1 << i);
+ }
+
+ flags >>= 1;
+ }
+
+ return initialized;
+}
+
+void
+SDL_Quit(void)
+{
+ SDL_bInMainQuit = SDL_TRUE;
+
+ /* Quit all subsystems */
+#if SDL_VIDEO_DRIVER_WINDOWS
+ SDL_HelperWindowDestroy();
+#endif
+ SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
+
+#if !SDL_TIMERS_DISABLED
+ SDL_TicksQuit();
+#endif
+
+ SDL_ClearHints();
+ SDL_AssertionsQuit();
+ SDL_LogResetPriorities();
+
+ /* Now that every subsystem has been quit, we reset the subsystem refcount
+ * and the list of initialized subsystems.
+ */
+ SDL_memset( SDL_SubsystemRefCount, 0x0, sizeof(SDL_SubsystemRefCount) );
+
+ SDL_bInMainQuit = SDL_FALSE;
+}
+
+/* Get the library version number */
+void
+SDL_GetVersion(SDL_version * ver)
+{
+ SDL_VERSION(ver);
+}
+
+/* Get the library source revision */
+const char *
+SDL_GetRevision(void)
+{
+ return SDL_REVISION;
+}
+
+/* Get the library source revision number */
+int
+SDL_GetRevisionNumber(void)
+{
+ return SDL_REVISION_NUMBER;
+}
+
+/* Get the name of the platform */
+const char *
+SDL_GetPlatform()
+{
+#if __AIX__
+ return "AIX";
+#elif __ANDROID__
+ return "Android";
+#elif __BSDI__
+ return "BSDI";
+#elif __DREAMCAST__
+ return "Dreamcast";
+#elif __EMSCRIPTEN__
+ return "Emscripten";
+#elif __FREEBSD__
+ return "FreeBSD";
+#elif __HAIKU__
+ return "Haiku";
+#elif __HPUX__
+ return "HP-UX";
+#elif __IRIX__
+ return "Irix";
+#elif __LINUX__
+ return "Linux";
+#elif __MINT__
+ return "Atari MiNT";
+#elif __MACOS__
+ return "MacOS Classic";
+#elif __MACOSX__
+ return "Mac OS X";
+#elif __NACL__
+ return "NaCl";
+#elif __NETBSD__
+ return "NetBSD";
+#elif __OPENBSD__
+ return "OpenBSD";
+#elif __OS2__
+ return "OS/2";
+#elif __OSF__
+ return "OSF/1";
+#elif __QNXNTO__
+ return "QNX Neutrino";
+#elif __RISCOS__
+ return "RISC OS";
+#elif __SOLARIS__
+ return "Solaris";
+#elif __WIN32__
+ return "Windows";
+#elif __WINRT__
+ return "WinRT";
+#elif __TVOS__
+ return "tvOS";
+#elif __IPHONEOS__
+ return "iOS";
+#elif __PSP__
+ return "PlayStation Portable";
+#else
+ return "Unknown (see SDL_platform.h)";
+#endif
+}
+
+#if defined(__WIN32__)
+
+#if (!defined(HAVE_LIBC) || defined(__WATCOMC__)) && !defined(SDL_STATIC_LIB)
+/* Need to include DllMain() on Watcom C for some reason.. */
+
+BOOL APIENTRY
+_DllMainCRTStartup(HANDLE hModule,
+ DWORD ul_reason_for_call, LPVOID lpReserved)
+{
+ switch (ul_reason_for_call) {
+ case DLL_PROCESS_ATTACH:
+ case DLL_THREAD_ATTACH:
+ case DLL_THREAD_DETACH:
+ case DLL_PROCESS_DETACH:
+ break;
+ }
+ return TRUE;
+}
+#endif /* Building DLL */
+
+#endif /* __WIN32__ */
+
+/* vi: set sts=4 ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/SDL_assert.c b/src/3rdparty/SDL2/src/SDL_assert.c
new file mode 100644
index 0000000..76f5d60
--- /dev/null
+++ b/src/3rdparty/SDL2/src/SDL_assert.c
@@ -0,0 +1,441 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "./SDL_internal.h"
+
+#if defined(__WIN32__)
+#include "core/windows/SDL_windows.h"
+#endif
+
+#include "SDL.h"
+#include "SDL_atomic.h"
+#include "SDL_messagebox.h"
+#include "SDL_video.h"
+#include "SDL_assert.h"
+#include "SDL_assert_c.h"
+#include "video/SDL_sysvideo.h"
+
+#ifdef __WIN32__
+#ifndef WS_OVERLAPPEDWINDOW
+#define WS_OVERLAPPEDWINDOW 0
+#endif
+#else /* fprintf, _exit(), etc. */
+#include <stdio.h>
+#include <stdlib.h>
+#if ! defined(__WINRT__)
+#include <unistd.h>
+#endif
+#endif
+
+#if defined(__EMSCRIPTEN__)
+#include <emscripten.h>
+#endif
+
+
+static SDL_assert_state SDLCALL
+SDL_PromptAssertion(const SDL_assert_data *data, void *userdata);
+
+/*
+ * We keep all triggered assertions in a singly-linked list so we can
+ * generate a report later.
+ */
+static SDL_assert_data *triggered_assertions = NULL;
+
+#ifndef SDL_THREADS_DISABLED
+static SDL_mutex *assertion_mutex = NULL;
+#endif
+
+static SDL_AssertionHandler assertion_handler = SDL_PromptAssertion;
+static void *assertion_userdata = NULL;
+
+#ifdef __GNUC__
+static void
+debug_print(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
+#endif
+
+static void
+debug_print(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ SDL_LogMessageV(SDL_LOG_CATEGORY_ASSERT, SDL_LOG_PRIORITY_WARN, fmt, ap);
+ va_end(ap);
+}
+
+
+static void SDL_AddAssertionToReport(SDL_assert_data *data)
+{
+ /* (data) is always a static struct defined with the assert macros, so
+ we don't have to worry about copying or allocating them. */
+ data->trigger_count++;
+ if (data->trigger_count == 1) { /* not yet added? */
+ data->next = triggered_assertions;
+ triggered_assertions = data;
+ }
+}
+
+
+static void SDL_GenerateAssertionReport(void)
+{
+ const SDL_assert_data *item = triggered_assertions;
+
+ /* only do this if the app hasn't assigned an assertion handler. */
+ if ((item != NULL) && (assertion_handler != SDL_PromptAssertion)) {
+ debug_print("\n\nSDL assertion report.\n");
+ debug_print("All SDL assertions between last init/quit:\n\n");
+
+ while (item != NULL) {
+ debug_print(
+ "'%s'\n"
+ " * %s (%s:%d)\n"
+ " * triggered %u time%s.\n"
+ " * always ignore: %s.\n",
+ item->condition, item->function, item->filename,
+ item->linenum, item->trigger_count,
+ (item->trigger_count == 1) ? "" : "s",
+ item->always_ignore ? "yes" : "no");
+ item = item->next;
+ }
+ debug_print("\n");
+
+ SDL_ResetAssertionReport();
+ }
+}
+
+
+static SDL_NORETURN void SDL_ExitProcess(int exitcode)
+{
+#ifdef __WIN32__
+ ExitProcess(exitcode);
+#elif defined(__EMSCRIPTEN__)
+ emscripten_cancel_main_loop(); /* this should "kill" the app. */
+ emscripten_force_exit(exitcode); /* this should "kill" the app. */
+ exit(exitcode);
+#else
+ _exit(exitcode);
+#endif
+}
+
+
+static SDL_NORETURN void SDL_AbortAssertion(void)
+{
+ SDL_Quit();
+ SDL_ExitProcess(42);
+}
+
+
+static SDL_assert_state SDLCALL
+SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
+{
+#ifdef __WIN32__
+ #define ENDLINE "\r\n"
+#else
+ #define ENDLINE "\n"
+#endif
+
+ const char *envr;
+ SDL_assert_state state = SDL_ASSERTION_ABORT;
+ SDL_Window *window;
+ SDL_MessageBoxData messagebox;
+ SDL_MessageBoxButtonData buttons[] = {
+ { 0, SDL_ASSERTION_RETRY, "Retry" },
+ { 0, SDL_ASSERTION_BREAK, "Break" },
+ { 0, SDL_ASSERTION_ABORT, "Abort" },
+ { SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT,
+ SDL_ASSERTION_IGNORE, "Ignore" },
+ { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT,
+ SDL_ASSERTION_ALWAYS_IGNORE, "Always Ignore" }
+ };
+ char *message;
+ int selected;
+
+ (void) userdata; /* unused in default handler. */
+
+ message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
+ if (!message) {
+ /* Uh oh, we're in real trouble now... */
+ return SDL_ASSERTION_ABORT;
+ }
+ SDL_snprintf(message, SDL_MAX_LOG_MESSAGE,
+ "Assertion failure at %s (%s:%d), triggered %u %s:" ENDLINE
+ " '%s'",
+ data->function, data->filename, data->linenum,
+ data->trigger_count, (data->trigger_count == 1) ? "time" : "times",
+ data->condition);
+
+ debug_print("\n\n%s\n\n", message);
+
+ /* let env. variable override, so unit tests won't block in a GUI. */
+ envr = SDL_getenv("SDL_ASSERT");
+ if (envr != NULL) {
+ SDL_stack_free(message);
+
+ if (SDL_strcmp(envr, "abort") == 0) {
+ return SDL_ASSERTION_ABORT;
+ } else if (SDL_strcmp(envr, "break") == 0) {
+ return SDL_ASSERTION_BREAK;
+ } else if (SDL_strcmp(envr, "retry") == 0) {
+ return SDL_ASSERTION_RETRY;
+ } else if (SDL_strcmp(envr, "ignore") == 0) {
+ return SDL_ASSERTION_IGNORE;
+ } else if (SDL_strcmp(envr, "always_ignore") == 0) {
+ return SDL_ASSERTION_ALWAYS_IGNORE;
+ } else {
+ return SDL_ASSERTION_ABORT; /* oh well. */
+ }
+ }
+
+ /* Leave fullscreen mode, if possible (scary!) */
+ window = SDL_GetFocusWindow();
+ if (window) {
+ if (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) {
+ SDL_MinimizeWindow(window);
+ } else {
+ /* !!! FIXME: ungrab the input if we're not fullscreen? */
+ /* No need to mess with the window */
+ window = NULL;
+ }
+ }
+
+ /* Show a messagebox if we can, otherwise fall back to stdio */
+ SDL_zero(messagebox);
+ messagebox.flags = SDL_MESSAGEBOX_WARNING;
+ messagebox.window = window;
+ messagebox.title = "Assertion Failed";
+ messagebox.message = message;
+ messagebox.numbuttons = SDL_arraysize(buttons);
+ messagebox.buttons = buttons;
+
+ if (SDL_ShowMessageBox(&messagebox, &selected) == 0) {
+ if (selected == -1) {
+ state = SDL_ASSERTION_IGNORE;
+ } else {
+ state = (SDL_assert_state)selected;
+ }
+ }
+
+ else
+ {
+#if defined(__EMSCRIPTEN__)
+ /* This is nasty, but we can't block on a custom UI. */
+ for ( ; ; ) {
+ SDL_bool okay = SDL_TRUE;
+ char *buf = (char *) EM_ASM_INT({
+ var str =
+ Pointer_stringify($0) + '\n\n' +
+ 'Abort/Retry/Ignore/AlwaysIgnore? [ariA] :';
+ var reply = window.prompt(str, "i");
+ if (reply === null) {
+ reply = "i";
+ }
+ return allocate(intArrayFromString(reply), 'i8', ALLOC_NORMAL);
+ }, message);
+
+ if (SDL_strcmp(buf, "a") == 0) {
+ state = SDL_ASSERTION_ABORT;
+ /* (currently) no break functionality on Emscripten
+ } else if (SDL_strcmp(buf, "b") == 0) {
+ state = SDL_ASSERTION_BREAK; */
+ } else if (SDL_strcmp(buf, "r") == 0) {
+ state = SDL_ASSERTION_RETRY;
+ } else if (SDL_strcmp(buf, "i") == 0) {
+ state = SDL_ASSERTION_IGNORE;
+ } else if (SDL_strcmp(buf, "A") == 0) {
+ state = SDL_ASSERTION_ALWAYS_IGNORE;
+ } else {
+ okay = SDL_FALSE;
+ }
+ free(buf);
+
+ if (okay) {
+ break;
+ }
+ }
+#elif defined(HAVE_STDIO_H)
+ /* this is a little hacky. */
+ for ( ; ; ) {
+ char buf[32];
+ fprintf(stderr, "Abort/Break/Retry/Ignore/AlwaysIgnore? [abriA] : ");
+ fflush(stderr);
+ if (fgets(buf, sizeof (buf), stdin) == NULL) {
+ break;
+ }
+
+ if (SDL_strncmp(buf, "a", 1) == 0) {
+ state = SDL_ASSERTION_ABORT;
+ break;
+ } else if (SDL_strncmp(buf, "b", 1) == 0) {
+ state = SDL_ASSERTION_BREAK;
+ break;
+ } else if (SDL_strncmp(buf, "r", 1) == 0) {
+ state = SDL_ASSERTION_RETRY;
+ break;
+ } else if (SDL_strncmp(buf, "i", 1) == 0) {
+ state = SDL_ASSERTION_IGNORE;
+ break;
+ } else if (SDL_strncmp(buf, "A", 1) == 0) {
+ state = SDL_ASSERTION_ALWAYS_IGNORE;
+ break;
+ }
+ }
+#endif /* HAVE_STDIO_H */
+ }
+
+ /* Re-enter fullscreen mode */
+ if (window) {
+ SDL_RestoreWindow(window);
+ }
+
+ SDL_stack_free(message);
+
+ return state;
+}
+
+
+SDL_assert_state
+SDL_ReportAssertion(SDL_assert_data *data, const char *func, const char *file,
+ int line)
+{
+ SDL_assert_state state = SDL_ASSERTION_IGNORE;
+ static int assertion_running = 0;
+
+#ifndef SDL_THREADS_DISABLED
+ static SDL_SpinLock spinlock = 0;
+ SDL_AtomicLock(&spinlock);
+ if (assertion_mutex == NULL) { /* never called SDL_Init()? */
+ assertion_mutex = SDL_CreateMutex();
+ if (assertion_mutex == NULL) {
+ SDL_AtomicUnlock(&spinlock);
+ return SDL_ASSERTION_IGNORE; /* oh well, I guess. */
+ }
+ }
+ SDL_AtomicUnlock(&spinlock);
+
+ if (SDL_LockMutex(assertion_mutex) < 0) {
+ return SDL_ASSERTION_IGNORE; /* oh well, I guess. */
+ }
+#endif
+
+ /* doing this because Visual C is upset over assigning in the macro. */
+ if (data->trigger_count == 0) {
+ data->function = func;
+ data->filename = file;
+ data->linenum = line;
+ }
+
+ SDL_AddAssertionToReport(data);
+
+ assertion_running++;
+ if (assertion_running > 1) { /* assert during assert! Abort. */
+ if (assertion_running == 2) {
+ SDL_AbortAssertion();
+ } else if (assertion_running == 3) { /* Abort asserted! */
+ SDL_ExitProcess(42);
+ } else {
+ while (1) { /* do nothing but spin; what else can you do?! */ }
+ }
+ }
+
+ if (!data->always_ignore) {
+ state = assertion_handler(data, assertion_userdata);
+ }
+
+ switch (state)
+ {
+ case SDL_ASSERTION_ABORT:
+ SDL_AbortAssertion();
+ return SDL_ASSERTION_IGNORE; /* shouldn't return, but oh well. */
+
+ case SDL_ASSERTION_ALWAYS_IGNORE:
+ state = SDL_ASSERTION_IGNORE;
+ data->always_ignore = 1;
+ break;
+
+ case SDL_ASSERTION_IGNORE:
+ case SDL_ASSERTION_RETRY:
+ case SDL_ASSERTION_BREAK:
+ break; /* macro handles these. */
+ }
+
+ assertion_running--;
+
+#ifndef SDL_THREADS_DISABLED
+ SDL_UnlockMutex(assertion_mutex);
+#endif
+
+ return state;
+}
+
+
+void SDL_AssertionsQuit(void)
+{
+ SDL_GenerateAssertionReport();
+#ifndef SDL_THREADS_DISABLED
+ if (assertion_mutex != NULL) {
+ SDL_DestroyMutex(assertion_mutex);
+ assertion_mutex = NULL;
+ }
+#endif
+}
+
+void SDL_SetAssertionHandler(SDL_AssertionHandler handler, void *userdata)
+{
+ if (handler != NULL) {
+ assertion_handler = handler;
+ assertion_userdata = userdata;
+ } else {
+ assertion_handler = SDL_PromptAssertion;
+ assertion_userdata = NULL;
+ }
+}
+
+const SDL_assert_data *SDL_GetAssertionReport(void)
+{
+ return triggered_assertions;
+}
+
+void SDL_ResetAssertionReport(void)
+{
+ SDL_assert_data *next = NULL;
+ SDL_assert_data *item;
+ for (item = triggered_assertions; item != NULL; item = next) {
+ next = (SDL_assert_data *) item->next;
+ item->always_ignore = SDL_FALSE;
+ item->trigger_count = 0;
+ item->next = NULL;
+ }
+
+ triggered_assertions = NULL;
+}
+
+SDL_AssertionHandler SDL_GetDefaultAssertionHandler(void)
+{
+ return SDL_PromptAssertion;
+}
+
+SDL_AssertionHandler SDL_GetAssertionHandler(void **userdata)
+{
+ if (userdata != NULL) {
+ *userdata = assertion_userdata;
+ }
+ return assertion_handler;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/SDL_assert_c.h b/src/3rdparty/SDL2/src/SDL_assert_c.h
new file mode 100644
index 0000000..aa690a3
--- /dev/null
+++ b/src/3rdparty/SDL2/src/SDL_assert_c.h
@@ -0,0 +1,24 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+extern void SDL_AssertionsQuit(void);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/SDL_dataqueue.c b/src/3rdparty/SDL2/src/SDL_dataqueue.c
new file mode 100644
index 0000000..97916f4
--- /dev/null
+++ b/src/3rdparty/SDL2/src/SDL_dataqueue.c
@@ -0,0 +1,339 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "./SDL_internal.h"
+#include "SDL.h"
+#include "./SDL_dataqueue.h"
+#include "SDL_assert.h"
+
+typedef struct SDL_DataQueuePacket
+{
+ size_t datalen; /* bytes currently in use in this packet. */
+ size_t startpos; /* bytes currently consumed in this packet. */
+ struct SDL_DataQueuePacket *next; /* next item in linked list. */
+ Uint8 data[SDL_VARIABLE_LENGTH_ARRAY]; /* packet data */
+} SDL_DataQueuePacket;
+
+struct SDL_DataQueue
+{
+ SDL_DataQueuePacket *head; /* device fed from here. */
+ SDL_DataQueuePacket *tail; /* queue fills to here. */
+ SDL_DataQueuePacket *pool; /* these are unused packets. */
+ size_t packet_size; /* size of new packets */
+ size_t queued_bytes; /* number of bytes of data in the queue. */
+};
+
+static void
+SDL_FreeDataQueueList(SDL_DataQueuePacket *packet)
+{
+ while (packet) {
+ SDL_DataQueuePacket *next = packet->next;
+ SDL_free(packet);
+ packet = next;
+ }
+}
+
+
+/* this all expects that you managed thread safety elsewhere. */
+
+SDL_DataQueue *
+SDL_NewDataQueue(const size_t _packetlen, const size_t initialslack)
+{
+ SDL_DataQueue *queue = (SDL_DataQueue *) SDL_malloc(sizeof (SDL_DataQueue));
+
+ if (!queue) {
+ SDL_OutOfMemory();
+ return NULL;
+ } else {
+ const size_t packetlen = _packetlen ? _packetlen : 1024;
+ const size_t wantpackets = (initialslack + (packetlen - 1)) / packetlen;
+ size_t i;
+
+ SDL_zerop(queue);
+ queue->packet_size = packetlen;
+
+ for (i = 0; i < wantpackets; i++) {
+ SDL_DataQueuePacket *packet = (SDL_DataQueuePacket *) SDL_malloc(sizeof (SDL_DataQueuePacket) + packetlen);
+ if (packet) { /* don't care if this fails, we'll deal later. */
+ packet->datalen = 0;
+ packet->startpos = 0;
+ packet->next = queue->pool;
+ queue->pool = packet;
+ }
+ }
+ }
+
+ return queue;
+}
+
+void
+SDL_FreeDataQueue(SDL_DataQueue *queue)
+{
+ if (queue) {
+ SDL_FreeDataQueueList(queue->head);
+ SDL_FreeDataQueueList(queue->pool);
+ SDL_free(queue);
+ }
+}
+
+void
+SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack)
+{
+ const size_t packet_size = queue ? queue->packet_size : 1;
+ const size_t slackpackets = (slack + (packet_size-1)) / packet_size;
+ SDL_DataQueuePacket *packet;
+ SDL_DataQueuePacket *prev = NULL;
+ size_t i;
+
+ if (!queue) {
+ return;
+ }
+
+ packet = queue->head;
+
+ /* merge the available pool and the current queue into one list. */
+ if (packet) {
+ queue->tail->next = queue->pool;
+ } else {
+ packet = queue->pool;
+ }
+
+ /* Remove the queued packets from the device. */
+ queue->tail = NULL;
+ queue->head = NULL;
+ queue->queued_bytes = 0;
+ queue->pool = packet;
+
+ /* Optionally keep some slack in the pool to reduce malloc pressure. */
+ for (i = 0; packet && (i < slackpackets); i++) {
+ prev = packet;
+ packet = packet->next;
+ }
+
+ if (prev) {
+ prev->next = NULL;
+ } else {
+ queue->pool = NULL;
+ }
+
+ SDL_FreeDataQueueList(packet); /* free extra packets */
+}
+
+static SDL_DataQueuePacket *
+AllocateDataQueuePacket(SDL_DataQueue *queue)
+{
+ SDL_DataQueuePacket *packet;
+
+ SDL_assert(queue != NULL);
+
+ packet = queue->pool;
+ if (packet != NULL) {
+ /* we have one available in the pool. */
+ queue->pool = packet->next;
+ } else {
+ /* Have to allocate a new one! */
+ packet = (SDL_DataQueuePacket *) SDL_malloc(sizeof (SDL_DataQueuePacket) + queue->packet_size);
+ if (packet == NULL) {
+ return NULL;
+ }
+ }
+
+ packet->datalen = 0;
+ packet->startpos = 0;
+ packet->next = NULL;
+
+ SDL_assert((queue->head != NULL) == (queue->queued_bytes != 0));
+ if (queue->tail == NULL) {
+ queue->head = packet;
+ } else {
+ queue->tail->next = packet;
+ }
+ queue->tail = packet;
+ return packet;
+}
+
+
+int
+SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *_data, const size_t _len)
+{
+ size_t len = _len;
+ const Uint8 *data = (const Uint8 *) _data;
+ const size_t packet_size = queue ? queue->packet_size : 0;
+ SDL_DataQueuePacket *orighead;
+ SDL_DataQueuePacket *origtail;
+ size_t origlen;
+ size_t datalen;
+
+ if (!queue) {
+ return SDL_InvalidParamError("queue");
+ }
+
+ orighead = queue->head;
+ origtail = queue->tail;
+ origlen = origtail ? origtail->datalen : 0;
+
+ while (len > 0) {
+ SDL_DataQueuePacket *packet = queue->tail;
+ SDL_assert(!packet || (packet->datalen <= packet_size));
+ if (!packet || (packet->datalen >= packet_size)) {
+ /* tail packet missing or completely full; we need a new packet. */
+ packet = AllocateDataQueuePacket(queue);
+ if (!packet) {
+ /* uhoh, reset so we've queued nothing new, free what we can. */
+ if (!origtail) {
+ packet = queue->head; /* whole queue. */
+ } else {
+ packet = origtail->next; /* what we added to existing queue. */
+ origtail->next = NULL;
+ origtail->datalen = origlen;
+ }
+ queue->head = orighead;
+ queue->tail = origtail;
+ queue->pool = NULL;
+
+ SDL_FreeDataQueueList(packet); /* give back what we can. */
+ return SDL_OutOfMemory();
+ }
+ }
+
+ datalen = SDL_min(len, packet_size - packet->datalen);
+ SDL_memcpy(packet->data + packet->datalen, data, datalen);
+ data += datalen;
+ len -= datalen;
+ packet->datalen += datalen;
+ queue->queued_bytes += datalen;
+ }
+
+ return 0;
+}
+
+size_t
+SDL_PeekIntoDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
+{
+ size_t len = _len;
+ Uint8 *buf = (Uint8 *) _buf;
+ Uint8 *ptr = buf;
+ SDL_DataQueuePacket *packet;
+
+ if (!queue) {
+ return 0;
+ }
+
+ for (packet = queue->head; len && packet; packet = packet->next) {
+ const size_t avail = packet->datalen - packet->startpos;
+ const size_t cpy = SDL_min(len, avail);
+ SDL_assert(queue->queued_bytes >= avail);
+
+ SDL_memcpy(ptr, packet->data + packet->startpos, cpy);
+ ptr += cpy;
+ len -= cpy;
+ }
+
+ return (size_t) (ptr - buf);
+}
+
+size_t
+SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
+{
+ size_t len = _len;
+ Uint8 *buf = (Uint8 *) _buf;
+ Uint8 *ptr = buf;
+ SDL_DataQueuePacket *packet;
+
+ if (!queue) {
+ return 0;
+ }
+
+ while ((len > 0) && ((packet = queue->head) != NULL)) {
+ const size_t avail = packet->datalen - packet->startpos;
+ const size_t cpy = SDL_min(len, avail);
+ SDL_assert(queue->queued_bytes >= avail);
+
+ SDL_memcpy(ptr, packet->data + packet->startpos, cpy);
+ packet->startpos += cpy;
+ ptr += cpy;
+ queue->queued_bytes -= cpy;
+ len -= cpy;
+
+ if (packet->startpos == packet->datalen) { /* packet is done, put it in the pool. */
+ queue->head = packet->next;
+ SDL_assert((packet->next != NULL) || (packet == queue->tail));
+ packet->next = queue->pool;
+ queue->pool = packet;
+ }
+ }
+
+ SDL_assert((queue->head != NULL) == (queue->queued_bytes != 0));
+
+ if (queue->head == NULL) {
+ queue->tail = NULL; /* in case we drained the queue entirely. */
+ }
+
+ return (size_t) (ptr - buf);
+}
+
+size_t
+SDL_CountDataQueue(SDL_DataQueue *queue)
+{
+ return queue ? queue->queued_bytes : 0;
+}
+
+void *
+SDL_ReserveSpaceInDataQueue(SDL_DataQueue *queue, const size_t len)
+{
+ SDL_DataQueuePacket *packet;
+
+ if (!queue) {
+ SDL_InvalidParamError("queue");
+ return NULL;
+ } else if (len == 0) {
+ SDL_InvalidParamError("len");
+ return NULL;
+ } else if (len > queue->packet_size) {
+ SDL_SetError("len is larger than packet size");
+ return NULL;
+ }
+
+ packet = queue->head;
+ if (packet) {
+ const size_t avail = queue->packet_size - packet->datalen;
+ if (len <= avail) { /* we can use the space at end of this packet. */
+ void *retval = packet->data + packet->datalen;
+ packet->datalen += len;
+ queue->queued_bytes += len;
+ return retval;
+ }
+ }
+
+ /* Need a fresh packet. */
+ packet = AllocateDataQueuePacket(queue);
+ if (!packet) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ packet->datalen = len;
+ queue->queued_bytes += len;
+ return packet->data;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/SDL_dataqueue.h b/src/3rdparty/SDL2/src/SDL_dataqueue.h
new file mode 100644
index 0000000..d44f58d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/SDL_dataqueue.h
@@ -0,0 +1,55 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#ifndef SDL_dataqueue_h_
+#define SDL_dataqueue_h_
+
+/* this is not (currently) a public API. But maybe it should be! */
+
+struct SDL_DataQueue;
+typedef struct SDL_DataQueue SDL_DataQueue;
+
+SDL_DataQueue *SDL_NewDataQueue(const size_t packetlen, const size_t initialslack);
+void SDL_FreeDataQueue(SDL_DataQueue *queue);
+void SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack);
+int SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *data, const size_t len);
+size_t SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *buf, const size_t len);
+size_t SDL_PeekIntoDataQueue(SDL_DataQueue *queue, void *buf, const size_t len);
+size_t SDL_CountDataQueue(SDL_DataQueue *queue);
+
+/* this sets a section of the data queue aside (possibly allocating memory for it)
+ as if it's been written to, but returns a pointer to that space. You may write
+ to this space until a read would consume it. Writes (and other calls to this
+ function) will safely append their data after this reserved space and can
+ be in flight at the same time. There is no thread safety.
+ If there isn't an existing block of memory that can contain the reserved
+ space, one will be allocated for it. You can not (currently) allocate
+ a space larger than the packetlen requested in SDL_NewDataQueue.
+ Returned buffer is uninitialized.
+ This lets you avoid an extra copy in some cases, but it's safer to use
+ SDL_WriteToDataQueue() unless you know what you're doing.
+ Returns pointer to buffer of at least (len) bytes, NULL on error.
+*/
+void *SDL_ReserveSpaceInDataQueue(SDL_DataQueue *queue, const size_t len);
+
+#endif /* SDL_dataqueue_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/SDL_error.c b/src/3rdparty/SDL2/src/SDL_error.c
new file mode 100644
index 0000000..14761c5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/SDL_error.c
@@ -0,0 +1,319 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "./SDL_internal.h"
+
+/* Simple error handling in SDL */
+
+#include "SDL_log.h"
+#include "SDL_error.h"
+#include "SDL_error_c.h"
+
+
+/* Routine to get the thread-specific error variable */
+#if SDL_THREADS_DISABLED
+/* The default (non-thread-safe) global error variable */
+static SDL_error SDL_global_error;
+#define SDL_GetErrBuf() (&SDL_global_error)
+#else
+extern SDL_error *SDL_GetErrBuf(void);
+#endif /* SDL_THREADS_DISABLED */
+
+#define SDL_ERRBUFIZE 1024
+
+/* Private functions */
+
+static const char *
+SDL_LookupString(const char *key)
+{
+ /* FIXME: Add code to lookup key in language string hash-table */
+ return key;
+}
+
+/* Public functions */
+
+static char *SDL_GetErrorMsg(char *errstr, int maxlen);
+
+int
+SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+ va_list ap;
+ SDL_error *error;
+
+ /* Ignore call if invalid format pointer was passed */
+ if (fmt == NULL) return -1;
+
+ /* Copy in the key, mark error as valid */
+ error = SDL_GetErrBuf();
+ error->error = 1;
+ SDL_strlcpy((char *) error->key, fmt, sizeof(error->key));
+
+ va_start(ap, fmt);
+ error->argc = 0;
+ while (*fmt) {
+ if (*fmt++ == '%') {
+ while (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) {
+ ++fmt;
+ }
+ switch (*fmt++) {
+ case 0: /* Malformed format string.. */
+ --fmt;
+ break;
+ case 'l':
+ switch (*fmt++) {
+ case 0: /* Malformed format string.. */
+ --fmt;
+ break;
+ case 'i': case 'd': case 'u':
+ error->args[error->argc++].value_l = va_arg(ap, long);
+ break;
+ }
+ break;
+ case 'c':
+ case 'i':
+ case 'd':
+ case 'u':
+ case 'o':
+ case 'x':
+ case 'X':
+ error->args[error->argc++].value_i = va_arg(ap, int);
+ break;
+ case 'f':
+ error->args[error->argc++].value_f = va_arg(ap, double);
+ break;
+ case 'p':
+ error->args[error->argc++].value_ptr = va_arg(ap, void *);
+ break;
+ case 's':
+ {
+ int i = error->argc;
+ const char *str = va_arg(ap, const char *);
+ if (str == NULL)
+ str = "(null)";
+ SDL_strlcpy((char *) error->args[i].buf, str,
+ ERR_MAX_STRLEN);
+ error->argc++;
+ }
+ break;
+ default:
+ break;
+ }
+ if (error->argc >= ERR_MAX_ARGS) {
+ break;
+ }
+ }
+ }
+ va_end(ap);
+
+ if (SDL_LogGetPriority(SDL_LOG_CATEGORY_ERROR) <= SDL_LOG_PRIORITY_DEBUG) {
+ /* If we are in debug mode, print out an error message
+ * Avoid stomping on the static buffer in GetError, just
+ * in case this is called while processing a ShowMessageBox to
+ * show an error already in that static buffer.
+ */
+ char errmsg[SDL_ERRBUFIZE];
+ SDL_GetErrorMsg(errmsg, sizeof(errmsg));
+ SDL_LogDebug(SDL_LOG_CATEGORY_ERROR, "%s", errmsg);
+ }
+ return -1;
+}
+
+/* Available for backwards compatibility */
+const char *
+SDL_GetError(void)
+{
+ static char errmsg[SDL_ERRBUFIZE];
+
+ return SDL_GetErrorMsg(errmsg, SDL_ERRBUFIZE);
+}
+
+void
+SDL_ClearError(void)
+{
+ SDL_error *error;
+
+ error = SDL_GetErrBuf();
+ error->error = 0;
+}
+
+/* Very common errors go here */
+int
+SDL_Error(SDL_errorcode code)
+{
+ switch (code) {
+ case SDL_ENOMEM:
+ return SDL_SetError("Out of memory");
+ case SDL_EFREAD:
+ return SDL_SetError("Error reading from datastream");
+ case SDL_EFWRITE:
+ return SDL_SetError("Error writing to datastream");
+ case SDL_EFSEEK:
+ return SDL_SetError("Error seeking in datastream");
+ case SDL_UNSUPPORTED:
+ return SDL_SetError("That operation is not supported");
+ default:
+ return SDL_SetError("Unknown SDL error");
+ }
+}
+
+#ifdef TEST_ERROR
+int
+main(int argc, char *argv[])
+{
+ char buffer[BUFSIZ + 1];
+
+ SDL_SetError("Hi there!");
+ printf("Error 1: %s\n", SDL_GetError());
+ SDL_ClearError();
+ SDL_memset(buffer, '1', BUFSIZ);
+ buffer[BUFSIZ] = 0;
+ SDL_SetError("This is the error: %s (%f)", buffer, 1.0);
+ printf("Error 2: %s\n", SDL_GetError());
+ exit(0);
+}
+#endif
+
+
+/* keep this at the end of the file so it works with GCC builds that don't
+ support "#pragma GCC diagnostic push" ... we'll just leave the warning
+ disabled after this. */
+/* this pragma arrived in GCC 4.2 and causes a warning on older GCCs! Sigh. */
+#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 2))))
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+#endif
+
+/* This function has a bit more overhead than most error functions
+ so that it supports internationalization and thread-safe errors.
+*/
+static char *
+SDL_GetErrorMsg(char *errstr, int maxlen)
+{
+ SDL_error *error;
+
+ /* Clear the error string */
+ *errstr = '\0';
+ --maxlen;
+
+ /* Get the thread-safe error, and print it out */
+ error = SDL_GetErrBuf();
+ if (error->error) {
+ const char *fmt;
+ char *msg = errstr;
+ int len;
+ int argi;
+
+ fmt = SDL_LookupString(error->key);
+ argi = 0;
+ while (*fmt && (maxlen > 0)) {
+ if (*fmt == '%') {
+ char tmp[32], *spot = tmp;
+ *spot++ = *fmt++;
+ while ((*fmt == '.' || (*fmt >= '0' && *fmt <= '9'))
+ && spot < (tmp + SDL_arraysize(tmp) - 2)) {
+ *spot++ = *fmt++;
+ }
+ if (*fmt == 'l') {
+ *spot++ = *fmt++;
+ *spot++ = *fmt++;
+ *spot++ = '\0';
+ switch (spot[-2]) {
+ case 'i': case 'd': case 'u':
+ len = SDL_snprintf(msg, maxlen, tmp,
+ error->args[argi++].value_l);
+ if (len > 0) {
+ msg += len;
+ maxlen -= len;
+ }
+ break;
+ }
+ continue;
+ }
+ *spot++ = *fmt++;
+ *spot++ = '\0';
+ switch (spot[-2]) {
+ case '%':
+ *msg++ = '%';
+ maxlen -= 1;
+ break;
+ case 'c':
+ case 'i':
+ case 'd':
+ case 'u':
+ case 'o':
+ case 'x':
+ case 'X':
+ len =
+ SDL_snprintf(msg, maxlen, tmp,
+ error->args[argi++].value_i);
+ if (len > 0) {
+ msg += len;
+ maxlen -= len;
+ }
+ break;
+
+ case 'f':
+ len =
+ SDL_snprintf(msg, maxlen, tmp,
+ error->args[argi++].value_f);
+ if (len > 0) {
+ msg += len;
+ maxlen -= len;
+ }
+ break;
+
+ case 'p':
+ len =
+ SDL_snprintf(msg, maxlen, tmp,
+ error->args[argi++].value_ptr);
+ if (len > 0) {
+ msg += len;
+ maxlen -= len;
+ }
+ break;
+
+ case 's':
+ len =
+ SDL_snprintf(msg, maxlen, tmp,
+ SDL_LookupString(error->args[argi++].
+ buf));
+ if (len > 0) {
+ msg += len;
+ maxlen -= len;
+ }
+ break;
+
+ }
+ } else {
+ *msg++ = *fmt++;
+ maxlen -= 1;
+ }
+ }
+
+ /* slide back if we've overshot the end of our buffer. */
+ if (maxlen < 0) {
+ msg -= (-maxlen) + 1;
+ }
+
+ *msg = 0; /* NULL terminate the string */
+ }
+ return (errstr);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/SDL_error_c.h b/src/3rdparty/SDL2/src/SDL_error_c.h
new file mode 100644
index 0000000..6bb9caa
--- /dev/null
+++ b/src/3rdparty/SDL2/src/SDL_error_c.h
@@ -0,0 +1,65 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "./SDL_internal.h"
+
+/* This file defines a structure that carries language-independent
+ error messages
+*/
+
+#ifndef SDL_error_c_h_
+#define SDL_error_c_h_
+
+#define ERR_MAX_STRLEN 128
+#define ERR_MAX_ARGS 5
+
+typedef struct SDL_error
+{
+ /* This is a numeric value corresponding to the current error */
+ int error;
+
+ /* This is a key used to index into a language hashtable containing
+ internationalized versions of the SDL error messages. If the key
+ is not in the hashtable, or no hashtable is available, the key is
+ used directly as an error message format string.
+ */
+ char key[ERR_MAX_STRLEN];
+
+ /* These are the arguments for the error functions */
+ int argc;
+ union
+ {
+ void *value_ptr;
+#if 0 /* What is a character anyway? (UNICODE issues) */
+ unsigned char value_c;
+#endif
+ int value_i;
+ long value_l;
+ double value_f;
+ char buf[ERR_MAX_STRLEN];
+ } args[ERR_MAX_ARGS];
+} SDL_error;
+
+/* Defined in SDL_thread.c */
+extern SDL_error *SDL_GetErrBuf(void);
+
+#endif /* SDL_error_c_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/SDL_hints.c b/src/3rdparty/SDL2/src/SDL_hints.c
new file mode 100644
index 0000000..09689aa
--- /dev/null
+++ b/src/3rdparty/SDL2/src/SDL_hints.c
@@ -0,0 +1,236 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "./SDL_internal.h"
+
+#include "SDL_hints.h"
+#include "SDL_error.h"
+
+
+/* Assuming there aren't many hints set and they aren't being queried in
+ critical performance paths, we'll just use linked lists here.
+ */
+typedef struct SDL_HintWatch {
+ SDL_HintCallback callback;
+ void *userdata;
+ struct SDL_HintWatch *next;
+} SDL_HintWatch;
+
+typedef struct SDL_Hint {
+ char *name;
+ char *value;
+ SDL_HintPriority priority;
+ SDL_HintWatch *callbacks;
+ struct SDL_Hint *next;
+} SDL_Hint;
+
+static SDL_Hint *SDL_hints;
+
+SDL_bool
+SDL_SetHintWithPriority(const char *name, const char *value,
+ SDL_HintPriority priority)
+{
+ const char *env;
+ SDL_Hint *hint;
+ SDL_HintWatch *entry;
+
+ if (!name || !value) {
+ return SDL_FALSE;
+ }
+
+ env = SDL_getenv(name);
+ if (env && priority < SDL_HINT_OVERRIDE) {
+ return SDL_FALSE;
+ }
+
+ for (hint = SDL_hints; hint; hint = hint->next) {
+ if (SDL_strcmp(name, hint->name) == 0) {
+ if (priority < hint->priority) {
+ return SDL_FALSE;
+ }
+ if (!hint->value || !value || SDL_strcmp(hint->value, value) != 0) {
+ for (entry = hint->callbacks; entry; ) {
+ /* Save the next entry in case this one is deleted */
+ SDL_HintWatch *next = entry->next;
+ entry->callback(entry->userdata, name, hint->value, value);
+ entry = next;
+ }
+ SDL_free(hint->value);
+ hint->value = value ? SDL_strdup(value) : NULL;
+ }
+ hint->priority = priority;
+ return SDL_TRUE;
+ }
+ }
+
+ /* Couldn't find the hint, add a new one */
+ hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
+ if (!hint) {
+ return SDL_FALSE;
+ }
+ hint->name = SDL_strdup(name);
+ hint->value = value ? SDL_strdup(value) : NULL;
+ hint->priority = priority;
+ hint->callbacks = NULL;
+ hint->next = SDL_hints;
+ SDL_hints = hint;
+ return SDL_TRUE;
+}
+
+SDL_bool
+SDL_SetHint(const char *name, const char *value)
+{
+ return SDL_SetHintWithPriority(name, value, SDL_HINT_NORMAL);
+}
+
+const char *
+SDL_GetHint(const char *name)
+{
+ const char *env;
+ SDL_Hint *hint;
+
+ env = SDL_getenv(name);
+ for (hint = SDL_hints; hint; hint = hint->next) {
+ if (SDL_strcmp(name, hint->name) == 0) {
+ if (!env || hint->priority == SDL_HINT_OVERRIDE) {
+ return hint->value;
+ }
+ break;
+ }
+ }
+ return env;
+}
+
+SDL_bool
+SDL_GetHintBoolean(const char *name, SDL_bool default_value)
+{
+ const char *hint = SDL_GetHint(name);
+ if (!hint || !*hint) {
+ return default_value;
+ }
+ if (*hint == '0' || SDL_strcasecmp(hint, "false") == 0) {
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
+}
+
+void
+SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
+{
+ SDL_Hint *hint;
+ SDL_HintWatch *entry;
+ const char *value;
+
+ if (!name || !*name) {
+ SDL_InvalidParamError("name");
+ return;
+ }
+ if (!callback) {
+ SDL_InvalidParamError("callback");
+ return;
+ }
+
+ SDL_DelHintCallback(name, callback, userdata);
+
+ entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry));
+ if (!entry) {
+ SDL_OutOfMemory();
+ return;
+ }
+ entry->callback = callback;
+ entry->userdata = userdata;
+
+ for (hint = SDL_hints; hint; hint = hint->next) {
+ if (SDL_strcmp(name, hint->name) == 0) {
+ break;
+ }
+ }
+ if (!hint) {
+ /* Need to add a hint entry for this watcher */
+ hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
+ if (!hint) {
+ SDL_OutOfMemory();
+ SDL_free(entry);
+ return;
+ }
+ hint->name = SDL_strdup(name);
+ hint->value = NULL;
+ hint->priority = SDL_HINT_DEFAULT;
+ hint->callbacks = NULL;
+ hint->next = SDL_hints;
+ SDL_hints = hint;
+ }
+
+ /* Add it to the callbacks for this hint */
+ entry->next = hint->callbacks;
+ hint->callbacks = entry;
+
+ /* Now call it with the current value */
+ value = SDL_GetHint(name);
+ callback(userdata, name, value, value);
+}
+
+void
+SDL_DelHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
+{
+ SDL_Hint *hint;
+ SDL_HintWatch *entry, *prev;
+
+ for (hint = SDL_hints; hint; hint = hint->next) {
+ if (SDL_strcmp(name, hint->name) == 0) {
+ prev = NULL;
+ for (entry = hint->callbacks; entry; entry = entry->next) {
+ if (callback == entry->callback && userdata == entry->userdata) {
+ if (prev) {
+ prev->next = entry->next;
+ } else {
+ hint->callbacks = entry->next;
+ }
+ SDL_free(entry);
+ break;
+ }
+ prev = entry;
+ }
+ return;
+ }
+ }
+}
+
+void SDL_ClearHints(void)
+{
+ SDL_Hint *hint;
+ SDL_HintWatch *entry;
+
+ while (SDL_hints) {
+ hint = SDL_hints;
+ SDL_hints = hint->next;
+
+ SDL_free(hint->name);
+ SDL_free(hint->value);
+ for (entry = hint->callbacks; entry; ) {
+ SDL_HintWatch *freeable = entry;
+ entry = entry->next;
+ SDL_free(freeable);
+ }
+ SDL_free(hint);
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/SDL_internal.h b/src/3rdparty/SDL2/src/SDL_internal.h
new file mode 100644
index 0000000..e0ba2a8
--- /dev/null
+++ b/src/3rdparty/SDL2/src/SDL_internal.h
@@ -0,0 +1,52 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#ifndef SDL_internal_h_
+#define SDL_internal_h_
+
+/* Many of SDL's features require _GNU_SOURCE on various platforms */
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+/* This is for a variable-length array at the end of a struct:
+ struct x { int y; char z[SDL_VARIABLE_LENGTH_ARRAY]; };
+ Use this because GCC 2 needs different magic than other compilers. */
+#if (defined(__GNUC__) && (__GNUC__ <= 2)) || defined(__CC_ARM) || defined(__cplusplus)
+#define SDL_VARIABLE_LENGTH_ARRAY 1
+#else
+#define SDL_VARIABLE_LENGTH_ARRAY
+#endif
+
+#include "dynapi/SDL_dynapi.h"
+
+#if SDL_DYNAMIC_API
+#include "dynapi/SDL_dynapi_overrides.h"
+/* force DECLSPEC and SDLCALL off...it's all internal symbols now.
+ These will have actual #defines during SDL_dynapi.c only */
+#define DECLSPEC
+#define SDLCALL
+#endif
+
+#include "SDL_config.h"
+
+#endif /* SDL_internal_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/SDL_log.c b/src/3rdparty/SDL2/src/SDL_log.c
new file mode 100644
index 0000000..b1bf27d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/SDL_log.c
@@ -0,0 +1,450 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "./SDL_internal.h"
+
+#if defined(__WIN32__) || defined(__WINRT__)
+#include "core/windows/SDL_windows.h"
+#endif
+
+/* Simple log messages in SDL */
+
+#include "SDL_error.h"
+#include "SDL_log.h"
+
+#if HAVE_STDIO_H
+#include <stdio.h>
+#endif
+
+#if defined(__ANDROID__)
+#include <android/log.h>
+#endif
+
+#define DEFAULT_PRIORITY SDL_LOG_PRIORITY_CRITICAL
+#define DEFAULT_ASSERT_PRIORITY SDL_LOG_PRIORITY_WARN
+#define DEFAULT_APPLICATION_PRIORITY SDL_LOG_PRIORITY_INFO
+#define DEFAULT_TEST_PRIORITY SDL_LOG_PRIORITY_VERBOSE
+
+typedef struct SDL_LogLevel
+{
+ int category;
+ SDL_LogPriority priority;
+ struct SDL_LogLevel *next;
+} SDL_LogLevel;
+
+/* The default log output function */
+static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority, const char *message);
+
+static SDL_LogLevel *SDL_loglevels;
+static SDL_LogPriority SDL_default_priority = DEFAULT_PRIORITY;
+static SDL_LogPriority SDL_assert_priority = DEFAULT_ASSERT_PRIORITY;
+static SDL_LogPriority SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
+static SDL_LogPriority SDL_test_priority = DEFAULT_TEST_PRIORITY;
+static SDL_LogOutputFunction SDL_log_function = SDL_LogOutput;
+static void *SDL_log_userdata = NULL;
+
+static const char *SDL_priority_prefixes[SDL_NUM_LOG_PRIORITIES] = {
+ NULL,
+ "VERBOSE",
+ "DEBUG",
+ "INFO",
+ "WARN",
+ "ERROR",
+ "CRITICAL"
+};
+
+#ifdef __ANDROID__
+static const char *SDL_category_prefixes[SDL_LOG_CATEGORY_RESERVED1] = {
+ "APP",
+ "ERROR",
+ "SYSTEM",
+ "AUDIO",
+ "VIDEO",
+ "RENDER",
+ "INPUT"
+};
+
+static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = {
+ ANDROID_LOG_UNKNOWN,
+ ANDROID_LOG_VERBOSE,
+ ANDROID_LOG_DEBUG,
+ ANDROID_LOG_INFO,
+ ANDROID_LOG_WARN,
+ ANDROID_LOG_ERROR,
+ ANDROID_LOG_FATAL
+};
+#endif /* __ANDROID__ */
+
+
+void
+SDL_LogSetAllPriority(SDL_LogPriority priority)
+{
+ SDL_LogLevel *entry;
+
+ for (entry = SDL_loglevels; entry; entry = entry->next) {
+ entry->priority = priority;
+ }
+ SDL_default_priority = priority;
+ SDL_assert_priority = priority;
+ SDL_application_priority = priority;
+}
+
+void
+SDL_LogSetPriority(int category, SDL_LogPriority priority)
+{
+ SDL_LogLevel *entry;
+
+ for (entry = SDL_loglevels; entry; entry = entry->next) {
+ if (entry->category == category) {
+ entry->priority = priority;
+ return;
+ }
+ }
+
+ /* Create a new entry */
+ entry = (SDL_LogLevel *)SDL_malloc(sizeof(*entry));
+ if (entry) {
+ entry->category = category;
+ entry->priority = priority;
+ entry->next = SDL_loglevels;
+ SDL_loglevels = entry;
+ }
+}
+
+SDL_LogPriority
+SDL_LogGetPriority(int category)
+{
+ SDL_LogLevel *entry;
+
+ for (entry = SDL_loglevels; entry; entry = entry->next) {
+ if (entry->category == category) {
+ return entry->priority;
+ }
+ }
+
+ if (category == SDL_LOG_CATEGORY_TEST) {
+ return SDL_test_priority;
+ } else if (category == SDL_LOG_CATEGORY_APPLICATION) {
+ return SDL_application_priority;
+ } else if (category == SDL_LOG_CATEGORY_ASSERT) {
+ return SDL_assert_priority;
+ } else {
+ return SDL_default_priority;
+ }
+}
+
+void
+SDL_LogResetPriorities(void)
+{
+ SDL_LogLevel *entry;
+
+ while (SDL_loglevels) {
+ entry = SDL_loglevels;
+ SDL_loglevels = entry->next;
+ SDL_free(entry);
+ }
+
+ SDL_default_priority = DEFAULT_PRIORITY;
+ SDL_assert_priority = DEFAULT_ASSERT_PRIORITY;
+ SDL_application_priority = DEFAULT_APPLICATION_PRIORITY;
+ SDL_test_priority = DEFAULT_TEST_PRIORITY;
+}
+
+void
+SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, fmt, ap);
+ va_end(ap);
+}
+
+void
+SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ SDL_LogMessageV(category, SDL_LOG_PRIORITY_VERBOSE, fmt, ap);
+ va_end(ap);
+}
+
+void
+SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ SDL_LogMessageV(category, SDL_LOG_PRIORITY_DEBUG, fmt, ap);
+ va_end(ap);
+}
+
+void
+SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ SDL_LogMessageV(category, SDL_LOG_PRIORITY_INFO, fmt, ap);
+ va_end(ap);
+}
+
+void
+SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ SDL_LogMessageV(category, SDL_LOG_PRIORITY_WARN, fmt, ap);
+ va_end(ap);
+}
+
+void
+SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ SDL_LogMessageV(category, SDL_LOG_PRIORITY_ERROR, fmt, ap);
+ va_end(ap);
+}
+
+void
+SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ SDL_LogMessageV(category, SDL_LOG_PRIORITY_CRITICAL, fmt, ap);
+ va_end(ap);
+}
+
+void
+SDL_LogMessage(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ SDL_LogMessageV(category, priority, fmt, ap);
+ va_end(ap);
+}
+
+#ifdef __ANDROID__
+static const char *
+GetCategoryPrefix(int category)
+{
+ if (category < SDL_LOG_CATEGORY_RESERVED1) {
+ return SDL_category_prefixes[category];
+ }
+ if (category < SDL_LOG_CATEGORY_CUSTOM) {
+ return "RESERVED";
+ }
+ return "CUSTOM";
+}
+#endif /* __ANDROID__ */
+
+void
+SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va_list ap)
+{
+ char *message;
+ size_t len;
+
+ /* Nothing to do if we don't have an output function */
+ if (!SDL_log_function) {
+ return;
+ }
+
+ /* Make sure we don't exceed array bounds */
+ if ((int)priority < 0 || priority >= SDL_NUM_LOG_PRIORITIES) {
+ return;
+ }
+
+ /* See if we want to do anything with this message */
+ if (priority < SDL_LogGetPriority(category)) {
+ return;
+ }
+
+ message = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
+ if (!message) {
+ return;
+ }
+
+ SDL_vsnprintf(message, SDL_MAX_LOG_MESSAGE, fmt, ap);
+
+ /* Chop off final endline. */
+ len = SDL_strlen(message);
+ if ((len > 0) && (message[len-1] == '\n')) {
+ message[--len] = '\0';
+ if ((len > 0) && (message[len-1] == '\r')) { /* catch "\r\n", too. */
+ message[--len] = '\0';
+ }
+ }
+
+ SDL_log_function(SDL_log_userdata, category, priority, message);
+ SDL_stack_free(message);
+}
+
+#if defined(__WIN32__) && !defined(HAVE_STDIO_H) && !defined(__WINRT__)
+/* Flag tracking the attachment of the console: 0=unattached, 1=attached to a console, 2=attached to a file, -1=error */
+static int consoleAttached = 0;
+
+/* Handle to stderr output of console. */
+static HANDLE stderrHandle = NULL;
+#endif
+
+static void SDLCALL
+SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
+ const char *message)
+{
+#if defined(__WIN32__) || defined(__WINRT__)
+ /* Way too many allocations here, urgh */
+ /* Note: One can't call SDL_SetError here, since that function itself logs. */
+ {
+ char *output;
+ size_t length;
+ LPTSTR tstr;
+
+#if !defined(HAVE_STDIO_H) && !defined(__WINRT__)
+ BOOL attachResult;
+ DWORD attachError;
+ unsigned long charsWritten;
+ DWORD consoleMode;
+
+ /* Maybe attach console and get stderr handle */
+ if (consoleAttached == 0) {
+ attachResult = AttachConsole(ATTACH_PARENT_PROCESS);
+ if (!attachResult) {
+ attachError = GetLastError();
+ if (attachError == ERROR_INVALID_HANDLE) {
+ /* This is expected when running from Visual Studio */
+ /*OutputDebugString(TEXT("Parent process has no console\r\n"));*/
+ consoleAttached = -1;
+ } else if (attachError == ERROR_GEN_FAILURE) {
+ OutputDebugString(TEXT("Could not attach to console of parent process\r\n"));
+ consoleAttached = -1;
+ } else if (attachError == ERROR_ACCESS_DENIED) {
+ /* Already attached */
+ consoleAttached = 1;
+ } else {
+ OutputDebugString(TEXT("Error attaching console\r\n"));
+ consoleAttached = -1;
+ }
+ } else {
+ /* Newly attached */
+ consoleAttached = 1;
+ }
+
+ if (consoleAttached == 1) {
+ stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
+
+ if (GetConsoleMode(stderrHandle, &consoleMode) == 0) {
+ /* WriteConsole fails if the output is redirected to a file. Must use WriteFile instead. */
+ consoleAttached = 2;
+ }
+ }
+ }
+#endif /* !defined(HAVE_STDIO_H) && !defined(__WINRT__) */
+
+ length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1 + 1 + 1;
+ output = SDL_stack_alloc(char, length);
+ SDL_snprintf(output, length, "%s: %s\r\n", SDL_priority_prefixes[priority], message);
+ tstr = WIN_UTF8ToString(output);
+
+ /* Output to debugger */
+ OutputDebugString(tstr);
+
+#if !defined(HAVE_STDIO_H) && !defined(__WINRT__)
+ /* Screen output to stderr, if console was attached. */
+ if (consoleAttached == 1) {
+ if (!WriteConsole(stderrHandle, tstr, lstrlen(tstr), &charsWritten, NULL)) {
+ OutputDebugString(TEXT("Error calling WriteConsole\r\n"));
+ if (GetLastError() == ERROR_NOT_ENOUGH_MEMORY) {
+ OutputDebugString(TEXT("Insufficient heap memory to write message\r\n"));
+ }
+ }
+
+ } else if (consoleAttached == 2) {
+ if (!WriteFile(stderrHandle, output, lstrlenA(output), &charsWritten, NULL)) {
+ OutputDebugString(TEXT("Error calling WriteFile\r\n"));
+ }
+ }
+#endif /* !defined(HAVE_STDIO_H) && !defined(__WINRT__) */
+
+ SDL_free(tstr);
+ SDL_stack_free(output);
+ }
+#elif defined(__ANDROID__)
+ {
+ char tag[32];
+
+ SDL_snprintf(tag, SDL_arraysize(tag), "SDL/%s", GetCategoryPrefix(category));
+ __android_log_write(SDL_android_priority[priority], tag, message);
+ }
+#elif defined(__APPLE__) && defined(SDL_VIDEO_DRIVER_COCOA)
+ /* Technically we don't need SDL_VIDEO_DRIVER_COCOA, but that's where this function is defined for now.
+ */
+ extern void SDL_NSLog(const char *text);
+ {
+ char *text;
+
+ text = SDL_stack_alloc(char, SDL_MAX_LOG_MESSAGE);
+ if (text) {
+ SDL_snprintf(text, SDL_MAX_LOG_MESSAGE, "%s: %s", SDL_priority_prefixes[priority], message);
+ SDL_NSLog(text);
+ SDL_stack_free(text);
+ return;
+ }
+ }
+#elif defined(__PSP__)
+ {
+ FILE* pFile;
+ pFile = fopen ("SDL_Log.txt", "a");
+ fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
+ fclose (pFile);
+ }
+#endif
+#if HAVE_STDIO_H
+ fprintf(stderr, "%s: %s\n", SDL_priority_prefixes[priority], message);
+#if __NACL__
+ fflush(stderr);
+#endif
+#endif
+}
+
+void
+SDL_LogGetOutputFunction(SDL_LogOutputFunction *callback, void **userdata)
+{
+ if (callback) {
+ *callback = SDL_log_function;
+ }
+ if (userdata) {
+ *userdata = SDL_log_userdata;
+ }
+}
+
+void
+SDL_LogSetOutputFunction(SDL_LogOutputFunction callback, void *userdata)
+{
+ SDL_log_function = callback;
+ SDL_log_userdata = userdata;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/atomic/SDL_atomic.c b/src/3rdparty/SDL2/src/atomic/SDL_atomic.c
new file mode 100644
index 0000000..df49201
--- /dev/null
+++ b/src/3rdparty/SDL2/src/atomic/SDL_atomic.c
@@ -0,0 +1,303 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "SDL_atomic.h"
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1500)
+#include <intrin.h>
+#define HAVE_MSC_ATOMICS 1
+#endif
+
+#if defined(__MACOSX__) /* !!! FIXME: should we favor gcc atomics? */
+#include <libkern/OSAtomic.h>
+#endif
+
+#if !defined(HAVE_GCC_ATOMICS) && defined(__SOLARIS__)
+#include <atomic.h>
+#endif
+
+/* The __atomic_load_n() intrinsic showed up in different times for different compilers. */
+#if defined(HAVE_GCC_ATOMICS)
+# if defined(__clang__)
+# if __has_builtin(__atomic_load_n)
+ /* !!! FIXME: this advertises as available in the NDK but uses an external symbol we don't have.
+ It might be in a later NDK or we might need an extra library? --ryan. */
+# if !defined(__ANDROID__)
+# define HAVE_ATOMIC_LOAD_N 1
+# endif
+# endif
+# elif defined(__GNUC__)
+# if (__GNUC__ >= 5)
+# define HAVE_ATOMIC_LOAD_N 1
+# endif
+# endif
+#endif
+
+#if defined(__WATCOMC__) && defined(__386__)
+#define HAVE_WATCOM_ATOMICS
+extern _inline int _SDL_xchg_watcom(volatile int *a, int v);
+#pragma aux _SDL_xchg_watcom = \
+ "xchg [ecx], eax" \
+ parm [ecx] [eax] \
+ value [eax] \
+ modify exact [eax];
+
+extern _inline unsigned char _SDL_cmpxchg_watcom(volatile int *a, int newval, int oldval);
+#pragma aux _SDL_cmpxchg_watcom = \
+ "lock cmpxchg [edx], ecx" \
+ "setz al" \
+ parm [edx] [ecx] [eax] \
+ value [al] \
+ modify exact [eax];
+
+extern _inline int _SDL_xadd_watcom(volatile int *a, int v);
+#pragma aux _SDL_xadd_watcom = \
+ "lock xadd [ecx], eax" \
+ parm [ecx] [eax] \
+ value [eax] \
+ modify exact [eax];
+#endif /* __WATCOMC__ && __386__ */
+
+/*
+ If any of the operations are not provided then we must emulate some
+ of them. That means we need a nice implementation of spin locks
+ that avoids the "one big lock" problem. We use a vector of spin
+ locks and pick which one to use based on the address of the operand
+ of the function.
+
+ To generate the index of the lock we first shift by 3 bits to get
+ rid on the zero bits that result from 32 and 64 bit allignment of
+ data. We then mask off all but 5 bits and use those 5 bits as an
+ index into the table.
+
+ Picking the lock this way insures that accesses to the same data at
+ the same time will go to the same lock. OTOH, accesses to different
+ data have only a 1/32 chance of hitting the same lock. That should
+ pretty much eliminate the chances of several atomic operations on
+ different data from waiting on the same "big lock". If it isn't
+ then the table of locks can be expanded to a new size so long as
+ the new size is a power of two.
+
+ Contributed by Bob Pendleton, bob@pendleton.com
+*/
+
+#if !defined(HAVE_MSC_ATOMICS) && !defined(HAVE_GCC_ATOMICS) && !defined(__MACOSX__) && !defined(__SOLARIS__) && !defined(HAVE_WATCOM_ATOMICS)
+#define EMULATE_CAS 1
+#endif
+
+#if EMULATE_CAS
+static SDL_SpinLock locks[32];
+
+static SDL_INLINE void
+enterLock(void *a)
+{
+ uintptr_t index = ((((uintptr_t)a) >> 3) & 0x1f);
+
+ SDL_AtomicLock(&locks[index]);
+}
+
+static SDL_INLINE void
+leaveLock(void *a)
+{
+ uintptr_t index = ((((uintptr_t)a) >> 3) & 0x1f);
+
+ SDL_AtomicUnlock(&locks[index]);
+}
+#endif
+
+
+SDL_bool
+SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval)
+{
+#ifdef HAVE_MSC_ATOMICS
+ return (_InterlockedCompareExchange((long*)&a->value, (long)newval, (long)oldval) == (long)oldval);
+#elif defined(HAVE_WATCOM_ATOMICS)
+ return (SDL_bool) _SDL_cmpxchg_watcom(&a->value, newval, oldval);
+#elif defined(HAVE_GCC_ATOMICS)
+ return (SDL_bool) __sync_bool_compare_and_swap(&a->value, oldval, newval);
+#elif defined(__MACOSX__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
+ return (SDL_bool) OSAtomicCompareAndSwap32Barrier(oldval, newval, &a->value);
+#elif defined(__SOLARIS__) && defined(_LP64)
+ return (SDL_bool) ((int) atomic_cas_64((volatile uint64_t*)&a->value, (uint64_t)oldval, (uint64_t)newval) == oldval);
+#elif defined(__SOLARIS__) && !defined(_LP64)
+ return (SDL_bool) ((int) atomic_cas_32((volatile uint32_t*)&a->value, (uint32_t)oldval, (uint32_t)newval) == oldval);
+#elif EMULATE_CAS
+ SDL_bool retval = SDL_FALSE;
+
+ enterLock(a);
+ if (a->value == oldval) {
+ a->value = newval;
+ retval = SDL_TRUE;
+ }
+ leaveLock(a);
+
+ return retval;
+#else
+ #error Please define your platform.
+#endif
+}
+
+SDL_bool
+SDL_AtomicCASPtr(void **a, void *oldval, void *newval)
+{
+#if defined(HAVE_MSC_ATOMICS) && (_M_IX86)
+ return (_InterlockedCompareExchange((long*)a, (long)newval, (long)oldval) == (long)oldval);
+#elif defined(HAVE_MSC_ATOMICS) && (!_M_IX86)
+ return (_InterlockedCompareExchangePointer(a, newval, oldval) == oldval);
+#elif defined(HAVE_WATCOM_ATOMICS)
+ return (SDL_bool) _SDL_cmpxchg_watcom((int *)a, (long)newval, (long)oldval);
+#elif defined(HAVE_GCC_ATOMICS)
+ return __sync_bool_compare_and_swap(a, oldval, newval);
+#elif defined(__MACOSX__) && defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
+ return (SDL_bool) OSAtomicCompareAndSwap64Barrier((int64_t)oldval, (int64_t)newval, (int64_t*) a);
+#elif defined(__MACOSX__) && !defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
+ return (SDL_bool) OSAtomicCompareAndSwap32Barrier((int32_t)oldval, (int32_t)newval, (int32_t*) a);
+#elif defined(__SOLARIS__)
+ return (SDL_bool) (atomic_cas_ptr(a, oldval, newval) == oldval);
+#elif EMULATE_CAS
+ SDL_bool retval = SDL_FALSE;
+
+ enterLock(a);
+ if (*a == oldval) {
+ *a = newval;
+ retval = SDL_TRUE;
+ }
+ leaveLock(a);
+
+ return retval;
+#else
+ #error Please define your platform.
+#endif
+}
+
+int
+SDL_AtomicSet(SDL_atomic_t *a, int v)
+{
+#ifdef HAVE_MSC_ATOMICS
+ return _InterlockedExchange((long*)&a->value, v);
+#elif defined(HAVE_WATCOM_ATOMICS)
+ return _SDL_xchg_watcom(&a->value, v);
+#elif defined(HAVE_GCC_ATOMICS)
+ return __sync_lock_test_and_set(&a->value, v);
+#elif defined(__SOLARIS__) && defined(_LP64)
+ return (int) atomic_swap_64((volatile uint64_t*)&a->value, (uint64_t)v);
+#elif defined(__SOLARIS__) && !defined(_LP64)
+ return (int) atomic_swap_32((volatile uint32_t*)&a->value, (uint32_t)v);
+#else
+ int value;
+ do {
+ value = a->value;
+ } while (!SDL_AtomicCAS(a, value, v));
+ return value;
+#endif
+}
+
+void*
+SDL_AtomicSetPtr(void **a, void *v)
+{
+#if defined(HAVE_MSC_ATOMICS) && (_M_IX86)
+ return (void *) _InterlockedExchange((long *)a, (long) v);
+#elif defined(HAVE_MSC_ATOMICS) && (!_M_IX86)
+ return _InterlockedExchangePointer(a, v);
+#elif defined(HAVE_WATCOM_ATOMICS)
+ return (void *) _SDL_xchg_watcom((int *)a, (long)v);
+#elif defined(HAVE_GCC_ATOMICS)
+ return __sync_lock_test_and_set(a, v);
+#elif defined(__SOLARIS__)
+ return atomic_swap_ptr(a, v);
+#else
+ void *value;
+ do {
+ value = *a;
+ } while (!SDL_AtomicCASPtr(a, value, v));
+ return value;
+#endif
+}
+
+int
+SDL_AtomicAdd(SDL_atomic_t *a, int v)
+{
+#ifdef HAVE_MSC_ATOMICS
+ return _InterlockedExchangeAdd((long*)&a->value, v);
+#elif defined(HAVE_WATCOM_ATOMICS)
+ return _SDL_xadd_watcom(&a->value, v);
+#elif defined(HAVE_GCC_ATOMICS)
+ return __sync_fetch_and_add(&a->value, v);
+#elif defined(__SOLARIS__)
+ int pv = a->value;
+ membar_consumer();
+#if defined(_LP64)
+ atomic_add_64((volatile uint64_t*)&a->value, v);
+#elif !defined(_LP64)
+ atomic_add_32((volatile uint32_t*)&a->value, v);
+#endif
+ return pv;
+#else
+ int value;
+ do {
+ value = a->value;
+ } while (!SDL_AtomicCAS(a, value, (value + v)));
+ return value;
+#endif
+}
+
+int
+SDL_AtomicGet(SDL_atomic_t *a)
+{
+#ifdef HAVE_ATOMIC_LOAD_N
+ return __atomic_load_n(&a->value, __ATOMIC_SEQ_CST);
+#else
+ int value;
+ do {
+ value = a->value;
+ } while (!SDL_AtomicCAS(a, value, value));
+ return value;
+#endif
+}
+
+void *
+SDL_AtomicGetPtr(void **a)
+{
+#ifdef HAVE_ATOMIC_LOAD_N
+ return __atomic_load_n(a, __ATOMIC_SEQ_CST);
+#else
+ void *value;
+ do {
+ value = *a;
+ } while (!SDL_AtomicCASPtr(a, value, value));
+ return value;
+#endif
+}
+
+void
+SDL_MemoryBarrierReleaseFunction(void)
+{
+ SDL_MemoryBarrierRelease();
+}
+
+void
+SDL_MemoryBarrierAcquireFunction(void)
+{
+ SDL_MemoryBarrierAcquire();
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/atomic/SDL_spinlock.c b/src/3rdparty/SDL2/src/atomic/SDL_spinlock.c
new file mode 100644
index 0000000..1ebc718
--- /dev/null
+++ b/src/3rdparty/SDL2/src/atomic/SDL_spinlock.c
@@ -0,0 +1,152 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#if defined(__WIN32__) || defined(__WINRT__)
+#include "../core/windows/SDL_windows.h"
+#endif
+
+#include "SDL_atomic.h"
+#include "SDL_mutex.h"
+#include "SDL_timer.h"
+
+#if !defined(HAVE_GCC_ATOMICS) && defined(__SOLARIS__)
+#include <atomic.h>
+#endif
+
+#if defined(__WATCOMC__) && defined(__386__)
+SDL_COMPILE_TIME_ASSERT(locksize, 4==sizeof(SDL_SpinLock));
+extern _inline int _SDL_xchg_watcom(volatile int *a, int v);
+#pragma aux _SDL_xchg_watcom = \
+ "xchg [ecx], eax" \
+ parm [ecx] [eax] \
+ value [eax] \
+ modify exact [eax];
+#endif /* __WATCOMC__ && __386__ */
+
+/* This function is where all the magic happens... */
+SDL_bool
+SDL_AtomicTryLock(SDL_SpinLock *lock)
+{
+#if SDL_ATOMIC_DISABLED
+ /* Terrible terrible damage */
+ static SDL_mutex *_spinlock_mutex;
+
+ if (!_spinlock_mutex) {
+ /* Race condition on first lock... */
+ _spinlock_mutex = SDL_CreateMutex();
+ }
+ SDL_LockMutex(_spinlock_mutex);
+ if (*lock == 0) {
+ *lock = 1;
+ SDL_UnlockMutex(_spinlock_mutex);
+ return SDL_TRUE;
+ } else {
+ SDL_UnlockMutex(_spinlock_mutex);
+ return SDL_FALSE;
+ }
+
+#elif defined(_MSC_VER)
+ SDL_COMPILE_TIME_ASSERT(locksize, sizeof(*lock) == sizeof(long));
+ return (InterlockedExchange((long*)lock, 1) == 0);
+
+#elif defined(__WATCOMC__) && defined(__386__)
+ return _SDL_xchg_watcom(lock, 1) == 0;
+
+#elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
+ return (__sync_lock_test_and_set(lock, 1) == 0);
+
+#elif defined(__GNUC__) && defined(__arm__) && \
+ (defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || \
+ defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5TE__) || \
+ defined(__ARM_ARCH_5TEJ__))
+ int result;
+ __asm__ __volatile__ (
+ "swp %0, %1, [%2]\n"
+ : "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory");
+ return (result == 0);
+
+#elif defined(__GNUC__) && defined(__arm__)
+ int result;
+ __asm__ __volatile__ (
+ "ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]"
+ : "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
+ return (result == 0);
+
+#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+ int result;
+ __asm__ __volatile__(
+ "lock ; xchgl %0, (%1)\n"
+ : "=r" (result) : "r" (lock), "0" (1) : "cc", "memory");
+ return (result == 0);
+
+#elif defined(__MACOSX__) || defined(__IPHONEOS__)
+ /* Maybe used for PowerPC, but the Intel asm or gcc atomics are favored. */
+ return OSAtomicCompareAndSwap32Barrier(0, 1, lock);
+
+#elif defined(__SOLARIS__) && defined(_LP64)
+ /* Used for Solaris with non-gcc compilers. */
+ return (SDL_bool) ((int) atomic_cas_64((volatile uint64_t*)lock, 0, 1) == 0);
+
+#elif defined(__SOLARIS__) && !defined(_LP64)
+ /* Used for Solaris with non-gcc compilers. */
+ return (SDL_bool) ((int) atomic_cas_32((volatile uint32_t*)lock, 0, 1) == 0);
+
+#else
+#error Please implement for your platform.
+ return SDL_FALSE;
+#endif
+}
+
+void
+SDL_AtomicLock(SDL_SpinLock *lock)
+{
+ /* FIXME: Should we have an eventual timeout? */
+ while (!SDL_AtomicTryLock(lock)) {
+ SDL_Delay(0);
+ }
+}
+
+void
+SDL_AtomicUnlock(SDL_SpinLock *lock)
+{
+#if defined(_MSC_VER)
+ _ReadWriteBarrier();
+ *lock = 0;
+
+#elif defined(__WATCOMC__) && defined(__386__)
+ SDL_CompilerBarrier ();
+ *lock = 0;
+
+#elif HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
+ __sync_lock_release(lock);
+
+#elif defined(__SOLARIS__)
+ /* Used for Solaris when not using gcc. */
+ *lock = 0;
+ membar_producer();
+
+#else
+ *lock = 0;
+#endif
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/SDL_audio.c b/src/3rdparty/SDL2/src/audio/SDL_audio.c
new file mode 100644
index 0000000..dcaebea
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/SDL_audio.c
@@ -0,0 +1,1635 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* Allow access to a raw mixing buffer */
+
+#include "SDL.h"
+#include "SDL_audio.h"
+#include "SDL_audio_c.h"
+#include "SDL_sysaudio.h"
+#include "../thread/SDL_systhread.h"
+
+#define _THIS SDL_AudioDevice *_this
+
+static SDL_AudioDriver current_audio;
+static SDL_AudioDevice *open_devices[16];
+
+/* Available audio drivers */
+static const AudioBootStrap *const bootstrap[] = {
+#if SDL_AUDIO_DRIVER_PULSEAUDIO
+ &PULSEAUDIO_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_ALSA
+ &ALSA_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_SNDIO
+ &SNDIO_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_NETBSD
+ &NETBSDAUDIO_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_OSS
+ &DSP_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_QSA
+ &QSAAUDIO_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_SUNAUDIO
+ &SUNAUDIO_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_ARTS
+ &ARTS_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_ESD
+ &ESD_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_NACL
+ &NACLAUDIO_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_NAS
+ &NAS_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_WASAPI
+ &WASAPI_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_DSOUND
+ &DSOUND_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_WINMM
+ &WINMM_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_PAUDIO
+ &PAUDIO_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_HAIKU
+ &HAIKUAUDIO_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_COREAUDIO
+ &COREAUDIO_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_FUSIONSOUND
+ &FUSIONSOUND_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_ANDROID
+ &ANDROIDAUDIO_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_PSP
+ &PSPAUDIO_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_EMSCRIPTEN
+ &EMSCRIPTENAUDIO_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_JACK
+ &JACK_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_DISK
+ &DISKAUDIO_bootstrap,
+#endif
+#if SDL_AUDIO_DRIVER_DUMMY
+ &DUMMYAUDIO_bootstrap,
+#endif
+ NULL
+};
+
+
+#ifdef HAVE_LIBSAMPLERATE_H
+#ifdef SDL_LIBSAMPLERATE_DYNAMIC
+static void *SRC_lib = NULL;
+#endif
+SDL_bool SRC_available = SDL_FALSE;
+int SRC_converter = 0;
+SRC_STATE* (*SRC_src_new)(int converter_type, int channels, int *error) = NULL;
+int (*SRC_src_process)(SRC_STATE *state, SRC_DATA *data) = NULL;
+int (*SRC_src_reset)(SRC_STATE *state) = NULL;
+SRC_STATE* (*SRC_src_delete)(SRC_STATE *state) = NULL;
+const char* (*SRC_src_strerror)(int error) = NULL;
+
+static SDL_bool
+LoadLibSampleRate(void)
+{
+ const char *hint = SDL_GetHint(SDL_HINT_AUDIO_RESAMPLING_MODE);
+
+ SRC_available = SDL_FALSE;
+ SRC_converter = 0;
+
+ if (!hint || *hint == '0' || SDL_strcasecmp(hint, "default") == 0) {
+ return SDL_FALSE; /* don't load anything. */
+ } else if (*hint == '1' || SDL_strcasecmp(hint, "fast") == 0) {
+ SRC_converter = SRC_SINC_FASTEST;
+ } else if (*hint == '2' || SDL_strcasecmp(hint, "medium") == 0) {
+ SRC_converter = SRC_SINC_MEDIUM_QUALITY;
+ } else if (*hint == '3' || SDL_strcasecmp(hint, "best") == 0) {
+ SRC_converter = SRC_SINC_BEST_QUALITY;
+ } else {
+ return SDL_FALSE; /* treat it like "default", don't load anything. */
+ }
+
+#ifdef SDL_LIBSAMPLERATE_DYNAMIC
+ SDL_assert(SRC_lib == NULL);
+ SRC_lib = SDL_LoadObject(SDL_LIBSAMPLERATE_DYNAMIC);
+ if (!SRC_lib) {
+ SDL_ClearError();
+ return SDL_FALSE;
+ }
+
+ SRC_src_new = (SRC_STATE* (*)(int converter_type, int channels, int *error))SDL_LoadFunction(SRC_lib, "src_new");
+ SRC_src_process = (int (*)(SRC_STATE *state, SRC_DATA *data))SDL_LoadFunction(SRC_lib, "src_process");
+ SRC_src_reset = (int(*)(SRC_STATE *state))SDL_LoadFunction(SRC_lib, "src_reset");
+ SRC_src_delete = (SRC_STATE* (*)(SRC_STATE *state))SDL_LoadFunction(SRC_lib, "src_delete");
+ SRC_src_strerror = (const char* (*)(int error))SDL_LoadFunction(SRC_lib, "src_strerror");
+
+ if (!SRC_src_new || !SRC_src_process || !SRC_src_reset || !SRC_src_delete || !SRC_src_strerror) {
+ SDL_UnloadObject(SRC_lib);
+ SRC_lib = NULL;
+ return SDL_FALSE;
+ }
+#else
+ SRC_src_new = src_new;
+ SRC_src_process = src_process;
+ SRC_src_reset = src_reset;
+ SRC_src_delete = src_delete;
+ SRC_src_strerror = src_strerror;
+#endif
+
+ SRC_available = SDL_TRUE;
+ return SDL_TRUE;
+}
+
+static void
+UnloadLibSampleRate(void)
+{
+#ifdef SDL_LIBSAMPLERATE_DYNAMIC
+ if (SRC_lib != NULL) {
+ SDL_UnloadObject(SRC_lib);
+ }
+ SRC_lib = NULL;
+#endif
+
+ SRC_available = SDL_FALSE;
+ SRC_src_new = NULL;
+ SRC_src_process = NULL;
+ SRC_src_reset = NULL;
+ SRC_src_delete = NULL;
+ SRC_src_strerror = NULL;
+}
+#endif
+
+static SDL_AudioDevice *
+get_audio_device(SDL_AudioDeviceID id)
+{
+ id--;
+ if ((id >= SDL_arraysize(open_devices)) || (open_devices[id] == NULL)) {
+ SDL_SetError("Invalid audio device ID");
+ return NULL;
+ }
+
+ return open_devices[id];
+}
+
+
+/* stubs for audio drivers that don't need a specific entry point... */
+static void
+SDL_AudioDetectDevices_Default(void)
+{
+ /* you have to write your own implementation if these assertions fail. */
+ SDL_assert(current_audio.impl.OnlyHasDefaultOutputDevice);
+ SDL_assert(current_audio.impl.OnlyHasDefaultCaptureDevice || !current_audio.impl.HasCaptureSupport);
+
+ SDL_AddAudioDevice(SDL_FALSE, DEFAULT_OUTPUT_DEVNAME, (void *) ((size_t) 0x1));
+ if (current_audio.impl.HasCaptureSupport) {
+ SDL_AddAudioDevice(SDL_TRUE, DEFAULT_INPUT_DEVNAME, (void *) ((size_t) 0x2));
+ }
+}
+
+static void
+SDL_AudioThreadInit_Default(_THIS)
+{ /* no-op. */
+}
+
+static void
+SDL_AudioThreadDeinit_Default(_THIS)
+{ /* no-op. */
+}
+
+static void
+SDL_AudioBeginLoopIteration_Default(_THIS)
+{ /* no-op. */
+}
+
+static void
+SDL_AudioWaitDevice_Default(_THIS)
+{ /* no-op. */
+}
+
+static void
+SDL_AudioPlayDevice_Default(_THIS)
+{ /* no-op. */
+}
+
+static int
+SDL_AudioGetPendingBytes_Default(_THIS)
+{
+ return 0;
+}
+
+static Uint8 *
+SDL_AudioGetDeviceBuf_Default(_THIS)
+{
+ return NULL;
+}
+
+static int
+SDL_AudioCaptureFromDevice_Default(_THIS, void *buffer, int buflen)
+{
+ return -1; /* just fail immediately. */
+}
+
+static void
+SDL_AudioFlushCapture_Default(_THIS)
+{ /* no-op. */
+}
+
+static void
+SDL_AudioPrepareToClose_Default(_THIS)
+{ /* no-op. */
+}
+
+static void
+SDL_AudioCloseDevice_Default(_THIS)
+{ /* no-op. */
+}
+
+static void
+SDL_AudioDeinitialize_Default(void)
+{ /* no-op. */
+}
+
+static void
+SDL_AudioFreeDeviceHandle_Default(void *handle)
+{ /* no-op. */
+}
+
+
+static int
+SDL_AudioOpenDevice_Default(_THIS, void *handle, const char *devname, int iscapture)
+{
+ return SDL_Unsupported();
+}
+
+static SDL_INLINE SDL_bool
+is_in_audio_device_thread(SDL_AudioDevice * device)
+{
+ /* The device thread locks the same mutex, but not through the public API.
+ This check is in case the application, in the audio callback,
+ tries to lock the thread that we've already locked from the
+ device thread...just in case we only have non-recursive mutexes. */
+ if (device->thread && (SDL_ThreadID() == device->threadid)) {
+ return SDL_TRUE;
+ }
+
+ return SDL_FALSE;
+}
+
+static void
+SDL_AudioLockDevice_Default(SDL_AudioDevice * device)
+{
+ if (!is_in_audio_device_thread(device)) {
+ SDL_LockMutex(device->mixer_lock);
+ }
+}
+
+static void
+SDL_AudioUnlockDevice_Default(SDL_AudioDevice * device)
+{
+ if (!is_in_audio_device_thread(device)) {
+ SDL_UnlockMutex(device->mixer_lock);
+ }
+}
+
+static void
+SDL_AudioLockOrUnlockDeviceWithNoMixerLock(SDL_AudioDevice * device)
+{
+}
+
+static void
+finish_audio_entry_points_init(void)
+{
+ /*
+ * Fill in stub functions for unused driver entry points. This lets us
+ * blindly call them without having to check for validity first.
+ */
+
+ if (current_audio.impl.SkipMixerLock) {
+ if (current_audio.impl.LockDevice == NULL) {
+ current_audio.impl.LockDevice = SDL_AudioLockOrUnlockDeviceWithNoMixerLock;
+ }
+ if (current_audio.impl.UnlockDevice == NULL) {
+ current_audio.impl.UnlockDevice = SDL_AudioLockOrUnlockDeviceWithNoMixerLock;
+ }
+ }
+
+#define FILL_STUB(x) \
+ if (current_audio.impl.x == NULL) { \
+ current_audio.impl.x = SDL_Audio##x##_Default; \
+ }
+ FILL_STUB(DetectDevices);
+ FILL_STUB(OpenDevice);
+ FILL_STUB(ThreadInit);
+ FILL_STUB(ThreadDeinit);
+ FILL_STUB(BeginLoopIteration);
+ FILL_STUB(WaitDevice);
+ FILL_STUB(PlayDevice);
+ FILL_STUB(GetPendingBytes);
+ FILL_STUB(GetDeviceBuf);
+ FILL_STUB(CaptureFromDevice);
+ FILL_STUB(FlushCapture);
+ FILL_STUB(PrepareToClose);
+ FILL_STUB(CloseDevice);
+ FILL_STUB(LockDevice);
+ FILL_STUB(UnlockDevice);
+ FILL_STUB(FreeDeviceHandle);
+ FILL_STUB(Deinitialize);
+#undef FILL_STUB
+}
+
+
+/* device hotplug support... */
+
+static int
+add_audio_device(const char *name, void *handle, SDL_AudioDeviceItem **devices, int *devCount)
+{
+ int retval = -1;
+ const size_t size = sizeof (SDL_AudioDeviceItem) + SDL_strlen(name) + 1;
+ SDL_AudioDeviceItem *item = (SDL_AudioDeviceItem *) SDL_malloc(size);
+ if (item == NULL) {
+ return -1;
+ }
+
+ SDL_assert(handle != NULL); /* we reserve NULL, audio backends can't use it. */
+
+ item->handle = handle;
+ SDL_strlcpy(item->name, name, size - sizeof (SDL_AudioDeviceItem));
+
+ SDL_LockMutex(current_audio.detectionLock);
+ item->next = *devices;
+ *devices = item;
+ retval = (*devCount)++;
+ SDL_UnlockMutex(current_audio.detectionLock);
+
+ return retval;
+}
+
+static SDL_INLINE int
+add_capture_device(const char *name, void *handle)
+{
+ SDL_assert(current_audio.impl.HasCaptureSupport);
+ return add_audio_device(name, handle, &current_audio.inputDevices, &current_audio.inputDeviceCount);
+}
+
+static SDL_INLINE int
+add_output_device(const char *name, void *handle)
+{
+ return add_audio_device(name, handle, &current_audio.outputDevices, &current_audio.outputDeviceCount);
+}
+
+static void
+free_device_list(SDL_AudioDeviceItem **devices, int *devCount)
+{
+ SDL_AudioDeviceItem *item, *next;
+ for (item = *devices; item != NULL; item = next) {
+ next = item->next;
+ if (item->handle != NULL) {
+ current_audio.impl.FreeDeviceHandle(item->handle);
+ }
+ SDL_free(item);
+ }
+ *devices = NULL;
+ *devCount = 0;
+}
+
+
+/* The audio backends call this when a new device is plugged in. */
+void
+SDL_AddAudioDevice(const int iscapture, const char *name, void *handle)
+{
+ const int device_index = iscapture ? add_capture_device(name, handle) : add_output_device(name, handle);
+ if (device_index != -1) {
+ /* Post the event, if desired */
+ if (SDL_GetEventState(SDL_AUDIODEVICEADDED) == SDL_ENABLE) {
+ SDL_Event event;
+ SDL_zero(event);
+ event.adevice.type = SDL_AUDIODEVICEADDED;
+ event.adevice.which = device_index;
+ event.adevice.iscapture = iscapture;
+ SDL_PushEvent(&event);
+ }
+ }
+}
+
+/* The audio backends call this when a currently-opened device is lost. */
+void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device)
+{
+ SDL_assert(get_audio_device(device->id) == device);
+
+ if (!SDL_AtomicGet(&device->enabled)) {
+ return;
+ }
+
+ /* Ends the audio callback and mark the device as STOPPED, but the
+ app still needs to close the device to free resources. */
+ current_audio.impl.LockDevice(device);
+ SDL_AtomicSet(&device->enabled, 0);
+ current_audio.impl.UnlockDevice(device);
+
+ /* Post the event, if desired */
+ if (SDL_GetEventState(SDL_AUDIODEVICEREMOVED) == SDL_ENABLE) {
+ SDL_Event event;
+ SDL_zero(event);
+ event.adevice.type = SDL_AUDIODEVICEREMOVED;
+ event.adevice.which = device->id;
+ event.adevice.iscapture = device->iscapture ? 1 : 0;
+ SDL_PushEvent(&event);
+ }
+}
+
+static void
+mark_device_removed(void *handle, SDL_AudioDeviceItem *devices, SDL_bool *removedFlag)
+{
+ SDL_AudioDeviceItem *item;
+ SDL_assert(handle != NULL);
+ for (item = devices; item != NULL; item = item->next) {
+ if (item->handle == handle) {
+ item->handle = NULL;
+ *removedFlag = SDL_TRUE;
+ return;
+ }
+ }
+}
+
+/* The audio backends call this when a device is removed from the system. */
+void
+SDL_RemoveAudioDevice(const int iscapture, void *handle)
+{
+ int device_index;
+ SDL_AudioDevice *device = NULL;
+
+ SDL_LockMutex(current_audio.detectionLock);
+ if (iscapture) {
+ mark_device_removed(handle, current_audio.inputDevices, &current_audio.captureDevicesRemoved);
+ } else {
+ mark_device_removed(handle, current_audio.outputDevices, &current_audio.outputDevicesRemoved);
+ }
+ for (device_index = 0; device_index < SDL_arraysize(open_devices); device_index++)
+ {
+ device = open_devices[device_index];
+ if (device != NULL && device->handle == handle)
+ {
+ SDL_OpenedAudioDeviceDisconnected(device);
+ break;
+ }
+ }
+ SDL_UnlockMutex(current_audio.detectionLock);
+
+ current_audio.impl.FreeDeviceHandle(handle);
+}
+
+
+
+/* buffer queueing support... */
+
+static void SDLCALL
+SDL_BufferQueueDrainCallback(void *userdata, Uint8 *stream, int len)
+{
+ /* this function always holds the mixer lock before being called. */
+ SDL_AudioDevice *device = (SDL_AudioDevice *) userdata;
+ size_t dequeued;
+
+ SDL_assert(device != NULL); /* this shouldn't ever happen, right?! */
+ SDL_assert(!device->iscapture); /* this shouldn't ever happen, right?! */
+ SDL_assert(len >= 0); /* this shouldn't ever happen, right?! */
+
+ dequeued = SDL_ReadFromDataQueue(device->buffer_queue, stream, len);
+ stream += dequeued;
+ len -= (int) dequeued;
+
+ if (len > 0) { /* fill any remaining space in the stream with silence. */
+ SDL_assert(SDL_CountDataQueue(device->buffer_queue) == 0);
+ SDL_memset(stream, device->spec.silence, len);
+ }
+}
+
+static void SDLCALL
+SDL_BufferQueueFillCallback(void *userdata, Uint8 *stream, int len)
+{
+ /* this function always holds the mixer lock before being called. */
+ SDL_AudioDevice *device = (SDL_AudioDevice *) userdata;
+
+ SDL_assert(device != NULL); /* this shouldn't ever happen, right?! */
+ SDL_assert(device->iscapture); /* this shouldn't ever happen, right?! */
+ SDL_assert(len >= 0); /* this shouldn't ever happen, right?! */
+
+ /* note that if this needs to allocate more space and run out of memory,
+ we have no choice but to quietly drop the data and hope it works out
+ later, but you probably have bigger problems in this case anyhow. */
+ SDL_WriteToDataQueue(device->buffer_queue, stream, len);
+}
+
+int
+SDL_QueueAudio(SDL_AudioDeviceID devid, const void *data, Uint32 len)
+{
+ SDL_AudioDevice *device = get_audio_device(devid);
+ int rc = 0;
+
+ if (!device) {
+ return -1; /* get_audio_device() will have set the error state */
+ } else if (device->iscapture) {
+ return SDL_SetError("This is a capture device, queueing not allowed");
+ } else if (device->callbackspec.callback != SDL_BufferQueueDrainCallback) {
+ return SDL_SetError("Audio device has a callback, queueing not allowed");
+ }
+
+ if (len > 0) {
+ current_audio.impl.LockDevice(device);
+ rc = SDL_WriteToDataQueue(device->buffer_queue, data, len);
+ current_audio.impl.UnlockDevice(device);
+ }
+
+ return rc;
+}
+
+Uint32
+SDL_DequeueAudio(SDL_AudioDeviceID devid, void *data, Uint32 len)
+{
+ SDL_AudioDevice *device = get_audio_device(devid);
+ Uint32 rc;
+
+ if ( (len == 0) || /* nothing to do? */
+ (!device) || /* called with bogus device id */
+ (!device->iscapture) || /* playback devices can't dequeue */
+ (device->callbackspec.callback != SDL_BufferQueueFillCallback) ) { /* not set for queueing */
+ return 0; /* just report zero bytes dequeued. */
+ }
+
+ current_audio.impl.LockDevice(device);
+ rc = (Uint32) SDL_ReadFromDataQueue(device->buffer_queue, data, len);
+ current_audio.impl.UnlockDevice(device);
+ return rc;
+}
+
+Uint32
+SDL_GetQueuedAudioSize(SDL_AudioDeviceID devid)
+{
+ Uint32 retval = 0;
+ SDL_AudioDevice *device = get_audio_device(devid);
+
+ if (!device) {
+ return 0;
+ }
+
+ /* Nothing to do unless we're set up for queueing. */
+ if (device->callbackspec.callback == SDL_BufferQueueDrainCallback) {
+ current_audio.impl.LockDevice(device);
+ retval = ((Uint32) SDL_CountDataQueue(device->buffer_queue)) + current_audio.impl.GetPendingBytes(device);
+ current_audio.impl.UnlockDevice(device);
+ } else if (device->callbackspec.callback == SDL_BufferQueueFillCallback) {
+ current_audio.impl.LockDevice(device);
+ retval = (Uint32) SDL_CountDataQueue(device->buffer_queue);
+ current_audio.impl.UnlockDevice(device);
+ }
+
+ return retval;
+}
+
+void
+SDL_ClearQueuedAudio(SDL_AudioDeviceID devid)
+{
+ SDL_AudioDevice *device = get_audio_device(devid);
+
+ if (!device) {
+ return; /* nothing to do. */
+ }
+
+ /* Blank out the device and release the mutex. Free it afterwards. */
+ current_audio.impl.LockDevice(device);
+
+ /* Keep up to two packets in the pool to reduce future malloc pressure. */
+ SDL_ClearDataQueue(device->buffer_queue, SDL_AUDIOBUFFERQUEUE_PACKETLEN * 2);
+
+ current_audio.impl.UnlockDevice(device);
+}
+
+
+/* The general mixing thread function */
+static int SDLCALL
+SDL_RunAudio(void *devicep)
+{
+ SDL_AudioDevice *device = (SDL_AudioDevice *) devicep;
+ void *udata = device->callbackspec.userdata;
+ SDL_AudioCallback callback = device->callbackspec.callback;
+ int data_len = 0;
+ Uint8 *data;
+
+ SDL_assert(!device->iscapture);
+
+ /* The audio mixing is always a high priority thread */
+ SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
+
+ /* Perform any thread setup */
+ device->threadid = SDL_ThreadID();
+ current_audio.impl.ThreadInit(device);
+
+ /* Loop, filling the audio buffers */
+ while (!SDL_AtomicGet(&device->shutdown)) {
+ current_audio.impl.BeginLoopIteration(device);
+ data_len = device->callbackspec.size;
+
+ /* Fill the current buffer with sound */
+ if (!device->stream && SDL_AtomicGet(&device->enabled)) {
+ SDL_assert(data_len == device->spec.size);
+ data = current_audio.impl.GetDeviceBuf(device);
+ } else {
+ /* if the device isn't enabled, we still write to the
+ work_buffer, so the app's callback will fire with
+ a regular frequency, in case they depend on that
+ for timing or progress. They can use hotplug
+ now to know if the device failed.
+ Streaming playback uses work_buffer, too. */
+ data = NULL;
+ }
+
+ if (data == NULL) {
+ data = device->work_buffer;
+ }
+
+ /* !!! FIXME: this should be LockDevice. */
+ SDL_LockMutex(device->mixer_lock);
+ if (SDL_AtomicGet(&device->paused)) {
+ SDL_memset(data, device->spec.silence, data_len);
+ } else {
+ callback(udata, data, data_len);
+ }
+ SDL_UnlockMutex(device->mixer_lock);
+
+ if (device->stream) {
+ /* Stream available audio to device, converting/resampling. */
+ /* if this fails...oh well. We'll play silence here. */
+ SDL_AudioStreamPut(device->stream, data, data_len);
+
+ while (SDL_AudioStreamAvailable(device->stream) >= ((int) device->spec.size)) {
+ int got;
+ data = SDL_AtomicGet(&device->enabled) ? current_audio.impl.GetDeviceBuf(device) : NULL;
+ got = SDL_AudioStreamGet(device->stream, data ? data : device->work_buffer, device->spec.size);
+ SDL_assert((got < 0) || (got == device->spec.size));
+
+ if (data == NULL) { /* device is having issues... */
+ const Uint32 delay = ((device->spec.samples * 1000) / device->spec.freq);
+ SDL_Delay(delay); /* wait for as long as this buffer would have played. Maybe device recovers later? */
+ } else {
+ if (got != device->spec.size) {
+ SDL_memset(data, device->spec.silence, device->spec.size);
+ }
+ current_audio.impl.PlayDevice(device);
+ current_audio.impl.WaitDevice(device);
+ }
+ }
+ } else if (data == device->work_buffer) {
+ /* nothing to do; pause like we queued a buffer to play. */
+ const Uint32 delay = ((device->spec.samples * 1000) / device->spec.freq);
+ SDL_Delay(delay);
+ } else { /* writing directly to the device. */
+ /* queue this buffer and wait for it to finish playing. */
+ current_audio.impl.PlayDevice(device);
+ current_audio.impl.WaitDevice(device);
+ }
+ }
+
+ current_audio.impl.PrepareToClose(device);
+
+ /* Wait for the audio to drain. */
+ SDL_Delay(((device->spec.samples * 1000) / device->spec.freq) * 2);
+
+ current_audio.impl.ThreadDeinit(device);
+
+ return 0;
+}
+
+/* !!! FIXME: this needs to deal with device spec changes. */
+/* The general capture thread function */
+static int SDLCALL
+SDL_CaptureAudio(void *devicep)
+{
+ SDL_AudioDevice *device = (SDL_AudioDevice *) devicep;
+ const int silence = (int) device->spec.silence;
+ const Uint32 delay = ((device->spec.samples * 1000) / device->spec.freq);
+ const int data_len = device->spec.size;
+ Uint8 *data;
+ void *udata = device->callbackspec.userdata;
+ SDL_AudioCallback callback = device->callbackspec.callback;
+
+ SDL_assert(device->iscapture);
+
+ /* The audio mixing is always a high priority thread */
+ SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
+
+ /* Perform any thread setup */
+ device->threadid = SDL_ThreadID();
+ current_audio.impl.ThreadInit(device);
+
+ /* Loop, filling the audio buffers */
+ while (!SDL_AtomicGet(&device->shutdown)) {
+ int still_need;
+ Uint8 *ptr;
+
+ current_audio.impl.BeginLoopIteration(device);
+
+ if (SDL_AtomicGet(&device->paused)) {
+ SDL_Delay(delay); /* just so we don't cook the CPU. */
+ if (device->stream) {
+ SDL_AudioStreamClear(device->stream);
+ }
+ current_audio.impl.FlushCapture(device); /* dump anything pending. */
+ continue;
+ }
+
+ /* Fill the current buffer with sound */
+ still_need = data_len;
+
+ /* Use the work_buffer to hold data read from the device. */
+ data = device->work_buffer;
+ SDL_assert(data != NULL);
+
+ ptr = data;
+
+ /* We still read from the device when "paused" to keep the state sane,
+ and block when there isn't data so this thread isn't eating CPU.
+ But we don't process it further or call the app's callback. */
+
+ if (!SDL_AtomicGet(&device->enabled)) {
+ SDL_Delay(delay); /* try to keep callback firing at normal pace. */
+ } else {
+ while (still_need > 0) {
+ const int rc = current_audio.impl.CaptureFromDevice(device, ptr, still_need);
+ SDL_assert(rc <= still_need); /* device should not overflow buffer. :) */
+ if (rc > 0) {
+ still_need -= rc;
+ ptr += rc;
+ } else { /* uhoh, device failed for some reason! */
+ SDL_OpenedAudioDeviceDisconnected(device);
+ break;
+ }
+ }
+ }
+
+ if (still_need > 0) {
+ /* Keep any data we already read, silence the rest. */
+ SDL_memset(ptr, silence, still_need);
+ }
+
+ if (device->stream) {
+ /* if this fails...oh well. */
+ SDL_AudioStreamPut(device->stream, data, data_len);
+
+ while (SDL_AudioStreamAvailable(device->stream) >= ((int) device->callbackspec.size)) {
+ const int got = SDL_AudioStreamGet(device->stream, device->work_buffer, device->callbackspec.size);
+ SDL_assert((got < 0) || (got == device->callbackspec.size));
+ if (got != device->callbackspec.size) {
+ SDL_memset(device->work_buffer, device->spec.silence, device->callbackspec.size);
+ }
+
+ /* !!! FIXME: this should be LockDevice. */
+ SDL_LockMutex(device->mixer_lock);
+ if (!SDL_AtomicGet(&device->paused)) {
+ callback(udata, device->work_buffer, device->callbackspec.size);
+ }
+ SDL_UnlockMutex(device->mixer_lock);
+ }
+ } else { /* feeding user callback directly without streaming. */
+ /* !!! FIXME: this should be LockDevice. */
+ SDL_LockMutex(device->mixer_lock);
+ if (!SDL_AtomicGet(&device->paused)) {
+ callback(udata, data, device->callbackspec.size);
+ }
+ SDL_UnlockMutex(device->mixer_lock);
+ }
+ }
+
+ current_audio.impl.FlushCapture(device);
+
+ current_audio.impl.ThreadDeinit(device);
+
+ return 0;
+}
+
+
+static SDL_AudioFormat
+SDL_ParseAudioFormat(const char *string)
+{
+#define CHECK_FMT_STRING(x) if (SDL_strcmp(string, #x) == 0) return AUDIO_##x
+ CHECK_FMT_STRING(U8);
+ CHECK_FMT_STRING(S8);
+ CHECK_FMT_STRING(U16LSB);
+ CHECK_FMT_STRING(S16LSB);
+ CHECK_FMT_STRING(U16MSB);
+ CHECK_FMT_STRING(S16MSB);
+ CHECK_FMT_STRING(U16SYS);
+ CHECK_FMT_STRING(S16SYS);
+ CHECK_FMT_STRING(U16);
+ CHECK_FMT_STRING(S16);
+ CHECK_FMT_STRING(S32LSB);
+ CHECK_FMT_STRING(S32MSB);
+ CHECK_FMT_STRING(S32SYS);
+ CHECK_FMT_STRING(S32);
+ CHECK_FMT_STRING(F32LSB);
+ CHECK_FMT_STRING(F32MSB);
+ CHECK_FMT_STRING(F32SYS);
+ CHECK_FMT_STRING(F32);
+#undef CHECK_FMT_STRING
+ return 0;
+}
+
+int
+SDL_GetNumAudioDrivers(void)
+{
+ return SDL_arraysize(bootstrap) - 1;
+}
+
+const char *
+SDL_GetAudioDriver(int index)
+{
+ if (index >= 0 && index < SDL_GetNumAudioDrivers()) {
+ return bootstrap[index]->name;
+ }
+ return NULL;
+}
+
+int
+SDL_AudioInit(const char *driver_name)
+{
+ int i = 0;
+ int initialized = 0;
+ int tried_to_init = 0;
+
+ if (SDL_WasInit(SDL_INIT_AUDIO)) {
+ SDL_AudioQuit(); /* shutdown driver if already running. */
+ }
+
+ SDL_zero(current_audio);
+ SDL_zero(open_devices);
+
+ /* Select the proper audio driver */
+ if (driver_name == NULL) {
+ driver_name = SDL_getenv("SDL_AUDIODRIVER");
+ }
+
+ for (i = 0; (!initialized) && (bootstrap[i]); ++i) {
+ /* make sure we should even try this driver before doing so... */
+ const AudioBootStrap *backend = bootstrap[i];
+ if ((driver_name && (SDL_strncasecmp(backend->name, driver_name, SDL_strlen(driver_name)) != 0)) ||
+ (!driver_name && backend->demand_only)) {
+ continue;
+ }
+
+ tried_to_init = 1;
+ SDL_zero(current_audio);
+ current_audio.name = backend->name;
+ current_audio.desc = backend->desc;
+ initialized = backend->init(&current_audio.impl);
+ }
+
+ if (!initialized) {
+ /* specific drivers will set the error message if they fail... */
+ if (!tried_to_init) {
+ if (driver_name) {
+ SDL_SetError("Audio target '%s' not available", driver_name);
+ } else {
+ SDL_SetError("No available audio device");
+ }
+ }
+
+ SDL_zero(current_audio);
+ return -1; /* No driver was available, so fail. */
+ }
+
+ current_audio.detectionLock = SDL_CreateMutex();
+
+ finish_audio_entry_points_init();
+
+ /* Make sure we have a list of devices available at startup. */
+ current_audio.impl.DetectDevices();
+
+#ifdef HAVE_LIBSAMPLERATE_H
+ LoadLibSampleRate();
+#endif
+
+ return 0;
+}
+
+/*
+ * Get the current audio driver name
+ */
+const char *
+SDL_GetCurrentAudioDriver()
+{
+ return current_audio.name;
+}
+
+/* Clean out devices that we've removed but had to keep around for stability. */
+static void
+clean_out_device_list(SDL_AudioDeviceItem **devices, int *devCount, SDL_bool *removedFlag)
+{
+ SDL_AudioDeviceItem *item = *devices;
+ SDL_AudioDeviceItem *prev = NULL;
+ int total = 0;
+
+ while (item) {
+ SDL_AudioDeviceItem *next = item->next;
+ if (item->handle != NULL) {
+ total++;
+ prev = item;
+ } else {
+ if (prev) {
+ prev->next = next;
+ } else {
+ *devices = next;
+ }
+ SDL_free(item);
+ }
+ item = next;
+ }
+
+ *devCount = total;
+ *removedFlag = SDL_FALSE;
+}
+
+
+int
+SDL_GetNumAudioDevices(int iscapture)
+{
+ int retval = 0;
+
+ if (!SDL_WasInit(SDL_INIT_AUDIO)) {
+ return -1;
+ }
+
+ SDL_LockMutex(current_audio.detectionLock);
+ if (iscapture && current_audio.captureDevicesRemoved) {
+ clean_out_device_list(&current_audio.inputDevices, &current_audio.inputDeviceCount, &current_audio.captureDevicesRemoved);
+ }
+
+ if (!iscapture && current_audio.outputDevicesRemoved) {
+ clean_out_device_list(&current_audio.outputDevices, &current_audio.outputDeviceCount, &current_audio.outputDevicesRemoved);
+ current_audio.outputDevicesRemoved = SDL_FALSE;
+ }
+
+ retval = iscapture ? current_audio.inputDeviceCount : current_audio.outputDeviceCount;
+ SDL_UnlockMutex(current_audio.detectionLock);
+
+ return retval;
+}
+
+
+const char *
+SDL_GetAudioDeviceName(int index, int iscapture)
+{
+ const char *retval = NULL;
+
+ if (!SDL_WasInit(SDL_INIT_AUDIO)) {
+ SDL_SetError("Audio subsystem is not initialized");
+ return NULL;
+ }
+
+ if ((iscapture) && (!current_audio.impl.HasCaptureSupport)) {
+ SDL_SetError("No capture support");
+ return NULL;
+ }
+
+ if (index >= 0) {
+ SDL_AudioDeviceItem *item;
+ int i;
+
+ SDL_LockMutex(current_audio.detectionLock);
+ item = iscapture ? current_audio.inputDevices : current_audio.outputDevices;
+ i = iscapture ? current_audio.inputDeviceCount : current_audio.outputDeviceCount;
+ if (index < i) {
+ for (i--; i > index; i--, item = item->next) {
+ SDL_assert(item != NULL);
+ }
+ SDL_assert(item != NULL);
+ retval = item->name;
+ }
+ SDL_UnlockMutex(current_audio.detectionLock);
+ }
+
+ if (retval == NULL) {
+ SDL_SetError("No such device");
+ }
+
+ return retval;
+}
+
+
+static void
+close_audio_device(SDL_AudioDevice * device)
+{
+ if (!device) {
+ return;
+ }
+
+ if (device->id > 0) {
+ SDL_AudioDevice *opendev = open_devices[device->id - 1];
+ SDL_assert((opendev == device) || (opendev == NULL));
+ if (opendev == device) {
+ open_devices[device->id - 1] = NULL;
+ }
+ }
+
+ SDL_AtomicSet(&device->shutdown, 1);
+ SDL_AtomicSet(&device->enabled, 0);
+ if (device->thread != NULL) {
+ SDL_WaitThread(device->thread, NULL);
+ }
+ if (device->mixer_lock != NULL) {
+ SDL_DestroyMutex(device->mixer_lock);
+ }
+
+ SDL_free(device->work_buffer);
+ SDL_FreeAudioStream(device->stream);
+
+ if (device->hidden != NULL) {
+ current_audio.impl.CloseDevice(device);
+ }
+
+ SDL_FreeDataQueue(device->buffer_queue);
+
+ SDL_free(device);
+}
+
+
+/*
+ * Sanity check desired AudioSpec for SDL_OpenAudio() in (orig).
+ * Fills in a sanitized copy in (prepared).
+ * Returns non-zero if okay, zero on fatal parameters in (orig).
+ */
+static int
+prepare_audiospec(const SDL_AudioSpec * orig, SDL_AudioSpec * prepared)
+{
+ SDL_memcpy(prepared, orig, sizeof(SDL_AudioSpec));
+
+ if (orig->freq == 0) {
+ const char *env = SDL_getenv("SDL_AUDIO_FREQUENCY");
+ if ((!env) || ((prepared->freq = SDL_atoi(env)) == 0)) {
+ prepared->freq = 22050; /* a reasonable default */
+ }
+ }
+
+ if (orig->format == 0) {
+ const char *env = SDL_getenv("SDL_AUDIO_FORMAT");
+ if ((!env) || ((prepared->format = SDL_ParseAudioFormat(env)) == 0)) {
+ prepared->format = AUDIO_S16; /* a reasonable default */
+ }
+ }
+
+ switch (orig->channels) {
+ case 0:{
+ const char *env = SDL_getenv("SDL_AUDIO_CHANNELS");
+ if ((!env) || ((prepared->channels = (Uint8) SDL_atoi(env)) == 0)) {
+ prepared->channels = 2; /* a reasonable default */
+ }
+ break;
+ }
+ case 1: /* Mono */
+ case 2: /* Stereo */
+ case 4: /* surround */
+ case 6: /* surround with center and lfe */
+ break;
+ default:
+ SDL_SetError("Unsupported number of audio channels.");
+ return 0;
+ }
+
+ if (orig->samples == 0) {
+ const char *env = SDL_getenv("SDL_AUDIO_SAMPLES");
+ if ((!env) || ((prepared->samples = (Uint16) SDL_atoi(env)) == 0)) {
+ /* Pick a default of ~46 ms at desired frequency */
+ /* !!! FIXME: remove this when the non-Po2 resampling is in. */
+ const int samples = (prepared->freq / 1000) * 46;
+ int power2 = 1;
+ while (power2 < samples) {
+ power2 *= 2;
+ }
+ prepared->samples = power2;
+ }
+ }
+
+ /* Calculate the silence and size of the audio specification */
+ SDL_CalculateAudioSpec(prepared);
+
+ return 1;
+}
+
+static SDL_AudioDeviceID
+open_audio_device(const char *devname, int iscapture,
+ const SDL_AudioSpec * desired, SDL_AudioSpec * obtained,
+ int allowed_changes, int min_id)
+{
+ const SDL_bool is_internal_thread = (desired->callback == NULL);
+ SDL_AudioDeviceID id = 0;
+ SDL_AudioSpec _obtained;
+ SDL_AudioDevice *device;
+ SDL_bool build_stream;
+ void *handle = NULL;
+ int i = 0;
+
+ if (!SDL_WasInit(SDL_INIT_AUDIO)) {
+ SDL_SetError("Audio subsystem is not initialized");
+ return 0;
+ }
+
+ if ((iscapture) && (!current_audio.impl.HasCaptureSupport)) {
+ SDL_SetError("No capture support");
+ return 0;
+ }
+
+ /* !!! FIXME: there is a race condition here if two devices open from two threads at once. */
+ /* Find an available device ID... */
+ for (id = min_id - 1; id < SDL_arraysize(open_devices); id++) {
+ if (open_devices[id] == NULL) {
+ break;
+ }
+ }
+
+ if (id == SDL_arraysize(open_devices)) {
+ SDL_SetError("Too many open audio devices");
+ return 0;
+ }
+
+ if (!obtained) {
+ obtained = &_obtained;
+ }
+ if (!prepare_audiospec(desired, obtained)) {
+ return 0;
+ }
+
+ /* If app doesn't care about a specific device, let the user override. */
+ if (devname == NULL) {
+ devname = SDL_getenv("SDL_AUDIO_DEVICE_NAME");
+ }
+
+ /*
+ * Catch device names at the high level for the simple case...
+ * This lets us have a basic "device enumeration" for systems that
+ * don't have multiple devices, but makes sure the device name is
+ * always NULL when it hits the low level.
+ *
+ * Also make sure that the simple case prevents multiple simultaneous
+ * opens of the default system device.
+ */
+
+ if ((iscapture) && (current_audio.impl.OnlyHasDefaultCaptureDevice)) {
+ if ((devname) && (SDL_strcmp(devname, DEFAULT_INPUT_DEVNAME) != 0)) {
+ SDL_SetError("No such device");
+ return 0;
+ }
+ devname = NULL;
+
+ for (i = 0; i < SDL_arraysize(open_devices); i++) {
+ if ((open_devices[i]) && (open_devices[i]->iscapture)) {
+ SDL_SetError("Audio device already open");
+ return 0;
+ }
+ }
+ } else if ((!iscapture) && (current_audio.impl.OnlyHasDefaultOutputDevice)) {
+ if ((devname) && (SDL_strcmp(devname, DEFAULT_OUTPUT_DEVNAME) != 0)) {
+ SDL_SetError("No such device");
+ return 0;
+ }
+ devname = NULL;
+
+ for (i = 0; i < SDL_arraysize(open_devices); i++) {
+ if ((open_devices[i]) && (!open_devices[i]->iscapture)) {
+ SDL_SetError("Audio device already open");
+ return 0;
+ }
+ }
+ } else if (devname != NULL) {
+ /* if the app specifies an exact string, we can pass the backend
+ an actual device handle thingey, which saves them the effort of
+ figuring out what device this was (such as, reenumerating
+ everything again to find the matching human-readable name).
+ It might still need to open a device based on the string for,
+ say, a network audio server, but this optimizes some cases. */
+ SDL_AudioDeviceItem *item;
+ SDL_LockMutex(current_audio.detectionLock);
+ for (item = iscapture ? current_audio.inputDevices : current_audio.outputDevices; item; item = item->next) {
+ if ((item->handle != NULL) && (SDL_strcmp(item->name, devname) == 0)) {
+ handle = item->handle;
+ break;
+ }
+ }
+ SDL_UnlockMutex(current_audio.detectionLock);
+ }
+
+ if (!current_audio.impl.AllowsArbitraryDeviceNames) {
+ /* has to be in our device list, or the default device. */
+ if ((handle == NULL) && (devname != NULL)) {
+ SDL_SetError("No such device.");
+ return 0;
+ }
+ }
+
+ device = (SDL_AudioDevice *) SDL_calloc(1, sizeof (SDL_AudioDevice));
+ if (device == NULL) {
+ SDL_OutOfMemory();
+ return 0;
+ }
+ device->id = id + 1;
+ device->spec = *obtained;
+ device->iscapture = iscapture ? SDL_TRUE : SDL_FALSE;
+ device->handle = handle;
+
+ SDL_AtomicSet(&device->shutdown, 0); /* just in case. */
+ SDL_AtomicSet(&device->paused, 1);
+ SDL_AtomicSet(&device->enabled, 1);
+
+ /* Create a mutex for locking the sound buffers */
+ if (!current_audio.impl.SkipMixerLock) {
+ device->mixer_lock = SDL_CreateMutex();
+ if (device->mixer_lock == NULL) {
+ close_audio_device(device);
+ SDL_SetError("Couldn't create mixer lock");
+ return 0;
+ }
+ }
+
+ if (current_audio.impl.OpenDevice(device, handle, devname, iscapture) < 0) {
+ close_audio_device(device);
+ return 0;
+ }
+
+ /* if your target really doesn't need it, set it to 0x1 or something. */
+ /* otherwise, close_audio_device() won't call impl.CloseDevice(). */
+ SDL_assert(device->hidden != NULL);
+
+ /* See if we need to do any conversion */
+ build_stream = SDL_FALSE;
+ if (obtained->freq != device->spec.freq) {
+ if (allowed_changes & SDL_AUDIO_ALLOW_FREQUENCY_CHANGE) {
+ obtained->freq = device->spec.freq;
+ } else {
+ build_stream = SDL_TRUE;
+ }
+ }
+ if (obtained->format != device->spec.format) {
+ if (allowed_changes & SDL_AUDIO_ALLOW_FORMAT_CHANGE) {
+ obtained->format = device->spec.format;
+ } else {
+ build_stream = SDL_TRUE;
+ }
+ }
+ if (obtained->channels != device->spec.channels) {
+ if (allowed_changes & SDL_AUDIO_ALLOW_CHANNELS_CHANGE) {
+ obtained->channels = device->spec.channels;
+ } else {
+ build_stream = SDL_TRUE;
+ }
+ }
+
+ /* !!! FIXME in 2.1: add SDL_AUDIO_ALLOW_SAMPLES_CHANGE flag?
+ As of 2.0.6, we will build a stream to buffer the difference between
+ what the app wants to feed and the device wants to eat, so everyone
+ gets their way. In prior releases, SDL would force the callback to
+ feed at the rate the device requested, adjusted for resampling.
+ */
+ if (device->spec.samples != obtained->samples) {
+ build_stream = SDL_TRUE;
+ }
+
+ SDL_CalculateAudioSpec(obtained); /* recalc after possible changes. */
+
+ device->callbackspec = *obtained;
+
+ if (build_stream) {
+ if (iscapture) {
+ device->stream = SDL_NewAudioStream(device->spec.format,
+ device->spec.channels, device->spec.freq,
+ obtained->format, obtained->channels, obtained->freq);
+ } else {
+ device->stream = SDL_NewAudioStream(obtained->format, obtained->channels,
+ obtained->freq, device->spec.format,
+ device->spec.channels, device->spec.freq);
+ }
+
+ if (!device->stream) {
+ close_audio_device(device);
+ return 0;
+ }
+ }
+
+ if (device->spec.callback == NULL) { /* use buffer queueing? */
+ /* pool a few packets to start. Enough for two callbacks. */
+ device->buffer_queue = SDL_NewDataQueue(SDL_AUDIOBUFFERQUEUE_PACKETLEN, obtained->size * 2);
+ if (!device->buffer_queue) {
+ close_audio_device(device);
+ SDL_SetError("Couldn't create audio buffer queue");
+ return 0;
+ }
+ device->callbackspec.callback = iscapture ? SDL_BufferQueueFillCallback : SDL_BufferQueueDrainCallback;
+ device->callbackspec.userdata = device;
+ }
+
+ /* Allocate a scratch audio buffer */
+ device->work_buffer_len = build_stream ? device->callbackspec.size : 0;
+ if (device->spec.size > device->work_buffer_len) {
+ device->work_buffer_len = device->spec.size;
+ }
+ SDL_assert(device->work_buffer_len > 0);
+
+ device->work_buffer = (Uint8 *) SDL_malloc(device->work_buffer_len);
+ if (device->work_buffer == NULL) {
+ close_audio_device(device);
+ SDL_OutOfMemory();
+ return 0;
+ }
+
+ open_devices[id] = device; /* add it to our list of open devices. */
+
+ /* Start the audio thread if necessary */
+ if (!current_audio.impl.ProvidesOwnCallbackThread) {
+ /* Start the audio thread */
+ /* !!! FIXME: we don't force the audio thread stack size here if it calls into user code, but maybe we should? */
+ /* buffer queueing callback only needs a few bytes, so make the stack tiny. */
+ const size_t stacksize = is_internal_thread ? 64 * 1024 : 0;
+ char threadname[64];
+
+ SDL_snprintf(threadname, sizeof (threadname), "SDLAudio%c%d", (iscapture) ? 'C' : 'P', (int) device->id);
+ device->thread = SDL_CreateThreadInternal(iscapture ? SDL_CaptureAudio : SDL_RunAudio, threadname, stacksize, device);
+
+ if (device->thread == NULL) {
+ close_audio_device(device);
+ SDL_SetError("Couldn't create audio thread");
+ return 0;
+ }
+ }
+
+ return device->id;
+}
+
+
+int
+SDL_OpenAudio(SDL_AudioSpec * desired, SDL_AudioSpec * obtained)
+{
+ SDL_AudioDeviceID id = 0;
+
+ /* Start up the audio driver, if necessary. This is legacy behaviour! */
+ if (!SDL_WasInit(SDL_INIT_AUDIO)) {
+ if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
+ return -1;
+ }
+ }
+
+ /* SDL_OpenAudio() is legacy and can only act on Device ID #1. */
+ if (open_devices[0] != NULL) {
+ SDL_SetError("Audio device is already opened");
+ return -1;
+ }
+
+ if (obtained) {
+ id = open_audio_device(NULL, 0, desired, obtained,
+ SDL_AUDIO_ALLOW_ANY_CHANGE, 1);
+ } else {
+ SDL_AudioSpec _obtained;
+ SDL_zero(_obtained);
+ id = open_audio_device(NULL, 0, desired, &_obtained, 0, 1);
+ /* On successful open, copy calculated values into 'desired'. */
+ if (id > 0) {
+ desired->size = _obtained.size;
+ desired->silence = _obtained.silence;
+ }
+ }
+
+ SDL_assert((id == 0) || (id == 1));
+ return (id == 0) ? -1 : 0;
+}
+
+SDL_AudioDeviceID
+SDL_OpenAudioDevice(const char *device, int iscapture,
+ const SDL_AudioSpec * desired, SDL_AudioSpec * obtained,
+ int allowed_changes)
+{
+ return open_audio_device(device, iscapture, desired, obtained,
+ allowed_changes, 2);
+}
+
+SDL_AudioStatus
+SDL_GetAudioDeviceStatus(SDL_AudioDeviceID devid)
+{
+ SDL_AudioDevice *device = get_audio_device(devid);
+ SDL_AudioStatus status = SDL_AUDIO_STOPPED;
+ if (device && SDL_AtomicGet(&device->enabled)) {
+ if (SDL_AtomicGet(&device->paused)) {
+ status = SDL_AUDIO_PAUSED;
+ } else {
+ status = SDL_AUDIO_PLAYING;
+ }
+ }
+ return status;
+}
+
+
+SDL_AudioStatus
+SDL_GetAudioStatus(void)
+{
+ return SDL_GetAudioDeviceStatus(1);
+}
+
+void
+SDL_PauseAudioDevice(SDL_AudioDeviceID devid, int pause_on)
+{
+ SDL_AudioDevice *device = get_audio_device(devid);
+ if (device) {
+ current_audio.impl.LockDevice(device);
+ SDL_AtomicSet(&device->paused, pause_on ? 1 : 0);
+ current_audio.impl.UnlockDevice(device);
+ }
+}
+
+void
+SDL_PauseAudio(int pause_on)
+{
+ SDL_PauseAudioDevice(1, pause_on);
+}
+
+
+void
+SDL_LockAudioDevice(SDL_AudioDeviceID devid)
+{
+ /* Obtain a lock on the mixing buffers */
+ SDL_AudioDevice *device = get_audio_device(devid);
+ if (device) {
+ current_audio.impl.LockDevice(device);
+ }
+}
+
+void
+SDL_LockAudio(void)
+{
+ SDL_LockAudioDevice(1);
+}
+
+void
+SDL_UnlockAudioDevice(SDL_AudioDeviceID devid)
+{
+ /* Obtain a lock on the mixing buffers */
+ SDL_AudioDevice *device = get_audio_device(devid);
+ if (device) {
+ current_audio.impl.UnlockDevice(device);
+ }
+}
+
+void
+SDL_UnlockAudio(void)
+{
+ SDL_UnlockAudioDevice(1);
+}
+
+void
+SDL_CloseAudioDevice(SDL_AudioDeviceID devid)
+{
+ close_audio_device(get_audio_device(devid));
+}
+
+void
+SDL_CloseAudio(void)
+{
+ SDL_CloseAudioDevice(1);
+}
+
+void
+SDL_AudioQuit(void)
+{
+ SDL_AudioDeviceID i;
+
+ if (!current_audio.name) { /* not initialized?! */
+ return;
+ }
+
+ for (i = 0; i < SDL_arraysize(open_devices); i++) {
+ close_audio_device(open_devices[i]);
+ }
+
+ free_device_list(&current_audio.outputDevices, &current_audio.outputDeviceCount);
+ free_device_list(&current_audio.inputDevices, &current_audio.inputDeviceCount);
+
+ /* Free the driver data */
+ current_audio.impl.Deinitialize();
+
+ SDL_DestroyMutex(current_audio.detectionLock);
+
+ SDL_zero(current_audio);
+ SDL_zero(open_devices);
+
+#ifdef HAVE_LIBSAMPLERATE_H
+ UnloadLibSampleRate();
+#endif
+
+ SDL_FreeResampleFilter();
+}
+
+#define NUM_FORMATS 10
+static int format_idx;
+static int format_idx_sub;
+static SDL_AudioFormat format_list[NUM_FORMATS][NUM_FORMATS] = {
+ {AUDIO_U8, AUDIO_S8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB,
+ AUDIO_U16MSB, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB},
+ {AUDIO_S8, AUDIO_U8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB,
+ AUDIO_U16MSB, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB},
+ {AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_S32LSB,
+ AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_U8, AUDIO_S8},
+ {AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_S32MSB,
+ AUDIO_S32LSB, AUDIO_F32MSB, AUDIO_F32LSB, AUDIO_U8, AUDIO_S8},
+ {AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_S32LSB,
+ AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_U8, AUDIO_S8},
+ {AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_S16MSB, AUDIO_S16LSB, AUDIO_S32MSB,
+ AUDIO_S32LSB, AUDIO_F32MSB, AUDIO_F32LSB, AUDIO_U8, AUDIO_S8},
+ {AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_S16LSB,
+ AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_U8, AUDIO_S8},
+ {AUDIO_S32MSB, AUDIO_S32LSB, AUDIO_F32MSB, AUDIO_F32LSB, AUDIO_S16MSB,
+ AUDIO_S16LSB, AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_U8, AUDIO_S8},
+ {AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_S16LSB,
+ AUDIO_S16MSB, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_U8, AUDIO_S8},
+ {AUDIO_F32MSB, AUDIO_F32LSB, AUDIO_S32MSB, AUDIO_S32LSB, AUDIO_S16MSB,
+ AUDIO_S16LSB, AUDIO_U16MSB, AUDIO_U16LSB, AUDIO_U8, AUDIO_S8},
+};
+
+SDL_AudioFormat
+SDL_FirstAudioFormat(SDL_AudioFormat format)
+{
+ for (format_idx = 0; format_idx < NUM_FORMATS; ++format_idx) {
+ if (format_list[format_idx][0] == format) {
+ break;
+ }
+ }
+ format_idx_sub = 0;
+ return SDL_NextAudioFormat();
+}
+
+SDL_AudioFormat
+SDL_NextAudioFormat(void)
+{
+ if ((format_idx == NUM_FORMATS) || (format_idx_sub == NUM_FORMATS)) {
+ return 0;
+ }
+ return format_list[format_idx][format_idx_sub++];
+}
+
+void
+SDL_CalculateAudioSpec(SDL_AudioSpec * spec)
+{
+ switch (spec->format) {
+ case AUDIO_U8:
+ spec->silence = 0x80;
+ break;
+ default:
+ spec->silence = 0x00;
+ break;
+ }
+ spec->size = SDL_AUDIO_BITSIZE(spec->format) / 8;
+ spec->size *= spec->channels;
+ spec->size *= spec->samples;
+}
+
+
+/*
+ * Moved here from SDL_mixer.c, since it relies on internals of an opened
+ * audio device (and is deprecated, by the way!).
+ */
+void
+SDL_MixAudio(Uint8 * dst, const Uint8 * src, Uint32 len, int volume)
+{
+ /* Mix the user-level audio format */
+ SDL_AudioDevice *device = get_audio_device(1);
+ if (device != NULL) {
+ SDL_MixAudioFormat(dst, src, device->callbackspec.format, len, volume);
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/SDL_audio_c.h b/src/3rdparty/SDL2/src/audio/SDL_audio_c.h
new file mode 100644
index 0000000..d47ebb1
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/SDL_audio_c.h
@@ -0,0 +1,79 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_audio_c_h_
+#define SDL_audio_c_h_
+
+#include "../SDL_internal.h"
+
+#ifndef DEBUG_CONVERT
+#define DEBUG_CONVERT 0
+#endif
+
+#if DEBUG_CONVERT
+#define LOG_DEBUG_CONVERT(from, to) fprintf(stderr, "Converting %s to %s.\n", from, to);
+#else
+#define LOG_DEBUG_CONVERT(from, to)
+#endif
+
+/* Functions and variables exported from SDL_audio.c for SDL_sysaudio.c */
+
+#ifdef HAVE_LIBSAMPLERATE_H
+#include "samplerate.h"
+extern SDL_bool SRC_available;
+extern int SRC_converter;
+extern SRC_STATE* (*SRC_src_new)(int converter_type, int channels, int *error);
+extern int (*SRC_src_process)(SRC_STATE *state, SRC_DATA *data);
+extern int (*SRC_src_reset)(SRC_STATE *state);
+extern SRC_STATE* (*SRC_src_delete)(SRC_STATE *state);
+extern const char* (*SRC_src_strerror)(int error);
+#endif
+
+/* Functions to get a list of "close" audio formats */
+extern SDL_AudioFormat SDL_FirstAudioFormat(SDL_AudioFormat format);
+extern SDL_AudioFormat SDL_NextAudioFormat(void);
+
+/* Function to calculate the size and silence for a SDL_AudioSpec */
+extern void SDL_CalculateAudioSpec(SDL_AudioSpec * spec);
+
+/* Choose the audio filter functions below */
+extern void SDL_ChooseAudioConverters(void);
+
+/* These pointers get set during SDL_ChooseAudioConverters() to various SIMD implementations. */
+extern SDL_AudioFilter SDL_Convert_S8_to_F32;
+extern SDL_AudioFilter SDL_Convert_U8_to_F32;
+extern SDL_AudioFilter SDL_Convert_S16_to_F32;
+extern SDL_AudioFilter SDL_Convert_U16_to_F32;
+extern SDL_AudioFilter SDL_Convert_S32_to_F32;
+extern SDL_AudioFilter SDL_Convert_F32_to_S8;
+extern SDL_AudioFilter SDL_Convert_F32_to_U8;
+extern SDL_AudioFilter SDL_Convert_F32_to_S16;
+extern SDL_AudioFilter SDL_Convert_F32_to_U16;
+extern SDL_AudioFilter SDL_Convert_F32_to_S32;
+
+/* You need to call SDL_PrepareResampleFilter() before using the internal resampler.
+ SDL_AudioQuit() calls SDL_FreeResamplerFilter(), you should never call it yourself. */
+extern int SDL_PrepareResampleFilter(void);
+extern void SDL_FreeResampleFilter(void);
+
+#endif /* SDL_audio_c_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/SDL_audiocvt.c b/src/3rdparty/SDL2/src/audio/SDL_audiocvt.c
new file mode 100644
index 0000000..7fde2b9
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/SDL_audiocvt.c
@@ -0,0 +1,1673 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* Functions for audio drivers to perform runtime conversion of audio format */
+
+/* FIXME: Channel weights when converting from more channels to fewer may need to be adjusted, see https://msdn.microsoft.com/en-us/library/windows/desktop/ff819070(v=vs.85).aspx
+*/
+
+#include "SDL.h"
+#include "SDL_audio.h"
+#include "SDL_audio_c.h"
+
+#include "SDL_loadso.h"
+#include "SDL_assert.h"
+#include "../SDL_dataqueue.h"
+#include "SDL_cpuinfo.h"
+
+#define DEBUG_AUDIOSTREAM 0
+
+#ifdef __SSE3__
+#define HAVE_SSE3_INTRINSICS 1
+#endif
+
+#if HAVE_SSE3_INTRINSICS
+/* Convert from stereo to mono. Average left and right. */
+static void SDLCALL
+SDL_ConvertStereoToMono_SSE3(SDL_AudioCVT * cvt, SDL_AudioFormat format)
+{
+ float *dst = (float *) cvt->buf;
+ const float *src = dst;
+ int i = cvt->len_cvt / 8;
+
+ LOG_DEBUG_CONVERT("stereo", "mono (using SSE3)");
+ SDL_assert(format == AUDIO_F32SYS);
+
+ /* We can only do this if dst is aligned to 16 bytes; since src is the
+ same pointer and it moves by 2, it can't be forcibly aligned. */
+ if ((((size_t) dst) & 15) == 0) {
+ /* Aligned! Do SSE blocks as long as we have 16 bytes available. */
+ const __m128 divby2 = _mm_set1_ps(0.5f);
+ while (i >= 4) { /* 4 * float32 */
+ _mm_store_ps(dst, _mm_mul_ps(_mm_hadd_ps(_mm_load_ps(src), _mm_load_ps(src+4)), divby2));
+ i -= 4; src += 8; dst += 4;
+ }
+ }
+
+ /* Finish off any leftovers with scalar operations. */
+ while (i) {
+ *dst = (src[0] + src[1]) * 0.5f;
+ dst++; i--; src += 2;
+ }
+
+ cvt->len_cvt /= 2;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index] (cvt, format);
+ }
+}
+#endif
+
+/* Convert from stereo to mono. Average left and right. */
+static void SDLCALL
+SDL_ConvertStereoToMono(SDL_AudioCVT * cvt, SDL_AudioFormat format)
+{
+ float *dst = (float *) cvt->buf;
+ const float *src = dst;
+ int i;
+
+ LOG_DEBUG_CONVERT("stereo", "mono");
+ SDL_assert(format == AUDIO_F32SYS);
+
+ for (i = cvt->len_cvt / 8; i; --i, src += 2) {
+ *(dst++) = (src[0] + src[1]) * 0.5f;
+ }
+
+ cvt->len_cvt /= 2;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index] (cvt, format);
+ }
+}
+
+
+/* Convert from 5.1 to stereo. Average left and right, distribute center, discard LFE. */
+static void SDLCALL
+SDL_Convert51ToStereo(SDL_AudioCVT * cvt, SDL_AudioFormat format)
+{
+ float *dst = (float *) cvt->buf;
+ const float *src = dst;
+ int i;
+
+ LOG_DEBUG_CONVERT("5.1", "stereo");
+ SDL_assert(format == AUDIO_F32SYS);
+
+ /* SDL's 5.1 layout: FL+FR+FC+LFE+BL+BR */
+ for (i = cvt->len_cvt / (sizeof (float) * 6); i; --i, src += 6, dst += 2) {
+ const float front_center_distributed = src[2] * 0.5f;
+ dst[0] = (src[0] + front_center_distributed + src[4]) / 2.5f; /* left */
+ dst[1] = (src[1] + front_center_distributed + src[5]) / 2.5f; /* right */
+ }
+
+ cvt->len_cvt /= 3;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index] (cvt, format);
+ }
+}
+
+
+/* Convert from quad to stereo. Average left and right. */
+static void SDLCALL
+SDL_ConvertQuadToStereo(SDL_AudioCVT * cvt, SDL_AudioFormat format)
+{
+ float *dst = (float *) cvt->buf;
+ const float *src = dst;
+ int i;
+
+ LOG_DEBUG_CONVERT("quad", "stereo");
+ SDL_assert(format == AUDIO_F32SYS);
+
+ for (i = cvt->len_cvt / (sizeof (float) * 4); i; --i, src += 4, dst += 2) {
+ dst[0] = (src[0] + src[2]) * 0.5f; /* left */
+ dst[1] = (src[1] + src[3]) * 0.5f; /* right */
+ }
+
+ cvt->len_cvt /= 2;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index] (cvt, format);
+ }
+}
+
+
+/* Convert from 7.1 to 5.1. Distribute sides across front and back. */
+static void SDLCALL
+SDL_Convert71To51(SDL_AudioCVT * cvt, SDL_AudioFormat format)
+{
+ float *dst = (float *) cvt->buf;
+ const float *src = dst;
+ int i;
+
+ LOG_DEBUG_CONVERT("7.1", "5.1");
+ SDL_assert(format == AUDIO_F32SYS);
+
+ for (i = cvt->len_cvt / (sizeof (float) * 8); i; --i, src += 8, dst += 6) {
+ const float surround_left_distributed = src[6] * 0.5f;
+ const float surround_right_distributed = src[7] * 0.5f;
+ dst[0] = (src[0] + surround_left_distributed) / 1.5f; /* FL */
+ dst[1] = (src[1] + surround_right_distributed) / 1.5f; /* FR */
+ dst[2] = src[2] / 1.5f; /* CC */
+ dst[3] = src[3] / 1.5f; /* LFE */
+ dst[4] = (src[4] + surround_left_distributed) / 1.5f; /* BL */
+ dst[5] = (src[5] + surround_right_distributed) / 1.5f; /* BR */
+ }
+
+ cvt->len_cvt /= 8;
+ cvt->len_cvt *= 6;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index] (cvt, format);
+ }
+}
+
+
+/* Convert from 5.1 to quad. Distribute center across front, discard LFE. */
+static void SDLCALL
+SDL_Convert51ToQuad(SDL_AudioCVT * cvt, SDL_AudioFormat format)
+{
+ float *dst = (float *) cvt->buf;
+ const float *src = dst;
+ int i;
+
+ LOG_DEBUG_CONVERT("5.1", "quad");
+ SDL_assert(format == AUDIO_F32SYS);
+
+ /* SDL's 4.0 layout: FL+FR+BL+BR */
+ /* SDL's 5.1 layout: FL+FR+FC+LFE+BL+BR */
+ for (i = cvt->len_cvt / (sizeof (float) * 6); i; --i, src += 6, dst += 4) {
+ const float front_center_distributed = src[2] * 0.5f;
+ dst[0] = (src[0] + front_center_distributed) / 1.5f; /* FL */
+ dst[1] = (src[1] + front_center_distributed) / 1.5f; /* FR */
+ dst[2] = src[4] / 1.5f; /* BL */
+ dst[3] = src[5] / 1.5f; /* BR */
+ }
+
+ cvt->len_cvt /= 6;
+ cvt->len_cvt *= 4;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index] (cvt, format);
+ }
+}
+
+
+/* Upmix mono to stereo (by duplication) */
+static void SDLCALL
+SDL_ConvertMonoToStereo(SDL_AudioCVT * cvt, SDL_AudioFormat format)
+{
+ const float *src = (const float *) (cvt->buf + cvt->len_cvt);
+ float *dst = (float *) (cvt->buf + cvt->len_cvt * 2);
+ int i;
+
+ LOG_DEBUG_CONVERT("mono", "stereo");
+ SDL_assert(format == AUDIO_F32SYS);
+
+ for (i = cvt->len_cvt / sizeof (float); i; --i) {
+ src--;
+ dst -= 2;
+ dst[0] = dst[1] = *src;
+ }
+
+ cvt->len_cvt *= 2;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index] (cvt, format);
+ }
+}
+
+
+/* Upmix stereo to a pseudo-5.1 stream */
+static void SDLCALL
+SDL_ConvertStereoTo51(SDL_AudioCVT * cvt, SDL_AudioFormat format)
+{
+ int i;
+ float lf, rf, ce;
+ const float *src = (const float *) (cvt->buf + cvt->len_cvt);
+ float *dst = (float *) (cvt->buf + cvt->len_cvt * 3);
+
+ LOG_DEBUG_CONVERT("stereo", "5.1");
+ SDL_assert(format == AUDIO_F32SYS);
+
+ for (i = cvt->len_cvt / (sizeof(float) * 2); i; --i) {
+ dst -= 6;
+ src -= 2;
+ lf = src[0];
+ rf = src[1];
+ ce = (lf + rf) * 0.5f;
+ /* !!! FIXME: FL and FR may clip */
+ dst[0] = lf + (lf - ce); /* FL */
+ dst[1] = rf + (rf - ce); /* FR */
+ dst[2] = ce; /* FC */
+ dst[3] = 0; /* LFE (only meant for special LFE effects) */
+ dst[4] = lf; /* BL */
+ dst[5] = rf; /* BR */
+ }
+
+ cvt->len_cvt *= 3;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index] (cvt, format);
+ }
+}
+
+
+/* Upmix quad to a pseudo-5.1 stream */
+static void SDLCALL
+SDL_ConvertQuadTo51(SDL_AudioCVT * cvt, SDL_AudioFormat format)
+{
+ int i;
+ float lf, rf, lb, rb, ce;
+ const float *src = (const float *) (cvt->buf + cvt->len_cvt);
+ float *dst = (float *) (cvt->buf + cvt->len_cvt * 3 / 2);
+
+ LOG_DEBUG_CONVERT("quad", "5.1");
+ SDL_assert(format == AUDIO_F32SYS);
+ SDL_assert(cvt->len_cvt % (sizeof(float) * 4) == 0);
+
+ for (i = cvt->len_cvt / (sizeof(float) * 4); i; --i) {
+ dst -= 6;
+ src -= 4;
+ lf = src[0];
+ rf = src[1];
+ lb = src[2];
+ rb = src[3];
+ ce = (lf + rf) * 0.5f;
+ /* !!! FIXME: FL and FR may clip */
+ dst[0] = lf + (lf - ce); /* FL */
+ dst[1] = rf + (rf - ce); /* FR */
+ dst[2] = ce; /* FC */
+ dst[3] = 0; /* LFE (only meant for special LFE effects) */
+ dst[4] = lb; /* BL */
+ dst[5] = rb; /* BR */
+ }
+
+ cvt->len_cvt = cvt->len_cvt * 3 / 2;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index] (cvt, format);
+ }
+}
+
+
+/* Upmix stereo to a pseudo-4.0 stream (by duplication) */
+static void SDLCALL
+SDL_ConvertStereoToQuad(SDL_AudioCVT * cvt, SDL_AudioFormat format)
+{
+ const float *src = (const float *) (cvt->buf + cvt->len_cvt);
+ float *dst = (float *) (cvt->buf + cvt->len_cvt * 2);
+ float lf, rf;
+ int i;
+
+ LOG_DEBUG_CONVERT("stereo", "quad");
+ SDL_assert(format == AUDIO_F32SYS);
+
+ for (i = cvt->len_cvt / (sizeof(float) * 2); i; --i) {
+ dst -= 4;
+ src -= 2;
+ lf = src[0];
+ rf = src[1];
+ dst[0] = lf; /* FL */
+ dst[1] = rf; /* FR */
+ dst[2] = lf; /* BL */
+ dst[3] = rf; /* BR */
+ }
+
+ cvt->len_cvt *= 2;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index] (cvt, format);
+ }
+}
+
+
+/* Upmix 5.1 to 7.1 */
+static void SDLCALL
+SDL_Convert51To71(SDL_AudioCVT * cvt, SDL_AudioFormat format)
+{
+ float lf, rf, lb, rb, ls, rs;
+ int i;
+ const float *src = (const float *) (cvt->buf + cvt->len_cvt);
+ float *dst = (float *) (cvt->buf + cvt->len_cvt * 4 / 3);
+
+ LOG_DEBUG_CONVERT("5.1", "7.1");
+ SDL_assert(format == AUDIO_F32SYS);
+ SDL_assert(cvt->len_cvt % (sizeof(float) * 6) == 0);
+
+ for (i = cvt->len_cvt / (sizeof(float) * 6); i; --i) {
+ dst -= 8;
+ src -= 6;
+ lf = src[0];
+ rf = src[1];
+ lb = src[4];
+ rb = src[5];
+ ls = (lf + lb) * 0.5f;
+ rs = (rf + rb) * 0.5f;
+ /* !!! FIXME: these four may clip */
+ lf += lf - ls;
+ rf += rf - ls;
+ lb += lb - ls;
+ rb += rb - ls;
+ dst[3] = src[3]; /* LFE */
+ dst[2] = src[2]; /* FC */
+ dst[7] = rs; /* SR */
+ dst[6] = ls; /* SL */
+ dst[5] = rb; /* BR */
+ dst[4] = lb; /* BL */
+ dst[1] = rf; /* FR */
+ dst[0] = lf; /* FL */
+ }
+
+ cvt->len_cvt = cvt->len_cvt * 4 / 3;
+
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index] (cvt, format);
+ }
+}
+
+/* SDL's resampler uses a "bandlimited interpolation" algorithm:
+ https://ccrma.stanford.edu/~jos/resample/ */
+
+#define RESAMPLER_ZERO_CROSSINGS 5
+#define RESAMPLER_BITS_PER_SAMPLE 16
+#define RESAMPLER_SAMPLES_PER_ZERO_CROSSING (1 << ((RESAMPLER_BITS_PER_SAMPLE / 2) + 1))
+#define RESAMPLER_FILTER_SIZE ((RESAMPLER_SAMPLES_PER_ZERO_CROSSING * RESAMPLER_ZERO_CROSSINGS) + 1)
+
+/* This is a "modified" bessel function, so you can't use POSIX j0() */
+static double
+bessel(const double x)
+{
+ const double xdiv2 = x / 2.0;
+ double i0 = 1.0f;
+ double f = 1.0f;
+ int i = 1;
+
+ while (SDL_TRUE) {
+ const double diff = SDL_pow(xdiv2, i * 2) / SDL_pow(f, 2);
+ if (diff < 1.0e-21f) {
+ break;
+ }
+ i0 += diff;
+ i++;
+ f *= (double) i;
+ }
+
+ return i0;
+}
+
+/* build kaiser table with cardinal sine applied to it, and array of differences between elements. */
+static void
+kaiser_and_sinc(float *table, float *diffs, const int tablelen, const double beta)
+{
+ const int lenm1 = tablelen - 1;
+ const int lenm1div2 = lenm1 / 2;
+ int i;
+
+ table[0] = 1.0f;
+ for (i = 1; i < tablelen; i++) {
+ const double kaiser = bessel(beta * SDL_sqrt(1.0 - SDL_pow(((i - lenm1) / 2.0) / lenm1div2, 2.0))) / bessel(beta);
+ table[tablelen - i] = (float) kaiser;
+ }
+
+ for (i = 1; i < tablelen; i++) {
+ const float x = (((float) i) / ((float) RESAMPLER_SAMPLES_PER_ZERO_CROSSING)) * ((float) M_PI);
+ table[i] *= SDL_sinf(x) / x;
+ diffs[i - 1] = table[i] - table[i - 1];
+ }
+ diffs[lenm1] = 0.0f;
+}
+
+
+static SDL_SpinLock ResampleFilterSpinlock = 0;
+static float *ResamplerFilter = NULL;
+static float *ResamplerFilterDifference = NULL;
+
+int
+SDL_PrepareResampleFilter(void)
+{
+ SDL_AtomicLock(&ResampleFilterSpinlock);
+ if (!ResamplerFilter) {
+ /* if dB > 50, beta=(0.1102 * (dB - 8.7)), according to Matlab. */
+ const double dB = 80.0;
+ const double beta = 0.1102 * (dB - 8.7);
+ const size_t alloclen = RESAMPLER_FILTER_SIZE * sizeof (float);
+
+ ResamplerFilter = (float *) SDL_malloc(alloclen);
+ if (!ResamplerFilter) {
+ SDL_AtomicUnlock(&ResampleFilterSpinlock);
+ return SDL_OutOfMemory();
+ }
+
+ ResamplerFilterDifference = (float *) SDL_malloc(alloclen);
+ if (!ResamplerFilterDifference) {
+ SDL_free(ResamplerFilter);
+ ResamplerFilter = NULL;
+ SDL_AtomicUnlock(&ResampleFilterSpinlock);
+ return SDL_OutOfMemory();
+ }
+ kaiser_and_sinc(ResamplerFilter, ResamplerFilterDifference, RESAMPLER_FILTER_SIZE, beta);
+ }
+ SDL_AtomicUnlock(&ResampleFilterSpinlock);
+ return 0;
+}
+
+void
+SDL_FreeResampleFilter(void)
+{
+ SDL_free(ResamplerFilter);
+ SDL_free(ResamplerFilterDifference);
+ ResamplerFilter = NULL;
+ ResamplerFilterDifference = NULL;
+}
+
+static int
+ResamplerPadding(const int inrate, const int outrate)
+{
+ if (inrate == outrate) {
+ return 0;
+ } else if (inrate > outrate) {
+ return (int) SDL_ceil(((float) (RESAMPLER_SAMPLES_PER_ZERO_CROSSING * inrate) / ((float) outrate)));
+ }
+ return RESAMPLER_SAMPLES_PER_ZERO_CROSSING;
+}
+
+/* lpadding and rpadding are expected to be buffers of (ResamplePadding(inrate, outrate) * chans * sizeof (float)) bytes. */
+static int
+SDL_ResampleAudio(const int chans, const int inrate, const int outrate,
+ const float *lpadding, const float *rpadding,
+ const float *inbuf, const int inbuflen,
+ float *outbuf, const int outbuflen)
+{
+ const double finrate = (double) inrate;
+ const double outtimeincr = 1.0 / ((float) outrate);
+ const double ratio = ((float) outrate) / ((float) inrate);
+ const int paddinglen = ResamplerPadding(inrate, outrate);
+ const int framelen = chans * (int)sizeof (float);
+ const int inframes = inbuflen / framelen;
+ const int wantedoutframes = (int) ((inbuflen / framelen) * ratio); /* outbuflen isn't total to write, it's total available. */
+ const int maxoutframes = outbuflen / framelen;
+ const int outframes = SDL_min(wantedoutframes, maxoutframes);
+ float *dst = outbuf;
+ double outtime = 0.0;
+ int i, j, chan;
+
+ for (i = 0; i < outframes; i++) {
+ const int srcindex = (int) (outtime * inrate);
+ const double intime = ((double) srcindex) / finrate;
+ const double innexttime = ((double) (srcindex + 1)) / finrate;
+ const double interpolation1 = 1.0 - ((innexttime - outtime) / (innexttime - intime));
+ const int filterindex1 = (int) (interpolation1 * RESAMPLER_SAMPLES_PER_ZERO_CROSSING);
+ const double interpolation2 = 1.0 - interpolation1;
+ const int filterindex2 = (int) (interpolation2 * RESAMPLER_SAMPLES_PER_ZERO_CROSSING);
+
+ for (chan = 0; chan < chans; chan++) {
+ float outsample = 0.0f;
+
+ /* do this twice to calculate the sample, once for the "left wing" and then same for the right. */
+ /* !!! FIXME: do both wings in one loop */
+ for (j = 0; (filterindex1 + (j * RESAMPLER_SAMPLES_PER_ZERO_CROSSING)) < RESAMPLER_FILTER_SIZE; j++) {
+ const int srcframe = srcindex - j;
+ /* !!! FIXME: we can bubble this conditional out of here by doing a pre loop. */
+ const float insample = (srcframe < 0) ? lpadding[((paddinglen + srcframe) * chans) + chan] : inbuf[(srcframe * chans) + chan];
+ outsample += (float)(insample * (ResamplerFilter[filterindex1 + (j * RESAMPLER_SAMPLES_PER_ZERO_CROSSING)] + (interpolation1 * ResamplerFilterDifference[filterindex1 + (j * RESAMPLER_SAMPLES_PER_ZERO_CROSSING)])));
+ }
+
+ for (j = 0; (filterindex2 + (j * RESAMPLER_SAMPLES_PER_ZERO_CROSSING)) < RESAMPLER_FILTER_SIZE; j++) {
+ const int srcframe = srcindex + 1 + j;
+ /* !!! FIXME: we can bubble this conditional out of here by doing a post loop. */
+ const float insample = (srcframe >= inframes) ? rpadding[((srcframe - inframes) * chans) + chan] : inbuf[(srcframe * chans) + chan];
+ outsample += (float)(insample * (ResamplerFilter[filterindex2 + (j * RESAMPLER_SAMPLES_PER_ZERO_CROSSING)] + (interpolation2 * ResamplerFilterDifference[filterindex2 + (j * RESAMPLER_SAMPLES_PER_ZERO_CROSSING)])));
+ }
+ *(dst++) = outsample;
+ }
+
+ outtime += outtimeincr;
+ }
+
+ return outframes * chans * sizeof (float);
+}
+
+int
+SDL_ConvertAudio(SDL_AudioCVT * cvt)
+{
+ /* !!! FIXME: (cvt) should be const; stack-copy it here. */
+ /* !!! FIXME: (actually, we can't...len_cvt needs to be updated. Grr.) */
+
+ /* Make sure there's data to convert */
+ if (cvt->buf == NULL) {
+ return SDL_SetError("No buffer allocated for conversion");
+ }
+
+ /* Return okay if no conversion is necessary */
+ cvt->len_cvt = cvt->len;
+ if (cvt->filters[0] == NULL) {
+ return 0;
+ }
+
+ /* Set up the conversion and go! */
+ cvt->filter_index = 0;
+ cvt->filters[0] (cvt, cvt->src_format);
+ return 0;
+}
+
+static void SDLCALL
+SDL_Convert_Byteswap(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+#if DEBUG_CONVERT
+ printf("Converting byte order\n");
+#endif
+
+ switch (SDL_AUDIO_BITSIZE(format)) {
+ #define CASESWAP(b) \
+ case b: { \
+ Uint##b *ptr = (Uint##b *) cvt->buf; \
+ int i; \
+ for (i = cvt->len_cvt / sizeof (*ptr); i; --i, ++ptr) { \
+ *ptr = SDL_Swap##b(*ptr); \
+ } \
+ break; \
+ }
+
+ CASESWAP(16);
+ CASESWAP(32);
+ CASESWAP(64);
+
+ #undef CASESWAP
+
+ default: SDL_assert(!"unhandled byteswap datatype!"); break;
+ }
+
+ if (cvt->filters[++cvt->filter_index]) {
+ /* flip endian flag for data. */
+ if (format & SDL_AUDIO_MASK_ENDIAN) {
+ format &= ~SDL_AUDIO_MASK_ENDIAN;
+ } else {
+ format |= SDL_AUDIO_MASK_ENDIAN;
+ }
+ cvt->filters[cvt->filter_index](cvt, format);
+ }
+}
+
+static int
+SDL_AddAudioCVTFilter(SDL_AudioCVT *cvt, const SDL_AudioFilter filter)
+{
+ if (cvt->filter_index >= SDL_AUDIOCVT_MAX_FILTERS) {
+ return SDL_SetError("Too many filters needed for conversion, exceeded maximum of %d", SDL_AUDIOCVT_MAX_FILTERS);
+ }
+ if (filter == NULL) {
+ return SDL_SetError("Audio filter pointer is NULL");
+ }
+ cvt->filters[cvt->filter_index++] = filter;
+ cvt->filters[cvt->filter_index] = NULL; /* Moving terminator */
+ return 0;
+}
+
+static int
+SDL_BuildAudioTypeCVTToFloat(SDL_AudioCVT *cvt, const SDL_AudioFormat src_fmt)
+{
+ int retval = 0; /* 0 == no conversion necessary. */
+
+ if ((SDL_AUDIO_ISBIGENDIAN(src_fmt) != 0) == (SDL_BYTEORDER == SDL_LIL_ENDIAN)) {
+ if (SDL_AddAudioCVTFilter(cvt, SDL_Convert_Byteswap) < 0) {
+ return -1;
+ }
+ retval = 1; /* added a converter. */
+ }
+
+ if (!SDL_AUDIO_ISFLOAT(src_fmt)) {
+ const Uint16 src_bitsize = SDL_AUDIO_BITSIZE(src_fmt);
+ const Uint16 dst_bitsize = 32;
+ SDL_AudioFilter filter = NULL;
+
+ switch (src_fmt & ~SDL_AUDIO_MASK_ENDIAN) {
+ case AUDIO_S8: filter = SDL_Convert_S8_to_F32; break;
+ case AUDIO_U8: filter = SDL_Convert_U8_to_F32; break;
+ case AUDIO_S16: filter = SDL_Convert_S16_to_F32; break;
+ case AUDIO_U16: filter = SDL_Convert_U16_to_F32; break;
+ case AUDIO_S32: filter = SDL_Convert_S32_to_F32; break;
+ default: SDL_assert(!"Unexpected audio format!"); break;
+ }
+
+ if (!filter) {
+ return SDL_SetError("No conversion from source format to float available");
+ }
+
+ if (SDL_AddAudioCVTFilter(cvt, filter) < 0) {
+ return -1;
+ }
+ if (src_bitsize < dst_bitsize) {
+ const int mult = (dst_bitsize / src_bitsize);
+ cvt->len_mult *= mult;
+ cvt->len_ratio *= mult;
+ } else if (src_bitsize > dst_bitsize) {
+ cvt->len_ratio /= (src_bitsize / dst_bitsize);
+ }
+
+ retval = 1; /* added a converter. */
+ }
+
+ return retval;
+}
+
+static int
+SDL_BuildAudioTypeCVTFromFloat(SDL_AudioCVT *cvt, const SDL_AudioFormat dst_fmt)
+{
+ int retval = 0; /* 0 == no conversion necessary. */
+
+ if (!SDL_AUDIO_ISFLOAT(dst_fmt)) {
+ const Uint16 dst_bitsize = SDL_AUDIO_BITSIZE(dst_fmt);
+ const Uint16 src_bitsize = 32;
+ SDL_AudioFilter filter = NULL;
+ switch (dst_fmt & ~SDL_AUDIO_MASK_ENDIAN) {
+ case AUDIO_S8: filter = SDL_Convert_F32_to_S8; break;
+ case AUDIO_U8: filter = SDL_Convert_F32_to_U8; break;
+ case AUDIO_S16: filter = SDL_Convert_F32_to_S16; break;
+ case AUDIO_U16: filter = SDL_Convert_F32_to_U16; break;
+ case AUDIO_S32: filter = SDL_Convert_F32_to_S32; break;
+ default: SDL_assert(!"Unexpected audio format!"); break;
+ }
+
+ if (!filter) {
+ return SDL_SetError("No conversion from float to destination format available");
+ }
+
+ if (SDL_AddAudioCVTFilter(cvt, filter) < 0) {
+ return -1;
+ }
+ if (src_bitsize < dst_bitsize) {
+ const int mult = (dst_bitsize / src_bitsize);
+ cvt->len_mult *= mult;
+ cvt->len_ratio *= mult;
+ } else if (src_bitsize > dst_bitsize) {
+ cvt->len_ratio /= (src_bitsize / dst_bitsize);
+ }
+ retval = 1; /* added a converter. */
+ }
+
+ if ((SDL_AUDIO_ISBIGENDIAN(dst_fmt) != 0) == (SDL_BYTEORDER == SDL_LIL_ENDIAN)) {
+ if (SDL_AddAudioCVTFilter(cvt, SDL_Convert_Byteswap) < 0) {
+ return -1;
+ }
+ retval = 1; /* added a converter. */
+ }
+
+ return retval;
+}
+
+static void
+SDL_ResampleCVT(SDL_AudioCVT *cvt, const int chans, const SDL_AudioFormat format)
+{
+ /* !!! FIXME in 2.1: there are ten slots in the filter list, and the theoretical maximum we use is six (seven with NULL terminator).
+ !!! FIXME in 2.1: We need to store data for this resampler, because the cvt structure doesn't store the original sample rates,
+ !!! FIXME in 2.1: so we steal the ninth and tenth slot. :( */
+ const int inrate = (int) (size_t) cvt->filters[SDL_AUDIOCVT_MAX_FILTERS-1];
+ const int outrate = (int) (size_t) cvt->filters[SDL_AUDIOCVT_MAX_FILTERS];
+ const float *src = (const float *) cvt->buf;
+ const int srclen = cvt->len_cvt;
+ /*float *dst = (float *) cvt->buf;
+ const int dstlen = (cvt->len * cvt->len_mult);*/
+ /* !!! FIXME: remove this if we can get the resampler to work in-place again. */
+ float *dst = (float *) (cvt->buf + srclen);
+ const int dstlen = (cvt->len * cvt->len_mult) - srclen;
+ const int paddingsamples = (ResamplerPadding(inrate, outrate) * chans);
+ float *padding;
+
+ SDL_assert(format == AUDIO_F32SYS);
+
+ /* we keep no streaming state here, so pad with silence on both ends. */
+ padding = (float *) SDL_calloc(paddingsamples, sizeof (float));
+ if (!padding) {
+ SDL_OutOfMemory();
+ return;
+ }
+
+ cvt->len_cvt = SDL_ResampleAudio(chans, inrate, outrate, padding, padding, src, srclen, dst, dstlen);
+
+ SDL_free(padding);
+
+ SDL_memmove(cvt->buf, dst, cvt->len_cvt); /* !!! FIXME: remove this if we can get the resampler to work in-place again. */
+
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, format);
+ }
+}
+
+/* !!! FIXME: We only have this macro salsa because SDL_AudioCVT doesn't
+ !!! FIXME: store channel info, so we have to have function entry
+ !!! FIXME: points for each supported channel count and multiple
+ !!! FIXME: vs arbitrary. When we rev the ABI, clean this up. */
+#define RESAMPLER_FUNCS(chans) \
+ static void SDLCALL \
+ SDL_ResampleCVT_c##chans(SDL_AudioCVT *cvt, SDL_AudioFormat format) { \
+ SDL_ResampleCVT(cvt, chans, format); \
+ }
+RESAMPLER_FUNCS(1)
+RESAMPLER_FUNCS(2)
+RESAMPLER_FUNCS(4)
+RESAMPLER_FUNCS(6)
+RESAMPLER_FUNCS(8)
+#undef RESAMPLER_FUNCS
+
+static SDL_AudioFilter
+ChooseCVTResampler(const int dst_channels)
+{
+ switch (dst_channels) {
+ case 1: return SDL_ResampleCVT_c1;
+ case 2: return SDL_ResampleCVT_c2;
+ case 4: return SDL_ResampleCVT_c4;
+ case 6: return SDL_ResampleCVT_c6;
+ case 8: return SDL_ResampleCVT_c8;
+ default: break;
+ }
+
+ return NULL;
+}
+
+static int
+SDL_BuildAudioResampleCVT(SDL_AudioCVT * cvt, const int dst_channels,
+ const int src_rate, const int dst_rate)
+{
+ SDL_AudioFilter filter;
+
+ if (src_rate == dst_rate) {
+ return 0; /* no conversion necessary. */
+ }
+
+ filter = ChooseCVTResampler(dst_channels);
+ if (filter == NULL) {
+ return SDL_SetError("No conversion available for these rates");
+ }
+
+ if (SDL_PrepareResampleFilter() < 0) {
+ return -1;
+ }
+
+ /* Update (cvt) with filter details... */
+ if (SDL_AddAudioCVTFilter(cvt, filter) < 0) {
+ return -1;
+ }
+
+ /* !!! FIXME in 2.1: there are ten slots in the filter list, and the theoretical maximum we use is six (seven with NULL terminator).
+ !!! FIXME in 2.1: We need to store data for this resampler, because the cvt structure doesn't store the original sample rates,
+ !!! FIXME in 2.1: so we steal the ninth and tenth slot. :( */
+ if (cvt->filter_index >= (SDL_AUDIOCVT_MAX_FILTERS-2)) {
+ return SDL_SetError("Too many filters needed for conversion, exceeded maximum of %d", SDL_AUDIOCVT_MAX_FILTERS-2);
+ }
+ cvt->filters[SDL_AUDIOCVT_MAX_FILTERS-1] = (SDL_AudioFilter) (size_t) src_rate;
+ cvt->filters[SDL_AUDIOCVT_MAX_FILTERS] = (SDL_AudioFilter) (size_t) dst_rate;
+
+ if (src_rate < dst_rate) {
+ const double mult = ((double) dst_rate) / ((double) src_rate);
+ cvt->len_mult *= (int) SDL_ceil(mult);
+ cvt->len_ratio *= mult;
+ } else {
+ cvt->len_ratio /= ((double) src_rate) / ((double) dst_rate);
+ }
+
+ /* !!! FIXME: remove this if we can get the resampler to work in-place again. */
+ /* the buffer is big enough to hold the destination now, but
+ we need it large enough to hold a separate scratch buffer. */
+ cvt->len_mult *= 2;
+
+ return 1; /* added a converter. */
+}
+
+static SDL_bool
+SDL_SupportedAudioFormat(const SDL_AudioFormat fmt)
+{
+ switch (fmt) {
+ case AUDIO_U8:
+ case AUDIO_S8:
+ case AUDIO_U16LSB:
+ case AUDIO_S16LSB:
+ case AUDIO_U16MSB:
+ case AUDIO_S16MSB:
+ case AUDIO_S32LSB:
+ case AUDIO_S32MSB:
+ case AUDIO_F32LSB:
+ case AUDIO_F32MSB:
+ return SDL_TRUE; /* supported. */
+
+ default:
+ break;
+ }
+
+ return SDL_FALSE; /* unsupported. */
+}
+
+static SDL_bool
+SDL_SupportedChannelCount(const int channels)
+{
+ switch (channels) {
+ case 1: /* mono */
+ case 2: /* stereo */
+ case 4: /* quad */
+ case 6: /* 5.1 */
+ case 8: /* 7.1 */
+ return SDL_TRUE; /* supported. */
+
+ default:
+ break;
+ }
+
+ return SDL_FALSE; /* unsupported. */
+}
+
+
+/* Creates a set of audio filters to convert from one format to another.
+ Returns 0 if no conversion is needed, 1 if the audio filter is set up,
+ or -1 if an error like invalid parameter, unsupported format, etc. occurred.
+*/
+
+int
+SDL_BuildAudioCVT(SDL_AudioCVT * cvt,
+ SDL_AudioFormat src_fmt, Uint8 src_channels, int src_rate,
+ SDL_AudioFormat dst_fmt, Uint8 dst_channels, int dst_rate)
+{
+ /* Sanity check target pointer */
+ if (cvt == NULL) {
+ return SDL_InvalidParamError("cvt");
+ }
+
+ /* Make sure we zero out the audio conversion before error checking */
+ SDL_zerop(cvt);
+
+ if (!SDL_SupportedAudioFormat(src_fmt)) {
+ return SDL_SetError("Invalid source format");
+ } else if (!SDL_SupportedAudioFormat(dst_fmt)) {
+ return SDL_SetError("Invalid destination format");
+ } else if (!SDL_SupportedChannelCount(src_channels)) {
+ return SDL_SetError("Invalid source channels");
+ } else if (!SDL_SupportedChannelCount(dst_channels)) {
+ return SDL_SetError("Invalid destination channels");
+ } else if (src_rate == 0) {
+ return SDL_SetError("Source rate is zero");
+ } else if (dst_rate == 0) {
+ return SDL_SetError("Destination rate is zero");
+ }
+
+#if DEBUG_CONVERT
+ printf("Build format %04x->%04x, channels %u->%u, rate %d->%d\n",
+ src_fmt, dst_fmt, src_channels, dst_channels, src_rate, dst_rate);
+#endif
+
+ /* Start off with no conversion necessary */
+ cvt->src_format = src_fmt;
+ cvt->dst_format = dst_fmt;
+ cvt->needed = 0;
+ cvt->filter_index = 0;
+ SDL_zero(cvt->filters);
+ cvt->len_mult = 1;
+ cvt->len_ratio = 1.0;
+ cvt->rate_incr = ((double) dst_rate) / ((double) src_rate);
+
+ /* Make sure we've chosen audio conversion functions (MMX, scalar, etc.) */
+ SDL_ChooseAudioConverters();
+
+ /* Type conversion goes like this now:
+ - byteswap to CPU native format first if necessary.
+ - convert to native Float32 if necessary.
+ - resample and change channel count if necessary.
+ - convert back to native format.
+ - byteswap back to foreign format if necessary.
+
+ The expectation is we can process data faster in float32
+ (possibly with SIMD), and making several passes over the same
+ buffer is likely to be CPU cache-friendly, avoiding the
+ biggest performance hit in modern times. Previously we had
+ (script-generated) custom converters for every data type and
+ it was a bloat on SDL compile times and final library size. */
+
+ /* see if we can skip float conversion entirely. */
+ if (src_rate == dst_rate && src_channels == dst_channels) {
+ if (src_fmt == dst_fmt) {
+ return 0;
+ }
+
+ /* just a byteswap needed? */
+ if ((src_fmt & ~SDL_AUDIO_MASK_ENDIAN) == (dst_fmt & ~SDL_AUDIO_MASK_ENDIAN)) {
+ if (SDL_AddAudioCVTFilter(cvt, SDL_Convert_Byteswap) < 0) {
+ return -1;
+ }
+ cvt->needed = 1;
+ return 1;
+ }
+ }
+
+ /* Convert data types, if necessary. Updates (cvt). */
+ if (SDL_BuildAudioTypeCVTToFloat(cvt, src_fmt) < 0) {
+ return -1; /* shouldn't happen, but just in case... */
+ }
+
+ /* Channel conversion */
+ if (src_channels < dst_channels) {
+ /* Upmixing */
+ /* Mono -> Stereo [-> ...] */
+ if ((src_channels == 1) && (dst_channels > 1)) {
+ if (SDL_AddAudioCVTFilter(cvt, SDL_ConvertMonoToStereo) < 0) {
+ return -1;
+ }
+ cvt->len_mult *= 2;
+ src_channels = 2;
+ cvt->len_ratio *= 2;
+ }
+ /* [Mono ->] Stereo -> 5.1 [-> 7.1] */
+ if ((src_channels == 2) && (dst_channels >= 6)) {
+ if (SDL_AddAudioCVTFilter(cvt, SDL_ConvertStereoTo51) < 0) {
+ return -1;
+ }
+ src_channels = 6;
+ cvt->len_mult *= 3;
+ cvt->len_ratio *= 3;
+ }
+ /* Quad -> 5.1 [-> 7.1] */
+ if ((src_channels == 4) && (dst_channels >= 6)) {
+ if (SDL_AddAudioCVTFilter(cvt, SDL_ConvertQuadTo51) < 0) {
+ return -1;
+ }
+ src_channels = 6;
+ cvt->len_mult = (cvt->len_mult * 3 + 1) / 2;
+ cvt->len_ratio *= 1.5;
+ }
+ /* [[Mono ->] Stereo ->] 5.1 -> 7.1 */
+ if ((src_channels == 6) && (dst_channels == 8)) {
+ if (SDL_AddAudioCVTFilter(cvt, SDL_Convert51To71) < 0) {
+ return -1;
+ }
+ src_channels = 8;
+ cvt->len_mult = (cvt->len_mult * 4 + 2) / 3;
+ /* Should be numerically exact with every valid input to this
+ function */
+ cvt->len_ratio = cvt->len_ratio * 4 / 3;
+ }
+ /* [Mono ->] Stereo -> Quad */
+ if ((src_channels == 2) && (dst_channels == 4)) {
+ if (SDL_AddAudioCVTFilter(cvt, SDL_ConvertStereoToQuad) < 0) {
+ return -1;
+ }
+ src_channels = 4;
+ cvt->len_mult *= 2;
+ cvt->len_ratio *= 2;
+ }
+ } else if (src_channels > dst_channels) {
+ /* Downmixing */
+ /* 7.1 -> 5.1 [-> Stereo [-> Mono]] */
+ /* 7.1 -> 5.1 [-> Quad] */
+ if ((src_channels == 8) && (dst_channels <= 6)) {
+ if (SDL_AddAudioCVTFilter(cvt, SDL_Convert71To51) < 0) {
+ return -1;
+ }
+ src_channels = 6;
+ cvt->len_ratio *= 0.75;
+ }
+ /* [7.1 ->] 5.1 -> Stereo [-> Mono] */
+ if ((src_channels == 6) && (dst_channels <= 2)) {
+ if (SDL_AddAudioCVTFilter(cvt, SDL_Convert51ToStereo) < 0) {
+ return -1;
+ }
+ src_channels = 2;
+ cvt->len_ratio /= 3;
+ }
+ /* 5.1 -> Quad */
+ if ((src_channels == 6) && (dst_channels == 4)) {
+ if (SDL_AddAudioCVTFilter(cvt, SDL_Convert51ToQuad) < 0) {
+ return -1;
+ }
+ src_channels = 4;
+ cvt->len_ratio = cvt->len_ratio * 2 / 3;
+ }
+ /* Quad -> Stereo [-> Mono] */
+ if ((src_channels == 4) && (dst_channels <= 2)) {
+ if (SDL_AddAudioCVTFilter(cvt, SDL_ConvertQuadToStereo) < 0) {
+ return -1;
+ }
+ src_channels = 2;
+ cvt->len_ratio /= 2;
+ }
+ /* [... ->] Stereo -> Mono */
+ if ((src_channels == 2) && (dst_channels == 1)) {
+ SDL_AudioFilter filter = NULL;
+
+ #if HAVE_SSE3_INTRINSICS
+ if (SDL_HasSSE3()) {
+ filter = SDL_ConvertStereoToMono_SSE3;
+ }
+ #endif
+
+ if (!filter) {
+ filter = SDL_ConvertStereoToMono;
+ }
+
+ if (SDL_AddAudioCVTFilter(cvt, filter) < 0) {
+ return -1;
+ }
+
+ src_channels = 1;
+ cvt->len_ratio /= 2;
+ }
+ }
+
+ if (src_channels != dst_channels) {
+ /* All combinations of supported channel counts should have been
+ handled by now, but let's be defensive */
+ return SDL_SetError("Invalid channel combination");
+ }
+
+ /* Do rate conversion, if necessary. Updates (cvt). */
+ if (SDL_BuildAudioResampleCVT(cvt, dst_channels, src_rate, dst_rate) < 0) {
+ return -1; /* shouldn't happen, but just in case... */
+ }
+
+ /* Move to final data type. */
+ if (SDL_BuildAudioTypeCVTFromFloat(cvt, dst_fmt) < 0) {
+ return -1; /* shouldn't happen, but just in case... */
+ }
+
+ cvt->needed = (cvt->filter_index != 0);
+ return (cvt->needed);
+}
+
+typedef int (*SDL_ResampleAudioStreamFunc)(SDL_AudioStream *stream, const void *inbuf, const int inbuflen, void *outbuf, const int outbuflen);
+typedef void (*SDL_ResetAudioStreamResamplerFunc)(SDL_AudioStream *stream);
+typedef void (*SDL_CleanupAudioStreamResamplerFunc)(SDL_AudioStream *stream);
+
+struct _SDL_AudioStream
+{
+ SDL_AudioCVT cvt_before_resampling;
+ SDL_AudioCVT cvt_after_resampling;
+ SDL_DataQueue *queue;
+ SDL_bool first_run;
+ Uint8 *staging_buffer;
+ int staging_buffer_size;
+ int staging_buffer_filled;
+ Uint8 *work_buffer_base; /* maybe unaligned pointer from SDL_realloc(). */
+ int work_buffer_len;
+ int src_sample_frame_size;
+ SDL_AudioFormat src_format;
+ Uint8 src_channels;
+ int src_rate;
+ int dst_sample_frame_size;
+ SDL_AudioFormat dst_format;
+ Uint8 dst_channels;
+ int dst_rate;
+ double rate_incr;
+ Uint8 pre_resample_channels;
+ int packetlen;
+ int resampler_padding_samples;
+ float *resampler_padding;
+ void *resampler_state;
+ SDL_ResampleAudioStreamFunc resampler_func;
+ SDL_ResetAudioStreamResamplerFunc reset_resampler_func;
+ SDL_CleanupAudioStreamResamplerFunc cleanup_resampler_func;
+};
+
+static Uint8 *
+EnsureStreamBufferSize(SDL_AudioStream *stream, const int newlen)
+{
+ Uint8 *ptr;
+ size_t offset;
+
+ if (stream->work_buffer_len >= newlen) {
+ ptr = stream->work_buffer_base;
+ } else {
+ ptr = (Uint8 *) SDL_realloc(stream->work_buffer_base, newlen + 32);
+ if (!ptr) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ /* Make sure we're aligned to 16 bytes for SIMD code. */
+ stream->work_buffer_base = ptr;
+ stream->work_buffer_len = newlen;
+ }
+
+ offset = ((size_t) ptr) & 15;
+ return offset ? ptr + (16 - offset) : ptr;
+}
+
+#ifdef HAVE_LIBSAMPLERATE_H
+static int
+SDL_ResampleAudioStream_SRC(SDL_AudioStream *stream, const void *_inbuf, const int inbuflen, void *_outbuf, const int outbuflen)
+{
+ const float *inbuf = (const float *) _inbuf;
+ float *outbuf = (float *) _outbuf;
+ const int framelen = sizeof(float) * stream->pre_resample_channels;
+ SRC_STATE *state = (SRC_STATE *)stream->resampler_state;
+ SRC_DATA data;
+ int result;
+
+ SDL_assert(inbuf != ((const float *) outbuf)); /* SDL_AudioStreamPut() shouldn't allow in-place resamples. */
+
+ data.data_in = (float *)inbuf; /* Older versions of libsamplerate had a non-const pointer, but didn't write to it */
+ data.input_frames = inbuflen / framelen;
+ data.input_frames_used = 0;
+
+ data.data_out = outbuf;
+ data.output_frames = outbuflen / framelen;
+
+ data.end_of_input = 0;
+ data.src_ratio = stream->rate_incr;
+
+ result = SRC_src_process(state, &data);
+ if (result != 0) {
+ SDL_SetError("src_process() failed: %s", SRC_src_strerror(result));
+ return 0;
+ }
+
+ /* If this fails, we need to store them off somewhere */
+ SDL_assert(data.input_frames_used == data.input_frames);
+
+ return data.output_frames_gen * (sizeof(float) * stream->pre_resample_channels);
+}
+
+static void
+SDL_ResetAudioStreamResampler_SRC(SDL_AudioStream *stream)
+{
+ SRC_src_reset((SRC_STATE *)stream->resampler_state);
+}
+
+static void
+SDL_CleanupAudioStreamResampler_SRC(SDL_AudioStream *stream)
+{
+ SRC_STATE *state = (SRC_STATE *)stream->resampler_state;
+ if (state) {
+ SRC_src_delete(state);
+ }
+
+ stream->resampler_state = NULL;
+ stream->resampler_func = NULL;
+ stream->reset_resampler_func = NULL;
+ stream->cleanup_resampler_func = NULL;
+}
+
+static SDL_bool
+SetupLibSampleRateResampling(SDL_AudioStream *stream)
+{
+ int result = 0;
+ SRC_STATE *state = NULL;
+
+ if (SRC_available) {
+ state = SRC_src_new(SRC_converter, stream->pre_resample_channels, &result);
+ if (!state) {
+ SDL_SetError("src_new() failed: %s", SRC_src_strerror(result));
+ }
+ }
+
+ if (!state) {
+ SDL_CleanupAudioStreamResampler_SRC(stream);
+ return SDL_FALSE;
+ }
+
+ stream->resampler_state = state;
+ stream->resampler_func = SDL_ResampleAudioStream_SRC;
+ stream->reset_resampler_func = SDL_ResetAudioStreamResampler_SRC;
+ stream->cleanup_resampler_func = SDL_CleanupAudioStreamResampler_SRC;
+
+ return SDL_TRUE;
+}
+#endif /* HAVE_LIBSAMPLERATE_H */
+
+
+static int
+SDL_ResampleAudioStream(SDL_AudioStream *stream, const void *_inbuf, const int inbuflen, void *_outbuf, const int outbuflen)
+{
+ const Uint8 *inbufend = ((const Uint8 *) _inbuf) + inbuflen;
+ const float *inbuf = (const float *) _inbuf;
+ float *outbuf = (float *) _outbuf;
+ const int chans = (int) stream->pre_resample_channels;
+ const int inrate = stream->src_rate;
+ const int outrate = stream->dst_rate;
+ const int paddingsamples = stream->resampler_padding_samples;
+ const int paddingbytes = paddingsamples * sizeof (float);
+ float *lpadding = (float *) stream->resampler_state;
+ const float *rpadding = (const float *) inbufend; /* we set this up so there are valid padding samples at the end of the input buffer. */
+ const int cpy = SDL_min(inbuflen, paddingbytes);
+ int retval;
+
+ SDL_assert(inbuf != ((const float *) outbuf)); /* SDL_AudioStreamPut() shouldn't allow in-place resamples. */
+
+ retval = SDL_ResampleAudio(chans, inrate, outrate, lpadding, rpadding, inbuf, inbuflen, outbuf, outbuflen);
+
+ /* update our left padding with end of current input, for next run. */
+ SDL_memcpy((lpadding + paddingsamples) - (cpy / sizeof (float)), inbufend - cpy, cpy);
+ return retval;
+}
+
+static void
+SDL_ResetAudioStreamResampler(SDL_AudioStream *stream)
+{
+ /* set all the padding to silence. */
+ const int len = stream->resampler_padding_samples;
+ SDL_memset(stream->resampler_state, '\0', len * sizeof (float));
+}
+
+static void
+SDL_CleanupAudioStreamResampler(SDL_AudioStream *stream)
+{
+ SDL_free(stream->resampler_state);
+}
+
+SDL_AudioStream *
+SDL_NewAudioStream(const SDL_AudioFormat src_format,
+ const Uint8 src_channels,
+ const int src_rate,
+ const SDL_AudioFormat dst_format,
+ const Uint8 dst_channels,
+ const int dst_rate)
+{
+ const int packetlen = 4096; /* !!! FIXME: good enough for now. */
+ Uint8 pre_resample_channels;
+ SDL_AudioStream *retval;
+
+ retval = (SDL_AudioStream *) SDL_calloc(1, sizeof (SDL_AudioStream));
+ if (!retval) {
+ return NULL;
+ }
+
+ /* If increasing channels, do it after resampling, since we'd just
+ do more work to resample duplicate channels. If we're decreasing, do
+ it first so we resample the interpolated data instead of interpolating
+ the resampled data (!!! FIXME: decide if that works in practice, though!). */
+ pre_resample_channels = SDL_min(src_channels, dst_channels);
+
+ retval->first_run = SDL_TRUE;
+ retval->src_sample_frame_size = (SDL_AUDIO_BITSIZE(src_format) / 8) * src_channels;
+ retval->src_format = src_format;
+ retval->src_channels = src_channels;
+ retval->src_rate = src_rate;
+ retval->dst_sample_frame_size = (SDL_AUDIO_BITSIZE(dst_format) / 8) * dst_channels;
+ retval->dst_format = dst_format;
+ retval->dst_channels = dst_channels;
+ retval->dst_rate = dst_rate;
+ retval->pre_resample_channels = pre_resample_channels;
+ retval->packetlen = packetlen;
+ retval->rate_incr = ((double) dst_rate) / ((double) src_rate);
+ retval->resampler_padding_samples = ResamplerPadding(retval->src_rate, retval->dst_rate) * pre_resample_channels;
+ retval->resampler_padding = (float *) SDL_calloc(retval->resampler_padding_samples, sizeof (float));
+
+ if (retval->resampler_padding == NULL) {
+ SDL_FreeAudioStream(retval);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ retval->staging_buffer_size = ((retval->resampler_padding_samples / retval->pre_resample_channels) * retval->src_sample_frame_size);
+ if (retval->staging_buffer_size > 0) {
+ retval->staging_buffer = (Uint8 *) SDL_malloc(retval->staging_buffer_size);
+ if (retval->staging_buffer == NULL) {
+ SDL_FreeAudioStream(retval);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ }
+
+ /* Not resampling? It's an easy conversion (and maybe not even that!) */
+ if (src_rate == dst_rate) {
+ retval->cvt_before_resampling.needed = SDL_FALSE;
+ if (SDL_BuildAudioCVT(&retval->cvt_after_resampling, src_format, src_channels, dst_rate, dst_format, dst_channels, dst_rate) < 0) {
+ SDL_FreeAudioStream(retval);
+ return NULL; /* SDL_BuildAudioCVT should have called SDL_SetError. */
+ }
+ } else {
+ /* Don't resample at first. Just get us to Float32 format. */
+ /* !!! FIXME: convert to int32 on devices without hardware float. */
+ if (SDL_BuildAudioCVT(&retval->cvt_before_resampling, src_format, src_channels, src_rate, AUDIO_F32SYS, pre_resample_channels, src_rate) < 0) {
+ SDL_FreeAudioStream(retval);
+ return NULL; /* SDL_BuildAudioCVT should have called SDL_SetError. */
+ }
+
+#ifdef HAVE_LIBSAMPLERATE_H
+ SetupLibSampleRateResampling(retval);
+#endif
+
+ if (!retval->resampler_func) {
+ retval->resampler_state = SDL_calloc(retval->resampler_padding_samples, sizeof (float));
+ if (!retval->resampler_state) {
+ SDL_FreeAudioStream(retval);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ if (SDL_PrepareResampleFilter() < 0) {
+ SDL_free(retval->resampler_state);
+ retval->resampler_state = NULL;
+ SDL_FreeAudioStream(retval);
+ return NULL;
+ }
+
+ retval->resampler_func = SDL_ResampleAudioStream;
+ retval->reset_resampler_func = SDL_ResetAudioStreamResampler;
+ retval->cleanup_resampler_func = SDL_CleanupAudioStreamResampler;
+ }
+
+ /* Convert us to the final format after resampling. */
+ if (SDL_BuildAudioCVT(&retval->cvt_after_resampling, AUDIO_F32SYS, pre_resample_channels, dst_rate, dst_format, dst_channels, dst_rate) < 0) {
+ SDL_FreeAudioStream(retval);
+ return NULL; /* SDL_BuildAudioCVT should have called SDL_SetError. */
+ }
+ }
+
+ retval->queue = SDL_NewDataQueue(packetlen, packetlen * 2);
+ if (!retval->queue) {
+ SDL_FreeAudioStream(retval);
+ return NULL; /* SDL_NewDataQueue should have called SDL_SetError. */
+ }
+
+ return retval;
+}
+
+static int
+SDL_AudioStreamPutInternal(SDL_AudioStream *stream, const void *buf, int len, int *maxputbytes)
+{
+ int buflen = len;
+ int workbuflen;
+ Uint8 *workbuf;
+ Uint8 *resamplebuf = NULL;
+ int resamplebuflen = 0;
+ int neededpaddingbytes;
+ int paddingbytes;
+
+ /* !!! FIXME: several converters can take advantage of SIMD, but only
+ !!! FIXME: if the data is aligned to 16 bytes. EnsureStreamBufferSize()
+ !!! FIXME: guarantees the buffer will align, but the
+ !!! FIXME: converters will iterate over the data backwards if
+ !!! FIXME: the output grows, and this means we won't align if buflen
+ !!! FIXME: isn't a multiple of 16. In these cases, we should chop off
+ !!! FIXME: a few samples at the end and convert them separately. */
+
+ /* no padding prepended on first run. */
+ neededpaddingbytes = stream->resampler_padding_samples * sizeof (float);
+ paddingbytes = stream->first_run ? 0 : neededpaddingbytes;
+ stream->first_run = SDL_FALSE;
+
+ /* Make sure the work buffer can hold all the data we need at once... */
+ workbuflen = buflen;
+ if (stream->cvt_before_resampling.needed) {
+ workbuflen *= stream->cvt_before_resampling.len_mult;
+ }
+
+ if (stream->dst_rate != stream->src_rate) {
+ /* resamples can't happen in place, so make space for second buf. */
+ const int framesize = stream->pre_resample_channels * sizeof (float);
+ const int frames = workbuflen / framesize;
+ resamplebuflen = ((int) SDL_ceil(frames * stream->rate_incr)) * framesize;
+ #if DEBUG_AUDIOSTREAM
+ printf("AUDIOSTREAM: will resample %d bytes to %d (ratio=%.6f)\n", workbuflen, resamplebuflen, stream->rate_incr);
+ #endif
+ workbuflen += resamplebuflen;
+ }
+
+ if (stream->cvt_after_resampling.needed) {
+ /* !!! FIXME: buffer might be big enough already? */
+ workbuflen *= stream->cvt_after_resampling.len_mult;
+ }
+
+ workbuflen += neededpaddingbytes;
+
+ #if DEBUG_AUDIOSTREAM
+ printf("AUDIOSTREAM: Putting %d bytes of preconverted audio, need %d byte work buffer\n", buflen, workbuflen);
+ #endif
+
+ workbuf = EnsureStreamBufferSize(stream, workbuflen);
+ if (!workbuf) {
+ return -1; /* probably out of memory. */
+ }
+
+ resamplebuf = workbuf; /* default if not resampling. */
+
+ SDL_memcpy(workbuf + paddingbytes, buf, buflen);
+
+ if (stream->cvt_before_resampling.needed) {
+ stream->cvt_before_resampling.buf = workbuf + paddingbytes;
+ stream->cvt_before_resampling.len = buflen;
+ if (SDL_ConvertAudio(&stream->cvt_before_resampling) == -1) {
+ return -1; /* uhoh! */
+ }
+ buflen = stream->cvt_before_resampling.len_cvt;
+
+ #if DEBUG_AUDIOSTREAM
+ printf("AUDIOSTREAM: After initial conversion we have %d bytes\n", buflen);
+ #endif
+ }
+
+ if (stream->dst_rate != stream->src_rate) {
+ /* save off some samples at the end; they are used for padding now so
+ the resampler is coherent and then used at the start of the next
+ put operation. Prepend last put operation's padding, too. */
+
+ /* prepend prior put's padding. :P */
+ if (paddingbytes) {
+ SDL_memcpy(workbuf, stream->resampler_padding, paddingbytes);
+ buflen += paddingbytes;
+ }
+
+ /* save off the data at the end for the next run. */
+ SDL_memcpy(stream->resampler_padding, workbuf + (buflen - neededpaddingbytes), neededpaddingbytes);
+
+ resamplebuf = workbuf + buflen; /* skip to second piece of workbuf. */
+ SDL_assert(buflen >= neededpaddingbytes);
+ if (buflen > neededpaddingbytes) {
+ buflen = stream->resampler_func(stream, workbuf, buflen - neededpaddingbytes, resamplebuf, resamplebuflen);
+ } else {
+ buflen = 0;
+ }
+
+ #if DEBUG_AUDIOSTREAM
+ printf("AUDIOSTREAM: After resampling we have %d bytes\n", buflen);
+ #endif
+ }
+
+ if (stream->cvt_after_resampling.needed && (buflen > 0)) {
+ stream->cvt_after_resampling.buf = resamplebuf;
+ stream->cvt_after_resampling.len = buflen;
+ if (SDL_ConvertAudio(&stream->cvt_after_resampling) == -1) {
+ return -1; /* uhoh! */
+ }
+ buflen = stream->cvt_after_resampling.len_cvt;
+
+ #if DEBUG_AUDIOSTREAM
+ printf("AUDIOSTREAM: After final conversion we have %d bytes\n", buflen);
+ #endif
+ }
+
+ #if DEBUG_AUDIOSTREAM
+ printf("AUDIOSTREAM: Final output is %d bytes\n", buflen);
+ #endif
+
+ if (maxputbytes) {
+ const int maxbytes = *maxputbytes;
+ if (buflen > maxbytes)
+ buflen = maxbytes;
+ *maxputbytes -= buflen;
+ }
+
+ /* resamplebuf holds the final output, even if we didn't resample. */
+ return buflen ? SDL_WriteToDataQueue(stream->queue, resamplebuf, buflen) : 0;
+}
+
+int
+SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, int len)
+{
+ /* !!! FIXME: several converters can take advantage of SIMD, but only
+ !!! FIXME: if the data is aligned to 16 bytes. EnsureStreamBufferSize()
+ !!! FIXME: guarantees the buffer will align, but the
+ !!! FIXME: converters will iterate over the data backwards if
+ !!! FIXME: the output grows, and this means we won't align if buflen
+ !!! FIXME: isn't a multiple of 16. In these cases, we should chop off
+ !!! FIXME: a few samples at the end and convert them separately. */
+
+ #if DEBUG_AUDIOSTREAM
+ printf("AUDIOSTREAM: wants to put %d preconverted bytes\n", buflen);
+ #endif
+
+ if (!stream) {
+ return SDL_InvalidParamError("stream");
+ } else if (!buf) {
+ return SDL_InvalidParamError("buf");
+ } else if (len == 0) {
+ return 0; /* nothing to do. */
+ } else if ((len % stream->src_sample_frame_size) != 0) {
+ return SDL_SetError("Can't add partial sample frames");
+ }
+
+ if (!stream->cvt_before_resampling.needed &&
+ (stream->dst_rate == stream->src_rate) &&
+ !stream->cvt_after_resampling.needed) {
+ #if DEBUG_AUDIOSTREAM
+ printf("AUDIOSTREAM: no conversion needed at all, queueing %d bytes.\n", len);
+ #endif
+ return SDL_WriteToDataQueue(stream->queue, buf, len);
+ }
+
+ while (len > 0) {
+ int amount;
+
+ /* If we don't have a staging buffer or we're given enough data that
+ we don't need to store it for later, skip the staging process.
+ */
+ if (!stream->staging_buffer_filled && len >= stream->staging_buffer_size) {
+ return SDL_AudioStreamPutInternal(stream, buf, len, NULL);
+ }
+
+ /* If there's not enough data to fill the staging buffer, just save it */
+ if ((stream->staging_buffer_filled + len) < stream->staging_buffer_size) {
+ SDL_memcpy(stream->staging_buffer + stream->staging_buffer_filled, buf, len);
+ stream->staging_buffer_filled += len;
+ return 0;
+ }
+
+ /* Fill the staging buffer, process it, and continue */
+ amount = (stream->staging_buffer_size - stream->staging_buffer_filled);
+ SDL_assert(amount > 0);
+ SDL_memcpy(stream->staging_buffer + stream->staging_buffer_filled, buf, amount);
+ stream->staging_buffer_filled = 0;
+ if (SDL_AudioStreamPutInternal(stream, stream->staging_buffer, stream->staging_buffer_size, NULL) < 0) {
+ return -1;
+ }
+ buf = (void *)((Uint8 *)buf + amount);
+ len -= amount;
+ }
+ return 0;
+}
+
+int SDL_AudioStreamFlush(SDL_AudioStream *stream)
+{
+ if (!stream) {
+ return SDL_InvalidParamError("stream");
+ }
+
+ #if DEBUG_AUDIOSTREAM
+ printf("AUDIOSTREAM: flushing! staging_buffer_filled=%d bytes\n", stream->staging_buffer_filled);
+ #endif
+
+ /* shouldn't use a staging buffer if we're not resampling. */
+ SDL_assert((stream->dst_rate != stream->src_rate) || (stream->staging_buffer_filled == 0));
+
+ if (stream->staging_buffer_filled > 0) {
+ /* push the staging buffer + silence. We need to flush out not just
+ the staging buffer, but the piece that the stream was saving off
+ for right-side resampler padding. */
+ const SDL_bool first_run = stream->first_run;
+ const int filled = stream->staging_buffer_filled;
+ int actual_input_frames = filled / stream->src_sample_frame_size;
+ if (!first_run)
+ actual_input_frames += stream->resampler_padding_samples / stream->pre_resample_channels;
+
+ if (actual_input_frames > 0) { /* don't bother if nothing to flush. */
+ /* This is how many bytes we're expecting without silence appended. */
+ int flush_remaining = ((int) SDL_ceil(actual_input_frames * stream->rate_incr)) * stream->dst_sample_frame_size;
+
+ #if DEBUG_AUDIOSTREAM
+ printf("AUDIOSTREAM: flushing with padding to get max %d bytes!\n", flush_remaining);
+ #endif
+
+ SDL_memset(stream->staging_buffer + filled, '\0', stream->staging_buffer_size - filled);
+ if (SDL_AudioStreamPutInternal(stream, stream->staging_buffer, stream->staging_buffer_size, &flush_remaining) < 0) {
+ return -1;
+ }
+
+ /* we have flushed out (or initially filled) the pending right-side
+ resampler padding, but we need to push more silence to guarantee
+ the staging buffer is fully flushed out, too. */
+ SDL_memset(stream->staging_buffer, '\0', filled);
+ if (SDL_AudioStreamPutInternal(stream, stream->staging_buffer, stream->staging_buffer_size, &flush_remaining) < 0) {
+ return -1;
+ }
+ }
+ }
+
+ stream->staging_buffer_filled = 0;
+ stream->first_run = SDL_TRUE;
+
+ return 0;
+}
+
+/* get converted/resampled data from the stream */
+int
+SDL_AudioStreamGet(SDL_AudioStream *stream, void *buf, int len)
+{
+ #if DEBUG_AUDIOSTREAM
+ printf("AUDIOSTREAM: want to get %d converted bytes\n", len);
+ #endif
+
+ if (!stream) {
+ return SDL_InvalidParamError("stream");
+ } else if (!buf) {
+ return SDL_InvalidParamError("buf");
+ } else if (len <= 0) {
+ return 0; /* nothing to do. */
+ } else if ((len % stream->dst_sample_frame_size) != 0) {
+ return SDL_SetError("Can't request partial sample frames");
+ }
+
+ return (int) SDL_ReadFromDataQueue(stream->queue, buf, len);
+}
+
+/* number of converted/resampled bytes available */
+int
+SDL_AudioStreamAvailable(SDL_AudioStream *stream)
+{
+ return stream ? (int) SDL_CountDataQueue(stream->queue) : 0;
+}
+
+void
+SDL_AudioStreamClear(SDL_AudioStream *stream)
+{
+ if (!stream) {
+ SDL_InvalidParamError("stream");
+ } else {
+ SDL_ClearDataQueue(stream->queue, stream->packetlen * 2);
+ if (stream->reset_resampler_func) {
+ stream->reset_resampler_func(stream);
+ }
+ stream->first_run = SDL_TRUE;
+ stream->staging_buffer_filled = 0;
+ }
+}
+
+/* dispose of a stream */
+void
+SDL_FreeAudioStream(SDL_AudioStream *stream)
+{
+ if (stream) {
+ if (stream->cleanup_resampler_func) {
+ stream->cleanup_resampler_func(stream);
+ }
+ SDL_FreeDataQueue(stream->queue);
+ SDL_free(stream->staging_buffer);
+ SDL_free(stream->work_buffer_base);
+ SDL_free(stream->resampler_padding);
+ SDL_free(stream);
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/audio/SDL_audiodev.c b/src/3rdparty/SDL2/src/audio/SDL_audiodev.c
new file mode 100644
index 0000000..d0b94a0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/SDL_audiodev.c
@@ -0,0 +1,124 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* Get the name of the audio device we use for output */
+
+#if SDL_AUDIO_DRIVER_NETBSD || SDL_AUDIO_DRIVER_OSS || SDL_AUDIO_DRIVER_SUNAUDIO
+
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h> /* For close() */
+
+#include "SDL_stdinc.h"
+#include "SDL_audiodev_c.h"
+
+#ifndef _PATH_DEV_DSP
+#if defined(__NETBSD__) || defined(__OPENBSD__)
+#define _PATH_DEV_DSP "/dev/audio"
+#else
+#define _PATH_DEV_DSP "/dev/dsp"
+#endif
+#endif
+#ifndef _PATH_DEV_DSP24
+#define _PATH_DEV_DSP24 "/dev/sound/dsp"
+#endif
+#ifndef _PATH_DEV_AUDIO
+#define _PATH_DEV_AUDIO "/dev/audio"
+#endif
+
+static void
+test_device(const int iscapture, const char *fname, int flags, int (*test) (int fd))
+{
+ struct stat sb;
+ if ((stat(fname, &sb) == 0) && (S_ISCHR(sb.st_mode))) {
+ const int audio_fd = open(fname, flags, 0);
+ if (audio_fd >= 0) {
+ const int okay = test(audio_fd);
+ close(audio_fd);
+ if (okay) {
+ static size_t dummyhandle = 0;
+ dummyhandle++;
+ SDL_assert(dummyhandle != 0);
+ SDL_AddAudioDevice(iscapture, fname, (void *) dummyhandle);
+ }
+ }
+ }
+}
+
+static int
+test_stub(int fd)
+{
+ return 1;
+}
+
+static void
+SDL_EnumUnixAudioDevices_Internal(const int iscapture, const int classic, int (*test)(int))
+{
+ const int flags = iscapture ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT;
+ const char *audiodev;
+ char audiopath[1024];
+
+ if (test == NULL)
+ test = test_stub;
+
+ /* Figure out what our audio device is */
+ if (((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) &&
+ ((audiodev = SDL_getenv("AUDIODEV")) == NULL)) {
+ if (classic) {
+ audiodev = _PATH_DEV_AUDIO;
+ } else {
+ struct stat sb;
+
+ /* Added support for /dev/sound/\* in Linux 2.4 */
+ if (((stat("/dev/sound", &sb) == 0) && S_ISDIR(sb.st_mode))
+ && ((stat(_PATH_DEV_DSP24, &sb) == 0)
+ && S_ISCHR(sb.st_mode))) {
+ audiodev = _PATH_DEV_DSP24;
+ } else {
+ audiodev = _PATH_DEV_DSP;
+ }
+ }
+ }
+ test_device(iscapture, audiodev, flags, test);
+
+ if (SDL_strlen(audiodev) < (sizeof(audiopath) - 3)) {
+ int instance = 0;
+ while (instance <= 64) {
+ SDL_snprintf(audiopath, SDL_arraysize(audiopath),
+ "%s%d", audiodev, instance);
+ instance++;
+ test_device(iscapture, audiopath, flags, test);
+ }
+ }
+}
+
+void
+SDL_EnumUnixAudioDevices(const int classic, int (*test)(int))
+{
+ SDL_EnumUnixAudioDevices_Internal(SDL_TRUE, classic, test);
+ SDL_EnumUnixAudioDevices_Internal(SDL_FALSE, classic, test);
+}
+
+#endif /* Audio driver selection */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/SDL_audiodev_c.h b/src/3rdparty/SDL2/src/audio/SDL_audiodev_c.h
new file mode 100644
index 0000000..15928d1
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/SDL_audiodev_c.h
@@ -0,0 +1,38 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL.h"
+#include "../SDL_internal.h"
+#include "SDL_sysaudio.h"
+
+/* Open the audio device for playback, and don't block if busy */
+/* #define USE_BLOCKING_WRITES */
+
+#ifdef USE_BLOCKING_WRITES
+#define OPEN_FLAGS_OUTPUT O_WRONLY
+#define OPEN_FLAGS_INPUT O_RDONLY
+#else
+#define OPEN_FLAGS_OUTPUT (O_WRONLY|O_NONBLOCK)
+#define OPEN_FLAGS_INPUT (O_RDONLY|O_NONBLOCK)
+#endif
+
+extern void SDL_EnumUnixAudioDevices(const int classic, int (*test)(int));
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/SDL_audiotypecvt.c b/src/3rdparty/SDL2/src/audio/SDL_audiotypecvt.c
new file mode 100644
index 0000000..2fbd916
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/SDL_audiotypecvt.c
@@ -0,0 +1,829 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../SDL_internal.h"
+#include "SDL_audio.h"
+#include "SDL_audio_c.h"
+#include "SDL_cpuinfo.h"
+#include "SDL_assert.h"
+
+/* !!! FIXME: write NEON code. */
+#define HAVE_NEON_INTRINSICS 0
+
+#ifdef __SSE2__
+#define HAVE_SSE2_INTRINSICS 1
+#endif
+
+#if defined(__x86_64__) && HAVE_SSE2_INTRINSICS
+#define NEED_SCALAR_CONVERTER_FALLBACKS 0 /* x86_64 guarantees SSE2. */
+#elif __MACOSX__ && HAVE_SSE2_INTRINSICS
+#define NEED_SCALAR_CONVERTER_FALLBACKS 0 /* Mac OS X/Intel guarantees SSE2. */
+#elif defined(__ARM_ARCH) && (__ARM_ARCH >= 8) && HAVE_NEON_INTRINSICS
+#define NEED_SCALAR_CONVERTER_FALLBACKS 0 /* ARMv8+ promise NEON. */
+#elif defined(__APPLE__) && defined(__ARM_ARCH) && (__ARM_ARCH >= 7) && HAVE_NEON_INTRINSICS
+#define NEED_SCALAR_CONVERTER_FALLBACKS 0 /* All Apple ARMv7 chips promise NEON support. */
+#endif
+
+/* Set to zero if platform is guaranteed to use a SIMD codepath here. */
+#ifndef NEED_SCALAR_CONVERTER_FALLBACKS
+#define NEED_SCALAR_CONVERTER_FALLBACKS 1
+#endif
+
+/* Function pointers set to a CPU-specific implementation. */
+SDL_AudioFilter SDL_Convert_S8_to_F32 = NULL;
+SDL_AudioFilter SDL_Convert_U8_to_F32 = NULL;
+SDL_AudioFilter SDL_Convert_S16_to_F32 = NULL;
+SDL_AudioFilter SDL_Convert_U16_to_F32 = NULL;
+SDL_AudioFilter SDL_Convert_S32_to_F32 = NULL;
+SDL_AudioFilter SDL_Convert_F32_to_S8 = NULL;
+SDL_AudioFilter SDL_Convert_F32_to_U8 = NULL;
+SDL_AudioFilter SDL_Convert_F32_to_S16 = NULL;
+SDL_AudioFilter SDL_Convert_F32_to_U16 = NULL;
+SDL_AudioFilter SDL_Convert_F32_to_S32 = NULL;
+
+
+#define DIVBY128 0.0078125f
+#define DIVBY32768 0.000030517578125f
+#define DIVBY2147483648 0.00000000046566128730773926
+
+
+#if NEED_SCALAR_CONVERTER_FALLBACKS
+static void SDLCALL
+SDL_Convert_S8_to_F32_Scalar(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const Sint8 *src = ((const Sint8 *) (cvt->buf + cvt->len_cvt)) - 1;
+ float *dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_S8", "AUDIO_F32");
+
+ for (i = cvt->len_cvt; i; --i, --src, --dst) {
+ *dst = ((float) *src) * DIVBY128;
+ }
+
+ cvt->len_cvt *= 4;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
+ }
+}
+
+static void SDLCALL
+SDL_Convert_U8_to_F32_Scalar(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const Uint8 *src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
+ float *dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_U8", "AUDIO_F32");
+
+ for (i = cvt->len_cvt; i; --i, --src, --dst) {
+ *dst = (((float) *src) * DIVBY128) - 1.0f;
+ }
+
+ cvt->len_cvt *= 4;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
+ }
+}
+
+static void SDLCALL
+SDL_Convert_S16_to_F32_Scalar(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const Sint16 *src = ((const Sint16 *) (cvt->buf + cvt->len_cvt)) - 1;
+ float *dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_S16", "AUDIO_F32");
+
+ for (i = cvt->len_cvt / sizeof (Sint16); i; --i, --src, --dst) {
+ *dst = ((float) *src) * DIVBY32768;
+ }
+
+ cvt->len_cvt *= 2;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
+ }
+}
+
+static void SDLCALL
+SDL_Convert_U16_to_F32_Scalar(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const Uint16 *src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
+ float *dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_U16", "AUDIO_F32");
+
+ for (i = cvt->len_cvt / sizeof (Uint16); i; --i, --src, --dst) {
+ *dst = (((float) *src) * DIVBY32768) - 1.0f;
+ }
+
+ cvt->len_cvt *= 2;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
+ }
+}
+
+static void SDLCALL
+SDL_Convert_S32_to_F32_Scalar(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const Sint32 *src = (const Sint32 *) cvt->buf;
+ float *dst = (float *) cvt->buf;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_S32", "AUDIO_F32");
+
+ for (i = cvt->len_cvt / sizeof (Sint32); i; --i, ++src, ++dst) {
+ *dst = (float) (((double) *src) * DIVBY2147483648);
+ }
+
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
+ }
+}
+
+static void SDLCALL
+SDL_Convert_F32_to_S8_Scalar(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const float *src = (const float *) cvt->buf;
+ Sint8 *dst = (Sint8 *) cvt->buf;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S8");
+
+ for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
+ const float sample = *src;
+ if (sample > 1.0f) {
+ *dst = 127;
+ } else if (sample < -1.0f) {
+ *dst = -127;
+ } else {
+ *dst = (Sint8)(sample * 127.0f);
+ }
+ }
+
+ cvt->len_cvt /= 4;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_S8);
+ }
+}
+
+static void SDLCALL
+SDL_Convert_F32_to_U8_Scalar(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const float *src = (const float *) cvt->buf;
+ Uint8 *dst = (Uint8 *) cvt->buf;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_U8");
+
+ for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
+ const float sample = *src;
+ if (sample > 1.0f) {
+ *dst = 255;
+ } else if (sample < -1.0f) {
+ *dst = 0;
+ } else {
+ *dst = (Uint8)((sample + 1.0f) * 127.0f);
+ }
+ }
+
+ cvt->len_cvt /= 4;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_U8);
+ }
+}
+
+static void SDLCALL
+SDL_Convert_F32_to_S16_Scalar(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const float *src = (const float *) cvt->buf;
+ Sint16 *dst = (Sint16 *) cvt->buf;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S16");
+
+ for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
+ const float sample = *src;
+ if (sample > 1.0f) {
+ *dst = 32767;
+ } else if (sample < -1.0f) {
+ *dst = -32767;
+ } else {
+ *dst = (Sint16)(sample * 32767.0f);
+ }
+ }
+
+ cvt->len_cvt /= 2;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_S16SYS);
+ }
+}
+
+static void SDLCALL
+SDL_Convert_F32_to_U16_Scalar(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const float *src = (const float *) cvt->buf;
+ Uint16 *dst = (Uint16 *) cvt->buf;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_U16");
+
+ for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
+ const float sample = *src;
+ if (sample > 1.0f) {
+ *dst = 65534;
+ } else if (sample < -1.0f) {
+ *dst = 0;
+ } else {
+ *dst = (Uint16)((sample + 1.0f) * 32767.0f);
+ }
+ }
+
+ cvt->len_cvt /= 2;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_U16SYS);
+ }
+}
+
+static void SDLCALL
+SDL_Convert_F32_to_S32_Scalar(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const float *src = (const float *) cvt->buf;
+ Sint32 *dst = (Sint32 *) cvt->buf;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S32");
+
+ for (i = cvt->len_cvt / sizeof (float); i; --i, ++src, ++dst) {
+ const float sample = *src;
+ if (sample > 1.0f) {
+ *dst = 2147483647;
+ } else if (sample < -1.0f) {
+ *dst = -2147483647;
+ } else {
+ *dst = (Sint32)((double)sample * 2147483647.0);
+ }
+ }
+
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_S32SYS);
+ }
+}
+#endif
+
+
+#if HAVE_SSE2_INTRINSICS
+static void SDLCALL
+SDL_Convert_S8_to_F32_SSE2(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const Sint8 *src = ((const Sint8 *) (cvt->buf + cvt->len_cvt)) - 1;
+ float *dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_S8", "AUDIO_F32 (using SSE2)");
+
+ /* Get dst aligned to 16 bytes (since buffer is growing, we don't have to worry about overreading from src) */
+ for (i = cvt->len_cvt; i && (((size_t) (dst-15)) & 15); --i, --src, --dst) {
+ *dst = ((float) *src) * DIVBY128;
+ }
+
+ src -= 15; dst -= 15; /* adjust to read SSE blocks from the start. */
+ SDL_assert(!i || ((((size_t) dst) & 15) == 0));
+
+ /* Make sure src is aligned too. */
+ if ((((size_t) src) & 15) == 0) {
+ /* Aligned! Do SSE blocks as long as we have 16 bytes available. */
+ const __m128i *mmsrc = (const __m128i *) src;
+ const __m128i zero = _mm_setzero_si128();
+ const __m128 divby128 = _mm_set1_ps(DIVBY128);
+ while (i >= 16) { /* 16 * 8-bit */
+ const __m128i bytes = _mm_load_si128(mmsrc); /* get 16 sint8 into an XMM register. */
+ /* treat as int16, shift left to clear every other sint16, then back right with sign-extend. Now sint16. */
+ const __m128i shorts1 = _mm_srai_epi16(_mm_slli_epi16(bytes, 8), 8);
+ /* right-shift-sign-extend gets us sint16 with the other set of values. */
+ const __m128i shorts2 = _mm_srai_epi16(bytes, 8);
+ /* unpack against zero to make these int32, shift to make them sign-extend, convert to float, multiply. Whew! */
+ const __m128 floats1 = _mm_mul_ps(_mm_cvtepi32_ps(_mm_srai_epi32(_mm_slli_epi32(_mm_unpacklo_epi16(shorts1, zero), 16), 16)), divby128);
+ const __m128 floats2 = _mm_mul_ps(_mm_cvtepi32_ps(_mm_srai_epi32(_mm_slli_epi32(_mm_unpacklo_epi16(shorts2, zero), 16), 16)), divby128);
+ const __m128 floats3 = _mm_mul_ps(_mm_cvtepi32_ps(_mm_srai_epi32(_mm_slli_epi32(_mm_unpackhi_epi16(shorts1, zero), 16), 16)), divby128);
+ const __m128 floats4 = _mm_mul_ps(_mm_cvtepi32_ps(_mm_srai_epi32(_mm_slli_epi32(_mm_unpackhi_epi16(shorts2, zero), 16), 16)), divby128);
+ /* Interleave back into correct order, store. */
+ _mm_store_ps(dst, _mm_unpacklo_ps(floats1, floats2));
+ _mm_store_ps(dst+4, _mm_unpackhi_ps(floats1, floats2));
+ _mm_store_ps(dst+8, _mm_unpacklo_ps(floats3, floats4));
+ _mm_store_ps(dst+12, _mm_unpackhi_ps(floats3, floats4));
+ i -= 16; mmsrc--; dst -= 16;
+ }
+
+ src = (const Sint8 *) mmsrc;
+ }
+
+ src += 15; dst += 15; /* adjust for any scalar finishing. */
+
+ /* Finish off any leftovers with scalar operations. */
+ while (i) {
+ *dst = ((float) *src) * DIVBY128;
+ i--; src--; dst--;
+ }
+
+ cvt->len_cvt *= 4;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
+ }
+}
+
+static void SDLCALL
+SDL_Convert_U8_to_F32_SSE2(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const Uint8 *src = ((const Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
+ float *dst = ((float *) (cvt->buf + cvt->len_cvt * 4)) - 1;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_U8", "AUDIO_F32 (using SSE2)");
+
+ /* Get dst aligned to 16 bytes (since buffer is growing, we don't have to worry about overreading from src) */
+ for (i = cvt->len_cvt; i && (((size_t) (dst-15)) & 15); --i, --src, --dst) {
+ *dst = (((float) *src) * DIVBY128) - 1.0f;
+ }
+
+ src -= 15; dst -= 15; /* adjust to read SSE blocks from the start. */
+ SDL_assert(!i || ((((size_t) dst) & 15) == 0));
+
+ /* Make sure src is aligned too. */
+ if ((((size_t) src) & 15) == 0) {
+ /* Aligned! Do SSE blocks as long as we have 16 bytes available. */
+ const __m128i *mmsrc = (const __m128i *) src;
+ const __m128i zero = _mm_setzero_si128();
+ const __m128 divby128 = _mm_set1_ps(DIVBY128);
+ const __m128 minus1 = _mm_set1_ps(-1.0f);
+ while (i >= 16) { /* 16 * 8-bit */
+ const __m128i bytes = _mm_load_si128(mmsrc); /* get 16 uint8 into an XMM register. */
+ /* treat as int16, shift left to clear every other sint16, then back right with zero-extend. Now uint16. */
+ const __m128i shorts1 = _mm_srli_epi16(_mm_slli_epi16(bytes, 8), 8);
+ /* right-shift-zero-extend gets us uint16 with the other set of values. */
+ const __m128i shorts2 = _mm_srli_epi16(bytes, 8);
+ /* unpack against zero to make these int32, convert to float, multiply, add. Whew! */
+ /* Note that AVX2 can do floating point multiply+add in one instruction, fwiw. SSE2 cannot. */
+ const __m128 floats1 = _mm_add_ps(_mm_mul_ps(_mm_cvtepi32_ps(_mm_unpacklo_epi16(shorts1, zero)), divby128), minus1);
+ const __m128 floats2 = _mm_add_ps(_mm_mul_ps(_mm_cvtepi32_ps(_mm_unpacklo_epi16(shorts2, zero)), divby128), minus1);
+ const __m128 floats3 = _mm_add_ps(_mm_mul_ps(_mm_cvtepi32_ps(_mm_unpackhi_epi16(shorts1, zero)), divby128), minus1);
+ const __m128 floats4 = _mm_add_ps(_mm_mul_ps(_mm_cvtepi32_ps(_mm_unpackhi_epi16(shorts2, zero)), divby128), minus1);
+ /* Interleave back into correct order, store. */
+ _mm_store_ps(dst, _mm_unpacklo_ps(floats1, floats2));
+ _mm_store_ps(dst+4, _mm_unpackhi_ps(floats1, floats2));
+ _mm_store_ps(dst+8, _mm_unpacklo_ps(floats3, floats4));
+ _mm_store_ps(dst+12, _mm_unpackhi_ps(floats3, floats4));
+ i -= 16; mmsrc--; dst -= 16;
+ }
+
+ src = (const Uint8 *) mmsrc;
+ }
+
+ src += 15; dst += 15; /* adjust for any scalar finishing. */
+
+ /* Finish off any leftovers with scalar operations. */
+ while (i) {
+ *dst = (((float) *src) * DIVBY128) - 1.0f;
+ i--; src--; dst--;
+ }
+
+ cvt->len_cvt *= 4;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
+ }
+}
+
+static void SDLCALL
+SDL_Convert_S16_to_F32_SSE2(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const Sint16 *src = ((const Sint16 *) (cvt->buf + cvt->len_cvt)) - 1;
+ float *dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_S16", "AUDIO_F32 (using SSE2)");
+
+ /* Get dst aligned to 16 bytes (since buffer is growing, we don't have to worry about overreading from src) */
+ for (i = cvt->len_cvt / sizeof (Sint16); i && (((size_t) (dst-7)) & 15); --i, --src, --dst) {
+ *dst = ((float) *src) * DIVBY32768;
+ }
+
+ src -= 7; dst -= 7; /* adjust to read SSE blocks from the start. */
+ SDL_assert(!i || ((((size_t) dst) & 15) == 0));
+
+ /* Make sure src is aligned too. */
+ if ((((size_t) src) & 15) == 0) {
+ /* Aligned! Do SSE blocks as long as we have 16 bytes available. */
+ const __m128 divby32768 = _mm_set1_ps(DIVBY32768);
+ while (i >= 8) { /* 8 * 16-bit */
+ const __m128i ints = _mm_load_si128((__m128i const *) src); /* get 8 sint16 into an XMM register. */
+ /* treat as int32, shift left to clear every other sint16, then back right with sign-extend. Now sint32. */
+ const __m128i a = _mm_srai_epi32(_mm_slli_epi32(ints, 16), 16);
+ /* right-shift-sign-extend gets us sint32 with the other set of values. */
+ const __m128i b = _mm_srai_epi32(ints, 16);
+ /* Interleave these back into the right order, convert to float, multiply, store. */
+ _mm_store_ps(dst, _mm_mul_ps(_mm_cvtepi32_ps(_mm_unpacklo_epi32(a, b)), divby32768));
+ _mm_store_ps(dst+4, _mm_mul_ps(_mm_cvtepi32_ps(_mm_unpackhi_epi32(a, b)), divby32768));
+ i -= 8; src -= 8; dst -= 8;
+ }
+ }
+
+ src += 7; dst += 7; /* adjust for any scalar finishing. */
+
+ /* Finish off any leftovers with scalar operations. */
+ while (i) {
+ *dst = ((float) *src) * DIVBY32768;
+ i--; src--; dst--;
+ }
+
+ cvt->len_cvt *= 2;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
+ }
+}
+
+static void SDLCALL
+SDL_Convert_U16_to_F32_SSE2(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const Uint16 *src = ((const Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
+ float *dst = ((float *) (cvt->buf + cvt->len_cvt * 2)) - 1;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_U16", "AUDIO_F32 (using SSE2)");
+
+ /* Get dst aligned to 16 bytes (since buffer is growing, we don't have to worry about overreading from src) */
+ for (i = cvt->len_cvt / sizeof (Sint16); i && (((size_t) (dst-7)) & 15); --i, --src, --dst) {
+ *dst = (((float) *src) * DIVBY32768) - 1.0f;
+ }
+
+ src -= 7; dst -= 7; /* adjust to read SSE blocks from the start. */
+ SDL_assert(!i || ((((size_t) dst) & 15) == 0));
+
+ /* Make sure src is aligned too. */
+ if ((((size_t) src) & 15) == 0) {
+ /* Aligned! Do SSE blocks as long as we have 16 bytes available. */
+ const __m128 divby32768 = _mm_set1_ps(DIVBY32768);
+ const __m128 minus1 = _mm_set1_ps(1.0f);
+ while (i >= 8) { /* 8 * 16-bit */
+ const __m128i ints = _mm_load_si128((__m128i const *) src); /* get 8 sint16 into an XMM register. */
+ /* treat as int32, shift left to clear every other sint16, then back right with zero-extend. Now sint32. */
+ const __m128i a = _mm_srli_epi32(_mm_slli_epi32(ints, 16), 16);
+ /* right-shift-sign-extend gets us sint32 with the other set of values. */
+ const __m128i b = _mm_srli_epi32(ints, 16);
+ /* Interleave these back into the right order, convert to float, multiply, store. */
+ _mm_store_ps(dst, _mm_add_ps(_mm_mul_ps(_mm_cvtepi32_ps(_mm_unpacklo_epi32(a, b)), divby32768), minus1));
+ _mm_store_ps(dst+4, _mm_add_ps(_mm_mul_ps(_mm_cvtepi32_ps(_mm_unpackhi_epi32(a, b)), divby32768), minus1));
+ i -= 8; src -= 8; dst -= 8;
+ }
+ }
+
+ src += 7; dst += 7; /* adjust for any scalar finishing. */
+
+ /* Finish off any leftovers with scalar operations. */
+ while (i) {
+ *dst = (((float) *src) * DIVBY32768) - 1.0f;
+ i--; src--; dst--;
+ }
+
+ cvt->len_cvt *= 2;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
+ }
+}
+
+#if defined(__GNUC__) && (__GNUC__ < 4)
+/* these were added as of gcc-4.0: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19418 */
+static inline __m128 _mm_castsi128_ps(__m128i __A) {
+ return (__m128) __A;
+}
+static inline __m128i _mm_castps_si128(__m128 __A) {
+ return (__m128i) __A;
+}
+#endif
+
+static void SDLCALL
+SDL_Convert_S32_to_F32_SSE2(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const Sint32 *src = (const Sint32 *) cvt->buf;
+ float *dst = (float *) cvt->buf;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_S32", "AUDIO_F32 (using SSE2)");
+
+ /* Get dst aligned to 16 bytes */
+ for (i = cvt->len_cvt / sizeof (Sint32); i && (((size_t) dst) & 15); --i, ++src, ++dst) {
+ *dst = (float) (((double) *src) * DIVBY2147483648);
+ }
+
+ SDL_assert(!i || ((((size_t) dst) & 15) == 0));
+ SDL_assert(!i || ((((size_t) src) & 15) == 0));
+
+ {
+ /* Aligned! Do SSE blocks as long as we have 16 bytes available. */
+ const __m128d divby2147483648 = _mm_set1_pd(DIVBY2147483648);
+ const __m128i *mmsrc = (const __m128i *) src;
+ while (i >= 4) { /* 4 * sint32 */
+ const __m128i ints = _mm_load_si128(mmsrc);
+ /* bitshift the whole register over, so _mm_cvtepi32_pd can read the top ints in the bottom of the vector. */
+ const __m128d doubles1 = _mm_mul_pd(_mm_cvtepi32_pd(_mm_srli_si128(ints, 8)), divby2147483648);
+ const __m128d doubles2 = _mm_mul_pd(_mm_cvtepi32_pd(ints), divby2147483648);
+ /* convert to float32, bitshift/or to get these into a vector to store. */
+ _mm_store_ps(dst, _mm_castsi128_ps(_mm_or_si128(_mm_slli_si128(_mm_castps_si128(_mm_cvtpd_ps(doubles1)), 8), _mm_castps_si128(_mm_cvtpd_ps(doubles2)))));
+ i -= 4; mmsrc++; dst += 4;
+ }
+ src = (const Sint32 *) mmsrc;
+ }
+
+ /* Finish off any leftovers with scalar operations. */
+ while (i) {
+ *dst = (float) (((double) *src) * DIVBY2147483648);
+ i--; src++; dst++;
+ }
+
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_F32SYS);
+ }
+}
+
+static void SDLCALL
+SDL_Convert_F32_to_S8_SSE2(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const float *src = (const float *) cvt->buf;
+ Sint8 *dst = (Sint8 *) cvt->buf;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S8 (using SSE2)");
+
+ /* Get dst aligned to 16 bytes */
+ for (i = cvt->len_cvt / sizeof (float); i && (((size_t) dst) & 15); --i, ++src, ++dst) {
+ *dst = (Sint8) (*src * 127.0f);
+ }
+
+ SDL_assert(!i || ((((size_t) dst) & 15) == 0));
+
+ /* Make sure src is aligned too. */
+ if ((((size_t) src) & 15) == 0) {
+ /* Aligned! Do SSE blocks as long as we have 16 bytes available. */
+ const __m128 mulby127 = _mm_set1_ps(127.0f);
+ __m128i *mmdst = (__m128i *) dst;
+ while (i >= 16) { /* 16 * float32 */
+ const __m128i ints1 = _mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(src), mulby127)); /* load 4 floats, convert to sint32 */
+ const __m128i ints2 = _mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(src+4), mulby127)); /* load 4 floats, convert to sint32 */
+ const __m128i ints3 = _mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(src+8), mulby127)); /* load 4 floats, convert to sint32 */
+ const __m128i ints4 = _mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(src+12), mulby127)); /* load 4 floats, convert to sint32 */
+ _mm_store_si128(mmdst, _mm_packs_epi16(_mm_packs_epi32(ints1, ints2), _mm_packs_epi32(ints3, ints4))); /* pack down, store out. */
+ i -= 16; src += 16; mmdst++;
+ }
+ dst = (Sint8 *) mmdst;
+ }
+
+ /* Finish off any leftovers with scalar operations. */
+ while (i) {
+ *dst = (Sint8) (*src * 127.0f);
+ i--; src++; dst++;
+ }
+
+ cvt->len_cvt /= 4;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_S8);
+ }
+}
+
+static void SDLCALL
+SDL_Convert_F32_to_U8_SSE2(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const float *src = (const float *) cvt->buf;
+ Uint8 *dst = (Uint8 *) cvt->buf;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_U8 (using SSE2)");
+
+ /* Get dst aligned to 16 bytes */
+ for (i = cvt->len_cvt / sizeof (float); i && (((size_t) dst) & 15); --i, ++src, ++dst) {
+ *dst = (Uint8) ((*src + 1.0f) * 127.0f);
+ }
+
+ SDL_assert(!i || ((((size_t) dst) & 15) == 0));
+
+ /* Make sure src is aligned too. */
+ if ((((size_t) src) & 15) == 0) {
+ /* Aligned! Do SSE blocks as long as we have 16 bytes available. */
+ const __m128 add1 = _mm_set1_ps(1.0f);
+ const __m128 mulby127 = _mm_set1_ps(127.0f);
+ __m128i *mmdst = (__m128i *) dst;
+ while (i >= 16) { /* 16 * float32 */
+ const __m128i ints1 = _mm_cvtps_epi32(_mm_mul_ps(_mm_add_ps(_mm_load_ps(src), add1), mulby127)); /* load 4 floats, convert to sint32 */
+ const __m128i ints2 = _mm_cvtps_epi32(_mm_mul_ps(_mm_add_ps(_mm_load_ps(src+4), add1), mulby127)); /* load 4 floats, convert to sint32 */
+ const __m128i ints3 = _mm_cvtps_epi32(_mm_mul_ps(_mm_add_ps(_mm_load_ps(src+8), add1), mulby127)); /* load 4 floats, convert to sint32 */
+ const __m128i ints4 = _mm_cvtps_epi32(_mm_mul_ps(_mm_add_ps(_mm_load_ps(src+12), add1), mulby127)); /* load 4 floats, convert to sint32 */
+ _mm_store_si128(mmdst, _mm_packus_epi16(_mm_packs_epi32(ints1, ints2), _mm_packs_epi32(ints3, ints4))); /* pack down, store out. */
+ i -= 16; src += 16; mmdst++;
+ }
+ dst = (Uint8 *) mmdst;
+ }
+
+ /* Finish off any leftovers with scalar operations. */
+ while (i) {
+ *dst = (Uint8) ((*src + 1.0f) * 127.0f);
+ i--; src++; dst++;
+ }
+
+ cvt->len_cvt /= 4;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_U8);
+ }
+}
+
+static void SDLCALL
+SDL_Convert_F32_to_S16_SSE2(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const float *src = (const float *) cvt->buf;
+ Sint16 *dst = (Sint16 *) cvt->buf;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S16 (using SSE2)");
+
+ /* Get dst aligned to 16 bytes */
+ for (i = cvt->len_cvt / sizeof (float); i && (((size_t) dst) & 15); --i, ++src, ++dst) {
+ *dst = (Sint16) (*src * 32767.0f);
+ }
+
+ SDL_assert(!i || ((((size_t) dst) & 15) == 0));
+
+ /* Make sure src is aligned too. */
+ if ((((size_t) src) & 15) == 0) {
+ /* Aligned! Do SSE blocks as long as we have 16 bytes available. */
+ const __m128 mulby32767 = _mm_set1_ps(32767.0f);
+ __m128i *mmdst = (__m128i *) dst;
+ while (i >= 8) { /* 8 * float32 */
+ const __m128i ints1 = _mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(src), mulby32767)); /* load 4 floats, convert to sint32 */
+ const __m128i ints2 = _mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(src+4), mulby32767)); /* load 4 floats, convert to sint32 */
+ _mm_store_si128(mmdst, _mm_packs_epi32(ints1, ints2)); /* pack to sint16, store out. */
+ i -= 8; src += 8; mmdst++;
+ }
+ dst = (Sint16 *) mmdst;
+ }
+
+ /* Finish off any leftovers with scalar operations. */
+ while (i) {
+ *dst = (Sint16) (*src * 32767.0f);
+ i--; src++; dst++;
+ }
+
+ cvt->len_cvt /= 2;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_S16SYS);
+ }
+}
+
+static void SDLCALL
+SDL_Convert_F32_to_U16_SSE2(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const float *src = (const float *) cvt->buf;
+ Uint16 *dst = (Uint16 *) cvt->buf;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_U16 (using SSE2)");
+
+ /* Get dst aligned to 16 bytes */
+ for (i = cvt->len_cvt / sizeof (float); i && (((size_t) dst) & 15); --i, ++src, ++dst) {
+ *dst = (Uint16) ((*src + 1.0f) * 32767.0f);
+ }
+
+ SDL_assert(!i || ((((size_t) dst) & 15) == 0));
+
+ /* Make sure src is aligned too. */
+ if ((((size_t) src) & 15) == 0) {
+ /* Aligned! Do SSE blocks as long as we have 16 bytes available. */
+ /* This calculates differently than the scalar path because SSE2 can't
+ pack int32 data down to unsigned int16. _mm_packs_epi32 does signed
+ saturation, so that would corrupt our data. _mm_packus_epi32 exists,
+ but not before SSE 4.1. So we convert from float to sint16, packing
+ that down with legit signed saturation, and then xor the top bit
+ against 1. This results in the correct unsigned 16-bit value, even
+ though it looks like dark magic. */
+ const __m128 mulby32767 = _mm_set1_ps(32767.0f);
+ const __m128i topbit = _mm_set1_epi16(-32768);
+ __m128i *mmdst = (__m128i *) dst;
+ while (i >= 8) { /* 8 * float32 */
+ const __m128i ints1 = _mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(src), mulby32767)); /* load 4 floats, convert to sint32 */
+ const __m128i ints2 = _mm_cvtps_epi32(_mm_mul_ps(_mm_load_ps(src+4), mulby32767)); /* load 4 floats, convert to sint32 */
+ _mm_store_si128(mmdst, _mm_xor_si128(_mm_packs_epi32(ints1, ints2), topbit)); /* pack to sint16, xor top bit, store out. */
+ i -= 8; src += 8; mmdst++;
+ }
+ dst = (Uint16 *) mmdst;
+ }
+
+ /* Finish off any leftovers with scalar operations. */
+ while (i) {
+ *dst = (Uint16) ((*src + 1.0f) * 32767.0f);
+ i--; src++; dst++;
+ }
+
+ cvt->len_cvt /= 2;
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_U16SYS);
+ }
+}
+
+static void SDLCALL
+SDL_Convert_F32_to_S32_SSE2(SDL_AudioCVT *cvt, SDL_AudioFormat format)
+{
+ const float *src = (const float *) cvt->buf;
+ Sint32 *dst = (Sint32 *) cvt->buf;
+ int i;
+
+ LOG_DEBUG_CONVERT("AUDIO_F32", "AUDIO_S32 (using SSE2)");
+
+ /* Get dst aligned to 16 bytes */
+ for (i = cvt->len_cvt / sizeof (float); i && (((size_t) dst) & 15); --i, ++src, ++dst) {
+ *dst = (Sint32) (((double) *src) * 2147483647.0);
+ }
+
+ SDL_assert(!i || ((((size_t) dst) & 15) == 0));
+ SDL_assert(!i || ((((size_t) src) & 15) == 0));
+
+ {
+ /* Aligned! Do SSE blocks as long as we have 16 bytes available. */
+ const __m128d mulby2147483647 = _mm_set1_pd(2147483647.0);
+ __m128i *mmdst = (__m128i *) dst;
+ while (i >= 4) { /* 4 * float32 */
+ const __m128 floats = _mm_load_ps(src);
+ /* bitshift the whole register over, so _mm_cvtps_pd can read the top floats in the bottom of the vector. */
+ const __m128d doubles1 = _mm_mul_pd(_mm_cvtps_pd(_mm_castsi128_ps(_mm_srli_si128(_mm_castps_si128(floats), 8))), mulby2147483647);
+ const __m128d doubles2 = _mm_mul_pd(_mm_cvtps_pd(floats), mulby2147483647);
+ _mm_store_si128(mmdst, _mm_or_si128(_mm_slli_si128(_mm_cvtpd_epi32(doubles1), 8), _mm_cvtpd_epi32(doubles2)));
+ i -= 4; src += 4; mmdst++;
+ }
+ dst = (Sint32 *) mmdst;
+ }
+
+ /* Finish off any leftovers with scalar operations. */
+ while (i) {
+ *dst = (Sint32) (((double) *src) * 2147483647.0);
+ i--; src++; dst++;
+ }
+
+ if (cvt->filters[++cvt->filter_index]) {
+ cvt->filters[cvt->filter_index](cvt, AUDIO_S32SYS);
+ }
+}
+#endif
+
+
+void SDL_ChooseAudioConverters(void)
+{
+ static SDL_bool converters_chosen = SDL_FALSE;
+
+ if (converters_chosen) {
+ return;
+ }
+
+#define SET_CONVERTER_FUNCS(fntype) \
+ SDL_Convert_S8_to_F32 = SDL_Convert_S8_to_F32_##fntype; \
+ SDL_Convert_U8_to_F32 = SDL_Convert_U8_to_F32_##fntype; \
+ SDL_Convert_S16_to_F32 = SDL_Convert_S16_to_F32_##fntype; \
+ SDL_Convert_U16_to_F32 = SDL_Convert_U16_to_F32_##fntype; \
+ SDL_Convert_S32_to_F32 = SDL_Convert_S32_to_F32_##fntype; \
+ SDL_Convert_F32_to_S8 = SDL_Convert_F32_to_S8_##fntype; \
+ SDL_Convert_F32_to_U8 = SDL_Convert_F32_to_U8_##fntype; \
+ SDL_Convert_F32_to_S16 = SDL_Convert_F32_to_S16_##fntype; \
+ SDL_Convert_F32_to_U16 = SDL_Convert_F32_to_U16_##fntype; \
+ SDL_Convert_F32_to_S32 = SDL_Convert_F32_to_S32_##fntype; \
+ converters_chosen = SDL_TRUE
+
+#if HAVE_SSE2_INTRINSICS
+ if (SDL_HasSSE2()) {
+ SET_CONVERTER_FUNCS(SSE2);
+ return;
+ }
+#endif
+
+#if NEED_SCALAR_CONVERTER_FALLBACKS
+ SET_CONVERTER_FUNCS(Scalar);
+#endif
+
+#undef SET_CONVERTER_FUNCS
+
+ SDL_assert(converters_chosen == SDL_TRUE);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/SDL_mixer.c b/src/3rdparty/SDL2/src/audio/SDL_mixer.c
new file mode 100644
index 0000000..d416a94
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/SDL_mixer.c
@@ -0,0 +1,369 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* This provides the default mixing callback for the SDL audio routines */
+
+#include "SDL_cpuinfo.h"
+#include "SDL_timer.h"
+#include "SDL_audio.h"
+#include "SDL_sysaudio.h"
+
+/* This table is used to add two sound values together and pin
+ * the value to avoid overflow. (used with permission from ARDI)
+ * Changed to use 0xFE instead of 0xFF for better sound quality.
+ */
+static const Uint8 mix8[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03,
+ 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
+ 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
+ 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24,
+ 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A,
+ 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
+ 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
+ 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B,
+ 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
+ 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71,
+ 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C,
+ 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92,
+ 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D,
+ 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8,
+ 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3,
+ 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE,
+ 0xBF, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9,
+ 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4,
+ 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA,
+ 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5,
+ 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFE, 0xFE,
+ 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
+ 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
+ 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
+ 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
+ 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
+ 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
+ 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
+ 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
+ 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
+ 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
+ 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
+ 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE
+};
+
+/* The volume ranges from 0 - 128 */
+#define ADJUST_VOLUME(s, v) (s = (s*v)/SDL_MIX_MAXVOLUME)
+#define ADJUST_VOLUME_U8(s, v) (s = (((s-128)*v)/SDL_MIX_MAXVOLUME)+128)
+
+
+void
+SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src, SDL_AudioFormat format,
+ Uint32 len, int volume)
+{
+ if (volume == 0) {
+ return;
+ }
+
+ switch (format) {
+
+ case AUDIO_U8:
+ {
+#if defined(__GNUC__) && defined(__M68000__) && !defined(__mcoldfire__) && defined(SDL_ASSEMBLY_ROUTINES)
+ SDL_MixAudio_m68k_U8((char *) dst, (char *) src,
+ (unsigned long) len, (long) volume,
+ (char *) mix8);
+#else
+ Uint8 src_sample;
+
+ while (len--) {
+ src_sample = *src;
+ ADJUST_VOLUME_U8(src_sample, volume);
+ *dst = mix8[*dst + src_sample];
+ ++dst;
+ ++src;
+ }
+#endif
+ }
+ break;
+
+ case AUDIO_S8:
+ {
+ Sint8 *dst8, *src8;
+ Sint8 src_sample;
+ int dst_sample;
+ const int max_audioval = ((1 << (8 - 1)) - 1);
+ const int min_audioval = -(1 << (8 - 1));
+
+ src8 = (Sint8 *) src;
+ dst8 = (Sint8 *) dst;
+ while (len--) {
+ src_sample = *src8;
+ ADJUST_VOLUME(src_sample, volume);
+ dst_sample = *dst8 + src_sample;
+ if (dst_sample > max_audioval) {
+ *dst8 = max_audioval;
+ } else if (dst_sample < min_audioval) {
+ *dst8 = min_audioval;
+ } else {
+ *dst8 = dst_sample;
+ }
+ ++dst8;
+ ++src8;
+ }
+ }
+ break;
+
+ case AUDIO_S16LSB:
+ {
+ Sint16 src1, src2;
+ int dst_sample;
+ const int max_audioval = ((1 << (16 - 1)) - 1);
+ const int min_audioval = -(1 << (16 - 1));
+
+ len /= 2;
+ while (len--) {
+ src1 = ((src[1]) << 8 | src[0]);
+ ADJUST_VOLUME(src1, volume);
+ src2 = ((dst[1]) << 8 | dst[0]);
+ src += 2;
+ dst_sample = src1 + src2;
+ if (dst_sample > max_audioval) {
+ dst_sample = max_audioval;
+ } else if (dst_sample < min_audioval) {
+ dst_sample = min_audioval;
+ }
+ dst[0] = dst_sample & 0xFF;
+ dst_sample >>= 8;
+ dst[1] = dst_sample & 0xFF;
+ dst += 2;
+ }
+ }
+ break;
+
+ case AUDIO_S16MSB:
+ {
+#if defined(__GNUC__) && defined(__M68000__) && !defined(__mcoldfire__) && defined(SDL_ASSEMBLY_ROUTINES)
+ SDL_MixAudio_m68k_S16MSB((short *) dst, (short *) src,
+ (unsigned long) len, (long) volume);
+#else
+ Sint16 src1, src2;
+ int dst_sample;
+ const int max_audioval = ((1 << (16 - 1)) - 1);
+ const int min_audioval = -(1 << (16 - 1));
+
+ len /= 2;
+ while (len--) {
+ src1 = ((src[0]) << 8 | src[1]);
+ ADJUST_VOLUME(src1, volume);
+ src2 = ((dst[0]) << 8 | dst[1]);
+ src += 2;
+ dst_sample = src1 + src2;
+ if (dst_sample > max_audioval) {
+ dst_sample = max_audioval;
+ } else if (dst_sample < min_audioval) {
+ dst_sample = min_audioval;
+ }
+ dst[1] = dst_sample & 0xFF;
+ dst_sample >>= 8;
+ dst[0] = dst_sample & 0xFF;
+ dst += 2;
+ }
+#endif
+ }
+ break;
+
+ case AUDIO_U16LSB:
+ {
+ Uint16 src1, src2;
+ int dst_sample;
+ const int max_audioval = 0xFFFF;
+
+ len /= 2;
+ while (len--) {
+ src1 = ((src[1]) << 8 | src[0]);
+ ADJUST_VOLUME(src1, volume);
+ src2 = ((dst[1]) << 8 | dst[0]);
+ src += 2;
+ dst_sample = src1 + src2;
+ if (dst_sample > max_audioval) {
+ dst_sample = max_audioval;
+ }
+ dst[0] = dst_sample & 0xFF;
+ dst_sample >>= 8;
+ dst[1] = dst_sample & 0xFF;
+ dst += 2;
+ }
+ }
+ break;
+
+ case AUDIO_U16MSB:
+ {
+ Uint16 src1, src2;
+ int dst_sample;
+ const int max_audioval = 0xFFFF;
+
+ len /= 2;
+ while (len--) {
+ src1 = ((src[0]) << 8 | src[1]);
+ ADJUST_VOLUME(src1, volume);
+ src2 = ((dst[0]) << 8 | dst[1]);
+ src += 2;
+ dst_sample = src1 + src2;
+ if (dst_sample > max_audioval) {
+ dst_sample = max_audioval;
+ }
+ dst[1] = dst_sample & 0xFF;
+ dst_sample >>= 8;
+ dst[0] = dst_sample & 0xFF;
+ dst += 2;
+ }
+ }
+ break;
+
+ case AUDIO_S32LSB:
+ {
+ const Uint32 *src32 = (Uint32 *) src;
+ Uint32 *dst32 = (Uint32 *) dst;
+ Sint64 src1, src2;
+ Sint64 dst_sample;
+ const Sint64 max_audioval = ((((Sint64) 1) << (32 - 1)) - 1);
+ const Sint64 min_audioval = -(((Sint64) 1) << (32 - 1));
+
+ len /= 4;
+ while (len--) {
+ src1 = (Sint64) ((Sint32) SDL_SwapLE32(*src32));
+ src32++;
+ ADJUST_VOLUME(src1, volume);
+ src2 = (Sint64) ((Sint32) SDL_SwapLE32(*dst32));
+ dst_sample = src1 + src2;
+ if (dst_sample > max_audioval) {
+ dst_sample = max_audioval;
+ } else if (dst_sample < min_audioval) {
+ dst_sample = min_audioval;
+ }
+ *(dst32++) = SDL_SwapLE32((Uint32) ((Sint32) dst_sample));
+ }
+ }
+ break;
+
+ case AUDIO_S32MSB:
+ {
+ const Uint32 *src32 = (Uint32 *) src;
+ Uint32 *dst32 = (Uint32 *) dst;
+ Sint64 src1, src2;
+ Sint64 dst_sample;
+ const Sint64 max_audioval = ((((Sint64) 1) << (32 - 1)) - 1);
+ const Sint64 min_audioval = -(((Sint64) 1) << (32 - 1));
+
+ len /= 4;
+ while (len--) {
+ src1 = (Sint64) ((Sint32) SDL_SwapBE32(*src32));
+ src32++;
+ ADJUST_VOLUME(src1, volume);
+ src2 = (Sint64) ((Sint32) SDL_SwapBE32(*dst32));
+ dst_sample = src1 + src2;
+ if (dst_sample > max_audioval) {
+ dst_sample = max_audioval;
+ } else if (dst_sample < min_audioval) {
+ dst_sample = min_audioval;
+ }
+ *(dst32++) = SDL_SwapBE32((Uint32) ((Sint32) dst_sample));
+ }
+ }
+ break;
+
+ case AUDIO_F32LSB:
+ {
+ const float fmaxvolume = 1.0f / ((float) SDL_MIX_MAXVOLUME);
+ const float fvolume = (float) volume;
+ const float *src32 = (float *) src;
+ float *dst32 = (float *) dst;
+ float src1, src2;
+ double dst_sample;
+ /* !!! FIXME: are these right? */
+ const double max_audioval = 3.402823466e+38F;
+ const double min_audioval = -3.402823466e+38F;
+
+ len /= 4;
+ while (len--) {
+ src1 = ((SDL_SwapFloatLE(*src32) * fvolume) * fmaxvolume);
+ src2 = SDL_SwapFloatLE(*dst32);
+ src32++;
+
+ dst_sample = ((double) src1) + ((double) src2);
+ if (dst_sample > max_audioval) {
+ dst_sample = max_audioval;
+ } else if (dst_sample < min_audioval) {
+ dst_sample = min_audioval;
+ }
+ *(dst32++) = SDL_SwapFloatLE((float) dst_sample);
+ }
+ }
+ break;
+
+ case AUDIO_F32MSB:
+ {
+ const float fmaxvolume = 1.0f / ((float) SDL_MIX_MAXVOLUME);
+ const float fvolume = (float) volume;
+ const float *src32 = (float *) src;
+ float *dst32 = (float *) dst;
+ float src1, src2;
+ double dst_sample;
+ /* !!! FIXME: are these right? */
+ const double max_audioval = 3.402823466e+38F;
+ const double min_audioval = -3.402823466e+38F;
+
+ len /= 4;
+ while (len--) {
+ src1 = ((SDL_SwapFloatBE(*src32) * fvolume) * fmaxvolume);
+ src2 = SDL_SwapFloatBE(*dst32);
+ src32++;
+
+ dst_sample = ((double) src1) + ((double) src2);
+ if (dst_sample > max_audioval) {
+ dst_sample = max_audioval;
+ } else if (dst_sample < min_audioval) {
+ dst_sample = min_audioval;
+ }
+ *(dst32++) = SDL_SwapFloatBE((float) dst_sample);
+ }
+ }
+ break;
+
+ default: /* If this happens... FIXME! */
+ SDL_SetError("SDL_MixAudioFormat(): unknown audio format");
+ return;
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/SDL_sysaudio.h b/src/3rdparty/SDL2/src/audio/SDL_sysaudio.h
new file mode 100644
index 0000000..f0e1f3d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/SDL_sysaudio.h
@@ -0,0 +1,211 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#ifndef SDL_sysaudio_h_
+#define SDL_sysaudio_h_
+
+#include "SDL_mutex.h"
+#include "SDL_thread.h"
+#include "../SDL_dataqueue.h"
+#include "./SDL_audio_c.h"
+
+/* !!! FIXME: These are wordy and unlocalized... */
+#define DEFAULT_OUTPUT_DEVNAME "System audio output device"
+#define DEFAULT_INPUT_DEVNAME "System audio capture device"
+
+/* The SDL audio driver */
+typedef struct SDL_AudioDevice SDL_AudioDevice;
+#define _THIS SDL_AudioDevice *_this
+
+/* Audio targets should call this as devices are added to the system (such as
+ a USB headset being plugged in), and should also be called for
+ for every device found during DetectDevices(). */
+extern void SDL_AddAudioDevice(const int iscapture, const char *name, void *handle);
+
+/* Audio targets should call this as devices are removed, so SDL can update
+ its list of available devices. */
+extern void SDL_RemoveAudioDevice(const int iscapture, void *handle);
+
+/* Audio targets should call this if an opened audio device is lost while
+ being used. This can happen due to i/o errors, or a device being unplugged,
+ etc. If the device is totally gone, please also call SDL_RemoveAudioDevice()
+ as appropriate so SDL's list of devices is accurate. */
+extern void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device);
+
+/* This is the size of a packet when using SDL_QueueAudio(). We allocate
+ these as necessary and pool them, under the assumption that we'll
+ eventually end up with a handful that keep recycling, meeting whatever
+ the app needs. We keep packing data tightly as more arrives to avoid
+ wasting space, and if we get a giant block of data, we'll split them
+ into multiple packets behind the scenes. My expectation is that most
+ apps will have 2-3 of these in the pool. 8k should cover most needs, but
+ if this is crippling for some embedded system, we can #ifdef this.
+ The system preallocates enough packets for 2 callbacks' worth of data. */
+#define SDL_AUDIOBUFFERQUEUE_PACKETLEN (8 * 1024)
+
+typedef struct SDL_AudioDriverImpl
+{
+ void (*DetectDevices) (void);
+ int (*OpenDevice) (_THIS, void *handle, const char *devname, int iscapture);
+ void (*ThreadInit) (_THIS); /* Called by audio thread at start */
+ void (*ThreadDeinit) (_THIS); /* Called by audio thread at end */
+ void (*BeginLoopIteration)(_THIS); /* Called by audio thread at top of loop */
+ void (*WaitDevice) (_THIS);
+ void (*PlayDevice) (_THIS);
+ int (*GetPendingBytes) (_THIS);
+ Uint8 *(*GetDeviceBuf) (_THIS);
+ int (*CaptureFromDevice) (_THIS, void *buffer, int buflen);
+ void (*FlushCapture) (_THIS);
+ void (*PrepareToClose) (_THIS); /**< Called between run and draining wait for playback devices */
+ void (*CloseDevice) (_THIS);
+ void (*LockDevice) (_THIS);
+ void (*UnlockDevice) (_THIS);
+ void (*FreeDeviceHandle) (void *handle); /**< SDL is done with handle from SDL_AddAudioDevice() */
+ void (*Deinitialize) (void);
+
+ /* !!! FIXME: add pause(), so we can optimize instead of mixing silence. */
+
+ /* Some flags to push duplicate code into the core and reduce #ifdefs. */
+ /* !!! FIXME: these should be SDL_bool */
+ int ProvidesOwnCallbackThread;
+ int SkipMixerLock;
+ int HasCaptureSupport;
+ int OnlyHasDefaultOutputDevice;
+ int OnlyHasDefaultCaptureDevice;
+ int AllowsArbitraryDeviceNames;
+} SDL_AudioDriverImpl;
+
+
+typedef struct SDL_AudioDeviceItem
+{
+ void *handle;
+ struct SDL_AudioDeviceItem *next;
+ char name[SDL_VARIABLE_LENGTH_ARRAY];
+} SDL_AudioDeviceItem;
+
+
+typedef struct SDL_AudioDriver
+{
+ /* * * */
+ /* The name of this audio driver */
+ const char *name;
+
+ /* * * */
+ /* The description of this audio driver */
+ const char *desc;
+
+ SDL_AudioDriverImpl impl;
+
+ /* A mutex for device detection */
+ SDL_mutex *detectionLock;
+ SDL_bool captureDevicesRemoved;
+ SDL_bool outputDevicesRemoved;
+ int outputDeviceCount;
+ int inputDeviceCount;
+ SDL_AudioDeviceItem *outputDevices;
+ SDL_AudioDeviceItem *inputDevices;
+} SDL_AudioDriver;
+
+
+/* Define the SDL audio driver structure */
+struct SDL_AudioDevice
+{
+ /* * * */
+ /* Data common to all devices */
+ SDL_AudioDeviceID id;
+
+ /* The device's current audio specification */
+ SDL_AudioSpec spec;
+
+ /* The callback's expected audio specification (converted vs device's spec). */
+ SDL_AudioSpec callbackspec;
+
+ /* Stream that converts and resamples. NULL if not needed. */
+ SDL_AudioStream *stream;
+
+ /* Current state flags */
+ SDL_atomic_t shutdown; /* true if we are signaling the play thread to end. */
+ SDL_atomic_t enabled; /* true if device is functioning and connected. */
+ SDL_atomic_t paused;
+ SDL_bool iscapture;
+
+ /* Scratch buffer used in the bridge between SDL and the user callback. */
+ Uint8 *work_buffer;
+
+ /* Size, in bytes, of work_buffer. */
+ Uint32 work_buffer_len;
+
+ /* A mutex for locking the mixing buffers */
+ SDL_mutex *mixer_lock;
+
+ /* A thread to feed the audio device */
+ SDL_Thread *thread;
+ SDL_threadID threadid;
+
+ /* Queued buffers (if app not using callback). */
+ SDL_DataQueue *buffer_queue;
+
+ /* * * */
+ /* Data private to this driver */
+ struct SDL_PrivateAudioData *hidden;
+
+ void *handle;
+};
+#undef _THIS
+
+typedef struct AudioBootStrap
+{
+ const char *name;
+ const char *desc;
+ int (*init) (SDL_AudioDriverImpl * impl);
+ int demand_only; /* 1==request explicitly, or it won't be available. */
+} AudioBootStrap;
+
+/* Not all of these are available in a given build. Use #ifdefs, etc. */
+extern AudioBootStrap PULSEAUDIO_bootstrap;
+extern AudioBootStrap ALSA_bootstrap;
+extern AudioBootStrap JACK_bootstrap;
+extern AudioBootStrap SNDIO_bootstrap;
+extern AudioBootStrap NETBSDAUDIO_bootstrap;
+extern AudioBootStrap DSP_bootstrap;
+extern AudioBootStrap QSAAUDIO_bootstrap;
+extern AudioBootStrap SUNAUDIO_bootstrap;
+extern AudioBootStrap ARTS_bootstrap;
+extern AudioBootStrap ESD_bootstrap;
+extern AudioBootStrap NACLAUDIO_bootstrap;
+extern AudioBootStrap NAS_bootstrap;
+extern AudioBootStrap WASAPI_bootstrap;
+extern AudioBootStrap DSOUND_bootstrap;
+extern AudioBootStrap WINMM_bootstrap;
+extern AudioBootStrap PAUDIO_bootstrap;
+extern AudioBootStrap HAIKUAUDIO_bootstrap;
+extern AudioBootStrap COREAUDIO_bootstrap;
+extern AudioBootStrap DISKAUDIO_bootstrap;
+extern AudioBootStrap DUMMYAUDIO_bootstrap;
+extern AudioBootStrap FUSIONSOUND_bootstrap;
+extern AudioBootStrap ANDROIDAUDIO_bootstrap;
+extern AudioBootStrap PSPAUDIO_bootstrap;
+extern AudioBootStrap EMSCRIPTENAUDIO_bootstrap;
+
+#endif /* SDL_sysaudio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/SDL_wave.c b/src/3rdparty/SDL2/src/audio/SDL_wave.c
new file mode 100644
index 0000000..2c76a8c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/SDL_wave.c
@@ -0,0 +1,694 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* Microsoft WAVE file loading routines */
+
+#include "SDL_audio.h"
+#include "SDL_wave.h"
+
+
+static int ReadChunk(SDL_RWops * src, Chunk * chunk);
+
+struct MS_ADPCM_decodestate
+{
+ Uint8 hPredictor;
+ Uint16 iDelta;
+ Sint16 iSamp1;
+ Sint16 iSamp2;
+};
+static struct MS_ADPCM_decoder
+{
+ WaveFMT wavefmt;
+ Uint16 wSamplesPerBlock;
+ Uint16 wNumCoef;
+ Sint16 aCoeff[7][2];
+ /* * * */
+ struct MS_ADPCM_decodestate state[2];
+} MS_ADPCM_state;
+
+static int
+InitMS_ADPCM(WaveFMT * format)
+{
+ Uint8 *rogue_feel;
+ int i;
+
+ /* Set the rogue pointer to the MS_ADPCM specific data */
+ MS_ADPCM_state.wavefmt.encoding = SDL_SwapLE16(format->encoding);
+ MS_ADPCM_state.wavefmt.channels = SDL_SwapLE16(format->channels);
+ MS_ADPCM_state.wavefmt.frequency = SDL_SwapLE32(format->frequency);
+ MS_ADPCM_state.wavefmt.byterate = SDL_SwapLE32(format->byterate);
+ MS_ADPCM_state.wavefmt.blockalign = SDL_SwapLE16(format->blockalign);
+ MS_ADPCM_state.wavefmt.bitspersample =
+ SDL_SwapLE16(format->bitspersample);
+ rogue_feel = (Uint8 *) format + sizeof(*format);
+ if (sizeof(*format) == 16) {
+ /* const Uint16 extra_info = ((rogue_feel[1] << 8) | rogue_feel[0]); */
+ rogue_feel += sizeof(Uint16);
+ }
+ MS_ADPCM_state.wSamplesPerBlock = ((rogue_feel[1] << 8) | rogue_feel[0]);
+ rogue_feel += sizeof(Uint16);
+ MS_ADPCM_state.wNumCoef = ((rogue_feel[1] << 8) | rogue_feel[0]);
+ rogue_feel += sizeof(Uint16);
+ if (MS_ADPCM_state.wNumCoef != 7) {
+ SDL_SetError("Unknown set of MS_ADPCM coefficients");
+ return (-1);
+ }
+ for (i = 0; i < MS_ADPCM_state.wNumCoef; ++i) {
+ MS_ADPCM_state.aCoeff[i][0] = ((rogue_feel[1] << 8) | rogue_feel[0]);
+ rogue_feel += sizeof(Uint16);
+ MS_ADPCM_state.aCoeff[i][1] = ((rogue_feel[1] << 8) | rogue_feel[0]);
+ rogue_feel += sizeof(Uint16);
+ }
+ return (0);
+}
+
+static Sint32
+MS_ADPCM_nibble(struct MS_ADPCM_decodestate *state,
+ Uint8 nybble, Sint16 * coeff)
+{
+ const Sint32 max_audioval = ((1 << (16 - 1)) - 1);
+ const Sint32 min_audioval = -(1 << (16 - 1));
+ const Sint32 adaptive[] = {
+ 230, 230, 230, 230, 307, 409, 512, 614,
+ 768, 614, 512, 409, 307, 230, 230, 230
+ };
+ Sint32 new_sample, delta;
+
+ new_sample = ((state->iSamp1 * coeff[0]) +
+ (state->iSamp2 * coeff[1])) / 256;
+ if (nybble & 0x08) {
+ new_sample += state->iDelta * (nybble - 0x10);
+ } else {
+ new_sample += state->iDelta * nybble;
+ }
+ if (new_sample < min_audioval) {
+ new_sample = min_audioval;
+ } else if (new_sample > max_audioval) {
+ new_sample = max_audioval;
+ }
+ delta = ((Sint32) state->iDelta * adaptive[nybble]) / 256;
+ if (delta < 16) {
+ delta = 16;
+ }
+ state->iDelta = (Uint16) delta;
+ state->iSamp2 = state->iSamp1;
+ state->iSamp1 = (Sint16) new_sample;
+ return (new_sample);
+}
+
+static int
+MS_ADPCM_decode(Uint8 ** audio_buf, Uint32 * audio_len)
+{
+ struct MS_ADPCM_decodestate *state[2];
+ Uint8 *freeable, *encoded, *decoded;
+ Sint32 encoded_len, samplesleft;
+ Sint8 nybble;
+ Uint8 stereo;
+ Sint16 *coeff[2];
+ Sint32 new_sample;
+
+ /* Allocate the proper sized output buffer */
+ encoded_len = *audio_len;
+ encoded = *audio_buf;
+ freeable = *audio_buf;
+ *audio_len = (encoded_len / MS_ADPCM_state.wavefmt.blockalign) *
+ MS_ADPCM_state.wSamplesPerBlock *
+ MS_ADPCM_state.wavefmt.channels * sizeof(Sint16);
+ *audio_buf = (Uint8 *) SDL_malloc(*audio_len);
+ if (*audio_buf == NULL) {
+ return SDL_OutOfMemory();
+ }
+ decoded = *audio_buf;
+
+ /* Get ready... Go! */
+ stereo = (MS_ADPCM_state.wavefmt.channels == 2);
+ state[0] = &MS_ADPCM_state.state[0];
+ state[1] = &MS_ADPCM_state.state[stereo];
+ while (encoded_len >= MS_ADPCM_state.wavefmt.blockalign) {
+ /* Grab the initial information for this block */
+ state[0]->hPredictor = *encoded++;
+ if (stereo) {
+ state[1]->hPredictor = *encoded++;
+ }
+ state[0]->iDelta = ((encoded[1] << 8) | encoded[0]);
+ encoded += sizeof(Sint16);
+ if (stereo) {
+ state[1]->iDelta = ((encoded[1] << 8) | encoded[0]);
+ encoded += sizeof(Sint16);
+ }
+ state[0]->iSamp1 = ((encoded[1] << 8) | encoded[0]);
+ encoded += sizeof(Sint16);
+ if (stereo) {
+ state[1]->iSamp1 = ((encoded[1] << 8) | encoded[0]);
+ encoded += sizeof(Sint16);
+ }
+ state[0]->iSamp2 = ((encoded[1] << 8) | encoded[0]);
+ encoded += sizeof(Sint16);
+ if (stereo) {
+ state[1]->iSamp2 = ((encoded[1] << 8) | encoded[0]);
+ encoded += sizeof(Sint16);
+ }
+ coeff[0] = MS_ADPCM_state.aCoeff[state[0]->hPredictor];
+ coeff[1] = MS_ADPCM_state.aCoeff[state[1]->hPredictor];
+
+ /* Store the two initial samples we start with */
+ decoded[0] = state[0]->iSamp2 & 0xFF;
+ decoded[1] = state[0]->iSamp2 >> 8;
+ decoded += 2;
+ if (stereo) {
+ decoded[0] = state[1]->iSamp2 & 0xFF;
+ decoded[1] = state[1]->iSamp2 >> 8;
+ decoded += 2;
+ }
+ decoded[0] = state[0]->iSamp1 & 0xFF;
+ decoded[1] = state[0]->iSamp1 >> 8;
+ decoded += 2;
+ if (stereo) {
+ decoded[0] = state[1]->iSamp1 & 0xFF;
+ decoded[1] = state[1]->iSamp1 >> 8;
+ decoded += 2;
+ }
+
+ /* Decode and store the other samples in this block */
+ samplesleft = (MS_ADPCM_state.wSamplesPerBlock - 2) *
+ MS_ADPCM_state.wavefmt.channels;
+ while (samplesleft > 0) {
+ nybble = (*encoded) >> 4;
+ new_sample = MS_ADPCM_nibble(state[0], nybble, coeff[0]);
+ decoded[0] = new_sample & 0xFF;
+ new_sample >>= 8;
+ decoded[1] = new_sample & 0xFF;
+ decoded += 2;
+
+ nybble = (*encoded) & 0x0F;
+ new_sample = MS_ADPCM_nibble(state[1], nybble, coeff[1]);
+ decoded[0] = new_sample & 0xFF;
+ new_sample >>= 8;
+ decoded[1] = new_sample & 0xFF;
+ decoded += 2;
+
+ ++encoded;
+ samplesleft -= 2;
+ }
+ encoded_len -= MS_ADPCM_state.wavefmt.blockalign;
+ }
+ SDL_free(freeable);
+ return (0);
+}
+
+struct IMA_ADPCM_decodestate
+{
+ Sint32 sample;
+ Sint8 index;
+};
+static struct IMA_ADPCM_decoder
+{
+ WaveFMT wavefmt;
+ Uint16 wSamplesPerBlock;
+ /* * * */
+ struct IMA_ADPCM_decodestate state[2];
+} IMA_ADPCM_state;
+
+static int
+InitIMA_ADPCM(WaveFMT * format)
+{
+ Uint8 *rogue_feel;
+
+ /* Set the rogue pointer to the IMA_ADPCM specific data */
+ IMA_ADPCM_state.wavefmt.encoding = SDL_SwapLE16(format->encoding);
+ IMA_ADPCM_state.wavefmt.channels = SDL_SwapLE16(format->channels);
+ IMA_ADPCM_state.wavefmt.frequency = SDL_SwapLE32(format->frequency);
+ IMA_ADPCM_state.wavefmt.byterate = SDL_SwapLE32(format->byterate);
+ IMA_ADPCM_state.wavefmt.blockalign = SDL_SwapLE16(format->blockalign);
+ IMA_ADPCM_state.wavefmt.bitspersample =
+ SDL_SwapLE16(format->bitspersample);
+ rogue_feel = (Uint8 *) format + sizeof(*format);
+ if (sizeof(*format) == 16) {
+ /* const Uint16 extra_info = ((rogue_feel[1] << 8) | rogue_feel[0]); */
+ rogue_feel += sizeof(Uint16);
+ }
+ IMA_ADPCM_state.wSamplesPerBlock = ((rogue_feel[1] << 8) | rogue_feel[0]);
+ return (0);
+}
+
+static Sint32
+IMA_ADPCM_nibble(struct IMA_ADPCM_decodestate *state, Uint8 nybble)
+{
+ const Sint32 max_audioval = ((1 << (16 - 1)) - 1);
+ const Sint32 min_audioval = -(1 << (16 - 1));
+ const int index_table[16] = {
+ -1, -1, -1, -1,
+ 2, 4, 6, 8,
+ -1, -1, -1, -1,
+ 2, 4, 6, 8
+ };
+ const Sint32 step_table[89] = {
+ 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31,
+ 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130,
+ 143, 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408,
+ 449, 494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282,
+ 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024, 3327,
+ 3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630,
+ 9493, 10442, 11487, 12635, 13899, 15289, 16818, 18500, 20350,
+ 22385, 24623, 27086, 29794, 32767
+ };
+ Sint32 delta, step;
+
+ /* Compute difference and new sample value */
+ if (state->index > 88) {
+ state->index = 88;
+ } else if (state->index < 0) {
+ state->index = 0;
+ }
+ /* explicit cast to avoid gcc warning about using 'char' as array index */
+ step = step_table[(int)state->index];
+ delta = step >> 3;
+ if (nybble & 0x04)
+ delta += step;
+ if (nybble & 0x02)
+ delta += (step >> 1);
+ if (nybble & 0x01)
+ delta += (step >> 2);
+ if (nybble & 0x08)
+ delta = -delta;
+ state->sample += delta;
+
+ /* Update index value */
+ state->index += index_table[nybble];
+
+ /* Clamp output sample */
+ if (state->sample > max_audioval) {
+ state->sample = max_audioval;
+ } else if (state->sample < min_audioval) {
+ state->sample = min_audioval;
+ }
+ return (state->sample);
+}
+
+/* Fill the decode buffer with a channel block of data (8 samples) */
+static void
+Fill_IMA_ADPCM_block(Uint8 * decoded, Uint8 * encoded,
+ int channel, int numchannels,
+ struct IMA_ADPCM_decodestate *state)
+{
+ int i;
+ Sint8 nybble;
+ Sint32 new_sample;
+
+ decoded += (channel * 2);
+ for (i = 0; i < 4; ++i) {
+ nybble = (*encoded) & 0x0F;
+ new_sample = IMA_ADPCM_nibble(state, nybble);
+ decoded[0] = new_sample & 0xFF;
+ new_sample >>= 8;
+ decoded[1] = new_sample & 0xFF;
+ decoded += 2 * numchannels;
+
+ nybble = (*encoded) >> 4;
+ new_sample = IMA_ADPCM_nibble(state, nybble);
+ decoded[0] = new_sample & 0xFF;
+ new_sample >>= 8;
+ decoded[1] = new_sample & 0xFF;
+ decoded += 2 * numchannels;
+
+ ++encoded;
+ }
+}
+
+static int
+IMA_ADPCM_decode(Uint8 ** audio_buf, Uint32 * audio_len)
+{
+ struct IMA_ADPCM_decodestate *state;
+ Uint8 *freeable, *encoded, *decoded;
+ Sint32 encoded_len, samplesleft;
+ unsigned int c, channels;
+
+ /* Check to make sure we have enough variables in the state array */
+ channels = IMA_ADPCM_state.wavefmt.channels;
+ if (channels > SDL_arraysize(IMA_ADPCM_state.state)) {
+ SDL_SetError("IMA ADPCM decoder can only handle %u channels",
+ (unsigned int)SDL_arraysize(IMA_ADPCM_state.state));
+ return (-1);
+ }
+ state = IMA_ADPCM_state.state;
+
+ /* Allocate the proper sized output buffer */
+ encoded_len = *audio_len;
+ encoded = *audio_buf;
+ freeable = *audio_buf;
+ *audio_len = (encoded_len / IMA_ADPCM_state.wavefmt.blockalign) *
+ IMA_ADPCM_state.wSamplesPerBlock *
+ IMA_ADPCM_state.wavefmt.channels * sizeof(Sint16);
+ *audio_buf = (Uint8 *) SDL_malloc(*audio_len);
+ if (*audio_buf == NULL) {
+ return SDL_OutOfMemory();
+ }
+ decoded = *audio_buf;
+
+ /* Get ready... Go! */
+ while (encoded_len >= IMA_ADPCM_state.wavefmt.blockalign) {
+ /* Grab the initial information for this block */
+ for (c = 0; c < channels; ++c) {
+ /* Fill the state information for this block */
+ state[c].sample = ((encoded[1] << 8) | encoded[0]);
+ encoded += 2;
+ if (state[c].sample & 0x8000) {
+ state[c].sample -= 0x10000;
+ }
+ state[c].index = *encoded++;
+ /* Reserved byte in buffer header, should be 0 */
+ if (*encoded++ != 0) {
+ /* Uh oh, corrupt data? Buggy code? */ ;
+ }
+
+ /* Store the initial sample we start with */
+ decoded[0] = (Uint8) (state[c].sample & 0xFF);
+ decoded[1] = (Uint8) (state[c].sample >> 8);
+ decoded += 2;
+ }
+
+ /* Decode and store the other samples in this block */
+ samplesleft = (IMA_ADPCM_state.wSamplesPerBlock - 1) * channels;
+ while (samplesleft > 0) {
+ for (c = 0; c < channels; ++c) {
+ Fill_IMA_ADPCM_block(decoded, encoded,
+ c, channels, &state[c]);
+ encoded += 4;
+ samplesleft -= 8;
+ }
+ decoded += (channels * 8 * 2);
+ }
+ encoded_len -= IMA_ADPCM_state.wavefmt.blockalign;
+ }
+ SDL_free(freeable);
+ return (0);
+}
+
+
+static int
+ConvertSint24ToSint32(Uint8 ** audio_buf, Uint32 * audio_len)
+{
+ const double DIVBY8388608 = 0.00000011920928955078125;
+ const Uint32 original_len = *audio_len;
+ const Uint32 samples = original_len / 3;
+ const Uint32 expanded_len = samples * sizeof (Uint32);
+ Uint8 *ptr = (Uint8 *) SDL_realloc(*audio_buf, expanded_len);
+ const Uint8 *src;
+ Uint32 *dst;
+ Uint32 i;
+
+ if (!ptr) {
+ return SDL_OutOfMemory();
+ }
+
+ *audio_buf = ptr;
+ *audio_len = expanded_len;
+
+ /* work from end to start, since we're expanding in-place. */
+ src = (ptr + original_len) - 3;
+ dst = ((Uint32 *) (ptr + expanded_len)) - 1;
+ for (i = 0; i < samples; i++) {
+ /* There's probably a faster way to do all this. */
+ const Sint32 converted = ((Sint32) ( (((Uint32) src[2]) << 24) |
+ (((Uint32) src[1]) << 16) |
+ (((Uint32) src[0]) << 8) )) >> 8;
+ const double scaled = (((double) converted) * DIVBY8388608);
+ src -= 3;
+ *(dst--) = (Sint32) (scaled * 2147483647.0);
+ }
+
+ return 0;
+}
+
+
+/* GUIDs that are used by WAVE_FORMAT_EXTENSIBLE */
+static const Uint8 extensible_pcm_guid[16] = { 1, 0, 0, 0, 0, 0, 16, 0, 128, 0, 0, 170, 0, 56, 155, 113 };
+static const Uint8 extensible_ieee_guid[16] = { 3, 0, 0, 0, 0, 0, 16, 0, 128, 0, 0, 170, 0, 56, 155, 113 };
+
+SDL_AudioSpec *
+SDL_LoadWAV_RW(SDL_RWops * src, int freesrc,
+ SDL_AudioSpec * spec, Uint8 ** audio_buf, Uint32 * audio_len)
+{
+ int was_error;
+ Chunk chunk;
+ int lenread;
+ int IEEE_float_encoded, MS_ADPCM_encoded, IMA_ADPCM_encoded;
+ int samplesize;
+
+ /* WAV magic header */
+ Uint32 RIFFchunk;
+ Uint32 wavelen = 0;
+ Uint32 WAVEmagic;
+ Uint32 headerDiff = 0;
+
+ /* FMT chunk */
+ WaveFMT *format = NULL;
+ WaveExtensibleFMT *ext = NULL;
+
+ SDL_zero(chunk);
+
+ /* Make sure we are passed a valid data source */
+ was_error = 0;
+ if (src == NULL) {
+ was_error = 1;
+ goto done;
+ }
+
+ /* Check the magic header */
+ RIFFchunk = SDL_ReadLE32(src);
+ wavelen = SDL_ReadLE32(src);
+ if (wavelen == WAVE) { /* The RIFFchunk has already been read */
+ WAVEmagic = wavelen;
+ wavelen = RIFFchunk;
+ RIFFchunk = RIFF;
+ } else {
+ WAVEmagic = SDL_ReadLE32(src);
+ }
+ if ((RIFFchunk != RIFF) || (WAVEmagic != WAVE)) {
+ SDL_SetError("Unrecognized file type (not WAVE)");
+ was_error = 1;
+ goto done;
+ }
+ headerDiff += sizeof(Uint32); /* for WAVE */
+
+ /* Read the audio data format chunk */
+ chunk.data = NULL;
+ do {
+ SDL_free(chunk.data);
+ chunk.data = NULL;
+ lenread = ReadChunk(src, &chunk);
+ if (lenread < 0) {
+ was_error = 1;
+ goto done;
+ }
+ /* 2 Uint32's for chunk header+len, plus the lenread */
+ headerDiff += lenread + 2 * sizeof(Uint32);
+ } while ((chunk.magic == FACT) || (chunk.magic == LIST) || (chunk.magic == BEXT) || (chunk.magic == JUNK));
+
+ /* Decode the audio data format */
+ format = (WaveFMT *) chunk.data;
+ if (chunk.magic != FMT) {
+ SDL_SetError("Complex WAVE files not supported");
+ was_error = 1;
+ goto done;
+ }
+ IEEE_float_encoded = MS_ADPCM_encoded = IMA_ADPCM_encoded = 0;
+ switch (SDL_SwapLE16(format->encoding)) {
+ case PCM_CODE:
+ /* We can understand this */
+ break;
+ case IEEE_FLOAT_CODE:
+ IEEE_float_encoded = 1;
+ /* We can understand this */
+ break;
+ case MS_ADPCM_CODE:
+ /* Try to understand this */
+ if (InitMS_ADPCM(format) < 0) {
+ was_error = 1;
+ goto done;
+ }
+ MS_ADPCM_encoded = 1;
+ break;
+ case IMA_ADPCM_CODE:
+ /* Try to understand this */
+ if (InitIMA_ADPCM(format) < 0) {
+ was_error = 1;
+ goto done;
+ }
+ IMA_ADPCM_encoded = 1;
+ break;
+ case EXTENSIBLE_CODE:
+ /* note that this ignores channel masks, smaller valid bit counts
+ inside a larger container, and most subtypes. This is just enough
+ to get things that didn't really _need_ WAVE_FORMAT_EXTENSIBLE
+ to be useful working when they use this format flag. */
+ ext = (WaveExtensibleFMT *) format;
+ if (SDL_SwapLE16(ext->size) < 22) {
+ SDL_SetError("bogus extended .wav header");
+ was_error = 1;
+ goto done;
+ }
+ if (SDL_memcmp(ext->subformat, extensible_pcm_guid, 16) == 0) {
+ break; /* cool. */
+ } else if (SDL_memcmp(ext->subformat, extensible_ieee_guid, 16) == 0) {
+ IEEE_float_encoded = 1;
+ break;
+ }
+ break;
+ case MP3_CODE:
+ SDL_SetError("MPEG Layer 3 data not supported");
+ was_error = 1;
+ goto done;
+ default:
+ SDL_SetError("Unknown WAVE data format: 0x%.4x",
+ SDL_SwapLE16(format->encoding));
+ was_error = 1;
+ goto done;
+ }
+ SDL_zerop(spec);
+ spec->freq = SDL_SwapLE32(format->frequency);
+
+ if (IEEE_float_encoded) {
+ if ((SDL_SwapLE16(format->bitspersample)) != 32) {
+ was_error = 1;
+ } else {
+ spec->format = AUDIO_F32;
+ }
+ } else {
+ switch (SDL_SwapLE16(format->bitspersample)) {
+ case 4:
+ if (MS_ADPCM_encoded || IMA_ADPCM_encoded) {
+ spec->format = AUDIO_S16;
+ } else {
+ was_error = 1;
+ }
+ break;
+ case 8:
+ spec->format = AUDIO_U8;
+ break;
+ case 16:
+ spec->format = AUDIO_S16;
+ break;
+ case 24: /* convert this. */
+ spec->format = AUDIO_S32;
+ break;
+ case 32:
+ spec->format = AUDIO_S32;
+ break;
+ default:
+ was_error = 1;
+ break;
+ }
+ }
+
+ if (was_error) {
+ SDL_SetError("Unknown %d-bit PCM data format",
+ SDL_SwapLE16(format->bitspersample));
+ goto done;
+ }
+ spec->channels = (Uint8) SDL_SwapLE16(format->channels);
+ spec->samples = 4096; /* Good default buffer size */
+
+ /* Read the audio data chunk */
+ *audio_buf = NULL;
+ do {
+ SDL_free(*audio_buf);
+ *audio_buf = NULL;
+ lenread = ReadChunk(src, &chunk);
+ if (lenread < 0) {
+ was_error = 1;
+ goto done;
+ }
+ *audio_len = lenread;
+ *audio_buf = chunk.data;
+ if (chunk.magic != DATA)
+ headerDiff += lenread + 2 * sizeof(Uint32);
+ } while (chunk.magic != DATA);
+ headerDiff += 2 * sizeof(Uint32); /* for the data chunk and len */
+
+ if (MS_ADPCM_encoded) {
+ if (MS_ADPCM_decode(audio_buf, audio_len) < 0) {
+ was_error = 1;
+ goto done;
+ }
+ }
+ if (IMA_ADPCM_encoded) {
+ if (IMA_ADPCM_decode(audio_buf, audio_len) < 0) {
+ was_error = 1;
+ goto done;
+ }
+ }
+
+ if (SDL_SwapLE16(format->bitspersample) == 24) {
+ if (ConvertSint24ToSint32(audio_buf, audio_len) < 0) {
+ was_error = 1;
+ goto done;
+ }
+ }
+
+ /* Don't return a buffer that isn't a multiple of samplesize */
+ samplesize = ((SDL_AUDIO_BITSIZE(spec->format)) / 8) * spec->channels;
+ *audio_len &= ~(samplesize - 1);
+
+ done:
+ SDL_free(format);
+ if (src) {
+ if (freesrc) {
+ SDL_RWclose(src);
+ } else {
+ /* seek to the end of the file (given by the RIFF chunk) */
+ SDL_RWseek(src, wavelen - chunk.length - headerDiff, RW_SEEK_CUR);
+ }
+ }
+ if (was_error) {
+ spec = NULL;
+ }
+ return (spec);
+}
+
+/* Since the WAV memory is allocated in the shared library, it must also
+ be freed here. (Necessary under Win32, VC++)
+ */
+void
+SDL_FreeWAV(Uint8 * audio_buf)
+{
+ SDL_free(audio_buf);
+}
+
+static int
+ReadChunk(SDL_RWops * src, Chunk * chunk)
+{
+ chunk->magic = SDL_ReadLE32(src);
+ chunk->length = SDL_ReadLE32(src);
+ chunk->data = (Uint8 *) SDL_malloc(chunk->length);
+ if (chunk->data == NULL) {
+ return SDL_OutOfMemory();
+ }
+ if (SDL_RWread(src, chunk->data, chunk->length, 1) != 1) {
+ SDL_free(chunk->data);
+ chunk->data = NULL;
+ return SDL_Error(SDL_EFREAD);
+ }
+ return (chunk->length);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/SDL_wave.h b/src/3rdparty/SDL2/src/audio/SDL_wave.h
new file mode 100644
index 0000000..5c60f75
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/SDL_wave.h
@@ -0,0 +1,77 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* WAVE files are little-endian */
+
+/*******************************************/
+/* Define values for Microsoft WAVE format */
+/*******************************************/
+#define RIFF 0x46464952 /* "RIFF" */
+#define WAVE 0x45564157 /* "WAVE" */
+#define FACT 0x74636166 /* "fact" */
+#define LIST 0x5453494c /* "LIST" */
+#define BEXT 0x74786562 /* "bext" */
+#define JUNK 0x4B4E554A /* "JUNK" */
+#define FMT 0x20746D66 /* "fmt " */
+#define DATA 0x61746164 /* "data" */
+#define PCM_CODE 0x0001
+#define MS_ADPCM_CODE 0x0002
+#define IEEE_FLOAT_CODE 0x0003
+#define IMA_ADPCM_CODE 0x0011
+#define MP3_CODE 0x0055
+#define EXTENSIBLE_CODE 0xFFFE
+#define WAVE_MONO 1
+#define WAVE_STEREO 2
+
+/* Normally, these three chunks come consecutively in a WAVE file */
+typedef struct WaveFMT
+{
+/* Not saved in the chunk we read:
+ Uint32 FMTchunk;
+ Uint32 fmtlen;
+*/
+ Uint16 encoding;
+ Uint16 channels; /* 1 = mono, 2 = stereo */
+ Uint32 frequency; /* One of 11025, 22050, or 44100 Hz */
+ Uint32 byterate; /* Average bytes per second */
+ Uint16 blockalign; /* Bytes per sample block */
+ Uint16 bitspersample; /* One of 8, 12, 16, or 4 for ADPCM */
+} WaveFMT;
+
+/* The general chunk found in the WAVE file */
+typedef struct Chunk
+{
+ Uint32 magic;
+ Uint32 length;
+ Uint8 *data;
+} Chunk;
+
+typedef struct WaveExtensibleFMT
+{
+ WaveFMT format;
+ Uint16 size;
+ Uint16 validbits;
+ Uint32 channelmask;
+ Uint8 subformat[16]; /* a GUID. */
+} WaveExtensibleFMT;
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/alsa/SDL_alsa_audio.c b/src/3rdparty/SDL2/src/audio/alsa/SDL_alsa_audio.c
new file mode 100644
index 0000000..2dba1ff
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/alsa/SDL_alsa_audio.c
@@ -0,0 +1,1030 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_ALSA
+
+/* Allow access to a raw mixing buffer */
+
+#include <sys/types.h>
+#include <signal.h> /* For kill() */
+#include <string.h>
+
+#include "SDL_assert.h"
+#include "SDL_timer.h"
+#include "SDL_audio.h"
+#include "../SDL_audio_c.h"
+#include "SDL_alsa_audio.h"
+
+#ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
+#include "SDL_loadso.h"
+#endif
+
+static int (*ALSA_snd_pcm_open)
+ (snd_pcm_t **, const char *, snd_pcm_stream_t, int);
+static int (*ALSA_snd_pcm_close) (snd_pcm_t * pcm);
+static snd_pcm_sframes_t (*ALSA_snd_pcm_writei)
+ (snd_pcm_t *, const void *, snd_pcm_uframes_t);
+static snd_pcm_sframes_t (*ALSA_snd_pcm_readi)
+ (snd_pcm_t *, void *, snd_pcm_uframes_t);
+static int (*ALSA_snd_pcm_recover) (snd_pcm_t *, int, int);
+static int (*ALSA_snd_pcm_prepare) (snd_pcm_t *);
+static int (*ALSA_snd_pcm_drain) (snd_pcm_t *);
+static const char *(*ALSA_snd_strerror) (int);
+static size_t(*ALSA_snd_pcm_hw_params_sizeof) (void);
+static size_t(*ALSA_snd_pcm_sw_params_sizeof) (void);
+static void (*ALSA_snd_pcm_hw_params_copy)
+ (snd_pcm_hw_params_t *, const snd_pcm_hw_params_t *);
+static int (*ALSA_snd_pcm_hw_params_any) (snd_pcm_t *, snd_pcm_hw_params_t *);
+static int (*ALSA_snd_pcm_hw_params_set_access)
+ (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_access_t);
+static int (*ALSA_snd_pcm_hw_params_set_format)
+ (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_format_t);
+static int (*ALSA_snd_pcm_hw_params_set_channels)
+ (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int);
+static int (*ALSA_snd_pcm_hw_params_get_channels)
+ (const snd_pcm_hw_params_t *, unsigned int *);
+static int (*ALSA_snd_pcm_hw_params_set_rate_near)
+ (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int *, int *);
+static int (*ALSA_snd_pcm_hw_params_set_period_size_near)
+ (snd_pcm_t *, snd_pcm_hw_params_t *, snd_pcm_uframes_t *, int *);
+static int (*ALSA_snd_pcm_hw_params_get_period_size)
+ (const snd_pcm_hw_params_t *, snd_pcm_uframes_t *, int *);
+static int (*ALSA_snd_pcm_hw_params_set_periods_near)
+ (snd_pcm_t *, snd_pcm_hw_params_t *, unsigned int *, int *);
+static int (*ALSA_snd_pcm_hw_params_get_periods)
+ (const snd_pcm_hw_params_t *, unsigned int *, int *);
+static int (*ALSA_snd_pcm_hw_params_set_buffer_size_near)
+ (snd_pcm_t *pcm, snd_pcm_hw_params_t *, snd_pcm_uframes_t *);
+static int (*ALSA_snd_pcm_hw_params_get_buffer_size)
+ (const snd_pcm_hw_params_t *, snd_pcm_uframes_t *);
+static int (*ALSA_snd_pcm_hw_params) (snd_pcm_t *, snd_pcm_hw_params_t *);
+static int (*ALSA_snd_pcm_sw_params_current) (snd_pcm_t *,
+ snd_pcm_sw_params_t *);
+static int (*ALSA_snd_pcm_sw_params_set_start_threshold)
+ (snd_pcm_t *, snd_pcm_sw_params_t *, snd_pcm_uframes_t);
+static int (*ALSA_snd_pcm_sw_params) (snd_pcm_t *, snd_pcm_sw_params_t *);
+static int (*ALSA_snd_pcm_nonblock) (snd_pcm_t *, int);
+static int (*ALSA_snd_pcm_wait)(snd_pcm_t *, int);
+static int (*ALSA_snd_pcm_sw_params_set_avail_min)
+ (snd_pcm_t *, snd_pcm_sw_params_t *, snd_pcm_uframes_t);
+static int (*ALSA_snd_pcm_reset)(snd_pcm_t *);
+static int (*ALSA_snd_device_name_hint) (int, const char *, void ***);
+static char* (*ALSA_snd_device_name_get_hint) (const void *, const char *);
+static int (*ALSA_snd_device_name_free_hint) (void **);
+#ifdef SND_CHMAP_API_VERSION
+static snd_pcm_chmap_t* (*ALSA_snd_pcm_get_chmap) (snd_pcm_t *);
+static int (*ALSA_snd_pcm_chmap_print) (const snd_pcm_chmap_t *map, size_t maxlen, char *buf);
+#endif
+
+#ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
+#define snd_pcm_hw_params_sizeof ALSA_snd_pcm_hw_params_sizeof
+#define snd_pcm_sw_params_sizeof ALSA_snd_pcm_sw_params_sizeof
+
+static const char *alsa_library = SDL_AUDIO_DRIVER_ALSA_DYNAMIC;
+static void *alsa_handle = NULL;
+
+static int
+load_alsa_sym(const char *fn, void **addr)
+{
+ *addr = SDL_LoadFunction(alsa_handle, fn);
+ if (*addr == NULL) {
+ /* Don't call SDL_SetError(): SDL_LoadFunction already did. */
+ return 0;
+ }
+
+ return 1;
+}
+
+/* cast funcs to char* first, to please GCC's strict aliasing rules. */
+#define SDL_ALSA_SYM(x) \
+ if (!load_alsa_sym(#x, (void **) (char *) &ALSA_##x)) return -1
+#else
+#define SDL_ALSA_SYM(x) ALSA_##x = x
+#endif
+
+static int
+load_alsa_syms(void)
+{
+ SDL_ALSA_SYM(snd_pcm_open);
+ SDL_ALSA_SYM(snd_pcm_close);
+ SDL_ALSA_SYM(snd_pcm_writei);
+ SDL_ALSA_SYM(snd_pcm_readi);
+ SDL_ALSA_SYM(snd_pcm_recover);
+ SDL_ALSA_SYM(snd_pcm_prepare);
+ SDL_ALSA_SYM(snd_pcm_drain);
+ SDL_ALSA_SYM(snd_strerror);
+ SDL_ALSA_SYM(snd_pcm_hw_params_sizeof);
+ SDL_ALSA_SYM(snd_pcm_sw_params_sizeof);
+ SDL_ALSA_SYM(snd_pcm_hw_params_copy);
+ SDL_ALSA_SYM(snd_pcm_hw_params_any);
+ SDL_ALSA_SYM(snd_pcm_hw_params_set_access);
+ SDL_ALSA_SYM(snd_pcm_hw_params_set_format);
+ SDL_ALSA_SYM(snd_pcm_hw_params_set_channels);
+ SDL_ALSA_SYM(snd_pcm_hw_params_get_channels);
+ SDL_ALSA_SYM(snd_pcm_hw_params_set_rate_near);
+ SDL_ALSA_SYM(snd_pcm_hw_params_set_period_size_near);
+ SDL_ALSA_SYM(snd_pcm_hw_params_get_period_size);
+ SDL_ALSA_SYM(snd_pcm_hw_params_set_periods_near);
+ SDL_ALSA_SYM(snd_pcm_hw_params_get_periods);
+ SDL_ALSA_SYM(snd_pcm_hw_params_set_buffer_size_near);
+ SDL_ALSA_SYM(snd_pcm_hw_params_get_buffer_size);
+ SDL_ALSA_SYM(snd_pcm_hw_params);
+ SDL_ALSA_SYM(snd_pcm_sw_params_current);
+ SDL_ALSA_SYM(snd_pcm_sw_params_set_start_threshold);
+ SDL_ALSA_SYM(snd_pcm_sw_params);
+ SDL_ALSA_SYM(snd_pcm_nonblock);
+ SDL_ALSA_SYM(snd_pcm_wait);
+ SDL_ALSA_SYM(snd_pcm_sw_params_set_avail_min);
+ SDL_ALSA_SYM(snd_pcm_reset);
+ SDL_ALSA_SYM(snd_device_name_hint);
+ SDL_ALSA_SYM(snd_device_name_get_hint);
+ SDL_ALSA_SYM(snd_device_name_free_hint);
+#ifdef SND_CHMAP_API_VERSION
+ SDL_ALSA_SYM(snd_pcm_get_chmap);
+ SDL_ALSA_SYM(snd_pcm_chmap_print);
+#endif
+
+ return 0;
+}
+
+#undef SDL_ALSA_SYM
+
+#ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
+
+static void
+UnloadALSALibrary(void)
+{
+ if (alsa_handle != NULL) {
+ SDL_UnloadObject(alsa_handle);
+ alsa_handle = NULL;
+ }
+}
+
+static int
+LoadALSALibrary(void)
+{
+ int retval = 0;
+ if (alsa_handle == NULL) {
+ alsa_handle = SDL_LoadObject(alsa_library);
+ if (alsa_handle == NULL) {
+ retval = -1;
+ /* Don't call SDL_SetError(): SDL_LoadObject already did. */
+ } else {
+ retval = load_alsa_syms();
+ if (retval < 0) {
+ UnloadALSALibrary();
+ }
+ }
+ }
+ return retval;
+}
+
+#else
+
+static void
+UnloadALSALibrary(void)
+{
+}
+
+static int
+LoadALSALibrary(void)
+{
+ load_alsa_syms();
+ return 0;
+}
+
+#endif /* SDL_AUDIO_DRIVER_ALSA_DYNAMIC */
+
+static const char *
+get_audio_device(void *handle, const int channels)
+{
+ const char *device;
+
+ if (handle != NULL) {
+ return (const char *) handle;
+ }
+
+ /* !!! FIXME: we also check "SDL_AUDIO_DEVICE_NAME" at the higher level. */
+ device = SDL_getenv("AUDIODEV"); /* Is there a standard variable name? */
+ if (device != NULL) {
+ return device;
+ }
+
+ if (channels == 6) {
+ return "plug:surround51";
+ } else if (channels == 4) {
+ return "plug:surround40";
+ }
+
+ return "default";
+}
+
+
+/* This function waits until it is possible to write a full sound buffer */
+static void
+ALSA_WaitDevice(_THIS)
+{
+ /* We're in blocking mode, so there's nothing to do here */
+}
+
+
+/* !!! FIXME: is there a channel swizzler in alsalib instead? */
+/*
+ * http://bugzilla.libsdl.org/show_bug.cgi?id=110
+ * "For Linux ALSA, this is FL-FR-RL-RR-C-LFE
+ * and for Windows DirectX [and CoreAudio], this is FL-FR-C-LFE-RL-RR"
+ */
+#define SWIZ6(T, buf, numframes) \
+ T *ptr = (T *) buf; \
+ Uint32 i; \
+ for (i = 0; i < numframes; i++, ptr += 6) { \
+ T tmp; \
+ tmp = ptr[2]; ptr[2] = ptr[4]; ptr[4] = tmp; \
+ tmp = ptr[3]; ptr[3] = ptr[5]; ptr[5] = tmp; \
+ }
+
+static void
+swizzle_alsa_channels_6_64bit(void *buffer, Uint32 bufferlen)
+{
+ SWIZ6(Uint64, buffer, bufferlen);
+}
+
+static void
+swizzle_alsa_channels_6_32bit(void *buffer, Uint32 bufferlen)
+{
+ SWIZ6(Uint32, buffer, bufferlen);
+}
+
+static void
+swizzle_alsa_channels_6_16bit(void *buffer, Uint32 bufferlen)
+{
+ SWIZ6(Uint16, buffer, bufferlen);
+}
+
+static void
+swizzle_alsa_channels_6_8bit(void *buffer, Uint32 bufferlen)
+{
+ SWIZ6(Uint8, buffer, bufferlen);
+}
+
+#undef SWIZ6
+
+
+/*
+ * Called right before feeding this->hidden->mixbuf to the hardware. Swizzle
+ * channels from Windows/Mac order to the format alsalib will want.
+ */
+static void
+swizzle_alsa_channels(_THIS, void *buffer, Uint32 bufferlen)
+{
+ if (this->spec.channels == 6) {
+ switch (SDL_AUDIO_BITSIZE(this->spec.format)) {
+ case 8: swizzle_alsa_channels_6_8bit(buffer, bufferlen); break;
+ case 16: swizzle_alsa_channels_6_16bit(buffer, bufferlen); break;
+ case 32: swizzle_alsa_channels_6_32bit(buffer, bufferlen); break;
+ case 64: swizzle_alsa_channels_6_64bit(buffer, bufferlen); break;
+ default: SDL_assert(!"unhandled bitsize"); break;
+ }
+ }
+
+ /* !!! FIXME: update this for 7.1 if needed, later. */
+}
+
+#ifdef SND_CHMAP_API_VERSION
+/* Some devices have the right channel map, no swizzling necessary */
+static void
+no_swizzle(_THIS, void *buffer, Uint32 bufferlen)
+{
+ return;
+}
+#endif /* SND_CHMAP_API_VERSION */
+
+
+static void
+ALSA_PlayDevice(_THIS)
+{
+ const Uint8 *sample_buf = (const Uint8 *) this->hidden->mixbuf;
+ const int frame_size = (((int) SDL_AUDIO_BITSIZE(this->spec.format)) / 8) *
+ this->spec.channels;
+ snd_pcm_uframes_t frames_left = ((snd_pcm_uframes_t) this->spec.samples);
+
+ this->hidden->swizzle_func(this, this->hidden->mixbuf, frames_left);
+
+ while ( frames_left > 0 && SDL_AtomicGet(&this->enabled) ) {
+ int status = ALSA_snd_pcm_writei(this->hidden->pcm_handle,
+ sample_buf, frames_left);
+
+ if (status < 0) {
+ if (status == -EAGAIN) {
+ /* Apparently snd_pcm_recover() doesn't handle this case -
+ does it assume snd_pcm_wait() above? */
+ SDL_Delay(1);
+ continue;
+ }
+ status = ALSA_snd_pcm_recover(this->hidden->pcm_handle, status, 0);
+ if (status < 0) {
+ /* Hmm, not much we can do - abort */
+ fprintf(stderr, "ALSA write failed (unrecoverable): %s\n",
+ ALSA_snd_strerror(status));
+ SDL_OpenedAudioDeviceDisconnected(this);
+ return;
+ }
+ continue;
+ }
+ else if (status == 0) {
+ /* No frames were written (no available space in pcm device).
+ Allow other threads to catch up. */
+ Uint32 delay = (frames_left / 2 * 1000) / this->spec.freq;
+ SDL_Delay(delay);
+ }
+
+ sample_buf += status * frame_size;
+ frames_left -= status;
+ }
+}
+
+static Uint8 *
+ALSA_GetDeviceBuf(_THIS)
+{
+ return (this->hidden->mixbuf);
+}
+
+static int
+ALSA_CaptureFromDevice(_THIS, void *buffer, int buflen)
+{
+ Uint8 *sample_buf = (Uint8 *) buffer;
+ const int frame_size = (((int) SDL_AUDIO_BITSIZE(this->spec.format)) / 8) *
+ this->spec.channels;
+ const int total_frames = buflen / frame_size;
+ snd_pcm_uframes_t frames_left = total_frames;
+ snd_pcm_uframes_t wait_time = frame_size / 2;
+
+ SDL_assert((buflen % frame_size) == 0);
+
+ while ( frames_left > 0 && SDL_AtomicGet(&this->enabled) ) {
+ int status;
+
+ status = ALSA_snd_pcm_readi(this->hidden->pcm_handle,
+ sample_buf, frames_left);
+
+ if (status == -EAGAIN) {
+ ALSA_snd_pcm_wait(this->hidden->pcm_handle, wait_time);
+ status = 0;
+ }
+ else if (status < 0) {
+ /*printf("ALSA: capture error %d\n", status);*/
+ status = ALSA_snd_pcm_recover(this->hidden->pcm_handle, status, 0);
+ if (status < 0) {
+ /* Hmm, not much we can do - abort */
+ fprintf(stderr, "ALSA read failed (unrecoverable): %s\n",
+ ALSA_snd_strerror(status));
+ return -1;
+ }
+ continue;
+ }
+
+ /*printf("ALSA: captured %d bytes\n", status * frame_size);*/
+ sample_buf += status * frame_size;
+ frames_left -= status;
+ }
+
+ this->hidden->swizzle_func(this, buffer, total_frames - frames_left);
+
+ return (total_frames - frames_left) * frame_size;
+}
+
+static void
+ALSA_FlushCapture(_THIS)
+{
+ ALSA_snd_pcm_reset(this->hidden->pcm_handle);
+}
+
+static void
+ALSA_CloseDevice(_THIS)
+{
+ if (this->hidden->pcm_handle) {
+ /* Wait for the submitted audio to drain
+ ALSA_snd_pcm_drop() can hang, so don't use that.
+ */
+ Uint32 delay = ((this->spec.samples * 1000) / this->spec.freq) * 2;
+ SDL_Delay(delay);
+
+ ALSA_snd_pcm_close(this->hidden->pcm_handle);
+ }
+ SDL_free(this->hidden->mixbuf);
+ SDL_free(this->hidden);
+}
+
+static int
+ALSA_finalize_hardware(_THIS, snd_pcm_hw_params_t *hwparams, int override)
+{
+ int status;
+ snd_pcm_uframes_t bufsize;
+
+ /* "set" the hardware with the desired parameters */
+ status = ALSA_snd_pcm_hw_params(this->hidden->pcm_handle, hwparams);
+ if ( status < 0 ) {
+ return(-1);
+ }
+
+ /* Get samples for the actual buffer size */
+ status = ALSA_snd_pcm_hw_params_get_buffer_size(hwparams, &bufsize);
+ if ( status < 0 ) {
+ return(-1);
+ }
+ if ( !override && bufsize != this->spec.samples * 2 ) {
+ return(-1);
+ }
+
+ /* !!! FIXME: Is this safe to do? */
+ this->spec.samples = bufsize / 2;
+
+ /* This is useful for debugging */
+ if ( SDL_getenv("SDL_AUDIO_ALSA_DEBUG") ) {
+ snd_pcm_uframes_t persize = 0;
+ unsigned int periods = 0;
+
+ ALSA_snd_pcm_hw_params_get_period_size(hwparams, &persize, NULL);
+ ALSA_snd_pcm_hw_params_get_periods(hwparams, &periods, NULL);
+
+ fprintf(stderr,
+ "ALSA: period size = %ld, periods = %u, buffer size = %lu\n",
+ persize, periods, bufsize);
+ }
+
+ return(0);
+}
+
+static int
+ALSA_set_period_size(_THIS, snd_pcm_hw_params_t *params, int override)
+{
+ const char *env;
+ int status;
+ snd_pcm_hw_params_t *hwparams;
+ snd_pcm_uframes_t frames;
+ unsigned int periods;
+
+ /* Copy the hardware parameters for this setup */
+ snd_pcm_hw_params_alloca(&hwparams);
+ ALSA_snd_pcm_hw_params_copy(hwparams, params);
+
+ if ( !override ) {
+ env = SDL_getenv("SDL_AUDIO_ALSA_SET_PERIOD_SIZE");
+ if ( env ) {
+ override = SDL_atoi(env);
+ if ( override == 0 ) {
+ return(-1);
+ }
+ }
+ }
+
+ frames = this->spec.samples;
+ status = ALSA_snd_pcm_hw_params_set_period_size_near(
+ this->hidden->pcm_handle, hwparams, &frames, NULL);
+ if ( status < 0 ) {
+ return(-1);
+ }
+
+ periods = 2;
+ status = ALSA_snd_pcm_hw_params_set_periods_near(
+ this->hidden->pcm_handle, hwparams, &periods, NULL);
+ if ( status < 0 ) {
+ return(-1);
+ }
+
+ return ALSA_finalize_hardware(this, hwparams, override);
+}
+
+static int
+ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params, int override)
+{
+ const char *env;
+ int status;
+ snd_pcm_hw_params_t *hwparams;
+ snd_pcm_uframes_t frames;
+
+ /* Copy the hardware parameters for this setup */
+ snd_pcm_hw_params_alloca(&hwparams);
+ ALSA_snd_pcm_hw_params_copy(hwparams, params);
+
+ if ( !override ) {
+ env = SDL_getenv("SDL_AUDIO_ALSA_SET_BUFFER_SIZE");
+ if ( env ) {
+ override = SDL_atoi(env);
+ if ( override == 0 ) {
+ return(-1);
+ }
+ }
+ }
+
+ frames = this->spec.samples * 2;
+ status = ALSA_snd_pcm_hw_params_set_buffer_size_near(
+ this->hidden->pcm_handle, hwparams, &frames);
+ if ( status < 0 ) {
+ return(-1);
+ }
+
+ return ALSA_finalize_hardware(this, hwparams, override);
+}
+
+static int
+ALSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ int status = 0;
+ snd_pcm_t *pcm_handle = NULL;
+ snd_pcm_hw_params_t *hwparams = NULL;
+ snd_pcm_sw_params_t *swparams = NULL;
+ snd_pcm_format_t format = 0;
+ SDL_AudioFormat test_format = 0;
+ unsigned int rate = 0;
+ unsigned int channels = 0;
+#ifdef SND_CHMAP_API_VERSION
+ snd_pcm_chmap_t *chmap;
+ char chmap_str[64];
+#endif
+
+ /* Initialize all variables that we clean on shutdown */
+ this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc((sizeof *this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(this->hidden);
+
+ /* Open the audio device */
+ /* Name of device should depend on # channels in spec */
+ status = ALSA_snd_pcm_open(&pcm_handle,
+ get_audio_device(handle, this->spec.channels),
+ iscapture ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
+ SND_PCM_NONBLOCK);
+
+ if (status < 0) {
+ return SDL_SetError("ALSA: Couldn't open audio device: %s",
+ ALSA_snd_strerror(status));
+ }
+
+ this->hidden->pcm_handle = pcm_handle;
+
+ /* Figure out what the hardware is capable of */
+ snd_pcm_hw_params_alloca(&hwparams);
+ status = ALSA_snd_pcm_hw_params_any(pcm_handle, hwparams);
+ if (status < 0) {
+ return SDL_SetError("ALSA: Couldn't get hardware config: %s",
+ ALSA_snd_strerror(status));
+ }
+
+ /* SDL only uses interleaved sample output */
+ status = ALSA_snd_pcm_hw_params_set_access(pcm_handle, hwparams,
+ SND_PCM_ACCESS_RW_INTERLEAVED);
+ if (status < 0) {
+ return SDL_SetError("ALSA: Couldn't set interleaved access: %s",
+ ALSA_snd_strerror(status));
+ }
+
+ /* Try for a closest match on audio format */
+ status = -1;
+ for (test_format = SDL_FirstAudioFormat(this->spec.format);
+ test_format && (status < 0);) {
+ status = 0; /* if we can't support a format, it'll become -1. */
+ switch (test_format) {
+ case AUDIO_U8:
+ format = SND_PCM_FORMAT_U8;
+ break;
+ case AUDIO_S8:
+ format = SND_PCM_FORMAT_S8;
+ break;
+ case AUDIO_S16LSB:
+ format = SND_PCM_FORMAT_S16_LE;
+ break;
+ case AUDIO_S16MSB:
+ format = SND_PCM_FORMAT_S16_BE;
+ break;
+ case AUDIO_U16LSB:
+ format = SND_PCM_FORMAT_U16_LE;
+ break;
+ case AUDIO_U16MSB:
+ format = SND_PCM_FORMAT_U16_BE;
+ break;
+ case AUDIO_S32LSB:
+ format = SND_PCM_FORMAT_S32_LE;
+ break;
+ case AUDIO_S32MSB:
+ format = SND_PCM_FORMAT_S32_BE;
+ break;
+ case AUDIO_F32LSB:
+ format = SND_PCM_FORMAT_FLOAT_LE;
+ break;
+ case AUDIO_F32MSB:
+ format = SND_PCM_FORMAT_FLOAT_BE;
+ break;
+ default:
+ status = -1;
+ break;
+ }
+ if (status >= 0) {
+ status = ALSA_snd_pcm_hw_params_set_format(pcm_handle,
+ hwparams, format);
+ }
+ if (status < 0) {
+ test_format = SDL_NextAudioFormat();
+ }
+ }
+ if (status < 0) {
+ return SDL_SetError("ALSA: Couldn't find any hardware audio formats");
+ }
+ this->spec.format = test_format;
+
+ /* Validate number of channels and determine if swizzling is necessary
+ * Assume original swizzling, until proven otherwise.
+ */
+ this->hidden->swizzle_func = swizzle_alsa_channels;
+#ifdef SND_CHMAP_API_VERSION
+ chmap = ALSA_snd_pcm_get_chmap(pcm_handle);
+ if (chmap) {
+ ALSA_snd_pcm_chmap_print(chmap, sizeof(chmap_str), chmap_str);
+ if (SDL_strcmp("FL FR FC LFE RL RR", chmap_str) == 0 ||
+ SDL_strcmp("FL FR FC LFE SL SR", chmap_str) == 0) {
+ this->hidden->swizzle_func = no_swizzle;
+ }
+ free(chmap);
+ }
+#endif /* SND_CHMAP_API_VERSION */
+
+ /* Set the number of channels */
+ status = ALSA_snd_pcm_hw_params_set_channels(pcm_handle, hwparams,
+ this->spec.channels);
+ channels = this->spec.channels;
+ if (status < 0) {
+ status = ALSA_snd_pcm_hw_params_get_channels(hwparams, &channels);
+ if (status < 0) {
+ return SDL_SetError("ALSA: Couldn't set audio channels");
+ }
+ this->spec.channels = channels;
+ }
+
+ /* Set the audio rate */
+ rate = this->spec.freq;
+ status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams,
+ &rate, NULL);
+ if (status < 0) {
+ return SDL_SetError("ALSA: Couldn't set audio frequency: %s",
+ ALSA_snd_strerror(status));
+ }
+ this->spec.freq = rate;
+
+ /* Set the buffer size, in samples */
+ if ( ALSA_set_period_size(this, hwparams, 0) < 0 &&
+ ALSA_set_buffer_size(this, hwparams, 0) < 0 ) {
+ /* Failed to set desired buffer size, do the best you can... */
+ status = ALSA_set_period_size(this, hwparams, 1);
+ if (status < 0) {
+ return SDL_SetError("Couldn't set hardware audio parameters: %s", ALSA_snd_strerror(status));
+ }
+ }
+ /* Set the software parameters */
+ snd_pcm_sw_params_alloca(&swparams);
+ status = ALSA_snd_pcm_sw_params_current(pcm_handle, swparams);
+ if (status < 0) {
+ return SDL_SetError("ALSA: Couldn't get software config: %s",
+ ALSA_snd_strerror(status));
+ }
+ status = ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, this->spec.samples);
+ if (status < 0) {
+ return SDL_SetError("Couldn't set minimum available samples: %s",
+ ALSA_snd_strerror(status));
+ }
+ status =
+ ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 1);
+ if (status < 0) {
+ return SDL_SetError("ALSA: Couldn't set start threshold: %s",
+ ALSA_snd_strerror(status));
+ }
+ status = ALSA_snd_pcm_sw_params(pcm_handle, swparams);
+ if (status < 0) {
+ return SDL_SetError("Couldn't set software audio parameters: %s",
+ ALSA_snd_strerror(status));
+ }
+
+ /* Calculate the final parameters for this audio specification */
+ SDL_CalculateAudioSpec(&this->spec);
+
+ /* Allocate mixing buffer */
+ if (!iscapture) {
+ this->hidden->mixlen = this->spec.size;
+ this->hidden->mixbuf = (Uint8 *) SDL_malloc(this->hidden->mixlen);
+ if (this->hidden->mixbuf == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(this->hidden->mixbuf, this->spec.silence, this->hidden->mixlen);
+ }
+
+ if (!iscapture) {
+ ALSA_snd_pcm_nonblock(pcm_handle, 0);
+ }
+
+ /* We're ready to rock and roll. :-) */
+ return 0;
+}
+
+typedef struct ALSA_Device
+{
+ char *name;
+ SDL_bool iscapture;
+ struct ALSA_Device *next;
+} ALSA_Device;
+
+static void
+add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSeen)
+{
+ ALSA_Device *dev = SDL_malloc(sizeof (ALSA_Device));
+ char *desc;
+ char *handle = NULL;
+ char *ptr;
+
+ if (!dev) {
+ return;
+ }
+
+ /* Not all alsa devices are enumerable via snd_device_name_get_hint
+ (i.e. bluetooth devices). Therefore if hint is passed in to this
+ function as NULL, assume name contains desc.
+ Make sure not to free the storage associated with desc in this case */
+ if (hint) {
+ desc = ALSA_snd_device_name_get_hint(hint, "DESC");
+ if (!desc) {
+ SDL_free(dev);
+ return;
+ }
+ } else {
+ desc = (char *) name;
+ }
+
+ SDL_assert(name != NULL);
+
+ /* some strings have newlines, like "HDA NVidia, HDMI 0\nHDMI Audio Output".
+ just chop the extra lines off, this seems to get a reasonable device
+ name without extra details. */
+ if ((ptr = strchr(desc, '\n')) != NULL) {
+ *ptr = '\0';
+ }
+
+ /*printf("ALSA: adding %s device '%s' (%s)\n", iscapture ? "capture" : "output", name, desc);*/
+
+ handle = SDL_strdup(name);
+ if (!handle) {
+ if (hint) {
+ free(desc);
+ }
+ SDL_free(dev);
+ return;
+ }
+
+ SDL_AddAudioDevice(iscapture, desc, handle);
+ if (hint)
+ free(desc);
+ dev->name = handle;
+ dev->iscapture = iscapture;
+ dev->next = *pSeen;
+ *pSeen = dev;
+}
+
+
+static SDL_atomic_t ALSA_hotplug_shutdown;
+static SDL_Thread *ALSA_hotplug_thread;
+
+static int SDLCALL
+ALSA_HotplugThread(void *arg)
+{
+ SDL_sem *first_run_semaphore = (SDL_sem *) arg;
+ ALSA_Device *devices = NULL;
+ ALSA_Device *next;
+ ALSA_Device *dev;
+ Uint32 ticks;
+
+ SDL_SetThreadPriority(SDL_THREAD_PRIORITY_LOW);
+
+ while (!SDL_AtomicGet(&ALSA_hotplug_shutdown)) {
+ void **hints = NULL;
+ ALSA_Device *unseen;
+ ALSA_Device *seen;
+ ALSA_Device *prev;
+
+ if (ALSA_snd_device_name_hint(-1, "pcm", &hints) != -1) {
+ int i, j;
+ const char *match = NULL;
+ int bestmatch = 0xFFFF;
+ size_t match_len = 0;
+ int defaultdev = -1;
+ static const char * const prefixes[] = {
+ "hw:", "sysdefault:", "default:", NULL
+ };
+
+ unseen = devices;
+ seen = NULL;
+ /* Apparently there are several different ways that ALSA lists
+ actual hardware. It could be prefixed with "hw:" or "default:"
+ or "sysdefault:" and maybe others. Go through the list and see
+ if we can find a preferred prefix for the system. */
+ for (i = 0; hints[i]; i++) {
+ char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
+ if (!name) {
+ continue;
+ }
+
+ /* full name, not a prefix */
+ if ((defaultdev == -1) && (SDL_strcmp(name, "default") == 0)) {
+ defaultdev = i;
+ }
+
+ for (j = 0; prefixes[j]; j++) {
+ const char *prefix = prefixes[j];
+ const size_t prefixlen = SDL_strlen(prefix);
+ if (SDL_strncmp(name, prefix, prefixlen) == 0) {
+ if (j < bestmatch) {
+ bestmatch = j;
+ match = prefix;
+ match_len = prefixlen;
+ }
+ }
+ }
+
+ free(name);
+ }
+
+ /* look through the list of device names to find matches */
+ for (i = 0; hints[i]; i++) {
+ char *name;
+
+ /* if we didn't find a device name prefix we like at all... */
+ if ((!match) && (defaultdev != i)) {
+ continue; /* ...skip anything that isn't the default device. */
+ }
+
+ name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
+ if (!name) {
+ continue;
+ }
+
+ /* only want physical hardware interfaces */
+ if (!match || (SDL_strncmp(name, match, match_len) == 0)) {
+ char *ioid = ALSA_snd_device_name_get_hint(hints[i], "IOID");
+ const SDL_bool isoutput = (ioid == NULL) || (SDL_strcmp(ioid, "Output") == 0);
+ const SDL_bool isinput = (ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0);
+ SDL_bool have_output = SDL_FALSE;
+ SDL_bool have_input = SDL_FALSE;
+
+ free(ioid);
+
+ if (!isoutput && !isinput) {
+ free(name);
+ continue;
+ }
+
+ prev = NULL;
+ for (dev = unseen; dev; dev = next) {
+ next = dev->next;
+ if ( (SDL_strcmp(dev->name, name) == 0) && (((isinput) && dev->iscapture) || ((isoutput) && !dev->iscapture)) ) {
+ if (prev) {
+ prev->next = next;
+ } else {
+ unseen = next;
+ }
+ dev->next = seen;
+ seen = dev;
+ if (isinput) have_input = SDL_TRUE;
+ if (isoutput) have_output = SDL_TRUE;
+ } else {
+ prev = dev;
+ }
+ }
+
+ if (isinput && !have_input) {
+ add_device(SDL_TRUE, name, hints[i], &seen);
+ }
+ if (isoutput && !have_output) {
+ add_device(SDL_FALSE, name, hints[i], &seen);
+ }
+ }
+
+ free(name);
+ }
+
+ ALSA_snd_device_name_free_hint(hints);
+
+ devices = seen; /* now we have a known-good list of attached devices. */
+
+ /* report anything still in unseen as removed. */
+ for (dev = unseen; dev; dev = next) {
+ /*printf("ALSA: removing usb %s device '%s'\n", dev->iscapture ? "capture" : "output", dev->name);*/
+ next = dev->next;
+ SDL_RemoveAudioDevice(dev->iscapture, dev->name);
+ SDL_free(dev->name);
+ SDL_free(dev);
+ }
+ }
+
+ /* On first run, tell ALSA_DetectDevices() that we have a complete device list so it can return. */
+ if (first_run_semaphore) {
+ SDL_SemPost(first_run_semaphore);
+ first_run_semaphore = NULL; /* let other thread clean it up. */
+ }
+
+ /* Block awhile before checking again, unless we're told to stop. */
+ ticks = SDL_GetTicks() + 5000;
+ while (!SDL_AtomicGet(&ALSA_hotplug_shutdown) && !SDL_TICKS_PASSED(SDL_GetTicks(), ticks)) {
+ SDL_Delay(100);
+ }
+ }
+
+ /* Shutting down! Clean up any data we've gathered. */
+ for (dev = devices; dev; dev = next) {
+ /*printf("ALSA: at shutdown, removing %s device '%s'\n", dev->iscapture ? "capture" : "output", dev->name);*/
+ next = dev->next;
+ SDL_free(dev->name);
+ SDL_free(dev);
+ }
+
+ return 0;
+}
+
+static void
+ALSA_DetectDevices(void)
+{
+ /* Start the device detection thread here, wait for an initial iteration to complete. */
+ SDL_sem *semaphore = SDL_CreateSemaphore(0);
+ if (!semaphore) {
+ return; /* oh well. */
+ }
+
+ SDL_AtomicSet(&ALSA_hotplug_shutdown, 0);
+
+ ALSA_hotplug_thread = SDL_CreateThread(ALSA_HotplugThread, "SDLHotplugALSA", semaphore);
+ if (ALSA_hotplug_thread) {
+ SDL_SemWait(semaphore); /* wait for the first iteration to finish. */
+ }
+
+ SDL_DestroySemaphore(semaphore);
+}
+
+static void
+ALSA_Deinitialize(void)
+{
+ if (ALSA_hotplug_thread != NULL) {
+ SDL_AtomicSet(&ALSA_hotplug_shutdown, 1);
+ SDL_WaitThread(ALSA_hotplug_thread, NULL);
+ ALSA_hotplug_thread = NULL;
+ }
+
+ UnloadALSALibrary();
+}
+
+static int
+ALSA_Init(SDL_AudioDriverImpl * impl)
+{
+ if (LoadALSALibrary() < 0) {
+ return 0;
+ }
+
+ /* Set the function pointers */
+ impl->DetectDevices = ALSA_DetectDevices;
+ impl->OpenDevice = ALSA_OpenDevice;
+ impl->WaitDevice = ALSA_WaitDevice;
+ impl->GetDeviceBuf = ALSA_GetDeviceBuf;
+ impl->PlayDevice = ALSA_PlayDevice;
+ impl->CloseDevice = ALSA_CloseDevice;
+ impl->Deinitialize = ALSA_Deinitialize;
+ impl->CaptureFromDevice = ALSA_CaptureFromDevice;
+ impl->FlushCapture = ALSA_FlushCapture;
+
+ impl->HasCaptureSupport = SDL_TRUE;
+
+ return 1; /* this audio target is available. */
+}
+
+
+AudioBootStrap ALSA_bootstrap = {
+ "alsa", "ALSA PCM audio", ALSA_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_ALSA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/alsa/SDL_alsa_audio.h b/src/3rdparty/SDL2/src/audio/alsa/SDL_alsa_audio.h
new file mode 100644
index 0000000..f620500
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/alsa/SDL_alsa_audio.h
@@ -0,0 +1,48 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_ALSA_audio_h_
+#define SDL_ALSA_audio_h_
+
+#include <alsa/asoundlib.h>
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData
+{
+ /* The audio device handle */
+ snd_pcm_t *pcm_handle;
+
+ /* Raw mixing buffer */
+ Uint8 *mixbuf;
+ int mixlen;
+
+ /* swizzle function */
+ void (*swizzle_func)(_THIS, void *buffer, Uint32 bufferlen);
+};
+
+#endif /* SDL_ALSA_audio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/android/SDL_androidaudio.c b/src/3rdparty/SDL2/src/audio/android/SDL_androidaudio.c
new file mode 100644
index 0000000..7a25424
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/android/SDL_androidaudio.c
@@ -0,0 +1,226 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_ANDROID
+
+/* Output audio to Android */
+
+#include "SDL_assert.h"
+#include "SDL_audio.h"
+#include "../SDL_audio_c.h"
+#include "SDL_androidaudio.h"
+
+#include "../../core/android/SDL_android.h"
+
+#include <android/log.h>
+
+static SDL_AudioDevice* audioDevice = NULL;
+static SDL_AudioDevice* captureDevice = NULL;
+
+static int
+ANDROIDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ SDL_AudioFormat test_format;
+
+ SDL_assert((captureDevice == NULL) || !iscapture);
+ SDL_assert((audioDevice == NULL) || iscapture);
+
+ if (iscapture) {
+ captureDevice = this;
+ } else {
+ audioDevice = this;
+ }
+
+ this->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, (sizeof *this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ test_format = SDL_FirstAudioFormat(this->spec.format);
+ while (test_format != 0) { /* no "UNKNOWN" constant */
+ if ((test_format == AUDIO_U8) || (test_format == AUDIO_S16LSB)) {
+ this->spec.format = test_format;
+ break;
+ }
+ test_format = SDL_NextAudioFormat();
+ }
+
+ if (test_format == 0) {
+ /* Didn't find a compatible format :( */
+ return SDL_SetError("No compatible audio format!");
+ }
+
+ if (this->spec.channels > 1) {
+ this->spec.channels = 2;
+ } else {
+ this->spec.channels = 1;
+ }
+
+ if (this->spec.freq < 8000) {
+ this->spec.freq = 8000;
+ }
+ if (this->spec.freq > 48000) {
+ this->spec.freq = 48000;
+ }
+
+ /* TODO: pass in/return a (Java) device ID */
+ this->spec.samples = Android_JNI_OpenAudioDevice(iscapture, this->spec.freq, this->spec.format == AUDIO_U8 ? 0 : 1, this->spec.channels, this->spec.samples);
+
+ if (this->spec.samples == 0) {
+ /* Init failed? */
+ return SDL_SetError("Java-side initialization failed!");
+ }
+
+ SDL_CalculateAudioSpec(&this->spec);
+
+ return 0;
+}
+
+static void
+ANDROIDAUDIO_PlayDevice(_THIS)
+{
+ Android_JNI_WriteAudioBuffer();
+}
+
+static Uint8 *
+ANDROIDAUDIO_GetDeviceBuf(_THIS)
+{
+ return Android_JNI_GetAudioBuffer();
+}
+
+static int
+ANDROIDAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
+{
+ return Android_JNI_CaptureAudioBuffer(buffer, buflen);
+}
+
+static void
+ANDROIDAUDIO_FlushCapture(_THIS)
+{
+ Android_JNI_FlushCapturedAudio();
+}
+
+static void
+ANDROIDAUDIO_CloseDevice(_THIS)
+{
+ /* At this point SDL_CloseAudioDevice via close_audio_device took care of terminating the audio thread
+ so it's safe to terminate the Java side buffer and AudioTrack
+ */
+ Android_JNI_CloseAudioDevice(this->iscapture);
+ if (this->iscapture) {
+ SDL_assert(captureDevice == this);
+ captureDevice = NULL;
+ } else {
+ SDL_assert(audioDevice == this);
+ audioDevice = NULL;
+ }
+ SDL_free(this->hidden);
+}
+
+static int
+ANDROIDAUDIO_Init(SDL_AudioDriverImpl * impl)
+{
+ /* Set the function pointers */
+ impl->OpenDevice = ANDROIDAUDIO_OpenDevice;
+ impl->PlayDevice = ANDROIDAUDIO_PlayDevice;
+ impl->GetDeviceBuf = ANDROIDAUDIO_GetDeviceBuf;
+ impl->CloseDevice = ANDROIDAUDIO_CloseDevice;
+ impl->CaptureFromDevice = ANDROIDAUDIO_CaptureFromDevice;
+ impl->FlushCapture = ANDROIDAUDIO_FlushCapture;
+
+ /* and the capabilities */
+ impl->HasCaptureSupport = SDL_TRUE;
+ impl->OnlyHasDefaultOutputDevice = 1;
+ impl->OnlyHasDefaultCaptureDevice = 1;
+
+ return 1; /* this audio target is available. */
+}
+
+AudioBootStrap ANDROIDAUDIO_bootstrap = {
+ "android", "SDL Android audio driver", ANDROIDAUDIO_Init, 0
+};
+
+/* Pause (block) all non already paused audio devices by taking their mixer lock */
+void ANDROIDAUDIO_PauseDevices(void)
+{
+ /* TODO: Handle multiple devices? */
+ struct SDL_PrivateAudioData *private;
+ if(audioDevice != NULL && audioDevice->hidden != NULL) {
+ private = (struct SDL_PrivateAudioData *) audioDevice->hidden;
+ if (SDL_AtomicGet(&audioDevice->paused)) {
+ /* The device is already paused, leave it alone */
+ private->resume = SDL_FALSE;
+ }
+ else {
+ SDL_LockMutex(audioDevice->mixer_lock);
+ SDL_AtomicSet(&audioDevice->paused, 1);
+ private->resume = SDL_TRUE;
+ }
+ }
+
+ if(captureDevice != NULL && captureDevice->hidden != NULL) {
+ private = (struct SDL_PrivateAudioData *) captureDevice->hidden;
+ if (SDL_AtomicGet(&captureDevice->paused)) {
+ /* The device is already paused, leave it alone */
+ private->resume = SDL_FALSE;
+ }
+ else {
+ SDL_LockMutex(captureDevice->mixer_lock);
+ SDL_AtomicSet(&captureDevice->paused, 1);
+ private->resume = SDL_TRUE;
+ }
+ }
+}
+
+/* Resume (unblock) all non already paused audio devices by releasing their mixer lock */
+void ANDROIDAUDIO_ResumeDevices(void)
+{
+ /* TODO: Handle multiple devices? */
+ struct SDL_PrivateAudioData *private;
+ if(audioDevice != NULL && audioDevice->hidden != NULL) {
+ private = (struct SDL_PrivateAudioData *) audioDevice->hidden;
+ if (private->resume) {
+ SDL_AtomicSet(&audioDevice->paused, 0);
+ private->resume = SDL_FALSE;
+ SDL_UnlockMutex(audioDevice->mixer_lock);
+ }
+ }
+
+ if(captureDevice != NULL && captureDevice->hidden != NULL) {
+ private = (struct SDL_PrivateAudioData *) captureDevice->hidden;
+ if (private->resume) {
+ SDL_AtomicSet(&captureDevice->paused, 0);
+ private->resume = SDL_FALSE;
+ SDL_UnlockMutex(captureDevice->mixer_lock);
+ }
+ }
+}
+
+#else
+
+void ANDROIDAUDIO_ResumeDevices(void) {}
+void ANDROIDAUDIO_PauseDevices(void) {}
+
+#endif /* SDL_AUDIO_DRIVER_ANDROID */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/audio/android/SDL_androidaudio.h b/src/3rdparty/SDL2/src/audio/android/SDL_androidaudio.h
new file mode 100644
index 0000000..c732ac6
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/android/SDL_androidaudio.h
@@ -0,0 +1,42 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_androidaudio_h_
+#define SDL_androidaudio_h_
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData
+{
+ /* Resume device if it was paused automatically */
+ int resume;
+};
+
+void ANDROIDAUDIO_ResumeDevices(void);
+void ANDROIDAUDIO_PauseDevices(void);
+
+#endif /* SDL_androidaudio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/arts/SDL_artsaudio.c b/src/3rdparty/SDL2/src/audio/arts/SDL_artsaudio.c
new file mode 100644
index 0000000..4e3ebf2
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/arts/SDL_artsaudio.c
@@ -0,0 +1,365 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_ARTS
+
+/* Allow access to a raw mixing buffer */
+
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
+#include <unistd.h>
+#include <errno.h>
+
+#include "SDL_timer.h"
+#include "SDL_audio.h"
+#include "../SDL_audio_c.h"
+#include "SDL_artsaudio.h"
+
+#ifdef SDL_AUDIO_DRIVER_ARTS_DYNAMIC
+#include "SDL_name.h"
+#include "SDL_loadso.h"
+#else
+#define SDL_NAME(X) X
+#endif
+
+#ifdef SDL_AUDIO_DRIVER_ARTS_DYNAMIC
+
+static const char *arts_library = SDL_AUDIO_DRIVER_ARTS_DYNAMIC;
+static void *arts_handle = NULL;
+
+/* !!! FIXME: I hate this SDL_NAME clutter...it makes everything so messy! */
+static int (*SDL_NAME(arts_init)) (void);
+static void (*SDL_NAME(arts_free)) (void);
+static arts_stream_t(*SDL_NAME(arts_play_stream)) (int rate, int bits,
+ int channels,
+ const char *name);
+static int (*SDL_NAME(arts_stream_set)) (arts_stream_t s,
+ arts_parameter_t param, int value);
+static int (*SDL_NAME(arts_stream_get)) (arts_stream_t s,
+ arts_parameter_t param);
+static int (*SDL_NAME(arts_write)) (arts_stream_t s, const void *buffer,
+ int count);
+static void (*SDL_NAME(arts_close_stream)) (arts_stream_t s);
+static int (*SDL_NAME(arts_suspend))(void);
+static int (*SDL_NAME(arts_suspended)) (void);
+static const char *(*SDL_NAME(arts_error_text)) (int errorcode);
+
+#define SDL_ARTS_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) }
+static struct
+{
+ const char *name;
+ void **func;
+} arts_functions[] = {
+/* *INDENT-OFF* */
+ SDL_ARTS_SYM(arts_init),
+ SDL_ARTS_SYM(arts_free),
+ SDL_ARTS_SYM(arts_play_stream),
+ SDL_ARTS_SYM(arts_stream_set),
+ SDL_ARTS_SYM(arts_stream_get),
+ SDL_ARTS_SYM(arts_write),
+ SDL_ARTS_SYM(arts_close_stream),
+ SDL_ARTS_SYM(arts_suspend),
+ SDL_ARTS_SYM(arts_suspended),
+ SDL_ARTS_SYM(arts_error_text),
+/* *INDENT-ON* */
+};
+
+#undef SDL_ARTS_SYM
+
+static void
+UnloadARTSLibrary()
+{
+ if (arts_handle != NULL) {
+ SDL_UnloadObject(arts_handle);
+ arts_handle = NULL;
+ }
+}
+
+static int
+LoadARTSLibrary(void)
+{
+ int i, retval = -1;
+
+ if (arts_handle == NULL) {
+ arts_handle = SDL_LoadObject(arts_library);
+ if (arts_handle != NULL) {
+ retval = 0;
+ for (i = 0; i < SDL_arraysize(arts_functions); ++i) {
+ *arts_functions[i].func =
+ SDL_LoadFunction(arts_handle, arts_functions[i].name);
+ if (!*arts_functions[i].func) {
+ retval = -1;
+ UnloadARTSLibrary();
+ break;
+ }
+ }
+ }
+ }
+
+ return retval;
+}
+
+#else
+
+static void
+UnloadARTSLibrary()
+{
+ return;
+}
+
+static int
+LoadARTSLibrary(void)
+{
+ return 0;
+}
+
+#endif /* SDL_AUDIO_DRIVER_ARTS_DYNAMIC */
+
+/* This function waits until it is possible to write a full sound buffer */
+static void
+ARTS_WaitDevice(_THIS)
+{
+ Sint32 ticks;
+
+ /* Check to see if the thread-parent process is still alive */
+ {
+ static int cnt = 0;
+ /* Note that this only works with thread implementations
+ that use a different process id for each thread.
+ */
+ /* Check every 10 loops */
+ if (this->hidden->parent && (((++cnt) % 10) == 0)) {
+ if (kill(this->hidden->parent, 0) < 0 && errno == ESRCH) {
+ SDL_OpenedAudioDeviceDisconnected(this);
+ }
+ }
+ }
+
+ /* Use timer for general audio synchronization */
+ ticks =
+ ((Sint32) (this->hidden->next_frame - SDL_GetTicks())) - FUDGE_TICKS;
+ if (ticks > 0) {
+ SDL_Delay(ticks);
+ }
+}
+
+static void
+ARTS_PlayDevice(_THIS)
+{
+ /* Write the audio data */
+ int written = SDL_NAME(arts_write) (this->hidden->stream,
+ this->hidden->mixbuf,
+ this->hidden->mixlen);
+
+ /* If timer synchronization is enabled, set the next write frame */
+ if (this->hidden->frame_ticks) {
+ this->hidden->next_frame += this->hidden->frame_ticks;
+ }
+
+ /* If we couldn't write, assume fatal error for now */
+ if (written < 0) {
+ SDL_OpenedAudioDeviceDisconnected(this);
+ }
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Wrote %d bytes of audio data\n", written);
+#endif
+}
+
+static Uint8 *
+ARTS_GetDeviceBuf(_THIS)
+{
+ return (this->hidden->mixbuf);
+}
+
+
+static void
+ARTS_CloseDevice(_THIS)
+{
+ if (this->hidden->stream) {
+ SDL_NAME(arts_close_stream) (this->hidden->stream);
+ }
+ SDL_NAME(arts_free) ();
+ SDL_free(this->hidden->mixbuf);
+ SDL_free(this->hidden);
+}
+
+static int
+ARTS_Suspend(void)
+{
+ const Uint32 abortms = SDL_GetTicks() + 3000; /* give up after 3 secs */
+ while ( (!SDL_NAME(arts_suspended)()) && !SDL_TICKS_PASSED(SDL_GetTicks(), abortms) ) {
+ if ( SDL_NAME(arts_suspend)() ) {
+ break;
+ }
+ }
+ return SDL_NAME(arts_suspended)();
+}
+
+static int
+ARTS_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ int rc = 0;
+ int bits = 0, frag_spec = 0;
+ SDL_AudioFormat test_format = 0, format = 0;
+
+ /* Initialize all variables that we clean on shutdown */
+ this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc((sizeof *this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(this->hidden);
+
+ /* Try for a closest match on audio format */
+ for (test_format = SDL_FirstAudioFormat(this->spec.format);
+ !format && test_format;) {
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
+#endif
+ switch (test_format) {
+ case AUDIO_U8:
+ bits = 8;
+ format = 1;
+ break;
+ case AUDIO_S16LSB:
+ bits = 16;
+ format = 1;
+ break;
+ default:
+ format = 0;
+ break;
+ }
+ if (!format) {
+ test_format = SDL_NextAudioFormat();
+ }
+ }
+ if (format == 0) {
+ return SDL_SetError("Couldn't find any hardware audio formats");
+ }
+ this->spec.format = test_format;
+
+ if ((rc = SDL_NAME(arts_init) ()) != 0) {
+ return SDL_SetError("Unable to initialize ARTS: %s",
+ SDL_NAME(arts_error_text) (rc));
+ }
+
+ if (!ARTS_Suspend()) {
+ return SDL_SetError("ARTS can not open audio device");
+ }
+
+ this->hidden->stream = SDL_NAME(arts_play_stream) (this->spec.freq,
+ bits,
+ this->spec.channels,
+ "SDL");
+
+ /* Play nothing so we have at least one write (server bug workaround). */
+ SDL_NAME(arts_write) (this->hidden->stream, "", 0);
+
+ /* Calculate the final parameters for this audio specification */
+ SDL_CalculateAudioSpec(&this->spec);
+
+ /* Determine the power of two of the fragment size */
+ for (frag_spec = 0; (0x01 << frag_spec) < this->spec.size; ++frag_spec);
+ if ((0x01 << frag_spec) != this->spec.size) {
+ return SDL_SetError("Fragment size must be a power of two");
+ }
+ frag_spec |= 0x00020000; /* two fragments, for low latency */
+
+#ifdef ARTS_P_PACKET_SETTINGS
+ SDL_NAME(arts_stream_set) (this->hidden->stream,
+ ARTS_P_PACKET_SETTINGS, frag_spec);
+#else
+ SDL_NAME(arts_stream_set) (this->hidden->stream, ARTS_P_PACKET_SIZE,
+ frag_spec & 0xffff);
+ SDL_NAME(arts_stream_set) (this->hidden->stream, ARTS_P_PACKET_COUNT,
+ frag_spec >> 16);
+#endif
+ this->spec.size = SDL_NAME(arts_stream_get) (this->hidden->stream,
+ ARTS_P_PACKET_SIZE);
+
+ /* Allocate mixing buffer */
+ this->hidden->mixlen = this->spec.size;
+ this->hidden->mixbuf = (Uint8 *) SDL_malloc(this->hidden->mixlen);
+ if (this->hidden->mixbuf == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
+
+ /* Get the parent process id (we're the parent of the audio thread) */
+ this->hidden->parent = getpid();
+
+ /* We're ready to rock and roll. :-) */
+ return 0;
+}
+
+
+static void
+ARTS_Deinitialize(void)
+{
+ UnloadARTSLibrary();
+}
+
+
+static int
+ARTS_Init(SDL_AudioDriverImpl * impl)
+{
+ if (LoadARTSLibrary() < 0) {
+ return 0;
+ } else {
+ if (SDL_NAME(arts_init) () != 0) {
+ UnloadARTSLibrary();
+ SDL_SetError("ARTS: arts_init failed (no audio server?)");
+ return 0;
+ }
+
+ /* Play a stream so aRts doesn't crash */
+ if (ARTS_Suspend()) {
+ arts_stream_t stream;
+ stream = SDL_NAME(arts_play_stream) (44100, 16, 2, "SDL");
+ SDL_NAME(arts_write) (stream, "", 0);
+ SDL_NAME(arts_close_stream) (stream);
+ }
+
+ SDL_NAME(arts_free) ();
+ }
+
+ /* Set the function pointers */
+ impl->OpenDevice = ARTS_OpenDevice;
+ impl->PlayDevice = ARTS_PlayDevice;
+ impl->WaitDevice = ARTS_WaitDevice;
+ impl->GetDeviceBuf = ARTS_GetDeviceBuf;
+ impl->CloseDevice = ARTS_CloseDevice;
+ impl->Deinitialize = ARTS_Deinitialize;
+ impl->OnlyHasDefaultOutputDevice = 1;
+
+ return 1; /* this audio target is available. */
+}
+
+
+AudioBootStrap ARTS_bootstrap = {
+ "arts", "Analog RealTime Synthesizer", ARTS_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_ARTS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/arts/SDL_artsaudio.h b/src/3rdparty/SDL2/src/audio/arts/SDL_artsaudio.h
new file mode 100644
index 0000000..7743654
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/arts/SDL_artsaudio.h
@@ -0,0 +1,53 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_artsaudio_h_
+#define SDL_artsaudio_h_
+
+#include <artsc.h>
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData
+{
+ /* The stream descriptor for the audio device */
+ arts_stream_t stream;
+
+ /* The parent process id, to detect when application quits */
+ pid_t parent;
+
+ /* Raw mixing buffer */
+ Uint8 *mixbuf;
+ int mixlen;
+
+ /* Support for audio timing using a timer, in addition to SDL_IOReady() */
+ float frame_ticks;
+ float next_frame;
+};
+#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
+
+#endif /* SDL_artsaudio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/coreaudio/SDL_coreaudio.h b/src/3rdparty/SDL2/src/audio/coreaudio/SDL_coreaudio.h
new file mode 100644
index 0000000..7ce8b8d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/coreaudio/SDL_coreaudio.h
@@ -0,0 +1,68 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_coreaudio_h_
+#define SDL_coreaudio_h_
+
+#include "../SDL_sysaudio.h"
+
+#if !defined(__IPHONEOS__)
+#define MACOSX_COREAUDIO 1
+#endif
+
+#if MACOSX_COREAUDIO
+#include <CoreAudio/CoreAudio.h>
+#include <CoreServices/CoreServices.h>
+#else
+#import <AVFoundation/AVFoundation.h>
+#import <UIKit/UIApplication.h>
+#endif
+
+#include <AudioToolbox/AudioToolbox.h>
+#include <AudioUnit/AudioUnit.h>
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData
+{
+ SDL_Thread *thread;
+ AudioQueueRef audioQueue;
+ AudioQueueBufferRef *audioBuffer;
+ void *buffer;
+ UInt32 bufferOffset;
+ UInt32 bufferSize;
+ AudioStreamBasicDescription strdesc;
+ SDL_sem *ready_semaphore;
+ char *thread_error;
+ SDL_atomic_t shutdown;
+#if MACOSX_COREAUDIO
+ AudioDeviceID deviceID;
+#else
+ SDL_bool interrupted;
+ CFTypeRef interruption_listener;
+#endif
+};
+
+#endif /* SDL_coreaudio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/coreaudio/SDL_coreaudio.m b/src/3rdparty/SDL2/src/audio/coreaudio/SDL_coreaudio.m
new file mode 100644
index 0000000..92f5f12
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/coreaudio/SDL_coreaudio.m
@@ -0,0 +1,891 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_COREAUDIO
+
+/* !!! FIXME: clean out some of the macro salsa in here. */
+
+#include "SDL_audio.h"
+#include "SDL_hints.h"
+#include "../SDL_audio_c.h"
+#include "../SDL_sysaudio.h"
+#include "SDL_coreaudio.h"
+#include "SDL_assert.h"
+#include "../../thread/SDL_systhread.h"
+
+#define DEBUG_COREAUDIO 0
+
+#define CHECK_RESULT(msg) \
+ if (result != noErr) { \
+ SDL_SetError("CoreAudio error (%s): %d", msg, (int) result); \
+ return 0; \
+ }
+
+#if MACOSX_COREAUDIO
+static const AudioObjectPropertyAddress devlist_address = {
+ kAudioHardwarePropertyDevices,
+ kAudioObjectPropertyScopeGlobal,
+ kAudioObjectPropertyElementMaster
+};
+
+typedef void (*addDevFn)(const char *name, const int iscapture, AudioDeviceID devId, void *data);
+
+typedef struct AudioDeviceList
+{
+ AudioDeviceID devid;
+ SDL_bool alive;
+ struct AudioDeviceList *next;
+} AudioDeviceList;
+
+static AudioDeviceList *output_devs = NULL;
+static AudioDeviceList *capture_devs = NULL;
+
+static SDL_bool
+add_to_internal_dev_list(const int iscapture, AudioDeviceID devId)
+{
+ AudioDeviceList *item = (AudioDeviceList *) SDL_malloc(sizeof (AudioDeviceList));
+ if (item == NULL) {
+ return SDL_FALSE;
+ }
+ item->devid = devId;
+ item->alive = SDL_TRUE;
+ item->next = iscapture ? capture_devs : output_devs;
+ if (iscapture) {
+ capture_devs = item;
+ } else {
+ output_devs = item;
+ }
+
+ return SDL_TRUE;
+}
+
+static void
+addToDevList(const char *name, const int iscapture, AudioDeviceID devId, void *data)
+{
+ if (add_to_internal_dev_list(iscapture, devId)) {
+ SDL_AddAudioDevice(iscapture, name, (void *) ((size_t) devId));
+ }
+}
+
+static void
+build_device_list(int iscapture, addDevFn addfn, void *addfndata)
+{
+ OSStatus result = noErr;
+ UInt32 size = 0;
+ AudioDeviceID *devs = NULL;
+ UInt32 i = 0;
+ UInt32 max = 0;
+
+ result = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject,
+ &devlist_address, 0, NULL, &size);
+ if (result != kAudioHardwareNoError)
+ return;
+
+ devs = (AudioDeviceID *) alloca(size);
+ if (devs == NULL)
+ return;
+
+ result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
+ &devlist_address, 0, NULL, &size, devs);
+ if (result != kAudioHardwareNoError)
+ return;
+
+ max = size / sizeof (AudioDeviceID);
+ for (i = 0; i < max; i++) {
+ CFStringRef cfstr = NULL;
+ char *ptr = NULL;
+ AudioDeviceID dev = devs[i];
+ AudioBufferList *buflist = NULL;
+ int usable = 0;
+ CFIndex len = 0;
+ const AudioObjectPropertyAddress addr = {
+ kAudioDevicePropertyStreamConfiguration,
+ iscapture ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput,
+ kAudioObjectPropertyElementMaster
+ };
+
+ const AudioObjectPropertyAddress nameaddr = {
+ kAudioObjectPropertyName,
+ iscapture ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput,
+ kAudioObjectPropertyElementMaster
+ };
+
+ result = AudioObjectGetPropertyDataSize(dev, &addr, 0, NULL, &size);
+ if (result != noErr)
+ continue;
+
+ buflist = (AudioBufferList *) SDL_malloc(size);
+ if (buflist == NULL)
+ continue;
+
+ result = AudioObjectGetPropertyData(dev, &addr, 0, NULL,
+ &size, buflist);
+
+ if (result == noErr) {
+ UInt32 j;
+ for (j = 0; j < buflist->mNumberBuffers; j++) {
+ if (buflist->mBuffers[j].mNumberChannels > 0) {
+ usable = 1;
+ break;
+ }
+ }
+ }
+
+ SDL_free(buflist);
+
+ if (!usable)
+ continue;
+
+
+ size = sizeof (CFStringRef);
+ result = AudioObjectGetPropertyData(dev, &nameaddr, 0, NULL, &size, &cfstr);
+ if (result != kAudioHardwareNoError)
+ continue;
+
+ len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstr),
+ kCFStringEncodingUTF8);
+
+ ptr = (char *) SDL_malloc(len + 1);
+ usable = ((ptr != NULL) &&
+ (CFStringGetCString
+ (cfstr, ptr, len + 1, kCFStringEncodingUTF8)));
+
+ CFRelease(cfstr);
+
+ if (usable) {
+ len = strlen(ptr);
+ /* Some devices have whitespace at the end...trim it. */
+ while ((len > 0) && (ptr[len - 1] == ' ')) {
+ len--;
+ }
+ usable = (len > 0);
+ }
+
+ if (usable) {
+ ptr[len] = '\0';
+
+#if DEBUG_COREAUDIO
+ printf("COREAUDIO: Found %s device #%d: '%s' (devid %d)\n",
+ ((iscapture) ? "capture" : "output"),
+ (int) i, ptr, (int) dev);
+#endif
+ addfn(ptr, iscapture, dev, addfndata);
+ }
+ SDL_free(ptr); /* addfn() would have copied the string. */
+ }
+}
+
+static void
+free_audio_device_list(AudioDeviceList **list)
+{
+ AudioDeviceList *item = *list;
+ while (item) {
+ AudioDeviceList *next = item->next;
+ SDL_free(item);
+ item = next;
+ }
+ *list = NULL;
+}
+
+static void
+COREAUDIO_DetectDevices(void)
+{
+ build_device_list(SDL_TRUE, addToDevList, NULL);
+ build_device_list(SDL_FALSE, addToDevList, NULL);
+}
+
+static void
+build_device_change_list(const char *name, const int iscapture, AudioDeviceID devId, void *data)
+{
+ AudioDeviceList **list = (AudioDeviceList **) data;
+ AudioDeviceList *item;
+ for (item = *list; item != NULL; item = item->next) {
+ if (item->devid == devId) {
+ item->alive = SDL_TRUE;
+ return;
+ }
+ }
+
+ add_to_internal_dev_list(iscapture, devId); /* new device, add it. */
+ SDL_AddAudioDevice(iscapture, name, (void *) ((size_t) devId));
+}
+
+static void
+reprocess_device_list(const int iscapture, AudioDeviceList **list)
+{
+ AudioDeviceList *item;
+ AudioDeviceList *prev = NULL;
+ for (item = *list; item != NULL; item = item->next) {
+ item->alive = SDL_FALSE;
+ }
+
+ build_device_list(iscapture, build_device_change_list, list);
+
+ /* free items in the list that aren't still alive. */
+ item = *list;
+ while (item != NULL) {
+ AudioDeviceList *next = item->next;
+ if (item->alive) {
+ prev = item;
+ } else {
+ SDL_RemoveAudioDevice(iscapture, (void *) ((size_t) item->devid));
+ if (prev) {
+ prev->next = item->next;
+ } else {
+ *list = item->next;
+ }
+ SDL_free(item);
+ }
+ item = next;
+ }
+}
+
+/* this is called when the system's list of available audio devices changes. */
+static OSStatus
+device_list_changed(AudioObjectID systemObj, UInt32 num_addr, const AudioObjectPropertyAddress *addrs, void *data)
+{
+ reprocess_device_list(SDL_TRUE, &capture_devs);
+ reprocess_device_list(SDL_FALSE, &output_devs);
+ return 0;
+}
+#endif
+
+
+static int open_playback_devices = 0;
+static int open_capture_devices = 0;
+
+#if !MACOSX_COREAUDIO
+
+static void interruption_begin(_THIS)
+{
+ if (this != NULL && this->hidden->audioQueue != NULL) {
+ this->hidden->interrupted = SDL_TRUE;
+ AudioQueuePause(this->hidden->audioQueue);
+ }
+}
+
+static void interruption_end(_THIS)
+{
+ if (this != NULL && this->hidden != NULL && this->hidden->audioQueue != NULL
+ && this->hidden->interrupted
+ && AudioQueueStart(this->hidden->audioQueue, NULL) == AVAudioSessionErrorCodeNone) {
+ this->hidden->interrupted = SDL_FALSE;
+ }
+}
+
+@interface SDLInterruptionListener : NSObject
+
+@property (nonatomic, assign) SDL_AudioDevice *device;
+
+@end
+
+@implementation SDLInterruptionListener
+
+- (void)audioSessionInterruption:(NSNotification *)note
+{
+ @synchronized (self) {
+ NSNumber *type = note.userInfo[AVAudioSessionInterruptionTypeKey];
+ if (type.unsignedIntegerValue == AVAudioSessionInterruptionTypeBegan) {
+ interruption_begin(self.device);
+ } else {
+ interruption_end(self.device);
+ }
+ }
+}
+
+- (void)applicationBecameActive:(NSNotification *)note
+{
+ @synchronized (self) {
+ interruption_end(self.device);
+ }
+}
+
+@end
+
+static BOOL update_audio_session(_THIS, SDL_bool open)
+{
+ @autoreleasepool {
+ AVAudioSession *session = [AVAudioSession sharedInstance];
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+ /* Set category to ambient by default so that other music continues playing. */
+ NSString *category = AVAudioSessionCategoryAmbient;
+ NSError *err = nil;
+
+ if (open_playback_devices && open_capture_devices) {
+ category = AVAudioSessionCategoryPlayAndRecord;
+ } else if (open_capture_devices) {
+ category = AVAudioSessionCategoryRecord;
+ } else {
+ const char *hint = SDL_GetHint(SDL_HINT_AUDIO_CATEGORY);
+ if (hint) {
+ if (SDL_strcasecmp(hint, "AVAudioSessionCategoryAmbient") == 0) {
+ category = AVAudioSessionCategoryAmbient;
+ } else if (SDL_strcasecmp(hint, "AVAudioSessionCategorySoloAmbient") == 0) {
+ category = AVAudioSessionCategorySoloAmbient;
+ } else if (SDL_strcasecmp(hint, "AVAudioSessionCategoryPlayback") == 0 ||
+ SDL_strcasecmp(hint, "playback") == 0) {
+ category = AVAudioSessionCategoryPlayback;
+ }
+ }
+ }
+
+ if (![session setCategory:category error:&err]) {
+ NSString *desc = err.description;
+ SDL_SetError("Could not set Audio Session category: %s", desc.UTF8String);
+ return NO;
+ }
+
+ if (open_playback_devices + open_capture_devices == 1) {
+ if (![session setActive:YES error:&err]) {
+ NSString *desc = err.description;
+ SDL_SetError("Could not activate Audio Session: %s", desc.UTF8String);
+ return NO;
+ }
+ } else if (!open_playback_devices && !open_capture_devices) {
+ [session setActive:NO error:nil];
+ }
+
+ if (open) {
+ SDLInterruptionListener *listener = [SDLInterruptionListener new];
+ listener.device = this;
+
+ [center addObserver:listener
+ selector:@selector(audioSessionInterruption:)
+ name:AVAudioSessionInterruptionNotification
+ object:session];
+
+ /* An interruption end notification is not guaranteed to be sent if
+ we were previously interrupted... resuming if needed when the app
+ becomes active seems to be the way to go. */
+ [center addObserver:listener
+ selector:@selector(applicationBecameActive:)
+ name:UIApplicationDidBecomeActiveNotification
+ object:session];
+
+ [center addObserver:listener
+ selector:@selector(applicationBecameActive:)
+ name:UIApplicationWillEnterForegroundNotification
+ object:session];
+
+ this->hidden->interruption_listener = CFBridgingRetain(listener);
+ } else {
+ if (this->hidden->interruption_listener != NULL) {
+ SDLInterruptionListener *listener = nil;
+ listener = (SDLInterruptionListener *) CFBridgingRelease(this->hidden->interruption_listener);
+ @synchronized (listener) {
+ listener.device = NULL;
+ }
+ [center removeObserver:listener];
+ }
+ }
+ }
+
+ return YES;
+}
+#endif
+
+
+/* The AudioQueue callback */
+static void
+outputCallback(void *inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer)
+{
+ SDL_AudioDevice *this = (SDL_AudioDevice *) inUserData;
+ if (SDL_AtomicGet(&this->hidden->shutdown)) {
+ return; /* don't do anything. */
+ }
+
+ if (!SDL_AtomicGet(&this->enabled) || SDL_AtomicGet(&this->paused)) {
+ /* Supply silence if audio is not enabled or paused */
+ SDL_memset(inBuffer->mAudioData, this->spec.silence, inBuffer->mAudioDataBytesCapacity);
+ } else {
+ UInt32 remaining = inBuffer->mAudioDataBytesCapacity;
+ Uint8 *ptr = (Uint8 *) inBuffer->mAudioData;
+
+ while (remaining > 0) {
+ UInt32 len;
+ if (this->hidden->bufferOffset >= this->hidden->bufferSize) {
+ /* Generate the data */
+ SDL_LockMutex(this->mixer_lock);
+ (*this->callbackspec.callback)(this->callbackspec.userdata,
+ this->hidden->buffer, this->hidden->bufferSize);
+ SDL_UnlockMutex(this->mixer_lock);
+ this->hidden->bufferOffset = 0;
+ }
+
+ len = this->hidden->bufferSize - this->hidden->bufferOffset;
+ if (len > remaining) {
+ len = remaining;
+ }
+ SDL_memcpy(ptr, (char *)this->hidden->buffer +
+ this->hidden->bufferOffset, len);
+ ptr = ptr + len;
+ remaining -= len;
+ this->hidden->bufferOffset += len;
+ }
+ }
+
+ AudioQueueEnqueueBuffer(this->hidden->audioQueue, inBuffer, 0, NULL);
+
+ inBuffer->mAudioDataByteSize = inBuffer->mAudioDataBytesCapacity;
+}
+
+static void
+inputCallback(void *inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer,
+ const AudioTimeStamp *inStartTime, UInt32 inNumberPacketDescriptions,
+ const AudioStreamPacketDescription *inPacketDescs )
+{
+ SDL_AudioDevice *this = (SDL_AudioDevice *) inUserData;
+
+ if (SDL_AtomicGet(&this->shutdown)) {
+ return; /* don't do anything. */
+ }
+
+ /* ignore unless we're active. */
+ if (!SDL_AtomicGet(&this->paused) && SDL_AtomicGet(&this->enabled) && !SDL_AtomicGet(&this->paused)) {
+ const Uint8 *ptr = (const Uint8 *) inBuffer->mAudioData;
+ UInt32 remaining = inBuffer->mAudioDataByteSize;
+ while (remaining > 0) {
+ UInt32 len = this->hidden->bufferSize - this->hidden->bufferOffset;
+ if (len > remaining) {
+ len = remaining;
+ }
+
+ SDL_memcpy((char *)this->hidden->buffer + this->hidden->bufferOffset, ptr, len);
+ ptr += len;
+ remaining -= len;
+ this->hidden->bufferOffset += len;
+
+ if (this->hidden->bufferOffset >= this->hidden->bufferSize) {
+ SDL_LockMutex(this->mixer_lock);
+ (*this->callbackspec.callback)(this->callbackspec.userdata, this->hidden->buffer, this->hidden->bufferSize);
+ SDL_UnlockMutex(this->mixer_lock);
+ this->hidden->bufferOffset = 0;
+ }
+ }
+ }
+
+ AudioQueueEnqueueBuffer(this->hidden->audioQueue, inBuffer, 0, NULL);
+}
+
+
+#if MACOSX_COREAUDIO
+static const AudioObjectPropertyAddress alive_address =
+{
+ kAudioDevicePropertyDeviceIsAlive,
+ kAudioObjectPropertyScopeGlobal,
+ kAudioObjectPropertyElementMaster
+};
+
+static OSStatus
+device_unplugged(AudioObjectID devid, UInt32 num_addr, const AudioObjectPropertyAddress *addrs, void *data)
+{
+ SDL_AudioDevice *this = (SDL_AudioDevice *) data;
+ SDL_bool dead = SDL_FALSE;
+ UInt32 isAlive = 1;
+ UInt32 size = sizeof (isAlive);
+ OSStatus error;
+
+ if (!SDL_AtomicGet(&this->enabled)) {
+ return 0; /* already known to be dead. */
+ }
+
+ error = AudioObjectGetPropertyData(this->hidden->deviceID, &alive_address,
+ 0, NULL, &size, &isAlive);
+
+ if (error == kAudioHardwareBadDeviceError) {
+ dead = SDL_TRUE; /* device was unplugged. */
+ } else if ((error == kAudioHardwareNoError) && (!isAlive)) {
+ dead = SDL_TRUE; /* device died in some other way. */
+ }
+
+ if (dead) {
+ SDL_OpenedAudioDeviceDisconnected(this);
+ }
+
+ return 0;
+}
+#endif
+
+static void
+COREAUDIO_CloseDevice(_THIS)
+{
+ const SDL_bool iscapture = this->iscapture;
+
+/* !!! FIXME: what does iOS do when a bluetooth audio device vanishes? Headphones unplugged? */
+/* !!! FIXME: (we only do a "default" device on iOS right now...can we do more?) */
+#if MACOSX_COREAUDIO
+ /* Fire a callback if the device stops being "alive" (disconnected, etc). */
+ AudioObjectRemovePropertyListener(this->hidden->deviceID, &alive_address, device_unplugged, this);
+#endif
+
+#if !MACOSX_COREAUDIO
+ update_audio_session(this, SDL_FALSE);
+#endif
+
+ /* if callback fires again, feed silence; don't call into the app. */
+ SDL_AtomicSet(&this->paused, 1);
+
+ if (this->hidden->audioQueue) {
+ AudioQueueDispose(this->hidden->audioQueue, 1);
+ }
+
+ if (this->hidden->thread) {
+ SDL_AtomicSet(&this->hidden->shutdown, 1);
+ SDL_WaitThread(this->hidden->thread, NULL);
+ }
+
+ if (this->hidden->ready_semaphore) {
+ SDL_DestroySemaphore(this->hidden->ready_semaphore);
+ }
+
+ /* AudioQueueDispose() frees the actual buffer objects. */
+ SDL_free(this->hidden->audioBuffer);
+ SDL_free(this->hidden->thread_error);
+ SDL_free(this->hidden->buffer);
+ SDL_free(this->hidden);
+
+ if (iscapture) {
+ open_capture_devices--;
+ } else {
+ open_playback_devices--;
+ }
+}
+
+#if MACOSX_COREAUDIO
+static int
+prepare_device(_THIS, void *handle, int iscapture)
+{
+ AudioDeviceID devid = (AudioDeviceID) ((size_t) handle);
+ OSStatus result = noErr;
+ UInt32 size = 0;
+ UInt32 alive = 0;
+ pid_t pid = 0;
+
+ AudioObjectPropertyAddress addr = {
+ 0,
+ kAudioObjectPropertyScopeGlobal,
+ kAudioObjectPropertyElementMaster
+ };
+
+ if (handle == NULL) {
+ size = sizeof (AudioDeviceID);
+ addr.mSelector =
+ ((iscapture) ? kAudioHardwarePropertyDefaultInputDevice :
+ kAudioHardwarePropertyDefaultOutputDevice);
+ result = AudioObjectGetPropertyData(kAudioObjectSystemObject, &addr,
+ 0, NULL, &size, &devid);
+ CHECK_RESULT("AudioHardwareGetProperty (default device)");
+ }
+
+ addr.mSelector = kAudioDevicePropertyDeviceIsAlive;
+ addr.mScope = iscapture ? kAudioDevicePropertyScopeInput :
+ kAudioDevicePropertyScopeOutput;
+
+ size = sizeof (alive);
+ result = AudioObjectGetPropertyData(devid, &addr, 0, NULL, &size, &alive);
+ CHECK_RESULT
+ ("AudioDeviceGetProperty (kAudioDevicePropertyDeviceIsAlive)");
+
+ if (!alive) {
+ SDL_SetError("CoreAudio: requested device exists, but isn't alive.");
+ return 0;
+ }
+
+ addr.mSelector = kAudioDevicePropertyHogMode;
+ size = sizeof (pid);
+ result = AudioObjectGetPropertyData(devid, &addr, 0, NULL, &size, &pid);
+
+ /* some devices don't support this property, so errors are fine here. */
+ if ((result == noErr) && (pid != -1)) {
+ SDL_SetError("CoreAudio: requested device is being hogged.");
+ return 0;
+ }
+
+ this->hidden->deviceID = devid;
+ return 1;
+}
+#endif
+
+static int
+prepare_audioqueue(_THIS)
+{
+ const AudioStreamBasicDescription *strdesc = &this->hidden->strdesc;
+ const int iscapture = this->iscapture;
+ OSStatus result;
+ int i;
+
+ SDL_assert(CFRunLoopGetCurrent() != NULL);
+
+ if (iscapture) {
+ result = AudioQueueNewInput(strdesc, inputCallback, this, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode, 0, &this->hidden->audioQueue);
+ CHECK_RESULT("AudioQueueNewInput");
+ } else {
+ result = AudioQueueNewOutput(strdesc, outputCallback, this, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode, 0, &this->hidden->audioQueue);
+ CHECK_RESULT("AudioQueueNewOutput");
+ }
+
+#if MACOSX_COREAUDIO
+{
+ const AudioObjectPropertyAddress prop = {
+ kAudioDevicePropertyDeviceUID,
+ iscapture ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput,
+ kAudioObjectPropertyElementMaster
+ };
+ CFStringRef devuid;
+ UInt32 devuidsize = sizeof (devuid);
+ result = AudioObjectGetPropertyData(this->hidden->deviceID, &prop, 0, NULL, &devuidsize, &devuid);
+ CHECK_RESULT("AudioObjectGetPropertyData (kAudioDevicePropertyDeviceUID)");
+ result = AudioQueueSetProperty(this->hidden->audioQueue, kAudioQueueProperty_CurrentDevice, &devuid, devuidsize);
+ CHECK_RESULT("AudioQueueSetProperty (kAudioQueueProperty_CurrentDevice)");
+
+ /* !!! FIXME: what does iOS do when a bluetooth audio device vanishes? Headphones unplugged? */
+ /* !!! FIXME: (we only do a "default" device on iOS right now...can we do more?) */
+ /* Fire a callback if the device stops being "alive" (disconnected, etc). */
+ AudioObjectAddPropertyListener(this->hidden->deviceID, &alive_address, device_unplugged, this);
+}
+#endif
+
+ /* Calculate the final parameters for this audio specification */
+ SDL_CalculateAudioSpec(&this->spec);
+
+ /* Allocate a sample buffer */
+ this->hidden->bufferSize = this->spec.size;
+ this->hidden->bufferOffset = iscapture ? 0 : this->hidden->bufferSize;
+
+ this->hidden->buffer = SDL_malloc(this->hidden->bufferSize);
+ if (this->hidden->buffer == NULL) {
+ SDL_OutOfMemory();
+ return 0;
+ }
+
+ /* Make sure we can feed the device a minimum amount of time */
+ double MINIMUM_AUDIO_BUFFER_TIME_MS = 15.0;
+#if defined(__IPHONEOS__)
+ if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {
+ /* Older iOS hardware, use 40 ms as a minimum time */
+ MINIMUM_AUDIO_BUFFER_TIME_MS = 40.0;
+ }
+#endif
+ const double msecs = (this->spec.samples / ((double) this->spec.freq)) * 1000.0;
+ int numAudioBuffers = 2;
+ if (msecs < MINIMUM_AUDIO_BUFFER_TIME_MS) { /* use more buffers if we have a VERY small sample set. */
+ numAudioBuffers = ((int)SDL_ceil(MINIMUM_AUDIO_BUFFER_TIME_MS / msecs) * 2);
+ }
+
+ this->hidden->audioBuffer = SDL_calloc(1, sizeof (AudioQueueBufferRef) * numAudioBuffers);
+ if (this->hidden->audioBuffer == NULL) {
+ SDL_OutOfMemory();
+ return 0;
+ }
+
+#if DEBUG_COREAUDIO
+ printf("COREAUDIO: numAudioBuffers == %d\n", numAudioBuffers);
+#endif
+
+ for (i = 0; i < numAudioBuffers; i++) {
+ result = AudioQueueAllocateBuffer(this->hidden->audioQueue, this->spec.size, &this->hidden->audioBuffer[i]);
+ CHECK_RESULT("AudioQueueAllocateBuffer");
+ SDL_memset(this->hidden->audioBuffer[i]->mAudioData, this->spec.silence, this->hidden->audioBuffer[i]->mAudioDataBytesCapacity);
+ this->hidden->audioBuffer[i]->mAudioDataByteSize = this->hidden->audioBuffer[i]->mAudioDataBytesCapacity;
+ result = AudioQueueEnqueueBuffer(this->hidden->audioQueue, this->hidden->audioBuffer[i], 0, NULL);
+ CHECK_RESULT("AudioQueueEnqueueBuffer");
+ }
+
+ result = AudioQueueStart(this->hidden->audioQueue, NULL);
+ CHECK_RESULT("AudioQueueStart");
+
+ /* We're running! */
+ return 1;
+}
+
+static int
+audioqueue_thread(void *arg)
+{
+ SDL_AudioDevice *this = (SDL_AudioDevice *) arg;
+ const int rc = prepare_audioqueue(this);
+ if (!rc) {
+ this->hidden->thread_error = SDL_strdup(SDL_GetError());
+ SDL_SemPost(this->hidden->ready_semaphore);
+ return 0;
+ }
+
+ /* init was successful, alert parent thread and start running... */
+ SDL_SemPost(this->hidden->ready_semaphore);
+ while (!SDL_AtomicGet(&this->hidden->shutdown)) {
+ CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.10, 1);
+ }
+
+ if (!this->iscapture) { /* Drain off any pending playback. */
+ const CFTimeInterval secs = (((this->spec.size / (SDL_AUDIO_BITSIZE(this->spec.format) / 8)) / this->spec.channels) / ((CFTimeInterval) this->spec.freq)) * 2.0;
+ CFRunLoopRunInMode(kCFRunLoopDefaultMode, secs, 0);
+ }
+
+ return 0;
+}
+
+static int
+COREAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ AudioStreamBasicDescription *strdesc;
+ SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
+ int valid_datatype = 0;
+
+ /* Initialize all variables that we clean on shutdown */
+ this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc((sizeof *this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(this->hidden);
+
+ strdesc = &this->hidden->strdesc;
+
+ if (iscapture) {
+ open_capture_devices++;
+ } else {
+ open_playback_devices++;
+ }
+
+#if !MACOSX_COREAUDIO
+ if (!update_audio_session(this, SDL_TRUE)) {
+ return -1;
+ }
+
+ /* Stop CoreAudio from doing expensive audio rate conversion */
+ @autoreleasepool {
+ AVAudioSession* session = [AVAudioSession sharedInstance];
+ [session setPreferredSampleRate:this->spec.freq error:nil];
+ this->spec.freq = (int)session.sampleRate;
+ }
+#endif
+
+ /* Setup a AudioStreamBasicDescription with the requested format */
+ SDL_zerop(strdesc);
+ strdesc->mFormatID = kAudioFormatLinearPCM;
+ strdesc->mFormatFlags = kLinearPCMFormatFlagIsPacked;
+ strdesc->mChannelsPerFrame = this->spec.channels;
+ strdesc->mSampleRate = this->spec.freq;
+ strdesc->mFramesPerPacket = 1;
+
+ while ((!valid_datatype) && (test_format)) {
+ this->spec.format = test_format;
+ /* Just a list of valid SDL formats, so people don't pass junk here. */
+ switch (test_format) {
+ case AUDIO_U8:
+ case AUDIO_S8:
+ case AUDIO_U16LSB:
+ case AUDIO_S16LSB:
+ case AUDIO_U16MSB:
+ case AUDIO_S16MSB:
+ case AUDIO_S32LSB:
+ case AUDIO_S32MSB:
+ case AUDIO_F32LSB:
+ case AUDIO_F32MSB:
+ valid_datatype = 1;
+ strdesc->mBitsPerChannel = SDL_AUDIO_BITSIZE(this->spec.format);
+ if (SDL_AUDIO_ISBIGENDIAN(this->spec.format))
+ strdesc->mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
+
+ if (SDL_AUDIO_ISFLOAT(this->spec.format))
+ strdesc->mFormatFlags |= kLinearPCMFormatFlagIsFloat;
+ else if (SDL_AUDIO_ISSIGNED(this->spec.format))
+ strdesc->mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
+ break;
+ }
+ }
+
+ if (!valid_datatype) { /* shouldn't happen, but just in case... */
+ return SDL_SetError("Unsupported audio format");
+ }
+
+ strdesc->mBytesPerFrame = strdesc->mBitsPerChannel * strdesc->mChannelsPerFrame / 8;
+ strdesc->mBytesPerPacket = strdesc->mBytesPerFrame * strdesc->mFramesPerPacket;
+
+#if MACOSX_COREAUDIO
+ if (!prepare_device(this, handle, iscapture)) {
+ return -1;
+ }
+#endif
+
+ /* This has to init in a new thread so it can get its own CFRunLoop. :/ */
+ SDL_AtomicSet(&this->hidden->shutdown, 0);
+ this->hidden->ready_semaphore = SDL_CreateSemaphore(0);
+ if (!this->hidden->ready_semaphore) {
+ return -1; /* oh well. */
+ }
+
+ this->hidden->thread = SDL_CreateThreadInternal(audioqueue_thread, "AudioQueue thread", 512 * 1024, this);
+ if (!this->hidden->thread) {
+ return -1;
+ }
+
+ SDL_SemWait(this->hidden->ready_semaphore);
+ SDL_DestroySemaphore(this->hidden->ready_semaphore);
+ this->hidden->ready_semaphore = NULL;
+
+ if ((this->hidden->thread != NULL) && (this->hidden->thread_error != NULL)) {
+ SDL_SetError("%s", this->hidden->thread_error);
+ return -1;
+ }
+
+ return (this->hidden->thread != NULL) ? 0 : -1;
+}
+
+static void
+COREAUDIO_Deinitialize(void)
+{
+#if MACOSX_COREAUDIO
+ AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &devlist_address, device_list_changed, NULL);
+ free_audio_device_list(&capture_devs);
+ free_audio_device_list(&output_devs);
+#endif
+}
+
+static int
+COREAUDIO_Init(SDL_AudioDriverImpl * impl)
+{
+ /* Set the function pointers */
+ impl->OpenDevice = COREAUDIO_OpenDevice;
+ impl->CloseDevice = COREAUDIO_CloseDevice;
+ impl->Deinitialize = COREAUDIO_Deinitialize;
+
+#if MACOSX_COREAUDIO
+ impl->DetectDevices = COREAUDIO_DetectDevices;
+ AudioObjectAddPropertyListener(kAudioObjectSystemObject, &devlist_address, device_list_changed, NULL);
+#else
+ impl->OnlyHasDefaultOutputDevice = 1;
+ impl->OnlyHasDefaultCaptureDevice = 1;
+#endif
+
+ impl->ProvidesOwnCallbackThread = 1;
+ impl->HasCaptureSupport = 1;
+
+ return 1; /* this audio target is available. */
+}
+
+AudioBootStrap COREAUDIO_bootstrap = {
+ "coreaudio", "CoreAudio", COREAUDIO_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_COREAUDIO */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/directsound/SDL_directsound.c b/src/3rdparty/SDL2/src/audio/directsound/SDL_directsound.c
new file mode 100644
index 0000000..09b83ae
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/directsound/SDL_directsound.c
@@ -0,0 +1,604 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_DSOUND
+
+/* Allow access to a raw mixing buffer */
+
+#include "SDL_assert.h"
+#include "SDL_timer.h"
+#include "SDL_loadso.h"
+#include "SDL_audio.h"
+#include "../SDL_audio_c.h"
+#include "SDL_directsound.h"
+
+#ifndef WAVE_FORMAT_IEEE_FLOAT
+#define WAVE_FORMAT_IEEE_FLOAT 0x0003
+#endif
+
+/* DirectX function pointers for audio */
+static void* DSoundDLL = NULL;
+typedef HRESULT (WINAPI *fnDirectSoundCreate8)(LPGUID,LPDIRECTSOUND*,LPUNKNOWN);
+typedef HRESULT (WINAPI *fnDirectSoundEnumerateW)(LPDSENUMCALLBACKW, LPVOID);
+typedef HRESULT (WINAPI *fnDirectSoundCaptureCreate8)(LPCGUID,LPDIRECTSOUNDCAPTURE8 *,LPUNKNOWN);
+typedef HRESULT (WINAPI *fnDirectSoundCaptureEnumerateW)(LPDSENUMCALLBACKW,LPVOID);
+static fnDirectSoundCreate8 pDirectSoundCreate8 = NULL;
+static fnDirectSoundEnumerateW pDirectSoundEnumerateW = NULL;
+static fnDirectSoundCaptureCreate8 pDirectSoundCaptureCreate8 = NULL;
+static fnDirectSoundCaptureEnumerateW pDirectSoundCaptureEnumerateW = NULL;
+
+static void
+DSOUND_Unload(void)
+{
+ pDirectSoundCreate8 = NULL;
+ pDirectSoundEnumerateW = NULL;
+ pDirectSoundCaptureCreate8 = NULL;
+ pDirectSoundCaptureEnumerateW = NULL;
+
+ if (DSoundDLL != NULL) {
+ SDL_UnloadObject(DSoundDLL);
+ DSoundDLL = NULL;
+ }
+}
+
+
+static int
+DSOUND_Load(void)
+{
+ int loaded = 0;
+
+ DSOUND_Unload();
+
+ DSoundDLL = SDL_LoadObject("DSOUND.DLL");
+ if (DSoundDLL == NULL) {
+ SDL_SetError("DirectSound: failed to load DSOUND.DLL");
+ } else {
+ /* Now make sure we have DirectX 8 or better... */
+ #define DSOUNDLOAD(f) { \
+ p##f = (fn##f) SDL_LoadFunction(DSoundDLL, #f); \
+ if (!p##f) loaded = 0; \
+ }
+ loaded = 1; /* will reset if necessary. */
+ DSOUNDLOAD(DirectSoundCreate8);
+ DSOUNDLOAD(DirectSoundEnumerateW);
+ DSOUNDLOAD(DirectSoundCaptureCreate8);
+ DSOUNDLOAD(DirectSoundCaptureEnumerateW);
+ #undef DSOUNDLOAD
+
+ if (!loaded) {
+ SDL_SetError("DirectSound: System doesn't appear to have DX8.");
+ }
+ }
+
+ if (!loaded) {
+ DSOUND_Unload();
+ }
+
+ return loaded;
+}
+
+static int
+SetDSerror(const char *function, int code)
+{
+ static const char *error;
+ static char errbuf[1024];
+
+ errbuf[0] = 0;
+ switch (code) {
+ case E_NOINTERFACE:
+ error = "Unsupported interface -- Is DirectX 8.0 or later installed?";
+ break;
+ case DSERR_ALLOCATED:
+ error = "Audio device in use";
+ break;
+ case DSERR_BADFORMAT:
+ error = "Unsupported audio format";
+ break;
+ case DSERR_BUFFERLOST:
+ error = "Mixing buffer was lost";
+ break;
+ case DSERR_CONTROLUNAVAIL:
+ error = "Control requested is not available";
+ break;
+ case DSERR_INVALIDCALL:
+ error = "Invalid call for the current state";
+ break;
+ case DSERR_INVALIDPARAM:
+ error = "Invalid parameter";
+ break;
+ case DSERR_NODRIVER:
+ error = "No audio device found";
+ break;
+ case DSERR_OUTOFMEMORY:
+ error = "Out of memory";
+ break;
+ case DSERR_PRIOLEVELNEEDED:
+ error = "Caller doesn't have priority";
+ break;
+ case DSERR_UNSUPPORTED:
+ error = "Function not supported";
+ break;
+ default:
+ SDL_snprintf(errbuf, SDL_arraysize(errbuf),
+ "%s: Unknown DirectSound error: 0x%x", function, code);
+ break;
+ }
+ if (!errbuf[0]) {
+ SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function,
+ error);
+ }
+ return SDL_SetError("%s", errbuf);
+}
+
+static void
+DSOUND_FreeDeviceHandle(void *handle)
+{
+ SDL_free(handle);
+}
+
+static BOOL CALLBACK
+FindAllDevs(LPGUID guid, LPCWSTR desc, LPCWSTR module, LPVOID data)
+{
+ const int iscapture = (int) ((size_t) data);
+ if (guid != NULL) { /* skip default device */
+ char *str = WIN_LookupAudioDeviceName(desc, guid);
+ if (str != NULL) {
+ LPGUID cpyguid = (LPGUID) SDL_malloc(sizeof (GUID));
+ SDL_memcpy(cpyguid, guid, sizeof (GUID));
+ SDL_AddAudioDevice(iscapture, str, cpyguid);
+ SDL_free(str); /* addfn() makes a copy of this string. */
+ }
+ }
+ return TRUE; /* keep enumerating. */
+}
+
+static void
+DSOUND_DetectDevices(void)
+{
+ pDirectSoundCaptureEnumerateW(FindAllDevs, (void *) ((size_t) 1));
+ pDirectSoundEnumerateW(FindAllDevs, (void *) ((size_t) 0));
+}
+
+
+static void
+DSOUND_WaitDevice(_THIS)
+{
+ DWORD status = 0;
+ DWORD cursor = 0;
+ DWORD junk = 0;
+ HRESULT result = DS_OK;
+
+ /* Semi-busy wait, since we have no way of getting play notification
+ on a primary mixing buffer located in hardware (DirectX 5.0)
+ */
+ result = IDirectSoundBuffer_GetCurrentPosition(this->hidden->mixbuf,
+ &junk, &cursor);
+ if (result != DS_OK) {
+ if (result == DSERR_BUFFERLOST) {
+ IDirectSoundBuffer_Restore(this->hidden->mixbuf);
+ }
+#ifdef DEBUG_SOUND
+ SetDSerror("DirectSound GetCurrentPosition", result);
+#endif
+ return;
+ }
+
+ while ((cursor / this->spec.size) == this->hidden->lastchunk) {
+ /* FIXME: find out how much time is left and sleep that long */
+ SDL_Delay(1);
+
+ /* Try to restore a lost sound buffer */
+ IDirectSoundBuffer_GetStatus(this->hidden->mixbuf, &status);
+ if ((status & DSBSTATUS_BUFFERLOST)) {
+ IDirectSoundBuffer_Restore(this->hidden->mixbuf);
+ IDirectSoundBuffer_GetStatus(this->hidden->mixbuf, &status);
+ if ((status & DSBSTATUS_BUFFERLOST)) {
+ break;
+ }
+ }
+ if (!(status & DSBSTATUS_PLAYING)) {
+ result = IDirectSoundBuffer_Play(this->hidden->mixbuf, 0, 0,
+ DSBPLAY_LOOPING);
+ if (result == DS_OK) {
+ continue;
+ }
+#ifdef DEBUG_SOUND
+ SetDSerror("DirectSound Play", result);
+#endif
+ return;
+ }
+
+ /* Find out where we are playing */
+ result = IDirectSoundBuffer_GetCurrentPosition(this->hidden->mixbuf,
+ &junk, &cursor);
+ if (result != DS_OK) {
+ SetDSerror("DirectSound GetCurrentPosition", result);
+ return;
+ }
+ }
+}
+
+static void
+DSOUND_PlayDevice(_THIS)
+{
+ /* Unlock the buffer, allowing it to play */
+ if (this->hidden->locked_buf) {
+ IDirectSoundBuffer_Unlock(this->hidden->mixbuf,
+ this->hidden->locked_buf,
+ this->spec.size, NULL, 0);
+ }
+}
+
+static Uint8 *
+DSOUND_GetDeviceBuf(_THIS)
+{
+ DWORD cursor = 0;
+ DWORD junk = 0;
+ HRESULT result = DS_OK;
+ DWORD rawlen = 0;
+
+ /* Figure out which blocks to fill next */
+ this->hidden->locked_buf = NULL;
+ result = IDirectSoundBuffer_GetCurrentPosition(this->hidden->mixbuf,
+ &junk, &cursor);
+ if (result == DSERR_BUFFERLOST) {
+ IDirectSoundBuffer_Restore(this->hidden->mixbuf);
+ result = IDirectSoundBuffer_GetCurrentPosition(this->hidden->mixbuf,
+ &junk, &cursor);
+ }
+ if (result != DS_OK) {
+ SetDSerror("DirectSound GetCurrentPosition", result);
+ return (NULL);
+ }
+ cursor /= this->spec.size;
+#ifdef DEBUG_SOUND
+ /* Detect audio dropouts */
+ {
+ DWORD spot = cursor;
+ if (spot < this->hidden->lastchunk) {
+ spot += this->hidden->num_buffers;
+ }
+ if (spot > this->hidden->lastchunk + 1) {
+ fprintf(stderr, "Audio dropout, missed %d fragments\n",
+ (spot - (this->hidden->lastchunk + 1)));
+ }
+ }
+#endif
+ this->hidden->lastchunk = cursor;
+ cursor = (cursor + 1) % this->hidden->num_buffers;
+ cursor *= this->spec.size;
+
+ /* Lock the audio buffer */
+ result = IDirectSoundBuffer_Lock(this->hidden->mixbuf, cursor,
+ this->spec.size,
+ (LPVOID *) & this->hidden->locked_buf,
+ &rawlen, NULL, &junk, 0);
+ if (result == DSERR_BUFFERLOST) {
+ IDirectSoundBuffer_Restore(this->hidden->mixbuf);
+ result = IDirectSoundBuffer_Lock(this->hidden->mixbuf, cursor,
+ this->spec.size,
+ (LPVOID *) & this->
+ hidden->locked_buf, &rawlen, NULL,
+ &junk, 0);
+ }
+ if (result != DS_OK) {
+ SetDSerror("DirectSound Lock", result);
+ return (NULL);
+ }
+ return (this->hidden->locked_buf);
+}
+
+static int
+DSOUND_CaptureFromDevice(_THIS, void *buffer, int buflen)
+{
+ struct SDL_PrivateAudioData *h = this->hidden;
+ DWORD junk, cursor, ptr1len, ptr2len;
+ VOID *ptr1, *ptr2;
+
+ SDL_assert(buflen == this->spec.size);
+
+ while (SDL_TRUE) {
+ if (SDL_AtomicGet(&this->shutdown)) { /* in case the buffer froze... */
+ SDL_memset(buffer, this->spec.silence, buflen);
+ return buflen;
+ }
+
+ if (IDirectSoundCaptureBuffer_GetCurrentPosition(h->capturebuf, &junk, &cursor) != DS_OK) {
+ return -1;
+ }
+ if ((cursor / this->spec.size) == h->lastchunk) {
+ SDL_Delay(1); /* FIXME: find out how much time is left and sleep that long */
+ } else {
+ break;
+ }
+ }
+
+ if (IDirectSoundCaptureBuffer_Lock(h->capturebuf, h->lastchunk * this->spec.size, this->spec.size, &ptr1, &ptr1len, &ptr2, &ptr2len, 0) != DS_OK) {
+ return -1;
+ }
+
+ SDL_assert(ptr1len == this->spec.size);
+ SDL_assert(ptr2 == NULL);
+ SDL_assert(ptr2len == 0);
+
+ SDL_memcpy(buffer, ptr1, ptr1len);
+
+ if (IDirectSoundCaptureBuffer_Unlock(h->capturebuf, ptr1, ptr1len, ptr2, ptr2len) != DS_OK) {
+ return -1;
+ }
+
+ h->lastchunk = (h->lastchunk + 1) % h->num_buffers;
+
+ return ptr1len;
+}
+
+static void
+DSOUND_FlushCapture(_THIS)
+{
+ struct SDL_PrivateAudioData *h = this->hidden;
+ DWORD junk, cursor;
+ if (IDirectSoundCaptureBuffer_GetCurrentPosition(h->capturebuf, &junk, &cursor) == DS_OK) {
+ h->lastchunk = cursor / this->spec.size;
+ }
+}
+
+static void
+DSOUND_CloseDevice(_THIS)
+{
+ if (this->hidden->mixbuf != NULL) {
+ IDirectSoundBuffer_Stop(this->hidden->mixbuf);
+ IDirectSoundBuffer_Release(this->hidden->mixbuf);
+ }
+ if (this->hidden->sound != NULL) {
+ IDirectSound_Release(this->hidden->sound);
+ }
+ if (this->hidden->capturebuf != NULL) {
+ IDirectSoundCaptureBuffer_Stop(this->hidden->capturebuf);
+ IDirectSoundCaptureBuffer_Release(this->hidden->capturebuf);
+ }
+ if (this->hidden->capture != NULL) {
+ IDirectSoundCapture_Release(this->hidden->capture);
+ }
+ SDL_free(this->hidden);
+}
+
+/* This function tries to create a secondary audio buffer, and returns the
+ number of audio chunks available in the created buffer. This is for
+ playback devices, not capture.
+*/
+static int
+CreateSecondary(_THIS, const DWORD bufsize, WAVEFORMATEX *wfmt)
+{
+ LPDIRECTSOUND sndObj = this->hidden->sound;
+ LPDIRECTSOUNDBUFFER *sndbuf = &this->hidden->mixbuf;
+ HRESULT result = DS_OK;
+ DSBUFFERDESC format;
+ LPVOID pvAudioPtr1, pvAudioPtr2;
+ DWORD dwAudioBytes1, dwAudioBytes2;
+
+ /* Try to create the secondary buffer */
+ SDL_zero(format);
+ format.dwSize = sizeof(format);
+ format.dwFlags = DSBCAPS_GETCURRENTPOSITION2;
+ format.dwFlags |= DSBCAPS_GLOBALFOCUS;
+ format.dwBufferBytes = bufsize;
+ format.lpwfxFormat = wfmt;
+ result = IDirectSound_CreateSoundBuffer(sndObj, &format, sndbuf, NULL);
+ if (result != DS_OK) {
+ return SetDSerror("DirectSound CreateSoundBuffer", result);
+ }
+ IDirectSoundBuffer_SetFormat(*sndbuf, wfmt);
+
+ /* Silence the initial audio buffer */
+ result = IDirectSoundBuffer_Lock(*sndbuf, 0, format.dwBufferBytes,
+ (LPVOID *) & pvAudioPtr1, &dwAudioBytes1,
+ (LPVOID *) & pvAudioPtr2, &dwAudioBytes2,
+ DSBLOCK_ENTIREBUFFER);
+ if (result == DS_OK) {
+ SDL_memset(pvAudioPtr1, this->spec.silence, dwAudioBytes1);
+ IDirectSoundBuffer_Unlock(*sndbuf,
+ (LPVOID) pvAudioPtr1, dwAudioBytes1,
+ (LPVOID) pvAudioPtr2, dwAudioBytes2);
+ }
+
+ /* We're ready to go */
+ return 0;
+}
+
+/* This function tries to create a capture buffer, and returns the
+ number of audio chunks available in the created buffer. This is for
+ capture devices, not playback.
+*/
+static int
+CreateCaptureBuffer(_THIS, const DWORD bufsize, WAVEFORMATEX *wfmt)
+{
+ LPDIRECTSOUNDCAPTURE capture = this->hidden->capture;
+ LPDIRECTSOUNDCAPTUREBUFFER *capturebuf = &this->hidden->capturebuf;
+ DSCBUFFERDESC format;
+ HRESULT result;
+
+ SDL_zero(format);
+ format.dwSize = sizeof (format);
+ format.dwFlags = DSCBCAPS_WAVEMAPPED;
+ format.dwBufferBytes = bufsize;
+ format.lpwfxFormat = wfmt;
+
+ result = IDirectSoundCapture_CreateCaptureBuffer(capture, &format, capturebuf, NULL);
+ if (result != DS_OK) {
+ return SetDSerror("DirectSound CreateCaptureBuffer", result);
+ }
+
+ result = IDirectSoundCaptureBuffer_Start(*capturebuf, DSCBSTART_LOOPING);
+ if (result != DS_OK) {
+ IDirectSoundCaptureBuffer_Release(*capturebuf);
+ return SetDSerror("DirectSound Start", result);
+ }
+
+#if 0
+ /* presumably this starts at zero, but just in case... */
+ result = IDirectSoundCaptureBuffer_GetCurrentPosition(*capturebuf, &junk, &cursor);
+ if (result != DS_OK) {
+ IDirectSoundCaptureBuffer_Stop(*capturebuf);
+ IDirectSoundCaptureBuffer_Release(*capturebuf);
+ return SetDSerror("DirectSound GetCurrentPosition", result);
+ }
+
+ this->hidden->lastchunk = cursor / this->spec.size;
+#endif
+
+ return 0;
+}
+
+static int
+DSOUND_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ const DWORD numchunks = 8;
+ HRESULT result;
+ SDL_bool valid_format = SDL_FALSE;
+ SDL_bool tried_format = SDL_FALSE;
+ SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
+ LPGUID guid = (LPGUID) handle;
+ DWORD bufsize;
+
+ /* Initialize all variables that we clean on shutdown */
+ this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc((sizeof *this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(this->hidden);
+
+ /* Open the audio device */
+ if (iscapture) {
+ result = pDirectSoundCaptureCreate8(guid, &this->hidden->capture, NULL);
+ if (result != DS_OK) {
+ return SetDSerror("DirectSoundCaptureCreate8", result);
+ }
+ } else {
+ result = pDirectSoundCreate8(guid, &this->hidden->sound, NULL);
+ if (result != DS_OK) {
+ return SetDSerror("DirectSoundCreate8", result);
+ }
+ result = IDirectSound_SetCooperativeLevel(this->hidden->sound,
+ GetDesktopWindow(),
+ DSSCL_NORMAL);
+ if (result != DS_OK) {
+ return SetDSerror("DirectSound SetCooperativeLevel", result);
+ }
+ }
+
+ while ((!valid_format) && (test_format)) {
+ switch (test_format) {
+ case AUDIO_U8:
+ case AUDIO_S16:
+ case AUDIO_S32:
+ case AUDIO_F32:
+ tried_format = SDL_TRUE;
+
+ this->spec.format = test_format;
+
+ /* Update the fragment size as size in bytes */
+ SDL_CalculateAudioSpec(&this->spec);
+
+ bufsize = numchunks * this->spec.size;
+ if ((bufsize < DSBSIZE_MIN) || (bufsize > DSBSIZE_MAX)) {
+ SDL_SetError("Sound buffer size must be between %d and %d",
+ (int) ((DSBSIZE_MIN < numchunks) ? 1 : DSBSIZE_MIN / numchunks),
+ (int) (DSBSIZE_MAX / numchunks));
+ } else {
+ int rc;
+ WAVEFORMATEX wfmt;
+ SDL_zero(wfmt);
+ if (SDL_AUDIO_ISFLOAT(this->spec.format)) {
+ wfmt.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
+ } else {
+ wfmt.wFormatTag = WAVE_FORMAT_PCM;
+ }
+
+ wfmt.wBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);
+ wfmt.nChannels = this->spec.channels;
+ wfmt.nSamplesPerSec = this->spec.freq;
+ wfmt.nBlockAlign = wfmt.nChannels * (wfmt.wBitsPerSample / 8);
+ wfmt.nAvgBytesPerSec = wfmt.nSamplesPerSec * wfmt.nBlockAlign;
+
+ rc = iscapture ? CreateCaptureBuffer(this, bufsize, &wfmt) : CreateSecondary(this, bufsize, &wfmt);
+ if (rc == 0) {
+ this->hidden->num_buffers = numchunks;
+ valid_format = SDL_TRUE;
+ }
+ }
+ break;
+ }
+ test_format = SDL_NextAudioFormat();
+ }
+
+ if (!valid_format) {
+ if (tried_format) {
+ return -1; /* CreateSecondary() should have called SDL_SetError(). */
+ }
+ return SDL_SetError("DirectSound: Unsupported audio format");
+ }
+
+ /* Playback buffers will auto-start playing in DSOUND_WaitDevice() */
+
+ return 0; /* good to go. */
+}
+
+
+static void
+DSOUND_Deinitialize(void)
+{
+ DSOUND_Unload();
+}
+
+
+static int
+DSOUND_Init(SDL_AudioDriverImpl * impl)
+{
+ if (!DSOUND_Load()) {
+ return 0;
+ }
+
+ /* Set the function pointers */
+ impl->DetectDevices = DSOUND_DetectDevices;
+ impl->OpenDevice = DSOUND_OpenDevice;
+ impl->PlayDevice = DSOUND_PlayDevice;
+ impl->WaitDevice = DSOUND_WaitDevice;
+ impl->GetDeviceBuf = DSOUND_GetDeviceBuf;
+ impl->CaptureFromDevice = DSOUND_CaptureFromDevice;
+ impl->FlushCapture = DSOUND_FlushCapture;
+ impl->CloseDevice = DSOUND_CloseDevice;
+ impl->FreeDeviceHandle = DSOUND_FreeDeviceHandle;
+ impl->Deinitialize = DSOUND_Deinitialize;
+
+ impl->HasCaptureSupport = SDL_TRUE;
+
+ return 1; /* this audio target is available. */
+}
+
+AudioBootStrap DSOUND_bootstrap = {
+ "directsound", "DirectSound", DSOUND_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_DSOUND */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/directsound/SDL_directsound.h b/src/3rdparty/SDL2/src/audio/directsound/SDL_directsound.h
new file mode 100644
index 0000000..acb7b6a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/directsound/SDL_directsound.h
@@ -0,0 +1,47 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_directsound_h_
+#define SDL_directsound_h_
+
+#include "../../core/windows/SDL_directx.h"
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+/* The DirectSound objects */
+struct SDL_PrivateAudioData
+{
+ LPDIRECTSOUND sound;
+ LPDIRECTSOUNDBUFFER mixbuf;
+ LPDIRECTSOUNDCAPTURE capture;
+ LPDIRECTSOUNDCAPTUREBUFFER capturebuf;
+ int num_buffers;
+ DWORD lastchunk;
+ Uint8 *locked_buf;
+};
+
+#endif /* SDL_directsound_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/disk/SDL_diskaudio.c b/src/3rdparty/SDL2/src/audio/disk/SDL_diskaudio.c
new file mode 100644
index 0000000..2250375
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/disk/SDL_diskaudio.c
@@ -0,0 +1,207 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_DISK
+
+/* Output raw audio data to a file. */
+
+#if HAVE_STDIO_H
+#include <stdio.h>
+#endif
+
+#include "SDL_rwops.h"
+#include "SDL_timer.h"
+#include "SDL_audio.h"
+#include "../SDL_audio_c.h"
+#include "SDL_diskaudio.h"
+#include "SDL_log.h"
+
+/* !!! FIXME: these should be SDL hints, not environment variables. */
+/* environment variables and defaults. */
+#define DISKENVR_OUTFILE "SDL_DISKAUDIOFILE"
+#define DISKDEFAULT_OUTFILE "sdlaudio.raw"
+#define DISKENVR_INFILE "SDL_DISKAUDIOFILEIN"
+#define DISKDEFAULT_INFILE "sdlaudio-in.raw"
+#define DISKENVR_IODELAY "SDL_DISKAUDIODELAY"
+
+/* This function waits until it is possible to write a full sound buffer */
+static void
+DISKAUDIO_WaitDevice(_THIS)
+{
+ SDL_Delay(this->hidden->io_delay);
+}
+
+static void
+DISKAUDIO_PlayDevice(_THIS)
+{
+ const size_t written = SDL_RWwrite(this->hidden->io,
+ this->hidden->mixbuf,
+ 1, this->spec.size);
+
+ /* If we couldn't write, assume fatal error for now */
+ if (written != this->spec.size) {
+ SDL_OpenedAudioDeviceDisconnected(this);
+ }
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Wrote %d bytes of audio data\n", written);
+#endif
+}
+
+static Uint8 *
+DISKAUDIO_GetDeviceBuf(_THIS)
+{
+ return (this->hidden->mixbuf);
+}
+
+static int
+DISKAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
+{
+ struct SDL_PrivateAudioData *h = this->hidden;
+ const int origbuflen = buflen;
+
+ SDL_Delay(h->io_delay);
+
+ if (h->io) {
+ const size_t br = SDL_RWread(h->io, buffer, 1, buflen);
+ buflen -= (int) br;
+ buffer = ((Uint8 *) buffer) + br;
+ if (buflen > 0) { /* EOF (or error, but whatever). */
+ SDL_RWclose(h->io);
+ h->io = NULL;
+ }
+ }
+
+ /* if we ran out of file, just write silence. */
+ SDL_memset(buffer, this->spec.silence, buflen);
+
+ return origbuflen;
+}
+
+static void
+DISKAUDIO_FlushCapture(_THIS)
+{
+ /* no op...we don't advance the file pointer or anything. */
+}
+
+
+static void
+DISKAUDIO_CloseDevice(_THIS)
+{
+ if (this->hidden->io != NULL) {
+ SDL_RWclose(this->hidden->io);
+ }
+ SDL_free(this->hidden->mixbuf);
+ SDL_free(this->hidden);
+}
+
+
+static const char *
+get_filename(const int iscapture, const char *devname)
+{
+ if (devname == NULL) {
+ devname = SDL_getenv(iscapture ? DISKENVR_INFILE : DISKENVR_OUTFILE);
+ if (devname == NULL) {
+ devname = iscapture ? DISKDEFAULT_INFILE : DISKDEFAULT_OUTFILE;
+ }
+ }
+ return devname;
+}
+
+static int
+DISKAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ /* handle != NULL means "user specified the placeholder name on the fake detected device list" */
+ const char *fname = get_filename(iscapture, handle ? NULL : devname);
+ const char *envr = SDL_getenv(DISKENVR_IODELAY);
+
+ this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc(sizeof(*this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(this->hidden);
+
+ if (envr != NULL) {
+ this->hidden->io_delay = SDL_atoi(envr);
+ } else {
+ this->hidden->io_delay = ((this->spec.samples * 1000) / this->spec.freq);
+ }
+
+ /* Open the audio device */
+ this->hidden->io = SDL_RWFromFile(fname, iscapture ? "rb" : "wb");
+ if (this->hidden->io == NULL) {
+ return -1;
+ }
+
+ /* Allocate mixing buffer */
+ if (!iscapture) {
+ this->hidden->mixbuf = (Uint8 *) SDL_malloc(this->spec.size);
+ if (this->hidden->mixbuf == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
+ }
+
+ SDL_LogCritical(SDL_LOG_CATEGORY_AUDIO,
+ "You are using the SDL disk i/o audio driver!\n");
+ SDL_LogCritical(SDL_LOG_CATEGORY_AUDIO,
+ " %s file [%s].\n", iscapture ? "Reading from" : "Writing to",
+ fname);
+
+ /* We're ready to rock and roll. :-) */
+ return 0;
+}
+
+static void
+DISKAUDIO_DetectDevices(void)
+{
+ SDL_AddAudioDevice(SDL_FALSE, DEFAULT_OUTPUT_DEVNAME, (void *) 0x1);
+ SDL_AddAudioDevice(SDL_TRUE, DEFAULT_INPUT_DEVNAME, (void *) 0x2);
+}
+
+static int
+DISKAUDIO_Init(SDL_AudioDriverImpl * impl)
+{
+ /* Set the function pointers */
+ impl->OpenDevice = DISKAUDIO_OpenDevice;
+ impl->WaitDevice = DISKAUDIO_WaitDevice;
+ impl->PlayDevice = DISKAUDIO_PlayDevice;
+ impl->GetDeviceBuf = DISKAUDIO_GetDeviceBuf;
+ impl->CaptureFromDevice = DISKAUDIO_CaptureFromDevice;
+ impl->FlushCapture = DISKAUDIO_FlushCapture;
+
+ impl->CloseDevice = DISKAUDIO_CloseDevice;
+ impl->DetectDevices = DISKAUDIO_DetectDevices;
+
+ impl->AllowsArbitraryDeviceNames = 1;
+ impl->HasCaptureSupport = SDL_TRUE;
+
+ return 1; /* this audio target is available. */
+}
+
+AudioBootStrap DISKAUDIO_bootstrap = {
+ "disk", "direct-to-disk audio", DISKAUDIO_Init, 1
+};
+
+#endif /* SDL_AUDIO_DRIVER_DISK */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/disk/SDL_diskaudio.h b/src/3rdparty/SDL2/src/audio/disk/SDL_diskaudio.h
new file mode 100644
index 0000000..7e73ebe
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/disk/SDL_diskaudio.h
@@ -0,0 +1,41 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_diskaudio_h_
+#define SDL_diskaudio_h_
+
+#include "SDL_rwops.h"
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData
+{
+ /* The file descriptor for the audio device */
+ SDL_RWops *io;
+ Uint32 io_delay;
+ Uint8 *mixbuf;
+};
+
+#endif /* SDL_diskaudio_h_ */
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/dsp/SDL_dspaudio.c b/src/3rdparty/SDL2/src/audio/dsp/SDL_dspaudio.c
new file mode 100644
index 0000000..77653be
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/dsp/SDL_dspaudio.c
@@ -0,0 +1,320 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_OSS
+
+/* Allow access to a raw mixing buffer */
+
+#include <stdio.h> /* For perror() */
+#include <string.h> /* For strerror() */
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+
+#if SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H
+/* This is installed on some systems */
+#include <soundcard.h>
+#else
+/* This is recommended by OSS */
+#include <sys/soundcard.h>
+#endif
+
+#include "SDL_timer.h"
+#include "SDL_audio.h"
+#include "../SDL_audio_c.h"
+#include "../SDL_audiodev_c.h"
+#include "SDL_dspaudio.h"
+
+
+static void
+DSP_DetectDevices(void)
+{
+ SDL_EnumUnixAudioDevices(0, NULL);
+}
+
+
+static void
+DSP_CloseDevice(_THIS)
+{
+ if (this->hidden->audio_fd >= 0) {
+ close(this->hidden->audio_fd);
+ }
+ SDL_free(this->hidden->mixbuf);
+ SDL_free(this->hidden);
+}
+
+
+static int
+DSP_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
+ int format;
+ int value;
+ int frag_spec;
+ SDL_AudioFormat test_format;
+
+ /* We don't care what the devname is...we'll try to open anything. */
+ /* ...but default to first name in the list... */
+ if (devname == NULL) {
+ devname = SDL_GetAudioDeviceName(0, iscapture);
+ if (devname == NULL) {
+ return SDL_SetError("No such audio device");
+ }
+ }
+
+ /* Make sure fragment size stays a power of 2, or OSS fails. */
+ /* I don't know which of these are actually legal values, though... */
+ if (this->spec.channels > 8)
+ this->spec.channels = 8;
+ else if (this->spec.channels > 4)
+ this->spec.channels = 4;
+ else if (this->spec.channels > 2)
+ this->spec.channels = 2;
+
+ /* Initialize all variables that we clean on shutdown */
+ this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc((sizeof *this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(this->hidden);
+
+ /* Open the audio device */
+ this->hidden->audio_fd = open(devname, flags, 0);
+ if (this->hidden->audio_fd < 0) {
+ return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
+ }
+
+ /* Make the file descriptor use blocking i/o with fcntl() */
+ {
+ long ctlflags;
+ ctlflags = fcntl(this->hidden->audio_fd, F_GETFL);
+ ctlflags &= ~O_NONBLOCK;
+ if (fcntl(this->hidden->audio_fd, F_SETFL, ctlflags) < 0) {
+ return SDL_SetError("Couldn't set audio blocking mode");
+ }
+ }
+
+ /* Get a list of supported hardware formats */
+ if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) {
+ perror("SNDCTL_DSP_GETFMTS");
+ return SDL_SetError("Couldn't get audio format list");
+ }
+
+ /* Try for a closest match on audio format */
+ format = 0;
+ for (test_format = SDL_FirstAudioFormat(this->spec.format);
+ !format && test_format;) {
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
+#endif
+ switch (test_format) {
+ case AUDIO_U8:
+ if (value & AFMT_U8) {
+ format = AFMT_U8;
+ }
+ break;
+ case AUDIO_S16LSB:
+ if (value & AFMT_S16_LE) {
+ format = AFMT_S16_LE;
+ }
+ break;
+ case AUDIO_S16MSB:
+ if (value & AFMT_S16_BE) {
+ format = AFMT_S16_BE;
+ }
+ break;
+#if 0
+/*
+ * These formats are not used by any real life systems so they are not
+ * needed here.
+ */
+ case AUDIO_S8:
+ if (value & AFMT_S8) {
+ format = AFMT_S8;
+ }
+ break;
+ case AUDIO_U16LSB:
+ if (value & AFMT_U16_LE) {
+ format = AFMT_U16_LE;
+ }
+ break;
+ case AUDIO_U16MSB:
+ if (value & AFMT_U16_BE) {
+ format = AFMT_U16_BE;
+ }
+ break;
+#endif
+ default:
+ format = 0;
+ break;
+ }
+ if (!format) {
+ test_format = SDL_NextAudioFormat();
+ }
+ }
+ if (format == 0) {
+ return SDL_SetError("Couldn't find any hardware audio formats");
+ }
+ this->spec.format = test_format;
+
+ /* Set the audio format */
+ value = format;
+ if ((ioctl(this->hidden->audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) ||
+ (value != format)) {
+ perror("SNDCTL_DSP_SETFMT");
+ return SDL_SetError("Couldn't set audio format");
+ }
+
+ /* Set the number of channels of output */
+ value = this->spec.channels;
+ if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0) {
+ perror("SNDCTL_DSP_CHANNELS");
+ return SDL_SetError("Cannot set the number of channels");
+ }
+ this->spec.channels = value;
+
+ /* Set the DSP frequency */
+ value = this->spec.freq;
+ if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_SPEED, &value) < 0) {
+ perror("SNDCTL_DSP_SPEED");
+ return SDL_SetError("Couldn't set audio frequency");
+ }
+ this->spec.freq = value;
+
+ /* Calculate the final parameters for this audio specification */
+ SDL_CalculateAudioSpec(&this->spec);
+
+ /* Determine the power of two of the fragment size */
+ for (frag_spec = 0; (0x01U << frag_spec) < this->spec.size; ++frag_spec);
+ if ((0x01U << frag_spec) != this->spec.size) {
+ return SDL_SetError("Fragment size must be a power of two");
+ }
+ frag_spec |= 0x00020000; /* two fragments, for low latency */
+
+ /* Set the audio buffering parameters */
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Requesting %d fragments of size %d\n",
+ (frag_spec >> 16), 1 << (frag_spec & 0xFFFF));
+#endif
+ if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag_spec) < 0) {
+ perror("SNDCTL_DSP_SETFRAGMENT");
+ }
+#ifdef DEBUG_AUDIO
+ {
+ audio_buf_info info;
+ ioctl(this->hidden->audio_fd, SNDCTL_DSP_GETOSPACE, &info);
+ fprintf(stderr, "fragments = %d\n", info.fragments);
+ fprintf(stderr, "fragstotal = %d\n", info.fragstotal);
+ fprintf(stderr, "fragsize = %d\n", info.fragsize);
+ fprintf(stderr, "bytes = %d\n", info.bytes);
+ }
+#endif
+
+ /* Allocate mixing buffer */
+ if (!iscapture) {
+ this->hidden->mixlen = this->spec.size;
+ this->hidden->mixbuf = (Uint8 *) SDL_malloc(this->hidden->mixlen);
+ if (this->hidden->mixbuf == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
+ }
+
+ /* We're ready to rock and roll. :-) */
+ return 0;
+}
+
+
+static void
+DSP_PlayDevice(_THIS)
+{
+ struct SDL_PrivateAudioData *h = this->hidden;
+ if (write(h->audio_fd, h->mixbuf, h->mixlen) == -1) {
+ perror("Audio write");
+ SDL_OpenedAudioDeviceDisconnected(this);
+ }
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Wrote %d bytes of audio data\n", h->mixlen);
+#endif
+}
+
+static Uint8 *
+DSP_GetDeviceBuf(_THIS)
+{
+ return (this->hidden->mixbuf);
+}
+
+static int
+DSP_CaptureFromDevice(_THIS, void *buffer, int buflen)
+{
+ return (int) read(this->hidden->audio_fd, buffer, buflen);
+}
+
+static void
+DSP_FlushCapture(_THIS)
+{
+ struct SDL_PrivateAudioData *h = this->hidden;
+ audio_buf_info info;
+ if (ioctl(h->audio_fd, SNDCTL_DSP_GETISPACE, &info) == 0) {
+ while (info.bytes > 0) {
+ char buf[512];
+ const size_t len = SDL_min(sizeof (buf), info.bytes);
+ const ssize_t br = read(h->audio_fd, buf, len);
+ if (br <= 0) {
+ break;
+ }
+ info.bytes -= br;
+ }
+ }
+}
+
+static int
+DSP_Init(SDL_AudioDriverImpl * impl)
+{
+ /* Set the function pointers */
+ impl->DetectDevices = DSP_DetectDevices;
+ impl->OpenDevice = DSP_OpenDevice;
+ impl->PlayDevice = DSP_PlayDevice;
+ impl->GetDeviceBuf = DSP_GetDeviceBuf;
+ impl->CloseDevice = DSP_CloseDevice;
+ impl->CaptureFromDevice = DSP_CaptureFromDevice;
+ impl->FlushCapture = DSP_FlushCapture;
+
+ impl->AllowsArbitraryDeviceNames = 1;
+ impl->HasCaptureSupport = SDL_TRUE;
+
+ return 1; /* this audio target is available. */
+}
+
+
+AudioBootStrap DSP_bootstrap = {
+ "dsp", "OSS /dev/dsp standard audio", DSP_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_OSS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/dsp/SDL_dspaudio.h b/src/3rdparty/SDL2/src/audio/dsp/SDL_dspaudio.h
new file mode 100644
index 0000000..6bd86d7
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/dsp/SDL_dspaudio.h
@@ -0,0 +1,43 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_dspaudio_h_
+#define SDL_dspaudio_h_
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData
+{
+ /* The file descriptor for the audio device */
+ int audio_fd;
+
+ /* Raw mixing buffer */
+ Uint8 *mixbuf;
+ int mixlen;
+};
+#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
+
+#endif /* SDL_dspaudio_h_ */
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/dummy/SDL_dummyaudio.c b/src/3rdparty/SDL2/src/audio/dummy/SDL_dummyaudio.c
new file mode 100644
index 0000000..f91dea3
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/dummy/SDL_dummyaudio.c
@@ -0,0 +1,65 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+/* Output audio to nowhere... */
+
+#include "SDL_timer.h"
+#include "SDL_audio.h"
+#include "../SDL_audio_c.h"
+#include "SDL_dummyaudio.h"
+
+static int
+DUMMYAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ return 0; /* always succeeds. */
+}
+
+static int
+DUMMYAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
+{
+ /* Delay to make this sort of simulate real audio input. */
+ SDL_Delay((this->spec.samples * 1000) / this->spec.freq);
+
+ /* always return a full buffer of silence. */
+ SDL_memset(buffer, this->spec.silence, buflen);
+ return buflen;
+}
+
+static int
+DUMMYAUDIO_Init(SDL_AudioDriverImpl * impl)
+{
+ /* Set the function pointers */
+ impl->OpenDevice = DUMMYAUDIO_OpenDevice;
+ impl->CaptureFromDevice = DUMMYAUDIO_CaptureFromDevice;
+
+ impl->OnlyHasDefaultOutputDevice = 1;
+ impl->OnlyHasDefaultCaptureDevice = 1;
+ impl->HasCaptureSupport = SDL_TRUE;
+
+ return 1; /* this audio target is available. */
+}
+
+AudioBootStrap DUMMYAUDIO_bootstrap = {
+ "dummy", "SDL dummy audio driver", DUMMYAUDIO_Init, 1
+};
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/dummy/SDL_dummyaudio.h b/src/3rdparty/SDL2/src/audio/dummy/SDL_dummyaudio.h
new file mode 100644
index 0000000..18241ee
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/dummy/SDL_dummyaudio.h
@@ -0,0 +1,41 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_dummyaudio_h_
+#define SDL_dummyaudio_h_
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData
+{
+ /* The file descriptor for the audio device */
+ Uint8 *mixbuf;
+ Uint32 mixlen;
+ Uint32 write_delay;
+ Uint32 initial_calls;
+};
+
+#endif /* SDL_dummyaudio_h_ */
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/emscripten/SDL_emscriptenaudio.c b/src/3rdparty/SDL2/src/audio/emscripten/SDL_emscriptenaudio.c
new file mode 100644
index 0000000..e519f08
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/emscripten/SDL_emscriptenaudio.c
@@ -0,0 +1,379 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_EMSCRIPTEN
+
+#include "SDL_audio.h"
+#include "SDL_log.h"
+#include "../SDL_audio_c.h"
+#include "SDL_emscriptenaudio.h"
+#include "SDL_assert.h"
+
+#include <emscripten/emscripten.h>
+
+static void
+FeedAudioDevice(_THIS, const void *buf, const int buflen)
+{
+ const int framelen = (SDL_AUDIO_BITSIZE(this->spec.format) / 8) * this->spec.channels;
+ EM_ASM_ARGS({
+ var numChannels = SDL2.audio.currentOutputBuffer['numberOfChannels'];
+ for (var c = 0; c < numChannels; ++c) {
+ var channelData = SDL2.audio.currentOutputBuffer['getChannelData'](c);
+ if (channelData.length != $1) {
+ throw 'Web Audio output buffer length mismatch! Destination size: ' + channelData.length + ' samples vs expected ' + $1 + ' samples!';
+ }
+
+ for (var j = 0; j < $1; ++j) {
+ channelData[j] = HEAPF32[$0 + ((j*numChannels + c) << 2) >> 2]; /* !!! FIXME: why are these shifts here? */
+ }
+ }
+ }, buf, buflen / framelen);
+}
+
+static void
+HandleAudioProcess(_THIS)
+{
+ SDL_AudioCallback callback = this->callbackspec.callback;
+ const int stream_len = this->callbackspec.size;
+
+ /* Only do something if audio is enabled */
+ if (!SDL_AtomicGet(&this->enabled) || SDL_AtomicGet(&this->paused)) {
+ if (this->stream) {
+ SDL_AudioStreamClear(this->stream);
+ }
+ return;
+ }
+
+ if (this->stream == NULL) { /* no conversion necessary. */
+ SDL_assert(this->spec.size == stream_len);
+ callback(this->callbackspec.userdata, this->work_buffer, stream_len);
+ } else { /* streaming/converting */
+ int got;
+ while (SDL_AudioStreamAvailable(this->stream) < ((int) this->spec.size)) {
+ callback(this->callbackspec.userdata, this->work_buffer, stream_len);
+ if (SDL_AudioStreamPut(this->stream, this->work_buffer, stream_len) == -1) {
+ SDL_AudioStreamClear(this->stream);
+ SDL_AtomicSet(&this->enabled, 0);
+ break;
+ }
+ }
+
+ got = SDL_AudioStreamGet(this->stream, this->work_buffer, this->spec.size);
+ SDL_assert((got < 0) || (got == this->spec.size));
+ if (got != this->spec.size) {
+ SDL_memset(this->work_buffer, this->spec.silence, this->spec.size);
+ }
+ }
+
+ FeedAudioDevice(this, this->work_buffer, this->spec.size);
+}
+
+static void
+HandleCaptureProcess(_THIS)
+{
+ SDL_AudioCallback callback = this->callbackspec.callback;
+ const int stream_len = this->callbackspec.size;
+
+ /* Only do something if audio is enabled */
+ if (!SDL_AtomicGet(&this->enabled) || SDL_AtomicGet(&this->paused)) {
+ SDL_AudioStreamClear(this->stream);
+ return;
+ }
+
+ EM_ASM_ARGS({
+ var numChannels = SDL2.capture.currentCaptureBuffer.numberOfChannels;
+ for (var c = 0; c < numChannels; ++c) {
+ var channelData = SDL2.capture.currentCaptureBuffer.getChannelData(c);
+ if (channelData.length != $1) {
+ throw 'Web Audio capture buffer length mismatch! Destination size: ' + channelData.length + ' samples vs expected ' + $1 + ' samples!';
+ }
+
+ if (numChannels == 1) { /* fastpath this a little for the common (mono) case. */
+ for (var j = 0; j < $1; ++j) {
+ setValue($0 + (j * 4), channelData[j], 'float');
+ }
+ } else {
+ for (var j = 0; j < $1; ++j) {
+ setValue($0 + (((j * numChannels) + c) * 4), channelData[j], 'float');
+ }
+ }
+ }
+ }, this->work_buffer, (this->spec.size / sizeof (float)) / this->spec.channels);
+
+ /* okay, we've got an interleaved float32 array in C now. */
+
+ if (this->stream == NULL) { /* no conversion necessary. */
+ SDL_assert(this->spec.size == stream_len);
+ callback(this->callbackspec.userdata, this->work_buffer, stream_len);
+ } else { /* streaming/converting */
+ if (SDL_AudioStreamPut(this->stream, this->work_buffer, this->spec.size) == -1) {
+ SDL_AtomicSet(&this->enabled, 0);
+ }
+
+ while (SDL_AudioStreamAvailable(this->stream) >= stream_len) {
+ const int got = SDL_AudioStreamGet(this->stream, this->work_buffer, stream_len);
+ SDL_assert((got < 0) || (got == stream_len));
+ if (got != stream_len) {
+ SDL_memset(this->work_buffer, this->callbackspec.silence, stream_len);
+ }
+ callback(this->callbackspec.userdata, this->work_buffer, stream_len); /* Send it to the app. */
+ }
+ }
+}
+
+
+static void
+EMSCRIPTENAUDIO_CloseDevice(_THIS)
+{
+ EM_ASM_({
+ if ($0) {
+ if (SDL2.capture.silenceTimer !== undefined) {
+ clearTimeout(SDL2.capture.silenceTimer);
+ }
+ if (SDL2.capture.stream !== undefined) {
+ var tracks = SDL2.capture.stream.getAudioTracks();
+ for (var i = 0; i < tracks.length; i++) {
+ SDL2.capture.stream.removeTrack(tracks[i]);
+ }
+ SDL2.capture.stream = undefined;
+ }
+ if (SDL2.capture.scriptProcessorNode !== undefined) {
+ SDL2.capture.scriptProcessorNode.onaudioprocess = function(audioProcessingEvent) {};
+ SDL2.capture.scriptProcessorNode.disconnect();
+ SDL2.capture.scriptProcessorNode = undefined;
+ }
+ if (SDL2.capture.mediaStreamNode !== undefined) {
+ SDL2.capture.mediaStreamNode.disconnect();
+ SDL2.capture.mediaStreamNode = undefined;
+ }
+ if (SDL2.capture.silenceBuffer !== undefined) {
+ SDL2.capture.silenceBuffer = undefined
+ }
+ SDL2.capture = undefined;
+ } else {
+ if (SDL2.audio.scriptProcessorNode != undefined) {
+ SDL2.audio.scriptProcessorNode.disconnect();
+ SDL2.audio.scriptProcessorNode = undefined;
+ }
+ SDL2.audio = undefined;
+ }
+ if ((SDL2.audioContext !== undefined) && (SDL2.audio === undefined) && (SDL2.capture === undefined)) {
+ SDL2.audioContext.close();
+ SDL2.audioContext = undefined;
+ }
+ }, this->iscapture);
+
+#if 0 /* !!! FIXME: currently not used. Can we move some stuff off the SDL2 namespace? --ryan. */
+ SDL_free(this->hidden);
+#endif
+}
+
+static int
+EMSCRIPTENAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ SDL_bool valid_format = SDL_FALSE;
+ SDL_AudioFormat test_format;
+ int result;
+
+ /* based on parts of library_sdl.js */
+
+ /* create context (TODO: this puts stuff in the global namespace...)*/
+ result = EM_ASM_INT({
+ if(typeof(SDL2) === 'undefined') {
+ SDL2 = {};
+ }
+ if (!$0) {
+ SDL2.audio = {};
+ } else {
+ SDL2.capture = {};
+ }
+
+ if (!SDL2.audioContext) {
+ if (typeof(AudioContext) !== 'undefined') {
+ SDL2.audioContext = new AudioContext();
+ } else if (typeof(webkitAudioContext) !== 'undefined') {
+ SDL2.audioContext = new webkitAudioContext();
+ }
+ }
+ return SDL2.audioContext === undefined ? -1 : 0;
+ }, iscapture);
+ if (result < 0) {
+ return SDL_SetError("Web Audio API is not available!");
+ }
+
+ test_format = SDL_FirstAudioFormat(this->spec.format);
+ while ((!valid_format) && (test_format)) {
+ switch (test_format) {
+ case AUDIO_F32: /* web audio only supports floats */
+ this->spec.format = test_format;
+
+ valid_format = SDL_TRUE;
+ break;
+ }
+ test_format = SDL_NextAudioFormat();
+ }
+
+ if (!valid_format) {
+ /* Didn't find a compatible format :( */
+ return SDL_SetError("No compatible audio format!");
+ }
+
+ /* Initialize all variables that we clean on shutdown */
+#if 0 /* !!! FIXME: currently not used. Can we move some stuff off the SDL2 namespace? --ryan. */
+ this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc((sizeof *this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(this->hidden);
+#endif
+
+ /* limit to native freq */
+ this->spec.freq = EM_ASM_INT_V({ return SDL2.audioContext.sampleRate; });
+
+ SDL_CalculateAudioSpec(&this->spec);
+
+ if (iscapture) {
+ /* The idea is to take the capture media stream, hook it up to an
+ audio graph where we can pass it through a ScriptProcessorNode
+ to access the raw PCM samples and push them to the SDL app's
+ callback. From there, we "process" the audio data into silence
+ and forget about it. */
+
+ /* This should, strictly speaking, use MediaRecorder for capture, but
+ this API is cleaner to use and better supported, and fires a
+ callback whenever there's enough data to fire down into the app.
+ The downside is that we are spending CPU time silencing a buffer
+ that the audiocontext uselessly mixes into any output. On the
+ upside, both of those things are not only run in native code in
+ the browser, they're probably SIMD code, too. MediaRecorder
+ feels like it's a pretty inefficient tapdance in similar ways,
+ to be honest. */
+
+ EM_ASM_({
+ var have_microphone = function(stream) {
+ //console.log('SDL audio capture: we have a microphone! Replacing silence callback.');
+ if (SDL2.capture.silenceTimer !== undefined) {
+ clearTimeout(SDL2.capture.silenceTimer);
+ SDL2.capture.silenceTimer = undefined;
+ }
+ SDL2.capture.mediaStreamNode = SDL2.audioContext.createMediaStreamSource(stream);
+ SDL2.capture.scriptProcessorNode = SDL2.audioContext.createScriptProcessor($1, $0, 1);
+ SDL2.capture.scriptProcessorNode.onaudioprocess = function(audioProcessingEvent) {
+ if ((SDL2 === undefined) || (SDL2.capture === undefined)) { return; }
+ audioProcessingEvent.outputBuffer.getChannelData(0).fill(0.0);
+ SDL2.capture.currentCaptureBuffer = audioProcessingEvent.inputBuffer;
+ Runtime.dynCall('vi', $2, [$3]);
+ };
+ SDL2.capture.mediaStreamNode.connect(SDL2.capture.scriptProcessorNode);
+ SDL2.capture.scriptProcessorNode.connect(SDL2.audioContext.destination);
+ SDL2.capture.stream = stream;
+ };
+
+ var no_microphone = function(error) {
+ //console.log('SDL audio capture: we DO NOT have a microphone! (' + error.name + ')...leaving silence callback running.');
+ };
+
+ /* we write silence to the audio callback until the microphone is available (user approves use, etc). */
+ SDL2.capture.silenceBuffer = SDL2.audioContext.createBuffer($0, $1, SDL2.audioContext.sampleRate);
+ SDL2.capture.silenceBuffer.getChannelData(0).fill(0.0);
+ var silence_callback = function() {
+ SDL2.capture.currentCaptureBuffer = SDL2.capture.silenceBuffer;
+ Runtime.dynCall('vi', $2, [$3]);
+ };
+
+ SDL2.capture.silenceTimer = setTimeout(silence_callback, ($1 / SDL2.audioContext.sampleRate) * 1000);
+
+ if ((navigator.mediaDevices !== undefined) && (navigator.mediaDevices.getUserMedia !== undefined)) {
+ navigator.mediaDevices.getUserMedia({ audio: true, video: false }).then(have_microphone).catch(no_microphone);
+ } else if (navigator.webkitGetUserMedia !== undefined) {
+ navigator.webkitGetUserMedia({ audio: true, video: false }, have_microphone, no_microphone);
+ }
+ }, this->spec.channels, this->spec.samples, HandleCaptureProcess, this);
+ } else {
+ /* setup a ScriptProcessorNode */
+ EM_ASM_ARGS({
+ SDL2.audio.scriptProcessorNode = SDL2.audioContext['createScriptProcessor']($1, 0, $0);
+ SDL2.audio.scriptProcessorNode['onaudioprocess'] = function (e) {
+ if ((SDL2 === undefined) || (SDL2.audio === undefined)) { return; }
+ SDL2.audio.currentOutputBuffer = e['outputBuffer'];
+ Runtime.dynCall('vi', $2, [$3]);
+ };
+ SDL2.audio.scriptProcessorNode['connect'](SDL2.audioContext['destination']);
+ }, this->spec.channels, this->spec.samples, HandleAudioProcess, this);
+ }
+
+ return 0;
+}
+
+static int
+EMSCRIPTENAUDIO_Init(SDL_AudioDriverImpl * impl)
+{
+ int available;
+ int capture_available;
+
+ /* Set the function pointers */
+ impl->OpenDevice = EMSCRIPTENAUDIO_OpenDevice;
+ impl->CloseDevice = EMSCRIPTENAUDIO_CloseDevice;
+
+ impl->OnlyHasDefaultOutputDevice = 1;
+
+ /* no threads here */
+ impl->SkipMixerLock = 1;
+ impl->ProvidesOwnCallbackThread = 1;
+
+ /* check availability */
+ available = EM_ASM_INT_V({
+ if (typeof(AudioContext) !== 'undefined') {
+ return 1;
+ } else if (typeof(webkitAudioContext) !== 'undefined') {
+ return 1;
+ }
+ return 0;
+ });
+
+ if (!available) {
+ SDL_SetError("No audio context available");
+ }
+
+ capture_available = available && EM_ASM_INT_V({
+ if ((typeof(navigator.mediaDevices) !== 'undefined') && (typeof(navigator.mediaDevices.getUserMedia) !== 'undefined')) {
+ return 1;
+ } else if (typeof(navigator.webkitGetUserMedia) !== 'undefined') {
+ return 1;
+ }
+ return 0;
+ });
+
+ impl->HasCaptureSupport = capture_available ? SDL_TRUE : SDL_FALSE;
+ impl->OnlyHasDefaultCaptureDevice = capture_available ? SDL_TRUE : SDL_FALSE;
+
+ return available;
+}
+
+AudioBootStrap EMSCRIPTENAUDIO_bootstrap = {
+ "emscripten", "SDL emscripten audio driver", EMSCRIPTENAUDIO_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_EMSCRIPTEN */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/emscripten/SDL_emscriptenaudio.h b/src/3rdparty/SDL2/src/audio/emscripten/SDL_emscriptenaudio.h
new file mode 100644
index 0000000..3c95668
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/emscripten/SDL_emscriptenaudio.h
@@ -0,0 +1,38 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_emscriptenaudio_h_
+#define SDL_emscriptenaudio_h_
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData
+{
+ int unused;
+};
+
+#endif /* SDL_emscriptenaudio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/esd/SDL_esdaudio.c b/src/3rdparty/SDL2/src/audio/esd/SDL_esdaudio.c
new file mode 100644
index 0000000..802ea78
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/esd/SDL_esdaudio.c
@@ -0,0 +1,335 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_ESD
+
+/* Allow access to an ESD network stream mixing buffer */
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <signal.h>
+#include <errno.h>
+#include <esd.h>
+
+#include "SDL_timer.h"
+#include "SDL_audio.h"
+#include "../SDL_audio_c.h"
+#include "SDL_esdaudio.h"
+
+#ifdef SDL_AUDIO_DRIVER_ESD_DYNAMIC
+#include "SDL_name.h"
+#include "SDL_loadso.h"
+#else
+#define SDL_NAME(X) X
+#endif
+
+#ifdef SDL_AUDIO_DRIVER_ESD_DYNAMIC
+
+static const char *esd_library = SDL_AUDIO_DRIVER_ESD_DYNAMIC;
+static void *esd_handle = NULL;
+
+static int (*SDL_NAME(esd_open_sound)) (const char *host);
+static int (*SDL_NAME(esd_close)) (int esd);
+static int (*SDL_NAME(esd_play_stream)) (esd_format_t format, int rate,
+ const char *host, const char *name);
+
+#define SDL_ESD_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) }
+static struct
+{
+ const char *name;
+ void **func;
+} const esd_functions[] = {
+ SDL_ESD_SYM(esd_open_sound),
+ SDL_ESD_SYM(esd_close), SDL_ESD_SYM(esd_play_stream),
+};
+
+#undef SDL_ESD_SYM
+
+static void
+UnloadESDLibrary()
+{
+ if (esd_handle != NULL) {
+ SDL_UnloadObject(esd_handle);
+ esd_handle = NULL;
+ }
+}
+
+static int
+LoadESDLibrary(void)
+{
+ int i, retval = -1;
+
+ if (esd_handle == NULL) {
+ esd_handle = SDL_LoadObject(esd_library);
+ if (esd_handle) {
+ retval = 0;
+ for (i = 0; i < SDL_arraysize(esd_functions); ++i) {
+ *esd_functions[i].func =
+ SDL_LoadFunction(esd_handle, esd_functions[i].name);
+ if (!*esd_functions[i].func) {
+ retval = -1;
+ UnloadESDLibrary();
+ break;
+ }
+ }
+ }
+ }
+ return retval;
+}
+
+#else
+
+static void
+UnloadESDLibrary()
+{
+ return;
+}
+
+static int
+LoadESDLibrary(void)
+{
+ return 0;
+}
+
+#endif /* SDL_AUDIO_DRIVER_ESD_DYNAMIC */
+
+
+/* This function waits until it is possible to write a full sound buffer */
+static void
+ESD_WaitDevice(_THIS)
+{
+ Sint32 ticks;
+
+ /* Check to see if the thread-parent process is still alive */
+ {
+ static int cnt = 0;
+ /* Note that this only works with thread implementations
+ that use a different process id for each thread.
+ */
+ /* Check every 10 loops */
+ if (this->hidden->parent && (((++cnt) % 10) == 0)) {
+ if (kill(this->hidden->parent, 0) < 0 && errno == ESRCH) {
+ SDL_OpenedAudioDeviceDisconnected(this);
+ }
+ }
+ }
+
+ /* Use timer for general audio synchronization */
+ ticks = ((Sint32) (this->hidden->next_frame - SDL_GetTicks())) - FUDGE_TICKS;
+ if (ticks > 0) {
+ SDL_Delay(ticks);
+ }
+}
+
+static void
+ESD_PlayDevice(_THIS)
+{
+ int written = 0;
+
+ /* Write the audio data, checking for EAGAIN on broken audio drivers */
+ do {
+ written = write(this->hidden->audio_fd,
+ this->hidden->mixbuf, this->hidden->mixlen);
+ if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) {
+ SDL_Delay(1); /* Let a little CPU time go by */
+ }
+ } while ((written < 0) &&
+ ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
+
+ /* Set the next write frame */
+ this->hidden->next_frame += this->hidden->frame_ticks;
+
+ /* If we couldn't write, assume fatal error for now */
+ if (written < 0) {
+ SDL_OpenedAudioDeviceDisconnected(this);
+ }
+}
+
+static Uint8 *
+ESD_GetDeviceBuf(_THIS)
+{
+ return (this->hidden->mixbuf);
+}
+
+static void
+ESD_CloseDevice(_THIS)
+{
+ if (this->hidden->audio_fd >= 0) {
+ SDL_NAME(esd_close) (this->hidden->audio_fd);
+ }
+ SDL_free(this->hidden->mixbuf);
+ SDL_free(this->hidden);
+}
+
+/* Try to get the name of the program */
+static char *
+get_progname(void)
+{
+ char *progname = NULL;
+#ifdef __LINUX__
+ FILE *fp;
+ static char temp[BUFSIZ];
+
+ SDL_snprintf(temp, SDL_arraysize(temp), "/proc/%d/cmdline", getpid());
+ fp = fopen(temp, "r");
+ if (fp != NULL) {
+ if (fgets(temp, sizeof(temp) - 1, fp)) {
+ progname = SDL_strrchr(temp, '/');
+ if (progname == NULL) {
+ progname = temp;
+ } else {
+ progname = progname + 1;
+ }
+ }
+ fclose(fp);
+ }
+#endif
+ return (progname);
+}
+
+
+static int
+ESD_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ esd_format_t format = (ESD_STREAM | ESD_PLAY);
+ SDL_AudioFormat test_format = 0;
+ int found = 0;
+
+ /* Initialize all variables that we clean on shutdown */
+ this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc((sizeof *this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(this->hidden);
+ this->hidden->audio_fd = -1;
+
+ /* Convert audio spec to the ESD audio format */
+ /* Try for a closest match on audio format */
+ for (test_format = SDL_FirstAudioFormat(this->spec.format);
+ !found && test_format; test_format = SDL_NextAudioFormat()) {
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
+#endif
+ found = 1;
+ switch (test_format) {
+ case AUDIO_U8:
+ format |= ESD_BITS8;
+ break;
+ case AUDIO_S16SYS:
+ format |= ESD_BITS16;
+ break;
+ default:
+ found = 0;
+ break;
+ }
+ }
+
+ if (!found) {
+ return SDL_SetError("Couldn't find any hardware audio formats");
+ }
+
+ if (this->spec.channels == 1) {
+ format |= ESD_MONO;
+ } else {
+ format |= ESD_STEREO;
+ }
+#if 0
+ this->spec.samples = ESD_BUF_SIZE; /* Darn, no way to change this yet */
+#endif
+
+ /* Open a connection to the ESD audio server */
+ this->hidden->audio_fd =
+ SDL_NAME(esd_play_stream) (format, this->spec.freq, NULL,
+ get_progname());
+
+ if (this->hidden->audio_fd < 0) {
+ return SDL_SetError("Couldn't open ESD connection");
+ }
+
+ /* Calculate the final parameters for this audio specification */
+ SDL_CalculateAudioSpec(&this->spec);
+ this->hidden->frame_ticks =
+ (float) (this->spec.samples * 1000) / this->spec.freq;
+ this->hidden->next_frame = SDL_GetTicks() + this->hidden->frame_ticks;
+
+ /* Allocate mixing buffer */
+ this->hidden->mixlen = this->spec.size;
+ this->hidden->mixbuf = (Uint8 *) SDL_malloc(this->hidden->mixlen);
+ if (this->hidden->mixbuf == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
+
+ /* Get the parent process id (we're the parent of the audio thread) */
+ this->hidden->parent = getpid();
+
+ /* We're ready to rock and roll. :-) */
+ return 0;
+}
+
+static void
+ESD_Deinitialize(void)
+{
+ UnloadESDLibrary();
+}
+
+static int
+ESD_Init(SDL_AudioDriverImpl * impl)
+{
+ if (LoadESDLibrary() < 0) {
+ return 0;
+ } else {
+ int connection = 0;
+
+ /* Don't start ESD if it's not running */
+ SDL_setenv("ESD_NO_SPAWN", "1", 0);
+
+ connection = SDL_NAME(esd_open_sound) (NULL);
+ if (connection < 0) {
+ UnloadESDLibrary();
+ SDL_SetError("ESD: esd_open_sound failed (no audio server?)");
+ return 0;
+ }
+ SDL_NAME(esd_close) (connection);
+ }
+
+ /* Set the function pointers */
+ impl->OpenDevice = ESD_OpenDevice;
+ impl->PlayDevice = ESD_PlayDevice;
+ impl->WaitDevice = ESD_WaitDevice;
+ impl->GetDeviceBuf = ESD_GetDeviceBuf;
+ impl->CloseDevice = ESD_CloseDevice;
+ impl->Deinitialize = ESD_Deinitialize;
+ impl->OnlyHasDefaultOutputDevice = 1;
+
+ return 1; /* this audio target is available. */
+}
+
+
+AudioBootStrap ESD_bootstrap = {
+ "esd", "Enlightened Sound Daemon", ESD_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_ESD */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/esd/SDL_esdaudio.h b/src/3rdparty/SDL2/src/audio/esd/SDL_esdaudio.h
new file mode 100644
index 0000000..9b5c25a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/esd/SDL_esdaudio.h
@@ -0,0 +1,51 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_esdaudio_h_
+#define SDL_esdaudio_h_
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData
+{
+ /* The file descriptor for the audio device */
+ int audio_fd;
+
+ /* The parent process id, to detect when application quits */
+ pid_t parent;
+
+ /* Raw mixing buffer */
+ Uint8 *mixbuf;
+ int mixlen;
+
+ /* Support for audio timing using a timer */
+ float frame_ticks;
+ float next_frame;
+};
+#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
+
+#endif /* SDL_esdaudio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/fusionsound/SDL_fsaudio.c b/src/3rdparty/SDL2/src/audio/fusionsound/SDL_fsaudio.c
new file mode 100644
index 0000000..36fa5c5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/fusionsound/SDL_fsaudio.c
@@ -0,0 +1,328 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_FUSIONSOUND
+
+/* !!! FIXME: why is this is SDL_FS_* instead of FUSIONSOUND_*? */
+
+/* Allow access to a raw mixing buffer */
+
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
+#include <unistd.h>
+
+#include "SDL_timer.h"
+#include "SDL_audio.h"
+#include "../SDL_audio_c.h"
+#include "SDL_fsaudio.h"
+
+#include <fusionsound/fusionsound_version.h>
+
+/* #define SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "libfusionsound.so" */
+
+#ifdef SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC
+#include "SDL_name.h"
+#include "SDL_loadso.h"
+#else
+#define SDL_NAME(X) X
+#endif
+
+#if (FUSIONSOUND_MAJOR_VERSION == 1) && (FUSIONSOUND_MINOR_VERSION < 1)
+typedef DFBResult DirectResult;
+#endif
+
+/* Buffers to use - more than 2 gives a lot of latency */
+#define FUSION_BUFFERS (2)
+
+#ifdef SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC
+
+static const char *fs_library = SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC;
+static void *fs_handle = NULL;
+
+static DirectResult (*SDL_NAME(FusionSoundInit)) (int *argc, char *(*argv[]));
+static DirectResult (*SDL_NAME(FusionSoundCreate)) (IFusionSound **
+ ret_interface);
+
+#define SDL_FS_SYM(x) { #x, (void **) (char *) &SDL_NAME(x) }
+static struct
+{
+ const char *name;
+ void **func;
+} fs_functions[] = {
+/* *INDENT-OFF* */
+ SDL_FS_SYM(FusionSoundInit),
+ SDL_FS_SYM(FusionSoundCreate),
+/* *INDENT-ON* */
+};
+
+#undef SDL_FS_SYM
+
+static void
+UnloadFusionSoundLibrary()
+{
+ if (fs_handle != NULL) {
+ SDL_UnloadObject(fs_handle);
+ fs_handle = NULL;
+ }
+}
+
+static int
+LoadFusionSoundLibrary(void)
+{
+ int i, retval = -1;
+
+ if (fs_handle == NULL) {
+ fs_handle = SDL_LoadObject(fs_library);
+ if (fs_handle != NULL) {
+ retval = 0;
+ for (i = 0; i < SDL_arraysize(fs_functions); ++i) {
+ *fs_functions[i].func =
+ SDL_LoadFunction(fs_handle, fs_functions[i].name);
+ if (!*fs_functions[i].func) {
+ retval = -1;
+ UnloadFusionSoundLibrary();
+ break;
+ }
+ }
+ }
+ }
+
+ return retval;
+}
+
+#else
+
+static void
+UnloadFusionSoundLibrary()
+{
+ return;
+}
+
+static int
+LoadFusionSoundLibrary(void)
+{
+ return 0;
+}
+
+#endif /* SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC */
+
+/* This function waits until it is possible to write a full sound buffer */
+static void
+SDL_FS_WaitDevice(_THIS)
+{
+ this->hidden->stream->Wait(this->hidden->stream,
+ this->hidden->mixsamples);
+}
+
+static void
+SDL_FS_PlayDevice(_THIS)
+{
+ DirectResult ret;
+
+ ret = this->hidden->stream->Write(this->hidden->stream,
+ this->hidden->mixbuf,
+ this->hidden->mixsamples);
+ /* If we couldn't write, assume fatal error for now */
+ if (ret) {
+ SDL_OpenedAudioDeviceDisconnected(this);
+ }
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Wrote %d bytes of audio data\n", this->hidden->mixlen);
+#endif
+}
+
+
+static Uint8 *
+SDL_FS_GetDeviceBuf(_THIS)
+{
+ return (this->hidden->mixbuf);
+}
+
+
+static void
+SDL_FS_CloseDevice(_THIS)
+{
+ if (this->hidden->stream) {
+ this->hidden->stream->Release(this->hidden->stream);
+ }
+ if (this->hidden->fs) {
+ this->hidden->fs->Release(this->hidden->fs);
+ }
+ SDL_free(this->hidden->mixbuf);
+ SDL_free(this->hidden);
+}
+
+
+static int
+SDL_FS_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ int bytes;
+ SDL_AudioFormat test_format = 0, format = 0;
+ FSSampleFormat fs_format;
+ FSStreamDescription desc;
+ DirectResult ret;
+
+ /* Initialize all variables that we clean on shutdown */
+ this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc((sizeof *this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(this->hidden);
+
+ /* Try for a closest match on audio format */
+ for (test_format = SDL_FirstAudioFormat(this->spec.format);
+ !format && test_format;) {
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
+#endif
+ switch (test_format) {
+ case AUDIO_U8:
+ fs_format = FSSF_U8;
+ bytes = 1;
+ format = 1;
+ break;
+ case AUDIO_S16SYS:
+ fs_format = FSSF_S16;
+ bytes = 2;
+ format = 1;
+ break;
+ case AUDIO_S32SYS:
+ fs_format = FSSF_S32;
+ bytes = 4;
+ format = 1;
+ break;
+ case AUDIO_F32SYS:
+ fs_format = FSSF_FLOAT;
+ bytes = 4;
+ format = 1;
+ break;
+ default:
+ format = 0;
+ break;
+ }
+ if (!format) {
+ test_format = SDL_NextAudioFormat();
+ }
+ }
+
+ if (format == 0) {
+ return SDL_SetError("Couldn't find any hardware audio formats");
+ }
+ this->spec.format = test_format;
+
+ /* Retrieve the main sound interface. */
+ ret = SDL_NAME(FusionSoundCreate) (&this->hidden->fs);
+ if (ret) {
+ return SDL_SetError("Unable to initialize FusionSound: %d", ret);
+ }
+
+ this->hidden->mixsamples = this->spec.size / bytes / this->spec.channels;
+
+ /* Fill stream description. */
+ desc.flags = FSSDF_SAMPLERATE | FSSDF_BUFFERSIZE |
+ FSSDF_CHANNELS | FSSDF_SAMPLEFORMAT | FSSDF_PREBUFFER;
+ desc.samplerate = this->spec.freq;
+ desc.buffersize = this->spec.size * FUSION_BUFFERS;
+ desc.channels = this->spec.channels;
+ desc.prebuffer = 10;
+ desc.sampleformat = fs_format;
+
+ ret =
+ this->hidden->fs->CreateStream(this->hidden->fs, &desc,
+ &this->hidden->stream);
+ if (ret) {
+ return SDL_SetError("Unable to create FusionSoundStream: %d", ret);
+ }
+
+ /* See what we got */
+ desc.flags = FSSDF_SAMPLERATE | FSSDF_BUFFERSIZE |
+ FSSDF_CHANNELS | FSSDF_SAMPLEFORMAT;
+ ret = this->hidden->stream->GetDescription(this->hidden->stream, &desc);
+
+ this->spec.freq = desc.samplerate;
+ this->spec.size =
+ desc.buffersize / FUSION_BUFFERS * bytes * desc.channels;
+ this->spec.channels = desc.channels;
+
+ /* Calculate the final parameters for this audio specification */
+ SDL_CalculateAudioSpec(&this->spec);
+
+ /* Allocate mixing buffer */
+ this->hidden->mixlen = this->spec.size;
+ this->hidden->mixbuf = (Uint8 *) SDL_malloc(this->hidden->mixlen);
+ if (this->hidden->mixbuf == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
+
+ /* We're ready to rock and roll. :-) */
+ return 0;
+}
+
+
+static void
+SDL_FS_Deinitialize(void)
+{
+ UnloadFusionSoundLibrary();
+}
+
+
+static int
+SDL_FS_Init(SDL_AudioDriverImpl * impl)
+{
+ if (LoadFusionSoundLibrary() < 0) {
+ return 0;
+ } else {
+ DirectResult ret;
+
+ ret = SDL_NAME(FusionSoundInit) (NULL, NULL);
+ if (ret) {
+ UnloadFusionSoundLibrary();
+ SDL_SetError
+ ("FusionSound: SDL_FS_init failed (FusionSoundInit: %d)",
+ ret);
+ return 0;
+ }
+ }
+
+ /* Set the function pointers */
+ impl->OpenDevice = SDL_FS_OpenDevice;
+ impl->PlayDevice = SDL_FS_PlayDevice;
+ impl->WaitDevice = SDL_FS_WaitDevice;
+ impl->GetDeviceBuf = SDL_FS_GetDeviceBuf;
+ impl->CloseDevice = SDL_FS_CloseDevice;
+ impl->Deinitialize = SDL_FS_Deinitialize;
+ impl->OnlyHasDefaultOutputDevice = 1;
+
+ return 1; /* this audio target is available. */
+}
+
+
+AudioBootStrap FUSIONSOUND_bootstrap = {
+ "fusionsound", "FusionSound", SDL_FS_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_FUSIONSOUND */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/fusionsound/SDL_fsaudio.h b/src/3rdparty/SDL2/src/audio/fusionsound/SDL_fsaudio.h
new file mode 100644
index 0000000..27e45ce
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/fusionsound/SDL_fsaudio.h
@@ -0,0 +1,50 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_fsaudio_h_
+#define SDL_fsaudio_h_
+
+#include <fusionsound/fusionsound.h>
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData
+{
+ /* Interface */
+ IFusionSound *fs;
+
+ /* The stream interface for the audio device */
+ IFusionSoundStream *stream;
+
+ /* Raw mixing buffer */
+ Uint8 *mixbuf;
+ int mixlen;
+ int mixsamples;
+
+};
+
+#endif /* SDL_fsaudio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/haiku/SDL_haikuaudio.cc b/src/3rdparty/SDL2/src/audio/haiku/SDL_haikuaudio.cc
new file mode 100644
index 0000000..52946a5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/haiku/SDL_haikuaudio.cc
@@ -0,0 +1,248 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_HAIKU
+
+/* Allow access to the audio stream on Haiku */
+
+#include <SoundPlayer.h>
+#include <signal.h>
+
+#include "../../main/haiku/SDL_BeApp.h"
+
+extern "C"
+{
+
+#include "SDL_audio.h"
+#include "../SDL_audio_c.h"
+#include "../SDL_sysaudio.h"
+#include "SDL_haikuaudio.h"
+#include "SDL_assert.h"
+
+}
+
+
+/* !!! FIXME: have the callback call the higher level to avoid code dupe. */
+/* The Haiku callback for handling the audio buffer */
+static void
+FillSound(void *device, void *stream, size_t len,
+ const media_raw_audio_format & format)
+{
+ SDL_AudioDevice *audio = (SDL_AudioDevice *) device;
+ SDL_AudioCallback callback = audio->callbackspec.callback;
+
+ /* Only do something if audio is enabled */
+ if (!SDL_AtomicGet(&audio->enabled) || SDL_AtomicGet(&audio->paused)) {
+ if (audio->stream) {
+ SDL_AudioStreamClear(audio->stream);
+ }
+ SDL_memset(stream, audio->spec.silence, len);
+ return;
+ }
+
+ SDL_assert(audio->spec.size == len);
+
+ if (audio->stream == NULL) { /* no conversion necessary. */
+ SDL_LockMutex(audio->mixer_lock);
+ callback(audio->callbackspec.userdata, (Uint8 *) stream, len);
+ SDL_UnlockMutex(audio->mixer_lock);
+ } else { /* streaming/converting */
+ const int stream_len = audio->callbackspec.size;
+ const int ilen = (int) len;
+ while (SDL_AudioStreamAvailable(audio->stream) < ilen) {
+ callback(audio->callbackspec.userdata, audio->work_buffer, stream_len);
+ if (SDL_AudioStreamPut(audio->stream, audio->work_buffer, stream_len) == -1) {
+ SDL_AudioStreamClear(audio->stream);
+ SDL_AtomicSet(&audio->enabled, 0);
+ break;
+ }
+ }
+
+ const int got = SDL_AudioStreamGet(audio->stream, stream, ilen);
+ SDL_assert((got < 0) || (got == ilen));
+ if (got != ilen) {
+ SDL_memset(stream, audio->spec.silence, len);
+ }
+ }
+}
+
+static void
+HAIKUAUDIO_CloseDevice(_THIS)
+{
+ if (_this->hidden->audio_obj) {
+ _this->hidden->audio_obj->Stop();
+ delete _this->hidden->audio_obj;
+ }
+ delete _this->hidden;
+}
+
+
+static const int sig_list[] = {
+ SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0
+};
+
+static inline void
+MaskSignals(sigset_t * omask)
+{
+ sigset_t mask;
+ int i;
+
+ sigemptyset(&mask);
+ for (i = 0; sig_list[i]; ++i) {
+ sigaddset(&mask, sig_list[i]);
+ }
+ sigprocmask(SIG_BLOCK, &mask, omask);
+}
+
+static inline void
+UnmaskSignals(sigset_t * omask)
+{
+ sigprocmask(SIG_SETMASK, omask, NULL);
+}
+
+
+static int
+HAIKUAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ int valid_datatype = 0;
+ media_raw_audio_format format;
+ SDL_AudioFormat test_format = SDL_FirstAudioFormat(_this->spec.format);
+
+ /* Initialize all variables that we clean on shutdown */
+ _this->hidden = new SDL_PrivateAudioData;
+ if (_this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(_this->hidden);
+
+ /* Parse the audio format and fill the Be raw audio format */
+ SDL_zero(format);
+ format.byte_order = B_MEDIA_LITTLE_ENDIAN;
+ format.frame_rate = (float) _this->spec.freq;
+ format.channel_count = _this->spec.channels; /* !!! FIXME: support > 2? */
+ while ((!valid_datatype) && (test_format)) {
+ valid_datatype = 1;
+ _this->spec.format = test_format;
+ switch (test_format) {
+ case AUDIO_S8:
+ format.format = media_raw_audio_format::B_AUDIO_CHAR;
+ break;
+
+ case AUDIO_U8:
+ format.format = media_raw_audio_format::B_AUDIO_UCHAR;
+ break;
+
+ case AUDIO_S16LSB:
+ format.format = media_raw_audio_format::B_AUDIO_SHORT;
+ break;
+
+ case AUDIO_S16MSB:
+ format.format = media_raw_audio_format::B_AUDIO_SHORT;
+ format.byte_order = B_MEDIA_BIG_ENDIAN;
+ break;
+
+ case AUDIO_S32LSB:
+ format.format = media_raw_audio_format::B_AUDIO_INT;
+ break;
+
+ case AUDIO_S32MSB:
+ format.format = media_raw_audio_format::B_AUDIO_INT;
+ format.byte_order = B_MEDIA_BIG_ENDIAN;
+ break;
+
+ case AUDIO_F32LSB:
+ format.format = media_raw_audio_format::B_AUDIO_FLOAT;
+ break;
+
+ case AUDIO_F32MSB:
+ format.format = media_raw_audio_format::B_AUDIO_FLOAT;
+ format.byte_order = B_MEDIA_BIG_ENDIAN;
+ break;
+
+ default:
+ valid_datatype = 0;
+ test_format = SDL_NextAudioFormat();
+ break;
+ }
+ }
+
+ if (!valid_datatype) { /* shouldn't happen, but just in case... */
+ return SDL_SetError("Unsupported audio format");
+ }
+
+ /* Calculate the final parameters for this audio specification */
+ SDL_CalculateAudioSpec(&_this->spec);
+
+ format.buffer_size = _this->spec.size;
+
+ /* Subscribe to the audio stream (creates a new thread) */
+ sigset_t omask;
+ MaskSignals(&omask);
+ _this->hidden->audio_obj = new BSoundPlayer(&format, "SDL Audio",
+ FillSound, NULL, _this);
+ UnmaskSignals(&omask);
+
+ if (_this->hidden->audio_obj->Start() == B_NO_ERROR) {
+ _this->hidden->audio_obj->SetHasData(true);
+ } else {
+ return SDL_SetError("Unable to start Be audio");
+ }
+
+ /* We're running! */
+ return 0;
+}
+
+static void
+HAIKUAUDIO_Deinitialize(void)
+{
+ SDL_QuitBeApp();
+}
+
+static int
+HAIKUAUDIO_Init(SDL_AudioDriverImpl * impl)
+{
+ /* Initialize the Be Application, if it's not already started */
+ if (SDL_InitBeApp() < 0) {
+ return 0;
+ }
+
+ /* Set the function pointers */
+ impl->OpenDevice = HAIKUAUDIO_OpenDevice;
+ impl->CloseDevice = HAIKUAUDIO_CloseDevice;
+ impl->Deinitialize = HAIKUAUDIO_Deinitialize;
+ impl->ProvidesOwnCallbackThread = 1;
+ impl->OnlyHasDefaultOutputDevice = 1;
+
+ return 1; /* this audio target is available. */
+}
+
+extern "C"
+{
+ extern AudioBootStrap HAIKUAUDIO_bootstrap;
+}
+AudioBootStrap HAIKUAUDIO_bootstrap = {
+ "haiku", "Haiku BSoundPlayer", HAIKUAUDIO_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_HAIKU */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/haiku/SDL_haikuaudio.h b/src/3rdparty/SDL2/src/audio/haiku/SDL_haikuaudio.h
new file mode 100644
index 0000000..f63ccdb
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/haiku/SDL_haikuaudio.h
@@ -0,0 +1,38 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_haikuaudio_h_
+#define SDL_haikuaudio_h_
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *_this
+
+struct SDL_PrivateAudioData
+{
+ BSoundPlayer *audio_obj;
+};
+
+#endif /* SDL_haikuaudio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/jack/SDL_jackaudio.c b/src/3rdparty/SDL2/src/audio/jack/SDL_jackaudio.c
new file mode 100644
index 0000000..a252da7
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/jack/SDL_jackaudio.c
@@ -0,0 +1,429 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_JACK
+
+#include "SDL_assert.h"
+#include "SDL_timer.h"
+#include "SDL_audio.h"
+#include "../SDL_audio_c.h"
+#include "SDL_jackaudio.h"
+#include "SDL_loadso.h"
+#include "../../thread/SDL_systhread.h"
+
+
+static jack_client_t * (*JACK_jack_client_open) (const char *, jack_options_t, jack_status_t *, ...);
+static int (*JACK_jack_client_close) (jack_client_t *);
+static void (*JACK_jack_on_shutdown) (jack_client_t *, JackShutdownCallback, void *);
+static int (*JACK_jack_activate) (jack_client_t *);
+static int (*JACK_jack_deactivate) (jack_client_t *);
+static void * (*JACK_jack_port_get_buffer) (jack_port_t *, jack_nframes_t);
+static int (*JACK_jack_port_unregister) (jack_client_t *, jack_port_t *);
+static void (*JACK_jack_free) (void *);
+static const char ** (*JACK_jack_get_ports) (jack_client_t *, const char *, const char *, unsigned long);
+static jack_nframes_t (*JACK_jack_get_sample_rate) (jack_client_t *);
+static jack_nframes_t (*JACK_jack_get_buffer_size) (jack_client_t *);
+static jack_port_t * (*JACK_jack_port_register) (jack_client_t *, const char *, const char *, unsigned long, unsigned long);
+static const char * (*JACK_jack_port_name) (const jack_port_t *);
+static int (*JACK_jack_connect) (jack_client_t *, const char *, const char *);
+static int (*JACK_jack_set_process_callback) (jack_client_t *, JackProcessCallback, void *);
+
+static int load_jack_syms(void);
+
+
+#ifdef SDL_AUDIO_DRIVER_JACK_DYNAMIC
+
+static const char *jack_library = SDL_AUDIO_DRIVER_JACK_DYNAMIC;
+static void *jack_handle = NULL;
+
+/* !!! FIXME: this is copy/pasted in several places now */
+static int
+load_jack_sym(const char *fn, void **addr)
+{
+ *addr = SDL_LoadFunction(jack_handle, fn);
+ if (*addr == NULL) {
+ /* Don't call SDL_SetError(): SDL_LoadFunction already did. */
+ return 0;
+ }
+
+ return 1;
+}
+
+/* cast funcs to char* first, to please GCC's strict aliasing rules. */
+#define SDL_JACK_SYM(x) \
+ if (!load_jack_sym(#x, (void **) (char *) &JACK_##x)) return -1
+
+static void
+UnloadJackLibrary(void)
+{
+ if (jack_handle != NULL) {
+ SDL_UnloadObject(jack_handle);
+ jack_handle = NULL;
+ }
+}
+
+static int
+LoadJackLibrary(void)
+{
+ int retval = 0;
+ if (jack_handle == NULL) {
+ jack_handle = SDL_LoadObject(jack_library);
+ if (jack_handle == NULL) {
+ retval = -1;
+ /* Don't call SDL_SetError(): SDL_LoadObject already did. */
+ } else {
+ retval = load_jack_syms();
+ if (retval < 0) {
+ UnloadJackLibrary();
+ }
+ }
+ }
+ return retval;
+}
+
+#else
+
+#define SDL_JACK_SYM(x) JACK_##x = x
+
+static void
+UnloadJackLibrary(void)
+{
+}
+
+static int
+LoadJackLibrary(void)
+{
+ load_jack_syms();
+ return 0;
+}
+
+#endif /* SDL_AUDIO_DRIVER_JACK_DYNAMIC */
+
+
+static int
+load_jack_syms(void)
+{
+ SDL_JACK_SYM(jack_client_open);
+ SDL_JACK_SYM(jack_client_close);
+ SDL_JACK_SYM(jack_on_shutdown);
+ SDL_JACK_SYM(jack_activate);
+ SDL_JACK_SYM(jack_deactivate);
+ SDL_JACK_SYM(jack_port_get_buffer);
+ SDL_JACK_SYM(jack_port_unregister);
+ SDL_JACK_SYM(jack_free);
+ SDL_JACK_SYM(jack_get_ports);
+ SDL_JACK_SYM(jack_get_sample_rate);
+ SDL_JACK_SYM(jack_get_buffer_size);
+ SDL_JACK_SYM(jack_port_register);
+ SDL_JACK_SYM(jack_port_name);
+ SDL_JACK_SYM(jack_connect);
+ SDL_JACK_SYM(jack_set_process_callback);
+ return 0;
+}
+
+
+static void
+jackShutdownCallback(void *arg) /* JACK went away; device is lost. */
+{
+ SDL_AudioDevice *this = (SDL_AudioDevice *) arg;
+ SDL_OpenedAudioDeviceDisconnected(this);
+ SDL_SemPost(this->hidden->iosem); /* unblock the SDL thread. */
+}
+
+// !!! FIXME: implement and register these!
+//typedef int(* JackSampleRateCallback)(jack_nframes_t nframes, void *arg)
+//typedef int(* JackBufferSizeCallback)(jack_nframes_t nframes, void *arg)
+
+static int
+jackProcessPlaybackCallback(jack_nframes_t nframes, void *arg)
+{
+ SDL_AudioDevice *this = (SDL_AudioDevice *) arg;
+ jack_port_t **ports = this->hidden->sdlports;
+ const int total_channels = this->spec.channels;
+ const int total_frames = this->spec.samples;
+ int channelsi;
+
+ if (!SDL_AtomicGet(&this->enabled)) {
+ /* silence the buffer to avoid repeats and corruption. */
+ SDL_memset(this->hidden->iobuffer, '\0', this->spec.size);
+ }
+
+ for (channelsi = 0; channelsi < total_channels; channelsi++) {
+ float *dst = (float *) JACK_jack_port_get_buffer(ports[channelsi], nframes);
+ if (dst) {
+ const float *src = ((float *) this->hidden->iobuffer) + channelsi;
+ int framesi;
+ for (framesi = 0; framesi < total_frames; framesi++) {
+ *(dst++) = *src;
+ src += total_channels;
+ }
+ }
+ }
+
+ SDL_SemPost(this->hidden->iosem); /* tell SDL thread we're done; refill the buffer. */
+ return 0; /* success */
+}
+
+
+/* This function waits until it is possible to write a full sound buffer */
+static void
+JACK_WaitDevice(_THIS)
+{
+ if (SDL_AtomicGet(&this->enabled)) {
+ if (SDL_SemWait(this->hidden->iosem) == -1) {
+ SDL_OpenedAudioDeviceDisconnected(this);
+ }
+ }
+}
+
+static Uint8 *
+JACK_GetDeviceBuf(_THIS)
+{
+ return (Uint8 *) this->hidden->iobuffer;
+}
+
+
+static int
+jackProcessCaptureCallback(jack_nframes_t nframes, void *arg)
+{
+ SDL_AudioDevice *this = (SDL_AudioDevice *) arg;
+ if (SDL_AtomicGet(&this->enabled)) {
+ jack_port_t **ports = this->hidden->sdlports;
+ const int total_channels = this->spec.channels;
+ const int total_frames = this->spec.samples;
+ int channelsi;
+
+ for (channelsi = 0; channelsi < total_channels; channelsi++) {
+ const float *src = (const float *) JACK_jack_port_get_buffer(ports[channelsi], nframes);
+ if (src) {
+ float *dst = ((float *) this->hidden->iobuffer) + channelsi;
+ int framesi;
+ for (framesi = 0; framesi < total_frames; framesi++) {
+ *dst = *(src++);
+ dst += total_channels;
+ }
+ }
+ }
+ }
+
+ SDL_SemPost(this->hidden->iosem); /* tell SDL thread we're done; new buffer is ready! */
+ return 0; /* success */
+}
+
+static int
+JACK_CaptureFromDevice(_THIS, void *buffer, int buflen)
+{
+ SDL_assert(buflen == this->spec.size); /* we always fill a full buffer. */
+
+ /* Wait for JACK to fill the iobuffer */
+ if (SDL_SemWait(this->hidden->iosem) == -1) {
+ return -1;
+ }
+
+ SDL_memcpy(buffer, this->hidden->iobuffer, buflen);
+ return buflen;
+}
+
+static void
+JACK_FlushCapture(_THIS)
+{
+ SDL_SemWait(this->hidden->iosem);
+}
+
+
+static void
+JACK_CloseDevice(_THIS)
+{
+ if (this->hidden->client) {
+ JACK_jack_deactivate(this->hidden->client);
+
+ if (this->hidden->sdlports) {
+ const int channels = this->spec.channels;
+ int i;
+ for (i = 0; i < channels; i++) {
+ JACK_jack_port_unregister(this->hidden->client, this->hidden->sdlports[i]);
+ }
+ SDL_free(this->hidden->sdlports);
+ }
+
+ JACK_jack_client_close(this->hidden->client);
+ }
+
+ if (this->hidden->iosem) {
+ SDL_DestroySemaphore(this->hidden->iosem);
+ }
+
+ if (this->hidden->devports) {
+ JACK_jack_free(this->hidden->devports);
+ }
+
+ SDL_free(this->hidden->iobuffer);
+}
+
+static int
+JACK_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ /* Note that JACK uses "output" for capture devices (they output audio
+ data to us) and "input" for playback (we input audio data to them).
+ Likewise, SDL's playback port will be "output" (we write data out)
+ and capture will be "input" (we read data in). */
+ const unsigned long sysportflags = iscapture ? JackPortIsOutput : JackPortIsInput;
+ const unsigned long sdlportflags = iscapture ? JackPortIsInput : JackPortIsOutput;
+ const JackProcessCallback callback = iscapture ? jackProcessCaptureCallback : jackProcessPlaybackCallback;
+ const char *sdlportstr = iscapture ? "input" : "output";
+ const char **devports = NULL;
+ jack_client_t *client = NULL;
+ jack_status_t status;
+ int channels = 0;
+ int i;
+
+ /* Initialize all variables that we clean on shutdown */
+ this->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof (*this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ /* !!! FIXME: we _still_ need an API to specify an app name */
+ client = JACK_jack_client_open("SDL", JackNoStartServer, &status, NULL);
+ this->hidden->client = client;
+ if (client == NULL) {
+ return SDL_SetError("Can't open JACK client");
+ }
+
+ devports = JACK_jack_get_ports(client, NULL, NULL, JackPortIsPhysical | sysportflags);
+ this->hidden->devports = devports;
+ if (!devports || !devports[0]) {
+ return SDL_SetError("No physical JACK ports available");
+ }
+
+ while (devports[++channels]) {
+ /* spin to count devports */
+ }
+
+ /* !!! FIXME: docs say about buffer size: "This size may change, clients that depend on it must register a bufsize_callback so they will be notified if it does." */
+
+ /* Jack pretty much demands what it wants. */
+ this->spec.format = AUDIO_F32SYS;
+ this->spec.freq = JACK_jack_get_sample_rate(client);
+ this->spec.channels = channels;
+ this->spec.samples = JACK_jack_get_buffer_size(client);
+
+ SDL_CalculateAudioSpec(&this->spec);
+
+ this->hidden->iosem = SDL_CreateSemaphore(0);
+ if (!this->hidden->iosem) {
+ return -1; /* error was set by SDL_CreateSemaphore */
+ }
+
+ this->hidden->iobuffer = (float *) SDL_calloc(1, this->spec.size);
+ if (!this->hidden->iobuffer) {
+ return SDL_OutOfMemory();
+ }
+
+ /* Build SDL's ports, which we will connect to the device ports. */
+ this->hidden->sdlports = (jack_port_t **) SDL_calloc(channels, sizeof (jack_port_t *));
+ if (this->hidden->sdlports == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ for (i = 0; i < channels; i++) {
+ char portname[32];
+ SDL_snprintf(portname, sizeof (portname), "sdl_jack_%s_%d", sdlportstr, i);
+ this->hidden->sdlports[i] = JACK_jack_port_register(client, portname, JACK_DEFAULT_AUDIO_TYPE, sdlportflags, 0);
+ if (this->hidden->sdlports[i] == NULL) {
+ return SDL_SetError("jack_port_register failed");
+ }
+ }
+
+ if (JACK_jack_set_process_callback(client, callback, this) != 0) {
+ return SDL_SetError("JACK: Couldn't set process callback");
+ }
+
+ JACK_jack_on_shutdown(client, jackShutdownCallback, this);
+
+ if (JACK_jack_activate(client) != 0) {
+ return SDL_SetError("Failed to activate JACK client");
+ }
+
+ /* once activated, we can connect all the ports. */
+ for (i = 0; i < channels; i++) {
+ const char *sdlport = JACK_jack_port_name(this->hidden->sdlports[i]);
+ const char *srcport = iscapture ? devports[i] : sdlport;
+ const char *dstport = iscapture ? sdlport : devports[i];
+ if (JACK_jack_connect(client, srcport, dstport) != 0) {
+ return SDL_SetError("Couldn't connect JACK ports: %s => %s", srcport, dstport);
+ }
+ }
+
+ /* don't need these anymore. */
+ this->hidden->devports = NULL;
+ JACK_jack_free(devports);
+
+ /* We're ready to rock and roll. :-) */
+ return 0;
+}
+
+static void
+JACK_Deinitialize(void)
+{
+ UnloadJackLibrary();
+}
+
+static int
+JACK_Init(SDL_AudioDriverImpl * impl)
+{
+ if (LoadJackLibrary() < 0) {
+ return 0;
+ } else {
+ /* Make sure a JACK server is running and available. */
+ jack_status_t status;
+ jack_client_t *client = JACK_jack_client_open("SDL", JackNoStartServer, &status, NULL);
+ if (client == NULL) {
+ UnloadJackLibrary();
+ return 0;
+ }
+ JACK_jack_client_close(client);
+ }
+
+ /* Set the function pointers */
+ impl->OpenDevice = JACK_OpenDevice;
+ impl->WaitDevice = JACK_WaitDevice;
+ impl->GetDeviceBuf = JACK_GetDeviceBuf;
+ impl->CloseDevice = JACK_CloseDevice;
+ impl->Deinitialize = JACK_Deinitialize;
+ impl->CaptureFromDevice = JACK_CaptureFromDevice;
+ impl->FlushCapture = JACK_FlushCapture;
+ impl->OnlyHasDefaultOutputDevice = SDL_TRUE;
+ impl->OnlyHasDefaultCaptureDevice = SDL_TRUE;
+ impl->HasCaptureSupport = SDL_TRUE;
+
+ return 1; /* this audio target is available. */
+}
+
+AudioBootStrap JACK_bootstrap = {
+ "jack", "JACK Audio Connection Kit", JACK_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_JACK */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/jack/SDL_jackaudio.h b/src/3rdparty/SDL2/src/audio/jack/SDL_jackaudio.h
new file mode 100644
index 0000000..aab199a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/jack/SDL_jackaudio.h
@@ -0,0 +1,42 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#ifndef SDL_jackaudio_h_
+#define SDL_jackaudio_h_
+
+#include <jack/jack.h>
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData
+{
+ jack_client_t *client;
+ SDL_sem *iosem;
+ float *iobuffer;
+ const char **devports;
+ jack_port_t **sdlports;
+};
+
+#endif /* SDL_jackaudio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/nacl/SDL_naclaudio.c b/src/3rdparty/SDL2/src/audio/nacl/SDL_naclaudio.c
new file mode 100644
index 0000000..3e3afc0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/nacl/SDL_naclaudio.c
@@ -0,0 +1,165 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_NACL
+
+#include "SDL_naclaudio.h"
+
+#include "SDL_audio.h"
+#include "SDL_mutex.h"
+#include "../SDL_audio_c.h"
+#include "../SDL_audiodev_c.h"
+
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/c/pp_instance.h"
+#include "ppapi_simple/ps.h"
+#include "ppapi_simple/ps_interface.h"
+#include "ppapi_simple/ps_event.h"
+
+/* The tag name used by NACL audio */
+#define NACLAUDIO_DRIVER_NAME "nacl"
+
+#define SAMPLE_FRAME_COUNT 4096
+
+/* Audio driver functions */
+static void nacl_audio_callback(void* samples, uint32_t buffer_size, PP_TimeDelta latency, void* data);
+
+/* FIXME: Make use of latency if needed */
+static void nacl_audio_callback(void* stream, uint32_t buffer_size, PP_TimeDelta latency, void* data) {
+ const int len = (int) buffer_size;
+ SDL_AudioDevice* _this = (SDL_AudioDevice*) data;
+ SDL_AudioCallback callback = _this->callbackspec.callback;
+
+ SDL_LockMutex(private->mutex); /* !!! FIXME: is this mutex necessary? */
+
+ /* Only do something if audio is enabled */
+ if (!SDL_AtomicGet(&_this->enabled) || SDL_AtomicGet(&_this->paused)) {
+ if (_this->stream) {
+ SDL_AudioStreamClear(_this->stream);
+ }
+ SDL_memset(stream, _this->spec.silence, len);
+ return;
+ }
+
+ SDL_assert(_this->spec.size == len);
+
+ if (_this->stream == NULL) { /* no conversion necessary. */
+ SDL_LockMutex(_this->mixer_lock);
+ callback(_this->callbackspec.userdata, stream, len);
+ SDL_UnlockMutex(_this->mixer_lock);
+ } else { /* streaming/converting */
+ const int stream_len = _this->callbackspec.size;
+ while (SDL_AudioStreamAvailable(_this->stream) < len) {
+ callback(_this->callbackspec.userdata, _this->work_buffer, stream_len);
+ if (SDL_AudioStreamPut(_this->stream, _this->work_buffer, stream_len) == -1) {
+ SDL_AudioStreamClear(_this->stream);
+ SDL_AtomicSet(&_this->enabled, 0);
+ break;
+ }
+ }
+
+ const int got = SDL_AudioStreamGet(_this->stream, stream, len);
+ SDL_assert((got < 0) || (got == len));
+ if (got != len) {
+ SDL_memset(stream, _this->spec.silence, len);
+ }
+ }
+
+ SDL_UnlockMutex(private->mutex);
+}
+
+static void NACLAUDIO_CloseDevice(SDL_AudioDevice *device) {
+ const PPB_Core *core = PSInterfaceCore();
+ const PPB_Audio *ppb_audio = PSInterfaceAudio();
+ SDL_PrivateAudioData *hidden = (SDL_PrivateAudioData *) device->hidden;
+
+ ppb_audio->StopPlayback(hidden->audio);
+ SDL_DestroyMutex(hidden->mutex);
+ core->ReleaseResource(hidden->audio);
+}
+
+static int
+NACLAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture) {
+ PP_Instance instance = PSGetInstanceId();
+ const PPB_Audio *ppb_audio = PSInterfaceAudio();
+ const PPB_AudioConfig *ppb_audiocfg = PSInterfaceAudioConfig();
+
+ private = (SDL_PrivateAudioData *) SDL_calloc(1, (sizeof *private));
+ if (private == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ private->mutex = SDL_CreateMutex();
+ _this->spec.freq = 44100;
+ _this->spec.format = AUDIO_S16LSB;
+ _this->spec.channels = 2;
+ _this->spec.samples = ppb_audiocfg->RecommendSampleFrameCount(
+ instance,
+ PP_AUDIOSAMPLERATE_44100,
+ SAMPLE_FRAME_COUNT);
+
+ /* Calculate the final parameters for this audio specification */
+ SDL_CalculateAudioSpec(&_this->spec);
+
+ private->audio = ppb_audio->Create(
+ instance,
+ ppb_audiocfg->CreateStereo16Bit(instance, PP_AUDIOSAMPLERATE_44100, _this->spec.samples),
+ nacl_audio_callback,
+ _this);
+
+ /* Start audio playback while we are still on the main thread. */
+ ppb_audio->StartPlayback(private->audio);
+
+ return 0;
+}
+
+static int
+NACLAUDIO_Init(SDL_AudioDriverImpl * impl)
+{
+ if (PSGetInstanceId() == 0) {
+ return 0;
+ }
+
+ /* Set the function pointers */
+ impl->OpenDevice = NACLAUDIO_OpenDevice;
+ impl->CloseDevice = NACLAUDIO_CloseDevice;
+ impl->OnlyHasDefaultOutputDevice = 1;
+ impl->ProvidesOwnCallbackThread = 1;
+ /*
+ * impl->WaitDevice = NACLAUDIO_WaitDevice;
+ * impl->GetDeviceBuf = NACLAUDIO_GetDeviceBuf;
+ * impl->PlayDevice = NACLAUDIO_PlayDevice;
+ * impl->Deinitialize = NACLAUDIO_Deinitialize;
+ */
+
+ return 1;
+}
+
+AudioBootStrap NACLAUDIO_bootstrap = {
+ NACLAUDIO_DRIVER_NAME, "SDL NaCl Audio Driver",
+ NACLAUDIO_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_NACL */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/nacl/SDL_naclaudio.h b/src/3rdparty/SDL2/src/audio/nacl/SDL_naclaudio.h
new file mode 100644
index 0000000..5ec842b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/nacl/SDL_naclaudio.h
@@ -0,0 +1,43 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_naclaudio_h_
+#define SDL_naclaudio_h_
+
+#include "SDL_audio.h"
+#include "../SDL_sysaudio.h"
+#include "SDL_mutex.h"
+
+#include "ppapi/c/ppb_audio.h"
+
+#define _THIS SDL_AudioDevice *_this
+#define private _this->hidden
+
+typedef struct SDL_PrivateAudioData {
+ SDL_mutex* mutex;
+ PP_Resource audio;
+} SDL_PrivateAudioData;
+
+#endif /* SDL_naclaudio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/nas/SDL_nasaudio.c b/src/3rdparty/SDL2/src/audio/nas/SDL_nasaudio.c
new file mode 100644
index 0000000..5a02a3b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/nas/SDL_nasaudio.c
@@ -0,0 +1,463 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_NAS
+
+/* Allow access to a raw mixing buffer */
+
+#include <signal.h>
+#include <unistd.h>
+
+#include "SDL_timer.h"
+#include "SDL_audio.h"
+#include "SDL_loadso.h"
+#include "../SDL_audio_c.h"
+#include "SDL_nasaudio.h"
+
+static void (*NAS_AuCloseServer) (AuServer *);
+static void (*NAS_AuNextEvent) (AuServer *, AuBool, AuEvent *);
+static AuBool(*NAS_AuDispatchEvent) (AuServer *, AuEvent *);
+static void (*NAS_AuHandleEvents) (AuServer *);
+static AuFlowID(*NAS_AuCreateFlow) (AuServer *, AuStatus *);
+static void (*NAS_AuStartFlow) (AuServer *, AuFlowID, AuStatus *);
+static void (*NAS_AuSetElements)
+ (AuServer *, AuFlowID, AuBool, int, AuElement *, AuStatus *);
+static void (*NAS_AuWriteElement)
+ (AuServer *, AuFlowID, int, AuUint32, AuPointer, AuBool, AuStatus *);
+static AuUint32 (*NAS_AuReadElement)
+ (AuServer *, AuFlowID, int, AuUint32, AuPointer, AuStatus *);
+static AuServer *(*NAS_AuOpenServer)
+ (_AuConst char *, int, _AuConst char *, int, _AuConst char *, char **);
+static AuEventHandlerRec *(*NAS_AuRegisterEventHandler)
+ (AuServer *, AuMask, int, AuID, AuEventHandlerCallback, AuPointer);
+
+
+#ifdef SDL_AUDIO_DRIVER_NAS_DYNAMIC
+
+static const char *nas_library = SDL_AUDIO_DRIVER_NAS_DYNAMIC;
+static void *nas_handle = NULL;
+
+static int
+load_nas_sym(const char *fn, void **addr)
+{
+ *addr = SDL_LoadFunction(nas_handle, fn);
+ if (*addr == NULL) {
+ return 0;
+ }
+ return 1;
+}
+
+/* cast funcs to char* first, to please GCC's strict aliasing rules. */
+#define SDL_NAS_SYM(x) \
+ if (!load_nas_sym(#x, (void **) (char *) &NAS_##x)) return -1
+#else
+#define SDL_NAS_SYM(x) NAS_##x = x
+#endif
+
+static int
+load_nas_syms(void)
+{
+ SDL_NAS_SYM(AuCloseServer);
+ SDL_NAS_SYM(AuNextEvent);
+ SDL_NAS_SYM(AuDispatchEvent);
+ SDL_NAS_SYM(AuHandleEvents);
+ SDL_NAS_SYM(AuCreateFlow);
+ SDL_NAS_SYM(AuStartFlow);
+ SDL_NAS_SYM(AuSetElements);
+ SDL_NAS_SYM(AuWriteElement);
+ SDL_NAS_SYM(AuReadElement);
+ SDL_NAS_SYM(AuOpenServer);
+ SDL_NAS_SYM(AuRegisterEventHandler);
+ return 0;
+}
+
+#undef SDL_NAS_SYM
+
+#ifdef SDL_AUDIO_DRIVER_NAS_DYNAMIC
+
+static void
+UnloadNASLibrary(void)
+{
+ if (nas_handle != NULL) {
+ SDL_UnloadObject(nas_handle);
+ nas_handle = NULL;
+ }
+}
+
+static int
+LoadNASLibrary(void)
+{
+ int retval = 0;
+ if (nas_handle == NULL) {
+ nas_handle = SDL_LoadObject(nas_library);
+ if (nas_handle == NULL) {
+ /* Copy error string so we can use it in a new SDL_SetError(). */
+ const char *origerr = SDL_GetError();
+ const size_t len = SDL_strlen(origerr) + 1;
+ char *err = (char *) alloca(len);
+ SDL_strlcpy(err, origerr, len);
+ retval = -1;
+ SDL_SetError("NAS: SDL_LoadObject('%s') failed: %s",
+ nas_library, err);
+ } else {
+ retval = load_nas_syms();
+ if (retval < 0) {
+ UnloadNASLibrary();
+ }
+ }
+ }
+ return retval;
+}
+
+#else
+
+static void
+UnloadNASLibrary(void)
+{
+}
+
+static int
+LoadNASLibrary(void)
+{
+ load_nas_syms();
+ return 0;
+}
+
+#endif /* SDL_AUDIO_DRIVER_NAS_DYNAMIC */
+
+/* This function waits until it is possible to write a full sound buffer */
+static void
+NAS_WaitDevice(_THIS)
+{
+ while (this->hidden->buf_free < this->hidden->mixlen) {
+ AuEvent ev;
+ NAS_AuNextEvent(this->hidden->aud, AuTrue, &ev);
+ NAS_AuDispatchEvent(this->hidden->aud, &ev);
+ }
+}
+
+static void
+NAS_PlayDevice(_THIS)
+{
+ while (this->hidden->mixlen > this->hidden->buf_free) {
+ /*
+ * We think the buffer is full? Yikes! Ask the server for events,
+ * in the hope that some of them is LowWater events telling us more
+ * of the buffer is free now than what we think.
+ */
+ AuEvent ev;
+ NAS_AuNextEvent(this->hidden->aud, AuTrue, &ev);
+ NAS_AuDispatchEvent(this->hidden->aud, &ev);
+ }
+ this->hidden->buf_free -= this->hidden->mixlen;
+
+ /* Write the audio data */
+ NAS_AuWriteElement(this->hidden->aud, this->hidden->flow, 0,
+ this->hidden->mixlen, this->hidden->mixbuf, AuFalse,
+ NULL);
+
+ this->hidden->written += this->hidden->mixlen;
+
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Wrote %d bytes of audio data\n", this->hidden->mixlen);
+#endif
+}
+
+static Uint8 *
+NAS_GetDeviceBuf(_THIS)
+{
+ return (this->hidden->mixbuf);
+}
+
+static int
+NAS_CaptureFromDevice(_THIS, void *buffer, int buflen)
+{
+ struct SDL_PrivateAudioData *h = this->hidden;
+ int retval;
+
+ while (SDL_TRUE) {
+ /* just keep the event queue moving and the server chattering. */
+ NAS_AuHandleEvents(h->aud);
+
+ retval = (int) NAS_AuReadElement(h->aud, h->flow, 1, buflen, buffer, NULL);
+ /*printf("read %d capture bytes\n", (int) retval);*/
+ if (retval == 0) {
+ SDL_Delay(10); /* don't burn the CPU if we're waiting for data. */
+ } else {
+ break;
+ }
+ }
+
+ return retval;
+}
+
+static void
+NAS_FlushCapture(_THIS)
+{
+ struct SDL_PrivateAudioData *h = this->hidden;
+ AuUint32 total = 0;
+ AuUint32 br;
+ Uint8 buf[512];
+
+ do {
+ /* just keep the event queue moving and the server chattering. */
+ NAS_AuHandleEvents(h->aud);
+ br = NAS_AuReadElement(h->aud, h->flow, 1, sizeof (buf), buf, NULL);
+ /*printf("flushed %d capture bytes\n", (int) br);*/
+ total += br;
+ } while ((br == sizeof (buf)) && (total < this->spec.size));
+}
+
+static void
+NAS_CloseDevice(_THIS)
+{
+ if (this->hidden->aud) {
+ NAS_AuCloseServer(this->hidden->aud);
+ }
+ SDL_free(this->hidden->mixbuf);
+ SDL_free(this->hidden);
+}
+
+static unsigned char
+sdlformat_to_auformat(unsigned int fmt)
+{
+ switch (fmt) {
+ case AUDIO_U8:
+ return AuFormatLinearUnsigned8;
+ case AUDIO_S8:
+ return AuFormatLinearSigned8;
+ case AUDIO_U16LSB:
+ return AuFormatLinearUnsigned16LSB;
+ case AUDIO_U16MSB:
+ return AuFormatLinearUnsigned16MSB;
+ case AUDIO_S16LSB:
+ return AuFormatLinearSigned16LSB;
+ case AUDIO_S16MSB:
+ return AuFormatLinearSigned16MSB;
+ }
+ return AuNone;
+}
+
+static AuBool
+event_handler(AuServer * aud, AuEvent * ev, AuEventHandlerRec * hnd)
+{
+ SDL_AudioDevice *this = (SDL_AudioDevice *) hnd->data;
+ struct SDL_PrivateAudioData *h = this->hidden;
+ if (this->iscapture) {
+ return AuTrue; /* we don't (currently) care about any of this for capture devices */
+ }
+
+ switch (ev->type) {
+ case AuEventTypeElementNotify:
+ {
+ AuElementNotifyEvent *event = (AuElementNotifyEvent *) ev;
+
+ switch (event->kind) {
+ case AuElementNotifyKindLowWater:
+ if (h->buf_free >= 0) {
+ h->really += event->num_bytes;
+ gettimeofday(&h->last_tv, 0);
+ h->buf_free += event->num_bytes;
+ } else {
+ h->buf_free = event->num_bytes;
+ }
+ break;
+ case AuElementNotifyKindState:
+ switch (event->cur_state) {
+ case AuStatePause:
+ if (event->reason != AuReasonUser) {
+ if (h->buf_free >= 0) {
+ h->really += event->num_bytes;
+ gettimeofday(&h->last_tv, 0);
+ h->buf_free += event->num_bytes;
+ } else {
+ h->buf_free = event->num_bytes;
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+ return AuTrue;
+}
+
+static AuDeviceID
+find_device(_THIS)
+{
+ /* These "Au" things are all macros, not functions... */
+ struct SDL_PrivateAudioData *h = this->hidden;
+ const unsigned int devicekind = this->iscapture ? AuComponentKindPhysicalInput : AuComponentKindPhysicalOutput;
+ const int numdevs = AuServerNumDevices(h->aud);
+ const int nch = this->spec.channels;
+ int i;
+
+ /* Try to find exact match on channels first... */
+ for (i = 0; i < numdevs; i++) {
+ const AuDeviceAttributes *dev = AuServerDevice(h->aud, i);
+ if ((AuDeviceKind(dev) == devicekind) && (AuDeviceNumTracks(dev) == nch)) {
+ return AuDeviceIdentifier(dev);
+ }
+ }
+
+ /* Take anything, then... */
+ for (i = 0; i < numdevs; i++) {
+ const AuDeviceAttributes *dev = AuServerDevice(h->aud, i);
+ if (AuDeviceKind(dev) == devicekind) {
+ this->spec.channels = AuDeviceNumTracks(dev);
+ return AuDeviceIdentifier(dev);
+ }
+ }
+ return AuNone;
+}
+
+static int
+NAS_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ AuElement elms[3];
+ int buffer_size;
+ SDL_AudioFormat test_format, format;
+
+ /* Initialize all variables that we clean on shutdown */
+ this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc((sizeof *this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(this->hidden);
+
+ /* Try for a closest match on audio format */
+ format = 0;
+ for (test_format = SDL_FirstAudioFormat(this->spec.format);
+ !format && test_format;) {
+ format = sdlformat_to_auformat(test_format);
+ if (format == AuNone) {
+ test_format = SDL_NextAudioFormat();
+ }
+ }
+ if (format == 0) {
+ return SDL_SetError("NAS: Couldn't find any hardware audio formats");
+ }
+ this->spec.format = test_format;
+
+ this->hidden->aud = NAS_AuOpenServer("", 0, NULL, 0, NULL, NULL);
+ if (this->hidden->aud == 0) {
+ return SDL_SetError("NAS: Couldn't open connection to NAS server");
+ }
+
+ this->hidden->dev = find_device(this);
+ if ((this->hidden->dev == AuNone)
+ || (!(this->hidden->flow = NAS_AuCreateFlow(this->hidden->aud, 0)))) {
+ return SDL_SetError("NAS: Couldn't find a fitting device on NAS server");
+ }
+
+ buffer_size = this->spec.freq;
+ if (buffer_size < 4096)
+ buffer_size = 4096;
+
+ if (buffer_size > 32768)
+ buffer_size = 32768; /* So that the buffer won't get unmanageably big. */
+
+ /* Calculate the final parameters for this audio specification */
+ SDL_CalculateAudioSpec(&this->spec);
+
+ if (iscapture) {
+ AuMakeElementImportDevice(elms, this->spec.freq, this->hidden->dev,
+ AuUnlimitedSamples, 0, NULL);
+ AuMakeElementExportClient(elms + 1, 0, this->spec.freq, format,
+ this->spec.channels, AuTrue, buffer_size,
+ buffer_size, 0, NULL);
+ } else {
+ AuMakeElementImportClient(elms, this->spec.freq, format,
+ this->spec.channels, AuTrue, buffer_size,
+ buffer_size / 4, 0, NULL);
+ AuMakeElementExportDevice(elms + 1, 0, this->hidden->dev, this->spec.freq,
+ AuUnlimitedSamples, 0, NULL);
+ }
+
+ NAS_AuSetElements(this->hidden->aud, this->hidden->flow, AuTrue,
+ 2, elms, NULL);
+
+ NAS_AuRegisterEventHandler(this->hidden->aud, AuEventHandlerIDMask, 0,
+ this->hidden->flow, event_handler,
+ (AuPointer) this);
+
+ NAS_AuStartFlow(this->hidden->aud, this->hidden->flow, NULL);
+
+ /* Allocate mixing buffer */
+ if (!iscapture) {
+ this->hidden->mixlen = this->spec.size;
+ this->hidden->mixbuf = (Uint8 *) SDL_malloc(this->hidden->mixlen);
+ if (this->hidden->mixbuf == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
+ }
+
+ /* We're ready to rock and roll. :-) */
+ return 0;
+}
+
+static void
+NAS_Deinitialize(void)
+{
+ UnloadNASLibrary();
+}
+
+static int
+NAS_Init(SDL_AudioDriverImpl * impl)
+{
+ if (LoadNASLibrary() < 0) {
+ return 0;
+ } else {
+ AuServer *aud = NAS_AuOpenServer("", 0, NULL, 0, NULL, NULL);
+ if (aud == NULL) {
+ SDL_SetError("NAS: AuOpenServer() failed (no audio server?)");
+ return 0;
+ }
+ NAS_AuCloseServer(aud);
+ }
+
+ /* Set the function pointers */
+ impl->OpenDevice = NAS_OpenDevice;
+ impl->PlayDevice = NAS_PlayDevice;
+ impl->WaitDevice = NAS_WaitDevice;
+ impl->GetDeviceBuf = NAS_GetDeviceBuf;
+ impl->CaptureFromDevice = NAS_CaptureFromDevice;
+ impl->FlushCapture = NAS_FlushCapture;
+ impl->CloseDevice = NAS_CloseDevice;
+ impl->Deinitialize = NAS_Deinitialize;
+
+ impl->OnlyHasDefaultOutputDevice = 1;
+ impl->OnlyHasDefaultCaptureDevice = 1;
+ impl->HasCaptureSupport = SDL_TRUE;
+
+ return 1; /* this audio target is available. */
+}
+
+AudioBootStrap NAS_bootstrap = {
+ "nas", "Network Audio System", NAS_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_NAS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/nas/SDL_nasaudio.h b/src/3rdparty/SDL2/src/audio/nas/SDL_nasaudio.h
new file mode 100644
index 0000000..b1a51d1
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/nas/SDL_nasaudio.h
@@ -0,0 +1,56 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_nasaudio_h_
+#define SDL_nasaudio_h_
+
+#ifdef __sgi
+#include <nas/audiolib.h>
+#else
+#include <audio/audiolib.h>
+#endif
+#include <sys/time.h>
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData
+{
+ AuServer *aud;
+ AuFlowID flow;
+ AuDeviceID dev;
+
+ /* Raw mixing buffer */
+ Uint8 *mixbuf;
+ int mixlen;
+
+ int written;
+ int really;
+ int bps;
+ struct timeval last_tv;
+ int buf_free;
+};
+#endif /* SDL_nasaudio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/netbsd/SDL_netbsdaudio.c b/src/3rdparty/SDL2/src/audio/netbsd/SDL_netbsdaudio.c
new file mode 100644
index 0000000..0dc0b25
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/netbsd/SDL_netbsdaudio.c
@@ -0,0 +1,412 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_NETBSD
+
+/*
+ * Driver for native NetBSD audio(4).
+ * vedge@vedge.com.ar.
+ */
+
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/audioio.h>
+
+#include "SDL_timer.h"
+#include "SDL_audio.h"
+#include "../../core/unix/SDL_poll.h"
+#include "../SDL_audio_c.h"
+#include "../SDL_audiodev_c.h"
+#include "SDL_netbsdaudio.h"
+
+/* Use timer for synchronization */
+/* #define USE_TIMER_SYNC */
+
+/* #define DEBUG_AUDIO */
+/* #define DEBUG_AUDIO_STREAM */
+
+
+static void
+NETBSDAUDIO_DetectDevices(void)
+{
+ SDL_EnumUnixAudioDevices(0, NULL);
+}
+
+
+static void
+NETBSDAUDIO_Status(_THIS)
+{
+#ifdef DEBUG_AUDIO
+ /* *INDENT-OFF* */
+ audio_info_t info;
+ const audio_prinfo *prinfo;
+
+ if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
+ fprintf(stderr, "AUDIO_GETINFO failed.\n");
+ return;
+ }
+
+ prinfo = this->iscapture ? &info.play : &info.record;
+
+ fprintf(stderr, "\n"
+ "[%s info]\n"
+ "buffer size : %d bytes\n"
+ "sample rate : %i Hz\n"
+ "channels : %i\n"
+ "precision : %i-bit\n"
+ "encoding : 0x%x\n"
+ "seek : %i\n"
+ "sample count : %i\n"
+ "EOF count : %i\n"
+ "paused : %s\n"
+ "error occured : %s\n"
+ "waiting : %s\n"
+ "active : %s\n"
+ "",
+ this->iscapture ? "record" : "play",
+ prinfo->buffer_size,
+ prinfo->sample_rate,
+ prinfo->channels,
+ prinfo->precision,
+ prinfo->encoding,
+ prinfo->seek,
+ prinfo->samples,
+ prinfo->eof,
+ prinfo->pause ? "yes" : "no",
+ prinfo->error ? "yes" : "no",
+ prinfo->waiting ? "yes" : "no",
+ prinfo->active ? "yes" : "no");
+
+ fprintf(stderr, "\n"
+ "[audio info]\n"
+ "monitor_gain : %i\n"
+ "hw block size : %d bytes\n"
+ "hi watermark : %i\n"
+ "lo watermark : %i\n"
+ "audio mode : %s\n"
+ "",
+ info.monitor_gain,
+ info.blocksize,
+ info.hiwat, info.lowat,
+ (info.mode == AUMODE_PLAY) ? "PLAY"
+ : (info.mode = AUMODE_RECORD) ? "RECORD"
+ : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL" : "?"));
+ /* *INDENT-ON* */
+#endif /* DEBUG_AUDIO */
+}
+
+
+/* This function waits until it is possible to write a full sound buffer */
+static void
+NETBSDAUDIO_WaitDevice(_THIS)
+{
+#ifndef USE_BLOCKING_WRITES /* Not necessary when using blocking writes */
+ /* See if we need to use timed audio synchronization */
+ if (this->hidden->frame_ticks) {
+ /* Use timer for general audio synchronization */
+ Sint32 ticks;
+
+ ticks = ((Sint32) (this->hidden->next_frame - SDL_GetTicks())) - FUDGE_TICKS;
+ if (ticks > 0) {
+ SDL_Delay(ticks);
+ }
+ } else {
+ /* Use SDL_IOReady() for audio synchronization */
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Waiting for audio to get ready\n");
+#endif
+ if (SDL_IOReady(this->hidden->audio_fd, SDL_TRUE, 10 * 1000)
+ <= 0) {
+ const char *message =
+ "Audio timeout - buggy audio driver? (disabled)";
+ /* In general we should never print to the screen,
+ but in this case we have no other way of letting
+ the user know what happened.
+ */
+ fprintf(stderr, "SDL: %s\n", message);
+ SDL_OpenedAudioDeviceDisconnected(this);
+ /* Don't try to close - may hang */
+ this->hidden->audio_fd = -1;
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Done disabling audio\n");
+#endif
+ }
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Ready!\n");
+#endif
+ }
+#endif /* !USE_BLOCKING_WRITES */
+}
+
+static void
+NETBSDAUDIO_PlayDevice(_THIS)
+{
+ int written, p = 0;
+
+ /* Write the audio data, checking for EAGAIN on broken audio drivers */
+ do {
+ written = write(this->hidden->audio_fd,
+ &this->hidden->mixbuf[p], this->hidden->mixlen - p);
+
+ if (written > 0)
+ p += written;
+ if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
+ /* Non recoverable error has occurred. It should be reported!!! */
+ perror("audio");
+ break;
+ }
+
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Wrote %d bytes of audio data\n", written);
+#endif
+
+ if (p < this->hidden->mixlen
+ || ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
+ SDL_Delay(1); /* Let a little CPU time go by */
+ }
+ } while (p < this->hidden->mixlen);
+
+ /* If timer synchronization is enabled, set the next write frame */
+ if (this->hidden->frame_ticks) {
+ this->hidden->next_frame += this->hidden->frame_ticks;
+ }
+
+ /* If we couldn't write, assume fatal error for now */
+ if (written < 0) {
+ SDL_OpenedAudioDeviceDisconnected(this);
+ }
+}
+
+static Uint8 *
+NETBSDAUDIO_GetDeviceBuf(_THIS)
+{
+ return (this->hidden->mixbuf);
+}
+
+
+static int
+NETBSDAUDIO_CaptureFromDevice(_THIS, void *_buffer, int buflen)
+{
+ Uint8 *buffer = (Uint8 *) _buffer;
+ int br, p = 0;
+
+ /* Capture the audio data, checking for EAGAIN on broken audio drivers */
+ do {
+ br = read(this->hidden->audio_fd, buffer + p, buflen - p);
+ if (br > 0)
+ p += br;
+ if (br == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
+ /* Non recoverable error has occurred. It should be reported!!! */
+ perror("audio");
+ return p ? p : -1;
+ }
+
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Captured %d bytes of audio data\n", br);
+#endif
+
+ if (p < buflen
+ || ((br < 0) && ((errno == 0) || (errno == EAGAIN)))) {
+ SDL_Delay(1); /* Let a little CPU time go by */
+ }
+ } while (p < buflen);
+}
+
+static void
+NETBSDAUDIO_FlushCapture(_THIS)
+{
+ audio_info_t info;
+ size_t remain;
+ Uint8 buf[512];
+
+ if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
+ return; /* oh well. */
+ }
+
+ remain = (size_t) (info.record.samples * (SDL_AUDIO_BITSIZE(this->spec.format) / 8));
+ while (remain > 0) {
+ const size_t len = SDL_min(sizeof (buf), remain);
+ const int br = read(this->hidden->audio_fd, buf, len);
+ if (br <= 0) {
+ return; /* oh well. */
+ }
+ remain -= br;
+ }
+}
+
+static void
+NETBSDAUDIO_CloseDevice(_THIS)
+{
+ if (this->hidden->audio_fd >= 0) {
+ close(this->hidden->audio_fd);
+ }
+ SDL_free(this->hidden->mixbuf);
+ SDL_free(this->hidden);
+}
+
+static int
+NETBSDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ const int flags = iscapture ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT;
+ SDL_AudioFormat format = 0;
+ audio_info_t info;
+ audio_prinfo *prinfo = iscapture ? &info.play : &info.record;
+
+ /* We don't care what the devname is...we'll try to open anything. */
+ /* ...but default to first name in the list... */
+ if (devname == NULL) {
+ devname = SDL_GetAudioDeviceName(0, iscapture);
+ if (devname == NULL) {
+ return SDL_SetError("No such audio device");
+ }
+ }
+
+ /* Initialize all variables that we clean on shutdown */
+ this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc((sizeof *this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(this->hidden);
+
+ /* Open the audio device */
+ this->hidden->audio_fd = open(devname, flags, 0);
+ if (this->hidden->audio_fd < 0) {
+ return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
+ }
+
+ AUDIO_INITINFO(&info);
+
+ /* Calculate the final parameters for this audio specification */
+ SDL_CalculateAudioSpec(&this->spec);
+
+ /* Set to play mode */
+ info.mode = iscapture ? AUMODE_RECORD : AUMODE_PLAY;
+ if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) < 0) {
+ return SDL_SetError("Couldn't put device into play mode");
+ }
+
+ AUDIO_INITINFO(&info);
+ for (format = SDL_FirstAudioFormat(this->spec.format);
+ format; format = SDL_NextAudioFormat()) {
+ switch (format) {
+ case AUDIO_U8:
+ prinfo->encoding = AUDIO_ENCODING_ULINEAR;
+ prinfo->precision = 8;
+ break;
+ case AUDIO_S8:
+ prinfo->encoding = AUDIO_ENCODING_SLINEAR;
+ prinfo->precision = 8;
+ break;
+ case AUDIO_S16LSB:
+ prinfo->encoding = AUDIO_ENCODING_SLINEAR_LE;
+ prinfo->precision = 16;
+ break;
+ case AUDIO_S16MSB:
+ prinfo->encoding = AUDIO_ENCODING_SLINEAR_BE;
+ prinfo->precision = 16;
+ break;
+ case AUDIO_U16LSB:
+ prinfo->encoding = AUDIO_ENCODING_ULINEAR_LE;
+ prinfo->precision = 16;
+ break;
+ case AUDIO_U16MSB:
+ prinfo->encoding = AUDIO_ENCODING_ULINEAR_BE;
+ prinfo->precision = 16;
+ break;
+ default:
+ continue;
+ }
+
+ if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == 0) {
+ break;
+ }
+ }
+
+ if (!format) {
+ return SDL_SetError("No supported encoding for 0x%x", this->spec.format);
+ }
+
+ this->spec.format = format;
+
+ AUDIO_INITINFO(&info);
+ prinfo->channels = this->spec.channels;
+ if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == -1) {
+ this->spec.channels = 1;
+ }
+ AUDIO_INITINFO(&info);
+ prinfo->sample_rate = this->spec.freq;
+ info.blocksize = this->spec.size;
+ info.hiwat = 5;
+ info.lowat = 3;
+ (void) ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info);
+ (void) ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info);
+ this->spec.freq = prinfo->sample_rate;
+
+ if (!iscapture) {
+ /* Allocate mixing buffer */
+ this->hidden->mixlen = this->spec.size;
+ this->hidden->mixbuf = (Uint8 *) SDL_malloc(this->hidden->mixlen);
+ if (this->hidden->mixbuf == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
+ }
+
+ NETBSDAUDIO_Status(this);
+
+ /* We're ready to rock and roll. :-) */
+ return 0;
+}
+
+static int
+NETBSDAUDIO_Init(SDL_AudioDriverImpl * impl)
+{
+ /* Set the function pointers */
+ impl->DetectDevices = NETBSDAUDIO_DetectDevices;
+ impl->OpenDevice = NETBSDAUDIO_OpenDevice;
+ impl->PlayDevice = NETBSDAUDIO_PlayDevice;
+ impl->WaitDevice = NETBSDAUDIO_WaitDevice;
+ impl->GetDeviceBuf = NETBSDAUDIO_GetDeviceBuf;
+ impl->CloseDevice = NETBSDAUDIO_CloseDevice;
+ impl->CaptureFromDevice = NETBSDAUDIO_CaptureFromDevice;
+ impl->FlushCapture = NETBSDAUDIO_FlushCapture;
+
+ impl->HasCaptureSupport = SDL_TRUE;
+ impl->AllowsArbitraryDeviceNames = 1;
+
+ return 1; /* this audio target is available. */
+}
+
+
+AudioBootStrap NETBSDAUDIO_bootstrap = {
+ "netbsd", "NetBSD audio", NETBSDAUDIO_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_NETBSD */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/netbsd/SDL_netbsdaudio.h b/src/3rdparty/SDL2/src/audio/netbsd/SDL_netbsdaudio.h
new file mode 100644
index 0000000..1c46068
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/netbsd/SDL_netbsdaudio.h
@@ -0,0 +1,48 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_netbsdaudio_h_
+#define SDL_netbsdaudio_h_
+
+#include "../SDL_sysaudio.h"
+
+#define _THIS SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData
+{
+ /* The file descriptor for the audio device */
+ int audio_fd;
+
+ /* Raw mixing buffer */
+ Uint8 *mixbuf;
+ int mixlen;
+
+ /* Support for audio timing using a timer, in addition to SDL_IOReady() */
+ float frame_ticks;
+ float next_frame;
+};
+
+#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
+
+#endif /* SDL_netbsdaudio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/paudio/SDL_paudio.c b/src/3rdparty/SDL2/src/audio/paudio/SDL_paudio.c
new file mode 100644
index 0000000..1e8c124
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/paudio/SDL_paudio.c
@@ -0,0 +1,516 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_PAUDIO
+
+/* Allow access to a raw mixing buffer */
+
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "SDL_timer.h"
+#include "SDL_audio.h"
+#include "SDL_stdinc.h"
+#include "../SDL_audio_c.h"
+#include "../../core/unix/SDL_poll.h"
+#include "SDL_paudio.h"
+
+/* #define DEBUG_AUDIO */
+
+/* A conflict within AIX 4.3.3 <sys/> headers and probably others as well.
+ * I guess nobody ever uses audio... Shame over AIX header files. */
+#include <sys/machine.h>
+#undef BIG_ENDIAN
+#include <sys/audio.h>
+
+/* Open the audio device for playback, and don't block if busy */
+/* #define OPEN_FLAGS (O_WRONLY|O_NONBLOCK) */
+#define OPEN_FLAGS O_WRONLY
+
+/* Get the name of the audio device we use for output */
+
+#ifndef _PATH_DEV_DSP
+#define _PATH_DEV_DSP "/dev/%caud%c/%c"
+#endif
+
+static char devsettings[][3] = {
+ {'p', '0', '1'}, {'p', '0', '2'}, {'p', '0', '3'}, {'p', '0', '4'},
+ {'p', '1', '1'}, {'p', '1', '2'}, {'p', '1', '3'}, {'p', '1', '4'},
+ {'p', '2', '1'}, {'p', '2', '2'}, {'p', '2', '3'}, {'p', '2', '4'},
+ {'p', '3', '1'}, {'p', '3', '2'}, {'p', '3', '3'}, {'p', '3', '4'},
+ {'b', '0', '1'}, {'b', '0', '2'}, {'b', '0', '3'}, {'b', '0', '4'},
+ {'b', '1', '1'}, {'b', '1', '2'}, {'b', '1', '3'}, {'b', '1', '4'},
+ {'b', '2', '1'}, {'b', '2', '2'}, {'b', '2', '3'}, {'b', '2', '4'},
+ {'b', '3', '1'}, {'b', '3', '2'}, {'b', '3', '3'}, {'b', '3', '4'},
+ {'\0', '\0', '\0'}
+};
+
+static int
+OpenUserDefinedDevice(char *path, int maxlen, int flags)
+{
+ const char *audiodev;
+ int fd;
+
+ /* Figure out what our audio device is */
+ if ((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) {
+ audiodev = SDL_getenv("AUDIODEV");
+ }
+ if (audiodev == NULL) {
+ return -1;
+ }
+ fd = open(audiodev, flags, 0);
+ if (path != NULL) {
+ SDL_strlcpy(path, audiodev, maxlen);
+ path[maxlen - 1] = '\0';
+ }
+ return fd;
+}
+
+static int
+OpenAudioPath(char *path, int maxlen, int flags, int classic)
+{
+ struct stat sb;
+ int cycle = 0;
+ int fd = OpenUserDefinedDevice(path, maxlen, flags);
+
+ if (fd != -1) {
+ return fd;
+ }
+
+ /* !!! FIXME: do we really need a table here? */
+ while (devsettings[cycle][0] != '\0') {
+ char audiopath[1024];
+ SDL_snprintf(audiopath, SDL_arraysize(audiopath),
+ _PATH_DEV_DSP,
+ devsettings[cycle][0],
+ devsettings[cycle][1], devsettings[cycle][2]);
+
+ if (stat(audiopath, &sb) == 0) {
+ fd = open(audiopath, flags, 0);
+ if (fd >= 0) {
+ if (path != NULL) {
+ SDL_strlcpy(path, audiopath, maxlen);
+ }
+ return fd;
+ }
+ }
+ }
+ return -1;
+}
+
+/* This function waits until it is possible to write a full sound buffer */
+static void
+PAUDIO_WaitDevice(_THIS)
+{
+ fd_set fdset;
+
+ /* See if we need to use timed audio synchronization */
+ if (this->hidden->frame_ticks) {
+ /* Use timer for general audio synchronization */
+ Sint32 ticks;
+
+ ticks = ((Sint32) (this->hidden->next_frame - SDL_GetTicks())) - FUDGE_TICKS;
+ if (ticks > 0) {
+ SDL_Delay(ticks);
+ }
+ } else {
+ int timeoutMS;
+ audio_buffer paud_bufinfo;
+
+ if (ioctl(this->hidden->audio_fd, AUDIO_BUFFER, &paud_bufinfo) < 0) {
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Couldn't get audio buffer information\n");
+#endif
+ timeoutMS = 10 * 1000;
+ } else {
+ timeoutMS = paud_bufinfo.write_buf_time;
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Waiting for write_buf_time=%d ms\n", timeoutMS);
+#endif
+ }
+
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Waiting for audio to get ready\n");
+#endif
+ if (SDL_IOReady(this->hidden->audio_fd, SDL_TRUE, timeoutMS) <= 0) {
+ /*
+ * In general we should never print to the screen,
+ * but in this case we have no other way of letting
+ * the user know what happened.
+ */
+ fprintf(stderr, "SDL: %s - Audio timeout - buggy audio driver? (disabled)\n", strerror(errno));
+ SDL_OpenedAudioDeviceDisconnected(this);
+ /* Don't try to close - may hang */
+ this->hidden->audio_fd = -1;
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Done disabling audio\n");
+#endif
+ }
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Ready!\n");
+#endif
+ }
+}
+
+static void
+PAUDIO_PlayDevice(_THIS)
+{
+ int written = 0;
+ const Uint8 *mixbuf = this->hidden->mixbuf;
+ const size_t mixlen = this->hidden->mixlen;
+
+ /* Write the audio data, checking for EAGAIN on broken audio drivers */
+ do {
+ written = write(this->hidden->audio_fd, mixbuf, mixlen);
+ if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) {
+ SDL_Delay(1); /* Let a little CPU time go by */
+ }
+ } while ((written < 0) &&
+ ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
+
+ /* If timer synchronization is enabled, set the next write frame */
+ if (this->hidden->frame_ticks) {
+ this->hidden->next_frame += this->hidden->frame_ticks;
+ }
+
+ /* If we couldn't write, assume fatal error for now */
+ if (written < 0) {
+ SDL_OpenedAudioDeviceDisconnected(this);
+ }
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Wrote %d bytes of audio data\n", written);
+#endif
+}
+
+static Uint8 *
+PAUDIO_GetDeviceBuf(_THIS)
+{
+ return this->hidden->mixbuf;
+}
+
+static void
+PAUDIO_CloseDevice(_THIS)
+{
+ if (this->hidden->audio_fd >= 0) {
+ close(this->hidden->audio_fd);
+ }
+ SDL_free(this->hidden->mixbuf);
+ SDL_free(this->hidden);
+}
+
+static int
+PAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ const char *workaround = SDL_getenv("SDL_DSP_NOSELECT");
+ char audiodev[1024];
+ const char *err = NULL;
+ int format;
+ int bytes_per_sample;
+ SDL_AudioFormat test_format;
+ audio_init paud_init;
+ audio_buffer paud_bufinfo;
+ audio_control paud_control;
+ audio_change paud_change;
+ int fd = -1;
+
+ /* Initialize all variables that we clean on shutdown */
+ this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc((sizeof *this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(this->hidden);
+
+ /* Open the audio device */
+ fd = OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
+ this->hidden->audio_fd = fd;
+ if (fd < 0) {
+ return SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
+ }
+
+ /*
+ * We can't set the buffer size - just ask the device for the maximum
+ * that we can have.
+ */
+ if (ioctl(fd, AUDIO_BUFFER, &paud_bufinfo) < 0) {
+ return SDL_SetError("Couldn't get audio buffer information");
+ }
+
+ if (this->spec.channels > 1)
+ this->spec.channels = 2;
+ else
+ this->spec.channels = 1;
+
+ /*
+ * Fields in the audio_init structure:
+ *
+ * Ignored by us:
+ *
+ * paud.loadpath[LOAD_PATH]; * DSP code to load, MWave chip only?
+ * paud.slot_number; * slot number of the adapter
+ * paud.device_id; * adapter identification number
+ *
+ * Input:
+ *
+ * paud.srate; * the sampling rate in Hz
+ * paud.bits_per_sample; * 8, 16, 32, ...
+ * paud.bsize; * block size for this rate
+ * paud.mode; * ADPCM, PCM, MU_LAW, A_LAW, SOURCE_MIX
+ * paud.channels; * 1=mono, 2=stereo
+ * paud.flags; * FIXED - fixed length data
+ * * LEFT_ALIGNED, RIGHT_ALIGNED (var len only)
+ * * TWOS_COMPLEMENT - 2's complement data
+ * * SIGNED - signed? comment seems wrong in sys/audio.h
+ * * BIG_ENDIAN
+ * paud.operation; * PLAY, RECORD
+ *
+ * Output:
+ *
+ * paud.flags; * PITCH - pitch is supported
+ * * INPUT - input is supported
+ * * OUTPUT - output is supported
+ * * MONITOR - monitor is supported
+ * * VOLUME - volume is supported
+ * * VOLUME_DELAY - volume delay is supported
+ * * BALANCE - balance is supported
+ * * BALANCE_DELAY - balance delay is supported
+ * * TREBLE - treble control is supported
+ * * BASS - bass control is supported
+ * * BESTFIT_PROVIDED - best fit returned
+ * * LOAD_CODE - DSP load needed
+ * paud.rc; * NO_PLAY - DSP code can't do play requests
+ * * NO_RECORD - DSP code can't do record requests
+ * * INVALID_REQUEST - request was invalid
+ * * CONFLICT - conflict with open's flags
+ * * OVERLOADED - out of DSP MIPS or memory
+ * paud.position_resolution; * smallest increment for position
+ */
+
+ paud_init.srate = this->spec.freq;
+ paud_init.mode = PCM;
+ paud_init.operation = PLAY;
+ paud_init.channels = this->spec.channels;
+
+ /* Try for a closest match on audio format */
+ format = 0;
+ for (test_format = SDL_FirstAudioFormat(this->spec.format);
+ !format && test_format;) {
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
+#endif
+ switch (test_format) {
+ case AUDIO_U8:
+ bytes_per_sample = 1;
+ paud_init.bits_per_sample = 8;
+ paud_init.flags = TWOS_COMPLEMENT | FIXED;
+ format = 1;
+ break;
+ case AUDIO_S8:
+ bytes_per_sample = 1;
+ paud_init.bits_per_sample = 8;
+ paud_init.flags = SIGNED | TWOS_COMPLEMENT | FIXED;
+ format = 1;
+ break;
+ case AUDIO_S16LSB:
+ bytes_per_sample = 2;
+ paud_init.bits_per_sample = 16;
+ paud_init.flags = SIGNED | TWOS_COMPLEMENT | FIXED;
+ format = 1;
+ break;
+ case AUDIO_S16MSB:
+ bytes_per_sample = 2;
+ paud_init.bits_per_sample = 16;
+ paud_init.flags = BIG_ENDIAN | SIGNED | TWOS_COMPLEMENT | FIXED;
+ format = 1;
+ break;
+ case AUDIO_U16LSB:
+ bytes_per_sample = 2;
+ paud_init.bits_per_sample = 16;
+ paud_init.flags = TWOS_COMPLEMENT | FIXED;
+ format = 1;
+ break;
+ case AUDIO_U16MSB:
+ bytes_per_sample = 2;
+ paud_init.bits_per_sample = 16;
+ paud_init.flags = BIG_ENDIAN | TWOS_COMPLEMENT | FIXED;
+ format = 1;
+ break;
+ default:
+ break;
+ }
+ if (!format) {
+ test_format = SDL_NextAudioFormat();
+ }
+ }
+ if (format == 0) {
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Couldn't find any hardware audio formats\n");
+#endif
+ return SDL_SetError("Couldn't find any hardware audio formats");
+ }
+ this->spec.format = test_format;
+
+ /*
+ * We know the buffer size and the max number of subsequent writes
+ * that can be pending. If more than one can pend, allow the application
+ * to do something like double buffering between our write buffer and
+ * the device's own buffer that we are filling with write() anyway.
+ *
+ * We calculate this->spec.samples like this because
+ * SDL_CalculateAudioSpec() will give put paud_bufinfo.write_buf_cap
+ * (or paud_bufinfo.write_buf_cap/2) into this->spec.size in return.
+ */
+ if (paud_bufinfo.request_buf_cap == 1) {
+ this->spec.samples = paud_bufinfo.write_buf_cap
+ / bytes_per_sample / this->spec.channels;
+ } else {
+ this->spec.samples = paud_bufinfo.write_buf_cap
+ / bytes_per_sample / this->spec.channels / 2;
+ }
+ paud_init.bsize = bytes_per_sample * this->spec.channels;
+
+ SDL_CalculateAudioSpec(&this->spec);
+
+ /*
+ * The AIX paud device init can't modify the values of the audio_init
+ * structure that we pass to it. So we don't need any recalculation
+ * of this stuff and no reinit call as in linux dsp code.
+ *
+ * /dev/paud supports all of the encoding formats, so we don't need
+ * to do anything like reopening the device, either.
+ */
+ if (ioctl(fd, AUDIO_INIT, &paud_init) < 0) {
+ switch (paud_init.rc) {
+ case 1:
+ err = "Couldn't set audio format: DSP can't do play requests";
+ break;
+ case 2:
+ err = "Couldn't set audio format: DSP can't do record requests";
+ break;
+ case 4:
+ err = "Couldn't set audio format: request was invalid";
+ break;
+ case 5:
+ err = "Couldn't set audio format: conflict with open's flags";
+ break;
+ case 6:
+ err = "Couldn't set audio format: out of DSP MIPS or memory";
+ break;
+ default:
+ err = "Couldn't set audio format: not documented in sys/audio.h";
+ break;
+ }
+ }
+
+ if (err != NULL) {
+ return SDL_SetError("Paudio: %s", err);
+ }
+
+ /* Allocate mixing buffer */
+ this->hidden->mixlen = this->spec.size;
+ this->hidden->mixbuf = (Uint8 *) SDL_malloc(this->hidden->mixlen);
+ if (this->hidden->mixbuf == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
+
+ /*
+ * Set some paramters: full volume, first speaker that we can find.
+ * Ignore the other settings for now.
+ */
+ paud_change.input = AUDIO_IGNORE; /* the new input source */
+ paud_change.output = OUTPUT_1; /* EXTERNAL_SPEAKER,INTERNAL_SPEAKER,OUTPUT_1 */
+ paud_change.monitor = AUDIO_IGNORE; /* the new monitor state */
+ paud_change.volume = 0x7fffffff; /* volume level [0-0x7fffffff] */
+ paud_change.volume_delay = AUDIO_IGNORE; /* the new volume delay */
+ paud_change.balance = 0x3fffffff; /* the new balance */
+ paud_change.balance_delay = AUDIO_IGNORE; /* the new balance delay */
+ paud_change.treble = AUDIO_IGNORE; /* the new treble state */
+ paud_change.bass = AUDIO_IGNORE; /* the new bass state */
+ paud_change.pitch = AUDIO_IGNORE; /* the new pitch state */
+
+ paud_control.ioctl_request = AUDIO_CHANGE;
+ paud_control.request_info = (char *) &paud_change;
+ if (ioctl(fd, AUDIO_CONTROL, &paud_control) < 0) {
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Can't change audio display settings\n");
+#endif
+ }
+
+ /*
+ * Tell the device to expect data. Actual start will wait for
+ * the first write() call.
+ */
+ paud_control.ioctl_request = AUDIO_START;
+ paud_control.position = 0;
+ if (ioctl(fd, AUDIO_CONTROL, &paud_control) < 0) {
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Can't start audio play\n");
+#endif
+ return SDL_SetError("Can't start audio play");
+ }
+
+ /* Check to see if we need to use SDL_IOReady() workaround */
+ if (workaround != NULL) {
+ this->hidden->frame_ticks = (float) (this->spec.samples * 1000) /
+ this->spec.freq;
+ this->hidden->next_frame = SDL_GetTicks() + this->hidden->frame_ticks;
+ }
+
+ /* We're ready to rock and roll. :-) */
+ return 0;
+}
+
+static int
+PAUDIO_Init(SDL_AudioDriverImpl * impl)
+{
+ /* !!! FIXME: not right for device enum? */
+ int fd = OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
+ if (fd < 0) {
+ SDL_SetError("PAUDIO: Couldn't open audio device");
+ return 0;
+ }
+ close(fd);
+
+ /* Set the function pointers */
+ impl->OpenDevice = PAUDIO_OpenDevice;
+ impl->PlayDevice = PAUDIO_PlayDevice;
+ impl->PlayDevice = PAUDIO_WaitDevice;
+ impl->GetDeviceBuf = PAUDIO_GetDeviceBuf;
+ impl->CloseDevice = PAUDIO_CloseDevice;
+ impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: add device enum! */
+
+ return 1; /* this audio target is available. */
+}
+
+AudioBootStrap PAUDIO_bootstrap = {
+ "paud", "AIX Paudio", PAUDIO_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_PAUDIO */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/paudio/SDL_paudio.h b/src/3rdparty/SDL2/src/audio/paudio/SDL_paudio.h
new file mode 100644
index 0000000..c295ae4
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/paudio/SDL_paudio.h
@@ -0,0 +1,48 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_paudio_h_
+#define SDL_paudio_h_
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData
+{
+ /* The file descriptor for the audio device */
+ int audio_fd;
+
+ /* Raw mixing buffer */
+ Uint8 *mixbuf;
+ int mixlen;
+
+ /* Support for audio timing using a timer, in addition to SDL_IOReady() */
+ float frame_ticks;
+ float next_frame;
+};
+#define FUDGE_TICKS 10 /* The scheduler overhead ticks per frame */
+
+#endif /* SDL_paudio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/psp/SDL_pspaudio.c b/src/3rdparty/SDL2/src/audio/psp/SDL_pspaudio.c
new file mode 100644
index 0000000..3e7b8e1
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/psp/SDL_pspaudio.c
@@ -0,0 +1,181 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_PSP
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <malloc.h>
+
+#include "SDL_audio.h"
+#include "SDL_error.h"
+#include "SDL_timer.h"
+#include "../SDL_audio_c.h"
+#include "../SDL_audiodev_c.h"
+#include "../SDL_sysaudio.h"
+#include "SDL_pspaudio.h"
+
+#include <pspaudio.h>
+#include <pspthreadman.h>
+
+/* The tag name used by PSP audio */
+#define PSPAUDIO_DRIVER_NAME "psp"
+
+static int
+PSPAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ int format, mixlen, i;
+ this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc(sizeof(*this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(this->hidden);
+ switch (this->spec.format & 0xff) {
+ case 8:
+ case 16:
+ this->spec.format = AUDIO_S16LSB;
+ break;
+ default:
+ return SDL_SetError("Unsupported audio format");
+ }
+
+ /* The sample count must be a multiple of 64. */
+ this->spec.samples = PSP_AUDIO_SAMPLE_ALIGN(this->spec.samples);
+ this->spec.freq = 44100;
+
+ /* Update the fragment size as size in bytes. */
+ SDL_CalculateAudioSpec(&this->spec);
+
+ /* Allocate the mixing buffer. Its size and starting address must
+ be a multiple of 64 bytes. Our sample count is already a multiple of
+ 64, so spec->size should be a multiple of 64 as well. */
+ mixlen = this->spec.size * NUM_BUFFERS;
+ this->hidden->rawbuf = (Uint8 *) memalign(64, mixlen);
+ if (this->hidden->rawbuf == NULL) {
+ return SDL_SetError("Couldn't allocate mixing buffer");
+ }
+
+ /* Setup the hardware channel. */
+ if (this->spec.channels == 1) {
+ format = PSP_AUDIO_FORMAT_MONO;
+ } else {
+ this->spec.channels = 2;
+ format = PSP_AUDIO_FORMAT_STEREO;
+ }
+ this->hidden->channel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, this->spec.samples, format);
+ if (this->hidden->channel < 0) {
+ free(this->hidden->rawbuf);
+ this->hidden->rawbuf = NULL;
+ return SDL_SetError("Couldn't reserve hardware channel");
+ }
+
+ memset(this->hidden->rawbuf, 0, mixlen);
+ for (i = 0; i < NUM_BUFFERS; i++) {
+ this->hidden->mixbufs[i] = &this->hidden->rawbuf[i * this->spec.size];
+ }
+
+ this->hidden->next_buffer = 0;
+ return 0;
+}
+
+static void PSPAUDIO_PlayDevice(_THIS)
+{
+ Uint8 *mixbuf = this->hidden->mixbufs[this->hidden->next_buffer];
+
+ if (this->spec.channels == 1) {
+ sceAudioOutputBlocking(this->hidden->channel, PSP_AUDIO_VOLUME_MAX, mixbuf);
+ } else {
+ sceAudioOutputPannedBlocking(this->hidden->channel, PSP_AUDIO_VOLUME_MAX, PSP_AUDIO_VOLUME_MAX, mixbuf);
+ }
+
+ this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS;
+}
+
+/* This function waits until it is possible to write a full sound buffer */
+static void PSPAUDIO_WaitDevice(_THIS)
+{
+ /* Because we block when sending audio, there's no need for this function to do anything. */
+}
+static Uint8 *PSPAUDIO_GetDeviceBuf(_THIS)
+{
+ return this->hidden->mixbufs[this->hidden->next_buffer];
+}
+
+static void PSPAUDIO_CloseDevice(_THIS)
+{
+ if (this->hidden->channel >= 0) {
+ sceAudioChRelease(this->hidden->channel);
+ }
+ free(this->hidden->rawbuf); /* this uses memalign(), not SDL_malloc(). */
+ SDL_free(this->hidden);
+}
+
+static void PSPAUDIO_ThreadInit(_THIS)
+{
+ /* Increase the priority of this audio thread by 1 to put it
+ ahead of other SDL threads. */
+ SceUID thid;
+ SceKernelThreadInfo status;
+ thid = sceKernelGetThreadId();
+ status.size = sizeof(SceKernelThreadInfo);
+ if (sceKernelReferThreadStatus(thid, &status) == 0) {
+ sceKernelChangeThreadPriority(thid, status.currentPriority - 1);
+ }
+}
+
+
+static int
+PSPAUDIO_Init(SDL_AudioDriverImpl * impl)
+{
+ /* Set the function pointers */
+ impl->OpenDevice = PSPAUDIO_OpenDevice;
+ impl->PlayDevice = PSPAUDIO_PlayDevice;
+ impl->WaitDevice = PSPAUDIO_WaitDevice;
+ impl->GetDeviceBuf = PSPAUDIO_GetDeviceBuf;
+ impl->CloseDevice = PSPAUDIO_CloseDevice;
+ impl->ThreadInit = PSPAUDIO_ThreadInit;
+
+ /* PSP audio device */
+ impl->OnlyHasDefaultOutputDevice = 1;
+/*
+ impl->HasCaptureSupport = 1;
+
+ impl->OnlyHasDefaultCaptureDevice = 1;
+*/
+ /*
+ impl->DetectDevices = DSOUND_DetectDevices;
+ impl->Deinitialize = DSOUND_Deinitialize;
+ */
+ return 1; /* this audio target is available. */
+}
+
+AudioBootStrap PSPAUDIO_bootstrap = {
+ "psp", "PSP audio driver", PSPAUDIO_Init, 0
+};
+
+ /* SDL_AUDI */
+
+#endif /* SDL_AUDIO_DRIVER_PSP */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/psp/SDL_pspaudio.h b/src/3rdparty/SDL2/src/audio/psp/SDL_pspaudio.h
new file mode 100644
index 0000000..3f0cdc1
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/psp/SDL_pspaudio.h
@@ -0,0 +1,45 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_pspaudio_h_
+#define SDL_pspaudio_h_
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+#define NUM_BUFFERS 2
+
+struct SDL_PrivateAudioData {
+ /* The hardware output channel. */
+ int channel;
+ /* The raw allocated mixing buffer. */
+ Uint8 *rawbuf;
+ /* Individual mixing buffers. */
+ Uint8 *mixbufs[NUM_BUFFERS];
+ /* Index of the next available mixing buffer. */
+ int next_buffer;
+};
+
+#endif /* SDL_pspaudio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/pulseaudio/SDL_pulseaudio.c b/src/3rdparty/SDL2/src/audio/pulseaudio/SDL_pulseaudio.c
new file mode 100644
index 0000000..1e98580
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/pulseaudio/SDL_pulseaudio.c
@@ -0,0 +1,782 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ The PulseAudio target for SDL 1.3 is based on the 1.3 arts target, with
+ the appropriate parts replaced with the 1.2 PulseAudio target code. This
+ was the cleanest way to move it to 1.3. The 1.2 target was written by
+ Stéphan Kochen: stephan .a.t. kochen.nl
+*/
+#include "../../SDL_internal.h"
+#include "SDL_assert.h"
+
+#if SDL_AUDIO_DRIVER_PULSEAUDIO
+
+/* Allow access to a raw mixing buffer */
+
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
+#include <unistd.h>
+#include <sys/types.h>
+#include <pulse/pulseaudio.h>
+
+#include "SDL_timer.h"
+#include "SDL_audio.h"
+#include "../SDL_audio_c.h"
+#include "SDL_pulseaudio.h"
+#include "SDL_loadso.h"
+#include "../../thread/SDL_systhread.h"
+
+#if (PA_API_VERSION < 12)
+/** Return non-zero if the passed state is one of the connected states */
+static SDL_INLINE int PA_CONTEXT_IS_GOOD(pa_context_state_t x) {
+ return
+ x == PA_CONTEXT_CONNECTING ||
+ x == PA_CONTEXT_AUTHORIZING ||
+ x == PA_CONTEXT_SETTING_NAME ||
+ x == PA_CONTEXT_READY;
+}
+/** Return non-zero if the passed state is one of the connected states */
+static SDL_INLINE int PA_STREAM_IS_GOOD(pa_stream_state_t x) {
+ return
+ x == PA_STREAM_CREATING ||
+ x == PA_STREAM_READY;
+}
+#endif /* pulseaudio <= 0.9.10 */
+
+
+static const char *(*PULSEAUDIO_pa_get_library_version) (void);
+static pa_channel_map *(*PULSEAUDIO_pa_channel_map_init_auto) (
+ pa_channel_map *, unsigned, pa_channel_map_def_t);
+static const char * (*PULSEAUDIO_pa_strerror) (int);
+static pa_mainloop * (*PULSEAUDIO_pa_mainloop_new) (void);
+static pa_mainloop_api * (*PULSEAUDIO_pa_mainloop_get_api) (pa_mainloop *);
+static int (*PULSEAUDIO_pa_mainloop_iterate) (pa_mainloop *, int, int *);
+static int (*PULSEAUDIO_pa_mainloop_run) (pa_mainloop *, int *);
+static void (*PULSEAUDIO_pa_mainloop_quit) (pa_mainloop *, int);
+static void (*PULSEAUDIO_pa_mainloop_free) (pa_mainloop *);
+
+static pa_operation_state_t (*PULSEAUDIO_pa_operation_get_state) (
+ pa_operation *);
+static void (*PULSEAUDIO_pa_operation_cancel) (pa_operation *);
+static void (*PULSEAUDIO_pa_operation_unref) (pa_operation *);
+
+static pa_context * (*PULSEAUDIO_pa_context_new) (pa_mainloop_api *,
+ const char *);
+static int (*PULSEAUDIO_pa_context_connect) (pa_context *, const char *,
+ pa_context_flags_t, const pa_spawn_api *);
+static pa_operation * (*PULSEAUDIO_pa_context_get_sink_info_list) (pa_context *, pa_sink_info_cb_t, void *);
+static pa_operation * (*PULSEAUDIO_pa_context_get_source_info_list) (pa_context *, pa_source_info_cb_t, void *);
+static pa_operation * (*PULSEAUDIO_pa_context_get_sink_info_by_index) (pa_context *, uint32_t, pa_sink_info_cb_t, void *);
+static pa_operation * (*PULSEAUDIO_pa_context_get_source_info_by_index) (pa_context *, uint32_t, pa_source_info_cb_t, void *);
+static pa_context_state_t (*PULSEAUDIO_pa_context_get_state) (pa_context *);
+static pa_operation * (*PULSEAUDIO_pa_context_subscribe) (pa_context *, pa_subscription_mask_t, pa_context_success_cb_t, void *);
+static void (*PULSEAUDIO_pa_context_set_subscribe_callback) (pa_context *, pa_context_subscribe_cb_t, void *);
+static void (*PULSEAUDIO_pa_context_disconnect) (pa_context *);
+static void (*PULSEAUDIO_pa_context_unref) (pa_context *);
+
+static pa_stream * (*PULSEAUDIO_pa_stream_new) (pa_context *, const char *,
+ const pa_sample_spec *, const pa_channel_map *);
+static int (*PULSEAUDIO_pa_stream_connect_playback) (pa_stream *, const char *,
+ const pa_buffer_attr *, pa_stream_flags_t, pa_cvolume *, pa_stream *);
+static int (*PULSEAUDIO_pa_stream_connect_record) (pa_stream *, const char *,
+ const pa_buffer_attr *, pa_stream_flags_t);
+static pa_stream_state_t (*PULSEAUDIO_pa_stream_get_state) (pa_stream *);
+static size_t (*PULSEAUDIO_pa_stream_writable_size) (pa_stream *);
+static size_t (*PULSEAUDIO_pa_stream_readable_size) (pa_stream *);
+static int (*PULSEAUDIO_pa_stream_write) (pa_stream *, const void *, size_t,
+ pa_free_cb_t, int64_t, pa_seek_mode_t);
+static pa_operation * (*PULSEAUDIO_pa_stream_drain) (pa_stream *,
+ pa_stream_success_cb_t, void *);
+static int (*PULSEAUDIO_pa_stream_peek) (pa_stream *, const void **, size_t *);
+static int (*PULSEAUDIO_pa_stream_drop) (pa_stream *);
+static pa_operation * (*PULSEAUDIO_pa_stream_flush) (pa_stream *,
+ pa_stream_success_cb_t, void *);
+static int (*PULSEAUDIO_pa_stream_disconnect) (pa_stream *);
+static void (*PULSEAUDIO_pa_stream_unref) (pa_stream *);
+
+static int load_pulseaudio_syms(void);
+
+
+#ifdef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC
+
+static const char *pulseaudio_library = SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC;
+static void *pulseaudio_handle = NULL;
+
+static int
+load_pulseaudio_sym(const char *fn, void **addr)
+{
+ *addr = SDL_LoadFunction(pulseaudio_handle, fn);
+ if (*addr == NULL) {
+ /* Don't call SDL_SetError(): SDL_LoadFunction already did. */
+ return 0;
+ }
+
+ return 1;
+}
+
+/* cast funcs to char* first, to please GCC's strict aliasing rules. */
+#define SDL_PULSEAUDIO_SYM(x) \
+ if (!load_pulseaudio_sym(#x, (void **) (char *) &PULSEAUDIO_##x)) return -1
+
+static void
+UnloadPulseAudioLibrary(void)
+{
+ if (pulseaudio_handle != NULL) {
+ SDL_UnloadObject(pulseaudio_handle);
+ pulseaudio_handle = NULL;
+ }
+}
+
+static int
+LoadPulseAudioLibrary(void)
+{
+ int retval = 0;
+ if (pulseaudio_handle == NULL) {
+ pulseaudio_handle = SDL_LoadObject(pulseaudio_library);
+ if (pulseaudio_handle == NULL) {
+ retval = -1;
+ /* Don't call SDL_SetError(): SDL_LoadObject already did. */
+ } else {
+ retval = load_pulseaudio_syms();
+ if (retval < 0) {
+ UnloadPulseAudioLibrary();
+ }
+ }
+ }
+ return retval;
+}
+
+#else
+
+#define SDL_PULSEAUDIO_SYM(x) PULSEAUDIO_##x = x
+
+static void
+UnloadPulseAudioLibrary(void)
+{
+}
+
+static int
+LoadPulseAudioLibrary(void)
+{
+ load_pulseaudio_syms();
+ return 0;
+}
+
+#endif /* SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC */
+
+
+static int
+load_pulseaudio_syms(void)
+{
+ SDL_PULSEAUDIO_SYM(pa_get_library_version);
+ SDL_PULSEAUDIO_SYM(pa_mainloop_new);
+ SDL_PULSEAUDIO_SYM(pa_mainloop_get_api);
+ SDL_PULSEAUDIO_SYM(pa_mainloop_iterate);
+ SDL_PULSEAUDIO_SYM(pa_mainloop_run);
+ SDL_PULSEAUDIO_SYM(pa_mainloop_quit);
+ SDL_PULSEAUDIO_SYM(pa_mainloop_free);
+ SDL_PULSEAUDIO_SYM(pa_operation_get_state);
+ SDL_PULSEAUDIO_SYM(pa_operation_cancel);
+ SDL_PULSEAUDIO_SYM(pa_operation_unref);
+ SDL_PULSEAUDIO_SYM(pa_context_new);
+ SDL_PULSEAUDIO_SYM(pa_context_connect);
+ SDL_PULSEAUDIO_SYM(pa_context_get_sink_info_list);
+ SDL_PULSEAUDIO_SYM(pa_context_get_source_info_list);
+ SDL_PULSEAUDIO_SYM(pa_context_get_sink_info_by_index);
+ SDL_PULSEAUDIO_SYM(pa_context_get_source_info_by_index);
+ SDL_PULSEAUDIO_SYM(pa_context_get_state);
+ SDL_PULSEAUDIO_SYM(pa_context_subscribe);
+ SDL_PULSEAUDIO_SYM(pa_context_set_subscribe_callback);
+ SDL_PULSEAUDIO_SYM(pa_context_disconnect);
+ SDL_PULSEAUDIO_SYM(pa_context_unref);
+ SDL_PULSEAUDIO_SYM(pa_stream_new);
+ SDL_PULSEAUDIO_SYM(pa_stream_connect_playback);
+ SDL_PULSEAUDIO_SYM(pa_stream_connect_record);
+ SDL_PULSEAUDIO_SYM(pa_stream_get_state);
+ SDL_PULSEAUDIO_SYM(pa_stream_writable_size);
+ SDL_PULSEAUDIO_SYM(pa_stream_readable_size);
+ SDL_PULSEAUDIO_SYM(pa_stream_write);
+ SDL_PULSEAUDIO_SYM(pa_stream_drain);
+ SDL_PULSEAUDIO_SYM(pa_stream_disconnect);
+ SDL_PULSEAUDIO_SYM(pa_stream_peek);
+ SDL_PULSEAUDIO_SYM(pa_stream_drop);
+ SDL_PULSEAUDIO_SYM(pa_stream_flush);
+ SDL_PULSEAUDIO_SYM(pa_stream_unref);
+ SDL_PULSEAUDIO_SYM(pa_channel_map_init_auto);
+ SDL_PULSEAUDIO_SYM(pa_strerror);
+ return 0;
+}
+
+static SDL_INLINE int
+squashVersion(const int major, const int minor, const int patch)
+{
+ return ((major & 0xFF) << 16) | ((minor & 0xFF) << 8) | (patch & 0xFF);
+}
+
+/* Workaround for older pulse: pa_context_new() must have non-NULL appname */
+static const char *
+getAppName(void)
+{
+ const char *verstr = PULSEAUDIO_pa_get_library_version();
+ if (verstr != NULL) {
+ int maj, min, patch;
+ if (SDL_sscanf(verstr, "%d.%d.%d", &maj, &min, &patch) == 3) {
+ if (squashVersion(maj, min, patch) >= squashVersion(0, 9, 15)) {
+ return NULL; /* 0.9.15+ handles NULL correctly. */
+ }
+ }
+ }
+ return "SDL Application"; /* oh well. */
+}
+
+static void
+WaitForPulseOperation(pa_mainloop *mainloop, pa_operation *o)
+{
+ /* This checks for NO errors currently. Either fix that, check results elsewhere, or do things you don't care about. */
+ if (mainloop && o) {
+ SDL_bool okay = SDL_TRUE;
+ while (okay && (PULSEAUDIO_pa_operation_get_state(o) == PA_OPERATION_RUNNING)) {
+ okay = (PULSEAUDIO_pa_mainloop_iterate(mainloop, 1, NULL) >= 0);
+ }
+ PULSEAUDIO_pa_operation_unref(o);
+ }
+}
+
+static void
+DisconnectFromPulseServer(pa_mainloop *mainloop, pa_context *context)
+{
+ if (context) {
+ PULSEAUDIO_pa_context_disconnect(context);
+ PULSEAUDIO_pa_context_unref(context);
+ }
+ if (mainloop != NULL) {
+ PULSEAUDIO_pa_mainloop_free(mainloop);
+ }
+}
+
+static int
+ConnectToPulseServer_Internal(pa_mainloop **_mainloop, pa_context **_context)
+{
+ pa_mainloop *mainloop = NULL;
+ pa_context *context = NULL;
+ pa_mainloop_api *mainloop_api = NULL;
+ int state = 0;
+
+ *_mainloop = NULL;
+ *_context = NULL;
+
+ /* Set up a new main loop */
+ if (!(mainloop = PULSEAUDIO_pa_mainloop_new())) {
+ return SDL_SetError("pa_mainloop_new() failed");
+ }
+
+ *_mainloop = mainloop;
+
+ mainloop_api = PULSEAUDIO_pa_mainloop_get_api(mainloop);
+ SDL_assert(mainloop_api); /* this never fails, right? */
+
+ context = PULSEAUDIO_pa_context_new(mainloop_api, getAppName());
+ if (!context) {
+ return SDL_SetError("pa_context_new() failed");
+ }
+ *_context = context;
+
+ /* Connect to the PulseAudio server */
+ if (PULSEAUDIO_pa_context_connect(context, NULL, 0, NULL) < 0) {
+ return SDL_SetError("Could not setup connection to PulseAudio");
+ }
+
+ do {
+ if (PULSEAUDIO_pa_mainloop_iterate(mainloop, 1, NULL) < 0) {
+ return SDL_SetError("pa_mainloop_iterate() failed");
+ }
+ state = PULSEAUDIO_pa_context_get_state(context);
+ if (!PA_CONTEXT_IS_GOOD(state)) {
+ return SDL_SetError("Could not connect to PulseAudio");
+ }
+ } while (state != PA_CONTEXT_READY);
+
+ return 0; /* connected and ready! */
+}
+
+static int
+ConnectToPulseServer(pa_mainloop **_mainloop, pa_context **_context)
+{
+ const int retval = ConnectToPulseServer_Internal(_mainloop, _context);
+ if (retval < 0) {
+ DisconnectFromPulseServer(*_mainloop, *_context);
+ }
+ return retval;
+}
+
+
+/* This function waits until it is possible to write a full sound buffer */
+static void
+PULSEAUDIO_WaitDevice(_THIS)
+{
+ struct SDL_PrivateAudioData *h = this->hidden;
+
+ while (SDL_AtomicGet(&this->enabled)) {
+ if (PULSEAUDIO_pa_context_get_state(h->context) != PA_CONTEXT_READY ||
+ PULSEAUDIO_pa_stream_get_state(h->stream) != PA_STREAM_READY ||
+ PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) {
+ SDL_OpenedAudioDeviceDisconnected(this);
+ return;
+ }
+ if (PULSEAUDIO_pa_stream_writable_size(h->stream) >= h->mixlen) {
+ return;
+ }
+ }
+}
+
+static void
+PULSEAUDIO_PlayDevice(_THIS)
+{
+ /* Write the audio data */
+ struct SDL_PrivateAudioData *h = this->hidden;
+ if (SDL_AtomicGet(&this->enabled)) {
+ if (PULSEAUDIO_pa_stream_write(h->stream, h->mixbuf, h->mixlen, NULL, 0LL, PA_SEEK_RELATIVE) < 0) {
+ SDL_OpenedAudioDeviceDisconnected(this);
+ }
+ }
+}
+
+static Uint8 *
+PULSEAUDIO_GetDeviceBuf(_THIS)
+{
+ return (this->hidden->mixbuf);
+}
+
+
+static int
+PULSEAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
+{
+ struct SDL_PrivateAudioData *h = this->hidden;
+ const void *data = NULL;
+ size_t nbytes = 0;
+
+ while (SDL_AtomicGet(&this->enabled)) {
+ if (h->capturebuf != NULL) {
+ const int cpy = SDL_min(buflen, h->capturelen);
+ SDL_memcpy(buffer, h->capturebuf, cpy);
+ /*printf("PULSEAUDIO: fed %d captured bytes\n", cpy);*/
+ h->capturebuf += cpy;
+ h->capturelen -= cpy;
+ if (h->capturelen == 0) {
+ h->capturebuf = NULL;
+ PULSEAUDIO_pa_stream_drop(h->stream); /* done with this fragment. */
+ }
+ return cpy; /* new data, return it. */
+ }
+
+ if (PULSEAUDIO_pa_context_get_state(h->context) != PA_CONTEXT_READY ||
+ PULSEAUDIO_pa_stream_get_state(h->stream) != PA_STREAM_READY ||
+ PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) {
+ SDL_OpenedAudioDeviceDisconnected(this);
+ return -1; /* uhoh, pulse failed! */
+ }
+
+ if (PULSEAUDIO_pa_stream_readable_size(h->stream) == 0) {
+ continue; /* no data available yet. */
+ }
+
+ /* a new fragment is available! */
+ PULSEAUDIO_pa_stream_peek(h->stream, &data, &nbytes);
+ SDL_assert(nbytes > 0);
+ if (data == NULL) { /* NULL==buffer had a hole. Ignore that. */
+ PULSEAUDIO_pa_stream_drop(h->stream); /* drop this fragment. */
+ } else {
+ /* store this fragment's data, start feeding it to SDL. */
+ /*printf("PULSEAUDIO: captured %d new bytes\n", (int) nbytes);*/
+ h->capturebuf = (const Uint8 *) data;
+ h->capturelen = nbytes;
+ }
+ }
+
+ return -1; /* not enabled? */
+}
+
+static void
+PULSEAUDIO_FlushCapture(_THIS)
+{
+ struct SDL_PrivateAudioData *h = this->hidden;
+ const void *data = NULL;
+ size_t nbytes = 0;
+
+ if (h->capturebuf != NULL) {
+ PULSEAUDIO_pa_stream_drop(h->stream);
+ h->capturebuf = NULL;
+ h->capturelen = 0;
+ }
+
+ while (SDL_TRUE) {
+ if (PULSEAUDIO_pa_context_get_state(h->context) != PA_CONTEXT_READY ||
+ PULSEAUDIO_pa_stream_get_state(h->stream) != PA_STREAM_READY ||
+ PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) {
+ SDL_OpenedAudioDeviceDisconnected(this);
+ return; /* uhoh, pulse failed! */
+ }
+
+ if (PULSEAUDIO_pa_stream_readable_size(h->stream) == 0) {
+ break; /* no data available, so we're done. */
+ }
+
+ /* a new fragment is available! Just dump it. */
+ PULSEAUDIO_pa_stream_peek(h->stream, &data, &nbytes);
+ PULSEAUDIO_pa_stream_drop(h->stream); /* drop this fragment. */
+ }
+}
+
+static void
+PULSEAUDIO_CloseDevice(_THIS)
+{
+ if (this->hidden->stream) {
+ if (this->hidden->capturebuf != NULL) {
+ PULSEAUDIO_pa_stream_drop(this->hidden->stream);
+ }
+ PULSEAUDIO_pa_stream_disconnect(this->hidden->stream);
+ PULSEAUDIO_pa_stream_unref(this->hidden->stream);
+ }
+
+ DisconnectFromPulseServer(this->hidden->mainloop, this->hidden->context);
+ SDL_free(this->hidden->mixbuf);
+ SDL_free(this->hidden->device_name);
+ SDL_free(this->hidden);
+}
+
+static void
+SinkDeviceNameCallback(pa_context *c, const pa_sink_info *i, int is_last, void *data)
+{
+ if (i) {
+ char **devname = (char **) data;
+ *devname = SDL_strdup(i->name);
+ }
+}
+
+static void
+SourceDeviceNameCallback(pa_context *c, const pa_source_info *i, int is_last, void *data)
+{
+ if (i) {
+ char **devname = (char **) data;
+ *devname = SDL_strdup(i->name);
+ }
+}
+
+static SDL_bool
+FindDeviceName(struct SDL_PrivateAudioData *h, const int iscapture, void *handle)
+{
+ const uint32_t idx = ((uint32_t) ((size_t) handle)) - 1;
+
+ if (handle == NULL) { /* NULL == default device. */
+ return SDL_TRUE;
+ }
+
+ if (iscapture) {
+ WaitForPulseOperation(h->mainloop,
+ PULSEAUDIO_pa_context_get_source_info_by_index(h->context, idx,
+ SourceDeviceNameCallback, &h->device_name));
+ } else {
+ WaitForPulseOperation(h->mainloop,
+ PULSEAUDIO_pa_context_get_sink_info_by_index(h->context, idx,
+ SinkDeviceNameCallback, &h->device_name));
+ }
+
+ return (h->device_name != NULL);
+}
+
+static int
+PULSEAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ struct SDL_PrivateAudioData *h = NULL;
+ Uint16 test_format = 0;
+ pa_sample_spec paspec;
+ pa_buffer_attr paattr;
+ pa_channel_map pacmap;
+ pa_stream_flags_t flags = 0;
+ int state = 0;
+ int rc = 0;
+
+ /* Initialize all variables that we clean on shutdown */
+ h = this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc((sizeof *this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(this->hidden);
+
+ paspec.format = PA_SAMPLE_INVALID;
+
+ /* Try for a closest match on audio format */
+ for (test_format = SDL_FirstAudioFormat(this->spec.format);
+ (paspec.format == PA_SAMPLE_INVALID) && test_format;) {
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Trying format 0x%4.4x\n", test_format);
+#endif
+ switch (test_format) {
+ case AUDIO_U8:
+ paspec.format = PA_SAMPLE_U8;
+ break;
+ case AUDIO_S16LSB:
+ paspec.format = PA_SAMPLE_S16LE;
+ break;
+ case AUDIO_S16MSB:
+ paspec.format = PA_SAMPLE_S16BE;
+ break;
+ case AUDIO_S32LSB:
+ paspec.format = PA_SAMPLE_S32LE;
+ break;
+ case AUDIO_S32MSB:
+ paspec.format = PA_SAMPLE_S32BE;
+ break;
+ case AUDIO_F32LSB:
+ paspec.format = PA_SAMPLE_FLOAT32LE;
+ break;
+ case AUDIO_F32MSB:
+ paspec.format = PA_SAMPLE_FLOAT32BE;
+ break;
+ default:
+ paspec.format = PA_SAMPLE_INVALID;
+ break;
+ }
+ if (paspec.format == PA_SAMPLE_INVALID) {
+ test_format = SDL_NextAudioFormat();
+ }
+ }
+ if (paspec.format == PA_SAMPLE_INVALID) {
+ return SDL_SetError("Couldn't find any hardware audio formats");
+ }
+ this->spec.format = test_format;
+
+ /* Calculate the final parameters for this audio specification */
+#ifdef PA_STREAM_ADJUST_LATENCY
+ this->spec.samples /= 2; /* Mix in smaller chunck to avoid underruns */
+#endif
+ SDL_CalculateAudioSpec(&this->spec);
+
+ /* Allocate mixing buffer */
+ if (!iscapture) {
+ h->mixlen = this->spec.size;
+ h->mixbuf = (Uint8 *) SDL_malloc(h->mixlen);
+ if (h->mixbuf == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(h->mixbuf, this->spec.silence, this->spec.size);
+ }
+
+ paspec.channels = this->spec.channels;
+ paspec.rate = this->spec.freq;
+
+ /* Reduced prebuffering compared to the defaults. */
+#ifdef PA_STREAM_ADJUST_LATENCY
+ /* 2x original requested bufsize */
+ paattr.tlength = h->mixlen * 4;
+ paattr.prebuf = -1;
+ paattr.maxlength = -1;
+ /* -1 can lead to pa_stream_writable_size() >= mixlen never being true */
+ paattr.minreq = h->mixlen;
+ flags = PA_STREAM_ADJUST_LATENCY;
+#else
+ paattr.tlength = h->mixlen*2;
+ paattr.prebuf = h->mixlen*2;
+ paattr.maxlength = h->mixlen*2;
+ paattr.minreq = h->mixlen;
+#endif
+
+ if (ConnectToPulseServer(&h->mainloop, &h->context) < 0) {
+ return SDL_SetError("Could not connect to PulseAudio server");
+ }
+
+ if (!FindDeviceName(h, iscapture, handle)) {
+ return SDL_SetError("Requested PulseAudio sink/source missing?");
+ }
+
+ /* The SDL ALSA output hints us that we use Windows' channel mapping */
+ /* http://bugzilla.libsdl.org/show_bug.cgi?id=110 */
+ PULSEAUDIO_pa_channel_map_init_auto(&pacmap, this->spec.channels,
+ PA_CHANNEL_MAP_WAVEEX);
+
+ h->stream = PULSEAUDIO_pa_stream_new(
+ h->context,
+ "Simple DirectMedia Layer", /* stream description */
+ &paspec, /* sample format spec */
+ &pacmap /* channel map */
+ );
+
+ if (h->stream == NULL) {
+ return SDL_SetError("Could not set up PulseAudio stream");
+ }
+
+ /* now that we have multi-device support, don't move a stream from
+ a device that was unplugged to something else, unless we're default. */
+ if (h->device_name != NULL) {
+ flags |= PA_STREAM_DONT_MOVE;
+ }
+
+ if (iscapture) {
+ rc = PULSEAUDIO_pa_stream_connect_record(h->stream, h->device_name, &paattr, flags);
+ } else {
+ rc = PULSEAUDIO_pa_stream_connect_playback(h->stream, h->device_name, &paattr, flags, NULL, NULL);
+ }
+
+ if (rc < 0) {
+ return SDL_SetError("Could not connect PulseAudio stream");
+ }
+
+ do {
+ if (PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) {
+ return SDL_SetError("pa_mainloop_iterate() failed");
+ }
+ state = PULSEAUDIO_pa_stream_get_state(h->stream);
+ if (!PA_STREAM_IS_GOOD(state)) {
+ return SDL_SetError("Could not connect PulseAudio stream");
+ }
+ } while (state != PA_STREAM_READY);
+
+ /* We're ready to rock and roll. :-) */
+ return 0;
+}
+
+static pa_mainloop *hotplug_mainloop = NULL;
+static pa_context *hotplug_context = NULL;
+static SDL_Thread *hotplug_thread = NULL;
+
+/* device handles are device index + 1, cast to void*, so we never pass a NULL. */
+
+/* This is called when PulseAudio adds an output ("sink") device. */
+static void
+SinkInfoCallback(pa_context *c, const pa_sink_info *i, int is_last, void *data)
+{
+ if (i) {
+ SDL_AddAudioDevice(SDL_FALSE, i->description, (void *) ((size_t) i->index+1));
+ }
+}
+
+/* This is called when PulseAudio adds a capture ("source") device. */
+static void
+SourceInfoCallback(pa_context *c, const pa_source_info *i, int is_last, void *data)
+{
+ if (i) {
+ /* Skip "monitor" sources. These are just output from other sinks. */
+ if (i->monitor_of_sink == PA_INVALID_INDEX) {
+ SDL_AddAudioDevice(SDL_TRUE, i->description, (void *) ((size_t) i->index+1));
+ }
+ }
+}
+
+/* This is called when PulseAudio has a device connected/removed/changed. */
+static void
+HotplugCallback(pa_context *c, pa_subscription_event_type_t t, uint32_t idx, void *data)
+{
+ const SDL_bool added = ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_NEW);
+ const SDL_bool removed = ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE);
+
+ if (added || removed) { /* we only care about add/remove events. */
+ const SDL_bool sink = ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SINK);
+ const SDL_bool source = ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SOURCE);
+
+ /* adds need sink details from the PulseAudio server. Another callback... */
+ if (added && sink) {
+ PULSEAUDIO_pa_context_get_sink_info_by_index(hotplug_context, idx, SinkInfoCallback, NULL);
+ } else if (added && source) {
+ PULSEAUDIO_pa_context_get_source_info_by_index(hotplug_context, idx, SourceInfoCallback, NULL);
+ } else if (removed && (sink || source)) {
+ /* removes we can handle just with the device index. */
+ SDL_RemoveAudioDevice(source != 0, (void *) ((size_t) idx+1));
+ }
+ }
+}
+
+/* this runs as a thread while the Pulse target is initialized to catch hotplug events. */
+static int SDLCALL
+HotplugThread(void *data)
+{
+ pa_operation *o;
+ SDL_SetThreadPriority(SDL_THREAD_PRIORITY_LOW);
+ PULSEAUDIO_pa_context_set_subscribe_callback(hotplug_context, HotplugCallback, NULL);
+ o = PULSEAUDIO_pa_context_subscribe(hotplug_context, PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_SOURCE, NULL, NULL);
+ PULSEAUDIO_pa_operation_unref(o); /* don't wait for it, just do our thing. */
+ PULSEAUDIO_pa_mainloop_run(hotplug_mainloop, NULL);
+ return 0;
+}
+
+static void
+PULSEAUDIO_DetectDevices()
+{
+ WaitForPulseOperation(hotplug_mainloop, PULSEAUDIO_pa_context_get_sink_info_list(hotplug_context, SinkInfoCallback, NULL));
+ WaitForPulseOperation(hotplug_mainloop, PULSEAUDIO_pa_context_get_source_info_list(hotplug_context, SourceInfoCallback, NULL));
+
+ /* ok, we have a sane list, let's set up hotplug notifications now... */
+ hotplug_thread = SDL_CreateThreadInternal(HotplugThread, "PulseHotplug", 256 * 1024, NULL);
+}
+
+static void
+PULSEAUDIO_Deinitialize(void)
+{
+ if (hotplug_thread) {
+ PULSEAUDIO_pa_mainloop_quit(hotplug_mainloop, 0);
+ SDL_WaitThread(hotplug_thread, NULL);
+ hotplug_thread = NULL;
+ }
+
+ DisconnectFromPulseServer(hotplug_mainloop, hotplug_context);
+ hotplug_mainloop = NULL;
+ hotplug_context = NULL;
+
+ UnloadPulseAudioLibrary();
+}
+
+static int
+PULSEAUDIO_Init(SDL_AudioDriverImpl * impl)
+{
+ if (LoadPulseAudioLibrary() < 0) {
+ return 0;
+ }
+
+ if (ConnectToPulseServer(&hotplug_mainloop, &hotplug_context) < 0) {
+ UnloadPulseAudioLibrary();
+ return 0;
+ }
+
+ /* Set the function pointers */
+ impl->DetectDevices = PULSEAUDIO_DetectDevices;
+ impl->OpenDevice = PULSEAUDIO_OpenDevice;
+ impl->PlayDevice = PULSEAUDIO_PlayDevice;
+ impl->WaitDevice = PULSEAUDIO_WaitDevice;
+ impl->GetDeviceBuf = PULSEAUDIO_GetDeviceBuf;
+ impl->CloseDevice = PULSEAUDIO_CloseDevice;
+ impl->Deinitialize = PULSEAUDIO_Deinitialize;
+ impl->CaptureFromDevice = PULSEAUDIO_CaptureFromDevice;
+ impl->FlushCapture = PULSEAUDIO_FlushCapture;
+
+ impl->HasCaptureSupport = SDL_TRUE;
+
+ return 1; /* this audio target is available. */
+}
+
+AudioBootStrap PULSEAUDIO_bootstrap = {
+ "pulseaudio", "PulseAudio", PULSEAUDIO_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_PULSEAUDIO */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/pulseaudio/SDL_pulseaudio.h b/src/3rdparty/SDL2/src/audio/pulseaudio/SDL_pulseaudio.h
new file mode 100644
index 0000000..61da70b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/pulseaudio/SDL_pulseaudio.h
@@ -0,0 +1,52 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_pulseaudio_h_
+#define SDL_pulseaudio_h_
+
+#include <pulse/simple.h>
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData
+{
+ char *device_name;
+
+ /* pulseaudio structures */
+ pa_mainloop *mainloop;
+ pa_context *context;
+ pa_stream *stream;
+
+ /* Raw mixing buffer */
+ Uint8 *mixbuf;
+ int mixlen;
+
+ const Uint8 *capturebuf;
+ int capturelen;
+};
+
+#endif /* SDL_pulseaudio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/qsa/SDL_qsa_audio.c b/src/3rdparty/SDL2/src/audio/qsa/SDL_qsa_audio.c
new file mode 100644
index 0000000..957ac2d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/qsa/SDL_qsa_audio.c
@@ -0,0 +1,666 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ * !!! FIXME: streamline this a little by removing all the
+ * !!! FIXME: if (capture) {} else {} sections that are identical
+ * !!! FIXME: except for one flag.
+ */
+
+/* !!! FIXME: can this target support hotplugging? */
+/* !!! FIXME: ...does SDL2 even support QNX? */
+
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_QSA
+
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sched.h>
+#include <sys/select.h>
+#include <sys/neutrino.h>
+#include <sys/asoundlib.h>
+
+#include "SDL_timer.h"
+#include "SDL_audio.h"
+#include "../../core/unix/SDL_poll.h"
+#include "../SDL_audio_c.h"
+#include "SDL_qsa_audio.h"
+
+/* default channel communication parameters */
+#define DEFAULT_CPARAMS_RATE 44100
+#define DEFAULT_CPARAMS_VOICES 1
+
+#define DEFAULT_CPARAMS_FRAG_SIZE 4096
+#define DEFAULT_CPARAMS_FRAGS_MIN 1
+#define DEFAULT_CPARAMS_FRAGS_MAX 1
+
+/* List of found devices */
+#define QSA_MAX_DEVICES 32
+#define QSA_MAX_NAME_LENGTH 81+16 /* Hardcoded in QSA, can't be changed */
+
+typedef struct _QSA_Device
+{
+ char name[QSA_MAX_NAME_LENGTH]; /* Long audio device name for SDL */
+ int cardno;
+ int deviceno;
+} QSA_Device;
+
+QSA_Device qsa_playback_device[QSA_MAX_DEVICES];
+uint32_t qsa_playback_devices;
+
+QSA_Device qsa_capture_device[QSA_MAX_DEVICES];
+uint32_t qsa_capture_devices;
+
+static SDL_INLINE int
+QSA_SetError(const char *fn, int status)
+{
+ return SDL_SetError("QSA: %s() failed: %s", fn, snd_strerror(status));
+}
+
+/* !!! FIXME: does this need to be here? Does the SDL version not work? */
+static void
+QSA_ThreadInit(_THIS)
+{
+ /* Increase default 10 priority to 25 to avoid jerky sound */
+ struct sched_param param;
+ if (SchedGet(0, 0, &param) != -1) {
+ param.sched_priority = param.sched_curpriority + 15;
+ SchedSet(0, 0, SCHED_NOCHANGE, &param);
+ }
+}
+
+/* PCM channel parameters initialize function */
+static void
+QSA_InitAudioParams(snd_pcm_channel_params_t * cpars)
+{
+ SDL_zerop(cpars);
+ cpars->channel = SND_PCM_CHANNEL_PLAYBACK;
+ cpars->mode = SND_PCM_MODE_BLOCK;
+ cpars->start_mode = SND_PCM_START_DATA;
+ cpars->stop_mode = SND_PCM_STOP_STOP;
+ cpars->format.format = SND_PCM_SFMT_S16_LE;
+ cpars->format.interleave = 1;
+ cpars->format.rate = DEFAULT_CPARAMS_RATE;
+ cpars->format.voices = DEFAULT_CPARAMS_VOICES;
+ cpars->buf.block.frag_size = DEFAULT_CPARAMS_FRAG_SIZE;
+ cpars->buf.block.frags_min = DEFAULT_CPARAMS_FRAGS_MIN;
+ cpars->buf.block.frags_max = DEFAULT_CPARAMS_FRAGS_MAX;
+}
+
+/* This function waits until it is possible to write a full sound buffer */
+static void
+QSA_WaitDevice(_THIS)
+{
+ int result;
+
+ /* Setup timeout for playing one fragment equal to 2 seconds */
+ /* If timeout occured than something wrong with hardware or driver */
+ /* For example, Vortex 8820 audio driver stucks on second DAC because */
+ /* it doesn't exist ! */
+ result = SDL_IOReady(this->hidden->audio_fd, !this->hidden->iscapture, 2 * 1000);
+ switch (result) {
+ case -1:
+ SDL_SetError("QSA: SDL_IOReady() failed: %s", strerror(errno));
+ break;
+ case 0:
+ SDL_SetError("QSA: timeout on buffer waiting occured");
+ this->hidden->timeout_on_wait = 1;
+ break;
+ default:
+ this->hidden->timeout_on_wait = 0;
+ break;
+ }
+}
+
+static void
+QSA_PlayDevice(_THIS)
+{
+ snd_pcm_channel_status_t cstatus;
+ int written;
+ int status;
+ int towrite;
+ void *pcmbuffer;
+
+ if (!SDL_AtomicGet(&this->enabled) || !this->hidden) {
+ return;
+ }
+
+ towrite = this->spec.size;
+ pcmbuffer = this->hidden->pcm_buf;
+
+ /* Write the audio data, checking for EAGAIN (buffer full) and underrun */
+ do {
+ written =
+ snd_pcm_plugin_write(this->hidden->audio_handle, pcmbuffer,
+ towrite);
+ if (written != towrite) {
+ /* Check if samples playback got stuck somewhere in hardware or in */
+ /* the audio device driver */
+ if ((errno == EAGAIN) && (written == 0)) {
+ if (this->hidden->timeout_on_wait != 0) {
+ SDL_SetError("QSA: buffer playback timeout");
+ return;
+ }
+ }
+
+ /* Check for errors or conditions */
+ if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
+ /* Let a little CPU time go by and try to write again */
+ SDL_Delay(1);
+
+ /* if we wrote some data */
+ towrite -= written;
+ pcmbuffer += written * this->spec.channels;
+ continue;
+ } else {
+ if ((errno == EINVAL) || (errno == EIO)) {
+ SDL_zero(cstatus);
+ if (!this->hidden->iscapture) {
+ cstatus.channel = SND_PCM_CHANNEL_PLAYBACK;
+ } else {
+ cstatus.channel = SND_PCM_CHANNEL_CAPTURE;
+ }
+
+ status =
+ snd_pcm_plugin_status(this->hidden->audio_handle,
+ &cstatus);
+ if (status < 0) {
+ QSA_SetError("snd_pcm_plugin_status", status);
+ return;
+ }
+
+ if ((cstatus.status == SND_PCM_STATUS_UNDERRUN) ||
+ (cstatus.status == SND_PCM_STATUS_READY)) {
+ if (!this->hidden->iscapture) {
+ status =
+ snd_pcm_plugin_prepare(this->hidden->
+ audio_handle,
+ SND_PCM_CHANNEL_PLAYBACK);
+ } else {
+ status =
+ snd_pcm_plugin_prepare(this->hidden->
+ audio_handle,
+ SND_PCM_CHANNEL_CAPTURE);
+ }
+ if (status < 0) {
+ QSA_SetError("snd_pcm_plugin_prepare", status);
+ return;
+ }
+ }
+ continue;
+ } else {
+ return;
+ }
+ }
+ } else {
+ /* we wrote all remaining data */
+ towrite -= written;
+ pcmbuffer += written * this->spec.channels;
+ }
+ } while ((towrite > 0) && SDL_AtomicGet(&this->enabled));
+
+ /* If we couldn't write, assume fatal error for now */
+ if (towrite != 0) {
+ SDL_OpenedAudioDeviceDisconnected(this);
+ }
+}
+
+static Uint8 *
+QSA_GetDeviceBuf(_THIS)
+{
+ return this->hidden->pcm_buf;
+}
+
+static void
+QSA_CloseDevice(_THIS)
+{
+ if (this->hidden->audio_handle != NULL) {
+ if (!this->hidden->iscapture) {
+ /* Finish playing available samples */
+ snd_pcm_plugin_flush(this->hidden->audio_handle,
+ SND_PCM_CHANNEL_PLAYBACK);
+ } else {
+ /* Cancel unread samples during capture */
+ snd_pcm_plugin_flush(this->hidden->audio_handle,
+ SND_PCM_CHANNEL_CAPTURE);
+ }
+ snd_pcm_close(this->hidden->audio_handle);
+ }
+
+ SDL_free(this->hidden->pcm_buf);
+ SDL_free(this->hidden);
+}
+
+static int
+QSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ const QSA_Device *device = (const QSA_Device *) handle;
+ int status = 0;
+ int format = 0;
+ SDL_AudioFormat test_format = 0;
+ int found = 0;
+ snd_pcm_channel_setup_t csetup;
+ snd_pcm_channel_params_t cparams;
+
+ /* Initialize all variables that we clean on shutdown */
+ this->hidden =
+ (struct SDL_PrivateAudioData *) SDL_calloc(1,
+ (sizeof
+ (struct
+ SDL_PrivateAudioData)));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ /* Initialize channel transfer parameters to default */
+ QSA_InitAudioParams(&cparams);
+
+ /* Initialize channel direction: capture or playback */
+ this->hidden->iscapture = iscapture ? SDL_TRUE : SDL_FALSE;
+
+ if (device != NULL) {
+ /* Open requested audio device */
+ this->hidden->deviceno = device->deviceno;
+ this->hidden->cardno = device->cardno;
+ status = snd_pcm_open(&this->hidden->audio_handle,
+ device->cardno, device->deviceno,
+ iscapture ? SND_PCM_OPEN_CAPTURE : SND_PCM_OPEN_PLAYBACK);
+ } else {
+ /* Open system default audio device */
+ status = snd_pcm_open_preferred(&this->hidden->audio_handle,
+ &this->hidden->cardno,
+ &this->hidden->deviceno,
+ iscapture ? SND_PCM_OPEN_CAPTURE : SND_PCM_OPEN_PLAYBACK);
+ }
+
+ /* Check if requested device is opened */
+ if (status < 0) {
+ this->hidden->audio_handle = NULL;
+ return QSA_SetError("snd_pcm_open", status);
+ }
+
+ /* Try for a closest match on audio format */
+ format = 0;
+ /* can't use format as SND_PCM_SFMT_U8 = 0 in qsa */
+ found = 0;
+
+ for (test_format = SDL_FirstAudioFormat(this->spec.format); !found;) {
+ /* if match found set format to equivalent QSA format */
+ switch (test_format) {
+ case AUDIO_U8:
+ {
+ format = SND_PCM_SFMT_U8;
+ found = 1;
+ }
+ break;
+ case AUDIO_S8:
+ {
+ format = SND_PCM_SFMT_S8;
+ found = 1;
+ }
+ break;
+ case AUDIO_S16LSB:
+ {
+ format = SND_PCM_SFMT_S16_LE;
+ found = 1;
+ }
+ break;
+ case AUDIO_S16MSB:
+ {
+ format = SND_PCM_SFMT_S16_BE;
+ found = 1;
+ }
+ break;
+ case AUDIO_U16LSB:
+ {
+ format = SND_PCM_SFMT_U16_LE;
+ found = 1;
+ }
+ break;
+ case AUDIO_U16MSB:
+ {
+ format = SND_PCM_SFMT_U16_BE;
+ found = 1;
+ }
+ break;
+ case AUDIO_S32LSB:
+ {
+ format = SND_PCM_SFMT_S32_LE;
+ found = 1;
+ }
+ break;
+ case AUDIO_S32MSB:
+ {
+ format = SND_PCM_SFMT_S32_BE;
+ found = 1;
+ }
+ break;
+ case AUDIO_F32LSB:
+ {
+ format = SND_PCM_SFMT_FLOAT_LE;
+ found = 1;
+ }
+ break;
+ case AUDIO_F32MSB:
+ {
+ format = SND_PCM_SFMT_FLOAT_BE;
+ found = 1;
+ }
+ break;
+ default:
+ {
+ break;
+ }
+ }
+
+ if (!found) {
+ test_format = SDL_NextAudioFormat();
+ }
+ }
+
+ /* assumes test_format not 0 on success */
+ if (test_format == 0) {
+ return SDL_SetError("QSA: Couldn't find any hardware audio formats");
+ }
+
+ this->spec.format = test_format;
+
+ /* Set the audio format */
+ cparams.format.format = format;
+
+ /* Set mono/stereo/4ch/6ch/8ch audio */
+ cparams.format.voices = this->spec.channels;
+
+ /* Set rate */
+ cparams.format.rate = this->spec.freq;
+
+ /* Setup the transfer parameters according to cparams */
+ status = snd_pcm_plugin_params(this->hidden->audio_handle, &cparams);
+ if (status < 0) {
+ return QSA_SetError("snd_pcm_plugin_params", status);
+ }
+
+ /* Make sure channel is setup right one last time */
+ SDL_zero(csetup);
+ if (!this->hidden->iscapture) {
+ csetup.channel = SND_PCM_CHANNEL_PLAYBACK;
+ } else {
+ csetup.channel = SND_PCM_CHANNEL_CAPTURE;
+ }
+
+ /* Setup an audio channel */
+ if (snd_pcm_plugin_setup(this->hidden->audio_handle, &csetup) < 0) {
+ return SDL_SetError("QSA: Unable to setup channel");
+ }
+
+ /* Calculate the final parameters for this audio specification */
+ SDL_CalculateAudioSpec(&this->spec);
+
+ this->hidden->pcm_len = this->spec.size;
+
+ if (this->hidden->pcm_len == 0) {
+ this->hidden->pcm_len =
+ csetup.buf.block.frag_size * this->spec.channels *
+ (snd_pcm_format_width(format) / 8);
+ }
+
+ /*
+ * Allocate memory to the audio buffer and initialize with silence
+ * (Note that buffer size must be a multiple of fragment size, so find
+ * closest multiple)
+ */
+ this->hidden->pcm_buf =
+ (Uint8 *) SDL_malloc(this->hidden->pcm_len);
+ if (this->hidden->pcm_buf == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(this->hidden->pcm_buf, this->spec.silence,
+ this->hidden->pcm_len);
+
+ /* get the file descriptor */
+ if (!this->hidden->iscapture) {
+ this->hidden->audio_fd =
+ snd_pcm_file_descriptor(this->hidden->audio_handle,
+ SND_PCM_CHANNEL_PLAYBACK);
+ } else {
+ this->hidden->audio_fd =
+ snd_pcm_file_descriptor(this->hidden->audio_handle,
+ SND_PCM_CHANNEL_CAPTURE);
+ }
+
+ if (this->hidden->audio_fd < 0) {
+ return QSA_SetError("snd_pcm_file_descriptor", status);
+ }
+
+ /* Prepare an audio channel */
+ if (!this->hidden->iscapture) {
+ /* Prepare audio playback */
+ status =
+ snd_pcm_plugin_prepare(this->hidden->audio_handle,
+ SND_PCM_CHANNEL_PLAYBACK);
+ } else {
+ /* Prepare audio capture */
+ status =
+ snd_pcm_plugin_prepare(this->hidden->audio_handle,
+ SND_PCM_CHANNEL_CAPTURE);
+ }
+
+ if (status < 0) {
+ return QSA_SetError("snd_pcm_plugin_prepare", status);
+ }
+
+ /* We're really ready to rock and roll. :-) */
+ return 0;
+}
+
+static void
+QSA_DetectDevices(void)
+{
+ uint32_t it;
+ uint32_t cards;
+ uint32_t devices;
+ int32_t status;
+
+ /* Detect amount of available devices */
+ /* this value can be changed in the runtime */
+ cards = snd_cards();
+
+ /* If io-audio manager is not running we will get 0 as number */
+ /* of available audio devices */
+ if (cards == 0) {
+ /* We have no any available audio devices */
+ return;
+ }
+
+ /* !!! FIXME: code duplication */
+ /* Find requested devices by type */
+ { /* output devices */
+ /* Playback devices enumeration requested */
+ for (it = 0; it < cards; it++) {
+ devices = 0;
+ do {
+ status =
+ snd_card_get_longname(it,
+ qsa_playback_device
+ [qsa_playback_devices].name,
+ QSA_MAX_NAME_LENGTH);
+ if (status == EOK) {
+ snd_pcm_t *handle;
+
+ /* Add device number to device name */
+ sprintf(qsa_playback_device[qsa_playback_devices].name +
+ SDL_strlen(qsa_playback_device
+ [qsa_playback_devices].name), " d%d",
+ devices);
+
+ /* Store associated card number id */
+ qsa_playback_device[qsa_playback_devices].cardno = it;
+
+ /* Check if this device id could play anything */
+ status =
+ snd_pcm_open(&handle, it, devices,
+ SND_PCM_OPEN_PLAYBACK);
+ if (status == EOK) {
+ qsa_playback_device[qsa_playback_devices].deviceno =
+ devices;
+ status = snd_pcm_close(handle);
+ if (status == EOK) {
+ SDL_AddAudioDevice(SDL_FALSE, qsa_playback_device[qsa_playback_devices].name, &qsa_playback_device[qsa_playback_devices]);
+ qsa_playback_devices++;
+ }
+ } else {
+ /* Check if we got end of devices list */
+ if (status == -ENOENT) {
+ break;
+ }
+ }
+ } else {
+ break;
+ }
+
+ /* Check if we reached maximum devices count */
+ if (qsa_playback_devices >= QSA_MAX_DEVICES) {
+ break;
+ }
+ devices++;
+ } while (1);
+
+ /* Check if we reached maximum devices count */
+ if (qsa_playback_devices >= QSA_MAX_DEVICES) {
+ break;
+ }
+ }
+ }
+
+ { /* capture devices */
+ /* Capture devices enumeration requested */
+ for (it = 0; it < cards; it++) {
+ devices = 0;
+ do {
+ status =
+ snd_card_get_longname(it,
+ qsa_capture_device
+ [qsa_capture_devices].name,
+ QSA_MAX_NAME_LENGTH);
+ if (status == EOK) {
+ snd_pcm_t *handle;
+
+ /* Add device number to device name */
+ sprintf(qsa_capture_device[qsa_capture_devices].name +
+ SDL_strlen(qsa_capture_device
+ [qsa_capture_devices].name), " d%d",
+ devices);
+
+ /* Store associated card number id */
+ qsa_capture_device[qsa_capture_devices].cardno = it;
+
+ /* Check if this device id could play anything */
+ status =
+ snd_pcm_open(&handle, it, devices,
+ SND_PCM_OPEN_CAPTURE);
+ if (status == EOK) {
+ qsa_capture_device[qsa_capture_devices].deviceno =
+ devices;
+ status = snd_pcm_close(handle);
+ if (status == EOK) {
+ SDL_AddAudioDevice(SDL_TRUE, qsa_capture_device[qsa_capture_devices].name, &qsa_capture_device[qsa_capture_devices]);
+ qsa_capture_devices++;
+ }
+ } else {
+ /* Check if we got end of devices list */
+ if (status == -ENOENT) {
+ break;
+ }
+ }
+
+ /* Check if we reached maximum devices count */
+ if (qsa_capture_devices >= QSA_MAX_DEVICES) {
+ break;
+ }
+ } else {
+ break;
+ }
+ devices++;
+ } while (1);
+
+ /* Check if we reached maximum devices count */
+ if (qsa_capture_devices >= QSA_MAX_DEVICES) {
+ break;
+ }
+ }
+ }
+}
+
+static void
+QSA_Deinitialize(void)
+{
+ /* Clear devices array on shutdown */
+ /* !!! FIXME: we zero these on init...any reason to do it here? */
+ SDL_zero(qsa_playback_device);
+ SDL_zero(qsa_capture_device);
+ qsa_playback_devices = 0;
+ qsa_capture_devices = 0;
+}
+
+static int
+QSA_Init(SDL_AudioDriverImpl * impl)
+{
+ /* Clear devices array */
+ SDL_zero(qsa_playback_device);
+ SDL_zero(qsa_capture_device);
+ qsa_playback_devices = 0;
+ qsa_capture_devices = 0;
+
+ /* Set function pointers */
+ /* DeviceLock and DeviceUnlock functions are used default, */
+ /* provided by SDL, which uses pthread_mutex for lock/unlock */
+ impl->DetectDevices = QSA_DetectDevices;
+ impl->OpenDevice = QSA_OpenDevice;
+ impl->ThreadInit = QSA_ThreadInit;
+ impl->WaitDevice = QSA_WaitDevice;
+ impl->PlayDevice = QSA_PlayDevice;
+ impl->GetDeviceBuf = QSA_GetDeviceBuf;
+ impl->CloseDevice = QSA_CloseDevice;
+ impl->Deinitialize = QSA_Deinitialize;
+ impl->LockDevice = NULL;
+ impl->UnlockDevice = NULL;
+
+ impl->ProvidesOwnCallbackThread = 0;
+ impl->SkipMixerLock = 0;
+ impl->HasCaptureSupport = 1;
+ impl->OnlyHasDefaultOutputDevice = 0;
+ impl->OnlyHasDefaultCaptureDevice = 0;
+
+ return 1; /* this audio target is available. */
+}
+
+AudioBootStrap QSAAUDIO_bootstrap = {
+ "qsa", "QNX QSA Audio", QSA_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_QSA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/qsa/SDL_qsa_audio.h b/src/3rdparty/SDL2/src/audio/qsa/SDL_qsa_audio.h
new file mode 100644
index 0000000..a6300c1
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/qsa/SDL_qsa_audio.h
@@ -0,0 +1,57 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef __SDL_QSA_AUDIO_H__
+#define __SDL_QSA_AUDIO_H__
+
+#include <sys/asoundlib.h>
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice* this
+
+struct SDL_PrivateAudioData
+{
+ /* SDL capture state */
+ SDL_bool iscapture;
+
+ /* The audio device handle */
+ int cardno;
+ int deviceno;
+ snd_pcm_t *audio_handle;
+
+ /* The audio file descriptor */
+ int audio_fd;
+
+ /* Select timeout status */
+ uint32_t timeout_on_wait;
+
+ /* Raw mixing buffer */
+ Uint8 *pcm_buf;
+ Uint32 pcm_len;
+};
+
+#endif /* __SDL_QSA_AUDIO_H__ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/sndio/SDL_sndioaudio.c b/src/3rdparty/SDL2/src/audio/sndio/SDL_sndioaudio.c
new file mode 100644
index 0000000..4a49171
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/sndio/SDL_sndioaudio.c
@@ -0,0 +1,382 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_SNDIO
+
+/* OpenBSD sndio target */
+
+#if HAVE_STDIO_H
+#include <stdio.h>
+#endif
+
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
+
+#include <poll.h>
+#include <unistd.h>
+
+#include "SDL_audio.h"
+#include "../SDL_audio_c.h"
+#include "SDL_sndioaudio.h"
+
+#ifdef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC
+#include "SDL_loadso.h"
+#endif
+
+#ifndef INFTIM
+#define INFTIM -1
+#endif
+
+#ifndef SIO_DEVANY
+#define SIO_DEVANY "default"
+#endif
+
+static struct sio_hdl * (*SNDIO_sio_open)(const char *, unsigned int, int);
+static void (*SNDIO_sio_close)(struct sio_hdl *);
+static int (*SNDIO_sio_setpar)(struct sio_hdl *, struct sio_par *);
+static int (*SNDIO_sio_getpar)(struct sio_hdl *, struct sio_par *);
+static int (*SNDIO_sio_start)(struct sio_hdl *);
+static int (*SNDIO_sio_stop)(struct sio_hdl *);
+static size_t (*SNDIO_sio_read)(struct sio_hdl *, void *, size_t);
+static size_t (*SNDIO_sio_write)(struct sio_hdl *, const void *, size_t);
+static int (*SNDIO_sio_nfds)(struct sio_hdl *);
+static int (*SNDIO_sio_pollfd)(struct sio_hdl *, struct pollfd *, int);
+static int (*SNDIO_sio_revents)(struct sio_hdl *, struct pollfd *);
+static int (*SNDIO_sio_eof)(struct sio_hdl *);
+static void (*SNDIO_sio_initpar)(struct sio_par *);
+
+#ifdef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC
+static const char *sndio_library = SDL_AUDIO_DRIVER_SNDIO_DYNAMIC;
+static void *sndio_handle = NULL;
+
+static int
+load_sndio_sym(const char *fn, void **addr)
+{
+ *addr = SDL_LoadFunction(sndio_handle, fn);
+ if (*addr == NULL) {
+ /* Don't call SDL_SetError(): SDL_LoadFunction already did. */
+ return 0;
+ }
+
+ return 1;
+}
+
+/* cast funcs to char* first, to please GCC's strict aliasing rules. */
+#define SDL_SNDIO_SYM(x) \
+ if (!load_sndio_sym(#x, (void **) (char *) &SNDIO_##x)) return -1
+#else
+#define SDL_SNDIO_SYM(x) SNDIO_##x = x
+#endif
+
+static int
+load_sndio_syms(void)
+{
+ SDL_SNDIO_SYM(sio_open);
+ SDL_SNDIO_SYM(sio_close);
+ SDL_SNDIO_SYM(sio_setpar);
+ SDL_SNDIO_SYM(sio_getpar);
+ SDL_SNDIO_SYM(sio_start);
+ SDL_SNDIO_SYM(sio_stop);
+ SDL_SNDIO_SYM(sio_read);
+ SDL_SNDIO_SYM(sio_write);
+ SDL_SNDIO_SYM(sio_nfds);
+ SDL_SNDIO_SYM(sio_pollfd);
+ SDL_SNDIO_SYM(sio_revents);
+ SDL_SNDIO_SYM(sio_eof);
+ SDL_SNDIO_SYM(sio_initpar);
+ return 0;
+}
+
+#undef SDL_SNDIO_SYM
+
+#ifdef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC
+
+static void
+UnloadSNDIOLibrary(void)
+{
+ if (sndio_handle != NULL) {
+ SDL_UnloadObject(sndio_handle);
+ sndio_handle = NULL;
+ }
+}
+
+static int
+LoadSNDIOLibrary(void)
+{
+ int retval = 0;
+ if (sndio_handle == NULL) {
+ sndio_handle = SDL_LoadObject(sndio_library);
+ if (sndio_handle == NULL) {
+ retval = -1;
+ /* Don't call SDL_SetError(): SDL_LoadObject already did. */
+ } else {
+ retval = load_sndio_syms();
+ if (retval < 0) {
+ UnloadSNDIOLibrary();
+ }
+ }
+ }
+ return retval;
+}
+
+#else
+
+static void
+UnloadSNDIOLibrary(void)
+{
+}
+
+static int
+LoadSNDIOLibrary(void)
+{
+ load_sndio_syms();
+ return 0;
+}
+
+#endif /* SDL_AUDIO_DRIVER_SNDIO_DYNAMIC */
+
+
+
+
+static void
+SNDIO_WaitDevice(_THIS)
+{
+ /* no-op; SNDIO_sio_write() blocks if necessary. */
+}
+
+static void
+SNDIO_PlayDevice(_THIS)
+{
+ const int written = SNDIO_sio_write(this->hidden->dev,
+ this->hidden->mixbuf,
+ this->hidden->mixlen);
+
+ /* If we couldn't write, assume fatal error for now */
+ if ( written == 0 ) {
+ SDL_OpenedAudioDeviceDisconnected(this);
+ }
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Wrote %d bytes of audio data\n", written);
+#endif
+}
+
+static int
+SNDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
+{
+ size_t r;
+ int revents;
+ int nfds;
+
+ /* Emulate a blocking read */
+ r = SNDIO_sio_read(this->hidden->dev, buffer, buflen);
+ while (r == 0 && !SNDIO_sio_eof(this->hidden->dev)) {
+ if ((nfds = SNDIO_sio_pollfd(this->hidden->dev, this->hidden->pfd, POLLIN)) <= 0
+ || poll(this->hidden->pfd, nfds, INFTIM) < 0) {
+ return -1;
+ }
+ revents = SNDIO_sio_revents(this->hidden->dev, this->hidden->pfd);
+ if (revents & POLLIN) {
+ r = SNDIO_sio_read(this->hidden->dev, buffer, buflen);
+ }
+ if (revents & POLLHUP) {
+ break;
+ }
+ }
+ return (int) r;
+}
+
+static void
+SNDIO_FlushCapture(_THIS)
+{
+ char buf[512];
+
+ while (SNDIO_sio_read(this->hidden->dev, buf, sizeof(buf)) != 0) {
+ /* do nothing */;
+ }
+}
+
+static Uint8 *
+SNDIO_GetDeviceBuf(_THIS)
+{
+ return this->hidden->mixbuf;
+}
+
+static void
+SNDIO_CloseDevice(_THIS)
+{
+ if ( this->hidden->pfd != NULL ) {
+ SDL_free(this->hidden->pfd);
+ }
+ if ( this->hidden->dev != NULL ) {
+ SNDIO_sio_stop(this->hidden->dev);
+ SNDIO_sio_close(this->hidden->dev);
+ }
+ SDL_free(this->hidden->mixbuf);
+ SDL_free(this->hidden);
+}
+
+static int
+SNDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
+ struct sio_par par;
+ int status;
+
+ this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc(sizeof(*this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(this->hidden);
+
+ this->hidden->mixlen = this->spec.size;
+
+ /* Capture devices must be non-blocking for SNDIO_FlushCapture */
+ if ((this->hidden->dev =
+ SNDIO_sio_open(devname != NULL ? devname : SIO_DEVANY,
+ iscapture ? SIO_REC : SIO_PLAY, iscapture)) == NULL) {
+ return SDL_SetError("sio_open() failed");
+ }
+
+ /* Allocate the pollfd array for capture devices */
+ if (iscapture && (this->hidden->pfd =
+ SDL_malloc(sizeof(struct pollfd) * SNDIO_sio_nfds(this->hidden->dev))) == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ SNDIO_sio_initpar(&par);
+
+ par.rate = this->spec.freq;
+ par.pchan = this->spec.channels;
+ par.round = this->spec.samples;
+ par.appbufsz = par.round * 2;
+
+ /* Try for a closest match on audio format */
+ status = -1;
+ while (test_format && (status < 0)) {
+ if (!SDL_AUDIO_ISFLOAT(test_format)) {
+ par.le = SDL_AUDIO_ISLITTLEENDIAN(test_format) ? 1 : 0;
+ par.sig = SDL_AUDIO_ISSIGNED(test_format) ? 1 : 0;
+ par.bits = SDL_AUDIO_BITSIZE(test_format);
+
+ if (SNDIO_sio_setpar(this->hidden->dev, &par) == 0) {
+ continue;
+ }
+ if (SNDIO_sio_getpar(this->hidden->dev, &par) == 0) {
+ return SDL_SetError("sio_getpar() failed");
+ }
+ if (par.bps != SIO_BPS(par.bits)) {
+ continue;
+ }
+ if ((par.bits == 8 * par.bps) || (par.msb)) {
+ status = 0;
+ break;
+ }
+ }
+ test_format = SDL_NextAudioFormat();
+ }
+
+ if (status < 0) {
+ return SDL_SetError("sndio: Couldn't find any hardware audio formats");
+ }
+
+ if ((par.bps == 4) && (par.sig) && (par.le))
+ this->spec.format = AUDIO_S32LSB;
+ else if ((par.bps == 4) && (par.sig) && (!par.le))
+ this->spec.format = AUDIO_S32MSB;
+ else if ((par.bps == 2) && (par.sig) && (par.le))
+ this->spec.format = AUDIO_S16LSB;
+ else if ((par.bps == 2) && (par.sig) && (!par.le))
+ this->spec.format = AUDIO_S16MSB;
+ else if ((par.bps == 2) && (!par.sig) && (par.le))
+ this->spec.format = AUDIO_U16LSB;
+ else if ((par.bps == 2) && (!par.sig) && (!par.le))
+ this->spec.format = AUDIO_U16MSB;
+ else if ((par.bps == 1) && (par.sig))
+ this->spec.format = AUDIO_S8;
+ else if ((par.bps == 1) && (!par.sig))
+ this->spec.format = AUDIO_U8;
+ else {
+ return SDL_SetError("sndio: Got unsupported hardware audio format.");
+ }
+
+ this->spec.freq = par.rate;
+ this->spec.channels = par.pchan;
+ this->spec.samples = par.round;
+
+ /* Calculate the final parameters for this audio specification */
+ SDL_CalculateAudioSpec(&this->spec);
+
+ /* Allocate mixing buffer */
+ this->hidden->mixlen = this->spec.size;
+ this->hidden->mixbuf = (Uint8 *) SDL_malloc(this->hidden->mixlen);
+ if (this->hidden->mixbuf == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(this->hidden->mixbuf, this->spec.silence, this->hidden->mixlen);
+
+ if (!SNDIO_sio_start(this->hidden->dev)) {
+ return SDL_SetError("sio_start() failed");
+ }
+
+ /* We're ready to rock and roll. :-) */
+ return 0;
+}
+
+static void
+SNDIO_Deinitialize(void)
+{
+ UnloadSNDIOLibrary();
+}
+
+static int
+SNDIO_Init(SDL_AudioDriverImpl * impl)
+{
+ if (LoadSNDIOLibrary() < 0) {
+ return 0;
+ }
+
+ /* Set the function pointers */
+ impl->OpenDevice = SNDIO_OpenDevice;
+ impl->WaitDevice = SNDIO_WaitDevice;
+ impl->PlayDevice = SNDIO_PlayDevice;
+ impl->GetDeviceBuf = SNDIO_GetDeviceBuf;
+ impl->CloseDevice = SNDIO_CloseDevice;
+ impl->CaptureFromDevice = SNDIO_CaptureFromDevice;
+ impl->FlushCapture = SNDIO_FlushCapture;
+ impl->Deinitialize = SNDIO_Deinitialize;
+
+ impl->AllowsArbitraryDeviceNames = 1;
+ impl->HasCaptureSupport = SDL_TRUE;
+
+ return 1; /* this audio target is available. */
+}
+
+AudioBootStrap SNDIO_bootstrap = {
+ "sndio", "OpenBSD sndio", SNDIO_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_SNDIO */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/sndio/SDL_sndioaudio.h b/src/3rdparty/SDL2/src/audio/sndio/SDL_sndioaudio.h
new file mode 100644
index 0000000..144bbc2
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/sndio/SDL_sndioaudio.h
@@ -0,0 +1,49 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_sndioaudio_h_
+#define SDL_sndioaudio_h_
+
+#include <poll.h>
+#include <sndio.h>
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData
+{
+ /* The audio device handle */
+ struct sio_hdl *dev;
+
+ /* Raw mixing buffer */
+ Uint8 *mixbuf;
+ int mixlen;
+
+ /* Polling structures for non-blocking sndio devices */
+ struct pollfd *pfd;
+};
+
+#endif /* SDL_sndioaudio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/sun/SDL_sunaudio.c b/src/3rdparty/SDL2/src/audio/sun/SDL_sunaudio.c
new file mode 100644
index 0000000..ddf94b3
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/sun/SDL_sunaudio.c
@@ -0,0 +1,419 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_SUNAUDIO
+
+/* Allow access to a raw mixing buffer */
+
+#include <fcntl.h>
+#include <errno.h>
+#ifdef __NETBSD__
+#include <sys/ioctl.h>
+#include <sys/audioio.h>
+#endif
+#ifdef __SVR4
+#include <sys/audioio.h>
+#else
+#include <sys/time.h>
+#include <sys/types.h>
+#endif
+#include <unistd.h>
+
+#include "SDL_timer.h"
+#include "SDL_audio.h"
+#include "../../core/unix/SDL_poll.h"
+#include "../SDL_audio_c.h"
+#include "../SDL_audiodev_c.h"
+#include "SDL_sunaudio.h"
+
+/* Open the audio device for playback, and don't block if busy */
+
+#if defined(AUDIO_GETINFO) && !defined(AUDIO_GETBUFINFO)
+#define AUDIO_GETBUFINFO AUDIO_GETINFO
+#endif
+
+/* Audio driver functions */
+static Uint8 snd2au(int sample);
+
+/* Audio driver bootstrap functions */
+static void
+SUNAUDIO_DetectDevices(void)
+{
+ SDL_EnumUnixAudioDevices(1, (int (*)(int)) NULL);
+}
+
+#ifdef DEBUG_AUDIO
+void
+CheckUnderflow(_THIS)
+{
+#ifdef AUDIO_GETBUFINFO
+ audio_info_t info;
+ int left;
+
+ ioctl(this->hidden->audio_fd, AUDIO_GETBUFINFO, &info);
+ left = (this->hidden->written - info.play.samples);
+ if (this->hidden->written && (left == 0)) {
+ fprintf(stderr, "audio underflow!\n");
+ }
+#endif
+}
+#endif
+
+static void
+SUNAUDIO_WaitDevice(_THIS)
+{
+#ifdef AUDIO_GETBUFINFO
+#define SLEEP_FUDGE 10 /* 10 ms scheduling fudge factor */
+ audio_info_t info;
+ Sint32 left;
+
+ ioctl(this->hidden->audio_fd, AUDIO_GETBUFINFO, &info);
+ left = (this->hidden->written - info.play.samples);
+ if (left > this->hidden->fragsize) {
+ Sint32 sleepy;
+
+ sleepy = ((left - this->hidden->fragsize) / this->hidden->frequency);
+ sleepy -= SLEEP_FUDGE;
+ if (sleepy > 0) {
+ SDL_Delay(sleepy);
+ }
+ }
+#else
+ SDL_IOReady(this->hidden->audio_fd, SDL_TRUE, -1);
+#endif
+}
+
+static void
+SUNAUDIO_PlayDevice(_THIS)
+{
+ /* Write the audio data */
+ if (this->hidden->ulaw_only) {
+ /* Assuming that this->spec.freq >= 8000 Hz */
+ int accum, incr, pos;
+ Uint8 *aubuf;
+
+ accum = 0;
+ incr = this->spec.freq / 8;
+ aubuf = this->hidden->ulaw_buf;
+ switch (this->hidden->audio_fmt & 0xFF) {
+ case 8:
+ {
+ Uint8 *sndbuf;
+
+ sndbuf = this->hidden->mixbuf;
+ for (pos = 0; pos < this->hidden->fragsize; ++pos) {
+ *aubuf = snd2au((0x80 - *sndbuf) * 64);
+ accum += incr;
+ while (accum > 0) {
+ accum -= 1000;
+ sndbuf += 1;
+ }
+ aubuf += 1;
+ }
+ }
+ break;
+ case 16:
+ {
+ Sint16 *sndbuf;
+
+ sndbuf = (Sint16 *) this->hidden->mixbuf;
+ for (pos = 0; pos < this->hidden->fragsize; ++pos) {
+ *aubuf = snd2au(*sndbuf / 4);
+ accum += incr;
+ while (accum > 0) {
+ accum -= 1000;
+ sndbuf += 1;
+ }
+ aubuf += 1;
+ }
+ }
+ break;
+ }
+#ifdef DEBUG_AUDIO
+ CheckUnderflow(this);
+#endif
+ if (write(this->hidden->audio_fd, this->hidden->ulaw_buf,
+ this->hidden->fragsize) < 0) {
+ /* Assume fatal error, for now */
+ SDL_OpenedAudioDeviceDisconnected(this);
+ }
+ this->hidden->written += this->hidden->fragsize;
+ } else {
+#ifdef DEBUG_AUDIO
+ CheckUnderflow(this);
+#endif
+ if (write(this->hidden->audio_fd, this->hidden->mixbuf,
+ this->spec.size) < 0) {
+ /* Assume fatal error, for now */
+ SDL_OpenedAudioDeviceDisconnected(this);
+ }
+ this->hidden->written += this->hidden->fragsize;
+ }
+}
+
+static Uint8 *
+SUNAUDIO_GetDeviceBuf(_THIS)
+{
+ return (this->hidden->mixbuf);
+}
+
+static void
+SUNAUDIO_CloseDevice(_THIS)
+{
+ SDL_free(this->hidden->ulaw_buf);
+ if (this->hidden->audio_fd >= 0) {
+ close(this->hidden->audio_fd);
+ }
+ SDL_free(this->hidden->mixbuf);
+ SDL_free(this->hidden);
+}
+
+static int
+SUNAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+#ifdef AUDIO_SETINFO
+ int enc;
+#endif
+ int desired_freq = 0;
+ const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
+ SDL_AudioFormat format = 0;
+ audio_info_t info;
+
+ /* We don't care what the devname is...we'll try to open anything. */
+ /* ...but default to first name in the list... */
+ if (devname == NULL) {
+ devname = SDL_GetAudioDeviceName(0, iscapture);
+ if (devname == NULL) {
+ return SDL_SetError("No such audio device");
+ }
+ }
+
+ /* Initialize all variables that we clean on shutdown */
+ this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc((sizeof *this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(this->hidden);
+
+ /* Open the audio device */
+ this->hidden->audio_fd = open(devname, flags, 0);
+ if (this->hidden->audio_fd < 0) {
+ return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
+ }
+
+ desired_freq = this->spec.freq;
+
+ /* Determine the audio parameters from the AudioSpec */
+ switch (SDL_AUDIO_BITSIZE(this->spec.format)) {
+
+ case 8:
+ { /* Unsigned 8 bit audio data */
+ this->spec.format = AUDIO_U8;
+#ifdef AUDIO_SETINFO
+ enc = AUDIO_ENCODING_LINEAR8;
+#endif
+ }
+ break;
+
+ case 16:
+ { /* Signed 16 bit audio data */
+ this->spec.format = AUDIO_S16SYS;
+#ifdef AUDIO_SETINFO
+ enc = AUDIO_ENCODING_LINEAR;
+#endif
+ }
+ break;
+
+ default:
+ {
+ /* !!! FIXME: fallback to conversion on unsupported types! */
+ return SDL_SetError("Unsupported audio format");
+ }
+ }
+ this->hidden->audio_fmt = this->spec.format;
+
+ this->hidden->ulaw_only = 0; /* modern Suns do support linear audio */
+#ifdef AUDIO_SETINFO
+ for (;;) {
+ audio_info_t info;
+ AUDIO_INITINFO(&info); /* init all fields to "no change" */
+
+ /* Try to set the requested settings */
+ info.play.sample_rate = this->spec.freq;
+ info.play.channels = this->spec.channels;
+ info.play.precision = (enc == AUDIO_ENCODING_ULAW)
+ ? 8 : this->spec.format & 0xff;
+ info.play.encoding = enc;
+ if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == 0) {
+
+ /* Check to be sure we got what we wanted */
+ if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
+ return SDL_SetError("Error getting audio parameters: %s",
+ strerror(errno));
+ }
+ if (info.play.encoding == enc
+ && info.play.precision == (this->spec.format & 0xff)
+ && info.play.channels == this->spec.channels) {
+ /* Yow! All seems to be well! */
+ this->spec.freq = info.play.sample_rate;
+ break;
+ }
+ }
+
+ switch (enc) {
+ case AUDIO_ENCODING_LINEAR8:
+ /* unsigned 8bit apparently not supported here */
+ enc = AUDIO_ENCODING_LINEAR;
+ this->spec.format = AUDIO_S16SYS;
+ break; /* try again */
+
+ case AUDIO_ENCODING_LINEAR:
+ /* linear 16bit didn't work either, resort to -law */
+ enc = AUDIO_ENCODING_ULAW;
+ this->spec.channels = 1;
+ this->spec.freq = 8000;
+ this->spec.format = AUDIO_U8;
+ this->hidden->ulaw_only = 1;
+ break;
+
+ default:
+ /* oh well... */
+ return SDL_SetError("Error setting audio parameters: %s",
+ strerror(errno));
+ }
+ }
+#endif /* AUDIO_SETINFO */
+ this->hidden->written = 0;
+
+ /* We can actually convert on-the-fly to U-Law */
+ if (this->hidden->ulaw_only) {
+ this->spec.freq = desired_freq;
+ this->hidden->fragsize = (this->spec.samples * 1000) /
+ (this->spec.freq / 8);
+ this->hidden->frequency = 8;
+ this->hidden->ulaw_buf = (Uint8 *) SDL_malloc(this->hidden->fragsize);
+ if (this->hidden->ulaw_buf == NULL) {
+ return SDL_OutOfMemory();
+ }
+ this->spec.channels = 1;
+ } else {
+ this->hidden->fragsize = this->spec.samples;
+ this->hidden->frequency = this->spec.freq / 1000;
+ }
+#ifdef DEBUG_AUDIO
+ fprintf(stderr, "Audio device %s U-Law only\n",
+ this->hidden->ulaw_only ? "is" : "is not");
+ fprintf(stderr, "format=0x%x chan=%d freq=%d\n",
+ this->spec.format, this->spec.channels, this->spec.freq);
+#endif
+
+ /* Update the fragment size as size in bytes */
+ SDL_CalculateAudioSpec(&this->spec);
+
+ /* Allocate mixing buffer */
+ this->hidden->mixbuf = (Uint8 *) SDL_malloc(this->spec.size);
+ if (this->hidden->mixbuf == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
+
+ /* We're ready to rock and roll. :-) */
+ return 0;
+}
+
+/************************************************************************/
+/* This function (snd2au()) copyrighted: */
+/************************************************************************/
+/* Copyright 1989 by Rich Gopstein and Harris Corporation */
+/* */
+/* Permission to use, copy, modify, and distribute this software */
+/* and its documentation for any purpose and without fee is */
+/* hereby granted, provided that the above copyright notice */
+/* appears in all copies and that both that copyright notice and */
+/* this permission notice appear in supporting documentation, and */
+/* that the name of Rich Gopstein and Harris Corporation not be */
+/* used in advertising or publicity pertaining to distribution */
+/* of the software without specific, written prior permission. */
+/* Rich Gopstein and Harris Corporation make no representations */
+/* about the suitability of this software for any purpose. It */
+/* provided "as is" without express or implied warranty. */
+/************************************************************************/
+
+static Uint8
+snd2au(int sample)
+{
+
+ int mask;
+
+ if (sample < 0) {
+ sample = -sample;
+ mask = 0x7f;
+ } else {
+ mask = 0xff;
+ }
+
+ if (sample < 32) {
+ sample = 0xF0 | (15 - sample / 2);
+ } else if (sample < 96) {
+ sample = 0xE0 | (15 - (sample - 32) / 4);
+ } else if (sample < 224) {
+ sample = 0xD0 | (15 - (sample - 96) / 8);
+ } else if (sample < 480) {
+ sample = 0xC0 | (15 - (sample - 224) / 16);
+ } else if (sample < 992) {
+ sample = 0xB0 | (15 - (sample - 480) / 32);
+ } else if (sample < 2016) {
+ sample = 0xA0 | (15 - (sample - 992) / 64);
+ } else if (sample < 4064) {
+ sample = 0x90 | (15 - (sample - 2016) / 128);
+ } else if (sample < 8160) {
+ sample = 0x80 | (15 - (sample - 4064) / 256);
+ } else {
+ sample = 0x80;
+ }
+ return (mask & sample);
+}
+
+static int
+SUNAUDIO_Init(SDL_AudioDriverImpl * impl)
+{
+ /* Set the function pointers */
+ impl->DetectDevices = SUNAUDIO_DetectDevices;
+ impl->OpenDevice = SUNAUDIO_OpenDevice;
+ impl->PlayDevice = SUNAUDIO_PlayDevice;
+ impl->WaitDevice = SUNAUDIO_WaitDevice;
+ impl->GetDeviceBuf = SUNAUDIO_GetDeviceBuf;
+ impl->CloseDevice = SUNAUDIO_CloseDevice;
+
+ impl->AllowsArbitraryDeviceNames = 1;
+
+ return 1; /* this audio target is available. */
+}
+
+AudioBootStrap SUNAUDIO_bootstrap = {
+ "audio", "UNIX /dev/audio interface", SUNAUDIO_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_SUNAUDIO */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/sun/SDL_sunaudio.h b/src/3rdparty/SDL2/src/audio/sun/SDL_sunaudio.h
new file mode 100644
index 0000000..2b7d57b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/sun/SDL_sunaudio.h
@@ -0,0 +1,47 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_sunaudio_h_
+#define SDL_sunaudio_h_
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData
+{
+ /* The file descriptor for the audio device */
+ int audio_fd;
+
+ SDL_AudioFormat audio_fmt; /* The app audio format */
+ Uint8 *mixbuf; /* The app mixing buffer */
+ int ulaw_only; /* Flag -- does hardware only output U-law? */
+ Uint8 *ulaw_buf; /* The U-law mixing buffer */
+ Sint32 written; /* The number of samples written */
+ int fragsize; /* The audio fragment size in samples */
+ int frequency; /* The audio frequency in KHz */
+};
+
+#endif /* SDL_sunaudio_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/wasapi/SDL_wasapi.c b/src/3rdparty/SDL2/src/audio/wasapi/SDL_wasapi.c
new file mode 100644
index 0000000..b7c8dda
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/wasapi/SDL_wasapi.c
@@ -0,0 +1,779 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_WASAPI
+
+#include "../../core/windows/SDL_windows.h"
+#include "SDL_audio.h"
+#include "SDL_timer.h"
+#include "../SDL_audio_c.h"
+#include "../SDL_sysaudio.h"
+#include "SDL_assert.h"
+#include "SDL_log.h"
+
+#define COBJMACROS
+#include <mmdeviceapi.h>
+#include <audioclient.h>
+
+#include "SDL_wasapi.h"
+
+/* This constant isn't available on MinGW-w64 */
+#ifndef AUDCLNT_STREAMFLAGS_RATEADJUST
+#define AUDCLNT_STREAMFLAGS_RATEADJUST 0x00100000
+#endif
+
+/* these increment as default devices change. Opened default devices pick up changes in their threads. */
+SDL_atomic_t WASAPI_DefaultPlaybackGeneration;
+SDL_atomic_t WASAPI_DefaultCaptureGeneration;
+
+/* This is a list of device id strings we have inflight, so we have consistent pointers to the same device. */
+typedef struct DevIdList
+{
+ WCHAR *str;
+ struct DevIdList *next;
+} DevIdList;
+
+static DevIdList *deviceid_list = NULL;
+
+/* Some GUIDs we need to know without linking to libraries that aren't available before Vista. */
+static const IID SDL_IID_IAudioRenderClient = { 0xf294acfc, 0x3146, 0x4483,{ 0xa7, 0xbf, 0xad, 0xdc, 0xa7, 0xc2, 0x60, 0xe2 } };
+static const IID SDL_IID_IAudioCaptureClient = { 0xc8adbd64, 0xe71e, 0x48a0,{ 0xa4, 0xde, 0x18, 0x5c, 0x39, 0x5c, 0xd3, 0x17 } };
+static const GUID SDL_KSDATAFORMAT_SUBTYPE_PCM = { 0x00000001, 0x0000, 0x0010,{ 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
+static const GUID SDL_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT = { 0x00000003, 0x0000, 0x0010,{ 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
+
+static SDL_bool
+WStrEqual(const WCHAR *a, const WCHAR *b)
+{
+ while (*a) {
+ if (*a != *b) {
+ return SDL_FALSE;
+ }
+ a++;
+ b++;
+ }
+ return *b == 0;
+}
+
+static size_t
+WStrLen(const WCHAR *wstr)
+{
+ size_t retval = 0;
+ if (wstr) {
+ while (*(wstr++)) {
+ retval++;
+ }
+ }
+ return retval;
+}
+
+static WCHAR *
+WStrDupe(const WCHAR *wstr)
+{
+ const size_t len = (WStrLen(wstr) + 1) * sizeof (WCHAR);
+ WCHAR *retval = (WCHAR *) SDL_malloc(len);
+ if (retval) {
+ SDL_memcpy(retval, wstr, len);
+ }
+ return retval;
+}
+
+
+void
+WASAPI_RemoveDevice(const SDL_bool iscapture, LPCWSTR devid)
+{
+ DevIdList *i;
+ DevIdList *next;
+ DevIdList *prev = NULL;
+ for (i = deviceid_list; i; i = next) {
+ next = i->next;
+ if (WStrEqual(i->str, devid)) {
+ if (prev) {
+ prev->next = next;
+ } else {
+ deviceid_list = next;
+ }
+ SDL_RemoveAudioDevice(iscapture, i->str);
+ SDL_free(i->str);
+ SDL_free(i);
+ }
+ prev = i;
+ }
+}
+
+void
+WASAPI_AddDevice(const SDL_bool iscapture, const char *devname, LPCWSTR devid)
+{
+ DevIdList *devidlist;
+
+ /* You can have multiple endpoints on a device that are mutually exclusive ("Speakers" vs "Line Out" or whatever).
+ In a perfect world, things that are unplugged won't be in this collection. The only gotcha is probably for
+ phones and tablets, where you might have an internal speaker and a headphone jack and expect both to be
+ available and switch automatically. (!!! FIXME...?) */
+
+ /* see if we already have this one. */
+ for (devidlist = deviceid_list; devidlist; devidlist = devidlist->next) {
+ if (WStrEqual(devidlist->str, devid)) {
+ return; /* we already have this. */
+ }
+ }
+
+ devidlist = (DevIdList *) SDL_malloc(sizeof (*devidlist));
+ if (!devidlist) {
+ return; /* oh well. */
+ }
+
+ devid = WStrDupe(devid);
+ if (!devid) {
+ SDL_free(devidlist);
+ return; /* oh well. */
+ }
+
+ devidlist->str = (WCHAR *) devid;
+ devidlist->next = deviceid_list;
+ deviceid_list = devidlist;
+
+ SDL_AddAudioDevice(iscapture, devname, (void *) devid);
+}
+
+static void
+WASAPI_DetectDevices(void)
+{
+ WASAPI_EnumerateEndpoints();
+}
+
+static int
+WASAPI_GetPendingBytes(_THIS)
+{
+ UINT32 frames = 0;
+
+ /* it's okay to fail here; we'll deal with failures in the audio thread. */
+ /* FIXME: need a lock around checking this->hidden->client */
+ if (this->hidden->client != NULL) { /* definitely activated? */
+ if (FAILED(IAudioClient_GetCurrentPadding(this->hidden->client, &frames))) {
+ return 0; /* oh well. */
+ }
+ }
+ return ((int) frames) * this->hidden->framesize;
+}
+
+static SDL_INLINE SDL_bool
+WasapiFailed(_THIS, const HRESULT err)
+{
+ if (err == S_OK) {
+ return SDL_FALSE;
+ }
+
+ if (err == AUDCLNT_E_DEVICE_INVALIDATED) {
+ this->hidden->device_lost = SDL_TRUE;
+ } else if (SDL_AtomicGet(&this->enabled)) {
+ IAudioClient_Stop(this->hidden->client);
+ SDL_OpenedAudioDeviceDisconnected(this);
+ SDL_assert(!SDL_AtomicGet(&this->enabled));
+ }
+
+ return SDL_TRUE;
+}
+
+static int
+UpdateAudioStream(_THIS, const SDL_AudioSpec *oldspec)
+{
+ /* Since WASAPI requires us to handle all audio conversion, and our
+ device format might have changed, we might have to add/remove/change
+ the audio stream that the higher level uses to convert data, so
+ SDL keeps firing the callback as if nothing happened here. */
+
+ if ( (this->callbackspec.channels == this->spec.channels) &&
+ (this->callbackspec.format == this->spec.format) &&
+ (this->callbackspec.freq == this->spec.freq) &&
+ (this->callbackspec.samples == this->spec.samples) ) {
+ /* no need to buffer/convert in an AudioStream! */
+ SDL_FreeAudioStream(this->stream);
+ this->stream = NULL;
+ } else if ( (oldspec->channels == this->spec.channels) &&
+ (oldspec->format == this->spec.format) &&
+ (oldspec->freq == this->spec.freq) ) {
+ /* The existing audio stream is okay to keep using. */
+ } else {
+ /* replace the audiostream for new format */
+ SDL_FreeAudioStream(this->stream);
+ if (this->iscapture) {
+ this->stream = SDL_NewAudioStream(this->spec.format,
+ this->spec.channels, this->spec.freq,
+ this->callbackspec.format,
+ this->callbackspec.channels,
+ this->callbackspec.freq);
+ } else {
+ this->stream = SDL_NewAudioStream(this->callbackspec.format,
+ this->callbackspec.channels,
+ this->callbackspec.freq, this->spec.format,
+ this->spec.channels, this->spec.freq);
+ }
+
+ if (!this->stream) {
+ return -1;
+ }
+ }
+
+ /* make sure our scratch buffer can cover the new device spec. */
+ if (this->spec.size > this->work_buffer_len) {
+ Uint8 *ptr = (Uint8 *) SDL_realloc(this->work_buffer, this->spec.size);
+ if (ptr == NULL) {
+ return SDL_OutOfMemory();
+ }
+ this->work_buffer = ptr;
+ this->work_buffer_len = this->spec.size;
+ }
+
+ return 0;
+}
+
+
+static void ReleaseWasapiDevice(_THIS);
+
+static SDL_bool
+RecoverWasapiDevice(_THIS)
+{
+ ReleaseWasapiDevice(this); /* dump the lost device's handles. */
+
+ if (this->hidden->default_device_generation) {
+ this->hidden->default_device_generation = SDL_AtomicGet(this->iscapture ? &WASAPI_DefaultCaptureGeneration : &WASAPI_DefaultPlaybackGeneration);
+ }
+
+ /* this can fail for lots of reasons, but the most likely is we had a
+ non-default device that was disconnected, so we can't recover. Default
+ devices try to reinitialize whatever the new default is, so it's more
+ likely to carry on here, but this handles a non-default device that
+ simply had its format changed in the Windows Control Panel. */
+ if (WASAPI_ActivateDevice(this, SDL_TRUE) == -1) {
+ SDL_OpenedAudioDeviceDisconnected(this);
+ return SDL_FALSE;
+ }
+
+ this->hidden->device_lost = SDL_FALSE;
+
+ return SDL_TRUE; /* okay, carry on with new device details! */
+}
+
+static SDL_bool
+RecoverWasapiIfLost(_THIS)
+{
+ const int generation = this->hidden->default_device_generation;
+ SDL_bool lost = this->hidden->device_lost;
+
+ if (!SDL_AtomicGet(&this->enabled)) {
+ return SDL_FALSE; /* already failed. */
+ }
+
+ if (!this->hidden->client) {
+ return SDL_TRUE; /* still waiting for activation. */
+ }
+
+ if (!lost && (generation > 0)) { /* is a default device? */
+ const int newgen = SDL_AtomicGet(this->iscapture ? &WASAPI_DefaultCaptureGeneration : &WASAPI_DefaultPlaybackGeneration);
+ if (generation != newgen) { /* the desired default device was changed, jump over to it. */
+ lost = SDL_TRUE;
+ }
+ }
+
+ return lost ? RecoverWasapiDevice(this) : SDL_TRUE;
+}
+
+static Uint8 *
+WASAPI_GetDeviceBuf(_THIS)
+{
+ /* get an endpoint buffer from WASAPI. */
+ BYTE *buffer = NULL;
+
+ while (RecoverWasapiIfLost(this) && this->hidden->render) {
+ if (!WasapiFailed(this, IAudioRenderClient_GetBuffer(this->hidden->render, this->spec.samples, &buffer))) {
+ return (Uint8 *) buffer;
+ }
+ SDL_assert(buffer == NULL);
+ }
+
+ return (Uint8 *) buffer;
+}
+
+static void
+WASAPI_PlayDevice(_THIS)
+{
+ if (this->hidden->render != NULL) { /* definitely activated? */
+ /* WasapiFailed() will mark the device for reacquisition or removal elsewhere. */
+ WasapiFailed(this, IAudioRenderClient_ReleaseBuffer(this->hidden->render, this->spec.samples, 0));
+ }
+}
+
+static void
+WASAPI_WaitDevice(_THIS)
+{
+ while (RecoverWasapiIfLost(this) && this->hidden->client && this->hidden->event) {
+ /*SDL_Log("WAITDEVICE");*/
+ if (WaitForSingleObjectEx(this->hidden->event, INFINITE, FALSE) == WAIT_OBJECT_0) {
+ const UINT32 maxpadding = this->spec.samples;
+ UINT32 padding = 0;
+ if (!WasapiFailed(this, IAudioClient_GetCurrentPadding(this->hidden->client, &padding))) {
+ /*SDL_Log("WASAPI EVENT! padding=%u maxpadding=%u", (unsigned int)padding, (unsigned int)maxpadding);*/
+ if (padding <= maxpadding) {
+ break;
+ }
+ }
+ } else {
+ /*SDL_Log("WASAPI FAILED EVENT!");*/
+ IAudioClient_Stop(this->hidden->client);
+ SDL_OpenedAudioDeviceDisconnected(this);
+ }
+ }
+}
+
+static int
+WASAPI_CaptureFromDevice(_THIS, void *buffer, int buflen)
+{
+ SDL_AudioStream *stream = this->hidden->capturestream;
+ const int avail = SDL_AudioStreamAvailable(stream);
+ if (avail > 0) {
+ const int cpy = SDL_min(buflen, avail);
+ SDL_AudioStreamGet(stream, buffer, cpy);
+ return cpy;
+ }
+
+ while (RecoverWasapiIfLost(this)) {
+ HRESULT ret;
+ BYTE *ptr = NULL;
+ UINT32 frames = 0;
+ DWORD flags = 0;
+
+ /* uhoh, client isn't activated yet, just return silence. */
+ if (!this->hidden->capture) {
+ /* Delay so we run at about the speed that audio would be arriving. */
+ SDL_Delay(((this->spec.samples * 1000) / this->spec.freq));
+ SDL_memset(buffer, this->spec.silence, buflen);
+ return buflen;
+ }
+
+ ret = IAudioCaptureClient_GetBuffer(this->hidden->capture, &ptr, &frames, &flags, NULL, NULL);
+ if (ret != AUDCLNT_S_BUFFER_EMPTY) {
+ WasapiFailed(this, ret); /* mark device lost/failed if necessary. */
+ }
+
+ if ((ret == AUDCLNT_S_BUFFER_EMPTY) || !frames) {
+ WASAPI_WaitDevice(this);
+ } else if (ret == S_OK) {
+ const int total = ((int) frames) * this->hidden->framesize;
+ const int cpy = SDL_min(buflen, total);
+ const int leftover = total - cpy;
+ const SDL_bool silent = (flags & AUDCLNT_BUFFERFLAGS_SILENT) ? SDL_TRUE : SDL_FALSE;
+
+ if (silent) {
+ SDL_memset(buffer, this->spec.silence, cpy);
+ } else {
+ SDL_memcpy(buffer, ptr, cpy);
+ }
+
+ if (leftover > 0) {
+ ptr += cpy;
+ if (silent) {
+ SDL_memset(ptr, this->spec.silence, leftover); /* I guess this is safe? */
+ }
+
+ if (SDL_AudioStreamPut(stream, ptr, leftover) == -1) {
+ return -1; /* uhoh, out of memory, etc. Kill device. :( */
+ }
+ }
+
+ ret = IAudioCaptureClient_ReleaseBuffer(this->hidden->capture, frames);
+ WasapiFailed(this, ret); /* mark device lost/failed if necessary. */
+
+ return cpy;
+ }
+ }
+
+ return -1; /* unrecoverable error. */
+}
+
+static void
+WASAPI_FlushCapture(_THIS)
+{
+ BYTE *ptr = NULL;
+ UINT32 frames = 0;
+ DWORD flags = 0;
+
+ if (!this->hidden->capture) {
+ return; /* not activated yet? */
+ }
+
+ /* just read until we stop getting packets, throwing them away. */
+ while (SDL_TRUE) {
+ const HRESULT ret = IAudioCaptureClient_GetBuffer(this->hidden->capture, &ptr, &frames, &flags, NULL, NULL);
+ if (ret == AUDCLNT_S_BUFFER_EMPTY) {
+ break; /* no more buffered data; we're done. */
+ } else if (WasapiFailed(this, ret)) {
+ break; /* failed for some other reason, abort. */
+ } else if (WasapiFailed(this, IAudioCaptureClient_ReleaseBuffer(this->hidden->capture, frames))) {
+ break; /* something broke. */
+ }
+ }
+ SDL_AudioStreamClear(this->hidden->capturestream);
+}
+
+static void
+ReleaseWasapiDevice(_THIS)
+{
+ if (this->hidden->client) {
+ IAudioClient_Stop(this->hidden->client);
+ IAudioClient_SetEventHandle(this->hidden->client, NULL);
+ IAudioClient_Release(this->hidden->client);
+ this->hidden->client = NULL;
+ }
+
+ if (this->hidden->render) {
+ IAudioRenderClient_Release(this->hidden->render);
+ this->hidden->render = NULL;
+ }
+
+ if (this->hidden->capture) {
+ IAudioCaptureClient_Release(this->hidden->capture);
+ this->hidden->capture = NULL;
+ }
+
+ if (this->hidden->waveformat) {
+ CoTaskMemFree(this->hidden->waveformat);
+ this->hidden->waveformat = NULL;
+ }
+
+ if (this->hidden->capturestream) {
+ SDL_FreeAudioStream(this->hidden->capturestream);
+ this->hidden->capturestream = NULL;
+ }
+
+ if (this->hidden->activation_handler) {
+ WASAPI_PlatformDeleteActivationHandler(this->hidden->activation_handler);
+ this->hidden->activation_handler = NULL;
+ }
+
+ if (this->hidden->event) {
+ CloseHandle(this->hidden->event);
+ this->hidden->event = NULL;
+ }
+}
+
+static void
+WASAPI_CloseDevice(_THIS)
+{
+ WASAPI_UnrefDevice(this);
+}
+
+void
+WASAPI_RefDevice(_THIS)
+{
+ SDL_AtomicIncRef(&this->hidden->refcount);
+}
+
+void
+WASAPI_UnrefDevice(_THIS)
+{
+ if (!SDL_AtomicDecRef(&this->hidden->refcount)) {
+ return;
+ }
+
+ /* actual closing happens here. */
+
+ /* don't touch this->hidden->task in here; it has to be reverted from
+ our callback thread. We do that in WASAPI_ThreadDeinit().
+ (likewise for this->hidden->coinitialized). */
+ ReleaseWasapiDevice(this);
+ SDL_free(this->hidden->devid);
+ SDL_free(this->hidden);
+}
+
+/* This is called once a device is activated, possibly asynchronously. */
+int
+WASAPI_PrepDevice(_THIS, const SDL_bool updatestream)
+{
+ /* !!! FIXME: we could request an exclusive mode stream, which is lower latency;
+ !!! it will write into the kernel's audio buffer directly instead of
+ !!! shared memory that a user-mode mixer then writes to the kernel with
+ !!! everything else. Doing this means any other sound using this device will
+ !!! stop playing, including the user's MP3 player and system notification
+ !!! sounds. You'd probably need to release the device when the app isn't in
+ !!! the foreground, to be a good citizen of the system. It's doable, but it's
+ !!! more work and causes some annoyances, and I don't know what the latency
+ !!! wins actually look like. Maybe add a hint to force exclusive mode at
+ !!! some point. To be sure, defaulting to shared mode is the right thing to
+ !!! do in any case. */
+ const SDL_AudioSpec oldspec = this->spec;
+ const AUDCLNT_SHAREMODE sharemode = AUDCLNT_SHAREMODE_SHARED;
+ UINT32 bufsize = 0; /* this is in sample frames, not samples, not bytes. */
+ REFERENCE_TIME duration = 0;
+ IAudioClient *client = this->hidden->client;
+ IAudioRenderClient *render = NULL;
+ IAudioCaptureClient *capture = NULL;
+ WAVEFORMATEX *waveformat = NULL;
+ SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
+ SDL_AudioFormat wasapi_format = 0;
+ SDL_bool valid_format = SDL_FALSE;
+ HRESULT ret = S_OK;
+ DWORD streamflags = 0;
+
+ SDL_assert(client != NULL);
+
+#ifdef __WINRT__ /* CreateEventEx() arrived in Vista, so we need an #ifdef for XP. */
+ this->hidden->event = CreateEventEx(NULL, NULL, 0, EVENT_ALL_ACCESS);
+#else
+ this->hidden->event = CreateEventW(NULL, 0, 0, NULL);
+#endif
+
+ if (this->hidden->event == NULL) {
+ return WIN_SetError("WASAPI can't create an event handle");
+ }
+
+ ret = IAudioClient_GetMixFormat(client, &waveformat);
+ if (FAILED(ret)) {
+ return WIN_SetErrorFromHRESULT("WASAPI can't determine mix format", ret);
+ }
+
+ SDL_assert(waveformat != NULL);
+ this->hidden->waveformat = waveformat;
+
+ this->spec.channels = (Uint8) waveformat->nChannels;
+
+ /* Make sure we have a valid format that we can convert to whatever WASAPI wants. */
+ if ((waveformat->wFormatTag == WAVE_FORMAT_IEEE_FLOAT) && (waveformat->wBitsPerSample == 32)) {
+ wasapi_format = AUDIO_F32SYS;
+ } else if ((waveformat->wFormatTag == WAVE_FORMAT_PCM) && (waveformat->wBitsPerSample == 16)) {
+ wasapi_format = AUDIO_S16SYS;
+ } else if ((waveformat->wFormatTag == WAVE_FORMAT_PCM) && (waveformat->wBitsPerSample == 32)) {
+ wasapi_format = AUDIO_S32SYS;
+ } else if (waveformat->wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
+ const WAVEFORMATEXTENSIBLE *ext = (const WAVEFORMATEXTENSIBLE *) waveformat;
+ if ((SDL_memcmp(&ext->SubFormat, &SDL_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, sizeof (GUID)) == 0) && (waveformat->wBitsPerSample == 32)) {
+ wasapi_format = AUDIO_F32SYS;
+ } else if ((SDL_memcmp(&ext->SubFormat, &SDL_KSDATAFORMAT_SUBTYPE_PCM, sizeof (GUID)) == 0) && (waveformat->wBitsPerSample == 16)) {
+ wasapi_format = AUDIO_S16SYS;
+ } else if ((SDL_memcmp(&ext->SubFormat, &SDL_KSDATAFORMAT_SUBTYPE_PCM, sizeof (GUID)) == 0) && (waveformat->wBitsPerSample == 32)) {
+ wasapi_format = AUDIO_S32SYS;
+ }
+ }
+
+ while ((!valid_format) && (test_format)) {
+ if (test_format == wasapi_format) {
+ this->spec.format = test_format;
+ valid_format = SDL_TRUE;
+ break;
+ }
+ test_format = SDL_NextAudioFormat();
+ }
+
+ if (!valid_format) {
+ return SDL_SetError("WASAPI: Unsupported audio format");
+ }
+
+ ret = IAudioClient_GetDevicePeriod(client, NULL, &duration);
+ if (FAILED(ret)) {
+ return WIN_SetErrorFromHRESULT("WASAPI can't determine minimum device period", ret);
+ }
+
+ /* favor WASAPI's resampler over our own, in Win7+. */
+ if (this->spec.freq != waveformat->nSamplesPerSec) {
+ /* RATEADJUST only works with output devices in share mode, and is available in Win7 and later.*/
+ if (WIN_IsWindows7OrGreater() && !this->iscapture && (sharemode == AUDCLNT_SHAREMODE_SHARED)) {
+ streamflags |= AUDCLNT_STREAMFLAGS_RATEADJUST;
+ waveformat->nSamplesPerSec = this->spec.freq;
+ waveformat->nAvgBytesPerSec = waveformat->nSamplesPerSec * waveformat->nChannels * (waveformat->wBitsPerSample / 8);
+ }
+ else {
+ this->spec.freq = waveformat->nSamplesPerSec; /* force sampling rate so our resampler kicks in. */
+ }
+ }
+
+ streamflags |= AUDCLNT_STREAMFLAGS_EVENTCALLBACK;
+ ret = IAudioClient_Initialize(client, sharemode, streamflags, duration, sharemode == AUDCLNT_SHAREMODE_SHARED ? 0 : duration, waveformat, NULL);
+ if (FAILED(ret)) {
+ return WIN_SetErrorFromHRESULT("WASAPI can't initialize audio client", ret);
+ }
+
+ ret = IAudioClient_SetEventHandle(client, this->hidden->event);
+ if (FAILED(ret)) {
+ return WIN_SetErrorFromHRESULT("WASAPI can't set event handle", ret);
+ }
+
+ ret = IAudioClient_GetBufferSize(client, &bufsize);
+ if (FAILED(ret)) {
+ return WIN_SetErrorFromHRESULT("WASAPI can't determine buffer size", ret);
+ }
+
+ this->spec.samples = (Uint16) bufsize;
+ if (!this->iscapture) {
+ this->spec.samples /= 2; /* fill half of the DMA buffer on each run. */
+ }
+
+ /* Update the fragment size as size in bytes */
+ SDL_CalculateAudioSpec(&this->spec);
+
+ this->hidden->framesize = (SDL_AUDIO_BITSIZE(this->spec.format) / 8) * this->spec.channels;
+
+ if (this->iscapture) {
+ this->hidden->capturestream = SDL_NewAudioStream(this->spec.format, this->spec.channels, this->spec.freq, this->spec.format, this->spec.channels, this->spec.freq);
+ if (!this->hidden->capturestream) {
+ return -1; /* already set SDL_Error */
+ }
+
+ ret = IAudioClient_GetService(client, &SDL_IID_IAudioCaptureClient, (void**) &capture);
+ if (FAILED(ret)) {
+ return WIN_SetErrorFromHRESULT("WASAPI can't get capture client service", ret);
+ }
+
+ SDL_assert(capture != NULL);
+ this->hidden->capture = capture;
+ ret = IAudioClient_Start(client);
+ if (FAILED(ret)) {
+ return WIN_SetErrorFromHRESULT("WASAPI can't start capture", ret);
+ }
+
+ WASAPI_FlushCapture(this); /* MSDN says you should flush capture endpoint right after startup. */
+ } else {
+ ret = IAudioClient_GetService(client, &SDL_IID_IAudioRenderClient, (void**) &render);
+ if (FAILED(ret)) {
+ return WIN_SetErrorFromHRESULT("WASAPI can't get render client service", ret);
+ }
+
+ SDL_assert(render != NULL);
+ this->hidden->render = render;
+ ret = IAudioClient_Start(client);
+ if (FAILED(ret)) {
+ return WIN_SetErrorFromHRESULT("WASAPI can't start playback", ret);
+ }
+ }
+
+ if (updatestream) {
+ if (UpdateAudioStream(this, &oldspec) == -1) {
+ return -1;
+ }
+ }
+
+ return 0; /* good to go. */
+}
+
+
+static int
+WASAPI_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ LPCWSTR devid = (LPCWSTR) handle;
+
+ /* Initialize all variables that we clean on shutdown */
+ this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc((sizeof *this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(this->hidden);
+
+ WASAPI_RefDevice(this); /* so CloseDevice() will unref to zero. */
+
+ if (!devid) { /* is default device? */
+ this->hidden->default_device_generation = SDL_AtomicGet(iscapture ? &WASAPI_DefaultCaptureGeneration : &WASAPI_DefaultPlaybackGeneration);
+ } else {
+ this->hidden->devid = WStrDupe(devid);
+ if (!this->hidden->devid) {
+ return SDL_OutOfMemory();
+ }
+ }
+
+ if (WASAPI_ActivateDevice(this, SDL_FALSE) == -1) {
+ return -1; /* already set error. */
+ }
+
+ /* Ready, but waiting for async device activation.
+ Until activation is successful, we will report silence from capture
+ devices and ignore data on playback devices.
+ Also, since we don't know the _actual_ device format until after
+ activation, we let the app have whatever it asks for. We set up
+ an SDL_AudioStream to convert, if necessary, once the activation
+ completes. */
+
+ return 0;
+}
+
+static void
+WASAPI_ThreadInit(_THIS)
+{
+ WASAPI_PlatformThreadInit(this);
+}
+
+static void
+WASAPI_ThreadDeinit(_THIS)
+{
+ WASAPI_PlatformThreadDeinit(this);
+}
+
+static void
+WASAPI_Deinitialize(void)
+{
+ DevIdList *devidlist;
+ DevIdList *next;
+
+ WASAPI_PlatformDeinit();
+
+ for (devidlist = deviceid_list; devidlist; devidlist = next) {
+ next = devidlist->next;
+ SDL_free(devidlist->str);
+ SDL_free(devidlist);
+ }
+ deviceid_list = NULL;
+}
+
+static int
+WASAPI_Init(SDL_AudioDriverImpl * impl)
+{
+ SDL_AtomicSet(&WASAPI_DefaultPlaybackGeneration, 1);
+ SDL_AtomicSet(&WASAPI_DefaultCaptureGeneration, 1);
+
+ if (WASAPI_PlatformInit() == -1) {
+ return 0;
+ }
+
+ /* Set the function pointers */
+ impl->DetectDevices = WASAPI_DetectDevices;
+ impl->ThreadInit = WASAPI_ThreadInit;
+ impl->ThreadDeinit = WASAPI_ThreadDeinit;
+ impl->BeginLoopIteration = WASAPI_BeginLoopIteration;
+ impl->OpenDevice = WASAPI_OpenDevice;
+ impl->PlayDevice = WASAPI_PlayDevice;
+ impl->WaitDevice = WASAPI_WaitDevice;
+ impl->GetPendingBytes = WASAPI_GetPendingBytes;
+ impl->GetDeviceBuf = WASAPI_GetDeviceBuf;
+ impl->CaptureFromDevice = WASAPI_CaptureFromDevice;
+ impl->FlushCapture = WASAPI_FlushCapture;
+ impl->CloseDevice = WASAPI_CloseDevice;
+ impl->Deinitialize = WASAPI_Deinitialize;
+ impl->HasCaptureSupport = 1;
+
+ return 1; /* this audio target is available. */
+}
+
+AudioBootStrap WASAPI_bootstrap = {
+ "wasapi", "WASAPI", WASAPI_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_WASAPI */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/wasapi/SDL_wasapi.h b/src/3rdparty/SDL2/src/audio/wasapi/SDL_wasapi.h
new file mode 100644
index 0000000..142c0e5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/wasapi/SDL_wasapi.h
@@ -0,0 +1,85 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_wasapi_h_
+#define SDL_wasapi_h_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#ifdef __cplusplus
+#define _THIS SDL_AudioDevice *_this
+#else
+#define _THIS SDL_AudioDevice *this
+#endif
+
+struct SDL_PrivateAudioData
+{
+ SDL_atomic_t refcount;
+ WCHAR *devid;
+ WAVEFORMATEX *waveformat;
+ IAudioClient *client;
+ IAudioRenderClient *render;
+ IAudioCaptureClient *capture;
+ SDL_AudioStream *capturestream;
+ HANDLE event;
+ HANDLE task;
+ SDL_bool coinitialized;
+ int framesize;
+ int default_device_generation;
+ SDL_bool device_lost;
+ void *activation_handler;
+ SDL_atomic_t just_activated;
+};
+
+/* these increment as default devices change. Opened default devices pick up changes in their threads. */
+extern SDL_atomic_t WASAPI_DefaultPlaybackGeneration;
+extern SDL_atomic_t WASAPI_DefaultCaptureGeneration;
+
+/* win32 and winrt implementations call into these. */
+int WASAPI_PrepDevice(_THIS, const SDL_bool updatestream);
+void WASAPI_RefDevice(_THIS);
+void WASAPI_UnrefDevice(_THIS);
+void WASAPI_AddDevice(const SDL_bool iscapture, const char *devname, LPCWSTR devid);
+void WASAPI_RemoveDevice(const SDL_bool iscapture, LPCWSTR devid);
+
+/* These are functions that are implemented differently for Windows vs WinRT. */
+int WASAPI_PlatformInit(void);
+void WASAPI_PlatformDeinit(void);
+void WASAPI_EnumerateEndpoints(void);
+int WASAPI_ActivateDevice(_THIS, const SDL_bool isrecovery);
+void WASAPI_PlatformThreadInit(_THIS);
+void WASAPI_PlatformThreadDeinit(_THIS);
+void WASAPI_PlatformDeleteActivationHandler(void *handler);
+void WASAPI_BeginLoopIteration(_THIS);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SDL_wasapi_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/wasapi/SDL_wasapi_win32.c b/src/3rdparty/SDL2/src/audio/wasapi/SDL_wasapi_win32.c
new file mode 100644
index 0000000..8b55582
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/wasapi/SDL_wasapi_win32.c
@@ -0,0 +1,417 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+/* This is code that Windows uses to talk to WASAPI-related system APIs.
+ This is for non-WinRT desktop apps. The C++/CX implementation of these
+ functions, exclusive to WinRT, are in SDL_wasapi_winrt.cpp.
+ The code in SDL_wasapi.c is used by both standard Windows and WinRT builds
+ to deal with audio and calls into these functions. */
+
+#if SDL_AUDIO_DRIVER_WASAPI && !defined(__WINRT__)
+
+#include "../../core/windows/SDL_windows.h"
+#include "SDL_audio.h"
+#include "SDL_timer.h"
+#include "../SDL_audio_c.h"
+#include "../SDL_sysaudio.h"
+#include "SDL_assert.h"
+#include "SDL_log.h"
+
+#define COBJMACROS
+#include <mmdeviceapi.h>
+#include <audioclient.h>
+
+#include "SDL_wasapi.h"
+
+static const ERole SDL_WASAPI_role = eConsole; /* !!! FIXME: should this be eMultimedia? Should be a hint? */
+
+/* This is global to the WASAPI target, to handle hotplug and default device lookup. */
+static IMMDeviceEnumerator *enumerator = NULL;
+
+/* PropVariantInit() is an inline function/macro in PropIdl.h that calls the C runtime's memset() directly. Use ours instead, to avoid dependency. */
+#ifdef PropVariantInit
+#undef PropVariantInit
+#endif
+#define PropVariantInit(p) SDL_zerop(p)
+
+/* handle to Avrt.dll--Vista and later!--for flagging the callback thread as "Pro Audio" (low latency). */
+static HMODULE libavrt = NULL;
+typedef HANDLE(WINAPI *pfnAvSetMmThreadCharacteristicsW)(LPWSTR, LPDWORD);
+typedef BOOL(WINAPI *pfnAvRevertMmThreadCharacteristics)(HANDLE);
+static pfnAvSetMmThreadCharacteristicsW pAvSetMmThreadCharacteristicsW = NULL;
+static pfnAvRevertMmThreadCharacteristics pAvRevertMmThreadCharacteristics = NULL;
+
+/* Some GUIDs we need to know without linking to libraries that aren't available before Vista. */
+static const CLSID SDL_CLSID_MMDeviceEnumerator = { 0xbcde0395, 0xe52f, 0x467c,{ 0x8e, 0x3d, 0xc4, 0x57, 0x92, 0x91, 0x69, 0x2e } };
+static const IID SDL_IID_IMMDeviceEnumerator = { 0xa95664d2, 0x9614, 0x4f35,{ 0xa7, 0x46, 0xde, 0x8d, 0xb6, 0x36, 0x17, 0xe6 } };
+static const IID SDL_IID_IMMNotificationClient = { 0x7991eec9, 0x7e89, 0x4d85,{ 0x83, 0x90, 0x6c, 0x70, 0x3c, 0xec, 0x60, 0xc0 } };
+static const IID SDL_IID_IMMEndpoint = { 0x1be09788, 0x6894, 0x4089,{ 0x85, 0x86, 0x9a, 0x2a, 0x6c, 0x26, 0x5a, 0xc5 } };
+static const IID SDL_IID_IAudioClient = { 0x1cb9ad4c, 0xdbfa, 0x4c32,{ 0xb1, 0x78, 0xc2, 0xf5, 0x68, 0xa7, 0x03, 0xb2 } };
+static const PROPERTYKEY SDL_PKEY_Device_FriendlyName = { { 0xa45c254e, 0xdf1c, 0x4efd,{ 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, } }, 14 };
+
+
+static char *
+GetWasapiDeviceName(IMMDevice *device)
+{
+ /* PKEY_Device_FriendlyName gives you "Speakers (SoundBlaster Pro)" which drives me nuts. I'd rather it be
+ "SoundBlaster Pro (Speakers)" but I guess that's developers vs users. Windows uses the FriendlyName in
+ its own UIs, like Volume Control, etc. */
+ char *utf8dev = NULL;
+ IPropertyStore *props = NULL;
+ if (SUCCEEDED(IMMDevice_OpenPropertyStore(device, STGM_READ, &props))) {
+ PROPVARIANT var;
+ PropVariantInit(&var);
+ if (SUCCEEDED(IPropertyStore_GetValue(props, &SDL_PKEY_Device_FriendlyName, &var))) {
+ utf8dev = WIN_StringToUTF8(var.pwszVal);
+ }
+ PropVariantClear(&var);
+ IPropertyStore_Release(props);
+ }
+ return utf8dev;
+}
+
+
+/* We need a COM subclass of IMMNotificationClient for hotplug support, which is
+ easy in C++, but we have to tapdance more to make work in C.
+ Thanks to this page for coaching on how to make this work:
+ https://www.codeproject.com/Articles/13601/COM-in-plain-C */
+
+typedef struct SDLMMNotificationClient
+{
+ const IMMNotificationClientVtbl *lpVtbl;
+ SDL_atomic_t refcount;
+} SDLMMNotificationClient;
+
+static HRESULT STDMETHODCALLTYPE
+SDLMMNotificationClient_QueryInterface(IMMNotificationClient *this, REFIID iid, void **ppv)
+{
+ if ((WIN_IsEqualIID(iid, &IID_IUnknown)) || (WIN_IsEqualIID(iid, &SDL_IID_IMMNotificationClient)))
+ {
+ *ppv = this;
+ this->lpVtbl->AddRef(this);
+ return S_OK;
+ }
+
+ *ppv = NULL;
+ return E_NOINTERFACE;
+}
+
+static ULONG STDMETHODCALLTYPE
+SDLMMNotificationClient_AddRef(IMMNotificationClient *ithis)
+{
+ SDLMMNotificationClient *this = (SDLMMNotificationClient *) ithis;
+ return (ULONG) (SDL_AtomicIncRef(&this->refcount) + 1);
+}
+
+static ULONG STDMETHODCALLTYPE
+SDLMMNotificationClient_Release(IMMNotificationClient *ithis)
+{
+ /* this is a static object; we don't ever free it. */
+ SDLMMNotificationClient *this = (SDLMMNotificationClient *) ithis;
+ const ULONG retval = SDL_AtomicDecRef(&this->refcount);
+ if (retval == 0) {
+ SDL_AtomicSet(&this->refcount, 0); /* uhh... */
+ return 0;
+ }
+ return retval - 1;
+}
+
+/* These are the entry points called when WASAPI device endpoints change. */
+static HRESULT STDMETHODCALLTYPE
+SDLMMNotificationClient_OnDefaultDeviceChanged(IMMNotificationClient *ithis, EDataFlow flow, ERole role, LPCWSTR pwstrDeviceId)
+{
+ if (role != SDL_WASAPI_role) {
+ return S_OK; /* ignore it. */
+ }
+
+ /* Increment the "generation," so opened devices will pick this up in their threads. */
+ switch (flow) {
+ case eRender:
+ SDL_AtomicAdd(&WASAPI_DefaultPlaybackGeneration, 1);
+ break;
+
+ case eCapture:
+ SDL_AtomicAdd(&WASAPI_DefaultCaptureGeneration, 1);
+ break;
+
+ case eAll:
+ SDL_AtomicAdd(&WASAPI_DefaultPlaybackGeneration, 1);
+ SDL_AtomicAdd(&WASAPI_DefaultCaptureGeneration, 1);
+ break;
+
+ default:
+ SDL_assert(!"uhoh, unexpected OnDefaultDeviceChange flow!");
+ break;
+ }
+
+ return S_OK;
+}
+
+static HRESULT STDMETHODCALLTYPE
+SDLMMNotificationClient_OnDeviceAdded(IMMNotificationClient *ithis, LPCWSTR pwstrDeviceId)
+{
+ /* we ignore this; devices added here then progress to ACTIVE, if appropriate, in
+ OnDeviceStateChange, making that a better place to deal with device adds. More
+ importantly: the first time you plug in a USB audio device, this callback will
+ fire, but when you unplug it, it isn't removed (it's state changes to NOTPRESENT).
+ Plugging it back in won't fire this callback again. */
+ return S_OK;
+}
+
+static HRESULT STDMETHODCALLTYPE
+SDLMMNotificationClient_OnDeviceRemoved(IMMNotificationClient *ithis, LPCWSTR pwstrDeviceId)
+{
+ /* See notes in OnDeviceAdded handler about why we ignore this. */
+ return S_OK;
+}
+
+static HRESULT STDMETHODCALLTYPE
+SDLMMNotificationClient_OnDeviceStateChanged(IMMNotificationClient *ithis, LPCWSTR pwstrDeviceId, DWORD dwNewState)
+{
+ IMMDevice *device = NULL;
+
+ if (SUCCEEDED(IMMDeviceEnumerator_GetDevice(enumerator, pwstrDeviceId, &device))) {
+ IMMEndpoint *endpoint = NULL;
+ if (SUCCEEDED(IMMDevice_QueryInterface(device, &SDL_IID_IMMEndpoint, (void **) &endpoint))) {
+ EDataFlow flow;
+ if (SUCCEEDED(IMMEndpoint_GetDataFlow(endpoint, &flow))) {
+ const SDL_bool iscapture = (flow == eCapture);
+ if (dwNewState == DEVICE_STATE_ACTIVE) {
+ char *utf8dev = GetWasapiDeviceName(device);
+ if (utf8dev) {
+ WASAPI_AddDevice(iscapture, utf8dev, pwstrDeviceId);
+ SDL_free(utf8dev);
+ }
+ } else {
+ WASAPI_RemoveDevice(iscapture, pwstrDeviceId);
+ }
+ }
+ IMMEndpoint_Release(endpoint);
+ }
+ IMMDevice_Release(device);
+ }
+
+ return S_OK;
+}
+
+static HRESULT STDMETHODCALLTYPE
+SDLMMNotificationClient_OnPropertyValueChanged(IMMNotificationClient *this, LPCWSTR pwstrDeviceId, const PROPERTYKEY key)
+{
+ return S_OK; /* we don't care about these. */
+}
+
+static const IMMNotificationClientVtbl notification_client_vtbl = {
+ SDLMMNotificationClient_QueryInterface,
+ SDLMMNotificationClient_AddRef,
+ SDLMMNotificationClient_Release,
+ SDLMMNotificationClient_OnDeviceStateChanged,
+ SDLMMNotificationClient_OnDeviceAdded,
+ SDLMMNotificationClient_OnDeviceRemoved,
+ SDLMMNotificationClient_OnDefaultDeviceChanged,
+ SDLMMNotificationClient_OnPropertyValueChanged
+};
+
+static SDLMMNotificationClient notification_client = { &notification_client_vtbl, { 1 } };
+
+
+int
+WASAPI_PlatformInit(void)
+{
+ HRESULT ret;
+
+ /* just skip the discussion with COM here. */
+ if (!WIN_IsWindowsVistaOrGreater()) {
+ return SDL_SetError("WASAPI support requires Windows Vista or later");
+ }
+
+ if (FAILED(WIN_CoInitialize())) {
+ return SDL_SetError("WASAPI: CoInitialize() failed");
+ }
+
+ ret = CoCreateInstance(&SDL_CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &SDL_IID_IMMDeviceEnumerator, (LPVOID) &enumerator);
+ if (FAILED(ret)) {
+ WIN_CoUninitialize();
+ return WIN_SetErrorFromHRESULT("WASAPI CoCreateInstance(MMDeviceEnumerator)", ret);
+ }
+
+ libavrt = LoadLibraryW(L"avrt.dll"); /* this library is available in Vista and later. No WinXP, so have to LoadLibrary to use it for now! */
+ if (libavrt) {
+ pAvSetMmThreadCharacteristicsW = (pfnAvSetMmThreadCharacteristicsW) GetProcAddress(libavrt, "AvSetMmThreadCharacteristicsW");
+ pAvRevertMmThreadCharacteristics = (pfnAvRevertMmThreadCharacteristics) GetProcAddress(libavrt, "AvRevertMmThreadCharacteristics");
+ }
+
+ return 0;
+}
+
+void
+WASAPI_PlatformDeinit(void)
+{
+ if (enumerator) {
+ IMMDeviceEnumerator_UnregisterEndpointNotificationCallback(enumerator, (IMMNotificationClient *) &notification_client);
+ IMMDeviceEnumerator_Release(enumerator);
+ enumerator = NULL;
+ }
+
+ if (libavrt) {
+ FreeLibrary(libavrt);
+ libavrt = NULL;
+ }
+
+ pAvSetMmThreadCharacteristicsW = NULL;
+ pAvRevertMmThreadCharacteristics = NULL;
+
+ WIN_CoUninitialize();
+}
+
+void
+WASAPI_PlatformThreadInit(_THIS)
+{
+ /* this thread uses COM. */
+ if (SUCCEEDED(WIN_CoInitialize())) { /* can't report errors, hope it worked! */
+ this->hidden->coinitialized = SDL_TRUE;
+ }
+
+ /* Set this thread to very high "Pro Audio" priority. */
+ if (pAvSetMmThreadCharacteristicsW) {
+ DWORD idx = 0;
+ this->hidden->task = pAvSetMmThreadCharacteristicsW(TEXT("Pro Audio"), &idx);
+ }
+}
+
+void
+WASAPI_PlatformThreadDeinit(_THIS)
+{
+ /* Set this thread back to normal priority. */
+ if (this->hidden->task && pAvRevertMmThreadCharacteristics) {
+ pAvRevertMmThreadCharacteristics(this->hidden->task);
+ this->hidden->task = NULL;
+ }
+
+ if (this->hidden->coinitialized) {
+ WIN_CoUninitialize();
+ this->hidden->coinitialized = SDL_FALSE;
+ }
+}
+
+int
+WASAPI_ActivateDevice(_THIS, const SDL_bool isrecovery)
+{
+ LPCWSTR devid = this->hidden->devid;
+ IMMDevice *device = NULL;
+ HRESULT ret;
+
+ if (devid == NULL) {
+ const EDataFlow dataflow = this->iscapture ? eCapture : eRender;
+ ret = IMMDeviceEnumerator_GetDefaultAudioEndpoint(enumerator, dataflow, SDL_WASAPI_role, &device);
+ } else {
+ ret = IMMDeviceEnumerator_GetDevice(enumerator, devid, &device);
+ }
+
+ if (FAILED(ret)) {
+ SDL_assert(device == NULL);
+ this->hidden->client = NULL;
+ return WIN_SetErrorFromHRESULT("WASAPI can't find requested audio endpoint", ret);
+ }
+
+ /* this is not async in standard win32, yay! */
+ ret = IMMDevice_Activate(device, &SDL_IID_IAudioClient, CLSCTX_ALL, NULL, (void **) &this->hidden->client);
+ IMMDevice_Release(device);
+
+ if (FAILED(ret)) {
+ SDL_assert(this->hidden->client == NULL);
+ return WIN_SetErrorFromHRESULT("WASAPI can't activate audio endpoint", ret);
+ }
+
+ SDL_assert(this->hidden->client != NULL);
+ if (WASAPI_PrepDevice(this, isrecovery) == -1) { /* not async, fire it right away. */
+ return -1;
+ }
+
+ return 0; /* good to go. */
+}
+
+
+static void
+WASAPI_EnumerateEndpointsForFlow(const SDL_bool iscapture)
+{
+ IMMDeviceCollection *collection = NULL;
+ UINT i, total;
+
+ /* Note that WASAPI separates "adapter devices" from "audio endpoint devices"
+ ...one adapter device ("SoundBlaster Pro") might have multiple endpoint devices ("Speakers", "Line-Out"). */
+
+ if (FAILED(IMMDeviceEnumerator_EnumAudioEndpoints(enumerator, iscapture ? eCapture : eRender, DEVICE_STATE_ACTIVE, &collection))) {
+ return;
+ }
+
+ if (FAILED(IMMDeviceCollection_GetCount(collection, &total))) {
+ IMMDeviceCollection_Release(collection);
+ return;
+ }
+
+ for (i = 0; i < total; i++) {
+ IMMDevice *device = NULL;
+ if (SUCCEEDED(IMMDeviceCollection_Item(collection, i, &device))) {
+ LPWSTR devid = NULL;
+ if (SUCCEEDED(IMMDevice_GetId(device, &devid))) {
+ char *devname = GetWasapiDeviceName(device);
+ if (devname) {
+ WASAPI_AddDevice(iscapture, devname, devid);
+ SDL_free(devname);
+ }
+ CoTaskMemFree(devid);
+ }
+ IMMDevice_Release(device);
+ }
+ }
+
+ IMMDeviceCollection_Release(collection);
+}
+
+void
+WASAPI_EnumerateEndpoints(void)
+{
+ WASAPI_EnumerateEndpointsForFlow(SDL_FALSE); /* playback */
+ WASAPI_EnumerateEndpointsForFlow(SDL_TRUE); /* capture */
+
+ /* if this fails, we just won't get hotplug events. Carry on anyhow. */
+ IMMDeviceEnumerator_RegisterEndpointNotificationCallback(enumerator, (IMMNotificationClient *) &notification_client);
+}
+
+void
+WASAPI_PlatformDeleteActivationHandler(void *handler)
+{
+ /* not asynchronous. */
+ SDL_assert(!"This function should have only been called on WinRT.");
+}
+
+void
+WASAPI_BeginLoopIteration(_THIS)
+{
+ /* no-op. */
+}
+
+#endif /* SDL_AUDIO_DRIVER_WASAPI && !defined(__WINRT__) */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/audio/wasapi/SDL_wasapi_winrt.cpp b/src/3rdparty/SDL2/src/audio/wasapi/SDL_wasapi_winrt.cpp
new file mode 100644
index 0000000..309ec6a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/wasapi/SDL_wasapi_winrt.cpp
@@ -0,0 +1,276 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+// This is C++/CX code that the WinRT port uses to talk to WASAPI-related
+// system APIs. The C implementation of these functions, for non-WinRT apps,
+// is in SDL_wasapi_win32.c. The code in SDL_wasapi.c is used by both standard
+// Windows and WinRT builds to deal with audio and calls into these functions.
+
+#if SDL_AUDIO_DRIVER_WASAPI && defined(__WINRT__)
+
+#include <Windows.h>
+#include <windows.ui.core.h>
+#include <windows.devices.enumeration.h>
+#include <windows.media.devices.h>
+#include <wrl/implements.h>
+
+extern "C" {
+#include "../../core/windows/SDL_windows.h"
+#include "SDL_audio.h"
+#include "SDL_timer.h"
+#include "../SDL_audio_c.h"
+#include "../SDL_sysaudio.h"
+#include "SDL_assert.h"
+#include "SDL_log.h"
+}
+
+#define COBJMACROS
+#include <mmdeviceapi.h>
+#include <audioclient.h>
+
+#include "SDL_wasapi.h"
+
+using namespace Windows::Devices::Enumeration;
+using namespace Windows::Media::Devices;
+using namespace Windows::Foundation;
+using namespace Microsoft::WRL;
+
+class SDL_WasapiDeviceEventHandler
+{
+public:
+ SDL_WasapiDeviceEventHandler(const SDL_bool _iscapture);
+ ~SDL_WasapiDeviceEventHandler();
+ void OnDeviceAdded(DeviceWatcher^ sender, DeviceInformation^ args);
+ void OnDeviceRemoved(DeviceWatcher^ sender, DeviceInformationUpdate^ args);
+ void OnDeviceUpdated(DeviceWatcher^ sender, DeviceInformationUpdate^ args);
+ void OnDefaultRenderDeviceChanged(Platform::Object^ sender, DefaultAudioRenderDeviceChangedEventArgs^ args);
+ void OnDefaultCaptureDeviceChanged(Platform::Object^ sender, DefaultAudioCaptureDeviceChangedEventArgs^ args);
+
+private:
+ const SDL_bool iscapture;
+ DeviceWatcher^ watcher;
+ Windows::Foundation::EventRegistrationToken added_handler;
+ Windows::Foundation::EventRegistrationToken removed_handler;
+ Windows::Foundation::EventRegistrationToken updated_handler;
+ Windows::Foundation::EventRegistrationToken default_changed_handler;
+};
+
+SDL_WasapiDeviceEventHandler::SDL_WasapiDeviceEventHandler(const SDL_bool _iscapture)
+ : iscapture(_iscapture)
+ , watcher(DeviceInformation::CreateWatcher(_iscapture ? DeviceClass::AudioCapture : DeviceClass::AudioRender))
+{
+ if (!watcher)
+ return; // uhoh.
+
+ // !!! FIXME: this doesn't need a lambda here, I think, if I make SDL_WasapiDeviceEventHandler a proper C++/CX class. --ryan.
+ added_handler = watcher->Added += ref new TypedEventHandler<DeviceWatcher^, DeviceInformation^>([this](DeviceWatcher^ sender, DeviceInformation^ args) { OnDeviceAdded(sender, args); } );
+ removed_handler = watcher->Removed += ref new TypedEventHandler<DeviceWatcher^, DeviceInformationUpdate^>([this](DeviceWatcher^ sender, DeviceInformationUpdate^ args) { OnDeviceRemoved(sender, args); } );
+ updated_handler = watcher->Updated += ref new TypedEventHandler<DeviceWatcher^, DeviceInformationUpdate^>([this](DeviceWatcher^ sender, DeviceInformationUpdate^ args) { OnDeviceUpdated(sender, args); } );
+ if (iscapture) {
+ default_changed_handler = MediaDevice::DefaultAudioCaptureDeviceChanged += ref new TypedEventHandler<Platform::Object^, DefaultAudioCaptureDeviceChangedEventArgs^>([this](Platform::Object^ sender, DefaultAudioCaptureDeviceChangedEventArgs^ args) { OnDefaultCaptureDeviceChanged(sender, args); } );
+ } else {
+ default_changed_handler = MediaDevice::DefaultAudioRenderDeviceChanged += ref new TypedEventHandler<Platform::Object^, DefaultAudioRenderDeviceChangedEventArgs^>([this](Platform::Object^ sender, DefaultAudioRenderDeviceChangedEventArgs^ args) { OnDefaultRenderDeviceChanged(sender, args); } );
+ }
+ watcher->Start();
+}
+
+SDL_WasapiDeviceEventHandler::~SDL_WasapiDeviceEventHandler()
+{
+ if (watcher) {
+ watcher->Added -= added_handler;
+ watcher->Removed -= removed_handler;
+ watcher->Updated -= updated_handler;
+ watcher->Stop();
+ watcher = nullptr;
+ }
+
+ if (iscapture) {
+ MediaDevice::DefaultAudioCaptureDeviceChanged -= default_changed_handler;
+ } else {
+ MediaDevice::DefaultAudioRenderDeviceChanged -= default_changed_handler;
+ }
+}
+
+void
+SDL_WasapiDeviceEventHandler::OnDeviceAdded(DeviceWatcher^ sender, DeviceInformation^ info)
+{
+ SDL_assert(sender == this->watcher);
+ char *utf8dev = WIN_StringToUTF8(info->Name->Data());
+ if (utf8dev) {
+ WASAPI_AddDevice(this->iscapture, utf8dev, info->Id->Data());
+ SDL_free(utf8dev);
+ }
+}
+
+void
+SDL_WasapiDeviceEventHandler::OnDeviceRemoved(DeviceWatcher^ sender, DeviceInformationUpdate^ info)
+{
+ SDL_assert(sender == this->watcher);
+ WASAPI_RemoveDevice(this->iscapture, info->Id->Data());
+}
+
+void
+SDL_WasapiDeviceEventHandler::OnDeviceUpdated(DeviceWatcher^ sender, DeviceInformationUpdate^ args)
+{
+ SDL_assert(sender == this->watcher);
+}
+
+void
+SDL_WasapiDeviceEventHandler::OnDefaultRenderDeviceChanged(Platform::Object^ sender, DefaultAudioRenderDeviceChangedEventArgs^ args)
+{
+ SDL_assert(this->iscapture);
+ SDL_AtomicAdd(&WASAPI_DefaultPlaybackGeneration, 1);
+}
+
+void
+SDL_WasapiDeviceEventHandler::OnDefaultCaptureDeviceChanged(Platform::Object^ sender, DefaultAudioCaptureDeviceChangedEventArgs^ args)
+{
+ SDL_assert(!this->iscapture);
+ SDL_AtomicAdd(&WASAPI_DefaultCaptureGeneration, 1);
+}
+
+
+static SDL_WasapiDeviceEventHandler *playback_device_event_handler;
+static SDL_WasapiDeviceEventHandler *capture_device_event_handler;
+
+int WASAPI_PlatformInit(void)
+{
+ return 0;
+}
+
+void WASAPI_PlatformDeinit(void)
+{
+ delete playback_device_event_handler;
+ playback_device_event_handler = nullptr;
+ delete capture_device_event_handler;
+ capture_device_event_handler = nullptr;
+}
+
+void WASAPI_EnumerateEndpoints(void)
+{
+ // DeviceWatchers will fire an Added event for each existing device at
+ // startup, so we don't need to enumerate them separately before
+ // listening for updates.
+ playback_device_event_handler = new SDL_WasapiDeviceEventHandler(SDL_FALSE);
+ capture_device_event_handler = new SDL_WasapiDeviceEventHandler(SDL_TRUE);
+}
+
+struct SDL_WasapiActivationHandler : public RuntimeClass< RuntimeClassFlags< ClassicCom >, FtmBase, IActivateAudioInterfaceCompletionHandler >
+{
+ SDL_WasapiActivationHandler() : device(nullptr) {}
+ STDMETHOD(ActivateCompleted)(IActivateAudioInterfaceAsyncOperation *operation);
+ SDL_AudioDevice *device;
+};
+
+HRESULT
+SDL_WasapiActivationHandler::ActivateCompleted(IActivateAudioInterfaceAsyncOperation *async)
+{
+ HRESULT result = S_OK;
+ IUnknown *iunknown = nullptr;
+ const HRESULT ret = async->GetActivateResult(&result, &iunknown);
+
+ if (SUCCEEDED(ret) && SUCCEEDED(result)) {
+ iunknown->QueryInterface(IID_PPV_ARGS(&device->hidden->client));
+ if (device->hidden->client) {
+ // Just set a flag, since we're probably in a different thread. We'll pick it up and init everything on our own thread to prevent races.
+ SDL_AtomicSet(&device->hidden->just_activated, 1);
+ }
+ }
+
+ WASAPI_UnrefDevice(device);
+
+ return S_OK;
+}
+
+void
+WASAPI_PlatformDeleteActivationHandler(void *handler)
+{
+ ((SDL_WasapiActivationHandler *) handler)->Release();
+}
+
+int
+WASAPI_ActivateDevice(_THIS, const SDL_bool isrecovery)
+{
+ LPCWSTR devid = _this->hidden->devid;
+ Platform::String^ defdevid;
+
+ if (devid == nullptr) {
+ defdevid = _this->iscapture ? MediaDevice::GetDefaultAudioCaptureId(AudioDeviceRole::Default) : MediaDevice::GetDefaultAudioRenderId(AudioDeviceRole::Default);
+ if (defdevid) {
+ devid = defdevid->Data();
+ }
+ }
+
+ SDL_AtomicSet(&_this->hidden->just_activated, 0);
+
+ ComPtr<SDL_WasapiActivationHandler> handler = Make<SDL_WasapiActivationHandler>();
+ if (handler == nullptr) {
+ return SDL_SetError("Failed to allocate WASAPI activation handler");
+ }
+
+ handler.Get()->AddRef(); // we hold a reference after ComPtr destructs on return, causing a Release, and Release ourselves in WASAPI_PlatformDeleteActivationHandler(), etc.
+ handler.Get()->device = _this;
+ _this->hidden->activation_handler = handler.Get();
+
+ WASAPI_RefDevice(_this); /* completion handler will unref it. */
+ IActivateAudioInterfaceAsyncOperation *async = nullptr;
+ const HRESULT ret = ActivateAudioInterfaceAsync(devid, __uuidof(IAudioClient), nullptr, handler.Get(), &async);
+
+ if (async != nullptr) {
+ async->Release();
+ }
+
+ if (FAILED(ret)) {
+ handler.Get()->Release();
+ WASAPI_UnrefDevice(_this);
+ return WIN_SetErrorFromHRESULT("WASAPI can't activate requested audio endpoint", ret);
+ }
+
+ return 0;
+}
+
+void
+WASAPI_BeginLoopIteration(_THIS)
+{
+ if (SDL_AtomicCAS(&_this->hidden->just_activated, 1, 0)) {
+ if (WASAPI_PrepDevice(_this, SDL_TRUE) == -1) {
+ SDL_OpenedAudioDeviceDisconnected(_this);
+ }
+ }
+}
+
+void
+WASAPI_PlatformThreadInit(_THIS)
+{
+ // !!! FIXME: set this thread to "Pro Audio" priority.
+}
+
+void
+WASAPI_PlatformThreadDeinit(_THIS)
+{
+ // !!! FIXME: set this thread to "Pro Audio" priority.
+}
+
+#endif // SDL_AUDIO_DRIVER_WASAPI && defined(__WINRT__)
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/winmm/SDL_winmm.c b/src/3rdparty/SDL2/src/audio/winmm/SDL_winmm.c
new file mode 100644
index 0000000..8e5c17b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/winmm/SDL_winmm.c
@@ -0,0 +1,457 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_WINMM
+
+/* Allow access to a raw mixing buffer */
+
+#include "../../core/windows/SDL_windows.h"
+#include <mmsystem.h>
+
+#include "SDL_assert.h"
+#include "SDL_timer.h"
+#include "SDL_audio.h"
+#include "../SDL_audio_c.h"
+#include "SDL_winmm.h"
+
+/* MinGW32 mmsystem.h doesn't include these structures */
+#if defined(__MINGW32__) && defined(_MMSYSTEM_H)
+
+typedef struct tagWAVEINCAPS2W
+{
+ WORD wMid;
+ WORD wPid;
+ MMVERSION vDriverVersion;
+ WCHAR szPname[MAXPNAMELEN];
+ DWORD dwFormats;
+ WORD wChannels;
+ WORD wReserved1;
+ GUID ManufacturerGuid;
+ GUID ProductGuid;
+ GUID NameGuid;
+} WAVEINCAPS2W,*PWAVEINCAPS2W,*NPWAVEINCAPS2W,*LPWAVEINCAPS2W;
+
+typedef struct tagWAVEOUTCAPS2W
+{
+ WORD wMid;
+ WORD wPid;
+ MMVERSION vDriverVersion;
+ WCHAR szPname[MAXPNAMELEN];
+ DWORD dwFormats;
+ WORD wChannels;
+ WORD wReserved1;
+ DWORD dwSupport;
+ GUID ManufacturerGuid;
+ GUID ProductGuid;
+ GUID NameGuid;
+} WAVEOUTCAPS2W,*PWAVEOUTCAPS2W,*NPWAVEOUTCAPS2W,*LPWAVEOUTCAPS2W;
+
+#endif /* defined(__MINGW32__) && defined(_MMSYSTEM_H) */
+
+#ifndef WAVE_FORMAT_IEEE_FLOAT
+#define WAVE_FORMAT_IEEE_FLOAT 0x0003
+#endif
+
+#define DETECT_DEV_IMPL(iscap, typ, capstyp) \
+static void DetectWave##typ##Devs(void) { \
+ const UINT iscapture = iscap ? 1 : 0; \
+ const UINT devcount = wave##typ##GetNumDevs(); \
+ capstyp##2W caps; \
+ UINT i; \
+ for (i = 0; i < devcount; i++) { \
+ if (wave##typ##GetDevCaps(i,(LP##capstyp##W)&caps,sizeof(caps))==MMSYSERR_NOERROR) { \
+ char *name = WIN_LookupAudioDeviceName(caps.szPname,&caps.NameGuid); \
+ if (name != NULL) { \
+ SDL_AddAudioDevice((int) iscapture, name, (void *) ((size_t) i+1)); \
+ SDL_free(name); \
+ } \
+ } \
+ } \
+}
+
+DETECT_DEV_IMPL(SDL_FALSE, Out, WAVEOUTCAPS)
+DETECT_DEV_IMPL(SDL_TRUE, In, WAVEINCAPS)
+
+static void
+WINMM_DetectDevices(void)
+{
+ DetectWaveInDevs();
+ DetectWaveOutDevs();
+}
+
+static void CALLBACK
+CaptureSound(HWAVEIN hwi, UINT uMsg, DWORD_PTR dwInstance,
+ DWORD_PTR dwParam1, DWORD_PTR dwParam2)
+{
+ SDL_AudioDevice *this = (SDL_AudioDevice *) dwInstance;
+
+ /* Only service "buffer is filled" messages */
+ if (uMsg != WIM_DATA)
+ return;
+
+ /* Signal that we have a new buffer of data */
+ ReleaseSemaphore(this->hidden->audio_sem, 1, NULL);
+}
+
+
+/* The Win32 callback for filling the WAVE device */
+static void CALLBACK
+FillSound(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance,
+ DWORD_PTR dwParam1, DWORD_PTR dwParam2)
+{
+ SDL_AudioDevice *this = (SDL_AudioDevice *) dwInstance;
+
+ /* Only service "buffer done playing" messages */
+ if (uMsg != WOM_DONE)
+ return;
+
+ /* Signal that we are done playing a buffer */
+ ReleaseSemaphore(this->hidden->audio_sem, 1, NULL);
+}
+
+static int
+SetMMerror(char *function, MMRESULT code)
+{
+ int len;
+ char errbuf[MAXERRORLENGTH];
+ wchar_t werrbuf[MAXERRORLENGTH];
+
+ SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function);
+ len = SDL_static_cast(int, SDL_strlen(errbuf));
+
+ waveOutGetErrorText(code, werrbuf, MAXERRORLENGTH - len);
+ WideCharToMultiByte(CP_ACP, 0, werrbuf, -1, errbuf + len,
+ MAXERRORLENGTH - len, NULL, NULL);
+
+ return SDL_SetError("%s", errbuf);
+}
+
+static void
+WINMM_WaitDevice(_THIS)
+{
+ /* Wait for an audio chunk to finish */
+ WaitForSingleObject(this->hidden->audio_sem, INFINITE);
+}
+
+static Uint8 *
+WINMM_GetDeviceBuf(_THIS)
+{
+ return (Uint8 *) (this->hidden->
+ wavebuf[this->hidden->next_buffer].lpData);
+}
+
+static void
+WINMM_PlayDevice(_THIS)
+{
+ /* Queue it up */
+ waveOutWrite(this->hidden->hout,
+ &this->hidden->wavebuf[this->hidden->next_buffer],
+ sizeof(this->hidden->wavebuf[0]));
+ this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS;
+}
+
+static int
+WINMM_CaptureFromDevice(_THIS, void *buffer, int buflen)
+{
+ const int nextbuf = this->hidden->next_buffer;
+ MMRESULT result;
+
+ SDL_assert(buflen == this->spec.size);
+
+ /* Wait for an audio chunk to finish */
+ WaitForSingleObject(this->hidden->audio_sem, INFINITE);
+
+ /* Copy it to caller's buffer... */
+ SDL_memcpy(buffer, this->hidden->wavebuf[nextbuf].lpData, this->spec.size);
+
+ /* requeue the buffer that just finished. */
+ result = waveInAddBuffer(this->hidden->hin,
+ &this->hidden->wavebuf[nextbuf],
+ sizeof (this->hidden->wavebuf[nextbuf]));
+ if (result != MMSYSERR_NOERROR) {
+ return -1; /* uhoh! Disable the device. */
+ }
+
+ /* queue the next buffer in sequence, next time. */
+ this->hidden->next_buffer = (nextbuf + 1) % NUM_BUFFERS;
+ return this->spec.size;
+}
+
+static void
+WINMM_FlushCapture(_THIS)
+{
+ /* Wait for an audio chunk to finish */
+ if (WaitForSingleObject(this->hidden->audio_sem, 0) == WAIT_OBJECT_0) {
+ const int nextbuf = this->hidden->next_buffer;
+ /* requeue the buffer that just finished without reading from it. */
+ waveInAddBuffer(this->hidden->hin,
+ &this->hidden->wavebuf[nextbuf],
+ sizeof (this->hidden->wavebuf[nextbuf]));
+ this->hidden->next_buffer = (nextbuf + 1) % NUM_BUFFERS;
+ }
+}
+
+static void
+WINMM_CloseDevice(_THIS)
+{
+ int i;
+
+ if (this->hidden->hout) {
+ waveOutReset(this->hidden->hout);
+
+ /* Clean up mixing buffers */
+ for (i = 0; i < NUM_BUFFERS; ++i) {
+ if (this->hidden->wavebuf[i].dwUser != 0xFFFF) {
+ waveOutUnprepareHeader(this->hidden->hout,
+ &this->hidden->wavebuf[i],
+ sizeof (this->hidden->wavebuf[i]));
+ }
+ }
+
+ waveOutClose(this->hidden->hout);
+ }
+
+ if (this->hidden->hin) {
+ waveInReset(this->hidden->hin);
+
+ /* Clean up mixing buffers */
+ for (i = 0; i < NUM_BUFFERS; ++i) {
+ if (this->hidden->wavebuf[i].dwUser != 0xFFFF) {
+ waveInUnprepareHeader(this->hidden->hin,
+ &this->hidden->wavebuf[i],
+ sizeof (this->hidden->wavebuf[i]));
+ }
+ }
+ waveInClose(this->hidden->hin);
+ }
+
+ if (this->hidden->audio_sem) {
+ CloseHandle(this->hidden->audio_sem);
+ }
+
+ SDL_free(this->hidden->mixbuf);
+ SDL_free(this->hidden);
+}
+
+static SDL_bool
+PrepWaveFormat(_THIS, UINT devId, WAVEFORMATEX *pfmt, const int iscapture)
+{
+ SDL_zerop(pfmt);
+
+ if (SDL_AUDIO_ISFLOAT(this->spec.format)) {
+ pfmt->wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
+ } else {
+ pfmt->wFormatTag = WAVE_FORMAT_PCM;
+ }
+ pfmt->wBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);
+
+ pfmt->nChannels = this->spec.channels;
+ pfmt->nSamplesPerSec = this->spec.freq;
+ pfmt->nBlockAlign = pfmt->nChannels * (pfmt->wBitsPerSample / 8);
+ pfmt->nAvgBytesPerSec = pfmt->nSamplesPerSec * pfmt->nBlockAlign;
+
+ if (iscapture) {
+ return (waveInOpen(0, devId, pfmt, 0, 0, WAVE_FORMAT_QUERY) == 0);
+ } else {
+ return (waveOutOpen(0, devId, pfmt, 0, 0, WAVE_FORMAT_QUERY) == 0);
+ }
+}
+
+static int
+WINMM_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+ SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
+ int valid_datatype = 0;
+ MMRESULT result;
+ WAVEFORMATEX waveformat;
+ UINT devId = WAVE_MAPPER; /* WAVE_MAPPER == choose system's default */
+ UINT i;
+
+ if (handle != NULL) { /* specific device requested? */
+ /* -1 because we increment the original value to avoid NULL. */
+ const size_t val = ((size_t) handle) - 1;
+ devId = (UINT) val;
+ }
+
+ /* Initialize all variables that we clean on shutdown */
+ this->hidden = (struct SDL_PrivateAudioData *)
+ SDL_malloc((sizeof *this->hidden));
+ if (this->hidden == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(this->hidden);
+
+ /* Initialize the wavebuf structures for closing */
+ for (i = 0; i < NUM_BUFFERS; ++i)
+ this->hidden->wavebuf[i].dwUser = 0xFFFF;
+
+ if (this->spec.channels > 2)
+ this->spec.channels = 2; /* !!! FIXME: is this right? */
+
+ while ((!valid_datatype) && (test_format)) {
+ switch (test_format) {
+ case AUDIO_U8:
+ case AUDIO_S16:
+ case AUDIO_S32:
+ case AUDIO_F32:
+ this->spec.format = test_format;
+ if (PrepWaveFormat(this, devId, &waveformat, iscapture)) {
+ valid_datatype = 1;
+ } else {
+ test_format = SDL_NextAudioFormat();
+ }
+ break;
+
+ default:
+ test_format = SDL_NextAudioFormat();
+ break;
+ }
+ }
+
+ if (!valid_datatype) {
+ return SDL_SetError("Unsupported audio format");
+ }
+
+ /* Update the fragment size as size in bytes */
+ SDL_CalculateAudioSpec(&this->spec);
+
+ /* Open the audio device */
+ if (iscapture) {
+ result = waveInOpen(&this->hidden->hin, devId, &waveformat,
+ (DWORD_PTR) CaptureSound, (DWORD_PTR) this,
+ CALLBACK_FUNCTION);
+ if (result != MMSYSERR_NOERROR) {
+ return SetMMerror("waveInOpen()", result);
+ }
+ } else {
+ result = waveOutOpen(&this->hidden->hout, devId, &waveformat,
+ (DWORD_PTR) FillSound, (DWORD_PTR) this,
+ CALLBACK_FUNCTION);
+ if (result != MMSYSERR_NOERROR) {
+ return SetMMerror("waveOutOpen()", result);
+ }
+ }
+
+#ifdef SOUND_DEBUG
+ /* Check the sound device we retrieved */
+ {
+ if (iscapture) {
+ WAVEINCAPS caps;
+ result = waveInGetDevCaps((UINT) this->hidden->hout,
+ &caps, sizeof (caps));
+ if (result != MMSYSERR_NOERROR) {
+ return SetMMerror("waveInGetDevCaps()", result);
+ }
+ printf("Audio device: %s\n", caps.szPname);
+ } else {
+ WAVEOUTCAPS caps;
+ result = waveOutGetDevCaps((UINT) this->hidden->hout,
+ &caps, sizeof(caps));
+ if (result != MMSYSERR_NOERROR) {
+ return SetMMerror("waveOutGetDevCaps()", result);
+ }
+ printf("Audio device: %s\n", caps.szPname);
+ }
+ }
+#endif
+
+ /* Create the audio buffer semaphore */
+ this->hidden->audio_sem =
+ CreateSemaphore(NULL, iscapture ? 0 : NUM_BUFFERS - 1, NUM_BUFFERS, NULL);
+ if (this->hidden->audio_sem == NULL) {
+ return SDL_SetError("Couldn't create semaphore");
+ }
+
+ /* Create the sound buffers */
+ this->hidden->mixbuf =
+ (Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size);
+ if (this->hidden->mixbuf == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ SDL_zero(this->hidden->wavebuf);
+ for (i = 0; i < NUM_BUFFERS; ++i) {
+ this->hidden->wavebuf[i].dwBufferLength = this->spec.size;
+ this->hidden->wavebuf[i].dwFlags = WHDR_DONE;
+ this->hidden->wavebuf[i].lpData =
+ (LPSTR) & this->hidden->mixbuf[i * this->spec.size];
+
+ if (iscapture) {
+ result = waveInPrepareHeader(this->hidden->hin,
+ &this->hidden->wavebuf[i],
+ sizeof(this->hidden->wavebuf[i]));
+ if (result != MMSYSERR_NOERROR) {
+ return SetMMerror("waveInPrepareHeader()", result);
+ }
+
+ result = waveInAddBuffer(this->hidden->hin,
+ &this->hidden->wavebuf[i],
+ sizeof(this->hidden->wavebuf[i]));
+ if (result != MMSYSERR_NOERROR) {
+ return SetMMerror("waveInAddBuffer()", result);
+ }
+ } else {
+ result = waveOutPrepareHeader(this->hidden->hout,
+ &this->hidden->wavebuf[i],
+ sizeof(this->hidden->wavebuf[i]));
+ if (result != MMSYSERR_NOERROR) {
+ return SetMMerror("waveOutPrepareHeader()", result);
+ }
+ }
+ }
+
+ if (iscapture) {
+ result = waveInStart(this->hidden->hin);
+ if (result != MMSYSERR_NOERROR) {
+ return SetMMerror("waveInStart()", result);
+ }
+ }
+
+ return 0; /* Ready to go! */
+}
+
+
+static int
+WINMM_Init(SDL_AudioDriverImpl * impl)
+{
+ /* Set the function pointers */
+ impl->DetectDevices = WINMM_DetectDevices;
+ impl->OpenDevice = WINMM_OpenDevice;
+ impl->PlayDevice = WINMM_PlayDevice;
+ impl->WaitDevice = WINMM_WaitDevice;
+ impl->GetDeviceBuf = WINMM_GetDeviceBuf;
+ impl->CaptureFromDevice = WINMM_CaptureFromDevice;
+ impl->FlushCapture = WINMM_FlushCapture;
+ impl->CloseDevice = WINMM_CloseDevice;
+
+ impl->HasCaptureSupport = SDL_TRUE;
+
+ return 1; /* this audio target is available. */
+}
+
+AudioBootStrap WINMM_bootstrap = {
+ "winmm", "Windows Waveform Audio", WINMM_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_WINMM */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/audio/winmm/SDL_winmm.h b/src/3rdparty/SDL2/src/audio/winmm/SDL_winmm.h
new file mode 100644
index 0000000..9342bb9
--- /dev/null
+++ b/src/3rdparty/SDL2/src/audio/winmm/SDL_winmm.h
@@ -0,0 +1,45 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_winmm_h_
+#define SDL_winmm_h_
+
+#include "../SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the audio functions */
+#define _THIS SDL_AudioDevice *this
+
+#define NUM_BUFFERS 2 /* -- Don't lower this! */
+
+struct SDL_PrivateAudioData
+{
+ HWAVEOUT hout;
+ HWAVEIN hin;
+ HANDLE audio_sem;
+ Uint8 *mixbuf; /* The raw allocated mixing buffer */
+ WAVEHDR wavebuf[NUM_BUFFERS]; /* Wave audio fragments */
+ int next_buffer;
+};
+
+#endif /* SDL_winmm_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/android/SDL_android.c b/src/3rdparty/SDL2/src/core/android/SDL_android.c
new file mode 100644
index 0000000..c40c676
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/android/SDL_android.c
@@ -0,0 +1,2171 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+#include "SDL_stdinc.h"
+#include "SDL_assert.h"
+#include "SDL_hints.h"
+#include "SDL_log.h"
+#include "SDL_main.h"
+
+#ifdef __ANDROID__
+
+#include "SDL_system.h"
+#include "SDL_android.h"
+
+#include "keyinfotable.h"
+
+#include "../../events/SDL_events_c.h"
+#include "../../video/android/SDL_androidkeyboard.h"
+#include "../../video/android/SDL_androidmouse.h"
+#include "../../video/android/SDL_androidtouch.h"
+#include "../../video/android/SDL_androidvideo.h"
+#include "../../video/android/SDL_androidwindow.h"
+#include "../../joystick/android/SDL_sysjoystick_c.h"
+#include "../../haptic/android/SDL_syshaptic_c.h"
+
+#include <android/log.h>
+#include <pthread.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <dlfcn.h>
+/* #define LOG_TAG "SDL_android" */
+/* #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) */
+/* #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) */
+#define LOGI(...) do {} while (0)
+#define LOGE(...) do {} while (0)
+
+
+#define SDL_JAVA_PREFIX org_libsdl_app
+#define CONCAT1(prefix, class, function) CONCAT2(prefix, class, function)
+#define CONCAT2(prefix, class, function) Java_ ## prefix ## _ ## class ## _ ## function
+#define SDL_JAVA_INTERFACE(function) CONCAT1(SDL_JAVA_PREFIX, SDLActivity, function)
+#define SDL_JAVA_AUDIO_INTERFACE(function) CONCAT1(SDL_JAVA_PREFIX, SDLAudioManager, function)
+#define SDL_JAVA_CONTROLLER_INTERFACE(function) CONCAT1(SDL_JAVA_PREFIX, SDLControllerManager, function)
+#define SDL_JAVA_INTERFACE_INPUT_CONNECTION(function) CONCAT1(SDL_JAVA_PREFIX, SDLInputConnection, function)
+
+
+/* Java class SDLActivity */
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(
+ JNIEnv* mEnv, jclass cls);
+
+JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(
+ JNIEnv* env, jclass cls,
+ jstring library, jstring function, jobject array);
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeDropFile)(
+ JNIEnv* env, jclass jcls,
+ jstring filename);
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
+ JNIEnv* env, jclass jcls,
+ jint width, jint height, jint format, jfloat rate);
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(
+ JNIEnv* env, jclass jcls);
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceDestroyed)(
+ JNIEnv* env, jclass jcls);
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyDown)(
+ JNIEnv* env, jclass jcls,
+ jint keycode);
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyUp)(
+ JNIEnv* env, jclass jcls,
+ jint keycode);
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyboardFocusLost)(
+ JNIEnv* env, jclass jcls);
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeTouch)(
+ JNIEnv* env, jclass jcls,
+ jint touch_device_id_in, jint pointer_finger_id_in,
+ jint action, jfloat x, jfloat y, jfloat p);
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeMouse)(
+ JNIEnv* env, jclass jcls,
+ jint button, jint action, jfloat x, jfloat y);
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeAccel)(
+ JNIEnv* env, jclass jcls,
+ jfloat x, jfloat y, jfloat z);
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeClipboardChanged)(
+ JNIEnv* env, jclass jcls);
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeLowMemory)(
+ JNIEnv* env, jclass cls);
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)(
+ JNIEnv* env, jclass cls);
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)(
+ JNIEnv* env, jclass cls);
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeResume)(
+ JNIEnv* env, jclass cls);
+
+JNIEXPORT jstring JNICALL SDL_JAVA_INTERFACE(nativeGetHint)(
+ JNIEnv* env, jclass cls,
+ jstring name);
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetenv)(
+ JNIEnv* env, jclass cls,
+ jstring name, jstring value);
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeEnvironmentVariablesSet)(
+ JNIEnv* env, jclass cls);
+
+/* Java class SDLInputConnection */
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeCommitText)(
+ JNIEnv* env, jclass cls,
+ jstring text, jint newCursorPosition);
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeSetComposingText)(
+ JNIEnv* env, jclass cls,
+ jstring text, jint newCursorPosition);
+
+/* Java class SDLAudioManager */
+JNIEXPORT void JNICALL SDL_JAVA_AUDIO_INTERFACE(nativeSetupJNI)(
+ JNIEnv *env, jclass jcls);
+
+/* Java class SDLControllerManager */
+JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeSetupJNI)(
+ JNIEnv *env, jclass jcls);
+
+JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadDown)(
+ JNIEnv* env, jclass jcls,
+ jint device_id, jint keycode);
+
+JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadUp)(
+ JNIEnv* env, jclass jcls,
+ jint device_id, jint keycode);
+
+JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativeJoy)(
+ JNIEnv* env, jclass jcls,
+ jint device_id, jint axis, jfloat value);
+
+JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativeHat)(
+ JNIEnv* env, jclass jcls,
+ jint device_id, jint hat_id, jint x, jint y);
+
+JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddJoystick)(
+ JNIEnv* env, jclass jcls,
+ jint device_id, jstring device_name, jstring device_desc, jint is_accelerometer,
+ jint nbuttons, jint naxes, jint nhats, jint nballs);
+
+JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveJoystick)(
+ JNIEnv* env, jclass jcls,
+ jint device_id);
+
+JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddHaptic)(
+ JNIEnv* env, jclass jcls,
+ jint device_id, jstring device_name);
+
+JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveHaptic)(
+ JNIEnv* env, jclass jcls,
+ jint device_id);
+
+
+
+/* Uncomment this to log messages entering and exiting methods in this file */
+/* #define DEBUG_JNI */
+
+static void Android_JNI_ThreadDestroyed(void*);
+
+/*******************************************************************************
+ This file links the Java side of Android with libsdl
+*******************************************************************************/
+#include <jni.h>
+
+
+/*******************************************************************************
+ Globals
+*******************************************************************************/
+static pthread_key_t mThreadKey;
+static JavaVM* mJavaVM;
+
+/* Main activity */
+static jclass mActivityClass;
+
+/* method signatures */
+static jmethodID midGetNativeSurface;
+static jmethodID midSetActivityTitle;
+static jmethodID midSetWindowStyle;
+static jmethodID midSetOrientation;
+static jmethodID midGetContext;
+static jmethodID midIsAndroidTV;
+static jmethodID midInputGetInputDeviceIds;
+static jmethodID midSendMessage;
+static jmethodID midShowTextInput;
+static jmethodID midIsScreenKeyboardShown;
+static jmethodID midClipboardSetText;
+static jmethodID midClipboardGetText;
+static jmethodID midClipboardHasText;
+static jmethodID midOpenAPKExpansionInputStream;
+static jmethodID midGetManifestEnvironmentVariables;
+static jmethodID midGetDisplayDPI;
+
+/* audio manager */
+static jclass mAudioManagerClass;
+
+/* method signatures */
+static jmethodID midAudioOpen;
+static jmethodID midAudioWriteShortBuffer;
+static jmethodID midAudioWriteByteBuffer;
+static jmethodID midAudioClose;
+static jmethodID midCaptureOpen;
+static jmethodID midCaptureReadShortBuffer;
+static jmethodID midCaptureReadByteBuffer;
+static jmethodID midCaptureClose;
+
+/* controller manager */
+static jclass mControllerManagerClass;
+
+/* method signatures */
+static jmethodID midPollInputDevices;
+static jmethodID midPollHapticDevices;
+static jmethodID midHapticRun;
+
+/* static fields */
+static jfieldID fidSeparateMouseAndTouch;
+
+/* Accelerometer data storage */
+static float fLastAccelerometer[3];
+static SDL_bool bHasNewData;
+
+static SDL_bool bHasEnvironmentVariables = SDL_FALSE;
+
+/*******************************************************************************
+ Functions called by JNI
+*******************************************************************************/
+
+/* Library init */
+JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
+{
+ JNIEnv *env;
+ mJavaVM = vm;
+ LOGI("JNI_OnLoad called");
+ if ((*mJavaVM)->GetEnv(mJavaVM, (void**) &env, JNI_VERSION_1_4) != JNI_OK) {
+ LOGE("Failed to get the environment using GetEnv()");
+ return -1;
+ }
+ /*
+ * Create mThreadKey so we can keep track of the JNIEnv assigned to each thread
+ * Refer to http://developer.android.com/guide/practices/design/jni.html for the rationale behind this
+ */
+ if (pthread_key_create(&mThreadKey, Android_JNI_ThreadDestroyed) != 0) {
+ __android_log_print(ANDROID_LOG_ERROR, "SDL", "Error initializing pthread key");
+ }
+ Android_JNI_SetupThread();
+
+ return JNI_VERSION_1_4;
+}
+
+void checkJNIReady()
+{
+ if (!mActivityClass || !mAudioManagerClass || !mControllerManagerClass) {
+ // We aren't fully initialized, let's just return.
+ return;
+ }
+
+ SDL_SetMainReady();
+}
+
+/* Activity initialization -- called before SDL_main() to initialize JNI bindings */
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jclass cls)
+{
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeSetupJNI()");
+
+ Android_JNI_SetupThread();
+
+ mActivityClass = (jclass)((*mEnv)->NewGlobalRef(mEnv, cls));
+
+ midGetNativeSurface = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
+ "getNativeSurface","()Landroid/view/Surface;");
+ midSetActivityTitle = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
+ "setActivityTitle","(Ljava/lang/String;)Z");
+ midSetWindowStyle = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
+ "setWindowStyle","(Z)V");
+ midSetOrientation = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
+ "setOrientation","(IIZLjava/lang/String;)V");
+ midGetContext = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
+ "getContext","()Landroid/content/Context;");
+ midIsAndroidTV = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
+ "isAndroidTV","()Z");
+ midInputGetInputDeviceIds = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
+ "inputGetInputDeviceIds", "(I)[I");
+ midSendMessage = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
+ "sendMessage", "(II)Z");
+ midShowTextInput = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
+ "showTextInput", "(IIII)Z");
+ midIsScreenKeyboardShown = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
+ "isScreenKeyboardShown","()Z");
+ midClipboardSetText = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
+ "clipboardSetText", "(Ljava/lang/String;)V");
+ midClipboardGetText = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
+ "clipboardGetText", "()Ljava/lang/String;");
+ midClipboardHasText = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
+ "clipboardHasText", "()Z");
+ midOpenAPKExpansionInputStream = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
+ "openAPKExpansionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
+
+ midGetManifestEnvironmentVariables = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
+ "getManifestEnvironmentVariables", "()Z");
+
+ midGetDisplayDPI = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;");
+ midGetDisplayDPI = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;");
+
+ if (!midGetNativeSurface ||
+ !midSetActivityTitle || !midSetWindowStyle || !midSetOrientation || !midGetContext || !midIsAndroidTV || !midInputGetInputDeviceIds ||
+ !midSendMessage || !midShowTextInput || !midIsScreenKeyboardShown ||
+ !midClipboardSetText || !midClipboardGetText || !midClipboardHasText ||
+ !midOpenAPKExpansionInputStream || !midGetManifestEnvironmentVariables|| !midGetDisplayDPI) {
+ __android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLActivity.java?");
+ }
+
+ fidSeparateMouseAndTouch = (*mEnv)->GetStaticFieldID(mEnv, mActivityClass, "mSeparateMouseAndTouch", "Z");
+
+ if (!fidSeparateMouseAndTouch) {
+ __android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java static fields, do you have the latest version of SDLActivity.java?");
+ }
+
+ checkJNIReady();
+}
+
+/* Audio initialization -- called before SDL_main() to initialize JNI bindings */
+JNIEXPORT void JNICALL SDL_JAVA_AUDIO_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jclass cls)
+{
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "AUDIO nativeSetupJNI()");
+
+ Android_JNI_SetupThread();
+
+ mAudioManagerClass = (jclass)((*mEnv)->NewGlobalRef(mEnv, cls));
+
+ midAudioOpen = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass,
+ "audioOpen", "(IZZI)I");
+ midAudioWriteShortBuffer = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass,
+ "audioWriteShortBuffer", "([S)V");
+ midAudioWriteByteBuffer = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass,
+ "audioWriteByteBuffer", "([B)V");
+ midAudioClose = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass,
+ "audioClose", "()V");
+ midCaptureOpen = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass,
+ "captureOpen", "(IZZI)I");
+ midCaptureReadShortBuffer = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass,
+ "captureReadShortBuffer", "([SZ)I");
+ midCaptureReadByteBuffer = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass,
+ "captureReadByteBuffer", "([BZ)I");
+ midCaptureClose = (*mEnv)->GetStaticMethodID(mEnv, mAudioManagerClass,
+ "captureClose", "()V");
+
+ if (!midAudioOpen || !midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioClose ||
+ !midCaptureOpen || !midCaptureReadShortBuffer || !midCaptureReadByteBuffer || !midCaptureClose) {
+ __android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLAudioManager.java?");
+ }
+
+ checkJNIReady();
+}
+
+/* Controller initialization -- called before SDL_main() to initialize JNI bindings */
+JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeSetupJNI)(JNIEnv* mEnv, jclass cls)
+{
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "CONTROLLER nativeSetupJNI()");
+
+ Android_JNI_SetupThread();
+
+ mControllerManagerClass = (jclass)((*mEnv)->NewGlobalRef(mEnv, cls));
+
+ midPollInputDevices = (*mEnv)->GetStaticMethodID(mEnv, mControllerManagerClass,
+ "pollInputDevices", "()V");
+ midPollHapticDevices = (*mEnv)->GetStaticMethodID(mEnv, mControllerManagerClass,
+ "pollHapticDevices", "()V");
+ midHapticRun = (*mEnv)->GetStaticMethodID(mEnv, mControllerManagerClass,
+ "hapticRun", "(II)V");
+
+ if (!midPollInputDevices || !midPollHapticDevices || !midHapticRun) {
+ __android_log_print(ANDROID_LOG_WARN, "SDL", "Missing some Java callbacks, do you have the latest version of SDLControllerManager.java?");
+ }
+
+ checkJNIReady();
+}
+
+/* SDL main function prototype */
+typedef int (*SDL_main_func)(int argc, char *argv[]);
+
+/* Start up the SDL app */
+JNIEXPORT int JNICALL SDL_JAVA_INTERFACE(nativeRunMain)(JNIEnv* env, jclass cls, jstring library, jstring function, jobject array)
+{
+ int status = -1;
+ const char *library_file;
+ void *library_handle;
+
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeRunMain()");
+
+ library_file = (*env)->GetStringUTFChars(env, library, NULL);
+ library_handle = dlopen(library_file, RTLD_GLOBAL);
+ if (library_handle) {
+ const char *function_name;
+ SDL_main_func SDL_main;
+
+ function_name = (*env)->GetStringUTFChars(env, function, NULL);
+ SDL_main = (SDL_main_func)dlsym(library_handle, function_name);
+ if (SDL_main) {
+ int i;
+ int argc;
+ int len;
+ char **argv;
+
+ /* Prepare the arguments. */
+ len = (*env)->GetArrayLength(env, array);
+ argv = SDL_stack_alloc(char*, 1 + len + 1);
+ argc = 0;
+ /* Use the name "app_process" so PHYSFS_platformCalcBaseDir() works.
+ https://bitbucket.org/MartinFelis/love-android-sdl2/issue/23/release-build-crash-on-start
+ */
+ argv[argc++] = SDL_strdup("app_process");
+ for (i = 0; i < len; ++i) {
+ const char* utf;
+ char* arg = NULL;
+ jstring string = (*env)->GetObjectArrayElement(env, array, i);
+ if (string) {
+ utf = (*env)->GetStringUTFChars(env, string, 0);
+ if (utf) {
+ arg = SDL_strdup(utf);
+ (*env)->ReleaseStringUTFChars(env, string, utf);
+ }
+ (*env)->DeleteLocalRef(env, string);
+ }
+ if (!arg) {
+ arg = SDL_strdup("");
+ }
+ argv[argc++] = arg;
+ }
+ argv[argc] = NULL;
+
+
+ /* Run the application. */
+ status = SDL_main(argc, argv);
+
+ /* Release the arguments. */
+ for (i = 0; i < argc; ++i) {
+ SDL_free(argv[i]);
+ }
+ SDL_stack_free(argv);
+
+ } else {
+ __android_log_print(ANDROID_LOG_ERROR, "SDL", "nativeRunMain(): Couldn't find function %s in library %s", function_name, library_file);
+ }
+ (*env)->ReleaseStringUTFChars(env, function, function_name);
+
+ dlclose(library_handle);
+
+ } else {
+ __android_log_print(ANDROID_LOG_ERROR, "SDL", "nativeRunMain(): Couldn't load library %s", library_file);
+ }
+ (*env)->ReleaseStringUTFChars(env, library, library_file);
+
+ /* Do not issue an exit or the whole application will terminate instead of just the SDL thread */
+ /* exit(status); */
+
+ return status;
+}
+
+/* Drop file */
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeDropFile)(
+ JNIEnv* env, jclass jcls,
+ jstring filename)
+{
+ const char *path = (*env)->GetStringUTFChars(env, filename, NULL);
+ SDL_SendDropFile(NULL, path);
+ (*env)->ReleaseStringUTFChars(env, filename, path);
+ SDL_SendDropComplete(NULL);
+}
+
+/* Resize */
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeResize)(
+ JNIEnv* env, jclass jcls,
+ jint width, jint height, jint format, jfloat rate)
+{
+ Android_SetScreenResolution(width, height, format, rate);
+}
+
+/* Paddown */
+JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadDown)(
+ JNIEnv* env, jclass jcls,
+ jint device_id, jint keycode)
+{
+ return Android_OnPadDown(device_id, keycode);
+}
+
+/* Padup */
+JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadUp)(
+ JNIEnv* env, jclass jcls,
+ jint device_id, jint keycode)
+{
+ return Android_OnPadUp(device_id, keycode);
+}
+
+/* Joy */
+JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativeJoy)(
+ JNIEnv* env, jclass jcls,
+ jint device_id, jint axis, jfloat value)
+{
+ Android_OnJoy(device_id, axis, value);
+}
+
+/* POV Hat */
+JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativeHat)(
+ JNIEnv* env, jclass jcls,
+ jint device_id, jint hat_id, jint x, jint y)
+{
+ Android_OnHat(device_id, hat_id, x, y);
+}
+
+
+JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddJoystick)(
+ JNIEnv* env, jclass jcls,
+ jint device_id, jstring device_name, jstring device_desc, jint is_accelerometer,
+ jint nbuttons, jint naxes, jint nhats, jint nballs)
+{
+ int retval;
+ const char *name = (*env)->GetStringUTFChars(env, device_name, NULL);
+ const char *desc = (*env)->GetStringUTFChars(env, device_desc, NULL);
+
+ retval = Android_AddJoystick(device_id, name, desc, (SDL_bool) is_accelerometer, nbuttons, naxes, nhats, nballs);
+
+ (*env)->ReleaseStringUTFChars(env, device_name, name);
+ (*env)->ReleaseStringUTFChars(env, device_desc, desc);
+
+ return retval;
+}
+
+JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveJoystick)(
+ JNIEnv* env, jclass jcls,
+ jint device_id)
+{
+ return Android_RemoveJoystick(device_id);
+}
+
+JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddHaptic)(
+ JNIEnv* env, jclass jcls, jint device_id, jstring device_name)
+{
+ int retval;
+ const char *name = (*env)->GetStringUTFChars(env, device_name, NULL);
+
+ retval = Android_AddHaptic(device_id, name);
+
+ (*env)->ReleaseStringUTFChars(env, device_name, name);
+
+ return retval;
+}
+
+JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveHaptic)(
+ JNIEnv* env, jclass jcls, jint device_id)
+{
+ return Android_RemoveHaptic(device_id);
+}
+
+
+/* Surface Created */
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv* env, jclass jcls)
+{
+ SDL_WindowData *data;
+ SDL_VideoDevice *_this;
+
+ if (Android_Window == NULL || Android_Window->driverdata == NULL ) {
+ return;
+ }
+
+ _this = SDL_GetVideoDevice();
+ data = (SDL_WindowData *) Android_Window->driverdata;
+
+ /* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */
+ if (data->egl_surface == EGL_NO_SURFACE) {
+ if(data->native_window) {
+ ANativeWindow_release(data->native_window);
+ }
+ data->native_window = Android_JNI_GetNativeWindow();
+ data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);
+ }
+
+ /* GL Context handling is done in the event loop because this function is run from the Java thread */
+
+}
+
+/* Surface Destroyed */
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceDestroyed)(JNIEnv* env, jclass jcls)
+{
+ /* We have to clear the current context and destroy the egl surface here
+ * Otherwise there's BAD_NATIVE_WINDOW errors coming from eglCreateWindowSurface on resume
+ * Ref: http://stackoverflow.com/questions/8762589/eglcreatewindowsurface-on-ics-and-switching-from-2d-to-3d
+ */
+ SDL_WindowData *data;
+ SDL_VideoDevice *_this;
+
+ if (Android_Window == NULL || Android_Window->driverdata == NULL ) {
+ return;
+ }
+
+ _this = SDL_GetVideoDevice();
+ data = (SDL_WindowData *) Android_Window->driverdata;
+
+ if (data->egl_surface != EGL_NO_SURFACE) {
+ SDL_EGL_MakeCurrent(_this, NULL, NULL);
+ SDL_EGL_DestroySurface(_this, data->egl_surface);
+ data->egl_surface = EGL_NO_SURFACE;
+ }
+
+ /* GL Context handling is done in the event loop because this function is run from the Java thread */
+
+}
+
+/* Keydown */
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyDown)(
+ JNIEnv* env, jclass jcls,
+ jint keycode)
+{
+ Android_OnKeyDown(keycode);
+}
+
+/* Keyup */
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyUp)(
+ JNIEnv* env, jclass jcls,
+ jint keycode)
+{
+ Android_OnKeyUp(keycode);
+}
+
+/* Keyboard Focus Lost */
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeKeyboardFocusLost)(
+ JNIEnv* env, jclass jcls)
+{
+ /* Calling SDL_StopTextInput will take care of hiding the keyboard and cleaning up the DummyText widget */
+ SDL_StopTextInput();
+}
+
+
+/* Touch */
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeTouch)(
+ JNIEnv* env, jclass jcls,
+ jint touch_device_id_in, jint pointer_finger_id_in,
+ jint action, jfloat x, jfloat y, jfloat p)
+{
+ Android_OnTouch(touch_device_id_in, pointer_finger_id_in, action, x, y, p);
+}
+
+/* Mouse */
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeMouse)(
+ JNIEnv* env, jclass jcls,
+ jint button, jint action, jfloat x, jfloat y)
+{
+ Android_OnMouse(button, action, x, y);
+}
+
+/* Accelerometer */
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeAccel)(
+ JNIEnv* env, jclass jcls,
+ jfloat x, jfloat y, jfloat z)
+{
+ fLastAccelerometer[0] = x;
+ fLastAccelerometer[1] = y;
+ fLastAccelerometer[2] = z;
+ bHasNewData = SDL_TRUE;
+}
+
+/* Clipboard */
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeClipboardChanged)(
+ JNIEnv* env, jclass jcls)
+{
+ SDL_SendClipboardUpdate();
+}
+
+/* Low memory */
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeLowMemory)(
+ JNIEnv* env, jclass cls)
+{
+ SDL_SendAppEvent(SDL_APP_LOWMEMORY);
+}
+
+/* Quit */
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)(
+ JNIEnv* env, jclass cls)
+{
+ /* Discard previous events. The user should have handled state storage
+ * in SDL_APP_WILLENTERBACKGROUND. After nativeQuit() is called, no
+ * events other than SDL_QUIT and SDL_APP_TERMINATING should fire */
+ SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
+ /* Inject a SDL_QUIT event */
+ SDL_SendQuit();
+ SDL_SendAppEvent(SDL_APP_TERMINATING);
+ /* Resume the event loop so that the app can catch SDL_QUIT which
+ * should now be the top event in the event queue. */
+ if (!SDL_SemValue(Android_ResumeSem)) SDL_SemPost(Android_ResumeSem);
+}
+
+/* Pause */
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)(
+ JNIEnv* env, jclass cls)
+{
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativePause()");
+
+ if (Android_Window) {
+ SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
+ SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
+ SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
+ SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
+
+ /* *After* sending the relevant events, signal the pause semaphore
+ * so the event loop knows to pause and (optionally) block itself */
+ if (!SDL_SemValue(Android_PauseSem)) SDL_SemPost(Android_PauseSem);
+ }
+}
+
+/* Resume */
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeResume)(
+ JNIEnv* env, jclass cls)
+{
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativeResume()");
+
+ if (Android_Window) {
+ SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
+ SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
+ SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
+ SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESTORED, 0, 0);
+ /* Signal the resume semaphore so the event loop knows to resume and restore the GL Context
+ * We can't restore the GL Context here because it needs to be done on the SDL main thread
+ * and this function will be called from the Java thread instead.
+ */
+ if (!SDL_SemValue(Android_ResumeSem)) SDL_SemPost(Android_ResumeSem);
+ }
+}
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeCommitText)(
+ JNIEnv* env, jclass cls,
+ jstring text, jint newCursorPosition)
+{
+ const char *utftext = (*env)->GetStringUTFChars(env, text, NULL);
+
+ SDL_SendKeyboardText(utftext);
+
+ (*env)->ReleaseStringUTFChars(env, text, utftext);
+}
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeGenerateScancodeForUnichar)(
+ JNIEnv* env, jclass cls,
+ jchar chUnicode)
+{
+ SDL_Scancode code = SDL_SCANCODE_UNKNOWN;
+ uint16_t mod = 0;
+
+ // We do not care about bigger than 127.
+ if (chUnicode < 127) {
+ AndroidKeyInfo info = unicharToAndroidKeyInfoTable[chUnicode];
+ code = info.code;
+ mod = info.mod;
+ }
+
+ if (mod & KMOD_SHIFT) {
+ /* If character uses shift, press shift down */
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT);
+ }
+
+ /* send a keydown and keyup even for the character */
+ SDL_SendKeyboardKey(SDL_PRESSED, code);
+ SDL_SendKeyboardKey(SDL_RELEASED, code);
+
+ if (mod & KMOD_SHIFT) {
+ /* If character uses shift, press shift back up */
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
+ }
+}
+
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE_INPUT_CONNECTION(nativeSetComposingText)(
+ JNIEnv* env, jclass cls,
+ jstring text, jint newCursorPosition)
+{
+ const char *utftext = (*env)->GetStringUTFChars(env, text, NULL);
+
+ SDL_SendEditingText(utftext, 0, 0);
+
+ (*env)->ReleaseStringUTFChars(env, text, utftext);
+}
+
+JNIEXPORT jstring JNICALL SDL_JAVA_INTERFACE(nativeGetHint)(
+ JNIEnv* env, jclass cls,
+ jstring name)
+{
+ const char *utfname = (*env)->GetStringUTFChars(env, name, NULL);
+ const char *hint = SDL_GetHint(utfname);
+
+ jstring result = (*env)->NewStringUTF(env, hint);
+ (*env)->ReleaseStringUTFChars(env, name, utfname);
+
+ return result;
+}
+
+JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetenv)(
+ JNIEnv* env, jclass cls,
+ jstring name, jstring value)
+{
+ const char *utfname = (*env)->GetStringUTFChars(env, name, NULL);
+ const char *utfvalue = (*env)->GetStringUTFChars(env, value, NULL);
+
+ SDL_setenv(utfname, utfvalue, 1);
+
+ (*env)->ReleaseStringUTFChars(env, name, utfname);
+ (*env)->ReleaseStringUTFChars(env, value, utfvalue);
+
+}
+
+/*******************************************************************************
+ Functions called by SDL into Java
+*******************************************************************************/
+
+static int s_active = 0;
+struct LocalReferenceHolder
+{
+ JNIEnv *m_env;
+ const char *m_func;
+};
+
+static struct LocalReferenceHolder LocalReferenceHolder_Setup(const char *func)
+{
+ struct LocalReferenceHolder refholder;
+ refholder.m_env = NULL;
+ refholder.m_func = func;
+#ifdef DEBUG_JNI
+ SDL_Log("Entering function %s", func);
+#endif
+ return refholder;
+}
+
+static SDL_bool LocalReferenceHolder_Init(struct LocalReferenceHolder *refholder, JNIEnv *env)
+{
+ const int capacity = 16;
+ if ((*env)->PushLocalFrame(env, capacity) < 0) {
+ SDL_SetError("Failed to allocate enough JVM local references");
+ return SDL_FALSE;
+ }
+ ++s_active;
+ refholder->m_env = env;
+ return SDL_TRUE;
+}
+
+static void LocalReferenceHolder_Cleanup(struct LocalReferenceHolder *refholder)
+{
+#ifdef DEBUG_JNI
+ SDL_Log("Leaving function %s", refholder->m_func);
+#endif
+ if (refholder->m_env) {
+ JNIEnv* env = refholder->m_env;
+ (*env)->PopLocalFrame(env, NULL);
+ --s_active;
+ }
+}
+
+static SDL_bool LocalReferenceHolder_IsActive(void)
+{
+ return s_active > 0;
+}
+
+ANativeWindow* Android_JNI_GetNativeWindow(void)
+{
+ ANativeWindow* anw;
+ jobject s;
+ JNIEnv *env = Android_JNI_GetEnv();
+
+ s = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetNativeSurface);
+ anw = ANativeWindow_fromSurface(env, s);
+ (*env)->DeleteLocalRef(env, s);
+
+ return anw;
+}
+
+void Android_JNI_SetActivityTitle(const char *title)
+{
+ JNIEnv *mEnv = Android_JNI_GetEnv();
+
+ jstring jtitle = (jstring)((*mEnv)->NewStringUTF(mEnv, title));
+ (*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, midSetActivityTitle, jtitle);
+ (*mEnv)->DeleteLocalRef(mEnv, jtitle);
+}
+
+void Android_JNI_SetWindowStyle(SDL_bool fullscreen)
+{
+ JNIEnv *mEnv = Android_JNI_GetEnv();
+ (*mEnv)->CallStaticVoidMethod(mEnv, mActivityClass, midSetWindowStyle, fullscreen ? 1 : 0);
+}
+
+void Android_JNI_SetOrientation(int w, int h, int resizable, const char *hint)
+{
+ JNIEnv *mEnv = Android_JNI_GetEnv();
+
+ jstring jhint = (jstring)((*mEnv)->NewStringUTF(mEnv, (hint ? hint : "")));
+ (*mEnv)->CallStaticVoidMethod(mEnv, mActivityClass, midSetOrientation, w, h, (resizable? 1 : 0), jhint);
+ (*mEnv)->DeleteLocalRef(mEnv, jhint);
+}
+
+SDL_bool Android_JNI_GetAccelerometerValues(float values[3])
+{
+ int i;
+ SDL_bool retval = SDL_FALSE;
+
+ if (bHasNewData) {
+ for (i = 0; i < 3; ++i) {
+ values[i] = fLastAccelerometer[i];
+ }
+ bHasNewData = SDL_FALSE;
+ retval = SDL_TRUE;
+ }
+
+ return retval;
+}
+
+static void Android_JNI_ThreadDestroyed(void* value)
+{
+ /* The thread is being destroyed, detach it from the Java VM and set the mThreadKey value to NULL as required */
+ JNIEnv *env = (JNIEnv*) value;
+ if (env != NULL) {
+ (*mJavaVM)->DetachCurrentThread(mJavaVM);
+ pthread_setspecific(mThreadKey, NULL);
+ }
+}
+
+JNIEnv* Android_JNI_GetEnv(void)
+{
+ /* From http://developer.android.com/guide/practices/jni.html
+ * All threads are Linux threads, scheduled by the kernel.
+ * They're usually started from managed code (using Thread.start), but they can also be created elsewhere and then
+ * attached to the JavaVM. For example, a thread started with pthread_create can be attached with the
+ * JNI AttachCurrentThread or AttachCurrentThreadAsDaemon functions. Until a thread is attached, it has no JNIEnv,
+ * and cannot make JNI calls.
+ * Attaching a natively-created thread causes a java.lang.Thread object to be constructed and added to the "main"
+ * ThreadGroup, making it visible to the debugger. Calling AttachCurrentThread on an already-attached thread
+ * is a no-op.
+ * Note: You can call this function any number of times for the same thread, there's no harm in it
+ */
+
+ JNIEnv *env;
+ int status = (*mJavaVM)->AttachCurrentThread(mJavaVM, &env, NULL);
+ if(status < 0) {
+ LOGE("failed to attach current thread");
+ return 0;
+ }
+
+ /* From http://developer.android.com/guide/practices/jni.html
+ * Threads attached through JNI must call DetachCurrentThread before they exit. If coding this directly is awkward,
+ * in Android 2.0 (Eclair) and higher you can use pthread_key_create to define a destructor function that will be
+ * called before the thread exits, and call DetachCurrentThread from there. (Use that key with pthread_setspecific
+ * to store the JNIEnv in thread-local-storage; that way it'll be passed into your destructor as the argument.)
+ * Note: The destructor is not called unless the stored value is != NULL
+ * Note: You can call this function any number of times for the same thread, there's no harm in it
+ * (except for some lost CPU cycles)
+ */
+ pthread_setspecific(mThreadKey, (void*) env);
+
+ return env;
+}
+
+int Android_JNI_SetupThread(void)
+{
+ Android_JNI_GetEnv();
+ return 1;
+}
+
+/*
+ * Audio support
+ */
+static jboolean audioBuffer16Bit = JNI_FALSE;
+static jobject audioBuffer = NULL;
+static void* audioBufferPinned = NULL;
+static jboolean captureBuffer16Bit = JNI_FALSE;
+static jobject captureBuffer = NULL;
+
+int Android_JNI_OpenAudioDevice(int iscapture, int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames)
+{
+ jboolean audioBufferStereo;
+ int audioBufferFrames;
+ jobject jbufobj = NULL;
+ jboolean isCopy;
+
+ JNIEnv *env = Android_JNI_GetEnv();
+
+ if (!env) {
+ LOGE("callback_handler: failed to attach current thread");
+ }
+ Android_JNI_SetupThread();
+
+ audioBufferStereo = channelCount > 1;
+
+ if (iscapture) {
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device for capture");
+ captureBuffer16Bit = is16Bit;
+ if ((*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureOpen, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames) != 0) {
+ /* Error during audio initialization */
+ __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: error on AudioRecord initialization!");
+ return 0;
+ }
+ } else {
+ __android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device for output");
+ audioBuffer16Bit = is16Bit;
+ if ((*env)->CallStaticIntMethod(env, mAudioManagerClass, midAudioOpen, sampleRate, audioBuffer16Bit, audioBufferStereo, desiredBufferFrames) != 0) {
+ /* Error during audio initialization */
+ __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: error on AudioTrack initialization!");
+ return 0;
+ }
+ }
+
+ /* Allocating the audio buffer from the Java side and passing it as the return value for audioInit no longer works on
+ * Android >= 4.2 due to a "stale global reference" error. So now we allocate this buffer directly from this side. */
+
+ if (is16Bit) {
+ jshortArray audioBufferLocal = (*env)->NewShortArray(env, desiredBufferFrames * (audioBufferStereo ? 2 : 1));
+ if (audioBufferLocal) {
+ jbufobj = (*env)->NewGlobalRef(env, audioBufferLocal);
+ (*env)->DeleteLocalRef(env, audioBufferLocal);
+ }
+ }
+ else {
+ jbyteArray audioBufferLocal = (*env)->NewByteArray(env, desiredBufferFrames * (audioBufferStereo ? 2 : 1));
+ if (audioBufferLocal) {
+ jbufobj = (*env)->NewGlobalRef(env, audioBufferLocal);
+ (*env)->DeleteLocalRef(env, audioBufferLocal);
+ }
+ }
+
+ if (jbufobj == NULL) {
+ __android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: could not allocate an audio buffer!");
+ return 0;
+ }
+
+ if (iscapture) {
+ captureBuffer = jbufobj;
+ } else {
+ audioBuffer = jbufobj;
+ }
+
+ isCopy = JNI_FALSE;
+
+ if (is16Bit) {
+ if (!iscapture) {
+ audioBufferPinned = (*env)->GetShortArrayElements(env, (jshortArray)audioBuffer, &isCopy);
+ }
+ audioBufferFrames = (*env)->GetArrayLength(env, (jshortArray)audioBuffer);
+ } else {
+ if (!iscapture) {
+ audioBufferPinned = (*env)->GetByteArrayElements(env, (jbyteArray)audioBuffer, &isCopy);
+ }
+ audioBufferFrames = (*env)->GetArrayLength(env, (jbyteArray)audioBuffer);
+ }
+
+ if (audioBufferStereo) {
+ audioBufferFrames /= 2;
+ }
+
+ return audioBufferFrames;
+}
+
+int Android_JNI_GetDisplayDPI(float *ddpi, float *xdpi, float *ydpi)
+{
+ JNIEnv *env = Android_JNI_GetEnv();
+
+ jobject jDisplayObj = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetDisplayDPI);
+ jclass jDisplayClass = (*env)->GetObjectClass(env, jDisplayObj);
+
+ jfieldID fidXdpi = (*env)->GetFieldID(env, jDisplayClass, "xdpi", "F");
+ jfieldID fidYdpi = (*env)->GetFieldID(env, jDisplayClass, "ydpi", "F");
+ jfieldID fidDdpi = (*env)->GetFieldID(env, jDisplayClass, "densityDpi", "I");
+
+ float nativeXdpi = (*env)->GetFloatField(env, jDisplayObj, fidXdpi);
+ float nativeYdpi = (*env)->GetFloatField(env, jDisplayObj, fidYdpi);
+ int nativeDdpi = (*env)->GetIntField(env, jDisplayObj, fidDdpi);
+
+
+ (*env)->DeleteLocalRef(env, jDisplayObj);
+ (*env)->DeleteLocalRef(env, jDisplayClass);
+
+ if (ddpi) {
+ *ddpi = (float)nativeDdpi;
+ }
+ if (xdpi) {
+ *xdpi = nativeXdpi;
+ }
+ if (ydpi) {
+ *ydpi = nativeYdpi;
+ }
+
+ return 0;
+}
+
+void * Android_JNI_GetAudioBuffer(void)
+{
+ return audioBufferPinned;
+}
+
+void Android_JNI_WriteAudioBuffer(void)
+{
+ JNIEnv *mAudioEnv = Android_JNI_GetEnv();
+
+ if (audioBuffer16Bit) {
+ (*mAudioEnv)->ReleaseShortArrayElements(mAudioEnv, (jshortArray)audioBuffer, (jshort *)audioBufferPinned, JNI_COMMIT);
+ (*mAudioEnv)->CallStaticVoidMethod(mAudioEnv, mAudioManagerClass, midAudioWriteShortBuffer, (jshortArray)audioBuffer);
+ } else {
+ (*mAudioEnv)->ReleaseByteArrayElements(mAudioEnv, (jbyteArray)audioBuffer, (jbyte *)audioBufferPinned, JNI_COMMIT);
+ (*mAudioEnv)->CallStaticVoidMethod(mAudioEnv, mAudioManagerClass, midAudioWriteByteBuffer, (jbyteArray)audioBuffer);
+ }
+
+ /* JNI_COMMIT means the changes are committed to the VM but the buffer remains pinned */
+}
+
+int Android_JNI_CaptureAudioBuffer(void *buffer, int buflen)
+{
+ JNIEnv *env = Android_JNI_GetEnv();
+ jboolean isCopy = JNI_FALSE;
+ jint br;
+
+ if (captureBuffer16Bit) {
+ SDL_assert((*env)->GetArrayLength(env, (jshortArray)captureBuffer) == (buflen / 2));
+ br = (*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureReadShortBuffer, (jshortArray)captureBuffer, JNI_TRUE);
+ if (br > 0) {
+ jshort *ptr = (*env)->GetShortArrayElements(env, (jshortArray)captureBuffer, &isCopy);
+ br *= 2;
+ SDL_memcpy(buffer, ptr, br);
+ (*env)->ReleaseShortArrayElements(env, (jshortArray)captureBuffer, (jshort *)ptr, JNI_ABORT);
+ }
+ } else {
+ SDL_assert((*env)->GetArrayLength(env, (jshortArray)captureBuffer) == buflen);
+ br = (*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureReadByteBuffer, (jbyteArray)captureBuffer, JNI_TRUE);
+ if (br > 0) {
+ jbyte *ptr = (*env)->GetByteArrayElements(env, (jbyteArray)captureBuffer, &isCopy);
+ SDL_memcpy(buffer, ptr, br);
+ (*env)->ReleaseByteArrayElements(env, (jbyteArray)captureBuffer, (jbyte *)ptr, JNI_ABORT);
+ }
+ }
+
+ return (int) br;
+}
+
+void Android_JNI_FlushCapturedAudio(void)
+{
+ JNIEnv *env = Android_JNI_GetEnv();
+#if 0 /* !!! FIXME: this needs API 23, or it'll do blocking reads and never end. */
+ if (captureBuffer16Bit) {
+ const jint len = (*env)->GetArrayLength(env, (jshortArray)captureBuffer);
+ while ((*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadShortBuffer, (jshortArray)captureBuffer, JNI_FALSE) == len) { /* spin */ }
+ } else {
+ const jint len = (*env)->GetArrayLength(env, (jbyteArray)captureBuffer);
+ while ((*env)->CallStaticIntMethod(env, mActivityClass, midCaptureReadByteBuffer, (jbyteArray)captureBuffer, JNI_FALSE) == len) { /* spin */ }
+ }
+#else
+ if (captureBuffer16Bit) {
+ (*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureReadShortBuffer, (jshortArray)captureBuffer, JNI_FALSE);
+ } else {
+ (*env)->CallStaticIntMethod(env, mAudioManagerClass, midCaptureReadByteBuffer, (jbyteArray)captureBuffer, JNI_FALSE);
+ }
+#endif
+}
+
+void Android_JNI_CloseAudioDevice(const int iscapture)
+{
+ JNIEnv *env = Android_JNI_GetEnv();
+
+ if (iscapture) {
+ (*env)->CallStaticVoidMethod(env, mAudioManagerClass, midCaptureClose);
+ if (captureBuffer) {
+ (*env)->DeleteGlobalRef(env, captureBuffer);
+ captureBuffer = NULL;
+ }
+ } else {
+ (*env)->CallStaticVoidMethod(env, mAudioManagerClass, midAudioClose);
+ if (audioBuffer) {
+ (*env)->DeleteGlobalRef(env, audioBuffer);
+ audioBuffer = NULL;
+ audioBufferPinned = NULL;
+ }
+ }
+}
+
+/* Test for an exception and call SDL_SetError with its detail if one occurs */
+/* If the parameter silent is truthy then SDL_SetError() will not be called. */
+static SDL_bool Android_JNI_ExceptionOccurred(SDL_bool silent)
+{
+ JNIEnv *mEnv = Android_JNI_GetEnv();
+ jthrowable exception;
+
+ SDL_assert(LocalReferenceHolder_IsActive());
+
+ exception = (*mEnv)->ExceptionOccurred(mEnv);
+ if (exception != NULL) {
+ jmethodID mid;
+
+ /* Until this happens most JNI operations have undefined behaviour */
+ (*mEnv)->ExceptionClear(mEnv);
+
+ if (!silent) {
+ jclass exceptionClass = (*mEnv)->GetObjectClass(mEnv, exception);
+ jclass classClass = (*mEnv)->FindClass(mEnv, "java/lang/Class");
+ jstring exceptionName;
+ const char* exceptionNameUTF8;
+ jstring exceptionMessage;
+
+ mid = (*mEnv)->GetMethodID(mEnv, classClass, "getName", "()Ljava/lang/String;");
+ exceptionName = (jstring)(*mEnv)->CallObjectMethod(mEnv, exceptionClass, mid);
+ exceptionNameUTF8 = (*mEnv)->GetStringUTFChars(mEnv, exceptionName, 0);
+
+ mid = (*mEnv)->GetMethodID(mEnv, exceptionClass, "getMessage", "()Ljava/lang/String;");
+ exceptionMessage = (jstring)(*mEnv)->CallObjectMethod(mEnv, exception, mid);
+
+ if (exceptionMessage != NULL) {
+ const char* exceptionMessageUTF8 = (*mEnv)->GetStringUTFChars(mEnv, exceptionMessage, 0);
+ SDL_SetError("%s: %s", exceptionNameUTF8, exceptionMessageUTF8);
+ (*mEnv)->ReleaseStringUTFChars(mEnv, exceptionMessage, exceptionMessageUTF8);
+ } else {
+ SDL_SetError("%s", exceptionNameUTF8);
+ }
+
+ (*mEnv)->ReleaseStringUTFChars(mEnv, exceptionName, exceptionNameUTF8);
+ }
+
+ return SDL_TRUE;
+ }
+
+ return SDL_FALSE;
+}
+
+static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx)
+{
+ struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
+
+ int result = 0;
+
+ jmethodID mid;
+ jobject context;
+ jobject assetManager;
+ jobject inputStream;
+ jclass channels;
+ jobject readableByteChannel;
+ jstring fileNameJString;
+ jobject fd;
+ jclass fdCls;
+ jfieldID descriptor;
+
+ JNIEnv *mEnv = Android_JNI_GetEnv();
+ if (!LocalReferenceHolder_Init(&refs, mEnv)) {
+ goto failure;
+ }
+
+ fileNameJString = (jstring)ctx->hidden.androidio.fileNameRef;
+ ctx->hidden.androidio.position = 0;
+
+ /* context = SDLActivity.getContext(); */
+ context = (*mEnv)->CallStaticObjectMethod(mEnv, mActivityClass, midGetContext);
+
+ /* assetManager = context.getAssets(); */
+ mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, context),
+ "getAssets", "()Landroid/content/res/AssetManager;");
+ assetManager = (*mEnv)->CallObjectMethod(mEnv, context, mid);
+
+ /* First let's try opening the file to obtain an AssetFileDescriptor.
+ * This method reads the files directly from the APKs using standard *nix calls
+ */
+ mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, assetManager), "openFd", "(Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;");
+ inputStream = (*mEnv)->CallObjectMethod(mEnv, assetManager, mid, fileNameJString);
+ if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
+ goto fallback;
+ }
+
+ mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), "getStartOffset", "()J");
+ ctx->hidden.androidio.offset = (*mEnv)->CallLongMethod(mEnv, inputStream, mid);
+ if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
+ goto fallback;
+ }
+
+ mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), "getDeclaredLength", "()J");
+ ctx->hidden.androidio.size = (*mEnv)->CallLongMethod(mEnv, inputStream, mid);
+ if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
+ goto fallback;
+ }
+
+ mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), "getFileDescriptor", "()Ljava/io/FileDescriptor;");
+ fd = (*mEnv)->CallObjectMethod(mEnv, inputStream, mid);
+ fdCls = (*mEnv)->GetObjectClass(mEnv, fd);
+ descriptor = (*mEnv)->GetFieldID(mEnv, fdCls, "descriptor", "I");
+ ctx->hidden.androidio.fd = (*mEnv)->GetIntField(mEnv, fd, descriptor);
+ ctx->hidden.androidio.assetFileDescriptorRef = (*mEnv)->NewGlobalRef(mEnv, inputStream);
+
+ /* Seek to the correct offset in the file. */
+ lseek(ctx->hidden.androidio.fd, (off_t)ctx->hidden.androidio.offset, SEEK_SET);
+
+ if (0) {
+fallback:
+ /* Disabled log message because of spam on the Nexus 7 */
+ /* __android_log_print(ANDROID_LOG_DEBUG, "SDL", "Falling back to legacy InputStream method for opening file"); */
+
+ /* Try the old method using InputStream */
+ ctx->hidden.androidio.assetFileDescriptorRef = NULL;
+
+ /* inputStream = assetManager.open(<filename>); */
+ mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, assetManager),
+ "open", "(Ljava/lang/String;I)Ljava/io/InputStream;");
+ inputStream = (*mEnv)->CallObjectMethod(mEnv, assetManager, mid, fileNameJString, 1 /* ACCESS_RANDOM */);
+ if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
+ /* Try fallback to APK expansion files */
+ inputStream = (*mEnv)->CallStaticObjectMethod(mEnv, mActivityClass, midOpenAPKExpansionInputStream, fileNameJString);
+
+ /* Exception is checked first because it always needs to be cleared.
+ * If no exception occurred then the last SDL error message is kept.
+ */
+ if (Android_JNI_ExceptionOccurred(SDL_FALSE) || !inputStream) {
+ goto failure;
+ }
+ }
+
+ ctx->hidden.androidio.inputStreamRef = (*mEnv)->NewGlobalRef(mEnv, inputStream);
+
+ /* Despite all the visible documentation on [Asset]InputStream claiming
+ * that the .available() method is not guaranteed to return the entire file
+ * size, comments in <sdk>/samples/<ver>/ApiDemos/src/com/example/ ...
+ * android/apis/content/ReadAsset.java imply that Android's
+ * AssetInputStream.available() /will/ always return the total file size
+ */
+
+ /* size = inputStream.available(); */
+ mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream),
+ "available", "()I");
+ ctx->hidden.androidio.size = (long)(*mEnv)->CallIntMethod(mEnv, inputStream, mid);
+ if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
+ goto failure;
+ }
+
+ /* readableByteChannel = Channels.newChannel(inputStream); */
+ channels = (*mEnv)->FindClass(mEnv, "java/nio/channels/Channels");
+ mid = (*mEnv)->GetStaticMethodID(mEnv, channels,
+ "newChannel",
+ "(Ljava/io/InputStream;)Ljava/nio/channels/ReadableByteChannel;");
+ readableByteChannel = (*mEnv)->CallStaticObjectMethod(
+ mEnv, channels, mid, inputStream);
+ if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
+ goto failure;
+ }
+
+ ctx->hidden.androidio.readableByteChannelRef =
+ (*mEnv)->NewGlobalRef(mEnv, readableByteChannel);
+
+ /* Store .read id for reading purposes */
+ mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, readableByteChannel),
+ "read", "(Ljava/nio/ByteBuffer;)I");
+ ctx->hidden.androidio.readMethod = mid;
+ }
+
+ if (0) {
+failure:
+ result = -1;
+
+ (*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.fileNameRef);
+
+ if(ctx->hidden.androidio.inputStreamRef != NULL) {
+ (*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.inputStreamRef);
+ }
+
+ if(ctx->hidden.androidio.readableByteChannelRef != NULL) {
+ (*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.readableByteChannelRef);
+ }
+
+ if(ctx->hidden.androidio.assetFileDescriptorRef != NULL) {
+ (*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.assetFileDescriptorRef);
+ }
+
+ }
+
+ LocalReferenceHolder_Cleanup(&refs);
+ return result;
+}
+
+int Android_JNI_FileOpen(SDL_RWops* ctx,
+ const char* fileName, const char* mode)
+{
+ struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
+ JNIEnv *mEnv = Android_JNI_GetEnv();
+ int retval;
+ jstring fileNameJString;
+
+ if (!LocalReferenceHolder_Init(&refs, mEnv)) {
+ LocalReferenceHolder_Cleanup(&refs);
+ return -1;
+ }
+
+ if (!ctx) {
+ LocalReferenceHolder_Cleanup(&refs);
+ return -1;
+ }
+
+ fileNameJString = (*mEnv)->NewStringUTF(mEnv, fileName);
+ ctx->hidden.androidio.fileNameRef = (*mEnv)->NewGlobalRef(mEnv, fileNameJString);
+ ctx->hidden.androidio.inputStreamRef = NULL;
+ ctx->hidden.androidio.readableByteChannelRef = NULL;
+ ctx->hidden.androidio.readMethod = NULL;
+ ctx->hidden.androidio.assetFileDescriptorRef = NULL;
+
+ retval = Internal_Android_JNI_FileOpen(ctx);
+ LocalReferenceHolder_Cleanup(&refs);
+ return retval;
+}
+
+size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer,
+ size_t size, size_t maxnum)
+{
+ struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
+
+ if (ctx->hidden.androidio.assetFileDescriptorRef) {
+ size_t bytesMax = size * maxnum;
+ size_t result;
+ if (ctx->hidden.androidio.size != -1 /* UNKNOWN_LENGTH */ && ctx->hidden.androidio.position + bytesMax > ctx->hidden.androidio.size) {
+ bytesMax = ctx->hidden.androidio.size - ctx->hidden.androidio.position;
+ }
+ result = read(ctx->hidden.androidio.fd, buffer, bytesMax );
+ if (result > 0) {
+ ctx->hidden.androidio.position += result;
+ LocalReferenceHolder_Cleanup(&refs);
+ return result / size;
+ }
+ LocalReferenceHolder_Cleanup(&refs);
+ return 0;
+ } else {
+ jlong bytesRemaining = (jlong) (size * maxnum);
+ jlong bytesMax = (jlong) (ctx->hidden.androidio.size - ctx->hidden.androidio.position);
+ int bytesRead = 0;
+ JNIEnv *mEnv;
+ jobject readableByteChannel;
+ jmethodID readMethod;
+ jobject byteBuffer;
+
+ /* Don't read more bytes than those that remain in the file, otherwise we get an exception */
+ if (bytesRemaining > bytesMax) bytesRemaining = bytesMax;
+
+ mEnv = Android_JNI_GetEnv();
+ if (!LocalReferenceHolder_Init(&refs, mEnv)) {
+ LocalReferenceHolder_Cleanup(&refs);
+ return 0;
+ }
+
+ readableByteChannel = (jobject)ctx->hidden.androidio.readableByteChannelRef;
+ readMethod = (jmethodID)ctx->hidden.androidio.readMethod;
+ byteBuffer = (*mEnv)->NewDirectByteBuffer(mEnv, buffer, bytesRemaining);
+
+ while (bytesRemaining > 0) {
+ /* result = readableByteChannel.read(...); */
+ int result = (*mEnv)->CallIntMethod(mEnv, readableByteChannel, readMethod, byteBuffer);
+
+ if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
+ LocalReferenceHolder_Cleanup(&refs);
+ return 0;
+ }
+
+ if (result < 0) {
+ break;
+ }
+
+ bytesRemaining -= result;
+ bytesRead += result;
+ ctx->hidden.androidio.position += result;
+ }
+ LocalReferenceHolder_Cleanup(&refs);
+ return bytesRead / size;
+ }
+}
+
+size_t Android_JNI_FileWrite(SDL_RWops* ctx, const void* buffer,
+ size_t size, size_t num)
+{
+ SDL_SetError("Cannot write to Android package filesystem");
+ return 0;
+}
+
+static int Internal_Android_JNI_FileClose(SDL_RWops* ctx, SDL_bool release)
+{
+ struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
+
+ int result = 0;
+ JNIEnv *mEnv = Android_JNI_GetEnv();
+
+ if (!LocalReferenceHolder_Init(&refs, mEnv)) {
+ LocalReferenceHolder_Cleanup(&refs);
+ return SDL_SetError("Failed to allocate enough JVM local references");
+ }
+
+ if (ctx) {
+ if (release) {
+ (*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.fileNameRef);
+ }
+
+ if (ctx->hidden.androidio.assetFileDescriptorRef) {
+ jobject inputStream = (jobject)ctx->hidden.androidio.assetFileDescriptorRef;
+ jmethodID mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream),
+ "close", "()V");
+ (*mEnv)->CallVoidMethod(mEnv, inputStream, mid);
+ (*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.assetFileDescriptorRef);
+ if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
+ result = -1;
+ }
+ }
+ else {
+ jobject inputStream = (jobject)ctx->hidden.androidio.inputStreamRef;
+
+ /* inputStream.close(); */
+ jmethodID mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream),
+ "close", "()V");
+ (*mEnv)->CallVoidMethod(mEnv, inputStream, mid);
+ (*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.inputStreamRef);
+ (*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.readableByteChannelRef);
+ if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
+ result = -1;
+ }
+ }
+
+ if (release) {
+ SDL_FreeRW(ctx);
+ }
+ }
+
+ LocalReferenceHolder_Cleanup(&refs);
+ return result;
+}
+
+
+Sint64 Android_JNI_FileSize(SDL_RWops* ctx)
+{
+ return ctx->hidden.androidio.size;
+}
+
+Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence)
+{
+ if (ctx->hidden.androidio.assetFileDescriptorRef) {
+ off_t ret;
+ switch (whence) {
+ case RW_SEEK_SET:
+ if (ctx->hidden.androidio.size != -1 /* UNKNOWN_LENGTH */ && offset > ctx->hidden.androidio.size) offset = ctx->hidden.androidio.size;
+ offset += ctx->hidden.androidio.offset;
+ break;
+ case RW_SEEK_CUR:
+ offset += ctx->hidden.androidio.position;
+ if (ctx->hidden.androidio.size != -1 /* UNKNOWN_LENGTH */ && offset > ctx->hidden.androidio.size) offset = ctx->hidden.androidio.size;
+ offset += ctx->hidden.androidio.offset;
+ break;
+ case RW_SEEK_END:
+ offset = ctx->hidden.androidio.offset + ctx->hidden.androidio.size + offset;
+ break;
+ default:
+ return SDL_SetError("Unknown value for 'whence'");
+ }
+ whence = SEEK_SET;
+
+ ret = lseek(ctx->hidden.androidio.fd, (off_t)offset, SEEK_SET);
+ if (ret == -1) return -1;
+ ctx->hidden.androidio.position = ret - ctx->hidden.androidio.offset;
+ } else {
+ Sint64 newPosition;
+ Sint64 movement;
+
+ switch (whence) {
+ case RW_SEEK_SET:
+ newPosition = offset;
+ break;
+ case RW_SEEK_CUR:
+ newPosition = ctx->hidden.androidio.position + offset;
+ break;
+ case RW_SEEK_END:
+ newPosition = ctx->hidden.androidio.size + offset;
+ break;
+ default:
+ return SDL_SetError("Unknown value for 'whence'");
+ }
+
+ /* Validate the new position */
+ if (newPosition < 0) {
+ return SDL_Error(SDL_EFSEEK);
+ }
+ if (newPosition > ctx->hidden.androidio.size) {
+ newPosition = ctx->hidden.androidio.size;
+ }
+
+ movement = newPosition - ctx->hidden.androidio.position;
+ if (movement > 0) {
+ unsigned char buffer[4096];
+
+ /* The easy case where we're seeking forwards */
+ while (movement > 0) {
+ Sint64 amount = sizeof (buffer);
+ size_t result;
+ if (amount > movement) {
+ amount = movement;
+ }
+ result = Android_JNI_FileRead(ctx, buffer, 1, amount);
+ if (result <= 0) {
+ /* Failed to read/skip the required amount, so fail */
+ return -1;
+ }
+
+ movement -= result;
+ }
+
+ } else if (movement < 0) {
+ /* We can't seek backwards so we have to reopen the file and seek */
+ /* forwards which obviously isn't very efficient */
+ Internal_Android_JNI_FileClose(ctx, SDL_FALSE);
+ Internal_Android_JNI_FileOpen(ctx);
+ Android_JNI_FileSeek(ctx, newPosition, RW_SEEK_SET);
+ }
+ }
+
+ return ctx->hidden.androidio.position;
+
+}
+
+int Android_JNI_FileClose(SDL_RWops* ctx)
+{
+ return Internal_Android_JNI_FileClose(ctx, SDL_TRUE);
+}
+
+int Android_JNI_SetClipboardText(const char* text)
+{
+ JNIEnv* env = Android_JNI_GetEnv();
+ jstring string = (*env)->NewStringUTF(env, text);
+ (*env)->CallStaticVoidMethod(env, mActivityClass, midClipboardSetText, string);
+ (*env)->DeleteLocalRef(env, string);
+ return 0;
+}
+
+char* Android_JNI_GetClipboardText(void)
+{
+ JNIEnv* env = Android_JNI_GetEnv();
+ char* text = NULL;
+ jstring string;
+
+ string = (*env)->CallStaticObjectMethod(env, mActivityClass, midClipboardGetText);
+ if (string) {
+ const char* utf = (*env)->GetStringUTFChars(env, string, 0);
+ if (utf) {
+ text = SDL_strdup(utf);
+ (*env)->ReleaseStringUTFChars(env, string, utf);
+ }
+ (*env)->DeleteLocalRef(env, string);
+ }
+
+ return (text == NULL) ? SDL_strdup("") : text;
+}
+
+SDL_bool Android_JNI_HasClipboardText(void)
+{
+ JNIEnv* env = Android_JNI_GetEnv();
+ jboolean retval = (*env)->CallStaticBooleanMethod(env, mActivityClass, midClipboardHasText);
+ return (retval == JNI_TRUE) ? SDL_TRUE : SDL_FALSE;
+}
+
+/* returns 0 on success or -1 on error (others undefined then)
+ * returns truthy or falsy value in plugged, charged and battery
+ * returns the value in seconds and percent or -1 if not available
+ */
+int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seconds, int* percent)
+{
+ struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
+ JNIEnv* env = Android_JNI_GetEnv();
+ jmethodID mid;
+ jobject context;
+ jstring action;
+ jclass cls;
+ jobject filter;
+ jobject intent;
+ jstring iname;
+ jmethodID imid;
+ jstring bname;
+ jmethodID bmid;
+ if (!LocalReferenceHolder_Init(&refs, env)) {
+ LocalReferenceHolder_Cleanup(&refs);
+ return -1;
+ }
+
+
+ /* context = SDLActivity.getContext(); */
+ context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
+
+ action = (*env)->NewStringUTF(env, "android.intent.action.BATTERY_CHANGED");
+
+ cls = (*env)->FindClass(env, "android/content/IntentFilter");
+
+ mid = (*env)->GetMethodID(env, cls, "<init>", "(Ljava/lang/String;)V");
+ filter = (*env)->NewObject(env, cls, mid, action);
+
+ (*env)->DeleteLocalRef(env, action);
+
+ mid = (*env)->GetMethodID(env, mActivityClass, "registerReceiver", "(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;");
+ intent = (*env)->CallObjectMethod(env, context, mid, NULL, filter);
+
+ (*env)->DeleteLocalRef(env, filter);
+
+ cls = (*env)->GetObjectClass(env, intent);
+
+ imid = (*env)->GetMethodID(env, cls, "getIntExtra", "(Ljava/lang/String;I)I");
+
+ /* Watch out for C89 scoping rules because of the macro */
+#define GET_INT_EXTRA(var, key) \
+ int var; \
+ iname = (*env)->NewStringUTF(env, key); \
+ var = (*env)->CallIntMethod(env, intent, imid, iname, -1); \
+ (*env)->DeleteLocalRef(env, iname);
+
+ bmid = (*env)->GetMethodID(env, cls, "getBooleanExtra", "(Ljava/lang/String;Z)Z");
+
+ /* Watch out for C89 scoping rules because of the macro */
+#define GET_BOOL_EXTRA(var, key) \
+ int var; \
+ bname = (*env)->NewStringUTF(env, key); \
+ var = (*env)->CallBooleanMethod(env, intent, bmid, bname, JNI_FALSE); \
+ (*env)->DeleteLocalRef(env, bname);
+
+ if (plugged) {
+ /* Watch out for C89 scoping rules because of the macro */
+ GET_INT_EXTRA(plug, "plugged") /* == BatteryManager.EXTRA_PLUGGED (API 5) */
+ if (plug == -1) {
+ LocalReferenceHolder_Cleanup(&refs);
+ return -1;
+ }
+ /* 1 == BatteryManager.BATTERY_PLUGGED_AC */
+ /* 2 == BatteryManager.BATTERY_PLUGGED_USB */
+ *plugged = (0 < plug) ? 1 : 0;
+ }
+
+ if (charged) {
+ /* Watch out for C89 scoping rules because of the macro */
+ GET_INT_EXTRA(status, "status") /* == BatteryManager.EXTRA_STATUS (API 5) */
+ if (status == -1) {
+ LocalReferenceHolder_Cleanup(&refs);
+ return -1;
+ }
+ /* 5 == BatteryManager.BATTERY_STATUS_FULL */
+ *charged = (status == 5) ? 1 : 0;
+ }
+
+ if (battery) {
+ GET_BOOL_EXTRA(present, "present") /* == BatteryManager.EXTRA_PRESENT (API 5) */
+ *battery = present ? 1 : 0;
+ }
+
+ if (seconds) {
+ *seconds = -1; /* not possible */
+ }
+
+ if (percent) {
+ int level;
+ int scale;
+
+ /* Watch out for C89 scoping rules because of the macro */
+ {
+ GET_INT_EXTRA(level_temp, "level") /* == BatteryManager.EXTRA_LEVEL (API 5) */
+ level = level_temp;
+ }
+ /* Watch out for C89 scoping rules because of the macro */
+ {
+ GET_INT_EXTRA(scale_temp, "scale") /* == BatteryManager.EXTRA_SCALE (API 5) */
+ scale = scale_temp;
+ }
+
+ if ((level == -1) || (scale == -1)) {
+ LocalReferenceHolder_Cleanup(&refs);
+ return -1;
+ }
+ *percent = level * 100 / scale;
+ }
+
+ (*env)->DeleteLocalRef(env, intent);
+
+ LocalReferenceHolder_Cleanup(&refs);
+ return 0;
+}
+
+/* returns number of found touch devices as return value and ids in parameter ids */
+int Android_JNI_GetTouchDeviceIds(int **ids) {
+ JNIEnv *env = Android_JNI_GetEnv();
+ jint sources = 4098; /* == InputDevice.SOURCE_TOUCHSCREEN */
+ jintArray array = (jintArray) (*env)->CallStaticObjectMethod(env, mActivityClass, midInputGetInputDeviceIds, sources);
+ int number = 0;
+ *ids = NULL;
+ if (array) {
+ number = (int) (*env)->GetArrayLength(env, array);
+ if (0 < number) {
+ jint* elements = (*env)->GetIntArrayElements(env, array, NULL);
+ if (elements) {
+ int i;
+ *ids = SDL_malloc(number * sizeof (**ids));
+ for (i = 0; i < number; ++i) { /* not assuming sizeof (jint) == sizeof (int) */
+ (*ids)[i] = elements[i];
+ }
+ (*env)->ReleaseIntArrayElements(env, array, elements, JNI_ABORT);
+ }
+ }
+ (*env)->DeleteLocalRef(env, array);
+ }
+ return number;
+}
+
+/* sets the mSeparateMouseAndTouch field */
+void Android_JNI_SetSeparateMouseAndTouch(SDL_bool new_value)
+{
+ JNIEnv *env = Android_JNI_GetEnv();
+ (*env)->SetStaticBooleanField(env, mActivityClass, fidSeparateMouseAndTouch, new_value ? JNI_TRUE : JNI_FALSE);
+}
+
+void Android_JNI_PollInputDevices(void)
+{
+ JNIEnv *env = Android_JNI_GetEnv();
+ (*env)->CallStaticVoidMethod(env, mControllerManagerClass, midPollInputDevices);
+}
+
+void Android_JNI_PollHapticDevices(void)
+{
+ JNIEnv *env = Android_JNI_GetEnv();
+ (*env)->CallStaticVoidMethod(env, mControllerManagerClass, midPollHapticDevices);
+}
+
+void Android_JNI_HapticRun(int device_id, int length)
+{
+ JNIEnv *env = Android_JNI_GetEnv();
+ (*env)->CallStaticVoidMethod(env, mControllerManagerClass, midHapticRun, device_id, length);
+}
+
+
+/* See SDLActivity.java for constants. */
+#define COMMAND_SET_KEEP_SCREEN_ON 5
+
+/* sends message to be handled on the UI event dispatch thread */
+int Android_JNI_SendMessage(int command, int param)
+{
+ JNIEnv *env = Android_JNI_GetEnv();
+ jboolean success;
+ success = (*env)->CallStaticBooleanMethod(env, mActivityClass, midSendMessage, command, param);
+ return success ? 0 : -1;
+}
+
+void Android_JNI_SuspendScreenSaver(SDL_bool suspend)
+{
+ Android_JNI_SendMessage(COMMAND_SET_KEEP_SCREEN_ON, (suspend == SDL_FALSE) ? 0 : 1);
+}
+
+void Android_JNI_ShowTextInput(SDL_Rect *inputRect)
+{
+ JNIEnv *env = Android_JNI_GetEnv();
+ (*env)->CallStaticBooleanMethod(env, mActivityClass, midShowTextInput,
+ inputRect->x,
+ inputRect->y,
+ inputRect->w,
+ inputRect->h );
+}
+
+void Android_JNI_HideTextInput(void)
+{
+ /* has to match Activity constant */
+ const int COMMAND_TEXTEDIT_HIDE = 3;
+ Android_JNI_SendMessage(COMMAND_TEXTEDIT_HIDE, 0);
+}
+
+SDL_bool Android_JNI_IsScreenKeyboardShown()
+{
+ JNIEnv *mEnv = Android_JNI_GetEnv();
+ jboolean is_shown = 0;
+ is_shown = (*mEnv)->CallStaticBooleanMethod(mEnv, mActivityClass, midIsScreenKeyboardShown);
+ return is_shown;
+}
+
+
+int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
+{
+ JNIEnv *env;
+ jclass clazz;
+ jmethodID mid;
+ jobject context;
+ jstring title;
+ jstring message;
+ jintArray button_flags;
+ jintArray button_ids;
+ jobjectArray button_texts;
+ jintArray colors;
+ jobject text;
+ jint temp;
+ int i;
+
+ env = Android_JNI_GetEnv();
+
+ /* convert parameters */
+
+ clazz = (*env)->FindClass(env, "java/lang/String");
+
+ title = (*env)->NewStringUTF(env, messageboxdata->title);
+ message = (*env)->NewStringUTF(env, messageboxdata->message);
+
+ button_flags = (*env)->NewIntArray(env, messageboxdata->numbuttons);
+ button_ids = (*env)->NewIntArray(env, messageboxdata->numbuttons);
+ button_texts = (*env)->NewObjectArray(env, messageboxdata->numbuttons,
+ clazz, NULL);
+ for (i = 0; i < messageboxdata->numbuttons; ++i) {
+ temp = messageboxdata->buttons[i].flags;
+ (*env)->SetIntArrayRegion(env, button_flags, i, 1, &temp);
+ temp = messageboxdata->buttons[i].buttonid;
+ (*env)->SetIntArrayRegion(env, button_ids, i, 1, &temp);
+ text = (*env)->NewStringUTF(env, messageboxdata->buttons[i].text);
+ (*env)->SetObjectArrayElement(env, button_texts, i, text);
+ (*env)->DeleteLocalRef(env, text);
+ }
+
+ if (messageboxdata->colorScheme) {
+ colors = (*env)->NewIntArray(env, SDL_MESSAGEBOX_COLOR_MAX);
+ for (i = 0; i < SDL_MESSAGEBOX_COLOR_MAX; ++i) {
+ temp = (0xFF << 24) |
+ (messageboxdata->colorScheme->colors[i].r << 16) |
+ (messageboxdata->colorScheme->colors[i].g << 8) |
+ (messageboxdata->colorScheme->colors[i].b << 0);
+ (*env)->SetIntArrayRegion(env, colors, i, 1, &temp);
+ }
+ } else {
+ colors = NULL;
+ }
+
+ (*env)->DeleteLocalRef(env, clazz);
+
+ /* context = SDLActivity.getContext(); */
+ context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
+
+ clazz = (*env)->GetObjectClass(env, context);
+
+ mid = (*env)->GetMethodID(env, clazz,
+ "messageboxShowMessageBox", "(ILjava/lang/String;Ljava/lang/String;[I[I[Ljava/lang/String;[I)I");
+ *buttonid = (*env)->CallIntMethod(env, context, mid,
+ messageboxdata->flags,
+ title,
+ message,
+ button_flags,
+ button_ids,
+ button_texts,
+ colors);
+
+ (*env)->DeleteLocalRef(env, context);
+ (*env)->DeleteLocalRef(env, clazz);
+
+ /* delete parameters */
+
+ (*env)->DeleteLocalRef(env, title);
+ (*env)->DeleteLocalRef(env, message);
+ (*env)->DeleteLocalRef(env, button_flags);
+ (*env)->DeleteLocalRef(env, button_ids);
+ (*env)->DeleteLocalRef(env, button_texts);
+ (*env)->DeleteLocalRef(env, colors);
+
+ return 0;
+}
+
+/*
+//////////////////////////////////////////////////////////////////////////////
+//
+// Functions exposed to SDL applications in SDL_system.h
+//////////////////////////////////////////////////////////////////////////////
+*/
+
+void *SDL_AndroidGetJNIEnv(void)
+{
+ return Android_JNI_GetEnv();
+}
+
+void *SDL_AndroidGetActivity(void)
+{
+ /* See SDL_system.h for caveats on using this function. */
+
+ JNIEnv *env = Android_JNI_GetEnv();
+ if (!env) {
+ return NULL;
+ }
+
+ /* return SDLActivity.getContext(); */
+ return (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
+}
+
+SDL_bool SDL_IsAndroidTV(void)
+{
+ JNIEnv *env = Android_JNI_GetEnv();
+ return (*env)->CallStaticBooleanMethod(env, mActivityClass, midIsAndroidTV);
+}
+
+const char * SDL_AndroidGetInternalStoragePath(void)
+{
+ static char *s_AndroidInternalFilesPath = NULL;
+
+ if (!s_AndroidInternalFilesPath) {
+ struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
+ jmethodID mid;
+ jobject context;
+ jobject fileObject;
+ jstring pathString;
+ const char *path;
+
+ JNIEnv *env = Android_JNI_GetEnv();
+ if (!LocalReferenceHolder_Init(&refs, env)) {
+ LocalReferenceHolder_Cleanup(&refs);
+ return NULL;
+ }
+
+ /* context = SDLActivity.getContext(); */
+ context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
+ if (!context) {
+ SDL_SetError("Couldn't get Android context!");
+ LocalReferenceHolder_Cleanup(&refs);
+ return NULL;
+ }
+
+ /* fileObj = context.getFilesDir(); */
+ mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
+ "getFilesDir", "()Ljava/io/File;");
+ fileObject = (*env)->CallObjectMethod(env, context, mid);
+ if (!fileObject) {
+ SDL_SetError("Couldn't get internal directory");
+ LocalReferenceHolder_Cleanup(&refs);
+ return NULL;
+ }
+
+ /* path = fileObject.getCanonicalPath(); */
+ mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, fileObject),
+ "getCanonicalPath", "()Ljava/lang/String;");
+ pathString = (jstring)(*env)->CallObjectMethod(env, fileObject, mid);
+ if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
+ LocalReferenceHolder_Cleanup(&refs);
+ return NULL;
+ }
+
+ path = (*env)->GetStringUTFChars(env, pathString, NULL);
+ s_AndroidInternalFilesPath = SDL_strdup(path);
+ (*env)->ReleaseStringUTFChars(env, pathString, path);
+
+ LocalReferenceHolder_Cleanup(&refs);
+ }
+ return s_AndroidInternalFilesPath;
+}
+
+int SDL_AndroidGetExternalStorageState(void)
+{
+ struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
+ jmethodID mid;
+ jclass cls;
+ jstring stateString;
+ const char *state;
+ int stateFlags;
+
+ JNIEnv *env = Android_JNI_GetEnv();
+ if (!LocalReferenceHolder_Init(&refs, env)) {
+ LocalReferenceHolder_Cleanup(&refs);
+ return 0;
+ }
+
+ cls = (*env)->FindClass(env, "android/os/Environment");
+ mid = (*env)->GetStaticMethodID(env, cls,
+ "getExternalStorageState", "()Ljava/lang/String;");
+ stateString = (jstring)(*env)->CallStaticObjectMethod(env, cls, mid);
+
+ state = (*env)->GetStringUTFChars(env, stateString, NULL);
+
+ /* Print an info message so people debugging know the storage state */
+ __android_log_print(ANDROID_LOG_INFO, "SDL", "external storage state: %s", state);
+
+ if (SDL_strcmp(state, "mounted") == 0) {
+ stateFlags = SDL_ANDROID_EXTERNAL_STORAGE_READ |
+ SDL_ANDROID_EXTERNAL_STORAGE_WRITE;
+ } else if (SDL_strcmp(state, "mounted_ro") == 0) {
+ stateFlags = SDL_ANDROID_EXTERNAL_STORAGE_READ;
+ } else {
+ stateFlags = 0;
+ }
+ (*env)->ReleaseStringUTFChars(env, stateString, state);
+
+ LocalReferenceHolder_Cleanup(&refs);
+ return stateFlags;
+}
+
+const char * SDL_AndroidGetExternalStoragePath(void)
+{
+ static char *s_AndroidExternalFilesPath = NULL;
+
+ if (!s_AndroidExternalFilesPath) {
+ struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
+ jmethodID mid;
+ jobject context;
+ jobject fileObject;
+ jstring pathString;
+ const char *path;
+
+ JNIEnv *env = Android_JNI_GetEnv();
+ if (!LocalReferenceHolder_Init(&refs, env)) {
+ LocalReferenceHolder_Cleanup(&refs);
+ return NULL;
+ }
+
+ /* context = SDLActivity.getContext(); */
+ context = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetContext);
+
+ /* fileObj = context.getExternalFilesDir(); */
+ mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
+ "getExternalFilesDir", "(Ljava/lang/String;)Ljava/io/File;");
+ fileObject = (*env)->CallObjectMethod(env, context, mid, NULL);
+ if (!fileObject) {
+ SDL_SetError("Couldn't get external directory");
+ LocalReferenceHolder_Cleanup(&refs);
+ return NULL;
+ }
+
+ /* path = fileObject.getAbsolutePath(); */
+ mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, fileObject),
+ "getAbsolutePath", "()Ljava/lang/String;");
+ pathString = (jstring)(*env)->CallObjectMethod(env, fileObject, mid);
+
+ path = (*env)->GetStringUTFChars(env, pathString, NULL);
+ s_AndroidExternalFilesPath = SDL_strdup(path);
+ (*env)->ReleaseStringUTFChars(env, pathString, path);
+
+ LocalReferenceHolder_Cleanup(&refs);
+ }
+ return s_AndroidExternalFilesPath;
+}
+
+void Android_JNI_GetManifestEnvironmentVariables(void)
+{
+ if (!mActivityClass || !midGetManifestEnvironmentVariables) {
+ __android_log_print(ANDROID_LOG_WARN, "SDL", "Request to get environment variables before JNI is ready");
+ return;
+ }
+
+ if (!bHasEnvironmentVariables) {
+ JNIEnv *env = Android_JNI_GetEnv();
+ SDL_bool ret = (*env)->CallStaticBooleanMethod(env, mActivityClass, midGetManifestEnvironmentVariables);
+ if (ret) {
+ bHasEnvironmentVariables = SDL_TRUE;
+ }
+ }
+}
+
+#endif /* __ANDROID__ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/android/SDL_android.h b/src/3rdparty/SDL2/src/core/android/SDL_android.h
new file mode 100644
index 0000000..c800dc6
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/android/SDL_android.h
@@ -0,0 +1,112 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+/* *INDENT-OFF* */
+extern "C" {
+/* *INDENT-ON* */
+#endif
+
+#include <EGL/eglplatform.h>
+#include <android/native_window_jni.h>
+
+#include "SDL_rect.h"
+
+/* Interface from the SDL library into the Android Java activity */
+extern void Android_JNI_SetActivityTitle(const char *title);
+extern void Android_JNI_SetWindowStyle(SDL_bool fullscreen);
+extern void Android_JNI_SetOrientation(int w, int h, int resizable, const char *hint);
+
+extern SDL_bool Android_JNI_GetAccelerometerValues(float values[3]);
+extern void Android_JNI_ShowTextInput(SDL_Rect *inputRect);
+extern void Android_JNI_HideTextInput(void);
+extern SDL_bool Android_JNI_IsScreenKeyboardShown(void);
+extern ANativeWindow* Android_JNI_GetNativeWindow(void);
+
+extern int Android_JNI_GetDisplayDPI(float *ddpi, float *xdpi, float *ydpi);
+
+/* Audio support */
+extern int Android_JNI_OpenAudioDevice(int iscapture, int sampleRate, int is16Bit, int channelCount, int desiredBufferFrames);
+extern void* Android_JNI_GetAudioBuffer(void);
+extern void Android_JNI_WriteAudioBuffer(void);
+extern int Android_JNI_CaptureAudioBuffer(void *buffer, int buflen);
+extern void Android_JNI_FlushCapturedAudio(void);
+extern void Android_JNI_CloseAudioDevice(const int iscapture);
+
+#include "SDL_rwops.h"
+
+int Android_JNI_FileOpen(SDL_RWops* ctx, const char* fileName, const char* mode);
+Sint64 Android_JNI_FileSize(SDL_RWops* ctx);
+Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence);
+size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer, size_t size, size_t maxnum);
+size_t Android_JNI_FileWrite(SDL_RWops* ctx, const void* buffer, size_t size, size_t num);
+int Android_JNI_FileClose(SDL_RWops* ctx);
+
+/* Environment support */
+void Android_JNI_GetManifestEnvironmentVariables(void);
+
+/* Clipboard support */
+int Android_JNI_SetClipboardText(const char* text);
+char* Android_JNI_GetClipboardText(void);
+SDL_bool Android_JNI_HasClipboardText(void);
+
+/* Power support */
+int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seconds, int* percent);
+
+/* Joystick support */
+void Android_JNI_PollInputDevices(void);
+
+/* Haptic support */
+void Android_JNI_PollHapticDevices(void);
+void Android_JNI_HapticRun(int device_id, int length);
+
+/* Video */
+void Android_JNI_SuspendScreenSaver(SDL_bool suspend);
+
+/* Touch support */
+int Android_JNI_GetTouchDeviceIds(int **ids);
+void Android_JNI_SetSeparateMouseAndTouch(SDL_bool new_value);
+
+/* Threads */
+#include <jni.h>
+JNIEnv *Android_JNI_GetEnv(void);
+int Android_JNI_SetupThread(void);
+
+/* Generic messages */
+int Android_JNI_SendMessage(int command, int param);
+
+/* Init */
+JNIEXPORT void JNICALL SDL_Android_Init(JNIEnv* mEnv, jclass cls);
+
+/* MessageBox */
+#include "SDL_messagebox.h"
+int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+/* *INDENT-OFF* */
+}
+/* *INDENT-ON* */
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/android/keyinfotable.h b/src/3rdparty/SDL2/src/core/android/keyinfotable.h
new file mode 100644
index 0000000..4437121
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/android/keyinfotable.h
@@ -0,0 +1,175 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef _ANDROID_KeyInfo
+#define _ANDROID_KeyInfo
+
+#include "SDL_scancode.h"
+#include "SDL_keycode.h"
+
+/*
+ This file is used by the keyboard code in SDL_uikitview.m to convert between characters
+ passed in from the iPhone's virtual keyboard, and tuples of SDL_Scancode and SDL_keymods.
+ For example unicharToUIKeyInfoTable['a'] would give you the scan code and keymod for lower
+ case a.
+*/
+
+typedef struct
+{
+ SDL_Scancode code;
+ uint16_t mod;
+} AndroidKeyInfo;
+
+/* So far only ASCII characters here */
+static AndroidKeyInfo unicharToAndroidKeyInfoTable[] = {
+/* 0 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 1 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 2 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 3 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 4 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 5 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 6 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 7 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 8 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 9 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 10 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 11 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 12 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 13 */ { SDL_SCANCODE_RETURN, 0 },
+/* 14 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 15 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 16 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 17 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 18 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 19 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 20 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 21 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 22 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 23 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 24 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 25 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 26 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 27 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 28 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 29 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 30 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 31 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 32 */ { SDL_SCANCODE_SPACE, 0 },
+/* 33 */ { SDL_SCANCODE_1, KMOD_SHIFT }, /* plus shift modifier '!' */
+/* 34 */ { SDL_SCANCODE_APOSTROPHE, KMOD_SHIFT }, /* plus shift modifier '"' */
+/* 35 */ { SDL_SCANCODE_3, KMOD_SHIFT }, /* plus shift modifier '#' */
+/* 36 */ { SDL_SCANCODE_4, KMOD_SHIFT }, /* plus shift modifier '$' */
+/* 37 */ { SDL_SCANCODE_5, KMOD_SHIFT }, /* plus shift modifier '%' */
+/* 38 */ { SDL_SCANCODE_7, KMOD_SHIFT }, /* plus shift modifier '&' */
+/* 39 */ { SDL_SCANCODE_APOSTROPHE, 0 }, /* ''' */
+/* 40 */ { SDL_SCANCODE_9, KMOD_SHIFT }, /* plus shift modifier '(' */
+/* 41 */ { SDL_SCANCODE_0, KMOD_SHIFT }, /* plus shift modifier ')' */
+/* 42 */ { SDL_SCANCODE_8, KMOD_SHIFT }, /* '*' */
+/* 43 */ { SDL_SCANCODE_EQUALS, KMOD_SHIFT }, /* plus shift modifier '+' */
+/* 44 */ { SDL_SCANCODE_COMMA, 0 }, /* ',' */
+/* 45 */ { SDL_SCANCODE_MINUS, 0 }, /* '-' */
+/* 46 */ { SDL_SCANCODE_PERIOD, 0 }, /* '.' */
+/* 47 */ { SDL_SCANCODE_SLASH, 0 }, /* '/' */
+/* 48 */ { SDL_SCANCODE_0, 0 },
+/* 49 */ { SDL_SCANCODE_1, 0 },
+/* 50 */ { SDL_SCANCODE_2, 0 },
+/* 51 */ { SDL_SCANCODE_3, 0 },
+/* 52 */ { SDL_SCANCODE_4, 0 },
+/* 53 */ { SDL_SCANCODE_5, 0 },
+/* 54 */ { SDL_SCANCODE_6, 0 },
+/* 55 */ { SDL_SCANCODE_7, 0 },
+/* 56 */ { SDL_SCANCODE_8, 0 },
+/* 57 */ { SDL_SCANCODE_9, 0 },
+/* 58 */ { SDL_SCANCODE_SEMICOLON, KMOD_SHIFT }, /* plus shift modifier ';' */
+/* 59 */ { SDL_SCANCODE_SEMICOLON, 0 },
+/* 60 */ { SDL_SCANCODE_COMMA, KMOD_SHIFT }, /* plus shift modifier '<' */
+/* 61 */ { SDL_SCANCODE_EQUALS, 0 },
+/* 62 */ { SDL_SCANCODE_PERIOD, KMOD_SHIFT }, /* plus shift modifier '>' */
+/* 63 */ { SDL_SCANCODE_SLASH, KMOD_SHIFT }, /* plus shift modifier '?' */
+/* 64 */ { SDL_SCANCODE_2, KMOD_SHIFT }, /* plus shift modifier '@' */
+/* 65 */ { SDL_SCANCODE_A, KMOD_SHIFT }, /* all the following need shift modifiers */
+/* 66 */ { SDL_SCANCODE_B, KMOD_SHIFT },
+/* 67 */ { SDL_SCANCODE_C, KMOD_SHIFT },
+/* 68 */ { SDL_SCANCODE_D, KMOD_SHIFT },
+/* 69 */ { SDL_SCANCODE_E, KMOD_SHIFT },
+/* 70 */ { SDL_SCANCODE_F, KMOD_SHIFT },
+/* 71 */ { SDL_SCANCODE_G, KMOD_SHIFT },
+/* 72 */ { SDL_SCANCODE_H, KMOD_SHIFT },
+/* 73 */ { SDL_SCANCODE_I, KMOD_SHIFT },
+/* 74 */ { SDL_SCANCODE_J, KMOD_SHIFT },
+/* 75 */ { SDL_SCANCODE_K, KMOD_SHIFT },
+/* 76 */ { SDL_SCANCODE_L, KMOD_SHIFT },
+/* 77 */ { SDL_SCANCODE_M, KMOD_SHIFT },
+/* 78 */ { SDL_SCANCODE_N, KMOD_SHIFT },
+/* 79 */ { SDL_SCANCODE_O, KMOD_SHIFT },
+/* 80 */ { SDL_SCANCODE_P, KMOD_SHIFT },
+/* 81 */ { SDL_SCANCODE_Q, KMOD_SHIFT },
+/* 82 */ { SDL_SCANCODE_R, KMOD_SHIFT },
+/* 83 */ { SDL_SCANCODE_S, KMOD_SHIFT },
+/* 84 */ { SDL_SCANCODE_T, KMOD_SHIFT },
+/* 85 */ { SDL_SCANCODE_U, KMOD_SHIFT },
+/* 86 */ { SDL_SCANCODE_V, KMOD_SHIFT },
+/* 87 */ { SDL_SCANCODE_W, KMOD_SHIFT },
+/* 88 */ { SDL_SCANCODE_X, KMOD_SHIFT },
+/* 89 */ { SDL_SCANCODE_Y, KMOD_SHIFT },
+/* 90 */ { SDL_SCANCODE_Z, KMOD_SHIFT },
+/* 91 */ { SDL_SCANCODE_LEFTBRACKET, 0 },
+/* 92 */ { SDL_SCANCODE_BACKSLASH, 0 },
+/* 93 */ { SDL_SCANCODE_RIGHTBRACKET, 0 },
+/* 94 */ { SDL_SCANCODE_6, KMOD_SHIFT }, /* plus shift modifier '^' */
+/* 95 */ { SDL_SCANCODE_MINUS, KMOD_SHIFT }, /* plus shift modifier '_' */
+/* 96 */ { SDL_SCANCODE_GRAVE, KMOD_SHIFT }, /* '`' */
+/* 97 */ { SDL_SCANCODE_A, 0 },
+/* 98 */ { SDL_SCANCODE_B, 0 },
+/* 99 */ { SDL_SCANCODE_C, 0 },
+/* 100 */{ SDL_SCANCODE_D, 0 },
+/* 101 */{ SDL_SCANCODE_E, 0 },
+/* 102 */{ SDL_SCANCODE_F, 0 },
+/* 103 */{ SDL_SCANCODE_G, 0 },
+/* 104 */{ SDL_SCANCODE_H, 0 },
+/* 105 */{ SDL_SCANCODE_I, 0 },
+/* 106 */{ SDL_SCANCODE_J, 0 },
+/* 107 */{ SDL_SCANCODE_K, 0 },
+/* 108 */{ SDL_SCANCODE_L, 0 },
+/* 109 */{ SDL_SCANCODE_M, 0 },
+/* 110 */{ SDL_SCANCODE_N, 0 },
+/* 111 */{ SDL_SCANCODE_O, 0 },
+/* 112 */{ SDL_SCANCODE_P, 0 },
+/* 113 */{ SDL_SCANCODE_Q, 0 },
+/* 114 */{ SDL_SCANCODE_R, 0 },
+/* 115 */{ SDL_SCANCODE_S, 0 },
+/* 116 */{ SDL_SCANCODE_T, 0 },
+/* 117 */{ SDL_SCANCODE_U, 0 },
+/* 118 */{ SDL_SCANCODE_V, 0 },
+/* 119 */{ SDL_SCANCODE_W, 0 },
+/* 120 */{ SDL_SCANCODE_X, 0 },
+/* 121 */{ SDL_SCANCODE_Y, 0 },
+/* 122 */{ SDL_SCANCODE_Z, 0 },
+/* 123 */{ SDL_SCANCODE_LEFTBRACKET, KMOD_SHIFT }, /* plus shift modifier '{' */
+/* 124 */{ SDL_SCANCODE_BACKSLASH, KMOD_SHIFT }, /* plus shift modifier '|' */
+/* 125 */{ SDL_SCANCODE_RIGHTBRACKET, KMOD_SHIFT }, /* plus shift modifier '}' */
+/* 126 */{ SDL_SCANCODE_GRAVE, KMOD_SHIFT }, /* plus shift modifier '~' */
+/* 127 */{ SDL_SCANCODE_BACKSPACE, KMOD_SHIFT }
+};
+
+#endif /* _ANDROID_KeyInfo */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/linux/SDL_dbus.c b/src/3rdparty/SDL2/src/core/linux/SDL_dbus.c
new file mode 100644
index 0000000..ff4f0fe
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/linux/SDL_dbus.c
@@ -0,0 +1,335 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+#include "SDL_dbus.h"
+
+#if SDL_USE_LIBDBUS
+/* we never link directly to libdbus. */
+#include "SDL_loadso.h"
+static const char *dbus_library = "libdbus-1.so.3";
+static void *dbus_handle = NULL;
+static unsigned int screensaver_cookie = 0;
+static SDL_DBusContext dbus;
+
+static int
+LoadDBUSSyms(void)
+{
+ #define SDL_DBUS_SYM2(x, y) \
+ if (!(dbus.x = SDL_LoadFunction(dbus_handle, #y))) return -1
+
+ #define SDL_DBUS_SYM(x) \
+ SDL_DBUS_SYM2(x, dbus_##x)
+
+ SDL_DBUS_SYM(bus_get_private);
+ SDL_DBUS_SYM(bus_register);
+ SDL_DBUS_SYM(bus_add_match);
+ SDL_DBUS_SYM(connection_open_private);
+ SDL_DBUS_SYM(connection_set_exit_on_disconnect);
+ SDL_DBUS_SYM(connection_get_is_connected);
+ SDL_DBUS_SYM(connection_add_filter);
+ SDL_DBUS_SYM(connection_try_register_object_path);
+ SDL_DBUS_SYM(connection_send);
+ SDL_DBUS_SYM(connection_send_with_reply_and_block);
+ SDL_DBUS_SYM(connection_close);
+ SDL_DBUS_SYM(connection_unref);
+ SDL_DBUS_SYM(connection_flush);
+ SDL_DBUS_SYM(connection_read_write);
+ SDL_DBUS_SYM(connection_dispatch);
+ SDL_DBUS_SYM(message_is_signal);
+ SDL_DBUS_SYM(message_new_method_call);
+ SDL_DBUS_SYM(message_append_args);
+ SDL_DBUS_SYM(message_append_args_valist);
+ SDL_DBUS_SYM(message_get_args);
+ SDL_DBUS_SYM(message_get_args_valist);
+ SDL_DBUS_SYM(message_iter_init);
+ SDL_DBUS_SYM(message_iter_next);
+ SDL_DBUS_SYM(message_iter_get_basic);
+ SDL_DBUS_SYM(message_iter_get_arg_type);
+ SDL_DBUS_SYM(message_iter_recurse);
+ SDL_DBUS_SYM(message_unref);
+ SDL_DBUS_SYM(error_init);
+ SDL_DBUS_SYM(error_is_set);
+ SDL_DBUS_SYM(error_free);
+ SDL_DBUS_SYM(get_local_machine_id);
+ SDL_DBUS_SYM(free);
+ SDL_DBUS_SYM(free_string_array);
+ SDL_DBUS_SYM(shutdown);
+
+ #undef SDL_DBUS_SYM
+ #undef SDL_DBUS_SYM2
+
+ return 0;
+}
+
+static void
+UnloadDBUSLibrary(void)
+{
+ if (dbus_handle != NULL) {
+ SDL_UnloadObject(dbus_handle);
+ dbus_handle = NULL;
+ }
+}
+
+static int
+LoadDBUSLibrary(void)
+{
+ int retval = 0;
+ if (dbus_handle == NULL) {
+ dbus_handle = SDL_LoadObject(dbus_library);
+ if (dbus_handle == NULL) {
+ retval = -1;
+ /* Don't call SDL_SetError(): SDL_LoadObject already did. */
+ } else {
+ retval = LoadDBUSSyms();
+ if (retval < 0) {
+ UnloadDBUSLibrary();
+ }
+ }
+ }
+
+ return retval;
+}
+
+void
+SDL_DBus_Init(void)
+{
+ if (!dbus.session_conn && LoadDBUSLibrary() != -1) {
+ DBusError err;
+ dbus.error_init(&err);
+ dbus.session_conn = dbus.bus_get_private(DBUS_BUS_SESSION, &err);
+ if (!dbus.error_is_set(&err)) {
+ dbus.system_conn = dbus.bus_get_private(DBUS_BUS_SYSTEM, &err);
+ }
+ if (dbus.error_is_set(&err)) {
+ dbus.error_free(&err);
+ SDL_DBus_Quit();
+ return; /* oh well */
+ }
+ dbus.connection_set_exit_on_disconnect(dbus.system_conn, 0);
+ dbus.connection_set_exit_on_disconnect(dbus.session_conn, 0);
+ }
+}
+
+void
+SDL_DBus_Quit(void)
+{
+ if (dbus.system_conn) {
+ dbus.connection_close(dbus.system_conn);
+ dbus.connection_unref(dbus.system_conn);
+ }
+ if (dbus.session_conn) {
+ dbus.connection_close(dbus.session_conn);
+ dbus.connection_unref(dbus.session_conn);
+ }
+/* Don't do this - bug 3950
+ dbus_shutdown() is a debug feature which closes all global resources in the dbus library. Calling this should be done by the app, not a library, because if there are multiple users of dbus in the process then SDL could shut it down even though another part is using it.
+*/
+#if 0
+ if (dbus.shutdown) {
+ dbus.shutdown();
+ }
+#endif
+ SDL_zero(dbus);
+ UnloadDBUSLibrary();
+}
+
+SDL_DBusContext *
+SDL_DBus_GetContext(void)
+{
+ if(!dbus_handle || !dbus.session_conn){
+ SDL_DBus_Init();
+ }
+
+ if(dbus_handle && dbus.session_conn){
+ return &dbus;
+ } else {
+ return NULL;
+ }
+}
+
+static SDL_bool
+SDL_DBus_CallMethodInternal(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, va_list ap)
+{
+ SDL_bool retval = SDL_FALSE;
+
+ if (conn) {
+ DBusMessage *msg = dbus.message_new_method_call(node, path, interface, method);
+ if (msg) {
+ int firstarg = va_arg(ap, int);
+ if ((firstarg == DBUS_TYPE_INVALID) || dbus.message_append_args_valist(msg, firstarg, ap)) {
+ DBusMessage *reply = dbus.connection_send_with_reply_and_block(conn, msg, 300, NULL);
+ if (reply) {
+ firstarg = va_arg(ap, int);
+ if ((firstarg == DBUS_TYPE_INVALID) || dbus.message_get_args_valist(reply, NULL, firstarg, ap)) {
+ retval = SDL_TRUE;
+ }
+ dbus.message_unref(reply);
+ }
+ }
+ dbus.message_unref(msg);
+ }
+ }
+
+ return retval;
+}
+
+SDL_bool
+SDL_DBus_CallMethodOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...)
+{
+ SDL_bool retval;
+ va_list ap;
+ va_start(ap, method);
+ retval = SDL_DBus_CallMethodInternal(conn, node, path, interface, method, ap);
+ va_end(ap);
+ return retval;
+}
+
+SDL_bool
+SDL_DBus_CallMethod(const char *node, const char *path, const char *interface, const char *method, ...)
+{
+ SDL_bool retval;
+ va_list ap;
+ va_start(ap, method);
+ retval = SDL_DBus_CallMethodInternal(dbus.session_conn, node, path, interface, method, ap);
+ va_end(ap);
+ return retval;
+}
+
+static SDL_bool
+SDL_DBus_CallVoidMethodInternal(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, va_list ap)
+{
+ SDL_bool retval = SDL_FALSE;
+
+ if (conn) {
+ DBusMessage *msg = dbus.message_new_method_call(node, path, interface, method);
+ if (msg) {
+ int firstarg = va_arg(ap, int);
+ if ((firstarg == DBUS_TYPE_INVALID) || dbus.message_append_args_valist(msg, firstarg, ap)) {
+ if (dbus.connection_send(conn, msg, NULL)) {
+ dbus.connection_flush(conn);
+ retval = SDL_TRUE;
+ }
+ }
+
+ dbus.message_unref(msg);
+ }
+ }
+
+ return retval;
+}
+
+SDL_bool
+SDL_DBus_CallVoidMethodOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...)
+{
+ SDL_bool retval;
+ va_list ap;
+ va_start(ap, method);
+ retval = SDL_DBus_CallVoidMethodInternal(conn, node, path, interface, method, ap);
+ va_end(ap);
+ return retval;
+}
+
+SDL_bool
+SDL_DBus_CallVoidMethod(const char *node, const char *path, const char *interface, const char *method, ...)
+{
+ SDL_bool retval;
+ va_list ap;
+ va_start(ap, method);
+ retval = SDL_DBus_CallVoidMethodInternal(dbus.session_conn, node, path, interface, method, ap);
+ va_end(ap);
+ return retval;
+}
+
+SDL_bool
+SDL_DBus_QueryPropertyOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *property, const int expectedtype, void *result)
+{
+ SDL_bool retval = SDL_FALSE;
+
+ if (conn) {
+ DBusMessage *msg = dbus.message_new_method_call(node, path, "org.freedesktop.DBus.Properties", "Get");
+ if (msg) {
+ if (dbus.message_append_args(msg, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID)) {
+ DBusMessage *reply = dbus.connection_send_with_reply_and_block(conn, msg, 300, NULL);
+ if (reply) {
+ DBusMessageIter iter, sub;
+ dbus.message_iter_init(reply, &iter);
+ if (dbus.message_iter_get_arg_type(&iter) == DBUS_TYPE_VARIANT) {
+ dbus.message_iter_recurse(&iter, &sub);
+ if (dbus.message_iter_get_arg_type(&sub) == expectedtype) {
+ dbus.message_iter_get_basic(&sub, result);
+ retval = SDL_TRUE;
+ }
+ }
+ dbus.message_unref(reply);
+ }
+ }
+ dbus.message_unref(msg);
+ }
+ }
+
+ return retval;
+}
+
+SDL_bool
+SDL_DBus_QueryProperty(const char *node, const char *path, const char *interface, const char *property, const int expectedtype, void *result)
+{
+ return SDL_DBus_QueryPropertyOnConnection(dbus.session_conn, node, path, interface, property, expectedtype, result);
+}
+
+
+void
+SDL_DBus_ScreensaverTickle(void)
+{
+ SDL_DBus_CallVoidMethod("org.gnome.ScreenSaver", "/org/gnome/ScreenSaver", "org.gnome.ScreenSaver", "SimulateUserActivity", DBUS_TYPE_INVALID);
+}
+
+SDL_bool
+SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
+{
+ if ( (inhibit && (screensaver_cookie != 0)) || (!inhibit && (screensaver_cookie == 0)) ) {
+ return SDL_TRUE;
+ } else {
+ const char *node = "org.freedesktop.ScreenSaver";
+ const char *path = "/org/freedesktop/ScreenSaver";
+ const char *interface = "org.freedesktop.ScreenSaver";
+
+ if (inhibit) {
+ const char *app = "My SDL application";
+ const char *reason = "Playing a game";
+ if (!SDL_DBus_CallMethod(node, path, interface, "Inhibit",
+ DBUS_TYPE_STRING, &app, DBUS_TYPE_STRING, &reason, DBUS_TYPE_INVALID,
+ DBUS_TYPE_UINT32, &screensaver_cookie, DBUS_TYPE_INVALID)) {
+ return SDL_FALSE;
+ }
+ return (screensaver_cookie != 0) ? SDL_TRUE : SDL_FALSE;
+ } else {
+ if (!SDL_DBus_CallVoidMethod(node, path, interface, "UnInhibit", DBUS_TYPE_UINT32, &screensaver_cookie, DBUS_TYPE_INVALID)) {
+ return SDL_FALSE;
+ }
+ screensaver_cookie = 0;
+ }
+ }
+
+ return SDL_TRUE;
+}
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/linux/SDL_dbus.h b/src/3rdparty/SDL2/src/core/linux/SDL_dbus.h
new file mode 100644
index 0000000..062543d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/linux/SDL_dbus.h
@@ -0,0 +1,97 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_dbus_h_
+#define SDL_dbus_h_
+
+#ifdef HAVE_DBUS_DBUS_H
+#define SDL_USE_LIBDBUS 1
+#include "SDL_stdinc.h"
+#include <dbus/dbus.h>
+
+
+typedef struct SDL_DBusContext {
+ DBusConnection *session_conn;
+ DBusConnection *system_conn;
+
+ DBusConnection *(*bus_get_private)(DBusBusType, DBusError *);
+ dbus_bool_t (*bus_register)(DBusConnection *, DBusError *);
+ void (*bus_add_match)(DBusConnection *, const char *, DBusError *);
+ DBusConnection * (*connection_open_private)(const char *, DBusError *);
+ void (*connection_set_exit_on_disconnect)(DBusConnection *, dbus_bool_t);
+ dbus_bool_t (*connection_get_is_connected)(DBusConnection *);
+ dbus_bool_t (*connection_add_filter)(DBusConnection *, DBusHandleMessageFunction,
+ void *, DBusFreeFunction);
+ dbus_bool_t (*connection_try_register_object_path)(DBusConnection *, const char *,
+ const DBusObjectPathVTable *, void *, DBusError *);
+ dbus_bool_t (*connection_send)(DBusConnection *, DBusMessage *, dbus_uint32_t *);
+ DBusMessage *(*connection_send_with_reply_and_block)(DBusConnection *, DBusMessage *, int, DBusError *);
+ void (*connection_close)(DBusConnection *);
+ void (*connection_unref)(DBusConnection *);
+ void (*connection_flush)(DBusConnection *);
+ dbus_bool_t (*connection_read_write)(DBusConnection *, int);
+ DBusDispatchStatus (*connection_dispatch)(DBusConnection *);
+ dbus_bool_t (*message_is_signal)(DBusMessage *, const char *, const char *);
+ DBusMessage *(*message_new_method_call)(const char *, const char *, const char *, const char *);
+ dbus_bool_t (*message_append_args)(DBusMessage *, int, ...);
+ dbus_bool_t (*message_append_args_valist)(DBusMessage *, int, va_list);
+ dbus_bool_t (*message_get_args)(DBusMessage *, DBusError *, int, ...);
+ dbus_bool_t (*message_get_args_valist)(DBusMessage *, DBusError *, int, va_list);
+ dbus_bool_t (*message_iter_init)(DBusMessage *, DBusMessageIter *);
+ dbus_bool_t (*message_iter_next)(DBusMessageIter *);
+ void (*message_iter_get_basic)(DBusMessageIter *, void *);
+ int (*message_iter_get_arg_type)(DBusMessageIter *);
+ void (*message_iter_recurse)(DBusMessageIter *, DBusMessageIter *);
+ void (*message_unref)(DBusMessage *);
+ void (*error_init)(DBusError *);
+ dbus_bool_t (*error_is_set)(const DBusError *);
+ void (*error_free)(DBusError *);
+ char *(*get_local_machine_id)(void);
+ void (*free)(void *);
+ void (*free_string_array)(char **);
+ void (*shutdown)(void);
+
+} SDL_DBusContext;
+
+extern void SDL_DBus_Init(void);
+extern void SDL_DBus_Quit(void);
+extern SDL_DBusContext * SDL_DBus_GetContext(void);
+
+/* These use the built-in Session connection. */
+extern SDL_bool SDL_DBus_CallMethod(const char *node, const char *path, const char *interface, const char *method, ...);
+extern SDL_bool SDL_DBus_CallVoidMethod(const char *node, const char *path, const char *interface, const char *method, ...);
+extern SDL_bool SDL_DBus_QueryProperty(const char *node, const char *path, const char *interface, const char *property, const int expectedtype, void *result);
+
+/* These use whatever connection you like. */
+extern SDL_bool SDL_DBus_CallMethodOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...);
+extern SDL_bool SDL_DBus_CallVoidMethodOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...);
+extern SDL_bool SDL_DBus_QueryPropertyOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *property, const int expectedtype, void *result);
+
+extern void SDL_DBus_ScreensaverTickle(void);
+extern SDL_bool SDL_DBus_ScreensaverInhibit(SDL_bool inhibit);
+
+#endif /* HAVE_DBUS_DBUS_H */
+
+#endif /* SDL_dbus_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/linux/SDL_evdev.c b/src/3rdparty/SDL2/src/core/linux/SDL_evdev.c
new file mode 100644
index 0000000..a506926
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/linux/SDL_evdev.c
@@ -0,0 +1,698 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_INPUT_LINUXEV
+
+/* This is based on the linux joystick driver */
+/* References: https://www.kernel.org/doc/Documentation/input/input.txt
+ * https://www.kernel.org/doc/Documentation/input/event-codes.txt
+ * /usr/include/linux/input.h
+ * The evtest application is also useful to debug the protocol
+ */
+
+#include "SDL_evdev.h"
+#include "SDL_evdev_kbd.h"
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/input.h>
+
+#include "SDL.h"
+#include "SDL_assert.h"
+#include "SDL_endian.h"
+#include "SDL_scancode.h"
+#include "../../events/SDL_events_c.h"
+#include "../../events/scancodes_linux.h" /* adds linux_scancode_table */
+#include "../../core/linux/SDL_udev.h"
+
+/* These are not defined in older Linux kernel headers */
+#ifndef SYN_DROPPED
+#define SYN_DROPPED 3
+#endif
+#ifndef ABS_MT_SLOT
+#define ABS_MT_SLOT 0x2f
+#define ABS_MT_POSITION_X 0x35
+#define ABS_MT_POSITION_Y 0x36
+#define ABS_MT_TRACKING_ID 0x39
+#endif
+
+typedef struct SDL_evdevlist_item
+{
+ char *path;
+ int fd;
+
+ /* TODO: use this for every device, not just touchscreen */
+ int out_of_sync;
+
+ /* TODO: expand on this to have data for every possible class (mouse,
+ keyboard, touchpad, etc.). Also there's probably some things in here we
+ can pull out to the SDL_evdevlist_item i.e. name */
+ int is_touchscreen;
+ struct {
+ char* name;
+
+ int min_x, max_x, range_x;
+ int min_y, max_y, range_y;
+
+ int max_slots;
+ int current_slot;
+ struct {
+ enum {
+ EVDEV_TOUCH_SLOTDELTA_NONE = 0,
+ EVDEV_TOUCH_SLOTDELTA_DOWN,
+ EVDEV_TOUCH_SLOTDELTA_UP,
+ EVDEV_TOUCH_SLOTDELTA_MOVE
+ } delta;
+ int tracking_id;
+ int x, y;
+ } * slots;
+ } * touchscreen_data;
+
+ struct SDL_evdevlist_item *next;
+} SDL_evdevlist_item;
+
+typedef struct SDL_EVDEV_PrivateData
+{
+ int ref_count;
+ int num_devices;
+ SDL_evdevlist_item *first;
+ SDL_evdevlist_item *last;
+ SDL_EVDEV_keyboard_state *kbd;
+} SDL_EVDEV_PrivateData;
+
+#define _THIS SDL_EVDEV_PrivateData *_this
+static _THIS = NULL;
+
+static SDL_Scancode SDL_EVDEV_translate_keycode(int keycode);
+static void SDL_EVDEV_sync_device(SDL_evdevlist_item *item);
+static int SDL_EVDEV_device_removed(const char *dev_path);
+
+#if SDL_USE_LIBUDEV
+static int SDL_EVDEV_device_added(const char *dev_path, int udev_class);
+static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class,
+ const char *dev_path);
+#endif /* SDL_USE_LIBUDEV */
+
+static Uint8 EVDEV_MouseButtons[] = {
+ SDL_BUTTON_LEFT, /* BTN_LEFT 0x110 */
+ SDL_BUTTON_RIGHT, /* BTN_RIGHT 0x111 */
+ SDL_BUTTON_MIDDLE, /* BTN_MIDDLE 0x112 */
+ SDL_BUTTON_X1, /* BTN_SIDE 0x113 */
+ SDL_BUTTON_X2, /* BTN_EXTRA 0x114 */
+ SDL_BUTTON_X2 + 1, /* BTN_FORWARD 0x115 */
+ SDL_BUTTON_X2 + 2, /* BTN_BACK 0x116 */
+ SDL_BUTTON_X2 + 3 /* BTN_TASK 0x117 */
+};
+
+int
+SDL_EVDEV_Init(void)
+{
+ if (_this == NULL) {
+ _this = (SDL_EVDEV_PrivateData*)SDL_calloc(1, sizeof(*_this));
+ if (_this == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+#if SDL_USE_LIBUDEV
+ if (SDL_UDEV_Init() < 0) {
+ SDL_free(_this);
+ _this = NULL;
+ return -1;
+ }
+
+ /* Set up the udev callback */
+ if (SDL_UDEV_AddCallback(SDL_EVDEV_udev_callback) < 0) {
+ SDL_UDEV_Quit();
+ SDL_free(_this);
+ _this = NULL;
+ return -1;
+ }
+
+ /* Force a scan to build the initial device list */
+ SDL_UDEV_Scan();
+#else
+ /* TODO: Scan the devices manually, like a caveman */
+#endif /* SDL_USE_LIBUDEV */
+
+ _this->kbd = SDL_EVDEV_kbd_init();
+ }
+
+ _this->ref_count += 1;
+
+ return 0;
+}
+
+void
+SDL_EVDEV_Quit(void)
+{
+ if (_this == NULL) {
+ return;
+ }
+
+ _this->ref_count -= 1;
+
+ if (_this->ref_count < 1) {
+#if SDL_USE_LIBUDEV
+ SDL_UDEV_DelCallback(SDL_EVDEV_udev_callback);
+ SDL_UDEV_Quit();
+#endif /* SDL_USE_LIBUDEV */
+
+ SDL_EVDEV_kbd_quit(_this->kbd);
+
+ /* Remove existing devices */
+ while(_this->first != NULL) {
+ SDL_EVDEV_device_removed(_this->first->path);
+ }
+
+ SDL_assert(_this->first == NULL);
+ SDL_assert(_this->last == NULL);
+ SDL_assert(_this->num_devices == 0);
+
+ SDL_free(_this);
+ _this = NULL;
+ }
+}
+
+#if SDL_USE_LIBUDEV
+static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_class,
+ const char* dev_path)
+{
+ if (dev_path == NULL) {
+ return;
+ }
+
+ switch(udev_event) {
+ case SDL_UDEV_DEVICEADDED:
+ if (!(udev_class & (SDL_UDEV_DEVICE_MOUSE | SDL_UDEV_DEVICE_KEYBOARD |
+ SDL_UDEV_DEVICE_TOUCHSCREEN)))
+ return;
+
+ SDL_EVDEV_device_added(dev_path, udev_class);
+ break;
+ case SDL_UDEV_DEVICEREMOVED:
+ SDL_EVDEV_device_removed(dev_path);
+ break;
+ default:
+ break;
+ }
+}
+#endif /* SDL_USE_LIBUDEV */
+
+void
+SDL_EVDEV_Poll(void)
+{
+ struct input_event events[32];
+ int i, j, len;
+ SDL_evdevlist_item *item;
+ SDL_Scancode scan_code;
+ int mouse_button;
+ SDL_Mouse *mouse;
+ float norm_x, norm_y;
+
+ if (!_this) {
+ return;
+ }
+
+#if SDL_USE_LIBUDEV
+ SDL_UDEV_Poll();
+#endif
+
+ mouse = SDL_GetMouse();
+
+ for (item = _this->first; item != NULL; item = item->next) {
+ while ((len = read(item->fd, events, (sizeof events))) > 0) {
+ len /= sizeof(events[0]);
+ for (i = 0; i < len; ++i) {
+ /* special handling for touchscreen, that should eventually be
+ used for all devices */
+ if (item->out_of_sync && item->is_touchscreen &&
+ events[i].type == EV_SYN && events[i].code != SYN_REPORT) {
+ break;
+ }
+
+ switch (events[i].type) {
+ case EV_KEY:
+ if (events[i].code >= BTN_MOUSE && events[i].code < BTN_MOUSE + SDL_arraysize(EVDEV_MouseButtons)) {
+ mouse_button = events[i].code - BTN_MOUSE;
+ if (events[i].value == 0) {
+ SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, EVDEV_MouseButtons[mouse_button]);
+ } else if (events[i].value == 1) {
+ SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_PRESSED, EVDEV_MouseButtons[mouse_button]);
+ }
+ break;
+ }
+
+ /* Probably keyboard */
+ scan_code = SDL_EVDEV_translate_keycode(events[i].code);
+ if (scan_code != SDL_SCANCODE_UNKNOWN) {
+ if (events[i].value == 0) {
+ SDL_SendKeyboardKey(SDL_RELEASED, scan_code);
+ } else if (events[i].value == 1 || events[i].value == 2 /* key repeated */) {
+ SDL_SendKeyboardKey(SDL_PRESSED, scan_code);
+ }
+ }
+ SDL_EVDEV_kbd_keycode(_this->kbd, events[i].code, events[i].value);
+ break;
+ case EV_ABS:
+ switch(events[i].code) {
+ case ABS_MT_SLOT:
+ if (!item->is_touchscreen) /* FIXME: temp hack */
+ break;
+ item->touchscreen_data->current_slot = events[i].value;
+ break;
+ case ABS_MT_TRACKING_ID:
+ if (!item->is_touchscreen) /* FIXME: temp hack */
+ break;
+ if (events[i].value >= 0) {
+ item->touchscreen_data->slots[item->touchscreen_data->current_slot].tracking_id = events[i].value;
+ item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_DOWN;
+ } else {
+ item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_UP;
+ }
+ break;
+ case ABS_MT_POSITION_X:
+ if (!item->is_touchscreen) /* FIXME: temp hack */
+ break;
+ item->touchscreen_data->slots[item->touchscreen_data->current_slot].x = events[i].value;
+ if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) {
+ item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE;
+ }
+ break;
+ case ABS_MT_POSITION_Y:
+ if (!item->is_touchscreen) /* FIXME: temp hack */
+ break;
+ item->touchscreen_data->slots[item->touchscreen_data->current_slot].y = events[i].value;
+ if (item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta == EVDEV_TOUCH_SLOTDELTA_NONE) {
+ item->touchscreen_data->slots[item->touchscreen_data->current_slot].delta = EVDEV_TOUCH_SLOTDELTA_MOVE;
+ }
+ break;
+ case ABS_X:
+ if (item->is_touchscreen) /* FIXME: temp hack */
+ break;
+ SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_FALSE, events[i].value, mouse->y);
+ break;
+ case ABS_Y:
+ if (item->is_touchscreen) /* FIXME: temp hack */
+ break;
+ SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_FALSE, mouse->x, events[i].value);
+ break;
+ default:
+ break;
+ }
+ break;
+ case EV_REL:
+ switch(events[i].code) {
+ case REL_X:
+ SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_TRUE, events[i].value, 0);
+ break;
+ case REL_Y:
+ SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_TRUE, 0, events[i].value);
+ break;
+ case REL_WHEEL:
+ SDL_SendMouseWheel(mouse->focus, mouse->mouseID, 0, events[i].value, SDL_MOUSEWHEEL_NORMAL);
+ break;
+ case REL_HWHEEL:
+ SDL_SendMouseWheel(mouse->focus, mouse->mouseID, events[i].value, 0, SDL_MOUSEWHEEL_NORMAL);
+ break;
+ default:
+ break;
+ }
+ break;
+ case EV_SYN:
+ switch (events[i].code) {
+ case SYN_REPORT:
+ if (!item->is_touchscreen) /* FIXME: temp hack */
+ break;
+
+ for(j = 0; j < item->touchscreen_data->max_slots; j++) {
+ norm_x = (float)(item->touchscreen_data->slots[j].x - item->touchscreen_data->min_x) /
+ (float)item->touchscreen_data->range_x;
+ norm_y = (float)(item->touchscreen_data->slots[j].y - item->touchscreen_data->min_y) /
+ (float)item->touchscreen_data->range_y;
+
+ switch(item->touchscreen_data->slots[j].delta) {
+ case EVDEV_TOUCH_SLOTDELTA_DOWN:
+ SDL_SendTouch(item->fd, item->touchscreen_data->slots[j].tracking_id, SDL_TRUE, norm_x, norm_y, 1.0f);
+ item->touchscreen_data->slots[j].delta = EVDEV_TOUCH_SLOTDELTA_NONE;
+ break;
+ case EVDEV_TOUCH_SLOTDELTA_UP:
+ SDL_SendTouch(item->fd, item->touchscreen_data->slots[j].tracking_id, SDL_FALSE, norm_x, norm_y, 1.0f);
+ item->touchscreen_data->slots[j].tracking_id = -1;
+ item->touchscreen_data->slots[j].delta = EVDEV_TOUCH_SLOTDELTA_NONE;
+ break;
+ case EVDEV_TOUCH_SLOTDELTA_MOVE:
+ SDL_SendTouchMotion(item->fd, item->touchscreen_data->slots[j].tracking_id, norm_x, norm_y, 1.0f);
+ item->touchscreen_data->slots[j].delta = EVDEV_TOUCH_SLOTDELTA_NONE;
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (item->out_of_sync)
+ item->out_of_sync = 0;
+ break;
+ case SYN_DROPPED:
+ if (item->is_touchscreen)
+ item->out_of_sync = 1;
+ SDL_EVDEV_sync_device(item);
+ break;
+ default:
+ break;
+ }
+ break;
+ }
+ }
+ }
+ }
+}
+
+static SDL_Scancode
+SDL_EVDEV_translate_keycode(int keycode)
+{
+ SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
+
+ if (keycode < SDL_arraysize(linux_scancode_table))
+ scancode = linux_scancode_table[keycode];
+
+ if (scancode == SDL_SCANCODE_UNKNOWN) {
+ SDL_Log("The key you just pressed is not recognized by SDL. To help "
+ "get this fixed, please report this to the SDL forums/mailing list "
+ "<https://discourse.libsdl.org/> EVDEV KeyCode %d", keycode);
+ }
+
+ return scancode;
+}
+
+#ifdef SDL_USE_LIBUDEV
+static int
+SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item)
+{
+ int ret, i;
+ char name[64];
+ struct input_absinfo abs_info;
+
+ if (!item->is_touchscreen)
+ return 0;
+
+ item->touchscreen_data = SDL_calloc(1, sizeof(*item->touchscreen_data));
+ if (item->touchscreen_data == NULL)
+ return SDL_OutOfMemory();
+
+ ret = ioctl(item->fd, EVIOCGNAME(sizeof(name)), name);
+ if (ret < 0) {
+ SDL_free(item->touchscreen_data);
+ return SDL_SetError("Failed to get evdev touchscreen name");
+ }
+
+ item->touchscreen_data->name = SDL_strdup(name);
+ if (item->touchscreen_data->name == NULL) {
+ SDL_free(item->touchscreen_data);
+ return SDL_OutOfMemory();
+ }
+
+ ret = ioctl(item->fd, EVIOCGABS(ABS_MT_POSITION_X), &abs_info);
+ if (ret < 0) {
+ SDL_free(item->touchscreen_data->name);
+ SDL_free(item->touchscreen_data);
+ return SDL_SetError("Failed to get evdev touchscreen limits");
+ }
+ item->touchscreen_data->min_x = abs_info.minimum;
+ item->touchscreen_data->max_x = abs_info.maximum;
+ item->touchscreen_data->range_x = abs_info.maximum - abs_info.minimum;
+
+ ret = ioctl(item->fd, EVIOCGABS(ABS_MT_POSITION_Y), &abs_info);
+ if (ret < 0) {
+ SDL_free(item->touchscreen_data->name);
+ SDL_free(item->touchscreen_data);
+ return SDL_SetError("Failed to get evdev touchscreen limits");
+ }
+ item->touchscreen_data->min_y = abs_info.minimum;
+ item->touchscreen_data->max_y = abs_info.maximum;
+ item->touchscreen_data->range_y = abs_info.maximum - abs_info.minimum;
+
+ ret = ioctl(item->fd, EVIOCGABS(ABS_MT_SLOT), &abs_info);
+ if (ret < 0) {
+ SDL_free(item->touchscreen_data->name);
+ SDL_free(item->touchscreen_data);
+ return SDL_SetError("Failed to get evdev touchscreen limits");
+ }
+ item->touchscreen_data->max_slots = abs_info.maximum + 1;
+
+ item->touchscreen_data->slots = SDL_calloc(
+ item->touchscreen_data->max_slots,
+ sizeof(*item->touchscreen_data->slots));
+ if (item->touchscreen_data->slots == NULL) {
+ SDL_free(item->touchscreen_data->name);
+ SDL_free(item->touchscreen_data);
+ return SDL_OutOfMemory();
+ }
+
+ for(i = 0; i < item->touchscreen_data->max_slots; i++) {
+ item->touchscreen_data->slots[i].tracking_id = -1;
+ }
+
+ ret = SDL_AddTouch(item->fd, /* I guess our fd is unique enough */
+ item->touchscreen_data->name);
+ if (ret < 0) {
+ SDL_free(item->touchscreen_data->slots);
+ SDL_free(item->touchscreen_data->name);
+ SDL_free(item->touchscreen_data);
+ return ret;
+ }
+
+ return 0;
+}
+#endif /* SDL_USE_LIBUDEV */
+
+static void
+SDL_EVDEV_destroy_touchscreen(SDL_evdevlist_item* item) {
+ if (!item->is_touchscreen)
+ return;
+
+ SDL_DelTouch(item->fd);
+ SDL_free(item->touchscreen_data->slots);
+ SDL_free(item->touchscreen_data->name);
+ SDL_free(item->touchscreen_data);
+}
+
+static void
+SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
+{
+#ifdef EVIOCGMTSLOTS
+ int i, ret;
+ struct input_absinfo abs_info;
+ /*
+ * struct input_mt_request_layout {
+ * __u32 code;
+ * __s32 values[num_slots];
+ * };
+ *
+ * this is the structure we're trying to emulate
+ */
+ __u32* mt_req_code;
+ __s32* mt_req_values;
+ size_t mt_req_size;
+
+ /* TODO: sync devices other than touchscreen */
+ if (!item->is_touchscreen)
+ return;
+
+ mt_req_size = sizeof(*mt_req_code) +
+ sizeof(*mt_req_values) * item->touchscreen_data->max_slots;
+
+ mt_req_code = SDL_calloc(1, mt_req_size);
+ if (mt_req_code == NULL) {
+ return;
+ }
+
+ mt_req_values = (__s32*)mt_req_code + 1;
+
+ *mt_req_code = ABS_MT_TRACKING_ID;
+ ret = ioctl(item->fd, EVIOCGMTSLOTS(mt_req_size), mt_req_code);
+ if (ret < 0) {
+ SDL_free(mt_req_code);
+ return;
+ }
+ for(i = 0; i < item->touchscreen_data->max_slots; i++) {
+ /*
+ * This doesn't account for the very edge case of the user removing their
+ * finger and replacing it on the screen during the time we're out of sync,
+ * which'll mean that we're not going from down -> up or up -> down, we're
+ * going from down -> down but with a different tracking id, meaning we'd
+ * have to tell SDL of the two events, but since we wait till SYN_REPORT in
+ * SDL_EVDEV_Poll to tell SDL, the current structure of this code doesn't
+ * allow it. Lets just pray to God it doesn't happen.
+ */
+ if (item->touchscreen_data->slots[i].tracking_id < 0 &&
+ mt_req_values[i] >= 0) {
+ item->touchscreen_data->slots[i].tracking_id = mt_req_values[i];
+ item->touchscreen_data->slots[i].delta = EVDEV_TOUCH_SLOTDELTA_DOWN;
+ } else if (item->touchscreen_data->slots[i].tracking_id >= 0 &&
+ mt_req_values[i] < 0) {
+ item->touchscreen_data->slots[i].tracking_id = -1;
+ item->touchscreen_data->slots[i].delta = EVDEV_TOUCH_SLOTDELTA_UP;
+ }
+ }
+
+ *mt_req_code = ABS_MT_POSITION_X;
+ ret = ioctl(item->fd, EVIOCGMTSLOTS(mt_req_size), mt_req_code);
+ if (ret < 0) {
+ SDL_free(mt_req_code);
+ return;
+ }
+ for(i = 0; i < item->touchscreen_data->max_slots; i++) {
+ if (item->touchscreen_data->slots[i].tracking_id >= 0 &&
+ item->touchscreen_data->slots[i].x != mt_req_values[i]) {
+ item->touchscreen_data->slots[i].x = mt_req_values[i];
+ if (item->touchscreen_data->slots[i].delta ==
+ EVDEV_TOUCH_SLOTDELTA_NONE) {
+ item->touchscreen_data->slots[i].delta =
+ EVDEV_TOUCH_SLOTDELTA_MOVE;
+ }
+ }
+ }
+
+ *mt_req_code = ABS_MT_POSITION_Y;
+ ret = ioctl(item->fd, EVIOCGMTSLOTS(mt_req_size), mt_req_code);
+ if (ret < 0) {
+ SDL_free(mt_req_code);
+ return;
+ }
+ for(i = 0; i < item->touchscreen_data->max_slots; i++) {
+ if (item->touchscreen_data->slots[i].tracking_id >= 0 &&
+ item->touchscreen_data->slots[i].y != mt_req_values[i]) {
+ item->touchscreen_data->slots[i].y = mt_req_values[i];
+ if (item->touchscreen_data->slots[i].delta ==
+ EVDEV_TOUCH_SLOTDELTA_NONE) {
+ item->touchscreen_data->slots[i].delta =
+ EVDEV_TOUCH_SLOTDELTA_MOVE;
+ }
+ }
+ }
+
+ ret = ioctl(item->fd, EVIOCGABS(ABS_MT_SLOT), &abs_info);
+ if (ret < 0) {
+ SDL_free(mt_req_code);
+ return;
+ }
+ item->touchscreen_data->current_slot = abs_info.value;
+
+ SDL_free(mt_req_code);
+
+#endif /* EVIOCGMTSLOTS */
+}
+
+#if SDL_USE_LIBUDEV
+static int
+SDL_EVDEV_device_added(const char *dev_path, int udev_class)
+{
+ int ret;
+ SDL_evdevlist_item *item;
+
+ /* Check to make sure it's not already in list. */
+ for (item = _this->first; item != NULL; item = item->next) {
+ if (SDL_strcmp(dev_path, item->path) == 0) {
+ return -1; /* already have this one */
+ }
+ }
+
+ item = (SDL_evdevlist_item *) SDL_calloc(1, sizeof (SDL_evdevlist_item));
+ if (item == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ item->fd = open(dev_path, O_RDONLY | O_NONBLOCK);
+ if (item->fd < 0) {
+ SDL_free(item);
+ return SDL_SetError("Unable to open %s", dev_path);
+ }
+
+ item->path = SDL_strdup(dev_path);
+ if (item->path == NULL) {
+ close(item->fd);
+ SDL_free(item);
+ return SDL_OutOfMemory();
+ }
+
+ if (udev_class & SDL_UDEV_DEVICE_TOUCHSCREEN) {
+ item->is_touchscreen = 1;
+
+ if ((ret = SDL_EVDEV_init_touchscreen(item)) < 0) {
+ close(item->fd);
+ SDL_free(item);
+ return ret;
+ }
+ }
+
+ if (_this->last == NULL) {
+ _this->first = _this->last = item;
+ } else {
+ _this->last->next = item;
+ _this->last = item;
+ }
+
+ SDL_EVDEV_sync_device(item);
+
+ return _this->num_devices++;
+}
+#endif /* SDL_USE_LIBUDEV */
+
+static int
+SDL_EVDEV_device_removed(const char *dev_path)
+{
+ SDL_evdevlist_item *item;
+ SDL_evdevlist_item *prev = NULL;
+
+ for (item = _this->first; item != NULL; item = item->next) {
+ /* found it, remove it. */
+ if (SDL_strcmp(dev_path, item->path) == 0) {
+ if (prev != NULL) {
+ prev->next = item->next;
+ } else {
+ SDL_assert(_this->first == item);
+ _this->first = item->next;
+ }
+ if (item == _this->last) {
+ _this->last = prev;
+ }
+ if (item->is_touchscreen) {
+ SDL_EVDEV_destroy_touchscreen(item);
+ }
+ close(item->fd);
+ SDL_free(item->path);
+ SDL_free(item);
+ _this->num_devices--;
+ return 0;
+ }
+ prev = item;
+ }
+
+ return -1;
+}
+
+
+#endif /* SDL_INPUT_LINUXEV */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/linux/SDL_evdev.h b/src/3rdparty/SDL2/src/core/linux/SDL_evdev.h
new file mode 100644
index 0000000..8d6d683
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/linux/SDL_evdev.h
@@ -0,0 +1,39 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_evdev_h_
+#define SDL_evdev_h_
+
+#ifdef SDL_INPUT_LINUXEV
+
+#include "SDL_events.h"
+
+extern int SDL_EVDEV_Init(void);
+extern void SDL_EVDEV_Quit(void);
+extern void SDL_EVDEV_Poll(void);
+
+#endif /* SDL_INPUT_LINUXEV */
+
+#endif /* SDL_evdev_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/linux/SDL_evdev_kbd.c b/src/3rdparty/SDL2/src/core/linux/SDL_evdev_kbd.c
new file mode 100644
index 0000000..250e644
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/linux/SDL_evdev_kbd.c
@@ -0,0 +1,677 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "SDL_evdev_kbd.h"
+
+#ifdef SDL_INPUT_LINUXKD
+
+/* This logic is adapted from drivers/tty/vt/keyboard.c in the Linux kernel source */
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/kd.h>
+#include <linux/keyboard.h>
+#include <linux/vt.h>
+#include <linux/tiocl.h> /* for TIOCL_GETSHIFTSTATE */
+
+#include "../../events/SDL_events_c.h"
+#include "SDL_evdev_kbd_default_accents.h"
+#include "SDL_evdev_kbd_default_keymap.h"
+
+/* These are not defined in older Linux kernel headers */
+#ifndef K_UNICODE
+#define K_UNICODE 0x03
+#endif
+#ifndef K_OFF
+#define K_OFF 0x04
+#endif
+
+/*
+ * Handler Tables.
+ */
+
+#define K_HANDLERS\
+ k_self, k_fn, k_spec, k_pad,\
+ k_dead, k_cons, k_cur, k_shift,\
+ k_meta, k_ascii, k_lock, k_lowercase,\
+ k_slock, k_dead2, k_brl, k_ignore
+
+typedef void (k_handler_fn)(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag);
+static k_handler_fn K_HANDLERS;
+static k_handler_fn *k_handler[16] = { K_HANDLERS };
+
+typedef void (fn_handler_fn)(SDL_EVDEV_keyboard_state *kbd);
+static void fn_enter(SDL_EVDEV_keyboard_state *kbd);
+static void fn_caps_toggle(SDL_EVDEV_keyboard_state *kbd);
+static void fn_caps_on(SDL_EVDEV_keyboard_state *kbd);
+static void fn_num(SDL_EVDEV_keyboard_state *kbd);
+static void fn_compose(SDL_EVDEV_keyboard_state *kbd);
+
+static fn_handler_fn *fn_handler[] =
+{
+ NULL, fn_enter, NULL, NULL,
+ NULL, NULL, NULL, fn_caps_toggle,
+ fn_num, NULL, NULL, NULL,
+ NULL, fn_caps_on, fn_compose, NULL,
+ NULL, NULL, NULL, fn_num
+};
+
+
+/*
+ * Keyboard State
+ */
+
+struct SDL_EVDEV_keyboard_state
+{
+ int console_fd;
+ int old_kbd_mode;
+ unsigned short **key_maps;
+ unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */
+ SDL_bool dead_key_next;
+ int npadch; /* -1 or number assembled on pad */
+ struct kbdiacrs *accents;
+ unsigned int diacr;
+ SDL_bool rep; /* flag telling character repeat */
+ unsigned char lockstate;
+ unsigned char slockstate;
+ unsigned char ledflagstate;
+ char shift_state;
+ char text[128];
+ unsigned int text_len;
+};
+
+#ifdef DUMP_ACCENTS
+static void SDL_EVDEV_dump_accents(SDL_EVDEV_keyboard_state *kbd)
+{
+ unsigned int i;
+
+ printf("static struct kbdiacrs default_accents = {\n");
+ printf(" %d,\n", kbd->accents->kb_cnt);
+ printf(" {\n");
+ for (i = 0; i < kbd->accents->kb_cnt; ++i) {
+ struct kbdiacr *diacr = &kbd->accents->kbdiacr[i];
+ printf(" { 0x%.2x, 0x%.2x, 0x%.2x },\n",
+ diacr->diacr, diacr->base, diacr->result);
+ }
+ while (i < 256) {
+ printf(" { 0x00, 0x00, 0x00 },\n");
+ ++i;
+ }
+ printf(" }\n");
+ printf("};\n");
+}
+#endif /* DUMP_ACCENTS */
+
+#ifdef DUMP_KEYMAP
+static void SDL_EVDEV_dump_keymap(SDL_EVDEV_keyboard_state *kbd)
+{
+ int i, j;
+
+ for (i = 0; i < MAX_NR_KEYMAPS; ++i) {
+ if (kbd->key_maps[i]) {
+ printf("static unsigned short default_key_map_%d[NR_KEYS] = {", i);
+ for (j = 0; j < NR_KEYS; ++j) {
+ if ((j%8) == 0) {
+ printf("\n ");
+ }
+ printf("0x%.4x, ", kbd->key_maps[i][j]);
+ }
+ printf("\n};\n");
+ }
+ }
+ printf("\n");
+ printf("static unsigned short *default_key_maps[MAX_NR_KEYMAPS] = {\n");
+ for (i = 0; i < MAX_NR_KEYMAPS; ++i) {
+ if (kbd->key_maps[i]) {
+ printf(" default_key_map_%d,\n", i);
+ } else {
+ printf(" NULL,\n");
+ }
+ }
+ printf("};\n");
+}
+#endif /* DUMP_KEYMAP */
+
+static int SDL_EVDEV_kbd_load_keymaps(SDL_EVDEV_keyboard_state *kbd)
+{
+ int i, j;
+
+ kbd->key_maps = (unsigned short **)SDL_calloc(MAX_NR_KEYMAPS, sizeof(unsigned short *));
+ if (!kbd->key_maps) {
+ return -1;
+ }
+
+ for (i = 0; i < MAX_NR_KEYMAPS; ++i) {
+ struct kbentry kbe;
+
+ kbe.kb_table = i;
+ kbe.kb_index = 0;
+ if (ioctl(kbd->console_fd, KDGKBENT, &kbe) < 0) {
+ return -1;
+ }
+
+ if (kbe.kb_value == K_NOSUCHMAP) {
+ continue;
+ }
+
+ kbd->key_maps[i] = (unsigned short *)SDL_malloc(NR_KEYS * sizeof(unsigned short));
+ if (!kbd->key_maps[i]) {
+ return -1;
+ }
+
+ for (j = 0; j < NR_KEYS; ++j) {
+ kbe.kb_table = i;
+ kbe.kb_index = j;
+ if (ioctl(kbd->console_fd, KDGKBENT, &kbe) < 0) {
+ return -1;
+ }
+ kbd->key_maps[i][j] = (kbe.kb_value ^ 0xf000);
+ }
+ }
+ return 0;
+}
+
+SDL_EVDEV_keyboard_state *
+SDL_EVDEV_kbd_init(void)
+{
+ SDL_EVDEV_keyboard_state *kbd;
+ int i;
+ char flag_state;
+ char shift_state[2] = {TIOCL_GETSHIFTSTATE, 0};
+
+ kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(*kbd));
+ if (!kbd) {
+ return NULL;
+ }
+
+ kbd->npadch = -1;
+
+ /* This might fail if we're not connected to a tty (e.g. on the Steam Link) */
+ kbd->console_fd = open("/dev/tty", O_RDONLY);
+
+ if (ioctl(kbd->console_fd, TIOCLINUX, shift_state) == 0) {
+ kbd->shift_state = *shift_state;
+ }
+
+ if (ioctl(kbd->console_fd, KDGKBLED, &flag_state) == 0) {
+ kbd->ledflagstate = flag_state;
+ }
+
+ kbd->accents = &default_accents;
+ if (ioctl(kbd->console_fd, KDGKBDIACR, kbd->accents) < 0) {
+ /* No worries, we'll use the default accent table */
+ }
+
+ kbd->key_maps = default_key_maps;
+ if (ioctl(kbd->console_fd, KDGKBMODE, &kbd->old_kbd_mode) == 0) {
+ /* Set the keyboard in UNICODE mode and load the keymaps */
+ ioctl(kbd->console_fd, KDSKBMODE, K_UNICODE);
+
+ if (SDL_EVDEV_kbd_load_keymaps(kbd) < 0) {
+ for (i = 0; i < MAX_NR_KEYMAPS; ++i) {
+ if (kbd->key_maps[i]) {
+ SDL_free(kbd->key_maps[i]);
+ }
+ }
+ SDL_free(kbd->key_maps);
+
+ kbd->key_maps = default_key_maps;
+ }
+
+ /* Mute the keyboard so keystrokes only generate evdev events
+ * and do not leak through to the console
+ */
+ ioctl(kbd->console_fd, KDSKBMODE, K_OFF);
+ }
+
+#ifdef DUMP_ACCENTS
+ SDL_EVDEV_dump_accents(kbd);
+#endif
+#ifdef DUMP_KEYMAP
+ SDL_EVDEV_dump_keymap(kbd);
+#endif
+ return kbd;
+}
+
+void
+SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
+{
+ if (!kbd) {
+ return;
+ }
+
+ if (kbd->console_fd >= 0) {
+ /* Restore the original keyboard mode */
+ ioctl(kbd->console_fd, KDSKBMODE, kbd->old_kbd_mode);
+
+ close(kbd->console_fd);
+ kbd->console_fd = -1;
+ }
+
+ if (kbd->key_maps && kbd->key_maps != default_key_maps) {
+ int i;
+ for (i = 0; i < MAX_NR_KEYMAPS; ++i) {
+ if (kbd->key_maps[i]) {
+ SDL_free(kbd->key_maps[i]);
+ }
+ }
+ SDL_free(kbd->key_maps);
+ }
+
+ SDL_free(kbd);
+}
+
+/*
+ * Helper Functions.
+ */
+static void put_queue(SDL_EVDEV_keyboard_state *kbd, uint c)
+{
+ /* c is already part of a UTF-8 sequence and safe to add as a character */
+ if (kbd->text_len < (sizeof(kbd->text)-1)) {
+ kbd->text[kbd->text_len++] = (char)c;
+ }
+}
+
+static void put_utf8(SDL_EVDEV_keyboard_state *kbd, uint c)
+{
+ if (c < 0x80)
+ /* 0******* */
+ put_queue(kbd, c);
+ else if (c < 0x800) {
+ /* 110***** 10****** */
+ put_queue(kbd, 0xc0 | (c >> 6));
+ put_queue(kbd, 0x80 | (c & 0x3f));
+ } else if (c < 0x10000) {
+ if (c >= 0xD800 && c < 0xE000)
+ return;
+ if (c == 0xFFFF)
+ return;
+ /* 1110**** 10****** 10****** */
+ put_queue(kbd, 0xe0 | (c >> 12));
+ put_queue(kbd, 0x80 | ((c >> 6) & 0x3f));
+ put_queue(kbd, 0x80 | (c & 0x3f));
+ } else if (c < 0x110000) {
+ /* 11110*** 10****** 10****** 10****** */
+ put_queue(kbd, 0xf0 | (c >> 18));
+ put_queue(kbd, 0x80 | ((c >> 12) & 0x3f));
+ put_queue(kbd, 0x80 | ((c >> 6) & 0x3f));
+ put_queue(kbd, 0x80 | (c & 0x3f));
+ }
+}
+
+/*
+ * We have a combining character DIACR here, followed by the character CH.
+ * If the combination occurs in the table, return the corresponding value.
+ * Otherwise, if CH is a space or equals DIACR, return DIACR.
+ * Otherwise, conclude that DIACR was not combining after all,
+ * queue it and return CH.
+ */
+static unsigned int handle_diacr(SDL_EVDEV_keyboard_state *kbd, unsigned int ch)
+{
+ unsigned int d = kbd->diacr;
+ unsigned int i;
+
+ kbd->diacr = 0;
+
+ for (i = 0; i < kbd->accents->kb_cnt; i++) {
+ if (kbd->accents->kbdiacr[i].diacr == d &&
+ kbd->accents->kbdiacr[i].base == ch) {
+ return kbd->accents->kbdiacr[i].result;
+ }
+ }
+
+ if (ch == ' ' || ch == d)
+ return d;
+
+ put_utf8(kbd, d);
+
+ return ch;
+}
+
+static int vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag)
+{
+ return ((kbd->ledflagstate >> flag) & 1);
+}
+
+static void set_vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag)
+{
+ kbd->ledflagstate |= 1 << flag;
+}
+
+static void clr_vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag)
+{
+ kbd->ledflagstate &= ~(1 << flag);
+}
+
+static void chg_vc_kbd_lock(SDL_EVDEV_keyboard_state *kbd, int flag)
+{
+ kbd->lockstate ^= 1 << flag;
+}
+
+static void chg_vc_kbd_slock(SDL_EVDEV_keyboard_state *kbd, int flag)
+{
+ kbd->slockstate ^= 1 << flag;
+}
+
+static void chg_vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag)
+{
+ kbd->ledflagstate ^= 1 << flag;
+}
+
+/*
+ * Special function handlers
+ */
+
+static void fn_enter(SDL_EVDEV_keyboard_state *kbd)
+{
+ if (kbd->diacr) {
+ put_utf8(kbd, kbd->diacr);
+ kbd->diacr = 0;
+ }
+}
+
+static void fn_caps_toggle(SDL_EVDEV_keyboard_state *kbd)
+{
+ if (kbd->rep)
+ return;
+
+ chg_vc_kbd_led(kbd, K_CAPSLOCK);
+}
+
+static void fn_caps_on(SDL_EVDEV_keyboard_state *kbd)
+{
+ if (kbd->rep)
+ return;
+
+ set_vc_kbd_led(kbd, K_CAPSLOCK);
+}
+
+static void fn_num(SDL_EVDEV_keyboard_state *kbd)
+{
+ if (!kbd->rep)
+ chg_vc_kbd_led(kbd, K_NUMLOCK);
+}
+
+static void fn_compose(SDL_EVDEV_keyboard_state *kbd)
+{
+ kbd->dead_key_next = SDL_TRUE;
+}
+
+/*
+ * Special key handlers
+ */
+
+static void k_ignore(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
+{
+}
+
+static void k_spec(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
+{
+ if (up_flag)
+ return;
+ if (value >= SDL_arraysize(fn_handler))
+ return;
+ if (fn_handler[value])
+ fn_handler[value](kbd);
+}
+
+static void k_lowercase(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
+{
+}
+
+static void k_self(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
+{
+ if (up_flag)
+ return; /* no action, if this is a key release */
+
+ if (kbd->diacr)
+ value = handle_diacr(kbd, value);
+
+ if (kbd->dead_key_next) {
+ kbd->dead_key_next = SDL_FALSE;
+ kbd->diacr = value;
+ return;
+ }
+ put_utf8(kbd, value);
+}
+
+static void k_deadunicode(SDL_EVDEV_keyboard_state *kbd, unsigned int value, char up_flag)
+{
+ if (up_flag)
+ return;
+
+ kbd->diacr = (kbd->diacr ? handle_diacr(kbd, value) : value);
+}
+
+static void k_dead(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
+{
+ const unsigned char ret_diacr[NR_DEAD] = {'`', '\'', '^', '~', '"', ',' };
+
+ k_deadunicode(kbd, ret_diacr[value], up_flag);
+}
+
+static void k_dead2(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
+{
+ k_deadunicode(kbd, value, up_flag);
+}
+
+static void k_cons(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
+{
+}
+
+static void k_fn(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
+{
+}
+
+static void k_cur(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
+{
+}
+
+static void k_pad(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
+{
+ static const char pad_chars[] = "0123456789+-*/\015,.?()#";
+
+ if (up_flag)
+ return; /* no action, if this is a key release */
+
+ if (!vc_kbd_led(kbd, K_NUMLOCK)) {
+ /* unprintable action */
+ return;
+ }
+
+ put_queue(kbd, pad_chars[value]);
+}
+
+static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
+{
+ int old_state = kbd->shift_state;
+
+ if (kbd->rep)
+ return;
+ /*
+ * Mimic typewriter:
+ * a CapsShift key acts like Shift but undoes CapsLock
+ */
+ if (value == KVAL(K_CAPSSHIFT)) {
+ value = KVAL(K_SHIFT);
+ if (!up_flag)
+ clr_vc_kbd_led(kbd, K_CAPSLOCK);
+ }
+
+ if (up_flag) {
+ /*
+ * handle the case that two shift or control
+ * keys are depressed simultaneously
+ */
+ if (kbd->shift_down[value])
+ kbd->shift_down[value]--;
+ } else
+ kbd->shift_down[value]++;
+
+ if (kbd->shift_down[value])
+ kbd->shift_state |= (1 << value);
+ else
+ kbd->shift_state &= ~(1 << value);
+
+ /* kludge */
+ if (up_flag && kbd->shift_state != old_state && kbd->npadch != -1) {
+ put_utf8(kbd, kbd->npadch);
+ kbd->npadch = -1;
+ }
+}
+
+static void k_meta(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
+{
+}
+
+static void k_ascii(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
+{
+ int base;
+
+ if (up_flag)
+ return;
+
+ if (value < 10) {
+ /* decimal input of code, while Alt depressed */
+ base = 10;
+ } else {
+ /* hexadecimal input of code, while AltGr depressed */
+ value -= 10;
+ base = 16;
+ }
+
+ if (kbd->npadch == -1)
+ kbd->npadch = value;
+ else
+ kbd->npadch = kbd->npadch * base + value;
+}
+
+static void k_lock(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
+{
+ if (up_flag || kbd->rep)
+ return;
+
+ chg_vc_kbd_lock(kbd, value);
+}
+
+static void k_slock(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
+{
+ k_shift(kbd, value, up_flag);
+ if (up_flag || kbd->rep)
+ return;
+
+ chg_vc_kbd_slock(kbd, value);
+ /* try to make Alt, oops, AltGr and such work */
+ if (!kbd->key_maps[kbd->lockstate ^ kbd->slockstate]) {
+ kbd->slockstate = 0;
+ chg_vc_kbd_slock(kbd, value);
+ }
+}
+
+static void k_brl(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag)
+{
+}
+
+void
+SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int down)
+{
+ unsigned char shift_final;
+ unsigned char type;
+ unsigned short *key_map;
+ unsigned short keysym;
+
+ if (!kbd) {
+ return;
+ }
+
+ kbd->rep = (down == 2);
+
+ shift_final = (kbd->shift_state | kbd->slockstate) ^ kbd->lockstate;
+ key_map = kbd->key_maps[shift_final];
+ if (!key_map) {
+ kbd->slockstate = 0;
+ return;
+ }
+
+ if (keycode < NR_KEYS) {
+ keysym = key_map[keycode];
+ } else {
+ return;
+ }
+
+ type = KTYP(keysym);
+
+ if (type < 0xf0) {
+ if (down) {
+ put_utf8(kbd, keysym);
+ }
+ } else {
+ type -= 0xf0;
+
+ /* if type is KT_LETTER then it can be affected by Caps Lock */
+ if (type == KT_LETTER) {
+ type = KT_LATIN;
+
+ if (vc_kbd_led(kbd, K_CAPSLOCK)) {
+ key_map = kbd->key_maps[shift_final ^ (1 << KG_SHIFT)];
+ if (key_map) {
+ keysym = key_map[keycode];
+ }
+ }
+ }
+
+ (*k_handler[type])(kbd, keysym & 0xff, !down);
+
+ if (type != KT_SLOCK) {
+ kbd->slockstate = 0;
+ }
+ }
+
+ if (kbd->text_len > 0) {
+ kbd->text[kbd->text_len] = '\0';
+ SDL_SendKeyboardText(kbd->text);
+ kbd->text_len = 0;
+ }
+}
+
+#else /* !SDL_INPUT_LINUXKD */
+
+SDL_EVDEV_keyboard_state *
+SDL_EVDEV_kbd_init(void)
+{
+ return NULL;
+}
+
+void
+SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode, int down)
+{
+}
+
+void
+SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *state)
+{
+}
+
+#endif /* SDL_INPUT_LINUXKD */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/linux/SDL_evdev_kbd.h b/src/3rdparty/SDL2/src/core/linux/SDL_evdev_kbd.h
new file mode 100644
index 0000000..831ba3a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/linux/SDL_evdev_kbd.h
@@ -0,0 +1,29 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+struct SDL_EVDEV_keyboard_state;
+typedef struct SDL_EVDEV_keyboard_state SDL_EVDEV_keyboard_state;
+
+extern SDL_EVDEV_keyboard_state *SDL_EVDEV_kbd_init(void);
+extern void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode, int down);
+extern void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *state);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/linux/SDL_evdev_kbd_default_accents.h b/src/3rdparty/SDL2/src/core/linux/SDL_evdev_kbd_default_accents.h
new file mode 100644
index 0000000..2fb5254
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/linux/SDL_evdev_kbd_default_accents.h
@@ -0,0 +1,284 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+static struct kbdiacrs default_accents = {
+ 68,
+ {
+ { 0x60, 0x41, 0xc0 },
+ { 0x60, 0x61, 0xe0 },
+ { 0x27, 0x41, 0xc1 },
+ { 0x27, 0x61, 0xe1 },
+ { 0x5e, 0x41, 0xc2 },
+ { 0x5e, 0x61, 0xe2 },
+ { 0x7e, 0x41, 0xc3 },
+ { 0x7e, 0x61, 0xe3 },
+ { 0x22, 0x41, 0xc4 },
+ { 0x22, 0x61, 0xe4 },
+ { 0x4f, 0x41, 0xc5 },
+ { 0x6f, 0x61, 0xe5 },
+ { 0x30, 0x41, 0xc5 },
+ { 0x30, 0x61, 0xe5 },
+ { 0x41, 0x41, 0xc5 },
+ { 0x61, 0x61, 0xe5 },
+ { 0x41, 0x45, 0xc6 },
+ { 0x61, 0x65, 0xe6 },
+ { 0x2c, 0x43, 0xc7 },
+ { 0x2c, 0x63, 0xe7 },
+ { 0x60, 0x45, 0xc8 },
+ { 0x60, 0x65, 0xe8 },
+ { 0x27, 0x45, 0xc9 },
+ { 0x27, 0x65, 0xe9 },
+ { 0x5e, 0x45, 0xca },
+ { 0x5e, 0x65, 0xea },
+ { 0x22, 0x45, 0xcb },
+ { 0x22, 0x65, 0xeb },
+ { 0x60, 0x49, 0xcc },
+ { 0x60, 0x69, 0xec },
+ { 0x27, 0x49, 0xcd },
+ { 0x27, 0x69, 0xed },
+ { 0x5e, 0x49, 0xce },
+ { 0x5e, 0x69, 0xee },
+ { 0x22, 0x49, 0xcf },
+ { 0x22, 0x69, 0xef },
+ { 0x2d, 0x44, 0xd0 },
+ { 0x2d, 0x64, 0xf0 },
+ { 0x7e, 0x4e, 0xd1 },
+ { 0x7e, 0x6e, 0xf1 },
+ { 0x60, 0x4f, 0xd2 },
+ { 0x60, 0x6f, 0xf2 },
+ { 0x27, 0x4f, 0xd3 },
+ { 0x27, 0x6f, 0xf3 },
+ { 0x5e, 0x4f, 0xd4 },
+ { 0x5e, 0x6f, 0xf4 },
+ { 0x7e, 0x4f, 0xd5 },
+ { 0x7e, 0x6f, 0xf5 },
+ { 0x22, 0x4f, 0xd6 },
+ { 0x22, 0x6f, 0xf6 },
+ { 0x2f, 0x4f, 0xd8 },
+ { 0x2f, 0x6f, 0xf8 },
+ { 0x60, 0x55, 0xd9 },
+ { 0x60, 0x75, 0xf9 },
+ { 0x27, 0x55, 0xda },
+ { 0x27, 0x75, 0xfa },
+ { 0x5e, 0x55, 0xdb },
+ { 0x5e, 0x75, 0xfb },
+ { 0x22, 0x55, 0xdc },
+ { 0x22, 0x75, 0xfc },
+ { 0x27, 0x59, 0xdd },
+ { 0x27, 0x79, 0xfd },
+ { 0x54, 0x48, 0xde },
+ { 0x74, 0x68, 0xfe },
+ { 0x73, 0x73, 0xdf },
+ { 0x22, 0x79, 0xff },
+ { 0x73, 0x7a, 0xdf },
+ { 0x69, 0x6a, 0xff },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ { 0x00, 0x00, 0x00 },
+ }
+};
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/linux/SDL_evdev_kbd_default_keymap.h b/src/3rdparty/SDL2/src/core/linux/SDL_evdev_kbd_default_keymap.h
new file mode 100644
index 0000000..0ed3050
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/linux/SDL_evdev_kbd_default_keymap.h
@@ -0,0 +1,4763 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+static unsigned short default_key_map_0[NR_KEYS] = {
+ 0xf200, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
+ 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
+ 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
+ 0xfb6f, 0xfb70, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb61, 0xfb73,
+ 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03b,
+ 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
+ 0xfb62, 0xfb6e, 0xfb6d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+};
+static unsigned short default_key_map_1[NR_KEYS] = {
+ 0xf200, 0xf01b, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
+ 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07f, 0xf009,
+ 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
+ 0xfb4f, 0xfb50, 0xf07b, 0xf07d, 0xf201, 0xf702, 0xfb41, 0xfb53,
+ 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03a,
+ 0xf022, 0xf07e, 0xf700, 0xf07c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
+ 0xfb42, 0xfb4e, 0xfb4d, 0xf03c, 0xf03e, 0xf03f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf10c, 0xf10d, 0xf10e, 0xf10f, 0xf110,
+ 0xf111, 0xf112, 0xf113, 0xf11e, 0xf11f, 0xf208, 0xf203, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03e, 0xf120,
+ 0xf121, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf20b, 0xf601, 0xf602, 0xf117, 0xf600, 0xf20a, 0xf115, 0xf116,
+ 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+};
+static unsigned short default_key_map_2[NR_KEYS] = {
+ 0xf200, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
+ 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
+ 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
+ 0xfb6f, 0xfb70, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb61, 0xfb73,
+ 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03b,
+ 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
+ 0xfb62, 0xfb6e, 0xfb6d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf916,
+ 0xf703, 0xf020, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf914, 0xf202, 0xf911,
+ 0xf912, 0xf913, 0xf917, 0xf90e, 0xf90f, 0xf910, 0xf918, 0xf90b,
+ 0xf90c, 0xf90d, 0xf90a, 0xf310, 0xf206, 0xf200, 0xf07c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf919, 0xf702, 0xf915, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+};
+static unsigned short default_key_map_3[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
+ 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07f, 0xf009,
+ 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
+ 0xfb4f, 0xfb50, 0xf07b, 0xf07d, 0xf201, 0xf702, 0xfb41, 0xfb53,
+ 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03a,
+ 0xf022, 0xf07e, 0xf700, 0xf07c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
+ 0xfb42, 0xfb4e, 0xfb4d, 0xf03c, 0xf03e, 0xf03f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf518, 0xf519, 0xf51a, 0xf51b, 0xf51c,
+ 0xf51d, 0xf51e, 0xf51f, 0xf520, 0xf521, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0x00a6, 0xf522,
+ 0xf523, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+#ifdef INCLUDE_EXTENDED_KEYMAP
+static unsigned short default_key_map_4[NR_KEYS] = {
+ 0xf200, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf000, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf122, 0xf123, 0xf124, 0xf125, 0xf126,
+ 0xf127, 0xf128, 0xf129, 0xf12a, 0xf12b, 0xf208, 0xf204, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf12c,
+ 0xf12d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+};
+static unsigned short default_key_map_5[NR_KEYS] = {
+ 0xf200, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf01e, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf12e, 0xf12f, 0xf130, 0xf131, 0xf132,
+ 0xf133, 0xf134, 0xf135, 0xf136, 0xf137, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf138,
+ 0xf139, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+};
+static unsigned short default_key_map_6[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf000, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf01c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_7[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf01e, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf518, 0xf519, 0xf51a, 0xf51b, 0xf51c,
+ 0xf51d, 0xf51e, 0xf51f, 0xf520, 0xf521, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf522,
+ 0xf523, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_8[NR_KEYS] = {
+ 0xf200, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
+ 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf87f, 0xf809,
+ 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
+ 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d, 0xf702, 0xf861, 0xf873,
+ 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf83b,
+ 0xf827, 0xf860, 0xf700, 0xf85c, 0xf87a, 0xf878, 0xf863, 0xf876,
+ 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
+ 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf202, 0xf907,
+ 0xf908, 0xf909, 0xf30b, 0xf904, 0xf905, 0xf906, 0xf30a, 0xf901,
+ 0xf902, 0xf903, 0xf900, 0xf310, 0xf206, 0xf200, 0xf83c, 0xf50a,
+ 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf212,
+ 0xf118, 0xf210, 0xf211, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+};
+static unsigned short default_key_map_9[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf821, 0xf840, 0xf823, 0xf824, 0xf825, 0xf85e,
+ 0xf826, 0xf82a, 0xf828, 0xf829, 0xf85f, 0xf82b, 0xf87f, 0xf809,
+ 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
+ 0xf84f, 0xf850, 0xf87b, 0xf87d, 0xf80d, 0xf702, 0xf841, 0xf853,
+ 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf83a,
+ 0xf822, 0xf87e, 0xf700, 0xf87c, 0xf85a, 0xf858, 0xf843, 0xf856,
+ 0xf842, 0xf84e, 0xf84d, 0xf83c, 0xf83e, 0xf83f, 0xf700, 0xf916,
+ 0xf703, 0xf820, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf914, 0xf209, 0xf911,
+ 0xf912, 0xf913, 0xf917, 0xf90e, 0xf90f, 0xf910, 0xf918, 0xf90b,
+ 0xf90c, 0xf90d, 0xf90a, 0xf310, 0xf206, 0xf200, 0xf83e, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf919, 0xf702, 0xf915, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_10[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
+ 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf87f, 0xf809,
+ 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
+ 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d, 0xf702, 0xf861, 0xf873,
+ 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf83b,
+ 0xf827, 0xf860, 0xf700, 0xf85c, 0xf87a, 0xf878, 0xf863, 0xf876,
+ 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf87c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_11[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf821, 0xf840, 0xf823, 0xf824, 0xf825, 0xf85e,
+ 0xf826, 0xf82a, 0xf828, 0xf829, 0xf85f, 0xf82b, 0xf87f, 0xf809,
+ 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
+ 0xf84f, 0xf850, 0xf87b, 0xf87d, 0xf80d, 0xf702, 0xf841, 0xf853,
+ 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf83a,
+ 0xf822, 0xf87e, 0xf700, 0xf87c, 0xf85a, 0xf858, 0xf843, 0xf856,
+ 0xf842, 0xf84e, 0xf84d, 0xf83c, 0xf83e, 0xf83f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf87c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_12[NR_KEYS] = {
+ 0xf200, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf800, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
+ 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf81c, 0xf50a,
+ 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+};
+static unsigned short default_key_map_13[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf81e, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf81c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_14[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf800, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf81c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_15[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf81e, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf81c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_16[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
+ 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
+ 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
+ 0xfb6f, 0xfb70, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb61, 0xfb73,
+ 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03b,
+ 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
+ 0xfb62, 0xfb6e, 0xfb6d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_17[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
+ 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07f, 0xf009,
+ 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
+ 0xfb4f, 0xfb50, 0xf07b, 0xf07d, 0xf201, 0xf702, 0xfb41, 0xfb53,
+ 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03a,
+ 0xf022, 0xf07e, 0xf700, 0xf07c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
+ 0xfb42, 0xfb4e, 0xfb4d, 0xf03c, 0xf03e, 0xf03f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf10c, 0xf10d, 0xf10e, 0xf10f, 0xf110,
+ 0xf111, 0xf112, 0xf113, 0xf11e, 0xf11f, 0xf208, 0xf203, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03e, 0xf120,
+ 0xf121, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf20b, 0xf601, 0xf602, 0xf117, 0xf600, 0xf20a, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_18[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
+ 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
+ 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
+ 0xfb6f, 0xfb70, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb61, 0xfb73,
+ 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03b,
+ 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
+ 0xfb62, 0xfb6e, 0xfb6d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf916,
+ 0xf703, 0xf020, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf914, 0xf202, 0xf911,
+ 0xf912, 0xf913, 0xf917, 0xf90e, 0xf90f, 0xf910, 0xf918, 0xf90b,
+ 0xf90c, 0xf90d, 0xf90a, 0xf310, 0xf206, 0xf200, 0xf07c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf919, 0xf702, 0xf915, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_19[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
+ 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07f, 0xf009,
+ 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
+ 0xfb4f, 0xfb50, 0xf07b, 0xf07d, 0xf201, 0xf702, 0xfb41, 0xfb53,
+ 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03a,
+ 0xf022, 0xf07e, 0xf700, 0xf07c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
+ 0xfb42, 0xfb4e, 0xfb4d, 0xf03c, 0xf03e, 0xf03f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf518, 0xf519, 0xf51a, 0xf51b, 0xf51c,
+ 0xf51d, 0xf51e, 0xf51f, 0xf520, 0xf521, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0x00a6, 0xf522,
+ 0xf523, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_20[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf000, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf122, 0xf123, 0xf124, 0xf125, 0xf126,
+ 0xf127, 0xf128, 0xf129, 0xf12a, 0xf12b, 0xf208, 0xf204, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf12c,
+ 0xf12d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_21[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf01e, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf12e, 0xf12f, 0xf130, 0xf131, 0xf132,
+ 0xf133, 0xf134, 0xf135, 0xf136, 0xf137, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf138,
+ 0xf139, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_22[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf000, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf01c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_23[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf01e, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf518, 0xf519, 0xf51a, 0xf51b, 0xf51c,
+ 0xf51d, 0xf51e, 0xf51f, 0xf520, 0xf521, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf522,
+ 0xf523, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_24[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
+ 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf87f, 0xf809,
+ 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
+ 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d, 0xf702, 0xf861, 0xf873,
+ 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf83b,
+ 0xf827, 0xf860, 0xf700, 0xf85c, 0xf87a, 0xf878, 0xf863, 0xf876,
+ 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
+ 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf202, 0xf907,
+ 0xf908, 0xf909, 0xf30b, 0xf904, 0xf905, 0xf906, 0xf30a, 0xf901,
+ 0xf902, 0xf903, 0xf900, 0xf310, 0xf206, 0xf200, 0xf83c, 0xf50a,
+ 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf212,
+ 0xf118, 0xf210, 0xf211, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_25[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf821, 0xf840, 0xf823, 0xf824, 0xf825, 0xf85e,
+ 0xf826, 0xf82a, 0xf828, 0xf829, 0xf85f, 0xf82b, 0xf87f, 0xf809,
+ 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
+ 0xf84f, 0xf850, 0xf87b, 0xf87d, 0xf80d, 0xf702, 0xf841, 0xf853,
+ 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf83a,
+ 0xf822, 0xf87e, 0xf700, 0xf87c, 0xf85a, 0xf858, 0xf843, 0xf856,
+ 0xf842, 0xf84e, 0xf84d, 0xf83c, 0xf83e, 0xf83f, 0xf700, 0xf916,
+ 0xf703, 0xf820, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf914, 0xf209, 0xf911,
+ 0xf912, 0xf913, 0xf917, 0xf90e, 0xf90f, 0xf910, 0xf918, 0xf90b,
+ 0xf90c, 0xf90d, 0xf90a, 0xf310, 0xf206, 0xf200, 0xf83e, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf919, 0xf702, 0xf915, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_26[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
+ 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf87f, 0xf809,
+ 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
+ 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d, 0xf702, 0xf861, 0xf873,
+ 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf83b,
+ 0xf827, 0xf860, 0xf700, 0xf85c, 0xf87a, 0xf878, 0xf863, 0xf876,
+ 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf87c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_27[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf821, 0xf840, 0xf823, 0xf824, 0xf825, 0xf85e,
+ 0xf826, 0xf82a, 0xf828, 0xf829, 0xf85f, 0xf82b, 0xf87f, 0xf809,
+ 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
+ 0xf84f, 0xf850, 0xf87b, 0xf87d, 0xf80d, 0xf702, 0xf841, 0xf853,
+ 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf83a,
+ 0xf822, 0xf87e, 0xf700, 0xf87c, 0xf85a, 0xf858, 0xf843, 0xf856,
+ 0xf842, 0xf84e, 0xf84d, 0xf83c, 0xf83e, 0xf83f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf87c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_28[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf800, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
+ 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf81c, 0xf50a,
+ 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_29[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf81e, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf81c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_30[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf800, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf81c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_31[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf81e, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf81c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_32[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
+ 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
+ 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
+ 0xfb6f, 0xfb70, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb61, 0xfb73,
+ 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03b,
+ 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
+ 0xfb62, 0xfb6e, 0xfb6d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_33[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
+ 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07f, 0xf009,
+ 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
+ 0xfb4f, 0xfb50, 0xf07b, 0xf07d, 0xf201, 0xf702, 0xfb41, 0xfb53,
+ 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03a,
+ 0xf022, 0xf07e, 0xf700, 0xf07c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
+ 0xfb42, 0xfb4e, 0xfb4d, 0xf03c, 0xf03e, 0xf03f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf10c, 0xf10d, 0xf10e, 0xf10f, 0xf110,
+ 0xf111, 0xf112, 0xf113, 0xf11e, 0xf11f, 0xf208, 0xf203, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03e, 0xf120,
+ 0xf121, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf20b, 0xf601, 0xf602, 0xf117, 0xf600, 0xf20a, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_34[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
+ 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
+ 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
+ 0xfb6f, 0xfb70, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb61, 0xfb73,
+ 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03b,
+ 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
+ 0xfb62, 0xfb6e, 0xfb6d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf916,
+ 0xf703, 0xf020, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf914, 0xf202, 0xf911,
+ 0xf912, 0xf913, 0xf917, 0xf90e, 0xf90f, 0xf910, 0xf918, 0xf90b,
+ 0xf90c, 0xf90d, 0xf90a, 0xf310, 0xf206, 0xf200, 0xf07c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf919, 0xf702, 0xf915, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_35[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
+ 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07f, 0xf009,
+ 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
+ 0xfb4f, 0xfb50, 0xf07b, 0xf07d, 0xf201, 0xf702, 0xfb41, 0xfb53,
+ 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03a,
+ 0xf022, 0xf07e, 0xf700, 0xf07c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
+ 0xfb42, 0xfb4e, 0xfb4d, 0xf03c, 0xf03e, 0xf03f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf518, 0xf519, 0xf51a, 0xf51b, 0xf51c,
+ 0xf51d, 0xf51e, 0xf51f, 0xf520, 0xf521, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0x00a6, 0xf522,
+ 0xf523, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_36[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf000, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf122, 0xf123, 0xf124, 0xf125, 0xf126,
+ 0xf127, 0xf128, 0xf129, 0xf12a, 0xf12b, 0xf208, 0xf204, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf12c,
+ 0xf12d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_37[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf01e, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf12e, 0xf12f, 0xf130, 0xf131, 0xf132,
+ 0xf133, 0xf134, 0xf135, 0xf136, 0xf137, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf138,
+ 0xf139, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_38[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf000, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf01c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_39[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf01e, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf518, 0xf519, 0xf51a, 0xf51b, 0xf51c,
+ 0xf51d, 0xf51e, 0xf51f, 0xf520, 0xf521, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf522,
+ 0xf523, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_40[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
+ 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf87f, 0xf809,
+ 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
+ 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d, 0xf702, 0xf861, 0xf873,
+ 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf83b,
+ 0xf827, 0xf860, 0xf700, 0xf85c, 0xf87a, 0xf878, 0xf863, 0xf876,
+ 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
+ 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf202, 0xf907,
+ 0xf908, 0xf909, 0xf30b, 0xf904, 0xf905, 0xf906, 0xf30a, 0xf901,
+ 0xf902, 0xf903, 0xf900, 0xf310, 0xf206, 0xf200, 0xf83c, 0xf50a,
+ 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf212,
+ 0xf118, 0xf210, 0xf211, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_41[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf821, 0xf840, 0xf823, 0xf824, 0xf825, 0xf85e,
+ 0xf826, 0xf82a, 0xf828, 0xf829, 0xf85f, 0xf82b, 0xf87f, 0xf809,
+ 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
+ 0xf84f, 0xf850, 0xf87b, 0xf87d, 0xf80d, 0xf702, 0xf841, 0xf853,
+ 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf83a,
+ 0xf822, 0xf87e, 0xf700, 0xf87c, 0xf85a, 0xf858, 0xf843, 0xf856,
+ 0xf842, 0xf84e, 0xf84d, 0xf83c, 0xf83e, 0xf83f, 0xf700, 0xf916,
+ 0xf703, 0xf820, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf914, 0xf209, 0xf911,
+ 0xf912, 0xf913, 0xf917, 0xf90e, 0xf90f, 0xf910, 0xf918, 0xf90b,
+ 0xf90c, 0xf90d, 0xf90a, 0xf310, 0xf206, 0xf200, 0xf83e, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf919, 0xf702, 0xf915, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_42[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
+ 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf87f, 0xf809,
+ 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
+ 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d, 0xf702, 0xf861, 0xf873,
+ 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf83b,
+ 0xf827, 0xf860, 0xf700, 0xf85c, 0xf87a, 0xf878, 0xf863, 0xf876,
+ 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf87c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_43[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf821, 0xf840, 0xf823, 0xf824, 0xf825, 0xf85e,
+ 0xf826, 0xf82a, 0xf828, 0xf829, 0xf85f, 0xf82b, 0xf87f, 0xf809,
+ 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
+ 0xf84f, 0xf850, 0xf87b, 0xf87d, 0xf80d, 0xf702, 0xf841, 0xf853,
+ 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf83a,
+ 0xf822, 0xf87e, 0xf700, 0xf87c, 0xf85a, 0xf858, 0xf843, 0xf856,
+ 0xf842, 0xf84e, 0xf84d, 0xf83c, 0xf83e, 0xf83f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf87c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_44[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf800, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
+ 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf81c, 0xf50a,
+ 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_45[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf81e, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf81c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_46[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf800, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf81c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_47[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf81e, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf81c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_48[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
+ 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
+ 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
+ 0xfb6f, 0xfb70, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb61, 0xfb73,
+ 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03b,
+ 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
+ 0xfb62, 0xfb6e, 0xfb6d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_49[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
+ 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07f, 0xf009,
+ 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
+ 0xfb4f, 0xfb50, 0xf07b, 0xf07d, 0xf201, 0xf702, 0xfb41, 0xfb53,
+ 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03a,
+ 0xf022, 0xf07e, 0xf700, 0xf07c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
+ 0xfb42, 0xfb4e, 0xfb4d, 0xf03c, 0xf03e, 0xf03f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf10c, 0xf10d, 0xf10e, 0xf10f, 0xf110,
+ 0xf111, 0xf112, 0xf113, 0xf11e, 0xf11f, 0xf208, 0xf203, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03e, 0xf120,
+ 0xf121, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf20b, 0xf601, 0xf602, 0xf117, 0xf600, 0xf20a, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_50[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
+ 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
+ 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
+ 0xfb6f, 0xfb70, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb61, 0xfb73,
+ 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03b,
+ 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
+ 0xfb62, 0xfb6e, 0xfb6d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf916,
+ 0xf703, 0xf020, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf914, 0xf202, 0xf911,
+ 0xf912, 0xf913, 0xf917, 0xf90e, 0xf90f, 0xf910, 0xf918, 0xf90b,
+ 0xf90c, 0xf90d, 0xf90a, 0xf310, 0xf206, 0xf200, 0xf07c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf919, 0xf702, 0xf915, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_51[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
+ 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07f, 0xf009,
+ 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
+ 0xfb4f, 0xfb50, 0xf07b, 0xf07d, 0xf201, 0xf702, 0xfb41, 0xfb53,
+ 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03a,
+ 0xf022, 0xf07e, 0xf700, 0xf07c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
+ 0xfb42, 0xfb4e, 0xfb4d, 0xf03c, 0xf03e, 0xf03f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf518, 0xf519, 0xf51a, 0xf51b, 0xf51c,
+ 0xf51d, 0xf51e, 0xf51f, 0xf520, 0xf521, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0x00a6, 0xf522,
+ 0xf523, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_52[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf000, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf122, 0xf123, 0xf124, 0xf125, 0xf126,
+ 0xf127, 0xf128, 0xf129, 0xf12a, 0xf12b, 0xf208, 0xf204, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf12c,
+ 0xf12d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_53[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf01e, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf12e, 0xf12f, 0xf130, 0xf131, 0xf132,
+ 0xf133, 0xf134, 0xf135, 0xf136, 0xf137, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf138,
+ 0xf139, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_54[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf000, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf01c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_55[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf01e, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf518, 0xf519, 0xf51a, 0xf51b, 0xf51c,
+ 0xf51d, 0xf51e, 0xf51f, 0xf520, 0xf521, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf522,
+ 0xf523, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_56[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
+ 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf87f, 0xf809,
+ 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
+ 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d, 0xf702, 0xf861, 0xf873,
+ 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf83b,
+ 0xf827, 0xf860, 0xf700, 0xf85c, 0xf87a, 0xf878, 0xf863, 0xf876,
+ 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
+ 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf202, 0xf907,
+ 0xf908, 0xf909, 0xf30b, 0xf904, 0xf905, 0xf906, 0xf30a, 0xf901,
+ 0xf902, 0xf903, 0xf900, 0xf310, 0xf206, 0xf200, 0xf83c, 0xf50a,
+ 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf212,
+ 0xf118, 0xf210, 0xf211, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_57[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf821, 0xf840, 0xf823, 0xf824, 0xf825, 0xf85e,
+ 0xf826, 0xf82a, 0xf828, 0xf829, 0xf85f, 0xf82b, 0xf87f, 0xf809,
+ 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
+ 0xf84f, 0xf850, 0xf87b, 0xf87d, 0xf80d, 0xf702, 0xf841, 0xf853,
+ 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf83a,
+ 0xf822, 0xf87e, 0xf700, 0xf87c, 0xf85a, 0xf858, 0xf843, 0xf856,
+ 0xf842, 0xf84e, 0xf84d, 0xf83c, 0xf83e, 0xf83f, 0xf700, 0xf916,
+ 0xf703, 0xf820, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf914, 0xf209, 0xf911,
+ 0xf912, 0xf913, 0xf917, 0xf90e, 0xf90f, 0xf910, 0xf918, 0xf90b,
+ 0xf90c, 0xf90d, 0xf90a, 0xf310, 0xf206, 0xf200, 0xf83e, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf919, 0xf702, 0xf915, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_58[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
+ 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf87f, 0xf809,
+ 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
+ 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d, 0xf702, 0xf861, 0xf873,
+ 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf83b,
+ 0xf827, 0xf860, 0xf700, 0xf85c, 0xf87a, 0xf878, 0xf863, 0xf876,
+ 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf87c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_59[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf821, 0xf840, 0xf823, 0xf824, 0xf825, 0xf85e,
+ 0xf826, 0xf82a, 0xf828, 0xf829, 0xf85f, 0xf82b, 0xf87f, 0xf809,
+ 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
+ 0xf84f, 0xf850, 0xf87b, 0xf87d, 0xf80d, 0xf702, 0xf841, 0xf853,
+ 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf83a,
+ 0xf822, 0xf87e, 0xf700, 0xf87c, 0xf85a, 0xf858, 0xf843, 0xf856,
+ 0xf842, 0xf84e, 0xf84d, 0xf83c, 0xf83e, 0xf83f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf87c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_60[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf800, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
+ 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf81c, 0xf50a,
+ 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_61[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf81e, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf81c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_62[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf800, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf81c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_63[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf81e, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf81c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_64[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
+ 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
+ 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
+ 0xfb4f, 0xfb50, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb41, 0xfb53,
+ 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03b,
+ 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
+ 0xfb42, 0xfb4e, 0xfb4d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_65[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
+ 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07f, 0xf009,
+ 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
+ 0xfb6f, 0xfb70, 0xf07b, 0xf07d, 0xf201, 0xf702, 0xfb61, 0xfb73,
+ 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03a,
+ 0xf022, 0xf07e, 0xf700, 0xf07c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
+ 0xfb62, 0xfb6e, 0xfb6d, 0xf03c, 0xf03e, 0xf03f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf10c, 0xf10d, 0xf10e, 0xf10f, 0xf110,
+ 0xf111, 0xf112, 0xf113, 0xf11e, 0xf11f, 0xf208, 0xf203, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03e, 0xf120,
+ 0xf121, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf20b, 0xf601, 0xf602, 0xf117, 0xf600, 0xf20a, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_66[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
+ 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
+ 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
+ 0xfb4f, 0xfb50, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb41, 0xfb53,
+ 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03b,
+ 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
+ 0xfb42, 0xfb4e, 0xfb4d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf916,
+ 0xf703, 0xf020, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf914, 0xf202, 0xf911,
+ 0xf912, 0xf913, 0xf917, 0xf90e, 0xf90f, 0xf910, 0xf918, 0xf90b,
+ 0xf90c, 0xf90d, 0xf90a, 0xf310, 0xf206, 0xf200, 0xf07c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf919, 0xf702, 0xf915, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_67[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
+ 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07f, 0xf009,
+ 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
+ 0xfb6f, 0xfb70, 0xf07b, 0xf07d, 0xf201, 0xf702, 0xfb61, 0xfb73,
+ 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03a,
+ 0xf022, 0xf07e, 0xf700, 0xf07c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
+ 0xfb62, 0xfb6e, 0xfb6d, 0xf03c, 0xf03e, 0xf03f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf518, 0xf519, 0xf51a, 0xf51b, 0xf51c,
+ 0xf51d, 0xf51e, 0xf51f, 0xf520, 0xf521, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0x00a6, 0xf522,
+ 0xf523, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_68[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf000, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf122, 0xf123, 0xf124, 0xf125, 0xf126,
+ 0xf127, 0xf128, 0xf129, 0xf12a, 0xf12b, 0xf208, 0xf204, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf12c,
+ 0xf12d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_69[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf01e, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf12e, 0xf12f, 0xf130, 0xf131, 0xf132,
+ 0xf133, 0xf134, 0xf135, 0xf136, 0xf137, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf138,
+ 0xf139, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_70[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf000, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf01c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_71[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf01e, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf518, 0xf519, 0xf51a, 0xf51b, 0xf51c,
+ 0xf51d, 0xf51e, 0xf51f, 0xf520, 0xf521, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf522,
+ 0xf523, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_72[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
+ 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf87f, 0xf809,
+ 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
+ 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d, 0xf702, 0xf861, 0xf873,
+ 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf83b,
+ 0xf827, 0xf860, 0xf700, 0xf85c, 0xf87a, 0xf878, 0xf863, 0xf876,
+ 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
+ 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf202, 0xf907,
+ 0xf908, 0xf909, 0xf30b, 0xf904, 0xf905, 0xf906, 0xf30a, 0xf901,
+ 0xf902, 0xf903, 0xf900, 0xf310, 0xf206, 0xf200, 0xf83c, 0xf50a,
+ 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf212,
+ 0xf118, 0xf210, 0xf211, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_73[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf821, 0xf840, 0xf823, 0xf824, 0xf825, 0xf85e,
+ 0xf826, 0xf82a, 0xf828, 0xf829, 0xf85f, 0xf82b, 0xf87f, 0xf809,
+ 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
+ 0xf84f, 0xf850, 0xf87b, 0xf87d, 0xf80d, 0xf702, 0xf841, 0xf853,
+ 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf83a,
+ 0xf822, 0xf87e, 0xf700, 0xf87c, 0xf85a, 0xf858, 0xf843, 0xf856,
+ 0xf842, 0xf84e, 0xf84d, 0xf83c, 0xf83e, 0xf83f, 0xf700, 0xf916,
+ 0xf703, 0xf820, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf914, 0xf209, 0xf911,
+ 0xf912, 0xf913, 0xf917, 0xf90e, 0xf90f, 0xf910, 0xf918, 0xf90b,
+ 0xf90c, 0xf90d, 0xf90a, 0xf310, 0xf206, 0xf200, 0xf83e, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf919, 0xf702, 0xf915, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_74[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
+ 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf87f, 0xf809,
+ 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
+ 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d, 0xf702, 0xf861, 0xf873,
+ 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf83b,
+ 0xf827, 0xf860, 0xf700, 0xf85c, 0xf87a, 0xf878, 0xf863, 0xf876,
+ 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf87c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_75[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf821, 0xf840, 0xf823, 0xf824, 0xf825, 0xf85e,
+ 0xf826, 0xf82a, 0xf828, 0xf829, 0xf85f, 0xf82b, 0xf87f, 0xf809,
+ 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
+ 0xf84f, 0xf850, 0xf87b, 0xf87d, 0xf80d, 0xf702, 0xf841, 0xf853,
+ 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf83a,
+ 0xf822, 0xf87e, 0xf700, 0xf87c, 0xf85a, 0xf858, 0xf843, 0xf856,
+ 0xf842, 0xf84e, 0xf84d, 0xf83c, 0xf83e, 0xf83f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf87c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_76[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf800, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
+ 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf81c, 0xf50a,
+ 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_77[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf81e, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf81c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_78[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf800, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf81c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_79[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf81e, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf81c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_80[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
+ 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
+ 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
+ 0xfb4f, 0xfb50, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb41, 0xfb53,
+ 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03b,
+ 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
+ 0xfb42, 0xfb4e, 0xfb4d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_81[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
+ 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07f, 0xf009,
+ 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
+ 0xfb6f, 0xfb70, 0xf07b, 0xf07d, 0xf201, 0xf702, 0xfb61, 0xfb73,
+ 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03a,
+ 0xf022, 0xf07e, 0xf700, 0xf07c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
+ 0xfb62, 0xfb6e, 0xfb6d, 0xf03c, 0xf03e, 0xf03f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf10c, 0xf10d, 0xf10e, 0xf10f, 0xf110,
+ 0xf111, 0xf112, 0xf113, 0xf11e, 0xf11f, 0xf208, 0xf203, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03e, 0xf120,
+ 0xf121, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf20b, 0xf601, 0xf602, 0xf117, 0xf600, 0xf20a, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_82[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
+ 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
+ 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
+ 0xfb4f, 0xfb50, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb41, 0xfb53,
+ 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03b,
+ 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
+ 0xfb42, 0xfb4e, 0xfb4d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf916,
+ 0xf703, 0xf020, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf914, 0xf202, 0xf911,
+ 0xf912, 0xf913, 0xf917, 0xf90e, 0xf90f, 0xf910, 0xf918, 0xf90b,
+ 0xf90c, 0xf90d, 0xf90a, 0xf310, 0xf206, 0xf200, 0xf07c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf919, 0xf702, 0xf915, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_83[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
+ 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07f, 0xf009,
+ 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
+ 0xfb6f, 0xfb70, 0xf07b, 0xf07d, 0xf201, 0xf702, 0xfb61, 0xfb73,
+ 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03a,
+ 0xf022, 0xf07e, 0xf700, 0xf07c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
+ 0xfb62, 0xfb6e, 0xfb6d, 0xf03c, 0xf03e, 0xf03f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf518, 0xf519, 0xf51a, 0xf51b, 0xf51c,
+ 0xf51d, 0xf51e, 0xf51f, 0xf520, 0xf521, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0x00a6, 0xf522,
+ 0xf523, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_84[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf000, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf122, 0xf123, 0xf124, 0xf125, 0xf126,
+ 0xf127, 0xf128, 0xf129, 0xf12a, 0xf12b, 0xf208, 0xf204, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf12c,
+ 0xf12d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_85[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf01e, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf12e, 0xf12f, 0xf130, 0xf131, 0xf132,
+ 0xf133, 0xf134, 0xf135, 0xf136, 0xf137, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf138,
+ 0xf139, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_86[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf000, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf01c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_87[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf01e, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf518, 0xf519, 0xf51a, 0xf51b, 0xf51c,
+ 0xf51d, 0xf51e, 0xf51f, 0xf520, 0xf521, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf522,
+ 0xf523, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_88[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
+ 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf87f, 0xf809,
+ 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
+ 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d, 0xf702, 0xf861, 0xf873,
+ 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf83b,
+ 0xf827, 0xf860, 0xf700, 0xf85c, 0xf87a, 0xf878, 0xf863, 0xf876,
+ 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
+ 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf202, 0xf907,
+ 0xf908, 0xf909, 0xf30b, 0xf904, 0xf905, 0xf906, 0xf30a, 0xf901,
+ 0xf902, 0xf903, 0xf900, 0xf310, 0xf206, 0xf200, 0xf83c, 0xf50a,
+ 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf212,
+ 0xf118, 0xf210, 0xf211, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_89[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf821, 0xf840, 0xf823, 0xf824, 0xf825, 0xf85e,
+ 0xf826, 0xf82a, 0xf828, 0xf829, 0xf85f, 0xf82b, 0xf87f, 0xf809,
+ 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
+ 0xf84f, 0xf850, 0xf87b, 0xf87d, 0xf80d, 0xf702, 0xf841, 0xf853,
+ 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf83a,
+ 0xf822, 0xf87e, 0xf700, 0xf87c, 0xf85a, 0xf858, 0xf843, 0xf856,
+ 0xf842, 0xf84e, 0xf84d, 0xf83c, 0xf83e, 0xf83f, 0xf700, 0xf916,
+ 0xf703, 0xf820, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf914, 0xf209, 0xf911,
+ 0xf912, 0xf913, 0xf917, 0xf90e, 0xf90f, 0xf910, 0xf918, 0xf90b,
+ 0xf90c, 0xf90d, 0xf90a, 0xf310, 0xf206, 0xf200, 0xf83e, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf919, 0xf702, 0xf915, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_90[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
+ 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf87f, 0xf809,
+ 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
+ 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d, 0xf702, 0xf861, 0xf873,
+ 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf83b,
+ 0xf827, 0xf860, 0xf700, 0xf85c, 0xf87a, 0xf878, 0xf863, 0xf876,
+ 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf87c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_91[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf821, 0xf840, 0xf823, 0xf824, 0xf825, 0xf85e,
+ 0xf826, 0xf82a, 0xf828, 0xf829, 0xf85f, 0xf82b, 0xf87f, 0xf809,
+ 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
+ 0xf84f, 0xf850, 0xf87b, 0xf87d, 0xf80d, 0xf702, 0xf841, 0xf853,
+ 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf83a,
+ 0xf822, 0xf87e, 0xf700, 0xf87c, 0xf85a, 0xf858, 0xf843, 0xf856,
+ 0xf842, 0xf84e, 0xf84d, 0xf83c, 0xf83e, 0xf83f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf87c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_92[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf800, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
+ 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf81c, 0xf50a,
+ 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_93[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf81e, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf81c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_94[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf800, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf81c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_95[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf81e, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf81c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_96[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
+ 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
+ 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
+ 0xfb4f, 0xfb50, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb41, 0xfb53,
+ 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03b,
+ 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
+ 0xfb42, 0xfb4e, 0xfb4d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_97[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
+ 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07f, 0xf009,
+ 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
+ 0xfb6f, 0xfb70, 0xf07b, 0xf07d, 0xf201, 0xf702, 0xfb61, 0xfb73,
+ 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03a,
+ 0xf022, 0xf07e, 0xf700, 0xf07c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
+ 0xfb62, 0xfb6e, 0xfb6d, 0xf03c, 0xf03e, 0xf03f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf10c, 0xf10d, 0xf10e, 0xf10f, 0xf110,
+ 0xf111, 0xf112, 0xf113, 0xf11e, 0xf11f, 0xf208, 0xf203, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03e, 0xf120,
+ 0xf121, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf20b, 0xf601, 0xf602, 0xf117, 0xf600, 0xf20a, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_98[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
+ 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
+ 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
+ 0xfb4f, 0xfb50, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb41, 0xfb53,
+ 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03b,
+ 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
+ 0xfb42, 0xfb4e, 0xfb4d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf916,
+ 0xf703, 0xf020, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf914, 0xf202, 0xf911,
+ 0xf912, 0xf913, 0xf917, 0xf90e, 0xf90f, 0xf910, 0xf918, 0xf90b,
+ 0xf90c, 0xf90d, 0xf90a, 0xf310, 0xf206, 0xf200, 0xf07c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf919, 0xf702, 0xf915, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_99[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
+ 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07f, 0xf009,
+ 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
+ 0xfb6f, 0xfb70, 0xf07b, 0xf07d, 0xf201, 0xf702, 0xfb61, 0xfb73,
+ 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03a,
+ 0xf022, 0xf07e, 0xf700, 0xf07c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
+ 0xfb62, 0xfb6e, 0xfb6d, 0xf03c, 0xf03e, 0xf03f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf518, 0xf519, 0xf51a, 0xf51b, 0xf51c,
+ 0xf51d, 0xf51e, 0xf51f, 0xf520, 0xf521, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0x00a6, 0xf522,
+ 0xf523, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_100[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf000, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf122, 0xf123, 0xf124, 0xf125, 0xf126,
+ 0xf127, 0xf128, 0xf129, 0xf12a, 0xf12b, 0xf208, 0xf204, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf12c,
+ 0xf12d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_101[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf01e, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf12e, 0xf12f, 0xf130, 0xf131, 0xf132,
+ 0xf133, 0xf134, 0xf135, 0xf136, 0xf137, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf138,
+ 0xf139, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_102[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf000, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf01c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_103[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf01e, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf518, 0xf519, 0xf51a, 0xf51b, 0xf51c,
+ 0xf51d, 0xf51e, 0xf51f, 0xf520, 0xf521, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf522,
+ 0xf523, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_104[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
+ 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf87f, 0xf809,
+ 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
+ 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d, 0xf702, 0xf861, 0xf873,
+ 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf83b,
+ 0xf827, 0xf860, 0xf700, 0xf85c, 0xf87a, 0xf878, 0xf863, 0xf876,
+ 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
+ 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf202, 0xf907,
+ 0xf908, 0xf909, 0xf30b, 0xf904, 0xf905, 0xf906, 0xf30a, 0xf901,
+ 0xf902, 0xf903, 0xf900, 0xf310, 0xf206, 0xf200, 0xf83c, 0xf50a,
+ 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf212,
+ 0xf118, 0xf210, 0xf211, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_105[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf821, 0xf840, 0xf823, 0xf824, 0xf825, 0xf85e,
+ 0xf826, 0xf82a, 0xf828, 0xf829, 0xf85f, 0xf82b, 0xf87f, 0xf809,
+ 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
+ 0xf84f, 0xf850, 0xf87b, 0xf87d, 0xf80d, 0xf702, 0xf841, 0xf853,
+ 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf83a,
+ 0xf822, 0xf87e, 0xf700, 0xf87c, 0xf85a, 0xf858, 0xf843, 0xf856,
+ 0xf842, 0xf84e, 0xf84d, 0xf83c, 0xf83e, 0xf83f, 0xf700, 0xf916,
+ 0xf703, 0xf820, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf914, 0xf209, 0xf911,
+ 0xf912, 0xf913, 0xf917, 0xf90e, 0xf90f, 0xf910, 0xf918, 0xf90b,
+ 0xf90c, 0xf90d, 0xf90a, 0xf310, 0xf206, 0xf200, 0xf83e, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf919, 0xf702, 0xf915, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_106[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
+ 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf87f, 0xf809,
+ 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
+ 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d, 0xf702, 0xf861, 0xf873,
+ 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf83b,
+ 0xf827, 0xf860, 0xf700, 0xf85c, 0xf87a, 0xf878, 0xf863, 0xf876,
+ 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf87c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_107[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf821, 0xf840, 0xf823, 0xf824, 0xf825, 0xf85e,
+ 0xf826, 0xf82a, 0xf828, 0xf829, 0xf85f, 0xf82b, 0xf87f, 0xf809,
+ 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
+ 0xf84f, 0xf850, 0xf87b, 0xf87d, 0xf80d, 0xf702, 0xf841, 0xf853,
+ 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf83a,
+ 0xf822, 0xf87e, 0xf700, 0xf87c, 0xf85a, 0xf858, 0xf843, 0xf856,
+ 0xf842, 0xf84e, 0xf84d, 0xf83c, 0xf83e, 0xf83f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf87c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_108[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf800, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
+ 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf81c, 0xf50a,
+ 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_109[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf81e, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf81c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_110[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf800, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf81c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_111[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf81e, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf81c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_112[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
+ 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
+ 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
+ 0xfb4f, 0xfb50, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb41, 0xfb53,
+ 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03b,
+ 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
+ 0xfb42, 0xfb4e, 0xfb4d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_113[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
+ 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07f, 0xf009,
+ 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
+ 0xfb6f, 0xfb70, 0xf07b, 0xf07d, 0xf201, 0xf702, 0xfb61, 0xfb73,
+ 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03a,
+ 0xf022, 0xf07e, 0xf700, 0xf07c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
+ 0xfb62, 0xfb6e, 0xfb6d, 0xf03c, 0xf03e, 0xf03f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf10c, 0xf10d, 0xf10e, 0xf10f, 0xf110,
+ 0xf111, 0xf112, 0xf113, 0xf11e, 0xf11f, 0xf208, 0xf203, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03e, 0xf120,
+ 0xf121, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf20b, 0xf601, 0xf602, 0xf117, 0xf600, 0xf20a, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_114[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
+ 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
+ 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
+ 0xfb4f, 0xfb50, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb41, 0xfb53,
+ 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03b,
+ 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
+ 0xfb42, 0xfb4e, 0xfb4d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf916,
+ 0xf703, 0xf020, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf914, 0xf202, 0xf911,
+ 0xf912, 0xf913, 0xf917, 0xf90e, 0xf90f, 0xf910, 0xf918, 0xf90b,
+ 0xf90c, 0xf90d, 0xf90a, 0xf310, 0xf206, 0xf200, 0xf07c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf919, 0xf702, 0xf915, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_115[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
+ 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07f, 0xf009,
+ 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
+ 0xfb6f, 0xfb70, 0xf07b, 0xf07d, 0xf201, 0xf702, 0xfb61, 0xfb73,
+ 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03a,
+ 0xf022, 0xf07e, 0xf700, 0xf07c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
+ 0xfb62, 0xfb6e, 0xfb6d, 0xf03c, 0xf03e, 0xf03f, 0xf700, 0xf30c,
+ 0xf703, 0xf020, 0xfa06, 0xf518, 0xf519, 0xf51a, 0xf51b, 0xf51c,
+ 0xf51d, 0xf51e, 0xf51f, 0xf520, 0xf521, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0x00a6, 0xf522,
+ 0xf523, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_116[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf000, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf122, 0xf123, 0xf124, 0xf125, 0xf126,
+ 0xf127, 0xf128, 0xf129, 0xf12a, 0xf12b, 0xf208, 0xf204, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf12c,
+ 0xf12d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_117[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf01e, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf12e, 0xf12f, 0xf130, 0xf131, 0xf132,
+ 0xf133, 0xf134, 0xf135, 0xf136, 0xf137, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf138,
+ 0xf139, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_118[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf000, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf01c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_119[NR_KEYS] = {
+ 0xf27e, 0xf01b, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf01e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf009,
+ 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
+ 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf00d, 0xf702, 0xf001, 0xf013,
+ 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
+ 0xf200, 0xf01e, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
+ 0xf002, 0xf00e, 0xf201, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
+ 0xf703, 0xf000, 0xfa06, 0xf518, 0xf519, 0xf51a, 0xf51b, 0xf51c,
+ 0xf51d, 0xf51e, 0xf51f, 0xf520, 0xf521, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf01c, 0xf522,
+ 0xf523, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf205,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_120[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
+ 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf87f, 0xf809,
+ 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
+ 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d, 0xf702, 0xf861, 0xf873,
+ 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf83b,
+ 0xf827, 0xf860, 0xf700, 0xf85c, 0xf87a, 0xf878, 0xf863, 0xf876,
+ 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
+ 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf202, 0xf907,
+ 0xf908, 0xf909, 0xf30b, 0xf904, 0xf905, 0xf906, 0xf30a, 0xf901,
+ 0xf902, 0xf903, 0xf900, 0xf310, 0xf206, 0xf200, 0xf83c, 0xf50a,
+ 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf212,
+ 0xf118, 0xf210, 0xf211, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_121[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf821, 0xf840, 0xf823, 0xf824, 0xf825, 0xf85e,
+ 0xf826, 0xf82a, 0xf828, 0xf829, 0xf85f, 0xf82b, 0xf87f, 0xf809,
+ 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
+ 0xf84f, 0xf850, 0xf87b, 0xf87d, 0xf80d, 0xf702, 0xf841, 0xf853,
+ 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf83a,
+ 0xf822, 0xf87e, 0xf700, 0xf87c, 0xf85a, 0xf858, 0xf843, 0xf856,
+ 0xf842, 0xf84e, 0xf84d, 0xf83c, 0xf83e, 0xf83f, 0xf700, 0xf916,
+ 0xf703, 0xf820, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf914, 0xf209, 0xf911,
+ 0xf912, 0xf913, 0xf917, 0xf90e, 0xf90f, 0xf910, 0xf918, 0xf90b,
+ 0xf90c, 0xf90d, 0xf90a, 0xf310, 0xf206, 0xf200, 0xf83e, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf919, 0xf702, 0xf915, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_122[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
+ 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf87f, 0xf809,
+ 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
+ 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d, 0xf702, 0xf861, 0xf873,
+ 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf83b,
+ 0xf827, 0xf860, 0xf700, 0xf85c, 0xf87a, 0xf878, 0xf863, 0xf876,
+ 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf87c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_123[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf821, 0xf840, 0xf823, 0xf824, 0xf825, 0xf85e,
+ 0xf826, 0xf82a, 0xf828, 0xf829, 0xf85f, 0xf82b, 0xf87f, 0xf809,
+ 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
+ 0xf84f, 0xf850, 0xf87b, 0xf87d, 0xf80d, 0xf702, 0xf841, 0xf853,
+ 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf83a,
+ 0xf822, 0xf87e, 0xf700, 0xf87c, 0xf85a, 0xf858, 0xf843, 0xf856,
+ 0xf842, 0xf84e, 0xf84d, 0xf83c, 0xf83e, 0xf83f, 0xf700, 0xf30c,
+ 0xf703, 0xf820, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf87c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf206, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_124[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf800, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
+ 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf81c, 0xf50a,
+ 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_125[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf81e, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
+ 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf81c, 0xf516,
+ 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_126[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf800, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf81c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+static unsigned short default_key_map_127[NR_KEYS] = {
+ 0xf27e, 0xf81b, 0xf200, 0xf800, 0xf200, 0xf200, 0xf200, 0xf81e,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf81f, 0xf200, 0xf808, 0xf809,
+ 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
+ 0xf80f, 0xf810, 0xf81b, 0xf81d, 0xf80d, 0xf702, 0xf801, 0xf813,
+ 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
+ 0xf200, 0xf81e, 0xf700, 0xf81c, 0xf81a, 0xf818, 0xf803, 0xf816,
+ 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf20e, 0xf87f, 0xf700, 0xf30c,
+ 0xf703, 0xf800, 0xfa06, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
+ 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
+ 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
+ 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf81c, 0xf10a,
+ 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf30e, 0xf702, 0xf30d, 0xf81c, 0xf703, 0xf205, 0xf114, 0xf603,
+ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf11d,
+ 0xf200, 0xf310, 0xf200, 0xf200, 0xf200, 0xf703, 0xf703, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+ 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
+};
+#endif /* INCLUDE_EXTENDED_KEYMAP */
+
+static unsigned short *default_key_maps[MAX_NR_KEYMAPS] = {
+ default_key_map_0,
+ default_key_map_1,
+ default_key_map_2,
+ default_key_map_3,
+#ifdef INCLUDE_EXTENDED_KEYMAP
+ default_key_map_4,
+ default_key_map_5,
+ default_key_map_6,
+ default_key_map_7,
+ default_key_map_8,
+ default_key_map_9,
+ default_key_map_10,
+ default_key_map_11,
+ default_key_map_12,
+ default_key_map_13,
+ default_key_map_14,
+ default_key_map_15,
+ default_key_map_16,
+ default_key_map_17,
+ default_key_map_18,
+ default_key_map_19,
+ default_key_map_20,
+ default_key_map_21,
+ default_key_map_22,
+ default_key_map_23,
+ default_key_map_24,
+ default_key_map_25,
+ default_key_map_26,
+ default_key_map_27,
+ default_key_map_28,
+ default_key_map_29,
+ default_key_map_30,
+ default_key_map_31,
+ default_key_map_32,
+ default_key_map_33,
+ default_key_map_34,
+ default_key_map_35,
+ default_key_map_36,
+ default_key_map_37,
+ default_key_map_38,
+ default_key_map_39,
+ default_key_map_40,
+ default_key_map_41,
+ default_key_map_42,
+ default_key_map_43,
+ default_key_map_44,
+ default_key_map_45,
+ default_key_map_46,
+ default_key_map_47,
+ default_key_map_48,
+ default_key_map_49,
+ default_key_map_50,
+ default_key_map_51,
+ default_key_map_52,
+ default_key_map_53,
+ default_key_map_54,
+ default_key_map_55,
+ default_key_map_56,
+ default_key_map_57,
+ default_key_map_58,
+ default_key_map_59,
+ default_key_map_60,
+ default_key_map_61,
+ default_key_map_62,
+ default_key_map_63,
+ default_key_map_64,
+ default_key_map_65,
+ default_key_map_66,
+ default_key_map_67,
+ default_key_map_68,
+ default_key_map_69,
+ default_key_map_70,
+ default_key_map_71,
+ default_key_map_72,
+ default_key_map_73,
+ default_key_map_74,
+ default_key_map_75,
+ default_key_map_76,
+ default_key_map_77,
+ default_key_map_78,
+ default_key_map_79,
+ default_key_map_80,
+ default_key_map_81,
+ default_key_map_82,
+ default_key_map_83,
+ default_key_map_84,
+ default_key_map_85,
+ default_key_map_86,
+ default_key_map_87,
+ default_key_map_88,
+ default_key_map_89,
+ default_key_map_90,
+ default_key_map_91,
+ default_key_map_92,
+ default_key_map_93,
+ default_key_map_94,
+ default_key_map_95,
+ default_key_map_96,
+ default_key_map_97,
+ default_key_map_98,
+ default_key_map_99,
+ default_key_map_100,
+ default_key_map_101,
+ default_key_map_102,
+ default_key_map_103,
+ default_key_map_104,
+ default_key_map_105,
+ default_key_map_106,
+ default_key_map_107,
+ default_key_map_108,
+ default_key_map_109,
+ default_key_map_110,
+ default_key_map_111,
+ default_key_map_112,
+ default_key_map_113,
+ default_key_map_114,
+ default_key_map_115,
+ default_key_map_116,
+ default_key_map_117,
+ default_key_map_118,
+ default_key_map_119,
+ default_key_map_120,
+ default_key_map_121,
+ default_key_map_122,
+ default_key_map_123,
+ default_key_map_124,
+ default_key_map_125,
+ default_key_map_126,
+ default_key_map_127,
+#else /* !INCLUDE_EXTENDED_KEYMAP */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+#endif /* INCLUDE_EXTENDED_KEYMAP */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+};
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/linux/SDL_fcitx.c b/src/3rdparty/SDL2/src/core/linux/SDL_fcitx.c
new file mode 100644
index 0000000..41954e9
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/linux/SDL_fcitx.c
@@ -0,0 +1,373 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef HAVE_FCITX_FRONTEND_H
+
+#include <fcitx/frontend.h>
+#include <unistd.h>
+
+#include "SDL_fcitx.h"
+#include "SDL_keycode.h"
+#include "SDL_keyboard.h"
+#include "../../events/SDL_keyboard_c.h"
+#include "SDL_dbus.h"
+#include "SDL_syswm.h"
+#if SDL_VIDEO_DRIVER_X11
+# include "../../video/x11/SDL_x11video.h"
+#endif
+#include "SDL_hints.h"
+
+#define FCITX_DBUS_SERVICE "org.fcitx.Fcitx"
+
+#define FCITX_IM_DBUS_PATH "/inputmethod"
+#define FCITX_IC_DBUS_PATH "/inputcontext_%d"
+
+#define FCITX_IM_DBUS_INTERFACE "org.fcitx.Fcitx.InputMethod"
+#define FCITX_IC_DBUS_INTERFACE "org.fcitx.Fcitx.InputContext"
+
+#define IC_NAME_MAX 64
+#define DBUS_TIMEOUT 500
+
+typedef struct _FcitxClient
+{
+ SDL_DBusContext *dbus;
+
+ char servicename[IC_NAME_MAX];
+ char icname[IC_NAME_MAX];
+
+ int id;
+
+ SDL_Rect cursor_rect;
+} FcitxClient;
+
+static FcitxClient fcitx_client;
+
+static int
+GetDisplayNumber()
+{
+ const char *display = SDL_getenv("DISPLAY");
+ const char *p = NULL;
+ int number = 0;
+
+ if (display == NULL)
+ return 0;
+
+ display = SDL_strchr(display, ':');
+ if (display == NULL)
+ return 0;
+
+ display++;
+ p = SDL_strchr(display, '.');
+ if (p == NULL && display != NULL) {
+ number = SDL_strtod(display, NULL);
+ } else {
+ char *buffer = SDL_strdup(display);
+ buffer[p - display] = '\0';
+ number = SDL_strtod(buffer, NULL);
+ SDL_free(buffer);
+ }
+
+ return number;
+}
+
+static char*
+GetAppName()
+{
+#if defined(__LINUX__) || defined(__FREEBSD__)
+ char *spot;
+ char procfile[1024];
+ char linkfile[1024];
+ int linksize;
+
+#if defined(__LINUX__)
+ SDL_snprintf(procfile, sizeof(procfile), "/proc/%d/exe", getpid());
+#elif defined(__FREEBSD__)
+ SDL_snprintf(procfile, sizeof(procfile), "/proc/%d/file", getpid());
+#endif
+ linksize = readlink(procfile, linkfile, sizeof(linkfile) - 1);
+ if (linksize > 0) {
+ linkfile[linksize] = '\0';
+ spot = SDL_strrchr(linkfile, '/');
+ if (spot) {
+ return SDL_strdup(spot + 1);
+ } else {
+ return SDL_strdup(linkfile);
+ }
+ }
+#endif /* __LINUX__ || __FREEBSD__ */
+
+ return SDL_strdup("SDL_App");
+}
+
+static DBusHandlerResult
+DBus_MessageFilter(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+ SDL_DBusContext *dbus = (SDL_DBusContext *)data;
+
+ if (dbus->message_is_signal(msg, FCITX_IC_DBUS_INTERFACE, "CommitString")) {
+ DBusMessageIter iter;
+ const char *text = NULL;
+
+ dbus->message_iter_init(msg, &iter);
+ dbus->message_iter_get_basic(&iter, &text);
+
+ if (text)
+ SDL_SendKeyboardText(text);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ if (dbus->message_is_signal(msg, FCITX_IC_DBUS_INTERFACE, "UpdatePreedit")) {
+ DBusMessageIter iter;
+ const char *text;
+
+ dbus->message_iter_init(msg, &iter);
+ dbus->message_iter_get_basic(&iter, &text);
+
+ if (text && *text) {
+ char buf[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
+ size_t text_bytes = SDL_strlen(text), i = 0;
+ size_t cursor = 0;
+
+ while (i < text_bytes) {
+ const size_t sz = SDL_utf8strlcpy(buf, text + i, sizeof(buf));
+ const size_t chars = SDL_utf8strlen(buf);
+
+ SDL_SendEditingText(buf, cursor, chars);
+
+ i += sz;
+ cursor += chars;
+ }
+ }
+
+ SDL_Fcitx_UpdateTextRect(NULL);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static void
+FcitxClientICCallMethod(FcitxClient *client, const char *method)
+{
+ SDL_DBus_CallVoidMethod(client->servicename, client->icname, FCITX_IC_DBUS_INTERFACE, method, DBUS_TYPE_INVALID);
+}
+
+static void SDLCALL
+Fcitx_SetCapabilities(void *data,
+ const char *name,
+ const char *old_val,
+ const char *internal_editing)
+{
+ FcitxClient *client = (FcitxClient *)data;
+ Uint32 caps = CAPACITY_NONE;
+
+ if (!(internal_editing && *internal_editing == '1')) {
+ caps |= CAPACITY_PREEDIT;
+ }
+
+ SDL_DBus_CallVoidMethod(client->servicename, client->icname, FCITX_IC_DBUS_INTERFACE, "SetCapacity", DBUS_TYPE_UINT32, &caps, DBUS_TYPE_INVALID);
+}
+
+static SDL_bool
+FcitxClientCreateIC(FcitxClient *client)
+{
+ char *appname = GetAppName();
+ pid_t pid = getpid();
+ int id = -1;
+ Uint32 enable, arg1, arg2, arg3, arg4;
+
+ if (!SDL_DBus_CallMethod(client->servicename, FCITX_IM_DBUS_PATH, FCITX_IM_DBUS_INTERFACE, "CreateICv3",
+ DBUS_TYPE_STRING, &appname, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID,
+ DBUS_TYPE_INT32, &id, DBUS_TYPE_BOOLEAN, &enable, DBUS_TYPE_UINT32, &arg1, DBUS_TYPE_UINT32, &arg2, DBUS_TYPE_UINT32, &arg3, DBUS_TYPE_UINT32, &arg4, DBUS_TYPE_INVALID)) {
+ id = -1; /* just in case. */
+ }
+
+ SDL_free(appname);
+
+ if (id >= 0) {
+ SDL_DBusContext *dbus = client->dbus;
+
+ client->id = id;
+
+ SDL_snprintf(client->icname, IC_NAME_MAX, FCITX_IC_DBUS_PATH, client->id);
+
+ dbus->bus_add_match(dbus->session_conn,
+ "type='signal', interface='org.fcitx.Fcitx.InputContext'",
+ NULL);
+ dbus->connection_add_filter(dbus->session_conn,
+ &DBus_MessageFilter, dbus,
+ NULL);
+ dbus->connection_flush(dbus->session_conn);
+
+ SDL_AddHintCallback(SDL_HINT_IME_INTERNAL_EDITING, Fcitx_SetCapabilities, client);
+ return SDL_TRUE;
+ }
+
+ return SDL_FALSE;
+}
+
+static Uint32
+Fcitx_ModState(void)
+{
+ Uint32 fcitx_mods = 0;
+ SDL_Keymod sdl_mods = SDL_GetModState();
+
+ if (sdl_mods & KMOD_SHIFT) fcitx_mods |= FcitxKeyState_Shift;
+ if (sdl_mods & KMOD_CAPS) fcitx_mods |= FcitxKeyState_CapsLock;
+ if (sdl_mods & KMOD_CTRL) fcitx_mods |= FcitxKeyState_Ctrl;
+ if (sdl_mods & KMOD_ALT) fcitx_mods |= FcitxKeyState_Alt;
+ if (sdl_mods & KMOD_NUM) fcitx_mods |= FcitxKeyState_NumLock;
+ if (sdl_mods & KMOD_LGUI) fcitx_mods |= FcitxKeyState_Super;
+ if (sdl_mods & KMOD_RGUI) fcitx_mods |= FcitxKeyState_Meta;
+
+ return fcitx_mods;
+}
+
+SDL_bool
+SDL_Fcitx_Init()
+{
+ fcitx_client.dbus = SDL_DBus_GetContext();
+
+ fcitx_client.cursor_rect.x = -1;
+ fcitx_client.cursor_rect.y = -1;
+ fcitx_client.cursor_rect.w = 0;
+ fcitx_client.cursor_rect.h = 0;
+
+ SDL_snprintf(fcitx_client.servicename, IC_NAME_MAX,
+ "%s-%d",
+ FCITX_DBUS_SERVICE, GetDisplayNumber());
+
+ return FcitxClientCreateIC(&fcitx_client);
+}
+
+void
+SDL_Fcitx_Quit()
+{
+ FcitxClientICCallMethod(&fcitx_client, "DestroyIC");
+}
+
+void
+SDL_Fcitx_SetFocus(SDL_bool focused)
+{
+ if (focused) {
+ FcitxClientICCallMethod(&fcitx_client, "FocusIn");
+ } else {
+ FcitxClientICCallMethod(&fcitx_client, "FocusOut");
+ }
+}
+
+void
+SDL_Fcitx_Reset(void)
+{
+ FcitxClientICCallMethod(&fcitx_client, "Reset");
+ FcitxClientICCallMethod(&fcitx_client, "CloseIC");
+}
+
+SDL_bool
+SDL_Fcitx_ProcessKeyEvent(Uint32 keysym, Uint32 keycode)
+{
+ Uint32 state = Fcitx_ModState();
+ Uint32 handled = SDL_FALSE;
+ int type = FCITX_PRESS_KEY;
+ Uint32 event_time = 0;
+
+ if (SDL_DBus_CallMethod(fcitx_client.servicename, fcitx_client.icname, FCITX_IC_DBUS_INTERFACE, "ProcessKeyEvent",
+ DBUS_TYPE_UINT32, &keysym, DBUS_TYPE_UINT32, &keycode, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INT32, &type, DBUS_TYPE_UINT32, &event_time, DBUS_TYPE_INVALID,
+ DBUS_TYPE_INT32, &handled, DBUS_TYPE_INVALID)) {
+ if (handled) {
+ SDL_Fcitx_UpdateTextRect(NULL);
+ return SDL_TRUE;
+ }
+ }
+
+ return SDL_FALSE;
+}
+
+void
+SDL_Fcitx_UpdateTextRect(SDL_Rect *rect)
+{
+ SDL_Window *focused_win = NULL;
+ SDL_SysWMinfo info;
+ int x = 0, y = 0;
+ SDL_Rect *cursor = &fcitx_client.cursor_rect;
+
+ if (rect) {
+ SDL_memcpy(cursor, rect, sizeof(SDL_Rect));
+ }
+
+ focused_win = SDL_GetKeyboardFocus();
+ if (!focused_win) {
+ return ;
+ }
+
+ SDL_VERSION(&info.version);
+ if (!SDL_GetWindowWMInfo(focused_win, &info)) {
+ return;
+ }
+
+ SDL_GetWindowPosition(focused_win, &x, &y);
+
+#if SDL_VIDEO_DRIVER_X11
+ if (info.subsystem == SDL_SYSWM_X11) {
+ SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayForWindow(focused_win)->driverdata;
+
+ Display *x_disp = info.info.x11.display;
+ Window x_win = info.info.x11.window;
+ int x_screen = displaydata->screen;
+ Window unused;
+ X11_XTranslateCoordinates(x_disp, x_win, RootWindow(x_disp, x_screen), 0, 0, &x, &y, &unused);
+ }
+#endif
+
+ if (cursor->x == -1 && cursor->y == -1 && cursor->w == 0 && cursor->h == 0) {
+ /* move to bottom left */
+ int w = 0, h = 0;
+ SDL_GetWindowSize(focused_win, &w, &h);
+ cursor->x = 0;
+ cursor->y = h;
+ }
+
+ x += cursor->x;
+ y += cursor->y;
+
+ SDL_DBus_CallVoidMethod(fcitx_client.servicename, fcitx_client.icname, FCITX_IC_DBUS_INTERFACE, "SetCursorRect",
+ DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y, DBUS_TYPE_INT32, &cursor->w, DBUS_TYPE_INT32, &cursor->h, DBUS_TYPE_INVALID);
+}
+
+void
+SDL_Fcitx_PumpEvents(void)
+{
+ SDL_DBusContext *dbus = fcitx_client.dbus;
+ DBusConnection *conn = dbus->session_conn;
+
+ dbus->connection_read_write(conn, 0);
+
+ while (dbus->connection_dispatch(conn) == DBUS_DISPATCH_DATA_REMAINS) {
+ /* Do nothing, actual work happens in DBus_MessageFilter */
+ usleep(10);
+ }
+}
+
+#endif /* HAVE_FCITX_FRONTEND_H */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/linux/SDL_fcitx.h b/src/3rdparty/SDL2/src/core/linux/SDL_fcitx.h
new file mode 100644
index 0000000..9407cd9
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/linux/SDL_fcitx.h
@@ -0,0 +1,40 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_fcitx_h_
+#define SDL_fcitx_h_
+
+#include "../../SDL_internal.h"
+
+#include "SDL_stdinc.h"
+#include "SDL_rect.h"
+
+extern SDL_bool SDL_Fcitx_Init(void);
+extern void SDL_Fcitx_Quit(void);
+extern void SDL_Fcitx_SetFocus(SDL_bool focused);
+extern void SDL_Fcitx_Reset(void);
+extern SDL_bool SDL_Fcitx_ProcessKeyEvent(Uint32 keysym, Uint32 keycode);
+extern void SDL_Fcitx_UpdateTextRect(SDL_Rect *rect);
+extern void SDL_Fcitx_PumpEvents(void);
+
+#endif /* SDL_fcitx_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/linux/SDL_ibus.c b/src/3rdparty/SDL2/src/core/linux/SDL_ibus.c
new file mode 100644
index 0000000..a9c3197
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/linux/SDL_ibus.c
@@ -0,0 +1,584 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef HAVE_IBUS_IBUS_H
+#include "SDL.h"
+#include "SDL_syswm.h"
+#include "SDL_ibus.h"
+#include "SDL_dbus.h"
+#include "../../video/SDL_sysvideo.h"
+#include "../../events/SDL_keyboard_c.h"
+
+#if SDL_VIDEO_DRIVER_X11
+ #include "../../video/x11/SDL_x11video.h"
+#endif
+
+#include <sys/inotify.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+static const char IBUS_SERVICE[] = "org.freedesktop.IBus";
+static const char IBUS_PATH[] = "/org/freedesktop/IBus";
+static const char IBUS_INTERFACE[] = "org.freedesktop.IBus";
+static const char IBUS_INPUT_INTERFACE[] = "org.freedesktop.IBus.InputContext";
+
+static char *input_ctx_path = NULL;
+static SDL_Rect ibus_cursor_rect = { 0, 0, 0, 0 };
+static DBusConnection *ibus_conn = NULL;
+static char *ibus_addr_file = NULL;
+static int inotify_fd = -1, inotify_wd = -1;
+
+static Uint32
+IBus_ModState(void)
+{
+ Uint32 ibus_mods = 0;
+ SDL_Keymod sdl_mods = SDL_GetModState();
+
+ /* Not sure about MOD3, MOD4 and HYPER mappings */
+ if (sdl_mods & KMOD_LSHIFT) ibus_mods |= IBUS_SHIFT_MASK;
+ if (sdl_mods & KMOD_CAPS) ibus_mods |= IBUS_LOCK_MASK;
+ if (sdl_mods & KMOD_LCTRL) ibus_mods |= IBUS_CONTROL_MASK;
+ if (sdl_mods & KMOD_LALT) ibus_mods |= IBUS_MOD1_MASK;
+ if (sdl_mods & KMOD_NUM) ibus_mods |= IBUS_MOD2_MASK;
+ if (sdl_mods & KMOD_MODE) ibus_mods |= IBUS_MOD5_MASK;
+ if (sdl_mods & KMOD_LGUI) ibus_mods |= IBUS_SUPER_MASK;
+ if (sdl_mods & KMOD_RGUI) ibus_mods |= IBUS_META_MASK;
+
+ return ibus_mods;
+}
+
+static const char *
+IBus_GetVariantText(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext *dbus)
+{
+ /* The text we need is nested weirdly, use dbus-monitor to see the structure better */
+ const char *text = NULL;
+ const char *struct_id = NULL;
+ DBusMessageIter sub1, sub2;
+
+ if (dbus->message_iter_get_arg_type(iter) != DBUS_TYPE_VARIANT) {
+ return NULL;
+ }
+
+ dbus->message_iter_recurse(iter, &sub1);
+
+ if (dbus->message_iter_get_arg_type(&sub1) != DBUS_TYPE_STRUCT) {
+ return NULL;
+ }
+
+ dbus->message_iter_recurse(&sub1, &sub2);
+
+ if (dbus->message_iter_get_arg_type(&sub2) != DBUS_TYPE_STRING) {
+ return NULL;
+ }
+
+ dbus->message_iter_get_basic(&sub2, &struct_id);
+ if (!struct_id || SDL_strncmp(struct_id, "IBusText", sizeof("IBusText")) != 0) {
+ return NULL;
+ }
+
+ dbus->message_iter_next(&sub2);
+ dbus->message_iter_next(&sub2);
+
+ if (dbus->message_iter_get_arg_type(&sub2) != DBUS_TYPE_STRING) {
+ return NULL;
+ }
+
+ dbus->message_iter_get_basic(&sub2, &text);
+
+ return text;
+}
+
+static DBusHandlerResult
+IBus_MessageHandler(DBusConnection *conn, DBusMessage *msg, void *user_data)
+{
+ SDL_DBusContext *dbus = (SDL_DBusContext *)user_data;
+
+ if (dbus->message_is_signal(msg, IBUS_INPUT_INTERFACE, "CommitText")) {
+ DBusMessageIter iter;
+ const char *text;
+
+ dbus->message_iter_init(msg, &iter);
+
+ text = IBus_GetVariantText(conn, &iter, dbus);
+ if (text && *text) {
+ char buf[SDL_TEXTINPUTEVENT_TEXT_SIZE];
+ size_t text_bytes = SDL_strlen(text), i = 0;
+
+ while (i < text_bytes) {
+ size_t sz = SDL_utf8strlcpy(buf, text+i, sizeof(buf));
+ SDL_SendKeyboardText(buf);
+
+ i += sz;
+ }
+ }
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ if (dbus->message_is_signal(msg, IBUS_INPUT_INTERFACE, "UpdatePreeditText")) {
+ DBusMessageIter iter;
+ const char *text;
+
+ dbus->message_iter_init(msg, &iter);
+ text = IBus_GetVariantText(conn, &iter, dbus);
+
+ if (text) {
+ char buf[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
+ size_t text_bytes = SDL_strlen(text), i = 0;
+ size_t cursor = 0;
+
+ do {
+ const size_t sz = SDL_utf8strlcpy(buf, text+i, sizeof(buf));
+ const size_t chars = SDL_utf8strlen(buf);
+
+ SDL_SendEditingText(buf, cursor, chars);
+
+ i += sz;
+ cursor += chars;
+ } while (i < text_bytes);
+ }
+
+ SDL_IBus_UpdateTextRect(NULL);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ if (dbus->message_is_signal(msg, IBUS_INPUT_INTERFACE, "HidePreeditText")) {
+ SDL_SendEditingText("", 0, 0);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static char *
+IBus_ReadAddressFromFile(const char *file_path)
+{
+ char addr_buf[1024];
+ SDL_bool success = SDL_FALSE;
+ FILE *addr_file;
+
+ addr_file = fopen(file_path, "r");
+ if (!addr_file) {
+ return NULL;
+ }
+
+ while (fgets(addr_buf, sizeof(addr_buf), addr_file)) {
+ if (SDL_strncmp(addr_buf, "IBUS_ADDRESS=", sizeof("IBUS_ADDRESS=")-1) == 0) {
+ size_t sz = SDL_strlen(addr_buf);
+ if (addr_buf[sz-1] == '\n') addr_buf[sz-1] = 0;
+ if (addr_buf[sz-2] == '\r') addr_buf[sz-2] = 0;
+ success = SDL_TRUE;
+ break;
+ }
+ }
+
+ fclose(addr_file);
+
+ if (success) {
+ return SDL_strdup(addr_buf + (sizeof("IBUS_ADDRESS=") - 1));
+ } else {
+ return NULL;
+ }
+}
+
+static char *
+IBus_GetDBusAddressFilename(void)
+{
+ SDL_DBusContext *dbus;
+ const char *disp_env;
+ char config_dir[PATH_MAX];
+ char *display = NULL;
+ const char *addr;
+ const char *conf_env;
+ char *key;
+ char file_path[PATH_MAX];
+ const char *host;
+ char *disp_num, *screen_num;
+
+ if (ibus_addr_file) {
+ return SDL_strdup(ibus_addr_file);
+ }
+
+ dbus = SDL_DBus_GetContext();
+ if (!dbus) {
+ return NULL;
+ }
+
+ /* Use this environment variable if it exists. */
+ addr = SDL_getenv("IBUS_ADDRESS");
+ if (addr && *addr) {
+ return SDL_strdup(addr);
+ }
+
+ /* Otherwise, we have to get the hostname, display, machine id, config dir
+ and look up the address from a filepath using all those bits, eek. */
+ disp_env = SDL_getenv("DISPLAY");
+
+ if (!disp_env || !*disp_env) {
+ display = SDL_strdup(":0.0");
+ } else {
+ display = SDL_strdup(disp_env);
+ }
+
+ host = display;
+ disp_num = SDL_strrchr(display, ':');
+ screen_num = SDL_strrchr(display, '.');
+
+ if (!disp_num) {
+ SDL_free(display);
+ return NULL;
+ }
+
+ *disp_num = 0;
+ disp_num++;
+
+ if (screen_num) {
+ *screen_num = 0;
+ }
+
+ if (!*host) {
+ host = "unix";
+ }
+
+ SDL_memset(config_dir, 0, sizeof(config_dir));
+
+ conf_env = SDL_getenv("XDG_CONFIG_HOME");
+ if (conf_env && *conf_env) {
+ SDL_strlcpy(config_dir, conf_env, sizeof(config_dir));
+ } else {
+ const char *home_env = SDL_getenv("HOME");
+ if (!home_env || !*home_env) {
+ SDL_free(display);
+ return NULL;
+ }
+ SDL_snprintf(config_dir, sizeof(config_dir), "%s/.config", home_env);
+ }
+
+ key = dbus->get_local_machine_id();
+
+ SDL_memset(file_path, 0, sizeof(file_path));
+ SDL_snprintf(file_path, sizeof(file_path), "%s/ibus/bus/%s-%s-%s",
+ config_dir, key, host, disp_num);
+ dbus->free(key);
+ SDL_free(display);
+
+ return SDL_strdup(file_path);
+}
+
+static SDL_bool IBus_CheckConnection(SDL_DBusContext *dbus);
+
+static void SDLCALL
+IBus_SetCapabilities(void *data, const char *name, const char *old_val,
+ const char *internal_editing)
+{
+ SDL_DBusContext *dbus = SDL_DBus_GetContext();
+
+ if (IBus_CheckConnection(dbus)) {
+ Uint32 caps = IBUS_CAP_FOCUS;
+ if (!(internal_editing && *internal_editing == '1')) {
+ caps |= IBUS_CAP_PREEDIT_TEXT;
+ }
+
+ SDL_DBus_CallVoidMethodOnConnection(ibus_conn, IBUS_SERVICE, input_ctx_path, IBUS_INPUT_INTERFACE, "SetCapabilities",
+ DBUS_TYPE_UINT32, &caps, DBUS_TYPE_INVALID);
+ }
+}
+
+
+static SDL_bool
+IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr)
+{
+ const char *client_name = "SDL2_Application";
+ const char *path = NULL;
+ SDL_bool result = SDL_FALSE;
+ DBusObjectPathVTable ibus_vtable;
+
+ SDL_zero(ibus_vtable);
+ ibus_vtable.message_function = &IBus_MessageHandler;
+
+ ibus_conn = dbus->connection_open_private(addr, NULL);
+
+ if (!ibus_conn) {
+ return SDL_FALSE;
+ }
+
+ dbus->connection_flush(ibus_conn);
+
+ if (!dbus->bus_register(ibus_conn, NULL)) {
+ ibus_conn = NULL;
+ return SDL_FALSE;
+ }
+
+ dbus->connection_flush(ibus_conn);
+
+ if (SDL_DBus_CallMethodOnConnection(ibus_conn, IBUS_SERVICE, IBUS_PATH, IBUS_INTERFACE, "CreateInputContext",
+ DBUS_TYPE_STRING, &client_name, DBUS_TYPE_INVALID,
+ DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) {
+ SDL_free(input_ctx_path);
+ input_ctx_path = SDL_strdup(path);
+ SDL_AddHintCallback(SDL_HINT_IME_INTERNAL_EDITING, IBus_SetCapabilities, NULL);
+
+ dbus->bus_add_match(ibus_conn, "type='signal',interface='org.freedesktop.IBus.InputContext'", NULL);
+ dbus->connection_try_register_object_path(ibus_conn, input_ctx_path, &ibus_vtable, dbus, NULL);
+ dbus->connection_flush(ibus_conn);
+ result = SDL_TRUE;
+ }
+
+ SDL_IBus_SetFocus(SDL_GetKeyboardFocus() != NULL);
+ SDL_IBus_UpdateTextRect(NULL);
+
+ return result;
+}
+
+static SDL_bool
+IBus_CheckConnection(SDL_DBusContext *dbus)
+{
+ if (!dbus) return SDL_FALSE;
+
+ if (ibus_conn && dbus->connection_get_is_connected(ibus_conn)) {
+ return SDL_TRUE;
+ }
+
+ if (inotify_fd > 0 && inotify_wd > 0) {
+ char buf[1024];
+ ssize_t readsize = read(inotify_fd, buf, sizeof(buf));
+ if (readsize > 0) {
+
+ char *p;
+ SDL_bool file_updated = SDL_FALSE;
+
+ for (p = buf; p < buf + readsize; /**/) {
+ struct inotify_event *event = (struct inotify_event*) p;
+ if (event->len > 0) {
+ char *addr_file_no_path = SDL_strrchr(ibus_addr_file, '/');
+ if (!addr_file_no_path) return SDL_FALSE;
+
+ if (SDL_strcmp(addr_file_no_path + 1, event->name) == 0) {
+ file_updated = SDL_TRUE;
+ break;
+ }
+ }
+
+ p += sizeof(struct inotify_event) + event->len;
+ }
+
+ if (file_updated) {
+ char *addr = IBus_ReadAddressFromFile(ibus_addr_file);
+ if (addr) {
+ SDL_bool result = IBus_SetupConnection(dbus, addr);
+ SDL_free(addr);
+ return result;
+ }
+ }
+ }
+ }
+
+ return SDL_FALSE;
+}
+
+SDL_bool
+SDL_IBus_Init(void)
+{
+ SDL_bool result = SDL_FALSE;
+ SDL_DBusContext *dbus = SDL_DBus_GetContext();
+
+ if (dbus) {
+ char *addr_file = IBus_GetDBusAddressFilename();
+ char *addr;
+ char *addr_file_dir;
+
+ if (!addr_file) {
+ return SDL_FALSE;
+ }
+
+ /* !!! FIXME: if ibus_addr_file != NULL, this will overwrite it and leak (twice!) */
+ ibus_addr_file = SDL_strdup(addr_file);
+
+ addr = IBus_ReadAddressFromFile(addr_file);
+ if (!addr) {
+ SDL_free(addr_file);
+ return SDL_FALSE;
+ }
+
+ if (inotify_fd < 0) {
+ inotify_fd = inotify_init();
+ fcntl(inotify_fd, F_SETFL, O_NONBLOCK);
+ }
+
+ addr_file_dir = SDL_strrchr(addr_file, '/');
+ if (addr_file_dir) {
+ *addr_file_dir = 0;
+ }
+
+ inotify_wd = inotify_add_watch(inotify_fd, addr_file, IN_CREATE | IN_MODIFY);
+ SDL_free(addr_file);
+
+ if (addr) {
+ result = IBus_SetupConnection(dbus, addr);
+ SDL_free(addr);
+ }
+ }
+
+ return result;
+}
+
+void
+SDL_IBus_Quit(void)
+{
+ SDL_DBusContext *dbus;
+
+ if (input_ctx_path) {
+ SDL_free(input_ctx_path);
+ input_ctx_path = NULL;
+ }
+
+ if (ibus_addr_file) {
+ SDL_free(ibus_addr_file);
+ ibus_addr_file = NULL;
+ }
+
+ dbus = SDL_DBus_GetContext();
+
+ if (dbus && ibus_conn) {
+ dbus->connection_close(ibus_conn);
+ dbus->connection_unref(ibus_conn);
+ }
+
+ if (inotify_fd > 0 && inotify_wd > 0) {
+ inotify_rm_watch(inotify_fd, inotify_wd);
+ inotify_wd = -1;
+ }
+
+ SDL_DelHintCallback(SDL_HINT_IME_INTERNAL_EDITING, IBus_SetCapabilities, NULL);
+
+ SDL_memset(&ibus_cursor_rect, 0, sizeof(ibus_cursor_rect));
+}
+
+static void
+IBus_SimpleMessage(const char *method)
+{
+ SDL_DBusContext *dbus = SDL_DBus_GetContext();
+
+ if (IBus_CheckConnection(dbus)) {
+ SDL_DBus_CallVoidMethodOnConnection(ibus_conn, IBUS_SERVICE, input_ctx_path, IBUS_INPUT_INTERFACE, method, DBUS_TYPE_INVALID);
+ }
+}
+
+void
+SDL_IBus_SetFocus(SDL_bool focused)
+{
+ const char *method = focused ? "FocusIn" : "FocusOut";
+ IBus_SimpleMessage(method);
+}
+
+void
+SDL_IBus_Reset(void)
+{
+ IBus_SimpleMessage("Reset");
+}
+
+SDL_bool
+SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode)
+{
+ Uint32 result = 0;
+ SDL_DBusContext *dbus = SDL_DBus_GetContext();
+
+ if (IBus_CheckConnection(dbus)) {
+ Uint32 mods = IBus_ModState();
+ if (!SDL_DBus_CallMethodOnConnection(ibus_conn, IBUS_SERVICE, input_ctx_path, IBUS_INPUT_INTERFACE, "ProcessKeyEvent",
+ DBUS_TYPE_UINT32, &keysym, DBUS_TYPE_UINT32, &keycode, DBUS_TYPE_UINT32, &mods, DBUS_TYPE_INVALID,
+ DBUS_TYPE_BOOLEAN, &result, DBUS_TYPE_INVALID)) {
+ result = 0;
+ }
+ }
+
+ SDL_IBus_UpdateTextRect(NULL);
+
+ return result ? SDL_TRUE : SDL_FALSE;
+}
+
+void
+SDL_IBus_UpdateTextRect(SDL_Rect *rect)
+{
+ SDL_Window *focused_win;
+ SDL_SysWMinfo info;
+ int x = 0, y = 0;
+ SDL_DBusContext *dbus;
+
+ if (rect) {
+ SDL_memcpy(&ibus_cursor_rect, rect, sizeof(ibus_cursor_rect));
+ }
+
+ focused_win = SDL_GetKeyboardFocus();
+ if (!focused_win) {
+ return;
+ }
+
+ SDL_VERSION(&info.version);
+ if (!SDL_GetWindowWMInfo(focused_win, &info)) {
+ return;
+ }
+
+ SDL_GetWindowPosition(focused_win, &x, &y);
+
+#if SDL_VIDEO_DRIVER_X11
+ if (info.subsystem == SDL_SYSWM_X11) {
+ SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayForWindow(focused_win)->driverdata;
+
+ Display *x_disp = info.info.x11.display;
+ Window x_win = info.info.x11.window;
+ int x_screen = displaydata->screen;
+ Window unused;
+
+ X11_XTranslateCoordinates(x_disp, x_win, RootWindow(x_disp, x_screen), 0, 0, &x, &y, &unused);
+ }
+#endif
+
+ x += ibus_cursor_rect.x;
+ y += ibus_cursor_rect.y;
+
+ dbus = SDL_DBus_GetContext();
+
+ if (IBus_CheckConnection(dbus)) {
+ SDL_DBus_CallVoidMethodOnConnection(ibus_conn, IBUS_SERVICE, input_ctx_path, IBUS_INPUT_INTERFACE, "SetCursorLocation",
+ DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y, DBUS_TYPE_INT32, &ibus_cursor_rect.w, DBUS_TYPE_INT32, &ibus_cursor_rect.h, DBUS_TYPE_INVALID);
+ }
+}
+
+void
+SDL_IBus_PumpEvents(void)
+{
+ SDL_DBusContext *dbus = SDL_DBus_GetContext();
+
+ if (IBus_CheckConnection(dbus)) {
+ dbus->connection_read_write(ibus_conn, 0);
+
+ while (dbus->connection_dispatch(ibus_conn) == DBUS_DISPATCH_DATA_REMAINS) {
+ /* Do nothing, actual work happens in IBus_MessageHandler */
+ }
+ }
+}
+
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/linux/SDL_ibus.h b/src/3rdparty/SDL2/src/core/linux/SDL_ibus.h
new file mode 100644
index 0000000..d533ff7
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/linux/SDL_ibus.h
@@ -0,0 +1,58 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_ibus_h_
+#define SDL_ibus_h_
+
+#ifdef HAVE_IBUS_IBUS_H
+#define SDL_USE_IBUS 1
+#include "SDL_stdinc.h"
+#include <ibus-1.0/ibus.h>
+
+extern SDL_bool SDL_IBus_Init(void);
+extern void SDL_IBus_Quit(void);
+
+/* Lets the IBus server know about changes in window focus */
+extern void SDL_IBus_SetFocus(SDL_bool focused);
+
+/* Closes the candidate list and resets any text currently being edited */
+extern void SDL_IBus_Reset(void);
+
+/* Sends a keypress event to IBus, returns SDL_TRUE if IBus used this event to
+ update its candidate list or change input methods. PumpEvents should be
+ called some time after this, to recieve the TextInput / TextEditing event back. */
+extern SDL_bool SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode);
+
+/* Update the position of IBus' candidate list. If rect is NULL then this will
+ just reposition it relative to the focused window's new position. */
+extern void SDL_IBus_UpdateTextRect(SDL_Rect *window_relative_rect);
+
+/* Checks DBus for new IBus events, and calls SDL_SendKeyboardText /
+ SDL_SendEditingText for each event it finds */
+extern void SDL_IBus_PumpEvents(void);
+
+#endif /* HAVE_IBUS_IBUS_H */
+
+#endif /* SDL_ibus_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/linux/SDL_ime.c b/src/3rdparty/SDL2/src/core/linux/SDL_ime.c
new file mode 100644
index 0000000..29b0182
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/linux/SDL_ime.c
@@ -0,0 +1,152 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "SDL_ime.h"
+#include "SDL_ibus.h"
+#include "SDL_fcitx.h"
+
+typedef SDL_bool (*_SDL_IME_Init)();
+typedef void (*_SDL_IME_Quit)();
+typedef void (*_SDL_IME_SetFocus)(SDL_bool);
+typedef void (*_SDL_IME_Reset)();
+typedef SDL_bool (*_SDL_IME_ProcessKeyEvent)(Uint32, Uint32);
+typedef void (*_SDL_IME_UpdateTextRect)(SDL_Rect *);
+typedef void (*_SDL_IME_PumpEvents)();
+
+static _SDL_IME_Init SDL_IME_Init_Real = NULL;
+static _SDL_IME_Quit SDL_IME_Quit_Real = NULL;
+static _SDL_IME_SetFocus SDL_IME_SetFocus_Real = NULL;
+static _SDL_IME_Reset SDL_IME_Reset_Real = NULL;
+static _SDL_IME_ProcessKeyEvent SDL_IME_ProcessKeyEvent_Real = NULL;
+static _SDL_IME_UpdateTextRect SDL_IME_UpdateTextRect_Real = NULL;
+static _SDL_IME_PumpEvents SDL_IME_PumpEvents_Real = NULL;
+
+static void
+InitIME()
+{
+ static SDL_bool inited = SDL_FALSE;
+#ifdef HAVE_FCITX_FRONTEND_H
+ const char *im_module = SDL_getenv("SDL_IM_MODULE");
+ const char *xmodifiers = SDL_getenv("XMODIFIERS");
+#endif
+
+ if (inited == SDL_TRUE)
+ return;
+
+ inited = SDL_TRUE;
+
+ /* See if fcitx IME support is being requested */
+#ifdef HAVE_FCITX_FRONTEND_H
+ if (!SDL_IME_Init_Real &&
+ ((im_module && SDL_strcmp(im_module, "fcitx") == 0) ||
+ (!im_module && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) {
+ SDL_IME_Init_Real = SDL_Fcitx_Init;
+ SDL_IME_Quit_Real = SDL_Fcitx_Quit;
+ SDL_IME_SetFocus_Real = SDL_Fcitx_SetFocus;
+ SDL_IME_Reset_Real = SDL_Fcitx_Reset;
+ SDL_IME_ProcessKeyEvent_Real = SDL_Fcitx_ProcessKeyEvent;
+ SDL_IME_UpdateTextRect_Real = SDL_Fcitx_UpdateTextRect;
+ SDL_IME_PumpEvents_Real = SDL_Fcitx_PumpEvents;
+ }
+#endif /* HAVE_FCITX_FRONTEND_H */
+
+ /* default to IBus */
+#ifdef HAVE_IBUS_IBUS_H
+ if (!SDL_IME_Init_Real) {
+ SDL_IME_Init_Real = SDL_IBus_Init;
+ SDL_IME_Quit_Real = SDL_IBus_Quit;
+ SDL_IME_SetFocus_Real = SDL_IBus_SetFocus;
+ SDL_IME_Reset_Real = SDL_IBus_Reset;
+ SDL_IME_ProcessKeyEvent_Real = SDL_IBus_ProcessKeyEvent;
+ SDL_IME_UpdateTextRect_Real = SDL_IBus_UpdateTextRect;
+ SDL_IME_PumpEvents_Real = SDL_IBus_PumpEvents;
+ }
+#endif /* HAVE_IBUS_IBUS_H */
+}
+
+SDL_bool
+SDL_IME_Init(void)
+{
+ InitIME();
+
+ if (SDL_IME_Init_Real) {
+ if (SDL_IME_Init_Real()) {
+ return SDL_TRUE;
+ }
+
+ /* uhoh, the IME implementation's init failed! Disable IME support. */
+ SDL_IME_Init_Real = NULL;
+ SDL_IME_Quit_Real = NULL;
+ SDL_IME_SetFocus_Real = NULL;
+ SDL_IME_Reset_Real = NULL;
+ SDL_IME_ProcessKeyEvent_Real = NULL;
+ SDL_IME_UpdateTextRect_Real = NULL;
+ SDL_IME_PumpEvents_Real = NULL;
+ }
+
+ return SDL_FALSE;
+}
+
+void
+SDL_IME_Quit(void)
+{
+ if (SDL_IME_Quit_Real)
+ SDL_IME_Quit_Real();
+}
+
+void
+SDL_IME_SetFocus(SDL_bool focused)
+{
+ if (SDL_IME_SetFocus_Real)
+ SDL_IME_SetFocus_Real(focused);
+}
+
+void
+SDL_IME_Reset(void)
+{
+ if (SDL_IME_Reset_Real)
+ SDL_IME_Reset_Real();
+}
+
+SDL_bool
+SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode)
+{
+ if (SDL_IME_ProcessKeyEvent_Real)
+ return SDL_IME_ProcessKeyEvent_Real(keysym, keycode);
+
+ return SDL_FALSE;
+}
+
+void
+SDL_IME_UpdateTextRect(SDL_Rect *rect)
+{
+ if (SDL_IME_UpdateTextRect_Real)
+ SDL_IME_UpdateTextRect_Real(rect);
+}
+
+void
+SDL_IME_PumpEvents()
+{
+ if (SDL_IME_PumpEvents_Real)
+ SDL_IME_PumpEvents_Real();
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/linux/SDL_ime.h b/src/3rdparty/SDL2/src/core/linux/SDL_ime.h
new file mode 100644
index 0000000..e39839c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/linux/SDL_ime.h
@@ -0,0 +1,40 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_ime_h_
+#define SDL_ime_h_
+
+#include "../../SDL_internal.h"
+
+#include "SDL_stdinc.h"
+#include "SDL_rect.h"
+
+extern SDL_bool SDL_IME_Init(void);
+extern void SDL_IME_Quit(void);
+extern void SDL_IME_SetFocus(SDL_bool focused);
+extern void SDL_IME_Reset(void);
+extern SDL_bool SDL_IME_ProcessKeyEvent(Uint32 keysym, Uint32 keycode);
+extern void SDL_IME_UpdateTextRect(SDL_Rect *rect);
+extern void SDL_IME_PumpEvents(void);
+
+#endif /* SDL_ime_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/linux/SDL_udev.c b/src/3rdparty/SDL2/src/core/linux/SDL_udev.c
new file mode 100644
index 0000000..dfbeb79
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/linux/SDL_udev.c
@@ -0,0 +1,553 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ * To list the properties of a device, try something like:
+ * udevadm info -a -n snd/hwC0D0 (for a sound card)
+ * udevadm info --query=all -n input/event3 (for a keyboard, mouse, etc)
+ * udevadm info --query=property -n input/event2
+ */
+#include "SDL_udev.h"
+
+#ifdef SDL_USE_LIBUDEV
+
+#include <linux/input.h>
+
+#include "SDL_assert.h"
+#include "SDL_loadso.h"
+#include "SDL_timer.h"
+#include "../unix/SDL_poll.h"
+
+static const char *SDL_UDEV_LIBS[] = { "libudev.so.1", "libudev.so.0" };
+
+#define _THIS SDL_UDEV_PrivateData *_this
+static _THIS = NULL;
+
+static SDL_bool SDL_UDEV_load_sym(const char *fn, void **addr);
+static int SDL_UDEV_load_syms(void);
+static SDL_bool SDL_UDEV_hotplug_update_available(void);
+static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev);
+
+static SDL_bool
+SDL_UDEV_load_sym(const char *fn, void **addr)
+{
+ *addr = SDL_LoadFunction(_this->udev_handle, fn);
+ if (*addr == NULL) {
+ /* Don't call SDL_SetError(): SDL_LoadFunction already did. */
+ return SDL_FALSE;
+ }
+
+ return SDL_TRUE;
+}
+
+static int
+SDL_UDEV_load_syms(void)
+{
+ /* cast funcs to char* first, to please GCC's strict aliasing rules. */
+ #define SDL_UDEV_SYM(x) \
+ if (!SDL_UDEV_load_sym(#x, (void **) (char *) & _this->x)) return -1
+
+ SDL_UDEV_SYM(udev_device_get_action);
+ SDL_UDEV_SYM(udev_device_get_devnode);
+ SDL_UDEV_SYM(udev_device_get_subsystem);
+ SDL_UDEV_SYM(udev_device_get_parent_with_subsystem_devtype);
+ SDL_UDEV_SYM(udev_device_get_property_value);
+ SDL_UDEV_SYM(udev_device_get_sysattr_value);
+ SDL_UDEV_SYM(udev_device_new_from_syspath);
+ SDL_UDEV_SYM(udev_device_unref);
+ SDL_UDEV_SYM(udev_enumerate_add_match_property);
+ SDL_UDEV_SYM(udev_enumerate_add_match_subsystem);
+ SDL_UDEV_SYM(udev_enumerate_get_list_entry);
+ SDL_UDEV_SYM(udev_enumerate_new);
+ SDL_UDEV_SYM(udev_enumerate_scan_devices);
+ SDL_UDEV_SYM(udev_enumerate_unref);
+ SDL_UDEV_SYM(udev_list_entry_get_name);
+ SDL_UDEV_SYM(udev_list_entry_get_next);
+ SDL_UDEV_SYM(udev_monitor_enable_receiving);
+ SDL_UDEV_SYM(udev_monitor_filter_add_match_subsystem_devtype);
+ SDL_UDEV_SYM(udev_monitor_get_fd);
+ SDL_UDEV_SYM(udev_monitor_new_from_netlink);
+ SDL_UDEV_SYM(udev_monitor_receive_device);
+ SDL_UDEV_SYM(udev_monitor_unref);
+ SDL_UDEV_SYM(udev_new);
+ SDL_UDEV_SYM(udev_unref);
+ SDL_UDEV_SYM(udev_device_new_from_devnum);
+ SDL_UDEV_SYM(udev_device_get_devnum);
+ #undef SDL_UDEV_SYM
+
+ return 0;
+}
+
+static SDL_bool
+SDL_UDEV_hotplug_update_available(void)
+{
+ if (_this->udev_mon != NULL) {
+ const int fd = _this->udev_monitor_get_fd(_this->udev_mon);
+ if (SDL_IOReady(fd, SDL_FALSE, 0)) {
+ return SDL_TRUE;
+ }
+ }
+ return SDL_FALSE;
+}
+
+
+int
+SDL_UDEV_Init(void)
+{
+ int retval = 0;
+
+ if (_this == NULL) {
+ _this = (SDL_UDEV_PrivateData *) SDL_calloc(1, sizeof(*_this));
+ if(_this == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ retval = SDL_UDEV_LoadLibrary();
+ if (retval < 0) {
+ SDL_UDEV_Quit();
+ return retval;
+ }
+
+ /* Set up udev monitoring
+ * Listen for input devices (mouse, keyboard, joystick, etc) and sound devices
+ */
+
+ _this->udev = _this->udev_new();
+ if (_this->udev == NULL) {
+ SDL_UDEV_Quit();
+ return SDL_SetError("udev_new() failed");
+ }
+
+ _this->udev_mon = _this->udev_monitor_new_from_netlink(_this->udev, "udev");
+ if (_this->udev_mon == NULL) {
+ SDL_UDEV_Quit();
+ return SDL_SetError("udev_monitor_new_from_netlink() failed");
+ }
+
+ _this->udev_monitor_filter_add_match_subsystem_devtype(_this->udev_mon, "input", NULL);
+ _this->udev_monitor_filter_add_match_subsystem_devtype(_this->udev_mon, "sound", NULL);
+ _this->udev_monitor_enable_receiving(_this->udev_mon);
+
+ /* Do an initial scan of existing devices */
+ SDL_UDEV_Scan();
+
+ }
+
+ _this->ref_count += 1;
+
+ return retval;
+}
+
+void
+SDL_UDEV_Quit(void)
+{
+ SDL_UDEV_CallbackList *item;
+
+ if (_this == NULL) {
+ return;
+ }
+
+ _this->ref_count -= 1;
+
+ if (_this->ref_count < 1) {
+
+ if (_this->udev_mon != NULL) {
+ _this->udev_monitor_unref(_this->udev_mon);
+ _this->udev_mon = NULL;
+ }
+ if (_this->udev != NULL) {
+ _this->udev_unref(_this->udev);
+ _this->udev = NULL;
+ }
+
+ /* Remove existing devices */
+ while (_this->first != NULL) {
+ item = _this->first;
+ _this->first = _this->first->next;
+ SDL_free(item);
+ }
+
+ SDL_UDEV_UnloadLibrary();
+ SDL_free(_this);
+ _this = NULL;
+ }
+}
+
+void
+SDL_UDEV_Scan(void)
+{
+ struct udev_enumerate *enumerate = NULL;
+ struct udev_list_entry *devs = NULL;
+ struct udev_list_entry *item = NULL;
+
+ if (_this == NULL) {
+ return;
+ }
+
+ enumerate = _this->udev_enumerate_new(_this->udev);
+ if (enumerate == NULL) {
+ SDL_UDEV_Quit();
+ SDL_SetError("udev_enumerate_new() failed");
+ return;
+ }
+
+ _this->udev_enumerate_add_match_subsystem(enumerate, "input");
+ _this->udev_enumerate_add_match_subsystem(enumerate, "sound");
+
+ _this->udev_enumerate_scan_devices(enumerate);
+ devs = _this->udev_enumerate_get_list_entry(enumerate);
+ for (item = devs; item; item = _this->udev_list_entry_get_next(item)) {
+ const char *path = _this->udev_list_entry_get_name(item);
+ struct udev_device *dev = _this->udev_device_new_from_syspath(_this->udev, path);
+ if (dev != NULL) {
+ device_event(SDL_UDEV_DEVICEADDED, dev);
+ _this->udev_device_unref(dev);
+ }
+ }
+
+ _this->udev_enumerate_unref(enumerate);
+}
+
+
+void
+SDL_UDEV_UnloadLibrary(void)
+{
+ if (_this == NULL) {
+ return;
+ }
+
+ if (_this->udev_handle != NULL) {
+ SDL_UnloadObject(_this->udev_handle);
+ _this->udev_handle = NULL;
+ }
+}
+
+int
+SDL_UDEV_LoadLibrary(void)
+{
+ int retval = 0, i;
+
+ if (_this == NULL) {
+ return SDL_SetError("UDEV not initialized");
+ }
+
+ /* See if there is a udev library already loaded */
+ if (SDL_UDEV_load_syms() == 0) {
+ return 0;
+ }
+
+#ifdef SDL_UDEV_DYNAMIC
+ /* Check for the build environment's libudev first */
+ if (_this->udev_handle == NULL) {
+ _this->udev_handle = SDL_LoadObject(SDL_UDEV_DYNAMIC);
+ if (_this->udev_handle != NULL) {
+ retval = SDL_UDEV_load_syms();
+ if (retval < 0) {
+ SDL_UDEV_UnloadLibrary();
+ }
+ }
+ }
+#endif
+
+ if (_this->udev_handle == NULL) {
+ for( i = 0 ; i < SDL_arraysize(SDL_UDEV_LIBS); i++) {
+ _this->udev_handle = SDL_LoadObject(SDL_UDEV_LIBS[i]);
+ if (_this->udev_handle != NULL) {
+ retval = SDL_UDEV_load_syms();
+ if (retval < 0) {
+ SDL_UDEV_UnloadLibrary();
+ }
+ else {
+ break;
+ }
+ }
+ }
+
+ if (_this->udev_handle == NULL) {
+ retval = -1;
+ /* Don't call SDL_SetError(): SDL_LoadObject already did. */
+ }
+ }
+
+ return retval;
+}
+
+#define BITS_PER_LONG (sizeof(unsigned long) * 8)
+#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
+#define OFF(x) ((x)%BITS_PER_LONG)
+#define LONG(x) ((x)/BITS_PER_LONG)
+#define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
+
+static void get_caps(struct udev_device *dev, struct udev_device *pdev, const char *attr, unsigned long *bitmask, size_t bitmask_len)
+{
+ const char *value;
+ char text[4096];
+ char *word;
+ int i;
+ unsigned long v;
+
+ SDL_memset(bitmask, 0, bitmask_len*sizeof(*bitmask));
+ value = _this->udev_device_get_sysattr_value(pdev, attr);
+ if (!value) {
+ return;
+ }
+
+ SDL_strlcpy(text, value, sizeof(text));
+ i = 0;
+ while ((word = SDL_strrchr(text, ' ')) != NULL) {
+ v = SDL_strtoul(word+1, NULL, 16);
+ if (i < bitmask_len) {
+ bitmask[i] = v;
+ }
+ ++i;
+ *word = '\0';
+ }
+ v = SDL_strtoul(text, NULL, 16);
+ if (i < bitmask_len) {
+ bitmask[i] = v;
+ }
+}
+
+static int
+guess_device_class(struct udev_device *dev)
+{
+ int devclass = 0;
+ struct udev_device *pdev;
+ unsigned long bitmask_ev[NBITS(EV_MAX)];
+ unsigned long bitmask_abs[NBITS(ABS_MAX)];
+ unsigned long bitmask_key[NBITS(KEY_MAX)];
+ unsigned long bitmask_rel[NBITS(REL_MAX)];
+ unsigned long keyboard_mask;
+
+ /* walk up the parental chain until we find the real input device; the
+ * argument is very likely a subdevice of this, like eventN */
+ pdev = dev;
+ while (pdev && !_this->udev_device_get_sysattr_value(pdev, "capabilities/ev")) {
+ pdev = _this->udev_device_get_parent_with_subsystem_devtype(pdev, "input", NULL);
+ }
+ if (!pdev) {
+ return 0;
+ }
+
+ get_caps(dev, pdev, "capabilities/ev", bitmask_ev, SDL_arraysize(bitmask_ev));
+ get_caps(dev, pdev, "capabilities/abs", bitmask_abs, SDL_arraysize(bitmask_abs));
+ get_caps(dev, pdev, "capabilities/rel", bitmask_rel, SDL_arraysize(bitmask_rel));
+ get_caps(dev, pdev, "capabilities/key", bitmask_key, SDL_arraysize(bitmask_key));
+
+ if (test_bit(EV_ABS, bitmask_ev) &&
+ test_bit(ABS_X, bitmask_abs) && test_bit(ABS_Y, bitmask_abs)) {
+ if (test_bit(BTN_STYLUS, bitmask_key) || test_bit(BTN_TOOL_PEN, bitmask_key)) {
+ ; /* ID_INPUT_TABLET */
+ } else if (test_bit(BTN_TOOL_FINGER, bitmask_key) && !test_bit(BTN_TOOL_PEN, bitmask_key)) {
+ ; /* ID_INPUT_TOUCHPAD */
+ } else if (test_bit(BTN_MOUSE, bitmask_key)) {
+ devclass |= SDL_UDEV_DEVICE_MOUSE; /* ID_INPUT_MOUSE */
+ } else if (test_bit(BTN_TOUCH, bitmask_key)) {
+ /* TODO: better determining between touchscreen and multitouch touchpad,
+ see https://github.com/systemd/systemd/blob/master/src/udev/udev-builtin-input_id.c */
+ devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN; /* ID_INPUT_TOUCHSCREEN */
+ }
+
+ if (test_bit(BTN_TRIGGER, bitmask_key) ||
+ test_bit(BTN_A, bitmask_key) ||
+ test_bit(BTN_1, bitmask_key) ||
+ test_bit(ABS_RX, bitmask_abs) ||
+ test_bit(ABS_RY, bitmask_abs) ||
+ test_bit(ABS_RZ, bitmask_abs) ||
+ test_bit(ABS_THROTTLE, bitmask_abs) ||
+ test_bit(ABS_RUDDER, bitmask_abs) ||
+ test_bit(ABS_WHEEL, bitmask_abs) ||
+ test_bit(ABS_GAS, bitmask_abs) ||
+ test_bit(ABS_BRAKE, bitmask_abs)) {
+ devclass |= SDL_UDEV_DEVICE_JOYSTICK; /* ID_INPUT_JOYSTICK */
+ }
+ }
+
+ if (test_bit(EV_REL, bitmask_ev) &&
+ test_bit(REL_X, bitmask_rel) && test_bit(REL_Y, bitmask_rel) &&
+ test_bit(BTN_MOUSE, bitmask_key)) {
+ devclass |= SDL_UDEV_DEVICE_MOUSE; /* ID_INPUT_MOUSE */
+ }
+
+ /* the first 32 bits are ESC, numbers, and Q to D; if we have any of
+ * those, consider it a keyboard device; do not test KEY_RESERVED, though */
+ keyboard_mask = 0xFFFFFFFE;
+ if ((bitmask_key[0] & keyboard_mask) != 0)
+ devclass |= SDL_UDEV_DEVICE_KEYBOARD; /* ID_INPUT_KEYBOARD */
+
+ return devclass;
+}
+
+static void
+device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
+{
+ const char *subsystem;
+ const char *val = NULL;
+ int devclass = 0;
+ const char *path;
+ SDL_UDEV_CallbackList *item;
+
+ path = _this->udev_device_get_devnode(dev);
+ if (path == NULL) {
+ return;
+ }
+
+ subsystem = _this->udev_device_get_subsystem(dev);
+ if (SDL_strcmp(subsystem, "sound") == 0) {
+ devclass = SDL_UDEV_DEVICE_SOUND;
+ } else if (SDL_strcmp(subsystem, "input") == 0) {
+ /* udev rules reference: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c */
+
+ val = _this->udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK");
+ if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
+ devclass |= SDL_UDEV_DEVICE_JOYSTICK;
+ }
+
+ val = _this->udev_device_get_property_value(dev, "ID_INPUT_MOUSE");
+ if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
+ devclass |= SDL_UDEV_DEVICE_MOUSE;
+ }
+
+ val = _this->udev_device_get_property_value(dev, "ID_INPUT_TOUCHSCREEN");
+ if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
+ devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN;
+ }
+
+ /* The undocumented rule is:
+ - All devices with keys get ID_INPUT_KEY
+ - From this subset, if they have ESC, numbers, and Q to D, it also gets ID_INPUT_KEYBOARD
+
+ Ref: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c#n183
+ */
+ val = _this->udev_device_get_property_value(dev, "ID_INPUT_KEY");
+ if (val != NULL && SDL_strcmp(val, "1") == 0 ) {
+ devclass |= SDL_UDEV_DEVICE_KEYBOARD;
+ }
+
+ if (devclass == 0) {
+ /* Fall back to old style input classes */
+ val = _this->udev_device_get_property_value(dev, "ID_CLASS");
+ if (val != NULL) {
+ if (SDL_strcmp(val, "joystick") == 0) {
+ devclass = SDL_UDEV_DEVICE_JOYSTICK;
+ } else if (SDL_strcmp(val, "mouse") == 0) {
+ devclass = SDL_UDEV_DEVICE_MOUSE;
+ } else if (SDL_strcmp(val, "kbd") == 0) {
+ devclass = SDL_UDEV_DEVICE_KEYBOARD;
+ } else {
+ return;
+ }
+ } else {
+ /* We could be linked with libudev on a system that doesn't have udev running */
+ devclass = guess_device_class(dev);
+ }
+ }
+ } else {
+ return;
+ }
+
+ /* Process callbacks */
+ for (item = _this->first; item != NULL; item = item->next) {
+ item->callback(type, devclass, path);
+ }
+}
+
+void
+SDL_UDEV_Poll(void)
+{
+ struct udev_device *dev = NULL;
+ const char *action = NULL;
+
+ if (_this == NULL) {
+ return;
+ }
+
+ while (SDL_UDEV_hotplug_update_available()) {
+ dev = _this->udev_monitor_receive_device(_this->udev_mon);
+ if (dev == NULL) {
+ break;
+ }
+ action = _this->udev_device_get_action(dev);
+
+ if (SDL_strcmp(action, "add") == 0) {
+ /* Wait for the device to finish initialization */
+ SDL_Delay(100);
+
+ device_event(SDL_UDEV_DEVICEADDED, dev);
+ } else if (SDL_strcmp(action, "remove") == 0) {
+ device_event(SDL_UDEV_DEVICEREMOVED, dev);
+ }
+
+ _this->udev_device_unref(dev);
+ }
+}
+
+int
+SDL_UDEV_AddCallback(SDL_UDEV_Callback cb)
+{
+ SDL_UDEV_CallbackList *item;
+ item = (SDL_UDEV_CallbackList *) SDL_calloc(1, sizeof (SDL_UDEV_CallbackList));
+ if (item == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ item->callback = cb;
+
+ if (_this->last == NULL) {
+ _this->first = _this->last = item;
+ } else {
+ _this->last->next = item;
+ _this->last = item;
+ }
+
+ return 1;
+}
+
+void
+SDL_UDEV_DelCallback(SDL_UDEV_Callback cb)
+{
+ SDL_UDEV_CallbackList *item;
+ SDL_UDEV_CallbackList *prev = NULL;
+
+ for (item = _this->first; item != NULL; item = item->next) {
+ /* found it, remove it. */
+ if (item->callback == cb) {
+ if (prev != NULL) {
+ prev->next = item->next;
+ } else {
+ SDL_assert(_this->first == item);
+ _this->first = item->next;
+ }
+ if (item == _this->last) {
+ _this->last = prev;
+ }
+ SDL_free(item);
+ return;
+ }
+ prev = item;
+ }
+
+}
+
+
+#endif /* SDL_USE_LIBUDEV */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/linux/SDL_udev.h b/src/3rdparty/SDL2/src/core/linux/SDL_udev.h
new file mode 100644
index 0000000..edf5187
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/linux/SDL_udev.h
@@ -0,0 +1,121 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_udev_h_
+#define SDL_udev_h_
+
+#if HAVE_LIBUDEV_H
+
+#ifndef SDL_USE_LIBUDEV
+#define SDL_USE_LIBUDEV 1
+#endif
+
+#include "SDL_loadso.h"
+#include "SDL_events.h"
+#include <libudev.h>
+#include <sys/time.h>
+#include <sys/types.h>
+
+/**
+ * \brief Device type
+ */
+
+typedef enum
+{
+ SDL_UDEV_DEVICEADDED = 1,
+ SDL_UDEV_DEVICEREMOVED
+} SDL_UDEV_deviceevent;
+
+/* A device can be any combination of these classes */
+typedef enum
+{
+ SDL_UDEV_DEVICE_UNKNOWN = 0x0000,
+ SDL_UDEV_DEVICE_MOUSE = 0x0001,
+ SDL_UDEV_DEVICE_KEYBOARD = 0x0002,
+ SDL_UDEV_DEVICE_JOYSTICK = 0x0004,
+ SDL_UDEV_DEVICE_SOUND = 0x0008,
+ SDL_UDEV_DEVICE_TOUCHSCREEN = 0x0010
+} SDL_UDEV_deviceclass;
+
+typedef void (*SDL_UDEV_Callback)(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath);
+
+typedef struct SDL_UDEV_CallbackList {
+ SDL_UDEV_Callback callback;
+ struct SDL_UDEV_CallbackList *next;
+} SDL_UDEV_CallbackList;
+
+typedef struct SDL_UDEV_PrivateData
+{
+ const char *udev_library;
+ void *udev_handle;
+ struct udev *udev;
+ struct udev_monitor *udev_mon;
+ int ref_count;
+ SDL_UDEV_CallbackList *first, *last;
+
+ /* Function pointers */
+ const char *(*udev_device_get_action)(struct udev_device *);
+ const char *(*udev_device_get_devnode)(struct udev_device *);
+ const char *(*udev_device_get_subsystem)(struct udev_device *);
+ struct udev_device *(*udev_device_get_parent_with_subsystem_devtype)(struct udev_device *udev_device, const char *subsystem, const char *devtype);
+ const char *(*udev_device_get_property_value)(struct udev_device *, const char *);
+ const char *(*udev_device_get_sysattr_value)(struct udev_device *udev_device, const char *sysattr);
+ struct udev_device *(*udev_device_new_from_syspath)(struct udev *, const char *);
+ void (*udev_device_unref)(struct udev_device *);
+ int (*udev_enumerate_add_match_property)(struct udev_enumerate *, const char *, const char *);
+ int (*udev_enumerate_add_match_subsystem)(struct udev_enumerate *, const char *);
+ struct udev_list_entry *(*udev_enumerate_get_list_entry)(struct udev_enumerate *);
+ struct udev_enumerate *(*udev_enumerate_new)(struct udev *);
+ int (*udev_enumerate_scan_devices)(struct udev_enumerate *);
+ void (*udev_enumerate_unref)(struct udev_enumerate *);
+ const char *(*udev_list_entry_get_name)(struct udev_list_entry *);
+ struct udev_list_entry *(*udev_list_entry_get_next)(struct udev_list_entry *);
+ int (*udev_monitor_enable_receiving)(struct udev_monitor *);
+ int (*udev_monitor_filter_add_match_subsystem_devtype)(struct udev_monitor *, const char *, const char *);
+ int (*udev_monitor_get_fd)(struct udev_monitor *);
+ struct udev_monitor *(*udev_monitor_new_from_netlink)(struct udev *, const char *);
+ struct udev_device *(*udev_monitor_receive_device)(struct udev_monitor *);
+ void (*udev_monitor_unref)(struct udev_monitor *);
+ struct udev *(*udev_new)(void);
+ void (*udev_unref)(struct udev *);
+ struct udev_device * (*udev_device_new_from_devnum)(struct udev *udev, char type, dev_t devnum);
+ dev_t (*udev_device_get_devnum) (struct udev_device *udev_device);
+} SDL_UDEV_PrivateData;
+
+extern int SDL_UDEV_Init(void);
+extern void SDL_UDEV_Quit(void);
+extern void SDL_UDEV_UnloadLibrary(void);
+extern int SDL_UDEV_LoadLibrary(void);
+extern void SDL_UDEV_Poll(void);
+extern void SDL_UDEV_Scan(void);
+extern int SDL_UDEV_AddCallback(SDL_UDEV_Callback cb);
+extern void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb);
+
+
+
+
+#endif /* HAVE_LIBUDEV_H */
+
+#endif /* SDL_udev_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/unix/SDL_poll.c b/src/3rdparty/SDL2/src/core/unix/SDL_poll.c
new file mode 100644
index 0000000..5ac6d0b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/unix/SDL_poll.c
@@ -0,0 +1,87 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#include "SDL_assert.h"
+#include "SDL_poll.h"
+
+#ifdef HAVE_POLL
+#include <poll.h>
+#else
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+#endif
+#include <errno.h>
+
+
+int
+SDL_IOReady(int fd, SDL_bool forWrite, int timeoutMS)
+{
+ int result;
+
+ /* Note: We don't bother to account for elapsed time if we get EINTR */
+ do
+ {
+#ifdef HAVE_POLL
+ struct pollfd info;
+
+ info.fd = fd;
+ if (forWrite) {
+ info.events = POLLOUT;
+ } else {
+ info.events = POLLIN | POLLPRI;
+ }
+ result = poll(&info, 1, timeoutMS);
+#else
+ fd_set rfdset, *rfdp = NULL;
+ fd_set wfdset, *wfdp = NULL;
+ struct timeval tv, *tvp = NULL;
+
+ /* If this assert triggers we'll corrupt memory here */
+ SDL_assert(fd >= 0 && fd < FD_SETSIZE);
+
+ if (forWrite) {
+ FD_ZERO(&wfdset);
+ FD_SET(fd, &wfdset);
+ wfdp = &wfdset;
+ } else {
+ FD_ZERO(&rfdset);
+ FD_SET(fd, &rfdset);
+ rfdp = &rfdset;
+ }
+
+ if (timeoutMS >= 0) {
+ tv.tv_sec = timeoutMS / 1000;
+ tv.tv_usec = (timeoutMS % 1000) * 1000;
+ tvp = &tv;
+ }
+
+ result = select(fd + 1, rfdp, wfdp, NULL, tvp);
+#endif /* HAVE_POLL */
+
+ } while ( result < 0 && errno == EINTR );
+
+ return result;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/unix/SDL_poll.h b/src/3rdparty/SDL2/src/core/unix/SDL_poll.h
new file mode 100644
index 0000000..bf20e23
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/unix/SDL_poll.h
@@ -0,0 +1,34 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_poll_h_
+#define SDL_poll_h_
+
+#include "SDL_stdinc.h"
+
+
+extern int SDL_IOReady(int fd, SDL_bool forWrite, int timeoutMS);
+
+#endif /* SDL_poll_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/windows/SDL_directx.h b/src/3rdparty/SDL2/src/core/windows/SDL_directx.h
new file mode 100644
index 0000000..7fe826f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/windows/SDL_directx.h
@@ -0,0 +1,111 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_directx_h_
+#define SDL_directx_h_
+
+/* Include all of the DirectX 8.0 headers and adds any necessary tweaks */
+
+#include "SDL_windows.h"
+#include <mmsystem.h>
+#ifndef WIN32
+#define WIN32
+#endif
+#undef WINNT
+
+/* Far pointers don't exist in 32-bit code */
+#ifndef FAR
+#define FAR
+#endif
+
+/* Error codes not yet included in Win32 API header files */
+#ifndef MAKE_HRESULT
+#define MAKE_HRESULT(sev,fac,code) \
+ ((HRESULT)(((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))))
+#endif
+
+#ifndef S_OK
+#define S_OK (HRESULT)0x00000000L
+#endif
+
+#ifndef SUCCEEDED
+#define SUCCEEDED(x) ((HRESULT)(x) >= 0)
+#endif
+#ifndef FAILED
+#define FAILED(x) ((HRESULT)(x)<0)
+#endif
+
+#ifndef E_FAIL
+#define E_FAIL (HRESULT)0x80000008L
+#endif
+#ifndef E_NOINTERFACE
+#define E_NOINTERFACE (HRESULT)0x80004002L
+#endif
+#ifndef E_OUTOFMEMORY
+#define E_OUTOFMEMORY (HRESULT)0x8007000EL
+#endif
+#ifndef E_INVALIDARG
+#define E_INVALIDARG (HRESULT)0x80070057L
+#endif
+#ifndef E_NOTIMPL
+#define E_NOTIMPL (HRESULT)0x80004001L
+#endif
+#ifndef REGDB_E_CLASSNOTREG
+#define REGDB_E_CLASSNOTREG (HRESULT)0x80040154L
+#endif
+
+/* Severity codes */
+#ifndef SEVERITY_ERROR
+#define SEVERITY_ERROR 1
+#endif
+
+/* Error facility codes */
+#ifndef FACILITY_WIN32
+#define FACILITY_WIN32 7
+#endif
+
+#ifndef FIELD_OFFSET
+#define FIELD_OFFSET(type, field) ((LONG)&(((type *)0)->field))
+#endif
+
+/* DirectX headers (if it isn't included, I haven't tested it yet)
+ */
+/* We need these defines to mark what version of DirectX API we use */
+#define DIRECTDRAW_VERSION 0x0700
+#define DIRECTSOUND_VERSION 0x0800
+#define DIRECTINPUT_VERSION 0x0800 /* Need version 7 for force feedback. Need version 8 so IDirectInput8_EnumDevices doesn't leak like a sieve... */
+
+#ifdef HAVE_DDRAW_H
+#include <ddraw.h>
+#endif
+#ifdef HAVE_DSOUND_H
+#include <dsound.h>
+#endif
+#ifdef HAVE_DINPUT_H
+#include <dinput.h>
+#else
+typedef struct { int unused; } DIDEVICEINSTANCE;
+#endif
+
+#endif /* SDL_directx_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/windows/SDL_windows.c b/src/3rdparty/SDL2/src/core/windows/SDL_windows.c
new file mode 100644
index 0000000..6624043
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/windows/SDL_windows.c
@@ -0,0 +1,230 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if defined(__WIN32__) || defined(__WINRT__)
+
+#include "SDL_windows.h"
+#include "SDL_error.h"
+#include "SDL_assert.h"
+
+#include <objbase.h> /* for CoInitialize/CoUninitialize (Win32 only) */
+
+#ifndef _WIN32_WINNT_VISTA
+#define _WIN32_WINNT_VISTA 0x0600
+#endif
+
+
+/* Sets an error message based on an HRESULT */
+int
+WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr)
+{
+ TCHAR buffer[1024];
+ char *message;
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hr, 0,
+ buffer, SDL_arraysize(buffer), NULL);
+ message = WIN_StringToUTF8(buffer);
+ SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message);
+ SDL_free(message);
+ return -1;
+}
+
+/* Sets an error message based on GetLastError() */
+int
+WIN_SetError(const char *prefix)
+{
+ return WIN_SetErrorFromHRESULT(prefix, GetLastError());
+}
+
+HRESULT
+WIN_CoInitialize(void)
+{
+ /* SDL handles any threading model, so initialize with the default, which
+ is compatible with OLE and if that doesn't work, try multi-threaded mode.
+
+ If you need multi-threaded mode, call CoInitializeEx() before SDL_Init()
+ */
+#ifdef __WINRT__
+ /* DLudwig: On WinRT, it is assumed that COM was initialized in main().
+ CoInitializeEx is available (not CoInitialize though), however
+ on WinRT, main() is typically declared with the [MTAThread]
+ attribute, which, AFAIK, should initialize COM.
+ */
+ return S_OK;
+#else
+ HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
+ if (hr == RPC_E_CHANGED_MODE) {
+ hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
+ }
+
+ /* S_FALSE means success, but someone else already initialized. */
+ /* You still need to call CoUninitialize in this case! */
+ if (hr == S_FALSE) {
+ return S_OK;
+ }
+
+ return hr;
+#endif
+}
+
+void
+WIN_CoUninitialize(void)
+{
+#ifndef __WINRT__
+ CoUninitialize();
+#endif
+}
+
+#ifndef __WINRT__
+static BOOL
+IsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor)
+{
+ OSVERSIONINFOEXW osvi;
+ DWORDLONG const dwlConditionMask = VerSetConditionMask(
+ VerSetConditionMask(
+ VerSetConditionMask(
+ 0, VER_MAJORVERSION, VER_GREATER_EQUAL ),
+ VER_MINORVERSION, VER_GREATER_EQUAL ),
+ VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL );
+
+ SDL_zero(osvi);
+ osvi.dwOSVersionInfoSize = sizeof(osvi);
+ osvi.dwMajorVersion = wMajorVersion;
+ osvi.dwMinorVersion = wMinorVersion;
+ osvi.wServicePackMajor = wServicePackMajor;
+
+ return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE;
+}
+#endif
+
+BOOL WIN_IsWindowsVistaOrGreater(void)
+{
+#ifdef __WINRT__
+ return TRUE;
+#else
+ return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_VISTA), LOBYTE(_WIN32_WINNT_VISTA), 0);
+#endif
+}
+
+BOOL WIN_IsWindows7OrGreater(void)
+{
+#ifdef __WINRT__
+ return TRUE;
+#else
+ return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN7), LOBYTE(_WIN32_WINNT_WIN7), 0);
+#endif
+}
+
+/*
+WAVExxxCAPS gives you 31 bytes for the device name, and just truncates if it's
+longer. However, since WinXP, you can use the WAVExxxCAPS2 structure, which
+will give you a name GUID. The full name is in the Windows Registry under
+that GUID, located here: HKLM\System\CurrentControlSet\Control\MediaCategories
+
+Note that drivers can report GUID_NULL for the name GUID, in which case,
+Windows makes a best effort to fill in those 31 bytes in the usual place.
+This info summarized from MSDN:
+
+http://web.archive.org/web/20131027093034/http://msdn.microsoft.com/en-us/library/windows/hardware/ff536382(v=vs.85).aspx
+
+Always look this up in the registry if possible, because the strings are
+different! At least on Win10, I see "Yeti Stereo Microphone" in the
+Registry, and a unhelpful "Microphone(Yeti Stereo Microph" in winmm. Sigh.
+
+(Also, DirectSound shouldn't be limited to 32 chars, but its device enum
+has the same problem.)
+
+WASAPI doesn't need this. This is just for DirectSound/WinMM.
+*/
+char *
+WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid)
+{
+#if __WINRT__
+ return WIN_StringToUTF8(name); /* No registry access on WinRT/UWP, go with what we've got. */
+#else
+ static const GUID nullguid = { 0 };
+ const unsigned char *ptr;
+ char keystr[128];
+ WCHAR *strw = NULL;
+ SDL_bool rc;
+ HKEY hkey;
+ DWORD len = 0;
+ char *retval = NULL;
+
+ if (WIN_IsEqualGUID(guid, &nullguid)) {
+ return WIN_StringToUTF8(name); /* No GUID, go with what we've got. */
+ }
+
+ ptr = (const unsigned char *) guid;
+ SDL_snprintf(keystr, sizeof (keystr),
+ "System\\CurrentControlSet\\Control\\MediaCategories\\{%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
+ ptr[3], ptr[2], ptr[1], ptr[0], ptr[5], ptr[4], ptr[7], ptr[6],
+ ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13], ptr[14], ptr[15]);
+
+ strw = WIN_UTF8ToString(keystr);
+ rc = (RegOpenKeyExW(HKEY_LOCAL_MACHINE, strw, 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS);
+ SDL_free(strw);
+ if (!rc) {
+ return WIN_StringToUTF8(name); /* oh well. */
+ }
+
+ rc = (RegQueryValueExW(hkey, L"Name", NULL, NULL, NULL, &len) == ERROR_SUCCESS);
+ if (!rc) {
+ RegCloseKey(hkey);
+ return WIN_StringToUTF8(name); /* oh well. */
+ }
+
+ strw = (WCHAR *) SDL_malloc(len + sizeof (WCHAR));
+ if (!strw) {
+ RegCloseKey(hkey);
+ return WIN_StringToUTF8(name); /* oh well. */
+ }
+
+ rc = (RegQueryValueExW(hkey, L"Name", NULL, NULL, (LPBYTE) strw, &len) == ERROR_SUCCESS);
+ RegCloseKey(hkey);
+ if (!rc) {
+ SDL_free(strw);
+ return WIN_StringToUTF8(name); /* oh well. */
+ }
+
+ strw[len / 2] = 0; /* make sure it's null-terminated. */
+
+ retval = WIN_StringToUTF8(strw);
+ SDL_free(strw);
+ return retval ? retval : WIN_StringToUTF8(name);
+#endif /* if __WINRT__ / else */
+}
+
+BOOL
+WIN_IsEqualGUID(const GUID * a, const GUID * b)
+{
+ return (SDL_memcmp(a, b, sizeof (*a)) == 0);
+}
+
+BOOL
+WIN_IsEqualIID(REFIID a, REFIID b)
+{
+ return (SDL_memcmp(a, b, sizeof (*a)) == 0);
+}
+
+#endif /* __WIN32__ || __WINRT__ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/windows/SDL_windows.h b/src/3rdparty/SDL2/src/core/windows/SDL_windows.h
new file mode 100644
index 0000000..4a3336a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/windows/SDL_windows.h
@@ -0,0 +1,75 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/* This is an include file for windows.h with the SDL build settings */
+
+#ifndef _INCLUDED_WINDOWS_H
+#define _INCLUDED_WINDOWS_H
+
+#if defined(__WIN32__)
+#define WIN32_LEAN_AND_MEAN
+#define STRICT
+#ifndef UNICODE
+#define UNICODE 1
+#endif
+#undef _WIN32_WINNT
+#define _WIN32_WINNT 0x501 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices(), 0x501 for raw input */
+#endif
+
+#include <windows.h>
+#include <basetyps.h> /* for REFIID with broken mingw.org headers */
+
+/* Routines to convert from UTF8 to native Windows text */
+#if UNICODE
+#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(S), (SDL_wcslen(S)+1)*sizeof(WCHAR))
+#define WIN_UTF8ToString(S) (WCHAR *)SDL_iconv_string("UTF-16LE", "UTF-8", (char *)(S), SDL_strlen(S)+1)
+#else
+/* !!! FIXME: UTF8ToString() can just be a SDL_strdup() here. */
+#define WIN_StringToUTF8(S) SDL_iconv_string("UTF-8", "ASCII", (char *)(S), (SDL_strlen(S)+1))
+#define WIN_UTF8ToString(S) SDL_iconv_string("ASCII", "UTF-8", (char *)(S), SDL_strlen(S)+1)
+#endif
+
+/* Sets an error message based on a given HRESULT */
+extern int WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr);
+
+/* Sets an error message based on GetLastError(). Always return -1. */
+extern int WIN_SetError(const char *prefix);
+
+/* Wrap up the oddities of CoInitialize() into a common function. */
+extern HRESULT WIN_CoInitialize(void);
+extern void WIN_CoUninitialize(void);
+
+/* Returns SDL_TRUE if we're running on Windows Vista and newer */
+extern BOOL WIN_IsWindowsVistaOrGreater(void);
+
+/* Returns SDL_TRUE if we're running on Windows 7 and newer */
+extern BOOL WIN_IsWindows7OrGreater(void);
+
+/* You need to SDL_free() the result of this call. */
+extern char *WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid);
+
+/* Checks to see if two GUID are the same. */
+extern BOOL WIN_IsEqualGUID(const GUID * a, const GUID * b);
+extern BOOL WIN_IsEqualIID(REFIID a, REFIID b);
+
+#endif /* _INCLUDED_WINDOWS_H */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/windows/SDL_xinput.c b/src/3rdparty/SDL2/src/core/windows/SDL_xinput.c
new file mode 100644
index 0000000..75bf600
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/windows/SDL_xinput.c
@@ -0,0 +1,139 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "SDL_assert.h"
+#include "SDL_xinput.h"
+
+
+#ifdef HAVE_XINPUT_H
+
+XInputGetState_t SDL_XInputGetState = NULL;
+XInputSetState_t SDL_XInputSetState = NULL;
+XInputGetCapabilities_t SDL_XInputGetCapabilities = NULL;
+XInputGetBatteryInformation_t SDL_XInputGetBatteryInformation = NULL;
+DWORD SDL_XInputVersion = 0;
+
+static HANDLE s_pXInputDLL = 0;
+static int s_XInputDLLRefCount = 0;
+
+
+#ifdef __WINRT__
+
+int
+WIN_LoadXInputDLL(void)
+{
+ /* Getting handles to system dlls (via LoadLibrary and its variants) is not
+ * supported on WinRT, thus, pointers to XInput's functions can't be
+ * retrieved via GetProcAddress.
+ *
+ * When on WinRT, assume that XInput is already loaded, and directly map
+ * its XInput.h-declared functions to the SDL_XInput* set of function
+ * pointers.
+ *
+ * Side-note: XInputGetStateEx is not available for use in WinRT.
+ * This seems to mean that support for the guide button is not available
+ * in WinRT, unfortunately.
+ */
+ SDL_XInputGetState = (XInputGetState_t)XInputGetState;
+ SDL_XInputSetState = (XInputSetState_t)XInputSetState;
+ SDL_XInputGetCapabilities = (XInputGetCapabilities_t)XInputGetCapabilities;
+ SDL_XInputGetBatteryInformation = (XInputGetBatteryInformation_t)XInputGetBatteryInformation;
+
+ /* XInput 1.4 ships with Windows 8 and 8.1: */
+ SDL_XInputVersion = (1 << 16) | 4;
+
+ return 0;
+}
+
+void
+WIN_UnloadXInputDLL(void)
+{
+}
+
+#else /* !__WINRT__ */
+
+int
+WIN_LoadXInputDLL(void)
+{
+ DWORD version = 0;
+
+ if (s_pXInputDLL) {
+ SDL_assert(s_XInputDLLRefCount > 0);
+ s_XInputDLLRefCount++;
+ return 0; /* already loaded */
+ }
+
+ version = (1 << 16) | 4;
+ s_pXInputDLL = LoadLibrary(L"XInput1_4.dll"); /* 1.4 Ships with Windows 8. */
+ if (!s_pXInputDLL) {
+ version = (1 << 16) | 3;
+ s_pXInputDLL = LoadLibrary(L"XInput1_3.dll"); /* 1.3 can be installed as a redistributable component. */
+ }
+ if (!s_pXInputDLL) {
+ s_pXInputDLL = LoadLibrary(L"bin\\XInput1_3.dll");
+ }
+ if (!s_pXInputDLL) {
+ /* "9.1.0" Ships with Vista and Win7, and is more limited than 1.3+ (e.g. XInputGetStateEx is not available.) */
+ s_pXInputDLL = LoadLibrary(L"XInput9_1_0.dll");
+ }
+ if (!s_pXInputDLL) {
+ return -1;
+ }
+
+ SDL_assert(s_XInputDLLRefCount == 0);
+ SDL_XInputVersion = version;
+ s_XInputDLLRefCount = 1;
+
+ /* 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think... */
+ SDL_XInputGetState = (XInputGetState_t)GetProcAddress((HMODULE)s_pXInputDLL, (LPCSTR)100);
+ if (!SDL_XInputGetState) {
+ SDL_XInputGetState = (XInputGetState_t)GetProcAddress((HMODULE)s_pXInputDLL, "XInputGetState");
+ }
+ SDL_XInputSetState = (XInputSetState_t)GetProcAddress((HMODULE)s_pXInputDLL, "XInputSetState");
+ SDL_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress((HMODULE)s_pXInputDLL, "XInputGetCapabilities");
+ SDL_XInputGetBatteryInformation = (XInputGetBatteryInformation_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetBatteryInformation" );
+ if (!SDL_XInputGetState || !SDL_XInputSetState || !SDL_XInputGetCapabilities) {
+ WIN_UnloadXInputDLL();
+ return -1;
+ }
+
+ return 0;
+}
+
+void
+WIN_UnloadXInputDLL(void)
+{
+ if (s_pXInputDLL) {
+ SDL_assert(s_XInputDLLRefCount > 0);
+ if (--s_XInputDLLRefCount == 0) {
+ FreeLibrary(s_pXInputDLL);
+ s_pXInputDLL = NULL;
+ }
+ } else {
+ SDL_assert(s_XInputDLLRefCount == 0);
+ }
+}
+
+#endif /* __WINRT__ */
+#endif /* HAVE_XINPUT_H */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/windows/SDL_xinput.h b/src/3rdparty/SDL2/src/core/windows/SDL_xinput.h
new file mode 100644
index 0000000..6106c2b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/windows/SDL_xinput.h
@@ -0,0 +1,177 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_xinput_h_
+#define SDL_xinput_h_
+
+#ifdef HAVE_XINPUT_H
+
+#include "SDL_windows.h"
+#include <xinput.h>
+
+#ifndef XUSER_MAX_COUNT
+#define XUSER_MAX_COUNT 4
+#endif
+#ifndef XUSER_INDEX_ANY
+#define XUSER_INDEX_ANY 0x000000FF
+#endif
+#ifndef XINPUT_CAPS_FFB_SUPPORTED
+#define XINPUT_CAPS_FFB_SUPPORTED 0x0001
+#endif
+
+#ifndef XINPUT_DEVSUBTYPE_UNKNOWN
+#define XINPUT_DEVSUBTYPE_UNKNOWN 0x00
+#endif
+#ifndef XINPUT_DEVSUBTYPE_GAMEPAD
+#define XINPUT_DEVSUBTYPE_GAMEPAD 0x01
+#endif
+#ifndef XINPUT_DEVSUBTYPE_WHEEL
+#define XINPUT_DEVSUBTYPE_WHEEL 0x02
+#endif
+#ifndef XINPUT_DEVSUBTYPE_ARCADE_STICK
+#define XINPUT_DEVSUBTYPE_ARCADE_STICK 0x03
+#endif
+#ifndef XINPUT_DEVSUBTYPE_FLIGHT_STICK
+#define XINPUT_DEVSUBTYPE_FLIGHT_STICK 0x04
+#endif
+#ifndef XINPUT_DEVSUBTYPE_DANCE_PAD
+#define XINPUT_DEVSUBTYPE_DANCE_PAD 0x05
+#endif
+#ifndef XINPUT_DEVSUBTYPE_GUITAR
+#define XINPUT_DEVSUBTYPE_GUITAR 0x06
+#endif
+#ifndef XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE
+#define XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE 0x07
+#endif
+#ifndef XINPUT_DEVSUBTYPE_DRUM_KIT
+#define XINPUT_DEVSUBTYPE_DRUM_KIT 0x08
+#endif
+#ifndef XINPUT_DEVSUBTYPE_GUITAR_BASS
+#define XINPUT_DEVSUBTYPE_GUITAR_BASS 0x0B
+#endif
+#ifndef XINPUT_DEVSUBTYPE_ARCADE_PAD
+#define XINPUT_DEVSUBTYPE_ARCADE_PAD 0x13
+#endif
+
+#ifndef XINPUT_GAMEPAD_GUIDE
+#define XINPUT_GAMEPAD_GUIDE 0x0400
+#endif
+
+#ifndef BATTERY_DEVTYPE_GAMEPAD
+#define BATTERY_DEVTYPE_GAMEPAD 0x00
+#endif
+#ifndef BATTERY_TYPE_WIRED
+#define BATTERY_TYPE_WIRED 0x01
+#endif
+
+#ifndef BATTERY_TYPE_UNKNOWN
+#define BATTERY_TYPE_UNKNOWN 0xFF
+#endif
+#ifndef BATTERY_LEVEL_EMPTY
+#define BATTERY_LEVEL_EMPTY 0x00
+#endif
+#ifndef BATTERY_LEVEL_LOW
+#define BATTERY_LEVEL_LOW 0x01
+#endif
+#ifndef BATTERY_LEVEL_MEDIUM
+#define BATTERY_LEVEL_MEDIUM 0x02
+#endif
+#ifndef BATTERY_LEVEL_FULL
+#define BATTERY_LEVEL_FULL 0x03
+#endif
+
+/* typedef's for XInput structs we use */
+
+#ifndef HAVE_XINPUT_GAMEPAD_EX
+typedef struct
+{
+ WORD wButtons;
+ BYTE bLeftTrigger;
+ BYTE bRightTrigger;
+ SHORT sThumbLX;
+ SHORT sThumbLY;
+ SHORT sThumbRX;
+ SHORT sThumbRY;
+ DWORD dwPaddingReserved;
+} XINPUT_GAMEPAD_EX;
+#endif
+
+#ifndef HAVE_XINPUT_STATE_EX
+typedef struct
+{
+ DWORD dwPacketNumber;
+ XINPUT_GAMEPAD_EX Gamepad;
+} XINPUT_STATE_EX;
+#endif
+
+typedef struct
+{
+ BYTE BatteryType;
+ BYTE BatteryLevel;
+} XINPUT_BATTERY_INFORMATION_EX;
+
+/* Forward decl's for XInput API's we load dynamically and use if available */
+typedef DWORD (WINAPI *XInputGetState_t)
+ (
+ DWORD dwUserIndex, /* [in] Index of the gamer associated with the device */
+ XINPUT_STATE_EX* pState /* [out] Receives the current state */
+ );
+
+typedef DWORD (WINAPI *XInputSetState_t)
+ (
+ DWORD dwUserIndex, /* [in] Index of the gamer associated with the device */
+ XINPUT_VIBRATION* pVibration /* [in, out] The vibration information to send to the controller */
+ );
+
+typedef DWORD (WINAPI *XInputGetCapabilities_t)
+ (
+ DWORD dwUserIndex, /* [in] Index of the gamer associated with the device */
+ DWORD dwFlags, /* [in] Input flags that identify the device type */
+ XINPUT_CAPABILITIES* pCapabilities /* [out] Receives the capabilities */
+ );
+
+typedef DWORD (WINAPI *XInputGetBatteryInformation_t)
+ (
+ DWORD dwUserIndex,
+ BYTE devType,
+ XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation
+ );
+
+extern int WIN_LoadXInputDLL(void);
+extern void WIN_UnloadXInputDLL(void);
+
+extern XInputGetState_t SDL_XInputGetState;
+extern XInputSetState_t SDL_XInputSetState;
+extern XInputGetCapabilities_t SDL_XInputGetCapabilities;
+extern XInputGetBatteryInformation_t SDL_XInputGetBatteryInformation;
+extern DWORD SDL_XInputVersion; /* ((major << 16) & 0xFF00) | (minor & 0xFF) */
+
+#define XINPUTGETSTATE SDL_XInputGetState
+#define XINPUTSETSTATE SDL_XInputSetState
+#define XINPUTGETCAPABILITIES SDL_XInputGetCapabilities
+#define XINPUTGETBATTERYINFORMATION SDL_XInputGetBatteryInformation
+
+#endif /* HAVE_XINPUT_H */
+
+#endif /* SDL_xinput_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_common.cpp b/src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_common.cpp
new file mode 100644
index 0000000..887b47e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_common.cpp
@@ -0,0 +1,66 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "SDL_system.h"
+#include "SDL_winrtapp_direct3d.h"
+#include "SDL_winrtapp_xaml.h"
+
+#include <wrl.h>
+
+int (*WINRT_SDLAppEntryPoint)(int, char **) = NULL;
+
+extern "C" DECLSPEC int
+SDL_WinRTRunApp(int (*mainFunction)(int, char **), void * xamlBackgroundPanel)
+{
+ if (xamlBackgroundPanel) {
+ return SDL_WinRTInitXAMLApp(mainFunction, xamlBackgroundPanel);
+ } else {
+ if (FAILED(Windows::Foundation::Initialize(RO_INIT_MULTITHREADED))) {
+ return 1;
+ }
+ return SDL_WinRTInitNonXAMLApp(mainFunction);
+ }
+}
+
+
+extern "C" DECLSPEC SDL_WinRT_DeviceFamily
+SDL_WinRTGetDeviceFamily()
+{
+#if NTDDI_VERSION >= NTDDI_WIN10 /* !!! FIXME: I have no idea if this is the right test. This is a UWP API, I think. Older windows should...just return "mobile"? I don't know. --ryan. */
+ Platform::String^ deviceFamily = Windows::System::Profile::AnalyticsInfo::VersionInfo->DeviceFamily;
+
+ if (deviceFamily->Equals("Windows.Desktop"))
+ {
+ return SDL_WINRT_DEVICEFAMILY_DESKTOP;
+ }
+ else if (deviceFamily->Equals("Windows.Mobile"))
+ {
+ return SDL_WINRT_DEVICEFAMILY_MOBILE;
+ }
+ else if (deviceFamily->Equals("Windows.Xbox"))
+ {
+ return SDL_WINRT_DEVICEFAMILY_XBOX;
+ }
+#endif
+
+ return SDL_WINRT_DEVICEFAMILY_UNKNOWN;
+} \ No newline at end of file
diff --git a/src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_common.h b/src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_common.h
new file mode 100644
index 0000000..d68704c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_common.h
@@ -0,0 +1,31 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#ifndef SDL_winrtapp_common_h_
+#define SDL_winrtapp_common_h_
+
+/* A pointer to the app's C-style main() function (which is a different
+ function than the WinRT app's actual entry point).
+ */
+extern int (*WINRT_SDLAppEntryPoint)(int, char **);
+
+#endif // SDL_winrtapp_common_h_
diff --git a/src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_direct3d.cpp b/src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_direct3d.cpp
new file mode 100644
index 0000000..6fa0bea
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_direct3d.cpp
@@ -0,0 +1,855 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+/* Standard C++11 includes */
+#include <functional>
+#include <string>
+#include <sstream>
+using namespace std;
+
+
+/* Windows includes */
+#include "ppltasks.h"
+using namespace concurrency;
+using namespace Windows::ApplicationModel;
+using namespace Windows::ApplicationModel::Core;
+using namespace Windows::ApplicationModel::Activation;
+using namespace Windows::Devices::Input;
+using namespace Windows::Graphics::Display;
+using namespace Windows::Foundation;
+using namespace Windows::System;
+using namespace Windows::UI::Core;
+using namespace Windows::UI::Input;
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+using namespace Windows::Phone::UI::Input;
+#endif
+
+
+/* SDL includes */
+extern "C" {
+#include "SDL_assert.h"
+#include "SDL_events.h"
+#include "SDL_hints.h"
+#include "SDL_log.h"
+#include "SDL_main.h"
+#include "SDL_stdinc.h"
+#include "SDL_render.h"
+#include "../../video/SDL_sysvideo.h"
+//#include "../../SDL_hints_c.h"
+#include "../../events/SDL_events_c.h"
+#include "../../events/SDL_keyboard_c.h"
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_windowevents_c.h"
+#include "../../render/SDL_sysrender.h"
+#include "../windows/SDL_windows.h"
+}
+
+#include "../../video/winrt/SDL_winrtevents_c.h"
+#include "../../video/winrt/SDL_winrtvideo_cpp.h"
+#include "SDL_winrtapp_common.h"
+#include "SDL_winrtapp_direct3d.h"
+
+#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
+/* Calling IDXGIDevice3::Trim on the active Direct3D 11.x device is necessary
+ * when Windows 8.1 apps are about to get suspended.
+ */
+extern "C" void D3D11_Trim(SDL_Renderer *);
+#endif
+
+
+// Compile-time debugging options:
+// To enable, uncomment; to disable, comment them out.
+//#define LOG_POINTER_EVENTS 1
+//#define LOG_WINDOW_EVENTS 1
+//#define LOG_ORIENTATION_EVENTS 1
+
+
+// HACK, DLudwig: record a reference to the global, WinRT 'app'/view.
+// SDL/WinRT will use this throughout its code.
+//
+// TODO, WinRT: consider replacing SDL_WinRTGlobalApp with something
+// non-global, such as something created inside
+// SDL_InitSubSystem(SDL_INIT_VIDEO), or something inside
+// SDL_CreateWindow().
+SDL_WinRTApp ^ SDL_WinRTGlobalApp = nullptr;
+
+ref class SDLApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource
+{
+public:
+ virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView();
+};
+
+IFrameworkView^ SDLApplicationSource::CreateView()
+{
+ // TODO, WinRT: see if this function (CreateView) can ever get called
+ // more than once. For now, just prevent it from ever assigning
+ // SDL_WinRTGlobalApp more than once.
+ SDL_assert(!SDL_WinRTGlobalApp);
+ SDL_WinRTApp ^ app = ref new SDL_WinRTApp();
+ if (!SDL_WinRTGlobalApp)
+ {
+ SDL_WinRTGlobalApp = app;
+ }
+ return app;
+}
+
+int SDL_WinRTInitNonXAMLApp(int (*mainFunction)(int, char **))
+{
+ WINRT_SDLAppEntryPoint = mainFunction;
+ auto direct3DApplicationSource = ref new SDLApplicationSource();
+ CoreApplication::Run(direct3DApplicationSource);
+ return 0;
+}
+
+static void SDLCALL
+WINRT_SetDisplayOrientationsPreference(void *userdata, const char *name, const char *oldValue, const char *newValue)
+{
+ SDL_assert(SDL_strcmp(name, SDL_HINT_ORIENTATIONS) == 0);
+
+ /* HACK: prevent SDL from altering an app's .appxmanifest-set orientation
+ * from being changed on startup, by detecting when SDL_HINT_ORIENTATIONS
+ * is getting registered.
+ *
+ * TODO, WinRT: consider reading in an app's .appxmanifest file, and apply its orientation when 'newValue == NULL'.
+ */
+ if ((oldValue == NULL) && (newValue == NULL)) {
+ return;
+ }
+
+ // Start with no orientation flags, then add each in as they're parsed
+ // from newValue.
+ unsigned int orientationFlags = 0;
+ if (newValue) {
+ std::istringstream tokenizer(newValue);
+ while (!tokenizer.eof()) {
+ std::string orientationName;
+ std::getline(tokenizer, orientationName, ' ');
+ if (orientationName == "LandscapeLeft") {
+ orientationFlags |= (unsigned int) DisplayOrientations::LandscapeFlipped;
+ } else if (orientationName == "LandscapeRight") {
+ orientationFlags |= (unsigned int) DisplayOrientations::Landscape;
+ } else if (orientationName == "Portrait") {
+ orientationFlags |= (unsigned int) DisplayOrientations::Portrait;
+ } else if (orientationName == "PortraitUpsideDown") {
+ orientationFlags |= (unsigned int) DisplayOrientations::PortraitFlipped;
+ }
+ }
+ }
+
+ // If no valid orientation flags were specified, use a reasonable set of defaults:
+ if (!orientationFlags) {
+ // TODO, WinRT: consider seeing if an app's default orientation flags can be found out via some API call(s).
+ orientationFlags = (unsigned int) ( \
+ DisplayOrientations::Landscape |
+ DisplayOrientations::LandscapeFlipped |
+ DisplayOrientations::Portrait |
+ DisplayOrientations::PortraitFlipped);
+ }
+
+ // Set the orientation/rotation preferences. Please note that this does
+ // not constitute a 100%-certain lock of a given set of possible
+ // orientations. According to Microsoft's documentation on WinRT [1]
+ // when a device is not capable of being rotated, Windows may ignore
+ // the orientation preferences, and stick to what the device is capable of
+ // displaying.
+ //
+ // [1] Documentation on the 'InitialRotationPreference' setting for a
+ // Windows app's manifest file describes how some orientation/rotation
+ // preferences may be ignored. See
+ // http://msdn.microsoft.com/en-us/library/windows/apps/hh700343.aspx
+ // for details. Microsoft's "Display orientation sample" also gives an
+ // outline of how Windows treats device rotation
+ // (http://code.msdn.microsoft.com/Display-Orientation-Sample-19a58e93).
+ WINRT_DISPLAY_PROPERTY(AutoRotationPreferences) = (DisplayOrientations) orientationFlags;
+}
+
+static void
+WINRT_ProcessWindowSizeChange() // TODO: Pass an SDL_Window-identifying thing into WINRT_ProcessWindowSizeChange()
+{
+ CoreWindow ^ coreWindow = CoreWindow::GetForCurrentThread();
+ if (coreWindow) {
+ if (WINRT_GlobalSDLWindow) {
+ SDL_Window * window = WINRT_GlobalSDLWindow;
+ SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
+
+ int x = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Left);
+ int y = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Top);
+ int w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
+ int h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
+
+#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) && (NTDDI_VERSION == NTDDI_WIN8)
+ /* WinPhone 8.0 always keeps its native window size in portrait,
+ regardless of orientation. This changes in WinPhone 8.1,
+ in which the native window's size changes along with
+ orientation.
+
+ Attempt to emulate WinPhone 8.1's behavior on WinPhone 8.0, with
+ regards to window size. This fixes a rendering bug that occurs
+ when a WinPhone 8.0 app is rotated to either 90 or 270 degrees.
+ */
+ const DisplayOrientations currentOrientation = WINRT_DISPLAY_PROPERTY(CurrentOrientation);
+ switch (currentOrientation) {
+ case DisplayOrientations::Landscape:
+ case DisplayOrientations::LandscapeFlipped: {
+ int tmp = w;
+ w = h;
+ h = tmp;
+ } break;
+ }
+#endif
+
+ const Uint32 latestFlags = WINRT_DetectWindowFlags(window);
+ if (latestFlags & SDL_WINDOW_MAXIMIZED) {
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
+ } else {
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
+ }
+
+ WINRT_UpdateWindowFlags(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
+
+ /* The window can move during a resize event, such as when maximizing
+ or resizing from a corner */
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
+ }
+ }
+}
+
+SDL_WinRTApp::SDL_WinRTApp() :
+ m_windowClosed(false),
+ m_windowVisible(true)
+{
+}
+
+void SDL_WinRTApp::Initialize(CoreApplicationView^ applicationView)
+{
+ applicationView->Activated +=
+ ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &SDL_WinRTApp::OnAppActivated);
+
+ CoreApplication::Suspending +=
+ ref new EventHandler<SuspendingEventArgs^>(this, &SDL_WinRTApp::OnSuspending);
+
+ CoreApplication::Resuming +=
+ ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnResuming);
+
+ CoreApplication::Exiting +=
+ ref new EventHandler<Platform::Object^>(this, &SDL_WinRTApp::OnExiting);
+
+#if NTDDI_VERSION >= NTDDI_WIN10
+ /* HACK ALERT! Xbox One doesn't seem to detect gamepads unless something
+ gets registered to receive Win10's Windows.Gaming.Input.Gamepad.GamepadAdded
+ events. We'll register an event handler for these events here, to make
+ sure that gamepad detection works later on, if requested.
+ */
+ Windows::Gaming::Input::Gamepad::GamepadAdded +=
+ ref new Windows::Foundation::EventHandler<Windows::Gaming::Input::Gamepad^>(
+ this, &SDL_WinRTApp::OnGamepadAdded
+ );
+#endif
+}
+
+#if NTDDI_VERSION > NTDDI_WIN8
+void SDL_WinRTApp::OnOrientationChanged(DisplayInformation^ sender, Object^ args)
+#else
+void SDL_WinRTApp::OnOrientationChanged(Object^ sender)
+#endif
+{
+#if LOG_ORIENTATION_EVENTS==1
+ {
+ CoreWindow^ window = CoreWindow::GetForCurrentThread();
+ if (window) {
+ SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d, CoreWindow Bounds={%f,%f,%f,%f}\n",
+ __FUNCTION__,
+ WINRT_DISPLAY_PROPERTY(CurrentOrientation),
+ WINRT_DISPLAY_PROPERTY(NativeOrientation),
+ WINRT_DISPLAY_PROPERTY(AutoRotationPreferences),
+ window->Bounds.X,
+ window->Bounds.Y,
+ window->Bounds.Width,
+ window->Bounds.Height);
+ } else {
+ SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d\n",
+ __FUNCTION__,
+ WINRT_DISPLAY_PROPERTY(CurrentOrientation),
+ WINRT_DISPLAY_PROPERTY(NativeOrientation),
+ WINRT_DISPLAY_PROPERTY(AutoRotationPreferences));
+ }
+ }
+#endif
+
+ WINRT_ProcessWindowSizeChange();
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+ // HACK: Make sure that orientation changes
+ // lead to the Direct3D renderer's viewport getting updated:
+ //
+ // For some reason, this doesn't seem to need to be done on Windows 8.x,
+ // even when going from Landscape to LandscapeFlipped. It only seems to
+ // be needed on Windows Phone, at least when I tested on my devices.
+ // I'm not currently sure why this is, but it seems to work fine. -- David L.
+ //
+ // TODO, WinRT: do more extensive research into why orientation changes on Win 8.x don't need D3D changes, or if they might, in some cases
+ SDL_Window * window = WINRT_GlobalSDLWindow;
+ if (window) {
+ SDL_WindowData * data = (SDL_WindowData *)window->driverdata;
+ int w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
+ int h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
+ SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_SIZE_CHANGED, w, h);
+ }
+#endif
+
+}
+
+void SDL_WinRTApp::SetWindow(CoreWindow^ window)
+{
+#if LOG_WINDOW_EVENTS==1
+ SDL_Log("%s, current orientation=%d, native orientation=%d, auto rot. pref=%d, window bounds={%f, %f, %f,%f}\n",
+ __FUNCTION__,
+ WINRT_DISPLAY_PROPERTY(CurrentOrientation),
+ WINRT_DISPLAY_PROPERTY(NativeOrientation),
+ WINRT_DISPLAY_PROPERTY(AutoRotationPreferences),
+ window->Bounds.X,
+ window->Bounds.Y,
+ window->Bounds.Width,
+ window->Bounds.Height);
+#endif
+
+ window->SizeChanged +=
+ ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &SDL_WinRTApp::OnWindowSizeChanged);
+
+ window->VisibilityChanged +=
+ ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &SDL_WinRTApp::OnVisibilityChanged);
+
+ window->Activated +=
+ ref new TypedEventHandler<CoreWindow^, WindowActivatedEventArgs^>(this, &SDL_WinRTApp::OnWindowActivated);
+
+ window->Closed +=
+ ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &SDL_WinRTApp::OnWindowClosed);
+
+#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
+ window->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0);
+#endif
+
+ window->PointerPressed +=
+ ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerPressed);
+
+ window->PointerMoved +=
+ ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerMoved);
+
+ window->PointerReleased +=
+ ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerReleased);
+
+ window->PointerEntered +=
+ ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerEntered);
+
+ window->PointerExited +=
+ ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerExited);
+
+ window->PointerWheelChanged +=
+ ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &SDL_WinRTApp::OnPointerWheelChanged);
+
+#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
+ // Retrieves relative-only mouse movements:
+ Windows::Devices::Input::MouseDevice::GetForCurrentView()->MouseMoved +=
+ ref new TypedEventHandler<MouseDevice^, MouseEventArgs^>(this, &SDL_WinRTApp::OnMouseMoved);
+#endif
+
+ window->KeyDown +=
+ ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyDown);
+
+ window->KeyUp +=
+ ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &SDL_WinRTApp::OnKeyUp);
+
+ window->CharacterReceived +=
+ ref new TypedEventHandler<CoreWindow^, CharacterReceivedEventArgs^>(this, &SDL_WinRTApp::OnCharacterReceived);
+
+#if NTDDI_VERSION >= NTDDI_WIN10
+ Windows::UI::Core::SystemNavigationManager::GetForCurrentView()->BackRequested +=
+ ref new EventHandler<BackRequestedEventArgs^>(this, &SDL_WinRTApp::OnBackButtonPressed);
+#elif WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+ HardwareButtons::BackPressed +=
+ ref new EventHandler<BackPressedEventArgs^>(this, &SDL_WinRTApp::OnBackButtonPressed);
+#endif
+
+#if NTDDI_VERSION > NTDDI_WIN8
+ DisplayInformation::GetForCurrentView()->OrientationChanged +=
+ ref new TypedEventHandler<Windows::Graphics::Display::DisplayInformation^, Object^>(this, &SDL_WinRTApp::OnOrientationChanged);
+#else
+ DisplayProperties::OrientationChanged +=
+ ref new DisplayPropertiesEventHandler(this, &SDL_WinRTApp::OnOrientationChanged);
+#endif
+
+ // Register the hint, SDL_HINT_ORIENTATIONS, with SDL.
+ // TODO, WinRT: see if an app's default orientation can be found out via WinRT API(s), then set the initial value of SDL_HINT_ORIENTATIONS accordingly.
+ SDL_AddHintCallback(SDL_HINT_ORIENTATIONS, WINRT_SetDisplayOrientationsPreference, NULL);
+
+#if (WINAPI_FAMILY == WINAPI_FAMILY_APP) && (NTDDI_VERSION < NTDDI_WIN10) // for Windows 8/8.1/RT apps... (and not Phone apps)
+ // Make sure we know when a user has opened the app's settings pane.
+ // This is needed in order to display a privacy policy, which needs
+ // to be done for network-enabled apps, as per Windows Store requirements.
+ using namespace Windows::UI::ApplicationSettings;
+ SettingsPane::GetForCurrentView()->CommandsRequested +=
+ ref new TypedEventHandler<SettingsPane^, SettingsPaneCommandsRequestedEventArgs^>
+ (this, &SDL_WinRTApp::OnSettingsPaneCommandsRequested);
+#endif
+}
+
+void SDL_WinRTApp::Load(Platform::String^ entryPoint)
+{
+}
+
+void SDL_WinRTApp::Run()
+{
+ SDL_SetMainReady();
+ if (WINRT_SDLAppEntryPoint)
+ {
+ // TODO, WinRT: pass the C-style main() a reasonably realistic
+ // representation of command line arguments.
+ int argc = 0;
+ char **argv = NULL;
+ WINRT_SDLAppEntryPoint(argc, argv);
+ }
+}
+
+static bool IsSDLWindowEventPending(SDL_WindowEventID windowEventID)
+{
+ SDL_Event events[128];
+ const int count = SDL_PeepEvents(events, sizeof(events)/sizeof(SDL_Event), SDL_PEEKEVENT, SDL_WINDOWEVENT, SDL_WINDOWEVENT);
+ for (int i = 0; i < count; ++i) {
+ if (events[i].window.event == windowEventID) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool SDL_WinRTApp::ShouldWaitForAppResumeEvents()
+{
+ /* Don't wait if the app is visible: */
+ if (m_windowVisible) {
+ return false;
+ }
+
+ /* Don't wait until the window-hide events finish processing.
+ * Do note that if an app-suspend event is sent (as indicated
+ * by SDL_APP_WILLENTERBACKGROUND and SDL_APP_DIDENTERBACKGROUND
+ * events), then this code may be a moot point, as WinRT's
+ * own event pump (aka ProcessEvents()) will pause regardless
+ * of what we do here. This happens on Windows Phone 8, to note.
+ * Windows 8.x apps, on the other hand, may get a chance to run
+ * these.
+ */
+ if (IsSDLWindowEventPending(SDL_WINDOWEVENT_HIDDEN)) {
+ return false;
+ } else if (IsSDLWindowEventPending(SDL_WINDOWEVENT_FOCUS_LOST)) {
+ return false;
+ } else if (IsSDLWindowEventPending(SDL_WINDOWEVENT_MINIMIZED)) {
+ return false;
+ }
+
+ return true;
+}
+
+void SDL_WinRTApp::PumpEvents()
+{
+ if (!m_windowClosed) {
+ if (!ShouldWaitForAppResumeEvents()) {
+ /* This is the normal way in which events should be pumped.
+ * 'ProcessAllIfPresent' will make ProcessEvents() process anywhere
+ * from zero to N events, and will then return.
+ */
+ CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
+ } else {
+ /* This style of event-pumping, with 'ProcessOneAndAllPending',
+ * will cause anywhere from one to N events to be processed. If
+ * at least one event is processed, the call will return. If
+ * no events are pending, then the call will wait until one is
+ * available, and will not return (to the caller) until this
+ * happens! This should only occur when the app is hidden.
+ */
+ CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
+ }
+ }
+}
+
+void SDL_WinRTApp::Uninitialize()
+{
+}
+
+#if (WINAPI_FAMILY == WINAPI_FAMILY_APP) && (NTDDI_VERSION < NTDDI_WIN10)
+void SDL_WinRTApp::OnSettingsPaneCommandsRequested(
+ Windows::UI::ApplicationSettings::SettingsPane ^p,
+ Windows::UI::ApplicationSettings::SettingsPaneCommandsRequestedEventArgs ^args)
+{
+ using namespace Platform;
+ using namespace Windows::UI::ApplicationSettings;
+ using namespace Windows::UI::Popups;
+
+ String ^privacyPolicyURL = nullptr; // a URL to an app's Privacy Policy
+ String ^privacyPolicyLabel = nullptr; // label/link text
+ const char *tmpHintValue = NULL; // SDL_GetHint-retrieved value, used immediately
+ wchar_t *tmpStr = NULL; // used for UTF8 to UCS2 conversion
+
+ // Setup a 'Privacy Policy' link, if one is available (via SDL_GetHint):
+ tmpHintValue = SDL_GetHint(SDL_HINT_WINRT_PRIVACY_POLICY_URL);
+ if (tmpHintValue && tmpHintValue[0] != '\0') {
+ // Convert the privacy policy's URL to UCS2:
+ tmpStr = WIN_UTF8ToString(tmpHintValue);
+ privacyPolicyURL = ref new String(tmpStr);
+ SDL_free(tmpStr);
+
+ // Optionally retrieve custom label-text for the link. If this isn't
+ // available, a default value will be used instead.
+ tmpHintValue = SDL_GetHint(SDL_HINT_WINRT_PRIVACY_POLICY_LABEL);
+ if (tmpHintValue && tmpHintValue[0] != '\0') {
+ tmpStr = WIN_UTF8ToString(tmpHintValue);
+ privacyPolicyLabel = ref new String(tmpStr);
+ SDL_free(tmpStr);
+ } else {
+ privacyPolicyLabel = ref new String(L"Privacy Policy");
+ }
+
+ // Register the link, along with a handler to be called if and when it is
+ // clicked:
+ auto cmd = ref new SettingsCommand(L"privacyPolicy", privacyPolicyLabel,
+ ref new UICommandInvokedHandler([=](IUICommand ^) {
+ Windows::System::Launcher::LaunchUriAsync(ref new Uri(privacyPolicyURL));
+ }));
+ args->Request->ApplicationCommands->Append(cmd);
+ }
+}
+#endif // if (WINAPI_FAMILY == WINAPI_FAMILY_APP) && (NTDDI_VERSION < NTDDI_WIN10)
+
+void SDL_WinRTApp::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
+{
+#if LOG_WINDOW_EVENTS==1
+ SDL_Log("%s, size={%f,%f}, bounds={%f,%f,%f,%f}, current orientation=%d, native orientation=%d, auto rot. pref=%d, WINRT_GlobalSDLWindow?=%s\n",
+ __FUNCTION__,
+ args->Size.Width, args->Size.Height,
+ sender->Bounds.X, sender->Bounds.Y, sender->Bounds.Width, sender->Bounds.Height,
+ WINRT_DISPLAY_PROPERTY(CurrentOrientation),
+ WINRT_DISPLAY_PROPERTY(NativeOrientation),
+ WINRT_DISPLAY_PROPERTY(AutoRotationPreferences),
+ (WINRT_GlobalSDLWindow ? "yes" : "no"));
+#endif
+
+ WINRT_ProcessWindowSizeChange();
+}
+
+void SDL_WinRTApp::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
+{
+#if LOG_WINDOW_EVENTS==1
+ SDL_Log("%s, visible?=%s, bounds={%f,%f,%f,%f}, WINRT_GlobalSDLWindow?=%s\n",
+ __FUNCTION__,
+ (args->Visible ? "yes" : "no"),
+ sender->Bounds.X, sender->Bounds.Y,
+ sender->Bounds.Width, sender->Bounds.Height,
+ (WINRT_GlobalSDLWindow ? "yes" : "no"));
+#endif
+
+ m_windowVisible = args->Visible;
+ if (WINRT_GlobalSDLWindow) {
+ SDL_bool wasSDLWindowSurfaceValid = WINRT_GlobalSDLWindow->surface_valid;
+ Uint32 latestWindowFlags = WINRT_DetectWindowFlags(WINRT_GlobalSDLWindow);
+ if (args->Visible) {
+ SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_SHOWN, 0, 0);
+ SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
+ if (latestWindowFlags & SDL_WINDOW_MAXIMIZED) {
+ SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
+ } else {
+ SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_RESTORED, 0, 0);
+ }
+ } else {
+ SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_HIDDEN, 0, 0);
+ SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
+ SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
+ }
+
+ // HACK: Prevent SDL's window-hide handling code, which currently
+ // triggers a fake window resize (possibly erronously), from
+ // marking the SDL window's surface as invalid.
+ //
+ // A better solution to this probably involves figuring out if the
+ // fake window resize can be prevented.
+ WINRT_GlobalSDLWindow->surface_valid = wasSDLWindowSurfaceValid;
+ }
+}
+
+void SDL_WinRTApp::OnWindowActivated(CoreWindow^ sender, WindowActivatedEventArgs^ args)
+{
+#if LOG_WINDOW_EVENTS==1
+ SDL_Log("%s, WINRT_GlobalSDLWindow?=%s\n\n",
+ __FUNCTION__,
+ (WINRT_GlobalSDLWindow ? "yes" : "no"));
+#endif
+
+ /* There's no property in Win 8.x to tell whether a window is active or
+ not. [De]activation events are, however, sent to the app. We'll just
+ record those, in case the CoreWindow gets wrapped by an SDL_Window at
+ some future time.
+ */
+ sender->CustomProperties->Insert("SDLHelperWindowActivationState", args->WindowActivationState);
+
+ SDL_Window * window = WINRT_GlobalSDLWindow;
+ if (window) {
+ if (args->WindowActivationState != CoreWindowActivationState::Deactivated) {
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0);
+ if (SDL_GetKeyboardFocus() != window) {
+ SDL_SetKeyboardFocus(window);
+ }
+
+ /* Send a mouse-motion event as appropriate.
+ This doesn't work when called from OnPointerEntered, at least
+ not in WinRT CoreWindow apps (as OnPointerEntered doesn't
+ appear to be called after window-reactivation, at least not
+ in Windows 10, Build 10586.3 (November 2015 update, non-beta).
+
+ Don't do it on WinPhone 8.0 though, as CoreWindow's 'PointerPosition'
+ property isn't available.
+ */
+#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) || (NTDDI_VERSION >= NTDDI_WINBLUE)
+ Point cursorPos = WINRT_TransformCursorPosition(window, sender->PointerPosition, TransformToSDLWindowSize);
+ SDL_SendMouseMotion(window, 0, 0, (int)cursorPos.X, (int)cursorPos.Y);
+#endif
+
+ /* TODO, WinRT: see if the Win32 bugfix from https://hg.libsdl.org/SDL/rev/d278747da408 needs to be applied (on window activation) */
+ //WIN_CheckAsyncMouseRelease(data);
+
+ /* TODO, WinRT: implement clipboard support, if possible */
+ ///*
+ // * FIXME: Update keyboard state
+ // */
+ //WIN_CheckClipboardUpdate(data->videodata);
+
+ // HACK: Resetting the mouse-cursor here seems to fix
+ // https://bugzilla.libsdl.org/show_bug.cgi?id=3217, whereby a
+ // WinRT app's mouse cursor may switch to Windows' 'wait' cursor,
+ // after a user alt-tabs back into a full-screened SDL app.
+ // This bug does not appear to reproduce 100% of the time.
+ // It may be a bug in Windows itself (v.10.0.586.36, as tested,
+ // and the most-recent as of this writing).
+ SDL_SetCursor(NULL);
+ } else {
+ if (SDL_GetKeyboardFocus() == window) {
+ SDL_SetKeyboardFocus(NULL);
+ }
+ }
+ }
+}
+
+void SDL_WinRTApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
+{
+#if LOG_WINDOW_EVENTS==1
+ SDL_Log("%s\n", __FUNCTION__);
+#endif
+ m_windowClosed = true;
+}
+
+void SDL_WinRTApp::OnAppActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
+{
+ CoreWindow::GetForCurrentThread()->Activate();
+}
+
+void SDL_WinRTApp::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args)
+{
+ // Save app state asynchronously after requesting a deferral. Holding a deferral
+ // indicates that the application is busy performing suspending operations. Be
+ // aware that a deferral may not be held indefinitely. After about five seconds,
+ // the app will be forced to exit.
+
+ // ... but first, let the app know it's about to go to the background.
+ // The separation of events may be important, given that the deferral
+ // runs in a separate thread. This'll make SDL_APP_WILLENTERBACKGROUND
+ // the only event among the two that runs in the main thread. Given
+ // that a few WinRT operations can only be done from the main thread
+ // (things that access the WinRT CoreWindow are one example of this),
+ // this could be important.
+ SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
+
+ SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
+ create_task([this, deferral]()
+ {
+ // Send an app did-enter-background event immediately to observers.
+ // CoreDispatcher::ProcessEvents, which is the backbone on which
+ // SDL_WinRTApp::PumpEvents is built, will not return to its caller
+ // once it sends out a suspend event. Any events posted to SDL's
+ // event queue won't get received until the WinRT app is resumed.
+ // SDL_AddEventWatch() may be used to receive app-suspend events on
+ // WinRT.
+ SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
+
+ // Let the Direct3D 11 renderer prepare for the app to be backgrounded.
+ // This is necessary for Windows 8.1, possibly elsewhere in the future.
+ // More details at: http://msdn.microsoft.com/en-us/library/windows/apps/Hh994929.aspx
+#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
+ if (WINRT_GlobalSDLWindow) {
+ SDL_Renderer * renderer = SDL_GetRenderer(WINRT_GlobalSDLWindow);
+ if (renderer && (SDL_strcmp(renderer->info.name, "direct3d11") == 0)) {
+ D3D11_Trim(renderer);
+ }
+ }
+#endif
+
+ deferral->Complete();
+ });
+}
+
+void SDL_WinRTApp::OnResuming(Platform::Object^ sender, Platform::Object^ args)
+{
+ // Restore any data or state that was unloaded on suspend. By default, data
+ // and state are persisted when resuming from suspend. Note that these events
+ // do not occur if the app was previously terminated.
+ SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
+ SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
+}
+
+void SDL_WinRTApp::OnExiting(Platform::Object^ sender, Platform::Object^ args)
+{
+ SDL_SendAppEvent(SDL_APP_TERMINATING);
+}
+
+static void
+WINRT_LogPointerEvent(const char * header, Windows::UI::Core::PointerEventArgs ^ args, Windows::Foundation::Point transformedPoint)
+{
+ Windows::UI::Input::PointerPoint ^ pt = args->CurrentPoint;
+ SDL_Log("%s: Position={%f,%f}, Transformed Pos={%f, %f}, MouseWheelDelta=%d, FrameId=%d, PointerId=%d, SDL button=%d\n",
+ header,
+ pt->Position.X, pt->Position.Y,
+ transformedPoint.X, transformedPoint.Y,
+ pt->Properties->MouseWheelDelta,
+ pt->FrameId,
+ pt->PointerId,
+ WINRT_GetSDLButtonForPointerPoint(pt));
+}
+
+void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
+{
+#if LOG_POINTER_EVENTS
+ WINRT_LogPointerEvent("pointer pressed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
+#endif
+
+ WINRT_ProcessPointerPressedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
+}
+
+void SDL_WinRTApp::OnPointerMoved(CoreWindow^ sender, PointerEventArgs^ args)
+{
+#if LOG_POINTER_EVENTS
+ WINRT_LogPointerEvent("pointer moved", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
+#endif
+
+ WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
+}
+
+void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
+{
+#if LOG_POINTER_EVENTS
+ WINRT_LogPointerEvent("pointer released", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
+#endif
+
+ WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
+}
+
+void SDL_WinRTApp::OnPointerEntered(CoreWindow^ sender, PointerEventArgs^ args)
+{
+#if LOG_POINTER_EVENTS
+ WINRT_LogPointerEvent("pointer entered", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
+#endif
+
+ WINRT_ProcessPointerEnteredEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
+}
+
+void SDL_WinRTApp::OnPointerExited(CoreWindow^ sender, PointerEventArgs^ args)
+{
+#if LOG_POINTER_EVENTS
+ WINRT_LogPointerEvent("pointer exited", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
+#endif
+
+ WINRT_ProcessPointerExitedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
+}
+
+void SDL_WinRTApp::OnPointerWheelChanged(CoreWindow^ sender, PointerEventArgs^ args)
+{
+#if LOG_POINTER_EVENTS
+ WINRT_LogPointerEvent("pointer wheel changed", args, WINRT_TransformCursorPosition(WINRT_GlobalSDLWindow, args->CurrentPoint->Position, TransformToSDLWindowSize));
+#endif
+
+ WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args->CurrentPoint);
+}
+
+void SDL_WinRTApp::OnMouseMoved(MouseDevice^ mouseDevice, MouseEventArgs^ args)
+{
+ WINRT_ProcessMouseMovedEvent(WINRT_GlobalSDLWindow, args);
+}
+
+void SDL_WinRTApp::OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
+{
+ WINRT_ProcessKeyDownEvent(args);
+}
+
+void SDL_WinRTApp::OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args)
+{
+ WINRT_ProcessKeyUpEvent(args);
+}
+
+void SDL_WinRTApp::OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args)
+{
+ WINRT_ProcessCharacterReceivedEvent(args);
+}
+
+template <typename BackButtonEventArgs>
+static void WINRT_OnBackButtonPressed(BackButtonEventArgs ^ args)
+{
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_AC_BACK);
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_AC_BACK);
+
+ if (SDL_GetHintBoolean(SDL_HINT_WINRT_HANDLE_BACK_BUTTON, SDL_FALSE)) {
+ args->Handled = true;
+ }
+}
+
+#if NTDDI_VERSION >= NTDDI_WIN10
+void SDL_WinRTApp::OnBackButtonPressed(Platform::Object^ sender, Windows::UI::Core::BackRequestedEventArgs^ args)
+
+{
+ WINRT_OnBackButtonPressed(args);
+}
+#elif WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+void SDL_WinRTApp::OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args)
+
+{
+ WINRT_OnBackButtonPressed(args);
+}
+#endif
+
+#if NTDDI_VERSION >= NTDDI_WIN10
+void SDL_WinRTApp::OnGamepadAdded(Platform::Object ^sender, Windows::Gaming::Input::Gamepad ^gamepad)
+{
+ /* HACK ALERT: Nothing needs to be done here, as this method currently
+ only exists to allow something to be registered with Win10's
+ GamepadAdded event, an operation that seems to be necessary to get
+ Xinput-based detection to work on Xbox One.
+ */
+}
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_direct3d.h b/src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_direct3d.h
new file mode 100644
index 0000000..7f52592
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_direct3d.h
@@ -0,0 +1,92 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include <Windows.h>
+
+extern int SDL_WinRTInitNonXAMLApp(int (*mainFunction)(int, char **));
+
+ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFrameworkView
+{
+public:
+ SDL_WinRTApp();
+
+ // IFrameworkView Methods.
+ virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView);
+ virtual void SetWindow(Windows::UI::Core::CoreWindow^ window);
+ virtual void Load(Platform::String^ entryPoint);
+ virtual void Run();
+ virtual void Uninitialize();
+
+internal:
+ // SDL-specific methods
+ void PumpEvents();
+
+protected:
+ bool ShouldWaitForAppResumeEvents();
+
+ // Event Handlers.
+
+#if (WINAPI_FAMILY == WINAPI_FAMILY_APP) && (NTDDI_VERSION < NTDDI_WIN10) // for Windows 8/8.1/RT apps... (and not Phone apps)
+ void OnSettingsPaneCommandsRequested(
+ Windows::UI::ApplicationSettings::SettingsPane ^p,
+ Windows::UI::ApplicationSettings::SettingsPaneCommandsRequestedEventArgs ^args);
+#endif // if (WINAPI_FAMILY == WINAPI_FAMILY_APP) && (NTDDI_VERSION < NTDDI_WIN10)
+
+#if NTDDI_VERSION > NTDDI_WIN8
+ void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args);
+#else
+ void OnOrientationChanged(Platform::Object^ sender);
+#endif
+ void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args);
+ void OnLogicalDpiChanged(Platform::Object^ sender);
+ void OnAppActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args);
+ void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ args);
+ void OnResuming(Platform::Object^ sender, Platform::Object^ args);
+ void OnExiting(Platform::Object^ sender, Platform::Object^ args);
+ void OnWindowActivated(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowActivatedEventArgs^ args);
+ void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args);
+ void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args);
+ void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
+ void OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
+ void OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
+ void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
+ void OnPointerEntered(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
+ void OnPointerExited(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
+ void OnMouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args);
+ void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
+ void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args);
+ void OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args);
+
+#if NTDDI_VERSION >= NTDDI_WIN10
+ void OnBackButtonPressed(Platform::Object^ sender, Windows::UI::Core::BackRequestedEventArgs^ args);
+#elif WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+ void OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args);
+#endif
+
+#if NTDDI_VERSION >= NTDDI_WIN10
+ void OnGamepadAdded(Platform::Object ^sender, Windows::Gaming::Input::Gamepad ^gamepad);
+#endif
+
+private:
+ bool m_windowClosed;
+ bool m_windowVisible;
+};
+
+extern SDL_WinRTApp ^ SDL_WinRTGlobalApp;
diff --git a/src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_xaml.cpp b/src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_xaml.cpp
new file mode 100644
index 0000000..9789d03
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_xaml.cpp
@@ -0,0 +1,160 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/* Windows includes */
+#include <agile.h>
+#include <Windows.h>
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_APP
+#include <windows.ui.xaml.media.dxinterop.h>
+#endif
+
+
+/* SDL includes */
+#include "../../SDL_internal.h"
+#include "SDL.h"
+#include "../../video/winrt/SDL_winrtevents_c.h"
+#include "../../video/winrt/SDL_winrtvideo_cpp.h"
+#include "SDL_winrtapp_common.h"
+#include "SDL_winrtapp_xaml.h"
+
+
+
+/* SDL-internal globals: */
+SDL_bool WINRT_XAMLWasEnabled = SDL_FALSE;
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_APP
+extern "C"
+ISwapChainBackgroundPanelNative * WINRT_GlobalSwapChainBackgroundPanelNative = NULL;
+static Windows::Foundation::EventRegistrationToken WINRT_XAMLAppEventToken;
+#endif
+
+
+/*
+ * Input event handlers (XAML)
+ */
+#if WINAPI_FAMILY == WINAPI_FAMILY_APP
+
+static void
+WINRT_OnPointerPressedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
+{
+ WINRT_ProcessPointerPressedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
+}
+
+static void
+WINRT_OnPointerMovedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
+{
+ WINRT_ProcessPointerMovedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
+}
+
+static void
+WINRT_OnPointerReleasedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
+{
+ WINRT_ProcessPointerReleasedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
+}
+
+static void
+WINRT_OnPointerWheelChangedViaXAML(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args)
+{
+ WINRT_ProcessPointerWheelChangedEvent(WINRT_GlobalSDLWindow, args->GetCurrentPoint(nullptr));
+}
+
+#endif // WINAPI_FAMILY == WINAPI_FAMILY_APP
+
+
+/*
+ * XAML-to-SDL Rendering Callback
+ */
+#if WINAPI_FAMILY == WINAPI_FAMILY_APP
+
+static void
+WINRT_OnRenderViaXAML(_In_ Platform::Object^ sender, _In_ Platform::Object^ args)
+{
+ WINRT_CycleXAMLThread();
+}
+
+#endif // WINAPI_FAMILY == WINAPI_FAMILY_APP
+
+
+/*
+ * SDL + XAML Initialization
+ */
+
+int
+SDL_WinRTInitXAMLApp(int (*mainFunction)(int, char **), void * backgroundPanelAsIInspectable)
+{
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+ return SDL_SetError("XAML support is not yet available in Windows Phone.");
+#else
+ // Declare C++/CX namespaces:
+ using namespace Platform;
+ using namespace Windows::Foundation;
+ using namespace Windows::UI::Core;
+ using namespace Windows::UI::Xaml;
+ using namespace Windows::UI::Xaml::Controls;
+ using namespace Windows::UI::Xaml::Input;
+ using namespace Windows::UI::Xaml::Media;
+
+ // Make sure we have a valid XAML element (to draw onto):
+ if ( ! backgroundPanelAsIInspectable) {
+ return SDL_SetError("'backgroundPanelAsIInspectable' can't be NULL");
+ }
+
+ Platform::Object ^ backgroundPanel = reinterpret_cast<Object ^>((IInspectable *) backgroundPanelAsIInspectable);
+ SwapChainBackgroundPanel ^swapChainBackgroundPanel = dynamic_cast<SwapChainBackgroundPanel ^>(backgroundPanel);
+ if ( ! swapChainBackgroundPanel) {
+ return SDL_SetError("An unknown or unsupported type of XAML control was specified.");
+ }
+
+ // Setup event handlers:
+ swapChainBackgroundPanel->PointerPressed += ref new PointerEventHandler(WINRT_OnPointerPressedViaXAML);
+ swapChainBackgroundPanel->PointerReleased += ref new PointerEventHandler(WINRT_OnPointerReleasedViaXAML);
+ swapChainBackgroundPanel->PointerWheelChanged += ref new PointerEventHandler(WINRT_OnPointerWheelChangedViaXAML);
+ swapChainBackgroundPanel->PointerMoved += ref new PointerEventHandler(WINRT_OnPointerMovedViaXAML);
+
+ // Setup for rendering:
+ IInspectable *panelInspectable = (IInspectable*) reinterpret_cast<IInspectable*>(swapChainBackgroundPanel);
+ panelInspectable->QueryInterface(__uuidof(ISwapChainBackgroundPanelNative), (void **)&WINRT_GlobalSwapChainBackgroundPanelNative);
+
+ WINRT_XAMLAppEventToken = CompositionTarget::Rendering::add(ref new EventHandler<Object^>(WINRT_OnRenderViaXAML));
+
+ // Make sure the app is ready to call the SDL-centric main() function:
+ WINRT_SDLAppEntryPoint = mainFunction;
+ SDL_SetMainReady();
+
+ // Make sure video-init knows that we're initializing XAML:
+ SDL_bool oldXAMLWasEnabledValue = WINRT_XAMLWasEnabled;
+ WINRT_XAMLWasEnabled = SDL_TRUE;
+
+ // Make sure video modes are detected now, while we still have access to the WinRT
+ // CoreWindow. WinRT will not allow the app's CoreWindow to be accessed via the
+ // SDL/WinRT thread.
+ if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
+ // SDL_InitSubSystem will, on error, set the SDL error. Let that propogate to
+ // the caller to here:
+ WINRT_XAMLWasEnabled = oldXAMLWasEnabledValue;
+ return -1;
+ }
+
+ // All done, for now.
+ return 0;
+#endif // WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP / else
+}
diff --git a/src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_xaml.h b/src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_xaml.h
new file mode 100644
index 0000000..85b4305
--- /dev/null
+++ b/src/3rdparty/SDL2/src/core/winrt/SDL_winrtapp_xaml.h
@@ -0,0 +1,33 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#ifndef SDL_winrtapp_xaml_h_
+#define SDL_winrtapp_xaml_h_
+
+#include "SDL_stdinc.h"
+
+#ifdef __cplusplus
+extern SDL_bool WINRT_XAMLWasEnabled;
+extern int SDL_WinRTInitXAMLApp(int (*mainFunction)(int, char **), void * backgroundPanelAsIInspectable);
+#endif // ifdef __cplusplus
+
+#endif // SDL_winrtapp_xaml_h_
diff --git a/src/3rdparty/SDL2/src/cpuinfo/SDL_cpuinfo.c b/src/3rdparty/SDL2/src/cpuinfo/SDL_cpuinfo.c
new file mode 100644
index 0000000..4e2c0f1
--- /dev/null
+++ b/src/3rdparty/SDL2/src/cpuinfo/SDL_cpuinfo.c
@@ -0,0 +1,777 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#ifdef TEST_MAIN
+#include "SDL_config.h"
+#else
+#include "../SDL_internal.h"
+#endif
+
+#if defined(__WIN32__)
+#include "../core/windows/SDL_windows.h"
+#endif
+#if defined(__OS2__)
+#define INCL_DOS
+#include <os2.h>
+#ifndef QSV_NUMPROCESSORS
+#define QSV_NUMPROCESSORS 26
+#endif
+#endif
+
+/* CPU feature detection for SDL */
+
+#include "SDL_cpuinfo.h"
+
+#ifdef HAVE_SYSCONF
+#include <unistd.h>
+#endif
+#ifdef HAVE_SYSCTLBYNAME
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
+#if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))
+#include <sys/sysctl.h> /* For AltiVec check */
+#elif defined(__OpenBSD__) && defined(__powerpc__)
+#include <sys/param.h>
+#include <sys/sysctl.h> /* For AltiVec check */
+#include <machine/cpu.h>
+#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
+#include <signal.h>
+#include <setjmp.h>
+#endif
+
+#if defined(__QNXNTO__)
+#include <sys/syspage.h>
+#endif
+
+#if (defined(__LINUX__) || defined(__ANDROID__)) && defined(__ARM_ARCH)
+/*#include <asm/hwcap.h>*/
+#ifndef AT_HWCAP
+#define AT_HWCAP 16
+#endif
+#ifndef HWCAP_NEON
+#define HWCAP_NEON (1 << 12)
+#endif
+#if defined HAVE_GETAUXVAL
+#include <sys/auxv.h>
+#else
+#include <fcntl.h>
+#endif
+#endif
+
+#define CPU_HAS_RDTSC 0x00000001
+#define CPU_HAS_ALTIVEC 0x00000002
+#define CPU_HAS_MMX 0x00000004
+#define CPU_HAS_3DNOW 0x00000008
+#define CPU_HAS_SSE 0x00000010
+#define CPU_HAS_SSE2 0x00000020
+#define CPU_HAS_SSE3 0x00000040
+#define CPU_HAS_SSE41 0x00000100
+#define CPU_HAS_SSE42 0x00000200
+#define CPU_HAS_AVX 0x00000400
+#define CPU_HAS_AVX2 0x00000800
+#define CPU_HAS_NEON 0x00001000
+
+#if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__ && !__OpenBSD__
+/* This is the brute force way of detecting instruction sets...
+ the idea is borrowed from the libmpeg2 library - thanks!
+ */
+static jmp_buf jmpbuf;
+static void
+illegal_instruction(int sig)
+{
+ longjmp(jmpbuf, 1);
+}
+#endif /* HAVE_SETJMP */
+
+static int
+CPU_haveCPUID(void)
+{
+ int has_CPUID = 0;
+
+/* *INDENT-OFF* */
+#ifndef SDL_CPUINFO_DISABLED
+#if defined(__GNUC__) && defined(i386)
+ __asm__ (
+" pushfl # Get original EFLAGS \n"
+" popl %%eax \n"
+" movl %%eax,%%ecx \n"
+" xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
+" pushl %%eax # Save new EFLAGS value on stack \n"
+" popfl # Replace current EFLAGS value \n"
+" pushfl # Get new EFLAGS \n"
+" popl %%eax # Store new EFLAGS in EAX \n"
+" xorl %%ecx,%%eax # Can not toggle ID bit, \n"
+" jz 1f # Processor=80486 \n"
+" movl $1,%0 # We have CPUID support \n"
+"1: \n"
+ : "=m" (has_CPUID)
+ :
+ : "%eax", "%ecx"
+ );
+#elif defined(__GNUC__) && defined(__x86_64__)
+/* Technically, if this is being compiled under __x86_64__ then it has
+ CPUid by definition. But it's nice to be able to prove it. :) */
+ __asm__ (
+" pushfq # Get original EFLAGS \n"
+" popq %%rax \n"
+" movq %%rax,%%rcx \n"
+" xorl $0x200000,%%eax # Flip ID bit in EFLAGS \n"
+" pushq %%rax # Save new EFLAGS value on stack \n"
+" popfq # Replace current EFLAGS value \n"
+" pushfq # Get new EFLAGS \n"
+" popq %%rax # Store new EFLAGS in EAX \n"
+" xorl %%ecx,%%eax # Can not toggle ID bit, \n"
+" jz 1f # Processor=80486 \n"
+" movl $1,%0 # We have CPUID support \n"
+"1: \n"
+ : "=m" (has_CPUID)
+ :
+ : "%rax", "%rcx"
+ );
+#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
+ __asm {
+ pushfd ; Get original EFLAGS
+ pop eax
+ mov ecx, eax
+ xor eax, 200000h ; Flip ID bit in EFLAGS
+ push eax ; Save new EFLAGS value on stack
+ popfd ; Replace current EFLAGS value
+ pushfd ; Get new EFLAGS
+ pop eax ; Store new EFLAGS in EAX
+ xor eax, ecx ; Can not toggle ID bit,
+ jz done ; Processor=80486
+ mov has_CPUID,1 ; We have CPUID support
+done:
+ }
+#elif defined(_MSC_VER) && defined(_M_X64)
+ has_CPUID = 1;
+#elif defined(__sun) && defined(__i386)
+ __asm (
+" pushfl \n"
+" popl %eax \n"
+" movl %eax,%ecx \n"
+" xorl $0x200000,%eax \n"
+" pushl %eax \n"
+" popfl \n"
+" pushfl \n"
+" popl %eax \n"
+" xorl %ecx,%eax \n"
+" jz 1f \n"
+" movl $1,-8(%ebp) \n"
+"1: \n"
+ );
+#elif defined(__sun) && defined(__amd64)
+ __asm (
+" pushfq \n"
+" popq %rax \n"
+" movq %rax,%rcx \n"
+" xorl $0x200000,%eax \n"
+" pushq %rax \n"
+" popfq \n"
+" pushfq \n"
+" popq %rax \n"
+" xorl %ecx,%eax \n"
+" jz 1f \n"
+" movl $1,-8(%rbp) \n"
+"1: \n"
+ );
+#endif
+#endif
+/* *INDENT-ON* */
+ return has_CPUID;
+}
+
+#if defined(__GNUC__) && defined(i386)
+#define cpuid(func, a, b, c, d) \
+ __asm__ __volatile__ ( \
+" pushl %%ebx \n" \
+" xorl %%ecx,%%ecx \n" \
+" cpuid \n" \
+" movl %%ebx, %%esi \n" \
+" popl %%ebx \n" : \
+ "=a" (a), "=S" (b), "=c" (c), "=d" (d) : "a" (func))
+#elif defined(__GNUC__) && defined(__x86_64__)
+#define cpuid(func, a, b, c, d) \
+ __asm__ __volatile__ ( \
+" pushq %%rbx \n" \
+" xorq %%rcx,%%rcx \n" \
+" cpuid \n" \
+" movq %%rbx, %%rsi \n" \
+" popq %%rbx \n" : \
+ "=a" (a), "=S" (b), "=c" (c), "=d" (d) : "a" (func))
+#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
+#define cpuid(func, a, b, c, d) \
+ __asm { \
+ __asm mov eax, func \
+ __asm xor ecx, ecx \
+ __asm cpuid \
+ __asm mov a, eax \
+ __asm mov b, ebx \
+ __asm mov c, ecx \
+ __asm mov d, edx \
+}
+#elif defined(_MSC_VER) && defined(_M_X64)
+#define cpuid(func, a, b, c, d) \
+{ \
+ int CPUInfo[4]; \
+ __cpuid(CPUInfo, func); \
+ a = CPUInfo[0]; \
+ b = CPUInfo[1]; \
+ c = CPUInfo[2]; \
+ d = CPUInfo[3]; \
+}
+#else
+#define cpuid(func, a, b, c, d) \
+ do { a = b = c = d = 0; (void) a; (void) b; (void) c; (void) d; } while (0)
+#endif
+
+static int CPU_CPUIDFeatures[4];
+static int CPU_CPUIDMaxFunction = 0;
+static SDL_bool CPU_OSSavesYMM = SDL_FALSE;
+
+static void
+CPU_calcCPUIDFeatures(void)
+{
+ static SDL_bool checked = SDL_FALSE;
+ if (!checked) {
+ checked = SDL_TRUE;
+ if (CPU_haveCPUID()) {
+ int a, b, c, d;
+ cpuid(0, a, b, c, d);
+ CPU_CPUIDMaxFunction = a;
+ if (CPU_CPUIDMaxFunction >= 1) {
+ cpuid(1, a, b, c, d);
+ CPU_CPUIDFeatures[0] = a;
+ CPU_CPUIDFeatures[1] = b;
+ CPU_CPUIDFeatures[2] = c;
+ CPU_CPUIDFeatures[3] = d;
+
+ /* Check to make sure we can call xgetbv */
+ if (c & 0x08000000) {
+ /* Call xgetbv to see if YMM register state is saved */
+#if defined(__GNUC__) && (defined(i386) || defined(__x86_64__))
+ __asm__(".byte 0x0f, 0x01, 0xd0" : "=a" (a) : "c" (0) : "%edx");
+#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) && (_MSC_FULL_VER >= 160040219) /* VS2010 SP1 */
+ a = (int)_xgetbv(0);
+#elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
+ __asm
+ {
+ xor ecx, ecx
+ _asm _emit 0x0f _asm _emit 0x01 _asm _emit 0xd0
+ mov a, eax
+ }
+#endif
+ CPU_OSSavesYMM = ((a & 6) == 6) ? SDL_TRUE : SDL_FALSE;
+ }
+ }
+ }
+ }
+}
+
+static int
+CPU_haveAltiVec(void)
+{
+ volatile int altivec = 0;
+#ifndef SDL_CPUINFO_DISABLED
+#if (defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))) || (defined(__OpenBSD__) && defined(__powerpc__))
+#ifdef __OpenBSD__
+ int selectors[2] = { CTL_MACHDEP, CPU_ALTIVEC };
+#else
+ int selectors[2] = { CTL_HW, HW_VECTORUNIT };
+#endif
+ int hasVectorUnit = 0;
+ size_t length = sizeof(hasVectorUnit);
+ int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0);
+ if (0 == error)
+ altivec = (hasVectorUnit != 0);
+#elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
+ void (*handler) (int sig);
+ handler = signal(SIGILL, illegal_instruction);
+ if (setjmp(jmpbuf) == 0) {
+ asm volatile ("mtspr 256, %0\n\t" "vand %%v0, %%v0, %%v0"::"r" (-1));
+ altivec = 1;
+ }
+ signal(SIGILL, handler);
+#endif
+#endif
+ return altivec;
+}
+
+#if (defined(__LINUX__) || defined(__ANDROID__)) && defined(__ARM_ARCH) && !defined(HAVE_GETAUXVAL)
+static int
+readProcAuxvForNeon(void)
+{
+ int neon = 0;
+ int kv[2];
+ const int fd = open("/proc/self/auxv", O_RDONLY);
+ if (fd != -1) {
+ while (read(fd, kv, sizeof (kv)) == sizeof (kv)) {
+ if (kv[0] == AT_HWCAP) {
+ neon = ((kv[1] & HWCAP_NEON) == HWCAP_NEON);
+ break;
+ }
+ }
+ close(fd);
+ }
+ return neon;
+}
+#endif
+
+
+static int
+CPU_haveNEON(void)
+{
+/* The way you detect NEON is a privileged instruction on ARM, so you have
+ query the OS kernel in a platform-specific way. :/ */
+#if defined(SDL_CPUINFO_DISABLED) || !defined(__ARM_ARCH)
+ return 0; /* disabled or not an ARM CPU at all. */
+#elif __ARM_ARCH >= 8
+ return 1; /* ARMv8 always has non-optional NEON support. */
+#elif defined(__APPLE__) && (__ARM_ARCH >= 7)
+ /* (note that sysctlbyname("hw.optional.neon") doesn't work!) */
+ return 1; /* all Apple ARMv7 chips and later have NEON. */
+#elif defined(__APPLE__)
+ return 0; /* assume anything else from Apple doesn't have NEON. */
+#elif defined(__QNXNTO__)
+ return SYSPAGE_ENTRY(cpuinfo)->flags & ARM_CPU_FLAG_NEON;
+#elif (defined(__LINUX__) || defined(__ANDROID__)) && defined(HAVE_GETAUXVAL)
+ return ((getauxval(AT_HWCAP) & HWCAP_NEON) == HWCAP_NEON);
+#elif (defined(__LINUX__) || defined(__ANDROID__))
+ return readProcAuxvForNeon(); /* Android offers a static library for this, but it just parses /proc/self/auxv */
+#elif (defined(__WINDOWS__) || defined(__WINRT__)) && defined(_M_ARM)
+ /* All WinRT ARM devices are required to support NEON, but just in case. */
+ return IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE) != 0;
+#else
+#warning SDL_HasNEON is not implemented for this ARM platform. Write me.
+ return 0;
+#endif
+}
+
+static int
+CPU_have3DNow(void)
+{
+ if (CPU_CPUIDMaxFunction > 0) { /* that is, do we have CPUID at all? */
+ int a, b, c, d;
+ cpuid(0x80000000, a, b, c, d);
+ if (a >= 0x80000001) {
+ cpuid(0x80000001, a, b, c, d);
+ return (d & 0x80000000);
+ }
+ }
+ return 0;
+}
+
+#define CPU_haveRDTSC() (CPU_CPUIDFeatures[3] & 0x00000010)
+#define CPU_haveMMX() (CPU_CPUIDFeatures[3] & 0x00800000)
+#define CPU_haveSSE() (CPU_CPUIDFeatures[3] & 0x02000000)
+#define CPU_haveSSE2() (CPU_CPUIDFeatures[3] & 0x04000000)
+#define CPU_haveSSE3() (CPU_CPUIDFeatures[2] & 0x00000001)
+#define CPU_haveSSE41() (CPU_CPUIDFeatures[2] & 0x00080000)
+#define CPU_haveSSE42() (CPU_CPUIDFeatures[2] & 0x00100000)
+#define CPU_haveAVX() (CPU_OSSavesYMM && (CPU_CPUIDFeatures[2] & 0x10000000))
+
+static int
+CPU_haveAVX2(void)
+{
+ if (CPU_OSSavesYMM && (CPU_CPUIDMaxFunction >= 7)) {
+ int a, b, c, d;
+ (void) a; (void) b; (void) c; (void) d; /* compiler warnings... */
+ cpuid(7, a, b, c, d);
+ return (b & 0x00000020);
+ }
+ return 0;
+}
+
+static int SDL_CPUCount = 0;
+
+int
+SDL_GetCPUCount(void)
+{
+ if (!SDL_CPUCount) {
+#ifndef SDL_CPUINFO_DISABLED
+#if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
+ if (SDL_CPUCount <= 0) {
+ SDL_CPUCount = (int)sysconf(_SC_NPROCESSORS_ONLN);
+ }
+#endif
+#ifdef HAVE_SYSCTLBYNAME
+ if (SDL_CPUCount <= 0) {
+ size_t size = sizeof(SDL_CPUCount);
+ sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
+ }
+#endif
+#ifdef __WIN32__
+ if (SDL_CPUCount <= 0) {
+ SYSTEM_INFO info;
+ GetSystemInfo(&info);
+ SDL_CPUCount = info.dwNumberOfProcessors;
+ }
+#endif
+#ifdef __OS2__
+ if (SDL_CPUCount <= 0) {
+ DosQuerySysInfo(QSV_NUMPROCESSORS, QSV_NUMPROCESSORS,
+ &SDL_CPUCount, sizeof(SDL_CPUCount) );
+ }
+#endif
+#endif
+ /* There has to be at least 1, right? :) */
+ if (SDL_CPUCount <= 0) {
+ SDL_CPUCount = 1;
+ }
+ }
+ return SDL_CPUCount;
+}
+
+/* Oh, such a sweet sweet trick, just not very useful. :) */
+static const char *
+SDL_GetCPUType(void)
+{
+ static char SDL_CPUType[13];
+
+ if (!SDL_CPUType[0]) {
+ int i = 0;
+
+ CPU_calcCPUIDFeatures();
+ if (CPU_CPUIDMaxFunction > 0) { /* do we have CPUID at all? */
+ int a, b, c, d;
+ cpuid(0x00000000, a, b, c, d);
+ (void) a;
+ SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
+ SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
+ SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
+ SDL_CPUType[i++] = (char)(b & 0xff);
+
+ SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
+ SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
+ SDL_CPUType[i++] = (char)(d & 0xff); d >>= 8;
+ SDL_CPUType[i++] = (char)(d & 0xff);
+
+ SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
+ SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
+ SDL_CPUType[i++] = (char)(c & 0xff); c >>= 8;
+ SDL_CPUType[i++] = (char)(c & 0xff);
+ }
+ if (!SDL_CPUType[0]) {
+ SDL_strlcpy(SDL_CPUType, "Unknown", sizeof(SDL_CPUType));
+ }
+ }
+ return SDL_CPUType;
+}
+
+
+#ifdef TEST_MAIN /* !!! FIXME: only used for test at the moment. */
+static const char *
+SDL_GetCPUName(void)
+{
+ static char SDL_CPUName[48];
+
+ if (!SDL_CPUName[0]) {
+ int i = 0;
+ int a, b, c, d;
+
+ CPU_calcCPUIDFeatures();
+ if (CPU_CPUIDMaxFunction > 0) { /* do we have CPUID at all? */
+ cpuid(0x80000000, a, b, c, d);
+ if (a >= 0x80000004) {
+ cpuid(0x80000002, a, b, c, d);
+ SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
+ SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
+ SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
+ SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
+ SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
+ SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
+ SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
+ SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
+ SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
+ SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
+ SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
+ SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
+ SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
+ SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
+ SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
+ SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
+ cpuid(0x80000003, a, b, c, d);
+ SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
+ SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
+ SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
+ SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
+ SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
+ SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
+ SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
+ SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
+ SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
+ SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
+ SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
+ SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
+ SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
+ SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
+ SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
+ SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
+ cpuid(0x80000004, a, b, c, d);
+ SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
+ SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
+ SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
+ SDL_CPUName[i++] = (char)(a & 0xff); a >>= 8;
+ SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
+ SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
+ SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
+ SDL_CPUName[i++] = (char)(b & 0xff); b >>= 8;
+ SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
+ SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
+ SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
+ SDL_CPUName[i++] = (char)(c & 0xff); c >>= 8;
+ SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
+ SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
+ SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
+ SDL_CPUName[i++] = (char)(d & 0xff); d >>= 8;
+ }
+ }
+ if (!SDL_CPUName[0]) {
+ SDL_strlcpy(SDL_CPUName, "Unknown", sizeof(SDL_CPUName));
+ }
+ }
+ return SDL_CPUName;
+}
+#endif
+
+int
+SDL_GetCPUCacheLineSize(void)
+{
+ const char *cpuType = SDL_GetCPUType();
+ int a, b, c, d;
+ (void) a; (void) b; (void) c; (void) d;
+ if (SDL_strcmp(cpuType, "GenuineIntel") == 0) {
+ cpuid(0x00000001, a, b, c, d);
+ return (((b >> 8) & 0xff) * 8);
+ } else if (SDL_strcmp(cpuType, "AuthenticAMD") == 0) {
+ cpuid(0x80000005, a, b, c, d);
+ return (c & 0xff);
+ } else {
+ /* Just make a guess here... */
+ return SDL_CACHELINE_SIZE;
+ }
+}
+
+static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
+
+static Uint32
+SDL_GetCPUFeatures(void)
+{
+ if (SDL_CPUFeatures == 0xFFFFFFFF) {
+ CPU_calcCPUIDFeatures();
+ SDL_CPUFeatures = 0;
+ if (CPU_haveRDTSC()) {
+ SDL_CPUFeatures |= CPU_HAS_RDTSC;
+ }
+ if (CPU_haveAltiVec()) {
+ SDL_CPUFeatures |= CPU_HAS_ALTIVEC;
+ }
+ if (CPU_haveMMX()) {
+ SDL_CPUFeatures |= CPU_HAS_MMX;
+ }
+ if (CPU_have3DNow()) {
+ SDL_CPUFeatures |= CPU_HAS_3DNOW;
+ }
+ if (CPU_haveSSE()) {
+ SDL_CPUFeatures |= CPU_HAS_SSE;
+ }
+ if (CPU_haveSSE2()) {
+ SDL_CPUFeatures |= CPU_HAS_SSE2;
+ }
+ if (CPU_haveSSE3()) {
+ SDL_CPUFeatures |= CPU_HAS_SSE3;
+ }
+ if (CPU_haveSSE41()) {
+ SDL_CPUFeatures |= CPU_HAS_SSE41;
+ }
+ if (CPU_haveSSE42()) {
+ SDL_CPUFeatures |= CPU_HAS_SSE42;
+ }
+ if (CPU_haveAVX()) {
+ SDL_CPUFeatures |= CPU_HAS_AVX;
+ }
+ if (CPU_haveAVX2()) {
+ SDL_CPUFeatures |= CPU_HAS_AVX2;
+ }
+ if (CPU_haveNEON()) {
+ SDL_CPUFeatures |= CPU_HAS_NEON;
+ }
+ }
+ return SDL_CPUFeatures;
+}
+
+#define CPU_FEATURE_AVAILABLE(f) ((SDL_GetCPUFeatures() & f) ? SDL_TRUE : SDL_FALSE)
+
+SDL_bool SDL_HasRDTSC(void)
+{
+ return CPU_FEATURE_AVAILABLE(CPU_HAS_RDTSC);
+}
+
+SDL_bool
+SDL_HasAltiVec(void)
+{
+ return CPU_FEATURE_AVAILABLE(CPU_HAS_ALTIVEC);
+}
+
+SDL_bool
+SDL_HasMMX(void)
+{
+ return CPU_FEATURE_AVAILABLE(CPU_HAS_MMX);
+}
+
+SDL_bool
+SDL_Has3DNow(void)
+{
+ return CPU_FEATURE_AVAILABLE(CPU_HAS_3DNOW);
+}
+
+SDL_bool
+SDL_HasSSE(void)
+{
+ return CPU_FEATURE_AVAILABLE(CPU_HAS_SSE);
+}
+
+SDL_bool
+SDL_HasSSE2(void)
+{
+ return CPU_FEATURE_AVAILABLE(CPU_HAS_SSE2);
+}
+
+SDL_bool
+SDL_HasSSE3(void)
+{
+ return CPU_FEATURE_AVAILABLE(CPU_HAS_SSE3);
+}
+
+SDL_bool
+SDL_HasSSE41(void)
+{
+ return CPU_FEATURE_AVAILABLE(CPU_HAS_SSE41);
+}
+
+SDL_bool
+SDL_HasSSE42(void)
+{
+ return CPU_FEATURE_AVAILABLE(CPU_HAS_SSE42);
+}
+
+SDL_bool
+SDL_HasAVX(void)
+{
+ return CPU_FEATURE_AVAILABLE(CPU_HAS_AVX);
+}
+
+SDL_bool
+SDL_HasAVX2(void)
+{
+ return CPU_FEATURE_AVAILABLE(CPU_HAS_AVX2);
+}
+
+SDL_bool
+SDL_HasNEON(void)
+{
+ return CPU_FEATURE_AVAILABLE(CPU_HAS_NEON);
+}
+
+static int SDL_SystemRAM = 0;
+
+int
+SDL_GetSystemRAM(void)
+{
+ if (!SDL_SystemRAM) {
+#ifndef SDL_CPUINFO_DISABLED
+#if defined(HAVE_SYSCONF) && defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE)
+ if (SDL_SystemRAM <= 0) {
+ SDL_SystemRAM = (int)((Sint64)sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE) / (1024*1024));
+ }
+#endif
+#ifdef HAVE_SYSCTLBYNAME
+ if (SDL_SystemRAM <= 0) {
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
+#ifdef HW_REALMEM
+ int mib[2] = {CTL_HW, HW_REALMEM};
+#else
+ /* might only report up to 2 GiB */
+ int mib[2] = {CTL_HW, HW_PHYSMEM};
+#endif /* HW_REALMEM */
+#else
+ int mib[2] = {CTL_HW, HW_MEMSIZE};
+#endif /* __FreeBSD__ || __FreeBSD_kernel__ */
+ Uint64 memsize = 0;
+ size_t len = sizeof(memsize);
+
+ if (sysctl(mib, 2, &memsize, &len, NULL, 0) == 0) {
+ SDL_SystemRAM = (int)(memsize / (1024*1024));
+ }
+ }
+#endif
+#ifdef __WIN32__
+ if (SDL_SystemRAM <= 0) {
+ MEMORYSTATUSEX stat;
+ stat.dwLength = sizeof(stat);
+ if (GlobalMemoryStatusEx(&stat)) {
+ SDL_SystemRAM = (int)(stat.ullTotalPhys / (1024 * 1024));
+ }
+ }
+#endif
+#ifdef __OS2__
+ if (SDL_SystemRAM <= 0) {
+ Uint32 sysram = 0;
+ DosQuerySysInfo(QSV_TOTPHYSMEM, QSV_TOTPHYSMEM, &sysram, 4);
+ SDL_SystemRAM = (int) (sysram / 0x100000U);
+ }
+#endif
+#endif
+ }
+ return SDL_SystemRAM;
+}
+
+
+#ifdef TEST_MAIN
+
+#include <stdio.h>
+
+int
+main()
+{
+ printf("CPU count: %d\n", SDL_GetCPUCount());
+ printf("CPU type: %s\n", SDL_GetCPUType());
+ printf("CPU name: %s\n", SDL_GetCPUName());
+ printf("CacheLine size: %d\n", SDL_GetCPUCacheLineSize());
+ printf("RDTSC: %d\n", SDL_HasRDTSC());
+ printf("Altivec: %d\n", SDL_HasAltiVec());
+ printf("MMX: %d\n", SDL_HasMMX());
+ printf("3DNow: %d\n", SDL_Has3DNow());
+ printf("SSE: %d\n", SDL_HasSSE());
+ printf("SSE2: %d\n", SDL_HasSSE2());
+ printf("SSE3: %d\n", SDL_HasSSE3());
+ printf("SSE4.1: %d\n", SDL_HasSSE41());
+ printf("SSE4.2: %d\n", SDL_HasSSE42());
+ printf("AVX: %d\n", SDL_HasAVX());
+ printf("AVX2: %d\n", SDL_HasAVX2());
+ printf("NEON: %d\n", SDL_HasNEON());
+ printf("RAM: %d MB\n", SDL_GetSystemRAM());
+ return 0;
+}
+
+#endif /* TEST_MAIN */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/dynapi/SDL_dynapi.c b/src/3rdparty/SDL2/src/dynapi/SDL_dynapi.c
new file mode 100644
index 0000000..b898826
--- /dev/null
+++ b/src/3rdparty/SDL2/src/dynapi/SDL_dynapi.c
@@ -0,0 +1,325 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "SDL_config.h"
+#include "SDL_dynapi.h"
+
+#if SDL_DYNAMIC_API
+
+#if defined(__OS2__)
+#define INCL_DOS
+#define INCL_DOSERRORS
+#include <dos.h>
+#endif
+
+#include "SDL.h"
+
+/* These headers have system specific definitions, so aren't included above */
+#include "SDL_syswm.h"
+#include "SDL_vulkan.h"
+
+/* This is the version of the dynamic API. This doesn't match the SDL version
+ and should not change until there's been a major revamp in API/ABI.
+ So 2.0.5 adds functions over 2.0.4? This number doesn't change;
+ the sizeof (jump_table) changes instead. But 2.1.0 changes how a function
+ works in an incompatible way or removes a function? This number changes,
+ since sizeof (jump_table) isn't sufficient anymore. It's likely
+ we'll forget to bump every time we add a function, so this is the
+ failsafe switch for major API change decisions. Respect it and use it
+ sparingly. */
+#define SDL_DYNAPI_VERSION 1
+
+static void SDL_InitDynamicAPI(void);
+
+
+/* BE CAREFUL CALLING ANY SDL CODE IN HERE, IT WILL BLOW UP.
+ Even self-contained stuff might call SDL_Error and break everything. */
+
+
+/* behold, the macro salsa! */
+
+/* !!! FIXME: ...disabled...until we write it. :) */
+#define DISABLE_JUMP_MAGIC 1
+
+#if DISABLE_JUMP_MAGIC
+/* Can't use the macro for varargs nonsense. This is atrocious. */
+#define SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, logname, prio) \
+ _static void SDLCALL SDL_Log##logname##name(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
+ va_list ap; initcall; va_start(ap, fmt); \
+ jump_table.SDL_LogMessageV(category, SDL_LOG_PRIORITY_##prio, fmt, ap); \
+ va_end(ap); \
+ }
+
+#define SDL_DYNAPI_VARARGS(_static, name, initcall) \
+ _static int SDLCALL SDL_SetError##name(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
+ char buf[512]; /* !!! FIXME: dynamic allocation */ \
+ va_list ap; initcall; va_start(ap, fmt); \
+ jump_table.SDL_vsnprintf(buf, sizeof (buf), fmt, ap); \
+ va_end(ap); \
+ return jump_table.SDL_SetError("%s", buf); \
+ } \
+ _static int SDLCALL SDL_sscanf##name(const char *buf, SDL_SCANF_FORMAT_STRING const char *fmt, ...) { \
+ int retval; va_list ap; initcall; va_start(ap, fmt); \
+ retval = jump_table.SDL_vsscanf(buf, fmt, ap); \
+ va_end(ap); \
+ return retval; \
+ } \
+ _static int SDLCALL SDL_snprintf##name(SDL_OUT_Z_CAP(maxlen) char *buf, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
+ int retval; va_list ap; initcall; va_start(ap, fmt); \
+ retval = jump_table.SDL_vsnprintf(buf, maxlen, fmt, ap); \
+ va_end(ap); \
+ return retval; \
+ } \
+ _static void SDLCALL SDL_Log##name(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
+ va_list ap; initcall; va_start(ap, fmt); \
+ jump_table.SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, fmt, ap); \
+ va_end(ap); \
+ } \
+ _static void SDLCALL SDL_LogMessage##name(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
+ va_list ap; initcall; va_start(ap, fmt); \
+ jump_table.SDL_LogMessageV(category, priority, fmt, ap); \
+ va_end(ap); \
+ } \
+ SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, Verbose, VERBOSE) \
+ SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, Debug, DEBUG) \
+ SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, Info, INFO) \
+ SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, Warn, WARN) \
+ SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, Error, ERROR) \
+ SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, Critical, CRITICAL)
+#endif
+
+
+/* Typedefs for function pointers for jump table, and predeclare funcs */
+/* The DEFAULT funcs will init jump table and then call real function. */
+/* The REAL funcs are the actual functions, name-mangled to not clash. */
+#define SDL_DYNAPI_PROC(rc,fn,params,args,ret) \
+ typedef rc (SDLCALL *SDL_DYNAPIFN_##fn) params; \
+ static rc SDLCALL fn##_DEFAULT params; \
+ extern rc SDLCALL fn##_REAL params;
+#include "SDL_dynapi_procs.h"
+#undef SDL_DYNAPI_PROC
+
+/* The jump table! */
+typedef struct {
+ #define SDL_DYNAPI_PROC(rc,fn,params,args,ret) SDL_DYNAPIFN_##fn fn;
+ #include "SDL_dynapi_procs.h"
+ #undef SDL_DYNAPI_PROC
+} SDL_DYNAPI_jump_table;
+
+/* Predeclare the default functions for initializing the jump table. */
+#define SDL_DYNAPI_PROC(rc,fn,params,args,ret) static rc SDLCALL fn##_DEFAULT params;
+#include "SDL_dynapi_procs.h"
+#undef SDL_DYNAPI_PROC
+
+/* The actual jump table. */
+static SDL_DYNAPI_jump_table jump_table = {
+ #define SDL_DYNAPI_PROC(rc,fn,params,args,ret) fn##_DEFAULT,
+ #include "SDL_dynapi_procs.h"
+ #undef SDL_DYNAPI_PROC
+};
+
+/* Default functions init the function table then call right thing. */
+#if DISABLE_JUMP_MAGIC
+#define SDL_DYNAPI_PROC(rc,fn,params,args,ret) \
+ static rc SDLCALL fn##_DEFAULT params { \
+ SDL_InitDynamicAPI(); \
+ ret jump_table.fn args; \
+ }
+#define SDL_DYNAPI_PROC_NO_VARARGS 1
+#include "SDL_dynapi_procs.h"
+#undef SDL_DYNAPI_PROC
+#undef SDL_DYNAPI_PROC_NO_VARARGS
+SDL_DYNAPI_VARARGS(static, _DEFAULT, SDL_InitDynamicAPI())
+#else
+/* !!! FIXME: need the jump magic. */
+#error Write me.
+#endif
+
+/* Public API functions to jump into the jump table. */
+#if DISABLE_JUMP_MAGIC
+#define SDL_DYNAPI_PROC(rc,fn,params,args,ret) \
+ rc SDLCALL fn params { ret jump_table.fn args; }
+#define SDL_DYNAPI_PROC_NO_VARARGS 1
+#include "SDL_dynapi_procs.h"
+#undef SDL_DYNAPI_PROC
+#undef SDL_DYNAPI_PROC_NO_VARARGS
+SDL_DYNAPI_VARARGS(,,)
+#else
+/* !!! FIXME: need the jump magic. */
+#error Write me.
+#endif
+
+
+
+/* Here's the exported entry point that fills in the jump table. */
+/* Use specific types when an "int" might suffice to keep this sane. */
+typedef Sint32 (SDLCALL *SDL_DYNAPI_ENTRYFN)(Uint32 apiver, void *table, Uint32 tablesize);
+extern DECLSPEC Sint32 SDLCALL SDL_DYNAPI_entry(Uint32, void *, Uint32);
+
+Sint32
+SDL_DYNAPI_entry(Uint32 apiver, void *table, Uint32 tablesize)
+{
+ SDL_DYNAPI_jump_table *output_jump_table = (SDL_DYNAPI_jump_table *) table;
+
+ if (apiver != SDL_DYNAPI_VERSION) {
+ /* !!! FIXME: can maybe handle older versions? */
+ return -1; /* not compatible. */
+ } else if (tablesize > sizeof (jump_table)) {
+ return -1; /* newer version of SDL with functions we can't provide. */
+ }
+
+ /* Init our jump table first. */
+ #define SDL_DYNAPI_PROC(rc,fn,params,args,ret) jump_table.fn = fn##_REAL;
+ #include "SDL_dynapi_procs.h"
+ #undef SDL_DYNAPI_PROC
+
+ /* Then the external table... */
+ if (output_jump_table != &jump_table) {
+ jump_table.SDL_memcpy(output_jump_table, &jump_table, tablesize);
+ }
+
+ /* Safe to call SDL functions now; jump table is initialized! */
+
+ return 0; /* success! */
+}
+
+
+/* Obviously we can't use SDL_LoadObject() to load SDL. :) */
+/* Also obviously, we never close the loaded library. */
+#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN 1
+#endif
+#include <windows.h>
+static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
+{
+ HANDLE lib = LoadLibraryA(fname);
+ void *retval = NULL;
+ if (lib) {
+ retval = GetProcAddress(lib, sym);
+ if (retval == NULL) {
+ FreeLibrary(lib);
+ }
+ }
+ return retval;
+}
+
+#elif defined(unix) || defined(__unix__) || defined(__APPLE__) || defined(__HAIKU__) || defined(__QNX__)
+#include <dlfcn.h>
+static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
+{
+ void *lib = dlopen(fname, RTLD_NOW | RTLD_LOCAL);
+ void *retval = NULL;
+ if (lib != NULL) {
+ retval = dlsym(lib, sym);
+ if (retval == NULL) {
+ dlclose(lib);
+ }
+ }
+ return retval;
+}
+
+#elif defined(__OS2__)
+static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
+{
+ HMODULE hmodule;
+ PFN retval = NULL;
+ char error[256];
+ if (DosLoadModule(&error, sizeof(error), fname, &hmodule) == NO_ERROR) {
+ if (DosQueryProcAddr(hmodule, 0, sym, &retval) != NO_ERROR) {
+ DosFreeModule(hmodule);
+ }
+ }
+ return (void *) retval;
+}
+
+#else
+#error Please define your platform.
+#endif
+
+
+static void
+SDL_InitDynamicAPILocked(void)
+{
+ const char *libname = SDL_getenv_REAL("SDL_DYNAMIC_API");
+ SDL_DYNAPI_ENTRYFN entry = SDL_DYNAPI_entry; /* funcs from here by default. */
+
+ if (libname) {
+ entry = (SDL_DYNAPI_ENTRYFN) get_sdlapi_entry(libname, "SDL_DYNAPI_entry");
+ if (!entry) {
+ /* !!! FIXME: fail to startup here instead? */
+ /* !!! FIXME: definitely warn user. */
+ /* Just fill in the function pointers from this library. */
+ entry = SDL_DYNAPI_entry;
+ }
+ }
+
+ if (entry(SDL_DYNAPI_VERSION, &jump_table, sizeof (jump_table)) < 0) {
+ /* !!! FIXME: fail to startup here instead? */
+ /* !!! FIXME: definitely warn user. */
+ /* Just fill in the function pointers from this library. */
+ if (entry != SDL_DYNAPI_entry) {
+ if (!SDL_DYNAPI_entry(SDL_DYNAPI_VERSION, &jump_table, sizeof (jump_table))) {
+ /* !!! FIXME: now we're screwed. Should definitely abort now. */
+ }
+ }
+ }
+
+ /* we intentionally never close the newly-loaded lib, of course. */
+}
+
+static void
+SDL_InitDynamicAPI(void)
+{
+ /* So the theory is that every function in the jump table defaults to
+ * calling this function, and then replaces itself with a version that
+ * doesn't call this function anymore. But it's possible that, in an
+ * extreme corner case, you can have a second thread hit this function
+ * while the jump table is being initialized by the first.
+ * In this case, a spinlock is really painful compared to what spinlocks
+ * _should_ be used for, but this would only happen once, and should be
+ * insanely rare, as you would have to spin a thread outside of SDL (as
+ * SDL_CreateThread() would also call this function before building the
+ * new thread).
+ */
+ static SDL_bool already_initialized = SDL_FALSE;
+
+ /* SDL_AtomicLock calls SDL mutex functions to emulate if
+ SDL_ATOMIC_DISABLED, which we can't do here, so in such a
+ configuration, you're on your own. */
+ #if !SDL_ATOMIC_DISABLED
+ static SDL_SpinLock lock = 0;
+ SDL_AtomicLock_REAL(&lock);
+ #endif
+
+ if (!already_initialized) {
+ SDL_InitDynamicAPILocked();
+ already_initialized = SDL_TRUE;
+ }
+
+ #if !SDL_ATOMIC_DISABLED
+ SDL_AtomicUnlock_REAL(&lock);
+ #endif
+}
+
+#endif /* SDL_DYNAMIC_API */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/dynapi/SDL_dynapi.h b/src/3rdparty/SDL2/src/dynapi/SDL_dynapi.h
new file mode 100644
index 0000000..73316f1
--- /dev/null
+++ b/src/3rdparty/SDL2/src/dynapi/SDL_dynapi.h
@@ -0,0 +1,67 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_dynapi_h_
+#define SDL_dynapi_h_
+
+/* IMPORTANT:
+ This is the master switch to disabling the dynamic API. We made it so you
+ have to hand-edit an internal source file in SDL to turn it off; you
+ can do it if you want it badly enough, but hopefully you won't want to.
+ You should understand the ramifications of turning this off: it makes it
+ hard to update your SDL in the field, and impossible if you've statically
+ linked SDL into your app. Understand that platforms change, and if we can't
+ drop in an updated SDL, your application can definitely break some time
+ in the future, even if it's fine today.
+ To be sure, as new system-level video and audio APIs are introduced, an
+ updated SDL can transparently take advantage of them, but your program will
+ not without this feature. Think hard before turning it off.
+*/
+#ifdef SDL_DYNAMIC_API /* Tried to force it on the command line? */
+#error Nope, you have to edit this file to force this off.
+#endif
+
+#ifdef __APPLE__
+#include "TargetConditionals.h"
+#endif
+
+#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE /* probably not useful on iOS. */
+#define SDL_DYNAMIC_API 0
+#elif defined(__native_client__) && __native_client__ /* probably not useful on NACL. */
+#define SDL_DYNAMIC_API 0
+#elif defined(__EMSCRIPTEN__) && __EMSCRIPTEN__ /* probably not useful on Emscripten. */
+#define SDL_DYNAMIC_API 0
+#elif defined(SDL_BUILDING_WINRT) && SDL_BUILDING_WINRT /* probably not useful on WinRT, given current .dll loading restrictions */
+#define SDL_DYNAMIC_API 0
+#elif defined(__PSP__) && __PSP__
+#define SDL_DYNAMIC_API 0
+#elif defined(__clang_analyzer__)
+#define SDL_DYNAMIC_API 0 /* Turn off for static analysis, so reports are more clear. */
+#endif
+
+/* everyone else. This is where we turn on the API if nothing forced it off. */
+#ifndef SDL_DYNAMIC_API
+#define SDL_DYNAMIC_API 1
+#endif
+
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/dynapi/SDL_dynapi_overrides.h b/src/3rdparty/SDL2/src/dynapi/SDL_dynapi_overrides.h
new file mode 100644
index 0000000..1ec2eaf
--- /dev/null
+++ b/src/3rdparty/SDL2/src/dynapi/SDL_dynapi_overrides.h
@@ -0,0 +1,671 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/* vi: set ts=4 sw=4 expandtab: */
+
+/* DO NOT EDIT THIS FILE BY HAND. It is autogenerated by gendynapi.pl. */
+
+#if !SDL_DYNAMIC_API
+#error You should not be here.
+#endif
+
+#define SDL_SetError SDL_SetError_REAL
+#define SDL_Log SDL_Log_REAL
+#define SDL_LogVerbose SDL_LogVerbose_REAL
+#define SDL_LogDebug SDL_LogDebug_REAL
+#define SDL_LogInfo SDL_LogInfo_REAL
+#define SDL_LogWarn SDL_LogWarn_REAL
+#define SDL_LogError SDL_LogError_REAL
+#define SDL_LogCritical SDL_LogCritical_REAL
+#define SDL_LogMessage SDL_LogMessage_REAL
+#define SDL_sscanf SDL_sscanf_REAL
+#define SDL_snprintf SDL_snprintf_REAL
+#define SDL_CreateThread SDL_CreateThread_REAL
+#define SDL_RWFromFP SDL_RWFromFP_REAL
+#define SDL_RegisterApp SDL_RegisterApp_REAL
+#define SDL_UnregisterApp SDL_UnregisterApp_REAL
+#define SDL_Direct3D9GetAdapterIndex SDL_Direct3D9GetAdapterIndex_REAL
+#define SDL_RenderGetD3D9Device SDL_RenderGetD3D9Device_REAL
+#define SDL_iPhoneSetAnimationCallback SDL_iPhoneSetAnimationCallback_REAL
+#define SDL_iPhoneSetEventPump SDL_iPhoneSetEventPump_REAL
+#define SDL_AndroidGetJNIEnv SDL_AndroidGetJNIEnv_REAL
+#define SDL_AndroidGetActivity SDL_AndroidGetActivity_REAL
+#define SDL_AndroidGetInternalStoragePath SDL_AndroidGetInternalStoragePath_REAL
+#define SDL_AndroidGetExternalStorageState SDL_AndroidGetExternalStorageState_REAL
+#define SDL_AndroidGetExternalStoragePath SDL_AndroidGetExternalStoragePath_REAL
+#define SDL_Init SDL_Init_REAL
+#define SDL_InitSubSystem SDL_InitSubSystem_REAL
+#define SDL_QuitSubSystem SDL_QuitSubSystem_REAL
+#define SDL_WasInit SDL_WasInit_REAL
+#define SDL_Quit SDL_Quit_REAL
+#define SDL_ReportAssertion SDL_ReportAssertion_REAL
+#define SDL_SetAssertionHandler SDL_SetAssertionHandler_REAL
+#define SDL_GetAssertionReport SDL_GetAssertionReport_REAL
+#define SDL_ResetAssertionReport SDL_ResetAssertionReport_REAL
+#define SDL_AtomicTryLock SDL_AtomicTryLock_REAL
+#define SDL_AtomicLock SDL_AtomicLock_REAL
+#define SDL_AtomicUnlock SDL_AtomicUnlock_REAL
+#define SDL_AtomicCAS SDL_AtomicCAS_REAL
+#define SDL_AtomicSet SDL_AtomicSet_REAL
+#define SDL_AtomicGet SDL_AtomicGet_REAL
+#define SDL_AtomicAdd SDL_AtomicAdd_REAL
+#define SDL_AtomicCASPtr SDL_AtomicCASPtr_REAL
+#define SDL_AtomicSetPtr SDL_AtomicSetPtr_REAL
+#define SDL_AtomicGetPtr SDL_AtomicGetPtr_REAL
+#define SDL_GetNumAudioDrivers SDL_GetNumAudioDrivers_REAL
+#define SDL_GetAudioDriver SDL_GetAudioDriver_REAL
+#define SDL_AudioInit SDL_AudioInit_REAL
+#define SDL_AudioQuit SDL_AudioQuit_REAL
+#define SDL_GetCurrentAudioDriver SDL_GetCurrentAudioDriver_REAL
+#define SDL_OpenAudio SDL_OpenAudio_REAL
+#define SDL_GetNumAudioDevices SDL_GetNumAudioDevices_REAL
+#define SDL_GetAudioDeviceName SDL_GetAudioDeviceName_REAL
+#define SDL_OpenAudioDevice SDL_OpenAudioDevice_REAL
+#define SDL_GetAudioStatus SDL_GetAudioStatus_REAL
+#define SDL_GetAudioDeviceStatus SDL_GetAudioDeviceStatus_REAL
+#define SDL_PauseAudio SDL_PauseAudio_REAL
+#define SDL_PauseAudioDevice SDL_PauseAudioDevice_REAL
+#define SDL_LoadWAV_RW SDL_LoadWAV_RW_REAL
+#define SDL_FreeWAV SDL_FreeWAV_REAL
+#define SDL_BuildAudioCVT SDL_BuildAudioCVT_REAL
+#define SDL_ConvertAudio SDL_ConvertAudio_REAL
+#define SDL_MixAudio SDL_MixAudio_REAL
+#define SDL_MixAudioFormat SDL_MixAudioFormat_REAL
+#define SDL_LockAudio SDL_LockAudio_REAL
+#define SDL_LockAudioDevice SDL_LockAudioDevice_REAL
+#define SDL_UnlockAudio SDL_UnlockAudio_REAL
+#define SDL_UnlockAudioDevice SDL_UnlockAudioDevice_REAL
+#define SDL_CloseAudio SDL_CloseAudio_REAL
+#define SDL_CloseAudioDevice SDL_CloseAudioDevice_REAL
+#define SDL_SetClipboardText SDL_SetClipboardText_REAL
+#define SDL_GetClipboardText SDL_GetClipboardText_REAL
+#define SDL_HasClipboardText SDL_HasClipboardText_REAL
+#define SDL_GetCPUCount SDL_GetCPUCount_REAL
+#define SDL_GetCPUCacheLineSize SDL_GetCPUCacheLineSize_REAL
+#define SDL_HasRDTSC SDL_HasRDTSC_REAL
+#define SDL_HasAltiVec SDL_HasAltiVec_REAL
+#define SDL_HasMMX SDL_HasMMX_REAL
+#define SDL_Has3DNow SDL_Has3DNow_REAL
+#define SDL_HasSSE SDL_HasSSE_REAL
+#define SDL_HasSSE2 SDL_HasSSE2_REAL
+#define SDL_HasSSE3 SDL_HasSSE3_REAL
+#define SDL_HasSSE41 SDL_HasSSE41_REAL
+#define SDL_HasSSE42 SDL_HasSSE42_REAL
+#define SDL_GetSystemRAM SDL_GetSystemRAM_REAL
+#define SDL_GetError SDL_GetError_REAL
+#define SDL_ClearError SDL_ClearError_REAL
+#define SDL_Error SDL_Error_REAL
+#define SDL_PumpEvents SDL_PumpEvents_REAL
+#define SDL_PeepEvents SDL_PeepEvents_REAL
+#define SDL_HasEvent SDL_HasEvent_REAL
+#define SDL_HasEvents SDL_HasEvents_REAL
+#define SDL_FlushEvent SDL_FlushEvent_REAL
+#define SDL_FlushEvents SDL_FlushEvents_REAL
+#define SDL_PollEvent SDL_PollEvent_REAL
+#define SDL_WaitEvent SDL_WaitEvent_REAL
+#define SDL_WaitEventTimeout SDL_WaitEventTimeout_REAL
+#define SDL_PushEvent SDL_PushEvent_REAL
+#define SDL_SetEventFilter SDL_SetEventFilter_REAL
+#define SDL_GetEventFilter SDL_GetEventFilter_REAL
+#define SDL_AddEventWatch SDL_AddEventWatch_REAL
+#define SDL_DelEventWatch SDL_DelEventWatch_REAL
+#define SDL_FilterEvents SDL_FilterEvents_REAL
+#define SDL_EventState SDL_EventState_REAL
+#define SDL_RegisterEvents SDL_RegisterEvents_REAL
+#define SDL_GetBasePath SDL_GetBasePath_REAL
+#define SDL_GetPrefPath SDL_GetPrefPath_REAL
+#define SDL_GameControllerAddMapping SDL_GameControllerAddMapping_REAL
+#define SDL_GameControllerMappingForGUID SDL_GameControllerMappingForGUID_REAL
+#define SDL_GameControllerMapping SDL_GameControllerMapping_REAL
+#define SDL_IsGameController SDL_IsGameController_REAL
+#define SDL_GameControllerNameForIndex SDL_GameControllerNameForIndex_REAL
+#define SDL_GameControllerOpen SDL_GameControllerOpen_REAL
+#define SDL_GameControllerName SDL_GameControllerName_REAL
+#define SDL_GameControllerGetAttached SDL_GameControllerGetAttached_REAL
+#define SDL_GameControllerGetJoystick SDL_GameControllerGetJoystick_REAL
+#define SDL_GameControllerEventState SDL_GameControllerEventState_REAL
+#define SDL_GameControllerUpdate SDL_GameControllerUpdate_REAL
+#define SDL_GameControllerGetAxisFromString SDL_GameControllerGetAxisFromString_REAL
+#define SDL_GameControllerGetStringForAxis SDL_GameControllerGetStringForAxis_REAL
+#define SDL_GameControllerGetBindForAxis SDL_GameControllerGetBindForAxis_REAL
+#define SDL_GameControllerGetAxis SDL_GameControllerGetAxis_REAL
+#define SDL_GameControllerGetButtonFromString SDL_GameControllerGetButtonFromString_REAL
+#define SDL_GameControllerGetStringForButton SDL_GameControllerGetStringForButton_REAL
+#define SDL_GameControllerGetBindForButton SDL_GameControllerGetBindForButton_REAL
+#define SDL_GameControllerGetButton SDL_GameControllerGetButton_REAL
+#define SDL_GameControllerClose SDL_GameControllerClose_REAL
+#define SDL_RecordGesture SDL_RecordGesture_REAL
+#define SDL_SaveAllDollarTemplates SDL_SaveAllDollarTemplates_REAL
+#define SDL_SaveDollarTemplate SDL_SaveDollarTemplate_REAL
+#define SDL_LoadDollarTemplates SDL_LoadDollarTemplates_REAL
+#define SDL_NumHaptics SDL_NumHaptics_REAL
+#define SDL_HapticName SDL_HapticName_REAL
+#define SDL_HapticOpen SDL_HapticOpen_REAL
+#define SDL_HapticOpened SDL_HapticOpened_REAL
+#define SDL_HapticIndex SDL_HapticIndex_REAL
+#define SDL_MouseIsHaptic SDL_MouseIsHaptic_REAL
+#define SDL_HapticOpenFromMouse SDL_HapticOpenFromMouse_REAL
+#define SDL_JoystickIsHaptic SDL_JoystickIsHaptic_REAL
+#define SDL_HapticOpenFromJoystick SDL_HapticOpenFromJoystick_REAL
+#define SDL_HapticClose SDL_HapticClose_REAL
+#define SDL_HapticNumEffects SDL_HapticNumEffects_REAL
+#define SDL_HapticNumEffectsPlaying SDL_HapticNumEffectsPlaying_REAL
+#define SDL_HapticQuery SDL_HapticQuery_REAL
+#define SDL_HapticNumAxes SDL_HapticNumAxes_REAL
+#define SDL_HapticEffectSupported SDL_HapticEffectSupported_REAL
+#define SDL_HapticNewEffect SDL_HapticNewEffect_REAL
+#define SDL_HapticUpdateEffect SDL_HapticUpdateEffect_REAL
+#define SDL_HapticRunEffect SDL_HapticRunEffect_REAL
+#define SDL_HapticStopEffect SDL_HapticStopEffect_REAL
+#define SDL_HapticDestroyEffect SDL_HapticDestroyEffect_REAL
+#define SDL_HapticGetEffectStatus SDL_HapticGetEffectStatus_REAL
+#define SDL_HapticSetGain SDL_HapticSetGain_REAL
+#define SDL_HapticSetAutocenter SDL_HapticSetAutocenter_REAL
+#define SDL_HapticPause SDL_HapticPause_REAL
+#define SDL_HapticUnpause SDL_HapticUnpause_REAL
+#define SDL_HapticStopAll SDL_HapticStopAll_REAL
+#define SDL_HapticRumbleSupported SDL_HapticRumbleSupported_REAL
+#define SDL_HapticRumbleInit SDL_HapticRumbleInit_REAL
+#define SDL_HapticRumblePlay SDL_HapticRumblePlay_REAL
+#define SDL_HapticRumbleStop SDL_HapticRumbleStop_REAL
+#define SDL_SetHintWithPriority SDL_SetHintWithPriority_REAL
+#define SDL_SetHint SDL_SetHint_REAL
+#define SDL_GetHint SDL_GetHint_REAL
+#define SDL_AddHintCallback SDL_AddHintCallback_REAL
+#define SDL_DelHintCallback SDL_DelHintCallback_REAL
+#define SDL_ClearHints SDL_ClearHints_REAL
+#define SDL_NumJoysticks SDL_NumJoysticks_REAL
+#define SDL_JoystickNameForIndex SDL_JoystickNameForIndex_REAL
+#define SDL_JoystickOpen SDL_JoystickOpen_REAL
+#define SDL_JoystickName SDL_JoystickName_REAL
+#define SDL_JoystickGetDeviceGUID SDL_JoystickGetDeviceGUID_REAL
+#define SDL_JoystickGetGUID SDL_JoystickGetGUID_REAL
+#define SDL_JoystickGetGUIDString SDL_JoystickGetGUIDString_REAL
+#define SDL_JoystickGetGUIDFromString SDL_JoystickGetGUIDFromString_REAL
+#define SDL_JoystickGetAttached SDL_JoystickGetAttached_REAL
+#define SDL_JoystickInstanceID SDL_JoystickInstanceID_REAL
+#define SDL_JoystickNumAxes SDL_JoystickNumAxes_REAL
+#define SDL_JoystickNumBalls SDL_JoystickNumBalls_REAL
+#define SDL_JoystickNumHats SDL_JoystickNumHats_REAL
+#define SDL_JoystickNumButtons SDL_JoystickNumButtons_REAL
+#define SDL_JoystickUpdate SDL_JoystickUpdate_REAL
+#define SDL_JoystickEventState SDL_JoystickEventState_REAL
+#define SDL_JoystickGetAxis SDL_JoystickGetAxis_REAL
+#define SDL_JoystickGetHat SDL_JoystickGetHat_REAL
+#define SDL_JoystickGetBall SDL_JoystickGetBall_REAL
+#define SDL_JoystickGetButton SDL_JoystickGetButton_REAL
+#define SDL_JoystickClose SDL_JoystickClose_REAL
+#define SDL_GetKeyboardFocus SDL_GetKeyboardFocus_REAL
+#define SDL_GetKeyboardState SDL_GetKeyboardState_REAL
+#define SDL_GetModState SDL_GetModState_REAL
+#define SDL_SetModState SDL_SetModState_REAL
+#define SDL_GetKeyFromScancode SDL_GetKeyFromScancode_REAL
+#define SDL_GetScancodeFromKey SDL_GetScancodeFromKey_REAL
+#define SDL_GetScancodeName SDL_GetScancodeName_REAL
+#define SDL_GetScancodeFromName SDL_GetScancodeFromName_REAL
+#define SDL_GetKeyName SDL_GetKeyName_REAL
+#define SDL_GetKeyFromName SDL_GetKeyFromName_REAL
+#define SDL_StartTextInput SDL_StartTextInput_REAL
+#define SDL_IsTextInputActive SDL_IsTextInputActive_REAL
+#define SDL_StopTextInput SDL_StopTextInput_REAL
+#define SDL_SetTextInputRect SDL_SetTextInputRect_REAL
+#define SDL_HasScreenKeyboardSupport SDL_HasScreenKeyboardSupport_REAL
+#define SDL_IsScreenKeyboardShown SDL_IsScreenKeyboardShown_REAL
+#define SDL_LoadObject SDL_LoadObject_REAL
+#define SDL_LoadFunction SDL_LoadFunction_REAL
+#define SDL_UnloadObject SDL_UnloadObject_REAL
+#define SDL_LogSetAllPriority SDL_LogSetAllPriority_REAL
+#define SDL_LogSetPriority SDL_LogSetPriority_REAL
+#define SDL_LogGetPriority SDL_LogGetPriority_REAL
+#define SDL_LogResetPriorities SDL_LogResetPriorities_REAL
+#define SDL_LogMessageV SDL_LogMessageV_REAL
+#define SDL_LogGetOutputFunction SDL_LogGetOutputFunction_REAL
+#define SDL_LogSetOutputFunction SDL_LogSetOutputFunction_REAL
+#define SDL_SetMainReady SDL_SetMainReady_REAL
+#define SDL_ShowMessageBox SDL_ShowMessageBox_REAL
+#define SDL_ShowSimpleMessageBox SDL_ShowSimpleMessageBox_REAL
+#define SDL_GetMouseFocus SDL_GetMouseFocus_REAL
+#define SDL_GetMouseState SDL_GetMouseState_REAL
+#define SDL_GetRelativeMouseState SDL_GetRelativeMouseState_REAL
+#define SDL_WarpMouseInWindow SDL_WarpMouseInWindow_REAL
+#define SDL_SetRelativeMouseMode SDL_SetRelativeMouseMode_REAL
+#define SDL_GetRelativeMouseMode SDL_GetRelativeMouseMode_REAL
+#define SDL_CreateCursor SDL_CreateCursor_REAL
+#define SDL_CreateColorCursor SDL_CreateColorCursor_REAL
+#define SDL_CreateSystemCursor SDL_CreateSystemCursor_REAL
+#define SDL_SetCursor SDL_SetCursor_REAL
+#define SDL_GetCursor SDL_GetCursor_REAL
+#define SDL_GetDefaultCursor SDL_GetDefaultCursor_REAL
+#define SDL_FreeCursor SDL_FreeCursor_REAL
+#define SDL_ShowCursor SDL_ShowCursor_REAL
+#define SDL_CreateMutex SDL_CreateMutex_REAL
+#define SDL_LockMutex SDL_LockMutex_REAL
+#define SDL_TryLockMutex SDL_TryLockMutex_REAL
+#define SDL_UnlockMutex SDL_UnlockMutex_REAL
+#define SDL_DestroyMutex SDL_DestroyMutex_REAL
+#define SDL_CreateSemaphore SDL_CreateSemaphore_REAL
+#define SDL_DestroySemaphore SDL_DestroySemaphore_REAL
+#define SDL_SemWait SDL_SemWait_REAL
+#define SDL_SemTryWait SDL_SemTryWait_REAL
+#define SDL_SemWaitTimeout SDL_SemWaitTimeout_REAL
+#define SDL_SemPost SDL_SemPost_REAL
+#define SDL_SemValue SDL_SemValue_REAL
+#define SDL_CreateCond SDL_CreateCond_REAL
+#define SDL_DestroyCond SDL_DestroyCond_REAL
+#define SDL_CondSignal SDL_CondSignal_REAL
+#define SDL_CondBroadcast SDL_CondBroadcast_REAL
+#define SDL_CondWait SDL_CondWait_REAL
+#define SDL_CondWaitTimeout SDL_CondWaitTimeout_REAL
+#define SDL_GetPixelFormatName SDL_GetPixelFormatName_REAL
+#define SDL_PixelFormatEnumToMasks SDL_PixelFormatEnumToMasks_REAL
+#define SDL_MasksToPixelFormatEnum SDL_MasksToPixelFormatEnum_REAL
+#define SDL_AllocFormat SDL_AllocFormat_REAL
+#define SDL_FreeFormat SDL_FreeFormat_REAL
+#define SDL_AllocPalette SDL_AllocPalette_REAL
+#define SDL_SetPixelFormatPalette SDL_SetPixelFormatPalette_REAL
+#define SDL_SetPaletteColors SDL_SetPaletteColors_REAL
+#define SDL_FreePalette SDL_FreePalette_REAL
+#define SDL_MapRGB SDL_MapRGB_REAL
+#define SDL_MapRGBA SDL_MapRGBA_REAL
+#define SDL_GetRGB SDL_GetRGB_REAL
+#define SDL_GetRGBA SDL_GetRGBA_REAL
+#define SDL_CalculateGammaRamp SDL_CalculateGammaRamp_REAL
+#define SDL_GetPlatform SDL_GetPlatform_REAL
+#define SDL_GetPowerInfo SDL_GetPowerInfo_REAL
+#define SDL_HasIntersection SDL_HasIntersection_REAL
+#define SDL_IntersectRect SDL_IntersectRect_REAL
+#define SDL_UnionRect SDL_UnionRect_REAL
+#define SDL_EnclosePoints SDL_EnclosePoints_REAL
+#define SDL_IntersectRectAndLine SDL_IntersectRectAndLine_REAL
+#define SDL_GetNumRenderDrivers SDL_GetNumRenderDrivers_REAL
+#define SDL_GetRenderDriverInfo SDL_GetRenderDriverInfo_REAL
+#define SDL_CreateWindowAndRenderer SDL_CreateWindowAndRenderer_REAL
+#define SDL_CreateRenderer SDL_CreateRenderer_REAL
+#define SDL_CreateSoftwareRenderer SDL_CreateSoftwareRenderer_REAL
+#define SDL_GetRenderer SDL_GetRenderer_REAL
+#define SDL_GetRendererInfo SDL_GetRendererInfo_REAL
+#define SDL_GetRendererOutputSize SDL_GetRendererOutputSize_REAL
+#define SDL_CreateTexture SDL_CreateTexture_REAL
+#define SDL_CreateTextureFromSurface SDL_CreateTextureFromSurface_REAL
+#define SDL_QueryTexture SDL_QueryTexture_REAL
+#define SDL_SetTextureColorMod SDL_SetTextureColorMod_REAL
+#define SDL_GetTextureColorMod SDL_GetTextureColorMod_REAL
+#define SDL_SetTextureAlphaMod SDL_SetTextureAlphaMod_REAL
+#define SDL_GetTextureAlphaMod SDL_GetTextureAlphaMod_REAL
+#define SDL_SetTextureBlendMode SDL_SetTextureBlendMode_REAL
+#define SDL_GetTextureBlendMode SDL_GetTextureBlendMode_REAL
+#define SDL_UpdateTexture SDL_UpdateTexture_REAL
+#define SDL_UpdateYUVTexture SDL_UpdateYUVTexture_REAL
+#define SDL_LockTexture SDL_LockTexture_REAL
+#define SDL_UnlockTexture SDL_UnlockTexture_REAL
+#define SDL_RenderTargetSupported SDL_RenderTargetSupported_REAL
+#define SDL_SetRenderTarget SDL_SetRenderTarget_REAL
+#define SDL_GetRenderTarget SDL_GetRenderTarget_REAL
+#define SDL_RenderSetLogicalSize SDL_RenderSetLogicalSize_REAL
+#define SDL_RenderGetLogicalSize SDL_RenderGetLogicalSize_REAL
+#define SDL_RenderSetViewport SDL_RenderSetViewport_REAL
+#define SDL_RenderGetViewport SDL_RenderGetViewport_REAL
+#define SDL_RenderSetClipRect SDL_RenderSetClipRect_REAL
+#define SDL_RenderGetClipRect SDL_RenderGetClipRect_REAL
+#define SDL_RenderSetScale SDL_RenderSetScale_REAL
+#define SDL_RenderGetScale SDL_RenderGetScale_REAL
+#define SDL_SetRenderDrawColor SDL_SetRenderDrawColor_REAL
+#define SDL_GetRenderDrawColor SDL_GetRenderDrawColor_REAL
+#define SDL_SetRenderDrawBlendMode SDL_SetRenderDrawBlendMode_REAL
+#define SDL_GetRenderDrawBlendMode SDL_GetRenderDrawBlendMode_REAL
+#define SDL_RenderClear SDL_RenderClear_REAL
+#define SDL_RenderDrawPoint SDL_RenderDrawPoint_REAL
+#define SDL_RenderDrawPoints SDL_RenderDrawPoints_REAL
+#define SDL_RenderDrawLine SDL_RenderDrawLine_REAL
+#define SDL_RenderDrawLines SDL_RenderDrawLines_REAL
+#define SDL_RenderDrawRect SDL_RenderDrawRect_REAL
+#define SDL_RenderDrawRects SDL_RenderDrawRects_REAL
+#define SDL_RenderFillRect SDL_RenderFillRect_REAL
+#define SDL_RenderFillRects SDL_RenderFillRects_REAL
+#define SDL_RenderCopy SDL_RenderCopy_REAL
+#define SDL_RenderCopyEx SDL_RenderCopyEx_REAL
+#define SDL_RenderReadPixels SDL_RenderReadPixels_REAL
+#define SDL_RenderPresent SDL_RenderPresent_REAL
+#define SDL_DestroyTexture SDL_DestroyTexture_REAL
+#define SDL_DestroyRenderer SDL_DestroyRenderer_REAL
+#define SDL_GL_BindTexture SDL_GL_BindTexture_REAL
+#define SDL_GL_UnbindTexture SDL_GL_UnbindTexture_REAL
+#define SDL_RWFromFile SDL_RWFromFile_REAL
+#define SDL_RWFromMem SDL_RWFromMem_REAL
+#define SDL_RWFromConstMem SDL_RWFromConstMem_REAL
+#define SDL_AllocRW SDL_AllocRW_REAL
+#define SDL_FreeRW SDL_FreeRW_REAL
+#define SDL_ReadU8 SDL_ReadU8_REAL
+#define SDL_ReadLE16 SDL_ReadLE16_REAL
+#define SDL_ReadBE16 SDL_ReadBE16_REAL
+#define SDL_ReadLE32 SDL_ReadLE32_REAL
+#define SDL_ReadBE32 SDL_ReadBE32_REAL
+#define SDL_ReadLE64 SDL_ReadLE64_REAL
+#define SDL_ReadBE64 SDL_ReadBE64_REAL
+#define SDL_WriteU8 SDL_WriteU8_REAL
+#define SDL_WriteLE16 SDL_WriteLE16_REAL
+#define SDL_WriteBE16 SDL_WriteBE16_REAL
+#define SDL_WriteLE32 SDL_WriteLE32_REAL
+#define SDL_WriteBE32 SDL_WriteBE32_REAL
+#define SDL_WriteLE64 SDL_WriteLE64_REAL
+#define SDL_WriteBE64 SDL_WriteBE64_REAL
+#define SDL_CreateShapedWindow SDL_CreateShapedWindow_REAL
+#define SDL_IsShapedWindow SDL_IsShapedWindow_REAL
+#define SDL_SetWindowShape SDL_SetWindowShape_REAL
+#define SDL_GetShapedWindowMode SDL_GetShapedWindowMode_REAL
+#define SDL_malloc SDL_malloc_REAL
+#define SDL_calloc SDL_calloc_REAL
+#define SDL_realloc SDL_realloc_REAL
+#define SDL_free SDL_free_REAL
+#define SDL_getenv SDL_getenv_REAL
+#define SDL_setenv SDL_setenv_REAL
+#define SDL_qsort SDL_qsort_REAL
+#define SDL_abs SDL_abs_REAL
+#define SDL_isdigit SDL_isdigit_REAL
+#define SDL_isspace SDL_isspace_REAL
+#define SDL_toupper SDL_toupper_REAL
+#define SDL_tolower SDL_tolower_REAL
+#define SDL_memset SDL_memset_REAL
+#define SDL_memcpy SDL_memcpy_REAL
+#define SDL_memmove SDL_memmove_REAL
+#define SDL_memcmp SDL_memcmp_REAL
+#define SDL_wcslen SDL_wcslen_REAL
+#define SDL_wcslcpy SDL_wcslcpy_REAL
+#define SDL_wcslcat SDL_wcslcat_REAL
+#define SDL_strlen SDL_strlen_REAL
+#define SDL_strlcpy SDL_strlcpy_REAL
+#define SDL_utf8strlcpy SDL_utf8strlcpy_REAL
+#define SDL_strlcat SDL_strlcat_REAL
+#define SDL_strdup SDL_strdup_REAL
+#define SDL_strrev SDL_strrev_REAL
+#define SDL_strupr SDL_strupr_REAL
+#define SDL_strlwr SDL_strlwr_REAL
+#define SDL_strchr SDL_strchr_REAL
+#define SDL_strrchr SDL_strrchr_REAL
+#define SDL_strstr SDL_strstr_REAL
+#define SDL_itoa SDL_itoa_REAL
+#define SDL_uitoa SDL_uitoa_REAL
+#define SDL_ltoa SDL_ltoa_REAL
+#define SDL_ultoa SDL_ultoa_REAL
+#define SDL_lltoa SDL_lltoa_REAL
+#define SDL_ulltoa SDL_ulltoa_REAL
+#define SDL_atoi SDL_atoi_REAL
+#define SDL_atof SDL_atof_REAL
+#define SDL_strtol SDL_strtol_REAL
+#define SDL_strtoul SDL_strtoul_REAL
+#define SDL_strtoll SDL_strtoll_REAL
+#define SDL_strtoull SDL_strtoull_REAL
+#define SDL_strtod SDL_strtod_REAL
+#define SDL_strcmp SDL_strcmp_REAL
+#define SDL_strncmp SDL_strncmp_REAL
+#define SDL_strcasecmp SDL_strcasecmp_REAL
+#define SDL_strncasecmp SDL_strncasecmp_REAL
+#define SDL_vsnprintf SDL_vsnprintf_REAL
+#define SDL_acos SDL_acos_REAL
+#define SDL_asin SDL_asin_REAL
+#define SDL_atan SDL_atan_REAL
+#define SDL_atan2 SDL_atan2_REAL
+#define SDL_ceil SDL_ceil_REAL
+#define SDL_copysign SDL_copysign_REAL
+#define SDL_cos SDL_cos_REAL
+#define SDL_cosf SDL_cosf_REAL
+#define SDL_fabs SDL_fabs_REAL
+#define SDL_floor SDL_floor_REAL
+#define SDL_log SDL_log_REAL
+#define SDL_pow SDL_pow_REAL
+#define SDL_scalbn SDL_scalbn_REAL
+#define SDL_sin SDL_sin_REAL
+#define SDL_sinf SDL_sinf_REAL
+#define SDL_sqrt SDL_sqrt_REAL
+#define SDL_iconv_open SDL_iconv_open_REAL
+#define SDL_iconv_close SDL_iconv_close_REAL
+#define SDL_iconv SDL_iconv_REAL
+#define SDL_iconv_string SDL_iconv_string_REAL
+#define SDL_CreateRGBSurfaceWithFormat SDL_CreateRGBSurfaceWithFormat_REAL
+#define SDL_CreateRGBSurfaceWithFormatFrom SDL_CreateRGBSurfaceWithFormatFrom_REAL
+#define SDL_CreateRGBSurface SDL_CreateRGBSurface_REAL
+#define SDL_CreateRGBSurfaceFrom SDL_CreateRGBSurfaceFrom_REAL
+#define SDL_FreeSurface SDL_FreeSurface_REAL
+#define SDL_SetSurfacePalette SDL_SetSurfacePalette_REAL
+#define SDL_LockSurface SDL_LockSurface_REAL
+#define SDL_UnlockSurface SDL_UnlockSurface_REAL
+#define SDL_LoadBMP_RW SDL_LoadBMP_RW_REAL
+#define SDL_SaveBMP_RW SDL_SaveBMP_RW_REAL
+#define SDL_SetSurfaceRLE SDL_SetSurfaceRLE_REAL
+#define SDL_SetColorKey SDL_SetColorKey_REAL
+#define SDL_GetColorKey SDL_GetColorKey_REAL
+#define SDL_SetSurfaceColorMod SDL_SetSurfaceColorMod_REAL
+#define SDL_GetSurfaceColorMod SDL_GetSurfaceColorMod_REAL
+#define SDL_SetSurfaceAlphaMod SDL_SetSurfaceAlphaMod_REAL
+#define SDL_GetSurfaceAlphaMod SDL_GetSurfaceAlphaMod_REAL
+#define SDL_SetSurfaceBlendMode SDL_SetSurfaceBlendMode_REAL
+#define SDL_GetSurfaceBlendMode SDL_GetSurfaceBlendMode_REAL
+#define SDL_SetClipRect SDL_SetClipRect_REAL
+#define SDL_GetClipRect SDL_GetClipRect_REAL
+#define SDL_ConvertSurface SDL_ConvertSurface_REAL
+#define SDL_ConvertSurfaceFormat SDL_ConvertSurfaceFormat_REAL
+#define SDL_ConvertPixels SDL_ConvertPixels_REAL
+#define SDL_FillRect SDL_FillRect_REAL
+#define SDL_FillRects SDL_FillRects_REAL
+#define SDL_UpperBlit SDL_UpperBlit_REAL
+#define SDL_LowerBlit SDL_LowerBlit_REAL
+#define SDL_SoftStretch SDL_SoftStretch_REAL
+#define SDL_UpperBlitScaled SDL_UpperBlitScaled_REAL
+#define SDL_LowerBlitScaled SDL_LowerBlitScaled_REAL
+#define SDL_GetWindowWMInfo SDL_GetWindowWMInfo_REAL
+#define SDL_GetThreadName SDL_GetThreadName_REAL
+#define SDL_ThreadID SDL_ThreadID_REAL
+#define SDL_GetThreadID SDL_GetThreadID_REAL
+#define SDL_SetThreadPriority SDL_SetThreadPriority_REAL
+#define SDL_WaitThread SDL_WaitThread_REAL
+#define SDL_DetachThread SDL_DetachThread_REAL
+#define SDL_TLSCreate SDL_TLSCreate_REAL
+#define SDL_TLSGet SDL_TLSGet_REAL
+#define SDL_TLSSet SDL_TLSSet_REAL
+#define SDL_GetTicks SDL_GetTicks_REAL
+#define SDL_GetPerformanceCounter SDL_GetPerformanceCounter_REAL
+#define SDL_GetPerformanceFrequency SDL_GetPerformanceFrequency_REAL
+#define SDL_Delay SDL_Delay_REAL
+#define SDL_AddTimer SDL_AddTimer_REAL
+#define SDL_RemoveTimer SDL_RemoveTimer_REAL
+#define SDL_GetNumTouchDevices SDL_GetNumTouchDevices_REAL
+#define SDL_GetTouchDevice SDL_GetTouchDevice_REAL
+#define SDL_GetNumTouchFingers SDL_GetNumTouchFingers_REAL
+#define SDL_GetTouchFinger SDL_GetTouchFinger_REAL
+#define SDL_GetVersion SDL_GetVersion_REAL
+#define SDL_GetRevision SDL_GetRevision_REAL
+#define SDL_GetRevisionNumber SDL_GetRevisionNumber_REAL
+#define SDL_GetNumVideoDrivers SDL_GetNumVideoDrivers_REAL
+#define SDL_GetVideoDriver SDL_GetVideoDriver_REAL
+#define SDL_VideoInit SDL_VideoInit_REAL
+#define SDL_VideoQuit SDL_VideoQuit_REAL
+#define SDL_GetCurrentVideoDriver SDL_GetCurrentVideoDriver_REAL
+#define SDL_GetNumVideoDisplays SDL_GetNumVideoDisplays_REAL
+#define SDL_GetDisplayName SDL_GetDisplayName_REAL
+#define SDL_GetDisplayBounds SDL_GetDisplayBounds_REAL
+#define SDL_GetDisplayDPI SDL_GetDisplayDPI_REAL
+#define SDL_GetNumDisplayModes SDL_GetNumDisplayModes_REAL
+#define SDL_GetDisplayMode SDL_GetDisplayMode_REAL
+#define SDL_GetDesktopDisplayMode SDL_GetDesktopDisplayMode_REAL
+#define SDL_GetCurrentDisplayMode SDL_GetCurrentDisplayMode_REAL
+#define SDL_GetClosestDisplayMode SDL_GetClosestDisplayMode_REAL
+#define SDL_GetWindowDisplayIndex SDL_GetWindowDisplayIndex_REAL
+#define SDL_SetWindowDisplayMode SDL_SetWindowDisplayMode_REAL
+#define SDL_GetWindowDisplayMode SDL_GetWindowDisplayMode_REAL
+#define SDL_GetWindowPixelFormat SDL_GetWindowPixelFormat_REAL
+#define SDL_CreateWindow SDL_CreateWindow_REAL
+#define SDL_CreateWindowFrom SDL_CreateWindowFrom_REAL
+#define SDL_GetWindowID SDL_GetWindowID_REAL
+#define SDL_GetWindowFromID SDL_GetWindowFromID_REAL
+#define SDL_GetWindowFlags SDL_GetWindowFlags_REAL
+#define SDL_SetWindowTitle SDL_SetWindowTitle_REAL
+#define SDL_GetWindowTitle SDL_GetWindowTitle_REAL
+#define SDL_SetWindowIcon SDL_SetWindowIcon_REAL
+#define SDL_SetWindowData SDL_SetWindowData_REAL
+#define SDL_GetWindowData SDL_GetWindowData_REAL
+#define SDL_SetWindowPosition SDL_SetWindowPosition_REAL
+#define SDL_GetWindowPosition SDL_GetWindowPosition_REAL
+#define SDL_SetWindowSize SDL_SetWindowSize_REAL
+#define SDL_GetWindowSize SDL_GetWindowSize_REAL
+#define SDL_SetWindowMinimumSize SDL_SetWindowMinimumSize_REAL
+#define SDL_GetWindowMinimumSize SDL_GetWindowMinimumSize_REAL
+#define SDL_SetWindowMaximumSize SDL_SetWindowMaximumSize_REAL
+#define SDL_GetWindowMaximumSize SDL_GetWindowMaximumSize_REAL
+#define SDL_SetWindowBordered SDL_SetWindowBordered_REAL
+#define SDL_ShowWindow SDL_ShowWindow_REAL
+#define SDL_HideWindow SDL_HideWindow_REAL
+#define SDL_RaiseWindow SDL_RaiseWindow_REAL
+#define SDL_MaximizeWindow SDL_MaximizeWindow_REAL
+#define SDL_MinimizeWindow SDL_MinimizeWindow_REAL
+#define SDL_RestoreWindow SDL_RestoreWindow_REAL
+#define SDL_SetWindowFullscreen SDL_SetWindowFullscreen_REAL
+#define SDL_GetWindowSurface SDL_GetWindowSurface_REAL
+#define SDL_UpdateWindowSurface SDL_UpdateWindowSurface_REAL
+#define SDL_UpdateWindowSurfaceRects SDL_UpdateWindowSurfaceRects_REAL
+#define SDL_SetWindowGrab SDL_SetWindowGrab_REAL
+#define SDL_GetWindowGrab SDL_GetWindowGrab_REAL
+#define SDL_SetWindowBrightness SDL_SetWindowBrightness_REAL
+#define SDL_GetWindowBrightness SDL_GetWindowBrightness_REAL
+#define SDL_SetWindowGammaRamp SDL_SetWindowGammaRamp_REAL
+#define SDL_GetWindowGammaRamp SDL_GetWindowGammaRamp_REAL
+#define SDL_DestroyWindow SDL_DestroyWindow_REAL
+#define SDL_IsScreenSaverEnabled SDL_IsScreenSaverEnabled_REAL
+#define SDL_EnableScreenSaver SDL_EnableScreenSaver_REAL
+#define SDL_DisableScreenSaver SDL_DisableScreenSaver_REAL
+#define SDL_GL_LoadLibrary SDL_GL_LoadLibrary_REAL
+#define SDL_GL_GetProcAddress SDL_GL_GetProcAddress_REAL
+#define SDL_GL_UnloadLibrary SDL_GL_UnloadLibrary_REAL
+#define SDL_GL_ExtensionSupported SDL_GL_ExtensionSupported_REAL
+#define SDL_GL_SetAttribute SDL_GL_SetAttribute_REAL
+#define SDL_GL_GetAttribute SDL_GL_GetAttribute_REAL
+#define SDL_GL_CreateContext SDL_GL_CreateContext_REAL
+#define SDL_GL_MakeCurrent SDL_GL_MakeCurrent_REAL
+#define SDL_GL_GetCurrentWindow SDL_GL_GetCurrentWindow_REAL
+#define SDL_GL_GetCurrentContext SDL_GL_GetCurrentContext_REAL
+#define SDL_GL_GetDrawableSize SDL_GL_GetDrawableSize_REAL
+#define SDL_GL_SetSwapInterval SDL_GL_SetSwapInterval_REAL
+#define SDL_GL_GetSwapInterval SDL_GL_GetSwapInterval_REAL
+#define SDL_GL_SwapWindow SDL_GL_SwapWindow_REAL
+#define SDL_GL_DeleteContext SDL_GL_DeleteContext_REAL
+#define SDL_vsscanf SDL_vsscanf_REAL
+#define SDL_GameControllerAddMappingsFromRW SDL_GameControllerAddMappingsFromRW_REAL
+#define SDL_GL_ResetAttributes SDL_GL_ResetAttributes_REAL
+#define SDL_HasAVX SDL_HasAVX_REAL
+#define SDL_GetDefaultAssertionHandler SDL_GetDefaultAssertionHandler_REAL
+#define SDL_GetAssertionHandler SDL_GetAssertionHandler_REAL
+#define SDL_DXGIGetOutputInfo SDL_DXGIGetOutputInfo_REAL
+#define SDL_RenderIsClipEnabled SDL_RenderIsClipEnabled_REAL
+#define SDL_WinRTRunApp SDL_WinRTRunApp_REAL
+#define SDL_WarpMouseGlobal SDL_WarpMouseGlobal_REAL
+#define SDL_WinRTGetFSPathUNICODE SDL_WinRTGetFSPathUNICODE_REAL
+#define SDL_WinRTGetFSPathUTF8 SDL_WinRTGetFSPathUTF8_REAL
+#define SDL_WinRTRunApp SDL_WinRTRunApp_REAL
+#define SDL_sqrtf SDL_sqrtf_REAL
+#define SDL_tan SDL_tan_REAL
+#define SDL_tanf SDL_tanf_REAL
+#define SDL_CaptureMouse SDL_CaptureMouse_REAL
+#define SDL_SetWindowHitTest SDL_SetWindowHitTest_REAL
+#define SDL_GetGlobalMouseState SDL_GetGlobalMouseState_REAL
+#define SDL_HasAVX2 SDL_HasAVX2_REAL
+#define SDL_QueueAudio SDL_QueueAudio_REAL
+#define SDL_GetQueuedAudioSize SDL_GetQueuedAudioSize_REAL
+#define SDL_ClearQueuedAudio SDL_ClearQueuedAudio_REAL
+#define SDL_GetGrabbedWindow SDL_GetGrabbedWindow_REAL
+#define SDL_SetWindowsMessageHook SDL_SetWindowsMessageHook_REAL
+#define SDL_JoystickCurrentPowerLevel SDL_JoystickCurrentPowerLevel_REAL
+#define SDL_GameControllerFromInstanceID SDL_GameControllerFromInstanceID_REAL
+#define SDL_JoystickFromInstanceID SDL_JoystickFromInstanceID_REAL
+#define SDL_GetDisplayUsableBounds SDL_GetDisplayUsableBounds_REAL
+#define SDL_GetWindowBordersSize SDL_GetWindowBordersSize_REAL
+#define SDL_SetWindowOpacity SDL_SetWindowOpacity_REAL
+#define SDL_GetWindowOpacity SDL_GetWindowOpacity_REAL
+#define SDL_SetWindowInputFocus SDL_SetWindowInputFocus_REAL
+#define SDL_SetWindowModalFor SDL_SetWindowModalFor_REAL
+#define SDL_RenderSetIntegerScale SDL_RenderSetIntegerScale_REAL
+#define SDL_RenderGetIntegerScale SDL_RenderGetIntegerScale_REAL
+#define SDL_DequeueAudio SDL_DequeueAudio_REAL
+#define SDL_SetWindowResizable SDL_SetWindowResizable_REAL
+#define SDL_CreateRGBSurfaceWithFormat SDL_CreateRGBSurfaceWithFormat_REAL
+#define SDL_CreateRGBSurfaceWithFormatFrom SDL_CreateRGBSurfaceWithFormatFrom_REAL
+#define SDL_GetHintBoolean SDL_GetHintBoolean_REAL
+#define SDL_JoystickGetDeviceVendor SDL_JoystickGetDeviceVendor_REAL
+#define SDL_JoystickGetDeviceProduct SDL_JoystickGetDeviceProduct_REAL
+#define SDL_JoystickGetDeviceProductVersion SDL_JoystickGetDeviceProductVersion_REAL
+#define SDL_JoystickGetVendor SDL_JoystickGetVendor_REAL
+#define SDL_JoystickGetProduct SDL_JoystickGetProduct_REAL
+#define SDL_JoystickGetProductVersion SDL_JoystickGetProductVersion_REAL
+#define SDL_GameControllerGetVendor SDL_GameControllerGetVendor_REAL
+#define SDL_GameControllerGetProduct SDL_GameControllerGetProduct_REAL
+#define SDL_GameControllerGetProductVersion SDL_GameControllerGetProductVersion_REAL
+#define SDL_HasNEON SDL_HasNEON_REAL
+#define SDL_GameControllerNumMappings SDL_GameControllerNumMappings_REAL
+#define SDL_GameControllerMappingForIndex SDL_GameControllerMappingForIndex_REAL
+#define SDL_JoystickGetAxisInitialState SDL_JoystickGetAxisInitialState_REAL
+#define SDL_JoystickGetDeviceType SDL_JoystickGetDeviceType_REAL
+#define SDL_JoystickGetType SDL_JoystickGetType_REAL
+#define SDL_MemoryBarrierReleaseFunction SDL_MemoryBarrierReleaseFunction_REAL
+#define SDL_MemoryBarrierAcquireFunction SDL_MemoryBarrierAcquireFunction_REAL
+#define SDL_JoystickGetDeviceInstanceID SDL_JoystickGetDeviceInstanceID_REAL
+#define SDL_utf8strlen SDL_utf8strlen_REAL
+#define SDL_LoadFile_RW SDL_LoadFile_RW_REAL
+#define SDL_wcscmp SDL_wcscmp_REAL
+#define SDL_ComposeCustomBlendMode SDL_ComposeCustomBlendMode_REAL
+#define SDL_DuplicateSurface SDL_DuplicateSurface_REAL
+#define SDL_Vulkan_LoadLibrary SDL_Vulkan_LoadLibrary_REAL
+#define SDL_Vulkan_GetVkGetInstanceProcAddr SDL_Vulkan_GetVkGetInstanceProcAddr_REAL
+#define SDL_Vulkan_UnloadLibrary SDL_Vulkan_UnloadLibrary_REAL
+#define SDL_Vulkan_GetInstanceExtensions SDL_Vulkan_GetInstanceExtensions_REAL
+#define SDL_Vulkan_CreateSurface SDL_Vulkan_CreateSurface_REAL
+#define SDL_Vulkan_GetDrawableSize SDL_Vulkan_GetDrawableSize_REAL
+#define SDL_LockJoysticks SDL_LockJoysticks_REAL
+#define SDL_UnlockJoysticks SDL_UnlockJoysticks_REAL
+#define SDL_GetMemoryFunctions SDL_GetMemoryFunctions_REAL
+#define SDL_SetMemoryFunctions SDL_SetMemoryFunctions_REAL
+#define SDL_GetNumAllocations SDL_GetNumAllocations_REAL
+#define SDL_NewAudioStream SDL_NewAudioStream_REAL
+#define SDL_AudioStreamPut SDL_AudioStreamPut_REAL
+#define SDL_AudioStreamGet SDL_AudioStreamGet_REAL
+#define SDL_AudioStreamClear SDL_AudioStreamClear_REAL
+#define SDL_AudioStreamAvailable SDL_AudioStreamAvailable_REAL
+#define SDL_FreeAudioStream SDL_FreeAudioStream_REAL
+#define SDL_AudioStreamFlush SDL_AudioStreamFlush_REAL
+#define SDL_acosf SDL_acosf_REAL
+#define SDL_asinf SDL_asinf_REAL
+#define SDL_atanf SDL_atanf_REAL
+#define SDL_atan2f SDL_atan2f_REAL
+#define SDL_ceilf SDL_ceilf_REAL
+#define SDL_copysignf SDL_copysignf_REAL
+#define SDL_fabsf SDL_fabsf_REAL
+#define SDL_floorf SDL_floorf_REAL
+#define SDL_logf SDL_logf_REAL
+#define SDL_powf SDL_powf_REAL
+#define SDL_scalbnf SDL_scalbnf_REAL
+#define SDL_fmod SDL_fmod_REAL
+#define SDL_fmodf SDL_fmodf_REAL
+#define SDL_SetYUVConversionMode SDL_SetYUVConversionMode_REAL
+#define SDL_GetYUVConversionMode SDL_GetYUVConversionMode_REAL
+#define SDL_GetYUVConversionModeForResolution SDL_GetYUVConversionModeForResolution_REAL
+#define SDL_RenderGetMetalLayer SDL_RenderGetMetalLayer_REAL
+#define SDL_RenderGetMetalCommandEncoder SDL_RenderGetMetalCommandEncoder_REAL
+#define SDL_IsAndroidTV SDL_IsAndroidTV_REAL
+#define SDL_WinRTGetDeviceFamily SDL_WinRTGetDeviceFamily_REAL
+#define SDL_log10 SDL_log10_REAL
+#define SDL_log10f SDL_log10f_REAL
diff --git a/src/3rdparty/SDL2/src/dynapi/SDL_dynapi_procs.h b/src/3rdparty/SDL2/src/dynapi/SDL_dynapi_procs.h
new file mode 100644
index 0000000..b715d33
--- /dev/null
+++ b/src/3rdparty/SDL2/src/dynapi/SDL_dynapi_procs.h
@@ -0,0 +1,709 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/* vi: set ts=4 sw=4 expandtab: */
+
+/*
+ DO NOT EDIT THIS FILE BY HAND. It is autogenerated by gendynapi.pl.
+ NEVER REARRANGE THIS FILE, THE ORDER IS ABI LAW.
+ Changing this file means bumping SDL_DYNAPI_VERSION. You can safely add
+ new items to the end of the file, though.
+ Also, this file gets included multiple times, don't add #pragma once, etc.
+*/
+
+/* direct jump magic can use these, the rest needs special code. */
+#if !SDL_DYNAPI_PROC_NO_VARARGS
+SDL_DYNAPI_PROC(int,SDL_SetError,(SDL_PRINTF_FORMAT_STRING const char *a, ...),(a),return)
+SDL_DYNAPI_PROC(void,SDL_Log,(SDL_PRINTF_FORMAT_STRING const char *a, ...),(a),)
+SDL_DYNAPI_PROC(void,SDL_LogVerbose,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
+SDL_DYNAPI_PROC(void,SDL_LogDebug,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
+SDL_DYNAPI_PROC(void,SDL_LogInfo,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
+SDL_DYNAPI_PROC(void,SDL_LogWarn,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
+SDL_DYNAPI_PROC(void,SDL_LogError,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
+SDL_DYNAPI_PROC(void,SDL_LogCritical,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
+SDL_DYNAPI_PROC(void,SDL_LogMessage,(int a, SDL_LogPriority b, SDL_PRINTF_FORMAT_STRING const char *c, ...),(a,b,c),)
+SDL_DYNAPI_PROC(int,SDL_sscanf,(const char *a, SDL_SCANF_FORMAT_STRING const char *b, ...),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_snprintf,(SDL_OUT_Z_CAP(b) char *a, size_t b, SDL_PRINTF_FORMAT_STRING const char *c, ...),(a,b,c),return)
+#endif
+
+#ifdef SDL_CreateThread
+#undef SDL_CreateThread
+#endif
+
+#if defined(__WIN32__) && !defined(HAVE_LIBC)
+SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThread,(SDL_ThreadFunction a, const char *b, void *c, pfnSDL_CurrentBeginThread d, pfnSDL_CurrentEndThread e),(a,b,c,d,e),return)
+#elif defined(__OS2__)
+SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThread,(SDL_ThreadFunction a, const char *b, void *c, pfnSDL_CurrentBeginThread d, pfnSDL_CurrentEndThread e),(a,b,c,d,e),return)
+#else
+SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThread,(SDL_ThreadFunction a, const char *b, void *c),(a,b,c),return)
+#endif
+
+#ifdef HAVE_STDIO_H
+SDL_DYNAPI_PROC(SDL_RWops*,SDL_RWFromFP,(FILE *a, SDL_bool b),(a,b),return)
+#else
+SDL_DYNAPI_PROC(SDL_RWops*,SDL_RWFromFP,(void *a, SDL_bool b),(a,b),return)
+#endif
+
+#ifdef __WIN32__
+SDL_DYNAPI_PROC(int,SDL_RegisterApp,(char *a, Uint32 b, void *c),(a,b,c),return)
+SDL_DYNAPI_PROC(void,SDL_UnregisterApp,(void),(),)
+SDL_DYNAPI_PROC(int,SDL_Direct3D9GetAdapterIndex,(int a),(a),return)
+SDL_DYNAPI_PROC(IDirect3DDevice9*,SDL_RenderGetD3D9Device,(SDL_Renderer *a),(a),return)
+#endif
+
+#ifdef __IPHONEOS__
+SDL_DYNAPI_PROC(int,SDL_iPhoneSetAnimationCallback,(SDL_Window *a, int b, void c, void *d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(void,SDL_iPhoneSetEventPump,(SDL_bool a),(a),)
+#endif
+
+#ifdef __ANDROID__
+SDL_DYNAPI_PROC(void*,SDL_AndroidGetJNIEnv,(void),(),return)
+SDL_DYNAPI_PROC(void*,SDL_AndroidGetActivity,(void),(),return)
+SDL_DYNAPI_PROC(const char*,SDL_AndroidGetInternalStoragePath,(void),(),return)
+SDL_DYNAPI_PROC(int,SDL_AndroidGetExternalStorageState,(void),(),return)
+SDL_DYNAPI_PROC(const char*,SDL_AndroidGetExternalStoragePath,(void),(),return)
+#endif
+
+SDL_DYNAPI_PROC(int,SDL_Init,(Uint32 a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_InitSubSystem,(Uint32 a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_QuitSubSystem,(Uint32 a),(a),)
+SDL_DYNAPI_PROC(Uint32,SDL_WasInit,(Uint32 a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_Quit,(void),(),)
+SDL_DYNAPI_PROC(SDL_assert_state,SDL_ReportAssertion,(SDL_assert_data *a, const char *b, const char *c, int d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(void,SDL_SetAssertionHandler,(SDL_AssertionHandler a, void *b),(a,b),)
+SDL_DYNAPI_PROC(const SDL_assert_data*,SDL_GetAssertionReport,(void),(),return)
+SDL_DYNAPI_PROC(void,SDL_ResetAssertionReport,(void),(),)
+SDL_DYNAPI_PROC(SDL_bool,SDL_AtomicTryLock,(SDL_SpinLock *a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_AtomicLock,(SDL_SpinLock *a),(a),)
+SDL_DYNAPI_PROC(void,SDL_AtomicUnlock,(SDL_SpinLock *a),(a),)
+SDL_DYNAPI_PROC(SDL_bool,SDL_AtomicCAS,(SDL_atomic_t *a, int b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_AtomicSet,(SDL_atomic_t *a, int b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_AtomicGet,(SDL_atomic_t *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_AtomicAdd,(SDL_atomic_t *a, int b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_AtomicCASPtr,(void **a, void *b, void *c),(a,b,c),return)
+SDL_DYNAPI_PROC(void*,SDL_AtomicSetPtr,(void **a, void *b),(a,b),return)
+SDL_DYNAPI_PROC(void*,SDL_AtomicGetPtr,(void **a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_GetNumAudioDrivers,(void),(),return)
+SDL_DYNAPI_PROC(const char*,SDL_GetAudioDriver,(int a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_AudioInit,(const char *a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_AudioQuit,(void),(),)
+SDL_DYNAPI_PROC(const char*,SDL_GetCurrentAudioDriver,(void),(),return)
+SDL_DYNAPI_PROC(int,SDL_OpenAudio,(SDL_AudioSpec *a, SDL_AudioSpec *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GetNumAudioDevices,(int a),(a),return)
+SDL_DYNAPI_PROC(const char*,SDL_GetAudioDeviceName,(int a, int b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_AudioDeviceID,SDL_OpenAudioDevice,(const char *a, int b, const SDL_AudioSpec *c, SDL_AudioSpec *d, int e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(SDL_AudioStatus,SDL_GetAudioStatus,(void),(),return)
+SDL_DYNAPI_PROC(SDL_AudioStatus,SDL_GetAudioDeviceStatus,(SDL_AudioDeviceID a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_PauseAudio,(int a),(a),)
+SDL_DYNAPI_PROC(void,SDL_PauseAudioDevice,(SDL_AudioDeviceID a, int b),(a,b),)
+SDL_DYNAPI_PROC(SDL_AudioSpec*,SDL_LoadWAV_RW,(SDL_RWops *a, int b, SDL_AudioSpec *c, Uint8 **d, Uint32 *e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(void,SDL_FreeWAV,(Uint8 *a),(a),)
+SDL_DYNAPI_PROC(int,SDL_BuildAudioCVT,(SDL_AudioCVT *a, SDL_AudioFormat b, Uint8 c, int d, SDL_AudioFormat e, Uint8 f, int g),(a,b,c,d,e,f,g),return)
+SDL_DYNAPI_PROC(int,SDL_ConvertAudio,(SDL_AudioCVT *a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_MixAudio,(Uint8 *a, const Uint8 *b, Uint32 c, int d),(a,b,c,d),)
+SDL_DYNAPI_PROC(void,SDL_MixAudioFormat,(Uint8 *a, const Uint8 *b, SDL_AudioFormat c, Uint32 d, int e),(a,b,c,d,e),)
+SDL_DYNAPI_PROC(void,SDL_LockAudio,(void),(),)
+SDL_DYNAPI_PROC(void,SDL_LockAudioDevice,(SDL_AudioDeviceID a),(a),)
+SDL_DYNAPI_PROC(void,SDL_UnlockAudio,(void),(),)
+SDL_DYNAPI_PROC(void,SDL_UnlockAudioDevice,(SDL_AudioDeviceID a),(a),)
+SDL_DYNAPI_PROC(void,SDL_CloseAudio,(void),(),)
+SDL_DYNAPI_PROC(void,SDL_CloseAudioDevice,(SDL_AudioDeviceID a),(a),)
+SDL_DYNAPI_PROC(int,SDL_SetClipboardText,(const char *a),(a),return)
+SDL_DYNAPI_PROC(char*,SDL_GetClipboardText,(void),(),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_HasClipboardText,(void),(),return)
+SDL_DYNAPI_PROC(int,SDL_GetCPUCount,(void),(),return)
+SDL_DYNAPI_PROC(int,SDL_GetCPUCacheLineSize,(void),(),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_HasRDTSC,(void),(),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_HasAltiVec,(void),(),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_HasMMX,(void),(),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_Has3DNow,(void),(),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_HasSSE,(void),(),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_HasSSE2,(void),(),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_HasSSE3,(void),(),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_HasSSE41,(void),(),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_HasSSE42,(void),(),return)
+SDL_DYNAPI_PROC(int,SDL_GetSystemRAM,(void),(),return)
+SDL_DYNAPI_PROC(const char*,SDL_GetError,(void),(),return)
+SDL_DYNAPI_PROC(void,SDL_ClearError,(void),(),)
+SDL_DYNAPI_PROC(int,SDL_Error,(SDL_errorcode a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_PumpEvents,(void),(),)
+SDL_DYNAPI_PROC(int,SDL_PeepEvents,(SDL_Event *a, int b, SDL_eventaction c, Uint32 d, Uint32 e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_HasEvent,(Uint32 a),(a),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_HasEvents,(Uint32 a, Uint32 b),(a,b),return)
+SDL_DYNAPI_PROC(void,SDL_FlushEvent,(Uint32 a),(a),)
+SDL_DYNAPI_PROC(void,SDL_FlushEvents,(Uint32 a, Uint32 b),(a,b),)
+SDL_DYNAPI_PROC(int,SDL_PollEvent,(SDL_Event *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_WaitEvent,(SDL_Event *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_WaitEventTimeout,(SDL_Event *a, int b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_PushEvent,(SDL_Event *a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_SetEventFilter,(SDL_EventFilter a, void *b),(a,b),)
+SDL_DYNAPI_PROC(SDL_bool,SDL_GetEventFilter,(SDL_EventFilter *a, void **b),(a,b),return)
+SDL_DYNAPI_PROC(void,SDL_AddEventWatch,(SDL_EventFilter a, void *b),(a,b),)
+SDL_DYNAPI_PROC(void,SDL_DelEventWatch,(SDL_EventFilter a, void *b),(a,b),)
+SDL_DYNAPI_PROC(void,SDL_FilterEvents,(SDL_EventFilter a, void *b),(a,b),)
+SDL_DYNAPI_PROC(Uint8,SDL_EventState,(Uint32 a, int b),(a,b),return)
+SDL_DYNAPI_PROC(Uint32,SDL_RegisterEvents,(int a),(a),return)
+SDL_DYNAPI_PROC(char*,SDL_GetBasePath,(void),(),return)
+SDL_DYNAPI_PROC(char*,SDL_GetPrefPath,(const char *a, const char *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GameControllerAddMapping,(const char *a),(a),return)
+SDL_DYNAPI_PROC(char*,SDL_GameControllerMappingForGUID,(SDL_JoystickGUID a),(a),return)
+SDL_DYNAPI_PROC(char*,SDL_GameControllerMapping,(SDL_GameController *a),(a),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_IsGameController,(int a),(a),return)
+SDL_DYNAPI_PROC(const char*,SDL_GameControllerNameForIndex,(int a),(a),return)
+SDL_DYNAPI_PROC(SDL_GameController*,SDL_GameControllerOpen,(int a),(a),return)
+SDL_DYNAPI_PROC(const char*,SDL_GameControllerName,(SDL_GameController *a),(a),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_GameControllerGetAttached,(SDL_GameController *a),(a),return)
+SDL_DYNAPI_PROC(SDL_Joystick*,SDL_GameControllerGetJoystick,(SDL_GameController *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_GameControllerEventState,(int a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_GameControllerUpdate,(void),(),)
+SDL_DYNAPI_PROC(SDL_GameControllerAxis,SDL_GameControllerGetAxisFromString,(const char *a),(a),return)
+SDL_DYNAPI_PROC(const char*,SDL_GameControllerGetStringForAxis,(SDL_GameControllerAxis a),(a),return)
+SDL_DYNAPI_PROC(SDL_GameControllerButtonBind,SDL_GameControllerGetBindForAxis,(SDL_GameController *a, SDL_GameControllerAxis b),(a,b),return)
+SDL_DYNAPI_PROC(Sint16,SDL_GameControllerGetAxis,(SDL_GameController *a, SDL_GameControllerAxis b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_GameControllerButton,SDL_GameControllerGetButtonFromString,(const char *a),(a),return)
+SDL_DYNAPI_PROC(const char*,SDL_GameControllerGetStringForButton,(SDL_GameControllerButton a),(a),return)
+SDL_DYNAPI_PROC(SDL_GameControllerButtonBind,SDL_GameControllerGetBindForButton,(SDL_GameController *a, SDL_GameControllerButton b),(a,b),return)
+SDL_DYNAPI_PROC(Uint8,SDL_GameControllerGetButton,(SDL_GameController *a, SDL_GameControllerButton b),(a,b),return)
+SDL_DYNAPI_PROC(void,SDL_GameControllerClose,(SDL_GameController *a),(a),)
+SDL_DYNAPI_PROC(int,SDL_RecordGesture,(SDL_TouchID a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_SaveAllDollarTemplates,(SDL_RWops *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_SaveDollarTemplate,(SDL_GestureID a, SDL_RWops *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_LoadDollarTemplates,(SDL_TouchID a, SDL_RWops *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_NumHaptics,(void),(),return)
+SDL_DYNAPI_PROC(const char*,SDL_HapticName,(int a),(a),return)
+SDL_DYNAPI_PROC(SDL_Haptic*,SDL_HapticOpen,(int a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_HapticOpened,(int a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_HapticIndex,(SDL_Haptic *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_MouseIsHaptic,(void),(),return)
+SDL_DYNAPI_PROC(SDL_Haptic*,SDL_HapticOpenFromMouse,(void),(),return)
+SDL_DYNAPI_PROC(int,SDL_JoystickIsHaptic,(SDL_Joystick *a),(a),return)
+SDL_DYNAPI_PROC(SDL_Haptic*,SDL_HapticOpenFromJoystick,(SDL_Joystick *a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_HapticClose,(SDL_Haptic *a),(a),)
+SDL_DYNAPI_PROC(int,SDL_HapticNumEffects,(SDL_Haptic *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_HapticNumEffectsPlaying,(SDL_Haptic *a),(a),return)
+SDL_DYNAPI_PROC(unsigned int,SDL_HapticQuery,(SDL_Haptic *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_HapticNumAxes,(SDL_Haptic *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_HapticEffectSupported,(SDL_Haptic *a, SDL_HapticEffect *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_HapticNewEffect,(SDL_Haptic *a, SDL_HapticEffect *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_HapticUpdateEffect,(SDL_Haptic *a, int b, SDL_HapticEffect *c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_HapticRunEffect,(SDL_Haptic *a, int b, Uint32 c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_HapticStopEffect,(SDL_Haptic *a, int b),(a,b),return)
+SDL_DYNAPI_PROC(void,SDL_HapticDestroyEffect,(SDL_Haptic *a, int b),(a,b),)
+SDL_DYNAPI_PROC(int,SDL_HapticGetEffectStatus,(SDL_Haptic *a, int b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_HapticSetGain,(SDL_Haptic *a, int b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_HapticSetAutocenter,(SDL_Haptic *a, int b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_HapticPause,(SDL_Haptic *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_HapticUnpause,(SDL_Haptic *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_HapticStopAll,(SDL_Haptic *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_HapticRumbleSupported,(SDL_Haptic *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_HapticRumbleInit,(SDL_Haptic *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_HapticRumblePlay,(SDL_Haptic *a, float b, Uint32 c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_HapticRumbleStop,(SDL_Haptic *a),(a),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_SetHintWithPriority,(const char *a, const char *b, SDL_HintPriority c),(a,b,c),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_SetHint,(const char *a, const char *b),(a,b),return)
+SDL_DYNAPI_PROC(const char*,SDL_GetHint,(const char *a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_AddHintCallback,(const char *a, SDL_HintCallback b, void *c),(a,b,c),)
+SDL_DYNAPI_PROC(void,SDL_DelHintCallback,(const char *a, SDL_HintCallback b, void *c),(a,b,c),)
+SDL_DYNAPI_PROC(void,SDL_ClearHints,(void),(),)
+SDL_DYNAPI_PROC(int,SDL_NumJoysticks,(void),(),return)
+SDL_DYNAPI_PROC(const char*,SDL_JoystickNameForIndex,(int a),(a),return)
+SDL_DYNAPI_PROC(SDL_Joystick*,SDL_JoystickOpen,(int a),(a),return)
+SDL_DYNAPI_PROC(const char*,SDL_JoystickName,(SDL_Joystick *a),(a),return)
+SDL_DYNAPI_PROC(SDL_JoystickGUID,SDL_JoystickGetDeviceGUID,(int a),(a),return)
+SDL_DYNAPI_PROC(SDL_JoystickGUID,SDL_JoystickGetGUID,(SDL_Joystick *a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_JoystickGetGUIDString,(SDL_JoystickGUID a, char *b, int c),(a,b,c),)
+SDL_DYNAPI_PROC(SDL_JoystickGUID,SDL_JoystickGetGUIDFromString,(const char *a),(a),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_JoystickGetAttached,(SDL_Joystick *a),(a),return)
+SDL_DYNAPI_PROC(SDL_JoystickID,SDL_JoystickInstanceID,(SDL_Joystick *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_JoystickNumAxes,(SDL_Joystick *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_JoystickNumBalls,(SDL_Joystick *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_JoystickNumHats,(SDL_Joystick *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_JoystickNumButtons,(SDL_Joystick *a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_JoystickUpdate,(void),(),)
+SDL_DYNAPI_PROC(int,SDL_JoystickEventState,(int a),(a),return)
+SDL_DYNAPI_PROC(Sint16,SDL_JoystickGetAxis,(SDL_Joystick *a, int b),(a,b),return)
+SDL_DYNAPI_PROC(Uint8,SDL_JoystickGetHat,(SDL_Joystick *a, int b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_JoystickGetBall,(SDL_Joystick *a, int b, int *c, int *d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(Uint8,SDL_JoystickGetButton,(SDL_Joystick *a, int b),(a,b),return)
+SDL_DYNAPI_PROC(void,SDL_JoystickClose,(SDL_Joystick *a),(a),)
+SDL_DYNAPI_PROC(SDL_Window*,SDL_GetKeyboardFocus,(void),(),return)
+SDL_DYNAPI_PROC(const Uint8*,SDL_GetKeyboardState,(int *a),(a),return)
+SDL_DYNAPI_PROC(SDL_Keymod,SDL_GetModState,(void),(),return)
+SDL_DYNAPI_PROC(void,SDL_SetModState,(SDL_Keymod a),(a),)
+SDL_DYNAPI_PROC(SDL_Keycode,SDL_GetKeyFromScancode,(SDL_Scancode a),(a),return)
+SDL_DYNAPI_PROC(SDL_Scancode,SDL_GetScancodeFromKey,(SDL_Keycode a),(a),return)
+SDL_DYNAPI_PROC(const char*,SDL_GetScancodeName,(SDL_Scancode a),(a),return)
+SDL_DYNAPI_PROC(SDL_Scancode,SDL_GetScancodeFromName,(const char *a),(a),return)
+SDL_DYNAPI_PROC(const char*,SDL_GetKeyName,(SDL_Keycode a),(a),return)
+SDL_DYNAPI_PROC(SDL_Keycode,SDL_GetKeyFromName,(const char *a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_StartTextInput,(void),(),)
+SDL_DYNAPI_PROC(SDL_bool,SDL_IsTextInputActive,(void),(),return)
+SDL_DYNAPI_PROC(void,SDL_StopTextInput,(void),(),)
+SDL_DYNAPI_PROC(void,SDL_SetTextInputRect,(SDL_Rect *a),(a),)
+SDL_DYNAPI_PROC(SDL_bool,SDL_HasScreenKeyboardSupport,(void),(),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_IsScreenKeyboardShown,(SDL_Window *a),(a),return)
+SDL_DYNAPI_PROC(void*,SDL_LoadObject,(const char *a),(a),return)
+SDL_DYNAPI_PROC(void*,SDL_LoadFunction,(void *a, const char *b),(a,b),return)
+SDL_DYNAPI_PROC(void,SDL_UnloadObject,(void *a),(a),)
+SDL_DYNAPI_PROC(void,SDL_LogSetAllPriority,(SDL_LogPriority a),(a),)
+SDL_DYNAPI_PROC(void,SDL_LogSetPriority,(int a, SDL_LogPriority b),(a,b),)
+SDL_DYNAPI_PROC(SDL_LogPriority,SDL_LogGetPriority,(int a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_LogResetPriorities,(void),(),)
+SDL_DYNAPI_PROC(void,SDL_LogMessageV,(int a, SDL_LogPriority b, const char *c, va_list d),(a,b,c,d),)
+SDL_DYNAPI_PROC(void,SDL_LogGetOutputFunction,(SDL_LogOutputFunction *a, void **b),(a,b),)
+SDL_DYNAPI_PROC(void,SDL_LogSetOutputFunction,(SDL_LogOutputFunction a, void *b),(a,b),)
+SDL_DYNAPI_PROC(void,SDL_SetMainReady,(void),(),)
+SDL_DYNAPI_PROC(int,SDL_ShowMessageBox,(const SDL_MessageBoxData *a, int *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_ShowSimpleMessageBox,(Uint32 a, const char *b, const char *c, SDL_Window *d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(SDL_Window*,SDL_GetMouseFocus,(void),(),return)
+SDL_DYNAPI_PROC(Uint32,SDL_GetMouseState,(int *a, int *b),(a,b),return)
+SDL_DYNAPI_PROC(Uint32,SDL_GetRelativeMouseState,(int *a, int *b),(a,b),return)
+SDL_DYNAPI_PROC(void,SDL_WarpMouseInWindow,(SDL_Window *a, int b, int c),(a,b,c),)
+SDL_DYNAPI_PROC(int,SDL_SetRelativeMouseMode,(SDL_bool a),(a),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_GetRelativeMouseMode,(void),(),return)
+SDL_DYNAPI_PROC(SDL_Cursor*,SDL_CreateCursor,(const Uint8 *a, const Uint8 *b, int c, int d, int e, int f),(a,b,c,d,e,f),return)
+SDL_DYNAPI_PROC(SDL_Cursor*,SDL_CreateColorCursor,(SDL_Surface *a, int b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(SDL_Cursor*,SDL_CreateSystemCursor,(SDL_SystemCursor a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_SetCursor,(SDL_Cursor *a),(a),)
+SDL_DYNAPI_PROC(SDL_Cursor*,SDL_GetCursor,(void),(),return)
+SDL_DYNAPI_PROC(SDL_Cursor*,SDL_GetDefaultCursor,(void),(),return)
+SDL_DYNAPI_PROC(void,SDL_FreeCursor,(SDL_Cursor *a),(a),)
+SDL_DYNAPI_PROC(int,SDL_ShowCursor,(int a),(a),return)
+SDL_DYNAPI_PROC(SDL_mutex*,SDL_CreateMutex,(void),(),return)
+SDL_DYNAPI_PROC(int,SDL_LockMutex,(SDL_mutex *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_TryLockMutex,(SDL_mutex *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_UnlockMutex,(SDL_mutex *a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_DestroyMutex,(SDL_mutex *a),(a),)
+SDL_DYNAPI_PROC(SDL_sem*,SDL_CreateSemaphore,(Uint32 a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_DestroySemaphore,(SDL_sem *a),(a),)
+SDL_DYNAPI_PROC(int,SDL_SemWait,(SDL_sem *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_SemTryWait,(SDL_sem *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_SemWaitTimeout,(SDL_sem *a, Uint32 b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_SemPost,(SDL_sem *a),(a),return)
+SDL_DYNAPI_PROC(Uint32,SDL_SemValue,(SDL_sem *a),(a),return)
+SDL_DYNAPI_PROC(SDL_cond*,SDL_CreateCond,(void),(),return)
+SDL_DYNAPI_PROC(void,SDL_DestroyCond,(SDL_cond *a),(a),)
+SDL_DYNAPI_PROC(int,SDL_CondSignal,(SDL_cond *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_CondBroadcast,(SDL_cond *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_CondWait,(SDL_cond *a, SDL_mutex *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_CondWaitTimeout,(SDL_cond *a, SDL_mutex *b, Uint32 c),(a,b,c),return)
+SDL_DYNAPI_PROC(const char*,SDL_GetPixelFormatName,(Uint32 a),(a),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_PixelFormatEnumToMasks,(Uint32 a, int *b, Uint32 *c, Uint32 *d, Uint32 *e, Uint32 *f),(a,b,c,d,e,f),return)
+SDL_DYNAPI_PROC(Uint32,SDL_MasksToPixelFormatEnum,(int a, Uint32 b, Uint32 c, Uint32 d, Uint32 e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(SDL_PixelFormat*,SDL_AllocFormat,(Uint32 a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_FreeFormat,(SDL_PixelFormat *a),(a),)
+SDL_DYNAPI_PROC(SDL_Palette*,SDL_AllocPalette,(int a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_SetPixelFormatPalette,(SDL_PixelFormat *a, SDL_Palette *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_SetPaletteColors,(SDL_Palette *a, const SDL_Color *b, int c, int d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(void,SDL_FreePalette,(SDL_Palette *a),(a),)
+SDL_DYNAPI_PROC(Uint32,SDL_MapRGB,(const SDL_PixelFormat *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(Uint32,SDL_MapRGBA,(const SDL_PixelFormat *a, Uint8 b, Uint8 c, Uint8 d, Uint8 e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(void,SDL_GetRGB,(Uint32 a, const SDL_PixelFormat *b, Uint8 *c, Uint8 *d, Uint8 *e),(a,b,c,d,e),)
+SDL_DYNAPI_PROC(void,SDL_GetRGBA,(Uint32 a, const SDL_PixelFormat *b, Uint8 *c, Uint8 *d, Uint8 *e, Uint8 *f),(a,b,c,d,e,f),)
+SDL_DYNAPI_PROC(void,SDL_CalculateGammaRamp,(float a, Uint16 *b),(a,b),)
+SDL_DYNAPI_PROC(const char*,SDL_GetPlatform,(void),(),return)
+SDL_DYNAPI_PROC(SDL_PowerState,SDL_GetPowerInfo,(int *a, int *b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_HasIntersection,(const SDL_Rect *a, const SDL_Rect *b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_IntersectRect,(const SDL_Rect *a, const SDL_Rect *b, SDL_Rect *c),(a,b,c),return)
+SDL_DYNAPI_PROC(void,SDL_UnionRect,(const SDL_Rect *a, const SDL_Rect *b, SDL_Rect *c),(a,b,c),)
+SDL_DYNAPI_PROC(SDL_bool,SDL_EnclosePoints,(const SDL_Point *a, int b, const SDL_Rect *c, SDL_Rect *d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_IntersectRectAndLine,(const SDL_Rect *a, int *b, int *c, int *d, int *e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(int,SDL_GetNumRenderDrivers,(void),(),return)
+SDL_DYNAPI_PROC(int,SDL_GetRenderDriverInfo,(int a, SDL_RendererInfo *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_CreateWindowAndRenderer,(int a, int b, Uint32 c, SDL_Window **d, SDL_Renderer **e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(SDL_Renderer*,SDL_CreateRenderer,(SDL_Window *a, int b, Uint32 c),(a,b,c),return)
+SDL_DYNAPI_PROC(SDL_Renderer*,SDL_CreateSoftwareRenderer,(SDL_Surface *a),(a),return)
+SDL_DYNAPI_PROC(SDL_Renderer*,SDL_GetRenderer,(SDL_Window *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_GetRendererInfo,(SDL_Renderer *a, SDL_RendererInfo *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GetRendererOutputSize,(SDL_Renderer *a, int *b, int *c),(a,b,c),return)
+SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTexture,(SDL_Renderer *a, Uint32 b, int c, int d, int e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTextureFromSurface,(SDL_Renderer *a, SDL_Surface *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_QueryTexture,(SDL_Texture *a, Uint32 *b, int *c, int *d, int *e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(int,SDL_SetTextureColorMod,(SDL_Texture *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(int,SDL_GetTextureColorMod,(SDL_Texture *a, Uint8 *b, Uint8 *c, Uint8 *d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(int,SDL_SetTextureAlphaMod,(SDL_Texture *a, Uint8 b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GetTextureAlphaMod,(SDL_Texture *a, Uint8 *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_SetTextureBlendMode,(SDL_Texture *a, SDL_BlendMode b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GetTextureBlendMode,(SDL_Texture *a, SDL_BlendMode *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_UpdateTexture,(SDL_Texture *a, const SDL_Rect *b, const void *c, int d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(int,SDL_UpdateYUVTexture,(SDL_Texture *a, const SDL_Rect *b, const Uint8 *c, int d, const Uint8 *e, int f, const Uint8 *g, int h),(a,b,c,d,e,f,g,h),return)
+SDL_DYNAPI_PROC(int,SDL_LockTexture,(SDL_Texture *a, const SDL_Rect *b, void **c, int *d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(void,SDL_UnlockTexture,(SDL_Texture *a),(a),)
+SDL_DYNAPI_PROC(SDL_bool,SDL_RenderTargetSupported,(SDL_Renderer *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_SetRenderTarget,(SDL_Renderer *a, SDL_Texture *b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_Texture*,SDL_GetRenderTarget,(SDL_Renderer *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_RenderSetLogicalSize,(SDL_Renderer *a, int b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(void,SDL_RenderGetLogicalSize,(SDL_Renderer *a, int *b, int *c),(a,b,c),)
+SDL_DYNAPI_PROC(int,SDL_RenderSetViewport,(SDL_Renderer *a, const SDL_Rect *b),(a,b),return)
+SDL_DYNAPI_PROC(void,SDL_RenderGetViewport,(SDL_Renderer *a, SDL_Rect *b),(a,b),)
+SDL_DYNAPI_PROC(int,SDL_RenderSetClipRect,(SDL_Renderer *a, const SDL_Rect *b),(a,b),return)
+SDL_DYNAPI_PROC(void,SDL_RenderGetClipRect,(SDL_Renderer *a, SDL_Rect *b),(a,b),)
+SDL_DYNAPI_PROC(int,SDL_RenderSetScale,(SDL_Renderer *a, float b, float c),(a,b,c),return)
+SDL_DYNAPI_PROC(void,SDL_RenderGetScale,(SDL_Renderer *a, float *b, float *c),(a,b,c),)
+SDL_DYNAPI_PROC(int,SDL_SetRenderDrawColor,(SDL_Renderer *a, Uint8 b, Uint8 c, Uint8 d, Uint8 e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(int,SDL_GetRenderDrawColor,(SDL_Renderer *a, Uint8 *b, Uint8 *c, Uint8 *d, Uint8 *e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(int,SDL_SetRenderDrawBlendMode,(SDL_Renderer *a, SDL_BlendMode b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GetRenderDrawBlendMode,(SDL_Renderer *a, SDL_BlendMode *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_RenderClear,(SDL_Renderer *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_RenderDrawPoint,(SDL_Renderer *a, int b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_RenderDrawPoints,(SDL_Renderer *a, const SDL_Point *b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_RenderDrawLine,(SDL_Renderer *a, int b, int c, int d, int e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(int,SDL_RenderDrawLines,(SDL_Renderer *a, const SDL_Point *b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_RenderDrawRect,(SDL_Renderer *a, const SDL_Rect *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_RenderDrawRects,(SDL_Renderer *a, const SDL_Rect *b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_RenderFillRect,(SDL_Renderer *a, const SDL_Rect *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_RenderFillRects,(SDL_Renderer *a, const SDL_Rect *b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_RenderCopy,(SDL_Renderer *a, SDL_Texture *b, const SDL_Rect *c, const SDL_Rect *d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(int,SDL_RenderCopyEx,(SDL_Renderer *a, SDL_Texture *b, const SDL_Rect *c, const SDL_Rect *d, const double e, const SDL_Point *f, const SDL_RendererFlip g),(a,b,c,d,e,f,g),return)
+SDL_DYNAPI_PROC(int,SDL_RenderReadPixels,(SDL_Renderer *a, const SDL_Rect *b, Uint32 c, void *d, int e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(void,SDL_RenderPresent,(SDL_Renderer *a),(a),)
+SDL_DYNAPI_PROC(void,SDL_DestroyTexture,(SDL_Texture *a),(a),)
+SDL_DYNAPI_PROC(void,SDL_DestroyRenderer,(SDL_Renderer *a),(a),)
+SDL_DYNAPI_PROC(int,SDL_GL_BindTexture,(SDL_Texture *a, float *b, float *c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_GL_UnbindTexture,(SDL_Texture *a),(a),return)
+SDL_DYNAPI_PROC(SDL_RWops*,SDL_RWFromFile,(const char *a, const char *b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_RWops*,SDL_RWFromMem,(void *a, int b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_RWops*,SDL_RWFromConstMem,(const void *a, int b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_RWops*,SDL_AllocRW,(void),(),return)
+SDL_DYNAPI_PROC(void,SDL_FreeRW,(SDL_RWops *a),(a),)
+SDL_DYNAPI_PROC(Uint8,SDL_ReadU8,(SDL_RWops *a),(a),return)
+SDL_DYNAPI_PROC(Uint16,SDL_ReadLE16,(SDL_RWops *a),(a),return)
+SDL_DYNAPI_PROC(Uint16,SDL_ReadBE16,(SDL_RWops *a),(a),return)
+SDL_DYNAPI_PROC(Uint32,SDL_ReadLE32,(SDL_RWops *a),(a),return)
+SDL_DYNAPI_PROC(Uint32,SDL_ReadBE32,(SDL_RWops *a),(a),return)
+SDL_DYNAPI_PROC(Uint64,SDL_ReadLE64,(SDL_RWops *a),(a),return)
+SDL_DYNAPI_PROC(Uint64,SDL_ReadBE64,(SDL_RWops *a),(a),return)
+SDL_DYNAPI_PROC(size_t,SDL_WriteU8,(SDL_RWops *a, Uint8 b),(a,b),return)
+SDL_DYNAPI_PROC(size_t,SDL_WriteLE16,(SDL_RWops *a, Uint16 b),(a,b),return)
+SDL_DYNAPI_PROC(size_t,SDL_WriteBE16,(SDL_RWops *a, Uint16 b),(a,b),return)
+SDL_DYNAPI_PROC(size_t,SDL_WriteLE32,(SDL_RWops *a, Uint32 b),(a,b),return)
+SDL_DYNAPI_PROC(size_t,SDL_WriteBE32,(SDL_RWops *a, Uint32 b),(a,b),return)
+SDL_DYNAPI_PROC(size_t,SDL_WriteLE64,(SDL_RWops *a, Uint64 b),(a,b),return)
+SDL_DYNAPI_PROC(size_t,SDL_WriteBE64,(SDL_RWops *a, Uint64 b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateShapedWindow,(const char *a, unsigned int b, unsigned int c, unsigned int d, unsigned int e, Uint32 f),(a,b,c,d,e,f),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_IsShapedWindow,(const SDL_Window *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_SetWindowShape,(SDL_Window *a, SDL_Surface *b, SDL_WindowShapeMode *c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_GetShapedWindowMode,(SDL_Window *a, SDL_WindowShapeMode *b),(a,b),return)
+SDL_DYNAPI_PROC(void*,SDL_malloc,(size_t a),(a),return)
+SDL_DYNAPI_PROC(void*,SDL_calloc,(size_t a, size_t b),(a,b),return)
+SDL_DYNAPI_PROC(void*,SDL_realloc,(void *a, size_t b),(a,b),return)
+SDL_DYNAPI_PROC(void,SDL_free,(void *a),(a),)
+SDL_DYNAPI_PROC(char*,SDL_getenv,(const char *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_setenv,(const char *a, const char *b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(void,SDL_qsort,(void *a, size_t b, size_t c, int (*d)(const void *, const void *)),(a,b,c,d),)
+SDL_DYNAPI_PROC(int,SDL_abs,(int a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_isdigit,(int a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_isspace,(int a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_toupper,(int a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_tolower,(int a),(a),return)
+SDL_DYNAPI_PROC(void*,SDL_memset,(SDL_OUT_BYTECAP(c) void *a, int b, size_t c),(a,b,c),return)
+SDL_DYNAPI_PROC(void*,SDL_memcpy,(SDL_OUT_BYTECAP(c) void *a, SDL_IN_BYTECAP(c) const void *b, size_t c),(a,b,c),return)
+SDL_DYNAPI_PROC(void*,SDL_memmove,(SDL_OUT_BYTECAP(c) void *a, SDL_IN_BYTECAP(c) const void *b, size_t c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_memcmp,(const void *a, const void *b, size_t c),(a,b,c),return)
+SDL_DYNAPI_PROC(size_t,SDL_wcslen,(const wchar_t *a),(a),return)
+SDL_DYNAPI_PROC(size_t,SDL_wcslcpy,(SDL_OUT_Z_CAP(c) wchar_t *a, const wchar_t *b, size_t c),(a,b,c),return)
+SDL_DYNAPI_PROC(size_t,SDL_wcslcat,(SDL_INOUT_Z_CAP(c) wchar_t *a, const wchar_t *b, size_t c),(a,b,c),return)
+SDL_DYNAPI_PROC(size_t,SDL_strlen,(const char *a),(a),return)
+SDL_DYNAPI_PROC(size_t,SDL_strlcpy,(SDL_OUT_Z_CAP(c) char *a, const char *b, size_t c),(a,b,c),return)
+SDL_DYNAPI_PROC(size_t,SDL_utf8strlcpy,(SDL_OUT_Z_CAP(c) char *a, const char *b, size_t c),(a,b,c),return)
+SDL_DYNAPI_PROC(size_t,SDL_strlcat,(SDL_INOUT_Z_CAP(c) char *a, const char *b, size_t c),(a,b,c),return)
+SDL_DYNAPI_PROC(char*,SDL_strdup,(const char *a),(a),return)
+SDL_DYNAPI_PROC(char*,SDL_strrev,(char *a),(a),return)
+SDL_DYNAPI_PROC(char*,SDL_strupr,(char *a),(a),return)
+SDL_DYNAPI_PROC(char*,SDL_strlwr,(char *a),(a),return)
+SDL_DYNAPI_PROC(char*,SDL_strchr,(const char *a, int b),(a,b),return)
+SDL_DYNAPI_PROC(char*,SDL_strrchr,(const char *a, int b),(a,b),return)
+SDL_DYNAPI_PROC(char*,SDL_strstr,(const char *a, const char *b),(a,b),return)
+SDL_DYNAPI_PROC(char*,SDL_itoa,(int a, char *b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(char*,SDL_uitoa,(unsigned int a, char *b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(char*,SDL_ltoa,(long a, char *b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(char*,SDL_ultoa,(unsigned long a, char *b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(char*,SDL_lltoa,(Sint64 a, char *b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(char*,SDL_ulltoa,(Uint64 a, char *b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_atoi,(const char *a),(a),return)
+SDL_DYNAPI_PROC(double,SDL_atof,(const char *a),(a),return)
+SDL_DYNAPI_PROC(long,SDL_strtol,(const char *a, char **b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(unsigned long,SDL_strtoul,(const char *a, char **b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(Sint64,SDL_strtoll,(const char *a, char **b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(Uint64,SDL_strtoull,(const char *a, char **b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(double,SDL_strtod,(const char *a, char **b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_strcmp,(const char *a, const char *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_strncmp,(const char *a, const char *b, size_t c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_strcasecmp,(const char *a, const char *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_strncasecmp,(const char *a, const char *b, size_t c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_vsnprintf,(SDL_OUT_Z_CAP(b) char *a, size_t b, const char *c, va_list d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(double,SDL_acos,(double a),(a),return)
+SDL_DYNAPI_PROC(double,SDL_asin,(double a),(a),return)
+SDL_DYNAPI_PROC(double,SDL_atan,(double a),(a),return)
+SDL_DYNAPI_PROC(double,SDL_atan2,(double a, double b),(a,b),return)
+SDL_DYNAPI_PROC(double,SDL_ceil,(double a),(a),return)
+SDL_DYNAPI_PROC(double,SDL_copysign,(double a, double b),(a,b),return)
+SDL_DYNAPI_PROC(double,SDL_cos,(double a),(a),return)
+SDL_DYNAPI_PROC(float,SDL_cosf,(float a),(a),return)
+SDL_DYNAPI_PROC(double,SDL_fabs,(double a),(a),return)
+SDL_DYNAPI_PROC(double,SDL_floor,(double a),(a),return)
+SDL_DYNAPI_PROC(double,SDL_log,(double a),(a),return)
+SDL_DYNAPI_PROC(double,SDL_pow,(double a, double b),(a,b),return)
+SDL_DYNAPI_PROC(double,SDL_scalbn,(double a, int b),(a,b),return)
+SDL_DYNAPI_PROC(double,SDL_sin,(double a),(a),return)
+SDL_DYNAPI_PROC(float,SDL_sinf,(float a),(a),return)
+SDL_DYNAPI_PROC(double,SDL_sqrt,(double a),(a),return)
+SDL_DYNAPI_PROC(SDL_iconv_t,SDL_iconv_open,(const char *a, const char *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_iconv_close,(SDL_iconv_t a),(a),return)
+SDL_DYNAPI_PROC(size_t,SDL_iconv,(SDL_iconv_t a, const char **b, size_t *c, char **d, size_t *e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(char*,SDL_iconv_string,(const char *a, const char *b, const char *c, size_t d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateRGBSurface,(Uint32 a, int b, int c, int d, Uint32 e, Uint32 f, Uint32 g, Uint32 h),(a,b,c,d,e,f,g,h),return)
+SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateRGBSurfaceFrom,(void *a, int b, int c, int d, int e, Uint32 f, Uint32 g, Uint32 h, Uint32 i),(a,b,c,d,e,f,g,h,i),return)
+SDL_DYNAPI_PROC(void,SDL_FreeSurface,(SDL_Surface *a),(a),)
+SDL_DYNAPI_PROC(int,SDL_SetSurfacePalette,(SDL_Surface *a, SDL_Palette *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_LockSurface,(SDL_Surface *a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_UnlockSurface,(SDL_Surface *a),(a),)
+SDL_DYNAPI_PROC(SDL_Surface*,SDL_LoadBMP_RW,(SDL_RWops *a, int b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_SaveBMP_RW,(SDL_Surface *a, SDL_RWops *b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_SetSurfaceRLE,(SDL_Surface *a, int b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_SetColorKey,(SDL_Surface *a, int b, Uint32 c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_GetColorKey,(SDL_Surface *a, Uint32 *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_SetSurfaceColorMod,(SDL_Surface *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(int,SDL_GetSurfaceColorMod,(SDL_Surface *a, Uint8 *b, Uint8 *c, Uint8 *d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(int,SDL_SetSurfaceAlphaMod,(SDL_Surface *a, Uint8 b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GetSurfaceAlphaMod,(SDL_Surface *a, Uint8 *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_SetSurfaceBlendMode,(SDL_Surface *a, SDL_BlendMode b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GetSurfaceBlendMode,(SDL_Surface *a, SDL_BlendMode *b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_SetClipRect,(SDL_Surface *a, const SDL_Rect *b),(a,b),return)
+SDL_DYNAPI_PROC(void,SDL_GetClipRect,(SDL_Surface *a, SDL_Rect *b),(a,b),)
+SDL_DYNAPI_PROC(SDL_Surface*,SDL_ConvertSurface,(SDL_Surface *a, const SDL_PixelFormat *b, Uint32 c),(a,b,c),return)
+SDL_DYNAPI_PROC(SDL_Surface*,SDL_ConvertSurfaceFormat,(SDL_Surface *a, Uint32 b, Uint32 c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_ConvertPixels,(int a, int b, Uint32 c, const void *d, int e, Uint32 f, void *g, int h),(a,b,c,d,e,f,g,h),return)
+SDL_DYNAPI_PROC(int,SDL_FillRect,(SDL_Surface *a, const SDL_Rect *b, Uint32 c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_FillRects,(SDL_Surface *a, const SDL_Rect *b, int c, Uint32 d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(int,SDL_UpperBlit,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, SDL_Rect *d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(int,SDL_LowerBlit,(SDL_Surface *a, SDL_Rect *b, SDL_Surface *c, SDL_Rect *d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(int,SDL_SoftStretch,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(int,SDL_UpperBlitScaled,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, SDL_Rect *d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(int,SDL_LowerBlitScaled,(SDL_Surface *a, SDL_Rect *b, SDL_Surface *c, SDL_Rect *d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_GetWindowWMInfo,(SDL_Window *a, SDL_SysWMinfo *b),(a,b),return)
+SDL_DYNAPI_PROC(const char*,SDL_GetThreadName,(SDL_Thread *a),(a),return)
+SDL_DYNAPI_PROC(SDL_threadID,SDL_ThreadID,(void),(),return)
+SDL_DYNAPI_PROC(SDL_threadID,SDL_GetThreadID,(SDL_Thread *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_SetThreadPriority,(SDL_ThreadPriority a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_WaitThread,(SDL_Thread *a, int *b),(a,b),)
+SDL_DYNAPI_PROC(void,SDL_DetachThread,(SDL_Thread *a),(a),)
+SDL_DYNAPI_PROC(SDL_TLSID,SDL_TLSCreate,(void),(),return)
+SDL_DYNAPI_PROC(void*,SDL_TLSGet,(SDL_TLSID a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_TLSSet,(SDL_TLSID a, const void *b, void (*c)(void*)),(a,b,c),return)
+SDL_DYNAPI_PROC(Uint32,SDL_GetTicks,(void),(),return)
+SDL_DYNAPI_PROC(Uint64,SDL_GetPerformanceCounter,(void),(),return)
+SDL_DYNAPI_PROC(Uint64,SDL_GetPerformanceFrequency,(void),(),return)
+SDL_DYNAPI_PROC(void,SDL_Delay,(Uint32 a),(a),)
+SDL_DYNAPI_PROC(SDL_TimerID,SDL_AddTimer,(Uint32 a, SDL_TimerCallback b, void *c),(a,b,c),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_RemoveTimer,(SDL_TimerID a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_GetNumTouchDevices,(void),(),return)
+SDL_DYNAPI_PROC(SDL_TouchID,SDL_GetTouchDevice,(int a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_GetNumTouchFingers,(SDL_TouchID a),(a),return)
+SDL_DYNAPI_PROC(SDL_Finger*,SDL_GetTouchFinger,(SDL_TouchID a, int b),(a,b),return)
+SDL_DYNAPI_PROC(void,SDL_GetVersion,(SDL_version *a),(a),)
+SDL_DYNAPI_PROC(const char*,SDL_GetRevision,(void),(),return)
+SDL_DYNAPI_PROC(int,SDL_GetRevisionNumber,(void),(),return)
+SDL_DYNAPI_PROC(int,SDL_GetNumVideoDrivers,(void),(),return)
+SDL_DYNAPI_PROC(const char*,SDL_GetVideoDriver,(int a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_VideoInit,(const char *a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_VideoQuit,(void),(),)
+SDL_DYNAPI_PROC(const char*,SDL_GetCurrentVideoDriver,(void),(),return)
+SDL_DYNAPI_PROC(int,SDL_GetNumVideoDisplays,(void),(),return)
+SDL_DYNAPI_PROC(const char*,SDL_GetDisplayName,(int a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_GetDisplayBounds,(int a, SDL_Rect *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GetNumDisplayModes,(int a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_GetDisplayMode,(int a, int b, SDL_DisplayMode *c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_GetDesktopDisplayMode,(int a, SDL_DisplayMode *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GetCurrentDisplayMode,(int a, SDL_DisplayMode *b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_DisplayMode*,SDL_GetClosestDisplayMode,(int a, const SDL_DisplayMode *b, SDL_DisplayMode *c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_GetWindowDisplayIndex,(SDL_Window *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_SetWindowDisplayMode,(SDL_Window *a, const SDL_DisplayMode *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GetWindowDisplayMode,(SDL_Window *a, SDL_DisplayMode *b),(a,b),return)
+SDL_DYNAPI_PROC(Uint32,SDL_GetWindowPixelFormat,(SDL_Window *a),(a),return)
+SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateWindow,(const char *a, int b, int c, int d, int e, Uint32 f),(a,b,c,d,e,f),return)
+SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateWindowFrom,(const void *a),(a),return)
+SDL_DYNAPI_PROC(Uint32,SDL_GetWindowID,(SDL_Window *a),(a),return)
+SDL_DYNAPI_PROC(SDL_Window*,SDL_GetWindowFromID,(Uint32 a),(a),return)
+SDL_DYNAPI_PROC(Uint32,SDL_GetWindowFlags,(SDL_Window *a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_SetWindowTitle,(SDL_Window *a, const char *b),(a,b),)
+SDL_DYNAPI_PROC(const char*,SDL_GetWindowTitle,(SDL_Window *a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_SetWindowIcon,(SDL_Window *a, SDL_Surface *b),(a,b),)
+SDL_DYNAPI_PROC(void*,SDL_SetWindowData,(SDL_Window *a, const char *b, void *c),(a,b,c),return)
+SDL_DYNAPI_PROC(void*,SDL_GetWindowData,(SDL_Window *a, const char *b),(a,b),return)
+SDL_DYNAPI_PROC(void,SDL_SetWindowPosition,(SDL_Window *a, int b, int c),(a,b,c),)
+SDL_DYNAPI_PROC(void,SDL_GetWindowPosition,(SDL_Window *a, int *b, int *c),(a,b,c),)
+SDL_DYNAPI_PROC(void,SDL_SetWindowSize,(SDL_Window *a, int b, int c),(a,b,c),)
+SDL_DYNAPI_PROC(void,SDL_GetWindowSize,(SDL_Window *a, int *b, int *c),(a,b,c),)
+SDL_DYNAPI_PROC(void,SDL_SetWindowMinimumSize,(SDL_Window *a, int b, int c),(a,b,c),)
+SDL_DYNAPI_PROC(void,SDL_GetWindowMinimumSize,(SDL_Window *a, int *b, int *c),(a,b,c),)
+SDL_DYNAPI_PROC(void,SDL_SetWindowMaximumSize,(SDL_Window *a, int b, int c),(a,b,c),)
+SDL_DYNAPI_PROC(void,SDL_GetWindowMaximumSize,(SDL_Window *a, int *b, int *c),(a,b,c),)
+SDL_DYNAPI_PROC(void,SDL_SetWindowBordered,(SDL_Window *a, SDL_bool b),(a,b),)
+SDL_DYNAPI_PROC(void,SDL_ShowWindow,(SDL_Window *a),(a),)
+SDL_DYNAPI_PROC(void,SDL_HideWindow,(SDL_Window *a),(a),)
+SDL_DYNAPI_PROC(void,SDL_RaiseWindow,(SDL_Window *a),(a),)
+SDL_DYNAPI_PROC(void,SDL_MaximizeWindow,(SDL_Window *a),(a),)
+SDL_DYNAPI_PROC(void,SDL_MinimizeWindow,(SDL_Window *a),(a),)
+SDL_DYNAPI_PROC(void,SDL_RestoreWindow,(SDL_Window *a),(a),)
+SDL_DYNAPI_PROC(int,SDL_SetWindowFullscreen,(SDL_Window *a, Uint32 b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_Surface*,SDL_GetWindowSurface,(SDL_Window *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_UpdateWindowSurface,(SDL_Window *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_UpdateWindowSurfaceRects,(SDL_Window *a, const SDL_Rect *b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(void,SDL_SetWindowGrab,(SDL_Window *a, SDL_bool b),(a,b),)
+SDL_DYNAPI_PROC(SDL_bool,SDL_GetWindowGrab,(SDL_Window *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_SetWindowBrightness,(SDL_Window *a, float b),(a,b),return)
+SDL_DYNAPI_PROC(float,SDL_GetWindowBrightness,(SDL_Window *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_SetWindowGammaRamp,(SDL_Window *a, const Uint16 *b, const Uint16 *c, const Uint16 *d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(int,SDL_GetWindowGammaRamp,(SDL_Window *a, Uint16 *b, Uint16 *c, Uint16 *d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(void,SDL_DestroyWindow,(SDL_Window *a),(a),)
+SDL_DYNAPI_PROC(SDL_bool,SDL_IsScreenSaverEnabled,(void),(),return)
+SDL_DYNAPI_PROC(void,SDL_EnableScreenSaver,(void),(),)
+SDL_DYNAPI_PROC(void,SDL_DisableScreenSaver,(void),(),)
+SDL_DYNAPI_PROC(int,SDL_GL_LoadLibrary,(const char *a),(a),return)
+SDL_DYNAPI_PROC(void*,SDL_GL_GetProcAddress,(const char *a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_GL_UnloadLibrary,(void),(),)
+SDL_DYNAPI_PROC(SDL_bool,SDL_GL_ExtensionSupported,(const char *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_GL_SetAttribute,(SDL_GLattr a, int b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GL_GetAttribute,(SDL_GLattr a, int *b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_GLContext,SDL_GL_CreateContext,(SDL_Window *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_GL_MakeCurrent,(SDL_Window *a, SDL_GLContext b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_Window*,SDL_GL_GetCurrentWindow,(void),(),return)
+SDL_DYNAPI_PROC(SDL_GLContext,SDL_GL_GetCurrentContext,(void),(),return)
+SDL_DYNAPI_PROC(void,SDL_GL_GetDrawableSize,(SDL_Window *a, int *b, int *c),(a,b,c),)
+SDL_DYNAPI_PROC(int,SDL_GL_SetSwapInterval,(int a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_GL_GetSwapInterval,(void),(),return)
+SDL_DYNAPI_PROC(void,SDL_GL_SwapWindow,(SDL_Window *a),(a),)
+SDL_DYNAPI_PROC(void,SDL_GL_DeleteContext,(SDL_GLContext a),(a),)
+SDL_DYNAPI_PROC(int,SDL_vsscanf,(const char *a, const char *b, va_list c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_GameControllerAddMappingsFromRW,(SDL_RWops *a, int b),(a,b),return)
+SDL_DYNAPI_PROC(void,SDL_GL_ResetAttributes,(void),(),)
+SDL_DYNAPI_PROC(SDL_bool,SDL_HasAVX,(void),(),return)
+SDL_DYNAPI_PROC(SDL_AssertionHandler,SDL_GetDefaultAssertionHandler,(void),(),return)
+SDL_DYNAPI_PROC(SDL_AssertionHandler,SDL_GetAssertionHandler,(void **a),(a),return)
+#ifdef __WIN32__
+SDL_DYNAPI_PROC(SDL_bool,SDL_DXGIGetOutputInfo,(int a,int *b, int *c),(a,b,c),return)
+#endif
+SDL_DYNAPI_PROC(SDL_bool,SDL_RenderIsClipEnabled,(SDL_Renderer *a),(a),return)
+#ifdef __WINRT__
+SDL_DYNAPI_PROC(int,SDL_WinRTRunApp,(int a, char **b, void *c),(a,b,c),return)
+SDL_DYNAPI_PROC(const wchar_t*,SDL_WinRTGetFSPathUNICODE,(SDL_WinRT_Path a),(a),return)
+SDL_DYNAPI_PROC(const char*,SDL_WinRTGetFSPathUTF8,(SDL_WinRT_Path a),(a),return)
+#endif
+SDL_DYNAPI_PROC(int,SDL_WarpMouseGlobal,(int a, int b),(a,b),return)
+SDL_DYNAPI_PROC(float,SDL_sqrtf,(float a),(a),return)
+SDL_DYNAPI_PROC(double,SDL_tan,(double a),(a),return)
+SDL_DYNAPI_PROC(float,SDL_tanf,(float a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_CaptureMouse,(SDL_bool a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_SetWindowHitTest,(SDL_Window *a, SDL_HitTest b, void *c),(a,b,c),return)
+SDL_DYNAPI_PROC(Uint32,SDL_GetGlobalMouseState,(int *a, int *b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_HasAVX2,(void),(),return)
+SDL_DYNAPI_PROC(int,SDL_QueueAudio,(SDL_AudioDeviceID a, const void *b, Uint32 c),(a,b,c),return)
+SDL_DYNAPI_PROC(Uint32,SDL_GetQueuedAudioSize,(SDL_AudioDeviceID a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_ClearQueuedAudio,(SDL_AudioDeviceID a),(a),)
+SDL_DYNAPI_PROC(SDL_Window*,SDL_GetGrabbedWindow,(void),(),return)
+#ifdef __WIN32__
+SDL_DYNAPI_PROC(void,SDL_SetWindowsMessageHook,(SDL_WindowsMessageHook a, void *b),(a,b),)
+#endif
+SDL_DYNAPI_PROC(int,SDL_GetDisplayDPI,(int a, float *b, float *c, float *d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(SDL_JoystickPowerLevel,SDL_JoystickCurrentPowerLevel,(SDL_Joystick *a),(a),return)
+SDL_DYNAPI_PROC(SDL_GameController*,SDL_GameControllerFromInstanceID,(SDL_JoystickID a),(a),return)
+SDL_DYNAPI_PROC(SDL_Joystick*,SDL_JoystickFromInstanceID,(SDL_JoystickID a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_GetDisplayUsableBounds,(int a, SDL_Rect *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GetWindowBordersSize,(SDL_Window *a, int *b, int *c, int *d, int *e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(int,SDL_SetWindowOpacity,(SDL_Window *a, float b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GetWindowOpacity,(SDL_Window *a, float *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_SetWindowInputFocus,(SDL_Window *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_SetWindowModalFor,(SDL_Window *a, SDL_Window *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_RenderSetIntegerScale,(SDL_Renderer *a, SDL_bool b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_RenderGetIntegerScale,(SDL_Renderer *a),(a),return)
+SDL_DYNAPI_PROC(Uint32,SDL_DequeueAudio,(SDL_AudioDeviceID a, void *b, Uint32 c),(a,b,c),return)
+SDL_DYNAPI_PROC(void,SDL_SetWindowResizable,(SDL_Window *a, SDL_bool b),(a,b),)
+SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateRGBSurfaceWithFormat,(Uint32 a, int b, int c, int d, Uint32 e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateRGBSurfaceWithFormatFrom,(void *a, int b, int c, int d, int e, Uint32 f),(a,b,c,d,e,f),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_GetHintBoolean,(const char *a, SDL_bool b),(a,b),return)
+SDL_DYNAPI_PROC(Uint16,SDL_JoystickGetDeviceVendor,(int a),(a),return)
+SDL_DYNAPI_PROC(Uint16,SDL_JoystickGetDeviceProduct,(int a),(a),return)
+SDL_DYNAPI_PROC(Uint16,SDL_JoystickGetDeviceProductVersion,(int a),(a),return)
+SDL_DYNAPI_PROC(Uint16,SDL_JoystickGetVendor,(SDL_Joystick *a),(a),return)
+SDL_DYNAPI_PROC(Uint16,SDL_JoystickGetProduct,(SDL_Joystick *a),(a),return)
+SDL_DYNAPI_PROC(Uint16,SDL_JoystickGetProductVersion,(SDL_Joystick *a),(a),return)
+SDL_DYNAPI_PROC(Uint16,SDL_GameControllerGetVendor,(SDL_GameController *a),(a),return)
+SDL_DYNAPI_PROC(Uint16,SDL_GameControllerGetProduct,(SDL_GameController *a),(a),return)
+SDL_DYNAPI_PROC(Uint16,SDL_GameControllerGetProductVersion,(SDL_GameController *a),(a),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_HasNEON,(void),(),return)
+SDL_DYNAPI_PROC(int,SDL_GameControllerNumMappings,(void),(),return)
+SDL_DYNAPI_PROC(char*,SDL_GameControllerMappingForIndex,(int a),(a),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_JoystickGetAxisInitialState,(SDL_Joystick *a, int b, Sint16 *c),(a,b,c),return)
+SDL_DYNAPI_PROC(SDL_JoystickType,SDL_JoystickGetDeviceType,(int a),(a),return)
+SDL_DYNAPI_PROC(SDL_JoystickType,SDL_JoystickGetType,(SDL_Joystick *a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_MemoryBarrierReleaseFunction,(void),(),)
+SDL_DYNAPI_PROC(void,SDL_MemoryBarrierAcquireFunction,(void),(),)
+SDL_DYNAPI_PROC(SDL_JoystickID,SDL_JoystickGetDeviceInstanceID,(int a),(a),return)
+SDL_DYNAPI_PROC(size_t,SDL_utf8strlen,(const char *a),(a),return)
+SDL_DYNAPI_PROC(void*,SDL_LoadFile_RW,(SDL_RWops *a, size_t *b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_wcscmp,(const wchar_t *a, const wchar_t *b),(a,b),return)
+SDL_DYNAPI_PROC(SDL_BlendMode,SDL_ComposeCustomBlendMode,(SDL_BlendFactor a, SDL_BlendFactor b, SDL_BlendOperation c, SDL_BlendFactor d, SDL_BlendFactor e, SDL_BlendOperation f),(a,b,c,d,e,f),return)
+SDL_DYNAPI_PROC(SDL_Surface*,SDL_DuplicateSurface,(SDL_Surface *a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_Vulkan_LoadLibrary,(const char *a),(a),return)
+SDL_DYNAPI_PROC(void*,SDL_Vulkan_GetVkGetInstanceProcAddr,(void),(),return)
+SDL_DYNAPI_PROC(void,SDL_Vulkan_UnloadLibrary,(void),(),)
+SDL_DYNAPI_PROC(SDL_bool,SDL_Vulkan_GetInstanceExtensions,(SDL_Window *a, unsigned int *b, const char **c),(a,b,c),return)
+SDL_DYNAPI_PROC(SDL_bool,SDL_Vulkan_CreateSurface,(SDL_Window *a, VkInstance b, VkSurfaceKHR *c),(a,b,c),return)
+SDL_DYNAPI_PROC(void,SDL_Vulkan_GetDrawableSize,(SDL_Window *a, int *b, int *c),(a,b,c),)
+SDL_DYNAPI_PROC(void,SDL_LockJoysticks,(void),(),)
+SDL_DYNAPI_PROC(void,SDL_UnlockJoysticks,(void),(),)
+SDL_DYNAPI_PROC(void,SDL_GetMemoryFunctions,(SDL_malloc_func *a, SDL_calloc_func *b, SDL_realloc_func *c, SDL_free_func *d),(a,b,c,d),)
+SDL_DYNAPI_PROC(int,SDL_SetMemoryFunctions,(SDL_malloc_func a, SDL_calloc_func b, SDL_realloc_func c, SDL_free_func d),(a,b,c,d),return)
+SDL_DYNAPI_PROC(int,SDL_GetNumAllocations,(void),(),return)
+SDL_DYNAPI_PROC(SDL_AudioStream*,SDL_NewAudioStream,(const SDL_AudioFormat a, const Uint8 b, const int c, const SDL_AudioFormat d, const Uint8 e, const int f),(a,b,c,d,e,f),return)
+SDL_DYNAPI_PROC(int,SDL_AudioStreamPut,(SDL_AudioStream *a, const void *b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_AudioStreamGet,(SDL_AudioStream *a, void *b, int c),(a,b,c),return)
+SDL_DYNAPI_PROC(void,SDL_AudioStreamClear,(SDL_AudioStream *a),(a),)
+SDL_DYNAPI_PROC(int,SDL_AudioStreamAvailable,(SDL_AudioStream *a),(a),return)
+SDL_DYNAPI_PROC(void,SDL_FreeAudioStream,(SDL_AudioStream *a),(a),)
+SDL_DYNAPI_PROC(int,SDL_AudioStreamFlush,(SDL_AudioStream *a),(a),return)
+SDL_DYNAPI_PROC(float,SDL_acosf,(float a),(a),return)
+SDL_DYNAPI_PROC(float,SDL_asinf,(float a),(a),return)
+SDL_DYNAPI_PROC(float,SDL_atanf,(float a),(a),return)
+SDL_DYNAPI_PROC(float,SDL_atan2f,(float a, float b),(a,b),return)
+SDL_DYNAPI_PROC(float,SDL_ceilf,(float a),(a),return)
+SDL_DYNAPI_PROC(float,SDL_copysignf,(float a, float b),(a,b),return)
+SDL_DYNAPI_PROC(float,SDL_fabsf,(float a),(a),return)
+SDL_DYNAPI_PROC(float,SDL_floorf,(float a),(a),return)
+SDL_DYNAPI_PROC(float,SDL_logf,(float a),(a),return)
+SDL_DYNAPI_PROC(float,SDL_powf,(float a, float b),(a,b),return)
+SDL_DYNAPI_PROC(float,SDL_scalbnf,(float a, int b),(a,b),return)
+SDL_DYNAPI_PROC(double,SDL_fmod,(double a, double b),(a,b),return)
+SDL_DYNAPI_PROC(float,SDL_fmodf,(float a, float b),(a,b),return)
+SDL_DYNAPI_PROC(void,SDL_SetYUVConversionMode,(SDL_YUV_CONVERSION_MODE a),(a),)
+SDL_DYNAPI_PROC(SDL_YUV_CONVERSION_MODE,SDL_GetYUVConversionMode,(void),(),return)
+SDL_DYNAPI_PROC(SDL_YUV_CONVERSION_MODE,SDL_GetYUVConversionModeForResolution,(int a, int b),(a,b),return)
+SDL_DYNAPI_PROC(void*,SDL_RenderGetMetalLayer,(SDL_Renderer *a),(a),return)
+SDL_DYNAPI_PROC(void*,SDL_RenderGetMetalCommandEncoder,(SDL_Renderer *a),(a),return)
+#ifdef __WINRT__
+SDL_DYNAPI_PROC(SDL_WinRT_DeviceFamily,SDL_WinRTGetDeviceFamily,(void),(),return)
+#endif
+#ifdef __ANDROID__
+SDL_DYNAPI_PROC(SDL_bool,SDL_IsAndroidTV,(void),(),return)
+#endif
+SDL_DYNAPI_PROC(double,SDL_log10,(double a),(a),return)
+SDL_DYNAPI_PROC(float,SDL_log10f,(float a),(a),return)
diff --git a/src/3rdparty/SDL2/src/dynapi/gendynapi.pl b/src/3rdparty/SDL2/src/dynapi/gendynapi.pl
new file mode 100644
index 0000000..721241b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/dynapi/gendynapi.pl
@@ -0,0 +1,141 @@
+#!/usr/bin/perl -w
+
+# Simple DirectMedia Layer
+# Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+#
+# This software is provided 'as-is', without any express or implied
+# warranty. In no event will the authors be held liable for any damages
+# arising from the use of this software.
+#
+# Permission is granted to anyone to use this software for any purpose,
+# including commercial applications, and to alter it and redistribute it
+# freely, subject to the following restrictions:
+#
+# 1. The origin of this software must not be misrepresented; you must not
+# claim that you wrote the original software. If you use this software
+# in a product, an acknowledgment in the product documentation would be
+# appreciated but is not required.
+# 2. Altered source versions must be plainly marked as such, and must not be
+# misrepresented as being the original software.
+# 3. This notice may not be removed or altered from any source distribution.
+
+# WHAT IS THIS?
+# When you add a public API to SDL, please run this script, make sure the
+# output looks sane (hg diff, it adds to existing files), and commit it.
+# It keeps the dynamic API jump table operating correctly.
+
+# If you wanted this to be readable, you shouldn't have used perl.
+
+use warnings;
+use strict;
+use File::Basename;
+
+chdir(dirname(__FILE__) . '/../..');
+my $sdl_dynapi_procs_h = "src/dynapi/SDL_dynapi_procs.h";
+my $sdl_dynapi_overrides_h = "src/dynapi/SDL_dynapi_overrides.h";
+
+my %existing = ();
+if (-f $sdl_dynapi_procs_h) {
+ open(SDL_DYNAPI_PROCS_H, '<', $sdl_dynapi_procs_h) or die("Can't open $sdl_dynapi_procs_h: $!\n");
+ while (<SDL_DYNAPI_PROCS_H>) {
+ if (/\ASDL_DYNAPI_PROC\(.*?,(.*?),/) {
+ $existing{$1} = 1;
+ }
+ }
+ close(SDL_DYNAPI_PROCS_H)
+}
+
+open(SDL_DYNAPI_PROCS_H, '>>', $sdl_dynapi_procs_h) or die("Can't open $sdl_dynapi_procs_h: $!\n");
+open(SDL_DYNAPI_OVERRIDES_H, '>>', $sdl_dynapi_overrides_h) or die("Can't open $sdl_dynapi_overrides_h: $!\n");
+
+opendir(HEADERS, 'include') or die("Can't open include dir: $!\n");
+while (readdir(HEADERS)) {
+ next if not /\.h\Z/;
+ my $header = "include/$_";
+ open(HEADER, '<', $header) or die("Can't open $header: $!\n");
+ while (<HEADER>) {
+ chomp;
+ next if not /\A\s*extern\s+DECLSPEC/;
+ my $decl = "$_ ";
+ if (not $decl =~ /\)\s*;/) {
+ while (<HEADER>) {
+ chomp;
+ s/\A\s+//;
+ s/\s+\Z//;
+ $decl .= "$_ ";
+ last if /\)\s*;/;
+ }
+ }
+
+ $decl =~ s/\s+\Z//;
+ #print("DECL: [$decl]\n");
+
+ if ($decl =~ /\A\s*extern\s+DECLSPEC\s+(const\s+|)(unsigned\s+|)(.*?)\s*(\*?)\s*SDLCALL\s+(.*?)\s*\((.*?)\);/) {
+ my $rc = "$1$2$3$4";
+ my $fn = $5;
+
+ next if $existing{$fn}; # already slotted into the jump table.
+
+ my @params = split(',', $6);
+
+ #print("rc == '$rc', fn == '$fn', params == '$params'\n");
+
+ my $retstr = ($rc eq 'void') ? '' : 'return';
+ my $paramstr = '(';
+ my $argstr = '(';
+ my $i = 0;
+ foreach (@params) {
+ my $str = $_;
+ $str =~ s/\A\s+//;
+ $str =~ s/\s+\Z//;
+ #print("1PARAM: $str\n");
+ if ($str eq 'void') {
+ $paramstr .= 'void';
+ } elsif ($str eq '...') {
+ if ($i > 0) {
+ $paramstr .= ', ';
+ }
+ $paramstr .= $str;
+ } elsif ($str =~ /\A\s*((const\s+|)(unsigned\s+|)([a-zA-Z0-9_]*)\s*([\*\s]*))\s*(.*?)\Z/) {
+ #print("PARSED: [$1], [$2], [$3], [$4], [$5]\n");
+ my $type = $1;
+ my $var = $6;
+ $type =~ s/\A\s+//;
+ $type =~ s/\s+\Z//;
+ $var =~ s/\A\s+//;
+ $var =~ s/\s+\Z//;
+ $type =~ s/\s*\*\Z/*/g;
+ $type =~ s/\s*(\*+)\Z/ $1/;
+ #print("SPLIT: ($type, $var)\n");
+ my $name = chr(ord('a') + $i);
+ if ($i > 0) {
+ $paramstr .= ', ';
+ $argstr .= ',';
+ }
+ my $spc = ($type =~ /\*\Z/) ? '' : ' ';
+ $paramstr .= "$type$spc$name";
+ $argstr .= "$name";
+ }
+ $i++;
+ }
+
+ $paramstr = '(void' if ($i == 0); # Just to make this consistent.
+
+ $paramstr .= ')';
+ $argstr .= ')';
+
+ print("NEW: $decl\n");
+ print SDL_DYNAPI_PROCS_H "SDL_DYNAPI_PROC($rc,$fn,$paramstr,$argstr,$retstr)\n";
+ print SDL_DYNAPI_OVERRIDES_H "#define $fn ${fn}_REAL\n";
+ } else {
+ print("Failed to parse decl [$decl]!\n");
+ }
+ }
+ close(HEADER);
+}
+closedir(HEADERS);
+
+close(SDL_DYNAPI_PROCS_H);
+close(SDL_DYNAPI_OVERRIDES_H);
+
+# vi: set ts=4 sw=4 expandtab:
diff --git a/src/3rdparty/SDL2/src/events/SDL_clipboardevents.c b/src/3rdparty/SDL2/src/events/SDL_clipboardevents.c
new file mode 100644
index 0000000..5c45853
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/SDL_clipboardevents.c
@@ -0,0 +1,46 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* Clipboard event handling code for SDL */
+
+#include "SDL_events.h"
+#include "SDL_events_c.h"
+#include "SDL_clipboardevents_c.h"
+
+
+int
+SDL_SendClipboardUpdate(void)
+{
+ int posted;
+
+ /* Post the event, if desired */
+ posted = 0;
+ if (SDL_GetEventState(SDL_CLIPBOARDUPDATE) == SDL_ENABLE) {
+ SDL_Event event;
+ event.type = SDL_CLIPBOARDUPDATE;
+
+ posted = (SDL_PushEvent(&event) > 0);
+ }
+ return (posted);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/SDL_clipboardevents_c.h b/src/3rdparty/SDL2/src/events/SDL_clipboardevents_c.h
new file mode 100644
index 0000000..24c450b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/SDL_clipboardevents_c.h
@@ -0,0 +1,30 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#ifndef SDL_clipboardevents_c_h_
+#define SDL_clipboardevents_c_h_
+
+extern int SDL_SendClipboardUpdate(void);
+
+#endif /* SDL_clipboardevents_c_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/SDL_dropevents.c b/src/3rdparty/SDL2/src/events/SDL_dropevents.c
new file mode 100644
index 0000000..39c5120
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/SDL_dropevents.c
@@ -0,0 +1,98 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* Drag and drop event handling code for SDL */
+
+#include "SDL_events.h"
+#include "SDL_events_c.h"
+#include "SDL_dropevents_c.h"
+
+#include "../video/SDL_sysvideo.h" /* for SDL_Window internals. */
+
+
+static int
+SDL_SendDrop(SDL_Window *window, const SDL_EventType evtype, const char *data)
+{
+ static SDL_bool app_is_dropping = SDL_FALSE;
+ int posted = 0;
+
+ /* Post the event, if desired */
+ if (SDL_GetEventState(evtype) == SDL_ENABLE) {
+ const SDL_bool need_begin = window ? !window->is_dropping : !app_is_dropping;
+ SDL_Event event;
+
+ if (need_begin) {
+ SDL_zero(event);
+ event.type = SDL_DROPBEGIN;
+
+ if (window) {
+ event.drop.windowID = window->id;
+ }
+
+ posted = (SDL_PushEvent(&event) > 0);
+ if (!posted) {
+ return 0;
+ }
+ if (window) {
+ window->is_dropping = SDL_TRUE;
+ } else {
+ app_is_dropping = SDL_TRUE;
+ }
+ }
+
+ SDL_zero(event);
+ event.type = evtype;
+ event.drop.file = data ? SDL_strdup(data) : NULL;
+ event.drop.windowID = window ? window->id : 0;
+ posted = (SDL_PushEvent(&event) > 0);
+
+ if (posted && (evtype == SDL_DROPCOMPLETE)) {
+ if (window) {
+ window->is_dropping = SDL_FALSE;
+ } else {
+ app_is_dropping = SDL_FALSE;
+ }
+ }
+ }
+ return posted;
+}
+
+int
+SDL_SendDropFile(SDL_Window *window, const char *file)
+{
+ return SDL_SendDrop(window, SDL_DROPFILE, file);
+}
+
+int
+SDL_SendDropText(SDL_Window *window, const char *text)
+{
+ return SDL_SendDrop(window, SDL_DROPTEXT, text);
+}
+
+int
+SDL_SendDropComplete(SDL_Window *window)
+{
+ return SDL_SendDrop(window, SDL_DROPCOMPLETE, NULL);
+}
+
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/SDL_dropevents_c.h b/src/3rdparty/SDL2/src/events/SDL_dropevents_c.h
new file mode 100644
index 0000000..79f37cc
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/SDL_dropevents_c.h
@@ -0,0 +1,32 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#ifndef SDL_dropevents_c_h_
+#define SDL_dropevents_c_h_
+
+extern int SDL_SendDropFile(SDL_Window *window, const char *file);
+extern int SDL_SendDropText(SDL_Window *window, const char *text);
+extern int SDL_SendDropComplete(SDL_Window *window);
+
+#endif /* SDL_dropevents_c_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/SDL_events.c b/src/3rdparty/SDL2/src/events/SDL_events.c
new file mode 100644
index 0000000..f2e5b62
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/SDL_events.c
@@ -0,0 +1,955 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* General event handling code for SDL */
+
+#include "SDL.h"
+#include "SDL_events.h"
+#include "SDL_thread.h"
+#include "SDL_events_c.h"
+#include "../timer/SDL_timer_c.h"
+#if !SDL_JOYSTICK_DISABLED
+#include "../joystick/SDL_joystick_c.h"
+#endif
+#include "../video/SDL_sysvideo.h"
+#include "SDL_syswm.h"
+
+/*#define SDL_DEBUG_EVENTS 1*/
+
+/* An arbitrary limit so we don't have unbounded growth */
+#define SDL_MAX_QUEUED_EVENTS 65535
+
+typedef struct SDL_EventWatcher {
+ SDL_EventFilter callback;
+ void *userdata;
+ SDL_bool removed;
+} SDL_EventWatcher;
+
+static SDL_mutex *SDL_event_watchers_lock;
+static SDL_EventWatcher SDL_EventOK;
+static SDL_EventWatcher *SDL_event_watchers = NULL;
+static int SDL_event_watchers_count = 0;
+static SDL_bool SDL_event_watchers_dispatching = SDL_FALSE;
+static SDL_bool SDL_event_watchers_removed = SDL_FALSE;
+
+typedef struct {
+ Uint32 bits[8];
+} SDL_DisabledEventBlock;
+
+static SDL_DisabledEventBlock *SDL_disabled_events[256];
+static Uint32 SDL_userevents = SDL_USEREVENT;
+
+/* Private data -- event queue */
+typedef struct _SDL_EventEntry
+{
+ SDL_Event event;
+ SDL_SysWMmsg msg;
+ struct _SDL_EventEntry *prev;
+ struct _SDL_EventEntry *next;
+} SDL_EventEntry;
+
+typedef struct _SDL_SysWMEntry
+{
+ SDL_SysWMmsg msg;
+ struct _SDL_SysWMEntry *next;
+} SDL_SysWMEntry;
+
+static struct
+{
+ SDL_mutex *lock;
+ SDL_atomic_t active;
+ SDL_atomic_t count;
+ int max_events_seen;
+ SDL_EventEntry *head;
+ SDL_EventEntry *tail;
+ SDL_EventEntry *free;
+ SDL_SysWMEntry *wmmsg_used;
+ SDL_SysWMEntry *wmmsg_free;
+} SDL_EventQ = { NULL, { 1 }, { 0 }, 0, NULL, NULL, NULL, NULL, NULL };
+
+
+#ifdef SDL_DEBUG_EVENTS
+
+/* this is to make printf() calls cleaner. */
+#define uint unsigned int
+
+static void
+SDL_DebugPrintEvent(const SDL_Event *event)
+{
+ /* !!! FIXME: This code is kinda ugly, sorry. */
+ printf("SDL EVENT: ");
+
+ if ((event->type >= SDL_USEREVENT) && (event->type <= SDL_LASTEVENT)) {
+ printf("SDL_USEREVENT");
+ if (event->type > SDL_USEREVENT) {
+ printf("+%u", ((uint) event->type) - SDL_USEREVENT);
+ }
+ printf(" (timestamp=%u windowid=%u code=%d data1=%p data2=%p)",
+ (uint) event->user.timestamp, (uint) event->user.windowID,
+ (int) event->user.code, event->user.data1, event->user.data2);
+ return;
+ }
+
+ switch (event->type) {
+ #define SDL_EVENT_CASE(x) case x: printf("%s", #x);
+ SDL_EVENT_CASE(SDL_FIRSTEVENT) printf("(THIS IS PROBABLY A BUG!)"); break;
+ SDL_EVENT_CASE(SDL_QUIT) printf("(timestamp=%u)", (uint) event->quit.timestamp); break;
+ SDL_EVENT_CASE(SDL_APP_TERMINATING) break;
+ SDL_EVENT_CASE(SDL_APP_LOWMEMORY) break;
+ SDL_EVENT_CASE(SDL_APP_WILLENTERBACKGROUND) break;
+ SDL_EVENT_CASE(SDL_APP_DIDENTERBACKGROUND) break;
+ SDL_EVENT_CASE(SDL_APP_WILLENTERFOREGROUND) break;
+ SDL_EVENT_CASE(SDL_APP_DIDENTERFOREGROUND) break;
+ SDL_EVENT_CASE(SDL_KEYMAPCHANGED) break;
+ SDL_EVENT_CASE(SDL_CLIPBOARDUPDATE) break;
+ SDL_EVENT_CASE(SDL_RENDER_TARGETS_RESET) break;
+ SDL_EVENT_CASE(SDL_RENDER_DEVICE_RESET) break;
+ #undef SDL_EVENT_CASE
+
+ #define SDL_EVENT_CASE(x) case x: printf("%s ", #x);
+
+ SDL_EVENT_CASE(SDL_WINDOWEVENT)
+ printf("(timestamp=%u windowid=%u event=", (uint) event->window.timestamp, (uint) event->window.windowID);
+ switch(event->window.event) {
+ case SDL_WINDOWEVENT_NONE: printf("none(THIS IS PROBABLY A BUG!)"); break;
+ #define SDL_WINDOWEVENT_CASE(x) case x: printf("%s", #x); break
+ SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_SHOWN);
+ SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_HIDDEN);
+ SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_EXPOSED);
+ SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_MOVED);
+ SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_RESIZED);
+ SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_SIZE_CHANGED);
+ SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_MINIMIZED);
+ SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_MAXIMIZED);
+ SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_RESTORED);
+ SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_ENTER);
+ SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_LEAVE);
+ SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_FOCUS_GAINED);
+ SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_FOCUS_LOST);
+ SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_CLOSE);
+ SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_TAKE_FOCUS);
+ SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_HIT_TEST);
+ #undef SDL_WINDOWEVENT_CASE
+ default: printf("UNKNOWN(bug? fixme?)"); break;
+ }
+ printf(" data1=%d data2=%d)", (int) event->window.data1, (int) event->window.data2);
+ break;
+
+ SDL_EVENT_CASE(SDL_SYSWMEVENT)
+ printf("(timestamp=%u)", (uint) event->syswm.timestamp);
+ /* !!! FIXME: we don't delve further at the moment. */
+ break;
+
+ #define PRINT_KEY_EVENT(event) \
+ printf("(timestamp=%u windowid=%u state=%s repeat=%s scancode=%u keycode=%u mod=%u)", \
+ (uint) event->key.timestamp, (uint) event->key.windowID, \
+ event->key.state == SDL_PRESSED ? "pressed" : "released", \
+ event->key.repeat ? "true" : "false", \
+ (uint) event->key.keysym.scancode, \
+ (uint) event->key.keysym.sym, \
+ (uint) event->key.keysym.mod)
+ SDL_EVENT_CASE(SDL_KEYDOWN) PRINT_KEY_EVENT(event); break;
+ SDL_EVENT_CASE(SDL_KEYUP) PRINT_KEY_EVENT(event); break;
+ #undef PRINT_KEY_EVENT
+
+ SDL_EVENT_CASE(SDL_TEXTEDITING)
+ printf("(timestamp=%u windowid=%u text='%s' start=%d length=%d)",
+ (uint) event->edit.timestamp, (uint) event->edit.windowID,
+ event->edit.text, (int) event->edit.start, (int) event->edit.length);
+ break;
+
+ SDL_EVENT_CASE(SDL_TEXTINPUT)
+ printf("(timestamp=%u windowid=%u text='%s')", (uint) event->text.timestamp, (uint) event->text.windowID, event->text.text);
+ break;
+
+
+ SDL_EVENT_CASE(SDL_MOUSEMOTION)
+ printf("(timestamp=%u windowid=%u which=%u state=%u x=%d y=%d xrel=%d yrel=%d)",
+ (uint) event->motion.timestamp, (uint) event->motion.windowID,
+ (uint) event->motion.which, (uint) event->motion.state,
+ (int) event->motion.x, (int) event->motion.y,
+ (int) event->motion.xrel, (int) event->motion.yrel);
+ break;
+
+ #define PRINT_MBUTTON_EVENT(event) \
+ printf("(timestamp=%u windowid=%u which=%u button=%u state=%s clicks=%u x=%d y=%d)", \
+ (uint) event->button.timestamp, (uint) event->button.windowID, \
+ (uint) event->button.which, (uint) event->button.button, \
+ event->button.state == SDL_PRESSED ? "pressed" : "released", \
+ (uint) event->button.clicks, (int) event->button.x, (int) event->button.y)
+ SDL_EVENT_CASE(SDL_MOUSEBUTTONDOWN) PRINT_MBUTTON_EVENT(event); break;
+ SDL_EVENT_CASE(SDL_MOUSEBUTTONUP) PRINT_MBUTTON_EVENT(event); break;
+ #undef PRINT_MBUTTON_EVENT
+
+
+ SDL_EVENT_CASE(SDL_MOUSEWHEEL)
+ printf("(timestamp=%u windowid=%u which=%u x=%d y=%d direction=%s)",
+ (uint) event->wheel.timestamp, (uint) event->wheel.windowID,
+ (uint) event->wheel.which, (int) event->wheel.x, (int) event->wheel.y,
+ event->wheel.direction == SDL_MOUSEWHEEL_NORMAL ? "normal" : "flipped");
+ break;
+
+ SDL_EVENT_CASE(SDL_JOYAXISMOTION)
+ printf("(timestamp=%u which=%d axis=%u value=%d)",
+ (uint) event->jaxis.timestamp, (int) event->jaxis.which,
+ (uint) event->jaxis.axis, (int) event->jaxis.value);
+ break;
+
+ SDL_EVENT_CASE(SDL_JOYBALLMOTION)
+ printf("(timestamp=%u which=%d ball=%u xrel=%d yrel=%d)",
+ (uint) event->jball.timestamp, (int) event->jball.which,
+ (uint) event->jball.ball, (int) event->jball.xrel, (int) event->jball.yrel);
+ break;
+
+ SDL_EVENT_CASE(SDL_JOYHATMOTION)
+ printf("(timestamp=%u which=%d hat=%u value=%u)",
+ (uint) event->jhat.timestamp, (int) event->jhat.which,
+ (uint) event->jhat.hat, (uint) event->jhat.value);
+ break;
+
+ #define PRINT_JBUTTON_EVENT(event) \
+ printf("(timestamp=%u which=%d button=%u state=%s)", \
+ (uint) event->jbutton.timestamp, (int) event->jbutton.which, \
+ (uint) event->jbutton.button, event->jbutton.state == SDL_PRESSED ? "pressed" : "released")
+ SDL_EVENT_CASE(SDL_JOYBUTTONDOWN) PRINT_JBUTTON_EVENT(event); break;
+ SDL_EVENT_CASE(SDL_JOYBUTTONUP) PRINT_JBUTTON_EVENT(event); break;
+ #undef PRINT_JBUTTON_EVENT
+
+ #define PRINT_JOYDEV_EVENT(event) printf("(timestamp=%u which=%d)", (uint) event->jdevice.timestamp, (int) event->jdevice.which)
+ SDL_EVENT_CASE(SDL_JOYDEVICEADDED) PRINT_JOYDEV_EVENT(event); break;
+ SDL_EVENT_CASE(SDL_JOYDEVICEREMOVED) PRINT_JOYDEV_EVENT(event); break;
+ #undef PRINT_JOYDEV_EVENT
+
+ SDL_EVENT_CASE(SDL_CONTROLLERAXISMOTION)
+ printf("(timestamp=%u which=%d axis=%u value=%d)",
+ (uint) event->caxis.timestamp, (int) event->caxis.which,
+ (uint) event->caxis.axis, (int) event->caxis.value);
+ break;
+
+ #define PRINT_CBUTTON_EVENT(event) \
+ printf("(timestamp=%u which=%d button=%u state=%s)", \
+ (uint) event->cbutton.timestamp, (int) event->cbutton.which, \
+ (uint) event->cbutton.button, event->cbutton.state == SDL_PRESSED ? "pressed" : "released")
+ SDL_EVENT_CASE(SDL_CONTROLLERBUTTONDOWN) PRINT_CBUTTON_EVENT(event); break;
+ SDL_EVENT_CASE(SDL_CONTROLLERBUTTONUP) PRINT_CBUTTON_EVENT(event); break;
+ #undef PRINT_CBUTTON_EVENT
+
+ #define PRINT_CONTROLLERDEV_EVENT(event) printf("(timestamp=%u which=%d)", (uint) event->cdevice.timestamp, (int) event->cdevice.which)
+ SDL_EVENT_CASE(SDL_CONTROLLERDEVICEADDED) PRINT_CONTROLLERDEV_EVENT(event); break;
+ SDL_EVENT_CASE(SDL_CONTROLLERDEVICEREMOVED) PRINT_CONTROLLERDEV_EVENT(event); break;
+ SDL_EVENT_CASE(SDL_CONTROLLERDEVICEREMAPPED) PRINT_CONTROLLERDEV_EVENT(event); break;
+ #undef PRINT_CONTROLLERDEV_EVENT
+
+ #define PRINT_FINGER_EVENT(event) \
+ printf("(timestamp=%u touchid=%lld fingerid=%lld x=%f y=%f dx=%f dy=%f pressure=%f)", \
+ (uint) event->tfinger.timestamp, (long long) event->tfinger.touchId, \
+ (long long) event->tfinger.fingerId, event->tfinger.x, event->tfinger.y, \
+ event->tfinger.dx, event->tfinger.dy, event->tfinger.pressure)
+ SDL_EVENT_CASE(SDL_FINGERDOWN) PRINT_FINGER_EVENT(event); break;
+ SDL_EVENT_CASE(SDL_FINGERUP) PRINT_FINGER_EVENT(event); break;
+ SDL_EVENT_CASE(SDL_FINGERMOTION) PRINT_FINGER_EVENT(event); break;
+ #undef PRINT_FINGER_EVENT
+
+ #define PRINT_DOLLAR_EVENT(event) \
+ printf("(timestamp=%u touchid=%lld gestureid=%lld numfingers=%u error=%f x=%f y=%f)", \
+ (uint) event->dgesture.timestamp, (long long) event->dgesture.touchId, \
+ (long long) event->dgesture.gestureId, (uint) event->dgesture.numFingers, \
+ event->dgesture.error, event->dgesture.x, event->dgesture.y);
+ SDL_EVENT_CASE(SDL_DOLLARGESTURE) PRINT_DOLLAR_EVENT(event); break;
+ SDL_EVENT_CASE(SDL_DOLLARRECORD) PRINT_DOLLAR_EVENT(event); break;
+ #undef PRINT_DOLLAR_EVENT
+
+ SDL_EVENT_CASE(SDL_MULTIGESTURE)
+ printf("(timestamp=%u touchid=%lld dtheta=%f ddist=%f x=%f y=%f numfingers=%u)",
+ (uint) event->mgesture.timestamp, (long long) event->mgesture.touchId,
+ event->mgesture.dTheta, event->mgesture.dDist,
+ event->mgesture.x, event->mgesture.y, (uint) event->mgesture.numFingers);
+ break;
+
+ #define PRINT_DROP_EVENT(event) printf("(file='%s' timestamp=%u windowid=%u)", event->drop.file, (uint) event->drop.timestamp, (uint) event->drop.windowID)
+ SDL_EVENT_CASE(SDL_DROPFILE) PRINT_DROP_EVENT(event); break;
+ SDL_EVENT_CASE(SDL_DROPTEXT) PRINT_DROP_EVENT(event); break;
+ SDL_EVENT_CASE(SDL_DROPBEGIN) PRINT_DROP_EVENT(event); break;
+ SDL_EVENT_CASE(SDL_DROPCOMPLETE) PRINT_DROP_EVENT(event); break;
+ #undef PRINT_DROP_EVENT
+
+ #define PRINT_AUDIODEV_EVENT(event) printf("(timestamp=%u which=%u iscapture=%s)", (uint) event->adevice.timestamp, (uint) event->adevice.which, event->adevice.iscapture ? "true" : "false");
+ SDL_EVENT_CASE(SDL_AUDIODEVICEADDED) PRINT_AUDIODEV_EVENT(event); break;
+ SDL_EVENT_CASE(SDL_AUDIODEVICEREMOVED) PRINT_AUDIODEV_EVENT(event); break;
+ #undef PRINT_AUDIODEV_EVENT
+
+ #undef SDL_EVENT_CASE
+
+ default:
+ printf("UNKNOWN SDL EVENT #%u! (Bug? FIXME?)", (uint) event->type);
+ break;
+ }
+
+ printf("\n");
+}
+#undef uint
+#endif
+
+
+
+/* Public functions */
+
+void
+SDL_StopEventLoop(void)
+{
+ const char *report = SDL_GetHint("SDL_EVENT_QUEUE_STATISTICS");
+ int i;
+ SDL_EventEntry *entry;
+ SDL_SysWMEntry *wmmsg;
+
+ if (SDL_EventQ.lock) {
+ SDL_LockMutex(SDL_EventQ.lock);
+ }
+
+ SDL_AtomicSet(&SDL_EventQ.active, 0);
+
+ if (report && SDL_atoi(report)) {
+ SDL_Log("SDL EVENT QUEUE: Maximum events in-flight: %d\n",
+ SDL_EventQ.max_events_seen);
+ }
+
+ /* Clean out EventQ */
+ for (entry = SDL_EventQ.head; entry; ) {
+ SDL_EventEntry *next = entry->next;
+ SDL_free(entry);
+ entry = next;
+ }
+ for (entry = SDL_EventQ.free; entry; ) {
+ SDL_EventEntry *next = entry->next;
+ SDL_free(entry);
+ entry = next;
+ }
+ for (wmmsg = SDL_EventQ.wmmsg_used; wmmsg; ) {
+ SDL_SysWMEntry *next = wmmsg->next;
+ SDL_free(wmmsg);
+ wmmsg = next;
+ }
+ for (wmmsg = SDL_EventQ.wmmsg_free; wmmsg; ) {
+ SDL_SysWMEntry *next = wmmsg->next;
+ SDL_free(wmmsg);
+ wmmsg = next;
+ }
+
+ SDL_AtomicSet(&SDL_EventQ.count, 0);
+ SDL_EventQ.max_events_seen = 0;
+ SDL_EventQ.head = NULL;
+ SDL_EventQ.tail = NULL;
+ SDL_EventQ.free = NULL;
+ SDL_EventQ.wmmsg_used = NULL;
+ SDL_EventQ.wmmsg_free = NULL;
+
+ /* Clear disabled event state */
+ for (i = 0; i < SDL_arraysize(SDL_disabled_events); ++i) {
+ SDL_free(SDL_disabled_events[i]);
+ SDL_disabled_events[i] = NULL;
+ }
+
+ if (SDL_event_watchers_lock) {
+ SDL_DestroyMutex(SDL_event_watchers_lock);
+ SDL_event_watchers_lock = NULL;
+ }
+ if (SDL_event_watchers) {
+ SDL_free(SDL_event_watchers);
+ SDL_event_watchers = NULL;
+ SDL_event_watchers_count = 0;
+ }
+ SDL_zero(SDL_EventOK);
+
+ if (SDL_EventQ.lock) {
+ SDL_UnlockMutex(SDL_EventQ.lock);
+ SDL_DestroyMutex(SDL_EventQ.lock);
+ SDL_EventQ.lock = NULL;
+ }
+}
+
+/* This function (and associated calls) may be called more than once */
+int
+SDL_StartEventLoop(void)
+{
+ /* We'll leave the event queue alone, since we might have gotten
+ some important events at launch (like SDL_DROPFILE)
+
+ FIXME: Does this introduce any other bugs with events at startup?
+ */
+
+ /* Create the lock and set ourselves active */
+#if !SDL_THREADS_DISABLED
+ if (!SDL_EventQ.lock) {
+ SDL_EventQ.lock = SDL_CreateMutex();
+ if (SDL_EventQ.lock == NULL) {
+ return -1;
+ }
+ }
+
+ if (!SDL_event_watchers_lock) {
+ SDL_event_watchers_lock = SDL_CreateMutex();
+ if (SDL_event_watchers_lock == NULL) {
+ return -1;
+ }
+ }
+#endif /* !SDL_THREADS_DISABLED */
+
+ /* Process most event types */
+ SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);
+ SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE);
+ SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE);
+
+ SDL_AtomicSet(&SDL_EventQ.active, 1);
+
+ return 0;
+}
+
+
+/* Add an event to the event queue -- called with the queue locked */
+static int
+SDL_AddEvent(SDL_Event * event)
+{
+ SDL_EventEntry *entry;
+ const int initial_count = SDL_AtomicGet(&SDL_EventQ.count);
+ int final_count;
+
+ if (initial_count >= SDL_MAX_QUEUED_EVENTS) {
+ SDL_SetError("Event queue is full (%d events)", initial_count);
+ return 0;
+ }
+
+ if (SDL_EventQ.free == NULL) {
+ entry = (SDL_EventEntry *)SDL_malloc(sizeof(*entry));
+ if (!entry) {
+ return 0;
+ }
+ } else {
+ entry = SDL_EventQ.free;
+ SDL_EventQ.free = entry->next;
+ }
+
+ #ifdef SDL_DEBUG_EVENTS
+ SDL_DebugPrintEvent(event);
+ #endif
+
+ entry->event = *event;
+ if (event->type == SDL_SYSWMEVENT) {
+ entry->msg = *event->syswm.msg;
+ entry->event.syswm.msg = &entry->msg;
+ }
+
+ if (SDL_EventQ.tail) {
+ SDL_EventQ.tail->next = entry;
+ entry->prev = SDL_EventQ.tail;
+ SDL_EventQ.tail = entry;
+ entry->next = NULL;
+ } else {
+ SDL_assert(!SDL_EventQ.head);
+ SDL_EventQ.head = entry;
+ SDL_EventQ.tail = entry;
+ entry->prev = NULL;
+ entry->next = NULL;
+ }
+
+ final_count = SDL_AtomicAdd(&SDL_EventQ.count, 1) + 1;
+ if (final_count > SDL_EventQ.max_events_seen) {
+ SDL_EventQ.max_events_seen = final_count;
+ }
+
+ return 1;
+}
+
+/* Remove an event from the queue -- called with the queue locked */
+static void
+SDL_CutEvent(SDL_EventEntry *entry)
+{
+ if (entry->prev) {
+ entry->prev->next = entry->next;
+ }
+ if (entry->next) {
+ entry->next->prev = entry->prev;
+ }
+
+ if (entry == SDL_EventQ.head) {
+ SDL_assert(entry->prev == NULL);
+ SDL_EventQ.head = entry->next;
+ }
+ if (entry == SDL_EventQ.tail) {
+ SDL_assert(entry->next == NULL);
+ SDL_EventQ.tail = entry->prev;
+ }
+
+ entry->next = SDL_EventQ.free;
+ SDL_EventQ.free = entry;
+ SDL_assert(SDL_AtomicGet(&SDL_EventQ.count) > 0);
+ SDL_AtomicAdd(&SDL_EventQ.count, -1);
+}
+
+/* Lock the event queue, take a peep at it, and unlock it */
+int
+SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
+ Uint32 minType, Uint32 maxType)
+{
+ int i, used;
+
+ /* Don't look after we've quit */
+ if (!SDL_AtomicGet(&SDL_EventQ.active)) {
+ /* We get a few spurious events at shutdown, so don't warn then */
+ if (action != SDL_ADDEVENT) {
+ SDL_SetError("The event system has been shut down");
+ }
+ return (-1);
+ }
+ /* Lock the event queue */
+ used = 0;
+ if (!SDL_EventQ.lock || SDL_LockMutex(SDL_EventQ.lock) == 0) {
+ if (action == SDL_ADDEVENT) {
+ for (i = 0; i < numevents; ++i) {
+ used += SDL_AddEvent(&events[i]);
+ }
+ } else {
+ SDL_EventEntry *entry, *next;
+ SDL_SysWMEntry *wmmsg, *wmmsg_next;
+ Uint32 type;
+
+ if (action == SDL_GETEVENT) {
+ /* Clean out any used wmmsg data
+ FIXME: Do we want to retain the data for some period of time?
+ */
+ for (wmmsg = SDL_EventQ.wmmsg_used; wmmsg; wmmsg = wmmsg_next) {
+ wmmsg_next = wmmsg->next;
+ wmmsg->next = SDL_EventQ.wmmsg_free;
+ SDL_EventQ.wmmsg_free = wmmsg;
+ }
+ SDL_EventQ.wmmsg_used = NULL;
+ }
+
+ for (entry = SDL_EventQ.head; entry && (!events || used < numevents); entry = next) {
+ next = entry->next;
+ type = entry->event.type;
+ if (minType <= type && type <= maxType) {
+ if (events) {
+ events[used] = entry->event;
+ if (entry->event.type == SDL_SYSWMEVENT) {
+ /* We need to copy the wmmsg somewhere safe.
+ For now we'll guarantee it's valid at least until
+ the next call to SDL_PeepEvents()
+ */
+ if (SDL_EventQ.wmmsg_free) {
+ wmmsg = SDL_EventQ.wmmsg_free;
+ SDL_EventQ.wmmsg_free = wmmsg->next;
+ } else {
+ wmmsg = (SDL_SysWMEntry *)SDL_malloc(sizeof(*wmmsg));
+ }
+ wmmsg->msg = *entry->event.syswm.msg;
+ wmmsg->next = SDL_EventQ.wmmsg_used;
+ SDL_EventQ.wmmsg_used = wmmsg;
+ events[used].syswm.msg = &wmmsg->msg;
+ }
+
+ if (action == SDL_GETEVENT) {
+ SDL_CutEvent(entry);
+ }
+ }
+ ++used;
+ }
+ }
+ }
+ if (SDL_EventQ.lock) {
+ SDL_UnlockMutex(SDL_EventQ.lock);
+ }
+ } else {
+ return SDL_SetError("Couldn't lock event queue");
+ }
+ return (used);
+}
+
+SDL_bool
+SDL_HasEvent(Uint32 type)
+{
+ return (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, type, type) > 0);
+}
+
+SDL_bool
+SDL_HasEvents(Uint32 minType, Uint32 maxType)
+{
+ return (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, minType, maxType) > 0);
+}
+
+void
+SDL_FlushEvent(Uint32 type)
+{
+ SDL_FlushEvents(type, type);
+}
+
+void
+SDL_FlushEvents(Uint32 minType, Uint32 maxType)
+{
+ /* Don't look after we've quit */
+ if (!SDL_AtomicGet(&SDL_EventQ.active)) {
+ return;
+ }
+
+ /* Make sure the events are current */
+#if 0
+ /* Actually, we can't do this since we might be flushing while processing
+ a resize event, and calling this might trigger further resize events.
+ */
+ SDL_PumpEvents();
+#endif
+
+ /* Lock the event queue */
+ if (!SDL_EventQ.lock || SDL_LockMutex(SDL_EventQ.lock) == 0) {
+ SDL_EventEntry *entry, *next;
+ Uint32 type;
+ for (entry = SDL_EventQ.head; entry; entry = next) {
+ next = entry->next;
+ type = entry->event.type;
+ if (minType <= type && type <= maxType) {
+ SDL_CutEvent(entry);
+ }
+ }
+ if (SDL_EventQ.lock) {
+ SDL_UnlockMutex(SDL_EventQ.lock);
+ }
+ }
+}
+
+/* Run the system dependent event loops */
+void
+SDL_PumpEvents(void)
+{
+ SDL_VideoDevice *_this = SDL_GetVideoDevice();
+
+ /* Get events from the video subsystem */
+ if (_this) {
+ _this->PumpEvents(_this);
+ }
+#if !SDL_JOYSTICK_DISABLED
+ /* Check for joystick state change */
+ if ((!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventState(SDL_QUERY))) {
+ SDL_JoystickUpdate();
+ }
+#endif
+
+ SDL_SendPendingQuit(); /* in case we had a signal handler fire, etc. */
+}
+
+/* Public functions */
+
+int
+SDL_PollEvent(SDL_Event * event)
+{
+ return SDL_WaitEventTimeout(event, 0);
+}
+
+int
+SDL_WaitEvent(SDL_Event * event)
+{
+ return SDL_WaitEventTimeout(event, -1);
+}
+
+int
+SDL_WaitEventTimeout(SDL_Event * event, int timeout)
+{
+ Uint32 expiration = 0;
+
+ if (timeout > 0)
+ expiration = SDL_GetTicks() + timeout;
+
+ for (;;) {
+ SDL_PumpEvents();
+ switch (SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT)) {
+ case -1:
+ return 0;
+ case 0:
+ if (timeout == 0) {
+ /* Polling and no events, just return */
+ return 0;
+ }
+ if (timeout > 0 && SDL_TICKS_PASSED(SDL_GetTicks(), expiration)) {
+ /* Timeout expired and no events */
+ return 0;
+ }
+ SDL_Delay(10);
+ break;
+ default:
+ /* Has events */
+ return 1;
+ }
+ }
+}
+
+int
+SDL_PushEvent(SDL_Event * event)
+{
+ event->common.timestamp = SDL_GetTicks();
+
+ if (SDL_EventOK.callback || SDL_event_watchers_count > 0) {
+ if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
+ if (SDL_EventOK.callback && !SDL_EventOK.callback(SDL_EventOK.userdata, event)) {
+ if (SDL_event_watchers_lock) {
+ SDL_UnlockMutex(SDL_event_watchers_lock);
+ }
+ return 0;
+ }
+
+ if (SDL_event_watchers_count > 0) {
+ /* Make sure we only dispatch the current watcher list */
+ int i, event_watchers_count = SDL_event_watchers_count;
+
+ SDL_event_watchers_dispatching = SDL_TRUE;
+ for (i = 0; i < event_watchers_count; ++i) {
+ if (!SDL_event_watchers[i].removed) {
+ SDL_event_watchers[i].callback(SDL_event_watchers[i].userdata, event);
+ }
+ }
+ SDL_event_watchers_dispatching = SDL_FALSE;
+
+ if (SDL_event_watchers_removed) {
+ for (i = SDL_event_watchers_count; i--; ) {
+ if (SDL_event_watchers[i].removed) {
+ --SDL_event_watchers_count;
+ if (i < SDL_event_watchers_count) {
+ SDL_memmove(&SDL_event_watchers[i], &SDL_event_watchers[i+1], (SDL_event_watchers_count - i) * sizeof(SDL_event_watchers[i]));
+ }
+ }
+ }
+ SDL_event_watchers_removed = SDL_FALSE;
+ }
+ }
+
+ if (SDL_event_watchers_lock) {
+ SDL_UnlockMutex(SDL_event_watchers_lock);
+ }
+ }
+ }
+
+ if (SDL_PeepEvents(event, 1, SDL_ADDEVENT, 0, 0) <= 0) {
+ return -1;
+ }
+
+ SDL_GestureProcessEvent(event);
+
+ return 1;
+}
+
+void
+SDL_SetEventFilter(SDL_EventFilter filter, void *userdata)
+{
+ if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
+ /* Set filter and discard pending events */
+ SDL_EventOK.callback = filter;
+ SDL_EventOK.userdata = userdata;
+ SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
+
+ if (SDL_event_watchers_lock) {
+ SDL_UnlockMutex(SDL_event_watchers_lock);
+ }
+ }
+}
+
+SDL_bool
+SDL_GetEventFilter(SDL_EventFilter * filter, void **userdata)
+{
+ SDL_EventWatcher event_ok;
+
+ if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
+ event_ok = SDL_EventOK;
+
+ if (SDL_event_watchers_lock) {
+ SDL_UnlockMutex(SDL_event_watchers_lock);
+ }
+ } else {
+ SDL_zero(event_ok);
+ }
+
+ if (filter) {
+ *filter = event_ok.callback;
+ }
+ if (userdata) {
+ *userdata = event_ok.userdata;
+ }
+ return event_ok.callback ? SDL_TRUE : SDL_FALSE;
+}
+
+void
+SDL_AddEventWatch(SDL_EventFilter filter, void *userdata)
+{
+ if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
+ SDL_EventWatcher *event_watchers;
+
+ event_watchers = SDL_realloc(SDL_event_watchers, (SDL_event_watchers_count + 1) * sizeof(*event_watchers));
+ if (event_watchers) {
+ SDL_EventWatcher *watcher;
+
+ SDL_event_watchers = event_watchers;
+ watcher = &SDL_event_watchers[SDL_event_watchers_count];
+ watcher->callback = filter;
+ watcher->userdata = userdata;
+ watcher->removed = SDL_FALSE;
+ ++SDL_event_watchers_count;
+ }
+
+ if (SDL_event_watchers_lock) {
+ SDL_UnlockMutex(SDL_event_watchers_lock);
+ }
+ }
+}
+
+void
+SDL_DelEventWatch(SDL_EventFilter filter, void *userdata)
+{
+ if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
+ int i;
+
+ for (i = 0; i < SDL_event_watchers_count; ++i) {
+ if (SDL_event_watchers[i].callback == filter && SDL_event_watchers[i].userdata == userdata) {
+ if (SDL_event_watchers_dispatching) {
+ SDL_event_watchers[i].removed = SDL_TRUE;
+ SDL_event_watchers_removed = SDL_TRUE;
+ } else {
+ --SDL_event_watchers_count;
+ if (i < SDL_event_watchers_count) {
+ SDL_memmove(&SDL_event_watchers[i], &SDL_event_watchers[i+1], (SDL_event_watchers_count - i) * sizeof(SDL_event_watchers[i]));
+ }
+ }
+ break;
+ }
+ }
+
+ if (SDL_event_watchers_lock) {
+ SDL_UnlockMutex(SDL_event_watchers_lock);
+ }
+ }
+}
+
+void
+SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
+{
+ if (!SDL_EventQ.lock || SDL_LockMutex(SDL_EventQ.lock) == 0) {
+ SDL_EventEntry *entry, *next;
+ for (entry = SDL_EventQ.head; entry; entry = next) {
+ next = entry->next;
+ if (!filter(userdata, &entry->event)) {
+ SDL_CutEvent(entry);
+ }
+ }
+ if (SDL_EventQ.lock) {
+ SDL_UnlockMutex(SDL_EventQ.lock);
+ }
+ }
+}
+
+Uint8
+SDL_EventState(Uint32 type, int state)
+{
+ Uint8 current_state;
+ Uint8 hi = ((type >> 8) & 0xff);
+ Uint8 lo = (type & 0xff);
+
+ if (SDL_disabled_events[hi] &&
+ (SDL_disabled_events[hi]->bits[lo/32] & (1 << (lo&31)))) {
+ current_state = SDL_DISABLE;
+ } else {
+ current_state = SDL_ENABLE;
+ }
+
+ if (state != current_state)
+ {
+ switch (state) {
+ case SDL_DISABLE:
+ /* Disable this event type and discard pending events */
+ if (!SDL_disabled_events[hi]) {
+ SDL_disabled_events[hi] = (SDL_DisabledEventBlock*) SDL_calloc(1, sizeof(SDL_DisabledEventBlock));
+ if (!SDL_disabled_events[hi]) {
+ /* Out of memory, nothing we can do... */
+ break;
+ }
+ }
+ SDL_disabled_events[hi]->bits[lo/32] |= (1 << (lo&31));
+ SDL_FlushEvent(type);
+ break;
+ case SDL_ENABLE:
+ SDL_disabled_events[hi]->bits[lo/32] &= ~(1 << (lo&31));
+ break;
+ default:
+ /* Querying state... */
+ break;
+ }
+ }
+
+ return current_state;
+}
+
+Uint32
+SDL_RegisterEvents(int numevents)
+{
+ Uint32 event_base;
+
+ if ((numevents > 0) && (SDL_userevents+numevents <= SDL_LASTEVENT)) {
+ event_base = SDL_userevents;
+ SDL_userevents += numevents;
+ } else {
+ event_base = (Uint32)-1;
+ }
+ return event_base;
+}
+
+int
+SDL_SendAppEvent(SDL_EventType eventType)
+{
+ int posted;
+
+ posted = 0;
+ if (SDL_GetEventState(eventType) == SDL_ENABLE) {
+ SDL_Event event;
+ event.type = eventType;
+ posted = (SDL_PushEvent(&event) > 0);
+ }
+ return (posted);
+}
+
+int
+SDL_SendSysWMEvent(SDL_SysWMmsg * message)
+{
+ int posted;
+
+ posted = 0;
+ if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
+ SDL_Event event;
+ SDL_memset(&event, 0, sizeof(event));
+ event.type = SDL_SYSWMEVENT;
+ event.syswm.msg = message;
+ posted = (SDL_PushEvent(&event) > 0);
+ }
+ /* Update internal event state */
+ return (posted);
+}
+
+int
+SDL_SendKeymapChangedEvent(void)
+{
+ return SDL_SendAppEvent(SDL_KEYMAPCHANGED);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/SDL_events_c.h b/src/3rdparty/SDL2/src/events/SDL_events_c.h
new file mode 100644
index 0000000..b1bd277
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/SDL_events_c.h
@@ -0,0 +1,49 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* Useful functions and variables from SDL_events.c */
+#include "SDL_events.h"
+#include "SDL_thread.h"
+#include "SDL_clipboardevents_c.h"
+#include "SDL_dropevents_c.h"
+#include "SDL_gesture_c.h"
+#include "SDL_keyboard_c.h"
+#include "SDL_mouse_c.h"
+#include "SDL_touch_c.h"
+#include "SDL_windowevents_c.h"
+
+/* Start and stop the event processing loop */
+extern int SDL_StartEventLoop(void);
+extern void SDL_StopEventLoop(void);
+extern void SDL_QuitInterrupt(void);
+
+extern int SDL_SendAppEvent(SDL_EventType eventType);
+extern int SDL_SendSysWMEvent(SDL_SysWMmsg * message);
+extern int SDL_SendKeymapChangedEvent(void);
+
+extern int SDL_QuitInit(void);
+extern int SDL_SendQuit(void);
+extern void SDL_QuitQuit(void);
+
+extern void SDL_SendPendingQuit(void);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/SDL_gesture.c b/src/3rdparty/SDL2/src/events/SDL_gesture.c
new file mode 100644
index 0000000..c3b73e0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/SDL_gesture.c
@@ -0,0 +1,700 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../SDL_internal.h"
+
+/* General gesture handling code for SDL */
+
+#include "SDL_events.h"
+#include "SDL_endian.h"
+#include "SDL_events_c.h"
+#include "SDL_gesture_c.h"
+
+/*
+#include <stdio.h>
+*/
+
+/* TODO: Replace with malloc */
+
+#define MAXPATHSIZE 1024
+
+#define DOLLARNPOINTS 64
+#define DOLLARSIZE 256
+
+#define ENABLE_DOLLAR
+
+#define PHI 0.618033989
+
+typedef struct {
+ float x,y;
+} SDL_FloatPoint;
+
+typedef struct {
+ float length;
+
+ int numPoints;
+ SDL_FloatPoint p[MAXPATHSIZE];
+} SDL_DollarPath;
+
+typedef struct {
+ SDL_FloatPoint path[DOLLARNPOINTS];
+ unsigned long hash;
+} SDL_DollarTemplate;
+
+typedef struct {
+ SDL_TouchID id;
+ SDL_FloatPoint centroid;
+ SDL_DollarPath dollarPath;
+ Uint16 numDownFingers;
+
+ int numDollarTemplates;
+ SDL_DollarTemplate *dollarTemplate;
+
+ SDL_bool recording;
+} SDL_GestureTouch;
+
+static SDL_GestureTouch *SDL_gestureTouch;
+static int SDL_numGestureTouches = 0;
+static SDL_bool recordAll;
+
+#if 0
+static void PrintPath(SDL_FloatPoint *path)
+{
+ int i;
+ printf("Path:");
+ for (i=0; i<DOLLARNPOINTS; i++) {
+ printf(" (%f,%f)",path[i].x,path[i].y);
+ }
+ printf("\n");
+}
+#endif
+
+int SDL_RecordGesture(SDL_TouchID touchId)
+{
+ int i;
+ if (touchId < 0) recordAll = SDL_TRUE;
+ for (i = 0; i < SDL_numGestureTouches; i++) {
+ if ((touchId < 0) || (SDL_gestureTouch[i].id == touchId)) {
+ SDL_gestureTouch[i].recording = SDL_TRUE;
+ if (touchId >= 0)
+ return 1;
+ }
+ }
+ return (touchId < 0);
+}
+
+void SDL_GestureQuit()
+{
+ SDL_free(SDL_gestureTouch);
+ SDL_gestureTouch = NULL;
+}
+
+static unsigned long SDL_HashDollar(SDL_FloatPoint* points)
+{
+ unsigned long hash = 5381;
+ int i;
+ for (i = 0; i < DOLLARNPOINTS; i++) {
+ hash = ((hash<<5) + hash) + (unsigned long)points[i].x;
+ hash = ((hash<<5) + hash) + (unsigned long)points[i].y;
+ }
+ return hash;
+}
+
+
+static int SaveTemplate(SDL_DollarTemplate *templ, SDL_RWops *dst)
+{
+ if (dst == NULL) {
+ return 0;
+ }
+
+ /* No Longer storing the Hash, rehash on load */
+ /* if (SDL_RWops.write(dst, &(templ->hash), sizeof(templ->hash), 1) != 1) return 0; */
+
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+ if (SDL_RWwrite(dst, templ->path,
+ sizeof(templ->path[0]),DOLLARNPOINTS) != DOLLARNPOINTS) {
+ return 0;
+ }
+#else
+ {
+ SDL_DollarTemplate copy = *templ;
+ SDL_FloatPoint *p = copy.path;
+ int i;
+ for (i = 0; i < DOLLARNPOINTS; i++, p++) {
+ p->x = SDL_SwapFloatLE(p->x);
+ p->y = SDL_SwapFloatLE(p->y);
+ }
+
+ if (SDL_RWwrite(dst, copy.path,
+ sizeof(copy.path[0]),DOLLARNPOINTS) != DOLLARNPOINTS) {
+ return 0;
+ }
+ }
+#endif
+
+ return 1;
+}
+
+
+int SDL_SaveAllDollarTemplates(SDL_RWops *dst)
+{
+ int i,j,rtrn = 0;
+ for (i = 0; i < SDL_numGestureTouches; i++) {
+ SDL_GestureTouch* touch = &SDL_gestureTouch[i];
+ for (j = 0; j < touch->numDollarTemplates; j++) {
+ rtrn += SaveTemplate(&touch->dollarTemplate[j], dst);
+ }
+ }
+ return rtrn;
+}
+
+int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *dst)
+{
+ int i,j;
+ for (i = 0; i < SDL_numGestureTouches; i++) {
+ SDL_GestureTouch* touch = &SDL_gestureTouch[i];
+ for (j = 0; j < touch->numDollarTemplates; j++) {
+ if (touch->dollarTemplate[j].hash == gestureId) {
+ return SaveTemplate(&touch->dollarTemplate[j], dst);
+ }
+ }
+ }
+ return SDL_SetError("Unknown gestureId");
+}
+
+/* path is an already sampled set of points
+Returns the index of the gesture on success, or -1 */
+static int SDL_AddDollarGesture_one(SDL_GestureTouch* inTouch, SDL_FloatPoint* path)
+{
+ SDL_DollarTemplate* dollarTemplate;
+ SDL_DollarTemplate *templ;
+ int index;
+
+ index = inTouch->numDollarTemplates;
+ dollarTemplate =
+ (SDL_DollarTemplate *)SDL_realloc(inTouch->dollarTemplate,
+ (index + 1) *
+ sizeof(SDL_DollarTemplate));
+ if (!dollarTemplate) {
+ return SDL_OutOfMemory();
+ }
+ inTouch->dollarTemplate = dollarTemplate;
+
+ templ = &inTouch->dollarTemplate[index];
+ SDL_memcpy(templ->path, path, DOLLARNPOINTS*sizeof(SDL_FloatPoint));
+ templ->hash = SDL_HashDollar(templ->path);
+ inTouch->numDollarTemplates++;
+
+ return index;
+}
+
+static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch, SDL_FloatPoint* path)
+{
+ int index = -1;
+ int i = 0;
+ if (inTouch == NULL) {
+ if (SDL_numGestureTouches == 0) return SDL_SetError("no gesture touch devices registered");
+ for (i = 0; i < SDL_numGestureTouches; i++) {
+ inTouch = &SDL_gestureTouch[i];
+ index = SDL_AddDollarGesture_one(inTouch, path);
+ if (index < 0)
+ return -1;
+ }
+ /* Use the index of the last one added. */
+ return index;
+ }
+ return SDL_AddDollarGesture_one(inTouch, path);
+}
+
+int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src)
+{
+ int i,loaded = 0;
+ SDL_GestureTouch *touch = NULL;
+ if (src == NULL) return 0;
+ if (touchId >= 0) {
+ for (i = 0; i < SDL_numGestureTouches; i++) {
+ if (SDL_gestureTouch[i].id == touchId) {
+ touch = &SDL_gestureTouch[i];
+ }
+ }
+ if (touch == NULL) {
+ return SDL_SetError("given touch id not found");
+ }
+ }
+
+ while (1) {
+ SDL_DollarTemplate templ;
+
+ if (SDL_RWread(src,templ.path,sizeof(templ.path[0]),DOLLARNPOINTS) < DOLLARNPOINTS) {
+ if (loaded == 0) {
+ return SDL_SetError("could not read any dollar gesture from rwops");
+ }
+ break;
+ }
+
+#if SDL_BYTEORDER != SDL_LIL_ENDIAN
+ for (i = 0; i < DOLLARNPOINTS; i++) {
+ SDL_FloatPoint *p = &templ.path[i];
+ p->x = SDL_SwapFloatLE(p->x);
+ p->y = SDL_SwapFloatLE(p->y);
+ }
+#endif
+
+ if (touchId >= 0) {
+ /* printf("Adding loaded gesture to 1 touch\n"); */
+ if (SDL_AddDollarGesture(touch, templ.path) >= 0)
+ loaded++;
+ }
+ else {
+ /* printf("Adding to: %i touches\n",SDL_numGestureTouches); */
+ for (i = 0; i < SDL_numGestureTouches; i++) {
+ touch = &SDL_gestureTouch[i];
+ /* printf("Adding loaded gesture to + touches\n"); */
+ /* TODO: What if this fails? */
+ SDL_AddDollarGesture(touch,templ.path);
+ }
+ loaded++;
+ }
+ }
+
+ return loaded;
+}
+
+
+static float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float ang)
+{
+ /* SDL_FloatPoint p[DOLLARNPOINTS]; */
+ float dist = 0;
+ SDL_FloatPoint p;
+ int i;
+ for (i = 0; i < DOLLARNPOINTS; i++) {
+ p.x = (float)(points[i].x * SDL_cos(ang) - points[i].y * SDL_sin(ang));
+ p.y = (float)(points[i].x * SDL_sin(ang) + points[i].y * SDL_cos(ang));
+ dist += (float)(SDL_sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+
+ (p.y-templ[i].y)*(p.y-templ[i].y)));
+ }
+ return dist/DOLLARNPOINTS;
+
+}
+
+static float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ)
+{
+ /*------------BEGIN DOLLAR BLACKBOX------------------
+ -TRANSLATED DIRECTLY FROM PSUDEO-CODE AVAILABLE AT-
+ -"http://depts.washington.edu/aimgroup/proj/dollar/"
+ */
+ double ta = -M_PI/4;
+ double tb = M_PI/4;
+ double dt = M_PI/90;
+ float x1 = (float)(PHI*ta + (1-PHI)*tb);
+ float f1 = dollarDifference(points,templ,x1);
+ float x2 = (float)((1-PHI)*ta + PHI*tb);
+ float f2 = dollarDifference(points,templ,x2);
+ while (SDL_fabs(ta-tb) > dt) {
+ if (f1 < f2) {
+ tb = x2;
+ x2 = x1;
+ f2 = f1;
+ x1 = (float)(PHI*ta + (1-PHI)*tb);
+ f1 = dollarDifference(points,templ,x1);
+ }
+ else {
+ ta = x1;
+ x1 = x2;
+ f1 = f2;
+ x2 = (float)((1-PHI)*ta + PHI*tb);
+ f2 = dollarDifference(points,templ,x2);
+ }
+ }
+ /*
+ if (f1 <= f2)
+ printf("Min angle (x1): %f\n",x1);
+ else if (f1 > f2)
+ printf("Min angle (x2): %f\n",x2);
+ */
+ return SDL_min(f1,f2);
+}
+
+/* DollarPath contains raw points, plus (possibly) the calculated length */
+static int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points)
+{
+ int i;
+ float interval;
+ float dist;
+ int numPoints = 0;
+ SDL_FloatPoint centroid;
+ float xmin,xmax,ymin,ymax;
+ float ang;
+ float w,h;
+ float length = path->length;
+
+ /* Calculate length if it hasn't already been done */
+ if (length <= 0) {
+ for (i=1;i < path->numPoints; i++) {
+ float dx = path->p[i ].x - path->p[i-1].x;
+ float dy = path->p[i ].y - path->p[i-1].y;
+ length += (float)(SDL_sqrt(dx*dx+dy*dy));
+ }
+ }
+
+ /* Resample */
+ interval = length/(DOLLARNPOINTS - 1);
+ dist = interval;
+
+ centroid.x = 0;centroid.y = 0;
+
+ /* printf("(%f,%f)\n",path->p[path->numPoints-1].x,path->p[path->numPoints-1].y); */
+ for (i = 1; i < path->numPoints; i++) {
+ float d = (float)(SDL_sqrt((path->p[i-1].x-path->p[i].x)*(path->p[i-1].x-path->p[i].x)+
+ (path->p[i-1].y-path->p[i].y)*(path->p[i-1].y-path->p[i].y)));
+ /* printf("d = %f dist = %f/%f\n",d,dist,interval); */
+ while (dist + d > interval) {
+ points[numPoints].x = path->p[i-1].x +
+ ((interval-dist)/d)*(path->p[i].x-path->p[i-1].x);
+ points[numPoints].y = path->p[i-1].y +
+ ((interval-dist)/d)*(path->p[i].y-path->p[i-1].y);
+ centroid.x += points[numPoints].x;
+ centroid.y += points[numPoints].y;
+ numPoints++;
+
+ dist -= interval;
+ }
+ dist += d;
+ }
+ if (numPoints < DOLLARNPOINTS-1) {
+ SDL_SetError("ERROR: NumPoints = %i", numPoints);
+ return 0;
+ }
+ /* copy the last point */
+ points[DOLLARNPOINTS-1] = path->p[path->numPoints-1];
+ numPoints = DOLLARNPOINTS;
+
+ centroid.x /= numPoints;
+ centroid.y /= numPoints;
+
+ /* printf("Centroid (%f,%f)",centroid.x,centroid.y); */
+ /* Rotate Points so point 0 is left of centroid and solve for the bounding box */
+ xmin = centroid.x;
+ xmax = centroid.x;
+ ymin = centroid.y;
+ ymax = centroid.y;
+
+ ang = (float)(SDL_atan2(centroid.y - points[0].y,
+ centroid.x - points[0].x));
+
+ for (i = 0; i<numPoints; i++) {
+ float px = points[i].x;
+ float py = points[i].y;
+ points[i].x = (float)((px - centroid.x)*SDL_cos(ang) -
+ (py - centroid.y)*SDL_sin(ang) + centroid.x);
+ points[i].y = (float)((px - centroid.x)*SDL_sin(ang) +
+ (py - centroid.y)*SDL_cos(ang) + centroid.y);
+
+
+ if (points[i].x < xmin) xmin = points[i].x;
+ if (points[i].x > xmax) xmax = points[i].x;
+ if (points[i].y < ymin) ymin = points[i].y;
+ if (points[i].y > ymax) ymax = points[i].y;
+ }
+
+ /* Scale points to DOLLARSIZE, and translate to the origin */
+ w = xmax-xmin;
+ h = ymax-ymin;
+
+ for (i=0; i<numPoints; i++) {
+ points[i].x = (points[i].x - centroid.x)*DOLLARSIZE/w;
+ points[i].y = (points[i].y - centroid.y)*DOLLARSIZE/h;
+ }
+ return numPoints;
+}
+
+static float dollarRecognize(const SDL_DollarPath *path,int *bestTempl,SDL_GestureTouch* touch)
+{
+ SDL_FloatPoint points[DOLLARNPOINTS];
+ int i;
+ float bestDiff = 10000;
+
+ SDL_memset(points, 0, sizeof(points));
+
+ dollarNormalize(path,points);
+
+ /* PrintPath(points); */
+ *bestTempl = -1;
+ for (i = 0; i < touch->numDollarTemplates; i++) {
+ float diff = bestDollarDifference(points,touch->dollarTemplate[i].path);
+ if (diff < bestDiff) {bestDiff = diff; *bestTempl = i;}
+ }
+ return bestDiff;
+}
+
+int SDL_GestureAddTouch(SDL_TouchID touchId)
+{
+ SDL_GestureTouch *gestureTouch = (SDL_GestureTouch *)SDL_realloc(SDL_gestureTouch,
+ (SDL_numGestureTouches + 1) *
+ sizeof(SDL_GestureTouch));
+
+ if (!gestureTouch) {
+ return SDL_OutOfMemory();
+ }
+
+ SDL_gestureTouch = gestureTouch;
+
+ SDL_zero(SDL_gestureTouch[SDL_numGestureTouches]);
+ SDL_gestureTouch[SDL_numGestureTouches].id = touchId;
+ SDL_numGestureTouches++;
+ return 0;
+}
+
+int SDL_GestureDelTouch(SDL_TouchID touchId)
+{
+ int i;
+ for (i = 0; i < SDL_numGestureTouches; i++) {
+ if (SDL_gestureTouch[i].id == touchId) {
+ break;
+ }
+ }
+
+ if (i == SDL_numGestureTouches) {
+ /* not found */
+ return -1;
+ }
+
+ SDL_free(SDL_gestureTouch[i].dollarTemplate);
+ SDL_zero(SDL_gestureTouch[i]);
+
+ SDL_numGestureTouches--;
+ SDL_memcpy(&SDL_gestureTouch[i], &SDL_gestureTouch[SDL_numGestureTouches], sizeof(SDL_gestureTouch[i]));
+ return 0;
+}
+
+static SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id)
+{
+ int i;
+ for (i = 0; i < SDL_numGestureTouches; i++) {
+ /* printf("%i ?= %i\n",SDL_gestureTouch[i].id,id); */
+ if (SDL_gestureTouch[i].id == id)
+ return &SDL_gestureTouch[i];
+ }
+ return NULL;
+}
+
+static int SDL_SendGestureMulti(SDL_GestureTouch* touch,float dTheta,float dDist)
+{
+ SDL_Event event;
+ event.mgesture.type = SDL_MULTIGESTURE;
+ event.mgesture.touchId = touch->id;
+ event.mgesture.x = touch->centroid.x;
+ event.mgesture.y = touch->centroid.y;
+ event.mgesture.dTheta = dTheta;
+ event.mgesture.dDist = dDist;
+ event.mgesture.numFingers = touch->numDownFingers;
+ return SDL_PushEvent(&event) > 0;
+}
+
+static int SDL_SendGestureDollar(SDL_GestureTouch* touch,
+ SDL_GestureID gestureId,float error)
+{
+ SDL_Event event;
+ event.dgesture.type = SDL_DOLLARGESTURE;
+ event.dgesture.touchId = touch->id;
+ event.dgesture.x = touch->centroid.x;
+ event.dgesture.y = touch->centroid.y;
+ event.dgesture.gestureId = gestureId;
+ event.dgesture.error = error;
+ /* A finger came up to trigger this event. */
+ event.dgesture.numFingers = touch->numDownFingers + 1;
+ return SDL_PushEvent(&event) > 0;
+}
+
+
+static int SDL_SendDollarRecord(SDL_GestureTouch* touch,SDL_GestureID gestureId)
+{
+ SDL_Event event;
+ event.dgesture.type = SDL_DOLLARRECORD;
+ event.dgesture.touchId = touch->id;
+ event.dgesture.gestureId = gestureId;
+ return SDL_PushEvent(&event) > 0;
+}
+
+
+void SDL_GestureProcessEvent(SDL_Event* event)
+{
+ float x,y;
+ int index;
+ int i;
+ float pathDx, pathDy;
+ SDL_FloatPoint lastP;
+ SDL_FloatPoint lastCentroid;
+ float lDist;
+ float Dist;
+ float dtheta;
+ float dDist;
+
+ if (event->type == SDL_FINGERMOTION ||
+ event->type == SDL_FINGERDOWN ||
+ event->type == SDL_FINGERUP) {
+ SDL_GestureTouch* inTouch = SDL_GetGestureTouch(event->tfinger.touchId);
+
+ /* Shouldn't be possible */
+ if (inTouch == NULL) return;
+
+ x = event->tfinger.x;
+ y = event->tfinger.y;
+
+ /* Finger Up */
+ if (event->type == SDL_FINGERUP) {
+ SDL_FloatPoint path[DOLLARNPOINTS];
+
+ inTouch->numDownFingers--;
+
+#ifdef ENABLE_DOLLAR
+ if (inTouch->recording) {
+ inTouch->recording = SDL_FALSE;
+ dollarNormalize(&inTouch->dollarPath,path);
+ /* PrintPath(path); */
+ if (recordAll) {
+ index = SDL_AddDollarGesture(NULL,path);
+ for (i = 0; i < SDL_numGestureTouches; i++)
+ SDL_gestureTouch[i].recording = SDL_FALSE;
+ }
+ else {
+ index = SDL_AddDollarGesture(inTouch,path);
+ }
+
+ if (index >= 0) {
+ SDL_SendDollarRecord(inTouch,inTouch->dollarTemplate[index].hash);
+ }
+ else {
+ SDL_SendDollarRecord(inTouch,-1);
+ }
+ }
+ else {
+ int bestTempl;
+ float error;
+ error = dollarRecognize(&inTouch->dollarPath,
+ &bestTempl,inTouch);
+ if (bestTempl >= 0){
+ /* Send Event */
+ unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash;
+ SDL_SendGestureDollar(inTouch,gestureId,error);
+ /* printf ("%s\n",);("Dollar error: %f\n",error); */
+ }
+ }
+#endif
+ /* inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers]; */
+ if (inTouch->numDownFingers > 0) {
+ inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers+1)-
+ x)/inTouch->numDownFingers;
+ inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers+1)-
+ y)/inTouch->numDownFingers;
+ }
+ }
+ else if (event->type == SDL_FINGERMOTION) {
+ float dx = event->tfinger.dx;
+ float dy = event->tfinger.dy;
+#ifdef ENABLE_DOLLAR
+ SDL_DollarPath* path = &inTouch->dollarPath;
+ if (path->numPoints < MAXPATHSIZE) {
+ path->p[path->numPoints].x = inTouch->centroid.x;
+ path->p[path->numPoints].y = inTouch->centroid.y;
+ pathDx =
+ (path->p[path->numPoints].x-path->p[path->numPoints-1].x);
+ pathDy =
+ (path->p[path->numPoints].y-path->p[path->numPoints-1].y);
+ path->length += (float)SDL_sqrt(pathDx*pathDx + pathDy*pathDy);
+ path->numPoints++;
+ }
+#endif
+ lastP.x = x - dx;
+ lastP.y = y - dy;
+ lastCentroid = inTouch->centroid;
+
+ inTouch->centroid.x += dx/inTouch->numDownFingers;
+ inTouch->centroid.y += dy/inTouch->numDownFingers;
+ /* printf("Centrid : (%f,%f)\n",inTouch->centroid.x,inTouch->centroid.y); */
+ if (inTouch->numDownFingers > 1) {
+ SDL_FloatPoint lv; /* Vector from centroid to last x,y position */
+ SDL_FloatPoint v; /* Vector from centroid to current x,y position */
+ /* lv = inTouch->gestureLast[j].cv; */
+ lv.x = lastP.x - lastCentroid.x;
+ lv.y = lastP.y - lastCentroid.y;
+ lDist = (float)SDL_sqrt(lv.x*lv.x + lv.y*lv.y);
+ /* printf("lDist = %f\n",lDist); */
+ v.x = x - inTouch->centroid.x;
+ v.y = y - inTouch->centroid.y;
+ /* inTouch->gestureLast[j].cv = v; */
+ Dist = (float)SDL_sqrt(v.x*v.x+v.y*v.y);
+ /* SDL_cos(dTheta) = (v . lv)/(|v| * |lv|) */
+
+ /* Normalize Vectors to simplify angle calculation */
+ lv.x/=lDist;
+ lv.y/=lDist;
+ v.x/=Dist;
+ v.y/=Dist;
+ dtheta = (float)SDL_atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
+
+ dDist = (Dist - lDist);
+ if (lDist == 0) {dDist = 0;dtheta = 0;} /* To avoid impossible values */
+
+ /* inTouch->gestureLast[j].dDist = dDist;
+ inTouch->gestureLast[j].dtheta = dtheta;
+
+ printf("dDist = %f, dTheta = %f\n",dDist,dtheta);
+ gdtheta = gdtheta*.9 + dtheta*.1;
+ gdDist = gdDist*.9 + dDist*.1
+ knob.r += dDist/numDownFingers;
+ knob.ang += dtheta;
+ printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist);
+ printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist); */
+ SDL_SendGestureMulti(inTouch,dtheta,dDist);
+ }
+ else {
+ /* inTouch->gestureLast[j].dDist = 0;
+ inTouch->gestureLast[j].dtheta = 0;
+ inTouch->gestureLast[j].cv.x = 0;
+ inTouch->gestureLast[j].cv.y = 0; */
+ }
+ /* inTouch->gestureLast[j].f.p.x = x;
+ inTouch->gestureLast[j].f.p.y = y;
+ break;
+ pressure? */
+ }
+ else if (event->type == SDL_FINGERDOWN) {
+
+ inTouch->numDownFingers++;
+ inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers - 1)+
+ x)/inTouch->numDownFingers;
+ inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers - 1)+
+ y)/inTouch->numDownFingers;
+ /* printf("Finger Down: (%f,%f). Centroid: (%f,%f\n",x,y,
+ inTouch->centroid.x,inTouch->centroid.y); */
+
+#ifdef ENABLE_DOLLAR
+ inTouch->dollarPath.length = 0;
+ inTouch->dollarPath.p[0].x = x;
+ inTouch->dollarPath.p[0].y = y;
+ inTouch->dollarPath.numPoints = 1;
+#endif
+ }
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/SDL_gesture_c.h b/src/3rdparty/SDL2/src/events/SDL_gesture_c.h
new file mode 100644
index 0000000..b8e4427
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/SDL_gesture_c.h
@@ -0,0 +1,35 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#ifndef SDL_gesture_c_h_
+#define SDL_gesture_c_h_
+
+extern int SDL_GestureAddTouch(SDL_TouchID touchId);
+extern int SDL_GestureDelTouch(SDL_TouchID touchId);
+
+extern void SDL_GestureProcessEvent(SDL_Event* event);
+
+extern void SDL_GestureQuit(void);
+
+#endif /* SDL_gesture_c_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/SDL_keyboard.c b/src/3rdparty/SDL2/src/events/SDL_keyboard.c
new file mode 100644
index 0000000..e129576
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/SDL_keyboard.c
@@ -0,0 +1,1033 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* General keyboard handling code for SDL */
+
+#include "SDL_timer.h"
+#include "SDL_events.h"
+#include "SDL_events_c.h"
+#include "SDL_assert.h"
+#include "../video/SDL_sysvideo.h"
+
+
+/* #define DEBUG_KEYBOARD */
+
+/* Global keyboard information */
+
+typedef struct SDL_Keyboard SDL_Keyboard;
+
+struct SDL_Keyboard
+{
+ /* Data common to all keyboards */
+ SDL_Window *focus;
+ Uint16 modstate;
+ Uint8 keystate[SDL_NUM_SCANCODES];
+ SDL_Keycode keymap[SDL_NUM_SCANCODES];
+};
+
+static SDL_Keyboard SDL_keyboard;
+
+static const SDL_Keycode SDL_default_keymap[SDL_NUM_SCANCODES] = {
+ 0, 0, 0, 0,
+ 'a',
+ 'b',
+ 'c',
+ 'd',
+ 'e',
+ 'f',
+ 'g',
+ 'h',
+ 'i',
+ 'j',
+ 'k',
+ 'l',
+ 'm',
+ 'n',
+ 'o',
+ 'p',
+ 'q',
+ 'r',
+ 's',
+ 't',
+ 'u',
+ 'v',
+ 'w',
+ 'x',
+ 'y',
+ 'z',
+ '1',
+ '2',
+ '3',
+ '4',
+ '5',
+ '6',
+ '7',
+ '8',
+ '9',
+ '0',
+ SDLK_RETURN,
+ SDLK_ESCAPE,
+ SDLK_BACKSPACE,
+ SDLK_TAB,
+ SDLK_SPACE,
+ '-',
+ '=',
+ '[',
+ ']',
+ '\\',
+ '#',
+ ';',
+ '\'',
+ '`',
+ ',',
+ '.',
+ '/',
+ SDLK_CAPSLOCK,
+ SDLK_F1,
+ SDLK_F2,
+ SDLK_F3,
+ SDLK_F4,
+ SDLK_F5,
+ SDLK_F6,
+ SDLK_F7,
+ SDLK_F8,
+ SDLK_F9,
+ SDLK_F10,
+ SDLK_F11,
+ SDLK_F12,
+ SDLK_PRINTSCREEN,
+ SDLK_SCROLLLOCK,
+ SDLK_PAUSE,
+ SDLK_INSERT,
+ SDLK_HOME,
+ SDLK_PAGEUP,
+ SDLK_DELETE,
+ SDLK_END,
+ SDLK_PAGEDOWN,
+ SDLK_RIGHT,
+ SDLK_LEFT,
+ SDLK_DOWN,
+ SDLK_UP,
+ SDLK_NUMLOCKCLEAR,
+ SDLK_KP_DIVIDE,
+ SDLK_KP_MULTIPLY,
+ SDLK_KP_MINUS,
+ SDLK_KP_PLUS,
+ SDLK_KP_ENTER,
+ SDLK_KP_1,
+ SDLK_KP_2,
+ SDLK_KP_3,
+ SDLK_KP_4,
+ SDLK_KP_5,
+ SDLK_KP_6,
+ SDLK_KP_7,
+ SDLK_KP_8,
+ SDLK_KP_9,
+ SDLK_KP_0,
+ SDLK_KP_PERIOD,
+ 0,
+ SDLK_APPLICATION,
+ SDLK_POWER,
+ SDLK_KP_EQUALS,
+ SDLK_F13,
+ SDLK_F14,
+ SDLK_F15,
+ SDLK_F16,
+ SDLK_F17,
+ SDLK_F18,
+ SDLK_F19,
+ SDLK_F20,
+ SDLK_F21,
+ SDLK_F22,
+ SDLK_F23,
+ SDLK_F24,
+ SDLK_EXECUTE,
+ SDLK_HELP,
+ SDLK_MENU,
+ SDLK_SELECT,
+ SDLK_STOP,
+ SDLK_AGAIN,
+ SDLK_UNDO,
+ SDLK_CUT,
+ SDLK_COPY,
+ SDLK_PASTE,
+ SDLK_FIND,
+ SDLK_MUTE,
+ SDLK_VOLUMEUP,
+ SDLK_VOLUMEDOWN,
+ 0, 0, 0,
+ SDLK_KP_COMMA,
+ SDLK_KP_EQUALSAS400,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ SDLK_ALTERASE,
+ SDLK_SYSREQ,
+ SDLK_CANCEL,
+ SDLK_CLEAR,
+ SDLK_PRIOR,
+ SDLK_RETURN2,
+ SDLK_SEPARATOR,
+ SDLK_OUT,
+ SDLK_OPER,
+ SDLK_CLEARAGAIN,
+ SDLK_CRSEL,
+ SDLK_EXSEL,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ SDLK_KP_00,
+ SDLK_KP_000,
+ SDLK_THOUSANDSSEPARATOR,
+ SDLK_DECIMALSEPARATOR,
+ SDLK_CURRENCYUNIT,
+ SDLK_CURRENCYSUBUNIT,
+ SDLK_KP_LEFTPAREN,
+ SDLK_KP_RIGHTPAREN,
+ SDLK_KP_LEFTBRACE,
+ SDLK_KP_RIGHTBRACE,
+ SDLK_KP_TAB,
+ SDLK_KP_BACKSPACE,
+ SDLK_KP_A,
+ SDLK_KP_B,
+ SDLK_KP_C,
+ SDLK_KP_D,
+ SDLK_KP_E,
+ SDLK_KP_F,
+ SDLK_KP_XOR,
+ SDLK_KP_POWER,
+ SDLK_KP_PERCENT,
+ SDLK_KP_LESS,
+ SDLK_KP_GREATER,
+ SDLK_KP_AMPERSAND,
+ SDLK_KP_DBLAMPERSAND,
+ SDLK_KP_VERTICALBAR,
+ SDLK_KP_DBLVERTICALBAR,
+ SDLK_KP_COLON,
+ SDLK_KP_HASH,
+ SDLK_KP_SPACE,
+ SDLK_KP_AT,
+ SDLK_KP_EXCLAM,
+ SDLK_KP_MEMSTORE,
+ SDLK_KP_MEMRECALL,
+ SDLK_KP_MEMCLEAR,
+ SDLK_KP_MEMADD,
+ SDLK_KP_MEMSUBTRACT,
+ SDLK_KP_MEMMULTIPLY,
+ SDLK_KP_MEMDIVIDE,
+ SDLK_KP_PLUSMINUS,
+ SDLK_KP_CLEAR,
+ SDLK_KP_CLEARENTRY,
+ SDLK_KP_BINARY,
+ SDLK_KP_OCTAL,
+ SDLK_KP_DECIMAL,
+ SDLK_KP_HEXADECIMAL,
+ 0, 0,
+ SDLK_LCTRL,
+ SDLK_LSHIFT,
+ SDLK_LALT,
+ SDLK_LGUI,
+ SDLK_RCTRL,
+ SDLK_RSHIFT,
+ SDLK_RALT,
+ SDLK_RGUI,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ SDLK_MODE,
+ SDLK_AUDIONEXT,
+ SDLK_AUDIOPREV,
+ SDLK_AUDIOSTOP,
+ SDLK_AUDIOPLAY,
+ SDLK_AUDIOMUTE,
+ SDLK_MEDIASELECT,
+ SDLK_WWW,
+ SDLK_MAIL,
+ SDLK_CALCULATOR,
+ SDLK_COMPUTER,
+ SDLK_AC_SEARCH,
+ SDLK_AC_HOME,
+ SDLK_AC_BACK,
+ SDLK_AC_FORWARD,
+ SDLK_AC_STOP,
+ SDLK_AC_REFRESH,
+ SDLK_AC_BOOKMARKS,
+ SDLK_BRIGHTNESSDOWN,
+ SDLK_BRIGHTNESSUP,
+ SDLK_DISPLAYSWITCH,
+ SDLK_KBDILLUMTOGGLE,
+ SDLK_KBDILLUMDOWN,
+ SDLK_KBDILLUMUP,
+ SDLK_EJECT,
+ SDLK_SLEEP,
+ SDLK_APP1,
+ SDLK_APP2,
+ SDLK_AUDIOREWIND,
+ SDLK_AUDIOFASTFORWARD,
+};
+
+static const char *SDL_scancode_names[SDL_NUM_SCANCODES] = {
+ NULL, NULL, NULL, NULL,
+ "A",
+ "B",
+ "C",
+ "D",
+ "E",
+ "F",
+ "G",
+ "H",
+ "I",
+ "J",
+ "K",
+ "L",
+ "M",
+ "N",
+ "O",
+ "P",
+ "Q",
+ "R",
+ "S",
+ "T",
+ "U",
+ "V",
+ "W",
+ "X",
+ "Y",
+ "Z",
+ "1",
+ "2",
+ "3",
+ "4",
+ "5",
+ "6",
+ "7",
+ "8",
+ "9",
+ "0",
+ "Return",
+ "Escape",
+ "Backspace",
+ "Tab",
+ "Space",
+ "-",
+ "=",
+ "[",
+ "]",
+ "\\",
+ "#",
+ ";",
+ "'",
+ "`",
+ ",",
+ ".",
+ "/",
+ "CapsLock",
+ "F1",
+ "F2",
+ "F3",
+ "F4",
+ "F5",
+ "F6",
+ "F7",
+ "F8",
+ "F9",
+ "F10",
+ "F11",
+ "F12",
+ "PrintScreen",
+ "ScrollLock",
+ "Pause",
+ "Insert",
+ "Home",
+ "PageUp",
+ "Delete",
+ "End",
+ "PageDown",
+ "Right",
+ "Left",
+ "Down",
+ "Up",
+ "Numlock",
+ "Keypad /",
+ "Keypad *",
+ "Keypad -",
+ "Keypad +",
+ "Keypad Enter",
+ "Keypad 1",
+ "Keypad 2",
+ "Keypad 3",
+ "Keypad 4",
+ "Keypad 5",
+ "Keypad 6",
+ "Keypad 7",
+ "Keypad 8",
+ "Keypad 9",
+ "Keypad 0",
+ "Keypad .",
+ NULL,
+ "Application",
+ "Power",
+ "Keypad =",
+ "F13",
+ "F14",
+ "F15",
+ "F16",
+ "F17",
+ "F18",
+ "F19",
+ "F20",
+ "F21",
+ "F22",
+ "F23",
+ "F24",
+ "Execute",
+ "Help",
+ "Menu",
+ "Select",
+ "Stop",
+ "Again",
+ "Undo",
+ "Cut",
+ "Copy",
+ "Paste",
+ "Find",
+ "Mute",
+ "VolumeUp",
+ "VolumeDown",
+ NULL, NULL, NULL,
+ "Keypad ,",
+ "Keypad = (AS400)",
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL,
+ "AltErase",
+ "SysReq",
+ "Cancel",
+ "Clear",
+ "Prior",
+ "Return",
+ "Separator",
+ "Out",
+ "Oper",
+ "Clear / Again",
+ "CrSel",
+ "ExSel",
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ "Keypad 00",
+ "Keypad 000",
+ "ThousandsSeparator",
+ "DecimalSeparator",
+ "CurrencyUnit",
+ "CurrencySubUnit",
+ "Keypad (",
+ "Keypad )",
+ "Keypad {",
+ "Keypad }",
+ "Keypad Tab",
+ "Keypad Backspace",
+ "Keypad A",
+ "Keypad B",
+ "Keypad C",
+ "Keypad D",
+ "Keypad E",
+ "Keypad F",
+ "Keypad XOR",
+ "Keypad ^",
+ "Keypad %",
+ "Keypad <",
+ "Keypad >",
+ "Keypad &",
+ "Keypad &&",
+ "Keypad |",
+ "Keypad ||",
+ "Keypad :",
+ "Keypad #",
+ "Keypad Space",
+ "Keypad @",
+ "Keypad !",
+ "Keypad MemStore",
+ "Keypad MemRecall",
+ "Keypad MemClear",
+ "Keypad MemAdd",
+ "Keypad MemSubtract",
+ "Keypad MemMultiply",
+ "Keypad MemDivide",
+ "Keypad +/-",
+ "Keypad Clear",
+ "Keypad ClearEntry",
+ "Keypad Binary",
+ "Keypad Octal",
+ "Keypad Decimal",
+ "Keypad Hexadecimal",
+ NULL, NULL,
+ "Left Ctrl",
+ "Left Shift",
+ "Left Alt",
+ "Left GUI",
+ "Right Ctrl",
+ "Right Shift",
+ "Right Alt",
+ "Right GUI",
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL,
+ "ModeSwitch",
+ "AudioNext",
+ "AudioPrev",
+ "AudioStop",
+ "AudioPlay",
+ "AudioMute",
+ "MediaSelect",
+ "WWW",
+ "Mail",
+ "Calculator",
+ "Computer",
+ "AC Search",
+ "AC Home",
+ "AC Back",
+ "AC Forward",
+ "AC Stop",
+ "AC Refresh",
+ "AC Bookmarks",
+ "BrightnessDown",
+ "BrightnessUp",
+ "DisplaySwitch",
+ "KBDIllumToggle",
+ "KBDIllumDown",
+ "KBDIllumUp",
+ "Eject",
+ "Sleep",
+ "App1",
+ "App2",
+ "AudioRewind",
+ "AudioFastForward",
+};
+
+/* Taken from SDL_iconv() */
+char *
+SDL_UCS4ToUTF8(Uint32 ch, char *dst)
+{
+ Uint8 *p = (Uint8 *) dst;
+ if (ch <= 0x7F) {
+ *p = (Uint8) ch;
+ ++dst;
+ } else if (ch <= 0x7FF) {
+ p[0] = 0xC0 | (Uint8) ((ch >> 6) & 0x1F);
+ p[1] = 0x80 | (Uint8) (ch & 0x3F);
+ dst += 2;
+ } else if (ch <= 0xFFFF) {
+ p[0] = 0xE0 | (Uint8) ((ch >> 12) & 0x0F);
+ p[1] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
+ p[2] = 0x80 | (Uint8) (ch & 0x3F);
+ dst += 3;
+ } else if (ch <= 0x1FFFFF) {
+ p[0] = 0xF0 | (Uint8) ((ch >> 18) & 0x07);
+ p[1] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
+ p[2] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
+ p[3] = 0x80 | (Uint8) (ch & 0x3F);
+ dst += 4;
+ } else if (ch <= 0x3FFFFFF) {
+ p[0] = 0xF8 | (Uint8) ((ch >> 24) & 0x03);
+ p[1] = 0x80 | (Uint8) ((ch >> 18) & 0x3F);
+ p[2] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
+ p[3] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
+ p[4] = 0x80 | (Uint8) (ch & 0x3F);
+ dst += 5;
+ } else {
+ p[0] = 0xFC | (Uint8) ((ch >> 30) & 0x01);
+ p[1] = 0x80 | (Uint8) ((ch >> 24) & 0x3F);
+ p[2] = 0x80 | (Uint8) ((ch >> 18) & 0x3F);
+ p[3] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
+ p[4] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
+ p[5] = 0x80 | (Uint8) (ch & 0x3F);
+ dst += 6;
+ }
+ return dst;
+}
+
+/* Public functions */
+int
+SDL_KeyboardInit(void)
+{
+ SDL_Keyboard *keyboard = &SDL_keyboard;
+
+ /* Set the default keymap */
+ SDL_memcpy(keyboard->keymap, SDL_default_keymap, sizeof(SDL_default_keymap));
+ return (0);
+}
+
+void
+SDL_ResetKeyboard(void)
+{
+ SDL_Keyboard *keyboard = &SDL_keyboard;
+ SDL_Scancode scancode;
+
+#ifdef DEBUG_KEYBOARD
+ printf("Resetting keyboard\n");
+#endif
+ for (scancode = (SDL_Scancode) 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
+ if (keyboard->keystate[scancode] == SDL_PRESSED) {
+ SDL_SendKeyboardKey(SDL_RELEASED, scancode);
+ }
+ }
+}
+
+void
+SDL_GetDefaultKeymap(SDL_Keycode * keymap)
+{
+ SDL_memcpy(keymap, SDL_default_keymap, sizeof(SDL_default_keymap));
+}
+
+void
+SDL_SetKeymap(int start, SDL_Keycode * keys, int length)
+{
+ SDL_Keyboard *keyboard = &SDL_keyboard;
+ SDL_Scancode scancode;
+
+ if (start < 0 || start + length > SDL_NUM_SCANCODES) {
+ return;
+ }
+
+ SDL_memcpy(&keyboard->keymap[start], keys, sizeof(*keys) * length);
+
+ /* The number key scancodes always map to the number key keycodes.
+ * On AZERTY layouts these technically are symbols, but users (and games)
+ * always think of them and view them in UI as number keys.
+ */
+ keyboard->keymap[SDL_SCANCODE_0] = SDLK_0;
+ for (scancode = SDL_SCANCODE_1; scancode <= SDL_SCANCODE_9; ++scancode) {
+ keyboard->keymap[scancode] = SDLK_1 + (scancode - SDL_SCANCODE_1);
+ }
+}
+
+void
+SDL_SetScancodeName(SDL_Scancode scancode, const char *name)
+{
+ SDL_scancode_names[scancode] = name;
+}
+
+SDL_Window *
+SDL_GetKeyboardFocus(void)
+{
+ SDL_Keyboard *keyboard = &SDL_keyboard;
+
+ return keyboard->focus;
+}
+
+void
+SDL_SetKeyboardFocus(SDL_Window * window)
+{
+ SDL_Keyboard *keyboard = &SDL_keyboard;
+
+ if (keyboard->focus && !window) {
+ /* We won't get anymore keyboard messages, so reset keyboard state */
+ SDL_ResetKeyboard();
+ }
+
+ /* See if the current window has lost focus */
+ if (keyboard->focus && keyboard->focus != window) {
+
+ /* new window shouldn't think it has mouse captured. */
+ SDL_assert(!window || !(window->flags & SDL_WINDOW_MOUSE_CAPTURE));
+
+ /* old window must lose an existing mouse capture. */
+ if (keyboard->focus->flags & SDL_WINDOW_MOUSE_CAPTURE) {
+ SDL_CaptureMouse(SDL_FALSE); /* drop the capture. */
+ SDL_assert(!(keyboard->focus->flags & SDL_WINDOW_MOUSE_CAPTURE));
+ }
+
+ SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_LOST,
+ 0, 0);
+
+ /* Ensures IME compositions are committed */
+ if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
+ SDL_VideoDevice *video = SDL_GetVideoDevice();
+ if (video && video->StopTextInput) {
+ video->StopTextInput(video);
+ }
+ }
+ }
+
+ keyboard->focus = window;
+
+ if (keyboard->focus) {
+ SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_GAINED,
+ 0, 0);
+
+ if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
+ SDL_VideoDevice *video = SDL_GetVideoDevice();
+ if (video && video->StartTextInput) {
+ video->StartTextInput(video);
+ }
+ }
+ }
+}
+
+int
+SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
+{
+ SDL_Keyboard *keyboard = &SDL_keyboard;
+ int posted;
+ SDL_Keymod modifier;
+ SDL_Keycode keycode;
+ Uint32 type;
+ Uint8 repeat;
+
+ if (!scancode) {
+ return 0;
+ }
+#ifdef DEBUG_KEYBOARD
+ printf("The '%s' key has been %s\n", SDL_GetScancodeName(scancode),
+ state == SDL_PRESSED ? "pressed" : "released");
+#endif
+
+ /* Figure out what type of event this is */
+ switch (state) {
+ case SDL_PRESSED:
+ type = SDL_KEYDOWN;
+ break;
+ case SDL_RELEASED:
+ type = SDL_KEYUP;
+ break;
+ default:
+ /* Invalid state -- bail */
+ return 0;
+ }
+
+ /* Drop events that don't change state */
+ repeat = (state && keyboard->keystate[scancode]);
+ if (keyboard->keystate[scancode] == state && !repeat) {
+#if 0
+ printf("Keyboard event didn't change state - dropped!\n");
+#endif
+ return 0;
+ }
+
+ /* Update internal keyboard state */
+ keyboard->keystate[scancode] = state;
+
+ keycode = keyboard->keymap[scancode];
+
+ /* Update modifiers state if applicable */
+ switch (keycode) {
+ case SDLK_LCTRL:
+ modifier = KMOD_LCTRL;
+ break;
+ case SDLK_RCTRL:
+ modifier = KMOD_RCTRL;
+ break;
+ case SDLK_LSHIFT:
+ modifier = KMOD_LSHIFT;
+ break;
+ case SDLK_RSHIFT:
+ modifier = KMOD_RSHIFT;
+ break;
+ case SDLK_LALT:
+ modifier = KMOD_LALT;
+ break;
+ case SDLK_RALT:
+ modifier = KMOD_RALT;
+ break;
+ case SDLK_LGUI:
+ modifier = KMOD_LGUI;
+ break;
+ case SDLK_RGUI:
+ modifier = KMOD_RGUI;
+ break;
+ case SDLK_MODE:
+ modifier = KMOD_MODE;
+ break;
+ default:
+ modifier = KMOD_NONE;
+ break;
+ }
+ if (SDL_KEYDOWN == type) {
+ switch (keycode) {
+ case SDLK_NUMLOCKCLEAR:
+ keyboard->modstate ^= KMOD_NUM;
+ break;
+ case SDLK_CAPSLOCK:
+ keyboard->modstate ^= KMOD_CAPS;
+ break;
+ default:
+ keyboard->modstate |= modifier;
+ break;
+ }
+ } else {
+ keyboard->modstate &= ~modifier;
+ }
+
+ /* Post the event, if desired */
+ posted = 0;
+ if (SDL_GetEventState(type) == SDL_ENABLE) {
+ SDL_Event event;
+ event.key.type = type;
+ event.key.state = state;
+ event.key.repeat = repeat;
+ event.key.keysym.scancode = scancode;
+ event.key.keysym.sym = keycode;
+ event.key.keysym.mod = keyboard->modstate;
+ event.key.windowID = keyboard->focus ? keyboard->focus->id : 0;
+ posted = (SDL_PushEvent(&event) > 0);
+ }
+ return (posted);
+}
+
+int
+SDL_SendKeyboardText(const char *text)
+{
+ SDL_Keyboard *keyboard = &SDL_keyboard;
+ int posted;
+
+ /* Don't post text events for unprintable characters */
+ if ((unsigned char)*text < ' ' || *text == 127) {
+ return 0;
+ }
+
+ /* Post the event, if desired */
+ posted = 0;
+ if (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) {
+ SDL_Event event;
+ event.text.type = SDL_TEXTINPUT;
+ event.text.windowID = keyboard->focus ? keyboard->focus->id : 0;
+ SDL_utf8strlcpy(event.text.text, text, SDL_arraysize(event.text.text));
+ posted = (SDL_PushEvent(&event) > 0);
+ }
+ return (posted);
+}
+
+int
+SDL_SendEditingText(const char *text, int start, int length)
+{
+ SDL_Keyboard *keyboard = &SDL_keyboard;
+ int posted;
+
+ /* Post the event, if desired */
+ posted = 0;
+ if (SDL_GetEventState(SDL_TEXTEDITING) == SDL_ENABLE) {
+ SDL_Event event;
+ event.edit.type = SDL_TEXTEDITING;
+ event.edit.windowID = keyboard->focus ? keyboard->focus->id : 0;
+ event.edit.start = start;
+ event.edit.length = length;
+ SDL_utf8strlcpy(event.edit.text, text, SDL_arraysize(event.edit.text));
+ posted = (SDL_PushEvent(&event) > 0);
+ }
+ return (posted);
+}
+
+void
+SDL_KeyboardQuit(void)
+{
+}
+
+const Uint8 *
+SDL_GetKeyboardState(int *numkeys)
+{
+ SDL_Keyboard *keyboard = &SDL_keyboard;
+
+ if (numkeys != (int *) 0) {
+ *numkeys = SDL_NUM_SCANCODES;
+ }
+ return keyboard->keystate;
+}
+
+SDL_Keymod
+SDL_GetModState(void)
+{
+ SDL_Keyboard *keyboard = &SDL_keyboard;
+
+ return (SDL_Keymod) keyboard->modstate;
+}
+
+void
+SDL_SetModState(SDL_Keymod modstate)
+{
+ SDL_Keyboard *keyboard = &SDL_keyboard;
+
+ keyboard->modstate = modstate;
+}
+
+/* Note that SDL_ToggleModState() is not a public API. SDL_SetModState() is. */
+void
+SDL_ToggleModState(const SDL_Keymod modstate, const SDL_bool toggle)
+{
+ SDL_Keyboard *keyboard = &SDL_keyboard;
+ if (toggle) {
+ keyboard->modstate |= modstate;
+ } else {
+ keyboard->modstate &= ~modstate;
+ }
+}
+
+
+SDL_Keycode
+SDL_GetKeyFromScancode(SDL_Scancode scancode)
+{
+ SDL_Keyboard *keyboard = &SDL_keyboard;
+
+ if (((int)scancode) < ((int)SDL_SCANCODE_UNKNOWN) || scancode >= SDL_NUM_SCANCODES) {
+ SDL_InvalidParamError("scancode");
+ return 0;
+ }
+
+ return keyboard->keymap[scancode];
+}
+
+SDL_Scancode
+SDL_GetScancodeFromKey(SDL_Keycode key)
+{
+ SDL_Keyboard *keyboard = &SDL_keyboard;
+ SDL_Scancode scancode;
+
+ for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES;
+ ++scancode) {
+ if (keyboard->keymap[scancode] == key) {
+ return scancode;
+ }
+ }
+ return SDL_SCANCODE_UNKNOWN;
+}
+
+const char *
+SDL_GetScancodeName(SDL_Scancode scancode)
+{
+ const char *name;
+ if (((int)scancode) < ((int)SDL_SCANCODE_UNKNOWN) || scancode >= SDL_NUM_SCANCODES) {
+ SDL_InvalidParamError("scancode");
+ return "";
+ }
+
+ name = SDL_scancode_names[scancode];
+ if (name)
+ return name;
+ else
+ return "";
+}
+
+SDL_Scancode SDL_GetScancodeFromName(const char *name)
+{
+ int i;
+
+ if (!name || !*name) {
+ SDL_InvalidParamError("name");
+ return SDL_SCANCODE_UNKNOWN;
+ }
+
+ for (i = 0; i < SDL_arraysize(SDL_scancode_names); ++i) {
+ if (!SDL_scancode_names[i]) {
+ continue;
+ }
+ if (SDL_strcasecmp(name, SDL_scancode_names[i]) == 0) {
+ return (SDL_Scancode)i;
+ }
+ }
+
+ SDL_InvalidParamError("name");
+ return SDL_SCANCODE_UNKNOWN;
+}
+
+const char *
+SDL_GetKeyName(SDL_Keycode key)
+{
+ static char name[8];
+ char *end;
+
+ if (key & SDLK_SCANCODE_MASK) {
+ return
+ SDL_GetScancodeName((SDL_Scancode) (key & ~SDLK_SCANCODE_MASK));
+ }
+
+ switch (key) {
+ case SDLK_RETURN:
+ return SDL_GetScancodeName(SDL_SCANCODE_RETURN);
+ case SDLK_ESCAPE:
+ return SDL_GetScancodeName(SDL_SCANCODE_ESCAPE);
+ case SDLK_BACKSPACE:
+ return SDL_GetScancodeName(SDL_SCANCODE_BACKSPACE);
+ case SDLK_TAB:
+ return SDL_GetScancodeName(SDL_SCANCODE_TAB);
+ case SDLK_SPACE:
+ return SDL_GetScancodeName(SDL_SCANCODE_SPACE);
+ case SDLK_DELETE:
+ return SDL_GetScancodeName(SDL_SCANCODE_DELETE);
+ default:
+ /* Unaccented letter keys on latin keyboards are normally
+ labeled in upper case (and probably on others like Greek or
+ Cyrillic too, so if you happen to know for sure, please
+ adapt this). */
+ if (key >= 'a' && key <= 'z') {
+ key -= 32;
+ }
+
+ end = SDL_UCS4ToUTF8((Uint32) key, name);
+ *end = '\0';
+ return name;
+ }
+}
+
+SDL_Keycode
+SDL_GetKeyFromName(const char *name)
+{
+ SDL_Keycode key;
+
+ /* Check input */
+ if (name == NULL) {
+ return SDLK_UNKNOWN;
+ }
+
+ /* If it's a single UTF-8 character, then that's the keycode itself */
+ key = *(const unsigned char *)name;
+ if (key >= 0xF0) {
+ if (SDL_strlen(name) == 4) {
+ int i = 0;
+ key = (Uint16)(name[i]&0x07) << 18;
+ key |= (Uint16)(name[++i]&0x3F) << 12;
+ key |= (Uint16)(name[++i]&0x3F) << 6;
+ key |= (Uint16)(name[++i]&0x3F);
+ return key;
+ }
+ return SDLK_UNKNOWN;
+ } else if (key >= 0xE0) {
+ if (SDL_strlen(name) == 3) {
+ int i = 0;
+ key = (Uint16)(name[i]&0x0F) << 12;
+ key |= (Uint16)(name[++i]&0x3F) << 6;
+ key |= (Uint16)(name[++i]&0x3F);
+ return key;
+ }
+ return SDLK_UNKNOWN;
+ } else if (key >= 0xC0) {
+ if (SDL_strlen(name) == 2) {
+ int i = 0;
+ key = (Uint16)(name[i]&0x1F) << 6;
+ key |= (Uint16)(name[++i]&0x3F);
+ return key;
+ }
+ return SDLK_UNKNOWN;
+ } else {
+ if (SDL_strlen(name) == 1) {
+ if (key >= 'A' && key <= 'Z') {
+ key += 32;
+ }
+ return key;
+ }
+
+ /* Get the scancode for this name, and the associated keycode */
+ return SDL_default_keymap[SDL_GetScancodeFromName(name)];
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/SDL_keyboard_c.h b/src/3rdparty/SDL2/src/events/SDL_keyboard_c.h
new file mode 100644
index 0000000..7f12a38
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/SDL_keyboard_c.h
@@ -0,0 +1,70 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#ifndef SDL_keyboard_c_h_
+#define SDL_keyboard_c_h_
+
+#include "SDL_keycode.h"
+#include "SDL_events.h"
+
+/* Initialize the keyboard subsystem */
+extern int SDL_KeyboardInit(void);
+
+/* Clear the state of the keyboard */
+extern void SDL_ResetKeyboard(void);
+
+/* Get the default keymap */
+extern void SDL_GetDefaultKeymap(SDL_Keycode * keymap);
+
+/* Set the mapping of scancode to key codes */
+extern void SDL_SetKeymap(int start, SDL_Keycode * keys, int length);
+
+/* Set a platform-dependent key name, overriding the default platform-agnostic
+ name. Encoded as UTF-8. The string is not copied, thus the pointer given to
+ this function must stay valid forever (or at least until the call to
+ VideoQuit()). */
+extern void SDL_SetScancodeName(SDL_Scancode scancode, const char *name);
+
+/* Set the keyboard focus window */
+extern void SDL_SetKeyboardFocus(SDL_Window * window);
+
+/* Send a keyboard key event */
+extern int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode);
+
+/* Send keyboard text input */
+extern int SDL_SendKeyboardText(const char *text);
+
+/* Send editing text for selected range from start to end */
+extern int SDL_SendEditingText(const char *text, int start, int end);
+
+/* Shutdown the keyboard subsystem */
+extern void SDL_KeyboardQuit(void);
+
+/* Convert to UTF-8 */
+extern char *SDL_UCS4ToUTF8(Uint32 ch, char *dst);
+
+/* Toggle on or off pieces of the keyboard mod state. */
+extern void SDL_ToggleModState(const SDL_Keymod modstate, const SDL_bool toggle);
+
+#endif /* SDL_keyboard_c_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/SDL_mouse.c b/src/3rdparty/SDL2/src/events/SDL_mouse.c
new file mode 100644
index 0000000..4f4e62f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/SDL_mouse.c
@@ -0,0 +1,1027 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* General mouse handling code for SDL */
+
+#include "SDL_assert.h"
+#include "SDL_hints.h"
+#include "SDL_timer.h"
+#include "SDL_events.h"
+#include "SDL_events_c.h"
+#include "../video/SDL_sysvideo.h"
+
+/* #define DEBUG_MOUSE */
+
+/* The mouse state */
+static SDL_Mouse SDL_mouse;
+static Uint32 SDL_double_click_time = 500;
+static int SDL_double_click_radius = 1;
+
+static int
+SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y);
+
+static void SDLCALL
+SDL_MouseNormalSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+{
+ SDL_Mouse *mouse = (SDL_Mouse *)userdata;
+
+ if (hint && *hint) {
+ mouse->normal_speed_scale = (float)SDL_atof(hint);
+ } else {
+ mouse->normal_speed_scale = 1.0f;
+ }
+}
+
+static void SDLCALL
+SDL_MouseRelativeSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+{
+ SDL_Mouse *mouse = (SDL_Mouse *)userdata;
+
+ if (hint && *hint) {
+ mouse->relative_speed_scale = (float)SDL_atof(hint);
+ } else {
+ mouse->relative_speed_scale = 1.0f;
+ }
+}
+
+static void SDLCALL
+SDL_TouchMouseEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+{
+ SDL_Mouse *mouse = (SDL_Mouse *)userdata;
+
+ if (hint && (*hint == '0' || SDL_strcasecmp(hint, "false") == 0)) {
+ mouse->touch_mouse_events = SDL_FALSE;
+ } else {
+ mouse->touch_mouse_events = SDL_TRUE;
+ }
+}
+
+/* Public functions */
+int
+SDL_MouseInit(void)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ SDL_zerop(mouse);
+
+ SDL_AddHintCallback(SDL_HINT_MOUSE_NORMAL_SPEED_SCALE,
+ SDL_MouseNormalSpeedScaleChanged, mouse);
+
+ SDL_AddHintCallback(SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE,
+ SDL_MouseRelativeSpeedScaleChanged, mouse);
+
+ SDL_AddHintCallback(SDL_HINT_TOUCH_MOUSE_EVENTS,
+ SDL_TouchMouseEventsChanged, mouse);
+
+ mouse->cursor_shown = SDL_TRUE;
+
+ return (0);
+}
+
+void
+SDL_SetDefaultCursor(SDL_Cursor * cursor)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ mouse->def_cursor = cursor;
+ if (!mouse->cur_cursor) {
+ SDL_SetCursor(cursor);
+ }
+}
+
+SDL_Mouse *
+SDL_GetMouse(void)
+{
+ return &SDL_mouse;
+}
+
+void
+SDL_SetDoubleClickTime(Uint32 interval)
+{
+ SDL_double_click_time = interval;
+}
+
+SDL_Window *
+SDL_GetMouseFocus(void)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ return mouse->focus;
+}
+
+#if 0
+void
+SDL_ResetMouse(void)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ Uint8 i;
+
+#ifdef DEBUG_MOUSE
+ printf("Resetting mouse\n");
+#endif
+ for (i = 1; i <= sizeof(mouse->buttonstate)*8; ++i) {
+ if (mouse->buttonstate & SDL_BUTTON(i)) {
+ SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, i);
+ }
+ }
+ SDL_assert(mouse->buttonstate == 0);
+}
+#endif
+
+void
+SDL_SetMouseFocus(SDL_Window * window)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ if (mouse->focus == window) {
+ return;
+ }
+
+ /* Actually, this ends up being a bad idea, because most operating
+ systems have an implicit grab when you press the mouse button down
+ so you can drag things out of the window and then get the mouse up
+ when it happens. So, #if 0...
+ */
+#if 0
+ if (mouse->focus && !window) {
+ /* We won't get anymore mouse messages, so reset mouse state */
+ SDL_ResetMouse();
+ }
+#endif
+
+ /* See if the current window has lost focus */
+ if (mouse->focus) {
+ SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
+ }
+
+ mouse->focus = window;
+ mouse->has_position = SDL_FALSE;
+
+ if (mouse->focus) {
+ SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
+ }
+
+ /* Update cursor visibility */
+ SDL_SetCursor(NULL);
+}
+
+/* Check to see if we need to synthesize focus events */
+static SDL_bool
+SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ SDL_bool inWindow = SDL_TRUE;
+
+ if (window && ((window->flags & SDL_WINDOW_MOUSE_CAPTURE) == 0)) {
+ int w, h;
+ SDL_GetWindowSize(window, &w, &h);
+ if (x < 0 || y < 0 || x >= w || y >= h) {
+ inWindow = SDL_FALSE;
+ }
+ }
+
+/* Linux doesn't give you mouse events outside your window unless you grab
+ the pointer.
+
+ Windows doesn't give you mouse events outside your window unless you call
+ SetCapture().
+
+ Both of these are slightly scary changes, so for now we'll punt and if the
+ mouse leaves the window you'll lose mouse focus and reset button state.
+*/
+#ifdef SUPPORT_DRAG_OUTSIDE_WINDOW
+ if (!inWindow && !buttonstate) {
+#else
+ if (!inWindow) {
+#endif
+ if (window == mouse->focus) {
+#ifdef DEBUG_MOUSE
+ printf("Mouse left window, synthesizing move & focus lost event\n");
+#endif
+ SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
+ SDL_SetMouseFocus(NULL);
+ }
+ return SDL_FALSE;
+ }
+
+ if (window != mouse->focus) {
+#ifdef DEBUG_MOUSE
+ printf("Mouse entered window, synthesizing focus gain & move event\n");
+#endif
+ SDL_SetMouseFocus(window);
+ SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
+ }
+ return SDL_TRUE;
+}
+
+int
+SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y)
+{
+ if (window && !relative) {
+ SDL_Mouse *mouse = SDL_GetMouse();
+ if (!SDL_UpdateMouseFocus(window, x, y, mouse->buttonstate)) {
+ return 0;
+ }
+ }
+
+ return SDL_PrivateSendMouseMotion(window, mouseID, relative, x, y);
+}
+
+static int
+GetScaledMouseDelta(float scale, int value, float *accum)
+{
+ if (scale != 1.0f) {
+ *accum += scale * value;
+ if (*accum >= 0.0f) {
+ value = (int)SDL_floor(*accum);
+ } else {
+ value = (int)SDL_ceil(*accum);
+ }
+ *accum -= value;
+ }
+ return value;
+}
+
+static int
+SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ int posted;
+ int xrel;
+ int yrel;
+
+ if (mouseID == SDL_TOUCH_MOUSEID && !mouse->touch_mouse_events) {
+ return 0;
+ }
+
+ if (mouseID != SDL_TOUCH_MOUSEID && mouse->relative_mode_warp) {
+ int center_x = 0, center_y = 0;
+ SDL_GetWindowSize(window, &center_x, &center_y);
+ center_x /= 2;
+ center_y /= 2;
+ if (x == center_x && y == center_y) {
+ mouse->last_x = center_x;
+ mouse->last_y = center_y;
+ return 0;
+ }
+ SDL_WarpMouseInWindow(window, center_x, center_y);
+ }
+
+ if (relative) {
+ if (mouse->relative_mode) {
+ x = GetScaledMouseDelta(mouse->relative_speed_scale, x, &mouse->scale_accum_x);
+ y = GetScaledMouseDelta(mouse->relative_speed_scale, y, &mouse->scale_accum_y);
+ } else {
+ x = GetScaledMouseDelta(mouse->normal_speed_scale, x, &mouse->scale_accum_x);
+ y = GetScaledMouseDelta(mouse->normal_speed_scale, y, &mouse->scale_accum_y);
+ }
+ xrel = x;
+ yrel = y;
+ x = (mouse->last_x + xrel);
+ y = (mouse->last_y + yrel);
+ } else {
+ xrel = x - mouse->last_x;
+ yrel = y - mouse->last_y;
+ }
+
+ /* Drop events that don't change state */
+ if (!xrel && !yrel) {
+#ifdef DEBUG_MOUSE
+ printf("Mouse event didn't change state - dropped!\n");
+#endif
+ return 0;
+ }
+
+ /* Ignore relative motion when first positioning the mouse */
+ if (!mouse->has_position) {
+ xrel = 0;
+ yrel = 0;
+ mouse->has_position = SDL_TRUE;
+ }
+
+ /* Ignore relative motion positioning the first touch */
+ if (mouseID == SDL_TOUCH_MOUSEID && !mouse->buttonstate) {
+ xrel = 0;
+ yrel = 0;
+ }
+
+ /* Update internal mouse coordinates */
+ if (!mouse->relative_mode) {
+ mouse->x = x;
+ mouse->y = y;
+ } else {
+ mouse->x += xrel;
+ mouse->y += yrel;
+ }
+
+ /* make sure that the pointers find themselves inside the windows,
+ unless we have the mouse captured. */
+ if (window && ((window->flags & SDL_WINDOW_MOUSE_CAPTURE) == 0)) {
+ int x_max = 0, y_max = 0;
+
+ /* !!! FIXME: shouldn't this be (window) instead of (mouse->focus)? */
+ SDL_GetWindowSize(mouse->focus, &x_max, &y_max);
+ --x_max;
+ --y_max;
+
+ if (mouse->x > x_max) {
+ mouse->x = x_max;
+ }
+ if (mouse->x < 0) {
+ mouse->x = 0;
+ }
+
+ if (mouse->y > y_max) {
+ mouse->y = y_max;
+ }
+ if (mouse->y < 0) {
+ mouse->y = 0;
+ }
+ }
+
+ mouse->xdelta += xrel;
+ mouse->ydelta += yrel;
+
+ /* Move the mouse cursor, if needed */
+ if (mouse->cursor_shown && !mouse->relative_mode &&
+ mouse->MoveCursor && mouse->cur_cursor) {
+ mouse->MoveCursor(mouse->cur_cursor);
+ }
+
+ /* Post the event, if desired */
+ posted = 0;
+ if (SDL_GetEventState(SDL_MOUSEMOTION) == SDL_ENABLE) {
+ SDL_Event event;
+ event.motion.type = SDL_MOUSEMOTION;
+ event.motion.windowID = mouse->focus ? mouse->focus->id : 0;
+ event.motion.which = mouseID;
+ event.motion.state = mouse->buttonstate;
+ event.motion.x = mouse->x;
+ event.motion.y = mouse->y;
+ event.motion.xrel = xrel;
+ event.motion.yrel = yrel;
+ posted = (SDL_PushEvent(&event) > 0);
+ }
+ if (relative) {
+ mouse->last_x = mouse->x;
+ mouse->last_y = mouse->y;
+ } else {
+ /* Use unclamped values if we're getting events outside the window */
+ mouse->last_x = x;
+ mouse->last_y = y;
+ }
+ return posted;
+}
+
+static SDL_MouseClickState *GetMouseClickState(SDL_Mouse *mouse, Uint8 button)
+{
+ if (button >= mouse->num_clickstates) {
+ int i, count = button + 1;
+ SDL_MouseClickState *clickstate = (SDL_MouseClickState *)SDL_realloc(mouse->clickstate, count * sizeof(*mouse->clickstate));
+ if (!clickstate) {
+ return NULL;
+ }
+ mouse->clickstate = clickstate;
+
+ for (i = mouse->num_clickstates; i < count; ++i) {
+ SDL_zero(mouse->clickstate[i]);
+ }
+ mouse->num_clickstates = count;
+ }
+ return &mouse->clickstate[button];
+}
+
+static int
+SDL_PrivateSendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ int posted;
+ Uint32 type;
+ Uint32 buttonstate = mouse->buttonstate;
+
+ if (mouseID == SDL_TOUCH_MOUSEID && !mouse->touch_mouse_events) {
+ return 0;
+ }
+
+ /* Figure out which event to perform */
+ switch (state) {
+ case SDL_PRESSED:
+ type = SDL_MOUSEBUTTONDOWN;
+ buttonstate |= SDL_BUTTON(button);
+ break;
+ case SDL_RELEASED:
+ type = SDL_MOUSEBUTTONUP;
+ buttonstate &= ~SDL_BUTTON(button);
+ break;
+ default:
+ /* Invalid state -- bail */
+ return 0;
+ }
+
+ /* We do this after calculating buttonstate so button presses gain focus */
+ if (window && state == SDL_PRESSED) {
+ SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
+ }
+
+ if (buttonstate == mouse->buttonstate) {
+ /* Ignore this event, no state change */
+ return 0;
+ }
+ mouse->buttonstate = buttonstate;
+
+ if (clicks < 0) {
+ SDL_MouseClickState *clickstate = GetMouseClickState(mouse, button);
+ if (clickstate) {
+ if (state == SDL_PRESSED) {
+ Uint32 now = SDL_GetTicks();
+
+ if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + SDL_double_click_time) ||
+ SDL_abs(mouse->x - clickstate->last_x) > SDL_double_click_radius ||
+ SDL_abs(mouse->y - clickstate->last_y) > SDL_double_click_radius) {
+ clickstate->click_count = 0;
+ }
+ clickstate->last_timestamp = now;
+ clickstate->last_x = mouse->x;
+ clickstate->last_y = mouse->y;
+ if (clickstate->click_count < 255) {
+ ++clickstate->click_count;
+ }
+ }
+ clicks = clickstate->click_count;
+ } else {
+ clicks = 1;
+ }
+ }
+
+ /* Post the event, if desired */
+ posted = 0;
+ if (SDL_GetEventState(type) == SDL_ENABLE) {
+ SDL_Event event;
+ event.type = type;
+ event.button.windowID = mouse->focus ? mouse->focus->id : 0;
+ event.button.which = mouseID;
+ event.button.state = state;
+ event.button.button = button;
+ event.button.clicks = (Uint8) SDL_min(clicks, 255);
+ event.button.x = mouse->x;
+ event.button.y = mouse->y;
+ posted = (SDL_PushEvent(&event) > 0);
+ }
+
+ /* We do this after dispatching event so button releases can lose focus */
+ if (window && state == SDL_RELEASED) {
+ SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
+ }
+
+ return posted;
+}
+
+int
+SDL_SendMouseButtonClicks(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
+{
+ clicks = SDL_max(clicks, 0);
+ return SDL_PrivateSendMouseButton(window, mouseID, state, button, clicks);
+}
+
+int
+SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
+{
+ return SDL_PrivateSendMouseButton(window, mouseID, state, button, -1);
+}
+
+int
+SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ int posted;
+ int integral_x, integral_y;
+
+ if (window) {
+ SDL_SetMouseFocus(window);
+ }
+
+ if (!x && !y) {
+ return 0;
+ }
+
+ mouse->accumulated_wheel_x += x;
+ if (mouse->accumulated_wheel_x > 0) {
+ integral_x = (int)SDL_floor(mouse->accumulated_wheel_x);
+ } else if (mouse->accumulated_wheel_x < 0) {
+ integral_x = (int)SDL_ceil(mouse->accumulated_wheel_x);
+ } else {
+ integral_x = 0;
+ }
+ mouse->accumulated_wheel_x -= integral_x;
+
+ mouse->accumulated_wheel_y += y;
+ if (mouse->accumulated_wheel_y > 0) {
+ integral_y = (int)SDL_floor(mouse->accumulated_wheel_y);
+ } else if (mouse->accumulated_wheel_y < 0) {
+ integral_y = (int)SDL_ceil(mouse->accumulated_wheel_y);
+ } else {
+ integral_y = 0;
+ }
+ mouse->accumulated_wheel_y -= integral_y;
+
+ /* Post the event, if desired */
+ posted = 0;
+ if (SDL_GetEventState(SDL_MOUSEWHEEL) == SDL_ENABLE) {
+ SDL_Event event;
+ event.type = SDL_MOUSEWHEEL;
+ event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
+ event.wheel.which = mouseID;
+#if 0 /* Uncomment this when it goes in for SDL 2.1 */
+ event.wheel.preciseX = x;
+ event.wheel.preciseY = y;
+#endif
+ event.wheel.x = integral_x;
+ event.wheel.y = integral_y;
+ event.wheel.direction = (Uint32)direction;
+ posted = (SDL_PushEvent(&event) > 0);
+ }
+ return posted;
+}
+
+void
+SDL_MouseQuit(void)
+{
+ SDL_Cursor *cursor, *next;
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ if (mouse->CaptureMouse) {
+ SDL_CaptureMouse(SDL_FALSE);
+ }
+ SDL_SetRelativeMouseMode(SDL_FALSE);
+ SDL_ShowCursor(1);
+
+ cursor = mouse->cursors;
+ while (cursor) {
+ next = cursor->next;
+ SDL_FreeCursor(cursor);
+ cursor = next;
+ }
+ mouse->cursors = NULL;
+
+ if (mouse->def_cursor && mouse->FreeCursor) {
+ mouse->FreeCursor(mouse->def_cursor);
+ mouse->def_cursor = NULL;
+ }
+
+ if (mouse->clickstate) {
+ SDL_free(mouse->clickstate);
+ mouse->clickstate = NULL;
+ }
+
+ SDL_DelHintCallback(SDL_HINT_MOUSE_NORMAL_SPEED_SCALE,
+ SDL_MouseNormalSpeedScaleChanged, mouse);
+
+ SDL_DelHintCallback(SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE,
+ SDL_MouseRelativeSpeedScaleChanged, mouse);
+}
+
+Uint32
+SDL_GetMouseState(int *x, int *y)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ if (x) {
+ *x = mouse->x;
+ }
+ if (y) {
+ *y = mouse->y;
+ }
+ return mouse->buttonstate;
+}
+
+Uint32
+SDL_GetRelativeMouseState(int *x, int *y)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ if (x) {
+ *x = mouse->xdelta;
+ }
+ if (y) {
+ *y = mouse->ydelta;
+ }
+ mouse->xdelta = 0;
+ mouse->ydelta = 0;
+ return mouse->buttonstate;
+}
+
+Uint32
+SDL_GetGlobalMouseState(int *x, int *y)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ int tmpx, tmpy;
+
+ /* make sure these are never NULL for the backend implementations... */
+ if (!x) {
+ x = &tmpx;
+ }
+ if (!y) {
+ y = &tmpy;
+ }
+
+ *x = *y = 0;
+
+ if (!mouse->GetGlobalMouseState) {
+ return 0;
+ }
+
+ return mouse->GetGlobalMouseState(x, y);
+}
+
+void
+SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ if (window == NULL) {
+ window = mouse->focus;
+ }
+
+ if (window == NULL) {
+ return;
+ }
+
+ if (mouse->WarpMouse) {
+ mouse->WarpMouse(window, x, y);
+ } else {
+ SDL_SendMouseMotion(window, mouse->mouseID, 0, x, y);
+ }
+}
+
+int
+SDL_WarpMouseGlobal(int x, int y)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ if (mouse->WarpMouseGlobal) {
+ return mouse->WarpMouseGlobal(x, y);
+ }
+
+ return SDL_Unsupported();
+}
+
+static SDL_bool
+ShouldUseRelativeModeWarp(SDL_Mouse *mouse)
+{
+ if (!mouse->SetRelativeMouseMode) {
+ return SDL_TRUE;
+ }
+
+ return SDL_GetHintBoolean(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, SDL_FALSE);
+}
+
+int
+SDL_SetRelativeMouseMode(SDL_bool enabled)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ SDL_Window *focusWindow = SDL_GetKeyboardFocus();
+
+ if (enabled == mouse->relative_mode) {
+ return 0;
+ }
+
+ if (enabled && focusWindow) {
+ /* Center it in the focused window to prevent clicks from going through
+ * to background windows.
+ */
+ SDL_SetMouseFocus(focusWindow);
+ SDL_WarpMouseInWindow(focusWindow, focusWindow->w/2, focusWindow->h/2);
+ }
+
+ /* Set the relative mode */
+ if (!enabled && mouse->relative_mode_warp) {
+ mouse->relative_mode_warp = SDL_FALSE;
+ } else if (enabled && ShouldUseRelativeModeWarp(mouse)) {
+ mouse->relative_mode_warp = SDL_TRUE;
+ } else if (mouse->SetRelativeMouseMode(enabled) < 0) {
+ if (enabled) {
+ /* Fall back to warp mode if native relative mode failed */
+ mouse->relative_mode_warp = SDL_TRUE;
+ }
+ }
+ mouse->relative_mode = enabled;
+ mouse->scale_accum_x = 0.0f;
+ mouse->scale_accum_y = 0.0f;
+
+ if (mouse->focus) {
+ SDL_UpdateWindowGrab(mouse->focus);
+
+ /* Put the cursor back to where the application expects it */
+ if (!enabled) {
+ SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
+ }
+ }
+
+ /* Flush pending mouse motion - ideally we would pump events, but that's not always safe */
+ SDL_FlushEvent(SDL_MOUSEMOTION);
+
+ /* Update cursor visibility */
+ SDL_SetCursor(NULL);
+
+ return 0;
+}
+
+SDL_bool
+SDL_GetRelativeMouseMode()
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ return mouse->relative_mode;
+}
+
+int
+SDL_CaptureMouse(SDL_bool enabled)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ SDL_Window *focusWindow;
+ SDL_bool isCaptured;
+
+ if (!mouse->CaptureMouse) {
+ return SDL_Unsupported();
+ }
+
+ focusWindow = SDL_GetKeyboardFocus();
+
+ isCaptured = focusWindow && (focusWindow->flags & SDL_WINDOW_MOUSE_CAPTURE);
+ if (isCaptured == enabled) {
+ return 0; /* already done! */
+ }
+
+ if (enabled) {
+ if (!focusWindow) {
+ return SDL_SetError("No window has focus");
+ } else if (mouse->CaptureMouse(focusWindow) == -1) {
+ return -1; /* CaptureMouse() should call SetError */
+ }
+ focusWindow->flags |= SDL_WINDOW_MOUSE_CAPTURE;
+ } else {
+ if (mouse->CaptureMouse(NULL) == -1) {
+ return -1; /* CaptureMouse() should call SetError */
+ }
+ focusWindow->flags &= ~SDL_WINDOW_MOUSE_CAPTURE;
+ }
+
+ return 0;
+}
+
+SDL_Cursor *
+SDL_CreateCursor(const Uint8 * data, const Uint8 * mask,
+ int w, int h, int hot_x, int hot_y)
+{
+ SDL_Surface *surface;
+ SDL_Cursor *cursor;
+ int x, y;
+ Uint32 *pixel;
+ Uint8 datab = 0, maskb = 0;
+ const Uint32 black = 0xFF000000;
+ const Uint32 white = 0xFFFFFFFF;
+ const Uint32 transparent = 0x00000000;
+
+ /* Make sure the width is a multiple of 8 */
+ w = ((w + 7) & ~7);
+
+ /* Create the surface from a bitmap */
+ surface = SDL_CreateRGBSurface(0, w, h, 32,
+ 0x00FF0000,
+ 0x0000FF00,
+ 0x000000FF,
+ 0xFF000000);
+ if (!surface) {
+ return NULL;
+ }
+ for (y = 0; y < h; ++y) {
+ pixel = (Uint32 *) ((Uint8 *) surface->pixels + y * surface->pitch);
+ for (x = 0; x < w; ++x) {
+ if ((x % 8) == 0) {
+ datab = *data++;
+ maskb = *mask++;
+ }
+ if (maskb & 0x80) {
+ *pixel++ = (datab & 0x80) ? black : white;
+ } else {
+ *pixel++ = (datab & 0x80) ? black : transparent;
+ }
+ datab <<= 1;
+ maskb <<= 1;
+ }
+ }
+
+ cursor = SDL_CreateColorCursor(surface, hot_x, hot_y);
+
+ SDL_FreeSurface(surface);
+
+ return cursor;
+}
+
+SDL_Cursor *
+SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ SDL_Surface *temp = NULL;
+ SDL_Cursor *cursor;
+
+ if (!surface) {
+ SDL_SetError("Passed NULL cursor surface");
+ return NULL;
+ }
+
+ if (!mouse->CreateCursor) {
+ SDL_SetError("Cursors are not currently supported");
+ return NULL;
+ }
+
+ /* Sanity check the hot spot */
+ if ((hot_x < 0) || (hot_y < 0) ||
+ (hot_x >= surface->w) || (hot_y >= surface->h)) {
+ SDL_SetError("Cursor hot spot doesn't lie within cursor");
+ return NULL;
+ }
+
+ if (surface->format->format != SDL_PIXELFORMAT_ARGB8888) {
+ temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888, 0);
+ if (!temp) {
+ return NULL;
+ }
+ surface = temp;
+ }
+
+ cursor = mouse->CreateCursor(surface, hot_x, hot_y);
+ if (cursor) {
+ cursor->next = mouse->cursors;
+ mouse->cursors = cursor;
+ }
+
+ SDL_FreeSurface(temp);
+
+ return cursor;
+}
+
+SDL_Cursor *
+SDL_CreateSystemCursor(SDL_SystemCursor id)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ SDL_Cursor *cursor;
+
+ if (!mouse->CreateSystemCursor) {
+ SDL_SetError("CreateSystemCursor is not currently supported");
+ return NULL;
+ }
+
+ cursor = mouse->CreateSystemCursor(id);
+ if (cursor) {
+ cursor->next = mouse->cursors;
+ mouse->cursors = cursor;
+ }
+
+ return cursor;
+}
+
+/* SDL_SetCursor(NULL) can be used to force the cursor redraw,
+ if this is desired for any reason. This is used when setting
+ the video mode and when the SDL window gains the mouse focus.
+ */
+void
+SDL_SetCursor(SDL_Cursor * cursor)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ /* Set the new cursor */
+ if (cursor) {
+ /* Make sure the cursor is still valid for this mouse */
+ if (cursor != mouse->def_cursor) {
+ SDL_Cursor *found;
+ for (found = mouse->cursors; found; found = found->next) {
+ if (found == cursor) {
+ break;
+ }
+ }
+ if (!found) {
+ SDL_SetError("Cursor not associated with the current mouse");
+ return;
+ }
+ }
+ mouse->cur_cursor = cursor;
+ } else {
+ if (mouse->focus) {
+ cursor = mouse->cur_cursor;
+ } else {
+ cursor = mouse->def_cursor;
+ }
+ }
+
+ if (cursor && mouse->cursor_shown && !mouse->relative_mode) {
+ if (mouse->ShowCursor) {
+ mouse->ShowCursor(cursor);
+ }
+ } else {
+ if (mouse->ShowCursor) {
+ mouse->ShowCursor(NULL);
+ }
+ }
+}
+
+SDL_Cursor *
+SDL_GetCursor(void)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ if (!mouse) {
+ return NULL;
+ }
+ return mouse->cur_cursor;
+}
+
+SDL_Cursor *
+SDL_GetDefaultCursor(void)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ if (!mouse) {
+ return NULL;
+ }
+ return mouse->def_cursor;
+}
+
+void
+SDL_FreeCursor(SDL_Cursor * cursor)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ SDL_Cursor *curr, *prev;
+
+ if (!cursor) {
+ return;
+ }
+
+ if (cursor == mouse->def_cursor) {
+ return;
+ }
+ if (cursor == mouse->cur_cursor) {
+ SDL_SetCursor(mouse->def_cursor);
+ }
+
+ for (prev = NULL, curr = mouse->cursors; curr;
+ prev = curr, curr = curr->next) {
+ if (curr == cursor) {
+ if (prev) {
+ prev->next = curr->next;
+ } else {
+ mouse->cursors = curr->next;
+ }
+
+ if (mouse->FreeCursor) {
+ mouse->FreeCursor(curr);
+ }
+ return;
+ }
+ }
+}
+
+int
+SDL_ShowCursor(int toggle)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ SDL_bool shown;
+
+ if (!mouse) {
+ return 0;
+ }
+
+ shown = mouse->cursor_shown;
+ if (toggle >= 0) {
+ if (toggle) {
+ mouse->cursor_shown = SDL_TRUE;
+ } else {
+ mouse->cursor_shown = SDL_FALSE;
+ }
+ if (mouse->cursor_shown != shown) {
+ SDL_SetCursor(NULL);
+ }
+ }
+ return shown;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/SDL_mouse_c.h b/src/3rdparty/SDL2/src/events/SDL_mouse_c.h
new file mode 100644
index 0000000..28089e0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/SDL_mouse_c.h
@@ -0,0 +1,141 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#ifndef SDL_mouse_c_h_
+#define SDL_mouse_c_h_
+
+#include "SDL_mouse.h"
+
+typedef Uint32 SDL_MouseID;
+
+struct SDL_Cursor
+{
+ struct SDL_Cursor *next;
+ void *driverdata;
+};
+
+typedef struct
+{
+ int last_x, last_y;
+ Uint32 last_timestamp;
+ Uint8 click_count;
+} SDL_MouseClickState;
+
+typedef struct
+{
+ /* Create a cursor from a surface */
+ SDL_Cursor *(*CreateCursor) (SDL_Surface * surface, int hot_x, int hot_y);
+
+ /* Create a system cursor */
+ SDL_Cursor *(*CreateSystemCursor) (SDL_SystemCursor id);
+
+ /* Show the specified cursor, or hide if cursor is NULL */
+ int (*ShowCursor) (SDL_Cursor * cursor);
+
+ /* This is called when a mouse motion event occurs */
+ void (*MoveCursor) (SDL_Cursor * cursor);
+
+ /* Free a window manager cursor */
+ void (*FreeCursor) (SDL_Cursor * cursor);
+
+ /* Warp the mouse to (x,y) within a window */
+ void (*WarpMouse) (SDL_Window * window, int x, int y);
+
+ /* Warp the mouse to (x,y) in screen space */
+ int (*WarpMouseGlobal) (int x, int y);
+
+ /* Set relative mode */
+ int (*SetRelativeMouseMode) (SDL_bool enabled);
+
+ /* Set mouse capture */
+ int (*CaptureMouse) (SDL_Window * window);
+
+ /* Get absolute mouse coordinates. (x) and (y) are never NULL and set to zero before call. */
+ Uint32 (*GetGlobalMouseState) (int *x, int *y);
+
+ /* Data common to all mice */
+ SDL_MouseID mouseID;
+ SDL_Window *focus;
+ int x;
+ int y;
+ int xdelta;
+ int ydelta;
+ int last_x, last_y; /* the last reported x and y coordinates */
+ float accumulated_wheel_x;
+ float accumulated_wheel_y;
+ Uint32 buttonstate;
+ SDL_bool has_position;
+ SDL_bool relative_mode;
+ SDL_bool relative_mode_warp;
+ float normal_speed_scale;
+ float relative_speed_scale;
+ float scale_accum_x;
+ float scale_accum_y;
+ SDL_bool touch_mouse_events;
+
+ /* Data for double-click tracking */
+ int num_clickstates;
+ SDL_MouseClickState *clickstate;
+
+ SDL_Cursor *cursors;
+ SDL_Cursor *def_cursor;
+ SDL_Cursor *cur_cursor;
+ SDL_bool cursor_shown;
+
+ /* Driver-dependent data. */
+ void *driverdata;
+} SDL_Mouse;
+
+
+/* Initialize the mouse subsystem */
+extern int SDL_MouseInit(void);
+
+/* Get the mouse state structure */
+SDL_Mouse *SDL_GetMouse(void);
+
+/* Set the default double-click interval */
+extern void SDL_SetDoubleClickTime(Uint32 interval);
+
+/* Set the default mouse cursor */
+extern void SDL_SetDefaultCursor(SDL_Cursor * cursor);
+
+/* Set the mouse focus window */
+extern void SDL_SetMouseFocus(SDL_Window * window);
+
+/* Send a mouse motion event */
+extern int SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y);
+
+/* Send a mouse button event */
+extern int SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button);
+
+/* Send a mouse button event with a click count */
+extern int SDL_SendMouseButtonClicks(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks);
+
+/* Send a mouse wheel event */
+extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction);
+
+/* Shutdown the mouse subsystem */
+extern void SDL_MouseQuit(void);
+
+#endif /* SDL_mouse_c_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/SDL_quit.c b/src/3rdparty/SDL2/src/events/SDL_quit.c
new file mode 100644
index 0000000..2b24efe
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/SDL_quit.c
@@ -0,0 +1,152 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+#include "SDL_hints.h"
+#include "SDL_assert.h"
+
+/* General quit handling code for SDL */
+
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
+
+#include "SDL_events.h"
+#include "SDL_events_c.h"
+
+static SDL_bool disable_signals = SDL_FALSE;
+static SDL_bool send_quit_pending = SDL_FALSE;
+
+#ifdef HAVE_SIGNAL_H
+static void
+SDL_HandleSIG(int sig)
+{
+ /* Reset the signal handler */
+ signal(sig, SDL_HandleSIG);
+
+ /* Send a quit event next time the event loop pumps. */
+ /* We can't send it in signal handler; malloc() might be interrupted! */
+ send_quit_pending = SDL_TRUE;
+}
+#endif /* HAVE_SIGNAL_H */
+
+/* Public functions */
+static int
+SDL_QuitInit_Internal(void)
+{
+#ifdef HAVE_SIGACTION
+ struct sigaction action;
+ sigaction(SIGINT, NULL, &action);
+#ifdef HAVE_SA_SIGACTION
+ if ( action.sa_handler == SIG_DFL && (void (*)(int))action.sa_sigaction == SIG_DFL ) {
+#else
+ if ( action.sa_handler == SIG_DFL ) {
+#endif
+ action.sa_handler = SDL_HandleSIG;
+ sigaction(SIGINT, &action, NULL);
+ }
+ sigaction(SIGTERM, NULL, &action);
+
+#ifdef HAVE_SA_SIGACTION
+ if ( action.sa_handler == SIG_DFL && (void (*)(int))action.sa_sigaction == SIG_DFL ) {
+#else
+ if ( action.sa_handler == SIG_DFL ) {
+#endif
+ action.sa_handler = SDL_HandleSIG;
+ sigaction(SIGTERM, &action, NULL);
+ }
+#elif HAVE_SIGNAL_H
+ void (*ohandler) (int);
+
+ /* Both SIGINT and SIGTERM are translated into quit interrupts */
+ ohandler = signal(SIGINT, SDL_HandleSIG);
+ if (ohandler != SIG_DFL)
+ signal(SIGINT, ohandler);
+ ohandler = signal(SIGTERM, SDL_HandleSIG);
+ if (ohandler != SIG_DFL)
+ signal(SIGTERM, ohandler);
+#endif /* HAVE_SIGNAL_H */
+
+ /* That's it! */
+ return 0;
+}
+
+int
+SDL_QuitInit(void)
+{
+ if (!SDL_GetHintBoolean(SDL_HINT_NO_SIGNAL_HANDLERS, SDL_FALSE)) {
+ return SDL_QuitInit_Internal();
+ }
+ return 0;
+}
+
+static void
+SDL_QuitQuit_Internal(void)
+{
+#ifdef HAVE_SIGACTION
+ struct sigaction action;
+ sigaction(SIGINT, NULL, &action);
+ if ( action.sa_handler == SDL_HandleSIG ) {
+ action.sa_handler = SIG_DFL;
+ sigaction(SIGINT, &action, NULL);
+ }
+ sigaction(SIGTERM, NULL, &action);
+ if ( action.sa_handler == SDL_HandleSIG ) {
+ action.sa_handler = SIG_DFL;
+ sigaction(SIGTERM, &action, NULL);
+ }
+#elif HAVE_SIGNAL_H
+ void (*ohandler) (int);
+
+ ohandler = signal(SIGINT, SIG_DFL);
+ if (ohandler != SDL_HandleSIG)
+ signal(SIGINT, ohandler);
+ ohandler = signal(SIGTERM, SIG_DFL);
+ if (ohandler != SDL_HandleSIG)
+ signal(SIGTERM, ohandler);
+#endif /* HAVE_SIGNAL_H */
+}
+
+void
+SDL_QuitQuit(void)
+{
+ if (!disable_signals) {
+ SDL_QuitQuit_Internal();
+ }
+}
+
+/* This function returns 1 if it's okay to close the application window */
+int
+SDL_SendQuit(void)
+{
+ send_quit_pending = SDL_FALSE;
+ return SDL_SendAppEvent(SDL_QUIT);
+}
+
+void
+SDL_SendPendingQuit(void)
+{
+ if (send_quit_pending) {
+ SDL_SendQuit();
+ SDL_assert(!send_quit_pending);
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/SDL_sysevents.h b/src/3rdparty/SDL2/src/events/SDL_sysevents.h
new file mode 100644
index 0000000..3d9ab92
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/SDL_sysevents.h
@@ -0,0 +1,36 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "../video/SDL_sysvideo.h"
+
+/* Useful functions and variables from SDL_sysevents.c */
+
+#if defined(__HAIKU__)
+/* The Haiku event loops run in a separate thread */
+#define MUST_THREAD_EVENTS
+#endif
+
+#ifdef __WIN32__ /* Windows doesn't allow a separate event thread */
+#define CANT_THREAD_EVENTS
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/SDL_touch.c b/src/3rdparty/SDL2/src/events/SDL_touch.c
new file mode 100644
index 0000000..0037416
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/SDL_touch.c
@@ -0,0 +1,375 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* General touch handling code for SDL */
+
+#include "SDL_assert.h"
+#include "SDL_events.h"
+#include "SDL_events_c.h"
+#include "../video/SDL_sysvideo.h"
+
+
+static int SDL_num_touch = 0;
+static SDL_Touch **SDL_touchDevices = NULL;
+
+
+/* Public functions */
+int
+SDL_TouchInit(void)
+{
+ return (0);
+}
+
+int
+SDL_GetNumTouchDevices(void)
+{
+ return SDL_num_touch;
+}
+
+SDL_TouchID
+SDL_GetTouchDevice(int index)
+{
+ if (index < 0 || index >= SDL_num_touch) {
+ SDL_SetError("Unknown touch device index %d", index);
+ return 0;
+ }
+ return SDL_touchDevices[index]->id;
+}
+
+static int
+SDL_GetTouchIndex(SDL_TouchID id)
+{
+ int index;
+ SDL_Touch *touch;
+
+ for (index = 0; index < SDL_num_touch; ++index) {
+ touch = SDL_touchDevices[index];
+ if (touch->id == id) {
+ return index;
+ }
+ }
+ return -1;
+}
+
+SDL_Touch *
+SDL_GetTouch(SDL_TouchID id)
+{
+ int index = SDL_GetTouchIndex(id);
+ if (index < 0 || index >= SDL_num_touch) {
+ if (SDL_GetVideoDevice()->ResetTouch != NULL) {
+ SDL_SetError("Unknown touch id %d, resetting", (int) id);
+ (SDL_GetVideoDevice()->ResetTouch)(SDL_GetVideoDevice());
+ } else {
+ SDL_SetError("Unknown touch device id %d, cannot reset", (int) id);
+ }
+ return NULL;
+ }
+ return SDL_touchDevices[index];
+}
+
+static int
+SDL_GetFingerIndex(const SDL_Touch * touch, SDL_FingerID fingerid)
+{
+ int index;
+ for (index = 0; index < touch->num_fingers; ++index) {
+ if (touch->fingers[index]->id == fingerid) {
+ return index;
+ }
+ }
+ return -1;
+}
+
+static SDL_Finger *
+SDL_GetFinger(const SDL_Touch * touch, SDL_FingerID id)
+{
+ int index = SDL_GetFingerIndex(touch, id);
+ if (index < 0 || index >= touch->num_fingers) {
+ return NULL;
+ }
+ return touch->fingers[index];
+}
+
+int
+SDL_GetNumTouchFingers(SDL_TouchID touchID)
+{
+ SDL_Touch *touch = SDL_GetTouch(touchID);
+ if (touch) {
+ return touch->num_fingers;
+ }
+ return 0;
+}
+
+SDL_Finger *
+SDL_GetTouchFinger(SDL_TouchID touchID, int index)
+{
+ SDL_Touch *touch = SDL_GetTouch(touchID);
+ if (!touch) {
+ return NULL;
+ }
+ if (index < 0 || index >= touch->num_fingers) {
+ SDL_SetError("Unknown touch finger");
+ return NULL;
+ }
+ return touch->fingers[index];
+}
+
+int
+SDL_AddTouch(SDL_TouchID touchID, const char *name)
+{
+ SDL_Touch **touchDevices;
+ int index;
+
+ index = SDL_GetTouchIndex(touchID);
+ if (index >= 0) {
+ return index;
+ }
+
+ /* Add the touch to the list of touch */
+ touchDevices = (SDL_Touch **) SDL_realloc(SDL_touchDevices,
+ (SDL_num_touch + 1) * sizeof(*touchDevices));
+ if (!touchDevices) {
+ return SDL_OutOfMemory();
+ }
+
+ SDL_touchDevices = touchDevices;
+ index = SDL_num_touch;
+
+ SDL_touchDevices[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchDevices[index]));
+ if (!SDL_touchDevices[index]) {
+ return SDL_OutOfMemory();
+ }
+
+ /* Added touch to list */
+ ++SDL_num_touch;
+
+ /* we're setting the touch properties */
+ SDL_touchDevices[index]->id = touchID;
+ SDL_touchDevices[index]->num_fingers = 0;
+ SDL_touchDevices[index]->max_fingers = 0;
+ SDL_touchDevices[index]->fingers = NULL;
+
+ /* Record this touch device for gestures */
+ /* We could do this on the fly in the gesture code if we wanted */
+ SDL_GestureAddTouch(touchID);
+
+ return index;
+}
+
+static int
+SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float y, float pressure)
+{
+ SDL_Finger *finger;
+
+ if (touch->num_fingers == touch->max_fingers) {
+ SDL_Finger **new_fingers;
+ new_fingers = (SDL_Finger **)SDL_realloc(touch->fingers, (touch->max_fingers+1)*sizeof(*touch->fingers));
+ if (!new_fingers) {
+ return SDL_OutOfMemory();
+ }
+ touch->fingers = new_fingers;
+ touch->fingers[touch->max_fingers] = (SDL_Finger *)SDL_malloc(sizeof(*finger));
+ if (!touch->fingers[touch->max_fingers]) {
+ return SDL_OutOfMemory();
+ }
+ touch->max_fingers++;
+ }
+
+ finger = touch->fingers[touch->num_fingers++];
+ finger->id = fingerid;
+ finger->x = x;
+ finger->y = y;
+ finger->pressure = pressure;
+ return 0;
+}
+
+static int
+SDL_DelFinger(SDL_Touch* touch, SDL_FingerID fingerid)
+{
+ SDL_Finger *temp;
+
+ int index = SDL_GetFingerIndex(touch, fingerid);
+ if (index < 0) {
+ return -1;
+ }
+
+ touch->num_fingers--;
+ temp = touch->fingers[index];
+ touch->fingers[index] = touch->fingers[touch->num_fingers];
+ touch->fingers[touch->num_fingers] = temp;
+ return 0;
+}
+
+int
+SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid,
+ SDL_bool down, float x, float y, float pressure)
+{
+ int posted;
+ SDL_Finger *finger;
+
+ SDL_Touch* touch = SDL_GetTouch(id);
+ if (!touch) {
+ return -1;
+ }
+
+ finger = SDL_GetFinger(touch, fingerid);
+ if (down) {
+ if (finger) {
+ /* This finger is already down */
+ return 0;
+ }
+
+ if (SDL_AddFinger(touch, fingerid, x, y, pressure) < 0) {
+ return 0;
+ }
+
+ posted = 0;
+ if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
+ SDL_Event event;
+ event.tfinger.type = SDL_FINGERDOWN;
+ event.tfinger.touchId = id;
+ event.tfinger.fingerId = fingerid;
+ event.tfinger.x = x;
+ event.tfinger.y = y;
+ event.tfinger.dx = 0;
+ event.tfinger.dy = 0;
+ event.tfinger.pressure = pressure;
+ posted = (SDL_PushEvent(&event) > 0);
+ }
+ } else {
+ if (!finger) {
+ /* This finger is already up */
+ return 0;
+ }
+
+ posted = 0;
+ if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
+ SDL_Event event;
+ event.tfinger.type = SDL_FINGERUP;
+ event.tfinger.touchId = id;
+ event.tfinger.fingerId = fingerid;
+ /* I don't trust the coordinates passed on fingerUp */
+ event.tfinger.x = finger->x;
+ event.tfinger.y = finger->y;
+ event.tfinger.dx = 0;
+ event.tfinger.dy = 0;
+ event.tfinger.pressure = pressure;
+ posted = (SDL_PushEvent(&event) > 0);
+ }
+
+ SDL_DelFinger(touch, fingerid);
+ }
+ return posted;
+}
+
+int
+SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid,
+ float x, float y, float pressure)
+{
+ SDL_Touch *touch;
+ SDL_Finger *finger;
+ int posted;
+ float xrel, yrel, prel;
+
+ touch = SDL_GetTouch(id);
+ if (!touch) {
+ return -1;
+ }
+
+ finger = SDL_GetFinger(touch,fingerid);
+ if (!finger) {
+ return SDL_SendTouch(id, fingerid, SDL_TRUE, x, y, pressure);
+ }
+
+ xrel = x - finger->x;
+ yrel = y - finger->y;
+ prel = pressure - finger->pressure;
+
+ /* Drop events that don't change state */
+ if (!xrel && !yrel && !prel) {
+#if 0
+ printf("Touch event didn't change state - dropped!\n");
+#endif
+ return 0;
+ }
+
+ /* Update internal touch coordinates */
+ finger->x = x;
+ finger->y = y;
+ finger->pressure = pressure;
+
+ /* Post the event, if desired */
+ posted = 0;
+ if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
+ SDL_Event event;
+ event.tfinger.type = SDL_FINGERMOTION;
+ event.tfinger.touchId = id;
+ event.tfinger.fingerId = fingerid;
+ event.tfinger.x = x;
+ event.tfinger.y = y;
+ event.tfinger.dx = xrel;
+ event.tfinger.dy = yrel;
+ event.tfinger.pressure = pressure;
+ posted = (SDL_PushEvent(&event) > 0);
+ }
+ return posted;
+}
+
+void
+SDL_DelTouch(SDL_TouchID id)
+{
+ int i;
+ int index = SDL_GetTouchIndex(id);
+ SDL_Touch *touch = SDL_GetTouch(id);
+
+ if (!touch) {
+ return;
+ }
+
+ for (i = 0; i < touch->max_fingers; ++i) {
+ SDL_free(touch->fingers[i]);
+ }
+ SDL_free(touch->fingers);
+ SDL_free(touch);
+
+ SDL_num_touch--;
+ SDL_touchDevices[index] = SDL_touchDevices[SDL_num_touch];
+
+ /* Delete this touch device for gestures */
+ SDL_GestureDelTouch(id);
+}
+
+void
+SDL_TouchQuit(void)
+{
+ int i;
+
+ for (i = SDL_num_touch; i--; ) {
+ SDL_DelTouch(SDL_touchDevices[i]->id);
+ }
+ SDL_assert(SDL_num_touch == 0);
+
+ SDL_free(SDL_touchDevices);
+ SDL_touchDevices = NULL;
+ SDL_GestureQuit();
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/SDL_touch_c.h b/src/3rdparty/SDL2/src/events/SDL_touch_c.h
new file mode 100644
index 0000000..2a44310
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/SDL_touch_c.h
@@ -0,0 +1,61 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+#include "../../include/SDL_touch.h"
+
+#ifndef SDL_touch_c_h_
+#define SDL_touch_c_h_
+
+typedef struct SDL_Touch
+{
+ SDL_TouchID id;
+ int num_fingers;
+ int max_fingers;
+ SDL_Finger** fingers;
+} SDL_Touch;
+
+
+/* Initialize the touch subsystem */
+extern int SDL_TouchInit(void);
+
+/* Add a touch, returning the index of the touch, or -1 if there was an error. */
+extern int SDL_AddTouch(SDL_TouchID id, const char *name);
+
+/* Get the touch with a given id */
+extern SDL_Touch *SDL_GetTouch(SDL_TouchID id);
+
+/* Send a touch down/up event for a touch */
+extern int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid,
+ SDL_bool down, float x, float y, float pressure);
+
+/* Send a touch motion event for a touch */
+extern int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid,
+ float x, float y, float pressure);
+
+/* Remove a touch */
+extern void SDL_DelTouch(SDL_TouchID id);
+
+/* Shutdown the touch subsystem */
+extern void SDL_TouchQuit(void);
+
+#endif /* SDL_touch_c_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/SDL_windowevents.c b/src/3rdparty/SDL2/src/events/SDL_windowevents.c
new file mode 100644
index 0000000..610fad5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/SDL_windowevents.c
@@ -0,0 +1,228 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* Window event handling code for SDL */
+
+#include "SDL_events.h"
+#include "SDL_events_c.h"
+#include "SDL_mouse_c.h"
+#include "../video/SDL_sysvideo.h"
+
+
+static int SDLCALL
+RemovePendingResizedEvents(void * userdata, SDL_Event *event)
+{
+ SDL_Event *new_event = (SDL_Event *)userdata;
+
+ if (event->type == SDL_WINDOWEVENT &&
+ event->window.event == SDL_WINDOWEVENT_RESIZED &&
+ event->window.windowID == new_event->window.windowID) {
+ /* We're about to post a new size event, drop the old one */
+ return 0;
+ }
+ return 1;
+}
+
+static int SDLCALL
+RemovePendingSizeChangedEvents(void * userdata, SDL_Event *event)
+{
+ SDL_Event *new_event = (SDL_Event *)userdata;
+
+ if (event->type == SDL_WINDOWEVENT &&
+ event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED &&
+ event->window.windowID == new_event->window.windowID) {
+ /* We're about to post a new size event, drop the old one */
+ return 0;
+ }
+ return 1;
+}
+
+static int SDLCALL
+RemovePendingMoveEvents(void * userdata, SDL_Event *event)
+{
+ SDL_Event *new_event = (SDL_Event *)userdata;
+
+ if (event->type == SDL_WINDOWEVENT &&
+ event->window.event == SDL_WINDOWEVENT_MOVED &&
+ event->window.windowID == new_event->window.windowID) {
+ /* We're about to post a new move event, drop the old one */
+ return 0;
+ }
+ return 1;
+}
+
+static int SDLCALL
+RemovePendingExposedEvents(void * userdata, SDL_Event *event)
+{
+ SDL_Event *new_event = (SDL_Event *)userdata;
+
+ if (event->type == SDL_WINDOWEVENT &&
+ event->window.event == SDL_WINDOWEVENT_EXPOSED &&
+ event->window.windowID == new_event->window.windowID) {
+ /* We're about to post a new exposed event, drop the old one */
+ return 0;
+ }
+ return 1;
+}
+
+int
+SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,
+ int data2)
+{
+ int posted;
+
+ if (!window) {
+ return 0;
+ }
+ switch (windowevent) {
+ case SDL_WINDOWEVENT_SHOWN:
+ if (window->flags & SDL_WINDOW_SHOWN) {
+ return 0;
+ }
+ window->flags &= ~SDL_WINDOW_HIDDEN;
+ window->flags |= SDL_WINDOW_SHOWN;
+ SDL_OnWindowShown(window);
+ break;
+ case SDL_WINDOWEVENT_HIDDEN:
+ if (!(window->flags & SDL_WINDOW_SHOWN)) {
+ return 0;
+ }
+ window->flags &= ~SDL_WINDOW_SHOWN;
+ window->flags |= SDL_WINDOW_HIDDEN;
+ SDL_OnWindowHidden(window);
+ break;
+ case SDL_WINDOWEVENT_MOVED:
+ if (SDL_WINDOWPOS_ISUNDEFINED(data1) ||
+ SDL_WINDOWPOS_ISUNDEFINED(data2)) {
+ return 0;
+ }
+ if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+ window->windowed.x = data1;
+ window->windowed.y = data2;
+ }
+ if (data1 == window->x && data2 == window->y) {
+ return 0;
+ }
+ window->x = data1;
+ window->y = data2;
+ break;
+ case SDL_WINDOWEVENT_RESIZED:
+ if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+ window->windowed.w = data1;
+ window->windowed.h = data2;
+ }
+ if (data1 == window->w && data2 == window->h) {
+ return 0;
+ }
+ window->w = data1;
+ window->h = data2;
+ SDL_OnWindowResized(window);
+ break;
+ case SDL_WINDOWEVENT_MINIMIZED:
+ if (window->flags & SDL_WINDOW_MINIMIZED) {
+ return 0;
+ }
+ window->flags &= ~SDL_WINDOW_MAXIMIZED;
+ window->flags |= SDL_WINDOW_MINIMIZED;
+ SDL_OnWindowMinimized(window);
+ break;
+ case SDL_WINDOWEVENT_MAXIMIZED:
+ if (window->flags & SDL_WINDOW_MAXIMIZED) {
+ return 0;
+ }
+ window->flags &= ~SDL_WINDOW_MINIMIZED;
+ window->flags |= SDL_WINDOW_MAXIMIZED;
+ break;
+ case SDL_WINDOWEVENT_RESTORED:
+ if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
+ return 0;
+ }
+ window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
+ SDL_OnWindowRestored(window);
+ break;
+ case SDL_WINDOWEVENT_ENTER:
+ if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
+ return 0;
+ }
+ window->flags |= SDL_WINDOW_MOUSE_FOCUS;
+ SDL_OnWindowEnter(window);
+ break;
+ case SDL_WINDOWEVENT_LEAVE:
+ if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
+ return 0;
+ }
+ window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
+ SDL_OnWindowLeave(window);
+ break;
+ case SDL_WINDOWEVENT_FOCUS_GAINED:
+ if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
+ return 0;
+ }
+ window->flags |= SDL_WINDOW_INPUT_FOCUS;
+ SDL_OnWindowFocusGained(window);
+ break;
+ case SDL_WINDOWEVENT_FOCUS_LOST:
+ if (!(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
+ return 0;
+ }
+ window->flags &= ~SDL_WINDOW_INPUT_FOCUS;
+ SDL_OnWindowFocusLost(window);
+ break;
+ }
+
+ /* Post the event, if desired */
+ posted = 0;
+ if (SDL_GetEventState(SDL_WINDOWEVENT) == SDL_ENABLE) {
+ SDL_Event event;
+ event.type = SDL_WINDOWEVENT;
+ event.window.event = windowevent;
+ event.window.data1 = data1;
+ event.window.data2 = data2;
+ event.window.windowID = window->id;
+
+ /* Fixes queue overflow with resize events that aren't processed */
+ if (windowevent == SDL_WINDOWEVENT_RESIZED) {
+ SDL_FilterEvents(RemovePendingResizedEvents, &event);
+ }
+ if (windowevent == SDL_WINDOWEVENT_SIZE_CHANGED) {
+ SDL_FilterEvents(RemovePendingSizeChangedEvents, &event);
+ }
+ if (windowevent == SDL_WINDOWEVENT_MOVED) {
+ SDL_FilterEvents(RemovePendingMoveEvents, &event);
+ }
+ if (windowevent == SDL_WINDOWEVENT_EXPOSED) {
+ SDL_FilterEvents(RemovePendingExposedEvents, &event);
+ }
+ posted = (SDL_PushEvent(&event) > 0);
+ }
+
+ if (windowevent == SDL_WINDOWEVENT_CLOSE) {
+ if ( !window->prev && !window->next ) {
+ /* This is the last window in the list so send the SDL_QUIT event */
+ SDL_SendQuit();
+ }
+ }
+
+ return (posted);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/SDL_windowevents_c.h b/src/3rdparty/SDL2/src/events/SDL_windowevents_c.h
new file mode 100644
index 0000000..a529a11
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/SDL_windowevents_c.h
@@ -0,0 +1,31 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#ifndef SDL_windowevents_c_h_
+#define SDL_windowevents_c_h_
+
+extern int SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent,
+ int data1, int data2);
+
+#endif /* SDL_windowevents_c_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/blank_cursor.h b/src/3rdparty/SDL2/src/events/blank_cursor.h
new file mode 100644
index 0000000..bc1bffa
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/blank_cursor.h
@@ -0,0 +1,33 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * A default blank 8x8 cursor */
+
+#define BLANK_CWIDTH 8
+#define BLANK_CHEIGHT 8
+#define BLANK_CHOTX 0
+#define BLANK_CHOTY 0
+
+static const unsigned char blank_cdata[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+static const unsigned char blank_cmask[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/default_cursor.h b/src/3rdparty/SDL2/src/events/default_cursor.h
new file mode 100644
index 0000000..27e82ff
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/default_cursor.h
@@ -0,0 +1,114 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Default cursor - it happens to be the Mac cursor, but could be anything */
+
+#define DEFAULT_CWIDTH 16
+#define DEFAULT_CHEIGHT 16
+#define DEFAULT_CHOTX 0
+#define DEFAULT_CHOTY 0
+
+/* Added a real MacOS cursor, at the request of Luc-Olivier de Charrire */
+#define USE_MACOS_CURSOR
+
+#ifdef USE_MACOS_CURSOR
+
+static const unsigned char default_cdata[] = {
+ 0x00, 0x00,
+ 0x40, 0x00,
+ 0x60, 0x00,
+ 0x70, 0x00,
+ 0x78, 0x00,
+ 0x7C, 0x00,
+ 0x7E, 0x00,
+ 0x7F, 0x00,
+ 0x7F, 0x80,
+ 0x7C, 0x00,
+ 0x6C, 0x00,
+ 0x46, 0x00,
+ 0x06, 0x00,
+ 0x03, 0x00,
+ 0x03, 0x00,
+ 0x00, 0x00
+};
+
+static const unsigned char default_cmask[] = {
+ 0xC0, 0x00,
+ 0xE0, 0x00,
+ 0xF0, 0x00,
+ 0xF8, 0x00,
+ 0xFC, 0x00,
+ 0xFE, 0x00,
+ 0xFF, 0x00,
+ 0xFF, 0x80,
+ 0xFF, 0xC0,
+ 0xFF, 0xE0,
+ 0xFE, 0x00,
+ 0xEF, 0x00,
+ 0xCF, 0x00,
+ 0x87, 0x80,
+ 0x07, 0x80,
+ 0x03, 0x00
+};
+
+#else
+
+static const unsigned char default_cdata[] = {
+ 0x00, 0x00,
+ 0x40, 0x00,
+ 0x60, 0x00,
+ 0x70, 0x00,
+ 0x78, 0x00,
+ 0x7C, 0x00,
+ 0x7E, 0x00,
+ 0x7F, 0x00,
+ 0x7F, 0x80,
+ 0x7C, 0x00,
+ 0x6C, 0x00,
+ 0x46, 0x00,
+ 0x06, 0x00,
+ 0x03, 0x00,
+ 0x03, 0x00,
+ 0x00, 0x00
+};
+
+static const unsigned char default_cmask[] = {
+ 0x40, 0x00,
+ 0xE0, 0x00,
+ 0xF0, 0x00,
+ 0xF8, 0x00,
+ 0xFC, 0x00,
+ 0xFE, 0x00,
+ 0xFF, 0x00,
+ 0xFF, 0x80,
+ 0xFF, 0xC0,
+ 0xFF, 0x80,
+ 0xFE, 0x00,
+ 0xEF, 0x00,
+ 0x4F, 0x00,
+ 0x07, 0x80,
+ 0x07, 0x80,
+ 0x03, 0x00
+};
+
+#endif /* USE_MACOS_CURSOR */
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/events/scancodes_darwin.h b/src/3rdparty/SDL2/src/events/scancodes_darwin.h
new file mode 100644
index 0000000..7848d86
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/scancodes_darwin.h
@@ -0,0 +1,159 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/* Mac virtual key code to SDL scancode mapping table
+ Sources:
+ - Inside Macintosh: Text <http://developer.apple.com/documentation/mac/Text/Text-571.html>
+ - Apple USB keyboard driver source <http://darwinsource.opendarwin.org/10.4.6.ppc/IOHIDFamily-172.8/IOHIDFamily/Cosmo_USB2ADB.c>
+ - experimentation on various ADB and USB ISO keyboards and one ADB ANSI keyboard
+*/
+/* *INDENT-OFF* */
+static const SDL_Scancode darwin_scancode_table[] = {
+ /* 0 */ SDL_SCANCODE_A,
+ /* 1 */ SDL_SCANCODE_S,
+ /* 2 */ SDL_SCANCODE_D,
+ /* 3 */ SDL_SCANCODE_F,
+ /* 4 */ SDL_SCANCODE_H,
+ /* 5 */ SDL_SCANCODE_G,
+ /* 6 */ SDL_SCANCODE_Z,
+ /* 7 */ SDL_SCANCODE_X,
+ /* 8 */ SDL_SCANCODE_C,
+ /* 9 */ SDL_SCANCODE_V,
+ /* 10 */ SDL_SCANCODE_NONUSBACKSLASH, /* SDL_SCANCODE_NONUSBACKSLASH on ANSI and JIS keyboards (if this key would exist there), SDL_SCANCODE_GRAVE on ISO. (The USB keyboard driver actually translates these usage codes to different virtual key codes depending on whether the keyboard is ISO/ANSI/JIS. That's why you have to help it identify the keyboard type when you plug in a PC USB keyboard. It's a historical thing - ADB keyboards are wired this way.) */
+ /* 11 */ SDL_SCANCODE_B,
+ /* 12 */ SDL_SCANCODE_Q,
+ /* 13 */ SDL_SCANCODE_W,
+ /* 14 */ SDL_SCANCODE_E,
+ /* 15 */ SDL_SCANCODE_R,
+ /* 16 */ SDL_SCANCODE_Y,
+ /* 17 */ SDL_SCANCODE_T,
+ /* 18 */ SDL_SCANCODE_1,
+ /* 19 */ SDL_SCANCODE_2,
+ /* 20 */ SDL_SCANCODE_3,
+ /* 21 */ SDL_SCANCODE_4,
+ /* 22 */ SDL_SCANCODE_6,
+ /* 23 */ SDL_SCANCODE_5,
+ /* 24 */ SDL_SCANCODE_EQUALS,
+ /* 25 */ SDL_SCANCODE_9,
+ /* 26 */ SDL_SCANCODE_7,
+ /* 27 */ SDL_SCANCODE_MINUS,
+ /* 28 */ SDL_SCANCODE_8,
+ /* 29 */ SDL_SCANCODE_0,
+ /* 30 */ SDL_SCANCODE_RIGHTBRACKET,
+ /* 31 */ SDL_SCANCODE_O,
+ /* 32 */ SDL_SCANCODE_U,
+ /* 33 */ SDL_SCANCODE_LEFTBRACKET,
+ /* 34 */ SDL_SCANCODE_I,
+ /* 35 */ SDL_SCANCODE_P,
+ /* 36 */ SDL_SCANCODE_RETURN,
+ /* 37 */ SDL_SCANCODE_L,
+ /* 38 */ SDL_SCANCODE_J,
+ /* 39 */ SDL_SCANCODE_APOSTROPHE,
+ /* 40 */ SDL_SCANCODE_K,
+ /* 41 */ SDL_SCANCODE_SEMICOLON,
+ /* 42 */ SDL_SCANCODE_BACKSLASH,
+ /* 43 */ SDL_SCANCODE_COMMA,
+ /* 44 */ SDL_SCANCODE_SLASH,
+ /* 45 */ SDL_SCANCODE_N,
+ /* 46 */ SDL_SCANCODE_M,
+ /* 47 */ SDL_SCANCODE_PERIOD,
+ /* 48 */ SDL_SCANCODE_TAB,
+ /* 49 */ SDL_SCANCODE_SPACE,
+ /* 50 */ SDL_SCANCODE_GRAVE, /* SDL_SCANCODE_GRAVE on ANSI and JIS keyboards, SDL_SCANCODE_NONUSBACKSLASH on ISO (see comment about virtual key code 10 above) */
+ /* 51 */ SDL_SCANCODE_BACKSPACE,
+ /* 52 */ SDL_SCANCODE_KP_ENTER, /* keyboard enter on portables */
+ /* 53 */ SDL_SCANCODE_ESCAPE,
+ /* 54 */ SDL_SCANCODE_RGUI,
+ /* 55 */ SDL_SCANCODE_LGUI,
+ /* 56 */ SDL_SCANCODE_LSHIFT,
+ /* 57 */ SDL_SCANCODE_CAPSLOCK,
+ /* 58 */ SDL_SCANCODE_LALT,
+ /* 59 */ SDL_SCANCODE_LCTRL,
+ /* 60 */ SDL_SCANCODE_RSHIFT,
+ /* 61 */ SDL_SCANCODE_RALT,
+ /* 62 */ SDL_SCANCODE_RCTRL,
+ /* 63 */ SDL_SCANCODE_RGUI, /* fn on portables, acts as a hardware-level modifier already, so we don't generate events for it, also XK_Meta_R */
+ /* 64 */ SDL_SCANCODE_F17,
+ /* 65 */ SDL_SCANCODE_KP_PERIOD,
+ /* 66 */ SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
+ /* 67 */ SDL_SCANCODE_KP_MULTIPLY,
+ /* 68 */ SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
+ /* 69 */ SDL_SCANCODE_KP_PLUS,
+ /* 70 */ SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
+ /* 71 */ SDL_SCANCODE_NUMLOCKCLEAR,
+ /* 72 */ SDL_SCANCODE_VOLUMEUP,
+ /* 73 */ SDL_SCANCODE_VOLUMEDOWN,
+ /* 74 */ SDL_SCANCODE_MUTE,
+ /* 75 */ SDL_SCANCODE_KP_DIVIDE,
+ /* 76 */ SDL_SCANCODE_KP_ENTER, /* keypad enter on external keyboards, fn-return on portables */
+ /* 77 */ SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
+ /* 78 */ SDL_SCANCODE_KP_MINUS,
+ /* 79 */ SDL_SCANCODE_F18,
+ /* 80 */ SDL_SCANCODE_F19,
+ /* 81 */ SDL_SCANCODE_KP_EQUALS,
+ /* 82 */ SDL_SCANCODE_KP_0,
+ /* 83 */ SDL_SCANCODE_KP_1,
+ /* 84 */ SDL_SCANCODE_KP_2,
+ /* 85 */ SDL_SCANCODE_KP_3,
+ /* 86 */ SDL_SCANCODE_KP_4,
+ /* 87 */ SDL_SCANCODE_KP_5,
+ /* 88 */ SDL_SCANCODE_KP_6,
+ /* 89 */ SDL_SCANCODE_KP_7,
+ /* 90 */ SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
+ /* 91 */ SDL_SCANCODE_KP_8,
+ /* 92 */ SDL_SCANCODE_KP_9,
+ /* 93 */ SDL_SCANCODE_INTERNATIONAL3, /* Cosmo_USB2ADB.c says "Yen (JIS)" */
+ /* 94 */ SDL_SCANCODE_INTERNATIONAL1, /* Cosmo_USB2ADB.c says "Ro (JIS)" */
+ /* 95 */ SDL_SCANCODE_KP_COMMA, /* Cosmo_USB2ADB.c says ", JIS only" */
+ /* 96 */ SDL_SCANCODE_F5,
+ /* 97 */ SDL_SCANCODE_F6,
+ /* 98 */ SDL_SCANCODE_F7,
+ /* 99 */ SDL_SCANCODE_F3,
+ /* 100 */ SDL_SCANCODE_F8,
+ /* 101 */ SDL_SCANCODE_F9,
+ /* 102 */ SDL_SCANCODE_LANG2, /* Cosmo_USB2ADB.c says "Eisu" */
+ /* 103 */ SDL_SCANCODE_F11,
+ /* 104 */ SDL_SCANCODE_LANG1, /* Cosmo_USB2ADB.c says "Kana" */
+ /* 105 */ SDL_SCANCODE_PRINTSCREEN, /* On ADB keyboards, this key is labeled "F13/print screen". Problem: USB has different usage codes for these two functions. On Apple USB keyboards, the key is labeled "F13" and sends the F13 usage code (SDL_SCANCODE_F13). I decided to use SDL_SCANCODE_PRINTSCREEN here nevertheless since SDL applications are more likely to assume the presence of a print screen key than an F13 key. */
+ /* 106 */ SDL_SCANCODE_F16,
+ /* 107 */ SDL_SCANCODE_SCROLLLOCK, /* F14/scroll lock, see comment about F13/print screen above */
+ /* 108 */ SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
+ /* 109 */ SDL_SCANCODE_F10,
+ /* 110 */ SDL_SCANCODE_APPLICATION, /* windows contextual menu key, fn-enter on portables */
+ /* 111 */ SDL_SCANCODE_F12,
+ /* 112 */ SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
+ /* 113 */ SDL_SCANCODE_PAUSE, /* F15/pause, see comment about F13/print screen above */
+ /* 114 */ SDL_SCANCODE_INSERT, /* the key is actually labeled "help" on Apple keyboards, and works as such in Mac OS, but it sends the "insert" usage code even on Apple USB keyboards */
+ /* 115 */ SDL_SCANCODE_HOME,
+ /* 116 */ SDL_SCANCODE_PAGEUP,
+ /* 117 */ SDL_SCANCODE_DELETE,
+ /* 118 */ SDL_SCANCODE_F4,
+ /* 119 */ SDL_SCANCODE_END,
+ /* 120 */ SDL_SCANCODE_F2,
+ /* 121 */ SDL_SCANCODE_PAGEDOWN,
+ /* 122 */ SDL_SCANCODE_F1,
+ /* 123 */ SDL_SCANCODE_LEFT,
+ /* 124 */ SDL_SCANCODE_RIGHT,
+ /* 125 */ SDL_SCANCODE_DOWN,
+ /* 126 */ SDL_SCANCODE_UP,
+ /* 127 */ SDL_SCANCODE_POWER
+};
+/* *INDENT-ON* */
diff --git a/src/3rdparty/SDL2/src/events/scancodes_linux.h b/src/3rdparty/SDL2/src/events/scancodes_linux.h
new file mode 100644
index 0000000..3fec4b5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/scancodes_linux.h
@@ -0,0 +1,263 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../include/SDL_scancode.h"
+
+/* Linux virtual key code to SDL_Keycode mapping table
+ Sources:
+ - Linux kernel source input.h
+*/
+/* *INDENT-OFF* */
+static SDL_Scancode const linux_scancode_table[] = {
+ /* 0 */ SDL_SCANCODE_UNKNOWN,
+ /* 1 */ SDL_SCANCODE_ESCAPE,
+ /* 2 */ SDL_SCANCODE_1,
+ /* 3 */ SDL_SCANCODE_2,
+ /* 4 */ SDL_SCANCODE_3,
+ /* 5 */ SDL_SCANCODE_4,
+ /* 6 */ SDL_SCANCODE_5,
+ /* 7 */ SDL_SCANCODE_6,
+ /* 8 */ SDL_SCANCODE_7,
+ /* 9 */ SDL_SCANCODE_8,
+ /* 10 */ SDL_SCANCODE_9,
+ /* 11 */ SDL_SCANCODE_0,
+ /* 12 */ SDL_SCANCODE_MINUS,
+ /* 13 */ SDL_SCANCODE_EQUALS,
+ /* 14 */ SDL_SCANCODE_BACKSPACE,
+ /* 15 */ SDL_SCANCODE_TAB,
+ /* 16 */ SDL_SCANCODE_Q,
+ /* 17 */ SDL_SCANCODE_W,
+ /* 18 */ SDL_SCANCODE_E,
+ /* 19 */ SDL_SCANCODE_R,
+ /* 20 */ SDL_SCANCODE_T,
+ /* 21 */ SDL_SCANCODE_Y,
+ /* 22 */ SDL_SCANCODE_U,
+ /* 23 */ SDL_SCANCODE_I,
+ /* 24 */ SDL_SCANCODE_O,
+ /* 25 */ SDL_SCANCODE_P,
+ /* 26 */ SDL_SCANCODE_LEFTBRACKET,
+ /* 27 */ SDL_SCANCODE_RIGHTBRACKET,
+ /* 28 */ SDL_SCANCODE_RETURN,
+ /* 29 */ SDL_SCANCODE_LCTRL,
+ /* 30 */ SDL_SCANCODE_A,
+ /* 31 */ SDL_SCANCODE_S,
+ /* 32 */ SDL_SCANCODE_D,
+ /* 33 */ SDL_SCANCODE_F,
+ /* 34 */ SDL_SCANCODE_G,
+ /* 35 */ SDL_SCANCODE_H,
+ /* 36 */ SDL_SCANCODE_J,
+ /* 37 */ SDL_SCANCODE_K,
+ /* 38 */ SDL_SCANCODE_L,
+ /* 39 */ SDL_SCANCODE_SEMICOLON,
+ /* 40 */ SDL_SCANCODE_APOSTROPHE,
+ /* 41 */ SDL_SCANCODE_GRAVE,
+ /* 42 */ SDL_SCANCODE_LSHIFT,
+ /* 43 */ SDL_SCANCODE_BACKSLASH,
+ /* 44 */ SDL_SCANCODE_Z,
+ /* 45 */ SDL_SCANCODE_X,
+ /* 46 */ SDL_SCANCODE_C,
+ /* 47 */ SDL_SCANCODE_V,
+ /* 48 */ SDL_SCANCODE_B,
+ /* 49 */ SDL_SCANCODE_N,
+ /* 50 */ SDL_SCANCODE_M,
+ /* 51 */ SDL_SCANCODE_COMMA,
+ /* 52 */ SDL_SCANCODE_PERIOD,
+ /* 53 */ SDL_SCANCODE_SLASH,
+ /* 54 */ SDL_SCANCODE_RSHIFT,
+ /* 55 */ SDL_SCANCODE_KP_MULTIPLY,
+ /* 56 */ SDL_SCANCODE_LALT,
+ /* 57 */ SDL_SCANCODE_SPACE,
+ /* 58 */ SDL_SCANCODE_CAPSLOCK,
+ /* 59 */ SDL_SCANCODE_F1,
+ /* 60 */ SDL_SCANCODE_F2,
+ /* 61 */ SDL_SCANCODE_F3,
+ /* 62 */ SDL_SCANCODE_F4,
+ /* 63 */ SDL_SCANCODE_F5,
+ /* 64 */ SDL_SCANCODE_F6,
+ /* 65 */ SDL_SCANCODE_F7,
+ /* 66 */ SDL_SCANCODE_F8,
+ /* 67 */ SDL_SCANCODE_F9,
+ /* 68 */ SDL_SCANCODE_F10,
+ /* 69 */ SDL_SCANCODE_NUMLOCKCLEAR,
+ /* 70 */ SDL_SCANCODE_SCROLLLOCK,
+ /* 71 */ SDL_SCANCODE_KP_7,
+ /* 72 */ SDL_SCANCODE_KP_8,
+ /* 73 */ SDL_SCANCODE_KP_9,
+ /* 74 */ SDL_SCANCODE_KP_MINUS,
+ /* 75 */ SDL_SCANCODE_KP_4,
+ /* 76 */ SDL_SCANCODE_KP_5,
+ /* 77 */ SDL_SCANCODE_KP_6,
+ /* 78 */ SDL_SCANCODE_KP_PLUS,
+ /* 79 */ SDL_SCANCODE_KP_1,
+ /* 80 */ SDL_SCANCODE_KP_2,
+ /* 81 */ SDL_SCANCODE_KP_3,
+ /* 82 */ SDL_SCANCODE_KP_0,
+ /* 83 */ SDL_SCANCODE_KP_PERIOD,
+ 0,
+ /* 85 */ SDL_SCANCODE_LANG5, /* KEY_ZENKAKUHANKAKU */
+ /* 86 */ SDL_SCANCODE_NONUSBACKSLASH, /* KEY_102ND */
+ /* 87 */ SDL_SCANCODE_F11,
+ /* 88 */ SDL_SCANCODE_F12,
+ /* 89 */ SDL_SCANCODE_INTERNATIONAL1, /* KEY_RO */
+ /* 90 */ SDL_SCANCODE_LANG3, /* KEY_KATAKANA */
+ /* 91 */ SDL_SCANCODE_LANG4, /* KEY_HIRAGANA */
+ /* 92 */ SDL_SCANCODE_INTERNATIONAL4, /* KEY_HENKAN */
+ /* 93 */ SDL_SCANCODE_INTERNATIONAL2, /* KEY_KATAKANAHIRAGANA */
+ /* 94 */ SDL_SCANCODE_INTERNATIONAL5, /* KEY_MUHENKAN */
+ /* 95 */ SDL_SCANCODE_INTERNATIONAL5, /* KEY_KPJPCOMMA */
+ /* 96 */ SDL_SCANCODE_KP_ENTER,
+ /* 97 */ SDL_SCANCODE_RCTRL,
+ /* 98 */ SDL_SCANCODE_KP_DIVIDE,
+ /* 99 */ SDL_SCANCODE_SYSREQ,
+ /* 100 */ SDL_SCANCODE_RALT,
+ /* 101 */ SDL_SCANCODE_UNKNOWN, /* KEY_LINEFEED */
+ /* 102 */ SDL_SCANCODE_HOME,
+ /* 103 */ SDL_SCANCODE_UP,
+ /* 104 */ SDL_SCANCODE_PAGEUP,
+ /* 105 */ SDL_SCANCODE_LEFT,
+ /* 106 */ SDL_SCANCODE_RIGHT,
+ /* 107 */ SDL_SCANCODE_END,
+ /* 108 */ SDL_SCANCODE_DOWN,
+ /* 109 */ SDL_SCANCODE_PAGEDOWN,
+ /* 110 */ SDL_SCANCODE_INSERT,
+ /* 111 */ SDL_SCANCODE_DELETE,
+ /* 112 */ SDL_SCANCODE_UNKNOWN, /* KEY_MACRO */
+ /* 113 */ SDL_SCANCODE_MUTE,
+ /* 114 */ SDL_SCANCODE_VOLUMEDOWN,
+ /* 115 */ SDL_SCANCODE_VOLUMEUP,
+ /* 116 */ SDL_SCANCODE_POWER,
+ /* 117 */ SDL_SCANCODE_KP_EQUALS,
+ /* 118 */ SDL_SCANCODE_KP_PLUSMINUS,
+ /* 119 */ SDL_SCANCODE_PAUSE,
+ 0,
+ /* 121 */ SDL_SCANCODE_KP_COMMA,
+ /* 122 */ SDL_SCANCODE_LANG1, /* KEY_HANGUEL */
+ /* 123 */ SDL_SCANCODE_LANG2, /* KEY_HANJA */
+ /* 124 */ SDL_SCANCODE_INTERNATIONAL3, /* KEY_YEN */
+ /* 125 */ SDL_SCANCODE_LGUI,
+ /* 126 */ SDL_SCANCODE_RGUI,
+ /* 127 */ SDL_SCANCODE_APPLICATION, /* KEY_COMPOSE */
+ /* 128 */ SDL_SCANCODE_STOP,
+ /* 129 */ SDL_SCANCODE_AGAIN,
+ /* 130 */ SDL_SCANCODE_UNKNOWN, /* KEY_PROPS */
+ /* 131 */ SDL_SCANCODE_UNDO,
+ /* 132 */ SDL_SCANCODE_UNKNOWN, /* KEY_FRONT */
+ /* 133 */ SDL_SCANCODE_COPY,
+ /* 134 */ SDL_SCANCODE_UNKNOWN, /* KEY_OPEN */
+ /* 135 */ SDL_SCANCODE_PASTE,
+ /* 136 */ SDL_SCANCODE_FIND,
+ /* 137 */ SDL_SCANCODE_CUT,
+ /* 138 */ SDL_SCANCODE_HELP,
+ /* 139 */ SDL_SCANCODE_MENU,
+ /* 140 */ SDL_SCANCODE_CALCULATOR,
+ /* 141 */ SDL_SCANCODE_UNKNOWN, /* KEY_SETUP */
+ /* 142 */ SDL_SCANCODE_SLEEP,
+ /* 143 */ SDL_SCANCODE_UNKNOWN, /* KEY_WAKEUP */
+ /* 144 */ SDL_SCANCODE_UNKNOWN, /* KEY_FILE */
+ /* 145 */ SDL_SCANCODE_UNKNOWN, /* KEY_SENDFILE */
+ /* 146 */ SDL_SCANCODE_UNKNOWN, /* KEY_DELETEFILE */
+ /* 147 */ SDL_SCANCODE_UNKNOWN, /* KEY_XFER */
+ /* 148 */ SDL_SCANCODE_APP1, /* KEY_PROG1 */
+ /* 149 */ SDL_SCANCODE_APP2, /* KEY_PROG2 */
+ /* 150 */ SDL_SCANCODE_WWW, /* KEY_WWW */
+ /* 151 */ SDL_SCANCODE_UNKNOWN, /* KEY_MSDOS */
+ /* 152 */ SDL_SCANCODE_UNKNOWN, /* KEY_COFFEE */
+ /* 153 */ SDL_SCANCODE_UNKNOWN, /* KEY_DIRECTION */
+ /* 154 */ SDL_SCANCODE_UNKNOWN, /* KEY_CYCLEWINDOWS */
+ /* 155 */ SDL_SCANCODE_MAIL,
+ /* 156 */ SDL_SCANCODE_AC_BOOKMARKS,
+ /* 157 */ SDL_SCANCODE_COMPUTER,
+ /* 158 */ SDL_SCANCODE_AC_BACK,
+ /* 159 */ SDL_SCANCODE_AC_FORWARD,
+ /* 160 */ SDL_SCANCODE_UNKNOWN, /* KEY_CLOSECD */
+ /* 161 */ SDL_SCANCODE_EJECT, /* KEY_EJECTCD */
+ /* 162 */ SDL_SCANCODE_UNKNOWN, /* KEY_EJECTCLOSECD */
+ /* 163 */ SDL_SCANCODE_AUDIONEXT, /* KEY_NEXTSONG */
+ /* 164 */ SDL_SCANCODE_AUDIOPLAY, /* KEY_PLAYPAUSE */
+ /* 165 */ SDL_SCANCODE_AUDIOPREV, /* KEY_PREVIOUSSONG */
+ /* 166 */ SDL_SCANCODE_AUDIOSTOP, /* KEY_STOPCD */
+ /* 167 */ SDL_SCANCODE_UNKNOWN, /* KEY_RECORD */
+ /* 168 */ SDL_SCANCODE_AUDIOREWIND, /* KEY_REWIND */
+ /* 169 */ SDL_SCANCODE_UNKNOWN, /* KEY_PHONE */
+ /* 170 */ SDL_SCANCODE_UNKNOWN, /* KEY_ISO */
+ /* 171 */ SDL_SCANCODE_UNKNOWN, /* KEY_CONFIG */
+ /* 172 */ SDL_SCANCODE_AC_HOME,
+ /* 173 */ SDL_SCANCODE_AC_REFRESH,
+ /* 174 */ SDL_SCANCODE_UNKNOWN, /* KEY_EXIT */
+ /* 175 */ SDL_SCANCODE_UNKNOWN, /* KEY_MOVE */
+ /* 176 */ SDL_SCANCODE_UNKNOWN, /* KEY_EDIT */
+ /* 177 */ SDL_SCANCODE_UNKNOWN, /* KEY_SCROLLUP */
+ /* 178 */ SDL_SCANCODE_UNKNOWN, /* KEY_SCROLLDOWN */
+ /* 179 */ SDL_SCANCODE_KP_LEFTPAREN,
+ /* 180 */ SDL_SCANCODE_KP_RIGHTPAREN,
+ /* 181 */ SDL_SCANCODE_UNKNOWN, /* KEY_NEW */
+ /* 182 */ SDL_SCANCODE_UNKNOWN, /* KEY_REDO */
+ /* 183 */ SDL_SCANCODE_F13,
+ /* 184 */ SDL_SCANCODE_F14,
+ /* 185 */ SDL_SCANCODE_F15,
+ /* 186 */ SDL_SCANCODE_F16,
+ /* 187 */ SDL_SCANCODE_F17,
+ /* 188 */ SDL_SCANCODE_F18,
+ /* 189 */ SDL_SCANCODE_F19,
+ /* 190 */ SDL_SCANCODE_F20,
+ /* 191 */ SDL_SCANCODE_F21,
+ /* 192 */ SDL_SCANCODE_F22,
+ /* 193 */ SDL_SCANCODE_F23,
+ /* 194 */ SDL_SCANCODE_F24,
+ 0, 0, 0, 0, 0,
+ /* 200 */ SDL_SCANCODE_UNKNOWN, /* KEY_PLAYCD */
+ /* 201 */ SDL_SCANCODE_UNKNOWN, /* KEY_PAUSECD */
+ /* 202 */ SDL_SCANCODE_UNKNOWN, /* KEY_PROG3 */
+ /* 203 */ SDL_SCANCODE_UNKNOWN, /* KEY_PROG4 */
+ 0,
+ /* 205 */ SDL_SCANCODE_UNKNOWN, /* KEY_SUSPEND */
+ /* 206 */ SDL_SCANCODE_UNKNOWN, /* KEY_CLOSE */
+ /* 207 */ SDL_SCANCODE_UNKNOWN, /* KEY_PLAY */
+ /* 208 */ SDL_SCANCODE_AUDIOFASTFORWARD, /* KEY_FASTFORWARD */
+ /* 209 */ SDL_SCANCODE_UNKNOWN, /* KEY_BASSBOOST */
+ /* 210 */ SDL_SCANCODE_UNKNOWN, /* KEY_PRINT */
+ /* 211 */ SDL_SCANCODE_UNKNOWN, /* KEY_HP */
+ /* 212 */ SDL_SCANCODE_UNKNOWN, /* KEY_CAMERA */
+ /* 213 */ SDL_SCANCODE_UNKNOWN, /* KEY_SOUND */
+ /* 214 */ SDL_SCANCODE_UNKNOWN, /* KEY_QUESTION */
+ /* 215 */ SDL_SCANCODE_UNKNOWN, /* KEY_EMAIL */
+ /* 216 */ SDL_SCANCODE_UNKNOWN, /* KEY_CHAT */
+ /* 217 */ SDL_SCANCODE_AC_SEARCH,
+ /* 218 */ SDL_SCANCODE_UNKNOWN, /* KEY_CONNECT */
+ /* 219 */ SDL_SCANCODE_UNKNOWN, /* KEY_FINANCE */
+ /* 220 */ SDL_SCANCODE_UNKNOWN, /* KEY_SPORT */
+ /* 221 */ SDL_SCANCODE_UNKNOWN, /* KEY_SHOP */
+ /* 222 */ SDL_SCANCODE_ALTERASE,
+ /* 223 */ SDL_SCANCODE_CANCEL,
+ /* 224 */ SDL_SCANCODE_BRIGHTNESSDOWN,
+ /* 225 */ SDL_SCANCODE_BRIGHTNESSUP,
+ /* 226 */ SDL_SCANCODE_UNKNOWN, /* KEY_MEDIA */
+ /* 227 */ SDL_SCANCODE_DISPLAYSWITCH, /* KEY_SWITCHVIDEOMODE */
+ /* 228 */ SDL_SCANCODE_KBDILLUMTOGGLE,
+ /* 229 */ SDL_SCANCODE_KBDILLUMDOWN,
+ /* 230 */ SDL_SCANCODE_KBDILLUMUP,
+ /* 231 */ SDL_SCANCODE_UNKNOWN, /* KEY_SEND */
+ /* 232 */ SDL_SCANCODE_UNKNOWN, /* KEY_REPLY */
+ /* 233 */ SDL_SCANCODE_UNKNOWN, /* KEY_FORWARDMAIL */
+ /* 234 */ SDL_SCANCODE_UNKNOWN, /* KEY_SAVE */
+ /* 235 */ SDL_SCANCODE_UNKNOWN, /* KEY_DOCUMENTS */
+ /* 236 */ SDL_SCANCODE_UNKNOWN, /* KEY_BATTERY */
+};
+/* *INDENT-ON* */
diff --git a/src/3rdparty/SDL2/src/events/scancodes_windows.h b/src/3rdparty/SDL2/src/events/scancodes_windows.h
new file mode 100644
index 0000000..f8eed1b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/scancodes_windows.h
@@ -0,0 +1,55 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../include/SDL_scancode.h"
+
+/* Windows scancode to SDL scancode mapping table */
+/* derived from Microsoft scan code document, http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/scancode.doc */
+
+/* *INDENT-OFF* */
+static const SDL_Scancode windows_scancode_table[] =
+{
+ /* 0 1 2 3 4 5 6 7 */
+ /* 8 9 A B C D E F */
+ SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_ESCAPE, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_3, SDL_SCANCODE_4, SDL_SCANCODE_5, SDL_SCANCODE_6, /* 0 */
+ SDL_SCANCODE_7, SDL_SCANCODE_8, SDL_SCANCODE_9, SDL_SCANCODE_0, SDL_SCANCODE_MINUS, SDL_SCANCODE_EQUALS, SDL_SCANCODE_BACKSPACE, SDL_SCANCODE_TAB, /* 0 */
+
+ SDL_SCANCODE_Q, SDL_SCANCODE_W, SDL_SCANCODE_E, SDL_SCANCODE_R, SDL_SCANCODE_T, SDL_SCANCODE_Y, SDL_SCANCODE_U, SDL_SCANCODE_I, /* 1 */
+ SDL_SCANCODE_O, SDL_SCANCODE_P, SDL_SCANCODE_LEFTBRACKET, SDL_SCANCODE_RIGHTBRACKET, SDL_SCANCODE_RETURN, SDL_SCANCODE_LCTRL, SDL_SCANCODE_A, SDL_SCANCODE_S, /* 1 */
+
+ SDL_SCANCODE_D, SDL_SCANCODE_F, SDL_SCANCODE_G, SDL_SCANCODE_H, SDL_SCANCODE_J, SDL_SCANCODE_K, SDL_SCANCODE_L, SDL_SCANCODE_SEMICOLON, /* 2 */
+ SDL_SCANCODE_APOSTROPHE, SDL_SCANCODE_GRAVE, SDL_SCANCODE_LSHIFT, SDL_SCANCODE_BACKSLASH, SDL_SCANCODE_Z, SDL_SCANCODE_X, SDL_SCANCODE_C, SDL_SCANCODE_V, /* 2 */
+
+ SDL_SCANCODE_B, SDL_SCANCODE_N, SDL_SCANCODE_M, SDL_SCANCODE_COMMA, SDL_SCANCODE_PERIOD, SDL_SCANCODE_SLASH, SDL_SCANCODE_RSHIFT, SDL_SCANCODE_PRINTSCREEN,/* 3 */
+ SDL_SCANCODE_LALT, SDL_SCANCODE_SPACE, SDL_SCANCODE_CAPSLOCK, SDL_SCANCODE_F1, SDL_SCANCODE_F2, SDL_SCANCODE_F3, SDL_SCANCODE_F4, SDL_SCANCODE_F5, /* 3 */
+
+ SDL_SCANCODE_F6, SDL_SCANCODE_F7, SDL_SCANCODE_F8, SDL_SCANCODE_F9, SDL_SCANCODE_F10, SDL_SCANCODE_NUMLOCKCLEAR, SDL_SCANCODE_SCROLLLOCK, SDL_SCANCODE_HOME, /* 4 */
+ SDL_SCANCODE_UP, SDL_SCANCODE_PAGEUP, SDL_SCANCODE_KP_MINUS, SDL_SCANCODE_LEFT, SDL_SCANCODE_KP_5, SDL_SCANCODE_RIGHT, SDL_SCANCODE_KP_PLUS, SDL_SCANCODE_END, /* 4 */
+
+ SDL_SCANCODE_DOWN, SDL_SCANCODE_PAGEDOWN, SDL_SCANCODE_INSERT, SDL_SCANCODE_DELETE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_NONUSBACKSLASH,SDL_SCANCODE_F11, /* 5 */
+ SDL_SCANCODE_F12, SDL_SCANCODE_PAUSE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_LGUI, SDL_SCANCODE_RGUI, SDL_SCANCODE_APPLICATION, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, /* 5 */
+
+ SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_F13, SDL_SCANCODE_F14, SDL_SCANCODE_F15, SDL_SCANCODE_F16, /* 6 */
+ SDL_SCANCODE_F17, SDL_SCANCODE_F18, SDL_SCANCODE_F19, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, /* 6 */
+
+ SDL_SCANCODE_INTERNATIONAL2, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL1, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, /* 7 */
+ SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL4, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL5, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL3, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN /* 7 */
+};
+/* *INDENT-ON* */
diff --git a/src/3rdparty/SDL2/src/events/scancodes_xfree86.h b/src/3rdparty/SDL2/src/events/scancodes_xfree86.h
new file mode 100644
index 0000000..7d1f844
--- /dev/null
+++ b/src/3rdparty/SDL2/src/events/scancodes_xfree86.h
@@ -0,0 +1,506 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../include/SDL_scancode.h"
+
+/* XFree86 key code to SDL scancode mapping table
+ Sources:
+ - atKeyNames.h from XFree86 source code
+*/
+/* *INDENT-OFF* */
+static const SDL_Scancode xfree86_scancode_table[] = {
+ /* 0 */ SDL_SCANCODE_UNKNOWN,
+ /* 1 */ SDL_SCANCODE_ESCAPE,
+ /* 2 */ SDL_SCANCODE_1,
+ /* 3 */ SDL_SCANCODE_2,
+ /* 4 */ SDL_SCANCODE_3,
+ /* 5 */ SDL_SCANCODE_4,
+ /* 6 */ SDL_SCANCODE_5,
+ /* 7 */ SDL_SCANCODE_6,
+ /* 8 */ SDL_SCANCODE_7,
+ /* 9 */ SDL_SCANCODE_8,
+ /* 10 */ SDL_SCANCODE_9,
+ /* 11 */ SDL_SCANCODE_0,
+ /* 12 */ SDL_SCANCODE_MINUS,
+ /* 13 */ SDL_SCANCODE_EQUALS,
+ /* 14 */ SDL_SCANCODE_BACKSPACE,
+ /* 15 */ SDL_SCANCODE_TAB,
+ /* 16 */ SDL_SCANCODE_Q,
+ /* 17 */ SDL_SCANCODE_W,
+ /* 18 */ SDL_SCANCODE_E,
+ /* 19 */ SDL_SCANCODE_R,
+ /* 20 */ SDL_SCANCODE_T,
+ /* 21 */ SDL_SCANCODE_Y,
+ /* 22 */ SDL_SCANCODE_U,
+ /* 23 */ SDL_SCANCODE_I,
+ /* 24 */ SDL_SCANCODE_O,
+ /* 25 */ SDL_SCANCODE_P,
+ /* 26 */ SDL_SCANCODE_LEFTBRACKET,
+ /* 27 */ SDL_SCANCODE_RIGHTBRACKET,
+ /* 28 */ SDL_SCANCODE_RETURN,
+ /* 29 */ SDL_SCANCODE_LCTRL,
+ /* 30 */ SDL_SCANCODE_A,
+ /* 31 */ SDL_SCANCODE_S,
+ /* 32 */ SDL_SCANCODE_D,
+ /* 33 */ SDL_SCANCODE_F,
+ /* 34 */ SDL_SCANCODE_G,
+ /* 35 */ SDL_SCANCODE_H,
+ /* 36 */ SDL_SCANCODE_J,
+ /* 37 */ SDL_SCANCODE_K,
+ /* 38 */ SDL_SCANCODE_L,
+ /* 39 */ SDL_SCANCODE_SEMICOLON,
+ /* 40 */ SDL_SCANCODE_APOSTROPHE,
+ /* 41 */ SDL_SCANCODE_GRAVE,
+ /* 42 */ SDL_SCANCODE_LSHIFT,
+ /* 43 */ SDL_SCANCODE_BACKSLASH,
+ /* 44 */ SDL_SCANCODE_Z,
+ /* 45 */ SDL_SCANCODE_X,
+ /* 46 */ SDL_SCANCODE_C,
+ /* 47 */ SDL_SCANCODE_V,
+ /* 48 */ SDL_SCANCODE_B,
+ /* 49 */ SDL_SCANCODE_N,
+ /* 50 */ SDL_SCANCODE_M,
+ /* 51 */ SDL_SCANCODE_COMMA,
+ /* 52 */ SDL_SCANCODE_PERIOD,
+ /* 53 */ SDL_SCANCODE_SLASH,
+ /* 54 */ SDL_SCANCODE_RSHIFT,
+ /* 55 */ SDL_SCANCODE_KP_MULTIPLY,
+ /* 56 */ SDL_SCANCODE_LALT,
+ /* 57 */ SDL_SCANCODE_SPACE,
+ /* 58 */ SDL_SCANCODE_CAPSLOCK,
+ /* 59 */ SDL_SCANCODE_F1,
+ /* 60 */ SDL_SCANCODE_F2,
+ /* 61 */ SDL_SCANCODE_F3,
+ /* 62 */ SDL_SCANCODE_F4,
+ /* 63 */ SDL_SCANCODE_F5,
+ /* 64 */ SDL_SCANCODE_F6,
+ /* 65 */ SDL_SCANCODE_F7,
+ /* 66 */ SDL_SCANCODE_F8,
+ /* 67 */ SDL_SCANCODE_F9,
+ /* 68 */ SDL_SCANCODE_F10,
+ /* 69 */ SDL_SCANCODE_NUMLOCKCLEAR,
+ /* 70 */ SDL_SCANCODE_SCROLLLOCK,
+ /* 71 */ SDL_SCANCODE_KP_7,
+ /* 72 */ SDL_SCANCODE_KP_8,
+ /* 73 */ SDL_SCANCODE_KP_9,
+ /* 74 */ SDL_SCANCODE_KP_MINUS,
+ /* 75 */ SDL_SCANCODE_KP_4,
+ /* 76 */ SDL_SCANCODE_KP_5,
+ /* 77 */ SDL_SCANCODE_KP_6,
+ /* 78 */ SDL_SCANCODE_KP_PLUS,
+ /* 79 */ SDL_SCANCODE_KP_1,
+ /* 80 */ SDL_SCANCODE_KP_2,
+ /* 81 */ SDL_SCANCODE_KP_3,
+ /* 82 */ SDL_SCANCODE_KP_0,
+ /* 83 */ SDL_SCANCODE_KP_PERIOD,
+ /* 84 */ SDL_SCANCODE_SYSREQ,
+ /* 85 */ SDL_SCANCODE_MODE,
+ /* 86 */ SDL_SCANCODE_NONUSBACKSLASH,
+ /* 87 */ SDL_SCANCODE_F11,
+ /* 88 */ SDL_SCANCODE_F12,
+ /* 89 */ SDL_SCANCODE_HOME,
+ /* 90 */ SDL_SCANCODE_UP,
+ /* 91 */ SDL_SCANCODE_PAGEUP,
+ /* 92 */ SDL_SCANCODE_LEFT,
+ /* 93 */ SDL_SCANCODE_BRIGHTNESSDOWN, /* on PowerBook G4 / KEY_Begin */
+ /* 94 */ SDL_SCANCODE_RIGHT,
+ /* 95 */ SDL_SCANCODE_END,
+ /* 96 */ SDL_SCANCODE_DOWN,
+ /* 97 */ SDL_SCANCODE_PAGEDOWN,
+ /* 98 */ SDL_SCANCODE_INSERT,
+ /* 99 */ SDL_SCANCODE_DELETE,
+ /* 100 */ SDL_SCANCODE_KP_ENTER,
+ /* 101 */ SDL_SCANCODE_RCTRL,
+ /* 102 */ SDL_SCANCODE_PAUSE,
+ /* 103 */ SDL_SCANCODE_PRINTSCREEN,
+ /* 104 */ SDL_SCANCODE_KP_DIVIDE,
+ /* 105 */ SDL_SCANCODE_RALT,
+ /* 106 */ SDL_SCANCODE_UNKNOWN, /* BREAK */
+ /* 107 */ SDL_SCANCODE_LGUI,
+ /* 108 */ SDL_SCANCODE_RGUI,
+ /* 109 */ SDL_SCANCODE_APPLICATION,
+ /* 110 */ SDL_SCANCODE_F13,
+ /* 111 */ SDL_SCANCODE_F14,
+ /* 112 */ SDL_SCANCODE_F15,
+ /* 113 */ SDL_SCANCODE_F16,
+ /* 114 */ SDL_SCANCODE_F17,
+ /* 115 */ SDL_SCANCODE_INTERNATIONAL1, /* \_ */
+ /* 116 */ SDL_SCANCODE_UNKNOWN, /* is translated to XK_ISO_Level3_Shift by my X server, but I have no keyboard that generates this code, so I don't know what the correct SDL_SCANCODE_* for it is */
+ /* 117 */ SDL_SCANCODE_UNKNOWN,
+ /* 118 */ SDL_SCANCODE_KP_EQUALS,
+ /* 119 */ SDL_SCANCODE_UNKNOWN,
+ /* 120 */ SDL_SCANCODE_UNKNOWN,
+ /* 121 */ SDL_SCANCODE_INTERNATIONAL4, /* Henkan_Mode */
+ /* 122 */ SDL_SCANCODE_UNKNOWN,
+ /* 123 */ SDL_SCANCODE_INTERNATIONAL5, /* Muhenkan */
+ /* 124 */ SDL_SCANCODE_UNKNOWN,
+ /* 125 */ SDL_SCANCODE_INTERNATIONAL3, /* Yen */
+ /* 126 */ SDL_SCANCODE_UNKNOWN,
+ /* 127 */ SDL_SCANCODE_UNKNOWN,
+ /* 128 */ SDL_SCANCODE_UNKNOWN,
+ /* 129 */ SDL_SCANCODE_UNKNOWN,
+ /* 130 */ SDL_SCANCODE_UNKNOWN,
+ /* 131 */ SDL_SCANCODE_UNKNOWN,
+ /* 132 */ SDL_SCANCODE_POWER,
+ /* 133 */ SDL_SCANCODE_MUTE,
+ /* 134 */ SDL_SCANCODE_VOLUMEDOWN,
+ /* 135 */ SDL_SCANCODE_VOLUMEUP,
+ /* 136 */ SDL_SCANCODE_HELP,
+ /* 137 */ SDL_SCANCODE_STOP,
+ /* 138 */ SDL_SCANCODE_AGAIN,
+ /* 139 */ SDL_SCANCODE_UNKNOWN, /* PROPS */
+ /* 140 */ SDL_SCANCODE_UNDO,
+ /* 141 */ SDL_SCANCODE_UNKNOWN, /* FRONT */
+ /* 142 */ SDL_SCANCODE_COPY,
+ /* 143 */ SDL_SCANCODE_UNKNOWN, /* OPEN */
+ /* 144 */ SDL_SCANCODE_PASTE,
+ /* 145 */ SDL_SCANCODE_FIND,
+ /* 146 */ SDL_SCANCODE_CUT,
+};
+
+/* for wireless usb keyboard (manufacturer TRUST) without numpad. */
+static const SDL_Scancode xfree86_scancode_table2[] = {
+ /* 0 */ SDL_SCANCODE_UNKNOWN,
+ /* 1 */ SDL_SCANCODE_ESCAPE,
+ /* 2 */ SDL_SCANCODE_1,
+ /* 3 */ SDL_SCANCODE_2,
+ /* 4 */ SDL_SCANCODE_3,
+ /* 5 */ SDL_SCANCODE_4,
+ /* 6 */ SDL_SCANCODE_5,
+ /* 7 */ SDL_SCANCODE_6,
+ /* 8 */ SDL_SCANCODE_7,
+ /* 9 */ SDL_SCANCODE_8,
+ /* 10 */ SDL_SCANCODE_9,
+ /* 11 */ SDL_SCANCODE_0,
+ /* 12 */ SDL_SCANCODE_MINUS,
+ /* 13 */ SDL_SCANCODE_EQUALS,
+ /* 14 */ SDL_SCANCODE_BACKSPACE,
+ /* 15 */ SDL_SCANCODE_TAB,
+ /* 16 */ SDL_SCANCODE_Q,
+ /* 17 */ SDL_SCANCODE_W,
+ /* 18 */ SDL_SCANCODE_E,
+ /* 19 */ SDL_SCANCODE_R,
+ /* 20 */ SDL_SCANCODE_T,
+ /* 21 */ SDL_SCANCODE_Y,
+ /* 22 */ SDL_SCANCODE_U,
+ /* 23 */ SDL_SCANCODE_I,
+ /* 24 */ SDL_SCANCODE_O,
+ /* 25 */ SDL_SCANCODE_P,
+ /* 26 */ SDL_SCANCODE_LEFTBRACKET,
+ /* 27 */ SDL_SCANCODE_RIGHTBRACKET,
+ /* 28 */ SDL_SCANCODE_RETURN,
+ /* 29 */ SDL_SCANCODE_LCTRL,
+ /* 30 */ SDL_SCANCODE_A,
+ /* 31 */ SDL_SCANCODE_S,
+ /* 32 */ SDL_SCANCODE_D,
+ /* 33 */ SDL_SCANCODE_F,
+ /* 34 */ SDL_SCANCODE_G,
+ /* 35 */ SDL_SCANCODE_H,
+ /* 36 */ SDL_SCANCODE_J,
+ /* 37 */ SDL_SCANCODE_K,
+ /* 38 */ SDL_SCANCODE_L,
+ /* 39 */ SDL_SCANCODE_SEMICOLON,
+ /* 40 */ SDL_SCANCODE_APOSTROPHE,
+ /* 41 */ SDL_SCANCODE_GRAVE,
+ /* 42 */ SDL_SCANCODE_LSHIFT,
+ /* 43 */ SDL_SCANCODE_BACKSLASH,
+ /* 44 */ SDL_SCANCODE_Z,
+ /* 45 */ SDL_SCANCODE_X,
+ /* 46 */ SDL_SCANCODE_C,
+ /* 47 */ SDL_SCANCODE_V,
+ /* 48 */ SDL_SCANCODE_B,
+ /* 49 */ SDL_SCANCODE_N,
+ /* 50 */ SDL_SCANCODE_M,
+ /* 51 */ SDL_SCANCODE_COMMA,
+ /* 52 */ SDL_SCANCODE_PERIOD,
+ /* 53 */ SDL_SCANCODE_SLASH,
+ /* 54 */ SDL_SCANCODE_RSHIFT,
+ /* 55 */ SDL_SCANCODE_KP_MULTIPLY,
+ /* 56 */ SDL_SCANCODE_LALT,
+ /* 57 */ SDL_SCANCODE_SPACE,
+ /* 58 */ SDL_SCANCODE_CAPSLOCK,
+ /* 59 */ SDL_SCANCODE_F1,
+ /* 60 */ SDL_SCANCODE_F2,
+ /* 61 */ SDL_SCANCODE_F3,
+ /* 62 */ SDL_SCANCODE_F4,
+ /* 63 */ SDL_SCANCODE_F5,
+ /* 64 */ SDL_SCANCODE_F6,
+ /* 65 */ SDL_SCANCODE_F7,
+ /* 66 */ SDL_SCANCODE_F8,
+ /* 67 */ SDL_SCANCODE_F9,
+ /* 68 */ SDL_SCANCODE_F10,
+ /* 69 */ SDL_SCANCODE_NUMLOCKCLEAR,
+ /* 70 */ SDL_SCANCODE_SCROLLLOCK,
+ /* 71 */ SDL_SCANCODE_KP_7,
+ /* 72 */ SDL_SCANCODE_KP_8,
+ /* 73 */ SDL_SCANCODE_KP_9,
+ /* 74 */ SDL_SCANCODE_KP_MINUS,
+ /* 75 */ SDL_SCANCODE_KP_4,
+ /* 76 */ SDL_SCANCODE_KP_5,
+ /* 77 */ SDL_SCANCODE_KP_6,
+ /* 78 */ SDL_SCANCODE_KP_PLUS,
+ /* 79 */ SDL_SCANCODE_KP_1,
+ /* 80 */ SDL_SCANCODE_KP_2,
+ /* 81 */ SDL_SCANCODE_KP_3,
+ /* 82 */ SDL_SCANCODE_KP_0,
+ /* 83 */ SDL_SCANCODE_KP_PERIOD,
+ /* 84 */ SDL_SCANCODE_SYSREQ, /* ???? */
+ /* 85 */ SDL_SCANCODE_MODE, /* ???? */
+ /* 86 */ SDL_SCANCODE_NONUSBACKSLASH,
+ /* 87 */ SDL_SCANCODE_F11,
+ /* 88 */ SDL_SCANCODE_F12,
+ /* 89 */ SDL_SCANCODE_INTERNATIONAL1, /* \_ */
+ /* 90 */ SDL_SCANCODE_UNKNOWN, /* Katakana */
+ /* 91 */ SDL_SCANCODE_UNKNOWN, /* Hiragana */
+ /* 92 */ SDL_SCANCODE_INTERNATIONAL4, /* Henkan_Mode */
+ /* 93 */ SDL_SCANCODE_INTERNATIONAL2, /* Hiragana_Katakana */
+ /* 94 */ SDL_SCANCODE_INTERNATIONAL5, /* Muhenkan */
+ /* 95 */ SDL_SCANCODE_UNKNOWN,
+ /* 96 */ SDL_SCANCODE_KP_ENTER,
+ /* 97 */ SDL_SCANCODE_RCTRL,
+ /* 98 */ SDL_SCANCODE_KP_DIVIDE,
+ /* 99 */ SDL_SCANCODE_PRINTSCREEN,
+ /* 100 */ SDL_SCANCODE_RALT, /* ISO_Level3_Shift, ALTGR, RALT */
+ /* 101 */ SDL_SCANCODE_UNKNOWN, /* Linefeed */
+ /* 102 */ SDL_SCANCODE_HOME,
+ /* 103 */ SDL_SCANCODE_UP,
+ /* 104 */ SDL_SCANCODE_PAGEUP,
+ /* 105 */ SDL_SCANCODE_LEFT,
+ /* 106 */ SDL_SCANCODE_RIGHT,
+ /* 107 */ SDL_SCANCODE_END,
+ /* 108 */ SDL_SCANCODE_DOWN,
+ /* 109 */ SDL_SCANCODE_PAGEDOWN,
+ /* 110 */ SDL_SCANCODE_INSERT,
+ /* 111 */ SDL_SCANCODE_DELETE,
+ /* 112 */ SDL_SCANCODE_UNKNOWN,
+ /* 113 */ SDL_SCANCODE_MUTE,
+ /* 114 */ SDL_SCANCODE_VOLUMEDOWN,
+ /* 115 */ SDL_SCANCODE_VOLUMEUP,
+ /* 116 */ SDL_SCANCODE_POWER,
+ /* 117 */ SDL_SCANCODE_KP_EQUALS,
+ /* 118 */ SDL_SCANCODE_UNKNOWN, /* plusminus */
+ /* 119 */ SDL_SCANCODE_PAUSE,
+ /* 120 */ SDL_SCANCODE_UNKNOWN, /* XF86LaunchA */
+ /* 121 */ SDL_SCANCODE_UNKNOWN, /* KP_Decimal */
+ /* 122 */ SDL_SCANCODE_UNKNOWN, /* Hangul */
+ /* 123 */ SDL_SCANCODE_UNKNOWN, /* Hangul_Hanja */
+ /* 124 */ SDL_SCANCODE_INTERNATIONAL3, /* Yen */
+ /* 125 */ SDL_SCANCODE_LGUI,
+ /* 126 */ SDL_SCANCODE_RGUI,
+ /* 127 */ SDL_SCANCODE_APPLICATION,
+ /* 128 */ SDL_SCANCODE_CANCEL,
+ /* 129 */ SDL_SCANCODE_AGAIN,
+ /* 130 */ SDL_SCANCODE_UNKNOWN, /* SunProps */
+ /* 131 */ SDL_SCANCODE_UNDO,
+ /* 132 */ SDL_SCANCODE_UNKNOWN, /* SunFront */
+ /* 133 */ SDL_SCANCODE_COPY,
+ /* 134 */ SDL_SCANCODE_UNKNOWN, /* SunOpen */
+ /* 135 */ SDL_SCANCODE_PASTE,
+ /* 136 */ SDL_SCANCODE_FIND,
+ /* 137 */ SDL_SCANCODE_CUT,
+ /* 138 */ SDL_SCANCODE_HELP,
+ /* 139 */ SDL_SCANCODE_UNKNOWN, /* XF86MenuKB */
+ /* 140 */ SDL_SCANCODE_CALCULATOR,
+ /* 141 */ SDL_SCANCODE_UNKNOWN,
+ /* 142 */ SDL_SCANCODE_SLEEP,
+ /* 143 */ SDL_SCANCODE_UNKNOWN, /* XF86WakeUp */
+ /* 144 */ SDL_SCANCODE_UNKNOWN, /* XF86Explorer */
+ /* 145 */ SDL_SCANCODE_UNKNOWN, /* XF86Send */
+ /* 146 */ SDL_SCANCODE_UNKNOWN,
+ /* 147 */ SDL_SCANCODE_UNKNOWN, /* XF86Xfer */
+ /* 148 */ SDL_SCANCODE_APP1, /* XF86Launch1 */
+ /* 149 */ SDL_SCANCODE_APP2, /* XF86Launch2 */
+ /* 150 */ SDL_SCANCODE_WWW,
+ /* 151 */ SDL_SCANCODE_UNKNOWN, /* XF86DOS */
+ /* 152 */ SDL_SCANCODE_UNKNOWN, /* XF86ScreenSaver */
+ /* 153 */ SDL_SCANCODE_UNKNOWN,
+ /* 154 */ SDL_SCANCODE_UNKNOWN, /* XF86RotateWindows */
+ /* 155 */ SDL_SCANCODE_MAIL,
+ /* 156 */ SDL_SCANCODE_AC_BOOKMARKS, /* XF86Favorites */
+ /* 157 */ SDL_SCANCODE_COMPUTER,
+ /* 158 */ SDL_SCANCODE_AC_BACK,
+ /* 159 */ SDL_SCANCODE_AC_FORWARD,
+ /* 160 */ SDL_SCANCODE_UNKNOWN,
+ /* 161 */ SDL_SCANCODE_EJECT,
+ /* 162 */ SDL_SCANCODE_EJECT,
+ /* 163 */ SDL_SCANCODE_AUDIONEXT,
+ /* 164 */ SDL_SCANCODE_AUDIOPLAY,
+ /* 165 */ SDL_SCANCODE_AUDIOPREV,
+ /* 166 */ SDL_SCANCODE_AUDIOSTOP,
+ /* 167 */ SDL_SCANCODE_UNKNOWN, /* XF86AudioRecord */
+ /* 168 */ SDL_SCANCODE_AUDIOREWIND, /* XF86AudioRewind */
+ /* 169 */ SDL_SCANCODE_UNKNOWN, /* XF86Phone */
+ /* 170 */ SDL_SCANCODE_UNKNOWN,
+ /* 171 */ SDL_SCANCODE_F13, /* XF86Tools */
+ /* 172 */ SDL_SCANCODE_AC_HOME,
+ /* 173 */ SDL_SCANCODE_AC_REFRESH,
+ /* 174 */ SDL_SCANCODE_UNKNOWN, /* XF86Close */
+ /* 175 */ SDL_SCANCODE_UNKNOWN,
+ /* 176 */ SDL_SCANCODE_UNKNOWN,
+ /* 177 */ SDL_SCANCODE_UNKNOWN, /* XF86ScrollUp */
+ /* 178 */ SDL_SCANCODE_UNKNOWN, /* XF86ScrollDown */
+ /* 179 */ SDL_SCANCODE_UNKNOWN, /* parenleft */
+ /* 180 */ SDL_SCANCODE_UNKNOWN, /* parenright */
+ /* 181 */ SDL_SCANCODE_UNKNOWN, /* XF86New */
+ /* 182 */ SDL_SCANCODE_AGAIN,
+ /* 183 */ SDL_SCANCODE_F13, /* XF86Tools */
+ /* 184 */ SDL_SCANCODE_F14, /* XF86Launch5 */
+ /* 185 */ SDL_SCANCODE_F15, /* XF86Launch6 */
+ /* 186 */ SDL_SCANCODE_F16, /* XF86Launch7 */
+ /* 187 */ SDL_SCANCODE_F17, /* XF86Launch8 */
+ /* 188 */ SDL_SCANCODE_F18, /* XF86Launch9 */
+ /* 189 */ SDL_SCANCODE_F19, /* null keysym */
+ /* 190 */ SDL_SCANCODE_UNKNOWN,
+ /* 191 */ SDL_SCANCODE_UNKNOWN,
+ /* 192 */ SDL_SCANCODE_UNKNOWN, /* XF86TouchpadToggle */
+ /* 193 */ SDL_SCANCODE_UNKNOWN,
+ /* 194 */ SDL_SCANCODE_UNKNOWN,
+ /* 195 */ SDL_SCANCODE_MODE,
+ /* 196 */ SDL_SCANCODE_UNKNOWN,
+ /* 197 */ SDL_SCANCODE_UNKNOWN,
+ /* 198 */ SDL_SCANCODE_UNKNOWN,
+ /* 199 */ SDL_SCANCODE_UNKNOWN,
+ /* 200 */ SDL_SCANCODE_AUDIOPLAY,
+ /* 201 */ SDL_SCANCODE_UNKNOWN, /* XF86AudioPause */
+ /* 202 */ SDL_SCANCODE_UNKNOWN, /* XF86Launch3 */
+ /* 203 */ SDL_SCANCODE_UNKNOWN, /* XF86Launch4 */
+ /* 204 */ SDL_SCANCODE_UNKNOWN, /* XF86LaunchB */
+ /* 205 */ SDL_SCANCODE_UNKNOWN, /* XF86Suspend */
+ /* 206 */ SDL_SCANCODE_UNKNOWN, /* XF86Close */
+ /* 207 */ SDL_SCANCODE_AUDIOPLAY,
+ /* 208 */ SDL_SCANCODE_AUDIONEXT,
+ /* 209 */ SDL_SCANCODE_UNKNOWN,
+ /* 210 */ SDL_SCANCODE_PRINTSCREEN,
+ /* 211 */ SDL_SCANCODE_UNKNOWN,
+ /* 212 */ SDL_SCANCODE_UNKNOWN, /* XF86WebCam */
+ /* 213 */ SDL_SCANCODE_UNKNOWN,
+ /* 214 */ SDL_SCANCODE_UNKNOWN,
+ /* 215 */ SDL_SCANCODE_MAIL,
+ /* 216 */ SDL_SCANCODE_UNKNOWN,
+ /* 217 */ SDL_SCANCODE_AC_SEARCH,
+ /* 218 */ SDL_SCANCODE_UNKNOWN,
+ /* 219 */ SDL_SCANCODE_UNKNOWN, /* XF86Finance */
+ /* 220 */ SDL_SCANCODE_UNKNOWN,
+ /* 221 */ SDL_SCANCODE_UNKNOWN, /* XF86Shop */
+ /* 222 */ SDL_SCANCODE_UNKNOWN,
+ /* 223 */ SDL_SCANCODE_STOP,
+ /* 224 */ SDL_SCANCODE_BRIGHTNESSDOWN,
+ /* 225 */ SDL_SCANCODE_BRIGHTNESSUP,
+ /* 226 */ SDL_SCANCODE_MEDIASELECT,
+ /* 227 */ SDL_SCANCODE_DISPLAYSWITCH,
+ /* 228 */ SDL_SCANCODE_KBDILLUMTOGGLE,
+ /* 229 */ SDL_SCANCODE_KBDILLUMDOWN,
+ /* 230 */ SDL_SCANCODE_KBDILLUMUP,
+ /* 231 */ SDL_SCANCODE_UNKNOWN, /* XF86Send */
+ /* 232 */ SDL_SCANCODE_UNKNOWN, /* XF86Reply */
+ /* 233 */ SDL_SCANCODE_UNKNOWN, /* XF86MailForward */
+ /* 234 */ SDL_SCANCODE_UNKNOWN, /* XF86Save */
+ /* 235 */ SDL_SCANCODE_UNKNOWN, /* XF86Documents */
+ /* 236 */ SDL_SCANCODE_UNKNOWN, /* XF86Battery */
+ /* 237 */ SDL_SCANCODE_UNKNOWN, /* XF86Bluetooth */
+ /* 238 */ SDL_SCANCODE_UNKNOWN, /* XF86WLAN */
+};
+
+/* Xvnc / Xtightvnc scancodes from xmodmap -pk */
+static const SDL_Scancode xvnc_scancode_table[] = {
+ /* 0 */ SDL_SCANCODE_LCTRL,
+ /* 1 */ SDL_SCANCODE_RCTRL,
+ /* 2 */ SDL_SCANCODE_LSHIFT,
+ /* 3 */ SDL_SCANCODE_RSHIFT,
+ /* 4 */ SDL_SCANCODE_UNKNOWN, /* Meta_L */
+ /* 5 */ SDL_SCANCODE_UNKNOWN, /* Meta_R */
+ /* 6 */ SDL_SCANCODE_LALT,
+ /* 7 */ SDL_SCANCODE_RALT,
+ /* 8 */ SDL_SCANCODE_SPACE,
+ /* 9 */ SDL_SCANCODE_0,
+ /* 10 */ SDL_SCANCODE_1,
+ /* 11 */ SDL_SCANCODE_2,
+ /* 12 */ SDL_SCANCODE_3,
+ /* 13 */ SDL_SCANCODE_4,
+ /* 14 */ SDL_SCANCODE_5,
+ /* 15 */ SDL_SCANCODE_6,
+ /* 16 */ SDL_SCANCODE_7,
+ /* 17 */ SDL_SCANCODE_8,
+ /* 18 */ SDL_SCANCODE_9,
+ /* 19 */ SDL_SCANCODE_MINUS,
+ /* 20 */ SDL_SCANCODE_EQUALS,
+ /* 21 */ SDL_SCANCODE_LEFTBRACKET,
+ /* 22 */ SDL_SCANCODE_RIGHTBRACKET,
+ /* 23 */ SDL_SCANCODE_SEMICOLON,
+ /* 24 */ SDL_SCANCODE_APOSTROPHE,
+ /* 25 */ SDL_SCANCODE_GRAVE,
+ /* 26 */ SDL_SCANCODE_COMMA,
+ /* 27 */ SDL_SCANCODE_PERIOD,
+ /* 28 */ SDL_SCANCODE_SLASH,
+ /* 29 */ SDL_SCANCODE_BACKSLASH,
+ /* 30 */ SDL_SCANCODE_A,
+ /* 31 */ SDL_SCANCODE_B,
+ /* 32 */ SDL_SCANCODE_C,
+ /* 33 */ SDL_SCANCODE_D,
+ /* 34 */ SDL_SCANCODE_E,
+ /* 35 */ SDL_SCANCODE_F,
+ /* 36 */ SDL_SCANCODE_G,
+ /* 37 */ SDL_SCANCODE_H,
+ /* 38 */ SDL_SCANCODE_I,
+ /* 39 */ SDL_SCANCODE_J,
+ /* 40 */ SDL_SCANCODE_K,
+ /* 41 */ SDL_SCANCODE_L,
+ /* 42 */ SDL_SCANCODE_M,
+ /* 43 */ SDL_SCANCODE_N,
+ /* 44 */ SDL_SCANCODE_O,
+ /* 45 */ SDL_SCANCODE_P,
+ /* 46 */ SDL_SCANCODE_Q,
+ /* 47 */ SDL_SCANCODE_R,
+ /* 48 */ SDL_SCANCODE_S,
+ /* 49 */ SDL_SCANCODE_T,
+ /* 50 */ SDL_SCANCODE_U,
+ /* 51 */ SDL_SCANCODE_V,
+ /* 52 */ SDL_SCANCODE_W,
+ /* 53 */ SDL_SCANCODE_X,
+ /* 54 */ SDL_SCANCODE_Y,
+ /* 55 */ SDL_SCANCODE_Z,
+ /* 56 */ SDL_SCANCODE_BACKSPACE,
+ /* 57 */ SDL_SCANCODE_RETURN,
+ /* 58 */ SDL_SCANCODE_TAB,
+ /* 59 */ SDL_SCANCODE_ESCAPE,
+ /* 60 */ SDL_SCANCODE_DELETE,
+ /* 61 */ SDL_SCANCODE_HOME,
+ /* 62 */ SDL_SCANCODE_END,
+ /* 63 */ SDL_SCANCODE_PAGEUP,
+ /* 64 */ SDL_SCANCODE_PAGEDOWN,
+ /* 65 */ SDL_SCANCODE_UP,
+ /* 66 */ SDL_SCANCODE_DOWN,
+ /* 67 */ SDL_SCANCODE_LEFT,
+ /* 68 */ SDL_SCANCODE_RIGHT,
+ /* 69 */ SDL_SCANCODE_F1,
+ /* 70 */ SDL_SCANCODE_F2,
+ /* 71 */ SDL_SCANCODE_F3,
+ /* 72 */ SDL_SCANCODE_F4,
+ /* 73 */ SDL_SCANCODE_F5,
+ /* 74 */ SDL_SCANCODE_F6,
+ /* 75 */ SDL_SCANCODE_F7,
+ /* 76 */ SDL_SCANCODE_F8,
+ /* 77 */ SDL_SCANCODE_F9,
+ /* 78 */ SDL_SCANCODE_F10,
+ /* 79 */ SDL_SCANCODE_F11,
+ /* 80 */ SDL_SCANCODE_F12,
+};
+
+/* *INDENT-ON* */
diff --git a/src/3rdparty/SDL2/src/file/SDL_rwops.c b/src/3rdparty/SDL2/src/file/SDL_rwops.c
new file mode 100644
index 0000000..cf5d3aa
--- /dev/null
+++ b/src/3rdparty/SDL2/src/file/SDL_rwops.c
@@ -0,0 +1,867 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/* We won't get fseeko64 on QNX if _LARGEFILE64_SOURCE is defined, but the
+ configure script knows the C runtime has it and enables it. */
+#ifndef __QNXNTO__
+/* Need this so Linux systems define fseek64o, ftell64o and off64_t */
+#define _LARGEFILE64_SOURCE
+#endif
+
+#include "../SDL_internal.h"
+
+#if defined(__WIN32__)
+#include "../core/windows/SDL_windows.h"
+#endif
+
+#ifdef HAVE_STDIO_H
+#include <stdio.h>
+#endif
+
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+
+/* This file provides a general interface for SDL to read and write
+ data sources. It can easily be extended to files, memory, etc.
+*/
+
+#include "SDL_endian.h"
+#include "SDL_rwops.h"
+
+#ifdef __APPLE__
+#include "cocoa/SDL_rwopsbundlesupport.h"
+#endif /* __APPLE__ */
+
+#ifdef __ANDROID__
+#include "../core/android/SDL_android.h"
+#include "SDL_system.h"
+#endif
+
+#if __NACL__
+#include "nacl_io/nacl_io.h"
+#endif
+
+#ifdef __WIN32__
+
+/* Functions to read/write Win32 API file pointers */
+
+#ifndef INVALID_SET_FILE_POINTER
+#define INVALID_SET_FILE_POINTER 0xFFFFFFFF
+#endif
+
+#define READAHEAD_BUFFER_SIZE 1024
+
+static int SDLCALL
+windows_file_open(SDL_RWops * context, const char *filename, const char *mode)
+{
+ UINT old_error_mode;
+ HANDLE h;
+ DWORD r_right, w_right;
+ DWORD must_exist, truncate;
+ int a_mode;
+
+ if (!context)
+ return -1; /* failed (invalid call) */
+
+ context->hidden.windowsio.h = INVALID_HANDLE_VALUE; /* mark this as unusable */
+ context->hidden.windowsio.buffer.data = NULL;
+ context->hidden.windowsio.buffer.size = 0;
+ context->hidden.windowsio.buffer.left = 0;
+
+ /* "r" = reading, file must exist */
+ /* "w" = writing, truncate existing, file may not exist */
+ /* "r+"= reading or writing, file must exist */
+ /* "a" = writing, append file may not exist */
+ /* "a+"= append + read, file may not exist */
+ /* "w+" = read, write, truncate. file may not exist */
+
+ must_exist = (SDL_strchr(mode, 'r') != NULL) ? OPEN_EXISTING : 0;
+ truncate = (SDL_strchr(mode, 'w') != NULL) ? CREATE_ALWAYS : 0;
+ r_right = (SDL_strchr(mode, '+') != NULL
+ || must_exist) ? GENERIC_READ : 0;
+ a_mode = (SDL_strchr(mode, 'a') != NULL) ? OPEN_ALWAYS : 0;
+ w_right = (a_mode || SDL_strchr(mode, '+')
+ || truncate) ? GENERIC_WRITE : 0;
+
+ if (!r_right && !w_right) /* inconsistent mode */
+ return -1; /* failed (invalid call) */
+
+ context->hidden.windowsio.buffer.data =
+ (char *) SDL_malloc(READAHEAD_BUFFER_SIZE);
+ if (!context->hidden.windowsio.buffer.data) {
+ return SDL_OutOfMemory();
+ }
+ /* Do not open a dialog box if failure */
+ old_error_mode =
+ SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS);
+
+ {
+ LPTSTR tstr = WIN_UTF8ToString(filename);
+ h = CreateFile(tstr, (w_right | r_right),
+ (w_right) ? 0 : FILE_SHARE_READ, NULL,
+ (must_exist | truncate | a_mode),
+ FILE_ATTRIBUTE_NORMAL, NULL);
+ SDL_free(tstr);
+ }
+
+ /* restore old behavior */
+ SetErrorMode(old_error_mode);
+
+ if (h == INVALID_HANDLE_VALUE) {
+ SDL_free(context->hidden.windowsio.buffer.data);
+ context->hidden.windowsio.buffer.data = NULL;
+ SDL_SetError("Couldn't open %s", filename);
+ return -2; /* failed (CreateFile) */
+ }
+ context->hidden.windowsio.h = h;
+ context->hidden.windowsio.append = a_mode ? SDL_TRUE : SDL_FALSE;
+
+ return 0; /* ok */
+}
+
+static Sint64 SDLCALL
+windows_file_size(SDL_RWops * context)
+{
+ LARGE_INTEGER size;
+
+ if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) {
+ return SDL_SetError("windows_file_size: invalid context/file not opened");
+ }
+
+ if (!GetFileSizeEx(context->hidden.windowsio.h, &size)) {
+ return WIN_SetError("windows_file_size");
+ }
+
+ return size.QuadPart;
+}
+
+static Sint64 SDLCALL
+windows_file_seek(SDL_RWops * context, Sint64 offset, int whence)
+{
+ DWORD windowswhence;
+ LARGE_INTEGER windowsoffset;
+
+ if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE) {
+ return SDL_SetError("windows_file_seek: invalid context/file not opened");
+ }
+
+ /* FIXME: We may be able to satisfy the seek within buffered data */
+ if (whence == RW_SEEK_CUR && context->hidden.windowsio.buffer.left) {
+ offset -= (long)context->hidden.windowsio.buffer.left;
+ }
+ context->hidden.windowsio.buffer.left = 0;
+
+ switch (whence) {
+ case RW_SEEK_SET:
+ windowswhence = FILE_BEGIN;
+ break;
+ case RW_SEEK_CUR:
+ windowswhence = FILE_CURRENT;
+ break;
+ case RW_SEEK_END:
+ windowswhence = FILE_END;
+ break;
+ default:
+ return SDL_SetError("windows_file_seek: Unknown value for 'whence'");
+ }
+
+ windowsoffset.QuadPart = offset;
+ if (!SetFilePointerEx(context->hidden.windowsio.h, windowsoffset, &windowsoffset, windowswhence)) {
+ return WIN_SetError("windows_file_seek");
+ }
+ return windowsoffset.QuadPart;
+}
+
+static size_t SDLCALL
+windows_file_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
+{
+ size_t total_need;
+ size_t total_read = 0;
+ size_t read_ahead;
+ DWORD byte_read;
+
+ total_need = size * maxnum;
+
+ if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE
+ || !total_need)
+ return 0;
+
+ if (context->hidden.windowsio.buffer.left > 0) {
+ void *data = (char *) context->hidden.windowsio.buffer.data +
+ context->hidden.windowsio.buffer.size -
+ context->hidden.windowsio.buffer.left;
+ read_ahead =
+ SDL_min(total_need, context->hidden.windowsio.buffer.left);
+ SDL_memcpy(ptr, data, read_ahead);
+ context->hidden.windowsio.buffer.left -= read_ahead;
+
+ if (read_ahead == total_need) {
+ return maxnum;
+ }
+ ptr = (char *) ptr + read_ahead;
+ total_need -= read_ahead;
+ total_read += read_ahead;
+ }
+
+ if (total_need < READAHEAD_BUFFER_SIZE) {
+ if (!ReadFile
+ (context->hidden.windowsio.h, context->hidden.windowsio.buffer.data,
+ READAHEAD_BUFFER_SIZE, &byte_read, NULL)) {
+ SDL_Error(SDL_EFREAD);
+ return 0;
+ }
+ read_ahead = SDL_min(total_need, (int) byte_read);
+ SDL_memcpy(ptr, context->hidden.windowsio.buffer.data, read_ahead);
+ context->hidden.windowsio.buffer.size = byte_read;
+ context->hidden.windowsio.buffer.left = byte_read - read_ahead;
+ total_read += read_ahead;
+ } else {
+ if (!ReadFile
+ (context->hidden.windowsio.h, ptr, (DWORD)total_need, &byte_read, NULL)) {
+ SDL_Error(SDL_EFREAD);
+ return 0;
+ }
+ total_read += byte_read;
+ }
+ return (total_read / size);
+}
+
+static size_t SDLCALL
+windows_file_write(SDL_RWops * context, const void *ptr, size_t size,
+ size_t num)
+{
+
+ size_t total_bytes;
+ DWORD byte_written;
+ size_t nwritten;
+
+ total_bytes = size * num;
+
+ if (!context || context->hidden.windowsio.h == INVALID_HANDLE_VALUE
+ || total_bytes <= 0 || !size)
+ return 0;
+
+ if (context->hidden.windowsio.buffer.left) {
+ SetFilePointer(context->hidden.windowsio.h,
+ -(LONG)context->hidden.windowsio.buffer.left, NULL,
+ FILE_CURRENT);
+ context->hidden.windowsio.buffer.left = 0;
+ }
+
+ /* if in append mode, we must go to the EOF before write */
+ if (context->hidden.windowsio.append) {
+ if (SetFilePointer(context->hidden.windowsio.h, 0L, NULL, FILE_END) ==
+ INVALID_SET_FILE_POINTER) {
+ SDL_Error(SDL_EFWRITE);
+ return 0;
+ }
+ }
+
+ if (!WriteFile
+ (context->hidden.windowsio.h, ptr, (DWORD)total_bytes, &byte_written, NULL)) {
+ SDL_Error(SDL_EFWRITE);
+ return 0;
+ }
+
+ nwritten = byte_written / size;
+ return nwritten;
+}
+
+static int SDLCALL
+windows_file_close(SDL_RWops * context)
+{
+
+ if (context) {
+ if (context->hidden.windowsio.h != INVALID_HANDLE_VALUE) {
+ CloseHandle(context->hidden.windowsio.h);
+ context->hidden.windowsio.h = INVALID_HANDLE_VALUE; /* to be sure */
+ }
+ SDL_free(context->hidden.windowsio.buffer.data);
+ context->hidden.windowsio.buffer.data = NULL;
+ SDL_FreeRW(context);
+ }
+ return 0;
+}
+#endif /* __WIN32__ */
+
+#ifdef HAVE_STDIO_H
+
+#ifdef HAVE_FOPEN64
+#define fopen fopen64
+#endif
+#ifdef HAVE_FSEEKO64
+#define fseek_off_t off64_t
+#define fseek fseeko64
+#define ftell ftello64
+#elif defined(HAVE_FSEEKO)
+#if defined(OFF_MIN) && defined(OFF_MAX)
+#define FSEEK_OFF_MIN OFF_MIN
+#define FSEEK_OFF_MAX OFF_MAX
+#elif defined(HAVE_LIMITS_H)
+/* POSIX doesn't specify the minimum and maximum macros for off_t so
+ * we have to improvise and dance around implementation-defined
+ * behavior. This may fail if the off_t type has padding bits or
+ * is not a two's-complement representation. The compilers will detect
+ * and eliminate the dead code if off_t has 64 bits.
+ */
+#define FSEEK_OFF_MAX (((((off_t)1 << (sizeof(off_t) * CHAR_BIT - 2)) - 1) << 1) + 1)
+#define FSEEK_OFF_MIN (-(FSEEK_OFF_MAX) - 1)
+#endif
+#define fseek_off_t off_t
+#define fseek fseeko
+#define ftell ftello
+#elif defined(HAVE__FSEEKI64)
+#define fseek_off_t __int64
+#define fseek _fseeki64
+#define ftell _ftelli64
+#else
+#ifdef HAVE_LIMITS_H
+#define FSEEK_OFF_MIN LONG_MIN
+#define FSEEK_OFF_MAX LONG_MAX
+#endif
+#define fseek_off_t long
+#endif
+
+/* Functions to read/write stdio file pointers */
+
+static Sint64 SDLCALL
+stdio_size(SDL_RWops * context)
+{
+ Sint64 pos, size;
+
+ pos = SDL_RWseek(context, 0, RW_SEEK_CUR);
+ if (pos < 0) {
+ return -1;
+ }
+ size = SDL_RWseek(context, 0, RW_SEEK_END);
+
+ SDL_RWseek(context, pos, RW_SEEK_SET);
+ return size;
+}
+
+static Sint64 SDLCALL
+stdio_seek(SDL_RWops * context, Sint64 offset, int whence)
+{
+#if defined(FSEEK_OFF_MIN) && defined(FSEEK_OFF_MAX)
+ if (offset < (Sint64)(FSEEK_OFF_MIN) || offset > (Sint64)(FSEEK_OFF_MAX)) {
+ return SDL_SetError("Seek offset out of range");
+ }
+#endif
+
+ if (fseek(context->hidden.stdio.fp, (fseek_off_t)offset, whence) == 0) {
+ Sint64 pos = ftell(context->hidden.stdio.fp);
+ if (pos < 0) {
+ return SDL_SetError("Couldn't get stream offset");
+ }
+ return pos;
+ }
+ return SDL_Error(SDL_EFSEEK);
+}
+
+static size_t SDLCALL
+stdio_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
+{
+ size_t nread;
+
+ nread = fread(ptr, size, maxnum, context->hidden.stdio.fp);
+ if (nread == 0 && ferror(context->hidden.stdio.fp)) {
+ SDL_Error(SDL_EFREAD);
+ }
+ return nread;
+}
+
+static size_t SDLCALL
+stdio_write(SDL_RWops * context, const void *ptr, size_t size, size_t num)
+{
+ size_t nwrote;
+
+ nwrote = fwrite(ptr, size, num, context->hidden.stdio.fp);
+ if (nwrote == 0 && ferror(context->hidden.stdio.fp)) {
+ SDL_Error(SDL_EFWRITE);
+ }
+ return nwrote;
+}
+
+static int SDLCALL
+stdio_close(SDL_RWops * context)
+{
+ int status = 0;
+ if (context) {
+ if (context->hidden.stdio.autoclose) {
+ /* WARNING: Check the return value here! */
+ if (fclose(context->hidden.stdio.fp) != 0) {
+ status = SDL_Error(SDL_EFWRITE);
+ }
+ }
+ SDL_FreeRW(context);
+ }
+ return status;
+}
+#endif /* !HAVE_STDIO_H */
+
+/* Functions to read/write memory pointers */
+
+static Sint64 SDLCALL
+mem_size(SDL_RWops * context)
+{
+ return (Sint64)(context->hidden.mem.stop - context->hidden.mem.base);
+}
+
+static Sint64 SDLCALL
+mem_seek(SDL_RWops * context, Sint64 offset, int whence)
+{
+ Uint8 *newpos;
+
+ switch (whence) {
+ case RW_SEEK_SET:
+ newpos = context->hidden.mem.base + offset;
+ break;
+ case RW_SEEK_CUR:
+ newpos = context->hidden.mem.here + offset;
+ break;
+ case RW_SEEK_END:
+ newpos = context->hidden.mem.stop + offset;
+ break;
+ default:
+ return SDL_SetError("Unknown value for 'whence'");
+ }
+ if (newpos < context->hidden.mem.base) {
+ newpos = context->hidden.mem.base;
+ }
+ if (newpos > context->hidden.mem.stop) {
+ newpos = context->hidden.mem.stop;
+ }
+ context->hidden.mem.here = newpos;
+ return (Sint64)(context->hidden.mem.here - context->hidden.mem.base);
+}
+
+static size_t SDLCALL
+mem_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
+{
+ size_t total_bytes;
+ size_t mem_available;
+
+ total_bytes = (maxnum * size);
+ if ((maxnum <= 0) || (size <= 0)
+ || ((total_bytes / maxnum) != (size_t) size)) {
+ return 0;
+ }
+
+ mem_available = (context->hidden.mem.stop - context->hidden.mem.here);
+ if (total_bytes > mem_available) {
+ total_bytes = mem_available;
+ }
+
+ SDL_memcpy(ptr, context->hidden.mem.here, total_bytes);
+ context->hidden.mem.here += total_bytes;
+
+ return (total_bytes / size);
+}
+
+static size_t SDLCALL
+mem_write(SDL_RWops * context, const void *ptr, size_t size, size_t num)
+{
+ if ((context->hidden.mem.here + (num * size)) > context->hidden.mem.stop) {
+ num = (context->hidden.mem.stop - context->hidden.mem.here) / size;
+ }
+ SDL_memcpy(context->hidden.mem.here, ptr, num * size);
+ context->hidden.mem.here += num * size;
+ return num;
+}
+
+static size_t SDLCALL
+mem_writeconst(SDL_RWops * context, const void *ptr, size_t size, size_t num)
+{
+ SDL_SetError("Can't write to read-only memory");
+ return 0;
+}
+
+static int SDLCALL
+mem_close(SDL_RWops * context)
+{
+ if (context) {
+ SDL_FreeRW(context);
+ }
+ return 0;
+}
+
+
+/* Functions to create SDL_RWops structures from various data sources */
+
+SDL_RWops *
+SDL_RWFromFile(const char *file, const char *mode)
+{
+ SDL_RWops *rwops = NULL;
+ if (!file || !*file || !mode || !*mode) {
+ SDL_SetError("SDL_RWFromFile(): No file or no mode specified");
+ return NULL;
+ }
+#if defined(__ANDROID__)
+#ifdef HAVE_STDIO_H
+ /* Try to open the file on the filesystem first */
+ if (*file == '/') {
+ FILE *fp = fopen(file, mode);
+ if (fp) {
+ return SDL_RWFromFP(fp, 1);
+ }
+ } else {
+ /* Try opening it from internal storage if it's a relative path */
+ char *path;
+ FILE *fp;
+
+ path = SDL_stack_alloc(char, PATH_MAX);
+ if (path) {
+ SDL_snprintf(path, PATH_MAX, "%s/%s",
+ SDL_AndroidGetInternalStoragePath(), file);
+ fp = fopen(path, mode);
+ SDL_stack_free(path);
+ if (fp) {
+ return SDL_RWFromFP(fp, 1);
+ }
+ }
+ }
+#endif /* HAVE_STDIO_H */
+
+ /* Try to open the file from the asset system */
+ rwops = SDL_AllocRW();
+ if (!rwops)
+ return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
+ if (Android_JNI_FileOpen(rwops, file, mode) < 0) {
+ SDL_FreeRW(rwops);
+ return NULL;
+ }
+ rwops->size = Android_JNI_FileSize;
+ rwops->seek = Android_JNI_FileSeek;
+ rwops->read = Android_JNI_FileRead;
+ rwops->write = Android_JNI_FileWrite;
+ rwops->close = Android_JNI_FileClose;
+ rwops->type = SDL_RWOPS_JNIFILE;
+
+#elif defined(__WIN32__)
+ rwops = SDL_AllocRW();
+ if (!rwops)
+ return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
+ if (windows_file_open(rwops, file, mode) < 0) {
+ SDL_FreeRW(rwops);
+ return NULL;
+ }
+ rwops->size = windows_file_size;
+ rwops->seek = windows_file_seek;
+ rwops->read = windows_file_read;
+ rwops->write = windows_file_write;
+ rwops->close = windows_file_close;
+ rwops->type = SDL_RWOPS_WINFILE;
+
+#elif HAVE_STDIO_H
+ {
+ #ifdef __APPLE__
+ FILE *fp = SDL_OpenFPFromBundleOrFallback(file, mode);
+ #elif __WINRT__
+ FILE *fp = NULL;
+ fopen_s(&fp, file, mode);
+ #else
+ FILE *fp = fopen(file, mode);
+ #endif
+ if (fp == NULL) {
+ SDL_SetError("Couldn't open %s", file);
+ } else {
+ rwops = SDL_RWFromFP(fp, 1);
+ }
+ }
+#else
+ SDL_SetError("SDL not compiled with stdio support");
+#endif /* !HAVE_STDIO_H */
+
+ return rwops;
+}
+
+#ifdef HAVE_STDIO_H
+SDL_RWops *
+SDL_RWFromFP(FILE * fp, SDL_bool autoclose)
+{
+ SDL_RWops *rwops = NULL;
+
+ rwops = SDL_AllocRW();
+ if (rwops != NULL) {
+ rwops->size = stdio_size;
+ rwops->seek = stdio_seek;
+ rwops->read = stdio_read;
+ rwops->write = stdio_write;
+ rwops->close = stdio_close;
+ rwops->hidden.stdio.fp = fp;
+ rwops->hidden.stdio.autoclose = autoclose;
+ rwops->type = SDL_RWOPS_STDFILE;
+ }
+ return rwops;
+}
+#else
+SDL_RWops *
+SDL_RWFromFP(void * fp, SDL_bool autoclose)
+{
+ SDL_SetError("SDL not compiled with stdio support");
+ return NULL;
+}
+#endif /* HAVE_STDIO_H */
+
+SDL_RWops *
+SDL_RWFromMem(void *mem, int size)
+{
+ SDL_RWops *rwops = NULL;
+ if (!mem) {
+ SDL_InvalidParamError("mem");
+ return rwops;
+ }
+ if (!size) {
+ SDL_InvalidParamError("size");
+ return rwops;
+ }
+
+ rwops = SDL_AllocRW();
+ if (rwops != NULL) {
+ rwops->size = mem_size;
+ rwops->seek = mem_seek;
+ rwops->read = mem_read;
+ rwops->write = mem_write;
+ rwops->close = mem_close;
+ rwops->hidden.mem.base = (Uint8 *) mem;
+ rwops->hidden.mem.here = rwops->hidden.mem.base;
+ rwops->hidden.mem.stop = rwops->hidden.mem.base + size;
+ rwops->type = SDL_RWOPS_MEMORY;
+ }
+ return rwops;
+}
+
+SDL_RWops *
+SDL_RWFromConstMem(const void *mem, int size)
+{
+ SDL_RWops *rwops = NULL;
+ if (!mem) {
+ SDL_InvalidParamError("mem");
+ return rwops;
+ }
+ if (!size) {
+ SDL_InvalidParamError("size");
+ return rwops;
+ }
+
+ rwops = SDL_AllocRW();
+ if (rwops != NULL) {
+ rwops->size = mem_size;
+ rwops->seek = mem_seek;
+ rwops->read = mem_read;
+ rwops->write = mem_writeconst;
+ rwops->close = mem_close;
+ rwops->hidden.mem.base = (Uint8 *) mem;
+ rwops->hidden.mem.here = rwops->hidden.mem.base;
+ rwops->hidden.mem.stop = rwops->hidden.mem.base + size;
+ rwops->type = SDL_RWOPS_MEMORY_RO;
+ }
+ return rwops;
+}
+
+SDL_RWops *
+SDL_AllocRW(void)
+{
+ SDL_RWops *area;
+
+ area = (SDL_RWops *) SDL_malloc(sizeof *area);
+ if (area == NULL) {
+ SDL_OutOfMemory();
+ } else {
+ area->type = SDL_RWOPS_UNKNOWN;
+ }
+ return area;
+}
+
+void
+SDL_FreeRW(SDL_RWops * area)
+{
+ SDL_free(area);
+}
+
+/* Load all the data from an SDL data stream */
+void *
+SDL_LoadFile_RW(SDL_RWops * src, size_t *datasize, int freesrc)
+{
+ const int FILE_CHUNK_SIZE = 1024;
+ Sint64 size;
+ size_t size_read, size_total;
+ void *data = NULL, *newdata;
+
+ if (!src) {
+ SDL_InvalidParamError("src");
+ return NULL;
+ }
+
+ size = SDL_RWsize(src);
+ if (size < 0) {
+ size = FILE_CHUNK_SIZE;
+ }
+ data = SDL_malloc((size_t)(size + 1));
+
+ size_total = 0;
+ for (;;) {
+ if ((((Sint64)size_total) + FILE_CHUNK_SIZE) > size) {
+ size = (size_total + FILE_CHUNK_SIZE);
+ newdata = SDL_realloc(data, (size_t)(size + 1));
+ if (!newdata) {
+ SDL_free(data);
+ data = NULL;
+ SDL_OutOfMemory();
+ goto done;
+ }
+ data = newdata;
+ }
+
+ size_read = SDL_RWread(src, (char *)data+size_total, 1, (size_t)(size-size_total));
+ if (size_read == 0) {
+ break;
+ }
+ size_total += size_read;
+ }
+
+ if (datasize) {
+ *datasize = size_total;
+ }
+ ((char *)data)[size_total] = '\0';
+
+done:
+ if (freesrc && src) {
+ SDL_RWclose(src);
+ }
+ return data;
+}
+
+/* Functions for dynamically reading and writing endian-specific values */
+
+Uint8
+SDL_ReadU8(SDL_RWops * src)
+{
+ Uint8 value = 0;
+
+ SDL_RWread(src, &value, sizeof (value), 1);
+ return value;
+}
+
+Uint16
+SDL_ReadLE16(SDL_RWops * src)
+{
+ Uint16 value = 0;
+
+ SDL_RWread(src, &value, sizeof (value), 1);
+ return SDL_SwapLE16(value);
+}
+
+Uint16
+SDL_ReadBE16(SDL_RWops * src)
+{
+ Uint16 value = 0;
+
+ SDL_RWread(src, &value, sizeof (value), 1);
+ return SDL_SwapBE16(value);
+}
+
+Uint32
+SDL_ReadLE32(SDL_RWops * src)
+{
+ Uint32 value = 0;
+
+ SDL_RWread(src, &value, sizeof (value), 1);
+ return SDL_SwapLE32(value);
+}
+
+Uint32
+SDL_ReadBE32(SDL_RWops * src)
+{
+ Uint32 value = 0;
+
+ SDL_RWread(src, &value, sizeof (value), 1);
+ return SDL_SwapBE32(value);
+}
+
+Uint64
+SDL_ReadLE64(SDL_RWops * src)
+{
+ Uint64 value = 0;
+
+ SDL_RWread(src, &value, sizeof (value), 1);
+ return SDL_SwapLE64(value);
+}
+
+Uint64
+SDL_ReadBE64(SDL_RWops * src)
+{
+ Uint64 value = 0;
+
+ SDL_RWread(src, &value, sizeof (value), 1);
+ return SDL_SwapBE64(value);
+}
+
+size_t
+SDL_WriteU8(SDL_RWops * dst, Uint8 value)
+{
+ return SDL_RWwrite(dst, &value, sizeof (value), 1);
+}
+
+size_t
+SDL_WriteLE16(SDL_RWops * dst, Uint16 value)
+{
+ const Uint16 swapped = SDL_SwapLE16(value);
+ return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
+}
+
+size_t
+SDL_WriteBE16(SDL_RWops * dst, Uint16 value)
+{
+ const Uint16 swapped = SDL_SwapBE16(value);
+ return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
+}
+
+size_t
+SDL_WriteLE32(SDL_RWops * dst, Uint32 value)
+{
+ const Uint32 swapped = SDL_SwapLE32(value);
+ return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
+}
+
+size_t
+SDL_WriteBE32(SDL_RWops * dst, Uint32 value)
+{
+ const Uint32 swapped = SDL_SwapBE32(value);
+ return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
+}
+
+size_t
+SDL_WriteLE64(SDL_RWops * dst, Uint64 value)
+{
+ const Uint64 swapped = SDL_SwapLE64(value);
+ return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
+}
+
+size_t
+SDL_WriteBE64(SDL_RWops * dst, Uint64 value)
+{
+ const Uint64 swapped = SDL_SwapBE64(value);
+ return SDL_RWwrite(dst, &swapped, sizeof (swapped), 1);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/file/cocoa/SDL_rwopsbundlesupport.h b/src/3rdparty/SDL2/src/file/cocoa/SDL_rwopsbundlesupport.h
new file mode 100644
index 0000000..64edc0d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/file/cocoa/SDL_rwopsbundlesupport.h
@@ -0,0 +1,30 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifdef __APPLE__
+
+#include <stdio.h>
+
+#ifndef SDL_rwopsbundlesupport_h
+#define SDL_rwopsbundlesupport_h
+FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode);
+#endif
+#endif
diff --git a/src/3rdparty/SDL2/src/file/cocoa/SDL_rwopsbundlesupport.m b/src/3rdparty/SDL2/src/file/cocoa/SDL_rwopsbundlesupport.m
new file mode 100644
index 0000000..8f1bf54
--- /dev/null
+++ b/src/3rdparty/SDL2/src/file/cocoa/SDL_rwopsbundlesupport.m
@@ -0,0 +1,62 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef __APPLE__
+#import <Foundation/Foundation.h>
+
+#include "SDL_rwopsbundlesupport.h"
+
+/* For proper OS X applications, the resources are contained inside the application bundle.
+ So the strategy is to first check the application bundle for the file, then fallback to the current working directory.
+ Note: One additional corner-case is if the resource is in a framework's resource bundle instead of the app.
+ We might want to use bundle identifiers, e.g. org.libsdl.sdl to get the bundle for the framework,
+ but we would somehow need to know what the bundle identifiers we need to search are.
+ Also, note the bundle layouts are different for iPhone and Mac.
+*/
+FILE* SDL_OpenFPFromBundleOrFallback(const char *file, const char *mode)
+{ @autoreleasepool
+{
+ FILE* fp = NULL;
+
+ /* If the file mode is writable, skip all the bundle stuff because generally the bundle is read-only. */
+ if(strcmp("r", mode) && strcmp("rb", mode)) {
+ return fopen(file, mode);
+ }
+
+ NSFileManager* file_manager = [NSFileManager defaultManager];
+ NSString* resource_path = [[NSBundle mainBundle] resourcePath];
+
+ NSString* ns_string_file_component = [file_manager stringWithFileSystemRepresentation:file length:strlen(file)];
+
+ NSString* full_path_with_file_to_try = [resource_path stringByAppendingPathComponent:ns_string_file_component];
+ if([file_manager fileExistsAtPath:full_path_with_file_to_try]) {
+ fp = fopen([full_path_with_file_to_try fileSystemRepresentation], mode);
+ } else {
+ fp = fopen(file, mode);
+ }
+
+ return fp;
+}}
+
+#endif /* __APPLE__ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/filesystem/android/SDL_sysfilesystem.c b/src/3rdparty/SDL2/src/filesystem/android/SDL_sysfilesystem.c
new file mode 100644
index 0000000..7f3f92d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/filesystem/android/SDL_sysfilesystem.c
@@ -0,0 +1,62 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_FILESYSTEM_ANDROID
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* System dependent filesystem routines */
+
+#include <unistd.h>
+
+#include "SDL_error.h"
+#include "SDL_filesystem.h"
+#include "SDL_system.h"
+
+
+char *
+SDL_GetBasePath(void)
+{
+ /* The current working directory is / on Android */
+ SDL_Unsupported();
+ return NULL;
+}
+
+char *
+SDL_GetPrefPath(const char *org, const char *app)
+{
+ const char *path = SDL_AndroidGetInternalStoragePath();
+ if (path) {
+ size_t pathlen = SDL_strlen(path)+2;
+ char *fullpath = (char *)SDL_malloc(pathlen);
+ if (!fullpath) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ SDL_snprintf(fullpath, pathlen, "%s/", path);
+ return fullpath;
+ }
+ return NULL;
+}
+
+#endif /* SDL_FILESYSTEM_ANDROID */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/filesystem/cocoa/SDL_sysfilesystem.m b/src/3rdparty/SDL2/src/filesystem/cocoa/SDL_sysfilesystem.m
new file mode 100644
index 0000000..6153a20
--- /dev/null
+++ b/src/3rdparty/SDL2/src/filesystem/cocoa/SDL_sysfilesystem.m
@@ -0,0 +1,117 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_FILESYSTEM_COCOA
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* System dependent filesystem routines */
+
+#include <Foundation/Foundation.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include "SDL_error.h"
+#include "SDL_stdinc.h"
+#include "SDL_filesystem.h"
+
+char *
+SDL_GetBasePath(void)
+{ @autoreleasepool
+{
+ NSBundle *bundle = [NSBundle mainBundle];
+ const char* baseType = [[[bundle infoDictionary] objectForKey:@"SDL_FILESYSTEM_BASE_DIR_TYPE"] UTF8String];
+ const char *base = NULL;
+ char *retval = NULL;
+
+ if (baseType == NULL) {
+ baseType = "resource";
+ }
+ if (SDL_strcasecmp(baseType, "bundle")==0) {
+ base = [[bundle bundlePath] fileSystemRepresentation];
+ } else if (SDL_strcasecmp(baseType, "parent")==0) {
+ base = [[[bundle bundlePath] stringByDeletingLastPathComponent] fileSystemRepresentation];
+ } else {
+ /* this returns the exedir for non-bundled and the resourceDir for bundled apps */
+ base = [[bundle resourcePath] fileSystemRepresentation];
+ }
+
+ if (base) {
+ const size_t len = SDL_strlen(base) + 2;
+ retval = (char *) SDL_malloc(len);
+ if (retval == NULL) {
+ SDL_OutOfMemory();
+ } else {
+ SDL_snprintf(retval, len, "%s/", base);
+ }
+ }
+
+ return retval;
+}}
+
+char *
+SDL_GetPrefPath(const char *org, const char *app)
+{ @autoreleasepool
+{
+ if (!app) {
+ SDL_InvalidParamError("app");
+ return NULL;
+ }
+ if (!org) {
+ org = "";
+ }
+
+ char *retval = NULL;
+ NSArray *array = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
+
+ if ([array count] > 0) { /* we only want the first item in the list. */
+ NSString *str = [array objectAtIndex:0];
+ const char *base = [str fileSystemRepresentation];
+ if (base) {
+ const size_t len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4;
+ retval = (char *) SDL_malloc(len);
+ if (retval == NULL) {
+ SDL_OutOfMemory();
+ } else {
+ char *ptr;
+ if (*org) {
+ SDL_snprintf(retval, len, "%s/%s/%s/", base, org, app);
+ } else {
+ SDL_snprintf(retval, len, "%s/%s/", base, app);
+ }
+ for (ptr = retval+1; *ptr; ptr++) {
+ if (*ptr == '/') {
+ *ptr = '\0';
+ mkdir(retval, 0700);
+ *ptr = '/';
+ }
+ }
+ mkdir(retval, 0700);
+ }
+ }
+ }
+
+ return retval;
+}}
+
+#endif /* SDL_FILESYSTEM_COCOA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/filesystem/dummy/SDL_sysfilesystem.c b/src/3rdparty/SDL2/src/filesystem/dummy/SDL_sysfilesystem.c
new file mode 100644
index 0000000..f4628a1
--- /dev/null
+++ b/src/3rdparty/SDL2/src/filesystem/dummy/SDL_sysfilesystem.c
@@ -0,0 +1,47 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if defined(SDL_FILESYSTEM_DUMMY) || defined(SDL_FILESYSTEM_DISABLED)
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* System dependent filesystem routines */
+
+#include "SDL_error.h"
+#include "SDL_filesystem.h"
+
+char *
+SDL_GetBasePath(void)
+{
+ SDL_Unsupported();
+ return NULL;
+}
+
+char *
+SDL_GetPrefPath(const char *org, const char *app)
+{
+ SDL_Unsupported();
+ return NULL;
+}
+
+#endif /* SDL_FILESYSTEM_DUMMY || SDL_FILESYSTEM_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/filesystem/emscripten/SDL_sysfilesystem.c b/src/3rdparty/SDL2/src/filesystem/emscripten/SDL_sysfilesystem.c
new file mode 100644
index 0000000..4ba57c1
--- /dev/null
+++ b/src/3rdparty/SDL2/src/filesystem/emscripten/SDL_sysfilesystem.c
@@ -0,0 +1,81 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_FILESYSTEM_EMSCRIPTEN
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* System dependent filesystem routines */
+#include <errno.h>
+#include <sys/stat.h>
+
+#include "SDL_error.h"
+#include "SDL_filesystem.h"
+
+#include <emscripten/emscripten.h>
+
+char *
+SDL_GetBasePath(void)
+{
+ char *retval = "/";
+ return SDL_strdup(retval);
+}
+
+char *
+SDL_GetPrefPath(const char *org, const char *app)
+{
+ const char *append = "/libsdl/";
+ char *retval;
+ size_t len = 0;
+
+ if (!app) {
+ SDL_InvalidParamError("app");
+ return NULL;
+ }
+ if (!org) {
+ org = "";
+ }
+
+ len = SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
+ retval = (char *) SDL_malloc(len);
+ if (!retval) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ if (*org) {
+ SDL_snprintf(retval, len, "%s%s/%s/", append, org, app);
+ } else {
+ SDL_snprintf(retval, len, "%s%s/", append, app);
+ }
+
+ if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
+ SDL_SetError("Couldn't create directory '%s': '%s'", retval, strerror(errno));
+ SDL_free(retval);
+ return NULL;
+ }
+
+ return retval;
+}
+
+#endif /* SDL_FILESYSTEM_EMSCRIPTEN */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/filesystem/haiku/SDL_sysfilesystem.cc b/src/3rdparty/SDL2/src/filesystem/haiku/SDL_sysfilesystem.cc
new file mode 100644
index 0000000..b56bc4b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/filesystem/haiku/SDL_sysfilesystem.cc
@@ -0,0 +1,110 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_FILESYSTEM_HAIKU
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* System dependent filesystem routines */
+
+#include <kernel/image.h>
+#include <storage/Directory.h>
+#include <storage/Entry.h>
+#include <storage/Path.h>
+
+#include "SDL_error.h"
+#include "SDL_stdinc.h"
+#include "SDL_assert.h"
+#include "SDL_filesystem.h"
+
+char *
+SDL_GetBasePath(void)
+{
+ image_info info;
+ int32 cookie = 0;
+
+ while (get_next_image_info(0, &cookie, &info) == B_OK) {
+ if (info.type == B_APP_IMAGE) {
+ break;
+ }
+ }
+
+ BEntry entry(info.name, true);
+ BPath path;
+ status_t rc = entry.GetPath(&path); /* (path) now has binary's path. */
+ SDL_assert(rc == B_OK);
+ rc = path.GetParent(&path); /* chop filename, keep directory. */
+ SDL_assert(rc == B_OK);
+ const char *str = path.Path();
+ SDL_assert(str != NULL);
+
+ const size_t len = SDL_strlen(str);
+ char *retval = (char *) SDL_malloc(len + 2);
+ if (!retval) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ SDL_memcpy(retval, str, len);
+ retval[len] = '/';
+ retval[len+1] = '\0';
+ return retval;
+}
+
+
+char *
+SDL_GetPrefPath(const char *org, const char *app)
+{
+ // !!! FIXME: is there a better way to do this?
+ const char *home = SDL_getenv("HOME");
+ const char *append = "/config/settings/";
+ size_t len = SDL_strlen(home);
+
+ if (!app) {
+ SDL_InvalidParamError("app");
+ return NULL;
+ }
+ if (!org) {
+ org = "";
+ }
+
+ if (!len || (home[len - 1] == '/')) {
+ ++append; // home empty or ends with separator, skip the one from append
+ }
+ len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
+ char *retval = (char *) SDL_malloc(len);
+ if (!retval) {
+ SDL_OutOfMemory();
+ } else {
+ if (*org) {
+ SDL_snprintf(retval, len, "%s%s%s/%s/", home, append, org, app);
+ } else {
+ SDL_snprintf(retval, len, "%s%s%s/", home, append, app);
+ }
+ create_directory(retval, 0700); // Haiku api: creates missing dirs
+ }
+
+ return retval;
+}
+
+#endif /* SDL_FILESYSTEM_HAIKU */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/filesystem/nacl/SDL_sysfilesystem.c b/src/3rdparty/SDL2/src/filesystem/nacl/SDL_sysfilesystem.c
new file mode 100644
index 0000000..f22ca75
--- /dev/null
+++ b/src/3rdparty/SDL2/src/filesystem/nacl/SDL_sysfilesystem.c
@@ -0,0 +1,43 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+#include "SDL_error.h"
+#include "SDL_filesystem.h"
+
+#ifdef SDL_FILESYSTEM_NACL
+
+char *
+SDL_GetBasePath(void)
+{
+ SDL_Unsupported();
+ return NULL;
+}
+
+char *
+SDL_GetPrefPath(const char *org, const char *app)
+{
+ SDL_Unsupported();
+ return NULL;
+}
+
+#endif /* SDL_FILESYSTEM_NACL */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/filesystem/unix/SDL_sysfilesystem.c b/src/3rdparty/SDL2/src/filesystem/unix/SDL_sysfilesystem.c
new file mode 100644
index 0000000..d6af39f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/filesystem/unix/SDL_sysfilesystem.c
@@ -0,0 +1,250 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_FILESYSTEM_UNIX
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* System dependent filesystem routines */
+
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <limits.h>
+#include <fcntl.h>
+
+#if defined(__FREEBSD__) || defined(__OPENBSD__)
+#include <sys/sysctl.h>
+#endif
+
+#include "SDL_error.h"
+#include "SDL_stdinc.h"
+#include "SDL_filesystem.h"
+#include "SDL_rwops.h"
+
+/* QNX's /proc/self/exefile is a text file and not a symlink. */
+#if !defined(__QNXNTO__)
+static char *
+readSymLink(const char *path)
+{
+ char *retval = NULL;
+ ssize_t len = 64;
+ ssize_t rc = -1;
+
+ while (1)
+ {
+ char *ptr = (char *) SDL_realloc(retval, (size_t) len);
+ if (ptr == NULL) {
+ SDL_OutOfMemory();
+ break;
+ }
+
+ retval = ptr;
+
+ rc = readlink(path, retval, len);
+ if (rc == -1) {
+ break; /* not a symlink, i/o error, etc. */
+ } else if (rc < len) {
+ retval[rc] = '\0'; /* readlink doesn't null-terminate. */
+ return retval; /* we're good to go. */
+ }
+
+ len *= 2; /* grow buffer, try again. */
+ }
+
+ SDL_free(retval);
+ return NULL;
+}
+#endif
+
+char *
+SDL_GetBasePath(void)
+{
+ char *retval = NULL;
+
+#if defined(__FREEBSD__)
+ char fullpath[PATH_MAX];
+ size_t buflen = sizeof (fullpath);
+ const int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
+ if (sysctl(mib, SDL_arraysize(mib), fullpath, &buflen, NULL, 0) != -1) {
+ retval = SDL_strdup(fullpath);
+ if (!retval) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ }
+#endif
+#if defined(__OPENBSD__)
+ char **retvalargs;
+ size_t len;
+ const int mib[] = { CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV };
+ if (sysctl(mib, 4, NULL, &len, NULL, 0) != -1) {
+ retvalargs = SDL_malloc(len);
+ if (!retvalargs) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ sysctl(mib, 4, retvalargs, &len, NULL, 0);
+ retval = SDL_malloc(PATH_MAX + 1);
+ if (retval)
+ realpath(retvalargs[0], retval);
+
+ SDL_free(retvalargs);
+ }
+#endif
+#if defined(__SOLARIS__)
+ const char *path = getexecname();
+ if ((path != NULL) && (path[0] == '/')) { /* must be absolute path... */
+ retval = SDL_strdup(path);
+ if (!retval) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ }
+#endif
+
+ /* is a Linux-style /proc filesystem available? */
+ if (!retval && (access("/proc", F_OK) == 0)) {
+ /* !!! FIXME: after 2.0.6 ships, let's delete this code and just
+ use the /proc/%llu version. There's no reason to have
+ two copies of this plus all the #ifdefs. --ryan. */
+#if defined(__FREEBSD__)
+ retval = readSymLink("/proc/curproc/file");
+#elif defined(__NETBSD__)
+ retval = readSymLink("/proc/curproc/exe");
+#elif defined(__QNXNTO__)
+ retval = SDL_LoadFile("/proc/self/exefile", NULL);
+#else
+ retval = readSymLink("/proc/self/exe"); /* linux. */
+ if (retval == NULL) {
+ /* older kernels don't have /proc/self ... try PID version... */
+ char path[64];
+ const int rc = (int) SDL_snprintf(path, sizeof(path),
+ "/proc/%llu/exe",
+ (unsigned long long) getpid());
+ if ( (rc > 0) && (rc < sizeof(path)) ) {
+ retval = readSymLink(path);
+ }
+ }
+#endif
+ }
+
+ /* If we had access to argv[0] here, we could check it for a path,
+ or troll through $PATH looking for it, too. */
+
+ if (retval != NULL) { /* chop off filename. */
+ char *ptr = SDL_strrchr(retval, '/');
+ if (ptr != NULL) {
+ *(ptr+1) = '\0';
+ } else { /* shouldn't happen, but just in case... */
+ SDL_free(retval);
+ retval = NULL;
+ }
+ }
+
+ if (retval != NULL) {
+ /* try to shrink buffer... */
+ char *ptr = (char *) SDL_realloc(retval, strlen(retval) + 1);
+ if (ptr != NULL)
+ retval = ptr; /* oh well if it failed. */
+ }
+
+ return retval;
+}
+
+char *
+SDL_GetPrefPath(const char *org, const char *app)
+{
+ /*
+ * We use XDG's base directory spec, even if you're not on Linux.
+ * This isn't strictly correct, but the results are relatively sane
+ * in any case.
+ *
+ * http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
+ */
+ const char *envr = SDL_getenv("XDG_DATA_HOME");
+ const char *append;
+ char *retval = NULL;
+ char *ptr = NULL;
+ size_t len = 0;
+
+ if (!app) {
+ SDL_InvalidParamError("app");
+ return NULL;
+ }
+ if (!org) {
+ org = "";
+ }
+
+ if (!envr) {
+ /* You end up with "$HOME/.local/share/Game Name 2" */
+ envr = SDL_getenv("HOME");
+ if (!envr) {
+ /* we could take heroic measures with /etc/passwd, but oh well. */
+ SDL_SetError("neither XDG_DATA_HOME nor HOME environment is set");
+ return NULL;
+ }
+ append = "/.local/share/";
+ } else {
+ append = "/";
+ }
+
+ len = SDL_strlen(envr);
+ if (envr[len - 1] == '/')
+ append += 1;
+
+ len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
+ retval = (char *) SDL_malloc(len);
+ if (!retval) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ if (*org) {
+ SDL_snprintf(retval, len, "%s%s%s/%s/", envr, append, org, app);
+ } else {
+ SDL_snprintf(retval, len, "%s%s%s/", envr, append, app);
+ }
+
+ for (ptr = retval+1; *ptr; ptr++) {
+ if (*ptr == '/') {
+ *ptr = '\0';
+ if (mkdir(retval, 0700) != 0 && errno != EEXIST)
+ goto error;
+ *ptr = '/';
+ }
+ }
+ if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
+error:
+ SDL_SetError("Couldn't create directory '%s': '%s'", retval, strerror(errno));
+ SDL_free(retval);
+ return NULL;
+ }
+
+ return retval;
+}
+
+#endif /* SDL_FILESYSTEM_UNIX */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/filesystem/windows/SDL_sysfilesystem.c b/src/3rdparty/SDL2/src/filesystem/windows/SDL_sysfilesystem.c
new file mode 100644
index 0000000..5219789
--- /dev/null
+++ b/src/3rdparty/SDL2/src/filesystem/windows/SDL_sysfilesystem.c
@@ -0,0 +1,192 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_FILESYSTEM_WINDOWS
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* System dependent filesystem routines */
+
+#include "../../core/windows/SDL_windows.h"
+#include <shlobj.h>
+
+#include "SDL_assert.h"
+#include "SDL_error.h"
+#include "SDL_stdinc.h"
+#include "SDL_filesystem.h"
+
+char *
+SDL_GetBasePath(void)
+{
+ typedef DWORD (WINAPI *GetModuleFileNameExW_t)(HANDLE, HMODULE, LPWSTR, DWORD);
+ GetModuleFileNameExW_t pGetModuleFileNameExW;
+ DWORD buflen = 128;
+ WCHAR *path = NULL;
+ HANDLE psapi = LoadLibrary(L"psapi.dll");
+ char *retval = NULL;
+ DWORD len = 0;
+ int i;
+
+ if (!psapi) {
+ WIN_SetError("Couldn't load psapi.dll");
+ return NULL;
+ }
+
+ pGetModuleFileNameExW = (GetModuleFileNameExW_t)GetProcAddress(psapi, "GetModuleFileNameExW");
+ if (!pGetModuleFileNameExW) {
+ WIN_SetError("Couldn't find GetModuleFileNameExW");
+ FreeLibrary(psapi);
+ return NULL;
+ }
+
+ while (SDL_TRUE) {
+ void *ptr = SDL_realloc(path, buflen * sizeof (WCHAR));
+ if (!ptr) {
+ SDL_free(path);
+ FreeLibrary(psapi);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ path = (WCHAR *) ptr;
+
+ len = pGetModuleFileNameExW(GetCurrentProcess(), NULL, path, buflen);
+ if (len != buflen) {
+ break;
+ }
+
+ /* buffer too small? Try again. */
+ buflen *= 2;
+ }
+
+ FreeLibrary(psapi);
+
+ if (len == 0) {
+ SDL_free(path);
+ WIN_SetError("Couldn't locate our .exe");
+ return NULL;
+ }
+
+ for (i = len-1; i > 0; i--) {
+ if (path[i] == '\\') {
+ break;
+ }
+ }
+
+ SDL_assert(i > 0); /* Should have been an absolute path. */
+ path[i+1] = '\0'; /* chop off filename. */
+
+ retval = WIN_StringToUTF8(path);
+ SDL_free(path);
+
+ return retval;
+}
+
+char *
+SDL_GetPrefPath(const char *org, const char *app)
+{
+ /*
+ * Vista and later has a new API for this, but SHGetFolderPath works there,
+ * and apparently just wraps the new API. This is the new way to do it:
+ *
+ * SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE,
+ * NULL, &wszPath);
+ */
+
+ WCHAR path[MAX_PATH];
+ char *retval = NULL;
+ WCHAR* worg = NULL;
+ WCHAR* wapp = NULL;
+ size_t new_wpath_len = 0;
+ BOOL api_result = FALSE;
+
+ if (!app) {
+ SDL_InvalidParamError("app");
+ return NULL;
+ }
+ if (!org) {
+ org = "";
+ }
+
+ if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path))) {
+ WIN_SetError("Couldn't locate our prefpath");
+ return NULL;
+ }
+
+ worg = WIN_UTF8ToString(org);
+ if (worg == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ wapp = WIN_UTF8ToString(app);
+ if (wapp == NULL) {
+ SDL_free(worg);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ new_wpath_len = lstrlenW(worg) + lstrlenW(wapp) + lstrlenW(path) + 3;
+
+ if ((new_wpath_len + 1) > MAX_PATH) {
+ SDL_free(worg);
+ SDL_free(wapp);
+ WIN_SetError("Path too long.");
+ return NULL;
+ }
+
+ if (*worg) {
+ lstrcatW(path, L"\\");
+ lstrcatW(path, worg);
+ }
+ SDL_free(worg);
+
+ api_result = CreateDirectoryW(path, NULL);
+ if (api_result == FALSE) {
+ if (GetLastError() != ERROR_ALREADY_EXISTS) {
+ SDL_free(wapp);
+ WIN_SetError("Couldn't create a prefpath.");
+ return NULL;
+ }
+ }
+
+ lstrcatW(path, L"\\");
+ lstrcatW(path, wapp);
+ SDL_free(wapp);
+
+ api_result = CreateDirectoryW(path, NULL);
+ if (api_result == FALSE) {
+ if (GetLastError() != ERROR_ALREADY_EXISTS) {
+ WIN_SetError("Couldn't create a prefpath.");
+ return NULL;
+ }
+ }
+
+ lstrcatW(path, L"\\");
+
+ retval = WIN_StringToUTF8(path);
+
+ return retval;
+}
+
+#endif /* SDL_FILESYSTEM_WINDOWS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/filesystem/winrt/SDL_sysfilesystem.cpp b/src/3rdparty/SDL2/src/filesystem/winrt/SDL_sysfilesystem.cpp
new file mode 100644
index 0000000..71818dd
--- /dev/null
+++ b/src/3rdparty/SDL2/src/filesystem/winrt/SDL_sysfilesystem.cpp
@@ -0,0 +1,233 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+/* TODO, WinRT: remove the need to compile this with C++/CX (/ZW) extensions, and if possible, without C++ at all
+*/
+
+#ifdef __WINRT__
+
+extern "C" {
+#include "SDL_filesystem.h"
+#include "SDL_error.h"
+#include "SDL_hints.h"
+#include "SDL_stdinc.h"
+#include "SDL_system.h"
+#include "../../core/windows/SDL_windows.h"
+}
+
+#include <string>
+#include <unordered_map>
+
+using namespace std;
+using namespace Windows::Storage;
+
+extern "C" const wchar_t *
+SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType)
+{
+ switch (pathType) {
+ case SDL_WINRT_PATH_INSTALLED_LOCATION:
+ {
+ static wstring path;
+ if (path.empty()) {
+ path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
+ }
+ return path.c_str();
+ }
+
+ case SDL_WINRT_PATH_LOCAL_FOLDER:
+ {
+ static wstring path;
+ if (path.empty()) {
+ path = ApplicationData::Current->LocalFolder->Path->Data();
+ }
+ return path.c_str();
+ }
+
+#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) || (NTDDI_VERSION > NTDDI_WIN8)
+ case SDL_WINRT_PATH_ROAMING_FOLDER:
+ {
+ static wstring path;
+ if (path.empty()) {
+ path = ApplicationData::Current->RoamingFolder->Path->Data();
+ }
+ return path.c_str();
+ }
+
+ case SDL_WINRT_PATH_TEMP_FOLDER:
+ {
+ static wstring path;
+ if (path.empty()) {
+ path = ApplicationData::Current->TemporaryFolder->Path->Data();
+ }
+ return path.c_str();
+ }
+#endif
+
+ default:
+ break;
+ }
+
+ SDL_Unsupported();
+ return NULL;
+}
+
+extern "C" const char *
+SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
+{
+ typedef unordered_map<SDL_WinRT_Path, string> UTF8PathMap;
+ static UTF8PathMap utf8Paths;
+
+ UTF8PathMap::iterator searchResult = utf8Paths.find(pathType);
+ if (searchResult != utf8Paths.end()) {
+ return searchResult->second.c_str();
+ }
+
+ const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType);
+ if (!ucs2Path) {
+ return NULL;
+ }
+
+ char * utf8Path = WIN_StringToUTF8(ucs2Path);
+ utf8Paths[pathType] = utf8Path;
+ SDL_free(utf8Path);
+ return utf8Paths[pathType].c_str();
+}
+
+extern "C" char *
+SDL_GetBasePath(void)
+{
+ const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_INSTALLED_LOCATION);
+ size_t destPathLen;
+ char * destPath = NULL;
+
+ if (!srcPath) {
+ SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError());
+ return NULL;
+ }
+
+ destPathLen = SDL_strlen(srcPath) + 2;
+ destPath = (char *) SDL_malloc(destPathLen);
+ if (!destPath) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ SDL_snprintf(destPath, destPathLen, "%s\\", srcPath);
+ return destPath;
+}
+
+extern "C" char *
+SDL_GetPrefPath(const char *org, const char *app)
+{
+ /* WinRT note: The 'SHGetFolderPath' API that is used in Windows 7 and
+ * earlier is not available on WinRT or Windows Phone. WinRT provides
+ * a similar API, but SHGetFolderPath can't be called, at least not
+ * without violating Microsoft's app-store requirements.
+ */
+
+ const WCHAR * srcPath = NULL;
+ WCHAR path[MAX_PATH];
+ char *retval = NULL;
+ WCHAR* worg = NULL;
+ WCHAR* wapp = NULL;
+ size_t new_wpath_len = 0;
+ BOOL api_result = FALSE;
+
+ if (!app) {
+ SDL_InvalidParamError("app");
+ return NULL;
+ }
+ if (!org) {
+ org = "";
+ }
+
+ srcPath = SDL_WinRTGetFSPathUNICODE(SDL_WINRT_PATH_LOCAL_FOLDER);
+ if ( ! srcPath) {
+ SDL_SetError("Unable to find a source path");
+ return NULL;
+ }
+
+ if (SDL_wcslen(srcPath) >= MAX_PATH) {
+ SDL_SetError("Path too long.");
+ return NULL;
+ }
+ SDL_wcslcpy(path, srcPath, SDL_arraysize(path));
+
+ worg = WIN_UTF8ToString(org);
+ if (worg == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ wapp = WIN_UTF8ToString(app);
+ if (wapp == NULL) {
+ SDL_free(worg);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ new_wpath_len = SDL_wcslen(worg) + SDL_wcslen(wapp) + SDL_wcslen(path) + 3;
+
+ if ((new_wpath_len + 1) > MAX_PATH) {
+ SDL_free(worg);
+ SDL_free(wapp);
+ SDL_SetError("Path too long.");
+ return NULL;
+ }
+
+ if (*worg) {
+ SDL_wcslcat(path, L"\\", new_wpath_len + 1);
+ SDL_wcslcat(path, worg, new_wpath_len + 1);
+ SDL_free(worg);
+ }
+
+ api_result = CreateDirectoryW(path, NULL);
+ if (api_result == FALSE) {
+ if (GetLastError() != ERROR_ALREADY_EXISTS) {
+ SDL_free(wapp);
+ WIN_SetError("Couldn't create a prefpath.");
+ return NULL;
+ }
+ }
+
+ SDL_wcslcat(path, L"\\", new_wpath_len + 1);
+ SDL_wcslcat(path, wapp, new_wpath_len + 1);
+ SDL_free(wapp);
+
+ api_result = CreateDirectoryW(path, NULL);
+ if (api_result == FALSE) {
+ if (GetLastError() != ERROR_ALREADY_EXISTS) {
+ WIN_SetError("Couldn't create a prefpath.");
+ return NULL;
+ }
+ }
+
+ SDL_wcslcat(path, L"\\", new_wpath_len + 1);
+
+ retval = WIN_StringToUTF8(path);
+
+ return retval;
+}
+
+#endif /* __WINRT__ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/haptic/SDL_haptic.c b/src/3rdparty/SDL2/src/haptic/SDL_haptic.c
new file mode 100644
index 0000000..4988c30
--- /dev/null
+++ b/src/3rdparty/SDL2/src/haptic/SDL_haptic.c
@@ -0,0 +1,849 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "SDL_syshaptic.h"
+#include "SDL_haptic_c.h"
+#include "../joystick/SDL_joystick_c.h" /* For SDL_PrivateJoystickValid */
+#include "SDL_assert.h"
+
+/* Global for SDL_windowshaptic.c */
+SDL_Haptic *SDL_haptics = NULL;
+
+/*
+ * Initializes the Haptic devices.
+ */
+int
+SDL_HapticInit(void)
+{
+ int status;
+
+ status = SDL_SYS_HapticInit();
+ if (status >= 0) {
+ status = 0;
+ }
+
+ return status;
+}
+
+
+/*
+ * Checks to see if the haptic device is valid
+ */
+static int
+ValidHaptic(SDL_Haptic * haptic)
+{
+ int valid;
+ SDL_Haptic *hapticlist;
+
+ valid = 0;
+ if (haptic != NULL) {
+ hapticlist = SDL_haptics;
+ while ( hapticlist )
+ {
+ if (hapticlist == haptic) {
+ valid = 1;
+ break;
+ }
+ hapticlist = hapticlist->next;
+ }
+ }
+
+ /* Create the error here. */
+ if (valid == 0) {
+ SDL_SetError("Haptic: Invalid haptic device identifier");
+ }
+
+ return valid;
+}
+
+
+/*
+ * Returns the number of available devices.
+ */
+int
+SDL_NumHaptics(void)
+{
+ return SDL_SYS_NumHaptics();
+}
+
+
+/*
+ * Gets the name of a Haptic device by index.
+ */
+const char *
+SDL_HapticName(int device_index)
+{
+ if ((device_index < 0) || (device_index >= SDL_NumHaptics())) {
+ SDL_SetError("Haptic: There are %d haptic devices available",
+ SDL_NumHaptics());
+ return NULL;
+ }
+ return SDL_SYS_HapticName(device_index);
+}
+
+
+/*
+ * Opens a Haptic device.
+ */
+SDL_Haptic *
+SDL_HapticOpen(int device_index)
+{
+ SDL_Haptic *haptic;
+ SDL_Haptic *hapticlist;
+
+ if ((device_index < 0) || (device_index >= SDL_NumHaptics())) {
+ SDL_SetError("Haptic: There are %d haptic devices available",
+ SDL_NumHaptics());
+ return NULL;
+ }
+
+ hapticlist = SDL_haptics;
+ /* If the haptic is already open, return it
+ * TODO: Should we create haptic instance IDs like the Joystick API?
+ */
+ while ( hapticlist )
+ {
+ if (device_index == hapticlist->index) {
+ haptic = hapticlist;
+ ++haptic->ref_count;
+ return haptic;
+ }
+ hapticlist = hapticlist->next;
+ }
+
+ /* Create the haptic device */
+ haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
+ if (haptic == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ /* Initialize the haptic device */
+ SDL_memset(haptic, 0, (sizeof *haptic));
+ haptic->rumble_id = -1;
+ haptic->index = device_index;
+ if (SDL_SYS_HapticOpen(haptic) < 0) {
+ SDL_free(haptic);
+ return NULL;
+ }
+
+ /* Add haptic to list */
+ ++haptic->ref_count;
+ /* Link the haptic in the list */
+ haptic->next = SDL_haptics;
+ SDL_haptics = haptic;
+
+ /* Disable autocenter and set gain to max. */
+ if (haptic->supported & SDL_HAPTIC_GAIN)
+ SDL_HapticSetGain(haptic, 100);
+ if (haptic->supported & SDL_HAPTIC_AUTOCENTER)
+ SDL_HapticSetAutocenter(haptic, 0);
+
+ return haptic;
+}
+
+
+/*
+ * Returns 1 if the device has been opened.
+ */
+int
+SDL_HapticOpened(int device_index)
+{
+ int opened;
+ SDL_Haptic *hapticlist;
+
+ /* Make sure it's valid. */
+ if ((device_index < 0) || (device_index >= SDL_NumHaptics())) {
+ SDL_SetError("Haptic: There are %d haptic devices available",
+ SDL_NumHaptics());
+ return 0;
+ }
+
+ opened = 0;
+ hapticlist = SDL_haptics;
+ /* TODO Should this use an instance ID? */
+ while ( hapticlist )
+ {
+ if (hapticlist->index == (Uint8) device_index) {
+ opened = 1;
+ break;
+ }
+ hapticlist = hapticlist->next;
+ }
+ return opened;
+}
+
+
+/*
+ * Returns the index to a haptic device.
+ */
+int
+SDL_HapticIndex(SDL_Haptic * haptic)
+{
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ return haptic->index;
+}
+
+
+/*
+ * Returns SDL_TRUE if mouse is haptic, SDL_FALSE if it isn't.
+ */
+int
+SDL_MouseIsHaptic(void)
+{
+ if (SDL_SYS_HapticMouse() < 0)
+ return SDL_FALSE;
+ return SDL_TRUE;
+}
+
+
+/*
+ * Returns the haptic device if mouse is haptic or NULL elsewise.
+ */
+SDL_Haptic *
+SDL_HapticOpenFromMouse(void)
+{
+ int device_index;
+
+ device_index = SDL_SYS_HapticMouse();
+
+ if (device_index < 0) {
+ SDL_SetError("Haptic: Mouse isn't a haptic device.");
+ return NULL;
+ }
+
+ return SDL_HapticOpen(device_index);
+}
+
+
+/*
+ * Returns SDL_TRUE if joystick has haptic features.
+ */
+int
+SDL_JoystickIsHaptic(SDL_Joystick * joystick)
+{
+ int ret;
+
+ /* Must be a valid joystick */
+ if (!SDL_PrivateJoystickValid(joystick)) {
+ return -1;
+ }
+
+ ret = SDL_SYS_JoystickIsHaptic(joystick);
+
+ if (ret > 0)
+ return SDL_TRUE;
+ else if (ret == 0)
+ return SDL_FALSE;
+ else
+ return -1;
+}
+
+
+/*
+ * Opens a haptic device from a joystick.
+ */
+SDL_Haptic *
+SDL_HapticOpenFromJoystick(SDL_Joystick * joystick)
+{
+ SDL_Haptic *haptic;
+ SDL_Haptic *hapticlist;
+
+ /* Make sure there is room. */
+ if (SDL_NumHaptics() <= 0) {
+ SDL_SetError("Haptic: There are %d haptic devices available",
+ SDL_NumHaptics());
+ return NULL;
+ }
+
+ /* Must be a valid joystick */
+ if (!SDL_PrivateJoystickValid(joystick)) {
+ SDL_SetError("Haptic: Joystick isn't valid.");
+ return NULL;
+ }
+
+ /* Joystick must be haptic */
+ if (SDL_SYS_JoystickIsHaptic(joystick) <= 0) {
+ SDL_SetError("Haptic: Joystick isn't a haptic device.");
+ return NULL;
+ }
+
+ hapticlist = SDL_haptics;
+ /* Check to see if joystick's haptic is already open */
+ while ( hapticlist )
+ {
+ if (SDL_SYS_JoystickSameHaptic(hapticlist, joystick)) {
+ haptic = hapticlist;
+ ++haptic->ref_count;
+ return haptic;
+ }
+ hapticlist = hapticlist->next;
+ }
+
+ /* Create the haptic device */
+ haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
+ if (haptic == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ /* Initialize the haptic device */
+ SDL_memset(haptic, 0, sizeof(SDL_Haptic));
+ haptic->rumble_id = -1;
+ if (SDL_SYS_HapticOpenFromJoystick(haptic, joystick) < 0) {
+ SDL_SetError("Haptic: SDL_SYS_HapticOpenFromJoystick failed.");
+ SDL_free(haptic);
+ return NULL;
+ }
+
+ /* Add haptic to list */
+ ++haptic->ref_count;
+ /* Link the haptic in the list */
+ haptic->next = SDL_haptics;
+ SDL_haptics = haptic;
+
+ return haptic;
+}
+
+
+/*
+ * Closes a SDL_Haptic device.
+ */
+void
+SDL_HapticClose(SDL_Haptic * haptic)
+{
+ int i;
+ SDL_Haptic *hapticlist;
+ SDL_Haptic *hapticlistprev;
+
+ /* Must be valid */
+ if (!ValidHaptic(haptic)) {
+ return;
+ }
+
+ /* Check if it's still in use */
+ if (--haptic->ref_count > 0) {
+ return;
+ }
+
+ /* Close it, properly removing effects if needed */
+ for (i = 0; i < haptic->neffects; i++) {
+ if (haptic->effects[i].hweffect != NULL) {
+ SDL_HapticDestroyEffect(haptic, i);
+ }
+ }
+ SDL_SYS_HapticClose(haptic);
+
+ /* Remove from the list */
+ hapticlist = SDL_haptics;
+ hapticlistprev = NULL;
+ while ( hapticlist )
+ {
+ if (haptic == hapticlist)
+ {
+ if ( hapticlistprev )
+ {
+ /* unlink this entry */
+ hapticlistprev->next = hapticlist->next;
+ }
+ else
+ {
+ SDL_haptics = haptic->next;
+ }
+
+ break;
+ }
+ hapticlistprev = hapticlist;
+ hapticlist = hapticlist->next;
+ }
+
+ /* Free */
+ SDL_free(haptic);
+}
+
+/*
+ * Cleans up after the subsystem.
+ */
+void
+SDL_HapticQuit(void)
+{
+ SDL_SYS_HapticQuit();
+ SDL_assert(SDL_haptics == NULL);
+ SDL_haptics = NULL;
+}
+
+/*
+ * Returns the number of effects a haptic device has.
+ */
+int
+SDL_HapticNumEffects(SDL_Haptic * haptic)
+{
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ return haptic->neffects;
+}
+
+
+/*
+ * Returns the number of effects a haptic device can play.
+ */
+int
+SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic)
+{
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ return haptic->nplaying;
+}
+
+
+/*
+ * Returns supported effects by the device.
+ */
+unsigned int
+SDL_HapticQuery(SDL_Haptic * haptic)
+{
+ if (!ValidHaptic(haptic)) {
+ return 0; /* same as if no effects were supported */
+ }
+
+ return haptic->supported;
+}
+
+
+/*
+ * Returns the number of axis on the device.
+ */
+int
+SDL_HapticNumAxes(SDL_Haptic * haptic)
+{
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ return haptic->naxes;
+}
+
+/*
+ * Checks to see if the device can support the effect.
+ */
+int
+SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect)
+{
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ if ((haptic->supported & effect->type) != 0)
+ return SDL_TRUE;
+ return SDL_FALSE;
+}
+
+/*
+ * Creates a new haptic effect.
+ */
+int
+SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect)
+{
+ int i;
+
+ /* Check for device validity. */
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ /* Check to see if effect is supported */
+ if (SDL_HapticEffectSupported(haptic, effect) == SDL_FALSE) {
+ return SDL_SetError("Haptic: Effect not supported by haptic device.");
+ }
+
+ /* See if there's a free slot */
+ for (i = 0; i < haptic->neffects; i++) {
+ if (haptic->effects[i].hweffect == NULL) {
+
+ /* Now let the backend create the real effect */
+ if (SDL_SYS_HapticNewEffect(haptic, &haptic->effects[i], effect)
+ != 0) {
+ return -1; /* Backend failed to create effect */
+ }
+
+ SDL_memcpy(&haptic->effects[i].effect, effect,
+ sizeof(SDL_HapticEffect));
+ return i;
+ }
+ }
+
+ return SDL_SetError("Haptic: Device has no free space left.");
+}
+
+/*
+ * Checks to see if an effect is valid.
+ */
+static int
+ValidEffect(SDL_Haptic * haptic, int effect)
+{
+ if ((effect < 0) || (effect >= haptic->neffects)) {
+ SDL_SetError("Haptic: Invalid effect identifier.");
+ return 0;
+ }
+ return 1;
+}
+
+/*
+ * Updates an effect.
+ */
+int
+SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect,
+ SDL_HapticEffect * data)
+{
+ if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
+ return -1;
+ }
+
+ /* Can't change type dynamically. */
+ if (data->type != haptic->effects[effect].effect.type) {
+ return SDL_SetError("Haptic: Updating effect type is illegal.");
+ }
+
+ /* Updates the effect */
+ if (SDL_SYS_HapticUpdateEffect(haptic, &haptic->effects[effect], data) <
+ 0) {
+ return -1;
+ }
+
+ SDL_memcpy(&haptic->effects[effect].effect, data,
+ sizeof(SDL_HapticEffect));
+ return 0;
+}
+
+
+/*
+ * Runs the haptic effect on the device.
+ */
+int
+SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, Uint32 iterations)
+{
+ if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
+ return -1;
+ }
+
+ /* Run the effect */
+ if (SDL_SYS_HapticRunEffect(haptic, &haptic->effects[effect], iterations)
+ < 0) {
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * Stops the haptic effect on the device.
+ */
+int
+SDL_HapticStopEffect(SDL_Haptic * haptic, int effect)
+{
+ if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
+ return -1;
+ }
+
+ /* Stop the effect */
+ if (SDL_SYS_HapticStopEffect(haptic, &haptic->effects[effect]) < 0) {
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * Gets rid of a haptic effect.
+ */
+void
+SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect)
+{
+ if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
+ return;
+ }
+
+ /* Not allocated */
+ if (haptic->effects[effect].hweffect == NULL) {
+ return;
+ }
+
+ SDL_SYS_HapticDestroyEffect(haptic, &haptic->effects[effect]);
+}
+
+/*
+ * Gets the status of a haptic effect.
+ */
+int
+SDL_HapticGetEffectStatus(SDL_Haptic * haptic, int effect)
+{
+ if (!ValidHaptic(haptic) || !ValidEffect(haptic, effect)) {
+ return -1;
+ }
+
+ if ((haptic->supported & SDL_HAPTIC_STATUS) == 0) {
+ return SDL_SetError("Haptic: Device does not support status queries.");
+ }
+
+ return SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]);
+}
+
+/*
+ * Sets the global gain of the device.
+ */
+int
+SDL_HapticSetGain(SDL_Haptic * haptic, int gain)
+{
+ const char *env;
+ int real_gain, max_gain;
+
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ if ((haptic->supported & SDL_HAPTIC_GAIN) == 0) {
+ return SDL_SetError("Haptic: Device does not support setting gain.");
+ }
+
+ if ((gain < 0) || (gain > 100)) {
+ return SDL_SetError("Haptic: Gain must be between 0 and 100.");
+ }
+
+ /* We use the envvar to get the maximum gain. */
+ env = SDL_getenv("SDL_HAPTIC_GAIN_MAX");
+ if (env != NULL) {
+ max_gain = SDL_atoi(env);
+
+ /* Check for sanity. */
+ if (max_gain < 0)
+ max_gain = 0;
+ else if (max_gain > 100)
+ max_gain = 100;
+
+ /* We'll scale it linearly with SDL_HAPTIC_GAIN_MAX */
+ real_gain = (gain * max_gain) / 100;
+ } else {
+ real_gain = gain;
+ }
+
+ if (SDL_SYS_HapticSetGain(haptic, real_gain) < 0) {
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * Makes the device autocenter, 0 disables.
+ */
+int
+SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
+{
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ if ((haptic->supported & SDL_HAPTIC_AUTOCENTER) == 0) {
+ return SDL_SetError("Haptic: Device does not support setting autocenter.");
+ }
+
+ if ((autocenter < 0) || (autocenter > 100)) {
+ return SDL_SetError("Haptic: Autocenter must be between 0 and 100.");
+ }
+
+ if (SDL_SYS_HapticSetAutocenter(haptic, autocenter) < 0) {
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * Pauses the haptic device.
+ */
+int
+SDL_HapticPause(SDL_Haptic * haptic)
+{
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ if ((haptic->supported & SDL_HAPTIC_PAUSE) == 0) {
+ return SDL_SetError("Haptic: Device does not support setting pausing.");
+ }
+
+ return SDL_SYS_HapticPause(haptic);
+}
+
+/*
+ * Unpauses the haptic device.
+ */
+int
+SDL_HapticUnpause(SDL_Haptic * haptic)
+{
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ if ((haptic->supported & SDL_HAPTIC_PAUSE) == 0) {
+ return 0; /* Not going to be paused, so we pretend it's unpaused. */
+ }
+
+ return SDL_SYS_HapticUnpause(haptic);
+}
+
+/*
+ * Stops all the currently playing effects.
+ */
+int
+SDL_HapticStopAll(SDL_Haptic * haptic)
+{
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ return SDL_SYS_HapticStopAll(haptic);
+}
+
+/*
+ * Checks to see if rumble is supported.
+ */
+int
+SDL_HapticRumbleSupported(SDL_Haptic * haptic)
+{
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ /* Most things can use SINE, but XInput only has LEFTRIGHT. */
+ return ((haptic->supported & (SDL_HAPTIC_SINE|SDL_HAPTIC_LEFTRIGHT)) != 0);
+}
+
+/*
+ * Initializes the haptic device for simple rumble playback.
+ */
+int
+SDL_HapticRumbleInit(SDL_Haptic * haptic)
+{
+ SDL_HapticEffect *efx = &haptic->rumble_effect;
+
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ /* Already allocated. */
+ if (haptic->rumble_id >= 0) {
+ return 0;
+ }
+
+ SDL_zerop(efx);
+ if (haptic->supported & SDL_HAPTIC_SINE) {
+ efx->type = SDL_HAPTIC_SINE;
+ efx->periodic.period = 1000;
+ efx->periodic.magnitude = 0x4000;
+ efx->periodic.length = 5000;
+ efx->periodic.attack_length = 0;
+ efx->periodic.fade_length = 0;
+ } else if (haptic->supported & SDL_HAPTIC_LEFTRIGHT) { /* XInput? */
+ efx->type = SDL_HAPTIC_LEFTRIGHT;
+ efx->leftright.length = 5000;
+ efx->leftright.large_magnitude = 0x4000;
+ efx->leftright.small_magnitude = 0x4000;
+ } else {
+ return SDL_SetError("Device doesn't support rumble");
+ }
+
+ haptic->rumble_id = SDL_HapticNewEffect(haptic, &haptic->rumble_effect);
+ if (haptic->rumble_id >= 0) {
+ return 0;
+ }
+ return -1;
+}
+
+/*
+ * Runs simple rumble on a haptic device
+ */
+int
+SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length)
+{
+ SDL_HapticEffect *efx;
+ Sint16 magnitude;
+
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ if (haptic->rumble_id < 0) {
+ return SDL_SetError("Haptic: Rumble effect not initialized on haptic device");
+ }
+
+ /* Clamp strength. */
+ if (strength > 1.0f) {
+ strength = 1.0f;
+ } else if (strength < 0.0f) {
+ strength = 0.0f;
+ }
+ magnitude = (Sint16)(32767.0f*strength);
+
+ efx = &haptic->rumble_effect;
+ if (efx->type == SDL_HAPTIC_SINE) {
+ efx->periodic.magnitude = magnitude;
+ efx->periodic.length = length;
+ } else if (efx->type == SDL_HAPTIC_LEFTRIGHT) {
+ efx->leftright.small_magnitude = efx->leftright.large_magnitude = magnitude;
+ efx->leftright.length = length;
+ } else {
+ SDL_assert(0 && "This should have been caught elsewhere");
+ }
+
+ if (SDL_HapticUpdateEffect(haptic, haptic->rumble_id, &haptic->rumble_effect) < 0) {
+ return -1;
+ }
+
+ return SDL_HapticRunEffect(haptic, haptic->rumble_id, 1);
+}
+
+/*
+ * Stops the simple rumble on a haptic device.
+ */
+int
+SDL_HapticRumbleStop(SDL_Haptic * haptic)
+{
+ if (!ValidHaptic(haptic)) {
+ return -1;
+ }
+
+ if (haptic->rumble_id < 0) {
+ return SDL_SetError("Haptic: Rumble effect not initialized on haptic device");
+ }
+
+ return SDL_HapticStopEffect(haptic, haptic->rumble_id);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/haptic/SDL_haptic_c.h b/src/3rdparty/SDL2/src/haptic/SDL_haptic_c.h
new file mode 100644
index 0000000..26d900d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/haptic/SDL_haptic_c.h
@@ -0,0 +1,25 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+extern int SDL_HapticInit(void);
+extern void SDL_HapticQuit(void);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/haptic/SDL_syshaptic.h b/src/3rdparty/SDL2/src/haptic/SDL_syshaptic.h
new file mode 100644
index 0000000..4f4cd9f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/haptic/SDL_syshaptic.h
@@ -0,0 +1,208 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../SDL_internal.h"
+
+#ifndef SDL_syshaptic_h_
+#define SDL_syshaptic_h_
+
+#include "SDL_haptic.h"
+
+
+struct haptic_effect
+{
+ SDL_HapticEffect effect; /* The current event */
+ struct haptic_hweffect *hweffect; /* The hardware behind the event */
+};
+
+/*
+ * The real SDL_Haptic struct.
+ */
+struct _SDL_Haptic
+{
+ Uint8 index; /* Stores index it is attached to */
+
+ struct haptic_effect *effects; /* Allocated effects */
+ int neffects; /* Maximum amount of effects */
+ int nplaying; /* Maximum amount of effects to play at the same time */
+ unsigned int supported; /* Supported effects */
+ int naxes; /* Number of axes on the device. */
+
+ struct haptic_hwdata *hwdata; /* Driver dependent */
+ int ref_count; /* Count for multiple opens */
+
+ int rumble_id; /* ID of rumble effect for simple rumble API. */
+ SDL_HapticEffect rumble_effect; /* Rumble effect. */
+ struct _SDL_Haptic *next; /* pointer to next haptic we have allocated */
+};
+
+/*
+ * Scans the system for haptic devices.
+ *
+ * Returns number of devices on success, -1 on error.
+ */
+extern int SDL_SYS_HapticInit(void);
+
+/* Function to return the number of haptic devices plugged in right now */
+extern int SDL_SYS_NumHaptics(void);
+
+/*
+ * Gets the device dependent name of the haptic device
+ */
+extern const char *SDL_SYS_HapticName(int index);
+
+/*
+ * Opens the haptic device for usage. The haptic device should have
+ * the index value set previously.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+extern int SDL_SYS_HapticOpen(SDL_Haptic * haptic);
+
+/*
+ * Returns the index of the haptic core pointer or -1 if none is found.
+ */
+int SDL_SYS_HapticMouse(void);
+
+/*
+ * Checks to see if the joystick has haptic capabilities.
+ *
+ * Returns >0 if haptic capabilities are detected, 0 if haptic
+ * capabilities aren't detected and -1 on error.
+ */
+extern int SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick);
+
+/*
+ * Opens the haptic device for usage using the same device as
+ * the joystick.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+extern int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic,
+ SDL_Joystick * joystick);
+/*
+ * Checks to see if haptic device and joystick device are the same.
+ *
+ * Returns 1 if they are the same, 0 if they aren't.
+ */
+extern int SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic,
+ SDL_Joystick * joystick);
+
+/*
+ * Closes a haptic device after usage.
+ */
+extern void SDL_SYS_HapticClose(SDL_Haptic * haptic);
+
+/*
+ * Performs a cleanup on the haptic subsystem.
+ */
+extern void SDL_SYS_HapticQuit(void);
+
+/*
+ * Creates a new haptic effect on the haptic device using base
+ * as a template for the effect.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+extern int SDL_SYS_HapticNewEffect(SDL_Haptic * haptic,
+ struct haptic_effect *effect,
+ SDL_HapticEffect * base);
+
+/*
+ * Updates the haptic effect on the haptic device using data
+ * as a template.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+extern int SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
+ struct haptic_effect *effect,
+ SDL_HapticEffect * data);
+
+/*
+ * Runs the effect on the haptic device.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+extern int SDL_SYS_HapticRunEffect(SDL_Haptic * haptic,
+ struct haptic_effect *effect,
+ Uint32 iterations);
+
+/*
+ * Stops the effect on the haptic device.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+extern int SDL_SYS_HapticStopEffect(SDL_Haptic * haptic,
+ struct haptic_effect *effect);
+
+/*
+ * Cleanups up the effect on the haptic device.
+ */
+extern void SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic,
+ struct haptic_effect *effect);
+
+/*
+ * Queries the device for the status of effect.
+ *
+ * Returns 0 if device is stopped, >0 if device is playing and
+ * -1 on error.
+ */
+extern int SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
+ struct haptic_effect *effect);
+
+/*
+ * Sets the global gain of the haptic device.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+extern int SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain);
+
+/*
+ * Sets the autocenter feature of the haptic device.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+extern int SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter);
+
+/*
+ * Pauses the haptic device.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+extern int SDL_SYS_HapticPause(SDL_Haptic * haptic);
+
+/*
+ * Unpauses the haptic device.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+extern int SDL_SYS_HapticUnpause(SDL_Haptic * haptic);
+
+/*
+ * Stops all the currently playing haptic effects on the device.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+extern int SDL_SYS_HapticStopAll(SDL_Haptic * haptic);
+
+#endif /* SDL_syshaptic_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/haptic/android/SDL_syshaptic.c b/src/3rdparty/SDL2/src/haptic/android/SDL_syshaptic.c
new file mode 100644
index 0000000..1fb2352
--- /dev/null
+++ b/src/3rdparty/SDL2/src/haptic/android/SDL_syshaptic.c
@@ -0,0 +1,357 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_HAPTIC_ANDROID
+
+#include "SDL_assert.h"
+#include "SDL_timer.h"
+#include "SDL_syshaptic_c.h"
+#include "../SDL_syshaptic.h"
+#include "SDL_haptic.h"
+#include "../../core/android/SDL_android.h"
+#include "SDL_joystick.h"
+#include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */
+#include "../../joystick/android/SDL_sysjoystick_c.h" /* For joystick hwdata */
+
+
+typedef struct SDL_hapticlist_item
+{
+ int device_id;
+ char *name;
+ SDL_Haptic *haptic;
+ struct SDL_hapticlist_item *next;
+} SDL_hapticlist_item;
+
+static SDL_hapticlist_item *SDL_hapticlist = NULL;
+static SDL_hapticlist_item *SDL_hapticlist_tail = NULL;
+static int numhaptics = 0;
+
+
+int
+SDL_SYS_HapticInit(void)
+{
+ /* Support for device connect/disconnect is API >= 16 only,
+ * so we poll every three seconds
+ * Ref: http://developer.android.com/reference/android/hardware/input/InputManager.InputDeviceListener.html
+ */
+ static Uint32 timeout = 0;
+ if (SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) {
+ timeout = SDL_GetTicks() + 3000;
+ Android_JNI_PollHapticDevices();
+ }
+ return (numhaptics);
+}
+
+int
+SDL_SYS_NumHaptics(void)
+{
+ return (numhaptics);
+}
+
+static SDL_hapticlist_item *
+HapticByOrder(int index)
+{
+ SDL_hapticlist_item *item = SDL_hapticlist;
+ if ((index < 0) || (index >= numhaptics)) {
+ return NULL;
+ }
+ while (index > 0) {
+ SDL_assert(item != NULL);
+ --index;
+ item = item->next;
+ }
+ return item;
+}
+
+static SDL_hapticlist_item *
+HapticByDevId (int device_id)
+{
+ SDL_hapticlist_item *item;
+ for (item = SDL_hapticlist; item != NULL; item = item->next) {
+ if (device_id == item->device_id) {
+ /*SDL_Log("=+=+=+=+=+= HapticByDevId id [%d]", device_id);*/
+ return item;
+ }
+ }
+ return NULL;
+}
+
+const char *
+SDL_SYS_HapticName(int index)
+{
+ SDL_hapticlist_item *item = HapticByOrder(index);
+ if (item == NULL ) {
+ SDL_SetError("No such device");
+ return NULL;
+ }
+ return item->name;
+}
+
+
+static SDL_hapticlist_item *
+OpenHaptic(SDL_Haptic *haptic, SDL_hapticlist_item *item)
+{
+ if (item == NULL ) {
+ SDL_SetError("No such device");
+ return NULL;
+ }
+ if (item->haptic != NULL) {
+ SDL_SetError("Haptic already opened");
+ return NULL;
+ }
+
+ haptic->hwdata = (struct haptic_hwdata *)item;
+ item->haptic = haptic;
+
+ haptic->supported = SDL_HAPTIC_LEFTRIGHT;
+ haptic->neffects = 1;
+ haptic->nplaying = haptic->neffects;
+ haptic->effects = (struct haptic_effect *)SDL_malloc (sizeof (struct haptic_effect) * haptic->neffects);
+ if (haptic->effects == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ SDL_memset(haptic->effects, 0, sizeof (struct haptic_effect) * haptic->neffects);
+ return item;
+}
+
+static SDL_hapticlist_item *
+OpenHapticByOrder(SDL_Haptic *haptic, int index)
+{
+ return OpenHaptic (haptic, HapticByOrder(index));
+}
+
+static SDL_hapticlist_item *
+OpenHapticByDevId(SDL_Haptic *haptic, int device_id)
+{
+ return OpenHaptic (haptic, HapticByDevId(device_id));
+}
+
+int
+SDL_SYS_HapticOpen(SDL_Haptic *haptic)
+{
+ return (OpenHapticByOrder(haptic, haptic->index) == NULL ? -1 : 0);
+}
+
+
+int
+SDL_SYS_HapticMouse(void)
+{
+ return 0;
+}
+
+
+int
+SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick)
+{
+ SDL_hapticlist_item *item;
+ item = HapticByDevId(((joystick_hwdata *)joystick->hwdata)->device_id);
+ return (item != NULL) ? 1 : 0;
+}
+
+
+int
+SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
+{
+ return (OpenHapticByDevId(haptic, ((joystick_hwdata *)joystick->hwdata)->device_id) == NULL ? -1 : 0);
+}
+
+
+int
+SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
+{
+ return (((SDL_hapticlist_item *)haptic->hwdata)->device_id == ((joystick_hwdata *)joystick->hwdata)->device_id ? 1 : 0);
+}
+
+
+void
+SDL_SYS_HapticClose(SDL_Haptic * haptic)
+{
+ ((SDL_hapticlist_item *)haptic->hwdata)->haptic = NULL;
+ haptic->hwdata = NULL;
+ return;
+}
+
+
+void
+SDL_SYS_HapticQuit(void)
+{
+ SDL_hapticlist_item *item = NULL;
+ SDL_hapticlist_item *next = NULL;
+
+ for (item = SDL_hapticlist; item; item = next) {
+ next = item->next;
+ SDL_free(item);
+ }
+
+ SDL_hapticlist = SDL_hapticlist_tail = NULL;
+ numhaptics = 0;
+ return;
+}
+
+
+int
+SDL_SYS_HapticNewEffect(SDL_Haptic * haptic,
+ struct haptic_effect *effect, SDL_HapticEffect * base)
+{
+ return 0;
+}
+
+
+int
+SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
+ struct haptic_effect *effect,
+ SDL_HapticEffect * data)
+{
+ return 0;
+}
+
+
+int
+SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
+ Uint32 iterations)
+{
+ Android_JNI_HapticRun (((SDL_hapticlist_item *)haptic->hwdata)->device_id, effect->effect.leftright.length);
+ return 0;
+}
+
+
+int
+SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ return 0;
+}
+
+
+void
+SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ return;
+}
+
+
+int
+SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
+ struct haptic_effect *effect)
+{
+ return 0;
+}
+
+
+int
+SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
+{
+ return 0;
+}
+
+
+int
+SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
+{
+ return 0;
+}
+
+int
+SDL_SYS_HapticPause(SDL_Haptic * haptic)
+{
+ return 0;
+}
+
+int
+SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
+{
+ return 0;
+}
+
+int
+SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
+{
+ return 0;
+}
+
+
+
+int
+Android_AddHaptic(int device_id, const char *name)
+{
+ SDL_hapticlist_item *item;
+ item = (SDL_hapticlist_item *) SDL_calloc(1, sizeof (SDL_hapticlist_item));
+ if (item == NULL) {
+ return -1;
+ }
+
+ item->device_id = device_id;
+ item->name = SDL_strdup (name);
+ if (item->name == NULL) {
+ SDL_free (item);
+ return -1;
+ }
+
+ if (SDL_hapticlist_tail == NULL) {
+ SDL_hapticlist = SDL_hapticlist_tail = item;
+ } else {
+ SDL_hapticlist_tail->next = item;
+ SDL_hapticlist_tail = item;
+ }
+
+ ++numhaptics;
+ return numhaptics;
+}
+
+int
+Android_RemoveHaptic(int device_id)
+{
+ SDL_hapticlist_item *item;
+ SDL_hapticlist_item *prev = NULL;
+
+ for (item = SDL_hapticlist; item != NULL; item = item->next) {
+ /* found it, remove it. */
+ if (device_id == item->device_id) {
+ const int retval = item->haptic ? item->haptic->index : -1;
+
+ if (prev != NULL) {
+ prev->next = item->next;
+ } else {
+ SDL_assert(SDL_hapticlist == item);
+ SDL_hapticlist = item->next;
+ }
+ if (item == SDL_hapticlist_tail) {
+ SDL_hapticlist_tail = prev;
+ }
+
+ /* Need to decrement the haptic count */
+ --numhaptics;
+ /* !!! TODO: Send a haptic remove event? */
+
+ SDL_free(item->name);
+ SDL_free(item);
+ return retval;
+ }
+ prev = item;
+ }
+ return -1;
+}
+
+
+#endif /* SDL_HAPTIC_ANDROID */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/haptic/android/SDL_syshaptic_c.h b/src/3rdparty/SDL2/src/haptic/android/SDL_syshaptic_c.h
new file mode 100644
index 0000000..08634d2
--- /dev/null
+++ b/src/3rdparty/SDL2/src/haptic/android/SDL_syshaptic_c.h
@@ -0,0 +1,12 @@
+#include "SDL_config.h"
+
+#ifdef SDL_HAPTIC_ANDROID
+
+
+extern int Android_AddHaptic(int device_id, const char *name);
+extern int Android_RemoveHaptic(int device_id);
+
+
+#endif /* SDL_HAPTIC_ANDROID */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/haptic/darwin/SDL_syshaptic.c b/src/3rdparty/SDL2/src/haptic/darwin/SDL_syshaptic.c
new file mode 100644
index 0000000..67cb9f5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/haptic/darwin/SDL_syshaptic.c
@@ -0,0 +1,1417 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_HAPTIC_IOKIT
+
+#include "SDL_assert.h"
+#include "SDL_stdinc.h"
+#include "SDL_haptic.h"
+#include "../SDL_syshaptic.h"
+#include "SDL_joystick.h"
+#include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */
+#include "../../joystick/darwin/SDL_sysjoystick_c.h" /* For joystick hwdata */
+#include "SDL_syshaptic_c.h"
+
+#include <IOKit/IOKitLib.h>
+#include <IOKit/hid/IOHIDKeys.h>
+#include <IOKit/hid/IOHIDUsageTables.h>
+#include <ForceFeedback/ForceFeedback.h>
+#include <ForceFeedback/ForceFeedbackConstants.h>
+
+#ifndef IO_OBJECT_NULL
+#define IO_OBJECT_NULL ((io_service_t)0)
+#endif
+
+/*
+ * List of available haptic devices.
+ */
+typedef struct SDL_hapticlist_item
+{
+ char name[256]; /* Name of the device. */
+
+ io_service_t dev; /* Node we use to create the device. */
+ SDL_Haptic *haptic; /* Haptic currently associated with it. */
+
+ /* Usage pages for determining if it's a mouse or not. */
+ long usage;
+ long usagePage;
+
+ struct SDL_hapticlist_item *next;
+} SDL_hapticlist_item;
+
+
+/*
+ * Haptic system hardware data.
+ */
+struct haptic_hwdata
+{
+ FFDeviceObjectReference device; /* Hardware device. */
+ UInt8 axes[3];
+};
+
+
+/*
+ * Haptic system effect data.
+ */
+struct haptic_hweffect
+{
+ FFEffectObjectReference ref; /* Reference. */
+ struct FFEFFECT effect; /* Hardware effect. */
+};
+
+/*
+ * Prototypes.
+ */
+static void SDL_SYS_HapticFreeFFEFFECT(FFEFFECT * effect, int type);
+static int HIDGetDeviceProduct(io_service_t dev, char *name);
+
+static SDL_hapticlist_item *SDL_hapticlist = NULL;
+static SDL_hapticlist_item *SDL_hapticlist_tail = NULL;
+static int numhaptics = -1;
+
+/*
+ * Like strerror but for force feedback errors.
+ */
+static const char *
+FFStrError(unsigned int err)
+{
+ switch (err) {
+ case FFERR_DEVICEFULL:
+ return "device full";
+ /* This should be valid, but for some reason isn't defined... */
+ /* case FFERR_DEVICENOTREG:
+ return "device not registered"; */
+ case FFERR_DEVICEPAUSED:
+ return "device paused";
+ case FFERR_DEVICERELEASED:
+ return "device released";
+ case FFERR_EFFECTPLAYING:
+ return "effect playing";
+ case FFERR_EFFECTTYPEMISMATCH:
+ return "effect type mismatch";
+ case FFERR_EFFECTTYPENOTSUPPORTED:
+ return "effect type not supported";
+ case FFERR_GENERIC:
+ return "undetermined error";
+ case FFERR_HASEFFECTS:
+ return "device has effects";
+ case FFERR_INCOMPLETEEFFECT:
+ return "incomplete effect";
+ case FFERR_INTERNAL:
+ return "internal fault";
+ case FFERR_INVALIDDOWNLOADID:
+ return "invalid download id";
+ case FFERR_INVALIDPARAM:
+ return "invalid parameter";
+ case FFERR_MOREDATA:
+ return "more data";
+ case FFERR_NOINTERFACE:
+ return "interface not supported";
+ case FFERR_NOTDOWNLOADED:
+ return "effect is not downloaded";
+ case FFERR_NOTINITIALIZED:
+ return "object has not been initialized";
+ case FFERR_OUTOFMEMORY:
+ return "out of memory";
+ case FFERR_UNPLUGGED:
+ return "device is unplugged";
+ case FFERR_UNSUPPORTED:
+ return "function call unsupported";
+ case FFERR_UNSUPPORTEDAXIS:
+ return "axis unsupported";
+
+ default:
+ return "unknown error";
+ }
+}
+
+
+/*
+ * Initializes the haptic subsystem.
+ */
+int
+SDL_SYS_HapticInit(void)
+{
+ IOReturn result;
+ io_iterator_t iter;
+ CFDictionaryRef match;
+ io_service_t device;
+
+ if (numhaptics != -1) {
+ return SDL_SetError("Haptic subsystem already initialized!");
+ }
+ numhaptics = 0;
+
+ /* Get HID devices. */
+ match = IOServiceMatching(kIOHIDDeviceKey);
+ if (match == NULL) {
+ return SDL_SetError("Haptic: Failed to get IOServiceMatching.");
+ }
+
+ /* Now search I/O Registry for matching devices. */
+ result = IOServiceGetMatchingServices(kIOMasterPortDefault, match, &iter);
+ if (result != kIOReturnSuccess) {
+ return SDL_SetError("Haptic: Couldn't create a HID object iterator.");
+ }
+ /* IOServiceGetMatchingServices consumes dictionary. */
+
+ if (!IOIteratorIsValid(iter)) { /* No iterator. */
+ return 0;
+ }
+
+ while ((device = IOIteratorNext(iter)) != IO_OBJECT_NULL) {
+ MacHaptic_MaybeAddDevice(device);
+ /* always release as the AddDevice will retain IF it's a forcefeedback device */
+ IOObjectRelease(device);
+ }
+ IOObjectRelease(iter);
+
+ return numhaptics;
+}
+
+int
+SDL_SYS_NumHaptics(void)
+{
+ return numhaptics;
+}
+
+static SDL_hapticlist_item *
+HapticByDevIndex(int device_index)
+{
+ SDL_hapticlist_item *item = SDL_hapticlist;
+
+ if ((device_index < 0) || (device_index >= numhaptics)) {
+ return NULL;
+ }
+
+ while (device_index > 0) {
+ SDL_assert(item != NULL);
+ --device_index;
+ item = item->next;
+ }
+
+ return item;
+}
+
+int
+MacHaptic_MaybeAddDevice( io_object_t device )
+{
+ IOReturn result;
+ CFMutableDictionaryRef hidProperties;
+ CFTypeRef refCF;
+ SDL_hapticlist_item *item;
+
+ if (numhaptics == -1) {
+ return -1; /* not initialized. We'll pick these up on enumeration if we init later. */
+ }
+
+ /* Check for force feedback. */
+ if (FFIsForceFeedback(device) != FF_OK) {
+ return -1;
+ }
+
+ /* Make sure we don't already have it */
+ for (item = SDL_hapticlist; item ; item = item->next)
+ {
+ if (IOObjectIsEqualTo((io_object_t) item->dev, device)) {
+ /* Already added */
+ return -1;
+ }
+ }
+
+ item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
+ if (item == NULL) {
+ return SDL_SetError("Could not allocate haptic storage");
+ }
+
+ /* retain it as we are going to keep it around a while */
+ IOObjectRetain(device);
+
+ /* Set basic device data. */
+ HIDGetDeviceProduct(device, item->name);
+ item->dev = device;
+
+ /* Set usage pages. */
+ hidProperties = 0;
+ refCF = 0;
+ result = IORegistryEntryCreateCFProperties(device,
+ &hidProperties,
+ kCFAllocatorDefault,
+ kNilOptions);
+ if ((result == KERN_SUCCESS) && hidProperties) {
+ refCF = CFDictionaryGetValue(hidProperties,
+ CFSTR(kIOHIDPrimaryUsagePageKey));
+ if (refCF) {
+ if (!CFNumberGetValue(refCF, kCFNumberLongType, &item->usagePage)) {
+ SDL_SetError("Haptic: Receiving device's usage page.");
+ }
+ refCF = CFDictionaryGetValue(hidProperties,
+ CFSTR(kIOHIDPrimaryUsageKey));
+ if (refCF) {
+ if (!CFNumberGetValue(refCF, kCFNumberLongType, &item->usage)) {
+ SDL_SetError("Haptic: Receiving device's usage.");
+ }
+ }
+ }
+ CFRelease(hidProperties);
+ }
+
+ if (SDL_hapticlist_tail == NULL) {
+ SDL_hapticlist = SDL_hapticlist_tail = item;
+ } else {
+ SDL_hapticlist_tail->next = item;
+ SDL_hapticlist_tail = item;
+ }
+
+ /* Device has been added. */
+ ++numhaptics;
+
+ return numhaptics;
+}
+
+int
+MacHaptic_MaybeRemoveDevice( io_object_t device )
+{
+ SDL_hapticlist_item *item;
+ SDL_hapticlist_item *prev = NULL;
+
+ if (numhaptics == -1) {
+ return -1; /* not initialized. ignore this. */
+ }
+
+ for (item = SDL_hapticlist; item != NULL; item = item->next) {
+ /* found it, remove it. */
+ if (IOObjectIsEqualTo((io_object_t) item->dev, device)) {
+ const int retval = item->haptic ? item->haptic->index : -1;
+
+ if (prev != NULL) {
+ prev->next = item->next;
+ } else {
+ SDL_assert(SDL_hapticlist == item);
+ SDL_hapticlist = item->next;
+ }
+ if (item == SDL_hapticlist_tail) {
+ SDL_hapticlist_tail = prev;
+ }
+
+ /* Need to decrement the haptic count */
+ --numhaptics;
+ /* !!! TODO: Send a haptic remove event? */
+
+ IOObjectRelease(item->dev);
+ SDL_free(item);
+ return retval;
+ }
+ prev = item;
+ }
+
+ return -1;
+}
+
+/*
+ * Return the name of a haptic device, does not need to be opened.
+ */
+const char *
+SDL_SYS_HapticName(int index)
+{
+ SDL_hapticlist_item *item;
+ item = HapticByDevIndex(index);
+ return item->name;
+}
+
+/*
+ * Gets the device's product name.
+ */
+static int
+HIDGetDeviceProduct(io_service_t dev, char *name)
+{
+ CFMutableDictionaryRef hidProperties, usbProperties;
+ io_registry_entry_t parent1, parent2;
+ kern_return_t ret;
+
+ hidProperties = usbProperties = 0;
+
+ ret = IORegistryEntryCreateCFProperties(dev, &hidProperties,
+ kCFAllocatorDefault, kNilOptions);
+ if ((ret != KERN_SUCCESS) || !hidProperties) {
+ return SDL_SetError("Haptic: Unable to create CFProperties.");
+ }
+
+ /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also
+ * get dictionary for USB properties: step up two levels and get CF dictionary for USB properties
+ */
+ if ((KERN_SUCCESS ==
+ IORegistryEntryGetParentEntry(dev, kIOServicePlane, &parent1))
+ && (KERN_SUCCESS ==
+ IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2))
+ && (KERN_SUCCESS ==
+ IORegistryEntryCreateCFProperties(parent2, &usbProperties,
+ kCFAllocatorDefault,
+ kNilOptions))) {
+ if (usbProperties) {
+ CFTypeRef refCF = 0;
+ /* get device info
+ * try hid dictionary first, if fail then go to USB dictionary
+ */
+
+
+ /* Get product name */
+ refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey));
+ if (!refCF) {
+ refCF = CFDictionaryGetValue(usbProperties,
+ CFSTR("USB Product Name"));
+ }
+ if (refCF) {
+ if (!CFStringGetCString(refCF, name, 256,
+ CFStringGetSystemEncoding())) {
+ return SDL_SetError("Haptic: CFStringGetCString error retrieving pDevice->product.");
+ }
+ }
+
+ CFRelease(usbProperties);
+ } else {
+ return SDL_SetError("Haptic: IORegistryEntryCreateCFProperties failed to create usbProperties.");
+ }
+
+ /* Release stuff. */
+ if (kIOReturnSuccess != IOObjectRelease(parent2)) {
+ SDL_SetError("Haptic: IOObjectRelease error with parent2.");
+ }
+ if (kIOReturnSuccess != IOObjectRelease(parent1)) {
+ SDL_SetError("Haptic: IOObjectRelease error with parent1.");
+ }
+ } else {
+ return SDL_SetError("Haptic: Error getting registry entries.");
+ }
+
+ return 0;
+}
+
+
+#define FF_TEST(ff, s) \
+if (features.supportedEffects & (ff)) supported |= (s)
+/*
+ * Gets supported features.
+ */
+static unsigned int
+GetSupportedFeatures(SDL_Haptic * haptic)
+{
+ HRESULT ret;
+ FFDeviceObjectReference device;
+ FFCAPABILITIES features;
+ unsigned int supported;
+ Uint32 val;
+
+ device = haptic->hwdata->device;
+
+ ret = FFDeviceGetForceFeedbackCapabilities(device, &features);
+ if (ret != FF_OK) {
+ return SDL_SetError("Haptic: Unable to get device's supported features.");
+ }
+
+ supported = 0;
+
+ /* Get maximum effects. */
+ haptic->neffects = features.storageCapacity;
+ haptic->nplaying = features.playbackCapacity;
+
+ /* Test for effects. */
+ FF_TEST(FFCAP_ET_CONSTANTFORCE, SDL_HAPTIC_CONSTANT);
+ FF_TEST(FFCAP_ET_RAMPFORCE, SDL_HAPTIC_RAMP);
+ /* !!! FIXME: put this back when we have more bits in 2.1 */
+ /* FF_TEST(FFCAP_ET_SQUARE, SDL_HAPTIC_SQUARE); */
+ FF_TEST(FFCAP_ET_SINE, SDL_HAPTIC_SINE);
+ FF_TEST(FFCAP_ET_TRIANGLE, SDL_HAPTIC_TRIANGLE);
+ FF_TEST(FFCAP_ET_SAWTOOTHUP, SDL_HAPTIC_SAWTOOTHUP);
+ FF_TEST(FFCAP_ET_SAWTOOTHDOWN, SDL_HAPTIC_SAWTOOTHDOWN);
+ FF_TEST(FFCAP_ET_SPRING, SDL_HAPTIC_SPRING);
+ FF_TEST(FFCAP_ET_DAMPER, SDL_HAPTIC_DAMPER);
+ FF_TEST(FFCAP_ET_INERTIA, SDL_HAPTIC_INERTIA);
+ FF_TEST(FFCAP_ET_FRICTION, SDL_HAPTIC_FRICTION);
+ FF_TEST(FFCAP_ET_CUSTOMFORCE, SDL_HAPTIC_CUSTOM);
+
+ /* Check if supports gain. */
+ ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_FFGAIN,
+ &val, sizeof(val));
+ if (ret == FF_OK) {
+ supported |= SDL_HAPTIC_GAIN;
+ } else if (ret != FFERR_UNSUPPORTED) {
+ return SDL_SetError("Haptic: Unable to get if device supports gain: %s.",
+ FFStrError(ret));
+ }
+
+ /* Checks if supports autocenter. */
+ ret = FFDeviceGetForceFeedbackProperty(device, FFPROP_AUTOCENTER,
+ &val, sizeof(val));
+ if (ret == FF_OK) {
+ supported |= SDL_HAPTIC_AUTOCENTER;
+ } else if (ret != FFERR_UNSUPPORTED) {
+ return SDL_SetError
+ ("Haptic: Unable to get if device supports autocenter: %s.",
+ FFStrError(ret));
+ }
+
+ /* Check for axes, we have an artificial limit on axes */
+ haptic->naxes = ((features.numFfAxes) > 3) ? 3 : features.numFfAxes;
+ /* Actually store the axes we want to use */
+ SDL_memcpy(haptic->hwdata->axes, features.ffAxes,
+ haptic->naxes * sizeof(Uint8));
+
+ /* Always supported features. */
+ supported |= SDL_HAPTIC_STATUS | SDL_HAPTIC_PAUSE;
+
+ haptic->supported = supported;
+ return 0;
+}
+
+
+/*
+ * Opens the haptic device from the file descriptor.
+ */
+static int
+SDL_SYS_HapticOpenFromService(SDL_Haptic * haptic, io_service_t service)
+{
+ HRESULT ret;
+ int ret2;
+
+ /* Allocate the hwdata */
+ haptic->hwdata = (struct haptic_hwdata *)
+ SDL_malloc(sizeof(*haptic->hwdata));
+ if (haptic->hwdata == NULL) {
+ SDL_OutOfMemory();
+ goto creat_err;
+ }
+ SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
+
+ /* Open the device */
+ ret = FFCreateDevice(service, &haptic->hwdata->device);
+ if (ret != FF_OK) {
+ SDL_SetError("Haptic: Unable to create device from service: %s.",
+ FFStrError(ret));
+ goto creat_err;
+ }
+
+ /* Get supported features. */
+ ret2 = GetSupportedFeatures(haptic);
+ if (ret2 < 0) {
+ goto open_err;
+ }
+
+
+ /* Reset and then enable actuators. */
+ ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
+ FFSFFC_RESET);
+ if (ret != FF_OK) {
+ SDL_SetError("Haptic: Unable to reset device: %s.", FFStrError(ret));
+ goto open_err;
+ }
+ ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
+ FFSFFC_SETACTUATORSON);
+ if (ret != FF_OK) {
+ SDL_SetError("Haptic: Unable to enable actuators: %s.",
+ FFStrError(ret));
+ goto open_err;
+ }
+
+
+ /* Allocate effects memory. */
+ haptic->effects = (struct haptic_effect *)
+ SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
+ if (haptic->effects == NULL) {
+ SDL_OutOfMemory();
+ goto open_err;
+ }
+ /* Clear the memory */
+ SDL_memset(haptic->effects, 0,
+ sizeof(struct haptic_effect) * haptic->neffects);
+
+ return 0;
+
+ /* Error handling */
+ open_err:
+ FFReleaseDevice(haptic->hwdata->device);
+ creat_err:
+ if (haptic->hwdata != NULL) {
+ SDL_free(haptic->hwdata);
+ haptic->hwdata = NULL;
+ }
+ return -1;
+
+}
+
+
+/*
+ * Opens a haptic device for usage.
+ */
+int
+SDL_SYS_HapticOpen(SDL_Haptic * haptic)
+{
+ SDL_hapticlist_item *item;
+ item = HapticByDevIndex(haptic->index);
+
+ return SDL_SYS_HapticOpenFromService(haptic, item->dev);
+}
+
+
+/*
+ * Opens a haptic device from first mouse it finds for usage.
+ */
+int
+SDL_SYS_HapticMouse(void)
+{
+ int device_index = 0;
+ SDL_hapticlist_item *item;
+
+ for (item = SDL_hapticlist; item; item = item->next) {
+ if ((item->usagePage == kHIDPage_GenericDesktop) &&
+ (item->usage == kHIDUsage_GD_Mouse)) {
+ return device_index;
+ }
+ ++device_index;
+ }
+
+ return -1;
+}
+
+
+/*
+ * Checks to see if a joystick has haptic features.
+ */
+int
+SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
+{
+ if (joystick->hwdata->ffservice != 0) {
+ return SDL_TRUE;
+ }
+ return SDL_FALSE;
+}
+
+
+/*
+ * Checks to see if the haptic device and joystick are in reality the same.
+ */
+int
+SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
+{
+ if (IOObjectIsEqualTo((io_object_t) ((size_t)haptic->hwdata->device),
+ joystick->hwdata->ffservice)) {
+ return 1;
+ }
+ return 0;
+}
+
+
+/*
+ * Opens a SDL_Haptic from a SDL_Joystick.
+ */
+int
+SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
+{
+ int device_index = 0;
+ SDL_hapticlist_item *item;
+
+ for (item = SDL_hapticlist; item; item = item->next) {
+ if (IOObjectIsEqualTo((io_object_t) item->dev,
+ joystick->hwdata->ffservice)) {
+ haptic->index = device_index;
+ break;
+ }
+ ++device_index;
+ }
+
+ return SDL_SYS_HapticOpenFromService(haptic, joystick->hwdata->ffservice);
+}
+
+
+/*
+ * Closes the haptic device.
+ */
+void
+SDL_SYS_HapticClose(SDL_Haptic * haptic)
+{
+ if (haptic->hwdata) {
+
+ /* Free Effects. */
+ SDL_free(haptic->effects);
+ haptic->effects = NULL;
+ haptic->neffects = 0;
+
+ /* Clean up */
+ FFReleaseDevice(haptic->hwdata->device);
+
+ /* Free */
+ SDL_free(haptic->hwdata);
+ haptic->hwdata = NULL;
+ }
+}
+
+
+/*
+ * Clean up after system specific haptic stuff
+ */
+void
+SDL_SYS_HapticQuit(void)
+{
+ SDL_hapticlist_item *item;
+ SDL_hapticlist_item *next = NULL;
+
+ for (item = SDL_hapticlist; item; item = next) {
+ next = item->next;
+ /* Opened and not closed haptics are leaked, this is on purpose.
+ * Close your haptic devices after usage. */
+
+ /* Free the io_service_t */
+ IOObjectRelease(item->dev);
+ SDL_free(item);
+ }
+
+ numhaptics = -1;
+ SDL_hapticlist = NULL;
+ SDL_hapticlist_tail = NULL;
+}
+
+
+/*
+ * Converts an SDL trigger button to an FFEFFECT trigger button.
+ */
+static DWORD
+FFGetTriggerButton(Uint16 button)
+{
+ DWORD dwTriggerButton;
+
+ dwTriggerButton = FFEB_NOTRIGGER;
+
+ if (button != 0) {
+ dwTriggerButton = FFJOFS_BUTTON(button - 1);
+ }
+
+ return dwTriggerButton;
+}
+
+
+/*
+ * Sets the direction.
+ */
+static int
+SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes)
+{
+ LONG *rglDir;
+
+ /* Handle no axes a part. */
+ if (naxes == 0) {
+ effect->dwFlags |= FFEFF_SPHERICAL; /* Set as default. */
+ effect->rglDirection = NULL;
+ return 0;
+ }
+
+ /* Has axes. */
+ rglDir = SDL_malloc(sizeof(LONG) * naxes);
+ if (rglDir == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(rglDir, 0, sizeof(LONG) * naxes);
+ effect->rglDirection = rglDir;
+
+ switch (dir->type) {
+ case SDL_HAPTIC_POLAR:
+ effect->dwFlags |= FFEFF_POLAR;
+ rglDir[0] = dir->dir[0];
+ return 0;
+ case SDL_HAPTIC_CARTESIAN:
+ effect->dwFlags |= FFEFF_CARTESIAN;
+ rglDir[0] = dir->dir[0];
+ if (naxes > 1) {
+ rglDir[1] = dir->dir[1];
+ }
+ if (naxes > 2) {
+ rglDir[2] = dir->dir[2];
+ }
+ return 0;
+ case SDL_HAPTIC_SPHERICAL:
+ effect->dwFlags |= FFEFF_SPHERICAL;
+ rglDir[0] = dir->dir[0];
+ if (naxes > 1) {
+ rglDir[1] = dir->dir[1];
+ }
+ if (naxes > 2) {
+ rglDir[2] = dir->dir[2];
+ }
+ return 0;
+
+ default:
+ return SDL_SetError("Haptic: Unknown direction type.");
+ }
+}
+
+
+/* Clamps and converts. */
+#define CCONVERT(x) (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
+/* Just converts. */
+#define CONVERT(x) (((x)*10000) / 0x7FFF)
+/*
+ * Creates the FFEFFECT from a SDL_HapticEffect.
+ */
+static int
+SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
+{
+ int i;
+ FFCONSTANTFORCE *constant = NULL;
+ FFPERIODIC *periodic = NULL;
+ FFCONDITION *condition = NULL; /* Actually an array of conditions - one per axis. */
+ FFRAMPFORCE *ramp = NULL;
+ FFCUSTOMFORCE *custom = NULL;
+ FFENVELOPE *envelope = NULL;
+ SDL_HapticConstant *hap_constant = NULL;
+ SDL_HapticPeriodic *hap_periodic = NULL;
+ SDL_HapticCondition *hap_condition = NULL;
+ SDL_HapticRamp *hap_ramp = NULL;
+ SDL_HapticCustom *hap_custom = NULL;
+ DWORD *axes = NULL;
+
+ /* Set global stuff. */
+ SDL_memset(dest, 0, sizeof(FFEFFECT));
+ dest->dwSize = sizeof(FFEFFECT); /* Set the structure size. */
+ dest->dwSamplePeriod = 0; /* Not used by us. */
+ dest->dwGain = 10000; /* Gain is set globally, not locally. */
+ dest->dwFlags = FFEFF_OBJECTOFFSETS; /* Seems obligatory. */
+
+ /* Envelope. */
+ envelope = SDL_malloc(sizeof(FFENVELOPE));
+ if (envelope == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(envelope, 0, sizeof(FFENVELOPE));
+ dest->lpEnvelope = envelope;
+ envelope->dwSize = sizeof(FFENVELOPE); /* Always should be this. */
+
+ /* Axes. */
+ dest->cAxes = haptic->naxes;
+ if (dest->cAxes > 0) {
+ axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
+ if (axes == NULL) {
+ return SDL_OutOfMemory();
+ }
+ axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
+ if (dest->cAxes > 1) {
+ axes[1] = haptic->hwdata->axes[1];
+ }
+ if (dest->cAxes > 2) {
+ axes[2] = haptic->hwdata->axes[2];
+ }
+ dest->rgdwAxes = axes;
+ }
+
+
+ /* The big type handling switch, even bigger then Linux's version. */
+ switch (src->type) {
+ case SDL_HAPTIC_CONSTANT:
+ hap_constant = &src->constant;
+ constant = SDL_malloc(sizeof(FFCONSTANTFORCE));
+ if (constant == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(constant, 0, sizeof(FFCONSTANTFORCE));
+
+ /* Specifics */
+ constant->lMagnitude = CONVERT(hap_constant->level);
+ dest->cbTypeSpecificParams = sizeof(FFCONSTANTFORCE);
+ dest->lpvTypeSpecificParams = constant;
+
+ /* Generics */
+ dest->dwDuration = hap_constant->length * 1000; /* In microseconds. */
+ dest->dwTriggerButton = FFGetTriggerButton(hap_constant->button);
+ dest->dwTriggerRepeatInterval = hap_constant->interval;
+ dest->dwStartDelay = hap_constant->delay * 1000; /* In microseconds. */
+
+ /* Direction. */
+ if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes)
+ < 0) {
+ return -1;
+ }
+
+ /* Envelope */
+ if ((hap_constant->attack_length == 0)
+ && (hap_constant->fade_length == 0)) {
+ SDL_free(envelope);
+ dest->lpEnvelope = NULL;
+ } else {
+ envelope->dwAttackLevel = CCONVERT(hap_constant->attack_level);
+ envelope->dwAttackTime = hap_constant->attack_length * 1000;
+ envelope->dwFadeLevel = CCONVERT(hap_constant->fade_level);
+ envelope->dwFadeTime = hap_constant->fade_length * 1000;
+ }
+
+ break;
+
+ case SDL_HAPTIC_SINE:
+ /* !!! FIXME: put this back when we have more bits in 2.1 */
+ /* case SDL_HAPTIC_SQUARE: */
+ case SDL_HAPTIC_TRIANGLE:
+ case SDL_HAPTIC_SAWTOOTHUP:
+ case SDL_HAPTIC_SAWTOOTHDOWN:
+ hap_periodic = &src->periodic;
+ periodic = SDL_malloc(sizeof(FFPERIODIC));
+ if (periodic == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(periodic, 0, sizeof(FFPERIODIC));
+
+ /* Specifics */
+ periodic->dwMagnitude = CONVERT(SDL_abs(hap_periodic->magnitude));
+ periodic->lOffset = CONVERT(hap_periodic->offset);
+ periodic->dwPhase =
+ (hap_periodic->phase + (hap_periodic->magnitude < 0 ? 18000 : 0)) % 36000;
+ periodic->dwPeriod = hap_periodic->period * 1000;
+ dest->cbTypeSpecificParams = sizeof(FFPERIODIC);
+ dest->lpvTypeSpecificParams = periodic;
+
+ /* Generics */
+ dest->dwDuration = hap_periodic->length * 1000; /* In microseconds. */
+ dest->dwTriggerButton = FFGetTriggerButton(hap_periodic->button);
+ dest->dwTriggerRepeatInterval = hap_periodic->interval;
+ dest->dwStartDelay = hap_periodic->delay * 1000; /* In microseconds. */
+
+ /* Direction. */
+ if (SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes)
+ < 0) {
+ return -1;
+ }
+
+ /* Envelope */
+ if ((hap_periodic->attack_length == 0)
+ && (hap_periodic->fade_length == 0)) {
+ SDL_free(envelope);
+ dest->lpEnvelope = NULL;
+ } else {
+ envelope->dwAttackLevel = CCONVERT(hap_periodic->attack_level);
+ envelope->dwAttackTime = hap_periodic->attack_length * 1000;
+ envelope->dwFadeLevel = CCONVERT(hap_periodic->fade_level);
+ envelope->dwFadeTime = hap_periodic->fade_length * 1000;
+ }
+
+ break;
+
+ case SDL_HAPTIC_SPRING:
+ case SDL_HAPTIC_DAMPER:
+ case SDL_HAPTIC_INERTIA:
+ case SDL_HAPTIC_FRICTION:
+ hap_condition = &src->condition;
+ if (dest->cAxes > 0) {
+ condition = SDL_malloc(sizeof(FFCONDITION) * dest->cAxes);
+ if (condition == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(condition, 0, sizeof(FFCONDITION));
+
+ /* Specifics */
+ for (i = 0; i < dest->cAxes; i++) {
+ condition[i].lOffset = CONVERT(hap_condition->center[i]);
+ condition[i].lPositiveCoefficient =
+ CONVERT(hap_condition->right_coeff[i]);
+ condition[i].lNegativeCoefficient =
+ CONVERT(hap_condition->left_coeff[i]);
+ condition[i].dwPositiveSaturation =
+ CCONVERT(hap_condition->right_sat[i] / 2);
+ condition[i].dwNegativeSaturation =
+ CCONVERT(hap_condition->left_sat[i] / 2);
+ condition[i].lDeadBand = CCONVERT(hap_condition->deadband[i] / 2);
+ }
+ }
+
+ dest->cbTypeSpecificParams = sizeof(FFCONDITION) * dest->cAxes;
+ dest->lpvTypeSpecificParams = condition;
+
+ /* Generics */
+ dest->dwDuration = hap_condition->length * 1000; /* In microseconds. */
+ dest->dwTriggerButton = FFGetTriggerButton(hap_condition->button);
+ dest->dwTriggerRepeatInterval = hap_condition->interval;
+ dest->dwStartDelay = hap_condition->delay * 1000; /* In microseconds. */
+
+ /* Direction. */
+ if (SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes)
+ < 0) {
+ return -1;
+ }
+
+ /* Envelope - Not actually supported by most CONDITION implementations. */
+ SDL_free(dest->lpEnvelope);
+ dest->lpEnvelope = NULL;
+
+ break;
+
+ case SDL_HAPTIC_RAMP:
+ hap_ramp = &src->ramp;
+ ramp = SDL_malloc(sizeof(FFRAMPFORCE));
+ if (ramp == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(ramp, 0, sizeof(FFRAMPFORCE));
+
+ /* Specifics */
+ ramp->lStart = CONVERT(hap_ramp->start);
+ ramp->lEnd = CONVERT(hap_ramp->end);
+ dest->cbTypeSpecificParams = sizeof(FFRAMPFORCE);
+ dest->lpvTypeSpecificParams = ramp;
+
+ /* Generics */
+ dest->dwDuration = hap_ramp->length * 1000; /* In microseconds. */
+ dest->dwTriggerButton = FFGetTriggerButton(hap_ramp->button);
+ dest->dwTriggerRepeatInterval = hap_ramp->interval;
+ dest->dwStartDelay = hap_ramp->delay * 1000; /* In microseconds. */
+
+ /* Direction. */
+ if (SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes) < 0) {
+ return -1;
+ }
+
+ /* Envelope */
+ if ((hap_ramp->attack_length == 0) && (hap_ramp->fade_length == 0)) {
+ SDL_free(envelope);
+ dest->lpEnvelope = NULL;
+ } else {
+ envelope->dwAttackLevel = CCONVERT(hap_ramp->attack_level);
+ envelope->dwAttackTime = hap_ramp->attack_length * 1000;
+ envelope->dwFadeLevel = CCONVERT(hap_ramp->fade_level);
+ envelope->dwFadeTime = hap_ramp->fade_length * 1000;
+ }
+
+ break;
+
+ case SDL_HAPTIC_CUSTOM:
+ hap_custom = &src->custom;
+ custom = SDL_malloc(sizeof(FFCUSTOMFORCE));
+ if (custom == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(custom, 0, sizeof(FFCUSTOMFORCE));
+
+ /* Specifics */
+ custom->cChannels = hap_custom->channels;
+ custom->dwSamplePeriod = hap_custom->period * 1000;
+ custom->cSamples = hap_custom->samples;
+ custom->rglForceData =
+ SDL_malloc(sizeof(LONG) * custom->cSamples * custom->cChannels);
+ for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) { /* Copy data. */
+ custom->rglForceData[i] = CCONVERT(hap_custom->data[i]);
+ }
+ dest->cbTypeSpecificParams = sizeof(FFCUSTOMFORCE);
+ dest->lpvTypeSpecificParams = custom;
+
+ /* Generics */
+ dest->dwDuration = hap_custom->length * 1000; /* In microseconds. */
+ dest->dwTriggerButton = FFGetTriggerButton(hap_custom->button);
+ dest->dwTriggerRepeatInterval = hap_custom->interval;
+ dest->dwStartDelay = hap_custom->delay * 1000; /* In microseconds. */
+
+ /* Direction. */
+ if (SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes) <
+ 0) {
+ return -1;
+ }
+
+ /* Envelope */
+ if ((hap_custom->attack_length == 0)
+ && (hap_custom->fade_length == 0)) {
+ SDL_free(envelope);
+ dest->lpEnvelope = NULL;
+ } else {
+ envelope->dwAttackLevel = CCONVERT(hap_custom->attack_level);
+ envelope->dwAttackTime = hap_custom->attack_length * 1000;
+ envelope->dwFadeLevel = CCONVERT(hap_custom->fade_level);
+ envelope->dwFadeTime = hap_custom->fade_length * 1000;
+ }
+
+ break;
+
+
+ default:
+ return SDL_SetError("Haptic: Unknown effect type.");
+ }
+
+ return 0;
+}
+
+
+/*
+ * Frees an FFEFFECT allocated by SDL_SYS_ToFFEFFECT.
+ */
+static void
+SDL_SYS_HapticFreeFFEFFECT(FFEFFECT * effect, int type)
+{
+ FFCUSTOMFORCE *custom;
+
+ SDL_free(effect->lpEnvelope);
+ effect->lpEnvelope = NULL;
+ SDL_free(effect->rgdwAxes);
+ effect->rgdwAxes = NULL;
+ if (effect->lpvTypeSpecificParams != NULL) {
+ if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */
+ custom = (FFCUSTOMFORCE *) effect->lpvTypeSpecificParams;
+ SDL_free(custom->rglForceData);
+ custom->rglForceData = NULL;
+ }
+ SDL_free(effect->lpvTypeSpecificParams);
+ effect->lpvTypeSpecificParams = NULL;
+ }
+ SDL_free(effect->rglDirection);
+ effect->rglDirection = NULL;
+}
+
+
+/*
+ * Gets the effect type from the generic SDL haptic effect wrapper.
+ */
+CFUUIDRef
+SDL_SYS_HapticEffectType(Uint16 type)
+{
+ switch (type) {
+ case SDL_HAPTIC_CONSTANT:
+ return kFFEffectType_ConstantForce_ID;
+
+ case SDL_HAPTIC_RAMP:
+ return kFFEffectType_RampForce_ID;
+
+ /* !!! FIXME: put this back when we have more bits in 2.1 */
+ /* case SDL_HAPTIC_SQUARE:
+ return kFFEffectType_Square_ID; */
+
+ case SDL_HAPTIC_SINE:
+ return kFFEffectType_Sine_ID;
+
+ case SDL_HAPTIC_TRIANGLE:
+ return kFFEffectType_Triangle_ID;
+
+ case SDL_HAPTIC_SAWTOOTHUP:
+ return kFFEffectType_SawtoothUp_ID;
+
+ case SDL_HAPTIC_SAWTOOTHDOWN:
+ return kFFEffectType_SawtoothDown_ID;
+
+ case SDL_HAPTIC_SPRING:
+ return kFFEffectType_Spring_ID;
+
+ case SDL_HAPTIC_DAMPER:
+ return kFFEffectType_Damper_ID;
+
+ case SDL_HAPTIC_INERTIA:
+ return kFFEffectType_Inertia_ID;
+
+ case SDL_HAPTIC_FRICTION:
+ return kFFEffectType_Friction_ID;
+
+ case SDL_HAPTIC_CUSTOM:
+ return kFFEffectType_CustomForce_ID;
+
+ default:
+ SDL_SetError("Haptic: Unknown effect type.");
+ return NULL;
+ }
+}
+
+
+/*
+ * Creates a new haptic effect.
+ */
+int
+SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
+ SDL_HapticEffect * base)
+{
+ HRESULT ret;
+ CFUUIDRef type;
+
+ /* Alloc the effect. */
+ effect->hweffect = (struct haptic_hweffect *)
+ SDL_malloc(sizeof(struct haptic_hweffect));
+ if (effect->hweffect == NULL) {
+ SDL_OutOfMemory();
+ goto err_hweffect;
+ }
+
+ /* Get the type. */
+ type = SDL_SYS_HapticEffectType(base->type);
+ if (type == NULL) {
+ goto err_hweffect;
+ }
+
+ /* Get the effect. */
+ if (SDL_SYS_ToFFEFFECT(haptic, &effect->hweffect->effect, base) < 0) {
+ goto err_effectdone;
+ }
+
+ /* Create the actual effect. */
+ ret = FFDeviceCreateEffect(haptic->hwdata->device, type,
+ &effect->hweffect->effect,
+ &effect->hweffect->ref);
+ if (ret != FF_OK) {
+ SDL_SetError("Haptic: Unable to create effect: %s.", FFStrError(ret));
+ goto err_effectdone;
+ }
+
+ return 0;
+
+ err_effectdone:
+ SDL_SYS_HapticFreeFFEFFECT(&effect->hweffect->effect, base->type);
+ err_hweffect:
+ SDL_free(effect->hweffect);
+ effect->hweffect = NULL;
+ return -1;
+}
+
+
+/*
+ * Updates an effect.
+ */
+int
+SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
+ struct haptic_effect *effect,
+ SDL_HapticEffect * data)
+{
+ HRESULT ret;
+ FFEffectParameterFlag flags;
+ FFEFFECT temp;
+
+ /* Get the effect. */
+ SDL_memset(&temp, 0, sizeof(FFEFFECT));
+ if (SDL_SYS_ToFFEFFECT(haptic, &temp, data) < 0) {
+ goto err_update;
+ }
+
+ /* Set the flags. Might be worthwhile to diff temp with loaded effect and
+ * only change those parameters. */
+ flags = FFEP_DIRECTION |
+ FFEP_DURATION |
+ FFEP_ENVELOPE |
+ FFEP_STARTDELAY |
+ FFEP_TRIGGERBUTTON |
+ FFEP_TRIGGERREPEATINTERVAL | FFEP_TYPESPECIFICPARAMS;
+
+ /* Create the actual effect. */
+ ret = FFEffectSetParameters(effect->hweffect->ref, &temp, flags);
+ if (ret != FF_OK) {
+ SDL_SetError("Haptic: Unable to update effect: %s.", FFStrError(ret));
+ goto err_update;
+ }
+
+ /* Copy it over. */
+ SDL_SYS_HapticFreeFFEFFECT(&effect->hweffect->effect, data->type);
+ SDL_memcpy(&effect->hweffect->effect, &temp, sizeof(FFEFFECT));
+
+ return 0;
+
+ err_update:
+ SDL_SYS_HapticFreeFFEFFECT(&temp, data->type);
+ return -1;
+}
+
+
+/*
+ * Runs an effect.
+ */
+int
+SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
+ Uint32 iterations)
+{
+ HRESULT ret;
+ Uint32 iter;
+
+ /* Check if it's infinite. */
+ if (iterations == SDL_HAPTIC_INFINITY) {
+ iter = FF_INFINITE;
+ } else
+ iter = iterations;
+
+ /* Run the effect. */
+ ret = FFEffectStart(effect->hweffect->ref, iter, 0);
+ if (ret != FF_OK) {
+ return SDL_SetError("Haptic: Unable to run the effect: %s.",
+ FFStrError(ret));
+ }
+
+ return 0;
+}
+
+
+/*
+ * Stops an effect.
+ */
+int
+SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ HRESULT ret;
+
+ ret = FFEffectStop(effect->hweffect->ref);
+ if (ret != FF_OK) {
+ return SDL_SetError("Haptic: Unable to stop the effect: %s.",
+ FFStrError(ret));
+ }
+
+ return 0;
+}
+
+
+/*
+ * Frees the effect.
+ */
+void
+SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ HRESULT ret;
+
+ ret = FFDeviceReleaseEffect(haptic->hwdata->device, effect->hweffect->ref);
+ if (ret != FF_OK) {
+ SDL_SetError("Haptic: Error removing the effect from the device: %s.",
+ FFStrError(ret));
+ }
+ SDL_SYS_HapticFreeFFEFFECT(&effect->hweffect->effect,
+ effect->effect.type);
+ SDL_free(effect->hweffect);
+ effect->hweffect = NULL;
+}
+
+
+/*
+ * Gets the status of a haptic effect.
+ */
+int
+SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
+ struct haptic_effect *effect)
+{
+ HRESULT ret;
+ FFEffectStatusFlag status;
+
+ ret = FFEffectGetEffectStatus(effect->hweffect->ref, &status);
+ if (ret != FF_OK) {
+ SDL_SetError("Haptic: Unable to get effect status: %s.",
+ FFStrError(ret));
+ return -1;
+ }
+
+ if (status == 0) {
+ return SDL_FALSE;
+ }
+ return SDL_TRUE; /* Assume it's playing or emulated. */
+}
+
+
+/*
+ * Sets the gain.
+ */
+int
+SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
+{
+ HRESULT ret;
+ Uint32 val;
+
+ val = gain * 100; /* Mac OS X uses 0 to 10,000 */
+ ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device,
+ FFPROP_FFGAIN, &val);
+ if (ret != FF_OK) {
+ return SDL_SetError("Haptic: Error setting gain: %s.", FFStrError(ret));
+ }
+
+ return 0;
+}
+
+
+/*
+ * Sets the autocentering.
+ */
+int
+SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
+{
+ HRESULT ret;
+ Uint32 val;
+
+ /* Mac OS X only has 0 (off) and 1 (on) */
+ if (autocenter == 0) {
+ val = 0;
+ } else {
+ val = 1;
+ }
+
+ ret = FFDeviceSetForceFeedbackProperty(haptic->hwdata->device,
+ FFPROP_AUTOCENTER, &val);
+ if (ret != FF_OK) {
+ return SDL_SetError("Haptic: Error setting autocenter: %s.",
+ FFStrError(ret));
+ }
+
+ return 0;
+}
+
+
+/*
+ * Pauses the device.
+ */
+int
+SDL_SYS_HapticPause(SDL_Haptic * haptic)
+{
+ HRESULT ret;
+
+ ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
+ FFSFFC_PAUSE);
+ if (ret != FF_OK) {
+ return SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
+ }
+
+ return 0;
+}
+
+
+/*
+ * Unpauses the device.
+ */
+int
+SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
+{
+ HRESULT ret;
+
+ ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
+ FFSFFC_CONTINUE);
+ if (ret != FF_OK) {
+ return SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
+ }
+
+ return 0;
+}
+
+
+/*
+ * Stops all currently playing effects.
+ */
+int
+SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
+{
+ HRESULT ret;
+
+ ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
+ FFSFFC_STOPALL);
+ if (ret != FF_OK) {
+ return SDL_SetError("Haptic: Error stopping device: %s.", FFStrError(ret));
+ }
+
+ return 0;
+}
+
+#endif /* SDL_HAPTIC_IOKIT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/haptic/darwin/SDL_syshaptic_c.h b/src/3rdparty/SDL2/src/haptic/darwin/SDL_syshaptic_c.h
new file mode 100644
index 0000000..073db53
--- /dev/null
+++ b/src/3rdparty/SDL2/src/haptic/darwin/SDL_syshaptic_c.h
@@ -0,0 +1,26 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+extern int MacHaptic_MaybeAddDevice( io_object_t device );
+extern int MacHaptic_MaybeRemoveDevice( io_object_t device );
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/haptic/dummy/SDL_syshaptic.c b/src/3rdparty/SDL2/src/haptic/dummy/SDL_syshaptic.c
new file mode 100644
index 0000000..283fe67
--- /dev/null
+++ b/src/3rdparty/SDL2/src/haptic/dummy/SDL_syshaptic.c
@@ -0,0 +1,186 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if defined(SDL_HAPTIC_DUMMY) || defined(SDL_HAPTIC_DISABLED)
+
+#include "SDL_haptic.h"
+#include "../SDL_syshaptic.h"
+
+
+static int
+SDL_SYS_LogicError(void)
+{
+ return SDL_SetError("Logic error: No haptic devices available.");
+}
+
+
+int
+SDL_SYS_HapticInit(void)
+{
+ return 0;
+}
+
+int
+SDL_SYS_NumHaptics(void)
+{
+ return 0;
+}
+
+const char *
+SDL_SYS_HapticName(int index)
+{
+ SDL_SYS_LogicError();
+ return NULL;
+}
+
+
+int
+SDL_SYS_HapticOpen(SDL_Haptic * haptic)
+{
+ return SDL_SYS_LogicError();
+}
+
+
+int
+SDL_SYS_HapticMouse(void)
+{
+ return -1;
+}
+
+
+int
+SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
+{
+ return 0;
+}
+
+
+int
+SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
+{
+ return SDL_SYS_LogicError();
+}
+
+
+int
+SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
+{
+ return 0;
+}
+
+
+void
+SDL_SYS_HapticClose(SDL_Haptic * haptic)
+{
+ return;
+}
+
+
+void
+SDL_SYS_HapticQuit(void)
+{
+ return;
+}
+
+
+int
+SDL_SYS_HapticNewEffect(SDL_Haptic * haptic,
+ struct haptic_effect *effect, SDL_HapticEffect * base)
+{
+ return SDL_SYS_LogicError();
+}
+
+
+int
+SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
+ struct haptic_effect *effect,
+ SDL_HapticEffect * data)
+{
+ return SDL_SYS_LogicError();
+}
+
+
+int
+SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
+ Uint32 iterations)
+{
+ return SDL_SYS_LogicError();
+}
+
+
+int
+SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ return SDL_SYS_LogicError();
+}
+
+
+void
+SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ SDL_SYS_LogicError();
+ return;
+}
+
+
+int
+SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
+ struct haptic_effect *effect)
+{
+ return SDL_SYS_LogicError();
+}
+
+
+int
+SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
+{
+ return SDL_SYS_LogicError();
+}
+
+
+int
+SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
+{
+ return SDL_SYS_LogicError();
+}
+
+int
+SDL_SYS_HapticPause(SDL_Haptic * haptic)
+{
+ return SDL_SYS_LogicError();
+}
+
+int
+SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
+{
+ return SDL_SYS_LogicError();
+}
+
+int
+SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
+{
+ return SDL_SYS_LogicError();
+}
+
+#endif /* SDL_HAPTIC_DUMMY || SDL_HAPTIC_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/haptic/linux/SDL_syshaptic.c b/src/3rdparty/SDL2/src/haptic/linux/SDL_syshaptic.c
new file mode 100644
index 0000000..9c11a2f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/haptic/linux/SDL_syshaptic.c
@@ -0,0 +1,1162 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_HAPTIC_LINUX
+
+#include "SDL_assert.h"
+#include "SDL_haptic.h"
+#include "../SDL_syshaptic.h"
+#include "SDL_joystick.h"
+#include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */
+#include "../../joystick/linux/SDL_sysjoystick_c.h" /* For joystick hwdata */
+#include "../../core/linux/SDL_udev.h"
+
+#include <unistd.h> /* close */
+#include <linux/input.h> /* Force feedback linux stuff. */
+#include <fcntl.h> /* O_RDWR */
+#include <limits.h> /* INT_MAX */
+#include <errno.h> /* errno, strerror */
+#include <math.h> /* atan2 */
+#include <sys/stat.h> /* stat */
+
+/* Just in case. */
+#ifndef M_PI
+# define M_PI 3.14159265358979323846
+#endif
+
+
+#define MAX_HAPTICS 32 /* It's doubtful someone has more then 32 evdev */
+
+static int MaybeAddDevice(const char *path);
+#if SDL_USE_LIBUDEV
+static int MaybeRemoveDevice(const char *path);
+static void haptic_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath);
+#endif /* SDL_USE_LIBUDEV */
+
+/*
+ * List of available haptic devices.
+ */
+typedef struct SDL_hapticlist_item
+{
+ char *fname; /* Dev path name (like /dev/input/event1) */
+ SDL_Haptic *haptic; /* Associated haptic. */
+ dev_t dev_num;
+ struct SDL_hapticlist_item *next;
+} SDL_hapticlist_item;
+
+
+/*
+ * Haptic system hardware data.
+ */
+struct haptic_hwdata
+{
+ int fd; /* File descriptor of the device. */
+ char *fname; /* Points to the name in SDL_hapticlist. */
+};
+
+
+/*
+ * Haptic system effect data.
+ */
+struct haptic_hweffect
+{
+ struct ff_effect effect; /* The linux kernel effect structure. */
+};
+
+static SDL_hapticlist_item *SDL_hapticlist = NULL;
+static SDL_hapticlist_item *SDL_hapticlist_tail = NULL;
+static int numhaptics = 0;
+
+#define test_bit(nr, addr) \
+ (((1UL << ((nr) & 31)) & (((const unsigned int *) addr)[(nr) >> 5])) != 0)
+#define EV_TEST(ev,f) \
+ if (test_bit((ev), features)) ret |= (f);
+/*
+ * Test whether a device has haptic properties.
+ * Returns available properties or 0 if there are none.
+ */
+static int
+EV_IsHaptic(int fd)
+{
+ unsigned int ret;
+ unsigned long features[1 + FF_MAX / sizeof(unsigned long)];
+
+ /* Ask device for what it has. */
+ ret = 0;
+ if (ioctl(fd, EVIOCGBIT(EV_FF, sizeof(features)), features) < 0) {
+ return SDL_SetError("Haptic: Unable to get device's features: %s",
+ strerror(errno));
+ }
+
+ /* Convert supported features to SDL_HAPTIC platform-neutral features. */
+ EV_TEST(FF_CONSTANT, SDL_HAPTIC_CONSTANT);
+ EV_TEST(FF_SINE, SDL_HAPTIC_SINE);
+ /* !!! FIXME: put this back when we have more bits in 2.1 */
+ /* EV_TEST(FF_SQUARE, SDL_HAPTIC_SQUARE); */
+ EV_TEST(FF_TRIANGLE, SDL_HAPTIC_TRIANGLE);
+ EV_TEST(FF_SAW_UP, SDL_HAPTIC_SAWTOOTHUP);
+ EV_TEST(FF_SAW_DOWN, SDL_HAPTIC_SAWTOOTHDOWN);
+ EV_TEST(FF_RAMP, SDL_HAPTIC_RAMP);
+ EV_TEST(FF_SPRING, SDL_HAPTIC_SPRING);
+ EV_TEST(FF_FRICTION, SDL_HAPTIC_FRICTION);
+ EV_TEST(FF_DAMPER, SDL_HAPTIC_DAMPER);
+ EV_TEST(FF_INERTIA, SDL_HAPTIC_INERTIA);
+ EV_TEST(FF_CUSTOM, SDL_HAPTIC_CUSTOM);
+ EV_TEST(FF_GAIN, SDL_HAPTIC_GAIN);
+ EV_TEST(FF_AUTOCENTER, SDL_HAPTIC_AUTOCENTER);
+ EV_TEST(FF_RUMBLE, SDL_HAPTIC_LEFTRIGHT);
+
+ /* Return what it supports. */
+ return ret;
+}
+
+
+/*
+ * Tests whether a device is a mouse or not.
+ */
+static int
+EV_IsMouse(int fd)
+{
+ unsigned long argp[40];
+
+ /* Ask for supported features. */
+ if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(argp)), argp) < 0) {
+ return -1;
+ }
+
+ /* Currently we only test for BTN_MOUSE which can give fake positives. */
+ if (test_bit(BTN_MOUSE, argp) != 0) {
+ return 1;
+ }
+
+ return 0;
+}
+
+/*
+ * Initializes the haptic subsystem by finding available devices.
+ */
+int
+SDL_SYS_HapticInit(void)
+{
+ const char joydev_pattern[] = "/dev/input/event%d";
+ char path[PATH_MAX];
+ int i, j;
+
+ /*
+ * Limit amount of checks to MAX_HAPTICS since we may or may not have
+ * permission to some or all devices.
+ */
+ i = 0;
+ for (j = 0; j < MAX_HAPTICS; ++j) {
+
+ snprintf(path, PATH_MAX, joydev_pattern, i++);
+ MaybeAddDevice(path);
+ }
+
+#if SDL_USE_LIBUDEV
+ if (SDL_UDEV_Init() < 0) {
+ return SDL_SetError("Could not initialize UDEV");
+ }
+
+ if ( SDL_UDEV_AddCallback(haptic_udev_callback) < 0) {
+ SDL_UDEV_Quit();
+ return SDL_SetError("Could not setup haptic <-> udev callback");
+ }
+#endif /* SDL_USE_LIBUDEV */
+
+ return numhaptics;
+}
+
+int
+SDL_SYS_NumHaptics(void)
+{
+ return numhaptics;
+}
+
+static SDL_hapticlist_item *
+HapticByDevIndex(int device_index)
+{
+ SDL_hapticlist_item *item = SDL_hapticlist;
+
+ if ((device_index < 0) || (device_index >= numhaptics)) {
+ return NULL;
+ }
+
+ while (device_index > 0) {
+ SDL_assert(item != NULL);
+ --device_index;
+ item = item->next;
+ }
+
+ return item;
+}
+
+#if SDL_USE_LIBUDEV
+static void haptic_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath)
+{
+ if (devpath == NULL || !(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
+ return;
+ }
+
+ switch( udev_type )
+ {
+ case SDL_UDEV_DEVICEADDED:
+ MaybeAddDevice(devpath);
+ break;
+
+ case SDL_UDEV_DEVICEREMOVED:
+ MaybeRemoveDevice(devpath);
+ break;
+
+ default:
+ break;
+ }
+
+}
+#endif /* SDL_USE_LIBUDEV */
+
+static int
+MaybeAddDevice(const char *path)
+{
+ struct stat sb;
+ int fd;
+ int success;
+ SDL_hapticlist_item *item;
+
+ if (path == NULL) {
+ return -1;
+ }
+
+ /* check to see if file exists */
+ if (stat(path, &sb) != 0) {
+ return -1;
+ }
+
+ /* check for duplicates */
+ for (item = SDL_hapticlist; item != NULL; item = item->next) {
+ if (item->dev_num == sb.st_rdev) {
+ return -1; /* duplicate. */
+ }
+ }
+
+ /* try to open */
+ fd = open(path, O_RDWR, 0);
+ if (fd < 0) {
+ return -1;
+ }
+
+#ifdef DEBUG_INPUT_EVENTS
+ printf("Checking %s\n", path);
+#endif
+
+ /* see if it works */
+ success = EV_IsHaptic(fd);
+ close(fd);
+ if (success <= 0) {
+ return -1;
+ }
+
+ item = (SDL_hapticlist_item *) SDL_calloc(1, sizeof (SDL_hapticlist_item));
+ if (item == NULL) {
+ return -1;
+ }
+
+ item->fname = SDL_strdup(path);
+ if (item->fname == NULL) {
+ SDL_free(item);
+ return -1;
+ }
+
+ item->dev_num = sb.st_rdev;
+
+ /* TODO: should we add instance IDs? */
+ if (SDL_hapticlist_tail == NULL) {
+ SDL_hapticlist = SDL_hapticlist_tail = item;
+ } else {
+ SDL_hapticlist_tail->next = item;
+ SDL_hapticlist_tail = item;
+ }
+
+ ++numhaptics;
+
+ /* !!! TODO: Send a haptic add event? */
+
+ return numhaptics;
+}
+
+#if SDL_USE_LIBUDEV
+static int
+MaybeRemoveDevice(const char* path)
+{
+ SDL_hapticlist_item *item;
+ SDL_hapticlist_item *prev = NULL;
+
+ if (path == NULL) {
+ return -1;
+ }
+
+ for (item = SDL_hapticlist; item != NULL; item = item->next) {
+ /* found it, remove it. */
+ if (SDL_strcmp(path, item->fname) == 0) {
+ const int retval = item->haptic ? item->haptic->index : -1;
+
+ if (prev != NULL) {
+ prev->next = item->next;
+ } else {
+ SDL_assert(SDL_hapticlist == item);
+ SDL_hapticlist = item->next;
+ }
+ if (item == SDL_hapticlist_tail) {
+ SDL_hapticlist_tail = prev;
+ }
+
+ /* Need to decrement the haptic count */
+ --numhaptics;
+ /* !!! TODO: Send a haptic remove event? */
+
+ SDL_free(item->fname);
+ SDL_free(item);
+ return retval;
+ }
+ prev = item;
+ }
+
+ return -1;
+}
+#endif /* SDL_USE_LIBUDEV */
+
+/*
+ * Gets the name from a file descriptor.
+ */
+static const char *
+SDL_SYS_HapticNameFromFD(int fd)
+{
+ static char namebuf[128];
+
+ /* We use the evdev name ioctl. */
+ if (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) {
+ return NULL;
+ }
+
+ return namebuf;
+}
+
+
+/*
+ * Return the name of a haptic device, does not need to be opened.
+ */
+const char *
+SDL_SYS_HapticName(int index)
+{
+ SDL_hapticlist_item *item;
+ int fd;
+ const char *name;
+
+ item = HapticByDevIndex(index);
+ /* Open the haptic device. */
+ name = NULL;
+ fd = open(item->fname, O_RDONLY, 0);
+
+ if (fd >= 0) {
+
+ name = SDL_SYS_HapticNameFromFD(fd);
+ if (name == NULL) {
+ /* No name found, return device character device */
+ name = item->fname;
+ }
+ close(fd);
+ }
+
+ return name;
+}
+
+
+/*
+ * Opens the haptic device from the file descriptor.
+ */
+static int
+SDL_SYS_HapticOpenFromFD(SDL_Haptic * haptic, int fd)
+{
+ /* Allocate the hwdata */
+ haptic->hwdata = (struct haptic_hwdata *)
+ SDL_malloc(sizeof(*haptic->hwdata));
+ if (haptic->hwdata == NULL) {
+ SDL_OutOfMemory();
+ goto open_err;
+ }
+ SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
+
+ /* Set the data. */
+ haptic->hwdata->fd = fd;
+ haptic->supported = EV_IsHaptic(fd);
+ haptic->naxes = 2; /* Hardcoded for now, not sure if it's possible to find out. */
+
+ /* Set the effects */
+ if (ioctl(fd, EVIOCGEFFECTS, &haptic->neffects) < 0) {
+ SDL_SetError("Haptic: Unable to query device memory: %s",
+ strerror(errno));
+ goto open_err;
+ }
+ haptic->nplaying = haptic->neffects; /* Linux makes no distinction. */
+ haptic->effects = (struct haptic_effect *)
+ SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
+ if (haptic->effects == NULL) {
+ SDL_OutOfMemory();
+ goto open_err;
+ }
+ /* Clear the memory */
+ SDL_memset(haptic->effects, 0,
+ sizeof(struct haptic_effect) * haptic->neffects);
+
+ return 0;
+
+ /* Error handling */
+ open_err:
+ close(fd);
+ if (haptic->hwdata != NULL) {
+ SDL_free(haptic->hwdata);
+ haptic->hwdata = NULL;
+ }
+ return -1;
+}
+
+
+/*
+ * Opens a haptic device for usage.
+ */
+int
+SDL_SYS_HapticOpen(SDL_Haptic * haptic)
+{
+ int fd;
+ int ret;
+ SDL_hapticlist_item *item;
+
+ item = HapticByDevIndex(haptic->index);
+ /* Open the character device */
+ fd = open(item->fname, O_RDWR, 0);
+ if (fd < 0) {
+ return SDL_SetError("Haptic: Unable to open %s: %s",
+ item->fname, strerror(errno));
+ }
+
+ /* Try to create the haptic. */
+ ret = SDL_SYS_HapticOpenFromFD(haptic, fd); /* Already closes on error. */
+ if (ret < 0) {
+ return -1;
+ }
+
+ /* Set the fname. */
+ haptic->hwdata->fname = SDL_strdup( item->fname );
+ return 0;
+}
+
+
+/*
+ * Opens a haptic device from first mouse it finds for usage.
+ */
+int
+SDL_SYS_HapticMouse(void)
+{
+ int fd;
+ int device_index = 0;
+ SDL_hapticlist_item *item;
+
+ for (item = SDL_hapticlist; item; item = item->next) {
+ /* Open the device. */
+ fd = open(item->fname, O_RDWR, 0);
+ if (fd < 0) {
+ return SDL_SetError("Haptic: Unable to open %s: %s",
+ item->fname, strerror(errno));
+ }
+
+ /* Is it a mouse? */
+ if (EV_IsMouse(fd)) {
+ close(fd);
+ return device_index;
+ }
+
+ close(fd);
+
+ ++device_index;
+ }
+
+ return -1;
+}
+
+
+/*
+ * Checks to see if a joystick has haptic features.
+ */
+int
+SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
+{
+ return EV_IsHaptic(joystick->hwdata->fd);
+}
+
+
+/*
+ * Checks to see if the haptic device and joystick are in reality the same.
+ */
+int
+SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
+{
+ /* We are assuming Linux is using evdev which should trump the old
+ * joystick methods. */
+ if (SDL_strcmp(joystick->hwdata->fname, haptic->hwdata->fname) == 0) {
+ return 1;
+ }
+ return 0;
+}
+
+
+/*
+ * Opens a SDL_Haptic from a SDL_Joystick.
+ */
+int
+SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
+{
+ int device_index = 0;
+ int fd;
+ int ret;
+ SDL_hapticlist_item *item;
+
+ /* Find the joystick in the haptic list. */
+ for (item = SDL_hapticlist; item; item = item->next) {
+ if (SDL_strcmp(item->fname, joystick->hwdata->fname) == 0) {
+ break;
+ }
+ ++device_index;
+ }
+ haptic->index = device_index;
+
+ if (device_index >= MAX_HAPTICS) {
+ return SDL_SetError("Haptic: Joystick doesn't have Haptic capabilities");
+ }
+
+ fd = open(joystick->hwdata->fname, O_RDWR, 0);
+ if (fd < 0) {
+ return SDL_SetError("Haptic: Unable to open %s: %s",
+ joystick->hwdata->fname, strerror(errno));
+ }
+ ret = SDL_SYS_HapticOpenFromFD(haptic, fd); /* Already closes on error. */
+ if (ret < 0) {
+ return -1;
+ }
+
+ haptic->hwdata->fname = SDL_strdup( joystick->hwdata->fname );
+
+ return 0;
+}
+
+
+/*
+ * Closes the haptic device.
+ */
+void
+SDL_SYS_HapticClose(SDL_Haptic * haptic)
+{
+ if (haptic->hwdata) {
+
+ /* Free effects. */
+ SDL_free(haptic->effects);
+ haptic->effects = NULL;
+ haptic->neffects = 0;
+
+ /* Clean up */
+ close(haptic->hwdata->fd);
+
+ /* Free */
+ SDL_free(haptic->hwdata->fname);
+ SDL_free(haptic->hwdata);
+ haptic->hwdata = NULL;
+ }
+
+ /* Clear the rest. */
+ SDL_memset(haptic, 0, sizeof(SDL_Haptic));
+}
+
+
+/*
+ * Clean up after system specific haptic stuff
+ */
+void
+SDL_SYS_HapticQuit(void)
+{
+ SDL_hapticlist_item *item = NULL;
+ SDL_hapticlist_item *next = NULL;
+
+ for (item = SDL_hapticlist; item; item = next) {
+ next = item->next;
+ /* Opened and not closed haptics are leaked, this is on purpose.
+ * Close your haptic devices after usage. */
+ SDL_free(item->fname);
+ SDL_free(item);
+ }
+
+#if SDL_USE_LIBUDEV
+ SDL_UDEV_DelCallback(haptic_udev_callback);
+ SDL_UDEV_Quit();
+#endif /* SDL_USE_LIBUDEV */
+
+ numhaptics = 0;
+ SDL_hapticlist = NULL;
+ SDL_hapticlist_tail = NULL;
+}
+
+
+/*
+ * Converts an SDL button to a ff_trigger button.
+ */
+static Uint16
+SDL_SYS_ToButton(Uint16 button)
+{
+ Uint16 ff_button;
+
+ ff_button = 0;
+
+ /*
+ * Not sure what the proper syntax is because this actually isn't implemented
+ * in the current kernel from what I've seen (2.6.26).
+ */
+ if (button != 0) {
+ ff_button = BTN_GAMEPAD + button - 1;
+ }
+
+ return ff_button;
+}
+
+
+/*
+ * Initializes the ff_effect usable direction from a SDL_HapticDirection.
+ */
+static int
+SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
+{
+ Uint32 tmp;
+
+ switch (src->type) {
+ case SDL_HAPTIC_POLAR:
+ /* Linux directions start from south.
+ (and range from 0 to 0xFFFF)
+ Quoting include/linux/input.h, line 926:
+ Direction of the effect is encoded as follows:
+ 0 deg -> 0x0000 (down)
+ 90 deg -> 0x4000 (left)
+ 180 deg -> 0x8000 (up)
+ 270 deg -> 0xC000 (right)
+ The force pulls into the direction specified by Linux directions,
+ i.e. the opposite convention of SDL directions.
+ */
+ tmp = ((src->dir[0] % 36000) * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
+ *dest = (Uint16) tmp;
+ break;
+
+ case SDL_HAPTIC_SPHERICAL:
+ /*
+ We convert to polar, because that's the only supported direction on Linux.
+ The first value of a spherical direction is practically the same as a
+ Polar direction, except that we have to add 90 degrees. It is the angle
+ from EAST {1,0} towards SOUTH {0,1}.
+ --> add 9000
+ --> finally convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
+ */
+ tmp = ((src->dir[0]) + 9000) % 36000; /* Convert to polars */
+ tmp = (tmp * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
+ *dest = (Uint16) tmp;
+ break;
+
+ case SDL_HAPTIC_CARTESIAN:
+ if (!src->dir[1])
+ *dest = (src->dir[0] >= 0 ? 0x4000 : 0xC000);
+ else if (!src->dir[0])
+ *dest = (src->dir[1] >= 0 ? 0x8000 : 0);
+ else {
+ float f = SDL_atan2(src->dir[1], src->dir[0]); /* Ideally we'd use fixed point math instead of floats... */
+ /*
+ atan2 takes the parameters: Y-axis-value and X-axis-value (in that order)
+ - Y-axis-value is the second coordinate (from center to SOUTH)
+ - X-axis-value is the first coordinate (from center to EAST)
+ We add 36000, because atan2 also returns negative values. Then we practically
+ have the first spherical value. Therefore we proceed as in case
+ SDL_HAPTIC_SPHERICAL and add another 9000 to get the polar value.
+ --> add 45000 in total
+ --> finally convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
+ */
+ tmp = (((Sint32) (f * 18000. / M_PI)) + 45000) % 36000;
+ tmp = (tmp * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
+ *dest = (Uint16) tmp;
+ }
+ break;
+
+ default:
+ return SDL_SetError("Haptic: Unsupported direction type.");
+ }
+
+ return 0;
+}
+
+
+#define CLAMP(x) (((x) > 32767) ? 32767 : x)
+/*
+ * Initializes the Linux effect struct from a haptic_effect.
+ * Values above 32767 (for unsigned) are unspecified so we must clamp.
+ */
+static int
+SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect * src)
+{
+ SDL_HapticConstant *constant;
+ SDL_HapticPeriodic *periodic;
+ SDL_HapticCondition *condition;
+ SDL_HapticRamp *ramp;
+ SDL_HapticLeftRight *leftright;
+
+ /* Clear up */
+ SDL_memset(dest, 0, sizeof(struct ff_effect));
+
+ switch (src->type) {
+ case SDL_HAPTIC_CONSTANT:
+ constant = &src->constant;
+
+ /* Header */
+ dest->type = FF_CONSTANT;
+ if (SDL_SYS_ToDirection(&dest->direction, &constant->direction) == -1)
+ return -1;
+
+ /* Replay */
+ dest->replay.length = (constant->length == SDL_HAPTIC_INFINITY) ?
+ 0 : CLAMP(constant->length);
+ dest->replay.delay = CLAMP(constant->delay);
+
+ /* Trigger */
+ dest->trigger.button = SDL_SYS_ToButton(constant->button);
+ dest->trigger.interval = CLAMP(constant->interval);
+
+ /* Constant */
+ dest->u.constant.level = constant->level;
+
+ /* Envelope */
+ dest->u.constant.envelope.attack_length =
+ CLAMP(constant->attack_length);
+ dest->u.constant.envelope.attack_level =
+ CLAMP(constant->attack_level);
+ dest->u.constant.envelope.fade_length = CLAMP(constant->fade_length);
+ dest->u.constant.envelope.fade_level = CLAMP(constant->fade_level);
+
+ break;
+
+ case SDL_HAPTIC_SINE:
+ /* !!! FIXME: put this back when we have more bits in 2.1 */
+ /* case SDL_HAPTIC_SQUARE: */
+ case SDL_HAPTIC_TRIANGLE:
+ case SDL_HAPTIC_SAWTOOTHUP:
+ case SDL_HAPTIC_SAWTOOTHDOWN:
+ periodic = &src->periodic;
+
+ /* Header */
+ dest->type = FF_PERIODIC;
+ if (SDL_SYS_ToDirection(&dest->direction, &periodic->direction) == -1)
+ return -1;
+
+ /* Replay */
+ dest->replay.length = (periodic->length == SDL_HAPTIC_INFINITY) ?
+ 0 : CLAMP(periodic->length);
+ dest->replay.delay = CLAMP(periodic->delay);
+
+ /* Trigger */
+ dest->trigger.button = SDL_SYS_ToButton(periodic->button);
+ dest->trigger.interval = CLAMP(periodic->interval);
+
+ /* Periodic */
+ if (periodic->type == SDL_HAPTIC_SINE)
+ dest->u.periodic.waveform = FF_SINE;
+ /* !!! FIXME: put this back when we have more bits in 2.1 */
+ /* else if (periodic->type == SDL_HAPTIC_SQUARE)
+ dest->u.periodic.waveform = FF_SQUARE; */
+ else if (periodic->type == SDL_HAPTIC_TRIANGLE)
+ dest->u.periodic.waveform = FF_TRIANGLE;
+ else if (periodic->type == SDL_HAPTIC_SAWTOOTHUP)
+ dest->u.periodic.waveform = FF_SAW_UP;
+ else if (periodic->type == SDL_HAPTIC_SAWTOOTHDOWN)
+ dest->u.periodic.waveform = FF_SAW_DOWN;
+ dest->u.periodic.period = CLAMP(periodic->period);
+ dest->u.periodic.magnitude = periodic->magnitude;
+ dest->u.periodic.offset = periodic->offset;
+ /* Linux phase is defined in interval "[0x0000, 0x10000[", corresponds with "[0deg, 360deg[" phase shift. */
+ dest->u.periodic.phase = ((Uint32)periodic->phase * 0x10000U) / 36000;
+
+ /* Envelope */
+ dest->u.periodic.envelope.attack_length =
+ CLAMP(periodic->attack_length);
+ dest->u.periodic.envelope.attack_level =
+ CLAMP(periodic->attack_level);
+ dest->u.periodic.envelope.fade_length = CLAMP(periodic->fade_length);
+ dest->u.periodic.envelope.fade_level = CLAMP(periodic->fade_level);
+
+ break;
+
+ case SDL_HAPTIC_SPRING:
+ case SDL_HAPTIC_DAMPER:
+ case SDL_HAPTIC_INERTIA:
+ case SDL_HAPTIC_FRICTION:
+ condition = &src->condition;
+
+ /* Header */
+ if (condition->type == SDL_HAPTIC_SPRING)
+ dest->type = FF_SPRING;
+ else if (condition->type == SDL_HAPTIC_DAMPER)
+ dest->type = FF_DAMPER;
+ else if (condition->type == SDL_HAPTIC_INERTIA)
+ dest->type = FF_INERTIA;
+ else if (condition->type == SDL_HAPTIC_FRICTION)
+ dest->type = FF_FRICTION;
+ dest->direction = 0; /* Handled by the condition-specifics. */
+
+ /* Replay */
+ dest->replay.length = (condition->length == SDL_HAPTIC_INFINITY) ?
+ 0 : CLAMP(condition->length);
+ dest->replay.delay = CLAMP(condition->delay);
+
+ /* Trigger */
+ dest->trigger.button = SDL_SYS_ToButton(condition->button);
+ dest->trigger.interval = CLAMP(condition->interval);
+
+ /* Condition */
+ /* X axis */
+ dest->u.condition[0].right_saturation = condition->right_sat[0];
+ dest->u.condition[0].left_saturation = condition->left_sat[0];
+ dest->u.condition[0].right_coeff = condition->right_coeff[0];
+ dest->u.condition[0].left_coeff = condition->left_coeff[0];
+ dest->u.condition[0].deadband = condition->deadband[0];
+ dest->u.condition[0].center = condition->center[0];
+ /* Y axis */
+ dest->u.condition[1].right_saturation = condition->right_sat[1];
+ dest->u.condition[1].left_saturation = condition->left_sat[1];
+ dest->u.condition[1].right_coeff = condition->right_coeff[1];
+ dest->u.condition[1].left_coeff = condition->left_coeff[1];
+ dest->u.condition[1].deadband = condition->deadband[1];
+ dest->u.condition[1].center = condition->center[1];
+
+ /*
+ * There is no envelope in the linux force feedback api for conditions.
+ */
+
+ break;
+
+ case SDL_HAPTIC_RAMP:
+ ramp = &src->ramp;
+
+ /* Header */
+ dest->type = FF_RAMP;
+ if (SDL_SYS_ToDirection(&dest->direction, &ramp->direction) == -1)
+ return -1;
+
+ /* Replay */
+ dest->replay.length = (ramp->length == SDL_HAPTIC_INFINITY) ?
+ 0 : CLAMP(ramp->length);
+ dest->replay.delay = CLAMP(ramp->delay);
+
+ /* Trigger */
+ dest->trigger.button = SDL_SYS_ToButton(ramp->button);
+ dest->trigger.interval = CLAMP(ramp->interval);
+
+ /* Ramp */
+ dest->u.ramp.start_level = ramp->start;
+ dest->u.ramp.end_level = ramp->end;
+
+ /* Envelope */
+ dest->u.ramp.envelope.attack_length = CLAMP(ramp->attack_length);
+ dest->u.ramp.envelope.attack_level = CLAMP(ramp->attack_level);
+ dest->u.ramp.envelope.fade_length = CLAMP(ramp->fade_length);
+ dest->u.ramp.envelope.fade_level = CLAMP(ramp->fade_level);
+
+ break;
+
+ case SDL_HAPTIC_LEFTRIGHT:
+ leftright = &src->leftright;
+
+ /* Header */
+ dest->type = FF_RUMBLE;
+ dest->direction = 0;
+
+ /* Replay */
+ dest->replay.length = (leftright->length == SDL_HAPTIC_INFINITY) ?
+ 0 : CLAMP(leftright->length);
+
+ /* Trigger */
+ dest->trigger.button = 0;
+ dest->trigger.interval = 0;
+
+ /* Rumble */
+ dest->u.rumble.strong_magnitude = leftright->large_magnitude;
+ dest->u.rumble.weak_magnitude = leftright->small_magnitude;
+
+ break;
+
+
+ default:
+ return SDL_SetError("Haptic: Unknown effect type.");
+ }
+
+ return 0;
+}
+
+
+/*
+ * Creates a new haptic effect.
+ */
+int
+SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
+ SDL_HapticEffect * base)
+{
+ struct ff_effect *linux_effect;
+
+ /* Allocate the hardware effect */
+ effect->hweffect = (struct haptic_hweffect *)
+ SDL_malloc(sizeof(struct haptic_hweffect));
+ if (effect->hweffect == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ /* Prepare the ff_effect */
+ linux_effect = &effect->hweffect->effect;
+ if (SDL_SYS_ToFFEffect(linux_effect, base) != 0) {
+ goto new_effect_err;
+ }
+ linux_effect->id = -1; /* Have the kernel give it an id */
+
+ /* Upload the effect */
+ if (ioctl(haptic->hwdata->fd, EVIOCSFF, linux_effect) < 0) {
+ SDL_SetError("Haptic: Error uploading effect to the device: %s",
+ strerror(errno));
+ goto new_effect_err;
+ }
+
+ return 0;
+
+ new_effect_err:
+ SDL_free(effect->hweffect);
+ effect->hweffect = NULL;
+ return -1;
+}
+
+
+/*
+ * Updates an effect.
+ *
+ * Note: Dynamically updating the direction can in some cases force
+ * the effect to restart and run once.
+ */
+int
+SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
+ struct haptic_effect *effect,
+ SDL_HapticEffect * data)
+{
+ struct ff_effect linux_effect;
+
+ /* Create the new effect */
+ if (SDL_SYS_ToFFEffect(&linux_effect, data) != 0) {
+ return -1;
+ }
+ linux_effect.id = effect->hweffect->effect.id;
+
+ /* See if it can be uploaded. */
+ if (ioctl(haptic->hwdata->fd, EVIOCSFF, &linux_effect) < 0) {
+ return SDL_SetError("Haptic: Error updating the effect: %s",
+ strerror(errno));
+ }
+
+ /* Copy the new effect into memory. */
+ SDL_memcpy(&effect->hweffect->effect, &linux_effect,
+ sizeof(struct ff_effect));
+
+ return effect->hweffect->effect.id;
+}
+
+
+/*
+ * Runs an effect.
+ */
+int
+SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
+ Uint32 iterations)
+{
+ struct input_event run;
+
+ /* Prepare to run the effect */
+ run.type = EV_FF;
+ run.code = effect->hweffect->effect.id;
+ /* We don't actually have infinity here, so we just do INT_MAX which is pretty damn close. */
+ run.value = (iterations > INT_MAX) ? INT_MAX : iterations;
+
+ if (write(haptic->hwdata->fd, (const void *) &run, sizeof(run)) < 0) {
+ return SDL_SetError("Haptic: Unable to run the effect: %s", strerror(errno));
+ }
+
+ return 0;
+}
+
+
+/*
+ * Stops an effect.
+ */
+int
+SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ struct input_event stop;
+
+ stop.type = EV_FF;
+ stop.code = effect->hweffect->effect.id;
+ stop.value = 0;
+
+ if (write(haptic->hwdata->fd, (const void *) &stop, sizeof(stop)) < 0) {
+ return SDL_SetError("Haptic: Unable to stop the effect: %s",
+ strerror(errno));
+ }
+
+ return 0;
+}
+
+
+/*
+ * Frees the effect.
+ */
+void
+SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ if (ioctl(haptic->hwdata->fd, EVIOCRMFF, effect->hweffect->effect.id) < 0) {
+ SDL_SetError("Haptic: Error removing the effect from the device: %s",
+ strerror(errno));
+ }
+ SDL_free(effect->hweffect);
+ effect->hweffect = NULL;
+}
+
+
+/*
+ * Gets the status of a haptic effect.
+ */
+int
+SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
+ struct haptic_effect *effect)
+{
+#if 0 /* Not supported atm. */
+ struct input_event ie;
+
+ ie.type = EV_FF;
+ ie.type = EV_FF_STATUS;
+ ie.code = effect->hweffect->effect.id;
+
+ if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
+ return SDL_SetError("Haptic: Error getting device status.");
+ }
+
+ return 0;
+#endif
+
+ return -1;
+}
+
+
+/*
+ * Sets the gain.
+ */
+int
+SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
+{
+ struct input_event ie;
+
+ ie.type = EV_FF;
+ ie.code = FF_GAIN;
+ ie.value = (0xFFFFUL * gain) / 100;
+
+ if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
+ return SDL_SetError("Haptic: Error setting gain: %s", strerror(errno));
+ }
+
+ return 0;
+}
+
+
+/*
+ * Sets the autocentering.
+ */
+int
+SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
+{
+ struct input_event ie;
+
+ ie.type = EV_FF;
+ ie.code = FF_AUTOCENTER;
+ ie.value = (0xFFFFUL * autocenter) / 100;
+
+ if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
+ return SDL_SetError("Haptic: Error setting autocenter: %s", strerror(errno));
+ }
+
+ return 0;
+}
+
+
+/*
+ * Pausing is not supported atm by linux.
+ */
+int
+SDL_SYS_HapticPause(SDL_Haptic * haptic)
+{
+ return -1;
+}
+
+
+/*
+ * Unpausing is not supported atm by linux.
+ */
+int
+SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
+{
+ return -1;
+}
+
+
+/*
+ * Stops all the currently playing effects.
+ */
+int
+SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
+{
+ int i, ret;
+
+ /* Linux does not support this natively so we have to loop. */
+ for (i = 0; i < haptic->neffects; i++) {
+ if (haptic->effects[i].hweffect != NULL) {
+ ret = SDL_SYS_HapticStopEffect(haptic, &haptic->effects[i]);
+ if (ret < 0) {
+ return SDL_SetError
+ ("Haptic: Error while trying to stop all playing effects.");
+ }
+ }
+ }
+ return 0;
+}
+
+#endif /* SDL_HAPTIC_LINUX */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/haptic/windows/SDL_dinputhaptic.c b/src/3rdparty/SDL2/src/haptic/windows/SDL_dinputhaptic.c
new file mode 100644
index 0000000..897d128
--- /dev/null
+++ b/src/3rdparty/SDL2/src/haptic/windows/SDL_dinputhaptic.c
@@ -0,0 +1,1305 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "SDL_error.h"
+#include "SDL_haptic.h"
+#include "../SDL_syshaptic.h"
+
+#if SDL_HAPTIC_DINPUT
+
+#include "SDL_stdinc.h"
+#include "SDL_timer.h"
+#include "SDL_windowshaptic_c.h"
+#include "SDL_dinputhaptic_c.h"
+#include "../../joystick/windows/SDL_windowsjoystick_c.h"
+
+/*
+ * External stuff.
+ */
+extern HWND SDL_HelperWindow;
+
+
+/*
+ * Internal stuff.
+ */
+static SDL_bool coinitialized = SDL_FALSE;
+static LPDIRECTINPUT8 dinput = NULL;
+
+
+/*
+ * Like SDL_SetError but for DX error codes.
+ */
+static int
+DI_SetError(const char *str, HRESULT err)
+{
+ /*
+ SDL_SetError("Haptic: %s - %s: %s", str,
+ DXGetErrorString8A(err), DXGetErrorDescription8A(err));
+ */
+ return SDL_SetError("Haptic error %s", str);
+}
+
+/*
+ * Callback to find the haptic devices.
+ */
+static BOOL CALLBACK
+EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
+{
+ (void) pContext;
+ SDL_DINPUT_MaybeAddDevice(pdidInstance);
+ return DIENUM_CONTINUE; /* continue enumerating */
+}
+
+int
+SDL_DINPUT_HapticInit(void)
+{
+ HRESULT ret;
+ HINSTANCE instance;
+
+ if (dinput != NULL) { /* Already open. */
+ return SDL_SetError("Haptic: SubSystem already open.");
+ }
+
+ ret = WIN_CoInitialize();
+ if (FAILED(ret)) {
+ return DI_SetError("Coinitialize", ret);
+ }
+
+ coinitialized = SDL_TRUE;
+
+ ret = CoCreateInstance(&CLSID_DirectInput8, NULL, CLSCTX_INPROC_SERVER,
+ &IID_IDirectInput8, (LPVOID)& dinput);
+ if (FAILED(ret)) {
+ SDL_SYS_HapticQuit();
+ return DI_SetError("CoCreateInstance", ret);
+ }
+
+ /* Because we used CoCreateInstance, we need to Initialize it, first. */
+ instance = GetModuleHandle(NULL);
+ if (instance == NULL) {
+ SDL_SYS_HapticQuit();
+ return SDL_SetError("GetModuleHandle() failed with error code %lu.",
+ GetLastError());
+ }
+ ret = IDirectInput8_Initialize(dinput, instance, DIRECTINPUT_VERSION);
+ if (FAILED(ret)) {
+ SDL_SYS_HapticQuit();
+ return DI_SetError("Initializing DirectInput device", ret);
+ }
+
+ /* Look for haptic devices. */
+ ret = IDirectInput8_EnumDevices(dinput,
+ 0,
+ EnumHapticsCallback,
+ NULL,
+ DIEDFL_FORCEFEEDBACK |
+ DIEDFL_ATTACHEDONLY);
+ if (FAILED(ret)) {
+ SDL_SYS_HapticQuit();
+ return DI_SetError("Enumerating DirectInput devices", ret);
+ }
+ return 0;
+}
+
+int
+SDL_DINPUT_MaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
+{
+ HRESULT ret;
+ LPDIRECTINPUTDEVICE8 device;
+ const DWORD needflags = DIDC_ATTACHED | DIDC_FORCEFEEDBACK;
+ DIDEVCAPS capabilities;
+ SDL_hapticlist_item *item = NULL;
+
+ if (dinput == NULL) {
+ return -1; /* not initialized. We'll pick these up on enumeration if we init later. */
+ }
+
+ /* Make sure we don't already have it */
+ for (item = SDL_hapticlist; item; item = item->next) {
+ if ((!item->bXInputHaptic) && (SDL_memcmp(&item->instance, pdidInstance, sizeof(*pdidInstance)) == 0)) {
+ return -1; /* Already added */
+ }
+ }
+
+ /* Open the device */
+ ret = IDirectInput8_CreateDevice(dinput, &pdidInstance->guidInstance, &device, NULL);
+ if (FAILED(ret)) {
+ /* DI_SetError("Creating DirectInput device",ret); */
+ return -1;
+ }
+
+ /* Get capabilities. */
+ SDL_zero(capabilities);
+ capabilities.dwSize = sizeof(DIDEVCAPS);
+ ret = IDirectInputDevice8_GetCapabilities(device, &capabilities);
+ IDirectInputDevice8_Release(device);
+ if (FAILED(ret)) {
+ /* DI_SetError("Getting device capabilities",ret); */
+ return -1;
+ }
+
+ if ((capabilities.dwFlags & needflags) != needflags) {
+ return -1; /* not a device we can use. */
+ }
+
+ item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
+ if (item == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ item->name = WIN_StringToUTF8(pdidInstance->tszProductName);
+ if (!item->name) {
+ SDL_free(item);
+ return -1;
+ }
+
+ /* Copy the instance over, useful for creating devices. */
+ SDL_memcpy(&item->instance, pdidInstance, sizeof(DIDEVICEINSTANCE));
+ SDL_memcpy(&item->capabilities, &capabilities, sizeof(capabilities));
+
+ return SDL_SYS_AddHapticDevice(item);
+}
+
+int
+SDL_DINPUT_MaybeRemoveDevice(const DIDEVICEINSTANCE * pdidInstance)
+{
+ SDL_hapticlist_item *item;
+ SDL_hapticlist_item *prev = NULL;
+
+ if (dinput == NULL) {
+ return -1; /* not initialized, ignore this. */
+ }
+
+ for (item = SDL_hapticlist; item != NULL; item = item->next) {
+ if (!item->bXInputHaptic && SDL_memcmp(&item->instance, pdidInstance, sizeof(*pdidInstance)) == 0) {
+ /* found it, remove it. */
+ return SDL_SYS_RemoveHapticDevice(prev, item);
+ }
+ prev = item;
+ }
+ return -1;
+}
+
+/*
+ * Callback to get supported axes.
+ */
+static BOOL CALLBACK
+DI_DeviceObjectCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
+{
+ SDL_Haptic *haptic = (SDL_Haptic *) pvRef;
+
+ if ((dev->dwType & DIDFT_AXIS) && (dev->dwFlags & DIDOI_FFACTUATOR)) {
+ const GUID *guid = &dev->guidType;
+ DWORD offset = 0;
+ if (WIN_IsEqualGUID(guid, &GUID_XAxis)) {
+ offset = DIJOFS_X;
+ } else if (WIN_IsEqualGUID(guid, &GUID_YAxis)) {
+ offset = DIJOFS_Y;
+ } else if (WIN_IsEqualGUID(guid, &GUID_ZAxis)) {
+ offset = DIJOFS_Z;
+ } else if (WIN_IsEqualGUID(guid, &GUID_RxAxis)) {
+ offset = DIJOFS_RX;
+ } else if (WIN_IsEqualGUID(guid, &GUID_RyAxis)) {
+ offset = DIJOFS_RY;
+ } else if (WIN_IsEqualGUID(guid, &GUID_RzAxis)) {
+ offset = DIJOFS_RZ;
+ } else {
+ return DIENUM_CONTINUE; /* can't use this, go on. */
+ }
+
+ haptic->hwdata->axes[haptic->naxes] = offset;
+ haptic->naxes++;
+
+ /* Currently using the artificial limit of 3 axes. */
+ if (haptic->naxes >= 3) {
+ return DIENUM_STOP;
+ }
+ }
+
+ return DIENUM_CONTINUE;
+}
+
+/*
+ * Callback to get all supported effects.
+ */
+#define EFFECT_TEST(e,s) \
+if (WIN_IsEqualGUID(&pei->guid, &(e))) \
+ haptic->supported |= (s)
+static BOOL CALLBACK
+DI_EffectCallback(LPCDIEFFECTINFO pei, LPVOID pv)
+{
+ /* Prepare the haptic device. */
+ SDL_Haptic *haptic = (SDL_Haptic *) pv;
+
+ /* Get supported. */
+ EFFECT_TEST(GUID_Spring, SDL_HAPTIC_SPRING);
+ EFFECT_TEST(GUID_Damper, SDL_HAPTIC_DAMPER);
+ EFFECT_TEST(GUID_Inertia, SDL_HAPTIC_INERTIA);
+ EFFECT_TEST(GUID_Friction, SDL_HAPTIC_FRICTION);
+ EFFECT_TEST(GUID_ConstantForce, SDL_HAPTIC_CONSTANT);
+ EFFECT_TEST(GUID_CustomForce, SDL_HAPTIC_CUSTOM);
+ EFFECT_TEST(GUID_Sine, SDL_HAPTIC_SINE);
+ /* !!! FIXME: put this back when we have more bits in 2.1 */
+ /* EFFECT_TEST(GUID_Square, SDL_HAPTIC_SQUARE); */
+ EFFECT_TEST(GUID_Triangle, SDL_HAPTIC_TRIANGLE);
+ EFFECT_TEST(GUID_SawtoothUp, SDL_HAPTIC_SAWTOOTHUP);
+ EFFECT_TEST(GUID_SawtoothDown, SDL_HAPTIC_SAWTOOTHDOWN);
+ EFFECT_TEST(GUID_RampForce, SDL_HAPTIC_RAMP);
+
+ /* Check for more. */
+ return DIENUM_CONTINUE;
+}
+
+/*
+ * Opens the haptic device.
+ *
+ * Steps:
+ * - Set cooperative level.
+ * - Set data format.
+ * - Acquire exclusiveness.
+ * - Reset actuators.
+ * - Get supported features.
+ */
+static int
+SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device8, SDL_bool is_joystick)
+{
+ HRESULT ret;
+ DIPROPDWORD dipdw;
+
+ /* Allocate the hwdata */
+ haptic->hwdata = (struct haptic_hwdata *)SDL_malloc(sizeof(*haptic->hwdata));
+ if (haptic->hwdata == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
+
+ /* We'll use the device8 from now on. */
+ haptic->hwdata->device = device8;
+ haptic->hwdata->is_joystick = is_joystick;
+
+ /* !!! FIXME: opening a haptic device here first will make an attempt to
+ !!! FIXME: SDL_JoystickOpen() that same device fail later, since we
+ !!! FIXME: have it open in exclusive mode. But this will allow
+ !!! FIXME: SDL_JoystickOpen() followed by SDL_HapticOpenFromJoystick()
+ !!! FIXME: to work, and that's probably the common case. Still,
+ !!! FIXME: ideally, We need to unify the opening code. */
+
+ if (!is_joystick) { /* if is_joystick, we already set this up elsewhere. */
+ /* Grab it exclusively to use force feedback stuff. */
+ ret = IDirectInputDevice8_SetCooperativeLevel(haptic->hwdata->device,
+ SDL_HelperWindow,
+ DISCL_EXCLUSIVE |
+ DISCL_BACKGROUND);
+ if (FAILED(ret)) {
+ DI_SetError("Setting cooperative level to exclusive", ret);
+ goto acquire_err;
+ }
+
+ /* Set data format. */
+ ret = IDirectInputDevice8_SetDataFormat(haptic->hwdata->device,
+ &SDL_c_dfDIJoystick2);
+ if (FAILED(ret)) {
+ DI_SetError("Setting data format", ret);
+ goto acquire_err;
+ }
+
+
+ /* Acquire the device. */
+ ret = IDirectInputDevice8_Acquire(haptic->hwdata->device);
+ if (FAILED(ret)) {
+ DI_SetError("Acquiring DirectInput device", ret);
+ goto acquire_err;
+ }
+ }
+
+ /* Get number of axes. */
+ ret = IDirectInputDevice8_EnumObjects(haptic->hwdata->device,
+ DI_DeviceObjectCallback,
+ haptic, DIDFT_AXIS);
+ if (FAILED(ret)) {
+ DI_SetError("Getting device axes", ret);
+ goto acquire_err;
+ }
+
+ /* Reset all actuators - just in case. */
+ ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
+ DISFFC_RESET);
+ if (FAILED(ret)) {
+ DI_SetError("Resetting device", ret);
+ goto acquire_err;
+ }
+
+ /* Enabling actuators. */
+ ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
+ DISFFC_SETACTUATORSON);
+ if (FAILED(ret)) {
+ DI_SetError("Enabling actuators", ret);
+ goto acquire_err;
+ }
+
+ /* Get supported effects. */
+ ret = IDirectInputDevice8_EnumEffects(haptic->hwdata->device,
+ DI_EffectCallback, haptic,
+ DIEFT_ALL);
+ if (FAILED(ret)) {
+ DI_SetError("Enumerating supported effects", ret);
+ goto acquire_err;
+ }
+ if (haptic->supported == 0) { /* Error since device supports nothing. */
+ SDL_SetError("Haptic: Internal error on finding supported effects.");
+ goto acquire_err;
+ }
+
+ /* Check autogain and autocenter. */
+ dipdw.diph.dwSize = sizeof(DIPROPDWORD);
+ dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
+ dipdw.diph.dwObj = 0;
+ dipdw.diph.dwHow = DIPH_DEVICE;
+ dipdw.dwData = 10000;
+ ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
+ DIPROP_FFGAIN, &dipdw.diph);
+ if (!FAILED(ret)) { /* Gain is supported. */
+ haptic->supported |= SDL_HAPTIC_GAIN;
+ }
+ dipdw.diph.dwObj = 0;
+ dipdw.diph.dwHow = DIPH_DEVICE;
+ dipdw.dwData = DIPROPAUTOCENTER_OFF;
+ ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
+ DIPROP_AUTOCENTER, &dipdw.diph);
+ if (!FAILED(ret)) { /* Autocenter is supported. */
+ haptic->supported |= SDL_HAPTIC_AUTOCENTER;
+ }
+
+ /* Status is always supported. */
+ haptic->supported |= SDL_HAPTIC_STATUS | SDL_HAPTIC_PAUSE;
+
+ /* Check maximum effects. */
+ haptic->neffects = 128; /* This is not actually supported as thus under windows,
+ there is no way to tell the number of EFFECTS that a
+ device can hold, so we'll just use a "random" number
+ instead and put warnings in SDL_haptic.h */
+ haptic->nplaying = 128; /* Even more impossible to get this then neffects. */
+
+ /* Prepare effects memory. */
+ haptic->effects = (struct haptic_effect *)
+ SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
+ if (haptic->effects == NULL) {
+ SDL_OutOfMemory();
+ goto acquire_err;
+ }
+ /* Clear the memory */
+ SDL_memset(haptic->effects, 0,
+ sizeof(struct haptic_effect) * haptic->neffects);
+
+ return 0;
+
+ /* Error handling */
+ acquire_err:
+ IDirectInputDevice8_Unacquire(haptic->hwdata->device);
+ return -1;
+}
+
+int
+SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
+{
+ HRESULT ret;
+ LPDIRECTINPUTDEVICE8 device;
+ LPDIRECTINPUTDEVICE8 device8;
+
+ /* Open the device */
+ ret = IDirectInput8_CreateDevice(dinput, &item->instance.guidInstance,
+ &device, NULL);
+ if (FAILED(ret)) {
+ DI_SetError("Creating DirectInput device", ret);
+ return -1;
+ }
+
+ /* Now get the IDirectInputDevice8 interface, instead. */
+ ret = IDirectInputDevice8_QueryInterface(device,
+ &IID_IDirectInputDevice8,
+ (LPVOID *)&device8);
+ /* Done with the temporary one now. */
+ IDirectInputDevice8_Release(device);
+ if (FAILED(ret)) {
+ DI_SetError("Querying DirectInput interface", ret);
+ return -1;
+ }
+
+ if (SDL_DINPUT_HapticOpenFromDevice(haptic, device8, SDL_FALSE) < 0) {
+ IDirectInputDevice8_Release(device8);
+ return -1;
+ }
+ return 0;
+}
+
+int
+SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
+{
+ HRESULT ret;
+ DIDEVICEINSTANCE hap_instance, joy_instance;
+
+ hap_instance.dwSize = sizeof(DIDEVICEINSTANCE);
+ joy_instance.dwSize = sizeof(DIDEVICEINSTANCE);
+
+ /* Get the device instances. */
+ ret = IDirectInputDevice8_GetDeviceInfo(haptic->hwdata->device,
+ &hap_instance);
+ if (FAILED(ret)) {
+ return 0;
+ }
+ ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice,
+ &joy_instance);
+ if (FAILED(ret)) {
+ return 0;
+ }
+
+ return WIN_IsEqualGUID(&hap_instance.guidInstance, &joy_instance.guidInstance);
+}
+
+int
+SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
+{
+ SDL_hapticlist_item *item;
+ int index = 0;
+ HRESULT ret;
+ DIDEVICEINSTANCE joy_instance;
+
+ joy_instance.dwSize = sizeof(DIDEVICEINSTANCE);
+ ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice, &joy_instance);
+ if (FAILED(ret)) {
+ return -1;
+ }
+
+ /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */
+ for (item = SDL_hapticlist; item != NULL; item = item->next) {
+ if (!item->bXInputHaptic && WIN_IsEqualGUID(&item->instance.guidInstance, &joy_instance.guidInstance)) {
+ haptic->index = index;
+ return SDL_DINPUT_HapticOpenFromDevice(haptic, joystick->hwdata->InputDevice, SDL_TRUE);
+ }
+ ++index;
+ }
+
+ SDL_SetError("Couldn't find joystick in haptic device list");
+ return -1;
+}
+
+void
+SDL_DINPUT_HapticClose(SDL_Haptic * haptic)
+{
+ IDirectInputDevice8_Unacquire(haptic->hwdata->device);
+
+ /* Only release if isn't grabbed by a joystick. */
+ if (haptic->hwdata->is_joystick == 0) {
+ IDirectInputDevice8_Release(haptic->hwdata->device);
+ }
+}
+
+void
+SDL_DINPUT_HapticQuit(void)
+{
+ if (dinput != NULL) {
+ IDirectInput8_Release(dinput);
+ dinput = NULL;
+ }
+
+ if (coinitialized) {
+ WIN_CoUninitialize();
+ coinitialized = SDL_FALSE;
+ }
+}
+
+/*
+ * Converts an SDL trigger button to an DIEFFECT trigger button.
+ */
+static DWORD
+DIGetTriggerButton(Uint16 button)
+{
+ DWORD dwTriggerButton;
+
+ dwTriggerButton = DIEB_NOTRIGGER;
+
+ if (button != 0) {
+ dwTriggerButton = DIJOFS_BUTTON(button - 1);
+ }
+
+ return dwTriggerButton;
+}
+
+
+/*
+ * Sets the direction.
+ */
+static int
+SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes)
+{
+ LONG *rglDir;
+
+ /* Handle no axes a part. */
+ if (naxes == 0) {
+ effect->dwFlags |= DIEFF_SPHERICAL; /* Set as default. */
+ effect->rglDirection = NULL;
+ return 0;
+ }
+
+ /* Has axes. */
+ rglDir = SDL_malloc(sizeof(LONG) * naxes);
+ if (rglDir == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(rglDir, 0, sizeof(LONG) * naxes);
+ effect->rglDirection = rglDir;
+
+ switch (dir->type) {
+ case SDL_HAPTIC_POLAR:
+ effect->dwFlags |= DIEFF_POLAR;
+ rglDir[0] = dir->dir[0];
+ return 0;
+ case SDL_HAPTIC_CARTESIAN:
+ effect->dwFlags |= DIEFF_CARTESIAN;
+ rglDir[0] = dir->dir[0];
+ if (naxes > 1)
+ rglDir[1] = dir->dir[1];
+ if (naxes > 2)
+ rglDir[2] = dir->dir[2];
+ return 0;
+ case SDL_HAPTIC_SPHERICAL:
+ effect->dwFlags |= DIEFF_SPHERICAL;
+ rglDir[0] = dir->dir[0];
+ if (naxes > 1)
+ rglDir[1] = dir->dir[1];
+ if (naxes > 2)
+ rglDir[2] = dir->dir[2];
+ return 0;
+
+ default:
+ return SDL_SetError("Haptic: Unknown direction type.");
+ }
+}
+
+/* Clamps and converts. */
+#define CCONVERT(x) (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
+/* Just converts. */
+#define CONVERT(x) (((x)*10000) / 0x7FFF)
+/*
+ * Creates the DIEFFECT from a SDL_HapticEffect.
+ */
+static int
+SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
+ SDL_HapticEffect * src)
+{
+ int i;
+ DICONSTANTFORCE *constant;
+ DIPERIODIC *periodic;
+ DICONDITION *condition; /* Actually an array of conditions - one per axis. */
+ DIRAMPFORCE *ramp;
+ DICUSTOMFORCE *custom;
+ DIENVELOPE *envelope;
+ SDL_HapticConstant *hap_constant;
+ SDL_HapticPeriodic *hap_periodic;
+ SDL_HapticCondition *hap_condition;
+ SDL_HapticRamp *hap_ramp;
+ SDL_HapticCustom *hap_custom;
+ DWORD *axes;
+
+ /* Set global stuff. */
+ SDL_memset(dest, 0, sizeof(DIEFFECT));
+ dest->dwSize = sizeof(DIEFFECT); /* Set the structure size. */
+ dest->dwSamplePeriod = 0; /* Not used by us. */
+ dest->dwGain = 10000; /* Gain is set globally, not locally. */
+ dest->dwFlags = DIEFF_OBJECTOFFSETS; /* Seems obligatory. */
+
+ /* Envelope. */
+ envelope = SDL_malloc(sizeof(DIENVELOPE));
+ if (envelope == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(envelope, 0, sizeof(DIENVELOPE));
+ dest->lpEnvelope = envelope;
+ envelope->dwSize = sizeof(DIENVELOPE); /* Always should be this. */
+
+ /* Axes. */
+ dest->cAxes = haptic->naxes;
+ if (dest->cAxes > 0) {
+ axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
+ if (axes == NULL) {
+ return SDL_OutOfMemory();
+ }
+ axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
+ if (dest->cAxes > 1) {
+ axes[1] = haptic->hwdata->axes[1];
+ }
+ if (dest->cAxes > 2) {
+ axes[2] = haptic->hwdata->axes[2];
+ }
+ dest->rgdwAxes = axes;
+ }
+
+ /* The big type handling switch, even bigger than Linux's version. */
+ switch (src->type) {
+ case SDL_HAPTIC_CONSTANT:
+ hap_constant = &src->constant;
+ constant = SDL_malloc(sizeof(DICONSTANTFORCE));
+ if (constant == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(constant, 0, sizeof(DICONSTANTFORCE));
+
+ /* Specifics */
+ constant->lMagnitude = CONVERT(hap_constant->level);
+ dest->cbTypeSpecificParams = sizeof(DICONSTANTFORCE);
+ dest->lpvTypeSpecificParams = constant;
+
+ /* Generics */
+ dest->dwDuration = hap_constant->length * 1000; /* In microseconds. */
+ dest->dwTriggerButton = DIGetTriggerButton(hap_constant->button);
+ dest->dwTriggerRepeatInterval = hap_constant->interval;
+ dest->dwStartDelay = hap_constant->delay * 1000; /* In microseconds. */
+
+ /* Direction. */
+ if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes) < 0) {
+ return -1;
+ }
+
+ /* Envelope */
+ if ((hap_constant->attack_length == 0)
+ && (hap_constant->fade_length == 0)) {
+ SDL_free(dest->lpEnvelope);
+ dest->lpEnvelope = NULL;
+ } else {
+ envelope->dwAttackLevel = CCONVERT(hap_constant->attack_level);
+ envelope->dwAttackTime = hap_constant->attack_length * 1000;
+ envelope->dwFadeLevel = CCONVERT(hap_constant->fade_level);
+ envelope->dwFadeTime = hap_constant->fade_length * 1000;
+ }
+
+ break;
+
+ case SDL_HAPTIC_SINE:
+ /* !!! FIXME: put this back when we have more bits in 2.1 */
+ /* case SDL_HAPTIC_SQUARE: */
+ case SDL_HAPTIC_TRIANGLE:
+ case SDL_HAPTIC_SAWTOOTHUP:
+ case SDL_HAPTIC_SAWTOOTHDOWN:
+ hap_periodic = &src->periodic;
+ periodic = SDL_malloc(sizeof(DIPERIODIC));
+ if (periodic == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(periodic, 0, sizeof(DIPERIODIC));
+
+ /* Specifics */
+ periodic->dwMagnitude = CONVERT(SDL_abs(hap_periodic->magnitude));
+ periodic->lOffset = CONVERT(hap_periodic->offset);
+ periodic->dwPhase =
+ (hap_periodic->phase + (hap_periodic->magnitude < 0 ? 18000 : 0)) % 36000;
+ periodic->dwPeriod = hap_periodic->period * 1000;
+ dest->cbTypeSpecificParams = sizeof(DIPERIODIC);
+ dest->lpvTypeSpecificParams = periodic;
+
+ /* Generics */
+ dest->dwDuration = hap_periodic->length * 1000; /* In microseconds. */
+ dest->dwTriggerButton = DIGetTriggerButton(hap_periodic->button);
+ dest->dwTriggerRepeatInterval = hap_periodic->interval;
+ dest->dwStartDelay = hap_periodic->delay * 1000; /* In microseconds. */
+
+ /* Direction. */
+ if (SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes)
+ < 0) {
+ return -1;
+ }
+
+ /* Envelope */
+ if ((hap_periodic->attack_length == 0)
+ && (hap_periodic->fade_length == 0)) {
+ SDL_free(dest->lpEnvelope);
+ dest->lpEnvelope = NULL;
+ } else {
+ envelope->dwAttackLevel = CCONVERT(hap_periodic->attack_level);
+ envelope->dwAttackTime = hap_periodic->attack_length * 1000;
+ envelope->dwFadeLevel = CCONVERT(hap_periodic->fade_level);
+ envelope->dwFadeTime = hap_periodic->fade_length * 1000;
+ }
+
+ break;
+
+ case SDL_HAPTIC_SPRING:
+ case SDL_HAPTIC_DAMPER:
+ case SDL_HAPTIC_INERTIA:
+ case SDL_HAPTIC_FRICTION:
+ hap_condition = &src->condition;
+ condition = SDL_malloc(sizeof(DICONDITION) * dest->cAxes);
+ if (condition == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(condition, 0, sizeof(DICONDITION));
+
+ /* Specifics */
+ for (i = 0; i < (int) dest->cAxes; i++) {
+ condition[i].lOffset = CONVERT(hap_condition->center[i]);
+ condition[i].lPositiveCoefficient =
+ CONVERT(hap_condition->right_coeff[i]);
+ condition[i].lNegativeCoefficient =
+ CONVERT(hap_condition->left_coeff[i]);
+ condition[i].dwPositiveSaturation =
+ CCONVERT(hap_condition->right_sat[i] / 2);
+ condition[i].dwNegativeSaturation =
+ CCONVERT(hap_condition->left_sat[i] / 2);
+ condition[i].lDeadBand = CCONVERT(hap_condition->deadband[i] / 2);
+ }
+ dest->cbTypeSpecificParams = sizeof(DICONDITION) * dest->cAxes;
+ dest->lpvTypeSpecificParams = condition;
+
+ /* Generics */
+ dest->dwDuration = hap_condition->length * 1000; /* In microseconds. */
+ dest->dwTriggerButton = DIGetTriggerButton(hap_condition->button);
+ dest->dwTriggerRepeatInterval = hap_condition->interval;
+ dest->dwStartDelay = hap_condition->delay * 1000; /* In microseconds. */
+
+ /* Direction. */
+ if (SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes)
+ < 0) {
+ return -1;
+ }
+
+ /* Envelope - Not actually supported by most CONDITION implementations. */
+ SDL_free(dest->lpEnvelope);
+ dest->lpEnvelope = NULL;
+
+ break;
+
+ case SDL_HAPTIC_RAMP:
+ hap_ramp = &src->ramp;
+ ramp = SDL_malloc(sizeof(DIRAMPFORCE));
+ if (ramp == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(ramp, 0, sizeof(DIRAMPFORCE));
+
+ /* Specifics */
+ ramp->lStart = CONVERT(hap_ramp->start);
+ ramp->lEnd = CONVERT(hap_ramp->end);
+ dest->cbTypeSpecificParams = sizeof(DIRAMPFORCE);
+ dest->lpvTypeSpecificParams = ramp;
+
+ /* Generics */
+ dest->dwDuration = hap_ramp->length * 1000; /* In microseconds. */
+ dest->dwTriggerButton = DIGetTriggerButton(hap_ramp->button);
+ dest->dwTriggerRepeatInterval = hap_ramp->interval;
+ dest->dwStartDelay = hap_ramp->delay * 1000; /* In microseconds. */
+
+ /* Direction. */
+ if (SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes) < 0) {
+ return -1;
+ }
+
+ /* Envelope */
+ if ((hap_ramp->attack_length == 0) && (hap_ramp->fade_length == 0)) {
+ SDL_free(dest->lpEnvelope);
+ dest->lpEnvelope = NULL;
+ } else {
+ envelope->dwAttackLevel = CCONVERT(hap_ramp->attack_level);
+ envelope->dwAttackTime = hap_ramp->attack_length * 1000;
+ envelope->dwFadeLevel = CCONVERT(hap_ramp->fade_level);
+ envelope->dwFadeTime = hap_ramp->fade_length * 1000;
+ }
+
+ break;
+
+ case SDL_HAPTIC_CUSTOM:
+ hap_custom = &src->custom;
+ custom = SDL_malloc(sizeof(DICUSTOMFORCE));
+ if (custom == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(custom, 0, sizeof(DICUSTOMFORCE));
+
+ /* Specifics */
+ custom->cChannels = hap_custom->channels;
+ custom->dwSamplePeriod = hap_custom->period * 1000;
+ custom->cSamples = hap_custom->samples;
+ custom->rglForceData =
+ SDL_malloc(sizeof(LONG) * custom->cSamples * custom->cChannels);
+ for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) { /* Copy data. */
+ custom->rglForceData[i] = CCONVERT(hap_custom->data[i]);
+ }
+ dest->cbTypeSpecificParams = sizeof(DICUSTOMFORCE);
+ dest->lpvTypeSpecificParams = custom;
+
+ /* Generics */
+ dest->dwDuration = hap_custom->length * 1000; /* In microseconds. */
+ dest->dwTriggerButton = DIGetTriggerButton(hap_custom->button);
+ dest->dwTriggerRepeatInterval = hap_custom->interval;
+ dest->dwStartDelay = hap_custom->delay * 1000; /* In microseconds. */
+
+ /* Direction. */
+ if (SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes) < 0) {
+ return -1;
+ }
+
+ /* Envelope */
+ if ((hap_custom->attack_length == 0)
+ && (hap_custom->fade_length == 0)) {
+ SDL_free(dest->lpEnvelope);
+ dest->lpEnvelope = NULL;
+ } else {
+ envelope->dwAttackLevel = CCONVERT(hap_custom->attack_level);
+ envelope->dwAttackTime = hap_custom->attack_length * 1000;
+ envelope->dwFadeLevel = CCONVERT(hap_custom->fade_level);
+ envelope->dwFadeTime = hap_custom->fade_length * 1000;
+ }
+
+ break;
+
+ default:
+ return SDL_SetError("Haptic: Unknown effect type.");
+ }
+
+ return 0;
+}
+
+
+/*
+ * Frees an DIEFFECT allocated by SDL_SYS_ToDIEFFECT.
+ */
+static void
+SDL_SYS_HapticFreeDIEFFECT(DIEFFECT * effect, int type)
+{
+ DICUSTOMFORCE *custom;
+
+ SDL_free(effect->lpEnvelope);
+ effect->lpEnvelope = NULL;
+ SDL_free(effect->rgdwAxes);
+ effect->rgdwAxes = NULL;
+ if (effect->lpvTypeSpecificParams != NULL) {
+ if (type == SDL_HAPTIC_CUSTOM) { /* Must free the custom data. */
+ custom = (DICUSTOMFORCE *) effect->lpvTypeSpecificParams;
+ SDL_free(custom->rglForceData);
+ custom->rglForceData = NULL;
+ }
+ SDL_free(effect->lpvTypeSpecificParams);
+ effect->lpvTypeSpecificParams = NULL;
+ }
+ SDL_free(effect->rglDirection);
+ effect->rglDirection = NULL;
+}
+
+/*
+ * Gets the effect type from the generic SDL haptic effect wrapper.
+ */
+static REFGUID
+SDL_SYS_HapticEffectType(SDL_HapticEffect * effect)
+{
+ switch (effect->type) {
+ case SDL_HAPTIC_CONSTANT:
+ return &GUID_ConstantForce;
+
+ case SDL_HAPTIC_RAMP:
+ return &GUID_RampForce;
+
+ /* !!! FIXME: put this back when we have more bits in 2.1 */
+ /* case SDL_HAPTIC_SQUARE:
+ return &GUID_Square; */
+
+ case SDL_HAPTIC_SINE:
+ return &GUID_Sine;
+
+ case SDL_HAPTIC_TRIANGLE:
+ return &GUID_Triangle;
+
+ case SDL_HAPTIC_SAWTOOTHUP:
+ return &GUID_SawtoothUp;
+
+ case SDL_HAPTIC_SAWTOOTHDOWN:
+ return &GUID_SawtoothDown;
+
+ case SDL_HAPTIC_SPRING:
+ return &GUID_Spring;
+
+ case SDL_HAPTIC_DAMPER:
+ return &GUID_Damper;
+
+ case SDL_HAPTIC_INERTIA:
+ return &GUID_Inertia;
+
+ case SDL_HAPTIC_FRICTION:
+ return &GUID_Friction;
+
+ case SDL_HAPTIC_CUSTOM:
+ return &GUID_CustomForce;
+
+ default:
+ return NULL;
+ }
+}
+int
+SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base)
+{
+ HRESULT ret;
+ REFGUID type = SDL_SYS_HapticEffectType(base);
+
+ if (type == NULL) {
+ SDL_SetError("Haptic: Unknown effect type.");
+ return -1;
+ }
+
+ /* Get the effect. */
+ if (SDL_SYS_ToDIEFFECT(haptic, &effect->hweffect->effect, base) < 0) {
+ goto err_effectdone;
+ }
+
+ /* Create the actual effect. */
+ ret = IDirectInputDevice8_CreateEffect(haptic->hwdata->device, type,
+ &effect->hweffect->effect,
+ &effect->hweffect->ref, NULL);
+ if (FAILED(ret)) {
+ DI_SetError("Unable to create effect", ret);
+ goto err_effectdone;
+ }
+
+ return 0;
+
+err_effectdone:
+ SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, base->type);
+ return -1;
+}
+
+int
+SDL_DINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data)
+{
+ HRESULT ret;
+ DWORD flags;
+ DIEFFECT temp;
+
+ /* Get the effect. */
+ SDL_memset(&temp, 0, sizeof(DIEFFECT));
+ if (SDL_SYS_ToDIEFFECT(haptic, &temp, data) < 0) {
+ goto err_update;
+ }
+
+ /* Set the flags. Might be worthwhile to diff temp with loaded effect and
+ * only change those parameters. */
+ flags = DIEP_DIRECTION |
+ DIEP_DURATION |
+ DIEP_ENVELOPE |
+ DIEP_STARTDELAY |
+ DIEP_TRIGGERBUTTON |
+ DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS;
+
+ /* Create the actual effect. */
+ ret =
+ IDirectInputEffect_SetParameters(effect->hweffect->ref, &temp, flags);
+ if (ret == DIERR_NOTEXCLUSIVEACQUIRED) {
+ IDirectInputDevice8_Unacquire(haptic->hwdata->device);
+ ret = IDirectInputDevice8_SetCooperativeLevel(haptic->hwdata->device, SDL_HelperWindow, DISCL_EXCLUSIVE | DISCL_BACKGROUND);
+ if (SUCCEEDED(ret)) {
+ ret = DIERR_NOTACQUIRED;
+ }
+ }
+ if (ret == DIERR_INPUTLOST || ret == DIERR_NOTACQUIRED) {
+ ret = IDirectInputDevice8_Acquire(haptic->hwdata->device);
+ if (SUCCEEDED(ret)) {
+ ret = IDirectInputEffect_SetParameters(effect->hweffect->ref, &temp, flags);
+ }
+ }
+ if (FAILED(ret)) {
+ DI_SetError("Unable to update effect", ret);
+ goto err_update;
+ }
+
+ /* Copy it over. */
+ SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, data->type);
+ SDL_memcpy(&effect->hweffect->effect, &temp, sizeof(DIEFFECT));
+
+ return 0;
+
+err_update:
+ SDL_SYS_HapticFreeDIEFFECT(&temp, data->type);
+ return -1;
+}
+
+int
+SDL_DINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations)
+{
+ HRESULT ret;
+ DWORD iter;
+
+ /* Check if it's infinite. */
+ if (iterations == SDL_HAPTIC_INFINITY) {
+ iter = INFINITE;
+ } else {
+ iter = iterations;
+ }
+
+ /* Run the effect. */
+ ret = IDirectInputEffect_Start(effect->hweffect->ref, iter, 0);
+ if (FAILED(ret)) {
+ return DI_SetError("Running the effect", ret);
+ }
+ return 0;
+}
+
+int
+SDL_DINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ HRESULT ret;
+
+ ret = IDirectInputEffect_Stop(effect->hweffect->ref);
+ if (FAILED(ret)) {
+ return DI_SetError("Unable to stop effect", ret);
+ }
+ return 0;
+}
+
+void
+SDL_DINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ HRESULT ret;
+
+ ret = IDirectInputEffect_Unload(effect->hweffect->ref);
+ if (FAILED(ret)) {
+ DI_SetError("Removing effect from the device", ret);
+ }
+ SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, effect->effect.type);
+}
+
+int
+SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ HRESULT ret;
+ DWORD status;
+
+ ret = IDirectInputEffect_GetEffectStatus(effect->hweffect->ref, &status);
+ if (FAILED(ret)) {
+ return DI_SetError("Getting effect status", ret);
+ }
+
+ if (status == 0)
+ return SDL_FALSE;
+ return SDL_TRUE;
+}
+
+int
+SDL_DINPUT_HapticSetGain(SDL_Haptic * haptic, int gain)
+{
+ HRESULT ret;
+ DIPROPDWORD dipdw;
+
+ /* Create the weird structure thingy. */
+ dipdw.diph.dwSize = sizeof(DIPROPDWORD);
+ dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
+ dipdw.diph.dwObj = 0;
+ dipdw.diph.dwHow = DIPH_DEVICE;
+ dipdw.dwData = gain * 100; /* 0 to 10,000 */
+
+ /* Try to set the autocenter. */
+ ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
+ DIPROP_FFGAIN, &dipdw.diph);
+ if (FAILED(ret)) {
+ return DI_SetError("Setting gain", ret);
+ }
+ return 0;
+}
+
+int
+SDL_DINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
+{
+ HRESULT ret;
+ DIPROPDWORD dipdw;
+
+ /* Create the weird structure thingy. */
+ dipdw.diph.dwSize = sizeof(DIPROPDWORD);
+ dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
+ dipdw.diph.dwObj = 0;
+ dipdw.diph.dwHow = DIPH_DEVICE;
+ dipdw.dwData = (autocenter == 0) ? DIPROPAUTOCENTER_OFF :
+ DIPROPAUTOCENTER_ON;
+
+ /* Try to set the autocenter. */
+ ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
+ DIPROP_AUTOCENTER, &dipdw.diph);
+ if (FAILED(ret)) {
+ return DI_SetError("Setting autocenter", ret);
+ }
+ return 0;
+}
+
+int
+SDL_DINPUT_HapticPause(SDL_Haptic * haptic)
+{
+ HRESULT ret;
+
+ /* Pause the device. */
+ ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
+ DISFFC_PAUSE);
+ if (FAILED(ret)) {
+ return DI_SetError("Pausing the device", ret);
+ }
+ return 0;
+}
+
+int
+SDL_DINPUT_HapticUnpause(SDL_Haptic * haptic)
+{
+ HRESULT ret;
+
+ /* Unpause the device. */
+ ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
+ DISFFC_CONTINUE);
+ if (FAILED(ret)) {
+ return DI_SetError("Pausing the device", ret);
+ }
+ return 0;
+}
+
+int
+SDL_DINPUT_HapticStopAll(SDL_Haptic * haptic)
+{
+ HRESULT ret;
+
+ /* Try to stop the effects. */
+ ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
+ DISFFC_STOPALL);
+ if (FAILED(ret)) {
+ return DI_SetError("Stopping the device", ret);
+ }
+ return 0;
+}
+
+#else /* !SDL_HAPTIC_DINPUT */
+
+typedef struct DIDEVICEINSTANCE DIDEVICEINSTANCE;
+typedef struct SDL_hapticlist_item SDL_hapticlist_item;
+
+int
+SDL_DINPUT_HapticInit(void)
+{
+ return 0;
+}
+
+int
+SDL_DINPUT_MaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_DINPUT_MaybeRemoveDevice(const DIDEVICEINSTANCE * pdidInstance)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
+{
+ return SDL_Unsupported();
+}
+
+void
+SDL_DINPUT_HapticClose(SDL_Haptic * haptic)
+{
+}
+
+void
+SDL_DINPUT_HapticQuit(void)
+{
+}
+
+int
+SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_DINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_DINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_DINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ return SDL_Unsupported();
+}
+
+void
+SDL_DINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+}
+
+int
+SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_DINPUT_HapticSetGain(SDL_Haptic * haptic, int gain)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_DINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_DINPUT_HapticPause(SDL_Haptic * haptic)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_DINPUT_HapticUnpause(SDL_Haptic * haptic)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_DINPUT_HapticStopAll(SDL_Haptic * haptic)
+{
+ return SDL_Unsupported();
+}
+
+#endif /* SDL_HAPTIC_DINPUT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/haptic/windows/SDL_dinputhaptic_c.h b/src/3rdparty/SDL2/src/haptic/windows/SDL_dinputhaptic_c.h
new file mode 100644
index 0000000..81c0ad1
--- /dev/null
+++ b/src/3rdparty/SDL2/src/haptic/windows/SDL_dinputhaptic_c.h
@@ -0,0 +1,47 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "SDL_haptic.h"
+#include "SDL_windowshaptic_c.h"
+
+
+extern int SDL_DINPUT_HapticInit(void);
+extern int SDL_DINPUT_MaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance);
+extern int SDL_DINPUT_MaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance);
+extern int SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item);
+extern int SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick);
+extern int SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick);
+extern void SDL_DINPUT_HapticClose(SDL_Haptic * haptic);
+extern void SDL_DINPUT_HapticQuit(void);
+extern int SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base);
+extern int SDL_DINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data);
+extern int SDL_DINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations);
+extern int SDL_DINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect);
+extern void SDL_DINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect);
+extern int SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect);
+extern int SDL_DINPUT_HapticSetGain(SDL_Haptic * haptic, int gain);
+extern int SDL_DINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter);
+extern int SDL_DINPUT_HapticPause(SDL_Haptic * haptic);
+extern int SDL_DINPUT_HapticUnpause(SDL_Haptic * haptic);
+extern int SDL_DINPUT_HapticStopAll(SDL_Haptic * haptic);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/haptic/windows/SDL_windowshaptic.c b/src/3rdparty/SDL2/src/haptic/windows/SDL_windowshaptic.c
new file mode 100644
index 0000000..3d7361d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/haptic/windows/SDL_windowshaptic.c
@@ -0,0 +1,449 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_HAPTIC_DINPUT || SDL_HAPTIC_XINPUT
+
+#include "SDL_assert.h"
+#include "SDL_thread.h"
+#include "SDL_mutex.h"
+#include "SDL_timer.h"
+#include "SDL_hints.h"
+#include "SDL_haptic.h"
+#include "../SDL_syshaptic.h"
+#include "SDL_joystick.h"
+#include "../../joystick/SDL_sysjoystick.h" /* For the real SDL_Joystick */
+#include "../../joystick/windows/SDL_windowsjoystick_c.h" /* For joystick hwdata */
+#include "../../joystick/windows/SDL_xinputjoystick_c.h" /* For xinput rumble */
+
+#include "SDL_windowshaptic_c.h"
+#include "SDL_dinputhaptic_c.h"
+#include "SDL_xinputhaptic_c.h"
+
+
+/*
+ * Internal stuff.
+ */
+SDL_hapticlist_item *SDL_hapticlist = NULL;
+static SDL_hapticlist_item *SDL_hapticlist_tail = NULL;
+static int numhaptics = 0;
+
+
+/*
+ * Initializes the haptic subsystem.
+ */
+int
+SDL_SYS_HapticInit(void)
+{
+ if (SDL_DINPUT_HapticInit() < 0) {
+ return -1;
+ }
+ if (SDL_XINPUT_HapticInit() < 0) {
+ return -1;
+ }
+ return numhaptics;
+}
+
+int
+SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item)
+{
+ if (SDL_hapticlist_tail == NULL) {
+ SDL_hapticlist = SDL_hapticlist_tail = item;
+ } else {
+ SDL_hapticlist_tail->next = item;
+ SDL_hapticlist_tail = item;
+ }
+
+ /* Device has been added. */
+ ++numhaptics;
+
+ return numhaptics;
+}
+
+int
+SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *item)
+{
+ const int retval = item->haptic ? item->haptic->index : -1;
+ if (prev != NULL) {
+ prev->next = item->next;
+ } else {
+ SDL_assert(SDL_hapticlist == item);
+ SDL_hapticlist = item->next;
+ }
+ if (item == SDL_hapticlist_tail) {
+ SDL_hapticlist_tail = prev;
+ }
+ --numhaptics;
+ /* !!! TODO: Send a haptic remove event? */
+ SDL_free(item);
+ return retval;
+}
+
+int
+SDL_SYS_NumHaptics(void)
+{
+ return numhaptics;
+}
+
+static SDL_hapticlist_item *
+HapticByDevIndex(int device_index)
+{
+ SDL_hapticlist_item *item = SDL_hapticlist;
+
+ if ((device_index < 0) || (device_index >= numhaptics)) {
+ return NULL;
+ }
+
+ while (device_index > 0) {
+ SDL_assert(item != NULL);
+ --device_index;
+ item = item->next;
+ }
+ return item;
+}
+
+/*
+ * Return the name of a haptic device, does not need to be opened.
+ */
+const char *
+SDL_SYS_HapticName(int index)
+{
+ SDL_hapticlist_item *item = HapticByDevIndex(index);
+ return item->name;
+}
+
+/*
+ * Opens a haptic device for usage.
+ */
+int
+SDL_SYS_HapticOpen(SDL_Haptic * haptic)
+{
+ SDL_hapticlist_item *item = HapticByDevIndex(haptic->index);
+ if (item->bXInputHaptic) {
+ return SDL_XINPUT_HapticOpen(haptic, item);
+ } else {
+ return SDL_DINPUT_HapticOpen(haptic, item);
+ }
+}
+
+
+/*
+ * Opens a haptic device from first mouse it finds for usage.
+ */
+int
+SDL_SYS_HapticMouse(void)
+{
+#if SDL_HAPTIC_DINPUT
+ SDL_hapticlist_item *item;
+ int index = 0;
+
+ /* Grab the first mouse haptic device we find. */
+ for (item = SDL_hapticlist; item != NULL; item = item->next) {
+ if (item->capabilities.dwDevType == DI8DEVCLASS_POINTER ) {
+ return index;
+ }
+ ++index;
+ }
+#endif /* SDL_HAPTIC_DINPUT */
+ return -1;
+}
+
+
+/*
+ * Checks to see if a joystick has haptic features.
+ */
+int
+SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
+{
+ const struct joystick_hwdata *hwdata = joystick->hwdata;
+#if SDL_HAPTIC_XINPUT
+ if (hwdata->bXInputHaptic) {
+ return 1;
+ }
+#endif
+#if SDL_HAPTIC_DINPUT
+ if (hwdata->Capabilities.dwFlags & DIDC_FORCEFEEDBACK) {
+ return 1;
+ }
+#endif
+ return 0;
+}
+
+/*
+ * Checks to see if the haptic device and joystick are in reality the same.
+ */
+int
+SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
+{
+ if (joystick->hwdata->bXInputHaptic != haptic->hwdata->bXInputHaptic) {
+ return 0; /* one is XInput, one is not; not the same device. */
+ } else if (joystick->hwdata->bXInputHaptic) {
+ return SDL_XINPUT_JoystickSameHaptic(haptic, joystick);
+ } else {
+ return SDL_DINPUT_JoystickSameHaptic(haptic, joystick);
+ }
+}
+
+/*
+ * Opens a SDL_Haptic from a SDL_Joystick.
+ */
+int
+SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
+{
+ if (joystick->hwdata->bXInputDevice) {
+ return SDL_XINPUT_HapticOpenFromJoystick(haptic, joystick);
+ } else {
+ return SDL_DINPUT_HapticOpenFromJoystick(haptic, joystick);
+ }
+}
+
+/*
+ * Closes the haptic device.
+ */
+void
+SDL_SYS_HapticClose(SDL_Haptic * haptic)
+{
+ if (haptic->hwdata) {
+
+ /* Free effects. */
+ SDL_free(haptic->effects);
+ haptic->effects = NULL;
+ haptic->neffects = 0;
+
+ /* Clean up */
+ if (haptic->hwdata->bXInputHaptic) {
+ SDL_XINPUT_HapticClose(haptic);
+ } else {
+ SDL_DINPUT_HapticClose(haptic);
+ }
+
+ /* Free */
+ SDL_free(haptic->hwdata);
+ haptic->hwdata = NULL;
+ }
+}
+
+/*
+ * Clean up after system specific haptic stuff
+ */
+void
+SDL_SYS_HapticQuit(void)
+{
+ SDL_hapticlist_item *item;
+ SDL_hapticlist_item *next = NULL;
+ SDL_Haptic *hapticitem = NULL;
+
+ extern SDL_Haptic *SDL_haptics;
+ for (hapticitem = SDL_haptics; hapticitem; hapticitem = hapticitem->next) {
+ if ((hapticitem->hwdata->bXInputHaptic) && (hapticitem->hwdata->thread)) {
+ /* we _have_ to stop the thread before we free the XInput DLL! */
+ SDL_AtomicSet(&hapticitem->hwdata->stopThread, 1);
+ SDL_WaitThread(hapticitem->hwdata->thread, NULL);
+ hapticitem->hwdata->thread = NULL;
+ }
+ }
+
+ for (item = SDL_hapticlist; item; item = next) {
+ /* Opened and not closed haptics are leaked, this is on purpose.
+ * Close your haptic devices after usage. */
+ /* !!! FIXME: (...is leaking on purpose a good idea?) - No, of course not. */
+ next = item->next;
+ SDL_free(item->name);
+ SDL_free(item);
+ }
+
+ SDL_XINPUT_HapticQuit();
+ SDL_DINPUT_HapticQuit();
+
+ numhaptics = 0;
+ SDL_hapticlist = NULL;
+ SDL_hapticlist_tail = NULL;
+}
+
+/*
+ * Creates a new haptic effect.
+ */
+int
+SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
+ SDL_HapticEffect * base)
+{
+ int result;
+
+ /* Alloc the effect. */
+ effect->hweffect = (struct haptic_hweffect *)
+ SDL_malloc(sizeof(struct haptic_hweffect));
+ if (effect->hweffect == NULL) {
+ SDL_OutOfMemory();
+ return -1;
+ }
+ SDL_zerop(effect->hweffect);
+
+ if (haptic->hwdata->bXInputHaptic) {
+ result = SDL_XINPUT_HapticNewEffect(haptic, effect, base);
+ } else {
+ result = SDL_DINPUT_HapticNewEffect(haptic, effect, base);
+ }
+ if (result < 0) {
+ SDL_free(effect->hweffect);
+ effect->hweffect = NULL;
+ }
+ return result;
+}
+
+/*
+ * Updates an effect.
+ */
+int
+SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
+ struct haptic_effect *effect,
+ SDL_HapticEffect * data)
+{
+ if (haptic->hwdata->bXInputHaptic) {
+ return SDL_XINPUT_HapticUpdateEffect(haptic, effect, data);
+ } else {
+ return SDL_DINPUT_HapticUpdateEffect(haptic, effect, data);
+ }
+}
+
+/*
+ * Runs an effect.
+ */
+int
+SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
+ Uint32 iterations)
+{
+ if (haptic->hwdata->bXInputHaptic) {
+ return SDL_XINPUT_HapticRunEffect(haptic, effect, iterations);
+ } else {
+ return SDL_DINPUT_HapticRunEffect(haptic, effect, iterations);
+ }
+}
+
+/*
+ * Stops an effect.
+ */
+int
+SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ if (haptic->hwdata->bXInputHaptic) {
+ return SDL_XINPUT_HapticStopEffect(haptic, effect);
+ } else {
+ return SDL_DINPUT_HapticStopEffect(haptic, effect);
+ }
+}
+
+/*
+ * Frees the effect.
+ */
+void
+SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ if (haptic->hwdata->bXInputHaptic) {
+ SDL_XINPUT_HapticDestroyEffect(haptic, effect);
+ } else {
+ SDL_DINPUT_HapticDestroyEffect(haptic, effect);
+ }
+ SDL_free(effect->hweffect);
+ effect->hweffect = NULL;
+}
+
+/*
+ * Gets the status of a haptic effect.
+ */
+int
+SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
+ struct haptic_effect *effect)
+{
+ if (haptic->hwdata->bXInputHaptic) {
+ return SDL_XINPUT_HapticGetEffectStatus(haptic, effect);
+ } else {
+ return SDL_DINPUT_HapticGetEffectStatus(haptic, effect);
+ }
+}
+
+/*
+ * Sets the gain.
+ */
+int
+SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
+{
+ if (haptic->hwdata->bXInputHaptic) {
+ return SDL_XINPUT_HapticSetGain(haptic, gain);
+ } else {
+ return SDL_DINPUT_HapticSetGain(haptic, gain);
+ }
+}
+
+/*
+ * Sets the autocentering.
+ */
+int
+SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
+{
+ if (haptic->hwdata->bXInputHaptic) {
+ return SDL_XINPUT_HapticSetAutocenter(haptic, autocenter);
+ } else {
+ return SDL_DINPUT_HapticSetAutocenter(haptic, autocenter);
+ }
+}
+
+/*
+ * Pauses the device.
+ */
+int
+SDL_SYS_HapticPause(SDL_Haptic * haptic)
+{
+ if (haptic->hwdata->bXInputHaptic) {
+ return SDL_XINPUT_HapticPause(haptic);
+ } else {
+ return SDL_DINPUT_HapticPause(haptic);
+ }
+}
+
+/*
+ * Pauses the device.
+ */
+int
+SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
+{
+ if (haptic->hwdata->bXInputHaptic) {
+ return SDL_XINPUT_HapticUnpause(haptic);
+ } else {
+ return SDL_DINPUT_HapticUnpause(haptic);
+ }
+}
+
+/*
+ * Stops all the playing effects on the device.
+ */
+int
+SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
+{
+ if (haptic->hwdata->bXInputHaptic) {
+ return SDL_XINPUT_HapticStopAll(haptic);
+ } else {
+ return SDL_DINPUT_HapticStopAll(haptic);
+ }
+}
+
+#endif /* SDL_HAPTIC_DINPUT || SDL_HAPTIC_XINPUT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/haptic/windows/SDL_windowshaptic_c.h b/src/3rdparty/SDL2/src/haptic/windows/SDL_windowshaptic_c.h
new file mode 100644
index 0000000..256ffbf
--- /dev/null
+++ b/src/3rdparty/SDL2/src/haptic/windows/SDL_windowshaptic_c.h
@@ -0,0 +1,88 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_windowshaptic_c_h_
+#define SDL_windowshaptic_c_h_
+
+#include "SDL_thread.h"
+#include "../SDL_syshaptic.h"
+#include "../../core/windows/SDL_directx.h"
+#include "../../core/windows/SDL_xinput.h"
+
+/*
+ * Haptic system hardware data.
+ */
+struct haptic_hwdata
+{
+#if SDL_HAPTIC_DINPUT
+ LPDIRECTINPUTDEVICE8 device;
+#endif
+ DWORD axes[3]; /* Axes to use. */
+ SDL_bool is_joystick; /* Device is loaded as joystick. */
+ Uint8 bXInputHaptic; /* Supports force feedback via XInput. */
+ Uint8 userid; /* XInput userid index for this joystick */
+ SDL_Thread *thread;
+ SDL_mutex *mutex;
+ Uint32 stopTicks;
+ SDL_atomic_t stopThread;
+};
+
+
+/*
+ * Haptic system effect data.
+ */
+struct haptic_hweffect
+{
+#if SDL_HAPTIC_DINPUT
+ DIEFFECT effect;
+ LPDIRECTINPUTEFFECT ref;
+#endif
+#if SDL_HAPTIC_XINPUT
+ XINPUT_VIBRATION vibration;
+#endif
+};
+
+/*
+* List of available haptic devices.
+*/
+typedef struct SDL_hapticlist_item
+{
+ char *name;
+ SDL_Haptic *haptic;
+#if SDL_HAPTIC_DINPUT
+ DIDEVICEINSTANCE instance;
+ DIDEVCAPS capabilities;
+#endif
+ SDL_bool bXInputHaptic; /* Supports force feedback via XInput. */
+ Uint8 userid; /* XInput userid index for this joystick */
+ struct SDL_hapticlist_item *next;
+} SDL_hapticlist_item;
+
+extern SDL_hapticlist_item *SDL_hapticlist;
+
+extern int SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item);
+extern int SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *item);
+
+#endif /* SDL_windowshaptic_c_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/haptic/windows/SDL_xinputhaptic.c b/src/3rdparty/SDL2/src/haptic/windows/SDL_xinputhaptic.c
new file mode 100644
index 0000000..53e7ad3
--- /dev/null
+++ b/src/3rdparty/SDL2/src/haptic/windows/SDL_xinputhaptic.c
@@ -0,0 +1,487 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "SDL_error.h"
+#include "SDL_haptic.h"
+#include "../SDL_syshaptic.h"
+
+#if SDL_HAPTIC_XINPUT
+
+#include "SDL_assert.h"
+#include "SDL_hints.h"
+#include "SDL_timer.h"
+#include "SDL_windowshaptic_c.h"
+#include "SDL_xinputhaptic_c.h"
+#include "../../core/windows/SDL_xinput.h"
+#include "../../joystick/windows/SDL_windowsjoystick_c.h"
+#include "../../thread/SDL_systhread.h"
+
+/*
+ * Internal stuff.
+ */
+static SDL_bool loaded_xinput = SDL_FALSE;
+
+
+int
+SDL_XINPUT_HapticInit(void)
+{
+ if (SDL_GetHintBoolean(SDL_HINT_XINPUT_ENABLED, SDL_TRUE)) {
+ loaded_xinput = (WIN_LoadXInputDLL() == 0);
+ }
+
+ if (loaded_xinput) {
+ DWORD i;
+ for (i = 0; i < XUSER_MAX_COUNT; i++) {
+ SDL_XINPUT_MaybeAddDevice(i);
+ }
+ }
+ return 0;
+}
+
+int
+SDL_XINPUT_MaybeAddDevice(const DWORD dwUserid)
+{
+ const Uint8 userid = (Uint8)dwUserid;
+ SDL_hapticlist_item *item;
+ XINPUT_VIBRATION state;
+
+ if ((!loaded_xinput) || (dwUserid >= XUSER_MAX_COUNT)) {
+ return -1;
+ }
+
+ /* Make sure we don't already have it */
+ for (item = SDL_hapticlist; item; item = item->next) {
+ if (item->bXInputHaptic && item->userid == userid) {
+ return -1; /* Already added */
+ }
+ }
+
+ SDL_zero(state);
+ if (XINPUTSETSTATE(dwUserid, &state) != ERROR_SUCCESS) {
+ return -1; /* no force feedback on this device. */
+ }
+
+ item = (SDL_hapticlist_item *)SDL_malloc(sizeof(SDL_hapticlist_item));
+ if (item == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ SDL_zerop(item);
+
+ /* !!! FIXME: I'm not bothering to query for a real name right now (can we even?) */
+ {
+ char buf[64];
+ SDL_snprintf(buf, sizeof(buf), "XInput Controller #%u", (unsigned int)(userid + 1));
+ item->name = SDL_strdup(buf);
+ }
+
+ if (!item->name) {
+ SDL_free(item);
+ return -1;
+ }
+
+ /* Copy the instance over, useful for creating devices. */
+ item->bXInputHaptic = SDL_TRUE;
+ item->userid = userid;
+
+ return SDL_SYS_AddHapticDevice(item);
+}
+
+int
+SDL_XINPUT_MaybeRemoveDevice(const DWORD dwUserid)
+{
+ const Uint8 userid = (Uint8)dwUserid;
+ SDL_hapticlist_item *item;
+ SDL_hapticlist_item *prev = NULL;
+
+ if ((!loaded_xinput) || (dwUserid >= XUSER_MAX_COUNT)) {
+ return -1;
+ }
+
+ for (item = SDL_hapticlist; item != NULL; item = item->next) {
+ if (item->bXInputHaptic && item->userid == userid) {
+ /* found it, remove it. */
+ return SDL_SYS_RemoveHapticDevice(prev, item);
+ }
+ prev = item;
+ }
+ return -1;
+}
+
+/* !!! FIXME: this is a hack, remove this later. */
+/* Since XInput doesn't offer a way to vibrate for X time, we hook into
+ * SDL_PumpEvents() to check if it's time to stop vibrating with some
+ * frequency.
+ * In practice, this works for 99% of use cases. But in an ideal world,
+ * we do this in a separate thread so that:
+ * - we aren't bound to when the app chooses to pump the event queue.
+ * - we aren't adding more polling to the event queue
+ * - we can emulate all the haptic effects correctly (start on a delay,
+ * mix multiple effects, etc).
+ *
+ * Mostly, this is here to get rumbling to work, and all the other features
+ * are absent in the XInput path for now. :(
+ */
+static int SDLCALL
+SDL_RunXInputHaptic(void *arg)
+{
+ struct haptic_hwdata *hwdata = (struct haptic_hwdata *) arg;
+
+ while (!SDL_AtomicGet(&hwdata->stopThread)) {
+ SDL_Delay(50);
+ SDL_LockMutex(hwdata->mutex);
+ /* If we're currently running and need to stop... */
+ if (hwdata->stopTicks) {
+ if ((hwdata->stopTicks != SDL_HAPTIC_INFINITY) && SDL_TICKS_PASSED(SDL_GetTicks(), hwdata->stopTicks)) {
+ XINPUT_VIBRATION vibration = { 0, 0 };
+ hwdata->stopTicks = 0;
+ XINPUTSETSTATE(hwdata->userid, &vibration);
+ }
+ }
+ SDL_UnlockMutex(hwdata->mutex);
+ }
+
+ return 0;
+}
+
+static int
+SDL_XINPUT_HapticOpenFromUserIndex(SDL_Haptic *haptic, const Uint8 userid)
+{
+ char threadName[32];
+ XINPUT_VIBRATION vibration = { 0, 0 }; /* stop any current vibration */
+ XINPUTSETSTATE(userid, &vibration);
+
+ haptic->supported = SDL_HAPTIC_LEFTRIGHT;
+
+ haptic->neffects = 1;
+ haptic->nplaying = 1;
+
+ /* Prepare effects memory. */
+ haptic->effects = (struct haptic_effect *)
+ SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
+ if (haptic->effects == NULL) {
+ return SDL_OutOfMemory();
+ }
+ /* Clear the memory */
+ SDL_memset(haptic->effects, 0,
+ sizeof(struct haptic_effect) * haptic->neffects);
+
+ haptic->hwdata = (struct haptic_hwdata *) SDL_malloc(sizeof(*haptic->hwdata));
+ if (haptic->hwdata == NULL) {
+ SDL_free(haptic->effects);
+ haptic->effects = NULL;
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
+
+ haptic->hwdata->bXInputHaptic = 1;
+ haptic->hwdata->userid = userid;
+
+ haptic->hwdata->mutex = SDL_CreateMutex();
+ if (haptic->hwdata->mutex == NULL) {
+ SDL_free(haptic->effects);
+ SDL_free(haptic->hwdata);
+ haptic->effects = NULL;
+ return SDL_SetError("Couldn't create XInput haptic mutex");
+ }
+
+ SDL_snprintf(threadName, sizeof(threadName), "SDLXInputDev%d", (int)userid);
+ haptic->hwdata->thread = SDL_CreateThreadInternal(SDL_RunXInputHaptic, threadName, 64 * 1024, haptic->hwdata);
+
+ if (haptic->hwdata->thread == NULL) {
+ SDL_DestroyMutex(haptic->hwdata->mutex);
+ SDL_free(haptic->effects);
+ SDL_free(haptic->hwdata);
+ haptic->effects = NULL;
+ return SDL_SetError("Couldn't create XInput haptic thread");
+ }
+
+ return 0;
+}
+
+int
+SDL_XINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
+{
+ return SDL_XINPUT_HapticOpenFromUserIndex(haptic, item->userid);
+}
+
+int
+SDL_XINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
+{
+ return (haptic->hwdata->userid == joystick->hwdata->userid);
+}
+
+int
+SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
+{
+ SDL_hapticlist_item *item;
+ int index = 0;
+
+ /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */
+ for (item = SDL_hapticlist; item != NULL; item = item->next) {
+ if (item->bXInputHaptic && item->userid == joystick->hwdata->userid) {
+ haptic->index = index;
+ return SDL_XINPUT_HapticOpenFromUserIndex(haptic, joystick->hwdata->userid);
+ }
+ ++index;
+ }
+
+ SDL_SetError("Couldn't find joystick in haptic device list");
+ return -1;
+}
+
+void
+SDL_XINPUT_HapticClose(SDL_Haptic * haptic)
+{
+ SDL_AtomicSet(&haptic->hwdata->stopThread, 1);
+ SDL_WaitThread(haptic->hwdata->thread, NULL);
+ SDL_DestroyMutex(haptic->hwdata->mutex);
+}
+
+void
+SDL_XINPUT_HapticQuit(void)
+{
+ if (loaded_xinput) {
+ WIN_UnloadXInputDLL();
+ loaded_xinput = SDL_FALSE;
+ }
+}
+
+int
+SDL_XINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base)
+{
+ SDL_assert(base->type == SDL_HAPTIC_LEFTRIGHT); /* should catch this at higher level */
+ return SDL_XINPUT_HapticUpdateEffect(haptic, effect, base);
+}
+
+int
+SDL_XINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data)
+{
+ XINPUT_VIBRATION *vib = &effect->hweffect->vibration;
+ SDL_assert(data->type == SDL_HAPTIC_LEFTRIGHT);
+ /* SDL_HapticEffect has max magnitude of 32767, XInput expects 65535 max, so multiply */
+ vib->wLeftMotorSpeed = data->leftright.large_magnitude * 2;
+ vib->wRightMotorSpeed = data->leftright.small_magnitude * 2;
+ SDL_LockMutex(haptic->hwdata->mutex);
+ if (haptic->hwdata->stopTicks) { /* running right now? Update it. */
+ XINPUTSETSTATE(haptic->hwdata->userid, vib);
+ }
+ SDL_UnlockMutex(haptic->hwdata->mutex);
+ return 0;
+}
+
+int
+SDL_XINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations)
+{
+ XINPUT_VIBRATION *vib = &effect->hweffect->vibration;
+ SDL_assert(effect->effect.type == SDL_HAPTIC_LEFTRIGHT); /* should catch this at higher level */
+ SDL_LockMutex(haptic->hwdata->mutex);
+ if (effect->effect.leftright.length == SDL_HAPTIC_INFINITY || iterations == SDL_HAPTIC_INFINITY) {
+ haptic->hwdata->stopTicks = SDL_HAPTIC_INFINITY;
+ } else if ((!effect->effect.leftright.length) || (!iterations)) {
+ /* do nothing. Effect runs for zero milliseconds. */
+ } else {
+ haptic->hwdata->stopTicks = SDL_GetTicks() + (effect->effect.leftright.length * iterations);
+ if ((haptic->hwdata->stopTicks == SDL_HAPTIC_INFINITY) || (haptic->hwdata->stopTicks == 0)) {
+ haptic->hwdata->stopTicks = 1; /* fix edge cases. */
+ }
+ }
+ SDL_UnlockMutex(haptic->hwdata->mutex);
+ return (XINPUTSETSTATE(haptic->hwdata->userid, vib) == ERROR_SUCCESS) ? 0 : -1;
+}
+
+int
+SDL_XINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ XINPUT_VIBRATION vibration = { 0, 0 };
+ SDL_LockMutex(haptic->hwdata->mutex);
+ haptic->hwdata->stopTicks = 0;
+ SDL_UnlockMutex(haptic->hwdata->mutex);
+ return (XINPUTSETSTATE(haptic->hwdata->userid, &vibration) == ERROR_SUCCESS) ? 0 : -1;
+}
+
+void
+SDL_XINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ SDL_XINPUT_HapticStopEffect(haptic, effect);
+}
+
+int
+SDL_XINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_XINPUT_HapticSetGain(SDL_Haptic * haptic, int gain)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_XINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_XINPUT_HapticPause(SDL_Haptic * haptic)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_XINPUT_HapticUnpause(SDL_Haptic * haptic)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_XINPUT_HapticStopAll(SDL_Haptic * haptic)
+{
+ XINPUT_VIBRATION vibration = { 0, 0 };
+ SDL_LockMutex(haptic->hwdata->mutex);
+ haptic->hwdata->stopTicks = 0;
+ SDL_UnlockMutex(haptic->hwdata->mutex);
+ return (XINPUTSETSTATE(haptic->hwdata->userid, &vibration) == ERROR_SUCCESS) ? 0 : -1;
+}
+
+#else /* !SDL_HAPTIC_XINPUT */
+
+#include "../../core/windows/SDL_windows.h"
+
+typedef struct SDL_hapticlist_item SDL_hapticlist_item;
+
+int
+SDL_XINPUT_HapticInit(void)
+{
+ return 0;
+}
+
+int
+SDL_XINPUT_MaybeAddDevice(const DWORD dwUserid)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_XINPUT_MaybeRemoveDevice(const DWORD dwUserid)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_XINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_XINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
+{
+ return SDL_Unsupported();
+}
+
+void
+SDL_XINPUT_HapticClose(SDL_Haptic * haptic)
+{
+}
+
+void
+SDL_XINPUT_HapticQuit(void)
+{
+}
+
+int
+SDL_XINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_XINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_XINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_XINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ return SDL_Unsupported();
+}
+
+void
+SDL_XINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+}
+
+int
+SDL_XINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_XINPUT_HapticSetGain(SDL_Haptic * haptic, int gain)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_XINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_XINPUT_HapticPause(SDL_Haptic * haptic)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_XINPUT_HapticUnpause(SDL_Haptic * haptic)
+{
+ return SDL_Unsupported();
+}
+
+int
+SDL_XINPUT_HapticStopAll(SDL_Haptic * haptic)
+{
+ return SDL_Unsupported();
+}
+
+#endif /* SDL_HAPTIC_XINPUT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/haptic/windows/SDL_xinputhaptic_c.h b/src/3rdparty/SDL2/src/haptic/windows/SDL_xinputhaptic_c.h
new file mode 100644
index 0000000..eed029e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/haptic/windows/SDL_xinputhaptic_c.h
@@ -0,0 +1,47 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "SDL_haptic.h"
+#include "SDL_windowshaptic_c.h"
+
+
+extern int SDL_XINPUT_HapticInit(void);
+extern int SDL_XINPUT_MaybeAddDevice(const DWORD dwUserid);
+extern int SDL_XINPUT_MaybeRemoveDevice(const DWORD dwUserid);
+extern int SDL_XINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item);
+extern int SDL_XINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick);
+extern int SDL_XINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick);
+extern void SDL_XINPUT_HapticClose(SDL_Haptic * haptic);
+extern void SDL_XINPUT_HapticQuit(void);
+extern int SDL_XINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base);
+extern int SDL_XINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data);
+extern int SDL_XINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations);
+extern int SDL_XINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect);
+extern void SDL_XINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect);
+extern int SDL_XINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect);
+extern int SDL_XINPUT_HapticSetGain(SDL_Haptic * haptic, int gain);
+extern int SDL_XINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter);
+extern int SDL_XINPUT_HapticPause(SDL_Haptic * haptic);
+extern int SDL_XINPUT_HapticUnpause(SDL_Haptic * haptic);
+extern int SDL_XINPUT_HapticStopAll(SDL_Haptic * haptic);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/SDL_gamecontroller.c b/src/3rdparty/SDL2/src/joystick/SDL_gamecontroller.c
new file mode 100644
index 0000000..b0f833a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/SDL_gamecontroller.c
@@ -0,0 +1,1871 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* This is the game controller API for Simple DirectMedia Layer */
+
+#include "SDL_events.h"
+#include "SDL_assert.h"
+#include "SDL_hints.h"
+#include "SDL_sysjoystick.h"
+#include "SDL_joystick_c.h"
+#include "SDL_gamecontrollerdb.h"
+
+#if !SDL_EVENTS_DISABLED
+#include "../events/SDL_events_c.h"
+#endif
+
+#if defined(__ANDROID__)
+#include "SDL_system.h"
+#endif
+
+
+#define SDL_CONTROLLER_PLATFORM_FIELD "platform:"
+
+/* a list of currently opened game controllers */
+static SDL_GameController *SDL_gamecontrollers = NULL;
+
+typedef struct
+{
+ SDL_GameControllerBindType inputType;
+ union
+ {
+ int button;
+
+ struct {
+ int axis;
+ int axis_min;
+ int axis_max;
+ } axis;
+
+ struct {
+ int hat;
+ int hat_mask;
+ } hat;
+
+ } input;
+
+ SDL_GameControllerBindType outputType;
+ union
+ {
+ SDL_GameControllerButton button;
+
+ struct {
+ SDL_GameControllerAxis axis;
+ int axis_min;
+ int axis_max;
+ } axis;
+
+ } output;
+
+} SDL_ExtendedGameControllerBind;
+
+/* our hard coded list of mapping support */
+typedef enum
+{
+ SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT,
+ SDL_CONTROLLER_MAPPING_PRIORITY_API,
+ SDL_CONTROLLER_MAPPING_PRIORITY_USER,
+} SDL_ControllerMappingPriority;
+
+typedef struct _ControllerMapping_t
+{
+ SDL_JoystickGUID guid;
+ char *name;
+ char *mapping;
+ SDL_ControllerMappingPriority priority;
+ struct _ControllerMapping_t *next;
+} ControllerMapping_t;
+
+static SDL_JoystickGUID s_zeroGUID;
+static ControllerMapping_t *s_pSupportedControllers = NULL;
+static ControllerMapping_t *s_pXInputMapping = NULL;
+static ControllerMapping_t *s_pEmscriptenMapping = NULL;
+
+/* The SDL game controller structure */
+struct _SDL_GameController
+{
+ SDL_Joystick *joystick; /* underlying joystick device */
+ int ref_count;
+
+ SDL_JoystickGUID guid;
+ const char *name;
+ int num_bindings;
+ SDL_ExtendedGameControllerBind *bindings;
+ SDL_ExtendedGameControllerBind **last_match_axis;
+ Uint8 *last_hat_mask;
+
+ struct _SDL_GameController *next; /* pointer to next game controller we have allocated */
+};
+
+
+typedef struct
+{
+ int num_entries;
+ int max_entries;
+ Uint32 *entries;
+} SDL_vidpid_list;
+
+static SDL_vidpid_list SDL_allowed_controllers;
+static SDL_vidpid_list SDL_ignored_controllers;
+
+static void
+SDL_LoadVIDPIDListFromHint(const char *hint, SDL_vidpid_list *list)
+{
+ Uint32 entry;
+ char *spot;
+ char *file = NULL;
+
+ list->num_entries = 0;
+
+ if (hint && *hint == '@') {
+ spot = file = (char *)SDL_LoadFile(hint+1, NULL);
+ } else {
+ spot = (char *)hint;
+ }
+
+ if (!spot) {
+ return;
+ }
+
+ while ((spot = SDL_strstr(spot, "0x")) != NULL) {
+ entry = (Uint16)SDL_strtol(spot, &spot, 0);
+ entry <<= 16;
+ spot = SDL_strstr(spot, "0x");
+ if (!spot) {
+ break;
+ }
+ entry |= (Uint16)SDL_strtol(spot, &spot, 0);
+
+ if (list->num_entries == list->max_entries) {
+ int max_entries = list->max_entries + 16;
+ Uint32 *entries = (Uint32 *)SDL_realloc(list->entries, max_entries*sizeof(*list->entries));
+ if (entries == NULL) {
+ /* Out of memory, go with what we have already */
+ break;
+ }
+ list->entries = entries;
+ list->max_entries = max_entries;
+ }
+ list->entries[list->num_entries++] = entry;
+ }
+
+ if (file) {
+ SDL_free(file);
+ }
+}
+
+static void SDLCALL
+SDL_GameControllerIgnoreDevicesChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+{
+ SDL_LoadVIDPIDListFromHint(hint, &SDL_ignored_controllers);
+}
+
+static void SDLCALL
+SDL_GameControllerIgnoreDevicesExceptChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+{
+ SDL_LoadVIDPIDListFromHint(hint, &SDL_allowed_controllers);
+}
+
+static int SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis, Sint16 value);
+static int SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button, Uint8 state);
+
+/*
+ * If there is an existing add event in the queue, it needs to be modified
+ * to have the right value for which, because the number of controllers in
+ * the system is now one less.
+ */
+static void UpdateEventsForDeviceRemoval()
+{
+ int i, num_events;
+ SDL_Event *events;
+
+ num_events = SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED);
+ if (num_events <= 0) {
+ return;
+ }
+
+ events = SDL_stack_alloc(SDL_Event, num_events);
+ if (!events) {
+ return;
+ }
+
+ num_events = SDL_PeepEvents(events, num_events, SDL_GETEVENT, SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEADDED);
+ for (i = 0; i < num_events; ++i) {
+ --events[i].cdevice.which;
+ }
+ SDL_PeepEvents(events, num_events, SDL_ADDEVENT, 0, 0);
+
+ SDL_stack_free(events);
+}
+
+static SDL_bool HasSameOutput(SDL_ExtendedGameControllerBind *a, SDL_ExtendedGameControllerBind *b)
+{
+ if (a->outputType != b->outputType) {
+ return SDL_FALSE;
+ }
+
+ if (a->outputType == SDL_CONTROLLER_BINDTYPE_AXIS) {
+ return (a->output.axis.axis == b->output.axis.axis);
+ } else {
+ return (a->output.button == b->output.button);
+ }
+}
+
+static void ResetOutput(SDL_GameController *gamecontroller, SDL_ExtendedGameControllerBind *bind)
+{
+ if (bind->outputType == SDL_CONTROLLER_BINDTYPE_AXIS) {
+ SDL_PrivateGameControllerAxis(gamecontroller, bind->output.axis.axis, 0);
+ } else {
+ SDL_PrivateGameControllerButton(gamecontroller, bind->output.button, SDL_RELEASED);
+ }
+}
+
+static void HandleJoystickAxis(SDL_GameController *gamecontroller, int axis, int value)
+{
+ int i;
+ SDL_ExtendedGameControllerBind *last_match = gamecontroller->last_match_axis[axis];
+ SDL_ExtendedGameControllerBind *match = NULL;
+
+ for (i = 0; i < gamecontroller->num_bindings; ++i) {
+ SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i];
+ if (binding->inputType == SDL_CONTROLLER_BINDTYPE_AXIS &&
+ axis == binding->input.axis.axis) {
+ if (binding->input.axis.axis_min < binding->input.axis.axis_max) {
+ if (value >= binding->input.axis.axis_min &&
+ value <= binding->input.axis.axis_max) {
+ match = binding;
+ break;
+ }
+ } else {
+ if (value >= binding->input.axis.axis_max &&
+ value <= binding->input.axis.axis_min) {
+ match = binding;
+ break;
+ }
+ }
+ }
+ }
+
+ if (last_match && (!match || !HasSameOutput(last_match, match))) {
+ /* Clear the last input that this axis generated */
+ ResetOutput(gamecontroller, last_match);
+ }
+
+ if (match) {
+ if (match->outputType == SDL_CONTROLLER_BINDTYPE_AXIS) {
+ if (match->input.axis.axis_min != match->output.axis.axis_min || match->input.axis.axis_max != match->output.axis.axis_max) {
+ float normalized_value = (float)(value - match->input.axis.axis_min) / (match->input.axis.axis_max - match->input.axis.axis_min);
+ value = match->output.axis.axis_min + (int)(normalized_value * (match->output.axis.axis_max - match->output.axis.axis_min));
+ }
+ SDL_PrivateGameControllerAxis(gamecontroller, match->output.axis.axis, (Sint16)value);
+ } else {
+ Uint8 state;
+ int threshold = match->input.axis.axis_min + (match->input.axis.axis_max - match->input.axis.axis_min) / 2;
+ if (match->input.axis.axis_max < match->input.axis.axis_min) {
+ state = (value <= threshold) ? SDL_PRESSED : SDL_RELEASED;
+ } else {
+ state = (value >= threshold) ? SDL_PRESSED : SDL_RELEASED;
+ }
+ SDL_PrivateGameControllerButton(gamecontroller, match->output.button, state);
+ }
+ }
+ gamecontroller->last_match_axis[axis] = match;
+}
+
+static void HandleJoystickButton(SDL_GameController *gamecontroller, int button, Uint8 state)
+{
+ int i;
+
+ for (i = 0; i < gamecontroller->num_bindings; ++i) {
+ SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i];
+ if (binding->inputType == SDL_CONTROLLER_BINDTYPE_BUTTON &&
+ button == binding->input.button) {
+ if (binding->outputType == SDL_CONTROLLER_BINDTYPE_AXIS) {
+ int value = state ? binding->output.axis.axis_max : binding->output.axis.axis_min;
+ SDL_PrivateGameControllerAxis(gamecontroller, binding->output.axis.axis, (Sint16)value);
+ } else {
+ SDL_PrivateGameControllerButton(gamecontroller, binding->output.button, state);
+ }
+ break;
+ }
+ }
+}
+
+static void HandleJoystickHat(SDL_GameController *gamecontroller, int hat, Uint8 value)
+{
+ int i;
+ Uint8 last_mask = gamecontroller->last_hat_mask[hat];
+ Uint8 changed_mask = (last_mask ^ value);
+
+ for (i = 0; i < gamecontroller->num_bindings; ++i) {
+ SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i];
+ if (binding->inputType == SDL_CONTROLLER_BINDTYPE_HAT && hat == binding->input.hat.hat) {
+ if ((changed_mask & binding->input.hat.hat_mask) != 0) {
+ if (value & binding->input.hat.hat_mask) {
+ if (binding->outputType == SDL_CONTROLLER_BINDTYPE_AXIS) {
+ SDL_PrivateGameControllerAxis(gamecontroller, binding->output.axis.axis, (Sint16)binding->output.axis.axis_max);
+ } else {
+ SDL_PrivateGameControllerButton(gamecontroller, binding->output.button, SDL_PRESSED);
+ }
+ } else {
+ ResetOutput(gamecontroller, binding);
+ }
+ }
+ }
+ }
+ gamecontroller->last_hat_mask[hat] = value;
+}
+
+/*
+ * Event filter to fire controller events from joystick ones
+ */
+static int SDLCALL SDL_GameControllerEventWatcher(void *userdata, SDL_Event * event)
+{
+ switch(event->type) {
+ case SDL_JOYAXISMOTION:
+ {
+ SDL_GameController *controllerlist = SDL_gamecontrollers;
+ while (controllerlist) {
+ if (controllerlist->joystick->instance_id == event->jaxis.which) {
+ HandleJoystickAxis(controllerlist, event->jaxis.axis, event->jaxis.value);
+ break;
+ }
+ controllerlist = controllerlist->next;
+ }
+ }
+ break;
+ case SDL_JOYBUTTONDOWN:
+ case SDL_JOYBUTTONUP:
+ {
+ SDL_GameController *controllerlist = SDL_gamecontrollers;
+ while (controllerlist) {
+ if (controllerlist->joystick->instance_id == event->jbutton.which) {
+ HandleJoystickButton(controllerlist, event->jbutton.button, event->jbutton.state);
+ break;
+ }
+ controllerlist = controllerlist->next;
+ }
+ }
+ break;
+ case SDL_JOYHATMOTION:
+ {
+ SDL_GameController *controllerlist = SDL_gamecontrollers;
+ while (controllerlist) {
+ if (controllerlist->joystick->instance_id == event->jhat.which) {
+ HandleJoystickHat(controllerlist, event->jhat.hat, event->jhat.value);
+ break;
+ }
+ controllerlist = controllerlist->next;
+ }
+ }
+ break;
+ case SDL_JOYDEVICEADDED:
+ {
+ if (SDL_IsGameController(event->jdevice.which)) {
+ SDL_Event deviceevent;
+ deviceevent.type = SDL_CONTROLLERDEVICEADDED;
+ deviceevent.cdevice.which = event->jdevice.which;
+ SDL_PushEvent(&deviceevent);
+ }
+ }
+ break;
+ case SDL_JOYDEVICEREMOVED:
+ {
+ SDL_GameController *controllerlist = SDL_gamecontrollers;
+ while (controllerlist) {
+ if (controllerlist->joystick->instance_id == event->jdevice.which) {
+ SDL_Event deviceevent;
+
+ deviceevent.type = SDL_CONTROLLERDEVICEREMOVED;
+ deviceevent.cdevice.which = event->jdevice.which;
+ SDL_PushEvent(&deviceevent);
+
+ UpdateEventsForDeviceRemoval();
+ break;
+ }
+ controllerlist = controllerlist->next;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+
+ return 1;
+}
+
+/*
+ * Helper function to scan the mappings database for a controller with the specified GUID
+ */
+static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID *guid)
+{
+ ControllerMapping_t *pSupportedController = s_pSupportedControllers;
+ while (pSupportedController) {
+ if (SDL_memcmp(guid, &pSupportedController->guid, sizeof(*guid)) == 0) {
+ return pSupportedController;
+ }
+ pSupportedController = pSupportedController->next;
+ }
+ return NULL;
+}
+
+static const char* map_StringForControllerAxis[] = {
+ "leftx",
+ "lefty",
+ "rightx",
+ "righty",
+ "lefttrigger",
+ "righttrigger",
+ NULL
+};
+
+/*
+ * convert a string to its enum equivalent
+ */
+SDL_GameControllerAxis SDL_GameControllerGetAxisFromString(const char *pchString)
+{
+ int entry;
+
+ if (pchString && (*pchString == '+' || *pchString == '-')) {
+ ++pchString;
+ }
+
+ if (!pchString || !pchString[0]) {
+ return SDL_CONTROLLER_AXIS_INVALID;
+ }
+
+ for (entry = 0; map_StringForControllerAxis[entry]; ++entry) {
+ if (!SDL_strcasecmp(pchString, map_StringForControllerAxis[entry]))
+ return (SDL_GameControllerAxis) entry;
+ }
+ return SDL_CONTROLLER_AXIS_INVALID;
+}
+
+/*
+ * convert an enum to its string equivalent
+ */
+const char* SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis)
+{
+ if (axis > SDL_CONTROLLER_AXIS_INVALID && axis < SDL_CONTROLLER_AXIS_MAX) {
+ return map_StringForControllerAxis[axis];
+ }
+ return NULL;
+}
+
+static const char* map_StringForControllerButton[] = {
+ "a",
+ "b",
+ "x",
+ "y",
+ "back",
+ "guide",
+ "start",
+ "leftstick",
+ "rightstick",
+ "leftshoulder",
+ "rightshoulder",
+ "dpup",
+ "dpdown",
+ "dpleft",
+ "dpright",
+ NULL
+};
+
+/*
+ * convert a string to its enum equivalent
+ */
+SDL_GameControllerButton SDL_GameControllerGetButtonFromString(const char *pchString)
+{
+ int entry;
+ if (!pchString || !pchString[0])
+ return SDL_CONTROLLER_BUTTON_INVALID;
+
+ for (entry = 0; map_StringForControllerButton[entry]; ++entry) {
+ if (SDL_strcasecmp(pchString, map_StringForControllerButton[entry]) == 0)
+ return (SDL_GameControllerButton) entry;
+ }
+ return SDL_CONTROLLER_BUTTON_INVALID;
+}
+
+/*
+ * convert an enum to its string equivalent
+ */
+const char* SDL_GameControllerGetStringForButton(SDL_GameControllerButton axis)
+{
+ if (axis > SDL_CONTROLLER_BUTTON_INVALID && axis < SDL_CONTROLLER_BUTTON_MAX) {
+ return map_StringForControllerButton[axis];
+ }
+ return NULL;
+}
+
+/*
+ * given a controller button name and a joystick name update our mapping structure with it
+ */
+static void SDL_PrivateGameControllerParseElement(SDL_GameController *gamecontroller, const char *szGameButton, const char *szJoystickButton)
+{
+ SDL_ExtendedGameControllerBind bind;
+ SDL_GameControllerButton button;
+ SDL_GameControllerAxis axis;
+ SDL_bool invert_input = SDL_FALSE;
+ char half_axis_input = 0;
+ char half_axis_output = 0;
+
+ if (*szGameButton == '+' || *szGameButton == '-') {
+ half_axis_output = *szGameButton++;
+ }
+
+ axis = SDL_GameControllerGetAxisFromString(szGameButton);
+ button = SDL_GameControllerGetButtonFromString(szGameButton);
+ if (axis != SDL_CONTROLLER_AXIS_INVALID) {
+ bind.outputType = SDL_CONTROLLER_BINDTYPE_AXIS;
+ bind.output.axis.axis = axis;
+ if (axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT || axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT) {
+ bind.output.axis.axis_min = 0;
+ bind.output.axis.axis_max = SDL_JOYSTICK_AXIS_MAX;
+ } else {
+ if (half_axis_output == '+') {
+ bind.output.axis.axis_min = 0;
+ bind.output.axis.axis_max = SDL_JOYSTICK_AXIS_MAX;
+ } else if (half_axis_output == '-') {
+ bind.output.axis.axis_min = 0;
+ bind.output.axis.axis_max = SDL_JOYSTICK_AXIS_MIN;
+ } else {
+ bind.output.axis.axis_min = SDL_JOYSTICK_AXIS_MIN;
+ bind.output.axis.axis_max = SDL_JOYSTICK_AXIS_MAX;
+ }
+ }
+ } else if (button != SDL_CONTROLLER_BUTTON_INVALID) {
+ bind.outputType = SDL_CONTROLLER_BINDTYPE_BUTTON;
+ bind.output.button = button;
+ } else {
+ SDL_SetError("Unexpected controller element %s", szGameButton);
+ return;
+ }
+
+ if (*szJoystickButton == '+' || *szJoystickButton == '-') {
+ half_axis_input = *szJoystickButton++;
+ }
+ if (szJoystickButton[SDL_strlen(szJoystickButton) - 1] == '~') {
+ invert_input = SDL_TRUE;
+ }
+
+ if (szJoystickButton[0] == 'a' && SDL_isdigit(szJoystickButton[1])) {
+ bind.inputType = SDL_CONTROLLER_BINDTYPE_AXIS;
+ bind.input.axis.axis = SDL_atoi(&szJoystickButton[1]);
+ if (half_axis_input == '+') {
+ bind.input.axis.axis_min = 0;
+ bind.input.axis.axis_max = SDL_JOYSTICK_AXIS_MAX;
+ } else if (half_axis_input == '-') {
+ bind.input.axis.axis_min = 0;
+ bind.input.axis.axis_max = SDL_JOYSTICK_AXIS_MIN;
+ } else {
+ bind.input.axis.axis_min = SDL_JOYSTICK_AXIS_MIN;
+ bind.input.axis.axis_max = SDL_JOYSTICK_AXIS_MAX;
+ }
+ if (invert_input) {
+ int tmp = bind.input.axis.axis_min;
+ bind.input.axis.axis_min = bind.input.axis.axis_max;
+ bind.input.axis.axis_max = tmp;
+ }
+ } else if (szJoystickButton[0] == 'b' && SDL_isdigit(szJoystickButton[1])) {
+ bind.inputType = SDL_CONTROLLER_BINDTYPE_BUTTON;
+ bind.input.button = SDL_atoi(&szJoystickButton[1]);
+ } else if (szJoystickButton[0] == 'h' && SDL_isdigit(szJoystickButton[1]) &&
+ szJoystickButton[2] == '.' && SDL_isdigit(szJoystickButton[3])) {
+ int hat = SDL_atoi(&szJoystickButton[1]);
+ int mask = SDL_atoi(&szJoystickButton[3]);
+ bind.inputType = SDL_CONTROLLER_BINDTYPE_HAT;
+ bind.input.hat.hat = hat;
+ bind.input.hat.hat_mask = mask;
+ } else {
+ SDL_SetError("Unexpected joystick element: %s", szJoystickButton);
+ return;
+ }
+
+ ++gamecontroller->num_bindings;
+ gamecontroller->bindings = (SDL_ExtendedGameControllerBind *)SDL_realloc(gamecontroller->bindings, gamecontroller->num_bindings * sizeof(*gamecontroller->bindings));
+ if (!gamecontroller->bindings) {
+ gamecontroller->num_bindings = 0;
+ SDL_OutOfMemory();
+ return;
+ }
+ gamecontroller->bindings[gamecontroller->num_bindings - 1] = bind;
+}
+
+
+/*
+ * given a controller mapping string update our mapping object
+ */
+static void
+SDL_PrivateGameControllerParseControllerConfigString(SDL_GameController *gamecontroller, const char *pchString)
+{
+ char szGameButton[20];
+ char szJoystickButton[20];
+ SDL_bool bGameButton = SDL_TRUE;
+ int i = 0;
+ const char *pchPos = pchString;
+
+ SDL_zero(szGameButton);
+ SDL_zero(szJoystickButton);
+
+ while (pchPos && *pchPos) {
+ if (*pchPos == ':') {
+ i = 0;
+ bGameButton = SDL_FALSE;
+ } else if (*pchPos == ' ') {
+
+ } else if (*pchPos == ',') {
+ i = 0;
+ bGameButton = SDL_TRUE;
+ SDL_PrivateGameControllerParseElement(gamecontroller, szGameButton, szJoystickButton);
+ SDL_zero(szGameButton);
+ SDL_zero(szJoystickButton);
+
+ } else if (bGameButton) {
+ if (i >= sizeof(szGameButton)) {
+ SDL_SetError("Button name too large: %s", szGameButton);
+ return;
+ }
+ szGameButton[i] = *pchPos;
+ i++;
+ } else {
+ if (i >= sizeof(szJoystickButton)) {
+ SDL_SetError("Joystick button name too large: %s", szJoystickButton);
+ return;
+ }
+ szJoystickButton[i] = *pchPos;
+ i++;
+ }
+ pchPos++;
+ }
+
+ SDL_PrivateGameControllerParseElement(gamecontroller, szGameButton, szJoystickButton);
+
+}
+
+/*
+ * Make a new button mapping struct
+ */
+static void SDL_PrivateLoadButtonMapping(SDL_GameController *gamecontroller, SDL_JoystickGUID guid, const char *pchName, const char *pchMapping)
+{
+ int i;
+
+ gamecontroller->guid = guid;
+ gamecontroller->name = pchName;
+ gamecontroller->num_bindings = 0;
+ SDL_memset(gamecontroller->last_match_axis, 0, gamecontroller->joystick->naxes * sizeof(*gamecontroller->last_match_axis));
+
+ SDL_PrivateGameControllerParseControllerConfigString(gamecontroller, pchMapping);
+
+ /* Set the zero point for triggers */
+ for (i = 0; i < gamecontroller->num_bindings; ++i) {
+ SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i];
+ if (binding->inputType == SDL_CONTROLLER_BINDTYPE_AXIS &&
+ binding->outputType == SDL_CONTROLLER_BINDTYPE_AXIS &&
+ (binding->output.axis.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT ||
+ binding->output.axis.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT)) {
+ if (binding->input.axis.axis < gamecontroller->joystick->naxes) {
+ gamecontroller->joystick->axes[binding->input.axis.axis].value =
+ gamecontroller->joystick->axes[binding->input.axis.axis].zero = (Sint16)binding->input.axis.axis_min;
+ }
+ }
+ }
+}
+
+
+/*
+ * grab the guid string from a mapping string
+ */
+static char *SDL_PrivateGetControllerGUIDFromMappingString(const char *pMapping)
+{
+ const char *pFirstComma = SDL_strchr(pMapping, ',');
+ if (pFirstComma) {
+ char *pchGUID = SDL_malloc(pFirstComma - pMapping + 1);
+ if (!pchGUID) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ SDL_memcpy(pchGUID, pMapping, pFirstComma - pMapping);
+ pchGUID[pFirstComma - pMapping] = '\0';
+
+ /* Convert old style GUIDs to the new style in 2.0.5 */
+#if __WIN32__
+ if (SDL_strlen(pchGUID) == 32 &&
+ SDL_memcmp(&pchGUID[20], "504944564944", 12) == 0) {
+ SDL_memcpy(&pchGUID[20], "000000000000", 12);
+ SDL_memcpy(&pchGUID[16], &pchGUID[4], 4);
+ SDL_memcpy(&pchGUID[8], &pchGUID[0], 4);
+ SDL_memcpy(&pchGUID[0], "03000000", 8);
+ }
+#elif __MACOSX__
+ if (SDL_strlen(pchGUID) == 32 &&
+ SDL_memcmp(&pchGUID[4], "000000000000", 12) == 0 &&
+ SDL_memcmp(&pchGUID[20], "000000000000", 12) == 0) {
+ SDL_memcpy(&pchGUID[20], "000000000000", 12);
+ SDL_memcpy(&pchGUID[8], &pchGUID[0], 4);
+ SDL_memcpy(&pchGUID[0], "03000000", 8);
+ }
+#endif
+ return pchGUID;
+ }
+ return NULL;
+}
+
+
+/*
+ * grab the name string from a mapping string
+ */
+static char *SDL_PrivateGetControllerNameFromMappingString(const char *pMapping)
+{
+ const char *pFirstComma, *pSecondComma;
+ char *pchName;
+
+ pFirstComma = SDL_strchr(pMapping, ',');
+ if (!pFirstComma)
+ return NULL;
+
+ pSecondComma = SDL_strchr(pFirstComma + 1, ',');
+ if (!pSecondComma)
+ return NULL;
+
+ pchName = SDL_malloc(pSecondComma - pFirstComma);
+ if (!pchName) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ SDL_memcpy(pchName, pFirstComma + 1, pSecondComma - pFirstComma);
+ pchName[pSecondComma - pFirstComma - 1] = 0;
+ return pchName;
+}
+
+
+/*
+ * grab the button mapping string from a mapping string
+ */
+static char *SDL_PrivateGetControllerMappingFromMappingString(const char *pMapping)
+{
+ const char *pFirstComma, *pSecondComma;
+
+ pFirstComma = SDL_strchr(pMapping, ',');
+ if (!pFirstComma)
+ return NULL;
+
+ pSecondComma = SDL_strchr(pFirstComma + 1, ',');
+ if (!pSecondComma)
+ return NULL;
+
+ return SDL_strdup(pSecondComma + 1); /* mapping is everything after the 3rd comma */
+}
+
+/*
+ * Helper function to refresh a mapping
+ */
+static void SDL_PrivateGameControllerRefreshMapping(ControllerMapping_t *pControllerMapping)
+{
+ SDL_GameController *gamecontrollerlist = SDL_gamecontrollers;
+ while (gamecontrollerlist) {
+ if (!SDL_memcmp(&gamecontrollerlist->guid, &pControllerMapping->guid, sizeof(pControllerMapping->guid))) {
+ SDL_Event event;
+ event.type = SDL_CONTROLLERDEVICEREMAPPED;
+ event.cdevice.which = gamecontrollerlist->joystick->instance_id;
+ SDL_PushEvent(&event);
+
+ /* Not really threadsafe. Should this lock access within SDL_GameControllerEventWatcher? */
+ SDL_PrivateLoadButtonMapping(gamecontrollerlist, pControllerMapping->guid, pControllerMapping->name, pControllerMapping->mapping);
+ }
+
+ gamecontrollerlist = gamecontrollerlist->next;
+ }
+}
+
+/*
+ * Helper function to add a mapping for a guid
+ */
+static ControllerMapping_t *
+SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, const char *mappingString, SDL_bool *existing, SDL_ControllerMappingPriority priority)
+{
+ char *pchName;
+ char *pchMapping;
+ ControllerMapping_t *pControllerMapping;
+
+ pchName = SDL_PrivateGetControllerNameFromMappingString(mappingString);
+ if (!pchName) {
+ SDL_SetError("Couldn't parse name from %s", mappingString);
+ return NULL;
+ }
+
+ pchMapping = SDL_PrivateGetControllerMappingFromMappingString(mappingString);
+ if (!pchMapping) {
+ SDL_free(pchName);
+ SDL_SetError("Couldn't parse %s", mappingString);
+ return NULL;
+ }
+
+ pControllerMapping = SDL_PrivateGetControllerMappingForGUID(&jGUID);
+ if (pControllerMapping) {
+ /* Only overwrite the mapping if the priority is the same or higher. */
+ if (pControllerMapping->priority <= priority) {
+ /* Update existing mapping */
+ SDL_free(pControllerMapping->name);
+ pControllerMapping->name = pchName;
+ SDL_free(pControllerMapping->mapping);
+ pControllerMapping->mapping = pchMapping;
+ pControllerMapping->priority = priority;
+ /* refresh open controllers */
+ SDL_PrivateGameControllerRefreshMapping(pControllerMapping);
+ } else {
+ SDL_free(pchName);
+ SDL_free(pchMapping);
+ }
+ *existing = SDL_TRUE;
+ } else {
+ pControllerMapping = SDL_malloc(sizeof(*pControllerMapping));
+ if (!pControllerMapping) {
+ SDL_free(pchName);
+ SDL_free(pchMapping);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ pControllerMapping->guid = jGUID;
+ pControllerMapping->name = pchName;
+ pControllerMapping->mapping = pchMapping;
+ pControllerMapping->next = NULL;
+ pControllerMapping->priority = priority;
+
+ if (s_pSupportedControllers) {
+ /* Add the mapping to the end of the list */
+ ControllerMapping_t *pCurrMapping, *pPrevMapping;
+
+ for ( pPrevMapping = s_pSupportedControllers, pCurrMapping = pPrevMapping->next;
+ pCurrMapping;
+ pPrevMapping = pCurrMapping, pCurrMapping = pCurrMapping->next ) {
+ continue;
+ }
+ pPrevMapping->next = pControllerMapping;
+ } else {
+ s_pSupportedControllers = pControllerMapping;
+ }
+ *existing = SDL_FALSE;
+ }
+ return pControllerMapping;
+}
+
+/*
+ * Helper function to determine pre-calculated offset to certain joystick mappings
+ */
+static ControllerMapping_t *SDL_PrivateGetControllerMappingForNameAndGUID(const char *name, SDL_JoystickGUID guid)
+{
+ ControllerMapping_t *mapping;
+
+ mapping = SDL_PrivateGetControllerMappingForGUID(&guid);
+#if defined(SDL_JOYSTICK_EMSCRIPTEN)
+ if (!mapping && s_pEmscriptenMapping) {
+ mapping = s_pEmscriptenMapping;
+ }
+#else
+ (void) s_pEmscriptenMapping; /* pacify ARMCC */
+#endif
+#ifdef __LINUX__
+ if (!mapping && name) {
+ if (SDL_strstr(name, "Xbox 360 Wireless Receiver")) {
+ /* The Linux driver xpad.c maps the wireless dpad to buttons */
+ SDL_bool existing;
+ mapping = SDL_PrivateAddMappingForGUID(guid,
+"none,X360 Wireless Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
+ &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
+ }
+ }
+#endif /* __LINUX__ */
+
+ if (!mapping && name) {
+ if (SDL_strstr(name, "Xbox") || SDL_strstr(name, "X-Box") || SDL_strstr(name, "XBOX")) {
+ mapping = s_pXInputMapping;
+ }
+ }
+ return mapping;
+}
+
+static ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
+{
+ const char *name;
+ SDL_JoystickGUID guid;
+ ControllerMapping_t *mapping;
+
+ SDL_LockJoysticks();
+
+ if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
+ SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
+ SDL_UnlockJoysticks();
+ return (NULL);
+ }
+
+ name = SDL_JoystickNameForIndex(device_index);
+ guid = SDL_JoystickGetDeviceGUID(device_index);
+ mapping = SDL_PrivateGetControllerMappingForNameAndGUID(name, guid);
+#if SDL_JOYSTICK_XINPUT
+ if (!mapping && SDL_SYS_IsXInputGamepad_DeviceIndex(device_index)) {
+ mapping = s_pXInputMapping;
+ }
+#endif
+#if defined(__ANDROID__)
+ if (!mapping && SDL_SYS_IsDPAD_DeviceIndex(device_index)) {
+ SDL_bool existing;
+ char mapping_string[1024];
+ SDL_snprintf(mapping_string, sizeof(mapping_string), "none,%s,a:b0,b:b4,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,", name);
+ mapping = SDL_PrivateAddMappingForGUID(guid, mapping_string,
+ &existing, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
+ }
+#endif /* __ANDROID__ */
+ SDL_UnlockJoysticks();
+ return mapping;
+}
+
+/*
+ * Add or update an entry into the Mappings Database
+ */
+int
+SDL_GameControllerAddMappingsFromRW(SDL_RWops * rw, int freerw)
+{
+ const char *platform = SDL_GetPlatform();
+ int controllers = 0;
+ char *buf, *line, *line_end, *tmp, *comma, line_platform[64];
+ size_t db_size, platform_len;
+
+ if (rw == NULL) {
+ return SDL_SetError("Invalid RWops");
+ }
+ db_size = (size_t)SDL_RWsize(rw);
+
+ buf = (char *)SDL_malloc(db_size + 1);
+ if (buf == NULL) {
+ if (freerw) {
+ SDL_RWclose(rw);
+ }
+ return SDL_SetError("Could not allocate space to read DB into memory");
+ }
+
+ if (SDL_RWread(rw, buf, db_size, 1) != 1) {
+ if (freerw) {
+ SDL_RWclose(rw);
+ }
+ SDL_free(buf);
+ return SDL_SetError("Could not read DB");
+ }
+
+ if (freerw) {
+ SDL_RWclose(rw);
+ }
+
+ buf[db_size] = '\0';
+ line = buf;
+
+ while (line < buf + db_size) {
+ line_end = SDL_strchr(line, '\n');
+ if (line_end != NULL) {
+ *line_end = '\0';
+ } else {
+ line_end = buf + db_size;
+ }
+
+ /* Extract and verify the platform */
+ tmp = SDL_strstr(line, SDL_CONTROLLER_PLATFORM_FIELD);
+ if (tmp != NULL) {
+ tmp += SDL_strlen(SDL_CONTROLLER_PLATFORM_FIELD);
+ comma = SDL_strchr(tmp, ',');
+ if (comma != NULL) {
+ platform_len = comma - tmp + 1;
+ if (platform_len + 1 < SDL_arraysize(line_platform)) {
+ SDL_strlcpy(line_platform, tmp, platform_len);
+ if (SDL_strncasecmp(line_platform, platform, platform_len) == 0 &&
+ SDL_GameControllerAddMapping(line) > 0) {
+ controllers++;
+ }
+ }
+ }
+ }
+
+ line = line_end + 1;
+ }
+
+ SDL_free(buf);
+ return controllers;
+}
+
+/*
+ * Add or update an entry into the Mappings Database with a priority
+ */
+static int
+SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMappingPriority priority)
+{
+ char *pchGUID;
+ SDL_JoystickGUID jGUID;
+ SDL_bool is_xinput_mapping = SDL_FALSE;
+ SDL_bool is_emscripten_mapping = SDL_FALSE;
+ SDL_bool existing = SDL_FALSE;
+ ControllerMapping_t *pControllerMapping;
+
+ if (!mappingString) {
+ return SDL_InvalidParamError("mappingString");
+ }
+
+ pchGUID = SDL_PrivateGetControllerGUIDFromMappingString(mappingString);
+ if (!pchGUID) {
+ return SDL_SetError("Couldn't parse GUID from %s", mappingString);
+ }
+ if (!SDL_strcasecmp(pchGUID, "xinput")) {
+ is_xinput_mapping = SDL_TRUE;
+ }
+ if (!SDL_strcasecmp(pchGUID, "emscripten")) {
+ is_emscripten_mapping = SDL_TRUE;
+ }
+ jGUID = SDL_JoystickGetGUIDFromString(pchGUID);
+ SDL_free(pchGUID);
+
+ pControllerMapping = SDL_PrivateAddMappingForGUID(jGUID, mappingString, &existing, priority);
+ if (!pControllerMapping) {
+ return -1;
+ }
+
+ if (existing) {
+ return 0;
+ } else {
+ if (is_xinput_mapping) {
+ s_pXInputMapping = pControllerMapping;
+ }
+ if (is_emscripten_mapping) {
+ s_pEmscriptenMapping = pControllerMapping;
+ }
+ return 1;
+ }
+}
+
+/*
+ * Add or update an entry into the Mappings Database
+ */
+int
+SDL_GameControllerAddMapping(const char *mappingString)
+{
+ return SDL_PrivateGameControllerAddMapping(mappingString, SDL_CONTROLLER_MAPPING_PRIORITY_API);
+}
+
+/*
+ * Get the number of mappings installed
+ */
+int
+SDL_GameControllerNumMappings(void)
+{
+ int num_mappings = 0;
+ ControllerMapping_t *mapping;
+
+ for (mapping = s_pSupportedControllers; mapping; mapping = mapping->next) {
+ if (SDL_memcmp(&mapping->guid, &s_zeroGUID, sizeof(mapping->guid)) == 0) {
+ continue;
+ }
+ ++num_mappings;
+ }
+ return num_mappings;
+}
+
+/*
+ * Get the mapping at a particular index.
+ */
+char *
+SDL_GameControllerMappingForIndex(int mapping_index)
+{
+ ControllerMapping_t *mapping;
+
+ for (mapping = s_pSupportedControllers; mapping; mapping = mapping->next) {
+ if (SDL_memcmp(&mapping->guid, &s_zeroGUID, sizeof(mapping->guid)) == 0) {
+ continue;
+ }
+ if (mapping_index == 0) {
+ char *pMappingString;
+ char pchGUID[33];
+ size_t needed;
+
+ SDL_JoystickGetGUIDString(mapping->guid, pchGUID, sizeof(pchGUID));
+ /* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
+ needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
+ pMappingString = SDL_malloc(needed);
+ if (!pMappingString) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
+ return pMappingString;
+ }
+ --mapping_index;
+ }
+ return NULL;
+}
+
+/*
+ * Get the mapping string for this GUID
+ */
+char *
+SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid)
+{
+ char *pMappingString = NULL;
+ ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(&guid);
+ if (mapping) {
+ char pchGUID[33];
+ size_t needed;
+ SDL_JoystickGetGUIDString(guid, pchGUID, sizeof(pchGUID));
+ /* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
+ needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
+ pMappingString = SDL_malloc(needed);
+ if (!pMappingString) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
+ }
+ return pMappingString;
+}
+
+/*
+ * Get the mapping string for this device
+ */
+char *
+SDL_GameControllerMapping(SDL_GameController * gamecontroller)
+{
+ if (!gamecontroller) {
+ return NULL;
+ }
+
+ return SDL_GameControllerMappingForGUID(gamecontroller->guid);
+}
+
+static void
+SDL_GameControllerLoadHints()
+{
+ const char *hint = SDL_GetHint(SDL_HINT_GAMECONTROLLERCONFIG);
+ if (hint && hint[0]) {
+ size_t nchHints = SDL_strlen(hint);
+ char *pUserMappings = SDL_malloc(nchHints + 1);
+ char *pTempMappings = pUserMappings;
+ SDL_memcpy(pUserMappings, hint, nchHints);
+ pUserMappings[nchHints] = '\0';
+ while (pUserMappings) {
+ char *pchNewLine = NULL;
+
+ pchNewLine = SDL_strchr(pUserMappings, '\n');
+ if (pchNewLine)
+ *pchNewLine = '\0';
+
+ SDL_PrivateGameControllerAddMapping(pUserMappings, SDL_CONTROLLER_MAPPING_PRIORITY_USER);
+
+ if (pchNewLine) {
+ pUserMappings = pchNewLine + 1;
+ } else {
+ pUserMappings = NULL;
+ }
+ }
+ SDL_free(pTempMappings);
+ }
+}
+
+/*
+ * Fill the given buffer with the expected controller mapping filepath.
+ * Usually this will just be CONTROLLER_MAPPING_FILE, but for Android,
+ * we want to get the internal storage path.
+ */
+static SDL_bool SDL_GetControllerMappingFilePath(char *path, size_t size)
+{
+#ifdef CONTROLLER_MAPPING_FILE
+#define STRING(X) SDL_STRINGIFY_ARG(X)
+ return SDL_strlcpy(path, STRING(CONTROLLER_MAPPING_FILE), size) < size;
+#elif defined(__ANDROID__)
+ return SDL_snprintf(path, size, "%s/controller_map.txt", SDL_AndroidGetInternalStoragePath()) < size;
+#else
+ return SDL_FALSE;
+#endif
+}
+
+/*
+ * Initialize the game controller system, mostly load our DB of controller config mappings
+ */
+int
+SDL_GameControllerInitMappings(void)
+{
+ char szControllerMapPath[1024];
+ int i = 0;
+ const char *pMappingString = NULL;
+ pMappingString = s_ControllerMappings[i];
+ while (pMappingString) {
+ SDL_PrivateGameControllerAddMapping(pMappingString, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
+
+ i++;
+ pMappingString = s_ControllerMappings[i];
+ }
+
+ if (SDL_GetControllerMappingFilePath(szControllerMapPath, sizeof(szControllerMapPath))) {
+ SDL_GameControllerAddMappingsFromFile(szControllerMapPath);
+ }
+
+ /* load in any user supplied config */
+ SDL_GameControllerLoadHints();
+
+ SDL_AddHintCallback(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES,
+ SDL_GameControllerIgnoreDevicesChanged, NULL);
+ SDL_AddHintCallback(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT,
+ SDL_GameControllerIgnoreDevicesExceptChanged, NULL);
+
+ return (0);
+}
+
+int
+SDL_GameControllerInit(void)
+{
+ int i;
+
+ /* watch for joy events and fire controller ones if needed */
+ SDL_AddEventWatch(SDL_GameControllerEventWatcher, NULL);
+
+ /* Send added events for controllers currently attached */
+ for (i = 0; i < SDL_NumJoysticks(); ++i) {
+ if (SDL_IsGameController(i)) {
+ SDL_Event deviceevent;
+ deviceevent.type = SDL_CONTROLLERDEVICEADDED;
+ deviceevent.cdevice.which = i;
+ SDL_PushEvent(&deviceevent);
+ }
+ }
+
+ return (0);
+}
+
+
+/*
+ * Get the implementation dependent name of a controller
+ */
+const char *
+SDL_GameControllerNameForIndex(int device_index)
+{
+ ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index);
+ if (pSupportedController) {
+ return pSupportedController->name;
+ }
+ return NULL;
+}
+
+
+/*
+ * Return 1 if the joystick with this name and GUID is a supported controller
+ */
+SDL_bool
+SDL_IsGameControllerNameAndGUID(const char *name, SDL_JoystickGUID guid)
+{
+ ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMappingForNameAndGUID(name, guid);
+ if (pSupportedController) {
+ return SDL_TRUE;
+ }
+ return SDL_FALSE;
+}
+
+/*
+ * Return 1 if the joystick at this device index is a supported controller
+ */
+SDL_bool
+SDL_IsGameController(int device_index)
+{
+ ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMapping(device_index);
+ if (pSupportedController) {
+ return SDL_TRUE;
+ }
+ return SDL_FALSE;
+}
+
+/*
+ * Return 1 if the game controller should be ignored by SDL
+ */
+SDL_bool SDL_ShouldIgnoreGameController(const char *name, SDL_JoystickGUID guid)
+{
+ int i;
+ Uint16 vendor;
+ Uint16 product;
+ Uint32 vidpid;
+
+ if (SDL_allowed_controllers.num_entries == 0 &&
+ SDL_ignored_controllers.num_entries == 0) {
+ return SDL_FALSE;
+ }
+
+ SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL);
+ vidpid = MAKE_VIDPID(vendor, product);
+
+ if (SDL_GetHintBoolean("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD", SDL_FALSE)) {
+ /* We shouldn't ignore Steam's virtual gamepad since it's using the hints to filter out the real controllers so it can remap input for the virtual controller */
+ SDL_bool bSteamVirtualGamepad = SDL_FALSE;
+#if defined(__LINUX__)
+ bSteamVirtualGamepad = (vendor == 0x28DE && product == 0x11FF);
+#elif defined(__MACOSX__)
+ bSteamVirtualGamepad = (SDL_strncmp(name, "GamePad-", 8) == 0);
+#elif defined(__WIN32__)
+ /* We can't tell on Windows, but Steam will block others in input hooks */
+ bSteamVirtualGamepad = SDL_TRUE;
+#endif
+ if (bSteamVirtualGamepad) {
+ return SDL_FALSE;
+ }
+ }
+
+ if (SDL_allowed_controllers.num_entries > 0) {
+ for (i = 0; i < SDL_allowed_controllers.num_entries; ++i) {
+ if (vidpid == SDL_allowed_controllers.entries[i]) {
+ return SDL_FALSE;
+ }
+ }
+ return SDL_TRUE;
+ } else {
+ for (i = 0; i < SDL_ignored_controllers.num_entries; ++i) {
+ if (vidpid == SDL_ignored_controllers.entries[i]) {
+ return SDL_TRUE;
+ }
+ }
+ return SDL_FALSE;
+ }
+}
+
+/*
+ * Open a controller for use - the index passed as an argument refers to
+ * the N'th controller on the system. This index is the value which will
+ * identify this controller in future controller events.
+ *
+ * This function returns a controller identifier, or NULL if an error occurred.
+ */
+SDL_GameController *
+SDL_GameControllerOpen(int device_index)
+{
+ SDL_GameController *gamecontroller;
+ SDL_GameController *gamecontrollerlist;
+ ControllerMapping_t *pSupportedController = NULL;
+
+ SDL_LockJoysticks();
+
+ if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
+ SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
+ SDL_UnlockJoysticks();
+ return (NULL);
+ }
+
+ gamecontrollerlist = SDL_gamecontrollers;
+ /* If the controller is already open, return it */
+ while (gamecontrollerlist) {
+ if (SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == gamecontrollerlist->joystick->instance_id) {
+ gamecontroller = gamecontrollerlist;
+ ++gamecontroller->ref_count;
+ SDL_UnlockJoysticks();
+ return (gamecontroller);
+ }
+ gamecontrollerlist = gamecontrollerlist->next;
+ }
+
+ /* Find a controller mapping */
+ pSupportedController = SDL_PrivateGetControllerMapping(device_index);
+ if (!pSupportedController) {
+ SDL_SetError("Couldn't find mapping for device (%d)", device_index);
+ SDL_UnlockJoysticks();
+ return NULL;
+ }
+
+ /* Create and initialize the controller */
+ gamecontroller = (SDL_GameController *) SDL_calloc(1, sizeof(*gamecontroller));
+ if (gamecontroller == NULL) {
+ SDL_OutOfMemory();
+ SDL_UnlockJoysticks();
+ return NULL;
+ }
+
+ gamecontroller->joystick = SDL_JoystickOpen(device_index);
+ if (!gamecontroller->joystick) {
+ SDL_free(gamecontroller);
+ SDL_UnlockJoysticks();
+ return NULL;
+ }
+
+ if (gamecontroller->joystick->naxes) {
+ gamecontroller->last_match_axis = (SDL_ExtendedGameControllerBind **)SDL_calloc(gamecontroller->joystick->naxes, sizeof(*gamecontroller->last_match_axis));
+ if (!gamecontroller->last_match_axis) {
+ SDL_OutOfMemory();
+ SDL_JoystickClose(gamecontroller->joystick);
+ SDL_free(gamecontroller);
+ SDL_UnlockJoysticks();
+ return NULL;
+ }
+ }
+ if (gamecontroller->joystick->nhats) {
+ gamecontroller->last_hat_mask = (Uint8 *)SDL_calloc(gamecontroller->joystick->nhats, sizeof(*gamecontroller->last_hat_mask));
+ if (!gamecontroller->last_hat_mask) {
+ SDL_OutOfMemory();
+ SDL_JoystickClose(gamecontroller->joystick);
+ SDL_free(gamecontroller->last_match_axis);
+ SDL_free(gamecontroller);
+ SDL_UnlockJoysticks();
+ return NULL;
+ }
+ }
+
+ SDL_PrivateLoadButtonMapping(gamecontroller, pSupportedController->guid, pSupportedController->name, pSupportedController->mapping);
+
+ /* Add the controller to list */
+ ++gamecontroller->ref_count;
+ /* Link the controller in the list */
+ gamecontroller->next = SDL_gamecontrollers;
+ SDL_gamecontrollers = gamecontroller;
+
+ SDL_UnlockJoysticks();
+
+ return (gamecontroller);
+}
+
+/*
+ * Manually pump for controller updates.
+ */
+void
+SDL_GameControllerUpdate(void)
+{
+ /* Just for API completeness; the joystick API does all the work. */
+ SDL_JoystickUpdate();
+}
+
+/*
+ * Get the current state of an axis control on a controller
+ */
+Sint16
+SDL_GameControllerGetAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis)
+{
+ int i;
+
+ if (!gamecontroller)
+ return 0;
+
+ for (i = 0; i < gamecontroller->num_bindings; ++i) {
+ SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i];
+ if (binding->outputType == SDL_CONTROLLER_BINDTYPE_AXIS && binding->output.axis.axis == axis) {
+ int value = 0;
+ SDL_bool valid_input_range;
+ SDL_bool valid_output_range;
+
+ if (binding->inputType == SDL_CONTROLLER_BINDTYPE_AXIS) {
+ value = SDL_JoystickGetAxis(gamecontroller->joystick, binding->input.axis.axis);
+ if (binding->input.axis.axis_min < binding->input.axis.axis_max) {
+ valid_input_range = (value >= binding->input.axis.axis_min && value <= binding->input.axis.axis_max);
+ } else {
+ valid_input_range = (value >= binding->input.axis.axis_max && value <= binding->input.axis.axis_min);
+ }
+ if (valid_input_range) {
+ if (binding->input.axis.axis_min != binding->output.axis.axis_min || binding->input.axis.axis_max != binding->output.axis.axis_max) {
+ float normalized_value = (float)(value - binding->input.axis.axis_min) / (binding->input.axis.axis_max - binding->input.axis.axis_min);
+ value = binding->output.axis.axis_min + (int)(normalized_value * (binding->output.axis.axis_max - binding->output.axis.axis_min));
+ }
+ }
+ } else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_BUTTON) {
+ value = SDL_JoystickGetButton(gamecontroller->joystick, binding->input.button);
+ if (value == SDL_PRESSED) {
+ value = binding->output.axis.axis_max;
+ }
+ } else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_HAT) {
+ int hat_mask = SDL_JoystickGetHat(gamecontroller->joystick, binding->input.hat.hat);
+ if (hat_mask & binding->input.hat.hat_mask) {
+ value = binding->output.axis.axis_max;
+ }
+ }
+
+ if (binding->output.axis.axis_min < binding->output.axis.axis_max) {
+ valid_output_range = (value >= binding->output.axis.axis_min && value <= binding->output.axis.axis_max);
+ } else {
+ valid_output_range = (value >= binding->output.axis.axis_max && value <= binding->output.axis.axis_min);
+ }
+ /* If the value is zero, there might be another binding that makes it non-zero */
+ if (value != 0 && valid_output_range) {
+ return (Sint16)value;
+ }
+ }
+ }
+ return 0;
+}
+
+/*
+ * Get the current state of a button on a controller
+ */
+Uint8
+SDL_GameControllerGetButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button)
+{
+ int i;
+
+ if (!gamecontroller)
+ return 0;
+
+ for (i = 0; i < gamecontroller->num_bindings; ++i) {
+ SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i];
+ if (binding->outputType == SDL_CONTROLLER_BINDTYPE_BUTTON && binding->output.button == button) {
+ if (binding->inputType == SDL_CONTROLLER_BINDTYPE_AXIS) {
+ SDL_bool valid_input_range;
+
+ int value = SDL_JoystickGetAxis(gamecontroller->joystick, binding->input.axis.axis);
+ int threshold = binding->input.axis.axis_min + (binding->input.axis.axis_max - binding->input.axis.axis_min) / 2;
+ if (binding->input.axis.axis_min < binding->input.axis.axis_max) {
+ valid_input_range = (value >= binding->input.axis.axis_min && value <= binding->input.axis.axis_max);
+ if (valid_input_range) {
+ return (value >= threshold) ? SDL_PRESSED : SDL_RELEASED;
+ }
+ } else {
+ valid_input_range = (value >= binding->input.axis.axis_max && value <= binding->input.axis.axis_min);
+ if (valid_input_range) {
+ return (value <= threshold) ? SDL_PRESSED : SDL_RELEASED;
+ }
+ }
+ } else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_BUTTON) {
+ return SDL_JoystickGetButton(gamecontroller->joystick, binding->input.button);
+ } else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_HAT) {
+ int hat_mask = SDL_JoystickGetHat(gamecontroller->joystick, binding->input.hat.hat);
+ return (hat_mask & binding->input.hat.hat_mask) ? SDL_PRESSED : SDL_RELEASED;
+ }
+ }
+ }
+ return SDL_RELEASED;
+}
+
+const char *
+SDL_GameControllerName(SDL_GameController * gamecontroller)
+{
+ if (!gamecontroller)
+ return NULL;
+
+ return gamecontroller->name;
+}
+
+Uint16
+SDL_GameControllerGetVendor(SDL_GameController * gamecontroller)
+{
+ return SDL_JoystickGetVendor(SDL_GameControllerGetJoystick(gamecontroller));
+}
+
+Uint16
+SDL_GameControllerGetProduct(SDL_GameController * gamecontroller)
+{
+ return SDL_JoystickGetProduct(SDL_GameControllerGetJoystick(gamecontroller));
+}
+
+Uint16
+SDL_GameControllerGetProductVersion(SDL_GameController * gamecontroller)
+{
+ return SDL_JoystickGetProductVersion(SDL_GameControllerGetJoystick(gamecontroller));
+}
+
+/*
+ * Return if the controller in question is currently attached to the system,
+ * \return 0 if not plugged in, 1 if still present.
+ */
+SDL_bool
+SDL_GameControllerGetAttached(SDL_GameController * gamecontroller)
+{
+ if (!gamecontroller)
+ return SDL_FALSE;
+
+ return SDL_JoystickGetAttached(gamecontroller->joystick);
+}
+
+/*
+ * Get the joystick for this controller
+ */
+SDL_Joystick *SDL_GameControllerGetJoystick(SDL_GameController * gamecontroller)
+{
+ if (!gamecontroller)
+ return NULL;
+
+ return gamecontroller->joystick;
+}
+
+
+/*
+ * Find the SDL_GameController that owns this instance id
+ */
+SDL_GameController *
+SDL_GameControllerFromInstanceID(SDL_JoystickID joyid)
+{
+ SDL_GameController *gamecontroller;
+
+ SDL_LockJoysticks();
+ gamecontroller = SDL_gamecontrollers;
+ while (gamecontroller) {
+ if (gamecontroller->joystick->instance_id == joyid) {
+ SDL_UnlockJoysticks();
+ return gamecontroller;
+ }
+ gamecontroller = gamecontroller->next;
+ }
+ SDL_UnlockJoysticks();
+ return NULL;
+}
+
+
+/*
+ * Get the SDL joystick layer binding for this controller axis mapping
+ */
+SDL_GameControllerButtonBind SDL_GameControllerGetBindForAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis)
+{
+ int i;
+ SDL_GameControllerButtonBind bind;
+ SDL_zero(bind);
+
+ if (!gamecontroller || axis == SDL_CONTROLLER_AXIS_INVALID)
+ return bind;
+
+ for (i = 0; i < gamecontroller->num_bindings; ++i) {
+ SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i];
+ if (binding->outputType == SDL_CONTROLLER_BINDTYPE_AXIS && binding->output.axis.axis == axis) {
+ bind.bindType = binding->inputType;
+ if (binding->inputType == SDL_CONTROLLER_BINDTYPE_AXIS) {
+ /* FIXME: There might be multiple axes bound now that we have axis ranges... */
+ bind.value.axis = binding->input.axis.axis;
+ } else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_BUTTON) {
+ bind.value.button = binding->input.button;
+ } else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_HAT) {
+ bind.value.hat.hat = binding->input.hat.hat;
+ bind.value.hat.hat_mask = binding->input.hat.hat_mask;
+ }
+ break;
+ }
+ }
+ return bind;
+}
+
+
+/*
+ * Get the SDL joystick layer binding for this controller button mapping
+ */
+SDL_GameControllerButtonBind SDL_GameControllerGetBindForButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button)
+{
+ int i;
+ SDL_GameControllerButtonBind bind;
+ SDL_zero(bind);
+
+ if (!gamecontroller || button == SDL_CONTROLLER_BUTTON_INVALID)
+ return bind;
+
+ for (i = 0; i < gamecontroller->num_bindings; ++i) {
+ SDL_ExtendedGameControllerBind *binding = &gamecontroller->bindings[i];
+ if (binding->outputType == SDL_CONTROLLER_BINDTYPE_BUTTON && binding->output.button == button) {
+ bind.bindType = binding->inputType;
+ if (binding->inputType == SDL_CONTROLLER_BINDTYPE_AXIS) {
+ bind.value.axis = binding->input.axis.axis;
+ } else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_BUTTON) {
+ bind.value.button = binding->input.button;
+ } else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_HAT) {
+ bind.value.hat.hat = binding->input.hat.hat;
+ bind.value.hat.hat_mask = binding->input.hat.hat_mask;
+ }
+ break;
+ }
+ }
+ return bind;
+}
+
+
+void
+SDL_GameControllerClose(SDL_GameController * gamecontroller)
+{
+ SDL_GameController *gamecontrollerlist, *gamecontrollerlistprev;
+
+ if (!gamecontroller)
+ return;
+
+ SDL_LockJoysticks();
+
+ /* First decrement ref count */
+ if (--gamecontroller->ref_count > 0) {
+ SDL_UnlockJoysticks();
+ return;
+ }
+
+ SDL_JoystickClose(gamecontroller->joystick);
+
+ gamecontrollerlist = SDL_gamecontrollers;
+ gamecontrollerlistprev = NULL;
+ while (gamecontrollerlist) {
+ if (gamecontroller == gamecontrollerlist) {
+ if (gamecontrollerlistprev) {
+ /* unlink this entry */
+ gamecontrollerlistprev->next = gamecontrollerlist->next;
+ } else {
+ SDL_gamecontrollers = gamecontroller->next;
+ }
+ break;
+ }
+ gamecontrollerlistprev = gamecontrollerlist;
+ gamecontrollerlist = gamecontrollerlist->next;
+ }
+
+ SDL_free(gamecontroller->bindings);
+ SDL_free(gamecontroller->last_match_axis);
+ SDL_free(gamecontroller->last_hat_mask);
+ SDL_free(gamecontroller);
+
+ SDL_UnlockJoysticks();
+}
+
+
+/*
+ * Quit the controller subsystem
+ */
+void
+SDL_GameControllerQuit(void)
+{
+ SDL_LockJoysticks();
+ while (SDL_gamecontrollers) {
+ SDL_gamecontrollers->ref_count = 1;
+ SDL_GameControllerClose(SDL_gamecontrollers);
+ }
+ SDL_UnlockJoysticks();
+}
+
+void
+SDL_GameControllerQuitMappings(void)
+{
+ ControllerMapping_t *pControllerMap;
+
+ while (s_pSupportedControllers) {
+ pControllerMap = s_pSupportedControllers;
+ s_pSupportedControllers = s_pSupportedControllers->next;
+ SDL_free(pControllerMap->name);
+ SDL_free(pControllerMap->mapping);
+ SDL_free(pControllerMap);
+ }
+
+ SDL_DelEventWatch(SDL_GameControllerEventWatcher, NULL);
+
+ SDL_DelHintCallback(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES,
+ SDL_GameControllerIgnoreDevicesChanged, NULL);
+ SDL_DelHintCallback(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT,
+ SDL_GameControllerIgnoreDevicesExceptChanged, NULL);
+
+ if (SDL_allowed_controllers.entries) {
+ SDL_free(SDL_allowed_controllers.entries);
+ SDL_zero(SDL_allowed_controllers);
+ }
+ if (SDL_ignored_controllers.entries) {
+ SDL_free(SDL_ignored_controllers.entries);
+ SDL_zero(SDL_ignored_controllers);
+ }
+}
+
+/*
+ * Event filter to transform joystick events into appropriate game controller ones
+ */
+static int
+SDL_PrivateGameControllerAxis(SDL_GameController * gamecontroller, SDL_GameControllerAxis axis, Sint16 value)
+{
+ int posted;
+
+ /* translate the event, if desired */
+ posted = 0;
+#if !SDL_EVENTS_DISABLED
+ if (SDL_GetEventState(SDL_CONTROLLERAXISMOTION) == SDL_ENABLE) {
+ SDL_Event event;
+ event.type = SDL_CONTROLLERAXISMOTION;
+ event.caxis.which = gamecontroller->joystick->instance_id;
+ event.caxis.axis = axis;
+ event.caxis.value = value;
+ posted = SDL_PushEvent(&event) == 1;
+ }
+#endif /* !SDL_EVENTS_DISABLED */
+ return (posted);
+}
+
+
+/*
+ * Event filter to transform joystick events into appropriate game controller ones
+ */
+static int
+SDL_PrivateGameControllerButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button, Uint8 state)
+{
+ int posted;
+#if !SDL_EVENTS_DISABLED
+ SDL_Event event;
+
+ if (button == SDL_CONTROLLER_BUTTON_INVALID)
+ return (0);
+
+ switch (state) {
+ case SDL_PRESSED:
+ event.type = SDL_CONTROLLERBUTTONDOWN;
+ break;
+ case SDL_RELEASED:
+ event.type = SDL_CONTROLLERBUTTONUP;
+ break;
+ default:
+ /* Invalid state -- bail */
+ return (0);
+ }
+#endif /* !SDL_EVENTS_DISABLED */
+
+ /* translate the event, if desired */
+ posted = 0;
+#if !SDL_EVENTS_DISABLED
+ if (SDL_GetEventState(event.type) == SDL_ENABLE) {
+ event.cbutton.which = gamecontroller->joystick->instance_id;
+ event.cbutton.button = button;
+ event.cbutton.state = state;
+ posted = SDL_PushEvent(&event) == 1;
+ }
+#endif /* !SDL_EVENTS_DISABLED */
+ return (posted);
+}
+
+/*
+ * Turn off controller events
+ */
+int
+SDL_GameControllerEventState(int state)
+{
+#if SDL_EVENTS_DISABLED
+ return SDL_IGNORE;
+#else
+ const Uint32 event_list[] = {
+ SDL_CONTROLLERAXISMOTION, SDL_CONTROLLERBUTTONDOWN, SDL_CONTROLLERBUTTONUP,
+ SDL_CONTROLLERDEVICEADDED, SDL_CONTROLLERDEVICEREMOVED, SDL_CONTROLLERDEVICEREMAPPED,
+ };
+ unsigned int i;
+
+ switch (state) {
+ case SDL_QUERY:
+ state = SDL_IGNORE;
+ for (i = 0; i < SDL_arraysize(event_list); ++i) {
+ state = SDL_EventState(event_list[i], SDL_QUERY);
+ if (state == SDL_ENABLE) {
+ break;
+ }
+ }
+ break;
+ default:
+ for (i = 0; i < SDL_arraysize(event_list); ++i) {
+ SDL_EventState(event_list[i], state);
+ }
+ break;
+ }
+ return (state);
+#endif /* SDL_EVENTS_DISABLED */
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/SDL_gamecontrollerdb.h b/src/3rdparty/SDL2/src/joystick/SDL_gamecontrollerdb.h
new file mode 100644
index 0000000..fdc0b59
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/SDL_gamecontrollerdb.h
@@ -0,0 +1,232 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+
+/* Default mappings we support
+
+ The easiest way to generate a new mapping is to start Steam in Big Picture
+ mode, configure your joystick and then look in config/config.vdf in your
+ Steam installation directory for the "SDL_GamepadBind" entry.
+
+ Alternatively, you can use the app located in test/controllermap
+ */
+static const char *s_ControllerMappings [] =
+{
+#if SDL_JOYSTICK_XINPUT
+ "xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
+#endif
+#if SDL_JOYSTICK_DINPUT
+ "03000000022000000090000000000000,8Bitdo NES30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a3,righty:a4,start:b11,x:b4,y:b3,",
+ "03000000203800000900000000000000,8Bitdo NES30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a3,righty:a4,start:b11,x:b4,y:b3,",
+ "03000000102800000900000000000000,8Bitdo SFC30 GamePad,a:b1,b:b0,back:b10,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b11,x:b4,y:b3,",
+ "03000000a00500003232000000000000,8Bitdo Zero GamePad,a:b0,b:b1,back:b10,dpdown:+a2,dpleft:-a0,dpright:+a0,dpup:-a2,leftshoulder:b6,rightshoulder:b7,start:b11,x:b3,y:b4,",
+ "03000000341a00003608000000000000,Afterglow PS3 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "03000000e82000006058000000000000,Cideko AK08b,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0,",
+ "03000000260900008888000000000000,Cyber Gadget GameCube Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b6,righttrigger:a4,rightx:a2,righty:a3~,start:b7,x:b2,y:b3,",
+ "03000000a306000022f6000000000000,Cyborg V.3 Rumble Pad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:+a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:-a3,rightx:a2,righty:a4,start:b9,x:b0,y:b3,",
+ "03000000ffff00000000000000000000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
+ "030000000d0f00006e00000000000000,HORIPAD 4 (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "030000000d0f00006600000000000000,HORIPAD 4 (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "030000000d0f00005f00000000000000,Hori Fighting Commander 4 (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "030000000d0f00005e00000000000000,Hori Fighting Commander 4 (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "030000008f0e00001330000000000000,HuiJia SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b6,rightshoulder:b7,start:b9,x:b3,y:b0,",
+ "030000006d04000016c2000000000000,Logitech Dual Action,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "030000006d04000018c2000000000000,Logitech F510 Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "030000006d04000019c2000000000000,Logitech F710 Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* Guide button doesn't seem to be sent in DInput mode. */
+ "03000000380700005032000000000000,Mad Catz FightPad PRO (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "03000000380700005082000000000000,Mad Catz FightPad PRO (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "03000000790000004418000000000000,Mayflash GameCube Controller,a:b1,b:b2,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:a4,rightx:a5,righty:a2,start:b9,x:b0,y:b3,",
+ "030000001008000001e5000000000000,NEXT SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b6,start:b9,x:b3,y:b0,",
+ "030000007e0500000920000000000000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
+ "03000000362800000100000000000000,OUYA Game Controller,a:b0,b:b3,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,guide:b14,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:b13,rightx:a3,righty:a4,x:b1,y:b2,",
+ "03000000888800000803000000000000,PS3 Controller,a:b2,b:b1,back:b8,dpdown:h0.8,dpleft:h0.4,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b9,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:b7,rightx:a3,righty:a4,start:b11,x:b0,y:b3,",
+ "030000004c0500006802000000000000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
+ "03000000250900000500000000000000,PS3 DualShock,a:b2,b:b1,back:b9,dpdown:h0.8,dpleft:h0.4,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b6,leftstick:b10,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b11,righttrigger:b5,rightx:a2,righty:a3,start:b8,x:b0,y:b3,",
+ "030000004c050000c405000000000000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "030000004c050000cc09000000000000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "030000004c050000a00b000000000000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "03000000790000001100000000000000,Retrolink SNES Controller,a:b2,b:b1,back:b8,dpdown:+a4,dpleft:-a3,dpright:+a3,dpup:-a4,leftshoulder:b4,rightshoulder:b5,start:b9,x:b3,y:b0,",
+ "030000006b140000010d000000000000,Revolution Pro Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "03000000a30600000cff000000000000,Saitek P2500 Force Rumble Pad,a:b2,b:b3,back:b11,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:b7,rightx:a2,righty:a3,x:b0,y:b1,",
+ "03000000a30600000b04000000010000,Saitek P990 Dual Analog Pad,a:b1,b:b2,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a3,righty:a2,start:b8,x:b0,y:b3,",
+ "03000000172700004431000000000000,XiaoMi Game Controller,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b20,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a7,rightx:a2,righty:a5,start:b11,x:b3,y:b4,",
+ "03000000830500006020000000000000,iBuffalo SNES Controller,a:b1,b:b0,back:b6,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b5,start:b7,x:b3,y:b2,",
+#endif
+#if defined(__MACOSX__)
+ "03000000022000000090000001000000,8Bitdo NES30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b4,y:b3,",
+ "03000000203800000900000000010000,8Bitdo NES30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b4,y:b3,",
+ "03000000102800000900000000000000,8Bitdo SFC30 GamePad Joystick,a:b1,b:b0,back:b10,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b11,x:b4,y:b3,",
+ "03000000a00500003232000008010000,8Bitdo Zero GamePad,a:b0,b:b1,back:b10,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b6,rightshoulder:b7,start:b11,x:b3,y:b4,",
+ "030000008305000031b0000000000000,Cideko AK08b,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "03000000260900008888000088020000,Cyber Gadget GameCube Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b6,righttrigger:a5,rightx:a2,righty:a3~,start:b7,x:b2,y:b3,",
+ "03000000a306000022f6000001030000,Cyborg V.3 Rumble Pad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:+a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:-a3,rightx:a2,righty:a4,start:b9,x:b0,y:b3,",
+ "0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
+ "030000000d0f00006e00000000010000,HORIPAD 4 (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "030000000d0f00006600000000010000,HORIPAD 4 (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "030000000d0f00005f00000000010000,Hori Fighting Commander 4 (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "030000000d0f00005e00000000010000,Hori Fighting Commander 4 (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "030000008f0e00001330000011010000,HuiJia SNES Controller,a:b4,b:b2,back:b16,dpdown:+a2,dpleft:-a0,dpright:+a0,dpup:-a2,leftshoulder:b12,rightshoulder:b14,start:b18,x:b6,y:b0,",
+ "030000006d04000016c2000014040000,Logitech Dual Action,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "030000006d04000016c2000000030000,Logitech Dual Action,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "030000006d04000016c2000000000000,Logitech F310 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* Guide button doesn't seem to be sent in DInput mode. */
+ "030000006d04000018c2000000000000,Logitech F510 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "030000006d0400001fc2000000000000,Logitech F710 Gamepad (XInput),a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
+ "030000006d04000019c2000000000000,Logitech Wireless Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* This includes F710 in DInput mode and the "Logitech Cordless RumblePad 2", at the very least. */
+ "03000000380700005032000000010000,Mad Catz FightPad PRO (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "03000000380700005082000000010000,Mad Catz FightPad PRO (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "03000000790000004418000000010000,Mayflash GameCube Controller,a:b1,b:b2,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:a4,rightx:a5,righty:a2,start:b9,x:b0,y:b3,",
+ "030000001008000001e5000006010000,NEXT SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b6,start:b9,x:b3,y:b0,",
+ "030000007e0500000920000000000000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
+ "030000004c0500006802000000010000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
+ "030000004c050000c405000000010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "030000004c050000cc09000000010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "030000004c050000a00b000000010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "03000000321500000010000000010000,Razer RAIJU,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "0300000032150000030a000000000000,Razer Wildcat,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
+ "03000000790000001100000006010000,Retrolink SNES Controller,a:b2,b:b1,back:b8,dpdown:+a4,dpleft:-a3,dpright:+a3,dpup:-a4,leftshoulder:b4,rightshoulder:b5,start:b9,x:b3,y:b0,",
+ "030000006b140000010d000000010000,Revolution Pro Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "030000003512000021ab000000000000,SFC30 Joystick,a:b1,b:b0,back:b10,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b11,x:b4,y:b3,",
+ "030000005e0400008e02000001000000,Steam Virtual GamePad,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
+ "03000000110100002014000001000000,SteelSeries Nimbus,a:b0,b:b1,dpdown:b9,dpleft:b11,dpright:b10,dpup:b8,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1~,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3~,x:b2,y:b3,",
+ "03000000381000002014000001000000,SteelSeries Nimbus,a:b0,b:b1,dpdown:b9,dpleft:b11,dpright:b10,dpup:b8,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1~,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3~,x:b2,y:b3,",
+ "03000000110100001714000000000000,SteelSeries Stratus XL,a:b0,b:b1,dpdown:b9,dpleft:b11,dpright:b10,dpup:b8,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1~,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3~,start:b12,x:b2,y:b3,",
+ "03000000110100001714000020010000,SteelSeries Stratus XL,a:b0,b:b1,dpdown:b9,dpleft:b11,dpright:b10,dpup:b8,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1~,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3~,start:b12,x:b2,y:b3,",
+ "030000005e0400008e02000000000000,X360 Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
+ "03000000c6240000045d000000000000,Xbox 360 Wired Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
+ "030000005e040000d102000000000000,Xbox One Wired Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
+ "030000005e040000e302000000000000,Xbox One Wired Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
+ "030000005e040000dd02000000000000,Xbox One Wired Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
+ "030000005e040000e002000003090000,Xbox Wireless Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
+ "030000005e040000ea02000000000000,Xbox Wireless Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
+ "030000005e040000fd02000003090000,Xbox Wireless Controller,a:b0,b:b1,back:b16,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b15,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
+ "03000000172700004431000029010000,XiaoMi Game Controller,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b15,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a6,rightx:a2,righty:a5,start:b11,x:b3,y:b4,",
+ "03000000120c0000100e000000010000,ZEROPLUS P4 Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "03000000830500006020000000010000,iBuffalo SNES Controller,a:b1,b:b0,back:b6,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b5,start:b7,x:b3,y:b2,",
+#endif
+#if defined(__LINUX__)
+ "03000000022000000090000011010000,8Bitdo NES30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b4,y:b3,",
+ "05000000203800000900000000010000,8Bitdo NES30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:b9,rightx:a2,righty:a3,start:b11,x:b4,y:b3,",
+ "05000000102800000900000000010000,8Bitdo SFC30 GamePad,a:b1,b:b0,back:b10,leftshoulder:b6,leftx:a0,lefty:a1,rightshoulder:b7,start:b11,x:b4,y:b3,",
+ "05000000a00500003232000008010000,8Bitdo Zero GamePad,a:b0,b:b1,back:b10,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b6,rightshoulder:b7,start:b11,x:b3,y:b4,",
+ "03000000100000008200000011010000,Akishop Customs PS360+ v1.66,a:b1,b:b2,back:b12,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,start:b9,x:b0,y:b3,",
+ "03000000e82000006058000001010000,Cideko AK08b,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0,",
+ "03000000260900008888000000010000,Cyber Gadget GameCube Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b6,righttrigger:a5,rightx:a2,righty:a3~,start:b7,x:b2,y:b3,",
+ "03000000a306000022f6000011010000,Cyborg V.3 Rumble Pad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:+a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:-a3,rightx:a2,righty:a4,start:b9,x:b0,y:b3,",
+ "03000000790000000600000010010000,DragonRise Inc. Generic USB Joystick,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a3,righty:a4,start:b9,x:b3,y:b0,",
+ "0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
+ "030000006f0e00000104000000010000,Gamestop Logic3 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
+ "030000000d0f00006e00000011010000,HORIPAD 4 (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "030000000d0f00006600000011010000,HORIPAD 4 (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "030000000d0f00005f00000011010000,Hori Fighting Commander 4 (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "030000000d0f00005e00000011010000,Hori Fighting Commander 4 (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "030000008f0e00001330000010010000,HuiJia SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b6,rightshoulder:b7,start:b9,x:b3,y:b0,",
+ "03000000ba2200002010000001010000,Jess Technology USB Game Controller,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b3,y:b0,",
+ "030000006d04000019c2000010010000,Logitech Cordless RumblePad 2,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "030000006d04000016c2000011010000,Logitech Dual Action,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "030000006d04000016c2000010010000,Logitech Dual Action,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "030000006d0400001dc2000014400000,Logitech F310 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
+ "030000006d0400001ec2000020200000,Logitech F510 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
+ "030000006d04000019c2000011010000,Logitech F710 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* Guide button doesn't seem to be sent in DInput mode. */
+ "030000006d0400001fc2000005030000,Logitech F710 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
+ "030000006d04000018c2000010010000,Logitech RumblePad 2,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "03000000380700005032000011010000,Mad Catz FightPad PRO (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "03000000380700005082000011010000,Mad Catz FightPad PRO (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "03000000380700008433000011010000,Mad Catz FightStick TE S+ PS3,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "03000000380700008483000011010000,Mad Catz FightStick TE S+ PS4,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "03000000380700003847000090040000,Mad Catz Wired Xbox 360 Controller (SFIV),a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
+ "03000000380700008034000011010000,Mad Catz fightstick (PS3),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "03000000380700008084000011010000,Mad Catz fightstick (PS4),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "03000000380700001888000010010000,MadCatz PC USB Wired Stick 8818,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "03000000790000004418000010010000,Mayflash GameCube Controller,a:b1,b:b2,dpdown:b14,dpleft:b15,dpright:b13,dpup:b12,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:a4,rightx:a5,righty:a2,start:b9,x:b0,y:b3,",
+ "030000001008000001e5000010010000,NEXT SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b6,start:b9,x:b3,y:b0,",
+ "03000000550900001072000011010000,NVIDIA Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b13,leftshoulder:b4,leftstick:b8,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a4,rightx:a2,righty:a3,start:b7,x:b2,y:b3,",
+ "050000007e0500000920000001000000,Nintendo Switch Pro Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
+ "050000007e0500003003000001000000,Nintendo Wii Remote Pro Controller,a:b0,b:b1,back:b8,dpdown:b14,dpleft:b15,dpright:b16,dpup:b13,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b2,",
+ "030000000d0500000308000010010000,Nostromo n45 Dual Analog Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b12,lefttrigger:b5,leftx:a0,lefty:a1,rightshoulder:b6,rightstick:b11,righttrigger:b7,rightx:a3,righty:a2,start:b10,x:b2,y:b3,",
+ "05000000362800000100000002010000,OUYA Game Controller,a:b0,b:b3,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,guide:b14,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,x:b1,y:b2,",
+ "030000006f0e00006401000001010000,PDP Battlefield One,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
+ "03000000ff1100004133000010010000,PS2 Controller,a:b2,b:b1,back:b8,leftshoulder:b6,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:b5,start:b9,x:b3,y:b0,",
+ "030000004c0500006802000010010000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
+ "050000004c0500006802000000010000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:a12,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:a13,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
+ "030000004c0500006802000011010000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
+ "030000004c0500006802000010810000,PS3 Controller,a:b0,b:b1,back:b8,dpdown:b14,dpleft:b15,dpright:b16,dpup:b13,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b3,y:b2,",
+ "050000004c0500006802000000810000,PS3 Controller,a:b0,b:b1,back:b8,dpdown:b14,dpleft:b15,dpright:b16,dpup:b13,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b3,y:b2,",
+ "030000004c0500006802000011810000,PS3 Controller,a:b0,b:b1,back:b8,dpdown:b14,dpleft:b15,dpright:b16,dpup:b13,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b3,y:b2,",
+ "03000000341a00003608000011010000,PS3 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
+ "030000004c050000c405000011010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "050000004c050000c405000000010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "030000004c050000cc09000011010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "050000004c050000cc09000000010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "030000004c050000a00b000011010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "030000004c050000c405000011810000,PS4 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b3,y:b2,",
+ "050000004c050000c405000000810000,PS4 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b3,y:b2,",
+ "030000004c050000cc09000011810000,PS4 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b3,y:b2,",
+ "050000004c050000cc09000001800000,PS4 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b3,y:b2,",
+ "050000004c050000cc09000000810000,PS4 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b3,y:b2,",
+ "030000004c050000a00b000011810000,PS4 Controller,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b11,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b12,righttrigger:a5,rightx:a3,righty:a4,start:b9,x:b3,y:b2,",
+ "03000000300f00001211000011010000,QanBa Arcade JoyStick,a:b2,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b5,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,righttrigger:b6,start:b9,x:b1,y:b3,",
+ "03000000321500000010000011010000,Razer RAIJU,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "03000000c6240000045d000025010000,Razer Sabertooth,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
+ "03000000321500000009000011010000,Razer Serval,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a4,rightx:a2,righty:a3,start:b7,x:b2,y:b3,",
+ "050000003215000000090000163a0000,Razer Serval,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a4,rightx:a2,righty:a3,start:b7,x:b2,y:b3,",
+ "0300000032150000030a000001010000,Razer Wildcat,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
+ "03000000790000001100000010010000,Retrolink SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b5,start:b9,x:b3,y:b0,",
+ "030000006b140000010d000011010000,Revolution Pro Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "03000000a30600000cff000010010000,Saitek P2500 Force Rumble Pad,a:b2,b:b3,back:b11,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:b7,rightx:a3,righty:a2,x:b0,y:b1,",
+ "03000000a30600000b04000000010000,Saitek P990 Dual Analog Pad,a:b1,b:b2,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a3,righty:a2,start:b8,x:b0,y:b3,",
+ "03000000de2800000211000001000000,Steam Controller,a:b0,b:b1,back:b6,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a3,start:b7,x:b2,y:b3,",
+ "05000000de2800000511000001000000,Steam Controller,a:b0,b:b1,back:b6,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a3,start:b7,x:b2,y:b3,",
+ "03000000de2800000112000001000000,Steam Controller,a:b0,b:b1,back:b6,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a3,start:b7,x:b2,y:b3,",
+ "05000000de2800000212000001000000,Steam Controller,a:b0,b:b1,back:b6,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a3,start:b7,x:b2,y:b3,",
+ "03000000de2800004211000001000000,Steam Controller,a:b0,b:b1,back:b6,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a3,start:b7,x:b2,y:b3,",
+ "03000000de280000fc11000001000000,Steam Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
+ "03000000de280000ff11000001000000,Steam Virtual Gamepad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
+ "xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
+ "050000005e040000e002000003090000,Xbox One Wireless Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
+ "050000005e040000fd02000003090000,Xbox One Wireless Controller,a:b0,b:b1,back:b15,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b16,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,",
+ "05000000172700004431000029010000,XiaoMi Game Controller,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b20,leftshoulder:b6,leftstick:b13,lefttrigger:a7,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a6,rightx:a2,righty:a5,start:b11,x:b3,y:b4,",
+ "03000000120c0000100e000011010000,ZEROPLUS P4 Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
+ "03000000830500006020000010010000,iBuffalo SNES Controller,a:b1,b:b0,back:b6,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b5,start:b7,x:b3,y:b2,",
+#endif
+#if defined(__ANDROID__)
+ "34323662653333636330306631326233,ASUS Gamepad,a:b0,b:b1,back:b4,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b6,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,x:b2,y:b3,",
+ "64633436313965656664373634323364,Microsoft X-Box 360 pad,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,x:b2,y:b3,",
+ "4e564944494120436f72706f72617469,NVIDIA Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
+ "61363931656135336130663561616264,NVIDIA Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
+ "37336435666338653565313731303834,NVIDIA Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
+ "35643031303033326130316330353564,PS4 Controller,a:b1,b:b17,back:b15,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b5,leftshoulder:b3,leftstick:b4,lefttrigger:+a3,leftx:a0,lefty:a1,rightshoulder:b18,rightstick:b6,righttrigger:+a4,rightx:a2,righty:a5,start:b16,x:b0,y:b2,",
+ "05000000de2800000511000001000000,Steam Controller,a:b0,b:b1,back:b6,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a3,start:b7,x:b2,y:b3,",
+ "34356136633366613530316338376136,Xbox Wireless Controller,a:b0,b:b1,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b3,leftstick:b15,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b18,rightstick:b16,righttrigger:a5,rightx:a3,righty:a4,x:b17,y:b2,",
+#endif
+#if defined(SDL_JOYSTICK_MFI)
+ "4d466947616d65706164010000000000,MFi Extended Gamepad,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a5,rightx:a3,righty:a4,start:b6,x:b2,y:b3,",
+ "4d466947616d65706164020000000000,MFi Gamepad,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,rightshoulder:b5,start:b6,x:b2,y:b3,",
+ "4d466947616d65706164030000000000,Remote,a:b0,b:b2,leftx:a0,lefty:a1,",
+ "05000000de2800000511000001000000,Steam Controller,a:b0,b:b1,back:b6,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:a3,start:b7,x:b2,y:b3,",
+#endif
+#if defined(SDL_JOYSTICK_EMSCRIPTEN)
+ "emscripten,Standard Gamepad,a:b0,b:b1,back:b8,dpdown:b13,dpleft:b14,dpright:b15,dpup:b12,guide:b16,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
+#endif
+ NULL
+};
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/SDL_joystick.c b/src/3rdparty/SDL2/src/joystick/SDL_joystick.c
new file mode 100644
index 0000000..b93c03d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/SDL_joystick.c
@@ -0,0 +1,1276 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* This is the joystick API for Simple DirectMedia Layer */
+
+#include "SDL.h"
+#include "SDL_events.h"
+#include "SDL_sysjoystick.h"
+#include "SDL_assert.h"
+#include "SDL_hints.h"
+
+#if !SDL_EVENTS_DISABLED
+#include "../events/SDL_events_c.h"
+#endif
+#include "../video/SDL_sysvideo.h"
+
+
+static SDL_bool SDL_joystick_allows_background_events = SDL_FALSE;
+static SDL_Joystick *SDL_joysticks = NULL;
+static SDL_bool SDL_updating_joystick = SDL_FALSE;
+static SDL_mutex *SDL_joystick_lock = NULL; /* This needs to support recursive locks */
+
+void
+SDL_LockJoysticks(void)
+{
+ if (SDL_joystick_lock) {
+ SDL_LockMutex(SDL_joystick_lock);
+ }
+}
+
+void
+SDL_UnlockJoysticks(void)
+{
+ if (SDL_joystick_lock) {
+ SDL_UnlockMutex(SDL_joystick_lock);
+ }
+}
+
+
+static void SDLCALL
+SDL_JoystickAllowBackgroundEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+{
+ if (hint && *hint == '1') {
+ SDL_joystick_allows_background_events = SDL_TRUE;
+ } else {
+ SDL_joystick_allows_background_events = SDL_FALSE;
+ }
+}
+
+int
+SDL_JoystickInit(void)
+{
+ int status;
+
+ SDL_GameControllerInitMappings();
+
+ /* Create the joystick list lock */
+ if (!SDL_joystick_lock) {
+ SDL_joystick_lock = SDL_CreateMutex();
+ }
+
+ /* See if we should allow joystick events while in the background */
+ SDL_AddHintCallback(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
+ SDL_JoystickAllowBackgroundEventsChanged, NULL);
+
+#if !SDL_EVENTS_DISABLED
+ if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) {
+ return -1;
+ }
+#endif /* !SDL_EVENTS_DISABLED */
+
+ status = SDL_SYS_JoystickInit();
+ if (status >= 0) {
+ status = 0;
+ }
+ return (status);
+}
+
+/*
+ * Count the number of joysticks attached to the system
+ */
+int
+SDL_NumJoysticks(void)
+{
+ return SDL_SYS_NumJoysticks();
+}
+
+/*
+ * Get the implementation dependent name of a joystick
+ */
+const char *
+SDL_JoystickNameForIndex(int device_index)
+{
+ if (device_index < 0 || device_index >= SDL_NumJoysticks()) {
+ SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
+ return (NULL);
+ }
+ return (SDL_SYS_JoystickNameForDeviceIndex(device_index));
+}
+
+/*
+ * Return true if this joystick is known to have all axes centered at zero
+ * This isn't generally needed unless the joystick never generates an initial axis value near zero,
+ * e.g. it's emulating axes with digital buttons
+ */
+static SDL_bool
+SDL_JoystickAxesCenteredAtZero(SDL_Joystick *joystick)
+{
+ static Uint32 zero_centered_joysticks[] = {
+ MAKE_VIDPID(0x0e8f, 0x3013), /* HuiJia SNES USB adapter */
+ MAKE_VIDPID(0x05a0, 0x3232), /* 8Bitdo Zero Gamepad */
+ };
+
+ int i;
+ Uint32 id = MAKE_VIDPID(SDL_JoystickGetVendor(joystick),
+ SDL_JoystickGetProduct(joystick));
+
+/*printf("JOYSTICK '%s' VID/PID 0x%.4x/0x%.4x AXES: %d\n", joystick->name, vendor, product, joystick->naxes);*/
+
+ if (joystick->naxes == 2) {
+ /* Assume D-pad or thumbstick style axes are centered at 0 */
+ return SDL_TRUE;
+ }
+
+ for (i = 0; i < SDL_arraysize(zero_centered_joysticks); ++i) {
+ if (id == zero_centered_joysticks[i]) {
+ return SDL_TRUE;
+ }
+ }
+ return SDL_FALSE;
+}
+
+/*
+ * Open a joystick for use - the index passed as an argument refers to
+ * the N'th joystick on the system. This index is the value which will
+ * identify this joystick in future joystick events.
+ *
+ * This function returns a joystick identifier, or NULL if an error occurred.
+ */
+SDL_Joystick *
+SDL_JoystickOpen(int device_index)
+{
+ SDL_Joystick *joystick;
+ SDL_Joystick *joysticklist;
+ const char *joystickname = NULL;
+
+ if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
+ SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
+ return (NULL);
+ }
+
+ SDL_LockJoysticks();
+
+ joysticklist = SDL_joysticks;
+ /* If the joystick is already open, return it
+ * it is important that we have a single joystick * for each instance id
+ */
+ while (joysticklist) {
+ if (SDL_JoystickGetDeviceInstanceID(device_index) == joysticklist->instance_id) {
+ joystick = joysticklist;
+ ++joystick->ref_count;
+ SDL_UnlockJoysticks();
+ return (joystick);
+ }
+ joysticklist = joysticklist->next;
+ }
+
+ /* Create and initialize the joystick */
+ joystick = (SDL_Joystick *) SDL_calloc(sizeof(*joystick), 1);
+ if (joystick == NULL) {
+ SDL_OutOfMemory();
+ SDL_UnlockJoysticks();
+ return NULL;
+ }
+
+ if (SDL_SYS_JoystickOpen(joystick, device_index) < 0) {
+ SDL_free(joystick);
+ SDL_UnlockJoysticks();
+ return NULL;
+ }
+
+ joystickname = SDL_SYS_JoystickNameForDeviceIndex(device_index);
+ if (joystickname)
+ joystick->name = SDL_strdup(joystickname);
+ else
+ joystick->name = NULL;
+
+ if (joystick->naxes > 0) {
+ joystick->axes = (SDL_JoystickAxisInfo *) SDL_calloc(joystick->naxes, sizeof(SDL_JoystickAxisInfo));
+ }
+ if (joystick->nhats > 0) {
+ joystick->hats = (Uint8 *) SDL_calloc(joystick->nhats, sizeof(Uint8));
+ }
+ if (joystick->nballs > 0) {
+ joystick->balls = (struct balldelta *) SDL_calloc(joystick->nballs, sizeof(*joystick->balls));
+ }
+ if (joystick->nbuttons > 0) {
+ joystick->buttons = (Uint8 *) SDL_calloc(joystick->nbuttons, sizeof(Uint8));
+ }
+ if (((joystick->naxes > 0) && !joystick->axes)
+ || ((joystick->nhats > 0) && !joystick->hats)
+ || ((joystick->nballs > 0) && !joystick->balls)
+ || ((joystick->nbuttons > 0) && !joystick->buttons)) {
+ SDL_OutOfMemory();
+ SDL_JoystickClose(joystick);
+ SDL_UnlockJoysticks();
+ return NULL;
+ }
+ joystick->epowerlevel = SDL_JOYSTICK_POWER_UNKNOWN;
+
+ /* If this joystick is known to have all zero centered axes, skip the auto-centering code */
+ if (SDL_JoystickAxesCenteredAtZero(joystick)) {
+ int i;
+
+ for (i = 0; i < joystick->naxes; ++i) {
+ joystick->axes[i].has_initial_value = SDL_TRUE;
+ }
+ }
+
+ joystick->is_game_controller = SDL_IsGameController(device_index);
+
+ /* Add joystick to list */
+ ++joystick->ref_count;
+ /* Link the joystick in the list */
+ joystick->next = SDL_joysticks;
+ SDL_joysticks = joystick;
+
+ SDL_UnlockJoysticks();
+
+ SDL_SYS_JoystickUpdate(joystick);
+
+ return (joystick);
+}
+
+
+/*
+ * Checks to make sure the joystick is valid.
+ */
+int
+SDL_PrivateJoystickValid(SDL_Joystick * joystick)
+{
+ int valid;
+
+ if (joystick == NULL) {
+ SDL_SetError("Joystick hasn't been opened yet");
+ valid = 0;
+ } else {
+ valid = 1;
+ }
+
+ return valid;
+}
+
+/*
+ * Get the number of multi-dimensional axis controls on a joystick
+ */
+int
+SDL_JoystickNumAxes(SDL_Joystick * joystick)
+{
+ if (!SDL_PrivateJoystickValid(joystick)) {
+ return (-1);
+ }
+ return (joystick->naxes);
+}
+
+/*
+ * Get the number of hats on a joystick
+ */
+int
+SDL_JoystickNumHats(SDL_Joystick * joystick)
+{
+ if (!SDL_PrivateJoystickValid(joystick)) {
+ return (-1);
+ }
+ return (joystick->nhats);
+}
+
+/*
+ * Get the number of trackballs on a joystick
+ */
+int
+SDL_JoystickNumBalls(SDL_Joystick * joystick)
+{
+ if (!SDL_PrivateJoystickValid(joystick)) {
+ return (-1);
+ }
+ return (joystick->nballs);
+}
+
+/*
+ * Get the number of buttons on a joystick
+ */
+int
+SDL_JoystickNumButtons(SDL_Joystick * joystick)
+{
+ if (!SDL_PrivateJoystickValid(joystick)) {
+ return (-1);
+ }
+ return (joystick->nbuttons);
+}
+
+/*
+ * Get the current state of an axis control on a joystick
+ */
+Sint16
+SDL_JoystickGetAxis(SDL_Joystick * joystick, int axis)
+{
+ Sint16 state;
+
+ if (!SDL_PrivateJoystickValid(joystick)) {
+ return (0);
+ }
+ if (axis < joystick->naxes) {
+ state = joystick->axes[axis].value;
+ } else {
+ SDL_SetError("Joystick only has %d axes", joystick->naxes);
+ state = 0;
+ }
+ return (state);
+}
+
+/*
+ * Get the initial state of an axis control on a joystick
+ */
+SDL_bool
+SDL_JoystickGetAxisInitialState(SDL_Joystick * joystick, int axis, Sint16 *state)
+{
+ if (!SDL_PrivateJoystickValid(joystick)) {
+ return SDL_FALSE;
+ }
+ if (axis >= joystick->naxes) {
+ SDL_SetError("Joystick only has %d axes", joystick->naxes);
+ return SDL_FALSE;
+ }
+ if (state) {
+ *state = joystick->axes[axis].initial_value;
+ }
+ return joystick->axes[axis].has_initial_value;
+}
+
+/*
+ * Get the current state of a hat on a joystick
+ */
+Uint8
+SDL_JoystickGetHat(SDL_Joystick * joystick, int hat)
+{
+ Uint8 state;
+
+ if (!SDL_PrivateJoystickValid(joystick)) {
+ return (0);
+ }
+ if (hat < joystick->nhats) {
+ state = joystick->hats[hat];
+ } else {
+ SDL_SetError("Joystick only has %d hats", joystick->nhats);
+ state = 0;
+ }
+ return (state);
+}
+
+/*
+ * Get the ball axis change since the last poll
+ */
+int
+SDL_JoystickGetBall(SDL_Joystick * joystick, int ball, int *dx, int *dy)
+{
+ int retval;
+
+ if (!SDL_PrivateJoystickValid(joystick)) {
+ return (-1);
+ }
+
+ retval = 0;
+ if (ball < joystick->nballs) {
+ if (dx) {
+ *dx = joystick->balls[ball].dx;
+ }
+ if (dy) {
+ *dy = joystick->balls[ball].dy;
+ }
+ joystick->balls[ball].dx = 0;
+ joystick->balls[ball].dy = 0;
+ } else {
+ return SDL_SetError("Joystick only has %d balls", joystick->nballs);
+ }
+ return (retval);
+}
+
+/*
+ * Get the current state of a button on a joystick
+ */
+Uint8
+SDL_JoystickGetButton(SDL_Joystick * joystick, int button)
+{
+ Uint8 state;
+
+ if (!SDL_PrivateJoystickValid(joystick)) {
+ return (0);
+ }
+ if (button < joystick->nbuttons) {
+ state = joystick->buttons[button];
+ } else {
+ SDL_SetError("Joystick only has %d buttons", joystick->nbuttons);
+ state = 0;
+ }
+ return (state);
+}
+
+/*
+ * Return if the joystick in question is currently attached to the system,
+ * \return SDL_FALSE if not plugged in, SDL_TRUE if still present.
+ */
+SDL_bool
+SDL_JoystickGetAttached(SDL_Joystick * joystick)
+{
+ if (!SDL_PrivateJoystickValid(joystick)) {
+ return SDL_FALSE;
+ }
+
+ return SDL_SYS_JoystickAttached(joystick);
+}
+
+/*
+ * Get the instance id for this opened joystick
+ */
+SDL_JoystickID
+SDL_JoystickInstanceID(SDL_Joystick * joystick)
+{
+ if (!SDL_PrivateJoystickValid(joystick)) {
+ return (-1);
+ }
+
+ return (joystick->instance_id);
+}
+
+/*
+ * Find the SDL_Joystick that owns this instance id
+ */
+SDL_Joystick *
+SDL_JoystickFromInstanceID(SDL_JoystickID joyid)
+{
+ SDL_Joystick *joystick;
+
+ SDL_LockJoysticks();
+ for (joystick = SDL_joysticks; joystick; joystick = joystick->next) {
+ if (joystick->instance_id == joyid) {
+ SDL_UnlockJoysticks();
+ return joystick;
+ }
+ }
+ SDL_UnlockJoysticks();
+ return NULL;
+}
+
+/*
+ * Get the friendly name of this joystick
+ */
+const char *
+SDL_JoystickName(SDL_Joystick * joystick)
+{
+ if (!SDL_PrivateJoystickValid(joystick)) {
+ return (NULL);
+ }
+
+ return (joystick->name);
+}
+
+/*
+ * Close a joystick previously opened with SDL_JoystickOpen()
+ */
+void
+SDL_JoystickClose(SDL_Joystick * joystick)
+{
+ SDL_Joystick *joysticklist;
+ SDL_Joystick *joysticklistprev;
+
+ if (!joystick) {
+ return;
+ }
+
+ SDL_LockJoysticks();
+
+ /* First decrement ref count */
+ if (--joystick->ref_count > 0) {
+ SDL_UnlockJoysticks();
+ return;
+ }
+
+ if (SDL_updating_joystick) {
+ SDL_UnlockJoysticks();
+ return;
+ }
+
+ SDL_SYS_JoystickClose(joystick);
+ joystick->hwdata = NULL;
+
+ joysticklist = SDL_joysticks;
+ joysticklistprev = NULL;
+ while (joysticklist) {
+ if (joystick == joysticklist) {
+ if (joysticklistprev) {
+ /* unlink this entry */
+ joysticklistprev->next = joysticklist->next;
+ } else {
+ SDL_joysticks = joystick->next;
+ }
+ break;
+ }
+ joysticklistprev = joysticklist;
+ joysticklist = joysticklist->next;
+ }
+
+ SDL_free(joystick->name);
+
+ /* Free the data associated with this joystick */
+ SDL_free(joystick->axes);
+ SDL_free(joystick->hats);
+ SDL_free(joystick->balls);
+ SDL_free(joystick->buttons);
+ SDL_free(joystick);
+
+ SDL_UnlockJoysticks();
+}
+
+void
+SDL_JoystickQuit(void)
+{
+ /* Make sure we're not getting called in the middle of updating joysticks */
+ SDL_assert(!SDL_updating_joystick);
+
+ SDL_LockJoysticks();
+
+ /* Stop the event polling */
+ while (SDL_joysticks) {
+ SDL_joysticks->ref_count = 1;
+ SDL_JoystickClose(SDL_joysticks);
+ }
+
+ /* Quit the joystick setup */
+ SDL_SYS_JoystickQuit();
+
+ SDL_UnlockJoysticks();
+
+#if !SDL_EVENTS_DISABLED
+ SDL_QuitSubSystem(SDL_INIT_EVENTS);
+#endif
+
+ SDL_DelHintCallback(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
+ SDL_JoystickAllowBackgroundEventsChanged, NULL);
+
+ if (SDL_joystick_lock) {
+ SDL_DestroyMutex(SDL_joystick_lock);
+ SDL_joystick_lock = NULL;
+ }
+
+ SDL_GameControllerQuitMappings();
+}
+
+
+static SDL_bool
+SDL_PrivateJoystickShouldIgnoreEvent()
+{
+ if (SDL_joystick_allows_background_events) {
+ return SDL_FALSE;
+ }
+
+ if (SDL_HasWindows() && SDL_GetKeyboardFocus() == NULL) {
+ /* We have windows but we don't have focus, ignore the event. */
+ return SDL_TRUE;
+ }
+ return SDL_FALSE;
+}
+
+/* These are global for SDL_sysjoystick.c and SDL_events.c */
+
+void SDL_PrivateJoystickAdded(int device_index)
+{
+#if !SDL_EVENTS_DISABLED
+ SDL_Event event;
+
+ event.type = SDL_JOYDEVICEADDED;
+
+ if (SDL_GetEventState(event.type) == SDL_ENABLE) {
+ event.jdevice.which = device_index;
+ SDL_PushEvent(&event);
+ }
+#endif /* !SDL_EVENTS_DISABLED */
+}
+
+/*
+ * If there is an existing add event in the queue, it needs to be modified
+ * to have the right value for which, because the number of controllers in
+ * the system is now one less.
+ */
+static void UpdateEventsForDeviceRemoval()
+{
+ int i, num_events;
+ SDL_Event *events;
+
+ num_events = SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED);
+ if (num_events <= 0) {
+ return;
+ }
+
+ events = SDL_stack_alloc(SDL_Event, num_events);
+ if (!events) {
+ return;
+ }
+
+ num_events = SDL_PeepEvents(events, num_events, SDL_GETEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEADDED);
+ for (i = 0; i < num_events; ++i) {
+ --events[i].jdevice.which;
+ }
+ SDL_PeepEvents(events, num_events, SDL_ADDEVENT, 0, 0);
+
+ SDL_stack_free(events);
+}
+
+void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
+{
+#if !SDL_EVENTS_DISABLED
+ SDL_Event event;
+
+ event.type = SDL_JOYDEVICEREMOVED;
+
+ if (SDL_GetEventState(event.type) == SDL_ENABLE) {
+ event.jdevice.which = device_instance;
+ SDL_PushEvent(&event);
+ }
+
+ UpdateEventsForDeviceRemoval();
+#endif /* !SDL_EVENTS_DISABLED */
+}
+
+int
+SDL_PrivateJoystickAxis(SDL_Joystick * joystick, Uint8 axis, Sint16 value)
+{
+ int posted;
+
+ /* Make sure we're not getting garbage or duplicate events */
+ if (axis >= joystick->naxes) {
+ return 0;
+ }
+ if (!joystick->axes[axis].has_initial_value) {
+ joystick->axes[axis].initial_value = value;
+ joystick->axes[axis].value = value;
+ joystick->axes[axis].zero = value;
+ joystick->axes[axis].has_initial_value = SDL_TRUE;
+ }
+ if (value == joystick->axes[axis].value) {
+ return 0;
+ }
+ if (!joystick->axes[axis].sent_initial_value) {
+ /* Make sure we don't send motion until there's real activity on this axis */
+ const int MAX_ALLOWED_JITTER = SDL_JOYSTICK_AXIS_MAX / 80; /* ShanWan PS3 controller needed 96 */
+ if (SDL_abs(value - joystick->axes[axis].value) <= MAX_ALLOWED_JITTER) {
+ return 0;
+ }
+ joystick->axes[axis].sent_initial_value = SDL_TRUE;
+ joystick->axes[axis].value = value; /* Just so we pass the check above */
+ SDL_PrivateJoystickAxis(joystick, axis, joystick->axes[axis].initial_value);
+ }
+
+ /* We ignore events if we don't have keyboard focus, except for centering
+ * events.
+ */
+ if (SDL_PrivateJoystickShouldIgnoreEvent()) {
+ if ((value > joystick->axes[axis].zero && value >= joystick->axes[axis].value) ||
+ (value < joystick->axes[axis].zero && value <= joystick->axes[axis].value)) {
+ return 0;
+ }
+ }
+
+ /* Update internal joystick state */
+ joystick->axes[axis].value = value;
+
+ /* Post the event, if desired */
+ posted = 0;
+#if !SDL_EVENTS_DISABLED
+ if (SDL_GetEventState(SDL_JOYAXISMOTION) == SDL_ENABLE) {
+ SDL_Event event;
+ event.type = SDL_JOYAXISMOTION;
+ event.jaxis.which = joystick->instance_id;
+ event.jaxis.axis = axis;
+ event.jaxis.value = value;
+ posted = SDL_PushEvent(&event) == 1;
+ }
+#endif /* !SDL_EVENTS_DISABLED */
+ return (posted);
+}
+
+int
+SDL_PrivateJoystickHat(SDL_Joystick * joystick, Uint8 hat, Uint8 value)
+{
+ int posted;
+
+ /* Make sure we're not getting garbage or duplicate events */
+ if (hat >= joystick->nhats) {
+ return 0;
+ }
+ if (value == joystick->hats[hat]) {
+ return 0;
+ }
+
+ /* We ignore events if we don't have keyboard focus, except for centering
+ * events.
+ */
+ if (SDL_PrivateJoystickShouldIgnoreEvent()) {
+ if (value != SDL_HAT_CENTERED) {
+ return 0;
+ }
+ }
+
+ /* Update internal joystick state */
+ joystick->hats[hat] = value;
+
+ /* Post the event, if desired */
+ posted = 0;
+#if !SDL_EVENTS_DISABLED
+ if (SDL_GetEventState(SDL_JOYHATMOTION) == SDL_ENABLE) {
+ SDL_Event event;
+ event.jhat.type = SDL_JOYHATMOTION;
+ event.jhat.which = joystick->instance_id;
+ event.jhat.hat = hat;
+ event.jhat.value = value;
+ posted = SDL_PushEvent(&event) == 1;
+ }
+#endif /* !SDL_EVENTS_DISABLED */
+ return (posted);
+}
+
+int
+SDL_PrivateJoystickBall(SDL_Joystick * joystick, Uint8 ball,
+ Sint16 xrel, Sint16 yrel)
+{
+ int posted;
+
+ /* Make sure we're not getting garbage events */
+ if (ball >= joystick->nballs) {
+ return 0;
+ }
+
+ /* We ignore events if we don't have keyboard focus. */
+ if (SDL_PrivateJoystickShouldIgnoreEvent()) {
+ return 0;
+ }
+
+ /* Update internal mouse state */
+ joystick->balls[ball].dx += xrel;
+ joystick->balls[ball].dy += yrel;
+
+ /* Post the event, if desired */
+ posted = 0;
+#if !SDL_EVENTS_DISABLED
+ if (SDL_GetEventState(SDL_JOYBALLMOTION) == SDL_ENABLE) {
+ SDL_Event event;
+ event.jball.type = SDL_JOYBALLMOTION;
+ event.jball.which = joystick->instance_id;
+ event.jball.ball = ball;
+ event.jball.xrel = xrel;
+ event.jball.yrel = yrel;
+ posted = SDL_PushEvent(&event) == 1;
+ }
+#endif /* !SDL_EVENTS_DISABLED */
+ return (posted);
+}
+
+int
+SDL_PrivateJoystickButton(SDL_Joystick * joystick, Uint8 button, Uint8 state)
+{
+ int posted;
+#if !SDL_EVENTS_DISABLED
+ SDL_Event event;
+
+ switch (state) {
+ case SDL_PRESSED:
+ event.type = SDL_JOYBUTTONDOWN;
+ break;
+ case SDL_RELEASED:
+ event.type = SDL_JOYBUTTONUP;
+ break;
+ default:
+ /* Invalid state -- bail */
+ return (0);
+ }
+#endif /* !SDL_EVENTS_DISABLED */
+
+ /* Make sure we're not getting garbage or duplicate events */
+ if (button >= joystick->nbuttons) {
+ return 0;
+ }
+ if (state == joystick->buttons[button]) {
+ return 0;
+ }
+
+ /* We ignore events if we don't have keyboard focus, except for button
+ * release. */
+ if (SDL_PrivateJoystickShouldIgnoreEvent()) {
+ if (state == SDL_PRESSED) {
+ return 0;
+ }
+ }
+
+ /* Update internal joystick state */
+ joystick->buttons[button] = state;
+
+ /* Post the event, if desired */
+ posted = 0;
+#if !SDL_EVENTS_DISABLED
+ if (SDL_GetEventState(event.type) == SDL_ENABLE) {
+ event.jbutton.which = joystick->instance_id;
+ event.jbutton.button = button;
+ event.jbutton.state = state;
+ posted = SDL_PushEvent(&event) == 1;
+ }
+#endif /* !SDL_EVENTS_DISABLED */
+ return (posted);
+}
+
+void
+SDL_JoystickUpdate(void)
+{
+ SDL_Joystick *joystick;
+
+ SDL_LockJoysticks();
+
+ if (SDL_updating_joystick) {
+ /* The joysticks are already being updated */
+ SDL_UnlockJoysticks();
+ return;
+ }
+
+ SDL_updating_joystick = SDL_TRUE;
+
+ /* Make sure the list is unlocked while dispatching events to prevent application deadlocks */
+ SDL_UnlockJoysticks();
+
+ for (joystick = SDL_joysticks; joystick; joystick = joystick->next) {
+ SDL_SYS_JoystickUpdate(joystick);
+
+ if (joystick->force_recentering) {
+ int i;
+
+ /* Tell the app that everything is centered/unpressed... */
+ for (i = 0; i < joystick->naxes; i++) {
+ if (joystick->axes[i].has_initial_value) {
+ SDL_PrivateJoystickAxis(joystick, i, joystick->axes[i].zero);
+ }
+ }
+
+ for (i = 0; i < joystick->nbuttons; i++) {
+ SDL_PrivateJoystickButton(joystick, i, 0);
+ }
+
+ for (i = 0; i < joystick->nhats; i++) {
+ SDL_PrivateJoystickHat(joystick, i, SDL_HAT_CENTERED);
+ }
+
+ joystick->force_recentering = SDL_FALSE;
+ }
+ }
+
+ SDL_LockJoysticks();
+
+ SDL_updating_joystick = SDL_FALSE;
+
+ /* If any joysticks were closed while updating, free them here */
+ for (joystick = SDL_joysticks; joystick; joystick = joystick->next) {
+ if (joystick->ref_count <= 0) {
+ SDL_JoystickClose(joystick);
+ }
+ }
+
+ /* this needs to happen AFTER walking the joystick list above, so that any
+ dangling hardware data from removed devices can be free'd
+ */
+ SDL_SYS_JoystickDetect();
+
+ SDL_UnlockJoysticks();
+}
+
+int
+SDL_JoystickEventState(int state)
+{
+#if SDL_EVENTS_DISABLED
+ return SDL_DISABLE;
+#else
+ const Uint32 event_list[] = {
+ SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYHATMOTION,
+ SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, SDL_JOYDEVICEADDED, SDL_JOYDEVICEREMOVED
+ };
+ unsigned int i;
+
+ switch (state) {
+ case SDL_QUERY:
+ state = SDL_DISABLE;
+ for (i = 0; i < SDL_arraysize(event_list); ++i) {
+ state = SDL_EventState(event_list[i], SDL_QUERY);
+ if (state == SDL_ENABLE) {
+ break;
+ }
+ }
+ break;
+ default:
+ for (i = 0; i < SDL_arraysize(event_list); ++i) {
+ SDL_EventState(event_list[i], state);
+ }
+ break;
+ }
+ return (state);
+#endif /* SDL_EVENTS_DISABLED */
+}
+
+void SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version)
+{
+ Uint16 *guid16 = (Uint16 *)guid.data;
+
+ /* If the GUID fits the form of BUS 0000 VENDOR 0000 PRODUCT 0000, return the data */
+ if (/* guid16[0] is device bus type */
+ guid16[1] == 0x0000 &&
+ /* guid16[2] is vendor ID */
+ guid16[3] == 0x0000 &&
+ /* guid16[4] is product ID */
+ guid16[5] == 0x0000
+ /* guid16[6] is product version */
+ ) {
+ if (vendor) {
+ *vendor = guid16[2];
+ }
+ if (product) {
+ *product = guid16[4];
+ }
+ if (version) {
+ *version = guid16[6];
+ }
+ } else {
+ if (vendor) {
+ *vendor = 0;
+ }
+ if (product) {
+ *product = 0;
+ }
+ if (version) {
+ *version = 0;
+ }
+ }
+}
+
+static SDL_bool SDL_IsJoystickProductWheel(Uint32 vidpid)
+{
+ static Uint32 wheel_joysticks[] = {
+ MAKE_VIDPID(0x046d, 0xc294), /* Logitech generic wheel */
+ MAKE_VIDPID(0x046d, 0xc295), /* Logitech Momo Force */
+ MAKE_VIDPID(0x046d, 0xc298), /* Logitech Driving Force Pro */
+ MAKE_VIDPID(0x046d, 0xc299), /* Logitech G25 */
+ MAKE_VIDPID(0x046d, 0xc29a), /* Logitech Driving Force GT */
+ MAKE_VIDPID(0x046d, 0xc29b), /* Logitech G27 */
+ MAKE_VIDPID(0x046d, 0xc261), /* Logitech G920 (initial mode) */
+ MAKE_VIDPID(0x046d, 0xc262), /* Logitech G920 (active mode) */
+ MAKE_VIDPID(0x044f, 0xb65d), /* Thrustmaster Wheel FFB */
+ MAKE_VIDPID(0x044f, 0xb66d), /* Thrustmaster Wheel FFB */
+ MAKE_VIDPID(0x044f, 0xb677), /* Thrustmaster T150 */
+ MAKE_VIDPID(0x044f, 0xb664), /* Thrustmaster TX (initial mode) */
+ MAKE_VIDPID(0x044f, 0xb669), /* Thrustmaster TX (active mode) */
+ };
+ int i;
+
+ for (i = 0; i < SDL_arraysize(wheel_joysticks); ++i) {
+ if (vidpid == wheel_joysticks[i]) {
+ return SDL_TRUE;
+ }
+ }
+ return SDL_FALSE;
+}
+
+static SDL_bool SDL_IsJoystickProductFlightStick(Uint32 vidpid)
+{
+ static Uint32 flightstick_joysticks[] = {
+ MAKE_VIDPID(0x044f, 0x0402), /* HOTAS Warthog Joystick */
+ MAKE_VIDPID(0x0738, 0x2221), /* Saitek Pro Flight X-56 Rhino Stick */
+ };
+ int i;
+
+ for (i = 0; i < SDL_arraysize(flightstick_joysticks); ++i) {
+ if (vidpid == flightstick_joysticks[i]) {
+ return SDL_TRUE;
+ }
+ }
+ return SDL_FALSE;
+}
+
+static SDL_bool SDL_IsJoystickProductThrottle(Uint32 vidpid)
+{
+ static Uint32 throttle_joysticks[] = {
+ MAKE_VIDPID(0x044f, 0x0404), /* HOTAS Warthog Throttle */
+ MAKE_VIDPID(0x0738, 0xa221), /* Saitek Pro Flight X-56 Rhino Throttle */
+ };
+ int i;
+
+ for (i = 0; i < SDL_arraysize(throttle_joysticks); ++i) {
+ if (vidpid == throttle_joysticks[i]) {
+ return SDL_TRUE;
+ }
+ }
+ return SDL_FALSE;
+}
+
+static SDL_JoystickType SDL_GetJoystickGUIDType(SDL_JoystickGUID guid)
+{
+ Uint16 vendor;
+ Uint16 product;
+ Uint32 vidpid;
+
+ if (guid.data[14] == 'x') {
+ /* XInput GUID, get the type based on the XInput device subtype */
+ switch (guid.data[15]) {
+ case 0x01: /* XINPUT_DEVSUBTYPE_GAMEPAD */
+ return SDL_JOYSTICK_TYPE_GAMECONTROLLER;
+ case 0x02: /* XINPUT_DEVSUBTYPE_WHEEL */
+ return SDL_JOYSTICK_TYPE_WHEEL;
+ case 0x03: /* XINPUT_DEVSUBTYPE_ARCADE_STICK */
+ return SDL_JOYSTICK_TYPE_ARCADE_STICK;
+ case 0x04: /* XINPUT_DEVSUBTYPE_FLIGHT_STICK */
+ return SDL_JOYSTICK_TYPE_FLIGHT_STICK;
+ case 0x05: /* XINPUT_DEVSUBTYPE_DANCE_PAD */
+ return SDL_JOYSTICK_TYPE_DANCE_PAD;
+ case 0x06: /* XINPUT_DEVSUBTYPE_GUITAR */
+ case 0x07: /* XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE */
+ case 0x0B: /* XINPUT_DEVSUBTYPE_GUITAR_BASS */
+ return SDL_JOYSTICK_TYPE_GUITAR;
+ case 0x08: /* XINPUT_DEVSUBTYPE_DRUM_KIT */
+ return SDL_JOYSTICK_TYPE_DRUM_KIT;
+ case 0x13: /* XINPUT_DEVSUBTYPE_ARCADE_PAD */
+ return SDL_JOYSTICK_TYPE_ARCADE_PAD;
+ default:
+ return SDL_JOYSTICK_TYPE_UNKNOWN;
+ }
+ }
+
+ SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL);
+ vidpid = MAKE_VIDPID(vendor, product);
+
+ if (SDL_IsJoystickProductWheel(vidpid)) {
+ return SDL_JOYSTICK_TYPE_WHEEL;
+ }
+
+ if (SDL_IsJoystickProductFlightStick(vidpid)) {
+ return SDL_JOYSTICK_TYPE_FLIGHT_STICK;
+ }
+
+ if (SDL_IsJoystickProductThrottle(vidpid)) {
+ return SDL_JOYSTICK_TYPE_THROTTLE;
+ }
+
+ return SDL_JOYSTICK_TYPE_UNKNOWN;
+}
+
+/* return the guid for this index */
+SDL_JoystickGUID SDL_JoystickGetDeviceGUID(int device_index)
+{
+ if (device_index < 0 || device_index >= SDL_NumJoysticks()) {
+ SDL_JoystickGUID emptyGUID;
+ SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
+ SDL_zero(emptyGUID);
+ return emptyGUID;
+ }
+ return SDL_SYS_JoystickGetDeviceGUID(device_index);
+}
+
+Uint16 SDL_JoystickGetDeviceVendor(int device_index)
+{
+ Uint16 vendor;
+ SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(device_index);
+
+ SDL_GetJoystickGUIDInfo(guid, &vendor, NULL, NULL);
+ return vendor;
+}
+
+Uint16 SDL_JoystickGetDeviceProduct(int device_index)
+{
+ Uint16 product;
+ SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(device_index);
+
+ SDL_GetJoystickGUIDInfo(guid, NULL, &product, NULL);
+ return product;
+}
+
+Uint16 SDL_JoystickGetDeviceProductVersion(int device_index)
+{
+ Uint16 version;
+ SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(device_index);
+
+ SDL_GetJoystickGUIDInfo(guid, NULL, NULL, &version);
+ return version;
+}
+
+SDL_JoystickType SDL_JoystickGetDeviceType(int device_index)
+{
+ SDL_JoystickType type;
+ SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(device_index);
+
+ type = SDL_GetJoystickGUIDType(guid);
+ if (type == SDL_JOYSTICK_TYPE_UNKNOWN) {
+ if (SDL_IsGameController(device_index)) {
+ type = SDL_JOYSTICK_TYPE_GAMECONTROLLER;
+ }
+ }
+ return type;
+}
+
+SDL_JoystickID SDL_JoystickGetDeviceInstanceID(int device_index)
+{
+ if (device_index < 0 || device_index >= SDL_NumJoysticks()) {
+ SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
+ return -1;
+ }
+ return SDL_SYS_GetInstanceIdOfDeviceIndex(device_index);
+}
+
+SDL_JoystickGUID SDL_JoystickGetGUID(SDL_Joystick * joystick)
+{
+ if (!SDL_PrivateJoystickValid(joystick)) {
+ SDL_JoystickGUID emptyGUID;
+ SDL_zero(emptyGUID);
+ return emptyGUID;
+ }
+ return SDL_SYS_JoystickGetGUID(joystick);
+}
+
+Uint16 SDL_JoystickGetVendor(SDL_Joystick * joystick)
+{
+ Uint16 vendor;
+ SDL_JoystickGUID guid = SDL_JoystickGetGUID(joystick);
+
+ SDL_GetJoystickGUIDInfo(guid, &vendor, NULL, NULL);
+ return vendor;
+}
+
+Uint16 SDL_JoystickGetProduct(SDL_Joystick * joystick)
+{
+ Uint16 product;
+ SDL_JoystickGUID guid = SDL_JoystickGetGUID(joystick);
+
+ SDL_GetJoystickGUIDInfo(guid, NULL, &product, NULL);
+ return product;
+}
+
+Uint16 SDL_JoystickGetProductVersion(SDL_Joystick * joystick)
+{
+ Uint16 version;
+ SDL_JoystickGUID guid = SDL_JoystickGetGUID(joystick);
+
+ SDL_GetJoystickGUIDInfo(guid, NULL, NULL, &version);
+ return version;
+}
+
+SDL_JoystickType SDL_JoystickGetType(SDL_Joystick * joystick)
+{
+ SDL_JoystickType type;
+ SDL_JoystickGUID guid = SDL_JoystickGetGUID(joystick);
+
+ type = SDL_GetJoystickGUIDType(guid);
+ if (type == SDL_JOYSTICK_TYPE_UNKNOWN) {
+ if (joystick && joystick->is_game_controller) {
+ type = SDL_JOYSTICK_TYPE_GAMECONTROLLER;
+ }
+ }
+ return type;
+}
+
+/* convert the guid to a printable string */
+void SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID)
+{
+ static const char k_rgchHexToASCII[] = "0123456789abcdef";
+ int i;
+
+ if ((pszGUID == NULL) || (cbGUID <= 0)) {
+ return;
+ }
+
+ for (i = 0; i < sizeof(guid.data) && i < (cbGUID-1)/2; i++) {
+ /* each input byte writes 2 ascii chars, and might write a null byte. */
+ /* If we don't have room for next input byte, stop */
+ unsigned char c = guid.data[i];
+
+ *pszGUID++ = k_rgchHexToASCII[c >> 4];
+ *pszGUID++ = k_rgchHexToASCII[c & 0x0F];
+ }
+ *pszGUID = '\0';
+}
+
+
+/*-----------------------------------------------------------------------------
+ * Purpose: Returns the 4 bit nibble for a hex character
+ * Input : c -
+ * Output : unsigned char
+ *-----------------------------------------------------------------------------*/
+static unsigned char nibble(char c)
+{
+ if ((c >= '0') && (c <= '9')) {
+ return (unsigned char)(c - '0');
+ }
+
+ if ((c >= 'A') && (c <= 'F')) {
+ return (unsigned char)(c - 'A' + 0x0a);
+ }
+
+ if ((c >= 'a') && (c <= 'f')) {
+ return (unsigned char)(c - 'a' + 0x0a);
+ }
+
+ /* received an invalid character, and no real way to return an error */
+ /* AssertMsg1(false, "Q_nibble invalid hex character '%c' ", c); */
+ return 0;
+}
+
+
+/* convert the string version of a joystick guid to the struct */
+SDL_JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID)
+{
+ SDL_JoystickGUID guid;
+ int maxoutputbytes= sizeof(guid);
+ size_t len = SDL_strlen(pchGUID);
+ Uint8 *p;
+ size_t i;
+
+ /* Make sure it's even */
+ len = (len) & ~0x1;
+
+ SDL_memset(&guid, 0x00, sizeof(guid));
+
+ p = (Uint8 *)&guid;
+ for (i = 0; (i < len) && ((p - (Uint8 *)&guid) < maxoutputbytes); i+=2, p++) {
+ *p = (nibble(pchGUID[i]) << 4) | nibble(pchGUID[i+1]);
+ }
+
+ return guid;
+}
+
+
+/* update the power level for this joystick */
+void SDL_PrivateJoystickBatteryLevel(SDL_Joystick * joystick, SDL_JoystickPowerLevel ePowerLevel)
+{
+ joystick->epowerlevel = ePowerLevel;
+}
+
+
+/* return its power level */
+SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick)
+{
+ if (!SDL_PrivateJoystickValid(joystick)) {
+ return (SDL_JOYSTICK_POWER_UNKNOWN);
+ }
+ return joystick->epowerlevel;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/SDL_joystick_c.h b/src/3rdparty/SDL2/src/joystick/SDL_joystick_c.h
new file mode 100644
index 0000000..0a8fdb4
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/SDL_joystick_c.h
@@ -0,0 +1,62 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* Useful functions and variables from SDL_joystick.c */
+#include "SDL_joystick.h"
+
+/* Initialization and shutdown functions */
+extern int SDL_JoystickInit(void);
+extern void SDL_JoystickQuit(void);
+
+/* Initialization and shutdown functions */
+extern int SDL_GameControllerInitMappings(void);
+extern void SDL_GameControllerQuitMappings(void);
+extern int SDL_GameControllerInit(void);
+extern void SDL_GameControllerQuit(void);
+
+/* Function to extract information from an SDL joystick GUID */
+extern void SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version);
+
+/* Function to return whether a joystick name and GUID is a game controller */
+extern SDL_bool SDL_IsGameControllerNameAndGUID(const char *name, SDL_JoystickGUID guid);
+
+/* Function to return whether a game controller should be ignored */
+extern SDL_bool SDL_ShouldIgnoreGameController(const char *name, SDL_JoystickGUID guid);
+
+/* Internal event queueing functions */
+extern void SDL_PrivateJoystickAdded(int device_index);
+extern void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance);
+extern int SDL_PrivateJoystickAxis(SDL_Joystick * joystick,
+ Uint8 axis, Sint16 value);
+extern int SDL_PrivateJoystickBall(SDL_Joystick * joystick,
+ Uint8 ball, Sint16 xrel, Sint16 yrel);
+extern int SDL_PrivateJoystickHat(SDL_Joystick * joystick,
+ Uint8 hat, Uint8 value);
+extern int SDL_PrivateJoystickButton(SDL_Joystick * joystick,
+ Uint8 button, Uint8 state);
+extern void SDL_PrivateJoystickBatteryLevel(SDL_Joystick * joystick,
+ SDL_JoystickPowerLevel ePowerLevel);
+
+/* Internal sanity checking functions */
+extern int SDL_PrivateJoystickValid(SDL_Joystick * joystick);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/SDL_sysjoystick.h b/src/3rdparty/SDL2/src/joystick/SDL_sysjoystick.h
new file mode 100644
index 0000000..7de5d83
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/SDL_sysjoystick.h
@@ -0,0 +1,136 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#ifndef SDL_sysjoystick_h_
+#define SDL_sysjoystick_h_
+
+/* This is the system specific header for the SDL joystick API */
+
+#include "SDL_joystick.h"
+#include "SDL_joystick_c.h"
+
+/* The SDL joystick structure */
+typedef struct _SDL_JoystickAxisInfo
+{
+ Sint16 initial_value; /* Initial axis state */
+ Sint16 value; /* Current axis state */
+ Sint16 zero; /* Zero point on the axis (-32768 for triggers) */
+ SDL_bool has_initial_value; /* Whether we've seen a value on the axis yet */
+ SDL_bool sent_initial_value; /* Whether we've sent the initial axis value */
+} SDL_JoystickAxisInfo;
+
+struct _SDL_Joystick
+{
+ SDL_JoystickID instance_id; /* Device instance, monotonically increasing from 0 */
+ char *name; /* Joystick name - system dependent */
+
+ int naxes; /* Number of axis controls on the joystick */
+ SDL_JoystickAxisInfo *axes;
+
+ int nhats; /* Number of hats on the joystick */
+ Uint8 *hats; /* Current hat states */
+
+ int nballs; /* Number of trackballs on the joystick */
+ struct balldelta {
+ int dx;
+ int dy;
+ } *balls; /* Current ball motion deltas */
+
+ int nbuttons; /* Number of buttons on the joystick */
+ Uint8 *buttons; /* Current button states */
+
+ struct joystick_hwdata *hwdata; /* Driver dependent information */
+
+ int ref_count; /* Reference count for multiple opens */
+
+ SDL_bool is_game_controller;
+ SDL_bool force_recentering; /* SDL_TRUE if this device needs to have its state reset to 0 */
+ SDL_JoystickPowerLevel epowerlevel; /* power level of this joystick, SDL_JOYSTICK_POWER_UNKNOWN if not supported */
+ struct _SDL_Joystick *next; /* pointer to next joystick we have allocated */
+};
+
+/* Macro to combine a USB vendor ID and product ID into a single Uint32 value */
+#define MAKE_VIDPID(VID, PID) (((Uint32)(VID))<<16|(PID))
+
+/* Function to scan the system for joysticks.
+ * Joystick 0 should be the system default joystick.
+ * This function should return the number of available joysticks, or -1
+ * on an unrecoverable fatal error.
+ */
+extern int SDL_SYS_JoystickInit(void);
+
+/* Function to return the number of joystick devices plugged in right now */
+extern int SDL_SYS_NumJoysticks(void);
+
+/* Function to cause any queued joystick insertions to be processed */
+extern void SDL_SYS_JoystickDetect(void);
+
+/* Function to get the device-dependent name of a joystick */
+extern const char *SDL_SYS_JoystickNameForDeviceIndex(int device_index);
+
+/* Function to get the current instance id of the joystick located at device_index */
+extern SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index);
+
+/* Function to open a joystick for use.
+ The joystick to open is specified by the device index.
+ This should fill the nbuttons and naxes fields of the joystick structure.
+ It returns 0, or -1 if there is an error.
+ */
+extern int SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index);
+
+/* Function to query if the joystick is currently attached
+ * It returns SDL_TRUE if attached, SDL_FALSE otherwise.
+ */
+extern SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick * joystick);
+
+/* Function to update the state of a joystick - called as a device poll.
+ * This function shouldn't update the joystick structure directly,
+ * but instead should call SDL_PrivateJoystick*() to deliver events
+ * and update joystick device state.
+ */
+extern void SDL_SYS_JoystickUpdate(SDL_Joystick * joystick);
+
+/* Function to close a joystick after use */
+extern void SDL_SYS_JoystickClose(SDL_Joystick * joystick);
+
+/* Function to perform any system-specific joystick related cleanup */
+extern void SDL_SYS_JoystickQuit(void);
+
+/* Function to return the stable GUID for a plugged in device */
+extern SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index);
+
+/* Function to return the stable GUID for a opened joystick */
+extern SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick);
+
+#if SDL_JOYSTICK_XINPUT
+/* Function returns SDL_TRUE if this device is an XInput gamepad */
+extern SDL_bool SDL_SYS_IsXInputGamepad_DeviceIndex(int device_index);
+#endif
+
+#if defined(__ANDROID__)
+/* Function returns SDL_TRUE if this device is a DPAD (maybe a TV remote) */
+extern SDL_bool SDL_SYS_IsDPAD_DeviceIndex(int device_index);
+#endif
+
+#endif /* SDL_sysjoystick_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/android/SDL_sysjoystick.c b/src/3rdparty/SDL2/src/joystick/android/SDL_sysjoystick.c
new file mode 100644
index 0000000..ce5a5df
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/android/SDL_sysjoystick.c
@@ -0,0 +1,687 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifdef SDL_JOYSTICK_ANDROID
+
+#include <stdio.h> /* For the definition of NULL */
+#include "SDL_error.h"
+#include "SDL_events.h"
+
+#include "SDL_joystick.h"
+#include "SDL_hints.h"
+#include "SDL_assert.h"
+#include "SDL_timer.h"
+#include "SDL_log.h"
+#include "SDL_sysjoystick_c.h"
+#include "../SDL_joystick_c.h"
+#include "../../events/SDL_keyboard_c.h"
+#include "../../core/android/SDL_android.h"
+#include "../steam/SDL_steamcontroller.h"
+
+#include "android/keycodes.h"
+
+/* As of platform android-14, android/keycodes.h is missing these defines */
+#ifndef AKEYCODE_BUTTON_1
+#define AKEYCODE_BUTTON_1 188
+#define AKEYCODE_BUTTON_2 189
+#define AKEYCODE_BUTTON_3 190
+#define AKEYCODE_BUTTON_4 191
+#define AKEYCODE_BUTTON_5 192
+#define AKEYCODE_BUTTON_6 193
+#define AKEYCODE_BUTTON_7 194
+#define AKEYCODE_BUTTON_8 195
+#define AKEYCODE_BUTTON_9 196
+#define AKEYCODE_BUTTON_10 197
+#define AKEYCODE_BUTTON_11 198
+#define AKEYCODE_BUTTON_12 199
+#define AKEYCODE_BUTTON_13 200
+#define AKEYCODE_BUTTON_14 201
+#define AKEYCODE_BUTTON_15 202
+#define AKEYCODE_BUTTON_16 203
+#endif
+
+#define ANDROID_ACCELEROMETER_NAME "Android Accelerometer"
+#define ANDROID_ACCELEROMETER_DEVICE_ID INT_MIN
+#define ANDROID_MAX_NBUTTONS 36
+
+static SDL_joylist_item * JoystickByDeviceId(int device_id);
+
+static SDL_joylist_item *SDL_joylist = NULL;
+static SDL_joylist_item *SDL_joylist_tail = NULL;
+static int numjoysticks = 0;
+static int instance_counter = 0;
+
+
+/* Function to convert Android keyCodes into SDL ones.
+ * This code manipulation is done to get a sequential list of codes.
+ * FIXME: This is only suited for the case where we use a fixed number of buttons determined by ANDROID_MAX_NBUTTONS
+ */
+static int
+keycode_to_SDL(int keycode)
+{
+ /* FIXME: If this function gets too unwieldy in the future, replace with a lookup table */
+ int button = 0;
+ switch (keycode) {
+ /* Some gamepad buttons (API 9) */
+ case AKEYCODE_BUTTON_A:
+ button = SDL_CONTROLLER_BUTTON_A;
+ break;
+ case AKEYCODE_BUTTON_B:
+ button = SDL_CONTROLLER_BUTTON_B;
+ break;
+ case AKEYCODE_BUTTON_X:
+ button = SDL_CONTROLLER_BUTTON_X;
+ break;
+ case AKEYCODE_BUTTON_Y:
+ button = SDL_CONTROLLER_BUTTON_Y;
+ break;
+ case AKEYCODE_BUTTON_L1:
+ button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER;
+ break;
+ case AKEYCODE_BUTTON_R1:
+ button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
+ break;
+ case AKEYCODE_BUTTON_THUMBL:
+ button = SDL_CONTROLLER_BUTTON_LEFTSTICK;
+ break;
+ case AKEYCODE_BUTTON_THUMBR:
+ button = SDL_CONTROLLER_BUTTON_RIGHTSTICK;
+ break;
+ case AKEYCODE_BUTTON_START:
+ button = SDL_CONTROLLER_BUTTON_START;
+ break;
+ case AKEYCODE_BACK:
+ case AKEYCODE_BUTTON_SELECT:
+ button = SDL_CONTROLLER_BUTTON_BACK;
+ break;
+ case AKEYCODE_BUTTON_MODE:
+ button = SDL_CONTROLLER_BUTTON_GUIDE;
+ break;
+ case AKEYCODE_BUTTON_L2:
+ button = SDL_CONTROLLER_BUTTON_MAX; /* Not supported by GameController */
+ break;
+ case AKEYCODE_BUTTON_R2:
+ button = SDL_CONTROLLER_BUTTON_MAX+1; /* Not supported by GameController */
+ break;
+ case AKEYCODE_BUTTON_C:
+ button = SDL_CONTROLLER_BUTTON_MAX+2; /* Not supported by GameController */
+ break;
+ case AKEYCODE_BUTTON_Z:
+ button = SDL_CONTROLLER_BUTTON_MAX+3; /* Not supported by GameController */
+ break;
+
+ /* D-Pad key codes (API 1) */
+ case AKEYCODE_DPAD_UP:
+ button = SDL_CONTROLLER_BUTTON_DPAD_UP;
+ break;
+ case AKEYCODE_DPAD_DOWN:
+ button = SDL_CONTROLLER_BUTTON_DPAD_DOWN;
+ break;
+ case AKEYCODE_DPAD_LEFT:
+ button = SDL_CONTROLLER_BUTTON_DPAD_LEFT;
+ break;
+ case AKEYCODE_DPAD_RIGHT:
+ button = SDL_CONTROLLER_BUTTON_DPAD_RIGHT;
+ break;
+ case AKEYCODE_DPAD_CENTER:
+ /* This is handled better by applications as the A button */
+ /*button = SDL_CONTROLLER_BUTTON_MAX+4;*/ /* Not supported by GameController */
+ button = SDL_CONTROLLER_BUTTON_A;
+ break;
+
+ /* More gamepad buttons (API 12), these get mapped to 20...35*/
+ case AKEYCODE_BUTTON_1:
+ case AKEYCODE_BUTTON_2:
+ case AKEYCODE_BUTTON_3:
+ case AKEYCODE_BUTTON_4:
+ case AKEYCODE_BUTTON_5:
+ case AKEYCODE_BUTTON_6:
+ case AKEYCODE_BUTTON_7:
+ case AKEYCODE_BUTTON_8:
+ case AKEYCODE_BUTTON_9:
+ case AKEYCODE_BUTTON_10:
+ case AKEYCODE_BUTTON_11:
+ case AKEYCODE_BUTTON_12:
+ case AKEYCODE_BUTTON_13:
+ case AKEYCODE_BUTTON_14:
+ case AKEYCODE_BUTTON_15:
+ case AKEYCODE_BUTTON_16:
+ button = keycode - AKEYCODE_BUTTON_1 + SDL_CONTROLLER_BUTTON_MAX + 5;
+ break;
+
+ default:
+ return -1;
+ /* break; -Wunreachable-code-break */
+ }
+
+ /* This is here in case future generations, probably with six fingers per hand,
+ * happily add new cases up above and forget to update the max number of buttons.
+ */
+ SDL_assert(button < ANDROID_MAX_NBUTTONS);
+ return button;
+}
+
+static SDL_Scancode
+button_to_scancode(int button)
+{
+ switch (button) {
+ case SDL_CONTROLLER_BUTTON_A:
+ return SDL_SCANCODE_RETURN;
+ case SDL_CONTROLLER_BUTTON_B:
+ return SDL_SCANCODE_ESCAPE;
+ case SDL_CONTROLLER_BUTTON_BACK:
+ return SDL_SCANCODE_ESCAPE;
+ case SDL_CONTROLLER_BUTTON_DPAD_UP:
+ return SDL_SCANCODE_UP;
+ case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
+ return SDL_SCANCODE_DOWN;
+ case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
+ return SDL_SCANCODE_LEFT;
+ case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
+ return SDL_SCANCODE_RIGHT;
+ }
+
+ /* Unsupported button */
+ return SDL_SCANCODE_UNKNOWN;
+}
+
+int
+Android_OnPadDown(int device_id, int keycode)
+{
+ SDL_joylist_item *item;
+ int button = keycode_to_SDL(keycode);
+ if (button >= 0) {
+ item = JoystickByDeviceId(device_id);
+ if (item && item->joystick) {
+ SDL_PrivateJoystickButton(item->joystick, button , SDL_PRESSED);
+ } else {
+ SDL_SendKeyboardKey(SDL_PRESSED, button_to_scancode(button));
+ }
+ return 0;
+ }
+
+ return -1;
+}
+
+int
+Android_OnPadUp(int device_id, int keycode)
+{
+ SDL_joylist_item *item;
+ int button = keycode_to_SDL(keycode);
+ if (button >= 0) {
+ item = JoystickByDeviceId(device_id);
+ if (item && item->joystick) {
+ SDL_PrivateJoystickButton(item->joystick, button, SDL_RELEASED);
+ } else {
+ SDL_SendKeyboardKey(SDL_RELEASED, button_to_scancode(button));
+ }
+ return 0;
+ }
+
+ return -1;
+}
+
+int
+Android_OnJoy(int device_id, int axis, float value)
+{
+ /* Android gives joy info normalized as [-1.0, 1.0] or [0.0, 1.0] */
+ SDL_joylist_item *item = JoystickByDeviceId(device_id);
+ if (item && item->joystick) {
+ SDL_PrivateJoystickAxis(item->joystick, axis, (Sint16) (32767.*value));
+ }
+
+ return 0;
+}
+
+int
+Android_OnHat(int device_id, int hat_id, int x, int y)
+{
+ const Uint8 position_map[3][3] = {
+ {SDL_HAT_LEFTUP, SDL_HAT_UP, SDL_HAT_RIGHTUP},
+ {SDL_HAT_LEFT, SDL_HAT_CENTERED, SDL_HAT_RIGHT},
+ {SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN}
+ };
+
+ if (x >= -1 && x <=1 && y >= -1 && y <= 1) {
+ SDL_joylist_item *item = JoystickByDeviceId(device_id);
+ if (item && item->joystick) {
+ SDL_PrivateJoystickHat(item->joystick, hat_id, position_map[y+1][x+1]);
+ }
+ return 0;
+ }
+
+ return -1;
+}
+
+
+int
+Android_AddJoystick(int device_id, const char *name, const char *desc, SDL_bool is_accelerometer, int nbuttons, int naxes, int nhats, int nballs)
+{
+ SDL_JoystickGUID guid;
+ SDL_joylist_item *item;
+
+ if (!SDL_GetHintBoolean(SDL_HINT_TV_REMOTE_AS_JOYSTICK, SDL_TRUE)) {
+ /* Ignore devices that aren't actually controllers (e.g. remotes), they'll be handled as keyboard input */
+ if (naxes < 2 && nhats < 1) {
+ return -1;
+ }
+ }
+
+ if (JoystickByDeviceId(device_id) != NULL || name == NULL) {
+ return -1;
+ }
+
+ /* the GUID is just the first 16 chars of the name for now */
+ SDL_zero(guid);
+ SDL_memcpy(&guid, desc, SDL_min(sizeof(guid), SDL_strlen(desc)));
+
+ item = (SDL_joylist_item *) SDL_malloc(sizeof (SDL_joylist_item));
+ if (item == NULL) {
+ return -1;
+ }
+
+ SDL_zerop(item);
+ item->guid = guid;
+ item->device_id = device_id;
+ item->name = SDL_strdup(name);
+ if (item->name == NULL) {
+ SDL_free(item);
+ return -1;
+ }
+
+ item->is_accelerometer = is_accelerometer;
+ if (nbuttons > -1) {
+ item->nbuttons = nbuttons;
+ }
+ else {
+ item->nbuttons = ANDROID_MAX_NBUTTONS;
+ }
+ item->naxes = naxes;
+ item->nhats = nhats;
+ item->nballs = nballs;
+ item->device_instance = instance_counter++;
+ if (SDL_joylist_tail == NULL) {
+ SDL_joylist = SDL_joylist_tail = item;
+ } else {
+ SDL_joylist_tail->next = item;
+ SDL_joylist_tail = item;
+ }
+
+ /* Need to increment the joystick count before we post the event */
+ ++numjoysticks;
+
+ SDL_PrivateJoystickAdded(numjoysticks - 1);
+
+#ifdef DEBUG_JOYSTICK
+ SDL_Log("Added joystick %s with device_id %d", name, device_id);
+#endif
+
+ return numjoysticks;
+}
+
+int
+Android_RemoveJoystick(int device_id)
+{
+ SDL_joylist_item *item = SDL_joylist;
+ SDL_joylist_item *prev = NULL;
+
+ /* Don't call JoystickByDeviceId here or there'll be an infinite loop! */
+ while (item != NULL) {
+ if (item->device_id == device_id) {
+ break;
+ }
+ prev = item;
+ item = item->next;
+ }
+
+ if (item == NULL) {
+ return -1;
+ }
+
+ if (item->joystick) {
+ item->joystick->hwdata = NULL;
+ }
+
+ if (prev != NULL) {
+ prev->next = item->next;
+ } else {
+ SDL_assert(SDL_joylist == item);
+ SDL_joylist = item->next;
+ }
+ if (item == SDL_joylist_tail) {
+ SDL_joylist_tail = prev;
+ }
+
+ /* Need to decrement the joystick count before we post the event */
+ --numjoysticks;
+
+ SDL_PrivateJoystickRemoved(item->device_instance);
+
+#ifdef DEBUG_JOYSTICK
+ SDL_Log("Removed joystick with device_id %d", device_id);
+#endif
+
+ SDL_free(item->name);
+ SDL_free(item);
+ return numjoysticks;
+}
+
+
+static SDL_bool SteamControllerConnectedCallback(const char *name, SDL_JoystickGUID guid, int *device_instance)
+{
+ SDL_joylist_item *item;
+
+ item = (SDL_joylist_item *)SDL_calloc(1, sizeof (SDL_joylist_item));
+ if (item == NULL) {
+ return SDL_FALSE;
+ }
+
+ *device_instance = item->device_instance = instance_counter++;
+ item->device_id = -1;
+ item->name = SDL_strdup(name);
+ item->guid = guid;
+ SDL_GetSteamControllerInputs(&item->nbuttons,
+ &item->naxes,
+ &item->nhats);
+ item->m_bSteamController = SDL_TRUE;
+
+ if (SDL_joylist_tail == NULL) {
+ SDL_joylist = SDL_joylist_tail = item;
+ } else {
+ SDL_joylist_tail->next = item;
+ SDL_joylist_tail = item;
+ }
+
+ /* Need to increment the joystick count before we post the event */
+ ++numjoysticks;
+
+ SDL_PrivateJoystickAdded(numjoysticks - 1);
+
+ return SDL_TRUE;
+}
+
+static void SteamControllerDisconnectedCallback(int device_instance)
+{
+ SDL_joylist_item *item = SDL_joylist;
+ SDL_joylist_item *prev = NULL;
+
+ while (item != NULL) {
+ if (item->device_instance == device_instance) {
+ break;
+ }
+ prev = item;
+ item = item->next;
+ }
+
+ if (item == NULL) {
+ return;
+ }
+
+ if (item->joystick) {
+ item->joystick->hwdata = NULL;
+ }
+
+ if (prev != NULL) {
+ prev->next = item->next;
+ } else {
+ SDL_assert(SDL_joylist == item);
+ SDL_joylist = item->next;
+ }
+ if (item == SDL_joylist_tail) {
+ SDL_joylist_tail = prev;
+ }
+
+ /* Need to decrement the joystick count before we post the event */
+ --numjoysticks;
+
+ SDL_PrivateJoystickRemoved(item->device_instance);
+
+ SDL_free(item->name);
+ SDL_free(item);
+}
+
+int
+SDL_SYS_JoystickInit(void)
+{
+ SDL_SYS_JoystickDetect();
+
+ if (SDL_GetHintBoolean(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_TRUE)) {
+ /* Default behavior, accelerometer as joystick */
+ Android_AddJoystick(ANDROID_ACCELEROMETER_DEVICE_ID, ANDROID_ACCELEROMETER_NAME, ANDROID_ACCELEROMETER_NAME, SDL_TRUE, 0, 3, 0, 0);
+ }
+
+ SDL_InitSteamControllers(SteamControllerConnectedCallback,
+ SteamControllerDisconnectedCallback);
+
+ return (numjoysticks);
+
+}
+
+int
+SDL_SYS_NumJoysticks(void)
+{
+ return numjoysticks;
+}
+
+void
+SDL_SYS_JoystickDetect(void)
+{
+ /* Support for device connect/disconnect is API >= 16 only,
+ * so we poll every three seconds
+ * Ref: http://developer.android.com/reference/android/hardware/input/InputManager.InputDeviceListener.html
+ */
+ static Uint32 timeout = 0;
+ if (!timeout || SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) {
+ timeout = SDL_GetTicks() + 3000;
+ Android_JNI_PollInputDevices();
+ }
+
+ SDL_UpdateSteamControllers();
+}
+
+static SDL_joylist_item *
+JoystickByDevIndex(int device_index)
+{
+ SDL_joylist_item *item = SDL_joylist;
+
+ if ((device_index < 0) || (device_index >= numjoysticks)) {
+ return NULL;
+ }
+
+ while (device_index > 0) {
+ SDL_assert(item != NULL);
+ device_index--;
+ item = item->next;
+ }
+
+ return item;
+}
+
+static SDL_joylist_item *
+JoystickByDeviceId(int device_id)
+{
+ SDL_joylist_item *item = SDL_joylist;
+
+ while (item != NULL) {
+ if (item->device_id == device_id) {
+ return item;
+ }
+ item = item->next;
+ }
+
+ /* Joystick not found, try adding it */
+ SDL_SYS_JoystickDetect();
+
+ while (item != NULL) {
+ if (item->device_id == device_id) {
+ return item;
+ }
+ item = item->next;
+ }
+
+ return NULL;
+}
+
+/* Function to get the device-dependent name of a joystick */
+const char *
+SDL_SYS_JoystickNameForDeviceIndex(int device_index)
+{
+ return JoystickByDevIndex(device_index)->name;
+}
+
+/* Function to perform the mapping from device index to the instance id for this index */
+SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
+{
+ return JoystickByDevIndex(device_index)->device_instance;
+}
+
+/* Function to open a joystick for use.
+ The joystick to open is specified by the device index.
+ This should fill the nbuttons and naxes fields of the joystick structure.
+ It returns 0, or -1 if there is an error.
+ */
+int
+SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
+{
+ SDL_joylist_item *item = JoystickByDevIndex(device_index);
+
+ if (item == NULL) {
+ return SDL_SetError("No such device");
+ }
+
+ if (item->joystick != NULL) {
+ return SDL_SetError("Joystick already opened");
+ }
+
+ joystick->instance_id = item->device_instance;
+ joystick->hwdata = (struct joystick_hwdata *) item;
+ item->joystick = joystick;
+ joystick->nhats = item->nhats;
+ joystick->nballs = item->nballs;
+ joystick->nbuttons = item->nbuttons;
+ joystick->naxes = item->naxes;
+
+ return (0);
+}
+
+/* Function to determine if this joystick is attached to the system right now */
+SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
+{
+ return joystick->hwdata != NULL;
+}
+
+void
+SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
+{
+ SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata;
+
+ if (item == NULL) {
+ return;
+ }
+
+ if (item->m_bSteamController) {
+ SDL_UpdateSteamController(joystick);
+ return;
+ }
+
+ if (item->is_accelerometer) {
+ int i;
+ Sint16 value;
+ float values[3];
+
+ if (Android_JNI_GetAccelerometerValues(values)) {
+ for (i = 0; i < 3; i++) {
+ if (values[i] > 1.0f) {
+ values[i] = 1.0f;
+ } else if (values[i] < -1.0f) {
+ values[i] = -1.0f;
+ }
+
+ value = (Sint16)(values[i] * 32767.0f);
+ SDL_PrivateJoystickAxis(item->joystick, i, value);
+ }
+ }
+ }
+}
+
+/* Function to close a joystick after use */
+void
+SDL_SYS_JoystickClose(SDL_Joystick * joystick)
+{
+ SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata;
+ if (item) {
+ item->joystick = NULL;
+ }
+}
+
+/* Function to perform any system-specific joystick related cleanup */
+void
+SDL_SYS_JoystickQuit(void)
+{
+/* We don't have any way to scan for joysticks at init, so don't wipe the list
+ * of joysticks here in case this is a reinit.
+ */
+#if 0
+ SDL_joylist_item *item = NULL;
+ SDL_joylist_item *next = NULL;
+
+ for (item = SDL_joylist; item; item = next) {
+ next = item->next;
+ SDL_free(item->name);
+ SDL_free(item);
+ }
+
+ SDL_joylist = SDL_joylist_tail = NULL;
+
+ numjoysticks = 0;
+ instance_counter = 0;
+#endif /* 0 */
+
+ SDL_QuitSteamControllers();
+}
+
+SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index)
+{
+ return JoystickByDevIndex(device_index)->guid;
+}
+
+SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
+{
+ SDL_JoystickGUID guid;
+
+ if (joystick->hwdata != NULL) {
+ return ((SDL_joylist_item*)joystick->hwdata)->guid;
+ }
+
+ SDL_zero(guid);
+ return guid;
+}
+
+SDL_bool SDL_SYS_IsDPAD_DeviceIndex(int device_index)
+{
+ return JoystickByDevIndex(device_index)->naxes == 0;
+}
+
+#endif /* SDL_JOYSTICK_ANDROID */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/android/SDL_sysjoystick_c.h b/src/3rdparty/SDL2/src/joystick/android/SDL_sysjoystick_c.h
new file mode 100644
index 0000000..c2cbc4e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/android/SDL_sysjoystick_c.h
@@ -0,0 +1,61 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifdef SDL_JOYSTICK_ANDROID
+
+#ifndef SDL_sysjoystick_c_h_
+#define SDL_sysjoystick_c_h_
+
+#include "../SDL_sysjoystick.h"
+
+extern int Android_OnPadDown(int device_id, int keycode);
+extern int Android_OnPadUp(int device_id, int keycode);
+extern int Android_OnJoy(int device_id, int axisnum, float value);
+extern int Android_OnHat(int device_id, int hat_id, int x, int y);
+extern int Android_AddJoystick(int device_id, const char *name, const char *desc, SDL_bool is_accelerometer, int nbuttons, int naxes, int nhats, int nballs);
+extern int Android_RemoveJoystick(int device_id);
+
+/* A linked list of available joysticks */
+typedef struct SDL_joylist_item
+{
+ int device_instance;
+ int device_id; /* Android's device id */
+ char *name; /* "SideWinder 3D Pro" or whatever */
+ SDL_JoystickGUID guid;
+ SDL_bool is_accelerometer;
+ SDL_Joystick *joystick;
+ int nbuttons, naxes, nhats, nballs;
+
+ /* Steam Controller support */
+ SDL_bool m_bSteamController;
+
+ struct SDL_joylist_item *next;
+} SDL_joylist_item;
+
+typedef SDL_joylist_item joystick_hwdata;
+
+#endif /* SDL_sysjoystick_c_h_ */
+
+#endif /* SDL_JOYSTICK_ANDROID */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/bsd/SDL_sysjoystick.c b/src/3rdparty/SDL2/src/joystick/bsd/SDL_sysjoystick.c
new file mode 100644
index 0000000..9408545
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/bsd/SDL_sysjoystick.c
@@ -0,0 +1,691 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_JOYSTICK_USBHID
+
+/*
+ * Joystick driver for the uhid(4) interface found in OpenBSD,
+ * NetBSD and FreeBSD.
+ *
+ * Maintainer: <vedge at csoft.org>
+ */
+
+#include <sys/param.h>
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#ifndef __FreeBSD_kernel_version
+#define __FreeBSD_kernel_version __FreeBSD_version
+#endif
+
+#if defined(HAVE_USB_H)
+#include <usb.h>
+#endif
+#ifdef __DragonFly__
+#include <bus/usb/usb.h>
+#include <bus/usb/usbhid.h>
+#else
+#include <dev/usb/usb.h>
+#include <dev/usb/usbhid.h>
+#endif
+
+#if defined(HAVE_USBHID_H)
+#include <usbhid.h>
+#elif defined(HAVE_LIBUSB_H)
+#include <libusb.h>
+#elif defined(HAVE_LIBUSBHID_H)
+#include <libusbhid.h>
+#endif
+
+#if defined(__FREEBSD__) || defined(__FreeBSD_kernel__)
+#ifndef __DragonFly__
+#include <osreldate.h>
+#endif
+#if __FreeBSD_kernel_version > 800063
+#include <dev/usb/usb_ioctl.h>
+#endif
+#include <sys/joystick.h>
+#endif
+
+#if SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
+#include <machine/joystick.h>
+#endif
+
+#include "SDL_joystick.h"
+#include "../SDL_sysjoystick.h"
+#include "../SDL_joystick_c.h"
+
+#define MAX_UHID_JOYS 64
+#define MAX_JOY_JOYS 2
+#define MAX_JOYS (MAX_UHID_JOYS + MAX_JOY_JOYS)
+
+
+struct report
+{
+#if defined(__FREEBSD__) && (__FreeBSD_kernel_version > 900000)
+ void *buf; /* Buffer */
+#elif defined(__FREEBSD__) && (__FreeBSD_kernel_version > 800063)
+ struct usb_gen_descriptor *buf; /* Buffer */
+#else
+ struct usb_ctl_report *buf; /* Buffer */
+#endif
+ size_t size; /* Buffer size */
+ int rid; /* Report ID */
+ enum
+ {
+ SREPORT_UNINIT,
+ SREPORT_CLEAN,
+ SREPORT_DIRTY
+ } status;
+};
+
+static struct
+{
+ int uhid_report;
+ hid_kind_t kind;
+ const char *name;
+} const repinfo[] = {
+ {UHID_INPUT_REPORT, hid_input, "input"},
+ {UHID_OUTPUT_REPORT, hid_output, "output"},
+ {UHID_FEATURE_REPORT, hid_feature, "feature"}
+};
+
+enum
+{
+ REPORT_INPUT = 0,
+ REPORT_OUTPUT = 1,
+ REPORT_FEATURE = 2
+};
+
+enum
+{
+ JOYAXE_X,
+ JOYAXE_Y,
+ JOYAXE_Z,
+ JOYAXE_SLIDER,
+ JOYAXE_WHEEL,
+ JOYAXE_RX,
+ JOYAXE_RY,
+ JOYAXE_RZ,
+ JOYAXE_count
+};
+
+struct joystick_hwdata
+{
+ int fd;
+ char *path;
+ enum
+ {
+ BSDJOY_UHID, /* uhid(4) */
+ BSDJOY_JOY /* joy(4) */
+ } type;
+ struct report_desc *repdesc;
+ struct report inreport;
+ int axis_map[JOYAXE_count]; /* map present JOYAXE_* to 0,1,.. */
+};
+
+static char *joynames[MAX_JOYS];
+static char *joydevnames[MAX_JOYS];
+
+static int report_alloc(struct report *, struct report_desc *, int);
+static void report_free(struct report *);
+
+#if defined(USBHID_UCR_DATA) || (defined(__FreeBSD_kernel__) && __FreeBSD_kernel_version <= 800063)
+#define REP_BUF_DATA(rep) ((rep)->buf->ucr_data)
+#elif (defined(__FREEBSD__) && (__FreeBSD_kernel_version > 900000))
+#define REP_BUF_DATA(rep) ((rep)->buf)
+#elif (defined(__FREEBSD__) && (__FreeBSD_kernel_version > 800063))
+#define REP_BUF_DATA(rep) ((rep)->buf->ugd_data)
+#else
+#define REP_BUF_DATA(rep) ((rep)->buf->data)
+#endif
+
+static int SDL_SYS_numjoysticks = 0;
+
+int
+SDL_SYS_JoystickInit(void)
+{
+ char s[16];
+ int i, fd;
+
+ SDL_SYS_numjoysticks = 0;
+
+ SDL_memset(joynames, 0, sizeof(joynames));
+ SDL_memset(joydevnames, 0, sizeof(joydevnames));
+
+ for (i = 0; i < MAX_UHID_JOYS; i++) {
+ SDL_Joystick nj;
+
+ SDL_snprintf(s, SDL_arraysize(s), "/dev/uhid%d", i);
+
+ joynames[SDL_SYS_numjoysticks] = SDL_strdup(s);
+
+ if (SDL_SYS_JoystickOpen(&nj, SDL_SYS_numjoysticks) == 0) {
+ SDL_SYS_JoystickClose(&nj);
+ SDL_SYS_numjoysticks++;
+ } else {
+ SDL_free(joynames[SDL_SYS_numjoysticks]);
+ joynames[SDL_SYS_numjoysticks] = NULL;
+ }
+ }
+ for (i = 0; i < MAX_JOY_JOYS; i++) {
+ SDL_snprintf(s, SDL_arraysize(s), "/dev/joy%d", i);
+ fd = open(s, O_RDONLY);
+ if (fd != -1) {
+ joynames[SDL_SYS_numjoysticks++] = SDL_strdup(s);
+ close(fd);
+ }
+ }
+
+ /* Read the default USB HID usage table. */
+ hid_init(NULL);
+
+ return (SDL_SYS_numjoysticks);
+}
+
+int
+SDL_SYS_NumJoysticks(void)
+{
+ return SDL_SYS_numjoysticks;
+}
+
+void
+SDL_SYS_JoystickDetect(void)
+{
+}
+
+const char *
+SDL_SYS_JoystickNameForDeviceIndex(int device_index)
+{
+ if (joydevnames[device_index] != NULL) {
+ return (joydevnames[device_index]);
+ }
+ return (joynames[device_index]);
+}
+
+/* Function to perform the mapping from device index to the instance id for this index */
+SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
+{
+ return device_index;
+}
+
+static int
+usage_to_joyaxe(unsigned usage)
+{
+ int joyaxe;
+ switch (usage) {
+ case HUG_X:
+ joyaxe = JOYAXE_X;
+ break;
+ case HUG_Y:
+ joyaxe = JOYAXE_Y;
+ break;
+ case HUG_Z:
+ joyaxe = JOYAXE_Z;
+ break;
+ case HUG_SLIDER:
+ joyaxe = JOYAXE_SLIDER;
+ break;
+ case HUG_WHEEL:
+ joyaxe = JOYAXE_WHEEL;
+ break;
+ case HUG_RX:
+ joyaxe = JOYAXE_RX;
+ break;
+ case HUG_RY:
+ joyaxe = JOYAXE_RY;
+ break;
+ case HUG_RZ:
+ joyaxe = JOYAXE_RZ;
+ break;
+ default:
+ joyaxe = -1;
+ }
+ return joyaxe;
+}
+
+static unsigned
+hatval_to_sdl(Sint32 hatval)
+{
+ static const unsigned hat_dir_map[8] = {
+ SDL_HAT_UP, SDL_HAT_RIGHTUP, SDL_HAT_RIGHT, SDL_HAT_RIGHTDOWN,
+ SDL_HAT_DOWN, SDL_HAT_LEFTDOWN, SDL_HAT_LEFT, SDL_HAT_LEFTUP
+ };
+ unsigned result;
+ if ((hatval & 7) == hatval)
+ result = hat_dir_map[hatval];
+ else
+ result = SDL_HAT_CENTERED;
+ return result;
+}
+
+
+int
+SDL_SYS_JoystickOpen(SDL_Joystick * joy, int device_index)
+{
+ char *path = joynames[device_index];
+ struct joystick_hwdata *hw;
+ struct hid_item hitem;
+ struct hid_data *hdata;
+ struct report *rep = NULL;
+ int fd;
+ int i;
+
+ fd = open(path, O_RDONLY);
+ if (fd == -1) {
+ return SDL_SetError("%s: %s", path, strerror(errno));
+ }
+
+ joy->instance_id = device_index;
+ hw = (struct joystick_hwdata *)
+ SDL_malloc(sizeof(struct joystick_hwdata));
+ if (hw == NULL) {
+ close(fd);
+ return SDL_OutOfMemory();
+ }
+ joy->hwdata = hw;
+ hw->fd = fd;
+ hw->path = SDL_strdup(path);
+ if (!SDL_strncmp(path, "/dev/joy", 8)) {
+ hw->type = BSDJOY_JOY;
+ joy->naxes = 2;
+ joy->nbuttons = 2;
+ joy->nhats = 0;
+ joy->nballs = 0;
+ joydevnames[device_index] = SDL_strdup("Gameport joystick");
+ goto usbend;
+ } else {
+ hw->type = BSDJOY_UHID;
+ }
+
+ {
+ int ax;
+ for (ax = 0; ax < JOYAXE_count; ax++)
+ hw->axis_map[ax] = -1;
+ }
+ hw->repdesc = hid_get_report_desc(fd);
+ if (hw->repdesc == NULL) {
+ SDL_SetError("%s: USB_GET_REPORT_DESC: %s", hw->path,
+ strerror(errno));
+ goto usberr;
+ }
+ rep = &hw->inreport;
+#if defined(__FREEBSD__) && (__FreeBSD_kernel_version > 800063) || defined(__FreeBSD_kernel__)
+ rep->rid = hid_get_report_id(fd);
+ if (rep->rid < 0) {
+#else
+ if (ioctl(fd, USB_GET_REPORT_ID, &rep->rid) < 0) {
+#endif
+ rep->rid = -1; /* XXX */
+ }
+#if defined(__NetBSD__)
+ usb_device_descriptor_t udd;
+ struct usb_string_desc usd;
+ if (ioctl(fd, USB_GET_DEVICE_DESC, &udd) == -1)
+ goto desc_failed;
+
+ /* Get default language */
+ usd.usd_string_index = USB_LANGUAGE_TABLE;
+ usd.usd_language_id = 0;
+ if (ioctl(fd, USB_GET_STRING_DESC, &usd) == -1 || usd.usd_desc.bLength < 4) {
+ usd.usd_language_id = 0;
+ } else {
+ usd.usd_language_id = UGETW(usd.usd_desc.bString[0]);
+ }
+
+ usd.usd_string_index = udd.iProduct;
+ if (ioctl(fd, USB_GET_STRING_DESC, &usd) == 0) {
+ char str[128];
+ char *new_name = NULL;
+ int i;
+ for (i = 0; i < (usd.usd_desc.bLength >> 1) - 1 && i < sizeof(str) - 1; i++) {
+ str[i] = UGETW(usd.usd_desc.bString[i]);
+ }
+ str[i] = '\0';
+ asprintf(&new_name, "%s @ %s", str, path);
+ if (new_name != NULL) {
+ SDL_free(joydevnames[SDL_SYS_numjoysticks]);
+ joydevnames[SDL_SYS_numjoysticks] = new_name;
+ }
+ }
+desc_failed:
+#endif
+ if (report_alloc(rep, hw->repdesc, REPORT_INPUT) < 0) {
+ goto usberr;
+ }
+ if (rep->size <= 0) {
+ SDL_SetError("%s: Input report descriptor has invalid length",
+ hw->path);
+ goto usberr;
+ }
+#if defined(USBHID_NEW) || (defined(__FREEBSD__) && __FreeBSD_kernel_version >= 500111) || defined(__FreeBSD_kernel__)
+ hdata = hid_start_parse(hw->repdesc, 1 << hid_input, rep->rid);
+#else
+ hdata = hid_start_parse(hw->repdesc, 1 << hid_input);
+#endif
+ if (hdata == NULL) {
+ SDL_SetError("%s: Cannot start HID parser", hw->path);
+ goto usberr;
+ }
+ joy->naxes = 0;
+ joy->nbuttons = 0;
+ joy->nhats = 0;
+ joy->nballs = 0;
+ for (i = 0; i < JOYAXE_count; i++)
+ hw->axis_map[i] = -1;
+
+ while (hid_get_item(hdata, &hitem) > 0) {
+ char *sp;
+ const char *s;
+
+ switch (hitem.kind) {
+ case hid_collection:
+ switch (HID_PAGE(hitem.usage)) {
+ case HUP_GENERIC_DESKTOP:
+ switch (HID_USAGE(hitem.usage)) {
+ case HUG_JOYSTICK:
+ case HUG_GAME_PAD:
+ s = hid_usage_in_page(hitem.usage);
+ sp = SDL_malloc(SDL_strlen(s) + 5);
+ SDL_snprintf(sp, SDL_strlen(s) + 5, "%s (%d)",
+ s, device_index);
+ joydevnames[device_index] = sp;
+ }
+ }
+ break;
+ case hid_input:
+ switch (HID_PAGE(hitem.usage)) {
+ case HUP_GENERIC_DESKTOP:
+ {
+ unsigned usage = HID_USAGE(hitem.usage);
+ int joyaxe = usage_to_joyaxe(usage);
+ if (joyaxe >= 0) {
+ hw->axis_map[joyaxe] = 1;
+ } else if (usage == HUG_HAT_SWITCH) {
+ joy->nhats++;
+ }
+ break;
+ }
+ case HUP_BUTTON:
+ joy->nbuttons++;
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ hid_end_parse(hdata);
+ for (i = 0; i < JOYAXE_count; i++)
+ if (hw->axis_map[i] > 0)
+ hw->axis_map[i] = joy->naxes++;
+
+ if (joy->naxes == 0 && joy->nbuttons == 0 && joy->nhats == 0 && joy->nballs == 0) {
+ SDL_SetError("%s: Not a joystick, ignoring", hw->path);
+ goto usberr;
+ }
+
+ usbend:
+ /* The poll blocks the event thread. */
+ fcntl(fd, F_SETFL, O_NONBLOCK);
+#ifdef __NetBSD__
+ /* Flush pending events */
+ if (rep) {
+ while (read(joy->hwdata->fd, REP_BUF_DATA(rep), rep->size) == rep->size)
+ ;
+ }
+#endif
+
+ return (0);
+ usberr:
+ close(hw->fd);
+ SDL_free(hw->path);
+ SDL_free(hw);
+ return (-1);
+}
+
+/* Function to determine if this joystick is attached to the system right now */
+SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
+{
+ return SDL_TRUE;
+}
+
+void
+SDL_SYS_JoystickUpdate(SDL_Joystick * joy)
+{
+ struct hid_item hitem;
+ struct hid_data *hdata;
+ struct report *rep;
+ int nbutton, naxe = -1;
+ Sint32 v;
+
+#if defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H || defined(__FreeBSD_kernel__)
+ struct joystick gameport;
+ static int x, y, xmin = 0xffff, ymin = 0xffff, xmax = 0, ymax = 0;
+
+ if (joy->hwdata->type == BSDJOY_JOY) {
+ while (read(joy->hwdata->fd, &gameport, sizeof gameport) == sizeof gameport) {
+ if (abs(x - gameport.x) > 8) {
+ x = gameport.x;
+ if (x < xmin) {
+ xmin = x;
+ }
+ if (x > xmax) {
+ xmax = x;
+ }
+ if (xmin == xmax) {
+ xmin--;
+ xmax++;
+ }
+ v = (Sint32) x;
+ v -= (xmax + xmin + 1) / 2;
+ v *= 32768 / ((xmax - xmin + 1) / 2);
+ SDL_PrivateJoystickAxis(joy, 0, v);
+ }
+ if (abs(y - gameport.y) > 8) {
+ y = gameport.y;
+ if (y < ymin) {
+ ymin = y;
+ }
+ if (y > ymax) {
+ ymax = y;
+ }
+ if (ymin == ymax) {
+ ymin--;
+ ymax++;
+ }
+ v = (Sint32) y;
+ v -= (ymax + ymin + 1) / 2;
+ v *= 32768 / ((ymax - ymin + 1) / 2);
+ SDL_PrivateJoystickAxis(joy, 1, v);
+ }
+ SDL_PrivateJoystickButton(joy, 0, gameport.b1);
+ SDL_PrivateJoystickButton(joy, 1, gameport.b2);
+ }
+ return;
+ }
+#endif /* defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H */
+
+ rep = &joy->hwdata->inreport;
+
+ while (read(joy->hwdata->fd, REP_BUF_DATA(rep), rep->size) == rep->size) {
+#if defined(USBHID_NEW) || (defined(__FREEBSD__) && __FreeBSD_kernel_version >= 500111) || defined(__FreeBSD_kernel__)
+ hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input, rep->rid);
+#else
+ hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input);
+#endif
+ if (hdata == NULL) {
+ /*fprintf(stderr, "%s: Cannot start HID parser\n", joy->hwdata->path);*/
+ continue;
+ }
+
+ for (nbutton = 0; hid_get_item(hdata, &hitem) > 0;) {
+ switch (hitem.kind) {
+ case hid_input:
+ switch (HID_PAGE(hitem.usage)) {
+ case HUP_GENERIC_DESKTOP:
+ {
+ unsigned usage = HID_USAGE(hitem.usage);
+ int joyaxe = usage_to_joyaxe(usage);
+ if (joyaxe >= 0) {
+ naxe = joy->hwdata->axis_map[joyaxe];
+ /* scaleaxe */
+ v = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
+ v -= (hitem.logical_maximum +
+ hitem.logical_minimum + 1) / 2;
+ v *= 32768 /
+ ((hitem.logical_maximum -
+ hitem.logical_minimum + 1) / 2);
+ SDL_PrivateJoystickAxis(joy, naxe, v);
+ } else if (usage == HUG_HAT_SWITCH) {
+ v = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
+ SDL_PrivateJoystickHat(joy, 0,
+ hatval_to_sdl(v) -
+ hitem.logical_minimum);
+ }
+ break;
+ }
+ case HUP_BUTTON:
+ v = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
+ SDL_PrivateJoystickButton(joy, nbutton, v);
+ nbutton++;
+ break;
+ default:
+ continue;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ hid_end_parse(hdata);
+ }
+}
+
+/* Function to close a joystick after use */
+void
+SDL_SYS_JoystickClose(SDL_Joystick * joy)
+{
+ if (SDL_strncmp(joy->hwdata->path, "/dev/joy", 8)) {
+ report_free(&joy->hwdata->inreport);
+ hid_dispose_report_desc(joy->hwdata->repdesc);
+ }
+ close(joy->hwdata->fd);
+ SDL_free(joy->hwdata->path);
+ SDL_free(joy->hwdata);
+}
+
+void
+SDL_SYS_JoystickQuit(void)
+{
+ int i;
+
+ for (i = 0; i < MAX_JOYS; i++) {
+ SDL_free(joynames[i]);
+ SDL_free(joydevnames[i]);
+ }
+
+ return;
+}
+
+SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
+{
+ SDL_JoystickGUID guid;
+ /* the GUID is just the first 16 chars of the name for now */
+ const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
+ SDL_zero( guid );
+ SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
+ return guid;
+}
+
+SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
+{
+ SDL_JoystickGUID guid;
+ /* the GUID is just the first 16 chars of the name for now */
+ const char *name = joystick->name;
+ SDL_zero( guid );
+ SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
+ return guid;
+}
+
+static int
+report_alloc(struct report *r, struct report_desc *rd, int repind)
+{
+ int len;
+
+#ifdef __DragonFly__
+ len = hid_report_size(rd, r->rid, repinfo[repind].kind);
+#elif __FREEBSD__
+# if (__FreeBSD_kernel_version >= 460000) || defined(__FreeBSD_kernel__)
+# if (__FreeBSD_kernel_version <= 500111)
+ len = hid_report_size(rd, r->rid, repinfo[repind].kind);
+# else
+ len = hid_report_size(rd, repinfo[repind].kind, r->rid);
+# endif
+# else
+ len = hid_report_size(rd, repinfo[repind].kind, &r->rid);
+# endif
+#else
+# ifdef USBHID_NEW
+ len = hid_report_size(rd, repinfo[repind].kind, r->rid);
+# else
+ len = hid_report_size(rd, repinfo[repind].kind, &r->rid);
+# endif
+#endif
+
+ if (len < 0) {
+ return SDL_SetError("Negative HID report size");
+ }
+ r->size = len;
+
+ if (r->size > 0) {
+#if defined(__FREEBSD__) && (__FreeBSD_kernel_version > 900000)
+ r->buf = SDL_malloc(r->size);
+#else
+ r->buf = SDL_malloc(sizeof(*r->buf) - sizeof(REP_BUF_DATA(r)) +
+ r->size);
+#endif
+ if (r->buf == NULL) {
+ return SDL_OutOfMemory();
+ }
+ } else {
+ r->buf = NULL;
+ }
+
+ r->status = SREPORT_CLEAN;
+ return 0;
+}
+
+static void
+report_free(struct report *r)
+{
+ SDL_free(r->buf);
+ r->status = SREPORT_UNINIT;
+}
+
+#endif /* SDL_JOYSTICK_USBHID */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/darwin/SDL_sysjoystick.c b/src/3rdparty/SDL2/src/joystick/darwin/SDL_sysjoystick.c
new file mode 100644
index 0000000..abfb1c6
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/darwin/SDL_sysjoystick.c
@@ -0,0 +1,837 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_JOYSTICK_IOKIT
+
+#include <IOKit/hid/IOHIDLib.h>
+
+/* For force feedback testing. */
+#include <ForceFeedback/ForceFeedback.h>
+#include <ForceFeedback/ForceFeedbackConstants.h>
+
+#include "SDL_joystick.h"
+#include "../SDL_sysjoystick.h"
+#include "../SDL_joystick_c.h"
+#include "SDL_sysjoystick_c.h"
+#include "SDL_events.h"
+#include "../../haptic/darwin/SDL_syshaptic_c.h" /* For haptic hot plugging */
+
+#define SDL_JOYSTICK_RUNLOOP_MODE CFSTR("SDLJoystick")
+
+/* The base object of the HID Manager API */
+static IOHIDManagerRef hidman = NULL;
+
+/* Linked list of all available devices */
+static recDevice *gpDeviceList = NULL;
+
+/* static incrementing counter for new joystick devices seen on the system. Devices should start with index 0 */
+static int s_joystick_instance_id = -1;
+
+static recDevice *GetDeviceForIndex(int device_index)
+{
+ recDevice *device = gpDeviceList;
+ while (device) {
+ if (!device->removed) {
+ if (device_index == 0)
+ break;
+
+ --device_index;
+ }
+ device = device->pNext;
+ }
+ return device;
+}
+
+static void
+FreeElementList(recElement *pElement)
+{
+ while (pElement) {
+ recElement *pElementNext = pElement->pNext;
+ SDL_free(pElement);
+ pElement = pElementNext;
+ }
+}
+
+static recDevice *
+FreeDevice(recDevice *removeDevice)
+{
+ recDevice *pDeviceNext = NULL;
+ if (removeDevice) {
+ if (removeDevice->deviceRef) {
+ IOHIDDeviceUnscheduleFromRunLoop(removeDevice->deviceRef, CFRunLoopGetCurrent(), SDL_JOYSTICK_RUNLOOP_MODE);
+ removeDevice->deviceRef = NULL;
+ }
+
+ /* save next device prior to disposing of this device */
+ pDeviceNext = removeDevice->pNext;
+
+ if ( gpDeviceList == removeDevice ) {
+ gpDeviceList = pDeviceNext;
+ } else {
+ recDevice *device = gpDeviceList;
+ while (device->pNext != removeDevice) {
+ device = device->pNext;
+ }
+ device->pNext = pDeviceNext;
+ }
+ removeDevice->pNext = NULL;
+
+ /* free element lists */
+ FreeElementList(removeDevice->firstAxis);
+ FreeElementList(removeDevice->firstButton);
+ FreeElementList(removeDevice->firstHat);
+
+ SDL_free(removeDevice);
+ }
+ return pDeviceNext;
+}
+
+static SDL_bool
+GetHIDElementState(recDevice *pDevice, recElement *pElement, SInt32 *pValue)
+{
+ SInt32 value = 0;
+ int returnValue = SDL_FALSE;
+
+ if (pDevice && pElement) {
+ IOHIDValueRef valueRef;
+ if (IOHIDDeviceGetValue(pDevice->deviceRef, pElement->elementRef, &valueRef) == kIOReturnSuccess) {
+ value = (SInt32) IOHIDValueGetIntegerValue(valueRef);
+
+ /* record min and max for auto calibration */
+ if (value < pElement->minReport) {
+ pElement->minReport = value;
+ }
+ if (value > pElement->maxReport) {
+ pElement->maxReport = value;
+ }
+ *pValue = value;
+
+ returnValue = SDL_TRUE;
+ }
+ }
+ return returnValue;
+}
+
+static SDL_bool
+GetHIDScaledCalibratedState(recDevice * pDevice, recElement * pElement, SInt32 min, SInt32 max, SInt32 *pValue)
+{
+ const float deviceScale = max - min;
+ const float readScale = pElement->maxReport - pElement->minReport;
+ int returnValue = SDL_FALSE;
+ if (GetHIDElementState(pDevice, pElement, pValue))
+ {
+ if (readScale == 0) {
+ returnValue = SDL_TRUE; /* no scaling at all */
+ }
+ else
+ {
+ *pValue = ((*pValue - pElement->minReport) * deviceScale / readScale) + min;
+ returnValue = SDL_TRUE;
+ }
+ }
+ return returnValue;
+}
+
+static void
+JoystickDeviceWasRemovedCallback(void *ctx, IOReturn result, void *sender)
+{
+ recDevice *device = (recDevice *) ctx;
+ device->removed = SDL_TRUE;
+ device->deviceRef = NULL; // deviceRef was invalidated due to the remove
+#if SDL_HAPTIC_IOKIT
+ MacHaptic_MaybeRemoveDevice(device->ffservice);
+#endif
+
+ SDL_PrivateJoystickRemoved(device->instance_id);
+}
+
+
+static void AddHIDElement(const void *value, void *parameter);
+
+/* Call AddHIDElement() on all elements in an array of IOHIDElementRefs */
+static void
+AddHIDElements(CFArrayRef array, recDevice *pDevice)
+{
+ const CFRange range = { 0, CFArrayGetCount(array) };
+ CFArrayApplyFunction(array, range, AddHIDElement, pDevice);
+}
+
+static SDL_bool
+ElementAlreadyAdded(const IOHIDElementCookie cookie, const recElement *listitem) {
+ while (listitem) {
+ if (listitem->cookie == cookie) {
+ return SDL_TRUE;
+ }
+ listitem = listitem->pNext;
+ }
+ return SDL_FALSE;
+}
+
+/* See if we care about this HID element, and if so, note it in our recDevice. */
+static void
+AddHIDElement(const void *value, void *parameter)
+{
+ recDevice *pDevice = (recDevice *) parameter;
+ IOHIDElementRef refElement = (IOHIDElementRef) value;
+ const CFTypeID elementTypeID = refElement ? CFGetTypeID(refElement) : 0;
+
+ if (refElement && (elementTypeID == IOHIDElementGetTypeID())) {
+ const IOHIDElementCookie cookie = IOHIDElementGetCookie(refElement);
+ const uint32_t usagePage = IOHIDElementGetUsagePage(refElement);
+ const uint32_t usage = IOHIDElementGetUsage(refElement);
+ recElement *element = NULL;
+ recElement **headElement = NULL;
+
+ /* look at types of interest */
+ switch (IOHIDElementGetType(refElement)) {
+ case kIOHIDElementTypeInput_Misc:
+ case kIOHIDElementTypeInput_Button:
+ case kIOHIDElementTypeInput_Axis: {
+ switch (usagePage) { /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */
+ case kHIDPage_GenericDesktop:
+ switch (usage) {
+ case kHIDUsage_GD_X:
+ case kHIDUsage_GD_Y:
+ case kHIDUsage_GD_Z:
+ case kHIDUsage_GD_Rx:
+ case kHIDUsage_GD_Ry:
+ case kHIDUsage_GD_Rz:
+ case kHIDUsage_GD_Slider:
+ case kHIDUsage_GD_Dial:
+ case kHIDUsage_GD_Wheel:
+ if (!ElementAlreadyAdded(cookie, pDevice->firstAxis)) {
+ element = (recElement *) SDL_calloc(1, sizeof (recElement));
+ if (element) {
+ pDevice->axes++;
+ headElement = &(pDevice->firstAxis);
+ }
+ }
+ break;
+
+ case kHIDUsage_GD_Hatswitch:
+ if (!ElementAlreadyAdded(cookie, pDevice->firstHat)) {
+ element = (recElement *) SDL_calloc(1, sizeof (recElement));
+ if (element) {
+ pDevice->hats++;
+ headElement = &(pDevice->firstHat);
+ }
+ }
+ break;
+ case kHIDUsage_GD_DPadUp:
+ case kHIDUsage_GD_DPadDown:
+ case kHIDUsage_GD_DPadRight:
+ case kHIDUsage_GD_DPadLeft:
+ case kHIDUsage_GD_Start:
+ case kHIDUsage_GD_Select:
+ case kHIDUsage_GD_SystemMainMenu:
+ if (!ElementAlreadyAdded(cookie, pDevice->firstButton)) {
+ element = (recElement *) SDL_calloc(1, sizeof (recElement));
+ if (element) {
+ pDevice->buttons++;
+ headElement = &(pDevice->firstButton);
+ }
+ }
+ break;
+ }
+ break;
+
+ case kHIDPage_Simulation:
+ switch (usage) {
+ case kHIDUsage_Sim_Rudder:
+ case kHIDUsage_Sim_Throttle:
+ case kHIDUsage_Sim_Accelerator:
+ case kHIDUsage_Sim_Brake:
+ if (!ElementAlreadyAdded(cookie, pDevice->firstAxis)) {
+ element = (recElement *) SDL_calloc(1, sizeof (recElement));
+ if (element) {
+ pDevice->axes++;
+ headElement = &(pDevice->firstAxis);
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case kHIDPage_Button:
+ case kHIDPage_Consumer: /* e.g. 'pause' button on Steelseries MFi gamepads. */
+ if (!ElementAlreadyAdded(cookie, pDevice->firstButton)) {
+ element = (recElement *) SDL_calloc(1, sizeof (recElement));
+ if (element) {
+ pDevice->buttons++;
+ headElement = &(pDevice->firstButton);
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+ break;
+
+ case kIOHIDElementTypeCollection: {
+ CFArrayRef array = IOHIDElementGetChildren(refElement);
+ if (array) {
+ AddHIDElements(array, pDevice);
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ if (element && headElement) { /* add to list */
+ recElement *elementPrevious = NULL;
+ recElement *elementCurrent = *headElement;
+ while (elementCurrent && usage >= elementCurrent->usage) {
+ elementPrevious = elementCurrent;
+ elementCurrent = elementCurrent->pNext;
+ }
+ if (elementPrevious) {
+ elementPrevious->pNext = element;
+ } else {
+ *headElement = element;
+ }
+
+ element->elementRef = refElement;
+ element->usagePage = usagePage;
+ element->usage = usage;
+ element->pNext = elementCurrent;
+
+ element->minReport = element->min = (SInt32) IOHIDElementGetLogicalMin(refElement);
+ element->maxReport = element->max = (SInt32) IOHIDElementGetLogicalMax(refElement);
+ element->cookie = IOHIDElementGetCookie(refElement);
+
+ pDevice->elements++;
+ }
+ }
+}
+
+static SDL_bool
+GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice)
+{
+ const Uint16 BUS_USB = 0x03;
+ const Uint16 BUS_BLUETOOTH = 0x05;
+ Sint32 vendor = 0;
+ Sint32 product = 0;
+ Sint32 version = 0;
+ CFTypeRef refCF = NULL;
+ CFArrayRef array = NULL;
+ Uint16 *guid16 = (Uint16 *)pDevice->guid.data;
+
+ /* get usage page and usage */
+ refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDPrimaryUsagePageKey));
+ if (refCF) {
+ CFNumberGetValue(refCF, kCFNumberSInt32Type, &pDevice->usagePage);
+ }
+ if (pDevice->usagePage != kHIDPage_GenericDesktop) {
+ return SDL_FALSE; /* Filter device list to non-keyboard/mouse stuff */
+ }
+
+ refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDPrimaryUsageKey));
+ if (refCF) {
+ CFNumberGetValue(refCF, kCFNumberSInt32Type, &pDevice->usage);
+ }
+
+ if ((pDevice->usage != kHIDUsage_GD_Joystick &&
+ pDevice->usage != kHIDUsage_GD_GamePad &&
+ pDevice->usage != kHIDUsage_GD_MultiAxisController)) {
+ return SDL_FALSE; /* Filter device list to non-keyboard/mouse stuff */
+ }
+
+ pDevice->deviceRef = hidDevice;
+
+ /* get device name */
+ refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDProductKey));
+ if (!refCF) {
+ /* Maybe we can't get "AwesomeJoystick2000", but we can get "Logitech"? */
+ refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDManufacturerKey));
+ }
+ if ((!refCF) || (!CFStringGetCString(refCF, pDevice->product, sizeof (pDevice->product), kCFStringEncodingUTF8))) {
+ SDL_strlcpy(pDevice->product, "Unidentified joystick", sizeof (pDevice->product));
+ }
+
+ refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDVendorIDKey));
+ if (refCF) {
+ CFNumberGetValue(refCF, kCFNumberSInt32Type, &vendor);
+ }
+
+ refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDProductIDKey));
+ if (refCF) {
+ CFNumberGetValue(refCF, kCFNumberSInt32Type, &product);
+ }
+
+ refCF = IOHIDDeviceGetProperty(hidDevice, CFSTR(kIOHIDVersionNumberKey));
+ if (refCF) {
+ CFNumberGetValue(refCF, kCFNumberSInt32Type, &version);
+ }
+
+ SDL_memset(pDevice->guid.data, 0, sizeof(pDevice->guid.data));
+
+ if (vendor && product) {
+ *guid16++ = SDL_SwapLE16(BUS_USB);
+ *guid16++ = 0;
+ *guid16++ = SDL_SwapLE16((Uint16)vendor);
+ *guid16++ = 0;
+ *guid16++ = SDL_SwapLE16((Uint16)product);
+ *guid16++ = 0;
+ *guid16++ = SDL_SwapLE16((Uint16)version);
+ *guid16++ = 0;
+ } else {
+ *guid16++ = SDL_SwapLE16(BUS_BLUETOOTH);
+ *guid16++ = 0;
+ SDL_strlcpy((char*)guid16, pDevice->product, sizeof(pDevice->guid.data) - 4);
+ }
+
+ array = IOHIDDeviceCopyMatchingElements(hidDevice, NULL, kIOHIDOptionsTypeNone);
+ if (array) {
+ AddHIDElements(array, pDevice);
+ CFRelease(array);
+ }
+
+ return SDL_TRUE;
+}
+
+static SDL_bool
+JoystickAlreadyKnown(IOHIDDeviceRef ioHIDDeviceObject)
+{
+ recDevice *i;
+ for (i = gpDeviceList; i != NULL; i = i->pNext) {
+ if (i->deviceRef == ioHIDDeviceObject) {
+ return SDL_TRUE;
+ }
+ }
+ return SDL_FALSE;
+}
+
+
+static void
+JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDeviceRef ioHIDDeviceObject)
+{
+ recDevice *device;
+ int device_index = 0;
+ io_service_t ioservice;
+
+ if (res != kIOReturnSuccess) {
+ return;
+ }
+
+ if (JoystickAlreadyKnown(ioHIDDeviceObject)) {
+ return; /* IOKit sent us a duplicate. */
+ }
+
+ device = (recDevice *) SDL_calloc(1, sizeof(recDevice));
+
+ if (!device) {
+ SDL_OutOfMemory();
+ return;
+ }
+
+ if (!GetDeviceInfo(ioHIDDeviceObject, device)) {
+ SDL_free(device);
+ return; /* not a device we care about, probably. */
+ }
+
+ if (SDL_IsGameControllerNameAndGUID(device->product, device->guid) &&
+ SDL_ShouldIgnoreGameController(device->product, device->guid)) {
+ SDL_free(device);
+ return;
+ }
+
+ /* Get notified when this device is disconnected. */
+ IOHIDDeviceRegisterRemovalCallback(ioHIDDeviceObject, JoystickDeviceWasRemovedCallback, device);
+ IOHIDDeviceScheduleWithRunLoop(ioHIDDeviceObject, CFRunLoopGetCurrent(), SDL_JOYSTICK_RUNLOOP_MODE);
+
+ /* Allocate an instance ID for this device */
+ device->instance_id = ++s_joystick_instance_id;
+
+ /* We have to do some storage of the io_service_t for SDL_HapticOpenFromJoystick */
+ ioservice = IOHIDDeviceGetService(ioHIDDeviceObject);
+#if SDL_HAPTIC_IOKIT
+ if ((ioservice) && (FFIsForceFeedback(ioservice) == FF_OK)) {
+ device->ffservice = ioservice;
+ MacHaptic_MaybeAddDevice(ioservice);
+ }
+#endif
+
+ /* Add device to the end of the list */
+ if ( !gpDeviceList ) {
+ gpDeviceList = device;
+ } else {
+ recDevice *curdevice;
+
+ curdevice = gpDeviceList;
+ while ( curdevice->pNext ) {
+ ++device_index;
+ curdevice = curdevice->pNext;
+ }
+ curdevice->pNext = device;
+ ++device_index; /* bump by one since we counted by pNext. */
+ }
+
+ SDL_PrivateJoystickAdded(device_index);
+}
+
+static SDL_bool
+ConfigHIDManager(CFArrayRef matchingArray)
+{
+ CFRunLoopRef runloop = CFRunLoopGetCurrent();
+
+ if (IOHIDManagerOpen(hidman, kIOHIDOptionsTypeNone) != kIOReturnSuccess) {
+ return SDL_FALSE;
+ }
+
+ IOHIDManagerSetDeviceMatchingMultiple(hidman, matchingArray);
+ IOHIDManagerRegisterDeviceMatchingCallback(hidman, JoystickDeviceWasAddedCallback, NULL);
+ IOHIDManagerScheduleWithRunLoop(hidman, runloop, SDL_JOYSTICK_RUNLOOP_MODE);
+
+ while (CFRunLoopRunInMode(SDL_JOYSTICK_RUNLOOP_MODE,0,TRUE) == kCFRunLoopRunHandledSource) {
+ /* no-op. Callback fires once per existing device. */
+ }
+
+ /* future hotplug events will come through SDL_JOYSTICK_RUNLOOP_MODE now. */
+
+ return SDL_TRUE; /* good to go. */
+}
+
+
+static CFDictionaryRef
+CreateHIDDeviceMatchDictionary(const UInt32 page, const UInt32 usage, int *okay)
+{
+ CFDictionaryRef retval = NULL;
+ CFNumberRef pageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page);
+ CFNumberRef usageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage);
+ const void *keys[2] = { (void *) CFSTR(kIOHIDDeviceUsagePageKey), (void *) CFSTR(kIOHIDDeviceUsageKey) };
+ const void *vals[2] = { (void *) pageNumRef, (void *) usageNumRef };
+
+ if (pageNumRef && usageNumRef) {
+ retval = CFDictionaryCreate(kCFAllocatorDefault, keys, vals, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+ }
+
+ if (pageNumRef) {
+ CFRelease(pageNumRef);
+ }
+ if (usageNumRef) {
+ CFRelease(usageNumRef);
+ }
+
+ if (!retval) {
+ *okay = 0;
+ }
+
+ return retval;
+}
+
+static SDL_bool
+CreateHIDManager(void)
+{
+ SDL_bool retval = SDL_FALSE;
+ int okay = 1;
+ const void *vals[] = {
+ (void *) CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick, &okay),
+ (void *) CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad, &okay),
+ (void *) CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_MultiAxisController, &okay),
+ };
+ const size_t numElements = SDL_arraysize(vals);
+ CFArrayRef array = okay ? CFArrayCreate(kCFAllocatorDefault, vals, numElements, &kCFTypeArrayCallBacks) : NULL;
+ size_t i;
+
+ for (i = 0; i < numElements; i++) {
+ if (vals[i]) {
+ CFRelease((CFTypeRef) vals[i]);
+ }
+ }
+
+ if (array) {
+ hidman = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
+ if (hidman != NULL) {
+ retval = ConfigHIDManager(array);
+ }
+ CFRelease(array);
+ }
+
+ return retval;
+}
+
+
+/* Function to scan the system for joysticks.
+ * Joystick 0 should be the system default joystick.
+ * This function should return the number of available joysticks, or -1
+ * on an unrecoverable fatal error.
+ */
+int
+SDL_SYS_JoystickInit(void)
+{
+ if (gpDeviceList) {
+ return SDL_SetError("Joystick: Device list already inited.");
+ }
+
+ if (!CreateHIDManager()) {
+ return SDL_SetError("Joystick: Couldn't initialize HID Manager");
+ }
+
+ return SDL_SYS_NumJoysticks();
+}
+
+/* Function to return the number of joystick devices plugged in right now */
+int
+SDL_SYS_NumJoysticks(void)
+{
+ recDevice *device = gpDeviceList;
+ int nJoySticks = 0;
+
+ while (device) {
+ if (!device->removed) {
+ nJoySticks++;
+ }
+ device = device->pNext;
+ }
+
+ return nJoySticks;
+}
+
+/* Function to cause any queued joystick insertions to be processed
+ */
+void
+SDL_SYS_JoystickDetect(void)
+{
+ recDevice *device = gpDeviceList;
+ while (device) {
+ if (device->removed) {
+ device = FreeDevice(device);
+ } else {
+ device = device->pNext;
+ }
+ }
+
+ /* run this after the checks above so we don't set device->removed and delete the device before
+ SDL_SYS_JoystickUpdate can run to clean up the SDL_Joystick object that owns this device */
+ while (CFRunLoopRunInMode(SDL_JOYSTICK_RUNLOOP_MODE,0,TRUE) == kCFRunLoopRunHandledSource) {
+ /* no-op. Pending callbacks will fire in CFRunLoopRunInMode(). */
+ }
+}
+
+/* Function to get the device-dependent name of a joystick */
+const char *
+SDL_SYS_JoystickNameForDeviceIndex(int device_index)
+{
+ recDevice *device = GetDeviceForIndex(device_index);
+ return device ? device->product : "UNKNOWN";
+}
+
+/* Function to return the instance id of the joystick at device_index
+ */
+SDL_JoystickID
+SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
+{
+ recDevice *device = GetDeviceForIndex(device_index);
+ return device ? device->instance_id : 0;
+}
+
+/* Function to open a joystick for use.
+ * The joystick to open is specified by the device index.
+ * This should fill the nbuttons and naxes fields of the joystick structure.
+ * It returns 0, or -1 if there is an error.
+ */
+int
+SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
+{
+ recDevice *device = GetDeviceForIndex(device_index);
+
+ joystick->instance_id = device->instance_id;
+ joystick->hwdata = device;
+ joystick->name = device->product;
+
+ joystick->naxes = device->axes;
+ joystick->nhats = device->hats;
+ joystick->nballs = 0;
+ joystick->nbuttons = device->buttons;
+ return 0;
+}
+
+/* Function to query if the joystick is currently attached
+ * It returns SDL_TRUE if attached, SDL_FALSE otherwise.
+ */
+SDL_bool
+SDL_SYS_JoystickAttached(SDL_Joystick * joystick)
+{
+ return joystick->hwdata != NULL;
+}
+
+/* Function to update the state of a joystick - called as a device poll.
+ * This function shouldn't update the joystick structure directly,
+ * but instead should call SDL_PrivateJoystick*() to deliver events
+ * and update joystick device state.
+ */
+void
+SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
+{
+ recDevice *device = joystick->hwdata;
+ recElement *element;
+ SInt32 value, range;
+ int i;
+
+ if (!device) {
+ return;
+ }
+
+ if (device->removed) { /* device was unplugged; ignore it. */
+ if (joystick->hwdata) {
+ joystick->force_recentering = SDL_TRUE;
+ joystick->hwdata = NULL;
+ }
+ return;
+ }
+
+ element = device->firstAxis;
+ i = 0;
+
+ int goodRead = SDL_FALSE;
+ while (element) {
+ goodRead = GetHIDScaledCalibratedState(device, element, -32768, 32767, &value);
+ if (goodRead) {
+ SDL_PrivateJoystickAxis(joystick, i, value);
+ }
+
+ element = element->pNext;
+ ++i;
+ }
+
+ element = device->firstButton;
+ i = 0;
+ while (element) {
+ goodRead = GetHIDElementState(device, element, &value);
+ if (goodRead) {
+ if (value > 1) { /* handle pressure-sensitive buttons */
+ value = 1;
+ }
+ SDL_PrivateJoystickButton(joystick, i, value);
+ }
+
+ element = element->pNext;
+ ++i;
+ }
+
+ element = device->firstHat;
+ i = 0;
+
+ while (element) {
+ Uint8 pos = 0;
+
+ range = (element->max - element->min + 1);
+ goodRead = GetHIDElementState(device, element, &value);
+ if (goodRead) {
+ value -= element->min;
+ if (range == 4) { /* 4 position hatswitch - scale up value */
+ value *= 2;
+ } else if (range != 8) { /* Neither a 4 nor 8 positions - fall back to default position (centered) */
+ value = -1;
+ }
+ switch (value) {
+ case 0:
+ pos = SDL_HAT_UP;
+ break;
+ case 1:
+ pos = SDL_HAT_RIGHTUP;
+ break;
+ case 2:
+ pos = SDL_HAT_RIGHT;
+ break;
+ case 3:
+ pos = SDL_HAT_RIGHTDOWN;
+ break;
+ case 4:
+ pos = SDL_HAT_DOWN;
+ break;
+ case 5:
+ pos = SDL_HAT_LEFTDOWN;
+ break;
+ case 6:
+ pos = SDL_HAT_LEFT;
+ break;
+ case 7:
+ pos = SDL_HAT_LEFTUP;
+ break;
+ default:
+ /* Every other value is mapped to center. We do that because some
+ * joysticks use 8 and some 15 for this value, and apparently
+ * there are even more variants out there - so we try to be generous.
+ */
+ pos = SDL_HAT_CENTERED;
+ break;
+ }
+
+ SDL_PrivateJoystickHat(joystick, i, pos);
+ }
+
+ element = element->pNext;
+ ++i;
+ }
+}
+
+/* Function to close a joystick after use */
+void
+SDL_SYS_JoystickClose(SDL_Joystick * joystick)
+{
+}
+
+/* Function to perform any system-specific joystick related cleanup */
+void
+SDL_SYS_JoystickQuit(void)
+{
+ while (FreeDevice(gpDeviceList)) {
+ /* spin */
+ }
+
+ if (hidman) {
+ IOHIDManagerUnscheduleFromRunLoop(hidman, CFRunLoopGetCurrent(), SDL_JOYSTICK_RUNLOOP_MODE);
+ IOHIDManagerClose(hidman, kIOHIDOptionsTypeNone);
+ CFRelease(hidman);
+ hidman = NULL;
+ }
+}
+
+
+SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
+{
+ recDevice *device = GetDeviceForIndex(device_index);
+ SDL_JoystickGUID guid;
+ if (device) {
+ guid = device->guid;
+ } else {
+ SDL_zero(guid);
+ }
+ return guid;
+}
+
+SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
+{
+ return joystick->hwdata->guid;
+}
+
+#endif /* SDL_JOYSTICK_IOKIT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/darwin/SDL_sysjoystick_c.h b/src/3rdparty/SDL2/src/joystick/darwin/SDL_sysjoystick_c.h
new file mode 100644
index 0000000..cde6a5c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/darwin/SDL_sysjoystick_c.h
@@ -0,0 +1,73 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_JOYSTICK_IOKIT_H
+#define SDL_JOYSTICK_IOKIT_H
+
+#include <IOKit/hid/IOHIDLib.h>
+
+struct recElement
+{
+ IOHIDElementRef elementRef;
+ IOHIDElementCookie cookie;
+ uint32_t usagePage, usage; /* HID usage */
+ SInt32 min; /* reported min value possible */
+ SInt32 max; /* reported max value possible */
+
+ /* runtime variables used for auto-calibration */
+ SInt32 minReport; /* min returned value */
+ SInt32 maxReport; /* max returned value */
+
+ struct recElement *pNext; /* next element in list */
+};
+typedef struct recElement recElement;
+
+struct joystick_hwdata
+{
+ IOHIDDeviceRef deviceRef; /* HIDManager device handle */
+ io_service_t ffservice; /* Interface for force feedback, 0 = no ff */
+
+ char product[256]; /* name of product */
+ uint32_t usage; /* usage page from IOUSBHID Parser.h which defines general usage */
+ uint32_t usagePage; /* usage within above page from IOUSBHID Parser.h which defines specific usage */
+
+ int axes; /* number of axis (calculated, not reported by device) */
+ int buttons; /* number of buttons (calculated, not reported by device) */
+ int hats; /* number of hat switches (calculated, not reported by device) */
+ int elements; /* number of total elements (should be total of above) (calculated, not reported by device) */
+
+ recElement *firstAxis;
+ recElement *firstButton;
+ recElement *firstHat;
+
+ SDL_bool removed;
+
+ int instance_id;
+ SDL_JoystickGUID guid;
+
+ struct joystick_hwdata *pNext; /* next device */
+};
+typedef struct joystick_hwdata recDevice;
+
+#endif /* SDL_JOYSTICK_IOKIT_H */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/dummy/SDL_sysjoystick.c b/src/3rdparty/SDL2/src/joystick/dummy/SDL_sysjoystick.c
new file mode 100644
index 0000000..3dd96a0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/dummy/SDL_sysjoystick.c
@@ -0,0 +1,127 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if defined(SDL_JOYSTICK_DUMMY) || defined(SDL_JOYSTICK_DISABLED)
+
+/* This is the dummy implementation of the SDL joystick API */
+
+#include "SDL_joystick.h"
+#include "../SDL_sysjoystick.h"
+#include "../SDL_joystick_c.h"
+
+/* Function to scan the system for joysticks.
+ * It should return 0, or -1 on an unrecoverable fatal error.
+ */
+int
+SDL_SYS_JoystickInit(void)
+{
+ return 0;
+}
+
+int
+SDL_SYS_NumJoysticks(void)
+{
+ return 0;
+}
+
+void
+SDL_SYS_JoystickDetect(void)
+{
+}
+
+/* Function to get the device-dependent name of a joystick */
+const char *
+SDL_SYS_JoystickNameForDeviceIndex(int device_index)
+{
+ SDL_SetError("Logic error: No joysticks available");
+ return (NULL);
+}
+
+/* Function to perform the mapping from device index to the instance id for this index */
+SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
+{
+ return device_index;
+}
+
+/* Function to open a joystick for use.
+ The joystick to open is specified by the device index.
+ This should fill the nbuttons and naxes fields of the joystick structure.
+ It returns 0, or -1 if there is an error.
+ */
+int
+SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
+{
+ return SDL_SetError("Logic error: No joysticks available");
+}
+
+/* Function to determine if this joystick is attached to the system right now */
+SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
+{
+ return SDL_TRUE;
+}
+
+/* Function to update the state of a joystick - called as a device poll.
+ * This function shouldn't update the joystick structure directly,
+ * but instead should call SDL_PrivateJoystick*() to deliver events
+ * and update joystick device state.
+ */
+void
+SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
+{
+}
+
+/* Function to close a joystick after use */
+void
+SDL_SYS_JoystickClose(SDL_Joystick * joystick)
+{
+}
+
+/* Function to perform any system-specific joystick related cleanup */
+void
+SDL_SYS_JoystickQuit(void)
+{
+}
+
+SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
+{
+ SDL_JoystickGUID guid;
+ /* the GUID is just the first 16 chars of the name for now */
+ const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
+ SDL_zero( guid );
+ SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
+ return guid;
+}
+
+
+SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
+{
+ SDL_JoystickGUID guid;
+ /* the GUID is just the first 16 chars of the name for now */
+ const char *name = joystick->name;
+ SDL_zero( guid );
+ SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
+ return guid;
+}
+
+#endif /* SDL_JOYSTICK_DUMMY || SDL_JOYSTICK_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/emscripten/SDL_sysjoystick.c b/src/3rdparty/SDL2/src/joystick/emscripten/SDL_sysjoystick.c
new file mode 100644
index 0000000..b5bcaad
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/emscripten/SDL_sysjoystick.c
@@ -0,0 +1,403 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifdef SDL_JOYSTICK_EMSCRIPTEN
+
+#include <stdio.h> /* For the definition of NULL */
+#include "SDL_error.h"
+#include "SDL_events.h"
+
+#include "SDL_joystick.h"
+#include "SDL_assert.h"
+#include "SDL_timer.h"
+#include "SDL_log.h"
+#include "SDL_sysjoystick_c.h"
+#include "../SDL_joystick_c.h"
+
+static SDL_joylist_item * JoystickByIndex(int index);
+
+static SDL_joylist_item *SDL_joylist = NULL;
+static SDL_joylist_item *SDL_joylist_tail = NULL;
+static int numjoysticks = 0;
+static int instance_counter = 0;
+
+static EM_BOOL
+Emscripten_JoyStickConnected(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData)
+{
+ int i;
+
+ SDL_joylist_item *item;
+
+ if (JoystickByIndex(gamepadEvent->index) != NULL) {
+ return 1;
+ }
+
+ item = (SDL_joylist_item *) SDL_malloc(sizeof (SDL_joylist_item));
+ if (item == NULL) {
+ return 1;
+ }
+
+ SDL_zerop(item);
+ item->index = gamepadEvent->index;
+
+ item->name = SDL_strdup(gamepadEvent->id);
+ if ( item->name == NULL ) {
+ SDL_free(item);
+ return 1;
+ }
+
+ item->mapping = SDL_strdup(gamepadEvent->mapping);
+ if ( item->mapping == NULL ) {
+ SDL_free(item->name);
+ SDL_free(item);
+ return 1;
+ }
+
+ item->naxes = gamepadEvent->numAxes;
+ item->nbuttons = gamepadEvent->numButtons;
+ item->device_instance = instance_counter++;
+
+ item->timestamp = gamepadEvent->timestamp;
+
+ for( i = 0; i < item->naxes; i++) {
+ item->axis[i] = gamepadEvent->axis[i];
+ }
+
+ for( i = 0; i < item->nbuttons; i++) {
+ item->analogButton[i] = gamepadEvent->analogButton[i];
+ item->digitalButton[i] = gamepadEvent->digitalButton[i];
+ }
+
+ if (SDL_joylist_tail == NULL) {
+ SDL_joylist = SDL_joylist_tail = item;
+ } else {
+ SDL_joylist_tail->next = item;
+ SDL_joylist_tail = item;
+ }
+
+ ++numjoysticks;
+
+ SDL_PrivateJoystickAdded(numjoysticks - 1);
+
+#ifdef DEBUG_JOYSTICK
+ SDL_Log("Number of joysticks is %d", numjoysticks);
+#endif
+
+#ifdef DEBUG_JOYSTICK
+ SDL_Log("Added joystick with index %d", item->index);
+#endif
+
+ return 1;
+}
+
+static EM_BOOL
+Emscripten_JoyStickDisconnected(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData)
+{
+ SDL_joylist_item *item = SDL_joylist;
+ SDL_joylist_item *prev = NULL;
+
+ while (item != NULL) {
+ if (item->index == gamepadEvent->index) {
+ break;
+ }
+ prev = item;
+ item = item->next;
+ }
+
+ if (item == NULL) {
+ return 1;
+ }
+
+ if (item->joystick) {
+ item->joystick->hwdata = NULL;
+ }
+
+ if (prev != NULL) {
+ prev->next = item->next;
+ } else {
+ SDL_assert(SDL_joylist == item);
+ SDL_joylist = item->next;
+ }
+ if (item == SDL_joylist_tail) {
+ SDL_joylist_tail = prev;
+ }
+
+ /* Need to decrement the joystick count before we post the event */
+ --numjoysticks;
+
+ SDL_PrivateJoystickRemoved(item->device_instance);
+
+#ifdef DEBUG_JOYSTICK
+ SDL_Log("Removed joystick with id %d", item->device_instance);
+#endif
+ SDL_free(item->name);
+ SDL_free(item->mapping);
+ SDL_free(item);
+ return 1;
+}
+
+/* Function to scan the system for joysticks.
+ * It should return 0, or -1 on an unrecoverable fatal error.
+ */
+int
+SDL_SYS_JoystickInit(void)
+{
+ int retval, i, numjs;
+ EmscriptenGamepadEvent gamepadState;
+
+ numjoysticks = 0;
+ numjs = emscripten_get_num_gamepads();
+
+ /* Check if gamepad is supported by browser */
+ if (numjs == EMSCRIPTEN_RESULT_NOT_SUPPORTED) {
+ return SDL_SetError("Gamepads not supported");
+ }
+
+ /* handle already connected gamepads */
+ if (numjs > 0) {
+ for(i = 0; i < numjs; i++) {
+ retval = emscripten_get_gamepad_status(i, &gamepadState);
+ if (retval == EMSCRIPTEN_RESULT_SUCCESS) {
+ Emscripten_JoyStickConnected(EMSCRIPTEN_EVENT_GAMEPADCONNECTED,
+ &gamepadState,
+ NULL);
+ }
+ }
+ }
+
+ retval = emscripten_set_gamepadconnected_callback(NULL,
+ 0,
+ Emscripten_JoyStickConnected);
+
+ if(retval != EMSCRIPTEN_RESULT_SUCCESS) {
+ SDL_SYS_JoystickQuit();
+ return SDL_SetError("Could not set gamepad connect callback");
+ }
+
+ retval = emscripten_set_gamepaddisconnected_callback(NULL,
+ 0,
+ Emscripten_JoyStickDisconnected);
+ if(retval != EMSCRIPTEN_RESULT_SUCCESS) {
+ SDL_SYS_JoystickQuit();
+ return SDL_SetError("Could not set gamepad disconnect callback");
+ }
+
+ return 0;
+}
+
+/* Returns item matching given SDL device index. */
+static SDL_joylist_item *
+JoystickByDeviceIndex(int device_index)
+{
+ SDL_joylist_item *item = SDL_joylist;
+
+ while (0 < device_index) {
+ --device_index;
+ item = item->next;
+ }
+
+ return item;
+}
+
+/* Returns item matching given HTML gamepad index. */
+static SDL_joylist_item *
+JoystickByIndex(int index)
+{
+ SDL_joylist_item *item = SDL_joylist;
+
+ if (index < 0) {
+ return NULL;
+ }
+
+ while (item != NULL) {
+ if (item->index == index) {
+ break;
+ }
+ item = item->next;
+ }
+
+ return item;
+}
+
+int
+SDL_SYS_NumJoysticks(void)
+{
+ return numjoysticks;
+}
+
+void
+SDL_SYS_JoystickDetect(void)
+{
+}
+
+/* Function to get the device-dependent name of a joystick */
+const char *
+SDL_SYS_JoystickNameForDeviceIndex(int device_index)
+{
+ return JoystickByDeviceIndex(device_index)->name;
+}
+
+/* Function to perform the mapping from device index to the instance id for this index */
+SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
+{
+ return JoystickByDeviceIndex(device_index)->device_instance;
+}
+
+/* Function to open a joystick for use.
+ The joystick to open is specified by the device index.
+ This should fill the nbuttons and naxes fields of the joystick structure.
+ It returns 0, or -1 if there is an error.
+ */
+int
+SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
+{
+ SDL_joylist_item *item = JoystickByDeviceIndex(device_index);
+
+ if (item == NULL ) {
+ return SDL_SetError("No such device");
+ }
+
+ if (item->joystick != NULL) {
+ return SDL_SetError("Joystick already opened");
+ }
+
+ joystick->instance_id = item->device_instance;
+ joystick->hwdata = (struct joystick_hwdata *) item;
+ item->joystick = joystick;
+
+ /* HTML5 Gamepad API doesn't say anything about these */
+ joystick->nhats = 0;
+ joystick->nballs = 0;
+
+ joystick->nbuttons = item->nbuttons;
+ joystick->naxes = item->naxes;
+
+ return (0);
+}
+
+/* Function to determine if this joystick is attached to the system right now */
+SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
+{
+ return joystick->hwdata != NULL;
+}
+
+/* Function to update the state of a joystick - called as a device poll.
+ * This function shouldn't update the joystick structure directly,
+ * but instead should call SDL_PrivateJoystick*() to deliver events
+ * and update joystick device state.
+ */
+void
+SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
+{
+ EmscriptenGamepadEvent gamepadState;
+ SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata;
+ int i, result, buttonState;
+
+ if (item) {
+ result = emscripten_get_gamepad_status(item->index, &gamepadState);
+ if( result == EMSCRIPTEN_RESULT_SUCCESS) {
+ if(gamepadState.timestamp == 0 || gamepadState.timestamp != item->timestamp) {
+ for(i = 0; i < item->nbuttons; i++) {
+ if(item->digitalButton[i] != gamepadState.digitalButton[i]) {
+ buttonState = gamepadState.digitalButton[i]? SDL_PRESSED: SDL_RELEASED;
+ SDL_PrivateJoystickButton(item->joystick, i, buttonState);
+ }
+
+ /* store values to compare them in the next update */
+ item->analogButton[i] = gamepadState.analogButton[i];
+ item->digitalButton[i] = gamepadState.digitalButton[i];
+ }
+
+ for(i = 0; i < item->naxes; i++) {
+ if(item->axis[i] != gamepadState.axis[i]) {
+ /* do we need to do conversion? */
+ SDL_PrivateJoystickAxis(item->joystick, i,
+ (Sint16) (32767.*gamepadState.axis[i]));
+ }
+
+ /* store to compare in next update */
+ item->axis[i] = gamepadState.axis[i];
+ }
+
+ item->timestamp = gamepadState.timestamp;
+ }
+ }
+ }
+}
+
+/* Function to close a joystick after use */
+void
+SDL_SYS_JoystickClose(SDL_Joystick * joystick)
+{
+ SDL_joylist_item *item = (SDL_joylist_item *) joystick->hwdata;
+ if (item) {
+ item->joystick = NULL;
+ }
+}
+
+/* Function to perform any system-specific joystick related cleanup */
+void
+SDL_SYS_JoystickQuit(void)
+{
+ SDL_joylist_item *item = NULL;
+ SDL_joylist_item *next = NULL;
+
+ for (item = SDL_joylist; item; item = next) {
+ next = item->next;
+ SDL_free(item->mapping);
+ SDL_free(item->name);
+ SDL_free(item);
+ }
+
+ SDL_joylist = SDL_joylist_tail = NULL;
+
+ numjoysticks = 0;
+ instance_counter = 0;
+
+ emscripten_set_gamepadconnected_callback(NULL, 0, NULL);
+ emscripten_set_gamepaddisconnected_callback(NULL, 0, NULL);
+}
+
+SDL_JoystickGUID
+SDL_SYS_JoystickGetDeviceGUID(int device_index)
+{
+ SDL_JoystickGUID guid;
+ /* the GUID is just the first 16 chars of the name for now */
+ const char *name = SDL_SYS_JoystickNameForDeviceIndex(device_index);
+ SDL_zero(guid);
+ SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
+ return guid;
+}
+
+SDL_JoystickGUID
+SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
+{
+ SDL_JoystickGUID guid;
+ /* the GUID is just the first 16 chars of the name for now */
+ const char *name = joystick->name;
+ SDL_zero(guid);
+ SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
+ return guid;
+}
+
+#endif /* SDL_JOYSTICK_EMSCRIPTEN */
diff --git a/src/3rdparty/SDL2/src/joystick/emscripten/SDL_sysjoystick_c.h b/src/3rdparty/SDL2/src/joystick/emscripten/SDL_sysjoystick_c.h
new file mode 100644
index 0000000..0c2be1d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/emscripten/SDL_sysjoystick_c.h
@@ -0,0 +1,52 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifdef SDL_JOYSTICK_EMSCRIPTEN
+#include "../SDL_sysjoystick.h"
+
+
+#include <emscripten/html5.h>
+
+/* A linked list of available joysticks */
+typedef struct SDL_joylist_item
+{
+ int index;
+ char *name;
+ char *mapping;
+ SDL_JoystickID device_instance;
+ SDL_Joystick *joystick;
+ int nbuttons;
+ int naxes;
+ double timestamp;
+ double axis[64];
+ double analogButton[64];
+ EM_BOOL digitalButton[64];
+
+ struct SDL_joylist_item *next;
+} SDL_joylist_item;
+
+typedef SDL_joylist_item joystick_hwdata;
+
+#endif /* SDL_JOYSTICK_EMSCRIPTEN */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/haiku/SDL_haikujoystick.cc b/src/3rdparty/SDL2/src/joystick/haiku/SDL_haikujoystick.cc
new file mode 100644
index 0000000..9ab2c72
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/haiku/SDL_haikujoystick.cc
@@ -0,0 +1,266 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_JOYSTICK_HAIKU
+
+/* This is the Haiku implementation of the SDL joystick API */
+
+#include <support/String.h>
+#include <device/Joystick.h>
+
+extern "C"
+{
+
+#include "SDL_joystick.h"
+#include "../SDL_sysjoystick.h"
+#include "../SDL_joystick_c.h"
+
+
+/* The maximum number of joysticks we'll detect */
+#define MAX_JOYSTICKS 16
+
+/* A list of available joysticks */
+ static char *SDL_joyport[MAX_JOYSTICKS];
+ static char *SDL_joyname[MAX_JOYSTICKS];
+
+/* The private structure used to keep track of a joystick */
+ struct joystick_hwdata
+ {
+ BJoystick *stick;
+ uint8 *new_hats;
+ int16 *new_axes;
+ };
+
+ static int SDL_SYS_numjoysticks = 0;
+
+/* Function to scan the system for joysticks.
+ * Joystick 0 should be the system default joystick.
+ * It should return 0, or -1 on an unrecoverable fatal error.
+ */
+ int SDL_SYS_JoystickInit(void)
+ {
+ BJoystick joystick;
+ int i;
+ int32 nports;
+ char name[B_OS_NAME_LENGTH];
+
+ /* Search for attached joysticks */
+ nports = joystick.CountDevices();
+ SDL_SYS_numjoysticks = 0;
+ SDL_memset(SDL_joyport, 0, (sizeof SDL_joyport));
+ SDL_memset(SDL_joyname, 0, (sizeof SDL_joyname));
+ for (i = 0; (SDL_SYS_numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i)
+ {
+ if (joystick.GetDeviceName(i, name) == B_OK) {
+ if (joystick.Open(name) != B_ERROR) {
+ BString stick_name;
+ joystick.GetControllerName(&stick_name);
+ SDL_joyport[SDL_SYS_numjoysticks] = SDL_strdup(name);
+ SDL_joyname[SDL_SYS_numjoysticks] = SDL_strdup(stick_name.String());
+ SDL_SYS_numjoysticks++;
+ joystick.Close();
+ }
+ }
+ }
+ return (SDL_SYS_numjoysticks);
+ }
+
+ int SDL_SYS_NumJoysticks(void)
+ {
+ return SDL_SYS_numjoysticks;
+ }
+
+ void SDL_SYS_JoystickDetect(void)
+ {
+ }
+
+/* Function to get the device-dependent name of a joystick */
+ const char *SDL_SYS_JoystickNameForDeviceIndex(int device_index)
+ {
+ return SDL_joyname[device_index];
+ }
+
+/* Function to perform the mapping from device index to the instance id for this index */
+ SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
+ {
+ return device_index;
+ }
+
+/* Function to open a joystick for use.
+ The joystick to open is specified by the device index.
+ This should fill the nbuttons and naxes fields of the joystick structure.
+ It returns 0, or -1 if there is an error.
+ */
+ int SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
+ {
+ BJoystick *stick;
+
+ /* Create the joystick data structure */
+ joystick->instance_id = device_index;
+ joystick->hwdata = (struct joystick_hwdata *)
+ SDL_malloc(sizeof(*joystick->hwdata));
+ if (joystick->hwdata == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
+ stick = new BJoystick;
+ joystick->hwdata->stick = stick;
+
+ /* Open the requested joystick for use */
+ if (stick->Open(SDL_joyport[device_index]) == B_ERROR) {
+ SDL_SYS_JoystickClose(joystick);
+ return SDL_SetError("Unable to open joystick");
+ }
+
+ /* Set the joystick to calibrated mode */
+ stick->EnableCalibration();
+
+ /* Get the number of buttons, hats, and axes on the joystick */
+ joystick->nbuttons = stick->CountButtons();
+ joystick->naxes = stick->CountAxes();
+ joystick->nhats = stick->CountHats();
+
+ joystick->hwdata->new_axes = (int16 *)
+ SDL_malloc(joystick->naxes * sizeof(int16));
+ joystick->hwdata->new_hats = (uint8 *)
+ SDL_malloc(joystick->nhats * sizeof(uint8));
+ if (!joystick->hwdata->new_hats || !joystick->hwdata->new_axes) {
+ SDL_SYS_JoystickClose(joystick);
+ return SDL_OutOfMemory();
+ }
+
+ /* We're done! */
+ return (0);
+ }
+
+/* Function to determine if this joystick is attached to the system right now */
+ SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
+ {
+ return SDL_TRUE;
+ }
+
+/* Function to update the state of a joystick - called as a device poll.
+ * This function shouldn't update the joystick structure directly,
+ * but instead should call SDL_PrivateJoystick*() to deliver events
+ * and update joystick device state.
+ */
+ void SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
+ {
+ static const Uint8 hat_map[9] = {
+ SDL_HAT_CENTERED,
+ SDL_HAT_UP,
+ SDL_HAT_RIGHTUP,
+ SDL_HAT_RIGHT,
+ SDL_HAT_RIGHTDOWN,
+ SDL_HAT_DOWN,
+ SDL_HAT_LEFTDOWN,
+ SDL_HAT_LEFT,
+ SDL_HAT_LEFTUP
+ };
+
+ BJoystick *stick;
+ int i;
+ int16 *axes;
+ uint8 *hats;
+ uint32 buttons;
+
+ /* Set up data pointers */
+ stick = joystick->hwdata->stick;
+ axes = joystick->hwdata->new_axes;
+ hats = joystick->hwdata->new_hats;
+
+ /* Get the new joystick state */
+ stick->Update();
+ stick->GetAxisValues(axes);
+ stick->GetHatValues(hats);
+ buttons = stick->ButtonValues();
+
+ /* Generate axis motion events */
+ for (i = 0; i < joystick->naxes; ++i) {
+ SDL_PrivateJoystickAxis(joystick, i, axes[i]);
+ }
+
+ /* Generate hat change events */
+ for (i = 0; i < joystick->nhats; ++i) {
+ SDL_PrivateJoystickHat(joystick, i, hat_map[hats[i]]);
+ }
+
+ /* Generate button events */
+ for (i = 0; i < joystick->nbuttons; ++i) {
+ SDL_PrivateJoystickButton(joystick, i, (buttons & 0x01));
+ buttons >>= 1;
+ }
+ }
+
+/* Function to close a joystick after use */
+ void SDL_SYS_JoystickClose(SDL_Joystick * joystick)
+ {
+ if (joystick->hwdata) {
+ joystick->hwdata->stick->Close();
+ delete joystick->hwdata->stick;
+ SDL_free(joystick->hwdata->new_hats);
+ SDL_free(joystick->hwdata->new_axes);
+ SDL_free(joystick->hwdata);
+ }
+ }
+
+/* Function to perform any system-specific joystick related cleanup */
+ void SDL_SYS_JoystickQuit(void)
+ {
+ int i;
+
+ for (i = 0; i < SDL_SYS_numjoysticks; ++i) {
+ SDL_free(SDL_joyport[i]);
+ }
+ SDL_joyport[0] = NULL;
+
+ for (i = 0; i < SDL_SYS_numjoysticks; ++i) {
+ SDL_free(SDL_joyname[i]);
+ }
+ SDL_joyname[0] = NULL;
+ }
+
+ SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
+ {
+ SDL_JoystickGUID guid;
+ /* the GUID is just the first 16 chars of the name for now */
+ const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
+ SDL_zero( guid );
+ SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
+ return guid;
+ }
+
+ SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
+ {
+ SDL_JoystickGUID guid;
+ /* the GUID is just the first 16 chars of the name for now */
+ const char *name = joystick->name;
+ SDL_zero( guid );
+ SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
+ return guid;
+ }
+
+}; // extern "C"
+
+#endif /* SDL_JOYSTICK_HAIKU */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/iphoneos/SDL_sysjoystick.m b/src/3rdparty/SDL2/src/joystick/iphoneos/SDL_sysjoystick.m
new file mode 100644
index 0000000..d601498
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/iphoneos/SDL_sysjoystick.m
@@ -0,0 +1,795 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+/* This is the iOS implementation of the SDL joystick API */
+#include "SDL_sysjoystick_c.h"
+
+/* needed for SDL_IPHONE_MAX_GFORCE macro */
+#include "SDL_config_iphoneos.h"
+
+#include "SDL_assert.h"
+#include "SDL_events.h"
+#include "SDL_joystick.h"
+#include "SDL_hints.h"
+#include "SDL_stdinc.h"
+#include "../SDL_sysjoystick.h"
+#include "../SDL_joystick_c.h"
+#include "../steam/SDL_steamcontroller.h"
+
+
+#if !SDL_EVENTS_DISABLED
+#include "../../events/SDL_events_c.h"
+#endif
+
+#if !TARGET_OS_TV
+#import <CoreMotion/CoreMotion.h>
+#endif
+
+#ifdef SDL_JOYSTICK_MFI
+#import <GameController/GameController.h>
+
+static id connectObserver = nil;
+static id disconnectObserver = nil;
+#endif /* SDL_JOYSTICK_MFI */
+
+#if !TARGET_OS_TV
+static const char *accelerometerName = "iOS Accelerometer";
+static CMMotionManager *motionManager = nil;
+#endif /* !TARGET_OS_TV */
+
+static SDL_JoystickDeviceItem *deviceList = NULL;
+
+static int numjoysticks = 0;
+static SDL_JoystickID instancecounter = 0;
+int SDL_AppleTVRemoteOpenedAsJoystick = 0;
+
+static SDL_JoystickDeviceItem *
+GetDeviceForIndex(int device_index)
+{
+ SDL_JoystickDeviceItem *device = deviceList;
+ int i = 0;
+
+ while (i < device_index) {
+ if (device == NULL) {
+ return NULL;
+ }
+ device = device->next;
+ i++;
+ }
+
+ return device;
+}
+
+static void
+SDL_SYS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCController *controller)
+{
+#ifdef SDL_JOYSTICK_MFI
+ const char *name = NULL;
+ /* Explicitly retain the controller because SDL_JoystickDeviceItem is a
+ * struct, and ARC doesn't work with structs. */
+ device->controller = (__bridge GCController *) CFBridgingRetain(controller);
+
+ if (controller.vendorName) {
+ name = controller.vendorName.UTF8String;
+ }
+
+ if (!name) {
+ name = "MFi Gamepad";
+ }
+
+ device->name = SDL_strdup(name);
+
+ device->guid.data[0] = 'M';
+ device->guid.data[1] = 'F';
+ device->guid.data[2] = 'i';
+ device->guid.data[3] = 'G';
+ device->guid.data[4] = 'a';
+ device->guid.data[5] = 'm';
+ device->guid.data[6] = 'e';
+ device->guid.data[7] = 'p';
+ device->guid.data[8] = 'a';
+ device->guid.data[9] = 'd';
+
+ if (controller.extendedGamepad) {
+ device->guid.data[10] = 1;
+ } else if (controller.gamepad) {
+ device->guid.data[10] = 2;
+ }
+#if TARGET_OS_TV
+ else if (controller.microGamepad) {
+ device->guid.data[10] = 3;
+ device->remote = SDL_TRUE;
+ }
+#endif /* TARGET_OS_TV */
+
+ if (controller.extendedGamepad) {
+ device->naxes = 6; /* 2 thumbsticks and 2 triggers */
+ device->nhats = 1; /* d-pad */
+ device->nbuttons = 7; /* ABXY, shoulder buttons, pause button */
+ } else if (controller.gamepad) {
+ device->naxes = 0; /* no traditional analog inputs */
+ device->nhats = 1; /* d-pad */
+ device->nbuttons = 7; /* ABXY, shoulder buttons, pause button */
+ }
+#if TARGET_OS_TV
+ else if (controller.microGamepad) {
+ device->naxes = 2; /* treat the touch surface as two axes */
+ device->nhats = 0; /* apparently the touch surface-as-dpad is buggy */
+ device->nbuttons = 3; /* AX, pause button */
+
+ controller.microGamepad.allowsRotation = SDL_GetHintBoolean(SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION, SDL_FALSE);
+ }
+#endif /* TARGET_OS_TV */
+
+ /* This will be set when the first button press of the controller is
+ * detected. */
+ controller.playerIndex = -1;
+
+#endif /* SDL_JOYSTICK_MFI */
+}
+
+static void
+SDL_SYS_AddJoystickDevice(GCController *controller, SDL_bool accelerometer)
+{
+ SDL_JoystickDeviceItem *device = deviceList;
+
+#if TARGET_OS_TV
+ if (!SDL_GetHintBoolean(SDL_HINT_TV_REMOTE_AS_JOYSTICK, SDL_TRUE)) {
+ /* Ignore devices that aren't actually controllers (e.g. remotes), they'll be handled as keyboard input */
+ if (controller && !controller.extendedGamepad && !controller.gamepad && controller.microGamepad) {
+ return;
+ }
+ }
+#endif
+
+ while (device != NULL) {
+ if (device->controller == controller) {
+ return;
+ }
+ device = device->next;
+ }
+
+ device = (SDL_JoystickDeviceItem *) SDL_calloc(1, sizeof(SDL_JoystickDeviceItem));
+ if (device == NULL) {
+ return;
+ }
+
+ device->accelerometer = accelerometer;
+ device->instance_id = instancecounter++;
+
+ if (accelerometer) {
+#if TARGET_OS_TV
+ SDL_free(device);
+ return;
+#else
+ device->name = SDL_strdup(accelerometerName);
+ device->naxes = 3; /* Device acceleration in the x, y, and z axes. */
+ device->nhats = 0;
+ device->nbuttons = 0;
+
+ /* Use the accelerometer name as a GUID. */
+ SDL_memcpy(&device->guid.data, device->name, SDL_min(sizeof(SDL_JoystickGUID), SDL_strlen(device->name)));
+#endif /* TARGET_OS_TV */
+ } else if (controller) {
+ SDL_SYS_AddMFIJoystickDevice(device, controller);
+ }
+
+ if (deviceList == NULL) {
+ deviceList = device;
+ } else {
+ SDL_JoystickDeviceItem *lastdevice = deviceList;
+ while (lastdevice->next != NULL) {
+ lastdevice = lastdevice->next;
+ }
+ lastdevice->next = device;
+ }
+
+ ++numjoysticks;
+
+ SDL_PrivateJoystickAdded(numjoysticks - 1);
+}
+
+static SDL_JoystickDeviceItem *
+SDL_SYS_RemoveJoystickDevice(SDL_JoystickDeviceItem *device)
+{
+ SDL_JoystickDeviceItem *prev = NULL;
+ SDL_JoystickDeviceItem *next = NULL;
+ SDL_JoystickDeviceItem *item = deviceList;
+
+ if (device == NULL) {
+ return NULL;
+ }
+
+ next = device->next;
+
+ while (item != NULL) {
+ if (item == device) {
+ break;
+ }
+ prev = item;
+ item = item->next;
+ }
+
+ /* Unlink the device item from the device list. */
+ if (prev) {
+ prev->next = device->next;
+ } else if (device == deviceList) {
+ deviceList = device->next;
+ }
+
+ if (device->joystick) {
+ device->joystick->hwdata = NULL;
+ }
+
+#ifdef SDL_JOYSTICK_MFI
+ @autoreleasepool {
+ if (device->controller) {
+ /* The controller was explicitly retained in the struct, so it
+ * should be explicitly released before freeing the struct. */
+ GCController *controller = CFBridgingRelease((__bridge CFTypeRef)(device->controller));
+ controller.controllerPausedHandler = nil;
+ device->controller = nil;
+ }
+ }
+#endif /* SDL_JOYSTICK_MFI */
+
+ --numjoysticks;
+
+ SDL_PrivateJoystickRemoved(device->instance_id);
+
+ SDL_free(device->name);
+ SDL_free(device);
+
+ return next;
+}
+
+#if TARGET_OS_TV
+static void SDLCALL
+SDL_AppleTVRemoteRotationHintChanged(void *udata, const char *name, const char *oldValue, const char *newValue)
+{
+ BOOL allowRotation = newValue != NULL && *newValue != '0';
+
+ @autoreleasepool {
+ for (GCController *controller in [GCController controllers]) {
+ if (controller.microGamepad) {
+ controller.microGamepad.allowsRotation = allowRotation;
+ }
+ }
+ }
+}
+#endif /* TARGET_OS_TV */
+
+static SDL_bool SteamControllerConnectedCallback(const char *name, SDL_JoystickGUID guid, int *device_instance)
+{
+ SDL_JoystickDeviceItem *device = (SDL_JoystickDeviceItem *)SDL_calloc(1, sizeof(SDL_JoystickDeviceItem));
+ if (device == NULL) {
+ return SDL_FALSE;
+ }
+
+ *device_instance = device->instance_id = instancecounter++;
+ device->name = SDL_strdup(name);
+ device->guid = guid;
+ SDL_GetSteamControllerInputs(&device->nbuttons,
+ &device->naxes,
+ &device->nhats);
+ device->m_bSteamController = SDL_TRUE;
+
+ if (deviceList == NULL) {
+ deviceList = device;
+ } else {
+ SDL_JoystickDeviceItem *lastdevice = deviceList;
+ while (lastdevice->next != NULL) {
+ lastdevice = lastdevice->next;
+ }
+ lastdevice->next = device;
+ }
+
+ ++numjoysticks;
+
+ SDL_PrivateJoystickAdded(numjoysticks - 1);
+
+ return SDL_TRUE;
+}
+
+static void SteamControllerDisconnectedCallback(int device_instance)
+{
+ SDL_JoystickDeviceItem *item;
+
+ for (item = deviceList; item; item = item->next) {
+ if (item->instance_id == device_instance) {
+ SDL_SYS_RemoveJoystickDevice(item);
+ break;
+ }
+ }
+}
+
+/* Function to scan the system for joysticks.
+ * Joystick 0 should be the system default joystick.
+ * It should return 0, or -1 on an unrecoverable fatal error.
+ */
+int
+SDL_SYS_JoystickInit(void)
+{
+ @autoreleasepool {
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+
+ SDL_InitSteamControllers(SteamControllerConnectedCallback,
+ SteamControllerDisconnectedCallback);
+
+#if !TARGET_OS_TV
+ if (SDL_GetHintBoolean(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_TRUE)) {
+ /* Default behavior, accelerometer as joystick */
+ SDL_SYS_AddJoystickDevice(nil, SDL_TRUE);
+ }
+#endif /* !TARGET_OS_TV */
+
+#ifdef SDL_JOYSTICK_MFI
+ /* GameController.framework was added in iOS 7. */
+ if (![GCController class]) {
+ return numjoysticks;
+ }
+
+ for (GCController *controller in [GCController controllers]) {
+ SDL_SYS_AddJoystickDevice(controller, SDL_FALSE);
+ }
+
+#if TARGET_OS_TV
+ SDL_AddHintCallback(SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION,
+ SDL_AppleTVRemoteRotationHintChanged, NULL);
+#endif /* TARGET_OS_TV */
+
+ connectObserver = [center addObserverForName:GCControllerDidConnectNotification
+ object:nil
+ queue:nil
+ usingBlock:^(NSNotification *note) {
+ GCController *controller = note.object;
+ SDL_SYS_AddJoystickDevice(controller, SDL_FALSE);
+ }];
+
+ disconnectObserver = [center addObserverForName:GCControllerDidDisconnectNotification
+ object:nil
+ queue:nil
+ usingBlock:^(NSNotification *note) {
+ GCController *controller = note.object;
+ SDL_JoystickDeviceItem *device = deviceList;
+ while (device != NULL) {
+ if (device->controller == controller) {
+ SDL_SYS_RemoveJoystickDevice(device);
+ break;
+ }
+ device = device->next;
+ }
+ }];
+#endif /* SDL_JOYSTICK_MFI */
+ }
+
+ return numjoysticks;
+}
+
+int
+SDL_SYS_NumJoysticks(void)
+{
+ return numjoysticks;
+}
+
+void
+SDL_SYS_JoystickDetect(void)
+{
+ SDL_UpdateSteamControllers();
+}
+
+/* Function to get the device-dependent name of a joystick */
+const char *
+SDL_SYS_JoystickNameForDeviceIndex(int device_index)
+{
+ SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
+ return device ? device->name : "Unknown";
+}
+
+/* Function to perform the mapping from device index to the instance id for this index */
+SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
+{
+ SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
+ return device ? device->instance_id : 0;
+}
+
+/* Function to open a joystick for use.
+ The joystick to open is specified by the device index.
+ This should fill the nbuttons and naxes fields of the joystick structure.
+ It returns 0, or -1 if there is an error.
+ */
+int
+SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
+{
+ SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
+ if (device == NULL) {
+ return SDL_SetError("Could not open Joystick: no hardware device for the specified index");
+ }
+
+ joystick->hwdata = device;
+ joystick->instance_id = device->instance_id;
+
+ joystick->naxes = device->naxes;
+ joystick->nhats = device->nhats;
+ joystick->nbuttons = device->nbuttons;
+ joystick->nballs = 0;
+
+ device->joystick = joystick;
+
+ @autoreleasepool {
+ if (device->accelerometer) {
+#if !TARGET_OS_TV
+ if (motionManager == nil) {
+ motionManager = [[CMMotionManager alloc] init];
+ }
+
+ /* Shorter times between updates can significantly increase CPU usage. */
+ motionManager.accelerometerUpdateInterval = 0.1;
+ [motionManager startAccelerometerUpdates];
+#endif /* !TARGET_OS_TV */
+ } else {
+#ifdef SDL_JOYSTICK_MFI
+ GCController *controller = device->controller;
+ controller.controllerPausedHandler = ^(GCController *c) {
+ if (joystick->hwdata) {
+ ++joystick->hwdata->num_pause_presses;
+ }
+ };
+#endif /* SDL_JOYSTICK_MFI */
+ }
+ }
+ if (device->remote) {
+ ++SDL_AppleTVRemoteOpenedAsJoystick;
+ }
+
+ return 0;
+}
+
+/* Function to determine if this joystick is attached to the system right now */
+SDL_bool
+SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
+{
+ return joystick->hwdata != NULL;
+}
+
+static void
+SDL_SYS_AccelerometerUpdate(SDL_Joystick * joystick)
+{
+#if !TARGET_OS_TV
+ const float maxgforce = SDL_IPHONE_MAX_GFORCE;
+ const SInt16 maxsint16 = 0x7FFF;
+ CMAcceleration accel;
+
+ @autoreleasepool {
+ if (!motionManager.isAccelerometerActive) {
+ return;
+ }
+
+ accel = motionManager.accelerometerData.acceleration;
+ }
+
+ /*
+ Convert accelerometer data from floating point to Sint16, which is what
+ the joystick system expects.
+
+ To do the conversion, the data is first clamped onto the interval
+ [-SDL_IPHONE_MAX_G_FORCE, SDL_IPHONE_MAX_G_FORCE], then the data is multiplied
+ by MAX_SINT16 so that it is mapped to the full range of an Sint16.
+
+ You can customize the clamped range of this function by modifying the
+ SDL_IPHONE_MAX_GFORCE macro in SDL_config_iphoneos.h.
+
+ Once converted to Sint16, the accelerometer data no longer has coherent
+ units. You can convert the data back to units of g-force by multiplying
+ it in your application's code by SDL_IPHONE_MAX_GFORCE / 0x7FFF.
+ */
+
+ /* clamp the data */
+ accel.x = SDL_min(SDL_max(accel.x, -maxgforce), maxgforce);
+ accel.y = SDL_min(SDL_max(accel.y, -maxgforce), maxgforce);
+ accel.z = SDL_min(SDL_max(accel.z, -maxgforce), maxgforce);
+
+ /* pass in data mapped to range of SInt16 */
+ SDL_PrivateJoystickAxis(joystick, 0, (accel.x / maxgforce) * maxsint16);
+ SDL_PrivateJoystickAxis(joystick, 1, -(accel.y / maxgforce) * maxsint16);
+ SDL_PrivateJoystickAxis(joystick, 2, (accel.z / maxgforce) * maxsint16);
+#endif /* !TARGET_OS_TV */
+}
+
+#ifdef SDL_JOYSTICK_MFI
+static Uint8
+SDL_SYS_MFIJoystickHatStateForDPad(GCControllerDirectionPad *dpad)
+{
+ Uint8 hat = 0;
+
+ if (dpad.up.isPressed) {
+ hat |= SDL_HAT_UP;
+ } else if (dpad.down.isPressed) {
+ hat |= SDL_HAT_DOWN;
+ }
+
+ if (dpad.left.isPressed) {
+ hat |= SDL_HAT_LEFT;
+ } else if (dpad.right.isPressed) {
+ hat |= SDL_HAT_RIGHT;
+ }
+
+ if (hat == 0) {
+ return SDL_HAT_CENTERED;
+ }
+
+ return hat;
+}
+#endif
+
+static void
+SDL_SYS_MFIJoystickUpdate(SDL_Joystick * joystick)
+{
+#if SDL_JOYSTICK_MFI
+ @autoreleasepool {
+ GCController *controller = joystick->hwdata->controller;
+ Uint8 hatstate = SDL_HAT_CENTERED;
+ int i;
+ int updateplayerindex = 0;
+
+ if (controller.extendedGamepad) {
+ GCExtendedGamepad *gamepad = controller.extendedGamepad;
+
+ /* Axis order matches the XInput Windows mappings. */
+ Sint16 axes[] = {
+ (Sint16) (gamepad.leftThumbstick.xAxis.value * 32767),
+ (Sint16) (gamepad.leftThumbstick.yAxis.value * -32767),
+ (Sint16) ((gamepad.leftTrigger.value * 65535) - 32768),
+ (Sint16) (gamepad.rightThumbstick.xAxis.value * 32767),
+ (Sint16) (gamepad.rightThumbstick.yAxis.value * -32767),
+ (Sint16) ((gamepad.rightTrigger.value * 65535) - 32768),
+ };
+
+ /* Button order matches the XInput Windows mappings. */
+ Uint8 buttons[] = {
+ gamepad.buttonA.isPressed, gamepad.buttonB.isPressed,
+ gamepad.buttonX.isPressed, gamepad.buttonY.isPressed,
+ gamepad.leftShoulder.isPressed,
+ gamepad.rightShoulder.isPressed,
+ };
+
+ hatstate = SDL_SYS_MFIJoystickHatStateForDPad(gamepad.dpad);
+
+ for (i = 0; i < SDL_arraysize(axes); i++) {
+ /* The triggers (axes 2 and 5) are resting at -32768 but SDL
+ * initializes its values to 0. We only want to make sure the
+ * player index is up to date if the user actually moves an axis. */
+ if ((i != 2 && i != 5) || axes[i] != -32768) {
+ updateplayerindex |= (joystick->axes[i].value != axes[i]);
+ }
+ SDL_PrivateJoystickAxis(joystick, i, axes[i]);
+ }
+
+ for (i = 0; i < SDL_arraysize(buttons); i++) {
+ updateplayerindex |= (joystick->buttons[i] != buttons[i]);
+ SDL_PrivateJoystickButton(joystick, i, buttons[i]);
+ }
+ } else if (controller.gamepad) {
+ GCGamepad *gamepad = controller.gamepad;
+
+ /* Button order matches the XInput Windows mappings. */
+ Uint8 buttons[] = {
+ gamepad.buttonA.isPressed, gamepad.buttonB.isPressed,
+ gamepad.buttonX.isPressed, gamepad.buttonY.isPressed,
+ gamepad.leftShoulder.isPressed,
+ gamepad.rightShoulder.isPressed,
+ };
+
+ hatstate = SDL_SYS_MFIJoystickHatStateForDPad(gamepad.dpad);
+
+ for (i = 0; i < SDL_arraysize(buttons); i++) {
+ updateplayerindex |= (joystick->buttons[i] != buttons[i]);
+ SDL_PrivateJoystickButton(joystick, i, buttons[i]);
+ }
+ }
+#if TARGET_OS_TV
+ else if (controller.microGamepad) {
+ GCMicroGamepad *gamepad = controller.microGamepad;
+
+ Sint16 axes[] = {
+ (Sint16) (gamepad.dpad.xAxis.value * 32767),
+ (Sint16) (gamepad.dpad.yAxis.value * -32767),
+ };
+
+ for (i = 0; i < SDL_arraysize(axes); i++) {
+ updateplayerindex |= (joystick->axes[i].value != axes[i]);
+ SDL_PrivateJoystickAxis(joystick, i, axes[i]);
+ }
+
+ Uint8 buttons[] = {
+ gamepad.buttonA.isPressed,
+ gamepad.buttonX.isPressed,
+ };
+
+ for (i = 0; i < SDL_arraysize(buttons); i++) {
+ updateplayerindex |= (joystick->buttons[i] != buttons[i]);
+ SDL_PrivateJoystickButton(joystick, i, buttons[i]);
+ }
+ }
+#endif /* TARGET_OS_TV */
+
+ if (joystick->nhats > 0) {
+ updateplayerindex |= (joystick->hats[0] != hatstate);
+ SDL_PrivateJoystickHat(joystick, 0, hatstate);
+ }
+
+ for (i = 0; i < joystick->hwdata->num_pause_presses; i++) {
+ /* The pause button is always last. */
+ Uint8 pausebutton = joystick->nbuttons - 1;
+
+ SDL_PrivateJoystickButton(joystick, pausebutton, SDL_PRESSED);
+ SDL_PrivateJoystickButton(joystick, pausebutton, SDL_RELEASED);
+
+ updateplayerindex = YES;
+ }
+
+ joystick->hwdata->num_pause_presses = 0;
+
+ if (updateplayerindex && controller.playerIndex == -1) {
+ BOOL usedPlayerIndexSlots[4] = {NO, NO, NO, NO};
+
+ /* Find the player index of all other connected controllers. */
+ for (GCController *c in [GCController controllers]) {
+ if (c != controller && c.playerIndex >= 0) {
+ usedPlayerIndexSlots[c.playerIndex] = YES;
+ }
+ }
+
+ /* Set this controller's player index to the first unused index.
+ * FIXME: This logic isn't great... but SDL doesn't expose this
+ * concept in its external API, so we don't have much to go on. */
+ for (i = 0; i < SDL_arraysize(usedPlayerIndexSlots); i++) {
+ if (!usedPlayerIndexSlots[i]) {
+ controller.playerIndex = i;
+ break;
+ }
+ }
+ }
+ }
+#endif /* SDL_JOYSTICK_MFI */
+}
+
+/* Function to update the state of a joystick - called as a device poll.
+ * This function shouldn't update the joystick structure directly,
+ * but instead should call SDL_PrivateJoystick*() to deliver events
+ * and update joystick device state.
+ */
+void
+SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
+{
+ SDL_JoystickDeviceItem *device = joystick->hwdata;
+
+ if (device == NULL) {
+ return;
+ }
+
+ if (device->m_bSteamController) {
+ SDL_UpdateSteamController(joystick);
+ return;
+ }
+
+ if (device->accelerometer) {
+ SDL_SYS_AccelerometerUpdate(joystick);
+ } else if (device->controller) {
+ SDL_SYS_MFIJoystickUpdate(joystick);
+ }
+}
+
+/* Function to close a joystick after use */
+void
+SDL_SYS_JoystickClose(SDL_Joystick * joystick)
+{
+ SDL_JoystickDeviceItem *device = joystick->hwdata;
+
+ if (device == NULL) {
+ return;
+ }
+
+ device->joystick = NULL;
+
+ @autoreleasepool {
+ if (device->accelerometer) {
+#if !TARGET_OS_TV
+ [motionManager stopAccelerometerUpdates];
+#endif /* !TARGET_OS_TV */
+ } else if (device->controller) {
+#ifdef SDL_JOYSTICK_MFI
+ GCController *controller = device->controller;
+ controller.controllerPausedHandler = nil;
+ controller.playerIndex = -1;
+#endif
+ }
+ }
+ if (device->remote) {
+ --SDL_AppleTVRemoteOpenedAsJoystick;
+ }
+}
+
+/* Function to perform any system-specific joystick related cleanup */
+void
+SDL_SYS_JoystickQuit(void)
+{
+ @autoreleasepool {
+#ifdef SDL_JOYSTICK_MFI
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+
+ if (connectObserver) {
+ [center removeObserver:connectObserver name:GCControllerDidConnectNotification object:nil];
+ connectObserver = nil;
+ }
+
+ if (disconnectObserver) {
+ [center removeObserver:disconnectObserver name:GCControllerDidDisconnectNotification object:nil];
+ disconnectObserver = nil;
+ }
+
+#if TARGET_OS_TV
+ SDL_DelHintCallback(SDL_HINT_APPLE_TV_REMOTE_ALLOW_ROTATION,
+ SDL_AppleTVRemoteRotationHintChanged, NULL);
+#endif /* TARGET_OS_TV */
+#endif /* SDL_JOYSTICK_MFI */
+
+ while (deviceList != NULL) {
+ SDL_SYS_RemoveJoystickDevice(deviceList);
+ }
+
+#if !TARGET_OS_TV
+ motionManager = nil;
+#endif /* !TARGET_OS_TV */
+ }
+
+ SDL_QuitSteamControllers();
+
+ numjoysticks = 0;
+}
+
+SDL_JoystickGUID
+SDL_SYS_JoystickGetDeviceGUID( int device_index )
+{
+ SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
+ SDL_JoystickGUID guid;
+ if (device) {
+ guid = device->guid;
+ } else {
+ SDL_zero(guid);
+ }
+ return guid;
+}
+
+SDL_JoystickGUID
+SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
+{
+ SDL_JoystickGUID guid;
+ if (joystick->hwdata) {
+ guid = joystick->hwdata->guid;
+ } else {
+ SDL_zero(guid);
+ }
+ return guid;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/iphoneos/SDL_sysjoystick_c.h b/src/3rdparty/SDL2/src/joystick/iphoneos/SDL_sysjoystick_c.h
new file mode 100644
index 0000000..7be5b04
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/iphoneos/SDL_sysjoystick_c.h
@@ -0,0 +1,59 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_JOYSTICK_IOS_H
+#define SDL_JOYSTICK_IOS_H
+
+#include "SDL_stdinc.h"
+#include "../SDL_sysjoystick.h"
+
+@class GCController;
+
+typedef struct joystick_hwdata
+{
+ SDL_bool accelerometer;
+ SDL_bool remote;
+
+ GCController __unsafe_unretained *controller;
+ int num_pause_presses;
+
+ char *name;
+ SDL_Joystick *joystick;
+ SDL_JoystickID instance_id;
+ SDL_JoystickGUID guid;
+
+ int naxes;
+ int nbuttons;
+ int nhats;
+
+ /* Steam Controller support */
+ SDL_bool m_bSteamController;
+
+ struct joystick_hwdata *next;
+} joystick_hwdata;
+
+typedef joystick_hwdata SDL_JoystickDeviceItem;
+
+#endif /* SDL_JOYSTICK_IOS_H */
+
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/linux/SDL_sysjoystick.c b/src/3rdparty/SDL2/src/joystick/linux/SDL_sysjoystick.c
new file mode 100644
index 0000000..457c4b8
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/linux/SDL_sysjoystick.c
@@ -0,0 +1,1049 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_JOYSTICK_LINUX
+
+#ifndef SDL_INPUT_LINUXEV
+#error SDL now requires a Linux 2.4+ kernel with /dev/input/event support.
+#endif
+
+/* This is the Linux implementation of the SDL joystick API */
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <limits.h> /* For the definition of PATH_MAX */
+#include <linux/joystick.h>
+
+#include "SDL_assert.h"
+#include "SDL_joystick.h"
+#include "SDL_endian.h"
+#include "../../events/SDL_events_c.h"
+#include "../SDL_sysjoystick.h"
+#include "../SDL_joystick_c.h"
+#include "../steam/SDL_steamcontroller.h"
+#include "SDL_sysjoystick_c.h"
+
+/* This isn't defined in older Linux kernel headers */
+#ifndef SYN_DROPPED
+#define SYN_DROPPED 3
+#endif
+
+#include "../../core/linux/SDL_udev.h"
+
+static int MaybeAddDevice(const char *path);
+#if SDL_USE_LIBUDEV
+static int MaybeRemoveDevice(const char *path);
+static void joystick_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath);
+#endif /* SDL_USE_LIBUDEV */
+
+
+/* A linked list of available joysticks */
+typedef struct SDL_joylist_item
+{
+ int device_instance;
+ char *path; /* "/dev/input/event2" or whatever */
+ char *name; /* "SideWinder 3D Pro" or whatever */
+ SDL_JoystickGUID guid;
+ dev_t devnum;
+ struct joystick_hwdata *hwdata;
+ struct SDL_joylist_item *next;
+
+ /* Steam Controller support */
+ SDL_bool m_bSteamController;
+} SDL_joylist_item;
+
+static SDL_joylist_item *SDL_joylist = NULL;
+static SDL_joylist_item *SDL_joylist_tail = NULL;
+static int numjoysticks = 0;
+static int instance_counter = 0;
+
+
+#define test_bit(nr, addr) \
+ (((1UL << ((nr) % (sizeof(long) * 8))) & ((addr)[(nr) / (sizeof(long) * 8)])) != 0)
+#define NBITS(x) ((((x)-1)/(sizeof(long) * 8))+1)
+
+static int
+IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *guid)
+{
+ /* This list is taken from:
+ https://raw.githubusercontent.com/denilsonsa/udev-joystick-blacklist/master/generate_rules.py
+ */
+ static Uint32 joystick_blacklist[] = {
+ /* Microsoft Microsoft Wireless Optical Desktop® 2.10 */
+ /* Microsoft Wireless Desktop - Comfort Edition */
+ MAKE_VIDPID(0x045e, 0x009d),
+
+ /* Microsoft Microsoft® Digital Media Pro Keyboard */
+ /* Microsoft Corp. Digital Media Pro Keyboard */
+ MAKE_VIDPID(0x045e, 0x00b0),
+
+ /* Microsoft Microsoft® Digital Media Keyboard */
+ /* Microsoft Corp. Digital Media Keyboard 1.0A */
+ MAKE_VIDPID(0x045e, 0x00b4),
+
+ /* Microsoft Microsoft® Digital Media Keyboard 3000 */
+ MAKE_VIDPID(0x045e, 0x0730),
+
+ /* Microsoft Microsoft® 2.4GHz Transceiver v6.0 */
+ /* Microsoft Microsoft® 2.4GHz Transceiver v8.0 */
+ /* Microsoft Corp. Nano Transceiver v1.0 for Bluetooth */
+ /* Microsoft Wireless Mobile Mouse 1000 */
+ /* Microsoft Wireless Desktop 3000 */
+ MAKE_VIDPID(0x045e, 0x0745),
+
+ /* Microsoft® SideWinder(TM) 2.4GHz Transceiver */
+ MAKE_VIDPID(0x045e, 0x0748),
+
+ /* Microsoft Corp. Wired Keyboard 600 */
+ MAKE_VIDPID(0x045e, 0x0750),
+
+ /* Microsoft Corp. Sidewinder X4 keyboard */
+ MAKE_VIDPID(0x045e, 0x0768),
+
+ /* Microsoft Corp. Arc Touch Mouse Transceiver */
+ MAKE_VIDPID(0x045e, 0x0773),
+
+ /* Microsoft® 2.4GHz Transceiver v9.0 */
+ /* Microsoft® Nano Transceiver v2.1 */
+ /* Microsoft Sculpt Ergonomic Keyboard (5KV-00001) */
+ MAKE_VIDPID(0x045e, 0x07a5),
+
+ /* Microsoft® Nano Transceiver v1.0 */
+ /* Microsoft Wireless Keyboard 800 */
+ MAKE_VIDPID(0x045e, 0x07b2),
+
+ /* Microsoft® Nano Transceiver v2.0 */
+ MAKE_VIDPID(0x045e, 0x0800),
+
+ /* List of Wacom devices at: http://linuxwacom.sourceforge.net/wiki/index.php/Device_IDs */
+ MAKE_VIDPID(0x056a, 0x0010), /* Wacom ET-0405 Graphire */
+ MAKE_VIDPID(0x056a, 0x0011), /* Wacom ET-0405A Graphire2 (4x5) */
+ MAKE_VIDPID(0x056a, 0x0012), /* Wacom ET-0507A Graphire2 (5x7) */
+ MAKE_VIDPID(0x056a, 0x0013), /* Wacom CTE-430 Graphire3 (4x5) */
+ MAKE_VIDPID(0x056a, 0x0014), /* Wacom CTE-630 Graphire3 (6x8) */
+ MAKE_VIDPID(0x056a, 0x0015), /* Wacom CTE-440 Graphire4 (4x5) */
+ MAKE_VIDPID(0x056a, 0x0016), /* Wacom CTE-640 Graphire4 (6x8) */
+ MAKE_VIDPID(0x056a, 0x0017), /* Wacom CTE-450 Bamboo Fun (4x5) */
+ MAKE_VIDPID(0x056a, 0x0016), /* Wacom CTE-640 Graphire 4 6x8 */
+ MAKE_VIDPID(0x056a, 0x0017), /* Wacom CTE-450 Bamboo Fun 4x5 */
+ MAKE_VIDPID(0x056a, 0x0018), /* Wacom CTE-650 Bamboo Fun 6x8 */
+ MAKE_VIDPID(0x056a, 0x0019), /* Wacom CTE-631 Bamboo One */
+ MAKE_VIDPID(0x056a, 0x00d1), /* Wacom Bamboo Pen and Touch CTH-460 */
+
+ MAKE_VIDPID(0x09da, 0x054f), /* A4 Tech Co., G7 750 mouse */
+ MAKE_VIDPID(0x09da, 0x3043), /* A4 Tech Co., Ltd Bloody R8A Gaming Mouse */
+ MAKE_VIDPID(0x09da, 0x31b5), /* A4 Tech Co., Ltd Bloody TL80 Terminator Laser Gaming Mouse */
+ MAKE_VIDPID(0x09da, 0x3997), /* A4 Tech Co., Ltd Bloody RT7 Terminator Wireless */
+ MAKE_VIDPID(0x09da, 0x3f8b), /* A4 Tech Co., Ltd Bloody V8 mouse */
+ MAKE_VIDPID(0x09da, 0x51f4), /* Modecom MC-5006 Keyboard */
+ MAKE_VIDPID(0x09da, 0x5589), /* A4 Tech Co., Ltd Terminator TL9 Laser Gaming Mouse */
+ MAKE_VIDPID(0x09da, 0x7b22), /* A4 Tech Co., Ltd Bloody V5 */
+ MAKE_VIDPID(0x09da, 0x7f2d), /* A4 Tech Co., Ltd Bloody R3 mouse */
+ MAKE_VIDPID(0x09da, 0x8090), /* A4 Tech Co., Ltd X-718BK Oscar Optical Gaming Mouse */
+ MAKE_VIDPID(0x09da, 0x9066), /* A4 Tech Co., Sharkoon Fireglider Optical */
+ MAKE_VIDPID(0x09da, 0x9090), /* A4 Tech Co., Ltd XL-730K / XL-750BK / XL-755BK Laser Mouse */
+ MAKE_VIDPID(0x09da, 0x90c0), /* A4 Tech Co., Ltd X7 G800V keyboard */
+ MAKE_VIDPID(0x09da, 0xf012), /* A4 Tech Co., Ltd Bloody V7 mouse */
+ MAKE_VIDPID(0x09da, 0xf32a), /* A4 Tech Co., Ltd Bloody B540 keyboard */
+ MAKE_VIDPID(0x09da, 0xf613), /* A4 Tech Co., Ltd Bloody V2 mouse */
+ MAKE_VIDPID(0x09da, 0xf624), /* A4 Tech Co., Ltd Bloody B120 Keyboard */
+
+ MAKE_VIDPID(0x1d57, 0xad03), /* [T3] 2.4GHz and IR Air Mouse Remote Control */
+
+ MAKE_VIDPID(0x1e7d, 0x2e4a), /* Roccat Tyon Mouse */
+
+ MAKE_VIDPID(0x20a0, 0x422d), /* Winkeyless.kr Keyboards */
+
+ MAKE_VIDPID(0x2516, 0x001f), /* Cooler Master Storm Mizar Mouse */
+ MAKE_VIDPID(0x2516, 0x0028), /* Cooler Master Storm Alcor Mouse */
+ };
+ struct input_id inpid;
+ int i;
+ Uint32 id;
+ Uint16 *guid16 = (Uint16 *)guid->data;
+
+#if !SDL_USE_LIBUDEV
+ /* When udev is enabled we only get joystick devices here, so there's no need to test them */
+ unsigned long evbit[NBITS(EV_MAX)] = { 0 };
+ unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
+ unsigned long absbit[NBITS(ABS_MAX)] = { 0 };
+
+ if ((ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit) < 0) ||
+ (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) ||
+ (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) {
+ return (0);
+ }
+
+ if (!(test_bit(EV_KEY, evbit) && test_bit(EV_ABS, evbit) &&
+ test_bit(ABS_X, absbit) && test_bit(ABS_Y, absbit))) {
+ return 0;
+ }
+#endif
+
+ if (ioctl(fd, EVIOCGNAME(namebuflen), namebuf) < 0) {
+ return 0;
+ }
+
+ if (ioctl(fd, EVIOCGID, &inpid) < 0) {
+ return 0;
+ }
+
+ /* Check the joystick blacklist */
+ id = MAKE_VIDPID(inpid.vendor, inpid.product);
+ for (i = 0; i < SDL_arraysize(joystick_blacklist); ++i) {
+ if (id == joystick_blacklist[i]) {
+ return 0;
+ }
+ }
+
+#ifdef DEBUG_JOYSTICK
+ printf("Joystick: %s, bustype = %d, vendor = 0x%.4x, product = 0x%.4x, version = %d\n", namebuf, inpid.bustype, inpid.vendor, inpid.product, inpid.version);
+#endif
+
+ SDL_memset(guid->data, 0, sizeof(guid->data));
+
+ /* We only need 16 bits for each of these; space them out to fill 128. */
+ /* Byteswap so devices get same GUID on little/big endian platforms. */
+ *guid16++ = SDL_SwapLE16(inpid.bustype);
+ *guid16++ = 0;
+
+ if (inpid.vendor && inpid.product) {
+ *guid16++ = SDL_SwapLE16(inpid.vendor);
+ *guid16++ = 0;
+ *guid16++ = SDL_SwapLE16(inpid.product);
+ *guid16++ = 0;
+ *guid16++ = SDL_SwapLE16(inpid.version);
+ *guid16++ = 0;
+ } else {
+ SDL_strlcpy((char*)guid16, namebuf, sizeof(guid->data) - 4);
+ }
+
+ if (SDL_IsGameControllerNameAndGUID(namebuf, *guid) &&
+ SDL_ShouldIgnoreGameController(namebuf, *guid)) {
+ return 0;
+ }
+ return 1;
+}
+
+#if SDL_USE_LIBUDEV
+static void joystick_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath)
+{
+ if (devpath == NULL) {
+ return;
+ }
+
+ switch (udev_type) {
+ case SDL_UDEV_DEVICEADDED:
+ if (!(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
+ return;
+ }
+ MaybeAddDevice(devpath);
+ break;
+
+ case SDL_UDEV_DEVICEREMOVED:
+ MaybeRemoveDevice(devpath);
+ break;
+
+ default:
+ break;
+ }
+
+}
+#endif /* SDL_USE_LIBUDEV */
+
+
+/* !!! FIXME: I would love to dump this code and use libudev instead. */
+static int
+MaybeAddDevice(const char *path)
+{
+ struct stat sb;
+ int fd = -1;
+ int isstick = 0;
+ char namebuf[128];
+ SDL_JoystickGUID guid;
+ SDL_joylist_item *item;
+
+ if (path == NULL) {
+ return -1;
+ }
+
+ if (stat(path, &sb) == -1) {
+ return -1;
+ }
+
+ /* Check to make sure it's not already in list. */
+ for (item = SDL_joylist; item != NULL; item = item->next) {
+ if (sb.st_rdev == item->devnum) {
+ return -1; /* already have this one */
+ }
+ }
+
+ fd = open(path, O_RDONLY, 0);
+ if (fd < 0) {
+ return -1;
+ }
+
+#ifdef DEBUG_INPUT_EVENTS
+ printf("Checking %s\n", path);
+#endif
+
+ isstick = IsJoystick(fd, namebuf, sizeof (namebuf), &guid);
+ close(fd);
+ if (!isstick) {
+ return -1;
+ }
+
+ item = (SDL_joylist_item *) SDL_malloc(sizeof (SDL_joylist_item));
+ if (item == NULL) {
+ return -1;
+ }
+
+ SDL_zerop(item);
+ item->devnum = sb.st_rdev;
+ item->path = SDL_strdup(path);
+ item->name = SDL_strdup(namebuf);
+ item->guid = guid;
+
+ if ( (item->path == NULL) || (item->name == NULL) ) {
+ SDL_free(item->path);
+ SDL_free(item->name);
+ SDL_free(item);
+ return -1;
+ }
+
+ item->device_instance = instance_counter++;
+ if (SDL_joylist_tail == NULL) {
+ SDL_joylist = SDL_joylist_tail = item;
+ } else {
+ SDL_joylist_tail->next = item;
+ SDL_joylist_tail = item;
+ }
+
+ /* Need to increment the joystick count before we post the event */
+ ++numjoysticks;
+
+ SDL_PrivateJoystickAdded(numjoysticks - 1);
+
+ return numjoysticks;
+}
+
+#if SDL_USE_LIBUDEV
+/* !!! FIXME: I would love to dump this code and use libudev instead. */
+static int
+MaybeRemoveDevice(const char *path)
+{
+ SDL_joylist_item *item;
+ SDL_joylist_item *prev = NULL;
+
+ if (path == NULL) {
+ return -1;
+ }
+
+ for (item = SDL_joylist; item != NULL; item = item->next) {
+ /* found it, remove it. */
+ if (SDL_strcmp(path, item->path) == 0) {
+ const int retval = item->device_instance;
+ if (item->hwdata) {
+ item->hwdata->item = NULL;
+ }
+ if (prev != NULL) {
+ prev->next = item->next;
+ } else {
+ SDL_assert(SDL_joylist == item);
+ SDL_joylist = item->next;
+ }
+ if (item == SDL_joylist_tail) {
+ SDL_joylist_tail = prev;
+ }
+
+ /* Need to decrement the joystick count before we post the event */
+ --numjoysticks;
+
+ SDL_PrivateJoystickRemoved(item->device_instance);
+
+ SDL_free(item->path);
+ SDL_free(item->name);
+ SDL_free(item);
+ return retval;
+ }
+ prev = item;
+ }
+
+ return -1;
+}
+#endif
+
+#if ! SDL_USE_LIBUDEV
+static int
+JoystickInitWithoutUdev(void)
+{
+ int i;
+ char path[PATH_MAX];
+
+ /* !!! FIXME: only finds sticks if they're called /dev/input/event[0..31] */
+ /* !!! FIXME: we could at least readdir() through /dev/input...? */
+ /* !!! FIXME: (or delete this and rely on libudev?) */
+ for (i = 0; i < 32; i++) {
+ SDL_snprintf(path, SDL_arraysize(path), "/dev/input/event%d", i);
+ MaybeAddDevice(path);
+ }
+
+ return numjoysticks;
+}
+#endif
+
+#if SDL_USE_LIBUDEV
+static int
+JoystickInitWithUdev(void)
+{
+ if (SDL_UDEV_Init() < 0) {
+ return SDL_SetError("Could not initialize UDEV");
+ }
+
+ /* Set up the udev callback */
+ if (SDL_UDEV_AddCallback(joystick_udev_callback) < 0) {
+ SDL_UDEV_Quit();
+ return SDL_SetError("Could not set up joystick <-> udev callback");
+ }
+
+ /* Force a scan to build the initial device list */
+ SDL_UDEV_Scan();
+
+ return numjoysticks;
+}
+#endif
+
+static SDL_bool SteamControllerConnectedCallback(const char *name, SDL_JoystickGUID guid, int *device_instance)
+{
+ SDL_joylist_item *item;
+
+ item = (SDL_joylist_item *) SDL_calloc(1, sizeof (SDL_joylist_item));
+ if (item == NULL) {
+ return SDL_FALSE;
+ }
+
+ item->path = SDL_strdup("");
+ item->name = SDL_strdup(name);
+ item->guid = guid;
+ item->m_bSteamController = SDL_TRUE;
+
+ if ((item->path == NULL) || (item->name == NULL)) {
+ SDL_free(item->path);
+ SDL_free(item->name);
+ SDL_free(item);
+ return SDL_FALSE;
+ }
+
+ *device_instance = item->device_instance = instance_counter++;
+ if (SDL_joylist_tail == NULL) {
+ SDL_joylist = SDL_joylist_tail = item;
+ } else {
+ SDL_joylist_tail->next = item;
+ SDL_joylist_tail = item;
+ }
+
+ /* Need to increment the joystick count before we post the event */
+ ++numjoysticks;
+
+ SDL_PrivateJoystickAdded(numjoysticks - 1);
+
+ return SDL_TRUE;
+}
+
+static void SteamControllerDisconnectedCallback(int device_instance)
+{
+ SDL_joylist_item *item;
+ SDL_joylist_item *prev = NULL;
+
+ for (item = SDL_joylist; item != NULL; item = item->next) {
+ /* found it, remove it. */
+ if (item->device_instance == device_instance) {
+ if (item->hwdata) {
+ item->hwdata->item = NULL;
+ }
+ if (prev != NULL) {
+ prev->next = item->next;
+ } else {
+ SDL_assert(SDL_joylist == item);
+ SDL_joylist = item->next;
+ }
+ if (item == SDL_joylist_tail) {
+ SDL_joylist_tail = prev;
+ }
+
+ /* Need to decrement the joystick count before we post the event */
+ --numjoysticks;
+
+ SDL_PrivateJoystickRemoved(item->device_instance);
+
+ SDL_free(item->name);
+ SDL_free(item);
+ return;
+ }
+ prev = item;
+ }
+}
+
+int
+SDL_SYS_JoystickInit(void)
+{
+ /* First see if the user specified one or more joysticks to use */
+ if (SDL_getenv("SDL_JOYSTICK_DEVICE") != NULL) {
+ char *envcopy, *envpath, *delim;
+ envcopy = SDL_strdup(SDL_getenv("SDL_JOYSTICK_DEVICE"));
+ envpath = envcopy;
+ while (envpath != NULL) {
+ delim = SDL_strchr(envpath, ':');
+ if (delim != NULL) {
+ *delim++ = '\0';
+ }
+ MaybeAddDevice(envpath);
+ envpath = delim;
+ }
+ SDL_free(envcopy);
+ }
+
+ SDL_InitSteamControllers(SteamControllerConnectedCallback,
+ SteamControllerDisconnectedCallback);
+
+#if SDL_USE_LIBUDEV
+ return JoystickInitWithUdev();
+#else
+ return JoystickInitWithoutUdev();
+#endif
+}
+
+int
+SDL_SYS_NumJoysticks(void)
+{
+ return numjoysticks;
+}
+
+void
+SDL_SYS_JoystickDetect(void)
+{
+#if SDL_USE_LIBUDEV
+ SDL_UDEV_Poll();
+#endif
+
+ SDL_UpdateSteamControllers();
+}
+
+static SDL_joylist_item *
+JoystickByDevIndex(int device_index)
+{
+ SDL_joylist_item *item = SDL_joylist;
+
+ if ((device_index < 0) || (device_index >= numjoysticks)) {
+ return NULL;
+ }
+
+ while (device_index > 0) {
+ SDL_assert(item != NULL);
+ device_index--;
+ item = item->next;
+ }
+
+ return item;
+}
+
+/* Function to get the device-dependent name of a joystick */
+const char *
+SDL_SYS_JoystickNameForDeviceIndex(int device_index)
+{
+ return JoystickByDevIndex(device_index)->name;
+}
+
+/* Function to perform the mapping from device index to the instance id for this index */
+SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
+{
+ return JoystickByDevIndex(device_index)->device_instance;
+}
+
+static int
+allocate_hatdata(SDL_Joystick * joystick)
+{
+ int i;
+
+ joystick->hwdata->hats =
+ (struct hwdata_hat *) SDL_malloc(joystick->nhats *
+ sizeof(struct hwdata_hat));
+ if (joystick->hwdata->hats == NULL) {
+ return (-1);
+ }
+ for (i = 0; i < joystick->nhats; ++i) {
+ joystick->hwdata->hats[i].axis[0] = 1;
+ joystick->hwdata->hats[i].axis[1] = 1;
+ }
+ return (0);
+}
+
+static int
+allocate_balldata(SDL_Joystick * joystick)
+{
+ int i;
+
+ joystick->hwdata->balls =
+ (struct hwdata_ball *) SDL_malloc(joystick->nballs *
+ sizeof(struct hwdata_ball));
+ if (joystick->hwdata->balls == NULL) {
+ return (-1);
+ }
+ for (i = 0; i < joystick->nballs; ++i) {
+ joystick->hwdata->balls[i].axis[0] = 0;
+ joystick->hwdata->balls[i].axis[1] = 0;
+ }
+ return (0);
+}
+
+static void
+ConfigJoystick(SDL_Joystick * joystick, int fd)
+{
+ int i, t;
+ unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
+ unsigned long absbit[NBITS(ABS_MAX)] = { 0 };
+ unsigned long relbit[NBITS(REL_MAX)] = { 0 };
+
+ /* See if this device uses the new unified event API */
+ if ((ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) &&
+ (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) >= 0) &&
+ (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbit)), relbit) >= 0)) {
+
+ /* Get the number of buttons, axes, and other thingamajigs */
+ for (i = BTN_JOYSTICK; i < KEY_MAX; ++i) {
+ if (test_bit(i, keybit)) {
+#ifdef DEBUG_INPUT_EVENTS
+ printf("Joystick has button: 0x%x\n", i);
+#endif
+ joystick->hwdata->key_map[i] = joystick->nbuttons;
+ ++joystick->nbuttons;
+ }
+ }
+ for (i = 0; i < BTN_JOYSTICK; ++i) {
+ if (test_bit(i, keybit)) {
+#ifdef DEBUG_INPUT_EVENTS
+ printf("Joystick has button: 0x%x\n", i);
+#endif
+ joystick->hwdata->key_map[i] = joystick->nbuttons;
+ ++joystick->nbuttons;
+ }
+ }
+ for (i = 0; i < ABS_MAX; ++i) {
+ /* Skip hats */
+ if (i == ABS_HAT0X) {
+ i = ABS_HAT3Y;
+ continue;
+ }
+ if (test_bit(i, absbit)) {
+ struct input_absinfo absinfo;
+
+ if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0) {
+ continue;
+ }
+#ifdef DEBUG_INPUT_EVENTS
+ printf("Joystick has absolute axis: 0x%.2x\n", i);
+ printf("Values = { %d, %d, %d, %d, %d }\n",
+ absinfo.value, absinfo.minimum, absinfo.maximum,
+ absinfo.fuzz, absinfo.flat);
+#endif /* DEBUG_INPUT_EVENTS */
+ joystick->hwdata->abs_map[i] = joystick->naxes;
+ if (absinfo.minimum == absinfo.maximum) {
+ joystick->hwdata->abs_correct[i].used = 0;
+ } else {
+ joystick->hwdata->abs_correct[i].used = 1;
+ joystick->hwdata->abs_correct[i].coef[0] =
+ (absinfo.maximum + absinfo.minimum) - 2 * absinfo.flat;
+ joystick->hwdata->abs_correct[i].coef[1] =
+ (absinfo.maximum + absinfo.minimum) + 2 * absinfo.flat;
+ t = ((absinfo.maximum - absinfo.minimum) - 4 * absinfo.flat);
+ if (t != 0) {
+ joystick->hwdata->abs_correct[i].coef[2] =
+ (1 << 28) / t;
+ } else {
+ joystick->hwdata->abs_correct[i].coef[2] = 0;
+ }
+ }
+ ++joystick->naxes;
+ }
+ }
+ for (i = ABS_HAT0X; i <= ABS_HAT3Y; i += 2) {
+ if (test_bit(i, absbit) || test_bit(i + 1, absbit)) {
+ struct input_absinfo absinfo;
+
+ if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0) {
+ continue;
+ }
+#ifdef DEBUG_INPUT_EVENTS
+ printf("Joystick has hat %d\n", (i - ABS_HAT0X) / 2);
+ printf("Values = { %d, %d, %d, %d, %d }\n",
+ absinfo.value, absinfo.minimum, absinfo.maximum,
+ absinfo.fuzz, absinfo.flat);
+#endif /* DEBUG_INPUT_EVENTS */
+ ++joystick->nhats;
+ }
+ }
+ if (test_bit(REL_X, relbit) || test_bit(REL_Y, relbit)) {
+ ++joystick->nballs;
+ }
+
+ /* Allocate data to keep track of these thingamajigs */
+ if (joystick->nhats > 0) {
+ if (allocate_hatdata(joystick) < 0) {
+ joystick->nhats = 0;
+ }
+ }
+ if (joystick->nballs > 0) {
+ if (allocate_balldata(joystick) < 0) {
+ joystick->nballs = 0;
+ }
+ }
+ }
+}
+
+
+/* Function to open a joystick for use.
+ The joystick to open is specified by the device index.
+ This should fill the nbuttons and naxes fields of the joystick structure.
+ It returns 0, or -1 if there is an error.
+ */
+int
+SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
+{
+ SDL_joylist_item *item = JoystickByDevIndex(device_index);
+
+ if (item == NULL) {
+ return SDL_SetError("No such device");
+ }
+
+ joystick->instance_id = item->device_instance;
+ joystick->hwdata = (struct joystick_hwdata *)
+ SDL_calloc(1, sizeof(*joystick->hwdata));
+ if (joystick->hwdata == NULL) {
+ return SDL_OutOfMemory();
+ }
+ joystick->hwdata->item = item;
+ joystick->hwdata->guid = item->guid;
+ joystick->hwdata->m_bSteamController = item->m_bSteamController;
+
+ if (item->m_bSteamController) {
+ joystick->hwdata->fd = -1;
+ SDL_GetSteamControllerInputs(&joystick->nbuttons,
+ &joystick->naxes,
+ &joystick->nhats);
+ } else {
+ int fd = open(item->path, O_RDONLY, 0);
+ if (fd < 0) {
+ SDL_free(joystick->hwdata);
+ joystick->hwdata = NULL;
+ return SDL_SetError("Unable to open %s", item->path);
+ }
+
+ joystick->hwdata->fd = fd;
+ joystick->hwdata->fname = SDL_strdup(item->path);
+ if (joystick->hwdata->fname == NULL) {
+ SDL_free(joystick->hwdata);
+ joystick->hwdata = NULL;
+ close(fd);
+ return SDL_OutOfMemory();
+ }
+
+ /* Set the joystick to non-blocking read mode */
+ fcntl(fd, F_SETFL, O_NONBLOCK);
+
+ /* Get the number of buttons and axes on the joystick */
+ ConfigJoystick(joystick, fd);
+ }
+
+ SDL_assert(item->hwdata == NULL);
+ item->hwdata = joystick->hwdata;
+
+ /* mark joystick as fresh and ready */
+ joystick->hwdata->fresh = 1;
+
+ return (0);
+}
+
+/* Function to determine if this joystick is attached to the system right now */
+SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
+{
+ return joystick->hwdata->item != NULL;
+}
+
+static SDL_INLINE void
+HandleHat(SDL_Joystick * stick, Uint8 hat, int axis, int value)
+{
+ struct hwdata_hat *the_hat;
+ const Uint8 position_map[3][3] = {
+ {SDL_HAT_LEFTUP, SDL_HAT_UP, SDL_HAT_RIGHTUP},
+ {SDL_HAT_LEFT, SDL_HAT_CENTERED, SDL_HAT_RIGHT},
+ {SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN}
+ };
+
+ the_hat = &stick->hwdata->hats[hat];
+ if (value < 0) {
+ value = 0;
+ } else if (value == 0) {
+ value = 1;
+ } else if (value > 0) {
+ value = 2;
+ }
+ if (value != the_hat->axis[axis]) {
+ the_hat->axis[axis] = value;
+ SDL_PrivateJoystickHat(stick, hat,
+ position_map[the_hat->
+ axis[1]][the_hat->axis[0]]);
+ }
+}
+
+static SDL_INLINE void
+HandleBall(SDL_Joystick * stick, Uint8 ball, int axis, int value)
+{
+ stick->hwdata->balls[ball].axis[axis] += value;
+}
+
+
+static SDL_INLINE int
+AxisCorrect(SDL_Joystick * joystick, int which, int value)
+{
+ struct axis_correct *correct;
+
+ correct = &joystick->hwdata->abs_correct[which];
+ if (correct->used) {
+ value *= 2;
+ if (value > correct->coef[0]) {
+ if (value < correct->coef[1]) {
+ return 0;
+ }
+ value -= correct->coef[1];
+ } else {
+ value -= correct->coef[0];
+ }
+ value *= correct->coef[2];
+ value >>= 13;
+ }
+
+ /* Clamp and return */
+ if (value < -32768)
+ return -32768;
+ if (value > 32767)
+ return 32767;
+
+ return value;
+}
+
+static SDL_INLINE void
+PollAllValues(SDL_Joystick * joystick)
+{
+ struct input_absinfo absinfo;
+ int a, b = 0;
+
+ /* Poll all axis */
+ for (a = ABS_X; b < ABS_MAX; a++) {
+ switch (a) {
+ case ABS_HAT0X:
+ case ABS_HAT0Y:
+ case ABS_HAT1X:
+ case ABS_HAT1Y:
+ case ABS_HAT2X:
+ case ABS_HAT2Y:
+ case ABS_HAT3X:
+ case ABS_HAT3Y:
+ /* ingore hats */
+ break;
+ default:
+ if (joystick->hwdata->abs_correct[b].used) {
+ if (ioctl(joystick->hwdata->fd, EVIOCGABS(a), &absinfo) >= 0) {
+ absinfo.value = AxisCorrect(joystick, b, absinfo.value);
+
+#ifdef DEBUG_INPUT_EVENTS
+ printf("Joystick : Re-read Axis %d (%d) val= %d\n",
+ joystick->hwdata->abs_map[b], a, absinfo.value);
+#endif
+ SDL_PrivateJoystickAxis(joystick,
+ joystick->hwdata->abs_map[b],
+ absinfo.value);
+ }
+ }
+ b++;
+ }
+ }
+}
+
+static SDL_INLINE void
+HandleInputEvents(SDL_Joystick * joystick)
+{
+ struct input_event events[32];
+ int i, len;
+ int code;
+
+ if (joystick->hwdata->fresh) {
+ PollAllValues(joystick);
+ joystick->hwdata->fresh = 0;
+ }
+
+ while ((len = read(joystick->hwdata->fd, events, (sizeof events))) > 0) {
+ len /= sizeof(events[0]);
+ for (i = 0; i < len; ++i) {
+ code = events[i].code;
+ switch (events[i].type) {
+ case EV_KEY:
+ SDL_PrivateJoystickButton(joystick,
+ joystick->hwdata->key_map[code],
+ events[i].value);
+ break;
+ case EV_ABS:
+ switch (code) {
+ case ABS_HAT0X:
+ case ABS_HAT0Y:
+ case ABS_HAT1X:
+ case ABS_HAT1Y:
+ case ABS_HAT2X:
+ case ABS_HAT2Y:
+ case ABS_HAT3X:
+ case ABS_HAT3Y:
+ code -= ABS_HAT0X;
+ HandleHat(joystick, code / 2, code % 2, events[i].value);
+ break;
+ default:
+ events[i].value =
+ AxisCorrect(joystick, code, events[i].value);
+ SDL_PrivateJoystickAxis(joystick,
+ joystick->hwdata->abs_map[code],
+ events[i].value);
+ break;
+ }
+ break;
+ case EV_REL:
+ switch (code) {
+ case REL_X:
+ case REL_Y:
+ code -= REL_X;
+ HandleBall(joystick, code / 2, code % 2, events[i].value);
+ break;
+ default:
+ break;
+ }
+ break;
+ case EV_SYN:
+ switch (code) {
+ case SYN_DROPPED :
+#ifdef DEBUG_INPUT_EVENTS
+ printf("Event SYN_DROPPED detected\n");
+#endif
+ PollAllValues(joystick);
+ break;
+ default:
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ }
+}
+
+void
+SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
+{
+ int i;
+
+ if (joystick->hwdata->m_bSteamController) {
+ SDL_UpdateSteamController(joystick);
+ return;
+ }
+
+ HandleInputEvents(joystick);
+
+ /* Deliver ball motion updates */
+ for (i = 0; i < joystick->nballs; ++i) {
+ int xrel, yrel;
+
+ xrel = joystick->hwdata->balls[i].axis[0];
+ yrel = joystick->hwdata->balls[i].axis[1];
+ if (xrel || yrel) {
+ joystick->hwdata->balls[i].axis[0] = 0;
+ joystick->hwdata->balls[i].axis[1] = 0;
+ SDL_PrivateJoystickBall(joystick, (Uint8) i, xrel, yrel);
+ }
+ }
+}
+
+/* Function to close a joystick after use */
+void
+SDL_SYS_JoystickClose(SDL_Joystick * joystick)
+{
+ if (joystick->hwdata) {
+ if (joystick->hwdata->fd >= 0) {
+ close(joystick->hwdata->fd);
+ }
+ if (joystick->hwdata->item) {
+ joystick->hwdata->item->hwdata = NULL;
+ }
+ SDL_free(joystick->hwdata->hats);
+ SDL_free(joystick->hwdata->balls);
+ SDL_free(joystick->hwdata->fname);
+ SDL_free(joystick->hwdata);
+ }
+}
+
+/* Function to perform any system-specific joystick related cleanup */
+void
+SDL_SYS_JoystickQuit(void)
+{
+ SDL_joylist_item *item = NULL;
+ SDL_joylist_item *next = NULL;
+
+ for (item = SDL_joylist; item; item = next) {
+ next = item->next;
+ SDL_free(item->path);
+ SDL_free(item->name);
+ SDL_free(item);
+ }
+
+ SDL_joylist = SDL_joylist_tail = NULL;
+
+ numjoysticks = 0;
+ instance_counter = 0;
+
+#if SDL_USE_LIBUDEV
+ SDL_UDEV_DelCallback(joystick_udev_callback);
+ SDL_UDEV_Quit();
+#endif
+
+ SDL_QuitSteamControllers();
+}
+
+SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
+{
+ return JoystickByDevIndex(device_index)->guid;
+}
+
+SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
+{
+ return joystick->hwdata->guid;
+}
+
+#endif /* SDL_JOYSTICK_LINUX */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/linux/SDL_sysjoystick_c.h b/src/3rdparty/SDL2/src/joystick/linux/SDL_sysjoystick_c.h
new file mode 100644
index 0000000..d06b387
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/linux/SDL_sysjoystick_c.h
@@ -0,0 +1,60 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include <linux/input.h>
+
+struct SDL_joylist_item;
+
+/* The private structure used to keep track of a joystick */
+struct joystick_hwdata
+{
+ int fd;
+ struct SDL_joylist_item *item;
+ SDL_JoystickGUID guid;
+ char *fname; /* Used in haptic subsystem */
+
+ /* The current Linux joystick driver maps hats to two axes */
+ struct hwdata_hat
+ {
+ int axis[2];
+ } *hats;
+ /* The current Linux joystick driver maps balls to two axes */
+ struct hwdata_ball
+ {
+ int axis[2];
+ } *balls;
+
+ /* Support for the Linux 2.4 unified input interface */
+ Uint8 key_map[KEY_MAX];
+ Uint8 abs_map[ABS_MAX];
+ struct axis_correct
+ {
+ int used;
+ int coef[3];
+ } abs_correct[ABS_MAX];
+
+ int fresh;
+
+ /* Steam Controller support */
+ SDL_bool m_bSteamController;
+};
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/psp/SDL_sysjoystick.c b/src/3rdparty/SDL2/src/joystick/psp/SDL_sysjoystick.c
new file mode 100644
index 0000000..228cbb2
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/psp/SDL_sysjoystick.c
@@ -0,0 +1,270 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_JOYSTICK_PSP
+
+/* This is the PSP implementation of the SDL joystick API */
+#include <pspctrl.h>
+#include <pspkernel.h>
+
+#include <stdio.h> /* For the definition of NULL */
+#include <stdlib.h>
+
+#include "../SDL_sysjoystick.h"
+#include "../SDL_joystick_c.h"
+
+#include "SDL_events.h"
+#include "SDL_error.h"
+#include "SDL_mutex.h"
+#include "SDL_timer.h"
+#include "../../thread/SDL_systhread.h"
+
+/* Current pad state */
+static SceCtrlData pad = { .Lx = 0, .Ly = 0, .Buttons = 0 };
+static SDL_sem *pad_sem = NULL;
+static SDL_Thread *thread = NULL;
+static int running = 0;
+static const enum PspCtrlButtons button_map[] = {
+ PSP_CTRL_TRIANGLE, PSP_CTRL_CIRCLE, PSP_CTRL_CROSS, PSP_CTRL_SQUARE,
+ PSP_CTRL_LTRIGGER, PSP_CTRL_RTRIGGER,
+ PSP_CTRL_DOWN, PSP_CTRL_LEFT, PSP_CTRL_UP, PSP_CTRL_RIGHT,
+ PSP_CTRL_SELECT, PSP_CTRL_START, PSP_CTRL_HOME, PSP_CTRL_HOLD };
+static int analog_map[256]; /* Map analog inputs to -32768 -> 32767 */
+
+typedef struct
+{
+ int x;
+ int y;
+} point;
+
+/* 4 points define the bezier-curve. */
+static point a = { 0, 0 };
+static point b = { 50, 0 };
+static point c = { 78, 32767 };
+static point d = { 128, 32767 };
+
+/* simple linear interpolation between two points */
+static SDL_INLINE void lerp (point *dest, point *a, point *b, float t)
+{
+ dest->x = a->x + (b->x - a->x)*t;
+ dest->y = a->y + (b->y - a->y)*t;
+}
+
+/* evaluate a point on a bezier-curve. t goes from 0 to 1.0 */
+static int calc_bezier_y(float t)
+{
+ point ab, bc, cd, abbc, bccd, dest;
+ lerp (&ab, &a, &b, t); /* point between a and b */
+ lerp (&bc, &b, &c, t); /* point between b and c */
+ lerp (&cd, &c, &d, t); /* point between c and d */
+ lerp (&abbc, &ab, &bc, t); /* point between ab and bc */
+ lerp (&bccd, &bc, &cd, t); /* point between bc and cd */
+ lerp (&dest, &abbc, &bccd, t); /* point on the bezier-curve */
+ return dest.y;
+}
+
+/*
+ * Collect pad data about once per frame
+ */
+int JoystickUpdate(void *data)
+{
+ while (running) {
+ SDL_SemWait(pad_sem);
+ sceCtrlPeekBufferPositive(&pad, 1);
+ SDL_SemPost(pad_sem);
+ /* Delay 1/60th of a second */
+ sceKernelDelayThread(1000000 / 60);
+ }
+ return 0;
+}
+
+
+
+/* Function to scan the system for joysticks.
+ * Joystick 0 should be the system default joystick.
+ * It should return number of joysticks, or -1 on an unrecoverable fatal error.
+ */
+int SDL_SYS_JoystickInit(void)
+{
+ int i;
+
+ /* Setup input */
+ sceCtrlSetSamplingCycle(0);
+ sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
+
+ /* Start thread to read data */
+ if((pad_sem = SDL_CreateSemaphore(1)) == NULL) {
+ return SDL_SetError("Can't create input semaphore");
+ }
+ running = 1;
+ if((thread = SDL_CreateThreadInternal(JoystickUpdate, "JoystickThread", 4096, NULL)) == NULL) {
+ return SDL_SetError("Can't create input thread");
+ }
+
+ /* Create an accurate map from analog inputs (0 to 255)
+ to SDL joystick positions (-32768 to 32767) */
+ for (i = 0; i < 128; i++)
+ {
+ float t = (float)i/127.0f;
+ analog_map[i+128] = calc_bezier_y(t);
+ analog_map[127-i] = -1 * analog_map[i+128];
+ }
+
+ return 1;
+}
+
+int SDL_SYS_NumJoysticks(void)
+{
+ return 1;
+}
+
+void SDL_SYS_JoystickDetect(void)
+{
+}
+
+/* Function to get the device-dependent name of a joystick */
+const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
+{
+ return "PSP builtin joypad";
+}
+
+/* Function to perform the mapping from device index to the instance id for this index */
+SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
+{
+ return device_index;
+}
+
+/* Function to get the device-dependent name of a joystick */
+const char *SDL_SYS_JoystickName(int index)
+{
+ if (index == 0)
+ return "PSP controller";
+
+ SDL_SetError("No joystick available with that index");
+ return(NULL);
+}
+
+/* Function to open a joystick for use.
+ The joystick to open is specified by the device index.
+ This should fill the nbuttons and naxes fields of the joystick structure.
+ It returns 0, or -1 if there is an error.
+ */
+int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
+{
+ joystick->nbuttons = 14;
+ joystick->naxes = 2;
+ joystick->nhats = 0;
+
+ return 0;
+}
+
+/* Function to determine if this joystick is attached to the system right now */
+SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
+{
+ return SDL_TRUE;
+}
+
+/* Function to update the state of a joystick - called as a device poll.
+ * This function shouldn't update the joystick structure directly,
+ * but instead should call SDL_PrivateJoystick*() to deliver events
+ * and update joystick device state.
+ */
+void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
+{
+ int i;
+ enum PspCtrlButtons buttons;
+ enum PspCtrlButtons changed;
+ unsigned char x, y;
+ static enum PspCtrlButtons old_buttons = 0;
+ static unsigned char old_x = 0, old_y = 0;
+
+ SDL_SemWait(pad_sem);
+ buttons = pad.Buttons;
+ x = pad.Lx;
+ y = pad.Ly;
+ SDL_SemPost(pad_sem);
+
+ /* Axes */
+ if(old_x != x) {
+ SDL_PrivateJoystickAxis(joystick, 0, analog_map[x]);
+ old_x = x;
+ }
+ if(old_y != y) {
+ SDL_PrivateJoystickAxis(joystick, 1, analog_map[y]);
+ old_y = y;
+ }
+
+ /* Buttons */
+ changed = old_buttons ^ buttons;
+ old_buttons = buttons;
+ if(changed) {
+ for(i=0; i<sizeof(button_map)/sizeof(button_map[0]); i++) {
+ if(changed & button_map[i]) {
+ SDL_PrivateJoystickButton(
+ joystick, i,
+ (buttons & button_map[i]) ?
+ SDL_PRESSED : SDL_RELEASED);
+ }
+ }
+ }
+
+ sceKernelDelayThread(0);
+}
+
+/* Function to close a joystick after use */
+void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
+{
+}
+
+/* Function to perform any system-specific joystick related cleanup */
+void SDL_SYS_JoystickQuit(void)
+{
+ /* Cleanup Threads and Semaphore. */
+ running = 0;
+ SDL_WaitThread(thread, NULL);
+ SDL_DestroySemaphore(pad_sem);
+}
+
+SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
+{
+ SDL_JoystickGUID guid;
+ /* the GUID is just the first 16 chars of the name for now */
+ const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
+ SDL_zero( guid );
+ SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
+ return guid;
+}
+
+SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
+{
+ SDL_JoystickGUID guid;
+ /* the GUID is just the first 16 chars of the name for now */
+ const char *name = joystick->name;
+ SDL_zero( guid );
+ SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
+ return guid;
+}
+
+#endif /* SDL_JOYSTICK_PSP */
+
+/* vim: ts=4 sw=4
+ */
diff --git a/src/3rdparty/SDL2/src/joystick/sort_controllers.py b/src/3rdparty/SDL2/src/joystick/sort_controllers.py
new file mode 100644
index 0000000..47213c2
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/sort_controllers.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+#
+# Script to sort the game controller database entries in SDL_gamecontroller.c
+
+import re
+
+
+filename = "SDL_gamecontrollerdb.h"
+input = open(filename)
+output = open(filename + ".new", "w")
+parsing_controllers = False
+controllers = []
+controller_guids = {}
+split_pattern = re.compile(r'([^"]*")([^,]*,)([^,]*,)([^"]*)(".*)')
+
+def save_controller(line):
+ global controllers
+ match = split_pattern.match(line)
+ entry = [ match.group(1), match.group(2), match.group(3) ]
+ bindings = sorted(match.group(4).split(","))
+ if (bindings[0] == ""):
+ bindings.pop(0)
+ entry.extend(",".join(bindings) + ",")
+ entry.append(match.group(5))
+ controllers.append(entry)
+
+def write_controllers():
+ global controllers
+ global controller_guids
+ for entry in sorted(controllers, key=lambda entry: entry[2]):
+ line = "".join(entry) + "\n"
+ line = line.replace("\t", " ")
+ if not line.endswith(",\n") and not line.endswith("*/\n"):
+ print("Warning: '%s' is missing a comma at the end of the line" % (line))
+ if (entry[1] in controller_guids):
+ print("Warning: entry '%s' is duplicate of entry '%s'" % (entry[2], controller_guids[entry[1]][2]))
+ controller_guids[entry[1]] = entry
+
+ output.write(line)
+ controllers = []
+ controller_guids = {}
+
+for line in input:
+ if (parsing_controllers):
+ if (line.startswith("{")):
+ output.write(line)
+ elif (line.startswith(" NULL")):
+ parsing_controllers = False
+ write_controllers()
+ output.write(line)
+ elif (line.startswith("#if")):
+ print("Parsing " + line.strip())
+ output.write(line)
+ elif (line.startswith("#endif")):
+ write_controllers()
+ output.write(line)
+ else:
+ save_controller(line)
+ else:
+ if (line.startswith("static const char *s_ControllerMappings")):
+ parsing_controllers = True
+
+ output.write(line)
+
+output.close()
+print("Finished writing %s.new" % filename)
diff --git a/src/3rdparty/SDL2/src/joystick/steam/SDL_steamcontroller.c b/src/3rdparty/SDL2/src/joystick/steam/SDL_steamcontroller.c
new file mode 100644
index 0000000..1edaa94
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/steam/SDL_steamcontroller.c
@@ -0,0 +1,52 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "../SDL_sysjoystick.h"
+#include "../SDL_joystick_c.h"
+#include "SDL_steamcontroller.h"
+
+
+void SDL_InitSteamControllers(SteamControllerConnectedCallback_t connectedCallback,
+ SteamControllerDisconnectedCallback_t disconnectedCallback)
+{
+}
+
+void SDL_GetSteamControllerInputs(int *nbuttons, int *naxes, int *nhats)
+{
+ *nbuttons = 0;
+ *naxes = 0;
+ *nhats = 0;
+}
+
+void SDL_UpdateSteamControllers(void)
+{
+}
+
+void SDL_UpdateSteamController(SDL_Joystick *joystick)
+{
+}
+
+void SDL_QuitSteamControllers(void)
+{
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/steam/SDL_steamcontroller.h b/src/3rdparty/SDL2/src/joystick/steam/SDL_steamcontroller.h
new file mode 100644
index 0000000..ce37b4d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/steam/SDL_steamcontroller.h
@@ -0,0 +1,33 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+typedef SDL_bool (*SteamControllerConnectedCallback_t)(const char *name, SDL_JoystickGUID guid, int *device_instance);
+typedef void (*SteamControllerDisconnectedCallback_t)(int device_instance);
+
+void SDL_InitSteamControllers(SteamControllerConnectedCallback_t connectedCallback,
+ SteamControllerDisconnectedCallback_t disconnectedCallback);
+void SDL_GetSteamControllerInputs(int *nbuttons, int *naxes, int *nhats);
+void SDL_UpdateSteamControllers(void);
+void SDL_UpdateSteamController(SDL_Joystick *joystick);
+void SDL_QuitSteamControllers(void);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/windows/SDL_dinputjoystick.c b/src/3rdparty/SDL2/src/joystick/windows/SDL_dinputjoystick.c
new file mode 100644
index 0000000..cff868b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/windows/SDL_dinputjoystick.c
@@ -0,0 +1,992 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "../SDL_sysjoystick.h"
+
+#if SDL_JOYSTICK_DINPUT
+
+#include "SDL_windowsjoystick_c.h"
+#include "SDL_dinputjoystick_c.h"
+#include "SDL_xinputjoystick_c.h"
+
+#ifndef DIDFT_OPTIONAL
+#define DIDFT_OPTIONAL 0x80000000
+#endif
+
+#define INPUT_QSIZE 32 /* Buffer up to 32 input messages */
+#define JOY_AXIS_THRESHOLD (((SDL_JOYSTICK_AXIS_MAX)-(SDL_JOYSTICK_AXIS_MIN))/100) /* 1% motion */
+
+/* external variables referenced. */
+extern HWND SDL_HelperWindow;
+
+/* local variables */
+static SDL_bool coinitialized = SDL_FALSE;
+static LPDIRECTINPUT8 dinput = NULL;
+static PRAWINPUTDEVICELIST SDL_RawDevList = NULL;
+static UINT SDL_RawDevListCount = 0;
+
+/* Taken from Wine - Thanks! */
+static DIOBJECTDATAFORMAT dfDIJoystick2[] = {
+ { &GUID_XAxis, DIJOFS_X, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_YAxis, DIJOFS_Y, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_ZAxis, DIJOFS_Z, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_RxAxis, DIJOFS_RX, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_RyAxis, DIJOFS_RY, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_RzAxis, DIJOFS_RZ, DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_Slider, DIJOFS_SLIDER(0), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_Slider, DIJOFS_SLIDER(1), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_POV, DIJOFS_POV(0), DIDFT_OPTIONAL | DIDFT_POV | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_POV, DIJOFS_POV(1), DIDFT_OPTIONAL | DIDFT_POV | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_POV, DIJOFS_POV(2), DIDFT_OPTIONAL | DIDFT_POV | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_POV, DIJOFS_POV(3), DIDFT_OPTIONAL | DIDFT_POV | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(0), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(1), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(2), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(3), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(4), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(5), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(6), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(7), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(8), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(9), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(10), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(11), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(12), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(13), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(14), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(15), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(16), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(17), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(18), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(19), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(20), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(21), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(22), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(23), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(24), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(25), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(26), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(27), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(28), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(29), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(30), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(31), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(32), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(33), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(34), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(35), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(36), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(37), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(38), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(39), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(40), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(41), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(42), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(43), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(44), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(45), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(46), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(47), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(48), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(49), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(50), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(51), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(52), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(53), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(54), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(55), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(56), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(57), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(58), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(59), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(60), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(61), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(62), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(63), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(64), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(65), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(66), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(67), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(68), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(69), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(70), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(71), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(72), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(73), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(74), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(75), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(76), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(77), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(78), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(79), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(80), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(81), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(82), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(83), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(84), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(85), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(86), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(87), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(88), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(89), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(90), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(91), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(92), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(93), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(94), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(95), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(96), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(97), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(98), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(99), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(100), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(101), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(102), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(103), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(104), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(105), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(106), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(107), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(108), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(109), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(110), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(111), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(112), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(113), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(114), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(115), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(116), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(117), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(118), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(119), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(120), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(121), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(122), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(123), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(124), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(125), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(126), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { NULL, DIJOFS_BUTTON(127), DIDFT_OPTIONAL | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_XAxis, FIELD_OFFSET(DIJOYSTATE2, lVX), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_YAxis, FIELD_OFFSET(DIJOYSTATE2, lVY), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_ZAxis, FIELD_OFFSET(DIJOYSTATE2, lVZ), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_RxAxis, FIELD_OFFSET(DIJOYSTATE2, lVRx), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_RyAxis, FIELD_OFFSET(DIJOYSTATE2, lVRy), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_RzAxis, FIELD_OFFSET(DIJOYSTATE2, lVRz), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_Slider, FIELD_OFFSET(DIJOYSTATE2, rglVSlider[0]), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_Slider, FIELD_OFFSET(DIJOYSTATE2, rglVSlider[1]), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_XAxis, FIELD_OFFSET(DIJOYSTATE2, lAX), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_YAxis, FIELD_OFFSET(DIJOYSTATE2, lAY), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_ZAxis, FIELD_OFFSET(DIJOYSTATE2, lAZ), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_RxAxis, FIELD_OFFSET(DIJOYSTATE2, lARx), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_RyAxis, FIELD_OFFSET(DIJOYSTATE2, lARy), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_RzAxis, FIELD_OFFSET(DIJOYSTATE2, lARz), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_Slider, FIELD_OFFSET(DIJOYSTATE2, rglASlider[0]), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_Slider, FIELD_OFFSET(DIJOYSTATE2, rglASlider[1]), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_XAxis, FIELD_OFFSET(DIJOYSTATE2, lFX), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_YAxis, FIELD_OFFSET(DIJOYSTATE2, lFY), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_ZAxis, FIELD_OFFSET(DIJOYSTATE2, lFZ), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_RxAxis, FIELD_OFFSET(DIJOYSTATE2, lFRx), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_RyAxis, FIELD_OFFSET(DIJOYSTATE2, lFRy), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_RzAxis, FIELD_OFFSET(DIJOYSTATE2, lFRz), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_Slider, FIELD_OFFSET(DIJOYSTATE2, rglFSlider[0]), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+ { &GUID_Slider, FIELD_OFFSET(DIJOYSTATE2, rglFSlider[1]), DIDFT_OPTIONAL | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0 },
+};
+
+const DIDATAFORMAT SDL_c_dfDIJoystick2 = {
+ sizeof(DIDATAFORMAT),
+ sizeof(DIOBJECTDATAFORMAT),
+ DIDF_ABSAXIS,
+ sizeof(DIJOYSTATE2),
+ SDL_arraysize(dfDIJoystick2),
+ dfDIJoystick2
+};
+
+/* Convert a DirectInput return code to a text message */
+static int
+SetDIerror(const char *function, HRESULT code)
+{
+ /*
+ return SDL_SetError("%s() [%s]: %s", function,
+ DXGetErrorString9A(code), DXGetErrorDescription9A(code));
+ */
+ return SDL_SetError("%s() DirectX error 0x%8.8lx", function, code);
+}
+
+static SDL_bool
+SDL_IsXInputDevice(const GUID* pGuidProductFromDirectInput)
+{
+ static GUID IID_ValveStreamingGamepad = { MAKELONG(0x28DE, 0x11FF), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
+ static GUID IID_X360WiredGamepad = { MAKELONG(0x045E, 0x02A1), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
+ static GUID IID_X360WirelessGamepad = { MAKELONG(0x045E, 0x028E), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
+ static GUID IID_XOneWiredGamepad = { MAKELONG(0x045E, 0x02FF), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
+ static GUID IID_XOneWirelessGamepad = { MAKELONG(0x045E, 0x02DD), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
+ static GUID IID_XOneNewWirelessGamepad = { MAKELONG(0x045E, 0x02D1), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
+ static GUID IID_XOneSWirelessGamepad = { MAKELONG(0x045E, 0x02EA), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
+ static GUID IID_XOneSBluetoothGamepad = { MAKELONG(0x045E, 0x02E0), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
+ static GUID IID_XOneEliteWirelessGamepad = { MAKELONG(0x045E, 0x02E3), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } };
+
+ static const GUID *s_XInputProductGUID[] = {
+ &IID_ValveStreamingGamepad,
+ &IID_X360WiredGamepad, /* Microsoft's wired X360 controller for Windows. */
+ &IID_X360WirelessGamepad, /* Microsoft's wireless X360 controller for Windows. */
+ &IID_XOneWiredGamepad, /* Microsoft's wired Xbox One controller for Windows. */
+ &IID_XOneWirelessGamepad, /* Microsoft's wireless Xbox One controller for Windows. */
+ &IID_XOneNewWirelessGamepad, /* Microsoft's updated wireless Xbox One controller (w/ 3.5 mm jack) for Windows. */
+ &IID_XOneSWirelessGamepad, /* Microsoft's wireless Xbox One S controller for Windows. */
+ &IID_XOneSBluetoothGamepad, /* Microsoft's Bluetooth Xbox One S controller for Windows. */
+ &IID_XOneEliteWirelessGamepad /* Microsoft's wireless Xbox One Elite controller for Windows. */
+ };
+
+ size_t iDevice;
+ UINT i;
+
+ if (!SDL_XINPUT_Enabled()) {
+ return SDL_FALSE;
+ }
+
+ /* Check for well known XInput device GUIDs */
+ /* This lets us skip RAWINPUT for popular devices. Also, we need to do this for the Valve Streaming Gamepad because it's virtualized and doesn't show up in the device list. */
+ for (iDevice = 0; iDevice < SDL_arraysize(s_XInputProductGUID); ++iDevice) {
+ if (SDL_memcmp(pGuidProductFromDirectInput, s_XInputProductGUID[iDevice], sizeof(GUID)) == 0) {
+ return SDL_TRUE;
+ }
+ }
+
+ /* Go through RAWINPUT (WinXP and later) to find HID devices. */
+ /* Cache this if we end up using it. */
+ if (SDL_RawDevList == NULL) {
+ if ((GetRawInputDeviceList(NULL, &SDL_RawDevListCount, sizeof(RAWINPUTDEVICELIST)) == -1) || (!SDL_RawDevListCount)) {
+ return SDL_FALSE; /* oh well. */
+ }
+
+ SDL_RawDevList = (PRAWINPUTDEVICELIST)SDL_malloc(sizeof(RAWINPUTDEVICELIST) * SDL_RawDevListCount);
+ if (SDL_RawDevList == NULL) {
+ SDL_OutOfMemory();
+ return SDL_FALSE;
+ }
+
+ if (GetRawInputDeviceList(SDL_RawDevList, &SDL_RawDevListCount, sizeof(RAWINPUTDEVICELIST)) == -1) {
+ SDL_free(SDL_RawDevList);
+ SDL_RawDevList = NULL;
+ return SDL_FALSE; /* oh well. */
+ }
+ }
+
+ for (i = 0; i < SDL_RawDevListCount; i++) {
+ RID_DEVICE_INFO rdi;
+ char devName[128];
+ UINT rdiSize = sizeof(rdi);
+ UINT nameSize = SDL_arraysize(devName);
+
+ rdi.cbSize = sizeof(rdi);
+ if ((SDL_RawDevList[i].dwType == RIM_TYPEHID) &&
+ (GetRawInputDeviceInfoA(SDL_RawDevList[i].hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) != ((UINT)-1)) &&
+ (MAKELONG(rdi.hid.dwVendorId, rdi.hid.dwProductId) == ((LONG)pGuidProductFromDirectInput->Data1)) &&
+ (GetRawInputDeviceInfoA(SDL_RawDevList[i].hDevice, RIDI_DEVICENAME, devName, &nameSize) != ((UINT)-1)) &&
+ (SDL_strstr(devName, "IG_") != NULL)) {
+ return SDL_TRUE;
+ }
+ }
+
+ return SDL_FALSE;
+}
+
+int
+SDL_DINPUT_JoystickInit(void)
+{
+ HRESULT result;
+ HINSTANCE instance;
+
+ result = WIN_CoInitialize();
+ if (FAILED(result)) {
+ return SetDIerror("CoInitialize", result);
+ }
+
+ coinitialized = SDL_TRUE;
+
+ result = CoCreateInstance(&CLSID_DirectInput8, NULL, CLSCTX_INPROC_SERVER,
+ &IID_IDirectInput8, (LPVOID)&dinput);
+
+ if (FAILED(result)) {
+ return SetDIerror("CoCreateInstance", result);
+ }
+
+ /* Because we used CoCreateInstance, we need to Initialize it, first. */
+ instance = GetModuleHandle(NULL);
+ if (instance == NULL) {
+ return SDL_SetError("GetModuleHandle() failed with error code %lu.", GetLastError());
+ }
+ result = IDirectInput8_Initialize(dinput, instance, DIRECTINPUT_VERSION);
+
+ if (FAILED(result)) {
+ return SetDIerror("IDirectInput::Initialize", result);
+ }
+ return 0;
+}
+
+/* helper function for direct input, gets called for each connected joystick */
+static BOOL CALLBACK
+EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
+{
+ const Uint16 BUS_USB = 0x03;
+ const Uint16 BUS_BLUETOOTH = 0x05;
+ JoyStick_DeviceData *pNewJoystick;
+ JoyStick_DeviceData *pPrevJoystick = NULL;
+ const DWORD devtype = (pdidInstance->dwDevType & 0xFF);
+ Uint16 *guid16;
+ WCHAR hidPath[MAX_PATH];
+
+ if (devtype == DI8DEVTYPE_SUPPLEMENTAL) {
+ /* Add any supplemental devices that should be ignored here */
+#define MAKE_TABLE_ENTRY(VID, PID) ((((DWORD)PID)<<16)|VID)
+ static DWORD ignored_devices[] = {
+ MAKE_TABLE_ENTRY(0, 0)
+ };
+#undef MAKE_TABLE_ENTRY
+ unsigned int i;
+
+ for (i = 0; i < SDL_arraysize(ignored_devices); ++i) {
+ if (pdidInstance->guidProduct.Data1 == ignored_devices[i]) {
+ return DIENUM_CONTINUE;
+ }
+ }
+ }
+
+ if (SDL_IsXInputDevice(&pdidInstance->guidProduct)) {
+ return DIENUM_CONTINUE; /* ignore XInput devices here, keep going. */
+ }
+
+ {
+ HRESULT result;
+ LPDIRECTINPUTDEVICE8 device;
+ LPDIRECTINPUTDEVICE8 InputDevice;
+ DIPROPGUIDANDPATH dipdw2;
+
+ result = IDirectInput8_CreateDevice(dinput, &(pdidInstance->guidInstance), &device, NULL);
+ if (FAILED(result)) {
+ return DIENUM_CONTINUE; /* better luck next time? */
+ }
+
+ /* Now get the IDirectInputDevice8 interface, instead. */
+ result = IDirectInputDevice8_QueryInterface(device, &IID_IDirectInputDevice8, (LPVOID *)&InputDevice);
+ /* We are done with this object. Use the stored one from now on. */
+ IDirectInputDevice8_Release(device);
+ if (FAILED(result)) {
+ return DIENUM_CONTINUE; /* better luck next time? */
+ }
+ dipdw2.diph.dwSize = sizeof(dipdw2);
+ dipdw2.diph.dwHeaderSize = sizeof(dipdw2.diph);
+ dipdw2.diph.dwObj = 0; // device property
+ dipdw2.diph.dwHow = DIPH_DEVICE;
+
+ result = IDirectInputDevice8_GetProperty(InputDevice, DIPROP_GUIDANDPATH, &dipdw2.diph);
+ IDirectInputDevice8_Release(InputDevice);
+ if (FAILED(result)) {
+ return DIENUM_CONTINUE; /* better luck next time? */
+ }
+
+ /* Get device path, compare that instead of GUID, additionally update GUIDs of joysticks with matching paths, in case they're not open yet. */
+ SDL_wcslcpy(hidPath, dipdw2.wszPath, SDL_arraysize(hidPath));
+ }
+
+ pNewJoystick = *(JoyStick_DeviceData **)pContext;
+ while (pNewJoystick) {
+ if (SDL_wcscmp(pNewJoystick->hidPath, hidPath) == 0) {
+ /* if we are replacing the front of the list then update it */
+ if (pNewJoystick == *(JoyStick_DeviceData **)pContext) {
+ *(JoyStick_DeviceData **)pContext = pNewJoystick->pNext;
+ } else if (pPrevJoystick) {
+ pPrevJoystick->pNext = pNewJoystick->pNext;
+ }
+
+ // Update with new guid/etc, if it has changed
+ pNewJoystick->dxdevice = *pdidInstance;
+
+ pNewJoystick->pNext = SYS_Joystick;
+ SYS_Joystick = pNewJoystick;
+
+ return DIENUM_CONTINUE; /* already have this joystick loaded, just keep going */
+ }
+
+ pPrevJoystick = pNewJoystick;
+ pNewJoystick = pNewJoystick->pNext;
+ }
+
+ pNewJoystick = (JoyStick_DeviceData *)SDL_malloc(sizeof(JoyStick_DeviceData));
+ if (!pNewJoystick) {
+ return DIENUM_CONTINUE; /* better luck next time? */
+ }
+
+ SDL_zerop(pNewJoystick);
+ SDL_wcslcpy(pNewJoystick->hidPath, hidPath, SDL_arraysize(pNewJoystick->hidPath));
+ pNewJoystick->joystickname = WIN_StringToUTF8(pdidInstance->tszProductName);
+ if (!pNewJoystick->joystickname) {
+ SDL_free(pNewJoystick);
+ return DIENUM_CONTINUE; /* better luck next time? */
+ }
+
+ SDL_memcpy(&(pNewJoystick->dxdevice), pdidInstance,
+ sizeof(DIDEVICEINSTANCE));
+
+ SDL_memset(pNewJoystick->guid.data, 0, sizeof(pNewJoystick->guid.data));
+
+ guid16 = (Uint16 *)pNewJoystick->guid.data;
+ if (SDL_memcmp(&pdidInstance->guidProduct.Data4[2], "PIDVID", 6) == 0) {
+ *guid16++ = SDL_SwapLE16(BUS_USB);
+ *guid16++ = 0;
+ *guid16++ = SDL_SwapLE16((Uint16)LOWORD(pdidInstance->guidProduct.Data1)); /* vendor */
+ *guid16++ = 0;
+ *guid16++ = SDL_SwapLE16((Uint16)HIWORD(pdidInstance->guidProduct.Data1)); /* product */
+ *guid16++ = 0;
+ *guid16++ = 0; /* version */
+ *guid16++ = 0;
+ } else {
+ *guid16++ = SDL_SwapLE16(BUS_BLUETOOTH);
+ *guid16++ = 0;
+ SDL_strlcpy((char*)guid16, pNewJoystick->joystickname, sizeof(pNewJoystick->guid.data) - 4);
+ }
+
+ if (SDL_IsGameControllerNameAndGUID(pNewJoystick->joystickname, pNewJoystick->guid) &&
+ SDL_ShouldIgnoreGameController(pNewJoystick->joystickname, pNewJoystick->guid)) {
+ SDL_free(pNewJoystick);
+ return DIENUM_CONTINUE;
+ }
+
+ SDL_SYS_AddJoystickDevice(pNewJoystick);
+
+ return DIENUM_CONTINUE; /* get next device, please */
+}
+
+void
+SDL_DINPUT_JoystickDetect(JoyStick_DeviceData **pContext)
+{
+ IDirectInput8_EnumDevices(dinput, DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, pContext, DIEDFL_ATTACHEDONLY);
+
+ if (SDL_RawDevList) {
+ SDL_free(SDL_RawDevList); /* in case we used this in DirectInput detection */
+ SDL_RawDevList = NULL;
+ }
+ SDL_RawDevListCount = 0;
+}
+
+static BOOL CALLBACK
+EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
+{
+ SDL_Joystick *joystick = (SDL_Joystick *)pvRef;
+ HRESULT result;
+ input_t *in = &joystick->hwdata->Inputs[joystick->hwdata->NumInputs];
+
+ if (dev->dwType & DIDFT_BUTTON) {
+ in->type = BUTTON;
+ in->num = joystick->nbuttons;
+ in->ofs = DIJOFS_BUTTON(in->num);
+ joystick->nbuttons++;
+ } else if (dev->dwType & DIDFT_POV) {
+ in->type = HAT;
+ in->num = joystick->nhats;
+ in->ofs = DIJOFS_POV(in->num);
+ joystick->nhats++;
+ } else if (dev->dwType & DIDFT_AXIS) {
+ DIPROPRANGE diprg;
+ DIPROPDWORD dilong;
+
+ in->type = AXIS;
+ in->num = joystick->naxes;
+ if (!SDL_memcmp(&dev->guidType, &GUID_XAxis, sizeof(dev->guidType)))
+ in->ofs = DIJOFS_X;
+ else if (!SDL_memcmp(&dev->guidType, &GUID_YAxis, sizeof(dev->guidType)))
+ in->ofs = DIJOFS_Y;
+ else if (!SDL_memcmp(&dev->guidType, &GUID_ZAxis, sizeof(dev->guidType)))
+ in->ofs = DIJOFS_Z;
+ else if (!SDL_memcmp(&dev->guidType, &GUID_RxAxis, sizeof(dev->guidType)))
+ in->ofs = DIJOFS_RX;
+ else if (!SDL_memcmp(&dev->guidType, &GUID_RyAxis, sizeof(dev->guidType)))
+ in->ofs = DIJOFS_RY;
+ else if (!SDL_memcmp(&dev->guidType, &GUID_RzAxis, sizeof(dev->guidType)))
+ in->ofs = DIJOFS_RZ;
+ else if (!SDL_memcmp(&dev->guidType, &GUID_Slider, sizeof(dev->guidType))) {
+ in->ofs = DIJOFS_SLIDER(joystick->hwdata->NumSliders);
+ ++joystick->hwdata->NumSliders;
+ } else {
+ return DIENUM_CONTINUE; /* not an axis we can grok */
+ }
+
+ diprg.diph.dwSize = sizeof(diprg);
+ diprg.diph.dwHeaderSize = sizeof(diprg.diph);
+ diprg.diph.dwObj = dev->dwType;
+ diprg.diph.dwHow = DIPH_BYID;
+ diprg.lMin = SDL_JOYSTICK_AXIS_MIN;
+ diprg.lMax = SDL_JOYSTICK_AXIS_MAX;
+
+ result =
+ IDirectInputDevice8_SetProperty(joystick->hwdata->InputDevice,
+ DIPROP_RANGE, &diprg.diph);
+ if (FAILED(result)) {
+ return DIENUM_CONTINUE; /* don't use this axis */
+ }
+
+ /* Set dead zone to 0. */
+ dilong.diph.dwSize = sizeof(dilong);
+ dilong.diph.dwHeaderSize = sizeof(dilong.diph);
+ dilong.diph.dwObj = dev->dwType;
+ dilong.diph.dwHow = DIPH_BYID;
+ dilong.dwData = 0;
+ result =
+ IDirectInputDevice8_SetProperty(joystick->hwdata->InputDevice,
+ DIPROP_DEADZONE, &dilong.diph);
+ if (FAILED(result)) {
+ return DIENUM_CONTINUE; /* don't use this axis */
+ }
+
+ joystick->naxes++;
+ } else {
+ /* not supported at this time */
+ return DIENUM_CONTINUE;
+ }
+
+ joystick->hwdata->NumInputs++;
+
+ if (joystick->hwdata->NumInputs == MAX_INPUTS) {
+ return DIENUM_STOP; /* too many */
+ }
+
+ return DIENUM_CONTINUE;
+}
+
+/* Sort using the data offset into the DInput struct.
+ * This gives a reasonable ordering for the inputs.
+ */
+static int
+SortDevFunc(const void *a, const void *b)
+{
+ const input_t *inputA = (const input_t*)a;
+ const input_t *inputB = (const input_t*)b;
+
+ if (inputA->ofs < inputB->ofs)
+ return -1;
+ if (inputA->ofs > inputB->ofs)
+ return 1;
+ return 0;
+}
+
+/* Sort the input objects and recalculate the indices for each input. */
+static void
+SortDevObjects(SDL_Joystick *joystick)
+{
+ input_t *inputs = joystick->hwdata->Inputs;
+ int nButtons = 0;
+ int nHats = 0;
+ int nAxis = 0;
+ int n;
+
+ SDL_qsort(inputs, joystick->hwdata->NumInputs, sizeof(input_t), SortDevFunc);
+
+ for (n = 0; n < joystick->hwdata->NumInputs; n++) {
+ switch (inputs[n].type) {
+ case BUTTON:
+ inputs[n].num = nButtons;
+ nButtons++;
+ break;
+
+ case HAT:
+ inputs[n].num = nHats;
+ nHats++;
+ break;
+
+ case AXIS:
+ inputs[n].num = nAxis;
+ nAxis++;
+ break;
+ }
+ }
+}
+
+int
+SDL_DINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice)
+{
+ HRESULT result;
+ LPDIRECTINPUTDEVICE8 device;
+ DIPROPDWORD dipdw;
+
+ joystick->hwdata->buffered = SDL_TRUE;
+ joystick->hwdata->Capabilities.dwSize = sizeof(DIDEVCAPS);
+
+ SDL_zero(dipdw);
+ dipdw.diph.dwSize = sizeof(DIPROPDWORD);
+ dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
+
+ result =
+ IDirectInput8_CreateDevice(dinput,
+ &(joystickdevice->dxdevice.guidInstance), &device, NULL);
+ if (FAILED(result)) {
+ return SetDIerror("IDirectInput::CreateDevice", result);
+ }
+
+ /* Now get the IDirectInputDevice8 interface, instead. */
+ result = IDirectInputDevice8_QueryInterface(device,
+ &IID_IDirectInputDevice8,
+ (LPVOID *)& joystick->
+ hwdata->InputDevice);
+ /* We are done with this object. Use the stored one from now on. */
+ IDirectInputDevice8_Release(device);
+
+ if (FAILED(result)) {
+ return SetDIerror("IDirectInputDevice8::QueryInterface", result);
+ }
+
+ /* Acquire shared access. Exclusive access is required for forces,
+ * though. */
+ result =
+ IDirectInputDevice8_SetCooperativeLevel(joystick->hwdata->
+ InputDevice, SDL_HelperWindow,
+ DISCL_EXCLUSIVE |
+ DISCL_BACKGROUND);
+ if (FAILED(result)) {
+ return SetDIerror("IDirectInputDevice8::SetCooperativeLevel", result);
+ }
+
+ /* Use the extended data structure: DIJOYSTATE2. */
+ result =
+ IDirectInputDevice8_SetDataFormat(joystick->hwdata->InputDevice,
+ &SDL_c_dfDIJoystick2);
+ if (FAILED(result)) {
+ return SetDIerror("IDirectInputDevice8::SetDataFormat", result);
+ }
+
+ /* Get device capabilities */
+ result =
+ IDirectInputDevice8_GetCapabilities(joystick->hwdata->InputDevice,
+ &joystick->hwdata->Capabilities);
+ if (FAILED(result)) {
+ return SetDIerror("IDirectInputDevice8::GetCapabilities", result);
+ }
+
+ /* Force capable? */
+ if (joystick->hwdata->Capabilities.dwFlags & DIDC_FORCEFEEDBACK) {
+
+ result = IDirectInputDevice8_Acquire(joystick->hwdata->InputDevice);
+ if (FAILED(result)) {
+ return SetDIerror("IDirectInputDevice8::Acquire", result);
+ }
+
+ /* reset all actuators. */
+ result =
+ IDirectInputDevice8_SendForceFeedbackCommand(joystick->hwdata->
+ InputDevice,
+ DISFFC_RESET);
+
+ /* Not necessarily supported, ignore if not supported.
+ if (FAILED(result)) {
+ return SetDIerror("IDirectInputDevice8::SendForceFeedbackCommand", result);
+ }
+ */
+
+ result = IDirectInputDevice8_Unacquire(joystick->hwdata->InputDevice);
+
+ if (FAILED(result)) {
+ return SetDIerror("IDirectInputDevice8::Unacquire", result);
+ }
+
+ /* Turn on auto-centering for a ForceFeedback device (until told
+ * otherwise). */
+ dipdw.diph.dwObj = 0;
+ dipdw.diph.dwHow = DIPH_DEVICE;
+ dipdw.dwData = DIPROPAUTOCENTER_ON;
+
+ result =
+ IDirectInputDevice8_SetProperty(joystick->hwdata->InputDevice,
+ DIPROP_AUTOCENTER, &dipdw.diph);
+
+ /* Not necessarily supported, ignore if not supported.
+ if (FAILED(result)) {
+ return SetDIerror("IDirectInputDevice8::SetProperty", result);
+ }
+ */
+ }
+
+ /* What buttons and axes does it have? */
+ IDirectInputDevice8_EnumObjects(joystick->hwdata->InputDevice,
+ EnumDevObjectsCallback, joystick,
+ DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV);
+
+ /* Reorder the input objects. Some devices do not report the X axis as
+ * the first axis, for example. */
+ SortDevObjects(joystick);
+
+ dipdw.diph.dwObj = 0;
+ dipdw.diph.dwHow = DIPH_DEVICE;
+ dipdw.dwData = INPUT_QSIZE;
+
+ /* Set the buffer size */
+ result =
+ IDirectInputDevice8_SetProperty(joystick->hwdata->InputDevice,
+ DIPROP_BUFFERSIZE, &dipdw.diph);
+
+ if (result == DI_POLLEDDEVICE) {
+ /* This device doesn't support buffering, so we're forced
+ * to use less reliable polling. */
+ joystick->hwdata->buffered = SDL_FALSE;
+ } else if (FAILED(result)) {
+ return SetDIerror("IDirectInputDevice8::SetProperty", result);
+ }
+ return 0;
+}
+
+static Uint8
+TranslatePOV(DWORD value)
+{
+ const int HAT_VALS[] = {
+ SDL_HAT_UP,
+ SDL_HAT_UP | SDL_HAT_RIGHT,
+ SDL_HAT_RIGHT,
+ SDL_HAT_DOWN | SDL_HAT_RIGHT,
+ SDL_HAT_DOWN,
+ SDL_HAT_DOWN | SDL_HAT_LEFT,
+ SDL_HAT_LEFT,
+ SDL_HAT_UP | SDL_HAT_LEFT
+ };
+
+ if (LOWORD(value) == 0xFFFF)
+ return SDL_HAT_CENTERED;
+
+ /* Round the value up: */
+ value += 4500 / 2;
+ value %= 36000;
+ value /= 4500;
+
+ if (value >= 8)
+ return SDL_HAT_CENTERED; /* shouldn't happen */
+
+ return HAT_VALS[value];
+}
+
+static void
+UpdateDINPUTJoystickState_Buffered(SDL_Joystick * joystick)
+{
+ int i;
+ HRESULT result;
+ DWORD numevents;
+ DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE];
+
+ numevents = INPUT_QSIZE;
+ result =
+ IDirectInputDevice8_GetDeviceData(joystick->hwdata->InputDevice,
+ sizeof(DIDEVICEOBJECTDATA), evtbuf,
+ &numevents, 0);
+ if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
+ IDirectInputDevice8_Acquire(joystick->hwdata->InputDevice);
+ result =
+ IDirectInputDevice8_GetDeviceData(joystick->hwdata->InputDevice,
+ sizeof(DIDEVICEOBJECTDATA),
+ evtbuf, &numevents, 0);
+ }
+
+ /* Handle the events or punt */
+ if (FAILED(result)) {
+ joystick->hwdata->send_remove_event = SDL_TRUE;
+ joystick->hwdata->removed = SDL_TRUE;
+ return;
+ }
+
+ for (i = 0; i < (int)numevents; ++i) {
+ int j;
+
+ for (j = 0; j < joystick->hwdata->NumInputs; ++j) {
+ const input_t *in = &joystick->hwdata->Inputs[j];
+
+ if (evtbuf[i].dwOfs != in->ofs)
+ continue;
+
+ switch (in->type) {
+ case AXIS:
+ SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)evtbuf[i].dwData);
+ break;
+ case BUTTON:
+ SDL_PrivateJoystickButton(joystick, in->num,
+ (Uint8)(evtbuf[i].dwData ? SDL_PRESSED : SDL_RELEASED));
+ break;
+ case HAT:
+ {
+ Uint8 pos = TranslatePOV(evtbuf[i].dwData);
+ SDL_PrivateJoystickHat(joystick, in->num, pos);
+ }
+ break;
+ }
+ }
+ }
+}
+
+/* Function to update the state of a joystick - called as a device poll.
+ * This function shouldn't update the joystick structure directly,
+ * but instead should call SDL_PrivateJoystick*() to deliver events
+ * and update joystick device state.
+ */
+static void
+UpdateDINPUTJoystickState_Polled(SDL_Joystick * joystick)
+{
+ DIJOYSTATE2 state;
+ HRESULT result;
+ int i;
+
+ result =
+ IDirectInputDevice8_GetDeviceState(joystick->hwdata->InputDevice,
+ sizeof(DIJOYSTATE2), &state);
+ if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
+ IDirectInputDevice8_Acquire(joystick->hwdata->InputDevice);
+ result =
+ IDirectInputDevice8_GetDeviceState(joystick->hwdata->InputDevice,
+ sizeof(DIJOYSTATE2), &state);
+ }
+
+ if (result != DI_OK) {
+ joystick->hwdata->send_remove_event = SDL_TRUE;
+ joystick->hwdata->removed = SDL_TRUE;
+ return;
+ }
+
+ /* Set each known axis, button and POV. */
+ for (i = 0; i < joystick->hwdata->NumInputs; ++i) {
+ const input_t *in = &joystick->hwdata->Inputs[i];
+
+ switch (in->type) {
+ case AXIS:
+ switch (in->ofs) {
+ case DIJOFS_X:
+ SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)state.lX);
+ break;
+ case DIJOFS_Y:
+ SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)state.lY);
+ break;
+ case DIJOFS_Z:
+ SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)state.lZ);
+ break;
+ case DIJOFS_RX:
+ SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)state.lRx);
+ break;
+ case DIJOFS_RY:
+ SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)state.lRy);
+ break;
+ case DIJOFS_RZ:
+ SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)state.lRz);
+ break;
+ case DIJOFS_SLIDER(0):
+ SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)state.rglSlider[0]);
+ break;
+ case DIJOFS_SLIDER(1):
+ SDL_PrivateJoystickAxis(joystick, in->num, (Sint16)state.rglSlider[1]);
+ break;
+ }
+ break;
+
+ case BUTTON:
+ SDL_PrivateJoystickButton(joystick, in->num,
+ (Uint8)(state.rgbButtons[in->ofs - DIJOFS_BUTTON0] ? SDL_PRESSED : SDL_RELEASED));
+ break;
+ case HAT:
+ {
+ Uint8 pos = TranslatePOV(state.rgdwPOV[in->ofs - DIJOFS_POV(0)]);
+ SDL_PrivateJoystickHat(joystick, in->num, pos);
+ break;
+ }
+ }
+ }
+}
+
+void
+SDL_DINPUT_JoystickUpdate(SDL_Joystick * joystick)
+{
+ HRESULT result;
+
+ result = IDirectInputDevice8_Poll(joystick->hwdata->InputDevice);
+ if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
+ IDirectInputDevice8_Acquire(joystick->hwdata->InputDevice);
+ IDirectInputDevice8_Poll(joystick->hwdata->InputDevice);
+ }
+
+ if (joystick->hwdata->buffered) {
+ UpdateDINPUTJoystickState_Buffered(joystick);
+ } else {
+ UpdateDINPUTJoystickState_Polled(joystick);
+ }
+}
+
+void
+SDL_DINPUT_JoystickClose(SDL_Joystick * joystick)
+{
+ IDirectInputDevice8_Unacquire(joystick->hwdata->InputDevice);
+ IDirectInputDevice8_Release(joystick->hwdata->InputDevice);
+}
+
+void
+SDL_DINPUT_JoystickQuit(void)
+{
+ if (dinput != NULL) {
+ IDirectInput8_Release(dinput);
+ dinput = NULL;
+ }
+
+ if (coinitialized) {
+ WIN_CoUninitialize();
+ coinitialized = SDL_FALSE;
+ }
+}
+
+#else /* !SDL_JOYSTICK_DINPUT */
+
+typedef struct JoyStick_DeviceData JoyStick_DeviceData;
+
+int
+SDL_DINPUT_JoystickInit(void)
+{
+ return 0;
+}
+
+void
+SDL_DINPUT_JoystickDetect(JoyStick_DeviceData **pContext)
+{
+}
+
+int
+SDL_DINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice)
+{
+ return SDL_Unsupported();
+}
+
+void
+SDL_DINPUT_JoystickUpdate(SDL_Joystick * joystick)
+{
+}
+
+void
+SDL_DINPUT_JoystickClose(SDL_Joystick * joystick)
+{
+}
+
+void
+SDL_DINPUT_JoystickQuit(void)
+{
+}
+
+#endif /* SDL_JOYSTICK_DINPUT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/windows/SDL_dinputjoystick_c.h b/src/3rdparty/SDL2/src/joystick/windows/SDL_dinputjoystick_c.h
new file mode 100644
index 0000000..5cc1890
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/windows/SDL_dinputjoystick_c.h
@@ -0,0 +1,30 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+extern int SDL_DINPUT_JoystickInit(void);
+extern void SDL_DINPUT_JoystickDetect(JoyStick_DeviceData **pContext);
+extern int SDL_DINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice);
+extern void SDL_DINPUT_JoystickUpdate(SDL_Joystick * joystick);
+extern void SDL_DINPUT_JoystickClose(SDL_Joystick * joystick);
+extern void SDL_DINPUT_JoystickQuit(void);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/windows/SDL_mmjoystick.c b/src/3rdparty/SDL2/src/joystick/windows/SDL_mmjoystick.c
new file mode 100644
index 0000000..9fa8665
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/windows/SDL_mmjoystick.c
@@ -0,0 +1,461 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_JOYSTICK_WINMM
+
+/* Win32 MultiMedia Joystick driver, contributed by Andrei de A. Formiga */
+
+#include "../../core/windows/SDL_windows.h"
+#include <mmsystem.h>
+#include <regstr.h>
+
+#include "SDL_events.h"
+#include "SDL_joystick.h"
+#include "../SDL_sysjoystick.h"
+#include "../SDL_joystick_c.h"
+
+#ifdef REGSTR_VAL_JOYOEMNAME
+#undef REGSTR_VAL_JOYOEMNAME
+#endif
+#define REGSTR_VAL_JOYOEMNAME "OEMName"
+
+#define MAX_JOYSTICKS 16
+#define MAX_AXES 6 /* each joystick can have up to 6 axes */
+#define MAX_BUTTONS 32 /* and 32 buttons */
+#define JOY_BUTTON_FLAG(n) (1<<n)
+
+
+/* array to hold joystick ID values */
+static UINT SYS_JoystickID[MAX_JOYSTICKS];
+static JOYCAPSA SYS_Joystick[MAX_JOYSTICKS];
+static char *SYS_JoystickName[MAX_JOYSTICKS];
+
+/* The private structure used to keep track of a joystick */
+struct joystick_hwdata
+{
+ /* joystick ID */
+ UINT id;
+
+ /* values used to translate device-specific coordinates into
+ SDL-standard ranges */
+ struct _transaxis
+ {
+ int offset;
+ float scale;
+ } transaxis[6];
+};
+
+/* Convert a Windows Multimedia API return code to a text message */
+static void SetMMerror(char *function, int code);
+
+
+static char *
+GetJoystickName(int index, const char *szRegKey)
+{
+ /* added 7/24/2004 by Eckhard Stolberg */
+ /*
+ see if there is a joystick for the current
+ index (1-16) listed in the registry
+ */
+ char *name = NULL;
+ HKEY hTopKey;
+ HKEY hKey;
+ DWORD regsize;
+ LONG regresult;
+ char regkey[256];
+ char regvalue[256];
+ char regname[256];
+
+ SDL_snprintf(regkey, SDL_arraysize(regkey),
+#ifdef UNICODE
+ "%S\\%s\\%S",
+#else
+ "%s\\%s\\%s",
+#endif
+ REGSTR_PATH_JOYCONFIG, szRegKey, REGSTR_KEY_JOYCURR);
+ hTopKey = HKEY_LOCAL_MACHINE;
+ regresult = RegOpenKeyExA(hTopKey, regkey, 0, KEY_READ, &hKey);
+ if (regresult != ERROR_SUCCESS) {
+ hTopKey = HKEY_CURRENT_USER;
+ regresult = RegOpenKeyExA(hTopKey, regkey, 0, KEY_READ, &hKey);
+ }
+ if (regresult != ERROR_SUCCESS) {
+ return NULL;
+ }
+
+ /* find the registry key name for the joystick's properties */
+ regsize = sizeof(regname);
+ SDL_snprintf(regvalue, SDL_arraysize(regvalue), "Joystick%d%s", index + 1,
+ REGSTR_VAL_JOYOEMNAME);
+ regresult =
+ RegQueryValueExA(hKey, regvalue, 0, 0, (LPBYTE) regname, &regsize);
+ RegCloseKey(hKey);
+
+ if (regresult != ERROR_SUCCESS) {
+ return NULL;
+ }
+
+ /* open that registry key */
+ SDL_snprintf(regkey, SDL_arraysize(regkey),
+#ifdef UNICODE
+ "%S\\%s",
+#else
+ "%s\\%s",
+#endif
+ REGSTR_PATH_JOYOEM, regname);
+ regresult = RegOpenKeyExA(hTopKey, regkey, 0, KEY_READ, &hKey);
+ if (regresult != ERROR_SUCCESS) {
+ return NULL;
+ }
+
+ /* find the size for the OEM name text */
+ regsize = sizeof(regvalue);
+ regresult =
+ RegQueryValueExA(hKey, REGSTR_VAL_JOYOEMNAME, 0, 0, NULL, &regsize);
+ if (regresult == ERROR_SUCCESS) {
+ /* allocate enough memory for the OEM name text ... */
+ name = (char *) SDL_malloc(regsize);
+ if (name) {
+ /* ... and read it from the registry */
+ regresult = RegQueryValueExA(hKey,
+ REGSTR_VAL_JOYOEMNAME, 0, 0,
+ (LPBYTE) name, &regsize);
+ }
+ }
+ RegCloseKey(hKey);
+
+ return (name);
+}
+
+static int SDL_SYS_numjoysticks = 0;
+
+/* Function to scan the system for joysticks.
+ * Joystick 0 should be the system default joystick.
+ * It should return 0, or -1 on an unrecoverable fatal error.
+ */
+int
+SDL_SYS_JoystickInit(void)
+{
+ int i;
+ int maxdevs;
+ JOYINFOEX joyinfo;
+ JOYCAPSA joycaps;
+ MMRESULT result;
+
+ /* Reset the joystick ID & name mapping tables */
+ for (i = 0; i < MAX_JOYSTICKS; ++i) {
+ SYS_JoystickID[i] = 0;
+ SYS_JoystickName[i] = NULL;
+ }
+
+ /* Loop over all potential joystick devices */
+ SDL_SYS_numjoysticks = 0;
+ maxdevs = joyGetNumDevs();
+ for (i = JOYSTICKID1; i < maxdevs && SDL_SYS_numjoysticks < MAX_JOYSTICKS; ++i) {
+
+ joyinfo.dwSize = sizeof(joyinfo);
+ joyinfo.dwFlags = JOY_RETURNALL;
+ result = joyGetPosEx(i, &joyinfo);
+ if (result == JOYERR_NOERROR) {
+ result = joyGetDevCapsA(i, &joycaps, sizeof(joycaps));
+ if (result == JOYERR_NOERROR) {
+ SYS_JoystickID[SDL_SYS_numjoysticks] = i;
+ SYS_Joystick[SDL_SYS_numjoysticks] = joycaps;
+ SYS_JoystickName[SDL_SYS_numjoysticks] =
+ GetJoystickName(i, joycaps.szRegKey);
+ SDL_SYS_numjoysticks++;
+ }
+ }
+ }
+ return (SDL_SYS_numjoysticks);
+}
+
+int
+SDL_SYS_NumJoysticks(void)
+{
+ return SDL_SYS_numjoysticks;
+}
+
+void
+SDL_SYS_JoystickDetect(void)
+{
+}
+
+/* Function to get the device-dependent name of a joystick */
+const char *
+SDL_SYS_JoystickNameForDeviceIndex(int device_index)
+{
+ if (SYS_JoystickName[device_index] != NULL) {
+ return (SYS_JoystickName[device_index]);
+ } else {
+ return (SYS_Joystick[device_index].szPname);
+ }
+}
+
+/* Function to perform the mapping from device index to the instance id for this index */
+SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
+{
+ return device_index;
+}
+
+/* Function to open a joystick for use.
+ The joystick to open is specified by the device index.
+ This should fill the nbuttons and naxes fields of the joystick structure.
+ It returns 0, or -1 if there is an error.
+ */
+int
+SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
+{
+ int index, i;
+ int caps_flags[MAX_AXES - 2] =
+ { JOYCAPS_HASZ, JOYCAPS_HASR, JOYCAPS_HASU, JOYCAPS_HASV };
+ int axis_min[MAX_AXES], axis_max[MAX_AXES];
+
+
+ /* shortcut */
+ index = device_index;
+ axis_min[0] = SYS_Joystick[index].wXmin;
+ axis_max[0] = SYS_Joystick[index].wXmax;
+ axis_min[1] = SYS_Joystick[index].wYmin;
+ axis_max[1] = SYS_Joystick[index].wYmax;
+ axis_min[2] = SYS_Joystick[index].wZmin;
+ axis_max[2] = SYS_Joystick[index].wZmax;
+ axis_min[3] = SYS_Joystick[index].wRmin;
+ axis_max[3] = SYS_Joystick[index].wRmax;
+ axis_min[4] = SYS_Joystick[index].wUmin;
+ axis_max[4] = SYS_Joystick[index].wUmax;
+ axis_min[5] = SYS_Joystick[index].wVmin;
+ axis_max[5] = SYS_Joystick[index].wVmax;
+
+ /* allocate memory for system specific hardware data */
+ joystick->instance_id = device_index;
+ joystick->hwdata =
+ (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata));
+ if (joystick->hwdata == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
+
+ /* set hardware data */
+ joystick->hwdata->id = SYS_JoystickID[index];
+ for (i = 0; i < MAX_AXES; ++i) {
+ if ((i < 2) || (SYS_Joystick[index].wCaps & caps_flags[i - 2])) {
+ joystick->hwdata->transaxis[i].offset = SDL_JOYSTICK_AXIS_MIN - axis_min[i];
+ joystick->hwdata->transaxis[i].scale =
+ (float) (SDL_JOYSTICK_AXIS_MAX - SDL_JOYSTICK_AXIS_MIN) / (axis_max[i] - axis_min[i]);
+ } else {
+ joystick->hwdata->transaxis[i].offset = 0;
+ joystick->hwdata->transaxis[i].scale = 1.0; /* Just in case */
+ }
+ }
+
+ /* fill nbuttons, naxes, and nhats fields */
+ joystick->nbuttons = SYS_Joystick[index].wNumButtons;
+ joystick->naxes = SYS_Joystick[index].wNumAxes;
+ if (SYS_Joystick[index].wCaps & JOYCAPS_HASPOV) {
+ joystick->nhats = 1;
+ } else {
+ joystick->nhats = 0;
+ }
+ return (0);
+}
+
+/* Function to determine if this joystick is attached to the system right now */
+SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
+{
+ return SDL_TRUE;
+}
+
+static Uint8
+TranslatePOV(DWORD value)
+{
+ Uint8 pos;
+
+ pos = SDL_HAT_CENTERED;
+ if (value != JOY_POVCENTERED) {
+ if ((value > JOY_POVLEFT) || (value < JOY_POVRIGHT)) {
+ pos |= SDL_HAT_UP;
+ }
+ if ((value > JOY_POVFORWARD) && (value < JOY_POVBACKWARD)) {
+ pos |= SDL_HAT_RIGHT;
+ }
+ if ((value > JOY_POVRIGHT) && (value < JOY_POVLEFT)) {
+ pos |= SDL_HAT_DOWN;
+ }
+ if (value > JOY_POVBACKWARD) {
+ pos |= SDL_HAT_LEFT;
+ }
+ }
+ return (pos);
+}
+
+/* Function to update the state of a joystick - called as a device poll.
+ * This function shouldn't update the joystick structure directly,
+ * but instead should call SDL_PrivateJoystick*() to deliver events
+ * and update joystick device state.
+ */
+void
+SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
+{
+ MMRESULT result;
+ int i;
+ DWORD flags[MAX_AXES] = { JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ,
+ JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
+ };
+ DWORD pos[MAX_AXES];
+ struct _transaxis *transaxis;
+ int value;
+ JOYINFOEX joyinfo;
+
+ joyinfo.dwSize = sizeof(joyinfo);
+ joyinfo.dwFlags = JOY_RETURNALL | JOY_RETURNPOVCTS;
+ if (!joystick->hats) {
+ joyinfo.dwFlags &= ~(JOY_RETURNPOV | JOY_RETURNPOVCTS);
+ }
+ result = joyGetPosEx(joystick->hwdata->id, &joyinfo);
+ if (result != JOYERR_NOERROR) {
+ SetMMerror("joyGetPosEx", result);
+ return;
+ }
+
+ /* joystick motion events */
+ pos[0] = joyinfo.dwXpos;
+ pos[1] = joyinfo.dwYpos;
+ pos[2] = joyinfo.dwZpos;
+ pos[3] = joyinfo.dwRpos;
+ pos[4] = joyinfo.dwUpos;
+ pos[5] = joyinfo.dwVpos;
+
+ transaxis = joystick->hwdata->transaxis;
+ for (i = 0; i < joystick->naxes; i++) {
+ if (joyinfo.dwFlags & flags[i]) {
+ value = (int) (((float) pos[i] + transaxis[i].offset) * transaxis[i].scale);
+ SDL_PrivateJoystickAxis(joystick, (Uint8) i, (Sint16) value);
+ }
+ }
+
+ /* joystick button events */
+ if (joyinfo.dwFlags & JOY_RETURNBUTTONS) {
+ for (i = 0; i < joystick->nbuttons; ++i) {
+ if (joyinfo.dwButtons & JOY_BUTTON_FLAG(i)) {
+ SDL_PrivateJoystickButton(joystick, (Uint8) i, SDL_PRESSED);
+ } else {
+ SDL_PrivateJoystickButton(joystick, (Uint8) i, SDL_RELEASED);
+ }
+ }
+ }
+
+ /* joystick hat events */
+ if (joyinfo.dwFlags & JOY_RETURNPOV) {
+ Uint8 pos;
+
+ pos = TranslatePOV(joyinfo.dwPOV);
+ SDL_PrivateJoystickHat(joystick, 0, pos);
+ }
+}
+
+/* Function to close a joystick after use */
+void
+SDL_SYS_JoystickClose(SDL_Joystick * joystick)
+{
+ SDL_free(joystick->hwdata);
+}
+
+/* Function to perform any system-specific joystick related cleanup */
+void
+SDL_SYS_JoystickQuit(void)
+{
+ int i;
+ for (i = 0; i < MAX_JOYSTICKS; i++) {
+ SDL_free(SYS_JoystickName[i]);
+ SYS_JoystickName[i] = NULL;
+ }
+}
+
+SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
+{
+ SDL_JoystickGUID guid;
+ /* the GUID is just the first 16 chars of the name for now */
+ const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
+ SDL_zero( guid );
+ SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
+ return guid;
+}
+
+SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
+{
+ SDL_JoystickGUID guid;
+ /* the GUID is just the first 16 chars of the name for now */
+ const char *name = joystick->name;
+ SDL_zero( guid );
+ SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
+ return guid;
+}
+
+
+/* implementation functions */
+void
+SetMMerror(char *function, int code)
+{
+ static char *error;
+ static char errbuf[1024];
+
+ errbuf[0] = 0;
+ switch (code) {
+ case MMSYSERR_NODRIVER:
+ error = "Joystick driver not present";
+ break;
+
+ case MMSYSERR_INVALPARAM:
+ case JOYERR_PARMS:
+ error = "Invalid parameter(s)";
+ break;
+
+ case MMSYSERR_BADDEVICEID:
+ error = "Bad device ID";
+ break;
+
+ case JOYERR_UNPLUGGED:
+ error = "Joystick not attached";
+ break;
+
+ case JOYERR_NOCANDO:
+ error = "Can't capture joystick input";
+ break;
+
+ default:
+ SDL_snprintf(errbuf, SDL_arraysize(errbuf),
+ "%s: Unknown Multimedia system error: 0x%x",
+ function, code);
+ break;
+ }
+
+ if (!errbuf[0]) {
+ SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function,
+ error);
+ }
+ SDL_SetError("%s", errbuf);
+}
+
+#endif /* SDL_JOYSTICK_WINMM */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/windows/SDL_windowsjoystick.c b/src/3rdparty/SDL2/src/joystick/windows/SDL_windowsjoystick.c
new file mode 100644
index 0000000..45cbea6
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/windows/SDL_windowsjoystick.c
@@ -0,0 +1,548 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_JOYSTICK_DINPUT || SDL_JOYSTICK_XINPUT
+
+/* DirectInput joystick driver; written by Glenn Maynard, based on Andrei de
+ * A. Formiga's WINMM driver.
+ *
+ * Hats and sliders are completely untested; the app I'm writing this for mostly
+ * doesn't use them and I don't own any joysticks with them.
+ *
+ * We don't bother to use event notification here. It doesn't seem to work
+ * with polled devices, and it's fine to call IDirectInputDevice8_GetDeviceData and
+ * let it return 0 events. */
+
+#include "SDL_error.h"
+#include "SDL_assert.h"
+#include "SDL_events.h"
+#include "SDL_timer.h"
+#include "SDL_mutex.h"
+#include "SDL_joystick.h"
+#include "../SDL_sysjoystick.h"
+#include "../../thread/SDL_systhread.h"
+#include "../../core/windows/SDL_windows.h"
+#if !defined(__WINRT__)
+#include <dbt.h>
+#endif
+
+#define INITGUID /* Only set here, if set twice will cause mingw32 to break. */
+#include "SDL_windowsjoystick_c.h"
+#include "SDL_dinputjoystick_c.h"
+#include "SDL_xinputjoystick_c.h"
+
+#include "../../haptic/windows/SDL_dinputhaptic_c.h" /* For haptic hot plugging */
+#include "../../haptic/windows/SDL_xinputhaptic_c.h" /* For haptic hot plugging */
+
+
+#ifndef DEVICE_NOTIFY_WINDOW_HANDLE
+#define DEVICE_NOTIFY_WINDOW_HANDLE 0x00000000
+#endif
+
+/* local variables */
+static SDL_bool s_bDeviceAdded = SDL_FALSE;
+static SDL_bool s_bDeviceRemoved = SDL_FALSE;
+static SDL_JoystickID s_nInstanceID = -1;
+static SDL_cond *s_condJoystickThread = NULL;
+static SDL_mutex *s_mutexJoyStickEnum = NULL;
+static SDL_Thread *s_threadJoystick = NULL;
+static SDL_bool s_bJoystickThreadQuit = SDL_FALSE;
+
+JoyStick_DeviceData *SYS_Joystick; /* array to hold joystick ID values */
+
+static SDL_bool s_bWindowsDeviceChanged = SDL_FALSE;
+
+#ifdef __WINRT__
+
+typedef struct
+{
+ int unused;
+} SDL_DeviceNotificationData;
+
+static void
+SDL_CleanupDeviceNotification(SDL_DeviceNotificationData *data)
+{
+}
+
+static int
+SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data)
+{
+ return 0;
+}
+
+static SDL_bool
+SDL_WaitForDeviceNotification(SDL_DeviceNotificationData *data, SDL_mutex *mutex)
+{
+ return SDL_FALSE;
+}
+
+#else /* !__WINRT__ */
+
+typedef struct
+{
+ HRESULT coinitialized;
+ WNDCLASSEX wincl;
+ HWND messageWindow;
+ HDEVNOTIFY hNotify;
+} SDL_DeviceNotificationData;
+
+#define IDT_SDL_DEVICE_CHANGE_TIMER_1 1200
+#define IDT_SDL_DEVICE_CHANGE_TIMER_2 1201
+
+/* windowproc for our joystick detect thread message only window, to detect any USB device addition/removal */
+static LRESULT CALLBACK
+SDL_PrivateJoystickDetectProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ switch (message) {
+ case WM_DEVICECHANGE:
+ switch (wParam) {
+ case DBT_DEVICEARRIVAL:
+ case DBT_DEVICEREMOVECOMPLETE:
+ if (((DEV_BROADCAST_HDR*)lParam)->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) {
+ /* notify 300ms and 2 seconds later to ensure all APIs have updated status */
+ SetTimer(hwnd, IDT_SDL_DEVICE_CHANGE_TIMER_1, 300, NULL);
+ SetTimer(hwnd, IDT_SDL_DEVICE_CHANGE_TIMER_2, 2000, NULL);
+ }
+ break;
+ }
+ return 0;
+ case WM_TIMER:
+ KillTimer(hwnd, wParam);
+ s_bWindowsDeviceChanged = SDL_TRUE;
+ return 0;
+ }
+
+ return DefWindowProc (hwnd, message, wParam, lParam);
+}
+
+static void
+SDL_CleanupDeviceNotification(SDL_DeviceNotificationData *data)
+{
+ if (data->hNotify)
+ UnregisterDeviceNotification(data->hNotify);
+
+ if (data->messageWindow)
+ DestroyWindow(data->messageWindow);
+
+ UnregisterClass(data->wincl.lpszClassName, data->wincl.hInstance);
+
+ if (data->coinitialized == S_OK) {
+ WIN_CoUninitialize();
+ }
+}
+
+static int
+SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data)
+{
+ DEV_BROADCAST_DEVICEINTERFACE dbh;
+ GUID GUID_DEVINTERFACE_HID = { 0x4D1E55B2L, 0xF16F, 0x11CF, { 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } };
+
+ SDL_zerop(data);
+
+ data->coinitialized = WIN_CoInitialize();
+
+ data->wincl.hInstance = GetModuleHandle(NULL);
+ data->wincl.lpszClassName = L"Message";
+ data->wincl.lpfnWndProc = SDL_PrivateJoystickDetectProc; /* This function is called by windows */
+ data->wincl.cbSize = sizeof (WNDCLASSEX);
+
+ if (!RegisterClassEx(&data->wincl)) {
+ WIN_SetError("Failed to create register class for joystick autodetect");
+ SDL_CleanupDeviceNotification(data);
+ return -1;
+ }
+
+ data->messageWindow = (HWND)CreateWindowEx(0, L"Message", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
+ if (!data->messageWindow) {
+ WIN_SetError("Failed to create message window for joystick autodetect");
+ SDL_CleanupDeviceNotification(data);
+ return -1;
+ }
+
+ SDL_zero(dbh);
+ dbh.dbcc_size = sizeof(dbh);
+ dbh.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
+ dbh.dbcc_classguid = GUID_DEVINTERFACE_HID;
+
+ data->hNotify = RegisterDeviceNotification(data->messageWindow, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE);
+ if (!data->hNotify) {
+ WIN_SetError("Failed to create notify device for joystick autodetect");
+ SDL_CleanupDeviceNotification(data);
+ return -1;
+ }
+ return 0;
+}
+
+static SDL_bool
+SDL_WaitForDeviceNotification(SDL_DeviceNotificationData *data, SDL_mutex *mutex)
+{
+ MSG msg;
+ int lastret = 1;
+
+ if (!data->messageWindow) {
+ return SDL_FALSE; /* device notifications require a window */
+ }
+
+ SDL_UnlockMutex(mutex);
+ while (lastret > 0 && s_bWindowsDeviceChanged == SDL_FALSE) {
+ lastret = GetMessage(&msg, NULL, 0, 0); /* WM_QUIT causes return value of 0 */
+ if (lastret > 0) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+ SDL_LockMutex(mutex);
+ return (lastret != -1) ? SDL_TRUE : SDL_FALSE;
+}
+
+#endif /* __WINRT__ */
+
+/* Function/thread to scan the system for joysticks. */
+static int
+SDL_JoystickThread(void *_data)
+{
+ SDL_DeviceNotificationData notification_data;
+
+#if SDL_JOYSTICK_XINPUT
+ SDL_bool bOpenedXInputDevices[XUSER_MAX_COUNT];
+ SDL_zero(bOpenedXInputDevices);
+#endif
+
+ if (SDL_CreateDeviceNotification(&notification_data) < 0) {
+ return -1;
+ }
+
+ SDL_LockMutex(s_mutexJoyStickEnum);
+ while (s_bJoystickThreadQuit == SDL_FALSE) {
+ SDL_bool bXInputChanged = SDL_FALSE;
+
+ if (SDL_WaitForDeviceNotification(&notification_data, s_mutexJoyStickEnum) == SDL_FALSE) {
+#if SDL_JOYSTICK_XINPUT
+ /* WM_DEVICECHANGE not working, poll for new XINPUT controllers */
+ SDL_CondWaitTimeout(s_condJoystickThread, s_mutexJoyStickEnum, 1000);
+ if (SDL_XINPUT_Enabled() && XINPUTGETCAPABILITIES) {
+ /* scan for any change in XInput devices */
+ Uint8 userId;
+ for (userId = 0; userId < XUSER_MAX_COUNT; userId++) {
+ XINPUT_CAPABILITIES capabilities;
+ const DWORD result = XINPUTGETCAPABILITIES(userId, XINPUT_FLAG_GAMEPAD, &capabilities);
+ const SDL_bool available = (result == ERROR_SUCCESS);
+ if (bOpenedXInputDevices[userId] != available) {
+ bXInputChanged = SDL_TRUE;
+ bOpenedXInputDevices[userId] = available;
+ }
+ }
+ }
+#else
+ /* WM_DEVICECHANGE not working, no XINPUT, no point in keeping thread alive */
+ break;
+#endif /* SDL_JOYSTICK_XINPUT */
+ }
+
+ if (s_bWindowsDeviceChanged || bXInputChanged) {
+ s_bDeviceRemoved = SDL_TRUE;
+ s_bDeviceAdded = SDL_TRUE;
+ s_bWindowsDeviceChanged = SDL_FALSE;
+ }
+ }
+ SDL_UnlockMutex(s_mutexJoyStickEnum);
+
+ SDL_CleanupDeviceNotification(&notification_data);
+
+ return 1;
+}
+
+void SDL_SYS_AddJoystickDevice(JoyStick_DeviceData *device)
+{
+ device->send_add_event = SDL_TRUE;
+ device->nInstanceID = ++s_nInstanceID;
+ device->pNext = SYS_Joystick;
+ SYS_Joystick = device;
+
+ s_bDeviceAdded = SDL_TRUE;
+}
+
+/* Function to scan the system for joysticks.
+ * Joystick 0 should be the system default joystick.
+ * It should return 0, or -1 on an unrecoverable fatal error.
+ */
+int
+SDL_SYS_JoystickInit(void)
+{
+ if (SDL_DINPUT_JoystickInit() < 0) {
+ SDL_SYS_JoystickQuit();
+ return -1;
+ }
+
+ if (SDL_XINPUT_JoystickInit() < 0) {
+ SDL_SYS_JoystickQuit();
+ return -1;
+ }
+
+ s_mutexJoyStickEnum = SDL_CreateMutex();
+ s_condJoystickThread = SDL_CreateCond();
+ s_bDeviceAdded = SDL_TRUE; /* force a scan of the system for joysticks this first time */
+
+ SDL_SYS_JoystickDetect();
+
+ if (!s_threadJoystick) {
+ /* spin up the thread to detect hotplug of devices */
+ s_bJoystickThreadQuit = SDL_FALSE;
+ s_threadJoystick = SDL_CreateThreadInternal(SDL_JoystickThread, "SDL_joystick", 64 * 1024, NULL);
+ }
+ return SDL_SYS_NumJoysticks();
+}
+
+/* return the number of joysticks that are connected right now */
+int
+SDL_SYS_NumJoysticks(void)
+{
+ int nJoysticks = 0;
+ JoyStick_DeviceData *device = SYS_Joystick;
+ while (device) {
+ nJoysticks++;
+ device = device->pNext;
+ }
+
+ return nJoysticks;
+}
+
+/* detect any new joysticks being inserted into the system */
+void
+SDL_SYS_JoystickDetect(void)
+{
+ JoyStick_DeviceData *pCurList = NULL;
+
+ /* only enum the devices if the joystick thread told us something changed */
+ if (!s_bDeviceAdded && !s_bDeviceRemoved) {
+ return; /* thread hasn't signaled, nothing to do right now. */
+ }
+
+ SDL_LockMutex(s_mutexJoyStickEnum);
+
+ s_bDeviceAdded = SDL_FALSE;
+ s_bDeviceRemoved = SDL_FALSE;
+
+ pCurList = SYS_Joystick;
+ SYS_Joystick = NULL;
+
+ /* Look for DirectInput joysticks, wheels, head trackers, gamepads, etc.. */
+ SDL_DINPUT_JoystickDetect(&pCurList);
+
+ /* Look for XInput devices. Do this last, so they're first in the final list. */
+ SDL_XINPUT_JoystickDetect(&pCurList);
+
+ SDL_UnlockMutex(s_mutexJoyStickEnum);
+
+ while (pCurList) {
+ JoyStick_DeviceData *pListNext = NULL;
+
+ if (pCurList->bXInputDevice) {
+ SDL_XINPUT_MaybeRemoveDevice(pCurList->XInputUserId);
+ } else {
+ SDL_DINPUT_MaybeRemoveDevice(&pCurList->dxdevice);
+ }
+
+ SDL_PrivateJoystickRemoved(pCurList->nInstanceID);
+
+ pListNext = pCurList->pNext;
+ SDL_free(pCurList->joystickname);
+ SDL_free(pCurList);
+ pCurList = pListNext;
+ }
+
+ if (s_bDeviceAdded) {
+ JoyStick_DeviceData *pNewJoystick;
+ int device_index = 0;
+ s_bDeviceAdded = SDL_FALSE;
+ pNewJoystick = SYS_Joystick;
+ while (pNewJoystick) {
+ if (pNewJoystick->send_add_event) {
+ if (pNewJoystick->bXInputDevice) {
+ SDL_XINPUT_MaybeAddDevice(pNewJoystick->XInputUserId);
+ } else {
+ SDL_DINPUT_MaybeAddDevice(&pNewJoystick->dxdevice);
+ }
+
+ SDL_PrivateJoystickAdded(device_index);
+
+ pNewJoystick->send_add_event = SDL_FALSE;
+ }
+ device_index++;
+ pNewJoystick = pNewJoystick->pNext;
+ }
+ }
+}
+
+/* Function to get the device-dependent name of a joystick */
+const char *
+SDL_SYS_JoystickNameForDeviceIndex(int device_index)
+{
+ JoyStick_DeviceData *device = SYS_Joystick;
+
+ for (; device_index > 0; device_index--)
+ device = device->pNext;
+
+ return device->joystickname;
+}
+
+/* Function to perform the mapping between current device instance and this joysticks instance id */
+SDL_JoystickID
+SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
+{
+ JoyStick_DeviceData *device = SYS_Joystick;
+ int index;
+
+ for (index = device_index; index > 0; index--)
+ device = device->pNext;
+
+ return device->nInstanceID;
+}
+
+/* Function to open a joystick for use.
+ The joystick to open is specified by the device index.
+ This should fill the nbuttons and naxes fields of the joystick structure.
+ It returns 0, or -1 if there is an error.
+ */
+int
+SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
+{
+ JoyStick_DeviceData *joystickdevice = SYS_Joystick;
+
+ for (; device_index > 0; device_index--)
+ joystickdevice = joystickdevice->pNext;
+
+ /* allocate memory for system specific hardware data */
+ joystick->instance_id = joystickdevice->nInstanceID;
+ joystick->hwdata =
+ (struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata));
+ if (joystick->hwdata == NULL) {
+ return SDL_OutOfMemory();
+ }
+ SDL_zerop(joystick->hwdata);
+ joystick->hwdata->guid = joystickdevice->guid;
+
+ if (joystickdevice->bXInputDevice) {
+ return SDL_XINPUT_JoystickOpen(joystick, joystickdevice);
+ } else {
+ return SDL_DINPUT_JoystickOpen(joystick, joystickdevice);
+ }
+}
+
+/* return true if this joystick is plugged in right now */
+SDL_bool
+SDL_SYS_JoystickAttached(SDL_Joystick * joystick)
+{
+ return joystick->hwdata && !joystick->hwdata->removed;
+}
+
+void
+SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
+{
+ if (!joystick->hwdata || joystick->hwdata->removed) {
+ return;
+ }
+
+ if (joystick->hwdata->bXInputDevice) {
+ SDL_XINPUT_JoystickUpdate(joystick);
+ } else {
+ SDL_DINPUT_JoystickUpdate(joystick);
+ }
+
+ if (joystick->hwdata->removed) {
+ joystick->force_recentering = SDL_TRUE;
+ }
+}
+
+/* Function to close a joystick after use */
+void
+SDL_SYS_JoystickClose(SDL_Joystick * joystick)
+{
+ if (joystick->hwdata->bXInputDevice) {
+ SDL_XINPUT_JoystickClose(joystick);
+ } else {
+ SDL_DINPUT_JoystickClose(joystick);
+ }
+
+ SDL_free(joystick->hwdata);
+}
+
+/* Function to perform any system-specific joystick related cleanup */
+void
+SDL_SYS_JoystickQuit(void)
+{
+ JoyStick_DeviceData *device = SYS_Joystick;
+
+ while (device) {
+ JoyStick_DeviceData *device_next = device->pNext;
+ SDL_free(device->joystickname);
+ SDL_free(device);
+ device = device_next;
+ }
+ SYS_Joystick = NULL;
+
+ if (s_threadJoystick) {
+ SDL_LockMutex(s_mutexJoyStickEnum);
+ s_bJoystickThreadQuit = SDL_TRUE;
+ SDL_CondBroadcast(s_condJoystickThread); /* signal the joystick thread to quit */
+ SDL_UnlockMutex(s_mutexJoyStickEnum);
+#ifndef __WINRT__
+ PostThreadMessage(SDL_GetThreadID(s_threadJoystick), WM_QUIT, 0, 0);
+#endif
+ SDL_WaitThread(s_threadJoystick, NULL); /* wait for it to bugger off */
+
+ SDL_DestroyMutex(s_mutexJoyStickEnum);
+ SDL_DestroyCond(s_condJoystickThread);
+ s_condJoystickThread= NULL;
+ s_mutexJoyStickEnum = NULL;
+ s_threadJoystick = NULL;
+ }
+
+ SDL_DINPUT_JoystickQuit();
+ SDL_XINPUT_JoystickQuit();
+
+ s_bDeviceAdded = SDL_FALSE;
+ s_bDeviceRemoved = SDL_FALSE;
+}
+
+/* return the stable device guid for this device index */
+SDL_JoystickGUID
+SDL_SYS_JoystickGetDeviceGUID(int device_index)
+{
+ JoyStick_DeviceData *device = SYS_Joystick;
+ int index;
+
+ for (index = device_index; index > 0; index--)
+ device = device->pNext;
+
+ return device->guid;
+}
+
+SDL_JoystickGUID
+SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
+{
+ return joystick->hwdata->guid;
+}
+
+#endif /* SDL_JOYSTICK_DINPUT || SDL_JOYSTICK_XINPUT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/windows/SDL_windowsjoystick_c.h b/src/3rdparty/SDL2/src/joystick/windows/SDL_windowsjoystick_c.h
new file mode 100644
index 0000000..01b8b3a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/windows/SDL_windowsjoystick_c.h
@@ -0,0 +1,93 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "SDL_events.h"
+#include "../SDL_sysjoystick.h"
+#include "../../core/windows/SDL_windows.h"
+#include "../../core/windows/SDL_directx.h"
+
+#define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */
+
+typedef struct JoyStick_DeviceData
+{
+ SDL_JoystickGUID guid;
+ char *joystickname;
+ Uint8 send_add_event;
+ SDL_JoystickID nInstanceID;
+ SDL_bool bXInputDevice;
+ BYTE SubType;
+ Uint8 XInputUserId;
+ DIDEVICEINSTANCE dxdevice;
+ WCHAR hidPath[MAX_PATH];
+ struct JoyStick_DeviceData *pNext;
+} JoyStick_DeviceData;
+
+extern JoyStick_DeviceData *SYS_Joystick; /* array to hold joystick ID values */
+
+typedef enum Type
+{
+ BUTTON,
+ AXIS,
+ HAT
+} Type;
+
+typedef struct input_t
+{
+ /* DirectInput offset for this input type: */
+ DWORD ofs;
+
+ /* Button, axis or hat: */
+ Type type;
+
+ /* SDL input offset: */
+ Uint8 num;
+} input_t;
+
+/* The private structure used to keep track of a joystick */
+struct joystick_hwdata
+{
+ SDL_JoystickGUID guid;
+ SDL_bool removed;
+ SDL_bool send_remove_event;
+
+#if SDL_JOYSTICK_DINPUT
+ LPDIRECTINPUTDEVICE8 InputDevice;
+ DIDEVCAPS Capabilities;
+ SDL_bool buffered;
+ input_t Inputs[MAX_INPUTS];
+ int NumInputs;
+ int NumSliders;
+#endif
+
+ SDL_bool bXInputDevice; /* SDL_TRUE if this device supports using the xinput API rather than DirectInput */
+ SDL_bool bXInputHaptic; /* Supports force feedback via XInput. */
+ Uint8 userid; /* XInput userid index for this joystick */
+ DWORD dwPacketNumber;
+};
+
+#if SDL_JOYSTICK_DINPUT
+extern const DIDATAFORMAT SDL_c_dfDIJoystick2;
+#endif
+
+extern void SDL_SYS_AddJoystickDevice(JoyStick_DeviceData *device);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/windows/SDL_xinputjoystick.c b/src/3rdparty/SDL2/src/joystick/windows/SDL_xinputjoystick.c
new file mode 100644
index 0000000..823e767
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/windows/SDL_xinputjoystick.c
@@ -0,0 +1,522 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "../SDL_sysjoystick.h"
+
+#if SDL_JOYSTICK_XINPUT
+
+#include "SDL_assert.h"
+#include "SDL_hints.h"
+#include "SDL_windowsjoystick_c.h"
+#include "SDL_xinputjoystick_c.h"
+
+/*
+ * Internal stuff.
+ */
+static SDL_bool s_bXInputEnabled = SDL_TRUE;
+static char *s_arrXInputDevicePath[XUSER_MAX_COUNT];
+
+
+static SDL_bool
+SDL_XInputUseOldJoystickMapping()
+{
+#ifdef __WINRT__
+ /* TODO: remove this __WINRT__ block, but only after integrating with UWP/WinRT's HID API */
+ /* FIXME: Why are Win8/10 different here? -flibit */
+ return (NTDDI_VERSION < NTDDI_WIN10);
+#else
+ static int s_XInputUseOldJoystickMapping = -1;
+ if (s_XInputUseOldJoystickMapping < 0) {
+ s_XInputUseOldJoystickMapping = SDL_GetHintBoolean(SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING, SDL_FALSE);
+ }
+ return (s_XInputUseOldJoystickMapping > 0);
+#endif
+}
+
+SDL_bool SDL_XINPUT_Enabled(void)
+{
+ return s_bXInputEnabled;
+}
+
+int
+SDL_XINPUT_JoystickInit(void)
+{
+ s_bXInputEnabled = SDL_GetHintBoolean(SDL_HINT_XINPUT_ENABLED, SDL_TRUE);
+
+ if (s_bXInputEnabled && WIN_LoadXInputDLL() < 0) {
+ s_bXInputEnabled = SDL_FALSE; /* oh well. */
+ }
+ return 0;
+}
+
+static char *
+GetXInputName(const Uint8 userid, BYTE SubType)
+{
+ char name[32];
+
+ if (SDL_XInputUseOldJoystickMapping()) {
+ SDL_snprintf(name, sizeof(name), "X360 Controller #%u", 1 + userid);
+ } else {
+ switch (SubType) {
+ case XINPUT_DEVSUBTYPE_GAMEPAD:
+ SDL_snprintf(name, sizeof(name), "XInput Controller #%u", 1 + userid);
+ break;
+ case XINPUT_DEVSUBTYPE_WHEEL:
+ SDL_snprintf(name, sizeof(name), "XInput Wheel #%u", 1 + userid);
+ break;
+ case XINPUT_DEVSUBTYPE_ARCADE_STICK:
+ SDL_snprintf(name, sizeof(name), "XInput ArcadeStick #%u", 1 + userid);
+ break;
+ case XINPUT_DEVSUBTYPE_FLIGHT_STICK:
+ SDL_snprintf(name, sizeof(name), "XInput FlightStick #%u", 1 + userid);
+ break;
+ case XINPUT_DEVSUBTYPE_DANCE_PAD:
+ SDL_snprintf(name, sizeof(name), "XInput DancePad #%u", 1 + userid);
+ break;
+ case XINPUT_DEVSUBTYPE_GUITAR:
+ case XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE:
+ case XINPUT_DEVSUBTYPE_GUITAR_BASS:
+ SDL_snprintf(name, sizeof(name), "XInput Guitar #%u", 1 + userid);
+ break;
+ case XINPUT_DEVSUBTYPE_DRUM_KIT:
+ SDL_snprintf(name, sizeof(name), "XInput DrumKit #%u", 1 + userid);
+ break;
+ case XINPUT_DEVSUBTYPE_ARCADE_PAD:
+ SDL_snprintf(name, sizeof(name), "XInput ArcadePad #%u", 1 + userid);
+ break;
+ default:
+ SDL_snprintf(name, sizeof(name), "XInput Device #%u", 1 + userid);
+ break;
+ }
+ }
+ return SDL_strdup(name);
+}
+
+/* We can't really tell what device is being used for XInput, but we can guess
+ and we'll be correct for the case where only one device is connected.
+ */
+static void
+GuessXInputDevice(Uint8 userid, Uint16 *pVID, Uint16 *pPID, Uint16 *pVersion)
+{
+#ifndef __WINRT__ /* TODO: remove this ifndef __WINRT__ block, but only after integrating with UWP/WinRT's HID API */
+
+ PRAWINPUTDEVICELIST devices = NULL;
+ UINT i, j, device_count = 0;
+
+ if ((GetRawInputDeviceList(NULL, &device_count, sizeof(RAWINPUTDEVICELIST)) == -1) || (!device_count)) {
+ return; /* oh well. */
+ }
+
+ devices = (PRAWINPUTDEVICELIST)SDL_malloc(sizeof(RAWINPUTDEVICELIST) * device_count);
+ if (devices == NULL) {
+ return;
+ }
+
+ if (GetRawInputDeviceList(devices, &device_count, sizeof(RAWINPUTDEVICELIST)) == -1) {
+ SDL_free(devices);
+ return; /* oh well. */
+ }
+
+ for (i = 0; i < device_count; i++) {
+ RID_DEVICE_INFO rdi;
+ char devName[128];
+ UINT rdiSize = sizeof(rdi);
+ UINT nameSize = SDL_arraysize(devName);
+
+ rdi.cbSize = sizeof(rdi);
+ if ((devices[i].dwType == RIM_TYPEHID) &&
+ (GetRawInputDeviceInfoA(devices[i].hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) != ((UINT)-1)) &&
+ (GetRawInputDeviceInfoA(devices[i].hDevice, RIDI_DEVICENAME, devName, &nameSize) != ((UINT)-1)) &&
+ (SDL_strstr(devName, "IG_") != NULL)) {
+ SDL_bool found = SDL_FALSE;
+ for (j = 0; j < SDL_arraysize(s_arrXInputDevicePath); ++j) {
+ if (j == userid) {
+ continue;
+ }
+ if (!s_arrXInputDevicePath[j]) {
+ continue;
+ }
+ if (SDL_strcmp(devName, s_arrXInputDevicePath[j]) == 0) {
+ found = SDL_TRUE;
+ break;
+ }
+ }
+ if (found) {
+ /* We already have this device in our XInput device list */
+ continue;
+ }
+
+ /* We don't actually know if this is the right device for this
+ * userid, but we'll record it so we'll at least be consistent
+ * when the raw device list changes.
+ */
+ *pVID = (Uint16)rdi.hid.dwVendorId;
+ *pPID = (Uint16)rdi.hid.dwProductId;
+ *pVersion = (Uint16)rdi.hid.dwVersionNumber;
+ if (s_arrXInputDevicePath[userid]) {
+ SDL_free(s_arrXInputDevicePath[userid]);
+ }
+ s_arrXInputDevicePath[userid] = SDL_strdup(devName);
+ break;
+ }
+ }
+ SDL_free(devices);
+#endif /* ifndef __WINRT__ */
+}
+
+static void
+AddXInputDevice(Uint8 userid, BYTE SubType, JoyStick_DeviceData **pContext)
+{
+ JoyStick_DeviceData *pPrevJoystick = NULL;
+ JoyStick_DeviceData *pNewJoystick = *pContext;
+
+ if (SDL_XInputUseOldJoystickMapping() && SubType != XINPUT_DEVSUBTYPE_GAMEPAD)
+ return;
+
+ if (SubType == XINPUT_DEVSUBTYPE_UNKNOWN)
+ return;
+
+ while (pNewJoystick) {
+ if (pNewJoystick->bXInputDevice && (pNewJoystick->XInputUserId == userid) && (pNewJoystick->SubType == SubType)) {
+ /* if we are replacing the front of the list then update it */
+ if (pNewJoystick == *pContext) {
+ *pContext = pNewJoystick->pNext;
+ } else if (pPrevJoystick) {
+ pPrevJoystick->pNext = pNewJoystick->pNext;
+ }
+
+ pNewJoystick->pNext = SYS_Joystick;
+ SYS_Joystick = pNewJoystick;
+ return; /* already in the list. */
+ }
+
+ pPrevJoystick = pNewJoystick;
+ pNewJoystick = pNewJoystick->pNext;
+ }
+
+ pNewJoystick = (JoyStick_DeviceData *)SDL_malloc(sizeof(JoyStick_DeviceData));
+ if (!pNewJoystick) {
+ return; /* better luck next time? */
+ }
+ SDL_zerop(pNewJoystick);
+
+ pNewJoystick->joystickname = GetXInputName(userid, SubType);
+ if (!pNewJoystick->joystickname) {
+ SDL_free(pNewJoystick);
+ return; /* better luck next time? */
+ }
+
+ pNewJoystick->bXInputDevice = SDL_TRUE;
+ if (SDL_XInputUseOldJoystickMapping()) {
+ SDL_zero(pNewJoystick->guid);
+ } else {
+ const Uint16 BUS_USB = 0x03;
+ Uint16 vendor = 0;
+ Uint16 product = 0;
+ Uint16 version = 0;
+ Uint16 *guid16 = (Uint16 *)pNewJoystick->guid.data;
+
+ GuessXInputDevice(userid, &vendor, &product, &version);
+
+ *guid16++ = SDL_SwapLE16(BUS_USB);
+ *guid16++ = 0;
+ *guid16++ = SDL_SwapLE16(vendor);
+ *guid16++ = 0;
+ *guid16++ = SDL_SwapLE16(product);
+ *guid16++ = 0;
+ *guid16++ = SDL_SwapLE16(version);
+ *guid16++ = 0;
+
+ /* Note that this is an XInput device and what subtype it is */
+ pNewJoystick->guid.data[14] = 'x';
+ pNewJoystick->guid.data[15] = SubType;
+ }
+ pNewJoystick->SubType = SubType;
+ pNewJoystick->XInputUserId = userid;
+
+ if (SDL_ShouldIgnoreGameController(pNewJoystick->joystickname, pNewJoystick->guid)) {
+ SDL_free(pNewJoystick);
+ return;
+ }
+
+ SDL_SYS_AddJoystickDevice(pNewJoystick);
+}
+
+void
+SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext)
+{
+ int iuserid;
+
+ if (!s_bXInputEnabled) {
+ return;
+ }
+
+ /* iterate in reverse, so these are in the final list in ascending numeric order. */
+ for (iuserid = XUSER_MAX_COUNT - 1; iuserid >= 0; iuserid--) {
+ const Uint8 userid = (Uint8)iuserid;
+ XINPUT_CAPABILITIES capabilities;
+ if (XINPUTGETCAPABILITIES(userid, XINPUT_FLAG_GAMEPAD, &capabilities) == ERROR_SUCCESS) {
+ AddXInputDevice(userid, capabilities.SubType, pContext);
+ }
+ }
+}
+
+int
+SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice)
+{
+ const Uint8 userId = joystickdevice->XInputUserId;
+ XINPUT_CAPABILITIES capabilities;
+ XINPUT_VIBRATION state;
+
+ SDL_assert(s_bXInputEnabled);
+ SDL_assert(XINPUTGETCAPABILITIES);
+ SDL_assert(XINPUTSETSTATE);
+ SDL_assert(userId < XUSER_MAX_COUNT);
+
+ joystick->hwdata->bXInputDevice = SDL_TRUE;
+
+ if (XINPUTGETCAPABILITIES(userId, XINPUT_FLAG_GAMEPAD, &capabilities) != ERROR_SUCCESS) {
+ SDL_free(joystick->hwdata);
+ joystick->hwdata = NULL;
+ return SDL_SetError("Failed to obtain XInput device capabilities. Device disconnected?");
+ }
+ SDL_zero(state);
+ joystick->hwdata->bXInputHaptic = (XINPUTSETSTATE(userId, &state) == ERROR_SUCCESS);
+ joystick->hwdata->userid = userId;
+
+ /* The XInput API has a hard coded button/axis mapping, so we just match it */
+ if (SDL_XInputUseOldJoystickMapping()) {
+ joystick->naxes = 6;
+ joystick->nbuttons = 15;
+ } else {
+ joystick->naxes = 6;
+ joystick->nbuttons = 11;
+ joystick->nhats = 1;
+ }
+ return 0;
+}
+
+static void
+UpdateXInputJoystickBatteryInformation(SDL_Joystick * joystick, XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation)
+{
+ if (pBatteryInformation->BatteryType != BATTERY_TYPE_UNKNOWN) {
+ SDL_JoystickPowerLevel ePowerLevel = SDL_JOYSTICK_POWER_UNKNOWN;
+ if (pBatteryInformation->BatteryType == BATTERY_TYPE_WIRED) {
+ ePowerLevel = SDL_JOYSTICK_POWER_WIRED;
+ } else {
+ switch (pBatteryInformation->BatteryLevel) {
+ case BATTERY_LEVEL_EMPTY:
+ ePowerLevel = SDL_JOYSTICK_POWER_EMPTY;
+ break;
+ case BATTERY_LEVEL_LOW:
+ ePowerLevel = SDL_JOYSTICK_POWER_LOW;
+ break;
+ case BATTERY_LEVEL_MEDIUM:
+ ePowerLevel = SDL_JOYSTICK_POWER_MEDIUM;
+ break;
+ default:
+ case BATTERY_LEVEL_FULL:
+ ePowerLevel = SDL_JOYSTICK_POWER_FULL;
+ break;
+ }
+ }
+
+ SDL_PrivateJoystickBatteryLevel(joystick, ePowerLevel);
+ }
+}
+
+static void
+UpdateXInputJoystickState_OLD(SDL_Joystick * joystick, XINPUT_STATE_EX *pXInputState, XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation)
+{
+ static WORD s_XInputButtons[] = {
+ XINPUT_GAMEPAD_DPAD_UP, XINPUT_GAMEPAD_DPAD_DOWN, XINPUT_GAMEPAD_DPAD_LEFT, XINPUT_GAMEPAD_DPAD_RIGHT,
+ XINPUT_GAMEPAD_START, XINPUT_GAMEPAD_BACK, XINPUT_GAMEPAD_LEFT_THUMB, XINPUT_GAMEPAD_RIGHT_THUMB,
+ XINPUT_GAMEPAD_LEFT_SHOULDER, XINPUT_GAMEPAD_RIGHT_SHOULDER,
+ XINPUT_GAMEPAD_A, XINPUT_GAMEPAD_B, XINPUT_GAMEPAD_X, XINPUT_GAMEPAD_Y,
+ XINPUT_GAMEPAD_GUIDE
+ };
+ WORD wButtons = pXInputState->Gamepad.wButtons;
+ Uint8 button;
+
+ SDL_PrivateJoystickAxis(joystick, 0, (Sint16)pXInputState->Gamepad.sThumbLX);
+ SDL_PrivateJoystickAxis(joystick, 1, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbLY)));
+ SDL_PrivateJoystickAxis(joystick, 2, (Sint16)pXInputState->Gamepad.sThumbRX);
+ SDL_PrivateJoystickAxis(joystick, 3, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbRY)));
+ SDL_PrivateJoystickAxis(joystick, 4, (Sint16)(((int)pXInputState->Gamepad.bLeftTrigger * 65535 / 255) - 32768));
+ SDL_PrivateJoystickAxis(joystick, 5, (Sint16)(((int)pXInputState->Gamepad.bRightTrigger * 65535 / 255) - 32768));
+
+ for (button = 0; button < SDL_arraysize(s_XInputButtons); ++button) {
+ SDL_PrivateJoystickButton(joystick, button, (wButtons & s_XInputButtons[button]) ? SDL_PRESSED : SDL_RELEASED);
+ }
+
+ UpdateXInputJoystickBatteryInformation(joystick, pBatteryInformation);
+}
+
+static void
+UpdateXInputJoystickState(SDL_Joystick * joystick, XINPUT_STATE_EX *pXInputState, XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation)
+{
+ static WORD s_XInputButtons[] = {
+ XINPUT_GAMEPAD_A, XINPUT_GAMEPAD_B, XINPUT_GAMEPAD_X, XINPUT_GAMEPAD_Y,
+ XINPUT_GAMEPAD_LEFT_SHOULDER, XINPUT_GAMEPAD_RIGHT_SHOULDER, XINPUT_GAMEPAD_BACK, XINPUT_GAMEPAD_START,
+ XINPUT_GAMEPAD_LEFT_THUMB, XINPUT_GAMEPAD_RIGHT_THUMB,
+ XINPUT_GAMEPAD_GUIDE
+ };
+ WORD wButtons = pXInputState->Gamepad.wButtons;
+ Uint8 button;
+ Uint8 hat = SDL_HAT_CENTERED;
+
+ SDL_PrivateJoystickAxis(joystick, 0, (Sint16)pXInputState->Gamepad.sThumbLX);
+ SDL_PrivateJoystickAxis(joystick, 1, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbLY)));
+ SDL_PrivateJoystickAxis(joystick, 2, (Sint16)(((int)pXInputState->Gamepad.bLeftTrigger * 65535 / 255) - 32768));
+ SDL_PrivateJoystickAxis(joystick, 3, (Sint16)pXInputState->Gamepad.sThumbRX);
+ SDL_PrivateJoystickAxis(joystick, 4, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbRY)));
+ SDL_PrivateJoystickAxis(joystick, 5, (Sint16)(((int)pXInputState->Gamepad.bRightTrigger * 65535 / 255) - 32768));
+
+ for (button = 0; button < SDL_arraysize(s_XInputButtons); ++button) {
+ SDL_PrivateJoystickButton(joystick, button, (wButtons & s_XInputButtons[button]) ? SDL_PRESSED : SDL_RELEASED);
+ }
+
+ if (wButtons & XINPUT_GAMEPAD_DPAD_UP) {
+ hat |= SDL_HAT_UP;
+ }
+ if (wButtons & XINPUT_GAMEPAD_DPAD_DOWN) {
+ hat |= SDL_HAT_DOWN;
+ }
+ if (wButtons & XINPUT_GAMEPAD_DPAD_LEFT) {
+ hat |= SDL_HAT_LEFT;
+ }
+ if (wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) {
+ hat |= SDL_HAT_RIGHT;
+ }
+ SDL_PrivateJoystickHat(joystick, 0, hat);
+
+ UpdateXInputJoystickBatteryInformation(joystick, pBatteryInformation);
+}
+
+void
+SDL_XINPUT_JoystickUpdate(SDL_Joystick * joystick)
+{
+ HRESULT result;
+ XINPUT_STATE_EX XInputState;
+ XINPUT_BATTERY_INFORMATION_EX XBatteryInformation;
+
+ if (!XINPUTGETSTATE)
+ return;
+
+ result = XINPUTGETSTATE(joystick->hwdata->userid, &XInputState);
+ if (result == ERROR_DEVICE_NOT_CONNECTED) {
+ Uint8 userid = joystick->hwdata->userid;
+
+ joystick->hwdata->send_remove_event = SDL_TRUE;
+ joystick->hwdata->removed = SDL_TRUE;
+ if (s_arrXInputDevicePath[userid]) {
+ SDL_free(s_arrXInputDevicePath[userid]);
+ s_arrXInputDevicePath[userid] = NULL;
+ }
+ return;
+ }
+
+ SDL_zero(XBatteryInformation);
+ if (XINPUTGETBATTERYINFORMATION) {
+ result = XINPUTGETBATTERYINFORMATION(joystick->hwdata->userid, BATTERY_DEVTYPE_GAMEPAD, &XBatteryInformation);
+ }
+
+ /* only fire events if the data changed from last time */
+ if (XInputState.dwPacketNumber && XInputState.dwPacketNumber != joystick->hwdata->dwPacketNumber) {
+ if (SDL_XInputUseOldJoystickMapping()) {
+ UpdateXInputJoystickState_OLD(joystick, &XInputState, &XBatteryInformation);
+ } else {
+ UpdateXInputJoystickState(joystick, &XInputState, &XBatteryInformation);
+ }
+ joystick->hwdata->dwPacketNumber = XInputState.dwPacketNumber;
+ }
+}
+
+void
+SDL_XINPUT_JoystickClose(SDL_Joystick * joystick)
+{
+}
+
+void
+SDL_XINPUT_JoystickQuit(void)
+{
+ if (s_bXInputEnabled) {
+ WIN_UnloadXInputDLL();
+ }
+}
+
+SDL_bool
+SDL_SYS_IsXInputGamepad_DeviceIndex(int device_index)
+{
+ JoyStick_DeviceData *device = SYS_Joystick;
+ int index;
+
+ for (index = device_index; index > 0; index--)
+ device = device->pNext;
+
+ return device->bXInputDevice;
+}
+
+#else /* !SDL_JOYSTICK_XINPUT */
+
+typedef struct JoyStick_DeviceData JoyStick_DeviceData;
+
+SDL_bool SDL_XINPUT_Enabled(void)
+{
+ return SDL_FALSE;
+}
+
+int
+SDL_XINPUT_JoystickInit(void)
+{
+ return 0;
+}
+
+void
+SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext)
+{
+}
+
+int
+SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice)
+{
+ return SDL_Unsupported();
+}
+
+void
+SDL_XINPUT_JoystickUpdate(SDL_Joystick * joystick)
+{
+}
+
+void
+SDL_XINPUT_JoystickClose(SDL_Joystick * joystick)
+{
+}
+
+void
+SDL_XINPUT_JoystickQuit(void)
+{
+}
+
+#endif /* SDL_JOYSTICK_XINPUT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/joystick/windows/SDL_xinputjoystick_c.h b/src/3rdparty/SDL2/src/joystick/windows/SDL_xinputjoystick_c.h
new file mode 100644
index 0000000..63616ee
--- /dev/null
+++ b/src/3rdparty/SDL2/src/joystick/windows/SDL_xinputjoystick_c.h
@@ -0,0 +1,33 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "../../core/windows/SDL_xinput.h"
+
+extern SDL_bool SDL_XINPUT_Enabled(void);
+extern int SDL_XINPUT_JoystickInit(void);
+extern void SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext);
+extern int SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice);
+extern void SDL_XINPUT_JoystickUpdate(SDL_Joystick * joystick);
+extern void SDL_XINPUT_JoystickClose(SDL_Joystick * joystick);
+extern void SDL_XINPUT_JoystickQuit(void);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/libm/e_atan2.c b/src/3rdparty/SDL2/src/libm/e_atan2.c
new file mode 100644
index 0000000..32b9725
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/e_atan2.c
@@ -0,0 +1,134 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/* __ieee754_atan2(y,x)
+ * Method :
+ * 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x).
+ * 2. Reduce x to positive by (if x and y are unexceptional):
+ * ARG (x+iy) = arctan(y/x) ... if x > 0,
+ * ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0,
+ *
+ * Special cases:
+ *
+ * ATAN2((anything), NaN ) is NaN;
+ * ATAN2(NAN , (anything) ) is NaN;
+ * ATAN2(+-0, +(anything but NaN)) is +-0 ;
+ * ATAN2(+-0, -(anything but NaN)) is +-pi ;
+ * ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2;
+ * ATAN2(+-(anything but INF and NaN), +INF) is +-0 ;
+ * ATAN2(+-(anything but INF and NaN), -INF) is +-pi;
+ * ATAN2(+-INF,+INF ) is +-pi/4 ;
+ * ATAN2(+-INF,-INF ) is +-3pi/4;
+ * ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2;
+ *
+ * Constants:
+ * The hexadecimal values are the intended ones for the following
+ * constants. The decimal values may be used, provided that the
+ * compiler will convert from decimal to binary accurately enough
+ * to produce the hexadecimal values shown.
+ */
+
+#include "math_libm.h"
+#include "math_private.h"
+
+static const double
+tiny = 1.0e-300,
+zero = 0.0,
+pi_o_4 = 7.8539816339744827900E-01, /* 0x3FE921FB, 0x54442D18 */
+pi_o_2 = 1.5707963267948965580E+00, /* 0x3FF921FB, 0x54442D18 */
+pi = 3.1415926535897931160E+00, /* 0x400921FB, 0x54442D18 */
+pi_lo = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */
+
+double attribute_hidden __ieee754_atan2(double y, double x)
+{
+ double z;
+ int32_t k,m,hx,hy,ix,iy;
+ u_int32_t lx,ly;
+
+ EXTRACT_WORDS(hx,lx,x);
+ ix = hx&0x7fffffff;
+ EXTRACT_WORDS(hy,ly,y);
+ iy = hy&0x7fffffff;
+ if(((ix|((lx|-(int32_t)lx)>>31))>0x7ff00000)||
+ ((iy|((ly|-(int32_t)ly)>>31))>0x7ff00000)) /* x or y is NaN */
+ return x+y;
+ if(((hx-0x3ff00000)|lx)==0) return atan(y); /* x=1.0 */
+ m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */
+
+ /* when y = 0 */
+ if((iy|ly)==0) {
+ switch(m) {
+ case 0:
+ case 1: return y; /* atan(+-0,+anything)=+-0 */
+ case 2: return pi+tiny;/* atan(+0,-anything) = pi */
+ case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */
+ }
+ }
+ /* when x = 0 */
+ if((ix|lx)==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
+
+ /* when x is INF */
+ if(ix==0x7ff00000) {
+ if(iy==0x7ff00000) {
+ switch(m) {
+ case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */
+ case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */
+ case 2: return 3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/
+ case 3: return -3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/
+ }
+ } else {
+ switch(m) {
+ case 0: return zero ; /* atan(+...,+INF) */
+ case 1: return -zero ; /* atan(-...,+INF) */
+ case 2: return pi+tiny ; /* atan(+...,-INF) */
+ case 3: return -pi-tiny ; /* atan(-...,-INF) */
+ }
+ }
+ }
+ /* when y is INF */
+ if(iy==0x7ff00000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
+
+ /* compute y/x */
+ k = (iy-ix)>>20;
+ if(k > 60) z=pi_o_2+0.5*pi_lo; /* |y/x| > 2**60 */
+ else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */
+ else z=atan(fabs(y/x)); /* safe to do y/x */
+ switch (m) {
+ case 0: return z ; /* atan(+,+) */
+ case 1: {
+ u_int32_t zh;
+ GET_HIGH_WORD(zh,z);
+ SET_HIGH_WORD(z,zh ^ 0x80000000);
+ }
+ return z ; /* atan(-,+) */
+ case 2: return pi-(z-pi_lo);/* atan(+,-) */
+ default: /* case 3 */
+ return (z-pi_lo)-pi;/* atan(-,-) */
+ }
+}
+
+/*
+ * wrapper atan2(y,x)
+ */
+#ifndef _IEEE_LIBM
+double atan2(double y, double x)
+{
+ double z = __ieee754_atan2(y, x);
+ if (_LIB_VERSION == _IEEE_ || isnan(x) || isnan(y))
+ return z;
+ if (x == 0.0 && y == 0.0)
+ return __kernel_standard(y,x,3); /* atan2(+-0,+-0) */
+ return z;
+}
+#else
+strong_alias(__ieee754_atan2, atan2)
+#endif
+libm_hidden_def(atan2)
diff --git a/src/3rdparty/SDL2/src/libm/e_fmod.c b/src/3rdparty/SDL2/src/libm/e_fmod.c
new file mode 100644
index 0000000..fd8bacb
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/e_fmod.c
@@ -0,0 +1,144 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/*
+ * __ieee754_fmod(x,y)
+ * Return x mod y in exact arithmetic
+ * Method: shift and subtract
+ */
+
+#include "math_libm.h"
+#include "math_private.h"
+
+static const double one = 1.0, Zero[] = {0.0, -0.0,};
+
+double attribute_hidden __ieee754_fmod(double x, double y)
+{
+ int32_t n,hx,hy,hz,ix,iy,sx,i;
+ u_int32_t lx,ly,lz;
+
+ EXTRACT_WORDS(hx,lx,x);
+ EXTRACT_WORDS(hy,ly,y);
+ sx = hx&0x80000000; /* sign of x */
+ hx ^=sx; /* |x| */
+ hy &= 0x7fffffff; /* |y| */
+
+ /* purge off exception values */
+ if((hy|ly)==0||(hx>=0x7ff00000)|| /* y=0,or x not finite */
+ ((hy|((ly|-(int32_t)ly)>>31))>0x7ff00000)) /* or y is NaN */
+ return (x*y)/(x*y);
+ if(hx<=hy) {
+ if((hx<hy)||(lx<ly)) return x; /* |x|<|y| return x */
+ if(lx==ly)
+ return Zero[(u_int32_t)sx>>31]; /* |x|=|y| return x*0*/
+ }
+
+ /* determine ix = ilogb(x) */
+ if(hx<0x00100000) { /* subnormal x */
+ if(hx==0) {
+ for (ix = -1043, i=lx; i>0; i<<=1) ix -=1;
+ } else {
+ for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1;
+ }
+ } else ix = (hx>>20)-1023;
+
+ /* determine iy = ilogb(y) */
+ if(hy<0x00100000) { /* subnormal y */
+ if(hy==0) {
+ for (iy = -1043, i=ly; i>0; i<<=1) iy -=1;
+ } else {
+ for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1;
+ }
+ } else iy = (hy>>20)-1023;
+
+ /* set up {hx,lx}, {hy,ly} and align y to x */
+ if(ix >= -1022)
+ hx = 0x00100000|(0x000fffff&hx);
+ else { /* subnormal x, shift x to normal */
+ n = -1022-ix;
+ if(n<=31) {
+ hx = (hx<<n)|(lx>>(32-n));
+ lx <<= n;
+ } else {
+ hx = lx<<(n-32);
+ lx = 0;
+ }
+ }
+ if(iy >= -1022)
+ hy = 0x00100000|(0x000fffff&hy);
+ else { /* subnormal y, shift y to normal */
+ n = -1022-iy;
+ if(n<=31) {
+ hy = (hy<<n)|(ly>>(32-n));
+ ly <<= n;
+ } else {
+ hy = ly<<(n-32);
+ ly = 0;
+ }
+ }
+
+ /* fix point fmod */
+ n = ix - iy;
+ while(n--) {
+ hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
+ if(hz<0){hx = hx+hx+(lx>>31); lx = lx+lx;}
+ else {
+ if((hz|lz)==0) /* return sign(x)*0 */
+ return Zero[(u_int32_t)sx>>31];
+ hx = hz+hz+(lz>>31); lx = lz+lz;
+ }
+ }
+ hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
+ if(hz>=0) {hx=hz;lx=lz;}
+
+ /* convert back to floating value and restore the sign */
+ if((hx|lx)==0) /* return sign(x)*0 */
+ return Zero[(u_int32_t)sx>>31];
+ while(hx<0x00100000) { /* normalize x */
+ hx = hx+hx+(lx>>31); lx = lx+lx;
+ iy -= 1;
+ }
+ if(iy>= -1022) { /* normalize output */
+ hx = ((hx-0x00100000)|((iy+1023)<<20));
+ INSERT_WORDS(x,hx|sx,lx);
+ } else { /* subnormal output */
+ n = -1022 - iy;
+ if(n<=20) {
+ lx = (lx>>n)|((u_int32_t)hx<<(32-n));
+ hx >>= n;
+ } else if (n<=31) {
+ lx = (hx<<(32-n))|(lx>>n); hx = sx;
+ } else {
+ lx = hx>>(n-32); hx = sx;
+ }
+ INSERT_WORDS(x,hx|sx,lx);
+ x *= one; /* create necessary signal */
+ }
+ return x; /* exact output */
+}
+
+/*
+ * wrapper fmod(x,y)
+ */
+#ifndef _IEEE_LIBM
+double fmod(double x, double y)
+{
+ double z = __ieee754_fmod(x, y);
+ if (_LIB_VERSION == _IEEE_ || isnan(y) || isnan(x))
+ return z;
+ if (y == 0.0)
+ return __kernel_standard(x, y, 27); /* fmod(x,0) */
+ return z;
+}
+#else
+strong_alias(__ieee754_fmod, fmod)
+#endif
+libm_hidden_def(fmod)
diff --git a/src/3rdparty/SDL2/src/libm/e_log.c b/src/3rdparty/SDL2/src/libm/e_log.c
new file mode 100644
index 0000000..208df81
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/e_log.c
@@ -0,0 +1,152 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+/* C4723: potential divide by zero. */
+#pragma warning ( disable : 4723 )
+#endif
+
+/* __ieee754_log(x)
+ * Return the logrithm of x
+ *
+ * Method :
+ * 1. Argument Reduction: find k and f such that
+ * x = 2^k * (1+f),
+ * where sqrt(2)/2 < 1+f < sqrt(2) .
+ *
+ * 2. Approximation of log(1+f).
+ * Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s)
+ * = 2s + 2/3 s**3 + 2/5 s**5 + .....,
+ * = 2s + s*R
+ * We use a special Reme algorithm on [0,0.1716] to generate
+ * a polynomial of degree 14 to approximate R The maximum error
+ * of this polynomial approximation is bounded by 2**-58.45. In
+ * other words,
+ * 2 4 6 8 10 12 14
+ * R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s +Lg6*s +Lg7*s
+ * (the values of Lg1 to Lg7 are listed in the program)
+ * and
+ * | 2 14 | -58.45
+ * | Lg1*s +...+Lg7*s - R(z) | <= 2
+ * | |
+ * Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2.
+ * In order to guarantee error in log below 1ulp, we compute log
+ * by
+ * log(1+f) = f - s*(f - R) (if f is not too large)
+ * log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy)
+ *
+ * 3. Finally, log(x) = k*ln2 + log(1+f).
+ * = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo)))
+ * Here ln2 is split into two floating point number:
+ * ln2_hi + ln2_lo,
+ * where n*ln2_hi is always exact for |n| < 2000.
+ *
+ * Special cases:
+ * log(x) is NaN with signal if x < 0 (including -INF) ;
+ * log(+INF) is +INF; log(0) is -INF with signal;
+ * log(NaN) is that NaN with no signal.
+ *
+ * Accuracy:
+ * according to an error analysis, the error is always less than
+ * 1 ulp (unit in the last place).
+ *
+ * Constants:
+ * The hexadecimal values are the intended ones for the following
+ * constants. The decimal values may be used, provided that the
+ * compiler will convert from decimal to binary accurately enough
+ * to produce the hexadecimal values shown.
+ */
+
+#include "math_libm.h"
+#include "math_private.h"
+
+static const double
+ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */
+ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */
+two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */
+Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */
+Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */
+Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */
+Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */
+Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */
+Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */
+Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
+
+static const double zero = 0.0;
+
+double attribute_hidden __ieee754_log(double x)
+{
+ double hfsq,f,s,z,R,w,t1,t2,dk;
+ int32_t k,hx,i,j;
+ u_int32_t lx;
+
+ EXTRACT_WORDS(hx,lx,x);
+
+ k=0;
+ if (hx < 0x00100000) { /* x < 2**-1022 */
+ if (((hx&0x7fffffff)|lx)==0)
+ return -two54/zero; /* log(+-0)=-inf */
+ if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
+ k -= 54; x *= two54; /* subnormal number, scale up x */
+ GET_HIGH_WORD(hx,x);
+ }
+ if (hx >= 0x7ff00000) return x+x;
+ k += (hx>>20)-1023;
+ hx &= 0x000fffff;
+ i = (hx+0x95f64)&0x100000;
+ SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */
+ k += (i>>20);
+ f = x-1.0;
+ if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */
+ if(f==zero) {if(k==0) return zero; else {dk=(double)k;
+ return dk*ln2_hi+dk*ln2_lo;}
+ }
+ R = f*f*(0.5-0.33333333333333333*f);
+ if(k==0) return f-R; else {dk=(double)k;
+ return dk*ln2_hi-((R-dk*ln2_lo)-f);}
+ }
+ s = f/(2.0+f);
+ dk = (double)k;
+ z = s*s;
+ i = hx-0x6147a;
+ w = z*z;
+ j = 0x6b851-hx;
+ t1= w*(Lg2+w*(Lg4+w*Lg6));
+ t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7)));
+ i |= j;
+ R = t2+t1;
+ if(i>0) {
+ hfsq=0.5*f*f;
+ if(k==0) return f-(hfsq-s*(hfsq+R)); else
+ return dk*ln2_hi-((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f);
+ } else {
+ if(k==0) return f-s*(f-R); else
+ return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f);
+ }
+}
+
+/*
+ * wrapper log(x)
+ */
+#ifndef _IEEE_LIBM
+double log(double x)
+{
+ double z = __ieee754_log(x);
+ if (_LIB_VERSION == _IEEE_ || isnan(x) || x > 0.0)
+ return z;
+ if (x == 0.0)
+ return __kernel_standard(x, x, 16); /* log(0) */
+ return __kernel_standard(x, x, 17); /* log(x<0) */
+}
+#else
+strong_alias(__ieee754_log, log)
+#endif
+libm_hidden_def(log)
diff --git a/src/3rdparty/SDL2/src/libm/e_log10.c b/src/3rdparty/SDL2/src/libm/e_log10.c
new file mode 100644
index 0000000..a30ba54
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/e_log10.c
@@ -0,0 +1,106 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+/* C4723: potential divide by zero. */
+#pragma warning ( disable : 4723 )
+#endif
+
+/* __ieee754_log10(x)
+ * Return the base 10 logarithm of x
+ *
+ * Method :
+ * Let log10_2hi = leading 40 bits of log10(2) and
+ * log10_2lo = log10(2) - log10_2hi,
+ * ivln10 = 1/log(10) rounded.
+ * Then
+ * n = ilogb(x),
+ * if(n<0) n = n+1;
+ * x = scalbn(x,-n);
+ * log10(x) := n*log10_2hi + (n*log10_2lo + ivln10*log(x))
+ *
+ * Note 1:
+ * To guarantee log10(10**n)=n, where 10**n is normal, the rounding
+ * mode must set to Round-to-Nearest.
+ * Note 2:
+ * [1/log(10)] rounded to 53 bits has error .198 ulps;
+ * log10 is monotonic at all binary break points.
+ *
+ * Special cases:
+ * log10(x) is NaN with signal if x < 0;
+ * log10(+INF) is +INF with no signal; log10(0) is -INF with signal;
+ * log10(NaN) is that NaN with no signal;
+ * log10(10**N) = N for N=0,1,...,22.
+ *
+ * Constants:
+ * The hexadecimal values are the intended ones for the following constants.
+ * The decimal values may be used, provided that the compiler will convert
+ * from decimal to binary accurately enough to produce the hexadecimal values
+ * shown.
+ */
+
+#include "math_libm.h"
+#include "math_private.h"
+
+static const double
+two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
+ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */
+log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
+log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
+
+static const double zero = 0.0;
+
+double attribute_hidden __ieee754_log10(double x)
+{
+ double y,z;
+ int32_t i,k,hx;
+ u_int32_t lx;
+
+ EXTRACT_WORDS(hx,lx,x);
+
+ k=0;
+ if (hx < 0x00100000) { /* x < 2**-1022 */
+ if (((hx&0x7fffffff)|lx)==0)
+ return -two54/zero; /* log(+-0)=-inf */
+ if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
+ k -= 54; x *= two54; /* subnormal number, scale up x */
+ GET_HIGH_WORD(hx,x);
+ }
+ if (hx >= 0x7ff00000) return x+x;
+ k += (hx>>20)-1023;
+ i = ((u_int32_t)k&0x80000000)>>31;
+ hx = (hx&0x000fffff)|((0x3ff-i)<<20);
+ y = (double)(k+i);
+ SET_HIGH_WORD(x,hx);
+ z = y*log10_2lo + ivln10*__ieee754_log(x);
+ return z+y*log10_2hi;
+}
+
+/*
+ * wrapper log10(X)
+ */
+#ifndef _IEEE_LIBM
+double log10(double x)
+{
+ double z = __ieee754_log10(x);
+ if (_LIB_VERSION == _IEEE_ || isnan(x))
+ return z;
+ if (x <= 0.0) {
+ if(x == 0.0)
+ return __kernel_standard(x, x, 18); /* log10(0) */
+ return __kernel_standard(x, x, 19); /* log10(x<0) */
+ }
+ return z;
+}
+#else
+strong_alias(__ieee754_log10, log10)
+#endif
+libm_hidden_def(log10)
diff --git a/src/3rdparty/SDL2/src/libm/e_pow.c b/src/3rdparty/SDL2/src/libm/e_pow.c
new file mode 100644
index 0000000..cfd1dbf
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/e_pow.c
@@ -0,0 +1,343 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/* __ieee754_pow(x,y) return x**y
+ *
+ * n
+ * Method: Let x = 2 * (1+f)
+ * 1. Compute and return log2(x) in two pieces:
+ * log2(x) = w1 + w2,
+ * where w1 has 53-24 = 29 bit trailing zeros.
+ * 2. Perform y*log2(x) = n+y' by simulating muti-precision
+ * arithmetic, where |y'|<=0.5.
+ * 3. Return x**y = 2**n*exp(y'*log2)
+ *
+ * Special cases:
+ * 1. +-1 ** anything is 1.0
+ * 2. +-1 ** +-INF is 1.0
+ * 3. (anything) ** 0 is 1
+ * 4. (anything) ** 1 is itself
+ * 5. (anything) ** NAN is NAN
+ * 6. NAN ** (anything except 0) is NAN
+ * 7. +-(|x| > 1) ** +INF is +INF
+ * 8. +-(|x| > 1) ** -INF is +0
+ * 9. +-(|x| < 1) ** +INF is +0
+ * 10 +-(|x| < 1) ** -INF is +INF
+ * 11. +0 ** (+anything except 0, NAN) is +0
+ * 12. -0 ** (+anything except 0, NAN, odd integer) is +0
+ * 13. +0 ** (-anything except 0, NAN) is +INF
+ * 14. -0 ** (-anything except 0, NAN, odd integer) is +INF
+ * 15. -0 ** (odd integer) = -( +0 ** (odd integer) )
+ * 16. +INF ** (+anything except 0,NAN) is +INF
+ * 17. +INF ** (-anything except 0,NAN) is +0
+ * 18. -INF ** (anything) = -0 ** (-anything)
+ * 19. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer)
+ * 20. (-anything except 0 and inf) ** (non-integer) is NAN
+ *
+ * Accuracy:
+ * pow(x,y) returns x**y nearly rounded. In particular
+ * pow(integer,integer)
+ * always returns the correct integer provided it is
+ * representable.
+ *
+ * Constants :
+ * The hexadecimal values are the intended ones for the following
+ * constants. The decimal values may be used, provided that the
+ * compiler will convert from decimal to binary accurately enough
+ * to produce the hexadecimal values shown.
+ */
+
+#include "math_libm.h"
+#include "math_private.h"
+
+#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+/* C4756: overflow in constant arithmetic */
+#pragma warning ( disable : 4756 )
+#endif
+
+static const double
+bp[] = {1.0, 1.5,},
+dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */
+dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */
+zero = 0.0,
+one = 1.0,
+two = 2.0,
+two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */
+huge = 1.0e300,
+tiny = 1.0e-300,
+ /* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */
+L1 = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */
+L2 = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */
+L3 = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */
+L4 = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */
+L5 = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */
+L6 = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */
+P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
+P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
+P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
+P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
+P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */
+lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
+lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */
+lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */
+ovt = 8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */
+cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */
+cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */
+cp_l = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/
+ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */
+ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/
+ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
+
+double attribute_hidden __ieee754_pow(double x, double y)
+{
+ double z,ax,z_h,z_l,p_h,p_l;
+ double y1,t1,t2,r,s,t,u,v,w;
+ int32_t i,j,k,yisint,n;
+ int32_t hx,hy,ix,iy;
+ u_int32_t lx,ly;
+
+ EXTRACT_WORDS(hx,lx,x);
+ /* x==1: 1**y = 1 (even if y is NaN) */
+ if (hx==0x3ff00000 && lx==0) {
+ return x;
+ }
+ ix = hx&0x7fffffff;
+
+ EXTRACT_WORDS(hy,ly,y);
+ iy = hy&0x7fffffff;
+
+ /* y==zero: x**0 = 1 */
+ if((iy|ly)==0) return one;
+
+ /* +-NaN return x+y */
+ if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) ||
+ iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0)))
+ return x+y;
+
+ /* determine if y is an odd int when x < 0
+ * yisint = 0 ... y is not an integer
+ * yisint = 1 ... y is an odd int
+ * yisint = 2 ... y is an even int
+ */
+ yisint = 0;
+ if(hx<0) {
+ if(iy>=0x43400000) yisint = 2; /* even integer y */
+ else if(iy>=0x3ff00000) {
+ k = (iy>>20)-0x3ff; /* exponent */
+ if(k>20) {
+ j = ly>>(52-k);
+ if((j<<(52-k))==ly) yisint = 2-(j&1);
+ } else if(ly==0) {
+ j = iy>>(20-k);
+ if((j<<(20-k))==iy) yisint = 2-(j&1);
+ }
+ }
+ }
+
+ /* special value of y */
+ if(ly==0) {
+ if (iy==0x7ff00000) { /* y is +-inf */
+ if (((ix-0x3ff00000)|lx)==0)
+ return one; /* +-1**+-inf is 1 (yes, weird rule) */
+ if (ix >= 0x3ff00000) /* (|x|>1)**+-inf = inf,0 */
+ return (hy>=0) ? y : zero;
+ /* (|x|<1)**-,+inf = inf,0 */
+ return (hy<0) ? -y : zero;
+ }
+ if(iy==0x3ff00000) { /* y is +-1 */
+ if(hy<0) return one/x; else return x;
+ }
+ if(hy==0x40000000) return x*x; /* y is 2 */
+ if(hy==0x3fe00000) { /* y is 0.5 */
+ if(hx>=0) /* x >= +0 */
+ return __ieee754_sqrt(x);
+ }
+ }
+
+ ax = fabs(x);
+ /* special value of x */
+ if(lx==0) {
+ if(ix==0x7ff00000||ix==0||ix==0x3ff00000){
+ z = ax; /*x is +-0,+-inf,+-1*/
+ if(hy<0) z = one/z; /* z = (1/|x|) */
+ if(hx<0) {
+ if(((ix-0x3ff00000)|yisint)==0) {
+ z = (z-z)/(z-z); /* (-1)**non-int is NaN */
+ } else if(yisint==1)
+ z = -z; /* (x<0)**odd = -(|x|**odd) */
+ }
+ return z;
+ }
+ }
+
+ /* (x<0)**(non-int) is NaN */
+ if(((((u_int32_t)hx>>31)-1)|yisint)==0) return (x-x)/(x-x);
+
+ /* |y| is huge */
+ if(iy>0x41e00000) { /* if |y| > 2**31 */
+ if(iy>0x43f00000){ /* if |y| > 2**64, must o/uflow */
+ if(ix<=0x3fefffff) return (hy<0)? huge*huge:tiny*tiny;
+ if(ix>=0x3ff00000) return (hy>0)? huge*huge:tiny*tiny;
+ }
+ /* over/underflow if x is not close to one */
+ if(ix<0x3fefffff) return (hy<0)? huge*huge:tiny*tiny;
+ if(ix>0x3ff00000) return (hy>0)? huge*huge:tiny*tiny;
+ /* now |1-x| is tiny <= 2**-20, suffice to compute
+ log(x) by x-x^2/2+x^3/3-x^4/4 */
+ t = x-1; /* t has 20 trailing zeros */
+ w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25));
+ u = ivln2_h*t; /* ivln2_h has 21 sig. bits */
+ v = t*ivln2_l-w*ivln2;
+ t1 = u+v;
+ SET_LOW_WORD(t1,0);
+ t2 = v-(t1-u);
+ } else {
+ double s2,s_h,s_l,t_h,t_l;
+ n = 0;
+ /* take care subnormal number */
+ if(ix<0x00100000)
+ {ax *= two53; n -= 53; GET_HIGH_WORD(ix,ax); }
+ n += ((ix)>>20)-0x3ff;
+ j = ix&0x000fffff;
+ /* determine interval */
+ ix = j|0x3ff00000; /* normalize ix */
+ if(j<=0x3988E) k=0; /* |x|<sqrt(3/2) */
+ else if(j<0xBB67A) k=1; /* |x|<sqrt(3) */
+ else {k=0;n+=1;ix -= 0x00100000;}
+ SET_HIGH_WORD(ax,ix);
+
+ /* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
+ u = ax-bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
+ v = one/(ax+bp[k]);
+ s = u*v;
+ s_h = s;
+ SET_LOW_WORD(s_h,0);
+ /* t_h=ax+bp[k] High */
+ t_h = zero;
+ SET_HIGH_WORD(t_h,((ix>>1)|0x20000000)+0x00080000+(k<<18));
+ t_l = ax - (t_h-bp[k]);
+ s_l = v*((u-s_h*t_h)-s_h*t_l);
+ /* compute log(ax) */
+ s2 = s*s;
+ r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6)))));
+ r += s_l*(s_h+s);
+ s2 = s_h*s_h;
+ t_h = 3.0+s2+r;
+ SET_LOW_WORD(t_h,0);
+ t_l = r-((t_h-3.0)-s2);
+ /* u+v = s*(1+...) */
+ u = s_h*t_h;
+ v = s_l*t_h+t_l*s;
+ /* 2/(3log2)*(s+...) */
+ p_h = u+v;
+ SET_LOW_WORD(p_h,0);
+ p_l = v-(p_h-u);
+ z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */
+ z_l = cp_l*p_h+p_l*cp+dp_l[k];
+ /* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */
+ t = (double)n;
+ t1 = (((z_h+z_l)+dp_h[k])+t);
+ SET_LOW_WORD(t1,0);
+ t2 = z_l-(((t1-t)-dp_h[k])-z_h);
+ }
+
+ s = one; /* s (sign of result -ve**odd) = -1 else = 1 */
+ if(((((u_int32_t)hx>>31)-1)|(yisint-1))==0)
+ s = -one;/* (-ve)**(odd int) */
+
+ /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */
+ y1 = y;
+ SET_LOW_WORD(y1,0);
+ p_l = (y-y1)*t1+y*t2;
+ p_h = y1*t1;
+ z = p_l+p_h;
+ EXTRACT_WORDS(j,i,z);
+ if (j>=0x40900000) { /* z >= 1024 */
+ if(((j-0x40900000)|i)!=0) /* if z > 1024 */
+ return s*huge*huge; /* overflow */
+ else {
+ if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */
+ }
+ } else if((j&0x7fffffff)>=0x4090cc00 ) { /* z <= -1075 */
+ if(((j-0xc090cc00)|i)!=0) /* z < -1075 */
+ return s*tiny*tiny; /* underflow */
+ else {
+ if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */
+ }
+ }
+ /*
+ * compute 2**(p_h+p_l)
+ */
+ i = j&0x7fffffff;
+ k = (i>>20)-0x3ff;
+ n = 0;
+ if(i>0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */
+ n = j+(0x00100000>>(k+1));
+ k = ((n&0x7fffffff)>>20)-0x3ff; /* new k for n */
+ t = zero;
+ SET_HIGH_WORD(t,n&~(0x000fffff>>k));
+ n = ((n&0x000fffff)|0x00100000)>>(20-k);
+ if(j<0) n = -n;
+ p_h -= t;
+ }
+ t = p_l+p_h;
+ SET_LOW_WORD(t,0);
+ u = t*lg2_h;
+ v = (p_l-(t-p_h))*lg2+t*lg2_l;
+ z = u+v;
+ w = v-(z-u);
+ t = z*z;
+ t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
+ r = (z*t1)/(t1-two)-(w+z*w);
+ z = one-(r-z);
+ GET_HIGH_WORD(j,z);
+ j += (n<<20);
+ if((j>>20)<=0) z = scalbn(z,n); /* subnormal output */
+ else SET_HIGH_WORD(z,j);
+ return s*z;
+}
+
+/*
+ * wrapper pow(x,y) return x**y
+ */
+#ifndef _IEEE_LIBM
+double pow(double x, double y)
+{
+ double z = __ieee754_pow(x, y);
+ if (_LIB_VERSION == _IEEE_|| isnan(y))
+ return z;
+ if (isnan(x)) {
+ if (y == 0.0)
+ return __kernel_standard(x, y, 42); /* pow(NaN,0.0) */
+ return z;
+ }
+ if (x == 0.0) {
+ if (y == 0.0)
+ return __kernel_standard(x, y, 20); /* pow(0.0,0.0) */
+ if (isfinite(y) && y < 0.0)
+ return __kernel_standard(x,y,23); /* pow(0.0,negative) */
+ return z;
+ }
+ if (!isfinite(z)) {
+ if (isfinite(x) && isfinite(y)) {
+ if (isnan(z))
+ return __kernel_standard(x, y, 24); /* pow neg**non-int */
+ return __kernel_standard(x, y, 21); /* pow overflow */
+ }
+ }
+ if (z == 0.0 && isfinite(x) && isfinite(y))
+ return __kernel_standard(x, y, 22); /* pow underflow */
+ return z;
+}
+#else
+strong_alias(__ieee754_pow, pow)
+#endif
+libm_hidden_def(pow)
diff --git a/src/3rdparty/SDL2/src/libm/e_rem_pio2.c b/src/3rdparty/SDL2/src/libm/e_rem_pio2.c
new file mode 100644
index 0000000..df7c2b8
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/e_rem_pio2.c
@@ -0,0 +1,161 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/* __ieee754_rem_pio2(x,y)
+ *
+ * return the remainder of x rem pi/2 in y[0]+y[1]
+ * use __kernel_rem_pio2()
+ */
+
+#include "math_libm.h"
+#include "math_private.h"
+
+/*
+ * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi
+ */
+static const int32_t two_over_pi[] = {
+0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62,
+0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A,
+0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129,
+0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41,
+0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8,
+0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF,
+0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5,
+0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08,
+0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3,
+0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880,
+0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B,
+};
+
+static const int32_t npio2_hw[] = {
+0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C,
+0x4025FDBB, 0x402921FB, 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C,
+0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB, 0x403AB41B, 0x403C463A,
+0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C,
+0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB,
+0x404858EB, 0x404921FB,
+};
+
+/*
+ * invpio2: 53 bits of 2/pi
+ * pio2_1: first 33 bit of pi/2
+ * pio2_1t: pi/2 - pio2_1
+ * pio2_2: second 33 bit of pi/2
+ * pio2_2t: pi/2 - (pio2_1+pio2_2)
+ * pio2_3: third 33 bit of pi/2
+ * pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3)
+ */
+
+static const double
+zero = 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
+half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
+two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
+invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
+pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */
+pio2_1t = 6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */
+pio2_2 = 6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */
+pio2_2t = 2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */
+pio2_3 = 2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */
+pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */
+
+int32_t attribute_hidden __ieee754_rem_pio2(double x, double *y)
+{
+ double z=0.0,w,t,r,fn;
+ double tx[3];
+ int32_t e0,i,j,nx,n,ix,hx;
+ u_int32_t low;
+
+ GET_HIGH_WORD(hx,x); /* high word of x */
+ ix = hx&0x7fffffff;
+ if(ix<=0x3fe921fb) /* |x| ~<= pi/4 , no need for reduction */
+ {y[0] = x; y[1] = 0; return 0;}
+ if(ix<0x4002d97c) { /* |x| < 3pi/4, special case with n=+-1 */
+ if(hx>0) {
+ z = x - pio2_1;
+ if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */
+ y[0] = z - pio2_1t;
+ y[1] = (z-y[0])-pio2_1t;
+ } else { /* near pi/2, use 33+33+53 bit pi */
+ z -= pio2_2;
+ y[0] = z - pio2_2t;
+ y[1] = (z-y[0])-pio2_2t;
+ }
+ return 1;
+ } else { /* negative x */
+ z = x + pio2_1;
+ if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */
+ y[0] = z + pio2_1t;
+ y[1] = (z-y[0])+pio2_1t;
+ } else { /* near pi/2, use 33+33+53 bit pi */
+ z += pio2_2;
+ y[0] = z + pio2_2t;
+ y[1] = (z-y[0])+pio2_2t;
+ }
+ return -1;
+ }
+ }
+ if(ix<=0x413921fb) { /* |x| ~<= 2^19*(pi/2), medium size */
+ t = fabs(x);
+ n = (int32_t) (t*invpio2+half);
+ fn = (double)n;
+ r = t-fn*pio2_1;
+ w = fn*pio2_1t; /* 1st round good to 85 bit */
+ if(n<32&&ix!=npio2_hw[n-1]) {
+ y[0] = r-w; /* quick check no cancellation */
+ } else {
+ u_int32_t high;
+ j = ix>>20;
+ y[0] = r-w;
+ GET_HIGH_WORD(high,y[0]);
+ i = j-((high>>20)&0x7ff);
+ if(i>16) { /* 2nd iteration needed, good to 118 */
+ t = r;
+ w = fn*pio2_2;
+ r = t-w;
+ w = fn*pio2_2t-((t-r)-w);
+ y[0] = r-w;
+ GET_HIGH_WORD(high,y[0]);
+ i = j-((high>>20)&0x7ff);
+ if(i>49) { /* 3rd iteration need, 151 bits acc */
+ t = r; /* will cover all possible cases */
+ w = fn*pio2_3;
+ r = t-w;
+ w = fn*pio2_3t-((t-r)-w);
+ y[0] = r-w;
+ }
+ }
+ }
+ y[1] = (r-y[0])-w;
+ if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
+ else return n;
+ }
+ /*
+ * all other (large) arguments
+ */
+ if(ix>=0x7ff00000) { /* x is inf or NaN */
+ y[0]=y[1]=x-x; return 0;
+ }
+ /* set z = scalbn(|x|,ilogb(x)-23) */
+ GET_LOW_WORD(low,x);
+ SET_LOW_WORD(z,low);
+ e0 = (ix>>20)-1046; /* e0 = ilogb(z)-23; */
+ SET_HIGH_WORD(z, ix - ((int32_t)(e0<<20)));
+ for(i=0;i<2;i++) {
+ tx[i] = (double)((int32_t)(z));
+ z = (z-tx[i])*two24;
+ }
+ tx[2] = z;
+ nx = 3;
+ while(tx[nx-1]==zero) nx--; /* skip zero term */
+ n = __kernel_rem_pio2(tx,y,e0,nx,2,two_over_pi);
+ if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
+ return n;
+}
diff --git a/src/3rdparty/SDL2/src/libm/e_sqrt.c b/src/3rdparty/SDL2/src/libm/e_sqrt.c
new file mode 100644
index 0000000..39c83e1
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/e_sqrt.c
@@ -0,0 +1,457 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/* __ieee754_sqrt(x)
+ * Return correctly rounded sqrt.
+ * ------------------------------------------
+ * | Use the hardware sqrt if you have one |
+ * ------------------------------------------
+ * Method:
+ * Bit by bit method using integer arithmetic. (Slow, but portable)
+ * 1. Normalization
+ * Scale x to y in [1,4) with even powers of 2:
+ * find an integer k such that 1 <= (y=x*2^(2k)) < 4, then
+ * sqrt(x) = 2^k * sqrt(y)
+ * 2. Bit by bit computation
+ * Let q = sqrt(y) truncated to i bit after binary point (q = 1),
+ * i 0
+ * i+1 2
+ * s = 2*q , and y = 2 * ( y - q ). (1)
+ * i i i i
+ *
+ * To compute q from q , one checks whether
+ * i+1 i
+ *
+ * -(i+1) 2
+ * (q + 2 ) <= y. (2)
+ * i
+ * -(i+1)
+ * If (2) is false, then q = q ; otherwise q = q + 2 .
+ * i+1 i i+1 i
+ *
+ * With some algebric manipulation, it is not difficult to see
+ * that (2) is equivalent to
+ * -(i+1)
+ * s + 2 <= y (3)
+ * i i
+ *
+ * The advantage of (3) is that s and y can be computed by
+ * i i
+ * the following recurrence formula:
+ * if (3) is false
+ *
+ * s = s , y = y ; (4)
+ * i+1 i i+1 i
+ *
+ * otherwise,
+ * -i -(i+1)
+ * s = s + 2 , y = y - s - 2 (5)
+ * i+1 i i+1 i i
+ *
+ * One may easily use induction to prove (4) and (5).
+ * Note. Since the left hand side of (3) contain only i+2 bits,
+ * it does not necessary to do a full (53-bit) comparison
+ * in (3).
+ * 3. Final rounding
+ * After generating the 53 bits result, we compute one more bit.
+ * Together with the remainder, we can decide whether the
+ * result is exact, bigger than 1/2ulp, or less than 1/2ulp
+ * (it will never equal to 1/2ulp).
+ * The rounding mode can be detected by checking whether
+ * huge + tiny is equal to huge, and whether huge - tiny is
+ * equal to huge for some floating point number "huge" and "tiny".
+ *
+ * Special cases:
+ * sqrt(+-0) = +-0 ... exact
+ * sqrt(inf) = inf
+ * sqrt(-ve) = NaN ... with invalid signal
+ * sqrt(NaN) = NaN ... with invalid signal for signaling NaN
+ *
+ * Other methods : see the appended file at the end of the program below.
+ *---------------
+ */
+
+#include "math_libm.h"
+#include "math_private.h"
+
+static const double one = 1.0, tiny = 1.0e-300;
+
+double attribute_hidden __ieee754_sqrt(double x)
+{
+ double z;
+ int32_t sign = (int)0x80000000;
+ int32_t ix0,s0,q,m,t,i;
+ u_int32_t r,t1,s1,ix1,q1;
+
+ EXTRACT_WORDS(ix0,ix1,x);
+
+ /* take care of Inf and NaN */
+ if((ix0&0x7ff00000)==0x7ff00000) {
+ return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf
+ sqrt(-inf)=sNaN */
+ }
+ /* take care of zero */
+ if(ix0<=0) {
+ if(((ix0&(~sign))|ix1)==0) return x;/* sqrt(+-0) = +-0 */
+ else if(ix0<0)
+ return (x-x)/(x-x); /* sqrt(-ve) = sNaN */
+ }
+ /* normalize x */
+ m = (ix0>>20);
+ if(m==0) { /* subnormal x */
+ while(ix0==0) {
+ m -= 21;
+ ix0 |= (ix1>>11); ix1 <<= 21;
+ }
+ for(i=0;(ix0&0x00100000)==0;i++) ix0<<=1;
+ m -= i-1;
+ ix0 |= (ix1>>(32-i));
+ ix1 <<= i;
+ }
+ m -= 1023; /* unbias exponent */
+ ix0 = (ix0&0x000fffff)|0x00100000;
+ if(m&1){ /* odd m, double x to make it even */
+ ix0 += ix0 + ((ix1&sign)>>31);
+ ix1 += ix1;
+ }
+ m >>= 1; /* m = [m/2] */
+
+ /* generate sqrt(x) bit by bit */
+ ix0 += ix0 + ((ix1&sign)>>31);
+ ix1 += ix1;
+ q = q1 = s0 = s1 = 0; /* [q,q1] = sqrt(x) */
+ r = 0x00200000; /* r = moving bit from right to left */
+
+ while(r!=0) {
+ t = s0+r;
+ if(t<=ix0) {
+ s0 = t+r;
+ ix0 -= t;
+ q += r;
+ }
+ ix0 += ix0 + ((ix1&sign)>>31);
+ ix1 += ix1;
+ r>>=1;
+ }
+
+ r = sign;
+ while(r!=0) {
+ t1 = s1+r;
+ t = s0;
+ if((t<ix0)||((t==ix0)&&(t1<=ix1))) {
+ s1 = t1+r;
+ if(((t1&sign)==sign)&&(s1&sign)==0) s0 += 1;
+ ix0 -= t;
+ if (ix1 < t1) ix0 -= 1;
+ ix1 -= t1;
+ q1 += r;
+ }
+ ix0 += ix0 + ((ix1&sign)>>31);
+ ix1 += ix1;
+ r>>=1;
+ }
+
+ /* use floating add to find out rounding direction */
+ if((ix0|ix1)!=0) {
+ z = one-tiny; /* trigger inexact flag */
+ if (z>=one) {
+ z = one+tiny;
+ if (q1==(u_int32_t)0xffffffff) { q1=0; q += 1;}
+ else if (z>one) {
+ if (q1==(u_int32_t)0xfffffffe) q+=1;
+ q1+=2;
+ } else
+ q1 += (q1&1);
+ }
+ }
+ ix0 = (q>>1)+0x3fe00000;
+ ix1 = q1>>1;
+ if ((q&1)==1) ix1 |= sign;
+ ix0 += (m <<20);
+ INSERT_WORDS(z,ix0,ix1);
+ return z;
+}
+
+/*
+ * wrapper sqrt(x)
+ */
+#ifndef _IEEE_LIBM
+double sqrt(double x)
+{
+ double z = __ieee754_sqrt(x);
+ if (_LIB_VERSION == _IEEE_ || isnan(x))
+ return z;
+ if (x < 0.0)
+ return __kernel_standard(x, x, 26); /* sqrt(negative) */
+ return z;
+}
+#else
+strong_alias(__ieee754_sqrt, sqrt)
+#endif
+libm_hidden_def(sqrt)
+
+
+/*
+Other methods (use floating-point arithmetic)
+-------------
+(This is a copy of a drafted paper by Prof W. Kahan
+and K.C. Ng, written in May, 1986)
+
+ Two algorithms are given here to implement sqrt(x)
+ (IEEE double precision arithmetic) in software.
+ Both supply sqrt(x) correctly rounded. The first algorithm (in
+ Section A) uses newton iterations and involves four divisions.
+ The second one uses reciproot iterations to avoid division, but
+ requires more multiplications. Both algorithms need the ability
+ to chop results of arithmetic operations instead of round them,
+ and the INEXACT flag to indicate when an arithmetic operation
+ is executed exactly with no roundoff error, all part of the
+ standard (IEEE 754-1985). The ability to perform shift, add,
+ subtract and logical AND operations upon 32-bit words is needed
+ too, though not part of the standard.
+
+A. sqrt(x) by Newton Iteration
+
+ (1) Initial approximation
+
+ Let x0 and x1 be the leading and the trailing 32-bit words of
+ a floating point number x (in IEEE double format) respectively
+
+ 1 11 52 ...widths
+ ------------------------------------------------------
+ x: |s| e | f |
+ ------------------------------------------------------
+ msb lsb msb lsb ...order
+
+
+ ------------------------ ------------------------
+ x0: |s| e | f1 | x1: | f2 |
+ ------------------------ ------------------------
+
+ By performing shifts and subtracts on x0 and x1 (both regarded
+ as integers), we obtain an 8-bit approximation of sqrt(x) as
+ follows.
+
+ k := (x0>>1) + 0x1ff80000;
+ y0 := k - T1[31&(k>>15)]. ... y ~ sqrt(x) to 8 bits
+ Here k is a 32-bit integer and T1[] is an integer array containing
+ correction terms. Now magically the floating value of y (y's
+ leading 32-bit word is y0, the value of its trailing word is 0)
+ approximates sqrt(x) to almost 8-bit.
+
+ Value of T1:
+ static int T1[32]= {
+ 0, 1024, 3062, 5746, 9193, 13348, 18162, 23592,
+ 29598, 36145, 43202, 50740, 58733, 67158, 75992, 85215,
+ 83599, 71378, 60428, 50647, 41945, 34246, 27478, 21581,
+ 16499, 12183, 8588, 5674, 3403, 1742, 661, 130,};
+
+ (2) Iterative refinement
+
+ Apply Heron's rule three times to y, we have y approximates
+ sqrt(x) to within 1 ulp (Unit in the Last Place):
+
+ y := (y+x/y)/2 ... almost 17 sig. bits
+ y := (y+x/y)/2 ... almost 35 sig. bits
+ y := y-(y-x/y)/2 ... within 1 ulp
+
+
+ Remark 1.
+ Another way to improve y to within 1 ulp is:
+
+ y := (y+x/y) ... almost 17 sig. bits to 2*sqrt(x)
+ y := y - 0x00100006 ... almost 18 sig. bits to sqrt(x)
+
+ 2
+ (x-y )*y
+ y := y + 2* ---------- ...within 1 ulp
+ 2
+ 3y + x
+
+
+ This formula has one division fewer than the one above; however,
+ it requires more multiplications and additions. Also x must be
+ scaled in advance to avoid spurious overflow in evaluating the
+ expression 3y*y+x. Hence it is not recommended uless division
+ is slow. If division is very slow, then one should use the
+ reciproot algorithm given in section B.
+
+ (3) Final adjustment
+
+ By twiddling y's last bit it is possible to force y to be
+ correctly rounded according to the prevailing rounding mode
+ as follows. Let r and i be copies of the rounding mode and
+ inexact flag before entering the square root program. Also we
+ use the expression y+-ulp for the next representable floating
+ numbers (up and down) of y. Note that y+-ulp = either fixed
+ point y+-1, or multiply y by nextafter(1,+-inf) in chopped
+ mode.
+
+ I := FALSE; ... reset INEXACT flag I
+ R := RZ; ... set rounding mode to round-toward-zero
+ z := x/y; ... chopped quotient, possibly inexact
+ If(not I) then { ... if the quotient is exact
+ if(z=y) {
+ I := i; ... restore inexact flag
+ R := r; ... restore rounded mode
+ return sqrt(x):=y.
+ } else {
+ z := z - ulp; ... special rounding
+ }
+ }
+ i := TRUE; ... sqrt(x) is inexact
+ If (r=RN) then z=z+ulp ... rounded-to-nearest
+ If (r=RP) then { ... round-toward-+inf
+ y = y+ulp; z=z+ulp;
+ }
+ y := y+z; ... chopped sum
+ y0:=y0-0x00100000; ... y := y/2 is correctly rounded.
+ I := i; ... restore inexact flag
+ R := r; ... restore rounded mode
+ return sqrt(x):=y.
+
+ (4) Special cases
+
+ Square root of +inf, +-0, or NaN is itself;
+ Square root of a negative number is NaN with invalid signal.
+
+
+B. sqrt(x) by Reciproot Iteration
+
+ (1) Initial approximation
+
+ Let x0 and x1 be the leading and the trailing 32-bit words of
+ a floating point number x (in IEEE double format) respectively
+ (see section A). By performing shifs and subtracts on x0 and y0,
+ we obtain a 7.8-bit approximation of 1/sqrt(x) as follows.
+
+ k := 0x5fe80000 - (x0>>1);
+ y0:= k - T2[63&(k>>14)]. ... y ~ 1/sqrt(x) to 7.8 bits
+
+ Here k is a 32-bit integer and T2[] is an integer array
+ containing correction terms. Now magically the floating
+ value of y (y's leading 32-bit word is y0, the value of
+ its trailing word y1 is set to zero) approximates 1/sqrt(x)
+ to almost 7.8-bit.
+
+ Value of T2:
+ static int T2[64]= {
+ 0x1500, 0x2ef8, 0x4d67, 0x6b02, 0x87be, 0xa395, 0xbe7a, 0xd866,
+ 0xf14a, 0x1091b,0x11fcd,0x13552,0x14999,0x15c98,0x16e34,0x17e5f,
+ 0x18d03,0x19a01,0x1a545,0x1ae8a,0x1b5c4,0x1bb01,0x1bfde,0x1c28d,
+ 0x1c2de,0x1c0db,0x1ba73,0x1b11c,0x1a4b5,0x1953d,0x18266,0x16be0,
+ 0x1683e,0x179d8,0x18a4d,0x19992,0x1a789,0x1b445,0x1bf61,0x1c989,
+ 0x1d16d,0x1d77b,0x1dddf,0x1e2ad,0x1e5bf,0x1e6e8,0x1e654,0x1e3cd,
+ 0x1df2a,0x1d635,0x1cb16,0x1be2c,0x1ae4e,0x19bde,0x1868e,0x16e2e,
+ 0x1527f,0x1334a,0x11051,0xe951, 0xbe01, 0x8e0d, 0x5924, 0x1edd,};
+
+ (2) Iterative refinement
+
+ Apply Reciproot iteration three times to y and multiply the
+ result by x to get an approximation z that matches sqrt(x)
+ to about 1 ulp. To be exact, we will have
+ -1ulp < sqrt(x)-z<1.0625ulp.
+
+ ... set rounding mode to Round-to-nearest
+ y := y*(1.5-0.5*x*y*y) ... almost 15 sig. bits to 1/sqrt(x)
+ y := y*((1.5-2^-30)+0.5*x*y*y)... about 29 sig. bits to 1/sqrt(x)
+ ... special arrangement for better accuracy
+ z := x*y ... 29 bits to sqrt(x), with z*y<1
+ z := z + 0.5*z*(1-z*y) ... about 1 ulp to sqrt(x)
+
+ Remark 2. The constant 1.5-2^-30 is chosen to bias the error so that
+ (a) the term z*y in the final iteration is always less than 1;
+ (b) the error in the final result is biased upward so that
+ -1 ulp < sqrt(x) - z < 1.0625 ulp
+ instead of |sqrt(x)-z|<1.03125ulp.
+
+ (3) Final adjustment
+
+ By twiddling y's last bit it is possible to force y to be
+ correctly rounded according to the prevailing rounding mode
+ as follows. Let r and i be copies of the rounding mode and
+ inexact flag before entering the square root program. Also we
+ use the expression y+-ulp for the next representable floating
+ numbers (up and down) of y. Note that y+-ulp = either fixed
+ point y+-1, or multiply y by nextafter(1,+-inf) in chopped
+ mode.
+
+ R := RZ; ... set rounding mode to round-toward-zero
+ switch(r) {
+ case RN: ... round-to-nearest
+ if(x<= z*(z-ulp)...chopped) z = z - ulp; else
+ if(x<= z*(z+ulp)...chopped) z = z; else z = z+ulp;
+ break;
+ case RZ:case RM: ... round-to-zero or round-to--inf
+ R:=RP; ... reset rounding mod to round-to-+inf
+ if(x<z*z ... rounded up) z = z - ulp; else
+ if(x>=(z+ulp)*(z+ulp) ...rounded up) z = z+ulp;
+ break;
+ case RP: ... round-to-+inf
+ if(x>(z+ulp)*(z+ulp)...chopped) z = z+2*ulp; else
+ if(x>z*z ...chopped) z = z+ulp;
+ break;
+ }
+
+ Remark 3. The above comparisons can be done in fixed point. For
+ example, to compare x and w=z*z chopped, it suffices to compare
+ x1 and w1 (the trailing parts of x and w), regarding them as
+ two's complement integers.
+
+ ...Is z an exact square root?
+ To determine whether z is an exact square root of x, let z1 be the
+ trailing part of z, and also let x0 and x1 be the leading and
+ trailing parts of x.
+
+ If ((z1&0x03ffffff)!=0) ... not exact if trailing 26 bits of z!=0
+ I := 1; ... Raise Inexact flag: z is not exact
+ else {
+ j := 1 - [(x0>>20)&1] ... j = logb(x) mod 2
+ k := z1 >> 26; ... get z's 25-th and 26-th
+ fraction bits
+ I := i or (k&j) or ((k&(j+j+1))!=(x1&3));
+ }
+ R:= r ... restore rounded mode
+ return sqrt(x):=z.
+
+ If multiplication is cheaper then the foregoing red tape, the
+ Inexact flag can be evaluated by
+
+ I := i;
+ I := (z*z!=x) or I.
+
+ Note that z*z can overwrite I; this value must be sensed if it is
+ True.
+
+ Remark 4. If z*z = x exactly, then bit 25 to bit 0 of z1 must be
+ zero.
+
+ --------------------
+ z1: | f2 |
+ --------------------
+ bit 31 bit 0
+
+ Further more, bit 27 and 26 of z1, bit 0 and 1 of x1, and the odd
+ or even of logb(x) have the following relations:
+
+ -------------------------------------------------
+ bit 27,26 of z1 bit 1,0 of x1 logb(x)
+ -------------------------------------------------
+ 00 00 odd and even
+ 01 01 even
+ 10 10 odd
+ 10 00 even
+ 11 01 even
+ -------------------------------------------------
+
+ (4) Special cases (see (4) of Section A).
+
+ */
diff --git a/src/3rdparty/SDL2/src/libm/k_cos.c b/src/3rdparty/SDL2/src/libm/k_cos.c
new file mode 100644
index 0000000..e1326fa
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/k_cos.c
@@ -0,0 +1,82 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/*
+ * __kernel_cos( x, y )
+ * kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164
+ * Input x is assumed to be bounded by ~pi/4 in magnitude.
+ * Input y is the tail of x.
+ *
+ * Algorithm
+ * 1. Since cos(-x) = cos(x), we need only to consider positive x.
+ * 2. if x < 2^-27 (hx<0x3e400000 0), return 1 with inexact if x!=0.
+ * 3. cos(x) is approximated by a polynomial of degree 14 on
+ * [0,pi/4]
+ * 4 14
+ * cos(x) ~ 1 - x*x/2 + C1*x + ... + C6*x
+ * where the remez error is
+ *
+ * | 2 4 6 8 10 12 14 | -58
+ * |cos(x)-(1-.5*x +C1*x +C2*x +C3*x +C4*x +C5*x +C6*x )| <= 2
+ * | |
+ *
+ * 4 6 8 10 12 14
+ * 4. let r = C1*x +C2*x +C3*x +C4*x +C5*x +C6*x , then
+ * cos(x) = 1 - x*x/2 + r
+ * since cos(x+y) ~ cos(x) - sin(x)*y
+ * ~ cos(x) - x*y,
+ * a correction term is necessary in cos(x) and hence
+ * cos(x+y) = 1 - (x*x/2 - (r - x*y))
+ * For better accuracy when x > 0.3, let qx = |x|/4 with
+ * the last 32 bits mask off, and if x > 0.78125, let qx = 0.28125.
+ * Then
+ * cos(x+y) = (1-qx) - ((x*x/2-qx) - (r-x*y)).
+ * Note that 1-qx and (x*x/2-qx) is EXACT here, and the
+ * magnitude of the latter is at least a quarter of x*x/2,
+ * thus, reducing the rounding error in the subtraction.
+ */
+
+#include "math_libm.h"
+#include "math_private.h"
+
+static const double
+one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
+C1 = 4.16666666666666019037e-02, /* 0x3FA55555, 0x5555554C */
+C2 = -1.38888888888741095749e-03, /* 0xBF56C16C, 0x16C15177 */
+C3 = 2.48015872894767294178e-05, /* 0x3EFA01A0, 0x19CB1590 */
+C4 = -2.75573143513906633035e-07, /* 0xBE927E4F, 0x809C52AD */
+C5 = 2.08757232129817482790e-09, /* 0x3E21EE9E, 0xBDB4B1C4 */
+C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */
+
+double attribute_hidden __kernel_cos(double x, double y)
+{
+ double a,hz,z,r,qx;
+ int32_t ix;
+ GET_HIGH_WORD(ix,x);
+ ix &= 0x7fffffff; /* ix = |x|'s high word*/
+ if(ix<0x3e400000) { /* if x < 2**27 */
+ if(((int)x)==0) return one; /* generate inexact */
+ }
+ z = x*x;
+ r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6)))));
+ if(ix < 0x3FD33333) /* if |x| < 0.3 */
+ return one - (0.5*z - (z*r - x*y));
+ else {
+ if(ix > 0x3fe90000) { /* x > 0.78125 */
+ qx = 0.28125;
+ } else {
+ INSERT_WORDS(qx,ix-0x00200000,0); /* x/4 */
+ }
+ hz = 0.5*z-qx;
+ a = one-qx;
+ return a - (hz - (z*r-x*y));
+ }
+}
diff --git a/src/3rdparty/SDL2/src/libm/k_rem_pio2.c b/src/3rdparty/SDL2/src/libm/k_rem_pio2.c
new file mode 100644
index 0000000..7b04275
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/k_rem_pio2.c
@@ -0,0 +1,299 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/*
+ * __kernel_rem_pio2(x,y,e0,nx,prec,ipio2)
+ * double x[],y[]; int e0,nx,prec; int ipio2[];
+ *
+ * __kernel_rem_pio2 return the last three digits of N with
+ * y = x - N*pi/2
+ * so that |y| < pi/2.
+ *
+ * The method is to compute the integer (mod 8) and fraction parts of
+ * (2/pi)*x without doing the full multiplication. In general we
+ * skip the part of the product that are known to be a huge integer (
+ * more accurately, = 0 mod 8 ). Thus the number of operations are
+ * independent of the exponent of the input.
+ *
+ * (2/pi) is represented by an array of 24-bit integers in ipio2[].
+ *
+ * Input parameters:
+ * x[] The input value (must be positive) is broken into nx
+ * pieces of 24-bit integers in double precision format.
+ * x[i] will be the i-th 24 bit of x. The scaled exponent
+ * of x[0] is given in input parameter e0 (i.e., x[0]*2^e0
+ * match x's up to 24 bits.
+ *
+ * Example of breaking a double positive z into x[0]+x[1]+x[2]:
+ * e0 = ilogb(z)-23
+ * z = scalbn(z,-e0)
+ * for i = 0,1,2
+ * x[i] = floor(z)
+ * z = (z-x[i])*2**24
+ *
+ *
+ * y[] ouput result in an array of double precision numbers.
+ * The dimension of y[] is:
+ * 24-bit precision 1
+ * 53-bit precision 2
+ * 64-bit precision 2
+ * 113-bit precision 3
+ * The actual value is the sum of them. Thus for 113-bit
+ * precison, one may have to do something like:
+ *
+ * long double t,w,r_head, r_tail;
+ * t = (long double)y[2] + (long double)y[1];
+ * w = (long double)y[0];
+ * r_head = t+w;
+ * r_tail = w - (r_head - t);
+ *
+ * e0 The exponent of x[0]
+ *
+ * nx dimension of x[]
+ *
+ * prec an integer indicating the precision:
+ * 0 24 bits (single)
+ * 1 53 bits (double)
+ * 2 64 bits (extended)
+ * 3 113 bits (quad)
+ *
+ * ipio2[]
+ * integer array, contains the (24*i)-th to (24*i+23)-th
+ * bit of 2/pi after binary point. The corresponding
+ * floating value is
+ *
+ * ipio2[i] * 2^(-24(i+1)).
+ *
+ * External function:
+ * double scalbn(), floor();
+ *
+ *
+ * Here is the description of some local variables:
+ *
+ * jk jk+1 is the initial number of terms of ipio2[] needed
+ * in the computation. The recommended value is 2,3,4,
+ * 6 for single, double, extended,and quad.
+ *
+ * jz local integer variable indicating the number of
+ * terms of ipio2[] used.
+ *
+ * jx nx - 1
+ *
+ * jv index for pointing to the suitable ipio2[] for the
+ * computation. In general, we want
+ * ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8
+ * is an integer. Thus
+ * e0-3-24*jv >= 0 or (e0-3)/24 >= jv
+ * Hence jv = max(0,(e0-3)/24).
+ *
+ * jp jp+1 is the number of terms in PIo2[] needed, jp = jk.
+ *
+ * q[] double array with integral value, representing the
+ * 24-bits chunk of the product of x and 2/pi.
+ *
+ * q0 the corresponding exponent of q[0]. Note that the
+ * exponent for q[i] would be q0-24*i.
+ *
+ * PIo2[] double precision array, obtained by cutting pi/2
+ * into 24 bits chunks.
+ *
+ * f[] ipio2[] in floating point
+ *
+ * iq[] integer array by breaking up q[] in 24-bits chunk.
+ *
+ * fq[] final product of x*(2/pi) in fq[0],..,fq[jk]
+ *
+ * ih integer. If >0 it indicates q[] is >= 0.5, hence
+ * it also indicates the *sign* of the result.
+ *
+ */
+
+
+/*
+ * Constants:
+ * The hexadecimal values are the intended ones for the following
+ * constants. The decimal values may be used, provided that the
+ * compiler will convert from decimal to binary accurately enough
+ * to produce the hexadecimal values shown.
+ */
+
+#include "math_libm.h"
+#include "math_private.h"
+
+static const int init_jk[] = {2,3,4,6}; /* initial value for jk */
+
+static const double PIo2[] = {
+ 1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */
+ 7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */
+ 5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */
+ 3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */
+ 1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */
+ 1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */
+ 2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */
+ 2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */
+};
+
+static const double
+zero = 0.0,
+one = 1.0,
+two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
+twon24 = 5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */
+
+int attribute_hidden __kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const int32_t *ipio2)
+{
+ int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
+ double z,fw,f[20],fq[20],q[20];
+
+ /* initialize jk*/
+ jk = init_jk[prec];
+ jp = jk;
+
+ /* determine jx,jv,q0, note that 3>q0 */
+ jx = nx-1;
+ jv = (e0-3)/24; if(jv<0) jv=0;
+ q0 = e0-24*(jv+1);
+
+ /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */
+ j = jv-jx; m = jx+jk;
+ for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (double) ipio2[j];
+
+ /* compute q[0],q[1],...q[jk] */
+ for (i=0;i<=jk;i++) {
+ for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j];
+ q[i] = fw;
+ }
+
+ jz = jk;
+recompute:
+ /* distill q[] into iq[] reversingly */
+ for(i=0,j=jz,z=q[jz];j>0;i++,j--) {
+ fw = (double)((int32_t)(twon24* z));
+ iq[i] = (int32_t)(z-two24*fw);
+ z = q[j-1]+fw;
+ }
+
+ /* compute n */
+ z = scalbn(z,q0); /* actual value of z */
+ z -= 8.0*floor(z*0.125); /* trim off integer >= 8 */
+ n = (int32_t) z;
+ z -= (double)n;
+ ih = 0;
+ if(q0>0) { /* need iq[jz-1] to determine n */
+ i = (iq[jz-1]>>(24-q0)); n += i;
+ iq[jz-1] -= i<<(24-q0);
+ ih = iq[jz-1]>>(23-q0);
+ }
+ else if(q0==0) ih = iq[jz-1]>>23;
+ else if(z>=0.5) ih=2;
+
+ if(ih>0) { /* q > 0.5 */
+ n += 1; carry = 0;
+ for(i=0;i<jz ;i++) { /* compute 1-q */
+ j = iq[i];
+ if(carry==0) {
+ if(j!=0) {
+ carry = 1; iq[i] = 0x1000000- j;
+ }
+ } else iq[i] = 0xffffff - j;
+ }
+ if(q0>0) { /* rare case: chance is 1 in 12 */
+ switch(q0) {
+ case 1:
+ iq[jz-1] &= 0x7fffff; break;
+ case 2:
+ iq[jz-1] &= 0x3fffff; break;
+ }
+ }
+ if(ih==2) {
+ z = one - z;
+ if(carry!=0) z -= scalbn(one,q0);
+ }
+ }
+
+ /* check if recomputation is needed */
+ if(z==zero) {
+ j = 0;
+ for (i=jz-1;i>=jk;i--) j |= iq[i];
+ if(j==0) { /* need recomputation */
+ for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */
+
+ for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */
+ f[jx+i] = (double) ipio2[jv+i];
+ for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j];
+ q[i] = fw;
+ }
+ jz += k;
+ goto recompute;
+ }
+ }
+
+ /* chop off zero terms */
+ if(z==0.0) {
+ jz -= 1; q0 -= 24;
+ while(iq[jz]==0) { jz--; q0-=24;}
+ } else { /* break z into 24-bit if necessary */
+ z = scalbn(z,-q0);
+ if(z>=two24) {
+ fw = (double)((int32_t)(twon24*z));
+ iq[jz] = (int32_t)(z-two24*fw);
+ jz += 1; q0 += 24;
+ iq[jz] = (int32_t) fw;
+ } else iq[jz] = (int32_t) z ;
+ }
+
+ /* convert integer "bit" chunk to floating-point value */
+ fw = scalbn(one,q0);
+ for(i=jz;i>=0;i--) {
+ q[i] = fw*(double)iq[i]; fw*=twon24;
+ }
+
+ /* compute PIo2[0,...,jp]*q[jz,...,0] */
+ for(i=jz;i>=0;i--) {
+ for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k];
+ fq[jz-i] = fw;
+ }
+
+ /* compress fq[] into y[] */
+ switch(prec) {
+ case 0:
+ fw = 0.0;
+ for (i=jz;i>=0;i--) fw += fq[i];
+ y[0] = (ih==0)? fw: -fw;
+ break;
+ case 1:
+ case 2:
+ fw = 0.0;
+ for (i=jz;i>=0;i--) fw += fq[i];
+ y[0] = (ih==0)? fw: -fw;
+ fw = fq[0]-fw;
+ for (i=1;i<=jz;i++) fw += fq[i];
+ y[1] = (ih==0)? fw: -fw;
+ break;
+ case 3: /* painful */
+ for (i=jz;i>0;i--) {
+ fw = fq[i-1]+fq[i];
+ fq[i] += fq[i-1]-fw;
+ fq[i-1] = fw;
+ }
+ for (i=jz;i>1;i--) {
+ fw = fq[i-1]+fq[i];
+ fq[i] += fq[i-1]-fw;
+ fq[i-1] = fw;
+ }
+ for (fw=0.0,i=jz;i>=2;i--) fw += fq[i];
+ if(ih==0) {
+ y[0] = fq[0]; y[1] = fq[1]; y[2] = fw;
+ } else {
+ y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw;
+ }
+ }
+ return n&7;
+}
diff --git a/src/3rdparty/SDL2/src/libm/k_sin.c b/src/3rdparty/SDL2/src/libm/k_sin.c
new file mode 100644
index 0000000..3520d6b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/k_sin.c
@@ -0,0 +1,65 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/* __kernel_sin( x, y, iy)
+ * kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854
+ * Input x is assumed to be bounded by ~pi/4 in magnitude.
+ * Input y is the tail of x.
+ * Input iy indicates whether y is 0. (if iy=0, y assume to be 0).
+ *
+ * Algorithm
+ * 1. Since sin(-x) = -sin(x), we need only to consider positive x.
+ * 2. if x < 2^-27 (hx<0x3e400000 0), return x with inexact if x!=0.
+ * 3. sin(x) is approximated by a polynomial of degree 13 on
+ * [0,pi/4]
+ * 3 13
+ * sin(x) ~ x + S1*x + ... + S6*x
+ * where
+ *
+ * |sin(x) 2 4 6 8 10 12 | -58
+ * |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2
+ * | x |
+ *
+ * 4. sin(x+y) = sin(x) + sin'(x')*y
+ * ~ sin(x) + (1-x*x/2)*y
+ * For better accuracy, let
+ * 3 2 2 2 2
+ * r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6))))
+ * then 3 2
+ * sin(x) = x + (S1*x + (x *(r-y/2)+y))
+ */
+
+#include "math_libm.h"
+#include "math_private.h"
+
+static const double
+half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
+S1 = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */
+S2 = 8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */
+S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */
+S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */
+S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */
+S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */
+
+double attribute_hidden __kernel_sin(double x, double y, int iy)
+{
+ double z,r,v;
+ int32_t ix;
+ GET_HIGH_WORD(ix,x);
+ ix &= 0x7fffffff; /* high word of x */
+ if(ix<0x3e400000) /* |x| < 2**-27 */
+ {if((int)x==0) return x;} /* generate inexact */
+ z = x*x;
+ v = z*x;
+ r = S2+z*(S3+z*(S4+z*(S5+z*S6)));
+ if(iy==0) return x+v*(S1+z*r);
+ else return x-((z*(half*y-v*r)-y)-v*S1);
+}
diff --git a/src/3rdparty/SDL2/src/libm/k_tan.c b/src/3rdparty/SDL2/src/libm/k_tan.c
new file mode 100644
index 0000000..47b4e3d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/k_tan.c
@@ -0,0 +1,118 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/* __kernel_tan( x, y, k )
+ * kernel tan function on [-pi/4, pi/4], pi/4 ~ 0.7854
+ * Input x is assumed to be bounded by ~pi/4 in magnitude.
+ * Input y is the tail of x.
+ * Input k indicates whether tan (if k=1) or
+ * -1/tan (if k= -1) is returned.
+ *
+ * Algorithm
+ * 1. Since tan(-x) = -tan(x), we need only to consider positive x.
+ * 2. if x < 2^-28 (hx<0x3e300000 0), return x with inexact if x!=0.
+ * 3. tan(x) is approximated by a odd polynomial of degree 27 on
+ * [0,0.67434]
+ * 3 27
+ * tan(x) ~ x + T1*x + ... + T13*x
+ * where
+ *
+ * |tan(x) 2 4 26 | -59.2
+ * |----- - (1+T1*x +T2*x +.... +T13*x )| <= 2
+ * | x |
+ *
+ * Note: tan(x+y) = tan(x) + tan'(x)*y
+ * ~ tan(x) + (1+x*x)*y
+ * Therefore, for better accuracy in computing tan(x+y), let
+ * 3 2 2 2 2
+ * r = x *(T2+x *(T3+x *(...+x *(T12+x *T13))))
+ * then
+ * 3 2
+ * tan(x+y) = x + (T1*x + (x *(r+y)+y))
+ *
+ * 4. For x in [0.67434,pi/4], let y = pi/4 - x, then
+ * tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y))
+ * = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y)))
+ */
+
+#include "math_libm.h"
+#include "math_private.h"
+
+static const double
+one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
+pio4 = 7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */
+pio4lo= 3.06161699786838301793e-17, /* 0x3C81A626, 0x33145C07 */
+T[] = {
+ 3.33333333333334091986e-01, /* 0x3FD55555, 0x55555563 */
+ 1.33333333333201242699e-01, /* 0x3FC11111, 0x1110FE7A */
+ 5.39682539762260521377e-02, /* 0x3FABA1BA, 0x1BB341FE */
+ 2.18694882948595424599e-02, /* 0x3F9664F4, 0x8406D637 */
+ 8.86323982359930005737e-03, /* 0x3F8226E3, 0xE96E8493 */
+ 3.59207910759131235356e-03, /* 0x3F6D6D22, 0xC9560328 */
+ 1.45620945432529025516e-03, /* 0x3F57DBC8, 0xFEE08315 */
+ 5.88041240820264096874e-04, /* 0x3F4344D8, 0xF2F26501 */
+ 2.46463134818469906812e-04, /* 0x3F3026F7, 0x1A8D1068 */
+ 7.81794442939557092300e-05, /* 0x3F147E88, 0xA03792A6 */
+ 7.14072491382608190305e-05, /* 0x3F12B80F, 0x32F0A7E9 */
+ -1.85586374855275456654e-05, /* 0xBEF375CB, 0xDB605373 */
+ 2.59073051863633712884e-05, /* 0x3EFB2A70, 0x74BF7AD4 */
+};
+
+double attribute_hidden __kernel_tan(double x, double y, int iy)
+{
+ double z,r,v,w,s;
+ int32_t ix,hx;
+ GET_HIGH_WORD(hx,x);
+ ix = hx&0x7fffffff; /* high word of |x| */
+ if(ix<0x3e300000) /* x < 2**-28 */
+ {if((int)x==0) { /* generate inexact */
+ u_int32_t low;
+ GET_LOW_WORD(low,x);
+ if(((ix|low)|(iy+1))==0) return one/fabs(x);
+ else return (iy==1)? x: -one/x;
+ }
+ }
+ if(ix>=0x3FE59428) { /* |x|>=0.6744 */
+ if(hx<0) {x = -x; y = -y;}
+ z = pio4-x;
+ w = pio4lo-y;
+ x = z+w; y = 0.0;
+ }
+ z = x*x;
+ w = z*z;
+ /* Break x^5*(T[1]+x^2*T[2]+...) into
+ * x^5(T[1]+x^4*T[3]+...+x^20*T[11]) +
+ * x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12]))
+ */
+ r = T[1]+w*(T[3]+w*(T[5]+w*(T[7]+w*(T[9]+w*T[11]))));
+ v = z*(T[2]+w*(T[4]+w*(T[6]+w*(T[8]+w*(T[10]+w*T[12])))));
+ s = z*x;
+ r = y + z*(s*(r+v)+y);
+ r += T[0]*s;
+ w = x+r;
+ if(ix>=0x3FE59428) {
+ v = (double)iy;
+ return (double)(1-((hx>>30)&2))*(v-2.0*(x-(w*w/(w+v)-r)));
+ }
+ if(iy==1) return w;
+ else { /* if allow error up to 2 ulp,
+ simply return -1.0/(x+r) here */
+ /* compute -1.0/(x+r) accurately */
+ double a,t;
+ z = w;
+ SET_LOW_WORD(z,0);
+ v = r-(z - x); /* z+v = r+x */
+ t = a = -1.0/w; /* a = -1.0/w */
+ SET_LOW_WORD(t,0);
+ s = 1.0+t*z;
+ return t+a*(s+t*v);
+ }
+}
diff --git a/src/3rdparty/SDL2/src/libm/math_libm.h b/src/3rdparty/SDL2/src/libm/math_libm.h
new file mode 100644
index 0000000..eb7bdd5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/math_libm.h
@@ -0,0 +1,40 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* Math routines from uClibc: http://www.uclibc.org */
+
+double SDL_uclibc_atan(double x);
+double SDL_uclibc_atan2(double y, double x);
+double SDL_uclibc_copysign(double x, double y);
+double SDL_uclibc_cos(double x);
+double SDL_uclibc_fabs(double x);
+double SDL_uclibc_floor(double x);
+double SDL_uclibc_fmod(double x, double y);
+double SDL_uclibc_log(double x);
+double SDL_uclibc_log10(double x);
+double SDL_uclibc_pow(double x, double y);
+double SDL_uclibc_scalbn(double x, int n);
+double SDL_uclibc_sin(double x);
+double SDL_uclibc_sqrt(double x);
+double SDL_uclibc_tan(double x);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/libm/math_private.h b/src/3rdparty/SDL2/src/libm/math_private.h
new file mode 100644
index 0000000..1c0c8a4
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/math_private.h
@@ -0,0 +1,226 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/*
+ * from: @(#)fdlibm.h 5.1 93/09/24
+ * $Id: math_private.h,v 1.3 2004/02/09 07:10:38 andersen Exp $
+ */
+
+#ifndef _MATH_PRIVATE_H_
+#define _MATH_PRIVATE_H_
+
+/* #include <endian.h> */
+#include "SDL_endian.h"
+/* #include <sys/types.h> */
+
+#define _IEEE_LIBM
+#define attribute_hidden
+#define libm_hidden_proto(x)
+#define libm_hidden_def(x)
+#define strong_alias(x, y)
+
+#ifndef __HAIKU__ /* already defined in a system header. */
+typedef unsigned int u_int32_t;
+#endif
+
+#define atan SDL_uclibc_atan
+#define __ieee754_atan2 SDL_uclibc_atan2
+#define copysign SDL_uclibc_copysign
+#define cos SDL_uclibc_cos
+#define fabs SDL_uclibc_fabs
+#define floor SDL_uclibc_floor
+#define __ieee754_fmod SDL_uclibc_fmod
+#define __ieee754_log SDL_uclibc_log
+#define __ieee754_log10 SDL_uclibc_log10
+#define __ieee754_pow SDL_uclibc_pow
+#define scalbln SDL_uclibc_scalbln
+#define scalbn SDL_uclibc_scalbn
+#define sin SDL_uclibc_sin
+#define __ieee754_sqrt SDL_uclibc_sqrt
+#define tan SDL_uclibc_tan
+
+/* The original fdlibm code used statements like:
+ n0 = ((*(int*)&one)>>29)^1; * index of high word *
+ ix0 = *(n0+(int*)&x); * high word of x *
+ ix1 = *((1-n0)+(int*)&x); * low word of x *
+ to dig two 32 bit words out of the 64 bit IEEE floating point
+ value. That is non-ANSI, and, moreover, the gcc instruction
+ scheduler gets it wrong. We instead use the following macros.
+ Unlike the original code, we determine the endianness at compile
+ time, not at run time; I don't see much benefit to selecting
+ endianness at run time. */
+
+/* A union which permits us to convert between a double and two 32 bit
+ ints. */
+
+/*
+ * Math on arm is special:
+ * For FPA, float words are always big-endian.
+ * For VFP, floats words follow the memory system mode.
+ */
+
+#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+
+typedef union
+{
+ double value;
+ struct
+ {
+ u_int32_t msw;
+ u_int32_t lsw;
+ } parts;
+} ieee_double_shape_type;
+
+#else
+
+typedef union
+{
+ double value;
+ struct
+ {
+ u_int32_t lsw;
+ u_int32_t msw;
+ } parts;
+} ieee_double_shape_type;
+
+#endif
+
+/* Get two 32 bit ints from a double. */
+
+#define EXTRACT_WORDS(ix0,ix1,d) \
+do { \
+ ieee_double_shape_type ew_u; \
+ ew_u.value = (d); \
+ (ix0) = ew_u.parts.msw; \
+ (ix1) = ew_u.parts.lsw; \
+} while (0)
+
+/* Get the more significant 32 bit int from a double. */
+
+#define GET_HIGH_WORD(i,d) \
+do { \
+ ieee_double_shape_type gh_u; \
+ gh_u.value = (d); \
+ (i) = gh_u.parts.msw; \
+} while (0)
+
+/* Get the less significant 32 bit int from a double. */
+
+#define GET_LOW_WORD(i,d) \
+do { \
+ ieee_double_shape_type gl_u; \
+ gl_u.value = (d); \
+ (i) = gl_u.parts.lsw; \
+} while (0)
+
+/* Set a double from two 32 bit ints. */
+
+#define INSERT_WORDS(d,ix0,ix1) \
+do { \
+ ieee_double_shape_type iw_u; \
+ iw_u.parts.msw = (ix0); \
+ iw_u.parts.lsw = (ix1); \
+ (d) = iw_u.value; \
+} while (0)
+
+/* Set the more significant 32 bits of a double from an int. */
+
+#define SET_HIGH_WORD(d,v) \
+do { \
+ ieee_double_shape_type sh_u; \
+ sh_u.value = (d); \
+ sh_u.parts.msw = (v); \
+ (d) = sh_u.value; \
+} while (0)
+
+/* Set the less significant 32 bits of a double from an int. */
+
+#define SET_LOW_WORD(d,v) \
+do { \
+ ieee_double_shape_type sl_u; \
+ sl_u.value = (d); \
+ sl_u.parts.lsw = (v); \
+ (d) = sl_u.value; \
+} while (0)
+
+/* A union which permits us to convert between a float and a 32 bit
+ int. */
+
+typedef union
+{
+ float value;
+ u_int32_t word;
+} ieee_float_shape_type;
+
+/* Get a 32 bit int from a float. */
+
+#define GET_FLOAT_WORD(i,d) \
+do { \
+ ieee_float_shape_type gf_u; \
+ gf_u.value = (d); \
+ (i) = gf_u.word; \
+} while (0)
+
+/* Set a float from a 32 bit int. */
+
+#define SET_FLOAT_WORD(d,i) \
+do { \
+ ieee_float_shape_type sf_u; \
+ sf_u.word = (i); \
+ (d) = sf_u.value; \
+} while (0)
+
+/* ieee style elementary functions */
+extern double
+__ieee754_sqrt(double)
+ attribute_hidden;
+ extern double __ieee754_acos(double) attribute_hidden;
+ extern double __ieee754_acosh(double) attribute_hidden;
+ extern double __ieee754_log(double) attribute_hidden;
+ extern double __ieee754_atanh(double) attribute_hidden;
+ extern double __ieee754_asin(double) attribute_hidden;
+ extern double __ieee754_atan2(double, double) attribute_hidden;
+ extern double __ieee754_exp(double) attribute_hidden;
+ extern double __ieee754_cosh(double) attribute_hidden;
+ extern double __ieee754_fmod(double, double) attribute_hidden;
+ extern double __ieee754_pow(double, double) attribute_hidden;
+ extern double __ieee754_lgamma_r(double, int *) attribute_hidden;
+ extern double __ieee754_gamma_r(double, int *) attribute_hidden;
+ extern double __ieee754_lgamma(double) attribute_hidden;
+ extern double __ieee754_gamma(double) attribute_hidden;
+ extern double __ieee754_log10(double) attribute_hidden;
+ extern double __ieee754_sinh(double) attribute_hidden;
+ extern double __ieee754_hypot(double, double) attribute_hidden;
+ extern double __ieee754_j0(double) attribute_hidden;
+ extern double __ieee754_j1(double) attribute_hidden;
+ extern double __ieee754_y0(double) attribute_hidden;
+ extern double __ieee754_y1(double) attribute_hidden;
+ extern double __ieee754_jn(int, double) attribute_hidden;
+ extern double __ieee754_yn(int, double) attribute_hidden;
+ extern double __ieee754_remainder(double, double) attribute_hidden;
+ extern int __ieee754_rem_pio2(double, double *) attribute_hidden;
+#if defined(_SCALB_INT)
+ extern double __ieee754_scalb(double, int) attribute_hidden;
+#else
+ extern double __ieee754_scalb(double, double) attribute_hidden;
+#endif
+
+/* fdlibm kernel function */
+#ifndef _IEEE_LIBM
+ extern double __kernel_standard(double, double, int) attribute_hidden;
+#endif
+ extern double __kernel_sin(double, double, int) attribute_hidden;
+ extern double __kernel_cos(double, double) attribute_hidden;
+ extern double __kernel_tan(double, double, int) attribute_hidden;
+ extern int __kernel_rem_pio2(double *, double *, int, int, int,
+ const int *) attribute_hidden;
+
+#endif /* _MATH_PRIVATE_H_ */
diff --git a/src/3rdparty/SDL2/src/libm/s_atan.c b/src/3rdparty/SDL2/src/libm/s_atan.c
new file mode 100644
index 0000000..f664f0e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/s_atan.c
@@ -0,0 +1,114 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/* atan(x)
+ * Method
+ * 1. Reduce x to positive by atan(x) = -atan(-x).
+ * 2. According to the integer k=4t+0.25 chopped, t=x, the argument
+ * is further reduced to one of the following intervals and the
+ * arctangent of t is evaluated by the corresponding formula:
+ *
+ * [0,7/16] atan(x) = t-t^3*(a1+t^2*(a2+...(a10+t^2*a11)...)
+ * [7/16,11/16] atan(x) = atan(1/2) + atan( (t-0.5)/(1+t/2) )
+ * [11/16.19/16] atan(x) = atan( 1 ) + atan( (t-1)/(1+t) )
+ * [19/16,39/16] atan(x) = atan(3/2) + atan( (t-1.5)/(1+1.5t) )
+ * [39/16,INF] atan(x) = atan(INF) + atan( -1/t )
+ *
+ * Constants:
+ * The hexadecimal values are the intended ones for the following
+ * constants. The decimal values may be used, provided that the
+ * compiler will convert from decimal to binary accurately enough
+ * to produce the hexadecimal values shown.
+ */
+
+#include "math_libm.h"
+#include "math_private.h"
+
+static const double atanhi[] = {
+ 4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */
+ 7.85398163397448278999e-01, /* atan(1.0)hi 0x3FE921FB, 0x54442D18 */
+ 9.82793723247329054082e-01, /* atan(1.5)hi 0x3FEF730B, 0xD281F69B */
+ 1.57079632679489655800e+00, /* atan(inf)hi 0x3FF921FB, 0x54442D18 */
+};
+
+static const double atanlo[] = {
+ 2.26987774529616870924e-17, /* atan(0.5)lo 0x3C7A2B7F, 0x222F65E2 */
+ 3.06161699786838301793e-17, /* atan(1.0)lo 0x3C81A626, 0x33145C07 */
+ 1.39033110312309984516e-17, /* atan(1.5)lo 0x3C700788, 0x7AF0CBBD */
+ 6.12323399573676603587e-17, /* atan(inf)lo 0x3C91A626, 0x33145C07 */
+};
+
+static const double aT[] = {
+ 3.33333333333329318027e-01, /* 0x3FD55555, 0x5555550D */
+ -1.99999999998764832476e-01, /* 0xBFC99999, 0x9998EBC4 */
+ 1.42857142725034663711e-01, /* 0x3FC24924, 0x920083FF */
+ -1.11111104054623557880e-01, /* 0xBFBC71C6, 0xFE231671 */
+ 9.09088713343650656196e-02, /* 0x3FB745CD, 0xC54C206E */
+ -7.69187620504482999495e-02, /* 0xBFB3B0F2, 0xAF749A6D */
+ 6.66107313738753120669e-02, /* 0x3FB10D66, 0xA0D03D51 */
+ -5.83357013379057348645e-02, /* 0xBFADDE2D, 0x52DEFD9A */
+ 4.97687799461593236017e-02, /* 0x3FA97B4B, 0x24760DEB */
+ -3.65315727442169155270e-02, /* 0xBFA2B444, 0x2C6A6C2F */
+ 1.62858201153657823623e-02, /* 0x3F90AD3A, 0xE322DA11 */
+};
+
+static const double
+one = 1.0,
+huge = 1.0e300;
+
+double atan(double x)
+{
+ double w,s1,s2,z;
+ int32_t ix,hx,id;
+
+ GET_HIGH_WORD(hx,x);
+ ix = hx&0x7fffffff;
+ if(ix>=0x44100000) { /* if |x| >= 2^66 */
+ u_int32_t low;
+ GET_LOW_WORD(low,x);
+ if(ix>0x7ff00000||
+ (ix==0x7ff00000&&(low!=0)))
+ return x+x; /* NaN */
+ if(hx>0) return atanhi[3]+atanlo[3];
+ else return -atanhi[3]-atanlo[3];
+ } if (ix < 0x3fdc0000) { /* |x| < 0.4375 */
+ if (ix < 0x3e200000) { /* |x| < 2^-29 */
+ if(huge+x>one) return x; /* raise inexact */
+ }
+ id = -1;
+ } else {
+ x = fabs(x);
+ if (ix < 0x3ff30000) { /* |x| < 1.1875 */
+ if (ix < 0x3fe60000) { /* 7/16 <=|x|<11/16 */
+ id = 0; x = (2.0*x-one)/(2.0+x);
+ } else { /* 11/16<=|x|< 19/16 */
+ id = 1; x = (x-one)/(x+one);
+ }
+ } else {
+ if (ix < 0x40038000) { /* |x| < 2.4375 */
+ id = 2; x = (x-1.5)/(one+1.5*x);
+ } else { /* 2.4375 <= |x| < 2^66 */
+ id = 3; x = -1.0/x;
+ }
+ }}
+ /* end of argument reduction */
+ z = x*x;
+ w = z*z;
+ /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */
+ s1 = z*(aT[0]+w*(aT[2]+w*(aT[4]+w*(aT[6]+w*(aT[8]+w*aT[10])))));
+ s2 = w*(aT[1]+w*(aT[3]+w*(aT[5]+w*(aT[7]+w*aT[9]))));
+ if (id<0) return x - x*(s1+s2);
+ else {
+ z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x);
+ return (hx<0)? -z:z;
+ }
+}
+libm_hidden_def(atan)
diff --git a/src/3rdparty/SDL2/src/libm/s_copysign.c b/src/3rdparty/SDL2/src/libm/s_copysign.c
new file mode 100644
index 0000000..a2f275b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/s_copysign.c
@@ -0,0 +1,29 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/*
+ * copysign(double x, double y)
+ * copysign(x,y) returns a value with the magnitude of x and
+ * with the sign bit of y.
+ */
+
+#include "math_libm.h"
+#include "math_private.h"
+
+double copysign(double x, double y)
+{
+ u_int32_t hx,hy;
+ GET_HIGH_WORD(hx,x);
+ GET_HIGH_WORD(hy,y);
+ SET_HIGH_WORD(x,(hx&0x7fffffff)|(hy&0x80000000));
+ return x;
+}
+libm_hidden_def(copysign)
diff --git a/src/3rdparty/SDL2/src/libm/s_cos.c b/src/3rdparty/SDL2/src/libm/s_cos.c
new file mode 100644
index 0000000..5540260
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/s_cos.c
@@ -0,0 +1,73 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/* cos(x)
+ * Return cosine function of x.
+ *
+ * kernel function:
+ * __kernel_sin ... sine function on [-pi/4,pi/4]
+ * __kernel_cos ... cosine function on [-pi/4,pi/4]
+ * __ieee754_rem_pio2 ... argument reduction routine
+ *
+ * Method.
+ * Let S,C and T denote the sin, cos and tan respectively on
+ * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
+ * in [-pi/4 , +pi/4], and let n = k mod 4.
+ * We have
+ *
+ * n sin(x) cos(x) tan(x)
+ * ----------------------------------------------------------
+ * 0 S C T
+ * 1 C -S -1/T
+ * 2 -S -C T
+ * 3 -C S -1/T
+ * ----------------------------------------------------------
+ *
+ * Special cases:
+ * Let trig be any of sin, cos, or tan.
+ * trig(+-INF) is NaN, with signals;
+ * trig(NaN) is that NaN;
+ *
+ * Accuracy:
+ * TRIG(x) returns trig(x) nearly rounded
+ */
+
+#include "math_libm.h"
+#include "math_private.h"
+
+double cos(double x)
+{
+ double y[2],z=0.0;
+ int32_t n, ix;
+
+ /* High word of x. */
+ GET_HIGH_WORD(ix,x);
+
+ /* |x| ~< pi/4 */
+ ix &= 0x7fffffff;
+ if(ix <= 0x3fe921fb) return __kernel_cos(x,z);
+
+ /* cos(Inf or NaN) is NaN */
+ else if (ix>=0x7ff00000) return x-x;
+
+ /* argument reduction needed */
+ else {
+ n = __ieee754_rem_pio2(x,y);
+ switch(n&3) {
+ case 0: return __kernel_cos(y[0],y[1]);
+ case 1: return -__kernel_sin(y[0],y[1],1);
+ case 2: return -__kernel_cos(y[0],y[1]);
+ default:
+ return __kernel_sin(y[0],y[1],1);
+ }
+ }
+}
+libm_hidden_def(cos)
diff --git a/src/3rdparty/SDL2/src/libm/s_fabs.c b/src/3rdparty/SDL2/src/libm/s_fabs.c
new file mode 100644
index 0000000..9ee943c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/s_fabs.c
@@ -0,0 +1,29 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/*
+ * fabs(x) returns the absolute value of x.
+ */
+
+/*#include <features.h>*/
+/* Prevent math.h from defining a colliding inline */
+#undef __USE_EXTERN_INLINES
+#include "math_libm.h"
+#include "math_private.h"
+
+double fabs(double x)
+{
+ u_int32_t high;
+ GET_HIGH_WORD(high,x);
+ SET_HIGH_WORD(x,high&0x7fffffff);
+ return x;
+}
+libm_hidden_def(fabs)
diff --git a/src/3rdparty/SDL2/src/libm/s_floor.c b/src/3rdparty/SDL2/src/libm/s_floor.c
new file mode 100644
index 0000000..3f9a5ce
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/s_floor.c
@@ -0,0 +1,71 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/*
+ * floor(x)
+ * Return x rounded toward -inf to integral value
+ * Method:
+ * Bit twiddling.
+ * Exception:
+ * Inexact flag raised if x not equal to floor(x).
+ */
+
+/*#include <features.h>*/
+/* Prevent math.h from defining a colliding inline */
+#undef __USE_EXTERN_INLINES
+#include "math_libm.h"
+#include "math_private.h"
+
+static const double huge = 1.0e300;
+
+double floor(double x)
+{
+ int32_t i0,i1,j0;
+ u_int32_t i,j;
+ EXTRACT_WORDS(i0,i1,x);
+ j0 = ((i0>>20)&0x7ff)-0x3ff;
+ if(j0<20) {
+ if(j0<0) { /* raise inexact if x != 0 */
+ if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
+ if(i0>=0) {i0=i1=0;}
+ else if(((i0&0x7fffffff)|i1)!=0)
+ { i0=0xbff00000;i1=0;}
+ }
+ } else {
+ i = (0x000fffff)>>j0;
+ if(((i0&i)|i1)==0) return x; /* x is integral */
+ if(huge+x>0.0) { /* raise inexact flag */
+ if(i0<0) i0 += (0x00100000)>>j0;
+ i0 &= (~i); i1=0;
+ }
+ }
+ } else if (j0>51) {
+ if(j0==0x400) return x+x; /* inf or NaN */
+ else return x; /* x is integral */
+ } else {
+ i = ((u_int32_t)(0xffffffff))>>(j0-20);
+ if((i1&i)==0) return x; /* x is integral */
+ if(huge+x>0.0) { /* raise inexact flag */
+ if(i0<0) {
+ if(j0==20) i0+=1;
+ else {
+ j = i1+(1<<(52-j0));
+ if(j<(u_int32_t)i1) i0 +=1 ; /* got a carry */
+ i1=j;
+ }
+ }
+ i1 &= (~i);
+ }
+ }
+ INSERT_WORDS(x,i0,i1);
+ return x;
+}
+libm_hidden_def(floor)
diff --git a/src/3rdparty/SDL2/src/libm/s_scalbn.c b/src/3rdparty/SDL2/src/libm/s_scalbn.c
new file mode 100644
index 0000000..6bb7192
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/s_scalbn.c
@@ -0,0 +1,69 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/*
+ * scalbln(double x, long n)
+ * scalbln(x,n) returns x * 2**n computed by exponent
+ * manipulation rather than by actually performing an
+ * exponentiation or a multiplication.
+ */
+
+#include "math_libm.h"
+#include "math_private.h"
+#include <limits.h>
+
+static const double
+two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
+twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
+huge = 1.0e+300,
+tiny = 1.0e-300;
+
+double scalbln(double x, long n)
+{
+ int32_t k, hx, lx;
+
+ EXTRACT_WORDS(hx, lx, x);
+ k = (hx & 0x7ff00000) >> 20; /* extract exponent */
+ if (k == 0) { /* 0 or subnormal x */
+ if ((lx | (hx & 0x7fffffff)) == 0)
+ return x; /* +-0 */
+ x *= two54;
+ GET_HIGH_WORD(hx, x);
+ k = ((hx & 0x7ff00000) >> 20) - 54;
+ }
+ if (k == 0x7ff)
+ return x + x; /* NaN or Inf */
+ k = k + n;
+ if (k > 0x7fe)
+ return huge * copysign(huge, x); /* overflow */
+ if (n < -50000)
+ return tiny * copysign(tiny, x); /* underflow */
+ if (k > 0) { /* normal result */
+ SET_HIGH_WORD(x, (hx & 0x800fffff) | (k << 20));
+ return x;
+ }
+ if (k <= -54) {
+ if (n > 50000) /* in case integer overflow in n+k */
+ return huge * copysign(huge, x); /* overflow */
+ return tiny * copysign(tiny, x); /* underflow */
+ }
+ k += 54; /* subnormal result */
+ SET_HIGH_WORD(x, (hx & 0x800fffff) | (k << 20));
+ return x * twom54;
+}
+libm_hidden_def(scalbln)
+
+
+double scalbn(double x, int n)
+{
+ return scalbln(x, n);
+}
+libm_hidden_def(scalbn)
diff --git a/src/3rdparty/SDL2/src/libm/s_sin.c b/src/3rdparty/SDL2/src/libm/s_sin.c
new file mode 100644
index 0000000..b3cd7a0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/s_sin.c
@@ -0,0 +1,73 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/* sin(x)
+ * Return sine function of x.
+ *
+ * kernel function:
+ * __kernel_sin ... sine function on [-pi/4,pi/4]
+ * __kernel_cos ... cose function on [-pi/4,pi/4]
+ * __ieee754_rem_pio2 ... argument reduction routine
+ *
+ * Method.
+ * Let S,C and T denote the sin, cos and tan respectively on
+ * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
+ * in [-pi/4 , +pi/4], and let n = k mod 4.
+ * We have
+ *
+ * n sin(x) cos(x) tan(x)
+ * ----------------------------------------------------------
+ * 0 S C T
+ * 1 C -S -1/T
+ * 2 -S -C T
+ * 3 -C S -1/T
+ * ----------------------------------------------------------
+ *
+ * Special cases:
+ * Let trig be any of sin, cos, or tan.
+ * trig(+-INF) is NaN, with signals;
+ * trig(NaN) is that NaN;
+ *
+ * Accuracy:
+ * TRIG(x) returns trig(x) nearly rounded
+ */
+
+#include "math_libm.h"
+#include "math_private.h"
+
+double sin(double x)
+{
+ double y[2],z=0.0;
+ int32_t n, ix;
+
+ /* High word of x. */
+ GET_HIGH_WORD(ix,x);
+
+ /* |x| ~< pi/4 */
+ ix &= 0x7fffffff;
+ if(ix <= 0x3fe921fb) return __kernel_sin(x,z,0);
+
+ /* sin(Inf or NaN) is NaN */
+ else if (ix>=0x7ff00000) return x-x;
+
+ /* argument reduction needed */
+ else {
+ n = __ieee754_rem_pio2(x,y);
+ switch(n&3) {
+ case 0: return __kernel_sin(y[0],y[1],1);
+ case 1: return __kernel_cos(y[0],y[1]);
+ case 2: return -__kernel_sin(y[0],y[1],1);
+ default:
+ return -__kernel_cos(y[0],y[1]);
+ }
+ }
+}
+libm_hidden_def(sin)
diff --git a/src/3rdparty/SDL2/src/libm/s_tan.c b/src/3rdparty/SDL2/src/libm/s_tan.c
new file mode 100644
index 0000000..18c8f5b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/libm/s_tan.c
@@ -0,0 +1,67 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/* tan(x)
+ * Return tangent function of x.
+ *
+ * kernel function:
+ * __kernel_tan ... tangent function on [-pi/4,pi/4]
+ * __ieee754_rem_pio2 ... argument reduction routine
+ *
+ * Method.
+ * Let S,C and T denote the sin, cos and tan respectively on
+ * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
+ * in [-pi/4 , +pi/4], and let n = k mod 4.
+ * We have
+ *
+ * n sin(x) cos(x) tan(x)
+ * ----------------------------------------------------------
+ * 0 S C T
+ * 1 C -S -1/T
+ * 2 -S -C T
+ * 3 -C S -1/T
+ * ----------------------------------------------------------
+ *
+ * Special cases:
+ * Let trig be any of sin, cos, or tan.
+ * trig(+-INF) is NaN, with signals;
+ * trig(NaN) is that NaN;
+ *
+ * Accuracy:
+ * TRIG(x) returns trig(x) nearly rounded
+ */
+
+#include "math_libm.h"
+#include "math_private.h"
+
+double tan(double x)
+{
+ double y[2],z=0.0;
+ int32_t n, ix;
+
+ /* High word of x. */
+ GET_HIGH_WORD(ix,x);
+
+ /* |x| ~< pi/4 */
+ ix &= 0x7fffffff;
+ if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1);
+
+ /* tan(Inf or NaN) is NaN */
+ else if (ix>=0x7ff00000) return x-x; /* NaN */
+
+ /* argument reduction needed */
+ else {
+ n = __ieee754_rem_pio2(x,y);
+ return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even
+ -1 -- n odd */
+ }
+}
+libm_hidden_def(tan)
diff --git a/src/3rdparty/SDL2/src/loadso/dlopen/SDL_sysloadso.c b/src/3rdparty/SDL2/src/loadso/dlopen/SDL_sysloadso.c
new file mode 100644
index 0000000..18b4b84
--- /dev/null
+++ b/src/3rdparty/SDL2/src/loadso/dlopen/SDL_sysloadso.c
@@ -0,0 +1,88 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_LOADSO_DLOPEN
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* System dependent library loading routines */
+
+#include <stdio.h>
+#include <dlfcn.h>
+
+#include "SDL_loadso.h"
+
+#if SDL_VIDEO_DRIVER_UIKIT
+#include "../../video/uikit/SDL_uikitvideo.h"
+#endif
+
+void *
+SDL_LoadObject(const char *sofile)
+{
+ void *handle;
+ const char *loaderror;
+
+#if SDL_VIDEO_DRIVER_UIKIT
+ if (!UIKit_IsSystemVersionAtLeast(8.0)) {
+ SDL_SetError("SDL_LoadObject requires iOS 8+");
+ return NULL;
+ }
+#endif
+
+ handle = dlopen(sofile, RTLD_NOW|RTLD_LOCAL);
+ loaderror = (char *) dlerror();
+ if (handle == NULL) {
+ SDL_SetError("Failed loading %s: %s", sofile, loaderror);
+ }
+ return (handle);
+}
+
+void *
+SDL_LoadFunction(void *handle, const char *name)
+{
+ void *symbol = dlsym(handle, name);
+ if (symbol == NULL) {
+ /* append an underscore for platforms that need that. */
+ size_t len = 1 + SDL_strlen(name) + 1;
+ char *_name = SDL_stack_alloc(char, len);
+ _name[0] = '_';
+ SDL_strlcpy(&_name[1], name, len);
+ symbol = dlsym(handle, _name);
+ SDL_stack_free(_name);
+ if (symbol == NULL) {
+ SDL_SetError("Failed loading %s: %s", name,
+ (const char *) dlerror());
+ }
+ }
+ return (symbol);
+}
+
+void
+SDL_UnloadObject(void *handle)
+{
+ if (handle != NULL) {
+ dlclose(handle);
+ }
+}
+
+#endif /* SDL_LOADSO_DLOPEN */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/loadso/dummy/SDL_sysloadso.c b/src/3rdparty/SDL2/src/loadso/dummy/SDL_sysloadso.c
new file mode 100644
index 0000000..291c08b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/loadso/dummy/SDL_sysloadso.c
@@ -0,0 +1,54 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if defined(SDL_LOADSO_DUMMY) || defined(SDL_LOADSO_DISABLED)
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* System dependent library loading routines */
+
+#include "SDL_loadso.h"
+
+void *
+SDL_LoadObject(const char *sofile)
+{
+ const char *loaderror = "SDL_LoadObject() not implemented";
+ SDL_SetError("Failed loading %s: %s", sofile, loaderror);
+ return (NULL);
+}
+
+void *
+SDL_LoadFunction(void *handle, const char *name)
+{
+ const char *loaderror = "SDL_LoadFunction() not implemented";
+ SDL_SetError("Failed loading %s: %s", name, loaderror);
+ return (NULL);
+}
+
+void
+SDL_UnloadObject(void *handle)
+{
+ /* no-op. */
+}
+
+#endif /* SDL_LOADSO_DUMMY || SDL_LOADSO_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/loadso/windows/SDL_sysloadso.c b/src/3rdparty/SDL2/src/loadso/windows/SDL_sysloadso.c
new file mode 100644
index 0000000..351570f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/loadso/windows/SDL_sysloadso.c
@@ -0,0 +1,80 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_LOADSO_WINDOWS
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* System dependent library loading routines */
+
+#include "../../core/windows/SDL_windows.h"
+
+#include "SDL_loadso.h"
+
+void *
+SDL_LoadObject(const char *sofile)
+{
+ LPTSTR tstr = WIN_UTF8ToString(sofile);
+#ifdef __WINRT__
+ /* WinRT only publically supports LoadPackagedLibrary() for loading .dll
+ files. LoadLibrary() is a private API, and not available for apps
+ (that can be published to MS' Windows Store.)
+ */
+ void *handle = (void *) LoadPackagedLibrary(tstr, 0);
+#else
+ void *handle = (void *) LoadLibrary(tstr);
+#endif
+ SDL_free(tstr);
+
+ /* Generate an error message if all loads failed */
+ if (handle == NULL) {
+ char errbuf[512];
+ SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
+ SDL_strlcat(errbuf, sofile, SDL_arraysize(errbuf));
+ WIN_SetError(errbuf);
+ }
+ return handle;
+}
+
+void *
+SDL_LoadFunction(void *handle, const char *name)
+{
+ void *symbol = (void *) GetProcAddress((HMODULE) handle, name);
+ if (symbol == NULL) {
+ char errbuf[512];
+ SDL_strlcpy(errbuf, "Failed loading ", SDL_arraysize(errbuf));
+ SDL_strlcat(errbuf, name, SDL_arraysize(errbuf));
+ WIN_SetError(errbuf);
+ }
+ return symbol;
+}
+
+void
+SDL_UnloadObject(void *handle)
+{
+ if (handle != NULL) {
+ FreeLibrary((HMODULE) handle);
+ }
+}
+
+#endif /* SDL_LOADSO_WINDOWS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/main/android/SDL_android_main.c b/src/3rdparty/SDL2/src/main/android/SDL_android_main.c
new file mode 100644
index 0000000..054738a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/main/android/SDL_android_main.c
@@ -0,0 +1,7 @@
+/*
+ SDL_android_main.c, placed in the public domain by Sam Lantinga 3/13/14
+
+ As of SDL 2.0.6 this file is no longer necessary.
+*/
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/main/dummy/SDL_dummy_main.c b/src/3rdparty/SDL2/src/main/dummy/SDL_dummy_main.c
new file mode 100644
index 0000000..0174136
--- /dev/null
+++ b/src/3rdparty/SDL2/src/main/dummy/SDL_dummy_main.c
@@ -0,0 +1,28 @@
+/*
+ SDL_dummy_main.c, placed in the public domain by Sam Lantinga 3/13/14
+*/
+#include "../../SDL_internal.h"
+
+/* Include the SDL main definition header */
+#include "SDL_main.h"
+
+#ifdef main
+#undef main
+int
+main(int argc, char *argv[])
+{
+ return (SDL_main(argc, argv));
+}
+#else
+/* Nothing to do on this platform */
+int
+SDL_main_stub_symbol(void);
+
+int
+SDL_main_stub_symbol(void)
+{
+ return 0;
+}
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/main/haiku/SDL_BApp.h b/src/3rdparty/SDL2/src/main/haiku/SDL_BApp.h
new file mode 100644
index 0000000..ba3f927
--- /dev/null
+++ b/src/3rdparty/SDL2/src/main/haiku/SDL_BApp.h
@@ -0,0 +1,399 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#ifndef SDL_BAPP_H
+#define SDL_BAPP_H
+
+#include <InterfaceKit.h>
+#if SDL_VIDEO_OPENGL
+#include <OpenGLKit.h>
+#endif
+
+#include "../../video/haiku/SDL_bkeyboard.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "../../SDL_internal.h"
+
+#include "SDL_video.h"
+
+/* Local includes */
+#include "../../events/SDL_events_c.h"
+#include "../../video/haiku/SDL_bframebuffer.h"
+
+#ifdef __cplusplus
+}
+#endif
+
+#include <vector>
+
+
+
+
+/* Forward declarations */
+class SDL_BWin;
+
+/* Message constants */
+enum ToSDL {
+ /* Intercepted by BWindow on its way to BView */
+ BAPP_MOUSE_MOVED,
+ BAPP_MOUSE_BUTTON,
+ BAPP_MOUSE_WHEEL,
+ BAPP_KEY,
+ BAPP_REPAINT, /* from _UPDATE_ */
+ /* From BWindow */
+ BAPP_MAXIMIZE, /* from B_ZOOM */
+ BAPP_MINIMIZE,
+ BAPP_RESTORE, /* TODO: IMPLEMENT! */
+ BAPP_SHOW,
+ BAPP_HIDE,
+ BAPP_MOUSE_FOCUS, /* caused by MOUSE_MOVE */
+ BAPP_KEYBOARD_FOCUS, /* from WINDOW_ACTIVATED */
+ BAPP_WINDOW_CLOSE_REQUESTED,
+ BAPP_WINDOW_MOVED,
+ BAPP_WINDOW_RESIZED,
+ BAPP_SCREEN_CHANGED
+};
+
+
+
+/* Create a descendant of BApplication */
+class SDL_BApp : public BApplication {
+public:
+ SDL_BApp(const char* signature) :
+ BApplication(signature) {
+#if SDL_VIDEO_OPENGL
+ _current_context = NULL;
+#endif
+ }
+
+
+ virtual ~SDL_BApp() {
+ }
+
+
+
+ /* Event-handling functions */
+ virtual void MessageReceived(BMessage* message) {
+ /* Sort out SDL-related messages */
+ switch ( message->what ) {
+ case BAPP_MOUSE_MOVED:
+ _HandleMouseMove(message);
+ break;
+
+ case BAPP_MOUSE_BUTTON:
+ _HandleMouseButton(message);
+ break;
+
+ case BAPP_MOUSE_WHEEL:
+ _HandleMouseWheel(message);
+ break;
+
+ case BAPP_KEY:
+ _HandleKey(message);
+ break;
+
+ case BAPP_REPAINT:
+ _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_EXPOSED);
+ break;
+
+ case BAPP_MAXIMIZE:
+ _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_MAXIMIZED);
+ break;
+
+ case BAPP_MINIMIZE:
+ _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_MINIMIZED);
+ break;
+
+ case BAPP_SHOW:
+ _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_SHOWN);
+ break;
+
+ case BAPP_HIDE:
+ _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_HIDDEN);
+ break;
+
+ case BAPP_MOUSE_FOCUS:
+ _HandleMouseFocus(message);
+ break;
+
+ case BAPP_KEYBOARD_FOCUS:
+ _HandleKeyboardFocus(message);
+ break;
+
+ case BAPP_WINDOW_CLOSE_REQUESTED:
+ _HandleBasicWindowEvent(message, SDL_WINDOWEVENT_CLOSE);
+ break;
+
+ case BAPP_WINDOW_MOVED:
+ _HandleWindowMoved(message);
+ break;
+
+ case BAPP_WINDOW_RESIZED:
+ _HandleWindowResized(message);
+ break;
+
+ case BAPP_SCREEN_CHANGED:
+ /* TODO: Handle screen resize or workspace change */
+ break;
+
+ default:
+ BApplication::MessageReceived(message);
+ break;
+ }
+ }
+
+ /* Window creation/destruction methods */
+ int32 GetID(SDL_Window *win) {
+ int32 i;
+ for(i = 0; i < _GetNumWindowSlots(); ++i) {
+ if( GetSDLWindow(i) == NULL ) {
+ _SetSDLWindow(win, i);
+ return i;
+ }
+ }
+
+ /* Expand the vector if all slots are full */
+ if( i == _GetNumWindowSlots() ) {
+ _PushBackWindow(win);
+ return i;
+ }
+
+ /* TODO: error handling */
+ return 0;
+ }
+
+ /* FIXME: Bad coding practice, but I can't include SDL_BWin.h here. Is
+ there another way to do this? */
+ void ClearID(SDL_BWin *bwin); /* Defined in SDL_BeApp.cc */
+
+
+ SDL_Window *GetSDLWindow(int32 winID) {
+ return _window_map[winID];
+ }
+
+#if SDL_VIDEO_OPENGL
+ void SetCurrentContext(BGLView *newContext) {
+ if(_current_context)
+ _current_context->UnlockGL();
+ _current_context = newContext;
+ if (_current_context)
+ _current_context->LockGL();
+ }
+#endif
+
+private:
+ /* Event management */
+ void _HandleBasicWindowEvent(BMessage *msg, int32 sdlEventType) {
+ SDL_Window *win;
+ int32 winID;
+ if(
+ !_GetWinID(msg, &winID)
+ ) {
+ return;
+ }
+ win = GetSDLWindow(winID);
+ SDL_SendWindowEvent(win, sdlEventType, 0, 0);
+ }
+
+ void _HandleMouseMove(BMessage *msg) {
+ SDL_Window *win;
+ int32 winID;
+ int32 x = 0, y = 0;
+ if(
+ !_GetWinID(msg, &winID) ||
+ msg->FindInt32("x", &x) != B_OK || /* x movement */
+ msg->FindInt32("y", &y) != B_OK /* y movement */
+ ) {
+ return;
+ }
+ win = GetSDLWindow(winID);
+ SDL_SendMouseMotion(win, 0, 0, x, y);
+
+ /* Tell the application that the mouse passed over, redraw needed */
+ BE_UpdateWindowFramebuffer(NULL,win,NULL,-1);
+ }
+
+ void _HandleMouseButton(BMessage *msg) {
+ SDL_Window *win;
+ int32 winID;
+ int32 button, state; /* left/middle/right, pressed/released */
+ if(
+ !_GetWinID(msg, &winID) ||
+ msg->FindInt32("button-id", &button) != B_OK ||
+ msg->FindInt32("button-state", &state) != B_OK
+ ) {
+ return;
+ }
+ win = GetSDLWindow(winID);
+ SDL_SendMouseButton(win, 0, state, button);
+ }
+
+ void _HandleMouseWheel(BMessage *msg) {
+ SDL_Window *win;
+ int32 winID;
+ int32 xTicks, yTicks;
+ if(
+ !_GetWinID(msg, &winID) ||
+ msg->FindInt32("xticks", &xTicks) != B_OK ||
+ msg->FindInt32("yticks", &yTicks) != B_OK
+ ) {
+ return;
+ }
+ win = GetSDLWindow(winID);
+ SDL_SendMouseWheel(win, 0, xTicks, yTicks, SDL_MOUSEWHEEL_NORMAL);
+ }
+
+ void _HandleKey(BMessage *msg) {
+ int32 scancode, state; /* scancode, pressed/released */
+ if(
+ msg->FindInt32("key-state", &state) != B_OK ||
+ msg->FindInt32("key-scancode", &scancode) != B_OK
+ ) {
+ return;
+ }
+
+ /* Make sure this isn't a repeated event (key pressed and held) */
+ if(state == SDL_PRESSED && BE_GetKeyState(scancode) == SDL_PRESSED) {
+ return;
+ }
+ BE_SetKeyState(scancode, state);
+ SDL_SendKeyboardKey(state, BE_GetScancodeFromBeKey(scancode));
+
+ if (state == SDL_PRESSED && SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
+ const int8 *keyUtf8;
+ ssize_t count;
+ if (msg->FindData("key-utf8", B_INT8_TYPE, (const void**)&keyUtf8, &count) == B_OK) {
+ char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
+ SDL_zero(text);
+ SDL_memcpy(text, keyUtf8, count);
+ SDL_SendKeyboardText(text);
+ }
+ }
+ }
+
+ void _HandleMouseFocus(BMessage *msg) {
+ SDL_Window *win;
+ int32 winID;
+ bool bSetFocus; /* If false, lose focus */
+ if(
+ !_GetWinID(msg, &winID) ||
+ msg->FindBool("focusGained", &bSetFocus) != B_OK
+ ) {
+ return;
+ }
+ win = GetSDLWindow(winID);
+ if(bSetFocus) {
+ SDL_SetMouseFocus(win);
+ } else if(SDL_GetMouseFocus() == win) {
+ /* Only lose all focus if this window was the current focus */
+ SDL_SetMouseFocus(NULL);
+ }
+ }
+
+ void _HandleKeyboardFocus(BMessage *msg) {
+ SDL_Window *win;
+ int32 winID;
+ bool bSetFocus; /* If false, lose focus */
+ if(
+ !_GetWinID(msg, &winID) ||
+ msg->FindBool("focusGained", &bSetFocus) != B_OK
+ ) {
+ return;
+ }
+ win = GetSDLWindow(winID);
+ if(bSetFocus) {
+ SDL_SetKeyboardFocus(win);
+ } else if(SDL_GetKeyboardFocus() == win) {
+ /* Only lose all focus if this window was the current focus */
+ SDL_SetKeyboardFocus(NULL);
+ }
+ }
+
+ void _HandleWindowMoved(BMessage *msg) {
+ SDL_Window *win;
+ int32 winID;
+ int32 xPos, yPos;
+ /* Get the window id and new x/y position of the window */
+ if(
+ !_GetWinID(msg, &winID) ||
+ msg->FindInt32("window-x", &xPos) != B_OK ||
+ msg->FindInt32("window-y", &yPos) != B_OK
+ ) {
+ return;
+ }
+ win = GetSDLWindow(winID);
+ SDL_SendWindowEvent(win, SDL_WINDOWEVENT_MOVED, xPos, yPos);
+ }
+
+ void _HandleWindowResized(BMessage *msg) {
+ SDL_Window *win;
+ int32 winID;
+ int32 w, h;
+ /* Get the window id ]and new x/y position of the window */
+ if(
+ !_GetWinID(msg, &winID) ||
+ msg->FindInt32("window-w", &w) != B_OK ||
+ msg->FindInt32("window-h", &h) != B_OK
+ ) {
+ return;
+ }
+ win = GetSDLWindow(winID);
+ SDL_SendWindowEvent(win, SDL_WINDOWEVENT_RESIZED, w, h);
+ }
+
+ bool _GetWinID(BMessage *msg, int32 *winID) {
+ return msg->FindInt32("window-id", winID) == B_OK;
+ }
+
+
+
+ /* Vector functions: Wraps vector stuff in case we need to change
+ implementation */
+ void _SetSDLWindow(SDL_Window *win, int32 winID) {
+ _window_map[winID] = win;
+ }
+
+ int32 _GetNumWindowSlots() {
+ return _window_map.size();
+ }
+
+
+ void _PopBackWindow() {
+ _window_map.pop_back();
+ }
+
+ void _PushBackWindow(SDL_Window *win) {
+ _window_map.push_back(win);
+ }
+
+
+ /* Members */
+ std::vector<SDL_Window*> _window_map; /* Keeps track of SDL_Windows by index-id */
+
+#if SDL_VIDEO_OPENGL
+ BGLView *_current_context;
+#endif
+};
+
+#endif
diff --git a/src/3rdparty/SDL2/src/main/haiku/SDL_BeApp.cc b/src/3rdparty/SDL2/src/main/haiku/SDL_BeApp.cc
new file mode 100644
index 0000000..f4ee179
--- /dev/null
+++ b/src/3rdparty/SDL2/src/main/haiku/SDL_BeApp.cc
@@ -0,0 +1,157 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if defined(__HAIKU__)
+
+/* Handle the BeApp specific portions of the application */
+
+#include <AppKit.h>
+#include <storage/AppFileInfo.h>
+#include <storage/Path.h>
+#include <storage/Entry.h>
+#include <storage/File.h>
+#include <unistd.h>
+
+#include "SDL_BApp.h" /* SDL_BApp class definition */
+#include "SDL_BeApp.h"
+#include "SDL_timer.h"
+#include "SDL_error.h"
+
+#include "../../video/haiku/SDL_BWin.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "../../thread/SDL_systhread.h"
+
+/* Flag to tell whether or not the Be application is active or not */
+static int SDL_BeAppActive = 0;
+static SDL_Thread *SDL_AppThread = NULL;
+
+static int
+StartBeApp(void *unused)
+{
+ BApplication *App;
+
+ // default application signature
+ const char *signature = "application/x-SDL-executable";
+ // dig resources for correct signature
+ image_info info;
+ int32 cookie = 0;
+ if (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) {
+ BFile f(info.name, O_RDONLY);
+ if (f.InitCheck() == B_OK) {
+ BAppFileInfo app_info(&f);
+ if (app_info.InitCheck() == B_OK) {
+ char sig[B_MIME_TYPE_LENGTH];
+ if (app_info.GetSignature(sig) == B_OK)
+ signature = strndup(sig, B_MIME_TYPE_LENGTH);
+ }
+ }
+ }
+
+ App = new SDL_BApp(signature);
+
+ App->Run();
+ delete App;
+ return (0);
+}
+
+/* Initialize the Be Application, if it's not already started */
+int
+SDL_InitBeApp(void)
+{
+ /* Create the BApplication that handles appserver interaction */
+ if (SDL_BeAppActive <= 0) {
+ SDL_AppThread = SDL_CreateThreadInternal(StartBeApp, "SDLApplication", 0, NULL);
+ if (SDL_AppThread == NULL) {
+ return SDL_SetError("Couldn't create BApplication thread");
+ }
+
+ /* Change working directory to that of executable */
+ app_info info;
+ if (B_OK == be_app->GetAppInfo(&info)) {
+ entry_ref ref = info.ref;
+ BEntry entry;
+ if (B_OK == entry.SetTo(&ref)) {
+ BPath path;
+ if (B_OK == path.SetTo(&entry)) {
+ if (B_OK == path.GetParent(&path)) {
+ chdir(path.Path());
+ }
+ }
+ }
+ }
+
+ do {
+ SDL_Delay(10);
+ } while ((be_app == NULL) || be_app->IsLaunching());
+
+ /* Mark the application active */
+ SDL_BeAppActive = 0;
+ }
+
+ /* Increment the application reference count */
+ ++SDL_BeAppActive;
+
+ /* The app is running, and we're ready to go */
+ return (0);
+}
+
+/* Quit the Be Application, if there's nothing left to do */
+void
+SDL_QuitBeApp(void)
+{
+ /* Decrement the application reference count */
+ --SDL_BeAppActive;
+
+ /* If the reference count reached zero, clean up the app */
+ if (SDL_BeAppActive == 0) {
+ if (SDL_AppThread != NULL) {
+ if (be_app != NULL) { /* Not tested */
+ be_app->PostMessage(B_QUIT_REQUESTED);
+ }
+ SDL_WaitThread(SDL_AppThread, NULL);
+ SDL_AppThread = NULL;
+ }
+ /* be_app should now be NULL since be_app has quit */
+ }
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+/* SDL_BApp functions */
+void SDL_BApp::ClearID(SDL_BWin *bwin) {
+ _SetSDLWindow(NULL, bwin->GetID());
+ int32 i = _GetNumWindowSlots() - 1;
+ while(i >= 0 && GetSDLWindow(i) == NULL) {
+ _PopBackWindow();
+ --i;
+ }
+}
+
+#endif /* __HAIKU__ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/main/haiku/SDL_BeApp.h b/src/3rdparty/SDL2/src/main/haiku/SDL_BeApp.h
new file mode 100644
index 0000000..83a2beb
--- /dev/null
+++ b/src/3rdparty/SDL2/src/main/haiku/SDL_BeApp.h
@@ -0,0 +1,38 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+/* Handle the BeApp specific portions of the application */
+
+/* Initialize the Be Application, if it's not already started */
+extern int SDL_InitBeApp(void);
+
+/* Quit the Be Application, if there's nothing left to do */
+extern void SDL_QuitBeApp(void);
+
+/* vi: set ts=4 sw=4 expandtab: */
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/src/3rdparty/SDL2/src/main/nacl/SDL_nacl_main.c b/src/3rdparty/SDL2/src/main/nacl/SDL_nacl_main.c
new file mode 100644
index 0000000..af66bdb
--- /dev/null
+++ b/src/3rdparty/SDL2/src/main/nacl/SDL_nacl_main.c
@@ -0,0 +1,93 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_NACL
+
+/* Include the SDL main definition header */
+#include "SDL_main.h"
+
+#include "ppapi_simple/ps_main.h"
+#include "ppapi_simple/ps_event.h"
+#include "ppapi_simple/ps_interface.h"
+#include "nacl_io/nacl_io.h"
+#include "sys/mount.h"
+
+extern void NACL_SetScreenResolution(int width, int height, Uint32 format);
+
+int
+nacl_main(int argc, char *argv[])
+{
+ int status;
+ PSEvent* ps_event;
+ PP_Resource event;
+ struct PP_Rect rect;
+ int ready = 0;
+ const PPB_View *ppb_view = PSInterfaceView();
+
+ /* This is started in a worker thread by ppapi_simple! */
+
+ /* Wait for the first PSE_INSTANCE_DIDCHANGEVIEW event before starting the app */
+
+ PSEventSetFilter(PSE_INSTANCE_DIDCHANGEVIEW);
+ while (!ready) {
+ /* Process all waiting events without blocking */
+ while (!ready && (ps_event = PSEventWaitAcquire()) != NULL) {
+ event = ps_event->as_resource;
+ switch(ps_event->type) {
+ /* From DidChangeView, contains a view resource */
+ case PSE_INSTANCE_DIDCHANGEVIEW:
+ ppb_view->GetRect(event, &rect);
+ NACL_SetScreenResolution(rect.size.width, rect.size.height, 0);
+ ready = 1;
+ break;
+ default:
+ break;
+ }
+ PSEventRelease(ps_event);
+ }
+ }
+
+ /* Do a default httpfs mount on /,
+ * apps can override this by unmounting /
+ * and remounting with the desired configuration
+ */
+ nacl_io_init_ppapi(PSGetInstanceId(), PSGetInterface);
+
+ umount("/");
+ mount(
+ "", /* source */
+ "/", /* target */
+ "httpfs", /* filesystemtype */
+ 0, /* mountflags */
+ ""); /* data specific to the html5fs type */
+
+ /* Everything is ready, start the user main function */
+ SDL_SetMainReady();
+ status = SDL_main(argc, argv);
+
+ return 0;
+}
+
+/* ppapi_simple will start nacl_main in a worker thread */
+PPAPI_SIMPLE_REGISTER_MAIN(nacl_main);
+
+#endif /* SDL_VIDEO_DRIVER_NACL */
diff --git a/src/3rdparty/SDL2/src/main/psp/SDL_psp_main.c b/src/3rdparty/SDL2/src/main/psp/SDL_psp_main.c
new file mode 100644
index 0000000..2ca8e44
--- /dev/null
+++ b/src/3rdparty/SDL2/src/main/psp/SDL_psp_main.c
@@ -0,0 +1,70 @@
+/*
+ SDL_psp_main.c, placed in the public domain by Sam Lantinga 3/13/14
+*/
+#include "SDL_config.h"
+
+#ifdef __PSP__
+
+#include "SDL_main.h"
+#include <pspkernel.h>
+#include <pspdebug.h>
+#include <pspsdk.h>
+#include <pspthreadman.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+/* If application's main() is redefined as SDL_main, and libSDLmain is
+ linked, then this file will create the standard exit callback,
+ define the PSP_MODULE_INFO macro, and exit back to the browser when
+ the program is finished.
+
+ You can still override other parameters in your own code if you
+ desire, such as PSP_HEAP_SIZE_KB, PSP_MAIN_THREAD_ATTR,
+ PSP_MAIN_THREAD_STACK_SIZE, etc.
+*/
+
+PSP_MODULE_INFO("SDL App", 0, 1, 1);
+
+int sdl_psp_exit_callback(int arg1, int arg2, void *common)
+{
+ exit(0);
+ return 0;
+}
+
+int sdl_psp_callback_thread(SceSize args, void *argp)
+{
+ int cbid;
+ cbid = sceKernelCreateCallback("Exit Callback",
+ sdl_psp_exit_callback, NULL);
+ sceKernelRegisterExitCallback(cbid);
+ sceKernelSleepThreadCB();
+ return 0;
+}
+
+int sdl_psp_setup_callbacks(void)
+{
+ int thid = 0;
+ thid = sceKernelCreateThread("update_thread",
+ sdl_psp_callback_thread, 0x11, 0xFA0, 0, 0);
+ if(thid >= 0)
+ sceKernelStartThread(thid, 0, 0);
+ return thid;
+}
+
+int main(int argc, char *argv[])
+{
+ pspDebugScreenInit();
+ sdl_psp_setup_callbacks();
+
+ /* Register sceKernelExitGame() to be called when we exit */
+ atexit(sceKernelExitGame);
+
+ SDL_SetMainReady();
+
+ (void)SDL_main(argc, argv);
+ return 0;
+}
+
+#endif /* __PSP__ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/main/windows/SDL_windows_main.c b/src/3rdparty/SDL2/src/main/windows/SDL_windows_main.c
new file mode 100644
index 0000000..5e643a4
--- /dev/null
+++ b/src/3rdparty/SDL2/src/main/windows/SDL_windows_main.c
@@ -0,0 +1,207 @@
+/*
+ SDL_windows_main.c, placed in the public domain by Sam Lantinga 4/13/98
+
+ The WinMain function -- calls your program's main() function
+*/
+#include "SDL_config.h"
+
+#ifdef __WIN32__
+
+/* Include this so we define UNICODE properly */
+#include "../../core/windows/SDL_windows.h"
+
+/* Include the SDL main definition header */
+#include "SDL.h"
+#include "SDL_main.h"
+
+#ifdef main
+# undef main
+#endif /* main */
+
+static void
+UnEscapeQuotes(char *arg)
+{
+ char *last = NULL;
+
+ while (*arg) {
+ if (*arg == '"' && (last != NULL && *last == '\\')) {
+ char *c_curr = arg;
+ char *c_last = last;
+
+ while (*c_curr) {
+ *c_last = *c_curr;
+ c_last = c_curr;
+ c_curr++;
+ }
+ *c_last = '\0';
+ }
+ last = arg;
+ arg++;
+ }
+}
+
+/* Parse a command line buffer into arguments */
+static int
+ParseCommandLine(char *cmdline, char **argv)
+{
+ char *bufp;
+ char *lastp = NULL;
+ int argc, last_argc;
+
+ argc = last_argc = 0;
+ for (bufp = cmdline; *bufp;) {
+ /* Skip leading whitespace */
+ while (*bufp == ' ' || *bufp == '\t') {
+ ++bufp;
+ }
+ /* Skip over argument */
+ if (*bufp == '"') {
+ ++bufp;
+ if (*bufp) {
+ if (argv) {
+ argv[argc] = bufp;
+ }
+ ++argc;
+ }
+ /* Skip over word */
+ lastp = bufp;
+ while (*bufp && (*bufp != '"' || *lastp == '\\')) {
+ lastp = bufp;
+ ++bufp;
+ }
+ } else {
+ if (*bufp) {
+ if (argv) {
+ argv[argc] = bufp;
+ }
+ ++argc;
+ }
+ /* Skip over word */
+ while (*bufp && (*bufp != ' ' && *bufp != '\t')) {
+ ++bufp;
+ }
+ }
+ if (*bufp) {
+ if (argv) {
+ *bufp = '\0';
+ }
+ ++bufp;
+ }
+
+ /* Strip out \ from \" sequences */
+ if (argv && last_argc != argc) {
+ UnEscapeQuotes(argv[last_argc]);
+ }
+ last_argc = argc;
+ }
+ if (argv) {
+ argv[argc] = NULL;
+ }
+ return (argc);
+}
+
+/* Pop up an out of memory message, returns to Windows */
+static BOOL
+OutOfMemory(void)
+{
+ SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal Error", "Out of memory - aborting", NULL);
+ return FALSE;
+}
+
+#if defined(_MSC_VER)
+/* The VC++ compiler needs main/wmain defined */
+# define console_ansi_main main
+# if UNICODE
+# define console_wmain wmain
+# endif
+#endif
+
+/* WinMain, main, and wmain eventually call into here. */
+static int
+main_utf8(int argc, char *argv[])
+{
+ SDL_SetMainReady();
+
+ /* Run the application main() code */
+ return SDL_main(argc, argv);
+}
+
+/* Gets the arguments with GetCommandLine, converts them to argc and argv
+ and calls main_utf8 */
+static int
+main_getcmdline()
+{
+ char **argv;
+ int argc;
+ char *cmdline;
+ int retval = 0;
+
+ /* Grab the command line */
+ TCHAR *text = GetCommandLine();
+#if UNICODE
+ cmdline = WIN_StringToUTF8(text);
+#else
+ /* !!! FIXME: are these in the system codepage? We need to convert to UTF-8. */
+ cmdline = SDL_strdup(text);
+#endif
+ if (cmdline == NULL) {
+ return OutOfMemory();
+ }
+
+ /* Parse it into argv and argc */
+ argc = ParseCommandLine(cmdline, NULL);
+ argv = SDL_stack_alloc(char *, argc + 1);
+ if (argv == NULL) {
+ return OutOfMemory();
+ }
+ ParseCommandLine(cmdline, argv);
+
+ retval = main_utf8(argc, argv);
+
+ SDL_stack_free(argv);
+ SDL_free(cmdline);
+
+ return retval;
+}
+
+/* This is where execution begins [console apps, ansi] */
+int
+console_ansi_main(int argc, char *argv[])
+{
+ return main_getcmdline();
+}
+
+
+#if UNICODE
+/* This is where execution begins [console apps, unicode] */
+int
+console_wmain(int argc, wchar_t *wargv[], wchar_t *wenvp)
+{
+ int retval = 0;
+ char **argv = SDL_stack_alloc(char*, argc + 1);
+ int i;
+
+ for (i = 0; i < argc; ++i) {
+ argv[i] = WIN_StringToUTF8(wargv[i]);
+ }
+ argv[argc] = NULL;
+
+ retval = main_utf8(argc, argv);
+
+ /* !!! FIXME: we are leaking all the elements of argv we allocated. */
+ SDL_stack_free(argv);
+
+ return retval;
+}
+#endif
+
+/* This is where execution begins [windowed apps] */
+int WINAPI
+WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
+{
+ return main_getcmdline();
+}
+
+#endif /* __WIN32__ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/main/windows/version.rc b/src/3rdparty/SDL2/src/main/windows/version.rc
new file mode 100644
index 0000000..6d16ad5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/main/windows/version.rc
@@ -0,0 +1,38 @@
+
+#include "winresrc.h"
+
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 2,0,8,0
+ PRODUCTVERSION 2,0,8,0
+ FILEFLAGSMASK 0x3fL
+ FILEFLAGS 0x0L
+ FILEOS 0x40004L
+ FILETYPE 0x2L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "CompanyName", "\0"
+ VALUE "FileDescription", "SDL\0"
+ VALUE "FileVersion", "2, 0, 8, 0\0"
+ VALUE "InternalName", "SDL\0"
+ VALUE "LegalCopyright", "Copyright 2018 Sam Lantinga\0"
+ VALUE "OriginalFilename", "SDL2.dll\0"
+ VALUE "ProductName", "Simple DirectMedia Layer\0"
+ VALUE "ProductVersion", "2, 0, 8, 0\0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
diff --git a/src/3rdparty/SDL2/src/main/winrt/SDL2-WinRTResource_BlankCursor.cur b/src/3rdparty/SDL2/src/main/winrt/SDL2-WinRTResource_BlankCursor.cur
new file mode 100644
index 0000000..c6556b8
--- /dev/null
+++ b/src/3rdparty/SDL2/src/main/winrt/SDL2-WinRTResource_BlankCursor.cur
Binary files differ
diff --git a/src/3rdparty/SDL2/src/main/winrt/SDL2-WinRTResources.rc b/src/3rdparty/SDL2/src/main/winrt/SDL2-WinRTResources.rc
new file mode 100644
index 0000000..988a8d5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/main/winrt/SDL2-WinRTResources.rc
@@ -0,0 +1,3 @@
+#include "winres.h"
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+5000 CURSOR "SDL2-WinRTResource_BlankCursor.cur"
diff --git a/src/3rdparty/SDL2/src/main/winrt/SDL_winrt_main_NonXAML.cpp b/src/3rdparty/SDL2/src/main/winrt/SDL_winrt_main_NonXAML.cpp
new file mode 100644
index 0000000..19d2250
--- /dev/null
+++ b/src/3rdparty/SDL2/src/main/winrt/SDL_winrt_main_NonXAML.cpp
@@ -0,0 +1,54 @@
+/*
+ SDL_winrt_main_NonXAML.cpp, placed in the public domain by David Ludwig 3/13/14
+*/
+
+#include "SDL_main.h"
+#include <wrl.h>
+
+/* At least one file in any SDL/WinRT app appears to require compilation
+ with C++/CX, otherwise a Windows Metadata file won't get created, and
+ an APPX0702 build error can appear shortly after linking.
+
+ The following set of preprocessor code forces this file to be compiled
+ as C++/CX, which appears to cause Visual C++ 2012's build tools to
+ create this .winmd file, and will help allow builds of SDL/WinRT apps
+ to proceed without error.
+
+ If other files in an app's project enable C++/CX compilation, then it might
+ be possible for SDL_winrt_main_NonXAML.cpp to be compiled without /ZW,
+ for Visual C++'s build tools to create a winmd file, and for the app to
+ build without APPX0702 errors. In this case, if
+ SDL_WINRT_METADATA_FILE_AVAILABLE is defined as a C/C++ macro, then
+ the #error (to force C++/CX compilation) will be disabled.
+
+ Please note that /ZW can be specified on a file-by-file basis. To do this,
+ right click on the file in Visual C++, click Properties, then change the
+ setting through the dialog that comes up.
+*/
+#ifndef SDL_WINRT_METADATA_FILE_AVAILABLE
+#ifndef __cplusplus_winrt
+#error SDL_winrt_main_NonXAML.cpp must be compiled with /ZW, otherwise build errors due to missing .winmd files can occur.
+#endif
+#endif
+
+/* Prevent MSVC++ from warning about threading models when defining our
+ custom WinMain. The threading model will instead be set via a direct
+ call to Windows::Foundation::Initialize (rather than via an attributed
+ function).
+
+ To note, this warning (C4447) does not seem to come up unless this file
+ is compiled with C++/CX enabled (via the /ZW compiler flag).
+*/
+#ifdef _MSC_VER
+#pragma warning(disable:4447)
+#endif
+
+/* Make sure the function to initialize the Windows Runtime gets linked in. */
+#ifdef _MSC_VER
+#pragma comment(lib, "runtimeobject.lib")
+#endif
+
+int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
+{
+ return SDL_WinRTRunApp(SDL_main, NULL);
+}
diff --git a/src/3rdparty/SDL2/src/power/SDL_power.c b/src/3rdparty/SDL2/src/power/SDL_power.c
new file mode 100644
index 0000000..e09e27b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/power/SDL_power.c
@@ -0,0 +1,116 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+#include "SDL_power.h"
+#include "SDL_syspower.h"
+
+/*
+ * Returns SDL_TRUE if we have a definitive answer.
+ * SDL_FALSE to try next implementation.
+ */
+typedef SDL_bool
+ (*SDL_GetPowerInfo_Impl) (SDL_PowerState * state, int *seconds,
+ int *percent);
+
+#ifndef SDL_POWER_DISABLED
+#ifdef SDL_POWER_HARDWIRED
+/* This is for things that _never_ have a battery */
+static SDL_bool
+SDL_GetPowerInfo_Hardwired(SDL_PowerState * state, int *seconds, int *percent)
+{
+ *seconds = -1;
+ *percent = -1;
+ *state = SDL_POWERSTATE_NO_BATTERY;
+ return SDL_TRUE;
+}
+#endif
+#endif
+
+
+static SDL_GetPowerInfo_Impl implementations[] = {
+#ifndef SDL_POWER_DISABLED
+#ifdef SDL_POWER_LINUX /* in order of preference. More than could work. */
+ SDL_GetPowerInfo_Linux_org_freedesktop_upower,
+ SDL_GetPowerInfo_Linux_sys_class_power_supply,
+ SDL_GetPowerInfo_Linux_proc_acpi,
+ SDL_GetPowerInfo_Linux_proc_apm,
+#endif
+#ifdef SDL_POWER_WINDOWS /* handles Win32, Win64, PocketPC. */
+ SDL_GetPowerInfo_Windows,
+#endif
+#ifdef SDL_POWER_UIKIT /* handles iPhone/iPad/etc */
+ SDL_GetPowerInfo_UIKit,
+#endif
+#ifdef SDL_POWER_MACOSX /* handles Mac OS X, Darwin. */
+ SDL_GetPowerInfo_MacOSX,
+#endif
+#ifdef SDL_POWER_HAIKU /* with BeOS euc.jp apm driver. Does this work on Haiku? */
+ SDL_GetPowerInfo_Haiku,
+#endif
+#ifdef SDL_POWER_ANDROID /* handles Android. */
+ SDL_GetPowerInfo_Android,
+#endif
+#ifdef SDL_POWER_PSP /* handles PSP. */
+ SDL_GetPowerInfo_PSP,
+#endif
+#ifdef SDL_POWER_WINRT /* handles WinRT */
+ SDL_GetPowerInfo_WinRT,
+#endif
+#ifdef SDL_POWER_EMSCRIPTEN /* handles Emscripten */
+ SDL_GetPowerInfo_Emscripten,
+#endif
+
+#ifdef SDL_POWER_HARDWIRED
+ SDL_GetPowerInfo_Hardwired,
+#endif
+#endif
+};
+
+SDL_PowerState
+SDL_GetPowerInfo(int *seconds, int *percent)
+{
+ const int total = sizeof(implementations) / sizeof(implementations[0]);
+ int _seconds, _percent;
+ SDL_PowerState retval = SDL_POWERSTATE_UNKNOWN;
+ int i;
+
+ /* Make these never NULL for platform-specific implementations. */
+ if (seconds == NULL) {
+ seconds = &_seconds;
+ }
+
+ if (percent == NULL) {
+ percent = &_percent;
+ }
+
+ for (i = 0; i < total; i++) {
+ if (implementations[i](&retval, seconds, percent)) {
+ return retval;
+ }
+ }
+
+ /* nothing was definitive. */
+ *seconds = -1;
+ *percent = -1;
+ return SDL_POWERSTATE_UNKNOWN;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/power/SDL_syspower.h b/src/3rdparty/SDL2/src/power/SDL_syspower.h
new file mode 100644
index 0000000..a9bf70c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/power/SDL_syspower.h
@@ -0,0 +1,47 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* These are functions that need to be implemented by a port of SDL */
+
+#ifndef SDL_syspower_h_
+#define SDL_syspower_h_
+
+#include "SDL_power.h"
+
+/* Not all of these are available in a given build. Use #ifdefs, etc. */
+SDL_bool SDL_GetPowerInfo_Linux_org_freedesktop_upower(SDL_PowerState *, int *, int *);
+SDL_bool SDL_GetPowerInfo_Linux_sys_class_power_supply(SDL_PowerState *, int *, int *);
+SDL_bool SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState *, int *, int *);
+SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *, int *, int *);
+SDL_bool SDL_GetPowerInfo_Windows(SDL_PowerState *, int *, int *);
+SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *, int *, int *);
+SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState *, int *, int *);
+SDL_bool SDL_GetPowerInfo_Haiku(SDL_PowerState *, int *, int *);
+SDL_bool SDL_GetPowerInfo_Android(SDL_PowerState *, int *, int *);
+SDL_bool SDL_GetPowerInfo_PSP(SDL_PowerState *, int *, int *);
+SDL_bool SDL_GetPowerInfo_WinRT(SDL_PowerState *, int *, int *);
+SDL_bool SDL_GetPowerInfo_Emscripten(SDL_PowerState *, int *, int *);
+SDL_bool SDL_GetPowerInfo_Hardwired(SDL_PowerState *, int *, int *);
+
+#endif /* SDL_syspower_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/power/android/SDL_syspower.c b/src/3rdparty/SDL2/src/power/android/SDL_syspower.c
new file mode 100644
index 0000000..f0f492d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/power/android/SDL_syspower.c
@@ -0,0 +1,64 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_POWER_DISABLED
+#if SDL_POWER_ANDROID
+
+#include "SDL_power.h"
+#include "../SDL_syspower.h"
+
+#include "../../core/android/SDL_android.h"
+
+SDL_bool
+SDL_GetPowerInfo_Android(SDL_PowerState * state, int *seconds, int *percent)
+{
+ int battery;
+ int plugged;
+ int charged;
+
+ if (Android_JNI_GetPowerInfo(&plugged, &charged, &battery, seconds, percent) != -1) {
+ if (plugged) {
+ if (charged) {
+ *state = SDL_POWERSTATE_CHARGED;
+ } else if (battery) {
+ *state = SDL_POWERSTATE_CHARGING;
+ } else {
+ *state = SDL_POWERSTATE_NO_BATTERY;
+ *seconds = -1;
+ *percent = -1;
+ }
+ } else {
+ *state = SDL_POWERSTATE_ON_BATTERY;
+ }
+ } else {
+ *state = SDL_POWERSTATE_UNKNOWN;
+ *seconds = -1;
+ *percent = -1;
+ }
+
+ return SDL_TRUE;
+}
+
+#endif /* SDL_POWER_ANDROID */
+#endif /* SDL_POWER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/power/emscripten/SDL_syspower.c b/src/3rdparty/SDL2/src/power/emscripten/SDL_syspower.c
new file mode 100644
index 0000000..9b92168
--- /dev/null
+++ b/src/3rdparty/SDL2/src/power/emscripten/SDL_syspower.c
@@ -0,0 +1,62 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_POWER_DISABLED
+#if SDL_POWER_EMSCRIPTEN
+
+#include <emscripten/html5.h>
+
+#include "SDL_power.h"
+
+SDL_bool
+SDL_GetPowerInfo_Emscripten(SDL_PowerState *state, int *seconds, int *percent)
+{
+ EmscriptenBatteryEvent batteryState;
+ int haveBattery = 0;
+
+ if (emscripten_get_battery_status(&batteryState) == EMSCRIPTEN_RESULT_NOT_SUPPORTED)
+ return SDL_FALSE;
+
+ haveBattery = batteryState.level != 1.0 || !batteryState.charging || batteryState.chargingTime != 0.0;
+
+ if (!haveBattery) {
+ *state = SDL_POWERSTATE_NO_BATTERY;
+ *seconds = -1;
+ *percent = -1;
+ return SDL_TRUE;
+ }
+
+ if (batteryState.charging)
+ *state = batteryState.chargingTime == 0.0 ? SDL_POWERSTATE_CHARGED : SDL_POWERSTATE_CHARGING;
+ else
+ *state = SDL_POWERSTATE_ON_BATTERY;
+
+ *seconds = batteryState.dischargingTime;
+ *percent = batteryState.level * 100;
+
+ return SDL_TRUE;
+}
+
+#endif /* SDL_POWER_EMSCRIPTEN */
+#endif /* SDL_POWER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/power/haiku/SDL_syspower.c b/src/3rdparty/SDL2/src/power/haiku/SDL_syspower.c
new file mode 100644
index 0000000..47961bb
--- /dev/null
+++ b/src/3rdparty/SDL2/src/power/haiku/SDL_syspower.c
@@ -0,0 +1,128 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+/* uses BeOS euc.jp apm driver. */
+/* !!! FIXME: does this thing even work on Haiku? */
+
+#ifndef SDL_POWER_DISABLED
+#if SDL_POWER_HAIKU
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <drivers/Drivers.h>
+
+/* These values are from apm.h ... */
+#define APM_DEVICE_PATH "/dev/misc/apm"
+#define APM_FUNC_OFFSET 0x5300
+#define APM_FUNC_GET_POWER_STATUS 10
+#define APM_DEVICE_ALL 1
+#define APM_BIOS_CALL (B_DEVICE_OP_CODES_END + 3)
+
+#include "SDL_power.h"
+
+SDL_bool
+SDL_GetPowerInfo_Haiku(SDL_PowerState * state, int *seconds, int *percent)
+{
+ const int fd = open("/dev/misc/apm", O_RDONLY);
+ SDL_bool need_details = SDL_FALSE;
+ uint16 regs[6];
+ uint8 ac_status;
+ uint8 battery_status;
+ uint8 battery_flags;
+ uint8 battery_life;
+ uint32 battery_time;
+ int rc;
+
+ if (fd == -1) {
+ return SDL_FALSE; /* maybe some other method will work? */
+ }
+
+ memset(regs, '\0', sizeof(regs));
+ regs[0] = APM_FUNC_OFFSET + APM_FUNC_GET_POWER_STATUS;
+ regs[1] = APM_DEVICE_ALL;
+ rc = ioctl(fd, APM_BIOS_CALL, regs);
+ close(fd);
+
+ if (rc < 0) {
+ return SDL_FALSE;
+ }
+
+ ac_status = regs[1] >> 8;
+ battery_status = regs[1] & 0xFF;
+ battery_flags = regs[2] >> 8;
+ battery_life = regs[2] & 0xFF;
+ battery_time = (uint32) regs[3];
+
+ /* in theory, _something_ should be set in battery_flags, right? */
+ if (battery_flags == 0x00) { /* older APM BIOS? Less fields. */
+ battery_time = 0xFFFF;
+ if (battery_status == 0xFF) {
+ battery_flags = 0xFF;
+ } else {
+ battery_flags = (1 << battery_status);
+ }
+ }
+
+ if ((battery_time != 0xFFFF) && (battery_time & (1 << 15))) {
+ /* time is in minutes, not seconds */
+ battery_time = (battery_time & 0x7FFF) * 60;
+ }
+
+ if (battery_flags == 0xFF) { /* unknown state */
+ *state = SDL_POWERSTATE_UNKNOWN;
+ } else if (battery_flags & (1 << 7)) { /* no battery */
+ *state = SDL_POWERSTATE_NO_BATTERY;
+ } else if (battery_flags & (1 << 3)) { /* charging */
+ *state = SDL_POWERSTATE_CHARGING;
+ need_details = SDL_TRUE;
+ } else if (ac_status == 1) {
+ *state = SDL_POWERSTATE_CHARGED; /* on AC, not charging. */
+ need_details = SDL_TRUE;
+ } else {
+ *state = SDL_POWERSTATE_ON_BATTERY; /* not on AC. */
+ need_details = SDL_TRUE;
+ }
+
+ *percent = -1;
+ *seconds = -1;
+ if (need_details) {
+ const int pct = (int) battery_life;
+ const int secs = (int) battery_time;
+
+ if (pct != 255) { /* 255 == unknown */
+ *percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
+ }
+ if (secs != 0xFFFF) { /* 0xFFFF == unknown */
+ *seconds = secs;
+ }
+ }
+
+ return SDL_TRUE; /* the definitive answer if APM driver replied. */
+}
+
+#endif /* SDL_POWER_HAIKU */
+#endif /* SDL_POWER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/power/linux/SDL_syspower.c b/src/3rdparty/SDL2/src/power/linux/SDL_syspower.c
new file mode 100644
index 0000000..105d5fe
--- /dev/null
+++ b/src/3rdparty/SDL2/src/power/linux/SDL_syspower.c
@@ -0,0 +1,642 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_POWER_DISABLED
+#if SDL_POWER_LINUX
+
+#include <stdio.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <fcntl.h>
+
+#include "SDL_power.h"
+#include "../SDL_syspower.h"
+
+#include "../../core/linux/SDL_dbus.h"
+
+static const char *proc_apm_path = "/proc/apm";
+static const char *proc_acpi_battery_path = "/proc/acpi/battery";
+static const char *proc_acpi_ac_adapter_path = "/proc/acpi/ac_adapter";
+static const char *sys_class_power_supply_path = "/sys/class/power_supply";
+
+static int
+open_power_file(const char *base, const char *node, const char *key)
+{
+ const size_t pathlen = strlen(base) + strlen(node) + strlen(key) + 3;
+ char *path = (char *) alloca(pathlen);
+ if (path == NULL) {
+ return -1; /* oh well. */
+ }
+
+ snprintf(path, pathlen, "%s/%s/%s", base, node, key);
+ return open(path, O_RDONLY);
+}
+
+
+static SDL_bool
+read_power_file(const char *base, const char *node, const char *key,
+ char *buf, size_t buflen)
+{
+ ssize_t br = 0;
+ const int fd = open_power_file(base, node, key);
+ if (fd == -1) {
+ return SDL_FALSE;
+ }
+ br = read(fd, buf, buflen-1);
+ close(fd);
+ if (br < 0) {
+ return SDL_FALSE;
+ }
+ buf[br] = '\0'; /* null-terminate the string. */
+ return SDL_TRUE;
+}
+
+
+static SDL_bool
+make_proc_acpi_key_val(char **_ptr, char **_key, char **_val)
+{
+ char *ptr = *_ptr;
+
+ while (*ptr == ' ') {
+ ptr++; /* skip whitespace. */
+ }
+
+ if (*ptr == '\0') {
+ return SDL_FALSE; /* EOF. */
+ }
+
+ *_key = ptr;
+
+ while ((*ptr != ':') && (*ptr != '\0')) {
+ ptr++;
+ }
+
+ if (*ptr == '\0') {
+ return SDL_FALSE; /* (unexpected) EOF. */
+ }
+
+ *(ptr++) = '\0'; /* terminate the key. */
+
+ while ((*ptr == ' ') && (*ptr != '\0')) {
+ ptr++; /* skip whitespace. */
+ }
+
+ if (*ptr == '\0') {
+ return SDL_FALSE; /* (unexpected) EOF. */
+ }
+
+ *_val = ptr;
+
+ while ((*ptr != '\n') && (*ptr != '\0')) {
+ ptr++;
+ }
+
+ if (*ptr != '\0') {
+ *(ptr++) = '\0'; /* terminate the value. */
+ }
+
+ *_ptr = ptr; /* store for next time. */
+ return SDL_TRUE;
+}
+
+static void
+check_proc_acpi_battery(const char * node, SDL_bool * have_battery,
+ SDL_bool * charging, int *seconds, int *percent)
+{
+ const char *base = proc_acpi_battery_path;
+ char info[1024];
+ char state[1024];
+ char *ptr = NULL;
+ char *key = NULL;
+ char *val = NULL;
+ SDL_bool charge = SDL_FALSE;
+ SDL_bool choose = SDL_FALSE;
+ int maximum = -1;
+ int remaining = -1;
+ int secs = -1;
+ int pct = -1;
+
+ if (!read_power_file(base, node, "state", state, sizeof (state))) {
+ return;
+ } else if (!read_power_file(base, node, "info", info, sizeof (info))) {
+ return;
+ }
+
+ ptr = &state[0];
+ while (make_proc_acpi_key_val(&ptr, &key, &val)) {
+ if (strcmp(key, "present") == 0) {
+ if (strcmp(val, "yes") == 0) {
+ *have_battery = SDL_TRUE;
+ }
+ } else if (strcmp(key, "charging state") == 0) {
+ /* !!! FIXME: what exactly _does_ charging/discharging mean? */
+ if (strcmp(val, "charging/discharging") == 0) {
+ charge = SDL_TRUE;
+ } else if (strcmp(val, "charging") == 0) {
+ charge = SDL_TRUE;
+ }
+ } else if (strcmp(key, "remaining capacity") == 0) {
+ char *endptr = NULL;
+ const int cvt = (int) strtol(val, &endptr, 10);
+ if (*endptr == ' ') {
+ remaining = cvt;
+ }
+ }
+ }
+
+ ptr = &info[0];
+ while (make_proc_acpi_key_val(&ptr, &key, &val)) {
+ if (strcmp(key, "design capacity") == 0) {
+ char *endptr = NULL;
+ const int cvt = (int) strtol(val, &endptr, 10);
+ if (*endptr == ' ') {
+ maximum = cvt;
+ }
+ }
+ }
+
+ if ((maximum >= 0) && (remaining >= 0)) {
+ pct = (int) ((((float) remaining) / ((float) maximum)) * 100.0f);
+ if (pct < 0) {
+ pct = 0;
+ } else if (pct > 100) {
+ pct = 100;
+ }
+ }
+
+ /* !!! FIXME: calculate (secs). */
+
+ /*
+ * We pick the battery that claims to have the most minutes left.
+ * (failing a report of minutes, we'll take the highest percent.)
+ */
+ if ((secs < 0) && (*seconds < 0)) {
+ if ((pct < 0) && (*percent < 0)) {
+ choose = SDL_TRUE; /* at least we know there's a battery. */
+ }
+ if (pct > *percent) {
+ choose = SDL_TRUE;
+ }
+ } else if (secs > *seconds) {
+ choose = SDL_TRUE;
+ }
+
+ if (choose) {
+ *seconds = secs;
+ *percent = pct;
+ *charging = charge;
+ }
+}
+
+static void
+check_proc_acpi_ac_adapter(const char * node, SDL_bool * have_ac)
+{
+ const char *base = proc_acpi_ac_adapter_path;
+ char state[256];
+ char *ptr = NULL;
+ char *key = NULL;
+ char *val = NULL;
+
+ if (!read_power_file(base, node, "state", state, sizeof (state))) {
+ return;
+ }
+
+ ptr = &state[0];
+ while (make_proc_acpi_key_val(&ptr, &key, &val)) {
+ if (strcmp(key, "state") == 0) {
+ if (strcmp(val, "on-line") == 0) {
+ *have_ac = SDL_TRUE;
+ }
+ }
+ }
+}
+
+
+SDL_bool
+SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState * state,
+ int *seconds, int *percent)
+{
+ struct dirent *dent = NULL;
+ DIR *dirp = NULL;
+ SDL_bool have_battery = SDL_FALSE;
+ SDL_bool have_ac = SDL_FALSE;
+ SDL_bool charging = SDL_FALSE;
+
+ *seconds = -1;
+ *percent = -1;
+ *state = SDL_POWERSTATE_UNKNOWN;
+
+ dirp = opendir(proc_acpi_battery_path);
+ if (dirp == NULL) {
+ return SDL_FALSE; /* can't use this interface. */
+ } else {
+ while ((dent = readdir(dirp)) != NULL) {
+ const char *node = dent->d_name;
+ check_proc_acpi_battery(node, &have_battery, &charging,
+ seconds, percent);
+ }
+ closedir(dirp);
+ }
+
+ dirp = opendir(proc_acpi_ac_adapter_path);
+ if (dirp == NULL) {
+ return SDL_FALSE; /* can't use this interface. */
+ } else {
+ while ((dent = readdir(dirp)) != NULL) {
+ const char *node = dent->d_name;
+ check_proc_acpi_ac_adapter(node, &have_ac);
+ }
+ closedir(dirp);
+ }
+
+ if (!have_battery) {
+ *state = SDL_POWERSTATE_NO_BATTERY;
+ } else if (charging) {
+ *state = SDL_POWERSTATE_CHARGING;
+ } else if (have_ac) {
+ *state = SDL_POWERSTATE_CHARGED;
+ } else {
+ *state = SDL_POWERSTATE_ON_BATTERY;
+ }
+
+ return SDL_TRUE; /* definitive answer. */
+}
+
+
+static SDL_bool
+next_string(char **_ptr, char **_str)
+{
+ char *ptr = *_ptr;
+ char *str = *_str;
+
+ while (*ptr == ' ') { /* skip any spaces... */
+ ptr++;
+ }
+
+ if (*ptr == '\0') {
+ return SDL_FALSE;
+ }
+
+ str = ptr;
+ while ((*ptr != ' ') && (*ptr != '\n') && (*ptr != '\0'))
+ ptr++;
+
+ if (*ptr != '\0')
+ *(ptr++) = '\0';
+
+ *_str = str;
+ *_ptr = ptr;
+ return SDL_TRUE;
+}
+
+static SDL_bool
+int_string(char *str, int *val)
+{
+ char *endptr = NULL;
+ *val = (int) strtol(str, &endptr, 0);
+ return ((*str != '\0') && (*endptr == '\0'));
+}
+
+/* http://lxr.linux.no/linux+v2.6.29/drivers/char/apm-emulation.c */
+SDL_bool
+SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState * state,
+ int *seconds, int *percent)
+{
+ SDL_bool need_details = SDL_FALSE;
+ int ac_status = 0;
+ int battery_status = 0;
+ int battery_flag = 0;
+ int battery_percent = 0;
+ int battery_time = 0;
+ const int fd = open(proc_apm_path, O_RDONLY);
+ char buf[128];
+ char *ptr = &buf[0];
+ char *str = NULL;
+ ssize_t br;
+
+ if (fd == -1) {
+ return SDL_FALSE; /* can't use this interface. */
+ }
+
+ br = read(fd, buf, sizeof (buf) - 1);
+ close(fd);
+
+ if (br < 0) {
+ return SDL_FALSE;
+ }
+
+ buf[br] = '\0'; /* null-terminate the string. */
+ if (!next_string(&ptr, &str)) { /* driver version */
+ return SDL_FALSE;
+ }
+ if (!next_string(&ptr, &str)) { /* BIOS version */
+ return SDL_FALSE;
+ }
+ if (!next_string(&ptr, &str)) { /* APM flags */
+ return SDL_FALSE;
+ }
+
+ if (!next_string(&ptr, &str)) { /* AC line status */
+ return SDL_FALSE;
+ } else if (!int_string(str, &ac_status)) {
+ return SDL_FALSE;
+ }
+
+ if (!next_string(&ptr, &str)) { /* battery status */
+ return SDL_FALSE;
+ } else if (!int_string(str, &battery_status)) {
+ return SDL_FALSE;
+ }
+ if (!next_string(&ptr, &str)) { /* battery flag */
+ return SDL_FALSE;
+ } else if (!int_string(str, &battery_flag)) {
+ return SDL_FALSE;
+ }
+ if (!next_string(&ptr, &str)) { /* remaining battery life percent */
+ return SDL_FALSE;
+ }
+ if (str[strlen(str) - 1] == '%') {
+ str[strlen(str) - 1] = '\0';
+ }
+ if (!int_string(str, &battery_percent)) {
+ return SDL_FALSE;
+ }
+
+ if (!next_string(&ptr, &str)) { /* remaining battery life time */
+ return SDL_FALSE;
+ } else if (!int_string(str, &battery_time)) {
+ return SDL_FALSE;
+ }
+
+ if (!next_string(&ptr, &str)) { /* remaining battery life time units */
+ return SDL_FALSE;
+ } else if (strcmp(str, "min") == 0) {
+ battery_time *= 60;
+ }
+
+ if (battery_flag == 0xFF) { /* unknown state */
+ *state = SDL_POWERSTATE_UNKNOWN;
+ } else if (battery_flag & (1 << 7)) { /* no battery */
+ *state = SDL_POWERSTATE_NO_BATTERY;
+ } else if (battery_flag & (1 << 3)) { /* charging */
+ *state = SDL_POWERSTATE_CHARGING;
+ need_details = SDL_TRUE;
+ } else if (ac_status == 1) {
+ *state = SDL_POWERSTATE_CHARGED; /* on AC, not charging. */
+ need_details = SDL_TRUE;
+ } else {
+ *state = SDL_POWERSTATE_ON_BATTERY;
+ need_details = SDL_TRUE;
+ }
+
+ *percent = -1;
+ *seconds = -1;
+ if (need_details) {
+ const int pct = battery_percent;
+ const int secs = battery_time;
+
+ if (pct >= 0) { /* -1 == unknown */
+ *percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
+ }
+ if (secs >= 0) { /* -1 == unknown */
+ *seconds = secs;
+ }
+ }
+
+ return SDL_TRUE;
+}
+
+SDL_bool
+SDL_GetPowerInfo_Linux_sys_class_power_supply(SDL_PowerState *state, int *seconds, int *percent)
+{
+ const char *base = sys_class_power_supply_path;
+ struct dirent *dent;
+ DIR *dirp;
+
+ dirp = opendir(base);
+ if (!dirp) {
+ return SDL_FALSE;
+ }
+
+ *state = SDL_POWERSTATE_NO_BATTERY; /* assume we're just plugged in. */
+ *seconds = -1;
+ *percent = -1;
+
+ while ((dent = readdir(dirp)) != NULL) {
+ const char *name = dent->d_name;
+ SDL_bool choose = SDL_FALSE;
+ char str[64];
+ SDL_PowerState st;
+ int secs;
+ int pct;
+
+ if ((SDL_strcmp(name, ".") == 0) || (SDL_strcmp(name, "..") == 0)) {
+ continue; /* skip these, of course. */
+ } else if (!read_power_file(base, name, "type", str, sizeof (str))) {
+ continue; /* Don't know _what_ we're looking at. Give up on it. */
+ } else if (SDL_strcmp(str, "Battery\n") != 0) {
+ continue; /* we don't care about UPS and such. */
+ }
+
+ /* if the scope is "device," it might be something like a PS4
+ controller reporting its own battery, and not something that powers
+ the system. Most system batteries don't list a scope at all; we
+ assume it's a system battery if not specified. */
+ if (read_power_file(base, name, "scope", str, sizeof (str))) {
+ if (SDL_strcmp(str, "device\n") == 0) {
+ continue; /* skip external devices with their own batteries. */
+ }
+ }
+
+ /* some drivers don't offer this, so if it's not explicitly reported assume it's present. */
+ if (read_power_file(base, name, "present", str, sizeof (str)) && (SDL_strcmp(str, "0\n") == 0)) {
+ st = SDL_POWERSTATE_NO_BATTERY;
+ } else if (!read_power_file(base, name, "status", str, sizeof (str))) {
+ st = SDL_POWERSTATE_UNKNOWN; /* uh oh */
+ } else if (SDL_strcmp(str, "Charging\n") == 0) {
+ st = SDL_POWERSTATE_CHARGING;
+ } else if (SDL_strcmp(str, "Discharging\n") == 0) {
+ st = SDL_POWERSTATE_ON_BATTERY;
+ } else if ((SDL_strcmp(str, "Full\n") == 0) || (SDL_strcmp(str, "Not charging\n") == 0)) {
+ st = SDL_POWERSTATE_CHARGED;
+ } else {
+ st = SDL_POWERSTATE_UNKNOWN; /* uh oh */
+ }
+
+ if (!read_power_file(base, name, "capacity", str, sizeof (str))) {
+ pct = -1;
+ } else {
+ pct = SDL_atoi(str);
+ pct = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
+ }
+
+ if (!read_power_file(base, name, "time_to_empty_now", str, sizeof (str))) {
+ secs = -1;
+ } else {
+ secs = SDL_atoi(str);
+ secs = (secs <= 0) ? -1 : secs; /* 0 == unknown */
+ }
+
+ /*
+ * We pick the battery that claims to have the most minutes left.
+ * (failing a report of minutes, we'll take the highest percent.)
+ */
+ if ((secs < 0) && (*seconds < 0)) {
+ if ((pct < 0) && (*percent < 0)) {
+ choose = SDL_TRUE; /* at least we know there's a battery. */
+ } else if (pct > *percent) {
+ choose = SDL_TRUE;
+ }
+ } else if (secs > *seconds) {
+ choose = SDL_TRUE;
+ }
+
+ if (choose) {
+ *seconds = secs;
+ *percent = pct;
+ *state = st;
+ }
+ }
+
+ closedir(dirp);
+ return SDL_TRUE; /* don't look any further. */
+}
+
+
+/* d-bus queries to org.freedesktop.UPower. */
+#if SDL_USE_LIBDBUS
+#define UPOWER_DBUS_NODE "org.freedesktop.UPower"
+#define UPOWER_DBUS_PATH "/org/freedesktop/UPower"
+#define UPOWER_DBUS_INTERFACE "org.freedesktop.UPower"
+#define UPOWER_DEVICE_DBUS_INTERFACE "org.freedesktop.UPower.Device"
+
+static void
+check_upower_device(DBusConnection *conn, const char *path, SDL_PowerState *state, int *seconds, int *percent)
+{
+ SDL_bool choose = SDL_FALSE;
+ SDL_PowerState st;
+ int secs;
+ int pct;
+ Uint32 ui32 = 0;
+ Sint64 si64 = 0;
+ double d = 0.0;
+
+ if (!SDL_DBus_QueryPropertyOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "Type", DBUS_TYPE_UINT32, &ui32)) {
+ return; /* Don't know _what_ we're looking at. Give up on it. */
+ } else if (ui32 != 2) { /* 2==Battery*/
+ return; /* we don't care about UPS and such. */
+ } else if (!SDL_DBus_QueryPropertyOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "PowerSupply", DBUS_TYPE_BOOLEAN, &ui32)) {
+ return;
+ } else if (!ui32) {
+ return; /* we don't care about random devices with batteries, like wireless controllers, etc */
+ } else if (!SDL_DBus_QueryPropertyOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "IsPresent", DBUS_TYPE_BOOLEAN, &ui32)) {
+ return;
+ } else if (!ui32) {
+ st = SDL_POWERSTATE_NO_BATTERY;
+ } else if (!SDL_DBus_QueryPropertyOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "State", DBUS_TYPE_UINT32, &ui32)) {
+ st = SDL_POWERSTATE_UNKNOWN; /* uh oh */
+ } else if (ui32 == 1) { /* 1 == charging */
+ st = SDL_POWERSTATE_CHARGING;
+ } else if ((ui32 == 2) || (ui32 == 3)) { /* 2 == discharging, 3 == empty. */
+ st = SDL_POWERSTATE_ON_BATTERY;
+ } else if (ui32 == 4) { /* 4 == full */
+ st = SDL_POWERSTATE_CHARGED;
+ } else {
+ st = SDL_POWERSTATE_UNKNOWN; /* uh oh */
+ }
+
+ if (!SDL_DBus_QueryPropertyOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "Percentage", DBUS_TYPE_DOUBLE, &d)) {
+ pct = -1; /* some old/cheap batteries don't set this property. */
+ } else {
+ pct = (int) d;
+ pct = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
+ }
+
+ if (!SDL_DBus_QueryPropertyOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "TimeToEmpty", DBUS_TYPE_INT64, &si64)) {
+ secs = -1;
+ } else {
+ secs = (int) si64;
+ secs = (secs <= 0) ? -1 : secs; /* 0 == unknown */
+ }
+
+ /*
+ * We pick the battery that claims to have the most minutes left.
+ * (failing a report of minutes, we'll take the highest percent.)
+ */
+ if ((secs < 0) && (*seconds < 0)) {
+ if ((pct < 0) && (*percent < 0)) {
+ choose = SDL_TRUE; /* at least we know there's a battery. */
+ } else if (pct > *percent) {
+ choose = SDL_TRUE;
+ }
+ } else if (secs > *seconds) {
+ choose = SDL_TRUE;
+ }
+
+ if (choose) {
+ *seconds = secs;
+ *percent = pct;
+ *state = st;
+ }
+}
+#endif
+
+SDL_bool
+SDL_GetPowerInfo_Linux_org_freedesktop_upower(SDL_PowerState *state, int *seconds, int *percent)
+{
+ SDL_bool retval = SDL_FALSE;
+
+ #if SDL_USE_LIBDBUS
+ SDL_DBusContext *dbus = SDL_DBus_GetContext();
+ char **paths = NULL;
+ int i, numpaths = 0;
+
+ if (!SDL_DBus_CallMethodOnConnection(dbus->system_conn, UPOWER_DBUS_NODE, UPOWER_DBUS_PATH, UPOWER_DBUS_INTERFACE, "EnumerateDevices",
+ DBUS_TYPE_INVALID,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &paths, &numpaths, DBUS_TYPE_INVALID)) {
+ return SDL_FALSE; /* try a different approach than UPower. */
+ }
+
+ retval = SDL_TRUE; /* Clearly we can use this interface. */
+ *state = SDL_POWERSTATE_NO_BATTERY; /* assume we're just plugged in. */
+ *seconds = -1;
+ *percent = -1;
+
+ for (i = 0; i < numpaths; i++) {
+ check_upower_device(dbus->system_conn, paths[i], state, seconds, percent);
+ }
+
+ if (dbus) {
+ dbus->free_string_array(paths);
+ }
+ #endif /* SDL_USE_LIBDBUS */
+
+ return retval;
+}
+
+#endif /* SDL_POWER_LINUX */
+#endif /* SDL_POWER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/power/macosx/SDL_syspower.c b/src/3rdparty/SDL2/src/power/macosx/SDL_syspower.c
new file mode 100644
index 0000000..f28b6c8
--- /dev/null
+++ b/src/3rdparty/SDL2/src/power/macosx/SDL_syspower.c
@@ -0,0 +1,192 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_POWER_DISABLED
+#if SDL_POWER_MACOSX
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <IOKit/ps/IOPowerSources.h>
+#include <IOKit/ps/IOPSKeys.h>
+
+#include "SDL_power.h"
+
+/* CoreFoundation is so verbose... */
+#define STRMATCH(a,b) (CFStringCompare(a, b, 0) == kCFCompareEqualTo)
+#define GETVAL(k,v) \
+ CFDictionaryGetValueIfPresent(dict, CFSTR(k), (const void **) v)
+
+/* Note that AC power sources also include a laptop battery it is charging. */
+static void
+checkps(CFDictionaryRef dict, SDL_bool * have_ac, SDL_bool * have_battery,
+ SDL_bool * charging, int *seconds, int *percent)
+{
+ CFStringRef strval; /* don't CFRelease() this. */
+ CFBooleanRef bval;
+ CFNumberRef numval;
+ SDL_bool charge = SDL_FALSE;
+ SDL_bool choose = SDL_FALSE;
+ SDL_bool is_ac = SDL_FALSE;
+ int secs = -1;
+ int maxpct = -1;
+ int pct = -1;
+
+ if ((GETVAL(kIOPSIsPresentKey, &bval)) && (bval == kCFBooleanFalse)) {
+ return; /* nothing to see here. */
+ }
+
+ if (!GETVAL(kIOPSPowerSourceStateKey, &strval)) {
+ return;
+ }
+
+ if (STRMATCH(strval, CFSTR(kIOPSACPowerValue))) {
+ is_ac = *have_ac = SDL_TRUE;
+ } else if (!STRMATCH(strval, CFSTR(kIOPSBatteryPowerValue))) {
+ return; /* not a battery? */
+ }
+
+ if ((GETVAL(kIOPSIsChargingKey, &bval)) && (bval == kCFBooleanTrue)) {
+ charge = SDL_TRUE;
+ }
+
+ if (GETVAL(kIOPSMaxCapacityKey, &numval)) {
+ SInt32 val = -1;
+ CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
+ if (val > 0) {
+ *have_battery = SDL_TRUE;
+ maxpct = (int) val;
+ }
+ }
+
+ if (GETVAL(kIOPSMaxCapacityKey, &numval)) {
+ SInt32 val = -1;
+ CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
+ if (val > 0) {
+ *have_battery = SDL_TRUE;
+ maxpct = (int) val;
+ }
+ }
+
+ if (GETVAL(kIOPSTimeToEmptyKey, &numval)) {
+ SInt32 val = -1;
+ CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
+
+ /* Mac OS X reports 0 minutes until empty if you're plugged in. :( */
+ if ((val == 0) && (is_ac)) {
+ val = -1; /* !!! FIXME: calc from timeToFull and capacity? */
+ }
+
+ secs = (int) val;
+ if (secs > 0) {
+ secs *= 60; /* value is in minutes, so convert to seconds. */
+ }
+ }
+
+ if (GETVAL(kIOPSCurrentCapacityKey, &numval)) {
+ SInt32 val = -1;
+ CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
+ pct = (int) val;
+ }
+
+ if ((pct > 0) && (maxpct > 0)) {
+ pct = (int) ((((double) pct) / ((double) maxpct)) * 100.0);
+ }
+
+ if (pct > 100) {
+ pct = 100;
+ }
+
+ /*
+ * We pick the battery that claims to have the most minutes left.
+ * (failing a report of minutes, we'll take the highest percent.)
+ */
+ if ((secs < 0) && (*seconds < 0)) {
+ if ((pct < 0) && (*percent < 0)) {
+ choose = SDL_TRUE; /* at least we know there's a battery. */
+ }
+ if (pct > *percent) {
+ choose = SDL_TRUE;
+ }
+ } else if (secs > *seconds) {
+ choose = SDL_TRUE;
+ }
+
+ if (choose) {
+ *seconds = secs;
+ *percent = pct;
+ *charging = charge;
+ }
+}
+
+#undef GETVAL
+#undef STRMATCH
+
+
+SDL_bool
+SDL_GetPowerInfo_MacOSX(SDL_PowerState * state, int *seconds, int *percent)
+{
+ CFTypeRef blob = IOPSCopyPowerSourcesInfo();
+
+ *seconds = -1;
+ *percent = -1;
+ *state = SDL_POWERSTATE_UNKNOWN;
+
+ if (blob != NULL) {
+ CFArrayRef list = IOPSCopyPowerSourcesList(blob);
+ if (list != NULL) {
+ /* don't CFRelease() the list items, or dictionaries! */
+ SDL_bool have_ac = SDL_FALSE;
+ SDL_bool have_battery = SDL_FALSE;
+ SDL_bool charging = SDL_FALSE;
+ const CFIndex total = CFArrayGetCount(list);
+ CFIndex i;
+ for (i = 0; i < total; i++) {
+ CFTypeRef ps = (CFTypeRef) CFArrayGetValueAtIndex(list, i);
+ CFDictionaryRef dict =
+ IOPSGetPowerSourceDescription(blob, ps);
+ if (dict != NULL) {
+ checkps(dict, &have_ac, &have_battery, &charging,
+ seconds, percent);
+ }
+ }
+
+ if (!have_battery) {
+ *state = SDL_POWERSTATE_NO_BATTERY;
+ } else if (charging) {
+ *state = SDL_POWERSTATE_CHARGING;
+ } else if (have_ac) {
+ *state = SDL_POWERSTATE_CHARGED;
+ } else {
+ *state = SDL_POWERSTATE_ON_BATTERY;
+ }
+
+ CFRelease(list);
+ }
+ CFRelease(blob);
+ }
+
+ return SDL_TRUE; /* always the definitive answer on Mac OS X. */
+}
+
+#endif /* SDL_POWER_MACOSX */
+#endif /* SDL_POWER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/power/psp/SDL_syspower.c b/src/3rdparty/SDL2/src/power/psp/SDL_syspower.c
new file mode 100644
index 0000000..74585b2
--- /dev/null
+++ b/src/3rdparty/SDL2/src/power/psp/SDL_syspower.c
@@ -0,0 +1,68 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_POWER_DISABLED
+#if SDL_POWER_PSP
+
+#include "SDL_power.h"
+#include <psppower.h>
+
+
+SDL_bool
+SDL_GetPowerInfo_PSP(SDL_PowerState * state, int *seconds,
+ int *percent)
+{
+ int battery = scePowerIsBatteryExist();
+ int plugged = scePowerIsPowerOnline();
+ int charging = scePowerIsBatteryCharging();
+
+ *state = SDL_POWERSTATE_UNKNOWN;
+ *seconds = -1;
+ *percent = -1;
+
+ if (!battery) {
+ *state = SDL_POWERSTATE_NO_BATTERY;
+ *seconds = -1;
+ *percent = -1;
+ } else if (charging) {
+ *state = SDL_POWERSTATE_CHARGING;
+ *percent = scePowerGetBatteryLifePercent();
+ *seconds = scePowerGetBatteryLifeTime()*60;
+ } else if (plugged) {
+ *state = SDL_POWERSTATE_CHARGED;
+ *percent = scePowerGetBatteryLifePercent();
+ *seconds = scePowerGetBatteryLifeTime()*60;
+ } else {
+ *state = SDL_POWERSTATE_ON_BATTERY;
+ *percent = scePowerGetBatteryLifePercent();
+ *seconds = scePowerGetBatteryLifeTime()*60;
+ }
+
+
+ return SDL_TRUE; /* always the definitive answer on PSP. */
+}
+
+#endif /* SDL_POWER_PSP */
+#endif /* SDL_POWER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/power/uikit/SDL_syspower.h b/src/3rdparty/SDL2/src/power/uikit/SDL_syspower.h
new file mode 100644
index 0000000..4a42fd2
--- /dev/null
+++ b/src/3rdparty/SDL2/src/power/uikit/SDL_syspower.h
@@ -0,0 +1,32 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_POWER_UIKIT
+
+#include "SDL_power.h"
+
+void SDL_UIKit_UpdateBatteryMonitoring(void);
+SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState * state, int *seconds, int *percent);
+
+#endif /* SDL_POWER_UIKIT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/power/uikit/SDL_syspower.m b/src/3rdparty/SDL2/src/power/uikit/SDL_syspower.m
new file mode 100644
index 0000000..cb8a252
--- /dev/null
+++ b/src/3rdparty/SDL2/src/power/uikit/SDL_syspower.m
@@ -0,0 +1,113 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_POWER_DISABLED
+#if SDL_POWER_UIKIT
+
+#import <UIKit/UIKit.h>
+
+#include "SDL_power.h"
+#include "SDL_timer.h"
+#include "SDL_assert.h"
+#include "SDL_syspower.h"
+
+#if !TARGET_OS_TV
+/* turn off the battery monitor if it's been more than X ms since last check. */
+static const int BATTERY_MONITORING_TIMEOUT = 3000;
+static Uint32 SDL_UIKitLastPowerInfoQuery = 0;
+
+void
+SDL_UIKit_UpdateBatteryMonitoring(void)
+{
+ if (SDL_UIKitLastPowerInfoQuery) {
+ if (SDL_TICKS_PASSED(SDL_GetTicks(), SDL_UIKitLastPowerInfoQuery + BATTERY_MONITORING_TIMEOUT)) {
+ UIDevice *uidev = [UIDevice currentDevice];
+ SDL_assert([uidev isBatteryMonitoringEnabled] == YES);
+ [uidev setBatteryMonitoringEnabled:NO];
+ SDL_UIKitLastPowerInfoQuery = 0;
+ }
+ }
+}
+#else
+void
+SDL_UIKit_UpdateBatteryMonitoring(void)
+{
+ /* Do nothing. */
+}
+#endif /* !TARGET_OS_TV */
+
+SDL_bool
+SDL_GetPowerInfo_UIKit(SDL_PowerState * state, int *seconds, int *percent)
+{
+#if TARGET_OS_TV
+ *state = SDL_POWERSTATE_NO_BATTERY;
+ *seconds = -1;
+ *percent = -1;
+#else /* TARGET_OS_TV */
+ @autoreleasepool {
+ UIDevice *uidev = [UIDevice currentDevice];
+
+ if (!SDL_UIKitLastPowerInfoQuery) {
+ SDL_assert(uidev.isBatteryMonitoringEnabled == NO);
+ uidev.batteryMonitoringEnabled = YES;
+ }
+
+ /* UIKit_GL_SwapWindow() (etc) will check this and disable the battery
+ * monitoring if the app hasn't queried it in the last X seconds.
+ * Apparently monitoring the battery burns battery life. :)
+ * Apple's docs say not to monitor the battery unless you need it.
+ */
+ SDL_UIKitLastPowerInfoQuery = SDL_GetTicks();
+
+ *seconds = -1; /* no API to estimate this in UIKit. */
+
+ switch (uidev.batteryState) {
+ case UIDeviceBatteryStateCharging:
+ *state = SDL_POWERSTATE_CHARGING;
+ break;
+
+ case UIDeviceBatteryStateFull:
+ *state = SDL_POWERSTATE_CHARGED;
+ break;
+
+ case UIDeviceBatteryStateUnplugged:
+ *state = SDL_POWERSTATE_ON_BATTERY;
+ break;
+
+ case UIDeviceBatteryStateUnknown:
+ default:
+ *state = SDL_POWERSTATE_UNKNOWN;
+ break;
+ }
+
+ const float level = uidev.batteryLevel;
+ *percent = ( (level < 0.0f) ? -1 : ((int) ((level * 100) + 0.5f)) );
+ }
+#endif /* TARGET_OS_TV */
+
+ return SDL_TRUE; /* always the definitive answer on iOS. */
+}
+
+#endif /* SDL_POWER_UIKIT */
+#endif /* SDL_POWER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/power/windows/SDL_syspower.c b/src/3rdparty/SDL2/src/power/windows/SDL_syspower.c
new file mode 100644
index 0000000..be6c9d3
--- /dev/null
+++ b/src/3rdparty/SDL2/src/power/windows/SDL_syspower.c
@@ -0,0 +1,76 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_POWER_DISABLED
+#if SDL_POWER_WINDOWS
+
+#include "../../core/windows/SDL_windows.h"
+
+#include "SDL_power.h"
+
+SDL_bool
+SDL_GetPowerInfo_Windows(SDL_PowerState * state, int *seconds, int *percent)
+{
+ SYSTEM_POWER_STATUS status;
+ SDL_bool need_details = SDL_FALSE;
+
+ /* This API should exist back to Win95. */
+ if (!GetSystemPowerStatus(&status))
+ {
+ /* !!! FIXME: push GetLastError() into SDL_GetError() */
+ *state = SDL_POWERSTATE_UNKNOWN;
+ } else if (status.BatteryFlag == 0xFF) { /* unknown state */
+ *state = SDL_POWERSTATE_UNKNOWN;
+ } else if (status.BatteryFlag & (1 << 7)) { /* no battery */
+ *state = SDL_POWERSTATE_NO_BATTERY;
+ } else if (status.BatteryFlag & (1 << 3)) { /* charging */
+ *state = SDL_POWERSTATE_CHARGING;
+ need_details = SDL_TRUE;
+ } else if (status.ACLineStatus == 1) {
+ *state = SDL_POWERSTATE_CHARGED; /* on AC, not charging. */
+ need_details = SDL_TRUE;
+ } else {
+ *state = SDL_POWERSTATE_ON_BATTERY; /* not on AC. */
+ need_details = SDL_TRUE;
+ }
+
+ *percent = -1;
+ *seconds = -1;
+ if (need_details) {
+ const int pct = (int) status.BatteryLifePercent;
+ const int secs = (int) status.BatteryLifeTime;
+
+ if (pct != 255) { /* 255 == unknown */
+ *percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
+ }
+ if (secs != 0xFFFFFFFF) { /* ((DWORD)-1) == unknown */
+ *seconds = secs;
+ }
+ }
+
+ return SDL_TRUE; /* always the definitive answer on Windows. */
+}
+
+#endif /* SDL_POWER_WINDOWS */
+#endif /* SDL_POWER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/power/winrt/SDL_syspower.cpp b/src/3rdparty/SDL2/src/power/winrt/SDL_syspower.cpp
new file mode 100644
index 0000000..9f2c2ad
--- /dev/null
+++ b/src/3rdparty/SDL2/src/power/winrt/SDL_syspower.cpp
@@ -0,0 +1,44 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_POWER_DISABLED
+#if SDL_POWER_WINRT
+
+#include "SDL_power.h"
+
+extern "C"
+SDL_bool
+SDL_GetPowerInfo_WinRT(SDL_PowerState * state, int *seconds, int *percent)
+{
+ /* TODO, WinRT: Battery info is available on at least one WinRT platform (Windows Phone 8). Implement SDL_GetPowerInfo_WinRT as appropriate. */
+ /* Notes:
+ - the Win32 function, GetSystemPowerStatus, is not available for use on WinRT
+ - Windows Phone 8 has a 'Battery' class, which is documented as available for C++
+ - More info on WP8's Battery class can be found at http://msdn.microsoft.com/library/windowsphone/develop/jj207231
+ */
+ return SDL_FALSE;
+}
+
+#endif /* SDL_POWER_WINRT */
+#endif /* SDL_POWER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/SDL_d3dmath.c b/src/3rdparty/SDL2/src/render/SDL_d3dmath.c
new file mode 100644
index 0000000..47eafb2
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/SDL_d3dmath.c
@@ -0,0 +1,136 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#if (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11) && !SDL_RENDER_DISABLED
+#include "SDL_stdinc.h"
+
+#include "SDL_d3dmath.h"
+
+/* Direct3D matrix math functions */
+
+Float4X4 MatrixIdentity()
+{
+ Float4X4 m;
+ SDL_zero(m);
+ m.v._11 = 1.0f;
+ m.v._22 = 1.0f;
+ m.v._33 = 1.0f;
+ m.v._44 = 1.0f;
+ return m;
+}
+
+Float4X4 MatrixMultiply(Float4X4 M1, Float4X4 M2)
+{
+ Float4X4 m;
+ m.v._11 = M1.v._11 * M2.v._11 + M1.v._12 * M2.v._21 + M1.v._13 * M2.v._31 + M1.v._14 * M2.v._41;
+ m.v._12 = M1.v._11 * M2.v._12 + M1.v._12 * M2.v._22 + M1.v._13 * M2.v._32 + M1.v._14 * M2.v._42;
+ m.v._13 = M1.v._11 * M2.v._13 + M1.v._12 * M2.v._23 + M1.v._13 * M2.v._33 + M1.v._14 * M2.v._43;
+ m.v._14 = M1.v._11 * M2.v._14 + M1.v._12 * M2.v._24 + M1.v._13 * M2.v._34 + M1.v._14 * M2.v._44;
+ m.v._21 = M1.v._21 * M2.v._11 + M1.v._22 * M2.v._21 + M1.v._23 * M2.v._31 + M1.v._24 * M2.v._41;
+ m.v._22 = M1.v._21 * M2.v._12 + M1.v._22 * M2.v._22 + M1.v._23 * M2.v._32 + M1.v._24 * M2.v._42;
+ m.v._23 = M1.v._21 * M2.v._13 + M1.v._22 * M2.v._23 + M1.v._23 * M2.v._33 + M1.v._24 * M2.v._43;
+ m.v._24 = M1.v._21 * M2.v._14 + M1.v._22 * M2.v._24 + M1.v._23 * M2.v._34 + M1.v._24 * M2.v._44;
+ m.v._31 = M1.v._31 * M2.v._11 + M1.v._32 * M2.v._21 + M1.v._33 * M2.v._31 + M1.v._34 * M2.v._41;
+ m.v._32 = M1.v._31 * M2.v._12 + M1.v._32 * M2.v._22 + M1.v._33 * M2.v._32 + M1.v._34 * M2.v._42;
+ m.v._33 = M1.v._31 * M2.v._13 + M1.v._32 * M2.v._23 + M1.v._33 * M2.v._33 + M1.v._34 * M2.v._43;
+ m.v._34 = M1.v._31 * M2.v._14 + M1.v._32 * M2.v._24 + M1.v._33 * M2.v._34 + M1.v._34 * M2.v._44;
+ m.v._41 = M1.v._41 * M2.v._11 + M1.v._42 * M2.v._21 + M1.v._43 * M2.v._31 + M1.v._44 * M2.v._41;
+ m.v._42 = M1.v._41 * M2.v._12 + M1.v._42 * M2.v._22 + M1.v._43 * M2.v._32 + M1.v._44 * M2.v._42;
+ m.v._43 = M1.v._41 * M2.v._13 + M1.v._42 * M2.v._23 + M1.v._43 * M2.v._33 + M1.v._44 * M2.v._43;
+ m.v._44 = M1.v._41 * M2.v._14 + M1.v._42 * M2.v._24 + M1.v._43 * M2.v._34 + M1.v._44 * M2.v._44;
+ return m;
+}
+
+Float4X4 MatrixScaling(float x, float y, float z)
+{
+ Float4X4 m;
+ SDL_zero(m);
+ m.v._11 = x;
+ m.v._22 = y;
+ m.v._33 = z;
+ m.v._44 = 1.0f;
+ return m;
+}
+
+Float4X4 MatrixTranslation(float x, float y, float z)
+{
+ Float4X4 m;
+ SDL_zero(m);
+ m.v._11 = 1.0f;
+ m.v._22 = 1.0f;
+ m.v._33 = 1.0f;
+ m.v._44 = 1.0f;
+ m.v._41 = x;
+ m.v._42 = y;
+ m.v._43 = z;
+ return m;
+}
+
+Float4X4 MatrixRotationX(float r)
+{
+ float sinR = SDL_sinf(r);
+ float cosR = SDL_cosf(r);
+ Float4X4 m;
+ SDL_zero(m);
+ m.v._11 = 1.0f;
+ m.v._22 = cosR;
+ m.v._23 = sinR;
+ m.v._32 = -sinR;
+ m.v._33 = cosR;
+ m.v._44 = 1.0f;
+ return m;
+}
+
+Float4X4 MatrixRotationY(float r)
+{
+ float sinR = SDL_sinf(r);
+ float cosR = SDL_cosf(r);
+ Float4X4 m;
+ SDL_zero(m);
+ m.v._11 = cosR;
+ m.v._13 = -sinR;
+ m.v._22 = 1.0f;
+ m.v._31 = sinR;
+ m.v._33 = cosR;
+ m.v._44 = 1.0f;
+ return m;
+}
+
+Float4X4 MatrixRotationZ(float r)
+{
+ float sinR = SDL_sinf(r);
+ float cosR = SDL_cosf(r);
+ Float4X4 m;
+ SDL_zero(m);
+ m.v._11 = cosR;
+ m.v._12 = sinR;
+ m.v._21 = -sinR;
+ m.v._22 = cosR;
+ m.v._33 = 1.0f;
+ m.v._44 = 1.0f;
+ return m;
+
+}
+
+#endif /* (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11) && !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/SDL_d3dmath.h b/src/3rdparty/SDL2/src/render/SDL_d3dmath.h
new file mode 100644
index 0000000..8555a17
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/SDL_d3dmath.h
@@ -0,0 +1,72 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#if (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11) && !SDL_RENDER_DISABLED
+
+/* Direct3D matrix math functions */
+
+typedef struct
+{
+ float x;
+ float y;
+} Float2;
+
+typedef struct
+{
+ float x;
+ float y;
+ float z;
+} Float3;
+
+typedef struct
+{
+ float x;
+ float y;
+ float z;
+ float w;
+} Float4;
+
+typedef struct
+{
+ union {
+ struct {
+ float _11, _12, _13, _14;
+ float _21, _22, _23, _24;
+ float _31, _32, _33, _34;
+ float _41, _42, _43, _44;
+ } v;
+ float m[4][4];
+ };
+} Float4X4;
+
+
+Float4X4 MatrixIdentity();
+Float4X4 MatrixMultiply(Float4X4 M1, Float4X4 M2);
+Float4X4 MatrixScaling(float x, float y, float z);
+Float4X4 MatrixTranslation(float x, float y, float z);
+Float4X4 MatrixRotationX(float r);
+Float4X4 MatrixRotationY(float r);
+Float4X4 MatrixRotationZ(float r);
+
+#endif /* (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11) && !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/SDL_render.c b/src/3rdparty/SDL2/src/render/SDL_render.c
new file mode 100644
index 0000000..8cd3a7b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/SDL_render.c
@@ -0,0 +1,2234 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* The SDL 2D rendering system */
+
+#include "SDL_assert.h"
+#include "SDL_hints.h"
+#include "SDL_log.h"
+#include "SDL_render.h"
+#include "SDL_sysrender.h"
+#include "software/SDL_render_sw_c.h"
+
+
+#define SDL_WINDOWRENDERDATA "_SDL_WindowRenderData"
+
+#define CHECK_RENDERER_MAGIC(renderer, retval) \
+ SDL_assert(renderer && renderer->magic == &renderer_magic); \
+ if (!renderer || renderer->magic != &renderer_magic) { \
+ SDL_SetError("Invalid renderer"); \
+ return retval; \
+ }
+
+#define CHECK_TEXTURE_MAGIC(texture, retval) \
+ SDL_assert(texture && texture->magic == &texture_magic); \
+ if (!texture || texture->magic != &texture_magic) { \
+ SDL_SetError("Invalid texture"); \
+ return retval; \
+ }
+
+/* Predefined blend modes */
+#define SDL_COMPOSE_BLENDMODE(srcColorFactor, dstColorFactor, colorOperation, \
+ srcAlphaFactor, dstAlphaFactor, alphaOperation) \
+ (SDL_BlendMode)(((Uint32)colorOperation << 0) | \
+ ((Uint32)srcColorFactor << 4) | \
+ ((Uint32)dstColorFactor << 8) | \
+ ((Uint32)alphaOperation << 16) | \
+ ((Uint32)srcAlphaFactor << 20) | \
+ ((Uint32)dstAlphaFactor << 24))
+
+#define SDL_BLENDMODE_NONE_FULL \
+ SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ZERO, SDL_BLENDOPERATION_ADD, \
+ SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ZERO, SDL_BLENDOPERATION_ADD)
+
+#define SDL_BLENDMODE_BLEND_FULL \
+ SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_SRC_ALPHA, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD, \
+ SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD)
+
+#define SDL_BLENDMODE_ADD_FULL \
+ SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_SRC_ALPHA, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD, \
+ SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD)
+
+#define SDL_BLENDMODE_MOD_FULL \
+ SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_SRC_COLOR, SDL_BLENDOPERATION_ADD, \
+ SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD)
+
+#if !SDL_RENDER_DISABLED
+static const SDL_RenderDriver *render_drivers[] = {
+#if SDL_VIDEO_RENDER_D3D
+ &D3D_RenderDriver,
+#endif
+#if SDL_VIDEO_RENDER_D3D11
+ &D3D11_RenderDriver,
+#endif
+#if SDL_VIDEO_RENDER_OGL
+ &GL_RenderDriver,
+#endif
+#if SDL_VIDEO_RENDER_OGL_ES2
+ &GLES2_RenderDriver,
+#endif
+#if SDL_VIDEO_RENDER_OGL_ES
+ &GLES_RenderDriver,
+#endif
+#if SDL_VIDEO_RENDER_DIRECTFB
+ &DirectFB_RenderDriver,
+#endif
+#if SDL_VIDEO_RENDER_METAL
+ &METAL_RenderDriver,
+#endif
+#if SDL_VIDEO_RENDER_PSP
+ &PSP_RenderDriver,
+#endif
+ &SW_RenderDriver
+};
+#endif /* !SDL_RENDER_DISABLED */
+
+static char renderer_magic;
+static char texture_magic;
+
+static int UpdateLogicalSize(SDL_Renderer *renderer);
+
+int
+SDL_GetNumRenderDrivers(void)
+{
+#if !SDL_RENDER_DISABLED
+ return SDL_arraysize(render_drivers);
+#else
+ return 0;
+#endif
+}
+
+int
+SDL_GetRenderDriverInfo(int index, SDL_RendererInfo * info)
+{
+#if !SDL_RENDER_DISABLED
+ if (index < 0 || index >= SDL_GetNumRenderDrivers()) {
+ return SDL_SetError("index must be in the range of 0 - %d",
+ SDL_GetNumRenderDrivers() - 1);
+ }
+ *info = render_drivers[index]->info;
+ return 0;
+#else
+ return SDL_SetError("SDL not built with rendering support");
+#endif
+}
+
+static int SDLCALL
+SDL_RendererEventWatch(void *userdata, SDL_Event *event)
+{
+ SDL_Renderer *renderer = (SDL_Renderer *)userdata;
+
+ if (event->type == SDL_WINDOWEVENT) {
+ SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
+ if (window == renderer->window) {
+ if (renderer->WindowEvent) {
+ renderer->WindowEvent(renderer, &event->window);
+ }
+
+ if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
+ /* Make sure we're operating on the default render target */
+ SDL_Texture *saved_target = SDL_GetRenderTarget(renderer);
+ if (saved_target) {
+ SDL_SetRenderTarget(renderer, NULL);
+ }
+
+ if (renderer->logical_w) {
+ UpdateLogicalSize(renderer);
+ } else {
+ /* Window was resized, reset viewport */
+ int w, h;
+
+ if (renderer->GetOutputSize) {
+ renderer->GetOutputSize(renderer, &w, &h);
+ } else {
+ SDL_GetWindowSize(renderer->window, &w, &h);
+ }
+
+ if (renderer->target) {
+ renderer->viewport_backup.x = 0;
+ renderer->viewport_backup.y = 0;
+ renderer->viewport_backup.w = w;
+ renderer->viewport_backup.h = h;
+ } else {
+ renderer->viewport.x = 0;
+ renderer->viewport.y = 0;
+ renderer->viewport.w = w;
+ renderer->viewport.h = h;
+ renderer->UpdateViewport(renderer);
+ }
+ }
+
+ if (saved_target) {
+ SDL_SetRenderTarget(renderer, saved_target);
+ }
+ } else if (event->window.event == SDL_WINDOWEVENT_HIDDEN) {
+ renderer->hidden = SDL_TRUE;
+ } else if (event->window.event == SDL_WINDOWEVENT_SHOWN) {
+ if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)) {
+ renderer->hidden = SDL_FALSE;
+ }
+ } else if (event->window.event == SDL_WINDOWEVENT_MINIMIZED) {
+ renderer->hidden = SDL_TRUE;
+ } else if (event->window.event == SDL_WINDOWEVENT_RESTORED ||
+ event->window.event == SDL_WINDOWEVENT_MAXIMIZED) {
+ if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_HIDDEN)) {
+ renderer->hidden = SDL_FALSE;
+ }
+ }
+ }
+ } else if (event->type == SDL_MOUSEMOTION) {
+ SDL_Window *window = SDL_GetWindowFromID(event->motion.windowID);
+ if (renderer->logical_w && window == renderer->window) {
+ event->motion.x -= (int)(renderer->viewport.x * renderer->dpi_scale.x);
+ event->motion.y -= (int)(renderer->viewport.y * renderer->dpi_scale.y);
+ event->motion.x = (int)(event->motion.x / (renderer->scale.x * renderer->dpi_scale.x));
+ event->motion.y = (int)(event->motion.y / (renderer->scale.y * renderer->dpi_scale.y));
+ if (event->motion.xrel > 0) {
+ event->motion.xrel = SDL_max(1, (int)(event->motion.xrel / (renderer->scale.x * renderer->dpi_scale.x)));
+ } else if (event->motion.xrel < 0) {
+ event->motion.xrel = SDL_min(-1, (int)(event->motion.xrel / (renderer->scale.x * renderer->dpi_scale.x)));
+ }
+ if (event->motion.yrel > 0) {
+ event->motion.yrel = SDL_max(1, (int)(event->motion.yrel / (renderer->scale.y * renderer->dpi_scale.y)));
+ } else if (event->motion.yrel < 0) {
+ event->motion.yrel = SDL_min(-1, (int)(event->motion.yrel / (renderer->scale.y * renderer->dpi_scale.y)));
+ }
+ }
+ } else if (event->type == SDL_MOUSEBUTTONDOWN ||
+ event->type == SDL_MOUSEBUTTONUP) {
+ SDL_Window *window = SDL_GetWindowFromID(event->button.windowID);
+ if (renderer->logical_w && window == renderer->window) {
+ event->button.x -= (int)(renderer->viewport.x * renderer->dpi_scale.x);
+ event->button.y -= (int)(renderer->viewport.y * renderer->dpi_scale.y);
+ event->button.x = (int)(event->button.x / (renderer->scale.x * renderer->dpi_scale.x));
+ event->button.y = (int)(event->button.y / (renderer->scale.y * renderer->dpi_scale.y));
+ }
+ } else if (event->type == SDL_FINGERDOWN ||
+ event->type == SDL_FINGERUP ||
+ event->type == SDL_FINGERMOTION) {
+ if (renderer->logical_w) {
+ int w = 1;
+ int h = 1;
+ SDL_GetRendererOutputSize(renderer, &w, &h);
+
+ event->tfinger.x *= (w - 1);
+ event->tfinger.y *= (h - 1);
+
+ event->tfinger.x -= (renderer->viewport.x * renderer->dpi_scale.x);
+ event->tfinger.y -= (renderer->viewport.y * renderer->dpi_scale.y);
+ event->tfinger.x = (event->tfinger.x / (renderer->scale.x * renderer->dpi_scale.x));
+ event->tfinger.y = (event->tfinger.y / (renderer->scale.y * renderer->dpi_scale.y));
+
+ if (renderer->logical_w > 1) {
+ event->tfinger.x = event->tfinger.x / (renderer->logical_w - 1);
+ } else {
+ event->tfinger.x = 0.5f;
+ }
+ if (renderer->logical_h > 1) {
+ event->tfinger.y = event->tfinger.y / (renderer->logical_h - 1);
+ } else {
+ event->tfinger.y = 0.5f;
+ }
+ }
+ }
+
+ return 0;
+}
+
+int
+SDL_CreateWindowAndRenderer(int width, int height, Uint32 window_flags,
+ SDL_Window **window, SDL_Renderer **renderer)
+{
+ *window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED,
+ SDL_WINDOWPOS_UNDEFINED,
+ width, height, window_flags);
+ if (!*window) {
+ *renderer = NULL;
+ return -1;
+ }
+
+ *renderer = SDL_CreateRenderer(*window, -1, 0);
+ if (!*renderer) {
+ return -1;
+ }
+
+ return 0;
+}
+
+SDL_Renderer *
+SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
+{
+#if !SDL_RENDER_DISABLED
+ SDL_Renderer *renderer = NULL;
+ int n = SDL_GetNumRenderDrivers();
+ const char *hint;
+
+ if (!window) {
+ SDL_SetError("Invalid window");
+ return NULL;
+ }
+
+ if (SDL_GetRenderer(window)) {
+ SDL_SetError("Renderer already associated with window");
+ return NULL;
+ }
+
+ if (SDL_GetHint(SDL_HINT_RENDER_VSYNC)) {
+ if (SDL_GetHintBoolean(SDL_HINT_RENDER_VSYNC, SDL_TRUE)) {
+ flags |= SDL_RENDERER_PRESENTVSYNC;
+ } else {
+ flags &= ~SDL_RENDERER_PRESENTVSYNC;
+ }
+ }
+
+ if (index < 0) {
+ hint = SDL_GetHint(SDL_HINT_RENDER_DRIVER);
+ if (hint) {
+ for (index = 0; index < n; ++index) {
+ const SDL_RenderDriver *driver = render_drivers[index];
+
+ if (SDL_strcasecmp(hint, driver->info.name) == 0) {
+ /* Create a new renderer instance */
+ renderer = driver->CreateRenderer(window, flags);
+ break;
+ }
+ }
+ }
+
+ if (!renderer) {
+ for (index = 0; index < n; ++index) {
+ const SDL_RenderDriver *driver = render_drivers[index];
+
+ if ((driver->info.flags & flags) == flags) {
+ /* Create a new renderer instance */
+ renderer = driver->CreateRenderer(window, flags);
+ if (renderer) {
+ /* Yay, we got one! */
+ break;
+ }
+ }
+ }
+ }
+ if (index == n) {
+ SDL_SetError("Couldn't find matching render driver");
+ return NULL;
+ }
+ } else {
+ if (index >= SDL_GetNumRenderDrivers()) {
+ SDL_SetError("index must be -1 or in the range of 0 - %d",
+ SDL_GetNumRenderDrivers() - 1);
+ return NULL;
+ }
+ /* Create a new renderer instance */
+ renderer = render_drivers[index]->CreateRenderer(window, flags);
+ }
+
+ if (renderer) {
+ renderer->magic = &renderer_magic;
+ renderer->window = window;
+ renderer->scale.x = 1.0f;
+ renderer->scale.y = 1.0f;
+ renderer->dpi_scale.x = 1.0f;
+ renderer->dpi_scale.y = 1.0f;
+
+ if (window && renderer->GetOutputSize) {
+ int window_w, window_h;
+ int output_w, output_h;
+ if (renderer->GetOutputSize(renderer, &output_w, &output_h) == 0) {
+ SDL_GetWindowSize(renderer->window, &window_w, &window_h);
+ renderer->dpi_scale.x = (float)window_w / output_w;
+ renderer->dpi_scale.y = (float)window_h / output_h;
+ }
+ }
+
+ if (SDL_GetWindowFlags(window) & (SDL_WINDOW_HIDDEN|SDL_WINDOW_MINIMIZED)) {
+ renderer->hidden = SDL_TRUE;
+ } else {
+ renderer->hidden = SDL_FALSE;
+ }
+
+ SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
+
+ SDL_RenderSetViewport(renderer, NULL);
+
+ SDL_AddEventWatch(SDL_RendererEventWatch, renderer);
+
+ SDL_LogInfo(SDL_LOG_CATEGORY_RENDER,
+ "Created renderer: %s", renderer->info.name);
+ }
+ return renderer;
+#else
+ SDL_SetError("SDL not built with rendering support");
+ return NULL;
+#endif
+}
+
+SDL_Renderer *
+SDL_CreateSoftwareRenderer(SDL_Surface * surface)
+{
+#if !SDL_RENDER_DISABLED
+ SDL_Renderer *renderer;
+
+ renderer = SW_CreateRendererForSurface(surface);
+
+ if (renderer) {
+ renderer->magic = &renderer_magic;
+ renderer->scale.x = 1.0f;
+ renderer->scale.y = 1.0f;
+
+ SDL_RenderSetViewport(renderer, NULL);
+ }
+ return renderer;
+#else
+ SDL_SetError("SDL not built with rendering support");
+ return NULL;
+#endif /* !SDL_RENDER_DISABLED */
+}
+
+SDL_Renderer *
+SDL_GetRenderer(SDL_Window * window)
+{
+ return (SDL_Renderer *)SDL_GetWindowData(window, SDL_WINDOWRENDERDATA);
+}
+
+int
+SDL_GetRendererInfo(SDL_Renderer * renderer, SDL_RendererInfo * info)
+{
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ *info = renderer->info;
+ return 0;
+}
+
+int
+SDL_GetRendererOutputSize(SDL_Renderer * renderer, int *w, int *h)
+{
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ if (renderer->target) {
+ return SDL_QueryTexture(renderer->target, NULL, NULL, w, h);
+ } else if (renderer->GetOutputSize) {
+ return renderer->GetOutputSize(renderer, w, h);
+ } else if (renderer->window) {
+ SDL_GetWindowSize(renderer->window, w, h);
+ return 0;
+ } else {
+ SDL_assert(0 && "This should never happen");
+ return SDL_SetError("Renderer doesn't support querying output size");
+ }
+}
+
+static SDL_bool
+IsSupportedBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
+{
+ switch (blendMode)
+ {
+ /* These are required to be supported by all renderers */
+ case SDL_BLENDMODE_NONE:
+ case SDL_BLENDMODE_BLEND:
+ case SDL_BLENDMODE_ADD:
+ case SDL_BLENDMODE_MOD:
+ return SDL_TRUE;
+
+ default:
+ return renderer->SupportsBlendMode && renderer->SupportsBlendMode(renderer, blendMode);
+ }
+}
+
+static SDL_bool
+IsSupportedFormat(SDL_Renderer * renderer, Uint32 format)
+{
+ Uint32 i;
+
+ for (i = 0; i < renderer->info.num_texture_formats; ++i) {
+ if (renderer->info.texture_formats[i] == format) {
+ return SDL_TRUE;
+ }
+ }
+ return SDL_FALSE;
+}
+
+static Uint32
+GetClosestSupportedFormat(SDL_Renderer * renderer, Uint32 format)
+{
+ Uint32 i;
+
+ if (SDL_ISPIXELFORMAT_FOURCC(format)) {
+ /* Look for an exact match */
+ for (i = 0; i < renderer->info.num_texture_formats; ++i) {
+ if (renderer->info.texture_formats[i] == format) {
+ return renderer->info.texture_formats[i];
+ }
+ }
+ } else {
+ SDL_bool hasAlpha = SDL_ISPIXELFORMAT_ALPHA(format);
+
+ /* We just want to match the first format that has the same channels */
+ for (i = 0; i < renderer->info.num_texture_formats; ++i) {
+ if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) &&
+ SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == hasAlpha) {
+ return renderer->info.texture_formats[i];
+ }
+ }
+ }
+ return renderer->info.texture_formats[0];
+}
+
+SDL_Texture *
+SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int h)
+{
+ SDL_Texture *texture;
+
+ CHECK_RENDERER_MAGIC(renderer, NULL);
+
+ if (!format) {
+ format = renderer->info.texture_formats[0];
+ }
+ if (SDL_BYTESPERPIXEL(format) == 0) {
+ SDL_SetError("Invalid texture format");
+ return NULL;
+ }
+ if (SDL_ISPIXELFORMAT_INDEXED(format)) {
+ SDL_SetError("Palettized textures are not supported");
+ return NULL;
+ }
+ if (w <= 0 || h <= 0) {
+ SDL_SetError("Texture dimensions can't be 0");
+ return NULL;
+ }
+ if ((renderer->info.max_texture_width && w > renderer->info.max_texture_width) ||
+ (renderer->info.max_texture_height && h > renderer->info.max_texture_height)) {
+ SDL_SetError("Texture dimensions are limited to %dx%d", renderer->info.max_texture_width, renderer->info.max_texture_height);
+ return NULL;
+ }
+ texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
+ if (!texture) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ texture->magic = &texture_magic;
+ texture->format = format;
+ texture->access = access;
+ texture->w = w;
+ texture->h = h;
+ texture->r = 255;
+ texture->g = 255;
+ texture->b = 255;
+ texture->a = 255;
+ texture->renderer = renderer;
+ texture->next = renderer->textures;
+ if (renderer->textures) {
+ renderer->textures->prev = texture;
+ }
+ renderer->textures = texture;
+
+ if (IsSupportedFormat(renderer, format)) {
+ if (renderer->CreateTexture(renderer, texture) < 0) {
+ SDL_DestroyTexture(texture);
+ return NULL;
+ }
+ } else {
+ texture->native = SDL_CreateTexture(renderer,
+ GetClosestSupportedFormat(renderer, format),
+ access, w, h);
+ if (!texture->native) {
+ SDL_DestroyTexture(texture);
+ return NULL;
+ }
+
+ /* Swap textures to have texture before texture->native in the list */
+ texture->native->next = texture->next;
+ if (texture->native->next) {
+ texture->native->next->prev = texture->native;
+ }
+ texture->prev = texture->native->prev;
+ if (texture->prev) {
+ texture->prev->next = texture;
+ }
+ texture->native->prev = texture;
+ texture->next = texture->native;
+ renderer->textures = texture;
+
+ if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
+ texture->yuv = SDL_SW_CreateYUVTexture(format, w, h);
+ if (!texture->yuv) {
+ SDL_DestroyTexture(texture);
+ return NULL;
+ }
+ } else if (access == SDL_TEXTUREACCESS_STREAMING) {
+ /* The pitch is 4 byte aligned */
+ texture->pitch = (((w * SDL_BYTESPERPIXEL(format)) + 3) & ~3);
+ texture->pixels = SDL_calloc(1, texture->pitch * h);
+ if (!texture->pixels) {
+ SDL_DestroyTexture(texture);
+ return NULL;
+ }
+ }
+ }
+ return texture;
+}
+
+SDL_Texture *
+SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface)
+{
+ const SDL_PixelFormat *fmt;
+ SDL_bool needAlpha;
+ Uint32 i;
+ Uint32 format;
+ SDL_Texture *texture;
+
+ CHECK_RENDERER_MAGIC(renderer, NULL);
+
+ if (!surface) {
+ SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface");
+ return NULL;
+ }
+
+ /* See what the best texture format is */
+ fmt = surface->format;
+ if (fmt->Amask || SDL_GetColorKey(surface, NULL) == 0) {
+ needAlpha = SDL_TRUE;
+ } else {
+ needAlpha = SDL_FALSE;
+ }
+ format = renderer->info.texture_formats[0];
+ for (i = 0; i < renderer->info.num_texture_formats; ++i) {
+ if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) &&
+ SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == needAlpha) {
+ format = renderer->info.texture_formats[i];
+ break;
+ }
+ }
+
+ texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC,
+ surface->w, surface->h);
+ if (!texture) {
+ return NULL;
+ }
+
+ if (format == surface->format->format) {
+ if (SDL_MUSTLOCK(surface)) {
+ SDL_LockSurface(surface);
+ SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
+ SDL_UnlockSurface(surface);
+ } else {
+ SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
+ }
+ } else {
+ SDL_PixelFormat *dst_fmt;
+ SDL_Surface *temp = NULL;
+
+ /* Set up a destination surface for the texture update */
+ dst_fmt = SDL_AllocFormat(format);
+ if (!dst_fmt) {
+ SDL_DestroyTexture(texture);
+ return NULL;
+ }
+ temp = SDL_ConvertSurface(surface, dst_fmt, 0);
+ SDL_FreeFormat(dst_fmt);
+ if (temp) {
+ SDL_UpdateTexture(texture, NULL, temp->pixels, temp->pitch);
+ SDL_FreeSurface(temp);
+ } else {
+ SDL_DestroyTexture(texture);
+ return NULL;
+ }
+ }
+
+ {
+ Uint8 r, g, b, a;
+ SDL_BlendMode blendMode;
+
+ SDL_GetSurfaceColorMod(surface, &r, &g, &b);
+ SDL_SetTextureColorMod(texture, r, g, b);
+
+ SDL_GetSurfaceAlphaMod(surface, &a);
+ SDL_SetTextureAlphaMod(texture, a);
+
+ if (SDL_GetColorKey(surface, NULL) == 0) {
+ /* We converted to a texture with alpha format */
+ SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
+ } else {
+ SDL_GetSurfaceBlendMode(surface, &blendMode);
+ SDL_SetTextureBlendMode(texture, blendMode);
+ }
+ }
+ return texture;
+}
+
+int
+SDL_QueryTexture(SDL_Texture * texture, Uint32 * format, int *access,
+ int *w, int *h)
+{
+ CHECK_TEXTURE_MAGIC(texture, -1);
+
+ if (format) {
+ *format = texture->format;
+ }
+ if (access) {
+ *access = texture->access;
+ }
+ if (w) {
+ *w = texture->w;
+ }
+ if (h) {
+ *h = texture->h;
+ }
+ return 0;
+}
+
+int
+SDL_SetTextureColorMod(SDL_Texture * texture, Uint8 r, Uint8 g, Uint8 b)
+{
+ SDL_Renderer *renderer;
+
+ CHECK_TEXTURE_MAGIC(texture, -1);
+
+ renderer = texture->renderer;
+ if (r < 255 || g < 255 || b < 255) {
+ texture->modMode |= SDL_TEXTUREMODULATE_COLOR;
+ } else {
+ texture->modMode &= ~SDL_TEXTUREMODULATE_COLOR;
+ }
+ texture->r = r;
+ texture->g = g;
+ texture->b = b;
+ if (texture->native) {
+ return SDL_SetTextureColorMod(texture->native, r, g, b);
+ } else if (renderer->SetTextureColorMod) {
+ return renderer->SetTextureColorMod(renderer, texture);
+ } else {
+ return 0;
+ }
+}
+
+int
+SDL_GetTextureColorMod(SDL_Texture * texture, Uint8 * r, Uint8 * g,
+ Uint8 * b)
+{
+ CHECK_TEXTURE_MAGIC(texture, -1);
+
+ if (r) {
+ *r = texture->r;
+ }
+ if (g) {
+ *g = texture->g;
+ }
+ if (b) {
+ *b = texture->b;
+ }
+ return 0;
+}
+
+int
+SDL_SetTextureAlphaMod(SDL_Texture * texture, Uint8 alpha)
+{
+ SDL_Renderer *renderer;
+
+ CHECK_TEXTURE_MAGIC(texture, -1);
+
+ renderer = texture->renderer;
+ if (alpha < 255) {
+ texture->modMode |= SDL_TEXTUREMODULATE_ALPHA;
+ } else {
+ texture->modMode &= ~SDL_TEXTUREMODULATE_ALPHA;
+ }
+ texture->a = alpha;
+ if (texture->native) {
+ return SDL_SetTextureAlphaMod(texture->native, alpha);
+ } else if (renderer->SetTextureAlphaMod) {
+ return renderer->SetTextureAlphaMod(renderer, texture);
+ } else {
+ return 0;
+ }
+}
+
+int
+SDL_GetTextureAlphaMod(SDL_Texture * texture, Uint8 * alpha)
+{
+ CHECK_TEXTURE_MAGIC(texture, -1);
+
+ if (alpha) {
+ *alpha = texture->a;
+ }
+ return 0;
+}
+
+int
+SDL_SetTextureBlendMode(SDL_Texture * texture, SDL_BlendMode blendMode)
+{
+ SDL_Renderer *renderer;
+
+ CHECK_TEXTURE_MAGIC(texture, -1);
+
+ renderer = texture->renderer;
+ if (!IsSupportedBlendMode(renderer, blendMode)) {
+ return SDL_Unsupported();
+ }
+ texture->blendMode = blendMode;
+ if (texture->native) {
+ return SDL_SetTextureBlendMode(texture->native, blendMode);
+ } else if (renderer->SetTextureBlendMode) {
+ return renderer->SetTextureBlendMode(renderer, texture);
+ } else {
+ return 0;
+ }
+}
+
+int
+SDL_GetTextureBlendMode(SDL_Texture * texture, SDL_BlendMode *blendMode)
+{
+ CHECK_TEXTURE_MAGIC(texture, -1);
+
+ if (blendMode) {
+ *blendMode = texture->blendMode;
+ }
+ return 0;
+}
+
+static int
+SDL_UpdateTextureYUV(SDL_Texture * texture, const SDL_Rect * rect,
+ const void *pixels, int pitch)
+{
+ SDL_Texture *native = texture->native;
+ SDL_Rect full_rect;
+
+ if (SDL_SW_UpdateYUVTexture(texture->yuv, rect, pixels, pitch) < 0) {
+ return -1;
+ }
+
+ full_rect.x = 0;
+ full_rect.y = 0;
+ full_rect.w = texture->w;
+ full_rect.h = texture->h;
+ rect = &full_rect;
+
+ if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
+ /* We can lock the texture and copy to it */
+ void *native_pixels = NULL;
+ int native_pitch = 0;
+
+ if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
+ return -1;
+ }
+ SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
+ rect->w, rect->h, native_pixels, native_pitch);
+ SDL_UnlockTexture(native);
+ } else {
+ /* Use a temporary buffer for updating */
+ const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
+ const size_t alloclen = rect->h * temp_pitch;
+ if (alloclen > 0) {
+ void *temp_pixels = SDL_malloc(alloclen);
+ if (!temp_pixels) {
+ return SDL_OutOfMemory();
+ }
+ SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
+ rect->w, rect->h, temp_pixels, temp_pitch);
+ SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch);
+ SDL_free(temp_pixels);
+ }
+ }
+ return 0;
+}
+
+static int
+SDL_UpdateTextureNative(SDL_Texture * texture, const SDL_Rect * rect,
+ const void *pixels, int pitch)
+{
+ SDL_Texture *native = texture->native;
+
+ if (!rect->w || !rect->h) {
+ return 0; /* nothing to do. */
+ }
+
+ if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
+ /* We can lock the texture and copy to it */
+ void *native_pixels = NULL;
+ int native_pitch = 0;
+
+ if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
+ return -1;
+ }
+ SDL_ConvertPixels(rect->w, rect->h,
+ texture->format, pixels, pitch,
+ native->format, native_pixels, native_pitch);
+ SDL_UnlockTexture(native);
+ } else {
+ /* Use a temporary buffer for updating */
+ const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
+ const size_t alloclen = rect->h * temp_pitch;
+ if (alloclen > 0) {
+ void *temp_pixels = SDL_malloc(alloclen);
+ if (!temp_pixels) {
+ return SDL_OutOfMemory();
+ }
+ SDL_ConvertPixels(rect->w, rect->h,
+ texture->format, pixels, pitch,
+ native->format, temp_pixels, temp_pitch);
+ SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch);
+ SDL_free(temp_pixels);
+ }
+ }
+ return 0;
+}
+
+int
+SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect,
+ const void *pixels, int pitch)
+{
+ SDL_Renderer *renderer;
+ SDL_Rect full_rect;
+
+ CHECK_TEXTURE_MAGIC(texture, -1);
+
+ if (!pixels) {
+ return SDL_InvalidParamError("pixels");
+ }
+ if (!pitch) {
+ return SDL_InvalidParamError("pitch");
+ }
+
+ if (!rect) {
+ full_rect.x = 0;
+ full_rect.y = 0;
+ full_rect.w = texture->w;
+ full_rect.h = texture->h;
+ rect = &full_rect;
+ }
+
+ if ((rect->w == 0) || (rect->h == 0)) {
+ return 0; /* nothing to do. */
+ } else if (texture->yuv) {
+ return SDL_UpdateTextureYUV(texture, rect, pixels, pitch);
+ } else if (texture->native) {
+ return SDL_UpdateTextureNative(texture, rect, pixels, pitch);
+ } else {
+ renderer = texture->renderer;
+ return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch);
+ }
+}
+
+static int
+SDL_UpdateTextureYUVPlanar(SDL_Texture * texture, const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch)
+{
+ SDL_Texture *native = texture->native;
+ SDL_Rect full_rect;
+
+ if (SDL_SW_UpdateYUVTexturePlanar(texture->yuv, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch) < 0) {
+ return -1;
+ }
+
+ full_rect.x = 0;
+ full_rect.y = 0;
+ full_rect.w = texture->w;
+ full_rect.h = texture->h;
+ rect = &full_rect;
+
+ if (!rect->w || !rect->h) {
+ return 0; /* nothing to do. */
+ }
+
+ if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
+ /* We can lock the texture and copy to it */
+ void *native_pixels = NULL;
+ int native_pitch = 0;
+
+ if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
+ return -1;
+ }
+ SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
+ rect->w, rect->h, native_pixels, native_pitch);
+ SDL_UnlockTexture(native);
+ } else {
+ /* Use a temporary buffer for updating */
+ const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
+ const size_t alloclen = rect->h * temp_pitch;
+ if (alloclen > 0) {
+ void *temp_pixels = SDL_malloc(alloclen);
+ if (!temp_pixels) {
+ return SDL_OutOfMemory();
+ }
+ SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
+ rect->w, rect->h, temp_pixels, temp_pitch);
+ SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch);
+ SDL_free(temp_pixels);
+ }
+ }
+ return 0;
+}
+
+int SDL_UpdateYUVTexture(SDL_Texture * texture, const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch)
+{
+ SDL_Renderer *renderer;
+ SDL_Rect full_rect;
+
+ CHECK_TEXTURE_MAGIC(texture, -1);
+
+ if (!Yplane) {
+ return SDL_InvalidParamError("Yplane");
+ }
+ if (!Ypitch) {
+ return SDL_InvalidParamError("Ypitch");
+ }
+ if (!Uplane) {
+ return SDL_InvalidParamError("Uplane");
+ }
+ if (!Upitch) {
+ return SDL_InvalidParamError("Upitch");
+ }
+ if (!Vplane) {
+ return SDL_InvalidParamError("Vplane");
+ }
+ if (!Vpitch) {
+ return SDL_InvalidParamError("Vpitch");
+ }
+
+ if (texture->format != SDL_PIXELFORMAT_YV12 &&
+ texture->format != SDL_PIXELFORMAT_IYUV) {
+ return SDL_SetError("Texture format must by YV12 or IYUV");
+ }
+
+ if (!rect) {
+ full_rect.x = 0;
+ full_rect.y = 0;
+ full_rect.w = texture->w;
+ full_rect.h = texture->h;
+ rect = &full_rect;
+ }
+
+ if (!rect->w || !rect->h) {
+ return 0; /* nothing to do. */
+ }
+
+ if (texture->yuv) {
+ return SDL_UpdateTextureYUVPlanar(texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
+ } else {
+ SDL_assert(!texture->native);
+ renderer = texture->renderer;
+ SDL_assert(renderer->UpdateTextureYUV);
+ if (renderer->UpdateTextureYUV) {
+ return renderer->UpdateTextureYUV(renderer, texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
+ } else {
+ return SDL_Unsupported();
+ }
+ }
+}
+
+static int
+SDL_LockTextureYUV(SDL_Texture * texture, const SDL_Rect * rect,
+ void **pixels, int *pitch)
+{
+ return SDL_SW_LockYUVTexture(texture->yuv, rect, pixels, pitch);
+}
+
+static int
+SDL_LockTextureNative(SDL_Texture * texture, const SDL_Rect * rect,
+ void **pixels, int *pitch)
+{
+ texture->locked_rect = *rect;
+ *pixels = (void *) ((Uint8 *) texture->pixels +
+ rect->y * texture->pitch +
+ rect->x * SDL_BYTESPERPIXEL(texture->format));
+ *pitch = texture->pitch;
+ return 0;
+}
+
+int
+SDL_LockTexture(SDL_Texture * texture, const SDL_Rect * rect,
+ void **pixels, int *pitch)
+{
+ SDL_Renderer *renderer;
+ SDL_Rect full_rect;
+
+ CHECK_TEXTURE_MAGIC(texture, -1);
+
+ if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
+ return SDL_SetError("SDL_LockTexture(): texture must be streaming");
+ }
+
+ if (!rect) {
+ full_rect.x = 0;
+ full_rect.y = 0;
+ full_rect.w = texture->w;
+ full_rect.h = texture->h;
+ rect = &full_rect;
+ }
+
+ if (texture->yuv) {
+ return SDL_LockTextureYUV(texture, rect, pixels, pitch);
+ } else if (texture->native) {
+ return SDL_LockTextureNative(texture, rect, pixels, pitch);
+ } else {
+ renderer = texture->renderer;
+ return renderer->LockTexture(renderer, texture, rect, pixels, pitch);
+ }
+}
+
+static void
+SDL_UnlockTextureYUV(SDL_Texture * texture)
+{
+ SDL_Texture *native = texture->native;
+ void *native_pixels = NULL;
+ int native_pitch = 0;
+ SDL_Rect rect;
+
+ rect.x = 0;
+ rect.y = 0;
+ rect.w = texture->w;
+ rect.h = texture->h;
+
+ if (SDL_LockTexture(native, &rect, &native_pixels, &native_pitch) < 0) {
+ return;
+ }
+ SDL_SW_CopyYUVToRGB(texture->yuv, &rect, native->format,
+ rect.w, rect.h, native_pixels, native_pitch);
+ SDL_UnlockTexture(native);
+}
+
+static void
+SDL_UnlockTextureNative(SDL_Texture * texture)
+{
+ SDL_Texture *native = texture->native;
+ void *native_pixels = NULL;
+ int native_pitch = 0;
+ const SDL_Rect *rect = &texture->locked_rect;
+ const void* pixels = (void *) ((Uint8 *) texture->pixels +
+ rect->y * texture->pitch +
+ rect->x * SDL_BYTESPERPIXEL(texture->format));
+ int pitch = texture->pitch;
+
+ if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
+ return;
+ }
+ SDL_ConvertPixels(rect->w, rect->h,
+ texture->format, pixels, pitch,
+ native->format, native_pixels, native_pitch);
+ SDL_UnlockTexture(native);
+}
+
+void
+SDL_UnlockTexture(SDL_Texture * texture)
+{
+ SDL_Renderer *renderer;
+
+ CHECK_TEXTURE_MAGIC(texture, );
+
+ if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
+ return;
+ }
+ if (texture->yuv) {
+ SDL_UnlockTextureYUV(texture);
+ } else if (texture->native) {
+ SDL_UnlockTextureNative(texture);
+ } else {
+ renderer = texture->renderer;
+ renderer->UnlockTexture(renderer, texture);
+ }
+}
+
+SDL_bool
+SDL_RenderTargetSupported(SDL_Renderer *renderer)
+{
+ if (!renderer || !renderer->SetRenderTarget) {
+ return SDL_FALSE;
+ }
+ return (renderer->info.flags & SDL_RENDERER_TARGETTEXTURE) != 0;
+}
+
+int
+SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
+{
+ if (!SDL_RenderTargetSupported(renderer)) {
+ return SDL_Unsupported();
+ }
+ if (texture == renderer->target) {
+ /* Nothing to do! */
+ return 0;
+ }
+
+ /* texture == NULL is valid and means reset the target to the window */
+ if (texture) {
+ CHECK_TEXTURE_MAGIC(texture, -1);
+ if (renderer != texture->renderer) {
+ return SDL_SetError("Texture was not created with this renderer");
+ }
+ if (texture->access != SDL_TEXTUREACCESS_TARGET) {
+ return SDL_SetError("Texture not created with SDL_TEXTUREACCESS_TARGET");
+ }
+ if (texture->native) {
+ /* Always render to the native texture */
+ texture = texture->native;
+ }
+ }
+
+ if (texture && !renderer->target) {
+ /* Make a backup of the viewport */
+ renderer->viewport_backup = renderer->viewport;
+ renderer->clip_rect_backup = renderer->clip_rect;
+ renderer->clipping_enabled_backup = renderer->clipping_enabled;
+ renderer->scale_backup = renderer->scale;
+ renderer->logical_w_backup = renderer->logical_w;
+ renderer->logical_h_backup = renderer->logical_h;
+ }
+ renderer->target = texture;
+
+ if (renderer->SetRenderTarget(renderer, texture) < 0) {
+ return -1;
+ }
+
+ if (texture) {
+ renderer->viewport.x = 0;
+ renderer->viewport.y = 0;
+ renderer->viewport.w = texture->w;
+ renderer->viewport.h = texture->h;
+ SDL_zero(renderer->clip_rect);
+ renderer->clipping_enabled = SDL_FALSE;
+ renderer->scale.x = 1.0f;
+ renderer->scale.y = 1.0f;
+ renderer->logical_w = texture->w;
+ renderer->logical_h = texture->h;
+ } else {
+ renderer->viewport = renderer->viewport_backup;
+ renderer->clip_rect = renderer->clip_rect_backup;
+ renderer->clipping_enabled = renderer->clipping_enabled_backup;
+ renderer->scale = renderer->scale_backup;
+ renderer->logical_w = renderer->logical_w_backup;
+ renderer->logical_h = renderer->logical_h_backup;
+ }
+ if (renderer->UpdateViewport(renderer) < 0) {
+ return -1;
+ }
+ if (renderer->UpdateClipRect(renderer) < 0) {
+ return -1;
+ }
+
+ /* All set! */
+ return 0;
+}
+
+SDL_Texture *
+SDL_GetRenderTarget(SDL_Renderer *renderer)
+{
+ return renderer->target;
+}
+
+static int
+UpdateLogicalSize(SDL_Renderer *renderer)
+{
+ int w = 1, h = 1;
+ float want_aspect;
+ float real_aspect;
+ float scale;
+ SDL_Rect viewport;
+ /* 0 is for letterbox, 1 is for overscan */
+ int scale_policy = 0;
+ const char *hint;
+
+ if (!renderer->logical_w || !renderer->logical_h) {
+ return 0;
+ }
+ if (SDL_GetRendererOutputSize(renderer, &w, &h) < 0) {
+ return -1;
+ }
+
+ hint = SDL_GetHint(SDL_HINT_RENDER_LOGICAL_SIZE_MODE);
+ if (hint && (*hint == '1' || SDL_strcasecmp(hint, "overscan") == 0)) {
+ SDL_bool overscan_supported = SDL_TRUE;
+ /* Unfortunately, Direct3D 9 doesn't support negative viewport numbers
+ which the overscan implementation relies on.
+ */
+ if (SDL_strcasecmp(SDL_GetCurrentVideoDriver(), "direct3d") == 0) {
+ overscan_supported = SDL_FALSE;
+ }
+ if (overscan_supported) {
+ scale_policy = 1;
+ }
+ }
+
+ want_aspect = (float)renderer->logical_w / renderer->logical_h;
+ real_aspect = (float)w / h;
+
+ /* Clear the scale because we're setting viewport in output coordinates */
+ SDL_RenderSetScale(renderer, 1.0f, 1.0f);
+
+ if (renderer->integer_scale) {
+ if (want_aspect > real_aspect) {
+ scale = (float)(w / renderer->logical_w);
+ } else {
+ scale = (float)(h / renderer->logical_h);
+ }
+ viewport.w = (int)SDL_ceil(renderer->logical_w * scale);
+ viewport.x = (w - viewport.w) / 2;
+ viewport.h = (int)SDL_ceil(renderer->logical_h * scale);
+ viewport.y = (h - viewport.h) / 2;
+
+ SDL_RenderSetViewport(renderer, &viewport);
+ } else if (SDL_fabs(want_aspect-real_aspect) < 0.0001) {
+ /* The aspect ratios are the same, just scale appropriately */
+ scale = (float)w / renderer->logical_w;
+ SDL_RenderSetViewport(renderer, NULL);
+ } else if (want_aspect > real_aspect) {
+ if (scale_policy == 1) {
+ /* We want a wider aspect ratio than is available -
+ zoom so logical height matches the real height
+ and the width will grow off the screen
+ */
+ scale = (float)h / renderer->logical_h;
+ viewport.y = 0;
+ viewport.h = h;
+ viewport.w = (int)SDL_ceil(renderer->logical_w * scale);
+ viewport.x = (w - viewport.w) / 2;
+ SDL_RenderSetViewport(renderer, &viewport);
+ } else {
+ /* We want a wider aspect ratio than is available - letterbox it */
+ scale = (float)w / renderer->logical_w;
+ viewport.x = 0;
+ viewport.w = w;
+ viewport.h = (int)SDL_ceil(renderer->logical_h * scale);
+ viewport.y = (h - viewport.h) / 2;
+ SDL_RenderSetViewport(renderer, &viewport);
+ }
+ } else {
+ if (scale_policy == 1) {
+ /* We want a narrower aspect ratio than is available -
+ zoom so logical width matches the real width
+ and the height will grow off the screen
+ */
+ scale = (float)w / renderer->logical_w;
+ viewport.x = 0;
+ viewport.w = w;
+ viewport.h = (int)SDL_ceil(renderer->logical_h * scale);
+ viewport.y = (h - viewport.h) / 2;
+ SDL_RenderSetViewport(renderer, &viewport);
+ } else {
+ /* We want a narrower aspect ratio than is available - use side-bars */
+ scale = (float)h / renderer->logical_h;
+ viewport.y = 0;
+ viewport.h = h;
+ viewport.w = (int)SDL_ceil(renderer->logical_w * scale);
+ viewport.x = (w - viewport.w) / 2;
+ SDL_RenderSetViewport(renderer, &viewport);
+ }
+ }
+
+ /* Set the new scale */
+ SDL_RenderSetScale(renderer, scale, scale);
+
+ return 0;
+}
+
+int
+SDL_RenderSetLogicalSize(SDL_Renderer * renderer, int w, int h)
+{
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ if (!w || !h) {
+ /* Clear any previous logical resolution */
+ renderer->logical_w = 0;
+ renderer->logical_h = 0;
+ SDL_RenderSetViewport(renderer, NULL);
+ SDL_RenderSetScale(renderer, 1.0f, 1.0f);
+ return 0;
+ }
+
+ renderer->logical_w = w;
+ renderer->logical_h = h;
+
+ return UpdateLogicalSize(renderer);
+}
+
+void
+SDL_RenderGetLogicalSize(SDL_Renderer * renderer, int *w, int *h)
+{
+ CHECK_RENDERER_MAGIC(renderer, );
+
+ if (w) {
+ *w = renderer->logical_w;
+ }
+ if (h) {
+ *h = renderer->logical_h;
+ }
+}
+
+int
+SDL_RenderSetIntegerScale(SDL_Renderer * renderer, SDL_bool enable)
+{
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ renderer->integer_scale = enable;
+
+ return UpdateLogicalSize(renderer);
+}
+
+SDL_bool
+SDLCALL SDL_RenderGetIntegerScale(SDL_Renderer * renderer)
+{
+ CHECK_RENDERER_MAGIC(renderer, SDL_FALSE);
+
+ return renderer->integer_scale;
+}
+
+int
+SDL_RenderSetViewport(SDL_Renderer * renderer, const SDL_Rect * rect)
+{
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ if (rect) {
+ renderer->viewport.x = (int)SDL_floor(rect->x * renderer->scale.x);
+ renderer->viewport.y = (int)SDL_floor(rect->y * renderer->scale.y);
+ renderer->viewport.w = (int)SDL_ceil(rect->w * renderer->scale.x);
+ renderer->viewport.h = (int)SDL_ceil(rect->h * renderer->scale.y);
+ } else {
+ renderer->viewport.x = 0;
+ renderer->viewport.y = 0;
+ if (SDL_GetRendererOutputSize(renderer, &renderer->viewport.w, &renderer->viewport.h) < 0) {
+ return -1;
+ }
+ }
+ return renderer->UpdateViewport(renderer);
+}
+
+void
+SDL_RenderGetViewport(SDL_Renderer * renderer, SDL_Rect * rect)
+{
+ CHECK_RENDERER_MAGIC(renderer, );
+
+ if (rect) {
+ rect->x = (int)(renderer->viewport.x / renderer->scale.x);
+ rect->y = (int)(renderer->viewport.y / renderer->scale.y);
+ rect->w = (int)(renderer->viewport.w / renderer->scale.x);
+ rect->h = (int)(renderer->viewport.h / renderer->scale.y);
+ }
+}
+
+int
+SDL_RenderSetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect)
+{
+ CHECK_RENDERER_MAGIC(renderer, -1)
+
+ if (rect) {
+ renderer->clipping_enabled = SDL_TRUE;
+ renderer->clip_rect.x = (int)SDL_floor(rect->x * renderer->scale.x);
+ renderer->clip_rect.y = (int)SDL_floor(rect->y * renderer->scale.y);
+ renderer->clip_rect.w = (int)SDL_ceil(rect->w * renderer->scale.x);
+ renderer->clip_rect.h = (int)SDL_ceil(rect->h * renderer->scale.y);
+ } else {
+ renderer->clipping_enabled = SDL_FALSE;
+ SDL_zero(renderer->clip_rect);
+ }
+ return renderer->UpdateClipRect(renderer);
+}
+
+void
+SDL_RenderGetClipRect(SDL_Renderer * renderer, SDL_Rect * rect)
+{
+ CHECK_RENDERER_MAGIC(renderer, )
+
+ if (rect) {
+ rect->x = (int)(renderer->clip_rect.x / renderer->scale.x);
+ rect->y = (int)(renderer->clip_rect.y / renderer->scale.y);
+ rect->w = (int)(renderer->clip_rect.w / renderer->scale.x);
+ rect->h = (int)(renderer->clip_rect.h / renderer->scale.y);
+ }
+}
+
+SDL_bool
+SDL_RenderIsClipEnabled(SDL_Renderer * renderer)
+{
+ CHECK_RENDERER_MAGIC(renderer, SDL_FALSE)
+ return renderer->clipping_enabled;
+}
+
+int
+SDL_RenderSetScale(SDL_Renderer * renderer, float scaleX, float scaleY)
+{
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ renderer->scale.x = scaleX;
+ renderer->scale.y = scaleY;
+ return 0;
+}
+
+void
+SDL_RenderGetScale(SDL_Renderer * renderer, float *scaleX, float *scaleY)
+{
+ CHECK_RENDERER_MAGIC(renderer, );
+
+ if (scaleX) {
+ *scaleX = renderer->scale.x;
+ }
+ if (scaleY) {
+ *scaleY = renderer->scale.y;
+ }
+}
+
+int
+SDL_SetRenderDrawColor(SDL_Renderer * renderer,
+ Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ renderer->r = r;
+ renderer->g = g;
+ renderer->b = b;
+ renderer->a = a;
+ return 0;
+}
+
+int
+SDL_GetRenderDrawColor(SDL_Renderer * renderer,
+ Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a)
+{
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ if (r) {
+ *r = renderer->r;
+ }
+ if (g) {
+ *g = renderer->g;
+ }
+ if (b) {
+ *b = renderer->b;
+ }
+ if (a) {
+ *a = renderer->a;
+ }
+ return 0;
+}
+
+int
+SDL_SetRenderDrawBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
+{
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ if (!IsSupportedBlendMode(renderer, blendMode)) {
+ return SDL_Unsupported();
+ }
+ renderer->blendMode = blendMode;
+ return 0;
+}
+
+int
+SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer, SDL_BlendMode *blendMode)
+{
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ *blendMode = renderer->blendMode;
+ return 0;
+}
+
+int
+SDL_RenderClear(SDL_Renderer * renderer)
+{
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ /* Don't draw while we're hidden */
+ if (renderer->hidden) {
+ return 0;
+ }
+ return renderer->RenderClear(renderer);
+}
+
+int
+SDL_RenderDrawPoint(SDL_Renderer * renderer, int x, int y)
+{
+ SDL_Point point;
+
+ point.x = x;
+ point.y = y;
+ return SDL_RenderDrawPoints(renderer, &point, 1);
+}
+
+static int
+RenderDrawPointsWithRects(SDL_Renderer * renderer,
+ const SDL_Point * points, int count)
+{
+ SDL_FRect *frects;
+ int i;
+ int status;
+
+ frects = SDL_stack_alloc(SDL_FRect, count);
+ if (!frects) {
+ return SDL_OutOfMemory();
+ }
+ for (i = 0; i < count; ++i) {
+ frects[i].x = points[i].x * renderer->scale.x;
+ frects[i].y = points[i].y * renderer->scale.y;
+ frects[i].w = renderer->scale.x;
+ frects[i].h = renderer->scale.y;
+ }
+
+ status = renderer->RenderFillRects(renderer, frects, count);
+
+ SDL_stack_free(frects);
+
+ return status;
+}
+
+int
+SDL_RenderDrawPoints(SDL_Renderer * renderer,
+ const SDL_Point * points, int count)
+{
+ SDL_FPoint *fpoints;
+ int i;
+ int status;
+
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ if (!points) {
+ return SDL_SetError("SDL_RenderDrawPoints(): Passed NULL points");
+ }
+ if (count < 1) {
+ return 0;
+ }
+
+ /* Don't draw while we're hidden */
+ if (renderer->hidden) {
+ return 0;
+ }
+
+ if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
+ return RenderDrawPointsWithRects(renderer, points, count);
+ }
+
+ fpoints = SDL_stack_alloc(SDL_FPoint, count);
+ if (!fpoints) {
+ return SDL_OutOfMemory();
+ }
+ for (i = 0; i < count; ++i) {
+ fpoints[i].x = points[i].x * renderer->scale.x;
+ fpoints[i].y = points[i].y * renderer->scale.y;
+ }
+
+ status = renderer->RenderDrawPoints(renderer, fpoints, count);
+
+ SDL_stack_free(fpoints);
+
+ return status;
+}
+
+int
+SDL_RenderDrawLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
+{
+ SDL_Point points[2];
+
+ points[0].x = x1;
+ points[0].y = y1;
+ points[1].x = x2;
+ points[1].y = y2;
+ return SDL_RenderDrawLines(renderer, points, 2);
+}
+
+static int
+RenderDrawLinesWithRects(SDL_Renderer * renderer,
+ const SDL_Point * points, int count)
+{
+ SDL_FRect *frect;
+ SDL_FRect *frects;
+ SDL_FPoint fpoints[2];
+ int i, nrects;
+ int status;
+
+ frects = SDL_stack_alloc(SDL_FRect, count-1);
+ if (!frects) {
+ return SDL_OutOfMemory();
+ }
+
+ status = 0;
+ nrects = 0;
+ for (i = 0; i < count-1; ++i) {
+ if (points[i].x == points[i+1].x) {
+ int minY = SDL_min(points[i].y, points[i+1].y);
+ int maxY = SDL_max(points[i].y, points[i+1].y);
+
+ frect = &frects[nrects++];
+ frect->x = points[i].x * renderer->scale.x;
+ frect->y = minY * renderer->scale.y;
+ frect->w = renderer->scale.x;
+ frect->h = (maxY - minY + 1) * renderer->scale.y;
+ } else if (points[i].y == points[i+1].y) {
+ int minX = SDL_min(points[i].x, points[i+1].x);
+ int maxX = SDL_max(points[i].x, points[i+1].x);
+
+ frect = &frects[nrects++];
+ frect->x = minX * renderer->scale.x;
+ frect->y = points[i].y * renderer->scale.y;
+ frect->w = (maxX - minX + 1) * renderer->scale.x;
+ frect->h = renderer->scale.y;
+ } else {
+ /* FIXME: We can't use a rect for this line... */
+ fpoints[0].x = points[i].x * renderer->scale.x;
+ fpoints[0].y = points[i].y * renderer->scale.y;
+ fpoints[1].x = points[i+1].x * renderer->scale.x;
+ fpoints[1].y = points[i+1].y * renderer->scale.y;
+ status += renderer->RenderDrawLines(renderer, fpoints, 2);
+ }
+ }
+
+ status += renderer->RenderFillRects(renderer, frects, nrects);
+
+ SDL_stack_free(frects);
+
+ if (status < 0) {
+ status = -1;
+ }
+ return status;
+}
+
+int
+SDL_RenderDrawLines(SDL_Renderer * renderer,
+ const SDL_Point * points, int count)
+{
+ SDL_FPoint *fpoints;
+ int i;
+ int status;
+
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ if (!points) {
+ return SDL_SetError("SDL_RenderDrawLines(): Passed NULL points");
+ }
+ if (count < 2) {
+ return 0;
+ }
+
+ /* Don't draw while we're hidden */
+ if (renderer->hidden) {
+ return 0;
+ }
+
+ if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
+ return RenderDrawLinesWithRects(renderer, points, count);
+ }
+
+ fpoints = SDL_stack_alloc(SDL_FPoint, count);
+ if (!fpoints) {
+ return SDL_OutOfMemory();
+ }
+ for (i = 0; i < count; ++i) {
+ fpoints[i].x = points[i].x * renderer->scale.x;
+ fpoints[i].y = points[i].y * renderer->scale.y;
+ }
+
+ status = renderer->RenderDrawLines(renderer, fpoints, count);
+
+ SDL_stack_free(fpoints);
+
+ return status;
+}
+
+int
+SDL_RenderDrawRect(SDL_Renderer * renderer, const SDL_Rect * rect)
+{
+ SDL_Rect full_rect;
+ SDL_Point points[5];
+
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ /* If 'rect' == NULL, then outline the whole surface */
+ if (!rect) {
+ SDL_RenderGetViewport(renderer, &full_rect);
+ full_rect.x = 0;
+ full_rect.y = 0;
+ rect = &full_rect;
+ }
+
+ points[0].x = rect->x;
+ points[0].y = rect->y;
+ points[1].x = rect->x+rect->w-1;
+ points[1].y = rect->y;
+ points[2].x = rect->x+rect->w-1;
+ points[2].y = rect->y+rect->h-1;
+ points[3].x = rect->x;
+ points[3].y = rect->y+rect->h-1;
+ points[4].x = rect->x;
+ points[4].y = rect->y;
+ return SDL_RenderDrawLines(renderer, points, 5);
+}
+
+int
+SDL_RenderDrawRects(SDL_Renderer * renderer,
+ const SDL_Rect * rects, int count)
+{
+ int i;
+
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ if (!rects) {
+ return SDL_SetError("SDL_RenderDrawRects(): Passed NULL rects");
+ }
+ if (count < 1) {
+ return 0;
+ }
+
+ /* Don't draw while we're hidden */
+ if (renderer->hidden) {
+ return 0;
+ }
+
+ for (i = 0; i < count; ++i) {
+ if (SDL_RenderDrawRect(renderer, &rects[i]) < 0) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+int
+SDL_RenderFillRect(SDL_Renderer * renderer, const SDL_Rect * rect)
+{
+ SDL_Rect full_rect = { 0, 0, 0, 0 };
+
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ /* If 'rect' == NULL, then outline the whole surface */
+ if (!rect) {
+ SDL_RenderGetViewport(renderer, &full_rect);
+ full_rect.x = 0;
+ full_rect.y = 0;
+ rect = &full_rect;
+ }
+ return SDL_RenderFillRects(renderer, rect, 1);
+}
+
+int
+SDL_RenderFillRects(SDL_Renderer * renderer,
+ const SDL_Rect * rects, int count)
+{
+ SDL_FRect *frects;
+ int i;
+ int status;
+
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ if (!rects) {
+ return SDL_SetError("SDL_RenderFillRects(): Passed NULL rects");
+ }
+ if (count < 1) {
+ return 0;
+ }
+
+ /* Don't draw while we're hidden */
+ if (renderer->hidden) {
+ return 0;
+ }
+
+ frects = SDL_stack_alloc(SDL_FRect, count);
+ if (!frects) {
+ return SDL_OutOfMemory();
+ }
+ for (i = 0; i < count; ++i) {
+ frects[i].x = rects[i].x * renderer->scale.x;
+ frects[i].y = rects[i].y * renderer->scale.y;
+ frects[i].w = rects[i].w * renderer->scale.x;
+ frects[i].h = rects[i].h * renderer->scale.y;
+ }
+
+ status = renderer->RenderFillRects(renderer, frects, count);
+
+ SDL_stack_free(frects);
+
+ return status;
+}
+
+int
+SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_Rect * dstrect)
+{
+ SDL_Rect real_srcrect = { 0, 0, 0, 0 };
+ SDL_Rect real_dstrect = { 0, 0, 0, 0 };
+ SDL_FRect frect;
+
+ CHECK_RENDERER_MAGIC(renderer, -1);
+ CHECK_TEXTURE_MAGIC(texture, -1);
+
+ if (renderer != texture->renderer) {
+ return SDL_SetError("Texture was not created with this renderer");
+ }
+
+ /* Don't draw while we're hidden */
+ if (renderer->hidden) {
+ return 0;
+ }
+
+ real_srcrect.x = 0;
+ real_srcrect.y = 0;
+ real_srcrect.w = texture->w;
+ real_srcrect.h = texture->h;
+ if (srcrect) {
+ if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
+ return 0;
+ }
+ }
+
+ SDL_RenderGetViewport(renderer, &real_dstrect);
+ real_dstrect.x = 0;
+ real_dstrect.y = 0;
+ if (dstrect) {
+ if (!SDL_HasIntersection(dstrect, &real_dstrect)) {
+ return 0;
+ }
+ real_dstrect = *dstrect;
+ }
+
+ if (texture->native) {
+ texture = texture->native;
+ }
+
+ frect.x = real_dstrect.x * renderer->scale.x;
+ frect.y = real_dstrect.y * renderer->scale.y;
+ frect.w = real_dstrect.w * renderer->scale.x;
+ frect.h = real_dstrect.h * renderer->scale.y;
+
+ return renderer->RenderCopy(renderer, texture, &real_srcrect, &frect);
+}
+
+
+int
+SDL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_Rect * dstrect,
+ const double angle, const SDL_Point *center, const SDL_RendererFlip flip)
+{
+ SDL_Rect real_srcrect = { 0, 0, 0, 0 };
+ SDL_Rect real_dstrect = { 0, 0, 0, 0 };
+ SDL_Point real_center;
+ SDL_FRect frect;
+ SDL_FPoint fcenter;
+
+ if (flip == SDL_FLIP_NONE && (int)(angle/360) == angle/360) { /* fast path when we don't need rotation or flipping */
+ return SDL_RenderCopy(renderer, texture, srcrect, dstrect);
+ }
+
+ CHECK_RENDERER_MAGIC(renderer, -1);
+ CHECK_TEXTURE_MAGIC(texture, -1);
+
+ if (renderer != texture->renderer) {
+ return SDL_SetError("Texture was not created with this renderer");
+ }
+ if (!renderer->RenderCopyEx) {
+ return SDL_SetError("Renderer does not support RenderCopyEx");
+ }
+
+ /* Don't draw while we're hidden */
+ if (renderer->hidden) {
+ return 0;
+ }
+
+ real_srcrect.x = 0;
+ real_srcrect.y = 0;
+ real_srcrect.w = texture->w;
+ real_srcrect.h = texture->h;
+ if (srcrect) {
+ if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
+ return 0;
+ }
+ }
+
+ /* We don't intersect the dstrect with the viewport as RenderCopy does because of potential rotation clipping issues... TODO: should we? */
+ if (dstrect) {
+ real_dstrect = *dstrect;
+ } else {
+ SDL_RenderGetViewport(renderer, &real_dstrect);
+ real_dstrect.x = 0;
+ real_dstrect.y = 0;
+ }
+
+ if (texture->native) {
+ texture = texture->native;
+ }
+
+ if (center) {
+ real_center = *center;
+ } else {
+ real_center.x = real_dstrect.w/2;
+ real_center.y = real_dstrect.h/2;
+ }
+
+ frect.x = real_dstrect.x * renderer->scale.x;
+ frect.y = real_dstrect.y * renderer->scale.y;
+ frect.w = real_dstrect.w * renderer->scale.x;
+ frect.h = real_dstrect.h * renderer->scale.y;
+
+ fcenter.x = real_center.x * renderer->scale.x;
+ fcenter.y = real_center.y * renderer->scale.y;
+
+ return renderer->RenderCopyEx(renderer, texture, &real_srcrect, &frect, angle, &fcenter, flip);
+}
+
+int
+SDL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 format, void * pixels, int pitch)
+{
+ SDL_Rect real_rect;
+
+ CHECK_RENDERER_MAGIC(renderer, -1);
+
+ if (!renderer->RenderReadPixels) {
+ return SDL_Unsupported();
+ }
+
+ if (!format) {
+ format = SDL_GetWindowPixelFormat(renderer->window);
+ }
+
+ real_rect.x = renderer->viewport.x;
+ real_rect.y = renderer->viewport.y;
+ real_rect.w = renderer->viewport.w;
+ real_rect.h = renderer->viewport.h;
+ if (rect) {
+ if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
+ return 0;
+ }
+ if (real_rect.y > rect->y) {
+ pixels = (Uint8 *)pixels + pitch * (real_rect.y - rect->y);
+ }
+ if (real_rect.x > rect->x) {
+ int bpp = SDL_BYTESPERPIXEL(format);
+ pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x);
+ }
+ }
+
+ return renderer->RenderReadPixels(renderer, &real_rect,
+ format, pixels, pitch);
+}
+
+void
+SDL_RenderPresent(SDL_Renderer * renderer)
+{
+ CHECK_RENDERER_MAGIC(renderer, );
+
+ /* Don't draw while we're hidden */
+ if (renderer->hidden) {
+ return;
+ }
+ renderer->RenderPresent(renderer);
+}
+
+void
+SDL_DestroyTexture(SDL_Texture * texture)
+{
+ SDL_Renderer *renderer;
+
+ CHECK_TEXTURE_MAGIC(texture, );
+
+ renderer = texture->renderer;
+ if (texture == renderer->target) {
+ SDL_SetRenderTarget(renderer, NULL);
+ }
+
+ texture->magic = NULL;
+
+ if (texture->next) {
+ texture->next->prev = texture->prev;
+ }
+ if (texture->prev) {
+ texture->prev->next = texture->next;
+ } else {
+ renderer->textures = texture->next;
+ }
+
+ if (texture->native) {
+ SDL_DestroyTexture(texture->native);
+ }
+ if (texture->yuv) {
+ SDL_SW_DestroyYUVTexture(texture->yuv);
+ }
+ SDL_free(texture->pixels);
+
+ renderer->DestroyTexture(renderer, texture);
+ SDL_free(texture);
+}
+
+void
+SDL_DestroyRenderer(SDL_Renderer * renderer)
+{
+ CHECK_RENDERER_MAGIC(renderer, );
+
+ SDL_DelEventWatch(SDL_RendererEventWatch, renderer);
+
+ /* Free existing textures for this renderer */
+ while (renderer->textures) {
+ SDL_Texture *tex = renderer->textures; (void) tex;
+ SDL_DestroyTexture(renderer->textures);
+ SDL_assert(tex != renderer->textures); /* satisfy static analysis. */
+ }
+
+ if (renderer->window) {
+ SDL_SetWindowData(renderer->window, SDL_WINDOWRENDERDATA, NULL);
+ }
+
+ /* It's no longer magical... */
+ renderer->magic = NULL;
+
+ /* Free the renderer instance */
+ renderer->DestroyRenderer(renderer);
+}
+
+int SDL_GL_BindTexture(SDL_Texture *texture, float *texw, float *texh)
+{
+ SDL_Renderer *renderer;
+
+ CHECK_TEXTURE_MAGIC(texture, -1);
+ renderer = texture->renderer;
+ if (texture->native) {
+ return SDL_GL_BindTexture(texture->native, texw, texh);
+ } else if (renderer && renderer->GL_BindTexture) {
+ return renderer->GL_BindTexture(renderer, texture, texw, texh);
+ } else {
+ return SDL_Unsupported();
+ }
+}
+
+int SDL_GL_UnbindTexture(SDL_Texture *texture)
+{
+ SDL_Renderer *renderer;
+
+ CHECK_TEXTURE_MAGIC(texture, -1);
+ renderer = texture->renderer;
+ if (texture->native) {
+ return SDL_GL_UnbindTexture(texture->native);
+ } else if (renderer && renderer->GL_UnbindTexture) {
+ return renderer->GL_UnbindTexture(renderer, texture);
+ }
+
+ return SDL_Unsupported();
+}
+
+void *
+SDL_RenderGetMetalLayer(SDL_Renderer * renderer)
+{
+ CHECK_RENDERER_MAGIC(renderer, NULL);
+
+ if (renderer->GetMetalLayer) {
+ return renderer->GetMetalLayer(renderer);
+ }
+ return NULL;
+}
+
+void *
+SDL_RenderGetMetalCommandEncoder(SDL_Renderer * renderer)
+{
+ CHECK_RENDERER_MAGIC(renderer, NULL);
+
+ if (renderer->GetMetalCommandEncoder) {
+ return renderer->GetMetalCommandEncoder(renderer);
+ }
+ return NULL;
+}
+
+static SDL_BlendMode
+SDL_GetShortBlendMode(SDL_BlendMode blendMode)
+{
+ if (blendMode == SDL_BLENDMODE_NONE_FULL) {
+ return SDL_BLENDMODE_NONE;
+ }
+ if (blendMode == SDL_BLENDMODE_BLEND_FULL) {
+ return SDL_BLENDMODE_BLEND;
+ }
+ if (blendMode == SDL_BLENDMODE_ADD_FULL) {
+ return SDL_BLENDMODE_ADD;
+ }
+ if (blendMode == SDL_BLENDMODE_MOD_FULL) {
+ return SDL_BLENDMODE_MOD;
+ }
+ return blendMode;
+}
+
+static SDL_BlendMode
+SDL_GetLongBlendMode(SDL_BlendMode blendMode)
+{
+ if (blendMode == SDL_BLENDMODE_NONE) {
+ return SDL_BLENDMODE_NONE_FULL;
+ }
+ if (blendMode == SDL_BLENDMODE_BLEND) {
+ return SDL_BLENDMODE_BLEND_FULL;
+ }
+ if (blendMode == SDL_BLENDMODE_ADD) {
+ return SDL_BLENDMODE_ADD_FULL;
+ }
+ if (blendMode == SDL_BLENDMODE_MOD) {
+ return SDL_BLENDMODE_MOD_FULL;
+ }
+ return blendMode;
+}
+
+SDL_BlendMode
+SDL_ComposeCustomBlendMode(SDL_BlendFactor srcColorFactor, SDL_BlendFactor dstColorFactor,
+ SDL_BlendOperation colorOperation,
+ SDL_BlendFactor srcAlphaFactor, SDL_BlendFactor dstAlphaFactor,
+ SDL_BlendOperation alphaOperation)
+{
+ SDL_BlendMode blendMode = SDL_COMPOSE_BLENDMODE(srcColorFactor, dstColorFactor, colorOperation,
+ srcAlphaFactor, dstAlphaFactor, alphaOperation);
+ return SDL_GetShortBlendMode(blendMode);
+}
+
+SDL_BlendFactor
+SDL_GetBlendModeSrcColorFactor(SDL_BlendMode blendMode)
+{
+ blendMode = SDL_GetLongBlendMode(blendMode);
+ return (SDL_BlendFactor)(((Uint32)blendMode >> 4) & 0xF);
+}
+
+SDL_BlendFactor
+SDL_GetBlendModeDstColorFactor(SDL_BlendMode blendMode)
+{
+ blendMode = SDL_GetLongBlendMode(blendMode);
+ return (SDL_BlendFactor)(((Uint32)blendMode >> 8) & 0xF);
+}
+
+SDL_BlendOperation
+SDL_GetBlendModeColorOperation(SDL_BlendMode blendMode)
+{
+ blendMode = SDL_GetLongBlendMode(blendMode);
+ return (SDL_BlendOperation)(((Uint32)blendMode >> 0) & 0xF);
+}
+
+SDL_BlendFactor
+SDL_GetBlendModeSrcAlphaFactor(SDL_BlendMode blendMode)
+{
+ blendMode = SDL_GetLongBlendMode(blendMode);
+ return (SDL_BlendFactor)(((Uint32)blendMode >> 20) & 0xF);
+}
+
+SDL_BlendFactor
+SDL_GetBlendModeDstAlphaFactor(SDL_BlendMode blendMode)
+{
+ blendMode = SDL_GetLongBlendMode(blendMode);
+ return (SDL_BlendFactor)(((Uint32)blendMode >> 24) & 0xF);
+}
+
+SDL_BlendOperation
+SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode)
+{
+ blendMode = SDL_GetLongBlendMode(blendMode);
+ return (SDL_BlendOperation)(((Uint32)blendMode >> 16) & 0xF);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/SDL_sysrender.h b/src/3rdparty/SDL2/src/render/SDL_sysrender.h
new file mode 100644
index 0000000..f0f54c8
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/SDL_sysrender.h
@@ -0,0 +1,204 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#ifndef SDL_sysrender_h_
+#define SDL_sysrender_h_
+
+#include "SDL_render.h"
+#include "SDL_events.h"
+#include "SDL_yuv_sw_c.h"
+
+/* The SDL 2D rendering system */
+
+typedef struct SDL_RenderDriver SDL_RenderDriver;
+
+typedef struct
+{
+ float x;
+ float y;
+} SDL_FPoint;
+
+typedef struct
+{
+ float x;
+ float y;
+ float w;
+ float h;
+} SDL_FRect;
+
+/* Define the SDL texture structure */
+struct SDL_Texture
+{
+ const void *magic;
+ Uint32 format; /**< The pixel format of the texture */
+ int access; /**< SDL_TextureAccess */
+ int w; /**< The width of the texture */
+ int h; /**< The height of the texture */
+ int modMode; /**< The texture modulation mode */
+ SDL_BlendMode blendMode; /**< The texture blend mode */
+ Uint8 r, g, b, a; /**< Texture modulation values */
+
+ SDL_Renderer *renderer;
+
+ /* Support for formats not supported directly by the renderer */
+ SDL_Texture *native;
+ SDL_SW_YUVTexture *yuv;
+ void *pixels;
+ int pitch;
+ SDL_Rect locked_rect;
+
+ void *driverdata; /**< Driver specific texture representation */
+
+ SDL_Texture *prev;
+ SDL_Texture *next;
+};
+
+/* Define the SDL renderer structure */
+struct SDL_Renderer
+{
+ const void *magic;
+
+ void (*WindowEvent) (SDL_Renderer * renderer, const SDL_WindowEvent *event);
+ int (*GetOutputSize) (SDL_Renderer * renderer, int *w, int *h);
+ SDL_bool (*SupportsBlendMode)(SDL_Renderer * renderer, SDL_BlendMode blendMode);
+ int (*CreateTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
+ int (*SetTextureColorMod) (SDL_Renderer * renderer,
+ SDL_Texture * texture);
+ int (*SetTextureAlphaMod) (SDL_Renderer * renderer,
+ SDL_Texture * texture);
+ int (*SetTextureBlendMode) (SDL_Renderer * renderer,
+ SDL_Texture * texture);
+ int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, const void *pixels,
+ int pitch);
+ int (*UpdateTextureYUV) (SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch);
+ int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, void **pixels, int *pitch);
+ void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
+ int (*SetRenderTarget) (SDL_Renderer * renderer, SDL_Texture * texture);
+ int (*UpdateViewport) (SDL_Renderer * renderer);
+ int (*UpdateClipRect) (SDL_Renderer * renderer);
+ int (*RenderClear) (SDL_Renderer * renderer);
+ int (*RenderDrawPoints) (SDL_Renderer * renderer, const SDL_FPoint * points,
+ int count);
+ int (*RenderDrawLines) (SDL_Renderer * renderer, const SDL_FPoint * points,
+ int count);
+ int (*RenderFillRects) (SDL_Renderer * renderer, const SDL_FRect * rects,
+ int count);
+ int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect);
+ int (*RenderCopyEx) (SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcquad, const SDL_FRect * dstrect,
+ const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip);
+ int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 format, void * pixels, int pitch);
+ void (*RenderPresent) (SDL_Renderer * renderer);
+ void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
+
+ void (*DestroyRenderer) (SDL_Renderer * renderer);
+
+ int (*GL_BindTexture) (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh);
+ int (*GL_UnbindTexture) (SDL_Renderer * renderer, SDL_Texture *texture);
+
+ void *(*GetMetalLayer) (SDL_Renderer * renderer);
+ void *(*GetMetalCommandEncoder) (SDL_Renderer * renderer);
+
+ /* The current renderer info */
+ SDL_RendererInfo info;
+
+ /* The window associated with the renderer */
+ SDL_Window *window;
+ SDL_bool hidden;
+
+ /* The logical resolution for rendering */
+ int logical_w;
+ int logical_h;
+ int logical_w_backup;
+ int logical_h_backup;
+
+ /* Whether or not to force the viewport to even integer intervals */
+ SDL_bool integer_scale;
+
+ /* The drawable area within the window */
+ SDL_Rect viewport;
+ SDL_Rect viewport_backup;
+
+ /* The clip rectangle within the window */
+ SDL_Rect clip_rect;
+ SDL_Rect clip_rect_backup;
+
+ /* Wether or not the clipping rectangle is used. */
+ SDL_bool clipping_enabled;
+ SDL_bool clipping_enabled_backup;
+
+ /* The render output coordinate scale */
+ SDL_FPoint scale;
+ SDL_FPoint scale_backup;
+
+ /* The pixel to point coordinate scale */
+ SDL_FPoint dpi_scale;
+
+ /* The list of textures */
+ SDL_Texture *textures;
+ SDL_Texture *target;
+
+ Uint8 r, g, b, a; /**< Color for drawing operations values */
+ SDL_BlendMode blendMode; /**< The drawing blend mode */
+
+ void *driverdata;
+};
+
+/* Define the SDL render driver structure */
+struct SDL_RenderDriver
+{
+ SDL_Renderer *(*CreateRenderer) (SDL_Window * window, Uint32 flags);
+
+ /* Info about the renderer capabilities */
+ SDL_RendererInfo info;
+};
+
+/* Not all of these are available in a given build. Use #ifdefs, etc. */
+extern SDL_RenderDriver D3D_RenderDriver;
+extern SDL_RenderDriver D3D11_RenderDriver;
+extern SDL_RenderDriver GL_RenderDriver;
+extern SDL_RenderDriver GLES2_RenderDriver;
+extern SDL_RenderDriver GLES_RenderDriver;
+extern SDL_RenderDriver DirectFB_RenderDriver;
+extern SDL_RenderDriver METAL_RenderDriver;
+extern SDL_RenderDriver PSP_RenderDriver;
+extern SDL_RenderDriver SW_RenderDriver;
+
+/* Blend mode functions */
+extern SDL_BlendFactor SDL_GetBlendModeSrcColorFactor(SDL_BlendMode blendMode);
+extern SDL_BlendFactor SDL_GetBlendModeDstColorFactor(SDL_BlendMode blendMode);
+extern SDL_BlendOperation SDL_GetBlendModeColorOperation(SDL_BlendMode blendMode);
+extern SDL_BlendFactor SDL_GetBlendModeSrcAlphaFactor(SDL_BlendMode blendMode);
+extern SDL_BlendFactor SDL_GetBlendModeDstAlphaFactor(SDL_BlendMode blendMode);
+extern SDL_BlendOperation SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode);
+
+#endif /* SDL_sysrender_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/SDL_yuv_sw.c b/src/3rdparty/SDL2/src/render/SDL_yuv_sw.c
new file mode 100644
index 0000000..c227cdc
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/SDL_yuv_sw.c
@@ -0,0 +1,414 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* This is the software implementation of the YUV texture support */
+
+#include "SDL_assert.h"
+
+#include "SDL_yuv_sw_c.h"
+
+
+SDL_SW_YUVTexture *
+SDL_SW_CreateYUVTexture(Uint32 format, int w, int h)
+{
+ SDL_SW_YUVTexture *swdata;
+
+ switch (format) {
+ case SDL_PIXELFORMAT_YV12:
+ case SDL_PIXELFORMAT_IYUV:
+ case SDL_PIXELFORMAT_YUY2:
+ case SDL_PIXELFORMAT_UYVY:
+ case SDL_PIXELFORMAT_YVYU:
+ case SDL_PIXELFORMAT_NV12:
+ case SDL_PIXELFORMAT_NV21:
+ break;
+ default:
+ SDL_SetError("Unsupported YUV format");
+ return NULL;
+ }
+
+ swdata = (SDL_SW_YUVTexture *) SDL_calloc(1, sizeof(*swdata));
+ if (!swdata) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ swdata->format = format;
+ swdata->target_format = SDL_PIXELFORMAT_UNKNOWN;
+ swdata->w = w;
+ swdata->h = h;
+ {
+ const int sz_plane = w * h;
+ const int sz_plane_chroma = ((w + 1) / 2) * ((h + 1) / 2);
+ const int sz_plane_packed = ((w + 1) / 2) * h;
+ int dst_size = 0;
+ switch(format)
+ {
+ case SDL_PIXELFORMAT_YV12: /**< Planar mode: Y + V + U (3 planes) */
+ case SDL_PIXELFORMAT_IYUV: /**< Planar mode: Y + U + V (3 planes) */
+ dst_size = sz_plane + sz_plane_chroma + sz_plane_chroma;
+ break;
+
+ case SDL_PIXELFORMAT_YUY2: /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
+ case SDL_PIXELFORMAT_UYVY: /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
+ case SDL_PIXELFORMAT_YVYU: /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
+ dst_size = 4 * sz_plane_packed;
+ break;
+
+ case SDL_PIXELFORMAT_NV12: /**< Planar mode: Y + U/V interleaved (2 planes) */
+ case SDL_PIXELFORMAT_NV21: /**< Planar mode: Y + V/U interleaved (2 planes) */
+ dst_size = sz_plane + sz_plane_chroma + sz_plane_chroma;
+ break;
+
+ default:
+ SDL_assert(0 && "We should never get here (caught above)");
+ break;
+ }
+ swdata->pixels = (Uint8 *) SDL_malloc(dst_size);
+ if (!swdata->pixels) {
+ SDL_SW_DestroyYUVTexture(swdata);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ }
+
+ /* Find the pitch and offset values for the texture */
+ switch (format) {
+ case SDL_PIXELFORMAT_YV12:
+ case SDL_PIXELFORMAT_IYUV:
+ swdata->pitches[0] = w;
+ swdata->pitches[1] = (swdata->pitches[0] + 1) / 2;
+ swdata->pitches[2] = (swdata->pitches[0] + 1) / 2;
+ swdata->planes[0] = swdata->pixels;
+ swdata->planes[1] = swdata->planes[0] + swdata->pitches[0] * h;
+ swdata->planes[2] = swdata->planes[1] + swdata->pitches[1] * ((h + 1) / 2);
+ break;
+ case SDL_PIXELFORMAT_YUY2:
+ case SDL_PIXELFORMAT_UYVY:
+ case SDL_PIXELFORMAT_YVYU:
+ swdata->pitches[0] = ((w + 1) / 2) * 4;
+ swdata->planes[0] = swdata->pixels;
+ break;
+
+ case SDL_PIXELFORMAT_NV12:
+ case SDL_PIXELFORMAT_NV21:
+ swdata->pitches[0] = w;
+ swdata->pitches[1] = 2 * ((swdata->pitches[0] + 1) / 2);
+ swdata->planes[0] = swdata->pixels;
+ swdata->planes[1] = swdata->planes[0] + swdata->pitches[0] * h;
+ break;
+
+ default:
+ SDL_assert(0 && "We should never get here (caught above)");
+ break;
+ }
+
+ /* We're all done.. */
+ return (swdata);
+}
+
+int
+SDL_SW_QueryYUVTexturePixels(SDL_SW_YUVTexture * swdata, void **pixels,
+ int *pitch)
+{
+ *pixels = swdata->planes[0];
+ *pitch = swdata->pitches[0];
+ return 0;
+}
+
+int
+SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
+ const void *pixels, int pitch)
+{
+ switch (swdata->format) {
+ case SDL_PIXELFORMAT_YV12:
+ case SDL_PIXELFORMAT_IYUV:
+ if (rect->x == 0 && rect->y == 0 &&
+ rect->w == swdata->w && rect->h == swdata->h) {
+ SDL_memcpy(swdata->pixels, pixels,
+ (swdata->h * swdata->w) + 2* ((swdata->h + 1) /2) * ((swdata->w + 1) / 2));
+ } else {
+ Uint8 *src, *dst;
+ int row;
+ size_t length;
+
+ /* Copy the Y plane */
+ src = (Uint8 *) pixels;
+ dst = swdata->pixels + rect->y * swdata->w + rect->x;
+ length = rect->w;
+ for (row = 0; row < rect->h; ++row) {
+ SDL_memcpy(dst, src, length);
+ src += pitch;
+ dst += swdata->w;
+ }
+
+ /* Copy the next plane */
+ src = (Uint8 *) pixels + rect->h * pitch;
+ dst = swdata->pixels + swdata->h * swdata->w;
+ dst += rect->y/2 * ((swdata->w + 1) / 2) + rect->x/2;
+ length = (rect->w + 1) / 2;
+ for (row = 0; row < (rect->h + 1)/2; ++row) {
+ SDL_memcpy(dst, src, length);
+ src += (pitch + 1)/2;
+ dst += (swdata->w + 1)/2;
+ }
+
+ /* Copy the next plane */
+ src = (Uint8 *) pixels + rect->h * pitch + ((rect->h + 1) / 2) * ((pitch + 1) / 2);
+ dst = swdata->pixels + swdata->h * swdata->w +
+ ((swdata->h + 1)/2) * ((swdata->w+1) / 2);
+ dst += rect->y/2 * ((swdata->w + 1)/2) + rect->x/2;
+ length = (rect->w + 1) / 2;
+ for (row = 0; row < (rect->h + 1)/2; ++row) {
+ SDL_memcpy(dst, src, length);
+ src += (pitch + 1)/2;
+ dst += (swdata->w + 1)/2;
+ }
+ }
+ break;
+ case SDL_PIXELFORMAT_YUY2:
+ case SDL_PIXELFORMAT_UYVY:
+ case SDL_PIXELFORMAT_YVYU:
+ {
+ Uint8 *src, *dst;
+ int row;
+ size_t length;
+
+ src = (Uint8 *) pixels;
+ dst =
+ swdata->planes[0] + rect->y * swdata->pitches[0] +
+ rect->x * 2;
+ length = 4 * ((rect->w + 1) / 2);
+ for (row = 0; row < rect->h; ++row) {
+ SDL_memcpy(dst, src, length);
+ src += pitch;
+ dst += swdata->pitches[0];
+ }
+ }
+ break;
+ case SDL_PIXELFORMAT_NV12:
+ case SDL_PIXELFORMAT_NV21:
+ {
+ if (rect->x == 0 && rect->y == 0 && rect->w == swdata->w && rect->h == swdata->h) {
+ SDL_memcpy(swdata->pixels, pixels,
+ (swdata->h * swdata->w) + 2* ((swdata->h + 1) /2) * ((swdata->w + 1) / 2));
+ } else {
+
+ Uint8 *src, *dst;
+ int row;
+ size_t length;
+
+ /* Copy the Y plane */
+ src = (Uint8 *) pixels;
+ dst = swdata->pixels + rect->y * swdata->w + rect->x;
+ length = rect->w;
+ for (row = 0; row < rect->h; ++row) {
+ SDL_memcpy(dst, src, length);
+ src += pitch;
+ dst += swdata->w;
+ }
+
+ /* Copy the next plane */
+ src = (Uint8 *) pixels + rect->h * pitch;
+ dst = swdata->pixels + swdata->h * swdata->w;
+ dst += 2 * ((rect->y + 1)/2) * ((swdata->w + 1) / 2) + 2 * (rect->x/2);
+ length = 2 * ((rect->w + 1) / 2);
+ for (row = 0; row < (rect->h + 1)/2; ++row) {
+ SDL_memcpy(dst, src, length);
+ src += 2 * ((pitch + 1)/2);
+ dst += 2 * ((swdata->w + 1)/2);
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+int
+SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch)
+{
+ const Uint8 *src;
+ Uint8 *dst;
+ int row;
+ size_t length;
+
+ /* Copy the Y plane */
+ src = Yplane;
+ dst = swdata->pixels + rect->y * swdata->w + rect->x;
+ length = rect->w;
+ for (row = 0; row < rect->h; ++row) {
+ SDL_memcpy(dst, src, length);
+ src += Ypitch;
+ dst += swdata->w;
+ }
+
+ /* Copy the U plane */
+ src = Uplane;
+ if (swdata->format == SDL_PIXELFORMAT_IYUV) {
+ dst = swdata->pixels + swdata->h * swdata->w;
+ } else {
+ dst = swdata->pixels + swdata->h * swdata->w +
+ ((swdata->h + 1) / 2) * ((swdata->w + 1) / 2);
+ }
+ dst += rect->y/2 * ((swdata->w + 1)/2) + rect->x/2;
+ length = (rect->w + 1) / 2;
+ for (row = 0; row < (rect->h + 1)/2; ++row) {
+ SDL_memcpy(dst, src, length);
+ src += Upitch;
+ dst += (swdata->w + 1)/2;
+ }
+
+ /* Copy the V plane */
+ src = Vplane;
+ if (swdata->format == SDL_PIXELFORMAT_YV12) {
+ dst = swdata->pixels + swdata->h * swdata->w;
+ } else {
+ dst = swdata->pixels + swdata->h * swdata->w +
+ ((swdata->h + 1) / 2) * ((swdata->w + 1) / 2);
+ }
+ dst += rect->y/2 * ((swdata->w + 1)/2) + rect->x/2;
+ length = (rect->w + 1) / 2;
+ for (row = 0; row < (rect->h + 1)/2; ++row) {
+ SDL_memcpy(dst, src, length);
+ src += Vpitch;
+ dst += (swdata->w + 1)/2;
+ }
+ return 0;
+}
+
+int
+SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
+ void **pixels, int *pitch)
+{
+ switch (swdata->format) {
+ case SDL_PIXELFORMAT_YV12:
+ case SDL_PIXELFORMAT_IYUV:
+ case SDL_PIXELFORMAT_NV12:
+ case SDL_PIXELFORMAT_NV21:
+ if (rect
+ && (rect->x != 0 || rect->y != 0 || rect->w != swdata->w
+ || rect->h != swdata->h)) {
+ return SDL_SetError
+ ("YV12, IYUV, NV12, NV21 textures only support full surface locks");
+ }
+ break;
+ }
+
+ if (rect) {
+ *pixels = swdata->planes[0] + rect->y * swdata->pitches[0] + rect->x * 2;
+ } else {
+ *pixels = swdata->planes[0];
+ }
+ *pitch = swdata->pitches[0];
+ return 0;
+}
+
+void
+SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture * swdata)
+{
+}
+
+int
+SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect,
+ Uint32 target_format, int w, int h, void *pixels,
+ int pitch)
+{
+ int stretch;
+
+ /* Make sure we're set up to display in the desired format */
+ if (target_format != swdata->target_format && swdata->display) {
+ SDL_FreeSurface(swdata->display);
+ swdata->display = NULL;
+ }
+
+ stretch = 0;
+ if (srcrect->x || srcrect->y || srcrect->w < swdata->w || srcrect->h < swdata->h) {
+ /* The source rectangle has been clipped.
+ Using a scratch surface is easier than adding clipped
+ source support to all the blitters, plus that would
+ slow them down in the general unclipped case.
+ */
+ stretch = 1;
+ } else if ((srcrect->w != w) || (srcrect->h != h)) {
+ stretch = 1;
+ }
+ if (stretch) {
+ int bpp;
+ Uint32 Rmask, Gmask, Bmask, Amask;
+
+ if (swdata->display) {
+ swdata->display->w = w;
+ swdata->display->h = h;
+ swdata->display->pixels = pixels;
+ swdata->display->pitch = pitch;
+ } else {
+ /* This must have succeeded in SDL_SW_SetupYUVDisplay() earlier */
+ SDL_PixelFormatEnumToMasks(target_format, &bpp, &Rmask, &Gmask,
+ &Bmask, &Amask);
+ swdata->display =
+ SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, Rmask,
+ Gmask, Bmask, Amask);
+ if (!swdata->display) {
+ return (-1);
+ }
+ }
+ if (!swdata->stretch) {
+ /* This must have succeeded in SDL_SW_SetupYUVDisplay() earlier */
+ SDL_PixelFormatEnumToMasks(target_format, &bpp, &Rmask, &Gmask,
+ &Bmask, &Amask);
+ swdata->stretch =
+ SDL_CreateRGBSurface(0, swdata->w, swdata->h, bpp, Rmask,
+ Gmask, Bmask, Amask);
+ if (!swdata->stretch) {
+ return (-1);
+ }
+ }
+ pixels = swdata->stretch->pixels;
+ pitch = swdata->stretch->pitch;
+ }
+ if (SDL_ConvertPixels(swdata->w, swdata->h, swdata->format,
+ swdata->planes[0], swdata->pitches[0],
+ target_format, pixels, pitch) < 0) {
+ return -1;
+ }
+ if (stretch) {
+ SDL_Rect rect = *srcrect;
+ SDL_SoftStretch(swdata->stretch, &rect, swdata->display, NULL);
+ }
+ return 0;
+}
+
+void
+SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture * swdata)
+{
+ if (swdata) {
+ SDL_free(swdata->pixels);
+ SDL_FreeSurface(swdata->stretch);
+ SDL_FreeSurface(swdata->display);
+ SDL_free(swdata);
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/SDL_yuv_sw_c.h b/src/3rdparty/SDL2/src/render/SDL_yuv_sw_c.h
new file mode 100644
index 0000000..0dfb5db
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/SDL_yuv_sw_c.h
@@ -0,0 +1,67 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "SDL_video.h"
+
+/* This is the software implementation of the YUV texture support */
+
+struct SDL_SW_YUVTexture
+{
+ Uint32 format;
+ Uint32 target_format;
+ int w, h;
+ Uint8 *pixels;
+
+ /* These are just so we don't have to allocate them separately */
+ Uint16 pitches[3];
+ Uint8 *planes[3];
+
+ /* This is a temporary surface in case we have to stretch copy */
+ SDL_Surface *stretch;
+ SDL_Surface *display;
+};
+
+typedef struct SDL_SW_YUVTexture SDL_SW_YUVTexture;
+
+SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(Uint32 format, int w, int h);
+int SDL_SW_QueryYUVTexturePixels(SDL_SW_YUVTexture * swdata, void **pixels,
+ int *pitch);
+int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
+ const void *pixels, int pitch);
+int SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch);
+int SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
+ void **pixels, int *pitch);
+void SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture * swdata);
+int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect,
+ Uint32 target_format, int w, int h, void *pixels,
+ int pitch);
+void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture * swdata);
+
+/* FIXME: This breaks on various versions of GCC and should be rewritten using intrinsics */
+#if 0 /* (__GNUC__ > 2) && defined(__i386__) && __OPTIMIZE__ && SDL_ASSEMBLY_ROUTINES && !defined(__clang__) */
+#define USE_MMX_ASSEMBLY 1
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/direct3d/SDL_render_d3d.c b/src/3rdparty/SDL2/src/render/direct3d/SDL_render_d3d.c
new file mode 100644
index 0000000..d3be571
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/direct3d/SDL_render_d3d.c
@@ -0,0 +1,1825 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "SDL_render.h"
+#include "SDL_system.h"
+
+#if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
+
+#include "../../core/windows/SDL_windows.h"
+
+#include "SDL_hints.h"
+#include "SDL_loadso.h"
+#include "SDL_syswm.h"
+#include "../SDL_sysrender.h"
+#include "../SDL_d3dmath.h"
+#include "../../video/windows/SDL_windowsvideo.h"
+
+#if SDL_VIDEO_RENDER_D3D
+#define D3D_DEBUG_INFO
+#include <d3d9.h>
+#endif
+
+#include "SDL_shaders_d3d.h"
+
+
+/* Direct3D renderer implementation */
+
+static SDL_Renderer *D3D_CreateRenderer(SDL_Window * window, Uint32 flags);
+static void D3D_WindowEvent(SDL_Renderer * renderer,
+ const SDL_WindowEvent *event);
+static SDL_bool D3D_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode);
+static int D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+static int D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, const void *pixels,
+ int pitch);
+static int D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch);
+static int D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, void **pixels, int *pitch);
+static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+static int D3D_SetRenderTargetInternal(SDL_Renderer * renderer, SDL_Texture * texture);
+static int D3D_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
+static int D3D_UpdateViewport(SDL_Renderer * renderer);
+static int D3D_UpdateClipRect(SDL_Renderer * renderer);
+static int D3D_RenderClear(SDL_Renderer * renderer);
+static int D3D_RenderDrawPoints(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count);
+static int D3D_RenderDrawLines(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count);
+static int D3D_RenderFillRects(SDL_Renderer * renderer,
+ const SDL_FRect * rects, int count);
+static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect);
+static int D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect,
+ const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip);
+static int D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 format, void * pixels, int pitch);
+static void D3D_RenderPresent(SDL_Renderer * renderer);
+static void D3D_DestroyTexture(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static void D3D_DestroyRenderer(SDL_Renderer * renderer);
+
+
+SDL_RenderDriver D3D_RenderDriver = {
+ D3D_CreateRenderer,
+ {
+ "direct3d",
+ (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
+ 1,
+ {SDL_PIXELFORMAT_ARGB8888},
+ 0,
+ 0}
+};
+
+typedef struct
+{
+ void* d3dDLL;
+ IDirect3D9 *d3d;
+ IDirect3DDevice9 *device;
+ UINT adapter;
+ D3DPRESENT_PARAMETERS pparams;
+ SDL_bool updateSize;
+ SDL_bool beginScene;
+ SDL_bool enableSeparateAlphaBlend;
+ D3DTEXTUREFILTERTYPE scaleMode[8];
+ IDirect3DSurface9 *defaultRenderTarget;
+ IDirect3DSurface9 *currentRenderTarget;
+ void* d3dxDLL;
+ LPDIRECT3DPIXELSHADER9 shaders[NUM_SHADERS];
+} D3D_RenderData;
+
+typedef struct
+{
+ SDL_bool dirty;
+ int w, h;
+ DWORD usage;
+ Uint32 format;
+ D3DFORMAT d3dfmt;
+ IDirect3DTexture9 *texture;
+ IDirect3DTexture9 *staging;
+} D3D_TextureRep;
+
+typedef struct
+{
+ D3D_TextureRep texture;
+ D3DTEXTUREFILTERTYPE scaleMode;
+
+ /* YV12 texture support */
+ SDL_bool yuv;
+ D3D_TextureRep utexture;
+ D3D_TextureRep vtexture;
+ Uint8 *pixels;
+ int pitch;
+ SDL_Rect locked_rect;
+} D3D_TextureData;
+
+typedef struct
+{
+ float x, y, z;
+ DWORD color;
+ float u, v;
+} Vertex;
+
+static int
+D3D_SetError(const char *prefix, HRESULT result)
+{
+ const char *error;
+
+ switch (result) {
+ case D3DERR_WRONGTEXTUREFORMAT:
+ error = "WRONGTEXTUREFORMAT";
+ break;
+ case D3DERR_UNSUPPORTEDCOLOROPERATION:
+ error = "UNSUPPORTEDCOLOROPERATION";
+ break;
+ case D3DERR_UNSUPPORTEDCOLORARG:
+ error = "UNSUPPORTEDCOLORARG";
+ break;
+ case D3DERR_UNSUPPORTEDALPHAOPERATION:
+ error = "UNSUPPORTEDALPHAOPERATION";
+ break;
+ case D3DERR_UNSUPPORTEDALPHAARG:
+ error = "UNSUPPORTEDALPHAARG";
+ break;
+ case D3DERR_TOOMANYOPERATIONS:
+ error = "TOOMANYOPERATIONS";
+ break;
+ case D3DERR_CONFLICTINGTEXTUREFILTER:
+ error = "CONFLICTINGTEXTUREFILTER";
+ break;
+ case D3DERR_UNSUPPORTEDFACTORVALUE:
+ error = "UNSUPPORTEDFACTORVALUE";
+ break;
+ case D3DERR_CONFLICTINGRENDERSTATE:
+ error = "CONFLICTINGRENDERSTATE";
+ break;
+ case D3DERR_UNSUPPORTEDTEXTUREFILTER:
+ error = "UNSUPPORTEDTEXTUREFILTER";
+ break;
+ case D3DERR_CONFLICTINGTEXTUREPALETTE:
+ error = "CONFLICTINGTEXTUREPALETTE";
+ break;
+ case D3DERR_DRIVERINTERNALERROR:
+ error = "DRIVERINTERNALERROR";
+ break;
+ case D3DERR_NOTFOUND:
+ error = "NOTFOUND";
+ break;
+ case D3DERR_MOREDATA:
+ error = "MOREDATA";
+ break;
+ case D3DERR_DEVICELOST:
+ error = "DEVICELOST";
+ break;
+ case D3DERR_DEVICENOTRESET:
+ error = "DEVICENOTRESET";
+ break;
+ case D3DERR_NOTAVAILABLE:
+ error = "NOTAVAILABLE";
+ break;
+ case D3DERR_OUTOFVIDEOMEMORY:
+ error = "OUTOFVIDEOMEMORY";
+ break;
+ case D3DERR_INVALIDDEVICE:
+ error = "INVALIDDEVICE";
+ break;
+ case D3DERR_INVALIDCALL:
+ error = "INVALIDCALL";
+ break;
+ case D3DERR_DRIVERINVALIDCALL:
+ error = "DRIVERINVALIDCALL";
+ break;
+ case D3DERR_WASSTILLDRAWING:
+ error = "WASSTILLDRAWING";
+ break;
+ default:
+ error = "UNKNOWN";
+ break;
+ }
+ return SDL_SetError("%s: %s", prefix, error);
+}
+
+static D3DFORMAT
+PixelFormatToD3DFMT(Uint32 format)
+{
+ switch (format) {
+ case SDL_PIXELFORMAT_RGB565:
+ return D3DFMT_R5G6B5;
+ case SDL_PIXELFORMAT_RGB888:
+ return D3DFMT_X8R8G8B8;
+ case SDL_PIXELFORMAT_ARGB8888:
+ return D3DFMT_A8R8G8B8;
+ case SDL_PIXELFORMAT_YV12:
+ case SDL_PIXELFORMAT_IYUV:
+ case SDL_PIXELFORMAT_NV12:
+ case SDL_PIXELFORMAT_NV21:
+ return D3DFMT_L8;
+ default:
+ return D3DFMT_UNKNOWN;
+ }
+}
+
+static Uint32
+D3DFMTToPixelFormat(D3DFORMAT format)
+{
+ switch (format) {
+ case D3DFMT_R5G6B5:
+ return SDL_PIXELFORMAT_RGB565;
+ case D3DFMT_X8R8G8B8:
+ return SDL_PIXELFORMAT_RGB888;
+ case D3DFMT_A8R8G8B8:
+ return SDL_PIXELFORMAT_ARGB8888;
+ default:
+ return SDL_PIXELFORMAT_UNKNOWN;
+ }
+}
+
+static void
+D3D_InitRenderState(D3D_RenderData *data)
+{
+ D3DMATRIX matrix;
+
+ IDirect3DDevice9 *device = data->device;
+
+ IDirect3DDevice9_SetVertexShader(device, NULL);
+ IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
+ IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
+ IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
+ IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
+
+ /* Enable color modulation by diffuse color */
+ IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP,
+ D3DTOP_MODULATE);
+ IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1,
+ D3DTA_TEXTURE);
+ IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2,
+ D3DTA_DIFFUSE);
+
+ /* Enable alpha modulation by diffuse alpha */
+ IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAOP,
+ D3DTOP_MODULATE);
+ IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1,
+ D3DTA_TEXTURE);
+ IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAARG2,
+ D3DTA_DIFFUSE);
+
+ /* Enable separate alpha blend function, if possible */
+ if (data->enableSeparateAlphaBlend) {
+ IDirect3DDevice9_SetRenderState(device, D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
+ }
+
+ /* Disable second texture stage, since we're done */
+ IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP,
+ D3DTOP_DISABLE);
+ IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_ALPHAOP,
+ D3DTOP_DISABLE);
+
+ /* Set an identity world and view matrix */
+ matrix.m[0][0] = 1.0f;
+ matrix.m[0][1] = 0.0f;
+ matrix.m[0][2] = 0.0f;
+ matrix.m[0][3] = 0.0f;
+ matrix.m[1][0] = 0.0f;
+ matrix.m[1][1] = 1.0f;
+ matrix.m[1][2] = 0.0f;
+ matrix.m[1][3] = 0.0f;
+ matrix.m[2][0] = 0.0f;
+ matrix.m[2][1] = 0.0f;
+ matrix.m[2][2] = 1.0f;
+ matrix.m[2][3] = 0.0f;
+ matrix.m[3][0] = 0.0f;
+ matrix.m[3][1] = 0.0f;
+ matrix.m[3][2] = 0.0f;
+ matrix.m[3][3] = 1.0f;
+ IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &matrix);
+ IDirect3DDevice9_SetTransform(device, D3DTS_VIEW, &matrix);
+
+ /* Reset our current scale mode */
+ SDL_memset(data->scaleMode, 0xFF, sizeof(data->scaleMode));
+
+ /* Start the render with beginScene */
+ data->beginScene = SDL_TRUE;
+}
+
+static int
+D3D_Reset(SDL_Renderer * renderer)
+{
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+ HRESULT result;
+ SDL_Texture *texture;
+
+ /* Release the default render target before reset */
+ if (data->defaultRenderTarget) {
+ IDirect3DSurface9_Release(data->defaultRenderTarget);
+ data->defaultRenderTarget = NULL;
+ }
+ if (data->currentRenderTarget != NULL) {
+ IDirect3DSurface9_Release(data->currentRenderTarget);
+ data->currentRenderTarget = NULL;
+ }
+
+ /* Release application render targets */
+ for (texture = renderer->textures; texture; texture = texture->next) {
+ if (texture->access == SDL_TEXTUREACCESS_TARGET) {
+ D3D_DestroyTexture(renderer, texture);
+ } else {
+ D3D_RecreateTexture(renderer, texture);
+ }
+ }
+
+ result = IDirect3DDevice9_Reset(data->device, &data->pparams);
+ if (FAILED(result)) {
+ if (result == D3DERR_DEVICELOST) {
+ /* Don't worry about it, we'll reset later... */
+ return 0;
+ } else {
+ return D3D_SetError("Reset()", result);
+ }
+ }
+
+ /* Allocate application render targets */
+ for (texture = renderer->textures; texture; texture = texture->next) {
+ if (texture->access == SDL_TEXTUREACCESS_TARGET) {
+ D3D_CreateTexture(renderer, texture);
+ }
+ }
+
+ IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget);
+ D3D_InitRenderState(data);
+ D3D_SetRenderTargetInternal(renderer, renderer->target);
+ D3D_UpdateViewport(renderer);
+
+ /* Let the application know that render targets were reset */
+ {
+ SDL_Event event;
+ event.type = SDL_RENDER_TARGETS_RESET;
+ SDL_PushEvent(&event);
+ }
+
+ return 0;
+}
+
+static int
+D3D_ActivateRenderer(SDL_Renderer * renderer)
+{
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+ HRESULT result;
+
+ if (data->updateSize) {
+ SDL_Window *window = renderer->window;
+ int w, h;
+ Uint32 window_flags = SDL_GetWindowFlags(window);
+
+ SDL_GetWindowSize(window, &w, &h);
+ data->pparams.BackBufferWidth = w;
+ data->pparams.BackBufferHeight = h;
+ if (window_flags & SDL_WINDOW_FULLSCREEN && (window_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
+ SDL_DisplayMode fullscreen_mode;
+ SDL_GetWindowDisplayMode(window, &fullscreen_mode);
+ data->pparams.Windowed = FALSE;
+ data->pparams.BackBufferFormat = PixelFormatToD3DFMT(fullscreen_mode.format);
+ data->pparams.FullScreen_RefreshRateInHz = fullscreen_mode.refresh_rate;
+ } else {
+ data->pparams.Windowed = TRUE;
+ data->pparams.BackBufferFormat = D3DFMT_UNKNOWN;
+ data->pparams.FullScreen_RefreshRateInHz = 0;
+ }
+ if (D3D_Reset(renderer) < 0) {
+ return -1;
+ }
+
+ data->updateSize = SDL_FALSE;
+ }
+ if (data->beginScene) {
+ result = IDirect3DDevice9_BeginScene(data->device);
+ if (result == D3DERR_DEVICELOST) {
+ if (D3D_Reset(renderer) < 0) {
+ return -1;
+ }
+ result = IDirect3DDevice9_BeginScene(data->device);
+ }
+ if (FAILED(result)) {
+ return D3D_SetError("BeginScene()", result);
+ }
+ data->beginScene = SDL_FALSE;
+ }
+ return 0;
+}
+
+SDL_Renderer *
+D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
+{
+ SDL_Renderer *renderer;
+ D3D_RenderData *data;
+ SDL_SysWMinfo windowinfo;
+ HRESULT result;
+ D3DPRESENT_PARAMETERS pparams;
+ IDirect3DSwapChain9 *chain;
+ D3DCAPS9 caps;
+ DWORD device_flags;
+ Uint32 window_flags;
+ int w, h;
+ SDL_DisplayMode fullscreen_mode;
+ int displayIndex;
+
+ renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
+ if (!renderer) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ data = (D3D_RenderData *) SDL_calloc(1, sizeof(*data));
+ if (!data) {
+ SDL_free(renderer);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ if (!D3D_LoadDLL(&data->d3dDLL, &data->d3d)) {
+ SDL_free(renderer);
+ SDL_free(data);
+ SDL_SetError("Unable to create Direct3D interface");
+ return NULL;
+ }
+
+ renderer->WindowEvent = D3D_WindowEvent;
+ renderer->SupportsBlendMode = D3D_SupportsBlendMode;
+ renderer->CreateTexture = D3D_CreateTexture;
+ renderer->UpdateTexture = D3D_UpdateTexture;
+ renderer->UpdateTextureYUV = D3D_UpdateTextureYUV;
+ renderer->LockTexture = D3D_LockTexture;
+ renderer->UnlockTexture = D3D_UnlockTexture;
+ renderer->SetRenderTarget = D3D_SetRenderTarget;
+ renderer->UpdateViewport = D3D_UpdateViewport;
+ renderer->UpdateClipRect = D3D_UpdateClipRect;
+ renderer->RenderClear = D3D_RenderClear;
+ renderer->RenderDrawPoints = D3D_RenderDrawPoints;
+ renderer->RenderDrawLines = D3D_RenderDrawLines;
+ renderer->RenderFillRects = D3D_RenderFillRects;
+ renderer->RenderCopy = D3D_RenderCopy;
+ renderer->RenderCopyEx = D3D_RenderCopyEx;
+ renderer->RenderReadPixels = D3D_RenderReadPixels;
+ renderer->RenderPresent = D3D_RenderPresent;
+ renderer->DestroyTexture = D3D_DestroyTexture;
+ renderer->DestroyRenderer = D3D_DestroyRenderer;
+ renderer->info = D3D_RenderDriver.info;
+ renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
+ renderer->driverdata = data;
+
+ SDL_VERSION(&windowinfo.version);
+ SDL_GetWindowWMInfo(window, &windowinfo);
+
+ window_flags = SDL_GetWindowFlags(window);
+ SDL_GetWindowSize(window, &w, &h);
+ SDL_GetWindowDisplayMode(window, &fullscreen_mode);
+
+ SDL_zero(pparams);
+ pparams.hDeviceWindow = windowinfo.info.win.window;
+ pparams.BackBufferWidth = w;
+ pparams.BackBufferHeight = h;
+ pparams.BackBufferCount = 1;
+ pparams.SwapEffect = D3DSWAPEFFECT_DISCARD;
+
+ if (window_flags & SDL_WINDOW_FULLSCREEN && (window_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
+ pparams.Windowed = FALSE;
+ pparams.BackBufferFormat = PixelFormatToD3DFMT(fullscreen_mode.format);
+ pparams.FullScreen_RefreshRateInHz = fullscreen_mode.refresh_rate;
+ } else {
+ pparams.Windowed = TRUE;
+ pparams.BackBufferFormat = D3DFMT_UNKNOWN;
+ pparams.FullScreen_RefreshRateInHz = 0;
+ }
+ if (flags & SDL_RENDERER_PRESENTVSYNC) {
+ pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
+ } else {
+ pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
+ }
+
+ /* Get the adapter for the display that the window is on */
+ displayIndex = SDL_GetWindowDisplayIndex(window);
+ data->adapter = SDL_Direct3D9GetAdapterIndex(displayIndex);
+
+ IDirect3D9_GetDeviceCaps(data->d3d, data->adapter, D3DDEVTYPE_HAL, &caps);
+
+ device_flags = D3DCREATE_FPU_PRESERVE;
+ if (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) {
+ device_flags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
+ } else {
+ device_flags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
+ }
+
+ if (SDL_GetHintBoolean(SDL_HINT_RENDER_DIRECT3D_THREADSAFE, SDL_FALSE)) {
+ device_flags |= D3DCREATE_MULTITHREADED;
+ }
+
+ result = IDirect3D9_CreateDevice(data->d3d, data->adapter,
+ D3DDEVTYPE_HAL,
+ pparams.hDeviceWindow,
+ device_flags,
+ &pparams, &data->device);
+ if (FAILED(result)) {
+ D3D_DestroyRenderer(renderer);
+ D3D_SetError("CreateDevice()", result);
+ return NULL;
+ }
+
+ /* Get presentation parameters to fill info */
+ result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain);
+ if (FAILED(result)) {
+ D3D_DestroyRenderer(renderer);
+ D3D_SetError("GetSwapChain()", result);
+ return NULL;
+ }
+ result = IDirect3DSwapChain9_GetPresentParameters(chain, &pparams);
+ if (FAILED(result)) {
+ IDirect3DSwapChain9_Release(chain);
+ D3D_DestroyRenderer(renderer);
+ D3D_SetError("GetPresentParameters()", result);
+ return NULL;
+ }
+ IDirect3DSwapChain9_Release(chain);
+ if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) {
+ renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
+ }
+ data->pparams = pparams;
+
+ IDirect3DDevice9_GetDeviceCaps(data->device, &caps);
+ renderer->info.max_texture_width = caps.MaxTextureWidth;
+ renderer->info.max_texture_height = caps.MaxTextureHeight;
+ if (caps.NumSimultaneousRTs >= 2) {
+ renderer->info.flags |= SDL_RENDERER_TARGETTEXTURE;
+ }
+
+ if (caps.PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND) {
+ data->enableSeparateAlphaBlend = SDL_TRUE;
+ }
+
+ /* Store the default render target */
+ IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget);
+ data->currentRenderTarget = NULL;
+
+ /* Set up parameters for rendering */
+ D3D_InitRenderState(data);
+
+ if (caps.MaxSimultaneousTextures >= 3) {
+ int i;
+ for (i = 0; i < SDL_arraysize(data->shaders); ++i) {
+ result = D3D9_CreatePixelShader(data->device, (D3D9_Shader)i, &data->shaders[i]);
+ if (FAILED(result)) {
+ D3D_SetError("CreatePixelShader()", result);
+ }
+ }
+ if (data->shaders[SHADER_YUV_JPEG] && data->shaders[SHADER_YUV_BT601] && data->shaders[SHADER_YUV_BT709]) {
+ renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_YV12;
+ renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_IYUV;
+ }
+ }
+ return renderer;
+}
+
+static void
+D3D_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
+{
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+
+ if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
+ data->updateSize = SDL_TRUE;
+ }
+}
+
+static D3DBLEND GetBlendFunc(SDL_BlendFactor factor)
+{
+ switch (factor) {
+ case SDL_BLENDFACTOR_ZERO:
+ return D3DBLEND_ZERO;
+ case SDL_BLENDFACTOR_ONE:
+ return D3DBLEND_ONE;
+ case SDL_BLENDFACTOR_SRC_COLOR:
+ return D3DBLEND_SRCCOLOR;
+ case SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR:
+ return D3DBLEND_INVSRCCOLOR;
+ case SDL_BLENDFACTOR_SRC_ALPHA:
+ return D3DBLEND_SRCALPHA;
+ case SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA:
+ return D3DBLEND_INVSRCALPHA;
+ case SDL_BLENDFACTOR_DST_COLOR:
+ return D3DBLEND_DESTCOLOR;
+ case SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR:
+ return D3DBLEND_INVDESTCOLOR;
+ case SDL_BLENDFACTOR_DST_ALPHA:
+ return D3DBLEND_DESTALPHA;
+ case SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA:
+ return D3DBLEND_INVDESTALPHA;
+ default:
+ return (D3DBLEND)0;
+ }
+}
+
+static SDL_bool
+D3D_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
+{
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+ SDL_BlendFactor srcColorFactor = SDL_GetBlendModeSrcColorFactor(blendMode);
+ SDL_BlendFactor srcAlphaFactor = SDL_GetBlendModeSrcAlphaFactor(blendMode);
+ SDL_BlendOperation colorOperation = SDL_GetBlendModeColorOperation(blendMode);
+ SDL_BlendFactor dstColorFactor = SDL_GetBlendModeDstColorFactor(blendMode);
+ SDL_BlendFactor dstAlphaFactor = SDL_GetBlendModeDstAlphaFactor(blendMode);
+ SDL_BlendOperation alphaOperation = SDL_GetBlendModeAlphaOperation(blendMode);
+
+ if (!GetBlendFunc(srcColorFactor) || !GetBlendFunc(srcAlphaFactor) ||
+ !GetBlendFunc(dstColorFactor) || !GetBlendFunc(dstAlphaFactor)) {
+ return SDL_FALSE;
+ }
+ if ((srcColorFactor != srcAlphaFactor || dstColorFactor != dstAlphaFactor) && !data->enableSeparateAlphaBlend) {
+ return SDL_FALSE;
+ }
+ if (colorOperation != SDL_BLENDOPERATION_ADD || alphaOperation != SDL_BLENDOPERATION_ADD) {
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
+}
+
+static D3DTEXTUREFILTERTYPE
+GetScaleQuality(void)
+{
+ const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
+
+ if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
+ return D3DTEXF_POINT;
+ } else /* if (*hint == '1' || SDL_strcasecmp(hint, "linear") == 0) */ {
+ return D3DTEXF_LINEAR;
+ }
+}
+
+static int
+D3D_CreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD usage, Uint32 format, D3DFORMAT d3dfmt, int w, int h)
+{
+ HRESULT result;
+
+ texture->dirty = SDL_FALSE;
+ texture->w = w;
+ texture->h = h;
+ texture->usage = usage;
+ texture->format = format;
+ texture->d3dfmt = d3dfmt;
+
+ result = IDirect3DDevice9_CreateTexture(device, w, h, 1, usage,
+ PixelFormatToD3DFMT(format),
+ D3DPOOL_DEFAULT, &texture->texture, NULL);
+ if (FAILED(result)) {
+ return D3D_SetError("CreateTexture(D3DPOOL_DEFAULT)", result);
+ }
+ return 0;
+}
+
+
+static int
+D3D_CreateStagingTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture)
+{
+ HRESULT result;
+
+ if (texture->staging == NULL) {
+ result = IDirect3DDevice9_CreateTexture(device, texture->w, texture->h, 1, 0,
+ texture->d3dfmt, D3DPOOL_SYSTEMMEM, &texture->staging, NULL);
+ if (FAILED(result)) {
+ return D3D_SetError("CreateTexture(D3DPOOL_SYSTEMMEM)", result);
+ }
+ }
+ return 0;
+}
+
+static int
+D3D_BindTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD sampler)
+{
+ HRESULT result;
+
+ if (texture->dirty && texture->staging) {
+ if (!texture->texture) {
+ result = IDirect3DDevice9_CreateTexture(device, texture->w, texture->h, 1, texture->usage,
+ PixelFormatToD3DFMT(texture->format), D3DPOOL_DEFAULT, &texture->texture, NULL);
+ if (FAILED(result)) {
+ return D3D_SetError("CreateTexture(D3DPOOL_DEFAULT)", result);
+ }
+ }
+
+ result = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)texture->staging, (IDirect3DBaseTexture9 *)texture->texture);
+ if (FAILED(result)) {
+ return D3D_SetError("UpdateTexture()", result);
+ }
+ texture->dirty = SDL_FALSE;
+ }
+ result = IDirect3DDevice9_SetTexture(device, sampler, (IDirect3DBaseTexture9 *)texture->texture);
+ if (FAILED(result)) {
+ return D3D_SetError("SetTexture()", result);
+ }
+ return 0;
+}
+
+static int
+D3D_RecreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture)
+{
+ if (texture->texture) {
+ IDirect3DTexture9_Release(texture->texture);
+ texture->texture = NULL;
+ }
+ if (texture->staging) {
+ IDirect3DTexture9_AddDirtyRect(texture->staging, NULL);
+ texture->dirty = SDL_TRUE;
+ }
+ return 0;
+}
+
+static int
+D3D_UpdateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, int x, int y, int w, int h, const void *pixels, int pitch)
+{
+ RECT d3drect;
+ D3DLOCKED_RECT locked;
+ const Uint8 *src;
+ Uint8 *dst;
+ int row, length;
+ HRESULT result;
+
+ if (D3D_CreateStagingTexture(device, texture) < 0) {
+ return -1;
+ }
+
+ d3drect.left = x;
+ d3drect.right = x + w;
+ d3drect.top = y;
+ d3drect.bottom = y + h;
+
+ result = IDirect3DTexture9_LockRect(texture->staging, 0, &locked, &d3drect, 0);
+ if (FAILED(result)) {
+ return D3D_SetError("LockRect()", result);
+ }
+
+ src = (const Uint8 *)pixels;
+ dst = (Uint8 *)locked.pBits;
+ length = w * SDL_BYTESPERPIXEL(texture->format);
+ if (length == pitch && length == locked.Pitch) {
+ SDL_memcpy(dst, src, length*h);
+ } else {
+ if (length > pitch) {
+ length = pitch;
+ }
+ if (length > locked.Pitch) {
+ length = locked.Pitch;
+ }
+ for (row = 0; row < h; ++row) {
+ SDL_memcpy(dst, src, length);
+ src += pitch;
+ dst += locked.Pitch;
+ }
+ }
+ result = IDirect3DTexture9_UnlockRect(texture->staging, 0);
+ if (FAILED(result)) {
+ return D3D_SetError("UnlockRect()", result);
+ }
+ texture->dirty = SDL_TRUE;
+
+ return 0;
+}
+
+static void
+D3D_DestroyTextureRep(D3D_TextureRep *texture)
+{
+ if (texture->texture) {
+ IDirect3DTexture9_Release(texture->texture);
+ texture->texture = NULL;
+ }
+ if (texture->staging) {
+ IDirect3DTexture9_Release(texture->staging);
+ texture->staging = NULL;
+ }
+}
+
+static int
+D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+ D3D_TextureData *texturedata;
+ DWORD usage;
+
+ texturedata = (D3D_TextureData *) SDL_calloc(1, sizeof(*texturedata));
+ if (!texturedata) {
+ return SDL_OutOfMemory();
+ }
+ texturedata->scaleMode = GetScaleQuality();
+
+ texture->driverdata = texturedata;
+
+ if (texture->access == SDL_TEXTUREACCESS_TARGET) {
+ usage = D3DUSAGE_RENDERTARGET;
+ } else {
+ usage = 0;
+ }
+
+ if (D3D_CreateTextureRep(data->device, &texturedata->texture, usage, texture->format, PixelFormatToD3DFMT(texture->format), texture->w, texture->h) < 0) {
+ return -1;
+ }
+
+ if (texture->format == SDL_PIXELFORMAT_YV12 ||
+ texture->format == SDL_PIXELFORMAT_IYUV) {
+ texturedata->yuv = SDL_TRUE;
+
+ if (D3D_CreateTextureRep(data->device, &texturedata->utexture, usage, texture->format, PixelFormatToD3DFMT(texture->format), (texture->w + 1) / 2, (texture->h + 1) / 2) < 0) {
+ return -1;
+ }
+
+ if (D3D_CreateTextureRep(data->device, &texturedata->vtexture, usage, texture->format, PixelFormatToD3DFMT(texture->format), (texture->w + 1) / 2, (texture->h + 1) / 2) < 0) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int
+D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
+ D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
+
+ if (!texturedata) {
+ return 0;
+ }
+
+ if (D3D_RecreateTextureRep(data->device, &texturedata->texture) < 0) {
+ return -1;
+ }
+
+ if (texturedata->yuv) {
+ if (D3D_RecreateTextureRep(data->device, &texturedata->utexture) < 0) {
+ return -1;
+ }
+
+ if (D3D_RecreateTextureRep(data->device, &texturedata->vtexture) < 0) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int
+D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, const void *pixels, int pitch)
+{
+ D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
+ D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
+
+ if (!texturedata) {
+ SDL_SetError("Texture is not currently available");
+ return -1;
+ }
+
+ if (D3D_UpdateTextureRep(data->device, &texturedata->texture, rect->x, rect->y, rect->w, rect->h, pixels, pitch) < 0) {
+ return -1;
+ }
+
+ if (texturedata->yuv) {
+ /* Skip to the correct offset into the next texture */
+ pixels = (const void*)((const Uint8*)pixels + rect->h * pitch);
+
+ if (D3D_UpdateTextureRep(data->device, texture->format == SDL_PIXELFORMAT_YV12 ? &texturedata->vtexture : &texturedata->utexture, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, pixels, (pitch + 1) / 2) < 0) {
+ return -1;
+ }
+
+ /* Skip to the correct offset into the next texture */
+ pixels = (const void*)((const Uint8*)pixels + ((rect->h + 1) / 2) * ((pitch + 1) / 2));
+ if (D3D_UpdateTextureRep(data->device, texture->format == SDL_PIXELFORMAT_YV12 ? &texturedata->utexture : &texturedata->vtexture, rect->x / 2, (rect->y + 1) / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, pixels, (pitch + 1) / 2) < 0) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int
+D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch)
+{
+ D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
+ D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
+
+ if (!texturedata) {
+ SDL_SetError("Texture is not currently available");
+ return -1;
+ }
+
+ if (D3D_UpdateTextureRep(data->device, &texturedata->texture, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) {
+ return -1;
+ }
+ if (D3D_UpdateTextureRep(data->device, &texturedata->utexture, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, Uplane, Upitch) < 0) {
+ return -1;
+ }
+ if (D3D_UpdateTextureRep(data->device, &texturedata->vtexture, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, Vplane, Vpitch) < 0) {
+ return -1;
+ }
+ return 0;
+}
+
+static int
+D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, void **pixels, int *pitch)
+{
+ D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
+ D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
+ IDirect3DDevice9 *device = data->device;
+
+ if (!texturedata) {
+ SDL_SetError("Texture is not currently available");
+ return -1;
+ }
+
+ texturedata->locked_rect = *rect;
+
+ if (texturedata->yuv) {
+ /* It's more efficient to upload directly... */
+ if (!texturedata->pixels) {
+ texturedata->pitch = texture->w;
+ texturedata->pixels = (Uint8 *)SDL_malloc((texture->h * texturedata->pitch * 3) / 2);
+ if (!texturedata->pixels) {
+ return SDL_OutOfMemory();
+ }
+ }
+ *pixels =
+ (void *) ((Uint8 *) texturedata->pixels + rect->y * texturedata->pitch +
+ rect->x * SDL_BYTESPERPIXEL(texture->format));
+ *pitch = texturedata->pitch;
+ } else {
+ RECT d3drect;
+ D3DLOCKED_RECT locked;
+ HRESULT result;
+
+ if (D3D_CreateStagingTexture(device, &texturedata->texture) < 0) {
+ return -1;
+ }
+
+ d3drect.left = rect->x;
+ d3drect.right = rect->x + rect->w;
+ d3drect.top = rect->y;
+ d3drect.bottom = rect->y + rect->h;
+
+ result = IDirect3DTexture9_LockRect(texturedata->texture.staging, 0, &locked, &d3drect, 0);
+ if (FAILED(result)) {
+ return D3D_SetError("LockRect()", result);
+ }
+ *pixels = locked.pBits;
+ *pitch = locked.Pitch;
+ }
+ return 0;
+}
+
+static void
+D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ /*D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;*/
+ D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
+
+ if (!texturedata) {
+ return;
+ }
+
+ if (texturedata->yuv) {
+ const SDL_Rect *rect = &texturedata->locked_rect;
+ void *pixels =
+ (void *) ((Uint8 *) texturedata->pixels + rect->y * texturedata->pitch +
+ rect->x * SDL_BYTESPERPIXEL(texture->format));
+ D3D_UpdateTexture(renderer, texture, rect, pixels, texturedata->pitch);
+ } else {
+ IDirect3DTexture9_UnlockRect(texturedata->texture.staging, 0);
+ texturedata->texture.dirty = SDL_TRUE;
+ }
+}
+
+static int
+D3D_SetRenderTargetInternal(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+ D3D_TextureData *texturedata;
+ D3D_TextureRep *texturerep;
+ HRESULT result;
+ IDirect3DDevice9 *device = data->device;
+
+ /* Release the previous render target if it wasn't the default one */
+ if (data->currentRenderTarget != NULL) {
+ IDirect3DSurface9_Release(data->currentRenderTarget);
+ data->currentRenderTarget = NULL;
+ }
+
+ if (texture == NULL) {
+ IDirect3DDevice9_SetRenderTarget(data->device, 0, data->defaultRenderTarget);
+ return 0;
+ }
+
+ texturedata = (D3D_TextureData *)texture->driverdata;
+ if (!texturedata) {
+ SDL_SetError("Texture is not currently available");
+ return -1;
+ }
+
+ /* Make sure the render target is updated if it was locked and written to */
+ texturerep = &texturedata->texture;
+ if (texturerep->dirty && texturerep->staging) {
+ if (!texturerep->texture) {
+ result = IDirect3DDevice9_CreateTexture(device, texturerep->w, texturerep->h, 1, texturerep->usage,
+ PixelFormatToD3DFMT(texturerep->format), D3DPOOL_DEFAULT, &texturerep->texture, NULL);
+ if (FAILED(result)) {
+ return D3D_SetError("CreateTexture(D3DPOOL_DEFAULT)", result);
+ }
+ }
+
+ result = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)texturerep->staging, (IDirect3DBaseTexture9 *)texturerep->texture);
+ if (FAILED(result)) {
+ return D3D_SetError("UpdateTexture()", result);
+ }
+ texturerep->dirty = SDL_FALSE;
+ }
+
+ result = IDirect3DTexture9_GetSurfaceLevel(texturedata->texture.texture, 0, &data->currentRenderTarget);
+ if(FAILED(result)) {
+ return D3D_SetError("GetSurfaceLevel()", result);
+ }
+ result = IDirect3DDevice9_SetRenderTarget(data->device, 0, data->currentRenderTarget);
+ if(FAILED(result)) {
+ return D3D_SetError("SetRenderTarget()", result);
+ }
+
+ return 0;
+}
+
+static int
+D3D_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ if (D3D_ActivateRenderer(renderer) < 0) {
+ return -1;
+ }
+
+ return D3D_SetRenderTargetInternal(renderer, texture);
+}
+
+static int
+D3D_UpdateViewport(SDL_Renderer * renderer)
+{
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+ D3DVIEWPORT9 viewport;
+ D3DMATRIX matrix;
+
+ /* Set the viewport */
+ viewport.X = renderer->viewport.x;
+ viewport.Y = renderer->viewport.y;
+ viewport.Width = renderer->viewport.w;
+ viewport.Height = renderer->viewport.h;
+ viewport.MinZ = 0.0f;
+ viewport.MaxZ = 1.0f;
+ IDirect3DDevice9_SetViewport(data->device, &viewport);
+
+ /* Set an orthographic projection matrix */
+ if (renderer->viewport.w && renderer->viewport.h) {
+ matrix.m[0][0] = 2.0f / renderer->viewport.w;
+ matrix.m[0][1] = 0.0f;
+ matrix.m[0][2] = 0.0f;
+ matrix.m[0][3] = 0.0f;
+ matrix.m[1][0] = 0.0f;
+ matrix.m[1][1] = -2.0f / renderer->viewport.h;
+ matrix.m[1][2] = 0.0f;
+ matrix.m[1][3] = 0.0f;
+ matrix.m[2][0] = 0.0f;
+ matrix.m[2][1] = 0.0f;
+ matrix.m[2][2] = 1.0f;
+ matrix.m[2][3] = 0.0f;
+ matrix.m[3][0] = -1.0f;
+ matrix.m[3][1] = 1.0f;
+ matrix.m[3][2] = 0.0f;
+ matrix.m[3][3] = 1.0f;
+ IDirect3DDevice9_SetTransform(data->device, D3DTS_PROJECTION, &matrix);
+ }
+
+ return 0;
+}
+
+static int
+D3D_UpdateClipRect(SDL_Renderer * renderer)
+{
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+
+ if (renderer->clipping_enabled) {
+ const SDL_Rect *rect = &renderer->clip_rect;
+ RECT r;
+ HRESULT result;
+
+ IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE, TRUE);
+ r.left = renderer->viewport.x + rect->x;
+ r.top = renderer->viewport.y + rect->y;
+ r.right = renderer->viewport.x + rect->x + rect->w;
+ r.bottom = renderer->viewport.y + rect->y + rect->h;
+
+ result = IDirect3DDevice9_SetScissorRect(data->device, &r);
+ if (result != D3D_OK) {
+ D3D_SetError("SetScissor()", result);
+ return -1;
+ }
+ } else {
+ IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE, FALSE);
+ }
+ return 0;
+}
+
+static int
+D3D_RenderClear(SDL_Renderer * renderer)
+{
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+ DWORD color;
+ HRESULT result;
+ int BackBufferWidth, BackBufferHeight;
+
+ if (D3D_ActivateRenderer(renderer) < 0) {
+ return -1;
+ }
+
+ color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
+
+ if (renderer->target) {
+ BackBufferWidth = renderer->target->w;
+ BackBufferHeight = renderer->target->h;
+ } else {
+ BackBufferWidth = data->pparams.BackBufferWidth;
+ BackBufferHeight = data->pparams.BackBufferHeight;
+ }
+
+ if (renderer->clipping_enabled) {
+ IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE, FALSE);
+ }
+
+ /* Don't reset the viewport if we don't have to! */
+ if (!renderer->viewport.x && !renderer->viewport.y &&
+ renderer->viewport.w == BackBufferWidth &&
+ renderer->viewport.h == BackBufferHeight) {
+ result = IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET, color, 0.0f, 0);
+ } else {
+ D3DVIEWPORT9 viewport;
+
+ /* Clear is defined to clear the entire render target */
+ viewport.X = 0;
+ viewport.Y = 0;
+ viewport.Width = BackBufferWidth;
+ viewport.Height = BackBufferHeight;
+ viewport.MinZ = 0.0f;
+ viewport.MaxZ = 1.0f;
+ IDirect3DDevice9_SetViewport(data->device, &viewport);
+
+ result = IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET, color, 0.0f, 0);
+
+ /* Reset the viewport */
+ viewport.X = renderer->viewport.x;
+ viewport.Y = renderer->viewport.y;
+ viewport.Width = renderer->viewport.w;
+ viewport.Height = renderer->viewport.h;
+ viewport.MinZ = 0.0f;
+ viewport.MaxZ = 1.0f;
+ IDirect3DDevice9_SetViewport(data->device, &viewport);
+ }
+
+ if (renderer->clipping_enabled) {
+ IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE, TRUE);
+ }
+
+ if (FAILED(result)) {
+ return D3D_SetError("Clear()", result);
+ }
+ return 0;
+}
+
+static void
+D3D_SetBlendMode(D3D_RenderData * data, SDL_BlendMode blendMode)
+{
+ if (blendMode == SDL_BLENDMODE_NONE) {
+ IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE, FALSE);
+ } else {
+ IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE, TRUE);
+ IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
+ GetBlendFunc(SDL_GetBlendModeSrcColorFactor(blendMode)));
+ IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
+ GetBlendFunc(SDL_GetBlendModeDstColorFactor(blendMode)));
+ if (data->enableSeparateAlphaBlend) {
+ IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLENDALPHA,
+ GetBlendFunc(SDL_GetBlendModeSrcAlphaFactor(blendMode)));
+ IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLENDALPHA,
+ GetBlendFunc(SDL_GetBlendModeDstAlphaFactor(blendMode)));
+ }
+ }
+}
+
+static int
+D3D_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points,
+ int count)
+{
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+ DWORD color;
+ Vertex *vertices;
+ int i;
+ HRESULT result;
+
+ if (D3D_ActivateRenderer(renderer) < 0) {
+ return -1;
+ }
+
+ D3D_SetBlendMode(data, renderer->blendMode);
+
+ result =
+ IDirect3DDevice9_SetTexture(data->device, 0,
+ (IDirect3DBaseTexture9 *) 0);
+ if (FAILED(result)) {
+ return D3D_SetError("SetTexture()", result);
+ }
+
+ color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
+
+ vertices = SDL_stack_alloc(Vertex, count);
+ for (i = 0; i < count; ++i) {
+ vertices[i].x = points[i].x;
+ vertices[i].y = points[i].y;
+ vertices[i].z = 0.0f;
+ vertices[i].color = color;
+ vertices[i].u = 0.0f;
+ vertices[i].v = 0.0f;
+ }
+ result =
+ IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, count,
+ vertices, sizeof(*vertices));
+ SDL_stack_free(vertices);
+ if (FAILED(result)) {
+ return D3D_SetError("DrawPrimitiveUP()", result);
+ }
+ return 0;
+}
+
+static int
+D3D_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points,
+ int count)
+{
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+ DWORD color;
+ Vertex *vertices;
+ int i;
+ HRESULT result;
+
+ if (D3D_ActivateRenderer(renderer) < 0) {
+ return -1;
+ }
+
+ D3D_SetBlendMode(data, renderer->blendMode);
+
+ result =
+ IDirect3DDevice9_SetTexture(data->device, 0,
+ (IDirect3DBaseTexture9 *) 0);
+ if (FAILED(result)) {
+ return D3D_SetError("SetTexture()", result);
+ }
+
+ color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
+
+ vertices = SDL_stack_alloc(Vertex, count);
+ for (i = 0; i < count; ++i) {
+ vertices[i].x = points[i].x;
+ vertices[i].y = points[i].y;
+ vertices[i].z = 0.0f;
+ vertices[i].color = color;
+ vertices[i].u = 0.0f;
+ vertices[i].v = 0.0f;
+ }
+ result =
+ IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_LINESTRIP, count-1,
+ vertices, sizeof(*vertices));
+
+ /* DirectX 9 has the same line rasterization semantics as GDI,
+ so we need to close the endpoint of the line */
+ if (count == 2 ||
+ points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
+ vertices[0].x = points[count-1].x;
+ vertices[0].y = points[count-1].y;
+ result = IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, 1, vertices, sizeof(*vertices));
+ }
+
+ SDL_stack_free(vertices);
+ if (FAILED(result)) {
+ return D3D_SetError("DrawPrimitiveUP()", result);
+ }
+ return 0;
+}
+
+static int
+D3D_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects,
+ int count)
+{
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+ DWORD color;
+ int i;
+ float minx, miny, maxx, maxy;
+ Vertex vertices[4];
+ HRESULT result;
+
+ if (D3D_ActivateRenderer(renderer) < 0) {
+ return -1;
+ }
+
+ D3D_SetBlendMode(data, renderer->blendMode);
+
+ result =
+ IDirect3DDevice9_SetTexture(data->device, 0,
+ (IDirect3DBaseTexture9 *) 0);
+ if (FAILED(result)) {
+ return D3D_SetError("SetTexture()", result);
+ }
+
+ color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
+
+ for (i = 0; i < count; ++i) {
+ const SDL_FRect *rect = &rects[i];
+
+ minx = rect->x;
+ miny = rect->y;
+ maxx = rect->x + rect->w;
+ maxy = rect->y + rect->h;
+
+ vertices[0].x = minx;
+ vertices[0].y = miny;
+ vertices[0].z = 0.0f;
+ vertices[0].color = color;
+ vertices[0].u = 0.0f;
+ vertices[0].v = 0.0f;
+
+ vertices[1].x = maxx;
+ vertices[1].y = miny;
+ vertices[1].z = 0.0f;
+ vertices[1].color = color;
+ vertices[1].u = 0.0f;
+ vertices[1].v = 0.0f;
+
+ vertices[2].x = maxx;
+ vertices[2].y = maxy;
+ vertices[2].z = 0.0f;
+ vertices[2].color = color;
+ vertices[2].u = 0.0f;
+ vertices[2].v = 0.0f;
+
+ vertices[3].x = minx;
+ vertices[3].y = maxy;
+ vertices[3].z = 0.0f;
+ vertices[3].color = color;
+ vertices[3].u = 0.0f;
+ vertices[3].v = 0.0f;
+
+ result =
+ IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN,
+ 2, vertices, sizeof(*vertices));
+ if (FAILED(result)) {
+ return D3D_SetError("DrawPrimitiveUP()", result);
+ }
+ }
+ return 0;
+}
+
+static void
+D3D_UpdateTextureScaleMode(D3D_RenderData *data, D3D_TextureData *texturedata, unsigned index)
+{
+ if (texturedata->scaleMode != data->scaleMode[index]) {
+ IDirect3DDevice9_SetSamplerState(data->device, index, D3DSAMP_MINFILTER,
+ texturedata->scaleMode);
+ IDirect3DDevice9_SetSamplerState(data->device, index, D3DSAMP_MAGFILTER,
+ texturedata->scaleMode);
+ IDirect3DDevice9_SetSamplerState(data->device, index, D3DSAMP_ADDRESSU,
+ D3DTADDRESS_CLAMP);
+ IDirect3DDevice9_SetSamplerState(data->device, index, D3DSAMP_ADDRESSV,
+ D3DTADDRESS_CLAMP);
+ data->scaleMode[index] = texturedata->scaleMode;
+ }
+}
+
+static int
+D3D_RenderSetupTextureState(SDL_Renderer * renderer, SDL_Texture * texture, LPDIRECT3DPIXELSHADER9 *shader)
+{
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+ D3D_TextureData *texturedata;
+
+ *shader = NULL;
+
+ texturedata = (D3D_TextureData *)texture->driverdata;
+ if (!texturedata) {
+ SDL_SetError("Texture is not currently available");
+ return -1;
+ }
+
+ D3D_UpdateTextureScaleMode(data, texturedata, 0);
+
+ if (D3D_BindTextureRep(data->device, &texturedata->texture, 0) < 0) {
+ return -1;
+ }
+
+ if (texturedata->yuv) {
+ switch (SDL_GetYUVConversionModeForResolution(texture->w, texture->h)) {
+ case SDL_YUV_CONVERSION_JPEG:
+ *shader = data->shaders[SHADER_YUV_JPEG];
+ break;
+ case SDL_YUV_CONVERSION_BT601:
+ *shader = data->shaders[SHADER_YUV_BT601];
+ break;
+ case SDL_YUV_CONVERSION_BT709:
+ *shader = data->shaders[SHADER_YUV_BT709];
+ break;
+ default:
+ return SDL_SetError("Unsupported YUV conversion mode");
+ }
+
+ D3D_UpdateTextureScaleMode(data, texturedata, 1);
+ D3D_UpdateTextureScaleMode(data, texturedata, 2);
+
+ if (D3D_BindTextureRep(data->device, &texturedata->utexture, 1) < 0) {
+ return -1;
+ }
+ if (D3D_BindTextureRep(data->device, &texturedata->vtexture, 2) < 0) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int
+D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect)
+{
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+ LPDIRECT3DPIXELSHADER9 shader;
+ float minx, miny, maxx, maxy;
+ float minu, maxu, minv, maxv;
+ DWORD color;
+ Vertex vertices[4];
+ HRESULT result;
+
+ if (D3D_ActivateRenderer(renderer) < 0) {
+ return -1;
+ }
+
+ minx = dstrect->x - 0.5f;
+ miny = dstrect->y - 0.5f;
+ maxx = dstrect->x + dstrect->w - 0.5f;
+ maxy = dstrect->y + dstrect->h - 0.5f;
+
+ minu = (float) srcrect->x / texture->w;
+ maxu = (float) (srcrect->x + srcrect->w) / texture->w;
+ minv = (float) srcrect->y / texture->h;
+ maxv = (float) (srcrect->y + srcrect->h) / texture->h;
+
+ color = D3DCOLOR_ARGB(texture->a, texture->r, texture->g, texture->b);
+
+ vertices[0].x = minx;
+ vertices[0].y = miny;
+ vertices[0].z = 0.0f;
+ vertices[0].color = color;
+ vertices[0].u = minu;
+ vertices[0].v = minv;
+
+ vertices[1].x = maxx;
+ vertices[1].y = miny;
+ vertices[1].z = 0.0f;
+ vertices[1].color = color;
+ vertices[1].u = maxu;
+ vertices[1].v = minv;
+
+ vertices[2].x = maxx;
+ vertices[2].y = maxy;
+ vertices[2].z = 0.0f;
+ vertices[2].color = color;
+ vertices[2].u = maxu;
+ vertices[2].v = maxv;
+
+ vertices[3].x = minx;
+ vertices[3].y = maxy;
+ vertices[3].z = 0.0f;
+ vertices[3].color = color;
+ vertices[3].u = minu;
+ vertices[3].v = maxv;
+
+ D3D_SetBlendMode(data, texture->blendMode);
+
+ if (D3D_RenderSetupTextureState(renderer, texture, &shader) < 0) {
+ return -1;
+ }
+
+ if (shader) {
+ result = IDirect3DDevice9_SetPixelShader(data->device, shader);
+ if (FAILED(result)) {
+ return D3D_SetError("SetShader()", result);
+ }
+ }
+ result = IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2,
+ vertices, sizeof(*vertices));
+ if (FAILED(result)) {
+ D3D_SetError("DrawPrimitiveUP()", result);
+ }
+ if (shader) {
+ IDirect3DDevice9_SetPixelShader(data->device, NULL);
+ }
+ return FAILED(result) ? -1 : 0;
+}
+
+
+static int
+D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect,
+ const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip)
+{
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+ LPDIRECT3DPIXELSHADER9 shader = NULL;
+ float minx, miny, maxx, maxy;
+ float minu, maxu, minv, maxv;
+ float centerx, centery;
+ DWORD color;
+ Vertex vertices[4];
+ Float4X4 modelMatrix;
+ HRESULT result;
+
+ if (D3D_ActivateRenderer(renderer) < 0) {
+ return -1;
+ }
+
+ centerx = center->x;
+ centery = center->y;
+
+ minx = -centerx;
+ maxx = dstrect->w - centerx;
+ miny = -centery;
+ maxy = dstrect->h - centery;
+
+ minu = (float) srcrect->x / texture->w;
+ maxu = (float) (srcrect->x + srcrect->w) / texture->w;
+ minv = (float) srcrect->y / texture->h;
+ maxv = (float) (srcrect->y + srcrect->h) / texture->h;
+
+ if (flip & SDL_FLIP_HORIZONTAL) {
+ float tmp = maxu;
+ maxu = minu;
+ minu = tmp;
+ }
+ if (flip & SDL_FLIP_VERTICAL) {
+ float tmp = maxv;
+ maxv = minv;
+ minv = tmp;
+ }
+
+ color = D3DCOLOR_ARGB(texture->a, texture->r, texture->g, texture->b);
+
+ vertices[0].x = minx;
+ vertices[0].y = miny;
+ vertices[0].z = 0.0f;
+ vertices[0].color = color;
+ vertices[0].u = minu;
+ vertices[0].v = minv;
+
+ vertices[1].x = maxx;
+ vertices[1].y = miny;
+ vertices[1].z = 0.0f;
+ vertices[1].color = color;
+ vertices[1].u = maxu;
+ vertices[1].v = minv;
+
+ vertices[2].x = maxx;
+ vertices[2].y = maxy;
+ vertices[2].z = 0.0f;
+ vertices[2].color = color;
+ vertices[2].u = maxu;
+ vertices[2].v = maxv;
+
+ vertices[3].x = minx;
+ vertices[3].y = maxy;
+ vertices[3].z = 0.0f;
+ vertices[3].color = color;
+ vertices[3].u = minu;
+ vertices[3].v = maxv;
+
+ D3D_SetBlendMode(data, texture->blendMode);
+
+ if (D3D_RenderSetupTextureState(renderer, texture, &shader) < 0) {
+ return -1;
+ }
+
+ /* Rotate and translate */
+ modelMatrix = MatrixMultiply(
+ MatrixRotationZ((float)(M_PI * (float) angle / 180.0f)),
+ MatrixTranslation(dstrect->x + center->x - 0.5f, dstrect->y + center->y - 0.5f, 0));
+ IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)&modelMatrix);
+
+ if (shader) {
+ result = IDirect3DDevice9_SetPixelShader(data->device, shader);
+ if (FAILED(result)) {
+ D3D_SetError("SetShader()", result);
+ goto done;
+ }
+ }
+ result = IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2,
+ vertices, sizeof(*vertices));
+ if (FAILED(result)) {
+ D3D_SetError("DrawPrimitiveUP()", result);
+ }
+done:
+ if (shader) {
+ IDirect3DDevice9_SetPixelShader(data->device, NULL);
+ }
+
+ modelMatrix = MatrixIdentity();
+ IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)&modelMatrix);
+
+ return FAILED(result) ? -1 : 0;
+}
+
+static int
+D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 format, void * pixels, int pitch)
+{
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+ D3DSURFACE_DESC desc;
+ LPDIRECT3DSURFACE9 backBuffer;
+ LPDIRECT3DSURFACE9 surface;
+ RECT d3drect;
+ D3DLOCKED_RECT locked;
+ HRESULT result;
+
+ if (data->currentRenderTarget) {
+ backBuffer = data->currentRenderTarget;
+ } else {
+ backBuffer = data->defaultRenderTarget;
+ }
+
+ result = IDirect3DSurface9_GetDesc(backBuffer, &desc);
+ if (FAILED(result)) {
+ IDirect3DSurface9_Release(backBuffer);
+ return D3D_SetError("GetDesc()", result);
+ }
+
+ result = IDirect3DDevice9_CreateOffscreenPlainSurface(data->device, desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &surface, NULL);
+ if (FAILED(result)) {
+ IDirect3DSurface9_Release(backBuffer);
+ return D3D_SetError("CreateOffscreenPlainSurface()", result);
+ }
+
+ result = IDirect3DDevice9_GetRenderTargetData(data->device, backBuffer, surface);
+ if (FAILED(result)) {
+ IDirect3DSurface9_Release(surface);
+ IDirect3DSurface9_Release(backBuffer);
+ return D3D_SetError("GetRenderTargetData()", result);
+ }
+
+ d3drect.left = rect->x;
+ d3drect.right = rect->x + rect->w;
+ d3drect.top = rect->y;
+ d3drect.bottom = rect->y + rect->h;
+
+ result = IDirect3DSurface9_LockRect(surface, &locked, &d3drect, D3DLOCK_READONLY);
+ if (FAILED(result)) {
+ IDirect3DSurface9_Release(surface);
+ IDirect3DSurface9_Release(backBuffer);
+ return D3D_SetError("LockRect()", result);
+ }
+
+ SDL_ConvertPixels(rect->w, rect->h,
+ D3DFMTToPixelFormat(desc.Format), locked.pBits, locked.Pitch,
+ format, pixels, pitch);
+
+ IDirect3DSurface9_UnlockRect(surface);
+
+ IDirect3DSurface9_Release(surface);
+
+ return 0;
+}
+
+static void
+D3D_RenderPresent(SDL_Renderer * renderer)
+{
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+ HRESULT result;
+
+ if (!data->beginScene) {
+ IDirect3DDevice9_EndScene(data->device);
+ data->beginScene = SDL_TRUE;
+ }
+
+ result = IDirect3DDevice9_TestCooperativeLevel(data->device);
+ if (result == D3DERR_DEVICELOST) {
+ /* We'll reset later */
+ return;
+ }
+ if (result == D3DERR_DEVICENOTRESET) {
+ D3D_Reset(renderer);
+ }
+ result = IDirect3DDevice9_Present(data->device, NULL, NULL, NULL, NULL);
+ if (FAILED(result)) {
+ D3D_SetError("Present()", result);
+ }
+}
+
+static void
+D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
+
+ if (!data) {
+ return;
+ }
+ D3D_DestroyTextureRep(&data->texture);
+ D3D_DestroyTextureRep(&data->utexture);
+ D3D_DestroyTextureRep(&data->vtexture);
+ SDL_free(data->pixels);
+ SDL_free(data);
+ texture->driverdata = NULL;
+}
+
+static void
+D3D_DestroyRenderer(SDL_Renderer * renderer)
+{
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+
+ if (data) {
+ int i;
+
+ /* Release the render target */
+ if (data->defaultRenderTarget) {
+ IDirect3DSurface9_Release(data->defaultRenderTarget);
+ data->defaultRenderTarget = NULL;
+ }
+ if (data->currentRenderTarget != NULL) {
+ IDirect3DSurface9_Release(data->currentRenderTarget);
+ data->currentRenderTarget = NULL;
+ }
+ for (i = 0; i < SDL_arraysize(data->shaders); ++i) {
+ if (data->shaders[i]) {
+ IDirect3DPixelShader9_Release(data->shaders[i]);
+ data->shaders[i] = NULL;
+ }
+ }
+ if (data->device) {
+ IDirect3DDevice9_Release(data->device);
+ data->device = NULL;
+ }
+ if (data->d3d) {
+ IDirect3D9_Release(data->d3d);
+ SDL_UnloadObject(data->d3dDLL);
+ }
+ SDL_free(data);
+ }
+ SDL_free(renderer);
+}
+#endif /* SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED */
+
+#ifdef __WIN32__
+/* This function needs to always exist on Windows, for the Dynamic API. */
+IDirect3DDevice9 *
+SDL_RenderGetD3D9Device(SDL_Renderer * renderer)
+{
+ IDirect3DDevice9 *device = NULL;
+
+#if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
+ D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
+
+ /* Make sure that this is a D3D renderer */
+ if (renderer->DestroyRenderer != D3D_DestroyRenderer) {
+ SDL_SetError("Renderer is not a D3D renderer");
+ return NULL;
+ }
+
+ device = data->device;
+ if (device) {
+ IDirect3DDevice9_AddRef(device);
+ }
+#endif /* SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED */
+
+ return device;
+}
+#endif /* __WIN32__ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/direct3d/SDL_shaders_d3d.c b/src/3rdparty/SDL2/src/render/direct3d/SDL_shaders_d3d.c
new file mode 100644
index 0000000..b95fddc
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/direct3d/SDL_shaders_d3d.c
@@ -0,0 +1,274 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "SDL_render.h"
+#include "SDL_system.h"
+
+#if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
+
+#include "../../core/windows/SDL_windows.h"
+
+#include <d3d9.h>
+
+#include "SDL_shaders_d3d.h"
+
+/* The shaders here were compiled with:
+
+ fxc /T ps_2_0 /Fo"<OUTPUT FILE>" "<INPUT FILE>"
+
+ Shader object code was converted to a list of DWORDs via the following
+ *nix style command (available separately from Windows + MSVC):
+
+ hexdump -v -e '6/4 "0x%08.8x, " "\n"' <FILE>
+*/
+
+/* --- D3D9_PixelShader_YUV_JPEG.hlsl ---
+ Texture2D theTextureY : register(t0);
+ Texture2D theTextureU : register(t1);
+ Texture2D theTextureV : register(t2);
+ SamplerState theSampler = sampler_state
+ {
+ addressU = Clamp;
+ addressV = Clamp;
+ mipfilter = NONE;
+ minfilter = LINEAR;
+ magfilter = LINEAR;
+ };
+
+ struct PixelShaderInput
+ {
+ float4 pos : SV_POSITION;
+ float2 tex : TEXCOORD0;
+ float4 color : COLOR0;
+ };
+
+ float4 main(PixelShaderInput input) : SV_TARGET
+ {
+ const float3 offset = {0.0, -0.501960814, -0.501960814};
+ const float3 Rcoeff = {1.0000, 0.0000, 1.4020};
+ const float3 Gcoeff = {1.0000, -0.3441, -0.7141};
+ const float3 Bcoeff = {1.0000, 1.7720, 0.0000};
+
+ float4 Output;
+
+ float3 yuv;
+ yuv.x = theTextureY.Sample(theSampler, input.tex).r;
+ yuv.y = theTextureU.Sample(theSampler, input.tex).r;
+ yuv.z = theTextureV.Sample(theSampler, input.tex).r;
+
+ yuv += offset;
+ Output.r = dot(yuv, Rcoeff);
+ Output.g = dot(yuv, Gcoeff);
+ Output.b = dot(yuv, Bcoeff);
+ Output.a = 1.0f;
+
+ return Output * input.color;
+ }
+*/
+static const DWORD D3D9_PixelShader_YUV_JPEG[] = {
+ 0xffff0200, 0x0044fffe, 0x42415443, 0x0000001c, 0x000000d7, 0xffff0200,
+ 0x00000003, 0x0000001c, 0x00000100, 0x000000d0, 0x00000058, 0x00010003,
+ 0x00000001, 0x00000070, 0x00000000, 0x00000080, 0x00020003, 0x00000001,
+ 0x00000098, 0x00000000, 0x000000a8, 0x00000003, 0x00000001, 0x000000c0,
+ 0x00000000, 0x53656874, 0x6c706d61, 0x742b7265, 0x65546568, 0x72757478,
+ 0xab005565, 0x00070004, 0x00040001, 0x00000001, 0x00000000, 0x53656874,
+ 0x6c706d61, 0x742b7265, 0x65546568, 0x72757478, 0xab005665, 0x00070004,
+ 0x00040001, 0x00000001, 0x00000000, 0x53656874, 0x6c706d61, 0x742b7265,
+ 0x65546568, 0x72757478, 0xab005965, 0x00070004, 0x00040001, 0x00000001,
+ 0x00000000, 0x325f7370, 0x4d00305f, 0x6f726369, 0x74666f73, 0x29522820,
+ 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e362072,
+ 0x36392e33, 0x312e3030, 0x34383336, 0xababab00, 0x05000051, 0xa00f0000,
+ 0x00000000, 0xbf008081, 0xbf008081, 0x3f800000, 0x05000051, 0xa00f0001,
+ 0x3f800000, 0x00000000, 0x3fb374bc, 0x00000000, 0x05000051, 0xa00f0002,
+ 0x3f800000, 0xbeb02de0, 0xbf36cf42, 0x00000000, 0x05000051, 0xa00f0003,
+ 0x3f800000, 0x3fe2d0e5, 0x00000000, 0x00000000, 0x0200001f, 0x80000000,
+ 0xb0030000, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f, 0x90000000,
+ 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f, 0x90000000,
+ 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, 0x03000042,
+ 0x800f0001, 0xb0e40000, 0xa0e40801, 0x03000042, 0x800f0002, 0xb0e40000,
+ 0xa0e40802, 0x02000001, 0x80020000, 0x80000001, 0x02000001, 0x80040000,
+ 0x80000002, 0x03000002, 0x80070000, 0x80e40000, 0xa0e40000, 0x03000008,
+ 0x80010001, 0x80e40000, 0xa0e40001, 0x03000008, 0x80020001, 0x80e40000,
+ 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000, 0xa0e40003, 0xa0aa0003,
+ 0x02000001, 0x80080001, 0xa0ff0000, 0x03000005, 0x800f0000, 0x80e40001,
+ 0x90e40000, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff
+};
+
+/* --- D3D9_PixelShader_YUV_BT601.hlsl ---
+ Texture2D theTextureY : register(t0);
+ Texture2D theTextureU : register(t1);
+ Texture2D theTextureV : register(t2);
+ SamplerState theSampler = sampler_state
+ {
+ addressU = Clamp;
+ addressV = Clamp;
+ mipfilter = NONE;
+ minfilter = LINEAR;
+ magfilter = LINEAR;
+ };
+
+ struct PixelShaderInput
+ {
+ float4 pos : SV_POSITION;
+ float2 tex : TEXCOORD0;
+ float4 color : COLOR0;
+ };
+
+ float4 main(PixelShaderInput input) : SV_TARGET
+ {
+ const float3 offset = {-0.0627451017, -0.501960814, -0.501960814};
+ const float3 Rcoeff = {1.1644, 0.0000, 1.5960};
+ const float3 Gcoeff = {1.1644, -0.3918, -0.8130};
+ const float3 Bcoeff = {1.1644, 2.0172, 0.0000};
+
+ float4 Output;
+
+ float3 yuv;
+ yuv.x = theTextureY.Sample(theSampler, input.tex).r;
+ yuv.y = theTextureU.Sample(theSampler, input.tex).r;
+ yuv.z = theTextureV.Sample(theSampler, input.tex).r;
+
+ yuv += offset;
+ Output.r = dot(yuv, Rcoeff);
+ Output.g = dot(yuv, Gcoeff);
+ Output.b = dot(yuv, Bcoeff);
+ Output.a = 1.0f;
+
+ return Output * input.color;
+ }
+*/
+static const DWORD D3D9_PixelShader_YUV_BT601[] = {
+ 0xffff0200, 0x0044fffe, 0x42415443, 0x0000001c, 0x000000d7, 0xffff0200,
+ 0x00000003, 0x0000001c, 0x00000100, 0x000000d0, 0x00000058, 0x00010003,
+ 0x00000001, 0x00000070, 0x00000000, 0x00000080, 0x00020003, 0x00000001,
+ 0x00000098, 0x00000000, 0x000000a8, 0x00000003, 0x00000001, 0x000000c0,
+ 0x00000000, 0x53656874, 0x6c706d61, 0x742b7265, 0x65546568, 0x72757478,
+ 0xab005565, 0x00070004, 0x00040001, 0x00000001, 0x00000000, 0x53656874,
+ 0x6c706d61, 0x742b7265, 0x65546568, 0x72757478, 0xab005665, 0x00070004,
+ 0x00040001, 0x00000001, 0x00000000, 0x53656874, 0x6c706d61, 0x742b7265,
+ 0x65546568, 0x72757478, 0xab005965, 0x00070004, 0x00040001, 0x00000001,
+ 0x00000000, 0x325f7370, 0x4d00305f, 0x6f726369, 0x74666f73, 0x29522820,
+ 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e362072,
+ 0x36392e33, 0x312e3030, 0x34383336, 0xababab00, 0x05000051, 0xa00f0000,
+ 0xbd808081, 0xbf008081, 0xbf008081, 0x3f800000, 0x05000051, 0xa00f0001,
+ 0x3f950b0f, 0x00000000, 0x3fcc49ba, 0x00000000, 0x05000051, 0xa00f0002,
+ 0x3f950b0f, 0xbec89a02, 0xbf5020c5, 0x00000000, 0x05000051, 0xa00f0003,
+ 0x3f950b0f, 0x400119ce, 0x00000000, 0x00000000, 0x0200001f, 0x80000000,
+ 0xb0030000, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f, 0x90000000,
+ 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f, 0x90000000,
+ 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, 0x03000042,
+ 0x800f0001, 0xb0e40000, 0xa0e40801, 0x03000042, 0x800f0002, 0xb0e40000,
+ 0xa0e40802, 0x02000001, 0x80020000, 0x80000001, 0x02000001, 0x80040000,
+ 0x80000002, 0x03000002, 0x80070000, 0x80e40000, 0xa0e40000, 0x03000008,
+ 0x80010001, 0x80e40000, 0xa0e40001, 0x03000008, 0x80020001, 0x80e40000,
+ 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000, 0xa0e40003, 0xa0aa0003,
+ 0x02000001, 0x80080001, 0xa0ff0000, 0x03000005, 0x800f0000, 0x80e40001,
+ 0x90e40000, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff
+};
+
+/* --- D3D9_PixelShader_YUV_BT709.hlsl ---
+ Texture2D theTextureY : register(t0);
+ Texture2D theTextureU : register(t1);
+ Texture2D theTextureV : register(t2);
+ SamplerState theSampler = sampler_state
+ {
+ addressU = Clamp;
+ addressV = Clamp;
+ mipfilter = NONE;
+ minfilter = LINEAR;
+ magfilter = LINEAR;
+ };
+
+ struct PixelShaderInput
+ {
+ float4 pos : SV_POSITION;
+ float2 tex : TEXCOORD0;
+ float4 color : COLOR0;
+ };
+
+ float4 main(PixelShaderInput input) : SV_TARGET
+ {
+ const float3 offset = {-0.0627451017, -0.501960814, -0.501960814};
+ const float3 Rcoeff = {1.1644, 0.0000, 1.7927};
+ const float3 Gcoeff = {1.1644, -0.2132, -0.5329};
+ const float3 Bcoeff = {1.1644, 2.1124, 0.0000};
+
+ float4 Output;
+
+ float3 yuv;
+ yuv.x = theTextureY.Sample(theSampler, input.tex).r;
+ yuv.y = theTextureU.Sample(theSampler, input.tex).r;
+ yuv.z = theTextureV.Sample(theSampler, input.tex).r;
+
+ yuv += offset;
+ Output.r = dot(yuv, Rcoeff);
+ Output.g = dot(yuv, Gcoeff);
+ Output.b = dot(yuv, Bcoeff);
+ Output.a = 1.0f;
+
+ return Output * input.color;
+ }
+*/
+static const DWORD D3D9_PixelShader_YUV_BT709[] = {
+ 0xffff0200, 0x0044fffe, 0x42415443, 0x0000001c, 0x000000d7, 0xffff0200,
+ 0x00000003, 0x0000001c, 0x00000100, 0x000000d0, 0x00000058, 0x00010003,
+ 0x00000001, 0x00000070, 0x00000000, 0x00000080, 0x00020003, 0x00000001,
+ 0x00000098, 0x00000000, 0x000000a8, 0x00000003, 0x00000001, 0x000000c0,
+ 0x00000000, 0x53656874, 0x6c706d61, 0x742b7265, 0x65546568, 0x72757478,
+ 0xab005565, 0x00070004, 0x00040001, 0x00000001, 0x00000000, 0x53656874,
+ 0x6c706d61, 0x742b7265, 0x65546568, 0x72757478, 0xab005665, 0x00070004,
+ 0x00040001, 0x00000001, 0x00000000, 0x53656874, 0x6c706d61, 0x742b7265,
+ 0x65546568, 0x72757478, 0xab005965, 0x00070004, 0x00040001, 0x00000001,
+ 0x00000000, 0x325f7370, 0x4d00305f, 0x6f726369, 0x74666f73, 0x29522820,
+ 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e362072,
+ 0x36392e33, 0x312e3030, 0x34383336, 0xababab00, 0x05000051, 0xa00f0000,
+ 0xbd808081, 0xbf008081, 0xbf008081, 0x3f800000, 0x05000051, 0xa00f0001,
+ 0x3f950b0f, 0x00000000, 0x3fe57732, 0x00000000, 0x05000051, 0xa00f0002,
+ 0x3f950b0f, 0xbe5a511a, 0xbf086c22, 0x00000000, 0x05000051, 0xa00f0003,
+ 0x3f950b0f, 0x40073190, 0x00000000, 0x00000000, 0x0200001f, 0x80000000,
+ 0xb0030000, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f, 0x90000000,
+ 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f, 0x90000000,
+ 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, 0x03000042,
+ 0x800f0001, 0xb0e40000, 0xa0e40801, 0x03000042, 0x800f0002, 0xb0e40000,
+ 0xa0e40802, 0x02000001, 0x80020000, 0x80000001, 0x02000001, 0x80040000,
+ 0x80000002, 0x03000002, 0x80070000, 0x80e40000, 0xa0e40000, 0x03000008,
+ 0x80010001, 0x80e40000, 0xa0e40001, 0x03000008, 0x80020001, 0x80e40000,
+ 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000, 0xa0e40003, 0xa0aa0003,
+ 0x02000001, 0x80080001, 0xa0ff0000, 0x03000005, 0x800f0000, 0x80e40001,
+ 0x90e40000, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff
+};
+
+
+static const DWORD *D3D9_shaders[] = {
+ D3D9_PixelShader_YUV_JPEG,
+ D3D9_PixelShader_YUV_BT601,
+ D3D9_PixelShader_YUV_BT709,
+};
+
+HRESULT D3D9_CreatePixelShader(IDirect3DDevice9 *d3dDevice, D3D9_Shader shader, IDirect3DPixelShader9 **pixelShader)
+{
+ return IDirect3DDevice9_CreatePixelShader(d3dDevice, D3D9_shaders[shader], pixelShader);
+}
+
+#endif /* SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/direct3d/SDL_shaders_d3d.h b/src/3rdparty/SDL2/src/render/direct3d/SDL_shaders_d3d.h
new file mode 100644
index 0000000..8549582
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/direct3d/SDL_shaders_d3d.h
@@ -0,0 +1,34 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+/* D3D9 shader implementation */
+
+typedef enum {
+ SHADER_YUV_JPEG,
+ SHADER_YUV_BT601,
+ SHADER_YUV_BT709,
+ NUM_SHADERS
+} D3D9_Shader;
+
+extern HRESULT D3D9_CreatePixelShader(IDirect3DDevice9 *d3dDevice, D3D9_Shader shader, IDirect3DPixelShader9 **pixelShader);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/direct3d11/SDL_render_d3d11.c b/src/3rdparty/SDL2/src/render/direct3d11/SDL_render_d3d11.c
new file mode 100644
index 0000000..e0ccfc4
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/direct3d11/SDL_render_d3d11.c
@@ -0,0 +1,2570 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
+
+#define COBJMACROS
+#include "../../core/windows/SDL_windows.h"
+#include "SDL_hints.h"
+#include "SDL_loadso.h"
+#include "SDL_syswm.h"
+#include "../SDL_sysrender.h"
+#include "../SDL_d3dmath.h"
+
+#include <d3d11_1.h>
+
+#include "SDL_shaders_d3d11.h"
+
+#ifdef __WINRT__
+
+#if NTDDI_VERSION > NTDDI_WIN8
+#include <DXGI1_3.h>
+#endif
+
+#include "SDL_render_winrt.h"
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_APP
+#include <windows.ui.xaml.media.dxinterop.h>
+/* TODO, WinRT, XAML: get the ISwapChainBackgroundPanelNative from something other than a global var */
+extern ISwapChainBackgroundPanelNative * WINRT_GlobalSwapChainBackgroundPanelNative;
+#endif /* WINAPI_FAMILY == WINAPI_FAMILY_APP */
+
+#endif /* __WINRT__ */
+
+
+#define SDL_COMPOSE_ERROR(str) SDL_STRINGIFY_ARG(__FUNCTION__) ", " str
+
+#define SAFE_RELEASE(X) if ((X)) { IUnknown_Release(SDL_static_cast(IUnknown*, X)); X = NULL; }
+
+
+/* Vertex shader, common values */
+typedef struct
+{
+ Float4X4 model;
+ Float4X4 projectionAndView;
+} VertexShaderConstants;
+
+/* Per-vertex data */
+typedef struct
+{
+ Float3 pos;
+ Float2 tex;
+ Float4 color;
+} VertexPositionColor;
+
+/* Per-texture data */
+typedef struct
+{
+ ID3D11Texture2D *mainTexture;
+ ID3D11ShaderResourceView *mainTextureResourceView;
+ ID3D11RenderTargetView *mainTextureRenderTargetView;
+ ID3D11Texture2D *stagingTexture;
+ int lockedTexturePositionX;
+ int lockedTexturePositionY;
+ D3D11_FILTER scaleMode;
+
+ /* YV12 texture support */
+ SDL_bool yuv;
+ ID3D11Texture2D *mainTextureU;
+ ID3D11ShaderResourceView *mainTextureResourceViewU;
+ ID3D11Texture2D *mainTextureV;
+ ID3D11ShaderResourceView *mainTextureResourceViewV;
+
+ /* NV12 texture support */
+ SDL_bool nv12;
+ ID3D11Texture2D *mainTextureNV;
+ ID3D11ShaderResourceView *mainTextureResourceViewNV;
+
+ Uint8 *pixels;
+ int pitch;
+ SDL_Rect locked_rect;
+} D3D11_TextureData;
+
+/* Blend mode data */
+typedef struct
+{
+ SDL_BlendMode blendMode;
+ ID3D11BlendState *blendState;
+} D3D11_BlendMode;
+
+/* Private renderer data */
+typedef struct
+{
+ void *hDXGIMod;
+ void *hD3D11Mod;
+ IDXGIFactory2 *dxgiFactory;
+ IDXGIAdapter *dxgiAdapter;
+ ID3D11Device1 *d3dDevice;
+ ID3D11DeviceContext1 *d3dContext;
+ IDXGISwapChain1 *swapChain;
+ DXGI_SWAP_EFFECT swapEffect;
+ ID3D11RenderTargetView *mainRenderTargetView;
+ ID3D11RenderTargetView *currentOffscreenRenderTargetView;
+ ID3D11InputLayout *inputLayout;
+ ID3D11Buffer *vertexBuffer;
+ ID3D11VertexShader *vertexShader;
+ ID3D11PixelShader *pixelShaders[NUM_SHADERS];
+ int blendModesCount;
+ D3D11_BlendMode *blendModes;
+ ID3D11SamplerState *nearestPixelSampler;
+ ID3D11SamplerState *linearSampler;
+ D3D_FEATURE_LEVEL featureLevel;
+
+ /* Rasterizers */
+ ID3D11RasterizerState *mainRasterizer;
+ ID3D11RasterizerState *clippedRasterizer;
+
+ /* Vertex buffer constants */
+ VertexShaderConstants vertexShaderConstantsData;
+ ID3D11Buffer *vertexShaderConstants;
+
+ /* Cached renderer properties */
+ DXGI_MODE_ROTATION rotation;
+ ID3D11RenderTargetView *currentRenderTargetView;
+ ID3D11RasterizerState *currentRasterizerState;
+ ID3D11BlendState *currentBlendState;
+ ID3D11PixelShader *currentShader;
+ ID3D11ShaderResourceView *currentShaderResource;
+ ID3D11SamplerState *currentSampler;
+} D3D11_RenderData;
+
+
+/* Define D3D GUIDs here so we don't have to include uuid.lib.
+*
+* Fix for SDL bug https://bugzilla.libsdl.org/show_bug.cgi?id=3437:
+* The extra 'SDL_' was added to the start of each IID's name, in order
+* to prevent build errors on both MinGW-w64 and WinRT/UWP.
+* (SDL bug https://bugzilla.libsdl.org/show_bug.cgi?id=3336 led to
+* linker errors in WinRT/UWP builds.)
+*/
+
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-const-variable"
+#endif
+
+static const GUID SDL_IID_IDXGIFactory2 = { 0x50c83a1c, 0xe072, 0x4c48, { 0x87, 0xb0, 0x36, 0x30, 0xfa, 0x36, 0xa6, 0xd0 } };
+static const GUID SDL_IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } };
+static const GUID SDL_IID_IDXGIDevice3 = { 0x6007896c, 0x3244, 0x4afd, { 0xbf, 0x18, 0xa6, 0xd3, 0xbe, 0xda, 0x50, 0x23 } };
+static const GUID SDL_IID_ID3D11Texture2D = { 0x6f15aaf2, 0xd208, 0x4e89, { 0x9a, 0xb4, 0x48, 0x95, 0x35, 0xd3, 0x4f, 0x9c } };
+static const GUID SDL_IID_ID3D11Device1 = { 0xa04bfb29, 0x08ef, 0x43d6, { 0xa4, 0x9c, 0xa9, 0xbd, 0xbd, 0xcb, 0xe6, 0x86 } };
+static const GUID SDL_IID_ID3D11DeviceContext1 = { 0xbb2c6faa, 0xb5fb, 0x4082, { 0x8e, 0x6b, 0x38, 0x8b, 0x8c, 0xfa, 0x90, 0xe1 } };
+static const GUID SDL_IID_ID3D11Debug = { 0x79cf2233, 0x7536, 0x4948, { 0x9d, 0x36, 0x1e, 0x46, 0x92, 0xdc, 0x57, 0x60 } };
+
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif
+
+
+/* Direct3D 11.1 renderer implementation */
+static SDL_Renderer *D3D11_CreateRenderer(SDL_Window * window, Uint32 flags);
+static void D3D11_WindowEvent(SDL_Renderer * renderer,
+ const SDL_WindowEvent *event);
+static SDL_bool D3D11_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode);
+static int D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+static int D3D11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, const void *srcPixels,
+ int srcPitch);
+static int D3D11_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch);
+static int D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, void **pixels, int *pitch);
+static void D3D11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+static int D3D11_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
+static int D3D11_UpdateViewport(SDL_Renderer * renderer);
+static int D3D11_UpdateClipRect(SDL_Renderer * renderer);
+static int D3D11_RenderClear(SDL_Renderer * renderer);
+static int D3D11_RenderDrawPoints(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count);
+static int D3D11_RenderDrawLines(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count);
+static int D3D11_RenderFillRects(SDL_Renderer * renderer,
+ const SDL_FRect * rects, int count);
+static int D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect);
+static int D3D11_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect,
+ const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip);
+static int D3D11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 format, void * pixels, int pitch);
+static void D3D11_RenderPresent(SDL_Renderer * renderer);
+static void D3D11_DestroyTexture(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static void D3D11_DestroyRenderer(SDL_Renderer * renderer);
+
+/* Direct3D 11.1 Internal Functions */
+static HRESULT D3D11_CreateDeviceResources(SDL_Renderer * renderer);
+static HRESULT D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer);
+static HRESULT D3D11_UpdateForWindowSizeChange(SDL_Renderer * renderer);
+static HRESULT D3D11_HandleDeviceLost(SDL_Renderer * renderer);
+static void D3D11_ReleaseMainRenderTargetView(SDL_Renderer * renderer);
+
+SDL_RenderDriver D3D11_RenderDriver = {
+ D3D11_CreateRenderer,
+ {
+ "direct3d11",
+ (
+ SDL_RENDERER_ACCELERATED |
+ SDL_RENDERER_PRESENTVSYNC |
+ SDL_RENDERER_TARGETTEXTURE
+ ), /* flags. see SDL_RendererFlags */
+ 6, /* num_texture_formats */
+ { /* texture_formats */
+ SDL_PIXELFORMAT_ARGB8888,
+ SDL_PIXELFORMAT_RGB888,
+ SDL_PIXELFORMAT_YV12,
+ SDL_PIXELFORMAT_IYUV,
+ SDL_PIXELFORMAT_NV12,
+ SDL_PIXELFORMAT_NV21
+ },
+ 0, /* max_texture_width: will be filled in later */
+ 0 /* max_texture_height: will be filled in later */
+ }
+};
+
+
+Uint32
+D3D11_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat)
+{
+ switch (dxgiFormat) {
+ case DXGI_FORMAT_B8G8R8A8_UNORM:
+ return SDL_PIXELFORMAT_ARGB8888;
+ case DXGI_FORMAT_B8G8R8X8_UNORM:
+ return SDL_PIXELFORMAT_RGB888;
+ default:
+ return SDL_PIXELFORMAT_UNKNOWN;
+ }
+}
+
+static DXGI_FORMAT
+SDLPixelFormatToDXGIFormat(Uint32 sdlFormat)
+{
+ switch (sdlFormat) {
+ case SDL_PIXELFORMAT_ARGB8888:
+ return DXGI_FORMAT_B8G8R8A8_UNORM;
+ case SDL_PIXELFORMAT_RGB888:
+ return DXGI_FORMAT_B8G8R8X8_UNORM;
+ case SDL_PIXELFORMAT_YV12:
+ case SDL_PIXELFORMAT_IYUV:
+ case SDL_PIXELFORMAT_NV12: /* For the Y texture */
+ case SDL_PIXELFORMAT_NV21: /* For the Y texture */
+ return DXGI_FORMAT_R8_UNORM;
+ default:
+ return DXGI_FORMAT_UNKNOWN;
+ }
+}
+
+SDL_Renderer *
+D3D11_CreateRenderer(SDL_Window * window, Uint32 flags)
+{
+ SDL_Renderer *renderer;
+ D3D11_RenderData *data;
+
+ renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
+ if (!renderer) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ data = (D3D11_RenderData *) SDL_calloc(1, sizeof(*data));
+ if (!data) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ renderer->WindowEvent = D3D11_WindowEvent;
+ renderer->SupportsBlendMode = D3D11_SupportsBlendMode;
+ renderer->CreateTexture = D3D11_CreateTexture;
+ renderer->UpdateTexture = D3D11_UpdateTexture;
+ renderer->UpdateTextureYUV = D3D11_UpdateTextureYUV;
+ renderer->LockTexture = D3D11_LockTexture;
+ renderer->UnlockTexture = D3D11_UnlockTexture;
+ renderer->SetRenderTarget = D3D11_SetRenderTarget;
+ renderer->UpdateViewport = D3D11_UpdateViewport;
+ renderer->UpdateClipRect = D3D11_UpdateClipRect;
+ renderer->RenderClear = D3D11_RenderClear;
+ renderer->RenderDrawPoints = D3D11_RenderDrawPoints;
+ renderer->RenderDrawLines = D3D11_RenderDrawLines;
+ renderer->RenderFillRects = D3D11_RenderFillRects;
+ renderer->RenderCopy = D3D11_RenderCopy;
+ renderer->RenderCopyEx = D3D11_RenderCopyEx;
+ renderer->RenderReadPixels = D3D11_RenderReadPixels;
+ renderer->RenderPresent = D3D11_RenderPresent;
+ renderer->DestroyTexture = D3D11_DestroyTexture;
+ renderer->DestroyRenderer = D3D11_DestroyRenderer;
+ renderer->info = D3D11_RenderDriver.info;
+ renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
+ renderer->driverdata = data;
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+ /* VSync is required in Windows Phone, at least for Win Phone 8.0 and 8.1.
+ * Failure to use it seems to either result in:
+ *
+ * - with the D3D11 debug runtime turned OFF, vsync seemingly gets turned
+ * off (framerate doesn't get capped), but nothing appears on-screen
+ *
+ * - with the D3D11 debug runtime turned ON, vsync gets automatically
+ * turned back on, and the following gets output to the debug console:
+ *
+ * DXGI ERROR: IDXGISwapChain::Present: Interval 0 is not supported, changed to Interval 1. [ UNKNOWN ERROR #1024: ]
+ */
+ renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
+#else
+ if ((flags & SDL_RENDERER_PRESENTVSYNC)) {
+ renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
+ }
+#endif
+
+ /* HACK: make sure the SDL_Renderer references the SDL_Window data now, in
+ * order to give init functions access to the underlying window handle:
+ */
+ renderer->window = window;
+
+ /* Initialize Direct3D resources */
+ if (FAILED(D3D11_CreateDeviceResources(renderer))) {
+ D3D11_DestroyRenderer(renderer);
+ return NULL;
+ }
+ if (FAILED(D3D11_CreateWindowSizeDependentResources(renderer))) {
+ D3D11_DestroyRenderer(renderer);
+ return NULL;
+ }
+
+ return renderer;
+}
+
+static void
+D3D11_ReleaseAll(SDL_Renderer * renderer)
+{
+ D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
+ SDL_Texture *texture = NULL;
+
+ /* Release all textures */
+ for (texture = renderer->textures; texture; texture = texture->next) {
+ D3D11_DestroyTexture(renderer, texture);
+ }
+
+ /* Release/reset everything else */
+ if (data) {
+ int i;
+
+ SAFE_RELEASE(data->dxgiFactory);
+ SAFE_RELEASE(data->dxgiAdapter);
+ SAFE_RELEASE(data->d3dDevice);
+ SAFE_RELEASE(data->d3dContext);
+ SAFE_RELEASE(data->swapChain);
+ SAFE_RELEASE(data->mainRenderTargetView);
+ SAFE_RELEASE(data->currentOffscreenRenderTargetView);
+ SAFE_RELEASE(data->inputLayout);
+ SAFE_RELEASE(data->vertexBuffer);
+ SAFE_RELEASE(data->vertexShader);
+ for (i = 0; i < SDL_arraysize(data->pixelShaders); ++i) {
+ SAFE_RELEASE(data->pixelShaders[i]);
+ }
+ if (data->blendModesCount > 0) {
+ for (i = 0; i < data->blendModesCount; ++i) {
+ SAFE_RELEASE(data->blendModes[i].blendState);
+ }
+ SDL_free(data->blendModes);
+
+ data->blendModesCount = 0;
+ }
+ SAFE_RELEASE(data->nearestPixelSampler);
+ SAFE_RELEASE(data->linearSampler);
+ SAFE_RELEASE(data->mainRasterizer);
+ SAFE_RELEASE(data->clippedRasterizer);
+ SAFE_RELEASE(data->vertexShaderConstants);
+
+ data->swapEffect = (DXGI_SWAP_EFFECT) 0;
+ data->rotation = DXGI_MODE_ROTATION_UNSPECIFIED;
+ data->currentRenderTargetView = NULL;
+ data->currentRasterizerState = NULL;
+ data->currentBlendState = NULL;
+ data->currentShader = NULL;
+ data->currentShaderResource = NULL;
+ data->currentSampler = NULL;
+
+ /* Unload the D3D libraries. This should be done last, in order
+ * to prevent IUnknown::Release() calls from crashing.
+ */
+ if (data->hD3D11Mod) {
+ SDL_UnloadObject(data->hD3D11Mod);
+ data->hD3D11Mod = NULL;
+ }
+ if (data->hDXGIMod) {
+ SDL_UnloadObject(data->hDXGIMod);
+ data->hDXGIMod = NULL;
+ }
+ }
+}
+
+static void
+D3D11_DestroyRenderer(SDL_Renderer * renderer)
+{
+ D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
+ D3D11_ReleaseAll(renderer);
+ if (data) {
+ SDL_free(data);
+ }
+ SDL_free(renderer);
+}
+
+static D3D11_BLEND GetBlendFunc(SDL_BlendFactor factor)
+{
+ switch (factor) {
+ case SDL_BLENDFACTOR_ZERO:
+ return D3D11_BLEND_ZERO;
+ case SDL_BLENDFACTOR_ONE:
+ return D3D11_BLEND_ONE;
+ case SDL_BLENDFACTOR_SRC_COLOR:
+ return D3D11_BLEND_SRC_COLOR;
+ case SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR:
+ return D3D11_BLEND_INV_SRC_COLOR;
+ case SDL_BLENDFACTOR_SRC_ALPHA:
+ return D3D11_BLEND_SRC_ALPHA;
+ case SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA:
+ return D3D11_BLEND_INV_SRC_ALPHA;
+ case SDL_BLENDFACTOR_DST_COLOR:
+ return D3D11_BLEND_DEST_COLOR;
+ case SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR:
+ return D3D11_BLEND_INV_DEST_COLOR;
+ case SDL_BLENDFACTOR_DST_ALPHA:
+ return D3D11_BLEND_DEST_ALPHA;
+ case SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA:
+ return D3D11_BLEND_INV_DEST_ALPHA;
+ default:
+ return (D3D11_BLEND)0;
+ }
+}
+
+static D3D11_BLEND_OP GetBlendEquation(SDL_BlendOperation operation)
+{
+ switch (operation) {
+ case SDL_BLENDOPERATION_ADD:
+ return D3D11_BLEND_OP_ADD;
+ case SDL_BLENDOPERATION_SUBTRACT:
+ return D3D11_BLEND_OP_SUBTRACT;
+ case SDL_BLENDOPERATION_REV_SUBTRACT:
+ return D3D11_BLEND_OP_REV_SUBTRACT;
+ case SDL_BLENDOPERATION_MINIMUM:
+ return D3D11_BLEND_OP_MIN;
+ case SDL_BLENDOPERATION_MAXIMUM:
+ return D3D11_BLEND_OP_MAX;
+ default:
+ return (D3D11_BLEND_OP)0;
+ }
+}
+
+static SDL_bool
+D3D11_CreateBlendState(SDL_Renderer * renderer, SDL_BlendMode blendMode)
+{
+ D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
+ SDL_BlendFactor srcColorFactor = SDL_GetBlendModeSrcColorFactor(blendMode);
+ SDL_BlendFactor srcAlphaFactor = SDL_GetBlendModeSrcAlphaFactor(blendMode);
+ SDL_BlendOperation colorOperation = SDL_GetBlendModeColorOperation(blendMode);
+ SDL_BlendFactor dstColorFactor = SDL_GetBlendModeDstColorFactor(blendMode);
+ SDL_BlendFactor dstAlphaFactor = SDL_GetBlendModeDstAlphaFactor(blendMode);
+ SDL_BlendOperation alphaOperation = SDL_GetBlendModeAlphaOperation(blendMode);
+ ID3D11BlendState *blendState = NULL;
+ D3D11_BlendMode *blendModes;
+ HRESULT result = S_OK;
+
+ D3D11_BLEND_DESC blendDesc;
+ SDL_zero(blendDesc);
+ blendDesc.AlphaToCoverageEnable = FALSE;
+ blendDesc.IndependentBlendEnable = FALSE;
+ blendDesc.RenderTarget[0].BlendEnable = TRUE;
+ blendDesc.RenderTarget[0].SrcBlend = GetBlendFunc(srcColorFactor);
+ blendDesc.RenderTarget[0].DestBlend = GetBlendFunc(dstColorFactor);
+ blendDesc.RenderTarget[0].BlendOp = GetBlendEquation(colorOperation);
+ blendDesc.RenderTarget[0].SrcBlendAlpha = GetBlendFunc(srcAlphaFactor);
+ blendDesc.RenderTarget[0].DestBlendAlpha = GetBlendFunc(dstAlphaFactor);
+ blendDesc.RenderTarget[0].BlendOpAlpha = GetBlendEquation(alphaOperation);
+ blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
+ result = ID3D11Device_CreateBlendState(data->d3dDevice, &blendDesc, &blendState);
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateBlendState"), result);
+ return SDL_FALSE;
+ }
+
+ blendModes = (D3D11_BlendMode *)SDL_realloc(data->blendModes, (data->blendModesCount + 1) * sizeof(*blendModes));
+ if (!blendModes) {
+ SAFE_RELEASE(blendState);
+ SDL_OutOfMemory();
+ return SDL_FALSE;
+ }
+ blendModes[data->blendModesCount].blendMode = blendMode;
+ blendModes[data->blendModesCount].blendState = blendState;
+ data->blendModes = blendModes;
+ ++data->blendModesCount;
+
+ return SDL_TRUE;
+}
+
+/* Create resources that depend on the device. */
+static HRESULT
+D3D11_CreateDeviceResources(SDL_Renderer * renderer)
+{
+ typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID riid, void **ppFactory);
+ PFN_CREATE_DXGI_FACTORY CreateDXGIFactoryFunc;
+ D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
+ PFN_D3D11_CREATE_DEVICE D3D11CreateDeviceFunc;
+ ID3D11Device *d3dDevice = NULL;
+ ID3D11DeviceContext *d3dContext = NULL;
+ IDXGIDevice1 *dxgiDevice = NULL;
+ HRESULT result = S_OK;
+ UINT creationFlags;
+ int i;
+
+ /* This array defines the set of DirectX hardware feature levels this app will support.
+ * Note the ordering should be preserved.
+ * Don't forget to declare your application's minimum required feature level in its
+ * description. All applications are assumed to support 9.1 unless otherwise stated.
+ */
+ D3D_FEATURE_LEVEL featureLevels[] =
+ {
+ D3D_FEATURE_LEVEL_11_1,
+ D3D_FEATURE_LEVEL_11_0,
+ D3D_FEATURE_LEVEL_10_1,
+ D3D_FEATURE_LEVEL_10_0,
+ D3D_FEATURE_LEVEL_9_3,
+ D3D_FEATURE_LEVEL_9_2,
+ D3D_FEATURE_LEVEL_9_1
+ };
+
+ D3D11_BUFFER_DESC constantBufferDesc;
+ D3D11_SAMPLER_DESC samplerDesc;
+ D3D11_RASTERIZER_DESC rasterDesc;
+
+#ifdef __WINRT__
+ CreateDXGIFactoryFunc = CreateDXGIFactory1;
+ D3D11CreateDeviceFunc = D3D11CreateDevice;
+#else
+ data->hDXGIMod = SDL_LoadObject("dxgi.dll");
+ if (!data->hDXGIMod) {
+ result = E_FAIL;
+ goto done;
+ }
+
+ CreateDXGIFactoryFunc = (PFN_CREATE_DXGI_FACTORY)SDL_LoadFunction(data->hDXGIMod, "CreateDXGIFactory");
+ if (!CreateDXGIFactoryFunc) {
+ result = E_FAIL;
+ goto done;
+ }
+
+ data->hD3D11Mod = SDL_LoadObject("d3d11.dll");
+ if (!data->hD3D11Mod) {
+ result = E_FAIL;
+ goto done;
+ }
+
+ D3D11CreateDeviceFunc = (PFN_D3D11_CREATE_DEVICE)SDL_LoadFunction(data->hD3D11Mod, "D3D11CreateDevice");
+ if (!D3D11CreateDeviceFunc) {
+ result = E_FAIL;
+ goto done;
+ }
+#endif /* __WINRT__ */
+
+ result = CreateDXGIFactoryFunc(&SDL_IID_IDXGIFactory2, (void **)&data->dxgiFactory);
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("CreateDXGIFactory"), result);
+ goto done;
+ }
+
+ /* FIXME: Should we use the default adapter? */
+ result = IDXGIFactory2_EnumAdapters(data->dxgiFactory, 0, &data->dxgiAdapter);
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("D3D11CreateDevice"), result);
+ goto done;
+ }
+
+ /* This flag adds support for surfaces with a different color channel ordering
+ * than the API default. It is required for compatibility with Direct2D.
+ */
+ creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
+
+ /* Make sure Direct3D's debugging feature gets used, if the app requests it. */
+ if (SDL_GetHintBoolean(SDL_HINT_RENDER_DIRECT3D11_DEBUG, SDL_FALSE)) {
+ creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
+ }
+
+ /* Create the Direct3D 11 API device object and a corresponding context. */
+ result = D3D11CreateDeviceFunc(
+ data->dxgiAdapter,
+ D3D_DRIVER_TYPE_UNKNOWN,
+ NULL,
+ creationFlags, /* Set set debug and Direct2D compatibility flags. */
+ featureLevels, /* List of feature levels this app can support. */
+ SDL_arraysize(featureLevels),
+ D3D11_SDK_VERSION, /* Always set this to D3D11_SDK_VERSION for Windows Store apps. */
+ &d3dDevice, /* Returns the Direct3D device created. */
+ &data->featureLevel, /* Returns feature level of device created. */
+ &d3dContext /* Returns the device immediate context. */
+ );
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("D3D11CreateDevice"), result);
+ goto done;
+ }
+
+ result = ID3D11Device_QueryInterface(d3dDevice, &SDL_IID_ID3D11Device1, (void **)&data->d3dDevice);
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device to ID3D11Device1"), result);
+ goto done;
+ }
+
+ result = ID3D11DeviceContext_QueryInterface(d3dContext, &SDL_IID_ID3D11DeviceContext1, (void **)&data->d3dContext);
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext to ID3D11DeviceContext1"), result);
+ goto done;
+ }
+
+ result = ID3D11Device_QueryInterface(d3dDevice, &SDL_IID_IDXGIDevice1, (void **)&dxgiDevice);
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device to IDXGIDevice1"), result);
+ goto done;
+ }
+
+ /* Ensure that DXGI does not queue more than one frame at a time. This both reduces latency and
+ * ensures that the application will only render after each VSync, minimizing power consumption.
+ */
+ result = IDXGIDevice1_SetMaximumFrameLatency(dxgiDevice, 1);
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGIDevice1::SetMaximumFrameLatency"), result);
+ goto done;
+ }
+
+ /* Make note of the maximum texture size
+ * Max texture sizes are documented on MSDN, at:
+ * http://msdn.microsoft.com/en-us/library/windows/apps/ff476876.aspx
+ */
+ switch (data->featureLevel) {
+ case D3D_FEATURE_LEVEL_11_1:
+ case D3D_FEATURE_LEVEL_11_0:
+ renderer->info.max_texture_width = renderer->info.max_texture_height = 16384;
+ break;
+
+ case D3D_FEATURE_LEVEL_10_1:
+ case D3D_FEATURE_LEVEL_10_0:
+ renderer->info.max_texture_width = renderer->info.max_texture_height = 8192;
+ break;
+
+ case D3D_FEATURE_LEVEL_9_3:
+ renderer->info.max_texture_width = renderer->info.max_texture_height = 4096;
+ break;
+
+ case D3D_FEATURE_LEVEL_9_2:
+ case D3D_FEATURE_LEVEL_9_1:
+ renderer->info.max_texture_width = renderer->info.max_texture_height = 2048;
+ break;
+
+ default:
+ SDL_SetError("%s, Unexpected feature level: %d", __FUNCTION__, data->featureLevel);
+ result = E_FAIL;
+ goto done;
+ }
+
+ if (D3D11_CreateVertexShader(data->d3dDevice, &data->vertexShader, &data->inputLayout) < 0) {
+ goto done;
+ }
+
+ for (i = 0; i < SDL_arraysize(data->pixelShaders); ++i) {
+ if (D3D11_CreatePixelShader(data->d3dDevice, (D3D11_Shader)i, &data->pixelShaders[i]) < 0) {
+ goto done;
+ }
+ }
+
+ /* Setup space to hold vertex shader constants: */
+ SDL_zero(constantBufferDesc);
+ constantBufferDesc.ByteWidth = sizeof(VertexShaderConstants);
+ constantBufferDesc.Usage = D3D11_USAGE_DEFAULT;
+ constantBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
+ result = ID3D11Device_CreateBuffer(data->d3dDevice,
+ &constantBufferDesc,
+ NULL,
+ &data->vertexShaderConstants
+ );
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateBuffer [vertex shader constants]"), result);
+ goto done;
+ }
+
+ /* Create samplers to use when drawing textures: */
+ SDL_zero(samplerDesc);
+ samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
+ samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
+ samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
+ samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
+ samplerDesc.MipLODBias = 0.0f;
+ samplerDesc.MaxAnisotropy = 1;
+ samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
+ samplerDesc.MinLOD = 0.0f;
+ samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
+ result = ID3D11Device_CreateSamplerState(data->d3dDevice,
+ &samplerDesc,
+ &data->nearestPixelSampler
+ );
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateSamplerState [nearest-pixel filter]"), result);
+ goto done;
+ }
+
+ samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
+ result = ID3D11Device_CreateSamplerState(data->d3dDevice,
+ &samplerDesc,
+ &data->linearSampler
+ );
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateSamplerState [linear filter]"), result);
+ goto done;
+ }
+
+ /* Setup Direct3D rasterizer states */
+ SDL_zero(rasterDesc);
+ rasterDesc.AntialiasedLineEnable = FALSE;
+ rasterDesc.CullMode = D3D11_CULL_NONE;
+ rasterDesc.DepthBias = 0;
+ rasterDesc.DepthBiasClamp = 0.0f;
+ rasterDesc.DepthClipEnable = TRUE;
+ rasterDesc.FillMode = D3D11_FILL_SOLID;
+ rasterDesc.FrontCounterClockwise = FALSE;
+ rasterDesc.MultisampleEnable = FALSE;
+ rasterDesc.ScissorEnable = FALSE;
+ rasterDesc.SlopeScaledDepthBias = 0.0f;
+ result = ID3D11Device_CreateRasterizerState(data->d3dDevice, &rasterDesc, &data->mainRasterizer);
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateRasterizerState [main rasterizer]"), result);
+ goto done;
+ }
+
+ rasterDesc.ScissorEnable = TRUE;
+ result = ID3D11Device_CreateRasterizerState(data->d3dDevice, &rasterDesc, &data->clippedRasterizer);
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateRasterizerState [clipped rasterizer]"), result);
+ goto done;
+ }
+
+ /* Create blending states: */
+ if (!D3D11_CreateBlendState(renderer, SDL_BLENDMODE_BLEND) ||
+ !D3D11_CreateBlendState(renderer, SDL_BLENDMODE_ADD) ||
+ !D3D11_CreateBlendState(renderer, SDL_BLENDMODE_MOD)) {
+ /* D3D11_CreateBlendMode will set the SDL error, if it fails */
+ goto done;
+ }
+
+ /* Setup render state that doesn't change */
+ ID3D11DeviceContext_IASetInputLayout(data->d3dContext, data->inputLayout);
+ ID3D11DeviceContext_VSSetShader(data->d3dContext, data->vertexShader, NULL, 0);
+ ID3D11DeviceContext_VSSetConstantBuffers(data->d3dContext, 0, 1, &data->vertexShaderConstants);
+
+done:
+ SAFE_RELEASE(d3dDevice);
+ SAFE_RELEASE(d3dContext);
+ SAFE_RELEASE(dxgiDevice);
+ return result;
+}
+
+#ifdef __WIN32__
+
+static DXGI_MODE_ROTATION
+D3D11_GetCurrentRotation()
+{
+ /* FIXME */
+ return DXGI_MODE_ROTATION_IDENTITY;
+}
+
+#endif /* __WIN32__ */
+
+static BOOL
+D3D11_IsDisplayRotated90Degrees(DXGI_MODE_ROTATION rotation)
+{
+ switch (rotation) {
+ case DXGI_MODE_ROTATION_ROTATE90:
+ case DXGI_MODE_ROTATION_ROTATE270:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
+static int
+D3D11_GetRotationForCurrentRenderTarget(SDL_Renderer * renderer)
+{
+ D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata;
+ if (data->currentOffscreenRenderTargetView) {
+ return DXGI_MODE_ROTATION_IDENTITY;
+ } else {
+ return data->rotation;
+ }
+}
+
+static int
+D3D11_GetViewportAlignedD3DRect(SDL_Renderer * renderer, const SDL_Rect * sdlRect, D3D11_RECT * outRect, BOOL includeViewportOffset)
+{
+ const int rotation = D3D11_GetRotationForCurrentRenderTarget(renderer);
+ switch (rotation) {
+ case DXGI_MODE_ROTATION_IDENTITY:
+ outRect->left = sdlRect->x;
+ outRect->right = sdlRect->x + sdlRect->w;
+ outRect->top = sdlRect->y;
+ outRect->bottom = sdlRect->y + sdlRect->h;
+ if (includeViewportOffset) {
+ outRect->left += renderer->viewport.x;
+ outRect->right += renderer->viewport.x;
+ outRect->top += renderer->viewport.y;
+ outRect->bottom += renderer->viewport.y;
+ }
+ break;
+ case DXGI_MODE_ROTATION_ROTATE270:
+ outRect->left = sdlRect->y;
+ outRect->right = sdlRect->y + sdlRect->h;
+ outRect->top = renderer->viewport.w - sdlRect->x - sdlRect->w;
+ outRect->bottom = renderer->viewport.w - sdlRect->x;
+ break;
+ case DXGI_MODE_ROTATION_ROTATE180:
+ outRect->left = renderer->viewport.w - sdlRect->x - sdlRect->w;
+ outRect->right = renderer->viewport.w - sdlRect->x;
+ outRect->top = renderer->viewport.h - sdlRect->y - sdlRect->h;
+ outRect->bottom = renderer->viewport.h - sdlRect->y;
+ break;
+ case DXGI_MODE_ROTATION_ROTATE90:
+ outRect->left = renderer->viewport.h - sdlRect->y - sdlRect->h;
+ outRect->right = renderer->viewport.h - sdlRect->y;
+ outRect->top = sdlRect->x;
+ outRect->bottom = sdlRect->x + sdlRect->h;
+ break;
+ default:
+ return SDL_SetError("The physical display is in an unknown or unsupported rotation");
+ }
+ return 0;
+}
+
+static HRESULT
+D3D11_CreateSwapChain(SDL_Renderer * renderer, int w, int h)
+{
+ D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata;
+#ifdef __WINRT__
+ IUnknown *coreWindow = D3D11_GetCoreWindowFromSDLRenderer(renderer);
+ const BOOL usingXAML = (coreWindow == NULL);
+#else
+ IUnknown *coreWindow = NULL;
+ const BOOL usingXAML = FALSE;
+#endif
+ HRESULT result = S_OK;
+
+ /* Create a swap chain using the same adapter as the existing Direct3D device. */
+ DXGI_SWAP_CHAIN_DESC1 swapChainDesc;
+ SDL_zero(swapChainDesc);
+ swapChainDesc.Width = w;
+ swapChainDesc.Height = h;
+ swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; /* This is the most common swap chain format. */
+ swapChainDesc.Stereo = FALSE;
+ swapChainDesc.SampleDesc.Count = 1; /* Don't use multi-sampling. */
+ swapChainDesc.SampleDesc.Quality = 0;
+ swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+ swapChainDesc.BufferCount = 2; /* Use double-buffering to minimize latency. */
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+ swapChainDesc.Scaling = DXGI_SCALING_STRETCH; /* On phone, only stretch and aspect-ratio stretch scaling are allowed. */
+ swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; /* On phone, no swap effects are supported. */
+ /* TODO, WinRT: see if Win 8.x DXGI_SWAP_CHAIN_DESC1 settings are available on Windows Phone 8.1, and if there's any advantage to having them on */
+#else
+ if (usingXAML) {
+ swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
+ } else {
+ swapChainDesc.Scaling = DXGI_SCALING_NONE;
+ }
+ swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; /* All Windows Store apps must use this SwapEffect. */
+#endif
+ swapChainDesc.Flags = 0;
+
+ if (coreWindow) {
+ result = IDXGIFactory2_CreateSwapChainForCoreWindow(data->dxgiFactory,
+ (IUnknown *)data->d3dDevice,
+ coreWindow,
+ &swapChainDesc,
+ NULL, /* Allow on all displays. */
+ &data->swapChain
+ );
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGIFactory2::CreateSwapChainForCoreWindow"), result);
+ goto done;
+ }
+ } else if (usingXAML) {
+ result = IDXGIFactory2_CreateSwapChainForComposition(data->dxgiFactory,
+ (IUnknown *)data->d3dDevice,
+ &swapChainDesc,
+ NULL,
+ &data->swapChain);
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGIFactory2::CreateSwapChainForComposition"), result);
+ goto done;
+ }
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_APP
+ result = ISwapChainBackgroundPanelNative_SetSwapChain(WINRT_GlobalSwapChainBackgroundPanelNative, (IDXGISwapChain *) data->swapChain);
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ISwapChainBackgroundPanelNative::SetSwapChain"), result);
+ goto done;
+ }
+#else
+ SDL_SetError(SDL_COMPOSE_ERROR("XAML support is not yet available for Windows Phone"));
+ result = E_FAIL;
+ goto done;
+#endif
+ } else {
+#ifdef __WIN32__
+ SDL_SysWMinfo windowinfo;
+ SDL_VERSION(&windowinfo.version);
+ SDL_GetWindowWMInfo(renderer->window, &windowinfo);
+
+ result = IDXGIFactory2_CreateSwapChainForHwnd(data->dxgiFactory,
+ (IUnknown *)data->d3dDevice,
+ windowinfo.info.win.window,
+ &swapChainDesc,
+ NULL,
+ NULL, /* Allow on all displays. */
+ &data->swapChain
+ );
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGIFactory2::CreateSwapChainForHwnd"), result);
+ goto done;
+ }
+
+ IDXGIFactory_MakeWindowAssociation(data->dxgiFactory, windowinfo.info.win.window, DXGI_MWA_NO_WINDOW_CHANGES);
+#else
+ SDL_SetError(__FUNCTION__", Unable to find something to attach a swap chain to");
+ goto done;
+#endif /* ifdef __WIN32__ / else */
+ }
+ data->swapEffect = swapChainDesc.SwapEffect;
+
+done:
+ SAFE_RELEASE(coreWindow);
+ return result;
+}
+
+
+/* Initialize all resources that change when the window's size changes. */
+static HRESULT
+D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
+{
+ D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata;
+ ID3D11Texture2D *backBuffer = NULL;
+ HRESULT result = S_OK;
+ int w, h;
+
+ /* Release the previous render target view */
+ D3D11_ReleaseMainRenderTargetView(renderer);
+
+ /* The width and height of the swap chain must be based on the display's
+ * non-rotated size.
+ */
+ SDL_GetWindowSize(renderer->window, &w, &h);
+ data->rotation = D3D11_GetCurrentRotation();
+ /* SDL_Log("%s: windowSize={%d,%d}, orientation=%d\n", __FUNCTION__, w, h, (int)data->rotation); */
+ if (D3D11_IsDisplayRotated90Degrees(data->rotation)) {
+ int tmp = w;
+ w = h;
+ h = tmp;
+ }
+
+ if (data->swapChain) {
+ /* IDXGISwapChain::ResizeBuffers is not available on Windows Phone 8. */
+#if !defined(__WINRT__) || (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP)
+ /* If the swap chain already exists, resize it. */
+ result = IDXGISwapChain_ResizeBuffers(data->swapChain,
+ 0,
+ w, h,
+ DXGI_FORMAT_UNKNOWN,
+ 0
+ );
+ if (result == DXGI_ERROR_DEVICE_REMOVED) {
+ /* If the device was removed for any reason, a new device and swap chain will need to be created. */
+ D3D11_HandleDeviceLost(renderer);
+
+ /* Everything is set up now. Do not continue execution of this method. HandleDeviceLost will reenter this method
+ * and correctly set up the new device.
+ */
+ goto done;
+ } else if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain::ResizeBuffers"), result);
+ goto done;
+ }
+#endif
+ } else {
+ result = D3D11_CreateSwapChain(renderer, w, h);
+ if (FAILED(result)) {
+ goto done;
+ }
+ }
+
+#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
+ /* Set the proper rotation for the swap chain.
+ *
+ * To note, the call for this, IDXGISwapChain1::SetRotation, is not necessary
+ * on Windows Phone 8.0, nor is it supported there.
+ *
+ * IDXGISwapChain1::SetRotation does seem to be available on Windows Phone 8.1,
+ * however I've yet to find a way to make it work. It might have something to
+ * do with IDXGISwapChain::ResizeBuffers appearing to not being available on
+ * Windows Phone 8.1 (it wasn't on Windows Phone 8.0), but I'm not 100% sure of this.
+ * The call doesn't appear to be entirely necessary though, and is a performance-related
+ * call, at least according to the following page on MSDN:
+ * http://code.msdn.microsoft.com/windowsapps/DXGI-swap-chain-rotation-21d13d71
+ * -- David L.
+ *
+ * TODO, WinRT: reexamine the docs for IDXGISwapChain1::SetRotation, see if might be available, usable, and prudent-to-call on WinPhone 8.1
+ */
+ if (data->swapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL) {
+ result = IDXGISwapChain1_SetRotation(data->swapChain, data->rotation);
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain1::SetRotation"), result);
+ goto done;
+ }
+ }
+#endif
+
+ result = IDXGISwapChain_GetBuffer(data->swapChain,
+ 0,
+ &SDL_IID_ID3D11Texture2D,
+ (void **)&backBuffer
+ );
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain::GetBuffer [back-buffer]"), result);
+ goto done;
+ }
+
+ /* Create a render target view of the swap chain back buffer. */
+ result = ID3D11Device_CreateRenderTargetView(data->d3dDevice,
+ (ID3D11Resource *)backBuffer,
+ NULL,
+ &data->mainRenderTargetView
+ );
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device::CreateRenderTargetView"), result);
+ goto done;
+ }
+
+ if (D3D11_UpdateViewport(renderer) != 0) {
+ /* D3D11_UpdateViewport will set the SDL error if it fails. */
+ result = E_FAIL;
+ goto done;
+ }
+
+done:
+ SAFE_RELEASE(backBuffer);
+ return result;
+}
+
+/* This method is called when the window's size changes. */
+static HRESULT
+D3D11_UpdateForWindowSizeChange(SDL_Renderer * renderer)
+{
+ return D3D11_CreateWindowSizeDependentResources(renderer);
+}
+
+HRESULT
+D3D11_HandleDeviceLost(SDL_Renderer * renderer)
+{
+ HRESULT result = S_OK;
+
+ D3D11_ReleaseAll(renderer);
+
+ result = D3D11_CreateDeviceResources(renderer);
+ if (FAILED(result)) {
+ /* D3D11_CreateDeviceResources will set the SDL error */
+ return result;
+ }
+
+ result = D3D11_UpdateForWindowSizeChange(renderer);
+ if (FAILED(result)) {
+ /* D3D11_UpdateForWindowSizeChange will set the SDL error */
+ return result;
+ }
+
+ /* Let the application know that the device has been reset */
+ {
+ SDL_Event event;
+ event.type = SDL_RENDER_DEVICE_RESET;
+ SDL_PushEvent(&event);
+ }
+
+ return S_OK;
+}
+
+void
+D3D11_Trim(SDL_Renderer * renderer)
+{
+#ifdef __WINRT__
+#if NTDDI_VERSION > NTDDI_WIN8
+ D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata;
+ HRESULT result = S_OK;
+ IDXGIDevice3 *dxgiDevice = NULL;
+
+ result = ID3D11Device_QueryInterface(data->d3dDevice, &SDL_IID_IDXGIDevice3, &dxgiDevice);
+ if (FAILED(result)) {
+ //WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device to IDXGIDevice3", result);
+ return;
+ }
+
+ IDXGIDevice3_Trim(dxgiDevice);
+ SAFE_RELEASE(dxgiDevice);
+#endif
+#endif
+}
+
+static void
+D3D11_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
+{
+ if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
+ D3D11_UpdateForWindowSizeChange(renderer);
+ }
+}
+
+static SDL_bool
+D3D11_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
+{
+ SDL_BlendFactor srcColorFactor = SDL_GetBlendModeSrcColorFactor(blendMode);
+ SDL_BlendFactor srcAlphaFactor = SDL_GetBlendModeSrcAlphaFactor(blendMode);
+ SDL_BlendOperation colorOperation = SDL_GetBlendModeColorOperation(blendMode);
+ SDL_BlendFactor dstColorFactor = SDL_GetBlendModeDstColorFactor(blendMode);
+ SDL_BlendFactor dstAlphaFactor = SDL_GetBlendModeDstAlphaFactor(blendMode);
+ SDL_BlendOperation alphaOperation = SDL_GetBlendModeAlphaOperation(blendMode);
+
+ if (!GetBlendFunc(srcColorFactor) || !GetBlendFunc(srcAlphaFactor) ||
+ !GetBlendEquation(colorOperation) ||
+ !GetBlendFunc(dstColorFactor) || !GetBlendFunc(dstAlphaFactor) ||
+ !GetBlendEquation(alphaOperation)) {
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
+}
+
+static D3D11_FILTER
+GetScaleQuality(void)
+{
+ const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
+ if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
+ return D3D11_FILTER_MIN_MAG_MIP_POINT;
+ } else /* if (*hint == '1' || SDL_strcasecmp(hint, "linear") == 0) */ {
+ return D3D11_FILTER_MIN_MAG_MIP_LINEAR;
+ }
+}
+
+static int
+D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
+ D3D11_TextureData *textureData;
+ HRESULT result;
+ DXGI_FORMAT textureFormat = SDLPixelFormatToDXGIFormat(texture->format);
+ D3D11_TEXTURE2D_DESC textureDesc;
+ D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc;
+
+ if (textureFormat == DXGI_FORMAT_UNKNOWN) {
+ return SDL_SetError("%s, An unsupported SDL pixel format (0x%x) was specified",
+ __FUNCTION__, texture->format);
+ }
+
+ textureData = (D3D11_TextureData*) SDL_calloc(1, sizeof(*textureData));
+ if (!textureData) {
+ SDL_OutOfMemory();
+ return -1;
+ }
+ textureData->scaleMode = GetScaleQuality();
+
+ texture->driverdata = textureData;
+
+ SDL_zero(textureDesc);
+ textureDesc.Width = texture->w;
+ textureDesc.Height = texture->h;
+ textureDesc.MipLevels = 1;
+ textureDesc.ArraySize = 1;
+ textureDesc.Format = textureFormat;
+ textureDesc.SampleDesc.Count = 1;
+ textureDesc.SampleDesc.Quality = 0;
+ textureDesc.MiscFlags = 0;
+
+ if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
+ textureDesc.Usage = D3D11_USAGE_DYNAMIC;
+ textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
+ } else {
+ textureDesc.Usage = D3D11_USAGE_DEFAULT;
+ textureDesc.CPUAccessFlags = 0;
+ }
+
+ if (texture->access == SDL_TEXTUREACCESS_TARGET) {
+ textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
+ } else {
+ textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
+ }
+
+ result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
+ &textureDesc,
+ NULL,
+ &textureData->mainTexture
+ );
+ if (FAILED(result)) {
+ D3D11_DestroyTexture(renderer, texture);
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
+ return -1;
+ }
+
+ if (texture->format == SDL_PIXELFORMAT_YV12 ||
+ texture->format == SDL_PIXELFORMAT_IYUV) {
+ textureData->yuv = SDL_TRUE;
+
+ textureDesc.Width = (textureDesc.Width + 1) / 2;
+ textureDesc.Height = (textureDesc.Height + 1) / 2;
+
+ result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
+ &textureDesc,
+ NULL,
+ &textureData->mainTextureU
+ );
+ if (FAILED(result)) {
+ D3D11_DestroyTexture(renderer, texture);
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
+ return -1;
+ }
+
+ result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
+ &textureDesc,
+ NULL,
+ &textureData->mainTextureV
+ );
+ if (FAILED(result)) {
+ D3D11_DestroyTexture(renderer, texture);
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
+ return -1;
+ }
+ }
+
+ if (texture->format == SDL_PIXELFORMAT_NV12 ||
+ texture->format == SDL_PIXELFORMAT_NV21) {
+ D3D11_TEXTURE2D_DESC nvTextureDesc = textureDesc;
+
+ textureData->nv12 = SDL_TRUE;
+
+ nvTextureDesc.Format = DXGI_FORMAT_R8G8_UNORM;
+ nvTextureDesc.Width = (textureDesc.Width + 1) / 2;
+ nvTextureDesc.Height = (textureDesc.Height + 1) / 2;
+
+ result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
+ &nvTextureDesc,
+ NULL,
+ &textureData->mainTextureNV
+ );
+ if (FAILED(result)) {
+ D3D11_DestroyTexture(renderer, texture);
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
+ return -1;
+ }
+ }
+
+ resourceViewDesc.Format = textureDesc.Format;
+ resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
+ resourceViewDesc.Texture2D.MostDetailedMip = 0;
+ resourceViewDesc.Texture2D.MipLevels = textureDesc.MipLevels;
+ result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
+ (ID3D11Resource *)textureData->mainTexture,
+ &resourceViewDesc,
+ &textureData->mainTextureResourceView
+ );
+ if (FAILED(result)) {
+ D3D11_DestroyTexture(renderer, texture);
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
+ return -1;
+ }
+
+ if (textureData->yuv) {
+ result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
+ (ID3D11Resource *)textureData->mainTextureU,
+ &resourceViewDesc,
+ &textureData->mainTextureResourceViewU
+ );
+ if (FAILED(result)) {
+ D3D11_DestroyTexture(renderer, texture);
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
+ return -1;
+ }
+ result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
+ (ID3D11Resource *)textureData->mainTextureV,
+ &resourceViewDesc,
+ &textureData->mainTextureResourceViewV
+ );
+ if (FAILED(result)) {
+ D3D11_DestroyTexture(renderer, texture);
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
+ return -1;
+ }
+ }
+
+ if (textureData->nv12) {
+ D3D11_SHADER_RESOURCE_VIEW_DESC nvResourceViewDesc = resourceViewDesc;
+
+ nvResourceViewDesc.Format = DXGI_FORMAT_R8G8_UNORM;
+
+ result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
+ (ID3D11Resource *)textureData->mainTextureNV,
+ &nvResourceViewDesc,
+ &textureData->mainTextureResourceViewNV
+ );
+ if (FAILED(result)) {
+ D3D11_DestroyTexture(renderer, texture);
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
+ return -1;
+ }
+ }
+
+ if (texture->access & SDL_TEXTUREACCESS_TARGET) {
+ D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
+ renderTargetViewDesc.Format = textureDesc.Format;
+ renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
+ renderTargetViewDesc.Texture2D.MipSlice = 0;
+
+ result = ID3D11Device_CreateRenderTargetView(rendererData->d3dDevice,
+ (ID3D11Resource *)textureData->mainTexture,
+ &renderTargetViewDesc,
+ &textureData->mainTextureRenderTargetView);
+ if (FAILED(result)) {
+ D3D11_DestroyTexture(renderer, texture);
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateRenderTargetView"), result);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+static void
+D3D11_DestroyTexture(SDL_Renderer * renderer,
+ SDL_Texture * texture)
+{
+ D3D11_TextureData *data = (D3D11_TextureData *)texture->driverdata;
+
+ if (!data) {
+ return;
+ }
+
+ SAFE_RELEASE(data->mainTexture);
+ SAFE_RELEASE(data->mainTextureResourceView);
+ SAFE_RELEASE(data->mainTextureRenderTargetView);
+ SAFE_RELEASE(data->stagingTexture);
+ SAFE_RELEASE(data->mainTextureU);
+ SAFE_RELEASE(data->mainTextureResourceViewU);
+ SAFE_RELEASE(data->mainTextureV);
+ SAFE_RELEASE(data->mainTextureResourceViewV);
+ SDL_free(data->pixels);
+ SDL_free(data);
+ texture->driverdata = NULL;
+}
+
+static int
+D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Texture2D *texture, int bpp, int x, int y, int w, int h, const void *pixels, int pitch)
+{
+ ID3D11Texture2D *stagingTexture;
+ const Uint8 *src;
+ Uint8 *dst;
+ int row;
+ UINT length;
+ HRESULT result;
+ D3D11_TEXTURE2D_DESC stagingTextureDesc;
+ D3D11_MAPPED_SUBRESOURCE textureMemory;
+
+ /* Create a 'staging' texture, which will be used to write to a portion of the main texture. */
+ ID3D11Texture2D_GetDesc(texture, &stagingTextureDesc);
+ stagingTextureDesc.Width = w;
+ stagingTextureDesc.Height = h;
+ stagingTextureDesc.BindFlags = 0;
+ stagingTextureDesc.MiscFlags = 0;
+ stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
+ stagingTextureDesc.Usage = D3D11_USAGE_STAGING;
+ result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
+ &stagingTextureDesc,
+ NULL,
+ &stagingTexture);
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D [create staging texture]"), result);
+ return -1;
+ }
+
+ /* Get a write-only pointer to data in the staging texture: */
+ result = ID3D11DeviceContext_Map(rendererData->d3dContext,
+ (ID3D11Resource *)stagingTexture,
+ 0,
+ D3D11_MAP_WRITE,
+ 0,
+ &textureMemory
+ );
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [map staging texture]"), result);
+ SAFE_RELEASE(stagingTexture);
+ return -1;
+ }
+
+ src = (const Uint8 *)pixels;
+ dst = textureMemory.pData;
+ length = w * bpp;
+ if (length == pitch && length == textureMemory.RowPitch) {
+ SDL_memcpy(dst, src, length*h);
+ } else {
+ if (length > (UINT)pitch) {
+ length = pitch;
+ }
+ if (length > textureMemory.RowPitch) {
+ length = textureMemory.RowPitch;
+ }
+ for (row = 0; row < h; ++row) {
+ SDL_memcpy(dst, src, length);
+ src += pitch;
+ dst += textureMemory.RowPitch;
+ }
+ }
+
+ /* Commit the pixel buffer's changes back to the staging texture: */
+ ID3D11DeviceContext_Unmap(rendererData->d3dContext,
+ (ID3D11Resource *)stagingTexture,
+ 0);
+
+ /* Copy the staging texture's contents back to the texture: */
+ ID3D11DeviceContext_CopySubresourceRegion(rendererData->d3dContext,
+ (ID3D11Resource *)texture,
+ 0,
+ x,
+ y,
+ 0,
+ (ID3D11Resource *)stagingTexture,
+ 0,
+ NULL);
+
+ SAFE_RELEASE(stagingTexture);
+
+ return 0;
+}
+
+static int
+D3D11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, const void * srcPixels,
+ int srcPitch)
+{
+ D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata;
+ D3D11_TextureData *textureData = (D3D11_TextureData *)texture->driverdata;
+
+ if (!textureData) {
+ SDL_SetError("Texture is not currently available");
+ return -1;
+ }
+
+ if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, SDL_BYTESPERPIXEL(texture->format), rect->x, rect->y, rect->w, rect->h, srcPixels, srcPitch) < 0) {
+ return -1;
+ }
+
+ if (textureData->yuv) {
+ /* Skip to the correct offset into the next texture */
+ srcPixels = (const void*)((const Uint8*)srcPixels + rect->h * srcPitch);
+
+ if (D3D11_UpdateTextureInternal(rendererData, texture->format == SDL_PIXELFORMAT_YV12 ? textureData->mainTextureV : textureData->mainTextureU, SDL_BYTESPERPIXEL(texture->format), rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, srcPixels, (srcPitch + 1) / 2) < 0) {
+ return -1;
+ }
+
+ /* Skip to the correct offset into the next texture */
+ srcPixels = (const void*)((const Uint8*)srcPixels + ((rect->h + 1) / 2) * ((srcPitch + 1) / 2));
+ if (D3D11_UpdateTextureInternal(rendererData, texture->format == SDL_PIXELFORMAT_YV12 ? textureData->mainTextureU : textureData->mainTextureV, SDL_BYTESPERPIXEL(texture->format), rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, srcPixels, (srcPitch + 1) / 2) < 0) {
+ return -1;
+ }
+ }
+
+ if (textureData->nv12) {
+ /* Skip to the correct offset into the next texture */
+ srcPixels = (const void*)((const Uint8*)srcPixels + rect->h * srcPitch);
+
+ if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureNV, 2, rect->x / 2, rect->y / 2, ((rect->w + 1) / 2), (rect->h + 1) / 2, srcPixels, 2*((srcPitch + 1) / 2)) < 0) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int
+D3D11_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch)
+{
+ D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata;
+ D3D11_TextureData *textureData = (D3D11_TextureData *)texture->driverdata;
+
+ if (!textureData) {
+ SDL_SetError("Texture is not currently available");
+ return -1;
+ }
+
+ if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, SDL_BYTESPERPIXEL(texture->format), rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) {
+ return -1;
+ }
+ if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureU, SDL_BYTESPERPIXEL(texture->format), rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Uplane, Upitch) < 0) {
+ return -1;
+ }
+ if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureV, SDL_BYTESPERPIXEL(texture->format), rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Vplane, Vpitch) < 0) {
+ return -1;
+ }
+ return 0;
+}
+
+static int
+D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, void **pixels, int *pitch)
+{
+ D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
+ D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata;
+ HRESULT result = S_OK;
+ D3D11_TEXTURE2D_DESC stagingTextureDesc;
+ D3D11_MAPPED_SUBRESOURCE textureMemory;
+
+ if (!textureData) {
+ SDL_SetError("Texture is not currently available");
+ return -1;
+ }
+
+ if (textureData->yuv || textureData->nv12) {
+ /* It's more efficient to upload directly... */
+ if (!textureData->pixels) {
+ textureData->pitch = texture->w;
+ textureData->pixels = (Uint8 *)SDL_malloc((texture->h * textureData->pitch * 3) / 2);
+ if (!textureData->pixels) {
+ return SDL_OutOfMemory();
+ }
+ }
+ textureData->locked_rect = *rect;
+ *pixels =
+ (void *)((Uint8 *)textureData->pixels + rect->y * textureData->pitch +
+ rect->x * SDL_BYTESPERPIXEL(texture->format));
+ *pitch = textureData->pitch;
+ return 0;
+ }
+
+ if (textureData->stagingTexture) {
+ return SDL_SetError("texture is already locked");
+ }
+
+ /* Create a 'staging' texture, which will be used to write to a portion
+ * of the main texture. This is necessary, as Direct3D 11.1 does not
+ * have the ability to write a CPU-bound pixel buffer to a rectangular
+ * subrect of a texture. Direct3D 11.1 can, however, write a pixel
+ * buffer to an entire texture, hence the use of a staging texture.
+ *
+ * TODO, WinRT: consider avoiding the use of a staging texture in D3D11_LockTexture if/when the entire texture is being updated
+ */
+ ID3D11Texture2D_GetDesc(textureData->mainTexture, &stagingTextureDesc);
+ stagingTextureDesc.Width = rect->w;
+ stagingTextureDesc.Height = rect->h;
+ stagingTextureDesc.BindFlags = 0;
+ stagingTextureDesc.MiscFlags = 0;
+ stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
+ stagingTextureDesc.Usage = D3D11_USAGE_STAGING;
+ result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
+ &stagingTextureDesc,
+ NULL,
+ &textureData->stagingTexture);
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D [create staging texture]"), result);
+ return -1;
+ }
+
+ /* Get a write-only pointer to data in the staging texture: */
+ result = ID3D11DeviceContext_Map(rendererData->d3dContext,
+ (ID3D11Resource *)textureData->stagingTexture,
+ 0,
+ D3D11_MAP_WRITE,
+ 0,
+ &textureMemory
+ );
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [map staging texture]"), result);
+ SAFE_RELEASE(textureData->stagingTexture);
+ return -1;
+ }
+
+ /* Make note of where the staging texture will be written to
+ * (on a call to SDL_UnlockTexture):
+ */
+ textureData->lockedTexturePositionX = rect->x;
+ textureData->lockedTexturePositionY = rect->y;
+
+ /* Make sure the caller has information on the texture's pixel buffer,
+ * then return:
+ */
+ *pixels = textureMemory.pData;
+ *pitch = textureMemory.RowPitch;
+ return 0;
+}
+
+static void
+D3D11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
+ D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata;
+
+ if (!textureData) {
+ return;
+ }
+
+ if (textureData->yuv || textureData->nv12) {
+ const SDL_Rect *rect = &textureData->locked_rect;
+ void *pixels =
+ (void *) ((Uint8 *) textureData->pixels + rect->y * textureData->pitch +
+ rect->x * SDL_BYTESPERPIXEL(texture->format));
+ D3D11_UpdateTexture(renderer, texture, rect, pixels, textureData->pitch);
+ return;
+ }
+
+ /* Commit the pixel buffer's changes back to the staging texture: */
+ ID3D11DeviceContext_Unmap(rendererData->d3dContext,
+ (ID3D11Resource *)textureData->stagingTexture,
+ 0);
+
+ /* Copy the staging texture's contents back to the main texture: */
+ ID3D11DeviceContext_CopySubresourceRegion(rendererData->d3dContext,
+ (ID3D11Resource *)textureData->mainTexture,
+ 0,
+ textureData->lockedTexturePositionX,
+ textureData->lockedTexturePositionY,
+ 0,
+ (ID3D11Resource *)textureData->stagingTexture,
+ 0,
+ NULL);
+
+ SAFE_RELEASE(textureData->stagingTexture);
+}
+
+static int
+D3D11_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
+ D3D11_TextureData *textureData = NULL;
+
+ if (texture == NULL) {
+ rendererData->currentOffscreenRenderTargetView = NULL;
+ return 0;
+ }
+
+ textureData = (D3D11_TextureData *) texture->driverdata;
+
+ if (!textureData->mainTextureRenderTargetView) {
+ return SDL_SetError("specified texture is not a render target");
+ }
+
+ rendererData->currentOffscreenRenderTargetView = textureData->mainTextureRenderTargetView;
+
+ return 0;
+}
+
+static void
+D3D11_SetModelMatrix(SDL_Renderer *renderer, const Float4X4 *matrix)
+{
+ D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata;
+
+ if (matrix) {
+ data->vertexShaderConstantsData.model = *matrix;
+ } else {
+ data->vertexShaderConstantsData.model = MatrixIdentity();
+ }
+
+ ID3D11DeviceContext_UpdateSubresource(data->d3dContext,
+ (ID3D11Resource *)data->vertexShaderConstants,
+ 0,
+ NULL,
+ &data->vertexShaderConstantsData,
+ 0,
+ 0
+ );
+}
+
+static int
+D3D11_UpdateViewport(SDL_Renderer * renderer)
+{
+ D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
+ Float4X4 projection;
+ Float4X4 view;
+ SDL_FRect orientationAlignedViewport;
+ BOOL swapDimensions;
+ D3D11_VIEWPORT viewport;
+ const int rotation = D3D11_GetRotationForCurrentRenderTarget(renderer);
+
+ if (renderer->viewport.w == 0 || renderer->viewport.h == 0) {
+ /* If the viewport is empty, assume that it is because
+ * SDL_CreateRenderer is calling it, and will call it again later
+ * with a non-empty viewport.
+ */
+ /* SDL_Log("%s, no viewport was set!\n", __FUNCTION__); */
+ return 0;
+ }
+
+ /* Make sure the SDL viewport gets rotated to that of the physical display's rotation.
+ * Keep in mind here that the Y-axis will be been inverted (from Direct3D's
+ * default coordinate system) so rotations will be done in the opposite
+ * direction of the DXGI_MODE_ROTATION enumeration.
+ */
+ switch (rotation) {
+ case DXGI_MODE_ROTATION_IDENTITY:
+ projection = MatrixIdentity();
+ break;
+ case DXGI_MODE_ROTATION_ROTATE270:
+ projection = MatrixRotationZ(SDL_static_cast(float, M_PI * 0.5f));
+ break;
+ case DXGI_MODE_ROTATION_ROTATE180:
+ projection = MatrixRotationZ(SDL_static_cast(float, M_PI));
+ break;
+ case DXGI_MODE_ROTATION_ROTATE90:
+ projection = MatrixRotationZ(SDL_static_cast(float, -M_PI * 0.5f));
+ break;
+ default:
+ return SDL_SetError("An unknown DisplayOrientation is being used");
+ }
+
+ /* Update the view matrix */
+ view.m[0][0] = 2.0f / renderer->viewport.w;
+ view.m[0][1] = 0.0f;
+ view.m[0][2] = 0.0f;
+ view.m[0][3] = 0.0f;
+ view.m[1][0] = 0.0f;
+ view.m[1][1] = -2.0f / renderer->viewport.h;
+ view.m[1][2] = 0.0f;
+ view.m[1][3] = 0.0f;
+ view.m[2][0] = 0.0f;
+ view.m[2][1] = 0.0f;
+ view.m[2][2] = 1.0f;
+ view.m[2][3] = 0.0f;
+ view.m[3][0] = -1.0f;
+ view.m[3][1] = 1.0f;
+ view.m[3][2] = 0.0f;
+ view.m[3][3] = 1.0f;
+
+ /* Combine the projection + view matrix together now, as both only get
+ * set here (as of this writing, on Dec 26, 2013). When done, store it
+ * for eventual transfer to the GPU.
+ */
+ data->vertexShaderConstantsData.projectionAndView = MatrixMultiply(
+ view,
+ projection);
+
+ /* Reset the model matrix */
+ D3D11_SetModelMatrix(renderer, NULL);
+
+ /* Update the Direct3D viewport, which seems to be aligned to the
+ * swap buffer's coordinate space, which is always in either
+ * a landscape mode, for all Windows 8/RT devices, or a portrait mode,
+ * for Windows Phone devices.
+ */
+ swapDimensions = D3D11_IsDisplayRotated90Degrees(rotation);
+ if (swapDimensions) {
+ orientationAlignedViewport.x = (float) renderer->viewport.y;
+ orientationAlignedViewport.y = (float) renderer->viewport.x;
+ orientationAlignedViewport.w = (float) renderer->viewport.h;
+ orientationAlignedViewport.h = (float) renderer->viewport.w;
+ } else {
+ orientationAlignedViewport.x = (float) renderer->viewport.x;
+ orientationAlignedViewport.y = (float) renderer->viewport.y;
+ orientationAlignedViewport.w = (float) renderer->viewport.w;
+ orientationAlignedViewport.h = (float) renderer->viewport.h;
+ }
+ /* TODO, WinRT: get custom viewports working with non-Landscape modes (Portrait, PortraitFlipped, and LandscapeFlipped) */
+
+ viewport.TopLeftX = orientationAlignedViewport.x;
+ viewport.TopLeftY = orientationAlignedViewport.y;
+ viewport.Width = orientationAlignedViewport.w;
+ viewport.Height = orientationAlignedViewport.h;
+ viewport.MinDepth = 0.0f;
+ viewport.MaxDepth = 1.0f;
+ /* SDL_Log("%s: D3D viewport = {%f,%f,%f,%f}\n", __FUNCTION__, viewport.TopLeftX, viewport.TopLeftY, viewport.Width, viewport.Height); */
+ ID3D11DeviceContext_RSSetViewports(data->d3dContext, 1, &viewport);
+
+ return 0;
+}
+
+static int
+D3D11_UpdateClipRect(SDL_Renderer * renderer)
+{
+ D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
+
+ if (!renderer->clipping_enabled) {
+ ID3D11DeviceContext_RSSetScissorRects(data->d3dContext, 0, NULL);
+ } else {
+ D3D11_RECT scissorRect;
+ if (D3D11_GetViewportAlignedD3DRect(renderer, &renderer->clip_rect, &scissorRect, TRUE) != 0) {
+ /* D3D11_GetViewportAlignedD3DRect will have set the SDL error */
+ return -1;
+ }
+ ID3D11DeviceContext_RSSetScissorRects(data->d3dContext, 1, &scissorRect);
+ }
+
+ return 0;
+}
+
+static void
+D3D11_ReleaseMainRenderTargetView(SDL_Renderer * renderer)
+{
+ D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata;
+ ID3D11DeviceContext_OMSetRenderTargets(data->d3dContext, 0, NULL, NULL);
+ SAFE_RELEASE(data->mainRenderTargetView);
+}
+
+static ID3D11RenderTargetView *
+D3D11_GetCurrentRenderTargetView(SDL_Renderer * renderer)
+{
+ D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
+ if (data->currentOffscreenRenderTargetView) {
+ return data->currentOffscreenRenderTargetView;
+ } else {
+ return data->mainRenderTargetView;
+ }
+}
+
+static int
+D3D11_RenderClear(SDL_Renderer * renderer)
+{
+ D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
+ const float colorRGBA[] = {
+ (renderer->r / 255.0f),
+ (renderer->g / 255.0f),
+ (renderer->b / 255.0f),
+ (renderer->a / 255.0f)
+ };
+ ID3D11DeviceContext_ClearRenderTargetView(data->d3dContext,
+ D3D11_GetCurrentRenderTargetView(renderer),
+ colorRGBA
+ );
+ return 0;
+}
+
+static int
+D3D11_UpdateVertexBuffer(SDL_Renderer *renderer,
+ const void * vertexData, size_t dataSizeInBytes)
+{
+ D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
+ D3D11_BUFFER_DESC vertexBufferDesc;
+ HRESULT result = S_OK;
+ D3D11_SUBRESOURCE_DATA vertexBufferData;
+ const UINT stride = sizeof(VertexPositionColor);
+ const UINT offset = 0;
+
+ if (rendererData->vertexBuffer) {
+ ID3D11Buffer_GetDesc(rendererData->vertexBuffer, &vertexBufferDesc);
+ } else {
+ SDL_zero(vertexBufferDesc);
+ }
+
+ if (rendererData->vertexBuffer && vertexBufferDesc.ByteWidth >= dataSizeInBytes) {
+ D3D11_MAPPED_SUBRESOURCE mappedResource;
+ result = ID3D11DeviceContext_Map(rendererData->d3dContext,
+ (ID3D11Resource *)rendererData->vertexBuffer,
+ 0,
+ D3D11_MAP_WRITE_DISCARD,
+ 0,
+ &mappedResource
+ );
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [vertex buffer]"), result);
+ return -1;
+ }
+ SDL_memcpy(mappedResource.pData, vertexData, dataSizeInBytes);
+ ID3D11DeviceContext_Unmap(rendererData->d3dContext, (ID3D11Resource *)rendererData->vertexBuffer, 0);
+ } else {
+ SAFE_RELEASE(rendererData->vertexBuffer);
+
+ vertexBufferDesc.ByteWidth = (UINT) dataSizeInBytes;
+ vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
+ vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
+ vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
+
+ SDL_zero(vertexBufferData);
+ vertexBufferData.pSysMem = vertexData;
+ vertexBufferData.SysMemPitch = 0;
+ vertexBufferData.SysMemSlicePitch = 0;
+
+ result = ID3D11Device_CreateBuffer(rendererData->d3dDevice,
+ &vertexBufferDesc,
+ &vertexBufferData,
+ &rendererData->vertexBuffer
+ );
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateBuffer [vertex buffer]"), result);
+ return -1;
+ }
+
+ ID3D11DeviceContext_IASetVertexBuffers(rendererData->d3dContext,
+ 0,
+ 1,
+ &rendererData->vertexBuffer,
+ &stride,
+ &offset
+ );
+ }
+
+ return 0;
+}
+
+static void
+D3D11_RenderStartDrawOp(SDL_Renderer * renderer)
+{
+ D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata;
+ ID3D11RasterizerState *rasterizerState;
+ ID3D11RenderTargetView *renderTargetView = D3D11_GetCurrentRenderTargetView(renderer);
+ if (renderTargetView != rendererData->currentRenderTargetView) {
+ ID3D11DeviceContext_OMSetRenderTargets(rendererData->d3dContext,
+ 1,
+ &renderTargetView,
+ NULL
+ );
+ rendererData->currentRenderTargetView = renderTargetView;
+ }
+
+ if (!renderer->clipping_enabled) {
+ rasterizerState = rendererData->mainRasterizer;
+ } else {
+ rasterizerState = rendererData->clippedRasterizer;
+ }
+ if (rasterizerState != rendererData->currentRasterizerState) {
+ ID3D11DeviceContext_RSSetState(rendererData->d3dContext, rasterizerState);
+ rendererData->currentRasterizerState = rasterizerState;
+ }
+}
+
+static void
+D3D11_RenderSetBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
+{
+ D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata;
+ ID3D11BlendState *blendState = NULL;
+ if (blendMode != SDL_BLENDMODE_NONE) {
+ int i;
+ for (i = 0; i < rendererData->blendModesCount; ++i) {
+ if (blendMode == rendererData->blendModes[i].blendMode) {
+ blendState = rendererData->blendModes[i].blendState;
+ break;
+ }
+ }
+ if (!blendState) {
+ if (D3D11_CreateBlendState(renderer, blendMode)) {
+ /* Successfully created the blend state, try again */
+ D3D11_RenderSetBlendMode(renderer, blendMode);
+ }
+ return;
+ }
+ }
+ if (blendState != rendererData->currentBlendState) {
+ ID3D11DeviceContext_OMSetBlendState(rendererData->d3dContext, blendState, 0, 0xFFFFFFFF);
+ rendererData->currentBlendState = blendState;
+ }
+}
+
+static void
+D3D11_SetPixelShader(SDL_Renderer * renderer,
+ ID3D11PixelShader * shader,
+ int numShaderResources,
+ ID3D11ShaderResourceView ** shaderResources,
+ ID3D11SamplerState * sampler)
+{
+ D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
+ ID3D11ShaderResourceView *shaderResource;
+ if (shader != rendererData->currentShader) {
+ ID3D11DeviceContext_PSSetShader(rendererData->d3dContext, shader, NULL, 0);
+ rendererData->currentShader = shader;
+ }
+ if (numShaderResources > 0) {
+ shaderResource = shaderResources[0];
+ } else {
+ shaderResource = NULL;
+ }
+ if (shaderResource != rendererData->currentShaderResource) {
+ ID3D11DeviceContext_PSSetShaderResources(rendererData->d3dContext, 0, numShaderResources, shaderResources);
+ rendererData->currentShaderResource = shaderResource;
+ }
+ if (sampler != rendererData->currentSampler) {
+ ID3D11DeviceContext_PSSetSamplers(rendererData->d3dContext, 0, 1, &sampler);
+ rendererData->currentSampler = sampler;
+ }
+}
+
+static void
+D3D11_RenderFinishDrawOp(SDL_Renderer * renderer,
+ D3D11_PRIMITIVE_TOPOLOGY primitiveTopology,
+ UINT vertexCount)
+{
+ D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
+
+ ID3D11DeviceContext_IASetPrimitiveTopology(rendererData->d3dContext, primitiveTopology);
+ ID3D11DeviceContext_Draw(rendererData->d3dContext, vertexCount, 0);
+}
+
+static int
+D3D11_RenderDrawPoints(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count)
+{
+ D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
+ float r, g, b, a;
+ VertexPositionColor *vertices;
+ int i;
+
+ r = (float)(renderer->r / 255.0f);
+ g = (float)(renderer->g / 255.0f);
+ b = (float)(renderer->b / 255.0f);
+ a = (float)(renderer->a / 255.0f);
+
+ vertices = SDL_stack_alloc(VertexPositionColor, count);
+ for (i = 0; i < count; ++i) {
+ const VertexPositionColor v = { { points[i].x + 0.5f, points[i].y + 0.5f, 0.0f }, { 0.0f, 0.0f }, { r, g, b, a } };
+ vertices[i] = v;
+ }
+
+ D3D11_RenderStartDrawOp(renderer);
+ D3D11_RenderSetBlendMode(renderer, renderer->blendMode);
+ if (D3D11_UpdateVertexBuffer(renderer, vertices, (unsigned int)count * sizeof(VertexPositionColor)) != 0) {
+ SDL_stack_free(vertices);
+ return -1;
+ }
+
+ D3D11_SetPixelShader(
+ renderer,
+ rendererData->pixelShaders[SHADER_SOLID],
+ 0,
+ NULL,
+ NULL);
+
+ D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST, count);
+ SDL_stack_free(vertices);
+ return 0;
+}
+
+static int
+D3D11_RenderDrawLines(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count)
+{
+ D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
+ float r, g, b, a;
+ VertexPositionColor *vertices;
+ int i;
+
+ r = (float)(renderer->r / 255.0f);
+ g = (float)(renderer->g / 255.0f);
+ b = (float)(renderer->b / 255.0f);
+ a = (float)(renderer->a / 255.0f);
+
+ vertices = SDL_stack_alloc(VertexPositionColor, count);
+ for (i = 0; i < count; ++i) {
+ const VertexPositionColor v = { { points[i].x + 0.5f, points[i].y + 0.5f, 0.0f }, { 0.0f, 0.0f }, { r, g, b, a } };
+ vertices[i] = v;
+ }
+
+ D3D11_RenderStartDrawOp(renderer);
+ D3D11_RenderSetBlendMode(renderer, renderer->blendMode);
+ if (D3D11_UpdateVertexBuffer(renderer, vertices, (unsigned int)count * sizeof(VertexPositionColor)) != 0) {
+ SDL_stack_free(vertices);
+ return -1;
+ }
+
+ D3D11_SetPixelShader(
+ renderer,
+ rendererData->pixelShaders[SHADER_SOLID],
+ 0,
+ NULL,
+ NULL);
+
+ D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP, count);
+
+ if (points[0].x != points[count - 1].x || points[0].y != points[count - 1].y) {
+ ID3D11DeviceContext_IASetPrimitiveTopology(rendererData->d3dContext, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
+ ID3D11DeviceContext_Draw(rendererData->d3dContext, 1, count - 1);
+ }
+
+ SDL_stack_free(vertices);
+ return 0;
+}
+
+static int
+D3D11_RenderFillRects(SDL_Renderer * renderer,
+ const SDL_FRect * rects, int count)
+{
+ D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
+ float r, g, b, a;
+ int i;
+
+ r = (float)(renderer->r / 255.0f);
+ g = (float)(renderer->g / 255.0f);
+ b = (float)(renderer->b / 255.0f);
+ a = (float)(renderer->a / 255.0f);
+
+ for (i = 0; i < count; ++i) {
+ VertexPositionColor vertices[] = {
+ { { rects[i].x, rects[i].y, 0.0f }, { 0.0f, 0.0f}, {r, g, b, a} },
+ { { rects[i].x, rects[i].y + rects[i].h, 0.0f }, { 0.0f, 0.0f }, { r, g, b, a } },
+ { { rects[i].x + rects[i].w, rects[i].y, 0.0f }, { 0.0f, 0.0f }, { r, g, b, a } },
+ { { rects[i].x + rects[i].w, rects[i].y + rects[i].h, 0.0f }, { 0.0f, 0.0f }, { r, g, b, a } },
+ };
+
+ D3D11_RenderStartDrawOp(renderer);
+ D3D11_RenderSetBlendMode(renderer, renderer->blendMode);
+ if (D3D11_UpdateVertexBuffer(renderer, vertices, sizeof(vertices)) != 0) {
+ return -1;
+ }
+
+ D3D11_SetPixelShader(
+ renderer,
+ rendererData->pixelShaders[SHADER_SOLID],
+ 0,
+ NULL,
+ NULL);
+
+ D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, SDL_arraysize(vertices));
+ }
+
+ return 0;
+}
+
+static int
+D3D11_RenderSetupSampler(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
+ D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata;
+ ID3D11SamplerState *textureSampler;
+
+ switch (textureData->scaleMode) {
+ case D3D11_FILTER_MIN_MAG_MIP_POINT:
+ textureSampler = rendererData->nearestPixelSampler;
+ break;
+ case D3D11_FILTER_MIN_MAG_MIP_LINEAR:
+ textureSampler = rendererData->linearSampler;
+ break;
+ default:
+ return SDL_SetError("Unknown scale mode: %d\n", textureData->scaleMode);
+ }
+
+ if (textureData->yuv) {
+ ID3D11ShaderResourceView *shaderResources[] = {
+ textureData->mainTextureResourceView,
+ textureData->mainTextureResourceViewU,
+ textureData->mainTextureResourceViewV
+ };
+ D3D11_Shader shader;
+
+ switch (SDL_GetYUVConversionModeForResolution(texture->w, texture->h)) {
+ case SDL_YUV_CONVERSION_JPEG:
+ shader = SHADER_YUV_JPEG;
+ break;
+ case SDL_YUV_CONVERSION_BT601:
+ shader = SHADER_YUV_BT601;
+ break;
+ case SDL_YUV_CONVERSION_BT709:
+ shader = SHADER_YUV_BT709;
+ break;
+ default:
+ return SDL_SetError("Unsupported YUV conversion mode");
+ }
+
+ D3D11_SetPixelShader(
+ renderer,
+ rendererData->pixelShaders[shader],
+ SDL_arraysize(shaderResources),
+ shaderResources,
+ textureSampler);
+
+ } else if (textureData->nv12) {
+ ID3D11ShaderResourceView *shaderResources[] = {
+ textureData->mainTextureResourceView,
+ textureData->mainTextureResourceViewNV,
+ };
+ D3D11_Shader shader;
+
+ switch (SDL_GetYUVConversionModeForResolution(texture->w, texture->h)) {
+ case SDL_YUV_CONVERSION_JPEG:
+ shader = texture->format == SDL_PIXELFORMAT_NV12 ? SHADER_NV12_JPEG : SHADER_NV21_JPEG;
+ break;
+ case SDL_YUV_CONVERSION_BT601:
+ shader = texture->format == SDL_PIXELFORMAT_NV12 ? SHADER_NV12_BT601 : SHADER_NV21_BT601;
+ break;
+ case SDL_YUV_CONVERSION_BT709:
+ shader = texture->format == SDL_PIXELFORMAT_NV12 ? SHADER_NV12_BT709 : SHADER_NV21_BT709;
+ break;
+ default:
+ return SDL_SetError("Unsupported YUV conversion mode");
+ }
+
+ D3D11_SetPixelShader(
+ renderer,
+ rendererData->pixelShaders[shader],
+ SDL_arraysize(shaderResources),
+ shaderResources,
+ textureSampler);
+
+ } else {
+ D3D11_SetPixelShader(
+ renderer,
+ rendererData->pixelShaders[SHADER_RGB],
+ 1,
+ &textureData->mainTextureResourceView,
+ textureSampler);
+ }
+
+ return 0;
+}
+
+static int
+D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect)
+{
+ D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
+ D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata;
+ float minu, maxu, minv, maxv;
+ Float4 color;
+ VertexPositionColor vertices[4];
+
+ D3D11_RenderStartDrawOp(renderer);
+ D3D11_RenderSetBlendMode(renderer, texture->blendMode);
+
+ minu = (float) srcrect->x / texture->w;
+ maxu = (float) (srcrect->x + srcrect->w) / texture->w;
+ minv = (float) srcrect->y / texture->h;
+ maxv = (float) (srcrect->y + srcrect->h) / texture->h;
+
+ color.x = 1.0f; /* red */
+ color.y = 1.0f; /* green */
+ color.z = 1.0f; /* blue */
+ color.w = 1.0f; /* alpha */
+ if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
+ color.x = (float)(texture->r / 255.0f); /* red */
+ color.y = (float)(texture->g / 255.0f); /* green */
+ color.z = (float)(texture->b / 255.0f); /* blue */
+ }
+ if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) {
+ color.w = (float)(texture->a / 255.0f); /* alpha */
+ }
+
+ vertices[0].pos.x = dstrect->x;
+ vertices[0].pos.y = dstrect->y;
+ vertices[0].pos.z = 0.0f;
+ vertices[0].tex.x = minu;
+ vertices[0].tex.y = minv;
+ vertices[0].color = color;
+
+ vertices[1].pos.x = dstrect->x;
+ vertices[1].pos.y = dstrect->y + dstrect->h;
+ vertices[1].pos.z = 0.0f;
+ vertices[1].tex.x = minu;
+ vertices[1].tex.y = maxv;
+ vertices[1].color = color;
+
+ vertices[2].pos.x = dstrect->x + dstrect->w;
+ vertices[2].pos.y = dstrect->y;
+ vertices[2].pos.z = 0.0f;
+ vertices[2].tex.x = maxu;
+ vertices[2].tex.y = minv;
+ vertices[2].color = color;
+
+ vertices[3].pos.x = dstrect->x + dstrect->w;
+ vertices[3].pos.y = dstrect->y + dstrect->h;
+ vertices[3].pos.z = 0.0f;
+ vertices[3].tex.x = maxu;
+ vertices[3].tex.y = maxv;
+ vertices[3].color = color;
+
+ if (D3D11_UpdateVertexBuffer(renderer, vertices, sizeof(vertices)) != 0) {
+ return -1;
+ }
+
+ if (D3D11_RenderSetupSampler(renderer, texture) < 0) {
+ return -1;
+ }
+
+ D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, sizeof(vertices) / sizeof(VertexPositionColor));
+
+ return 0;
+}
+
+static int
+D3D11_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect,
+ const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip)
+{
+ D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
+ D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata;
+ float minu, maxu, minv, maxv;
+ Float4 color;
+ Float4X4 modelMatrix;
+ float minx, maxx, miny, maxy;
+ VertexPositionColor vertices[4];
+
+ D3D11_RenderStartDrawOp(renderer);
+ D3D11_RenderSetBlendMode(renderer, texture->blendMode);
+
+ minu = (float) srcrect->x / texture->w;
+ maxu = (float) (srcrect->x + srcrect->w) / texture->w;
+ minv = (float) srcrect->y / texture->h;
+ maxv = (float) (srcrect->y + srcrect->h) / texture->h;
+
+ color.x = 1.0f; /* red */
+ color.y = 1.0f; /* green */
+ color.z = 1.0f; /* blue */
+ color.w = 1.0f; /* alpha */
+ if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
+ color.x = (float)(texture->r / 255.0f); /* red */
+ color.y = (float)(texture->g / 255.0f); /* green */
+ color.z = (float)(texture->b / 255.0f); /* blue */
+ }
+ if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) {
+ color.w = (float)(texture->a / 255.0f); /* alpha */
+ }
+
+ if (flip & SDL_FLIP_HORIZONTAL) {
+ float tmp = maxu;
+ maxu = minu;
+ minu = tmp;
+ }
+ if (flip & SDL_FLIP_VERTICAL) {
+ float tmp = maxv;
+ maxv = minv;
+ minv = tmp;
+ }
+
+ modelMatrix = MatrixMultiply(
+ MatrixRotationZ((float)(M_PI * (float) angle / 180.0f)),
+ MatrixTranslation(dstrect->x + center->x, dstrect->y + center->y, 0)
+ );
+ D3D11_SetModelMatrix(renderer, &modelMatrix);
+
+ minx = -center->x;
+ maxx = dstrect->w - center->x;
+ miny = -center->y;
+ maxy = dstrect->h - center->y;
+
+ vertices[0].pos.x = minx;
+ vertices[0].pos.y = miny;
+ vertices[0].pos.z = 0.0f;
+ vertices[0].tex.x = minu;
+ vertices[0].tex.y = minv;
+ vertices[0].color = color;
+
+ vertices[1].pos.x = minx;
+ vertices[1].pos.y = maxy;
+ vertices[1].pos.z = 0.0f;
+ vertices[1].tex.x = minu;
+ vertices[1].tex.y = maxv;
+ vertices[1].color = color;
+
+ vertices[2].pos.x = maxx;
+ vertices[2].pos.y = miny;
+ vertices[2].pos.z = 0.0f;
+ vertices[2].tex.x = maxu;
+ vertices[2].tex.y = minv;
+ vertices[2].color = color;
+
+ vertices[3].pos.x = maxx;
+ vertices[3].pos.y = maxy;
+ vertices[3].pos.z = 0.0f;
+ vertices[3].tex.x = maxu;
+ vertices[3].tex.y = maxv;
+ vertices[3].color = color;
+
+ if (D3D11_UpdateVertexBuffer(renderer, vertices, sizeof(vertices)) != 0) {
+ return -1;
+ }
+
+ if (D3D11_RenderSetupSampler(renderer, texture) < 0) {
+ return -1;
+ }
+
+ D3D11_RenderFinishDrawOp(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, sizeof(vertices) / sizeof(VertexPositionColor));
+
+ D3D11_SetModelMatrix(renderer, NULL);
+
+ return 0;
+}
+
+static int
+D3D11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 format, void * pixels, int pitch)
+{
+ D3D11_RenderData * data = (D3D11_RenderData *) renderer->driverdata;
+ ID3D11Texture2D *backBuffer = NULL;
+ ID3D11Texture2D *stagingTexture = NULL;
+ HRESULT result;
+ int status = -1;
+ D3D11_TEXTURE2D_DESC stagingTextureDesc;
+ D3D11_RECT srcRect = {0, 0, 0, 0};
+ D3D11_BOX srcBox;
+ D3D11_MAPPED_SUBRESOURCE textureMemory;
+
+ /* Retrieve a pointer to the back buffer: */
+ result = IDXGISwapChain_GetBuffer(data->swapChain,
+ 0,
+ &SDL_IID_ID3D11Texture2D,
+ (void **)&backBuffer
+ );
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain1::GetBuffer [get back buffer]"), result);
+ goto done;
+ }
+
+ /* Create a staging texture to copy the screen's data to: */
+ ID3D11Texture2D_GetDesc(backBuffer, &stagingTextureDesc);
+ stagingTextureDesc.Width = rect->w;
+ stagingTextureDesc.Height = rect->h;
+ stagingTextureDesc.BindFlags = 0;
+ stagingTextureDesc.MiscFlags = 0;
+ stagingTextureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
+ stagingTextureDesc.Usage = D3D11_USAGE_STAGING;
+ result = ID3D11Device_CreateTexture2D(data->d3dDevice,
+ &stagingTextureDesc,
+ NULL,
+ &stagingTexture);
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D [create staging texture]"), result);
+ goto done;
+ }
+
+ /* Copy the desired portion of the back buffer to the staging texture: */
+ if (D3D11_GetViewportAlignedD3DRect(renderer, rect, &srcRect, FALSE) != 0) {
+ /* D3D11_GetViewportAlignedD3DRect will have set the SDL error */
+ goto done;
+ }
+
+ srcBox.left = srcRect.left;
+ srcBox.right = srcRect.right;
+ srcBox.top = srcRect.top;
+ srcBox.bottom = srcRect.bottom;
+ srcBox.front = 0;
+ srcBox.back = 1;
+ ID3D11DeviceContext_CopySubresourceRegion(data->d3dContext,
+ (ID3D11Resource *)stagingTexture,
+ 0,
+ 0, 0, 0,
+ (ID3D11Resource *)backBuffer,
+ 0,
+ &srcBox);
+
+ /* Map the staging texture's data to CPU-accessible memory: */
+ result = ID3D11DeviceContext_Map(data->d3dContext,
+ (ID3D11Resource *)stagingTexture,
+ 0,
+ D3D11_MAP_READ,
+ 0,
+ &textureMemory);
+ if (FAILED(result)) {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [map staging texture]"), result);
+ goto done;
+ }
+
+ /* Copy the data into the desired buffer, converting pixels to the
+ * desired format at the same time:
+ */
+ if (SDL_ConvertPixels(
+ rect->w, rect->h,
+ D3D11_DXGIFormatToSDLPixelFormat(stagingTextureDesc.Format),
+ textureMemory.pData,
+ textureMemory.RowPitch,
+ format,
+ pixels,
+ pitch) != 0) {
+ /* When SDL_ConvertPixels fails, it'll have already set the format.
+ * Get the error message, and attach some extra data to it.
+ */
+ char errorMessage[1024];
+ SDL_snprintf(errorMessage, sizeof(errorMessage), "%s, Convert Pixels failed: %s", __FUNCTION__, SDL_GetError());
+ SDL_SetError("%s", errorMessage);
+ goto done;
+ }
+
+ /* Unmap the texture: */
+ ID3D11DeviceContext_Unmap(data->d3dContext,
+ (ID3D11Resource *)stagingTexture,
+ 0);
+
+ status = 0;
+
+done:
+ SAFE_RELEASE(backBuffer);
+ SAFE_RELEASE(stagingTexture);
+ return status;
+}
+
+static void
+D3D11_RenderPresent(SDL_Renderer * renderer)
+{
+ D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
+ UINT syncInterval;
+ UINT presentFlags;
+ HRESULT result;
+ DXGI_PRESENT_PARAMETERS parameters;
+
+ SDL_zero(parameters);
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+ syncInterval = 1;
+ presentFlags = 0;
+ result = IDXGISwapChain_Present(data->swapChain, syncInterval, presentFlags);
+#else
+ if (renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) {
+ syncInterval = 1;
+ presentFlags = 0;
+ } else {
+ syncInterval = 0;
+ presentFlags = DXGI_PRESENT_DO_NOT_WAIT;
+ }
+
+ /* The application may optionally specify "dirty" or "scroll"
+ * rects to improve efficiency in certain scenarios.
+ * This option is not available on Windows Phone 8, to note.
+ */
+ result = IDXGISwapChain1_Present1(data->swapChain, syncInterval, presentFlags, &parameters);
+#endif
+
+ /* Discard the contents of the render target.
+ * This is a valid operation only when the existing contents will be entirely
+ * overwritten. If dirty or scroll rects are used, this call should be removed.
+ */
+ ID3D11DeviceContext1_DiscardView(data->d3dContext, (ID3D11View*)data->mainRenderTargetView);
+
+ /* When the present flips, it unbinds the current view, so bind it again on the next draw call */
+ data->currentRenderTargetView = NULL;
+
+ if (FAILED(result) && result != DXGI_ERROR_WAS_STILL_DRAWING) {
+ /* If the device was removed either by a disconnect or a driver upgrade, we
+ * must recreate all device resources.
+ *
+ * TODO, WinRT: consider throwing an exception if D3D11_RenderPresent fails, especially if there is a way to salvage debug info from users' machines
+ */
+ if ( result == DXGI_ERROR_DEVICE_REMOVED ) {
+ D3D11_HandleDeviceLost(renderer);
+ } else if (result == DXGI_ERROR_INVALID_CALL) {
+ /* We probably went through a fullscreen <-> windowed transition */
+ D3D11_CreateWindowSizeDependentResources(renderer);
+ } else {
+ WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain::Present"), result);
+ }
+ }
+}
+
+#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/direct3d11/SDL_render_winrt.cpp b/src/3rdparty/SDL2/src/render/direct3d11/SDL_render_winrt.cpp
new file mode 100644
index 0000000..2f2c3e5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/direct3d11/SDL_render_winrt.cpp
@@ -0,0 +1,116 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
+
+#include "SDL_syswm.h"
+#include "../../video/winrt/SDL_winrtvideo_cpp.h"
+extern "C" {
+#include "../SDL_sysrender.h"
+}
+
+#include <windows.ui.core.h>
+#include <windows.graphics.display.h>
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_APP
+#include <windows.ui.xaml.media.dxinterop.h>
+#endif
+
+using namespace Windows::UI::Core;
+using namespace Windows::Graphics::Display;
+
+#include <DXGI.h>
+
+#include "SDL_render_winrt.h"
+
+
+extern "C" void *
+D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer)
+{
+ SDL_Window * sdlWindow = renderer->window;
+ if ( ! renderer->window ) {
+ return NULL;
+ }
+
+ SDL_SysWMinfo sdlWindowInfo;
+ SDL_VERSION(&sdlWindowInfo.version);
+ if ( ! SDL_GetWindowWMInfo(sdlWindow, &sdlWindowInfo) ) {
+ return NULL;
+ }
+
+ if (sdlWindowInfo.subsystem != SDL_SYSWM_WINRT) {
+ return NULL;
+ }
+
+ if (!sdlWindowInfo.info.winrt.window) {
+ return NULL;
+ }
+
+ ABI::Windows::UI::Core::ICoreWindow *coreWindow = NULL;
+ if (FAILED(sdlWindowInfo.info.winrt.window->QueryInterface(&coreWindow))) {
+ return NULL;
+ }
+
+ IUnknown *coreWindowAsIUnknown = NULL;
+ coreWindow->QueryInterface(&coreWindowAsIUnknown);
+ coreWindow->Release();
+
+ return coreWindowAsIUnknown;
+}
+
+extern "C" DXGI_MODE_ROTATION
+D3D11_GetCurrentRotation()
+{
+ const DisplayOrientations currentOrientation = WINRT_DISPLAY_PROPERTY(CurrentOrientation);
+
+ switch (currentOrientation) {
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+ /* Windows Phone rotations */
+ case DisplayOrientations::Landscape:
+ return DXGI_MODE_ROTATION_ROTATE90;
+ case DisplayOrientations::Portrait:
+ return DXGI_MODE_ROTATION_IDENTITY;
+ case DisplayOrientations::LandscapeFlipped:
+ return DXGI_MODE_ROTATION_ROTATE270;
+ case DisplayOrientations::PortraitFlipped:
+ return DXGI_MODE_ROTATION_ROTATE180;
+#else
+ /* Non-Windows-Phone rotations (ex: Windows 8, Windows RT) */
+ case DisplayOrientations::Landscape:
+ return DXGI_MODE_ROTATION_IDENTITY;
+ case DisplayOrientations::Portrait:
+ return DXGI_MODE_ROTATION_ROTATE270;
+ case DisplayOrientations::LandscapeFlipped:
+ return DXGI_MODE_ROTATION_ROTATE180;
+ case DisplayOrientations::PortraitFlipped:
+ return DXGI_MODE_ROTATION_ROTATE90;
+#endif /* WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP */
+ }
+
+ return DXGI_MODE_ROTATION_IDENTITY;
+}
+
+
+#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/direct3d11/SDL_render_winrt.h b/src/3rdparty/SDL2/src/render/direct3d11/SDL_render_winrt.h
new file mode 100644
index 0000000..7bb8fb7
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/direct3d11/SDL_render_winrt.h
@@ -0,0 +1,40 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
+
+#include "SDL_render.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void * D3D11_GetCoreWindowFromSDLRenderer(SDL_Renderer * renderer);
+DXGI_MODE_ROTATION D3D11_GetCurrentRotation();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/direct3d11/SDL_shaders_d3d11.c b/src/3rdparty/SDL2/src/render/direct3d11/SDL_shaders_d3d11.c
new file mode 100644
index 0000000..f1277b9
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/direct3d11/SDL_shaders_d3d11.c
@@ -0,0 +1,1957 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
+
+#include "SDL_stdinc.h"
+
+#define COBJMACROS
+#include "../../core/windows/SDL_windows.h"
+#include <d3d11_1.h>
+
+#include "SDL_shaders_d3d11.h"
+
+#define SDL_COMPOSE_ERROR(str) SDL_STRINGIFY_ARG(__FUNCTION__) ", " str
+
+
+/* Direct3D 11.x shaders
+
+ SDL's shaders are compiled into SDL itself, to simplify distribution.
+
+ All Direct3D 11.x shaders were compiled with the following:
+
+ fxc /E"main" /T "<TYPE>" /Fo"<OUTPUT FILE>" "<INPUT FILE>"
+
+ Variables:
+ - <TYPE>: the type of shader. A table of utilized shader types is
+ listed below.
+ - <OUTPUT FILE>: where to store compiled output
+ - <INPUT FILE>: where to read shader source code from
+
+ Shader types:
+ - ps_4_0_level_9_1: Pixel shader for Windows 8+, including Windows RT
+ - vs_4_0_level_9_1: Vertex shader for Windows 8+, including Windows RT
+ - ps_4_0_level_9_3: Pixel shader for Windows Phone 8
+ - vs_4_0_level_9_3: Vertex shader for Windows Phone 8
+
+
+ Shader object code was converted to a list of DWORDs via the following
+ *nix style command (available separately from Windows + MSVC):
+
+ hexdump -v -e '6/4 "0x%08.8x, " "\n"' <FILE>
+ */
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+#define D3D11_USE_SHADER_MODEL_4_0_level_9_3
+#else
+#define D3D11_USE_SHADER_MODEL_4_0_level_9_1
+#endif
+
+/* The color-only-rendering pixel shader:
+
+ --- D3D11_PixelShader_Colors.hlsl ---
+ struct PixelShaderInput
+ {
+ float4 pos : SV_POSITION;
+ float2 tex : TEXCOORD0;
+ float4 color : COLOR0;
+ };
+
+ float4 main(PixelShaderInput input) : SV_TARGET
+ {
+ return input.color;
+ }
+*/
+#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1)
+static const DWORD D3D11_PixelShader_Colors[] = {
+ 0x43425844, 0xd74c28fe, 0xa1eb8804, 0x269d512a, 0x7699723d, 0x00000001,
+ 0x00000240, 0x00000006, 0x00000038, 0x00000084, 0x000000c4, 0x00000140,
+ 0x00000198, 0x0000020c, 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200,
+ 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
+ 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0001, 0x02000001,
+ 0x800f0800, 0xb0e40001, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040,
+ 0x0000000e, 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2,
+ 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002,
+ 0x0100003e, 0x54415453, 0x00000074, 0x00000002, 0x00000000, 0x00000000,
+ 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x46454452, 0x00000050, 0x00000000, 0x00000000,
+ 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d,
+ 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072,
+ 0x6c69706d, 0x39207265, 0x2e30332e, 0x30303239, 0x3336312e, 0xab003438,
+ 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
+ 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
+ 0x00000000, 0x00000003, 0x00000001, 0x00000003, 0x00000065, 0x00000000,
+ 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
+ 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
+ 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
+ 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
+};
+#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3)
+static const DWORD D3D11_PixelShader_Colors[] = {
+ 0x43425844, 0x93f6ccfc, 0x5f919270, 0x7a11aa4f, 0x9148e931, 0x00000001,
+ 0x00000240, 0x00000006, 0x00000038, 0x00000084, 0x000000c4, 0x00000140,
+ 0x00000198, 0x0000020c, 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200,
+ 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
+ 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0001, 0x02000001,
+ 0x800f0800, 0xb0e40001, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040,
+ 0x0000000e, 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2,
+ 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002,
+ 0x0100003e, 0x54415453, 0x00000074, 0x00000002, 0x00000000, 0x00000000,
+ 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x46454452, 0x00000050, 0x00000000, 0x00000000,
+ 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d,
+ 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072,
+ 0x6c69706d, 0x39207265, 0x2e30332e, 0x30303239, 0x3336312e, 0xab003438,
+ 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
+ 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
+ 0x00000000, 0x00000003, 0x00000001, 0x00000003, 0x00000065, 0x00000000,
+ 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
+ 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
+ 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
+ 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
+};
+#else
+#error "An appropriate 'colors' pixel shader is not defined."
+#endif
+
+/* The texture-rendering pixel shader:
+
+ --- D3D11_PixelShader_Textures.hlsl ---
+ Texture2D theTexture : register(t0);
+ SamplerState theSampler : register(s0);
+
+ struct PixelShaderInput
+ {
+ float4 pos : SV_POSITION;
+ float2 tex : TEXCOORD0;
+ float4 color : COLOR0;
+ };
+
+ float4 main(PixelShaderInput input) : SV_TARGET
+ {
+ return theTexture.Sample(theSampler, input.tex) * input.color;
+ }
+*/
+#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1)
+static const DWORD D3D11_PixelShader_Textures[] = {
+ 0x43425844, 0x6299b59f, 0x155258f2, 0x873ab86a, 0xfcbb6dcd, 0x00000001,
+ 0x00000330, 0x00000006, 0x00000038, 0x000000c0, 0x0000015c, 0x000001d8,
+ 0x00000288, 0x000002fc, 0x396e6f41, 0x00000080, 0x00000080, 0xffff0200,
+ 0x00000058, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001,
+ 0x00280000, 0x00000000, 0xffff0200, 0x0200001f, 0x80000000, 0xb0030000,
+ 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000, 0xa00f0800,
+ 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, 0x03000005, 0x800f0000,
+ 0x80e40000, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff,
+ 0x52444853, 0x00000094, 0x00000040, 0x00000025, 0x0300005a, 0x00106000,
+ 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03001062,
+ 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, 0x03000065,
+ 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x09000045, 0x001000f2,
+ 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
+ 0x00000000, 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
+ 0x00101e46, 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x00000003,
+ 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x00000000, 0x00000000,
+ 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000a8,
+ 0x00000000, 0x00000000, 0x00000002, 0x0000001c, 0xffff0400, 0x00000100,
+ 0x00000072, 0x0000005c, 0x00000003, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000001, 0x00000001, 0x00000067, 0x00000002, 0x00000005,
+ 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x53656874,
+ 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x694d0065, 0x736f7263,
+ 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564, 0x706d6f43,
+ 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336, 0xababab00,
+ 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
+ 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
+ 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000,
+ 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
+ 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
+ 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
+ 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
+};
+#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3)
+static const DWORD D3D11_PixelShader_Textures[] = {
+ 0x43425844, 0x5876569a, 0x01b6c87e, 0x8447454f, 0xc7f3ef10, 0x00000001,
+ 0x00000330, 0x00000006, 0x00000038, 0x000000c0, 0x0000015c, 0x000001d8,
+ 0x00000288, 0x000002fc, 0x396e6f41, 0x00000080, 0x00000080, 0xffff0200,
+ 0x00000058, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001,
+ 0x00280000, 0x00000000, 0xffff0201, 0x0200001f, 0x80000000, 0xb0030000,
+ 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000, 0xa00f0800,
+ 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800, 0x03000005, 0x800f0000,
+ 0x80e40000, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff,
+ 0x52444853, 0x00000094, 0x00000040, 0x00000025, 0x0300005a, 0x00106000,
+ 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03001062,
+ 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, 0x03000065,
+ 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x09000045, 0x001000f2,
+ 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
+ 0x00000000, 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
+ 0x00101e46, 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x00000003,
+ 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x00000000, 0x00000000,
+ 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000a8,
+ 0x00000000, 0x00000000, 0x00000002, 0x0000001c, 0xffff0400, 0x00000100,
+ 0x00000072, 0x0000005c, 0x00000003, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000001, 0x00000001, 0x00000067, 0x00000002, 0x00000005,
+ 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x53656874,
+ 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x694d0065, 0x736f7263,
+ 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564, 0x706d6f43,
+ 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336, 0xababab00,
+ 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
+ 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
+ 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000,
+ 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
+ 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
+ 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
+ 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
+};
+#else
+#error "An appropriate 'textures' pixel shader is not defined"
+#endif
+
+/* The yuv-rendering pixel shader:
+
+ --- D3D11_PixelShader_YUV_JPEG.hlsl ---
+ Texture2D theTextureY : register(t0);
+ Texture2D theTextureU : register(t1);
+ Texture2D theTextureV : register(t2);
+ SamplerState theSampler : register(s0);
+
+ struct PixelShaderInput
+ {
+ float4 pos : SV_POSITION;
+ float2 tex : TEXCOORD0;
+ float4 color : COLOR0;
+ };
+
+ float4 main(PixelShaderInput input) : SV_TARGET
+ {
+ const float3 offset = {0.0, -0.501960814, -0.501960814};
+ const float3 Rcoeff = {1.0000, 0.0000, 1.4020};
+ const float3 Gcoeff = {1.0000, -0.3441, -0.7141};
+ const float3 Bcoeff = {1.0000, 1.7720, 0.0000};
+
+ float4 Output;
+
+ float3 yuv;
+ yuv.x = theTextureY.Sample(theSampler, input.tex).r;
+ yuv.y = theTextureU.Sample(theSampler, input.tex).r;
+ yuv.z = theTextureV.Sample(theSampler, input.tex).r;
+
+ yuv += offset;
+ Output.r = dot(yuv, Rcoeff);
+ Output.g = dot(yuv, Gcoeff);
+ Output.b = dot(yuv, Bcoeff);
+ Output.a = 1.0f;
+
+ return Output * input.color;
+ }
+
+*/
+#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1)
+static const DWORD D3D11_PixelShader_YUV_JPEG[] = {
+ 0x43425844, 0x10359e9c, 0x92c3d2c4, 0x00bf0cd5, 0x5ce8c499, 0x00000001,
+ 0x000005e8, 0x00000006, 0x00000038, 0x000001dc, 0x000003bc, 0x00000438,
+ 0x00000540, 0x000005b4, 0x396e6f41, 0x0000019c, 0x0000019c, 0xffff0200,
+ 0x0000016c, 0x00000030, 0x00300000, 0x00300000, 0x00300000, 0x00240003,
+ 0x00300000, 0x00000000, 0x00010001, 0x00020002, 0xffff0200, 0x05000051,
+ 0xa00f0000, 0x00000000, 0xbf008081, 0xbf008081, 0x3f800000, 0x05000051,
+ 0xa00f0001, 0x3f800000, 0x3fb374bc, 0x00000000, 0x00000000, 0x05000051,
+ 0xa00f0002, 0x3f800000, 0xbeb02de0, 0xbf36cf42, 0x00000000, 0x05000051,
+ 0xa00f0003, 0x3f800000, 0x3fe2d0e5, 0x00000000, 0x00000000, 0x0200001f,
+ 0x80000000, 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f,
+ 0x90000000, 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f,
+ 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800,
+ 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40801, 0x03000042, 0x800f0002,
+ 0xb0e40000, 0xa0e40802, 0x02000001, 0x80020000, 0x80000001, 0x02000001,
+ 0x80040000, 0x80000002, 0x03000002, 0x80070000, 0x80e40000, 0xa0e40000,
+ 0x03000005, 0x80080000, 0x80000000, 0xa0000001, 0x04000004, 0x80010001,
+ 0x80aa0000, 0xa0550001, 0x80ff0000, 0x03000008, 0x80020001, 0x80e40000,
+ 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000, 0xa0e40003, 0xa0aa0003,
+ 0x02000001, 0x80080001, 0xa0ff0000, 0x03000005, 0x800f0000, 0x80e40001,
+ 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x52444853,
+ 0x000001d8, 0x00000040, 0x00000076, 0x0300005a, 0x00106000, 0x00000000,
+ 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858, 0x00107000,
+ 0x00000001, 0x00005555, 0x04001858, 0x00107000, 0x00000002, 0x00005555,
+ 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002,
+ 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x09000045,
+ 0x001000f2, 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000,
+ 0x00106000, 0x00000000, 0x09000045, 0x001000f2, 0x00000001, 0x00101046,
+ 0x00000001, 0x00107e46, 0x00000001, 0x00106000, 0x00000000, 0x05000036,
+ 0x00100022, 0x00000000, 0x0010000a, 0x00000001, 0x09000045, 0x001000f2,
+ 0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000002, 0x00106000,
+ 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x0010000a, 0x00000001,
+ 0x0a000000, 0x00100072, 0x00000000, 0x00100246, 0x00000000, 0x00004002,
+ 0x00000000, 0xbf008081, 0xbf008081, 0x00000000, 0x0a00000f, 0x00100012,
+ 0x00000001, 0x00100086, 0x00000000, 0x00004002, 0x3f800000, 0x3fb374bc,
+ 0x00000000, 0x00000000, 0x0a000010, 0x00100022, 0x00000001, 0x00100246,
+ 0x00000000, 0x00004002, 0x3f800000, 0xbeb02de0, 0xbf36cf42, 0x00000000,
+ 0x0a00000f, 0x00100042, 0x00000001, 0x00100046, 0x00000000, 0x00004002,
+ 0x3f800000, 0x3fe2d0e5, 0x00000000, 0x00000000, 0x05000036, 0x00100082,
+ 0x00000001, 0x00004001, 0x3f800000, 0x07000038, 0x001020f2, 0x00000000,
+ 0x00100e46, 0x00000001, 0x00101e46, 0x00000002, 0x0100003e, 0x54415453,
+ 0x00000074, 0x0000000c, 0x00000002, 0x00000000, 0x00000003, 0x00000005,
+ 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x46454452, 0x00000100, 0x00000000, 0x00000000, 0x00000004, 0x0000001c,
+ 0xffff0400, 0x00000100, 0x000000cb, 0x0000009c, 0x00000003, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x000000a7,
+ 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000000, 0x00000001,
+ 0x0000000d, 0x000000b3, 0x00000002, 0x00000005, 0x00000004, 0xffffffff,
+ 0x00000001, 0x00000001, 0x0000000d, 0x000000bf, 0x00000002, 0x00000005,
+ 0x00000004, 0xffffffff, 0x00000002, 0x00000001, 0x0000000d, 0x53656874,
+ 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x74005965, 0x65546568,
+ 0x72757478, 0x74005565, 0x65546568, 0x72757478, 0x4d005665, 0x6f726369,
+ 0x74666f73, 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320,
+ 0x656c6970, 0x2e362072, 0x36392e33, 0x312e3030, 0x34383336, 0xababab00,
+ 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
+ 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
+ 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000,
+ 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
+ 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
+ 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
+ 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
+};
+#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3)
+static const DWORD D3D11_PixelShader_YUV_JPEG[] = {
+ 0x43425844, 0x616d6673, 0x83174178, 0x15aac25d, 0x2a340487, 0x00000001,
+ 0x000005c0, 0x00000006, 0x00000038, 0x000001b4, 0x00000394, 0x00000410,
+ 0x00000518, 0x0000058c, 0x396e6f41, 0x00000174, 0x00000174, 0xffff0200,
+ 0x00000144, 0x00000030, 0x00300000, 0x00300000, 0x00300000, 0x00240003,
+ 0x00300000, 0x00000000, 0x00010001, 0x00020002, 0xffff0201, 0x05000051,
+ 0xa00f0000, 0x00000000, 0xbf008081, 0x3f800000, 0x3fb374bc, 0x05000051,
+ 0xa00f0001, 0x3f800000, 0xbeb02de0, 0xbf36cf42, 0x00000000, 0x05000051,
+ 0xa00f0002, 0x3f800000, 0x3fe2d0e5, 0x00000000, 0x00000000, 0x0200001f,
+ 0x80000000, 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f,
+ 0x90000000, 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f,
+ 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40801,
+ 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40800, 0x02000001, 0x80020001,
+ 0x80000000, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40802, 0x02000001,
+ 0x80040001, 0x80000000, 0x03000002, 0x80070000, 0x80e40001, 0xa0d40000,
+ 0x0400005a, 0x80010001, 0x80e80000, 0xa0ee0000, 0xa0000000, 0x03000008,
+ 0x80020001, 0x80e40000, 0xa0e40001, 0x0400005a, 0x80040001, 0x80e40000,
+ 0xa0e40002, 0xa0aa0002, 0x02000001, 0x80080001, 0xa0aa0000, 0x03000005,
+ 0x800f0000, 0x80e40001, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000,
+ 0x0000ffff, 0x52444853, 0x000001d8, 0x00000040, 0x00000076, 0x0300005a,
+ 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
+ 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04001858, 0x00107000,
+ 0x00000002, 0x00005555, 0x03001062, 0x00101032, 0x00000001, 0x03001062,
+ 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
+ 0x00000002, 0x09000045, 0x001000f2, 0x00000000, 0x00101046, 0x00000001,
+ 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x09000045, 0x001000f2,
+ 0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000001, 0x00106000,
+ 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x0010000a, 0x00000001,
+ 0x09000045, 0x001000f2, 0x00000001, 0x00101046, 0x00000001, 0x00107e46,
+ 0x00000002, 0x00106000, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
+ 0x0010000a, 0x00000001, 0x0a000000, 0x00100072, 0x00000000, 0x00100246,
+ 0x00000000, 0x00004002, 0x00000000, 0xbf008081, 0xbf008081, 0x00000000,
+ 0x0a00000f, 0x00100012, 0x00000001, 0x00100086, 0x00000000, 0x00004002,
+ 0x3f800000, 0x3fb374bc, 0x00000000, 0x00000000, 0x0a000010, 0x00100022,
+ 0x00000001, 0x00100246, 0x00000000, 0x00004002, 0x3f800000, 0xbeb02de0,
+ 0xbf36cf42, 0x00000000, 0x0a00000f, 0x00100042, 0x00000001, 0x00100046,
+ 0x00000000, 0x00004002, 0x3f800000, 0x3fe2d0e5, 0x00000000, 0x00000000,
+ 0x05000036, 0x00100082, 0x00000001, 0x00004001, 0x3f800000, 0x07000038,
+ 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00101e46, 0x00000002,
+ 0x0100003e, 0x54415453, 0x00000074, 0x0000000c, 0x00000002, 0x00000000,
+ 0x00000003, 0x00000005, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x46454452, 0x00000100, 0x00000000, 0x00000000,
+ 0x00000004, 0x0000001c, 0xffff0400, 0x00000100, 0x000000cb, 0x0000009c,
+ 0x00000003, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
+ 0x00000001, 0x000000a7, 0x00000002, 0x00000005, 0x00000004, 0xffffffff,
+ 0x00000000, 0x00000001, 0x0000000d, 0x000000b3, 0x00000002, 0x00000005,
+ 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000d, 0x000000bf,
+ 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000002, 0x00000001,
+ 0x0000000d, 0x53656874, 0x6c706d61, 0x74007265, 0x65546568, 0x72757478,
+ 0x74005965, 0x65546568, 0x72757478, 0x74005565, 0x65546568, 0x72757478,
+ 0x4d005665, 0x6f726369, 0x74666f73, 0x29522820, 0x534c4820, 0x6853204c,
+ 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e362072, 0x36392e33, 0x312e3030,
+ 0x34383336, 0xababab00, 0x4e475349, 0x0000006c, 0x00000003, 0x00000008,
+ 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
+ 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303,
+ 0x00000065, 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f,
+ 0x505f5653, 0x5449534f, 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300,
+ 0xab00524f, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
+ 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
+ 0x45475241, 0xabab0054
+};
+#else
+#error "An appropriate 'yuv' pixel shader is not defined."
+#endif
+
+/* The yuv-rendering pixel shader:
+
+ --- D3D11_PixelShader_YUV_BT601.hlsl ---
+ Texture2D theTextureY : register(t0);
+ Texture2D theTextureU : register(t1);
+ Texture2D theTextureV : register(t2);
+ SamplerState theSampler : register(s0);
+
+ struct PixelShaderInput
+ {
+ float4 pos : SV_POSITION;
+ float2 tex : TEXCOORD0;
+ float4 color : COLOR0;
+ };
+
+ float4 main(PixelShaderInput input) : SV_TARGET
+ {
+ const float3 offset = {-0.0627451017, -0.501960814, -0.501960814};
+ const float3 Rcoeff = {1.1644, 0.0000, 1.5960};
+ const float3 Gcoeff = {1.1644, -0.3918, -0.8130};
+ const float3 Bcoeff = {1.1644, 2.0172, 0.0000};
+
+ float4 Output;
+
+ float3 yuv;
+ yuv.x = theTextureY.Sample(theSampler, input.tex).r;
+ yuv.y = theTextureU.Sample(theSampler, input.tex).r;
+ yuv.z = theTextureV.Sample(theSampler, input.tex).r;
+
+ yuv += offset;
+ Output.r = dot(yuv, Rcoeff);
+ Output.g = dot(yuv, Gcoeff);
+ Output.b = dot(yuv, Bcoeff);
+ Output.a = 1.0f;
+
+ return Output * input.color;
+ }
+
+*/
+#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1)
+static const DWORD D3D11_PixelShader_YUV_BT601[] = {
+ 0x43425844, 0x628ec838, 0xbe9cec6a, 0xc9ee10bb, 0x63283218, 0x00000001,
+ 0x000005e8, 0x00000006, 0x00000038, 0x000001dc, 0x000003bc, 0x00000438,
+ 0x00000540, 0x000005b4, 0x396e6f41, 0x0000019c, 0x0000019c, 0xffff0200,
+ 0x0000016c, 0x00000030, 0x00300000, 0x00300000, 0x00300000, 0x00240003,
+ 0x00300000, 0x00000000, 0x00010001, 0x00020002, 0xffff0200, 0x05000051,
+ 0xa00f0000, 0xbd808081, 0xbf008081, 0xbf008081, 0x3f800000, 0x05000051,
+ 0xa00f0001, 0x3f950b0f, 0x3fcc49ba, 0x00000000, 0x00000000, 0x05000051,
+ 0xa00f0002, 0x3f950b0f, 0xbec89a02, 0xbf5020c5, 0x00000000, 0x05000051,
+ 0xa00f0003, 0x3f950b0f, 0x400119ce, 0x00000000, 0x00000000, 0x0200001f,
+ 0x80000000, 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f,
+ 0x90000000, 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f,
+ 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800,
+ 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40801, 0x03000042, 0x800f0002,
+ 0xb0e40000, 0xa0e40802, 0x02000001, 0x80020000, 0x80000001, 0x02000001,
+ 0x80040000, 0x80000002, 0x03000002, 0x80070000, 0x80e40000, 0xa0e40000,
+ 0x03000005, 0x80080000, 0x80000000, 0xa0000001, 0x04000004, 0x80010001,
+ 0x80aa0000, 0xa0550001, 0x80ff0000, 0x03000008, 0x80020001, 0x80e40000,
+ 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000, 0xa0e40003, 0xa0aa0003,
+ 0x02000001, 0x80080001, 0xa0ff0000, 0x03000005, 0x800f0000, 0x80e40001,
+ 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x52444853,
+ 0x000001d8, 0x00000040, 0x00000076, 0x0300005a, 0x00106000, 0x00000000,
+ 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858, 0x00107000,
+ 0x00000001, 0x00005555, 0x04001858, 0x00107000, 0x00000002, 0x00005555,
+ 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002,
+ 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x09000045,
+ 0x001000f2, 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000,
+ 0x00106000, 0x00000000, 0x09000045, 0x001000f2, 0x00000001, 0x00101046,
+ 0x00000001, 0x00107e46, 0x00000001, 0x00106000, 0x00000000, 0x05000036,
+ 0x00100022, 0x00000000, 0x0010000a, 0x00000001, 0x09000045, 0x001000f2,
+ 0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000002, 0x00106000,
+ 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x0010000a, 0x00000001,
+ 0x0a000000, 0x00100072, 0x00000000, 0x00100246, 0x00000000, 0x00004002,
+ 0xbd808081, 0xbf008081, 0xbf008081, 0x00000000, 0x0a00000f, 0x00100012,
+ 0x00000001, 0x00100086, 0x00000000, 0x00004002, 0x3f950b0f, 0x3fcc49ba,
+ 0x00000000, 0x00000000, 0x0a000010, 0x00100022, 0x00000001, 0x00100246,
+ 0x00000000, 0x00004002, 0x3f950b0f, 0xbec89a02, 0xbf5020c5, 0x00000000,
+ 0x0a00000f, 0x00100042, 0x00000001, 0x00100046, 0x00000000, 0x00004002,
+ 0x3f950b0f, 0x400119ce, 0x00000000, 0x00000000, 0x05000036, 0x00100082,
+ 0x00000001, 0x00004001, 0x3f800000, 0x07000038, 0x001020f2, 0x00000000,
+ 0x00100e46, 0x00000001, 0x00101e46, 0x00000002, 0x0100003e, 0x54415453,
+ 0x00000074, 0x0000000c, 0x00000002, 0x00000000, 0x00000003, 0x00000005,
+ 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x46454452, 0x00000100, 0x00000000, 0x00000000, 0x00000004, 0x0000001c,
+ 0xffff0400, 0x00000100, 0x000000cb, 0x0000009c, 0x00000003, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x000000a7,
+ 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000000, 0x00000001,
+ 0x0000000d, 0x000000b3, 0x00000002, 0x00000005, 0x00000004, 0xffffffff,
+ 0x00000001, 0x00000001, 0x0000000d, 0x000000bf, 0x00000002, 0x00000005,
+ 0x00000004, 0xffffffff, 0x00000002, 0x00000001, 0x0000000d, 0x53656874,
+ 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x74005965, 0x65546568,
+ 0x72757478, 0x74005565, 0x65546568, 0x72757478, 0x4d005665, 0x6f726369,
+ 0x74666f73, 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320,
+ 0x656c6970, 0x2e362072, 0x36392e33, 0x312e3030, 0x34383336, 0xababab00,
+ 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
+ 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
+ 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000,
+ 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
+ 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
+ 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
+ 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
+};
+#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3)
+static const DWORD D3D11_PixelShader_YUV_BT601[] = {
+ 0x43425844, 0x692b159b, 0xf58723cc, 0xf4ceac9e, 0x35eec738, 0x00000001,
+ 0x000005c0, 0x00000006, 0x00000038, 0x000001b4, 0x00000394, 0x00000410,
+ 0x00000518, 0x0000058c, 0x396e6f41, 0x00000174, 0x00000174, 0xffff0200,
+ 0x00000144, 0x00000030, 0x00300000, 0x00300000, 0x00300000, 0x00240003,
+ 0x00300000, 0x00000000, 0x00010001, 0x00020002, 0xffff0201, 0x05000051,
+ 0xa00f0000, 0xbd808081, 0xbf008081, 0x3f800000, 0x00000000, 0x05000051,
+ 0xa00f0001, 0x3f950b0f, 0x3fcc49ba, 0x00000000, 0x400119ce, 0x05000051,
+ 0xa00f0002, 0x3f950b0f, 0xbec89a02, 0xbf5020c5, 0x00000000, 0x0200001f,
+ 0x80000000, 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f,
+ 0x90000000, 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f,
+ 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40801,
+ 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40800, 0x02000001, 0x80020001,
+ 0x80000000, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40802, 0x02000001,
+ 0x80040001, 0x80000000, 0x03000002, 0x80070000, 0x80e40001, 0xa0d40000,
+ 0x0400005a, 0x80010001, 0x80e80000, 0xa0e40001, 0xa0aa0001, 0x03000008,
+ 0x80020001, 0x80e40000, 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000,
+ 0xa0ec0001, 0xa0aa0001, 0x02000001, 0x80080001, 0xa0aa0000, 0x03000005,
+ 0x800f0000, 0x80e40001, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000,
+ 0x0000ffff, 0x52444853, 0x000001d8, 0x00000040, 0x00000076, 0x0300005a,
+ 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
+ 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04001858, 0x00107000,
+ 0x00000002, 0x00005555, 0x03001062, 0x00101032, 0x00000001, 0x03001062,
+ 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
+ 0x00000002, 0x09000045, 0x001000f2, 0x00000000, 0x00101046, 0x00000001,
+ 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x09000045, 0x001000f2,
+ 0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000001, 0x00106000,
+ 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x0010000a, 0x00000001,
+ 0x09000045, 0x001000f2, 0x00000001, 0x00101046, 0x00000001, 0x00107e46,
+ 0x00000002, 0x00106000, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
+ 0x0010000a, 0x00000001, 0x0a000000, 0x00100072, 0x00000000, 0x00100246,
+ 0x00000000, 0x00004002, 0xbd808081, 0xbf008081, 0xbf008081, 0x00000000,
+ 0x0a00000f, 0x00100012, 0x00000001, 0x00100086, 0x00000000, 0x00004002,
+ 0x3f950b0f, 0x3fcc49ba, 0x00000000, 0x00000000, 0x0a000010, 0x00100022,
+ 0x00000001, 0x00100246, 0x00000000, 0x00004002, 0x3f950b0f, 0xbec89a02,
+ 0xbf5020c5, 0x00000000, 0x0a00000f, 0x00100042, 0x00000001, 0x00100046,
+ 0x00000000, 0x00004002, 0x3f950b0f, 0x400119ce, 0x00000000, 0x00000000,
+ 0x05000036, 0x00100082, 0x00000001, 0x00004001, 0x3f800000, 0x07000038,
+ 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00101e46, 0x00000002,
+ 0x0100003e, 0x54415453, 0x00000074, 0x0000000c, 0x00000002, 0x00000000,
+ 0x00000003, 0x00000005, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x46454452, 0x00000100, 0x00000000, 0x00000000,
+ 0x00000004, 0x0000001c, 0xffff0400, 0x00000100, 0x000000cb, 0x0000009c,
+ 0x00000003, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
+ 0x00000001, 0x000000a7, 0x00000002, 0x00000005, 0x00000004, 0xffffffff,
+ 0x00000000, 0x00000001, 0x0000000d, 0x000000b3, 0x00000002, 0x00000005,
+ 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000d, 0x000000bf,
+ 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000002, 0x00000001,
+ 0x0000000d, 0x53656874, 0x6c706d61, 0x74007265, 0x65546568, 0x72757478,
+ 0x74005965, 0x65546568, 0x72757478, 0x74005565, 0x65546568, 0x72757478,
+ 0x4d005665, 0x6f726369, 0x74666f73, 0x29522820, 0x534c4820, 0x6853204c,
+ 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e362072, 0x36392e33, 0x312e3030,
+ 0x34383336, 0xababab00, 0x4e475349, 0x0000006c, 0x00000003, 0x00000008,
+ 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
+ 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303,
+ 0x00000065, 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f,
+ 0x505f5653, 0x5449534f, 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300,
+ 0xab00524f, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
+ 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
+ 0x45475241, 0xabab0054
+};
+#else
+#error "An appropriate 'yuv' pixel shader is not defined."
+#endif
+
+/* The yuv-rendering pixel shader:
+
+ --- D3D11_PixelShader_YUV_BT709.hlsl ---
+ Texture2D theTextureY : register(t0);
+ Texture2D theTextureU : register(t1);
+ Texture2D theTextureV : register(t2);
+ SamplerState theSampler : register(s0);
+
+ struct PixelShaderInput
+ {
+ float4 pos : SV_POSITION;
+ float2 tex : TEXCOORD0;
+ float4 color : COLOR0;
+ };
+
+ float4 main(PixelShaderInput input) : SV_TARGET
+ {
+ const float3 offset = {-0.0627451017, -0.501960814, -0.501960814};
+ const float3 Rcoeff = {1.1644, 0.0000, 1.7927};
+ const float3 Gcoeff = {1.1644, -0.2132, -0.5329};
+ const float3 Bcoeff = {1.1644, 2.1124, 0.0000};
+
+ float4 Output;
+
+ float3 yuv;
+ yuv.x = theTextureY.Sample(theSampler, input.tex).r;
+ yuv.y = theTextureU.Sample(theSampler, input.tex).r;
+ yuv.z = theTextureV.Sample(theSampler, input.tex).r;
+
+ yuv += offset;
+ Output.r = dot(yuv, Rcoeff);
+ Output.g = dot(yuv, Gcoeff);
+ Output.b = dot(yuv, Bcoeff);
+ Output.a = 1.0f;
+
+ return Output * input.color;
+ }
+
+*/
+#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1)
+static const DWORD D3D11_PixelShader_YUV_BT709[] = {
+ 0x43425844, 0x5045fa84, 0xc2908cce, 0x278dacc3, 0xd4276f8f, 0x00000001,
+ 0x000005e8, 0x00000006, 0x00000038, 0x000001dc, 0x000003bc, 0x00000438,
+ 0x00000540, 0x000005b4, 0x396e6f41, 0x0000019c, 0x0000019c, 0xffff0200,
+ 0x0000016c, 0x00000030, 0x00300000, 0x00300000, 0x00300000, 0x00240003,
+ 0x00300000, 0x00000000, 0x00010001, 0x00020002, 0xffff0200, 0x05000051,
+ 0xa00f0000, 0xbd808081, 0xbf008081, 0xbf008081, 0x3f800000, 0x05000051,
+ 0xa00f0001, 0x3f950b0f, 0x3fe57732, 0x00000000, 0x00000000, 0x05000051,
+ 0xa00f0002, 0x3f950b0f, 0xbe5a511a, 0xbf086c22, 0x00000000, 0x05000051,
+ 0xa00f0003, 0x3f950b0f, 0x40073190, 0x00000000, 0x00000000, 0x0200001f,
+ 0x80000000, 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f,
+ 0x90000000, 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f,
+ 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40800,
+ 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40801, 0x03000042, 0x800f0002,
+ 0xb0e40000, 0xa0e40802, 0x02000001, 0x80020000, 0x80000001, 0x02000001,
+ 0x80040000, 0x80000002, 0x03000002, 0x80070000, 0x80e40000, 0xa0e40000,
+ 0x03000005, 0x80080000, 0x80000000, 0xa0000001, 0x04000004, 0x80010001,
+ 0x80aa0000, 0xa0550001, 0x80ff0000, 0x03000008, 0x80020001, 0x80e40000,
+ 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000, 0xa0e40003, 0xa0aa0003,
+ 0x02000001, 0x80080001, 0xa0ff0000, 0x03000005, 0x800f0000, 0x80e40001,
+ 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x52444853,
+ 0x000001d8, 0x00000040, 0x00000076, 0x0300005a, 0x00106000, 0x00000000,
+ 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858, 0x00107000,
+ 0x00000001, 0x00005555, 0x04001858, 0x00107000, 0x00000002, 0x00005555,
+ 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002,
+ 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x09000045,
+ 0x001000f2, 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000,
+ 0x00106000, 0x00000000, 0x09000045, 0x001000f2, 0x00000001, 0x00101046,
+ 0x00000001, 0x00107e46, 0x00000001, 0x00106000, 0x00000000, 0x05000036,
+ 0x00100022, 0x00000000, 0x0010000a, 0x00000001, 0x09000045, 0x001000f2,
+ 0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000002, 0x00106000,
+ 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x0010000a, 0x00000001,
+ 0x0a000000, 0x00100072, 0x00000000, 0x00100246, 0x00000000, 0x00004002,
+ 0xbd808081, 0xbf008081, 0xbf008081, 0x00000000, 0x0a00000f, 0x00100012,
+ 0x00000001, 0x00100086, 0x00000000, 0x00004002, 0x3f950b0f, 0x3fe57732,
+ 0x00000000, 0x00000000, 0x0a000010, 0x00100022, 0x00000001, 0x00100246,
+ 0x00000000, 0x00004002, 0x3f950b0f, 0xbe5a511a, 0xbf086c22, 0x00000000,
+ 0x0a00000f, 0x00100042, 0x00000001, 0x00100046, 0x00000000, 0x00004002,
+ 0x3f950b0f, 0x40073190, 0x00000000, 0x00000000, 0x05000036, 0x00100082,
+ 0x00000001, 0x00004001, 0x3f800000, 0x07000038, 0x001020f2, 0x00000000,
+ 0x00100e46, 0x00000001, 0x00101e46, 0x00000002, 0x0100003e, 0x54415453,
+ 0x00000074, 0x0000000c, 0x00000002, 0x00000000, 0x00000003, 0x00000005,
+ 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x46454452, 0x00000100, 0x00000000, 0x00000000, 0x00000004, 0x0000001c,
+ 0xffff0400, 0x00000100, 0x000000cb, 0x0000009c, 0x00000003, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001, 0x000000a7,
+ 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000000, 0x00000001,
+ 0x0000000d, 0x000000b3, 0x00000002, 0x00000005, 0x00000004, 0xffffffff,
+ 0x00000001, 0x00000001, 0x0000000d, 0x000000bf, 0x00000002, 0x00000005,
+ 0x00000004, 0xffffffff, 0x00000002, 0x00000001, 0x0000000d, 0x53656874,
+ 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x74005965, 0x65546568,
+ 0x72757478, 0x74005565, 0x65546568, 0x72757478, 0x4d005665, 0x6f726369,
+ 0x74666f73, 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320,
+ 0x656c6970, 0x2e362072, 0x36392e33, 0x312e3030, 0x34383336, 0xababab00,
+ 0x4e475349, 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000,
+ 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
+ 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000,
+ 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f,
+ 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f,
+ 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
+ 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
+};
+#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3)
+static const DWORD D3D11_PixelShader_YUV_BT709[] = {
+ 0x43425844, 0x72d13260, 0xf6c36f65, 0x8b9b28f5, 0x5010733c, 0x00000001,
+ 0x000005c0, 0x00000006, 0x00000038, 0x000001b4, 0x00000394, 0x00000410,
+ 0x00000518, 0x0000058c, 0x396e6f41, 0x00000174, 0x00000174, 0xffff0200,
+ 0x00000144, 0x00000030, 0x00300000, 0x00300000, 0x00300000, 0x00240003,
+ 0x00300000, 0x00000000, 0x00010001, 0x00020002, 0xffff0201, 0x05000051,
+ 0xa00f0000, 0xbd808081, 0xbf008081, 0x3f800000, 0x00000000, 0x05000051,
+ 0xa00f0001, 0x3f950b0f, 0x3fe57732, 0x00000000, 0x40073190, 0x05000051,
+ 0xa00f0002, 0x3f950b0f, 0xbe5a511a, 0xbf086c22, 0x00000000, 0x0200001f,
+ 0x80000000, 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f,
+ 0x90000000, 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x0200001f,
+ 0x90000000, 0xa00f0802, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40801,
+ 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40800, 0x02000001, 0x80020001,
+ 0x80000000, 0x03000042, 0x800f0000, 0xb0e40000, 0xa0e40802, 0x02000001,
+ 0x80040001, 0x80000000, 0x03000002, 0x80070000, 0x80e40001, 0xa0d40000,
+ 0x0400005a, 0x80010001, 0x80e80000, 0xa0e40001, 0xa0aa0001, 0x03000008,
+ 0x80020001, 0x80e40000, 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000,
+ 0xa0ec0001, 0xa0aa0001, 0x02000001, 0x80080001, 0xa0aa0000, 0x03000005,
+ 0x800f0000, 0x80e40001, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000,
+ 0x0000ffff, 0x52444853, 0x000001d8, 0x00000040, 0x00000076, 0x0300005a,
+ 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
+ 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04001858, 0x00107000,
+ 0x00000002, 0x00005555, 0x03001062, 0x00101032, 0x00000001, 0x03001062,
+ 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
+ 0x00000002, 0x09000045, 0x001000f2, 0x00000000, 0x00101046, 0x00000001,
+ 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x09000045, 0x001000f2,
+ 0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000001, 0x00106000,
+ 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x0010000a, 0x00000001,
+ 0x09000045, 0x001000f2, 0x00000001, 0x00101046, 0x00000001, 0x00107e46,
+ 0x00000002, 0x00106000, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
+ 0x0010000a, 0x00000001, 0x0a000000, 0x00100072, 0x00000000, 0x00100246,
+ 0x00000000, 0x00004002, 0xbd808081, 0xbf008081, 0xbf008081, 0x00000000,
+ 0x0a00000f, 0x00100012, 0x00000001, 0x00100086, 0x00000000, 0x00004002,
+ 0x3f950b0f, 0x3fe57732, 0x00000000, 0x00000000, 0x0a000010, 0x00100022,
+ 0x00000001, 0x00100246, 0x00000000, 0x00004002, 0x3f950b0f, 0xbe5a511a,
+ 0xbf086c22, 0x00000000, 0x0a00000f, 0x00100042, 0x00000001, 0x00100046,
+ 0x00000000, 0x00004002, 0x3f950b0f, 0x40073190, 0x00000000, 0x00000000,
+ 0x05000036, 0x00100082, 0x00000001, 0x00004001, 0x3f800000, 0x07000038,
+ 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00101e46, 0x00000002,
+ 0x0100003e, 0x54415453, 0x00000074, 0x0000000c, 0x00000002, 0x00000000,
+ 0x00000003, 0x00000005, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x46454452, 0x00000100, 0x00000000, 0x00000000,
+ 0x00000004, 0x0000001c, 0xffff0400, 0x00000100, 0x000000cb, 0x0000009c,
+ 0x00000003, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
+ 0x00000001, 0x000000a7, 0x00000002, 0x00000005, 0x00000004, 0xffffffff,
+ 0x00000000, 0x00000001, 0x0000000d, 0x000000b3, 0x00000002, 0x00000005,
+ 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000d, 0x000000bf,
+ 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000002, 0x00000001,
+ 0x0000000d, 0x53656874, 0x6c706d61, 0x74007265, 0x65546568, 0x72757478,
+ 0x74005965, 0x65546568, 0x72757478, 0x74005565, 0x65546568, 0x72757478,
+ 0x4d005665, 0x6f726369, 0x74666f73, 0x29522820, 0x534c4820, 0x6853204c,
+ 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e362072, 0x36392e33, 0x312e3030,
+ 0x34383336, 0xababab00, 0x4e475349, 0x0000006c, 0x00000003, 0x00000008,
+ 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
+ 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303,
+ 0x00000065, 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f,
+ 0x505f5653, 0x5449534f, 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300,
+ 0xab00524f, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
+ 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
+ 0x45475241, 0xabab0054
+};
+#else
+#error "An appropriate 'yuv' pixel shader is not defined."
+#endif
+
+/* The yuv-rendering pixel shader:
+
+ --- D3D11_PixelShader_NV12_JPEG.hlsl ---
+ Texture2D theTextureY : register(t0);
+ Texture2D theTextureUV : register(t1);
+ SamplerState theSampler : register(s0);
+
+ struct PixelShaderInput
+ {
+ float4 pos : SV_POSITION;
+ float2 tex : TEXCOORD0;
+ float4 color : COLOR0;
+ };
+
+ float4 main(PixelShaderInput input) : SV_TARGET
+ {
+ const float3 offset = {0.0, -0.501960814, -0.501960814};
+ const float3 Rcoeff = {1.0000, 0.0000, 1.4020};
+ const float3 Gcoeff = {1.0000, -0.3441, -0.7141};
+ const float3 Bcoeff = {1.0000, 1.7720, 0.0000};
+
+ float4 Output;
+
+ float3 yuv;
+ yuv.x = theTextureY.Sample(theSampler, input.tex).r;
+ yuv.yz = theTextureUV.Sample(theSampler, input.tex).rg;
+
+ yuv += offset;
+ Output.r = dot(yuv, Rcoeff);
+ Output.g = dot(yuv, Gcoeff);
+ Output.b = dot(yuv, Bcoeff);
+ Output.a = 1.0f;
+
+ return Output * input.color;
+ }
+
+*/
+#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1)
+static const DWORD D3D11_PixelShader_NV12_JPEG[] = {
+ 0x43425844, 0x8fb9c77a, 0xe9e39686, 0x62b0e0e9, 0xd2bf8183, 0x00000001,
+ 0x00000548, 0x00000006, 0x00000038, 0x000001b0, 0x00000348, 0x000003c4,
+ 0x000004a0, 0x00000514, 0x396e6f41, 0x00000170, 0x00000170, 0xffff0200,
+ 0x00000144, 0x0000002c, 0x002c0000, 0x002c0000, 0x002c0000, 0x00240002,
+ 0x002c0000, 0x00000000, 0x00010001, 0xffff0200, 0x05000051, 0xa00f0000,
+ 0x00000000, 0xbf008081, 0xbf008081, 0x3f800000, 0x05000051, 0xa00f0001,
+ 0x3f800000, 0x3fb374bc, 0x00000000, 0x00000000, 0x05000051, 0xa00f0002,
+ 0x3f800000, 0xbeb02de0, 0xbf36cf42, 0x00000000, 0x05000051, 0xa00f0003,
+ 0x3f800000, 0x3fe2d0e5, 0x00000000, 0x00000000, 0x0200001f, 0x80000000,
+ 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000,
+ 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x03000042, 0x800f0000,
+ 0xb0e40000, 0xa0e40800, 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40801,
+ 0x02000001, 0x80060000, 0x80d20001, 0x03000002, 0x80070000, 0x80e40000,
+ 0xa0e40000, 0x03000005, 0x80080000, 0x80000000, 0xa0000001, 0x04000004,
+ 0x80010001, 0x80aa0000, 0xa0550001, 0x80ff0000, 0x03000008, 0x80020001,
+ 0x80e40000, 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000, 0xa0e40003,
+ 0xa0aa0003, 0x02000001, 0x80080001, 0xa0ff0000, 0x03000005, 0x800f0000,
+ 0x80e40001, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff,
+ 0x52444853, 0x00000190, 0x00000040, 0x00000064, 0x0300005a, 0x00106000,
+ 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
+ 0x00107000, 0x00000001, 0x00005555, 0x03001062, 0x00101032, 0x00000001,
+ 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000,
+ 0x02000068, 0x00000002, 0x09000045, 0x001000f2, 0x00000000, 0x00101046,
+ 0x00000001, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x09000045,
+ 0x001000f2, 0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000001,
+ 0x00106000, 0x00000000, 0x05000036, 0x00100062, 0x00000000, 0x00100106,
+ 0x00000001, 0x0a000000, 0x00100072, 0x00000000, 0x00100246, 0x00000000,
+ 0x00004002, 0x00000000, 0xbf008081, 0xbf008081, 0x00000000, 0x0a00000f,
+ 0x00100012, 0x00000001, 0x00100086, 0x00000000, 0x00004002, 0x3f800000,
+ 0x3fb374bc, 0x00000000, 0x00000000, 0x0a000010, 0x00100022, 0x00000001,
+ 0x00100246, 0x00000000, 0x00004002, 0x3f800000, 0xbeb02de0, 0xbf36cf42,
+ 0x00000000, 0x0a00000f, 0x00100042, 0x00000001, 0x00100046, 0x00000000,
+ 0x00004002, 0x3f800000, 0x3fe2d0e5, 0x00000000, 0x00000000, 0x05000036,
+ 0x00100082, 0x00000001, 0x00004001, 0x3f800000, 0x07000038, 0x001020f2,
+ 0x00000000, 0x00100e46, 0x00000001, 0x00101e46, 0x00000002, 0x0100003e,
+ 0x54415453, 0x00000074, 0x0000000a, 0x00000002, 0x00000000, 0x00000003,
+ 0x00000005, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x46454452, 0x000000d4, 0x00000000, 0x00000000, 0x00000003,
+ 0x0000001c, 0xffff0400, 0x00000100, 0x000000a0, 0x0000007c, 0x00000003,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001,
+ 0x00000087, 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000000,
+ 0x00000001, 0x0000000d, 0x00000093, 0x00000002, 0x00000005, 0x00000004,
+ 0xffffffff, 0x00000001, 0x00000001, 0x0000000d, 0x53656874, 0x6c706d61,
+ 0x74007265, 0x65546568, 0x72757478, 0x74005965, 0x65546568, 0x72757478,
+ 0x00565565, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53,
+ 0x65646168, 0x6f432072, 0x6c69706d, 0x36207265, 0x392e332e, 0x2e303036,
+ 0x38333631, 0xabab0034, 0x4e475349, 0x0000006c, 0x00000003, 0x00000008,
+ 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
+ 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303,
+ 0x00000065, 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f,
+ 0x505f5653, 0x5449534f, 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300,
+ 0xab00524f, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
+ 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
+ 0x45475241, 0xabab0054
+};
+#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3)
+static const DWORD D3D11_PixelShader_NV12_JPEG[] = {
+ 0x43425844, 0xe33e5d8b, 0x1b5f6461, 0x1afee99f, 0xcc345c04, 0x00000001,
+ 0x00000520, 0x00000006, 0x00000038, 0x00000188, 0x00000320, 0x0000039c,
+ 0x00000478, 0x000004ec, 0x396e6f41, 0x00000148, 0x00000148, 0xffff0200,
+ 0x0000011c, 0x0000002c, 0x002c0000, 0x002c0000, 0x002c0000, 0x00240002,
+ 0x002c0000, 0x00000000, 0x00010001, 0xffff0201, 0x05000051, 0xa00f0000,
+ 0x00000000, 0xbf008081, 0x3f800000, 0x3fb374bc, 0x05000051, 0xa00f0001,
+ 0x3f800000, 0xbeb02de0, 0xbf36cf42, 0x00000000, 0x05000051, 0xa00f0002,
+ 0x3f800000, 0x3fe2d0e5, 0x00000000, 0x00000000, 0x0200001f, 0x80000000,
+ 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000,
+ 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x03000042, 0x800f0000,
+ 0xb0e40000, 0xa0e40801, 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40800,
+ 0x02000001, 0x80060001, 0x80d00000, 0x03000002, 0x80070000, 0x80e40001,
+ 0xa0d40000, 0x0400005a, 0x80010001, 0x80e80000, 0xa0ee0000, 0xa0000000,
+ 0x03000008, 0x80020001, 0x80e40000, 0xa0e40001, 0x0400005a, 0x80040001,
+ 0x80e40000, 0xa0e40002, 0xa0aa0002, 0x02000001, 0x80080001, 0xa0aa0000,
+ 0x03000005, 0x800f0000, 0x80e40001, 0xb0e40001, 0x02000001, 0x800f0800,
+ 0x80e40000, 0x0000ffff, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
+ 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000,
+ 0x00005555, 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x03001062,
+ 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, 0x03000065,
+ 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x09000045, 0x001000f2,
+ 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
+ 0x00000000, 0x09000045, 0x001000f2, 0x00000001, 0x00101046, 0x00000001,
+ 0x00107e46, 0x00000001, 0x00106000, 0x00000000, 0x05000036, 0x00100062,
+ 0x00000000, 0x00100106, 0x00000001, 0x0a000000, 0x00100072, 0x00000000,
+ 0x00100246, 0x00000000, 0x00004002, 0x00000000, 0xbf008081, 0xbf008081,
+ 0x00000000, 0x0a00000f, 0x00100012, 0x00000001, 0x00100086, 0x00000000,
+ 0x00004002, 0x3f800000, 0x3fb374bc, 0x00000000, 0x00000000, 0x0a000010,
+ 0x00100022, 0x00000001, 0x00100246, 0x00000000, 0x00004002, 0x3f800000,
+ 0xbeb02de0, 0xbf36cf42, 0x00000000, 0x0a00000f, 0x00100042, 0x00000001,
+ 0x00100046, 0x00000000, 0x00004002, 0x3f800000, 0x3fe2d0e5, 0x00000000,
+ 0x00000000, 0x05000036, 0x00100082, 0x00000001, 0x00004001, 0x3f800000,
+ 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00101e46,
+ 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x0000000a, 0x00000002,
+ 0x00000000, 0x00000003, 0x00000005, 0x00000000, 0x00000000, 0x00000001,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000d4, 0x00000000,
+ 0x00000000, 0x00000003, 0x0000001c, 0xffff0400, 0x00000100, 0x000000a0,
+ 0x0000007c, 0x00000003, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000001, 0x00000001, 0x00000087, 0x00000002, 0x00000005, 0x00000004,
+ 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x00000093, 0x00000002,
+ 0x00000005, 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000d,
+ 0x53656874, 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x74005965,
+ 0x65546568, 0x72757478, 0x00565565, 0x7263694d, 0x666f736f, 0x52282074,
+ 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x36207265,
+ 0x392e332e, 0x2e303036, 0x38333631, 0xabab0034, 0x4e475349, 0x0000006c,
+ 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
+ 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000001, 0x00000303, 0x00000065, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x43584554,
+ 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x0000002c, 0x00000001,
+ 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
+ 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
+};
+#else
+#error "An appropriate 'yuv' pixel shader is not defined."
+#endif
+
+/* The yuv-rendering pixel shader:
+
+ --- D3D11_PixelShader_NV12_BT601.hlsl ---
+ Texture2D theTextureY : register(t0);
+ Texture2D theTextureUV : register(t1);
+ SamplerState theSampler : register(s0);
+
+ struct PixelShaderInput
+ {
+ float4 pos : SV_POSITION;
+ float2 tex : TEXCOORD0;
+ float4 color : COLOR0;
+ };
+
+ float4 main(PixelShaderInput input) : SV_TARGET
+ {
+ const float3 offset = {-0.0627451017, -0.501960814, -0.501960814};
+ const float3 Rcoeff = {1.1644, 0.0000, 1.5960};
+ const float3 Gcoeff = {1.1644, -0.3918, -0.8130};
+ const float3 Bcoeff = {1.1644, 2.0172, 0.0000};
+
+ float4 Output;
+
+ float3 yuv;
+ yuv.x = theTextureY.Sample(theSampler, input.tex).r;
+ yuv.yz = theTextureUV.Sample(theSampler, input.tex).rg;
+
+ yuv += offset;
+ Output.r = dot(yuv, Rcoeff);
+ Output.g = dot(yuv, Gcoeff);
+ Output.b = dot(yuv, Bcoeff);
+ Output.a = 1.0f;
+
+ return Output * input.color;
+ }
+
+*/
+#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1)
+static const DWORD D3D11_PixelShader_NV12_BT601[] = {
+ 0x43425844, 0xd1d24a0c, 0x337c447a, 0x22b55cff, 0xb5c9c74b, 0x00000001,
+ 0x00000548, 0x00000006, 0x00000038, 0x000001b0, 0x00000348, 0x000003c4,
+ 0x000004a0, 0x00000514, 0x396e6f41, 0x00000170, 0x00000170, 0xffff0200,
+ 0x00000144, 0x0000002c, 0x002c0000, 0x002c0000, 0x002c0000, 0x00240002,
+ 0x002c0000, 0x00000000, 0x00010001, 0xffff0200, 0x05000051, 0xa00f0000,
+ 0xbd808081, 0xbf008081, 0xbf008081, 0x3f800000, 0x05000051, 0xa00f0001,
+ 0x3f950b0f, 0x3fcc49ba, 0x00000000, 0x00000000, 0x05000051, 0xa00f0002,
+ 0x3f950b0f, 0xbec89a02, 0xbf5020c5, 0x00000000, 0x05000051, 0xa00f0003,
+ 0x3f950b0f, 0x400119ce, 0x00000000, 0x00000000, 0x0200001f, 0x80000000,
+ 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000,
+ 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x03000042, 0x800f0000,
+ 0xb0e40000, 0xa0e40800, 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40801,
+ 0x02000001, 0x80060000, 0x80d20001, 0x03000002, 0x80070000, 0x80e40000,
+ 0xa0e40000, 0x03000005, 0x80080000, 0x80000000, 0xa0000001, 0x04000004,
+ 0x80010001, 0x80aa0000, 0xa0550001, 0x80ff0000, 0x03000008, 0x80020001,
+ 0x80e40000, 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000, 0xa0e40003,
+ 0xa0aa0003, 0x02000001, 0x80080001, 0xa0ff0000, 0x03000005, 0x800f0000,
+ 0x80e40001, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff,
+ 0x52444853, 0x00000190, 0x00000040, 0x00000064, 0x0300005a, 0x00106000,
+ 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
+ 0x00107000, 0x00000001, 0x00005555, 0x03001062, 0x00101032, 0x00000001,
+ 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000,
+ 0x02000068, 0x00000002, 0x09000045, 0x001000f2, 0x00000000, 0x00101046,
+ 0x00000001, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x09000045,
+ 0x001000f2, 0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000001,
+ 0x00106000, 0x00000000, 0x05000036, 0x00100062, 0x00000000, 0x00100106,
+ 0x00000001, 0x0a000000, 0x00100072, 0x00000000, 0x00100246, 0x00000000,
+ 0x00004002, 0xbd808081, 0xbf008081, 0xbf008081, 0x00000000, 0x0a00000f,
+ 0x00100012, 0x00000001, 0x00100086, 0x00000000, 0x00004002, 0x3f950b0f,
+ 0x3fcc49ba, 0x00000000, 0x00000000, 0x0a000010, 0x00100022, 0x00000001,
+ 0x00100246, 0x00000000, 0x00004002, 0x3f950b0f, 0xbec89a02, 0xbf5020c5,
+ 0x00000000, 0x0a00000f, 0x00100042, 0x00000001, 0x00100046, 0x00000000,
+ 0x00004002, 0x3f950b0f, 0x400119ce, 0x00000000, 0x00000000, 0x05000036,
+ 0x00100082, 0x00000001, 0x00004001, 0x3f800000, 0x07000038, 0x001020f2,
+ 0x00000000, 0x00100e46, 0x00000001, 0x00101e46, 0x00000002, 0x0100003e,
+ 0x54415453, 0x00000074, 0x0000000a, 0x00000002, 0x00000000, 0x00000003,
+ 0x00000005, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x46454452, 0x000000d4, 0x00000000, 0x00000000, 0x00000003,
+ 0x0000001c, 0xffff0400, 0x00000100, 0x000000a0, 0x0000007c, 0x00000003,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001,
+ 0x00000087, 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000000,
+ 0x00000001, 0x0000000d, 0x00000093, 0x00000002, 0x00000005, 0x00000004,
+ 0xffffffff, 0x00000001, 0x00000001, 0x0000000d, 0x53656874, 0x6c706d61,
+ 0x74007265, 0x65546568, 0x72757478, 0x74005965, 0x65546568, 0x72757478,
+ 0x00565565, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53,
+ 0x65646168, 0x6f432072, 0x6c69706d, 0x36207265, 0x392e332e, 0x2e303036,
+ 0x38333631, 0xabab0034, 0x4e475349, 0x0000006c, 0x00000003, 0x00000008,
+ 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
+ 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303,
+ 0x00000065, 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f,
+ 0x505f5653, 0x5449534f, 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300,
+ 0xab00524f, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
+ 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
+ 0x45475241, 0xabab0054
+};
+#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3)
+static const DWORD D3D11_PixelShader_NV12_BT601[] = {
+ 0x43425844, 0x84b8b692, 0x589b9edd, 0x51ef2f0b, 0xf7247962, 0x00000001,
+ 0x00000520, 0x00000006, 0x00000038, 0x00000188, 0x00000320, 0x0000039c,
+ 0x00000478, 0x000004ec, 0x396e6f41, 0x00000148, 0x00000148, 0xffff0200,
+ 0x0000011c, 0x0000002c, 0x002c0000, 0x002c0000, 0x002c0000, 0x00240002,
+ 0x002c0000, 0x00000000, 0x00010001, 0xffff0201, 0x05000051, 0xa00f0000,
+ 0xbd808081, 0xbf008081, 0x3f800000, 0x00000000, 0x05000051, 0xa00f0001,
+ 0x3f950b0f, 0x3fcc49ba, 0x00000000, 0x400119ce, 0x05000051, 0xa00f0002,
+ 0x3f950b0f, 0xbec89a02, 0xbf5020c5, 0x00000000, 0x0200001f, 0x80000000,
+ 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000,
+ 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x03000042, 0x800f0000,
+ 0xb0e40000, 0xa0e40801, 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40800,
+ 0x02000001, 0x80060001, 0x80d00000, 0x03000002, 0x80070000, 0x80e40001,
+ 0xa0d40000, 0x0400005a, 0x80010001, 0x80e80000, 0xa0e40001, 0xa0aa0001,
+ 0x03000008, 0x80020001, 0x80e40000, 0xa0e40002, 0x0400005a, 0x80040001,
+ 0x80e40000, 0xa0ec0001, 0xa0aa0001, 0x02000001, 0x80080001, 0xa0aa0000,
+ 0x03000005, 0x800f0000, 0x80e40001, 0xb0e40001, 0x02000001, 0x800f0800,
+ 0x80e40000, 0x0000ffff, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
+ 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000,
+ 0x00005555, 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x03001062,
+ 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, 0x03000065,
+ 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x09000045, 0x001000f2,
+ 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
+ 0x00000000, 0x09000045, 0x001000f2, 0x00000001, 0x00101046, 0x00000001,
+ 0x00107e46, 0x00000001, 0x00106000, 0x00000000, 0x05000036, 0x00100062,
+ 0x00000000, 0x00100106, 0x00000001, 0x0a000000, 0x00100072, 0x00000000,
+ 0x00100246, 0x00000000, 0x00004002, 0xbd808081, 0xbf008081, 0xbf008081,
+ 0x00000000, 0x0a00000f, 0x00100012, 0x00000001, 0x00100086, 0x00000000,
+ 0x00004002, 0x3f950b0f, 0x3fcc49ba, 0x00000000, 0x00000000, 0x0a000010,
+ 0x00100022, 0x00000001, 0x00100246, 0x00000000, 0x00004002, 0x3f950b0f,
+ 0xbec89a02, 0xbf5020c5, 0x00000000, 0x0a00000f, 0x00100042, 0x00000001,
+ 0x00100046, 0x00000000, 0x00004002, 0x3f950b0f, 0x400119ce, 0x00000000,
+ 0x00000000, 0x05000036, 0x00100082, 0x00000001, 0x00004001, 0x3f800000,
+ 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00101e46,
+ 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x0000000a, 0x00000002,
+ 0x00000000, 0x00000003, 0x00000005, 0x00000000, 0x00000000, 0x00000001,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000d4, 0x00000000,
+ 0x00000000, 0x00000003, 0x0000001c, 0xffff0400, 0x00000100, 0x000000a0,
+ 0x0000007c, 0x00000003, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000001, 0x00000001, 0x00000087, 0x00000002, 0x00000005, 0x00000004,
+ 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x00000093, 0x00000002,
+ 0x00000005, 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000d,
+ 0x53656874, 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x74005965,
+ 0x65546568, 0x72757478, 0x00565565, 0x7263694d, 0x666f736f, 0x52282074,
+ 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x36207265,
+ 0x392e332e, 0x2e303036, 0x38333631, 0xabab0034, 0x4e475349, 0x0000006c,
+ 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
+ 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000001, 0x00000303, 0x00000065, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x43584554,
+ 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x0000002c, 0x00000001,
+ 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
+ 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
+};
+#else
+#error "An appropriate 'yuv' pixel shader is not defined."
+#endif
+
+/* The yuv-rendering pixel shader:
+
+ --- D3D11_PixelShader_NV12_BT709.hlsl ---
+ Texture2D theTextureY : register(t0);
+ Texture2D theTextureUV : register(t1);
+ SamplerState theSampler : register(s0);
+
+ struct PixelShaderInput
+ {
+ float4 pos : SV_POSITION;
+ float2 tex : TEXCOORD0;
+ float4 color : COLOR0;
+ };
+
+ float4 main(PixelShaderInput input) : SV_TARGET
+ {
+ const float3 offset = {-0.0627451017, -0.501960814, -0.501960814};
+ const float3 Rcoeff = {1.1644, 0.0000, 1.7927};
+ const float3 Gcoeff = {1.1644, -0.2132, -0.5329};
+ const float3 Bcoeff = {1.1644, 2.1124, 0.0000};
+
+ float4 Output;
+
+ float3 yuv;
+ yuv.x = theTextureY.Sample(theSampler, input.tex).r;
+ yuv.yz = theTextureUV.Sample(theSampler, input.tex).rg;
+
+ yuv += offset;
+ Output.r = dot(yuv, Rcoeff);
+ Output.g = dot(yuv, Gcoeff);
+ Output.b = dot(yuv, Bcoeff);
+ Output.a = 1.0f;
+
+ return Output * input.color;
+ }
+
+*/
+#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1)
+static const DWORD D3D11_PixelShader_NV12_BT709[] = {
+ 0x43425844, 0x40d1b8d5, 0xaf4b78b5, 0x907fd0b5, 0xa2d23686, 0x00000001,
+ 0x00000548, 0x00000006, 0x00000038, 0x000001b0, 0x00000348, 0x000003c4,
+ 0x000004a0, 0x00000514, 0x396e6f41, 0x00000170, 0x00000170, 0xffff0200,
+ 0x00000144, 0x0000002c, 0x002c0000, 0x002c0000, 0x002c0000, 0x00240002,
+ 0x002c0000, 0x00000000, 0x00010001, 0xffff0200, 0x05000051, 0xa00f0000,
+ 0xbd808081, 0xbf008081, 0xbf008081, 0x3f800000, 0x05000051, 0xa00f0001,
+ 0x3f950b0f, 0x3fe57732, 0x00000000, 0x00000000, 0x05000051, 0xa00f0002,
+ 0x3f950b0f, 0xbe5a511a, 0xbf086c22, 0x00000000, 0x05000051, 0xa00f0003,
+ 0x3f950b0f, 0x40073190, 0x00000000, 0x00000000, 0x0200001f, 0x80000000,
+ 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000,
+ 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x03000042, 0x800f0000,
+ 0xb0e40000, 0xa0e40800, 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40801,
+ 0x02000001, 0x80060000, 0x80d20001, 0x03000002, 0x80070000, 0x80e40000,
+ 0xa0e40000, 0x03000005, 0x80080000, 0x80000000, 0xa0000001, 0x04000004,
+ 0x80010001, 0x80aa0000, 0xa0550001, 0x80ff0000, 0x03000008, 0x80020001,
+ 0x80e40000, 0xa0e40002, 0x0400005a, 0x80040001, 0x80e40000, 0xa0e40003,
+ 0xa0aa0003, 0x02000001, 0x80080001, 0xa0ff0000, 0x03000005, 0x800f0000,
+ 0x80e40001, 0xb0e40001, 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff,
+ 0x52444853, 0x00000190, 0x00000040, 0x00000064, 0x0300005a, 0x00106000,
+ 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
+ 0x00107000, 0x00000001, 0x00005555, 0x03001062, 0x00101032, 0x00000001,
+ 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000,
+ 0x02000068, 0x00000002, 0x09000045, 0x001000f2, 0x00000000, 0x00101046,
+ 0x00000001, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x09000045,
+ 0x001000f2, 0x00000001, 0x00101046, 0x00000001, 0x00107e46, 0x00000001,
+ 0x00106000, 0x00000000, 0x05000036, 0x00100062, 0x00000000, 0x00100106,
+ 0x00000001, 0x0a000000, 0x00100072, 0x00000000, 0x00100246, 0x00000000,
+ 0x00004002, 0xbd808081, 0xbf008081, 0xbf008081, 0x00000000, 0x0a00000f,
+ 0x00100012, 0x00000001, 0x00100086, 0x00000000, 0x00004002, 0x3f950b0f,
+ 0x3fe57732, 0x00000000, 0x00000000, 0x0a000010, 0x00100022, 0x00000001,
+ 0x00100246, 0x00000000, 0x00004002, 0x3f950b0f, 0xbe5a511a, 0xbf086c22,
+ 0x00000000, 0x0a00000f, 0x00100042, 0x00000001, 0x00100046, 0x00000000,
+ 0x00004002, 0x3f950b0f, 0x40073190, 0x00000000, 0x00000000, 0x05000036,
+ 0x00100082, 0x00000001, 0x00004001, 0x3f800000, 0x07000038, 0x001020f2,
+ 0x00000000, 0x00100e46, 0x00000001, 0x00101e46, 0x00000002, 0x0100003e,
+ 0x54415453, 0x00000074, 0x0000000a, 0x00000002, 0x00000000, 0x00000003,
+ 0x00000005, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x46454452, 0x000000d4, 0x00000000, 0x00000000, 0x00000003,
+ 0x0000001c, 0xffff0400, 0x00000100, 0x000000a0, 0x0000007c, 0x00000003,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000001,
+ 0x00000087, 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000000,
+ 0x00000001, 0x0000000d, 0x00000093, 0x00000002, 0x00000005, 0x00000004,
+ 0xffffffff, 0x00000001, 0x00000001, 0x0000000d, 0x53656874, 0x6c706d61,
+ 0x74007265, 0x65546568, 0x72757478, 0x74005965, 0x65546568, 0x72757478,
+ 0x00565565, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53,
+ 0x65646168, 0x6f432072, 0x6c69706d, 0x36207265, 0x392e332e, 0x2e303036,
+ 0x38333631, 0xabab0034, 0x4e475349, 0x0000006c, 0x00000003, 0x00000008,
+ 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
+ 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303,
+ 0x00000065, 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f,
+ 0x505f5653, 0x5449534f, 0x004e4f49, 0x43584554, 0x44524f4f, 0x4c4f4300,
+ 0xab00524f, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
+ 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
+ 0x45475241, 0xabab0054
+};
+#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3)
+static const DWORD D3D11_PixelShader_NV12_BT709[] = {
+ 0x43425844, 0xa3bba187, 0x71b6afa9, 0x15998682, 0x2d545cae, 0x00000001,
+ 0x00000520, 0x00000006, 0x00000038, 0x00000188, 0x00000320, 0x0000039c,
+ 0x00000478, 0x000004ec, 0x396e6f41, 0x00000148, 0x00000148, 0xffff0200,
+ 0x0000011c, 0x0000002c, 0x002c0000, 0x002c0000, 0x002c0000, 0x00240002,
+ 0x002c0000, 0x00000000, 0x00010001, 0xffff0201, 0x05000051, 0xa00f0000,
+ 0xbd808081, 0xbf008081, 0x3f800000, 0x00000000, 0x05000051, 0xa00f0001,
+ 0x3f950b0f, 0x3fe57732, 0x00000000, 0x40073190, 0x05000051, 0xa00f0002,
+ 0x3f950b0f, 0xbe5a511a, 0xbf086c22, 0x00000000, 0x0200001f, 0x80000000,
+ 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000,
+ 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x03000042, 0x800f0000,
+ 0xb0e40000, 0xa0e40801, 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40800,
+ 0x02000001, 0x80060001, 0x80d00000, 0x03000002, 0x80070000, 0x80e40001,
+ 0xa0d40000, 0x0400005a, 0x80010001, 0x80e80000, 0xa0e40001, 0xa0aa0001,
+ 0x03000008, 0x80020001, 0x80e40000, 0xa0e40002, 0x0400005a, 0x80040001,
+ 0x80e40000, 0xa0ec0001, 0xa0aa0001, 0x02000001, 0x80080001, 0xa0aa0000,
+ 0x03000005, 0x800f0000, 0x80e40001, 0xb0e40001, 0x02000001, 0x800f0800,
+ 0x80e40000, 0x0000ffff, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
+ 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000,
+ 0x00005555, 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x03001062,
+ 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, 0x03000065,
+ 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x09000045, 0x001000f2,
+ 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
+ 0x00000000, 0x09000045, 0x001000f2, 0x00000001, 0x00101046, 0x00000001,
+ 0x00107e46, 0x00000001, 0x00106000, 0x00000000, 0x05000036, 0x00100062,
+ 0x00000000, 0x00100106, 0x00000001, 0x0a000000, 0x00100072, 0x00000000,
+ 0x00100246, 0x00000000, 0x00004002, 0xbd808081, 0xbf008081, 0xbf008081,
+ 0x00000000, 0x0a00000f, 0x00100012, 0x00000001, 0x00100086, 0x00000000,
+ 0x00004002, 0x3f950b0f, 0x3fe57732, 0x00000000, 0x00000000, 0x0a000010,
+ 0x00100022, 0x00000001, 0x00100246, 0x00000000, 0x00004002, 0x3f950b0f,
+ 0xbe5a511a, 0xbf086c22, 0x00000000, 0x0a00000f, 0x00100042, 0x00000001,
+ 0x00100046, 0x00000000, 0x00004002, 0x3f950b0f, 0x40073190, 0x00000000,
+ 0x00000000, 0x05000036, 0x00100082, 0x00000001, 0x00004001, 0x3f800000,
+ 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00101e46,
+ 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x0000000a, 0x00000002,
+ 0x00000000, 0x00000003, 0x00000005, 0x00000000, 0x00000000, 0x00000001,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000d4, 0x00000000,
+ 0x00000000, 0x00000003, 0x0000001c, 0xffff0400, 0x00000100, 0x000000a0,
+ 0x0000007c, 0x00000003, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000001, 0x00000001, 0x00000087, 0x00000002, 0x00000005, 0x00000004,
+ 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x00000093, 0x00000002,
+ 0x00000005, 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000d,
+ 0x53656874, 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x74005965,
+ 0x65546568, 0x72757478, 0x00565565, 0x7263694d, 0x666f736f, 0x52282074,
+ 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x36207265,
+ 0x392e332e, 0x2e303036, 0x38333631, 0xabab0034, 0x4e475349, 0x0000006c,
+ 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
+ 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000001, 0x00000303, 0x00000065, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x43584554,
+ 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x0000002c, 0x00000001,
+ 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
+ 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
+};
+#else
+#error "An appropriate 'yuv' pixel shader is not defined."
+#endif
+
+/* The yuv-rendering pixel shader:
+
+ --- D3D11_PixelShader_NV21_JPEG.hlsl ---
+ Texture2D theTextureY : register(t0);
+ Texture2D theTextureUV : register(t1);
+ SamplerState theSampler : register(s0);
+
+ struct PixelShaderInput
+ {
+ float4 pos : SV_POSITION;
+ float2 tex : TEXCOORD0;
+ float4 color : COLOR0;
+ };
+
+ float4 main(PixelShaderInput input) : SV_TARGET
+ {
+ const float3 offset = {0.0, -0.501960814, -0.501960814};
+ const float3 Rcoeff = {1.0000, 0.0000, 1.4020};
+ const float3 Gcoeff = {1.0000, -0.3441, -0.7141};
+ const float3 Bcoeff = {1.0000, 1.7720, 0.0000};
+
+ float4 Output;
+
+ float3 yuv;
+ yuv.x = theTextureY.Sample(theSampler, input.tex).r;
+ yuv.yz = theTextureUV.Sample(theSampler, input.tex).gr;
+
+ yuv += offset;
+ Output.r = dot(yuv, Rcoeff);
+ Output.g = dot(yuv, Gcoeff);
+ Output.b = dot(yuv, Bcoeff);
+ Output.a = 1.0f;
+
+ return Output * input.color;
+ }
+
+*/
+#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1)
+static const DWORD D3D11_PixelShader_NV21_JPEG[] = {
+ 0x43425844, 0x9c41f579, 0xfd1019d8, 0x7c27e3ae, 0x52e3a5ff, 0x00000001,
+ 0x00000554, 0x00000006, 0x00000038, 0x000001bc, 0x00000354, 0x000003d0,
+ 0x000004ac, 0x00000520, 0x396e6f41, 0x0000017c, 0x0000017c, 0xffff0200,
+ 0x00000150, 0x0000002c, 0x002c0000, 0x002c0000, 0x002c0000, 0x00240002,
+ 0x002c0000, 0x00000000, 0x00010001, 0xffff0200, 0x05000051, 0xa00f0000,
+ 0x00000000, 0xbf008081, 0xbf008081, 0x3f800000, 0x05000051, 0xa00f0001,
+ 0x3f800000, 0x3fb374bc, 0x00000000, 0x00000000, 0x05000051, 0xa00f0002,
+ 0x3f800000, 0xbeb02de0, 0xbf36cf42, 0x00000000, 0x05000051, 0xa00f0003,
+ 0x3f800000, 0x3fe2d0e5, 0x00000000, 0x00000000, 0x0200001f, 0x80000000,
+ 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000,
+ 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x03000042, 0x800f0000,
+ 0xb0e40000, 0xa0e40800, 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40801,
+ 0x02000001, 0x80020000, 0x80550001, 0x02000001, 0x80040000, 0x80000001,
+ 0x03000002, 0x80070000, 0x80e40000, 0xa0e40000, 0x03000005, 0x80080000,
+ 0x80000000, 0xa0000001, 0x04000004, 0x80010001, 0x80aa0000, 0xa0550001,
+ 0x80ff0000, 0x03000008, 0x80020001, 0x80e40000, 0xa0e40002, 0x0400005a,
+ 0x80040001, 0x80e40000, 0xa0e40003, 0xa0aa0003, 0x02000001, 0x80080001,
+ 0xa0ff0000, 0x03000005, 0x800f0000, 0x80e40001, 0xb0e40001, 0x02000001,
+ 0x800f0800, 0x80e40000, 0x0000ffff, 0x52444853, 0x00000190, 0x00000040,
+ 0x00000064, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000,
+ 0x00000000, 0x00005555, 0x04001858, 0x00107000, 0x00000001, 0x00005555,
+ 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002,
+ 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x09000045,
+ 0x001000f2, 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000,
+ 0x00106000, 0x00000000, 0x09000045, 0x001000f2, 0x00000001, 0x00101046,
+ 0x00000001, 0x00107e46, 0x00000001, 0x00106000, 0x00000000, 0x05000036,
+ 0x00100062, 0x00000000, 0x00100456, 0x00000001, 0x0a000000, 0x00100072,
+ 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000000, 0xbf008081,
+ 0xbf008081, 0x00000000, 0x0a00000f, 0x00100012, 0x00000001, 0x00100086,
+ 0x00000000, 0x00004002, 0x3f800000, 0x3fb374bc, 0x00000000, 0x00000000,
+ 0x0a000010, 0x00100022, 0x00000001, 0x00100246, 0x00000000, 0x00004002,
+ 0x3f800000, 0xbeb02de0, 0xbf36cf42, 0x00000000, 0x0a00000f, 0x00100042,
+ 0x00000001, 0x00100046, 0x00000000, 0x00004002, 0x3f800000, 0x3fe2d0e5,
+ 0x00000000, 0x00000000, 0x05000036, 0x00100082, 0x00000001, 0x00004001,
+ 0x3f800000, 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001,
+ 0x00101e46, 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x0000000a,
+ 0x00000002, 0x00000000, 0x00000003, 0x00000005, 0x00000000, 0x00000000,
+ 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000d4,
+ 0x00000000, 0x00000000, 0x00000003, 0x0000001c, 0xffff0400, 0x00000100,
+ 0x000000a0, 0x0000007c, 0x00000003, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000001, 0x00000001, 0x00000087, 0x00000002, 0x00000005,
+ 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x00000093,
+ 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000001, 0x00000001,
+ 0x0000000d, 0x53656874, 0x6c706d61, 0x74007265, 0x65546568, 0x72757478,
+ 0x74005965, 0x65546568, 0x72757478, 0x00565565, 0x7263694d, 0x666f736f,
+ 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d,
+ 0x36207265, 0x392e332e, 0x2e303036, 0x38333631, 0xabab0034, 0x4e475349,
+ 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
+ 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
+ 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000, 0x00000000,
+ 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
+ 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x0000002c,
+ 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
+};
+#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3)
+static const DWORD D3D11_PixelShader_NV21_JPEG[] = {
+ 0x43425844, 0x5705ccc9, 0xeb57571d, 0x8ce556e0, 0x2adef743, 0x00000001,
+ 0x00000520, 0x00000006, 0x00000038, 0x00000188, 0x00000320, 0x0000039c,
+ 0x00000478, 0x000004ec, 0x396e6f41, 0x00000148, 0x00000148, 0xffff0200,
+ 0x0000011c, 0x0000002c, 0x002c0000, 0x002c0000, 0x002c0000, 0x00240002,
+ 0x002c0000, 0x00000000, 0x00010001, 0xffff0201, 0x05000051, 0xa00f0000,
+ 0x00000000, 0xbf008081, 0x3f800000, 0x3fb374bc, 0x05000051, 0xa00f0001,
+ 0x3f800000, 0xbeb02de0, 0xbf36cf42, 0x00000000, 0x05000051, 0xa00f0002,
+ 0x3f800000, 0x3fe2d0e5, 0x00000000, 0x00000000, 0x0200001f, 0x80000000,
+ 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000,
+ 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x03000042, 0x800f0000,
+ 0xb0e40000, 0xa0e40801, 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40800,
+ 0x02000001, 0x80060001, 0x80c40000, 0x03000002, 0x80070000, 0x80e40001,
+ 0xa0d40000, 0x0400005a, 0x80010001, 0x80e80000, 0xa0ee0000, 0xa0000000,
+ 0x03000008, 0x80020001, 0x80e40000, 0xa0e40001, 0x0400005a, 0x80040001,
+ 0x80e40000, 0xa0e40002, 0xa0aa0002, 0x02000001, 0x80080001, 0xa0aa0000,
+ 0x03000005, 0x800f0000, 0x80e40001, 0xb0e40001, 0x02000001, 0x800f0800,
+ 0x80e40000, 0x0000ffff, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
+ 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000,
+ 0x00005555, 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x03001062,
+ 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, 0x03000065,
+ 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x09000045, 0x001000f2,
+ 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
+ 0x00000000, 0x09000045, 0x001000f2, 0x00000001, 0x00101046, 0x00000001,
+ 0x00107e46, 0x00000001, 0x00106000, 0x00000000, 0x05000036, 0x00100062,
+ 0x00000000, 0x00100456, 0x00000001, 0x0a000000, 0x00100072, 0x00000000,
+ 0x00100246, 0x00000000, 0x00004002, 0x00000000, 0xbf008081, 0xbf008081,
+ 0x00000000, 0x0a00000f, 0x00100012, 0x00000001, 0x00100086, 0x00000000,
+ 0x00004002, 0x3f800000, 0x3fb374bc, 0x00000000, 0x00000000, 0x0a000010,
+ 0x00100022, 0x00000001, 0x00100246, 0x00000000, 0x00004002, 0x3f800000,
+ 0xbeb02de0, 0xbf36cf42, 0x00000000, 0x0a00000f, 0x00100042, 0x00000001,
+ 0x00100046, 0x00000000, 0x00004002, 0x3f800000, 0x3fe2d0e5, 0x00000000,
+ 0x00000000, 0x05000036, 0x00100082, 0x00000001, 0x00004001, 0x3f800000,
+ 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00101e46,
+ 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x0000000a, 0x00000002,
+ 0x00000000, 0x00000003, 0x00000005, 0x00000000, 0x00000000, 0x00000001,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000d4, 0x00000000,
+ 0x00000000, 0x00000003, 0x0000001c, 0xffff0400, 0x00000100, 0x000000a0,
+ 0x0000007c, 0x00000003, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000001, 0x00000001, 0x00000087, 0x00000002, 0x00000005, 0x00000004,
+ 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x00000093, 0x00000002,
+ 0x00000005, 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000d,
+ 0x53656874, 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x74005965,
+ 0x65546568, 0x72757478, 0x00565565, 0x7263694d, 0x666f736f, 0x52282074,
+ 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x36207265,
+ 0x392e332e, 0x2e303036, 0x38333631, 0xabab0034, 0x4e475349, 0x0000006c,
+ 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
+ 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000001, 0x00000303, 0x00000065, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x43584554,
+ 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x0000002c, 0x00000001,
+ 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
+ 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
+};
+#else
+#error "An appropriate 'yuv' pixel shader is not defined."
+#endif
+
+/* The yuv-rendering pixel shader:
+
+ --- D3D11_PixelShader_NV21_BT601.hlsl ---
+ Texture2D theTextureY : register(t0);
+ Texture2D theTextureUV : register(t1);
+ SamplerState theSampler : register(s0);
+
+ struct PixelShaderInput
+ {
+ float4 pos : SV_POSITION;
+ float2 tex : TEXCOORD0;
+ float4 color : COLOR0;
+ };
+
+ float4 main(PixelShaderInput input) : SV_TARGET
+ {
+ const float3 offset = {-0.0627451017, -0.501960814, -0.501960814};
+ const float3 Rcoeff = {1.1644, 0.0000, 1.5960};
+ const float3 Gcoeff = {1.1644, -0.3918, -0.8130};
+ const float3 Bcoeff = {1.1644, 2.0172, 0.0000};
+
+ float4 Output;
+
+ float3 yuv;
+ yuv.x = theTextureY.Sample(theSampler, input.tex).r;
+ yuv.yz = theTextureUV.Sample(theSampler, input.tex).gr;
+
+ yuv += offset;
+ Output.r = dot(yuv, Rcoeff);
+ Output.g = dot(yuv, Gcoeff);
+ Output.b = dot(yuv, Bcoeff);
+ Output.a = 1.0f;
+
+ return Output * input.color;
+ }
+
+*/
+#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1)
+static const DWORD D3D11_PixelShader_NV21_BT601[] = {
+ 0x43425844, 0x7fc6cfdc, 0xba87a4ff, 0xa72685a6, 0xa051b38c, 0x00000001,
+ 0x00000554, 0x00000006, 0x00000038, 0x000001bc, 0x00000354, 0x000003d0,
+ 0x000004ac, 0x00000520, 0x396e6f41, 0x0000017c, 0x0000017c, 0xffff0200,
+ 0x00000150, 0x0000002c, 0x002c0000, 0x002c0000, 0x002c0000, 0x00240002,
+ 0x002c0000, 0x00000000, 0x00010001, 0xffff0200, 0x05000051, 0xa00f0000,
+ 0xbd808081, 0xbf008081, 0xbf008081, 0x3f800000, 0x05000051, 0xa00f0001,
+ 0x3f950b0f, 0x3fcc49ba, 0x00000000, 0x00000000, 0x05000051, 0xa00f0002,
+ 0x3f950b0f, 0xbec89a02, 0xbf5020c5, 0x00000000, 0x05000051, 0xa00f0003,
+ 0x3f950b0f, 0x400119ce, 0x00000000, 0x00000000, 0x0200001f, 0x80000000,
+ 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000,
+ 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x03000042, 0x800f0000,
+ 0xb0e40000, 0xa0e40800, 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40801,
+ 0x02000001, 0x80020000, 0x80550001, 0x02000001, 0x80040000, 0x80000001,
+ 0x03000002, 0x80070000, 0x80e40000, 0xa0e40000, 0x03000005, 0x80080000,
+ 0x80000000, 0xa0000001, 0x04000004, 0x80010001, 0x80aa0000, 0xa0550001,
+ 0x80ff0000, 0x03000008, 0x80020001, 0x80e40000, 0xa0e40002, 0x0400005a,
+ 0x80040001, 0x80e40000, 0xa0e40003, 0xa0aa0003, 0x02000001, 0x80080001,
+ 0xa0ff0000, 0x03000005, 0x800f0000, 0x80e40001, 0xb0e40001, 0x02000001,
+ 0x800f0800, 0x80e40000, 0x0000ffff, 0x52444853, 0x00000190, 0x00000040,
+ 0x00000064, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000,
+ 0x00000000, 0x00005555, 0x04001858, 0x00107000, 0x00000001, 0x00005555,
+ 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002,
+ 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x09000045,
+ 0x001000f2, 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000,
+ 0x00106000, 0x00000000, 0x09000045, 0x001000f2, 0x00000001, 0x00101046,
+ 0x00000001, 0x00107e46, 0x00000001, 0x00106000, 0x00000000, 0x05000036,
+ 0x00100062, 0x00000000, 0x00100456, 0x00000001, 0x0a000000, 0x00100072,
+ 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0xbd808081, 0xbf008081,
+ 0xbf008081, 0x00000000, 0x0a00000f, 0x00100012, 0x00000001, 0x00100086,
+ 0x00000000, 0x00004002, 0x3f950b0f, 0x3fcc49ba, 0x00000000, 0x00000000,
+ 0x0a000010, 0x00100022, 0x00000001, 0x00100246, 0x00000000, 0x00004002,
+ 0x3f950b0f, 0xbec89a02, 0xbf5020c5, 0x00000000, 0x0a00000f, 0x00100042,
+ 0x00000001, 0x00100046, 0x00000000, 0x00004002, 0x3f950b0f, 0x400119ce,
+ 0x00000000, 0x00000000, 0x05000036, 0x00100082, 0x00000001, 0x00004001,
+ 0x3f800000, 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001,
+ 0x00101e46, 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x0000000a,
+ 0x00000002, 0x00000000, 0x00000003, 0x00000005, 0x00000000, 0x00000000,
+ 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000d4,
+ 0x00000000, 0x00000000, 0x00000003, 0x0000001c, 0xffff0400, 0x00000100,
+ 0x000000a0, 0x0000007c, 0x00000003, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000001, 0x00000001, 0x00000087, 0x00000002, 0x00000005,
+ 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x00000093,
+ 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000001, 0x00000001,
+ 0x0000000d, 0x53656874, 0x6c706d61, 0x74007265, 0x65546568, 0x72757478,
+ 0x74005965, 0x65546568, 0x72757478, 0x00565565, 0x7263694d, 0x666f736f,
+ 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d,
+ 0x36207265, 0x392e332e, 0x2e303036, 0x38333631, 0xabab0034, 0x4e475349,
+ 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
+ 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
+ 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000, 0x00000000,
+ 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
+ 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x0000002c,
+ 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
+};
+#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3)
+static const DWORD D3D11_PixelShader_NV21_BT601[] = {
+ 0x43425844, 0x1e92bca4, 0xfeb04e20, 0x3f4226b1, 0xc89c58ad, 0x00000001,
+ 0x00000520, 0x00000006, 0x00000038, 0x00000188, 0x00000320, 0x0000039c,
+ 0x00000478, 0x000004ec, 0x396e6f41, 0x00000148, 0x00000148, 0xffff0200,
+ 0x0000011c, 0x0000002c, 0x002c0000, 0x002c0000, 0x002c0000, 0x00240002,
+ 0x002c0000, 0x00000000, 0x00010001, 0xffff0201, 0x05000051, 0xa00f0000,
+ 0xbd808081, 0xbf008081, 0x3f800000, 0x00000000, 0x05000051, 0xa00f0001,
+ 0x3f950b0f, 0x3fcc49ba, 0x00000000, 0x400119ce, 0x05000051, 0xa00f0002,
+ 0x3f950b0f, 0xbec89a02, 0xbf5020c5, 0x00000000, 0x0200001f, 0x80000000,
+ 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000,
+ 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x03000042, 0x800f0000,
+ 0xb0e40000, 0xa0e40801, 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40800,
+ 0x02000001, 0x80060001, 0x80c40000, 0x03000002, 0x80070000, 0x80e40001,
+ 0xa0d40000, 0x0400005a, 0x80010001, 0x80e80000, 0xa0e40001, 0xa0aa0001,
+ 0x03000008, 0x80020001, 0x80e40000, 0xa0e40002, 0x0400005a, 0x80040001,
+ 0x80e40000, 0xa0ec0001, 0xa0aa0001, 0x02000001, 0x80080001, 0xa0aa0000,
+ 0x03000005, 0x800f0000, 0x80e40001, 0xb0e40001, 0x02000001, 0x800f0800,
+ 0x80e40000, 0x0000ffff, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
+ 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000,
+ 0x00005555, 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x03001062,
+ 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, 0x03000065,
+ 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x09000045, 0x001000f2,
+ 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
+ 0x00000000, 0x09000045, 0x001000f2, 0x00000001, 0x00101046, 0x00000001,
+ 0x00107e46, 0x00000001, 0x00106000, 0x00000000, 0x05000036, 0x00100062,
+ 0x00000000, 0x00100456, 0x00000001, 0x0a000000, 0x00100072, 0x00000000,
+ 0x00100246, 0x00000000, 0x00004002, 0xbd808081, 0xbf008081, 0xbf008081,
+ 0x00000000, 0x0a00000f, 0x00100012, 0x00000001, 0x00100086, 0x00000000,
+ 0x00004002, 0x3f950b0f, 0x3fcc49ba, 0x00000000, 0x00000000, 0x0a000010,
+ 0x00100022, 0x00000001, 0x00100246, 0x00000000, 0x00004002, 0x3f950b0f,
+ 0xbec89a02, 0xbf5020c5, 0x00000000, 0x0a00000f, 0x00100042, 0x00000001,
+ 0x00100046, 0x00000000, 0x00004002, 0x3f950b0f, 0x400119ce, 0x00000000,
+ 0x00000000, 0x05000036, 0x00100082, 0x00000001, 0x00004001, 0x3f800000,
+ 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00101e46,
+ 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x0000000a, 0x00000002,
+ 0x00000000, 0x00000003, 0x00000005, 0x00000000, 0x00000000, 0x00000001,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000d4, 0x00000000,
+ 0x00000000, 0x00000003, 0x0000001c, 0xffff0400, 0x00000100, 0x000000a0,
+ 0x0000007c, 0x00000003, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000001, 0x00000001, 0x00000087, 0x00000002, 0x00000005, 0x00000004,
+ 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x00000093, 0x00000002,
+ 0x00000005, 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000d,
+ 0x53656874, 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x74005965,
+ 0x65546568, 0x72757478, 0x00565565, 0x7263694d, 0x666f736f, 0x52282074,
+ 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x36207265,
+ 0x392e332e, 0x2e303036, 0x38333631, 0xabab0034, 0x4e475349, 0x0000006c,
+ 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
+ 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000001, 0x00000303, 0x00000065, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x43584554,
+ 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x0000002c, 0x00000001,
+ 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
+ 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
+};
+#else
+#error "An appropriate 'yuv' pixel shader is not defined."
+#endif
+
+/* The yuv-rendering pixel shader:
+
+ --- D3D11_PixelShader_NV21_BT709.hlsl ---
+ Texture2D theTextureY : register(t0);
+ Texture2D theTextureUV : register(t1);
+ SamplerState theSampler : register(s0);
+
+ struct PixelShaderInput
+ {
+ float4 pos : SV_POSITION;
+ float2 tex : TEXCOORD0;
+ float4 color : COLOR0;
+ };
+
+ float4 main(PixelShaderInput input) : SV_TARGET
+ {
+ const float3 offset = {-0.0627451017, -0.501960814, -0.501960814};
+ const float3 Rcoeff = {1.1644, 0.0000, 1.7927};
+ const float3 Gcoeff = {1.1644, -0.2132, -0.5329};
+ const float3 Bcoeff = {1.1644, 2.1124, 0.0000};
+
+ float4 Output;
+
+ float3 yuv;
+ yuv.x = theTextureY.Sample(theSampler, input.tex).r;
+ yuv.yz = theTextureUV.Sample(theSampler, input.tex).gr;
+
+ yuv += offset;
+ Output.r = dot(yuv, Rcoeff);
+ Output.g = dot(yuv, Gcoeff);
+ Output.b = dot(yuv, Bcoeff);
+ Output.a = 1.0f;
+
+ return Output * input.color;
+ }
+
+*/
+#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1)
+static const DWORD D3D11_PixelShader_NV21_BT709[] = {
+ 0x43425844, 0x754ba6c4, 0xe321a747, 0x23680787, 0x6bb1bdcc, 0x00000001,
+ 0x00000554, 0x00000006, 0x00000038, 0x000001bc, 0x00000354, 0x000003d0,
+ 0x000004ac, 0x00000520, 0x396e6f41, 0x0000017c, 0x0000017c, 0xffff0200,
+ 0x00000150, 0x0000002c, 0x002c0000, 0x002c0000, 0x002c0000, 0x00240002,
+ 0x002c0000, 0x00000000, 0x00010001, 0xffff0200, 0x05000051, 0xa00f0000,
+ 0xbd808081, 0xbf008081, 0xbf008081, 0x3f800000, 0x05000051, 0xa00f0001,
+ 0x3f950b0f, 0x3fe57732, 0x00000000, 0x00000000, 0x05000051, 0xa00f0002,
+ 0x3f950b0f, 0xbe5a511a, 0xbf086c22, 0x00000000, 0x05000051, 0xa00f0003,
+ 0x3f950b0f, 0x40073190, 0x00000000, 0x00000000, 0x0200001f, 0x80000000,
+ 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000,
+ 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x03000042, 0x800f0000,
+ 0xb0e40000, 0xa0e40800, 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40801,
+ 0x02000001, 0x80020000, 0x80550001, 0x02000001, 0x80040000, 0x80000001,
+ 0x03000002, 0x80070000, 0x80e40000, 0xa0e40000, 0x03000005, 0x80080000,
+ 0x80000000, 0xa0000001, 0x04000004, 0x80010001, 0x80aa0000, 0xa0550001,
+ 0x80ff0000, 0x03000008, 0x80020001, 0x80e40000, 0xa0e40002, 0x0400005a,
+ 0x80040001, 0x80e40000, 0xa0e40003, 0xa0aa0003, 0x02000001, 0x80080001,
+ 0xa0ff0000, 0x03000005, 0x800f0000, 0x80e40001, 0xb0e40001, 0x02000001,
+ 0x800f0800, 0x80e40000, 0x0000ffff, 0x52444853, 0x00000190, 0x00000040,
+ 0x00000064, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000,
+ 0x00000000, 0x00005555, 0x04001858, 0x00107000, 0x00000001, 0x00005555,
+ 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002,
+ 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x09000045,
+ 0x001000f2, 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000,
+ 0x00106000, 0x00000000, 0x09000045, 0x001000f2, 0x00000001, 0x00101046,
+ 0x00000001, 0x00107e46, 0x00000001, 0x00106000, 0x00000000, 0x05000036,
+ 0x00100062, 0x00000000, 0x00100456, 0x00000001, 0x0a000000, 0x00100072,
+ 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0xbd808081, 0xbf008081,
+ 0xbf008081, 0x00000000, 0x0a00000f, 0x00100012, 0x00000001, 0x00100086,
+ 0x00000000, 0x00004002, 0x3f950b0f, 0x3fe57732, 0x00000000, 0x00000000,
+ 0x0a000010, 0x00100022, 0x00000001, 0x00100246, 0x00000000, 0x00004002,
+ 0x3f950b0f, 0xbe5a511a, 0xbf086c22, 0x00000000, 0x0a00000f, 0x00100042,
+ 0x00000001, 0x00100046, 0x00000000, 0x00004002, 0x3f950b0f, 0x40073190,
+ 0x00000000, 0x00000000, 0x05000036, 0x00100082, 0x00000001, 0x00004001,
+ 0x3f800000, 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001,
+ 0x00101e46, 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x0000000a,
+ 0x00000002, 0x00000000, 0x00000003, 0x00000005, 0x00000000, 0x00000000,
+ 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000d4,
+ 0x00000000, 0x00000000, 0x00000003, 0x0000001c, 0xffff0400, 0x00000100,
+ 0x000000a0, 0x0000007c, 0x00000003, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000001, 0x00000001, 0x00000087, 0x00000002, 0x00000005,
+ 0x00000004, 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x00000093,
+ 0x00000002, 0x00000005, 0x00000004, 0xffffffff, 0x00000001, 0x00000001,
+ 0x0000000d, 0x53656874, 0x6c706d61, 0x74007265, 0x65546568, 0x72757478,
+ 0x74005965, 0x65546568, 0x72757478, 0x00565565, 0x7263694d, 0x666f736f,
+ 0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d,
+ 0x36207265, 0x392e332e, 0x2e303036, 0x38333631, 0xabab0034, 0x4e475349,
+ 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
+ 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
+ 0x00000003, 0x00000001, 0x00000303, 0x00000065, 0x00000000, 0x00000000,
+ 0x00000003, 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
+ 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x0000002c,
+ 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
+};
+#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3)
+static const DWORD D3D11_PixelShader_NV21_BT709[] = {
+ 0x43425844, 0xb6219b20, 0xb71bbcf7, 0xf361cc45, 0xc4d5f5be, 0x00000001,
+ 0x00000520, 0x00000006, 0x00000038, 0x00000188, 0x00000320, 0x0000039c,
+ 0x00000478, 0x000004ec, 0x396e6f41, 0x00000148, 0x00000148, 0xffff0200,
+ 0x0000011c, 0x0000002c, 0x002c0000, 0x002c0000, 0x002c0000, 0x00240002,
+ 0x002c0000, 0x00000000, 0x00010001, 0xffff0201, 0x05000051, 0xa00f0000,
+ 0xbd808081, 0xbf008081, 0x3f800000, 0x00000000, 0x05000051, 0xa00f0001,
+ 0x3f950b0f, 0x3fe57732, 0x00000000, 0x40073190, 0x05000051, 0xa00f0002,
+ 0x3f950b0f, 0xbe5a511a, 0xbf086c22, 0x00000000, 0x0200001f, 0x80000000,
+ 0xb0030000, 0x0200001f, 0x80000000, 0xb00f0001, 0x0200001f, 0x90000000,
+ 0xa00f0800, 0x0200001f, 0x90000000, 0xa00f0801, 0x03000042, 0x800f0000,
+ 0xb0e40000, 0xa0e40801, 0x03000042, 0x800f0001, 0xb0e40000, 0xa0e40800,
+ 0x02000001, 0x80060001, 0x80c40000, 0x03000002, 0x80070000, 0x80e40001,
+ 0xa0d40000, 0x0400005a, 0x80010001, 0x80e80000, 0xa0e40001, 0xa0aa0001,
+ 0x03000008, 0x80020001, 0x80e40000, 0xa0e40002, 0x0400005a, 0x80040001,
+ 0x80e40000, 0xa0ec0001, 0xa0aa0001, 0x02000001, 0x80080001, 0xa0aa0000,
+ 0x03000005, 0x800f0000, 0x80e40001, 0xb0e40001, 0x02000001, 0x800f0800,
+ 0x80e40000, 0x0000ffff, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
+ 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000,
+ 0x00005555, 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x03001062,
+ 0x00101032, 0x00000001, 0x03001062, 0x001010f2, 0x00000002, 0x03000065,
+ 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x09000045, 0x001000f2,
+ 0x00000000, 0x00101046, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
+ 0x00000000, 0x09000045, 0x001000f2, 0x00000001, 0x00101046, 0x00000001,
+ 0x00107e46, 0x00000001, 0x00106000, 0x00000000, 0x05000036, 0x00100062,
+ 0x00000000, 0x00100456, 0x00000001, 0x0a000000, 0x00100072, 0x00000000,
+ 0x00100246, 0x00000000, 0x00004002, 0xbd808081, 0xbf008081, 0xbf008081,
+ 0x00000000, 0x0a00000f, 0x00100012, 0x00000001, 0x00100086, 0x00000000,
+ 0x00004002, 0x3f950b0f, 0x3fe57732, 0x00000000, 0x00000000, 0x0a000010,
+ 0x00100022, 0x00000001, 0x00100246, 0x00000000, 0x00004002, 0x3f950b0f,
+ 0xbe5a511a, 0xbf086c22, 0x00000000, 0x0a00000f, 0x00100042, 0x00000001,
+ 0x00100046, 0x00000000, 0x00004002, 0x3f950b0f, 0x40073190, 0x00000000,
+ 0x00000000, 0x05000036, 0x00100082, 0x00000001, 0x00004001, 0x3f800000,
+ 0x07000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00101e46,
+ 0x00000002, 0x0100003e, 0x54415453, 0x00000074, 0x0000000a, 0x00000002,
+ 0x00000000, 0x00000003, 0x00000005, 0x00000000, 0x00000000, 0x00000001,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000002,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x46454452, 0x000000d4, 0x00000000,
+ 0x00000000, 0x00000003, 0x0000001c, 0xffff0400, 0x00000100, 0x000000a0,
+ 0x0000007c, 0x00000003, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000001, 0x00000001, 0x00000087, 0x00000002, 0x00000005, 0x00000004,
+ 0xffffffff, 0x00000000, 0x00000001, 0x0000000d, 0x00000093, 0x00000002,
+ 0x00000005, 0x00000004, 0xffffffff, 0x00000001, 0x00000001, 0x0000000d,
+ 0x53656874, 0x6c706d61, 0x74007265, 0x65546568, 0x72757478, 0x74005965,
+ 0x65546568, 0x72757478, 0x00565565, 0x7263694d, 0x666f736f, 0x52282074,
+ 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x36207265,
+ 0x392e332e, 0x2e303036, 0x38333631, 0xabab0034, 0x4e475349, 0x0000006c,
+ 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
+ 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000001, 0x00000303, 0x00000065, 0x00000000, 0x00000000, 0x00000003,
+ 0x00000002, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x43584554,
+ 0x44524f4f, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x0000002c, 0x00000001,
+ 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
+ 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054
+};
+#else
+#error "An appropriate 'yuv' pixel shader is not defined."
+#endif
+
+/* The sole vertex shader:
+
+ --- D3D11_VertexShader.hlsl ---
+ #pragma pack_matrix( row_major )
+
+ cbuffer VertexShaderConstants : register(b0)
+ {
+ matrix model;
+ matrix projectionAndView;
+ };
+
+ struct VertexShaderInput
+ {
+ float3 pos : POSITION;
+ float2 tex : TEXCOORD0;
+ float4 color : COLOR0;
+ };
+
+ struct VertexShaderOutput
+ {
+ float4 pos : SV_POSITION;
+ float2 tex : TEXCOORD0;
+ float4 color : COLOR0;
+ };
+
+ VertexShaderOutput main(VertexShaderInput input)
+ {
+ VertexShaderOutput output;
+ float4 pos = float4(input.pos, 1.0f);
+
+ // Transform the vertex position into projected space.
+ pos = mul(pos, model);
+ pos = mul(pos, projectionAndView);
+ output.pos = pos;
+
+ // Pass through texture coordinates and color values without transformation
+ output.tex = input.tex;
+ output.color = input.color;
+
+ return output;
+ }
+*/
+#if defined(D3D11_USE_SHADER_MODEL_4_0_level_9_1)
+static const DWORD D3D11_VertexShader[] = {
+ 0x43425844, 0x62dfae5f, 0x3e8bd8df, 0x9ec97127, 0x5044eefb, 0x00000001,
+ 0x00000598, 0x00000006, 0x00000038, 0x0000016c, 0x00000334, 0x000003b0,
+ 0x000004b4, 0x00000524, 0x396e6f41, 0x0000012c, 0x0000012c, 0xfffe0200,
+ 0x000000f8, 0x00000034, 0x00240001, 0x00300000, 0x00300000, 0x00240000,
+ 0x00300001, 0x00000000, 0x00010008, 0x00000000, 0x00000000, 0xfffe0200,
+ 0x0200001f, 0x80000005, 0x900f0000, 0x0200001f, 0x80010005, 0x900f0001,
+ 0x0200001f, 0x80020005, 0x900f0002, 0x03000005, 0x800f0000, 0x90550000,
+ 0xa0e40002, 0x04000004, 0x800f0000, 0x90000000, 0xa0e40001, 0x80e40000,
+ 0x04000004, 0x800f0000, 0x90aa0000, 0xa0e40003, 0x80e40000, 0x03000002,
+ 0x800f0000, 0x80e40000, 0xa0e40004, 0x03000005, 0x800f0001, 0x80550000,
+ 0xa0e40006, 0x04000004, 0x800f0001, 0x80000000, 0xa0e40005, 0x80e40001,
+ 0x04000004, 0x800f0001, 0x80aa0000, 0xa0e40007, 0x80e40001, 0x04000004,
+ 0x800f0000, 0x80ff0000, 0xa0e40008, 0x80e40001, 0x04000004, 0xc0030000,
+ 0x80ff0000, 0xa0e40000, 0x80e40000, 0x02000001, 0xc00c0000, 0x80e40000,
+ 0x02000001, 0xe0030000, 0x90e40001, 0x02000001, 0xe00f0001, 0x90e40002,
+ 0x0000ffff, 0x52444853, 0x000001c0, 0x00010040, 0x00000070, 0x04000059,
+ 0x00208e46, 0x00000000, 0x00000008, 0x0300005f, 0x00101072, 0x00000000,
+ 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002,
+ 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032,
+ 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000002,
+ 0x08000038, 0x001000f2, 0x00000000, 0x00101556, 0x00000000, 0x00208e46,
+ 0x00000000, 0x00000001, 0x0a000032, 0x001000f2, 0x00000000, 0x00101006,
+ 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
+ 0x0a000032, 0x001000f2, 0x00000000, 0x00101aa6, 0x00000000, 0x00208e46,
+ 0x00000000, 0x00000002, 0x00100e46, 0x00000000, 0x08000000, 0x001000f2,
+ 0x00000000, 0x00100e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
+ 0x08000038, 0x001000f2, 0x00000001, 0x00100556, 0x00000000, 0x00208e46,
+ 0x00000000, 0x00000005, 0x0a000032, 0x001000f2, 0x00000001, 0x00100006,
+ 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x00100e46, 0x00000001,
+ 0x0a000032, 0x001000f2, 0x00000001, 0x00100aa6, 0x00000000, 0x00208e46,
+ 0x00000000, 0x00000006, 0x00100e46, 0x00000001, 0x0a000032, 0x001020f2,
+ 0x00000000, 0x00100ff6, 0x00000000, 0x00208e46, 0x00000000, 0x00000007,
+ 0x00100e46, 0x00000001, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
+ 0x00000001, 0x05000036, 0x001020f2, 0x00000002, 0x00101e46, 0x00000002,
+ 0x0100003e, 0x54415453, 0x00000074, 0x0000000b, 0x00000002, 0x00000000,
+ 0x00000006, 0x00000003, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x46454452, 0x000000fc, 0x00000001, 0x00000054,
+ 0x00000001, 0x0000001c, 0xfffe0400, 0x00000100, 0x000000c6, 0x0000003c,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
+ 0x00000001, 0x74726556, 0x68537865, 0x72656461, 0x736e6f43, 0x746e6174,
+ 0xabab0073, 0x0000003c, 0x00000002, 0x0000006c, 0x00000080, 0x00000000,
+ 0x00000000, 0x0000009c, 0x00000000, 0x00000040, 0x00000002, 0x000000a4,
+ 0x00000000, 0x000000b4, 0x00000040, 0x00000040, 0x00000002, 0x000000a4,
+ 0x00000000, 0x65646f6d, 0xabab006c, 0x00030002, 0x00040004, 0x00000000,
+ 0x00000000, 0x6a6f7270, 0x69746365, 0x6e416e6f, 0x65695664, 0x694d0077,
+ 0x736f7263, 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564,
+ 0x706d6f43, 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336,
+ 0xababab00, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
+ 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000707, 0x00000059,
+ 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000062,
+ 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x49534f50,
+ 0x4e4f4954, 0x58455400, 0x524f4f43, 0x4f430044, 0x00524f4c, 0x4e47534f,
+ 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
+ 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
+ 0x00000003, 0x00000001, 0x00000c03, 0x00000065, 0x00000000, 0x00000000,
+ 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
+ 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f
+};
+#elif defined(D3D11_USE_SHADER_MODEL_4_0_level_9_3)
+static const DWORD D3D11_VertexShader[] = {
+ 0x43425844, 0x01a24e41, 0x696af551, 0x4b2a87d1, 0x82ea03f6, 0x00000001,
+ 0x00000598, 0x00000006, 0x00000038, 0x0000016c, 0x00000334, 0x000003b0,
+ 0x000004b4, 0x00000524, 0x396e6f41, 0x0000012c, 0x0000012c, 0xfffe0200,
+ 0x000000f8, 0x00000034, 0x00240001, 0x00300000, 0x00300000, 0x00240000,
+ 0x00300001, 0x00000000, 0x00010008, 0x00000000, 0x00000000, 0xfffe0201,
+ 0x0200001f, 0x80000005, 0x900f0000, 0x0200001f, 0x80010005, 0x900f0001,
+ 0x0200001f, 0x80020005, 0x900f0002, 0x03000005, 0x800f0000, 0x90550000,
+ 0xa0e40002, 0x04000004, 0x800f0000, 0x90000000, 0xa0e40001, 0x80e40000,
+ 0x04000004, 0x800f0000, 0x90aa0000, 0xa0e40003, 0x80e40000, 0x03000002,
+ 0x800f0000, 0x80e40000, 0xa0e40004, 0x03000005, 0x800f0001, 0x80550000,
+ 0xa0e40006, 0x04000004, 0x800f0001, 0x80000000, 0xa0e40005, 0x80e40001,
+ 0x04000004, 0x800f0001, 0x80aa0000, 0xa0e40007, 0x80e40001, 0x04000004,
+ 0x800f0000, 0x80ff0000, 0xa0e40008, 0x80e40001, 0x04000004, 0xc0030000,
+ 0x80ff0000, 0xa0e40000, 0x80e40000, 0x02000001, 0xc00c0000, 0x80e40000,
+ 0x02000001, 0xe0030000, 0x90e40001, 0x02000001, 0xe00f0001, 0x90e40002,
+ 0x0000ffff, 0x52444853, 0x000001c0, 0x00010040, 0x00000070, 0x04000059,
+ 0x00208e46, 0x00000000, 0x00000008, 0x0300005f, 0x00101072, 0x00000000,
+ 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002,
+ 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032,
+ 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000002,
+ 0x08000038, 0x001000f2, 0x00000000, 0x00101556, 0x00000000, 0x00208e46,
+ 0x00000000, 0x00000001, 0x0a000032, 0x001000f2, 0x00000000, 0x00101006,
+ 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
+ 0x0a000032, 0x001000f2, 0x00000000, 0x00101aa6, 0x00000000, 0x00208e46,
+ 0x00000000, 0x00000002, 0x00100e46, 0x00000000, 0x08000000, 0x001000f2,
+ 0x00000000, 0x00100e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
+ 0x08000038, 0x001000f2, 0x00000001, 0x00100556, 0x00000000, 0x00208e46,
+ 0x00000000, 0x00000005, 0x0a000032, 0x001000f2, 0x00000001, 0x00100006,
+ 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x00100e46, 0x00000001,
+ 0x0a000032, 0x001000f2, 0x00000001, 0x00100aa6, 0x00000000, 0x00208e46,
+ 0x00000000, 0x00000006, 0x00100e46, 0x00000001, 0x0a000032, 0x001020f2,
+ 0x00000000, 0x00100ff6, 0x00000000, 0x00208e46, 0x00000000, 0x00000007,
+ 0x00100e46, 0x00000001, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
+ 0x00000001, 0x05000036, 0x001020f2, 0x00000002, 0x00101e46, 0x00000002,
+ 0x0100003e, 0x54415453, 0x00000074, 0x0000000b, 0x00000002, 0x00000000,
+ 0x00000006, 0x00000003, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x46454452, 0x000000fc, 0x00000001, 0x00000054,
+ 0x00000001, 0x0000001c, 0xfffe0400, 0x00000100, 0x000000c6, 0x0000003c,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
+ 0x00000001, 0x74726556, 0x68537865, 0x72656461, 0x736e6f43, 0x746e6174,
+ 0xabab0073, 0x0000003c, 0x00000002, 0x0000006c, 0x00000080, 0x00000000,
+ 0x00000000, 0x0000009c, 0x00000000, 0x00000040, 0x00000002, 0x000000a4,
+ 0x00000000, 0x000000b4, 0x00000040, 0x00000040, 0x00000002, 0x000000a4,
+ 0x00000000, 0x65646f6d, 0xabab006c, 0x00030002, 0x00040004, 0x00000000,
+ 0x00000000, 0x6a6f7270, 0x69746365, 0x6e416e6f, 0x65695664, 0x694d0077,
+ 0x736f7263, 0x2074666f, 0x20295228, 0x4c534c48, 0x61685320, 0x20726564,
+ 0x706d6f43, 0x72656c69, 0x332e3920, 0x32392e30, 0x312e3030, 0x34383336,
+ 0xababab00, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
+ 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000707, 0x00000059,
+ 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000303, 0x00000062,
+ 0x00000000, 0x00000000, 0x00000003, 0x00000002, 0x00000f0f, 0x49534f50,
+ 0x4e4f4954, 0x58455400, 0x524f4f43, 0x4f430044, 0x00524f4c, 0x4e47534f,
+ 0x0000006c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001,
+ 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
+ 0x00000003, 0x00000001, 0x00000c03, 0x00000065, 0x00000000, 0x00000000,
+ 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
+ 0x43584554, 0x44524f4f, 0x4c4f4300, 0xab00524f
+};
+#else
+#error "An appropriate vertex shader is not defined."
+#endif
+
+static struct
+{
+ const void *shader_data;
+ SIZE_T shader_size;
+} D3D11_shaders[] = {
+ { D3D11_PixelShader_Colors, sizeof(D3D11_PixelShader_Colors) },
+ { D3D11_PixelShader_Textures, sizeof(D3D11_PixelShader_Textures) },
+ { D3D11_PixelShader_YUV_JPEG, sizeof(D3D11_PixelShader_YUV_JPEG) },
+ { D3D11_PixelShader_YUV_BT601, sizeof(D3D11_PixelShader_YUV_BT601) },
+ { D3D11_PixelShader_YUV_BT709, sizeof(D3D11_PixelShader_YUV_BT709) },
+ { D3D11_PixelShader_NV12_JPEG, sizeof(D3D11_PixelShader_NV12_JPEG) },
+ { D3D11_PixelShader_NV12_BT601, sizeof(D3D11_PixelShader_NV12_BT601) },
+ { D3D11_PixelShader_NV12_BT709, sizeof(D3D11_PixelShader_NV12_BT709) },
+ { D3D11_PixelShader_NV21_JPEG, sizeof(D3D11_PixelShader_NV21_JPEG) },
+ { D3D11_PixelShader_NV21_BT601, sizeof(D3D11_PixelShader_NV21_BT601) },
+ { D3D11_PixelShader_NV21_BT709, sizeof(D3D11_PixelShader_NV21_BT709) },
+};
+
+int D3D11_CreateVertexShader(ID3D11Device1 *d3dDevice, ID3D11VertexShader **vertexShader, ID3D11InputLayout **inputLayout)
+{
+ /* Declare how the input layout for SDL's vertex shader will be setup: */
+ const D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
+ {
+ { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
+ { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
+ { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 },
+ };
+ HRESULT result;
+
+ /* Load in SDL's one and only vertex shader: */
+ result = ID3D11Device_CreateVertexShader(d3dDevice,
+ D3D11_VertexShader,
+ sizeof(D3D11_VertexShader),
+ NULL,
+ vertexShader
+ );
+ if (FAILED(result)) {
+ return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateVertexShader"), result);
+ }
+
+ /* Create an input layout for SDL's vertex shader: */
+ result = ID3D11Device_CreateInputLayout(d3dDevice,
+ vertexDesc,
+ ARRAYSIZE(vertexDesc),
+ D3D11_VertexShader,
+ sizeof(D3D11_VertexShader),
+ inputLayout
+ );
+ if (FAILED(result)) {
+ return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateInputLayout"), result);
+ }
+ return 0;
+}
+
+int D3D11_CreatePixelShader(ID3D11Device1 *d3dDevice, D3D11_Shader shader, ID3D11PixelShader **pixelShader)
+{
+ HRESULT result;
+
+ result = ID3D11Device_CreatePixelShader(d3dDevice,
+ D3D11_shaders[shader].shader_data,
+ D3D11_shaders[shader].shader_size,
+ NULL,
+ pixelShader
+ );
+ if (FAILED(result)) {
+ return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreatePixelShader"), result);
+ }
+ return 0;
+}
+
+#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/direct3d11/SDL_shaders_d3d11.h b/src/3rdparty/SDL2/src/render/direct3d11/SDL_shaders_d3d11.h
new file mode 100644
index 0000000..b28b572
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/direct3d11/SDL_shaders_d3d11.h
@@ -0,0 +1,43 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+/* D3D11 shader implementation */
+
+typedef enum {
+ SHADER_SOLID,
+ SHADER_RGB,
+ SHADER_YUV_JPEG,
+ SHADER_YUV_BT601,
+ SHADER_YUV_BT709,
+ SHADER_NV12_JPEG,
+ SHADER_NV12_BT601,
+ SHADER_NV12_BT709,
+ SHADER_NV21_JPEG,
+ SHADER_NV21_BT601,
+ SHADER_NV21_BT709,
+ NUM_SHADERS
+} D3D11_Shader;
+
+extern int D3D11_CreateVertexShader(ID3D11Device1 *d3dDevice, ID3D11VertexShader **vertexShader, ID3D11InputLayout **inputLayout);
+extern int D3D11_CreatePixelShader(ID3D11Device1 *d3dDevice, D3D11_Shader shader, ID3D11PixelShader **pixelShader);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/metal/SDL_render_metal.m b/src/3rdparty/SDL2/src/render/metal/SDL_render_metal.m
new file mode 100644
index 0000000..f7af72d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/metal/SDL_render_metal.m
@@ -0,0 +1,1429 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_RENDER_METAL && !SDL_RENDER_DISABLED
+
+#include "SDL_hints.h"
+#include "SDL_log.h"
+#include "SDL_assert.h"
+#include "SDL_syswm.h"
+#include "../SDL_sysrender.h"
+
+#ifdef __MACOSX__
+#include "../../video/cocoa/SDL_cocoametalview.h"
+#else
+#include "../../video/uikit/SDL_uikitmetalview.h"
+#endif
+#include <Availability.h>
+#import <Metal/Metal.h>
+#import <QuartzCore/CAMetalLayer.h>
+
+/* Regenerate these with build-metal-shaders.sh */
+#ifdef __MACOSX__
+#include "SDL_shaders_metal_osx.h"
+#else
+#include "SDL_shaders_metal_ios.h"
+#endif
+
+/* Apple Metal renderer implementation */
+
+static SDL_Renderer *METAL_CreateRenderer(SDL_Window * window, Uint32 flags);
+static void METAL_WindowEvent(SDL_Renderer * renderer,
+ const SDL_WindowEvent *event);
+static int METAL_GetOutputSize(SDL_Renderer * renderer, int *w, int *h);
+static SDL_bool METAL_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode);
+static int METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+static int METAL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, const void *pixels,
+ int pitch);
+static int METAL_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch);
+static int METAL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, void **pixels, int *pitch);
+static void METAL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+static int METAL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
+static int METAL_UpdateViewport(SDL_Renderer * renderer);
+static int METAL_UpdateClipRect(SDL_Renderer * renderer);
+static int METAL_RenderClear(SDL_Renderer * renderer);
+static int METAL_RenderDrawPoints(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count);
+static int METAL_RenderDrawLines(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count);
+static int METAL_RenderFillRects(SDL_Renderer * renderer,
+ const SDL_FRect * rects, int count);
+static int METAL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect);
+static int METAL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect,
+ const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip);
+static int METAL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 pixel_format, void * pixels, int pitch);
+static void METAL_RenderPresent(SDL_Renderer * renderer);
+static void METAL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+static void METAL_DestroyRenderer(SDL_Renderer * renderer);
+static void *METAL_GetMetalLayer(SDL_Renderer * renderer);
+static void *METAL_GetMetalCommandEncoder(SDL_Renderer * renderer);
+
+SDL_RenderDriver METAL_RenderDriver = {
+ METAL_CreateRenderer,
+ {
+ "metal",
+ (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
+ 6,
+ {
+ SDL_PIXELFORMAT_ARGB8888,
+ SDL_PIXELFORMAT_ABGR8888,
+ SDL_PIXELFORMAT_YV12,
+ SDL_PIXELFORMAT_IYUV,
+ SDL_PIXELFORMAT_NV12,
+ SDL_PIXELFORMAT_NV21
+ },
+ 0, 0,
+ }
+};
+
+/* macOS requires constants in a buffer to have a 256 byte alignment. */
+#ifdef __MACOSX__
+#define CONSTANT_ALIGN 256
+#else
+#define CONSTANT_ALIGN 4
+#endif
+
+#define ALIGN_CONSTANTS(size) ((size + CONSTANT_ALIGN - 1) & (~(CONSTANT_ALIGN - 1)))
+
+static const size_t CONSTANTS_OFFSET_IDENTITY = 0;
+static const size_t CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM = ALIGN_CONSTANTS(CONSTANTS_OFFSET_IDENTITY + sizeof(float) * 16);
+static const size_t CONSTANTS_OFFSET_DECODE_JPEG = ALIGN_CONSTANTS(CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM + sizeof(float) * 16);
+static const size_t CONSTANTS_OFFSET_DECODE_BT601 = ALIGN_CONSTANTS(CONSTANTS_OFFSET_DECODE_JPEG + sizeof(float) * 4 * 4);
+static const size_t CONSTANTS_OFFSET_DECODE_BT709 = ALIGN_CONSTANTS(CONSTANTS_OFFSET_DECODE_BT601 + sizeof(float) * 4 * 4);
+static const size_t CONSTANTS_OFFSET_CLEAR_VERTS = ALIGN_CONSTANTS(CONSTANTS_OFFSET_DECODE_BT709 + sizeof(float) * 4 * 4);
+static const size_t CONSTANTS_LENGTH = CONSTANTS_OFFSET_CLEAR_VERTS + sizeof(float) * 6;
+
+typedef enum SDL_MetalVertexFunction
+{
+ SDL_METAL_VERTEX_SOLID,
+ SDL_METAL_VERTEX_COPY,
+} SDL_MetalVertexFunction;
+
+typedef enum SDL_MetalFragmentFunction
+{
+ SDL_METAL_FRAGMENT_SOLID = 0,
+ SDL_METAL_FRAGMENT_COPY,
+ SDL_METAL_FRAGMENT_YUV,
+ SDL_METAL_FRAGMENT_NV12,
+ SDL_METAL_FRAGMENT_NV21,
+ SDL_METAL_FRAGMENT_COUNT,
+} SDL_MetalFragmentFunction;
+
+typedef struct METAL_PipelineState
+{
+ SDL_BlendMode blendMode;
+ void *pipe;
+} METAL_PipelineState;
+
+typedef struct METAL_PipelineCache
+{
+ METAL_PipelineState *states;
+ int count;
+ SDL_MetalVertexFunction vertexFunction;
+ SDL_MetalFragmentFunction fragmentFunction;
+ MTLPixelFormat renderTargetFormat;
+ const char *label;
+} METAL_PipelineCache;
+
+/* Each shader combination used by drawing functions has a separate pipeline
+ * cache, and we have a separate list of caches for each render target pixel
+ * format. This is more efficient than iterating over a global cache to find
+ * the pipeline based on the specified shader combination and RT pixel format,
+ * since we know what the RT pixel format is when we set the render target, and
+ * we know what the shader combination is inside each drawing function's code. */
+typedef struct METAL_ShaderPipelines
+{
+ MTLPixelFormat renderTargetFormat;
+ METAL_PipelineCache caches[SDL_METAL_FRAGMENT_COUNT];
+} METAL_ShaderPipelines;
+
+@interface METAL_RenderData : NSObject
+ @property (nonatomic, retain) id<MTLDevice> mtldevice;
+ @property (nonatomic, retain) id<MTLCommandQueue> mtlcmdqueue;
+ @property (nonatomic, retain) id<MTLCommandBuffer> mtlcmdbuffer;
+ @property (nonatomic, retain) id<MTLRenderCommandEncoder> mtlcmdencoder;
+ @property (nonatomic, retain) id<MTLLibrary> mtllibrary;
+ @property (nonatomic, retain) id<CAMetalDrawable> mtlbackbuffer;
+ @property (nonatomic, retain) id<MTLSamplerState> mtlsamplernearest;
+ @property (nonatomic, retain) id<MTLSamplerState> mtlsamplerlinear;
+ @property (nonatomic, retain) id<MTLBuffer> mtlbufconstants;
+ @property (nonatomic, retain) CAMetalLayer *mtllayer;
+ @property (nonatomic, retain) MTLRenderPassDescriptor *mtlpassdesc;
+ @property (nonatomic, assign) METAL_ShaderPipelines *activepipelines;
+ @property (nonatomic, assign) METAL_ShaderPipelines *allpipelines;
+ @property (nonatomic, assign) int pipelinescount;
+@end
+
+@implementation METAL_RenderData
+#if !__has_feature(objc_arc)
+- (void)dealloc
+{
+ [_mtldevice release];
+ [_mtlcmdqueue release];
+ [_mtlcmdbuffer release];
+ [_mtlcmdencoder release];
+ [_mtllibrary release];
+ [_mtlbackbuffer release];
+ [_mtlsamplernearest release];
+ [_mtlsamplerlinear release];
+ [_mtlbufconstants release];
+ [_mtllayer release];
+ [_mtlpassdesc release];
+ [super dealloc];
+}
+#endif
+@end
+
+@interface METAL_TextureData : NSObject
+ @property (nonatomic, retain) id<MTLTexture> mtltexture;
+ @property (nonatomic, retain) id<MTLTexture> mtltexture_uv;
+ @property (nonatomic, retain) id<MTLSamplerState> mtlsampler;
+ @property (nonatomic, assign) SDL_MetalFragmentFunction fragmentFunction;
+ @property (nonatomic, assign) BOOL yuv;
+ @property (nonatomic, assign) BOOL nv12;
+ @property (nonatomic, assign) size_t conversionBufferOffset;
+@end
+
+@implementation METAL_TextureData
+#if !__has_feature(objc_arc)
+- (void)dealloc
+{
+ [_mtltexture release];
+ [_mtltexture_uv release];
+ [_mtlsampler release];
+ [super dealloc];
+}
+#endif
+@end
+
+static int
+IsMetalAvailable(const SDL_SysWMinfo *syswm)
+{
+ if (syswm->subsystem != SDL_SYSWM_COCOA && syswm->subsystem != SDL_SYSWM_UIKIT) {
+ return SDL_SetError("Metal render target only supports Cocoa and UIKit video targets at the moment.");
+ }
+
+ // this checks a weak symbol.
+#if (defined(__MACOSX__) && (MAC_OS_X_VERSION_MIN_REQUIRED < 101100))
+ if (MTLCreateSystemDefaultDevice == NULL) { // probably on 10.10 or lower.
+ return SDL_SetError("Metal framework not available on this system");
+ }
+#endif
+
+ return 0;
+}
+
+static const MTLBlendOperation invalidBlendOperation = (MTLBlendOperation)0xFFFFFFFF;
+static const MTLBlendFactor invalidBlendFactor = (MTLBlendFactor)0xFFFFFFFF;
+
+static MTLBlendOperation
+GetBlendOperation(SDL_BlendOperation operation)
+{
+ switch (operation) {
+ case SDL_BLENDOPERATION_ADD: return MTLBlendOperationAdd;
+ case SDL_BLENDOPERATION_SUBTRACT: return MTLBlendOperationSubtract;
+ case SDL_BLENDOPERATION_REV_SUBTRACT: return MTLBlendOperationReverseSubtract;
+ case SDL_BLENDOPERATION_MINIMUM: return MTLBlendOperationMin;
+ case SDL_BLENDOPERATION_MAXIMUM: return MTLBlendOperationMax;
+ default: return invalidBlendOperation;
+ }
+}
+
+static MTLBlendFactor
+GetBlendFactor(SDL_BlendFactor factor)
+{
+ switch (factor) {
+ case SDL_BLENDFACTOR_ZERO: return MTLBlendFactorZero;
+ case SDL_BLENDFACTOR_ONE: return MTLBlendFactorOne;
+ case SDL_BLENDFACTOR_SRC_COLOR: return MTLBlendFactorSourceColor;
+ case SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR: return MTLBlendFactorOneMinusSourceColor;
+ case SDL_BLENDFACTOR_SRC_ALPHA: return MTLBlendFactorSourceAlpha;
+ case SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA: return MTLBlendFactorOneMinusSourceAlpha;
+ case SDL_BLENDFACTOR_DST_COLOR: return MTLBlendFactorDestinationColor;
+ case SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR: return MTLBlendFactorOneMinusDestinationColor;
+ case SDL_BLENDFACTOR_DST_ALPHA: return MTLBlendFactorDestinationAlpha;
+ case SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA: return MTLBlendFactorOneMinusDestinationAlpha;
+ default: return invalidBlendFactor;
+ }
+}
+
+static NSString *
+GetVertexFunctionName(SDL_MetalVertexFunction function)
+{
+ switch (function) {
+ case SDL_METAL_VERTEX_SOLID: return @"SDL_Solid_vertex";
+ case SDL_METAL_VERTEX_COPY: return @"SDL_Copy_vertex";
+ default: return nil;
+ }
+}
+
+static NSString *
+GetFragmentFunctionName(SDL_MetalFragmentFunction function)
+{
+ switch (function) {
+ case SDL_METAL_FRAGMENT_SOLID: return @"SDL_Solid_fragment";
+ case SDL_METAL_FRAGMENT_COPY: return @"SDL_Copy_fragment";
+ case SDL_METAL_FRAGMENT_YUV: return @"SDL_YUV_fragment";
+ case SDL_METAL_FRAGMENT_NV12: return @"SDL_NV12_fragment";
+ case SDL_METAL_FRAGMENT_NV21: return @"SDL_NV21_fragment";
+ default: return nil;
+ }
+}
+
+static id<MTLRenderPipelineState>
+MakePipelineState(METAL_RenderData *data, METAL_PipelineCache *cache,
+ NSString *blendlabel, SDL_BlendMode blendmode)
+{
+ id<MTLFunction> mtlvertfn = [data.mtllibrary newFunctionWithName:GetVertexFunctionName(cache->vertexFunction)];
+ id<MTLFunction> mtlfragfn = [data.mtllibrary newFunctionWithName:GetFragmentFunctionName(cache->fragmentFunction)];
+ SDL_assert(mtlvertfn != nil);
+ SDL_assert(mtlfragfn != nil);
+
+ MTLRenderPipelineDescriptor *mtlpipedesc = [[MTLRenderPipelineDescriptor alloc] init];
+ mtlpipedesc.vertexFunction = mtlvertfn;
+ mtlpipedesc.fragmentFunction = mtlfragfn;
+
+ MTLRenderPipelineColorAttachmentDescriptor *rtdesc = mtlpipedesc.colorAttachments[0];
+
+ rtdesc.pixelFormat = cache->renderTargetFormat;
+
+ if (blendmode != SDL_BLENDMODE_NONE) {
+ rtdesc.blendingEnabled = YES;
+ rtdesc.sourceRGBBlendFactor = GetBlendFactor(SDL_GetBlendModeSrcColorFactor(blendmode));
+ rtdesc.destinationRGBBlendFactor = GetBlendFactor(SDL_GetBlendModeDstColorFactor(blendmode));
+ rtdesc.rgbBlendOperation = GetBlendOperation(SDL_GetBlendModeColorOperation(blendmode));
+ rtdesc.sourceAlphaBlendFactor = GetBlendFactor(SDL_GetBlendModeSrcAlphaFactor(blendmode));
+ rtdesc.destinationAlphaBlendFactor = GetBlendFactor(SDL_GetBlendModeDstAlphaFactor(blendmode));
+ rtdesc.alphaBlendOperation = GetBlendOperation(SDL_GetBlendModeAlphaOperation(blendmode));
+ } else {
+ rtdesc.blendingEnabled = NO;
+ }
+
+ mtlpipedesc.label = [@(cache->label) stringByAppendingString:blendlabel];
+
+ NSError *err = nil;
+ id<MTLRenderPipelineState> state = [data.mtldevice newRenderPipelineStateWithDescriptor:mtlpipedesc error:&err];
+ SDL_assert(err == nil);
+
+ METAL_PipelineState pipeline;
+ pipeline.blendMode = blendmode;
+ pipeline.pipe = (void *)CFBridgingRetain(state);
+
+ METAL_PipelineState *states = SDL_realloc(cache->states, (cache->count + 1) * sizeof(pipeline));
+
+#if !__has_feature(objc_arc)
+ [mtlpipedesc release]; // !!! FIXME: can these be reused for each creation, or does the pipeline obtain it?
+ [mtlvertfn release];
+ [mtlfragfn release];
+ [state release];
+#endif
+
+ if (states) {
+ states[cache->count++] = pipeline;
+ cache->states = states;
+ return (__bridge id<MTLRenderPipelineState>)pipeline.pipe;
+ } else {
+ CFBridgingRelease(pipeline.pipe);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+}
+
+static void
+MakePipelineCache(METAL_RenderData *data, METAL_PipelineCache *cache, const char *label,
+ MTLPixelFormat rtformat, SDL_MetalVertexFunction vertfn, SDL_MetalFragmentFunction fragfn)
+{
+ SDL_zerop(cache);
+
+ cache->vertexFunction = vertfn;
+ cache->fragmentFunction = fragfn;
+ cache->renderTargetFormat = rtformat;
+ cache->label = label;
+
+ /* Create pipeline states for the default blend modes. Custom blend modes
+ * will be added to the cache on-demand. */
+ MakePipelineState(data, cache, @" (blend=none)", SDL_BLENDMODE_NONE);
+ MakePipelineState(data, cache, @" (blend=blend)", SDL_BLENDMODE_BLEND);
+ MakePipelineState(data, cache, @" (blend=add)", SDL_BLENDMODE_ADD);
+ MakePipelineState(data, cache, @" (blend=mod)", SDL_BLENDMODE_MOD);
+}
+
+static void
+DestroyPipelineCache(METAL_PipelineCache *cache)
+{
+ if (cache != NULL) {
+ for (int i = 0; i < cache->count; i++) {
+ CFBridgingRelease(cache->states[i].pipe);
+ }
+
+ SDL_free(cache->states);
+ }
+}
+
+void
+MakeShaderPipelines(METAL_RenderData *data, METAL_ShaderPipelines *pipelines, MTLPixelFormat rtformat)
+{
+ SDL_zerop(pipelines);
+
+ pipelines->renderTargetFormat = rtformat;
+
+ MakePipelineCache(data, &pipelines->caches[SDL_METAL_FRAGMENT_SOLID], "SDL primitives pipeline", rtformat, SDL_METAL_VERTEX_SOLID, SDL_METAL_FRAGMENT_SOLID);
+ MakePipelineCache(data, &pipelines->caches[SDL_METAL_FRAGMENT_COPY], "SDL copy pipeline", rtformat, SDL_METAL_VERTEX_COPY, SDL_METAL_FRAGMENT_COPY);
+ MakePipelineCache(data, &pipelines->caches[SDL_METAL_FRAGMENT_YUV], "SDL YUV pipeline", rtformat, SDL_METAL_VERTEX_COPY, SDL_METAL_FRAGMENT_YUV);
+ MakePipelineCache(data, &pipelines->caches[SDL_METAL_FRAGMENT_NV12], "SDL NV12 pipeline", rtformat, SDL_METAL_VERTEX_COPY, SDL_METAL_FRAGMENT_NV12);
+ MakePipelineCache(data, &pipelines->caches[SDL_METAL_FRAGMENT_NV21], "SDL NV21 pipeline", rtformat, SDL_METAL_VERTEX_COPY, SDL_METAL_FRAGMENT_NV21);
+}
+
+static METAL_ShaderPipelines *
+ChooseShaderPipelines(METAL_RenderData *data, MTLPixelFormat rtformat)
+{
+ METAL_ShaderPipelines *allpipelines = data.allpipelines;
+ int count = data.pipelinescount;
+
+ for (int i = 0; i < count; i++) {
+ if (allpipelines[i].renderTargetFormat == rtformat) {
+ return &allpipelines[i];
+ }
+ }
+
+ allpipelines = SDL_realloc(allpipelines, (count + 1) * sizeof(METAL_ShaderPipelines));
+
+ if (allpipelines == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ MakeShaderPipelines(data, &allpipelines[count], rtformat);
+
+ data.allpipelines = allpipelines;
+ data.pipelinescount = count + 1;
+
+ return &data.allpipelines[count];
+}
+
+static void
+DestroyAllPipelines(METAL_ShaderPipelines *allpipelines, int count)
+{
+ if (allpipelines != NULL) {
+ for (int i = 0; i < count; i++) {
+ for (int cache = 0; cache < SDL_METAL_FRAGMENT_COUNT; cache++) {
+ DestroyPipelineCache(&allpipelines[i].caches[cache]);
+ }
+ }
+
+ SDL_free(allpipelines);
+ }
+}
+
+static inline id<MTLRenderPipelineState>
+ChoosePipelineState(METAL_RenderData *data, METAL_ShaderPipelines *pipelines, SDL_MetalFragmentFunction fragfn, SDL_BlendMode blendmode)
+{
+ METAL_PipelineCache *cache = &pipelines->caches[fragfn];
+
+ for (int i = 0; i < cache->count; i++) {
+ if (cache->states[i].blendMode == blendmode) {
+ return (__bridge id<MTLRenderPipelineState>)cache->states[i].pipe;
+ }
+ }
+
+ return MakePipelineState(data, cache, [NSString stringWithFormat:@" (blend=custom 0x%x)", blendmode], blendmode);
+}
+
+static SDL_Renderer *
+METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
+{ @autoreleasepool {
+ SDL_Renderer *renderer = NULL;
+ METAL_RenderData *data = NULL;
+ id<MTLDevice> mtldevice = nil;
+ SDL_SysWMinfo syswm;
+
+ SDL_VERSION(&syswm.version);
+ if (!SDL_GetWindowWMInfo(window, &syswm)) {
+ return NULL;
+ }
+
+ if (IsMetalAvailable(&syswm) == -1) {
+ return NULL;
+ }
+
+ renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
+ if (!renderer) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ // !!! FIXME: MTLCopyAllDevices() can find other GPUs on macOS...
+ mtldevice = MTLCreateSystemDefaultDevice();
+
+ if (mtldevice == nil) {
+ SDL_free(renderer);
+ SDL_SetError("Failed to obtain Metal device");
+ return NULL;
+ }
+
+ // !!! FIXME: error checking on all of this.
+ data = [[METAL_RenderData alloc] init];
+
+ renderer->driverdata = (void*)CFBridgingRetain(data);
+ renderer->window = window;
+
+#ifdef __MACOSX__
+ NSView *view = Cocoa_Mtl_AddMetalView(window);
+ CAMetalLayer *layer = (CAMetalLayer *)[view layer];
+
+ layer.device = mtldevice;
+
+ //layer.colorspace = nil;
+
+#else
+ UIView *view = UIKit_Mtl_AddMetalView(window);
+ CAMetalLayer *layer = (CAMetalLayer *)[view layer];
+#endif
+
+ // Necessary for RenderReadPixels.
+ layer.framebufferOnly = NO;
+
+ data.mtldevice = layer.device;
+ data.mtllayer = layer;
+ id<MTLCommandQueue> mtlcmdqueue = [data.mtldevice newCommandQueue];
+ data.mtlcmdqueue = mtlcmdqueue;
+ data.mtlcmdqueue.label = @"SDL Metal Renderer";
+ data.mtlpassdesc = [MTLRenderPassDescriptor renderPassDescriptor];
+
+ NSError *err = nil;
+
+ // The compiled .metallib is embedded in a static array in a header file
+ // but the original shader source code is in SDL_shaders_metal.metal.
+ dispatch_data_t mtllibdata = dispatch_data_create(sdl_metallib, sdl_metallib_len, dispatch_get_global_queue(0, 0), ^{});
+ id<MTLLibrary> mtllibrary = [data.mtldevice newLibraryWithData:mtllibdata error:&err];
+ data.mtllibrary = mtllibrary;
+ SDL_assert(err == nil);
+#if !__has_feature(objc_arc)
+ dispatch_release(mtllibdata);
+#endif
+ data.mtllibrary.label = @"SDL Metal renderer shader library";
+
+ /* Do some shader pipeline state loading up-front rather than on demand. */
+ data.pipelinescount = 0;
+ data.allpipelines = NULL;
+ ChooseShaderPipelines(data, MTLPixelFormatBGRA8Unorm);
+
+ MTLSamplerDescriptor *samplerdesc = [[MTLSamplerDescriptor alloc] init];
+
+ samplerdesc.minFilter = MTLSamplerMinMagFilterNearest;
+ samplerdesc.magFilter = MTLSamplerMinMagFilterNearest;
+ id<MTLSamplerState> mtlsamplernearest = [data.mtldevice newSamplerStateWithDescriptor:samplerdesc];
+ data.mtlsamplernearest = mtlsamplernearest;
+
+ samplerdesc.minFilter = MTLSamplerMinMagFilterLinear;
+ samplerdesc.magFilter = MTLSamplerMinMagFilterLinear;
+ id<MTLSamplerState> mtlsamplerlinear = [data.mtldevice newSamplerStateWithDescriptor:samplerdesc];
+ data.mtlsamplerlinear = mtlsamplerlinear;
+
+ /* Note: matrices are column major. */
+ float identitytransform[16] = {
+ 1.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f,
+ };
+
+ float halfpixeltransform[16] = {
+ 1.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f,
+ 0.5f, 0.5f, 0.0f, 1.0f,
+ };
+
+ /* Metal pads float3s to 16 bytes. */
+ float decodetransformJPEG[4*4] = {
+ 0.0, -0.501960814, -0.501960814, 0.0, /* offset */
+ 1.0000, 0.0000, 1.4020, 0.0, /* Rcoeff */
+ 1.0000, -0.3441, -0.7141, 0.0, /* Gcoeff */
+ 1.0000, 1.7720, 0.0000, 0.0, /* Bcoeff */
+ };
+
+ float decodetransformBT601[4*4] = {
+ -0.0627451017, -0.501960814, -0.501960814, 0.0, /* offset */
+ 1.1644, 0.0000, 1.5960, 0.0, /* Rcoeff */
+ 1.1644, -0.3918, -0.8130, 0.0, /* Gcoeff */
+ 1.1644, 2.0172, 0.0000, 0.0, /* Bcoeff */
+ };
+
+ float decodetransformBT709[4*4] = {
+ 0.0, -0.501960814, -0.501960814, 0.0, /* offset */
+ 1.0000, 0.0000, 1.4020, 0.0, /* Rcoeff */
+ 1.0000, -0.3441, -0.7141, 0.0, /* Gcoeff */
+ 1.0000, 1.7720, 0.0000, 0.0, /* Bcoeff */
+ };
+
+ float clearverts[6] = {0.0f, 0.0f, 0.0f, 2.0f, 2.0f, 0.0f};
+
+ id<MTLBuffer> mtlbufconstantstaging = [data.mtldevice newBufferWithLength:CONSTANTS_LENGTH options:MTLResourceStorageModeShared];
+ mtlbufconstantstaging.label = @"SDL constant staging data";
+
+ id<MTLBuffer> mtlbufconstants = [data.mtldevice newBufferWithLength:CONSTANTS_LENGTH options:MTLResourceStorageModePrivate];
+ data.mtlbufconstants = mtlbufconstants;
+ data.mtlbufconstants.label = @"SDL constant data";
+
+ char *constantdata = [mtlbufconstantstaging contents];
+ SDL_memcpy(constantdata + CONSTANTS_OFFSET_IDENTITY, identitytransform, sizeof(identitytransform));
+ SDL_memcpy(constantdata + CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM, halfpixeltransform, sizeof(halfpixeltransform));
+ SDL_memcpy(constantdata + CONSTANTS_OFFSET_DECODE_JPEG, decodetransformJPEG, sizeof(decodetransformJPEG));
+ SDL_memcpy(constantdata + CONSTANTS_OFFSET_DECODE_BT601, decodetransformBT601, sizeof(decodetransformBT601));
+ SDL_memcpy(constantdata + CONSTANTS_OFFSET_DECODE_BT709, decodetransformBT709, sizeof(decodetransformBT709));
+ SDL_memcpy(constantdata + CONSTANTS_OFFSET_CLEAR_VERTS, clearverts, sizeof(clearverts));
+
+ id<MTLCommandBuffer> cmdbuffer = [data.mtlcmdqueue commandBuffer];
+ id<MTLBlitCommandEncoder> blitcmd = [cmdbuffer blitCommandEncoder];
+
+ [blitcmd copyFromBuffer:mtlbufconstantstaging sourceOffset:0 toBuffer:data.mtlbufconstants destinationOffset:0 size:CONSTANTS_LENGTH];
+
+ [blitcmd endEncoding];
+ [cmdbuffer commit];
+
+ // !!! FIXME: force more clears here so all the drawables are sane to start, and our static buffers are definitely flushed.
+
+ renderer->WindowEvent = METAL_WindowEvent;
+ renderer->GetOutputSize = METAL_GetOutputSize;
+ renderer->SupportsBlendMode = METAL_SupportsBlendMode;
+ renderer->CreateTexture = METAL_CreateTexture;
+ renderer->UpdateTexture = METAL_UpdateTexture;
+ renderer->UpdateTextureYUV = METAL_UpdateTextureYUV;
+ renderer->LockTexture = METAL_LockTexture;
+ renderer->UnlockTexture = METAL_UnlockTexture;
+ renderer->SetRenderTarget = METAL_SetRenderTarget;
+ renderer->UpdateViewport = METAL_UpdateViewport;
+ renderer->UpdateClipRect = METAL_UpdateClipRect;
+ renderer->RenderClear = METAL_RenderClear;
+ renderer->RenderDrawPoints = METAL_RenderDrawPoints;
+ renderer->RenderDrawLines = METAL_RenderDrawLines;
+ renderer->RenderFillRects = METAL_RenderFillRects;
+ renderer->RenderCopy = METAL_RenderCopy;
+ renderer->RenderCopyEx = METAL_RenderCopyEx;
+ renderer->RenderReadPixels = METAL_RenderReadPixels;
+ renderer->RenderPresent = METAL_RenderPresent;
+ renderer->DestroyTexture = METAL_DestroyTexture;
+ renderer->DestroyRenderer = METAL_DestroyRenderer;
+ renderer->GetMetalLayer = METAL_GetMetalLayer;
+ renderer->GetMetalCommandEncoder = METAL_GetMetalCommandEncoder;
+
+ renderer->info = METAL_RenderDriver.info;
+ renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
+
+#if defined(__MACOSX__) && defined(MAC_OS_X_VERSION_10_13)
+ if (@available(macOS 10.13, *)) {
+ data.mtllayer.displaySyncEnabled = (flags & SDL_RENDERER_PRESENTVSYNC) != 0;
+ } else
+#endif
+ {
+ renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
+ }
+
+ /* https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf */
+ int maxtexsize = 4096;
+#if defined(__MACOSX__)
+ maxtexsize = 16384;
+#elif defined(__TVOS__)
+ maxtexsize = 8192;
+#ifdef __TVOS_11_0
+ if (@available(tvOS 11.0, *)) {
+ if ([mtldevice supportsFeatureSet:MTLFeatureSet_tvOS_GPUFamily2_v1]) {
+ maxtexsize = 16384;
+ }
+ }
+#endif
+#else
+#ifdef __IPHONE_11_0
+ if ([mtldevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily4_v1]) {
+ maxtexsize = 16384;
+ } else
+#endif
+#ifdef __IPHONE_10_0
+ if ([mtldevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v1]) {
+ maxtexsize = 16384;
+ } else
+#endif
+ if ([mtldevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily2_v2] || [mtldevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v2]) {
+ maxtexsize = 8192;
+ } else {
+ maxtexsize = 4096;
+ }
+#endif
+
+ renderer->info.max_texture_width = maxtexsize;
+ renderer->info.max_texture_height = maxtexsize;
+
+#if !__has_feature(objc_arc)
+ [mtlcmdqueue release];
+ [mtllibrary release];
+ [samplerdesc release];
+ [mtlsamplernearest release];
+ [mtlsamplerlinear release];
+ [mtlbufconstants release];
+ [view release];
+ [data release];
+ [mtldevice release];
+#endif
+
+ return renderer;
+}}
+
+static void
+METAL_ActivateRenderCommandEncoder(SDL_Renderer * renderer, MTLLoadAction load)
+{
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+
+ /* Our SetRenderTarget just signals that the next render operation should
+ * set up a new render pass. This is where that work happens. */
+ if (data.mtlcmdencoder == nil) {
+ id<MTLTexture> mtltexture = nil;
+
+ if (renderer->target != NULL) {
+ METAL_TextureData *texdata = (__bridge METAL_TextureData *)renderer->target->driverdata;
+ mtltexture = texdata.mtltexture;
+ } else {
+ if (data.mtlbackbuffer == nil) {
+ /* The backbuffer's contents aren't guaranteed to persist after
+ * presenting, so we can leave it undefined when loading it. */
+ data.mtlbackbuffer = [data.mtllayer nextDrawable];
+ if (load == MTLLoadActionLoad) {
+ load = MTLLoadActionDontCare;
+ }
+ }
+ mtltexture = data.mtlbackbuffer.texture;
+ }
+
+ SDL_assert(mtltexture);
+
+ if (load == MTLLoadActionClear) {
+ MTLClearColor color = MTLClearColorMake(renderer->r/255.0, renderer->g/255.0, renderer->b/255.0, renderer->a/255.0);
+ data.mtlpassdesc.colorAttachments[0].clearColor = color;
+ }
+
+ data.mtlpassdesc.colorAttachments[0].loadAction = load;
+ data.mtlpassdesc.colorAttachments[0].texture = mtltexture;
+
+ data.mtlcmdbuffer = [data.mtlcmdqueue commandBuffer];
+ data.mtlcmdencoder = [data.mtlcmdbuffer renderCommandEncoderWithDescriptor:data.mtlpassdesc];
+
+ if (data.mtlbackbuffer != nil && mtltexture == data.mtlbackbuffer.texture) {
+ data.mtlcmdencoder.label = @"SDL metal renderer backbuffer";
+ } else {
+ data.mtlcmdencoder.label = @"SDL metal renderer render target";
+ }
+
+ data.activepipelines = ChooseShaderPipelines(data, mtltexture.pixelFormat);
+
+ /* Make sure the viewport and clip rect are set on the new render pass. */
+ METAL_UpdateViewport(renderer);
+ METAL_UpdateClipRect(renderer);
+ }
+}
+
+static void
+METAL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
+{
+ if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED ||
+ event->event == SDL_WINDOWEVENT_SHOWN ||
+ event->event == SDL_WINDOWEVENT_HIDDEN) {
+ // !!! FIXME: write me
+ }
+}
+
+static int
+METAL_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
+{ @autoreleasepool {
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+ if (w) {
+ *w = (int)data.mtllayer.drawableSize.width;
+ }
+ if (h) {
+ *h = (int)data.mtllayer.drawableSize.height;
+ }
+ return 0;
+}}
+
+static SDL_bool
+METAL_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
+{
+ SDL_BlendFactor srcColorFactor = SDL_GetBlendModeSrcColorFactor(blendMode);
+ SDL_BlendFactor srcAlphaFactor = SDL_GetBlendModeSrcAlphaFactor(blendMode);
+ SDL_BlendOperation colorOperation = SDL_GetBlendModeColorOperation(blendMode);
+ SDL_BlendFactor dstColorFactor = SDL_GetBlendModeDstColorFactor(blendMode);
+ SDL_BlendFactor dstAlphaFactor = SDL_GetBlendModeDstAlphaFactor(blendMode);
+ SDL_BlendOperation alphaOperation = SDL_GetBlendModeAlphaOperation(blendMode);
+
+ if (GetBlendFactor(srcColorFactor) == invalidBlendFactor ||
+ GetBlendFactor(srcAlphaFactor) == invalidBlendFactor ||
+ GetBlendOperation(colorOperation) == invalidBlendOperation ||
+ GetBlendFactor(dstColorFactor) == invalidBlendFactor ||
+ GetBlendFactor(dstAlphaFactor) == invalidBlendFactor ||
+ GetBlendOperation(alphaOperation) == invalidBlendOperation) {
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
+}
+
+static int
+METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{ @autoreleasepool {
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+ MTLPixelFormat pixfmt;
+
+ switch (texture->format) {
+ case SDL_PIXELFORMAT_ABGR8888:
+ pixfmt = MTLPixelFormatRGBA8Unorm;
+ break;
+ case SDL_PIXELFORMAT_ARGB8888:
+ pixfmt = MTLPixelFormatBGRA8Unorm;
+ break;
+ case SDL_PIXELFORMAT_IYUV:
+ case SDL_PIXELFORMAT_YV12:
+ case SDL_PIXELFORMAT_NV12:
+ case SDL_PIXELFORMAT_NV21:
+ pixfmt = MTLPixelFormatR8Unorm;
+ break;
+ default:
+ return SDL_SetError("Texture format %s not supported by Metal", SDL_GetPixelFormatName(texture->format));
+ }
+
+ MTLTextureDescriptor *mtltexdesc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:pixfmt
+ width:(NSUInteger)texture->w height:(NSUInteger)texture->h mipmapped:NO];
+
+ /* Not available in iOS 8. */
+ if ([mtltexdesc respondsToSelector:@selector(usage)]) {
+ if (texture->access == SDL_TEXTUREACCESS_TARGET) {
+ mtltexdesc.usage = MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget;
+ } else {
+ mtltexdesc.usage = MTLTextureUsageShaderRead;
+ }
+ }
+
+ id<MTLTexture> mtltexture = [data.mtldevice newTextureWithDescriptor:mtltexdesc];
+ if (mtltexture == nil) {
+ return SDL_SetError("Texture allocation failed");
+ }
+
+ id<MTLTexture> mtltexture_uv = nil;
+
+ BOOL yuv = (texture->format == SDL_PIXELFORMAT_IYUV) || (texture->format == SDL_PIXELFORMAT_YV12);
+ BOOL nv12 = (texture->format == SDL_PIXELFORMAT_NV12) || (texture->format == SDL_PIXELFORMAT_NV21);
+
+ if (yuv) {
+ mtltexdesc.pixelFormat = MTLPixelFormatR8Unorm;
+ mtltexdesc.width = (texture->w + 1) / 2;
+ mtltexdesc.height = (texture->h + 1) / 2;
+ mtltexdesc.textureType = MTLTextureType2DArray;
+ mtltexdesc.arrayLength = 2;
+ mtltexture_uv = [data.mtldevice newTextureWithDescriptor:mtltexdesc];
+ } else if (nv12) {
+ mtltexdesc.pixelFormat = MTLPixelFormatRG8Unorm;
+ mtltexdesc.width = (texture->w + 1) / 2;
+ mtltexdesc.height = (texture->h + 1) / 2;
+ mtltexture_uv = [data.mtldevice newTextureWithDescriptor:mtltexdesc];
+ }
+
+ METAL_TextureData *texturedata = [[METAL_TextureData alloc] init];
+ const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
+ if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
+ texturedata.mtlsampler = data.mtlsamplernearest;
+ } else {
+ texturedata.mtlsampler = data.mtlsamplerlinear;
+ }
+ texturedata.mtltexture = mtltexture;
+ texturedata.mtltexture_uv = mtltexture_uv;
+
+ texturedata.yuv = yuv;
+ texturedata.nv12 = nv12;
+
+ if (yuv) {
+ texturedata.fragmentFunction = SDL_METAL_FRAGMENT_YUV;
+ } else if (texture->format == SDL_PIXELFORMAT_NV12) {
+ texturedata.fragmentFunction = SDL_METAL_FRAGMENT_NV12;
+ } else if (texture->format == SDL_PIXELFORMAT_NV21) {
+ texturedata.fragmentFunction = SDL_METAL_FRAGMENT_NV21;
+ } else {
+ texturedata.fragmentFunction = SDL_METAL_FRAGMENT_COPY;
+ }
+
+ if (yuv || nv12) {
+ size_t offset = 0;
+ SDL_YUV_CONVERSION_MODE mode = SDL_GetYUVConversionModeForResolution(texture->w, texture->h);
+ switch (mode) {
+ case SDL_YUV_CONVERSION_JPEG: offset = CONSTANTS_OFFSET_DECODE_JPEG; break;
+ case SDL_YUV_CONVERSION_BT601: offset = CONSTANTS_OFFSET_DECODE_BT601; break;
+ case SDL_YUV_CONVERSION_BT709: offset = CONSTANTS_OFFSET_DECODE_BT709; break;
+ default: offset = 0; break;
+ }
+ texturedata.conversionBufferOffset = offset;
+ }
+
+ texture->driverdata = (void*)CFBridgingRetain(texturedata);
+
+#if !__has_feature(objc_arc)
+ [texturedata release];
+ [mtltexture release];
+ [mtltexture_uv release];
+#endif
+
+ return 0;
+}}
+
+static int
+METAL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, const void *pixels, int pitch)
+{ @autoreleasepool {
+ METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
+
+ /* !!! FIXME: replaceRegion does not do any synchronization, so it might
+ * !!! FIXME: stomp on a previous frame's data that's currently being read
+ * !!! FIXME: by the GPU. */
+ [texturedata.mtltexture replaceRegion:MTLRegionMake2D(rect->x, rect->y, rect->w, rect->h)
+ mipmapLevel:0
+ withBytes:pixels
+ bytesPerRow:pitch];
+
+ if (texturedata.yuv) {
+ int Uslice = texture->format == SDL_PIXELFORMAT_YV12 ? 1 : 0;
+ int Vslice = texture->format == SDL_PIXELFORMAT_YV12 ? 0 : 1;
+
+ /* Skip to the correct offset into the next texture */
+ pixels = (const void*)((const Uint8*)pixels + rect->h * pitch);
+ [texturedata.mtltexture_uv replaceRegion:MTLRegionMake2D(rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2)
+ mipmapLevel:0
+ slice:Uslice
+ withBytes:pixels
+ bytesPerRow:(pitch + 1) / 2
+ bytesPerImage:0];
+
+ /* Skip to the correct offset into the next texture */
+ pixels = (const void*)((const Uint8*)pixels + ((rect->h + 1) / 2) * ((pitch + 1)/2));
+ [texturedata.mtltexture_uv replaceRegion:MTLRegionMake2D(rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2)
+ mipmapLevel:0
+ slice:Vslice
+ withBytes:pixels
+ bytesPerRow:(pitch + 1) / 2
+ bytesPerImage:0];
+ }
+
+ if (texturedata.nv12) {
+ /* Skip to the correct offset into the next texture */
+ pixels = (const void*)((const Uint8*)pixels + rect->h * pitch);
+ [texturedata.mtltexture_uv replaceRegion:MTLRegionMake2D(rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2)
+ mipmapLevel:0
+ slice:0
+ withBytes:pixels
+ bytesPerRow:2 * ((pitch + 1) / 2)
+ bytesPerImage:0];
+ }
+
+ return 0;
+}}
+
+static int
+METAL_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch)
+{ @autoreleasepool {
+ METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
+ int Uslice = texture->format == SDL_PIXELFORMAT_YV12 ? 1 : 0;
+ int Vslice = texture->format == SDL_PIXELFORMAT_YV12 ? 0 : 1;
+
+ /* Bail out if we're supposed to update an empty rectangle */
+ if (rect->w <= 0 || rect->h <= 0) {
+ return 0;
+ }
+
+ [texturedata.mtltexture replaceRegion:MTLRegionMake2D(rect->x, rect->y, rect->w, rect->h)
+ mipmapLevel:0
+ withBytes:Yplane
+ bytesPerRow:Ypitch];
+
+ [texturedata.mtltexture_uv replaceRegion:MTLRegionMake2D(rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2)
+ mipmapLevel:0
+ slice:Uslice
+ withBytes:Uplane
+ bytesPerRow:Upitch
+ bytesPerImage:0];
+
+ [texturedata.mtltexture_uv replaceRegion:MTLRegionMake2D(rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2)
+ mipmapLevel:0
+ slice:Vslice
+ withBytes:Vplane
+ bytesPerRow:Vpitch
+ bytesPerImage:0];
+
+ return 0;
+}}
+
+static int
+METAL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, void **pixels, int *pitch)
+{
+ return SDL_Unsupported(); // !!! FIXME: write me
+}
+
+static void
+METAL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ // !!! FIXME: write me
+}
+
+static int
+METAL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
+{ @autoreleasepool {
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+
+ if (data.mtlcmdencoder) {
+ /* End encoding for the previous render target so we can set up a new
+ * render pass for this one. */
+ [data.mtlcmdencoder endEncoding];
+ [data.mtlcmdbuffer commit];
+
+ data.mtlcmdencoder = nil;
+ data.mtlcmdbuffer = nil;
+ }
+
+ /* We don't begin a new render pass right away - we delay it until an actual
+ * draw or clear happens. That way we can use hardware clears when possible,
+ * which are only available when beginning a new render pass. */
+ return 0;
+}}
+
+static int
+METAL_SetOrthographicProjection(SDL_Renderer *renderer, int w, int h)
+{ @autoreleasepool {
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+ float projection[4][4];
+
+ if (!w || !h) {
+ return 0;
+ }
+
+ /* Prepare an orthographic projection */
+ projection[0][0] = 2.0f / w;
+ projection[0][1] = 0.0f;
+ projection[0][2] = 0.0f;
+ projection[0][3] = 0.0f;
+ projection[1][0] = 0.0f;
+ projection[1][1] = -2.0f / h;
+ projection[1][2] = 0.0f;
+ projection[1][3] = 0.0f;
+ projection[2][0] = 0.0f;
+ projection[2][1] = 0.0f;
+ projection[2][2] = 0.0f;
+ projection[2][3] = 0.0f;
+ projection[3][0] = -1.0f;
+ projection[3][1] = 1.0f;
+ projection[3][2] = 0.0f;
+ projection[3][3] = 1.0f;
+
+ // !!! FIXME: This should be in a buffer...
+ [data.mtlcmdencoder setVertexBytes:projection length:sizeof(float)*16 atIndex:2];
+ return 0;
+}}
+
+static int
+METAL_UpdateViewport(SDL_Renderer * renderer)
+{ @autoreleasepool {
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+ if (data.mtlcmdencoder) {
+ MTLViewport viewport;
+ viewport.originX = renderer->viewport.x;
+ viewport.originY = renderer->viewport.y;
+ viewport.width = renderer->viewport.w;
+ viewport.height = renderer->viewport.h;
+ viewport.znear = 0.0;
+ viewport.zfar = 1.0;
+ [data.mtlcmdencoder setViewport:viewport];
+ METAL_SetOrthographicProjection(renderer, renderer->viewport.w, renderer->viewport.h);
+ }
+ return 0;
+}}
+
+static int
+METAL_UpdateClipRect(SDL_Renderer * renderer)
+{ @autoreleasepool {
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+ if (data.mtlcmdencoder) {
+ MTLScissorRect mtlrect;
+ // !!! FIXME: should this care about the viewport?
+ if (renderer->clipping_enabled) {
+ const SDL_Rect *rect = &renderer->clip_rect;
+ mtlrect.x = renderer->viewport.x + rect->x;
+ mtlrect.y = renderer->viewport.x + rect->y;
+ mtlrect.width = rect->w;
+ mtlrect.height = rect->h;
+ } else {
+ mtlrect.x = renderer->viewport.x;
+ mtlrect.y = renderer->viewport.y;
+ mtlrect.width = renderer->viewport.w;
+ mtlrect.height = renderer->viewport.h;
+ }
+ if (mtlrect.width > 0 && mtlrect.height > 0) {
+ [data.mtlcmdencoder setScissorRect:mtlrect];
+ }
+ }
+ return 0;
+}}
+
+static int
+METAL_RenderClear(SDL_Renderer * renderer)
+{ @autoreleasepool {
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+
+ /* Since we set up the render command encoder lazily when a draw is
+ * requested, we can do the fast path hardware clear if no draws have
+ * happened since the last SetRenderTarget. */
+ if (data.mtlcmdencoder == nil) {
+ METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionClear);
+ } else {
+ // !!! FIXME: render color should live in a dedicated uniform buffer.
+ const float color[4] = { ((float)renderer->r) / 255.0f, ((float)renderer->g) / 255.0f, ((float)renderer->b) / 255.0f, ((float)renderer->a) / 255.0f };
+
+ MTLViewport viewport; // RenderClear ignores the viewport state, though, so reset that.
+ viewport.originX = viewport.originY = 0.0;
+ viewport.width = data.mtlpassdesc.colorAttachments[0].texture.width;
+ viewport.height = data.mtlpassdesc.colorAttachments[0].texture.height;
+ viewport.znear = 0.0;
+ viewport.zfar = 1.0;
+
+ // Slow path for clearing: draw a filled fullscreen triangle.
+ METAL_SetOrthographicProjection(renderer, 1, 1);
+ [data.mtlcmdencoder setViewport:viewport];
+ [data.mtlcmdencoder setRenderPipelineState:ChoosePipelineState(data, data.activepipelines, SDL_METAL_FRAGMENT_SOLID, SDL_BLENDMODE_NONE)];
+ [data.mtlcmdencoder setVertexBuffer:data.mtlbufconstants offset:CONSTANTS_OFFSET_CLEAR_VERTS atIndex:0];
+ [data.mtlcmdencoder setVertexBuffer:data.mtlbufconstants offset:CONSTANTS_OFFSET_IDENTITY atIndex:3];
+ [data.mtlcmdencoder setFragmentBytes:color length:sizeof(color) atIndex:0];
+ [data.mtlcmdencoder drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:0 vertexCount:3];
+
+ // reset the viewport for the rest of our usual drawing work...
+ viewport.originX = renderer->viewport.x;
+ viewport.originY = renderer->viewport.y;
+ viewport.width = renderer->viewport.w;
+ viewport.height = renderer->viewport.h;
+ viewport.znear = 0.0;
+ viewport.zfar = 1.0;
+ [data.mtlcmdencoder setViewport:viewport];
+ METAL_SetOrthographicProjection(renderer, renderer->viewport.w, renderer->viewport.h);
+ }
+
+ return 0;
+}}
+
+// normalize a value from 0.0f to len into 0.0f to 1.0f.
+static inline float
+normtex(const float _val, const float len)
+{
+ return _val / len;
+}
+
+static int
+DrawVerts(SDL_Renderer * renderer, const SDL_FPoint * points, int count,
+ const MTLPrimitiveType primtype)
+{ @autoreleasepool {
+ METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad);
+
+ const size_t vertlen = (sizeof (float) * 2) * count;
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+
+ // !!! FIXME: render color should live in a dedicated uniform buffer.
+ const float color[4] = { ((float)renderer->r) / 255.0f, ((float)renderer->g) / 255.0f, ((float)renderer->b) / 255.0f, ((float)renderer->a) / 255.0f };
+
+ [data.mtlcmdencoder setRenderPipelineState:ChoosePipelineState(data, data.activepipelines, SDL_METAL_FRAGMENT_SOLID, renderer->blendMode)];
+ [data.mtlcmdencoder setFragmentBytes:color length:sizeof(color) atIndex:0];
+
+ [data.mtlcmdencoder setVertexBytes:points length:vertlen atIndex:0];
+ [data.mtlcmdencoder setVertexBuffer:data.mtlbufconstants offset:CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM atIndex:3];
+ [data.mtlcmdencoder drawPrimitives:primtype vertexStart:0 vertexCount:count];
+
+ return 0;
+}}
+
+static int
+METAL_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points, int count)
+{
+ return DrawVerts(renderer, points, count, MTLPrimitiveTypePoint);
+}
+
+static int
+METAL_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points, int count)
+{
+ return DrawVerts(renderer, points, count, MTLPrimitiveTypeLineStrip);
+}
+
+static int
+METAL_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, int count)
+{ @autoreleasepool {
+ METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad);
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+
+ // !!! FIXME: render color should live in a dedicated uniform buffer.
+ const float color[4] = { ((float)renderer->r) / 255.0f, ((float)renderer->g) / 255.0f, ((float)renderer->b) / 255.0f, ((float)renderer->a) / 255.0f };
+
+ [data.mtlcmdencoder setRenderPipelineState:ChoosePipelineState(data, data.activepipelines, SDL_METAL_FRAGMENT_SOLID, renderer->blendMode)];
+ [data.mtlcmdencoder setFragmentBytes:color length:sizeof(color) atIndex:0];
+ [data.mtlcmdencoder setVertexBuffer:data.mtlbufconstants offset:CONSTANTS_OFFSET_IDENTITY atIndex:3];
+
+ for (int i = 0; i < count; i++, rects++) {
+ if ((rects->w <= 0.0f) || (rects->h <= 0.0f)) continue;
+
+ const float verts[] = {
+ rects->x, rects->y + rects->h,
+ rects->x, rects->y,
+ rects->x + rects->w, rects->y + rects->h,
+ rects->x + rects->w, rects->y
+ };
+
+ [data.mtlcmdencoder setVertexBytes:verts length:sizeof(verts) atIndex:0];
+ [data.mtlcmdencoder drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];
+ }
+
+ return 0;
+}}
+
+static void
+METAL_SetupRenderCopy(METAL_RenderData *data, SDL_Texture *texture, METAL_TextureData *texturedata)
+{
+ float color[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
+ if (texture->modMode) {
+ color[0] = ((float)texture->r) / 255.0f;
+ color[1] = ((float)texture->g) / 255.0f;
+ color[2] = ((float)texture->b) / 255.0f;
+ color[3] = ((float)texture->a) / 255.0f;
+ }
+
+ [data.mtlcmdencoder setRenderPipelineState:ChoosePipelineState(data, data.activepipelines, texturedata.fragmentFunction, texture->blendMode)];
+ [data.mtlcmdencoder setFragmentBytes:color length:sizeof(color) atIndex:0];
+ [data.mtlcmdencoder setFragmentSamplerState:texturedata.mtlsampler atIndex:0];
+
+ [data.mtlcmdencoder setFragmentTexture:texturedata.mtltexture atIndex:0];
+
+ if (texturedata.yuv || texturedata.nv12) {
+ [data.mtlcmdencoder setFragmentTexture:texturedata.mtltexture_uv atIndex:1];
+ [data.mtlcmdencoder setFragmentBuffer:data.mtlbufconstants offset:texturedata.conversionBufferOffset atIndex:1];
+ }
+}
+
+static int
+METAL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect)
+{ @autoreleasepool {
+ METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad);
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+ METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
+ const float texw = (float) texturedata.mtltexture.width;
+ const float texh = (float) texturedata.mtltexture.height;
+
+ METAL_SetupRenderCopy(data, texture, texturedata);
+
+ const float xy[] = {
+ dstrect->x, dstrect->y + dstrect->h,
+ dstrect->x, dstrect->y,
+ dstrect->x + dstrect->w, dstrect->y + dstrect->h,
+ dstrect->x + dstrect->w, dstrect->y
+ };
+
+ const float uv[] = {
+ normtex(srcrect->x, texw), normtex(srcrect->y + srcrect->h, texh),
+ normtex(srcrect->x, texw), normtex(srcrect->y, texh),
+ normtex(srcrect->x + srcrect->w, texw), normtex(srcrect->y + srcrect->h, texh),
+ normtex(srcrect->x + srcrect->w, texw), normtex(srcrect->y, texh)
+ };
+
+ [data.mtlcmdencoder setVertexBytes:xy length:sizeof(xy) atIndex:0];
+ [data.mtlcmdencoder setVertexBytes:uv length:sizeof(uv) atIndex:1];
+ [data.mtlcmdencoder setVertexBuffer:data.mtlbufconstants offset:CONSTANTS_OFFSET_IDENTITY atIndex:3];
+ [data.mtlcmdencoder drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];
+
+ return 0;
+}}
+
+static int
+METAL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect,
+ const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
+{ @autoreleasepool {
+ METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad);
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+ METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
+ const float texw = (float) texturedata.mtltexture.width;
+ const float texh = (float) texturedata.mtltexture.height;
+ float transform[16];
+ float minu, maxu, minv, maxv;
+
+ METAL_SetupRenderCopy(data, texture, texturedata);
+
+ minu = normtex(srcrect->x, texw);
+ maxu = normtex(srcrect->x + srcrect->w, texw);
+ minv = normtex(srcrect->y, texh);
+ maxv = normtex(srcrect->y + srcrect->h, texh);
+
+ if (flip & SDL_FLIP_HORIZONTAL) {
+ float tmp = maxu;
+ maxu = minu;
+ minu = tmp;
+ }
+ if (flip & SDL_FLIP_VERTICAL) {
+ float tmp = maxv;
+ maxv = minv;
+ minv = tmp;
+ }
+
+ const float uv[] = {
+ minu, maxv,
+ minu, minv,
+ maxu, maxv,
+ maxu, minv
+ };
+
+ const float xy[] = {
+ -center->x, dstrect->h - center->y,
+ -center->x, -center->y,
+ dstrect->w - center->x, dstrect->h - center->y,
+ dstrect->w - center->x, -center->y
+ };
+
+ {
+ float rads = (float)(M_PI * (float) angle / 180.0f);
+ float c = cosf(rads), s = sinf(rads);
+ SDL_memset(transform, 0, sizeof(transform));
+
+ transform[10] = transform[15] = 1.0f;
+
+ /* Rotation */
+ transform[0] = c;
+ transform[1] = s;
+ transform[4] = -s;
+ transform[5] = c;
+
+ /* Translation */
+ transform[12] = dstrect->x + center->x;
+ transform[13] = dstrect->y + center->y;
+ }
+
+ [data.mtlcmdencoder setVertexBytes:xy length:sizeof(xy) atIndex:0];
+ [data.mtlcmdencoder setVertexBytes:uv length:sizeof(uv) atIndex:1];
+ [data.mtlcmdencoder setVertexBytes:transform length:sizeof(transform) atIndex:3];
+ [data.mtlcmdencoder drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];
+
+ return 0;
+}}
+
+static int
+METAL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 pixel_format, void * pixels, int pitch)
+{ @autoreleasepool {
+ METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad);
+
+ // !!! FIXME: this probably needs to commit the current command buffer, and probably waitUntilCompleted
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+ id<MTLTexture> mtltexture = data.mtlpassdesc.colorAttachments[0].texture;
+ MTLRegion mtlregion = MTLRegionMake2D(rect->x, rect->y, rect->w, rect->h);
+
+ // we only do BGRA8 or RGBA8 at the moment, so 4 will do.
+ const int temp_pitch = rect->w * 4;
+ void *temp_pixels = SDL_malloc(temp_pitch * rect->h);
+ if (!temp_pixels) {
+ return SDL_OutOfMemory();
+ }
+
+ [mtltexture getBytes:temp_pixels bytesPerRow:temp_pitch fromRegion:mtlregion mipmapLevel:0];
+
+ const Uint32 temp_format = (mtltexture.pixelFormat == MTLPixelFormatBGRA8Unorm) ? SDL_PIXELFORMAT_ARGB8888 : SDL_PIXELFORMAT_ABGR8888;
+ const int status = SDL_ConvertPixels(rect->w, rect->h, temp_format, temp_pixels, temp_pitch, pixel_format, pixels, pitch);
+ SDL_free(temp_pixels);
+ return status;
+}}
+
+static void
+METAL_RenderPresent(SDL_Renderer * renderer)
+{ @autoreleasepool {
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+
+ if (data.mtlcmdencoder != nil) {
+ [data.mtlcmdencoder endEncoding];
+ }
+ if (data.mtlbackbuffer != nil) {
+ [data.mtlcmdbuffer presentDrawable:data.mtlbackbuffer];
+ }
+ if (data.mtlcmdbuffer != nil) {
+ [data.mtlcmdbuffer commit];
+ }
+ data.mtlcmdencoder = nil;
+ data.mtlcmdbuffer = nil;
+ data.mtlbackbuffer = nil;
+}}
+
+static void
+METAL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{ @autoreleasepool {
+ CFBridgingRelease(texture->driverdata);
+ texture->driverdata = NULL;
+}}
+
+static void
+METAL_DestroyRenderer(SDL_Renderer * renderer)
+{ @autoreleasepool {
+ if (renderer->driverdata) {
+ METAL_RenderData *data = CFBridgingRelease(renderer->driverdata);
+
+ if (data.mtlcmdencoder != nil) {
+ [data.mtlcmdencoder endEncoding];
+ }
+
+ DestroyAllPipelines(data.allpipelines, data.pipelinescount);
+ }
+
+ SDL_free(renderer);
+}}
+
+static void *
+METAL_GetMetalLayer(SDL_Renderer * renderer)
+{ @autoreleasepool {
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+ return (__bridge void*)data.mtllayer;
+}}
+
+static void *
+METAL_GetMetalCommandEncoder(SDL_Renderer * renderer)
+{ @autoreleasepool {
+ METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad);
+ METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
+ return (__bridge void*)data.mtlcmdencoder;
+}}
+
+#endif /* SDL_VIDEO_RENDER_METAL && !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/metal/SDL_shaders_metal.metal b/src/3rdparty/SDL2/src/render/metal/SDL_shaders_metal.metal
new file mode 100644
index 0000000..8df3b75
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/metal/SDL_shaders_metal.metal
@@ -0,0 +1,109 @@
+#include <metal_texture>
+#include <metal_matrix>
+
+using namespace metal;
+
+struct SolidVertexOutput
+{
+ float4 position [[position]];
+ float pointSize [[point_size]];
+};
+
+vertex SolidVertexOutput SDL_Solid_vertex(const device float2 *position [[buffer(0)]],
+ constant float4x4 &projection [[buffer(2)]],
+ constant float4x4 &transform [[buffer(3)]],
+ uint vid [[vertex_id]])
+{
+ SolidVertexOutput v;
+ v.position = (projection * transform) * float4(position[vid], 0.0f, 1.0f);
+ v.pointSize = 1.0f;
+ return v;
+}
+
+fragment float4 SDL_Solid_fragment(constant float4 &col [[buffer(0)]])
+{
+ return col;
+}
+
+struct CopyVertexOutput
+{
+ float4 position [[position]];
+ float2 texcoord;
+};
+
+vertex CopyVertexOutput SDL_Copy_vertex(const device float2 *position [[buffer(0)]],
+ const device float2 *texcoords [[buffer(1)]],
+ constant float4x4 &projection [[buffer(2)]],
+ constant float4x4 &transform [[buffer(3)]],
+ uint vid [[vertex_id]])
+{
+ CopyVertexOutput v;
+ v.position = (projection * transform) * float4(position[vid], 0.0f, 1.0f);
+ v.texcoord = texcoords[vid];
+ return v;
+}
+
+fragment float4 SDL_Copy_fragment(CopyVertexOutput vert [[stage_in]],
+ constant float4 &col [[buffer(0)]],
+ texture2d<float> tex [[texture(0)]],
+ sampler s [[sampler(0)]])
+{
+ return tex.sample(s, vert.texcoord) * col;
+}
+
+struct YUVDecode
+{
+ float3 offset;
+ float3 Rcoeff;
+ float3 Gcoeff;
+ float3 Bcoeff;
+};
+
+fragment float4 SDL_YUV_fragment(CopyVertexOutput vert [[stage_in]],
+ constant float4 &col [[buffer(0)]],
+ constant YUVDecode &decode [[buffer(1)]],
+ texture2d<float> texY [[texture(0)]],
+ texture2d_array<float> texUV [[texture(1)]],
+ sampler s [[sampler(0)]])
+{
+ float3 yuv;
+ yuv.x = texY.sample(s, vert.texcoord).r;
+ yuv.y = texUV.sample(s, vert.texcoord, 0).r;
+ yuv.z = texUV.sample(s, vert.texcoord, 1).r;
+
+ yuv += decode.offset;
+
+ return col * float4(dot(yuv, decode.Rcoeff), dot(yuv, decode.Gcoeff), dot(yuv, decode.Bcoeff), 1.0);
+}
+
+fragment float4 SDL_NV12_fragment(CopyVertexOutput vert [[stage_in]],
+ constant float4 &col [[buffer(0)]],
+ constant YUVDecode &decode [[buffer(1)]],
+ texture2d<float> texY [[texture(0)]],
+ texture2d<float> texUV [[texture(1)]],
+ sampler s [[sampler(0)]])
+{
+ float3 yuv;
+ yuv.x = texY.sample(s, vert.texcoord).r;
+ yuv.yz = texUV.sample(s, vert.texcoord).rg;
+
+ yuv += decode.offset;
+
+ return col * float4(dot(yuv, decode.Rcoeff), dot(yuv, decode.Gcoeff), dot(yuv, decode.Bcoeff), 1.0);
+}
+
+fragment float4 SDL_NV21_fragment(CopyVertexOutput vert [[stage_in]],
+ constant float4 &col [[buffer(0)]],
+ constant YUVDecode &decode [[buffer(1)]],
+ texture2d<float> texY [[texture(0)]],
+ texture2d<float> texUV [[texture(1)]],
+ sampler s [[sampler(0)]])
+{
+ float3 yuv;
+ yuv.x = texY.sample(s, vert.texcoord).r;
+ yuv.yz = texUV.sample(s, vert.texcoord).gr;
+
+ yuv += decode.offset;
+
+ return col * float4(dot(yuv, decode.Rcoeff), dot(yuv, decode.Gcoeff), dot(yuv, decode.Bcoeff), 1.0);
+}
diff --git a/src/3rdparty/SDL2/src/render/metal/SDL_shaders_metal_ios.h b/src/3rdparty/SDL2/src/render/metal/SDL_shaders_metal_ios.h
new file mode 100644
index 0000000..1c93252
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/metal/SDL_shaders_metal_ios.h
@@ -0,0 +1,1899 @@
+const unsigned char sdl_metallib[] = {
+ 0x4d, 0x54, 0x4c, 0x42, 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xd8, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0x03, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xa8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x18, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x54, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00,
+ 0x4e, 0x41, 0x4d, 0x45, 0x11, 0x00, 0x53, 0x44, 0x4c, 0x5f, 0x53, 0x6f,
+ 0x6c, 0x69, 0x64, 0x5f, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x00, 0x54,
+ 0x59, 0x50, 0x45, 0x01, 0x00, 0x00, 0x48, 0x41, 0x53, 0x48, 0x20, 0x00,
+ 0xa1, 0x91, 0x35, 0x76, 0xce, 0x36, 0x38, 0x71, 0xba, 0x1c, 0x81, 0x62,
+ 0xda, 0x7c, 0x6b, 0x94, 0xc7, 0x88, 0x39, 0xd4, 0x91, 0xc2, 0xe7, 0xf9,
+ 0x21, 0x8c, 0x74, 0x25, 0xa9, 0xb0, 0x81, 0x85, 0x4f, 0x46, 0x46, 0x54,
+ 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x56, 0x45, 0x52, 0x53, 0x08, 0x00, 0x01, 0x00, 0x08, 0x00,
+ 0x01, 0x00, 0x01, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x77, 0x00, 0x00, 0x00,
+ 0x4e, 0x41, 0x4d, 0x45, 0x10, 0x00, 0x53, 0x44, 0x4c, 0x5f, 0x43, 0x6f,
+ 0x70, 0x79, 0x5f, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x00, 0x54, 0x59,
+ 0x50, 0x45, 0x01, 0x00, 0x00, 0x48, 0x41, 0x53, 0x48, 0x20, 0x00, 0x71,
+ 0xbb, 0x07, 0x58, 0x1b, 0x7c, 0x44, 0xaa, 0x03, 0xc8, 0xab, 0x11, 0xe4,
+ 0x63, 0xdb, 0xe3, 0xe6, 0xce, 0x52, 0x97, 0x34, 0x82, 0xf0, 0x46, 0x70,
+ 0xaa, 0xa9, 0x31, 0x51, 0x3c, 0xe8, 0x39, 0x4f, 0x46, 0x46, 0x54, 0x18,
+ 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x56, 0x45, 0x52, 0x53, 0x08, 0x00, 0x01, 0x00, 0x08, 0x00, 0x01,
+ 0x00, 0x01, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x7a, 0x00, 0x00, 0x00, 0x4e,
+ 0x41, 0x4d, 0x45, 0x13, 0x00, 0x53, 0x44, 0x4c, 0x5f, 0x53, 0x6f, 0x6c,
+ 0x69, 0x64, 0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x00,
+ 0x54, 0x59, 0x50, 0x45, 0x01, 0x00, 0x01, 0x48, 0x41, 0x53, 0x48, 0x20,
+ 0x00, 0x4a, 0x07, 0x48, 0xd3, 0xb7, 0x7a, 0x3a, 0x01, 0x6c, 0xaa, 0x80,
+ 0xde, 0x84, 0x6e, 0x3c, 0x9a, 0xdd, 0x55, 0x90, 0x43, 0xa6, 0xdd, 0xbb,
+ 0xd6, 0xeb, 0xea, 0x81, 0x62, 0xf6, 0x50, 0x04, 0x95, 0x4f, 0x46, 0x46,
+ 0x54, 0x18, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x16, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x56, 0x45, 0x52, 0x53, 0x08, 0x00, 0x01, 0x00, 0x08,
+ 0x00, 0x01, 0x00, 0x01, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x79, 0x00, 0x00,
+ 0x00, 0x4e, 0x41, 0x4d, 0x45, 0x12, 0x00, 0x53, 0x44, 0x4c, 0x5f, 0x43,
+ 0x6f, 0x70, 0x79, 0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74,
+ 0x00, 0x54, 0x59, 0x50, 0x45, 0x01, 0x00, 0x01, 0x48, 0x41, 0x53, 0x48,
+ 0x20, 0x00, 0x4c, 0xaa, 0x05, 0x27, 0x1a, 0x40, 0x5c, 0xe3, 0xd5, 0x46,
+ 0x38, 0xad, 0x07, 0xe7, 0x70, 0xdf, 0xde, 0x83, 0x74, 0x96, 0x26, 0x6e,
+ 0x35, 0x7b, 0xc9, 0xc5, 0x46, 0x08, 0x51, 0xb4, 0x13, 0xa8, 0x4f, 0x46,
+ 0x46, 0x54, 0x18, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x1f, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x56, 0x45, 0x52, 0x53, 0x08, 0x00, 0x01, 0x00,
+ 0x08, 0x00, 0x01, 0x00, 0x01, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x78, 0x00,
+ 0x00, 0x00, 0x4e, 0x41, 0x4d, 0x45, 0x11, 0x00, 0x53, 0x44, 0x4c, 0x5f,
+ 0x59, 0x55, 0x56, 0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74,
+ 0x00, 0x54, 0x59, 0x50, 0x45, 0x01, 0x00, 0x01, 0x48, 0x41, 0x53, 0x48,
+ 0x20, 0x00, 0xc9, 0x73, 0x33, 0x9a, 0x36, 0x6d, 0x15, 0x10, 0xa2, 0x81,
+ 0xaa, 0xbf, 0x27, 0xb1, 0x22, 0xc6, 0x0a, 0x7b, 0x68, 0x66, 0xdb, 0xe9,
+ 0xab, 0x19, 0x22, 0x40, 0x87, 0x6b, 0x10, 0x93, 0xc5, 0xf5, 0x4f, 0x46,
+ 0x46, 0x54, 0x18, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x2a, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x56, 0x45, 0x52, 0x53, 0x08, 0x00, 0x01, 0x00,
+ 0x08, 0x00, 0x01, 0x00, 0x01, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x79, 0x00,
+ 0x00, 0x00, 0x4e, 0x41, 0x4d, 0x45, 0x12, 0x00, 0x53, 0x44, 0x4c, 0x5f,
+ 0x4e, 0x56, 0x31, 0x32, 0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e,
+ 0x74, 0x00, 0x54, 0x59, 0x50, 0x45, 0x01, 0x00, 0x01, 0x48, 0x41, 0x53,
+ 0x48, 0x20, 0x00, 0x59, 0x54, 0x77, 0x75, 0xe5, 0xb6, 0xd5, 0x2e, 0xf7,
+ 0xb1, 0x9d, 0xd1, 0x75, 0x39, 0x4c, 0x97, 0x0f, 0x40, 0x58, 0xaa, 0xc9,
+ 0x42, 0xe8, 0x03, 0x29, 0x1e, 0x93, 0x63, 0x0c, 0x91, 0x38, 0xc8, 0x4f,
+ 0x46, 0x46, 0x54, 0x18, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x38, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x45, 0x52, 0x53, 0x08, 0x00, 0x01,
+ 0x00, 0x08, 0x00, 0x01, 0x00, 0x01, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x79,
+ 0x00, 0x00, 0x00, 0x4e, 0x41, 0x4d, 0x45, 0x12, 0x00, 0x53, 0x44, 0x4c,
+ 0x5f, 0x4e, 0x56, 0x32, 0x31, 0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65,
+ 0x6e, 0x74, 0x00, 0x54, 0x59, 0x50, 0x45, 0x01, 0x00, 0x01, 0x48, 0x41,
+ 0x53, 0x48, 0x20, 0x00, 0x77, 0x01, 0x3e, 0x26, 0x2e, 0xc2, 0xe2, 0x34,
+ 0x70, 0xcf, 0x0c, 0x9e, 0x0d, 0xed, 0x69, 0xa4, 0x2a, 0x9c, 0x80, 0x06,
+ 0x52, 0xd1, 0x4b, 0x77, 0x6d, 0xda, 0x29, 0x27, 0x51, 0x25, 0xf4, 0x92,
+ 0x4f, 0x46, 0x46, 0x54, 0x18, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x46,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x45, 0x52, 0x53, 0x08, 0x00,
+ 0x01, 0x00, 0x08, 0x00, 0x01, 0x00, 0x01, 0x00, 0x45, 0x4e, 0x44, 0x54,
+ 0x04, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x04, 0x00, 0x00, 0x00,
+ 0x45, 0x4e, 0x44, 0x54, 0x04, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x44, 0x54,
+ 0x04, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x04, 0x00, 0x00, 0x00,
+ 0x45, 0x4e, 0x44, 0x54, 0x04, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x44, 0x54,
+ 0x04, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x04, 0x00, 0x00, 0x00,
+ 0x45, 0x4e, 0x44, 0x54, 0x04, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x44, 0x54,
+ 0x04, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x04, 0x00, 0x00, 0x00,
+ 0x45, 0x4e, 0x44, 0x54, 0x04, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x44, 0x54,
+ 0x04, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x04, 0x00, 0x00, 0x00,
+ 0x45, 0x4e, 0x44, 0x54, 0xde, 0xc0, 0x17, 0x0b, 0x00, 0x00, 0x00, 0x00,
+ 0x14, 0x00, 0x00, 0x00, 0x30, 0x0b, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+ 0x42, 0x43, 0xc0, 0xde, 0x21, 0x0c, 0x00, 0x00, 0xc9, 0x02, 0x00, 0x00,
+ 0x0b, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00,
+ 0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39,
+ 0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19, 0x1e, 0x04, 0x8b, 0x62,
+ 0x80, 0x14, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42, 0xa4, 0x10, 0x32, 0x14,
+ 0x38, 0x08, 0x18, 0x49, 0x0a, 0x32, 0x44, 0x24, 0x48, 0x0a, 0x90, 0x21,
+ 0x23, 0xc4, 0x52, 0x80, 0x0c, 0x19, 0x21, 0x72, 0x24, 0x07, 0xc8, 0x48,
+ 0x11, 0x62, 0xa8, 0xa0, 0xa8, 0x40, 0xc6, 0xf0, 0x01, 0x00, 0x00, 0x00,
+ 0x51, 0x18, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x1b, 0x8c, 0x20, 0x00,
+ 0x16, 0xa0, 0xda, 0x60, 0x08, 0x02, 0xb0, 0x00, 0xd5, 0x06, 0x63, 0x18,
+ 0x80, 0x05, 0xa8, 0x36, 0x90, 0x0b, 0xf1, 0xff, 0xff, 0xff, 0xff, 0x03,
+ 0x20, 0x01, 0x15, 0x31, 0x0e, 0xef, 0x20, 0x0f, 0xf2, 0x50, 0x0e, 0xe3,
+ 0x40, 0x0f, 0xec, 0x90, 0x0f, 0x6d, 0x20, 0x0f, 0xef, 0x50, 0x0f, 0xee,
+ 0x40, 0x0e, 0xe5, 0x40, 0x0e, 0x6d, 0x40, 0x0e, 0xe9, 0x60, 0x0f, 0xe9,
+ 0x40, 0x0e, 0xe5, 0xd0, 0x06, 0xf3, 0x10, 0x0f, 0xf2, 0x40, 0x0f, 0x6d,
+ 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x80,
+ 0x39, 0x84, 0x03, 0x3b, 0xcc, 0x43, 0x39, 0x00, 0x04, 0x39, 0xa4, 0xc3,
+ 0x3c, 0x84, 0x83, 0x38, 0xb0, 0x43, 0x39, 0xb4, 0x01, 0x3d, 0x84, 0x43,
+ 0x3a, 0xb0, 0x43, 0x1b, 0x8c, 0x43, 0x38, 0xb0, 0x03, 0x3b, 0xcc, 0x03,
+ 0x60, 0x0e, 0xe1, 0xc0, 0x0e, 0xf3, 0x50, 0x0e, 0x00, 0xc1, 0x0e, 0xe5,
+ 0x30, 0x0f, 0xf3, 0xd0, 0x06, 0xf0, 0x20, 0x0f, 0xe5, 0x30, 0x0e, 0xe9,
+ 0x30, 0x0f, 0xe5, 0xd0, 0x06, 0xe6, 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xe4,
+ 0x00, 0xd0, 0x83, 0x3c, 0xd4, 0x43, 0x39, 0x00, 0x84, 0x3b, 0xbc, 0x43,
+ 0x1b, 0x98, 0x83, 0x3c, 0x84, 0x43, 0x3b, 0x94, 0x43, 0x1b, 0xc0, 0xc3,
+ 0x3b, 0xa4, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xc8, 0x43, 0x1b, 0x94, 0x03,
+ 0x3b, 0xa4, 0x43, 0x3b, 0x00, 0xf4, 0x20, 0x0f, 0xf5, 0x50, 0x0e, 0xc0,
+ 0xe0, 0x0e, 0xef, 0xd0, 0x06, 0xe6, 0x20, 0x0f, 0xe1, 0xd0, 0x0e, 0xe5,
+ 0xd0, 0x06, 0xf0, 0xf0, 0x0e, 0xe9, 0xe0, 0x0e, 0xf4, 0x50, 0x0e, 0xf2,
+ 0xd0, 0x06, 0xe5, 0xc0, 0x0e, 0xe9, 0xd0, 0x0e, 0x6d, 0xe0, 0x0e, 0xef,
+ 0xe0, 0x0e, 0x6d, 0xc0, 0x0e, 0xe5, 0x10, 0x0e, 0xe6, 0x00, 0x10, 0xee,
+ 0xf0, 0x0e, 0x6d, 0x90, 0x0e, 0xee, 0x60, 0x0e, 0xf3, 0xd0, 0x06, 0xe6,
+ 0x00, 0x0f, 0x6d, 0xd0, 0x0e, 0xe1, 0x40, 0x0f, 0xe8, 0x00, 0xd0, 0x83,
+ 0x3c, 0xd4, 0x43, 0x39, 0x00, 0x84, 0x3b, 0xbc, 0x43, 0x1b, 0xa8, 0x43,
+ 0x3d, 0xb4, 0x03, 0x3c, 0xb4, 0x01, 0x3d, 0x84, 0x83, 0x38, 0xb0, 0x43,
+ 0x39, 0xcc, 0x03, 0x60, 0x0e, 0xe1, 0xc0, 0x0e, 0xf3, 0x50, 0x0e, 0x00,
+ 0xe1, 0x0e, 0xef, 0xd0, 0x06, 0xee, 0x10, 0x0e, 0xee, 0x30, 0x0f, 0x6d,
+ 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x00,
+ 0x3d, 0xc8, 0x43, 0x3d, 0x94, 0x03, 0x40, 0xb8, 0xc3, 0x3b, 0xb4, 0xc1,
+ 0x3c, 0xa4, 0xc3, 0x39, 0xb8, 0x43, 0x39, 0x90, 0x43, 0x1b, 0xe8, 0x43,
+ 0x39, 0xc8, 0xc3, 0x3b, 0xcc, 0x43, 0x1b, 0x98, 0x03, 0x3c, 0xb4, 0x41,
+ 0x3b, 0x84, 0x03, 0x3d, 0xa0, 0x03, 0x60, 0x0e, 0xe1, 0xc0, 0x0e, 0xf3,
+ 0x50, 0x0e, 0x00, 0x31, 0x0f, 0xf4, 0x10, 0x0e, 0xe3, 0xb0, 0x0e, 0x6d,
+ 0x00, 0x0f, 0xf2, 0xf0, 0x0e, 0xf4, 0x50, 0x0e, 0xe3, 0x40, 0x0f, 0xef,
+ 0x20, 0x0f, 0x6d, 0x20, 0x0e, 0xf5, 0x60, 0x0e, 0xe6, 0x50, 0x0e, 0xf2,
+ 0xd0, 0x06, 0xf3, 0x90, 0x0e, 0xfa, 0x50, 0x0e, 0x00, 0x1e, 0x00, 0x04,
+ 0x3d, 0x84, 0x83, 0x3c, 0x9c, 0x43, 0x39, 0xd0, 0x43, 0x1b, 0x98, 0x43,
+ 0x39, 0x84, 0x03, 0x3d, 0xd4, 0x83, 0x3c, 0x94, 0xc3, 0x3c, 0x00, 0x6d,
+ 0x60, 0x0e, 0xf0, 0x10, 0x07, 0x76, 0x00, 0x10, 0xf5, 0xe0, 0x0e, 0xf3,
+ 0x10, 0x0e, 0xe6, 0x50, 0x0e, 0x6d, 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed,
+ 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x00, 0x3d, 0xc8, 0x43, 0x3d, 0x94, 0x03,
+ 0x40, 0xd4, 0xc3, 0x3c, 0x94, 0x43, 0x1b, 0xcc, 0xc3, 0x3b, 0x98, 0x03,
+ 0x3d, 0xb4, 0x81, 0x39, 0xb0, 0xc3, 0x3b, 0x84, 0x03, 0x3d, 0x00, 0xe6,
+ 0x10, 0x0e, 0xec, 0x30, 0x0f, 0xe5, 0x00, 0x00, 0x49, 0x18, 0x00, 0x00,
+ 0x02, 0x00, 0x00, 0x00, 0x13, 0x88, 0x40, 0x18, 0x08, 0x00, 0x00, 0x00,
+ 0x89, 0x20, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09,
+ 0x20, 0x64, 0x85, 0x04, 0x93, 0x22, 0xa4, 0x84, 0x04, 0x93, 0x22, 0xe3,
+ 0x84, 0xa1, 0x90, 0x14, 0x12, 0x4c, 0x8a, 0x8c, 0x0b, 0x84, 0xa4, 0x4c,
+ 0x10, 0x50, 0x33, 0x00, 0xc3, 0x08, 0x04, 0x70, 0x9f, 0x34, 0x45, 0x94,
+ 0x30, 0xf9, 0xac, 0xb3, 0x20, 0xc3, 0x4b, 0x44, 0x13, 0x71, 0xa1, 0xd4,
+ 0xf4, 0x50, 0x93, 0xff, 0x00, 0x82, 0x42, 0x0c, 0x58, 0x08, 0x60, 0x18,
+ 0x41, 0x00, 0x06, 0x11, 0x86, 0x20, 0x09, 0xc2, 0x4c, 0xd3, 0x38, 0xb0,
+ 0x43, 0x38, 0xcc, 0xc3, 0x3c, 0xb8, 0x41, 0x3b, 0x94, 0x03, 0x3d, 0x84,
+ 0x03, 0x3b, 0xe8, 0x81, 0x1e, 0xb4, 0x43, 0x38, 0xd0, 0x83, 0x3c, 0xa4,
+ 0x03, 0x3e, 0xa0, 0xa0, 0x0c, 0x22, 0x18, 0xc2, 0x1c, 0x01, 0x18, 0x94,
+ 0x42, 0x90, 0x73, 0x10, 0xa5, 0x81, 0x00, 0x32, 0x73, 0x04, 0xa0, 0x30,
+ 0x88, 0x10, 0x08, 0x53, 0x00, 0x23, 0x00, 0xc3, 0x08, 0x04, 0x32, 0x47,
+ 0x10, 0x50, 0x00, 0x00, 0x13, 0xa8, 0x70, 0x48, 0x07, 0x79, 0xb0, 0x03,
+ 0x3a, 0x68, 0x83, 0x70, 0x80, 0x07, 0x78, 0x60, 0x87, 0x72, 0x68, 0x83,
+ 0x74, 0x78, 0x87, 0x79, 0xc8, 0x03, 0x37, 0x80, 0x03, 0x37, 0x80, 0x83,
+ 0x0d, 0xef, 0x51, 0x0e, 0x6d, 0x00, 0x0f, 0x7a, 0x60, 0x07, 0x74, 0xa0,
+ 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe9, 0x10,
+ 0x07, 0x7a, 0x80, 0x07, 0x7a, 0x80, 0x07, 0x6d, 0x90, 0x0e, 0x78, 0xa0,
+ 0x07, 0x78, 0xa0, 0x07, 0x78, 0xd0, 0x06, 0xe9, 0x10, 0x07, 0x76, 0xa0,
+ 0x07, 0x71, 0x60, 0x07, 0x7a, 0x10, 0x07, 0x76, 0xd0, 0x06, 0xe9, 0x30,
+ 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0,
+ 0x06, 0xe9, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60,
+ 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20,
+ 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xe6, 0x60, 0x07, 0x74, 0xa0,
+ 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x80,
+ 0x07, 0x70, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20,
+ 0x07, 0x78, 0xd0, 0x06, 0xf6, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x60,
+ 0x07, 0x7a, 0x10, 0x07, 0x76, 0xd0, 0x06, 0xf6, 0x20, 0x07, 0x74, 0xa0,
+ 0x07, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xf6, 0x30,
+ 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0,
+ 0x06, 0xf6, 0x40, 0x07, 0x78, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60,
+ 0x07, 0x74, 0xd0, 0x06, 0xf6, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40,
+ 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xf6, 0x90, 0x07, 0x76, 0xa0,
+ 0x07, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0,
+ 0x06, 0xf6, 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80,
+ 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x90,
+ 0x07, 0x72, 0xa0, 0x07, 0x72, 0x50, 0x07, 0x76, 0xa0, 0x07, 0x72, 0x50,
+ 0x07, 0x76, 0xd0, 0x06, 0xf6, 0x20, 0x07, 0x75, 0x60, 0x07, 0x7a, 0x20,
+ 0x07, 0x75, 0x60, 0x07, 0x7a, 0x20, 0x07, 0x75, 0x60, 0x07, 0x6d, 0x60,
+ 0x0f, 0x75, 0x10, 0x07, 0x72, 0xa0, 0x07, 0x75, 0x10, 0x07, 0x72, 0xa0,
+ 0x07, 0x75, 0x10, 0x07, 0x72, 0xd0, 0x06, 0xf6, 0x10, 0x07, 0x70, 0x20,
+ 0x07, 0x74, 0xa0, 0x07, 0x71, 0x00, 0x07, 0x72, 0x40, 0x07, 0x7a, 0x10,
+ 0x07, 0x70, 0x20, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x80, 0x07, 0x70, 0xa0,
+ 0x07, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0,
+ 0x06, 0xee, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x73, 0x20,
+ 0x07, 0x43, 0x18, 0x05, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
+ 0x2c, 0x10, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x10,
+ 0x19, 0x11, 0x4c, 0x90, 0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0x42,
+ 0x25, 0x30, 0x02, 0x50, 0x80, 0x01, 0x05, 0x51, 0x04, 0x05, 0x52, 0x06,
+ 0xd4, 0x46, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00,
+ 0x1a, 0x03, 0x4c, 0x10, 0xd7, 0x20, 0x08, 0x0e, 0x8e, 0xad, 0x0c, 0x84,
+ 0x89, 0xc9, 0xaa, 0x09, 0xc4, 0xae, 0x4c, 0x6e, 0x2e, 0xed, 0xcd, 0x0d,
+ 0x04, 0x07, 0x46, 0xc6, 0x25, 0x06, 0x04, 0xa5, 0xad, 0x8c, 0x2e, 0x8c,
+ 0xcd, 0xac, 0xac, 0x05, 0x07, 0x46, 0xc6, 0x25, 0xc6, 0x65, 0x86, 0x26,
+ 0x65, 0x88, 0xb0, 0x00, 0x43, 0x0c, 0x24, 0x40, 0x08, 0x44, 0x60, 0xd1,
+ 0x54, 0x46, 0x17, 0xc6, 0x36, 0x04, 0x59, 0x06, 0x24, 0x40, 0x02, 0x44,
+ 0xe0, 0x16, 0x96, 0x26, 0xe7, 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56,
+ 0xe6, 0x42, 0x56, 0xe6, 0xf6, 0x26, 0xd7, 0x36, 0xf7, 0x45, 0x96, 0x36,
+ 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0x58, 0x0a, 0x72, 0x61, 0x69, 0x72,
+ 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x2e, 0x66, 0x61, 0x73,
+ 0x74, 0x5f, 0x6d, 0x61, 0x74, 0x68, 0x5f, 0x65, 0x6e, 0x61, 0x62, 0x6c,
+ 0x65, 0x43, 0x84, 0xe5, 0x20, 0x19, 0x84, 0xa5, 0xc9, 0xb9, 0x8c, 0xbd,
+ 0xb5, 0xc1, 0xa5, 0xb1, 0x95, 0xb9, 0x98, 0xc9, 0x85, 0xb5, 0x95, 0x89,
+ 0xd5, 0x99, 0x99, 0x95, 0xc9, 0x7d, 0x99, 0x95, 0xd1, 0x8d, 0xa1, 0x7d,
+ 0x95, 0xb9, 0x85, 0x89, 0xb1, 0x95, 0x0d, 0x11, 0x96, 0x84, 0x61, 0x10,
+ 0x96, 0x26, 0xe7, 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56, 0xe6, 0xe2,
+ 0x16, 0x46, 0x97, 0x66, 0x57, 0xf6, 0x45, 0xf6, 0x56, 0x27, 0xc6, 0x56,
+ 0xf6, 0x45, 0x96, 0x36, 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0x58, 0x16,
+ 0x32, 0x61, 0x69, 0x72, 0x2e, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f,
+ 0x6e, 0x8c, 0xc2, 0xd2, 0xe4, 0x5c, 0xc2, 0xe4, 0xce, 0xbe, 0xe8, 0xf2,
+ 0xe0, 0xca, 0xbe, 0xdc, 0xc2, 0xda, 0xca, 0x68, 0x98, 0xb1, 0xbd, 0x85,
+ 0xd1, 0xd1, 0x90, 0x09, 0x4b, 0x93, 0x73, 0x09, 0x93, 0x3b, 0xfb, 0x72,
+ 0x0b, 0x6b, 0x2b, 0x23, 0x02, 0xf7, 0x36, 0x97, 0x46, 0x97, 0xf6, 0xe6,
+ 0x36, 0x44, 0x59, 0x9a, 0xc5, 0x59, 0x9e, 0x05, 0x5a, 0x22, 0x3a, 0x61,
+ 0x69, 0x72, 0x2e, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x73, 0x69, 0x7a,
+ 0x65, 0x2c, 0xcc, 0xd8, 0xde, 0xc2, 0xe8, 0x98, 0xc0, 0xbd, 0xa5, 0xb9,
+ 0xd1, 0x4d, 0xa5, 0xe9, 0x95, 0x0d, 0x51, 0x96, 0x69, 0x71, 0x16, 0x6a,
+ 0x81, 0x96, 0x6a, 0x08, 0xb1, 0x48, 0x8b, 0x45, 0x25, 0x2c, 0x4d, 0xce,
+ 0x45, 0xac, 0xce, 0xcc, 0xac, 0x4c, 0x8e, 0x52, 0x58, 0x9a, 0x9c, 0x0b,
+ 0xdb, 0xdb, 0x58, 0x18, 0x5d, 0xda, 0x9b, 0xdb, 0x57, 0x9a, 0x1b, 0x59,
+ 0x19, 0x1e, 0x91, 0xb0, 0x34, 0x39, 0x17, 0xb9, 0xb2, 0x30, 0x32, 0x46,
+ 0x61, 0x69, 0x72, 0x2e, 0x61, 0x72, 0x67, 0x5f, 0x74, 0x79, 0x70, 0x65,
+ 0x5f, 0x73, 0x69, 0x7a, 0x65, 0xbc, 0xc2, 0xd2, 0xe4, 0x5c, 0xc2, 0xe4,
+ 0xce, 0xbe, 0xe8, 0xf2, 0xe0, 0xca, 0xbe, 0xc2, 0xd8, 0xd2, 0xce, 0xdc,
+ 0xbe, 0xe6, 0xd2, 0xf4, 0xca, 0x68, 0x98, 0xb1, 0xbd, 0x85, 0xd1, 0xc9,
+ 0x0c, 0xe1, 0x10, 0x61, 0xc1, 0x96, 0x0c, 0x11, 0x90, 0x60, 0xd1, 0x96,
+ 0x0d, 0x21, 0x16, 0x0e, 0x21, 0x16, 0x67, 0xe9, 0x16, 0x68, 0x89, 0xf8,
+ 0x84, 0xa5, 0xc9, 0xb9, 0x88, 0xd5, 0x99, 0x99, 0x95, 0xc9, 0x7d, 0xcd,
+ 0xa5, 0xe9, 0x95, 0x11, 0x31, 0x63, 0x7b, 0x0b, 0xa3, 0xa3, 0xc1, 0xa3,
+ 0xa1, 0x02, 0x27, 0xf7, 0xa6, 0x56, 0x36, 0x46, 0x97, 0xf6, 0xe6, 0x36,
+ 0x04, 0x0c, 0x90, 0x60, 0xc1, 0x96, 0x0f, 0x19, 0x96, 0x0c, 0x29, 0x90,
+ 0x60, 0xd1, 0x96, 0x0d, 0x19, 0x16, 0x0e, 0x31, 0x16, 0x67, 0x01, 0x83,
+ 0x05, 0x5a, 0xc2, 0x80, 0x09, 0x9d, 0x5c, 0x98, 0xdb, 0x9c, 0xd9, 0x9b,
+ 0x5c, 0xdb, 0x10, 0x30, 0x40, 0x8a, 0x05, 0x5b, 0x3e, 0x64, 0x58, 0x32,
+ 0xe4, 0x40, 0x82, 0x45, 0x5b, 0x36, 0x64, 0x58, 0x38, 0xc4, 0x58, 0x9c,
+ 0x05, 0x0c, 0x16, 0x68, 0x19, 0x03, 0x36, 0x61, 0x69, 0x72, 0x2e, 0x76,
+ 0x65, 0x72, 0x74, 0x65, 0x78, 0x5f, 0x69, 0x64, 0x24, 0xea, 0xd2, 0xdc,
+ 0xe8, 0x38, 0xd8, 0xa5, 0x91, 0x0d, 0x61, 0x90, 0x63, 0x29, 0x83, 0xc5,
+ 0x59, 0xcc, 0x60, 0x81, 0x96, 0x33, 0x18, 0x82, 0x2c, 0xde, 0x22, 0x06,
+ 0x0b, 0x19, 0x2c, 0x68, 0x30, 0xc4, 0x50, 0x80, 0xe5, 0x5a, 0xd2, 0x80,
+ 0xcf, 0x5b, 0x9b, 0x5b, 0x1a, 0xdc, 0x1b, 0x5d, 0x99, 0x1b, 0x1d, 0xc8,
+ 0x18, 0x5a, 0x98, 0x1c, 0x9f, 0xa9, 0xb4, 0x36, 0x38, 0xb6, 0x32, 0x90,
+ 0xa1, 0x95, 0x15, 0x10, 0x2a, 0xa1, 0xa0, 0xa0, 0x21, 0xc2, 0xc2, 0x06,
+ 0x43, 0x8c, 0x65, 0x0d, 0x96, 0x36, 0x68, 0x90, 0x21, 0xc6, 0xe2, 0x06,
+ 0x8b, 0x1b, 0x34, 0xc8, 0x08, 0x85, 0x1d, 0xd8, 0xc1, 0x1e, 0xda, 0xc1,
+ 0x0d, 0xd2, 0x81, 0x1c, 0xca, 0xc1, 0x1d, 0xe8, 0x61, 0x4a, 0x10, 0x8c,
+ 0x58, 0xc2, 0x21, 0x1d, 0xe4, 0xc1, 0x0d, 0xec, 0xa1, 0x1c, 0xe4, 0x61,
+ 0x1e, 0xd2, 0xe1, 0x1d, 0xdc, 0x61, 0x4a, 0x20, 0x8c, 0xa0, 0xc2, 0x21,
+ 0x1d, 0xe4, 0xc1, 0x0d, 0xd8, 0x21, 0x1c, 0xdc, 0xe1, 0x1c, 0xea, 0x21,
+ 0x1c, 0xce, 0xa1, 0x1c, 0x7e, 0xc1, 0x1e, 0xca, 0x41, 0x1e, 0xe6, 0x21,
+ 0x1d, 0xde, 0xc1, 0x1d, 0xa6, 0x04, 0xc4, 0x88, 0x29, 0x1c, 0xd2, 0x41,
+ 0x1e, 0xdc, 0x60, 0x1c, 0xde, 0xa1, 0x1d, 0xe0, 0x21, 0x1d, 0xd8, 0xa1,
+ 0x1c, 0x7e, 0xe1, 0x1d, 0xe0, 0x81, 0x1e, 0xd2, 0xe1, 0x1d, 0xdc, 0x61,
+ 0x1e, 0xa6, 0x10, 0x06, 0xa2, 0x30, 0x23, 0x94, 0x70, 0x48, 0x07, 0x79,
+ 0x70, 0x03, 0x7b, 0x28, 0x07, 0x79, 0xa0, 0x87, 0x72, 0xc0, 0x87, 0x29,
+ 0x81, 0x1a, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00,
+ 0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66, 0x14, 0x01, 0x3d, 0x88,
+ 0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07, 0x79, 0x78, 0x07, 0x73,
+ 0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e,
+ 0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce, 0xa1, 0x1c, 0x66, 0x30,
+ 0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b, 0xcc, 0x03, 0x3d, 0xc8,
+ 0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c, 0x74, 0x70, 0x07, 0x7b,
+ 0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07, 0x7a, 0x70, 0x03, 0x76,
+ 0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11, 0x0e, 0xec, 0x90, 0x0e,
+ 0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0, 0x0e, 0xf0, 0x50, 0x0e,
+ 0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8, 0x21, 0x1d, 0xc2, 0x61,
+ 0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xb4,
+ 0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b, 0xcc, 0xf0, 0x14, 0x76,
+ 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87, 0x72, 0x68, 0x07, 0x37,
+ 0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07, 0x76, 0x28, 0x07, 0x76,
+ 0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87, 0x5f, 0x08, 0x87, 0x71,
+ 0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81, 0x2c, 0xee, 0xf0, 0x0e,
+ 0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30, 0x03, 0x62, 0xc8, 0xa1,
+ 0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xdc, 0x61,
+ 0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca, 0x61, 0x06, 0xd6, 0x90,
+ 0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39, 0xc8, 0x43, 0x39, 0xb8,
+ 0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b, 0x94, 0xc3, 0x2f, 0xbc,
+ 0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b, 0xb0, 0xc3, 0x0c, 0xc7,
+ 0x69, 0x87, 0x70, 0x58, 0x87, 0x72, 0x70, 0x83, 0x74, 0x68, 0x07, 0x78,
+ 0x60, 0x87, 0x74, 0x18, 0x87, 0x74, 0xa0, 0x87, 0x19, 0xce, 0x53, 0x0f,
+ 0xee, 0x00, 0x0f, 0xf2, 0x50, 0x0e, 0xe4, 0x90, 0x0e, 0xe3, 0x40, 0x0f,
+ 0xe1, 0x20, 0x0e, 0xec, 0x50, 0x0e, 0x33, 0x20, 0x28, 0x1d, 0xdc, 0xc1,
+ 0x1e, 0xc2, 0x41, 0x1e, 0xd2, 0x21, 0x1c, 0xdc, 0x81, 0x1e, 0xdc, 0xe0,
+ 0x1c, 0xe4, 0xe1, 0x1d, 0xea, 0x01, 0x1e, 0x66, 0x18, 0x51, 0x38, 0xb0,
+ 0x43, 0x3a, 0x9c, 0x83, 0x3b, 0xcc, 0x50, 0x24, 0x76, 0x60, 0x07, 0x7b,
+ 0x68, 0x07, 0x37, 0x60, 0x87, 0x77, 0x78, 0x07, 0x78, 0x98, 0x51, 0x4c,
+ 0xf4, 0x90, 0x0f, 0xf0, 0x50, 0x0e, 0x00, 0x00, 0x71, 0x20, 0x00, 0x00,
+ 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0xb1, 0x5d, 0xf9, 0xb3, 0xce, 0x82,
+ 0x0c, 0x7f, 0x45, 0x44, 0x13, 0x71, 0x01, 0x00, 0x61, 0x20, 0x00, 0x00,
+ 0x69, 0x00, 0x00, 0x00, 0x13, 0x04, 0x47, 0x2c, 0x10, 0x00, 0x00, 0x00,
+ 0x0a, 0x00, 0x00, 0x00, 0x14, 0xe7, 0x20, 0x84, 0x60, 0x9a, 0x46, 0x00,
+ 0xa8, 0x95, 0x41, 0x11, 0x94, 0x00, 0xa1, 0x42, 0x98, 0x01, 0xa0, 0x31,
+ 0x03, 0x40, 0x62, 0x06, 0x80, 0xc2, 0x0c, 0x00, 0x81, 0x11, 0x80, 0x31,
+ 0x02, 0x10, 0x04, 0x41, 0xfc, 0x03, 0x00, 0x00, 0x33, 0x11, 0x0c, 0x12,
+ 0x14, 0x33, 0x11, 0x0c, 0x12, 0x14, 0xe3, 0x11, 0xd1, 0x94, 0x4d, 0x14,
+ 0x94, 0x59, 0x82, 0x60, 0xa0, 0x02, 0xb1, 0x03, 0xe0, 0x0c, 0x86, 0x0b,
+ 0x9a, 0x8c, 0x47, 0x50, 0x57, 0x17, 0x50, 0x50, 0x06, 0x19, 0x82, 0x65,
+ 0xb2, 0xc0, 0x90, 0xcf, 0x2c, 0x81, 0x30, 0x50, 0x81, 0x90, 0x42, 0x50,
+ 0x09, 0x03, 0x15, 0x01, 0x11, 0x44, 0xc2, 0x18, 0x42, 0x21, 0xcc, 0x31,
+ 0x40, 0x01, 0x19, 0x0c, 0x32, 0x04, 0x51, 0x76, 0x45, 0x93, 0xf1, 0x88,
+ 0x2f, 0x0c, 0xce, 0x20, 0xa0, 0xa0, 0x58, 0x40, 0xc8, 0xc7, 0x02, 0x04,
+ 0x3e, 0xa6, 0xb0, 0x01, 0x0c, 0x86, 0x1b, 0x02, 0x0e, 0x0c, 0x66, 0x19,
+ 0x06, 0x21, 0x18, 0x8f, 0xb0, 0xce, 0xa0, 0x0d, 0xa2, 0xc1, 0x88, 0x80,
+ 0x28, 0x00, 0x9b, 0xde, 0x00, 0x06, 0xc3, 0x0d, 0xc1, 0x07, 0x06, 0xb3,
+ 0x0c, 0x44, 0x10, 0x8c, 0x47, 0x64, 0x6a, 0x00, 0x07, 0x6a, 0x40, 0x41,
+ 0x19, 0x8f, 0xd8, 0xd8, 0x40, 0x0e, 0xc6, 0x80, 0x82, 0x32, 0x1e, 0xd1,
+ 0xb9, 0x01, 0x1d, 0x98, 0x01, 0x05, 0x65, 0x3c, 0xe2, 0x83, 0x03, 0x3b,
+ 0x48, 0x03, 0x0a, 0xca, 0x78, 0x04, 0x18, 0xc8, 0x01, 0x1e, 0xc8, 0xc1,
+ 0x60, 0x44, 0x80, 0x14, 0xc0, 0x78, 0x44, 0x18, 0xcc, 0x41, 0x1e, 0xa8,
+ 0xc1, 0x60, 0x44, 0x70, 0x14, 0xc0, 0x78, 0x84, 0x18, 0xd0, 0x81, 0x1e,
+ 0xb0, 0xc1, 0x60, 0x44, 0x60, 0x14, 0xc0, 0x78, 0xc4, 0x18, 0xd4, 0xc1,
+ 0x1e, 0xb8, 0xc1, 0x60, 0x44, 0x50, 0x14, 0xc0, 0xc9, 0x41, 0x8b, 0xf1,
+ 0x04, 0x3b, 0x08, 0x28, 0x20, 0x83, 0x0c, 0x41, 0x1b, 0xd0, 0xc1, 0x1c,
+ 0x43, 0xb0, 0x06, 0x7d, 0x30, 0xc7, 0x10, 0xac, 0x01, 0x1f, 0x0c, 0x32,
+ 0x04, 0x6e, 0x60, 0x07, 0x16, 0x48, 0xf2, 0x99, 0x25, 0x28, 0x06, 0x2a,
+ 0x10, 0x95, 0x20, 0xaa, 0x62, 0xa0, 0x22, 0x20, 0x88, 0xa8, 0x18, 0x43,
+ 0x28, 0x84, 0x39, 0x86, 0x39, 0x08, 0x4e, 0x61, 0x90, 0x21, 0xa0, 0x03,
+ 0x3e, 0xb8, 0xa2, 0xc9, 0x78, 0x84, 0x1c, 0x90, 0x82, 0x2a, 0x04, 0x14,
+ 0x14, 0x0b, 0x08, 0xf9, 0x58, 0x80, 0xc0, 0xc7, 0x94, 0x57, 0x80, 0xc1,
+ 0x70, 0x43, 0xf0, 0x07, 0x60, 0x30, 0xcb, 0x60, 0x14, 0xc1, 0x6c, 0x43,
+ 0x1f, 0x0c, 0xc0, 0x6c, 0x43, 0xb0, 0x07, 0x41, 0x06, 0x01, 0x31, 0x00,
+ 0x08, 0x00, 0x00, 0x00, 0x5b, 0x86, 0x21, 0x78, 0x83, 0x2d, 0x03, 0x12,
+ 0xbc, 0xc1, 0x96, 0x61, 0x0a, 0xde, 0x60, 0xcb, 0xa0, 0x05, 0x6f, 0xb0,
+ 0x65, 0x80, 0x83, 0xe0, 0x0d, 0xb6, 0x0c, 0x7e, 0x10, 0xbc, 0x01, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xde, 0xc0, 0x17, 0x0b,
+ 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x88, 0x0b, 0x00, 0x00,
+ 0xff, 0xff, 0xff, 0xff, 0x42, 0x43, 0xc0, 0xde, 0x21, 0x0c, 0x00, 0x00,
+ 0xdf, 0x02, 0x00, 0x00, 0x0b, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x12, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49,
+ 0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19,
+ 0x1e, 0x04, 0x8b, 0x62, 0x80, 0x14, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42,
+ 0xa4, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x49, 0x0a, 0x32, 0x44, 0x24,
+ 0x48, 0x0a, 0x90, 0x21, 0x23, 0xc4, 0x52, 0x80, 0x0c, 0x19, 0x21, 0x72,
+ 0x24, 0x07, 0xc8, 0x48, 0x11, 0x62, 0xa8, 0xa0, 0xa8, 0x40, 0xc6, 0xf0,
+ 0x01, 0x00, 0x00, 0x00, 0x51, 0x18, 0x00, 0x00, 0x86, 0x00, 0x00, 0x00,
+ 0x1b, 0x8c, 0x20, 0x00, 0x16, 0xa0, 0xda, 0x60, 0x08, 0x02, 0xb0, 0x00,
+ 0xd5, 0x06, 0x63, 0x18, 0x80, 0x05, 0xa8, 0x36, 0x18, 0x04, 0x01, 0x2c,
+ 0x40, 0xb5, 0x81, 0x5c, 0x8a, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x09,
+ 0xa8, 0x88, 0x71, 0x78, 0x07, 0x79, 0x90, 0x87, 0x72, 0x18, 0x07, 0x7a,
+ 0x60, 0x87, 0x7c, 0x68, 0x03, 0x79, 0x78, 0x87, 0x7a, 0x70, 0x07, 0x72,
+ 0x28, 0x07, 0x72, 0x68, 0x03, 0x72, 0x48, 0x07, 0x7b, 0x48, 0x07, 0x72,
+ 0x28, 0x87, 0x36, 0x98, 0x87, 0x78, 0x90, 0x07, 0x7a, 0x68, 0x03, 0x73,
+ 0x80, 0x87, 0x36, 0x68, 0x87, 0x70, 0xa0, 0x07, 0x74, 0x00, 0xcc, 0x21,
+ 0x1c, 0xd8, 0x61, 0x1e, 0xca, 0x01, 0x20, 0xc8, 0x21, 0x1d, 0xe6, 0x21,
+ 0x1c, 0xc4, 0x81, 0x1d, 0xca, 0xa1, 0x0d, 0xe8, 0x21, 0x1c, 0xd2, 0x81,
+ 0x1d, 0xda, 0x60, 0x1c, 0xc2, 0x81, 0x1d, 0xd8, 0x61, 0x1e, 0x00, 0x73,
+ 0x08, 0x07, 0x76, 0x98, 0x87, 0x72, 0x00, 0x08, 0x76, 0x28, 0x87, 0x79,
+ 0x98, 0x87, 0x36, 0x80, 0x07, 0x79, 0x28, 0x87, 0x71, 0x48, 0x87, 0x79,
+ 0x28, 0x87, 0x36, 0x30, 0x07, 0x78, 0x68, 0x87, 0x70, 0x20, 0x07, 0x80,
+ 0x1e, 0xe4, 0xa1, 0x1e, 0xca, 0x01, 0x20, 0xdc, 0xe1, 0x1d, 0xda, 0xc0,
+ 0x1c, 0xe4, 0x21, 0x1c, 0xda, 0xa1, 0x1c, 0xda, 0x00, 0x1e, 0xde, 0x21,
+ 0x1d, 0xdc, 0x81, 0x1e, 0xca, 0x41, 0x1e, 0xda, 0xa0, 0x1c, 0xd8, 0x21,
+ 0x1d, 0xda, 0x01, 0xa0, 0x07, 0x79, 0xa8, 0x87, 0x72, 0x00, 0x06, 0x77,
+ 0x78, 0x87, 0x36, 0x30, 0x07, 0x79, 0x08, 0x87, 0x76, 0x28, 0x87, 0x36,
+ 0x80, 0x87, 0x77, 0x48, 0x07, 0x77, 0xa0, 0x87, 0x72, 0x90, 0x87, 0x36,
+ 0x28, 0x07, 0x76, 0x48, 0x87, 0x76, 0x68, 0x03, 0x77, 0x78, 0x07, 0x77,
+ 0x68, 0x03, 0x76, 0x28, 0x87, 0x70, 0x30, 0x07, 0x80, 0x70, 0x87, 0x77,
+ 0x68, 0x83, 0x74, 0x70, 0x07, 0x73, 0x98, 0x87, 0x36, 0x30, 0x07, 0x78,
+ 0x68, 0x83, 0x76, 0x08, 0x07, 0x7a, 0x40, 0x07, 0x80, 0x1e, 0xe4, 0xa1,
+ 0x1e, 0xca, 0x01, 0x20, 0xdc, 0xe1, 0x1d, 0xda, 0x40, 0x1d, 0xea, 0xa1,
+ 0x1d, 0xe0, 0xa1, 0x0d, 0xe8, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca, 0x61,
+ 0x1e, 0x00, 0x73, 0x08, 0x07, 0x76, 0x98, 0x87, 0x72, 0x00, 0x08, 0x77,
+ 0x78, 0x87, 0x36, 0x70, 0x87, 0x70, 0x70, 0x87, 0x79, 0x68, 0x03, 0x73,
+ 0x80, 0x87, 0x36, 0x68, 0x87, 0x70, 0xa0, 0x07, 0x74, 0x00, 0xe8, 0x41,
+ 0x1e, 0xea, 0xa1, 0x1c, 0x00, 0xc2, 0x1d, 0xde, 0xa1, 0x0d, 0xe6, 0x21,
+ 0x1d, 0xce, 0xc1, 0x1d, 0xca, 0x81, 0x1c, 0xda, 0x40, 0x1f, 0xca, 0x41,
+ 0x1e, 0xde, 0x61, 0x1e, 0xda, 0xc0, 0x1c, 0xe0, 0xa1, 0x0d, 0xda, 0x21,
+ 0x1c, 0xe8, 0x01, 0x1d, 0x00, 0x73, 0x08, 0x07, 0x76, 0x98, 0x87, 0x72,
+ 0x00, 0x88, 0x79, 0xa0, 0x87, 0x70, 0x18, 0x87, 0x75, 0x68, 0x03, 0x78,
+ 0x90, 0x87, 0x77, 0xa0, 0x87, 0x72, 0x18, 0x07, 0x7a, 0x78, 0x07, 0x79,
+ 0x68, 0x03, 0x71, 0xa8, 0x07, 0x73, 0x30, 0x87, 0x72, 0x90, 0x87, 0x36,
+ 0x98, 0x87, 0x74, 0xd0, 0x87, 0x72, 0x00, 0xf0, 0x00, 0x20, 0xe8, 0x21,
+ 0x1c, 0xe4, 0xe1, 0x1c, 0xca, 0x81, 0x1e, 0xda, 0xc0, 0x1c, 0xca, 0x21,
+ 0x1c, 0xe8, 0xa1, 0x1e, 0xe4, 0xa1, 0x1c, 0xe6, 0x01, 0x68, 0x03, 0x73,
+ 0x80, 0x87, 0x38, 0xb0, 0x03, 0x80, 0xa8, 0x07, 0x77, 0x98, 0x87, 0x70,
+ 0x30, 0x87, 0x72, 0x68, 0x03, 0x73, 0x80, 0x87, 0x36, 0x68, 0x87, 0x70,
+ 0xa0, 0x07, 0x74, 0x00, 0xe8, 0x41, 0x1e, 0xea, 0xa1, 0x1c, 0x00, 0xa2,
+ 0x1e, 0xe6, 0xa1, 0x1c, 0xda, 0x60, 0x1e, 0xde, 0xc1, 0x1c, 0xe8, 0xa1,
+ 0x0d, 0xcc, 0x81, 0x1d, 0xde, 0x21, 0x1c, 0xe8, 0x01, 0x30, 0x87, 0x70,
+ 0x60, 0x87, 0x79, 0x28, 0x07, 0x00, 0x00, 0x00, 0x49, 0x18, 0x00, 0x00,
+ 0x02, 0x00, 0x00, 0x00, 0x13, 0x8a, 0x40, 0x18, 0x88, 0x02, 0x00, 0x00,
+ 0x89, 0x20, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09,
+ 0x20, 0x64, 0x85, 0x04, 0x93, 0x22, 0xa4, 0x84, 0x04, 0x93, 0x22, 0xe3,
+ 0x84, 0xa1, 0x90, 0x14, 0x12, 0x4c, 0x8a, 0x8c, 0x0b, 0x84, 0xa4, 0x4c,
+ 0x10, 0x50, 0x33, 0x00, 0xc3, 0x08, 0x04, 0x30, 0x8c, 0x20, 0x00, 0xe7,
+ 0x49, 0x53, 0x44, 0x09, 0x93, 0xcf, 0x39, 0x0f, 0xf6, 0x12, 0xd1, 0x44,
+ 0x5c, 0x28, 0x35, 0x3d, 0xd4, 0xe4, 0x3f, 0x80, 0xa0, 0x10, 0x03, 0x16,
+ 0x82, 0x18, 0x44, 0x10, 0x82, 0x24, 0x08, 0x33, 0x4d, 0xe3, 0xc0, 0x0e,
+ 0xe1, 0x30, 0x0f, 0xf3, 0xe0, 0x06, 0xed, 0x50, 0x0e, 0xf4, 0x10, 0x0e,
+ 0xec, 0xa0, 0x07, 0x7a, 0xd0, 0x0e, 0xe1, 0x40, 0x0f, 0xf2, 0x90, 0x0e,
+ 0xf8, 0x80, 0x82, 0x32, 0x88, 0x60, 0x08, 0x73, 0x04, 0x60, 0x50, 0x8c,
+ 0x41, 0xc8, 0x39, 0x88, 0xd2, 0x40, 0x00, 0x99, 0x39, 0x02, 0x50, 0x18,
+ 0x44, 0x08, 0x84, 0x29, 0x80, 0x11, 0x80, 0x61, 0x04, 0x02, 0x99, 0x23,
+ 0x08, 0x28, 0x00, 0x00, 0x13, 0xa8, 0x70, 0x48, 0x07, 0x79, 0xb0, 0x03,
+ 0x3a, 0x68, 0x83, 0x70, 0x80, 0x07, 0x78, 0x60, 0x87, 0x72, 0x68, 0x83,
+ 0x74, 0x78, 0x87, 0x79, 0xc8, 0x03, 0x37, 0x80, 0x03, 0x37, 0x80, 0x83,
+ 0x0d, 0xef, 0x51, 0x0e, 0x6d, 0x00, 0x0f, 0x7a, 0x60, 0x07, 0x74, 0xa0,
+ 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe9, 0x10,
+ 0x07, 0x7a, 0x80, 0x07, 0x7a, 0x80, 0x07, 0x6d, 0x90, 0x0e, 0x78, 0xa0,
+ 0x07, 0x78, 0xa0, 0x07, 0x78, 0xd0, 0x06, 0xe9, 0x10, 0x07, 0x76, 0xa0,
+ 0x07, 0x71, 0x60, 0x07, 0x7a, 0x10, 0x07, 0x76, 0xd0, 0x06, 0xe9, 0x30,
+ 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0,
+ 0x06, 0xe9, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60,
+ 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20,
+ 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xe6, 0x60, 0x07, 0x74, 0xa0,
+ 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x80,
+ 0x07, 0x70, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20,
+ 0x07, 0x78, 0xd0, 0x06, 0xf6, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x60,
+ 0x07, 0x7a, 0x10, 0x07, 0x76, 0xd0, 0x06, 0xf6, 0x20, 0x07, 0x74, 0xa0,
+ 0x07, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xf6, 0x30,
+ 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0,
+ 0x06, 0xf6, 0x40, 0x07, 0x78, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60,
+ 0x07, 0x74, 0xd0, 0x06, 0xf6, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40,
+ 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xf6, 0x90, 0x07, 0x76, 0xa0,
+ 0x07, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0,
+ 0x06, 0xf6, 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80,
+ 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x90,
+ 0x07, 0x72, 0xa0, 0x07, 0x72, 0x50, 0x07, 0x76, 0xa0, 0x07, 0x72, 0x50,
+ 0x07, 0x76, 0xd0, 0x06, 0xf6, 0x20, 0x07, 0x75, 0x60, 0x07, 0x7a, 0x20,
+ 0x07, 0x75, 0x60, 0x07, 0x7a, 0x20, 0x07, 0x75, 0x60, 0x07, 0x6d, 0x60,
+ 0x0f, 0x75, 0x10, 0x07, 0x72, 0xa0, 0x07, 0x75, 0x10, 0x07, 0x72, 0xa0,
+ 0x07, 0x75, 0x10, 0x07, 0x72, 0xd0, 0x06, 0xf6, 0x10, 0x07, 0x70, 0x20,
+ 0x07, 0x74, 0xa0, 0x07, 0x71, 0x00, 0x07, 0x72, 0x40, 0x07, 0x7a, 0x10,
+ 0x07, 0x70, 0x20, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x80, 0x07, 0x70, 0xa0,
+ 0x07, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0,
+ 0x06, 0xee, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x73, 0x20,
+ 0x07, 0x43, 0x18, 0x05, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
+ 0x2c, 0x10, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x10,
+ 0x19, 0x11, 0x4c, 0x90, 0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0x42,
+ 0x25, 0x50, 0x10, 0x23, 0x00, 0x05, 0x18, 0x50, 0x04, 0x05, 0x52, 0x06,
+ 0x85, 0x40, 0x6d, 0x04, 0x00, 0x00, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
+ 0xd3, 0x00, 0x00, 0x00, 0x1a, 0x03, 0x4c, 0x10, 0xd7, 0x20, 0x08, 0x0e,
+ 0x8e, 0xad, 0x0c, 0x84, 0x89, 0xc9, 0xaa, 0x09, 0xc4, 0xae, 0x4c, 0x6e,
+ 0x2e, 0xed, 0xcd, 0x0d, 0x04, 0x07, 0x46, 0xc6, 0x25, 0x06, 0x04, 0xa5,
+ 0xad, 0x8c, 0x2e, 0x8c, 0xcd, 0xac, 0xac, 0x05, 0x07, 0x46, 0xc6, 0x25,
+ 0xc6, 0x65, 0x86, 0x26, 0x65, 0x88, 0xb0, 0x00, 0x43, 0x0c, 0x24, 0x40,
+ 0x04, 0x64, 0x60, 0xd1, 0x54, 0x46, 0x17, 0xc6, 0x36, 0x04, 0x59, 0x06,
+ 0x24, 0x40, 0x02, 0x64, 0xe0, 0x16, 0x96, 0x26, 0xe7, 0x32, 0xf6, 0xd6,
+ 0x06, 0x97, 0xc6, 0x56, 0xe6, 0x42, 0x56, 0xe6, 0xf6, 0x26, 0xd7, 0x36,
+ 0xf7, 0x45, 0x96, 0x36, 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0x58, 0x0a,
+ 0x72, 0x61, 0x69, 0x72, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65,
+ 0x2e, 0x66, 0x61, 0x73, 0x74, 0x5f, 0x6d, 0x61, 0x74, 0x68, 0x5f, 0x65,
+ 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x43, 0x84, 0xe5, 0x20, 0x19, 0x84, 0xa5,
+ 0xc9, 0xb9, 0x8c, 0xbd, 0xb5, 0xc1, 0xa5, 0xb1, 0x95, 0xb9, 0x98, 0xc9,
+ 0x85, 0xb5, 0x95, 0x89, 0xd5, 0x99, 0x99, 0x95, 0xc9, 0x7d, 0x99, 0x95,
+ 0xd1, 0x8d, 0xa1, 0x7d, 0x95, 0xb9, 0x85, 0x89, 0xb1, 0x95, 0x0d, 0x11,
+ 0x96, 0x84, 0x61, 0x10, 0x96, 0x26, 0xe7, 0x32, 0xf6, 0xd6, 0x06, 0x97,
+ 0xc6, 0x56, 0xe6, 0xe2, 0x16, 0x46, 0x97, 0x66, 0x57, 0xf6, 0x45, 0xf6,
+ 0x56, 0x27, 0xc6, 0x56, 0xf6, 0x45, 0x96, 0x36, 0x17, 0x26, 0xc6, 0x56,
+ 0x36, 0x44, 0x58, 0x16, 0x32, 0x61, 0x69, 0x72, 0x2e, 0x70, 0x6f, 0x73,
+ 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x8c, 0xc2, 0xd2, 0xe4, 0x5c, 0xc2, 0xe4,
+ 0xce, 0xbe, 0xe8, 0xf2, 0xe0, 0xca, 0xbe, 0xdc, 0xc2, 0xda, 0xca, 0x68,
+ 0x98, 0xb1, 0xbd, 0x85, 0xd1, 0xd1, 0x90, 0x09, 0x4b, 0x93, 0x73, 0x09,
+ 0x93, 0x3b, 0xfb, 0x72, 0x0b, 0x6b, 0x2b, 0x23, 0x02, 0xf7, 0x36, 0x97,
+ 0x46, 0x97, 0xf6, 0xe6, 0x36, 0x44, 0x59, 0x9a, 0xc5, 0x59, 0x9e, 0x05,
+ 0x5a, 0x22, 0x46, 0x61, 0x69, 0x72, 0x2e, 0x76, 0x65, 0x72, 0x74, 0x65,
+ 0x78, 0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0xcc, 0xce, 0xca, 0xdc,
+ 0xca, 0xe4, 0xc2, 0xe8, 0xca, 0xc8, 0x50, 0x70, 0xe8, 0xca, 0xf0, 0xc6,
+ 0xde, 0xde, 0xe4, 0xc8, 0x88, 0xec, 0x64, 0xbe, 0xcc, 0x52, 0x68, 0x98,
+ 0xb1, 0xbd, 0x85, 0xd1, 0xc9, 0x10, 0xa1, 0x2b, 0xc3, 0x1b, 0x7b, 0x7b,
+ 0x93, 0x23, 0x1b, 0xc2, 0x2c, 0xd3, 0x42, 0x2d, 0xce, 0x52, 0x2d, 0xd0,
+ 0x62, 0x0d, 0x21, 0x16, 0x69, 0xb9, 0xa8, 0x84, 0xa5, 0xc9, 0xb9, 0x88,
+ 0xd5, 0x99, 0x99, 0x95, 0xc9, 0x51, 0x0a, 0x4b, 0x93, 0x73, 0x61, 0x7b,
+ 0x1b, 0x0b, 0xa3, 0x4b, 0x7b, 0x73, 0xfb, 0x4a, 0x73, 0x23, 0x2b, 0xc3,
+ 0x23, 0x12, 0x96, 0x26, 0xe7, 0x22, 0x57, 0x16, 0x46, 0xc6, 0x28, 0x2c,
+ 0x4d, 0xce, 0x25, 0x4c, 0xee, 0xec, 0x8b, 0x2e, 0x0f, 0xae, 0xec, 0x6b,
+ 0x2e, 0x4d, 0xaf, 0x8c, 0x57, 0x58, 0x9a, 0x9c, 0x4b, 0x98, 0xdc, 0xd9,
+ 0x17, 0x5d, 0x1e, 0x5c, 0xd9, 0x57, 0x18, 0x5b, 0xda, 0x99, 0xdb, 0xd7,
+ 0x5c, 0x9a, 0x5e, 0xd9, 0x10, 0x0e, 0x19, 0x96, 0x6c, 0xd1, 0x90, 0x01,
+ 0x09, 0x96, 0x6d, 0xe1, 0x10, 0x61, 0xe9, 0x10, 0x61, 0x71, 0x96, 0x6a,
+ 0x81, 0x96, 0x88, 0x09, 0x5d, 0x19, 0xde, 0xd8, 0xdb, 0x9b, 0x1c, 0xd9,
+ 0xdc, 0x10, 0x0e, 0x09, 0x96, 0x6c, 0xd1, 0x90, 0x00, 0x09, 0x96, 0x6d,
+ 0xe1, 0x10, 0x61, 0xe9, 0x10, 0x61, 0x71, 0x96, 0x6a, 0x81, 0x96, 0x8f,
+ 0x4f, 0x58, 0x9a, 0x9c, 0x8b, 0x58, 0x9d, 0x99, 0x59, 0x99, 0xdc, 0xd7,
+ 0x5c, 0x9a, 0x5e, 0x19, 0x11, 0x33, 0xb6, 0xb7, 0x30, 0x3a, 0x1a, 0x3c,
+ 0x1a, 0x2a, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e,
+ 0x43, 0xc0, 0x00, 0x29, 0x96, 0x6c, 0x09, 0x03, 0x84, 0x58, 0x34, 0xa4,
+ 0x40, 0x82, 0x65, 0x5b, 0x38, 0x84, 0x58, 0x3a, 0xc4, 0x58, 0x9c, 0x45,
+ 0x0c, 0x16, 0x68, 0x19, 0x03, 0x26, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x66,
+ 0x6f, 0x72, 0x6d, 0x43, 0xc0, 0x00, 0x39, 0x96, 0x6c, 0x09, 0x03, 0x84,
+ 0x58, 0x34, 0xe4, 0x40, 0x82, 0x65, 0x5b, 0x38, 0x84, 0x58, 0x3a, 0xc4,
+ 0x58, 0x9c, 0x45, 0x0c, 0x16, 0x68, 0x29, 0x03, 0x36, 0x61, 0x69, 0x72,
+ 0x2e, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x5f, 0x69, 0x64, 0x24, 0xea,
+ 0xd2, 0xdc, 0xe8, 0x38, 0xd8, 0xa5, 0x91, 0x0d, 0x61, 0x10, 0x64, 0x39,
+ 0x83, 0xc5, 0x59, 0xd0, 0x60, 0x81, 0x96, 0x34, 0x18, 0xa2, 0x2c, 0xde,
+ 0x02, 0x06, 0x0b, 0x19, 0x2c, 0x66, 0xb0, 0xa8, 0xc1, 0x10, 0x43, 0x01,
+ 0x16, 0x6c, 0x59, 0x03, 0x3e, 0x6f, 0x6d, 0x6e, 0x69, 0x70, 0x6f, 0x74,
+ 0x65, 0x6e, 0x74, 0x20, 0x63, 0x68, 0x61, 0x72, 0x7c, 0xa6, 0xd2, 0xda,
+ 0xe0, 0xd8, 0xca, 0x40, 0x86, 0x56, 0x56, 0x40, 0xa8, 0x84, 0x82, 0x82,
+ 0x86, 0x08, 0x8b, 0x1b, 0x0c, 0x31, 0x96, 0x36, 0x58, 0xde, 0xa0, 0x49,
+ 0x86, 0x18, 0x0b, 0x1c, 0x2c, 0x70, 0xd0, 0x24, 0x23, 0x14, 0x76, 0x60,
+ 0x07, 0x7b, 0x68, 0x07, 0x37, 0x48, 0x07, 0x72, 0x28, 0x07, 0x77, 0xa0,
+ 0x87, 0x29, 0x41, 0x30, 0x62, 0x09, 0x87, 0x74, 0x90, 0x07, 0x37, 0xb0,
+ 0x87, 0x72, 0x90, 0x87, 0x79, 0x48, 0x87, 0x77, 0x70, 0x87, 0x29, 0x81,
+ 0x30, 0x82, 0x0a, 0x87, 0x74, 0x90, 0x07, 0x37, 0x60, 0x87, 0x70, 0x70,
+ 0x87, 0x73, 0xa8, 0x87, 0x70, 0x38, 0x87, 0x72, 0xf8, 0x05, 0x7b, 0x28,
+ 0x07, 0x79, 0x98, 0x87, 0x74, 0x78, 0x07, 0x77, 0x98, 0x12, 0x10, 0x23,
+ 0xa6, 0x70, 0x48, 0x07, 0x79, 0x70, 0x83, 0x71, 0x78, 0x87, 0x76, 0x80,
+ 0x87, 0x74, 0x60, 0x87, 0x72, 0xf8, 0x85, 0x77, 0x80, 0x07, 0x7a, 0x48,
+ 0x87, 0x77, 0x70, 0x87, 0x79, 0x98, 0x42, 0x18, 0x88, 0xc2, 0x8c, 0x50,
+ 0xc2, 0x21, 0x1d, 0xe4, 0xc1, 0x0d, 0xec, 0xa1, 0x1c, 0xe4, 0x81, 0x1e,
+ 0xca, 0x01, 0x1f, 0xa6, 0x04, 0x6c, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
+ 0x5c, 0x00, 0x00, 0x00, 0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66,
+ 0x14, 0x01, 0x3d, 0x88, 0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07,
+ 0x79, 0x78, 0x07, 0x73, 0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10,
+ 0x0e, 0xf4, 0x80, 0x0e, 0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce,
+ 0xa1, 0x1c, 0x66, 0x30, 0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b,
+ 0xcc, 0x03, 0x3d, 0xc8, 0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c,
+ 0x74, 0x70, 0x07, 0x7b, 0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07,
+ 0x7a, 0x70, 0x03, 0x76, 0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11,
+ 0x0e, 0xec, 0x90, 0x0e, 0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0,
+ 0x0e, 0xf0, 0x50, 0x0e, 0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8,
+ 0x21, 0x1d, 0xc2, 0x61, 0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b,
+ 0xd0, 0x43, 0x39, 0xb4, 0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b,
+ 0xcc, 0xf0, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87,
+ 0x72, 0x68, 0x07, 0x37, 0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07,
+ 0x76, 0x28, 0x07, 0x76, 0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87,
+ 0x5f, 0x08, 0x87, 0x71, 0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81,
+ 0x2c, 0xee, 0xf0, 0x0e, 0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30,
+ 0x03, 0x62, 0xc8, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4,
+ 0xa1, 0x1c, 0xdc, 0x61, 0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca,
+ 0x61, 0x06, 0xd6, 0x90, 0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39,
+ 0xc8, 0x43, 0x39, 0xb8, 0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b,
+ 0x94, 0xc3, 0x2f, 0xbc, 0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b,
+ 0xb0, 0xc3, 0x0c, 0xc7, 0x69, 0x87, 0x70, 0x58, 0x87, 0x72, 0x70, 0x83,
+ 0x74, 0x68, 0x07, 0x78, 0x60, 0x87, 0x74, 0x18, 0x87, 0x74, 0xa0, 0x87,
+ 0x19, 0xce, 0x53, 0x0f, 0xee, 0x00, 0x0f, 0xf2, 0x50, 0x0e, 0xe4, 0x90,
+ 0x0e, 0xe3, 0x40, 0x0f, 0xe1, 0x20, 0x0e, 0xec, 0x50, 0x0e, 0x33, 0x20,
+ 0x28, 0x1d, 0xdc, 0xc1, 0x1e, 0xc2, 0x41, 0x1e, 0xd2, 0x21, 0x1c, 0xdc,
+ 0x81, 0x1e, 0xdc, 0xe0, 0x1c, 0xe4, 0xe1, 0x1d, 0xea, 0x01, 0x1e, 0x66,
+ 0x18, 0x51, 0x38, 0xb0, 0x43, 0x3a, 0x9c, 0x83, 0x3b, 0xcc, 0x50, 0x24,
+ 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x60, 0x87, 0x77, 0x78, 0x07,
+ 0x78, 0x98, 0x51, 0x4c, 0xf4, 0x90, 0x0f, 0xf0, 0x50, 0x0e, 0x00, 0x00,
+ 0x71, 0x20, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x06, 0xf0, 0xb0, 0x5d,
+ 0xf9, 0x73, 0xce, 0x83, 0xfd, 0x15, 0x11, 0x4d, 0xc4, 0x05, 0x00, 0x00,
+ 0x61, 0x20, 0x00, 0x00, 0x6d, 0x00, 0x00, 0x00, 0x13, 0x04, 0x47, 0x2c,
+ 0x10, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x14, 0xe7, 0x20, 0x86,
+ 0x80, 0xa2, 0x46, 0x00, 0xa8, 0x95, 0x41, 0x11, 0x94, 0x00, 0xa1, 0x19,
+ 0x00, 0x1a, 0x33, 0x00, 0x24, 0x66, 0x00, 0x28, 0xcc, 0x00, 0x10, 0x18,
+ 0x23, 0x00, 0x41, 0x10, 0xc4, 0xbf, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x33, 0x11, 0x0c, 0x12, 0x14, 0x33, 0x11, 0x0c, 0x12, 0x14, 0xe3, 0x11,
+ 0xd0, 0x94, 0x4d, 0x14, 0x94, 0x59, 0x82, 0x60, 0xa0, 0x02, 0xb1, 0x03,
+ 0xe0, 0x0c, 0x86, 0x0b, 0x9a, 0x8c, 0x47, 0x4c, 0x57, 0x17, 0x50, 0x50,
+ 0x06, 0x19, 0x82, 0x45, 0xb2, 0xc0, 0x90, 0xcf, 0x2c, 0x81, 0x30, 0x50,
+ 0x81, 0x98, 0x42, 0x50, 0x09, 0x03, 0x15, 0x01, 0x11, 0x44, 0xc2, 0x18,
+ 0x42, 0x21, 0xcc, 0x31, 0x40, 0x01, 0x19, 0x0c, 0x32, 0x04, 0x11, 0x76,
+ 0x45, 0x93, 0xf1, 0x08, 0x2f, 0x0c, 0xce, 0x20, 0xa0, 0xa0, 0x58, 0x40,
+ 0xc8, 0xc7, 0x02, 0x04, 0x3e, 0xa6, 0xb4, 0x01, 0x0c, 0x86, 0x1b, 0x82,
+ 0x33, 0x00, 0x83, 0x59, 0x86, 0x41, 0x08, 0xc6, 0x23, 0xac, 0x33, 0x68,
+ 0x83, 0x68, 0x30, 0x22, 0x20, 0x0a, 0xc0, 0x26, 0x38, 0x80, 0xc1, 0x70,
+ 0x43, 0xa0, 0x06, 0x60, 0x30, 0xcb, 0x40, 0x04, 0xc1, 0x78, 0x44, 0xa6,
+ 0x06, 0x70, 0xa0, 0x06, 0x14, 0x94, 0xf1, 0x88, 0x8d, 0x0d, 0xe4, 0x40,
+ 0x0c, 0x28, 0x28, 0xe3, 0x11, 0x9d, 0x1b, 0xd0, 0x41, 0x19, 0x50, 0x50,
+ 0xc6, 0x23, 0x3e, 0x38, 0xb0, 0x03, 0x34, 0xa0, 0xa0, 0x8c, 0x47, 0x80,
+ 0x81, 0x1c, 0xe0, 0x81, 0x1c, 0x0c, 0x46, 0x04, 0x48, 0x01, 0x8c, 0x47,
+ 0x84, 0xc1, 0x1c, 0xe4, 0x41, 0x1a, 0x0c, 0x46, 0x04, 0x47, 0x01, 0x8c,
+ 0x47, 0x88, 0x01, 0x1d, 0xe8, 0xc1, 0x1a, 0x0c, 0x46, 0x04, 0x46, 0x01,
+ 0x8c, 0x47, 0x8c, 0x41, 0x1d, 0xec, 0x41, 0x1b, 0x0c, 0x46, 0x04, 0x45,
+ 0x01, 0x5c, 0x1c, 0xb4, 0x18, 0x4f, 0xb0, 0x83, 0x80, 0x02, 0x32, 0xc8,
+ 0x10, 0xb0, 0xc1, 0x1c, 0xcc, 0x31, 0x04, 0x6a, 0xe0, 0x07, 0x73, 0x0c,
+ 0x01, 0x1b, 0xf4, 0xc1, 0x20, 0x43, 0xe0, 0x06, 0x75, 0x60, 0x81, 0x24,
+ 0x9f, 0x59, 0x82, 0x62, 0xa0, 0x02, 0x61, 0x09, 0xa2, 0x2a, 0x06, 0x2a,
+ 0x02, 0x82, 0x88, 0x8a, 0x31, 0x84, 0x42, 0x98, 0x63, 0x98, 0x83, 0xe0,
+ 0x14, 0x06, 0x19, 0x02, 0x3a, 0xd8, 0x83, 0x2b, 0x9a, 0x8c, 0x47, 0xc8,
+ 0x01, 0x29, 0xa8, 0x42, 0x40, 0x41, 0xb1, 0x80, 0x90, 0x8f, 0x05, 0x08,
+ 0x7c, 0x4c, 0x81, 0x05, 0x18, 0x0c, 0x37, 0x04, 0xaa, 0x00, 0x06, 0xb3,
+ 0x0c, 0x46, 0x11, 0x8c, 0x27, 0xa0, 0x02, 0x45, 0x01, 0x99, 0x6d, 0x00,
+ 0x85, 0x02, 0x98, 0x6d, 0x08, 0x84, 0x20, 0x83, 0x80, 0x18, 0x00, 0x00,
+ 0x0a, 0x00, 0x00, 0x00, 0x5b, 0x86, 0x21, 0x88, 0x83, 0x2d, 0x03, 0x12,
+ 0xc4, 0xc1, 0x96, 0x61, 0x0a, 0xe2, 0x60, 0xcb, 0xa0, 0x05, 0x71, 0xb0,
+ 0x65, 0x80, 0x83, 0x20, 0x0e, 0xb6, 0x0c, 0x7e, 0x10, 0xc4, 0xc1, 0x96,
+ 0xa1, 0x14, 0x82, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xde, 0xc0, 0x17, 0x0b,
+ 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x90, 0x08, 0x00, 0x00,
+ 0xff, 0xff, 0xff, 0xff, 0x42, 0x43, 0xc0, 0xde, 0x21, 0x0c, 0x00, 0x00,
+ 0x21, 0x02, 0x00, 0x00, 0x0b, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x12, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49,
+ 0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19,
+ 0x1e, 0x04, 0x8b, 0x62, 0x80, 0x10, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42,
+ 0x84, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x49, 0x0a, 0x32, 0x44, 0x24,
+ 0x48, 0x0a, 0x90, 0x21, 0x23, 0xc4, 0x52, 0x80, 0x0c, 0x19, 0x21, 0x72,
+ 0x24, 0x07, 0xc8, 0x08, 0x11, 0x62, 0xa8, 0xa0, 0xa8, 0x40, 0xc6, 0xf0,
+ 0x01, 0x00, 0x00, 0x00, 0x51, 0x18, 0x00, 0x00, 0x81, 0x00, 0x00, 0x00,
+ 0x1b, 0x8c, 0x20, 0x00, 0x16, 0xa0, 0xda, 0x40, 0x2e, 0xc2, 0xff, 0xff,
+ 0xff, 0xff, 0x0f, 0x80, 0x04, 0x54, 0xc4, 0x38, 0xbc, 0x83, 0x3c, 0xc8,
+ 0x43, 0x39, 0x8c, 0x03, 0x3d, 0xb0, 0x43, 0x3e, 0xb4, 0x81, 0x3c, 0xbc,
+ 0x43, 0x3d, 0xb8, 0x03, 0x39, 0x94, 0x03, 0x39, 0xb4, 0x01, 0x39, 0xa4,
+ 0x83, 0x3d, 0xa4, 0x03, 0x39, 0x94, 0x43, 0x1b, 0xcc, 0x43, 0x3c, 0xc8,
+ 0x03, 0x3d, 0xb4, 0x81, 0x39, 0xc0, 0x43, 0x1b, 0xb4, 0x43, 0x38, 0xd0,
+ 0x03, 0x3a, 0x00, 0xe6, 0x10, 0x0e, 0xec, 0x30, 0x0f, 0xe5, 0x00, 0x10,
+ 0xe4, 0x90, 0x0e, 0xf3, 0x10, 0x0e, 0xe2, 0xc0, 0x0e, 0xe5, 0xd0, 0x06,
+ 0xf4, 0x10, 0x0e, 0xe9, 0xc0, 0x0e, 0x6d, 0x30, 0x0e, 0xe1, 0xc0, 0x0e,
+ 0xec, 0x30, 0x0f, 0x80, 0x39, 0x84, 0x03, 0x3b, 0xcc, 0x43, 0x39, 0x00,
+ 0x04, 0x3b, 0x94, 0xc3, 0x3c, 0xcc, 0x43, 0x1b, 0xc0, 0x83, 0x3c, 0x94,
+ 0xc3, 0x38, 0xa4, 0xc3, 0x3c, 0x94, 0x43, 0x1b, 0x98, 0x03, 0x3c, 0xb4,
+ 0x43, 0x38, 0x90, 0x03, 0x40, 0x0f, 0xf2, 0x50, 0x0f, 0xe5, 0x00, 0x10,
+ 0xee, 0xf0, 0x0e, 0x6d, 0x60, 0x0e, 0xf2, 0x10, 0x0e, 0xed, 0x50, 0x0e,
+ 0x6d, 0x00, 0x0f, 0xef, 0x90, 0x0e, 0xee, 0x40, 0x0f, 0xe5, 0x20, 0x0f,
+ 0x6d, 0x50, 0x0e, 0xec, 0x90, 0x0e, 0xed, 0x00, 0xd0, 0x83, 0x3c, 0xd4,
+ 0x43, 0x39, 0x00, 0x83, 0x3b, 0xbc, 0x43, 0x1b, 0x98, 0x83, 0x3c, 0x84,
+ 0x43, 0x3b, 0x94, 0x43, 0x1b, 0xc0, 0xc3, 0x3b, 0xa4, 0x83, 0x3b, 0xd0,
+ 0x43, 0x39, 0xc8, 0x43, 0x1b, 0x94, 0x03, 0x3b, 0xa4, 0x43, 0x3b, 0xb4,
+ 0x81, 0x3b, 0xbc, 0x83, 0x3b, 0xb4, 0x01, 0x3b, 0x94, 0x43, 0x38, 0x98,
+ 0x03, 0x40, 0xb8, 0xc3, 0x3b, 0xb4, 0x41, 0x3a, 0xb8, 0x83, 0x39, 0xcc,
+ 0x43, 0x1b, 0x98, 0x03, 0x3c, 0xb4, 0x41, 0x3b, 0x84, 0x03, 0x3d, 0xa0,
+ 0x03, 0x40, 0x0f, 0xf2, 0x50, 0x0f, 0xe5, 0x00, 0x10, 0xee, 0xf0, 0x0e,
+ 0x6d, 0xa0, 0x0e, 0xf5, 0xd0, 0x0e, 0xf0, 0xd0, 0x06, 0xf4, 0x10, 0x0e,
+ 0xe2, 0xc0, 0x0e, 0xe5, 0x30, 0x0f, 0x80, 0x39, 0x84, 0x03, 0x3b, 0xcc,
+ 0x43, 0x39, 0x00, 0x84, 0x3b, 0xbc, 0x43, 0x1b, 0xb8, 0x43, 0x38, 0xb8,
+ 0xc3, 0x3c, 0xb4, 0x81, 0x39, 0xc0, 0x43, 0x1b, 0xb4, 0x43, 0x38, 0xd0,
+ 0x03, 0x3a, 0x00, 0xf4, 0x20, 0x0f, 0xf5, 0x50, 0x0e, 0x00, 0xe1, 0x0e,
+ 0xef, 0xd0, 0x06, 0xf3, 0x90, 0x0e, 0xe7, 0xe0, 0x0e, 0xe5, 0x40, 0x0e,
+ 0x6d, 0xa0, 0x0f, 0xe5, 0x20, 0x0f, 0xef, 0x30, 0x0f, 0x6d, 0x60, 0x0e,
+ 0xf0, 0xd0, 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x80, 0x39, 0x84,
+ 0x03, 0x3b, 0xcc, 0x43, 0x39, 0x00, 0xc4, 0x3c, 0xd0, 0x43, 0x38, 0x8c,
+ 0xc3, 0x3a, 0xb4, 0x01, 0x3c, 0xc8, 0xc3, 0x3b, 0xd0, 0x43, 0x39, 0x8c,
+ 0x03, 0x3d, 0xbc, 0x83, 0x3c, 0xb4, 0x81, 0x38, 0xd4, 0x83, 0x39, 0x98,
+ 0x43, 0x39, 0xc8, 0x43, 0x1b, 0xcc, 0x43, 0x3a, 0xe8, 0x43, 0x39, 0x00,
+ 0x78, 0x00, 0x10, 0xf4, 0x10, 0x0e, 0xf2, 0x70, 0x0e, 0xe5, 0x40, 0x0f,
+ 0x6d, 0x60, 0x0e, 0xe5, 0x10, 0x0e, 0xf4, 0x50, 0x0f, 0xf2, 0x50, 0x0e,
+ 0xf3, 0x00, 0xb4, 0x81, 0x39, 0xc0, 0x43, 0x1c, 0xd8, 0x01, 0x40, 0xd4,
+ 0x83, 0x3b, 0xcc, 0x43, 0x38, 0x98, 0x43, 0x39, 0xb4, 0x81, 0x39, 0xc0,
+ 0x43, 0x1b, 0xb4, 0x43, 0x38, 0xd0, 0x03, 0x3a, 0x00, 0xf4, 0x20, 0x0f,
+ 0xf5, 0x50, 0x0e, 0x00, 0x51, 0x0f, 0xf3, 0x50, 0x0e, 0x6d, 0x30, 0x0f,
+ 0xef, 0x60, 0x0e, 0xf4, 0xd0, 0x06, 0xe6, 0xc0, 0x0e, 0xef, 0x10, 0x0e,
+ 0xf4, 0x00, 0x98, 0x43, 0x38, 0xb0, 0xc3, 0x3c, 0x94, 0x03, 0x00, 0x00,
+ 0x49, 0x18, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x13, 0x84, 0x40, 0x00,
+ 0x89, 0x20, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x32, 0x22, 0x08, 0x09,
+ 0x20, 0x64, 0x85, 0x04, 0x13, 0x22, 0xa4, 0x84, 0x04, 0x13, 0x22, 0xe3,
+ 0x84, 0xa1, 0x90, 0x14, 0x12, 0x4c, 0x88, 0x8c, 0x0b, 0x84, 0x84, 0x4c,
+ 0x10, 0x24, 0x33, 0x00, 0xc3, 0x08, 0x04, 0x30, 0x88, 0x10, 0x08, 0x45,
+ 0x08, 0xa1, 0x19, 0x08, 0x98, 0x23, 0x00, 0x83, 0x39, 0x02, 0x50, 0x18,
+ 0x01, 0x00, 0x00, 0x00, 0x13, 0xa8, 0x70, 0x48, 0x07, 0x79, 0xb0, 0x03,
+ 0x3a, 0x68, 0x83, 0x70, 0x80, 0x07, 0x78, 0x60, 0x87, 0x72, 0x68, 0x83,
+ 0x74, 0x78, 0x87, 0x79, 0xc8, 0x03, 0x37, 0x80, 0x03, 0x37, 0x80, 0x83,
+ 0x0d, 0xef, 0x51, 0x0e, 0x6d, 0x00, 0x0f, 0x7a, 0x60, 0x07, 0x74, 0xa0,
+ 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe9, 0x10,
+ 0x07, 0x7a, 0x80, 0x07, 0x7a, 0x80, 0x07, 0x6d, 0x90, 0x0e, 0x78, 0xa0,
+ 0x07, 0x78, 0xa0, 0x07, 0x78, 0xd0, 0x06, 0xe9, 0x10, 0x07, 0x76, 0xa0,
+ 0x07, 0x71, 0x60, 0x07, 0x7a, 0x10, 0x07, 0x76, 0xd0, 0x06, 0xe9, 0x30,
+ 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0,
+ 0x06, 0xe9, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60,
+ 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20,
+ 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xe6, 0x60, 0x07, 0x74, 0xa0,
+ 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x80,
+ 0x07, 0x70, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20,
+ 0x07, 0x78, 0xd0, 0x06, 0xf6, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x60,
+ 0x07, 0x7a, 0x10, 0x07, 0x76, 0xd0, 0x06, 0xf6, 0x20, 0x07, 0x74, 0xa0,
+ 0x07, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xf6, 0x30,
+ 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0,
+ 0x06, 0xf6, 0x40, 0x07, 0x78, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60,
+ 0x07, 0x74, 0xd0, 0x06, 0xf6, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40,
+ 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xf6, 0x90, 0x07, 0x76, 0xa0,
+ 0x07, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0,
+ 0x06, 0xf6, 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80,
+ 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x90,
+ 0x07, 0x72, 0xa0, 0x07, 0x72, 0x50, 0x07, 0x76, 0xa0, 0x07, 0x72, 0x50,
+ 0x07, 0x76, 0xd0, 0x06, 0xf6, 0x20, 0x07, 0x75, 0x60, 0x07, 0x7a, 0x20,
+ 0x07, 0x75, 0x60, 0x07, 0x7a, 0x20, 0x07, 0x75, 0x60, 0x07, 0x6d, 0x60,
+ 0x0f, 0x75, 0x10, 0x07, 0x72, 0xa0, 0x07, 0x75, 0x10, 0x07, 0x72, 0xa0,
+ 0x07, 0x75, 0x10, 0x07, 0x72, 0xd0, 0x06, 0xf6, 0x10, 0x07, 0x70, 0x20,
+ 0x07, 0x74, 0xa0, 0x07, 0x71, 0x00, 0x07, 0x72, 0x40, 0x07, 0x7a, 0x10,
+ 0x07, 0x70, 0x20, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x80, 0x07, 0x70, 0xa0,
+ 0x07, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0,
+ 0x06, 0xee, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x73, 0x20,
+ 0x07, 0x43, 0x18, 0x02, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
+ 0x2c, 0x10, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x0c,
+ 0x19, 0x11, 0x4c, 0x90, 0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0xb2,
+ 0x11, 0x80, 0x12, 0x28, 0x90, 0x82, 0xa0, 0x1b, 0x01, 0x00, 0x00, 0x00,
+ 0x79, 0x18, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x1a, 0x03, 0x4c, 0x10,
+ 0xd7, 0x20, 0x08, 0x0e, 0x8e, 0xad, 0x0c, 0x84, 0x89, 0xc9, 0xaa, 0x09,
+ 0xc4, 0xae, 0x4c, 0x6e, 0x2e, 0xed, 0xcd, 0x0d, 0x04, 0x07, 0x46, 0xc6,
+ 0x25, 0x06, 0x04, 0xa5, 0xad, 0x8c, 0x2e, 0x8c, 0xcd, 0xac, 0xac, 0x05,
+ 0x07, 0x46, 0xc6, 0x25, 0xc6, 0x65, 0x86, 0x26, 0x65, 0x88, 0x50, 0x00,
+ 0x43, 0x0c, 0x43, 0x30, 0x08, 0x23, 0x60, 0xd1, 0x54, 0x46, 0x17, 0xc6,
+ 0x36, 0x04, 0x29, 0x06, 0x43, 0x30, 0x04, 0x23, 0xe0, 0x16, 0x96, 0x26,
+ 0xe7, 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56, 0xe6, 0x42, 0x56, 0xe6,
+ 0xf6, 0x26, 0xd7, 0x36, 0xf7, 0x45, 0x96, 0x36, 0x17, 0x26, 0xc6, 0x56,
+ 0x36, 0x44, 0x28, 0x0a, 0x72, 0x61, 0x69, 0x72, 0x2e, 0x63, 0x6f, 0x6d,
+ 0x70, 0x69, 0x6c, 0x65, 0x2e, 0x66, 0x61, 0x73, 0x74, 0x5f, 0x6d, 0x61,
+ 0x74, 0x68, 0x5f, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x43, 0x84, 0xe2,
+ 0x20, 0x19, 0x84, 0xa5, 0xc9, 0xb9, 0x8c, 0xbd, 0xb5, 0xc1, 0xa5, 0xb1,
+ 0x95, 0xb9, 0x98, 0xc9, 0x85, 0xb5, 0x95, 0x89, 0xd5, 0x99, 0x99, 0x95,
+ 0xc9, 0x7d, 0x99, 0x95, 0xd1, 0x8d, 0xa1, 0x7d, 0x95, 0xb9, 0x85, 0x89,
+ 0xb1, 0x95, 0x0d, 0x11, 0x8a, 0x84, 0x61, 0x10, 0x96, 0x26, 0xe7, 0x32,
+ 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56, 0xe6, 0xe2, 0x16, 0x46, 0x97, 0x66,
+ 0x57, 0xf6, 0x45, 0xf6, 0x56, 0x27, 0xc6, 0x56, 0xf6, 0x45, 0x96, 0x36,
+ 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0x28, 0x16, 0x46, 0x61, 0x69, 0x72,
+ 0x2e, 0x72, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x5f, 0x74, 0x61, 0x72, 0x67,
+ 0x65, 0x74, 0x8c, 0xc2, 0xd2, 0xe4, 0x5c, 0xc2, 0xe4, 0xce, 0xbe, 0xe8,
+ 0xf2, 0xe0, 0xca, 0xbe, 0xdc, 0xc2, 0xda, 0xca, 0x68, 0x98, 0xb1, 0xbd,
+ 0x85, 0xd1, 0xd1, 0x0c, 0x41, 0x8a, 0xc6, 0x08, 0x0a, 0xa7, 0x78, 0x86,
+ 0x08, 0x05, 0x44, 0x25, 0x2c, 0x4d, 0xce, 0x45, 0xac, 0xce, 0xcc, 0xac,
+ 0x4c, 0x8e, 0x4f, 0x58, 0x9a, 0x9c, 0x8b, 0x58, 0x9d, 0x99, 0x59, 0x99,
+ 0xdc, 0xd7, 0x5c, 0x9a, 0x5e, 0x19, 0xa5, 0xb0, 0x34, 0x39, 0x17, 0xb6,
+ 0xb7, 0xb1, 0x30, 0xba, 0xb4, 0x37, 0xb7, 0xaf, 0x34, 0x37, 0xb2, 0x32,
+ 0x3c, 0x22, 0x61, 0x69, 0x72, 0x2e, 0x72, 0x65, 0x61, 0x64, 0x8c, 0xc2,
+ 0xd2, 0xe4, 0x5c, 0xc2, 0xe4, 0xce, 0xbe, 0xe8, 0xf2, 0xe0, 0xca, 0xbe,
+ 0xe6, 0xd2, 0xf4, 0xca, 0x78, 0x85, 0xa5, 0xc9, 0xb9, 0x84, 0xc9, 0x9d,
+ 0x7d, 0xd1, 0xe5, 0xc1, 0x95, 0x7d, 0x85, 0xb1, 0xa5, 0x9d, 0xb9, 0x7d,
+ 0xcd, 0xa5, 0xe9, 0x95, 0x91, 0x09, 0x4b, 0x93, 0x73, 0x09, 0x93, 0x3b,
+ 0xfb, 0x72, 0x0b, 0x6b, 0x2b, 0xe3, 0x30, 0xf6, 0xc6, 0x36, 0x04, 0x0c,
+ 0x8c, 0xa0, 0x90, 0x8a, 0xc9, 0x18, 0x0a, 0xca, 0x08, 0x0c, 0xa1, 0xa8,
+ 0x0a, 0xcb, 0x18, 0x8a, 0xcb, 0x18, 0x0a, 0xa7, 0x78, 0x0a, 0xac, 0xc8,
+ 0x86, 0x08, 0x85, 0x36, 0xc4, 0x20, 0x80, 0x22, 0x2a, 0x36, 0x3e, 0x6f,
+ 0x6d, 0x6e, 0x69, 0x70, 0x6f, 0x74, 0x65, 0x6e, 0x74, 0x20, 0x63, 0x68,
+ 0x61, 0x72, 0x7c, 0xa6, 0xd2, 0xda, 0xe0, 0xd8, 0xca, 0x40, 0x86, 0x56,
+ 0x56, 0x40, 0xa8, 0x84, 0x82, 0x82, 0x86, 0x08, 0x85, 0x37, 0xc4, 0x28,
+ 0xba, 0xe2, 0x3b, 0x8a, 0x21, 0x46, 0x01, 0x06, 0x05, 0x18, 0x1c, 0xc5,
+ 0x08, 0x85, 0x1d, 0xd8, 0xc1, 0x1e, 0xda, 0xc1, 0x0d, 0xd2, 0x81, 0x1c,
+ 0xca, 0xc1, 0x1d, 0xe8, 0x61, 0x4a, 0x10, 0x8c, 0x58, 0xc2, 0x21, 0x1d,
+ 0xe4, 0xc1, 0x0d, 0xec, 0xa1, 0x1c, 0xe4, 0x61, 0x1e, 0xd2, 0xe1, 0x1d,
+ 0xdc, 0x61, 0x4a, 0x20, 0x8c, 0xa0, 0xc2, 0x21, 0x1d, 0xe4, 0xc1, 0x0d,
+ 0xd8, 0x21, 0x1c, 0xdc, 0xe1, 0x1c, 0xea, 0x21, 0x1c, 0xce, 0xa1, 0x1c,
+ 0x7e, 0xc1, 0x1e, 0xca, 0x41, 0x1e, 0xe6, 0x21, 0x1d, 0xde, 0xc1, 0x1d,
+ 0xa6, 0x04, 0xc4, 0x88, 0x29, 0x1c, 0xd2, 0x41, 0x1e, 0xdc, 0x60, 0x1c,
+ 0xde, 0xa1, 0x1d, 0xe0, 0x21, 0x1d, 0xd8, 0xa1, 0x1c, 0x7e, 0xe1, 0x1d,
+ 0xe0, 0x81, 0x1e, 0xd2, 0xe1, 0x1d, 0xdc, 0x61, 0x1e, 0xa6, 0x10, 0x06,
+ 0xa2, 0x30, 0x23, 0x98, 0x70, 0x48, 0x07, 0x79, 0x70, 0x03, 0x73, 0x90,
+ 0x87, 0x70, 0x38, 0x87, 0x76, 0x28, 0x07, 0x77, 0xa0, 0x87, 0x29, 0x01,
+ 0x07, 0x00, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00,
+ 0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66, 0x14, 0x01, 0x3d, 0x88,
+ 0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07, 0x79, 0x78, 0x07, 0x73,
+ 0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e,
+ 0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce, 0xa1, 0x1c, 0x66, 0x30,
+ 0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b, 0xcc, 0x03, 0x3d, 0xc8,
+ 0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c, 0x74, 0x70, 0x07, 0x7b,
+ 0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07, 0x7a, 0x70, 0x03, 0x76,
+ 0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11, 0x0e, 0xec, 0x90, 0x0e,
+ 0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0, 0x0e, 0xf0, 0x50, 0x0e,
+ 0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8, 0x21, 0x1d, 0xc2, 0x61,
+ 0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xb4,
+ 0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b, 0xcc, 0xf0, 0x14, 0x76,
+ 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87, 0x72, 0x68, 0x07, 0x37,
+ 0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07, 0x76, 0x28, 0x07, 0x76,
+ 0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87, 0x5f, 0x08, 0x87, 0x71,
+ 0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81, 0x2c, 0xee, 0xf0, 0x0e,
+ 0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30, 0x03, 0x62, 0xc8, 0xa1,
+ 0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xdc, 0x61,
+ 0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca, 0x61, 0x06, 0xd6, 0x90,
+ 0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39, 0xc8, 0x43, 0x39, 0xb8,
+ 0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b, 0x94, 0xc3, 0x2f, 0xbc,
+ 0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b, 0xb0, 0xc3, 0x0c, 0xc7,
+ 0x69, 0x87, 0x70, 0x58, 0x87, 0x72, 0x70, 0x83, 0x74, 0x68, 0x07, 0x78,
+ 0x60, 0x87, 0x74, 0x18, 0x87, 0x74, 0xa0, 0x87, 0x19, 0xce, 0x53, 0x0f,
+ 0xee, 0x00, 0x0f, 0xf2, 0x50, 0x0e, 0xe4, 0x90, 0x0e, 0xe3, 0x40, 0x0f,
+ 0xe1, 0x20, 0x0e, 0xec, 0x50, 0x0e, 0x33, 0x20, 0x28, 0x1d, 0xdc, 0xc1,
+ 0x1e, 0xc2, 0x41, 0x1e, 0xd2, 0x21, 0x1c, 0xdc, 0x81, 0x1e, 0xdc, 0xe0,
+ 0x1c, 0xe4, 0xe1, 0x1d, 0xea, 0x01, 0x1e, 0x66, 0x18, 0x51, 0x38, 0xb0,
+ 0x43, 0x3a, 0x9c, 0x83, 0x3b, 0xcc, 0x50, 0x24, 0x76, 0x60, 0x07, 0x7b,
+ 0x68, 0x07, 0x37, 0x60, 0x87, 0x77, 0x78, 0x07, 0x78, 0x98, 0x51, 0x4c,
+ 0xf4, 0x90, 0x0f, 0xf0, 0x50, 0x0e, 0x00, 0x00, 0x71, 0x20, 0x00, 0x00,
+ 0x05, 0x00, 0x00, 0x00, 0x06, 0x20, 0xb1, 0x5d, 0xf9, 0xb3, 0xce, 0x82,
+ 0x0c, 0x7f, 0x11, 0x01, 0x06, 0x43, 0x34, 0x13, 0x00, 0x00, 0x00, 0x00,
+ 0x61, 0x20, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x13, 0x04, 0x01, 0x05,
+ 0x25, 0x83, 0x80, 0x18, 0x02, 0x00, 0x00, 0x00, 0x5b, 0x06, 0x20, 0x08,
+ 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xde, 0xc0, 0x17, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
+ 0x60, 0x0a, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x42, 0x43, 0xc0, 0xde,
+ 0x21, 0x0c, 0x00, 0x00, 0x95, 0x02, 0x00, 0x00, 0x0b, 0x82, 0x20, 0x00,
+ 0x02, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91,
+ 0x41, 0xc8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0c,
+ 0x25, 0x05, 0x08, 0x19, 0x1e, 0x04, 0x8b, 0x62, 0x80, 0x14, 0x45, 0x02,
+ 0x42, 0x92, 0x0b, 0x42, 0xa4, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x49,
+ 0x0a, 0x32, 0x44, 0x24, 0x48, 0x0a, 0x90, 0x21, 0x23, 0xc4, 0x52, 0x80,
+ 0x0c, 0x19, 0x21, 0x72, 0x24, 0x07, 0xc8, 0x48, 0x11, 0x62, 0xa8, 0xa0,
+ 0xa8, 0x40, 0xc6, 0xf0, 0x01, 0x00, 0x00, 0x00, 0x51, 0x18, 0x00, 0x00,
+ 0x89, 0x00, 0x00, 0x00, 0x1b, 0x8c, 0x60, 0x00, 0x16, 0xa0, 0xda, 0x60,
+ 0x08, 0x05, 0xb0, 0x00, 0xd5, 0x06, 0x73, 0x19, 0xfe, 0xff, 0xff, 0xff,
+ 0x7f, 0x00, 0x18, 0x40, 0x02, 0x2a, 0x62, 0x1c, 0xde, 0x41, 0x1e, 0xe4,
+ 0xa1, 0x1c, 0xc6, 0x81, 0x1e, 0xd8, 0x21, 0x1f, 0xda, 0x40, 0x1e, 0xde,
+ 0xa1, 0x1e, 0xdc, 0x81, 0x1c, 0xca, 0x81, 0x1c, 0xda, 0x80, 0x1c, 0xd2,
+ 0xc1, 0x1e, 0xd2, 0x81, 0x1c, 0xca, 0xa1, 0x0d, 0xe6, 0x21, 0x1e, 0xe4,
+ 0x81, 0x1e, 0xda, 0xc0, 0x1c, 0xe0, 0xa1, 0x0d, 0xda, 0x21, 0x1c, 0xe8,
+ 0x01, 0x1d, 0x00, 0x73, 0x08, 0x07, 0x76, 0x98, 0x87, 0x72, 0x00, 0x08,
+ 0x72, 0x48, 0x87, 0x79, 0x08, 0x07, 0x71, 0x60, 0x87, 0x72, 0x68, 0x03,
+ 0x7a, 0x08, 0x87, 0x74, 0x60, 0x87, 0x36, 0x18, 0x87, 0x70, 0x60, 0x07,
+ 0x76, 0x98, 0x07, 0xc0, 0x1c, 0xc2, 0x81, 0x1d, 0xe6, 0xa1, 0x1c, 0x00,
+ 0x82, 0x1d, 0xca, 0x61, 0x1e, 0xe6, 0xa1, 0x0d, 0xe0, 0x41, 0x1e, 0xca,
+ 0x61, 0x1c, 0xd2, 0x61, 0x1e, 0xca, 0xa1, 0x0d, 0xcc, 0x01, 0x1e, 0xda,
+ 0x21, 0x1c, 0xc8, 0x01, 0xa0, 0x07, 0x79, 0xa8, 0x87, 0x72, 0x00, 0x08,
+ 0x77, 0x78, 0x87, 0x36, 0x30, 0x07, 0x79, 0x08, 0x87, 0x76, 0x28, 0x87,
+ 0x36, 0x80, 0x87, 0x77, 0x48, 0x07, 0x77, 0xa0, 0x87, 0x72, 0x90, 0x87,
+ 0x36, 0x28, 0x07, 0x76, 0x48, 0x87, 0x76, 0x00, 0xe8, 0x41, 0x1e, 0xea,
+ 0xa1, 0x1c, 0x80, 0xc1, 0x1d, 0xde, 0xa1, 0x0d, 0xcc, 0x41, 0x1e, 0xc2,
+ 0xa1, 0x1d, 0xca, 0xa1, 0x0d, 0xe0, 0xe1, 0x1d, 0xd2, 0xc1, 0x1d, 0xe8,
+ 0xa1, 0x1c, 0xe4, 0xa1, 0x0d, 0xca, 0x81, 0x1d, 0xd2, 0xa1, 0x1d, 0xda,
+ 0xc0, 0x1d, 0xde, 0xc1, 0x1d, 0xda, 0x80, 0x1d, 0xca, 0x21, 0x1c, 0xcc,
+ 0x01, 0x20, 0xdc, 0xe1, 0x1d, 0xda, 0x20, 0x1d, 0xdc, 0xc1, 0x1c, 0xe6,
+ 0xa1, 0x0d, 0xcc, 0x01, 0x1e, 0xda, 0xa0, 0x1d, 0xc2, 0x81, 0x1e, 0xd0,
+ 0x01, 0xa0, 0x07, 0x79, 0xa8, 0x87, 0x72, 0x00, 0x08, 0x77, 0x78, 0x87,
+ 0x36, 0x50, 0x87, 0x7a, 0x68, 0x07, 0x78, 0x68, 0x03, 0x7a, 0x08, 0x07,
+ 0x71, 0x60, 0x87, 0x72, 0x98, 0x07, 0xc0, 0x1c, 0xc2, 0x81, 0x1d, 0xe6,
+ 0xa1, 0x1c, 0x00, 0xc2, 0x1d, 0xde, 0xa1, 0x0d, 0xdc, 0x21, 0x1c, 0xdc,
+ 0x61, 0x1e, 0xda, 0xc0, 0x1c, 0xe0, 0xa1, 0x0d, 0xda, 0x21, 0x1c, 0xe8,
+ 0x01, 0x1d, 0x00, 0x7a, 0x90, 0x87, 0x7a, 0x28, 0x07, 0x80, 0x70, 0x87,
+ 0x77, 0x68, 0x83, 0x79, 0x48, 0x87, 0x73, 0x70, 0x87, 0x72, 0x20, 0x87,
+ 0x36, 0xd0, 0x87, 0x72, 0x90, 0x87, 0x77, 0x98, 0x87, 0x36, 0x30, 0x07,
+ 0x78, 0x68, 0x83, 0x76, 0x08, 0x07, 0x7a, 0x40, 0x07, 0xc0, 0x1c, 0xc2,
+ 0x81, 0x1d, 0xe6, 0xa1, 0x1c, 0x00, 0x62, 0x1e, 0xe8, 0x21, 0x1c, 0xc6,
+ 0x61, 0x1d, 0xda, 0x00, 0x1e, 0xe4, 0xe1, 0x1d, 0xe8, 0xa1, 0x1c, 0xc6,
+ 0x81, 0x1e, 0xde, 0x41, 0x1e, 0xda, 0x40, 0x1c, 0xea, 0xc1, 0x1c, 0xcc,
+ 0xa1, 0x1c, 0xe4, 0xa1, 0x0d, 0xe6, 0x21, 0x1d, 0xf4, 0xa1, 0x1c, 0x00,
+ 0x3c, 0x00, 0x08, 0x7a, 0x08, 0x07, 0x79, 0x38, 0x87, 0x72, 0xa0, 0x87,
+ 0x36, 0x30, 0x87, 0x72, 0x08, 0x07, 0x7a, 0xa8, 0x07, 0x79, 0x28, 0x87,
+ 0x79, 0x00, 0xda, 0xc0, 0x1c, 0xe0, 0x21, 0x0e, 0xec, 0x00, 0x20, 0xea,
+ 0xc1, 0x1d, 0xe6, 0x21, 0x1c, 0xcc, 0xa1, 0x1c, 0xda, 0xc0, 0x1c, 0xe0,
+ 0xa1, 0x0d, 0xda, 0x21, 0x1c, 0xe8, 0x01, 0x1d, 0x00, 0x7a, 0x90, 0x87,
+ 0x7a, 0x28, 0x07, 0x80, 0xa8, 0x87, 0x79, 0x28, 0x87, 0x36, 0x98, 0x87,
+ 0x77, 0x30, 0x07, 0x7a, 0x68, 0x03, 0x73, 0x60, 0x87, 0x77, 0x08, 0x07,
+ 0x7a, 0x00, 0xcc, 0x21, 0x1c, 0xd8, 0x61, 0x1e, 0xca, 0x01, 0xd8, 0x40,
+ 0x10, 0x01, 0xb0, 0x6c, 0x20, 0x0a, 0x01, 0x58, 0x36, 0x20, 0xc6, 0xff,
+ 0xff, 0xff, 0xff, 0x0f, 0x00, 0x03, 0x48, 0x40, 0x05, 0x00, 0x00, 0x00,
+ 0x49, 0x18, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x13, 0x86, 0x40, 0x18,
+ 0x26, 0x0c, 0x44, 0x61, 0x00, 0x00, 0x00, 0x00, 0x89, 0x20, 0x00, 0x00,
+ 0x1e, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09, 0x20, 0x64, 0x85, 0x04,
+ 0x93, 0x22, 0xa4, 0x84, 0x04, 0x93, 0x22, 0xe3, 0x84, 0xa1, 0x90, 0x14,
+ 0x12, 0x4c, 0x8a, 0x8c, 0x0b, 0x84, 0xa4, 0x4c, 0x10, 0x48, 0x33, 0x00,
+ 0xc3, 0x08, 0x04, 0x30, 0x8c, 0x20, 0x00, 0x83, 0x08, 0x81, 0x70, 0x94,
+ 0x34, 0x45, 0x94, 0x30, 0xf9, 0xff, 0x44, 0x5c, 0x13, 0x15, 0x11, 0xbf,
+ 0x3d, 0xfc, 0xd3, 0x18, 0x01, 0x30, 0x88, 0x40, 0x04, 0x17, 0x49, 0x53,
+ 0x44, 0x09, 0x93, 0xff, 0x4b, 0x00, 0xf3, 0x2c, 0x44, 0xf4, 0x4f, 0x63,
+ 0x04, 0xc0, 0x20, 0x82, 0x21, 0x14, 0x23, 0x04, 0x31, 0xca, 0x21, 0x34,
+ 0x47, 0x10, 0xcc, 0x11, 0x80, 0xc1, 0x30, 0x82, 0xb0, 0x14, 0x24, 0x94,
+ 0x23, 0x14, 0x53, 0x80, 0xda, 0x40, 0xc0, 0x1c, 0x01, 0x28, 0x8c, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x13, 0xa8, 0x70, 0x48, 0x07, 0x79, 0xb0, 0x03,
+ 0x3a, 0x68, 0x83, 0x70, 0x80, 0x07, 0x78, 0x60, 0x87, 0x72, 0x68, 0x83,
+ 0x74, 0x78, 0x87, 0x79, 0xc8, 0x03, 0x37, 0x80, 0x03, 0x37, 0x80, 0x83,
+ 0x0d, 0xef, 0x51, 0x0e, 0x6d, 0x00, 0x0f, 0x7a, 0x60, 0x07, 0x74, 0xa0,
+ 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe9, 0x10,
+ 0x07, 0x7a, 0x80, 0x07, 0x7a, 0x80, 0x07, 0x6d, 0x90, 0x0e, 0x78, 0xa0,
+ 0x07, 0x78, 0xa0, 0x07, 0x78, 0xd0, 0x06, 0xe9, 0x10, 0x07, 0x76, 0xa0,
+ 0x07, 0x71, 0x60, 0x07, 0x7a, 0x10, 0x07, 0x76, 0xd0, 0x06, 0xe9, 0x30,
+ 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0,
+ 0x06, 0xe9, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60,
+ 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20,
+ 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xe6, 0x60, 0x07, 0x74, 0xa0,
+ 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x80,
+ 0x07, 0x70, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20,
+ 0x07, 0x78, 0xd0, 0x06, 0xf6, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x60,
+ 0x07, 0x7a, 0x10, 0x07, 0x76, 0xd0, 0x06, 0xf6, 0x20, 0x07, 0x74, 0xa0,
+ 0x07, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xf6, 0x30,
+ 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0,
+ 0x06, 0xf6, 0x40, 0x07, 0x78, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60,
+ 0x07, 0x74, 0xd0, 0x06, 0xf6, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40,
+ 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xf6, 0x90, 0x07, 0x76, 0xa0,
+ 0x07, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0,
+ 0x06, 0xf6, 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80,
+ 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x90,
+ 0x07, 0x72, 0xa0, 0x07, 0x72, 0x50, 0x07, 0x76, 0xa0, 0x07, 0x72, 0x50,
+ 0x07, 0x76, 0xd0, 0x06, 0xf6, 0x20, 0x07, 0x75, 0x60, 0x07, 0x7a, 0x20,
+ 0x07, 0x75, 0x60, 0x07, 0x7a, 0x20, 0x07, 0x75, 0x60, 0x07, 0x6d, 0x60,
+ 0x0f, 0x75, 0x10, 0x07, 0x72, 0xa0, 0x07, 0x75, 0x10, 0x07, 0x72, 0xa0,
+ 0x07, 0x75, 0x10, 0x07, 0x72, 0xd0, 0x06, 0xf6, 0x10, 0x07, 0x70, 0x20,
+ 0x07, 0x74, 0xa0, 0x07, 0x71, 0x00, 0x07, 0x72, 0x40, 0x07, 0x7a, 0x10,
+ 0x07, 0x70, 0x20, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x80, 0x07, 0x70, 0xa0,
+ 0x07, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0,
+ 0x06, 0xee, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x73, 0x20,
+ 0x07, 0x43, 0x98, 0x04, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
+ 0x21, 0x8c, 0x03, 0x04, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x16,
+ 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x10,
+ 0x19, 0x11, 0x4c, 0x90, 0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0x5a,
+ 0x25, 0x30, 0x02, 0x50, 0x20, 0x05, 0x51, 0x04, 0x65, 0x50, 0x08, 0x04,
+ 0x47, 0x00, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00,
+ 0x1a, 0x03, 0x4c, 0x10, 0xd7, 0x20, 0x08, 0x0e, 0x8e, 0xad, 0x0c, 0x84,
+ 0x89, 0xc9, 0xaa, 0x09, 0xc4, 0xae, 0x4c, 0x6e, 0x2e, 0xed, 0xcd, 0x0d,
+ 0x04, 0x07, 0x46, 0xc6, 0x25, 0x06, 0x04, 0xa5, 0xad, 0x8c, 0x2e, 0x8c,
+ 0xcd, 0xac, 0xac, 0x05, 0x07, 0x46, 0xc6, 0x25, 0xc6, 0x65, 0x86, 0x26,
+ 0x65, 0x88, 0xf0, 0x00, 0x43, 0x8c, 0x45, 0x58, 0x8a, 0x65, 0x60, 0xd1,
+ 0x54, 0x46, 0x17, 0xc6, 0x36, 0x04, 0x79, 0x86, 0x45, 0x58, 0x84, 0x65,
+ 0xe0, 0x16, 0x96, 0x26, 0xe7, 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56,
+ 0xe6, 0x42, 0x56, 0xe6, 0xf6, 0x26, 0xd7, 0x36, 0xf7, 0x45, 0x96, 0x36,
+ 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0x78, 0x0a, 0x72, 0x61, 0x69, 0x72,
+ 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x2e, 0x66, 0x61, 0x73,
+ 0x74, 0x5f, 0x6d, 0x61, 0x74, 0x68, 0x5f, 0x65, 0x6e, 0x61, 0x62, 0x6c,
+ 0x65, 0x43, 0x84, 0xe7, 0x20, 0x19, 0x84, 0xa5, 0xc9, 0xb9, 0x8c, 0xbd,
+ 0xb5, 0xc1, 0xa5, 0xb1, 0x95, 0xb9, 0x98, 0xc9, 0x85, 0xb5, 0x95, 0x89,
+ 0xd5, 0x99, 0x99, 0x95, 0xc9, 0x7d, 0x99, 0x95, 0xd1, 0x8d, 0xa1, 0x7d,
+ 0x95, 0xb9, 0x85, 0x89, 0xb1, 0x95, 0x0d, 0x11, 0x9e, 0x84, 0x61, 0x10,
+ 0x96, 0x26, 0xe7, 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56, 0xe6, 0xe2,
+ 0x16, 0x46, 0x97, 0x66, 0x57, 0xf6, 0x45, 0xf6, 0x56, 0x27, 0xc6, 0x56,
+ 0xf6, 0x45, 0x96, 0x36, 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0x78, 0x16,
+ 0x46, 0x61, 0x69, 0x72, 0x2e, 0x72, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x5f,
+ 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x8c, 0xc2, 0xd2, 0xe4, 0x5c, 0xc2,
+ 0xe4, 0xce, 0xbe, 0xe8, 0xf2, 0xe0, 0xca, 0xbe, 0xdc, 0xc2, 0xda, 0xca,
+ 0x68, 0x98, 0xb1, 0xbd, 0x85, 0xd1, 0xd1, 0x0c, 0x41, 0x9e, 0x66, 0x19,
+ 0x1e, 0xe7, 0x79, 0x86, 0x08, 0x0f, 0x44, 0x26, 0x2c, 0x4d, 0xce, 0x05,
+ 0xee, 0x6d, 0x2e, 0x8d, 0x2e, 0xed, 0xcd, 0x8d, 0x4a, 0x58, 0x9a, 0x9c,
+ 0xcb, 0x58, 0x99, 0x1b, 0x5d, 0x99, 0x1c, 0xa5, 0xb0, 0x34, 0x39, 0x17,
+ 0xb7, 0xb7, 0x2f, 0xb8, 0x32, 0xb9, 0x39, 0xb8, 0xb2, 0x31, 0xba, 0x34,
+ 0xbb, 0x32, 0x32, 0x61, 0x69, 0x72, 0x2e, 0x61, 0x72, 0x67, 0x5f, 0x6e,
+ 0x61, 0x6d, 0x65, 0x44, 0xe0, 0xde, 0xe6, 0xd2, 0xe8, 0xd2, 0xde, 0xdc,
+ 0x86, 0x40, 0xcb, 0xf0, 0x48, 0xcf, 0xf4, 0x50, 0x8f, 0xf3, 0x3c, 0x4f,
+ 0xf5, 0x58, 0x94, 0xc2, 0xd2, 0xe4, 0x5c, 0xcc, 0xe4, 0xc2, 0xce, 0xda,
+ 0xca, 0xdc, 0xe8, 0xbe, 0xd2, 0xdc, 0xe0, 0xea, 0xe8, 0x98, 0x9d, 0x95,
+ 0xb9, 0x95, 0xc9, 0x85, 0xd1, 0x95, 0x91, 0xa1, 0xe0, 0xd0, 0x95, 0xe1,
+ 0x8d, 0xbd, 0xbd, 0xc9, 0x91, 0x11, 0xd9, 0xc9, 0x7c, 0x99, 0xa5, 0xf0,
+ 0x09, 0x4b, 0x93, 0x73, 0x81, 0x2b, 0x93, 0x9b, 0x83, 0x2b, 0x1b, 0xa3,
+ 0x4b, 0xb3, 0x2b, 0xa3, 0x61, 0xc6, 0xf6, 0x16, 0x46, 0x27, 0x43, 0x84,
+ 0xae, 0x0c, 0x6f, 0xec, 0xed, 0x4d, 0x8e, 0x6c, 0x88, 0xb4, 0x08, 0x0f,
+ 0xf6, 0x64, 0xcf, 0xf4, 0x68, 0x8f, 0xf3, 0x6c, 0x4f, 0xf5, 0x70, 0x54,
+ 0xc2, 0xd2, 0xe4, 0x5c, 0xc4, 0xea, 0xcc, 0xcc, 0xca, 0xe4, 0xf8, 0x84,
+ 0xa5, 0xc9, 0xb9, 0x88, 0xd5, 0x99, 0x99, 0x95, 0xc9, 0x7d, 0xcd, 0xa5,
+ 0xe9, 0x95, 0x51, 0x0a, 0x4b, 0x93, 0x73, 0x61, 0x7b, 0x1b, 0x0b, 0xa3,
+ 0x4b, 0x7b, 0x73, 0xfb, 0x4a, 0x73, 0x23, 0x2b, 0xc3, 0x23, 0x12, 0x96,
+ 0x26, 0xe7, 0x22, 0x57, 0x16, 0x46, 0xc6, 0x28, 0x2c, 0x4d, 0xce, 0x25,
+ 0x4c, 0xee, 0xec, 0x8b, 0x2e, 0x0f, 0xae, 0xec, 0x6b, 0x2e, 0x4d, 0xaf,
+ 0x8c, 0x57, 0x58, 0x9a, 0x9c, 0x4b, 0x98, 0xdc, 0xd9, 0x17, 0x5d, 0x1e,
+ 0x5c, 0xd9, 0x57, 0x18, 0x5b, 0xda, 0x99, 0xdb, 0xd7, 0x5c, 0x9a, 0x5e,
+ 0x19, 0x87, 0xb1, 0x37, 0xb6, 0x21, 0x60, 0xb0, 0x18, 0x8f, 0xf7, 0x7c,
+ 0x0b, 0xf1, 0x80, 0xc1, 0x32, 0x2c, 0xc2, 0x13, 0x06, 0x8f, 0x18, 0x2c,
+ 0xc4, 0x33, 0x06, 0x0b, 0xf1, 0x38, 0xcf, 0xf3, 0x54, 0x0f, 0x19, 0x70,
+ 0x09, 0x4b, 0x93, 0x73, 0xa1, 0x2b, 0xc3, 0xa3, 0xab, 0x93, 0x2b, 0xa3,
+ 0x12, 0x96, 0x26, 0xe7, 0x32, 0x17, 0xd6, 0x06, 0xc7, 0x56, 0x46, 0x8c,
+ 0xae, 0x0c, 0x8f, 0xae, 0x4e, 0xae, 0x4c, 0x86, 0x8c, 0xc7, 0x8c, 0xed,
+ 0x2d, 0x8c, 0x8e, 0x05, 0x64, 0x2e, 0xac, 0x0d, 0x8e, 0xad, 0xcc, 0x87,
+ 0x03, 0x5d, 0x19, 0xde, 0x10, 0x6a, 0x39, 0x1e, 0x33, 0x78, 0xc0, 0x60,
+ 0x19, 0x16, 0xe1, 0x39, 0x83, 0xc7, 0x79, 0xd0, 0xe0, 0xa9, 0x9e, 0x34,
+ 0xe0, 0x12, 0x96, 0x26, 0xe7, 0x32, 0x17, 0xd6, 0x06, 0xc7, 0x56, 0x26,
+ 0xc7, 0x63, 0x2e, 0xac, 0x0d, 0x8e, 0xad, 0x4c, 0x8e, 0xc1, 0xdc, 0x10,
+ 0x69, 0x41, 0x9e, 0x35, 0x78, 0xc0, 0x60, 0x19, 0x16, 0xe1, 0x71, 0x1e,
+ 0x36, 0x78, 0xaa, 0xa7, 0x0d, 0x86, 0x28, 0xcf, 0xf5, 0x74, 0x4f, 0x19,
+ 0x3c, 0x6a, 0xf0, 0xb8, 0xc1, 0x10, 0x23, 0x01, 0x9e, 0xe8, 0x79, 0x03,
+ 0x3e, 0x6f, 0x6d, 0x6e, 0x69, 0x70, 0x6f, 0x74, 0x65, 0x6e, 0x74, 0x20,
+ 0x63, 0x68, 0x61, 0x72, 0x7c, 0xa6, 0xd2, 0xda, 0xe0, 0xd8, 0xca, 0x40,
+ 0x86, 0x56, 0x56, 0x40, 0xa8, 0x84, 0x82, 0x82, 0x86, 0x08, 0x8f, 0x1c,
+ 0x0c, 0x31, 0x9e, 0x38, 0x78, 0xe6, 0x00, 0x4a, 0x86, 0x18, 0x0f, 0x1d,
+ 0x3c, 0x74, 0x00, 0x25, 0x23, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07,
+ 0x37, 0x48, 0x07, 0x72, 0x28, 0x07, 0x77, 0xa0, 0x87, 0x29, 0x41, 0x30,
+ 0x62, 0x09, 0x87, 0x74, 0x90, 0x07, 0x37, 0xb0, 0x87, 0x72, 0x90, 0x87,
+ 0x79, 0x48, 0x87, 0x77, 0x70, 0x87, 0x29, 0x81, 0x30, 0x82, 0x0a, 0x87,
+ 0x74, 0x90, 0x07, 0x37, 0x60, 0x87, 0x70, 0x70, 0x87, 0x73, 0xa8, 0x87,
+ 0x70, 0x38, 0x87, 0x72, 0xf8, 0x05, 0x7b, 0x28, 0x07, 0x79, 0x98, 0x87,
+ 0x74, 0x78, 0x07, 0x77, 0x98, 0x12, 0x10, 0x23, 0xa6, 0x70, 0x48, 0x07,
+ 0x79, 0x70, 0x83, 0x71, 0x78, 0x87, 0x76, 0x80, 0x87, 0x74, 0x60, 0x87,
+ 0x72, 0xf8, 0x85, 0x77, 0x80, 0x07, 0x7a, 0x48, 0x87, 0x77, 0x70, 0x87,
+ 0x79, 0x98, 0x42, 0x18, 0x88, 0xc2, 0x8c, 0x60, 0xc2, 0x21, 0x1d, 0xe4,
+ 0xc1, 0x0d, 0xcc, 0x41, 0x1e, 0xc2, 0xe1, 0x1c, 0xda, 0xa1, 0x1c, 0xdc,
+ 0x81, 0x1e, 0xa6, 0x04, 0x70, 0x00, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
+ 0x5c, 0x00, 0x00, 0x00, 0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66,
+ 0x14, 0x01, 0x3d, 0x88, 0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07,
+ 0x79, 0x78, 0x07, 0x73, 0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10,
+ 0x0e, 0xf4, 0x80, 0x0e, 0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce,
+ 0xa1, 0x1c, 0x66, 0x30, 0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b,
+ 0xcc, 0x03, 0x3d, 0xc8, 0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c,
+ 0x74, 0x70, 0x07, 0x7b, 0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07,
+ 0x7a, 0x70, 0x03, 0x76, 0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11,
+ 0x0e, 0xec, 0x90, 0x0e, 0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0,
+ 0x0e, 0xf0, 0x50, 0x0e, 0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8,
+ 0x21, 0x1d, 0xc2, 0x61, 0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b,
+ 0xd0, 0x43, 0x39, 0xb4, 0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b,
+ 0xcc, 0xf0, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87,
+ 0x72, 0x68, 0x07, 0x37, 0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07,
+ 0x76, 0x28, 0x07, 0x76, 0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87,
+ 0x5f, 0x08, 0x87, 0x71, 0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81,
+ 0x2c, 0xee, 0xf0, 0x0e, 0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30,
+ 0x03, 0x62, 0xc8, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4,
+ 0xa1, 0x1c, 0xdc, 0x61, 0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca,
+ 0x61, 0x06, 0xd6, 0x90, 0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39,
+ 0xc8, 0x43, 0x39, 0xb8, 0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b,
+ 0x94, 0xc3, 0x2f, 0xbc, 0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b,
+ 0xb0, 0xc3, 0x0c, 0xc7, 0x69, 0x87, 0x70, 0x58, 0x87, 0x72, 0x70, 0x83,
+ 0x74, 0x68, 0x07, 0x78, 0x60, 0x87, 0x74, 0x18, 0x87, 0x74, 0xa0, 0x87,
+ 0x19, 0xce, 0x53, 0x0f, 0xee, 0x00, 0x0f, 0xf2, 0x50, 0x0e, 0xe4, 0x90,
+ 0x0e, 0xe3, 0x40, 0x0f, 0xe1, 0x20, 0x0e, 0xec, 0x50, 0x0e, 0x33, 0x20,
+ 0x28, 0x1d, 0xdc, 0xc1, 0x1e, 0xc2, 0x41, 0x1e, 0xd2, 0x21, 0x1c, 0xdc,
+ 0x81, 0x1e, 0xdc, 0xe0, 0x1c, 0xe4, 0xe1, 0x1d, 0xea, 0x01, 0x1e, 0x66,
+ 0x18, 0x51, 0x38, 0xb0, 0x43, 0x3a, 0x9c, 0x83, 0x3b, 0xcc, 0x50, 0x24,
+ 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x60, 0x87, 0x77, 0x78, 0x07,
+ 0x78, 0x98, 0x51, 0x4c, 0xf4, 0x90, 0x0f, 0xf0, 0x50, 0x0e, 0x00, 0x00,
+ 0x71, 0x20, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x06, 0x10, 0xb1, 0x5d,
+ 0xf9, 0x73, 0xce, 0x83, 0xfd, 0x45, 0x04, 0x18, 0x0c, 0xd1, 0x4c, 0x16,
+ 0xb0, 0x01, 0x48, 0xe4, 0x4b, 0x00, 0xf3, 0x2c, 0xc4, 0x3f, 0x11, 0xd7,
+ 0x44, 0x45, 0xc4, 0x6f, 0x0f, 0x7e, 0x85, 0x17, 0xb7, 0x0d, 0x00, 0x00,
+ 0x61, 0x20, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x13, 0x04, 0x41, 0x2c,
+ 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xc4, 0x46, 0x00, 0x48,
+ 0xd5, 0xc0, 0x08, 0x00, 0x81, 0x11, 0x00, 0x00, 0x23, 0x06, 0x8a, 0x10,
+ 0x48, 0x46, 0x81, 0x0c, 0x84, 0x10, 0x10, 0x52, 0x2c, 0x10, 0xe4, 0x93,
+ 0x41, 0x40, 0x0c, 0x00, 0x02, 0x00, 0x00, 0x00, 0x5b, 0x86, 0x20, 0xa8,
+ 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xde, 0xc0, 0x17, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
+ 0x6c, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x42, 0x43, 0xc0, 0xde,
+ 0x21, 0x0c, 0x00, 0x00, 0x98, 0x03, 0x00, 0x00, 0x0b, 0x82, 0x20, 0x00,
+ 0x02, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91,
+ 0x41, 0xc8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0c,
+ 0x25, 0x05, 0x08, 0x19, 0x1e, 0x04, 0x8b, 0x62, 0x80, 0x14, 0x45, 0x02,
+ 0x42, 0x92, 0x0b, 0x42, 0xa4, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x49,
+ 0x0a, 0x32, 0x44, 0x24, 0x48, 0x0a, 0x90, 0x21, 0x23, 0xc4, 0x52, 0x80,
+ 0x0c, 0x19, 0x21, 0x72, 0x24, 0x07, 0xc8, 0x48, 0x11, 0x62, 0xa8, 0xa0,
+ 0xa8, 0x40, 0xc6, 0xf0, 0x01, 0x00, 0x00, 0x00, 0x51, 0x18, 0x00, 0x00,
+ 0x03, 0x01, 0x00, 0x00, 0x1b, 0x8c, 0x60, 0x00, 0x16, 0xa0, 0xda, 0x60,
+ 0x08, 0x04, 0xb0, 0x00, 0xd5, 0x06, 0x63, 0x38, 0x80, 0x05, 0xa8, 0x36,
+ 0x90, 0x0b, 0xf1, 0xff, 0xff, 0xff, 0xff, 0x03, 0xc0, 0x00, 0x12, 0x31,
+ 0x0e, 0xef, 0x20, 0x0f, 0xf2, 0x50, 0x0e, 0xe3, 0x40, 0x0f, 0xec, 0x90,
+ 0x0f, 0x6d, 0x20, 0x0f, 0xef, 0x50, 0x0f, 0xee, 0x40, 0x0e, 0xe5, 0x40,
+ 0x0e, 0x6d, 0x40, 0x0e, 0xe9, 0x60, 0x0f, 0xe9, 0x40, 0x0e, 0xe5, 0xd0,
+ 0x06, 0xf3, 0x10, 0x0f, 0xf2, 0x40, 0x0f, 0x6d, 0x60, 0x0e, 0xf0, 0xd0,
+ 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x80, 0x39, 0x84, 0x03, 0x3b,
+ 0xcc, 0x43, 0x39, 0x00, 0x04, 0x39, 0xa4, 0xc3, 0x3c, 0x84, 0x83, 0x38,
+ 0xb0, 0x43, 0x39, 0xb4, 0x01, 0x3d, 0x84, 0x43, 0x3a, 0xb0, 0x43, 0x1b,
+ 0x8c, 0x43, 0x38, 0xb0, 0x03, 0x3b, 0xcc, 0x03, 0x60, 0x0e, 0xe1, 0xc0,
+ 0x0e, 0xf3, 0x50, 0x0e, 0x00, 0xc1, 0x0e, 0xe5, 0x30, 0x0f, 0xf3, 0xd0,
+ 0x06, 0xf0, 0x20, 0x0f, 0xe5, 0x30, 0x0e, 0xe9, 0x30, 0x0f, 0xe5, 0xd0,
+ 0x06, 0xe6, 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xe4, 0x00, 0xd0, 0x83, 0x3c,
+ 0xd4, 0x43, 0x39, 0x00, 0x84, 0x3b, 0xbc, 0x43, 0x1b, 0x98, 0x83, 0x3c,
+ 0x84, 0x43, 0x3b, 0x94, 0x43, 0x1b, 0xc0, 0xc3, 0x3b, 0xa4, 0x83, 0x3b,
+ 0xd0, 0x43, 0x39, 0xc8, 0x43, 0x1b, 0x94, 0x03, 0x3b, 0xa4, 0x43, 0x3b,
+ 0x00, 0xf4, 0x20, 0x0f, 0xf5, 0x50, 0x0e, 0xc0, 0xe0, 0x0e, 0xef, 0xd0,
+ 0x06, 0xe6, 0x20, 0x0f, 0xe1, 0xd0, 0x0e, 0xe5, 0xd0, 0x06, 0xf0, 0xf0,
+ 0x0e, 0xe9, 0xe0, 0x0e, 0xf4, 0x50, 0x0e, 0xf2, 0xd0, 0x06, 0xe5, 0xc0,
+ 0x0e, 0xe9, 0xd0, 0x0e, 0x6d, 0xe0, 0x0e, 0xef, 0xe0, 0x0e, 0x6d, 0xc0,
+ 0x0e, 0xe5, 0x10, 0x0e, 0xe6, 0x00, 0x10, 0xee, 0xf0, 0x0e, 0x6d, 0x90,
+ 0x0e, 0xee, 0x60, 0x0e, 0xf3, 0xd0, 0x06, 0xe6, 0x00, 0x0f, 0x6d, 0xd0,
+ 0x0e, 0xe1, 0x40, 0x0f, 0xe8, 0x00, 0xd0, 0x83, 0x3c, 0xd4, 0x43, 0x39,
+ 0x00, 0x84, 0x3b, 0xbc, 0x43, 0x1b, 0xa8, 0x43, 0x3d, 0xb4, 0x03, 0x3c,
+ 0xb4, 0x01, 0x3d, 0x84, 0x83, 0x38, 0xb0, 0x43, 0x39, 0xcc, 0x03, 0x60,
+ 0x0e, 0xe1, 0xc0, 0x0e, 0xf3, 0x50, 0x0e, 0x00, 0xe1, 0x0e, 0xef, 0xd0,
+ 0x06, 0xee, 0x10, 0x0e, 0xee, 0x30, 0x0f, 0x6d, 0x60, 0x0e, 0xf0, 0xd0,
+ 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x00, 0x3d, 0xc8, 0x43, 0x3d,
+ 0x94, 0x03, 0x40, 0xb8, 0xc3, 0x3b, 0xb4, 0xc1, 0x3c, 0xa4, 0xc3, 0x39,
+ 0xb8, 0x43, 0x39, 0x90, 0x43, 0x1b, 0xe8, 0x43, 0x39, 0xc8, 0xc3, 0x3b,
+ 0xcc, 0x43, 0x1b, 0x98, 0x03, 0x3c, 0xb4, 0x41, 0x3b, 0x84, 0x03, 0x3d,
+ 0xa0, 0x03, 0x60, 0x0e, 0xe1, 0xc0, 0x0e, 0xf3, 0x50, 0x0e, 0x00, 0x31,
+ 0x0f, 0xf4, 0x10, 0x0e, 0xe3, 0xb0, 0x0e, 0x6d, 0x00, 0x0f, 0xf2, 0xf0,
+ 0x0e, 0xf4, 0x50, 0x0e, 0xe3, 0x40, 0x0f, 0xef, 0x20, 0x0f, 0x6d, 0x20,
+ 0x0e, 0xf5, 0x60, 0x0e, 0xe6, 0x50, 0x0e, 0xf2, 0xd0, 0x06, 0xf3, 0x90,
+ 0x0e, 0xfa, 0x50, 0x0e, 0x00, 0x1e, 0x00, 0x04, 0x3d, 0x84, 0x83, 0x3c,
+ 0x9c, 0x43, 0x39, 0xd0, 0x43, 0x1b, 0x98, 0x43, 0x39, 0x84, 0x03, 0x3d,
+ 0xd4, 0x83, 0x3c, 0x94, 0xc3, 0x3c, 0x00, 0x6d, 0x60, 0x0e, 0xf0, 0x10,
+ 0x07, 0x76, 0x00, 0x10, 0xf5, 0xe0, 0x0e, 0xf3, 0x10, 0x0e, 0xe6, 0x50,
+ 0x0e, 0x6d, 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80,
+ 0x0e, 0x00, 0x3d, 0xc8, 0x43, 0x3d, 0x94, 0x03, 0x40, 0xd4, 0xc3, 0x3c,
+ 0x94, 0x43, 0x1b, 0xcc, 0xc3, 0x3b, 0x98, 0x03, 0x3d, 0xb4, 0x81, 0x39,
+ 0xb0, 0xc3, 0x3b, 0x84, 0x03, 0x3d, 0x00, 0xe6, 0x10, 0x0e, 0xec, 0x30,
+ 0x0f, 0xe5, 0x00, 0x6c, 0x50, 0x95, 0xe2, 0xff, 0xff, 0xff, 0xff, 0x07,
+ 0x62, 0x1c, 0xde, 0x41, 0x1e, 0xe4, 0xa1, 0x1c, 0xc6, 0x81, 0x1e, 0xd8,
+ 0x21, 0x1f, 0xda, 0x40, 0x1e, 0xde, 0xa1, 0x1e, 0xdc, 0x81, 0x1c, 0xca,
+ 0x81, 0x1c, 0xda, 0x80, 0x1c, 0xd2, 0xc1, 0x1e, 0xd2, 0x81, 0x1c, 0xca,
+ 0xa1, 0x0d, 0xe6, 0x21, 0x1e, 0xe4, 0x81, 0x1e, 0xda, 0xc0, 0x1c, 0xe0,
+ 0xa1, 0x0d, 0xda, 0x21, 0x1c, 0xe8, 0x01, 0x1d, 0x00, 0x73, 0x08, 0x07,
+ 0x76, 0x98, 0x87, 0x72, 0x00, 0x08, 0x72, 0x48, 0x87, 0x79, 0x08, 0x07,
+ 0x71, 0x60, 0x87, 0x72, 0x68, 0x03, 0x7a, 0x08, 0x87, 0x74, 0x60, 0x87,
+ 0x36, 0x18, 0x87, 0x70, 0x60, 0x07, 0x76, 0x98, 0x07, 0xc0, 0x1c, 0xc2,
+ 0x81, 0x1d, 0xe6, 0xa1, 0x1c, 0x00, 0x82, 0x1d, 0xca, 0x61, 0x1e, 0xe6,
+ 0xa1, 0x0d, 0xe0, 0x41, 0x1e, 0xca, 0x61, 0x1c, 0xd2, 0x61, 0x1e, 0xca,
+ 0xa1, 0x0d, 0xcc, 0x01, 0x1e, 0xda, 0x21, 0x1c, 0xc8, 0x01, 0xa0, 0x07,
+ 0x79, 0xa8, 0x87, 0x72, 0x00, 0x08, 0x77, 0x78, 0x87, 0x36, 0x30, 0x07,
+ 0x79, 0x08, 0x87, 0x76, 0x28, 0x87, 0x36, 0x80, 0x87, 0x77, 0x48, 0x07,
+ 0x77, 0xa0, 0x87, 0x72, 0x90, 0x87, 0x36, 0x28, 0x07, 0x76, 0x48, 0x87,
+ 0x76, 0x00, 0xe8, 0x41, 0x1e, 0xea, 0xa1, 0x1c, 0x80, 0xc1, 0x1d, 0xde,
+ 0xa1, 0x0d, 0xcc, 0x41, 0x1e, 0xc2, 0xa1, 0x1d, 0xca, 0xa1, 0x0d, 0xe0,
+ 0xe1, 0x1d, 0xd2, 0xc1, 0x1d, 0xe8, 0xa1, 0x1c, 0xe4, 0xa1, 0x0d, 0xca,
+ 0x81, 0x1d, 0xd2, 0xa1, 0x1d, 0xda, 0xc0, 0x1d, 0xde, 0xc1, 0x1d, 0xda,
+ 0x80, 0x1d, 0xca, 0x21, 0x1c, 0xcc, 0x01, 0x20, 0xdc, 0xe1, 0x1d, 0xda,
+ 0x20, 0x1d, 0xdc, 0xc1, 0x1c, 0xe6, 0xa1, 0x0d, 0xcc, 0x01, 0x1e, 0xda,
+ 0xa0, 0x1d, 0xc2, 0x81, 0x1e, 0xd0, 0x01, 0xa0, 0x07, 0x79, 0xa8, 0x87,
+ 0x72, 0x00, 0x08, 0x77, 0x78, 0x87, 0x36, 0x70, 0x87, 0x70, 0x70, 0x87,
+ 0x79, 0x68, 0x03, 0x73, 0x80, 0x87, 0x36, 0x68, 0x87, 0x70, 0xa0, 0x07,
+ 0x74, 0x00, 0xe8, 0x41, 0x1e, 0xea, 0xa1, 0x1c, 0x00, 0xc2, 0x1d, 0xde,
+ 0xa1, 0x0d, 0xe6, 0x21, 0x1d, 0xce, 0xc1, 0x1d, 0xca, 0x81, 0x1c, 0xda,
+ 0x40, 0x1f, 0xca, 0x41, 0x1e, 0xde, 0x61, 0x1e, 0xda, 0xc0, 0x1c, 0xe0,
+ 0xa1, 0x0d, 0xda, 0x21, 0x1c, 0xe8, 0x01, 0x1d, 0x00, 0x73, 0x08, 0x07,
+ 0x76, 0x98, 0x87, 0x72, 0x00, 0x88, 0x79, 0xa0, 0x87, 0x70, 0x18, 0x87,
+ 0x75, 0x68, 0x03, 0x78, 0x90, 0x87, 0x77, 0xa0, 0x87, 0x72, 0x18, 0x07,
+ 0x7a, 0x78, 0x07, 0x79, 0x68, 0x03, 0x71, 0xa8, 0x07, 0x73, 0x30, 0x87,
+ 0x72, 0x90, 0x87, 0x36, 0x98, 0x87, 0x74, 0xd0, 0x87, 0x72, 0x00, 0xf0,
+ 0x00, 0x20, 0xe8, 0x21, 0x1c, 0xe4, 0xe1, 0x1c, 0xca, 0x81, 0x1e, 0xda,
+ 0xc0, 0x1c, 0xca, 0x21, 0x1c, 0xe8, 0xa1, 0x1e, 0xe4, 0xa1, 0x1c, 0xe6,
+ 0x01, 0x68, 0x03, 0x73, 0x80, 0x87, 0x38, 0xb0, 0x03, 0x80, 0xa8, 0x07,
+ 0x77, 0x98, 0x87, 0x70, 0x30, 0x87, 0x72, 0x68, 0x03, 0x73, 0x80, 0x87,
+ 0x36, 0x68, 0x87, 0x70, 0xa0, 0x07, 0x74, 0x00, 0xe8, 0x41, 0x1e, 0xea,
+ 0xa1, 0x1c, 0x00, 0xa2, 0x1e, 0xe6, 0xa1, 0x1c, 0xda, 0x60, 0x1e, 0xde,
+ 0xc1, 0x1c, 0xe8, 0xa1, 0x0d, 0xcc, 0x81, 0x1d, 0xde, 0x21, 0x1c, 0xe8,
+ 0x01, 0x30, 0x87, 0x70, 0x60, 0x87, 0x79, 0x28, 0x07, 0x60, 0x03, 0x61,
+ 0x04, 0xc0, 0xb2, 0x81, 0x38, 0x04, 0x60, 0xd9, 0x80, 0x20, 0xff, 0xff,
+ 0xff, 0xff, 0x3f, 0x00, 0x0c, 0x20, 0x01, 0xd5, 0x06, 0x22, 0xf9, 0xff,
+ 0xff, 0xff, 0xff, 0x01, 0x90, 0x00, 0x00, 0x00, 0x49, 0x18, 0x00, 0x00,
+ 0x04, 0x00, 0x00, 0x00, 0x13, 0x88, 0x40, 0x18, 0x88, 0x09, 0x41, 0x31,
+ 0x61, 0x30, 0x0e, 0x64, 0x42, 0x90, 0x00, 0x00, 0x89, 0x20, 0x00, 0x00,
+ 0x31, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09, 0x20, 0x64, 0x85, 0x04,
+ 0x93, 0x22, 0xa4, 0x84, 0x04, 0x93, 0x22, 0xe3, 0x84, 0xa1, 0x90, 0x14,
+ 0x12, 0x4c, 0x8a, 0x8c, 0x0b, 0x84, 0xa4, 0x4c, 0x10, 0x78, 0x33, 0x00,
+ 0xc3, 0x08, 0x04, 0x30, 0x8c, 0x20, 0x00, 0x83, 0x08, 0x81, 0x30, 0x8c,
+ 0x30, 0x00, 0x07, 0x49, 0x53, 0x44, 0x09, 0x93, 0x2f, 0xbb, 0x6f, 0x47,
+ 0x08, 0xce, 0x40, 0x20, 0x82, 0x10, 0x42, 0x06, 0x11, 0x0a, 0xe1, 0x28,
+ 0x69, 0x8a, 0x28, 0x61, 0xf2, 0xff, 0x89, 0xb8, 0x26, 0x2a, 0x22, 0x7e,
+ 0x7b, 0xf8, 0xa7, 0x31, 0x02, 0x60, 0x10, 0xe1, 0x08, 0x4e, 0x93, 0xa6,
+ 0x88, 0x12, 0x26, 0xff, 0x9f, 0x88, 0x6b, 0xa2, 0x22, 0xe2, 0xb7, 0x87,
+ 0x1f, 0x88, 0x22, 0x00, 0xfb, 0xa7, 0x31, 0x02, 0x60, 0x10, 0x21, 0x09,
+ 0x2e, 0x92, 0xa6, 0x88, 0x12, 0x26, 0xff, 0x97, 0x00, 0xe6, 0x59, 0x88,
+ 0xe8, 0x9f, 0xc6, 0x08, 0x80, 0x41, 0x84, 0x45, 0x28, 0x48, 0x08, 0x62,
+ 0x18, 0xa4, 0x18, 0xb5, 0x32, 0x00, 0x42, 0xe8, 0xcd, 0x11, 0x80, 0xc1,
+ 0x1c, 0x41, 0x30, 0x8c, 0x20, 0x44, 0x25, 0x09, 0x8a, 0x89, 0x28, 0xa7,
+ 0x04, 0x44, 0x0b, 0x12, 0x10, 0x13, 0x72, 0x4a, 0x40, 0x76, 0x20, 0x60,
+ 0x18, 0x61, 0x88, 0x86, 0x11, 0x88, 0x68, 0x8e, 0x00, 0x14, 0x06, 0x11,
+ 0x08, 0x61, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0xa8, 0x70, 0x48,
+ 0x07, 0x79, 0xb0, 0x03, 0x3a, 0x68, 0x83, 0x70, 0x80, 0x07, 0x78, 0x60,
+ 0x87, 0x72, 0x68, 0x83, 0x74, 0x78, 0x87, 0x79, 0xc8, 0x03, 0x37, 0x80,
+ 0x03, 0x37, 0x80, 0x83, 0x0d, 0xef, 0x51, 0x0e, 0x6d, 0x00, 0x0f, 0x7a,
+ 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74,
+ 0xd0, 0x06, 0xe9, 0x10, 0x07, 0x7a, 0x80, 0x07, 0x7a, 0x80, 0x07, 0x6d,
+ 0x90, 0x0e, 0x78, 0xa0, 0x07, 0x78, 0xa0, 0x07, 0x78, 0xd0, 0x06, 0xe9,
+ 0x10, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x60, 0x07, 0x7a, 0x10, 0x07, 0x76,
+ 0xd0, 0x06, 0xe9, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x7a,
+ 0x30, 0x07, 0x72, 0xd0, 0x06, 0xe9, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76,
+ 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x30, 0x07, 0x72,
+ 0xa0, 0x07, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xe6,
+ 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74,
+ 0xd0, 0x06, 0xe6, 0x80, 0x07, 0x70, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78,
+ 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0, 0x06, 0xf6, 0x10, 0x07, 0x76,
+ 0xa0, 0x07, 0x71, 0x60, 0x07, 0x7a, 0x10, 0x07, 0x76, 0xd0, 0x06, 0xf6,
+ 0x20, 0x07, 0x74, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72,
+ 0xd0, 0x06, 0xf6, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x7a,
+ 0x30, 0x07, 0x72, 0xd0, 0x06, 0xf6, 0x40, 0x07, 0x78, 0xa0, 0x07, 0x76,
+ 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xf6, 0x60, 0x07, 0x74,
+ 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xf6,
+ 0x90, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71,
+ 0x20, 0x07, 0x78, 0xd0, 0x06, 0xf6, 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a,
+ 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d,
+ 0x60, 0x0f, 0x71, 0x90, 0x07, 0x72, 0xa0, 0x07, 0x72, 0x50, 0x07, 0x76,
+ 0xa0, 0x07, 0x72, 0x50, 0x07, 0x76, 0xd0, 0x06, 0xf6, 0x20, 0x07, 0x75,
+ 0x60, 0x07, 0x7a, 0x20, 0x07, 0x75, 0x60, 0x07, 0x7a, 0x20, 0x07, 0x75,
+ 0x60, 0x07, 0x6d, 0x60, 0x0f, 0x75, 0x10, 0x07, 0x72, 0xa0, 0x07, 0x75,
+ 0x10, 0x07, 0x72, 0xa0, 0x07, 0x75, 0x10, 0x07, 0x72, 0xd0, 0x06, 0xf6,
+ 0x10, 0x07, 0x70, 0x20, 0x07, 0x74, 0xa0, 0x07, 0x71, 0x00, 0x07, 0x72,
+ 0x40, 0x07, 0x7a, 0x10, 0x07, 0x70, 0x20, 0x07, 0x74, 0xd0, 0x06, 0xe6,
+ 0x80, 0x07, 0x70, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71,
+ 0x20, 0x07, 0x78, 0xd0, 0x06, 0xee, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x76,
+ 0xa0, 0x07, 0x73, 0x20, 0x07, 0x43, 0x18, 0x07, 0x00, 0x80, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x80, 0x21, 0x0c, 0x04, 0x04, 0x80, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0xc0, 0x10, 0xa6, 0x02, 0x02, 0x60, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x60, 0x08, 0x73, 0x01, 0x01, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x90, 0x05, 0x02, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x14,
+ 0x19, 0x11, 0x4c, 0x90, 0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0x8a,
+ 0x23, 0x00, 0x25, 0x50, 0x20, 0x05, 0x18, 0x50, 0x10, 0x45, 0x50, 0x06,
+ 0x05, 0x54, 0x60, 0x85, 0x50, 0x0a, 0xc5, 0x40, 0x7b, 0x04, 0x00, 0x00,
+ 0x79, 0x18, 0x00, 0x00, 0x15, 0x01, 0x00, 0x00, 0x1a, 0x03, 0x4c, 0x10,
+ 0xd7, 0x20, 0x08, 0x0e, 0x8e, 0xad, 0x0c, 0x84, 0x89, 0xc9, 0xaa, 0x09,
+ 0xc4, 0xae, 0x4c, 0x6e, 0x2e, 0xed, 0xcd, 0x0d, 0x04, 0x07, 0x46, 0xc6,
+ 0x25, 0x06, 0x04, 0xa5, 0xad, 0x8c, 0x2e, 0x8c, 0xcd, 0xac, 0xac, 0x05,
+ 0x07, 0x46, 0xc6, 0x25, 0xc6, 0x65, 0x86, 0x26, 0x65, 0x88, 0x80, 0x01,
+ 0x43, 0x8c, 0xa8, 0x88, 0x90, 0x88, 0x60, 0xd1, 0x54, 0x46, 0x17, 0xc6,
+ 0x36, 0x04, 0xc1, 0x86, 0xa8, 0x88, 0x8a, 0x88, 0xe0, 0x16, 0x96, 0x26,
+ 0xe7, 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56, 0xe6, 0x42, 0x56, 0xe6,
+ 0xf6, 0x26, 0xd7, 0x36, 0xf7, 0x45, 0x96, 0x36, 0x17, 0x26, 0xc6, 0x56,
+ 0x36, 0x44, 0xc0, 0x0a, 0x72, 0x61, 0x69, 0x72, 0x2e, 0x63, 0x6f, 0x6d,
+ 0x70, 0x69, 0x6c, 0x65, 0x2e, 0x66, 0x61, 0x73, 0x74, 0x5f, 0x6d, 0x61,
+ 0x74, 0x68, 0x5f, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x43, 0x04, 0xec,
+ 0x20, 0x19, 0x84, 0xa5, 0xc9, 0xb9, 0x8c, 0xbd, 0xb5, 0xc1, 0xa5, 0xb1,
+ 0x95, 0xb9, 0x98, 0xc9, 0x85, 0xb5, 0x95, 0x89, 0xd5, 0x99, 0x99, 0x95,
+ 0xc9, 0x7d, 0x99, 0x95, 0xd1, 0x8d, 0xa1, 0x7d, 0x95, 0xb9, 0x85, 0x89,
+ 0xb1, 0x95, 0x0d, 0x11, 0xb0, 0x84, 0x61, 0x10, 0x96, 0x26, 0xe7, 0x32,
+ 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56, 0xe6, 0xe2, 0x16, 0x46, 0x97, 0x66,
+ 0x57, 0xf6, 0x45, 0xf6, 0x56, 0x27, 0xc6, 0x56, 0xf6, 0x45, 0x96, 0x36,
+ 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0xc0, 0x16, 0x46, 0x61, 0x69, 0x72,
+ 0x2e, 0x72, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x5f, 0x74, 0x61, 0x72, 0x67,
+ 0x65, 0x74, 0x8c, 0xc2, 0xd2, 0xe4, 0x5c, 0xc2, 0xe4, 0xce, 0xbe, 0xe8,
+ 0xf2, 0xe0, 0xca, 0xbe, 0xdc, 0xc2, 0xda, 0xca, 0x68, 0x98, 0xb1, 0xbd,
+ 0x85, 0xd1, 0xd1, 0x0c, 0x41, 0xb0, 0x26, 0x22, 0x30, 0x07, 0x7b, 0x86,
+ 0x08, 0x18, 0x44, 0x26, 0x2c, 0x4d, 0xce, 0x05, 0xee, 0x6d, 0x2e, 0x8d,
+ 0x2e, 0xed, 0xcd, 0x8d, 0x4a, 0x58, 0x9a, 0x9c, 0xcb, 0x58, 0x99, 0x1b,
+ 0x5d, 0x99, 0x1c, 0xa5, 0xb0, 0x34, 0x39, 0x17, 0xb7, 0xb7, 0x2f, 0xb8,
+ 0x32, 0xb9, 0x39, 0xb8, 0xb2, 0x31, 0xba, 0x34, 0xbb, 0x32, 0x32, 0x61,
+ 0x69, 0x72, 0x2e, 0x61, 0x72, 0x67, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x44,
+ 0xe0, 0xde, 0xe6, 0xd2, 0xe8, 0xd2, 0xde, 0xdc, 0x86, 0x40, 0x11, 0x81,
+ 0x49, 0xd8, 0x84, 0x51, 0x98, 0x83, 0x3d, 0x58, 0x85, 0x59, 0x94, 0xc2,
+ 0xd2, 0xe4, 0x5c, 0xcc, 0xe4, 0xc2, 0xce, 0xda, 0xca, 0xdc, 0xe8, 0xbe,
+ 0xd2, 0xdc, 0xe0, 0xea, 0xe8, 0x98, 0x9d, 0x95, 0xb9, 0x95, 0xc9, 0x85,
+ 0xd1, 0x95, 0x91, 0xa1, 0xe0, 0xd0, 0x95, 0xe1, 0x8d, 0xbd, 0xbd, 0xc9,
+ 0x91, 0x11, 0xd9, 0xc9, 0x7c, 0x99, 0xa5, 0xf0, 0x09, 0x4b, 0x93, 0x73,
+ 0x81, 0x2b, 0x93, 0x9b, 0x83, 0x2b, 0x1b, 0xa3, 0x4b, 0xb3, 0x2b, 0xa3,
+ 0x61, 0xc6, 0xf6, 0x16, 0x46, 0x27, 0x43, 0x84, 0xae, 0x0c, 0x6f, 0xec,
+ 0xed, 0x4d, 0x8e, 0x6c, 0x88, 0x14, 0x15, 0x18, 0x86, 0x65, 0xd8, 0x84,
+ 0x69, 0x98, 0x83, 0x6d, 0x58, 0x85, 0x71, 0x54, 0xc2, 0xd2, 0xe4, 0x5c,
+ 0xc4, 0xea, 0xcc, 0xcc, 0xca, 0xe4, 0xf8, 0x84, 0xa5, 0xc9, 0xb9, 0x88,
+ 0xd5, 0x99, 0x99, 0x95, 0xc9, 0x7d, 0xcd, 0xa5, 0xe9, 0x95, 0x51, 0x0a,
+ 0x4b, 0x93, 0x73, 0x61, 0x7b, 0x1b, 0x0b, 0xa3, 0x4b, 0x7b, 0x73, 0xfb,
+ 0x4a, 0x73, 0x23, 0x2b, 0xc3, 0x23, 0x12, 0x96, 0x26, 0xe7, 0x22, 0x57,
+ 0x16, 0x46, 0xc6, 0x28, 0x2c, 0x4d, 0xce, 0x25, 0x4c, 0xee, 0xec, 0x8b,
+ 0x2e, 0x0f, 0xae, 0xec, 0x6b, 0x2e, 0x4d, 0xaf, 0x8c, 0x57, 0x58, 0x9a,
+ 0x9c, 0x4b, 0x98, 0xdc, 0xd9, 0x17, 0x5d, 0x1e, 0x5c, 0xd9, 0x57, 0x18,
+ 0x5b, 0xda, 0x99, 0xdb, 0xd7, 0x5c, 0x9a, 0x5e, 0x19, 0x87, 0xb1, 0x37,
+ 0xb6, 0x21, 0x60, 0x10, 0x25, 0x98, 0x87, 0x7d, 0x91, 0x81, 0x81, 0x41,
+ 0x44, 0x44, 0x05, 0x16, 0x06, 0x98, 0x18, 0x44, 0x06, 0x36, 0x06, 0x91,
+ 0x81, 0x39, 0xd8, 0x83, 0x55, 0x18, 0x19, 0x90, 0x0a, 0x4b, 0x93, 0x73,
+ 0x99, 0xa3, 0x93, 0xab, 0x1b, 0xa3, 0xfb, 0xa2, 0xcb, 0x83, 0x2b, 0xfb,
+ 0x4a, 0x73, 0x33, 0x7b, 0xa3, 0x61, 0xc6, 0xf6, 0x16, 0x46, 0x37, 0x43,
+ 0xe3, 0xcd, 0xcc, 0x6c, 0xae, 0x8c, 0x8e, 0x86, 0xd4, 0xd8, 0x5b, 0x99,
+ 0x99, 0x19, 0x8d, 0xa3, 0xb1, 0xb7, 0x32, 0x33, 0x33, 0x1a, 0x42, 0x63,
+ 0x6f, 0x65, 0x66, 0x66, 0x43, 0xd0, 0x20, 0x22, 0x22, 0x23, 0x22, 0xb0,
+ 0x33, 0xc0, 0xd0, 0x20, 0x32, 0x22, 0x23, 0x22, 0xb0, 0x33, 0xc0, 0xd2,
+ 0x20, 0x5a, 0x22, 0x23, 0x22, 0xb0, 0x33, 0xc0, 0xd4, 0x20, 0x62, 0x22,
+ 0x23, 0x22, 0xb0, 0x33, 0xc0, 0xd6, 0x80, 0x49, 0x56, 0x95, 0x15, 0x51,
+ 0xd9, 0xd8, 0x1b, 0x59, 0x19, 0x0d, 0xb2, 0xb2, 0xb1, 0x37, 0xb2, 0xb2,
+ 0x21, 0x64, 0x10, 0x29, 0x98, 0x87, 0x7d, 0xd1, 0x81, 0x81, 0x41, 0x54,
+ 0x44, 0x05, 0x16, 0x06, 0x98, 0x19, 0x60, 0x6c, 0x80, 0x89, 0x41, 0x74,
+ 0x60, 0x63, 0x10, 0x19, 0x98, 0x83, 0xb5, 0x01, 0x56, 0x61, 0x6e, 0xc0,
+ 0x25, 0x2c, 0x4d, 0xce, 0x85, 0xae, 0x0c, 0x8f, 0xae, 0x4e, 0xae, 0x8c,
+ 0x4a, 0x58, 0x9a, 0x9c, 0xcb, 0x5c, 0x58, 0x1b, 0x1c, 0x5b, 0x19, 0x31,
+ 0xba, 0x32, 0x3c, 0xba, 0x3a, 0xb9, 0x32, 0x19, 0x32, 0x1e, 0x33, 0xb6,
+ 0xb7, 0x30, 0x3a, 0x16, 0x90, 0xb9, 0xb0, 0x36, 0x38, 0xb6, 0x32, 0x1f,
+ 0x12, 0x74, 0x65, 0x78, 0x59, 0x43, 0xa8, 0xa8, 0xc1, 0xe0, 0x00, 0x03,
+ 0x83, 0x88, 0x88, 0x0a, 0x2c, 0x0e, 0x30, 0x07, 0x93, 0x03, 0xac, 0xc2,
+ 0xe6, 0x80, 0x1e, 0x5d, 0x19, 0x1e, 0x5d, 0x9d, 0x5c, 0x99, 0x0c, 0xd9,
+ 0x57, 0x98, 0x9c, 0x5c, 0x58, 0x1e, 0x8f, 0x19, 0xdb, 0x5b, 0x18, 0x1d,
+ 0x0b, 0xc8, 0x5c, 0x58, 0x1b, 0x1c, 0x5b, 0x99, 0x0f, 0x0b, 0xba, 0x32,
+ 0xbc, 0x2a, 0xab, 0x21, 0x54, 0xe4, 0x60, 0x70, 0x80, 0x81, 0x41, 0x54,
+ 0x44, 0x05, 0x16, 0x07, 0x98, 0x83, 0xd5, 0x01, 0x56, 0x61, 0x76, 0xc0,
+ 0x25, 0x2c, 0x4d, 0xce, 0x65, 0x2e, 0xac, 0x0d, 0x8e, 0xad, 0x4c, 0x8e,
+ 0xc7, 0x5c, 0x58, 0x1b, 0x1c, 0x5b, 0x99, 0x1c, 0x83, 0xb9, 0x21, 0x52,
+ 0xf4, 0x60, 0x78, 0x80, 0x81, 0x41, 0x44, 0x44, 0x05, 0xe6, 0x60, 0x79,
+ 0x80, 0x55, 0x98, 0x1e, 0x0c, 0x71, 0xb0, 0x0b, 0xeb, 0xb0, 0x32, 0xc0,
+ 0xde, 0x00, 0xa3, 0x03, 0xec, 0x0e, 0xb0, 0x3d, 0x18, 0x62, 0x38, 0x00,
+ 0x16, 0x61, 0x7c, 0xc0, 0xe7, 0xad, 0xcd, 0x2d, 0x0d, 0xee, 0x8d, 0xae,
+ 0xcc, 0x8d, 0x0e, 0x64, 0x0c, 0x2d, 0x4c, 0x8e, 0xcf, 0x54, 0x5a, 0x1b,
+ 0x1c, 0x5b, 0x19, 0xc8, 0xd0, 0xca, 0x0a, 0x08, 0x95, 0x50, 0x50, 0xd0,
+ 0x10, 0x01, 0xfb, 0x83, 0x21, 0x06, 0xe6, 0x07, 0x18, 0x28, 0x6c, 0xd0,
+ 0x10, 0x03, 0x0b, 0x05, 0x2c, 0x14, 0x36, 0x68, 0x84, 0xc2, 0x0e, 0xec,
+ 0x60, 0x0f, 0xed, 0xe0, 0x06, 0xe9, 0x40, 0x0e, 0xe5, 0xe0, 0x0e, 0xf4,
+ 0x30, 0x25, 0x08, 0x46, 0x2c, 0xe1, 0x90, 0x0e, 0xf2, 0xe0, 0x06, 0xf6,
+ 0x50, 0x0e, 0xf2, 0x30, 0x0f, 0xe9, 0xf0, 0x0e, 0xee, 0x30, 0x25, 0x10,
+ 0x46, 0x50, 0xe1, 0x90, 0x0e, 0xf2, 0xe0, 0x06, 0xec, 0x10, 0x0e, 0xee,
+ 0x70, 0x0e, 0xf5, 0x10, 0x0e, 0xe7, 0x50, 0x0e, 0xbf, 0x60, 0x0f, 0xe5,
+ 0x20, 0x0f, 0xf3, 0x90, 0x0e, 0xef, 0xe0, 0x0e, 0x53, 0x02, 0x62, 0xc4,
+ 0x14, 0x0e, 0xe9, 0x20, 0x0f, 0x6e, 0x30, 0x0e, 0xef, 0xd0, 0x0e, 0xf0,
+ 0x90, 0x0e, 0xec, 0x50, 0x0e, 0xbf, 0xf0, 0x0e, 0xf0, 0x40, 0x0f, 0xe9,
+ 0xf0, 0x0e, 0xee, 0x30, 0x0f, 0x53, 0x08, 0x03, 0x51, 0x98, 0x11, 0x4c,
+ 0x38, 0xa4, 0x83, 0x3c, 0xb8, 0x81, 0x39, 0xc8, 0x43, 0x38, 0x9c, 0x43,
+ 0x3b, 0x94, 0x83, 0x3b, 0xd0, 0xc3, 0x94, 0xa0, 0x0f, 0x00, 0x00, 0x00,
+ 0x79, 0x18, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x33, 0x08, 0x80, 0x1c,
+ 0xc4, 0xe1, 0x1c, 0x66, 0x14, 0x01, 0x3d, 0x88, 0x43, 0x38, 0x84, 0xc3,
+ 0x8c, 0x42, 0x80, 0x07, 0x79, 0x78, 0x07, 0x73, 0x98, 0x71, 0x0c, 0xe6,
+ 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x33, 0x0c, 0x42, 0x1e,
+ 0xc2, 0xc1, 0x1d, 0xce, 0xa1, 0x1c, 0x66, 0x30, 0x05, 0x3d, 0x88, 0x43,
+ 0x38, 0x84, 0x83, 0x1b, 0xcc, 0x03, 0x3d, 0xc8, 0x43, 0x3d, 0x8c, 0x03,
+ 0x3d, 0xcc, 0x78, 0x8c, 0x74, 0x70, 0x07, 0x7b, 0x08, 0x07, 0x79, 0x48,
+ 0x87, 0x70, 0x70, 0x07, 0x7a, 0x70, 0x03, 0x76, 0x78, 0x87, 0x70, 0x20,
+ 0x87, 0x19, 0xcc, 0x11, 0x0e, 0xec, 0x90, 0x0e, 0xe1, 0x30, 0x0f, 0x6e,
+ 0x30, 0x0f, 0xe3, 0xf0, 0x0e, 0xf0, 0x50, 0x0e, 0x33, 0x10, 0xc4, 0x1d,
+ 0xde, 0x21, 0x1c, 0xd8, 0x21, 0x1d, 0xc2, 0x61, 0x1e, 0x66, 0x30, 0x89,
+ 0x3b, 0xbc, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xb4, 0x03, 0x3c, 0xbc, 0x83,
+ 0x3c, 0x84, 0x03, 0x3b, 0xcc, 0xf0, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68,
+ 0x07, 0x37, 0x68, 0x87, 0x72, 0x68, 0x07, 0x37, 0x80, 0x87, 0x70, 0x90,
+ 0x87, 0x70, 0x60, 0x07, 0x76, 0x28, 0x07, 0x76, 0xf8, 0x05, 0x76, 0x78,
+ 0x87, 0x77, 0x80, 0x87, 0x5f, 0x08, 0x87, 0x71, 0x18, 0x87, 0x72, 0x98,
+ 0x87, 0x79, 0x98, 0x81, 0x2c, 0xee, 0xf0, 0x0e, 0xee, 0xe0, 0x0e, 0xf5,
+ 0xc0, 0x0e, 0xec, 0x30, 0x03, 0x62, 0xc8, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c,
+ 0xcc, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xdc, 0x61, 0x1c, 0xca, 0x21, 0x1c,
+ 0xc4, 0x81, 0x1d, 0xca, 0x61, 0x06, 0xd6, 0x90, 0x43, 0x39, 0xc8, 0x43,
+ 0x39, 0x98, 0x43, 0x39, 0xc8, 0x43, 0x39, 0xb8, 0xc3, 0x38, 0x94, 0x43,
+ 0x38, 0x88, 0x03, 0x3b, 0x94, 0xc3, 0x2f, 0xbc, 0x83, 0x3c, 0xfc, 0x82,
+ 0x3b, 0xd4, 0x03, 0x3b, 0xb0, 0xc3, 0x0c, 0xc7, 0x69, 0x87, 0x70, 0x58,
+ 0x87, 0x72, 0x70, 0x83, 0x74, 0x68, 0x07, 0x78, 0x60, 0x87, 0x74, 0x18,
+ 0x87, 0x74, 0xa0, 0x87, 0x19, 0xce, 0x53, 0x0f, 0xee, 0x00, 0x0f, 0xf2,
+ 0x50, 0x0e, 0xe4, 0x90, 0x0e, 0xe3, 0x40, 0x0f, 0xe1, 0x20, 0x0e, 0xec,
+ 0x50, 0x0e, 0x33, 0x20, 0x28, 0x1d, 0xdc, 0xc1, 0x1e, 0xc2, 0x41, 0x1e,
+ 0xd2, 0x21, 0x1c, 0xdc, 0x81, 0x1e, 0xdc, 0xe0, 0x1c, 0xe4, 0xe1, 0x1d,
+ 0xea, 0x01, 0x1e, 0x66, 0x18, 0x51, 0x38, 0xb0, 0x43, 0x3a, 0x9c, 0x83,
+ 0x3b, 0xcc, 0x50, 0x24, 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x60,
+ 0x87, 0x77, 0x78, 0x07, 0x78, 0x98, 0x51, 0x4c, 0xf4, 0x90, 0x0f, 0xf0,
+ 0x50, 0x0e, 0x00, 0x00, 0x71, 0x20, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
+ 0x26, 0x10, 0x06, 0x00, 0x12, 0xf9, 0x12, 0xc0, 0x3c, 0x0b, 0xf1, 0x4f,
+ 0xc4, 0x35, 0x51, 0x11, 0xf1, 0xdb, 0xc3, 0x0f, 0x44, 0x11, 0x80, 0xf9,
+ 0x15, 0x5e, 0xdc, 0xb6, 0x05, 0x34, 0x00, 0x12, 0xf9, 0x83, 0x33, 0xf9,
+ 0xd5, 0x5d, 0xdc, 0xb6, 0x0d, 0x6c, 0x00, 0x12, 0xf9, 0x12, 0xc0, 0x3c,
+ 0x0b, 0xf1, 0x4f, 0xc4, 0x35, 0x51, 0x11, 0xf1, 0xdb, 0x83, 0x5f, 0xe1,
+ 0xc5, 0x6d, 0x1b, 0x00, 0xc4, 0x76, 0xe5, 0x2f, 0xbb, 0xef, 0x5f, 0x44,
+ 0x80, 0xc1, 0x10, 0xcd, 0x04, 0x00, 0x00, 0x00, 0x61, 0x20, 0x00, 0x00,
+ 0x3e, 0x00, 0x00, 0x00, 0x13, 0x04, 0x41, 0x2c, 0x10, 0x00, 0x00, 0x00,
+ 0x0b, 0x00, 0x00, 0x00, 0xa4, 0xe7, 0x20, 0x88, 0x22, 0xe1, 0x28, 0xcf,
+ 0x31, 0x10, 0x1c, 0x37, 0xd6, 0x00, 0x04, 0x02, 0xcd, 0x11, 0x00, 0x8a,
+ 0x33, 0x00, 0x24, 0x6b, 0x60, 0x04, 0x80, 0xc8, 0x0c, 0x00, 0x85, 0x19,
+ 0x00, 0x02, 0x63, 0x04, 0x20, 0x08, 0x82, 0xf8, 0x37, 0x02, 0x00, 0x00,
+ 0x23, 0x06, 0xca, 0x10, 0x80, 0x81, 0xc3, 0x44, 0x06, 0x52, 0x04, 0x23,
+ 0x06, 0xcb, 0x10, 0x88, 0x81, 0xd3, 0x48, 0x60, 0x70, 0x24, 0x86, 0x30,
+ 0x86, 0x10, 0x84, 0xc1, 0x20, 0xc3, 0x60, 0x34, 0x73, 0x0c, 0x81, 0x20,
+ 0x06, 0x23, 0x06, 0xcb, 0x10, 0x98, 0x81, 0x14, 0x59, 0x63, 0xb0, 0x34,
+ 0x8a, 0x31, 0x86, 0x10, 0x94, 0xc1, 0x1c, 0xc3, 0x10, 0x84, 0xc1, 0x20,
+ 0x43, 0xc0, 0x4c, 0x87, 0x8d, 0xa5, 0xa0, 0xd8, 0x10, 0xc0, 0x87, 0xb8,
+ 0x32, 0xc8, 0x20, 0x40, 0xd6, 0x78, 0x43, 0x17, 0x06, 0x6c, 0x70, 0xc1,
+ 0x58, 0x0a, 0xca, 0x20, 0x43, 0x40, 0x69, 0x23, 0x06, 0x05, 0x11, 0xd0,
+ 0x41, 0x11, 0xcc, 0x31, 0x58, 0x81, 0x1c, 0x8c, 0x37, 0x8c, 0xc1, 0x19,
+ 0xb8, 0xc1, 0x05, 0x63, 0x29, 0x28, 0x83, 0x0c, 0x81, 0x06, 0x06, 0x23,
+ 0x06, 0x05, 0x11, 0xe8, 0xc1, 0x12, 0xcc, 0x31, 0x18, 0xc1, 0x1d, 0x8c,
+ 0x37, 0xa4, 0x41, 0x1b, 0xcc, 0xc1, 0x05, 0x63, 0x29, 0x28, 0x83, 0x0c,
+ 0x01, 0x18, 0x98, 0xc1, 0x88, 0x41, 0x41, 0x04, 0xa0, 0x10, 0x05, 0x73,
+ 0x0c, 0x46, 0x90, 0x07, 0x73, 0x0c, 0x81, 0x18, 0xe4, 0x81, 0x05, 0x95,
+ 0x7c, 0x32, 0x08, 0x88, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x5b, 0x06, 0x26, 0x10, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xde, 0xc0, 0x17, 0x0b, 0x00, 0x00, 0x00, 0x00,
+ 0x14, 0x00, 0x00, 0x00, 0xf0, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+ 0x42, 0x43, 0xc0, 0xde, 0x21, 0x0c, 0x00, 0x00, 0x79, 0x03, 0x00, 0x00,
+ 0x0b, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00,
+ 0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39,
+ 0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19, 0x1e, 0x04, 0x8b, 0x62,
+ 0x80, 0x14, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42, 0xa4, 0x10, 0x32, 0x14,
+ 0x38, 0x08, 0x18, 0x49, 0x0a, 0x32, 0x44, 0x24, 0x48, 0x0a, 0x90, 0x21,
+ 0x23, 0xc4, 0x52, 0x80, 0x0c, 0x19, 0x21, 0x72, 0x24, 0x07, 0xc8, 0x48,
+ 0x11, 0x62, 0xa8, 0xa0, 0xa8, 0x40, 0xc6, 0xf0, 0x01, 0x00, 0x00, 0x00,
+ 0x51, 0x18, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x1b, 0x8c, 0x60, 0x00,
+ 0x16, 0xa0, 0xda, 0x60, 0x08, 0x04, 0xb0, 0x00, 0xd5, 0x06, 0x63, 0x38,
+ 0x80, 0x05, 0xa8, 0x36, 0x90, 0x0b, 0xf1, 0xff, 0xff, 0xff, 0xff, 0x03,
+ 0xc0, 0x00, 0x12, 0x31, 0x0e, 0xef, 0x20, 0x0f, 0xf2, 0x50, 0x0e, 0xe3,
+ 0x40, 0x0f, 0xec, 0x90, 0x0f, 0x6d, 0x20, 0x0f, 0xef, 0x50, 0x0f, 0xee,
+ 0x40, 0x0e, 0xe5, 0x40, 0x0e, 0x6d, 0x40, 0x0e, 0xe9, 0x60, 0x0f, 0xe9,
+ 0x40, 0x0e, 0xe5, 0xd0, 0x06, 0xf3, 0x10, 0x0f, 0xf2, 0x40, 0x0f, 0x6d,
+ 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x80,
+ 0x39, 0x84, 0x03, 0x3b, 0xcc, 0x43, 0x39, 0x00, 0x04, 0x39, 0xa4, 0xc3,
+ 0x3c, 0x84, 0x83, 0x38, 0xb0, 0x43, 0x39, 0xb4, 0x01, 0x3d, 0x84, 0x43,
+ 0x3a, 0xb0, 0x43, 0x1b, 0x8c, 0x43, 0x38, 0xb0, 0x03, 0x3b, 0xcc, 0x03,
+ 0x60, 0x0e, 0xe1, 0xc0, 0x0e, 0xf3, 0x50, 0x0e, 0x00, 0xc1, 0x0e, 0xe5,
+ 0x30, 0x0f, 0xf3, 0xd0, 0x06, 0xf0, 0x20, 0x0f, 0xe5, 0x30, 0x0e, 0xe9,
+ 0x30, 0x0f, 0xe5, 0xd0, 0x06, 0xe6, 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xe4,
+ 0x00, 0xd0, 0x83, 0x3c, 0xd4, 0x43, 0x39, 0x00, 0x84, 0x3b, 0xbc, 0x43,
+ 0x1b, 0x98, 0x83, 0x3c, 0x84, 0x43, 0x3b, 0x94, 0x43, 0x1b, 0xc0, 0xc3,
+ 0x3b, 0xa4, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xc8, 0x43, 0x1b, 0x94, 0x03,
+ 0x3b, 0xa4, 0x43, 0x3b, 0x00, 0xf4, 0x20, 0x0f, 0xf5, 0x50, 0x0e, 0xc0,
+ 0xe0, 0x0e, 0xef, 0xd0, 0x06, 0xe6, 0x20, 0x0f, 0xe1, 0xd0, 0x0e, 0xe5,
+ 0xd0, 0x06, 0xf0, 0xf0, 0x0e, 0xe9, 0xe0, 0x0e, 0xf4, 0x50, 0x0e, 0xf2,
+ 0xd0, 0x06, 0xe5, 0xc0, 0x0e, 0xe9, 0xd0, 0x0e, 0x6d, 0xe0, 0x0e, 0xef,
+ 0xe0, 0x0e, 0x6d, 0xc0, 0x0e, 0xe5, 0x10, 0x0e, 0xe6, 0x00, 0x10, 0xee,
+ 0xf0, 0x0e, 0x6d, 0x90, 0x0e, 0xee, 0x60, 0x0e, 0xf3, 0xd0, 0x06, 0xe6,
+ 0x00, 0x0f, 0x6d, 0xd0, 0x0e, 0xe1, 0x40, 0x0f, 0xe8, 0x00, 0xd0, 0x83,
+ 0x3c, 0xd4, 0x43, 0x39, 0x00, 0x84, 0x3b, 0xbc, 0x43, 0x1b, 0xa8, 0x43,
+ 0x3d, 0xb4, 0x03, 0x3c, 0xb4, 0x01, 0x3d, 0x84, 0x83, 0x38, 0xb0, 0x43,
+ 0x39, 0xcc, 0x03, 0x60, 0x0e, 0xe1, 0xc0, 0x0e, 0xf3, 0x50, 0x0e, 0x00,
+ 0xe1, 0x0e, 0xef, 0xd0, 0x06, 0xee, 0x10, 0x0e, 0xee, 0x30, 0x0f, 0x6d,
+ 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x00,
+ 0x3d, 0xc8, 0x43, 0x3d, 0x94, 0x03, 0x40, 0xb8, 0xc3, 0x3b, 0xb4, 0xc1,
+ 0x3c, 0xa4, 0xc3, 0x39, 0xb8, 0x43, 0x39, 0x90, 0x43, 0x1b, 0xe8, 0x43,
+ 0x39, 0xc8, 0xc3, 0x3b, 0xcc, 0x43, 0x1b, 0x98, 0x03, 0x3c, 0xb4, 0x41,
+ 0x3b, 0x84, 0x03, 0x3d, 0xa0, 0x03, 0x60, 0x0e, 0xe1, 0xc0, 0x0e, 0xf3,
+ 0x50, 0x0e, 0x00, 0x31, 0x0f, 0xf4, 0x10, 0x0e, 0xe3, 0xb0, 0x0e, 0x6d,
+ 0x00, 0x0f, 0xf2, 0xf0, 0x0e, 0xf4, 0x50, 0x0e, 0xe3, 0x40, 0x0f, 0xef,
+ 0x20, 0x0f, 0x6d, 0x20, 0x0e, 0xf5, 0x60, 0x0e, 0xe6, 0x50, 0x0e, 0xf2,
+ 0xd0, 0x06, 0xf3, 0x90, 0x0e, 0xfa, 0x50, 0x0e, 0x00, 0x1e, 0x00, 0x04,
+ 0x3d, 0x84, 0x83, 0x3c, 0x9c, 0x43, 0x39, 0xd0, 0x43, 0x1b, 0x98, 0x43,
+ 0x39, 0x84, 0x03, 0x3d, 0xd4, 0x83, 0x3c, 0x94, 0xc3, 0x3c, 0x00, 0x6d,
+ 0x60, 0x0e, 0xf0, 0x10, 0x07, 0x76, 0x00, 0x10, 0xf5, 0xe0, 0x0e, 0xf3,
+ 0x10, 0x0e, 0xe6, 0x50, 0x0e, 0x6d, 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed,
+ 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x00, 0x3d, 0xc8, 0x43, 0x3d, 0x94, 0x03,
+ 0x40, 0xd4, 0xc3, 0x3c, 0x94, 0x43, 0x1b, 0xcc, 0xc3, 0x3b, 0x98, 0x03,
+ 0x3d, 0xb4, 0x81, 0x39, 0xb0, 0xc3, 0x3b, 0x84, 0x03, 0x3d, 0x00, 0xe6,
+ 0x10, 0x0e, 0xec, 0x30, 0x0f, 0xe5, 0x00, 0x6c, 0x50, 0x95, 0xe2, 0xff,
+ 0xff, 0xff, 0xff, 0x07, 0x62, 0x1c, 0xde, 0x41, 0x1e, 0xe4, 0xa1, 0x1c,
+ 0xc6, 0x81, 0x1e, 0xd8, 0x21, 0x1f, 0xda, 0x40, 0x1e, 0xde, 0xa1, 0x1e,
+ 0xdc, 0x81, 0x1c, 0xca, 0x81, 0x1c, 0xda, 0x80, 0x1c, 0xd2, 0xc1, 0x1e,
+ 0xd2, 0x81, 0x1c, 0xca, 0xa1, 0x0d, 0xe6, 0x21, 0x1e, 0xe4, 0x81, 0x1e,
+ 0xda, 0xc0, 0x1c, 0xe0, 0xa1, 0x0d, 0xda, 0x21, 0x1c, 0xe8, 0x01, 0x1d,
+ 0x00, 0x73, 0x08, 0x07, 0x76, 0x98, 0x87, 0x72, 0x00, 0x08, 0x72, 0x48,
+ 0x87, 0x79, 0x08, 0x07, 0x71, 0x60, 0x87, 0x72, 0x68, 0x03, 0x7a, 0x08,
+ 0x87, 0x74, 0x60, 0x87, 0x36, 0x18, 0x87, 0x70, 0x60, 0x07, 0x76, 0x98,
+ 0x07, 0xc0, 0x1c, 0xc2, 0x81, 0x1d, 0xe6, 0xa1, 0x1c, 0x00, 0x82, 0x1d,
+ 0xca, 0x61, 0x1e, 0xe6, 0xa1, 0x0d, 0xe0, 0x41, 0x1e, 0xca, 0x61, 0x1c,
+ 0xd2, 0x61, 0x1e, 0xca, 0xa1, 0x0d, 0xcc, 0x01, 0x1e, 0xda, 0x21, 0x1c,
+ 0xc8, 0x01, 0xa0, 0x07, 0x79, 0xa8, 0x87, 0x72, 0x00, 0x08, 0x77, 0x78,
+ 0x87, 0x36, 0x30, 0x07, 0x79, 0x08, 0x87, 0x76, 0x28, 0x87, 0x36, 0x80,
+ 0x87, 0x77, 0x48, 0x07, 0x77, 0xa0, 0x87, 0x72, 0x90, 0x87, 0x36, 0x28,
+ 0x07, 0x76, 0x48, 0x87, 0x76, 0x00, 0xe8, 0x41, 0x1e, 0xea, 0xa1, 0x1c,
+ 0x80, 0xc1, 0x1d, 0xde, 0xa1, 0x0d, 0xcc, 0x41, 0x1e, 0xc2, 0xa1, 0x1d,
+ 0xca, 0xa1, 0x0d, 0xe0, 0xe1, 0x1d, 0xd2, 0xc1, 0x1d, 0xe8, 0xa1, 0x1c,
+ 0xe4, 0xa1, 0x0d, 0xca, 0x81, 0x1d, 0xd2, 0xa1, 0x1d, 0xda, 0xc0, 0x1d,
+ 0xde, 0xc1, 0x1d, 0xda, 0x80, 0x1d, 0xca, 0x21, 0x1c, 0xcc, 0x01, 0x20,
+ 0xdc, 0xe1, 0x1d, 0xda, 0x20, 0x1d, 0xdc, 0xc1, 0x1c, 0xe6, 0xa1, 0x0d,
+ 0xcc, 0x01, 0x1e, 0xda, 0xa0, 0x1d, 0xc2, 0x81, 0x1e, 0xd0, 0x01, 0xa0,
+ 0x07, 0x79, 0xa8, 0x87, 0x72, 0x00, 0x08, 0x77, 0x78, 0x87, 0x36, 0x70,
+ 0x87, 0x70, 0x70, 0x87, 0x79, 0x68, 0x03, 0x73, 0x80, 0x87, 0x36, 0x68,
+ 0x87, 0x70, 0xa0, 0x07, 0x74, 0x00, 0xe8, 0x41, 0x1e, 0xea, 0xa1, 0x1c,
+ 0x00, 0xc2, 0x1d, 0xde, 0xa1, 0x0d, 0xe6, 0x21, 0x1d, 0xce, 0xc1, 0x1d,
+ 0xca, 0x81, 0x1c, 0xda, 0x40, 0x1f, 0xca, 0x41, 0x1e, 0xde, 0x61, 0x1e,
+ 0xda, 0xc0, 0x1c, 0xe0, 0xa1, 0x0d, 0xda, 0x21, 0x1c, 0xe8, 0x01, 0x1d,
+ 0x00, 0x73, 0x08, 0x07, 0x76, 0x98, 0x87, 0x72, 0x00, 0x88, 0x79, 0xa0,
+ 0x87, 0x70, 0x18, 0x87, 0x75, 0x68, 0x03, 0x78, 0x90, 0x87, 0x77, 0xa0,
+ 0x87, 0x72, 0x18, 0x07, 0x7a, 0x78, 0x07, 0x79, 0x68, 0x03, 0x71, 0xa8,
+ 0x07, 0x73, 0x30, 0x87, 0x72, 0x90, 0x87, 0x36, 0x98, 0x87, 0x74, 0xd0,
+ 0x87, 0x72, 0x00, 0xf0, 0x00, 0x20, 0xe8, 0x21, 0x1c, 0xe4, 0xe1, 0x1c,
+ 0xca, 0x81, 0x1e, 0xda, 0xc0, 0x1c, 0xca, 0x21, 0x1c, 0xe8, 0xa1, 0x1e,
+ 0xe4, 0xa1, 0x1c, 0xe6, 0x01, 0x68, 0x03, 0x73, 0x80, 0x87, 0x38, 0xb0,
+ 0x03, 0x80, 0xa8, 0x07, 0x77, 0x98, 0x87, 0x70, 0x30, 0x87, 0x72, 0x68,
+ 0x03, 0x73, 0x80, 0x87, 0x36, 0x68, 0x87, 0x70, 0xa0, 0x07, 0x74, 0x00,
+ 0xe8, 0x41, 0x1e, 0xea, 0xa1, 0x1c, 0x00, 0xa2, 0x1e, 0xe6, 0xa1, 0x1c,
+ 0xda, 0x60, 0x1e, 0xde, 0xc1, 0x1c, 0xe8, 0xa1, 0x0d, 0xcc, 0x81, 0x1d,
+ 0xde, 0x21, 0x1c, 0xe8, 0x01, 0x30, 0x87, 0x70, 0x60, 0x87, 0x79, 0x28,
+ 0x07, 0x60, 0x03, 0x61, 0x04, 0xc0, 0xb2, 0x81, 0x38, 0x04, 0x60, 0xd9,
+ 0x80, 0x20, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x0c, 0x20, 0x01, 0xd5,
+ 0x06, 0x22, 0xf9, 0xff, 0xff, 0xff, 0xff, 0x01, 0x90, 0x00, 0x00, 0x00,
+ 0x49, 0x18, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x13, 0x88, 0x40, 0x18,
+ 0x88, 0x09, 0x41, 0x31, 0x61, 0x30, 0x0e, 0x64, 0x42, 0x90, 0x00, 0x00,
+ 0x89, 0x20, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09,
+ 0x20, 0x64, 0x85, 0x04, 0x93, 0x22, 0xa4, 0x84, 0x04, 0x93, 0x22, 0xe3,
+ 0x84, 0xa1, 0x90, 0x14, 0x12, 0x4c, 0x8a, 0x8c, 0x0b, 0x84, 0xa4, 0x4c,
+ 0x10, 0x68, 0x33, 0x00, 0xc3, 0x08, 0x04, 0x30, 0x8c, 0x20, 0x00, 0x83,
+ 0x08, 0x81, 0x30, 0x8c, 0x30, 0x00, 0x07, 0x49, 0x53, 0x44, 0x09, 0x93,
+ 0x2f, 0xbb, 0x6f, 0x47, 0x08, 0xce, 0x40, 0x20, 0x82, 0x10, 0x42, 0x06,
+ 0x11, 0x0a, 0xe1, 0x28, 0x69, 0x8a, 0x28, 0x61, 0xf2, 0xff, 0x89, 0xb8,
+ 0x26, 0x2a, 0x22, 0x7e, 0x7b, 0xf8, 0xa7, 0x31, 0x02, 0x60, 0x10, 0xe1,
+ 0x08, 0x2e, 0x92, 0xa6, 0x88, 0x12, 0x26, 0xff, 0x97, 0x00, 0xe6, 0x59,
+ 0x88, 0xe8, 0x9f, 0xc6, 0x08, 0x80, 0x41, 0x84, 0x44, 0x28, 0x48, 0x08,
+ 0x62, 0x18, 0x84, 0x14, 0xad, 0x32, 0x00, 0x42, 0xa8, 0xcd, 0x11, 0x04,
+ 0x73, 0x04, 0x60, 0x30, 0x8c, 0x20, 0x40, 0x05, 0x09, 0x48, 0x89, 0x17,
+ 0x1f, 0x20, 0x39, 0x10, 0x30, 0x8c, 0x30, 0x40, 0xc3, 0x08, 0x04, 0x34,
+ 0x47, 0x00, 0x0a, 0x83, 0x08, 0x84, 0x30, 0x02, 0x00, 0x00, 0x00, 0x00,
+ 0x13, 0xa8, 0x70, 0x48, 0x07, 0x79, 0xb0, 0x03, 0x3a, 0x68, 0x83, 0x70,
+ 0x80, 0x07, 0x78, 0x60, 0x87, 0x72, 0x68, 0x83, 0x74, 0x78, 0x87, 0x79,
+ 0xc8, 0x03, 0x37, 0x80, 0x03, 0x37, 0x80, 0x83, 0x0d, 0xef, 0x51, 0x0e,
+ 0x6d, 0x00, 0x0f, 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07,
+ 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe9, 0x10, 0x07, 0x7a, 0x80, 0x07,
+ 0x7a, 0x80, 0x07, 0x6d, 0x90, 0x0e, 0x78, 0xa0, 0x07, 0x78, 0xa0, 0x07,
+ 0x78, 0xd0, 0x06, 0xe9, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x60, 0x07,
+ 0x7a, 0x10, 0x07, 0x76, 0xd0, 0x06, 0xe9, 0x30, 0x07, 0x72, 0xa0, 0x07,
+ 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xe9, 0x60, 0x07,
+ 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06,
+ 0xe6, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07,
+ 0x72, 0xd0, 0x06, 0xe6, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07,
+ 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x80, 0x07, 0x70, 0xa0, 0x07,
+ 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0, 0x06,
+ 0xf6, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x60, 0x07, 0x7a, 0x10, 0x07,
+ 0x76, 0xd0, 0x06, 0xf6, 0x20, 0x07, 0x74, 0xa0, 0x07, 0x73, 0x20, 0x07,
+ 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xf6, 0x30, 0x07, 0x72, 0xa0, 0x07,
+ 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xf6, 0x40, 0x07,
+ 0x78, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06,
+ 0xf6, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07,
+ 0x74, 0xd0, 0x06, 0xf6, 0x90, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x20, 0x07,
+ 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0, 0x06, 0xf6, 0x10, 0x07,
+ 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07,
+ 0x72, 0x80, 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x90, 0x07, 0x72, 0xa0, 0x07,
+ 0x72, 0x50, 0x07, 0x76, 0xa0, 0x07, 0x72, 0x50, 0x07, 0x76, 0xd0, 0x06,
+ 0xf6, 0x20, 0x07, 0x75, 0x60, 0x07, 0x7a, 0x20, 0x07, 0x75, 0x60, 0x07,
+ 0x7a, 0x20, 0x07, 0x75, 0x60, 0x07, 0x6d, 0x60, 0x0f, 0x75, 0x10, 0x07,
+ 0x72, 0xa0, 0x07, 0x75, 0x10, 0x07, 0x72, 0xa0, 0x07, 0x75, 0x10, 0x07,
+ 0x72, 0xd0, 0x06, 0xf6, 0x10, 0x07, 0x70, 0x20, 0x07, 0x74, 0xa0, 0x07,
+ 0x71, 0x00, 0x07, 0x72, 0x40, 0x07, 0x7a, 0x10, 0x07, 0x70, 0x20, 0x07,
+ 0x74, 0xd0, 0x06, 0xe6, 0x80, 0x07, 0x70, 0xa0, 0x07, 0x71, 0x20, 0x07,
+ 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0, 0x06, 0xee, 0x80, 0x07,
+ 0x7a, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x43, 0x18, 0x06,
+ 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x21, 0x8c, 0x03, 0x04,
+ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x10, 0x66, 0x02, 0x02, 0x60,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x0b, 0x04, 0x0a, 0x00, 0x00, 0x00,
+ 0x32, 0x1e, 0x98, 0x14, 0x19, 0x11, 0x4c, 0x90, 0x8c, 0x09, 0x26, 0x47,
+ 0xc6, 0x04, 0x43, 0x82, 0x23, 0x00, 0x25, 0x50, 0x20, 0x05, 0x18, 0x50,
+ 0x10, 0x45, 0x50, 0x06, 0x05, 0x54, 0x60, 0x85, 0x50, 0x0a, 0xc5, 0x40,
+ 0x77, 0x04, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00, 0x0d, 0x01, 0x00, 0x00,
+ 0x1a, 0x03, 0x4c, 0x10, 0xd7, 0x20, 0x08, 0x0e, 0x8e, 0xad, 0x0c, 0x84,
+ 0x89, 0xc9, 0xaa, 0x09, 0xc4, 0xae, 0x4c, 0x6e, 0x2e, 0xed, 0xcd, 0x0d,
+ 0x04, 0x07, 0x46, 0xc6, 0x25, 0x06, 0x04, 0xa5, 0xad, 0x8c, 0x2e, 0x8c,
+ 0xcd, 0xac, 0xac, 0x05, 0x07, 0x46, 0xc6, 0x25, 0xc6, 0x65, 0x86, 0x26,
+ 0x65, 0x88, 0x40, 0x01, 0x43, 0x0c, 0x88, 0x80, 0x0e, 0x68, 0x60, 0xd1,
+ 0x54, 0x46, 0x17, 0xc6, 0x36, 0x04, 0xa1, 0x06, 0x88, 0x80, 0x08, 0x68,
+ 0xe0, 0x16, 0x96, 0x26, 0xe7, 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56,
+ 0xe6, 0x42, 0x56, 0xe6, 0xf6, 0x26, 0xd7, 0x36, 0xf7, 0x45, 0x96, 0x36,
+ 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0xa0, 0x0a, 0x72, 0x61, 0x69, 0x72,
+ 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x2e, 0x66, 0x61, 0x73,
+ 0x74, 0x5f, 0x6d, 0x61, 0x74, 0x68, 0x5f, 0x65, 0x6e, 0x61, 0x62, 0x6c,
+ 0x65, 0x43, 0x04, 0xea, 0x20, 0x19, 0x84, 0xa5, 0xc9, 0xb9, 0x8c, 0xbd,
+ 0xb5, 0xc1, 0xa5, 0xb1, 0x95, 0xb9, 0x98, 0xc9, 0x85, 0xb5, 0x95, 0x89,
+ 0xd5, 0x99, 0x99, 0x95, 0xc9, 0x7d, 0x99, 0x95, 0xd1, 0x8d, 0xa1, 0x7d,
+ 0x95, 0xb9, 0x85, 0x89, 0xb1, 0x95, 0x0d, 0x11, 0xa8, 0x84, 0x61, 0x10,
+ 0x96, 0x26, 0xe7, 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56, 0xe6, 0xe2,
+ 0x16, 0x46, 0x97, 0x66, 0x57, 0xf6, 0x45, 0xf6, 0x56, 0x27, 0xc6, 0x56,
+ 0xf6, 0x45, 0x96, 0x36, 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0xa0, 0x16,
+ 0x46, 0x61, 0x69, 0x72, 0x2e, 0x72, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x5f,
+ 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x8c, 0xc2, 0xd2, 0xe4, 0x5c, 0xc2,
+ 0xe4, 0xce, 0xbe, 0xe8, 0xf2, 0xe0, 0xca, 0xbe, 0xdc, 0xc2, 0xda, 0xca,
+ 0x68, 0x98, 0xb1, 0xbd, 0x85, 0xd1, 0xd1, 0x0c, 0x41, 0xa8, 0x06, 0x1a,
+ 0x28, 0x87, 0x7a, 0x86, 0x08, 0x14, 0x44, 0x26, 0x2c, 0x4d, 0xce, 0x05,
+ 0xee, 0x6d, 0x2e, 0x8d, 0x2e, 0xed, 0xcd, 0x8d, 0x4a, 0x58, 0x9a, 0x9c,
+ 0xcb, 0x58, 0x99, 0x1b, 0x5d, 0x99, 0x1c, 0xa5, 0xb0, 0x34, 0x39, 0x17,
+ 0xb7, 0xb7, 0x2f, 0xb8, 0x32, 0xb9, 0x39, 0xb8, 0xb2, 0x31, 0xba, 0x34,
+ 0xbb, 0x32, 0x32, 0x61, 0x69, 0x72, 0x2e, 0x61, 0x72, 0x67, 0x5f, 0x6e,
+ 0x61, 0x6d, 0x65, 0x44, 0xe0, 0xde, 0xe6, 0xd2, 0xe8, 0xd2, 0xde, 0xdc,
+ 0x86, 0x40, 0xd0, 0x40, 0x49, 0xd4, 0x44, 0x51, 0x94, 0x43, 0x3d, 0x54,
+ 0x45, 0x59, 0x94, 0xc2, 0xd2, 0xe4, 0x5c, 0xcc, 0xe4, 0xc2, 0xce, 0xda,
+ 0xca, 0xdc, 0xe8, 0xbe, 0xd2, 0xdc, 0xe0, 0xea, 0xe8, 0x98, 0x9d, 0x95,
+ 0xb9, 0x95, 0xc9, 0x85, 0xd1, 0x95, 0x91, 0xa1, 0xe0, 0xd0, 0x95, 0xe1,
+ 0x8d, 0xbd, 0xbd, 0xc9, 0x91, 0x11, 0xd9, 0xc9, 0x7c, 0x99, 0xa5, 0xf0,
+ 0x09, 0x4b, 0x93, 0x73, 0x81, 0x2b, 0x93, 0x9b, 0x83, 0x2b, 0x1b, 0xa3,
+ 0x4b, 0xb3, 0x2b, 0xa3, 0x61, 0xc6, 0xf6, 0x16, 0x46, 0x27, 0x43, 0x84,
+ 0xae, 0x0c, 0x6f, 0xec, 0xed, 0x4d, 0x8e, 0x6c, 0x88, 0x04, 0x11, 0x14,
+ 0x46, 0x65, 0xd4, 0x44, 0x69, 0x94, 0x43, 0x6d, 0x54, 0x45, 0x71, 0x54,
+ 0xc2, 0xd2, 0xe4, 0x5c, 0xc4, 0xea, 0xcc, 0xcc, 0xca, 0xe4, 0xf8, 0x84,
+ 0xa5, 0xc9, 0xb9, 0x88, 0xd5, 0x99, 0x99, 0x95, 0xc9, 0x7d, 0xcd, 0xa5,
+ 0xe9, 0x95, 0x51, 0x0a, 0x4b, 0x93, 0x73, 0x61, 0x7b, 0x1b, 0x0b, 0xa3,
+ 0x4b, 0x7b, 0x73, 0xfb, 0x4a, 0x73, 0x23, 0x2b, 0xc3, 0x23, 0x12, 0x96,
+ 0x26, 0xe7, 0x22, 0x57, 0x16, 0x46, 0xc6, 0x28, 0x2c, 0x4d, 0xce, 0x25,
+ 0x4c, 0xee, 0xec, 0x8b, 0x2e, 0x0f, 0xae, 0xec, 0x6b, 0x2e, 0x4d, 0xaf,
+ 0x8c, 0x57, 0x58, 0x9a, 0x9c, 0x4b, 0x98, 0xdc, 0xd9, 0x17, 0x5d, 0x1e,
+ 0x5c, 0xd9, 0x57, 0x18, 0x5b, 0xda, 0x99, 0xdb, 0xd7, 0x5c, 0x9a, 0x5e,
+ 0x19, 0x87, 0xb1, 0x37, 0xb6, 0x21, 0x60, 0x00, 0x21, 0x94, 0x47, 0x7d,
+ 0x50, 0x41, 0x81, 0x01, 0x34, 0x40, 0x04, 0x15, 0x06, 0x94, 0x18, 0x40,
+ 0x05, 0x35, 0x06, 0x50, 0x41, 0x39, 0xd4, 0x43, 0x55, 0x14, 0x19, 0x90,
+ 0x0a, 0x4b, 0x93, 0x73, 0x99, 0xa3, 0x93, 0xab, 0x1b, 0xa3, 0xfb, 0xa2,
+ 0xcb, 0x83, 0x2b, 0xfb, 0x4a, 0x73, 0x33, 0x7b, 0xa3, 0x61, 0xc6, 0xf6,
+ 0x16, 0x46, 0x37, 0x43, 0xe3, 0xcd, 0xcc, 0x6c, 0xae, 0x8c, 0x8e, 0x86,
+ 0xd4, 0xd8, 0x5b, 0x99, 0x99, 0x19, 0x8d, 0xa3, 0xb1, 0xb7, 0x32, 0x33,
+ 0x33, 0x1a, 0x42, 0x63, 0x6f, 0x65, 0x66, 0x66, 0x43, 0xd0, 0x00, 0x1a,
+ 0xa0, 0x02, 0x1a, 0xa8, 0x33, 0xa0, 0xd0, 0x00, 0x2a, 0xa0, 0x02, 0x1a,
+ 0xa8, 0x33, 0xa0, 0xd2, 0x00, 0x52, 0xa0, 0x02, 0x1a, 0xa8, 0x33, 0xa0,
+ 0xd4, 0x00, 0x5a, 0xa0, 0x02, 0x1a, 0xa8, 0x33, 0xa0, 0xd6, 0x80, 0x49,
+ 0x56, 0x95, 0x15, 0x51, 0xd9, 0xd8, 0x1b, 0x59, 0x19, 0x0d, 0xb2, 0xb2,
+ 0xb1, 0x37, 0xb2, 0xb2, 0x21, 0x64, 0x00, 0x25, 0x94, 0x47, 0x7d, 0x90,
+ 0x41, 0x81, 0x01, 0x44, 0x40, 0x04, 0x15, 0x06, 0x94, 0x19, 0x50, 0x6c,
+ 0x40, 0x89, 0x01, 0x64, 0x50, 0x63, 0x00, 0x15, 0x94, 0x43, 0xb5, 0x01,
+ 0x55, 0x51, 0x6e, 0xc0, 0x25, 0x2c, 0x4d, 0xce, 0x85, 0xae, 0x0c, 0x8f,
+ 0xae, 0x4e, 0xae, 0x8c, 0x4a, 0x58, 0x9a, 0x9c, 0xcb, 0x5c, 0x58, 0x1b,
+ 0x1c, 0x5b, 0x19, 0x31, 0xba, 0x32, 0x3c, 0xba, 0x3a, 0xb9, 0x32, 0x19,
+ 0x32, 0x1e, 0x33, 0xb6, 0xb7, 0x30, 0x3a, 0x16, 0x90, 0xb9, 0xb0, 0x36,
+ 0x38, 0xb6, 0x32, 0x1f, 0x12, 0x74, 0x65, 0x78, 0x59, 0x43, 0x28, 0x88,
+ 0xa1, 0xe0, 0x80, 0x02, 0x03, 0x68, 0x80, 0x08, 0x2a, 0x0e, 0x28, 0x87,
+ 0x92, 0x03, 0xaa, 0xa2, 0xe6, 0x80, 0x05, 0x5d, 0x19, 0x5e, 0x95, 0xd5,
+ 0x10, 0x0a, 0x6a, 0x28, 0x38, 0xa0, 0xc0, 0x00, 0x22, 0x20, 0x82, 0x8a,
+ 0x03, 0xca, 0xa1, 0xe4, 0x80, 0xaa, 0xa8, 0x3a, 0xe0, 0x12, 0x96, 0x26,
+ 0xe7, 0x32, 0x17, 0xd6, 0x06, 0xc7, 0x56, 0x26, 0xc7, 0x63, 0x2e, 0xac,
+ 0x0d, 0x8e, 0xad, 0x4c, 0x8e, 0xc1, 0xdc, 0x10, 0x09, 0x72, 0xa8, 0x3b,
+ 0xa0, 0xc0, 0x00, 0x1a, 0x20, 0x82, 0x72, 0x28, 0x3c, 0xa0, 0x2a, 0x2a,
+ 0x0f, 0x86, 0x38, 0xd4, 0x45, 0x75, 0x54, 0x19, 0x50, 0x6f, 0x40, 0xd1,
+ 0x01, 0x65, 0x07, 0x94, 0x1e, 0x0c, 0x31, 0x18, 0x80, 0x8a, 0xa8, 0x3d,
+ 0xe0, 0xf3, 0xd6, 0xe6, 0x96, 0x06, 0xf7, 0x46, 0x57, 0xe6, 0x46, 0x07,
+ 0x32, 0x86, 0x16, 0x26, 0xc7, 0x67, 0x2a, 0xad, 0x0d, 0x8e, 0xad, 0x0c,
+ 0x64, 0x68, 0x65, 0x05, 0x84, 0x4a, 0x28, 0x28, 0x68, 0x88, 0x40, 0xf9,
+ 0xc1, 0x10, 0x83, 0xea, 0x03, 0xea, 0x0f, 0xae, 0x67, 0x88, 0x41, 0x81,
+ 0x02, 0x05, 0x0a, 0xd7, 0x33, 0x42, 0x61, 0x07, 0x76, 0xb0, 0x87, 0x76,
+ 0x70, 0x83, 0x74, 0x20, 0x87, 0x72, 0x70, 0x07, 0x7a, 0x98, 0x12, 0x04,
+ 0x23, 0x96, 0x70, 0x48, 0x07, 0x79, 0x70, 0x03, 0x7b, 0x28, 0x07, 0x79,
+ 0x98, 0x87, 0x74, 0x78, 0x07, 0x77, 0x98, 0x12, 0x08, 0x23, 0xa8, 0x70,
+ 0x48, 0x07, 0x79, 0x70, 0x03, 0x76, 0x08, 0x07, 0x77, 0x38, 0x87, 0x7a,
+ 0x08, 0x87, 0x73, 0x28, 0x87, 0x5f, 0xb0, 0x87, 0x72, 0x90, 0x87, 0x79,
+ 0x48, 0x87, 0x77, 0x70, 0x87, 0x29, 0x01, 0x31, 0x62, 0x0a, 0x87, 0x74,
+ 0x90, 0x07, 0x37, 0x18, 0x87, 0x77, 0x68, 0x07, 0x78, 0x48, 0x07, 0x76,
+ 0x28, 0x87, 0x5f, 0x78, 0x07, 0x78, 0xa0, 0x87, 0x74, 0x78, 0x07, 0x77,
+ 0x98, 0x87, 0x29, 0x84, 0x81, 0x28, 0xcc, 0x08, 0x26, 0x1c, 0xd2, 0x41,
+ 0x1e, 0xdc, 0xc0, 0x1c, 0xe4, 0x21, 0x1c, 0xce, 0xa1, 0x1d, 0xca, 0xc1,
+ 0x1d, 0xe8, 0x61, 0x4a, 0xc0, 0x07, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
+ 0x5c, 0x00, 0x00, 0x00, 0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66,
+ 0x14, 0x01, 0x3d, 0x88, 0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07,
+ 0x79, 0x78, 0x07, 0x73, 0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10,
+ 0x0e, 0xf4, 0x80, 0x0e, 0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce,
+ 0xa1, 0x1c, 0x66, 0x30, 0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b,
+ 0xcc, 0x03, 0x3d, 0xc8, 0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c,
+ 0x74, 0x70, 0x07, 0x7b, 0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07,
+ 0x7a, 0x70, 0x03, 0x76, 0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11,
+ 0x0e, 0xec, 0x90, 0x0e, 0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0,
+ 0x0e, 0xf0, 0x50, 0x0e, 0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8,
+ 0x21, 0x1d, 0xc2, 0x61, 0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b,
+ 0xd0, 0x43, 0x39, 0xb4, 0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b,
+ 0xcc, 0xf0, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87,
+ 0x72, 0x68, 0x07, 0x37, 0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07,
+ 0x76, 0x28, 0x07, 0x76, 0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87,
+ 0x5f, 0x08, 0x87, 0x71, 0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81,
+ 0x2c, 0xee, 0xf0, 0x0e, 0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30,
+ 0x03, 0x62, 0xc8, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4,
+ 0xa1, 0x1c, 0xdc, 0x61, 0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca,
+ 0x61, 0x06, 0xd6, 0x90, 0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39,
+ 0xc8, 0x43, 0x39, 0xb8, 0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b,
+ 0x94, 0xc3, 0x2f, 0xbc, 0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b,
+ 0xb0, 0xc3, 0x0c, 0xc7, 0x69, 0x87, 0x70, 0x58, 0x87, 0x72, 0x70, 0x83,
+ 0x74, 0x68, 0x07, 0x78, 0x60, 0x87, 0x74, 0x18, 0x87, 0x74, 0xa0, 0x87,
+ 0x19, 0xce, 0x53, 0x0f, 0xee, 0x00, 0x0f, 0xf2, 0x50, 0x0e, 0xe4, 0x90,
+ 0x0e, 0xe3, 0x40, 0x0f, 0xe1, 0x20, 0x0e, 0xec, 0x50, 0x0e, 0x33, 0x20,
+ 0x28, 0x1d, 0xdc, 0xc1, 0x1e, 0xc2, 0x41, 0x1e, 0xd2, 0x21, 0x1c, 0xdc,
+ 0x81, 0x1e, 0xdc, 0xe0, 0x1c, 0xe4, 0xe1, 0x1d, 0xea, 0x01, 0x1e, 0x66,
+ 0x18, 0x51, 0x38, 0xb0, 0x43, 0x3a, 0x9c, 0x83, 0x3b, 0xcc, 0x50, 0x24,
+ 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x60, 0x87, 0x77, 0x78, 0x07,
+ 0x78, 0x98, 0x51, 0x4c, 0xf4, 0x90, 0x0f, 0xf0, 0x50, 0x0e, 0x00, 0x00,
+ 0x71, 0x20, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x16, 0xd0, 0x00, 0x48,
+ 0xe4, 0x0f, 0xce, 0xe4, 0x57, 0x77, 0x71, 0xdb, 0x26, 0xb0, 0x01, 0x48,
+ 0xe4, 0x4b, 0x00, 0xf3, 0x2c, 0xc4, 0x3f, 0x11, 0xd7, 0x44, 0x45, 0xc4,
+ 0x6f, 0x0f, 0x7e, 0x85, 0x17, 0xb7, 0x6d, 0x00, 0x11, 0xdb, 0x95, 0xff,
+ 0xf9, 0xd6, 0xf6, 0x5f, 0x44, 0x80, 0xc1, 0x10, 0xcd, 0x04, 0x00, 0x00,
+ 0x61, 0x20, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x13, 0x04, 0x41, 0x2c,
+ 0x10, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x64, 0xe7, 0x20, 0x06,
+ 0x02, 0xe9, 0xa8, 0x8e, 0x35, 0x00, 0x03, 0x31, 0xc7, 0x30, 0x10, 0xdd,
+ 0x1c, 0xc3, 0xd0, 0x75, 0xf4, 0x6a, 0x60, 0x04, 0x80, 0xe0, 0x0c, 0x00,
+ 0xc5, 0x11, 0x00, 0xaa, 0x63, 0x0d, 0x40, 0x20, 0x10, 0x99, 0x01, 0xa0,
+ 0x30, 0x03, 0x40, 0x60, 0x8c, 0x00, 0x04, 0x41, 0x10, 0xff, 0x46, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x23, 0x06, 0xca, 0x10, 0x88, 0x01, 0xe4, 0x4c,
+ 0x89, 0x81, 0x04, 0x23, 0x06, 0xca, 0x10, 0x8c, 0x01, 0xf4, 0x50, 0xca,
+ 0x91, 0x08, 0x83, 0x0c, 0x42, 0xc1, 0x0c, 0x32, 0x08, 0x86, 0x33, 0xc8,
+ 0x20, 0x04, 0xd0, 0x20, 0x43, 0x90, 0x48, 0x77, 0x8d, 0xa5, 0xa0, 0xd8,
+ 0x10, 0xc0, 0x87, 0xb6, 0x32, 0xc8, 0x20, 0x34, 0xcf, 0x78, 0x03, 0x07,
+ 0x06, 0x6b, 0x70, 0xc1, 0x58, 0x0a, 0xca, 0x20, 0x43, 0x10, 0x4d, 0x23,
+ 0x06, 0x05, 0x11, 0xc8, 0x41, 0x11, 0xcc, 0x31, 0x4c, 0x41, 0x1c, 0x8c,
+ 0x37, 0x88, 0x81, 0x19, 0xb4, 0xc1, 0x05, 0x63, 0x29, 0x28, 0x83, 0x0c,
+ 0xc1, 0x95, 0x8d, 0x18, 0x14, 0x44, 0x80, 0x07, 0x4b, 0x30, 0xc7, 0x60,
+ 0x04, 0x76, 0x30, 0xde, 0x80, 0x06, 0x6c, 0x20, 0x07, 0x17, 0x8c, 0xa5,
+ 0xa0, 0x0c, 0x32, 0x04, 0xdd, 0x37, 0x62, 0x50, 0x10, 0x81, 0x1f, 0x44,
+ 0xc1, 0x1c, 0x83, 0x11, 0xe0, 0xc1, 0x1c, 0x43, 0xf0, 0xe1, 0x81, 0x05,
+ 0x95, 0x7c, 0x32, 0x08, 0x88, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x5b, 0x86, 0x24, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xde, 0xc0, 0x17, 0x0b, 0x00, 0x00, 0x00, 0x00,
+ 0x14, 0x00, 0x00, 0x00, 0xf8, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+ 0x42, 0x43, 0xc0, 0xde, 0x21, 0x0c, 0x00, 0x00, 0x7b, 0x03, 0x00, 0x00,
+ 0x0b, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00,
+ 0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39,
+ 0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19, 0x1e, 0x04, 0x8b, 0x62,
+ 0x80, 0x14, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42, 0xa4, 0x10, 0x32, 0x14,
+ 0x38, 0x08, 0x18, 0x49, 0x0a, 0x32, 0x44, 0x24, 0x48, 0x0a, 0x90, 0x21,
+ 0x23, 0xc4, 0x52, 0x80, 0x0c, 0x19, 0x21, 0x72, 0x24, 0x07, 0xc8, 0x48,
+ 0x11, 0x62, 0xa8, 0xa0, 0xa8, 0x40, 0xc6, 0xf0, 0x01, 0x00, 0x00, 0x00,
+ 0x51, 0x18, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x1b, 0x8c, 0x60, 0x00,
+ 0x16, 0xa0, 0xda, 0x60, 0x08, 0x04, 0xb0, 0x00, 0xd5, 0x06, 0x63, 0x38,
+ 0x80, 0x05, 0xa8, 0x36, 0x90, 0x0b, 0xf1, 0xff, 0xff, 0xff, 0xff, 0x03,
+ 0xc0, 0x00, 0x12, 0x31, 0x0e, 0xef, 0x20, 0x0f, 0xf2, 0x50, 0x0e, 0xe3,
+ 0x40, 0x0f, 0xec, 0x90, 0x0f, 0x6d, 0x20, 0x0f, 0xef, 0x50, 0x0f, 0xee,
+ 0x40, 0x0e, 0xe5, 0x40, 0x0e, 0x6d, 0x40, 0x0e, 0xe9, 0x60, 0x0f, 0xe9,
+ 0x40, 0x0e, 0xe5, 0xd0, 0x06, 0xf3, 0x10, 0x0f, 0xf2, 0x40, 0x0f, 0x6d,
+ 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x80,
+ 0x39, 0x84, 0x03, 0x3b, 0xcc, 0x43, 0x39, 0x00, 0x04, 0x39, 0xa4, 0xc3,
+ 0x3c, 0x84, 0x83, 0x38, 0xb0, 0x43, 0x39, 0xb4, 0x01, 0x3d, 0x84, 0x43,
+ 0x3a, 0xb0, 0x43, 0x1b, 0x8c, 0x43, 0x38, 0xb0, 0x03, 0x3b, 0xcc, 0x03,
+ 0x60, 0x0e, 0xe1, 0xc0, 0x0e, 0xf3, 0x50, 0x0e, 0x00, 0xc1, 0x0e, 0xe5,
+ 0x30, 0x0f, 0xf3, 0xd0, 0x06, 0xf0, 0x20, 0x0f, 0xe5, 0x30, 0x0e, 0xe9,
+ 0x30, 0x0f, 0xe5, 0xd0, 0x06, 0xe6, 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xe4,
+ 0x00, 0xd0, 0x83, 0x3c, 0xd4, 0x43, 0x39, 0x00, 0x84, 0x3b, 0xbc, 0x43,
+ 0x1b, 0x98, 0x83, 0x3c, 0x84, 0x43, 0x3b, 0x94, 0x43, 0x1b, 0xc0, 0xc3,
+ 0x3b, 0xa4, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xc8, 0x43, 0x1b, 0x94, 0x03,
+ 0x3b, 0xa4, 0x43, 0x3b, 0x00, 0xf4, 0x20, 0x0f, 0xf5, 0x50, 0x0e, 0xc0,
+ 0xe0, 0x0e, 0xef, 0xd0, 0x06, 0xe6, 0x20, 0x0f, 0xe1, 0xd0, 0x0e, 0xe5,
+ 0xd0, 0x06, 0xf0, 0xf0, 0x0e, 0xe9, 0xe0, 0x0e, 0xf4, 0x50, 0x0e, 0xf2,
+ 0xd0, 0x06, 0xe5, 0xc0, 0x0e, 0xe9, 0xd0, 0x0e, 0x6d, 0xe0, 0x0e, 0xef,
+ 0xe0, 0x0e, 0x6d, 0xc0, 0x0e, 0xe5, 0x10, 0x0e, 0xe6, 0x00, 0x10, 0xee,
+ 0xf0, 0x0e, 0x6d, 0x90, 0x0e, 0xee, 0x60, 0x0e, 0xf3, 0xd0, 0x06, 0xe6,
+ 0x00, 0x0f, 0x6d, 0xd0, 0x0e, 0xe1, 0x40, 0x0f, 0xe8, 0x00, 0xd0, 0x83,
+ 0x3c, 0xd4, 0x43, 0x39, 0x00, 0x84, 0x3b, 0xbc, 0x43, 0x1b, 0xa8, 0x43,
+ 0x3d, 0xb4, 0x03, 0x3c, 0xb4, 0x01, 0x3d, 0x84, 0x83, 0x38, 0xb0, 0x43,
+ 0x39, 0xcc, 0x03, 0x60, 0x0e, 0xe1, 0xc0, 0x0e, 0xf3, 0x50, 0x0e, 0x00,
+ 0xe1, 0x0e, 0xef, 0xd0, 0x06, 0xee, 0x10, 0x0e, 0xee, 0x30, 0x0f, 0x6d,
+ 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x00,
+ 0x3d, 0xc8, 0x43, 0x3d, 0x94, 0x03, 0x40, 0xb8, 0xc3, 0x3b, 0xb4, 0xc1,
+ 0x3c, 0xa4, 0xc3, 0x39, 0xb8, 0x43, 0x39, 0x90, 0x43, 0x1b, 0xe8, 0x43,
+ 0x39, 0xc8, 0xc3, 0x3b, 0xcc, 0x43, 0x1b, 0x98, 0x03, 0x3c, 0xb4, 0x41,
+ 0x3b, 0x84, 0x03, 0x3d, 0xa0, 0x03, 0x60, 0x0e, 0xe1, 0xc0, 0x0e, 0xf3,
+ 0x50, 0x0e, 0x00, 0x31, 0x0f, 0xf4, 0x10, 0x0e, 0xe3, 0xb0, 0x0e, 0x6d,
+ 0x00, 0x0f, 0xf2, 0xf0, 0x0e, 0xf4, 0x50, 0x0e, 0xe3, 0x40, 0x0f, 0xef,
+ 0x20, 0x0f, 0x6d, 0x20, 0x0e, 0xf5, 0x60, 0x0e, 0xe6, 0x50, 0x0e, 0xf2,
+ 0xd0, 0x06, 0xf3, 0x90, 0x0e, 0xfa, 0x50, 0x0e, 0x00, 0x1e, 0x00, 0x04,
+ 0x3d, 0x84, 0x83, 0x3c, 0x9c, 0x43, 0x39, 0xd0, 0x43, 0x1b, 0x98, 0x43,
+ 0x39, 0x84, 0x03, 0x3d, 0xd4, 0x83, 0x3c, 0x94, 0xc3, 0x3c, 0x00, 0x6d,
+ 0x60, 0x0e, 0xf0, 0x10, 0x07, 0x76, 0x00, 0x10, 0xf5, 0xe0, 0x0e, 0xf3,
+ 0x10, 0x0e, 0xe6, 0x50, 0x0e, 0x6d, 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed,
+ 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x00, 0x3d, 0xc8, 0x43, 0x3d, 0x94, 0x03,
+ 0x40, 0xd4, 0xc3, 0x3c, 0x94, 0x43, 0x1b, 0xcc, 0xc3, 0x3b, 0x98, 0x03,
+ 0x3d, 0xb4, 0x81, 0x39, 0xb0, 0xc3, 0x3b, 0x84, 0x03, 0x3d, 0x00, 0xe6,
+ 0x10, 0x0e, 0xec, 0x30, 0x0f, 0xe5, 0x00, 0x6c, 0x50, 0x95, 0xe2, 0xff,
+ 0xff, 0xff, 0xff, 0x07, 0x62, 0x1c, 0xde, 0x41, 0x1e, 0xe4, 0xa1, 0x1c,
+ 0xc6, 0x81, 0x1e, 0xd8, 0x21, 0x1f, 0xda, 0x40, 0x1e, 0xde, 0xa1, 0x1e,
+ 0xdc, 0x81, 0x1c, 0xca, 0x81, 0x1c, 0xda, 0x80, 0x1c, 0xd2, 0xc1, 0x1e,
+ 0xd2, 0x81, 0x1c, 0xca, 0xa1, 0x0d, 0xe6, 0x21, 0x1e, 0xe4, 0x81, 0x1e,
+ 0xda, 0xc0, 0x1c, 0xe0, 0xa1, 0x0d, 0xda, 0x21, 0x1c, 0xe8, 0x01, 0x1d,
+ 0x00, 0x73, 0x08, 0x07, 0x76, 0x98, 0x87, 0x72, 0x00, 0x08, 0x72, 0x48,
+ 0x87, 0x79, 0x08, 0x07, 0x71, 0x60, 0x87, 0x72, 0x68, 0x03, 0x7a, 0x08,
+ 0x87, 0x74, 0x60, 0x87, 0x36, 0x18, 0x87, 0x70, 0x60, 0x07, 0x76, 0x98,
+ 0x07, 0xc0, 0x1c, 0xc2, 0x81, 0x1d, 0xe6, 0xa1, 0x1c, 0x00, 0x82, 0x1d,
+ 0xca, 0x61, 0x1e, 0xe6, 0xa1, 0x0d, 0xe0, 0x41, 0x1e, 0xca, 0x61, 0x1c,
+ 0xd2, 0x61, 0x1e, 0xca, 0xa1, 0x0d, 0xcc, 0x01, 0x1e, 0xda, 0x21, 0x1c,
+ 0xc8, 0x01, 0xa0, 0x07, 0x79, 0xa8, 0x87, 0x72, 0x00, 0x08, 0x77, 0x78,
+ 0x87, 0x36, 0x30, 0x07, 0x79, 0x08, 0x87, 0x76, 0x28, 0x87, 0x36, 0x80,
+ 0x87, 0x77, 0x48, 0x07, 0x77, 0xa0, 0x87, 0x72, 0x90, 0x87, 0x36, 0x28,
+ 0x07, 0x76, 0x48, 0x87, 0x76, 0x00, 0xe8, 0x41, 0x1e, 0xea, 0xa1, 0x1c,
+ 0x80, 0xc1, 0x1d, 0xde, 0xa1, 0x0d, 0xcc, 0x41, 0x1e, 0xc2, 0xa1, 0x1d,
+ 0xca, 0xa1, 0x0d, 0xe0, 0xe1, 0x1d, 0xd2, 0xc1, 0x1d, 0xe8, 0xa1, 0x1c,
+ 0xe4, 0xa1, 0x0d, 0xca, 0x81, 0x1d, 0xd2, 0xa1, 0x1d, 0xda, 0xc0, 0x1d,
+ 0xde, 0xc1, 0x1d, 0xda, 0x80, 0x1d, 0xca, 0x21, 0x1c, 0xcc, 0x01, 0x20,
+ 0xdc, 0xe1, 0x1d, 0xda, 0x20, 0x1d, 0xdc, 0xc1, 0x1c, 0xe6, 0xa1, 0x0d,
+ 0xcc, 0x01, 0x1e, 0xda, 0xa0, 0x1d, 0xc2, 0x81, 0x1e, 0xd0, 0x01, 0xa0,
+ 0x07, 0x79, 0xa8, 0x87, 0x72, 0x00, 0x08, 0x77, 0x78, 0x87, 0x36, 0x70,
+ 0x87, 0x70, 0x70, 0x87, 0x79, 0x68, 0x03, 0x73, 0x80, 0x87, 0x36, 0x68,
+ 0x87, 0x70, 0xa0, 0x07, 0x74, 0x00, 0xe8, 0x41, 0x1e, 0xea, 0xa1, 0x1c,
+ 0x00, 0xc2, 0x1d, 0xde, 0xa1, 0x0d, 0xe6, 0x21, 0x1d, 0xce, 0xc1, 0x1d,
+ 0xca, 0x81, 0x1c, 0xda, 0x40, 0x1f, 0xca, 0x41, 0x1e, 0xde, 0x61, 0x1e,
+ 0xda, 0xc0, 0x1c, 0xe0, 0xa1, 0x0d, 0xda, 0x21, 0x1c, 0xe8, 0x01, 0x1d,
+ 0x00, 0x73, 0x08, 0x07, 0x76, 0x98, 0x87, 0x72, 0x00, 0x88, 0x79, 0xa0,
+ 0x87, 0x70, 0x18, 0x87, 0x75, 0x68, 0x03, 0x78, 0x90, 0x87, 0x77, 0xa0,
+ 0x87, 0x72, 0x18, 0x07, 0x7a, 0x78, 0x07, 0x79, 0x68, 0x03, 0x71, 0xa8,
+ 0x07, 0x73, 0x30, 0x87, 0x72, 0x90, 0x87, 0x36, 0x98, 0x87, 0x74, 0xd0,
+ 0x87, 0x72, 0x00, 0xf0, 0x00, 0x20, 0xe8, 0x21, 0x1c, 0xe4, 0xe1, 0x1c,
+ 0xca, 0x81, 0x1e, 0xda, 0xc0, 0x1c, 0xca, 0x21, 0x1c, 0xe8, 0xa1, 0x1e,
+ 0xe4, 0xa1, 0x1c, 0xe6, 0x01, 0x68, 0x03, 0x73, 0x80, 0x87, 0x38, 0xb0,
+ 0x03, 0x80, 0xa8, 0x07, 0x77, 0x98, 0x87, 0x70, 0x30, 0x87, 0x72, 0x68,
+ 0x03, 0x73, 0x80, 0x87, 0x36, 0x68, 0x87, 0x70, 0xa0, 0x07, 0x74, 0x00,
+ 0xe8, 0x41, 0x1e, 0xea, 0xa1, 0x1c, 0x00, 0xa2, 0x1e, 0xe6, 0xa1, 0x1c,
+ 0xda, 0x60, 0x1e, 0xde, 0xc1, 0x1c, 0xe8, 0xa1, 0x0d, 0xcc, 0x81, 0x1d,
+ 0xde, 0x21, 0x1c, 0xe8, 0x01, 0x30, 0x87, 0x70, 0x60, 0x87, 0x79, 0x28,
+ 0x07, 0x60, 0x03, 0x61, 0x04, 0xc0, 0xb2, 0x81, 0x38, 0x04, 0x60, 0xd9,
+ 0x80, 0x20, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x0c, 0x20, 0x01, 0xd5,
+ 0x06, 0x22, 0xf9, 0xff, 0xff, 0xff, 0xff, 0x01, 0x90, 0x00, 0x00, 0x00,
+ 0x49, 0x18, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x13, 0x88, 0x40, 0x18,
+ 0x88, 0x09, 0x41, 0x31, 0x61, 0x30, 0x0e, 0x64, 0x42, 0x90, 0x00, 0x00,
+ 0x89, 0x20, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09,
+ 0x20, 0x64, 0x85, 0x04, 0x93, 0x22, 0xa4, 0x84, 0x04, 0x93, 0x22, 0xe3,
+ 0x84, 0xa1, 0x90, 0x14, 0x12, 0x4c, 0x8a, 0x8c, 0x0b, 0x84, 0xa4, 0x4c,
+ 0x10, 0x68, 0x33, 0x00, 0xc3, 0x08, 0x04, 0x30, 0x8c, 0x20, 0x00, 0x83,
+ 0x08, 0x81, 0x30, 0x8c, 0x30, 0x00, 0x07, 0x49, 0x53, 0x44, 0x09, 0x93,
+ 0x2f, 0xbb, 0x6f, 0x47, 0x08, 0xce, 0x40, 0x20, 0x82, 0x10, 0x42, 0x06,
+ 0x11, 0x0a, 0xe1, 0x28, 0x69, 0x8a, 0x28, 0x61, 0xf2, 0xff, 0x89, 0xb8,
+ 0x26, 0x2a, 0x22, 0x7e, 0x7b, 0xf8, 0xa7, 0x31, 0x02, 0x60, 0x10, 0xe1,
+ 0x08, 0x2e, 0x92, 0xa6, 0x88, 0x12, 0x26, 0xff, 0x97, 0x00, 0xe6, 0x59,
+ 0x88, 0xe8, 0x9f, 0xc6, 0x08, 0x80, 0x41, 0x84, 0x44, 0x28, 0x48, 0x08,
+ 0x62, 0x18, 0x84, 0x14, 0xad, 0x32, 0x00, 0x42, 0xa8, 0xcd, 0x11, 0x04,
+ 0x73, 0x04, 0x60, 0x30, 0x8c, 0x20, 0x40, 0x05, 0x09, 0x48, 0x89, 0x17,
+ 0x1f, 0x20, 0x39, 0x10, 0x30, 0x8c, 0x30, 0x40, 0xc3, 0x08, 0x04, 0x34,
+ 0x47, 0x00, 0x0a, 0x83, 0x08, 0x84, 0x30, 0x02, 0x00, 0x00, 0x00, 0x00,
+ 0x13, 0xa8, 0x70, 0x48, 0x07, 0x79, 0xb0, 0x03, 0x3a, 0x68, 0x83, 0x70,
+ 0x80, 0x07, 0x78, 0x60, 0x87, 0x72, 0x68, 0x83, 0x74, 0x78, 0x87, 0x79,
+ 0xc8, 0x03, 0x37, 0x80, 0x03, 0x37, 0x80, 0x83, 0x0d, 0xef, 0x51, 0x0e,
+ 0x6d, 0x00, 0x0f, 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07,
+ 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe9, 0x10, 0x07, 0x7a, 0x80, 0x07,
+ 0x7a, 0x80, 0x07, 0x6d, 0x90, 0x0e, 0x78, 0xa0, 0x07, 0x78, 0xa0, 0x07,
+ 0x78, 0xd0, 0x06, 0xe9, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x60, 0x07,
+ 0x7a, 0x10, 0x07, 0x76, 0xd0, 0x06, 0xe9, 0x30, 0x07, 0x72, 0xa0, 0x07,
+ 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xe9, 0x60, 0x07,
+ 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06,
+ 0xe6, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07,
+ 0x72, 0xd0, 0x06, 0xe6, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07,
+ 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06, 0xe6, 0x80, 0x07, 0x70, 0xa0, 0x07,
+ 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0, 0x06,
+ 0xf6, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x60, 0x07, 0x7a, 0x10, 0x07,
+ 0x76, 0xd0, 0x06, 0xf6, 0x20, 0x07, 0x74, 0xa0, 0x07, 0x73, 0x20, 0x07,
+ 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xf6, 0x30, 0x07, 0x72, 0xa0, 0x07,
+ 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xd0, 0x06, 0xf6, 0x40, 0x07,
+ 0x78, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xd0, 0x06,
+ 0xf6, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07,
+ 0x74, 0xd0, 0x06, 0xf6, 0x90, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x20, 0x07,
+ 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0, 0x06, 0xf6, 0x10, 0x07,
+ 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07,
+ 0x72, 0x80, 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x90, 0x07, 0x72, 0xa0, 0x07,
+ 0x72, 0x50, 0x07, 0x76, 0xa0, 0x07, 0x72, 0x50, 0x07, 0x76, 0xd0, 0x06,
+ 0xf6, 0x20, 0x07, 0x75, 0x60, 0x07, 0x7a, 0x20, 0x07, 0x75, 0x60, 0x07,
+ 0x7a, 0x20, 0x07, 0x75, 0x60, 0x07, 0x6d, 0x60, 0x0f, 0x75, 0x10, 0x07,
+ 0x72, 0xa0, 0x07, 0x75, 0x10, 0x07, 0x72, 0xa0, 0x07, 0x75, 0x10, 0x07,
+ 0x72, 0xd0, 0x06, 0xf6, 0x10, 0x07, 0x70, 0x20, 0x07, 0x74, 0xa0, 0x07,
+ 0x71, 0x00, 0x07, 0x72, 0x40, 0x07, 0x7a, 0x10, 0x07, 0x70, 0x20, 0x07,
+ 0x74, 0xd0, 0x06, 0xe6, 0x80, 0x07, 0x70, 0xa0, 0x07, 0x71, 0x20, 0x07,
+ 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0, 0x06, 0xee, 0x80, 0x07,
+ 0x7a, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x43, 0x18, 0x06,
+ 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x21, 0x8c, 0x03, 0x04,
+ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x10, 0x66, 0x02, 0x02, 0x60,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x0b, 0x04, 0x0a, 0x00, 0x00, 0x00,
+ 0x32, 0x1e, 0x98, 0x14, 0x19, 0x11, 0x4c, 0x90, 0x8c, 0x09, 0x26, 0x47,
+ 0xc6, 0x04, 0x43, 0x82, 0x23, 0x00, 0x25, 0x50, 0x20, 0x05, 0x18, 0x50,
+ 0x10, 0x45, 0x50, 0x06, 0x05, 0x54, 0x60, 0x85, 0x50, 0x0a, 0xc5, 0x40,
+ 0x77, 0x04, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00, 0x0d, 0x01, 0x00, 0x00,
+ 0x1a, 0x03, 0x4c, 0x10, 0xd7, 0x20, 0x08, 0x0e, 0x8e, 0xad, 0x0c, 0x84,
+ 0x89, 0xc9, 0xaa, 0x09, 0xc4, 0xae, 0x4c, 0x6e, 0x2e, 0xed, 0xcd, 0x0d,
+ 0x04, 0x07, 0x46, 0xc6, 0x25, 0x06, 0x04, 0xa5, 0xad, 0x8c, 0x2e, 0x8c,
+ 0xcd, 0xac, 0xac, 0x05, 0x07, 0x46, 0xc6, 0x25, 0xc6, 0x65, 0x86, 0x26,
+ 0x65, 0x88, 0x40, 0x01, 0x43, 0x0c, 0x88, 0x80, 0x0e, 0x68, 0x60, 0xd1,
+ 0x54, 0x46, 0x17, 0xc6, 0x36, 0x04, 0xa1, 0x06, 0x88, 0x80, 0x08, 0x68,
+ 0xe0, 0x16, 0x96, 0x26, 0xe7, 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56,
+ 0xe6, 0x42, 0x56, 0xe6, 0xf6, 0x26, 0xd7, 0x36, 0xf7, 0x45, 0x96, 0x36,
+ 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0xa0, 0x0a, 0x72, 0x61, 0x69, 0x72,
+ 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x2e, 0x66, 0x61, 0x73,
+ 0x74, 0x5f, 0x6d, 0x61, 0x74, 0x68, 0x5f, 0x65, 0x6e, 0x61, 0x62, 0x6c,
+ 0x65, 0x43, 0x04, 0xea, 0x20, 0x19, 0x84, 0xa5, 0xc9, 0xb9, 0x8c, 0xbd,
+ 0xb5, 0xc1, 0xa5, 0xb1, 0x95, 0xb9, 0x98, 0xc9, 0x85, 0xb5, 0x95, 0x89,
+ 0xd5, 0x99, 0x99, 0x95, 0xc9, 0x7d, 0x99, 0x95, 0xd1, 0x8d, 0xa1, 0x7d,
+ 0x95, 0xb9, 0x85, 0x89, 0xb1, 0x95, 0x0d, 0x11, 0xa8, 0x84, 0x61, 0x10,
+ 0x96, 0x26, 0xe7, 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56, 0xe6, 0xe2,
+ 0x16, 0x46, 0x97, 0x66, 0x57, 0xf6, 0x45, 0xf6, 0x56, 0x27, 0xc6, 0x56,
+ 0xf6, 0x45, 0x96, 0x36, 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0xa0, 0x16,
+ 0x46, 0x61, 0x69, 0x72, 0x2e, 0x72, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x5f,
+ 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x8c, 0xc2, 0xd2, 0xe4, 0x5c, 0xc2,
+ 0xe4, 0xce, 0xbe, 0xe8, 0xf2, 0xe0, 0xca, 0xbe, 0xdc, 0xc2, 0xda, 0xca,
+ 0x68, 0x98, 0xb1, 0xbd, 0x85, 0xd1, 0xd1, 0x0c, 0x41, 0xa8, 0x06, 0x1a,
+ 0x28, 0x87, 0x7a, 0x86, 0x08, 0x14, 0x44, 0x26, 0x2c, 0x4d, 0xce, 0x05,
+ 0xee, 0x6d, 0x2e, 0x8d, 0x2e, 0xed, 0xcd, 0x8d, 0x4a, 0x58, 0x9a, 0x9c,
+ 0xcb, 0x58, 0x99, 0x1b, 0x5d, 0x99, 0x1c, 0xa5, 0xb0, 0x34, 0x39, 0x17,
+ 0xb7, 0xb7, 0x2f, 0xb8, 0x32, 0xb9, 0x39, 0xb8, 0xb2, 0x31, 0xba, 0x34,
+ 0xbb, 0x32, 0x32, 0x61, 0x69, 0x72, 0x2e, 0x61, 0x72, 0x67, 0x5f, 0x6e,
+ 0x61, 0x6d, 0x65, 0x44, 0xe0, 0xde, 0xe6, 0xd2, 0xe8, 0xd2, 0xde, 0xdc,
+ 0x86, 0x40, 0xd0, 0x40, 0x49, 0xd4, 0x44, 0x51, 0x94, 0x43, 0x3d, 0x54,
+ 0x45, 0x59, 0x94, 0xc2, 0xd2, 0xe4, 0x5c, 0xcc, 0xe4, 0xc2, 0xce, 0xda,
+ 0xca, 0xdc, 0xe8, 0xbe, 0xd2, 0xdc, 0xe0, 0xea, 0xe8, 0x98, 0x9d, 0x95,
+ 0xb9, 0x95, 0xc9, 0x85, 0xd1, 0x95, 0x91, 0xa1, 0xe0, 0xd0, 0x95, 0xe1,
+ 0x8d, 0xbd, 0xbd, 0xc9, 0x91, 0x11, 0xd9, 0xc9, 0x7c, 0x99, 0xa5, 0xf0,
+ 0x09, 0x4b, 0x93, 0x73, 0x81, 0x2b, 0x93, 0x9b, 0x83, 0x2b, 0x1b, 0xa3,
+ 0x4b, 0xb3, 0x2b, 0xa3, 0x61, 0xc6, 0xf6, 0x16, 0x46, 0x27, 0x43, 0x84,
+ 0xae, 0x0c, 0x6f, 0xec, 0xed, 0x4d, 0x8e, 0x6c, 0x88, 0x04, 0x11, 0x14,
+ 0x46, 0x65, 0xd4, 0x44, 0x69, 0x94, 0x43, 0x6d, 0x54, 0x45, 0x71, 0x54,
+ 0xc2, 0xd2, 0xe4, 0x5c, 0xc4, 0xea, 0xcc, 0xcc, 0xca, 0xe4, 0xf8, 0x84,
+ 0xa5, 0xc9, 0xb9, 0x88, 0xd5, 0x99, 0x99, 0x95, 0xc9, 0x7d, 0xcd, 0xa5,
+ 0xe9, 0x95, 0x51, 0x0a, 0x4b, 0x93, 0x73, 0x61, 0x7b, 0x1b, 0x0b, 0xa3,
+ 0x4b, 0x7b, 0x73, 0xfb, 0x4a, 0x73, 0x23, 0x2b, 0xc3, 0x23, 0x12, 0x96,
+ 0x26, 0xe7, 0x22, 0x57, 0x16, 0x46, 0xc6, 0x28, 0x2c, 0x4d, 0xce, 0x25,
+ 0x4c, 0xee, 0xec, 0x8b, 0x2e, 0x0f, 0xae, 0xec, 0x6b, 0x2e, 0x4d, 0xaf,
+ 0x8c, 0x57, 0x58, 0x9a, 0x9c, 0x4b, 0x98, 0xdc, 0xd9, 0x17, 0x5d, 0x1e,
+ 0x5c, 0xd9, 0x57, 0x18, 0x5b, 0xda, 0x99, 0xdb, 0xd7, 0x5c, 0x9a, 0x5e,
+ 0x19, 0x87, 0xb1, 0x37, 0xb6, 0x21, 0x60, 0x00, 0x21, 0x94, 0x47, 0x7d,
+ 0x50, 0x41, 0x81, 0x01, 0x34, 0x40, 0x04, 0x15, 0x06, 0x94, 0x18, 0x40,
+ 0x05, 0x35, 0x06, 0x50, 0x41, 0x39, 0xd4, 0x43, 0x55, 0x14, 0x19, 0x90,
+ 0x0a, 0x4b, 0x93, 0x73, 0x99, 0xa3, 0x93, 0xab, 0x1b, 0xa3, 0xfb, 0xa2,
+ 0xcb, 0x83, 0x2b, 0xfb, 0x4a, 0x73, 0x33, 0x7b, 0xa3, 0x61, 0xc6, 0xf6,
+ 0x16, 0x46, 0x37, 0x43, 0xe3, 0xcd, 0xcc, 0x6c, 0xae, 0x8c, 0x8e, 0x86,
+ 0xd4, 0xd8, 0x5b, 0x99, 0x99, 0x19, 0x8d, 0xa3, 0xb1, 0xb7, 0x32, 0x33,
+ 0x33, 0x1a, 0x42, 0x63, 0x6f, 0x65, 0x66, 0x66, 0x43, 0xd0, 0x00, 0x1a,
+ 0xa0, 0x02, 0x1a, 0xa8, 0x33, 0xa0, 0xd0, 0x00, 0x2a, 0xa0, 0x02, 0x1a,
+ 0xa8, 0x33, 0xa0, 0xd2, 0x00, 0x52, 0xa0, 0x02, 0x1a, 0xa8, 0x33, 0xa0,
+ 0xd4, 0x00, 0x5a, 0xa0, 0x02, 0x1a, 0xa8, 0x33, 0xa0, 0xd6, 0x80, 0x49,
+ 0x56, 0x95, 0x15, 0x51, 0xd9, 0xd8, 0x1b, 0x59, 0x19, 0x0d, 0xb2, 0xb2,
+ 0xb1, 0x37, 0xb2, 0xb2, 0x21, 0x64, 0x00, 0x25, 0x94, 0x47, 0x7d, 0x90,
+ 0x41, 0x81, 0x01, 0x44, 0x40, 0x04, 0x15, 0x06, 0x94, 0x19, 0x50, 0x6c,
+ 0x40, 0x89, 0x01, 0x64, 0x50, 0x63, 0x00, 0x15, 0x94, 0x43, 0xb5, 0x01,
+ 0x55, 0x51, 0x6e, 0xc0, 0x25, 0x2c, 0x4d, 0xce, 0x85, 0xae, 0x0c, 0x8f,
+ 0xae, 0x4e, 0xae, 0x8c, 0x4a, 0x58, 0x9a, 0x9c, 0xcb, 0x5c, 0x58, 0x1b,
+ 0x1c, 0x5b, 0x19, 0x31, 0xba, 0x32, 0x3c, 0xba, 0x3a, 0xb9, 0x32, 0x19,
+ 0x32, 0x1e, 0x33, 0xb6, 0xb7, 0x30, 0x3a, 0x16, 0x90, 0xb9, 0xb0, 0x36,
+ 0x38, 0xb6, 0x32, 0x1f, 0x12, 0x74, 0x65, 0x78, 0x59, 0x43, 0x28, 0x88,
+ 0xa1, 0xe0, 0x80, 0x02, 0x03, 0x68, 0x80, 0x08, 0x2a, 0x0e, 0x28, 0x87,
+ 0x92, 0x03, 0xaa, 0xa2, 0xe6, 0x80, 0x05, 0x5d, 0x19, 0x5e, 0x95, 0xd5,
+ 0x10, 0x0a, 0x6a, 0x28, 0x38, 0xa0, 0xc0, 0x00, 0x22, 0x20, 0x82, 0x8a,
+ 0x03, 0xca, 0xa1, 0xe4, 0x80, 0xaa, 0xa8, 0x3a, 0xe0, 0x12, 0x96, 0x26,
+ 0xe7, 0x32, 0x17, 0xd6, 0x06, 0xc7, 0x56, 0x26, 0xc7, 0x63, 0x2e, 0xac,
+ 0x0d, 0x8e, 0xad, 0x4c, 0x8e, 0xc1, 0xdc, 0x10, 0x09, 0x72, 0xa8, 0x3b,
+ 0xa0, 0xc0, 0x00, 0x1a, 0x20, 0x82, 0x72, 0x28, 0x3c, 0xa0, 0x2a, 0x2a,
+ 0x0f, 0x86, 0x38, 0xd4, 0x45, 0x75, 0x54, 0x19, 0x50, 0x6f, 0x40, 0xd1,
+ 0x01, 0x65, 0x07, 0x94, 0x1e, 0x0c, 0x31, 0x18, 0x80, 0x8a, 0xa8, 0x3d,
+ 0xe0, 0xf3, 0xd6, 0xe6, 0x96, 0x06, 0xf7, 0x46, 0x57, 0xe6, 0x46, 0x07,
+ 0x32, 0x86, 0x16, 0x26, 0xc7, 0x67, 0x2a, 0xad, 0x0d, 0x8e, 0xad, 0x0c,
+ 0x64, 0x68, 0x65, 0x05, 0x84, 0x4a, 0x28, 0x28, 0x68, 0x88, 0x40, 0xf9,
+ 0xc1, 0x10, 0x83, 0xea, 0x03, 0xea, 0x0f, 0xae, 0x67, 0x88, 0x41, 0x81,
+ 0x02, 0x05, 0x0a, 0xd7, 0x33, 0x42, 0x61, 0x07, 0x76, 0xb0, 0x87, 0x76,
+ 0x70, 0x83, 0x74, 0x20, 0x87, 0x72, 0x70, 0x07, 0x7a, 0x98, 0x12, 0x04,
+ 0x23, 0x96, 0x70, 0x48, 0x07, 0x79, 0x70, 0x03, 0x7b, 0x28, 0x07, 0x79,
+ 0x98, 0x87, 0x74, 0x78, 0x07, 0x77, 0x98, 0x12, 0x08, 0x23, 0xa8, 0x70,
+ 0x48, 0x07, 0x79, 0x70, 0x03, 0x76, 0x08, 0x07, 0x77, 0x38, 0x87, 0x7a,
+ 0x08, 0x87, 0x73, 0x28, 0x87, 0x5f, 0xb0, 0x87, 0x72, 0x90, 0x87, 0x79,
+ 0x48, 0x87, 0x77, 0x70, 0x87, 0x29, 0x01, 0x31, 0x62, 0x0a, 0x87, 0x74,
+ 0x90, 0x07, 0x37, 0x18, 0x87, 0x77, 0x68, 0x07, 0x78, 0x48, 0x07, 0x76,
+ 0x28, 0x87, 0x5f, 0x78, 0x07, 0x78, 0xa0, 0x87, 0x74, 0x78, 0x07, 0x77,
+ 0x98, 0x87, 0x29, 0x84, 0x81, 0x28, 0xcc, 0x08, 0x26, 0x1c, 0xd2, 0x41,
+ 0x1e, 0xdc, 0xc0, 0x1c, 0xe4, 0x21, 0x1c, 0xce, 0xa1, 0x1d, 0xca, 0xc1,
+ 0x1d, 0xe8, 0x61, 0x4a, 0xc0, 0x07, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
+ 0x5c, 0x00, 0x00, 0x00, 0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66,
+ 0x14, 0x01, 0x3d, 0x88, 0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07,
+ 0x79, 0x78, 0x07, 0x73, 0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10,
+ 0x0e, 0xf4, 0x80, 0x0e, 0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce,
+ 0xa1, 0x1c, 0x66, 0x30, 0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b,
+ 0xcc, 0x03, 0x3d, 0xc8, 0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c,
+ 0x74, 0x70, 0x07, 0x7b, 0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07,
+ 0x7a, 0x70, 0x03, 0x76, 0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11,
+ 0x0e, 0xec, 0x90, 0x0e, 0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0,
+ 0x0e, 0xf0, 0x50, 0x0e, 0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8,
+ 0x21, 0x1d, 0xc2, 0x61, 0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b,
+ 0xd0, 0x43, 0x39, 0xb4, 0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b,
+ 0xcc, 0xf0, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87,
+ 0x72, 0x68, 0x07, 0x37, 0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07,
+ 0x76, 0x28, 0x07, 0x76, 0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87,
+ 0x5f, 0x08, 0x87, 0x71, 0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81,
+ 0x2c, 0xee, 0xf0, 0x0e, 0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30,
+ 0x03, 0x62, 0xc8, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4,
+ 0xa1, 0x1c, 0xdc, 0x61, 0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca,
+ 0x61, 0x06, 0xd6, 0x90, 0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39,
+ 0xc8, 0x43, 0x39, 0xb8, 0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b,
+ 0x94, 0xc3, 0x2f, 0xbc, 0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b,
+ 0xb0, 0xc3, 0x0c, 0xc7, 0x69, 0x87, 0x70, 0x58, 0x87, 0x72, 0x70, 0x83,
+ 0x74, 0x68, 0x07, 0x78, 0x60, 0x87, 0x74, 0x18, 0x87, 0x74, 0xa0, 0x87,
+ 0x19, 0xce, 0x53, 0x0f, 0xee, 0x00, 0x0f, 0xf2, 0x50, 0x0e, 0xe4, 0x90,
+ 0x0e, 0xe3, 0x40, 0x0f, 0xe1, 0x20, 0x0e, 0xec, 0x50, 0x0e, 0x33, 0x20,
+ 0x28, 0x1d, 0xdc, 0xc1, 0x1e, 0xc2, 0x41, 0x1e, 0xd2, 0x21, 0x1c, 0xdc,
+ 0x81, 0x1e, 0xdc, 0xe0, 0x1c, 0xe4, 0xe1, 0x1d, 0xea, 0x01, 0x1e, 0x66,
+ 0x18, 0x51, 0x38, 0xb0, 0x43, 0x3a, 0x9c, 0x83, 0x3b, 0xcc, 0x50, 0x24,
+ 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x60, 0x87, 0x77, 0x78, 0x07,
+ 0x78, 0x98, 0x51, 0x4c, 0xf4, 0x90, 0x0f, 0xf0, 0x50, 0x0e, 0x00, 0x00,
+ 0x71, 0x20, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x16, 0xd0, 0x00, 0x48,
+ 0xe4, 0x0f, 0xce, 0xe4, 0x57, 0x77, 0x71, 0xdb, 0x26, 0xb0, 0x01, 0x48,
+ 0xe4, 0x4b, 0x00, 0xf3, 0x2c, 0xc4, 0x3f, 0x11, 0xd7, 0x44, 0x45, 0xc4,
+ 0x6f, 0x0f, 0x7e, 0x85, 0x17, 0xb7, 0x6d, 0x00, 0x11, 0xdb, 0x95, 0xff,
+ 0xf9, 0xda, 0xf5, 0x5f, 0x44, 0x80, 0xc1, 0x10, 0xcd, 0x04, 0x00, 0x00,
+ 0x61, 0x20, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x13, 0x04, 0x41, 0x2c,
+ 0x10, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x64, 0xe7, 0x20, 0x06,
+ 0x02, 0xf1, 0xa8, 0x8e, 0x35, 0x00, 0x03, 0x31, 0xc7, 0x30, 0x10, 0xde,
+ 0x1c, 0xc3, 0xe0, 0x79, 0x63, 0x0d, 0x40, 0x20, 0xd0, 0xab, 0x81, 0x11,
+ 0x00, 0x82, 0x33, 0x00, 0x14, 0x47, 0x00, 0xc6, 0x12, 0x02, 0x80, 0xc8,
+ 0x0c, 0x00, 0x89, 0x19, 0x00, 0x0a, 0x33, 0x00, 0x04, 0xc6, 0x08, 0x40,
+ 0x10, 0x04, 0xf1, 0x6f, 0x04, 0x00, 0x00, 0x00, 0x23, 0x06, 0xca, 0x10,
+ 0x90, 0x81, 0x04, 0x55, 0xca, 0x91, 0x04, 0x23, 0x06, 0xca, 0x10, 0x94,
+ 0x81, 0x14, 0x59, 0x0b, 0xa2, 0x08, 0x83, 0x0c, 0x41, 0x81, 0x0c, 0x32,
+ 0x0c, 0xc6, 0x33, 0xc8, 0x20, 0x20, 0xd1, 0x20, 0x83, 0x10, 0x4c, 0x83,
+ 0x0c, 0xc1, 0x52, 0x9d, 0x36, 0x96, 0x82, 0x62, 0x43, 0x00, 0x1f, 0xf2,
+ 0xca, 0x20, 0x83, 0xe0, 0x58, 0xe3, 0x0d, 0xdf, 0x18, 0xb8, 0xc1, 0x05,
+ 0x63, 0x29, 0x28, 0x83, 0x0c, 0x81, 0xa4, 0x8d, 0x18, 0x14, 0x44, 0x50,
+ 0x07, 0x45, 0x30, 0xc7, 0x40, 0x05, 0x74, 0x30, 0xde, 0x50, 0x06, 0x69,
+ 0x00, 0x07, 0x17, 0x8c, 0xa5, 0xa0, 0x0c, 0x32, 0x04, 0x18, 0x18, 0x8c,
+ 0x18, 0x14, 0x44, 0xb0, 0x07, 0x4b, 0x30, 0xc7, 0x60, 0x04, 0x79, 0x30,
+ 0xde, 0xb0, 0x06, 0x6f, 0x50, 0x07, 0x17, 0x8c, 0xa5, 0xa0, 0x0c, 0x32,
+ 0x04, 0x9e, 0x19, 0x8c, 0x18, 0x14, 0x44, 0x10, 0x0a, 0x51, 0x30, 0xc7,
+ 0x60, 0x04, 0x7b, 0x30, 0xc7, 0x10, 0x80, 0xc1, 0x1e, 0x58, 0x50, 0xc9,
+ 0x27, 0x83, 0x80, 0x18, 0x02, 0x00, 0x00, 0x00, 0x5b, 0x06, 0x25, 0x08,
+ 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00
+};
+const unsigned int sdl_metallib_len = 22744;
diff --git a/src/3rdparty/SDL2/src/render/metal/SDL_shaders_metal_osx.h b/src/3rdparty/SDL2/src/render/metal/SDL_shaders_metal_osx.h
new file mode 100644
index 0000000..787c6fe
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/metal/SDL_shaders_metal_osx.h
@@ -0,0 +1,1903 @@
+const unsigned char sdl_metallib[] = {
+ 0x4d, 0x54, 0x4c, 0x42, 0x01, 0x80, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x08, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0x03, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xa8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x18, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x54, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00,
+ 0x4e, 0x41, 0x4d, 0x45, 0x11, 0x00, 0x53, 0x44, 0x4c, 0x5f, 0x53, 0x6f,
+ 0x6c, 0x69, 0x64, 0x5f, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x00, 0x54,
+ 0x59, 0x50, 0x45, 0x01, 0x00, 0x00, 0x48, 0x41, 0x53, 0x48, 0x20, 0x00,
+ 0xcb, 0x86, 0x8e, 0x78, 0x90, 0x1d, 0xa9, 0xc3, 0xb9, 0xec, 0xcd, 0xec,
+ 0x69, 0xba, 0x3d, 0x7e, 0x97, 0xb5, 0xa9, 0x05, 0x01, 0xbe, 0x87, 0xd8,
+ 0x0c, 0xca, 0x1a, 0xb4, 0x91, 0x54, 0x7e, 0x29, 0x4f, 0x46, 0x46, 0x54,
+ 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x56, 0x45, 0x52, 0x53, 0x08, 0x00, 0x01, 0x00, 0x08, 0x00,
+ 0x01, 0x00, 0x01, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x77, 0x00, 0x00, 0x00,
+ 0x4e, 0x41, 0x4d, 0x45, 0x10, 0x00, 0x53, 0x44, 0x4c, 0x5f, 0x43, 0x6f,
+ 0x70, 0x79, 0x5f, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x00, 0x54, 0x59,
+ 0x50, 0x45, 0x01, 0x00, 0x00, 0x48, 0x41, 0x53, 0x48, 0x20, 0x00, 0xf5,
+ 0xc6, 0xe3, 0x26, 0x71, 0xe3, 0x1c, 0x45, 0x4d, 0xb1, 0xdb, 0x0e, 0x1a,
+ 0x29, 0x85, 0x9d, 0xa7, 0x04, 0x40, 0x91, 0x18, 0x99, 0x5c, 0x9f, 0xdb,
+ 0x7c, 0x30, 0xd1, 0x67, 0x59, 0xd8, 0xa4, 0x4f, 0x46, 0x46, 0x54, 0x18,
+ 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x56, 0x45, 0x52, 0x53, 0x08, 0x00, 0x01, 0x00, 0x08, 0x00, 0x01,
+ 0x00, 0x01, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x7a, 0x00, 0x00, 0x00, 0x4e,
+ 0x41, 0x4d, 0x45, 0x13, 0x00, 0x53, 0x44, 0x4c, 0x5f, 0x53, 0x6f, 0x6c,
+ 0x69, 0x64, 0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x00,
+ 0x54, 0x59, 0x50, 0x45, 0x01, 0x00, 0x01, 0x48, 0x41, 0x53, 0x48, 0x20,
+ 0x00, 0x31, 0xa8, 0x6b, 0xb7, 0x4d, 0x8a, 0x56, 0xc7, 0x91, 0xa4, 0x37,
+ 0xfd, 0xa6, 0xbf, 0x79, 0xd1, 0x55, 0x8c, 0xd5, 0x1b, 0x88, 0x69, 0x8e,
+ 0x6c, 0xf0, 0x53, 0x1b, 0xd3, 0x35, 0xfe, 0x3f, 0x01, 0x4f, 0x46, 0x46,
+ 0x54, 0x18, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x56, 0x45, 0x52, 0x53, 0x08, 0x00, 0x01, 0x00, 0x08,
+ 0x00, 0x01, 0x00, 0x01, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x79, 0x00, 0x00,
+ 0x00, 0x4e, 0x41, 0x4d, 0x45, 0x12, 0x00, 0x53, 0x44, 0x4c, 0x5f, 0x43,
+ 0x6f, 0x70, 0x79, 0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74,
+ 0x00, 0x54, 0x59, 0x50, 0x45, 0x01, 0x00, 0x01, 0x48, 0x41, 0x53, 0x48,
+ 0x20, 0x00, 0x52, 0xe7, 0xfc, 0x67, 0x4e, 0xed, 0x7a, 0xa8, 0x44, 0x82,
+ 0xb2, 0x41, 0x3c, 0xdb, 0x9e, 0xe8, 0x5b, 0xbb, 0x30, 0x60, 0xf8, 0xa1,
+ 0x94, 0xac, 0xb4, 0x80, 0xaa, 0x08, 0xa6, 0xa0, 0xe6, 0xfd, 0x4f, 0x46,
+ 0x46, 0x54, 0x18, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x1f, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x56, 0x45, 0x52, 0x53, 0x08, 0x00, 0x01, 0x00,
+ 0x08, 0x00, 0x01, 0x00, 0x01, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x78, 0x00,
+ 0x00, 0x00, 0x4e, 0x41, 0x4d, 0x45, 0x11, 0x00, 0x53, 0x44, 0x4c, 0x5f,
+ 0x59, 0x55, 0x56, 0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74,
+ 0x00, 0x54, 0x59, 0x50, 0x45, 0x01, 0x00, 0x01, 0x48, 0x41, 0x53, 0x48,
+ 0x20, 0x00, 0x28, 0x59, 0x9d, 0x20, 0x32, 0xc7, 0x94, 0x63, 0xa8, 0xda,
+ 0x9c, 0xac, 0x28, 0xb8, 0x01, 0xc3, 0x5f, 0x48, 0xf6, 0x74, 0x09, 0x1a,
+ 0xd9, 0x84, 0x91, 0x19, 0xc6, 0xe7, 0x4e, 0x94, 0x47, 0xce, 0x4f, 0x46,
+ 0x46, 0x54, 0x18, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x2a, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x56, 0x45, 0x52, 0x53, 0x08, 0x00, 0x01, 0x00,
+ 0x08, 0x00, 0x01, 0x00, 0x01, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x79, 0x00,
+ 0x00, 0x00, 0x4e, 0x41, 0x4d, 0x45, 0x12, 0x00, 0x53, 0x44, 0x4c, 0x5f,
+ 0x4e, 0x56, 0x31, 0x32, 0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e,
+ 0x74, 0x00, 0x54, 0x59, 0x50, 0x45, 0x01, 0x00, 0x01, 0x48, 0x41, 0x53,
+ 0x48, 0x20, 0x00, 0x08, 0x35, 0xd4, 0x21, 0x2f, 0xca, 0x8d, 0x22, 0xb2,
+ 0xa3, 0x9a, 0xd8, 0xd9, 0x46, 0x6d, 0x01, 0x7d, 0x06, 0x95, 0x04, 0x7a,
+ 0x94, 0xdf, 0x2b, 0xd2, 0x21, 0xea, 0x99, 0x9f, 0x2b, 0xda, 0x65, 0x4f,
+ 0x46, 0x46, 0x54, 0x18, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x38, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x45, 0x52, 0x53, 0x08, 0x00, 0x01,
+ 0x00, 0x08, 0x00, 0x01, 0x00, 0x01, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x79,
+ 0x00, 0x00, 0x00, 0x4e, 0x41, 0x4d, 0x45, 0x12, 0x00, 0x53, 0x44, 0x4c,
+ 0x5f, 0x4e, 0x56, 0x32, 0x31, 0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65,
+ 0x6e, 0x74, 0x00, 0x54, 0x59, 0x50, 0x45, 0x01, 0x00, 0x01, 0x48, 0x41,
+ 0x53, 0x48, 0x20, 0x00, 0xe0, 0x53, 0xda, 0x06, 0xef, 0x80, 0x49, 0x61,
+ 0xf6, 0x9e, 0xee, 0xfe, 0x49, 0xb6, 0xd2, 0xce, 0xb8, 0xea, 0x5f, 0x9a,
+ 0xf4, 0x77, 0x35, 0xe7, 0xd3, 0xfc, 0x0f, 0xf6, 0x01, 0xe5, 0x90, 0xd6,
+ 0x4f, 0x46, 0x46, 0x54, 0x18, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x46,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x45, 0x52, 0x53, 0x08, 0x00,
+ 0x01, 0x00, 0x08, 0x00, 0x01, 0x00, 0x01, 0x00, 0x45, 0x4e, 0x44, 0x54,
+ 0x04, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x04, 0x00, 0x00, 0x00,
+ 0x45, 0x4e, 0x44, 0x54, 0x04, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x44, 0x54,
+ 0x04, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x04, 0x00, 0x00, 0x00,
+ 0x45, 0x4e, 0x44, 0x54, 0x04, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x44, 0x54,
+ 0x04, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x04, 0x00, 0x00, 0x00,
+ 0x45, 0x4e, 0x44, 0x54, 0x04, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x44, 0x54,
+ 0x04, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x04, 0x00, 0x00, 0x00,
+ 0x45, 0x4e, 0x44, 0x54, 0x04, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x44, 0x54,
+ 0x04, 0x00, 0x00, 0x00, 0x45, 0x4e, 0x44, 0x54, 0x04, 0x00, 0x00, 0x00,
+ 0x45, 0x4e, 0x44, 0x54, 0xde, 0xc0, 0x17, 0x0b, 0x00, 0x00, 0x00, 0x00,
+ 0x14, 0x00, 0x00, 0x00, 0x38, 0x0b, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+ 0x42, 0x43, 0xc0, 0xde, 0x21, 0x0c, 0x00, 0x00, 0xcb, 0x02, 0x00, 0x00,
+ 0x0b, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00,
+ 0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39,
+ 0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19, 0x1e, 0x04, 0x8b, 0x62,
+ 0x80, 0x14, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42, 0xa4, 0x10, 0x32, 0x14,
+ 0x38, 0x08, 0x18, 0x49, 0x0a, 0x32, 0x44, 0x24, 0x48, 0x0a, 0x90, 0x21,
+ 0x23, 0xc4, 0x52, 0x80, 0x0c, 0x19, 0x21, 0x72, 0x24, 0x07, 0xc8, 0x48,
+ 0x11, 0x62, 0xa8, 0xa0, 0xa8, 0x40, 0xc6, 0xf0, 0x01, 0x00, 0x00, 0x00,
+ 0x51, 0x18, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x1b, 0x8c, 0x20, 0x00,
+ 0x16, 0xa0, 0xda, 0x60, 0x08, 0x02, 0xb0, 0x00, 0xd5, 0x06, 0x63, 0x18,
+ 0x80, 0x05, 0xa8, 0x36, 0x90, 0x0b, 0xf1, 0xff, 0xff, 0xff, 0xff, 0x03,
+ 0x20, 0x01, 0x15, 0x31, 0x0e, 0xef, 0x20, 0x0f, 0xf2, 0x50, 0x0e, 0xe3,
+ 0x40, 0x0f, 0xec, 0x90, 0x0f, 0x6d, 0x20, 0x0f, 0xef, 0x50, 0x0f, 0xee,
+ 0x40, 0x0e, 0xe5, 0x40, 0x0e, 0x6d, 0x40, 0x0e, 0xe9, 0x60, 0x0f, 0xe9,
+ 0x40, 0x0e, 0xe5, 0xd0, 0x06, 0xf3, 0x10, 0x0f, 0xf2, 0x40, 0x0f, 0x6d,
+ 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x80,
+ 0x39, 0x84, 0x03, 0x3b, 0xcc, 0x43, 0x39, 0x00, 0x04, 0x39, 0xa4, 0xc3,
+ 0x3c, 0x84, 0x83, 0x38, 0xb0, 0x43, 0x39, 0xb4, 0x01, 0x3d, 0x84, 0x43,
+ 0x3a, 0xb0, 0x43, 0x1b, 0x8c, 0x43, 0x38, 0xb0, 0x03, 0x3b, 0xcc, 0x03,
+ 0x60, 0x0e, 0xe1, 0xc0, 0x0e, 0xf3, 0x50, 0x0e, 0x00, 0xc1, 0x0e, 0xe5,
+ 0x30, 0x0f, 0xf3, 0xd0, 0x06, 0xf0, 0x20, 0x0f, 0xe5, 0x30, 0x0e, 0xe9,
+ 0x30, 0x0f, 0xe5, 0xd0, 0x06, 0xe6, 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xe4,
+ 0x00, 0xd0, 0x83, 0x3c, 0xd4, 0x43, 0x39, 0x00, 0x84, 0x3b, 0xbc, 0x43,
+ 0x1b, 0x98, 0x83, 0x3c, 0x84, 0x43, 0x3b, 0x94, 0x43, 0x1b, 0xc0, 0xc3,
+ 0x3b, 0xa4, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xc8, 0x43, 0x1b, 0x94, 0x03,
+ 0x3b, 0xa4, 0x43, 0x3b, 0x00, 0xf4, 0x20, 0x0f, 0xf5, 0x50, 0x0e, 0xc0,
+ 0xe0, 0x0e, 0xef, 0xd0, 0x06, 0xe6, 0x20, 0x0f, 0xe1, 0xd0, 0x0e, 0xe5,
+ 0xd0, 0x06, 0xf0, 0xf0, 0x0e, 0xe9, 0xe0, 0x0e, 0xf4, 0x50, 0x0e, 0xf2,
+ 0xd0, 0x06, 0xe5, 0xc0, 0x0e, 0xe9, 0xd0, 0x0e, 0x6d, 0xe0, 0x0e, 0xef,
+ 0xe0, 0x0e, 0x6d, 0xc0, 0x0e, 0xe5, 0x10, 0x0e, 0xe6, 0x00, 0x10, 0xee,
+ 0xf0, 0x0e, 0x6d, 0x90, 0x0e, 0xee, 0x60, 0x0e, 0xf3, 0xd0, 0x06, 0xe6,
+ 0x00, 0x0f, 0x6d, 0xd0, 0x0e, 0xe1, 0x40, 0x0f, 0xe8, 0x00, 0xd0, 0x83,
+ 0x3c, 0xd4, 0x43, 0x39, 0x00, 0x84, 0x3b, 0xbc, 0x43, 0x1b, 0xa8, 0x43,
+ 0x3d, 0xb4, 0x03, 0x3c, 0xb4, 0x01, 0x3d, 0x84, 0x83, 0x38, 0xb0, 0x43,
+ 0x39, 0xcc, 0x03, 0x60, 0x0e, 0xe1, 0xc0, 0x0e, 0xf3, 0x50, 0x0e, 0x00,
+ 0xe1, 0x0e, 0xef, 0xd0, 0x06, 0xee, 0x10, 0x0e, 0xee, 0x30, 0x0f, 0x6d,
+ 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x00,
+ 0x3d, 0xc8, 0x43, 0x3d, 0x94, 0x03, 0x40, 0xb8, 0xc3, 0x3b, 0xb4, 0xc1,
+ 0x3c, 0xa4, 0xc3, 0x39, 0xb8, 0x43, 0x39, 0x90, 0x43, 0x1b, 0xe8, 0x43,
+ 0x39, 0xc8, 0xc3, 0x3b, 0xcc, 0x43, 0x1b, 0x98, 0x03, 0x3c, 0xb4, 0x41,
+ 0x3b, 0x84, 0x03, 0x3d, 0xa0, 0x03, 0x60, 0x0e, 0xe1, 0xc0, 0x0e, 0xf3,
+ 0x50, 0x0e, 0x00, 0x31, 0x0f, 0xf4, 0x10, 0x0e, 0xe3, 0xb0, 0x0e, 0x6d,
+ 0x00, 0x0f, 0xf2, 0xf0, 0x0e, 0xf4, 0x50, 0x0e, 0xe3, 0x40, 0x0f, 0xef,
+ 0x20, 0x0f, 0x6d, 0x20, 0x0e, 0xf5, 0x60, 0x0e, 0xe6, 0x50, 0x0e, 0xf2,
+ 0xd0, 0x06, 0xf3, 0x90, 0x0e, 0xfa, 0x50, 0x0e, 0x00, 0x1e, 0x00, 0x04,
+ 0x3d, 0x84, 0x83, 0x3c, 0x9c, 0x43, 0x39, 0xd0, 0x43, 0x1b, 0x98, 0x43,
+ 0x39, 0x84, 0x03, 0x3d, 0xd4, 0x83, 0x3c, 0x94, 0xc3, 0x3c, 0x00, 0x6d,
+ 0x60, 0x0e, 0xf0, 0x10, 0x07, 0x76, 0x00, 0x10, 0xf5, 0xe0, 0x0e, 0xf3,
+ 0x10, 0x0e, 0xe6, 0x50, 0x0e, 0x6d, 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed,
+ 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x00, 0x3d, 0xc8, 0x43, 0x3d, 0x94, 0x03,
+ 0x40, 0xd4, 0xc3, 0x3c, 0x94, 0x43, 0x1b, 0xcc, 0xc3, 0x3b, 0x98, 0x03,
+ 0x3d, 0xb4, 0x81, 0x39, 0xb0, 0xc3, 0x3b, 0x84, 0x03, 0x3d, 0x00, 0xe6,
+ 0x10, 0x0e, 0xec, 0x30, 0x0f, 0xe5, 0x00, 0x00, 0x49, 0x18, 0x00, 0x00,
+ 0x02, 0x00, 0x00, 0x00, 0x13, 0x88, 0x40, 0x18, 0x08, 0x00, 0x00, 0x00,
+ 0x89, 0x20, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09,
+ 0x20, 0x64, 0x85, 0x04, 0x93, 0x22, 0xa4, 0x84, 0x04, 0x93, 0x22, 0xe3,
+ 0x84, 0xa1, 0x90, 0x14, 0x12, 0x4c, 0x8a, 0x8c, 0x0b, 0x84, 0xa4, 0x4c,
+ 0x10, 0x50, 0x33, 0x00, 0xc3, 0x08, 0x04, 0x70, 0x9f, 0x34, 0x45, 0x94,
+ 0x30, 0xf9, 0xac, 0xb3, 0x20, 0xc3, 0x4b, 0x44, 0x13, 0x71, 0xa1, 0xd4,
+ 0xf4, 0x50, 0x93, 0xff, 0x00, 0x82, 0x42, 0x0c, 0x58, 0x08, 0x60, 0x18,
+ 0x41, 0x00, 0x06, 0x11, 0x86, 0x20, 0x09, 0xc2, 0x4c, 0xd3, 0x38, 0xb0,
+ 0x43, 0x38, 0xcc, 0xc3, 0x3c, 0xb8, 0x41, 0x3b, 0x94, 0x03, 0x3d, 0x84,
+ 0x03, 0x3b, 0xe8, 0x81, 0x1e, 0xb4, 0x43, 0x38, 0xd0, 0x83, 0x3c, 0xa4,
+ 0x03, 0x3e, 0xa0, 0xa0, 0x0c, 0x22, 0x18, 0xc2, 0x1c, 0x01, 0x18, 0x94,
+ 0x42, 0x90, 0x73, 0x10, 0xa5, 0x81, 0x00, 0x32, 0x73, 0x04, 0xa0, 0x30,
+ 0x88, 0x10, 0x08, 0x53, 0x00, 0x23, 0x00, 0xc3, 0x08, 0x04, 0x32, 0x47,
+ 0x10, 0x50, 0x00, 0x00, 0x13, 0xb2, 0x70, 0x48, 0x07, 0x79, 0xb0, 0x03,
+ 0x3a, 0x68, 0x83, 0x70, 0x80, 0x07, 0x78, 0x60, 0x87, 0x72, 0x68, 0x83,
+ 0x76, 0x08, 0x87, 0x71, 0x78, 0x87, 0x79, 0xc0, 0x87, 0x38, 0x80, 0x03,
+ 0x37, 0x88, 0x83, 0x38, 0x70, 0x03, 0x38, 0xd8, 0xf0, 0x1e, 0xe5, 0xd0,
+ 0x06, 0xf0, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0,
+ 0x07, 0x76, 0x40, 0x07, 0x6d, 0x90, 0x0e, 0x71, 0xa0, 0x07, 0x78, 0xa0,
+ 0x07, 0x78, 0xd0, 0x06, 0xe9, 0x80, 0x07, 0x7a, 0x80, 0x07, 0x7a, 0x80,
+ 0x07, 0x6d, 0x90, 0x0e, 0x71, 0x60, 0x07, 0x7a, 0x10, 0x07, 0x76, 0xa0,
+ 0x07, 0x71, 0x60, 0x07, 0x6d, 0x90, 0x0e, 0x73, 0x20, 0x07, 0x7a, 0x30,
+ 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x76, 0x40,
+ 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x60,
+ 0x0e, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20,
+ 0x07, 0x6d, 0x60, 0x0e, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0,
+ 0x07, 0x76, 0x40, 0x07, 0x6d, 0x60, 0x0e, 0x78, 0x00, 0x07, 0x7a, 0x10,
+ 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d, 0x60,
+ 0x0f, 0x71, 0x60, 0x07, 0x7a, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x60,
+ 0x07, 0x6d, 0x60, 0x0f, 0x72, 0x40, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0,
+ 0x07, 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0f, 0x73, 0x20, 0x07, 0x7a, 0x30,
+ 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0f, 0x74, 0x80,
+ 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x60,
+ 0x0f, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40,
+ 0x07, 0x6d, 0x60, 0x0f, 0x79, 0x60, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80,
+ 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x20,
+ 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20,
+ 0x07, 0x78, 0xd0, 0x06, 0xf6, 0x10, 0x07, 0x79, 0x20, 0x07, 0x7a, 0x20,
+ 0x07, 0x75, 0x60, 0x07, 0x7a, 0x20, 0x07, 0x75, 0x60, 0x07, 0x6d, 0x60,
+ 0x0f, 0x72, 0x50, 0x07, 0x76, 0xa0, 0x07, 0x72, 0x50, 0x07, 0x76, 0xa0,
+ 0x07, 0x72, 0x50, 0x07, 0x76, 0xd0, 0x06, 0xf6, 0x50, 0x07, 0x71, 0x20,
+ 0x07, 0x7a, 0x50, 0x07, 0x71, 0x20, 0x07, 0x7a, 0x50, 0x07, 0x71, 0x20,
+ 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x00, 0x07, 0x72, 0x40, 0x07, 0x7a, 0x10,
+ 0x07, 0x70, 0x20, 0x07, 0x74, 0xa0, 0x07, 0x71, 0x00, 0x07, 0x72, 0x40,
+ 0x07, 0x6d, 0x60, 0x0e, 0x78, 0x00, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80,
+ 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d, 0xe0, 0x0e, 0x78, 0xa0,
+ 0x07, 0x71, 0x60, 0x07, 0x7a, 0x30, 0x07, 0x72, 0x30, 0x84, 0x51, 0x00,
+ 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x02, 0x01, 0x00, 0x00,
+ 0x08, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x10, 0x19, 0x11, 0x4c, 0x90,
+ 0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0x42, 0x25, 0x30, 0x02, 0x50,
+ 0x80, 0x01, 0x05, 0x51, 0x04, 0x05, 0x52, 0x06, 0xd4, 0x46, 0x00, 0x00,
+ 0x79, 0x18, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x1a, 0x03, 0x4c, 0x10,
+ 0xd7, 0x20, 0x08, 0x0e, 0x8e, 0xad, 0x0c, 0x84, 0x89, 0xc9, 0xaa, 0x09,
+ 0xc4, 0xae, 0x4c, 0x6e, 0x2e, 0xed, 0xcd, 0x0d, 0x04, 0x07, 0x46, 0xc6,
+ 0x25, 0x06, 0x04, 0xa5, 0xad, 0x8c, 0x2e, 0x8c, 0xcd, 0xac, 0xac, 0x05,
+ 0x07, 0x46, 0xc6, 0x25, 0xc6, 0x65, 0x86, 0x26, 0x65, 0x88, 0xb0, 0x00,
+ 0x43, 0x0c, 0x24, 0x40, 0x08, 0x44, 0x60, 0xd1, 0x54, 0x46, 0x17, 0xc6,
+ 0x36, 0x04, 0x59, 0x06, 0x24, 0x40, 0x02, 0x44, 0xe0, 0x16, 0x96, 0x26,
+ 0xe7, 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56, 0xe6, 0x42, 0x56, 0xe6,
+ 0xf6, 0x26, 0xd7, 0x36, 0xf7, 0x45, 0x96, 0x36, 0x17, 0x26, 0xc6, 0x56,
+ 0x36, 0x44, 0x58, 0x0a, 0x72, 0x61, 0x69, 0x72, 0x2e, 0x63, 0x6f, 0x6d,
+ 0x70, 0x69, 0x6c, 0x65, 0x2e, 0x66, 0x61, 0x73, 0x74, 0x5f, 0x6d, 0x61,
+ 0x74, 0x68, 0x5f, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x43, 0x84, 0xe5,
+ 0x60, 0x19, 0x84, 0xa5, 0xc9, 0xb9, 0x8c, 0xbd, 0xb5, 0xc1, 0xa5, 0xb1,
+ 0x95, 0xb9, 0x98, 0xc9, 0x85, 0xb5, 0x95, 0x89, 0xd5, 0x99, 0x99, 0x95,
+ 0xc9, 0x7d, 0x99, 0x95, 0xd1, 0x8d, 0xa1, 0x7d, 0x91, 0xa5, 0xcd, 0x85,
+ 0x89, 0xb1, 0x95, 0x0d, 0x11, 0x96, 0x84, 0x61, 0x10, 0x96, 0x26, 0xe7,
+ 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56, 0xe6, 0xe2, 0x16, 0x46, 0x97,
+ 0x66, 0x57, 0xf6, 0x45, 0xf6, 0x56, 0x27, 0xc6, 0x56, 0xf6, 0x45, 0x96,
+ 0x36, 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0x58, 0x16, 0x32, 0x61, 0x69,
+ 0x72, 0x2e, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x8c, 0xc2,
+ 0xd2, 0xe4, 0x5c, 0xc2, 0xe4, 0xce, 0xbe, 0xe8, 0xf2, 0xe0, 0xca, 0xbe,
+ 0xdc, 0xc2, 0xda, 0xca, 0x68, 0x98, 0xb1, 0xbd, 0x85, 0xd1, 0xd1, 0x90,
+ 0x09, 0x4b, 0x93, 0x73, 0x09, 0x93, 0x3b, 0xfb, 0x72, 0x0b, 0x6b, 0x2b,
+ 0x23, 0x02, 0xf7, 0x36, 0x97, 0x46, 0x97, 0xf6, 0xe6, 0x36, 0x44, 0x59,
+ 0x9a, 0xc5, 0x59, 0x9e, 0x05, 0x5a, 0x22, 0x3a, 0x61, 0x69, 0x72, 0x2e,
+ 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x2c, 0xcc,
+ 0xd8, 0xde, 0xc2, 0xe8, 0x98, 0xc0, 0xbd, 0xa5, 0xb9, 0xd1, 0x4d, 0xa5,
+ 0xe9, 0x95, 0x0d, 0x51, 0x96, 0x69, 0x71, 0x16, 0x6a, 0x81, 0x96, 0x6a,
+ 0x08, 0xb1, 0x48, 0x8b, 0x45, 0x25, 0x2c, 0x4d, 0xce, 0x45, 0xac, 0xce,
+ 0xcc, 0xac, 0x4c, 0x8e, 0x52, 0x58, 0x9a, 0x9c, 0x0b, 0xdb, 0xdb, 0x58,
+ 0x18, 0x5d, 0xda, 0x9b, 0xdb, 0x57, 0x9a, 0x1b, 0x59, 0x19, 0x1e, 0x91,
+ 0xb0, 0x34, 0x39, 0x17, 0xb9, 0xb2, 0x30, 0x32, 0x46, 0x61, 0x69, 0x72,
+ 0x2e, 0x61, 0x72, 0x67, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x5f, 0x73, 0x69,
+ 0x7a, 0x65, 0xbc, 0xc2, 0xd2, 0xe4, 0x5c, 0xc2, 0xe4, 0xce, 0xbe, 0xe8,
+ 0xf2, 0xe0, 0xca, 0xbe, 0xc2, 0xd8, 0xd2, 0xce, 0xdc, 0xbe, 0xe6, 0xd2,
+ 0xf4, 0xca, 0x68, 0x98, 0xb1, 0xbd, 0x85, 0xd1, 0xc9, 0x0c, 0xe1, 0x10,
+ 0x61, 0xc1, 0x96, 0x0c, 0x11, 0x90, 0x60, 0xd1, 0x96, 0x0d, 0x21, 0x16,
+ 0x0e, 0x21, 0x16, 0x67, 0xe9, 0x16, 0x68, 0x89, 0xf8, 0x84, 0xa5, 0xc9,
+ 0xb9, 0x88, 0xd5, 0x99, 0x99, 0x95, 0xc9, 0x7d, 0xcd, 0xa5, 0xe9, 0x95,
+ 0x11, 0x31, 0x63, 0x7b, 0x0b, 0xa3, 0xa3, 0xc1, 0xa3, 0xa1, 0x02, 0x27,
+ 0xf7, 0xa6, 0x56, 0x36, 0x46, 0x97, 0xf6, 0xe6, 0x36, 0x04, 0x0c, 0x90,
+ 0x60, 0xc1, 0x96, 0x0f, 0x19, 0x96, 0x0c, 0x29, 0x90, 0x60, 0xd1, 0x96,
+ 0x0d, 0x19, 0x16, 0x0e, 0x31, 0x16, 0x67, 0x01, 0x83, 0x05, 0x5a, 0xc2,
+ 0x80, 0x09, 0x9d, 0x5c, 0x98, 0xdb, 0x9c, 0xd9, 0x9b, 0x5c, 0xdb, 0x10,
+ 0x30, 0x40, 0x8a, 0x05, 0x5b, 0x3e, 0x64, 0x58, 0x32, 0xe4, 0x40, 0x82,
+ 0x45, 0x5b, 0x36, 0x64, 0x58, 0x38, 0xc4, 0x58, 0x9c, 0x05, 0x0c, 0x16,
+ 0x68, 0x19, 0x03, 0x36, 0x61, 0x69, 0x72, 0x2e, 0x76, 0x65, 0x72, 0x74,
+ 0x65, 0x78, 0x5f, 0x69, 0x64, 0x24, 0xea, 0xd2, 0xdc, 0xe8, 0x38, 0xd8,
+ 0xa5, 0x91, 0x0d, 0x61, 0x90, 0x63, 0x29, 0x83, 0xc5, 0x59, 0xcc, 0x60,
+ 0x81, 0x96, 0x33, 0x18, 0x82, 0x2c, 0xde, 0x22, 0x06, 0x0b, 0x19, 0x2c,
+ 0x68, 0x30, 0xc4, 0x50, 0x80, 0xe5, 0x5a, 0xd2, 0x80, 0xcf, 0x5b, 0x9b,
+ 0x5b, 0x1a, 0xdc, 0x1b, 0x5d, 0x99, 0x1b, 0x1d, 0xc8, 0x18, 0x5a, 0x98,
+ 0x1c, 0x9f, 0xa9, 0xb4, 0x36, 0x38, 0xb6, 0x32, 0x90, 0xa1, 0x95, 0x15,
+ 0x10, 0x2a, 0xa1, 0xa0, 0xa0, 0x21, 0xc2, 0xc2, 0x06, 0x43, 0x8c, 0x65,
+ 0x0d, 0x96, 0x36, 0x68, 0x90, 0x21, 0xc6, 0xe2, 0x06, 0x8b, 0x1b, 0x34,
+ 0xc8, 0x08, 0x85, 0x1d, 0xd8, 0xc1, 0x1e, 0xda, 0xc1, 0x0d, 0xd2, 0x81,
+ 0x1c, 0xca, 0xc1, 0x1d, 0xe8, 0x61, 0x4a, 0x10, 0x8c, 0x58, 0xc2, 0x21,
+ 0x1d, 0xe4, 0xc1, 0x0d, 0xec, 0xa1, 0x1c, 0xe4, 0x61, 0x1e, 0xd2, 0xe1,
+ 0x1d, 0xdc, 0x61, 0x4a, 0x20, 0x8c, 0xa0, 0xc2, 0x21, 0x1d, 0xe4, 0xc1,
+ 0x0d, 0xd8, 0x21, 0x1c, 0xdc, 0xe1, 0x1c, 0xea, 0x21, 0x1c, 0xce, 0xa1,
+ 0x1c, 0x7e, 0xc1, 0x1e, 0xca, 0x41, 0x1e, 0xe6, 0x21, 0x1d, 0xde, 0xc1,
+ 0x1d, 0xa6, 0x04, 0xc4, 0x88, 0x29, 0x1c, 0xd2, 0x41, 0x1e, 0xdc, 0x60,
+ 0x1c, 0xde, 0xa1, 0x1d, 0xe0, 0x21, 0x1d, 0xd8, 0xa1, 0x1c, 0x7e, 0xe1,
+ 0x1d, 0xe0, 0x81, 0x1e, 0xd2, 0xe1, 0x1d, 0xdc, 0x61, 0x1e, 0xa6, 0x10,
+ 0x06, 0xa2, 0x30, 0x23, 0x94, 0x70, 0x48, 0x07, 0x79, 0x70, 0x03, 0x7b,
+ 0x28, 0x07, 0x79, 0xa0, 0x87, 0x72, 0xc0, 0x87, 0x29, 0x81, 0x1a, 0x00,
+ 0x79, 0x18, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x33, 0x08, 0x80, 0x1c,
+ 0xc4, 0xe1, 0x1c, 0x66, 0x14, 0x01, 0x3d, 0x88, 0x43, 0x38, 0x84, 0xc3,
+ 0x8c, 0x42, 0x80, 0x07, 0x79, 0x78, 0x07, 0x73, 0x98, 0x71, 0x0c, 0xe6,
+ 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x33, 0x0c, 0x42, 0x1e,
+ 0xc2, 0xc1, 0x1d, 0xce, 0xa1, 0x1c, 0x66, 0x30, 0x05, 0x3d, 0x88, 0x43,
+ 0x38, 0x84, 0x83, 0x1b, 0xcc, 0x03, 0x3d, 0xc8, 0x43, 0x3d, 0x8c, 0x03,
+ 0x3d, 0xcc, 0x78, 0x8c, 0x74, 0x70, 0x07, 0x7b, 0x08, 0x07, 0x79, 0x48,
+ 0x87, 0x70, 0x70, 0x07, 0x7a, 0x70, 0x03, 0x76, 0x78, 0x87, 0x70, 0x20,
+ 0x87, 0x19, 0xcc, 0x11, 0x0e, 0xec, 0x90, 0x0e, 0xe1, 0x30, 0x0f, 0x6e,
+ 0x30, 0x0f, 0xe3, 0xf0, 0x0e, 0xf0, 0x50, 0x0e, 0x33, 0x10, 0xc4, 0x1d,
+ 0xde, 0x21, 0x1c, 0xd8, 0x21, 0x1d, 0xc2, 0x61, 0x1e, 0x66, 0x30, 0x89,
+ 0x3b, 0xbc, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xb4, 0x03, 0x3c, 0xbc, 0x83,
+ 0x3c, 0x84, 0x03, 0x3b, 0xcc, 0xf0, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68,
+ 0x07, 0x37, 0x68, 0x87, 0x72, 0x68, 0x07, 0x37, 0x80, 0x87, 0x70, 0x90,
+ 0x87, 0x70, 0x60, 0x07, 0x76, 0x28, 0x07, 0x76, 0xf8, 0x05, 0x76, 0x78,
+ 0x87, 0x77, 0x80, 0x87, 0x5f, 0x08, 0x87, 0x71, 0x18, 0x87, 0x72, 0x98,
+ 0x87, 0x79, 0x98, 0x81, 0x2c, 0xee, 0xf0, 0x0e, 0xee, 0xe0, 0x0e, 0xf5,
+ 0xc0, 0x0e, 0xec, 0x30, 0x03, 0x62, 0xc8, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c,
+ 0xcc, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xdc, 0x61, 0x1c, 0xca, 0x21, 0x1c,
+ 0xc4, 0x81, 0x1d, 0xca, 0x61, 0x06, 0xd6, 0x90, 0x43, 0x39, 0xc8, 0x43,
+ 0x39, 0x98, 0x43, 0x39, 0xc8, 0x43, 0x39, 0xb8, 0xc3, 0x38, 0x94, 0x43,
+ 0x38, 0x88, 0x03, 0x3b, 0x94, 0xc3, 0x2f, 0xbc, 0x83, 0x3c, 0xfc, 0x82,
+ 0x3b, 0xd4, 0x03, 0x3b, 0xb0, 0xc3, 0x0c, 0xc7, 0x69, 0x87, 0x70, 0x58,
+ 0x87, 0x72, 0x70, 0x83, 0x74, 0x68, 0x07, 0x78, 0x60, 0x87, 0x74, 0x18,
+ 0x87, 0x74, 0xa0, 0x87, 0x19, 0xce, 0x53, 0x0f, 0xee, 0x00, 0x0f, 0xf2,
+ 0x50, 0x0e, 0xe4, 0x90, 0x0e, 0xe3, 0x40, 0x0f, 0xe1, 0x20, 0x0e, 0xec,
+ 0x50, 0x0e, 0x33, 0x20, 0x28, 0x1d, 0xdc, 0xc1, 0x1e, 0xc2, 0x41, 0x1e,
+ 0xd2, 0x21, 0x1c, 0xdc, 0x81, 0x1e, 0xdc, 0xe0, 0x1c, 0xe4, 0xe1, 0x1d,
+ 0xea, 0x01, 0x1e, 0x66, 0x18, 0x51, 0x38, 0xb0, 0x43, 0x3a, 0x9c, 0x83,
+ 0x3b, 0xcc, 0x50, 0x24, 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x60,
+ 0x87, 0x77, 0x78, 0x07, 0x78, 0x98, 0x51, 0x4c, 0xf4, 0x90, 0x0f, 0xf0,
+ 0x50, 0x0e, 0x00, 0x00, 0x71, 0x20, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
+ 0x06, 0x00, 0xb1, 0x5d, 0xf9, 0xb3, 0xce, 0x82, 0x0c, 0x7f, 0x45, 0x44,
+ 0x13, 0x71, 0x01, 0x00, 0x61, 0x20, 0x00, 0x00, 0x69, 0x00, 0x00, 0x00,
+ 0x13, 0x04, 0x47, 0x2c, 0x10, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
+ 0x14, 0x47, 0x00, 0xa8, 0x95, 0x41, 0x11, 0x94, 0x00, 0xa1, 0x42, 0x20,
+ 0x31, 0x03, 0x40, 0x61, 0x06, 0x80, 0xc0, 0x08, 0xc0, 0x18, 0x01, 0x08,
+ 0x82, 0x20, 0xfe, 0x01, 0x33, 0x11, 0x0c, 0x12, 0x14, 0x33, 0x11, 0x0c,
+ 0x12, 0x14, 0xe3, 0x11, 0x0e, 0x64, 0x41, 0x14, 0x94, 0x59, 0x82, 0x60,
+ 0xa0, 0x02, 0x81, 0x03, 0xe0, 0x0c, 0x86, 0x0b, 0x9a, 0x8c, 0x47, 0x44,
+ 0x94, 0x16, 0x50, 0x50, 0x06, 0x19, 0x82, 0x25, 0xb2, 0xc0, 0x90, 0xcf,
+ 0x2c, 0x81, 0x30, 0x50, 0x81, 0xf8, 0x41, 0x50, 0x09, 0x03, 0x15, 0x01,
+ 0x11, 0x44, 0xc2, 0x18, 0x42, 0x21, 0xcc, 0x31, 0x40, 0x41, 0x18, 0x0c,
+ 0x32, 0x04, 0xd1, 0x75, 0x45, 0x93, 0xf1, 0x08, 0xce, 0x23, 0x83, 0x80,
+ 0x82, 0x62, 0x01, 0x21, 0x1f, 0x0b, 0x10, 0xf8, 0x98, 0x92, 0x06, 0x30,
+ 0x18, 0x6e, 0x08, 0x34, 0x30, 0x98, 0x65, 0x18, 0x84, 0x60, 0x3c, 0xc2,
+ 0x22, 0x03, 0x35, 0x88, 0x06, 0x23, 0x02, 0xa2, 0x00, 0x6c, 0x62, 0x03,
+ 0x18, 0x0c, 0x37, 0x04, 0x1d, 0x18, 0xcc, 0x32, 0x10, 0x41, 0x30, 0x1e,
+ 0x91, 0x9d, 0x41, 0x1b, 0x9c, 0x01, 0x05, 0x65, 0x3c, 0x62, 0x4b, 0x83,
+ 0x37, 0x08, 0x03, 0x0a, 0xca, 0x78, 0x44, 0xb7, 0x06, 0x71, 0x40, 0x06,
+ 0x14, 0x94, 0xf1, 0x88, 0xaf, 0x0d, 0xe6, 0xe0, 0x0c, 0x28, 0x28, 0xe3,
+ 0x11, 0x60, 0xf0, 0x06, 0x75, 0xf0, 0x06, 0x83, 0x11, 0x01, 0x52, 0x00,
+ 0xe3, 0x11, 0x61, 0x00, 0x07, 0x76, 0x80, 0x06, 0x83, 0x11, 0xc1, 0x51,
+ 0x00, 0xe3, 0x11, 0x62, 0x10, 0x07, 0x77, 0xa0, 0x06, 0x83, 0x11, 0x81,
+ 0x51, 0x00, 0xe3, 0x11, 0x63, 0x20, 0x07, 0x78, 0xc0, 0x06, 0x83, 0x11,
+ 0x41, 0x51, 0x00, 0xf7, 0x06, 0x2d, 0xc6, 0x13, 0xe6, 0x20, 0xa0, 0x80,
+ 0x8c, 0x21, 0x04, 0x7c, 0x30, 0xc7, 0xc0, 0x06, 0x41, 0x1f, 0x8c, 0x21,
+ 0x0c, 0x7f, 0x30, 0xc7, 0x20, 0x04, 0xa0, 0x30, 0xc7, 0x10, 0xb8, 0x41,
+ 0x1f, 0xcc, 0x31, 0x04, 0x6e, 0xc0, 0x07, 0x83, 0x0c, 0x41, 0x1c, 0xdc,
+ 0x81, 0x05, 0x95, 0x7c, 0x66, 0x09, 0x8a, 0x81, 0x0a, 0x44, 0x25, 0x88,
+ 0xaa, 0x18, 0xa8, 0x08, 0x08, 0x22, 0x2a, 0xc6, 0x10, 0x0a, 0x61, 0x8e,
+ 0xc1, 0x0e, 0x82, 0x53, 0x18, 0x64, 0x08, 0xee, 0xa0, 0x0f, 0xae, 0x68,
+ 0x32, 0x1e, 0x51, 0x07, 0xa4, 0xa0, 0x0a, 0x01, 0x05, 0xc5, 0x02, 0x42,
+ 0x3e, 0x16, 0x20, 0xf0, 0x31, 0xe5, 0x15, 0x60, 0x30, 0xdc, 0x10, 0x80,
+ 0x02, 0x18, 0xcc, 0x32, 0x18, 0x45, 0x30, 0xdb, 0x00, 0x0a, 0x03, 0x30,
+ 0xdb, 0x10, 0xf8, 0x41, 0x90, 0x41, 0x40, 0x0c, 0x08, 0x00, 0x00, 0x00,
+ 0x5b, 0x86, 0x21, 0x78, 0x83, 0x2d, 0x03, 0x12, 0xbc, 0xc1, 0x96, 0x61,
+ 0x0a, 0xde, 0x60, 0xcb, 0xa0, 0x05, 0x6f, 0xb0, 0x65, 0x80, 0x83, 0xe0,
+ 0x0d, 0xb6, 0x0c, 0xa1, 0x10, 0xbc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xde, 0xc0, 0x17, 0x0b,
+ 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x90, 0x0b, 0x00, 0x00,
+ 0xff, 0xff, 0xff, 0xff, 0x42, 0x43, 0xc0, 0xde, 0x21, 0x0c, 0x00, 0x00,
+ 0xe1, 0x02, 0x00, 0x00, 0x0b, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x12, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49,
+ 0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19,
+ 0x1e, 0x04, 0x8b, 0x62, 0x80, 0x14, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42,
+ 0xa4, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x49, 0x0a, 0x32, 0x44, 0x24,
+ 0x48, 0x0a, 0x90, 0x21, 0x23, 0xc4, 0x52, 0x80, 0x0c, 0x19, 0x21, 0x72,
+ 0x24, 0x07, 0xc8, 0x48, 0x11, 0x62, 0xa8, 0xa0, 0xa8, 0x40, 0xc6, 0xf0,
+ 0x01, 0x00, 0x00, 0x00, 0x51, 0x18, 0x00, 0x00, 0x86, 0x00, 0x00, 0x00,
+ 0x1b, 0x8c, 0x20, 0x00, 0x16, 0xa0, 0xda, 0x60, 0x08, 0x02, 0xb0, 0x00,
+ 0xd5, 0x06, 0x63, 0x18, 0x80, 0x05, 0xa8, 0x36, 0x18, 0x04, 0x01, 0x2c,
+ 0x40, 0xb5, 0x81, 0x5c, 0x8a, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x09,
+ 0xa8, 0x88, 0x71, 0x78, 0x07, 0x79, 0x90, 0x87, 0x72, 0x18, 0x07, 0x7a,
+ 0x60, 0x87, 0x7c, 0x68, 0x03, 0x79, 0x78, 0x87, 0x7a, 0x70, 0x07, 0x72,
+ 0x28, 0x07, 0x72, 0x68, 0x03, 0x72, 0x48, 0x07, 0x7b, 0x48, 0x07, 0x72,
+ 0x28, 0x87, 0x36, 0x98, 0x87, 0x78, 0x90, 0x07, 0x7a, 0x68, 0x03, 0x73,
+ 0x80, 0x87, 0x36, 0x68, 0x87, 0x70, 0xa0, 0x07, 0x74, 0x00, 0xcc, 0x21,
+ 0x1c, 0xd8, 0x61, 0x1e, 0xca, 0x01, 0x20, 0xc8, 0x21, 0x1d, 0xe6, 0x21,
+ 0x1c, 0xc4, 0x81, 0x1d, 0xca, 0xa1, 0x0d, 0xe8, 0x21, 0x1c, 0xd2, 0x81,
+ 0x1d, 0xda, 0x60, 0x1c, 0xc2, 0x81, 0x1d, 0xd8, 0x61, 0x1e, 0x00, 0x73,
+ 0x08, 0x07, 0x76, 0x98, 0x87, 0x72, 0x00, 0x08, 0x76, 0x28, 0x87, 0x79,
+ 0x98, 0x87, 0x36, 0x80, 0x07, 0x79, 0x28, 0x87, 0x71, 0x48, 0x87, 0x79,
+ 0x28, 0x87, 0x36, 0x30, 0x07, 0x78, 0x68, 0x87, 0x70, 0x20, 0x07, 0x80,
+ 0x1e, 0xe4, 0xa1, 0x1e, 0xca, 0x01, 0x20, 0xdc, 0xe1, 0x1d, 0xda, 0xc0,
+ 0x1c, 0xe4, 0x21, 0x1c, 0xda, 0xa1, 0x1c, 0xda, 0x00, 0x1e, 0xde, 0x21,
+ 0x1d, 0xdc, 0x81, 0x1e, 0xca, 0x41, 0x1e, 0xda, 0xa0, 0x1c, 0xd8, 0x21,
+ 0x1d, 0xda, 0x01, 0xa0, 0x07, 0x79, 0xa8, 0x87, 0x72, 0x00, 0x06, 0x77,
+ 0x78, 0x87, 0x36, 0x30, 0x07, 0x79, 0x08, 0x87, 0x76, 0x28, 0x87, 0x36,
+ 0x80, 0x87, 0x77, 0x48, 0x07, 0x77, 0xa0, 0x87, 0x72, 0x90, 0x87, 0x36,
+ 0x28, 0x07, 0x76, 0x48, 0x87, 0x76, 0x68, 0x03, 0x77, 0x78, 0x07, 0x77,
+ 0x68, 0x03, 0x76, 0x28, 0x87, 0x70, 0x30, 0x07, 0x80, 0x70, 0x87, 0x77,
+ 0x68, 0x83, 0x74, 0x70, 0x07, 0x73, 0x98, 0x87, 0x36, 0x30, 0x07, 0x78,
+ 0x68, 0x83, 0x76, 0x08, 0x07, 0x7a, 0x40, 0x07, 0x80, 0x1e, 0xe4, 0xa1,
+ 0x1e, 0xca, 0x01, 0x20, 0xdc, 0xe1, 0x1d, 0xda, 0x40, 0x1d, 0xea, 0xa1,
+ 0x1d, 0xe0, 0xa1, 0x0d, 0xe8, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca, 0x61,
+ 0x1e, 0x00, 0x73, 0x08, 0x07, 0x76, 0x98, 0x87, 0x72, 0x00, 0x08, 0x77,
+ 0x78, 0x87, 0x36, 0x70, 0x87, 0x70, 0x70, 0x87, 0x79, 0x68, 0x03, 0x73,
+ 0x80, 0x87, 0x36, 0x68, 0x87, 0x70, 0xa0, 0x07, 0x74, 0x00, 0xe8, 0x41,
+ 0x1e, 0xea, 0xa1, 0x1c, 0x00, 0xc2, 0x1d, 0xde, 0xa1, 0x0d, 0xe6, 0x21,
+ 0x1d, 0xce, 0xc1, 0x1d, 0xca, 0x81, 0x1c, 0xda, 0x40, 0x1f, 0xca, 0x41,
+ 0x1e, 0xde, 0x61, 0x1e, 0xda, 0xc0, 0x1c, 0xe0, 0xa1, 0x0d, 0xda, 0x21,
+ 0x1c, 0xe8, 0x01, 0x1d, 0x00, 0x73, 0x08, 0x07, 0x76, 0x98, 0x87, 0x72,
+ 0x00, 0x88, 0x79, 0xa0, 0x87, 0x70, 0x18, 0x87, 0x75, 0x68, 0x03, 0x78,
+ 0x90, 0x87, 0x77, 0xa0, 0x87, 0x72, 0x18, 0x07, 0x7a, 0x78, 0x07, 0x79,
+ 0x68, 0x03, 0x71, 0xa8, 0x07, 0x73, 0x30, 0x87, 0x72, 0x90, 0x87, 0x36,
+ 0x98, 0x87, 0x74, 0xd0, 0x87, 0x72, 0x00, 0xf0, 0x00, 0x20, 0xe8, 0x21,
+ 0x1c, 0xe4, 0xe1, 0x1c, 0xca, 0x81, 0x1e, 0xda, 0xc0, 0x1c, 0xca, 0x21,
+ 0x1c, 0xe8, 0xa1, 0x1e, 0xe4, 0xa1, 0x1c, 0xe6, 0x01, 0x68, 0x03, 0x73,
+ 0x80, 0x87, 0x38, 0xb0, 0x03, 0x80, 0xa8, 0x07, 0x77, 0x98, 0x87, 0x70,
+ 0x30, 0x87, 0x72, 0x68, 0x03, 0x73, 0x80, 0x87, 0x36, 0x68, 0x87, 0x70,
+ 0xa0, 0x07, 0x74, 0x00, 0xe8, 0x41, 0x1e, 0xea, 0xa1, 0x1c, 0x00, 0xa2,
+ 0x1e, 0xe6, 0xa1, 0x1c, 0xda, 0x60, 0x1e, 0xde, 0xc1, 0x1c, 0xe8, 0xa1,
+ 0x0d, 0xcc, 0x81, 0x1d, 0xde, 0x21, 0x1c, 0xe8, 0x01, 0x30, 0x87, 0x70,
+ 0x60, 0x87, 0x79, 0x28, 0x07, 0x00, 0x00, 0x00, 0x49, 0x18, 0x00, 0x00,
+ 0x02, 0x00, 0x00, 0x00, 0x13, 0x8a, 0x40, 0x18, 0x88, 0x02, 0x00, 0x00,
+ 0x89, 0x20, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09,
+ 0x20, 0x64, 0x85, 0x04, 0x93, 0x22, 0xa4, 0x84, 0x04, 0x93, 0x22, 0xe3,
+ 0x84, 0xa1, 0x90, 0x14, 0x12, 0x4c, 0x8a, 0x8c, 0x0b, 0x84, 0xa4, 0x4c,
+ 0x10, 0x50, 0x33, 0x00, 0xc3, 0x08, 0x04, 0x30, 0x8c, 0x20, 0x00, 0xe7,
+ 0x49, 0x53, 0x44, 0x09, 0x93, 0xcf, 0x39, 0x0f, 0xf6, 0x12, 0xd1, 0x44,
+ 0x5c, 0x28, 0x35, 0x3d, 0xd4, 0xe4, 0x3f, 0x80, 0xa0, 0x10, 0x03, 0x16,
+ 0x82, 0x18, 0x44, 0x10, 0x82, 0x24, 0x08, 0x33, 0x4d, 0xe3, 0xc0, 0x0e,
+ 0xe1, 0x30, 0x0f, 0xf3, 0xe0, 0x06, 0xed, 0x50, 0x0e, 0xf4, 0x10, 0x0e,
+ 0xec, 0xa0, 0x07, 0x7a, 0xd0, 0x0e, 0xe1, 0x40, 0x0f, 0xf2, 0x90, 0x0e,
+ 0xf8, 0x80, 0x82, 0x32, 0x88, 0x60, 0x08, 0x73, 0x04, 0x60, 0x50, 0x8c,
+ 0x41, 0xc8, 0x39, 0x88, 0xd2, 0x40, 0x00, 0x99, 0x39, 0x02, 0x50, 0x18,
+ 0x44, 0x08, 0x84, 0x29, 0x80, 0x11, 0x80, 0x61, 0x04, 0x02, 0x99, 0x23,
+ 0x08, 0x28, 0x00, 0x00, 0x13, 0xb2, 0x70, 0x48, 0x07, 0x79, 0xb0, 0x03,
+ 0x3a, 0x68, 0x83, 0x70, 0x80, 0x07, 0x78, 0x60, 0x87, 0x72, 0x68, 0x83,
+ 0x76, 0x08, 0x87, 0x71, 0x78, 0x87, 0x79, 0xc0, 0x87, 0x38, 0x80, 0x03,
+ 0x37, 0x88, 0x83, 0x38, 0x70, 0x03, 0x38, 0xd8, 0xf0, 0x1e, 0xe5, 0xd0,
+ 0x06, 0xf0, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0,
+ 0x07, 0x76, 0x40, 0x07, 0x6d, 0x90, 0x0e, 0x71, 0xa0, 0x07, 0x78, 0xa0,
+ 0x07, 0x78, 0xd0, 0x06, 0xe9, 0x80, 0x07, 0x7a, 0x80, 0x07, 0x7a, 0x80,
+ 0x07, 0x6d, 0x90, 0x0e, 0x71, 0x60, 0x07, 0x7a, 0x10, 0x07, 0x76, 0xa0,
+ 0x07, 0x71, 0x60, 0x07, 0x6d, 0x90, 0x0e, 0x73, 0x20, 0x07, 0x7a, 0x30,
+ 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x76, 0x40,
+ 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x60,
+ 0x0e, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20,
+ 0x07, 0x6d, 0x60, 0x0e, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0,
+ 0x07, 0x76, 0x40, 0x07, 0x6d, 0x60, 0x0e, 0x78, 0x00, 0x07, 0x7a, 0x10,
+ 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d, 0x60,
+ 0x0f, 0x71, 0x60, 0x07, 0x7a, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x60,
+ 0x07, 0x6d, 0x60, 0x0f, 0x72, 0x40, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0,
+ 0x07, 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0f, 0x73, 0x20, 0x07, 0x7a, 0x30,
+ 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0f, 0x74, 0x80,
+ 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x60,
+ 0x0f, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40,
+ 0x07, 0x6d, 0x60, 0x0f, 0x79, 0x60, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80,
+ 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x20,
+ 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20,
+ 0x07, 0x78, 0xd0, 0x06, 0xf6, 0x10, 0x07, 0x79, 0x20, 0x07, 0x7a, 0x20,
+ 0x07, 0x75, 0x60, 0x07, 0x7a, 0x20, 0x07, 0x75, 0x60, 0x07, 0x6d, 0x60,
+ 0x0f, 0x72, 0x50, 0x07, 0x76, 0xa0, 0x07, 0x72, 0x50, 0x07, 0x76, 0xa0,
+ 0x07, 0x72, 0x50, 0x07, 0x76, 0xd0, 0x06, 0xf6, 0x50, 0x07, 0x71, 0x20,
+ 0x07, 0x7a, 0x50, 0x07, 0x71, 0x20, 0x07, 0x7a, 0x50, 0x07, 0x71, 0x20,
+ 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x00, 0x07, 0x72, 0x40, 0x07, 0x7a, 0x10,
+ 0x07, 0x70, 0x20, 0x07, 0x74, 0xa0, 0x07, 0x71, 0x00, 0x07, 0x72, 0x40,
+ 0x07, 0x6d, 0x60, 0x0e, 0x78, 0x00, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80,
+ 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d, 0xe0, 0x0e, 0x78, 0xa0,
+ 0x07, 0x71, 0x60, 0x07, 0x7a, 0x30, 0x07, 0x72, 0x30, 0x84, 0x51, 0x00,
+ 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x02, 0x01, 0x00, 0x00,
+ 0x09, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x10, 0x19, 0x11, 0x4c, 0x90,
+ 0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0x42, 0x25, 0x50, 0x10, 0x23,
+ 0x00, 0x05, 0x18, 0x50, 0x04, 0x05, 0x52, 0x06, 0x85, 0x40, 0x6d, 0x04,
+ 0x00, 0x00, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00, 0xd3, 0x00, 0x00, 0x00,
+ 0x1a, 0x03, 0x4c, 0x10, 0xd7, 0x20, 0x08, 0x0e, 0x8e, 0xad, 0x0c, 0x84,
+ 0x89, 0xc9, 0xaa, 0x09, 0xc4, 0xae, 0x4c, 0x6e, 0x2e, 0xed, 0xcd, 0x0d,
+ 0x04, 0x07, 0x46, 0xc6, 0x25, 0x06, 0x04, 0xa5, 0xad, 0x8c, 0x2e, 0x8c,
+ 0xcd, 0xac, 0xac, 0x05, 0x07, 0x46, 0xc6, 0x25, 0xc6, 0x65, 0x86, 0x26,
+ 0x65, 0x88, 0xb0, 0x00, 0x43, 0x0c, 0x24, 0x40, 0x04, 0x64, 0x60, 0xd1,
+ 0x54, 0x46, 0x17, 0xc6, 0x36, 0x04, 0x59, 0x06, 0x24, 0x40, 0x02, 0x64,
+ 0xe0, 0x16, 0x96, 0x26, 0xe7, 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56,
+ 0xe6, 0x42, 0x56, 0xe6, 0xf6, 0x26, 0xd7, 0x36, 0xf7, 0x45, 0x96, 0x36,
+ 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0x58, 0x0a, 0x72, 0x61, 0x69, 0x72,
+ 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x2e, 0x66, 0x61, 0x73,
+ 0x74, 0x5f, 0x6d, 0x61, 0x74, 0x68, 0x5f, 0x65, 0x6e, 0x61, 0x62, 0x6c,
+ 0x65, 0x43, 0x84, 0xe5, 0x60, 0x19, 0x84, 0xa5, 0xc9, 0xb9, 0x8c, 0xbd,
+ 0xb5, 0xc1, 0xa5, 0xb1, 0x95, 0xb9, 0x98, 0xc9, 0x85, 0xb5, 0x95, 0x89,
+ 0xd5, 0x99, 0x99, 0x95, 0xc9, 0x7d, 0x99, 0x95, 0xd1, 0x8d, 0xa1, 0x7d,
+ 0x91, 0xa5, 0xcd, 0x85, 0x89, 0xb1, 0x95, 0x0d, 0x11, 0x96, 0x84, 0x61,
+ 0x10, 0x96, 0x26, 0xe7, 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56, 0xe6,
+ 0xe2, 0x16, 0x46, 0x97, 0x66, 0x57, 0xf6, 0x45, 0xf6, 0x56, 0x27, 0xc6,
+ 0x56, 0xf6, 0x45, 0x96, 0x36, 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0x58,
+ 0x16, 0x32, 0x61, 0x69, 0x72, 0x2e, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69,
+ 0x6f, 0x6e, 0x8c, 0xc2, 0xd2, 0xe4, 0x5c, 0xc2, 0xe4, 0xce, 0xbe, 0xe8,
+ 0xf2, 0xe0, 0xca, 0xbe, 0xdc, 0xc2, 0xda, 0xca, 0x68, 0x98, 0xb1, 0xbd,
+ 0x85, 0xd1, 0xd1, 0x90, 0x09, 0x4b, 0x93, 0x73, 0x09, 0x93, 0x3b, 0xfb,
+ 0x72, 0x0b, 0x6b, 0x2b, 0x23, 0x02, 0xf7, 0x36, 0x97, 0x46, 0x97, 0xf6,
+ 0xe6, 0x36, 0x44, 0x59, 0x9a, 0xc5, 0x59, 0x9e, 0x05, 0x5a, 0x22, 0x46,
+ 0x61, 0x69, 0x72, 0x2e, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x5f, 0x6f,
+ 0x75, 0x74, 0x70, 0x75, 0x74, 0xcc, 0xce, 0xca, 0xdc, 0xca, 0xe4, 0xc2,
+ 0xe8, 0xca, 0xc8, 0x50, 0x70, 0xe8, 0xca, 0xf0, 0xc6, 0xde, 0xde, 0xe4,
+ 0xc8, 0x88, 0xec, 0x64, 0xbe, 0xcc, 0x52, 0x68, 0x98, 0xb1, 0xbd, 0x85,
+ 0xd1, 0xc9, 0x10, 0xa1, 0x2b, 0xc3, 0x1b, 0x7b, 0x7b, 0x93, 0x23, 0x1b,
+ 0xc2, 0x2c, 0xd3, 0x42, 0x2d, 0xce, 0x52, 0x2d, 0xd0, 0x62, 0x0d, 0x21,
+ 0x16, 0x69, 0xb9, 0xa8, 0x84, 0xa5, 0xc9, 0xb9, 0x88, 0xd5, 0x99, 0x99,
+ 0x95, 0xc9, 0x51, 0x0a, 0x4b, 0x93, 0x73, 0x61, 0x7b, 0x1b, 0x0b, 0xa3,
+ 0x4b, 0x7b, 0x73, 0xfb, 0x4a, 0x73, 0x23, 0x2b, 0xc3, 0x23, 0x12, 0x96,
+ 0x26, 0xe7, 0x22, 0x57, 0x16, 0x46, 0xc6, 0x28, 0x2c, 0x4d, 0xce, 0x25,
+ 0x4c, 0xee, 0xec, 0x8b, 0x2e, 0x0f, 0xae, 0xec, 0x6b, 0x2e, 0x4d, 0xaf,
+ 0x8c, 0x57, 0x58, 0x9a, 0x9c, 0x4b, 0x98, 0xdc, 0xd9, 0x17, 0x5d, 0x1e,
+ 0x5c, 0xd9, 0x57, 0x18, 0x5b, 0xda, 0x99, 0xdb, 0xd7, 0x5c, 0x9a, 0x5e,
+ 0xd9, 0x10, 0x0e, 0x19, 0x96, 0x6c, 0xd1, 0x90, 0x01, 0x09, 0x96, 0x6d,
+ 0xe1, 0x10, 0x61, 0xe9, 0x10, 0x61, 0x71, 0x96, 0x6a, 0x81, 0x96, 0x88,
+ 0x09, 0x5d, 0x19, 0xde, 0xd8, 0xdb, 0x9b, 0x1c, 0xd9, 0xdc, 0x10, 0x0e,
+ 0x09, 0x96, 0x6c, 0xd1, 0x90, 0x00, 0x09, 0x96, 0x6d, 0xe1, 0x10, 0x61,
+ 0xe9, 0x10, 0x61, 0x71, 0x96, 0x6a, 0x81, 0x96, 0x8f, 0x4f, 0x58, 0x9a,
+ 0x9c, 0x8b, 0x58, 0x9d, 0x99, 0x59, 0x99, 0xdc, 0xd7, 0x5c, 0x9a, 0x5e,
+ 0x19, 0x11, 0x33, 0xb6, 0xb7, 0x30, 0x3a, 0x1a, 0x3c, 0x1a, 0x2a, 0x70,
+ 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0xc0, 0x00,
+ 0x29, 0x96, 0x6c, 0x09, 0x03, 0x84, 0x58, 0x34, 0xa4, 0x40, 0x82, 0x65,
+ 0x5b, 0x38, 0x84, 0x58, 0x3a, 0xc4, 0x58, 0x9c, 0x45, 0x0c, 0x16, 0x68,
+ 0x19, 0x03, 0x26, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x6f, 0x72, 0x6d,
+ 0x43, 0xc0, 0x00, 0x39, 0x96, 0x6c, 0x09, 0x03, 0x84, 0x58, 0x34, 0xe4,
+ 0x40, 0x82, 0x65, 0x5b, 0x38, 0x84, 0x58, 0x3a, 0xc4, 0x58, 0x9c, 0x45,
+ 0x0c, 0x16, 0x68, 0x29, 0x03, 0x36, 0x61, 0x69, 0x72, 0x2e, 0x76, 0x65,
+ 0x72, 0x74, 0x65, 0x78, 0x5f, 0x69, 0x64, 0x24, 0xea, 0xd2, 0xdc, 0xe8,
+ 0x38, 0xd8, 0xa5, 0x91, 0x0d, 0x61, 0x10, 0x64, 0x39, 0x83, 0xc5, 0x59,
+ 0xd0, 0x60, 0x81, 0x96, 0x34, 0x18, 0xa2, 0x2c, 0xde, 0x02, 0x06, 0x0b,
+ 0x19, 0x2c, 0x66, 0xb0, 0xa8, 0xc1, 0x10, 0x43, 0x01, 0x16, 0x6c, 0x59,
+ 0x03, 0x3e, 0x6f, 0x6d, 0x6e, 0x69, 0x70, 0x6f, 0x74, 0x65, 0x6e, 0x74,
+ 0x20, 0x63, 0x68, 0x61, 0x72, 0x7c, 0xa6, 0xd2, 0xda, 0xe0, 0xd8, 0xca,
+ 0x40, 0x86, 0x56, 0x56, 0x40, 0xa8, 0x84, 0x82, 0x82, 0x86, 0x08, 0x8b,
+ 0x1b, 0x0c, 0x31, 0x96, 0x36, 0x58, 0xde, 0xa0, 0x49, 0x86, 0x18, 0x0b,
+ 0x1c, 0x2c, 0x70, 0xd0, 0x24, 0x23, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68,
+ 0x07, 0x37, 0x48, 0x07, 0x72, 0x28, 0x07, 0x77, 0xa0, 0x87, 0x29, 0x41,
+ 0x30, 0x62, 0x09, 0x87, 0x74, 0x90, 0x07, 0x37, 0xb0, 0x87, 0x72, 0x90,
+ 0x87, 0x79, 0x48, 0x87, 0x77, 0x70, 0x87, 0x29, 0x81, 0x30, 0x82, 0x0a,
+ 0x87, 0x74, 0x90, 0x07, 0x37, 0x60, 0x87, 0x70, 0x70, 0x87, 0x73, 0xa8,
+ 0x87, 0x70, 0x38, 0x87, 0x72, 0xf8, 0x05, 0x7b, 0x28, 0x07, 0x79, 0x98,
+ 0x87, 0x74, 0x78, 0x07, 0x77, 0x98, 0x12, 0x10, 0x23, 0xa6, 0x70, 0x48,
+ 0x07, 0x79, 0x70, 0x83, 0x71, 0x78, 0x87, 0x76, 0x80, 0x87, 0x74, 0x60,
+ 0x87, 0x72, 0xf8, 0x85, 0x77, 0x80, 0x07, 0x7a, 0x48, 0x87, 0x77, 0x70,
+ 0x87, 0x79, 0x98, 0x42, 0x18, 0x88, 0xc2, 0x8c, 0x50, 0xc2, 0x21, 0x1d,
+ 0xe4, 0xc1, 0x0d, 0xec, 0xa1, 0x1c, 0xe4, 0x81, 0x1e, 0xca, 0x01, 0x1f,
+ 0xa6, 0x04, 0x6c, 0x00, 0x79, 0x18, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00,
+ 0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66, 0x14, 0x01, 0x3d, 0x88,
+ 0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07, 0x79, 0x78, 0x07, 0x73,
+ 0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e,
+ 0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce, 0xa1, 0x1c, 0x66, 0x30,
+ 0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b, 0xcc, 0x03, 0x3d, 0xc8,
+ 0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c, 0x74, 0x70, 0x07, 0x7b,
+ 0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07, 0x7a, 0x70, 0x03, 0x76,
+ 0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11, 0x0e, 0xec, 0x90, 0x0e,
+ 0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0, 0x0e, 0xf0, 0x50, 0x0e,
+ 0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8, 0x21, 0x1d, 0xc2, 0x61,
+ 0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xb4,
+ 0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b, 0xcc, 0xf0, 0x14, 0x76,
+ 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87, 0x72, 0x68, 0x07, 0x37,
+ 0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07, 0x76, 0x28, 0x07, 0x76,
+ 0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87, 0x5f, 0x08, 0x87, 0x71,
+ 0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81, 0x2c, 0xee, 0xf0, 0x0e,
+ 0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30, 0x03, 0x62, 0xc8, 0xa1,
+ 0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xdc, 0x61,
+ 0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca, 0x61, 0x06, 0xd6, 0x90,
+ 0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39, 0xc8, 0x43, 0x39, 0xb8,
+ 0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b, 0x94, 0xc3, 0x2f, 0xbc,
+ 0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b, 0xb0, 0xc3, 0x0c, 0xc7,
+ 0x69, 0x87, 0x70, 0x58, 0x87, 0x72, 0x70, 0x83, 0x74, 0x68, 0x07, 0x78,
+ 0x60, 0x87, 0x74, 0x18, 0x87, 0x74, 0xa0, 0x87, 0x19, 0xce, 0x53, 0x0f,
+ 0xee, 0x00, 0x0f, 0xf2, 0x50, 0x0e, 0xe4, 0x90, 0x0e, 0xe3, 0x40, 0x0f,
+ 0xe1, 0x20, 0x0e, 0xec, 0x50, 0x0e, 0x33, 0x20, 0x28, 0x1d, 0xdc, 0xc1,
+ 0x1e, 0xc2, 0x41, 0x1e, 0xd2, 0x21, 0x1c, 0xdc, 0x81, 0x1e, 0xdc, 0xe0,
+ 0x1c, 0xe4, 0xe1, 0x1d, 0xea, 0x01, 0x1e, 0x66, 0x18, 0x51, 0x38, 0xb0,
+ 0x43, 0x3a, 0x9c, 0x83, 0x3b, 0xcc, 0x50, 0x24, 0x76, 0x60, 0x07, 0x7b,
+ 0x68, 0x07, 0x37, 0x60, 0x87, 0x77, 0x78, 0x07, 0x78, 0x98, 0x51, 0x4c,
+ 0xf4, 0x90, 0x0f, 0xf0, 0x50, 0x0e, 0x00, 0x00, 0x71, 0x20, 0x00, 0x00,
+ 0x04, 0x00, 0x00, 0x00, 0x06, 0xf0, 0xb0, 0x5d, 0xf9, 0x73, 0xce, 0x83,
+ 0xfd, 0x15, 0x11, 0x4d, 0xc4, 0x05, 0x00, 0x00, 0x61, 0x20, 0x00, 0x00,
+ 0x6d, 0x00, 0x00, 0x00, 0x13, 0x04, 0x47, 0x2c, 0x10, 0x00, 0x00, 0x00,
+ 0x07, 0x00, 0x00, 0x00, 0x14, 0x47, 0x00, 0xa8, 0x95, 0x41, 0x11, 0x94,
+ 0x00, 0x8d, 0x19, 0x00, 0x0a, 0x33, 0x00, 0x04, 0xc6, 0x08, 0x40, 0x10,
+ 0x04, 0xf1, 0x6f, 0x04, 0x00, 0x00, 0x00, 0x00, 0x33, 0x11, 0x0c, 0x12,
+ 0x14, 0x33, 0x11, 0x0c, 0x12, 0x14, 0xe3, 0x11, 0x0d, 0x64, 0x41, 0x14,
+ 0x94, 0x59, 0x82, 0x60, 0xa0, 0x02, 0x81, 0x03, 0xe0, 0x0c, 0x86, 0x0b,
+ 0x9a, 0x8c, 0x47, 0x40, 0x94, 0x16, 0x50, 0x50, 0x06, 0x19, 0x82, 0x05,
+ 0xb2, 0xc0, 0x90, 0xcf, 0x2c, 0x81, 0x30, 0x50, 0x81, 0x80, 0x42, 0x50,
+ 0x09, 0x03, 0x15, 0x01, 0x11, 0x44, 0xc2, 0x18, 0x42, 0x21, 0xcc, 0x31,
+ 0x40, 0x41, 0x18, 0x0c, 0x32, 0x04, 0x91, 0x75, 0x45, 0x93, 0xf1, 0x88,
+ 0xcd, 0x23, 0x83, 0x80, 0x82, 0x62, 0x01, 0x21, 0x1f, 0x0b, 0x10, 0xf8,
+ 0x98, 0xa2, 0x06, 0x30, 0x18, 0x6e, 0x08, 0xc8, 0x00, 0x0c, 0x66, 0x19,
+ 0x06, 0x21, 0x18, 0x8f, 0xb0, 0xc8, 0x40, 0x0d, 0xa2, 0xc1, 0x88, 0x80,
+ 0x28, 0x00, 0x9b, 0xda, 0x00, 0x06, 0xc3, 0x0d, 0xc1, 0x19, 0x80, 0xc1,
+ 0x2c, 0x03, 0x11, 0x04, 0xe3, 0x11, 0xd9, 0x19, 0xb4, 0xc1, 0x19, 0x50,
+ 0x50, 0xc6, 0x23, 0xb6, 0x34, 0x78, 0x03, 0x30, 0xa0, 0xa0, 0x8c, 0x47,
+ 0x74, 0x6b, 0x10, 0x07, 0x63, 0x40, 0x41, 0x19, 0x8f, 0xf8, 0xda, 0x60,
+ 0x0e, 0xcc, 0x80, 0x82, 0x32, 0x1e, 0x01, 0x06, 0x6f, 0x50, 0x07, 0x6f,
+ 0x30, 0x18, 0x11, 0x20, 0x05, 0x30, 0x1e, 0x11, 0x06, 0x70, 0x60, 0x07,
+ 0x67, 0x30, 0x18, 0x11, 0x1c, 0x05, 0x30, 0x1e, 0x21, 0x06, 0x71, 0x70,
+ 0x07, 0x69, 0x30, 0x18, 0x11, 0x18, 0x05, 0x30, 0x1e, 0x31, 0x06, 0x72,
+ 0x80, 0x07, 0x6b, 0x30, 0x18, 0x11, 0x14, 0x05, 0x70, 0x6e, 0xd0, 0x62,
+ 0x3c, 0x61, 0x0e, 0x02, 0x0a, 0xc8, 0x18, 0x42, 0xc0, 0x07, 0x73, 0x0c,
+ 0x6c, 0x10, 0xf4, 0xc1, 0x18, 0xc2, 0x00, 0x0a, 0x73, 0x0c, 0x42, 0x10,
+ 0x0a, 0x73, 0x0c, 0x41, 0x1b, 0xf8, 0xc1, 0x1c, 0x43, 0xf0, 0x06, 0x7d,
+ 0x30, 0xc8, 0x10, 0xc4, 0x81, 0x1d, 0x58, 0x50, 0xc9, 0x67, 0x96, 0xa0,
+ 0x18, 0xa8, 0x40, 0x58, 0x82, 0xa8, 0x8a, 0x81, 0x8a, 0x80, 0x20, 0xa2,
+ 0x62, 0x0c, 0xa1, 0x10, 0xe6, 0x18, 0xec, 0x20, 0x38, 0x85, 0x41, 0x86,
+ 0xe0, 0x0e, 0xf8, 0xe0, 0x8a, 0x26, 0xe3, 0x11, 0x75, 0x40, 0x0a, 0xaa,
+ 0x10, 0x50, 0x50, 0x2c, 0x20, 0xe4, 0x63, 0x01, 0x02, 0x1f, 0x53, 0x60,
+ 0x01, 0x06, 0xc3, 0x0d, 0x81, 0x2a, 0x80, 0xc1, 0x2c, 0x83, 0x51, 0x04,
+ 0xe3, 0x09, 0xa8, 0x70, 0x51, 0x40, 0x66, 0x1b, 0x44, 0xa1, 0x00, 0x66,
+ 0x1b, 0x02, 0x21, 0xc8, 0x20, 0x20, 0x06, 0x00, 0x0a, 0x00, 0x00, 0x00,
+ 0x5b, 0x86, 0x21, 0x88, 0x83, 0x2d, 0x03, 0x12, 0xc4, 0xc1, 0x96, 0x61,
+ 0x0a, 0xe2, 0x60, 0xcb, 0xa0, 0x05, 0x71, 0xb0, 0x65, 0x80, 0x83, 0x20,
+ 0x0e, 0xb6, 0x0c, 0xa1, 0x10, 0xc4, 0xc1, 0x96, 0x01, 0x15, 0x82, 0x38,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xde, 0xc0, 0x17, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
+ 0x98, 0x08, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x42, 0x43, 0xc0, 0xde,
+ 0x21, 0x0c, 0x00, 0x00, 0x23, 0x02, 0x00, 0x00, 0x0b, 0x82, 0x20, 0x00,
+ 0x02, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91,
+ 0x41, 0xc8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0c,
+ 0x25, 0x05, 0x08, 0x19, 0x1e, 0x04, 0x8b, 0x62, 0x80, 0x10, 0x45, 0x02,
+ 0x42, 0x92, 0x0b, 0x42, 0x84, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x49,
+ 0x0a, 0x32, 0x44, 0x24, 0x48, 0x0a, 0x90, 0x21, 0x23, 0xc4, 0x52, 0x80,
+ 0x0c, 0x19, 0x21, 0x72, 0x24, 0x07, 0xc8, 0x08, 0x11, 0x62, 0xa8, 0xa0,
+ 0xa8, 0x40, 0xc6, 0xf0, 0x01, 0x00, 0x00, 0x00, 0x51, 0x18, 0x00, 0x00,
+ 0x81, 0x00, 0x00, 0x00, 0x1b, 0x8c, 0x20, 0x00, 0x16, 0xa0, 0xda, 0x40,
+ 0x2e, 0xc2, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x80, 0x04, 0x54, 0xc4, 0x38,
+ 0xbc, 0x83, 0x3c, 0xc8, 0x43, 0x39, 0x8c, 0x03, 0x3d, 0xb0, 0x43, 0x3e,
+ 0xb4, 0x81, 0x3c, 0xbc, 0x43, 0x3d, 0xb8, 0x03, 0x39, 0x94, 0x03, 0x39,
+ 0xb4, 0x01, 0x39, 0xa4, 0x83, 0x3d, 0xa4, 0x03, 0x39, 0x94, 0x43, 0x1b,
+ 0xcc, 0x43, 0x3c, 0xc8, 0x03, 0x3d, 0xb4, 0x81, 0x39, 0xc0, 0x43, 0x1b,
+ 0xb4, 0x43, 0x38, 0xd0, 0x03, 0x3a, 0x00, 0xe6, 0x10, 0x0e, 0xec, 0x30,
+ 0x0f, 0xe5, 0x00, 0x10, 0xe4, 0x90, 0x0e, 0xf3, 0x10, 0x0e, 0xe2, 0xc0,
+ 0x0e, 0xe5, 0xd0, 0x06, 0xf4, 0x10, 0x0e, 0xe9, 0xc0, 0x0e, 0x6d, 0x30,
+ 0x0e, 0xe1, 0xc0, 0x0e, 0xec, 0x30, 0x0f, 0x80, 0x39, 0x84, 0x03, 0x3b,
+ 0xcc, 0x43, 0x39, 0x00, 0x04, 0x3b, 0x94, 0xc3, 0x3c, 0xcc, 0x43, 0x1b,
+ 0xc0, 0x83, 0x3c, 0x94, 0xc3, 0x38, 0xa4, 0xc3, 0x3c, 0x94, 0x43, 0x1b,
+ 0x98, 0x03, 0x3c, 0xb4, 0x43, 0x38, 0x90, 0x03, 0x40, 0x0f, 0xf2, 0x50,
+ 0x0f, 0xe5, 0x00, 0x10, 0xee, 0xf0, 0x0e, 0x6d, 0x60, 0x0e, 0xf2, 0x10,
+ 0x0e, 0xed, 0x50, 0x0e, 0x6d, 0x00, 0x0f, 0xef, 0x90, 0x0e, 0xee, 0x40,
+ 0x0f, 0xe5, 0x20, 0x0f, 0x6d, 0x50, 0x0e, 0xec, 0x90, 0x0e, 0xed, 0x00,
+ 0xd0, 0x83, 0x3c, 0xd4, 0x43, 0x39, 0x00, 0x83, 0x3b, 0xbc, 0x43, 0x1b,
+ 0x98, 0x83, 0x3c, 0x84, 0x43, 0x3b, 0x94, 0x43, 0x1b, 0xc0, 0xc3, 0x3b,
+ 0xa4, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xc8, 0x43, 0x1b, 0x94, 0x03, 0x3b,
+ 0xa4, 0x43, 0x3b, 0xb4, 0x81, 0x3b, 0xbc, 0x83, 0x3b, 0xb4, 0x01, 0x3b,
+ 0x94, 0x43, 0x38, 0x98, 0x03, 0x40, 0xb8, 0xc3, 0x3b, 0xb4, 0x41, 0x3a,
+ 0xb8, 0x83, 0x39, 0xcc, 0x43, 0x1b, 0x98, 0x03, 0x3c, 0xb4, 0x41, 0x3b,
+ 0x84, 0x03, 0x3d, 0xa0, 0x03, 0x40, 0x0f, 0xf2, 0x50, 0x0f, 0xe5, 0x00,
+ 0x10, 0xee, 0xf0, 0x0e, 0x6d, 0xa0, 0x0e, 0xf5, 0xd0, 0x0e, 0xf0, 0xd0,
+ 0x06, 0xf4, 0x10, 0x0e, 0xe2, 0xc0, 0x0e, 0xe5, 0x30, 0x0f, 0x80, 0x39,
+ 0x84, 0x03, 0x3b, 0xcc, 0x43, 0x39, 0x00, 0x84, 0x3b, 0xbc, 0x43, 0x1b,
+ 0xb8, 0x43, 0x38, 0xb8, 0xc3, 0x3c, 0xb4, 0x81, 0x39, 0xc0, 0x43, 0x1b,
+ 0xb4, 0x43, 0x38, 0xd0, 0x03, 0x3a, 0x00, 0xf4, 0x20, 0x0f, 0xf5, 0x50,
+ 0x0e, 0x00, 0xe1, 0x0e, 0xef, 0xd0, 0x06, 0xf3, 0x90, 0x0e, 0xe7, 0xe0,
+ 0x0e, 0xe5, 0x40, 0x0e, 0x6d, 0xa0, 0x0f, 0xe5, 0x20, 0x0f, 0xef, 0x30,
+ 0x0f, 0x6d, 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80,
+ 0x0e, 0x80, 0x39, 0x84, 0x03, 0x3b, 0xcc, 0x43, 0x39, 0x00, 0xc4, 0x3c,
+ 0xd0, 0x43, 0x38, 0x8c, 0xc3, 0x3a, 0xb4, 0x01, 0x3c, 0xc8, 0xc3, 0x3b,
+ 0xd0, 0x43, 0x39, 0x8c, 0x03, 0x3d, 0xbc, 0x83, 0x3c, 0xb4, 0x81, 0x38,
+ 0xd4, 0x83, 0x39, 0x98, 0x43, 0x39, 0xc8, 0x43, 0x1b, 0xcc, 0x43, 0x3a,
+ 0xe8, 0x43, 0x39, 0x00, 0x78, 0x00, 0x10, 0xf4, 0x10, 0x0e, 0xf2, 0x70,
+ 0x0e, 0xe5, 0x40, 0x0f, 0x6d, 0x60, 0x0e, 0xe5, 0x10, 0x0e, 0xf4, 0x50,
+ 0x0f, 0xf2, 0x50, 0x0e, 0xf3, 0x00, 0xb4, 0x81, 0x39, 0xc0, 0x43, 0x1c,
+ 0xd8, 0x01, 0x40, 0xd4, 0x83, 0x3b, 0xcc, 0x43, 0x38, 0x98, 0x43, 0x39,
+ 0xb4, 0x81, 0x39, 0xc0, 0x43, 0x1b, 0xb4, 0x43, 0x38, 0xd0, 0x03, 0x3a,
+ 0x00, 0xf4, 0x20, 0x0f, 0xf5, 0x50, 0x0e, 0x00, 0x51, 0x0f, 0xf3, 0x50,
+ 0x0e, 0x6d, 0x30, 0x0f, 0xef, 0x60, 0x0e, 0xf4, 0xd0, 0x06, 0xe6, 0xc0,
+ 0x0e, 0xef, 0x10, 0x0e, 0xf4, 0x00, 0x98, 0x43, 0x38, 0xb0, 0xc3, 0x3c,
+ 0x94, 0x03, 0x00, 0x00, 0x49, 0x18, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+ 0x13, 0x84, 0x40, 0x00, 0x89, 0x20, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00,
+ 0x32, 0x22, 0x08, 0x09, 0x20, 0x64, 0x85, 0x04, 0x13, 0x22, 0xa4, 0x84,
+ 0x04, 0x13, 0x22, 0xe3, 0x84, 0xa1, 0x90, 0x14, 0x12, 0x4c, 0x88, 0x8c,
+ 0x0b, 0x84, 0x84, 0x4c, 0x10, 0x24, 0x33, 0x00, 0xc3, 0x08, 0x04, 0x30,
+ 0x88, 0x10, 0x08, 0x45, 0x08, 0xa1, 0x19, 0x08, 0x98, 0x23, 0x00, 0x83,
+ 0x39, 0x02, 0x50, 0x18, 0x01, 0x00, 0x00, 0x00, 0x13, 0xb2, 0x70, 0x48,
+ 0x07, 0x79, 0xb0, 0x03, 0x3a, 0x68, 0x83, 0x70, 0x80, 0x07, 0x78, 0x60,
+ 0x87, 0x72, 0x68, 0x83, 0x76, 0x08, 0x87, 0x71, 0x78, 0x87, 0x79, 0xc0,
+ 0x87, 0x38, 0x80, 0x03, 0x37, 0x88, 0x83, 0x38, 0x70, 0x03, 0x38, 0xd8,
+ 0xf0, 0x1e, 0xe5, 0xd0, 0x06, 0xf0, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a,
+ 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x90, 0x0e, 0x71,
+ 0xa0, 0x07, 0x78, 0xa0, 0x07, 0x78, 0xd0, 0x06, 0xe9, 0x80, 0x07, 0x7a,
+ 0x80, 0x07, 0x7a, 0x80, 0x07, 0x6d, 0x90, 0x0e, 0x71, 0x60, 0x07, 0x7a,
+ 0x10, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x60, 0x07, 0x6d, 0x90, 0x0e, 0x73,
+ 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d,
+ 0x90, 0x0e, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76,
+ 0x40, 0x07, 0x6d, 0x60, 0x0e, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72,
+ 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0e, 0x76, 0x40, 0x07, 0x7a,
+ 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x60, 0x0e, 0x78,
+ 0x00, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72,
+ 0x80, 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x60, 0x07, 0x7a, 0x10, 0x07, 0x76,
+ 0xa0, 0x07, 0x71, 0x60, 0x07, 0x6d, 0x60, 0x0f, 0x72, 0x40, 0x07, 0x7a,
+ 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0f, 0x73,
+ 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d,
+ 0x60, 0x0f, 0x74, 0x80, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76,
+ 0x40, 0x07, 0x6d, 0x60, 0x0f, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74,
+ 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x60, 0x0f, 0x79, 0x60, 0x07, 0x7a,
+ 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d,
+ 0x60, 0x0f, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78,
+ 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0, 0x06, 0xf6, 0x10, 0x07, 0x79,
+ 0x20, 0x07, 0x7a, 0x20, 0x07, 0x75, 0x60, 0x07, 0x7a, 0x20, 0x07, 0x75,
+ 0x60, 0x07, 0x6d, 0x60, 0x0f, 0x72, 0x50, 0x07, 0x76, 0xa0, 0x07, 0x72,
+ 0x50, 0x07, 0x76, 0xa0, 0x07, 0x72, 0x50, 0x07, 0x76, 0xd0, 0x06, 0xf6,
+ 0x50, 0x07, 0x71, 0x20, 0x07, 0x7a, 0x50, 0x07, 0x71, 0x20, 0x07, 0x7a,
+ 0x50, 0x07, 0x71, 0x20, 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x00, 0x07, 0x72,
+ 0x40, 0x07, 0x7a, 0x10, 0x07, 0x70, 0x20, 0x07, 0x74, 0xa0, 0x07, 0x71,
+ 0x00, 0x07, 0x72, 0x40, 0x07, 0x6d, 0x60, 0x0e, 0x78, 0x00, 0x07, 0x7a,
+ 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d,
+ 0xe0, 0x0e, 0x78, 0xa0, 0x07, 0x71, 0x60, 0x07, 0x7a, 0x30, 0x07, 0x72,
+ 0x30, 0x84, 0x21, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8,
+ 0x02, 0x01, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x0c,
+ 0x19, 0x11, 0x4c, 0x90, 0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0xb2,
+ 0x11, 0x80, 0x12, 0x28, 0x90, 0x82, 0xa0, 0x1b, 0x01, 0x00, 0x00, 0x00,
+ 0x79, 0x18, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x1a, 0x03, 0x4c, 0x10,
+ 0xd7, 0x20, 0x08, 0x0e, 0x8e, 0xad, 0x0c, 0x84, 0x89, 0xc9, 0xaa, 0x09,
+ 0xc4, 0xae, 0x4c, 0x6e, 0x2e, 0xed, 0xcd, 0x0d, 0x04, 0x07, 0x46, 0xc6,
+ 0x25, 0x06, 0x04, 0xa5, 0xad, 0x8c, 0x2e, 0x8c, 0xcd, 0xac, 0xac, 0x05,
+ 0x07, 0x46, 0xc6, 0x25, 0xc6, 0x65, 0x86, 0x26, 0x65, 0x88, 0x50, 0x00,
+ 0x43, 0x0c, 0x43, 0x30, 0x08, 0x23, 0x60, 0xd1, 0x54, 0x46, 0x17, 0xc6,
+ 0x36, 0x04, 0x29, 0x06, 0x43, 0x30, 0x04, 0x23, 0xe0, 0x16, 0x96, 0x26,
+ 0xe7, 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56, 0xe6, 0x42, 0x56, 0xe6,
+ 0xf6, 0x26, 0xd7, 0x36, 0xf7, 0x45, 0x96, 0x36, 0x17, 0x26, 0xc6, 0x56,
+ 0x36, 0x44, 0x28, 0x0a, 0x72, 0x61, 0x69, 0x72, 0x2e, 0x63, 0x6f, 0x6d,
+ 0x70, 0x69, 0x6c, 0x65, 0x2e, 0x66, 0x61, 0x73, 0x74, 0x5f, 0x6d, 0x61,
+ 0x74, 0x68, 0x5f, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x43, 0x84, 0xe2,
+ 0x60, 0x19, 0x84, 0xa5, 0xc9, 0xb9, 0x8c, 0xbd, 0xb5, 0xc1, 0xa5, 0xb1,
+ 0x95, 0xb9, 0x98, 0xc9, 0x85, 0xb5, 0x95, 0x89, 0xd5, 0x99, 0x99, 0x95,
+ 0xc9, 0x7d, 0x99, 0x95, 0xd1, 0x8d, 0xa1, 0x7d, 0x91, 0xa5, 0xcd, 0x85,
+ 0x89, 0xb1, 0x95, 0x0d, 0x11, 0x8a, 0x84, 0x61, 0x10, 0x96, 0x26, 0xe7,
+ 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56, 0xe6, 0xe2, 0x16, 0x46, 0x97,
+ 0x66, 0x57, 0xf6, 0x45, 0xf6, 0x56, 0x27, 0xc6, 0x56, 0xf6, 0x45, 0x96,
+ 0x36, 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0x28, 0x16, 0x46, 0x61, 0x69,
+ 0x72, 0x2e, 0x72, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x5f, 0x74, 0x61, 0x72,
+ 0x67, 0x65, 0x74, 0x8c, 0xc2, 0xd2, 0xe4, 0x5c, 0xc2, 0xe4, 0xce, 0xbe,
+ 0xe8, 0xf2, 0xe0, 0xca, 0xbe, 0xdc, 0xc2, 0xda, 0xca, 0x68, 0x98, 0xb1,
+ 0xbd, 0x85, 0xd1, 0xd1, 0x0c, 0x41, 0x8a, 0xc6, 0x08, 0x0a, 0xa7, 0x78,
+ 0x86, 0x08, 0x05, 0x44, 0x25, 0x2c, 0x4d, 0xce, 0x45, 0xac, 0xce, 0xcc,
+ 0xac, 0x4c, 0x8e, 0x4f, 0x58, 0x9a, 0x9c, 0x8b, 0x58, 0x9d, 0x99, 0x59,
+ 0x99, 0xdc, 0xd7, 0x5c, 0x9a, 0x5e, 0x19, 0xa5, 0xb0, 0x34, 0x39, 0x17,
+ 0xb6, 0xb7, 0xb1, 0x30, 0xba, 0xb4, 0x37, 0xb7, 0xaf, 0x34, 0x37, 0xb2,
+ 0x32, 0x3c, 0x22, 0x61, 0x69, 0x72, 0x2e, 0x72, 0x65, 0x61, 0x64, 0x8c,
+ 0xc2, 0xd2, 0xe4, 0x5c, 0xc2, 0xe4, 0xce, 0xbe, 0xe8, 0xf2, 0xe0, 0xca,
+ 0xbe, 0xe6, 0xd2, 0xf4, 0xca, 0x78, 0x85, 0xa5, 0xc9, 0xb9, 0x84, 0xc9,
+ 0x9d, 0x7d, 0xd1, 0xe5, 0xc1, 0x95, 0x7d, 0x85, 0xb1, 0xa5, 0x9d, 0xb9,
+ 0x7d, 0xcd, 0xa5, 0xe9, 0x95, 0x91, 0x09, 0x4b, 0x93, 0x73, 0x09, 0x93,
+ 0x3b, 0xfb, 0x72, 0x0b, 0x6b, 0x2b, 0xe3, 0x30, 0xf6, 0xc6, 0x36, 0x04,
+ 0x0c, 0x8c, 0xa0, 0x90, 0x8a, 0xc9, 0x18, 0x0a, 0xca, 0x08, 0x0c, 0xa1,
+ 0xa8, 0x0a, 0xcb, 0x18, 0x8a, 0xcb, 0x18, 0x0a, 0xa7, 0x78, 0x0a, 0xac,
+ 0xc8, 0x86, 0x08, 0x85, 0x36, 0xc4, 0x20, 0x80, 0x22, 0x2a, 0x36, 0x3e,
+ 0x6f, 0x6d, 0x6e, 0x69, 0x70, 0x6f, 0x74, 0x65, 0x6e, 0x74, 0x20, 0x63,
+ 0x68, 0x61, 0x72, 0x7c, 0xa6, 0xd2, 0xda, 0xe0, 0xd8, 0xca, 0x40, 0x86,
+ 0x56, 0x56, 0x40, 0xa8, 0x84, 0x82, 0x82, 0x86, 0x08, 0x85, 0x37, 0xc4,
+ 0x28, 0xba, 0xe2, 0x3b, 0x8a, 0x21, 0x46, 0x01, 0x06, 0x05, 0x18, 0x1c,
+ 0xc5, 0x08, 0x85, 0x1d, 0xd8, 0xc1, 0x1e, 0xda, 0xc1, 0x0d, 0xd2, 0x81,
+ 0x1c, 0xca, 0xc1, 0x1d, 0xe8, 0x61, 0x4a, 0x10, 0x8c, 0x58, 0xc2, 0x21,
+ 0x1d, 0xe4, 0xc1, 0x0d, 0xec, 0xa1, 0x1c, 0xe4, 0x61, 0x1e, 0xd2, 0xe1,
+ 0x1d, 0xdc, 0x61, 0x4a, 0x20, 0x8c, 0xa0, 0xc2, 0x21, 0x1d, 0xe4, 0xc1,
+ 0x0d, 0xd8, 0x21, 0x1c, 0xdc, 0xe1, 0x1c, 0xea, 0x21, 0x1c, 0xce, 0xa1,
+ 0x1c, 0x7e, 0xc1, 0x1e, 0xca, 0x41, 0x1e, 0xe6, 0x21, 0x1d, 0xde, 0xc1,
+ 0x1d, 0xa6, 0x04, 0xc4, 0x88, 0x29, 0x1c, 0xd2, 0x41, 0x1e, 0xdc, 0x60,
+ 0x1c, 0xde, 0xa1, 0x1d, 0xe0, 0x21, 0x1d, 0xd8, 0xa1, 0x1c, 0x7e, 0xe1,
+ 0x1d, 0xe0, 0x81, 0x1e, 0xd2, 0xe1, 0x1d, 0xdc, 0x61, 0x1e, 0xa6, 0x10,
+ 0x06, 0xa2, 0x30, 0x23, 0x98, 0x70, 0x48, 0x07, 0x79, 0x70, 0x03, 0x73,
+ 0x90, 0x87, 0x70, 0x38, 0x87, 0x76, 0x28, 0x07, 0x77, 0xa0, 0x87, 0x29,
+ 0x01, 0x07, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00,
+ 0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66, 0x14, 0x01, 0x3d, 0x88,
+ 0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07, 0x79, 0x78, 0x07, 0x73,
+ 0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e,
+ 0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce, 0xa1, 0x1c, 0x66, 0x30,
+ 0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b, 0xcc, 0x03, 0x3d, 0xc8,
+ 0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c, 0x74, 0x70, 0x07, 0x7b,
+ 0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07, 0x7a, 0x70, 0x03, 0x76,
+ 0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11, 0x0e, 0xec, 0x90, 0x0e,
+ 0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0, 0x0e, 0xf0, 0x50, 0x0e,
+ 0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8, 0x21, 0x1d, 0xc2, 0x61,
+ 0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xb4,
+ 0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b, 0xcc, 0xf0, 0x14, 0x76,
+ 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87, 0x72, 0x68, 0x07, 0x37,
+ 0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07, 0x76, 0x28, 0x07, 0x76,
+ 0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87, 0x5f, 0x08, 0x87, 0x71,
+ 0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81, 0x2c, 0xee, 0xf0, 0x0e,
+ 0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30, 0x03, 0x62, 0xc8, 0xa1,
+ 0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xdc, 0x61,
+ 0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca, 0x61, 0x06, 0xd6, 0x90,
+ 0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39, 0xc8, 0x43, 0x39, 0xb8,
+ 0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b, 0x94, 0xc3, 0x2f, 0xbc,
+ 0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b, 0xb0, 0xc3, 0x0c, 0xc7,
+ 0x69, 0x87, 0x70, 0x58, 0x87, 0x72, 0x70, 0x83, 0x74, 0x68, 0x07, 0x78,
+ 0x60, 0x87, 0x74, 0x18, 0x87, 0x74, 0xa0, 0x87, 0x19, 0xce, 0x53, 0x0f,
+ 0xee, 0x00, 0x0f, 0xf2, 0x50, 0x0e, 0xe4, 0x90, 0x0e, 0xe3, 0x40, 0x0f,
+ 0xe1, 0x20, 0x0e, 0xec, 0x50, 0x0e, 0x33, 0x20, 0x28, 0x1d, 0xdc, 0xc1,
+ 0x1e, 0xc2, 0x41, 0x1e, 0xd2, 0x21, 0x1c, 0xdc, 0x81, 0x1e, 0xdc, 0xe0,
+ 0x1c, 0xe4, 0xe1, 0x1d, 0xea, 0x01, 0x1e, 0x66, 0x18, 0x51, 0x38, 0xb0,
+ 0x43, 0x3a, 0x9c, 0x83, 0x3b, 0xcc, 0x50, 0x24, 0x76, 0x60, 0x07, 0x7b,
+ 0x68, 0x07, 0x37, 0x60, 0x87, 0x77, 0x78, 0x07, 0x78, 0x98, 0x51, 0x4c,
+ 0xf4, 0x90, 0x0f, 0xf0, 0x50, 0x0e, 0x00, 0x00, 0x71, 0x20, 0x00, 0x00,
+ 0x05, 0x00, 0x00, 0x00, 0x06, 0x20, 0xb1, 0x5d, 0xf9, 0xb3, 0xce, 0x82,
+ 0x0c, 0x7f, 0x11, 0x01, 0x06, 0x43, 0x34, 0x13, 0x00, 0x00, 0x00, 0x00,
+ 0x61, 0x20, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x13, 0x04, 0x01, 0x05,
+ 0x25, 0x83, 0x80, 0x18, 0x02, 0x00, 0x00, 0x00, 0x5b, 0x06, 0x20, 0x08,
+ 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xde, 0xc0, 0x17, 0x0b, 0x00, 0x00, 0x00, 0x00,
+ 0x14, 0x00, 0x00, 0x00, 0x68, 0x0a, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+ 0x42, 0x43, 0xc0, 0xde, 0x21, 0x0c, 0x00, 0x00, 0x97, 0x02, 0x00, 0x00,
+ 0x0b, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00,
+ 0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39,
+ 0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19, 0x1e, 0x04, 0x8b, 0x62,
+ 0x80, 0x14, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42, 0xa4, 0x10, 0x32, 0x14,
+ 0x38, 0x08, 0x18, 0x49, 0x0a, 0x32, 0x44, 0x24, 0x48, 0x0a, 0x90, 0x21,
+ 0x23, 0xc4, 0x52, 0x80, 0x0c, 0x19, 0x21, 0x72, 0x24, 0x07, 0xc8, 0x48,
+ 0x11, 0x62, 0xa8, 0xa0, 0xa8, 0x40, 0xc6, 0xf0, 0x01, 0x00, 0x00, 0x00,
+ 0x51, 0x18, 0x00, 0x00, 0x89, 0x00, 0x00, 0x00, 0x1b, 0x8c, 0x60, 0x00,
+ 0x16, 0xa0, 0xda, 0x60, 0x08, 0x05, 0xb0, 0x00, 0xd5, 0x06, 0x73, 0x19,
+ 0xfe, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x18, 0x40, 0x02, 0x2a, 0x62, 0x1c,
+ 0xde, 0x41, 0x1e, 0xe4, 0xa1, 0x1c, 0xc6, 0x81, 0x1e, 0xd8, 0x21, 0x1f,
+ 0xda, 0x40, 0x1e, 0xde, 0xa1, 0x1e, 0xdc, 0x81, 0x1c, 0xca, 0x81, 0x1c,
+ 0xda, 0x80, 0x1c, 0xd2, 0xc1, 0x1e, 0xd2, 0x81, 0x1c, 0xca, 0xa1, 0x0d,
+ 0xe6, 0x21, 0x1e, 0xe4, 0x81, 0x1e, 0xda, 0xc0, 0x1c, 0xe0, 0xa1, 0x0d,
+ 0xda, 0x21, 0x1c, 0xe8, 0x01, 0x1d, 0x00, 0x73, 0x08, 0x07, 0x76, 0x98,
+ 0x87, 0x72, 0x00, 0x08, 0x72, 0x48, 0x87, 0x79, 0x08, 0x07, 0x71, 0x60,
+ 0x87, 0x72, 0x68, 0x03, 0x7a, 0x08, 0x87, 0x74, 0x60, 0x87, 0x36, 0x18,
+ 0x87, 0x70, 0x60, 0x07, 0x76, 0x98, 0x07, 0xc0, 0x1c, 0xc2, 0x81, 0x1d,
+ 0xe6, 0xa1, 0x1c, 0x00, 0x82, 0x1d, 0xca, 0x61, 0x1e, 0xe6, 0xa1, 0x0d,
+ 0xe0, 0x41, 0x1e, 0xca, 0x61, 0x1c, 0xd2, 0x61, 0x1e, 0xca, 0xa1, 0x0d,
+ 0xcc, 0x01, 0x1e, 0xda, 0x21, 0x1c, 0xc8, 0x01, 0xa0, 0x07, 0x79, 0xa8,
+ 0x87, 0x72, 0x00, 0x08, 0x77, 0x78, 0x87, 0x36, 0x30, 0x07, 0x79, 0x08,
+ 0x87, 0x76, 0x28, 0x87, 0x36, 0x80, 0x87, 0x77, 0x48, 0x07, 0x77, 0xa0,
+ 0x87, 0x72, 0x90, 0x87, 0x36, 0x28, 0x07, 0x76, 0x48, 0x87, 0x76, 0x00,
+ 0xe8, 0x41, 0x1e, 0xea, 0xa1, 0x1c, 0x80, 0xc1, 0x1d, 0xde, 0xa1, 0x0d,
+ 0xcc, 0x41, 0x1e, 0xc2, 0xa1, 0x1d, 0xca, 0xa1, 0x0d, 0xe0, 0xe1, 0x1d,
+ 0xd2, 0xc1, 0x1d, 0xe8, 0xa1, 0x1c, 0xe4, 0xa1, 0x0d, 0xca, 0x81, 0x1d,
+ 0xd2, 0xa1, 0x1d, 0xda, 0xc0, 0x1d, 0xde, 0xc1, 0x1d, 0xda, 0x80, 0x1d,
+ 0xca, 0x21, 0x1c, 0xcc, 0x01, 0x20, 0xdc, 0xe1, 0x1d, 0xda, 0x20, 0x1d,
+ 0xdc, 0xc1, 0x1c, 0xe6, 0xa1, 0x0d, 0xcc, 0x01, 0x1e, 0xda, 0xa0, 0x1d,
+ 0xc2, 0x81, 0x1e, 0xd0, 0x01, 0xa0, 0x07, 0x79, 0xa8, 0x87, 0x72, 0x00,
+ 0x08, 0x77, 0x78, 0x87, 0x36, 0x50, 0x87, 0x7a, 0x68, 0x07, 0x78, 0x68,
+ 0x03, 0x7a, 0x08, 0x07, 0x71, 0x60, 0x87, 0x72, 0x98, 0x07, 0xc0, 0x1c,
+ 0xc2, 0x81, 0x1d, 0xe6, 0xa1, 0x1c, 0x00, 0xc2, 0x1d, 0xde, 0xa1, 0x0d,
+ 0xdc, 0x21, 0x1c, 0xdc, 0x61, 0x1e, 0xda, 0xc0, 0x1c, 0xe0, 0xa1, 0x0d,
+ 0xda, 0x21, 0x1c, 0xe8, 0x01, 0x1d, 0x00, 0x7a, 0x90, 0x87, 0x7a, 0x28,
+ 0x07, 0x80, 0x70, 0x87, 0x77, 0x68, 0x83, 0x79, 0x48, 0x87, 0x73, 0x70,
+ 0x87, 0x72, 0x20, 0x87, 0x36, 0xd0, 0x87, 0x72, 0x90, 0x87, 0x77, 0x98,
+ 0x87, 0x36, 0x30, 0x07, 0x78, 0x68, 0x83, 0x76, 0x08, 0x07, 0x7a, 0x40,
+ 0x07, 0xc0, 0x1c, 0xc2, 0x81, 0x1d, 0xe6, 0xa1, 0x1c, 0x00, 0x62, 0x1e,
+ 0xe8, 0x21, 0x1c, 0xc6, 0x61, 0x1d, 0xda, 0x00, 0x1e, 0xe4, 0xe1, 0x1d,
+ 0xe8, 0xa1, 0x1c, 0xc6, 0x81, 0x1e, 0xde, 0x41, 0x1e, 0xda, 0x40, 0x1c,
+ 0xea, 0xc1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4, 0xa1, 0x0d, 0xe6, 0x21, 0x1d,
+ 0xf4, 0xa1, 0x1c, 0x00, 0x3c, 0x00, 0x08, 0x7a, 0x08, 0x07, 0x79, 0x38,
+ 0x87, 0x72, 0xa0, 0x87, 0x36, 0x30, 0x87, 0x72, 0x08, 0x07, 0x7a, 0xa8,
+ 0x07, 0x79, 0x28, 0x87, 0x79, 0x00, 0xda, 0xc0, 0x1c, 0xe0, 0x21, 0x0e,
+ 0xec, 0x00, 0x20, 0xea, 0xc1, 0x1d, 0xe6, 0x21, 0x1c, 0xcc, 0xa1, 0x1c,
+ 0xda, 0xc0, 0x1c, 0xe0, 0xa1, 0x0d, 0xda, 0x21, 0x1c, 0xe8, 0x01, 0x1d,
+ 0x00, 0x7a, 0x90, 0x87, 0x7a, 0x28, 0x07, 0x80, 0xa8, 0x87, 0x79, 0x28,
+ 0x87, 0x36, 0x98, 0x87, 0x77, 0x30, 0x07, 0x7a, 0x68, 0x03, 0x73, 0x60,
+ 0x87, 0x77, 0x08, 0x07, 0x7a, 0x00, 0xcc, 0x21, 0x1c, 0xd8, 0x61, 0x1e,
+ 0xca, 0x01, 0xd8, 0x40, 0x10, 0x01, 0xb0, 0x6c, 0x20, 0x0a, 0x01, 0x58,
+ 0x36, 0x20, 0xc6, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x03, 0x48, 0x40,
+ 0x05, 0x00, 0x00, 0x00, 0x49, 0x18, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
+ 0x13, 0x86, 0x40, 0x18, 0x26, 0x0c, 0x44, 0x61, 0x00, 0x00, 0x00, 0x00,
+ 0x89, 0x20, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09,
+ 0x20, 0x64, 0x85, 0x04, 0x93, 0x22, 0xa4, 0x84, 0x04, 0x93, 0x22, 0xe3,
+ 0x84, 0xa1, 0x90, 0x14, 0x12, 0x4c, 0x8a, 0x8c, 0x0b, 0x84, 0xa4, 0x4c,
+ 0x10, 0x48, 0x33, 0x00, 0xc3, 0x08, 0x04, 0x30, 0x8c, 0x20, 0x00, 0x83,
+ 0x08, 0x81, 0x70, 0x94, 0x34, 0x45, 0x94, 0x30, 0xf9, 0xff, 0x44, 0x5c,
+ 0x13, 0x15, 0x11, 0xbf, 0x3d, 0xfc, 0xd3, 0x18, 0x01, 0x30, 0x88, 0x40,
+ 0x04, 0x17, 0x49, 0x53, 0x44, 0x09, 0x93, 0xff, 0x4b, 0x00, 0xf3, 0x2c,
+ 0x44, 0xf4, 0x4f, 0x63, 0x04, 0xc0, 0x20, 0x82, 0x21, 0x14, 0x23, 0x04,
+ 0x31, 0xca, 0x21, 0x34, 0x47, 0x10, 0xcc, 0x11, 0x80, 0xc1, 0x30, 0x82,
+ 0xb0, 0x14, 0x24, 0x94, 0x23, 0x14, 0x53, 0x80, 0xda, 0x40, 0xc0, 0x1c,
+ 0x01, 0x28, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0xb2, 0x70, 0x48,
+ 0x07, 0x79, 0xb0, 0x03, 0x3a, 0x68, 0x83, 0x70, 0x80, 0x07, 0x78, 0x60,
+ 0x87, 0x72, 0x68, 0x83, 0x76, 0x08, 0x87, 0x71, 0x78, 0x87, 0x79, 0xc0,
+ 0x87, 0x38, 0x80, 0x03, 0x37, 0x88, 0x83, 0x38, 0x70, 0x03, 0x38, 0xd8,
+ 0xf0, 0x1e, 0xe5, 0xd0, 0x06, 0xf0, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a,
+ 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x90, 0x0e, 0x71,
+ 0xa0, 0x07, 0x78, 0xa0, 0x07, 0x78, 0xd0, 0x06, 0xe9, 0x80, 0x07, 0x7a,
+ 0x80, 0x07, 0x7a, 0x80, 0x07, 0x6d, 0x90, 0x0e, 0x71, 0x60, 0x07, 0x7a,
+ 0x10, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x60, 0x07, 0x6d, 0x90, 0x0e, 0x73,
+ 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d,
+ 0x90, 0x0e, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76,
+ 0x40, 0x07, 0x6d, 0x60, 0x0e, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72,
+ 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0e, 0x76, 0x40, 0x07, 0x7a,
+ 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x60, 0x0e, 0x78,
+ 0x00, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72,
+ 0x80, 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x60, 0x07, 0x7a, 0x10, 0x07, 0x76,
+ 0xa0, 0x07, 0x71, 0x60, 0x07, 0x6d, 0x60, 0x0f, 0x72, 0x40, 0x07, 0x7a,
+ 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0f, 0x73,
+ 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d,
+ 0x60, 0x0f, 0x74, 0x80, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76,
+ 0x40, 0x07, 0x6d, 0x60, 0x0f, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74,
+ 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x60, 0x0f, 0x79, 0x60, 0x07, 0x7a,
+ 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d,
+ 0x60, 0x0f, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78,
+ 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0, 0x06, 0xf6, 0x10, 0x07, 0x79,
+ 0x20, 0x07, 0x7a, 0x20, 0x07, 0x75, 0x60, 0x07, 0x7a, 0x20, 0x07, 0x75,
+ 0x60, 0x07, 0x6d, 0x60, 0x0f, 0x72, 0x50, 0x07, 0x76, 0xa0, 0x07, 0x72,
+ 0x50, 0x07, 0x76, 0xa0, 0x07, 0x72, 0x50, 0x07, 0x76, 0xd0, 0x06, 0xf6,
+ 0x50, 0x07, 0x71, 0x20, 0x07, 0x7a, 0x50, 0x07, 0x71, 0x20, 0x07, 0x7a,
+ 0x50, 0x07, 0x71, 0x20, 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x00, 0x07, 0x72,
+ 0x40, 0x07, 0x7a, 0x10, 0x07, 0x70, 0x20, 0x07, 0x74, 0xa0, 0x07, 0x71,
+ 0x00, 0x07, 0x72, 0x40, 0x07, 0x6d, 0x60, 0x0e, 0x78, 0x00, 0x07, 0x7a,
+ 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d,
+ 0xe0, 0x0e, 0x78, 0xa0, 0x07, 0x71, 0x60, 0x07, 0x7a, 0x30, 0x07, 0x72,
+ 0x30, 0x84, 0x49, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
+ 0xc2, 0x38, 0x40, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x81,
+ 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x10,
+ 0x19, 0x11, 0x4c, 0x90, 0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0x5a,
+ 0x25, 0x30, 0x02, 0x50, 0x20, 0x05, 0x51, 0x04, 0x65, 0x50, 0x08, 0x04,
+ 0x47, 0x00, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00,
+ 0x1a, 0x03, 0x4c, 0x10, 0xd7, 0x20, 0x08, 0x0e, 0x8e, 0xad, 0x0c, 0x84,
+ 0x89, 0xc9, 0xaa, 0x09, 0xc4, 0xae, 0x4c, 0x6e, 0x2e, 0xed, 0xcd, 0x0d,
+ 0x04, 0x07, 0x46, 0xc6, 0x25, 0x06, 0x04, 0xa5, 0xad, 0x8c, 0x2e, 0x8c,
+ 0xcd, 0xac, 0xac, 0x05, 0x07, 0x46, 0xc6, 0x25, 0xc6, 0x65, 0x86, 0x26,
+ 0x65, 0x88, 0xf0, 0x00, 0x43, 0x8c, 0x45, 0x58, 0x8a, 0x65, 0x60, 0xd1,
+ 0x54, 0x46, 0x17, 0xc6, 0x36, 0x04, 0x79, 0x86, 0x45, 0x58, 0x84, 0x65,
+ 0xe0, 0x16, 0x96, 0x26, 0xe7, 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56,
+ 0xe6, 0x42, 0x56, 0xe6, 0xf6, 0x26, 0xd7, 0x36, 0xf7, 0x45, 0x96, 0x36,
+ 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0x78, 0x0a, 0x72, 0x61, 0x69, 0x72,
+ 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x2e, 0x66, 0x61, 0x73,
+ 0x74, 0x5f, 0x6d, 0x61, 0x74, 0x68, 0x5f, 0x65, 0x6e, 0x61, 0x62, 0x6c,
+ 0x65, 0x43, 0x84, 0xe7, 0x60, 0x19, 0x84, 0xa5, 0xc9, 0xb9, 0x8c, 0xbd,
+ 0xb5, 0xc1, 0xa5, 0xb1, 0x95, 0xb9, 0x98, 0xc9, 0x85, 0xb5, 0x95, 0x89,
+ 0xd5, 0x99, 0x99, 0x95, 0xc9, 0x7d, 0x99, 0x95, 0xd1, 0x8d, 0xa1, 0x7d,
+ 0x91, 0xa5, 0xcd, 0x85, 0x89, 0xb1, 0x95, 0x0d, 0x11, 0x9e, 0x84, 0x61,
+ 0x10, 0x96, 0x26, 0xe7, 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56, 0xe6,
+ 0xe2, 0x16, 0x46, 0x97, 0x66, 0x57, 0xf6, 0x45, 0xf6, 0x56, 0x27, 0xc6,
+ 0x56, 0xf6, 0x45, 0x96, 0x36, 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0x78,
+ 0x16, 0x46, 0x61, 0x69, 0x72, 0x2e, 0x72, 0x65, 0x6e, 0x64, 0x65, 0x72,
+ 0x5f, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x8c, 0xc2, 0xd2, 0xe4, 0x5c,
+ 0xc2, 0xe4, 0xce, 0xbe, 0xe8, 0xf2, 0xe0, 0xca, 0xbe, 0xdc, 0xc2, 0xda,
+ 0xca, 0x68, 0x98, 0xb1, 0xbd, 0x85, 0xd1, 0xd1, 0x0c, 0x41, 0x9e, 0x66,
+ 0x19, 0x1e, 0xe7, 0x79, 0x86, 0x08, 0x0f, 0x44, 0x26, 0x2c, 0x4d, 0xce,
+ 0x05, 0xee, 0x6d, 0x2e, 0x8d, 0x2e, 0xed, 0xcd, 0x8d, 0x4a, 0x58, 0x9a,
+ 0x9c, 0xcb, 0x58, 0x99, 0x1b, 0x5d, 0x99, 0x1c, 0xa5, 0xb0, 0x34, 0x39,
+ 0x17, 0xb7, 0xb7, 0x2f, 0xb8, 0x32, 0xb9, 0x39, 0xb8, 0xb2, 0x31, 0xba,
+ 0x34, 0xbb, 0x32, 0x32, 0x61, 0x69, 0x72, 0x2e, 0x61, 0x72, 0x67, 0x5f,
+ 0x6e, 0x61, 0x6d, 0x65, 0x44, 0xe0, 0xde, 0xe6, 0xd2, 0xe8, 0xd2, 0xde,
+ 0xdc, 0x86, 0x40, 0xcb, 0xf0, 0x48, 0xcf, 0xf4, 0x50, 0x8f, 0xf3, 0x3c,
+ 0x4f, 0xf5, 0x58, 0x94, 0xc2, 0xd2, 0xe4, 0x5c, 0xcc, 0xe4, 0xc2, 0xce,
+ 0xda, 0xca, 0xdc, 0xe8, 0xbe, 0xd2, 0xdc, 0xe0, 0xea, 0xe8, 0x98, 0x9d,
+ 0x95, 0xb9, 0x95, 0xc9, 0x85, 0xd1, 0x95, 0x91, 0xa1, 0xe0, 0xd0, 0x95,
+ 0xe1, 0x8d, 0xbd, 0xbd, 0xc9, 0x91, 0x11, 0xd9, 0xc9, 0x7c, 0x99, 0xa5,
+ 0xf0, 0x09, 0x4b, 0x93, 0x73, 0x81, 0x2b, 0x93, 0x9b, 0x83, 0x2b, 0x1b,
+ 0xa3, 0x4b, 0xb3, 0x2b, 0xa3, 0x61, 0xc6, 0xf6, 0x16, 0x46, 0x27, 0x43,
+ 0x84, 0xae, 0x0c, 0x6f, 0xec, 0xed, 0x4d, 0x8e, 0x6c, 0x88, 0xb4, 0x08,
+ 0x0f, 0xf6, 0x64, 0xcf, 0xf4, 0x68, 0x8f, 0xf3, 0x6c, 0x4f, 0xf5, 0x70,
+ 0x54, 0xc2, 0xd2, 0xe4, 0x5c, 0xc4, 0xea, 0xcc, 0xcc, 0xca, 0xe4, 0xf8,
+ 0x84, 0xa5, 0xc9, 0xb9, 0x88, 0xd5, 0x99, 0x99, 0x95, 0xc9, 0x7d, 0xcd,
+ 0xa5, 0xe9, 0x95, 0x51, 0x0a, 0x4b, 0x93, 0x73, 0x61, 0x7b, 0x1b, 0x0b,
+ 0xa3, 0x4b, 0x7b, 0x73, 0xfb, 0x4a, 0x73, 0x23, 0x2b, 0xc3, 0x23, 0x12,
+ 0x96, 0x26, 0xe7, 0x22, 0x57, 0x16, 0x46, 0xc6, 0x28, 0x2c, 0x4d, 0xce,
+ 0x25, 0x4c, 0xee, 0xec, 0x8b, 0x2e, 0x0f, 0xae, 0xec, 0x6b, 0x2e, 0x4d,
+ 0xaf, 0x8c, 0x57, 0x58, 0x9a, 0x9c, 0x4b, 0x98, 0xdc, 0xd9, 0x17, 0x5d,
+ 0x1e, 0x5c, 0xd9, 0x57, 0x18, 0x5b, 0xda, 0x99, 0xdb, 0xd7, 0x5c, 0x9a,
+ 0x5e, 0x19, 0x87, 0xb1, 0x37, 0xb6, 0x21, 0x60, 0xb0, 0x18, 0x8f, 0xf7,
+ 0x7c, 0x0b, 0xf1, 0x80, 0xc1, 0x32, 0x2c, 0xc2, 0x13, 0x06, 0x8f, 0x18,
+ 0x2c, 0xc4, 0x33, 0x06, 0x0b, 0xf1, 0x38, 0xcf, 0xf3, 0x54, 0x0f, 0x19,
+ 0x70, 0x09, 0x4b, 0x93, 0x73, 0xa1, 0x2b, 0xc3, 0xa3, 0xab, 0x93, 0x2b,
+ 0xa3, 0x12, 0x96, 0x26, 0xe7, 0x32, 0x17, 0xd6, 0x06, 0xc7, 0x56, 0x46,
+ 0x8c, 0xae, 0x0c, 0x8f, 0xae, 0x4e, 0xae, 0x4c, 0x86, 0x8c, 0xc7, 0x8c,
+ 0xed, 0x2d, 0x8c, 0x8e, 0x05, 0x64, 0x2e, 0xac, 0x0d, 0x8e, 0xad, 0xcc,
+ 0x87, 0x03, 0x5d, 0x19, 0xde, 0x10, 0x6a, 0x39, 0x1e, 0x33, 0x78, 0xc0,
+ 0x60, 0x19, 0x16, 0xe1, 0x39, 0x83, 0xc7, 0x79, 0xd0, 0xe0, 0xa9, 0x9e,
+ 0x34, 0xe0, 0x12, 0x96, 0x26, 0xe7, 0x32, 0x17, 0xd6, 0x06, 0xc7, 0x56,
+ 0x26, 0xc7, 0x63, 0x2e, 0xac, 0x0d, 0x8e, 0xad, 0x4c, 0x8e, 0xc1, 0xdc,
+ 0x10, 0x69, 0x41, 0x9e, 0x35, 0x78, 0xc0, 0x60, 0x19, 0x16, 0xe1, 0x71,
+ 0x1e, 0x36, 0x78, 0xaa, 0xa7, 0x0d, 0x86, 0x28, 0xcf, 0xf5, 0x74, 0x4f,
+ 0x19, 0x3c, 0x6a, 0xf0, 0xb8, 0xc1, 0x10, 0x23, 0x01, 0x9e, 0xe8, 0x79,
+ 0x03, 0x3e, 0x6f, 0x6d, 0x6e, 0x69, 0x70, 0x6f, 0x74, 0x65, 0x6e, 0x74,
+ 0x20, 0x63, 0x68, 0x61, 0x72, 0x7c, 0xa6, 0xd2, 0xda, 0xe0, 0xd8, 0xca,
+ 0x40, 0x86, 0x56, 0x56, 0x40, 0xa8, 0x84, 0x82, 0x82, 0x86, 0x08, 0x8f,
+ 0x1c, 0x0c, 0x31, 0x9e, 0x38, 0x78, 0xe6, 0x00, 0x4a, 0x86, 0x18, 0x0f,
+ 0x1d, 0x3c, 0x74, 0x00, 0x25, 0x23, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68,
+ 0x07, 0x37, 0x48, 0x07, 0x72, 0x28, 0x07, 0x77, 0xa0, 0x87, 0x29, 0x41,
+ 0x30, 0x62, 0x09, 0x87, 0x74, 0x90, 0x07, 0x37, 0xb0, 0x87, 0x72, 0x90,
+ 0x87, 0x79, 0x48, 0x87, 0x77, 0x70, 0x87, 0x29, 0x81, 0x30, 0x82, 0x0a,
+ 0x87, 0x74, 0x90, 0x07, 0x37, 0x60, 0x87, 0x70, 0x70, 0x87, 0x73, 0xa8,
+ 0x87, 0x70, 0x38, 0x87, 0x72, 0xf8, 0x05, 0x7b, 0x28, 0x07, 0x79, 0x98,
+ 0x87, 0x74, 0x78, 0x07, 0x77, 0x98, 0x12, 0x10, 0x23, 0xa6, 0x70, 0x48,
+ 0x07, 0x79, 0x70, 0x83, 0x71, 0x78, 0x87, 0x76, 0x80, 0x87, 0x74, 0x60,
+ 0x87, 0x72, 0xf8, 0x85, 0x77, 0x80, 0x07, 0x7a, 0x48, 0x87, 0x77, 0x70,
+ 0x87, 0x79, 0x98, 0x42, 0x18, 0x88, 0xc2, 0x8c, 0x60, 0xc2, 0x21, 0x1d,
+ 0xe4, 0xc1, 0x0d, 0xcc, 0x41, 0x1e, 0xc2, 0xe1, 0x1c, 0xda, 0xa1, 0x1c,
+ 0xdc, 0x81, 0x1e, 0xa6, 0x04, 0x70, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
+ 0x5c, 0x00, 0x00, 0x00, 0x33, 0x08, 0x80, 0x1c, 0xc4, 0xe1, 0x1c, 0x66,
+ 0x14, 0x01, 0x3d, 0x88, 0x43, 0x38, 0x84, 0xc3, 0x8c, 0x42, 0x80, 0x07,
+ 0x79, 0x78, 0x07, 0x73, 0x98, 0x71, 0x0c, 0xe6, 0x00, 0x0f, 0xed, 0x10,
+ 0x0e, 0xf4, 0x80, 0x0e, 0x33, 0x0c, 0x42, 0x1e, 0xc2, 0xc1, 0x1d, 0xce,
+ 0xa1, 0x1c, 0x66, 0x30, 0x05, 0x3d, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1b,
+ 0xcc, 0x03, 0x3d, 0xc8, 0x43, 0x3d, 0x8c, 0x03, 0x3d, 0xcc, 0x78, 0x8c,
+ 0x74, 0x70, 0x07, 0x7b, 0x08, 0x07, 0x79, 0x48, 0x87, 0x70, 0x70, 0x07,
+ 0x7a, 0x70, 0x03, 0x76, 0x78, 0x87, 0x70, 0x20, 0x87, 0x19, 0xcc, 0x11,
+ 0x0e, 0xec, 0x90, 0x0e, 0xe1, 0x30, 0x0f, 0x6e, 0x30, 0x0f, 0xe3, 0xf0,
+ 0x0e, 0xf0, 0x50, 0x0e, 0x33, 0x10, 0xc4, 0x1d, 0xde, 0x21, 0x1c, 0xd8,
+ 0x21, 0x1d, 0xc2, 0x61, 0x1e, 0x66, 0x30, 0x89, 0x3b, 0xbc, 0x83, 0x3b,
+ 0xd0, 0x43, 0x39, 0xb4, 0x03, 0x3c, 0xbc, 0x83, 0x3c, 0x84, 0x03, 0x3b,
+ 0xcc, 0xf0, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x68, 0x87,
+ 0x72, 0x68, 0x07, 0x37, 0x80, 0x87, 0x70, 0x90, 0x87, 0x70, 0x60, 0x07,
+ 0x76, 0x28, 0x07, 0x76, 0xf8, 0x05, 0x76, 0x78, 0x87, 0x77, 0x80, 0x87,
+ 0x5f, 0x08, 0x87, 0x71, 0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98, 0x81,
+ 0x2c, 0xee, 0xf0, 0x0e, 0xee, 0xe0, 0x0e, 0xf5, 0xc0, 0x0e, 0xec, 0x30,
+ 0x03, 0x62, 0xc8, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xcc, 0xa1, 0x1c, 0xe4,
+ 0xa1, 0x1c, 0xdc, 0x61, 0x1c, 0xca, 0x21, 0x1c, 0xc4, 0x81, 0x1d, 0xca,
+ 0x61, 0x06, 0xd6, 0x90, 0x43, 0x39, 0xc8, 0x43, 0x39, 0x98, 0x43, 0x39,
+ 0xc8, 0x43, 0x39, 0xb8, 0xc3, 0x38, 0x94, 0x43, 0x38, 0x88, 0x03, 0x3b,
+ 0x94, 0xc3, 0x2f, 0xbc, 0x83, 0x3c, 0xfc, 0x82, 0x3b, 0xd4, 0x03, 0x3b,
+ 0xb0, 0xc3, 0x0c, 0xc7, 0x69, 0x87, 0x70, 0x58, 0x87, 0x72, 0x70, 0x83,
+ 0x74, 0x68, 0x07, 0x78, 0x60, 0x87, 0x74, 0x18, 0x87, 0x74, 0xa0, 0x87,
+ 0x19, 0xce, 0x53, 0x0f, 0xee, 0x00, 0x0f, 0xf2, 0x50, 0x0e, 0xe4, 0x90,
+ 0x0e, 0xe3, 0x40, 0x0f, 0xe1, 0x20, 0x0e, 0xec, 0x50, 0x0e, 0x33, 0x20,
+ 0x28, 0x1d, 0xdc, 0xc1, 0x1e, 0xc2, 0x41, 0x1e, 0xd2, 0x21, 0x1c, 0xdc,
+ 0x81, 0x1e, 0xdc, 0xe0, 0x1c, 0xe4, 0xe1, 0x1d, 0xea, 0x01, 0x1e, 0x66,
+ 0x18, 0x51, 0x38, 0xb0, 0x43, 0x3a, 0x9c, 0x83, 0x3b, 0xcc, 0x50, 0x24,
+ 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x60, 0x87, 0x77, 0x78, 0x07,
+ 0x78, 0x98, 0x51, 0x4c, 0xf4, 0x90, 0x0f, 0xf0, 0x50, 0x0e, 0x00, 0x00,
+ 0x71, 0x20, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x06, 0x10, 0xb1, 0x5d,
+ 0xf9, 0x73, 0xce, 0x83, 0xfd, 0x45, 0x04, 0x18, 0x0c, 0xd1, 0x4c, 0x16,
+ 0xb0, 0x01, 0x48, 0xe4, 0x4b, 0x00, 0xf3, 0x2c, 0xc4, 0x3f, 0x11, 0xd7,
+ 0x44, 0x45, 0xc4, 0x6f, 0x0f, 0x7e, 0x85, 0x17, 0xb7, 0x0d, 0x00, 0x00,
+ 0x61, 0x20, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x13, 0x04, 0x41, 0x2c,
+ 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xc4, 0x46, 0x00, 0x48,
+ 0xd5, 0xc0, 0x08, 0x00, 0x81, 0x11, 0x00, 0x00, 0x23, 0x06, 0x8a, 0x10,
+ 0x48, 0x46, 0x81, 0x0c, 0x84, 0x10, 0x10, 0x52, 0x2c, 0x10, 0xe4, 0x93,
+ 0x41, 0x40, 0x0c, 0x00, 0x02, 0x00, 0x00, 0x00, 0x5b, 0x86, 0x20, 0xa8,
+ 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xde, 0xc0, 0x17, 0x0b, 0x00, 0x00, 0x00, 0x00,
+ 0x14, 0x00, 0x00, 0x00, 0x74, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
+ 0x42, 0x43, 0xc0, 0xde, 0x21, 0x0c, 0x00, 0x00, 0x9a, 0x03, 0x00, 0x00,
+ 0x0b, 0x82, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00,
+ 0x07, 0x81, 0x23, 0x91, 0x41, 0xc8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39,
+ 0x92, 0x01, 0x84, 0x0c, 0x25, 0x05, 0x08, 0x19, 0x1e, 0x04, 0x8b, 0x62,
+ 0x80, 0x14, 0x45, 0x02, 0x42, 0x92, 0x0b, 0x42, 0xa4, 0x10, 0x32, 0x14,
+ 0x38, 0x08, 0x18, 0x49, 0x0a, 0x32, 0x44, 0x24, 0x48, 0x0a, 0x90, 0x21,
+ 0x23, 0xc4, 0x52, 0x80, 0x0c, 0x19, 0x21, 0x72, 0x24, 0x07, 0xc8, 0x48,
+ 0x11, 0x62, 0xa8, 0xa0, 0xa8, 0x40, 0xc6, 0xf0, 0x01, 0x00, 0x00, 0x00,
+ 0x51, 0x18, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x1b, 0x8c, 0x60, 0x00,
+ 0x16, 0xa0, 0xda, 0x60, 0x08, 0x04, 0xb0, 0x00, 0xd5, 0x06, 0x63, 0x38,
+ 0x80, 0x05, 0xa8, 0x36, 0x90, 0x0b, 0xf1, 0xff, 0xff, 0xff, 0xff, 0x03,
+ 0xc0, 0x00, 0x12, 0x31, 0x0e, 0xef, 0x20, 0x0f, 0xf2, 0x50, 0x0e, 0xe3,
+ 0x40, 0x0f, 0xec, 0x90, 0x0f, 0x6d, 0x20, 0x0f, 0xef, 0x50, 0x0f, 0xee,
+ 0x40, 0x0e, 0xe5, 0x40, 0x0e, 0x6d, 0x40, 0x0e, 0xe9, 0x60, 0x0f, 0xe9,
+ 0x40, 0x0e, 0xe5, 0xd0, 0x06, 0xf3, 0x10, 0x0f, 0xf2, 0x40, 0x0f, 0x6d,
+ 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x80,
+ 0x39, 0x84, 0x03, 0x3b, 0xcc, 0x43, 0x39, 0x00, 0x04, 0x39, 0xa4, 0xc3,
+ 0x3c, 0x84, 0x83, 0x38, 0xb0, 0x43, 0x39, 0xb4, 0x01, 0x3d, 0x84, 0x43,
+ 0x3a, 0xb0, 0x43, 0x1b, 0x8c, 0x43, 0x38, 0xb0, 0x03, 0x3b, 0xcc, 0x03,
+ 0x60, 0x0e, 0xe1, 0xc0, 0x0e, 0xf3, 0x50, 0x0e, 0x00, 0xc1, 0x0e, 0xe5,
+ 0x30, 0x0f, 0xf3, 0xd0, 0x06, 0xf0, 0x20, 0x0f, 0xe5, 0x30, 0x0e, 0xe9,
+ 0x30, 0x0f, 0xe5, 0xd0, 0x06, 0xe6, 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xe4,
+ 0x00, 0xd0, 0x83, 0x3c, 0xd4, 0x43, 0x39, 0x00, 0x84, 0x3b, 0xbc, 0x43,
+ 0x1b, 0x98, 0x83, 0x3c, 0x84, 0x43, 0x3b, 0x94, 0x43, 0x1b, 0xc0, 0xc3,
+ 0x3b, 0xa4, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xc8, 0x43, 0x1b, 0x94, 0x03,
+ 0x3b, 0xa4, 0x43, 0x3b, 0x00, 0xf4, 0x20, 0x0f, 0xf5, 0x50, 0x0e, 0xc0,
+ 0xe0, 0x0e, 0xef, 0xd0, 0x06, 0xe6, 0x20, 0x0f, 0xe1, 0xd0, 0x0e, 0xe5,
+ 0xd0, 0x06, 0xf0, 0xf0, 0x0e, 0xe9, 0xe0, 0x0e, 0xf4, 0x50, 0x0e, 0xf2,
+ 0xd0, 0x06, 0xe5, 0xc0, 0x0e, 0xe9, 0xd0, 0x0e, 0x6d, 0xe0, 0x0e, 0xef,
+ 0xe0, 0x0e, 0x6d, 0xc0, 0x0e, 0xe5, 0x10, 0x0e, 0xe6, 0x00, 0x10, 0xee,
+ 0xf0, 0x0e, 0x6d, 0x90, 0x0e, 0xee, 0x60, 0x0e, 0xf3, 0xd0, 0x06, 0xe6,
+ 0x00, 0x0f, 0x6d, 0xd0, 0x0e, 0xe1, 0x40, 0x0f, 0xe8, 0x00, 0xd0, 0x83,
+ 0x3c, 0xd4, 0x43, 0x39, 0x00, 0x84, 0x3b, 0xbc, 0x43, 0x1b, 0xa8, 0x43,
+ 0x3d, 0xb4, 0x03, 0x3c, 0xb4, 0x01, 0x3d, 0x84, 0x83, 0x38, 0xb0, 0x43,
+ 0x39, 0xcc, 0x03, 0x60, 0x0e, 0xe1, 0xc0, 0x0e, 0xf3, 0x50, 0x0e, 0x00,
+ 0xe1, 0x0e, 0xef, 0xd0, 0x06, 0xee, 0x10, 0x0e, 0xee, 0x30, 0x0f, 0x6d,
+ 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x00,
+ 0x3d, 0xc8, 0x43, 0x3d, 0x94, 0x03, 0x40, 0xb8, 0xc3, 0x3b, 0xb4, 0xc1,
+ 0x3c, 0xa4, 0xc3, 0x39, 0xb8, 0x43, 0x39, 0x90, 0x43, 0x1b, 0xe8, 0x43,
+ 0x39, 0xc8, 0xc3, 0x3b, 0xcc, 0x43, 0x1b, 0x98, 0x03, 0x3c, 0xb4, 0x41,
+ 0x3b, 0x84, 0x03, 0x3d, 0xa0, 0x03, 0x60, 0x0e, 0xe1, 0xc0, 0x0e, 0xf3,
+ 0x50, 0x0e, 0x00, 0x31, 0x0f, 0xf4, 0x10, 0x0e, 0xe3, 0xb0, 0x0e, 0x6d,
+ 0x00, 0x0f, 0xf2, 0xf0, 0x0e, 0xf4, 0x50, 0x0e, 0xe3, 0x40, 0x0f, 0xef,
+ 0x20, 0x0f, 0x6d, 0x20, 0x0e, 0xf5, 0x60, 0x0e, 0xe6, 0x50, 0x0e, 0xf2,
+ 0xd0, 0x06, 0xf3, 0x90, 0x0e, 0xfa, 0x50, 0x0e, 0x00, 0x1e, 0x00, 0x04,
+ 0x3d, 0x84, 0x83, 0x3c, 0x9c, 0x43, 0x39, 0xd0, 0x43, 0x1b, 0x98, 0x43,
+ 0x39, 0x84, 0x03, 0x3d, 0xd4, 0x83, 0x3c, 0x94, 0xc3, 0x3c, 0x00, 0x6d,
+ 0x60, 0x0e, 0xf0, 0x10, 0x07, 0x76, 0x00, 0x10, 0xf5, 0xe0, 0x0e, 0xf3,
+ 0x10, 0x0e, 0xe6, 0x50, 0x0e, 0x6d, 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed,
+ 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x00, 0x3d, 0xc8, 0x43, 0x3d, 0x94, 0x03,
+ 0x40, 0xd4, 0xc3, 0x3c, 0x94, 0x43, 0x1b, 0xcc, 0xc3, 0x3b, 0x98, 0x03,
+ 0x3d, 0xb4, 0x81, 0x39, 0xb0, 0xc3, 0x3b, 0x84, 0x03, 0x3d, 0x00, 0xe6,
+ 0x10, 0x0e, 0xec, 0x30, 0x0f, 0xe5, 0x00, 0x6c, 0x50, 0x95, 0xe2, 0xff,
+ 0xff, 0xff, 0xff, 0x07, 0x62, 0x1c, 0xde, 0x41, 0x1e, 0xe4, 0xa1, 0x1c,
+ 0xc6, 0x81, 0x1e, 0xd8, 0x21, 0x1f, 0xda, 0x40, 0x1e, 0xde, 0xa1, 0x1e,
+ 0xdc, 0x81, 0x1c, 0xca, 0x81, 0x1c, 0xda, 0x80, 0x1c, 0xd2, 0xc1, 0x1e,
+ 0xd2, 0x81, 0x1c, 0xca, 0xa1, 0x0d, 0xe6, 0x21, 0x1e, 0xe4, 0x81, 0x1e,
+ 0xda, 0xc0, 0x1c, 0xe0, 0xa1, 0x0d, 0xda, 0x21, 0x1c, 0xe8, 0x01, 0x1d,
+ 0x00, 0x73, 0x08, 0x07, 0x76, 0x98, 0x87, 0x72, 0x00, 0x08, 0x72, 0x48,
+ 0x87, 0x79, 0x08, 0x07, 0x71, 0x60, 0x87, 0x72, 0x68, 0x03, 0x7a, 0x08,
+ 0x87, 0x74, 0x60, 0x87, 0x36, 0x18, 0x87, 0x70, 0x60, 0x07, 0x76, 0x98,
+ 0x07, 0xc0, 0x1c, 0xc2, 0x81, 0x1d, 0xe6, 0xa1, 0x1c, 0x00, 0x82, 0x1d,
+ 0xca, 0x61, 0x1e, 0xe6, 0xa1, 0x0d, 0xe0, 0x41, 0x1e, 0xca, 0x61, 0x1c,
+ 0xd2, 0x61, 0x1e, 0xca, 0xa1, 0x0d, 0xcc, 0x01, 0x1e, 0xda, 0x21, 0x1c,
+ 0xc8, 0x01, 0xa0, 0x07, 0x79, 0xa8, 0x87, 0x72, 0x00, 0x08, 0x77, 0x78,
+ 0x87, 0x36, 0x30, 0x07, 0x79, 0x08, 0x87, 0x76, 0x28, 0x87, 0x36, 0x80,
+ 0x87, 0x77, 0x48, 0x07, 0x77, 0xa0, 0x87, 0x72, 0x90, 0x87, 0x36, 0x28,
+ 0x07, 0x76, 0x48, 0x87, 0x76, 0x00, 0xe8, 0x41, 0x1e, 0xea, 0xa1, 0x1c,
+ 0x80, 0xc1, 0x1d, 0xde, 0xa1, 0x0d, 0xcc, 0x41, 0x1e, 0xc2, 0xa1, 0x1d,
+ 0xca, 0xa1, 0x0d, 0xe0, 0xe1, 0x1d, 0xd2, 0xc1, 0x1d, 0xe8, 0xa1, 0x1c,
+ 0xe4, 0xa1, 0x0d, 0xca, 0x81, 0x1d, 0xd2, 0xa1, 0x1d, 0xda, 0xc0, 0x1d,
+ 0xde, 0xc1, 0x1d, 0xda, 0x80, 0x1d, 0xca, 0x21, 0x1c, 0xcc, 0x01, 0x20,
+ 0xdc, 0xe1, 0x1d, 0xda, 0x20, 0x1d, 0xdc, 0xc1, 0x1c, 0xe6, 0xa1, 0x0d,
+ 0xcc, 0x01, 0x1e, 0xda, 0xa0, 0x1d, 0xc2, 0x81, 0x1e, 0xd0, 0x01, 0xa0,
+ 0x07, 0x79, 0xa8, 0x87, 0x72, 0x00, 0x08, 0x77, 0x78, 0x87, 0x36, 0x70,
+ 0x87, 0x70, 0x70, 0x87, 0x79, 0x68, 0x03, 0x73, 0x80, 0x87, 0x36, 0x68,
+ 0x87, 0x70, 0xa0, 0x07, 0x74, 0x00, 0xe8, 0x41, 0x1e, 0xea, 0xa1, 0x1c,
+ 0x00, 0xc2, 0x1d, 0xde, 0xa1, 0x0d, 0xe6, 0x21, 0x1d, 0xce, 0xc1, 0x1d,
+ 0xca, 0x81, 0x1c, 0xda, 0x40, 0x1f, 0xca, 0x41, 0x1e, 0xde, 0x61, 0x1e,
+ 0xda, 0xc0, 0x1c, 0xe0, 0xa1, 0x0d, 0xda, 0x21, 0x1c, 0xe8, 0x01, 0x1d,
+ 0x00, 0x73, 0x08, 0x07, 0x76, 0x98, 0x87, 0x72, 0x00, 0x88, 0x79, 0xa0,
+ 0x87, 0x70, 0x18, 0x87, 0x75, 0x68, 0x03, 0x78, 0x90, 0x87, 0x77, 0xa0,
+ 0x87, 0x72, 0x18, 0x07, 0x7a, 0x78, 0x07, 0x79, 0x68, 0x03, 0x71, 0xa8,
+ 0x07, 0x73, 0x30, 0x87, 0x72, 0x90, 0x87, 0x36, 0x98, 0x87, 0x74, 0xd0,
+ 0x87, 0x72, 0x00, 0xf0, 0x00, 0x20, 0xe8, 0x21, 0x1c, 0xe4, 0xe1, 0x1c,
+ 0xca, 0x81, 0x1e, 0xda, 0xc0, 0x1c, 0xca, 0x21, 0x1c, 0xe8, 0xa1, 0x1e,
+ 0xe4, 0xa1, 0x1c, 0xe6, 0x01, 0x68, 0x03, 0x73, 0x80, 0x87, 0x38, 0xb0,
+ 0x03, 0x80, 0xa8, 0x07, 0x77, 0x98, 0x87, 0x70, 0x30, 0x87, 0x72, 0x68,
+ 0x03, 0x73, 0x80, 0x87, 0x36, 0x68, 0x87, 0x70, 0xa0, 0x07, 0x74, 0x00,
+ 0xe8, 0x41, 0x1e, 0xea, 0xa1, 0x1c, 0x00, 0xa2, 0x1e, 0xe6, 0xa1, 0x1c,
+ 0xda, 0x60, 0x1e, 0xde, 0xc1, 0x1c, 0xe8, 0xa1, 0x0d, 0xcc, 0x81, 0x1d,
+ 0xde, 0x21, 0x1c, 0xe8, 0x01, 0x30, 0x87, 0x70, 0x60, 0x87, 0x79, 0x28,
+ 0x07, 0x60, 0x03, 0x61, 0x04, 0xc0, 0xb2, 0x81, 0x38, 0x04, 0x60, 0xd9,
+ 0x80, 0x20, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x0c, 0x20, 0x01, 0xd5,
+ 0x06, 0x22, 0xf9, 0xff, 0xff, 0xff, 0xff, 0x01, 0x90, 0x00, 0x00, 0x00,
+ 0x49, 0x18, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x13, 0x88, 0x40, 0x18,
+ 0x88, 0x09, 0x41, 0x31, 0x61, 0x30, 0x0e, 0x64, 0x42, 0x90, 0x00, 0x00,
+ 0x89, 0x20, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09,
+ 0x20, 0x64, 0x85, 0x04, 0x93, 0x22, 0xa4, 0x84, 0x04, 0x93, 0x22, 0xe3,
+ 0x84, 0xa1, 0x90, 0x14, 0x12, 0x4c, 0x8a, 0x8c, 0x0b, 0x84, 0xa4, 0x4c,
+ 0x10, 0x78, 0x33, 0x00, 0xc3, 0x08, 0x04, 0x30, 0x8c, 0x20, 0x00, 0x83,
+ 0x08, 0x81, 0x30, 0x8c, 0x30, 0x00, 0x07, 0x49, 0x53, 0x44, 0x09, 0x93,
+ 0x2f, 0xbb, 0x6f, 0x47, 0x08, 0xce, 0x40, 0x20, 0x82, 0x10, 0x42, 0x06,
+ 0x11, 0x0a, 0xe1, 0x28, 0x69, 0x8a, 0x28, 0x61, 0xf2, 0xff, 0x89, 0xb8,
+ 0x26, 0x2a, 0x22, 0x7e, 0x7b, 0xf8, 0xa7, 0x31, 0x02, 0x60, 0x10, 0xe1,
+ 0x08, 0x4e, 0x93, 0xa6, 0x88, 0x12, 0x26, 0xff, 0x9f, 0x88, 0x6b, 0xa2,
+ 0x22, 0xe2, 0xb7, 0x87, 0x1f, 0x88, 0x22, 0x00, 0xfb, 0xa7, 0x31, 0x02,
+ 0x60, 0x10, 0x21, 0x09, 0x2e, 0x92, 0xa6, 0x88, 0x12, 0x26, 0xff, 0x97,
+ 0x00, 0xe6, 0x59, 0x88, 0xe8, 0x9f, 0xc6, 0x08, 0x80, 0x41, 0x84, 0x45,
+ 0x28, 0x48, 0x08, 0x62, 0x18, 0xa4, 0x18, 0xb5, 0x32, 0x00, 0x42, 0xe8,
+ 0xcd, 0x11, 0x80, 0xc1, 0x1c, 0x41, 0x30, 0x8c, 0x20, 0x44, 0x25, 0x09,
+ 0x8a, 0x89, 0x28, 0xa7, 0x04, 0x44, 0x0b, 0x12, 0x10, 0x13, 0x72, 0x4a,
+ 0x40, 0x76, 0x20, 0x60, 0x18, 0x61, 0x88, 0x86, 0x11, 0x88, 0x68, 0x8e,
+ 0x00, 0x14, 0x06, 0x11, 0x08, 0x61, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x13, 0xb2, 0x70, 0x48, 0x07, 0x79, 0xb0, 0x03, 0x3a, 0x68, 0x83, 0x70,
+ 0x80, 0x07, 0x78, 0x60, 0x87, 0x72, 0x68, 0x83, 0x76, 0x08, 0x87, 0x71,
+ 0x78, 0x87, 0x79, 0xc0, 0x87, 0x38, 0x80, 0x03, 0x37, 0x88, 0x83, 0x38,
+ 0x70, 0x03, 0x38, 0xd8, 0xf0, 0x1e, 0xe5, 0xd0, 0x06, 0xf0, 0xa0, 0x07,
+ 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07,
+ 0x6d, 0x90, 0x0e, 0x71, 0xa0, 0x07, 0x78, 0xa0, 0x07, 0x78, 0xd0, 0x06,
+ 0xe9, 0x80, 0x07, 0x7a, 0x80, 0x07, 0x7a, 0x80, 0x07, 0x6d, 0x90, 0x0e,
+ 0x71, 0x60, 0x07, 0x7a, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x60, 0x07,
+ 0x6d, 0x90, 0x0e, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07,
+ 0x73, 0x20, 0x07, 0x6d, 0x90, 0x0e, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07,
+ 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x60, 0x0e, 0x73, 0x20, 0x07,
+ 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0e,
+ 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07,
+ 0x6d, 0x60, 0x0e, 0x78, 0x00, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07,
+ 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x60, 0x07,
+ 0x7a, 0x10, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x60, 0x07, 0x6d, 0x60, 0x0f,
+ 0x72, 0x40, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07,
+ 0x6d, 0x60, 0x0f, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07,
+ 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0f, 0x74, 0x80, 0x07, 0x7a, 0x60, 0x07,
+ 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x60, 0x0f, 0x76, 0x40, 0x07,
+ 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x60, 0x0f,
+ 0x79, 0x60, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07,
+ 0x72, 0x80, 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07,
+ 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0, 0x06,
+ 0xf6, 0x10, 0x07, 0x79, 0x20, 0x07, 0x7a, 0x20, 0x07, 0x75, 0x60, 0x07,
+ 0x7a, 0x20, 0x07, 0x75, 0x60, 0x07, 0x6d, 0x60, 0x0f, 0x72, 0x50, 0x07,
+ 0x76, 0xa0, 0x07, 0x72, 0x50, 0x07, 0x76, 0xa0, 0x07, 0x72, 0x50, 0x07,
+ 0x76, 0xd0, 0x06, 0xf6, 0x50, 0x07, 0x71, 0x20, 0x07, 0x7a, 0x50, 0x07,
+ 0x71, 0x20, 0x07, 0x7a, 0x50, 0x07, 0x71, 0x20, 0x07, 0x6d, 0x60, 0x0f,
+ 0x71, 0x00, 0x07, 0x72, 0x40, 0x07, 0x7a, 0x10, 0x07, 0x70, 0x20, 0x07,
+ 0x74, 0xa0, 0x07, 0x71, 0x00, 0x07, 0x72, 0x40, 0x07, 0x6d, 0x60, 0x0e,
+ 0x78, 0x00, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07,
+ 0x72, 0x80, 0x07, 0x6d, 0xe0, 0x0e, 0x78, 0xa0, 0x07, 0x71, 0x60, 0x07,
+ 0x7a, 0x30, 0x07, 0x72, 0x30, 0x84, 0x71, 0x00, 0x00, 0x08, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x18, 0xc2, 0x40, 0x40, 0x00, 0x08, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x0c, 0x61, 0x2a, 0x20, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x86, 0x30, 0x17, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x59, 0x20, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x14,
+ 0x19, 0x11, 0x4c, 0x90, 0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0x8a,
+ 0x23, 0x00, 0x25, 0x50, 0x20, 0x05, 0x18, 0x50, 0x10, 0x45, 0x50, 0x06,
+ 0x05, 0x54, 0x60, 0x85, 0x50, 0x0a, 0xc5, 0x40, 0x7b, 0x04, 0x00, 0x00,
+ 0x79, 0x18, 0x00, 0x00, 0x15, 0x01, 0x00, 0x00, 0x1a, 0x03, 0x4c, 0x10,
+ 0xd7, 0x20, 0x08, 0x0e, 0x8e, 0xad, 0x0c, 0x84, 0x89, 0xc9, 0xaa, 0x09,
+ 0xc4, 0xae, 0x4c, 0x6e, 0x2e, 0xed, 0xcd, 0x0d, 0x04, 0x07, 0x46, 0xc6,
+ 0x25, 0x06, 0x04, 0xa5, 0xad, 0x8c, 0x2e, 0x8c, 0xcd, 0xac, 0xac, 0x05,
+ 0x07, 0x46, 0xc6, 0x25, 0xc6, 0x65, 0x86, 0x26, 0x65, 0x88, 0x80, 0x01,
+ 0x43, 0x8c, 0xa8, 0x88, 0x90, 0x88, 0x60, 0xd1, 0x54, 0x46, 0x17, 0xc6,
+ 0x36, 0x04, 0xc1, 0x86, 0xa8, 0x88, 0x8a, 0x88, 0xe0, 0x16, 0x96, 0x26,
+ 0xe7, 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56, 0xe6, 0x42, 0x56, 0xe6,
+ 0xf6, 0x26, 0xd7, 0x36, 0xf7, 0x45, 0x96, 0x36, 0x17, 0x26, 0xc6, 0x56,
+ 0x36, 0x44, 0xc0, 0x0a, 0x72, 0x61, 0x69, 0x72, 0x2e, 0x63, 0x6f, 0x6d,
+ 0x70, 0x69, 0x6c, 0x65, 0x2e, 0x66, 0x61, 0x73, 0x74, 0x5f, 0x6d, 0x61,
+ 0x74, 0x68, 0x5f, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x43, 0x04, 0xec,
+ 0x60, 0x19, 0x84, 0xa5, 0xc9, 0xb9, 0x8c, 0xbd, 0xb5, 0xc1, 0xa5, 0xb1,
+ 0x95, 0xb9, 0x98, 0xc9, 0x85, 0xb5, 0x95, 0x89, 0xd5, 0x99, 0x99, 0x95,
+ 0xc9, 0x7d, 0x99, 0x95, 0xd1, 0x8d, 0xa1, 0x7d, 0x91, 0xa5, 0xcd, 0x85,
+ 0x89, 0xb1, 0x95, 0x0d, 0x11, 0xb0, 0x84, 0x61, 0x10, 0x96, 0x26, 0xe7,
+ 0x32, 0xf6, 0xd6, 0x06, 0x97, 0xc6, 0x56, 0xe6, 0xe2, 0x16, 0x46, 0x97,
+ 0x66, 0x57, 0xf6, 0x45, 0xf6, 0x56, 0x27, 0xc6, 0x56, 0xf6, 0x45, 0x96,
+ 0x36, 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0xc0, 0x16, 0x46, 0x61, 0x69,
+ 0x72, 0x2e, 0x72, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x5f, 0x74, 0x61, 0x72,
+ 0x67, 0x65, 0x74, 0x8c, 0xc2, 0xd2, 0xe4, 0x5c, 0xc2, 0xe4, 0xce, 0xbe,
+ 0xe8, 0xf2, 0xe0, 0xca, 0xbe, 0xdc, 0xc2, 0xda, 0xca, 0x68, 0x98, 0xb1,
+ 0xbd, 0x85, 0xd1, 0xd1, 0x0c, 0x41, 0xb0, 0x26, 0x22, 0x30, 0x07, 0x7b,
+ 0x86, 0x08, 0x18, 0x44, 0x26, 0x2c, 0x4d, 0xce, 0x05, 0xee, 0x6d, 0x2e,
+ 0x8d, 0x2e, 0xed, 0xcd, 0x8d, 0x4a, 0x58, 0x9a, 0x9c, 0xcb, 0x58, 0x99,
+ 0x1b, 0x5d, 0x99, 0x1c, 0xa5, 0xb0, 0x34, 0x39, 0x17, 0xb7, 0xb7, 0x2f,
+ 0xb8, 0x32, 0xb9, 0x39, 0xb8, 0xb2, 0x31, 0xba, 0x34, 0xbb, 0x32, 0x32,
+ 0x61, 0x69, 0x72, 0x2e, 0x61, 0x72, 0x67, 0x5f, 0x6e, 0x61, 0x6d, 0x65,
+ 0x44, 0xe0, 0xde, 0xe6, 0xd2, 0xe8, 0xd2, 0xde, 0xdc, 0x86, 0x40, 0x11,
+ 0x81, 0x49, 0xd8, 0x84, 0x51, 0x98, 0x83, 0x3d, 0x58, 0x85, 0x59, 0x94,
+ 0xc2, 0xd2, 0xe4, 0x5c, 0xcc, 0xe4, 0xc2, 0xce, 0xda, 0xca, 0xdc, 0xe8,
+ 0xbe, 0xd2, 0xdc, 0xe0, 0xea, 0xe8, 0x98, 0x9d, 0x95, 0xb9, 0x95, 0xc9,
+ 0x85, 0xd1, 0x95, 0x91, 0xa1, 0xe0, 0xd0, 0x95, 0xe1, 0x8d, 0xbd, 0xbd,
+ 0xc9, 0x91, 0x11, 0xd9, 0xc9, 0x7c, 0x99, 0xa5, 0xf0, 0x09, 0x4b, 0x93,
+ 0x73, 0x81, 0x2b, 0x93, 0x9b, 0x83, 0x2b, 0x1b, 0xa3, 0x4b, 0xb3, 0x2b,
+ 0xa3, 0x61, 0xc6, 0xf6, 0x16, 0x46, 0x27, 0x43, 0x84, 0xae, 0x0c, 0x6f,
+ 0xec, 0xed, 0x4d, 0x8e, 0x6c, 0x88, 0x14, 0x15, 0x18, 0x86, 0x65, 0xd8,
+ 0x84, 0x69, 0x98, 0x83, 0x6d, 0x58, 0x85, 0x71, 0x54, 0xc2, 0xd2, 0xe4,
+ 0x5c, 0xc4, 0xea, 0xcc, 0xcc, 0xca, 0xe4, 0xf8, 0x84, 0xa5, 0xc9, 0xb9,
+ 0x88, 0xd5, 0x99, 0x99, 0x95, 0xc9, 0x7d, 0xcd, 0xa5, 0xe9, 0x95, 0x51,
+ 0x0a, 0x4b, 0x93, 0x73, 0x61, 0x7b, 0x1b, 0x0b, 0xa3, 0x4b, 0x7b, 0x73,
+ 0xfb, 0x4a, 0x73, 0x23, 0x2b, 0xc3, 0x23, 0x12, 0x96, 0x26, 0xe7, 0x22,
+ 0x57, 0x16, 0x46, 0xc6, 0x28, 0x2c, 0x4d, 0xce, 0x25, 0x4c, 0xee, 0xec,
+ 0x8b, 0x2e, 0x0f, 0xae, 0xec, 0x6b, 0x2e, 0x4d, 0xaf, 0x8c, 0x57, 0x58,
+ 0x9a, 0x9c, 0x4b, 0x98, 0xdc, 0xd9, 0x17, 0x5d, 0x1e, 0x5c, 0xd9, 0x57,
+ 0x18, 0x5b, 0xda, 0x99, 0xdb, 0xd7, 0x5c, 0x9a, 0x5e, 0x19, 0x87, 0xb1,
+ 0x37, 0xb6, 0x21, 0x60, 0x10, 0x25, 0x98, 0x87, 0x7d, 0x91, 0x81, 0x81,
+ 0x41, 0x44, 0x44, 0x05, 0x16, 0x06, 0x98, 0x18, 0x44, 0x06, 0x36, 0x06,
+ 0x91, 0x81, 0x39, 0xd8, 0x83, 0x55, 0x18, 0x19, 0x90, 0x0a, 0x4b, 0x93,
+ 0x73, 0x99, 0xa3, 0x93, 0xab, 0x1b, 0xa3, 0xfb, 0xa2, 0xcb, 0x83, 0x2b,
+ 0xfb, 0x4a, 0x73, 0x33, 0x7b, 0xa3, 0x61, 0xc6, 0xf6, 0x16, 0x46, 0x37,
+ 0x43, 0xe3, 0xcd, 0xcc, 0x6c, 0xae, 0x8c, 0x8e, 0x86, 0xd4, 0xd8, 0x5b,
+ 0x99, 0x99, 0x19, 0x8d, 0xa3, 0xb1, 0xb7, 0x32, 0x33, 0x33, 0x1a, 0x42,
+ 0x63, 0x6f, 0x65, 0x66, 0x66, 0x43, 0xd0, 0x20, 0x22, 0x22, 0x23, 0x22,
+ 0xb0, 0x33, 0xc0, 0xd0, 0x20, 0x32, 0x22, 0x23, 0x22, 0xb0, 0x33, 0xc0,
+ 0xd2, 0x20, 0x5a, 0x22, 0x23, 0x22, 0xb0, 0x33, 0xc0, 0xd4, 0x20, 0x62,
+ 0x22, 0x23, 0x22, 0xb0, 0x33, 0xc0, 0xd6, 0x80, 0x49, 0x56, 0x95, 0x15,
+ 0x51, 0xd9, 0xd8, 0x1b, 0x59, 0x19, 0x0d, 0xb2, 0xb2, 0xb1, 0x37, 0xb2,
+ 0xb2, 0x21, 0x64, 0x10, 0x29, 0x98, 0x87, 0x7d, 0xd1, 0x81, 0x81, 0x41,
+ 0x54, 0x44, 0x05, 0x16, 0x06, 0x98, 0x19, 0x60, 0x6c, 0x80, 0x89, 0x41,
+ 0x74, 0x60, 0x63, 0x10, 0x19, 0x98, 0x83, 0xb5, 0x01, 0x56, 0x61, 0x6e,
+ 0xc0, 0x25, 0x2c, 0x4d, 0xce, 0x85, 0xae, 0x0c, 0x8f, 0xae, 0x4e, 0xae,
+ 0x8c, 0x4a, 0x58, 0x9a, 0x9c, 0xcb, 0x5c, 0x58, 0x1b, 0x1c, 0x5b, 0x19,
+ 0x31, 0xba, 0x32, 0x3c, 0xba, 0x3a, 0xb9, 0x32, 0x19, 0x32, 0x1e, 0x33,
+ 0xb6, 0xb7, 0x30, 0x3a, 0x16, 0x90, 0xb9, 0xb0, 0x36, 0x38, 0xb6, 0x32,
+ 0x1f, 0x12, 0x74, 0x65, 0x78, 0x59, 0x43, 0xa8, 0xa8, 0xc1, 0xe0, 0x00,
+ 0x03, 0x83, 0x88, 0x88, 0x0a, 0x2c, 0x0e, 0x30, 0x07, 0x93, 0x03, 0xac,
+ 0xc2, 0xe6, 0x80, 0x1e, 0x5d, 0x19, 0x1e, 0x5d, 0x9d, 0x5c, 0x99, 0x0c,
+ 0xd9, 0x57, 0x98, 0x9c, 0x5c, 0x58, 0x1e, 0x8f, 0x19, 0xdb, 0x5b, 0x18,
+ 0x1d, 0x0b, 0xc8, 0x5c, 0x58, 0x1b, 0x1c, 0x5b, 0x99, 0x0f, 0x0b, 0xba,
+ 0x32, 0xbc, 0x2a, 0xab, 0x21, 0x54, 0xe4, 0x60, 0x70, 0x80, 0x81, 0x41,
+ 0x54, 0x44, 0x05, 0x16, 0x07, 0x98, 0x83, 0xd5, 0x01, 0x56, 0x61, 0x76,
+ 0xc0, 0x25, 0x2c, 0x4d, 0xce, 0x65, 0x2e, 0xac, 0x0d, 0x8e, 0xad, 0x4c,
+ 0x8e, 0xc7, 0x5c, 0x58, 0x1b, 0x1c, 0x5b, 0x99, 0x1c, 0x83, 0xb9, 0x21,
+ 0x52, 0xf4, 0x60, 0x78, 0x80, 0x81, 0x41, 0x44, 0x44, 0x05, 0xe6, 0x60,
+ 0x79, 0x80, 0x55, 0x98, 0x1e, 0x0c, 0x71, 0xb0, 0x0b, 0xeb, 0xb0, 0x32,
+ 0xc0, 0xde, 0x00, 0xa3, 0x03, 0xec, 0x0e, 0xb0, 0x3d, 0x18, 0x62, 0x38,
+ 0x00, 0x16, 0x61, 0x7c, 0xc0, 0xe7, 0xad, 0xcd, 0x2d, 0x0d, 0xee, 0x8d,
+ 0xae, 0xcc, 0x8d, 0x0e, 0x64, 0x0c, 0x2d, 0x4c, 0x8e, 0xcf, 0x54, 0x5a,
+ 0x1b, 0x1c, 0x5b, 0x19, 0xc8, 0xd0, 0xca, 0x0a, 0x08, 0x95, 0x50, 0x50,
+ 0xd0, 0x10, 0x01, 0xfb, 0x83, 0x21, 0x06, 0xe6, 0x07, 0x18, 0x28, 0x6c,
+ 0xd0, 0x10, 0x03, 0x0b, 0x05, 0x2c, 0x14, 0x36, 0x68, 0x84, 0xc2, 0x0e,
+ 0xec, 0x60, 0x0f, 0xed, 0xe0, 0x06, 0xe9, 0x40, 0x0e, 0xe5, 0xe0, 0x0e,
+ 0xf4, 0x30, 0x25, 0x08, 0x46, 0x2c, 0xe1, 0x90, 0x0e, 0xf2, 0xe0, 0x06,
+ 0xf6, 0x50, 0x0e, 0xf2, 0x30, 0x0f, 0xe9, 0xf0, 0x0e, 0xee, 0x30, 0x25,
+ 0x10, 0x46, 0x50, 0xe1, 0x90, 0x0e, 0xf2, 0xe0, 0x06, 0xec, 0x10, 0x0e,
+ 0xee, 0x70, 0x0e, 0xf5, 0x10, 0x0e, 0xe7, 0x50, 0x0e, 0xbf, 0x60, 0x0f,
+ 0xe5, 0x20, 0x0f, 0xf3, 0x90, 0x0e, 0xef, 0xe0, 0x0e, 0x53, 0x02, 0x62,
+ 0xc4, 0x14, 0x0e, 0xe9, 0x20, 0x0f, 0x6e, 0x30, 0x0e, 0xef, 0xd0, 0x0e,
+ 0xf0, 0x90, 0x0e, 0xec, 0x50, 0x0e, 0xbf, 0xf0, 0x0e, 0xf0, 0x40, 0x0f,
+ 0xe9, 0xf0, 0x0e, 0xee, 0x30, 0x0f, 0x53, 0x08, 0x03, 0x51, 0x98, 0x11,
+ 0x4c, 0x38, 0xa4, 0x83, 0x3c, 0xb8, 0x81, 0x39, 0xc8, 0x43, 0x38, 0x9c,
+ 0x43, 0x3b, 0x94, 0x83, 0x3b, 0xd0, 0xc3, 0x94, 0xa0, 0x0f, 0x00, 0x00,
+ 0x79, 0x18, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x33, 0x08, 0x80, 0x1c,
+ 0xc4, 0xe1, 0x1c, 0x66, 0x14, 0x01, 0x3d, 0x88, 0x43, 0x38, 0x84, 0xc3,
+ 0x8c, 0x42, 0x80, 0x07, 0x79, 0x78, 0x07, 0x73, 0x98, 0x71, 0x0c, 0xe6,
+ 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x33, 0x0c, 0x42, 0x1e,
+ 0xc2, 0xc1, 0x1d, 0xce, 0xa1, 0x1c, 0x66, 0x30, 0x05, 0x3d, 0x88, 0x43,
+ 0x38, 0x84, 0x83, 0x1b, 0xcc, 0x03, 0x3d, 0xc8, 0x43, 0x3d, 0x8c, 0x03,
+ 0x3d, 0xcc, 0x78, 0x8c, 0x74, 0x70, 0x07, 0x7b, 0x08, 0x07, 0x79, 0x48,
+ 0x87, 0x70, 0x70, 0x07, 0x7a, 0x70, 0x03, 0x76, 0x78, 0x87, 0x70, 0x20,
+ 0x87, 0x19, 0xcc, 0x11, 0x0e, 0xec, 0x90, 0x0e, 0xe1, 0x30, 0x0f, 0x6e,
+ 0x30, 0x0f, 0xe3, 0xf0, 0x0e, 0xf0, 0x50, 0x0e, 0x33, 0x10, 0xc4, 0x1d,
+ 0xde, 0x21, 0x1c, 0xd8, 0x21, 0x1d, 0xc2, 0x61, 0x1e, 0x66, 0x30, 0x89,
+ 0x3b, 0xbc, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xb4, 0x03, 0x3c, 0xbc, 0x83,
+ 0x3c, 0x84, 0x03, 0x3b, 0xcc, 0xf0, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68,
+ 0x07, 0x37, 0x68, 0x87, 0x72, 0x68, 0x07, 0x37, 0x80, 0x87, 0x70, 0x90,
+ 0x87, 0x70, 0x60, 0x07, 0x76, 0x28, 0x07, 0x76, 0xf8, 0x05, 0x76, 0x78,
+ 0x87, 0x77, 0x80, 0x87, 0x5f, 0x08, 0x87, 0x71, 0x18, 0x87, 0x72, 0x98,
+ 0x87, 0x79, 0x98, 0x81, 0x2c, 0xee, 0xf0, 0x0e, 0xee, 0xe0, 0x0e, 0xf5,
+ 0xc0, 0x0e, 0xec, 0x30, 0x03, 0x62, 0xc8, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c,
+ 0xcc, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xdc, 0x61, 0x1c, 0xca, 0x21, 0x1c,
+ 0xc4, 0x81, 0x1d, 0xca, 0x61, 0x06, 0xd6, 0x90, 0x43, 0x39, 0xc8, 0x43,
+ 0x39, 0x98, 0x43, 0x39, 0xc8, 0x43, 0x39, 0xb8, 0xc3, 0x38, 0x94, 0x43,
+ 0x38, 0x88, 0x03, 0x3b, 0x94, 0xc3, 0x2f, 0xbc, 0x83, 0x3c, 0xfc, 0x82,
+ 0x3b, 0xd4, 0x03, 0x3b, 0xb0, 0xc3, 0x0c, 0xc7, 0x69, 0x87, 0x70, 0x58,
+ 0x87, 0x72, 0x70, 0x83, 0x74, 0x68, 0x07, 0x78, 0x60, 0x87, 0x74, 0x18,
+ 0x87, 0x74, 0xa0, 0x87, 0x19, 0xce, 0x53, 0x0f, 0xee, 0x00, 0x0f, 0xf2,
+ 0x50, 0x0e, 0xe4, 0x90, 0x0e, 0xe3, 0x40, 0x0f, 0xe1, 0x20, 0x0e, 0xec,
+ 0x50, 0x0e, 0x33, 0x20, 0x28, 0x1d, 0xdc, 0xc1, 0x1e, 0xc2, 0x41, 0x1e,
+ 0xd2, 0x21, 0x1c, 0xdc, 0x81, 0x1e, 0xdc, 0xe0, 0x1c, 0xe4, 0xe1, 0x1d,
+ 0xea, 0x01, 0x1e, 0x66, 0x18, 0x51, 0x38, 0xb0, 0x43, 0x3a, 0x9c, 0x83,
+ 0x3b, 0xcc, 0x50, 0x24, 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x60,
+ 0x87, 0x77, 0x78, 0x07, 0x78, 0x98, 0x51, 0x4c, 0xf4, 0x90, 0x0f, 0xf0,
+ 0x50, 0x0e, 0x00, 0x00, 0x71, 0x20, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
+ 0x26, 0x10, 0x06, 0x00, 0x12, 0xf9, 0x12, 0xc0, 0x3c, 0x0b, 0xf1, 0x4f,
+ 0xc4, 0x35, 0x51, 0x11, 0xf1, 0xdb, 0xc3, 0x0f, 0x44, 0x11, 0x80, 0xf9,
+ 0x15, 0x5e, 0xdc, 0xb6, 0x05, 0x34, 0x00, 0x12, 0xf9, 0x83, 0x33, 0xf9,
+ 0xd5, 0x5d, 0xdc, 0xb6, 0x0d, 0x6c, 0x00, 0x12, 0xf9, 0x12, 0xc0, 0x3c,
+ 0x0b, 0xf1, 0x4f, 0xc4, 0x35, 0x51, 0x11, 0xf1, 0xdb, 0x83, 0x5f, 0xe1,
+ 0xc5, 0x6d, 0x1b, 0x00, 0xc4, 0x76, 0xe5, 0x2f, 0xbb, 0xef, 0x5f, 0x44,
+ 0x80, 0xc1, 0x10, 0xcd, 0x04, 0x00, 0x00, 0x00, 0x61, 0x20, 0x00, 0x00,
+ 0x3e, 0x00, 0x00, 0x00, 0x13, 0x04, 0x41, 0x2c, 0x10, 0x00, 0x00, 0x00,
+ 0x0b, 0x00, 0x00, 0x00, 0xa4, 0xe7, 0x20, 0x88, 0x22, 0xe1, 0x28, 0xcf,
+ 0x31, 0x10, 0x1c, 0x37, 0xd6, 0x00, 0x04, 0x02, 0xcd, 0x11, 0x00, 0x8a,
+ 0x33, 0x00, 0x24, 0x6b, 0x60, 0x04, 0x80, 0xc8, 0x0c, 0x00, 0x85, 0x19,
+ 0x00, 0x02, 0x63, 0x04, 0x20, 0x08, 0x82, 0xf8, 0x37, 0x02, 0x00, 0x00,
+ 0x23, 0x06, 0xca, 0x10, 0x80, 0x81, 0xc3, 0x44, 0x06, 0x52, 0x04, 0x23,
+ 0x06, 0xcb, 0x10, 0x88, 0x81, 0xd3, 0x48, 0x60, 0x70, 0x24, 0x86, 0x30,
+ 0x86, 0x10, 0x84, 0xc1, 0x20, 0xc3, 0x60, 0x34, 0x73, 0x0c, 0x81, 0x20,
+ 0x06, 0x23, 0x06, 0xcb, 0x10, 0x98, 0x81, 0x14, 0x59, 0x63, 0xb0, 0x34,
+ 0x8a, 0x31, 0x86, 0x10, 0x94, 0xc1, 0x1c, 0xc3, 0x10, 0x84, 0xc1, 0x20,
+ 0x43, 0xc0, 0x4c, 0x87, 0x8d, 0xa5, 0xa0, 0xd8, 0x10, 0xc0, 0x87, 0xb8,
+ 0x32, 0xc8, 0x20, 0x40, 0xd6, 0x78, 0x43, 0x17, 0x06, 0x6c, 0x70, 0xc1,
+ 0x58, 0x0a, 0xca, 0x20, 0x43, 0x40, 0x69, 0x23, 0x06, 0x05, 0x11, 0xd0,
+ 0x41, 0x11, 0xcc, 0x31, 0x58, 0x81, 0x1c, 0x8c, 0x37, 0x8c, 0xc1, 0x19,
+ 0xb8, 0xc1, 0x05, 0x63, 0x29, 0x28, 0x83, 0x0c, 0x81, 0x06, 0x06, 0x23,
+ 0x06, 0x05, 0x11, 0xe8, 0xc1, 0x12, 0xcc, 0x31, 0x18, 0xc1, 0x1d, 0x8c,
+ 0x37, 0xa4, 0x41, 0x1b, 0xcc, 0xc1, 0x05, 0x63, 0x29, 0x28, 0x83, 0x0c,
+ 0x01, 0x18, 0x98, 0xc1, 0x88, 0x41, 0x41, 0x04, 0xa0, 0x10, 0x05, 0x73,
+ 0x0c, 0x46, 0x90, 0x07, 0x73, 0x0c, 0x81, 0x18, 0xe4, 0x81, 0x05, 0x95,
+ 0x7c, 0x32, 0x08, 0x88, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x5b, 0x06, 0x26, 0x10, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xde, 0xc0, 0x17, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
+ 0xf8, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x42, 0x43, 0xc0, 0xde,
+ 0x21, 0x0c, 0x00, 0x00, 0x7b, 0x03, 0x00, 0x00, 0x0b, 0x82, 0x20, 0x00,
+ 0x02, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91,
+ 0x41, 0xc8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0c,
+ 0x25, 0x05, 0x08, 0x19, 0x1e, 0x04, 0x8b, 0x62, 0x80, 0x14, 0x45, 0x02,
+ 0x42, 0x92, 0x0b, 0x42, 0xa4, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x49,
+ 0x0a, 0x32, 0x44, 0x24, 0x48, 0x0a, 0x90, 0x21, 0x23, 0xc4, 0x52, 0x80,
+ 0x0c, 0x19, 0x21, 0x72, 0x24, 0x07, 0xc8, 0x48, 0x11, 0x62, 0xa8, 0xa0,
+ 0xa8, 0x40, 0xc6, 0xf0, 0x01, 0x00, 0x00, 0x00, 0x51, 0x18, 0x00, 0x00,
+ 0x03, 0x01, 0x00, 0x00, 0x1b, 0x8c, 0x60, 0x00, 0x16, 0xa0, 0xda, 0x60,
+ 0x08, 0x04, 0xb0, 0x00, 0xd5, 0x06, 0x63, 0x38, 0x80, 0x05, 0xa8, 0x36,
+ 0x90, 0x0b, 0xf1, 0xff, 0xff, 0xff, 0xff, 0x03, 0xc0, 0x00, 0x12, 0x31,
+ 0x0e, 0xef, 0x20, 0x0f, 0xf2, 0x50, 0x0e, 0xe3, 0x40, 0x0f, 0xec, 0x90,
+ 0x0f, 0x6d, 0x20, 0x0f, 0xef, 0x50, 0x0f, 0xee, 0x40, 0x0e, 0xe5, 0x40,
+ 0x0e, 0x6d, 0x40, 0x0e, 0xe9, 0x60, 0x0f, 0xe9, 0x40, 0x0e, 0xe5, 0xd0,
+ 0x06, 0xf3, 0x10, 0x0f, 0xf2, 0x40, 0x0f, 0x6d, 0x60, 0x0e, 0xf0, 0xd0,
+ 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x80, 0x39, 0x84, 0x03, 0x3b,
+ 0xcc, 0x43, 0x39, 0x00, 0x04, 0x39, 0xa4, 0xc3, 0x3c, 0x84, 0x83, 0x38,
+ 0xb0, 0x43, 0x39, 0xb4, 0x01, 0x3d, 0x84, 0x43, 0x3a, 0xb0, 0x43, 0x1b,
+ 0x8c, 0x43, 0x38, 0xb0, 0x03, 0x3b, 0xcc, 0x03, 0x60, 0x0e, 0xe1, 0xc0,
+ 0x0e, 0xf3, 0x50, 0x0e, 0x00, 0xc1, 0x0e, 0xe5, 0x30, 0x0f, 0xf3, 0xd0,
+ 0x06, 0xf0, 0x20, 0x0f, 0xe5, 0x30, 0x0e, 0xe9, 0x30, 0x0f, 0xe5, 0xd0,
+ 0x06, 0xe6, 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xe4, 0x00, 0xd0, 0x83, 0x3c,
+ 0xd4, 0x43, 0x39, 0x00, 0x84, 0x3b, 0xbc, 0x43, 0x1b, 0x98, 0x83, 0x3c,
+ 0x84, 0x43, 0x3b, 0x94, 0x43, 0x1b, 0xc0, 0xc3, 0x3b, 0xa4, 0x83, 0x3b,
+ 0xd0, 0x43, 0x39, 0xc8, 0x43, 0x1b, 0x94, 0x03, 0x3b, 0xa4, 0x43, 0x3b,
+ 0x00, 0xf4, 0x20, 0x0f, 0xf5, 0x50, 0x0e, 0xc0, 0xe0, 0x0e, 0xef, 0xd0,
+ 0x06, 0xe6, 0x20, 0x0f, 0xe1, 0xd0, 0x0e, 0xe5, 0xd0, 0x06, 0xf0, 0xf0,
+ 0x0e, 0xe9, 0xe0, 0x0e, 0xf4, 0x50, 0x0e, 0xf2, 0xd0, 0x06, 0xe5, 0xc0,
+ 0x0e, 0xe9, 0xd0, 0x0e, 0x6d, 0xe0, 0x0e, 0xef, 0xe0, 0x0e, 0x6d, 0xc0,
+ 0x0e, 0xe5, 0x10, 0x0e, 0xe6, 0x00, 0x10, 0xee, 0xf0, 0x0e, 0x6d, 0x90,
+ 0x0e, 0xee, 0x60, 0x0e, 0xf3, 0xd0, 0x06, 0xe6, 0x00, 0x0f, 0x6d, 0xd0,
+ 0x0e, 0xe1, 0x40, 0x0f, 0xe8, 0x00, 0xd0, 0x83, 0x3c, 0xd4, 0x43, 0x39,
+ 0x00, 0x84, 0x3b, 0xbc, 0x43, 0x1b, 0xa8, 0x43, 0x3d, 0xb4, 0x03, 0x3c,
+ 0xb4, 0x01, 0x3d, 0x84, 0x83, 0x38, 0xb0, 0x43, 0x39, 0xcc, 0x03, 0x60,
+ 0x0e, 0xe1, 0xc0, 0x0e, 0xf3, 0x50, 0x0e, 0x00, 0xe1, 0x0e, 0xef, 0xd0,
+ 0x06, 0xee, 0x10, 0x0e, 0xee, 0x30, 0x0f, 0x6d, 0x60, 0x0e, 0xf0, 0xd0,
+ 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x00, 0x3d, 0xc8, 0x43, 0x3d,
+ 0x94, 0x03, 0x40, 0xb8, 0xc3, 0x3b, 0xb4, 0xc1, 0x3c, 0xa4, 0xc3, 0x39,
+ 0xb8, 0x43, 0x39, 0x90, 0x43, 0x1b, 0xe8, 0x43, 0x39, 0xc8, 0xc3, 0x3b,
+ 0xcc, 0x43, 0x1b, 0x98, 0x03, 0x3c, 0xb4, 0x41, 0x3b, 0x84, 0x03, 0x3d,
+ 0xa0, 0x03, 0x60, 0x0e, 0xe1, 0xc0, 0x0e, 0xf3, 0x50, 0x0e, 0x00, 0x31,
+ 0x0f, 0xf4, 0x10, 0x0e, 0xe3, 0xb0, 0x0e, 0x6d, 0x00, 0x0f, 0xf2, 0xf0,
+ 0x0e, 0xf4, 0x50, 0x0e, 0xe3, 0x40, 0x0f, 0xef, 0x20, 0x0f, 0x6d, 0x20,
+ 0x0e, 0xf5, 0x60, 0x0e, 0xe6, 0x50, 0x0e, 0xf2, 0xd0, 0x06, 0xf3, 0x90,
+ 0x0e, 0xfa, 0x50, 0x0e, 0x00, 0x1e, 0x00, 0x04, 0x3d, 0x84, 0x83, 0x3c,
+ 0x9c, 0x43, 0x39, 0xd0, 0x43, 0x1b, 0x98, 0x43, 0x39, 0x84, 0x03, 0x3d,
+ 0xd4, 0x83, 0x3c, 0x94, 0xc3, 0x3c, 0x00, 0x6d, 0x60, 0x0e, 0xf0, 0x10,
+ 0x07, 0x76, 0x00, 0x10, 0xf5, 0xe0, 0x0e, 0xf3, 0x10, 0x0e, 0xe6, 0x50,
+ 0x0e, 0x6d, 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80,
+ 0x0e, 0x00, 0x3d, 0xc8, 0x43, 0x3d, 0x94, 0x03, 0x40, 0xd4, 0xc3, 0x3c,
+ 0x94, 0x43, 0x1b, 0xcc, 0xc3, 0x3b, 0x98, 0x03, 0x3d, 0xb4, 0x81, 0x39,
+ 0xb0, 0xc3, 0x3b, 0x84, 0x03, 0x3d, 0x00, 0xe6, 0x10, 0x0e, 0xec, 0x30,
+ 0x0f, 0xe5, 0x00, 0x6c, 0x50, 0x95, 0xe2, 0xff, 0xff, 0xff, 0xff, 0x07,
+ 0x62, 0x1c, 0xde, 0x41, 0x1e, 0xe4, 0xa1, 0x1c, 0xc6, 0x81, 0x1e, 0xd8,
+ 0x21, 0x1f, 0xda, 0x40, 0x1e, 0xde, 0xa1, 0x1e, 0xdc, 0x81, 0x1c, 0xca,
+ 0x81, 0x1c, 0xda, 0x80, 0x1c, 0xd2, 0xc1, 0x1e, 0xd2, 0x81, 0x1c, 0xca,
+ 0xa1, 0x0d, 0xe6, 0x21, 0x1e, 0xe4, 0x81, 0x1e, 0xda, 0xc0, 0x1c, 0xe0,
+ 0xa1, 0x0d, 0xda, 0x21, 0x1c, 0xe8, 0x01, 0x1d, 0x00, 0x73, 0x08, 0x07,
+ 0x76, 0x98, 0x87, 0x72, 0x00, 0x08, 0x72, 0x48, 0x87, 0x79, 0x08, 0x07,
+ 0x71, 0x60, 0x87, 0x72, 0x68, 0x03, 0x7a, 0x08, 0x87, 0x74, 0x60, 0x87,
+ 0x36, 0x18, 0x87, 0x70, 0x60, 0x07, 0x76, 0x98, 0x07, 0xc0, 0x1c, 0xc2,
+ 0x81, 0x1d, 0xe6, 0xa1, 0x1c, 0x00, 0x82, 0x1d, 0xca, 0x61, 0x1e, 0xe6,
+ 0xa1, 0x0d, 0xe0, 0x41, 0x1e, 0xca, 0x61, 0x1c, 0xd2, 0x61, 0x1e, 0xca,
+ 0xa1, 0x0d, 0xcc, 0x01, 0x1e, 0xda, 0x21, 0x1c, 0xc8, 0x01, 0xa0, 0x07,
+ 0x79, 0xa8, 0x87, 0x72, 0x00, 0x08, 0x77, 0x78, 0x87, 0x36, 0x30, 0x07,
+ 0x79, 0x08, 0x87, 0x76, 0x28, 0x87, 0x36, 0x80, 0x87, 0x77, 0x48, 0x07,
+ 0x77, 0xa0, 0x87, 0x72, 0x90, 0x87, 0x36, 0x28, 0x07, 0x76, 0x48, 0x87,
+ 0x76, 0x00, 0xe8, 0x41, 0x1e, 0xea, 0xa1, 0x1c, 0x80, 0xc1, 0x1d, 0xde,
+ 0xa1, 0x0d, 0xcc, 0x41, 0x1e, 0xc2, 0xa1, 0x1d, 0xca, 0xa1, 0x0d, 0xe0,
+ 0xe1, 0x1d, 0xd2, 0xc1, 0x1d, 0xe8, 0xa1, 0x1c, 0xe4, 0xa1, 0x0d, 0xca,
+ 0x81, 0x1d, 0xd2, 0xa1, 0x1d, 0xda, 0xc0, 0x1d, 0xde, 0xc1, 0x1d, 0xda,
+ 0x80, 0x1d, 0xca, 0x21, 0x1c, 0xcc, 0x01, 0x20, 0xdc, 0xe1, 0x1d, 0xda,
+ 0x20, 0x1d, 0xdc, 0xc1, 0x1c, 0xe6, 0xa1, 0x0d, 0xcc, 0x01, 0x1e, 0xda,
+ 0xa0, 0x1d, 0xc2, 0x81, 0x1e, 0xd0, 0x01, 0xa0, 0x07, 0x79, 0xa8, 0x87,
+ 0x72, 0x00, 0x08, 0x77, 0x78, 0x87, 0x36, 0x70, 0x87, 0x70, 0x70, 0x87,
+ 0x79, 0x68, 0x03, 0x73, 0x80, 0x87, 0x36, 0x68, 0x87, 0x70, 0xa0, 0x07,
+ 0x74, 0x00, 0xe8, 0x41, 0x1e, 0xea, 0xa1, 0x1c, 0x00, 0xc2, 0x1d, 0xde,
+ 0xa1, 0x0d, 0xe6, 0x21, 0x1d, 0xce, 0xc1, 0x1d, 0xca, 0x81, 0x1c, 0xda,
+ 0x40, 0x1f, 0xca, 0x41, 0x1e, 0xde, 0x61, 0x1e, 0xda, 0xc0, 0x1c, 0xe0,
+ 0xa1, 0x0d, 0xda, 0x21, 0x1c, 0xe8, 0x01, 0x1d, 0x00, 0x73, 0x08, 0x07,
+ 0x76, 0x98, 0x87, 0x72, 0x00, 0x88, 0x79, 0xa0, 0x87, 0x70, 0x18, 0x87,
+ 0x75, 0x68, 0x03, 0x78, 0x90, 0x87, 0x77, 0xa0, 0x87, 0x72, 0x18, 0x07,
+ 0x7a, 0x78, 0x07, 0x79, 0x68, 0x03, 0x71, 0xa8, 0x07, 0x73, 0x30, 0x87,
+ 0x72, 0x90, 0x87, 0x36, 0x98, 0x87, 0x74, 0xd0, 0x87, 0x72, 0x00, 0xf0,
+ 0x00, 0x20, 0xe8, 0x21, 0x1c, 0xe4, 0xe1, 0x1c, 0xca, 0x81, 0x1e, 0xda,
+ 0xc0, 0x1c, 0xca, 0x21, 0x1c, 0xe8, 0xa1, 0x1e, 0xe4, 0xa1, 0x1c, 0xe6,
+ 0x01, 0x68, 0x03, 0x73, 0x80, 0x87, 0x38, 0xb0, 0x03, 0x80, 0xa8, 0x07,
+ 0x77, 0x98, 0x87, 0x70, 0x30, 0x87, 0x72, 0x68, 0x03, 0x73, 0x80, 0x87,
+ 0x36, 0x68, 0x87, 0x70, 0xa0, 0x07, 0x74, 0x00, 0xe8, 0x41, 0x1e, 0xea,
+ 0xa1, 0x1c, 0x00, 0xa2, 0x1e, 0xe6, 0xa1, 0x1c, 0xda, 0x60, 0x1e, 0xde,
+ 0xc1, 0x1c, 0xe8, 0xa1, 0x0d, 0xcc, 0x81, 0x1d, 0xde, 0x21, 0x1c, 0xe8,
+ 0x01, 0x30, 0x87, 0x70, 0x60, 0x87, 0x79, 0x28, 0x07, 0x60, 0x03, 0x61,
+ 0x04, 0xc0, 0xb2, 0x81, 0x38, 0x04, 0x60, 0xd9, 0x80, 0x20, 0xff, 0xff,
+ 0xff, 0xff, 0x3f, 0x00, 0x0c, 0x20, 0x01, 0xd5, 0x06, 0x22, 0xf9, 0xff,
+ 0xff, 0xff, 0xff, 0x01, 0x90, 0x00, 0x00, 0x00, 0x49, 0x18, 0x00, 0x00,
+ 0x04, 0x00, 0x00, 0x00, 0x13, 0x88, 0x40, 0x18, 0x88, 0x09, 0x41, 0x31,
+ 0x61, 0x30, 0x0e, 0x64, 0x42, 0x90, 0x00, 0x00, 0x89, 0x20, 0x00, 0x00,
+ 0x28, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09, 0x20, 0x64, 0x85, 0x04,
+ 0x93, 0x22, 0xa4, 0x84, 0x04, 0x93, 0x22, 0xe3, 0x84, 0xa1, 0x90, 0x14,
+ 0x12, 0x4c, 0x8a, 0x8c, 0x0b, 0x84, 0xa4, 0x4c, 0x10, 0x68, 0x33, 0x00,
+ 0xc3, 0x08, 0x04, 0x30, 0x8c, 0x20, 0x00, 0x83, 0x08, 0x81, 0x30, 0x8c,
+ 0x30, 0x00, 0x07, 0x49, 0x53, 0x44, 0x09, 0x93, 0x2f, 0xbb, 0x6f, 0x47,
+ 0x08, 0xce, 0x40, 0x20, 0x82, 0x10, 0x42, 0x06, 0x11, 0x0a, 0xe1, 0x28,
+ 0x69, 0x8a, 0x28, 0x61, 0xf2, 0xff, 0x89, 0xb8, 0x26, 0x2a, 0x22, 0x7e,
+ 0x7b, 0xf8, 0xa7, 0x31, 0x02, 0x60, 0x10, 0xe1, 0x08, 0x2e, 0x92, 0xa6,
+ 0x88, 0x12, 0x26, 0xff, 0x97, 0x00, 0xe6, 0x59, 0x88, 0xe8, 0x9f, 0xc6,
+ 0x08, 0x80, 0x41, 0x84, 0x44, 0x28, 0x48, 0x08, 0x62, 0x18, 0x84, 0x14,
+ 0xad, 0x32, 0x00, 0x42, 0xa8, 0xcd, 0x11, 0x04, 0x73, 0x04, 0x60, 0x30,
+ 0x8c, 0x20, 0x40, 0x05, 0x09, 0x48, 0x89, 0x17, 0x1f, 0x20, 0x39, 0x10,
+ 0x30, 0x8c, 0x30, 0x40, 0xc3, 0x08, 0x04, 0x34, 0x47, 0x00, 0x0a, 0x83,
+ 0x08, 0x84, 0x30, 0x02, 0x00, 0x00, 0x00, 0x00, 0x13, 0xb2, 0x70, 0x48,
+ 0x07, 0x79, 0xb0, 0x03, 0x3a, 0x68, 0x83, 0x70, 0x80, 0x07, 0x78, 0x60,
+ 0x87, 0x72, 0x68, 0x83, 0x76, 0x08, 0x87, 0x71, 0x78, 0x87, 0x79, 0xc0,
+ 0x87, 0x38, 0x80, 0x03, 0x37, 0x88, 0x83, 0x38, 0x70, 0x03, 0x38, 0xd8,
+ 0xf0, 0x1e, 0xe5, 0xd0, 0x06, 0xf0, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a,
+ 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x90, 0x0e, 0x71,
+ 0xa0, 0x07, 0x78, 0xa0, 0x07, 0x78, 0xd0, 0x06, 0xe9, 0x80, 0x07, 0x7a,
+ 0x80, 0x07, 0x7a, 0x80, 0x07, 0x6d, 0x90, 0x0e, 0x71, 0x60, 0x07, 0x7a,
+ 0x10, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x60, 0x07, 0x6d, 0x90, 0x0e, 0x73,
+ 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d,
+ 0x90, 0x0e, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76,
+ 0x40, 0x07, 0x6d, 0x60, 0x0e, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72,
+ 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0e, 0x76, 0x40, 0x07, 0x7a,
+ 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x60, 0x0e, 0x78,
+ 0x00, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72,
+ 0x80, 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x60, 0x07, 0x7a, 0x10, 0x07, 0x76,
+ 0xa0, 0x07, 0x71, 0x60, 0x07, 0x6d, 0x60, 0x0f, 0x72, 0x40, 0x07, 0x7a,
+ 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0f, 0x73,
+ 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d,
+ 0x60, 0x0f, 0x74, 0x80, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76,
+ 0x40, 0x07, 0x6d, 0x60, 0x0f, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74,
+ 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x60, 0x0f, 0x79, 0x60, 0x07, 0x7a,
+ 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d,
+ 0x60, 0x0f, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78,
+ 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0, 0x06, 0xf6, 0x10, 0x07, 0x79,
+ 0x20, 0x07, 0x7a, 0x20, 0x07, 0x75, 0x60, 0x07, 0x7a, 0x20, 0x07, 0x75,
+ 0x60, 0x07, 0x6d, 0x60, 0x0f, 0x72, 0x50, 0x07, 0x76, 0xa0, 0x07, 0x72,
+ 0x50, 0x07, 0x76, 0xa0, 0x07, 0x72, 0x50, 0x07, 0x76, 0xd0, 0x06, 0xf6,
+ 0x50, 0x07, 0x71, 0x20, 0x07, 0x7a, 0x50, 0x07, 0x71, 0x20, 0x07, 0x7a,
+ 0x50, 0x07, 0x71, 0x20, 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x00, 0x07, 0x72,
+ 0x40, 0x07, 0x7a, 0x10, 0x07, 0x70, 0x20, 0x07, 0x74, 0xa0, 0x07, 0x71,
+ 0x00, 0x07, 0x72, 0x40, 0x07, 0x6d, 0x60, 0x0e, 0x78, 0x00, 0x07, 0x7a,
+ 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d,
+ 0xe0, 0x0e, 0x78, 0xa0, 0x07, 0x71, 0x60, 0x07, 0x7a, 0x30, 0x07, 0x72,
+ 0x30, 0x84, 0x61, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
+ 0xc2, 0x38, 0x40, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x61,
+ 0x26, 0x20, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb2, 0x40, 0x00,
+ 0x0a, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x14, 0x19, 0x11, 0x4c, 0x90,
+ 0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0x82, 0x23, 0x00, 0x25, 0x50,
+ 0x20, 0x05, 0x18, 0x50, 0x10, 0x45, 0x50, 0x06, 0x05, 0x54, 0x60, 0x85,
+ 0x50, 0x0a, 0xc5, 0x40, 0x77, 0x04, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
+ 0x0d, 0x01, 0x00, 0x00, 0x1a, 0x03, 0x4c, 0x10, 0xd7, 0x20, 0x08, 0x0e,
+ 0x8e, 0xad, 0x0c, 0x84, 0x89, 0xc9, 0xaa, 0x09, 0xc4, 0xae, 0x4c, 0x6e,
+ 0x2e, 0xed, 0xcd, 0x0d, 0x04, 0x07, 0x46, 0xc6, 0x25, 0x06, 0x04, 0xa5,
+ 0xad, 0x8c, 0x2e, 0x8c, 0xcd, 0xac, 0xac, 0x05, 0x07, 0x46, 0xc6, 0x25,
+ 0xc6, 0x65, 0x86, 0x26, 0x65, 0x88, 0x40, 0x01, 0x43, 0x0c, 0x88, 0x80,
+ 0x0e, 0x68, 0x60, 0xd1, 0x54, 0x46, 0x17, 0xc6, 0x36, 0x04, 0xa1, 0x06,
+ 0x88, 0x80, 0x08, 0x68, 0xe0, 0x16, 0x96, 0x26, 0xe7, 0x32, 0xf6, 0xd6,
+ 0x06, 0x97, 0xc6, 0x56, 0xe6, 0x42, 0x56, 0xe6, 0xf6, 0x26, 0xd7, 0x36,
+ 0xf7, 0x45, 0x96, 0x36, 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0xa0, 0x0a,
+ 0x72, 0x61, 0x69, 0x72, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65,
+ 0x2e, 0x66, 0x61, 0x73, 0x74, 0x5f, 0x6d, 0x61, 0x74, 0x68, 0x5f, 0x65,
+ 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x43, 0x04, 0xea, 0x60, 0x19, 0x84, 0xa5,
+ 0xc9, 0xb9, 0x8c, 0xbd, 0xb5, 0xc1, 0xa5, 0xb1, 0x95, 0xb9, 0x98, 0xc9,
+ 0x85, 0xb5, 0x95, 0x89, 0xd5, 0x99, 0x99, 0x95, 0xc9, 0x7d, 0x99, 0x95,
+ 0xd1, 0x8d, 0xa1, 0x7d, 0x91, 0xa5, 0xcd, 0x85, 0x89, 0xb1, 0x95, 0x0d,
+ 0x11, 0xa8, 0x84, 0x61, 0x10, 0x96, 0x26, 0xe7, 0x32, 0xf6, 0xd6, 0x06,
+ 0x97, 0xc6, 0x56, 0xe6, 0xe2, 0x16, 0x46, 0x97, 0x66, 0x57, 0xf6, 0x45,
+ 0xf6, 0x56, 0x27, 0xc6, 0x56, 0xf6, 0x45, 0x96, 0x36, 0x17, 0x26, 0xc6,
+ 0x56, 0x36, 0x44, 0xa0, 0x16, 0x46, 0x61, 0x69, 0x72, 0x2e, 0x72, 0x65,
+ 0x6e, 0x64, 0x65, 0x72, 0x5f, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x8c,
+ 0xc2, 0xd2, 0xe4, 0x5c, 0xc2, 0xe4, 0xce, 0xbe, 0xe8, 0xf2, 0xe0, 0xca,
+ 0xbe, 0xdc, 0xc2, 0xda, 0xca, 0x68, 0x98, 0xb1, 0xbd, 0x85, 0xd1, 0xd1,
+ 0x0c, 0x41, 0xa8, 0x06, 0x1a, 0x28, 0x87, 0x7a, 0x86, 0x08, 0x14, 0x44,
+ 0x26, 0x2c, 0x4d, 0xce, 0x05, 0xee, 0x6d, 0x2e, 0x8d, 0x2e, 0xed, 0xcd,
+ 0x8d, 0x4a, 0x58, 0x9a, 0x9c, 0xcb, 0x58, 0x99, 0x1b, 0x5d, 0x99, 0x1c,
+ 0xa5, 0xb0, 0x34, 0x39, 0x17, 0xb7, 0xb7, 0x2f, 0xb8, 0x32, 0xb9, 0x39,
+ 0xb8, 0xb2, 0x31, 0xba, 0x34, 0xbb, 0x32, 0x32, 0x61, 0x69, 0x72, 0x2e,
+ 0x61, 0x72, 0x67, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x44, 0xe0, 0xde, 0xe6,
+ 0xd2, 0xe8, 0xd2, 0xde, 0xdc, 0x86, 0x40, 0xd0, 0x40, 0x49, 0xd4, 0x44,
+ 0x51, 0x94, 0x43, 0x3d, 0x54, 0x45, 0x59, 0x94, 0xc2, 0xd2, 0xe4, 0x5c,
+ 0xcc, 0xe4, 0xc2, 0xce, 0xda, 0xca, 0xdc, 0xe8, 0xbe, 0xd2, 0xdc, 0xe0,
+ 0xea, 0xe8, 0x98, 0x9d, 0x95, 0xb9, 0x95, 0xc9, 0x85, 0xd1, 0x95, 0x91,
+ 0xa1, 0xe0, 0xd0, 0x95, 0xe1, 0x8d, 0xbd, 0xbd, 0xc9, 0x91, 0x11, 0xd9,
+ 0xc9, 0x7c, 0x99, 0xa5, 0xf0, 0x09, 0x4b, 0x93, 0x73, 0x81, 0x2b, 0x93,
+ 0x9b, 0x83, 0x2b, 0x1b, 0xa3, 0x4b, 0xb3, 0x2b, 0xa3, 0x61, 0xc6, 0xf6,
+ 0x16, 0x46, 0x27, 0x43, 0x84, 0xae, 0x0c, 0x6f, 0xec, 0xed, 0x4d, 0x8e,
+ 0x6c, 0x88, 0x04, 0x11, 0x14, 0x46, 0x65, 0xd4, 0x44, 0x69, 0x94, 0x43,
+ 0x6d, 0x54, 0x45, 0x71, 0x54, 0xc2, 0xd2, 0xe4, 0x5c, 0xc4, 0xea, 0xcc,
+ 0xcc, 0xca, 0xe4, 0xf8, 0x84, 0xa5, 0xc9, 0xb9, 0x88, 0xd5, 0x99, 0x99,
+ 0x95, 0xc9, 0x7d, 0xcd, 0xa5, 0xe9, 0x95, 0x51, 0x0a, 0x4b, 0x93, 0x73,
+ 0x61, 0x7b, 0x1b, 0x0b, 0xa3, 0x4b, 0x7b, 0x73, 0xfb, 0x4a, 0x73, 0x23,
+ 0x2b, 0xc3, 0x23, 0x12, 0x96, 0x26, 0xe7, 0x22, 0x57, 0x16, 0x46, 0xc6,
+ 0x28, 0x2c, 0x4d, 0xce, 0x25, 0x4c, 0xee, 0xec, 0x8b, 0x2e, 0x0f, 0xae,
+ 0xec, 0x6b, 0x2e, 0x4d, 0xaf, 0x8c, 0x57, 0x58, 0x9a, 0x9c, 0x4b, 0x98,
+ 0xdc, 0xd9, 0x17, 0x5d, 0x1e, 0x5c, 0xd9, 0x57, 0x18, 0x5b, 0xda, 0x99,
+ 0xdb, 0xd7, 0x5c, 0x9a, 0x5e, 0x19, 0x87, 0xb1, 0x37, 0xb6, 0x21, 0x60,
+ 0x00, 0x21, 0x94, 0x47, 0x7d, 0x50, 0x41, 0x81, 0x01, 0x34, 0x40, 0x04,
+ 0x15, 0x06, 0x94, 0x18, 0x40, 0x05, 0x35, 0x06, 0x50, 0x41, 0x39, 0xd4,
+ 0x43, 0x55, 0x14, 0x19, 0x90, 0x0a, 0x4b, 0x93, 0x73, 0x99, 0xa3, 0x93,
+ 0xab, 0x1b, 0xa3, 0xfb, 0xa2, 0xcb, 0x83, 0x2b, 0xfb, 0x4a, 0x73, 0x33,
+ 0x7b, 0xa3, 0x61, 0xc6, 0xf6, 0x16, 0x46, 0x37, 0x43, 0xe3, 0xcd, 0xcc,
+ 0x6c, 0xae, 0x8c, 0x8e, 0x86, 0xd4, 0xd8, 0x5b, 0x99, 0x99, 0x19, 0x8d,
+ 0xa3, 0xb1, 0xb7, 0x32, 0x33, 0x33, 0x1a, 0x42, 0x63, 0x6f, 0x65, 0x66,
+ 0x66, 0x43, 0xd0, 0x00, 0x1a, 0xa0, 0x02, 0x1a, 0xa8, 0x33, 0xa0, 0xd0,
+ 0x00, 0x2a, 0xa0, 0x02, 0x1a, 0xa8, 0x33, 0xa0, 0xd2, 0x00, 0x52, 0xa0,
+ 0x02, 0x1a, 0xa8, 0x33, 0xa0, 0xd4, 0x00, 0x5a, 0xa0, 0x02, 0x1a, 0xa8,
+ 0x33, 0xa0, 0xd6, 0x80, 0x49, 0x56, 0x95, 0x15, 0x51, 0xd9, 0xd8, 0x1b,
+ 0x59, 0x19, 0x0d, 0xb2, 0xb2, 0xb1, 0x37, 0xb2, 0xb2, 0x21, 0x64, 0x00,
+ 0x25, 0x94, 0x47, 0x7d, 0x90, 0x41, 0x81, 0x01, 0x44, 0x40, 0x04, 0x15,
+ 0x06, 0x94, 0x19, 0x50, 0x6c, 0x40, 0x89, 0x01, 0x64, 0x50, 0x63, 0x00,
+ 0x15, 0x94, 0x43, 0xb5, 0x01, 0x55, 0x51, 0x6e, 0xc0, 0x25, 0x2c, 0x4d,
+ 0xce, 0x85, 0xae, 0x0c, 0x8f, 0xae, 0x4e, 0xae, 0x8c, 0x4a, 0x58, 0x9a,
+ 0x9c, 0xcb, 0x5c, 0x58, 0x1b, 0x1c, 0x5b, 0x19, 0x31, 0xba, 0x32, 0x3c,
+ 0xba, 0x3a, 0xb9, 0x32, 0x19, 0x32, 0x1e, 0x33, 0xb6, 0xb7, 0x30, 0x3a,
+ 0x16, 0x90, 0xb9, 0xb0, 0x36, 0x38, 0xb6, 0x32, 0x1f, 0x12, 0x74, 0x65,
+ 0x78, 0x59, 0x43, 0x28, 0x88, 0xa1, 0xe0, 0x80, 0x02, 0x03, 0x68, 0x80,
+ 0x08, 0x2a, 0x0e, 0x28, 0x87, 0x92, 0x03, 0xaa, 0xa2, 0xe6, 0x80, 0x05,
+ 0x5d, 0x19, 0x5e, 0x95, 0xd5, 0x10, 0x0a, 0x6a, 0x28, 0x38, 0xa0, 0xc0,
+ 0x00, 0x22, 0x20, 0x82, 0x8a, 0x03, 0xca, 0xa1, 0xe4, 0x80, 0xaa, 0xa8,
+ 0x3a, 0xe0, 0x12, 0x96, 0x26, 0xe7, 0x32, 0x17, 0xd6, 0x06, 0xc7, 0x56,
+ 0x26, 0xc7, 0x63, 0x2e, 0xac, 0x0d, 0x8e, 0xad, 0x4c, 0x8e, 0xc1, 0xdc,
+ 0x10, 0x09, 0x72, 0xa8, 0x3b, 0xa0, 0xc0, 0x00, 0x1a, 0x20, 0x82, 0x72,
+ 0x28, 0x3c, 0xa0, 0x2a, 0x2a, 0x0f, 0x86, 0x38, 0xd4, 0x45, 0x75, 0x54,
+ 0x19, 0x50, 0x6f, 0x40, 0xd1, 0x01, 0x65, 0x07, 0x94, 0x1e, 0x0c, 0x31,
+ 0x18, 0x80, 0x8a, 0xa8, 0x3d, 0xe0, 0xf3, 0xd6, 0xe6, 0x96, 0x06, 0xf7,
+ 0x46, 0x57, 0xe6, 0x46, 0x07, 0x32, 0x86, 0x16, 0x26, 0xc7, 0x67, 0x2a,
+ 0xad, 0x0d, 0x8e, 0xad, 0x0c, 0x64, 0x68, 0x65, 0x05, 0x84, 0x4a, 0x28,
+ 0x28, 0x68, 0x88, 0x40, 0xf9, 0xc1, 0x10, 0x83, 0xea, 0x03, 0xea, 0x0f,
+ 0xae, 0x67, 0x88, 0x41, 0x81, 0x02, 0x05, 0x0a, 0xd7, 0x33, 0x42, 0x61,
+ 0x07, 0x76, 0xb0, 0x87, 0x76, 0x70, 0x83, 0x74, 0x20, 0x87, 0x72, 0x70,
+ 0x07, 0x7a, 0x98, 0x12, 0x04, 0x23, 0x96, 0x70, 0x48, 0x07, 0x79, 0x70,
+ 0x03, 0x7b, 0x28, 0x07, 0x79, 0x98, 0x87, 0x74, 0x78, 0x07, 0x77, 0x98,
+ 0x12, 0x08, 0x23, 0xa8, 0x70, 0x48, 0x07, 0x79, 0x70, 0x03, 0x76, 0x08,
+ 0x07, 0x77, 0x38, 0x87, 0x7a, 0x08, 0x87, 0x73, 0x28, 0x87, 0x5f, 0xb0,
+ 0x87, 0x72, 0x90, 0x87, 0x79, 0x48, 0x87, 0x77, 0x70, 0x87, 0x29, 0x01,
+ 0x31, 0x62, 0x0a, 0x87, 0x74, 0x90, 0x07, 0x37, 0x18, 0x87, 0x77, 0x68,
+ 0x07, 0x78, 0x48, 0x07, 0x76, 0x28, 0x87, 0x5f, 0x78, 0x07, 0x78, 0xa0,
+ 0x87, 0x74, 0x78, 0x07, 0x77, 0x98, 0x87, 0x29, 0x84, 0x81, 0x28, 0xcc,
+ 0x08, 0x26, 0x1c, 0xd2, 0x41, 0x1e, 0xdc, 0xc0, 0x1c, 0xe4, 0x21, 0x1c,
+ 0xce, 0xa1, 0x1d, 0xca, 0xc1, 0x1d, 0xe8, 0x61, 0x4a, 0xc0, 0x07, 0x00,
+ 0x79, 0x18, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x33, 0x08, 0x80, 0x1c,
+ 0xc4, 0xe1, 0x1c, 0x66, 0x14, 0x01, 0x3d, 0x88, 0x43, 0x38, 0x84, 0xc3,
+ 0x8c, 0x42, 0x80, 0x07, 0x79, 0x78, 0x07, 0x73, 0x98, 0x71, 0x0c, 0xe6,
+ 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x33, 0x0c, 0x42, 0x1e,
+ 0xc2, 0xc1, 0x1d, 0xce, 0xa1, 0x1c, 0x66, 0x30, 0x05, 0x3d, 0x88, 0x43,
+ 0x38, 0x84, 0x83, 0x1b, 0xcc, 0x03, 0x3d, 0xc8, 0x43, 0x3d, 0x8c, 0x03,
+ 0x3d, 0xcc, 0x78, 0x8c, 0x74, 0x70, 0x07, 0x7b, 0x08, 0x07, 0x79, 0x48,
+ 0x87, 0x70, 0x70, 0x07, 0x7a, 0x70, 0x03, 0x76, 0x78, 0x87, 0x70, 0x20,
+ 0x87, 0x19, 0xcc, 0x11, 0x0e, 0xec, 0x90, 0x0e, 0xe1, 0x30, 0x0f, 0x6e,
+ 0x30, 0x0f, 0xe3, 0xf0, 0x0e, 0xf0, 0x50, 0x0e, 0x33, 0x10, 0xc4, 0x1d,
+ 0xde, 0x21, 0x1c, 0xd8, 0x21, 0x1d, 0xc2, 0x61, 0x1e, 0x66, 0x30, 0x89,
+ 0x3b, 0xbc, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xb4, 0x03, 0x3c, 0xbc, 0x83,
+ 0x3c, 0x84, 0x03, 0x3b, 0xcc, 0xf0, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68,
+ 0x07, 0x37, 0x68, 0x87, 0x72, 0x68, 0x07, 0x37, 0x80, 0x87, 0x70, 0x90,
+ 0x87, 0x70, 0x60, 0x07, 0x76, 0x28, 0x07, 0x76, 0xf8, 0x05, 0x76, 0x78,
+ 0x87, 0x77, 0x80, 0x87, 0x5f, 0x08, 0x87, 0x71, 0x18, 0x87, 0x72, 0x98,
+ 0x87, 0x79, 0x98, 0x81, 0x2c, 0xee, 0xf0, 0x0e, 0xee, 0xe0, 0x0e, 0xf5,
+ 0xc0, 0x0e, 0xec, 0x30, 0x03, 0x62, 0xc8, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c,
+ 0xcc, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xdc, 0x61, 0x1c, 0xca, 0x21, 0x1c,
+ 0xc4, 0x81, 0x1d, 0xca, 0x61, 0x06, 0xd6, 0x90, 0x43, 0x39, 0xc8, 0x43,
+ 0x39, 0x98, 0x43, 0x39, 0xc8, 0x43, 0x39, 0xb8, 0xc3, 0x38, 0x94, 0x43,
+ 0x38, 0x88, 0x03, 0x3b, 0x94, 0xc3, 0x2f, 0xbc, 0x83, 0x3c, 0xfc, 0x82,
+ 0x3b, 0xd4, 0x03, 0x3b, 0xb0, 0xc3, 0x0c, 0xc7, 0x69, 0x87, 0x70, 0x58,
+ 0x87, 0x72, 0x70, 0x83, 0x74, 0x68, 0x07, 0x78, 0x60, 0x87, 0x74, 0x18,
+ 0x87, 0x74, 0xa0, 0x87, 0x19, 0xce, 0x53, 0x0f, 0xee, 0x00, 0x0f, 0xf2,
+ 0x50, 0x0e, 0xe4, 0x90, 0x0e, 0xe3, 0x40, 0x0f, 0xe1, 0x20, 0x0e, 0xec,
+ 0x50, 0x0e, 0x33, 0x20, 0x28, 0x1d, 0xdc, 0xc1, 0x1e, 0xc2, 0x41, 0x1e,
+ 0xd2, 0x21, 0x1c, 0xdc, 0x81, 0x1e, 0xdc, 0xe0, 0x1c, 0xe4, 0xe1, 0x1d,
+ 0xea, 0x01, 0x1e, 0x66, 0x18, 0x51, 0x38, 0xb0, 0x43, 0x3a, 0x9c, 0x83,
+ 0x3b, 0xcc, 0x50, 0x24, 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x60,
+ 0x87, 0x77, 0x78, 0x07, 0x78, 0x98, 0x51, 0x4c, 0xf4, 0x90, 0x0f, 0xf0,
+ 0x50, 0x0e, 0x00, 0x00, 0x71, 0x20, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00,
+ 0x16, 0xd0, 0x00, 0x48, 0xe4, 0x0f, 0xce, 0xe4, 0x57, 0x77, 0x71, 0xdb,
+ 0x26, 0xb0, 0x01, 0x48, 0xe4, 0x4b, 0x00, 0xf3, 0x2c, 0xc4, 0x3f, 0x11,
+ 0xd7, 0x44, 0x45, 0xc4, 0x6f, 0x0f, 0x7e, 0x85, 0x17, 0xb7, 0x6d, 0x00,
+ 0x11, 0xdb, 0x95, 0xff, 0xf9, 0xd6, 0xf6, 0x5f, 0x44, 0x80, 0xc1, 0x10,
+ 0xcd, 0x04, 0x00, 0x00, 0x61, 0x20, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00,
+ 0x13, 0x04, 0x41, 0x2c, 0x10, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00,
+ 0x64, 0xe7, 0x20, 0x06, 0x02, 0xe9, 0xa8, 0x8e, 0x35, 0x00, 0x03, 0x31,
+ 0xc7, 0x30, 0x10, 0xdd, 0x1c, 0xc3, 0xd0, 0x75, 0xf4, 0x6a, 0x60, 0x04,
+ 0x80, 0xe0, 0x0c, 0x00, 0xc5, 0x11, 0x00, 0xaa, 0x63, 0x0d, 0x40, 0x20,
+ 0x10, 0x99, 0x01, 0xa0, 0x30, 0x03, 0x40, 0x60, 0x8c, 0x00, 0x04, 0x41,
+ 0x10, 0xff, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x06, 0xca, 0x10,
+ 0x88, 0x01, 0xe4, 0x4c, 0x89, 0x81, 0x04, 0x23, 0x06, 0xca, 0x10, 0x8c,
+ 0x01, 0xf4, 0x50, 0xca, 0x91, 0x08, 0x83, 0x0c, 0x42, 0xc1, 0x0c, 0x32,
+ 0x08, 0x86, 0x33, 0xc8, 0x20, 0x04, 0xd0, 0x20, 0x43, 0x90, 0x48, 0x77,
+ 0x8d, 0xa5, 0xa0, 0xd8, 0x10, 0xc0, 0x87, 0xb6, 0x32, 0xc8, 0x20, 0x34,
+ 0xcf, 0x78, 0x03, 0x07, 0x06, 0x6b, 0x70, 0xc1, 0x58, 0x0a, 0xca, 0x20,
+ 0x43, 0x10, 0x4d, 0x23, 0x06, 0x05, 0x11, 0xc8, 0x41, 0x11, 0xcc, 0x31,
+ 0x4c, 0x41, 0x1c, 0x8c, 0x37, 0x88, 0x81, 0x19, 0xb4, 0xc1, 0x05, 0x63,
+ 0x29, 0x28, 0x83, 0x0c, 0xc1, 0x95, 0x8d, 0x18, 0x14, 0x44, 0x80, 0x07,
+ 0x4b, 0x30, 0xc7, 0x60, 0x04, 0x76, 0x30, 0xde, 0x80, 0x06, 0x6c, 0x20,
+ 0x07, 0x17, 0x8c, 0xa5, 0xa0, 0x0c, 0x32, 0x04, 0xdd, 0x37, 0x62, 0x50,
+ 0x10, 0x81, 0x1f, 0x44, 0xc1, 0x1c, 0x83, 0x11, 0xe0, 0xc1, 0x1c, 0x43,
+ 0xf0, 0xe1, 0x81, 0x05, 0x95, 0x7c, 0x32, 0x08, 0x88, 0x01, 0x00, 0x00,
+ 0x02, 0x00, 0x00, 0x00, 0x5b, 0x86, 0x24, 0x08, 0x05, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xde, 0xc0, 0x17, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
+ 0x00, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x42, 0x43, 0xc0, 0xde,
+ 0x21, 0x0c, 0x00, 0x00, 0x7d, 0x03, 0x00, 0x00, 0x0b, 0x82, 0x20, 0x00,
+ 0x02, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x07, 0x81, 0x23, 0x91,
+ 0x41, 0xc8, 0x04, 0x49, 0x06, 0x10, 0x32, 0x39, 0x92, 0x01, 0x84, 0x0c,
+ 0x25, 0x05, 0x08, 0x19, 0x1e, 0x04, 0x8b, 0x62, 0x80, 0x14, 0x45, 0x02,
+ 0x42, 0x92, 0x0b, 0x42, 0xa4, 0x10, 0x32, 0x14, 0x38, 0x08, 0x18, 0x49,
+ 0x0a, 0x32, 0x44, 0x24, 0x48, 0x0a, 0x90, 0x21, 0x23, 0xc4, 0x52, 0x80,
+ 0x0c, 0x19, 0x21, 0x72, 0x24, 0x07, 0xc8, 0x48, 0x11, 0x62, 0xa8, 0xa0,
+ 0xa8, 0x40, 0xc6, 0xf0, 0x01, 0x00, 0x00, 0x00, 0x51, 0x18, 0x00, 0x00,
+ 0x03, 0x01, 0x00, 0x00, 0x1b, 0x8c, 0x60, 0x00, 0x16, 0xa0, 0xda, 0x60,
+ 0x08, 0x04, 0xb0, 0x00, 0xd5, 0x06, 0x63, 0x38, 0x80, 0x05, 0xa8, 0x36,
+ 0x90, 0x0b, 0xf1, 0xff, 0xff, 0xff, 0xff, 0x03, 0xc0, 0x00, 0x12, 0x31,
+ 0x0e, 0xef, 0x20, 0x0f, 0xf2, 0x50, 0x0e, 0xe3, 0x40, 0x0f, 0xec, 0x90,
+ 0x0f, 0x6d, 0x20, 0x0f, 0xef, 0x50, 0x0f, 0xee, 0x40, 0x0e, 0xe5, 0x40,
+ 0x0e, 0x6d, 0x40, 0x0e, 0xe9, 0x60, 0x0f, 0xe9, 0x40, 0x0e, 0xe5, 0xd0,
+ 0x06, 0xf3, 0x10, 0x0f, 0xf2, 0x40, 0x0f, 0x6d, 0x60, 0x0e, 0xf0, 0xd0,
+ 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x80, 0x39, 0x84, 0x03, 0x3b,
+ 0xcc, 0x43, 0x39, 0x00, 0x04, 0x39, 0xa4, 0xc3, 0x3c, 0x84, 0x83, 0x38,
+ 0xb0, 0x43, 0x39, 0xb4, 0x01, 0x3d, 0x84, 0x43, 0x3a, 0xb0, 0x43, 0x1b,
+ 0x8c, 0x43, 0x38, 0xb0, 0x03, 0x3b, 0xcc, 0x03, 0x60, 0x0e, 0xe1, 0xc0,
+ 0x0e, 0xf3, 0x50, 0x0e, 0x00, 0xc1, 0x0e, 0xe5, 0x30, 0x0f, 0xf3, 0xd0,
+ 0x06, 0xf0, 0x20, 0x0f, 0xe5, 0x30, 0x0e, 0xe9, 0x30, 0x0f, 0xe5, 0xd0,
+ 0x06, 0xe6, 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xe4, 0x00, 0xd0, 0x83, 0x3c,
+ 0xd4, 0x43, 0x39, 0x00, 0x84, 0x3b, 0xbc, 0x43, 0x1b, 0x98, 0x83, 0x3c,
+ 0x84, 0x43, 0x3b, 0x94, 0x43, 0x1b, 0xc0, 0xc3, 0x3b, 0xa4, 0x83, 0x3b,
+ 0xd0, 0x43, 0x39, 0xc8, 0x43, 0x1b, 0x94, 0x03, 0x3b, 0xa4, 0x43, 0x3b,
+ 0x00, 0xf4, 0x20, 0x0f, 0xf5, 0x50, 0x0e, 0xc0, 0xe0, 0x0e, 0xef, 0xd0,
+ 0x06, 0xe6, 0x20, 0x0f, 0xe1, 0xd0, 0x0e, 0xe5, 0xd0, 0x06, 0xf0, 0xf0,
+ 0x0e, 0xe9, 0xe0, 0x0e, 0xf4, 0x50, 0x0e, 0xf2, 0xd0, 0x06, 0xe5, 0xc0,
+ 0x0e, 0xe9, 0xd0, 0x0e, 0x6d, 0xe0, 0x0e, 0xef, 0xe0, 0x0e, 0x6d, 0xc0,
+ 0x0e, 0xe5, 0x10, 0x0e, 0xe6, 0x00, 0x10, 0xee, 0xf0, 0x0e, 0x6d, 0x90,
+ 0x0e, 0xee, 0x60, 0x0e, 0xf3, 0xd0, 0x06, 0xe6, 0x00, 0x0f, 0x6d, 0xd0,
+ 0x0e, 0xe1, 0x40, 0x0f, 0xe8, 0x00, 0xd0, 0x83, 0x3c, 0xd4, 0x43, 0x39,
+ 0x00, 0x84, 0x3b, 0xbc, 0x43, 0x1b, 0xa8, 0x43, 0x3d, 0xb4, 0x03, 0x3c,
+ 0xb4, 0x01, 0x3d, 0x84, 0x83, 0x38, 0xb0, 0x43, 0x39, 0xcc, 0x03, 0x60,
+ 0x0e, 0xe1, 0xc0, 0x0e, 0xf3, 0x50, 0x0e, 0x00, 0xe1, 0x0e, 0xef, 0xd0,
+ 0x06, 0xee, 0x10, 0x0e, 0xee, 0x30, 0x0f, 0x6d, 0x60, 0x0e, 0xf0, 0xd0,
+ 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x00, 0x3d, 0xc8, 0x43, 0x3d,
+ 0x94, 0x03, 0x40, 0xb8, 0xc3, 0x3b, 0xb4, 0xc1, 0x3c, 0xa4, 0xc3, 0x39,
+ 0xb8, 0x43, 0x39, 0x90, 0x43, 0x1b, 0xe8, 0x43, 0x39, 0xc8, 0xc3, 0x3b,
+ 0xcc, 0x43, 0x1b, 0x98, 0x03, 0x3c, 0xb4, 0x41, 0x3b, 0x84, 0x03, 0x3d,
+ 0xa0, 0x03, 0x60, 0x0e, 0xe1, 0xc0, 0x0e, 0xf3, 0x50, 0x0e, 0x00, 0x31,
+ 0x0f, 0xf4, 0x10, 0x0e, 0xe3, 0xb0, 0x0e, 0x6d, 0x00, 0x0f, 0xf2, 0xf0,
+ 0x0e, 0xf4, 0x50, 0x0e, 0xe3, 0x40, 0x0f, 0xef, 0x20, 0x0f, 0x6d, 0x20,
+ 0x0e, 0xf5, 0x60, 0x0e, 0xe6, 0x50, 0x0e, 0xf2, 0xd0, 0x06, 0xf3, 0x90,
+ 0x0e, 0xfa, 0x50, 0x0e, 0x00, 0x1e, 0x00, 0x04, 0x3d, 0x84, 0x83, 0x3c,
+ 0x9c, 0x43, 0x39, 0xd0, 0x43, 0x1b, 0x98, 0x43, 0x39, 0x84, 0x03, 0x3d,
+ 0xd4, 0x83, 0x3c, 0x94, 0xc3, 0x3c, 0x00, 0x6d, 0x60, 0x0e, 0xf0, 0x10,
+ 0x07, 0x76, 0x00, 0x10, 0xf5, 0xe0, 0x0e, 0xf3, 0x10, 0x0e, 0xe6, 0x50,
+ 0x0e, 0x6d, 0x60, 0x0e, 0xf0, 0xd0, 0x06, 0xed, 0x10, 0x0e, 0xf4, 0x80,
+ 0x0e, 0x00, 0x3d, 0xc8, 0x43, 0x3d, 0x94, 0x03, 0x40, 0xd4, 0xc3, 0x3c,
+ 0x94, 0x43, 0x1b, 0xcc, 0xc3, 0x3b, 0x98, 0x03, 0x3d, 0xb4, 0x81, 0x39,
+ 0xb0, 0xc3, 0x3b, 0x84, 0x03, 0x3d, 0x00, 0xe6, 0x10, 0x0e, 0xec, 0x30,
+ 0x0f, 0xe5, 0x00, 0x6c, 0x50, 0x95, 0xe2, 0xff, 0xff, 0xff, 0xff, 0x07,
+ 0x62, 0x1c, 0xde, 0x41, 0x1e, 0xe4, 0xa1, 0x1c, 0xc6, 0x81, 0x1e, 0xd8,
+ 0x21, 0x1f, 0xda, 0x40, 0x1e, 0xde, 0xa1, 0x1e, 0xdc, 0x81, 0x1c, 0xca,
+ 0x81, 0x1c, 0xda, 0x80, 0x1c, 0xd2, 0xc1, 0x1e, 0xd2, 0x81, 0x1c, 0xca,
+ 0xa1, 0x0d, 0xe6, 0x21, 0x1e, 0xe4, 0x81, 0x1e, 0xda, 0xc0, 0x1c, 0xe0,
+ 0xa1, 0x0d, 0xda, 0x21, 0x1c, 0xe8, 0x01, 0x1d, 0x00, 0x73, 0x08, 0x07,
+ 0x76, 0x98, 0x87, 0x72, 0x00, 0x08, 0x72, 0x48, 0x87, 0x79, 0x08, 0x07,
+ 0x71, 0x60, 0x87, 0x72, 0x68, 0x03, 0x7a, 0x08, 0x87, 0x74, 0x60, 0x87,
+ 0x36, 0x18, 0x87, 0x70, 0x60, 0x07, 0x76, 0x98, 0x07, 0xc0, 0x1c, 0xc2,
+ 0x81, 0x1d, 0xe6, 0xa1, 0x1c, 0x00, 0x82, 0x1d, 0xca, 0x61, 0x1e, 0xe6,
+ 0xa1, 0x0d, 0xe0, 0x41, 0x1e, 0xca, 0x61, 0x1c, 0xd2, 0x61, 0x1e, 0xca,
+ 0xa1, 0x0d, 0xcc, 0x01, 0x1e, 0xda, 0x21, 0x1c, 0xc8, 0x01, 0xa0, 0x07,
+ 0x79, 0xa8, 0x87, 0x72, 0x00, 0x08, 0x77, 0x78, 0x87, 0x36, 0x30, 0x07,
+ 0x79, 0x08, 0x87, 0x76, 0x28, 0x87, 0x36, 0x80, 0x87, 0x77, 0x48, 0x07,
+ 0x77, 0xa0, 0x87, 0x72, 0x90, 0x87, 0x36, 0x28, 0x07, 0x76, 0x48, 0x87,
+ 0x76, 0x00, 0xe8, 0x41, 0x1e, 0xea, 0xa1, 0x1c, 0x80, 0xc1, 0x1d, 0xde,
+ 0xa1, 0x0d, 0xcc, 0x41, 0x1e, 0xc2, 0xa1, 0x1d, 0xca, 0xa1, 0x0d, 0xe0,
+ 0xe1, 0x1d, 0xd2, 0xc1, 0x1d, 0xe8, 0xa1, 0x1c, 0xe4, 0xa1, 0x0d, 0xca,
+ 0x81, 0x1d, 0xd2, 0xa1, 0x1d, 0xda, 0xc0, 0x1d, 0xde, 0xc1, 0x1d, 0xda,
+ 0x80, 0x1d, 0xca, 0x21, 0x1c, 0xcc, 0x01, 0x20, 0xdc, 0xe1, 0x1d, 0xda,
+ 0x20, 0x1d, 0xdc, 0xc1, 0x1c, 0xe6, 0xa1, 0x0d, 0xcc, 0x01, 0x1e, 0xda,
+ 0xa0, 0x1d, 0xc2, 0x81, 0x1e, 0xd0, 0x01, 0xa0, 0x07, 0x79, 0xa8, 0x87,
+ 0x72, 0x00, 0x08, 0x77, 0x78, 0x87, 0x36, 0x70, 0x87, 0x70, 0x70, 0x87,
+ 0x79, 0x68, 0x03, 0x73, 0x80, 0x87, 0x36, 0x68, 0x87, 0x70, 0xa0, 0x07,
+ 0x74, 0x00, 0xe8, 0x41, 0x1e, 0xea, 0xa1, 0x1c, 0x00, 0xc2, 0x1d, 0xde,
+ 0xa1, 0x0d, 0xe6, 0x21, 0x1d, 0xce, 0xc1, 0x1d, 0xca, 0x81, 0x1c, 0xda,
+ 0x40, 0x1f, 0xca, 0x41, 0x1e, 0xde, 0x61, 0x1e, 0xda, 0xc0, 0x1c, 0xe0,
+ 0xa1, 0x0d, 0xda, 0x21, 0x1c, 0xe8, 0x01, 0x1d, 0x00, 0x73, 0x08, 0x07,
+ 0x76, 0x98, 0x87, 0x72, 0x00, 0x88, 0x79, 0xa0, 0x87, 0x70, 0x18, 0x87,
+ 0x75, 0x68, 0x03, 0x78, 0x90, 0x87, 0x77, 0xa0, 0x87, 0x72, 0x18, 0x07,
+ 0x7a, 0x78, 0x07, 0x79, 0x68, 0x03, 0x71, 0xa8, 0x07, 0x73, 0x30, 0x87,
+ 0x72, 0x90, 0x87, 0x36, 0x98, 0x87, 0x74, 0xd0, 0x87, 0x72, 0x00, 0xf0,
+ 0x00, 0x20, 0xe8, 0x21, 0x1c, 0xe4, 0xe1, 0x1c, 0xca, 0x81, 0x1e, 0xda,
+ 0xc0, 0x1c, 0xca, 0x21, 0x1c, 0xe8, 0xa1, 0x1e, 0xe4, 0xa1, 0x1c, 0xe6,
+ 0x01, 0x68, 0x03, 0x73, 0x80, 0x87, 0x38, 0xb0, 0x03, 0x80, 0xa8, 0x07,
+ 0x77, 0x98, 0x87, 0x70, 0x30, 0x87, 0x72, 0x68, 0x03, 0x73, 0x80, 0x87,
+ 0x36, 0x68, 0x87, 0x70, 0xa0, 0x07, 0x74, 0x00, 0xe8, 0x41, 0x1e, 0xea,
+ 0xa1, 0x1c, 0x00, 0xa2, 0x1e, 0xe6, 0xa1, 0x1c, 0xda, 0x60, 0x1e, 0xde,
+ 0xc1, 0x1c, 0xe8, 0xa1, 0x0d, 0xcc, 0x81, 0x1d, 0xde, 0x21, 0x1c, 0xe8,
+ 0x01, 0x30, 0x87, 0x70, 0x60, 0x87, 0x79, 0x28, 0x07, 0x60, 0x03, 0x61,
+ 0x04, 0xc0, 0xb2, 0x81, 0x38, 0x04, 0x60, 0xd9, 0x80, 0x20, 0xff, 0xff,
+ 0xff, 0xff, 0x3f, 0x00, 0x0c, 0x20, 0x01, 0xd5, 0x06, 0x22, 0xf9, 0xff,
+ 0xff, 0xff, 0xff, 0x01, 0x90, 0x00, 0x00, 0x00, 0x49, 0x18, 0x00, 0x00,
+ 0x04, 0x00, 0x00, 0x00, 0x13, 0x88, 0x40, 0x18, 0x88, 0x09, 0x41, 0x31,
+ 0x61, 0x30, 0x0e, 0x64, 0x42, 0x90, 0x00, 0x00, 0x89, 0x20, 0x00, 0x00,
+ 0x28, 0x00, 0x00, 0x00, 0x32, 0x22, 0x48, 0x09, 0x20, 0x64, 0x85, 0x04,
+ 0x93, 0x22, 0xa4, 0x84, 0x04, 0x93, 0x22, 0xe3, 0x84, 0xa1, 0x90, 0x14,
+ 0x12, 0x4c, 0x8a, 0x8c, 0x0b, 0x84, 0xa4, 0x4c, 0x10, 0x68, 0x33, 0x00,
+ 0xc3, 0x08, 0x04, 0x30, 0x8c, 0x20, 0x00, 0x83, 0x08, 0x81, 0x30, 0x8c,
+ 0x30, 0x00, 0x07, 0x49, 0x53, 0x44, 0x09, 0x93, 0x2f, 0xbb, 0x6f, 0x47,
+ 0x08, 0xce, 0x40, 0x20, 0x82, 0x10, 0x42, 0x06, 0x11, 0x0a, 0xe1, 0x28,
+ 0x69, 0x8a, 0x28, 0x61, 0xf2, 0xff, 0x89, 0xb8, 0x26, 0x2a, 0x22, 0x7e,
+ 0x7b, 0xf8, 0xa7, 0x31, 0x02, 0x60, 0x10, 0xe1, 0x08, 0x2e, 0x92, 0xa6,
+ 0x88, 0x12, 0x26, 0xff, 0x97, 0x00, 0xe6, 0x59, 0x88, 0xe8, 0x9f, 0xc6,
+ 0x08, 0x80, 0x41, 0x84, 0x44, 0x28, 0x48, 0x08, 0x62, 0x18, 0x84, 0x14,
+ 0xad, 0x32, 0x00, 0x42, 0xa8, 0xcd, 0x11, 0x04, 0x73, 0x04, 0x60, 0x30,
+ 0x8c, 0x20, 0x40, 0x05, 0x09, 0x48, 0x89, 0x17, 0x1f, 0x20, 0x39, 0x10,
+ 0x30, 0x8c, 0x30, 0x40, 0xc3, 0x08, 0x04, 0x34, 0x47, 0x00, 0x0a, 0x83,
+ 0x08, 0x84, 0x30, 0x02, 0x00, 0x00, 0x00, 0x00, 0x13, 0xb2, 0x70, 0x48,
+ 0x07, 0x79, 0xb0, 0x03, 0x3a, 0x68, 0x83, 0x70, 0x80, 0x07, 0x78, 0x60,
+ 0x87, 0x72, 0x68, 0x83, 0x76, 0x08, 0x87, 0x71, 0x78, 0x87, 0x79, 0xc0,
+ 0x87, 0x38, 0x80, 0x03, 0x37, 0x88, 0x83, 0x38, 0x70, 0x03, 0x38, 0xd8,
+ 0xf0, 0x1e, 0xe5, 0xd0, 0x06, 0xf0, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x7a,
+ 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x90, 0x0e, 0x71,
+ 0xa0, 0x07, 0x78, 0xa0, 0x07, 0x78, 0xd0, 0x06, 0xe9, 0x80, 0x07, 0x7a,
+ 0x80, 0x07, 0x7a, 0x80, 0x07, 0x6d, 0x90, 0x0e, 0x71, 0x60, 0x07, 0x7a,
+ 0x10, 0x07, 0x76, 0xa0, 0x07, 0x71, 0x60, 0x07, 0x6d, 0x90, 0x0e, 0x73,
+ 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d,
+ 0x90, 0x0e, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76,
+ 0x40, 0x07, 0x6d, 0x60, 0x0e, 0x73, 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72,
+ 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0e, 0x76, 0x40, 0x07, 0x7a,
+ 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x60, 0x0e, 0x78,
+ 0x00, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72,
+ 0x80, 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x60, 0x07, 0x7a, 0x10, 0x07, 0x76,
+ 0xa0, 0x07, 0x71, 0x60, 0x07, 0x6d, 0x60, 0x0f, 0x72, 0x40, 0x07, 0x7a,
+ 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d, 0x60, 0x0f, 0x73,
+ 0x20, 0x07, 0x7a, 0x30, 0x07, 0x72, 0xa0, 0x07, 0x73, 0x20, 0x07, 0x6d,
+ 0x60, 0x0f, 0x74, 0x80, 0x07, 0x7a, 0x60, 0x07, 0x74, 0xa0, 0x07, 0x76,
+ 0x40, 0x07, 0x6d, 0x60, 0x0f, 0x76, 0x40, 0x07, 0x7a, 0x60, 0x07, 0x74,
+ 0xa0, 0x07, 0x76, 0x40, 0x07, 0x6d, 0x60, 0x0f, 0x79, 0x60, 0x07, 0x7a,
+ 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d,
+ 0x60, 0x0f, 0x71, 0x20, 0x07, 0x78, 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78,
+ 0xa0, 0x07, 0x71, 0x20, 0x07, 0x78, 0xd0, 0x06, 0xf6, 0x10, 0x07, 0x79,
+ 0x20, 0x07, 0x7a, 0x20, 0x07, 0x75, 0x60, 0x07, 0x7a, 0x20, 0x07, 0x75,
+ 0x60, 0x07, 0x6d, 0x60, 0x0f, 0x72, 0x50, 0x07, 0x76, 0xa0, 0x07, 0x72,
+ 0x50, 0x07, 0x76, 0xa0, 0x07, 0x72, 0x50, 0x07, 0x76, 0xd0, 0x06, 0xf6,
+ 0x50, 0x07, 0x71, 0x20, 0x07, 0x7a, 0x50, 0x07, 0x71, 0x20, 0x07, 0x7a,
+ 0x50, 0x07, 0x71, 0x20, 0x07, 0x6d, 0x60, 0x0f, 0x71, 0x00, 0x07, 0x72,
+ 0x40, 0x07, 0x7a, 0x10, 0x07, 0x70, 0x20, 0x07, 0x74, 0xa0, 0x07, 0x71,
+ 0x00, 0x07, 0x72, 0x40, 0x07, 0x6d, 0x60, 0x0e, 0x78, 0x00, 0x07, 0x7a,
+ 0x10, 0x07, 0x72, 0x80, 0x07, 0x7a, 0x10, 0x07, 0x72, 0x80, 0x07, 0x6d,
+ 0xe0, 0x0e, 0x78, 0xa0, 0x07, 0x71, 0x60, 0x07, 0x7a, 0x30, 0x07, 0x72,
+ 0x30, 0x84, 0x61, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
+ 0xc2, 0x38, 0x40, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x61,
+ 0x26, 0x20, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb2, 0x40, 0x00,
+ 0x0a, 0x00, 0x00, 0x00, 0x32, 0x1e, 0x98, 0x14, 0x19, 0x11, 0x4c, 0x90,
+ 0x8c, 0x09, 0x26, 0x47, 0xc6, 0x04, 0x43, 0x82, 0x23, 0x00, 0x25, 0x50,
+ 0x20, 0x05, 0x18, 0x50, 0x10, 0x45, 0x50, 0x06, 0x05, 0x54, 0x60, 0x85,
+ 0x50, 0x0a, 0xc5, 0x40, 0x77, 0x04, 0x00, 0x00, 0x79, 0x18, 0x00, 0x00,
+ 0x0d, 0x01, 0x00, 0x00, 0x1a, 0x03, 0x4c, 0x10, 0xd7, 0x20, 0x08, 0x0e,
+ 0x8e, 0xad, 0x0c, 0x84, 0x89, 0xc9, 0xaa, 0x09, 0xc4, 0xae, 0x4c, 0x6e,
+ 0x2e, 0xed, 0xcd, 0x0d, 0x04, 0x07, 0x46, 0xc6, 0x25, 0x06, 0x04, 0xa5,
+ 0xad, 0x8c, 0x2e, 0x8c, 0xcd, 0xac, 0xac, 0x05, 0x07, 0x46, 0xc6, 0x25,
+ 0xc6, 0x65, 0x86, 0x26, 0x65, 0x88, 0x40, 0x01, 0x43, 0x0c, 0x88, 0x80,
+ 0x0e, 0x68, 0x60, 0xd1, 0x54, 0x46, 0x17, 0xc6, 0x36, 0x04, 0xa1, 0x06,
+ 0x88, 0x80, 0x08, 0x68, 0xe0, 0x16, 0x96, 0x26, 0xe7, 0x32, 0xf6, 0xd6,
+ 0x06, 0x97, 0xc6, 0x56, 0xe6, 0x42, 0x56, 0xe6, 0xf6, 0x26, 0xd7, 0x36,
+ 0xf7, 0x45, 0x96, 0x36, 0x17, 0x26, 0xc6, 0x56, 0x36, 0x44, 0xa0, 0x0a,
+ 0x72, 0x61, 0x69, 0x72, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65,
+ 0x2e, 0x66, 0x61, 0x73, 0x74, 0x5f, 0x6d, 0x61, 0x74, 0x68, 0x5f, 0x65,
+ 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x43, 0x04, 0xea, 0x60, 0x19, 0x84, 0xa5,
+ 0xc9, 0xb9, 0x8c, 0xbd, 0xb5, 0xc1, 0xa5, 0xb1, 0x95, 0xb9, 0x98, 0xc9,
+ 0x85, 0xb5, 0x95, 0x89, 0xd5, 0x99, 0x99, 0x95, 0xc9, 0x7d, 0x99, 0x95,
+ 0xd1, 0x8d, 0xa1, 0x7d, 0x91, 0xa5, 0xcd, 0x85, 0x89, 0xb1, 0x95, 0x0d,
+ 0x11, 0xa8, 0x84, 0x61, 0x10, 0x96, 0x26, 0xe7, 0x32, 0xf6, 0xd6, 0x06,
+ 0x97, 0xc6, 0x56, 0xe6, 0xe2, 0x16, 0x46, 0x97, 0x66, 0x57, 0xf6, 0x45,
+ 0xf6, 0x56, 0x27, 0xc6, 0x56, 0xf6, 0x45, 0x96, 0x36, 0x17, 0x26, 0xc6,
+ 0x56, 0x36, 0x44, 0xa0, 0x16, 0x46, 0x61, 0x69, 0x72, 0x2e, 0x72, 0x65,
+ 0x6e, 0x64, 0x65, 0x72, 0x5f, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x8c,
+ 0xc2, 0xd2, 0xe4, 0x5c, 0xc2, 0xe4, 0xce, 0xbe, 0xe8, 0xf2, 0xe0, 0xca,
+ 0xbe, 0xdc, 0xc2, 0xda, 0xca, 0x68, 0x98, 0xb1, 0xbd, 0x85, 0xd1, 0xd1,
+ 0x0c, 0x41, 0xa8, 0x06, 0x1a, 0x28, 0x87, 0x7a, 0x86, 0x08, 0x14, 0x44,
+ 0x26, 0x2c, 0x4d, 0xce, 0x05, 0xee, 0x6d, 0x2e, 0x8d, 0x2e, 0xed, 0xcd,
+ 0x8d, 0x4a, 0x58, 0x9a, 0x9c, 0xcb, 0x58, 0x99, 0x1b, 0x5d, 0x99, 0x1c,
+ 0xa5, 0xb0, 0x34, 0x39, 0x17, 0xb7, 0xb7, 0x2f, 0xb8, 0x32, 0xb9, 0x39,
+ 0xb8, 0xb2, 0x31, 0xba, 0x34, 0xbb, 0x32, 0x32, 0x61, 0x69, 0x72, 0x2e,
+ 0x61, 0x72, 0x67, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x44, 0xe0, 0xde, 0xe6,
+ 0xd2, 0xe8, 0xd2, 0xde, 0xdc, 0x86, 0x40, 0xd0, 0x40, 0x49, 0xd4, 0x44,
+ 0x51, 0x94, 0x43, 0x3d, 0x54, 0x45, 0x59, 0x94, 0xc2, 0xd2, 0xe4, 0x5c,
+ 0xcc, 0xe4, 0xc2, 0xce, 0xda, 0xca, 0xdc, 0xe8, 0xbe, 0xd2, 0xdc, 0xe0,
+ 0xea, 0xe8, 0x98, 0x9d, 0x95, 0xb9, 0x95, 0xc9, 0x85, 0xd1, 0x95, 0x91,
+ 0xa1, 0xe0, 0xd0, 0x95, 0xe1, 0x8d, 0xbd, 0xbd, 0xc9, 0x91, 0x11, 0xd9,
+ 0xc9, 0x7c, 0x99, 0xa5, 0xf0, 0x09, 0x4b, 0x93, 0x73, 0x81, 0x2b, 0x93,
+ 0x9b, 0x83, 0x2b, 0x1b, 0xa3, 0x4b, 0xb3, 0x2b, 0xa3, 0x61, 0xc6, 0xf6,
+ 0x16, 0x46, 0x27, 0x43, 0x84, 0xae, 0x0c, 0x6f, 0xec, 0xed, 0x4d, 0x8e,
+ 0x6c, 0x88, 0x04, 0x11, 0x14, 0x46, 0x65, 0xd4, 0x44, 0x69, 0x94, 0x43,
+ 0x6d, 0x54, 0x45, 0x71, 0x54, 0xc2, 0xd2, 0xe4, 0x5c, 0xc4, 0xea, 0xcc,
+ 0xcc, 0xca, 0xe4, 0xf8, 0x84, 0xa5, 0xc9, 0xb9, 0x88, 0xd5, 0x99, 0x99,
+ 0x95, 0xc9, 0x7d, 0xcd, 0xa5, 0xe9, 0x95, 0x51, 0x0a, 0x4b, 0x93, 0x73,
+ 0x61, 0x7b, 0x1b, 0x0b, 0xa3, 0x4b, 0x7b, 0x73, 0xfb, 0x4a, 0x73, 0x23,
+ 0x2b, 0xc3, 0x23, 0x12, 0x96, 0x26, 0xe7, 0x22, 0x57, 0x16, 0x46, 0xc6,
+ 0x28, 0x2c, 0x4d, 0xce, 0x25, 0x4c, 0xee, 0xec, 0x8b, 0x2e, 0x0f, 0xae,
+ 0xec, 0x6b, 0x2e, 0x4d, 0xaf, 0x8c, 0x57, 0x58, 0x9a, 0x9c, 0x4b, 0x98,
+ 0xdc, 0xd9, 0x17, 0x5d, 0x1e, 0x5c, 0xd9, 0x57, 0x18, 0x5b, 0xda, 0x99,
+ 0xdb, 0xd7, 0x5c, 0x9a, 0x5e, 0x19, 0x87, 0xb1, 0x37, 0xb6, 0x21, 0x60,
+ 0x00, 0x21, 0x94, 0x47, 0x7d, 0x50, 0x41, 0x81, 0x01, 0x34, 0x40, 0x04,
+ 0x15, 0x06, 0x94, 0x18, 0x40, 0x05, 0x35, 0x06, 0x50, 0x41, 0x39, 0xd4,
+ 0x43, 0x55, 0x14, 0x19, 0x90, 0x0a, 0x4b, 0x93, 0x73, 0x99, 0xa3, 0x93,
+ 0xab, 0x1b, 0xa3, 0xfb, 0xa2, 0xcb, 0x83, 0x2b, 0xfb, 0x4a, 0x73, 0x33,
+ 0x7b, 0xa3, 0x61, 0xc6, 0xf6, 0x16, 0x46, 0x37, 0x43, 0xe3, 0xcd, 0xcc,
+ 0x6c, 0xae, 0x8c, 0x8e, 0x86, 0xd4, 0xd8, 0x5b, 0x99, 0x99, 0x19, 0x8d,
+ 0xa3, 0xb1, 0xb7, 0x32, 0x33, 0x33, 0x1a, 0x42, 0x63, 0x6f, 0x65, 0x66,
+ 0x66, 0x43, 0xd0, 0x00, 0x1a, 0xa0, 0x02, 0x1a, 0xa8, 0x33, 0xa0, 0xd0,
+ 0x00, 0x2a, 0xa0, 0x02, 0x1a, 0xa8, 0x33, 0xa0, 0xd2, 0x00, 0x52, 0xa0,
+ 0x02, 0x1a, 0xa8, 0x33, 0xa0, 0xd4, 0x00, 0x5a, 0xa0, 0x02, 0x1a, 0xa8,
+ 0x33, 0xa0, 0xd6, 0x80, 0x49, 0x56, 0x95, 0x15, 0x51, 0xd9, 0xd8, 0x1b,
+ 0x59, 0x19, 0x0d, 0xb2, 0xb2, 0xb1, 0x37, 0xb2, 0xb2, 0x21, 0x64, 0x00,
+ 0x25, 0x94, 0x47, 0x7d, 0x90, 0x41, 0x81, 0x01, 0x44, 0x40, 0x04, 0x15,
+ 0x06, 0x94, 0x19, 0x50, 0x6c, 0x40, 0x89, 0x01, 0x64, 0x50, 0x63, 0x00,
+ 0x15, 0x94, 0x43, 0xb5, 0x01, 0x55, 0x51, 0x6e, 0xc0, 0x25, 0x2c, 0x4d,
+ 0xce, 0x85, 0xae, 0x0c, 0x8f, 0xae, 0x4e, 0xae, 0x8c, 0x4a, 0x58, 0x9a,
+ 0x9c, 0xcb, 0x5c, 0x58, 0x1b, 0x1c, 0x5b, 0x19, 0x31, 0xba, 0x32, 0x3c,
+ 0xba, 0x3a, 0xb9, 0x32, 0x19, 0x32, 0x1e, 0x33, 0xb6, 0xb7, 0x30, 0x3a,
+ 0x16, 0x90, 0xb9, 0xb0, 0x36, 0x38, 0xb6, 0x32, 0x1f, 0x12, 0x74, 0x65,
+ 0x78, 0x59, 0x43, 0x28, 0x88, 0xa1, 0xe0, 0x80, 0x02, 0x03, 0x68, 0x80,
+ 0x08, 0x2a, 0x0e, 0x28, 0x87, 0x92, 0x03, 0xaa, 0xa2, 0xe6, 0x80, 0x05,
+ 0x5d, 0x19, 0x5e, 0x95, 0xd5, 0x10, 0x0a, 0x6a, 0x28, 0x38, 0xa0, 0xc0,
+ 0x00, 0x22, 0x20, 0x82, 0x8a, 0x03, 0xca, 0xa1, 0xe4, 0x80, 0xaa, 0xa8,
+ 0x3a, 0xe0, 0x12, 0x96, 0x26, 0xe7, 0x32, 0x17, 0xd6, 0x06, 0xc7, 0x56,
+ 0x26, 0xc7, 0x63, 0x2e, 0xac, 0x0d, 0x8e, 0xad, 0x4c, 0x8e, 0xc1, 0xdc,
+ 0x10, 0x09, 0x72, 0xa8, 0x3b, 0xa0, 0xc0, 0x00, 0x1a, 0x20, 0x82, 0x72,
+ 0x28, 0x3c, 0xa0, 0x2a, 0x2a, 0x0f, 0x86, 0x38, 0xd4, 0x45, 0x75, 0x54,
+ 0x19, 0x50, 0x6f, 0x40, 0xd1, 0x01, 0x65, 0x07, 0x94, 0x1e, 0x0c, 0x31,
+ 0x18, 0x80, 0x8a, 0xa8, 0x3d, 0xe0, 0xf3, 0xd6, 0xe6, 0x96, 0x06, 0xf7,
+ 0x46, 0x57, 0xe6, 0x46, 0x07, 0x32, 0x86, 0x16, 0x26, 0xc7, 0x67, 0x2a,
+ 0xad, 0x0d, 0x8e, 0xad, 0x0c, 0x64, 0x68, 0x65, 0x05, 0x84, 0x4a, 0x28,
+ 0x28, 0x68, 0x88, 0x40, 0xf9, 0xc1, 0x10, 0x83, 0xea, 0x03, 0xea, 0x0f,
+ 0xae, 0x67, 0x88, 0x41, 0x81, 0x02, 0x05, 0x0a, 0xd7, 0x33, 0x42, 0x61,
+ 0x07, 0x76, 0xb0, 0x87, 0x76, 0x70, 0x83, 0x74, 0x20, 0x87, 0x72, 0x70,
+ 0x07, 0x7a, 0x98, 0x12, 0x04, 0x23, 0x96, 0x70, 0x48, 0x07, 0x79, 0x70,
+ 0x03, 0x7b, 0x28, 0x07, 0x79, 0x98, 0x87, 0x74, 0x78, 0x07, 0x77, 0x98,
+ 0x12, 0x08, 0x23, 0xa8, 0x70, 0x48, 0x07, 0x79, 0x70, 0x03, 0x76, 0x08,
+ 0x07, 0x77, 0x38, 0x87, 0x7a, 0x08, 0x87, 0x73, 0x28, 0x87, 0x5f, 0xb0,
+ 0x87, 0x72, 0x90, 0x87, 0x79, 0x48, 0x87, 0x77, 0x70, 0x87, 0x29, 0x01,
+ 0x31, 0x62, 0x0a, 0x87, 0x74, 0x90, 0x07, 0x37, 0x18, 0x87, 0x77, 0x68,
+ 0x07, 0x78, 0x48, 0x07, 0x76, 0x28, 0x87, 0x5f, 0x78, 0x07, 0x78, 0xa0,
+ 0x87, 0x74, 0x78, 0x07, 0x77, 0x98, 0x87, 0x29, 0x84, 0x81, 0x28, 0xcc,
+ 0x08, 0x26, 0x1c, 0xd2, 0x41, 0x1e, 0xdc, 0xc0, 0x1c, 0xe4, 0x21, 0x1c,
+ 0xce, 0xa1, 0x1d, 0xca, 0xc1, 0x1d, 0xe8, 0x61, 0x4a, 0xc0, 0x07, 0x00,
+ 0x79, 0x18, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x33, 0x08, 0x80, 0x1c,
+ 0xc4, 0xe1, 0x1c, 0x66, 0x14, 0x01, 0x3d, 0x88, 0x43, 0x38, 0x84, 0xc3,
+ 0x8c, 0x42, 0x80, 0x07, 0x79, 0x78, 0x07, 0x73, 0x98, 0x71, 0x0c, 0xe6,
+ 0x00, 0x0f, 0xed, 0x10, 0x0e, 0xf4, 0x80, 0x0e, 0x33, 0x0c, 0x42, 0x1e,
+ 0xc2, 0xc1, 0x1d, 0xce, 0xa1, 0x1c, 0x66, 0x30, 0x05, 0x3d, 0x88, 0x43,
+ 0x38, 0x84, 0x83, 0x1b, 0xcc, 0x03, 0x3d, 0xc8, 0x43, 0x3d, 0x8c, 0x03,
+ 0x3d, 0xcc, 0x78, 0x8c, 0x74, 0x70, 0x07, 0x7b, 0x08, 0x07, 0x79, 0x48,
+ 0x87, 0x70, 0x70, 0x07, 0x7a, 0x70, 0x03, 0x76, 0x78, 0x87, 0x70, 0x20,
+ 0x87, 0x19, 0xcc, 0x11, 0x0e, 0xec, 0x90, 0x0e, 0xe1, 0x30, 0x0f, 0x6e,
+ 0x30, 0x0f, 0xe3, 0xf0, 0x0e, 0xf0, 0x50, 0x0e, 0x33, 0x10, 0xc4, 0x1d,
+ 0xde, 0x21, 0x1c, 0xd8, 0x21, 0x1d, 0xc2, 0x61, 0x1e, 0x66, 0x30, 0x89,
+ 0x3b, 0xbc, 0x83, 0x3b, 0xd0, 0x43, 0x39, 0xb4, 0x03, 0x3c, 0xbc, 0x83,
+ 0x3c, 0x84, 0x03, 0x3b, 0xcc, 0xf0, 0x14, 0x76, 0x60, 0x07, 0x7b, 0x68,
+ 0x07, 0x37, 0x68, 0x87, 0x72, 0x68, 0x07, 0x37, 0x80, 0x87, 0x70, 0x90,
+ 0x87, 0x70, 0x60, 0x07, 0x76, 0x28, 0x07, 0x76, 0xf8, 0x05, 0x76, 0x78,
+ 0x87, 0x77, 0x80, 0x87, 0x5f, 0x08, 0x87, 0x71, 0x18, 0x87, 0x72, 0x98,
+ 0x87, 0x79, 0x98, 0x81, 0x2c, 0xee, 0xf0, 0x0e, 0xee, 0xe0, 0x0e, 0xf5,
+ 0xc0, 0x0e, 0xec, 0x30, 0x03, 0x62, 0xc8, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c,
+ 0xcc, 0xa1, 0x1c, 0xe4, 0xa1, 0x1c, 0xdc, 0x61, 0x1c, 0xca, 0x21, 0x1c,
+ 0xc4, 0x81, 0x1d, 0xca, 0x61, 0x06, 0xd6, 0x90, 0x43, 0x39, 0xc8, 0x43,
+ 0x39, 0x98, 0x43, 0x39, 0xc8, 0x43, 0x39, 0xb8, 0xc3, 0x38, 0x94, 0x43,
+ 0x38, 0x88, 0x03, 0x3b, 0x94, 0xc3, 0x2f, 0xbc, 0x83, 0x3c, 0xfc, 0x82,
+ 0x3b, 0xd4, 0x03, 0x3b, 0xb0, 0xc3, 0x0c, 0xc7, 0x69, 0x87, 0x70, 0x58,
+ 0x87, 0x72, 0x70, 0x83, 0x74, 0x68, 0x07, 0x78, 0x60, 0x87, 0x74, 0x18,
+ 0x87, 0x74, 0xa0, 0x87, 0x19, 0xce, 0x53, 0x0f, 0xee, 0x00, 0x0f, 0xf2,
+ 0x50, 0x0e, 0xe4, 0x90, 0x0e, 0xe3, 0x40, 0x0f, 0xe1, 0x20, 0x0e, 0xec,
+ 0x50, 0x0e, 0x33, 0x20, 0x28, 0x1d, 0xdc, 0xc1, 0x1e, 0xc2, 0x41, 0x1e,
+ 0xd2, 0x21, 0x1c, 0xdc, 0x81, 0x1e, 0xdc, 0xe0, 0x1c, 0xe4, 0xe1, 0x1d,
+ 0xea, 0x01, 0x1e, 0x66, 0x18, 0x51, 0x38, 0xb0, 0x43, 0x3a, 0x9c, 0x83,
+ 0x3b, 0xcc, 0x50, 0x24, 0x76, 0x60, 0x07, 0x7b, 0x68, 0x07, 0x37, 0x60,
+ 0x87, 0x77, 0x78, 0x07, 0x78, 0x98, 0x51, 0x4c, 0xf4, 0x90, 0x0f, 0xf0,
+ 0x50, 0x0e, 0x00, 0x00, 0x71, 0x20, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00,
+ 0x16, 0xd0, 0x00, 0x48, 0xe4, 0x0f, 0xce, 0xe4, 0x57, 0x77, 0x71, 0xdb,
+ 0x26, 0xb0, 0x01, 0x48, 0xe4, 0x4b, 0x00, 0xf3, 0x2c, 0xc4, 0x3f, 0x11,
+ 0xd7, 0x44, 0x45, 0xc4, 0x6f, 0x0f, 0x7e, 0x85, 0x17, 0xb7, 0x6d, 0x00,
+ 0x11, 0xdb, 0x95, 0xff, 0xf9, 0xda, 0xf5, 0x5f, 0x44, 0x80, 0xc1, 0x10,
+ 0xcd, 0x04, 0x00, 0x00, 0x61, 0x20, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
+ 0x13, 0x04, 0x41, 0x2c, 0x10, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
+ 0x64, 0xe7, 0x20, 0x06, 0x02, 0xf1, 0xa8, 0x8e, 0x35, 0x00, 0x03, 0x31,
+ 0xc7, 0x30, 0x10, 0xde, 0x1c, 0xc3, 0xe0, 0x79, 0x63, 0x0d, 0x40, 0x20,
+ 0xd0, 0xab, 0x81, 0x11, 0x00, 0x82, 0x33, 0x00, 0x14, 0x47, 0x00, 0xc6,
+ 0x12, 0x02, 0x80, 0xc8, 0x0c, 0x00, 0x89, 0x19, 0x00, 0x0a, 0x33, 0x00,
+ 0x04, 0xc6, 0x08, 0x40, 0x10, 0x04, 0xf1, 0x6f, 0x04, 0x00, 0x00, 0x00,
+ 0x23, 0x06, 0xca, 0x10, 0x90, 0x81, 0x04, 0x55, 0xca, 0x91, 0x04, 0x23,
+ 0x06, 0xca, 0x10, 0x94, 0x81, 0x14, 0x59, 0x0b, 0xa2, 0x08, 0x83, 0x0c,
+ 0x41, 0x81, 0x0c, 0x32, 0x0c, 0xc6, 0x33, 0xc8, 0x20, 0x20, 0xd1, 0x20,
+ 0x83, 0x10, 0x4c, 0x83, 0x0c, 0xc1, 0x52, 0x9d, 0x36, 0x96, 0x82, 0x62,
+ 0x43, 0x00, 0x1f, 0xf2, 0xca, 0x20, 0x83, 0xe0, 0x58, 0xe3, 0x0d, 0xdf,
+ 0x18, 0xb8, 0xc1, 0x05, 0x63, 0x29, 0x28, 0x83, 0x0c, 0x81, 0xa4, 0x8d,
+ 0x18, 0x14, 0x44, 0x50, 0x07, 0x45, 0x30, 0xc7, 0x40, 0x05, 0x74, 0x30,
+ 0xde, 0x50, 0x06, 0x69, 0x00, 0x07, 0x17, 0x8c, 0xa5, 0xa0, 0x0c, 0x32,
+ 0x04, 0x18, 0x18, 0x8c, 0x18, 0x14, 0x44, 0xb0, 0x07, 0x4b, 0x30, 0xc7,
+ 0x60, 0x04, 0x79, 0x30, 0xde, 0xb0, 0x06, 0x6f, 0x50, 0x07, 0x17, 0x8c,
+ 0xa5, 0xa0, 0x0c, 0x32, 0x04, 0x9e, 0x19, 0x8c, 0x18, 0x14, 0x44, 0x10,
+ 0x0a, 0x51, 0x30, 0xc7, 0x60, 0x04, 0x7b, 0x30, 0xc7, 0x10, 0x80, 0xc1,
+ 0x1e, 0x58, 0x50, 0xc9, 0x27, 0x83, 0x80, 0x18, 0x02, 0x00, 0x00, 0x00,
+ 0x5b, 0x06, 0x25, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00
+};
+const unsigned int sdl_metallib_len = 22792;
diff --git a/src/3rdparty/SDL2/src/render/metal/build-metal-shaders.sh b/src/3rdparty/SDL2/src/render/metal/build-metal-shaders.sh
new file mode 100644
index 0000000..8ebf63e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/metal/build-metal-shaders.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+set -x
+set -e
+cd `dirname "$0"`
+
+generate_shaders()
+{
+ platform=$1
+ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/usr/bin/metal -std=$platform-metal1.1 -Wall -O3 -o ./sdl.air ./SDL_shaders_metal.metal || exit $?
+ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/usr/bin/metal-ar rc sdl.metalar sdl.air || exit $?
+ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/usr/bin/metallib -o sdl.metallib sdl.metalar || exit $?
+ xxd -i sdl.metallib | perl -w -p -e 's/\Aunsigned /const unsigned /;' >./SDL_shaders_metal_$platform.h
+ rm -f sdl.air sdl.metalar sdl.metallib
+}
+
+generate_shaders osx
+generate_shaders ios
diff --git a/src/3rdparty/SDL2/src/render/opengl/SDL_glfuncs.h b/src/3rdparty/SDL2/src/render/opengl/SDL_glfuncs.h
new file mode 100644
index 0000000..02be0e1
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/opengl/SDL_glfuncs.h
@@ -0,0 +1,478 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/* list of OpenGL functions sorted alphabetically
+ If you need to use a GL function from the SDL video subsystem,
+ change its entry from SDL_PROC_UNUSED to SDL_PROC and rebuild.
+*/
+#define SDL_PROC_UNUSED(ret,func,params)
+
+SDL_PROC_UNUSED(void, glAccum, (GLenum, GLfloat))
+SDL_PROC_UNUSED(void, glAlphaFunc, (GLenum, GLclampf))
+SDL_PROC_UNUSED(GLboolean, glAreTexturesResident,
+ (GLsizei, const GLuint *, GLboolean *))
+SDL_PROC_UNUSED(void, glArrayElement, (GLint))
+SDL_PROC(void, glBegin, (GLenum))
+SDL_PROC(void, glBindTexture, (GLenum, GLuint))
+SDL_PROC_UNUSED(void, glBitmap,
+ (GLsizei, GLsizei, GLfloat, GLfloat, GLfloat, GLfloat,
+ const GLubyte *))
+SDL_PROC(void, glBlendEquation, (GLenum))
+SDL_PROC_UNUSED(void, glBlendFunc, (GLenum, GLenum))
+SDL_PROC(void, glBlendFuncSeparate, (GLenum, GLenum, GLenum, GLenum))
+SDL_PROC_UNUSED(void, glCallList, (GLuint))
+SDL_PROC_UNUSED(void, glCallLists, (GLsizei, GLenum, const GLvoid *))
+SDL_PROC(void, glClear, (GLbitfield))
+SDL_PROC_UNUSED(void, glClearAccum, (GLfloat, GLfloat, GLfloat, GLfloat))
+SDL_PROC(void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf))
+SDL_PROC_UNUSED(void, glClearDepth, (GLclampd))
+SDL_PROC_UNUSED(void, glClearIndex, (GLfloat))
+SDL_PROC_UNUSED(void, glClearStencil, (GLint))
+SDL_PROC_UNUSED(void, glClipPlane, (GLenum, const GLdouble *))
+SDL_PROC_UNUSED(void, glColor3b, (GLbyte, GLbyte, GLbyte))
+SDL_PROC_UNUSED(void, glColor3bv, (const GLbyte *))
+SDL_PROC_UNUSED(void, glColor3d, (GLdouble, GLdouble, GLdouble))
+SDL_PROC_UNUSED(void, glColor3dv, (const GLdouble *))
+SDL_PROC_UNUSED(void, glColor3f, (GLfloat, GLfloat, GLfloat))
+SDL_PROC(void, glColor3fv, (const GLfloat *))
+SDL_PROC_UNUSED(void, glColor3i, (GLint, GLint, GLint))
+SDL_PROC_UNUSED(void, glColor3iv, (const GLint *))
+SDL_PROC_UNUSED(void, glColor3s, (GLshort, GLshort, GLshort))
+SDL_PROC_UNUSED(void, glColor3sv, (const GLshort *))
+SDL_PROC_UNUSED(void, glColor3ub, (GLubyte, GLubyte, GLubyte))
+SDL_PROC_UNUSED(void, glColor3ubv, (const GLubyte *))
+SDL_PROC_UNUSED(void, glColor3ui, (GLuint, GLuint, GLuint))
+SDL_PROC_UNUSED(void, glColor3uiv, (const GLuint *))
+SDL_PROC_UNUSED(void, glColor3us, (GLushort, GLushort, GLushort))
+SDL_PROC_UNUSED(void, glColor3usv, (const GLushort *))
+SDL_PROC_UNUSED(void, glColor4b, (GLbyte, GLbyte, GLbyte, GLbyte))
+SDL_PROC_UNUSED(void, glColor4bv, (const GLbyte *))
+SDL_PROC_UNUSED(void, glColor4d, (GLdouble, GLdouble, GLdouble, GLdouble))
+SDL_PROC_UNUSED(void, glColor4dv, (const GLdouble *))
+SDL_PROC(void, glColor4f, (GLfloat, GLfloat, GLfloat, GLfloat))
+SDL_PROC_UNUSED(void, glColor4fv, (const GLfloat *))
+SDL_PROC_UNUSED(void, glColor4i, (GLint, GLint, GLint, GLint))
+SDL_PROC_UNUSED(void, glColor4iv, (const GLint *))
+SDL_PROC_UNUSED(void, glColor4s, (GLshort, GLshort, GLshort, GLshort))
+SDL_PROC_UNUSED(void, glColor4sv, (const GLshort *))
+SDL_PROC_UNUSED(void, glColor4ub,
+ (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha))
+SDL_PROC_UNUSED(void, glColor4ubv, (const GLubyte * v))
+SDL_PROC_UNUSED(void, glColor4ui,
+ (GLuint red, GLuint green, GLuint blue, GLuint alpha))
+SDL_PROC_UNUSED(void, glColor4uiv, (const GLuint * v))
+SDL_PROC_UNUSED(void, glColor4us,
+ (GLushort red, GLushort green, GLushort blue, GLushort alpha))
+SDL_PROC_UNUSED(void, glColor4usv, (const GLushort * v))
+SDL_PROC_UNUSED(void, glColorMask,
+ (GLboolean red, GLboolean green, GLboolean blue,
+ GLboolean alpha))
+SDL_PROC_UNUSED(void, glColorMaterial, (GLenum face, GLenum mode))
+SDL_PROC_UNUSED(void, glColorPointer,
+ (GLint size, GLenum type, GLsizei stride,
+ const GLvoid * pointer))
+SDL_PROC_UNUSED(void, glCopyPixels,
+ (GLint x, GLint y, GLsizei width, GLsizei height,
+ GLenum type))
+SDL_PROC_UNUSED(void, glCopyTexImage1D,
+ (GLenum target, GLint level, GLenum internalFormat, GLint x,
+ GLint y, GLsizei width, GLint border))
+SDL_PROC_UNUSED(void, glCopyTexImage2D,
+ (GLenum target, GLint level, GLenum internalFormat, GLint x,
+ GLint y, GLsizei width, GLsizei height, GLint border))
+SDL_PROC_UNUSED(void, glCopyTexSubImage1D,
+ (GLenum target, GLint level, GLint xoffset, GLint x, GLint y,
+ GLsizei width))
+SDL_PROC_UNUSED(void, glCopyTexSubImage2D,
+ (GLenum target, GLint level, GLint xoffset, GLint yoffset,
+ GLint x, GLint y, GLsizei width, GLsizei height))
+SDL_PROC_UNUSED(void, glCullFace, (GLenum mode))
+SDL_PROC_UNUSED(void, glDeleteLists, (GLuint list, GLsizei range))
+SDL_PROC(void, glDeleteTextures, (GLsizei n, const GLuint * textures))
+SDL_PROC(void, glDepthFunc, (GLenum func))
+SDL_PROC_UNUSED(void, glDepthMask, (GLboolean flag))
+SDL_PROC_UNUSED(void, glDepthRange, (GLclampd zNear, GLclampd zFar))
+SDL_PROC(void, glDisable, (GLenum cap))
+SDL_PROC_UNUSED(void, glDisableClientState, (GLenum array))
+SDL_PROC_UNUSED(void, glDrawArrays, (GLenum mode, GLint first, GLsizei count))
+SDL_PROC_UNUSED(void, glDrawBuffer, (GLenum mode))
+SDL_PROC_UNUSED(void, glDrawElements,
+ (GLenum mode, GLsizei count, GLenum type,
+ const GLvoid * indices))
+SDL_PROC(void, glDrawPixels,
+ (GLsizei width, GLsizei height, GLenum format, GLenum type,
+ const GLvoid * pixels))
+SDL_PROC_UNUSED(void, glEdgeFlag, (GLboolean flag))
+SDL_PROC_UNUSED(void, glEdgeFlagPointer,
+ (GLsizei stride, const GLvoid * pointer))
+SDL_PROC_UNUSED(void, glEdgeFlagv, (const GLboolean * flag))
+SDL_PROC(void, glEnable, (GLenum cap))
+SDL_PROC_UNUSED(void, glEnableClientState, (GLenum array))
+SDL_PROC(void, glEnd, (void))
+SDL_PROC_UNUSED(void, glEndList, (void))
+SDL_PROC_UNUSED(void, glEvalCoord1d, (GLdouble u))
+SDL_PROC_UNUSED(void, glEvalCoord1dv, (const GLdouble * u))
+SDL_PROC_UNUSED(void, glEvalCoord1f, (GLfloat u))
+SDL_PROC_UNUSED(void, glEvalCoord1fv, (const GLfloat * u))
+SDL_PROC_UNUSED(void, glEvalCoord2d, (GLdouble u, GLdouble v))
+SDL_PROC_UNUSED(void, glEvalCoord2dv, (const GLdouble * u))
+SDL_PROC_UNUSED(void, glEvalCoord2f, (GLfloat u, GLfloat v))
+SDL_PROC_UNUSED(void, glEvalCoord2fv, (const GLfloat * u))
+SDL_PROC_UNUSED(void, glEvalMesh1, (GLenum mode, GLint i1, GLint i2))
+SDL_PROC_UNUSED(void, glEvalMesh2,
+ (GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2))
+SDL_PROC_UNUSED(void, glEvalPoint1, (GLint i))
+SDL_PROC_UNUSED(void, glEvalPoint2, (GLint i, GLint j))
+SDL_PROC_UNUSED(void, glFeedbackBuffer,
+ (GLsizei size, GLenum type, GLfloat * buffer))
+SDL_PROC_UNUSED(void, glFinish, (void))
+SDL_PROC_UNUSED(void, glFlush, (void))
+SDL_PROC_UNUSED(void, glFogf, (GLenum pname, GLfloat param))
+SDL_PROC_UNUSED(void, glFogfv, (GLenum pname, const GLfloat * params))
+SDL_PROC_UNUSED(void, glFogi, (GLenum pname, GLint param))
+SDL_PROC_UNUSED(void, glFogiv, (GLenum pname, const GLint * params))
+SDL_PROC_UNUSED(void, glFrontFace, (GLenum mode))
+SDL_PROC_UNUSED(void, glFrustum,
+ (GLdouble left, GLdouble right, GLdouble bottom,
+ GLdouble top, GLdouble zNear, GLdouble zFar))
+SDL_PROC_UNUSED(GLuint, glGenLists, (GLsizei range))
+SDL_PROC(void, glGenTextures, (GLsizei n, GLuint * textures))
+SDL_PROC_UNUSED(void, glGetBooleanv, (GLenum pname, GLboolean * params))
+SDL_PROC_UNUSED(void, glGetClipPlane, (GLenum plane, GLdouble * equation))
+SDL_PROC_UNUSED(void, glGetDoublev, (GLenum pname, GLdouble * params))
+SDL_PROC(GLenum, glGetError, (void))
+SDL_PROC_UNUSED(void, glGetFloatv, (GLenum pname, GLfloat * params))
+SDL_PROC(void, glGetIntegerv, (GLenum pname, GLint * params))
+SDL_PROC_UNUSED(void, glGetLightfv,
+ (GLenum light, GLenum pname, GLfloat * params))
+SDL_PROC_UNUSED(void, glGetLightiv,
+ (GLenum light, GLenum pname, GLint * params))
+SDL_PROC_UNUSED(void, glGetMapdv, (GLenum target, GLenum query, GLdouble * v))
+SDL_PROC_UNUSED(void, glGetMapfv, (GLenum target, GLenum query, GLfloat * v))
+SDL_PROC_UNUSED(void, glGetMapiv, (GLenum target, GLenum query, GLint * v))
+SDL_PROC_UNUSED(void, glGetMaterialfv,
+ (GLenum face, GLenum pname, GLfloat * params))
+SDL_PROC_UNUSED(void, glGetMaterialiv,
+ (GLenum face, GLenum pname, GLint * params))
+SDL_PROC_UNUSED(void, glGetPixelMapfv, (GLenum map, GLfloat * values))
+SDL_PROC_UNUSED(void, glGetPixelMapuiv, (GLenum map, GLuint * values))
+SDL_PROC_UNUSED(void, glGetPixelMapusv, (GLenum map, GLushort * values))
+SDL_PROC(void, glGetPointerv, (GLenum pname, GLvoid * *params))
+SDL_PROC_UNUSED(void, glGetPolygonStipple, (GLubyte * mask))
+SDL_PROC(const GLubyte *, glGetString, (GLenum name))
+SDL_PROC_UNUSED(void, glGetTexEnvfv,
+ (GLenum target, GLenum pname, GLfloat * params))
+SDL_PROC_UNUSED(void, glGetTexEnviv,
+ (GLenum target, GLenum pname, GLint * params))
+SDL_PROC_UNUSED(void, glGetTexGendv,
+ (GLenum coord, GLenum pname, GLdouble * params))
+SDL_PROC_UNUSED(void, glGetTexGenfv,
+ (GLenum coord, GLenum pname, GLfloat * params))
+SDL_PROC_UNUSED(void, glGetTexGeniv,
+ (GLenum coord, GLenum pname, GLint * params))
+SDL_PROC_UNUSED(void, glGetTexImage,
+ (GLenum target, GLint level, GLenum format, GLenum type,
+ GLvoid * pixels))
+SDL_PROC_UNUSED(void, glGetTexLevelParameterfv,
+ (GLenum target, GLint level, GLenum pname, GLfloat * params))
+SDL_PROC_UNUSED(void, glGetTexLevelParameteriv,
+ (GLenum target, GLint level, GLenum pname, GLint * params))
+SDL_PROC_UNUSED(void, glGetTexParameterfv,
+ (GLenum target, GLenum pname, GLfloat * params))
+SDL_PROC_UNUSED(void, glGetTexParameteriv,
+ (GLenum target, GLenum pname, GLint * params))
+SDL_PROC_UNUSED(void, glHint, (GLenum target, GLenum mode))
+SDL_PROC_UNUSED(void, glIndexMask, (GLuint mask))
+SDL_PROC_UNUSED(void, glIndexPointer,
+ (GLenum type, GLsizei stride, const GLvoid * pointer))
+SDL_PROC_UNUSED(void, glIndexd, (GLdouble c))
+SDL_PROC_UNUSED(void, glIndexdv, (const GLdouble * c))
+SDL_PROC_UNUSED(void, glIndexf, (GLfloat c))
+SDL_PROC_UNUSED(void, glIndexfv, (const GLfloat * c))
+SDL_PROC_UNUSED(void, glIndexi, (GLint c))
+SDL_PROC_UNUSED(void, glIndexiv, (const GLint * c))
+SDL_PROC_UNUSED(void, glIndexs, (GLshort c))
+SDL_PROC_UNUSED(void, glIndexsv, (const GLshort * c))
+SDL_PROC_UNUSED(void, glIndexub, (GLubyte c))
+SDL_PROC_UNUSED(void, glIndexubv, (const GLubyte * c))
+SDL_PROC_UNUSED(void, glInitNames, (void))
+SDL_PROC_UNUSED(void, glInterleavedArrays,
+ (GLenum format, GLsizei stride, const GLvoid * pointer))
+SDL_PROC_UNUSED(GLboolean, glIsEnabled, (GLenum cap))
+SDL_PROC_UNUSED(GLboolean, glIsList, (GLuint list))
+SDL_PROC_UNUSED(GLboolean, glIsTexture, (GLuint texture))
+SDL_PROC_UNUSED(void, glLightModelf, (GLenum pname, GLfloat param))
+SDL_PROC_UNUSED(void, glLightModelfv, (GLenum pname, const GLfloat * params))
+SDL_PROC_UNUSED(void, glLightModeli, (GLenum pname, GLint param))
+SDL_PROC_UNUSED(void, glLightModeliv, (GLenum pname, const GLint * params))
+SDL_PROC_UNUSED(void, glLightf, (GLenum light, GLenum pname, GLfloat param))
+SDL_PROC_UNUSED(void, glLightfv,
+ (GLenum light, GLenum pname, const GLfloat * params))
+SDL_PROC_UNUSED(void, glLighti, (GLenum light, GLenum pname, GLint param))
+SDL_PROC_UNUSED(void, glLightiv,
+ (GLenum light, GLenum pname, const GLint * params))
+SDL_PROC_UNUSED(void, glLineStipple, (GLint factor, GLushort pattern))
+SDL_PROC(void, glLineWidth, (GLfloat width))
+SDL_PROC_UNUSED(void, glListBase, (GLuint base))
+SDL_PROC(void, glLoadIdentity, (void))
+SDL_PROC_UNUSED(void, glLoadMatrixd, (const GLdouble * m))
+SDL_PROC_UNUSED(void, glLoadMatrixf, (const GLfloat * m))
+SDL_PROC_UNUSED(void, glLoadName, (GLuint name))
+SDL_PROC_UNUSED(void, glLogicOp, (GLenum opcode))
+SDL_PROC_UNUSED(void, glMap1d,
+ (GLenum target, GLdouble u1, GLdouble u2, GLint stride,
+ GLint order, const GLdouble * points))
+SDL_PROC_UNUSED(void, glMap1f,
+ (GLenum target, GLfloat u1, GLfloat u2, GLint stride,
+ GLint order, const GLfloat * points))
+SDL_PROC_UNUSED(void, glMap2d,
+ (GLenum target, GLdouble u1, GLdouble u2, GLint ustride,
+ GLint uorder, GLdouble v1, GLdouble v2, GLint vstride,
+ GLint vorder, const GLdouble * points))
+SDL_PROC_UNUSED(void, glMap2f,
+ (GLenum target, GLfloat u1, GLfloat u2, GLint ustride,
+ GLint uorder, GLfloat v1, GLfloat v2, GLint vstride,
+ GLint vorder, const GLfloat * points))
+SDL_PROC_UNUSED(void, glMapGrid1d, (GLint un, GLdouble u1, GLdouble u2))
+SDL_PROC_UNUSED(void, glMapGrid1f, (GLint un, GLfloat u1, GLfloat u2))
+SDL_PROC_UNUSED(void, glMapGrid2d,
+ (GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1,
+ GLdouble v2))
+SDL_PROC_UNUSED(void, glMapGrid2f,
+ (GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1,
+ GLfloat v2))
+SDL_PROC_UNUSED(void, glMaterialf, (GLenum face, GLenum pname, GLfloat param))
+SDL_PROC_UNUSED(void, glMaterialfv,
+ (GLenum face, GLenum pname, const GLfloat * params))
+SDL_PROC_UNUSED(void, glMateriali, (GLenum face, GLenum pname, GLint param))
+SDL_PROC_UNUSED(void, glMaterialiv,
+ (GLenum face, GLenum pname, const GLint * params))
+SDL_PROC(void, glMatrixMode, (GLenum mode))
+SDL_PROC_UNUSED(void, glMultMatrixd, (const GLdouble * m))
+SDL_PROC_UNUSED(void, glMultMatrixf, (const GLfloat * m))
+SDL_PROC_UNUSED(void, glNewList, (GLuint list, GLenum mode))
+SDL_PROC_UNUSED(void, glNormal3b, (GLbyte nx, GLbyte ny, GLbyte nz))
+SDL_PROC_UNUSED(void, glNormal3bv, (const GLbyte * v))
+SDL_PROC_UNUSED(void, glNormal3d, (GLdouble nx, GLdouble ny, GLdouble nz))
+SDL_PROC_UNUSED(void, glNormal3dv, (const GLdouble * v))
+SDL_PROC_UNUSED(void, glNormal3f, (GLfloat nx, GLfloat ny, GLfloat nz))
+SDL_PROC_UNUSED(void, glNormal3fv, (const GLfloat * v))
+SDL_PROC_UNUSED(void, glNormal3i, (GLint nx, GLint ny, GLint nz))
+SDL_PROC_UNUSED(void, glNormal3iv, (const GLint * v))
+SDL_PROC_UNUSED(void, glNormal3s, (GLshort nx, GLshort ny, GLshort nz))
+SDL_PROC_UNUSED(void, glNormal3sv, (const GLshort * v))
+SDL_PROC_UNUSED(void, glNormalPointer,
+ (GLenum type, GLsizei stride, const GLvoid * pointer))
+SDL_PROC(void, glOrtho,
+ (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top,
+ GLdouble zNear, GLdouble zFar))
+SDL_PROC_UNUSED(void, glPassThrough, (GLfloat token))
+SDL_PROC_UNUSED(void, glPixelMapfv,
+ (GLenum map, GLsizei mapsize, const GLfloat * values))
+SDL_PROC_UNUSED(void, glPixelMapuiv,
+ (GLenum map, GLsizei mapsize, const GLuint * values))
+SDL_PROC_UNUSED(void, glPixelMapusv,
+ (GLenum map, GLsizei mapsize, const GLushort * values))
+SDL_PROC_UNUSED(void, glPixelStoref, (GLenum pname, GLfloat param))
+SDL_PROC(void, glPixelStorei, (GLenum pname, GLint param))
+SDL_PROC_UNUSED(void, glPixelTransferf, (GLenum pname, GLfloat param))
+SDL_PROC_UNUSED(void, glPixelTransferi, (GLenum pname, GLint param))
+SDL_PROC_UNUSED(void, glPixelZoom, (GLfloat xfactor, GLfloat yfactor))
+SDL_PROC(void, glPointSize, (GLfloat size))
+SDL_PROC_UNUSED(void, glPolygonMode, (GLenum face, GLenum mode))
+SDL_PROC_UNUSED(void, glPolygonOffset, (GLfloat factor, GLfloat units))
+SDL_PROC_UNUSED(void, glPolygonStipple, (const GLubyte * mask))
+SDL_PROC_UNUSED(void, glPopAttrib, (void))
+SDL_PROC_UNUSED(void, glPopClientAttrib, (void))
+SDL_PROC(void, glPopMatrix, (void))
+SDL_PROC_UNUSED(void, glPopName, (void))
+SDL_PROC_UNUSED(void, glPrioritizeTextures,
+ (GLsizei n, const GLuint * textures,
+ const GLclampf * priorities))
+SDL_PROC_UNUSED(void, glPushAttrib, (GLbitfield mask))
+SDL_PROC_UNUSED(void, glPushClientAttrib, (GLbitfield mask))
+SDL_PROC(void, glPushMatrix, (void))
+SDL_PROC_UNUSED(void, glPushName, (GLuint name))
+SDL_PROC_UNUSED(void, glRasterPos2d, (GLdouble x, GLdouble y))
+SDL_PROC_UNUSED(void, glRasterPos2dv, (const GLdouble * v))
+SDL_PROC_UNUSED(void, glRasterPos2f, (GLfloat x, GLfloat y))
+SDL_PROC_UNUSED(void, glRasterPos2fv, (const GLfloat * v))
+SDL_PROC(void, glRasterPos2i, (GLint x, GLint y))
+SDL_PROC_UNUSED(void, glRasterPos2iv, (const GLint * v))
+SDL_PROC_UNUSED(void, glRasterPos2s, (GLshort x, GLshort y))
+SDL_PROC_UNUSED(void, glRasterPos2sv, (const GLshort * v))
+SDL_PROC_UNUSED(void, glRasterPos3d, (GLdouble x, GLdouble y, GLdouble z))
+SDL_PROC_UNUSED(void, glRasterPos3dv, (const GLdouble * v))
+SDL_PROC_UNUSED(void, glRasterPos3f, (GLfloat x, GLfloat y, GLfloat z))
+SDL_PROC_UNUSED(void, glRasterPos3fv, (const GLfloat * v))
+SDL_PROC_UNUSED(void, glRasterPos3i, (GLint x, GLint y, GLint z))
+SDL_PROC_UNUSED(void, glRasterPos3iv, (const GLint * v))
+SDL_PROC_UNUSED(void, glRasterPos3s, (GLshort x, GLshort y, GLshort z))
+SDL_PROC_UNUSED(void, glRasterPos3sv, (const GLshort * v))
+SDL_PROC_UNUSED(void, glRasterPos4d,
+ (GLdouble x, GLdouble y, GLdouble z, GLdouble w))
+SDL_PROC_UNUSED(void, glRasterPos4dv, (const GLdouble * v))
+SDL_PROC_UNUSED(void, glRasterPos4f,
+ (GLfloat x, GLfloat y, GLfloat z, GLfloat w))
+SDL_PROC_UNUSED(void, glRasterPos4fv, (const GLfloat * v))
+SDL_PROC_UNUSED(void, glRasterPos4i, (GLint x, GLint y, GLint z, GLint w))
+SDL_PROC_UNUSED(void, glRasterPos4iv, (const GLint * v))
+SDL_PROC_UNUSED(void, glRasterPos4s,
+ (GLshort x, GLshort y, GLshort z, GLshort w))
+SDL_PROC_UNUSED(void, glRasterPos4sv, (const GLshort * v))
+SDL_PROC(void, glReadBuffer, (GLenum mode))
+SDL_PROC(void, glReadPixels,
+ (GLint x, GLint y, GLsizei width, GLsizei height,
+ GLenum format, GLenum type, GLvoid * pixels))
+SDL_PROC_UNUSED(void, glRectd,
+ (GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2))
+SDL_PROC_UNUSED(void, glRectdv, (const GLdouble * v1, const GLdouble * v2))
+SDL_PROC(void, glRectf,
+ (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2))
+SDL_PROC_UNUSED(void, glRectfv, (const GLfloat * v1, const GLfloat * v2))
+SDL_PROC_UNUSED(void, glRecti, (GLint x1, GLint y1, GLint x2, GLint y2))
+SDL_PROC_UNUSED(void, glRectiv, (const GLint * v1, const GLint * v2))
+SDL_PROC_UNUSED(void, glRects,
+ (GLshort x1, GLshort y1, GLshort x2, GLshort y2))
+SDL_PROC_UNUSED(void, glRectsv, (const GLshort * v1, const GLshort * v2))
+SDL_PROC_UNUSED(GLint, glRenderMode, (GLenum mode))
+SDL_PROC(void, glRotated,
+ (GLdouble angle, GLdouble x, GLdouble y, GLdouble z))
+SDL_PROC(void, glRotatef,
+ (GLfloat angle, GLfloat x, GLfloat y, GLfloat z))
+SDL_PROC_UNUSED(void, glScaled, (GLdouble x, GLdouble y, GLdouble z))
+SDL_PROC_UNUSED(void, glScalef, (GLfloat x, GLfloat y, GLfloat z))
+SDL_PROC(void, glScissor, (GLint x, GLint y, GLsizei width, GLsizei height))
+SDL_PROC_UNUSED(void, glSelectBuffer, (GLsizei size, GLuint * buffer))
+SDL_PROC(void, glShadeModel, (GLenum mode))
+SDL_PROC_UNUSED(void, glStencilFunc, (GLenum func, GLint ref, GLuint mask))
+SDL_PROC_UNUSED(void, glStencilMask, (GLuint mask))
+SDL_PROC_UNUSED(void, glStencilOp, (GLenum fail, GLenum zfail, GLenum zpass))
+SDL_PROC_UNUSED(void, glTexCoord1d, (GLdouble s))
+SDL_PROC_UNUSED(void, glTexCoord1dv, (const GLdouble * v))
+SDL_PROC_UNUSED(void, glTexCoord1f, (GLfloat s))
+SDL_PROC_UNUSED(void, glTexCoord1fv, (const GLfloat * v))
+SDL_PROC_UNUSED(void, glTexCoord1i, (GLint s))
+SDL_PROC_UNUSED(void, glTexCoord1iv, (const GLint * v))
+SDL_PROC_UNUSED(void, glTexCoord1s, (GLshort s))
+SDL_PROC_UNUSED(void, glTexCoord1sv, (const GLshort * v))
+SDL_PROC_UNUSED(void, glTexCoord2d, (GLdouble s, GLdouble t))
+SDL_PROC_UNUSED(void, glTexCoord2dv, (const GLdouble * v))
+SDL_PROC(void, glTexCoord2f, (GLfloat s, GLfloat t))
+SDL_PROC_UNUSED(void, glTexCoord2fv, (const GLfloat * v))
+SDL_PROC_UNUSED(void, glTexCoord2i, (GLint s, GLint t))
+SDL_PROC_UNUSED(void, glTexCoord2iv, (const GLint * v))
+SDL_PROC_UNUSED(void, glTexCoord2s, (GLshort s, GLshort t))
+SDL_PROC_UNUSED(void, glTexCoord2sv, (const GLshort * v))
+SDL_PROC_UNUSED(void, glTexCoord3d, (GLdouble s, GLdouble t, GLdouble r))
+SDL_PROC_UNUSED(void, glTexCoord3dv, (const GLdouble * v))
+SDL_PROC_UNUSED(void, glTexCoord3f, (GLfloat s, GLfloat t, GLfloat r))
+SDL_PROC_UNUSED(void, glTexCoord3fv, (const GLfloat * v))
+SDL_PROC_UNUSED(void, glTexCoord3i, (GLint s, GLint t, GLint r))
+SDL_PROC_UNUSED(void, glTexCoord3iv, (const GLint * v))
+SDL_PROC_UNUSED(void, glTexCoord3s, (GLshort s, GLshort t, GLshort r))
+SDL_PROC_UNUSED(void, glTexCoord3sv, (const GLshort * v))
+SDL_PROC_UNUSED(void, glTexCoord4d,
+ (GLdouble s, GLdouble t, GLdouble r, GLdouble q))
+SDL_PROC_UNUSED(void, glTexCoord4dv, (const GLdouble * v))
+SDL_PROC_UNUSED(void, glTexCoord4f,
+ (GLfloat s, GLfloat t, GLfloat r, GLfloat q))
+SDL_PROC_UNUSED(void, glTexCoord4fv, (const GLfloat * v))
+SDL_PROC_UNUSED(void, glTexCoord4i, (GLint s, GLint t, GLint r, GLint q))
+SDL_PROC_UNUSED(void, glTexCoord4iv, (const GLint * v))
+SDL_PROC_UNUSED(void, glTexCoord4s,
+ (GLshort s, GLshort t, GLshort r, GLshort q))
+SDL_PROC_UNUSED(void, glTexCoord4sv, (const GLshort * v))
+SDL_PROC_UNUSED(void, glTexCoordPointer,
+ (GLint size, GLenum type, GLsizei stride,
+ const GLvoid * pointer))
+SDL_PROC(void, glTexEnvf, (GLenum target, GLenum pname, GLfloat param))
+SDL_PROC_UNUSED(void, glTexEnvfv,
+ (GLenum target, GLenum pname, const GLfloat * params))
+SDL_PROC_UNUSED(void, glTexEnvi, (GLenum target, GLenum pname, GLint param))
+SDL_PROC_UNUSED(void, glTexEnviv,
+ (GLenum target, GLenum pname, const GLint * params))
+SDL_PROC_UNUSED(void, glTexGend, (GLenum coord, GLenum pname, GLdouble param))
+SDL_PROC_UNUSED(void, glTexGendv,
+ (GLenum coord, GLenum pname, const GLdouble * params))
+SDL_PROC_UNUSED(void, glTexGenf, (GLenum coord, GLenum pname, GLfloat param))
+SDL_PROC_UNUSED(void, glTexGenfv,
+ (GLenum coord, GLenum pname, const GLfloat * params))
+SDL_PROC_UNUSED(void, glTexGeni, (GLenum coord, GLenum pname, GLint param))
+SDL_PROC_UNUSED(void, glTexGeniv,
+ (GLenum coord, GLenum pname, const GLint * params))
+SDL_PROC_UNUSED(void, glTexImage1D,
+ (GLenum target, GLint level, GLint internalformat,
+ GLsizei width, GLint border, GLenum format, GLenum type,
+ const GLvoid * pixels))
+SDL_PROC(void, glTexImage2D,
+ (GLenum target, GLint level, GLint internalformat, GLsizei width,
+ GLsizei height, GLint border, GLenum format, GLenum type,
+ const GLvoid * pixels))
+SDL_PROC_UNUSED(void, glTexParameterf,
+ (GLenum target, GLenum pname, GLfloat param))
+SDL_PROC_UNUSED(void, glTexParameterfv,
+ (GLenum target, GLenum pname, const GLfloat * params))
+SDL_PROC(void, glTexParameteri, (GLenum target, GLenum pname, GLint param))
+SDL_PROC_UNUSED(void, glTexParameteriv,
+ (GLenum target, GLenum pname, const GLint * params))
+SDL_PROC_UNUSED(void, glTexSubImage1D,
+ (GLenum target, GLint level, GLint xoffset, GLsizei width,
+ GLenum format, GLenum type, const GLvoid * pixels))
+SDL_PROC(void, glTexSubImage2D,
+ (GLenum target, GLint level, GLint xoffset, GLint yoffset,
+ GLsizei width, GLsizei height, GLenum format, GLenum type,
+ const GLvoid * pixels))
+SDL_PROC_UNUSED(void, glTranslated, (GLdouble x, GLdouble y, GLdouble z))
+SDL_PROC(void, glTranslatef, (GLfloat x, GLfloat y, GLfloat z))
+SDL_PROC_UNUSED(void, glVertex2d, (GLdouble x, GLdouble y))
+SDL_PROC_UNUSED(void, glVertex2dv, (const GLdouble * v))
+SDL_PROC(void, glVertex2f, (GLfloat x, GLfloat y))
+SDL_PROC_UNUSED(void, glVertex2fv, (const GLfloat * v))
+SDL_PROC_UNUSED(void, glVertex2i, (GLint x, GLint y))
+SDL_PROC_UNUSED(void, glVertex2iv, (const GLint * v))
+SDL_PROC_UNUSED(void, glVertex2s, (GLshort x, GLshort y))
+SDL_PROC_UNUSED(void, glVertex2sv, (const GLshort * v))
+SDL_PROC_UNUSED(void, glVertex3d, (GLdouble x, GLdouble y, GLdouble z))
+SDL_PROC_UNUSED(void, glVertex3dv, (const GLdouble * v))
+SDL_PROC_UNUSED(void, glVertex3f, (GLfloat x, GLfloat y, GLfloat z))
+SDL_PROC(void, glVertex3fv, (const GLfloat * v))
+SDL_PROC_UNUSED(void, glVertex3i, (GLint x, GLint y, GLint z))
+SDL_PROC_UNUSED(void, glVertex3iv, (const GLint * v))
+SDL_PROC_UNUSED(void, glVertex3s, (GLshort x, GLshort y, GLshort z))
+SDL_PROC_UNUSED(void, glVertex3sv, (const GLshort * v))
+SDL_PROC_UNUSED(void, glVertex4d,
+ (GLdouble x, GLdouble y, GLdouble z, GLdouble w))
+SDL_PROC_UNUSED(void, glVertex4dv, (const GLdouble * v))
+SDL_PROC_UNUSED(void, glVertex4f,
+ (GLfloat x, GLfloat y, GLfloat z, GLfloat w))
+SDL_PROC_UNUSED(void, glVertex4fv, (const GLfloat * v))
+SDL_PROC_UNUSED(void, glVertex4i, (GLint x, GLint y, GLint z, GLint w))
+SDL_PROC_UNUSED(void, glVertex4iv, (const GLint * v))
+SDL_PROC_UNUSED(void, glVertex4s,
+ (GLshort x, GLshort y, GLshort z, GLshort w))
+SDL_PROC_UNUSED(void, glVertex4sv, (const GLshort * v))
+SDL_PROC_UNUSED(void, glVertexPointer,
+ (GLint size, GLenum type, GLsizei stride,
+ const GLvoid * pointer))
+SDL_PROC(void, glViewport, (GLint x, GLint y, GLsizei width, GLsizei height))
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/opengl/SDL_render_gl.c b/src/3rdparty/SDL2/src/render/opengl/SDL_render_gl.c
new file mode 100644
index 0000000..1c379eb
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/opengl/SDL_render_gl.c
@@ -0,0 +1,1690 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED
+
+#include "SDL_hints.h"
+#include "SDL_log.h"
+#include "SDL_assert.h"
+#include "SDL_opengl.h"
+#include "../SDL_sysrender.h"
+#include "SDL_shaders_gl.h"
+
+#ifdef __MACOSX__
+#include <OpenGL/OpenGL.h>
+#endif
+
+/* To prevent unnecessary window recreation,
+ * these should match the defaults selected in SDL_GL_ResetAttributes
+ */
+
+#define RENDERER_CONTEXT_MAJOR 2
+#define RENDERER_CONTEXT_MINOR 1
+
+/* OpenGL renderer implementation */
+
+/* Details on optimizing the texture path on Mac OS X:
+ http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/opengl_texturedata.html
+*/
+
+/* Used to re-create the window with OpenGL capability */
+extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
+
+static const float inv255f = 1.0f / 255.0f;
+
+static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags);
+static void GL_WindowEvent(SDL_Renderer * renderer,
+ const SDL_WindowEvent *event);
+static int GL_GetOutputSize(SDL_Renderer * renderer, int *w, int *h);
+static SDL_bool GL_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode);
+static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, const void *pixels,
+ int pitch);
+static int GL_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch);
+static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, void **pixels, int *pitch);
+static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+static int GL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
+static int GL_UpdateViewport(SDL_Renderer * renderer);
+static int GL_UpdateClipRect(SDL_Renderer * renderer);
+static int GL_RenderClear(SDL_Renderer * renderer);
+static int GL_RenderDrawPoints(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count);
+static int GL_RenderDrawLines(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count);
+static int GL_RenderFillRects(SDL_Renderer * renderer,
+ const SDL_FRect * rects, int count);
+static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect);
+static int GL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect,
+ const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip);
+static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 pixel_format, void * pixels, int pitch);
+static void GL_RenderPresent(SDL_Renderer * renderer);
+static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+static void GL_DestroyRenderer(SDL_Renderer * renderer);
+static int GL_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh);
+static int GL_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture);
+
+SDL_RenderDriver GL_RenderDriver = {
+ GL_CreateRenderer,
+ {
+ "opengl",
+ (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
+ 1,
+ {SDL_PIXELFORMAT_ARGB8888},
+ 0,
+ 0}
+};
+
+typedef struct GL_FBOList GL_FBOList;
+
+struct GL_FBOList
+{
+ Uint32 w, h;
+ GLuint FBO;
+ GL_FBOList *next;
+};
+
+typedef struct
+{
+ SDL_GLContext context;
+
+ SDL_bool debug_enabled;
+ SDL_bool GL_ARB_debug_output_supported;
+ int errors;
+ char **error_messages;
+ GLDEBUGPROCARB next_error_callback;
+ GLvoid *next_error_userparam;
+
+ SDL_bool GL_ARB_texture_non_power_of_two_supported;
+ SDL_bool GL_ARB_texture_rectangle_supported;
+ struct {
+ GL_Shader shader;
+ Uint32 color;
+ SDL_BlendMode blendMode;
+ } current;
+
+ SDL_bool GL_EXT_framebuffer_object_supported;
+ GL_FBOList *framebuffers;
+
+ /* OpenGL functions */
+#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
+#include "SDL_glfuncs.h"
+#undef SDL_PROC
+
+ /* Multitexture support */
+ SDL_bool GL_ARB_multitexture_supported;
+ PFNGLACTIVETEXTUREARBPROC glActiveTextureARB;
+ GLint num_texture_units;
+
+ PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT;
+ PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT;
+ PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT;
+ PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT;
+ PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT;
+
+ /* Shader support */
+ GL_ShaderContext *shaders;
+
+} GL_RenderData;
+
+typedef struct
+{
+ GLuint texture;
+ GLenum type;
+ GLfloat texw;
+ GLfloat texh;
+ GLenum format;
+ GLenum formattype;
+ void *pixels;
+ int pitch;
+ SDL_Rect locked_rect;
+
+ /* YUV texture support */
+ SDL_bool yuv;
+ SDL_bool nv12;
+ GLuint utexture;
+ GLuint vtexture;
+
+ GL_FBOList *fbo;
+} GL_TextureData;
+
+SDL_FORCE_INLINE const char*
+GL_TranslateError (GLenum error)
+{
+#define GL_ERROR_TRANSLATE(e) case e: return #e;
+ switch (error) {
+ GL_ERROR_TRANSLATE(GL_INVALID_ENUM)
+ GL_ERROR_TRANSLATE(GL_INVALID_VALUE)
+ GL_ERROR_TRANSLATE(GL_INVALID_OPERATION)
+ GL_ERROR_TRANSLATE(GL_OUT_OF_MEMORY)
+ GL_ERROR_TRANSLATE(GL_NO_ERROR)
+ GL_ERROR_TRANSLATE(GL_STACK_OVERFLOW)
+ GL_ERROR_TRANSLATE(GL_STACK_UNDERFLOW)
+ GL_ERROR_TRANSLATE(GL_TABLE_TOO_LARGE)
+ default:
+ return "UNKNOWN";
+}
+#undef GL_ERROR_TRANSLATE
+}
+
+SDL_FORCE_INLINE void
+GL_ClearErrors(SDL_Renderer *renderer)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+
+ if (!data->debug_enabled)
+ {
+ return;
+ }
+ if (data->GL_ARB_debug_output_supported) {
+ if (data->errors) {
+ int i;
+ for (i = 0; i < data->errors; ++i) {
+ SDL_free(data->error_messages[i]);
+ }
+ SDL_free(data->error_messages);
+
+ data->errors = 0;
+ data->error_messages = NULL;
+ }
+ } else {
+ while (data->glGetError() != GL_NO_ERROR) {
+ continue;
+ }
+ }
+}
+
+SDL_FORCE_INLINE int
+GL_CheckAllErrors (const char *prefix, SDL_Renderer *renderer, const char *file, int line, const char *function)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+ int ret = 0;
+
+ if (!data->debug_enabled)
+ {
+ return 0;
+ }
+ if (data->GL_ARB_debug_output_supported) {
+ if (data->errors) {
+ int i;
+ for (i = 0; i < data->errors; ++i) {
+ SDL_SetError("%s: %s (%d): %s %s", prefix, file, line, function, data->error_messages[i]);
+ ret = -1;
+ }
+ GL_ClearErrors(renderer);
+ }
+ } else {
+ /* check gl errors (can return multiple errors) */
+ for (;;) {
+ GLenum error = data->glGetError();
+ if (error != GL_NO_ERROR) {
+ if (prefix == NULL || prefix[0] == '\0') {
+ prefix = "generic";
+ }
+ SDL_SetError("%s: %s (%d): %s %s (0x%X)", prefix, file, line, function, GL_TranslateError(error), error);
+ ret = -1;
+ } else {
+ break;
+ }
+ }
+ }
+ return ret;
+}
+
+#if 0
+#define GL_CheckError(prefix, renderer)
+#else
+#define GL_CheckError(prefix, renderer) GL_CheckAllErrors(prefix, renderer, SDL_FILE, SDL_LINE, SDL_FUNCTION)
+#endif
+
+static int
+GL_LoadFunctions(GL_RenderData * data)
+{
+#ifdef __SDL_NOGETPROCADDR__
+#define SDL_PROC(ret,func,params) data->func=func;
+#else
+#define SDL_PROC(ret,func,params) \
+ do { \
+ data->func = SDL_GL_GetProcAddress(#func); \
+ if ( ! data->func ) { \
+ return SDL_SetError("Couldn't load GL function %s: %s", #func, SDL_GetError()); \
+ } \
+ } while ( 0 );
+#endif /* __SDL_NOGETPROCADDR__ */
+
+#include "SDL_glfuncs.h"
+#undef SDL_PROC
+ return 0;
+}
+
+static SDL_GLContext SDL_CurrentContext = NULL;
+
+static int
+GL_ActivateRenderer(SDL_Renderer * renderer)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+
+ if (SDL_CurrentContext != data->context ||
+ SDL_GL_GetCurrentContext() != data->context) {
+ if (SDL_GL_MakeCurrent(renderer->window, data->context) < 0) {
+ return -1;
+ }
+ SDL_CurrentContext = data->context;
+
+ GL_UpdateViewport(renderer);
+ }
+
+ GL_ClearErrors(renderer);
+
+ return 0;
+}
+
+/* This is called if we need to invalidate all of the SDL OpenGL state */
+static void
+GL_ResetState(SDL_Renderer *renderer)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+
+ if (SDL_GL_GetCurrentContext() == data->context) {
+ GL_UpdateViewport(renderer);
+ } else {
+ GL_ActivateRenderer(renderer);
+ }
+
+ data->current.shader = SHADER_NONE;
+ data->current.color = 0xffffffff;
+ data->current.blendMode = SDL_BLENDMODE_INVALID;
+
+ data->glDisable(GL_DEPTH_TEST);
+ data->glDisable(GL_CULL_FACE);
+ /* This ended up causing video discrepancies between OpenGL and Direct3D */
+ /* data->glEnable(GL_LINE_SMOOTH); */
+
+ data->glMatrixMode(GL_MODELVIEW);
+ data->glLoadIdentity();
+
+ GL_CheckError("", renderer);
+}
+
+static void APIENTRY
+GL_HandleDebugMessage(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const char *message, const void *userParam)
+{
+ SDL_Renderer *renderer = (SDL_Renderer *) userParam;
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+
+ if (type == GL_DEBUG_TYPE_ERROR_ARB) {
+ /* Record this error */
+ int errors = data->errors + 1;
+ char **error_messages = SDL_realloc(data->error_messages, errors * sizeof(*data->error_messages));
+ if (error_messages) {
+ data->errors = errors;
+ data->error_messages = error_messages;
+ data->error_messages[data->errors-1] = SDL_strdup(message);
+ }
+ }
+
+ /* If there's another error callback, pass it along, otherwise log it */
+ if (data->next_error_callback) {
+ data->next_error_callback(source, type, id, severity, length, message, data->next_error_userparam);
+ } else {
+ if (type == GL_DEBUG_TYPE_ERROR_ARB) {
+ SDL_LogError(SDL_LOG_CATEGORY_RENDER, "%s", message);
+ } else {
+ SDL_LogDebug(SDL_LOG_CATEGORY_RENDER, "%s", message);
+ }
+ }
+}
+
+static GL_FBOList *
+GL_GetFBO(GL_RenderData *data, Uint32 w, Uint32 h)
+{
+ GL_FBOList *result = data->framebuffers;
+
+ while (result && ((result->w != w) || (result->h != h))) {
+ result = result->next;
+ }
+
+ if (!result) {
+ result = SDL_malloc(sizeof(GL_FBOList));
+ if (result) {
+ result->w = w;
+ result->h = h;
+ data->glGenFramebuffersEXT(1, &result->FBO);
+ result->next = data->framebuffers;
+ data->framebuffers = result;
+ }
+ }
+ return result;
+}
+
+SDL_Renderer *
+GL_CreateRenderer(SDL_Window * window, Uint32 flags)
+{
+ SDL_Renderer *renderer;
+ GL_RenderData *data;
+ GLint value;
+ Uint32 window_flags;
+ int profile_mask = 0, major = 0, minor = 0;
+ SDL_bool changed_window = SDL_FALSE;
+
+ SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask);
+ SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
+ SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
+
+ window_flags = SDL_GetWindowFlags(window);
+ if (!(window_flags & SDL_WINDOW_OPENGL) ||
+ profile_mask == SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
+
+ changed_window = SDL_TRUE;
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
+
+ if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
+ goto error;
+ }
+ }
+
+ renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
+ if (!renderer) {
+ SDL_OutOfMemory();
+ goto error;
+ }
+
+ data = (GL_RenderData *) SDL_calloc(1, sizeof(*data));
+ if (!data) {
+ GL_DestroyRenderer(renderer);
+ SDL_OutOfMemory();
+ goto error;
+ }
+
+ renderer->WindowEvent = GL_WindowEvent;
+ renderer->GetOutputSize = GL_GetOutputSize;
+ renderer->SupportsBlendMode = GL_SupportsBlendMode;
+ renderer->CreateTexture = GL_CreateTexture;
+ renderer->UpdateTexture = GL_UpdateTexture;
+ renderer->UpdateTextureYUV = GL_UpdateTextureYUV;
+ renderer->LockTexture = GL_LockTexture;
+ renderer->UnlockTexture = GL_UnlockTexture;
+ renderer->SetRenderTarget = GL_SetRenderTarget;
+ renderer->UpdateViewport = GL_UpdateViewport;
+ renderer->UpdateClipRect = GL_UpdateClipRect;
+ renderer->RenderClear = GL_RenderClear;
+ renderer->RenderDrawPoints = GL_RenderDrawPoints;
+ renderer->RenderDrawLines = GL_RenderDrawLines;
+ renderer->RenderFillRects = GL_RenderFillRects;
+ renderer->RenderCopy = GL_RenderCopy;
+ renderer->RenderCopyEx = GL_RenderCopyEx;
+ renderer->RenderReadPixels = GL_RenderReadPixels;
+ renderer->RenderPresent = GL_RenderPresent;
+ renderer->DestroyTexture = GL_DestroyTexture;
+ renderer->DestroyRenderer = GL_DestroyRenderer;
+ renderer->GL_BindTexture = GL_BindTexture;
+ renderer->GL_UnbindTexture = GL_UnbindTexture;
+ renderer->info = GL_RenderDriver.info;
+ renderer->info.flags = SDL_RENDERER_ACCELERATED;
+ renderer->driverdata = data;
+ renderer->window = window;
+
+ data->context = SDL_GL_CreateContext(window);
+ if (!data->context) {
+ GL_DestroyRenderer(renderer);
+ goto error;
+ }
+ if (SDL_GL_MakeCurrent(window, data->context) < 0) {
+ GL_DestroyRenderer(renderer);
+ goto error;
+ }
+
+ if (GL_LoadFunctions(data) < 0) {
+ GL_DestroyRenderer(renderer);
+ goto error;
+ }
+
+#ifdef __MACOSX__
+ /* Enable multi-threaded rendering */
+ /* Disabled until Ryan finishes his VBO/PBO code...
+ CGLEnable(CGLGetCurrentContext(), kCGLCEMPEngine);
+ */
+#endif
+
+ if (flags & SDL_RENDERER_PRESENTVSYNC) {
+ SDL_GL_SetSwapInterval(1);
+ } else {
+ SDL_GL_SetSwapInterval(0);
+ }
+ if (SDL_GL_GetSwapInterval() > 0) {
+ renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
+ }
+
+ /* Check for debug output support */
+ if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_FLAGS, &value) == 0 &&
+ (value & SDL_GL_CONTEXT_DEBUG_FLAG)) {
+ data->debug_enabled = SDL_TRUE;
+ }
+ if (data->debug_enabled && SDL_GL_ExtensionSupported("GL_ARB_debug_output")) {
+ PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARBFunc = (PFNGLDEBUGMESSAGECALLBACKARBPROC) SDL_GL_GetProcAddress("glDebugMessageCallbackARB");
+
+ data->GL_ARB_debug_output_supported = SDL_TRUE;
+ data->glGetPointerv(GL_DEBUG_CALLBACK_FUNCTION_ARB, (GLvoid **)(char *)&data->next_error_callback);
+ data->glGetPointerv(GL_DEBUG_CALLBACK_USER_PARAM_ARB, &data->next_error_userparam);
+ glDebugMessageCallbackARBFunc(GL_HandleDebugMessage, renderer);
+
+ /* Make sure our callback is called when errors actually happen */
+ data->glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
+ }
+
+ if (SDL_GL_ExtensionSupported("GL_ARB_texture_non_power_of_two")) {
+ data->GL_ARB_texture_non_power_of_two_supported = SDL_TRUE;
+ } else if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle") ||
+ SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
+ data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
+ }
+ if (data->GL_ARB_texture_rectangle_supported) {
+ data->glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &value);
+ renderer->info.max_texture_width = value;
+ renderer->info.max_texture_height = value;
+ } else {
+ data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
+ renderer->info.max_texture_width = value;
+ renderer->info.max_texture_height = value;
+ }
+
+ /* Check for multitexture support */
+ if (SDL_GL_ExtensionSupported("GL_ARB_multitexture")) {
+ data->glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) SDL_GL_GetProcAddress("glActiveTextureARB");
+ if (data->glActiveTextureARB) {
+ data->GL_ARB_multitexture_supported = SDL_TRUE;
+ data->glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &data->num_texture_units);
+ }
+ }
+
+ /* Check for shader support */
+ if (SDL_GetHintBoolean(SDL_HINT_RENDER_OPENGL_SHADERS, SDL_TRUE)) {
+ data->shaders = GL_CreateShaderContext();
+ }
+ SDL_LogInfo(SDL_LOG_CATEGORY_RENDER, "OpenGL shaders: %s",
+ data->shaders ? "ENABLED" : "DISABLED");
+
+ /* We support YV12 textures using 3 textures and a shader */
+ if (data->shaders && data->num_texture_units >= 3) {
+ renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_YV12;
+ renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_IYUV;
+ renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_NV12;
+ renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_NV21;
+ }
+
+#ifdef __MACOSX__
+ renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_UYVY;
+#endif
+
+ if (SDL_GL_ExtensionSupported("GL_EXT_framebuffer_object")) {
+ data->GL_EXT_framebuffer_object_supported = SDL_TRUE;
+ data->glGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC)
+ SDL_GL_GetProcAddress("glGenFramebuffersEXT");
+ data->glDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC)
+ SDL_GL_GetProcAddress("glDeleteFramebuffersEXT");
+ data->glFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)
+ SDL_GL_GetProcAddress("glFramebufferTexture2DEXT");
+ data->glBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC)
+ SDL_GL_GetProcAddress("glBindFramebufferEXT");
+ data->glCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)
+ SDL_GL_GetProcAddress("glCheckFramebufferStatusEXT");
+ renderer->info.flags |= SDL_RENDERER_TARGETTEXTURE;
+ }
+ data->framebuffers = NULL;
+
+ /* Set up parameters for rendering */
+ GL_ResetState(renderer);
+
+ return renderer;
+
+error:
+ if (changed_window) {
+ /* Uh oh, better try to put it back... */
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
+ SDL_RecreateWindow(window, window_flags);
+ }
+ return NULL;
+}
+
+static void
+GL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
+{
+ if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED ||
+ event->event == SDL_WINDOWEVENT_SHOWN ||
+ event->event == SDL_WINDOWEVENT_HIDDEN) {
+ /* Rebind the context to the window area and update matrices */
+ SDL_CurrentContext = NULL;
+ }
+}
+
+static int
+GL_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
+{
+ SDL_GL_GetDrawableSize(renderer->window, w, h);
+ return 0;
+}
+
+static GLenum GetBlendFunc(SDL_BlendFactor factor)
+{
+ switch (factor) {
+ case SDL_BLENDFACTOR_ZERO:
+ return GL_ZERO;
+ case SDL_BLENDFACTOR_ONE:
+ return GL_ONE;
+ case SDL_BLENDFACTOR_SRC_COLOR:
+ return GL_SRC_COLOR;
+ case SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR:
+ return GL_ONE_MINUS_SRC_COLOR;
+ case SDL_BLENDFACTOR_SRC_ALPHA:
+ return GL_SRC_ALPHA;
+ case SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA:
+ return GL_ONE_MINUS_SRC_ALPHA;
+ case SDL_BLENDFACTOR_DST_COLOR:
+ return GL_DST_COLOR;
+ case SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR:
+ return GL_ONE_MINUS_DST_COLOR;
+ case SDL_BLENDFACTOR_DST_ALPHA:
+ return GL_DST_ALPHA;
+ case SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA:
+ return GL_ONE_MINUS_DST_ALPHA;
+ default:
+ return GL_INVALID_ENUM;
+ }
+}
+
+static GLenum GetBlendEquation(SDL_BlendOperation operation)
+{
+ switch (operation) {
+ case SDL_BLENDOPERATION_ADD:
+ return GL_FUNC_ADD;
+ case SDL_BLENDOPERATION_SUBTRACT:
+ return GL_FUNC_SUBTRACT;
+ case SDL_BLENDOPERATION_REV_SUBTRACT:
+ return GL_FUNC_REVERSE_SUBTRACT;
+ default:
+ return GL_INVALID_ENUM;
+ }
+}
+
+static SDL_bool
+GL_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
+{
+ SDL_BlendFactor srcColorFactor = SDL_GetBlendModeSrcColorFactor(blendMode);
+ SDL_BlendFactor srcAlphaFactor = SDL_GetBlendModeSrcAlphaFactor(blendMode);
+ SDL_BlendOperation colorOperation = SDL_GetBlendModeColorOperation(blendMode);
+ SDL_BlendFactor dstColorFactor = SDL_GetBlendModeDstColorFactor(blendMode);
+ SDL_BlendFactor dstAlphaFactor = SDL_GetBlendModeDstAlphaFactor(blendMode);
+ SDL_BlendOperation alphaOperation = SDL_GetBlendModeAlphaOperation(blendMode);
+
+ if (GetBlendFunc(srcColorFactor) == GL_INVALID_ENUM ||
+ GetBlendFunc(srcAlphaFactor) == GL_INVALID_ENUM ||
+ GetBlendEquation(colorOperation) == GL_INVALID_ENUM ||
+ GetBlendFunc(dstColorFactor) == GL_INVALID_ENUM ||
+ GetBlendFunc(dstAlphaFactor) == GL_INVALID_ENUM ||
+ GetBlendEquation(alphaOperation) == GL_INVALID_ENUM) {
+ return SDL_FALSE;
+ }
+ if (colorOperation != alphaOperation) {
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
+}
+
+SDL_FORCE_INLINE int
+power_of_2(int input)
+{
+ int value = 1;
+
+ while (value < input) {
+ value <<= 1;
+ }
+ return value;
+}
+
+SDL_FORCE_INLINE SDL_bool
+convert_format(GL_RenderData *renderdata, Uint32 pixel_format,
+ GLint* internalFormat, GLenum* format, GLenum* type)
+{
+ switch (pixel_format) {
+ case SDL_PIXELFORMAT_ARGB8888:
+ *internalFormat = GL_RGBA8;
+ *format = GL_BGRA;
+ *type = GL_UNSIGNED_INT_8_8_8_8_REV;
+ break;
+ case SDL_PIXELFORMAT_YV12:
+ case SDL_PIXELFORMAT_IYUV:
+ case SDL_PIXELFORMAT_NV12:
+ case SDL_PIXELFORMAT_NV21:
+ *internalFormat = GL_LUMINANCE;
+ *format = GL_LUMINANCE;
+ *type = GL_UNSIGNED_BYTE;
+ break;
+#ifdef __MACOSX__
+ case SDL_PIXELFORMAT_UYVY:
+ *internalFormat = GL_RGB8;
+ *format = GL_YCBCR_422_APPLE;
+ *type = GL_UNSIGNED_SHORT_8_8_APPLE;
+ break;
+#endif
+ default:
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
+}
+
+static GLenum
+GetScaleQuality(void)
+{
+ const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
+
+ if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
+ return GL_NEAREST;
+ } else {
+ return GL_LINEAR;
+ }
+}
+
+static int
+GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
+ GL_TextureData *data;
+ GLint internalFormat;
+ GLenum format, type;
+ int texture_w, texture_h;
+ GLenum scaleMode;
+
+ GL_ActivateRenderer(renderer);
+
+ if (texture->access == SDL_TEXTUREACCESS_TARGET &&
+ !renderdata->GL_EXT_framebuffer_object_supported) {
+ return SDL_SetError("Render targets not supported by OpenGL");
+ }
+
+ if (!convert_format(renderdata, texture->format, &internalFormat,
+ &format, &type)) {
+ return SDL_SetError("Texture format %s not supported by OpenGL",
+ SDL_GetPixelFormatName(texture->format));
+ }
+
+ data = (GL_TextureData *) SDL_calloc(1, sizeof(*data));
+ if (!data) {
+ return SDL_OutOfMemory();
+ }
+
+ if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
+ size_t size;
+ data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
+ size = texture->h * data->pitch;
+ if (texture->format == SDL_PIXELFORMAT_YV12 ||
+ texture->format == SDL_PIXELFORMAT_IYUV) {
+ /* Need to add size for the U and V planes */
+ size += 2 * ((texture->h + 1) / 2) * ((data->pitch + 1) / 2);
+ }
+ if (texture->format == SDL_PIXELFORMAT_NV12 ||
+ texture->format == SDL_PIXELFORMAT_NV21) {
+ /* Need to add size for the U/V plane */
+ size += 2 * ((texture->h + 1) / 2) * ((data->pitch + 1) / 2);
+ }
+ data->pixels = SDL_calloc(1, size);
+ if (!data->pixels) {
+ SDL_free(data);
+ return SDL_OutOfMemory();
+ }
+ }
+
+ if (texture->access == SDL_TEXTUREACCESS_TARGET) {
+ data->fbo = GL_GetFBO(renderdata, texture->w, texture->h);
+ } else {
+ data->fbo = NULL;
+ }
+
+ GL_CheckError("", renderer);
+ renderdata->glGenTextures(1, &data->texture);
+ if (GL_CheckError("glGenTextures()", renderer) < 0) {
+ if (data->pixels) {
+ SDL_free(data->pixels);
+ }
+ SDL_free(data);
+ return -1;
+ }
+ texture->driverdata = data;
+
+ if (renderdata->GL_ARB_texture_non_power_of_two_supported) {
+ data->type = GL_TEXTURE_2D;
+ texture_w = texture->w;
+ texture_h = texture->h;
+ data->texw = 1.0f;
+ data->texh = 1.0f;
+ } else if (renderdata->GL_ARB_texture_rectangle_supported) {
+ data->type = GL_TEXTURE_RECTANGLE_ARB;
+ texture_w = texture->w;
+ texture_h = texture->h;
+ data->texw = (GLfloat) texture_w;
+ data->texh = (GLfloat) texture_h;
+ } else {
+ data->type = GL_TEXTURE_2D;
+ texture_w = power_of_2(texture->w);
+ texture_h = power_of_2(texture->h);
+ data->texw = (GLfloat) (texture->w) / texture_w;
+ data->texh = (GLfloat) texture->h / texture_h;
+ }
+
+ data->format = format;
+ data->formattype = type;
+ scaleMode = GetScaleQuality();
+ renderdata->glEnable(data->type);
+ renderdata->glBindTexture(data->type, data->texture);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, scaleMode);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, scaleMode);
+ /* According to the spec, CLAMP_TO_EDGE is the default for TEXTURE_RECTANGLE
+ and setting it causes an INVALID_ENUM error in the latest NVidia drivers.
+ */
+ if (data->type != GL_TEXTURE_RECTANGLE_ARB) {
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
+ GL_CLAMP_TO_EDGE);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
+ GL_CLAMP_TO_EDGE);
+ }
+#ifdef __MACOSX__
+#ifndef GL_TEXTURE_STORAGE_HINT_APPLE
+#define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC
+#endif
+#ifndef STORAGE_CACHED_APPLE
+#define STORAGE_CACHED_APPLE 0x85BE
+#endif
+#ifndef STORAGE_SHARED_APPLE
+#define STORAGE_SHARED_APPLE 0x85BF
+#endif
+ if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
+ GL_STORAGE_SHARED_APPLE);
+ } else {
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
+ GL_STORAGE_CACHED_APPLE);
+ }
+ if (texture->access == SDL_TEXTUREACCESS_STREAMING
+ && texture->format == SDL_PIXELFORMAT_ARGB8888
+ && (texture->w % 8) == 0) {
+ renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
+ renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH,
+ (data->pitch / SDL_BYTESPERPIXEL(texture->format)));
+ renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
+ texture_h, 0, format, type, data->pixels);
+ renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
+ }
+ else
+#endif
+ {
+ renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
+ texture_h, 0, format, type, NULL);
+ }
+ renderdata->glDisable(data->type);
+ if (GL_CheckError("glTexImage2D()", renderer) < 0) {
+ return -1;
+ }
+
+ if (texture->format == SDL_PIXELFORMAT_YV12 ||
+ texture->format == SDL_PIXELFORMAT_IYUV) {
+ data->yuv = SDL_TRUE;
+
+ renderdata->glGenTextures(1, &data->utexture);
+ renderdata->glGenTextures(1, &data->vtexture);
+ renderdata->glEnable(data->type);
+
+ renderdata->glBindTexture(data->type, data->utexture);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
+ scaleMode);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
+ scaleMode);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
+ GL_CLAMP_TO_EDGE);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
+ GL_CLAMP_TO_EDGE);
+ renderdata->glTexImage2D(data->type, 0, internalFormat, (texture_w+1)/2,
+ (texture_h+1)/2, 0, format, type, NULL);
+
+ renderdata->glBindTexture(data->type, data->vtexture);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
+ scaleMode);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
+ scaleMode);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
+ GL_CLAMP_TO_EDGE);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
+ GL_CLAMP_TO_EDGE);
+ renderdata->glTexImage2D(data->type, 0, internalFormat, (texture_w+1)/2,
+ (texture_h+1)/2, 0, format, type, NULL);
+
+ renderdata->glDisable(data->type);
+ }
+
+ if (texture->format == SDL_PIXELFORMAT_NV12 ||
+ texture->format == SDL_PIXELFORMAT_NV21) {
+ data->nv12 = SDL_TRUE;
+
+ renderdata->glGenTextures(1, &data->utexture);
+ renderdata->glEnable(data->type);
+
+ renderdata->glBindTexture(data->type, data->utexture);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
+ scaleMode);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
+ scaleMode);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
+ GL_CLAMP_TO_EDGE);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
+ GL_CLAMP_TO_EDGE);
+ renderdata->glTexImage2D(data->type, 0, GL_LUMINANCE_ALPHA, (texture_w+1)/2,
+ (texture_h+1)/2, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NULL);
+ renderdata->glDisable(data->type);
+ }
+
+ return GL_CheckError("", renderer);
+}
+
+static int
+GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, const void *pixels, int pitch)
+{
+ GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
+ GL_TextureData *data = (GL_TextureData *) texture->driverdata;
+ const int texturebpp = SDL_BYTESPERPIXEL(texture->format);
+
+ SDL_assert(texturebpp != 0); /* otherwise, division by zero later. */
+
+ GL_ActivateRenderer(renderer);
+
+ renderdata->glEnable(data->type);
+ renderdata->glBindTexture(data->type, data->texture);
+ renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, (pitch / texturebpp));
+ renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
+ rect->h, data->format, data->formattype,
+ pixels);
+ if (data->yuv) {
+ renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, ((pitch + 1) / 2));
+
+ /* Skip to the correct offset into the next texture */
+ pixels = (const void*)((const Uint8*)pixels + rect->h * pitch);
+ if (texture->format == SDL_PIXELFORMAT_YV12) {
+ renderdata->glBindTexture(data->type, data->vtexture);
+ } else {
+ renderdata->glBindTexture(data->type, data->utexture);
+ }
+ renderdata->glTexSubImage2D(data->type, 0, rect->x/2, rect->y/2,
+ (rect->w+1)/2, (rect->h+1)/2,
+ data->format, data->formattype, pixels);
+
+ /* Skip to the correct offset into the next texture */
+ pixels = (const void*)((const Uint8*)pixels + ((rect->h + 1) / 2) * ((pitch + 1) / 2));
+ if (texture->format == SDL_PIXELFORMAT_YV12) {
+ renderdata->glBindTexture(data->type, data->utexture);
+ } else {
+ renderdata->glBindTexture(data->type, data->vtexture);
+ }
+ renderdata->glTexSubImage2D(data->type, 0, rect->x/2, rect->y/2,
+ (rect->w+1)/2, (rect->h+1)/2,
+ data->format, data->formattype, pixels);
+ }
+
+ if (data->nv12) {
+ renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, ((pitch + 1) / 2));
+
+ /* Skip to the correct offset into the next texture */
+ pixels = (const void*)((const Uint8*)pixels + rect->h * pitch);
+ renderdata->glBindTexture(data->type, data->utexture);
+ renderdata->glTexSubImage2D(data->type, 0, rect->x/2, rect->y/2,
+ (rect->w + 1)/2, (rect->h + 1)/2,
+ GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, pixels);
+ }
+ renderdata->glDisable(data->type);
+
+ return GL_CheckError("glTexSubImage2D()", renderer);
+}
+
+static int
+GL_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch)
+{
+ GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
+ GL_TextureData *data = (GL_TextureData *) texture->driverdata;
+
+ GL_ActivateRenderer(renderer);
+
+ renderdata->glEnable(data->type);
+ renderdata->glBindTexture(data->type, data->texture);
+ renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, Ypitch);
+ renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
+ rect->h, data->format, data->formattype,
+ Yplane);
+
+ renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, Upitch);
+ renderdata->glBindTexture(data->type, data->utexture);
+ renderdata->glTexSubImage2D(data->type, 0, rect->x/2, rect->y/2,
+ (rect->w + 1)/2, (rect->h + 1)/2,
+ data->format, data->formattype, Uplane);
+
+ renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, Vpitch);
+ renderdata->glBindTexture(data->type, data->vtexture);
+ renderdata->glTexSubImage2D(data->type, 0, rect->x/2, rect->y/2,
+ (rect->w + 1)/2, (rect->h + 1)/2,
+ data->format, data->formattype, Vplane);
+ renderdata->glDisable(data->type);
+
+ return GL_CheckError("glTexSubImage2D()", renderer);
+}
+
+static int
+GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, void **pixels, int *pitch)
+{
+ GL_TextureData *data = (GL_TextureData *) texture->driverdata;
+
+ data->locked_rect = *rect;
+ *pixels =
+ (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
+ rect->x * SDL_BYTESPERPIXEL(texture->format));
+ *pitch = data->pitch;
+ return 0;
+}
+
+static void
+GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ GL_TextureData *data = (GL_TextureData *) texture->driverdata;
+ const SDL_Rect *rect;
+ void *pixels;
+
+ rect = &data->locked_rect;
+ pixels =
+ (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
+ rect->x * SDL_BYTESPERPIXEL(texture->format));
+ GL_UpdateTexture(renderer, texture, rect, pixels, data->pitch);
+}
+
+static int
+GL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+ GL_TextureData *texturedata;
+ GLenum status;
+
+ GL_ActivateRenderer(renderer);
+
+ if (!data->GL_EXT_framebuffer_object_supported) {
+ return SDL_SetError("Render targets not supported by OpenGL");
+ }
+
+ if (texture == NULL) {
+ data->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ return 0;
+ }
+
+ texturedata = (GL_TextureData *) texture->driverdata;
+ data->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, texturedata->fbo->FBO);
+ /* TODO: check if texture pixel format allows this operation */
+ data->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, texturedata->type, texturedata->texture, 0);
+ /* Check FBO status */
+ status = data->glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
+ if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ return SDL_SetError("glFramebufferTexture2DEXT() failed");
+ }
+ return 0;
+}
+
+static int
+GL_UpdateViewport(SDL_Renderer * renderer)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+
+ if (SDL_CurrentContext != data->context) {
+ /* We'll update the viewport after we rebind the context */
+ return 0;
+ }
+
+ if (renderer->target) {
+ data->glViewport(renderer->viewport.x, renderer->viewport.y,
+ renderer->viewport.w, renderer->viewport.h);
+ } else {
+ int w, h;
+
+ SDL_GL_GetDrawableSize(renderer->window, &w, &h);
+ data->glViewport(renderer->viewport.x, (h - renderer->viewport.y - renderer->viewport.h),
+ renderer->viewport.w, renderer->viewport.h);
+ }
+
+ data->glMatrixMode(GL_PROJECTION);
+ data->glLoadIdentity();
+ if (renderer->viewport.w && renderer->viewport.h) {
+ if (renderer->target) {
+ data->glOrtho((GLdouble) 0,
+ (GLdouble) renderer->viewport.w,
+ (GLdouble) 0,
+ (GLdouble) renderer->viewport.h,
+ 0.0, 1.0);
+ } else {
+ data->glOrtho((GLdouble) 0,
+ (GLdouble) renderer->viewport.w,
+ (GLdouble) renderer->viewport.h,
+ (GLdouble) 0,
+ 0.0, 1.0);
+ }
+ }
+ data->glMatrixMode(GL_MODELVIEW);
+
+ return GL_CheckError("", renderer);
+}
+
+static int
+GL_UpdateClipRect(SDL_Renderer * renderer)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+
+ if (renderer->clipping_enabled) {
+ const SDL_Rect *rect = &renderer->clip_rect;
+ data->glEnable(GL_SCISSOR_TEST);
+ if (renderer->target) {
+ data->glScissor(renderer->viewport.x + rect->x, renderer->viewport.y + rect->y, rect->w, rect->h);
+ } else {
+ int w, h;
+
+ SDL_GL_GetDrawableSize(renderer->window, &w, &h);
+ data->glScissor(renderer->viewport.x + rect->x, h - renderer->viewport.y - rect->y - rect->h, rect->w, rect->h);
+ }
+ } else {
+ data->glDisable(GL_SCISSOR_TEST);
+ }
+ return 0;
+}
+
+static void
+GL_SetShader(GL_RenderData * data, GL_Shader shader)
+{
+ if (data->shaders && shader != data->current.shader) {
+ GL_SelectShader(data->shaders, shader);
+ data->current.shader = shader;
+ }
+}
+
+static void
+GL_SetColor(GL_RenderData * data, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ Uint32 color = ((a << 24) | (r << 16) | (g << 8) | b);
+
+ if (color != data->current.color) {
+ data->glColor4f((GLfloat) r * inv255f,
+ (GLfloat) g * inv255f,
+ (GLfloat) b * inv255f,
+ (GLfloat) a * inv255f);
+ data->current.color = color;
+ }
+}
+
+static void
+GL_SetBlendMode(GL_RenderData * data, SDL_BlendMode blendMode)
+{
+ if (blendMode != data->current.blendMode) {
+ if (blendMode == SDL_BLENDMODE_NONE) {
+ data->glDisable(GL_BLEND);
+ } else {
+ data->glEnable(GL_BLEND);
+ data->glBlendFuncSeparate(GetBlendFunc(SDL_GetBlendModeSrcColorFactor(blendMode)),
+ GetBlendFunc(SDL_GetBlendModeDstColorFactor(blendMode)),
+ GetBlendFunc(SDL_GetBlendModeSrcAlphaFactor(blendMode)),
+ GetBlendFunc(SDL_GetBlendModeDstAlphaFactor(blendMode)));
+ data->glBlendEquation(GetBlendEquation(SDL_GetBlendModeColorOperation(blendMode)));
+ }
+ data->current.blendMode = blendMode;
+ }
+}
+
+static void
+GL_SetDrawingState(SDL_Renderer * renderer)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+
+ GL_ActivateRenderer(renderer);
+
+ GL_SetColor(data, renderer->r,
+ renderer->g,
+ renderer->b,
+ renderer->a);
+
+ GL_SetBlendMode(data, renderer->blendMode);
+
+ GL_SetShader(data, SHADER_SOLID);
+}
+
+static int
+GL_RenderClear(SDL_Renderer * renderer)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+
+ GL_ActivateRenderer(renderer);
+
+ data->glClearColor((GLfloat) renderer->r * inv255f,
+ (GLfloat) renderer->g * inv255f,
+ (GLfloat) renderer->b * inv255f,
+ (GLfloat) renderer->a * inv255f);
+
+ if (renderer->clipping_enabled) {
+ data->glDisable(GL_SCISSOR_TEST);
+ }
+
+ data->glClear(GL_COLOR_BUFFER_BIT);
+
+ if (renderer->clipping_enabled) {
+ data->glEnable(GL_SCISSOR_TEST);
+ }
+
+ return 0;
+}
+
+static int
+GL_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points,
+ int count)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+ int i;
+
+ GL_SetDrawingState(renderer);
+
+ data->glBegin(GL_POINTS);
+ for (i = 0; i < count; ++i) {
+ data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
+ }
+ data->glEnd();
+
+ return 0;
+}
+
+static int
+GL_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points,
+ int count)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+ int i;
+
+ GL_SetDrawingState(renderer);
+
+ if (count > 2 &&
+ points[0].x == points[count-1].x && points[0].y == points[count-1].y) {
+ data->glBegin(GL_LINE_LOOP);
+ /* GL_LINE_LOOP takes care of the final segment */
+ --count;
+ for (i = 0; i < count; ++i) {
+ data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
+ }
+ data->glEnd();
+ } else {
+#if defined(__MACOSX__) || defined(__WIN32__)
+#else
+ int x1, y1, x2, y2;
+#endif
+
+ data->glBegin(GL_LINE_STRIP);
+ for (i = 0; i < count; ++i) {
+ data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
+ }
+ data->glEnd();
+
+ /* The line is half open, so we need one more point to complete it.
+ * http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node47.html
+ * If we have to, we can use vertical line and horizontal line textures
+ * for vertical and horizontal lines, and then create custom textures
+ * for diagonal lines and software render those. It's terrible, but at
+ * least it would be pixel perfect.
+ */
+ data->glBegin(GL_POINTS);
+#if defined(__MACOSX__) || defined(__WIN32__)
+ /* Mac OS X and Windows seem to always leave the last point open */
+ data->glVertex2f(0.5f + points[count-1].x, 0.5f + points[count-1].y);
+#else
+ /* Linux seems to leave the right-most or bottom-most point open */
+ x1 = points[0].x;
+ y1 = points[0].y;
+ x2 = points[count-1].x;
+ y2 = points[count-1].y;
+
+ if (x1 > x2) {
+ data->glVertex2f(0.5f + x1, 0.5f + y1);
+ } else if (x2 > x1) {
+ data->glVertex2f(0.5f + x2, 0.5f + y2);
+ }
+ if (y1 > y2) {
+ data->glVertex2f(0.5f + x1, 0.5f + y1);
+ } else if (y2 > y1) {
+ data->glVertex2f(0.5f + x2, 0.5f + y2);
+ }
+#endif
+ data->glEnd();
+ }
+ return GL_CheckError("", renderer);
+}
+
+static int
+GL_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, int count)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+ int i;
+
+ GL_SetDrawingState(renderer);
+
+ for (i = 0; i < count; ++i) {
+ const SDL_FRect *rect = &rects[i];
+
+ data->glRectf(rect->x, rect->y, rect->x + rect->w, rect->y + rect->h);
+ }
+ return GL_CheckError("", renderer);
+}
+
+static int
+GL_SetupCopy(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+ GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
+
+ data->glEnable(texturedata->type);
+ if (texturedata->yuv) {
+ data->glActiveTextureARB(GL_TEXTURE2_ARB);
+ data->glBindTexture(texturedata->type, texturedata->vtexture);
+
+ data->glActiveTextureARB(GL_TEXTURE1_ARB);
+ data->glBindTexture(texturedata->type, texturedata->utexture);
+
+ data->glActiveTextureARB(GL_TEXTURE0_ARB);
+ }
+ if (texturedata->nv12) {
+ data->glActiveTextureARB(GL_TEXTURE1_ARB);
+ data->glBindTexture(texturedata->type, texturedata->utexture);
+
+ data->glActiveTextureARB(GL_TEXTURE0_ARB);
+ }
+ data->glBindTexture(texturedata->type, texturedata->texture);
+
+ if (texture->modMode) {
+ GL_SetColor(data, texture->r, texture->g, texture->b, texture->a);
+ } else {
+ GL_SetColor(data, 255, 255, 255, 255);
+ }
+
+ GL_SetBlendMode(data, texture->blendMode);
+
+ if (texturedata->yuv || texturedata->nv12) {
+ switch (SDL_GetYUVConversionModeForResolution(texture->w, texture->h)) {
+ case SDL_YUV_CONVERSION_JPEG:
+ if (texturedata->yuv) {
+ GL_SetShader(data, SHADER_YUV_JPEG);
+ } else if (texture->format == SDL_PIXELFORMAT_NV12) {
+ GL_SetShader(data, SHADER_NV12_JPEG);
+ } else {
+ GL_SetShader(data, SHADER_NV21_JPEG);
+ }
+ break;
+ case SDL_YUV_CONVERSION_BT601:
+ if (texturedata->yuv) {
+ GL_SetShader(data, SHADER_YUV_BT601);
+ } else if (texture->format == SDL_PIXELFORMAT_NV12) {
+ GL_SetShader(data, SHADER_NV12_BT601);
+ } else {
+ GL_SetShader(data, SHADER_NV21_BT601);
+ }
+ break;
+ case SDL_YUV_CONVERSION_BT709:
+ if (texturedata->yuv) {
+ GL_SetShader(data, SHADER_YUV_BT709);
+ } else if (texture->format == SDL_PIXELFORMAT_NV12) {
+ GL_SetShader(data, SHADER_NV12_BT709);
+ } else {
+ GL_SetShader(data, SHADER_NV21_BT709);
+ }
+ break;
+ default:
+ return SDL_SetError("Unsupported YUV conversion mode");
+ }
+ } else {
+ GL_SetShader(data, SHADER_RGB);
+ }
+ return 0;
+}
+
+static int
+GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+ GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
+ GLfloat minx, miny, maxx, maxy;
+ GLfloat minu, maxu, minv, maxv;
+
+ GL_ActivateRenderer(renderer);
+
+ if (GL_SetupCopy(renderer, texture) < 0) {
+ return -1;
+ }
+
+ minx = dstrect->x;
+ miny = dstrect->y;
+ maxx = dstrect->x + dstrect->w;
+ maxy = dstrect->y + dstrect->h;
+
+ minu = (GLfloat) srcrect->x / texture->w;
+ minu *= texturedata->texw;
+ maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
+ maxu *= texturedata->texw;
+ minv = (GLfloat) srcrect->y / texture->h;
+ minv *= texturedata->texh;
+ maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
+ maxv *= texturedata->texh;
+
+ data->glBegin(GL_TRIANGLE_STRIP);
+ data->glTexCoord2f(minu, minv);
+ data->glVertex2f(minx, miny);
+ data->glTexCoord2f(maxu, minv);
+ data->glVertex2f(maxx, miny);
+ data->glTexCoord2f(minu, maxv);
+ data->glVertex2f(minx, maxy);
+ data->glTexCoord2f(maxu, maxv);
+ data->glVertex2f(maxx, maxy);
+ data->glEnd();
+
+ data->glDisable(texturedata->type);
+
+ return GL_CheckError("", renderer);
+}
+
+static int
+GL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect,
+ const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+ GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
+ GLfloat minx, miny, maxx, maxy;
+ GLfloat centerx, centery;
+ GLfloat minu, maxu, minv, maxv;
+
+ GL_ActivateRenderer(renderer);
+
+ if (GL_SetupCopy(renderer, texture) < 0) {
+ return -1;
+ }
+
+ centerx = center->x;
+ centery = center->y;
+
+ if (flip & SDL_FLIP_HORIZONTAL) {
+ minx = dstrect->w - centerx;
+ maxx = -centerx;
+ }
+ else {
+ minx = -centerx;
+ maxx = dstrect->w - centerx;
+ }
+
+ if (flip & SDL_FLIP_VERTICAL) {
+ miny = dstrect->h - centery;
+ maxy = -centery;
+ }
+ else {
+ miny = -centery;
+ maxy = dstrect->h - centery;
+ }
+
+ minu = (GLfloat) srcrect->x / texture->w;
+ minu *= texturedata->texw;
+ maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
+ maxu *= texturedata->texw;
+ minv = (GLfloat) srcrect->y / texture->h;
+ minv *= texturedata->texh;
+ maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
+ maxv *= texturedata->texh;
+
+ /* Translate to flip, rotate, translate to position */
+ data->glPushMatrix();
+ data->glTranslatef((GLfloat)dstrect->x + centerx, (GLfloat)dstrect->y + centery, (GLfloat)0.0);
+ data->glRotated(angle, (GLdouble)0.0, (GLdouble)0.0, (GLdouble)1.0);
+
+ data->glBegin(GL_TRIANGLE_STRIP);
+ data->glTexCoord2f(minu, minv);
+ data->glVertex2f(minx, miny);
+ data->glTexCoord2f(maxu, minv);
+ data->glVertex2f(maxx, miny);
+ data->glTexCoord2f(minu, maxv);
+ data->glVertex2f(minx, maxy);
+ data->glTexCoord2f(maxu, maxv);
+ data->glVertex2f(maxx, maxy);
+ data->glEnd();
+ data->glPopMatrix();
+
+ data->glDisable(texturedata->type);
+
+ return GL_CheckError("", renderer);
+}
+
+static int
+GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 pixel_format, void * pixels, int pitch)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+ Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ARGB8888;
+ void *temp_pixels;
+ int temp_pitch;
+ GLint internalFormat;
+ GLenum format, type;
+ Uint8 *src, *dst, *tmp;
+ int w, h, length, rows;
+ int status;
+
+ GL_ActivateRenderer(renderer);
+
+ if (!convert_format(data, temp_format, &internalFormat, &format, &type)) {
+ return SDL_SetError("Texture format %s not supported by OpenGL",
+ SDL_GetPixelFormatName(temp_format));
+ }
+
+ if (!rect->w || !rect->h) {
+ return 0; /* nothing to do. */
+ }
+
+ temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
+ temp_pixels = SDL_malloc(rect->h * temp_pitch);
+ if (!temp_pixels) {
+ return SDL_OutOfMemory();
+ }
+
+ SDL_GetRendererOutputSize(renderer, &w, &h);
+
+ data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
+ data->glPixelStorei(GL_PACK_ROW_LENGTH,
+ (temp_pitch / SDL_BYTESPERPIXEL(temp_format)));
+
+ data->glReadPixels(rect->x, renderer->target ? rect->y : (h-rect->y)-rect->h,
+ rect->w, rect->h, format, type, temp_pixels);
+
+ if (GL_CheckError("glReadPixels()", renderer) < 0) {
+ SDL_free(temp_pixels);
+ return -1;
+ }
+
+ /* Flip the rows to be top-down if necessary */
+ if (!renderer->target) {
+ length = rect->w * SDL_BYTESPERPIXEL(temp_format);
+ src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
+ dst = (Uint8*)temp_pixels;
+ tmp = SDL_stack_alloc(Uint8, length);
+ rows = rect->h / 2;
+ while (rows--) {
+ SDL_memcpy(tmp, dst, length);
+ SDL_memcpy(dst, src, length);
+ SDL_memcpy(src, tmp, length);
+ dst += temp_pitch;
+ src -= temp_pitch;
+ }
+ SDL_stack_free(tmp);
+ }
+
+ status = SDL_ConvertPixels(rect->w, rect->h,
+ temp_format, temp_pixels, temp_pitch,
+ pixel_format, pixels, pitch);
+ SDL_free(temp_pixels);
+
+ return status;
+}
+
+static void
+GL_RenderPresent(SDL_Renderer * renderer)
+{
+ GL_ActivateRenderer(renderer);
+
+ SDL_GL_SwapWindow(renderer->window);
+}
+
+static void
+GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
+ GL_TextureData *data = (GL_TextureData *) texture->driverdata;
+
+ GL_ActivateRenderer(renderer);
+
+ if (!data) {
+ return;
+ }
+ if (data->texture) {
+ renderdata->glDeleteTextures(1, &data->texture);
+ }
+ if (data->yuv) {
+ renderdata->glDeleteTextures(1, &data->utexture);
+ renderdata->glDeleteTextures(1, &data->vtexture);
+ }
+ SDL_free(data->pixels);
+ SDL_free(data);
+ texture->driverdata = NULL;
+}
+
+static void
+GL_DestroyRenderer(SDL_Renderer * renderer)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+
+ if (data) {
+ if (data->context != NULL) {
+ /* make sure we delete the right resources! */
+ GL_ActivateRenderer(renderer);
+ }
+
+ GL_ClearErrors(renderer);
+ if (data->GL_ARB_debug_output_supported) {
+ PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARBFunc = (PFNGLDEBUGMESSAGECALLBACKARBPROC) SDL_GL_GetProcAddress("glDebugMessageCallbackARB");
+
+ /* Uh oh, we don't have a safe way of removing ourselves from the callback chain, if it changed after we set our callback. */
+ /* For now, just always replace the callback with the original one */
+ glDebugMessageCallbackARBFunc(data->next_error_callback, data->next_error_userparam);
+ }
+ if (data->shaders) {
+ GL_DestroyShaderContext(data->shaders);
+ }
+ if (data->context) {
+ while (data->framebuffers) {
+ GL_FBOList *nextnode = data->framebuffers->next;
+ /* delete the framebuffer object */
+ data->glDeleteFramebuffersEXT(1, &data->framebuffers->FBO);
+ GL_CheckError("", renderer);
+ SDL_free(data->framebuffers);
+ data->framebuffers = nextnode;
+ }
+ SDL_GL_DeleteContext(data->context);
+ }
+ SDL_free(data);
+ }
+ SDL_free(renderer);
+}
+
+static int
+GL_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+ GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
+ GL_ActivateRenderer(renderer);
+
+ data->glEnable(texturedata->type);
+ if (texturedata->yuv) {
+ data->glActiveTextureARB(GL_TEXTURE2_ARB);
+ data->glBindTexture(texturedata->type, texturedata->vtexture);
+
+ data->glActiveTextureARB(GL_TEXTURE1_ARB);
+ data->glBindTexture(texturedata->type, texturedata->utexture);
+
+ data->glActiveTextureARB(GL_TEXTURE0_ARB);
+ }
+ data->glBindTexture(texturedata->type, texturedata->texture);
+
+ if(texw) *texw = (float)texturedata->texw;
+ if(texh) *texh = (float)texturedata->texh;
+
+ return 0;
+}
+
+static int
+GL_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture)
+{
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+ GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
+ GL_ActivateRenderer(renderer);
+
+ if (texturedata->yuv) {
+ data->glActiveTextureARB(GL_TEXTURE2_ARB);
+ data->glDisable(texturedata->type);
+
+ data->glActiveTextureARB(GL_TEXTURE1_ARB);
+ data->glDisable(texturedata->type);
+
+ data->glActiveTextureARB(GL_TEXTURE0_ARB);
+ }
+
+ data->glDisable(texturedata->type);
+
+ return 0;
+}
+
+#endif /* SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/opengl/SDL_shaders_gl.c b/src/3rdparty/SDL2/src/render/opengl/SDL_shaders_gl.c
new file mode 100644
index 0000000..251b54d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/opengl/SDL_shaders_gl.c
@@ -0,0 +1,524 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED
+
+#include "SDL_stdinc.h"
+#include "SDL_log.h"
+#include "SDL_opengl.h"
+#include "SDL_video.h"
+#include "SDL_shaders_gl.h"
+
+/* OpenGL shader implementation */
+
+/* #define DEBUG_SHADERS */
+
+typedef struct
+{
+ GLhandleARB program;
+ GLhandleARB vert_shader;
+ GLhandleARB frag_shader;
+} GL_ShaderData;
+
+struct GL_ShaderContext
+{
+ GLenum (*glGetError)(void);
+
+ PFNGLATTACHOBJECTARBPROC glAttachObjectARB;
+ PFNGLCOMPILESHADERARBPROC glCompileShaderARB;
+ PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB;
+ PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB;
+ PFNGLDELETEOBJECTARBPROC glDeleteObjectARB;
+ PFNGLGETINFOLOGARBPROC glGetInfoLogARB;
+ PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
+ PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB;
+ PFNGLLINKPROGRAMARBPROC glLinkProgramARB;
+ PFNGLSHADERSOURCEARBPROC glShaderSourceARB;
+ PFNGLUNIFORM1IARBPROC glUniform1iARB;
+ PFNGLUNIFORM1FARBPROC glUniform1fARB;
+ PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;
+
+ SDL_bool GL_ARB_texture_rectangle_supported;
+
+ GL_ShaderData shaders[NUM_SHADERS];
+};
+
+#define COLOR_VERTEX_SHADER \
+"varying vec4 v_color;\n" \
+"\n" \
+"void main()\n" \
+"{\n" \
+" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" \
+" v_color = gl_Color;\n" \
+"}" \
+
+#define TEXTURE_VERTEX_SHADER \
+"varying vec4 v_color;\n" \
+"varying vec2 v_texCoord;\n" \
+"\n" \
+"void main()\n" \
+"{\n" \
+" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" \
+" v_color = gl_Color;\n" \
+" v_texCoord = vec2(gl_MultiTexCoord0);\n" \
+"}" \
+
+#define JPEG_SHADER_CONSTANTS \
+"// YUV offset \n" \
+"const vec3 offset = vec3(0, -0.501960814, -0.501960814);\n" \
+"\n" \
+"// RGB coefficients \n" \
+"const vec3 Rcoeff = vec3(1, 0.000, 1.402);\n" \
+"const vec3 Gcoeff = vec3(1, -0.3441, -0.7141);\n" \
+"const vec3 Bcoeff = vec3(1, 1.772, 0.000);\n" \
+
+#define BT601_SHADER_CONSTANTS \
+"// YUV offset \n" \
+"const vec3 offset = vec3(-0.0627451017, -0.501960814, -0.501960814);\n" \
+"\n" \
+"// RGB coefficients \n" \
+"const vec3 Rcoeff = vec3(1.1644, 0.000, 1.596);\n" \
+"const vec3 Gcoeff = vec3(1.1644, -0.3918, -0.813);\n" \
+"const vec3 Bcoeff = vec3(1.1644, 2.0172, 0.000);\n" \
+
+#define BT709_SHADER_CONSTANTS \
+"// YUV offset \n" \
+"const vec3 offset = vec3(-0.0627451017, -0.501960814, -0.501960814);\n" \
+"\n" \
+"// RGB coefficients \n" \
+"const vec3 Rcoeff = vec3(1.1644, 0.000, 1.7927);\n" \
+"const vec3 Gcoeff = vec3(1.1644, -0.2132, -0.5329);\n" \
+"const vec3 Bcoeff = vec3(1.1644, 2.1124, 0.000);\n" \
+
+#define YUV_SHADER_PROLOGUE \
+"varying vec4 v_color;\n" \
+"varying vec2 v_texCoord;\n" \
+"uniform sampler2D tex0; // Y \n" \
+"uniform sampler2D tex1; // U \n" \
+"uniform sampler2D tex2; // V \n" \
+"\n" \
+
+#define YUV_SHADER_BODY \
+"\n" \
+"void main()\n" \
+"{\n" \
+" vec2 tcoord;\n" \
+" vec3 yuv, rgb;\n" \
+"\n" \
+" // Get the Y value \n" \
+" tcoord = v_texCoord;\n" \
+" yuv.x = texture2D(tex0, tcoord).r;\n" \
+"\n" \
+" // Get the U and V values \n" \
+" tcoord *= UVCoordScale;\n" \
+" yuv.y = texture2D(tex1, tcoord).r;\n" \
+" yuv.z = texture2D(tex2, tcoord).r;\n" \
+"\n" \
+" // Do the color transform \n" \
+" yuv += offset;\n" \
+" rgb.r = dot(yuv, Rcoeff);\n" \
+" rgb.g = dot(yuv, Gcoeff);\n" \
+" rgb.b = dot(yuv, Bcoeff);\n" \
+"\n" \
+" // That was easy. :) \n" \
+" gl_FragColor = vec4(rgb, 1.0) * v_color;\n" \
+"}" \
+
+#define NV12_SHADER_PROLOGUE \
+"varying vec4 v_color;\n" \
+"varying vec2 v_texCoord;\n" \
+"uniform sampler2D tex0; // Y \n" \
+"uniform sampler2D tex1; // U/V \n" \
+"\n" \
+
+#define NV12_SHADER_BODY \
+"\n" \
+"void main()\n" \
+"{\n" \
+" vec2 tcoord;\n" \
+" vec3 yuv, rgb;\n" \
+"\n" \
+" // Get the Y value \n" \
+" tcoord = v_texCoord;\n" \
+" yuv.x = texture2D(tex0, tcoord).r;\n" \
+"\n" \
+" // Get the U and V values \n" \
+" tcoord *= UVCoordScale;\n" \
+" yuv.yz = texture2D(tex1, tcoord).ra;\n" \
+"\n" \
+" // Do the color transform \n" \
+" yuv += offset;\n" \
+" rgb.r = dot(yuv, Rcoeff);\n" \
+" rgb.g = dot(yuv, Gcoeff);\n" \
+" rgb.b = dot(yuv, Bcoeff);\n" \
+"\n" \
+" // That was easy. :) \n" \
+" gl_FragColor = vec4(rgb, 1.0) * v_color;\n" \
+"}" \
+
+#define NV21_SHADER_PROLOGUE \
+"varying vec4 v_color;\n" \
+"varying vec2 v_texCoord;\n" \
+"uniform sampler2D tex0; // Y \n" \
+"uniform sampler2D tex1; // U/V \n" \
+"\n" \
+
+#define NV21_SHADER_BODY \
+"\n" \
+"void main()\n" \
+"{\n" \
+" vec2 tcoord;\n" \
+" vec3 yuv, rgb;\n" \
+"\n" \
+" // Get the Y value \n" \
+" tcoord = v_texCoord;\n" \
+" yuv.x = texture2D(tex0, tcoord).r;\n" \
+"\n" \
+" // Get the U and V values \n" \
+" tcoord *= UVCoordScale;\n" \
+" yuv.yz = texture2D(tex1, tcoord).ar;\n" \
+"\n" \
+" // Do the color transform \n" \
+" yuv += offset;\n" \
+" rgb.r = dot(yuv, Rcoeff);\n" \
+" rgb.g = dot(yuv, Gcoeff);\n" \
+" rgb.b = dot(yuv, Bcoeff);\n" \
+"\n" \
+" // That was easy. :) \n" \
+" gl_FragColor = vec4(rgb, 1.0) * v_color;\n" \
+"}" \
+
+/*
+ * NOTE: Always use sampler2D, etc here. We'll #define them to the
+ * texture_rectangle versions if we choose to use that extension.
+ */
+static const char *shader_source[NUM_SHADERS][2] =
+{
+ /* SHADER_NONE */
+ { NULL, NULL },
+
+ /* SHADER_SOLID */
+ {
+ /* vertex shader */
+ COLOR_VERTEX_SHADER,
+ /* fragment shader */
+"varying vec4 v_color;\n"
+"\n"
+"void main()\n"
+"{\n"
+" gl_FragColor = v_color;\n"
+"}"
+ },
+
+ /* SHADER_RGB */
+ {
+ /* vertex shader */
+ TEXTURE_VERTEX_SHADER,
+ /* fragment shader */
+"varying vec4 v_color;\n"
+"varying vec2 v_texCoord;\n"
+"uniform sampler2D tex0;\n"
+"\n"
+"void main()\n"
+"{\n"
+" gl_FragColor = texture2D(tex0, v_texCoord) * v_color;\n"
+"}"
+ },
+
+ /* SHADER_YUV_JPEG */
+ {
+ /* vertex shader */
+ TEXTURE_VERTEX_SHADER,
+ /* fragment shader */
+ YUV_SHADER_PROLOGUE
+ JPEG_SHADER_CONSTANTS
+ YUV_SHADER_BODY
+ },
+ /* SHADER_YUV_BT601 */
+ {
+ /* vertex shader */
+ TEXTURE_VERTEX_SHADER,
+ /* fragment shader */
+ YUV_SHADER_PROLOGUE
+ BT601_SHADER_CONSTANTS
+ YUV_SHADER_BODY
+ },
+ /* SHADER_YUV_BT709 */
+ {
+ /* vertex shader */
+ TEXTURE_VERTEX_SHADER,
+ /* fragment shader */
+ YUV_SHADER_PROLOGUE
+ BT709_SHADER_CONSTANTS
+ YUV_SHADER_BODY
+ },
+ /* SHADER_NV12_JPEG */
+ {
+ /* vertex shader */
+ TEXTURE_VERTEX_SHADER,
+ /* fragment shader */
+ NV12_SHADER_PROLOGUE
+ JPEG_SHADER_CONSTANTS
+ NV12_SHADER_BODY
+ },
+ /* SHADER_NV12_BT601 */
+ {
+ /* vertex shader */
+ TEXTURE_VERTEX_SHADER,
+ /* fragment shader */
+ NV12_SHADER_PROLOGUE
+ BT601_SHADER_CONSTANTS
+ NV12_SHADER_BODY
+ },
+ /* SHADER_NV12_BT709 */
+ {
+ /* vertex shader */
+ TEXTURE_VERTEX_SHADER,
+ /* fragment shader */
+ NV12_SHADER_PROLOGUE
+ BT709_SHADER_CONSTANTS
+ NV12_SHADER_BODY
+ },
+ /* SHADER_NV21_JPEG */
+ {
+ /* vertex shader */
+ TEXTURE_VERTEX_SHADER,
+ /* fragment shader */
+ NV21_SHADER_PROLOGUE
+ JPEG_SHADER_CONSTANTS
+ NV21_SHADER_BODY
+ },
+ /* SHADER_NV21_BT601 */
+ {
+ /* vertex shader */
+ TEXTURE_VERTEX_SHADER,
+ /* fragment shader */
+ NV21_SHADER_PROLOGUE
+ BT601_SHADER_CONSTANTS
+ NV21_SHADER_BODY
+ },
+ /* SHADER_NV21_BT709 */
+ {
+ /* vertex shader */
+ TEXTURE_VERTEX_SHADER,
+ /* fragment shader */
+ NV21_SHADER_PROLOGUE
+ BT709_SHADER_CONSTANTS
+ NV21_SHADER_BODY
+ },
+};
+
+static SDL_bool
+CompileShader(GL_ShaderContext *ctx, GLhandleARB shader, const char *defines, const char *source)
+{
+ GLint status;
+ const char *sources[2];
+
+ sources[0] = defines;
+ sources[1] = source;
+
+ ctx->glShaderSourceARB(shader, SDL_arraysize(sources), sources, NULL);
+ ctx->glCompileShaderARB(shader);
+ ctx->glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
+ if (status == 0) {
+ GLint length;
+ char *info;
+
+ ctx->glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
+ info = SDL_stack_alloc(char, length+1);
+ ctx->glGetInfoLogARB(shader, length, NULL, info);
+ SDL_LogError(SDL_LOG_CATEGORY_RENDER,
+ "Failed to compile shader:\n%s%s\n%s", defines, source, info);
+#ifdef DEBUG_SHADERS
+ fprintf(stderr,
+ "Failed to compile shader:\n%s%s\n%s", defines, source, info);
+#endif
+ SDL_stack_free(info);
+
+ return SDL_FALSE;
+ } else {
+ return SDL_TRUE;
+ }
+}
+
+static SDL_bool
+CompileShaderProgram(GL_ShaderContext *ctx, int index, GL_ShaderData *data)
+{
+ const int num_tmus_bound = 4;
+ const char *vert_defines = "";
+ const char *frag_defines = "";
+ int i;
+ GLint location;
+
+ if (index == SHADER_NONE) {
+ return SDL_TRUE;
+ }
+
+ ctx->glGetError();
+
+ /* Make sure we use the correct sampler type for our texture type */
+ if (ctx->GL_ARB_texture_rectangle_supported) {
+ frag_defines =
+"#define sampler2D sampler2DRect\n"
+"#define texture2D texture2DRect\n"
+"#define UVCoordScale 0.5\n";
+ } else {
+ frag_defines =
+"#define UVCoordScale 1.0\n";
+ }
+
+ /* Create one program object to rule them all */
+ data->program = ctx->glCreateProgramObjectARB();
+
+ /* Create the vertex shader */
+ data->vert_shader = ctx->glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
+ if (!CompileShader(ctx, data->vert_shader, vert_defines, shader_source[index][0])) {
+ return SDL_FALSE;
+ }
+
+ /* Create the fragment shader */
+ data->frag_shader = ctx->glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
+ if (!CompileShader(ctx, data->frag_shader, frag_defines, shader_source[index][1])) {
+ return SDL_FALSE;
+ }
+
+ /* ... and in the darkness bind them */
+ ctx->glAttachObjectARB(data->program, data->vert_shader);
+ ctx->glAttachObjectARB(data->program, data->frag_shader);
+ ctx->glLinkProgramARB(data->program);
+
+ /* Set up some uniform variables */
+ ctx->glUseProgramObjectARB(data->program);
+ for (i = 0; i < num_tmus_bound; ++i) {
+ char tex_name[10];
+ SDL_snprintf(tex_name, SDL_arraysize(tex_name), "tex%d", i);
+ location = ctx->glGetUniformLocationARB(data->program, tex_name);
+ if (location >= 0) {
+ ctx->glUniform1iARB(location, i);
+ }
+ }
+ ctx->glUseProgramObjectARB(0);
+
+ return (ctx->glGetError() == GL_NO_ERROR);
+}
+
+static void
+DestroyShaderProgram(GL_ShaderContext *ctx, GL_ShaderData *data)
+{
+ ctx->glDeleteObjectARB(data->vert_shader);
+ ctx->glDeleteObjectARB(data->frag_shader);
+ ctx->glDeleteObjectARB(data->program);
+}
+
+GL_ShaderContext *
+GL_CreateShaderContext(void)
+{
+ GL_ShaderContext *ctx;
+ SDL_bool shaders_supported;
+ int i;
+
+ ctx = (GL_ShaderContext *)SDL_calloc(1, sizeof(*ctx));
+ if (!ctx) {
+ return NULL;
+ }
+
+ if (!SDL_GL_ExtensionSupported("GL_ARB_texture_non_power_of_two") &&
+ (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle") ||
+ SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle"))) {
+ ctx->GL_ARB_texture_rectangle_supported = SDL_TRUE;
+ }
+
+ /* Check for shader support */
+ shaders_supported = SDL_FALSE;
+ if (SDL_GL_ExtensionSupported("GL_ARB_shader_objects") &&
+ SDL_GL_ExtensionSupported("GL_ARB_shading_language_100") &&
+ SDL_GL_ExtensionSupported("GL_ARB_vertex_shader") &&
+ SDL_GL_ExtensionSupported("GL_ARB_fragment_shader")) {
+ ctx->glGetError = (GLenum (*)(void)) SDL_GL_GetProcAddress("glGetError");
+ ctx->glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) SDL_GL_GetProcAddress("glAttachObjectARB");
+ ctx->glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) SDL_GL_GetProcAddress("glCompileShaderARB");
+ ctx->glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glCreateProgramObjectARB");
+ ctx->glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) SDL_GL_GetProcAddress("glCreateShaderObjectARB");
+ ctx->glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) SDL_GL_GetProcAddress("glDeleteObjectARB");
+ ctx->glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC) SDL_GL_GetProcAddress("glGetInfoLogARB");
+ ctx->glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) SDL_GL_GetProcAddress("glGetObjectParameterivARB");
+ ctx->glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) SDL_GL_GetProcAddress("glGetUniformLocationARB");
+ ctx->glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) SDL_GL_GetProcAddress("glLinkProgramARB");
+ ctx->glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) SDL_GL_GetProcAddress("glShaderSourceARB");
+ ctx->glUniform1iARB = (PFNGLUNIFORM1IARBPROC) SDL_GL_GetProcAddress("glUniform1iARB");
+ ctx->glUniform1fARB = (PFNGLUNIFORM1FARBPROC) SDL_GL_GetProcAddress("glUniform1fARB");
+ ctx->glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glUseProgramObjectARB");
+ if (ctx->glGetError &&
+ ctx->glAttachObjectARB &&
+ ctx->glCompileShaderARB &&
+ ctx->glCreateProgramObjectARB &&
+ ctx->glCreateShaderObjectARB &&
+ ctx->glDeleteObjectARB &&
+ ctx->glGetInfoLogARB &&
+ ctx->glGetObjectParameterivARB &&
+ ctx->glGetUniformLocationARB &&
+ ctx->glLinkProgramARB &&
+ ctx->glShaderSourceARB &&
+ ctx->glUniform1iARB &&
+ ctx->glUniform1fARB &&
+ ctx->glUseProgramObjectARB) {
+ shaders_supported = SDL_TRUE;
+ }
+ }
+
+ if (!shaders_supported) {
+ SDL_free(ctx);
+ return NULL;
+ }
+
+ /* Compile all the shaders */
+ for (i = 0; i < NUM_SHADERS; ++i) {
+ if (!CompileShaderProgram(ctx, i, &ctx->shaders[i])) {
+ GL_DestroyShaderContext(ctx);
+ return NULL;
+ }
+ }
+
+ /* We're done! */
+ return ctx;
+}
+
+void
+GL_SelectShader(GL_ShaderContext *ctx, GL_Shader shader)
+{
+ ctx->glUseProgramObjectARB(ctx->shaders[shader].program);
+}
+
+void
+GL_DestroyShaderContext(GL_ShaderContext *ctx)
+{
+ int i;
+
+ for (i = 0; i < NUM_SHADERS; ++i) {
+ DestroyShaderProgram(ctx, &ctx->shaders[i]);
+ }
+ SDL_free(ctx);
+}
+
+#endif /* SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/opengl/SDL_shaders_gl.h b/src/3rdparty/SDL2/src/render/opengl/SDL_shaders_gl.h
new file mode 100644
index 0000000..9805c59
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/opengl/SDL_shaders_gl.h
@@ -0,0 +1,47 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+/* OpenGL shader implementation */
+
+typedef enum {
+ SHADER_NONE,
+ SHADER_SOLID,
+ SHADER_RGB,
+ SHADER_YUV_JPEG,
+ SHADER_YUV_BT601,
+ SHADER_YUV_BT709,
+ SHADER_NV12_JPEG,
+ SHADER_NV12_BT601,
+ SHADER_NV12_BT709,
+ SHADER_NV21_JPEG,
+ SHADER_NV21_BT601,
+ SHADER_NV21_BT709,
+ NUM_SHADERS
+} GL_Shader;
+
+typedef struct GL_ShaderContext GL_ShaderContext;
+
+extern GL_ShaderContext * GL_CreateShaderContext(void);
+extern void GL_SelectShader(GL_ShaderContext *ctx, GL_Shader shader);
+extern void GL_DestroyShaderContext(GL_ShaderContext *ctx);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/opengles/SDL_glesfuncs.h b/src/3rdparty/SDL2/src/render/opengles/SDL_glesfuncs.h
new file mode 100644
index 0000000..e00982b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/opengles/SDL_glesfuncs.h
@@ -0,0 +1,65 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+SDL_PROC(void, glBindTexture, (GLenum, GLuint))
+SDL_PROC(void, glBlendFunc, (GLenum, GLenum))
+SDL_PROC_OES(void, glBlendEquationOES, (GLenum))
+SDL_PROC_OES(void, glBlendEquationSeparateOES, (GLenum, GLenum))
+SDL_PROC_OES(void, glBlendFuncSeparateOES, (GLenum, GLenum, GLenum, GLenum))
+SDL_PROC(void, glClear, (GLbitfield))
+SDL_PROC(void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf))
+SDL_PROC(void, glColor4f, (GLfloat, GLfloat, GLfloat, GLfloat))
+SDL_PROC(void, glDeleteTextures, (GLsizei, const GLuint *))
+SDL_PROC(void, glDisable, (GLenum))
+SDL_PROC(void, glDisableClientState, (GLenum array))
+SDL_PROC(void, glDrawArrays, (GLenum, GLint, GLsizei))
+SDL_PROC_OES(void, glDrawTexfOES, (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat))
+SDL_PROC(void, glEnable, (GLenum))
+SDL_PROC(void, glEnableClientState, (GLenum))
+SDL_PROC(void, glFinish, (void))
+SDL_PROC_OES(void, glGenFramebuffersOES, (GLsizei, GLuint *))
+SDL_PROC(void, glGenTextures, (GLsizei, GLuint *))
+SDL_PROC(GLenum, glGetError, (void))
+SDL_PROC(void, glGetIntegerv, (GLenum, GLint *))
+SDL_PROC(void, glLoadIdentity, (void))
+SDL_PROC(void, glMatrixMode, (GLenum))
+SDL_PROC(void, glOrthof, (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat))
+SDL_PROC(void, glPixelStorei, (GLenum, GLint))
+SDL_PROC(void, glReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*))
+SDL_PROC(void, glScissor, (GLint, GLint, GLsizei, GLsizei))
+SDL_PROC(void, glTexCoordPointer, (GLint, GLenum, GLsizei, const GLvoid *))
+SDL_PROC(void, glTexEnvf, (GLenum, GLenum, GLfloat))
+SDL_PROC(void, glTexImage2D, (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *))
+SDL_PROC(void, glTexParameteri, (GLenum, GLenum, GLint))
+SDL_PROC(void, glTexParameteriv, (GLenum, GLenum, const GLint *))
+SDL_PROC(void, glTexSubImage2D, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *))
+SDL_PROC(void, glVertexPointer, (GLint, GLenum, GLsizei, const GLvoid *))
+SDL_PROC(void, glViewport, (GLint, GLint, GLsizei, GLsizei))
+SDL_PROC_OES(void, glBindFramebufferOES, (GLenum, GLuint))
+SDL_PROC_OES(void, glFramebufferTexture2DOES, (GLenum, GLenum, GLenum, GLuint, GLint))
+SDL_PROC_OES(GLenum, glCheckFramebufferStatusOES, (GLenum))
+SDL_PROC(void, glPushMatrix, (void))
+SDL_PROC(void, glTranslatef, (GLfloat, GLfloat, GLfloat))
+SDL_PROC(void, glRotatef, (GLfloat, GLfloat, GLfloat, GLfloat))
+SDL_PROC(void, glPopMatrix, (void))
+SDL_PROC_OES(void, glDeleteFramebuffersOES, (GLsizei, const GLuint*))
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/opengles/SDL_render_gles.c b/src/3rdparty/SDL2/src/render/opengles/SDL_render_gles.c
new file mode 100644
index 0000000..d6bfca5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/opengles/SDL_render_gles.c
@@ -0,0 +1,1290 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_RENDER_OGL_ES && !SDL_RENDER_DISABLED
+
+#include "SDL_hints.h"
+#include "SDL_opengles.h"
+#include "../SDL_sysrender.h"
+
+/* To prevent unnecessary window recreation,
+ * these should match the defaults selected in SDL_GL_ResetAttributes
+ */
+
+#define RENDERER_CONTEXT_MAJOR 1
+#define RENDERER_CONTEXT_MINOR 1
+
+#if defined(SDL_VIDEO_DRIVER_PANDORA)
+
+/* Empty function stub to get OpenGL ES 1.x support without */
+/* OpenGL ES extension GL_OES_draw_texture supported */
+GL_API void GL_APIENTRY
+glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height)
+{
+ return;
+}
+
+#endif /* SDL_VIDEO_DRIVER_PANDORA */
+
+/* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */
+
+/* Used to re-create the window with OpenGL ES capability */
+extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
+
+static const float inv255f = 1.0f / 255.0f;
+
+static SDL_Renderer *GLES_CreateRenderer(SDL_Window * window, Uint32 flags);
+static void GLES_WindowEvent(SDL_Renderer * renderer,
+ const SDL_WindowEvent *event);
+static int GLES_GetOutputSize(SDL_Renderer * renderer, int *w, int *h);
+static SDL_bool GLES_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode);
+static int GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+static int GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, const void *pixels,
+ int pitch);
+static int GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, void **pixels, int *pitch);
+static void GLES_UnlockTexture(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static int GLES_SetRenderTarget(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static int GLES_UpdateViewport(SDL_Renderer * renderer);
+static int GLES_UpdateClipRect(SDL_Renderer * renderer);
+static int GLES_RenderClear(SDL_Renderer * renderer);
+static int GLES_RenderDrawPoints(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count);
+static int GLES_RenderDrawLines(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count);
+static int GLES_RenderFillRects(SDL_Renderer * renderer,
+ const SDL_FRect * rects, int count);
+static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect,
+ const SDL_FRect * dstrect);
+static int GLES_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect,
+ const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip);
+static int GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 pixel_format, void * pixels, int pitch);
+static void GLES_RenderPresent(SDL_Renderer * renderer);
+static void GLES_DestroyTexture(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static void GLES_DestroyRenderer(SDL_Renderer * renderer);
+static int GLES_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh);
+static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture);
+
+typedef struct GLES_FBOList GLES_FBOList;
+
+struct GLES_FBOList
+{
+ Uint32 w, h;
+ GLuint FBO;
+ GLES_FBOList *next;
+};
+
+
+SDL_RenderDriver GLES_RenderDriver = {
+ GLES_CreateRenderer,
+ {
+ "opengles",
+ (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC),
+ 1,
+ {SDL_PIXELFORMAT_ABGR8888},
+ 0,
+ 0}
+};
+
+typedef struct
+{
+ SDL_GLContext context;
+ struct {
+ Uint32 color;
+ SDL_BlendMode blendMode;
+ SDL_bool tex_coords;
+ } current;
+
+#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
+#define SDL_PROC_OES SDL_PROC
+#include "SDL_glesfuncs.h"
+#undef SDL_PROC
+#undef SDL_PROC_OES
+ SDL_bool GL_OES_framebuffer_object_supported;
+ GLES_FBOList *framebuffers;
+ GLuint window_framebuffer;
+
+ SDL_bool GL_OES_blend_func_separate_supported;
+ SDL_bool GL_OES_blend_equation_separate_supported;
+ SDL_bool GL_OES_blend_subtract_supported;
+} GLES_RenderData;
+
+typedef struct
+{
+ GLuint texture;
+ GLenum type;
+ GLfloat texw;
+ GLfloat texh;
+ GLenum format;
+ GLenum formattype;
+ void *pixels;
+ int pitch;
+ GLES_FBOList *fbo;
+} GLES_TextureData;
+
+static int
+GLES_SetError(const char *prefix, GLenum result)
+{
+ const char *error;
+
+ switch (result) {
+ case GL_NO_ERROR:
+ error = "GL_NO_ERROR";
+ break;
+ case GL_INVALID_ENUM:
+ error = "GL_INVALID_ENUM";
+ break;
+ case GL_INVALID_VALUE:
+ error = "GL_INVALID_VALUE";
+ break;
+ case GL_INVALID_OPERATION:
+ error = "GL_INVALID_OPERATION";
+ break;
+ case GL_STACK_OVERFLOW:
+ error = "GL_STACK_OVERFLOW";
+ break;
+ case GL_STACK_UNDERFLOW:
+ error = "GL_STACK_UNDERFLOW";
+ break;
+ case GL_OUT_OF_MEMORY:
+ error = "GL_OUT_OF_MEMORY";
+ break;
+ default:
+ error = "UNKNOWN";
+ break;
+ }
+ return SDL_SetError("%s: %s", prefix, error);
+}
+
+static int GLES_LoadFunctions(GLES_RenderData * data)
+{
+#if SDL_VIDEO_DRIVER_UIKIT
+#define __SDL_NOGETPROCADDR__
+#elif SDL_VIDEO_DRIVER_ANDROID
+#define __SDL_NOGETPROCADDR__
+#elif SDL_VIDEO_DRIVER_PANDORA
+#define __SDL_NOGETPROCADDR__
+#endif
+
+#ifdef __SDL_NOGETPROCADDR__
+#define SDL_PROC(ret,func,params) data->func=func;
+#define SDL_PROC_OES(ret,func,params) data->func=func;
+#else
+#define SDL_PROC(ret,func,params) \
+ do { \
+ data->func = SDL_GL_GetProcAddress(#func); \
+ if ( ! data->func ) { \
+ return SDL_SetError("Couldn't load GLES function %s: %s", #func, SDL_GetError()); \
+ } \
+ } while ( 0 );
+#define SDL_PROC_OES(ret,func,params) \
+ do { \
+ data->func = SDL_GL_GetProcAddress(#func); \
+ } while ( 0 );
+#endif /* __SDL_NOGETPROCADDR__ */
+
+#include "SDL_glesfuncs.h"
+#undef SDL_PROC
+#undef SDL_PROC_OES
+ return 0;
+}
+
+static SDL_GLContext SDL_CurrentContext = NULL;
+
+static GLES_FBOList *
+GLES_GetFBO(GLES_RenderData *data, Uint32 w, Uint32 h)
+{
+ GLES_FBOList *result = data->framebuffers;
+ while ((result) && ((result->w != w) || (result->h != h)) ) {
+ result = result->next;
+ }
+ if (result == NULL) {
+ result = SDL_malloc(sizeof(GLES_FBOList));
+ result->w = w;
+ result->h = h;
+ data->glGenFramebuffersOES(1, &result->FBO);
+ result->next = data->framebuffers;
+ data->framebuffers = result;
+ }
+ return result;
+}
+
+
+static int
+GLES_ActivateRenderer(SDL_Renderer * renderer)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+
+ if (SDL_CurrentContext != data->context) {
+ if (SDL_GL_MakeCurrent(renderer->window, data->context) < 0) {
+ return -1;
+ }
+ SDL_CurrentContext = data->context;
+
+ GLES_UpdateViewport(renderer);
+ }
+ return 0;
+}
+
+/* This is called if we need to invalidate all of the SDL OpenGL state */
+static void
+GLES_ResetState(SDL_Renderer *renderer)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+
+ if (SDL_CurrentContext == data->context) {
+ GLES_UpdateViewport(renderer);
+ } else {
+ GLES_ActivateRenderer(renderer);
+ }
+
+ data->current.color = 0xffffffff;
+ data->current.blendMode = SDL_BLENDMODE_INVALID;
+ data->current.tex_coords = SDL_FALSE;
+
+ data->glDisable(GL_DEPTH_TEST);
+ data->glDisable(GL_CULL_FACE);
+
+ data->glMatrixMode(GL_MODELVIEW);
+ data->glLoadIdentity();
+
+ data->glEnableClientState(GL_VERTEX_ARRAY);
+ data->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+}
+
+SDL_Renderer *
+GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
+{
+
+ SDL_Renderer *renderer;
+ GLES_RenderData *data;
+ GLint value;
+ Uint32 window_flags;
+ int profile_mask = 0, major = 0, minor = 0;
+ SDL_bool changed_window = SDL_FALSE;
+
+ SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask);
+ SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
+ SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
+
+ window_flags = SDL_GetWindowFlags(window);
+ if (!(window_flags & SDL_WINDOW_OPENGL) ||
+ profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
+
+ changed_window = SDL_TRUE;
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
+
+ if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
+ goto error;
+ }
+ }
+
+ renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
+ if (!renderer) {
+ SDL_OutOfMemory();
+ goto error;
+ }
+
+ data = (GLES_RenderData *) SDL_calloc(1, sizeof(*data));
+ if (!data) {
+ GLES_DestroyRenderer(renderer);
+ SDL_OutOfMemory();
+ goto error;
+ }
+
+ renderer->WindowEvent = GLES_WindowEvent;
+ renderer->GetOutputSize = GLES_GetOutputSize;
+ renderer->SupportsBlendMode = GLES_SupportsBlendMode;
+ renderer->CreateTexture = GLES_CreateTexture;
+ renderer->UpdateTexture = GLES_UpdateTexture;
+ renderer->LockTexture = GLES_LockTexture;
+ renderer->UnlockTexture = GLES_UnlockTexture;
+ renderer->SetRenderTarget = GLES_SetRenderTarget;
+ renderer->UpdateViewport = GLES_UpdateViewport;
+ renderer->UpdateClipRect = GLES_UpdateClipRect;
+ renderer->RenderClear = GLES_RenderClear;
+ renderer->RenderDrawPoints = GLES_RenderDrawPoints;
+ renderer->RenderDrawLines = GLES_RenderDrawLines;
+ renderer->RenderFillRects = GLES_RenderFillRects;
+ renderer->RenderCopy = GLES_RenderCopy;
+ renderer->RenderCopyEx = GLES_RenderCopyEx;
+ renderer->RenderReadPixels = GLES_RenderReadPixels;
+ renderer->RenderPresent = GLES_RenderPresent;
+ renderer->DestroyTexture = GLES_DestroyTexture;
+ renderer->DestroyRenderer = GLES_DestroyRenderer;
+ renderer->GL_BindTexture = GLES_BindTexture;
+ renderer->GL_UnbindTexture = GLES_UnbindTexture;
+ renderer->info = GLES_RenderDriver.info;
+ renderer->info.flags = SDL_RENDERER_ACCELERATED;
+ renderer->driverdata = data;
+ renderer->window = window;
+
+ data->context = SDL_GL_CreateContext(window);
+ if (!data->context) {
+ GLES_DestroyRenderer(renderer);
+ goto error;
+ }
+ if (SDL_GL_MakeCurrent(window, data->context) < 0) {
+ GLES_DestroyRenderer(renderer);
+ goto error;
+ }
+
+ if (GLES_LoadFunctions(data) < 0) {
+ GLES_DestroyRenderer(renderer);
+ goto error;
+ }
+
+ if (flags & SDL_RENDERER_PRESENTVSYNC) {
+ SDL_GL_SetSwapInterval(1);
+ } else {
+ SDL_GL_SetSwapInterval(0);
+ }
+ if (SDL_GL_GetSwapInterval() > 0) {
+ renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
+ }
+
+ value = 0;
+ data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
+ renderer->info.max_texture_width = value;
+ value = 0;
+ data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
+ renderer->info.max_texture_height = value;
+
+ /* Android does not report GL_OES_framebuffer_object but the functionality seems to be there anyway */
+ if (SDL_GL_ExtensionSupported("GL_OES_framebuffer_object") || data->glGenFramebuffersOES) {
+ data->GL_OES_framebuffer_object_supported = SDL_TRUE;
+ renderer->info.flags |= SDL_RENDERER_TARGETTEXTURE;
+
+ value = 0;
+ data->glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &value);
+ data->window_framebuffer = (GLuint)value;
+ }
+ data->framebuffers = NULL;
+
+ if (SDL_GL_ExtensionSupported("GL_OES_blend_func_separate")) {
+ data->GL_OES_blend_func_separate_supported = SDL_TRUE;
+ }
+ if (SDL_GL_ExtensionSupported("GL_OES_blend_equation_separate")) {
+ data->GL_OES_blend_equation_separate_supported = SDL_TRUE;
+ }
+ if (SDL_GL_ExtensionSupported("GL_OES_blend_subtract")) {
+ data->GL_OES_blend_subtract_supported = SDL_TRUE;
+ }
+
+ /* Set up parameters for rendering */
+ GLES_ResetState(renderer);
+
+ return renderer;
+
+error:
+ if (changed_window) {
+ /* Uh oh, better try to put it back... */
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
+ SDL_RecreateWindow(window, window_flags);
+ }
+ return NULL;
+}
+
+static void
+GLES_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+
+ if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED ||
+ event->event == SDL_WINDOWEVENT_SHOWN ||
+ event->event == SDL_WINDOWEVENT_HIDDEN) {
+ /* Rebind the context to the window area and update matrices */
+ SDL_CurrentContext = NULL;
+ }
+
+ if (event->event == SDL_WINDOWEVENT_MINIMIZED) {
+ /* According to Apple documentation, we need to finish drawing NOW! */
+ data->glFinish();
+ }
+}
+
+static int
+GLES_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
+{
+ SDL_GL_GetDrawableSize(renderer->window, w, h);
+ return 0;
+}
+
+static GLenum GetBlendFunc(SDL_BlendFactor factor)
+{
+ switch (factor) {
+ case SDL_BLENDFACTOR_ZERO:
+ return GL_ZERO;
+ case SDL_BLENDFACTOR_ONE:
+ return GL_ONE;
+ case SDL_BLENDFACTOR_SRC_COLOR:
+ return GL_SRC_COLOR;
+ case SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR:
+ return GL_ONE_MINUS_SRC_COLOR;
+ case SDL_BLENDFACTOR_SRC_ALPHA:
+ return GL_SRC_ALPHA;
+ case SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA:
+ return GL_ONE_MINUS_SRC_ALPHA;
+ case SDL_BLENDFACTOR_DST_COLOR:
+ return GL_DST_COLOR;
+ case SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR:
+ return GL_ONE_MINUS_DST_COLOR;
+ case SDL_BLENDFACTOR_DST_ALPHA:
+ return GL_DST_ALPHA;
+ case SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA:
+ return GL_ONE_MINUS_DST_ALPHA;
+ default:
+ return GL_INVALID_ENUM;
+ }
+}
+
+static GLenum GetBlendEquation(SDL_BlendOperation operation)
+{
+ switch (operation) {
+ case SDL_BLENDOPERATION_ADD:
+ return GL_FUNC_ADD_OES;
+ case SDL_BLENDOPERATION_SUBTRACT:
+ return GL_FUNC_SUBTRACT_OES;
+ case SDL_BLENDOPERATION_REV_SUBTRACT:
+ return GL_FUNC_REVERSE_SUBTRACT_OES;
+ default:
+ return GL_INVALID_ENUM;
+ }
+}
+
+static SDL_bool
+GLES_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+ SDL_BlendFactor srcColorFactor = SDL_GetBlendModeSrcColorFactor(blendMode);
+ SDL_BlendFactor srcAlphaFactor = SDL_GetBlendModeSrcAlphaFactor(blendMode);
+ SDL_BlendOperation colorOperation = SDL_GetBlendModeColorOperation(blendMode);
+ SDL_BlendFactor dstColorFactor = SDL_GetBlendModeDstColorFactor(blendMode);
+ SDL_BlendFactor dstAlphaFactor = SDL_GetBlendModeDstAlphaFactor(blendMode);
+ SDL_BlendOperation alphaOperation = SDL_GetBlendModeAlphaOperation(blendMode);
+
+ if (GetBlendFunc(srcColorFactor) == GL_INVALID_ENUM ||
+ GetBlendFunc(srcAlphaFactor) == GL_INVALID_ENUM ||
+ GetBlendEquation(colorOperation) == GL_INVALID_ENUM ||
+ GetBlendFunc(dstColorFactor) == GL_INVALID_ENUM ||
+ GetBlendFunc(dstAlphaFactor) == GL_INVALID_ENUM ||
+ GetBlendEquation(alphaOperation) == GL_INVALID_ENUM) {
+ return SDL_FALSE;
+ }
+ if ((srcColorFactor != srcAlphaFactor || dstColorFactor != dstAlphaFactor) && !data->GL_OES_blend_func_separate_supported) {
+ return SDL_FALSE;
+ }
+ if (colorOperation != alphaOperation && !data->GL_OES_blend_equation_separate_supported) {
+ return SDL_FALSE;
+ }
+ if (colorOperation != SDL_BLENDOPERATION_ADD && !data->GL_OES_blend_subtract_supported) {
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
+}
+
+static SDL_INLINE int
+power_of_2(int input)
+{
+ int value = 1;
+
+ while (value < input) {
+ value <<= 1;
+ }
+ return value;
+}
+
+static GLenum
+GetScaleQuality(void)
+{
+ const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
+
+ if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
+ return GL_NEAREST;
+ } else {
+ return GL_LINEAR;
+ }
+}
+
+static int
+GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
+ GLES_TextureData *data;
+ GLint internalFormat;
+ GLenum format, type;
+ int texture_w, texture_h;
+ GLenum scaleMode;
+ GLenum result;
+
+ GLES_ActivateRenderer(renderer);
+
+ switch (texture->format) {
+ case SDL_PIXELFORMAT_ABGR8888:
+ internalFormat = GL_RGBA;
+ format = GL_RGBA;
+ type = GL_UNSIGNED_BYTE;
+ break;
+ default:
+ return SDL_SetError("Texture format not supported");
+ }
+
+ data = (GLES_TextureData *) SDL_calloc(1, sizeof(*data));
+ if (!data) {
+ return SDL_OutOfMemory();
+ }
+
+ if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
+ data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
+ data->pixels = SDL_calloc(1, texture->h * data->pitch);
+ if (!data->pixels) {
+ SDL_free(data);
+ return SDL_OutOfMemory();
+ }
+ }
+
+
+ if (texture->access == SDL_TEXTUREACCESS_TARGET) {
+ if (!renderdata->GL_OES_framebuffer_object_supported) {
+ SDL_free(data);
+ return SDL_SetError("GL_OES_framebuffer_object not supported");
+ }
+ data->fbo = GLES_GetFBO(renderer->driverdata, texture->w, texture->h);
+ } else {
+ data->fbo = NULL;
+ }
+
+
+ renderdata->glGetError();
+ renderdata->glEnable(GL_TEXTURE_2D);
+ renderdata->glGenTextures(1, &data->texture);
+ result = renderdata->glGetError();
+ if (result != GL_NO_ERROR) {
+ SDL_free(data);
+ return GLES_SetError("glGenTextures()", result);
+ }
+
+ data->type = GL_TEXTURE_2D;
+ /* no NPOV textures allowed in OpenGL ES (yet) */
+ texture_w = power_of_2(texture->w);
+ texture_h = power_of_2(texture->h);
+ data->texw = (GLfloat) texture->w / texture_w;
+ data->texh = (GLfloat) texture->h / texture_h;
+
+ data->format = format;
+ data->formattype = type;
+ scaleMode = GetScaleQuality();
+ renderdata->glBindTexture(data->type, data->texture);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, scaleMode);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, scaleMode);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+ renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
+ texture_h, 0, format, type, NULL);
+ renderdata->glDisable(GL_TEXTURE_2D);
+
+ result = renderdata->glGetError();
+ if (result != GL_NO_ERROR) {
+ SDL_free(data);
+ return GLES_SetError("glTexImage2D()", result);
+ }
+
+ texture->driverdata = data;
+ return 0;
+}
+
+static int
+GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, const void *pixels, int pitch)
+{
+ GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
+ GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
+ Uint8 *blob = NULL;
+ Uint8 *src;
+ int srcPitch;
+ int y;
+
+ GLES_ActivateRenderer(renderer);
+
+ /* Bail out if we're supposed to update an empty rectangle */
+ if (rect->w <= 0 || rect->h <= 0) {
+ return 0;
+ }
+
+ /* Reformat the texture data into a tightly packed array */
+ srcPitch = rect->w * SDL_BYTESPERPIXEL(texture->format);
+ src = (Uint8 *)pixels;
+ if (pitch != srcPitch) {
+ blob = (Uint8 *)SDL_malloc(srcPitch * rect->h);
+ if (!blob) {
+ return SDL_OutOfMemory();
+ }
+ src = blob;
+ for (y = 0; y < rect->h; ++y) {
+ SDL_memcpy(src, pixels, srcPitch);
+ src += srcPitch;
+ pixels = (Uint8 *)pixels + pitch;
+ }
+ src = blob;
+ }
+
+ /* Create a texture subimage with the supplied data */
+ renderdata->glGetError();
+ renderdata->glEnable(data->type);
+ renderdata->glBindTexture(data->type, data->texture);
+ renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ renderdata->glTexSubImage2D(data->type,
+ 0,
+ rect->x,
+ rect->y,
+ rect->w,
+ rect->h,
+ data->format,
+ data->formattype,
+ src);
+ renderdata->glDisable(data->type);
+ SDL_free(blob);
+
+ if (renderdata->glGetError() != GL_NO_ERROR) {
+ return SDL_SetError("Failed to update texture");
+ }
+ return 0;
+}
+
+static int
+GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, void **pixels, int *pitch)
+{
+ GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
+
+ *pixels =
+ (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
+ rect->x * SDL_BYTESPERPIXEL(texture->format));
+ *pitch = data->pitch;
+ return 0;
+}
+
+static void
+GLES_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
+ SDL_Rect rect;
+
+ /* We do whole texture updates, at least for now */
+ rect.x = 0;
+ rect.y = 0;
+ rect.w = texture->w;
+ rect.h = texture->h;
+ GLES_UpdateTexture(renderer, texture, &rect, data->pixels, data->pitch);
+}
+
+static int
+GLES_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+ GLES_TextureData *texturedata = NULL;
+ GLenum status;
+
+ if (!data->GL_OES_framebuffer_object_supported) {
+ return SDL_SetError("Can't enable render target support in this renderer");
+ }
+
+ if (texture == NULL) {
+ data->glBindFramebufferOES(GL_FRAMEBUFFER_OES, data->window_framebuffer);
+ return 0;
+ }
+
+ texturedata = (GLES_TextureData *) texture->driverdata;
+ data->glBindFramebufferOES(GL_FRAMEBUFFER_OES, texturedata->fbo->FBO);
+ /* TODO: check if texture pixel format allows this operation */
+ data->glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, texturedata->type, texturedata->texture, 0);
+ /* Check FBO status */
+ status = data->glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
+ if (status != GL_FRAMEBUFFER_COMPLETE_OES) {
+ return SDL_SetError("glFramebufferTexture2DOES() failed");
+ }
+ return 0;
+}
+
+static int
+GLES_UpdateViewport(SDL_Renderer * renderer)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+
+ if (SDL_CurrentContext != data->context) {
+ /* We'll update the viewport after we rebind the context */
+ return 0;
+ }
+
+ if (renderer->target) {
+ data->glViewport(renderer->viewport.x, renderer->viewport.y,
+ renderer->viewport.w, renderer->viewport.h);
+ } else {
+ int w, h;
+
+ SDL_GL_GetDrawableSize(renderer->window, &w, &h);
+ data->glViewport(renderer->viewport.x, (h - renderer->viewport.y - renderer->viewport.h),
+ renderer->viewport.w, renderer->viewport.h);
+ }
+
+ data->glMatrixMode(GL_PROJECTION);
+ data->glLoadIdentity();
+ if (renderer->viewport.w && renderer->viewport.h) {
+ if (renderer->target) {
+ data->glOrthof((GLfloat) 0,
+ (GLfloat) renderer->viewport.w,
+ (GLfloat) 0,
+ (GLfloat) renderer->viewport.h,
+ 0.0, 1.0);
+ } else {
+ data->glOrthof((GLfloat) 0,
+ (GLfloat) renderer->viewport.w,
+ (GLfloat) renderer->viewport.h,
+ (GLfloat) 0,
+ 0.0, 1.0);
+ }
+ }
+ data->glMatrixMode(GL_MODELVIEW);
+
+ return 0;
+}
+
+static int
+GLES_UpdateClipRect(SDL_Renderer * renderer)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+
+ if (SDL_CurrentContext != data->context) {
+ /* We'll update the clip rect after we rebind the context */
+ return 0;
+ }
+
+ if (renderer->clipping_enabled) {
+ const SDL_Rect *rect = &renderer->clip_rect;
+ data->glEnable(GL_SCISSOR_TEST);
+ if (renderer->target) {
+ data->glScissor(renderer->viewport.x + rect->x, renderer->viewport.y + rect->y, rect->w, rect->h);
+ } else {
+ int w, h;
+
+ SDL_GL_GetDrawableSize(renderer->window, &w, &h);
+ data->glScissor(renderer->viewport.x + rect->x, h - renderer->viewport.y - rect->y - rect->h, rect->w, rect->h);
+ }
+ } else {
+ data->glDisable(GL_SCISSOR_TEST);
+ }
+ return 0;
+}
+
+static void
+GLES_SetColor(GLES_RenderData * data, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ Uint32 color = ((a << 24) | (r << 16) | (g << 8) | b);
+
+ if (color != data->current.color) {
+ data->glColor4f((GLfloat) r * inv255f,
+ (GLfloat) g * inv255f,
+ (GLfloat) b * inv255f,
+ (GLfloat) a * inv255f);
+ data->current.color = color;
+ }
+}
+
+static void
+GLES_SetBlendMode(GLES_RenderData * data, SDL_BlendMode blendMode)
+{
+ if (blendMode != data->current.blendMode) {
+ if (blendMode == SDL_BLENDMODE_NONE) {
+ data->glDisable(GL_BLEND);
+ } else {
+ data->glEnable(GL_BLEND);
+ if (data->GL_OES_blend_func_separate_supported) {
+ data->glBlendFuncSeparateOES(GetBlendFunc(SDL_GetBlendModeSrcColorFactor(blendMode)),
+ GetBlendFunc(SDL_GetBlendModeDstColorFactor(blendMode)),
+ GetBlendFunc(SDL_GetBlendModeSrcAlphaFactor(blendMode)),
+ GetBlendFunc(SDL_GetBlendModeDstAlphaFactor(blendMode)));
+ } else {
+ data->glBlendFunc(GetBlendFunc(SDL_GetBlendModeSrcColorFactor(blendMode)),
+ GetBlendFunc(SDL_GetBlendModeDstColorFactor(blendMode)));
+ }
+ if (data->GL_OES_blend_equation_separate_supported) {
+ data->glBlendEquationSeparateOES(GetBlendEquation(SDL_GetBlendModeColorOperation(blendMode)),
+ GetBlendEquation(SDL_GetBlendModeAlphaOperation(blendMode)));
+ } else if (data->GL_OES_blend_subtract_supported) {
+ data->glBlendEquationOES(GetBlendEquation(SDL_GetBlendModeColorOperation(blendMode)));
+ }
+ }
+ data->current.blendMode = blendMode;
+ }
+}
+
+static void
+GLES_SetTexCoords(GLES_RenderData * data, SDL_bool enabled)
+{
+ if (enabled != data->current.tex_coords) {
+ if (enabled) {
+ data->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ } else {
+ data->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ }
+ data->current.tex_coords = enabled;
+ }
+}
+
+static void
+GLES_SetDrawingState(SDL_Renderer * renderer)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+
+ GLES_ActivateRenderer(renderer);
+
+ GLES_SetColor(data, (GLfloat) renderer->r,
+ (GLfloat) renderer->g,
+ (GLfloat) renderer->b,
+ (GLfloat) renderer->a);
+
+ GLES_SetBlendMode(data, renderer->blendMode);
+
+ GLES_SetTexCoords(data, SDL_FALSE);
+}
+
+static int
+GLES_RenderClear(SDL_Renderer * renderer)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+
+ GLES_ActivateRenderer(renderer);
+
+ data->glClearColor((GLfloat) renderer->r * inv255f,
+ (GLfloat) renderer->g * inv255f,
+ (GLfloat) renderer->b * inv255f,
+ (GLfloat) renderer->a * inv255f);
+
+ if (renderer->clipping_enabled) {
+ data->glDisable(GL_SCISSOR_TEST);
+ }
+
+ data->glClear(GL_COLOR_BUFFER_BIT);
+
+ if (renderer->clipping_enabled) {
+ data->glEnable(GL_SCISSOR_TEST);
+ }
+
+ return 0;
+}
+
+static int
+GLES_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points,
+ int count)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+ GLfloat *vertices;
+ int idx;
+
+ GLES_SetDrawingState(renderer);
+
+ /* Emit the specified vertices as points */
+ vertices = SDL_stack_alloc(GLfloat, count * 2);
+ for (idx = 0; idx < count; ++idx) {
+ GLfloat x = points[idx].x + 0.5f;
+ GLfloat y = points[idx].y + 0.5f;
+
+ vertices[idx * 2] = x;
+ vertices[(idx * 2) + 1] = y;
+ }
+
+ data->glVertexPointer(2, GL_FLOAT, 0, vertices);
+ data->glDrawArrays(GL_POINTS, 0, count);
+ SDL_stack_free(vertices);
+ return 0;
+}
+
+static int
+GLES_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points,
+ int count)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+ GLfloat *vertices;
+ int idx;
+
+ GLES_SetDrawingState(renderer);
+
+ /* Emit a line strip including the specified vertices */
+ vertices = SDL_stack_alloc(GLfloat, count * 2);
+ for (idx = 0; idx < count; ++idx) {
+ GLfloat x = points[idx].x + 0.5f;
+ GLfloat y = points[idx].y + 0.5f;
+
+ vertices[idx * 2] = x;
+ vertices[(idx * 2) + 1] = y;
+ }
+
+ data->glVertexPointer(2, GL_FLOAT, 0, vertices);
+ if (count > 2 &&
+ points[0].x == points[count-1].x && points[0].y == points[count-1].y) {
+ /* GL_LINE_LOOP takes care of the final segment */
+ --count;
+ data->glDrawArrays(GL_LINE_LOOP, 0, count);
+ } else {
+ data->glDrawArrays(GL_LINE_STRIP, 0, count);
+ /* We need to close the endpoint of the line */
+ data->glDrawArrays(GL_POINTS, count-1, 1);
+ }
+ SDL_stack_free(vertices);
+
+ return 0;
+}
+
+static int
+GLES_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects,
+ int count)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+ int i;
+
+ GLES_SetDrawingState(renderer);
+
+ for (i = 0; i < count; ++i) {
+ const SDL_FRect *rect = &rects[i];
+ GLfloat minx = rect->x;
+ GLfloat maxx = rect->x + rect->w;
+ GLfloat miny = rect->y;
+ GLfloat maxy = rect->y + rect->h;
+ GLfloat vertices[8];
+ vertices[0] = minx;
+ vertices[1] = miny;
+ vertices[2] = maxx;
+ vertices[3] = miny;
+ vertices[4] = minx;
+ vertices[5] = maxy;
+ vertices[6] = maxx;
+ vertices[7] = maxy;
+
+ data->glVertexPointer(2, GL_FLOAT, 0, vertices);
+ data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ }
+
+ return 0;
+}
+
+static int
+GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+ GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
+ GLfloat minx, miny, maxx, maxy;
+ GLfloat minu, maxu, minv, maxv;
+ GLfloat vertices[8];
+ GLfloat texCoords[8];
+
+ GLES_ActivateRenderer(renderer);
+
+ data->glEnable(GL_TEXTURE_2D);
+
+ data->glBindTexture(texturedata->type, texturedata->texture);
+
+ if (texture->modMode) {
+ GLES_SetColor(data, texture->r, texture->g, texture->b, texture->a);
+ } else {
+ GLES_SetColor(data, 255, 255, 255, 255);
+ }
+
+ GLES_SetBlendMode(data, texture->blendMode);
+
+ GLES_SetTexCoords(data, SDL_TRUE);
+
+ minx = dstrect->x;
+ miny = dstrect->y;
+ maxx = dstrect->x + dstrect->w;
+ maxy = dstrect->y + dstrect->h;
+
+ minu = (GLfloat) srcrect->x / texture->w;
+ minu *= texturedata->texw;
+ maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
+ maxu *= texturedata->texw;
+ minv = (GLfloat) srcrect->y / texture->h;
+ minv *= texturedata->texh;
+ maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
+ maxv *= texturedata->texh;
+
+ vertices[0] = minx;
+ vertices[1] = miny;
+ vertices[2] = maxx;
+ vertices[3] = miny;
+ vertices[4] = minx;
+ vertices[5] = maxy;
+ vertices[6] = maxx;
+ vertices[7] = maxy;
+
+ texCoords[0] = minu;
+ texCoords[1] = minv;
+ texCoords[2] = maxu;
+ texCoords[3] = minv;
+ texCoords[4] = minu;
+ texCoords[5] = maxv;
+ texCoords[6] = maxu;
+ texCoords[7] = maxv;
+
+ data->glVertexPointer(2, GL_FLOAT, 0, vertices);
+ data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
+ data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ data->glDisable(GL_TEXTURE_2D);
+
+ return 0;
+}
+
+static int
+GLES_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect,
+ const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
+{
+
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+ GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
+ GLfloat minx, miny, maxx, maxy;
+ GLfloat minu, maxu, minv, maxv;
+ GLfloat centerx, centery;
+ GLfloat vertices[8];
+ GLfloat texCoords[8];
+
+
+ GLES_ActivateRenderer(renderer);
+
+ data->glEnable(GL_TEXTURE_2D);
+
+ data->glBindTexture(texturedata->type, texturedata->texture);
+
+ if (texture->modMode) {
+ GLES_SetColor(data, texture->r, texture->g, texture->b, texture->a);
+ } else {
+ GLES_SetColor(data, 255, 255, 255, 255);
+ }
+
+ GLES_SetBlendMode(data, texture->blendMode);
+
+ GLES_SetTexCoords(data, SDL_TRUE);
+
+ centerx = center->x;
+ centery = center->y;
+
+ /* Rotate and translate */
+ data->glPushMatrix();
+ data->glTranslatef(dstrect->x + centerx, dstrect->y + centery, 0.0f);
+ data->glRotatef((GLfloat)angle, 0.0f, 0.0f, 1.0f);
+
+ if (flip & SDL_FLIP_HORIZONTAL) {
+ minx = dstrect->w - centerx;
+ maxx = -centerx;
+ } else {
+ minx = -centerx;
+ maxx = dstrect->w - centerx;
+ }
+
+ if (flip & SDL_FLIP_VERTICAL) {
+ miny = dstrect->h - centery;
+ maxy = -centery;
+ } else {
+ miny = -centery;
+ maxy = dstrect->h - centery;
+ }
+
+ minu = (GLfloat) srcrect->x / texture->w;
+ minu *= texturedata->texw;
+ maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
+ maxu *= texturedata->texw;
+ minv = (GLfloat) srcrect->y / texture->h;
+ minv *= texturedata->texh;
+ maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
+ maxv *= texturedata->texh;
+
+ vertices[0] = minx;
+ vertices[1] = miny;
+ vertices[2] = maxx;
+ vertices[3] = miny;
+ vertices[4] = minx;
+ vertices[5] = maxy;
+ vertices[6] = maxx;
+ vertices[7] = maxy;
+
+ texCoords[0] = minu;
+ texCoords[1] = minv;
+ texCoords[2] = maxu;
+ texCoords[3] = minv;
+ texCoords[4] = minu;
+ texCoords[5] = maxv;
+ texCoords[6] = maxu;
+ texCoords[7] = maxv;
+ data->glVertexPointer(2, GL_FLOAT, 0, vertices);
+ data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
+ data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ data->glPopMatrix();
+ data->glDisable(GL_TEXTURE_2D);
+
+ return 0;
+}
+
+static int
+GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 pixel_format, void * pixels, int pitch)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+ Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888;
+ void *temp_pixels;
+ int temp_pitch;
+ Uint8 *src, *dst, *tmp;
+ int w, h, length, rows;
+ int status;
+
+ GLES_ActivateRenderer(renderer);
+
+ temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
+ temp_pixels = SDL_malloc(rect->h * temp_pitch);
+ if (!temp_pixels) {
+ return SDL_OutOfMemory();
+ }
+
+ SDL_GetRendererOutputSize(renderer, &w, &h);
+
+ data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
+
+ data->glReadPixels(rect->x, renderer->target ? rect->y : (h-rect->y)-rect->h,
+ rect->w, rect->h, GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels);
+
+ /* Flip the rows to be top-down if necessary */
+ if (!renderer->target) {
+ length = rect->w * SDL_BYTESPERPIXEL(temp_format);
+ src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
+ dst = (Uint8*)temp_pixels;
+ tmp = SDL_stack_alloc(Uint8, length);
+ rows = rect->h / 2;
+ while (rows--) {
+ SDL_memcpy(tmp, dst, length);
+ SDL_memcpy(dst, src, length);
+ SDL_memcpy(src, tmp, length);
+ dst += temp_pitch;
+ src -= temp_pitch;
+ }
+ SDL_stack_free(tmp);
+ }
+
+ status = SDL_ConvertPixels(rect->w, rect->h,
+ temp_format, temp_pixels, temp_pitch,
+ pixel_format, pixels, pitch);
+ SDL_free(temp_pixels);
+
+ return status;
+}
+
+static void
+GLES_RenderPresent(SDL_Renderer * renderer)
+{
+ GLES_ActivateRenderer(renderer);
+
+ SDL_GL_SwapWindow(renderer->window);
+}
+
+static void
+GLES_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
+
+ GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
+
+ GLES_ActivateRenderer(renderer);
+
+ if (!data) {
+ return;
+ }
+ if (data->texture) {
+ renderdata->glDeleteTextures(1, &data->texture);
+ }
+ SDL_free(data->pixels);
+ SDL_free(data);
+ texture->driverdata = NULL;
+}
+
+static void
+GLES_DestroyRenderer(SDL_Renderer * renderer)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+
+ if (data) {
+ if (data->context) {
+ while (data->framebuffers) {
+ GLES_FBOList *nextnode = data->framebuffers->next;
+ data->glDeleteFramebuffersOES(1, &data->framebuffers->FBO);
+ SDL_free(data->framebuffers);
+ data->framebuffers = nextnode;
+ }
+ SDL_GL_DeleteContext(data->context);
+ }
+ SDL_free(data);
+ }
+ SDL_free(renderer);
+}
+
+static int GLES_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+ GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
+ GLES_ActivateRenderer(renderer);
+
+ data->glEnable(GL_TEXTURE_2D);
+ data->glBindTexture(texturedata->type, texturedata->texture);
+
+ if (texw) {
+ *texw = (float)texturedata->texw;
+ }
+ if (texh) {
+ *texh = (float)texturedata->texh;
+ }
+
+ return 0;
+}
+
+static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture)
+{
+ GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
+ GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
+ GLES_ActivateRenderer(renderer);
+ data->glDisable(texturedata->type);
+
+ return 0;
+}
+
+#endif /* SDL_VIDEO_RENDER_OGL_ES && !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/opengles2/SDL_gles2funcs.h b/src/3rdparty/SDL2/src/render/opengles2/SDL_gles2funcs.h
new file mode 100644
index 0000000..b6a1436
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/opengles2/SDL_gles2funcs.h
@@ -0,0 +1,80 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+SDL_PROC(void, glActiveTexture, (GLenum))
+SDL_PROC(void, glAttachShader, (GLuint, GLuint))
+SDL_PROC(void, glBindAttribLocation, (GLuint, GLuint, const char *))
+SDL_PROC(void, glBindTexture, (GLenum, GLuint))
+SDL_PROC(void, glBlendEquationSeparate, (GLenum, GLenum))
+SDL_PROC(void, glBlendFuncSeparate, (GLenum, GLenum, GLenum, GLenum))
+SDL_PROC(void, glClear, (GLbitfield))
+SDL_PROC(void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf))
+SDL_PROC(void, glCompileShader, (GLuint))
+SDL_PROC(GLuint, glCreateProgram, (void))
+SDL_PROC(GLuint, glCreateShader, (GLenum))
+SDL_PROC(void, glDeleteProgram, (GLuint))
+SDL_PROC(void, glDeleteShader, (GLuint))
+SDL_PROC(void, glDeleteTextures, (GLsizei, const GLuint *))
+SDL_PROC(void, glDisable, (GLenum))
+SDL_PROC(void, glDisableVertexAttribArray, (GLuint))
+SDL_PROC(void, glDrawArrays, (GLenum, GLint, GLsizei))
+SDL_PROC(void, glEnable, (GLenum))
+SDL_PROC(void, glEnableVertexAttribArray, (GLuint))
+SDL_PROC(void, glFinish, (void))
+SDL_PROC(void, glGenFramebuffers, (GLsizei, GLuint *))
+SDL_PROC(void, glGenTextures, (GLsizei, GLuint *))
+SDL_PROC(void, glGetBooleanv, (GLenum, GLboolean *))
+SDL_PROC(const GLubyte *, glGetString, (GLenum))
+SDL_PROC(GLenum, glGetError, (void))
+SDL_PROC(void, glGetIntegerv, (GLenum, GLint *))
+SDL_PROC(void, glGetProgramiv, (GLuint, GLenum, GLint *))
+SDL_PROC(void, glGetShaderInfoLog, (GLuint, GLsizei, GLsizei *, char *))
+SDL_PROC(void, glGetShaderiv, (GLuint, GLenum, GLint *))
+SDL_PROC(GLint, glGetUniformLocation, (GLuint, const char *))
+SDL_PROC(void, glLinkProgram, (GLuint))
+SDL_PROC(void, glPixelStorei, (GLenum, GLint))
+SDL_PROC(void, glReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*))
+SDL_PROC(void, glScissor, (GLint, GLint, GLsizei, GLsizei))
+SDL_PROC(void, glShaderBinary, (GLsizei, const GLuint *, GLenum, const void *, GLsizei))
+#if __NACL__ || __ANDROID__
+SDL_PROC(void, glShaderSource, (GLuint, GLsizei, const GLchar **, const GLint *))
+#else
+SDL_PROC(void, glShaderSource, (GLuint, GLsizei, const GLchar* const*, const GLint *))
+#endif
+SDL_PROC(void, glTexImage2D, (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const void *))
+SDL_PROC(void, glTexParameteri, (GLenum, GLenum, GLint))
+SDL_PROC(void, glTexSubImage2D, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *))
+SDL_PROC(void, glUniform1i, (GLint, GLint))
+SDL_PROC(void, glUniform4f, (GLint, GLfloat, GLfloat, GLfloat, GLfloat))
+SDL_PROC(void, glUniformMatrix4fv, (GLint, GLsizei, GLboolean, const GLfloat *))
+SDL_PROC(void, glUseProgram, (GLuint))
+SDL_PROC(void, glVertexAttribPointer, (GLuint, GLint, GLenum, GLboolean, GLsizei, const void *))
+SDL_PROC(void, glViewport, (GLint, GLint, GLsizei, GLsizei))
+SDL_PROC(void, glBindFramebuffer, (GLenum, GLuint))
+SDL_PROC(void, glFramebufferTexture2D, (GLenum, GLenum, GLenum, GLuint, GLint))
+SDL_PROC(GLenum, glCheckFramebufferStatus, (GLenum))
+SDL_PROC(void, glDeleteFramebuffers, (GLsizei, const GLuint *))
+SDL_PROC(GLint, glGetAttribLocation, (GLuint, const GLchar *))
+SDL_PROC(void, glGetProgramInfoLog, (GLuint, GLsizei, GLsizei*, GLchar*))
+SDL_PROC(void, glGenBuffers, (GLsizei, GLuint *))
+SDL_PROC(void, glBindBuffer, (GLenum, GLuint))
+SDL_PROC(void, glBufferData, (GLenum, GLsizeiptr, const GLvoid *, GLenum))
+SDL_PROC(void, glBufferSubData, (GLenum, GLintptr, GLsizeiptr, const GLvoid *))
diff --git a/src/3rdparty/SDL2/src/render/opengles2/SDL_render_gles2.c b/src/3rdparty/SDL2/src/render/opengles2/SDL_render_gles2.c
new file mode 100644
index 0000000..0cd388c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/opengles2/SDL_render_gles2.c
@@ -0,0 +1,2258 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED
+
+#include "SDL_assert.h"
+#include "SDL_hints.h"
+#include "SDL_opengles2.h"
+#include "../SDL_sysrender.h"
+#include "../../video/SDL_blit.h"
+#include "SDL_shaders_gles2.h"
+
+/* !!! FIXME: Emscripten makes these into WebGL calls, and WebGL doesn't offer
+ !!! FIXME: client-side arrays (without an Emscripten compatibility hack,
+ !!! FIXME: at least), but the current VBO code here is dramatically
+ !!! FIXME: slower on actual iOS devices, even though the iOS Simulator
+ !!! FIXME: is okay. Some time after 2.0.4 ships, we should revisit this,
+ !!! FIXME: fix the performance bottleneck, and make everything use VBOs.
+*/
+#ifdef __EMSCRIPTEN__
+#define SDL_GLES2_USE_VBOS 1
+#else
+#define SDL_GLES2_USE_VBOS 0
+#endif
+
+/* To prevent unnecessary window recreation,
+ * these should match the defaults selected in SDL_GL_ResetAttributes
+ */
+#define RENDERER_CONTEXT_MAJOR 2
+#define RENDERER_CONTEXT_MINOR 0
+
+/* Used to re-create the window with OpenGL ES capability */
+extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
+
+/*************************************************************************************************
+ * Bootstrap data *
+ *************************************************************************************************/
+
+static SDL_Renderer *GLES2_CreateRenderer(SDL_Window *window, Uint32 flags);
+
+SDL_RenderDriver GLES2_RenderDriver = {
+ GLES2_CreateRenderer,
+ {
+ "opengles2",
+ (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
+ 4,
+ {
+ SDL_PIXELFORMAT_ARGB8888,
+ SDL_PIXELFORMAT_ABGR8888,
+ SDL_PIXELFORMAT_RGB888,
+ SDL_PIXELFORMAT_BGR888
+ },
+ 0,
+ 0
+ }
+};
+
+/*************************************************************************************************
+ * Context structures *
+ *************************************************************************************************/
+
+typedef struct GLES2_FBOList GLES2_FBOList;
+
+struct GLES2_FBOList
+{
+ Uint32 w, h;
+ GLuint FBO;
+ GLES2_FBOList *next;
+};
+
+typedef struct GLES2_TextureData
+{
+ GLenum texture;
+ GLenum texture_type;
+ GLenum pixel_format;
+ GLenum pixel_type;
+ void *pixel_data;
+ int pitch;
+ /* YUV texture support */
+ SDL_bool yuv;
+ SDL_bool nv12;
+ GLenum texture_v;
+ GLenum texture_u;
+ GLES2_FBOList *fbo;
+} GLES2_TextureData;
+
+typedef struct GLES2_ShaderCacheEntry
+{
+ GLuint id;
+ GLES2_ShaderType type;
+ const GLES2_ShaderInstance *instance;
+ int references;
+ Uint8 modulation_r, modulation_g, modulation_b, modulation_a;
+ struct GLES2_ShaderCacheEntry *prev;
+ struct GLES2_ShaderCacheEntry *next;
+} GLES2_ShaderCacheEntry;
+
+typedef struct GLES2_ShaderCache
+{
+ int count;
+ GLES2_ShaderCacheEntry *head;
+} GLES2_ShaderCache;
+
+typedef struct GLES2_ProgramCacheEntry
+{
+ GLuint id;
+ GLES2_ShaderCacheEntry *vertex_shader;
+ GLES2_ShaderCacheEntry *fragment_shader;
+ GLuint uniform_locations[16];
+ Uint8 color_r, color_g, color_b, color_a;
+ Uint8 modulation_r, modulation_g, modulation_b, modulation_a;
+ GLfloat projection[4][4];
+ struct GLES2_ProgramCacheEntry *prev;
+ struct GLES2_ProgramCacheEntry *next;
+} GLES2_ProgramCacheEntry;
+
+typedef struct GLES2_ProgramCache
+{
+ int count;
+ GLES2_ProgramCacheEntry *head;
+ GLES2_ProgramCacheEntry *tail;
+} GLES2_ProgramCache;
+
+typedef enum
+{
+ GLES2_ATTRIBUTE_POSITION = 0,
+ GLES2_ATTRIBUTE_TEXCOORD = 1,
+ GLES2_ATTRIBUTE_ANGLE = 2,
+ GLES2_ATTRIBUTE_CENTER = 3,
+} GLES2_Attribute;
+
+typedef enum
+{
+ GLES2_UNIFORM_PROJECTION,
+ GLES2_UNIFORM_TEXTURE,
+ GLES2_UNIFORM_MODULATION,
+ GLES2_UNIFORM_COLOR,
+ GLES2_UNIFORM_TEXTURE_U,
+ GLES2_UNIFORM_TEXTURE_V
+} GLES2_Uniform;
+
+typedef enum
+{
+ GLES2_IMAGESOURCE_SOLID,
+ GLES2_IMAGESOURCE_TEXTURE_ABGR,
+ GLES2_IMAGESOURCE_TEXTURE_ARGB,
+ GLES2_IMAGESOURCE_TEXTURE_RGB,
+ GLES2_IMAGESOURCE_TEXTURE_BGR,
+ GLES2_IMAGESOURCE_TEXTURE_YUV,
+ GLES2_IMAGESOURCE_TEXTURE_NV12,
+ GLES2_IMAGESOURCE_TEXTURE_NV21,
+ GLES2_IMAGESOURCE_TEXTURE_EXTERNAL_OES
+} GLES2_ImageSource;
+
+typedef struct GLES2_DriverContext
+{
+ SDL_GLContext *context;
+
+ SDL_bool debug_enabled;
+
+ struct {
+ SDL_BlendMode blendMode;
+ SDL_bool tex_coords;
+ } current;
+
+#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
+#include "SDL_gles2funcs.h"
+#undef SDL_PROC
+ GLES2_FBOList *framebuffers;
+ GLuint window_framebuffer;
+
+ int shader_format_count;
+ GLenum *shader_formats;
+ GLES2_ShaderCache shader_cache;
+ GLES2_ProgramCache program_cache;
+ GLES2_ProgramCacheEntry *current_program;
+ Uint8 clear_r, clear_g, clear_b, clear_a;
+
+#if SDL_GLES2_USE_VBOS
+ GLuint vertex_buffers[4];
+ GLsizeiptr vertex_buffer_size[4];
+#endif
+} GLES2_DriverContext;
+
+#define GLES2_MAX_CACHED_PROGRAMS 8
+
+
+SDL_FORCE_INLINE const char*
+GL_TranslateError (GLenum error)
+{
+#define GL_ERROR_TRANSLATE(e) case e: return #e;
+ switch (error) {
+ GL_ERROR_TRANSLATE(GL_INVALID_ENUM)
+ GL_ERROR_TRANSLATE(GL_INVALID_VALUE)
+ GL_ERROR_TRANSLATE(GL_INVALID_OPERATION)
+ GL_ERROR_TRANSLATE(GL_OUT_OF_MEMORY)
+ GL_ERROR_TRANSLATE(GL_NO_ERROR)
+ default:
+ return "UNKNOWN";
+}
+#undef GL_ERROR_TRANSLATE
+}
+
+SDL_FORCE_INLINE void
+GL_ClearErrors(SDL_Renderer *renderer)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *) renderer->driverdata;
+
+ if (!data->debug_enabled) {
+ return;
+ }
+ while (data->glGetError() != GL_NO_ERROR) {
+ continue;
+ }
+}
+
+SDL_FORCE_INLINE int
+GL_CheckAllErrors (const char *prefix, SDL_Renderer *renderer, const char *file, int line, const char *function)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *) renderer->driverdata;
+ int ret = 0;
+
+ if (!data->debug_enabled) {
+ return 0;
+ }
+ /* check gl errors (can return multiple errors) */
+ for (;;) {
+ GLenum error = data->glGetError();
+ if (error != GL_NO_ERROR) {
+ if (prefix == NULL || prefix[0] == '\0') {
+ prefix = "generic";
+ }
+ SDL_SetError("%s: %s (%d): %s %s (0x%X)", prefix, file, line, function, GL_TranslateError(error), error);
+ ret = -1;
+ } else {
+ break;
+ }
+ }
+ return ret;
+}
+
+#if 0
+#define GL_CheckError(prefix, renderer)
+#else
+#define GL_CheckError(prefix, renderer) GL_CheckAllErrors(prefix, renderer, SDL_FILE, SDL_LINE, SDL_FUNCTION)
+#endif
+
+
+/*************************************************************************************************
+ * Renderer state APIs *
+ *************************************************************************************************/
+
+static int GLES2_ActivateRenderer(SDL_Renderer *renderer);
+static void GLES2_WindowEvent(SDL_Renderer * renderer,
+ const SDL_WindowEvent *event);
+static int GLES2_UpdateViewport(SDL_Renderer * renderer);
+static void GLES2_DestroyRenderer(SDL_Renderer *renderer);
+static int GLES2_SetOrthographicProjection(SDL_Renderer *renderer);
+
+
+static SDL_GLContext SDL_CurrentContext = NULL;
+
+static int GLES2_LoadFunctions(GLES2_DriverContext * data)
+{
+#if SDL_VIDEO_DRIVER_UIKIT
+#define __SDL_NOGETPROCADDR__
+#elif SDL_VIDEO_DRIVER_ANDROID
+#define __SDL_NOGETPROCADDR__
+#elif SDL_VIDEO_DRIVER_PANDORA
+#define __SDL_NOGETPROCADDR__
+#endif
+
+#if defined __SDL_NOGETPROCADDR__
+#define SDL_PROC(ret,func,params) data->func=func;
+#else
+#define SDL_PROC(ret,func,params) \
+ do { \
+ data->func = SDL_GL_GetProcAddress(#func); \
+ if ( ! data->func ) { \
+ return SDL_SetError("Couldn't load GLES2 function %s: %s", #func, SDL_GetError()); \
+ } \
+ } while ( 0 );
+#endif /* __SDL_NOGETPROCADDR__ */
+
+#include "SDL_gles2funcs.h"
+#undef SDL_PROC
+ return 0;
+}
+
+static GLES2_FBOList *
+GLES2_GetFBO(GLES2_DriverContext *data, Uint32 w, Uint32 h)
+{
+ GLES2_FBOList *result = data->framebuffers;
+ while ((result) && ((result->w != w) || (result->h != h)) ) {
+ result = result->next;
+ }
+ if (result == NULL) {
+ result = SDL_malloc(sizeof(GLES2_FBOList));
+ result->w = w;
+ result->h = h;
+ data->glGenFramebuffers(1, &result->FBO);
+ result->next = data->framebuffers;
+ data->framebuffers = result;
+ }
+ return result;
+}
+
+static int
+GLES2_ActivateRenderer(SDL_Renderer * renderer)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+
+ if (SDL_CurrentContext != data->context) {
+ /* Null out the current program to ensure we set it again */
+ data->current_program = NULL;
+
+ if (SDL_GL_MakeCurrent(renderer->window, data->context) < 0) {
+ return -1;
+ }
+ SDL_CurrentContext = data->context;
+
+ GLES2_UpdateViewport(renderer);
+ }
+
+ GL_ClearErrors(renderer);
+
+ return 0;
+}
+
+static void
+GLES2_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+
+ if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED ||
+ event->event == SDL_WINDOWEVENT_SHOWN ||
+ event->event == SDL_WINDOWEVENT_HIDDEN) {
+ /* Rebind the context to the window area */
+ SDL_CurrentContext = NULL;
+ }
+
+ if (event->event == SDL_WINDOWEVENT_MINIMIZED) {
+ /* According to Apple documentation, we need to finish drawing NOW! */
+ data->glFinish();
+ }
+}
+
+static int
+GLES2_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
+{
+ SDL_GL_GetDrawableSize(renderer->window, w, h);
+ return 0;
+}
+
+static GLenum GetBlendFunc(SDL_BlendFactor factor)
+{
+ switch (factor) {
+ case SDL_BLENDFACTOR_ZERO:
+ return GL_ZERO;
+ case SDL_BLENDFACTOR_ONE:
+ return GL_ONE;
+ case SDL_BLENDFACTOR_SRC_COLOR:
+ return GL_SRC_COLOR;
+ case SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR:
+ return GL_ONE_MINUS_SRC_COLOR;
+ case SDL_BLENDFACTOR_SRC_ALPHA:
+ return GL_SRC_ALPHA;
+ case SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA:
+ return GL_ONE_MINUS_SRC_ALPHA;
+ case SDL_BLENDFACTOR_DST_COLOR:
+ return GL_DST_COLOR;
+ case SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR:
+ return GL_ONE_MINUS_DST_COLOR;
+ case SDL_BLENDFACTOR_DST_ALPHA:
+ return GL_DST_ALPHA;
+ case SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA:
+ return GL_ONE_MINUS_DST_ALPHA;
+ default:
+ return GL_INVALID_ENUM;
+ }
+}
+
+static GLenum GetBlendEquation(SDL_BlendOperation operation)
+{
+ switch (operation) {
+ case SDL_BLENDOPERATION_ADD:
+ return GL_FUNC_ADD;
+ case SDL_BLENDOPERATION_SUBTRACT:
+ return GL_FUNC_SUBTRACT;
+ case SDL_BLENDOPERATION_REV_SUBTRACT:
+ return GL_FUNC_REVERSE_SUBTRACT;
+ default:
+ return GL_INVALID_ENUM;
+ }
+}
+
+static SDL_bool
+GLES2_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
+{
+ SDL_BlendFactor srcColorFactor = SDL_GetBlendModeSrcColorFactor(blendMode);
+ SDL_BlendFactor srcAlphaFactor = SDL_GetBlendModeSrcAlphaFactor(blendMode);
+ SDL_BlendOperation colorOperation = SDL_GetBlendModeColorOperation(blendMode);
+ SDL_BlendFactor dstColorFactor = SDL_GetBlendModeDstColorFactor(blendMode);
+ SDL_BlendFactor dstAlphaFactor = SDL_GetBlendModeDstAlphaFactor(blendMode);
+ SDL_BlendOperation alphaOperation = SDL_GetBlendModeAlphaOperation(blendMode);
+
+ if (GetBlendFunc(srcColorFactor) == GL_INVALID_ENUM ||
+ GetBlendFunc(srcAlphaFactor) == GL_INVALID_ENUM ||
+ GetBlendEquation(colorOperation) == GL_INVALID_ENUM ||
+ GetBlendFunc(dstColorFactor) == GL_INVALID_ENUM ||
+ GetBlendFunc(dstAlphaFactor) == GL_INVALID_ENUM ||
+ GetBlendEquation(alphaOperation) == GL_INVALID_ENUM) {
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
+}
+
+static int
+GLES2_UpdateViewport(SDL_Renderer * renderer)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+
+ if (SDL_CurrentContext != data->context) {
+ /* We'll update the viewport after we rebind the context */
+ return 0;
+ }
+
+ if (renderer->target) {
+ data->glViewport(renderer->viewport.x, renderer->viewport.y,
+ renderer->viewport.w, renderer->viewport.h);
+ } else {
+ int w, h;
+
+ SDL_GL_GetDrawableSize(renderer->window, &w, &h);
+ data->glViewport(renderer->viewport.x, (h - renderer->viewport.y - renderer->viewport.h),
+ renderer->viewport.w, renderer->viewport.h);
+ }
+
+ if (data->current_program) {
+ GLES2_SetOrthographicProjection(renderer);
+ }
+ return GL_CheckError("", renderer);
+}
+
+static int
+GLES2_UpdateClipRect(SDL_Renderer * renderer)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+
+ if (SDL_CurrentContext != data->context) {
+ /* We'll update the clip rect after we rebind the context */
+ return 0;
+ }
+
+ if (renderer->clipping_enabled) {
+ const SDL_Rect *rect = &renderer->clip_rect;
+ data->glEnable(GL_SCISSOR_TEST);
+ if (renderer->target) {
+ data->glScissor(renderer->viewport.x + rect->x, renderer->viewport.y + rect->y, rect->w, rect->h);
+ } else {
+ int w, h;
+
+ SDL_GL_GetDrawableSize(renderer->window, &w, &h);
+ data->glScissor(renderer->viewport.x + rect->x, h - renderer->viewport.y - rect->y - rect->h, rect->w, rect->h);
+ }
+ } else {
+ data->glDisable(GL_SCISSOR_TEST);
+ }
+ return 0;
+}
+
+static void
+GLES2_DestroyRenderer(SDL_Renderer *renderer)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+
+ /* Deallocate everything */
+ if (data) {
+ GLES2_ActivateRenderer(renderer);
+
+ {
+ GLES2_ShaderCacheEntry *entry;
+ GLES2_ShaderCacheEntry *next;
+ entry = data->shader_cache.head;
+ while (entry) {
+ data->glDeleteShader(entry->id);
+ next = entry->next;
+ SDL_free(entry);
+ entry = next;
+ }
+ }
+ {
+ GLES2_ProgramCacheEntry *entry;
+ GLES2_ProgramCacheEntry *next;
+ entry = data->program_cache.head;
+ while (entry) {
+ data->glDeleteProgram(entry->id);
+ next = entry->next;
+ SDL_free(entry);
+ entry = next;
+ }
+ }
+ if (data->context) {
+ while (data->framebuffers) {
+ GLES2_FBOList *nextnode = data->framebuffers->next;
+ data->glDeleteFramebuffers(1, &data->framebuffers->FBO);
+ GL_CheckError("", renderer);
+ SDL_free(data->framebuffers);
+ data->framebuffers = nextnode;
+ }
+ SDL_GL_DeleteContext(data->context);
+ }
+ SDL_free(data->shader_formats);
+ SDL_free(data);
+ }
+ SDL_free(renderer);
+}
+
+/*************************************************************************************************
+ * Texture APIs *
+ *************************************************************************************************/
+
+static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture);
+static int GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
+ const void *pixels, int pitch);
+static int GLES2_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch);
+static int GLES2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
+ void **pixels, int *pitch);
+static void GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture);
+static int GLES2_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
+static void GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture);
+
+static GLenum
+GetScaleQuality(void)
+{
+ const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
+
+ if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
+ return GL_NEAREST;
+ } else {
+ return GL_LINEAR;
+ }
+}
+
+static int
+GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
+{
+ GLES2_DriverContext *renderdata = (GLES2_DriverContext *)renderer->driverdata;
+ GLES2_TextureData *data;
+ GLenum format;
+ GLenum type;
+ GLenum scaleMode;
+
+ GLES2_ActivateRenderer(renderer);
+
+ /* Determine the corresponding GLES texture format params */
+ switch (texture->format)
+ {
+ case SDL_PIXELFORMAT_ARGB8888:
+ case SDL_PIXELFORMAT_ABGR8888:
+ case SDL_PIXELFORMAT_RGB888:
+ case SDL_PIXELFORMAT_BGR888:
+ format = GL_RGBA;
+ type = GL_UNSIGNED_BYTE;
+ break;
+ case SDL_PIXELFORMAT_IYUV:
+ case SDL_PIXELFORMAT_YV12:
+ case SDL_PIXELFORMAT_NV12:
+ case SDL_PIXELFORMAT_NV21:
+ format = GL_LUMINANCE;
+ type = GL_UNSIGNED_BYTE;
+ break;
+#ifdef GL_TEXTURE_EXTERNAL_OES
+ case SDL_PIXELFORMAT_EXTERNAL_OES:
+ format = GL_NONE;
+ type = GL_NONE;
+ break;
+#endif
+ default:
+ return SDL_SetError("Texture format not supported");
+ }
+
+ if (texture->format == SDL_PIXELFORMAT_EXTERNAL_OES &&
+ texture->access != SDL_TEXTUREACCESS_STATIC) {
+ return SDL_SetError("Unsupported texture access for SDL_PIXELFORMAT_EXTERNAL_OES");
+ }
+
+ /* Allocate a texture struct */
+ data = (GLES2_TextureData *)SDL_calloc(1, sizeof(GLES2_TextureData));
+ if (!data) {
+ return SDL_OutOfMemory();
+ }
+ data->texture = 0;
+#ifdef GL_TEXTURE_EXTERNAL_OES
+ data->texture_type = (texture->format == SDL_PIXELFORMAT_EXTERNAL_OES) ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D;
+#else
+ data->texture_type = GL_TEXTURE_2D;
+#endif
+ data->pixel_format = format;
+ data->pixel_type = type;
+ data->yuv = ((texture->format == SDL_PIXELFORMAT_IYUV) || (texture->format == SDL_PIXELFORMAT_YV12));
+ data->nv12 = ((texture->format == SDL_PIXELFORMAT_NV12) || (texture->format == SDL_PIXELFORMAT_NV21));
+ data->texture_u = 0;
+ data->texture_v = 0;
+ scaleMode = GetScaleQuality();
+
+ /* Allocate a blob for image renderdata */
+ if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
+ size_t size;
+ data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
+ size = texture->h * data->pitch;
+ if (data->yuv) {
+ /* Need to add size for the U and V planes */
+ size += 2 * ((texture->h + 1) / 2) * ((data->pitch + 1) / 2);
+ }
+ if (data->nv12) {
+ /* Need to add size for the U/V plane */
+ size += 2 * ((texture->h + 1) / 2) * ((data->pitch + 1) / 2);
+ }
+ data->pixel_data = SDL_calloc(1, size);
+ if (!data->pixel_data) {
+ SDL_free(data);
+ return SDL_OutOfMemory();
+ }
+ }
+
+ /* Allocate the texture */
+ GL_CheckError("", renderer);
+
+ if (data->yuv) {
+ renderdata->glGenTextures(1, &data->texture_v);
+ if (GL_CheckError("glGenTexures()", renderer) < 0) {
+ return -1;
+ }
+ renderdata->glActiveTexture(GL_TEXTURE2);
+ renderdata->glBindTexture(data->texture_type, data->texture_v);
+ renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MIN_FILTER, scaleMode);
+ renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, scaleMode);
+ renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ renderdata->glTexImage2D(data->texture_type, 0, format, (texture->w + 1) / 2, (texture->h + 1) / 2, 0, format, type, NULL);
+
+ renderdata->glGenTextures(1, &data->texture_u);
+ if (GL_CheckError("glGenTexures()", renderer) < 0) {
+ return -1;
+ }
+ renderdata->glActiveTexture(GL_TEXTURE1);
+ renderdata->glBindTexture(data->texture_type, data->texture_u);
+ renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MIN_FILTER, scaleMode);
+ renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, scaleMode);
+ renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ renderdata->glTexImage2D(data->texture_type, 0, format, (texture->w + 1) / 2, (texture->h + 1) / 2, 0, format, type, NULL);
+ if (GL_CheckError("glTexImage2D()", renderer) < 0) {
+ return -1;
+ }
+ }
+
+ if (data->nv12) {
+ renderdata->glGenTextures(1, &data->texture_u);
+ if (GL_CheckError("glGenTexures()", renderer) < 0) {
+ return -1;
+ }
+ renderdata->glActiveTexture(GL_TEXTURE1);
+ renderdata->glBindTexture(data->texture_type, data->texture_u);
+ renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MIN_FILTER, scaleMode);
+ renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, scaleMode);
+ renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ renderdata->glTexImage2D(data->texture_type, 0, GL_LUMINANCE_ALPHA, (texture->w + 1) / 2, (texture->h + 1) / 2, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NULL);
+ if (GL_CheckError("glTexImage2D()", renderer) < 0) {
+ return -1;
+ }
+ }
+
+ renderdata->glGenTextures(1, &data->texture);
+ if (GL_CheckError("glGenTexures()", renderer) < 0) {
+ return -1;
+ }
+ texture->driverdata = data;
+ renderdata->glActiveTexture(GL_TEXTURE0);
+ renderdata->glBindTexture(data->texture_type, data->texture);
+ renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MIN_FILTER, scaleMode);
+ renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, scaleMode);
+ renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ if (texture->format != SDL_PIXELFORMAT_EXTERNAL_OES) {
+ renderdata->glTexImage2D(data->texture_type, 0, format, texture->w, texture->h, 0, format, type, NULL);
+ if (GL_CheckError("glTexImage2D()", renderer) < 0) {
+ return -1;
+ }
+ }
+
+ if (texture->access == SDL_TEXTUREACCESS_TARGET) {
+ data->fbo = GLES2_GetFBO(renderer->driverdata, texture->w, texture->h);
+ } else {
+ data->fbo = NULL;
+ }
+
+ return GL_CheckError("", renderer);
+}
+
+static int
+GLES2_TexSubImage2D(GLES2_DriverContext *data, GLenum target, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels, GLint pitch, GLint bpp)
+{
+ Uint8 *blob = NULL;
+ Uint8 *src;
+ int src_pitch;
+ int y;
+
+ /* Reformat the texture data into a tightly packed array */
+ src_pitch = width * bpp;
+ src = (Uint8 *)pixels;
+ if (pitch != src_pitch) {
+ blob = (Uint8 *)SDL_malloc(src_pitch * height);
+ if (!blob) {
+ return SDL_OutOfMemory();
+ }
+ src = blob;
+ for (y = 0; y < height; ++y)
+ {
+ SDL_memcpy(src, pixels, src_pitch);
+ src += src_pitch;
+ pixels = (Uint8 *)pixels + pitch;
+ }
+ src = blob;
+ }
+
+ data->glTexSubImage2D(target, 0, xoffset, yoffset, width, height, format, type, src);
+ if (blob) {
+ SDL_free(blob);
+ }
+ return 0;
+}
+
+static int
+GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
+ const void *pixels, int pitch)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+ GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
+
+ GLES2_ActivateRenderer(renderer);
+
+ /* Bail out if we're supposed to update an empty rectangle */
+ if (rect->w <= 0 || rect->h <= 0) {
+ return 0;
+ }
+
+ /* Create a texture subimage with the supplied data */
+ data->glBindTexture(tdata->texture_type, tdata->texture);
+ GLES2_TexSubImage2D(data, tdata->texture_type,
+ rect->x,
+ rect->y,
+ rect->w,
+ rect->h,
+ tdata->pixel_format,
+ tdata->pixel_type,
+ pixels, pitch, SDL_BYTESPERPIXEL(texture->format));
+
+ if (tdata->yuv) {
+ /* Skip to the correct offset into the next texture */
+ pixels = (const void*)((const Uint8*)pixels + rect->h * pitch);
+ if (texture->format == SDL_PIXELFORMAT_YV12) {
+ data->glBindTexture(tdata->texture_type, tdata->texture_v);
+ } else {
+ data->glBindTexture(tdata->texture_type, tdata->texture_u);
+ }
+ GLES2_TexSubImage2D(data, tdata->texture_type,
+ rect->x / 2,
+ rect->y / 2,
+ (rect->w + 1) / 2,
+ (rect->h + 1) / 2,
+ tdata->pixel_format,
+ tdata->pixel_type,
+ pixels, (pitch + 1) / 2, 1);
+
+
+ /* Skip to the correct offset into the next texture */
+ pixels = (const void*)((const Uint8*)pixels + ((rect->h + 1) / 2) * ((pitch + 1)/2));
+ if (texture->format == SDL_PIXELFORMAT_YV12) {
+ data->glBindTexture(tdata->texture_type, tdata->texture_u);
+ } else {
+ data->glBindTexture(tdata->texture_type, tdata->texture_v);
+ }
+ GLES2_TexSubImage2D(data, tdata->texture_type,
+ rect->x / 2,
+ rect->y / 2,
+ (rect->w + 1) / 2,
+ (rect->h + 1) / 2,
+ tdata->pixel_format,
+ tdata->pixel_type,
+ pixels, (pitch + 1) / 2, 1);
+ }
+
+ if (tdata->nv12) {
+ /* Skip to the correct offset into the next texture */
+ pixels = (const void*)((const Uint8*)pixels + rect->h * pitch);
+ data->glBindTexture(tdata->texture_type, tdata->texture_u);
+ GLES2_TexSubImage2D(data, tdata->texture_type,
+ rect->x / 2,
+ rect->y / 2,
+ (rect->w + 1) / 2,
+ (rect->h + 1) / 2,
+ GL_LUMINANCE_ALPHA,
+ GL_UNSIGNED_BYTE,
+ pixels, 2 * ((pitch + 1) / 2), 2);
+ }
+
+ return GL_CheckError("glTexSubImage2D()", renderer);
+}
+
+static int
+GLES2_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect,
+ const Uint8 *Yplane, int Ypitch,
+ const Uint8 *Uplane, int Upitch,
+ const Uint8 *Vplane, int Vpitch)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+ GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
+
+ GLES2_ActivateRenderer(renderer);
+
+ /* Bail out if we're supposed to update an empty rectangle */
+ if (rect->w <= 0 || rect->h <= 0) {
+ return 0;
+ }
+
+ data->glBindTexture(tdata->texture_type, tdata->texture_v);
+ GLES2_TexSubImage2D(data, tdata->texture_type,
+ rect->x / 2,
+ rect->y / 2,
+ (rect->w + 1) / 2,
+ (rect->h + 1) / 2,
+ tdata->pixel_format,
+ tdata->pixel_type,
+ Vplane, Vpitch, 1);
+
+ data->glBindTexture(tdata->texture_type, tdata->texture_u);
+ GLES2_TexSubImage2D(data, tdata->texture_type,
+ rect->x / 2,
+ rect->y / 2,
+ (rect->w + 1) / 2,
+ (rect->h + 1) / 2,
+ tdata->pixel_format,
+ tdata->pixel_type,
+ Uplane, Upitch, 1);
+
+ data->glBindTexture(tdata->texture_type, tdata->texture);
+ GLES2_TexSubImage2D(data, tdata->texture_type,
+ rect->x,
+ rect->y,
+ rect->w,
+ rect->h,
+ tdata->pixel_format,
+ tdata->pixel_type,
+ Yplane, Ypitch, 1);
+
+ return GL_CheckError("glTexSubImage2D()", renderer);
+}
+
+static int
+GLES2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
+ void **pixels, int *pitch)
+{
+ GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
+
+ /* Retrieve the buffer/pitch for the specified region */
+ *pixels = (Uint8 *)tdata->pixel_data +
+ (tdata->pitch * rect->y) +
+ (rect->x * SDL_BYTESPERPIXEL(texture->format));
+ *pitch = tdata->pitch;
+
+ return 0;
+}
+
+static void
+GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
+{
+ GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
+ SDL_Rect rect;
+
+ /* We do whole texture updates, at least for now */
+ rect.x = 0;
+ rect.y = 0;
+ rect.w = texture->w;
+ rect.h = texture->h;
+ GLES2_UpdateTexture(renderer, texture, &rect, tdata->pixel_data, tdata->pitch);
+}
+
+static int
+GLES2_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *) renderer->driverdata;
+ GLES2_TextureData *texturedata = NULL;
+ GLenum status;
+
+ if (texture == NULL) {
+ data->glBindFramebuffer(GL_FRAMEBUFFER, data->window_framebuffer);
+ } else {
+ texturedata = (GLES2_TextureData *) texture->driverdata;
+ data->glBindFramebuffer(GL_FRAMEBUFFER, texturedata->fbo->FBO);
+ /* TODO: check if texture pixel format allows this operation */
+ data->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texturedata->texture_type, texturedata->texture, 0);
+ /* Check FBO status */
+ status = data->glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ if (status != GL_FRAMEBUFFER_COMPLETE) {
+ return SDL_SetError("glFramebufferTexture2D() failed");
+ }
+ }
+ return 0;
+}
+
+static void
+GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+ GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
+
+ GLES2_ActivateRenderer(renderer);
+
+ /* Destroy the texture */
+ if (tdata) {
+ data->glDeleteTextures(1, &tdata->texture);
+ if (tdata->texture_v) {
+ data->glDeleteTextures(1, &tdata->texture_v);
+ }
+ if (tdata->texture_u) {
+ data->glDeleteTextures(1, &tdata->texture_u);
+ }
+ SDL_free(tdata->pixel_data);
+ SDL_free(tdata);
+ texture->driverdata = NULL;
+ }
+}
+
+/*************************************************************************************************
+ * Shader management functions *
+ *************************************************************************************************/
+
+static GLES2_ShaderCacheEntry *GLES2_CacheShader(SDL_Renderer *renderer, GLES2_ShaderType type);
+static void GLES2_EvictShader(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *entry);
+static GLES2_ProgramCacheEntry *GLES2_CacheProgram(SDL_Renderer *renderer,
+ GLES2_ShaderCacheEntry *vertex,
+ GLES2_ShaderCacheEntry *fragment);
+static int GLES2_SelectProgram(SDL_Renderer *renderer, GLES2_ImageSource source, int w, int h);
+
+static GLES2_ProgramCacheEntry *
+GLES2_CacheProgram(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *vertex,
+ GLES2_ShaderCacheEntry *fragment)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+ GLES2_ProgramCacheEntry *entry;
+ GLES2_ShaderCacheEntry *shaderEntry;
+ GLint linkSuccessful;
+
+ /* Check if we've already cached this program */
+ entry = data->program_cache.head;
+ while (entry) {
+ if (entry->vertex_shader == vertex && entry->fragment_shader == fragment) {
+ break;
+ }
+ entry = entry->next;
+ }
+ if (entry) {
+ if (data->program_cache.head != entry) {
+ if (entry->next) {
+ entry->next->prev = entry->prev;
+ }
+ if (entry->prev) {
+ entry->prev->next = entry->next;
+ }
+ entry->prev = NULL;
+ entry->next = data->program_cache.head;
+ data->program_cache.head->prev = entry;
+ data->program_cache.head = entry;
+ }
+ return entry;
+ }
+
+ /* Create a program cache entry */
+ entry = (GLES2_ProgramCacheEntry *)SDL_calloc(1, sizeof(GLES2_ProgramCacheEntry));
+ if (!entry) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ entry->vertex_shader = vertex;
+ entry->fragment_shader = fragment;
+
+ /* Create the program and link it */
+ entry->id = data->glCreateProgram();
+ data->glAttachShader(entry->id, vertex->id);
+ data->glAttachShader(entry->id, fragment->id);
+ data->glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_POSITION, "a_position");
+ data->glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_TEXCOORD, "a_texCoord");
+ data->glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_ANGLE, "a_angle");
+ data->glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_CENTER, "a_center");
+ data->glLinkProgram(entry->id);
+ data->glGetProgramiv(entry->id, GL_LINK_STATUS, &linkSuccessful);
+ if (!linkSuccessful) {
+ data->glDeleteProgram(entry->id);
+ SDL_free(entry);
+ SDL_SetError("Failed to link shader program");
+ return NULL;
+ }
+
+ /* Predetermine locations of uniform variables */
+ entry->uniform_locations[GLES2_UNIFORM_PROJECTION] =
+ data->glGetUniformLocation(entry->id, "u_projection");
+ entry->uniform_locations[GLES2_UNIFORM_TEXTURE_V] =
+ data->glGetUniformLocation(entry->id, "u_texture_v");
+ entry->uniform_locations[GLES2_UNIFORM_TEXTURE_U] =
+ data->glGetUniformLocation(entry->id, "u_texture_u");
+ entry->uniform_locations[GLES2_UNIFORM_TEXTURE] =
+ data->glGetUniformLocation(entry->id, "u_texture");
+ entry->uniform_locations[GLES2_UNIFORM_MODULATION] =
+ data->glGetUniformLocation(entry->id, "u_modulation");
+ entry->uniform_locations[GLES2_UNIFORM_COLOR] =
+ data->glGetUniformLocation(entry->id, "u_color");
+
+ entry->modulation_r = entry->modulation_g = entry->modulation_b = entry->modulation_a = 255;
+ entry->color_r = entry->color_g = entry->color_b = entry->color_a = 255;
+
+ data->glUseProgram(entry->id);
+ data->glUniform1i(entry->uniform_locations[GLES2_UNIFORM_TEXTURE_V], 2); /* always texture unit 2. */
+ data->glUniform1i(entry->uniform_locations[GLES2_UNIFORM_TEXTURE_U], 1); /* always texture unit 1. */
+ data->glUniform1i(entry->uniform_locations[GLES2_UNIFORM_TEXTURE], 0); /* always texture unit 0. */
+ data->glUniformMatrix4fv(entry->uniform_locations[GLES2_UNIFORM_PROJECTION], 1, GL_FALSE, (GLfloat *)entry->projection);
+ data->glUniform4f(entry->uniform_locations[GLES2_UNIFORM_MODULATION], 1.0f, 1.0f, 1.0f, 1.0f);
+ data->glUniform4f(entry->uniform_locations[GLES2_UNIFORM_COLOR], 1.0f, 1.0f, 1.0f, 1.0f);
+
+ /* Cache the linked program */
+ if (data->program_cache.head) {
+ entry->next = data->program_cache.head;
+ data->program_cache.head->prev = entry;
+ } else {
+ data->program_cache.tail = entry;
+ }
+ data->program_cache.head = entry;
+ ++data->program_cache.count;
+
+ /* Increment the refcount of the shaders we're using */
+ ++vertex->references;
+ ++fragment->references;
+
+ /* Evict the last entry from the cache if we exceed the limit */
+ if (data->program_cache.count > GLES2_MAX_CACHED_PROGRAMS) {
+ shaderEntry = data->program_cache.tail->vertex_shader;
+ if (--shaderEntry->references <= 0) {
+ GLES2_EvictShader(renderer, shaderEntry);
+ }
+ shaderEntry = data->program_cache.tail->fragment_shader;
+ if (--shaderEntry->references <= 0) {
+ GLES2_EvictShader(renderer, shaderEntry);
+ }
+ data->glDeleteProgram(data->program_cache.tail->id);
+ data->program_cache.tail = data->program_cache.tail->prev;
+ SDL_free(data->program_cache.tail->next);
+ data->program_cache.tail->next = NULL;
+ --data->program_cache.count;
+ }
+ return entry;
+}
+
+static GLES2_ShaderCacheEntry *
+GLES2_CacheShader(SDL_Renderer *renderer, GLES2_ShaderType type)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+ const GLES2_Shader *shader;
+ const GLES2_ShaderInstance *instance = NULL;
+ GLES2_ShaderCacheEntry *entry = NULL;
+ GLint compileSuccessful = GL_FALSE;
+ int i, j;
+
+ /* Find the corresponding shader */
+ shader = GLES2_GetShader(type);
+ if (!shader) {
+ SDL_SetError("No shader matching the requested characteristics was found");
+ return NULL;
+ }
+
+ /* Find a matching shader instance that's supported on this hardware */
+ for (i = 0; i < shader->instance_count && !instance; ++i) {
+ for (j = 0; j < data->shader_format_count && !instance; ++j) {
+ if (!shader->instances[i]) {
+ continue;
+ }
+ if (shader->instances[i]->format != data->shader_formats[j]) {
+ continue;
+ }
+ instance = shader->instances[i];
+ }
+ }
+ if (!instance) {
+ SDL_SetError("The specified shader cannot be loaded on the current platform");
+ return NULL;
+ }
+
+ /* Check if we've already cached this shader */
+ entry = data->shader_cache.head;
+ while (entry) {
+ if (entry->instance == instance) {
+ break;
+ }
+ entry = entry->next;
+ }
+ if (entry) {
+ return entry;
+ }
+
+ /* Create a shader cache entry */
+ entry = (GLES2_ShaderCacheEntry *)SDL_calloc(1, sizeof(GLES2_ShaderCacheEntry));
+ if (!entry) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ entry->type = type;
+ entry->instance = instance;
+
+ /* Compile or load the selected shader instance */
+ entry->id = data->glCreateShader(instance->type);
+ if (instance->format == (GLenum)-1) {
+ data->glShaderSource(entry->id, 1, (const char **)(char *)&instance->data, NULL);
+ data->glCompileShader(entry->id);
+ data->glGetShaderiv(entry->id, GL_COMPILE_STATUS, &compileSuccessful);
+ } else {
+ data->glShaderBinary(1, &entry->id, instance->format, instance->data, instance->length);
+ compileSuccessful = GL_TRUE;
+ }
+ if (!compileSuccessful) {
+ char *info = NULL;
+ int length = 0;
+
+ data->glGetShaderiv(entry->id, GL_INFO_LOG_LENGTH, &length);
+ if (length > 0) {
+ info = SDL_stack_alloc(char, length);
+ if (info) {
+ data->glGetShaderInfoLog(entry->id, length, &length, info);
+ }
+ }
+ if (info) {
+ SDL_SetError("Failed to load the shader: %s", info);
+ SDL_stack_free(info);
+ } else {
+ SDL_SetError("Failed to load the shader");
+ }
+ data->glDeleteShader(entry->id);
+ SDL_free(entry);
+ return NULL;
+ }
+
+ /* Link the shader entry in at the front of the cache */
+ if (data->shader_cache.head) {
+ entry->next = data->shader_cache.head;
+ data->shader_cache.head->prev = entry;
+ }
+ data->shader_cache.head = entry;
+ ++data->shader_cache.count;
+ return entry;
+}
+
+static void
+GLES2_EvictShader(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *entry)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+
+ /* Unlink the shader from the cache */
+ if (entry->next) {
+ entry->next->prev = entry->prev;
+ }
+ if (entry->prev) {
+ entry->prev->next = entry->next;
+ }
+ if (data->shader_cache.head == entry) {
+ data->shader_cache.head = entry->next;
+ }
+ --data->shader_cache.count;
+
+ /* Deallocate the shader */
+ data->glDeleteShader(entry->id);
+ SDL_free(entry);
+}
+
+static int
+GLES2_SelectProgram(SDL_Renderer *renderer, GLES2_ImageSource source, int w, int h)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+ GLES2_ShaderCacheEntry *vertex = NULL;
+ GLES2_ShaderCacheEntry *fragment = NULL;
+ GLES2_ShaderType vtype, ftype;
+ GLES2_ProgramCacheEntry *program;
+
+ /* Select an appropriate shader pair for the specified modes */
+ vtype = GLES2_SHADER_VERTEX_DEFAULT;
+ switch (source) {
+ case GLES2_IMAGESOURCE_SOLID:
+ ftype = GLES2_SHADER_FRAGMENT_SOLID_SRC;
+ break;
+ case GLES2_IMAGESOURCE_TEXTURE_ABGR:
+ ftype = GLES2_SHADER_FRAGMENT_TEXTURE_ABGR_SRC;
+ break;
+ case GLES2_IMAGESOURCE_TEXTURE_ARGB:
+ ftype = GLES2_SHADER_FRAGMENT_TEXTURE_ARGB_SRC;
+ break;
+ case GLES2_IMAGESOURCE_TEXTURE_RGB:
+ ftype = GLES2_SHADER_FRAGMENT_TEXTURE_RGB_SRC;
+ break;
+ case GLES2_IMAGESOURCE_TEXTURE_BGR:
+ ftype = GLES2_SHADER_FRAGMENT_TEXTURE_BGR_SRC;
+ break;
+ case GLES2_IMAGESOURCE_TEXTURE_YUV:
+ switch (SDL_GetYUVConversionModeForResolution(w, h)) {
+ case SDL_YUV_CONVERSION_JPEG:
+ ftype = GLES2_SHADER_FRAGMENT_TEXTURE_YUV_JPEG_SRC;
+ break;
+ case SDL_YUV_CONVERSION_BT601:
+ ftype = GLES2_SHADER_FRAGMENT_TEXTURE_YUV_BT601_SRC;
+ break;
+ case SDL_YUV_CONVERSION_BT709:
+ ftype = GLES2_SHADER_FRAGMENT_TEXTURE_YUV_BT709_SRC;
+ break;
+ default:
+ SDL_SetError("Unsupported YUV conversion mode: %d\n", SDL_GetYUVConversionModeForResolution(w, h));
+ goto fault;
+ }
+ break;
+ case GLES2_IMAGESOURCE_TEXTURE_NV12:
+ switch (SDL_GetYUVConversionModeForResolution(w, h)) {
+ case SDL_YUV_CONVERSION_JPEG:
+ ftype = GLES2_SHADER_FRAGMENT_TEXTURE_NV12_JPEG_SRC;
+ break;
+ case SDL_YUV_CONVERSION_BT601:
+ ftype = GLES2_SHADER_FRAGMENT_TEXTURE_NV12_BT601_SRC;
+ break;
+ case SDL_YUV_CONVERSION_BT709:
+ ftype = GLES2_SHADER_FRAGMENT_TEXTURE_NV12_BT709_SRC;
+ break;
+ default:
+ SDL_SetError("Unsupported YUV conversion mode: %d\n", SDL_GetYUVConversionModeForResolution(w, h));
+ goto fault;
+ }
+ break;
+ case GLES2_IMAGESOURCE_TEXTURE_NV21:
+ switch (SDL_GetYUVConversionModeForResolution(w, h)) {
+ case SDL_YUV_CONVERSION_JPEG:
+ ftype = GLES2_SHADER_FRAGMENT_TEXTURE_NV21_JPEG_SRC;
+ break;
+ case SDL_YUV_CONVERSION_BT601:
+ ftype = GLES2_SHADER_FRAGMENT_TEXTURE_NV21_BT601_SRC;
+ break;
+ case SDL_YUV_CONVERSION_BT709:
+ ftype = GLES2_SHADER_FRAGMENT_TEXTURE_NV21_BT709_SRC;
+ break;
+ default:
+ SDL_SetError("Unsupported YUV conversion mode: %d\n", SDL_GetYUVConversionModeForResolution(w, h));
+ goto fault;
+ }
+ break;
+ case GLES2_IMAGESOURCE_TEXTURE_EXTERNAL_OES:
+ ftype = GLES2_SHADER_FRAGMENT_TEXTURE_EXTERNAL_OES_SRC;
+ break;
+ default:
+ goto fault;
+ }
+
+ /* Load the requested shaders */
+ vertex = GLES2_CacheShader(renderer, vtype);
+ if (!vertex) {
+ goto fault;
+ }
+ fragment = GLES2_CacheShader(renderer, ftype);
+ if (!fragment) {
+ goto fault;
+ }
+
+ /* Check if we need to change programs at all */
+ if (data->current_program &&
+ data->current_program->vertex_shader == vertex &&
+ data->current_program->fragment_shader == fragment) {
+ return 0;
+ }
+
+ /* Generate a matching program */
+ program = GLES2_CacheProgram(renderer, vertex, fragment);
+ if (!program) {
+ goto fault;
+ }
+
+ /* Select that program in OpenGL */
+ data->glUseProgram(program->id);
+
+ /* Set the current program */
+ data->current_program = program;
+
+ /* Activate an orthographic projection */
+ if (GLES2_SetOrthographicProjection(renderer) < 0) {
+ goto fault;
+ }
+
+ /* Clean up and return */
+ return 0;
+fault:
+ if (vertex && vertex->references <= 0) {
+ GLES2_EvictShader(renderer, vertex);
+ }
+ if (fragment && fragment->references <= 0) {
+ GLES2_EvictShader(renderer, fragment);
+ }
+ data->current_program = NULL;
+ return -1;
+}
+
+static int
+GLES2_SetOrthographicProjection(SDL_Renderer *renderer)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+ GLfloat projection[4][4];
+
+ if (!renderer->viewport.w || !renderer->viewport.h) {
+ return 0;
+ }
+
+ /* Prepare an orthographic projection */
+ projection[0][0] = 2.0f / renderer->viewport.w;
+ projection[0][1] = 0.0f;
+ projection[0][2] = 0.0f;
+ projection[0][3] = 0.0f;
+ projection[1][0] = 0.0f;
+ if (renderer->target) {
+ projection[1][1] = 2.0f / renderer->viewport.h;
+ } else {
+ projection[1][1] = -2.0f / renderer->viewport.h;
+ }
+ projection[1][2] = 0.0f;
+ projection[1][3] = 0.0f;
+ projection[2][0] = 0.0f;
+ projection[2][1] = 0.0f;
+ projection[2][2] = 0.0f;
+ projection[2][3] = 0.0f;
+ projection[3][0] = -1.0f;
+ if (renderer->target) {
+ projection[3][1] = -1.0f;
+ } else {
+ projection[3][1] = 1.0f;
+ }
+ projection[3][2] = 0.0f;
+ projection[3][3] = 1.0f;
+
+ /* Set the projection matrix */
+ if (SDL_memcmp(data->current_program->projection, projection, sizeof (projection)) != 0) {
+ const GLuint locProjection = data->current_program->uniform_locations[GLES2_UNIFORM_PROJECTION];
+ data->glUniformMatrix4fv(locProjection, 1, GL_FALSE, (GLfloat *)projection);
+ SDL_memcpy(data->current_program->projection, projection, sizeof (projection));
+ }
+
+ return 0;
+}
+
+/*************************************************************************************************
+ * Rendering functions *
+ *************************************************************************************************/
+
+static const float inv255f = 1.0f / 255.0f;
+
+static int GLES2_RenderClear(SDL_Renderer *renderer);
+static int GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int count);
+static int GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_FPoint *points, int count);
+static int GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count);
+static int GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect,
+ const SDL_FRect *dstrect);
+static int GLES2_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect,
+ const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip);
+static int GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 pixel_format, void * pixels, int pitch);
+static void GLES2_RenderPresent(SDL_Renderer *renderer);
+
+static SDL_bool
+CompareColors(Uint8 r1, Uint8 g1, Uint8 b1, Uint8 a1,
+ Uint8 r2, Uint8 g2, Uint8 b2, Uint8 a2)
+{
+ Uint32 Pixel1, Pixel2;
+ RGBA8888_FROM_RGBA(Pixel1, r1, g1, b1, a1);
+ RGBA8888_FROM_RGBA(Pixel2, r2, g2, b2, a2);
+ return (Pixel1 == Pixel2);
+}
+
+static int
+GLES2_RenderClear(SDL_Renderer * renderer)
+{
+ Uint8 r, g, b, a;
+
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+
+ GLES2_ActivateRenderer(renderer);
+
+ if (!CompareColors(data->clear_r, data->clear_g, data->clear_b, data->clear_a,
+ renderer->r, renderer->g, renderer->b, renderer->a)) {
+
+ /* Select the color to clear with */
+ g = renderer->g;
+ a = renderer->a;
+
+ if (renderer->target &&
+ (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 ||
+ renderer->target->format == SDL_PIXELFORMAT_RGB888)) {
+ r = renderer->b;
+ b = renderer->r;
+ } else {
+ r = renderer->r;
+ b = renderer->b;
+ }
+
+ data->glClearColor((GLfloat) r * inv255f,
+ (GLfloat) g * inv255f,
+ (GLfloat) b * inv255f,
+ (GLfloat) a * inv255f);
+ data->clear_r = renderer->r;
+ data->clear_g = renderer->g;
+ data->clear_b = renderer->b;
+ data->clear_a = renderer->a;
+ }
+
+ if (renderer->clipping_enabled) {
+ data->glDisable(GL_SCISSOR_TEST);
+ }
+
+ data->glClear(GL_COLOR_BUFFER_BIT);
+
+ if (renderer->clipping_enabled) {
+ data->glEnable(GL_SCISSOR_TEST);
+ }
+
+ return 0;
+}
+
+static void
+GLES2_SetBlendMode(GLES2_DriverContext *data, SDL_BlendMode blendMode)
+{
+ if (blendMode != data->current.blendMode) {
+ if (blendMode == SDL_BLENDMODE_NONE) {
+ data->glDisable(GL_BLEND);
+ } else {
+ data->glEnable(GL_BLEND);
+ data->glBlendFuncSeparate(GetBlendFunc(SDL_GetBlendModeSrcColorFactor(blendMode)),
+ GetBlendFunc(SDL_GetBlendModeDstColorFactor(blendMode)),
+ GetBlendFunc(SDL_GetBlendModeSrcAlphaFactor(blendMode)),
+ GetBlendFunc(SDL_GetBlendModeDstAlphaFactor(blendMode)));
+ data->glBlendEquationSeparate(GetBlendEquation(SDL_GetBlendModeColorOperation(blendMode)),
+ GetBlendEquation(SDL_GetBlendModeAlphaOperation(blendMode)));
+ }
+ data->current.blendMode = blendMode;
+ }
+}
+
+static void
+GLES2_SetTexCoords(GLES2_DriverContext * data, SDL_bool enabled)
+{
+ if (enabled != data->current.tex_coords) {
+ if (enabled) {
+ data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
+ } else {
+ data->glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
+ }
+ data->current.tex_coords = enabled;
+ }
+}
+
+static int
+GLES2_SetDrawingState(SDL_Renderer * renderer)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+ GLES2_ProgramCacheEntry *program;
+ Uint8 r, g, b, a;
+
+ GLES2_ActivateRenderer(renderer);
+
+ GLES2_SetBlendMode(data, renderer->blendMode);
+
+ GLES2_SetTexCoords(data, SDL_FALSE);
+
+ /* Activate an appropriate shader and set the projection matrix */
+ if (GLES2_SelectProgram(renderer, GLES2_IMAGESOURCE_SOLID, 0, 0) < 0) {
+ return -1;
+ }
+
+ /* Select the color to draw with */
+ g = renderer->g;
+ a = renderer->a;
+
+ if (renderer->target &&
+ (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 ||
+ renderer->target->format == SDL_PIXELFORMAT_RGB888)) {
+ r = renderer->b;
+ b = renderer->r;
+ } else {
+ r = renderer->r;
+ b = renderer->b;
+ }
+
+ program = data->current_program;
+ if (!CompareColors(program->color_r, program->color_g, program->color_b, program->color_a, r, g, b, a)) {
+ /* Select the color to draw with */
+ data->glUniform4f(program->uniform_locations[GLES2_UNIFORM_COLOR], r * inv255f, g * inv255f, b * inv255f, a * inv255f);
+ program->color_r = r;
+ program->color_g = g;
+ program->color_b = b;
+ program->color_a = a;
+ }
+
+ return 0;
+}
+
+static int
+GLES2_UpdateVertexBuffer(SDL_Renderer *renderer, GLES2_Attribute attr,
+ const void *vertexData, size_t dataSizeInBytes)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+
+#if !SDL_GLES2_USE_VBOS
+ data->glVertexAttribPointer(attr, attr == GLES2_ATTRIBUTE_ANGLE ? 1 : 2, GL_FLOAT, GL_FALSE, 0, vertexData);
+#else
+ if (!data->vertex_buffers[attr]) {
+ data->glGenBuffers(1, &data->vertex_buffers[attr]);
+ }
+
+ data->glBindBuffer(GL_ARRAY_BUFFER, data->vertex_buffers[attr]);
+
+ if (data->vertex_buffer_size[attr] < dataSizeInBytes) {
+ data->glBufferData(GL_ARRAY_BUFFER, dataSizeInBytes, vertexData, GL_STREAM_DRAW);
+ data->vertex_buffer_size[attr] = dataSizeInBytes;
+ } else {
+ data->glBufferSubData(GL_ARRAY_BUFFER, 0, dataSizeInBytes, vertexData);
+ }
+
+ data->glVertexAttribPointer(attr, attr == GLES2_ATTRIBUTE_ANGLE ? 1 : 2, GL_FLOAT, GL_FALSE, 0, 0);
+#endif
+
+ return 0;
+}
+
+static int
+GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+ GLfloat *vertices;
+ int idx;
+
+ if (GLES2_SetDrawingState(renderer) < 0) {
+ return -1;
+ }
+
+ /* Emit the specified vertices as points */
+ vertices = SDL_stack_alloc(GLfloat, count * 2);
+ for (idx = 0; idx < count; ++idx) {
+ GLfloat x = points[idx].x + 0.5f;
+ GLfloat y = points[idx].y + 0.5f;
+
+ vertices[idx * 2] = x;
+ vertices[(idx * 2) + 1] = y;
+ }
+ /*data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
+ GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, count * 2 * sizeof(GLfloat));
+ data->glDrawArrays(GL_POINTS, 0, count);
+ SDL_stack_free(vertices);
+ return 0;
+}
+
+static int
+GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+ GLfloat *vertices;
+ int idx;
+
+ if (GLES2_SetDrawingState(renderer) < 0) {
+ return -1;
+ }
+
+ /* Emit a line strip including the specified vertices */
+ vertices = SDL_stack_alloc(GLfloat, count * 2);
+ for (idx = 0; idx < count; ++idx) {
+ GLfloat x = points[idx].x + 0.5f;
+ GLfloat y = points[idx].y + 0.5f;
+
+ vertices[idx * 2] = x;
+ vertices[(idx * 2) + 1] = y;
+ }
+ /*data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
+ GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, count * 2 * sizeof(GLfloat));
+ data->glDrawArrays(GL_LINE_STRIP, 0, count);
+
+ /* We need to close the endpoint of the line */
+ if (count == 2 ||
+ points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
+ data->glDrawArrays(GL_POINTS, count-1, 1);
+ }
+ SDL_stack_free(vertices);
+
+ return GL_CheckError("", renderer);
+}
+
+static int
+GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+ GLfloat vertices[8];
+ int idx;
+
+ if (GLES2_SetDrawingState(renderer) < 0) {
+ return -1;
+ }
+
+ /* Emit a line loop for each rectangle */
+ for (idx = 0; idx < count; ++idx) {
+ const SDL_FRect *rect = &rects[idx];
+
+ GLfloat xMin = rect->x;
+ GLfloat xMax = (rect->x + rect->w);
+ GLfloat yMin = rect->y;
+ GLfloat yMax = (rect->y + rect->h);
+
+ vertices[0] = xMin;
+ vertices[1] = yMin;
+ vertices[2] = xMax;
+ vertices[3] = yMin;
+ vertices[4] = xMin;
+ vertices[5] = yMax;
+ vertices[6] = xMax;
+ vertices[7] = yMax;
+ /*data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
+ GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, 8 * sizeof(GLfloat));
+ data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ }
+ return GL_CheckError("", renderer);
+}
+
+static int
+GLES2_SetupCopy(SDL_Renderer *renderer, SDL_Texture *texture)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+ GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
+ GLES2_ImageSource sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
+ GLES2_ProgramCacheEntry *program;
+ Uint8 r, g, b, a;
+
+ /* Activate an appropriate shader and set the projection matrix */
+ if (renderer->target) {
+ /* Check if we need to do color mapping between the source and render target textures */
+ if (renderer->target->format != texture->format) {
+ switch (texture->format) {
+ case SDL_PIXELFORMAT_ARGB8888:
+ switch (renderer->target->format) {
+ case SDL_PIXELFORMAT_ABGR8888:
+ case SDL_PIXELFORMAT_BGR888:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
+ break;
+ case SDL_PIXELFORMAT_RGB888:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
+ break;
+ }
+ break;
+ case SDL_PIXELFORMAT_ABGR8888:
+ switch (renderer->target->format) {
+ case SDL_PIXELFORMAT_ARGB8888:
+ case SDL_PIXELFORMAT_RGB888:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
+ break;
+ case SDL_PIXELFORMAT_BGR888:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
+ break;
+ }
+ break;
+ case SDL_PIXELFORMAT_RGB888:
+ switch (renderer->target->format) {
+ case SDL_PIXELFORMAT_ABGR8888:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
+ break;
+ case SDL_PIXELFORMAT_ARGB8888:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
+ break;
+ case SDL_PIXELFORMAT_BGR888:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
+ break;
+ }
+ break;
+ case SDL_PIXELFORMAT_BGR888:
+ switch (renderer->target->format) {
+ case SDL_PIXELFORMAT_ABGR8888:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
+ break;
+ case SDL_PIXELFORMAT_ARGB8888:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB;
+ break;
+ case SDL_PIXELFORMAT_RGB888:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
+ break;
+ }
+ break;
+ case SDL_PIXELFORMAT_IYUV:
+ case SDL_PIXELFORMAT_YV12:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_YUV;
+ break;
+ case SDL_PIXELFORMAT_NV12:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_NV12;
+ break;
+ case SDL_PIXELFORMAT_NV21:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_NV21;
+ break;
+ case SDL_PIXELFORMAT_EXTERNAL_OES:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_EXTERNAL_OES;
+ break;
+ default:
+ return SDL_SetError("Unsupported texture format");
+ }
+ } else {
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR; /* Texture formats match, use the non color mapping shader (even if the formats are not ABGR) */
+ }
+ } else {
+ switch (texture->format) {
+ case SDL_PIXELFORMAT_ARGB8888:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
+ break;
+ case SDL_PIXELFORMAT_ABGR8888:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
+ break;
+ case SDL_PIXELFORMAT_RGB888:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB;
+ break;
+ case SDL_PIXELFORMAT_BGR888:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
+ break;
+ case SDL_PIXELFORMAT_IYUV:
+ case SDL_PIXELFORMAT_YV12:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_YUV;
+ break;
+ case SDL_PIXELFORMAT_NV12:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_NV12;
+ break;
+ case SDL_PIXELFORMAT_NV21:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_NV21;
+ break;
+ case SDL_PIXELFORMAT_EXTERNAL_OES:
+ sourceType = GLES2_IMAGESOURCE_TEXTURE_EXTERNAL_OES;
+ break;
+ default:
+ return SDL_SetError("Unsupported texture format");
+ }
+ }
+
+ if (GLES2_SelectProgram(renderer, sourceType, texture->w, texture->h) < 0) {
+ return -1;
+ }
+
+ /* Select the target texture */
+ if (tdata->yuv) {
+ data->glActiveTexture(GL_TEXTURE2);
+ data->glBindTexture(tdata->texture_type, tdata->texture_v);
+
+ data->glActiveTexture(GL_TEXTURE1);
+ data->glBindTexture(tdata->texture_type, tdata->texture_u);
+
+ data->glActiveTexture(GL_TEXTURE0);
+ }
+ if (tdata->nv12) {
+ data->glActiveTexture(GL_TEXTURE1);
+ data->glBindTexture(tdata->texture_type, tdata->texture_u);
+
+ data->glActiveTexture(GL_TEXTURE0);
+ }
+ data->glBindTexture(tdata->texture_type, tdata->texture);
+
+ /* Configure color modulation */
+ g = texture->g;
+ a = texture->a;
+
+ if (renderer->target &&
+ (renderer->target->format == SDL_PIXELFORMAT_ARGB8888 ||
+ renderer->target->format == SDL_PIXELFORMAT_RGB888)) {
+ r = texture->b;
+ b = texture->r;
+ } else {
+ r = texture->r;
+ b = texture->b;
+ }
+
+ program = data->current_program;
+
+ if (!CompareColors(program->modulation_r, program->modulation_g, program->modulation_b, program->modulation_a, r, g, b, a)) {
+ data->glUniform4f(program->uniform_locations[GLES2_UNIFORM_MODULATION], r * inv255f, g * inv255f, b * inv255f, a * inv255f);
+ program->modulation_r = r;
+ program->modulation_g = g;
+ program->modulation_b = b;
+ program->modulation_a = a;
+ }
+
+ /* Configure texture blending */
+ GLES2_SetBlendMode(data, texture->blendMode);
+
+ GLES2_SetTexCoords(data, SDL_TRUE);
+ return 0;
+}
+
+static int
+GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect,
+ const SDL_FRect *dstrect)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+ GLfloat vertices[8];
+ GLfloat texCoords[8];
+
+ GLES2_ActivateRenderer(renderer);
+
+ if (GLES2_SetupCopy(renderer, texture) < 0) {
+ return -1;
+ }
+
+ /* Emit the textured quad */
+ vertices[0] = dstrect->x;
+ vertices[1] = dstrect->y;
+ vertices[2] = (dstrect->x + dstrect->w);
+ vertices[3] = dstrect->y;
+ vertices[4] = dstrect->x;
+ vertices[5] = (dstrect->y + dstrect->h);
+ vertices[6] = (dstrect->x + dstrect->w);
+ vertices[7] = (dstrect->y + dstrect->h);
+ /*data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
+ GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, 8 * sizeof(GLfloat));
+ texCoords[0] = srcrect->x / (GLfloat)texture->w;
+ texCoords[1] = srcrect->y / (GLfloat)texture->h;
+ texCoords[2] = (srcrect->x + srcrect->w) / (GLfloat)texture->w;
+ texCoords[3] = srcrect->y / (GLfloat)texture->h;
+ texCoords[4] = srcrect->x / (GLfloat)texture->w;
+ texCoords[5] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
+ texCoords[6] = (srcrect->x + srcrect->w) / (GLfloat)texture->w;
+ texCoords[7] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
+ /*data->glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords);*/
+ GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_TEXCOORD, texCoords, 8 * sizeof(GLfloat));
+ data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ return GL_CheckError("", renderer);
+}
+
+static int
+GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect,
+ const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+ GLfloat vertices[8];
+ GLfloat texCoords[8];
+ GLfloat translate[8];
+ GLfloat fAngle[4];
+ GLfloat tmp;
+
+ GLES2_ActivateRenderer(renderer);
+
+ if (GLES2_SetupCopy(renderer, texture) < 0) {
+ return -1;
+ }
+
+ data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_CENTER);
+ data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_ANGLE);
+ fAngle[0] = fAngle[1] = fAngle[2] = fAngle[3] = (GLfloat)(360.0f - angle);
+ /* Calculate the center of rotation */
+ translate[0] = translate[2] = translate[4] = translate[6] = (center->x + dstrect->x);
+ translate[1] = translate[3] = translate[5] = translate[7] = (center->y + dstrect->y);
+
+ /* Emit the textured quad */
+ vertices[0] = dstrect->x;
+ vertices[1] = dstrect->y;
+ vertices[2] = (dstrect->x + dstrect->w);
+ vertices[3] = dstrect->y;
+ vertices[4] = dstrect->x;
+ vertices[5] = (dstrect->y + dstrect->h);
+ vertices[6] = (dstrect->x + dstrect->w);
+ vertices[7] = (dstrect->y + dstrect->h);
+ if (flip & SDL_FLIP_HORIZONTAL) {
+ tmp = vertices[0];
+ vertices[0] = vertices[4] = vertices[2];
+ vertices[2] = vertices[6] = tmp;
+ }
+ if (flip & SDL_FLIP_VERTICAL) {
+ tmp = vertices[1];
+ vertices[1] = vertices[3] = vertices[5];
+ vertices[5] = vertices[7] = tmp;
+ }
+
+ /*data->glVertexAttribPointer(GLES2_ATTRIBUTE_ANGLE, 1, GL_FLOAT, GL_FALSE, 0, &fAngle);
+ data->glVertexAttribPointer(GLES2_ATTRIBUTE_CENTER, 2, GL_FLOAT, GL_FALSE, 0, translate);
+ data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
+
+ GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_ANGLE, fAngle, 4 * sizeof(GLfloat));
+ GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_CENTER, translate, 8 * sizeof(GLfloat));
+ GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, 8 * sizeof(GLfloat));
+
+ texCoords[0] = srcrect->x / (GLfloat)texture->w;
+ texCoords[1] = srcrect->y / (GLfloat)texture->h;
+ texCoords[2] = (srcrect->x + srcrect->w) / (GLfloat)texture->w;
+ texCoords[3] = srcrect->y / (GLfloat)texture->h;
+ texCoords[4] = srcrect->x / (GLfloat)texture->w;
+ texCoords[5] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
+ texCoords[6] = (srcrect->x + srcrect->w) / (GLfloat)texture->w;
+ texCoords[7] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
+ /*data->glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords);*/
+ GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_TEXCOORD, texCoords, 8 * sizeof(GLfloat));
+ data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ data->glDisableVertexAttribArray(GLES2_ATTRIBUTE_CENTER);
+ data->glDisableVertexAttribArray(GLES2_ATTRIBUTE_ANGLE);
+
+ return GL_CheckError("", renderer);
+}
+
+static int
+GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 pixel_format, void * pixels, int pitch)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+ Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888;
+ void *temp_pixels;
+ int temp_pitch;
+ Uint8 *src, *dst, *tmp;
+ int w, h, length, rows;
+ int status;
+
+ GLES2_ActivateRenderer(renderer);
+
+ temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
+ temp_pixels = SDL_malloc(rect->h * temp_pitch);
+ if (!temp_pixels) {
+ return SDL_OutOfMemory();
+ }
+
+ SDL_GetRendererOutputSize(renderer, &w, &h);
+
+ data->glReadPixels(rect->x, renderer->target ? rect->y : (h-rect->y)-rect->h,
+ rect->w, rect->h, GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels);
+ if (GL_CheckError("glReadPixels()", renderer) < 0) {
+ return -1;
+ }
+
+ /* Flip the rows to be top-down if necessary */
+ if (!renderer->target) {
+ length = rect->w * SDL_BYTESPERPIXEL(temp_format);
+ src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
+ dst = (Uint8*)temp_pixels;
+ tmp = SDL_stack_alloc(Uint8, length);
+ rows = rect->h / 2;
+ while (rows--) {
+ SDL_memcpy(tmp, dst, length);
+ SDL_memcpy(dst, src, length);
+ SDL_memcpy(src, tmp, length);
+ dst += temp_pitch;
+ src -= temp_pitch;
+ }
+ SDL_stack_free(tmp);
+ }
+
+ status = SDL_ConvertPixels(rect->w, rect->h,
+ temp_format, temp_pixels, temp_pitch,
+ pixel_format, pixels, pitch);
+ SDL_free(temp_pixels);
+
+ return status;
+}
+
+static void
+GLES2_RenderPresent(SDL_Renderer *renderer)
+{
+ GLES2_ActivateRenderer(renderer);
+
+ /* Tell the video driver to swap buffers */
+ SDL_GL_SwapWindow(renderer->window);
+}
+
+
+/*************************************************************************************************
+ * Bind/unbinding of textures
+ *************************************************************************************************/
+static int GLES2_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh);
+static int GLES2_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture);
+
+static int GLES2_BindTexture (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+ GLES2_TextureData *texturedata = (GLES2_TextureData *)texture->driverdata;
+ GLES2_ActivateRenderer(renderer);
+
+ data->glBindTexture(texturedata->texture_type, texturedata->texture);
+
+ if (texw) {
+ *texw = 1.0;
+ }
+ if (texh) {
+ *texh = 1.0;
+ }
+
+ return 0;
+}
+
+static int GLES2_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
+ GLES2_TextureData *texturedata = (GLES2_TextureData *)texture->driverdata;
+ GLES2_ActivateRenderer(renderer);
+
+ data->glBindTexture(texturedata->texture_type, 0);
+
+ return 0;
+}
+
+
+/*************************************************************************************************
+ * Renderer instantiation *
+ *************************************************************************************************/
+
+#ifdef ZUNE_HD
+#define GL_NVIDIA_PLATFORM_BINARY_NV 0x890B
+#endif
+
+static void
+GLES2_ResetState(SDL_Renderer *renderer)
+{
+ GLES2_DriverContext *data = (GLES2_DriverContext *) renderer->driverdata;
+
+ if (SDL_CurrentContext == data->context) {
+ GLES2_UpdateViewport(renderer);
+ } else {
+ GLES2_ActivateRenderer(renderer);
+ }
+
+ data->current.blendMode = SDL_BLENDMODE_INVALID;
+ data->current.tex_coords = SDL_FALSE;
+
+ data->glActiveTexture(GL_TEXTURE0);
+ data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
+ data->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+ data->glClearColor((GLfloat) data->clear_r * inv255f,
+ (GLfloat) data->clear_g * inv255f,
+ (GLfloat) data->clear_b * inv255f,
+ (GLfloat) data->clear_a * inv255f);
+
+ data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
+ data->glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
+
+ GL_CheckError("", renderer);
+}
+
+static SDL_Renderer *
+GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
+{
+ SDL_Renderer *renderer;
+ GLES2_DriverContext *data;
+ GLint nFormats;
+#ifndef ZUNE_HD
+ GLboolean hasCompiler;
+#endif
+ Uint32 window_flags = 0; /* -Wconditional-uninitialized */
+ GLint window_framebuffer;
+ GLint value;
+ int profile_mask = 0, major = 0, minor = 0;
+ SDL_bool changed_window = SDL_FALSE;
+
+ if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask) < 0) {
+ goto error;
+ }
+ if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major) < 0) {
+ goto error;
+ }
+ if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor) < 0) {
+ goto error;
+ }
+
+ window_flags = SDL_GetWindowFlags(window);
+ /* OpenGL ES 3.0 is a superset of OpenGL ES 2.0 */
+ if (!(window_flags & SDL_WINDOW_OPENGL) ||
+ profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major < RENDERER_CONTEXT_MAJOR) {
+
+ changed_window = SDL_TRUE;
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
+
+ if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
+ goto error;
+ }
+ }
+
+ /* Create the renderer struct */
+ renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(SDL_Renderer));
+ if (!renderer) {
+ SDL_OutOfMemory();
+ goto error;
+ }
+
+ data = (GLES2_DriverContext *)SDL_calloc(1, sizeof(GLES2_DriverContext));
+ if (!data) {
+ GLES2_DestroyRenderer(renderer);
+ SDL_OutOfMemory();
+ goto error;
+ }
+ renderer->info = GLES2_RenderDriver.info;
+ renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
+ renderer->driverdata = data;
+ renderer->window = window;
+
+ /* Create an OpenGL ES 2.0 context */
+ data->context = SDL_GL_CreateContext(window);
+ if (!data->context) {
+ GLES2_DestroyRenderer(renderer);
+ goto error;
+ }
+ if (SDL_GL_MakeCurrent(window, data->context) < 0) {
+ GLES2_DestroyRenderer(renderer);
+ goto error;
+ }
+
+ if (GLES2_LoadFunctions(data) < 0) {
+ GLES2_DestroyRenderer(renderer);
+ goto error;
+ }
+
+#if __WINRT__
+ /* DLudwig, 2013-11-29: ANGLE for WinRT doesn't seem to work unless VSync
+ * is turned on. Not doing so will freeze the screen's contents to that
+ * of the first drawn frame.
+ */
+ flags |= SDL_RENDERER_PRESENTVSYNC;
+#endif
+
+ if (flags & SDL_RENDERER_PRESENTVSYNC) {
+ SDL_GL_SetSwapInterval(1);
+ } else {
+ SDL_GL_SetSwapInterval(0);
+ }
+ if (SDL_GL_GetSwapInterval() > 0) {
+ renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
+ }
+
+ /* Check for debug output support */
+ if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_FLAGS, &value) == 0 &&
+ (value & SDL_GL_CONTEXT_DEBUG_FLAG)) {
+ data->debug_enabled = SDL_TRUE;
+ }
+
+ value = 0;
+ data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
+ renderer->info.max_texture_width = value;
+ value = 0;
+ data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
+ renderer->info.max_texture_height = value;
+
+ /* Determine supported shader formats */
+ /* HACK: glGetInteger is broken on the Zune HD's compositor, so we just hardcode this */
+#ifdef ZUNE_HD
+ nFormats = 1;
+#else /* !ZUNE_HD */
+ data->glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &nFormats);
+ data->glGetBooleanv(GL_SHADER_COMPILER, &hasCompiler);
+ if (hasCompiler) {
+ ++nFormats;
+ }
+#endif /* ZUNE_HD */
+ data->shader_formats = (GLenum *)SDL_calloc(nFormats, sizeof(GLenum));
+ if (!data->shader_formats) {
+ GLES2_DestroyRenderer(renderer);
+ SDL_OutOfMemory();
+ goto error;
+ }
+ data->shader_format_count = nFormats;
+#ifdef ZUNE_HD
+ data->shader_formats[0] = GL_NVIDIA_PLATFORM_BINARY_NV;
+#else /* !ZUNE_HD */
+ data->glGetIntegerv(GL_SHADER_BINARY_FORMATS, (GLint *)data->shader_formats);
+ if (hasCompiler) {
+ data->shader_formats[nFormats - 1] = (GLenum)-1;
+ }
+#endif /* ZUNE_HD */
+
+ data->framebuffers = NULL;
+ data->glGetIntegerv(GL_FRAMEBUFFER_BINDING, &window_framebuffer);
+ data->window_framebuffer = (GLuint)window_framebuffer;
+
+ /* Populate the function pointers for the module */
+ renderer->WindowEvent = GLES2_WindowEvent;
+ renderer->GetOutputSize = GLES2_GetOutputSize;
+ renderer->SupportsBlendMode = GLES2_SupportsBlendMode;
+ renderer->CreateTexture = GLES2_CreateTexture;
+ renderer->UpdateTexture = GLES2_UpdateTexture;
+ renderer->UpdateTextureYUV = GLES2_UpdateTextureYUV;
+ renderer->LockTexture = GLES2_LockTexture;
+ renderer->UnlockTexture = GLES2_UnlockTexture;
+ renderer->SetRenderTarget = GLES2_SetRenderTarget;
+ renderer->UpdateViewport = GLES2_UpdateViewport;
+ renderer->UpdateClipRect = GLES2_UpdateClipRect;
+ renderer->RenderClear = GLES2_RenderClear;
+ renderer->RenderDrawPoints = GLES2_RenderDrawPoints;
+ renderer->RenderDrawLines = GLES2_RenderDrawLines;
+ renderer->RenderFillRects = GLES2_RenderFillRects;
+ renderer->RenderCopy = GLES2_RenderCopy;
+ renderer->RenderCopyEx = GLES2_RenderCopyEx;
+ renderer->RenderReadPixels = GLES2_RenderReadPixels;
+ renderer->RenderPresent = GLES2_RenderPresent;
+ renderer->DestroyTexture = GLES2_DestroyTexture;
+ renderer->DestroyRenderer = GLES2_DestroyRenderer;
+ renderer->GL_BindTexture = GLES2_BindTexture;
+ renderer->GL_UnbindTexture = GLES2_UnbindTexture;
+
+ renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_YV12;
+ renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_IYUV;
+ renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_NV12;
+ renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_NV21;
+#ifdef GL_TEXTURE_EXTERNAL_OES
+ renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_EXTERNAL_OES;
+#endif
+
+ GLES2_ResetState(renderer);
+
+ return renderer;
+
+error:
+ if (changed_window) {
+ /* Uh oh, better try to put it back... */
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
+ SDL_RecreateWindow(window, window_flags);
+ }
+ return NULL;
+}
+
+#endif /* SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/opengles2/SDL_shaders_gles2.c b/src/3rdparty/SDL2/src/render/opengles2/SDL_shaders_gles2.c
new file mode 100644
index 0000000..b0bcdff
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/opengles2/SDL_shaders_gles2.c
@@ -0,0 +1,569 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED
+
+#include "SDL_video.h"
+#include "SDL_opengles2.h"
+#include "SDL_shaders_gles2.h"
+#include "SDL_stdinc.h"
+
+/*************************************************************************************************
+ * Vertex/fragment shader source *
+ *************************************************************************************************/
+
+static const Uint8 GLES2_VertexSrc_Default_[] = " \
+ uniform mat4 u_projection; \
+ attribute vec2 a_position; \
+ attribute vec2 a_texCoord; \
+ attribute float a_angle; \
+ attribute vec2 a_center; \
+ varying vec2 v_texCoord; \
+ \
+ void main() \
+ { \
+ float angle = radians(a_angle); \
+ float c = cos(angle); \
+ float s = sin(angle); \
+ mat2 rotationMatrix = mat2(c, -s, s, c); \
+ vec2 position = rotationMatrix * (a_position - a_center) + a_center; \
+ v_texCoord = a_texCoord; \
+ gl_Position = u_projection * vec4(position, 0.0, 1.0);\
+ gl_PointSize = 1.0; \
+ } \
+";
+
+static const Uint8 GLES2_FragmentSrc_SolidSrc_[] = " \
+ precision mediump float; \
+ uniform vec4 u_color; \
+ \
+ void main() \
+ { \
+ gl_FragColor = u_color; \
+ } \
+";
+
+static const Uint8 GLES2_FragmentSrc_TextureABGRSrc_[] = " \
+ precision mediump float; \
+ uniform sampler2D u_texture; \
+ uniform vec4 u_modulation; \
+ varying vec2 v_texCoord; \
+ \
+ void main() \
+ { \
+ gl_FragColor = texture2D(u_texture, v_texCoord); \
+ gl_FragColor *= u_modulation; \
+ } \
+";
+
+/* ARGB to ABGR conversion */
+static const Uint8 GLES2_FragmentSrc_TextureARGBSrc_[] = " \
+ precision mediump float; \
+ uniform sampler2D u_texture; \
+ uniform vec4 u_modulation; \
+ varying vec2 v_texCoord; \
+ \
+ void main() \
+ { \
+ vec4 abgr = texture2D(u_texture, v_texCoord); \
+ gl_FragColor = abgr; \
+ gl_FragColor.r = abgr.b; \
+ gl_FragColor.b = abgr.r; \
+ gl_FragColor *= u_modulation; \
+ } \
+";
+
+/* RGB to ABGR conversion */
+static const Uint8 GLES2_FragmentSrc_TextureRGBSrc_[] = " \
+ precision mediump float; \
+ uniform sampler2D u_texture; \
+ uniform vec4 u_modulation; \
+ varying vec2 v_texCoord; \
+ \
+ void main() \
+ { \
+ vec4 abgr = texture2D(u_texture, v_texCoord); \
+ gl_FragColor = abgr; \
+ gl_FragColor.r = abgr.b; \
+ gl_FragColor.b = abgr.r; \
+ gl_FragColor.a = 1.0; \
+ gl_FragColor *= u_modulation; \
+ } \
+";
+
+/* BGR to ABGR conversion */
+static const Uint8 GLES2_FragmentSrc_TextureBGRSrc_[] = " \
+ precision mediump float; \
+ uniform sampler2D u_texture; \
+ uniform vec4 u_modulation; \
+ varying vec2 v_texCoord; \
+ \
+ void main() \
+ { \
+ vec4 abgr = texture2D(u_texture, v_texCoord); \
+ gl_FragColor = abgr; \
+ gl_FragColor.a = 1.0; \
+ gl_FragColor *= u_modulation; \
+ } \
+";
+
+#define JPEG_SHADER_CONSTANTS \
+"// YUV offset \n" \
+"const vec3 offset = vec3(0, -0.501960814, -0.501960814);\n" \
+"\n" \
+"// RGB coefficients \n" \
+"const mat3 matrix = mat3( 1, 1, 1,\n" \
+" 0, -0.3441, 1.772,\n" \
+" 1.402, -0.7141, 0);\n" \
+
+#define BT601_SHADER_CONSTANTS \
+"// YUV offset \n" \
+"const vec3 offset = vec3(-0.0627451017, -0.501960814, -0.501960814);\n" \
+"\n" \
+"// RGB coefficients \n" \
+"const mat3 matrix = mat3( 1.1644, 1.1644, 1.1644,\n" \
+" 0, -0.3918, 2.0172,\n" \
+" 1.596, -0.813, 0);\n" \
+
+#define BT709_SHADER_CONSTANTS \
+"// YUV offset \n" \
+"const vec3 offset = vec3(-0.0627451017, -0.501960814, -0.501960814);\n" \
+"\n" \
+"// RGB coefficients \n" \
+"const mat3 matrix = mat3( 1.1644, 1.1644, 1.1644,\n" \
+" 0, -0.2132, 2.1124,\n" \
+" 1.7927, -0.5329, 0);\n" \
+
+
+#define YUV_SHADER_PROLOGUE \
+"precision mediump float;\n" \
+"uniform sampler2D u_texture;\n" \
+"uniform sampler2D u_texture_u;\n" \
+"uniform sampler2D u_texture_v;\n" \
+"uniform vec4 u_modulation;\n" \
+"varying vec2 v_texCoord;\n" \
+"\n" \
+
+#define YUV_SHADER_BODY \
+"\n" \
+"void main()\n" \
+"{\n" \
+" mediump vec3 yuv;\n" \
+" lowp vec3 rgb;\n" \
+"\n" \
+" // Get the YUV values \n" \
+" yuv.x = texture2D(u_texture, v_texCoord).r;\n" \
+" yuv.y = texture2D(u_texture_u, v_texCoord).r;\n" \
+" yuv.z = texture2D(u_texture_v, v_texCoord).r;\n" \
+"\n" \
+" // Do the color transform \n" \
+" yuv += offset;\n" \
+" rgb = matrix * yuv;\n" \
+"\n" \
+" // That was easy. :) \n" \
+" gl_FragColor = vec4(rgb, 1);\n" \
+" gl_FragColor *= u_modulation;\n" \
+"}" \
+
+#define NV12_SHADER_BODY \
+"\n" \
+"void main()\n" \
+"{\n" \
+" mediump vec3 yuv;\n" \
+" lowp vec3 rgb;\n" \
+"\n" \
+" // Get the YUV values \n" \
+" yuv.x = texture2D(u_texture, v_texCoord).r;\n" \
+" yuv.yz = texture2D(u_texture_u, v_texCoord).ra;\n" \
+"\n" \
+" // Do the color transform \n" \
+" yuv += offset;\n" \
+" rgb = matrix * yuv;\n" \
+"\n" \
+" // That was easy. :) \n" \
+" gl_FragColor = vec4(rgb, 1);\n" \
+" gl_FragColor *= u_modulation;\n" \
+"}" \
+
+#define NV21_SHADER_BODY \
+"\n" \
+"void main()\n" \
+"{\n" \
+" mediump vec3 yuv;\n" \
+" lowp vec3 rgb;\n" \
+"\n" \
+" // Get the YUV values \n" \
+" yuv.x = texture2D(u_texture, v_texCoord).r;\n" \
+" yuv.yz = texture2D(u_texture_u, v_texCoord).ar;\n" \
+"\n" \
+" // Do the color transform \n" \
+" yuv += offset;\n" \
+" rgb = matrix * yuv;\n" \
+"\n" \
+" // That was easy. :) \n" \
+" gl_FragColor = vec4(rgb, 1);\n" \
+" gl_FragColor *= u_modulation;\n" \
+"}" \
+
+/* YUV to ABGR conversion */
+static const Uint8 GLES2_FragmentSrc_TextureYUVJPEGSrc_[] = \
+ YUV_SHADER_PROLOGUE \
+ JPEG_SHADER_CONSTANTS \
+ YUV_SHADER_BODY \
+;
+static const Uint8 GLES2_FragmentSrc_TextureYUVBT601Src_[] = \
+ YUV_SHADER_PROLOGUE \
+ BT601_SHADER_CONSTANTS \
+ YUV_SHADER_BODY \
+;
+static const Uint8 GLES2_FragmentSrc_TextureYUVBT709Src_[] = \
+ YUV_SHADER_PROLOGUE \
+ BT709_SHADER_CONSTANTS \
+ YUV_SHADER_BODY \
+;
+
+/* NV12 to ABGR conversion */
+static const Uint8 GLES2_FragmentSrc_TextureNV12JPEGSrc_[] = \
+ YUV_SHADER_PROLOGUE \
+ JPEG_SHADER_CONSTANTS \
+ NV12_SHADER_BODY \
+;
+static const Uint8 GLES2_FragmentSrc_TextureNV12BT601Src_[] = \
+ YUV_SHADER_PROLOGUE \
+ BT601_SHADER_CONSTANTS \
+ NV12_SHADER_BODY \
+;
+static const Uint8 GLES2_FragmentSrc_TextureNV12BT709Src_[] = \
+ YUV_SHADER_PROLOGUE \
+ BT709_SHADER_CONSTANTS \
+ NV12_SHADER_BODY \
+;
+
+/* NV21 to ABGR conversion */
+static const Uint8 GLES2_FragmentSrc_TextureNV21JPEGSrc_[] = \
+ YUV_SHADER_PROLOGUE \
+ JPEG_SHADER_CONSTANTS \
+ NV21_SHADER_BODY \
+;
+static const Uint8 GLES2_FragmentSrc_TextureNV21BT601Src_[] = \
+ YUV_SHADER_PROLOGUE \
+ BT601_SHADER_CONSTANTS \
+ NV21_SHADER_BODY \
+;
+static const Uint8 GLES2_FragmentSrc_TextureNV21BT709Src_[] = \
+ YUV_SHADER_PROLOGUE \
+ BT709_SHADER_CONSTANTS \
+ NV21_SHADER_BODY \
+;
+
+/* Custom Android video format texture */
+static const Uint8 GLES2_FragmentSrc_TextureExternalOESSrc_[] = " \
+ #extension GL_OES_EGL_image_external : require\n\
+ precision mediump float; \
+ uniform samplerExternalOES u_texture; \
+ uniform vec4 u_modulation; \
+ varying vec2 v_texCoord; \
+ \
+ void main() \
+ { \
+ gl_FragColor = texture2D(u_texture, v_texCoord); \
+ gl_FragColor *= u_modulation; \
+ } \
+";
+
+static const GLES2_ShaderInstance GLES2_VertexSrc_Default = {
+ GL_VERTEX_SHADER,
+ GLES2_SOURCE_SHADER,
+ sizeof(GLES2_VertexSrc_Default_),
+ GLES2_VertexSrc_Default_
+};
+
+static const GLES2_ShaderInstance GLES2_FragmentSrc_SolidSrc = {
+ GL_FRAGMENT_SHADER,
+ GLES2_SOURCE_SHADER,
+ sizeof(GLES2_FragmentSrc_SolidSrc_),
+ GLES2_FragmentSrc_SolidSrc_
+};
+
+static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureABGRSrc = {
+ GL_FRAGMENT_SHADER,
+ GLES2_SOURCE_SHADER,
+ sizeof(GLES2_FragmentSrc_TextureABGRSrc_),
+ GLES2_FragmentSrc_TextureABGRSrc_
+};
+
+static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureARGBSrc = {
+ GL_FRAGMENT_SHADER,
+ GLES2_SOURCE_SHADER,
+ sizeof(GLES2_FragmentSrc_TextureARGBSrc_),
+ GLES2_FragmentSrc_TextureARGBSrc_
+};
+
+static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureRGBSrc = {
+ GL_FRAGMENT_SHADER,
+ GLES2_SOURCE_SHADER,
+ sizeof(GLES2_FragmentSrc_TextureRGBSrc_),
+ GLES2_FragmentSrc_TextureRGBSrc_
+};
+
+static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureBGRSrc = {
+ GL_FRAGMENT_SHADER,
+ GLES2_SOURCE_SHADER,
+ sizeof(GLES2_FragmentSrc_TextureBGRSrc_),
+ GLES2_FragmentSrc_TextureBGRSrc_
+};
+
+static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureYUVJPEGSrc = {
+ GL_FRAGMENT_SHADER,
+ GLES2_SOURCE_SHADER,
+ sizeof(GLES2_FragmentSrc_TextureYUVJPEGSrc_),
+ GLES2_FragmentSrc_TextureYUVJPEGSrc_
+};
+
+static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureYUVBT601Src = {
+ GL_FRAGMENT_SHADER,
+ GLES2_SOURCE_SHADER,
+ sizeof(GLES2_FragmentSrc_TextureYUVBT601Src_),
+ GLES2_FragmentSrc_TextureYUVBT601Src_
+};
+
+static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureYUVBT709Src = {
+ GL_FRAGMENT_SHADER,
+ GLES2_SOURCE_SHADER,
+ sizeof(GLES2_FragmentSrc_TextureYUVBT709Src_),
+ GLES2_FragmentSrc_TextureYUVBT709Src_
+};
+
+static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureNV12JPEGSrc = {
+ GL_FRAGMENT_SHADER,
+ GLES2_SOURCE_SHADER,
+ sizeof(GLES2_FragmentSrc_TextureNV12JPEGSrc_),
+ GLES2_FragmentSrc_TextureNV12JPEGSrc_
+};
+
+static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureNV12BT601Src = {
+ GL_FRAGMENT_SHADER,
+ GLES2_SOURCE_SHADER,
+ sizeof(GLES2_FragmentSrc_TextureNV12BT601Src_),
+ GLES2_FragmentSrc_TextureNV12BT601Src_
+};
+
+static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureNV21BT709Src = {
+ GL_FRAGMENT_SHADER,
+ GLES2_SOURCE_SHADER,
+ sizeof(GLES2_FragmentSrc_TextureNV21BT709Src_),
+ GLES2_FragmentSrc_TextureNV21BT709Src_
+};
+
+static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureNV21JPEGSrc = {
+ GL_FRAGMENT_SHADER,
+ GLES2_SOURCE_SHADER,
+ sizeof(GLES2_FragmentSrc_TextureNV21JPEGSrc_),
+ GLES2_FragmentSrc_TextureNV21JPEGSrc_
+};
+
+static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureNV21BT601Src = {
+ GL_FRAGMENT_SHADER,
+ GLES2_SOURCE_SHADER,
+ sizeof(GLES2_FragmentSrc_TextureNV21BT601Src_),
+ GLES2_FragmentSrc_TextureNV21BT601Src_
+};
+
+static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureNV12BT709Src = {
+ GL_FRAGMENT_SHADER,
+ GLES2_SOURCE_SHADER,
+ sizeof(GLES2_FragmentSrc_TextureNV12BT709Src_),
+ GLES2_FragmentSrc_TextureNV12BT709Src_
+};
+
+static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureExternalOESSrc = {
+ GL_FRAGMENT_SHADER,
+ GLES2_SOURCE_SHADER,
+ sizeof(GLES2_FragmentSrc_TextureExternalOESSrc_),
+ GLES2_FragmentSrc_TextureExternalOESSrc_
+};
+
+
+/*************************************************************************************************
+ * Vertex/fragment shader definitions *
+ *************************************************************************************************/
+
+static GLES2_Shader GLES2_VertexShader_Default = {
+ 1,
+ {
+ &GLES2_VertexSrc_Default
+ }
+};
+
+static GLES2_Shader GLES2_FragmentShader_SolidSrc = {
+ 1,
+ {
+ &GLES2_FragmentSrc_SolidSrc
+ }
+};
+
+static GLES2_Shader GLES2_FragmentShader_TextureABGRSrc = {
+ 1,
+ {
+ &GLES2_FragmentSrc_TextureABGRSrc
+ }
+};
+
+static GLES2_Shader GLES2_FragmentShader_TextureARGBSrc = {
+ 1,
+ {
+ &GLES2_FragmentSrc_TextureARGBSrc
+ }
+};
+
+static GLES2_Shader GLES2_FragmentShader_TextureRGBSrc = {
+ 1,
+ {
+ &GLES2_FragmentSrc_TextureRGBSrc
+ }
+};
+
+static GLES2_Shader GLES2_FragmentShader_TextureBGRSrc = {
+ 1,
+ {
+ &GLES2_FragmentSrc_TextureBGRSrc
+ }
+};
+
+static GLES2_Shader GLES2_FragmentShader_TextureYUVJPEGSrc = {
+ 1,
+ {
+ &GLES2_FragmentSrc_TextureYUVJPEGSrc
+ }
+};
+
+static GLES2_Shader GLES2_FragmentShader_TextureYUVBT601Src = {
+ 1,
+ {
+ &GLES2_FragmentSrc_TextureYUVBT601Src
+ }
+};
+
+static GLES2_Shader GLES2_FragmentShader_TextureYUVBT709Src = {
+ 1,
+ {
+ &GLES2_FragmentSrc_TextureYUVBT709Src
+ }
+};
+
+static GLES2_Shader GLES2_FragmentShader_TextureNV12JPEGSrc = {
+ 1,
+ {
+ &GLES2_FragmentSrc_TextureNV12JPEGSrc
+ }
+};
+
+static GLES2_Shader GLES2_FragmentShader_TextureNV12BT601Src = {
+ 1,
+ {
+ &GLES2_FragmentSrc_TextureNV12BT601Src
+ }
+};
+
+static GLES2_Shader GLES2_FragmentShader_TextureNV12BT709Src = {
+ 1,
+ {
+ &GLES2_FragmentSrc_TextureNV12BT709Src
+ }
+};
+
+static GLES2_Shader GLES2_FragmentShader_TextureNV21JPEGSrc = {
+ 1,
+ {
+ &GLES2_FragmentSrc_TextureNV21JPEGSrc
+ }
+};
+
+static GLES2_Shader GLES2_FragmentShader_TextureNV21BT601Src = {
+ 1,
+ {
+ &GLES2_FragmentSrc_TextureNV21BT601Src
+ }
+};
+
+static GLES2_Shader GLES2_FragmentShader_TextureNV21BT709Src = {
+ 1,
+ {
+ &GLES2_FragmentSrc_TextureNV21BT709Src
+ }
+};
+
+static GLES2_Shader GLES2_FragmentShader_TextureExternalOESSrc = {
+ 1,
+ {
+ &GLES2_FragmentSrc_TextureExternalOESSrc
+ }
+};
+
+
+/*************************************************************************************************
+ * Shader selector *
+ *************************************************************************************************/
+
+const GLES2_Shader *GLES2_GetShader(GLES2_ShaderType type)
+{
+ switch (type) {
+ case GLES2_SHADER_VERTEX_DEFAULT:
+ return &GLES2_VertexShader_Default;
+ case GLES2_SHADER_FRAGMENT_SOLID_SRC:
+ return &GLES2_FragmentShader_SolidSrc;
+ case GLES2_SHADER_FRAGMENT_TEXTURE_ABGR_SRC:
+ return &GLES2_FragmentShader_TextureABGRSrc;
+ case GLES2_SHADER_FRAGMENT_TEXTURE_ARGB_SRC:
+ return &GLES2_FragmentShader_TextureARGBSrc;
+ case GLES2_SHADER_FRAGMENT_TEXTURE_RGB_SRC:
+ return &GLES2_FragmentShader_TextureRGBSrc;
+ case GLES2_SHADER_FRAGMENT_TEXTURE_BGR_SRC:
+ return &GLES2_FragmentShader_TextureBGRSrc;
+ case GLES2_SHADER_FRAGMENT_TEXTURE_YUV_JPEG_SRC:
+ return &GLES2_FragmentShader_TextureYUVJPEGSrc;
+ case GLES2_SHADER_FRAGMENT_TEXTURE_YUV_BT601_SRC:
+ return &GLES2_FragmentShader_TextureYUVBT601Src;
+ case GLES2_SHADER_FRAGMENT_TEXTURE_YUV_BT709_SRC:
+ return &GLES2_FragmentShader_TextureYUVBT709Src;
+ case GLES2_SHADER_FRAGMENT_TEXTURE_NV12_JPEG_SRC:
+ return &GLES2_FragmentShader_TextureNV12JPEGSrc;
+ case GLES2_SHADER_FRAGMENT_TEXTURE_NV12_BT601_SRC:
+ return &GLES2_FragmentShader_TextureNV12BT601Src;
+ case GLES2_SHADER_FRAGMENT_TEXTURE_NV12_BT709_SRC:
+ return &GLES2_FragmentShader_TextureNV12BT709Src;
+ case GLES2_SHADER_FRAGMENT_TEXTURE_NV21_JPEG_SRC:
+ return &GLES2_FragmentShader_TextureNV21JPEGSrc;
+ case GLES2_SHADER_FRAGMENT_TEXTURE_NV21_BT601_SRC:
+ return &GLES2_FragmentShader_TextureNV21BT601Src;
+ case GLES2_SHADER_FRAGMENT_TEXTURE_NV21_BT709_SRC:
+ return &GLES2_FragmentShader_TextureNV21BT709Src;
+ case GLES2_SHADER_FRAGMENT_TEXTURE_EXTERNAL_OES_SRC:
+ return &GLES2_FragmentShader_TextureExternalOESSrc;
+ default:
+ return NULL;
+ }
+}
+
+#endif /* SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/opengles2/SDL_shaders_gles2.h b/src/3rdparty/SDL2/src/render/opengles2/SDL_shaders_gles2.h
new file mode 100644
index 0000000..c16ce12
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/opengles2/SDL_shaders_gles2.h
@@ -0,0 +1,70 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_shaders_gles2_h_
+#define SDL_shaders_gles2_h_
+
+#if SDL_VIDEO_RENDER_OGL_ES2
+
+typedef struct GLES2_ShaderInstance
+{
+ GLenum type;
+ GLenum format;
+ int length;
+ const void *data;
+} GLES2_ShaderInstance;
+
+typedef struct GLES2_Shader
+{
+ int instance_count;
+ const GLES2_ShaderInstance *instances[4];
+} GLES2_Shader;
+
+typedef enum
+{
+ GLES2_SHADER_VERTEX_DEFAULT,
+ GLES2_SHADER_FRAGMENT_SOLID_SRC,
+ GLES2_SHADER_FRAGMENT_TEXTURE_ABGR_SRC,
+ GLES2_SHADER_FRAGMENT_TEXTURE_ARGB_SRC,
+ GLES2_SHADER_FRAGMENT_TEXTURE_BGR_SRC,
+ GLES2_SHADER_FRAGMENT_TEXTURE_RGB_SRC,
+ GLES2_SHADER_FRAGMENT_TEXTURE_YUV_JPEG_SRC,
+ GLES2_SHADER_FRAGMENT_TEXTURE_YUV_BT601_SRC,
+ GLES2_SHADER_FRAGMENT_TEXTURE_YUV_BT709_SRC,
+ GLES2_SHADER_FRAGMENT_TEXTURE_NV12_JPEG_SRC,
+ GLES2_SHADER_FRAGMENT_TEXTURE_NV12_BT601_SRC,
+ GLES2_SHADER_FRAGMENT_TEXTURE_NV12_BT709_SRC,
+ GLES2_SHADER_FRAGMENT_TEXTURE_NV21_JPEG_SRC,
+ GLES2_SHADER_FRAGMENT_TEXTURE_NV21_BT601_SRC,
+ GLES2_SHADER_FRAGMENT_TEXTURE_NV21_BT709_SRC,
+ GLES2_SHADER_FRAGMENT_TEXTURE_EXTERNAL_OES_SRC
+} GLES2_ShaderType;
+
+#define GLES2_SOURCE_SHADER (GLenum)-1
+
+const GLES2_Shader *GLES2_GetShader(GLES2_ShaderType type);
+
+#endif /* SDL_VIDEO_RENDER_OGL_ES2 */
+
+#endif /* SDL_shaders_gles2_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/psp/SDL_render_psp.c b/src/3rdparty/SDL2/src/render/psp/SDL_render_psp.c
new file mode 100644
index 0000000..38f893e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/psp/SDL_render_psp.c
@@ -0,0 +1,1028 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_RENDER_PSP
+
+#include "SDL_hints.h"
+#include "../SDL_sysrender.h"
+
+#include <pspkernel.h>
+#include <pspdisplay.h>
+#include <pspgu.h>
+#include <pspgum.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <pspge.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <vram.h>
+
+
+
+
+/* PSP renderer implementation, based on the PGE */
+
+
+extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
+
+
+static SDL_Renderer *PSP_CreateRenderer(SDL_Window * window, Uint32 flags);
+static void PSP_WindowEvent(SDL_Renderer * renderer,
+ const SDL_WindowEvent *event);
+static int PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+static int PSP_SetTextureColorMod(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static int PSP_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, const void *pixels,
+ int pitch);
+static int PSP_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, void **pixels, int *pitch);
+static void PSP_UnlockTexture(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static int PSP_SetRenderTarget(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static int PSP_UpdateViewport(SDL_Renderer * renderer);
+static int PSP_RenderClear(SDL_Renderer * renderer);
+static int PSP_RenderDrawPoints(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count);
+static int PSP_RenderDrawLines(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count);
+static int PSP_RenderFillRects(SDL_Renderer * renderer,
+ const SDL_FRect * rects, int count);
+static int PSP_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect,
+ const SDL_FRect * dstrect);
+static int PSP_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 pixel_format, void * pixels, int pitch);
+static int PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect,
+ const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip);
+static void PSP_RenderPresent(SDL_Renderer * renderer);
+static void PSP_DestroyTexture(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static void PSP_DestroyRenderer(SDL_Renderer * renderer);
+
+/*
+SDL_RenderDriver PSP_RenderDriver = {
+ PSP_CreateRenderer,
+ {
+ "PSP",
+ (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
+ 1,
+ {SDL_PIXELFORMAT_ABGR8888},
+ 0,
+ 0}
+};
+*/
+SDL_RenderDriver PSP_RenderDriver = {
+ .CreateRenderer = PSP_CreateRenderer,
+ .info = {
+ .name = "PSP",
+ .flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE,
+ .num_texture_formats = 4,
+ .texture_formats = { [0] = SDL_PIXELFORMAT_BGR565,
+ [1] = SDL_PIXELFORMAT_ABGR1555,
+ [2] = SDL_PIXELFORMAT_ABGR4444,
+ [3] = SDL_PIXELFORMAT_ABGR8888,
+ },
+ .max_texture_width = 512,
+ .max_texture_height = 512,
+ }
+};
+
+#define PSP_SCREEN_WIDTH 480
+#define PSP_SCREEN_HEIGHT 272
+
+#define PSP_FRAME_BUFFER_WIDTH 512
+#define PSP_FRAME_BUFFER_SIZE (PSP_FRAME_BUFFER_WIDTH*PSP_SCREEN_HEIGHT)
+
+static unsigned int __attribute__((aligned(16))) DisplayList[262144];
+
+
+#define COL5650(r,g,b,a) ((r>>3) | ((g>>2)<<5) | ((b>>3)<<11))
+#define COL5551(r,g,b,a) ((r>>3) | ((g>>3)<<5) | ((b>>3)<<10) | (a>0?0x7000:0))
+#define COL4444(r,g,b,a) ((r>>4) | ((g>>4)<<4) | ((b>>4)<<8) | ((a>>4)<<12))
+#define COL8888(r,g,b,a) ((r) | ((g)<<8) | ((b)<<16) | ((a)<<24))
+
+
+typedef struct
+{
+ void* frontbuffer ;
+ void* backbuffer ;
+ SDL_bool initialized ;
+ SDL_bool displayListAvail ;
+ unsigned int psm ;
+ unsigned int bpp ;
+
+ SDL_bool vsync;
+ unsigned int currentColor;
+ int currentBlendMode;
+
+} PSP_RenderData;
+
+
+typedef struct
+{
+ void *data; /**< Image data. */
+ unsigned int size; /**< Size of data in bytes. */
+ unsigned int width; /**< Image width. */
+ unsigned int height; /**< Image height. */
+ unsigned int textureWidth; /**< Texture width (power of two). */
+ unsigned int textureHeight; /**< Texture height (power of two). */
+ unsigned int bits; /**< Image bits per pixel. */
+ unsigned int format; /**< Image format - one of ::pgePixelFormat. */
+ unsigned int pitch;
+ SDL_bool swizzled; /**< Is image swizzled. */
+
+} PSP_TextureData;
+
+typedef struct
+{
+ float x, y, z;
+} VertV;
+
+
+typedef struct
+{
+ float u, v;
+ float x, y, z;
+
+} VertTV;
+
+
+/* Return next power of 2 */
+static int
+TextureNextPow2(unsigned int w)
+{
+ if(w == 0)
+ return 0;
+
+ unsigned int n = 2;
+
+ while(w > n)
+ n <<= 1;
+
+ return n;
+}
+
+
+static int
+GetScaleQuality(void)
+{
+ const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
+
+ if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
+ return GU_NEAREST; /* GU_NEAREST good for tile-map */
+ } else {
+ return GU_LINEAR; /* GU_LINEAR good for scaling */
+ }
+}
+
+static int
+PixelFormatToPSPFMT(Uint32 format)
+{
+ switch (format) {
+ case SDL_PIXELFORMAT_BGR565:
+ return GU_PSM_5650;
+ case SDL_PIXELFORMAT_ABGR1555:
+ return GU_PSM_5551;
+ case SDL_PIXELFORMAT_ABGR4444:
+ return GU_PSM_4444;
+ case SDL_PIXELFORMAT_ABGR8888:
+ return GU_PSM_8888;
+ default:
+ return GU_PSM_8888;
+ }
+}
+
+void
+StartDrawing(SDL_Renderer * renderer)
+{
+ PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
+ if(data->displayListAvail)
+ return;
+
+ sceGuStart(GU_DIRECT, DisplayList);
+ data->displayListAvail = SDL_TRUE;
+}
+
+
+int
+TextureSwizzle(PSP_TextureData *psp_texture)
+{
+ if(psp_texture->swizzled)
+ return 1;
+
+ int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
+ int height = psp_texture->size / bytewidth;
+
+ int rowblocks = (bytewidth>>4);
+ int rowblocksadd = (rowblocks-1)<<7;
+ unsigned int blockaddress = 0;
+ unsigned int *src = (unsigned int*) psp_texture->data;
+
+ unsigned char *data = NULL;
+ data = malloc(psp_texture->size);
+
+ int j;
+
+ for(j = 0; j < height; j++, blockaddress += 16)
+ {
+ unsigned int *block;
+
+ block = (unsigned int*)&data[blockaddress];
+
+ int i;
+
+ for(i = 0; i < rowblocks; i++)
+ {
+ *block++ = *src++;
+ *block++ = *src++;
+ *block++ = *src++;
+ *block++ = *src++;
+ block += 28;
+ }
+
+ if((j & 0x7) == 0x7)
+ blockaddress += rowblocksadd;
+ }
+
+ free(psp_texture->data);
+ psp_texture->data = data;
+ psp_texture->swizzled = SDL_TRUE;
+
+ return 1;
+}
+int TextureUnswizzle(PSP_TextureData *psp_texture)
+{
+ if(!psp_texture->swizzled)
+ return 1;
+
+ int blockx, blocky;
+
+ int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
+ int height = psp_texture->size / bytewidth;
+
+ int widthblocks = bytewidth/16;
+ int heightblocks = height/8;
+
+ int dstpitch = (bytewidth - 16)/4;
+ int dstrow = bytewidth * 8;
+
+ unsigned int *src = (unsigned int*) psp_texture->data;
+
+ unsigned char *data = NULL;
+
+ data = malloc(psp_texture->size);
+
+ if(!data)
+ return 0;
+
+ sceKernelDcacheWritebackAll();
+
+ int j;
+
+ unsigned char *ydst = (unsigned char *)data;
+
+ for(blocky = 0; blocky < heightblocks; ++blocky)
+ {
+ unsigned char *xdst = ydst;
+
+ for(blockx = 0; blockx < widthblocks; ++blockx)
+ {
+ unsigned int *block;
+
+ block = (unsigned int*)xdst;
+
+ for(j = 0; j < 8; ++j)
+ {
+ *(block++) = *(src++);
+ *(block++) = *(src++);
+ *(block++) = *(src++);
+ *(block++) = *(src++);
+ block += dstpitch;
+ }
+
+ xdst += 16;
+ }
+
+ ydst += dstrow;
+ }
+
+ free(psp_texture->data);
+
+ psp_texture->data = data;
+
+ psp_texture->swizzled = SDL_FALSE;
+
+ return 1;
+}
+
+SDL_Renderer *
+PSP_CreateRenderer(SDL_Window * window, Uint32 flags)
+{
+
+ SDL_Renderer *renderer;
+ PSP_RenderData *data;
+ int pixelformat;
+ renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
+ if (!renderer) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ data = (PSP_RenderData *) SDL_calloc(1, sizeof(*data));
+ if (!data) {
+ PSP_DestroyRenderer(renderer);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+
+ renderer->WindowEvent = PSP_WindowEvent;
+ renderer->CreateTexture = PSP_CreateTexture;
+ renderer->SetTextureColorMod = PSP_SetTextureColorMod;
+ renderer->UpdateTexture = PSP_UpdateTexture;
+ renderer->LockTexture = PSP_LockTexture;
+ renderer->UnlockTexture = PSP_UnlockTexture;
+ renderer->SetRenderTarget = PSP_SetRenderTarget;
+ renderer->UpdateViewport = PSP_UpdateViewport;
+ renderer->RenderClear = PSP_RenderClear;
+ renderer->RenderDrawPoints = PSP_RenderDrawPoints;
+ renderer->RenderDrawLines = PSP_RenderDrawLines;
+ renderer->RenderFillRects = PSP_RenderFillRects;
+ renderer->RenderCopy = PSP_RenderCopy;
+ renderer->RenderReadPixels = PSP_RenderReadPixels;
+ renderer->RenderCopyEx = PSP_RenderCopyEx;
+ renderer->RenderPresent = PSP_RenderPresent;
+ renderer->DestroyTexture = PSP_DestroyTexture;
+ renderer->DestroyRenderer = PSP_DestroyRenderer;
+ renderer->info = PSP_RenderDriver.info;
+ renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
+ renderer->driverdata = data;
+ renderer->window = window;
+
+ if (data->initialized != SDL_FALSE)
+ return 0;
+ data->initialized = SDL_TRUE;
+
+ if (flags & SDL_RENDERER_PRESENTVSYNC) {
+ data->vsync = SDL_TRUE;
+ } else {
+ data->vsync = SDL_FALSE;
+ }
+
+ pixelformat=PixelFormatToPSPFMT(SDL_GetWindowPixelFormat(window));
+ switch(pixelformat)
+ {
+ case GU_PSM_4444:
+ case GU_PSM_5650:
+ case GU_PSM_5551:
+ data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<1);
+ data->backbuffer = (unsigned int *)(0);
+ data->bpp = 2;
+ data->psm = pixelformat;
+ break;
+ default:
+ data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<2);
+ data->backbuffer = (unsigned int *)(0);
+ data->bpp = 4;
+ data->psm = GU_PSM_8888;
+ break;
+ }
+
+ sceGuInit();
+ /* setup GU */
+ sceGuStart(GU_DIRECT, DisplayList);
+ sceGuDrawBuffer(data->psm, data->frontbuffer, PSP_FRAME_BUFFER_WIDTH);
+ sceGuDispBuffer(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, data->backbuffer, PSP_FRAME_BUFFER_WIDTH);
+
+
+ sceGuOffset(2048 - (PSP_SCREEN_WIDTH>>1), 2048 - (PSP_SCREEN_HEIGHT>>1));
+ sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
+
+ data->frontbuffer = vabsptr(data->frontbuffer);
+ data->backbuffer = vabsptr(data->backbuffer);
+
+ /* Scissoring */
+ sceGuScissor(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
+ sceGuEnable(GU_SCISSOR_TEST);
+
+ /* Backface culling */
+ sceGuFrontFace(GU_CCW);
+ sceGuEnable(GU_CULL_FACE);
+
+ /* Texturing */
+ sceGuEnable(GU_TEXTURE_2D);
+ sceGuShadeModel(GU_SMOOTH);
+ sceGuTexWrap(GU_REPEAT, GU_REPEAT);
+
+ /* Blending */
+ sceGuEnable(GU_BLEND);
+ sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
+
+ sceGuTexFilter(GU_LINEAR,GU_LINEAR);
+
+ sceGuFinish();
+ sceGuSync(0,0);
+ sceDisplayWaitVblankStartCB();
+ sceGuDisplay(GU_TRUE);
+
+ return renderer;
+}
+
+static void
+PSP_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
+{
+
+}
+
+
+static int
+PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+/* PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata; */
+ PSP_TextureData* psp_texture = (PSP_TextureData*) SDL_calloc(1, sizeof(*psp_texture));
+
+ if(!psp_texture)
+ return -1;
+
+ psp_texture->swizzled = SDL_FALSE;
+ psp_texture->width = texture->w;
+ psp_texture->height = texture->h;
+ psp_texture->textureHeight = TextureNextPow2(texture->h);
+ psp_texture->textureWidth = TextureNextPow2(texture->w);
+ psp_texture->format = PixelFormatToPSPFMT(texture->format);
+
+ switch(psp_texture->format)
+ {
+ case GU_PSM_5650:
+ case GU_PSM_5551:
+ case GU_PSM_4444:
+ psp_texture->bits = 16;
+ break;
+
+ case GU_PSM_8888:
+ psp_texture->bits = 32;
+ break;
+
+ default:
+ return -1;
+ }
+
+ psp_texture->pitch = psp_texture->textureWidth * SDL_BYTESPERPIXEL(texture->format);
+ psp_texture->size = psp_texture->textureHeight*psp_texture->pitch;
+ psp_texture->data = SDL_calloc(1, psp_texture->size);
+
+ if(!psp_texture->data)
+ {
+ SDL_free(psp_texture);
+ return SDL_OutOfMemory();
+ }
+ texture->driverdata = psp_texture;
+
+ return 0;
+}
+
+static int
+PSP_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ return SDL_Unsupported();
+}
+
+void
+TextureActivate(SDL_Texture * texture)
+{
+ PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
+ int scaleMode = GetScaleQuality();
+
+ /* Swizzling is useless with small textures. */
+ if (texture->w >= 16 || texture->h >= 16)
+ {
+ TextureSwizzle(psp_texture);
+ }
+
+ sceGuEnable(GU_TEXTURE_2D);
+ sceGuTexWrap(GU_REPEAT, GU_REPEAT);
+ sceGuTexMode(psp_texture->format, 0, 0, psp_texture->swizzled);
+ sceGuTexFilter(scaleMode, scaleMode); /* GU_NEAREST good for tile-map */
+ /* GU_LINEAR good for scaling */
+ sceGuTexImage(0, psp_texture->textureWidth, psp_texture->textureHeight, psp_texture->textureWidth, psp_texture->data);
+ sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
+}
+
+
+static int
+PSP_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, const void *pixels, int pitch)
+{
+/* PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; */
+ const Uint8 *src;
+ Uint8 *dst;
+ int row, length,dpitch;
+ src = pixels;
+
+ PSP_LockTexture(renderer, texture,rect,(void **)&dst, &dpitch);
+ length = rect->w * SDL_BYTESPERPIXEL(texture->format);
+ if (length == pitch && length == dpitch) {
+ SDL_memcpy(dst, src, length*rect->h);
+ } else {
+ for (row = 0; row < rect->h; ++row) {
+ SDL_memcpy(dst, src, length);
+ src += pitch;
+ dst += dpitch;
+ }
+ }
+
+ sceKernelDcacheWritebackAll();
+ return 0;
+}
+
+static int
+PSP_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, void **pixels, int *pitch)
+{
+ PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
+
+ *pixels =
+ (void *) ((Uint8 *) psp_texture->data + rect->y * psp_texture->pitch +
+ rect->x * SDL_BYTESPERPIXEL(texture->format));
+ *pitch = psp_texture->pitch;
+ return 0;
+}
+
+static void
+PSP_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
+ SDL_Rect rect;
+
+ /* We do whole texture updates, at least for now */
+ rect.x = 0;
+ rect.y = 0;
+ rect.w = texture->w;
+ rect.h = texture->h;
+ PSP_UpdateTexture(renderer, texture, &rect, psp_texture->data, psp_texture->pitch);
+}
+
+static int
+PSP_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+
+ return 0;
+}
+
+static int
+PSP_UpdateViewport(SDL_Renderer * renderer)
+{
+
+ return 0;
+}
+
+
+static void
+PSP_SetBlendMode(SDL_Renderer * renderer, int blendMode)
+{
+ PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
+ if (blendMode != data-> currentBlendMode) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_NONE:
+ sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
+ sceGuDisable(GU_BLEND);
+ break;
+ case SDL_BLENDMODE_BLEND:
+ sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
+ sceGuEnable(GU_BLEND);
+ sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0 );
+ break;
+ case SDL_BLENDMODE_ADD:
+ sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
+ sceGuEnable(GU_BLEND);
+ sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_FIX, 0, 0x00FFFFFF );
+ break;
+ case SDL_BLENDMODE_MOD:
+ sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
+ sceGuEnable(GU_BLEND);
+ sceGuBlendFunc( GU_ADD, GU_FIX, GU_SRC_COLOR, 0, 0);
+ break;
+ }
+ data->currentBlendMode = blendMode;
+ }
+}
+
+
+
+static int
+PSP_RenderClear(SDL_Renderer * renderer)
+{
+ /* start list */
+ StartDrawing(renderer);
+ int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
+ sceGuClearColor(color);
+ sceGuClearDepth(0);
+ sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT|GU_FAST_CLEAR_BIT);
+
+ return 0;
+}
+
+static int
+PSP_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points,
+ int count)
+{
+ int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
+ int i;
+ StartDrawing(renderer);
+ VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV));
+
+ for (i = 0; i < count; ++i) {
+ vertices[i].x = points[i].x;
+ vertices[i].y = points[i].y;
+ vertices[i].z = 0.0f;
+ }
+ sceGuDisable(GU_TEXTURE_2D);
+ sceGuColor(color);
+ sceGuShadeModel(GU_FLAT);
+ sceGuDrawArray(GU_POINTS, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, vertices);
+ sceGuShadeModel(GU_SMOOTH);
+ sceGuEnable(GU_TEXTURE_2D);
+
+ return 0;
+}
+
+static int
+PSP_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points,
+ int count)
+{
+ int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
+ int i;
+ StartDrawing(renderer);
+ VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV));
+
+ for (i = 0; i < count; ++i) {
+ vertices[i].x = points[i].x;
+ vertices[i].y = points[i].y;
+ vertices[i].z = 0.0f;
+ }
+
+ sceGuDisable(GU_TEXTURE_2D);
+ sceGuColor(color);
+ sceGuShadeModel(GU_FLAT);
+ sceGuDrawArray(GU_LINE_STRIP, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, vertices);
+ sceGuShadeModel(GU_SMOOTH);
+ sceGuEnable(GU_TEXTURE_2D);
+
+ return 0;
+}
+
+static int
+PSP_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects,
+ int count)
+{
+ int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
+ int i;
+ StartDrawing(renderer);
+
+ for (i = 0; i < count; ++i) {
+ const SDL_FRect *rect = &rects[i];
+ VertV* vertices = (VertV*)sceGuGetMemory((sizeof(VertV)<<1));
+ vertices[0].x = rect->x;
+ vertices[0].y = rect->y;
+ vertices[0].z = 0.0f;
+
+ vertices[1].x = rect->x + rect->w;
+ vertices[1].y = rect->y + rect->h;
+ vertices[1].z = 0.0f;
+
+ sceGuDisable(GU_TEXTURE_2D);
+ sceGuColor(color);
+ sceGuShadeModel(GU_FLAT);
+ sceGuDrawArray(GU_SPRITES, GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
+ sceGuShadeModel(GU_SMOOTH);
+ sceGuEnable(GU_TEXTURE_2D);
+ }
+
+ return 0;
+}
+
+
+#define PI 3.14159265358979f
+
+#define radToDeg(x) ((x)*180.f/PI)
+#define degToRad(x) ((x)*PI/180.f)
+
+float MathAbs(float x)
+{
+ float result;
+
+ __asm__ volatile (
+ "mtv %1, S000\n"
+ "vabs.s S000, S000\n"
+ "mfv %0, S000\n"
+ : "=r"(result) : "r"(x));
+
+ return result;
+}
+
+void MathSincos(float r, float *s, float *c)
+{
+ __asm__ volatile (
+ "mtv %2, S002\n"
+ "vcst.s S003, VFPU_2_PI\n"
+ "vmul.s S002, S002, S003\n"
+ "vrot.p C000, S002, [s, c]\n"
+ "mfv %0, S000\n"
+ "mfv %1, S001\n"
+ : "=r"(*s), "=r"(*c): "r"(r));
+}
+
+void Swap(float *a, float *b)
+{
+ float n=*a;
+ *a = *b;
+ *b = n;
+}
+
+static int
+PSP_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect)
+{
+ float x, y, width, height;
+ float u0, v0, u1, v1;
+ unsigned char alpha;
+
+ x = dstrect->x;
+ y = dstrect->y;
+ width = dstrect->w;
+ height = dstrect->h;
+
+ u0 = srcrect->x;
+ v0 = srcrect->y;
+ u1 = srcrect->x + srcrect->w;
+ v1 = srcrect->y + srcrect->h;
+
+ alpha = texture->a;
+
+ StartDrawing(renderer);
+ TextureActivate(texture);
+ PSP_SetBlendMode(renderer, renderer->blendMode);
+
+ if(alpha != 255)
+ {
+ sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
+ sceGuColor(GU_RGBA(255, 255, 255, alpha));
+ }else{
+ sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
+ sceGuColor(0xFFFFFFFF);
+ }
+
+ if((MathAbs(u1) - MathAbs(u0)) < 64.0f)
+ {
+ VertTV* vertices = (VertTV*)sceGuGetMemory((sizeof(VertTV))<<1);
+
+ vertices[0].u = u0;
+ vertices[0].v = v0;
+ vertices[0].x = x;
+ vertices[0].y = y;
+ vertices[0].z = 0;
+
+ vertices[1].u = u1;
+ vertices[1].v = v1;
+ vertices[1].x = x + width;
+ vertices[1].y = y + height;
+ vertices[1].z = 0;
+
+ sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
+ }
+ else
+ {
+ float start, end;
+ float curU = u0;
+ float curX = x;
+ float endX = x + width;
+ float slice = 64.0f;
+ float ustep = (u1 - u0)/width * slice;
+
+ if(ustep < 0.0f)
+ ustep = -ustep;
+
+ for(start = 0, end = width; start < end; start += slice)
+ {
+ VertTV* vertices = (VertTV*)sceGuGetMemory((sizeof(VertTV))<<1);
+
+ float polyWidth = ((curX + slice) > endX) ? (endX - curX) : slice;
+ float sourceWidth = ((curU + ustep) > u1) ? (u1 - curU) : ustep;
+
+ vertices[0].u = curU;
+ vertices[0].v = v0;
+ vertices[0].x = curX;
+ vertices[0].y = y;
+ vertices[0].z = 0;
+
+ curU += sourceWidth;
+ curX += polyWidth;
+
+ vertices[1].u = curU;
+ vertices[1].v = v1;
+ vertices[1].x = curX;
+ vertices[1].y = (y + height);
+ vertices[1].z = 0;
+
+ sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
+ }
+ }
+
+ if(alpha != 255)
+ sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
+ return 0;
+}
+
+static int
+PSP_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 pixel_format, void * pixels, int pitch)
+
+{
+ return SDL_Unsupported();
+}
+
+
+static int
+PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect,
+ const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
+{
+ float x, y, width, height;
+ float u0, v0, u1, v1;
+ unsigned char alpha;
+ float centerx, centery;
+
+ x = dstrect->x;
+ y = dstrect->y;
+ width = dstrect->w;
+ height = dstrect->h;
+
+ u0 = srcrect->x;
+ v0 = srcrect->y;
+ u1 = srcrect->x + srcrect->w;
+ v1 = srcrect->y + srcrect->h;
+
+ centerx = center->x;
+ centery = center->y;
+
+ alpha = texture->a;
+
+ StartDrawing(renderer);
+ TextureActivate(texture);
+ PSP_SetBlendMode(renderer, renderer->blendMode);
+
+ if(alpha != 255)
+ {
+ sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
+ sceGuColor(GU_RGBA(255, 255, 255, alpha));
+ }else{
+ sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
+ sceGuColor(0xFFFFFFFF);
+ }
+
+/* x += width * 0.5f; */
+/* y += height * 0.5f; */
+ x += centerx;
+ y += centery;
+
+ float c, s;
+
+ MathSincos(degToRad(angle), &s, &c);
+
+/* width *= 0.5f; */
+/* height *= 0.5f; */
+ width -= centerx;
+ height -= centery;
+
+
+ float cw = c*width;
+ float sw = s*width;
+ float ch = c*height;
+ float sh = s*height;
+
+ VertTV* vertices = (VertTV*)sceGuGetMemory(sizeof(VertTV)<<2);
+
+ vertices[0].u = u0;
+ vertices[0].v = v0;
+ vertices[0].x = x - cw + sh;
+ vertices[0].y = y - sw - ch;
+ vertices[0].z = 0;
+
+ vertices[1].u = u0;
+ vertices[1].v = v1;
+ vertices[1].x = x - cw - sh;
+ vertices[1].y = y - sw + ch;
+ vertices[1].z = 0;
+
+ vertices[2].u = u1;
+ vertices[2].v = v1;
+ vertices[2].x = x + cw - sh;
+ vertices[2].y = y + sw + ch;
+ vertices[2].z = 0;
+
+ vertices[3].u = u1;
+ vertices[3].v = v0;
+ vertices[3].x = x + cw + sh;
+ vertices[3].y = y + sw - ch;
+ vertices[3].z = 0;
+
+ if (flip & SDL_FLIP_VERTICAL) {
+ Swap(&vertices[0].v, &vertices[2].v);
+ Swap(&vertices[1].v, &vertices[3].v);
+ }
+ if (flip & SDL_FLIP_HORIZONTAL) {
+ Swap(&vertices[0].u, &vertices[2].u);
+ Swap(&vertices[1].u, &vertices[3].u);
+ }
+
+ sceGuDrawArray(GU_TRIANGLE_FAN, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 4, 0, vertices);
+
+ if(alpha != 255)
+ sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
+ return 0;
+}
+
+static void
+PSP_RenderPresent(SDL_Renderer * renderer)
+{
+ PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
+ if(!data->displayListAvail)
+ return;
+
+ data->displayListAvail = SDL_FALSE;
+ sceGuFinish();
+ sceGuSync(0,0);
+
+/* if(data->vsync) */
+ sceDisplayWaitVblankStart();
+
+ data->backbuffer = data->frontbuffer;
+ data->frontbuffer = vabsptr(sceGuSwapBuffers());
+
+}
+
+static void
+PSP_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata;
+ PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
+
+ if (renderdata == 0)
+ return;
+
+ if(psp_texture == 0)
+ return;
+
+ SDL_free(psp_texture->data);
+ SDL_free(psp_texture);
+ texture->driverdata = NULL;
+}
+
+static void
+PSP_DestroyRenderer(SDL_Renderer * renderer)
+{
+ PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
+ if (data) {
+ if (!data->initialized)
+ return;
+
+ StartDrawing(renderer);
+
+ sceGuTerm();
+/* vfree(data->backbuffer); */
+/* vfree(data->frontbuffer); */
+
+ data->initialized = SDL_FALSE;
+ data->displayListAvail = SDL_FALSE;
+ SDL_free(data);
+ }
+ SDL_free(renderer);
+}
+
+#endif /* SDL_VIDEO_RENDER_PSP */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/render/software/SDL_blendfillrect.c b/src/3rdparty/SDL2/src/render/software/SDL_blendfillrect.c
new file mode 100644
index 0000000..8a3f750
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/software/SDL_blendfillrect.c
@@ -0,0 +1,336 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if !SDL_RENDER_DISABLED
+
+#include "SDL_draw.h"
+#include "SDL_blendfillrect.h"
+
+
+static int
+SDL_BlendFillRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect,
+ SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ unsigned inva = 0xff - a;
+
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB555);
+ break;
+ case SDL_BLENDMODE_ADD:
+ FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB555);
+ break;
+ case SDL_BLENDMODE_MOD:
+ FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB555);
+ break;
+ default:
+ FILLRECT(Uint16, DRAW_SETPIXEL_RGB555);
+ break;
+ }
+ return 0;
+}
+
+static int
+SDL_BlendFillRect_RGB565(SDL_Surface * dst, const SDL_Rect * rect,
+ SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ unsigned inva = 0xff - a;
+
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB565);
+ break;
+ case SDL_BLENDMODE_ADD:
+ FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB565);
+ break;
+ case SDL_BLENDMODE_MOD:
+ FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB565);
+ break;
+ default:
+ FILLRECT(Uint16, DRAW_SETPIXEL_RGB565);
+ break;
+ }
+ return 0;
+}
+
+static int
+SDL_BlendFillRect_RGB888(SDL_Surface * dst, const SDL_Rect * rect,
+ SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ unsigned inva = 0xff - a;
+
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB888);
+ break;
+ case SDL_BLENDMODE_ADD:
+ FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB888);
+ break;
+ case SDL_BLENDMODE_MOD:
+ FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGB888);
+ break;
+ default:
+ FILLRECT(Uint32, DRAW_SETPIXEL_RGB888);
+ break;
+ }
+ return 0;
+}
+
+static int
+SDL_BlendFillRect_ARGB8888(SDL_Surface * dst, const SDL_Rect * rect,
+ SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ unsigned inva = 0xff - a;
+
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888);
+ break;
+ case SDL_BLENDMODE_ADD:
+ FILLRECT(Uint32, DRAW_SETPIXEL_ADD_ARGB8888);
+ break;
+ case SDL_BLENDMODE_MOD:
+ FILLRECT(Uint32, DRAW_SETPIXEL_MOD_ARGB8888);
+ break;
+ default:
+ FILLRECT(Uint32, DRAW_SETPIXEL_ARGB8888);
+ break;
+ }
+ return 0;
+}
+
+static int
+SDL_BlendFillRect_RGB(SDL_Surface * dst, const SDL_Rect * rect,
+ SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ SDL_PixelFormat *fmt = dst->format;
+ unsigned inva = 0xff - a;
+
+ switch (fmt->BytesPerPixel) {
+ case 2:
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ FILLRECT(Uint16, DRAW_SETPIXEL_BLEND_RGB);
+ break;
+ case SDL_BLENDMODE_ADD:
+ FILLRECT(Uint16, DRAW_SETPIXEL_ADD_RGB);
+ break;
+ case SDL_BLENDMODE_MOD:
+ FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB);
+ break;
+ default:
+ FILLRECT(Uint16, DRAW_SETPIXEL_RGB);
+ break;
+ }
+ return 0;
+ case 4:
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGB);
+ break;
+ case SDL_BLENDMODE_ADD:
+ FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGB);
+ break;
+ case SDL_BLENDMODE_MOD:
+ FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGB);
+ break;
+ default:
+ FILLRECT(Uint32, DRAW_SETPIXEL_RGB);
+ break;
+ }
+ return 0;
+ default:
+ return SDL_Unsupported();
+ }
+}
+
+static int
+SDL_BlendFillRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect,
+ SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ SDL_PixelFormat *fmt = dst->format;
+ unsigned inva = 0xff - a;
+
+ switch (fmt->BytesPerPixel) {
+ case 4:
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ FILLRECT(Uint32, DRAW_SETPIXEL_BLEND_RGBA);
+ break;
+ case SDL_BLENDMODE_ADD:
+ FILLRECT(Uint32, DRAW_SETPIXEL_ADD_RGBA);
+ break;
+ case SDL_BLENDMODE_MOD:
+ FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGBA);
+ break;
+ default:
+ FILLRECT(Uint32, DRAW_SETPIXEL_RGBA);
+ break;
+ }
+ return 0;
+ default:
+ return SDL_Unsupported();
+ }
+}
+
+int
+SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect,
+ SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ SDL_Rect clipped;
+
+ if (!dst) {
+ return SDL_SetError("Passed NULL destination surface");
+ }
+
+ /* This function doesn't work on surfaces < 8 bpp */
+ if (dst->format->BitsPerPixel < 8) {
+ return SDL_SetError("SDL_BlendFillRect(): Unsupported surface format");
+ }
+
+ /* If 'rect' == NULL, then fill the whole surface */
+ if (rect) {
+ /* Perform clipping */
+ if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
+ return 0;
+ }
+ rect = &clipped;
+ } else {
+ rect = &dst->clip_rect;
+ }
+
+ if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
+ r = DRAW_MUL(r, a);
+ g = DRAW_MUL(g, a);
+ b = DRAW_MUL(b, a);
+ }
+
+ switch (dst->format->BitsPerPixel) {
+ case 15:
+ switch (dst->format->Rmask) {
+ case 0x7C00:
+ return SDL_BlendFillRect_RGB555(dst, rect, blendMode, r, g, b, a);
+ }
+ break;
+ case 16:
+ switch (dst->format->Rmask) {
+ case 0xF800:
+ return SDL_BlendFillRect_RGB565(dst, rect, blendMode, r, g, b, a);
+ }
+ break;
+ case 32:
+ switch (dst->format->Rmask) {
+ case 0x00FF0000:
+ if (!dst->format->Amask) {
+ return SDL_BlendFillRect_RGB888(dst, rect, blendMode, r, g, b, a);
+ } else {
+ return SDL_BlendFillRect_ARGB8888(dst, rect, blendMode, r, g, b, a);
+ }
+ /* break; -Wunreachable-code-break */
+ }
+ break;
+ default:
+ break;
+ }
+
+ if (!dst->format->Amask) {
+ return SDL_BlendFillRect_RGB(dst, rect, blendMode, r, g, b, a);
+ } else {
+ return SDL_BlendFillRect_RGBA(dst, rect, blendMode, r, g, b, a);
+ }
+}
+
+int
+SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
+ SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ SDL_Rect rect;
+ int i;
+ int (*func)(SDL_Surface * dst, const SDL_Rect * rect,
+ SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
+ int status = 0;
+
+ if (!dst) {
+ return SDL_SetError("Passed NULL destination surface");
+ }
+
+ /* This function doesn't work on surfaces < 8 bpp */
+ if (dst->format->BitsPerPixel < 8) {
+ return SDL_SetError("SDL_BlendFillRects(): Unsupported surface format");
+ }
+
+ if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
+ r = DRAW_MUL(r, a);
+ g = DRAW_MUL(g, a);
+ b = DRAW_MUL(b, a);
+ }
+
+ /* FIXME: Does this function pointer slow things down significantly? */
+ switch (dst->format->BitsPerPixel) {
+ case 15:
+ switch (dst->format->Rmask) {
+ case 0x7C00:
+ func = SDL_BlendFillRect_RGB555;
+ }
+ break;
+ case 16:
+ switch (dst->format->Rmask) {
+ case 0xF800:
+ func = SDL_BlendFillRect_RGB565;
+ }
+ break;
+ case 32:
+ switch (dst->format->Rmask) {
+ case 0x00FF0000:
+ if (!dst->format->Amask) {
+ func = SDL_BlendFillRect_RGB888;
+ } else {
+ func = SDL_BlendFillRect_ARGB8888;
+ }
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+
+ if (!func) {
+ if (!dst->format->Amask) {
+ func = SDL_BlendFillRect_RGB;
+ } else {
+ func = SDL_BlendFillRect_RGBA;
+ }
+ }
+
+ for (i = 0; i < count; ++i) {
+ /* Perform clipping */
+ if (!SDL_IntersectRect(&rects[i], &dst->clip_rect, &rect)) {
+ continue;
+ }
+ status = func(dst, &rect, blendMode, r, g, b, a);
+ }
+ return status;
+}
+
+#endif /* !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/software/SDL_blendfillrect.h b/src/3rdparty/SDL2/src/render/software/SDL_blendfillrect.h
new file mode 100644
index 0000000..262210f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/software/SDL_blendfillrect.h
@@ -0,0 +1,27 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+
+extern int SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
+extern int SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/software/SDL_blendline.c b/src/3rdparty/SDL2/src/render/software/SDL_blendline.c
new file mode 100644
index 0000000..0ed0ccd
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/software/SDL_blendline.c
@@ -0,0 +1,777 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if !SDL_RENDER_DISABLED
+
+#include "SDL_draw.h"
+#include "SDL_blendline.h"
+#include "SDL_blendpoint.h"
+
+
+static void
+SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2,
+ SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
+ SDL_bool draw_end)
+{
+ const SDL_PixelFormat *fmt = dst->format;
+ unsigned r, g, b, a, inva;
+
+ if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
+ r = DRAW_MUL(_r, _a);
+ g = DRAW_MUL(_g, _a);
+ b = DRAW_MUL(_b, _a);
+ a = _a;
+ } else {
+ r = _r;
+ g = _g;
+ b = _b;
+ a = _a;
+ }
+ inva = (a ^ 0xff);
+
+ if (y1 == y2) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end);
+ break;
+ default:
+ HLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
+ break;
+ }
+ } else if (x1 == x2) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end);
+ break;
+ default:
+ VLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
+ break;
+ }
+ } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end);
+ break;
+ default:
+ DLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
+ break;
+ }
+ } else {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY2_BLEND_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
+ draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY2_ADD_RGB, DRAW_SETPIXELXY2_ADD_RGB,
+ draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY2_MOD_RGB, DRAW_SETPIXELXY2_MOD_RGB,
+ draw_end);
+ break;
+ default:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY2_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
+ draw_end);
+ break;
+ }
+ }
+}
+
+static void
+SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2,
+ SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
+ SDL_bool draw_end)
+{
+ unsigned r, g, b, a, inva;
+
+ if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
+ r = DRAW_MUL(_r, _a);
+ g = DRAW_MUL(_g, _a);
+ b = DRAW_MUL(_b, _a);
+ a = _a;
+ } else {
+ r = _r;
+ g = _g;
+ b = _b;
+ a = _a;
+ }
+ inva = (a ^ 0xff);
+
+ if (y1 == y2) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end);
+ break;
+ default:
+ HLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
+ break;
+ }
+ } else if (x1 == x2) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end);
+ break;
+ default:
+ VLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
+ break;
+ }
+ } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end);
+ break;
+ default:
+ DLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
+ break;
+ }
+ } else {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY_BLEND_RGB555, DRAW_SETPIXELXY_BLEND_RGB555,
+ draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY_ADD_RGB555, DRAW_SETPIXELXY_ADD_RGB555,
+ draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY_MOD_RGB555, DRAW_SETPIXELXY_MOD_RGB555,
+ draw_end);
+ break;
+ default:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY_RGB555, DRAW_SETPIXELXY_BLEND_RGB555,
+ draw_end);
+ break;
+ }
+ }
+}
+
+static void
+SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2,
+ SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
+ SDL_bool draw_end)
+{
+ unsigned r, g, b, a, inva;
+
+ if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
+ r = DRAW_MUL(_r, _a);
+ g = DRAW_MUL(_g, _a);
+ b = DRAW_MUL(_b, _a);
+ a = _a;
+ } else {
+ r = _r;
+ g = _g;
+ b = _b;
+ a = _a;
+ }
+ inva = (a ^ 0xff);
+
+ if (y1 == y2) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end);
+ break;
+ default:
+ HLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
+ break;
+ }
+ } else if (x1 == x2) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end);
+ break;
+ default:
+ VLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
+ break;
+ }
+ } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end);
+ break;
+ default:
+ DLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
+ break;
+ }
+ } else {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY_BLEND_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
+ draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY_ADD_RGB565, DRAW_SETPIXELXY_ADD_RGB565,
+ draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY_MOD_RGB565, DRAW_SETPIXELXY_MOD_RGB565,
+ draw_end);
+ break;
+ default:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
+ draw_end);
+ break;
+ }
+ }
+}
+
+static void
+SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
+ SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
+ SDL_bool draw_end)
+{
+ const SDL_PixelFormat *fmt = dst->format;
+ unsigned r, g, b, a, inva;
+
+ if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
+ r = DRAW_MUL(_r, _a);
+ g = DRAW_MUL(_g, _a);
+ b = DRAW_MUL(_b, _a);
+ a = _a;
+ } else {
+ r = _r;
+ g = _g;
+ b = _b;
+ a = _a;
+ }
+ inva = (a ^ 0xff);
+
+ if (y1 == y2) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ HLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end);
+ break;
+ default:
+ HLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
+ break;
+ }
+ } else if (x1 == x2) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ VLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end);
+ break;
+ default:
+ VLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
+ break;
+ }
+ } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ DLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end);
+ break;
+ default:
+ DLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
+ break;
+ }
+ } else {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY4_BLEND_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
+ draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY4_ADD_RGB, DRAW_SETPIXELXY4_ADD_RGB,
+ draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY4_MOD_RGB, DRAW_SETPIXELXY4_MOD_RGB,
+ draw_end);
+ break;
+ default:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY4_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
+ draw_end);
+ break;
+ }
+ }
+}
+
+static void
+SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
+ SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
+ SDL_bool draw_end)
+{
+ const SDL_PixelFormat *fmt = dst->format;
+ unsigned r, g, b, a, inva;
+
+ if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
+ r = DRAW_MUL(_r, _a);
+ g = DRAW_MUL(_g, _a);
+ b = DRAW_MUL(_b, _a);
+ a = _a;
+ } else {
+ r = _r;
+ g = _g;
+ b = _b;
+ a = _a;
+ }
+ inva = (a ^ 0xff);
+
+ if (y1 == y2) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ HLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ HLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end);
+ break;
+ default:
+ HLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
+ break;
+ }
+ } else if (x1 == x2) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ VLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ VLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end);
+ break;
+ default:
+ VLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
+ break;
+ }
+ } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ DLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ DLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end);
+ break;
+ default:
+ DLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
+ break;
+ }
+ } else {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY4_BLEND_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
+ draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY4_ADD_RGBA, DRAW_SETPIXELXY4_ADD_RGBA,
+ draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY4_MOD_RGBA, DRAW_SETPIXELXY4_MOD_RGBA,
+ draw_end);
+ break;
+ default:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY4_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
+ draw_end);
+ break;
+ }
+ }
+}
+
+static void
+SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
+ SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
+ SDL_bool draw_end)
+{
+ unsigned r, g, b, a, inva;
+
+ if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
+ r = DRAW_MUL(_r, _a);
+ g = DRAW_MUL(_g, _a);
+ b = DRAW_MUL(_b, _a);
+ a = _a;
+ } else {
+ r = _r;
+ g = _g;
+ b = _b;
+ a = _a;
+ }
+ inva = (a ^ 0xff);
+
+ if (y1 == y2) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ HLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end);
+ break;
+ default:
+ HLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
+ break;
+ }
+ } else if (x1 == x2) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ VLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end);
+ break;
+ default:
+ VLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
+ break;
+ }
+ } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ DLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end);
+ break;
+ default:
+ DLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
+ break;
+ }
+ } else {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY_BLEND_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
+ draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY_ADD_RGB888, DRAW_SETPIXELXY_ADD_RGB888,
+ draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY_MOD_RGB888, DRAW_SETPIXELXY_MOD_RGB888,
+ draw_end);
+ break;
+ default:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
+ draw_end);
+ break;
+ }
+ }
+}
+
+static void
+SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
+ SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
+ SDL_bool draw_end)
+{
+ unsigned r, g, b, a, inva;
+
+ if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
+ r = DRAW_MUL(_r, _a);
+ g = DRAW_MUL(_g, _a);
+ b = DRAW_MUL(_b, _a);
+ a = _a;
+ } else {
+ r = _r;
+ g = _g;
+ b = _b;
+ a = _a;
+ }
+ inva = (a ^ 0xff);
+
+ if (y1 == y2) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ HLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ HLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ HLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end);
+ break;
+ default:
+ HLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
+ break;
+ }
+ } else if (x1 == x2) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ VLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ VLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ VLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end);
+ break;
+ default:
+ VLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
+ break;
+ }
+ } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ DLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ DLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ DLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end);
+ break;
+ default:
+ DLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
+ break;
+ }
+ } else {
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY_BLEND_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
+ draw_end);
+ break;
+ case SDL_BLENDMODE_ADD:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY_ADD_ARGB8888, DRAW_SETPIXELXY_ADD_ARGB8888,
+ draw_end);
+ break;
+ case SDL_BLENDMODE_MOD:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY_MOD_ARGB8888, DRAW_SETPIXELXY_MOD_ARGB8888,
+ draw_end);
+ break;
+ default:
+ AALINE(x1, y1, x2, y2,
+ DRAW_SETPIXELXY_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
+ draw_end);
+ break;
+ }
+ }
+}
+
+typedef void (*BlendLineFunc) (SDL_Surface * dst,
+ int x1, int y1, int x2, int y2,
+ SDL_BlendMode blendMode,
+ Uint8 r, Uint8 g, Uint8 b, Uint8 a,
+ SDL_bool draw_end);
+
+static BlendLineFunc
+SDL_CalculateBlendLineFunc(const SDL_PixelFormat * fmt)
+{
+ switch (fmt->BytesPerPixel) {
+ case 2:
+ if (fmt->Rmask == 0x7C00) {
+ return SDL_BlendLine_RGB555;
+ } else if (fmt->Rmask == 0xF800) {
+ return SDL_BlendLine_RGB565;
+ } else {
+ return SDL_BlendLine_RGB2;
+ }
+ /* break; -Wunreachable-code-break */
+ case 4:
+ if (fmt->Rmask == 0x00FF0000) {
+ if (fmt->Amask) {
+ return SDL_BlendLine_ARGB8888;
+ } else {
+ return SDL_BlendLine_RGB888;
+ }
+ } else {
+ if (fmt->Amask) {
+ return SDL_BlendLine_RGBA4;
+ } else {
+ return SDL_BlendLine_RGB4;
+ }
+ }
+ }
+ return NULL;
+}
+
+int
+SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2,
+ SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ BlendLineFunc func;
+
+ if (!dst) {
+ return SDL_SetError("SDL_BlendLine(): Passed NULL destination surface");
+ }
+
+ func = SDL_CalculateBlendLineFunc(dst->format);
+ if (!func) {
+ return SDL_SetError("SDL_BlendLine(): Unsupported surface format");
+ }
+
+ /* Perform clipping */
+ /* FIXME: We don't actually want to clip, as it may change line slope */
+ if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
+ return 0;
+ }
+
+ func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, SDL_TRUE);
+ return 0;
+}
+
+int
+SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
+ SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ int i;
+ int x1, y1;
+ int x2, y2;
+ SDL_bool draw_end;
+ BlendLineFunc func;
+
+ if (!dst) {
+ return SDL_SetError("SDL_BlendLines(): Passed NULL destination surface");
+ }
+
+ func = SDL_CalculateBlendLineFunc(dst->format);
+ if (!func) {
+ return SDL_SetError("SDL_BlendLines(): Unsupported surface format");
+ }
+
+ for (i = 1; i < count; ++i) {
+ x1 = points[i-1].x;
+ y1 = points[i-1].y;
+ x2 = points[i].x;
+ y2 = points[i].y;
+
+ /* Perform clipping */
+ /* FIXME: We don't actually want to clip, as it may change line slope */
+ if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
+ continue;
+ }
+
+ /* Draw the end if it was clipped */
+ draw_end = (x2 != points[i].x || y2 != points[i].y);
+
+ func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, draw_end);
+ }
+ if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
+ SDL_BlendPoint(dst, points[count-1].x, points[count-1].y,
+ blendMode, r, g, b, a);
+ }
+ return 0;
+}
+
+#endif /* !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/software/SDL_blendline.h b/src/3rdparty/SDL2/src/render/software/SDL_blendline.h
new file mode 100644
index 0000000..82072cb
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/software/SDL_blendline.h
@@ -0,0 +1,27 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+
+extern int SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
+extern int SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/software/SDL_blendpoint.c b/src/3rdparty/SDL2/src/render/software/SDL_blendpoint.c
new file mode 100644
index 0000000..37fb498
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/software/SDL_blendpoint.c
@@ -0,0 +1,341 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if !SDL_RENDER_DISABLED
+
+#include "SDL_draw.h"
+#include "SDL_blendpoint.h"
+
+
+static int
+SDL_BlendPoint_RGB555(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
+ Uint8 g, Uint8 b, Uint8 a)
+{
+ unsigned inva = 0xff - a;
+
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ DRAW_SETPIXELXY_BLEND_RGB555(x, y);
+ break;
+ case SDL_BLENDMODE_ADD:
+ DRAW_SETPIXELXY_ADD_RGB555(x, y);
+ break;
+ case SDL_BLENDMODE_MOD:
+ DRAW_SETPIXELXY_MOD_RGB555(x, y);
+ break;
+ default:
+ DRAW_SETPIXELXY_RGB555(x, y);
+ break;
+ }
+ return 0;
+}
+
+static int
+SDL_BlendPoint_RGB565(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
+ Uint8 g, Uint8 b, Uint8 a)
+{
+ unsigned inva = 0xff - a;
+
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ DRAW_SETPIXELXY_BLEND_RGB565(x, y);
+ break;
+ case SDL_BLENDMODE_ADD:
+ DRAW_SETPIXELXY_ADD_RGB565(x, y);
+ break;
+ case SDL_BLENDMODE_MOD:
+ DRAW_SETPIXELXY_MOD_RGB565(x, y);
+ break;
+ default:
+ DRAW_SETPIXELXY_RGB565(x, y);
+ break;
+ }
+ return 0;
+}
+
+static int
+SDL_BlendPoint_RGB888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
+ Uint8 g, Uint8 b, Uint8 a)
+{
+ unsigned inva = 0xff - a;
+
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ DRAW_SETPIXELXY_BLEND_RGB888(x, y);
+ break;
+ case SDL_BLENDMODE_ADD:
+ DRAW_SETPIXELXY_ADD_RGB888(x, y);
+ break;
+ case SDL_BLENDMODE_MOD:
+ DRAW_SETPIXELXY_MOD_RGB888(x, y);
+ break;
+ default:
+ DRAW_SETPIXELXY_RGB888(x, y);
+ break;
+ }
+ return 0;
+}
+
+static int
+SDL_BlendPoint_ARGB8888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode,
+ Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ unsigned inva = 0xff - a;
+
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ DRAW_SETPIXELXY_BLEND_ARGB8888(x, y);
+ break;
+ case SDL_BLENDMODE_ADD:
+ DRAW_SETPIXELXY_ADD_ARGB8888(x, y);
+ break;
+ case SDL_BLENDMODE_MOD:
+ DRAW_SETPIXELXY_MOD_ARGB8888(x, y);
+ break;
+ default:
+ DRAW_SETPIXELXY_ARGB8888(x, y);
+ break;
+ }
+ return 0;
+}
+
+static int
+SDL_BlendPoint_RGB(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
+ Uint8 g, Uint8 b, Uint8 a)
+{
+ SDL_PixelFormat *fmt = dst->format;
+ unsigned inva = 0xff - a;
+
+ switch (fmt->BytesPerPixel) {
+ case 2:
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ DRAW_SETPIXELXY2_BLEND_RGB(x, y);
+ break;
+ case SDL_BLENDMODE_ADD:
+ DRAW_SETPIXELXY2_ADD_RGB(x, y);
+ break;
+ case SDL_BLENDMODE_MOD:
+ DRAW_SETPIXELXY2_MOD_RGB(x, y);
+ break;
+ default:
+ DRAW_SETPIXELXY2_RGB(x, y);
+ break;
+ }
+ return 0;
+ case 4:
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ DRAW_SETPIXELXY4_BLEND_RGB(x, y);
+ break;
+ case SDL_BLENDMODE_ADD:
+ DRAW_SETPIXELXY4_ADD_RGB(x, y);
+ break;
+ case SDL_BLENDMODE_MOD:
+ DRAW_SETPIXELXY4_MOD_RGB(x, y);
+ break;
+ default:
+ DRAW_SETPIXELXY4_RGB(x, y);
+ break;
+ }
+ return 0;
+ default:
+ return SDL_Unsupported();
+ }
+}
+
+static int
+SDL_BlendPoint_RGBA(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
+ Uint8 g, Uint8 b, Uint8 a)
+{
+ SDL_PixelFormat *fmt = dst->format;
+ unsigned inva = 0xff - a;
+
+ switch (fmt->BytesPerPixel) {
+ case 4:
+ switch (blendMode) {
+ case SDL_BLENDMODE_BLEND:
+ DRAW_SETPIXELXY4_BLEND_RGBA(x, y);
+ break;
+ case SDL_BLENDMODE_ADD:
+ DRAW_SETPIXELXY4_ADD_RGBA(x, y);
+ break;
+ case SDL_BLENDMODE_MOD:
+ DRAW_SETPIXELXY4_MOD_RGBA(x, y);
+ break;
+ default:
+ DRAW_SETPIXELXY4_RGBA(x, y);
+ break;
+ }
+ return 0;
+ default:
+ return SDL_Unsupported();
+ }
+}
+
+int
+SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
+ Uint8 g, Uint8 b, Uint8 a)
+{
+ if (!dst) {
+ return SDL_SetError("Passed NULL destination surface");
+ }
+
+ /* This function doesn't work on surfaces < 8 bpp */
+ if (dst->format->BitsPerPixel < 8) {
+ return SDL_SetError("SDL_BlendPoint(): Unsupported surface format");
+ }
+
+ /* Perform clipping */
+ if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
+ x >= (dst->clip_rect.x + dst->clip_rect.w) ||
+ y >= (dst->clip_rect.y + dst->clip_rect.h)) {
+ return 0;
+ }
+
+ if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
+ r = DRAW_MUL(r, a);
+ g = DRAW_MUL(g, a);
+ b = DRAW_MUL(b, a);
+ }
+
+ switch (dst->format->BitsPerPixel) {
+ case 15:
+ switch (dst->format->Rmask) {
+ case 0x7C00:
+ return SDL_BlendPoint_RGB555(dst, x, y, blendMode, r, g, b, a);
+ }
+ break;
+ case 16:
+ switch (dst->format->Rmask) {
+ case 0xF800:
+ return SDL_BlendPoint_RGB565(dst, x, y, blendMode, r, g, b, a);
+ }
+ break;
+ case 32:
+ switch (dst->format->Rmask) {
+ case 0x00FF0000:
+ if (!dst->format->Amask) {
+ return SDL_BlendPoint_RGB888(dst, x, y, blendMode, r, g, b, a);
+ } else {
+ return SDL_BlendPoint_ARGB8888(dst, x, y, blendMode, r, g, b, a);
+ }
+ /* break; -Wunreachable-code-break */
+ }
+ break;
+ default:
+ break;
+ }
+
+ if (!dst->format->Amask) {
+ return SDL_BlendPoint_RGB(dst, x, y, blendMode, r, g, b, a);
+ } else {
+ return SDL_BlendPoint_RGBA(dst, x, y, blendMode, r, g, b, a);
+ }
+}
+
+int
+SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count,
+ SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ int minx, miny;
+ int maxx, maxy;
+ int i;
+ int x, y;
+ int (*func)(SDL_Surface * dst, int x, int y,
+ SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
+ int status = 0;
+
+ if (!dst) {
+ return SDL_SetError("Passed NULL destination surface");
+ }
+
+ /* This function doesn't work on surfaces < 8 bpp */
+ if (dst->format->BitsPerPixel < 8) {
+ return SDL_SetError("SDL_BlendPoints(): Unsupported surface format");
+ }
+
+ if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
+ r = DRAW_MUL(r, a);
+ g = DRAW_MUL(g, a);
+ b = DRAW_MUL(b, a);
+ }
+
+ /* FIXME: Does this function pointer slow things down significantly? */
+ switch (dst->format->BitsPerPixel) {
+ case 15:
+ switch (dst->format->Rmask) {
+ case 0x7C00:
+ func = SDL_BlendPoint_RGB555;
+ break;
+ }
+ break;
+ case 16:
+ switch (dst->format->Rmask) {
+ case 0xF800:
+ func = SDL_BlendPoint_RGB565;
+ break;
+ }
+ break;
+ case 32:
+ switch (dst->format->Rmask) {
+ case 0x00FF0000:
+ if (!dst->format->Amask) {
+ func = SDL_BlendPoint_RGB888;
+ } else {
+ func = SDL_BlendPoint_ARGB8888;
+ }
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+
+ if (!func) {
+ if (!dst->format->Amask) {
+ func = SDL_BlendPoint_RGB;
+ } else {
+ func = SDL_BlendPoint_RGBA;
+ }
+ }
+
+ minx = dst->clip_rect.x;
+ maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
+ miny = dst->clip_rect.y;
+ maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
+
+ for (i = 0; i < count; ++i) {
+ x = points[i].x;
+ y = points[i].y;
+
+ if (x < minx || x > maxx || y < miny || y > maxy) {
+ continue;
+ }
+ status = func(dst, x, y, blendMode, r, g, b, a);
+ }
+ return status;
+}
+
+#endif /* !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/software/SDL_blendpoint.h b/src/3rdparty/SDL2/src/render/software/SDL_blendpoint.h
new file mode 100644
index 0000000..dd9e49c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/software/SDL_blendpoint.h
@@ -0,0 +1,27 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+
+extern int SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
+extern int SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/software/SDL_draw.h b/src/3rdparty/SDL2/src/render/software/SDL_draw.h
new file mode 100644
index 0000000..945f2bc
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/software/SDL_draw.h
@@ -0,0 +1,576 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "../../video/SDL_blit.h"
+
+/* This code assumes that r, g, b, a are the source color,
+ * and in the blend and add case, the RGB values are premultiplied by a.
+ */
+
+#define DRAW_MUL(_a, _b) (((unsigned)(_a)*(_b))/255)
+
+#define DRAW_FASTSETPIXEL(type) \
+ *pixel = (type) color
+
+#define DRAW_FASTSETPIXEL1 DRAW_FASTSETPIXEL(Uint8)
+#define DRAW_FASTSETPIXEL2 DRAW_FASTSETPIXEL(Uint16)
+#define DRAW_FASTSETPIXEL4 DRAW_FASTSETPIXEL(Uint32)
+
+#define DRAW_FASTSETPIXELXY(x, y, type, bpp, color) \
+ *(type *)((Uint8 *)dst->pixels + (y) * dst->pitch \
+ + (x) * bpp) = (type) color
+
+#define DRAW_FASTSETPIXELXY1(x, y) DRAW_FASTSETPIXELXY(x, y, Uint8, 1, color)
+#define DRAW_FASTSETPIXELXY2(x, y) DRAW_FASTSETPIXELXY(x, y, Uint16, 2, color)
+#define DRAW_FASTSETPIXELXY4(x, y) DRAW_FASTSETPIXELXY(x, y, Uint32, 4, color)
+
+#define DRAW_SETPIXEL(setpixel) \
+do { \
+ unsigned sr = r, sg = g, sb = b, sa = a; (void) sa; \
+ setpixel; \
+} while (0)
+
+#define DRAW_SETPIXEL_BLEND(getpixel, setpixel) \
+do { \
+ unsigned sr, sg, sb, sa = 0xFF; \
+ getpixel; \
+ sr = DRAW_MUL(inva, sr) + r; \
+ sg = DRAW_MUL(inva, sg) + g; \
+ sb = DRAW_MUL(inva, sb) + b; \
+ sa = DRAW_MUL(inva, sa) + a; \
+ setpixel; \
+} while (0)
+
+#define DRAW_SETPIXEL_ADD(getpixel, setpixel) \
+do { \
+ unsigned sr, sg, sb, sa; (void) sa; \
+ getpixel; \
+ sr += r; if (sr > 0xff) sr = 0xff; \
+ sg += g; if (sg > 0xff) sg = 0xff; \
+ sb += b; if (sb > 0xff) sb = 0xff; \
+ setpixel; \
+} while (0)
+
+#define DRAW_SETPIXEL_MOD(getpixel, setpixel) \
+do { \
+ unsigned sr, sg, sb, sa; (void) sa; \
+ getpixel; \
+ sr = DRAW_MUL(sr, r); \
+ sg = DRAW_MUL(sg, g); \
+ sb = DRAW_MUL(sb, b); \
+ setpixel; \
+} while (0)
+
+#define DRAW_SETPIXELXY(x, y, type, bpp, op) \
+do { \
+ type *pixel = (type *)((Uint8 *)dst->pixels + (y) * dst->pitch \
+ + (x) * bpp); \
+ op; \
+} while (0)
+
+/*
+ * Define draw operators for RGB555
+ */
+
+#define DRAW_SETPIXEL_RGB555 \
+ DRAW_SETPIXEL(RGB555_FROM_RGB(*pixel, sr, sg, sb))
+
+#define DRAW_SETPIXEL_BLEND_RGB555 \
+ DRAW_SETPIXEL_BLEND(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
+ RGB555_FROM_RGB(*pixel, sr, sg, sb))
+
+#define DRAW_SETPIXEL_ADD_RGB555 \
+ DRAW_SETPIXEL_ADD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
+ RGB555_FROM_RGB(*pixel, sr, sg, sb))
+
+#define DRAW_SETPIXEL_MOD_RGB555 \
+ DRAW_SETPIXEL_MOD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
+ RGB555_FROM_RGB(*pixel, sr, sg, sb))
+
+#define DRAW_SETPIXELXY_RGB555(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB555)
+
+#define DRAW_SETPIXELXY_BLEND_RGB555(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB555)
+
+#define DRAW_SETPIXELXY_ADD_RGB555(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB555)
+
+#define DRAW_SETPIXELXY_MOD_RGB555(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB555)
+
+/*
+ * Define draw operators for RGB565
+ */
+
+#define DRAW_SETPIXEL_RGB565 \
+ DRAW_SETPIXEL(RGB565_FROM_RGB(*pixel, sr, sg, sb))
+
+#define DRAW_SETPIXEL_BLEND_RGB565 \
+ DRAW_SETPIXEL_BLEND(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
+ RGB565_FROM_RGB(*pixel, sr, sg, sb))
+
+#define DRAW_SETPIXEL_ADD_RGB565 \
+ DRAW_SETPIXEL_ADD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
+ RGB565_FROM_RGB(*pixel, sr, sg, sb))
+
+#define DRAW_SETPIXEL_MOD_RGB565 \
+ DRAW_SETPIXEL_MOD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
+ RGB565_FROM_RGB(*pixel, sr, sg, sb))
+
+#define DRAW_SETPIXELXY_RGB565(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB565)
+
+#define DRAW_SETPIXELXY_BLEND_RGB565(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB565)
+
+#define DRAW_SETPIXELXY_ADD_RGB565(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB565)
+
+#define DRAW_SETPIXELXY_MOD_RGB565(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB565)
+
+/*
+ * Define draw operators for RGB888
+ */
+
+#define DRAW_SETPIXEL_RGB888 \
+ DRAW_SETPIXEL(RGB888_FROM_RGB(*pixel, sr, sg, sb))
+
+#define DRAW_SETPIXEL_BLEND_RGB888 \
+ DRAW_SETPIXEL_BLEND(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
+ RGB888_FROM_RGB(*pixel, sr, sg, sb))
+
+#define DRAW_SETPIXEL_ADD_RGB888 \
+ DRAW_SETPIXEL_ADD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
+ RGB888_FROM_RGB(*pixel, sr, sg, sb))
+
+#define DRAW_SETPIXEL_MOD_RGB888 \
+ DRAW_SETPIXEL_MOD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
+ RGB888_FROM_RGB(*pixel, sr, sg, sb))
+
+#define DRAW_SETPIXELXY_RGB888(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB888)
+
+#define DRAW_SETPIXELXY_BLEND_RGB888(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB888)
+
+#define DRAW_SETPIXELXY_ADD_RGB888(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB888)
+
+#define DRAW_SETPIXELXY_MOD_RGB888(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGB888)
+
+/*
+ * Define draw operators for ARGB8888
+ */
+
+#define DRAW_SETPIXEL_ARGB8888 \
+ DRAW_SETPIXEL(ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
+
+#define DRAW_SETPIXEL_BLEND_ARGB8888 \
+ DRAW_SETPIXEL_BLEND(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
+ ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
+
+#define DRAW_SETPIXEL_ADD_ARGB8888 \
+ DRAW_SETPIXEL_ADD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
+ ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
+
+#define DRAW_SETPIXEL_MOD_ARGB8888 \
+ DRAW_SETPIXEL_MOD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
+ ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
+
+#define DRAW_SETPIXELXY_ARGB8888(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ARGB8888)
+
+#define DRAW_SETPIXELXY_BLEND_ARGB8888(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_ARGB8888)
+
+#define DRAW_SETPIXELXY_ADD_ARGB8888(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_ARGB8888)
+
+#define DRAW_SETPIXELXY_MOD_ARGB8888(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_ARGB8888)
+
+/*
+ * Define draw operators for general RGB
+ */
+
+#define DRAW_SETPIXEL_RGB \
+ DRAW_SETPIXEL(PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
+
+#define DRAW_SETPIXEL_BLEND_RGB \
+ DRAW_SETPIXEL_BLEND(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
+ PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
+
+#define DRAW_SETPIXEL_ADD_RGB \
+ DRAW_SETPIXEL_ADD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
+ PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
+
+#define DRAW_SETPIXEL_MOD_RGB \
+ DRAW_SETPIXEL_MOD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
+ PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
+
+#define DRAW_SETPIXELXY2_RGB(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB)
+
+#define DRAW_SETPIXELXY4_RGB(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB)
+
+#define DRAW_SETPIXELXY2_BLEND_RGB(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_BLEND_RGB)
+
+#define DRAW_SETPIXELXY4_BLEND_RGB(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGB)
+
+#define DRAW_SETPIXELXY2_ADD_RGB(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_ADD_RGB)
+
+#define DRAW_SETPIXELXY4_ADD_RGB(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGB)
+
+#define DRAW_SETPIXELXY2_MOD_RGB(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB)
+
+#define DRAW_SETPIXELXY4_MOD_RGB(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGB)
+
+
+/*
+ * Define draw operators for general RGBA
+ */
+
+#define DRAW_SETPIXEL_RGBA \
+ DRAW_SETPIXEL(PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
+
+#define DRAW_SETPIXEL_BLEND_RGBA \
+ DRAW_SETPIXEL_BLEND(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
+ PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
+
+#define DRAW_SETPIXEL_ADD_RGBA \
+ DRAW_SETPIXEL_ADD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
+ PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
+
+#define DRAW_SETPIXEL_MOD_RGBA \
+ DRAW_SETPIXEL_MOD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
+ PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
+
+#define DRAW_SETPIXELXY4_RGBA(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGBA)
+
+#define DRAW_SETPIXELXY4_BLEND_RGBA(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_BLEND_RGBA)
+
+#define DRAW_SETPIXELXY4_ADD_RGBA(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ADD_RGBA)
+
+#define DRAW_SETPIXELXY4_MOD_RGBA(x, y) \
+ DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGBA)
+
+/*
+ * Define line drawing macro
+ */
+
+#define ABS(_x) ((_x) < 0 ? -(_x) : (_x))
+
+/* Horizontal line */
+#define HLINE(type, op, draw_end) \
+{ \
+ int length; \
+ int pitch = (dst->pitch / dst->format->BytesPerPixel); \
+ type *pixel; \
+ if (x1 <= x2) { \
+ pixel = (type *)dst->pixels + y1 * pitch + x1; \
+ length = draw_end ? (x2-x1+1) : (x2-x1); \
+ } else { \
+ pixel = (type *)dst->pixels + y1 * pitch + x2; \
+ if (!draw_end) { \
+ ++pixel; \
+ } \
+ length = draw_end ? (x1-x2+1) : (x1-x2); \
+ } \
+ while (length--) { \
+ op; \
+ ++pixel; \
+ } \
+}
+
+/* Vertical line */
+#define VLINE(type, op, draw_end) \
+{ \
+ int length; \
+ int pitch = (dst->pitch / dst->format->BytesPerPixel); \
+ type *pixel; \
+ if (y1 <= y2) { \
+ pixel = (type *)dst->pixels + y1 * pitch + x1; \
+ length = draw_end ? (y2-y1+1) : (y2-y1); \
+ } else { \
+ pixel = (type *)dst->pixels + y2 * pitch + x1; \
+ if (!draw_end) { \
+ pixel += pitch; \
+ } \
+ length = draw_end ? (y1-y2+1) : (y1-y2); \
+ } \
+ while (length--) { \
+ op; \
+ pixel += pitch; \
+ } \
+}
+
+/* Diagonal line */
+#define DLINE(type, op, draw_end) \
+{ \
+ int length; \
+ int pitch = (dst->pitch / dst->format->BytesPerPixel); \
+ type *pixel; \
+ if (y1 <= y2) { \
+ pixel = (type *)dst->pixels + y1 * pitch + x1; \
+ if (x1 <= x2) { \
+ ++pitch; \
+ } else { \
+ --pitch; \
+ } \
+ length = (y2-y1); \
+ } else { \
+ pixel = (type *)dst->pixels + y2 * pitch + x2; \
+ if (x2 <= x1) { \
+ ++pitch; \
+ } else { \
+ --pitch; \
+ } \
+ if (!draw_end) { \
+ pixel += pitch; \
+ } \
+ length = (y1-y2); \
+ } \
+ if (draw_end) { \
+ ++length; \
+ } \
+ while (length--) { \
+ op; \
+ pixel += pitch; \
+ } \
+}
+
+/* Bresenham's line algorithm */
+#define BLINE(x1, y1, x2, y2, op, draw_end) \
+{ \
+ int i, deltax, deltay, numpixels; \
+ int d, dinc1, dinc2; \
+ int x, xinc1, xinc2; \
+ int y, yinc1, yinc2; \
+ \
+ deltax = ABS(x2 - x1); \
+ deltay = ABS(y2 - y1); \
+ \
+ if (deltax >= deltay) { \
+ numpixels = deltax + 1; \
+ d = (2 * deltay) - deltax; \
+ dinc1 = deltay * 2; \
+ dinc2 = (deltay - deltax) * 2; \
+ xinc1 = 1; \
+ xinc2 = 1; \
+ yinc1 = 0; \
+ yinc2 = 1; \
+ } else { \
+ numpixels = deltay + 1; \
+ d = (2 * deltax) - deltay; \
+ dinc1 = deltax * 2; \
+ dinc2 = (deltax - deltay) * 2; \
+ xinc1 = 0; \
+ xinc2 = 1; \
+ yinc1 = 1; \
+ yinc2 = 1; \
+ } \
+ \
+ if (x1 > x2) { \
+ xinc1 = -xinc1; \
+ xinc2 = -xinc2; \
+ } \
+ if (y1 > y2) { \
+ yinc1 = -yinc1; \
+ yinc2 = -yinc2; \
+ } \
+ \
+ x = x1; \
+ y = y1; \
+ \
+ if (!draw_end) { \
+ --numpixels; \
+ } \
+ for (i = 0; i < numpixels; ++i) { \
+ op(x, y); \
+ if (d < 0) { \
+ d += dinc1; \
+ x += xinc1; \
+ y += yinc1; \
+ } else { \
+ d += dinc2; \
+ x += xinc2; \
+ y += yinc2; \
+ } \
+ } \
+}
+
+/* Xiaolin Wu's line algorithm, based on Michael Abrash's implementation */
+#define WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
+{ \
+ Uint16 ErrorAdj, ErrorAcc; \
+ Uint16 ErrorAccTemp, Weighting; \
+ int DeltaX, DeltaY, Temp, XDir; \
+ unsigned r, g, b, a, inva; \
+ \
+ /* Draw the initial pixel, which is always exactly intersected by \
+ the line and so needs no weighting */ \
+ opaque_op(x1, y1); \
+ \
+ /* Draw the final pixel, which is always exactly intersected by the line \
+ and so needs no weighting */ \
+ if (draw_end) { \
+ opaque_op(x2, y2); \
+ } \
+ \
+ /* Make sure the line runs top to bottom */ \
+ if (y1 > y2) { \
+ Temp = y1; y1 = y2; y2 = Temp; \
+ Temp = x1; x1 = x2; x2 = Temp; \
+ } \
+ DeltaY = y2 - y1; \
+ \
+ if ((DeltaX = x2 - x1) >= 0) { \
+ XDir = 1; \
+ } else { \
+ XDir = -1; \
+ DeltaX = -DeltaX; /* make DeltaX positive */ \
+ } \
+ \
+ /* line is not horizontal, diagonal, or vertical */ \
+ ErrorAcc = 0; /* initialize the line error accumulator to 0 */ \
+ \
+ /* Is this an X-major or Y-major line? */ \
+ if (DeltaY > DeltaX) { \
+ /* Y-major line; calculate 16-bit fixed-point fractional part of a \
+ pixel that X advances each time Y advances 1 pixel, truncating the \
+ result so that we won't overrun the endpoint along the X axis */ \
+ ErrorAdj = ((unsigned long) DeltaX << 16) / (unsigned long) DeltaY; \
+ /* Draw all pixels other than the first and last */ \
+ while (--DeltaY) { \
+ ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
+ ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
+ if (ErrorAcc <= ErrorAccTemp) { \
+ /* The error accumulator turned over, so advance the X coord */ \
+ x1 += XDir; \
+ } \
+ y1++; /* Y-major, so always advance Y */ \
+ /* The IntensityBits most significant bits of ErrorAcc give us the \
+ intensity weighting for this pixel, and the complement of the \
+ weighting for the paired pixel */ \
+ Weighting = ErrorAcc >> 8; \
+ { \
+ a = DRAW_MUL(_a, (Weighting ^ 255)); \
+ r = DRAW_MUL(_r, a); \
+ g = DRAW_MUL(_g, a); \
+ b = DRAW_MUL(_b, a); \
+ inva = (a ^ 0xFF); \
+ blend_op(x1, y1); \
+ } \
+ { \
+ a = DRAW_MUL(_a, Weighting); \
+ r = DRAW_MUL(_r, a); \
+ g = DRAW_MUL(_g, a); \
+ b = DRAW_MUL(_b, a); \
+ inva = (a ^ 0xFF); \
+ blend_op(x1 + XDir, y1); \
+ } \
+ } \
+ } else { \
+ /* X-major line; calculate 16-bit fixed-point fractional part of a \
+ pixel that Y advances each time X advances 1 pixel, truncating the \
+ result to avoid overrunning the endpoint along the X axis */ \
+ ErrorAdj = ((unsigned long) DeltaY << 16) / (unsigned long) DeltaX; \
+ /* Draw all pixels other than the first and last */ \
+ while (--DeltaX) { \
+ ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
+ ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
+ if (ErrorAcc <= ErrorAccTemp) { \
+ /* The error accumulator turned over, so advance the Y coord */ \
+ y1++; \
+ } \
+ x1 += XDir; /* X-major, so always advance X */ \
+ /* The IntensityBits most significant bits of ErrorAcc give us the \
+ intensity weighting for this pixel, and the complement of the \
+ weighting for the paired pixel */ \
+ Weighting = ErrorAcc >> 8; \
+ { \
+ a = DRAW_MUL(_a, (Weighting ^ 255)); \
+ r = DRAW_MUL(_r, a); \
+ g = DRAW_MUL(_g, a); \
+ b = DRAW_MUL(_b, a); \
+ inva = (a ^ 0xFF); \
+ blend_op(x1, y1); \
+ } \
+ { \
+ a = DRAW_MUL(_a, Weighting); \
+ r = DRAW_MUL(_r, a); \
+ g = DRAW_MUL(_g, a); \
+ b = DRAW_MUL(_b, a); \
+ inva = (a ^ 0xFF); \
+ blend_op(x1, y1 + 1); \
+ } \
+ } \
+ } \
+}
+
+#ifdef AA_LINES
+#define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
+ WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end)
+#else
+#define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
+ BLINE(x1, y1, x2, y2, opaque_op, draw_end)
+#endif
+
+/*
+ * Define fill rect macro
+ */
+
+#define FILLRECT(type, op) \
+do { \
+ int width = rect->w; \
+ int height = rect->h; \
+ int pitch = (dst->pitch / dst->format->BytesPerPixel); \
+ int skip = pitch - width; \
+ type *pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \
+ while (height--) { \
+ { int n = (width+3)/4; \
+ switch (width & 3) { \
+ case 0: do { op; pixel++; /* fallthrough */ \
+ case 3: op; pixel++; /* fallthrough */ \
+ case 2: op; pixel++; /* fallthrough */ \
+ case 1: op; pixel++; /* fallthrough */ \
+ } while ( --n > 0 ); \
+ } \
+ } \
+ pixel += skip; \
+ } \
+} while (0)
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/software/SDL_drawline.c b/src/3rdparty/SDL2/src/render/software/SDL_drawline.c
new file mode 100644
index 0000000..eeb54ed
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/software/SDL_drawline.c
@@ -0,0 +1,209 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if !SDL_RENDER_DISABLED
+
+#include "SDL_draw.h"
+#include "SDL_drawline.h"
+#include "SDL_drawpoint.h"
+
+
+static void
+SDL_DrawLine1(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
+ SDL_bool draw_end)
+{
+ if (y1 == y2) {
+ int length;
+ int pitch = (dst->pitch / dst->format->BytesPerPixel);
+ Uint8 *pixel;
+ if (x1 <= x2) {
+ pixel = (Uint8 *)dst->pixels + y1 * pitch + x1;
+ length = draw_end ? (x2-x1+1) : (x2-x1);
+ } else {
+ pixel = (Uint8 *)dst->pixels + y1 * pitch + x2;
+ if (!draw_end) {
+ ++pixel;
+ }
+ length = draw_end ? (x1-x2+1) : (x1-x2);
+ }
+ SDL_memset(pixel, color, length);
+ } else if (x1 == x2) {
+ VLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end);
+ } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
+ DLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end);
+ } else {
+ BLINE(x1, y1, x2, y2, DRAW_FASTSETPIXELXY1, draw_end);
+ }
+}
+
+static void
+SDL_DrawLine2(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
+ SDL_bool draw_end)
+{
+ if (y1 == y2) {
+ HLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
+ } else if (x1 == x2) {
+ VLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
+ } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
+ DLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
+ } else {
+ Uint8 _r, _g, _b, _a;
+ const SDL_PixelFormat * fmt = dst->format;
+ SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
+ if (fmt->Rmask == 0x7C00) {
+ AALINE(x1, y1, x2, y2,
+ DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB555,
+ draw_end);
+ } else if (fmt->Rmask == 0xF800) {
+ AALINE(x1, y1, x2, y2,
+ DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB565,
+ draw_end);
+ } else {
+ AALINE(x1, y1, x2, y2,
+ DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY2_BLEND_RGB,
+ draw_end);
+ }
+ }
+}
+
+static void
+SDL_DrawLine4(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
+ SDL_bool draw_end)
+{
+ if (y1 == y2) {
+ HLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
+ } else if (x1 == x2) {
+ VLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
+ } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
+ DLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
+ } else {
+ Uint8 _r, _g, _b, _a;
+ const SDL_PixelFormat * fmt = dst->format;
+ SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
+ if (fmt->Rmask == 0x00FF0000) {
+ if (!fmt->Amask) {
+ AALINE(x1, y1, x2, y2,
+ DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_RGB888,
+ draw_end);
+ } else {
+ AALINE(x1, y1, x2, y2,
+ DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_ARGB8888,
+ draw_end);
+ }
+ } else {
+ AALINE(x1, y1, x2, y2,
+ DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY4_BLEND_RGB,
+ draw_end);
+ }
+ }
+}
+
+typedef void (*DrawLineFunc) (SDL_Surface * dst,
+ int x1, int y1, int x2, int y2,
+ Uint32 color, SDL_bool draw_end);
+
+static DrawLineFunc
+SDL_CalculateDrawLineFunc(const SDL_PixelFormat * fmt)
+{
+ switch (fmt->BytesPerPixel) {
+ case 1:
+ if (fmt->BitsPerPixel < 8) {
+ break;
+ }
+ return SDL_DrawLine1;
+ case 2:
+ return SDL_DrawLine2;
+ case 4:
+ return SDL_DrawLine4;
+ }
+ return NULL;
+}
+
+int
+SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
+{
+ DrawLineFunc func;
+
+ if (!dst) {
+ return SDL_SetError("SDL_DrawLine(): Passed NULL destination surface");
+ }
+
+ func = SDL_CalculateDrawLineFunc(dst->format);
+ if (!func) {
+ return SDL_SetError("SDL_DrawLine(): Unsupported surface format");
+ }
+
+ /* Perform clipping */
+ /* FIXME: We don't actually want to clip, as it may change line slope */
+ if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
+ return 0;
+ }
+
+ func(dst, x1, y1, x2, y2, color, SDL_TRUE);
+ return 0;
+}
+
+int
+SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
+ Uint32 color)
+{
+ int i;
+ int x1, y1;
+ int x2, y2;
+ SDL_bool draw_end;
+ DrawLineFunc func;
+
+ if (!dst) {
+ return SDL_SetError("SDL_DrawLines(): Passed NULL destination surface");
+ }
+
+ func = SDL_CalculateDrawLineFunc(dst->format);
+ if (!func) {
+ return SDL_SetError("SDL_DrawLines(): Unsupported surface format");
+ }
+
+ for (i = 1; i < count; ++i) {
+ x1 = points[i-1].x;
+ y1 = points[i-1].y;
+ x2 = points[i].x;
+ y2 = points[i].y;
+
+ /* Perform clipping */
+ /* FIXME: We don't actually want to clip, as it may change line slope */
+ if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
+ continue;
+ }
+
+ /* Draw the end if it was clipped */
+ draw_end = (x2 != points[i].x || y2 != points[i].y);
+
+ func(dst, x1, y1, x2, y2, color, draw_end);
+ }
+ if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
+ SDL_DrawPoint(dst, points[count-1].x, points[count-1].y, color);
+ }
+ return 0;
+}
+
+#endif /* !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/software/SDL_drawline.h b/src/3rdparty/SDL2/src/render/software/SDL_drawline.h
new file mode 100644
index 0000000..9395d50
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/software/SDL_drawline.h
@@ -0,0 +1,27 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+
+extern int SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color);
+extern int SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/software/SDL_drawpoint.c b/src/3rdparty/SDL2/src/render/software/SDL_drawpoint.c
new file mode 100644
index 0000000..64a4e52
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/software/SDL_drawpoint.c
@@ -0,0 +1,114 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if !SDL_RENDER_DISABLED
+
+#include "SDL_draw.h"
+#include "SDL_drawpoint.h"
+
+
+int
+SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color)
+{
+ if (!dst) {
+ return SDL_SetError("Passed NULL destination surface");
+ }
+
+ /* This function doesn't work on surfaces < 8 bpp */
+ if (dst->format->BitsPerPixel < 8) {
+ return SDL_SetError("SDL_DrawPoint(): Unsupported surface format");
+ }
+
+ /* Perform clipping */
+ if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
+ x >= (dst->clip_rect.x + dst->clip_rect.w) ||
+ y >= (dst->clip_rect.y + dst->clip_rect.h)) {
+ return 0;
+ }
+
+ switch (dst->format->BytesPerPixel) {
+ case 1:
+ DRAW_FASTSETPIXELXY1(x, y);
+ break;
+ case 2:
+ DRAW_FASTSETPIXELXY2(x, y);
+ break;
+ case 3:
+ return SDL_Unsupported();
+ case 4:
+ DRAW_FASTSETPIXELXY4(x, y);
+ break;
+ }
+ return 0;
+}
+
+int
+SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count,
+ Uint32 color)
+{
+ int minx, miny;
+ int maxx, maxy;
+ int i;
+ int x, y;
+
+ if (!dst) {
+ return SDL_SetError("Passed NULL destination surface");
+ }
+
+ /* This function doesn't work on surfaces < 8 bpp */
+ if (dst->format->BitsPerPixel < 8) {
+ return SDL_SetError("SDL_DrawPoints(): Unsupported surface format");
+ }
+
+ minx = dst->clip_rect.x;
+ maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
+ miny = dst->clip_rect.y;
+ maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
+
+ for (i = 0; i < count; ++i) {
+ x = points[i].x;
+ y = points[i].y;
+
+ if (x < minx || x > maxx || y < miny || y > maxy) {
+ continue;
+ }
+
+ switch (dst->format->BytesPerPixel) {
+ case 1:
+ DRAW_FASTSETPIXELXY1(x, y);
+ break;
+ case 2:
+ DRAW_FASTSETPIXELXY2(x, y);
+ break;
+ case 3:
+ return SDL_Unsupported();
+ case 4:
+ DRAW_FASTSETPIXELXY4(x, y);
+ break;
+ }
+ }
+ return 0;
+}
+
+#endif /* !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/software/SDL_drawpoint.h b/src/3rdparty/SDL2/src/render/software/SDL_drawpoint.h
new file mode 100644
index 0000000..c366700
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/software/SDL_drawpoint.h
@@ -0,0 +1,27 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+
+extern int SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color);
+extern int SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/software/SDL_render_sw.c b/src/3rdparty/SDL2/src/render/software/SDL_render_sw.c
new file mode 100644
index 0000000..89e54b8
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/software/SDL_render_sw.c
@@ -0,0 +1,894 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if !SDL_RENDER_DISABLED
+
+#include "../SDL_sysrender.h"
+#include "SDL_render_sw_c.h"
+#include "SDL_hints.h"
+
+#include "SDL_draw.h"
+#include "SDL_blendfillrect.h"
+#include "SDL_blendline.h"
+#include "SDL_blendpoint.h"
+#include "SDL_drawline.h"
+#include "SDL_drawpoint.h"
+#include "SDL_rotate.h"
+
+/* SDL surface based renderer implementation */
+
+static SDL_Renderer *SW_CreateRenderer(SDL_Window * window, Uint32 flags);
+static void SW_WindowEvent(SDL_Renderer * renderer,
+ const SDL_WindowEvent *event);
+static int SW_GetOutputSize(SDL_Renderer * renderer, int *w, int *h);
+static int SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+static int SW_SetTextureColorMod(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static int SW_SetTextureAlphaMod(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static int SW_SetTextureBlendMode(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static int SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, const void *pixels,
+ int pitch);
+static int SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, void **pixels, int *pitch);
+static void SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+static int SW_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
+static int SW_UpdateViewport(SDL_Renderer * renderer);
+static int SW_UpdateClipRect(SDL_Renderer * renderer);
+static int SW_RenderClear(SDL_Renderer * renderer);
+static int SW_RenderDrawPoints(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count);
+static int SW_RenderDrawLines(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count);
+static int SW_RenderFillRects(SDL_Renderer * renderer,
+ const SDL_FRect * rects, int count);
+static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect);
+static int SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect,
+ const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip);
+static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 format, void * pixels, int pitch);
+static void SW_RenderPresent(SDL_Renderer * renderer);
+static void SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
+static void SW_DestroyRenderer(SDL_Renderer * renderer);
+
+
+SDL_RenderDriver SW_RenderDriver = {
+ SW_CreateRenderer,
+ {
+ "software",
+ SDL_RENDERER_SOFTWARE | SDL_RENDERER_TARGETTEXTURE,
+ 8,
+ {
+ SDL_PIXELFORMAT_ARGB8888,
+ SDL_PIXELFORMAT_ABGR8888,
+ SDL_PIXELFORMAT_RGBA8888,
+ SDL_PIXELFORMAT_BGRA8888,
+ SDL_PIXELFORMAT_RGB888,
+ SDL_PIXELFORMAT_BGR888,
+ SDL_PIXELFORMAT_RGB565,
+ SDL_PIXELFORMAT_RGB555
+ },
+ 0,
+ 0}
+};
+
+typedef struct
+{
+ SDL_Surface *surface;
+ SDL_Surface *window;
+} SW_RenderData;
+
+
+static SDL_Surface *
+SW_ActivateRenderer(SDL_Renderer * renderer)
+{
+ SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
+
+ if (!data->surface) {
+ data->surface = data->window;
+ }
+ if (!data->surface) {
+ SDL_Surface *surface = SDL_GetWindowSurface(renderer->window);
+ if (surface) {
+ data->surface = data->window = surface;
+
+ SW_UpdateViewport(renderer);
+ SW_UpdateClipRect(renderer);
+ }
+ }
+ return data->surface;
+}
+
+SDL_Renderer *
+SW_CreateRendererForSurface(SDL_Surface * surface)
+{
+ SDL_Renderer *renderer;
+ SW_RenderData *data;
+
+ if (!surface) {
+ SDL_SetError("Can't create renderer for NULL surface");
+ return NULL;
+ }
+
+ renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
+ if (!renderer) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ data = (SW_RenderData *) SDL_calloc(1, sizeof(*data));
+ if (!data) {
+ SW_DestroyRenderer(renderer);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ data->surface = surface;
+ data->window = surface;
+
+ renderer->WindowEvent = SW_WindowEvent;
+ renderer->GetOutputSize = SW_GetOutputSize;
+ renderer->CreateTexture = SW_CreateTexture;
+ renderer->SetTextureColorMod = SW_SetTextureColorMod;
+ renderer->SetTextureAlphaMod = SW_SetTextureAlphaMod;
+ renderer->SetTextureBlendMode = SW_SetTextureBlendMode;
+ renderer->UpdateTexture = SW_UpdateTexture;
+ renderer->LockTexture = SW_LockTexture;
+ renderer->UnlockTexture = SW_UnlockTexture;
+ renderer->SetRenderTarget = SW_SetRenderTarget;
+ renderer->UpdateViewport = SW_UpdateViewport;
+ renderer->UpdateClipRect = SW_UpdateClipRect;
+ renderer->RenderClear = SW_RenderClear;
+ renderer->RenderDrawPoints = SW_RenderDrawPoints;
+ renderer->RenderDrawLines = SW_RenderDrawLines;
+ renderer->RenderFillRects = SW_RenderFillRects;
+ renderer->RenderCopy = SW_RenderCopy;
+ renderer->RenderCopyEx = SW_RenderCopyEx;
+ renderer->RenderReadPixels = SW_RenderReadPixels;
+ renderer->RenderPresent = SW_RenderPresent;
+ renderer->DestroyTexture = SW_DestroyTexture;
+ renderer->DestroyRenderer = SW_DestroyRenderer;
+ renderer->info = SW_RenderDriver.info;
+ renderer->driverdata = data;
+
+ SW_ActivateRenderer(renderer);
+
+ return renderer;
+}
+
+SDL_Renderer *
+SW_CreateRenderer(SDL_Window * window, Uint32 flags)
+{
+ SDL_Surface *surface;
+
+ surface = SDL_GetWindowSurface(window);
+ if (!surface) {
+ return NULL;
+ }
+ return SW_CreateRendererForSurface(surface);
+}
+
+static void
+SW_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
+{
+ SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
+
+ if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
+ data->surface = NULL;
+ data->window = NULL;
+ }
+}
+
+static int
+SW_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
+{
+ SDL_Surface *surface = SW_ActivateRenderer(renderer);
+
+ if (surface) {
+ if (w) {
+ *w = surface->w;
+ }
+ if (h) {
+ *h = surface->h;
+ }
+ return 0;
+ } else {
+ SDL_SetError("Software renderer doesn't have an output surface");
+ return -1;
+ }
+}
+
+static int
+SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ int bpp;
+ Uint32 Rmask, Gmask, Bmask, Amask;
+
+ if (!SDL_PixelFormatEnumToMasks
+ (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
+ return SDL_SetError("Unknown texture format");
+ }
+
+ texture->driverdata =
+ SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask,
+ Bmask, Amask);
+ SDL_SetSurfaceColorMod(texture->driverdata, texture->r, texture->g,
+ texture->b);
+ SDL_SetSurfaceAlphaMod(texture->driverdata, texture->a);
+ SDL_SetSurfaceBlendMode(texture->driverdata, texture->blendMode);
+
+ /* Only RLE encode textures without an alpha channel since the RLE coder
+ * discards the color values of pixels with an alpha value of zero.
+ */
+ if (texture->access == SDL_TEXTUREACCESS_STATIC && !Amask) {
+ SDL_SetSurfaceRLE(texture->driverdata, 1);
+ }
+
+ if (!texture->driverdata) {
+ return -1;
+ }
+ return 0;
+}
+
+static int
+SW_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
+ /* If the color mod is ever enabled (non-white), permanently disable RLE (which doesn't support
+ * color mod) to avoid potentially frequent RLE encoding/decoding.
+ */
+ if ((texture->r & texture->g & texture->b) != 255) {
+ SDL_SetSurfaceRLE(surface, 0);
+ }
+ return SDL_SetSurfaceColorMod(surface, texture->r, texture->g,
+ texture->b);
+}
+
+static int
+SW_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
+ /* If the texture ever has multiple alpha values (surface alpha plus alpha channel), permanently
+ * disable RLE (which doesn't support this) to avoid potentially frequent RLE encoding/decoding.
+ */
+ if (texture->a != 255 && surface->format->Amask) {
+ SDL_SetSurfaceRLE(surface, 0);
+ }
+ return SDL_SetSurfaceAlphaMod(surface, texture->a);
+}
+
+static int
+SW_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
+ /* If add or mod blending are ever enabled, permanently disable RLE (which doesn't support
+ * them) to avoid potentially frequent RLE encoding/decoding.
+ */
+ if ((texture->blendMode == SDL_BLENDMODE_ADD || texture->blendMode == SDL_BLENDMODE_MOD)) {
+ SDL_SetSurfaceRLE(surface, 0);
+ }
+ return SDL_SetSurfaceBlendMode(surface, texture->blendMode);
+}
+
+static int
+SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, const void *pixels, int pitch)
+{
+ SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
+ Uint8 *src, *dst;
+ int row;
+ size_t length;
+
+ if(SDL_MUSTLOCK(surface))
+ SDL_LockSurface(surface);
+ src = (Uint8 *) pixels;
+ dst = (Uint8 *) surface->pixels +
+ rect->y * surface->pitch +
+ rect->x * surface->format->BytesPerPixel;
+ length = rect->w * surface->format->BytesPerPixel;
+ for (row = 0; row < rect->h; ++row) {
+ SDL_memcpy(dst, src, length);
+ src += pitch;
+ dst += surface->pitch;
+ }
+ if(SDL_MUSTLOCK(surface))
+ SDL_UnlockSurface(surface);
+ return 0;
+}
+
+static int
+SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, void **pixels, int *pitch)
+{
+ SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
+
+ *pixels =
+ (void *) ((Uint8 *) surface->pixels + rect->y * surface->pitch +
+ rect->x * surface->format->BytesPerPixel);
+ *pitch = surface->pitch;
+ return 0;
+}
+
+static void
+SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+}
+
+static int
+SW_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
+
+ if (texture ) {
+ data->surface = (SDL_Surface *) texture->driverdata;
+ } else {
+ data->surface = data->window;
+ }
+ return 0;
+}
+
+static int
+SW_UpdateViewport(SDL_Renderer * renderer)
+{
+ SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
+ SDL_Surface *surface = data->surface;
+
+ if (!surface) {
+ /* We'll update the viewport after we recreate the surface */
+ return 0;
+ }
+
+ SDL_SetClipRect(data->surface, &renderer->viewport);
+ return 0;
+}
+
+static int
+SW_UpdateClipRect(SDL_Renderer * renderer)
+{
+ SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
+ SDL_Surface *surface = data->surface;
+ if (surface) {
+ if (renderer->clipping_enabled) {
+ SDL_Rect clip_rect;
+ clip_rect = renderer->clip_rect;
+ clip_rect.x += renderer->viewport.x;
+ clip_rect.y += renderer->viewport.y;
+ SDL_IntersectRect(&renderer->viewport, &clip_rect, &clip_rect);
+ SDL_SetClipRect(surface, &clip_rect);
+ } else {
+ SDL_SetClipRect(surface, &renderer->viewport);
+ }
+ }
+ return 0;
+}
+
+static int
+SW_RenderClear(SDL_Renderer * renderer)
+{
+ SDL_Surface *surface = SW_ActivateRenderer(renderer);
+ Uint32 color;
+ SDL_Rect clip_rect;
+
+ if (!surface) {
+ return -1;
+ }
+
+ color = SDL_MapRGBA(surface->format,
+ renderer->r, renderer->g, renderer->b, renderer->a);
+
+ /* By definition the clear ignores the clip rect */
+ clip_rect = surface->clip_rect;
+ SDL_SetClipRect(surface, NULL);
+ SDL_FillRect(surface, NULL, color);
+ SDL_SetClipRect(surface, &clip_rect);
+ return 0;
+}
+
+static int
+SW_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points,
+ int count)
+{
+ SDL_Surface *surface = SW_ActivateRenderer(renderer);
+ SDL_Point *final_points;
+ int i, status;
+
+ if (!surface) {
+ return -1;
+ }
+
+ final_points = SDL_stack_alloc(SDL_Point, count);
+ if (!final_points) {
+ return SDL_OutOfMemory();
+ }
+ if (renderer->viewport.x || renderer->viewport.y) {
+ int x = renderer->viewport.x;
+ int y = renderer->viewport.y;
+
+ for (i = 0; i < count; ++i) {
+ final_points[i].x = (int)(x + points[i].x);
+ final_points[i].y = (int)(y + points[i].y);
+ }
+ } else {
+ for (i = 0; i < count; ++i) {
+ final_points[i].x = (int)points[i].x;
+ final_points[i].y = (int)points[i].y;
+ }
+ }
+
+ /* Draw the points! */
+ if (renderer->blendMode == SDL_BLENDMODE_NONE) {
+ Uint32 color = SDL_MapRGBA(surface->format,
+ renderer->r, renderer->g, renderer->b,
+ renderer->a);
+
+ status = SDL_DrawPoints(surface, final_points, count, color);
+ } else {
+ status = SDL_BlendPoints(surface, final_points, count,
+ renderer->blendMode,
+ renderer->r, renderer->g, renderer->b,
+ renderer->a);
+ }
+ SDL_stack_free(final_points);
+
+ return status;
+}
+
+static int
+SW_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points,
+ int count)
+{
+ SDL_Surface *surface = SW_ActivateRenderer(renderer);
+ SDL_Point *final_points;
+ int i, status;
+
+ if (!surface) {
+ return -1;
+ }
+
+ final_points = SDL_stack_alloc(SDL_Point, count);
+ if (!final_points) {
+ return SDL_OutOfMemory();
+ }
+ if (renderer->viewport.x || renderer->viewport.y) {
+ int x = renderer->viewport.x;
+ int y = renderer->viewport.y;
+
+ for (i = 0; i < count; ++i) {
+ final_points[i].x = (int)(x + points[i].x);
+ final_points[i].y = (int)(y + points[i].y);
+ }
+ } else {
+ for (i = 0; i < count; ++i) {
+ final_points[i].x = (int)points[i].x;
+ final_points[i].y = (int)points[i].y;
+ }
+ }
+
+ /* Draw the lines! */
+ if (renderer->blendMode == SDL_BLENDMODE_NONE) {
+ Uint32 color = SDL_MapRGBA(surface->format,
+ renderer->r, renderer->g, renderer->b,
+ renderer->a);
+
+ status = SDL_DrawLines(surface, final_points, count, color);
+ } else {
+ status = SDL_BlendLines(surface, final_points, count,
+ renderer->blendMode,
+ renderer->r, renderer->g, renderer->b,
+ renderer->a);
+ }
+ SDL_stack_free(final_points);
+
+ return status;
+}
+
+static int
+SW_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, int count)
+{
+ SDL_Surface *surface = SW_ActivateRenderer(renderer);
+ SDL_Rect *final_rects;
+ int i, status;
+
+ if (!surface) {
+ return -1;
+ }
+
+ final_rects = SDL_stack_alloc(SDL_Rect, count);
+ if (!final_rects) {
+ return SDL_OutOfMemory();
+ }
+ if (renderer->viewport.x || renderer->viewport.y) {
+ int x = renderer->viewport.x;
+ int y = renderer->viewport.y;
+
+ for (i = 0; i < count; ++i) {
+ final_rects[i].x = (int)(x + rects[i].x);
+ final_rects[i].y = (int)(y + rects[i].y);
+ final_rects[i].w = SDL_max((int)rects[i].w, 1);
+ final_rects[i].h = SDL_max((int)rects[i].h, 1);
+ }
+ } else {
+ for (i = 0; i < count; ++i) {
+ final_rects[i].x = (int)rects[i].x;
+ final_rects[i].y = (int)rects[i].y;
+ final_rects[i].w = SDL_max((int)rects[i].w, 1);
+ final_rects[i].h = SDL_max((int)rects[i].h, 1);
+ }
+ }
+
+ if (renderer->blendMode == SDL_BLENDMODE_NONE) {
+ Uint32 color = SDL_MapRGBA(surface->format,
+ renderer->r, renderer->g, renderer->b,
+ renderer->a);
+ status = SDL_FillRects(surface, final_rects, count, color);
+ } else {
+ status = SDL_BlendFillRects(surface, final_rects, count,
+ renderer->blendMode,
+ renderer->r, renderer->g, renderer->b,
+ renderer->a);
+ }
+ SDL_stack_free(final_rects);
+
+ return status;
+}
+
+static int
+SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect)
+{
+ SDL_Surface *surface = SW_ActivateRenderer(renderer);
+ SDL_Surface *src = (SDL_Surface *) texture->driverdata;
+ SDL_Rect final_rect;
+
+ if (!surface) {
+ return -1;
+ }
+
+ if (renderer->viewport.x || renderer->viewport.y) {
+ final_rect.x = (int)(renderer->viewport.x + dstrect->x);
+ final_rect.y = (int)(renderer->viewport.y + dstrect->y);
+ } else {
+ final_rect.x = (int)dstrect->x;
+ final_rect.y = (int)dstrect->y;
+ }
+ final_rect.w = (int)dstrect->w;
+ final_rect.h = (int)dstrect->h;
+
+ if ( srcrect->w == final_rect.w && srcrect->h == final_rect.h ) {
+ return SDL_BlitSurface(src, srcrect, surface, &final_rect);
+ } else {
+ /* If scaling is ever done, permanently disable RLE (which doesn't support scaling)
+ * to avoid potentially frequent RLE encoding/decoding.
+ */
+ SDL_SetSurfaceRLE(surface, 0);
+ return SDL_BlitScaled(src, srcrect, surface, &final_rect);
+ }
+}
+
+static int
+GetScaleQuality(void)
+{
+ const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
+
+ if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
+ return 0;
+ } else {
+ return 1;
+ }
+}
+
+static int
+SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect,
+ const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip)
+{
+ SDL_Surface *surface = SW_ActivateRenderer(renderer);
+ SDL_Surface *src = (SDL_Surface *) texture->driverdata;
+ SDL_Rect final_rect, tmp_rect;
+ SDL_Surface *src_clone, *src_rotated, *src_scaled;
+ SDL_Surface *mask = NULL, *mask_rotated = NULL;
+ int retval = 0, dstwidth, dstheight, abscenterx, abscentery;
+ double cangle, sangle, px, py, p1x, p1y, p2x, p2y, p3x, p3y, p4x, p4y;
+ SDL_BlendMode blendmode;
+ Uint8 alphaMod, rMod, gMod, bMod;
+ int applyModulation = SDL_FALSE;
+ int blitRequired = SDL_FALSE;
+ int isOpaque = SDL_FALSE;
+
+ if (!surface) {
+ return -1;
+ }
+
+ if (renderer->viewport.x || renderer->viewport.y) {
+ final_rect.x = (int)(renderer->viewport.x + dstrect->x);
+ final_rect.y = (int)(renderer->viewport.y + dstrect->y);
+ } else {
+ final_rect.x = (int)dstrect->x;
+ final_rect.y = (int)dstrect->y;
+ }
+ final_rect.w = (int)dstrect->w;
+ final_rect.h = (int)dstrect->h;
+
+ tmp_rect = final_rect;
+ tmp_rect.x = 0;
+ tmp_rect.y = 0;
+
+ /* It is possible to encounter an RLE encoded surface here and locking it is
+ * necessary because this code is going to access the pixel buffer directly.
+ */
+ if (SDL_MUSTLOCK(src)) {
+ SDL_LockSurface(src);
+ }
+
+ /* Clone the source surface but use its pixel buffer directly.
+ * The original source surface must be treated as read-only.
+ */
+ src_clone = SDL_CreateRGBSurfaceFrom(src->pixels, src->w, src->h, src->format->BitsPerPixel, src->pitch,
+ src->format->Rmask, src->format->Gmask,
+ src->format->Bmask, src->format->Amask);
+ if (src_clone == NULL) {
+ if (SDL_MUSTLOCK(src)) {
+ SDL_UnlockSurface(src);
+ }
+ return -1;
+ }
+
+ SDL_GetSurfaceBlendMode(src, &blendmode);
+ SDL_GetSurfaceAlphaMod(src, &alphaMod);
+ SDL_GetSurfaceColorMod(src, &rMod, &gMod, &bMod);
+
+ /* SDLgfx_rotateSurface only accepts 32-bit surfaces with a 8888 layout. Everything else has to be converted. */
+ if (src->format->BitsPerPixel != 32 || SDL_PIXELLAYOUT(src->format->format) != SDL_PACKEDLAYOUT_8888 || !src->format->Amask) {
+ blitRequired = SDL_TRUE;
+ }
+
+ /* If scaling and cropping is necessary, it has to be taken care of before the rotation. */
+ if (!(srcrect->w == final_rect.w && srcrect->h == final_rect.h && srcrect->x == 0 && srcrect->y == 0)) {
+ blitRequired = SDL_TRUE;
+ }
+
+ /* The color and alpha modulation has to be applied before the rotation when using the NONE and MOD blend modes. */
+ if ((blendmode == SDL_BLENDMODE_NONE || blendmode == SDL_BLENDMODE_MOD) && (alphaMod & rMod & gMod & bMod) != 255) {
+ applyModulation = SDL_TRUE;
+ SDL_SetSurfaceAlphaMod(src_clone, alphaMod);
+ SDL_SetSurfaceColorMod(src_clone, rMod, gMod, bMod);
+ }
+
+ /* Opaque surfaces are much easier to handle with the NONE blend mode. */
+ if (blendmode == SDL_BLENDMODE_NONE && !src->format->Amask && alphaMod == 255) {
+ isOpaque = SDL_TRUE;
+ }
+
+ /* The NONE blend mode requires a mask for non-opaque surfaces. This mask will be used
+ * to clear the pixels in the destination surface. The other steps are explained below.
+ */
+ if (blendmode == SDL_BLENDMODE_NONE && !isOpaque) {
+ mask = SDL_CreateRGBSurface(0, final_rect.w, final_rect.h, 32,
+ 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
+ if (mask == NULL) {
+ retval = -1;
+ } else {
+ SDL_SetSurfaceBlendMode(mask, SDL_BLENDMODE_MOD);
+ }
+ }
+
+ /* Create a new surface should there be a format mismatch or if scaling, cropping,
+ * or modulation is required. It's possible to use the source surface directly otherwise.
+ */
+ if (!retval && (blitRequired || applyModulation)) {
+ SDL_Rect scale_rect = tmp_rect;
+ src_scaled = SDL_CreateRGBSurface(0, final_rect.w, final_rect.h, 32,
+ 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
+ if (src_scaled == NULL) {
+ retval = -1;
+ } else {
+ SDL_SetSurfaceBlendMode(src_clone, SDL_BLENDMODE_NONE);
+ retval = SDL_BlitScaled(src_clone, srcrect, src_scaled, &scale_rect);
+ SDL_FreeSurface(src_clone);
+ src_clone = src_scaled;
+ src_scaled = NULL;
+ }
+ }
+
+ /* SDLgfx_rotateSurface is going to make decisions depending on the blend mode. */
+ SDL_SetSurfaceBlendMode(src_clone, blendmode);
+
+ if (!retval) {
+ SDLgfx_rotozoomSurfaceSizeTrig(tmp_rect.w, tmp_rect.h, angle, &dstwidth, &dstheight, &cangle, &sangle);
+ src_rotated = SDLgfx_rotateSurface(src_clone, angle, dstwidth/2, dstheight/2, GetScaleQuality(), flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL, dstwidth, dstheight, cangle, sangle);
+ if (src_rotated == NULL) {
+ retval = -1;
+ }
+ if (!retval && mask != NULL) {
+ /* The mask needed for the NONE blend mode gets rotated with the same parameters. */
+ mask_rotated = SDLgfx_rotateSurface(mask, angle, dstwidth/2, dstheight/2, SDL_FALSE, 0, 0, dstwidth, dstheight, cangle, sangle);
+ if (mask_rotated == NULL) {
+ retval = -1;
+ }
+ }
+ if (!retval) {
+ /* Find out where the new origin is by rotating the four final_rect points around the center and then taking the extremes */
+ abscenterx = final_rect.x + (int)center->x;
+ abscentery = final_rect.y + (int)center->y;
+ /* Compensate the angle inversion to match the behaviour of the other backends */
+ sangle = -sangle;
+
+ /* Top Left */
+ px = final_rect.x - abscenterx;
+ py = final_rect.y - abscentery;
+ p1x = px * cangle - py * sangle + abscenterx;
+ p1y = px * sangle + py * cangle + abscentery;
+
+ /* Top Right */
+ px = final_rect.x + final_rect.w - abscenterx;
+ py = final_rect.y - abscentery;
+ p2x = px * cangle - py * sangle + abscenterx;
+ p2y = px * sangle + py * cangle + abscentery;
+
+ /* Bottom Left */
+ px = final_rect.x - abscenterx;
+ py = final_rect.y + final_rect.h - abscentery;
+ p3x = px * cangle - py * sangle + abscenterx;
+ p3y = px * sangle + py * cangle + abscentery;
+
+ /* Bottom Right */
+ px = final_rect.x + final_rect.w - abscenterx;
+ py = final_rect.y + final_rect.h - abscentery;
+ p4x = px * cangle - py * sangle + abscenterx;
+ p4y = px * sangle + py * cangle + abscentery;
+
+ tmp_rect.x = (int)MIN(MIN(p1x, p2x), MIN(p3x, p4x));
+ tmp_rect.y = (int)MIN(MIN(p1y, p2y), MIN(p3y, p4y));
+ tmp_rect.w = dstwidth;
+ tmp_rect.h = dstheight;
+
+ /* The NONE blend mode needs some special care with non-opaque surfaces.
+ * Other blend modes or opaque surfaces can be blitted directly.
+ */
+ if (blendmode != SDL_BLENDMODE_NONE || isOpaque) {
+ if (applyModulation == SDL_FALSE) {
+ /* If the modulation wasn't already applied, make it happen now. */
+ SDL_SetSurfaceAlphaMod(src_rotated, alphaMod);
+ SDL_SetSurfaceColorMod(src_rotated, rMod, gMod, bMod);
+ }
+ retval = SDL_BlitSurface(src_rotated, NULL, surface, &tmp_rect);
+ } else {
+ /* The NONE blend mode requires three steps to get the pixels onto the destination surface.
+ * First, the area where the rotated pixels will be blitted to get set to zero.
+ * This is accomplished by simply blitting a mask with the NONE blend mode.
+ * The colorkey set by the rotate function will discard the correct pixels.
+ */
+ SDL_Rect mask_rect = tmp_rect;
+ SDL_SetSurfaceBlendMode(mask_rotated, SDL_BLENDMODE_NONE);
+ retval = SDL_BlitSurface(mask_rotated, NULL, surface, &mask_rect);
+ if (!retval) {
+ /* The next step copies the alpha value. This is done with the BLEND blend mode and
+ * by modulating the source colors with 0. Since the destination is all zeros, this
+ * will effectively set the destination alpha to the source alpha.
+ */
+ SDL_SetSurfaceColorMod(src_rotated, 0, 0, 0);
+ mask_rect = tmp_rect;
+ retval = SDL_BlitSurface(src_rotated, NULL, surface, &mask_rect);
+ if (!retval) {
+ /* The last step gets the color values in place. The ADD blend mode simply adds them to
+ * the destination (where the color values are all zero). However, because the ADD blend
+ * mode modulates the colors with the alpha channel, a surface without an alpha mask needs
+ * to be created. This makes all source pixels opaque and the colors get copied correctly.
+ */
+ SDL_Surface *src_rotated_rgb;
+ src_rotated_rgb = SDL_CreateRGBSurfaceFrom(src_rotated->pixels, src_rotated->w, src_rotated->h,
+ src_rotated->format->BitsPerPixel, src_rotated->pitch,
+ src_rotated->format->Rmask, src_rotated->format->Gmask,
+ src_rotated->format->Bmask, 0);
+ if (src_rotated_rgb == NULL) {
+ retval = -1;
+ } else {
+ SDL_SetSurfaceBlendMode(src_rotated_rgb, SDL_BLENDMODE_ADD);
+ retval = SDL_BlitSurface(src_rotated_rgb, NULL, surface, &tmp_rect);
+ SDL_FreeSurface(src_rotated_rgb);
+ }
+ }
+ }
+ SDL_FreeSurface(mask_rotated);
+ }
+ if (src_rotated != NULL) {
+ SDL_FreeSurface(src_rotated);
+ }
+ }
+ }
+
+ if (SDL_MUSTLOCK(src)) {
+ SDL_UnlockSurface(src);
+ }
+ if (mask != NULL) {
+ SDL_FreeSurface(mask);
+ }
+ if (src_clone != NULL) {
+ SDL_FreeSurface(src_clone);
+ }
+ return retval;
+}
+
+static int
+SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 format, void * pixels, int pitch)
+{
+ SDL_Surface *surface = SW_ActivateRenderer(renderer);
+ Uint32 src_format;
+ void *src_pixels;
+
+ if (!surface) {
+ return -1;
+ }
+
+ /* NOTE: The rect is already adjusted according to the viewport by
+ * SDL_RenderReadPixels.
+ */
+
+ if (rect->x < 0 || rect->x+rect->w > surface->w ||
+ rect->y < 0 || rect->y+rect->h > surface->h) {
+ return SDL_SetError("Tried to read outside of surface bounds");
+ }
+
+ src_format = surface->format->format;
+ src_pixels = (void*)((Uint8 *) surface->pixels +
+ rect->y * surface->pitch +
+ rect->x * surface->format->BytesPerPixel);
+
+ return SDL_ConvertPixels(rect->w, rect->h,
+ src_format, src_pixels, surface->pitch,
+ format, pixels, pitch);
+}
+
+static void
+SW_RenderPresent(SDL_Renderer * renderer)
+{
+ SDL_Window *window = renderer->window;
+
+ if (window) {
+ SDL_UpdateWindowSurface(window);
+ }
+}
+
+static void
+SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
+
+ SDL_FreeSurface(surface);
+}
+
+static void
+SW_DestroyRenderer(SDL_Renderer * renderer)
+{
+ SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
+
+ SDL_free(data);
+ SDL_free(renderer);
+}
+
+#endif /* !SDL_RENDER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/software/SDL_render_sw_c.h b/src/3rdparty/SDL2/src/render/software/SDL_render_sw_c.h
new file mode 100644
index 0000000..8f065de
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/software/SDL_render_sw_c.h
@@ -0,0 +1,24 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+extern SDL_Renderer * SW_CreateRendererForSurface(SDL_Surface * surface);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/render/software/SDL_rotate.c b/src/3rdparty/SDL2/src/render/software/SDL_rotate.c
new file mode 100644
index 0000000..4476204
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/software/SDL_rotate.c
@@ -0,0 +1,530 @@
+/*
+
+SDL_rotate.c: rotates 32bit or 8bit surfaces
+
+Shamelessly stolen from SDL_gfx by Andreas Schiffler. Original copyright follows:
+
+Copyright (C) 2001-2011 Andreas Schiffler
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+
+Andreas Schiffler -- aschiffler at ferzkopp dot net
+
+*/
+#include "../../SDL_internal.h"
+
+#if defined(__WIN32__)
+#include "../../core/windows/SDL_windows.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "SDL.h"
+#include "SDL_rotate.h"
+
+/* ---- Internally used structures */
+
+/* !
+\brief A 32 bit RGBA pixel.
+*/
+typedef struct tColorRGBA {
+ Uint8 r;
+ Uint8 g;
+ Uint8 b;
+ Uint8 a;
+} tColorRGBA;
+
+/* !
+\brief A 8bit Y/palette pixel.
+*/
+typedef struct tColorY {
+ Uint8 y;
+} tColorY;
+
+/* !
+\brief Returns maximum of two numbers a and b.
+*/
+#define MAX(a,b) (((a) > (b)) ? (a) : (b))
+
+/* !
+\brief Number of guard rows added to destination surfaces.
+
+This is a simple but effective workaround for observed issues.
+These rows allocate extra memory and are then hidden from the surface.
+Rows are added to the end of destination surfaces when they are allocated.
+This catches any potential overflows which seem to happen with
+just the right src image dimensions and scale/rotation and can lead
+to a situation where the program can segfault.
+*/
+#define GUARD_ROWS (2)
+
+/* !
+\brief Returns colorkey info for a surface
+*/
+static Uint32
+_colorkey(SDL_Surface *src)
+{
+ Uint32 key = 0;
+ SDL_GetColorKey(src, &key);
+ return key;
+}
+
+
+/* !
+\brief Internal target surface sizing function for rotations with trig result return.
+
+\param width The source surface width.
+\param height The source surface height.
+\param angle The angle to rotate in degrees.
+\param dstwidth The calculated width of the destination surface.
+\param dstheight The calculated height of the destination surface.
+\param cangle The sine of the angle
+\param sangle The cosine of the angle
+
+*/
+void
+SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle,
+ int *dstwidth, int *dstheight,
+ double *cangle, double *sangle)
+{
+ /* The trig code below gets the wrong size (due to FP inaccuracy?) when angle is a multiple of 90 degrees */
+ int angle90 = (int)(angle/90);
+ if(angle90 == angle/90) { /* if the angle is a multiple of 90 degrees */
+ angle90 %= 4;
+ if(angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
+ if(angle90 & 1) {
+ *dstwidth = height;
+ *dstheight = width;
+ *cangle = 0;
+ *sangle = angle90 == 1 ? -1 : 1; /* reversed because our rotations are clockwise */
+ } else {
+ *dstwidth = width;
+ *dstheight = height;
+ *cangle = angle90 == 0 ? 1 : -1;
+ *sangle = 0;
+ }
+ } else {
+ double x, y, cx, cy, sx, sy;
+ double radangle;
+ int dstwidthhalf, dstheighthalf;
+ /*
+ * Determine destination width and height by rotating a centered source box
+ */
+ radangle = angle * (M_PI / -180.0); /* reverse the angle because our rotations are clockwise */
+ *sangle = SDL_sin(radangle);
+ *cangle = SDL_cos(radangle);
+ x = (double)(width / 2);
+ y = (double)(height / 2);
+ cx = *cangle * x;
+ cy = *cangle * y;
+ sx = *sangle * x;
+ sy = *sangle * y;
+
+ dstwidthhalf = MAX((int)
+ SDL_ceil(MAX(MAX(MAX(SDL_fabs(cx + sy), SDL_fabs(cx - sy)), SDL_fabs(-cx + sy)), SDL_fabs(-cx - sy))), 1);
+ dstheighthalf = MAX((int)
+ SDL_ceil(MAX(MAX(MAX(SDL_fabs(sx + cy), SDL_fabs(sx - cy)), SDL_fabs(-sx + cy)), SDL_fabs(-sx - cy))), 1);
+ *dstwidth = 2 * dstwidthhalf;
+ *dstheight = 2 * dstheighthalf;
+ }
+}
+
+/* Computes source pointer X/Y increments for a rotation that's a multiple of 90 degrees. */
+static void
+computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int flipy,
+ int *sincx, int *sincy, int *signx, int *signy)
+{
+ int pitch = flipy ? -src->pitch : src->pitch;
+ if (flipx) {
+ bpp = -bpp;
+ }
+ switch (angle) { /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
+ case 0: *sincx = bpp; *sincy = pitch - src->w * *sincx; *signx = *signy = 1; break;
+ case 1: *sincx = -pitch; *sincy = bpp - *sincx * src->h; *signx = 1; *signy = -1; break;
+ case 2: *sincx = -bpp; *sincy = -src->w * *sincx - pitch; *signx = *signy = -1; break;
+ case 3: default: *sincx = pitch; *sincy = -*sincx * src->h - bpp; *signx = -1; *signy = 1; break;
+ }
+ if (flipx) {
+ *signx = -*signx;
+ }
+ if (flipy) {
+ *signy = -*signy;
+ }
+}
+
+/* Performs a relatively fast rotation/flip when the angle is a multiple of 90 degrees. */
+#define TRANSFORM_SURFACE_90(pixelType) \
+ int dy, dincy = dst->pitch - dst->w*sizeof(pixelType), sincx, sincy, signx, signy; \
+ Uint8 *sp = (Uint8*)src->pixels, *dp = (Uint8*)dst->pixels, *de; \
+ \
+ computeSourceIncrements90(src, sizeof(pixelType), angle, flipx, flipy, &sincx, &sincy, &signx, &signy); \
+ if (signx < 0) sp += (src->w-1)*sizeof(pixelType); \
+ if (signy < 0) sp += (src->h-1)*src->pitch; \
+ \
+ for (dy = 0; dy < dst->h; sp += sincy, dp += dincy, dy++) { \
+ if (sincx == sizeof(pixelType)) { /* if advancing src and dest equally, use memcpy */ \
+ SDL_memcpy(dp, sp, dst->w*sizeof(pixelType)); \
+ sp += dst->w*sizeof(pixelType); \
+ dp += dst->w*sizeof(pixelType); \
+ } else { \
+ for (de = dp + dst->w*sizeof(pixelType); dp != de; sp += sincx, dp += sizeof(pixelType)) { \
+ *(pixelType*)dp = *(pixelType*)sp; \
+ } \
+ } \
+ }
+
+static void
+transformSurfaceRGBA90(SDL_Surface * src, SDL_Surface * dst, int angle, int flipx, int flipy)
+{
+ TRANSFORM_SURFACE_90(tColorRGBA);
+}
+
+static void
+transformSurfaceY90(SDL_Surface * src, SDL_Surface * dst, int angle, int flipx, int flipy)
+{
+ TRANSFORM_SURFACE_90(tColorY);
+}
+
+#undef TRANSFORM_SURFACE_90
+
+/* !
+\brief Internal 32 bit rotozoomer with optional anti-aliasing.
+
+Rotates and zooms 32 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control
+parameters by scanning the destination surface and applying optionally anti-aliasing
+by bilinear interpolation.
+Assumes src and dst surfaces are of 32 bit depth.
+Assumes dst surface was allocated with the correct dimensions.
+
+\param src Source surface.
+\param dst Destination surface.
+\param cx Horizontal center coordinate.
+\param cy Vertical center coordinate.
+\param isin Integer version of sine of angle.
+\param icos Integer version of cosine of angle.
+\param flipx Flag indicating horizontal mirroring should be applied.
+\param flipy Flag indicating vertical mirroring should be applied.
+\param smooth Flag indicating anti-aliasing should be used.
+*/
+static void
+_transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy, int smooth)
+{
+ int x, y, t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh;
+ tColorRGBA c00, c01, c10, c11, cswap;
+ tColorRGBA *pc, *sp;
+ int gap;
+
+ /*
+ * Variable setup
+ */
+ xd = ((src->w - dst->w) << 15);
+ yd = ((src->h - dst->h) << 15);
+ ax = (cx << 16) - (icos * cx);
+ ay = (cy << 16) - (isin * cx);
+ sw = src->w - 1;
+ sh = src->h - 1;
+ pc = (tColorRGBA*) dst->pixels;
+ gap = dst->pitch - dst->w * 4;
+
+ /*
+ * Switch between interpolating and non-interpolating code
+ */
+ if (smooth) {
+ for (y = 0; y < dst->h; y++) {
+ dy = cy - y;
+ sdx = (ax + (isin * dy)) + xd;
+ sdy = (ay - (icos * dy)) + yd;
+ for (x = 0; x < dst->w; x++) {
+ dx = (sdx >> 16);
+ dy = (sdy >> 16);
+ if (flipx) dx = sw - dx;
+ if (flipy) dy = sh - dy;
+ if ((dx > -1) && (dy > -1) && (dx < (src->w-1)) && (dy < (src->h-1))) {
+ sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy) + dx;
+ c00 = *sp;
+ sp += 1;
+ c01 = *sp;
+ sp += (src->pitch/4);
+ c11 = *sp;
+ sp -= 1;
+ c10 = *sp;
+ if (flipx) {
+ cswap = c00; c00=c01; c01=cswap;
+ cswap = c10; c10=c11; c11=cswap;
+ }
+ if (flipy) {
+ cswap = c00; c00=c10; c10=cswap;
+ cswap = c01; c01=c11; c11=cswap;
+ }
+ /*
+ * Interpolate colors
+ */
+ ex = (sdx & 0xffff);
+ ey = (sdy & 0xffff);
+ t1 = ((((c01.r - c00.r) * ex) >> 16) + c00.r) & 0xff;
+ t2 = ((((c11.r - c10.r) * ex) >> 16) + c10.r) & 0xff;
+ pc->r = (((t2 - t1) * ey) >> 16) + t1;
+ t1 = ((((c01.g - c00.g) * ex) >> 16) + c00.g) & 0xff;
+ t2 = ((((c11.g - c10.g) * ex) >> 16) + c10.g) & 0xff;
+ pc->g = (((t2 - t1) * ey) >> 16) + t1;
+ t1 = ((((c01.b - c00.b) * ex) >> 16) + c00.b) & 0xff;
+ t2 = ((((c11.b - c10.b) * ex) >> 16) + c10.b) & 0xff;
+ pc->b = (((t2 - t1) * ey) >> 16) + t1;
+ t1 = ((((c01.a - c00.a) * ex) >> 16) + c00.a) & 0xff;
+ t2 = ((((c11.a - c10.a) * ex) >> 16) + c10.a) & 0xff;
+ pc->a = (((t2 - t1) * ey) >> 16) + t1;
+ }
+ sdx += icos;
+ sdy += isin;
+ pc++;
+ }
+ pc = (tColorRGBA *) ((Uint8 *) pc + gap);
+ }
+ } else {
+ for (y = 0; y < dst->h; y++) {
+ dy = cy - y;
+ sdx = (ax + (isin * dy)) + xd;
+ sdy = (ay - (icos * dy)) + yd;
+ for (x = 0; x < dst->w; x++) {
+ dx = (sdx >> 16);
+ dy = (sdy >> 16);
+ if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) {
+ if(flipx) dx = sw - dx;
+ if(flipy) dy = sh - dy;
+ *pc = *((tColorRGBA *)((Uint8 *)src->pixels + src->pitch * dy) + dx);
+ }
+ sdx += icos;
+ sdy += isin;
+ pc++;
+ }
+ pc = (tColorRGBA *) ((Uint8 *) pc + gap);
+ }
+ }
+}
+
+/* !
+
+\brief Rotates and zooms 8 bit palette/Y 'src' surface to 'dst' surface without smoothing.
+
+Rotates and zooms 8 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control
+parameters by scanning the destination surface.
+Assumes src and dst surfaces are of 8 bit depth.
+Assumes dst surface was allocated with the correct dimensions.
+
+\param src Source surface.
+\param dst Destination surface.
+\param cx Horizontal center coordinate.
+\param cy Vertical center coordinate.
+\param isin Integer version of sine of angle.
+\param icos Integer version of cosine of angle.
+\param flipx Flag indicating horizontal mirroring should be applied.
+\param flipy Flag indicating vertical mirroring should be applied.
+*/
+static void
+transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy)
+{
+ int x, y, dx, dy, xd, yd, sdx, sdy, ax, ay;
+ tColorY *pc;
+ int gap;
+
+ /*
+ * Variable setup
+ */
+ xd = ((src->w - dst->w) << 15);
+ yd = ((src->h - dst->h) << 15);
+ ax = (cx << 16) - (icos * cx);
+ ay = (cy << 16) - (isin * cx);
+ pc = (tColorY*) dst->pixels;
+ gap = dst->pitch - dst->w;
+ /*
+ * Clear surface to colorkey
+ */
+ SDL_memset(pc, (int)(_colorkey(src) & 0xff), dst->pitch * dst->h);
+ /*
+ * Iterate through destination surface
+ */
+ for (y = 0; y < dst->h; y++) {
+ dy = cy - y;
+ sdx = (ax + (isin * dy)) + xd;
+ sdy = (ay - (icos * dy)) + yd;
+ for (x = 0; x < dst->w; x++) {
+ dx = (sdx >> 16);
+ dy = (sdy >> 16);
+ if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) {
+ if (flipx) dx = (src->w-1)-dx;
+ if (flipy) dy = (src->h-1)-dy;
+ *pc = *((tColorY *)src->pixels + src->pitch * dy + dx);
+ }
+ sdx += icos;
+ sdy += isin;
+ pc++;
+ }
+ pc += gap;
+ }
+}
+
+
+/* !
+\brief Rotates and zooms a surface with different horizontal and vertival scaling factors and optional anti-aliasing.
+
+Rotates a 32-bit or 8-bit 'src' surface to newly created 'dst' surface.
+'angle' is the rotation in degrees, 'centerx' and 'centery' the rotation center. If 'smooth' is set
+then the destination 32-bit surface is anti-aliased. 8-bit surfaces must have a colorkey. 32-bit
+surfaces must have a 8888 layout with red, green, blue and alpha masks (any ordering goes).
+The blend mode of the 'src' surface has some effects on generation of the 'dst' surface: The NONE
+mode will set the BLEND mode on the 'dst' surface. The MOD mode either generates a white 'dst'
+surface and sets the colorkey or fills the it with the colorkey before copying the pixels.
+When using the NONE and MOD modes, color and alpha modulation must be applied before using this function.
+
+\param src The surface to rotozoom.
+\param angle The angle to rotate in degrees.
+\param centerx The horizontal coordinate of the center of rotation
+\param zoomy The vertical coordinate of the center of rotation
+\param smooth Antialiasing flag; set to SMOOTHING_ON to enable.
+\param flipx Set to 1 to flip the image horizontally
+\param flipy Set to 1 to flip the image vertically
+\param dstwidth The destination surface width
+\param dstheight The destination surface height
+\param cangle The angle cosine
+\param sangle The angle sine
+\return The new rotated surface.
+
+*/
+
+SDL_Surface *
+SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery, int smooth, int flipx, int flipy, int dstwidth, int dstheight, double cangle, double sangle)
+{
+ SDL_Surface *rz_dst;
+ int is8bit, angle90;
+ int i;
+ SDL_BlendMode blendmode;
+ Uint32 colorkey = 0;
+ int colorKeyAvailable = SDL_FALSE;
+ double sangleinv, cangleinv;
+
+ /* Sanity check */
+ if (src == NULL)
+ return NULL;
+
+ if (SDL_GetColorKey(src, &colorkey) == 0) {
+ colorKeyAvailable = SDL_TRUE;
+ }
+
+ /* This function requires a 32-bit surface or 8-bit surface with a colorkey */
+ is8bit = src->format->BitsPerPixel == 8 && colorKeyAvailable;
+ if (!(is8bit || (src->format->BitsPerPixel == 32 && src->format->Amask)))
+ return NULL;
+
+ /* Calculate target factors from sin/cos and zoom */
+ sangleinv = sangle*65536.0;
+ cangleinv = cangle*65536.0;
+
+ /* Alloc space to completely contain the rotated surface */
+ rz_dst = NULL;
+ if (is8bit) {
+ /* Target surface is 8 bit */
+ rz_dst = SDL_CreateRGBSurface(0, dstwidth, dstheight + GUARD_ROWS, 8, 0, 0, 0, 0);
+ if (rz_dst != NULL) {
+ for (i = 0; i < src->format->palette->ncolors; i++) {
+ rz_dst->format->palette->colors[i] = src->format->palette->colors[i];
+ }
+ rz_dst->format->palette->ncolors = src->format->palette->ncolors;
+ }
+ } else {
+ /* Target surface is 32 bit with source RGBA ordering */
+ rz_dst = SDL_CreateRGBSurface(0, dstwidth, dstheight + GUARD_ROWS, 32,
+ src->format->Rmask, src->format->Gmask,
+ src->format->Bmask, src->format->Amask);
+ }
+
+ /* Check target */
+ if (rz_dst == NULL)
+ return NULL;
+
+ /* Adjust for guard rows */
+ rz_dst->h = dstheight;
+
+ SDL_GetSurfaceBlendMode(src, &blendmode);
+
+ if (colorKeyAvailable == SDL_TRUE) {
+ /* If available, the colorkey will be used to discard the pixels that are outside of the rotated area. */
+ SDL_SetColorKey(rz_dst, SDL_TRUE, colorkey);
+ SDL_FillRect(rz_dst, NULL, colorkey);
+ } else if (blendmode == SDL_BLENDMODE_NONE) {
+ blendmode = SDL_BLENDMODE_BLEND;
+ } else if (blendmode == SDL_BLENDMODE_MOD) {
+ /* Without a colorkey, the target texture has to be white for the MOD blend mode so
+ * that the pixels outside the rotated area don't affect the destination surface.
+ */
+ colorkey = SDL_MapRGBA(rz_dst->format, 255, 255, 255, 0);
+ SDL_FillRect(rz_dst, NULL, colorkey);
+ /* Setting a white colorkey for the destination surface makes the final blit discard
+ * all pixels outside of the rotated area. This doesn't interfere with anything because
+ * white pixels are already a no-op and the MOD blend mode does not interact with alpha.
+ */
+ SDL_SetColorKey(rz_dst, SDL_TRUE, colorkey);
+ }
+
+ SDL_SetSurfaceBlendMode(rz_dst, blendmode);
+
+ /* Lock source surface */
+ if (SDL_MUSTLOCK(src)) {
+ SDL_LockSurface(src);
+ }
+
+ /* check if the rotation is a multiple of 90 degrees so we can take a fast path and also somewhat reduce
+ * the off-by-one problem in _transformSurfaceRGBA that expresses itself when the rotation is near
+ * multiples of 90 degrees.
+ */
+ angle90 = (int)(angle/90);
+ if (angle90 == angle/90) {
+ angle90 %= 4;
+ if (angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
+ } else {
+ angle90 = -1;
+ }
+
+ if (is8bit) {
+ /* Call the 8-bit transformation routine to do the rotation */
+ if(angle90 >= 0) {
+ transformSurfaceY90(src, rz_dst, angle90, flipx, flipy);
+ } else {
+ transformSurfaceY(src, rz_dst, centerx, centery, (int)sangleinv, (int)cangleinv,
+ flipx, flipy);
+ }
+ } else {
+ /* Call the 32-bit transformation routine to do the rotation */
+ if (angle90 >= 0) {
+ transformSurfaceRGBA90(src, rz_dst, angle90, flipx, flipy);
+ } else {
+ _transformSurfaceRGBA(src, rz_dst, centerx, centery, (int)sangleinv, (int)cangleinv,
+ flipx, flipy, smooth);
+ }
+ }
+
+ /* Unlock source surface */
+ if (SDL_MUSTLOCK(src)) {
+ SDL_UnlockSurface(src);
+ }
+
+ /* Return rotated surface */
+ return rz_dst;
+}
diff --git a/src/3rdparty/SDL2/src/render/software/SDL_rotate.h b/src/3rdparty/SDL2/src/render/software/SDL_rotate.h
new file mode 100644
index 0000000..2bf2ea8
--- /dev/null
+++ b/src/3rdparty/SDL2/src/render/software/SDL_rotate.h
@@ -0,0 +1,28 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef MIN
+#define MIN(a,b) (((a) < (b)) ? (a) : (b))
+#endif
+
+extern SDL_Surface *SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery, int smooth, int flipx, int flipy, int dstwidth, int dstheight, double cangle, double sangle);
+extern void SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, int *dstwidth, int *dstheight, double *cangle, double *sangle);
+
diff --git a/src/3rdparty/SDL2/src/stdlib/SDL_getenv.c b/src/3rdparty/SDL2/src/stdlib/SDL_getenv.c
new file mode 100644
index 0000000..591a314
--- /dev/null
+++ b/src/3rdparty/SDL2/src/stdlib/SDL_getenv.c
@@ -0,0 +1,315 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
+#define SDL_DISABLE_ANALYZE_MACROS 1
+#endif
+
+#include "../SDL_internal.h"
+
+#if defined(__WIN32__)
+#include "../core/windows/SDL_windows.h"
+#endif
+
+#if defined(__ANDROID__)
+#include "../core/android/SDL_android.h"
+#endif
+
+#include "SDL_stdinc.h"
+
+#if defined(__WIN32__) && (!defined(HAVE_SETENV) || !defined(HAVE_GETENV))
+/* Note this isn't thread-safe! */
+static char *SDL_envmem = NULL; /* Ugh, memory leak */
+static size_t SDL_envmemlen = 0;
+#endif
+
+/* Put a variable into the environment */
+/* Note: Name may not contain a '=' character. (Reference: http://www.unix.com/man-page/Linux/3/setenv/) */
+#if defined(HAVE_SETENV)
+int
+SDL_setenv(const char *name, const char *value, int overwrite)
+{
+ /* Input validation */
+ if (!name || SDL_strlen(name) == 0 || SDL_strchr(name, '=') != NULL || !value) {
+ return (-1);
+ }
+
+ return setenv(name, value, overwrite);
+}
+#elif defined(__WIN32__)
+int
+SDL_setenv(const char *name, const char *value, int overwrite)
+{
+ /* Input validation */
+ if (!name || SDL_strlen(name) == 0 || SDL_strchr(name, '=') != NULL || !value) {
+ return (-1);
+ }
+
+ if (!overwrite) {
+ if (GetEnvironmentVariableA(name, NULL, 0) > 0) {
+ return 0; /* asked not to overwrite existing value. */
+ }
+ }
+ if (!SetEnvironmentVariableA(name, *value ? value : NULL)) {
+ return -1;
+ }
+ return 0;
+}
+/* We have a real environment table, but no real setenv? Fake it w/ putenv. */
+#elif (defined(HAVE_GETENV) && defined(HAVE_PUTENV) && !defined(HAVE_SETENV))
+int
+SDL_setenv(const char *name, const char *value, int overwrite)
+{
+ size_t len;
+ char *new_variable;
+
+ /* Input validation */
+ if (!name || SDL_strlen(name) == 0 || SDL_strchr(name, '=') != NULL || !value) {
+ return (-1);
+ }
+
+ if (getenv(name) != NULL) {
+ if (overwrite) {
+ unsetenv(name);
+ } else {
+ return 0; /* leave the existing one there. */
+ }
+ }
+
+ /* This leaks. Sorry. Get a better OS so we don't have to do this. */
+ len = SDL_strlen(name) + SDL_strlen(value) + 2;
+ new_variable = (char *) SDL_malloc(len);
+ if (!new_variable) {
+ return (-1);
+ }
+
+ SDL_snprintf(new_variable, len, "%s=%s", name, value);
+ return putenv(new_variable);
+}
+#else /* roll our own */
+static char **SDL_env = (char **) 0;
+int
+SDL_setenv(const char *name, const char *value, int overwrite)
+{
+ int added;
+ int len, i;
+ char **new_env;
+ char *new_variable;
+
+ /* Input validation */
+ if (!name || SDL_strlen(name) == 0 || SDL_strchr(name, '=') != NULL || !value) {
+ return (-1);
+ }
+
+ /* See if it already exists */
+ if (!overwrite && SDL_getenv(name)) {
+ return 0;
+ }
+
+ /* Allocate memory for the variable */
+ len = SDL_strlen(name) + SDL_strlen(value) + 2;
+ new_variable = (char *) SDL_malloc(len);
+ if (!new_variable) {
+ return (-1);
+ }
+
+ SDL_snprintf(new_variable, len, "%s=%s", name, value);
+ value = new_variable + SDL_strlen(name) + 1;
+ name = new_variable;
+
+ /* Actually put it into the environment */
+ added = 0;
+ i = 0;
+ if (SDL_env) {
+ /* Check to see if it's already there... */
+ len = (value - name);
+ for (; SDL_env[i]; ++i) {
+ if (SDL_strncmp(SDL_env[i], name, len) == 0) {
+ break;
+ }
+ }
+ /* If we found it, just replace the entry */
+ if (SDL_env[i]) {
+ SDL_free(SDL_env[i]);
+ SDL_env[i] = new_variable;
+ added = 1;
+ }
+ }
+
+ /* Didn't find it in the environment, expand and add */
+ if (!added) {
+ new_env = SDL_realloc(SDL_env, (i + 2) * sizeof(char *));
+ if (new_env) {
+ SDL_env = new_env;
+ SDL_env[i++] = new_variable;
+ SDL_env[i++] = (char *) 0;
+ added = 1;
+ } else {
+ SDL_free(new_variable);
+ }
+ }
+ return (added ? 0 : -1);
+}
+#endif
+
+/* Retrieve a variable named "name" from the environment */
+#if defined(HAVE_GETENV)
+char *
+SDL_getenv(const char *name)
+{
+#if defined(__ANDROID__)
+ /* Make sure variables from the application manifest are available */
+ Android_JNI_GetManifestEnvironmentVariables();
+#endif
+
+ /* Input validation */
+ if (!name || !*name) {
+ return NULL;
+ }
+
+ return getenv(name);
+}
+#elif defined(__WIN32__)
+char *
+SDL_getenv(const char *name)
+{
+ size_t bufferlen;
+
+ /* Input validation */
+ if (!name || SDL_strlen(name)==0) {
+ return NULL;
+ }
+
+ bufferlen =
+ GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
+ if (bufferlen == 0) {
+ return NULL;
+ }
+ if (bufferlen > SDL_envmemlen) {
+ char *newmem = (char *) SDL_realloc(SDL_envmem, bufferlen);
+ if (newmem == NULL) {
+ return NULL;
+ }
+ SDL_envmem = newmem;
+ SDL_envmemlen = bufferlen;
+ GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
+ }
+ return SDL_envmem;
+}
+#else
+char *
+SDL_getenv(const char *name)
+{
+ int len, i;
+ char *value;
+
+ /* Input validation */
+ if (!name || SDL_strlen(name)==0) {
+ return NULL;
+ }
+
+ value = (char *) 0;
+ if (SDL_env) {
+ len = SDL_strlen(name);
+ for (i = 0; SDL_env[i] && !value; ++i) {
+ if ((SDL_strncmp(SDL_env[i], name, len) == 0) &&
+ (SDL_env[i][len] == '=')) {
+ value = &SDL_env[i][len + 1];
+ }
+ }
+ }
+ return value;
+}
+#endif
+
+
+#ifdef TEST_MAIN
+#include <stdio.h>
+
+int
+main(int argc, char *argv[])
+{
+ char *value;
+
+ printf("Checking for non-existent variable... ");
+ fflush(stdout);
+ if (!SDL_getenv("EXISTS")) {
+ printf("okay\n");
+ } else {
+ printf("failed\n");
+ }
+ printf("Setting FIRST=VALUE1 in the environment... ");
+ fflush(stdout);
+ if (SDL_setenv("FIRST", "VALUE1", 0) == 0) {
+ printf("okay\n");
+ } else {
+ printf("failed\n");
+ }
+ printf("Getting FIRST from the environment... ");
+ fflush(stdout);
+ value = SDL_getenv("FIRST");
+ if (value && (SDL_strcmp(value, "VALUE1") == 0)) {
+ printf("okay\n");
+ } else {
+ printf("failed\n");
+ }
+ printf("Setting SECOND=VALUE2 in the environment... ");
+ fflush(stdout);
+ if (SDL_setenv("SECOND", "VALUE2", 0) == 0) {
+ printf("okay\n");
+ } else {
+ printf("failed\n");
+ }
+ printf("Getting SECOND from the environment... ");
+ fflush(stdout);
+ value = SDL_getenv("SECOND");
+ if (value && (SDL_strcmp(value, "VALUE2") == 0)) {
+ printf("okay\n");
+ } else {
+ printf("failed\n");
+ }
+ printf("Setting FIRST=NOVALUE in the environment... ");
+ fflush(stdout);
+ if (SDL_setenv("FIRST", "NOVALUE", 1) == 0) {
+ printf("okay\n");
+ } else {
+ printf("failed\n");
+ }
+ printf("Getting FIRST from the environment... ");
+ fflush(stdout);
+ value = SDL_getenv("FIRST");
+ if (value && (SDL_strcmp(value, "NOVALUE") == 0)) {
+ printf("okay\n");
+ } else {
+ printf("failed\n");
+ }
+ printf("Checking for non-existent variable... ");
+ fflush(stdout);
+ if (!SDL_getenv("EXISTS")) {
+ printf("okay\n");
+ } else {
+ printf("failed\n");
+ }
+ return (0);
+}
+#endif /* TEST_MAIN */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/stdlib/SDL_iconv.c b/src/3rdparty/SDL2/src/stdlib/SDL_iconv.c
new file mode 100644
index 0000000..f8dbc9f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/stdlib/SDL_iconv.c
@@ -0,0 +1,934 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
+#define SDL_DISABLE_ANALYZE_MACROS 1
+#endif
+
+#include "../SDL_internal.h"
+
+/* This file contains portable iconv functions for SDL */
+
+#include "SDL_stdinc.h"
+#include "SDL_endian.h"
+
+#if defined(HAVE_ICONV) && defined(HAVE_ICONV_H)
+#include <iconv.h>
+
+/* Depending on which standard the iconv() was implemented with,
+ iconv() may or may not use const char ** for the inbuf param.
+ If we get this wrong, it's just a warning, so no big deal.
+*/
+#if defined(_XGP6) || defined(__APPLE__) || \
+ defined(__EMSCRIPTEN__) || \
+ (defined(__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) || \
+ (defined(_NEWLIB_VERSION)))
+#define ICONV_INBUF_NONCONST
+#endif
+
+#include <errno.h>
+
+SDL_COMPILE_TIME_ASSERT(iconv_t, sizeof (iconv_t) <= sizeof (SDL_iconv_t));
+
+SDL_iconv_t
+SDL_iconv_open(const char *tocode, const char *fromcode)
+{
+ return (SDL_iconv_t) ((size_t) iconv_open(tocode, fromcode));
+}
+
+int
+SDL_iconv_close(SDL_iconv_t cd)
+{
+ return iconv_close((iconv_t) ((size_t) cd));
+}
+
+size_t
+SDL_iconv(SDL_iconv_t cd,
+ const char **inbuf, size_t * inbytesleft,
+ char **outbuf, size_t * outbytesleft)
+{
+ size_t retCode;
+#ifdef ICONV_INBUF_NONCONST
+ retCode = iconv((iconv_t) ((size_t) cd), (char **) inbuf, inbytesleft, outbuf, outbytesleft);
+#else
+ retCode = iconv((iconv_t) ((size_t) cd), inbuf, inbytesleft, outbuf, outbytesleft);
+#endif
+ if (retCode == (size_t) - 1) {
+ switch (errno) {
+ case E2BIG:
+ return SDL_ICONV_E2BIG;
+ case EILSEQ:
+ return SDL_ICONV_EILSEQ;
+ case EINVAL:
+ return SDL_ICONV_EINVAL;
+ default:
+ return SDL_ICONV_ERROR;
+ }
+ }
+ return retCode;
+}
+
+#else
+
+/* Lots of useful information on Unicode at:
+ http://www.cl.cam.ac.uk/~mgk25/unicode.html
+*/
+
+#define UNICODE_BOM 0xFEFF
+
+#define UNKNOWN_ASCII '?'
+#define UNKNOWN_UNICODE 0xFFFD
+
+enum
+{
+ ENCODING_UNKNOWN,
+ ENCODING_ASCII,
+ ENCODING_LATIN1,
+ ENCODING_UTF8,
+ ENCODING_UTF16, /* Needs byte order marker */
+ ENCODING_UTF16BE,
+ ENCODING_UTF16LE,
+ ENCODING_UTF32, /* Needs byte order marker */
+ ENCODING_UTF32BE,
+ ENCODING_UTF32LE,
+ ENCODING_UCS2BE,
+ ENCODING_UCS2LE,
+ ENCODING_UCS4BE,
+ ENCODING_UCS4LE,
+};
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+#define ENCODING_UTF16NATIVE ENCODING_UTF16BE
+#define ENCODING_UTF32NATIVE ENCODING_UTF32BE
+#define ENCODING_UCS2NATIVE ENCODING_UCS2BE
+#define ENCODING_UCS4NATIVE ENCODING_UCS4BE
+#else
+#define ENCODING_UTF16NATIVE ENCODING_UTF16LE
+#define ENCODING_UTF32NATIVE ENCODING_UTF32LE
+#define ENCODING_UCS2NATIVE ENCODING_UCS2LE
+#define ENCODING_UCS4NATIVE ENCODING_UCS4LE
+#endif
+
+struct _SDL_iconv_t
+{
+ int src_fmt;
+ int dst_fmt;
+};
+
+static struct
+{
+ const char *name;
+ int format;
+} encodings[] = {
+/* *INDENT-OFF* */
+ { "ASCII", ENCODING_ASCII },
+ { "US-ASCII", ENCODING_ASCII },
+ { "8859-1", ENCODING_LATIN1 },
+ { "ISO-8859-1", ENCODING_LATIN1 },
+ { "UTF8", ENCODING_UTF8 },
+ { "UTF-8", ENCODING_UTF8 },
+ { "UTF16", ENCODING_UTF16 },
+ { "UTF-16", ENCODING_UTF16 },
+ { "UTF16BE", ENCODING_UTF16BE },
+ { "UTF-16BE", ENCODING_UTF16BE },
+ { "UTF16LE", ENCODING_UTF16LE },
+ { "UTF-16LE", ENCODING_UTF16LE },
+ { "UTF32", ENCODING_UTF32 },
+ { "UTF-32", ENCODING_UTF32 },
+ { "UTF32BE", ENCODING_UTF32BE },
+ { "UTF-32BE", ENCODING_UTF32BE },
+ { "UTF32LE", ENCODING_UTF32LE },
+ { "UTF-32LE", ENCODING_UTF32LE },
+ { "UCS2", ENCODING_UCS2BE },
+ { "UCS-2", ENCODING_UCS2BE },
+ { "UCS-2LE", ENCODING_UCS2LE },
+ { "UCS-2BE", ENCODING_UCS2BE },
+ { "UCS-2-INTERNAL", ENCODING_UCS2NATIVE },
+ { "UCS4", ENCODING_UCS4BE },
+ { "UCS-4", ENCODING_UCS4BE },
+ { "UCS-4LE", ENCODING_UCS4LE },
+ { "UCS-4BE", ENCODING_UCS4BE },
+ { "UCS-4-INTERNAL", ENCODING_UCS4NATIVE },
+/* *INDENT-ON* */
+};
+
+static const char *
+getlocale(char *buffer, size_t bufsize)
+{
+ const char *lang;
+ char *ptr;
+
+ lang = SDL_getenv("LC_ALL");
+ if (!lang) {
+ lang = SDL_getenv("LC_CTYPE");
+ }
+ if (!lang) {
+ lang = SDL_getenv("LC_MESSAGES");
+ }
+ if (!lang) {
+ lang = SDL_getenv("LANG");
+ }
+ if (!lang || !*lang || SDL_strcmp(lang, "C") == 0) {
+ lang = "ASCII";
+ }
+
+ /* We need to trim down strings like "en_US.UTF-8@blah" to "UTF-8" */
+ ptr = SDL_strchr(lang, '.');
+ if (ptr != NULL) {
+ lang = ptr + 1;
+ }
+
+ SDL_strlcpy(buffer, lang, bufsize);
+ ptr = SDL_strchr(buffer, '@');
+ if (ptr != NULL) {
+ *ptr = '\0'; /* chop end of string. */
+ }
+
+ return buffer;
+}
+
+SDL_iconv_t
+SDL_iconv_open(const char *tocode, const char *fromcode)
+{
+ int src_fmt = ENCODING_UNKNOWN;
+ int dst_fmt = ENCODING_UNKNOWN;
+ int i;
+ char fromcode_buffer[64];
+ char tocode_buffer[64];
+
+ if (!fromcode || !*fromcode) {
+ fromcode = getlocale(fromcode_buffer, sizeof(fromcode_buffer));
+ }
+ if (!tocode || !*tocode) {
+ tocode = getlocale(tocode_buffer, sizeof(tocode_buffer));
+ }
+ for (i = 0; i < SDL_arraysize(encodings); ++i) {
+ if (SDL_strcasecmp(fromcode, encodings[i].name) == 0) {
+ src_fmt = encodings[i].format;
+ if (dst_fmt != ENCODING_UNKNOWN) {
+ break;
+ }
+ }
+ if (SDL_strcasecmp(tocode, encodings[i].name) == 0) {
+ dst_fmt = encodings[i].format;
+ if (src_fmt != ENCODING_UNKNOWN) {
+ break;
+ }
+ }
+ }
+ if (src_fmt != ENCODING_UNKNOWN && dst_fmt != ENCODING_UNKNOWN) {
+ SDL_iconv_t cd = (SDL_iconv_t) SDL_malloc(sizeof(*cd));
+ if (cd) {
+ cd->src_fmt = src_fmt;
+ cd->dst_fmt = dst_fmt;
+ return cd;
+ }
+ }
+ return (SDL_iconv_t) - 1;
+}
+
+size_t
+SDL_iconv(SDL_iconv_t cd,
+ const char **inbuf, size_t * inbytesleft,
+ char **outbuf, size_t * outbytesleft)
+{
+ /* For simplicity, we'll convert everything to and from UCS-4 */
+ const char *src;
+ char *dst;
+ size_t srclen, dstlen;
+ Uint32 ch = 0;
+ size_t total;
+
+ if (!inbuf || !*inbuf) {
+ /* Reset the context */
+ return 0;
+ }
+ if (!outbuf || !*outbuf || !outbytesleft || !*outbytesleft) {
+ return SDL_ICONV_E2BIG;
+ }
+ src = *inbuf;
+ srclen = (inbytesleft ? *inbytesleft : 0);
+ dst = *outbuf;
+ dstlen = *outbytesleft;
+
+ switch (cd->src_fmt) {
+ case ENCODING_UTF16:
+ /* Scan for a byte order marker */
+ {
+ Uint8 *p = (Uint8 *) src;
+ size_t n = srclen / 2;
+ while (n) {
+ if (p[0] == 0xFF && p[1] == 0xFE) {
+ cd->src_fmt = ENCODING_UTF16BE;
+ break;
+ } else if (p[0] == 0xFE && p[1] == 0xFF) {
+ cd->src_fmt = ENCODING_UTF16LE;
+ break;
+ }
+ p += 2;
+ --n;
+ }
+ if (n == 0) {
+ /* We can't tell, default to host order */
+ cd->src_fmt = ENCODING_UTF16NATIVE;
+ }
+ }
+ break;
+ case ENCODING_UTF32:
+ /* Scan for a byte order marker */
+ {
+ Uint8 *p = (Uint8 *) src;
+ size_t n = srclen / 4;
+ while (n) {
+ if (p[0] == 0xFF && p[1] == 0xFE &&
+ p[2] == 0x00 && p[3] == 0x00) {
+ cd->src_fmt = ENCODING_UTF32BE;
+ break;
+ } else if (p[0] == 0x00 && p[1] == 0x00 &&
+ p[2] == 0xFE && p[3] == 0xFF) {
+ cd->src_fmt = ENCODING_UTF32LE;
+ break;
+ }
+ p += 4;
+ --n;
+ }
+ if (n == 0) {
+ /* We can't tell, default to host order */
+ cd->src_fmt = ENCODING_UTF32NATIVE;
+ }
+ }
+ break;
+ }
+
+ switch (cd->dst_fmt) {
+ case ENCODING_UTF16:
+ /* Default to host order, need to add byte order marker */
+ if (dstlen < 2) {
+ return SDL_ICONV_E2BIG;
+ }
+ *(Uint16 *) dst = UNICODE_BOM;
+ dst += 2;
+ dstlen -= 2;
+ cd->dst_fmt = ENCODING_UTF16NATIVE;
+ break;
+ case ENCODING_UTF32:
+ /* Default to host order, need to add byte order marker */
+ if (dstlen < 4) {
+ return SDL_ICONV_E2BIG;
+ }
+ *(Uint32 *) dst = UNICODE_BOM;
+ dst += 4;
+ dstlen -= 4;
+ cd->dst_fmt = ENCODING_UTF32NATIVE;
+ break;
+ }
+
+ total = 0;
+ while (srclen > 0) {
+ /* Decode a character */
+ switch (cd->src_fmt) {
+ case ENCODING_ASCII:
+ {
+ Uint8 *p = (Uint8 *) src;
+ ch = (Uint32) (p[0] & 0x7F);
+ ++src;
+ --srclen;
+ }
+ break;
+ case ENCODING_LATIN1:
+ {
+ Uint8 *p = (Uint8 *) src;
+ ch = (Uint32) p[0];
+ ++src;
+ --srclen;
+ }
+ break;
+ case ENCODING_UTF8: /* RFC 3629 */
+ {
+ Uint8 *p = (Uint8 *) src;
+ size_t left = 0;
+ SDL_bool overlong = SDL_FALSE;
+ if (p[0] >= 0xFC) {
+ if ((p[0] & 0xFE) != 0xFC) {
+ /* Skip illegal sequences
+ return SDL_ICONV_EILSEQ;
+ */
+ ch = UNKNOWN_UNICODE;
+ } else {
+ if (p[0] == 0xFC && srclen > 1 && (p[1] & 0xFC) == 0x80) {
+ overlong = SDL_TRUE;
+ }
+ ch = (Uint32) (p[0] & 0x01);
+ left = 5;
+ }
+ } else if (p[0] >= 0xF8) {
+ if ((p[0] & 0xFC) != 0xF8) {
+ /* Skip illegal sequences
+ return SDL_ICONV_EILSEQ;
+ */
+ ch = UNKNOWN_UNICODE;
+ } else {
+ if (p[0] == 0xF8 && srclen > 1 && (p[1] & 0xF8) == 0x80) {
+ overlong = SDL_TRUE;
+ }
+ ch = (Uint32) (p[0] & 0x03);
+ left = 4;
+ }
+ } else if (p[0] >= 0xF0) {
+ if ((p[0] & 0xF8) != 0xF0) {
+ /* Skip illegal sequences
+ return SDL_ICONV_EILSEQ;
+ */
+ ch = UNKNOWN_UNICODE;
+ } else {
+ if (p[0] == 0xF0 && srclen > 1 && (p[1] & 0xF0) == 0x80) {
+ overlong = SDL_TRUE;
+ }
+ ch = (Uint32) (p[0] & 0x07);
+ left = 3;
+ }
+ } else if (p[0] >= 0xE0) {
+ if ((p[0] & 0xF0) != 0xE0) {
+ /* Skip illegal sequences
+ return SDL_ICONV_EILSEQ;
+ */
+ ch = UNKNOWN_UNICODE;
+ } else {
+ if (p[0] == 0xE0 && srclen > 1 && (p[1] & 0xE0) == 0x80) {
+ overlong = SDL_TRUE;
+ }
+ ch = (Uint32) (p[0] & 0x0F);
+ left = 2;
+ }
+ } else if (p[0] >= 0xC0) {
+ if ((p[0] & 0xE0) != 0xC0) {
+ /* Skip illegal sequences
+ return SDL_ICONV_EILSEQ;
+ */
+ ch = UNKNOWN_UNICODE;
+ } else {
+ if ((p[0] & 0xDE) == 0xC0) {
+ overlong = SDL_TRUE;
+ }
+ ch = (Uint32) (p[0] & 0x1F);
+ left = 1;
+ }
+ } else {
+ if ((p[0] & 0x80) != 0x00) {
+ /* Skip illegal sequences
+ return SDL_ICONV_EILSEQ;
+ */
+ ch = UNKNOWN_UNICODE;
+ } else {
+ ch = (Uint32) p[0];
+ }
+ }
+ ++src;
+ --srclen;
+ if (srclen < left) {
+ return SDL_ICONV_EINVAL;
+ }
+ while (left--) {
+ ++p;
+ if ((p[0] & 0xC0) != 0x80) {
+ /* Skip illegal sequences
+ return SDL_ICONV_EILSEQ;
+ */
+ ch = UNKNOWN_UNICODE;
+ break;
+ }
+ ch <<= 6;
+ ch |= (p[0] & 0x3F);
+ ++src;
+ --srclen;
+ }
+ if (overlong) {
+ /* Potential security risk
+ return SDL_ICONV_EILSEQ;
+ */
+ ch = UNKNOWN_UNICODE;
+ }
+ if ((ch >= 0xD800 && ch <= 0xDFFF) ||
+ (ch == 0xFFFE || ch == 0xFFFF) || ch > 0x10FFFF) {
+ /* Skip illegal sequences
+ return SDL_ICONV_EILSEQ;
+ */
+ ch = UNKNOWN_UNICODE;
+ }
+ }
+ break;
+ case ENCODING_UTF16BE: /* RFC 2781 */
+ {
+ Uint8 *p = (Uint8 *) src;
+ Uint16 W1, W2;
+ if (srclen < 2) {
+ return SDL_ICONV_EINVAL;
+ }
+ W1 = ((Uint16) p[0] << 8) | (Uint16) p[1];
+ src += 2;
+ srclen -= 2;
+ if (W1 < 0xD800 || W1 > 0xDFFF) {
+ ch = (Uint32) W1;
+ break;
+ }
+ if (W1 > 0xDBFF) {
+ /* Skip illegal sequences
+ return SDL_ICONV_EILSEQ;
+ */
+ ch = UNKNOWN_UNICODE;
+ break;
+ }
+ if (srclen < 2) {
+ return SDL_ICONV_EINVAL;
+ }
+ p = (Uint8 *) src;
+ W2 = ((Uint16) p[0] << 8) | (Uint16) p[1];
+ src += 2;
+ srclen -= 2;
+ if (W2 < 0xDC00 || W2 > 0xDFFF) {
+ /* Skip illegal sequences
+ return SDL_ICONV_EILSEQ;
+ */
+ ch = UNKNOWN_UNICODE;
+ break;
+ }
+ ch = (((Uint32) (W1 & 0x3FF) << 10) |
+ (Uint32) (W2 & 0x3FF)) + 0x10000;
+ }
+ break;
+ case ENCODING_UTF16LE: /* RFC 2781 */
+ {
+ Uint8 *p = (Uint8 *) src;
+ Uint16 W1, W2;
+ if (srclen < 2) {
+ return SDL_ICONV_EINVAL;
+ }
+ W1 = ((Uint16) p[1] << 8) | (Uint16) p[0];
+ src += 2;
+ srclen -= 2;
+ if (W1 < 0xD800 || W1 > 0xDFFF) {
+ ch = (Uint32) W1;
+ break;
+ }
+ if (W1 > 0xDBFF) {
+ /* Skip illegal sequences
+ return SDL_ICONV_EILSEQ;
+ */
+ ch = UNKNOWN_UNICODE;
+ break;
+ }
+ if (srclen < 2) {
+ return SDL_ICONV_EINVAL;
+ }
+ p = (Uint8 *) src;
+ W2 = ((Uint16) p[1] << 8) | (Uint16) p[0];
+ src += 2;
+ srclen -= 2;
+ if (W2 < 0xDC00 || W2 > 0xDFFF) {
+ /* Skip illegal sequences
+ return SDL_ICONV_EILSEQ;
+ */
+ ch = UNKNOWN_UNICODE;
+ break;
+ }
+ ch = (((Uint32) (W1 & 0x3FF) << 10) |
+ (Uint32) (W2 & 0x3FF)) + 0x10000;
+ }
+ break;
+ case ENCODING_UCS2LE:
+ {
+ Uint8 *p = (Uint8 *) src;
+ if (srclen < 2) {
+ return SDL_ICONV_EINVAL;
+ }
+ ch = ((Uint32) p[1] << 8) | (Uint32) p[0];
+ src += 2;
+ srclen -= 2;
+ }
+ break;
+ case ENCODING_UCS2BE:
+ {
+ Uint8 *p = (Uint8 *) src;
+ if (srclen < 2) {
+ return SDL_ICONV_EINVAL;
+ }
+ ch = ((Uint32) p[0] << 8) | (Uint32) p[1];
+ src += 2;
+ srclen -= 2;
+ }
+ break;
+ case ENCODING_UCS4BE:
+ case ENCODING_UTF32BE:
+ {
+ Uint8 *p = (Uint8 *) src;
+ if (srclen < 4) {
+ return SDL_ICONV_EINVAL;
+ }
+ ch = ((Uint32) p[0] << 24) |
+ ((Uint32) p[1] << 16) |
+ ((Uint32) p[2] << 8) | (Uint32) p[3];
+ src += 4;
+ srclen -= 4;
+ }
+ break;
+ case ENCODING_UCS4LE:
+ case ENCODING_UTF32LE:
+ {
+ Uint8 *p = (Uint8 *) src;
+ if (srclen < 4) {
+ return SDL_ICONV_EINVAL;
+ }
+ ch = ((Uint32) p[3] << 24) |
+ ((Uint32) p[2] << 16) |
+ ((Uint32) p[1] << 8) | (Uint32) p[0];
+ src += 4;
+ srclen -= 4;
+ }
+ break;
+ }
+
+ /* Encode a character */
+ switch (cd->dst_fmt) {
+ case ENCODING_ASCII:
+ {
+ Uint8 *p = (Uint8 *) dst;
+ if (dstlen < 1) {
+ return SDL_ICONV_E2BIG;
+ }
+ if (ch > 0x7F) {
+ *p = UNKNOWN_ASCII;
+ } else {
+ *p = (Uint8) ch;
+ }
+ ++dst;
+ --dstlen;
+ }
+ break;
+ case ENCODING_LATIN1:
+ {
+ Uint8 *p = (Uint8 *) dst;
+ if (dstlen < 1) {
+ return SDL_ICONV_E2BIG;
+ }
+ if (ch > 0xFF) {
+ *p = UNKNOWN_ASCII;
+ } else {
+ *p = (Uint8) ch;
+ }
+ ++dst;
+ --dstlen;
+ }
+ break;
+ case ENCODING_UTF8: /* RFC 3629 */
+ {
+ Uint8 *p = (Uint8 *) dst;
+ if (ch > 0x10FFFF) {
+ ch = UNKNOWN_UNICODE;
+ }
+ if (ch <= 0x7F) {
+ if (dstlen < 1) {
+ return SDL_ICONV_E2BIG;
+ }
+ *p = (Uint8) ch;
+ ++dst;
+ --dstlen;
+ } else if (ch <= 0x7FF) {
+ if (dstlen < 2) {
+ return SDL_ICONV_E2BIG;
+ }
+ p[0] = 0xC0 | (Uint8) ((ch >> 6) & 0x1F);
+ p[1] = 0x80 | (Uint8) (ch & 0x3F);
+ dst += 2;
+ dstlen -= 2;
+ } else if (ch <= 0xFFFF) {
+ if (dstlen < 3) {
+ return SDL_ICONV_E2BIG;
+ }
+ p[0] = 0xE0 | (Uint8) ((ch >> 12) & 0x0F);
+ p[1] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
+ p[2] = 0x80 | (Uint8) (ch & 0x3F);
+ dst += 3;
+ dstlen -= 3;
+ } else if (ch <= 0x1FFFFF) {
+ if (dstlen < 4) {
+ return SDL_ICONV_E2BIG;
+ }
+ p[0] = 0xF0 | (Uint8) ((ch >> 18) & 0x07);
+ p[1] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
+ p[2] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
+ p[3] = 0x80 | (Uint8) (ch & 0x3F);
+ dst += 4;
+ dstlen -= 4;
+ } else if (ch <= 0x3FFFFFF) {
+ if (dstlen < 5) {
+ return SDL_ICONV_E2BIG;
+ }
+ p[0] = 0xF8 | (Uint8) ((ch >> 24) & 0x03);
+ p[1] = 0x80 | (Uint8) ((ch >> 18) & 0x3F);
+ p[2] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
+ p[3] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
+ p[4] = 0x80 | (Uint8) (ch & 0x3F);
+ dst += 5;
+ dstlen -= 5;
+ } else {
+ if (dstlen < 6) {
+ return SDL_ICONV_E2BIG;
+ }
+ p[0] = 0xFC | (Uint8) ((ch >> 30) & 0x01);
+ p[1] = 0x80 | (Uint8) ((ch >> 24) & 0x3F);
+ p[2] = 0x80 | (Uint8) ((ch >> 18) & 0x3F);
+ p[3] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
+ p[4] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
+ p[5] = 0x80 | (Uint8) (ch & 0x3F);
+ dst += 6;
+ dstlen -= 6;
+ }
+ }
+ break;
+ case ENCODING_UTF16BE: /* RFC 2781 */
+ {
+ Uint8 *p = (Uint8 *) dst;
+ if (ch > 0x10FFFF) {
+ ch = UNKNOWN_UNICODE;
+ }
+ if (ch < 0x10000) {
+ if (dstlen < 2) {
+ return SDL_ICONV_E2BIG;
+ }
+ p[0] = (Uint8) (ch >> 8);
+ p[1] = (Uint8) ch;
+ dst += 2;
+ dstlen -= 2;
+ } else {
+ Uint16 W1, W2;
+ if (dstlen < 4) {
+ return SDL_ICONV_E2BIG;
+ }
+ ch = ch - 0x10000;
+ W1 = 0xD800 | (Uint16) ((ch >> 10) & 0x3FF);
+ W2 = 0xDC00 | (Uint16) (ch & 0x3FF);
+ p[0] = (Uint8) (W1 >> 8);
+ p[1] = (Uint8) W1;
+ p[2] = (Uint8) (W2 >> 8);
+ p[3] = (Uint8) W2;
+ dst += 4;
+ dstlen -= 4;
+ }
+ }
+ break;
+ case ENCODING_UTF16LE: /* RFC 2781 */
+ {
+ Uint8 *p = (Uint8 *) dst;
+ if (ch > 0x10FFFF) {
+ ch = UNKNOWN_UNICODE;
+ }
+ if (ch < 0x10000) {
+ if (dstlen < 2) {
+ return SDL_ICONV_E2BIG;
+ }
+ p[1] = (Uint8) (ch >> 8);
+ p[0] = (Uint8) ch;
+ dst += 2;
+ dstlen -= 2;
+ } else {
+ Uint16 W1, W2;
+ if (dstlen < 4) {
+ return SDL_ICONV_E2BIG;
+ }
+ ch = ch - 0x10000;
+ W1 = 0xD800 | (Uint16) ((ch >> 10) & 0x3FF);
+ W2 = 0xDC00 | (Uint16) (ch & 0x3FF);
+ p[1] = (Uint8) (W1 >> 8);
+ p[0] = (Uint8) W1;
+ p[3] = (Uint8) (W2 >> 8);
+ p[2] = (Uint8) W2;
+ dst += 4;
+ dstlen -= 4;
+ }
+ }
+ break;
+ case ENCODING_UCS2BE:
+ {
+ Uint8 *p = (Uint8 *) dst;
+ if (ch > 0xFFFF) {
+ ch = UNKNOWN_UNICODE;
+ }
+ if (dstlen < 2) {
+ return SDL_ICONV_E2BIG;
+ }
+ p[0] = (Uint8) (ch >> 8);
+ p[1] = (Uint8) ch;
+ dst += 2;
+ dstlen -= 2;
+ }
+ break;
+ case ENCODING_UCS2LE:
+ {
+ Uint8 *p = (Uint8 *) dst;
+ if (ch > 0xFFFF) {
+ ch = UNKNOWN_UNICODE;
+ }
+ if (dstlen < 2) {
+ return SDL_ICONV_E2BIG;
+ }
+ p[1] = (Uint8) (ch >> 8);
+ p[0] = (Uint8) ch;
+ dst += 2;
+ dstlen -= 2;
+ }
+ break;
+ case ENCODING_UTF32BE:
+ if (ch > 0x10FFFF) {
+ ch = UNKNOWN_UNICODE;
+ }
+ /* fallthrough */
+ case ENCODING_UCS4BE:
+ if (ch > 0x7FFFFFFF) {
+ ch = UNKNOWN_UNICODE;
+ }
+ {
+ Uint8 *p = (Uint8 *) dst;
+ if (dstlen < 4) {
+ return SDL_ICONV_E2BIG;
+ }
+ p[0] = (Uint8) (ch >> 24);
+ p[1] = (Uint8) (ch >> 16);
+ p[2] = (Uint8) (ch >> 8);
+ p[3] = (Uint8) ch;
+ dst += 4;
+ dstlen -= 4;
+ }
+ break;
+ case ENCODING_UTF32LE:
+ if (ch > 0x10FFFF) {
+ ch = UNKNOWN_UNICODE;
+ }
+ /* fallthrough */
+ case ENCODING_UCS4LE:
+ if (ch > 0x7FFFFFFF) {
+ ch = UNKNOWN_UNICODE;
+ }
+ {
+ Uint8 *p = (Uint8 *) dst;
+ if (dstlen < 4) {
+ return SDL_ICONV_E2BIG;
+ }
+ p[3] = (Uint8) (ch >> 24);
+ p[2] = (Uint8) (ch >> 16);
+ p[1] = (Uint8) (ch >> 8);
+ p[0] = (Uint8) ch;
+ dst += 4;
+ dstlen -= 4;
+ }
+ break;
+ }
+
+ /* Update state */
+ *inbuf = src;
+ *inbytesleft = srclen;
+ *outbuf = dst;
+ *outbytesleft = dstlen;
+ ++total;
+ }
+ return total;
+}
+
+int
+SDL_iconv_close(SDL_iconv_t cd)
+{
+ if (cd != (SDL_iconv_t)-1) {
+ SDL_free(cd);
+ }
+ return 0;
+}
+
+#endif /* !HAVE_ICONV */
+
+char *
+SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf,
+ size_t inbytesleft)
+{
+ SDL_iconv_t cd;
+ char *string;
+ size_t stringsize;
+ char *outbuf;
+ size_t outbytesleft;
+ size_t retCode = 0;
+
+ cd = SDL_iconv_open(tocode, fromcode);
+ if (cd == (SDL_iconv_t) - 1) {
+ /* See if we can recover here (fixes iconv on Solaris 11) */
+ if (!tocode || !*tocode) {
+ tocode = "UTF-8";
+ }
+ if (!fromcode || !*fromcode) {
+ fromcode = "UTF-8";
+ }
+ cd = SDL_iconv_open(tocode, fromcode);
+ }
+ if (cd == (SDL_iconv_t) - 1) {
+ return NULL;
+ }
+
+ stringsize = inbytesleft > 4 ? inbytesleft : 4;
+ string = SDL_malloc(stringsize);
+ if (!string) {
+ SDL_iconv_close(cd);
+ return NULL;
+ }
+ outbuf = string;
+ outbytesleft = stringsize;
+ SDL_memset(outbuf, 0, 4);
+
+ while (inbytesleft > 0) {
+ retCode = SDL_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
+ switch (retCode) {
+ case SDL_ICONV_E2BIG:
+ {
+ char *oldstring = string;
+ stringsize *= 2;
+ string = SDL_realloc(string, stringsize);
+ if (!string) {
+ SDL_iconv_close(cd);
+ return NULL;
+ }
+ outbuf = string + (outbuf - oldstring);
+ outbytesleft = stringsize - (outbuf - string);
+ SDL_memset(outbuf, 0, 4);
+ }
+ break;
+ case SDL_ICONV_EILSEQ:
+ /* Try skipping some input data - not perfect, but... */
+ ++inbuf;
+ --inbytesleft;
+ break;
+ case SDL_ICONV_EINVAL:
+ case SDL_ICONV_ERROR:
+ /* We can't continue... */
+ inbytesleft = 0;
+ break;
+ }
+ }
+ SDL_iconv_close(cd);
+
+ return string;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/stdlib/SDL_malloc.c b/src/3rdparty/SDL2/src/stdlib/SDL_malloc.c
new file mode 100644
index 0000000..ace76bf
--- /dev/null
+++ b/src/3rdparty/SDL2/src/stdlib/SDL_malloc.c
@@ -0,0 +1,5376 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
+#define SDL_DISABLE_ANALYZE_MACROS 1
+#endif
+
+#include "../SDL_internal.h"
+
+/* This file contains portable memory management functions for SDL */
+#include "SDL_stdinc.h"
+#include "SDL_atomic.h"
+#include "SDL_error.h"
+
+#ifndef HAVE_MALLOC
+#define LACKS_SYS_TYPES_H
+#define LACKS_STDIO_H
+#define LACKS_STRINGS_H
+#define LACKS_STRING_H
+#define LACKS_STDLIB_H
+#define ABORT
+#define USE_LOCKS 1
+#define USE_DL_PREFIX
+
+/*
+ This is a version (aka dlmalloc) of malloc/free/realloc written by
+ Doug Lea and released to the public domain, as explained at
+ http://creativecommons.org/licenses/publicdomain. Send questions,
+ comments, complaints, performance data, etc to dl@cs.oswego.edu
+
+* Version 2.8.3 Thu Sep 22 11:16:15 2005 Doug Lea (dl at gee)
+
+ Note: There may be an updated version of this malloc obtainable at
+ ftp://gee.cs.oswego.edu/pub/misc/malloc.c
+ Check before installing!
+
+* Quickstart
+
+ This library is all in one file to simplify the most common usage:
+ ftp it, compile it (-O3), and link it into another program. All of
+ the compile-time options default to reasonable values for use on
+ most platforms. You might later want to step through various
+ compile-time and dynamic tuning options.
+
+ For convenience, an include file for code using this malloc is at:
+ ftp://gee.cs.oswego.edu/pub/misc/malloc-2.8.3.h
+ You don't really need this .h file unless you call functions not
+ defined in your system include files. The .h file contains only the
+ excerpts from this file needed for using this malloc on ANSI C/C++
+ systems, so long as you haven't changed compile-time options about
+ naming and tuning parameters. If you do, then you can create your
+ own malloc.h that does include all settings by cutting at the point
+ indicated below. Note that you may already by default be using a C
+ library containing a malloc that is based on some version of this
+ malloc (for example in linux). You might still want to use the one
+ in this file to customize settings or to avoid overheads associated
+ with library versions.
+
+* Vital statistics:
+
+ Supported pointer/size_t representation: 4 or 8 bytes
+ size_t MUST be an unsigned type of the same width as
+ pointers. (If you are using an ancient system that declares
+ size_t as a signed type, or need it to be a different width
+ than pointers, you can use a previous release of this malloc
+ (e.g. 2.7.2) supporting these.)
+
+ Alignment: 8 bytes (default)
+ This suffices for nearly all current machines and C compilers.
+ However, you can define MALLOC_ALIGNMENT to be wider than this
+ if necessary (up to 128bytes), at the expense of using more space.
+
+ Minimum overhead per allocated chunk: 4 or 8 bytes (if 4byte sizes)
+ 8 or 16 bytes (if 8byte sizes)
+ Each malloced chunk has a hidden word of overhead holding size
+ and status information, and additional cross-check word
+ if FOOTERS is defined.
+
+ Minimum allocated size: 4-byte ptrs: 16 bytes (including overhead)
+ 8-byte ptrs: 32 bytes (including overhead)
+
+ Even a request for zero bytes (i.e., malloc(0)) returns a
+ pointer to something of the minimum allocatable size.
+ The maximum overhead wastage (i.e., number of extra bytes
+ allocated than were requested in malloc) is less than or equal
+ to the minimum size, except for requests >= mmap_threshold that
+ are serviced via mmap(), where the worst case wastage is about
+ 32 bytes plus the remainder from a system page (the minimal
+ mmap unit); typically 4096 or 8192 bytes.
+
+ Security: static-safe; optionally more or less
+ The "security" of malloc refers to the ability of malicious
+ code to accentuate the effects of errors (for example, freeing
+ space that is not currently malloc'ed or overwriting past the
+ ends of chunks) in code that calls malloc. This malloc
+ guarantees not to modify any memory locations below the base of
+ heap, i.e., static variables, even in the presence of usage
+ errors. The routines additionally detect most improper frees
+ and reallocs. All this holds as long as the static bookkeeping
+ for malloc itself is not corrupted by some other means. This
+ is only one aspect of security -- these checks do not, and
+ cannot, detect all possible programming errors.
+
+ If FOOTERS is defined nonzero, then each allocated chunk
+ carries an additional check word to verify that it was malloced
+ from its space. These check words are the same within each
+ execution of a program using malloc, but differ across
+ executions, so externally crafted fake chunks cannot be
+ freed. This improves security by rejecting frees/reallocs that
+ could corrupt heap memory, in addition to the checks preventing
+ writes to statics that are always on. This may further improve
+ security at the expense of time and space overhead. (Note that
+ FOOTERS may also be worth using with MSPACES.)
+
+ By default detected errors cause the program to abort (calling
+ "abort()"). You can override this to instead proceed past
+ errors by defining PROCEED_ON_ERROR. In this case, a bad free
+ has no effect, and a malloc that encounters a bad address
+ caused by user overwrites will ignore the bad address by
+ dropping pointers and indices to all known memory. This may
+ be appropriate for programs that should continue if at all
+ possible in the face of programming errors, although they may
+ run out of memory because dropped memory is never reclaimed.
+
+ If you don't like either of these options, you can define
+ CORRUPTION_ERROR_ACTION and USAGE_ERROR_ACTION to do anything
+ else. And if if you are sure that your program using malloc has
+ no errors or vulnerabilities, you can define INSECURE to 1,
+ which might (or might not) provide a small performance improvement.
+
+ Thread-safety: NOT thread-safe unless USE_LOCKS defined
+ When USE_LOCKS is defined, each public call to malloc, free,
+ etc is surrounded with either a pthread mutex or a win32
+ spinlock (depending on WIN32). This is not especially fast, and
+ can be a major bottleneck. It is designed only to provide
+ minimal protection in concurrent environments, and to provide a
+ basis for extensions. If you are using malloc in a concurrent
+ program, consider instead using ptmalloc, which is derived from
+ a version of this malloc. (See http://www.malloc.de).
+
+ System requirements: Any combination of MORECORE and/or MMAP/MUNMAP
+ This malloc can use unix sbrk or any emulation (invoked using
+ the CALL_MORECORE macro) and/or mmap/munmap or any emulation
+ (invoked using CALL_MMAP/CALL_MUNMAP) to get and release system
+ memory. On most unix systems, it tends to work best if both
+ MORECORE and MMAP are enabled. On Win32, it uses emulations
+ based on VirtualAlloc. It also uses common C library functions
+ like memset.
+
+ Compliance: I believe it is compliant with the Single Unix Specification
+ (See http://www.unix.org). Also SVID/XPG, ANSI C, and probably
+ others as well.
+
+* Overview of algorithms
+
+ This is not the fastest, most space-conserving, most portable, or
+ most tunable malloc ever written. However it is among the fastest
+ while also being among the most space-conserving, portable and
+ tunable. Consistent balance across these factors results in a good
+ general-purpose allocator for malloc-intensive programs.
+
+ In most ways, this malloc is a best-fit allocator. Generally, it
+ chooses the best-fitting existing chunk for a request, with ties
+ broken in approximately least-recently-used order. (This strategy
+ normally maintains low fragmentation.) However, for requests less
+ than 256bytes, it deviates from best-fit when there is not an
+ exactly fitting available chunk by preferring to use space adjacent
+ to that used for the previous small request, as well as by breaking
+ ties in approximately most-recently-used order. (These enhance
+ locality of series of small allocations.) And for very large requests
+ (>= 256Kb by default), it relies on system memory mapping
+ facilities, if supported. (This helps avoid carrying around and
+ possibly fragmenting memory used only for large chunks.)
+
+ All operations (except malloc_stats and mallinfo) have execution
+ times that are bounded by a constant factor of the number of bits in
+ a size_t, not counting any clearing in calloc or copying in realloc,
+ or actions surrounding MORECORE and MMAP that have times
+ proportional to the number of non-contiguous regions returned by
+ system allocation routines, which is often just 1.
+
+ The implementation is not very modular and seriously overuses
+ macros. Perhaps someday all C compilers will do as good a job
+ inlining modular code as can now be done by brute-force expansion,
+ but now, enough of them seem not to.
+
+ Some compilers issue a lot of warnings about code that is
+ dead/unreachable only on some platforms, and also about intentional
+ uses of negation on unsigned types. All known cases of each can be
+ ignored.
+
+ For a longer but out of date high-level description, see
+ http://gee.cs.oswego.edu/dl/html/malloc.html
+
+* MSPACES
+ If MSPACES is defined, then in addition to malloc, free, etc.,
+ this file also defines mspace_malloc, mspace_free, etc. These
+ are versions of malloc routines that take an "mspace" argument
+ obtained using create_mspace, to control all internal bookkeeping.
+ If ONLY_MSPACES is defined, only these versions are compiled.
+ So if you would like to use this allocator for only some allocations,
+ and your system malloc for others, you can compile with
+ ONLY_MSPACES and then do something like...
+ static mspace mymspace = create_mspace(0,0); // for example
+ #define mymalloc(bytes) mspace_malloc(mymspace, bytes)
+
+ (Note: If you only need one instance of an mspace, you can instead
+ use "USE_DL_PREFIX" to relabel the global malloc.)
+
+ You can similarly create thread-local allocators by storing
+ mspaces as thread-locals. For example:
+ static __thread mspace tlms = 0;
+ void* tlmalloc(size_t bytes) {
+ if (tlms == 0) tlms = create_mspace(0, 0);
+ return mspace_malloc(tlms, bytes);
+ }
+ void tlfree(void* mem) { mspace_free(tlms, mem); }
+
+ Unless FOOTERS is defined, each mspace is completely independent.
+ You cannot allocate from one and free to another (although
+ conformance is only weakly checked, so usage errors are not always
+ caught). If FOOTERS is defined, then each chunk carries around a tag
+ indicating its originating mspace, and frees are directed to their
+ originating spaces.
+
+ ------------------------- Compile-time options ---------------------------
+
+Be careful in setting #define values for numerical constants of type
+size_t. On some systems, literal values are not automatically extended
+to size_t precision unless they are explicitly casted.
+
+WIN32 default: defined if _WIN32 defined
+ Defining WIN32 sets up defaults for MS environment and compilers.
+ Otherwise defaults are for unix.
+
+MALLOC_ALIGNMENT default: (size_t)8
+ Controls the minimum alignment for malloc'ed chunks. It must be a
+ power of two and at least 8, even on machines for which smaller
+ alignments would suffice. It may be defined as larger than this
+ though. Note however that code and data structures are optimized for
+ the case of 8-byte alignment.
+
+MSPACES default: 0 (false)
+ If true, compile in support for independent allocation spaces.
+ This is only supported if HAVE_MMAP is true.
+
+ONLY_MSPACES default: 0 (false)
+ If true, only compile in mspace versions, not regular versions.
+
+USE_LOCKS default: 0 (false)
+ Causes each call to each public routine to be surrounded with
+ pthread or WIN32 mutex lock/unlock. (If set true, this can be
+ overridden on a per-mspace basis for mspace versions.)
+
+FOOTERS default: 0
+ If true, provide extra checking and dispatching by placing
+ information in the footers of allocated chunks. This adds
+ space and time overhead.
+
+INSECURE default: 0
+ If true, omit checks for usage errors and heap space overwrites.
+
+USE_DL_PREFIX default: NOT defined
+ Causes compiler to prefix all public routines with the string 'dl'.
+ This can be useful when you only want to use this malloc in one part
+ of a program, using your regular system malloc elsewhere.
+
+ABORT default: defined as abort()
+ Defines how to abort on failed checks. On most systems, a failed
+ check cannot die with an "assert" or even print an informative
+ message, because the underlying print routines in turn call malloc,
+ which will fail again. Generally, the best policy is to simply call
+ abort(). It's not very useful to do more than this because many
+ errors due to overwriting will show up as address faults (null, odd
+ addresses etc) rather than malloc-triggered checks, so will also
+ abort. Also, most compilers know that abort() does not return, so
+ can better optimize code conditionally calling it.
+
+PROCEED_ON_ERROR default: defined as 0 (false)
+ Controls whether detected bad addresses cause them to bypassed
+ rather than aborting. If set, detected bad arguments to free and
+ realloc are ignored. And all bookkeeping information is zeroed out
+ upon a detected overwrite of freed heap space, thus losing the
+ ability to ever return it from malloc again, but enabling the
+ application to proceed. If PROCEED_ON_ERROR is defined, the
+ static variable malloc_corruption_error_count is compiled in
+ and can be examined to see if errors have occurred. This option
+ generates slower code than the default abort policy.
+
+DEBUG default: NOT defined
+ The DEBUG setting is mainly intended for people trying to modify
+ this code or diagnose problems when porting to new platforms.
+ However, it may also be able to better isolate user errors than just
+ using runtime checks. The assertions in the check routines spell
+ out in more detail the assumptions and invariants underlying the
+ algorithms. The checking is fairly extensive, and will slow down
+ execution noticeably. Calling malloc_stats or mallinfo with DEBUG
+ set will attempt to check every non-mmapped allocated and free chunk
+ in the course of computing the summaries.
+
+ABORT_ON_ASSERT_FAILURE default: defined as 1 (true)
+ Debugging assertion failures can be nearly impossible if your
+ version of the assert macro causes malloc to be called, which will
+ lead to a cascade of further failures, blowing the runtime stack.
+ ABORT_ON_ASSERT_FAILURE cause assertions failures to call abort(),
+ which will usually make debugging easier.
+
+MALLOC_FAILURE_ACTION default: sets errno to ENOMEM, or no-op on win32
+ The action to take before "return 0" when malloc fails to be able to
+ return memory because there is none available.
+
+HAVE_MORECORE default: 1 (true) unless win32 or ONLY_MSPACES
+ True if this system supports sbrk or an emulation of it.
+
+MORECORE default: sbrk
+ The name of the sbrk-style system routine to call to obtain more
+ memory. See below for guidance on writing custom MORECORE
+ functions. The type of the argument to sbrk/MORECORE varies across
+ systems. It cannot be size_t, because it supports negative
+ arguments, so it is normally the signed type of the same width as
+ size_t (sometimes declared as "intptr_t"). It doesn't much matter
+ though. Internally, we only call it with arguments less than half
+ the max value of a size_t, which should work across all reasonable
+ possibilities, although sometimes generating compiler warnings. See
+ near the end of this file for guidelines for creating a custom
+ version of MORECORE.
+
+MORECORE_CONTIGUOUS default: 1 (true)
+ If true, take advantage of fact that consecutive calls to MORECORE
+ with positive arguments always return contiguous increasing
+ addresses. This is true of unix sbrk. It does not hurt too much to
+ set it true anyway, since malloc copes with non-contiguities.
+ Setting it false when definitely non-contiguous saves time
+ and possibly wasted space it would take to discover this though.
+
+MORECORE_CANNOT_TRIM default: NOT defined
+ True if MORECORE cannot release space back to the system when given
+ negative arguments. This is generally necessary only if you are
+ using a hand-crafted MORECORE function that cannot handle negative
+ arguments.
+
+HAVE_MMAP default: 1 (true)
+ True if this system supports mmap or an emulation of it. If so, and
+ HAVE_MORECORE is not true, MMAP is used for all system
+ allocation. If set and HAVE_MORECORE is true as well, MMAP is
+ primarily used to directly allocate very large blocks. It is also
+ used as a backup strategy in cases where MORECORE fails to provide
+ space from system. Note: A single call to MUNMAP is assumed to be
+ able to unmap memory that may have be allocated using multiple calls
+ to MMAP, so long as they are adjacent.
+
+HAVE_MREMAP default: 1 on linux, else 0
+ If true realloc() uses mremap() to re-allocate large blocks and
+ extend or shrink allocation spaces.
+
+MMAP_CLEARS default: 1 on unix
+ True if mmap clears memory so calloc doesn't need to. This is true
+ for standard unix mmap using /dev/zero.
+
+USE_BUILTIN_FFS default: 0 (i.e., not used)
+ Causes malloc to use the builtin ffs() function to compute indices.
+ Some compilers may recognize and intrinsify ffs to be faster than the
+ supplied C version. Also, the case of x86 using gcc is special-cased
+ to an asm instruction, so is already as fast as it can be, and so
+ this setting has no effect. (On most x86s, the asm version is only
+ slightly faster than the C version.)
+
+malloc_getpagesize default: derive from system includes, or 4096.
+ The system page size. To the extent possible, this malloc manages
+ memory from the system in page-size units. This may be (and
+ usually is) a function rather than a constant. This is ignored
+ if WIN32, where page size is determined using getSystemInfo during
+ initialization.
+
+USE_DEV_RANDOM default: 0 (i.e., not used)
+ Causes malloc to use /dev/random to initialize secure magic seed for
+ stamping footers. Otherwise, the current time is used.
+
+NO_MALLINFO default: 0
+ If defined, don't compile "mallinfo". This can be a simple way
+ of dealing with mismatches between system declarations and
+ those in this file.
+
+MALLINFO_FIELD_TYPE default: size_t
+ The type of the fields in the mallinfo struct. This was originally
+ defined as "int" in SVID etc, but is more usefully defined as
+ size_t. The value is used only if HAVE_USR_INCLUDE_MALLOC_H is not set
+
+REALLOC_ZERO_BYTES_FREES default: not defined
+ This should be set if a call to realloc with zero bytes should
+ be the same as a call to free. Some people think it should. Otherwise,
+ since this malloc returns a unique pointer for malloc(0), so does
+ realloc(p, 0).
+
+LACKS_UNISTD_H, LACKS_FCNTL_H, LACKS_SYS_PARAM_H, LACKS_SYS_MMAN_H
+LACKS_STRINGS_H, LACKS_STRING_H, LACKS_SYS_TYPES_H, LACKS_ERRNO_H
+LACKS_STDLIB_H default: NOT defined unless on WIN32
+ Define these if your system does not have these header files.
+ You might need to manually insert some of the declarations they provide.
+
+DEFAULT_GRANULARITY default: page size if MORECORE_CONTIGUOUS,
+ system_info.dwAllocationGranularity in WIN32,
+ otherwise 64K.
+ Also settable using mallopt(M_GRANULARITY, x)
+ The unit for allocating and deallocating memory from the system. On
+ most systems with contiguous MORECORE, there is no reason to
+ make this more than a page. However, systems with MMAP tend to
+ either require or encourage larger granularities. You can increase
+ this value to prevent system allocation functions to be called so
+ often, especially if they are slow. The value must be at least one
+ page and must be a power of two. Setting to 0 causes initialization
+ to either page size or win32 region size. (Note: In previous
+ versions of malloc, the equivalent of this option was called
+ "TOP_PAD")
+
+DEFAULT_TRIM_THRESHOLD default: 2MB
+ Also settable using mallopt(M_TRIM_THRESHOLD, x)
+ The maximum amount of unused top-most memory to keep before
+ releasing via malloc_trim in free(). Automatic trimming is mainly
+ useful in long-lived programs using contiguous MORECORE. Because
+ trimming via sbrk can be slow on some systems, and can sometimes be
+ wasteful (in cases where programs immediately afterward allocate
+ more large chunks) the value should be high enough so that your
+ overall system performance would improve by releasing this much
+ memory. As a rough guide, you might set to a value close to the
+ average size of a process (program) running on your system.
+ Releasing this much memory would allow such a process to run in
+ memory. Generally, it is worth tuning trim thresholds when a
+ program undergoes phases where several large chunks are allocated
+ and released in ways that can reuse each other's storage, perhaps
+ mixed with phases where there are no such chunks at all. The trim
+ value must be greater than page size to have any useful effect. To
+ disable trimming completely, you can set to MAX_SIZE_T. Note that the trick
+ some people use of mallocing a huge space and then freeing it at
+ program startup, in an attempt to reserve system memory, doesn't
+ have the intended effect under automatic trimming, since that memory
+ will immediately be returned to the system.
+
+DEFAULT_MMAP_THRESHOLD default: 256K
+ Also settable using mallopt(M_MMAP_THRESHOLD, x)
+ The request size threshold for using MMAP to directly service a
+ request. Requests of at least this size that cannot be allocated
+ using already-existing space will be serviced via mmap. (If enough
+ normal freed space already exists it is used instead.) Using mmap
+ segregates relatively large chunks of memory so that they can be
+ individually obtained and released from the host system. A request
+ serviced through mmap is never reused by any other request (at least
+ not directly; the system may just so happen to remap successive
+ requests to the same locations). Segregating space in this way has
+ the benefits that: Mmapped space can always be individually released
+ back to the system, which helps keep the system level memory demands
+ of a long-lived program low. Also, mapped memory doesn't become
+ `locked' between other chunks, as can happen with normally allocated
+ chunks, which means that even trimming via malloc_trim would not
+ release them. However, it has the disadvantage that the space
+ cannot be reclaimed, consolidated, and then used to service later
+ requests, as happens with normal chunks. The advantages of mmap
+ nearly always outweigh disadvantages for "large" chunks, but the
+ value of "large" may vary across systems. The default is an
+ empirically derived value that works well in most systems. You can
+ disable mmap by setting to MAX_SIZE_T.
+
+*/
+
+#ifndef WIN32
+#ifdef _WIN32
+#define WIN32 1
+#endif /* _WIN32 */
+#endif /* WIN32 */
+#ifdef WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#define HAVE_MMAP 1
+#define HAVE_MORECORE 0
+#define LACKS_UNISTD_H
+#define LACKS_SYS_PARAM_H
+#define LACKS_SYS_MMAN_H
+#define LACKS_STRING_H
+#define LACKS_STRINGS_H
+#define LACKS_SYS_TYPES_H
+#define LACKS_ERRNO_H
+#define LACKS_FCNTL_H
+#define MALLOC_FAILURE_ACTION
+#define MMAP_CLEARS 0 /* WINCE and some others apparently don't clear */
+#endif /* WIN32 */
+
+#if defined(DARWIN) || defined(_DARWIN)
+/* Mac OSX docs advise not to use sbrk; it seems better to use mmap */
+#ifndef HAVE_MORECORE
+#define HAVE_MORECORE 0
+#define HAVE_MMAP 1
+#endif /* HAVE_MORECORE */
+#endif /* DARWIN */
+
+#ifndef LACKS_SYS_TYPES_H
+#include <sys/types.h> /* For size_t */
+#endif /* LACKS_SYS_TYPES_H */
+
+/* The maximum possible size_t value has all bits set */
+#define MAX_SIZE_T (~(size_t)0)
+
+#ifndef ONLY_MSPACES
+#define ONLY_MSPACES 0
+#endif /* ONLY_MSPACES */
+#ifndef MSPACES
+#if ONLY_MSPACES
+#define MSPACES 1
+#else /* ONLY_MSPACES */
+#define MSPACES 0
+#endif /* ONLY_MSPACES */
+#endif /* MSPACES */
+#ifndef MALLOC_ALIGNMENT
+#define MALLOC_ALIGNMENT ((size_t)8U)
+#endif /* MALLOC_ALIGNMENT */
+#ifndef FOOTERS
+#define FOOTERS 0
+#endif /* FOOTERS */
+#ifndef ABORT
+#define ABORT abort()
+#endif /* ABORT */
+#ifndef ABORT_ON_ASSERT_FAILURE
+#define ABORT_ON_ASSERT_FAILURE 1
+#endif /* ABORT_ON_ASSERT_FAILURE */
+#ifndef PROCEED_ON_ERROR
+#define PROCEED_ON_ERROR 0
+#endif /* PROCEED_ON_ERROR */
+#ifndef USE_LOCKS
+#define USE_LOCKS 0
+#endif /* USE_LOCKS */
+#ifndef INSECURE
+#define INSECURE 0
+#endif /* INSECURE */
+#ifndef HAVE_MMAP
+#define HAVE_MMAP 1
+#endif /* HAVE_MMAP */
+#ifndef MMAP_CLEARS
+#define MMAP_CLEARS 1
+#endif /* MMAP_CLEARS */
+#ifndef HAVE_MREMAP
+#ifdef linux
+#define HAVE_MREMAP 1
+#else /* linux */
+#define HAVE_MREMAP 0
+#endif /* linux */
+#endif /* HAVE_MREMAP */
+#ifndef MALLOC_FAILURE_ACTION
+#define MALLOC_FAILURE_ACTION errno = ENOMEM;
+#endif /* MALLOC_FAILURE_ACTION */
+#ifndef HAVE_MORECORE
+#if ONLY_MSPACES
+#define HAVE_MORECORE 0
+#else /* ONLY_MSPACES */
+#define HAVE_MORECORE 1
+#endif /* ONLY_MSPACES */
+#endif /* HAVE_MORECORE */
+#if !HAVE_MORECORE
+#define MORECORE_CONTIGUOUS 0
+#else /* !HAVE_MORECORE */
+#ifndef MORECORE
+#define MORECORE sbrk
+#endif /* MORECORE */
+#ifndef MORECORE_CONTIGUOUS
+#define MORECORE_CONTIGUOUS 1
+#endif /* MORECORE_CONTIGUOUS */
+#endif /* HAVE_MORECORE */
+#ifndef DEFAULT_GRANULARITY
+#if MORECORE_CONTIGUOUS
+#define DEFAULT_GRANULARITY (0) /* 0 means to compute in init_mparams */
+#else /* MORECORE_CONTIGUOUS */
+#define DEFAULT_GRANULARITY ((size_t)64U * (size_t)1024U)
+#endif /* MORECORE_CONTIGUOUS */
+#endif /* DEFAULT_GRANULARITY */
+#ifndef DEFAULT_TRIM_THRESHOLD
+#ifndef MORECORE_CANNOT_TRIM
+#define DEFAULT_TRIM_THRESHOLD ((size_t)2U * (size_t)1024U * (size_t)1024U)
+#else /* MORECORE_CANNOT_TRIM */
+#define DEFAULT_TRIM_THRESHOLD MAX_SIZE_T
+#endif /* MORECORE_CANNOT_TRIM */
+#endif /* DEFAULT_TRIM_THRESHOLD */
+#ifndef DEFAULT_MMAP_THRESHOLD
+#if HAVE_MMAP
+#define DEFAULT_MMAP_THRESHOLD ((size_t)256U * (size_t)1024U)
+#else /* HAVE_MMAP */
+#define DEFAULT_MMAP_THRESHOLD MAX_SIZE_T
+#endif /* HAVE_MMAP */
+#endif /* DEFAULT_MMAP_THRESHOLD */
+#ifndef USE_BUILTIN_FFS
+#define USE_BUILTIN_FFS 0
+#endif /* USE_BUILTIN_FFS */
+#ifndef USE_DEV_RANDOM
+#define USE_DEV_RANDOM 0
+#endif /* USE_DEV_RANDOM */
+#ifndef NO_MALLINFO
+#define NO_MALLINFO 0
+#endif /* NO_MALLINFO */
+#ifndef MALLINFO_FIELD_TYPE
+#define MALLINFO_FIELD_TYPE size_t
+#endif /* MALLINFO_FIELD_TYPE */
+
+#ifndef memset
+#define memset SDL_memset
+#endif
+#ifndef memcpy
+#define memcpy SDL_memcpy
+#endif
+
+/*
+ mallopt tuning options. SVID/XPG defines four standard parameter
+ numbers for mallopt, normally defined in malloc.h. None of these
+ are used in this malloc, so setting them has no effect. But this
+ malloc does support the following options.
+*/
+
+#define M_TRIM_THRESHOLD (-1)
+#define M_GRANULARITY (-2)
+#define M_MMAP_THRESHOLD (-3)
+
+/* ------------------------ Mallinfo declarations ------------------------ */
+
+#if !NO_MALLINFO
+/*
+ This version of malloc supports the standard SVID/XPG mallinfo
+ routine that returns a struct containing usage properties and
+ statistics. It should work on any system that has a
+ /usr/include/malloc.h defining struct mallinfo. The main
+ declaration needed is the mallinfo struct that is returned (by-copy)
+ by mallinfo(). The malloinfo struct contains a bunch of fields that
+ are not even meaningful in this version of malloc. These fields are
+ are instead filled by mallinfo() with other numbers that might be of
+ interest.
+
+ HAVE_USR_INCLUDE_MALLOC_H should be set if you have a
+ /usr/include/malloc.h file that includes a declaration of struct
+ mallinfo. If so, it is included; else a compliant version is
+ declared below. These must be precisely the same for mallinfo() to
+ work. The original SVID version of this struct, defined on most
+ systems with mallinfo, declares all fields as ints. But some others
+ define as unsigned long. If your system defines the fields using a
+ type of different width than listed here, you MUST #include your
+ system version and #define HAVE_USR_INCLUDE_MALLOC_H.
+*/
+
+/* #define HAVE_USR_INCLUDE_MALLOC_H */
+
+#ifdef HAVE_USR_INCLUDE_MALLOC_H
+#include "/usr/include/malloc.h"
+#else /* HAVE_USR_INCLUDE_MALLOC_H */
+
+struct mallinfo
+{
+ MALLINFO_FIELD_TYPE arena; /* non-mmapped space allocated from system */
+ MALLINFO_FIELD_TYPE ordblks; /* number of free chunks */
+ MALLINFO_FIELD_TYPE smblks; /* always 0 */
+ MALLINFO_FIELD_TYPE hblks; /* always 0 */
+ MALLINFO_FIELD_TYPE hblkhd; /* space in mmapped regions */
+ MALLINFO_FIELD_TYPE usmblks; /* maximum total allocated space */
+ MALLINFO_FIELD_TYPE fsmblks; /* always 0 */
+ MALLINFO_FIELD_TYPE uordblks; /* total allocated space */
+ MALLINFO_FIELD_TYPE fordblks; /* total free space */
+ MALLINFO_FIELD_TYPE keepcost; /* releasable (via malloc_trim) space */
+};
+
+#endif /* HAVE_USR_INCLUDE_MALLOC_H */
+#endif /* NO_MALLINFO */
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#if !ONLY_MSPACES
+
+/* ------------------- Declarations of public routines ------------------- */
+
+#ifndef USE_DL_PREFIX
+#define dlcalloc calloc
+#define dlfree free
+#define dlmalloc malloc
+#define dlmemalign memalign
+#define dlrealloc realloc
+#define dlvalloc valloc
+#define dlpvalloc pvalloc
+#define dlmallinfo mallinfo
+#define dlmallopt mallopt
+#define dlmalloc_trim malloc_trim
+#define dlmalloc_stats malloc_stats
+#define dlmalloc_usable_size malloc_usable_size
+#define dlmalloc_footprint malloc_footprint
+#define dlmalloc_max_footprint malloc_max_footprint
+#define dlindependent_calloc independent_calloc
+#define dlindependent_comalloc independent_comalloc
+#endif /* USE_DL_PREFIX */
+
+
+/*
+ malloc(size_t n)
+ Returns a pointer to a newly allocated chunk of at least n bytes, or
+ null if no space is available, in which case errno is set to ENOMEM
+ on ANSI C systems.
+
+ If n is zero, malloc returns a minimum-sized chunk. (The minimum
+ size is 16 bytes on most 32bit systems, and 32 bytes on 64bit
+ systems.) Note that size_t is an unsigned type, so calls with
+ arguments that would be negative if signed are interpreted as
+ requests for huge amounts of space, which will often fail. The
+ maximum supported value of n differs across systems, but is in all
+ cases less than the maximum representable value of a size_t.
+*/
+ void *dlmalloc(size_t);
+
+/*
+ free(void* p)
+ Releases the chunk of memory pointed to by p, that had been previously
+ allocated using malloc or a related routine such as realloc.
+ It has no effect if p is null. If p was not malloced or already
+ freed, free(p) will by default cause the current program to abort.
+*/
+ void dlfree(void *);
+
+/*
+ calloc(size_t n_elements, size_t element_size);
+ Returns a pointer to n_elements * element_size bytes, with all locations
+ set to zero.
+*/
+ void *dlcalloc(size_t, size_t);
+
+/*
+ realloc(void* p, size_t n)
+ Returns a pointer to a chunk of size n that contains the same data
+ as does chunk p up to the minimum of (n, p's size) bytes, or null
+ if no space is available.
+
+ The returned pointer may or may not be the same as p. The algorithm
+ prefers extending p in most cases when possible, otherwise it
+ employs the equivalent of a malloc-copy-free sequence.
+
+ If p is null, realloc is equivalent to malloc.
+
+ If space is not available, realloc returns null, errno is set (if on
+ ANSI) and p is NOT freed.
+
+ if n is for fewer bytes than already held by p, the newly unused
+ space is lopped off and freed if possible. realloc with a size
+ argument of zero (re)allocates a minimum-sized chunk.
+
+ The old unix realloc convention of allowing the last-free'd chunk
+ to be used as an argument to realloc is not supported.
+*/
+
+ void *dlrealloc(void *, size_t);
+
+/*
+ memalign(size_t alignment, size_t n);
+ Returns a pointer to a newly allocated chunk of n bytes, aligned
+ in accord with the alignment argument.
+
+ The alignment argument should be a power of two. If the argument is
+ not a power of two, the nearest greater power is used.
+ 8-byte alignment is guaranteed by normal malloc calls, so don't
+ bother calling memalign with an argument of 8 or less.
+
+ Overreliance on memalign is a sure way to fragment space.
+*/
+ void *dlmemalign(size_t, size_t);
+
+/*
+ valloc(size_t n);
+ Equivalent to memalign(pagesize, n), where pagesize is the page
+ size of the system. If the pagesize is unknown, 4096 is used.
+*/
+ void *dlvalloc(size_t);
+
+/*
+ mallopt(int parameter_number, int parameter_value)
+ Sets tunable parameters The format is to provide a
+ (parameter-number, parameter-value) pair. mallopt then sets the
+ corresponding parameter to the argument value if it can (i.e., so
+ long as the value is meaningful), and returns 1 if successful else
+ 0. SVID/XPG/ANSI defines four standard param numbers for mallopt,
+ normally defined in malloc.h. None of these are use in this malloc,
+ so setting them has no effect. But this malloc also supports other
+ options in mallopt. See below for details. Briefly, supported
+ parameters are as follows (listed defaults are for "typical"
+ configurations).
+
+ Symbol param # default allowed param values
+ M_TRIM_THRESHOLD -1 2*1024*1024 any (MAX_SIZE_T disables)
+ M_GRANULARITY -2 page size any power of 2 >= page size
+ M_MMAP_THRESHOLD -3 256*1024 any (or 0 if no MMAP support)
+*/
+ int dlmallopt(int, int);
+
+/*
+ malloc_footprint();
+ Returns the number of bytes obtained from the system. The total
+ number of bytes allocated by malloc, realloc etc., is less than this
+ value. Unlike mallinfo, this function returns only a precomputed
+ result, so can be called frequently to monitor memory consumption.
+ Even if locks are otherwise defined, this function does not use them,
+ so results might not be up to date.
+*/
+ size_t dlmalloc_footprint(void);
+
+/*
+ malloc_max_footprint();
+ Returns the maximum number of bytes obtained from the system. This
+ value will be greater than current footprint if deallocated space
+ has been reclaimed by the system. The peak number of bytes allocated
+ by malloc, realloc etc., is less than this value. Unlike mallinfo,
+ this function returns only a precomputed result, so can be called
+ frequently to monitor memory consumption. Even if locks are
+ otherwise defined, this function does not use them, so results might
+ not be up to date.
+*/
+ size_t dlmalloc_max_footprint(void);
+
+#if !NO_MALLINFO
+/*
+ mallinfo()
+ Returns (by copy) a struct containing various summary statistics:
+
+ arena: current total non-mmapped bytes allocated from system
+ ordblks: the number of free chunks
+ smblks: always zero.
+ hblks: current number of mmapped regions
+ hblkhd: total bytes held in mmapped regions
+ usmblks: the maximum total allocated space. This will be greater
+ than current total if trimming has occurred.
+ fsmblks: always zero
+ uordblks: current total allocated space (normal or mmapped)
+ fordblks: total free space
+ keepcost: the maximum number of bytes that could ideally be released
+ back to system via malloc_trim. ("ideally" means that
+ it ignores page restrictions etc.)
+
+ Because these fields are ints, but internal bookkeeping may
+ be kept as longs, the reported values may wrap around zero and
+ thus be inaccurate.
+*/
+ struct mallinfo dlmallinfo(void);
+#endif /* NO_MALLINFO */
+
+/*
+ independent_calloc(size_t n_elements, size_t element_size, void* chunks[]);
+
+ independent_calloc is similar to calloc, but instead of returning a
+ single cleared space, it returns an array of pointers to n_elements
+ independent elements that can hold contents of size elem_size, each
+ of which starts out cleared, and can be independently freed,
+ realloc'ed etc. The elements are guaranteed to be adjacently
+ allocated (this is not guaranteed to occur with multiple callocs or
+ mallocs), which may also improve cache locality in some
+ applications.
+
+ The "chunks" argument is optional (i.e., may be null, which is
+ probably the most typical usage). If it is null, the returned array
+ is itself dynamically allocated and should also be freed when it is
+ no longer needed. Otherwise, the chunks array must be of at least
+ n_elements in length. It is filled in with the pointers to the
+ chunks.
+
+ In either case, independent_calloc returns this pointer array, or
+ null if the allocation failed. If n_elements is zero and "chunks"
+ is null, it returns a chunk representing an array with zero elements
+ (which should be freed if not wanted).
+
+ Each element must be individually freed when it is no longer
+ needed. If you'd like to instead be able to free all at once, you
+ should instead use regular calloc and assign pointers into this
+ space to represent elements. (In this case though, you cannot
+ independently free elements.)
+
+ independent_calloc simplifies and speeds up implementations of many
+ kinds of pools. It may also be useful when constructing large data
+ structures that initially have a fixed number of fixed-sized nodes,
+ but the number is not known at compile time, and some of the nodes
+ may later need to be freed. For example:
+
+ struct Node { int item; struct Node* next; };
+
+ struct Node* build_list() {
+ struct Node** pool;
+ int n = read_number_of_nodes_needed();
+ if (n <= 0) return 0;
+ pool = (struct Node**)(independent_calloc(n, sizeof(struct Node), 0);
+ if (pool == 0) die();
+ // organize into a linked list...
+ struct Node* first = pool[0];
+ for (i = 0; i < n-1; ++i)
+ pool[i]->next = pool[i+1];
+ free(pool); // Can now free the array (or not, if it is needed later)
+ return first;
+ }
+*/
+ void **dlindependent_calloc(size_t, size_t, void **);
+
+/*
+ independent_comalloc(size_t n_elements, size_t sizes[], void* chunks[]);
+
+ independent_comalloc allocates, all at once, a set of n_elements
+ chunks with sizes indicated in the "sizes" array. It returns
+ an array of pointers to these elements, each of which can be
+ independently freed, realloc'ed etc. The elements are guaranteed to
+ be adjacently allocated (this is not guaranteed to occur with
+ multiple callocs or mallocs), which may also improve cache locality
+ in some applications.
+
+ The "chunks" argument is optional (i.e., may be null). If it is null
+ the returned array is itself dynamically allocated and should also
+ be freed when it is no longer needed. Otherwise, the chunks array
+ must be of at least n_elements in length. It is filled in with the
+ pointers to the chunks.
+
+ In either case, independent_comalloc returns this pointer array, or
+ null if the allocation failed. If n_elements is zero and chunks is
+ null, it returns a chunk representing an array with zero elements
+ (which should be freed if not wanted).
+
+ Each element must be individually freed when it is no longer
+ needed. If you'd like to instead be able to free all at once, you
+ should instead use a single regular malloc, and assign pointers at
+ particular offsets in the aggregate space. (In this case though, you
+ cannot independently free elements.)
+
+ independent_comallac differs from independent_calloc in that each
+ element may have a different size, and also that it does not
+ automatically clear elements.
+
+ independent_comalloc can be used to speed up allocation in cases
+ where several structs or objects must always be allocated at the
+ same time. For example:
+
+ struct Head { ... }
+ struct Foot { ... }
+
+ void send_message(char* msg) {
+ int msglen = strlen(msg);
+ size_t sizes[3] = { sizeof(struct Head), msglen, sizeof(struct Foot) };
+ void* chunks[3];
+ if (independent_comalloc(3, sizes, chunks) == 0)
+ die();
+ struct Head* head = (struct Head*)(chunks[0]);
+ char* body = (char*)(chunks[1]);
+ struct Foot* foot = (struct Foot*)(chunks[2]);
+ // ...
+ }
+
+ In general though, independent_comalloc is worth using only for
+ larger values of n_elements. For small values, you probably won't
+ detect enough difference from series of malloc calls to bother.
+
+ Overuse of independent_comalloc can increase overall memory usage,
+ since it cannot reuse existing noncontiguous small chunks that
+ might be available for some of the elements.
+*/
+ void **dlindependent_comalloc(size_t, size_t *, void **);
+
+
+/*
+ pvalloc(size_t n);
+ Equivalent to valloc(minimum-page-that-holds(n)), that is,
+ round up n to nearest pagesize.
+ */
+ void *dlpvalloc(size_t);
+
+/*
+ malloc_trim(size_t pad);
+
+ If possible, gives memory back to the system (via negative arguments
+ to sbrk) if there is unused memory at the `high' end of the malloc
+ pool or in unused MMAP segments. You can call this after freeing
+ large blocks of memory to potentially reduce the system-level memory
+ requirements of a program. However, it cannot guarantee to reduce
+ memory. Under some allocation patterns, some large free blocks of
+ memory will be locked between two used chunks, so they cannot be
+ given back to the system.
+
+ The `pad' argument to malloc_trim represents the amount of free
+ trailing space to leave untrimmed. If this argument is zero, only
+ the minimum amount of memory to maintain internal data structures
+ will be left. Non-zero arguments can be supplied to maintain enough
+ trailing space to service future expected allocations without having
+ to re-obtain memory from the system.
+
+ Malloc_trim returns 1 if it actually released any memory, else 0.
+*/
+ int dlmalloc_trim(size_t);
+
+/*
+ malloc_usable_size(void* p);
+
+ Returns the number of bytes you can actually use in
+ an allocated chunk, which may be more than you requested (although
+ often not) due to alignment and minimum size constraints.
+ You can use this many bytes without worrying about
+ overwriting other allocated objects. This is not a particularly great
+ programming practice. malloc_usable_size can be more useful in
+ debugging and assertions, for example:
+
+ p = malloc(n);
+ assert(malloc_usable_size(p) >= 256);
+*/
+ size_t dlmalloc_usable_size(void *);
+
+/*
+ malloc_stats();
+ Prints on stderr the amount of space obtained from the system (both
+ via sbrk and mmap), the maximum amount (which may be more than
+ current if malloc_trim and/or munmap got called), and the current
+ number of bytes allocated via malloc (or realloc, etc) but not yet
+ freed. Note that this is the number of bytes allocated, not the
+ number requested. It will be larger than the number requested
+ because of alignment and bookkeeping overhead. Because it includes
+ alignment wastage as being in use, this figure may be greater than
+ zero even when no user-level chunks are allocated.
+
+ The reported current and maximum system memory can be inaccurate if
+ a program makes other calls to system memory allocation functions
+ (normally sbrk) outside of malloc.
+
+ malloc_stats prints only the most commonly interesting statistics.
+ More information can be obtained by calling mallinfo.
+*/
+ void dlmalloc_stats(void);
+
+#endif /* ONLY_MSPACES */
+
+#if MSPACES
+
+/*
+ mspace is an opaque type representing an independent
+ region of space that supports mspace_malloc, etc.
+*/
+ typedef void *mspace;
+
+/*
+ create_mspace creates and returns a new independent space with the
+ given initial capacity, or, if 0, the default granularity size. It
+ returns null if there is no system memory available to create the
+ space. If argument locked is non-zero, the space uses a separate
+ lock to control access. The capacity of the space will grow
+ dynamically as needed to service mspace_malloc requests. You can
+ control the sizes of incremental increases of this space by
+ compiling with a different DEFAULT_GRANULARITY or dynamically
+ setting with mallopt(M_GRANULARITY, value).
+*/
+ mspace create_mspace(size_t capacity, int locked);
+
+/*
+ destroy_mspace destroys the given space, and attempts to return all
+ of its memory back to the system, returning the total number of
+ bytes freed. After destruction, the results of access to all memory
+ used by the space become undefined.
+*/
+ size_t destroy_mspace(mspace msp);
+
+/*
+ create_mspace_with_base uses the memory supplied as the initial base
+ of a new mspace. Part (less than 128*sizeof(size_t) bytes) of this
+ space is used for bookkeeping, so the capacity must be at least this
+ large. (Otherwise 0 is returned.) When this initial space is
+ exhausted, additional memory will be obtained from the system.
+ Destroying this space will deallocate all additionally allocated
+ space (if possible) but not the initial base.
+*/
+ mspace create_mspace_with_base(void *base, size_t capacity, int locked);
+
+/*
+ mspace_malloc behaves as malloc, but operates within
+ the given space.
+*/
+ void *mspace_malloc(mspace msp, size_t bytes);
+
+/*
+ mspace_free behaves as free, but operates within
+ the given space.
+
+ If compiled with FOOTERS==1, mspace_free is not actually needed.
+ free may be called instead of mspace_free because freed chunks from
+ any space are handled by their originating spaces.
+*/
+ void mspace_free(mspace msp, void *mem);
+
+/*
+ mspace_realloc behaves as realloc, but operates within
+ the given space.
+
+ If compiled with FOOTERS==1, mspace_realloc is not actually
+ needed. realloc may be called instead of mspace_realloc because
+ realloced chunks from any space are handled by their originating
+ spaces.
+*/
+ void *mspace_realloc(mspace msp, void *mem, size_t newsize);
+
+/*
+ mspace_calloc behaves as calloc, but operates within
+ the given space.
+*/
+ void *mspace_calloc(mspace msp, size_t n_elements, size_t elem_size);
+
+/*
+ mspace_memalign behaves as memalign, but operates within
+ the given space.
+*/
+ void *mspace_memalign(mspace msp, size_t alignment, size_t bytes);
+
+/*
+ mspace_independent_calloc behaves as independent_calloc, but
+ operates within the given space.
+*/
+ void **mspace_independent_calloc(mspace msp, size_t n_elements,
+ size_t elem_size, void *chunks[]);
+
+/*
+ mspace_independent_comalloc behaves as independent_comalloc, but
+ operates within the given space.
+*/
+ void **mspace_independent_comalloc(mspace msp, size_t n_elements,
+ size_t sizes[], void *chunks[]);
+
+/*
+ mspace_footprint() returns the number of bytes obtained from the
+ system for this space.
+*/
+ size_t mspace_footprint(mspace msp);
+
+/*
+ mspace_max_footprint() returns the peak number of bytes obtained from the
+ system for this space.
+*/
+ size_t mspace_max_footprint(mspace msp);
+
+
+#if !NO_MALLINFO
+/*
+ mspace_mallinfo behaves as mallinfo, but reports properties of
+ the given space.
+*/
+ struct mallinfo mspace_mallinfo(mspace msp);
+#endif /* NO_MALLINFO */
+
+/*
+ mspace_malloc_stats behaves as malloc_stats, but reports
+ properties of the given space.
+*/
+ void mspace_malloc_stats(mspace msp);
+
+/*
+ mspace_trim behaves as malloc_trim, but
+ operates within the given space.
+*/
+ int mspace_trim(mspace msp, size_t pad);
+
+/*
+ An alias for mallopt.
+*/
+ int mspace_mallopt(int, int);
+
+#endif /* MSPACES */
+
+#ifdef __cplusplus
+}; /* end of extern "C" */
+#endif /* __cplusplus */
+
+/*
+ ========================================================================
+ To make a fully customizable malloc.h header file, cut everything
+ above this line, put into file malloc.h, edit to suit, and #include it
+ on the next line, as well as in programs that use this malloc.
+ ========================================================================
+*/
+
+/* #include "malloc.h" */
+
+/*------------------------------ internal #includes ---------------------- */
+
+#ifdef _MSC_VER
+#pragma warning( disable : 4146 ) /* no "unsigned" warnings */
+#endif /* _MSC_VER */
+
+#ifndef LACKS_STDIO_H
+#include <stdio.h> /* for printing in malloc_stats */
+#endif
+
+#ifndef LACKS_ERRNO_H
+#include <errno.h> /* for MALLOC_FAILURE_ACTION */
+#endif /* LACKS_ERRNO_H */
+#if FOOTERS
+#include <time.h> /* for magic initialization */
+#endif /* FOOTERS */
+#ifndef LACKS_STDLIB_H
+#include <stdlib.h> /* for abort() */
+#endif /* LACKS_STDLIB_H */
+#ifdef DEBUG
+#if ABORT_ON_ASSERT_FAILURE
+#define assert(x) if(!(x)) ABORT
+#else /* ABORT_ON_ASSERT_FAILURE */
+#include <assert.h>
+#endif /* ABORT_ON_ASSERT_FAILURE */
+#else /* DEBUG */
+#define assert(x)
+#endif /* DEBUG */
+#ifndef LACKS_STRING_H
+#include <string.h> /* for memset etc */
+#endif /* LACKS_STRING_H */
+#if USE_BUILTIN_FFS
+#ifndef LACKS_STRINGS_H
+#include <strings.h> /* for ffs */
+#endif /* LACKS_STRINGS_H */
+#endif /* USE_BUILTIN_FFS */
+#if HAVE_MMAP
+#ifndef LACKS_SYS_MMAN_H
+#include <sys/mman.h> /* for mmap */
+#endif /* LACKS_SYS_MMAN_H */
+#ifndef LACKS_FCNTL_H
+#include <fcntl.h>
+#endif /* LACKS_FCNTL_H */
+#endif /* HAVE_MMAP */
+#if HAVE_MORECORE
+#ifndef LACKS_UNISTD_H
+#include <unistd.h> /* for sbrk */
+#else /* LACKS_UNISTD_H */
+#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
+extern void *sbrk(ptrdiff_t);
+#endif /* FreeBSD etc */
+#endif /* LACKS_UNISTD_H */
+#endif /* HAVE_MMAP */
+
+#ifndef WIN32
+#ifndef malloc_getpagesize
+# ifdef _SC_PAGESIZE /* some SVR4 systems omit an underscore */
+# ifndef _SC_PAGE_SIZE
+# define _SC_PAGE_SIZE _SC_PAGESIZE
+# endif
+# endif
+# ifdef _SC_PAGE_SIZE
+# define malloc_getpagesize sysconf(_SC_PAGE_SIZE)
+# else
+# if defined(BSD) || defined(DGUX) || defined(HAVE_GETPAGESIZE)
+extern size_t getpagesize();
+# define malloc_getpagesize getpagesize()
+# else
+# ifdef WIN32 /* use supplied emulation of getpagesize */
+# define malloc_getpagesize getpagesize()
+# else
+# ifndef LACKS_SYS_PARAM_H
+# include <sys/param.h>
+# endif
+# ifdef EXEC_PAGESIZE
+# define malloc_getpagesize EXEC_PAGESIZE
+# else
+# ifdef NBPG
+# ifndef CLSIZE
+# define malloc_getpagesize NBPG
+# else
+# define malloc_getpagesize (NBPG * CLSIZE)
+# endif
+# else
+# ifdef NBPC
+# define malloc_getpagesize NBPC
+# else
+# ifdef PAGESIZE
+# define malloc_getpagesize PAGESIZE
+# else /* just guess */
+# define malloc_getpagesize ((size_t)4096U)
+# endif
+# endif
+# endif
+# endif
+# endif
+# endif
+# endif
+#endif
+#endif
+
+/* ------------------- size_t and alignment properties -------------------- */
+
+/* The byte and bit size of a size_t */
+#define SIZE_T_SIZE (sizeof(size_t))
+#define SIZE_T_BITSIZE (sizeof(size_t) << 3)
+
+/* Some constants coerced to size_t */
+/* Annoying but necessary to avoid errors on some plaftorms */
+#define SIZE_T_ZERO ((size_t)0)
+#define SIZE_T_ONE ((size_t)1)
+#define SIZE_T_TWO ((size_t)2)
+#define TWO_SIZE_T_SIZES (SIZE_T_SIZE<<1)
+#define FOUR_SIZE_T_SIZES (SIZE_T_SIZE<<2)
+#define SIX_SIZE_T_SIZES (FOUR_SIZE_T_SIZES+TWO_SIZE_T_SIZES)
+#define HALF_MAX_SIZE_T (MAX_SIZE_T / 2U)
+
+/* The bit mask value corresponding to MALLOC_ALIGNMENT */
+#define CHUNK_ALIGN_MASK (MALLOC_ALIGNMENT - SIZE_T_ONE)
+
+/* True if address a has acceptable alignment */
+#define is_aligned(A) (((size_t)((A)) & (CHUNK_ALIGN_MASK)) == 0)
+
+/* the number of bytes to offset an address to align it */
+#define align_offset(A)\
+ ((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :\
+ ((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK))
+
+/* -------------------------- MMAP preliminaries ------------------------- */
+
+/*
+ If HAVE_MORECORE or HAVE_MMAP are false, we just define calls and
+ checks to fail so compiler optimizer can delete code rather than
+ using so many "#if"s.
+*/
+
+
+/* MORECORE and MMAP must return MFAIL on failure */
+#define MFAIL ((void*)(MAX_SIZE_T))
+#define CMFAIL ((char*)(MFAIL)) /* defined for convenience */
+
+#if !HAVE_MMAP
+#define IS_MMAPPED_BIT (SIZE_T_ZERO)
+#define USE_MMAP_BIT (SIZE_T_ZERO)
+#define CALL_MMAP(s) MFAIL
+#define CALL_MUNMAP(a, s) (-1)
+#define DIRECT_MMAP(s) MFAIL
+
+#else /* HAVE_MMAP */
+#define IS_MMAPPED_BIT (SIZE_T_ONE)
+#define USE_MMAP_BIT (SIZE_T_ONE)
+
+#ifndef WIN32
+#define CALL_MUNMAP(a, s) munmap((a), (s))
+#define MMAP_PROT (PROT_READ|PROT_WRITE)
+#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
+#define MAP_ANONYMOUS MAP_ANON
+#endif /* MAP_ANON */
+#ifdef MAP_ANONYMOUS
+#define MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS)
+#define CALL_MMAP(s) mmap(0, (s), MMAP_PROT, MMAP_FLAGS, -1, 0)
+#else /* MAP_ANONYMOUS */
+/*
+ Nearly all versions of mmap support MAP_ANONYMOUS, so the following
+ is unlikely to be needed, but is supplied just in case.
+*/
+#define MMAP_FLAGS (MAP_PRIVATE)
+static int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */
+#define CALL_MMAP(s) ((dev_zero_fd < 0) ? \
+ (dev_zero_fd = open("/dev/zero", O_RDWR), \
+ mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0)) : \
+ mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0))
+#endif /* MAP_ANONYMOUS */
+
+#define DIRECT_MMAP(s) CALL_MMAP(s)
+#else /* WIN32 */
+
+/* Win32 MMAP via VirtualAlloc */
+static void *
+win32mmap(size_t size)
+{
+ void *ptr =
+ VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
+ return (ptr != 0) ? ptr : MFAIL;
+}
+
+/* For direct MMAP, use MEM_TOP_DOWN to minimize interference */
+static void *
+win32direct_mmap(size_t size)
+{
+ void *ptr = VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN,
+ PAGE_READWRITE);
+ return (ptr != 0) ? ptr : MFAIL;
+}
+
+/* This function supports releasing coalesed segments */
+static int
+win32munmap(void *ptr, size_t size)
+{
+ MEMORY_BASIC_INFORMATION minfo;
+ char *cptr = ptr;
+ while (size) {
+ if (VirtualQuery(cptr, &minfo, sizeof(minfo)) == 0)
+ return -1;
+ if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr ||
+ minfo.State != MEM_COMMIT || minfo.RegionSize > size)
+ return -1;
+ if (VirtualFree(cptr, 0, MEM_RELEASE) == 0)
+ return -1;
+ cptr += minfo.RegionSize;
+ size -= minfo.RegionSize;
+ }
+ return 0;
+}
+
+#define CALL_MMAP(s) win32mmap(s)
+#define CALL_MUNMAP(a, s) win32munmap((a), (s))
+#define DIRECT_MMAP(s) win32direct_mmap(s)
+#endif /* WIN32 */
+#endif /* HAVE_MMAP */
+
+#if HAVE_MMAP && HAVE_MREMAP
+#define CALL_MREMAP(addr, osz, nsz, mv) mremap((addr), (osz), (nsz), (mv))
+#else /* HAVE_MMAP && HAVE_MREMAP */
+#define CALL_MREMAP(addr, osz, nsz, mv) MFAIL
+#endif /* HAVE_MMAP && HAVE_MREMAP */
+
+#if HAVE_MORECORE
+#define CALL_MORECORE(S) MORECORE(S)
+#else /* HAVE_MORECORE */
+#define CALL_MORECORE(S) MFAIL
+#endif /* HAVE_MORECORE */
+
+/* mstate bit set if continguous morecore disabled or failed */
+#define USE_NONCONTIGUOUS_BIT (4U)
+
+/* segment bit set in create_mspace_with_base */
+#define EXTERN_BIT (8U)
+
+
+/* --------------------------- Lock preliminaries ------------------------ */
+
+#if USE_LOCKS
+
+/*
+ When locks are defined, there are up to two global locks:
+
+ * If HAVE_MORECORE, morecore_mutex protects sequences of calls to
+ MORECORE. In many cases sys_alloc requires two calls, that should
+ not be interleaved with calls by other threads. This does not
+ protect against direct calls to MORECORE by other threads not
+ using this lock, so there is still code to cope the best we can on
+ interference.
+
+ * magic_init_mutex ensures that mparams.magic and other
+ unique mparams values are initialized only once.
+*/
+
+#ifndef WIN32
+/* By default use posix locks */
+#include <pthread.h>
+#define MLOCK_T pthread_mutex_t
+#define INITIAL_LOCK(l) pthread_mutex_init(l, NULL)
+#define ACQUIRE_LOCK(l) pthread_mutex_lock(l)
+#define RELEASE_LOCK(l) pthread_mutex_unlock(l)
+
+#if HAVE_MORECORE
+static MLOCK_T morecore_mutex = PTHREAD_MUTEX_INITIALIZER;
+#endif /* HAVE_MORECORE */
+
+static MLOCK_T magic_init_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+#else /* WIN32 */
+/*
+ Because lock-protected regions have bounded times, and there
+ are no recursive lock calls, we can use simple spinlocks.
+*/
+
+#define MLOCK_T long
+static int
+win32_acquire_lock(MLOCK_T * sl)
+{
+ for (;;) {
+#ifdef InterlockedCompareExchangePointer
+ if (!InterlockedCompareExchange(sl, 1, 0))
+ return 0;
+#else /* Use older void* version */
+ if (!InterlockedCompareExchange((void **) sl, (void *) 1, (void *) 0))
+ return 0;
+#endif /* InterlockedCompareExchangePointer */
+ Sleep(0);
+ }
+}
+
+static void
+win32_release_lock(MLOCK_T * sl)
+{
+ InterlockedExchange(sl, 0);
+}
+
+#define INITIAL_LOCK(l) *(l)=0
+#define ACQUIRE_LOCK(l) win32_acquire_lock(l)
+#define RELEASE_LOCK(l) win32_release_lock(l)
+#if HAVE_MORECORE
+static MLOCK_T morecore_mutex;
+#endif /* HAVE_MORECORE */
+static MLOCK_T magic_init_mutex;
+#endif /* WIN32 */
+
+#define USE_LOCK_BIT (2U)
+#else /* USE_LOCKS */
+#define USE_LOCK_BIT (0U)
+#define INITIAL_LOCK(l)
+#endif /* USE_LOCKS */
+
+#if USE_LOCKS && HAVE_MORECORE
+#define ACQUIRE_MORECORE_LOCK() ACQUIRE_LOCK(&morecore_mutex);
+#define RELEASE_MORECORE_LOCK() RELEASE_LOCK(&morecore_mutex);
+#else /* USE_LOCKS && HAVE_MORECORE */
+#define ACQUIRE_MORECORE_LOCK()
+#define RELEASE_MORECORE_LOCK()
+#endif /* USE_LOCKS && HAVE_MORECORE */
+
+#if USE_LOCKS
+#define ACQUIRE_MAGIC_INIT_LOCK() ACQUIRE_LOCK(&magic_init_mutex);
+#define RELEASE_MAGIC_INIT_LOCK() RELEASE_LOCK(&magic_init_mutex);
+#else /* USE_LOCKS */
+#define ACQUIRE_MAGIC_INIT_LOCK()
+#define RELEASE_MAGIC_INIT_LOCK()
+#endif /* USE_LOCKS */
+
+
+/* ----------------------- Chunk representations ------------------------ */
+
+/*
+ (The following includes lightly edited explanations by Colin Plumb.)
+
+ The malloc_chunk declaration below is misleading (but accurate and
+ necessary). It declares a "view" into memory allowing access to
+ necessary fields at known offsets from a given base.
+
+ Chunks of memory are maintained using a `boundary tag' method as
+ originally described by Knuth. (See the paper by Paul Wilson
+ ftp://ftp.cs.utexas.edu/pub/garbage/allocsrv.ps for a survey of such
+ techniques.) Sizes of free chunks are stored both in the front of
+ each chunk and at the end. This makes consolidating fragmented
+ chunks into bigger chunks fast. The head fields also hold bits
+ representing whether chunks are free or in use.
+
+ Here are some pictures to make it clearer. They are "exploded" to
+ show that the state of a chunk can be thought of as extending from
+ the high 31 bits of the head field of its header through the
+ prev_foot and PINUSE_BIT bit of the following chunk header.
+
+ A chunk that's in use looks like:
+
+ chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Size of previous chunk (if P = 1) |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |P|
+ | Size of this chunk 1| +-+
+ mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | |
+ +- -+
+ | |
+ +- -+
+ | :
+ +- size - sizeof(size_t) available payload bytes -+
+ : |
+ chunk-> +- -+
+ | |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1|
+ | Size of next chunk (may or may not be in use) | +-+
+ mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ And if it's free, it looks like this:
+
+ chunk-> +- -+
+ | User payload (must be in use, or we would have merged!) |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |P|
+ | Size of this chunk 0| +-+
+ mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Next pointer |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Prev pointer |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | :
+ +- size - sizeof(struct chunk) unused bytes -+
+ : |
+ chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Size of this chunk |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0|
+ | Size of next chunk (must be in use, or we would have merged)| +-+
+ mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | :
+ +- User payload -+
+ : |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ |0|
+ +-+
+ Note that since we always merge adjacent free chunks, the chunks
+ adjacent to a free chunk must be in use.
+
+ Given a pointer to a chunk (which can be derived trivially from the
+ payload pointer) we can, in O(1) time, find out whether the adjacent
+ chunks are free, and if so, unlink them from the lists that they
+ are on and merge them with the current chunk.
+
+ Chunks always begin on even word boundaries, so the mem portion
+ (which is returned to the user) is also on an even word boundary, and
+ thus at least double-word aligned.
+
+ The P (PINUSE_BIT) bit, stored in the unused low-order bit of the
+ chunk size (which is always a multiple of two words), is an in-use
+ bit for the *previous* chunk. If that bit is *clear*, then the
+ word before the current chunk size contains the previous chunk
+ size, and can be used to find the front of the previous chunk.
+ The very first chunk allocated always has this bit set, preventing
+ access to non-existent (or non-owned) memory. If pinuse is set for
+ any given chunk, then you CANNOT determine the size of the
+ previous chunk, and might even get a memory addressing fault when
+ trying to do so.
+
+ The C (CINUSE_BIT) bit, stored in the unused second-lowest bit of
+ the chunk size redundantly records whether the current chunk is
+ inuse. This redundancy enables usage checks within free and realloc,
+ and reduces indirection when freeing and consolidating chunks.
+
+ Each freshly allocated chunk must have both cinuse and pinuse set.
+ That is, each allocated chunk borders either a previously allocated
+ and still in-use chunk, or the base of its memory arena. This is
+ ensured by making all allocations from the the `lowest' part of any
+ found chunk. Further, no free chunk physically borders another one,
+ so each free chunk is known to be preceded and followed by either
+ inuse chunks or the ends of memory.
+
+ Note that the `foot' of the current chunk is actually represented
+ as the prev_foot of the NEXT chunk. This makes it easier to
+ deal with alignments etc but can be very confusing when trying
+ to extend or adapt this code.
+
+ The exceptions to all this are
+
+ 1. The special chunk `top' is the top-most available chunk (i.e.,
+ the one bordering the end of available memory). It is treated
+ specially. Top is never included in any bin, is used only if
+ no other chunk is available, and is released back to the
+ system if it is very large (see M_TRIM_THRESHOLD). In effect,
+ the top chunk is treated as larger (and thus less well
+ fitting) than any other available chunk. The top chunk
+ doesn't update its trailing size field since there is no next
+ contiguous chunk that would have to index off it. However,
+ space is still allocated for it (TOP_FOOT_SIZE) to enable
+ separation or merging when space is extended.
+
+ 3. Chunks allocated via mmap, which have the lowest-order bit
+ (IS_MMAPPED_BIT) set in their prev_foot fields, and do not set
+ PINUSE_BIT in their head fields. Because they are allocated
+ one-by-one, each must carry its own prev_foot field, which is
+ also used to hold the offset this chunk has within its mmapped
+ region, which is needed to preserve alignment. Each mmapped
+ chunk is trailed by the first two fields of a fake next-chunk
+ for sake of usage checks.
+
+*/
+
+struct malloc_chunk
+{
+ size_t prev_foot; /* Size of previous chunk (if free). */
+ size_t head; /* Size and inuse bits. */
+ struct malloc_chunk *fd; /* double links -- used only if free. */
+ struct malloc_chunk *bk;
+};
+
+typedef struct malloc_chunk mchunk;
+typedef struct malloc_chunk *mchunkptr;
+typedef struct malloc_chunk *sbinptr; /* The type of bins of chunks */
+typedef size_t bindex_t; /* Described below */
+typedef unsigned int binmap_t; /* Described below */
+typedef unsigned int flag_t; /* The type of various bit flag sets */
+
+/* ------------------- Chunks sizes and alignments ----------------------- */
+
+#define MCHUNK_SIZE (sizeof(mchunk))
+
+#if FOOTERS
+#define CHUNK_OVERHEAD (TWO_SIZE_T_SIZES)
+#else /* FOOTERS */
+#define CHUNK_OVERHEAD (SIZE_T_SIZE)
+#endif /* FOOTERS */
+
+/* MMapped chunks need a second word of overhead ... */
+#define MMAP_CHUNK_OVERHEAD (TWO_SIZE_T_SIZES)
+/* ... and additional padding for fake next-chunk at foot */
+#define MMAP_FOOT_PAD (FOUR_SIZE_T_SIZES)
+
+/* The smallest size we can malloc is an aligned minimal chunk */
+#define MIN_CHUNK_SIZE\
+ ((MCHUNK_SIZE + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK)
+
+/* conversion from malloc headers to user pointers, and back */
+#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
+#define mem2chunk(mem) ((mchunkptr)((char*)(mem) - TWO_SIZE_T_SIZES))
+/* chunk associated with aligned address A */
+#define align_as_chunk(A) (mchunkptr)((A) + align_offset(chunk2mem(A)))
+
+/* Bounds on request (not chunk) sizes. */
+#define MAX_REQUEST ((-MIN_CHUNK_SIZE) << 2)
+#define MIN_REQUEST (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE)
+
+/* pad request bytes into a usable size */
+#define pad_request(req) \
+ (((req) + CHUNK_OVERHEAD + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK)
+
+/* pad request, checking for minimum (but not maximum) */
+#define request2size(req) \
+ (((req) < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(req))
+
+
+/* ------------------ Operations on head and foot fields ----------------- */
+
+/*
+ The head field of a chunk is or'ed with PINUSE_BIT when previous
+ adjacent chunk in use, and or'ed with CINUSE_BIT if this chunk is in
+ use. If the chunk was obtained with mmap, the prev_foot field has
+ IS_MMAPPED_BIT set, otherwise holding the offset of the base of the
+ mmapped region to the base of the chunk.
+*/
+
+#define PINUSE_BIT (SIZE_T_ONE)
+#define CINUSE_BIT (SIZE_T_TWO)
+#define INUSE_BITS (PINUSE_BIT|CINUSE_BIT)
+
+/* Head value for fenceposts */
+#define FENCEPOST_HEAD (INUSE_BITS|SIZE_T_SIZE)
+
+/* extraction of fields from head words */
+#define cinuse(p) ((p)->head & CINUSE_BIT)
+#define pinuse(p) ((p)->head & PINUSE_BIT)
+#define chunksize(p) ((p)->head & ~(INUSE_BITS))
+
+#define clear_pinuse(p) ((p)->head &= ~PINUSE_BIT)
+#define clear_cinuse(p) ((p)->head &= ~CINUSE_BIT)
+
+/* Treat space at ptr +/- offset as a chunk */
+#define chunk_plus_offset(p, s) ((mchunkptr)(((char*)(p)) + (s)))
+#define chunk_minus_offset(p, s) ((mchunkptr)(((char*)(p)) - (s)))
+
+/* Ptr to next or previous physical malloc_chunk. */
+#define next_chunk(p) ((mchunkptr)( ((char*)(p)) + ((p)->head & ~INUSE_BITS)))
+#define prev_chunk(p) ((mchunkptr)( ((char*)(p)) - ((p)->prev_foot) ))
+
+/* extract next chunk's pinuse bit */
+#define next_pinuse(p) ((next_chunk(p)->head) & PINUSE_BIT)
+
+/* Get/set size at footer */
+#define get_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_foot)
+#define set_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_foot = (s))
+
+/* Set size, pinuse bit, and foot */
+#define set_size_and_pinuse_of_free_chunk(p, s)\
+ ((p)->head = (s|PINUSE_BIT), set_foot(p, s))
+
+/* Set size, pinuse bit, foot, and clear next pinuse */
+#define set_free_with_pinuse(p, s, n)\
+ (clear_pinuse(n), set_size_and_pinuse_of_free_chunk(p, s))
+
+#define is_mmapped(p)\
+ (!((p)->head & PINUSE_BIT) && ((p)->prev_foot & IS_MMAPPED_BIT))
+
+/* Get the internal overhead associated with chunk p */
+#define overhead_for(p)\
+ (is_mmapped(p)? MMAP_CHUNK_OVERHEAD : CHUNK_OVERHEAD)
+
+/* Return true if malloced space is not necessarily cleared */
+#if MMAP_CLEARS
+#define calloc_must_clear(p) (!is_mmapped(p))
+#else /* MMAP_CLEARS */
+#define calloc_must_clear(p) (1)
+#endif /* MMAP_CLEARS */
+
+/* ---------------------- Overlaid data structures ----------------------- */
+
+/*
+ When chunks are not in use, they are treated as nodes of either
+ lists or trees.
+
+ "Small" chunks are stored in circular doubly-linked lists, and look
+ like this:
+
+ chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Size of previous chunk |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ `head:' | Size of chunk, in bytes |P|
+ mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Forward pointer to next chunk in list |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Back pointer to previous chunk in list |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Unused space (may be 0 bytes long) .
+ . .
+ . |
+nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ `foot:' | Size of chunk, in bytes |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Larger chunks are kept in a form of bitwise digital trees (aka
+ tries) keyed on chunksizes. Because malloc_tree_chunks are only for
+ free chunks greater than 256 bytes, their size doesn't impose any
+ constraints on user chunk sizes. Each node looks like:
+
+ chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Size of previous chunk |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ `head:' | Size of chunk, in bytes |P|
+ mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Forward pointer to next chunk of same size |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Back pointer to previous chunk of same size |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Pointer to left child (child[0]) |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Pointer to right child (child[1]) |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Pointer to parent |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | bin index of this chunk |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ | Unused space .
+ . |
+nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ `foot:' | Size of chunk, in bytes |
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Each tree holding treenodes is a tree of unique chunk sizes. Chunks
+ of the same size are arranged in a circularly-linked list, with only
+ the oldest chunk (the next to be used, in our FIFO ordering)
+ actually in the tree. (Tree members are distinguished by a non-null
+ parent pointer.) If a chunk with the same size an an existing node
+ is inserted, it is linked off the existing node using pointers that
+ work in the same way as fd/bk pointers of small chunks.
+
+ Each tree contains a power of 2 sized range of chunk sizes (the
+ smallest is 0x100 <= x < 0x180), which is is divided in half at each
+ tree level, with the chunks in the smaller half of the range (0x100
+ <= x < 0x140 for the top nose) in the left subtree and the larger
+ half (0x140 <= x < 0x180) in the right subtree. This is, of course,
+ done by inspecting individual bits.
+
+ Using these rules, each node's left subtree contains all smaller
+ sizes than its right subtree. However, the node at the root of each
+ subtree has no particular ordering relationship to either. (The
+ dividing line between the subtree sizes is based on trie relation.)
+ If we remove the last chunk of a given size from the interior of the
+ tree, we need to replace it with a leaf node. The tree ordering
+ rules permit a node to be replaced by any leaf below it.
+
+ The smallest chunk in a tree (a common operation in a best-fit
+ allocator) can be found by walking a path to the leftmost leaf in
+ the tree. Unlike a usual binary tree, where we follow left child
+ pointers until we reach a null, here we follow the right child
+ pointer any time the left one is null, until we reach a leaf with
+ both child pointers null. The smallest chunk in the tree will be
+ somewhere along that path.
+
+ The worst case number of steps to add, find, or remove a node is
+ bounded by the number of bits differentiating chunks within
+ bins. Under current bin calculations, this ranges from 6 up to 21
+ (for 32 bit sizes) or up to 53 (for 64 bit sizes). The typical case
+ is of course much better.
+*/
+
+struct malloc_tree_chunk
+{
+ /* The first four fields must be compatible with malloc_chunk */
+ size_t prev_foot;
+ size_t head;
+ struct malloc_tree_chunk *fd;
+ struct malloc_tree_chunk *bk;
+
+ struct malloc_tree_chunk *child[2];
+ struct malloc_tree_chunk *parent;
+ bindex_t index;
+};
+
+typedef struct malloc_tree_chunk tchunk;
+typedef struct malloc_tree_chunk *tchunkptr;
+typedef struct malloc_tree_chunk *tbinptr; /* The type of bins of trees */
+
+/* A little helper macro for trees */
+#define leftmost_child(t) ((t)->child[0] != 0? (t)->child[0] : (t)->child[1])
+
+/* ----------------------------- Segments -------------------------------- */
+
+/*
+ Each malloc space may include non-contiguous segments, held in a
+ list headed by an embedded malloc_segment record representing the
+ top-most space. Segments also include flags holding properties of
+ the space. Large chunks that are directly allocated by mmap are not
+ included in this list. They are instead independently created and
+ destroyed without otherwise keeping track of them.
+
+ Segment management mainly comes into play for spaces allocated by
+ MMAP. Any call to MMAP might or might not return memory that is
+ adjacent to an existing segment. MORECORE normally contiguously
+ extends the current space, so this space is almost always adjacent,
+ which is simpler and faster to deal with. (This is why MORECORE is
+ used preferentially to MMAP when both are available -- see
+ sys_alloc.) When allocating using MMAP, we don't use any of the
+ hinting mechanisms (inconsistently) supported in various
+ implementations of unix mmap, or distinguish reserving from
+ committing memory. Instead, we just ask for space, and exploit
+ contiguity when we get it. It is probably possible to do
+ better than this on some systems, but no general scheme seems
+ to be significantly better.
+
+ Management entails a simpler variant of the consolidation scheme
+ used for chunks to reduce fragmentation -- new adjacent memory is
+ normally prepended or appended to an existing segment. However,
+ there are limitations compared to chunk consolidation that mostly
+ reflect the fact that segment processing is relatively infrequent
+ (occurring only when getting memory from system) and that we
+ don't expect to have huge numbers of segments:
+
+ * Segments are not indexed, so traversal requires linear scans. (It
+ would be possible to index these, but is not worth the extra
+ overhead and complexity for most programs on most platforms.)
+ * New segments are only appended to old ones when holding top-most
+ memory; if they cannot be prepended to others, they are held in
+ different segments.
+
+ Except for the top-most segment of an mstate, each segment record
+ is kept at the tail of its segment. Segments are added by pushing
+ segment records onto the list headed by &mstate.seg for the
+ containing mstate.
+
+ Segment flags control allocation/merge/deallocation policies:
+ * If EXTERN_BIT set, then we did not allocate this segment,
+ and so should not try to deallocate or merge with others.
+ (This currently holds only for the initial segment passed
+ into create_mspace_with_base.)
+ * If IS_MMAPPED_BIT set, the segment may be merged with
+ other surrounding mmapped segments and trimmed/de-allocated
+ using munmap.
+ * If neither bit is set, then the segment was obtained using
+ MORECORE so can be merged with surrounding MORECORE'd segments
+ and deallocated/trimmed using MORECORE with negative arguments.
+*/
+
+struct malloc_segment
+{
+ char *base; /* base address */
+ size_t size; /* allocated size */
+ struct malloc_segment *next; /* ptr to next segment */
+ flag_t sflags; /* mmap and extern flag */
+};
+
+#define is_mmapped_segment(S) ((S)->sflags & IS_MMAPPED_BIT)
+#define is_extern_segment(S) ((S)->sflags & EXTERN_BIT)
+
+typedef struct malloc_segment msegment;
+typedef struct malloc_segment *msegmentptr;
+
+/* ---------------------------- malloc_state ----------------------------- */
+
+/*
+ A malloc_state holds all of the bookkeeping for a space.
+ The main fields are:
+
+ Top
+ The topmost chunk of the currently active segment. Its size is
+ cached in topsize. The actual size of topmost space is
+ topsize+TOP_FOOT_SIZE, which includes space reserved for adding
+ fenceposts and segment records if necessary when getting more
+ space from the system. The size at which to autotrim top is
+ cached from mparams in trim_check, except that it is disabled if
+ an autotrim fails.
+
+ Designated victim (dv)
+ This is the preferred chunk for servicing small requests that
+ don't have exact fits. It is normally the chunk split off most
+ recently to service another small request. Its size is cached in
+ dvsize. The link fields of this chunk are not maintained since it
+ is not kept in a bin.
+
+ SmallBins
+ An array of bin headers for free chunks. These bins hold chunks
+ with sizes less than MIN_LARGE_SIZE bytes. Each bin contains
+ chunks of all the same size, spaced 8 bytes apart. To simplify
+ use in double-linked lists, each bin header acts as a malloc_chunk
+ pointing to the real first node, if it exists (else pointing to
+ itself). This avoids special-casing for headers. But to avoid
+ waste, we allocate only the fd/bk pointers of bins, and then use
+ repositioning tricks to treat these as the fields of a chunk.
+
+ TreeBins
+ Treebins are pointers to the roots of trees holding a range of
+ sizes. There are 2 equally spaced treebins for each power of two
+ from TREE_SHIFT to TREE_SHIFT+16. The last bin holds anything
+ larger.
+
+ Bin maps
+ There is one bit map for small bins ("smallmap") and one for
+ treebins ("treemap). Each bin sets its bit when non-empty, and
+ clears the bit when empty. Bit operations are then used to avoid
+ bin-by-bin searching -- nearly all "search" is done without ever
+ looking at bins that won't be selected. The bit maps
+ conservatively use 32 bits per map word, even if on 64bit system.
+ For a good description of some of the bit-based techniques used
+ here, see Henry S. Warren Jr's book "Hacker's Delight" (and
+ supplement at http://hackersdelight.org/). Many of these are
+ intended to reduce the branchiness of paths through malloc etc, as
+ well as to reduce the number of memory locations read or written.
+
+ Segments
+ A list of segments headed by an embedded malloc_segment record
+ representing the initial space.
+
+ Address check support
+ The least_addr field is the least address ever obtained from
+ MORECORE or MMAP. Attempted frees and reallocs of any address less
+ than this are trapped (unless INSECURE is defined).
+
+ Magic tag
+ A cross-check field that should always hold same value as mparams.magic.
+
+ Flags
+ Bits recording whether to use MMAP, locks, or contiguous MORECORE
+
+ Statistics
+ Each space keeps track of current and maximum system memory
+ obtained via MORECORE or MMAP.
+
+ Locking
+ If USE_LOCKS is defined, the "mutex" lock is acquired and released
+ around every public call using this mspace.
+*/
+
+/* Bin types, widths and sizes */
+#define NSMALLBINS (32U)
+#define NTREEBINS (32U)
+#define SMALLBIN_SHIFT (3U)
+#define SMALLBIN_WIDTH (SIZE_T_ONE << SMALLBIN_SHIFT)
+#define TREEBIN_SHIFT (8U)
+#define MIN_LARGE_SIZE (SIZE_T_ONE << TREEBIN_SHIFT)
+#define MAX_SMALL_SIZE (MIN_LARGE_SIZE - SIZE_T_ONE)
+#define MAX_SMALL_REQUEST (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD)
+
+struct malloc_state
+{
+ binmap_t smallmap;
+ binmap_t treemap;
+ size_t dvsize;
+ size_t topsize;
+ char *least_addr;
+ mchunkptr dv;
+ mchunkptr top;
+ size_t trim_check;
+ size_t magic;
+ mchunkptr smallbins[(NSMALLBINS + 1) * 2];
+ tbinptr treebins[NTREEBINS];
+ size_t footprint;
+ size_t max_footprint;
+ flag_t mflags;
+#if USE_LOCKS
+ MLOCK_T mutex; /* locate lock among fields that rarely change */
+#endif /* USE_LOCKS */
+ msegment seg;
+};
+
+typedef struct malloc_state *mstate;
+
+/* ------------- Global malloc_state and malloc_params ------------------- */
+
+/*
+ malloc_params holds global properties, including those that can be
+ dynamically set using mallopt. There is a single instance, mparams,
+ initialized in init_mparams.
+*/
+
+struct malloc_params
+{
+ size_t magic;
+ size_t page_size;
+ size_t granularity;
+ size_t mmap_threshold;
+ size_t trim_threshold;
+ flag_t default_mflags;
+};
+
+static struct malloc_params mparams;
+
+/* The global malloc_state used for all non-"mspace" calls */
+static struct malloc_state _gm_;
+#define gm (&_gm_)
+#define is_global(M) ((M) == &_gm_)
+#define is_initialized(M) ((M)->top != 0)
+
+/* -------------------------- system alloc setup ------------------------- */
+
+/* Operations on mflags */
+
+#define use_lock(M) ((M)->mflags & USE_LOCK_BIT)
+#define enable_lock(M) ((M)->mflags |= USE_LOCK_BIT)
+#define disable_lock(M) ((M)->mflags &= ~USE_LOCK_BIT)
+
+#define use_mmap(M) ((M)->mflags & USE_MMAP_BIT)
+#define enable_mmap(M) ((M)->mflags |= USE_MMAP_BIT)
+#define disable_mmap(M) ((M)->mflags &= ~USE_MMAP_BIT)
+
+#define use_noncontiguous(M) ((M)->mflags & USE_NONCONTIGUOUS_BIT)
+#define disable_contiguous(M) ((M)->mflags |= USE_NONCONTIGUOUS_BIT)
+
+#define set_lock(M,L)\
+ ((M)->mflags = (L)?\
+ ((M)->mflags | USE_LOCK_BIT) :\
+ ((M)->mflags & ~USE_LOCK_BIT))
+
+/* page-align a size */
+#define page_align(S)\
+ (((S) + (mparams.page_size)) & ~(mparams.page_size - SIZE_T_ONE))
+
+/* granularity-align a size */
+#define granularity_align(S)\
+ (((S) + (mparams.granularity)) & ~(mparams.granularity - SIZE_T_ONE))
+
+#define is_page_aligned(S)\
+ (((size_t)(S) & (mparams.page_size - SIZE_T_ONE)) == 0)
+#define is_granularity_aligned(S)\
+ (((size_t)(S) & (mparams.granularity - SIZE_T_ONE)) == 0)
+
+/* True if segment S holds address A */
+#define segment_holds(S, A)\
+ ((char*)(A) >= S->base && (char*)(A) < S->base + S->size)
+
+/* Return segment holding given address */
+static msegmentptr
+segment_holding(mstate m, char *addr)
+{
+ msegmentptr sp = &m->seg;
+ for (;;) {
+ if (addr >= sp->base && addr < sp->base + sp->size)
+ return sp;
+ if ((sp = sp->next) == 0)
+ return 0;
+ }
+}
+
+/* Return true if segment contains a segment link */
+static int
+has_segment_link(mstate m, msegmentptr ss)
+{
+ msegmentptr sp = &m->seg;
+ for (;;) {
+ if ((char *) sp >= ss->base && (char *) sp < ss->base + ss->size)
+ return 1;
+ if ((sp = sp->next) == 0)
+ return 0;
+ }
+}
+
+#ifndef MORECORE_CANNOT_TRIM
+#define should_trim(M,s) ((s) > (M)->trim_check)
+#else /* MORECORE_CANNOT_TRIM */
+#define should_trim(M,s) (0)
+#endif /* MORECORE_CANNOT_TRIM */
+
+/*
+ TOP_FOOT_SIZE is padding at the end of a segment, including space
+ that may be needed to place segment records and fenceposts when new
+ noncontiguous segments are added.
+*/
+#define TOP_FOOT_SIZE\
+ (align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
+
+
+/* ------------------------------- Hooks -------------------------------- */
+
+/*
+ PREACTION should be defined to return 0 on success, and nonzero on
+ failure. If you are not using locking, you can redefine these to do
+ anything you like.
+*/
+
+#if USE_LOCKS
+
+/* Ensure locks are initialized */
+#define GLOBALLY_INITIALIZE() (mparams.page_size == 0 && init_mparams())
+
+#define PREACTION(M) ((GLOBALLY_INITIALIZE() || use_lock(M))? ACQUIRE_LOCK(&(M)->mutex) : 0)
+#define POSTACTION(M) { if (use_lock(M)) RELEASE_LOCK(&(M)->mutex); }
+#else /* USE_LOCKS */
+
+#ifndef PREACTION
+#define PREACTION(M) (0)
+#endif /* PREACTION */
+
+#ifndef POSTACTION
+#define POSTACTION(M)
+#endif /* POSTACTION */
+
+#endif /* USE_LOCKS */
+
+/*
+ CORRUPTION_ERROR_ACTION is triggered upon detected bad addresses.
+ USAGE_ERROR_ACTION is triggered on detected bad frees and
+ reallocs. The argument p is an address that might have triggered the
+ fault. It is ignored by the two predefined actions, but might be
+ useful in custom actions that try to help diagnose errors.
+*/
+
+#if PROCEED_ON_ERROR
+
+/* A count of the number of corruption errors causing resets */
+int malloc_corruption_error_count;
+
+/* default corruption action */
+static void reset_on_error(mstate m);
+
+#define CORRUPTION_ERROR_ACTION(m) reset_on_error(m)
+#define USAGE_ERROR_ACTION(m, p)
+
+#else /* PROCEED_ON_ERROR */
+
+#ifndef CORRUPTION_ERROR_ACTION
+#define CORRUPTION_ERROR_ACTION(m) ABORT
+#endif /* CORRUPTION_ERROR_ACTION */
+
+#ifndef USAGE_ERROR_ACTION
+#define USAGE_ERROR_ACTION(m,p) ABORT
+#endif /* USAGE_ERROR_ACTION */
+
+#endif /* PROCEED_ON_ERROR */
+
+/* -------------------------- Debugging setup ---------------------------- */
+
+#if ! DEBUG
+
+#define check_free_chunk(M,P)
+#define check_inuse_chunk(M,P)
+#define check_malloced_chunk(M,P,N)
+#define check_mmapped_chunk(M,P)
+#define check_malloc_state(M)
+#define check_top_chunk(M,P)
+
+#else /* DEBUG */
+#define check_free_chunk(M,P) do_check_free_chunk(M,P)
+#define check_inuse_chunk(M,P) do_check_inuse_chunk(M,P)
+#define check_top_chunk(M,P) do_check_top_chunk(M,P)
+#define check_malloced_chunk(M,P,N) do_check_malloced_chunk(M,P,N)
+#define check_mmapped_chunk(M,P) do_check_mmapped_chunk(M,P)
+#define check_malloc_state(M) do_check_malloc_state(M)
+
+static void do_check_any_chunk(mstate m, mchunkptr p);
+static void do_check_top_chunk(mstate m, mchunkptr p);
+static void do_check_mmapped_chunk(mstate m, mchunkptr p);
+static void do_check_inuse_chunk(mstate m, mchunkptr p);
+static void do_check_free_chunk(mstate m, mchunkptr p);
+static void do_check_malloced_chunk(mstate m, void *mem, size_t s);
+static void do_check_tree(mstate m, tchunkptr t);
+static void do_check_treebin(mstate m, bindex_t i);
+static void do_check_smallbin(mstate m, bindex_t i);
+static void do_check_malloc_state(mstate m);
+static int bin_find(mstate m, mchunkptr x);
+static size_t traverse_and_check(mstate m);
+#endif /* DEBUG */
+
+/* ---------------------------- Indexing Bins ---------------------------- */
+
+#define is_small(s) (((s) >> SMALLBIN_SHIFT) < NSMALLBINS)
+#define small_index(s) ((s) >> SMALLBIN_SHIFT)
+#define small_index2size(i) ((i) << SMALLBIN_SHIFT)
+#define MIN_SMALL_INDEX (small_index(MIN_CHUNK_SIZE))
+
+/* addressing by index. See above about smallbin repositioning */
+#define smallbin_at(M, i) ((sbinptr)((char*)&((M)->smallbins[(i)<<1])))
+#define treebin_at(M,i) (&((M)->treebins[i]))
+
+/* assign tree index for size S to variable I */
+#if defined(__GNUC__) && defined(i386)
+#define compute_tree_index(S, I)\
+{\
+ size_t X = S >> TREEBIN_SHIFT;\
+ if (X == 0)\
+ I = 0;\
+ else if (X > 0xFFFF)\
+ I = NTREEBINS-1;\
+ else {\
+ unsigned int K;\
+ __asm__("bsrl %1,%0\n\t" : "=r" (K) : "rm" (X));\
+ I = (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\
+ }\
+}
+#else /* GNUC */
+#define compute_tree_index(S, I)\
+{\
+ size_t X = S >> TREEBIN_SHIFT;\
+ if (X == 0)\
+ I = 0;\
+ else if (X > 0xFFFF)\
+ I = NTREEBINS-1;\
+ else {\
+ unsigned int Y = (unsigned int)X;\
+ unsigned int N = ((Y - 0x100) >> 16) & 8;\
+ unsigned int K = (((Y <<= N) - 0x1000) >> 16) & 4;\
+ N += K;\
+ N += K = (((Y <<= K) - 0x4000) >> 16) & 2;\
+ K = 14 - N + ((Y <<= K) >> 15);\
+ I = (K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1));\
+ }\
+}
+#endif /* GNUC */
+
+/* Bit representing maximum resolved size in a treebin at i */
+#define bit_for_tree_index(i) \
+ (i == NTREEBINS-1)? (SIZE_T_BITSIZE-1) : (((i) >> 1) + TREEBIN_SHIFT - 2)
+
+/* Shift placing maximum resolved bit in a treebin at i as sign bit */
+#define leftshift_for_tree_index(i) \
+ ((i == NTREEBINS-1)? 0 : \
+ ((SIZE_T_BITSIZE-SIZE_T_ONE) - (((i) >> 1) + TREEBIN_SHIFT - 2)))
+
+/* The size of the smallest chunk held in bin with index i */
+#define minsize_for_tree_index(i) \
+ ((SIZE_T_ONE << (((i) >> 1) + TREEBIN_SHIFT)) | \
+ (((size_t)((i) & SIZE_T_ONE)) << (((i) >> 1) + TREEBIN_SHIFT - 1)))
+
+
+/* ------------------------ Operations on bin maps ----------------------- */
+
+/* bit corresponding to given index */
+#define idx2bit(i) ((binmap_t)(1) << (i))
+
+/* Mark/Clear bits with given index */
+#define mark_smallmap(M,i) ((M)->smallmap |= idx2bit(i))
+#define clear_smallmap(M,i) ((M)->smallmap &= ~idx2bit(i))
+#define smallmap_is_marked(M,i) ((M)->smallmap & idx2bit(i))
+
+#define mark_treemap(M,i) ((M)->treemap |= idx2bit(i))
+#define clear_treemap(M,i) ((M)->treemap &= ~idx2bit(i))
+#define treemap_is_marked(M,i) ((M)->treemap & idx2bit(i))
+
+/* index corresponding to given bit */
+
+#if defined(__GNUC__) && defined(i386)
+#define compute_bit2idx(X, I)\
+{\
+ unsigned int J;\
+ __asm__("bsfl %1,%0\n\t" : "=r" (J) : "rm" (X));\
+ I = (bindex_t)J;\
+}
+
+#else /* GNUC */
+#if USE_BUILTIN_FFS
+#define compute_bit2idx(X, I) I = ffs(X)-1
+
+#else /* USE_BUILTIN_FFS */
+#define compute_bit2idx(X, I)\
+{\
+ unsigned int Y = X - 1;\
+ unsigned int K = Y >> (16-4) & 16;\
+ unsigned int N = K; Y >>= K;\
+ N += K = Y >> (8-3) & 8; Y >>= K;\
+ N += K = Y >> (4-2) & 4; Y >>= K;\
+ N += K = Y >> (2-1) & 2; Y >>= K;\
+ N += K = Y >> (1-0) & 1; Y >>= K;\
+ I = (bindex_t)(N + Y);\
+}
+#endif /* USE_BUILTIN_FFS */
+#endif /* GNUC */
+
+/* isolate the least set bit of a bitmap */
+#define least_bit(x) ((x) & -(x))
+
+/* mask with all bits to left of least bit of x on */
+#define left_bits(x) ((x<<1) | -(x<<1))
+
+/* mask with all bits to left of or equal to least bit of x on */
+#define same_or_left_bits(x) ((x) | -(x))
+
+
+/* ----------------------- Runtime Check Support ------------------------- */
+
+/*
+ For security, the main invariant is that malloc/free/etc never
+ writes to a static address other than malloc_state, unless static
+ malloc_state itself has been corrupted, which cannot occur via
+ malloc (because of these checks). In essence this means that we
+ believe all pointers, sizes, maps etc held in malloc_state, but
+ check all of those linked or offsetted from other embedded data
+ structures. These checks are interspersed with main code in a way
+ that tends to minimize their run-time cost.
+
+ When FOOTERS is defined, in addition to range checking, we also
+ verify footer fields of inuse chunks, which can be used guarantee
+ that the mstate controlling malloc/free is intact. This is a
+ streamlined version of the approach described by William Robertson
+ et al in "Run-time Detection of Heap-based Overflows" LISA'03
+ http://www.usenix.org/events/lisa03/tech/robertson.html The footer
+ of an inuse chunk holds the xor of its mstate and a random seed,
+ that is checked upon calls to free() and realloc(). This is
+ (probablistically) unguessable from outside the program, but can be
+ computed by any code successfully malloc'ing any chunk, so does not
+ itself provide protection against code that has already broken
+ security through some other means. Unlike Robertson et al, we
+ always dynamically check addresses of all offset chunks (previous,
+ next, etc). This turns out to be cheaper than relying on hashes.
+*/
+
+#if !INSECURE
+/* Check if address a is at least as high as any from MORECORE or MMAP */
+#define ok_address(M, a) ((char*)(a) >= (M)->least_addr)
+/* Check if address of next chunk n is higher than base chunk p */
+#define ok_next(p, n) ((char*)(p) < (char*)(n))
+/* Check if p has its cinuse bit on */
+#define ok_cinuse(p) cinuse(p)
+/* Check if p has its pinuse bit on */
+#define ok_pinuse(p) pinuse(p)
+
+#else /* !INSECURE */
+#define ok_address(M, a) (1)
+#define ok_next(b, n) (1)
+#define ok_cinuse(p) (1)
+#define ok_pinuse(p) (1)
+#endif /* !INSECURE */
+
+#if (FOOTERS && !INSECURE)
+/* Check if (alleged) mstate m has expected magic field */
+#define ok_magic(M) ((M)->magic == mparams.magic)
+#else /* (FOOTERS && !INSECURE) */
+#define ok_magic(M) (1)
+#endif /* (FOOTERS && !INSECURE) */
+
+
+/* In gcc, use __builtin_expect to minimize impact of checks */
+#if !INSECURE
+#if defined(__GNUC__) && __GNUC__ >= 3
+#define RTCHECK(e) __builtin_expect(e, 1)
+#else /* GNUC */
+#define RTCHECK(e) (e)
+#endif /* GNUC */
+#else /* !INSECURE */
+#define RTCHECK(e) (1)
+#endif /* !INSECURE */
+
+/* macros to set up inuse chunks with or without footers */
+
+#if !FOOTERS
+
+#define mark_inuse_foot(M,p,s)
+
+/* Set cinuse bit and pinuse bit of next chunk */
+#define set_inuse(M,p,s)\
+ ((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\
+ ((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT)
+
+/* Set cinuse and pinuse of this chunk and pinuse of next chunk */
+#define set_inuse_and_pinuse(M,p,s)\
+ ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\
+ ((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT)
+
+/* Set size, cinuse and pinuse bit of this chunk */
+#define set_size_and_pinuse_of_inuse_chunk(M, p, s)\
+ ((p)->head = (s|PINUSE_BIT|CINUSE_BIT))
+
+#else /* FOOTERS */
+
+/* Set foot of inuse chunk to be xor of mstate and seed */
+#define mark_inuse_foot(M,p,s)\
+ (((mchunkptr)((char*)(p) + (s)))->prev_foot = ((size_t)(M) ^ mparams.magic))
+
+#define get_mstate_for(p)\
+ ((mstate)(((mchunkptr)((char*)(p) +\
+ (chunksize(p))))->prev_foot ^ mparams.magic))
+
+#define set_inuse(M,p,s)\
+ ((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\
+ (((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT), \
+ mark_inuse_foot(M,p,s))
+
+#define set_inuse_and_pinuse(M,p,s)\
+ ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\
+ (((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT),\
+ mark_inuse_foot(M,p,s))
+
+#define set_size_and_pinuse_of_inuse_chunk(M, p, s)\
+ ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\
+ mark_inuse_foot(M, p, s))
+
+#endif /* !FOOTERS */
+
+/* ---------------------------- setting mparams -------------------------- */
+
+/* Initialize mparams */
+static int
+init_mparams(void)
+{
+ if (mparams.page_size == 0) {
+ size_t s;
+
+ mparams.mmap_threshold = DEFAULT_MMAP_THRESHOLD;
+ mparams.trim_threshold = DEFAULT_TRIM_THRESHOLD;
+#if MORECORE_CONTIGUOUS
+ mparams.default_mflags = USE_LOCK_BIT | USE_MMAP_BIT;
+#else /* MORECORE_CONTIGUOUS */
+ mparams.default_mflags =
+ USE_LOCK_BIT | USE_MMAP_BIT | USE_NONCONTIGUOUS_BIT;
+#endif /* MORECORE_CONTIGUOUS */
+
+#if (FOOTERS && !INSECURE)
+ {
+#if USE_DEV_RANDOM
+ int fd;
+ unsigned char buf[sizeof(size_t)];
+ /* Try to use /dev/urandom, else fall back on using time */
+ if ((fd = open("/dev/urandom", O_RDONLY)) >= 0 &&
+ read(fd, buf, sizeof(buf)) == sizeof(buf)) {
+ s = *((size_t *) buf);
+ close(fd);
+ } else
+#endif /* USE_DEV_RANDOM */
+ s = (size_t) (time(0) ^ (size_t) 0x55555555U);
+
+ s |= (size_t) 8U; /* ensure nonzero */
+ s &= ~(size_t) 7U; /* improve chances of fault for bad values */
+
+ }
+#else /* (FOOTERS && !INSECURE) */
+ s = (size_t) 0x58585858U;
+#endif /* (FOOTERS && !INSECURE) */
+ ACQUIRE_MAGIC_INIT_LOCK();
+ if (mparams.magic == 0) {
+ mparams.magic = s;
+ /* Set up lock for main malloc area */
+ INITIAL_LOCK(&gm->mutex);
+ gm->mflags = mparams.default_mflags;
+ }
+ RELEASE_MAGIC_INIT_LOCK();
+
+#ifndef WIN32
+ mparams.page_size = malloc_getpagesize;
+ mparams.granularity = ((DEFAULT_GRANULARITY != 0) ?
+ DEFAULT_GRANULARITY : mparams.page_size);
+#else /* WIN32 */
+ {
+ SYSTEM_INFO system_info;
+ GetSystemInfo(&system_info);
+ mparams.page_size = system_info.dwPageSize;
+ mparams.granularity = system_info.dwAllocationGranularity;
+ }
+#endif /* WIN32 */
+
+ /* Sanity-check configuration:
+ size_t must be unsigned and as wide as pointer type.
+ ints must be at least 4 bytes.
+ alignment must be at least 8.
+ Alignment, min chunk size, and page size must all be powers of 2.
+ */
+ if ((sizeof(size_t) != sizeof(char *)) ||
+ (MAX_SIZE_T < MIN_CHUNK_SIZE) ||
+ (sizeof(int) < 4) ||
+ (MALLOC_ALIGNMENT < (size_t) 8U) ||
+ ((MALLOC_ALIGNMENT & (MALLOC_ALIGNMENT - SIZE_T_ONE)) != 0) ||
+ ((MCHUNK_SIZE & (MCHUNK_SIZE - SIZE_T_ONE)) != 0) ||
+ ((mparams.granularity & (mparams.granularity - SIZE_T_ONE)) != 0)
+ || ((mparams.page_size & (mparams.page_size - SIZE_T_ONE)) != 0))
+ ABORT;
+ }
+ return 0;
+}
+
+/* support for mallopt */
+static int
+change_mparam(int param_number, int value)
+{
+ size_t val = (size_t) value;
+ init_mparams();
+ switch (param_number) {
+ case M_TRIM_THRESHOLD:
+ mparams.trim_threshold = val;
+ return 1;
+ case M_GRANULARITY:
+ if (val >= mparams.page_size && ((val & (val - 1)) == 0)) {
+ mparams.granularity = val;
+ return 1;
+ } else
+ return 0;
+ case M_MMAP_THRESHOLD:
+ mparams.mmap_threshold = val;
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+#if DEBUG
+/* ------------------------- Debugging Support --------------------------- */
+
+/* Check properties of any chunk, whether free, inuse, mmapped etc */
+static void
+do_check_any_chunk(mstate m, mchunkptr p)
+{
+ assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD));
+ assert(ok_address(m, p));
+}
+
+/* Check properties of top chunk */
+static void
+do_check_top_chunk(mstate m, mchunkptr p)
+{
+ msegmentptr sp = segment_holding(m, (char *) p);
+ size_t sz = chunksize(p);
+ assert(sp != 0);
+ assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD));
+ assert(ok_address(m, p));
+ assert(sz == m->topsize);
+ assert(sz > 0);
+ assert(sz == ((sp->base + sp->size) - (char *) p) - TOP_FOOT_SIZE);
+ assert(pinuse(p));
+ assert(!next_pinuse(p));
+}
+
+/* Check properties of (inuse) mmapped chunks */
+static void
+do_check_mmapped_chunk(mstate m, mchunkptr p)
+{
+ size_t sz = chunksize(p);
+ size_t len = (sz + (p->prev_foot & ~IS_MMAPPED_BIT) + MMAP_FOOT_PAD);
+ assert(is_mmapped(p));
+ assert(use_mmap(m));
+ assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD));
+ assert(ok_address(m, p));
+ assert(!is_small(sz));
+ assert((len & (mparams.page_size - SIZE_T_ONE)) == 0);
+ assert(chunk_plus_offset(p, sz)->head == FENCEPOST_HEAD);
+ assert(chunk_plus_offset(p, sz + SIZE_T_SIZE)->head == 0);
+}
+
+/* Check properties of inuse chunks */
+static void
+do_check_inuse_chunk(mstate m, mchunkptr p)
+{
+ do_check_any_chunk(m, p);
+ assert(cinuse(p));
+ assert(next_pinuse(p));
+ /* If not pinuse and not mmapped, previous chunk has OK offset */
+ assert(is_mmapped(p) || pinuse(p) || next_chunk(prev_chunk(p)) == p);
+ if (is_mmapped(p))
+ do_check_mmapped_chunk(m, p);
+}
+
+/* Check properties of free chunks */
+static void
+do_check_free_chunk(mstate m, mchunkptr p)
+{
+ size_t sz = p->head & ~(PINUSE_BIT | CINUSE_BIT);
+ mchunkptr next = chunk_plus_offset(p, sz);
+ do_check_any_chunk(m, p);
+ assert(!cinuse(p));
+ assert(!next_pinuse(p));
+ assert(!is_mmapped(p));
+ if (p != m->dv && p != m->top) {
+ if (sz >= MIN_CHUNK_SIZE) {
+ assert((sz & CHUNK_ALIGN_MASK) == 0);
+ assert(is_aligned(chunk2mem(p)));
+ assert(next->prev_foot == sz);
+ assert(pinuse(p));
+ assert(next == m->top || cinuse(next));
+ assert(p->fd->bk == p);
+ assert(p->bk->fd == p);
+ } else /* markers are always of size SIZE_T_SIZE */
+ assert(sz == SIZE_T_SIZE);
+ }
+}
+
+/* Check properties of malloced chunks at the point they are malloced */
+static void
+do_check_malloced_chunk(mstate m, void *mem, size_t s)
+{
+ if (mem != 0) {
+ mchunkptr p = mem2chunk(mem);
+ size_t sz = p->head & ~(PINUSE_BIT | CINUSE_BIT);
+ do_check_inuse_chunk(m, p);
+ assert((sz & CHUNK_ALIGN_MASK) == 0);
+ assert(sz >= MIN_CHUNK_SIZE);
+ assert(sz >= s);
+ /* unless mmapped, size is less than MIN_CHUNK_SIZE more than request */
+ assert(is_mmapped(p) || sz < (s + MIN_CHUNK_SIZE));
+ }
+}
+
+/* Check a tree and its subtrees. */
+static void
+do_check_tree(mstate m, tchunkptr t)
+{
+ tchunkptr head = 0;
+ tchunkptr u = t;
+ bindex_t tindex = t->index;
+ size_t tsize = chunksize(t);
+ bindex_t idx;
+ compute_tree_index(tsize, idx);
+ assert(tindex == idx);
+ assert(tsize >= MIN_LARGE_SIZE);
+ assert(tsize >= minsize_for_tree_index(idx));
+ assert((idx == NTREEBINS - 1)
+ || (tsize < minsize_for_tree_index((idx + 1))));
+
+ do { /* traverse through chain of same-sized nodes */
+ do_check_any_chunk(m, ((mchunkptr) u));
+ assert(u->index == tindex);
+ assert(chunksize(u) == tsize);
+ assert(!cinuse(u));
+ assert(!next_pinuse(u));
+ assert(u->fd->bk == u);
+ assert(u->bk->fd == u);
+ if (u->parent == 0) {
+ assert(u->child[0] == 0);
+ assert(u->child[1] == 0);
+ } else {
+ assert(head == 0); /* only one node on chain has parent */
+ head = u;
+ assert(u->parent != u);
+ assert(u->parent->child[0] == u ||
+ u->parent->child[1] == u ||
+ *((tbinptr *) (u->parent)) == u);
+ if (u->child[0] != 0) {
+ assert(u->child[0]->parent == u);
+ assert(u->child[0] != u);
+ do_check_tree(m, u->child[0]);
+ }
+ if (u->child[1] != 0) {
+ assert(u->child[1]->parent == u);
+ assert(u->child[1] != u);
+ do_check_tree(m, u->child[1]);
+ }
+ if (u->child[0] != 0 && u->child[1] != 0) {
+ assert(chunksize(u->child[0]) < chunksize(u->child[1]));
+ }
+ }
+ u = u->fd;
+ } while (u != t);
+ assert(head != 0);
+}
+
+/* Check all the chunks in a treebin. */
+static void
+do_check_treebin(mstate m, bindex_t i)
+{
+ tbinptr *tb = treebin_at(m, i);
+ tchunkptr t = *tb;
+ int empty = (m->treemap & (1U << i)) == 0;
+ if (t == 0)
+ assert(empty);
+ if (!empty)
+ do_check_tree(m, t);
+}
+
+/* Check all the chunks in a smallbin. */
+static void
+do_check_smallbin(mstate m, bindex_t i)
+{
+ sbinptr b = smallbin_at(m, i);
+ mchunkptr p = b->bk;
+ unsigned int empty = (m->smallmap & (1U << i)) == 0;
+ if (p == b)
+ assert(empty);
+ if (!empty) {
+ for (; p != b; p = p->bk) {
+ size_t size = chunksize(p);
+ mchunkptr q;
+ /* each chunk claims to be free */
+ do_check_free_chunk(m, p);
+ /* chunk belongs in bin */
+ assert(small_index(size) == i);
+ assert(p->bk == b || chunksize(p->bk) == chunksize(p));
+ /* chunk is followed by an inuse chunk */
+ q = next_chunk(p);
+ if (q->head != FENCEPOST_HEAD)
+ do_check_inuse_chunk(m, q);
+ }
+ }
+}
+
+/* Find x in a bin. Used in other check functions. */
+static int
+bin_find(mstate m, mchunkptr x)
+{
+ size_t size = chunksize(x);
+ if (is_small(size)) {
+ bindex_t sidx = small_index(size);
+ sbinptr b = smallbin_at(m, sidx);
+ if (smallmap_is_marked(m, sidx)) {
+ mchunkptr p = b;
+ do {
+ if (p == x)
+ return 1;
+ } while ((p = p->fd) != b);
+ }
+ } else {
+ bindex_t tidx;
+ compute_tree_index(size, tidx);
+ if (treemap_is_marked(m, tidx)) {
+ tchunkptr t = *treebin_at(m, tidx);
+ size_t sizebits = size << leftshift_for_tree_index(tidx);
+ while (t != 0 && chunksize(t) != size) {
+ t = t->child[(sizebits >> (SIZE_T_BITSIZE - SIZE_T_ONE)) & 1];
+ sizebits <<= 1;
+ }
+ if (t != 0) {
+ tchunkptr u = t;
+ do {
+ if (u == (tchunkptr) x)
+ return 1;
+ } while ((u = u->fd) != t);
+ }
+ }
+ }
+ return 0;
+}
+
+/* Traverse each chunk and check it; return total */
+static size_t
+traverse_and_check(mstate m)
+{
+ size_t sum = 0;
+ if (is_initialized(m)) {
+ msegmentptr s = &m->seg;
+ sum += m->topsize + TOP_FOOT_SIZE;
+ while (s != 0) {
+ mchunkptr q = align_as_chunk(s->base);
+ mchunkptr lastq = 0;
+ assert(pinuse(q));
+ while (segment_holds(s, q) &&
+ q != m->top && q->head != FENCEPOST_HEAD) {
+ sum += chunksize(q);
+ if (cinuse(q)) {
+ assert(!bin_find(m, q));
+ do_check_inuse_chunk(m, q);
+ } else {
+ assert(q == m->dv || bin_find(m, q));
+ assert(lastq == 0 || cinuse(lastq)); /* Not 2 consecutive free */
+ do_check_free_chunk(m, q);
+ }
+ lastq = q;
+ q = next_chunk(q);
+ }
+ s = s->next;
+ }
+ }
+ return sum;
+}
+
+/* Check all properties of malloc_state. */
+static void
+do_check_malloc_state(mstate m)
+{
+ bindex_t i;
+ size_t total;
+ /* check bins */
+ for (i = 0; i < NSMALLBINS; ++i)
+ do_check_smallbin(m, i);
+ for (i = 0; i < NTREEBINS; ++i)
+ do_check_treebin(m, i);
+
+ if (m->dvsize != 0) { /* check dv chunk */
+ do_check_any_chunk(m, m->dv);
+ assert(m->dvsize == chunksize(m->dv));
+ assert(m->dvsize >= MIN_CHUNK_SIZE);
+ assert(bin_find(m, m->dv) == 0);
+ }
+
+ if (m->top != 0) { /* check top chunk */
+ do_check_top_chunk(m, m->top);
+ assert(m->topsize == chunksize(m->top));
+ assert(m->topsize > 0);
+ assert(bin_find(m, m->top) == 0);
+ }
+
+ total = traverse_and_check(m);
+ assert(total <= m->footprint);
+ assert(m->footprint <= m->max_footprint);
+}
+#endif /* DEBUG */
+
+/* ----------------------------- statistics ------------------------------ */
+
+#if !NO_MALLINFO
+static struct mallinfo
+internal_mallinfo(mstate m)
+{
+ struct mallinfo nm = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ if (!PREACTION(m)) {
+ check_malloc_state(m);
+ if (is_initialized(m)) {
+ size_t nfree = SIZE_T_ONE; /* top always free */
+ size_t mfree = m->topsize + TOP_FOOT_SIZE;
+ size_t sum = mfree;
+ msegmentptr s = &m->seg;
+ while (s != 0) {
+ mchunkptr q = align_as_chunk(s->base);
+ while (segment_holds(s, q) &&
+ q != m->top && q->head != FENCEPOST_HEAD) {
+ size_t sz = chunksize(q);
+ sum += sz;
+ if (!cinuse(q)) {
+ mfree += sz;
+ ++nfree;
+ }
+ q = next_chunk(q);
+ }
+ s = s->next;
+ }
+
+ nm.arena = sum;
+ nm.ordblks = nfree;
+ nm.hblkhd = m->footprint - sum;
+ nm.usmblks = m->max_footprint;
+ nm.uordblks = m->footprint - mfree;
+ nm.fordblks = mfree;
+ nm.keepcost = m->topsize;
+ }
+
+ POSTACTION(m);
+ }
+ return nm;
+}
+#endif /* !NO_MALLINFO */
+
+static void
+internal_malloc_stats(mstate m)
+{
+ if (!PREACTION(m)) {
+#ifndef LACKS_STDIO_H
+ size_t maxfp = 0;
+#endif
+ size_t fp = 0;
+ size_t used = 0;
+ check_malloc_state(m);
+ if (is_initialized(m)) {
+ msegmentptr s = &m->seg;
+#ifndef LACKS_STDIO_H
+ maxfp = m->max_footprint;
+#endif
+ fp = m->footprint;
+ used = fp - (m->topsize + TOP_FOOT_SIZE);
+
+ while (s != 0) {
+ mchunkptr q = align_as_chunk(s->base);
+ while (segment_holds(s, q) &&
+ q != m->top && q->head != FENCEPOST_HEAD) {
+ if (!cinuse(q))
+ used -= chunksize(q);
+ q = next_chunk(q);
+ }
+ s = s->next;
+ }
+ }
+#ifndef LACKS_STDIO_H
+ fprintf(stderr, "max system bytes = %10lu\n",
+ (unsigned long) (maxfp));
+ fprintf(stderr, "system bytes = %10lu\n", (unsigned long) (fp));
+ fprintf(stderr, "in use bytes = %10lu\n", (unsigned long) (used));
+#endif
+
+ POSTACTION(m);
+ }
+}
+
+/* ----------------------- Operations on smallbins ----------------------- */
+
+/*
+ Various forms of linking and unlinking are defined as macros. Even
+ the ones for trees, which are very long but have very short typical
+ paths. This is ugly but reduces reliance on inlining support of
+ compilers.
+*/
+
+/* Link a free chunk into a smallbin */
+#define insert_small_chunk(M, P, S) {\
+ bindex_t I = small_index(S);\
+ mchunkptr B = smallbin_at(M, I);\
+ mchunkptr F = B;\
+ assert(S >= MIN_CHUNK_SIZE);\
+ if (!smallmap_is_marked(M, I))\
+ mark_smallmap(M, I);\
+ else if (RTCHECK(ok_address(M, B->fd)))\
+ F = B->fd;\
+ else {\
+ CORRUPTION_ERROR_ACTION(M);\
+ }\
+ B->fd = P;\
+ F->bk = P;\
+ P->fd = F;\
+ P->bk = B;\
+}
+
+/* Unlink a chunk from a smallbin */
+#define unlink_small_chunk(M, P, S) {\
+ mchunkptr F = P->fd;\
+ mchunkptr B = P->bk;\
+ bindex_t I = small_index(S);\
+ assert(P != B);\
+ assert(P != F);\
+ assert(chunksize(P) == small_index2size(I));\
+ if (F == B)\
+ clear_smallmap(M, I);\
+ else if (RTCHECK((F == smallbin_at(M,I) || ok_address(M, F)) &&\
+ (B == smallbin_at(M,I) || ok_address(M, B)))) {\
+ F->bk = B;\
+ B->fd = F;\
+ }\
+ else {\
+ CORRUPTION_ERROR_ACTION(M);\
+ }\
+}
+
+/* Unlink the first chunk from a smallbin */
+#define unlink_first_small_chunk(M, B, P, I) {\
+ mchunkptr F = P->fd;\
+ assert(P != B);\
+ assert(P != F);\
+ assert(chunksize(P) == small_index2size(I));\
+ if (B == F)\
+ clear_smallmap(M, I);\
+ else if (RTCHECK(ok_address(M, F))) {\
+ B->fd = F;\
+ F->bk = B;\
+ }\
+ else {\
+ CORRUPTION_ERROR_ACTION(M);\
+ }\
+}
+
+/* Replace dv node, binning the old one */
+/* Used only when dvsize known to be small */
+#define replace_dv(M, P, S) {\
+ size_t DVS = M->dvsize;\
+ if (DVS != 0) {\
+ mchunkptr DV = M->dv;\
+ assert(is_small(DVS));\
+ insert_small_chunk(M, DV, DVS);\
+ }\
+ M->dvsize = S;\
+ M->dv = P;\
+}
+
+/* ------------------------- Operations on trees ------------------------- */
+
+/* Insert chunk into tree */
+#define insert_large_chunk(M, X, S) {\
+ tbinptr* H;\
+ bindex_t I;\
+ compute_tree_index(S, I);\
+ H = treebin_at(M, I);\
+ X->index = I;\
+ X->child[0] = X->child[1] = 0;\
+ if (!treemap_is_marked(M, I)) {\
+ mark_treemap(M, I);\
+ *H = X;\
+ X->parent = (tchunkptr)H;\
+ X->fd = X->bk = X;\
+ }\
+ else {\
+ tchunkptr T = *H;\
+ size_t K = S << leftshift_for_tree_index(I);\
+ for (;;) {\
+ if (chunksize(T) != S) {\
+ tchunkptr* C = &(T->child[(K >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]);\
+ K <<= 1;\
+ if (*C != 0)\
+ T = *C;\
+ else if (RTCHECK(ok_address(M, C))) {\
+ *C = X;\
+ X->parent = T;\
+ X->fd = X->bk = X;\
+ break;\
+ }\
+ else {\
+ CORRUPTION_ERROR_ACTION(M);\
+ break;\
+ }\
+ }\
+ else {\
+ tchunkptr F = T->fd;\
+ if (RTCHECK(ok_address(M, T) && ok_address(M, F))) {\
+ T->fd = F->bk = X;\
+ X->fd = F;\
+ X->bk = T;\
+ X->parent = 0;\
+ break;\
+ }\
+ else {\
+ CORRUPTION_ERROR_ACTION(M);\
+ break;\
+ }\
+ }\
+ }\
+ }\
+}
+
+/*
+ Unlink steps:
+
+ 1. If x is a chained node, unlink it from its same-sized fd/bk links
+ and choose its bk node as its replacement.
+ 2. If x was the last node of its size, but not a leaf node, it must
+ be replaced with a leaf node (not merely one with an open left or
+ right), to make sure that lefts and rights of descendents
+ correspond properly to bit masks. We use the rightmost descendent
+ of x. We could use any other leaf, but this is easy to locate and
+ tends to counteract removal of leftmosts elsewhere, and so keeps
+ paths shorter than minimally guaranteed. This doesn't loop much
+ because on average a node in a tree is near the bottom.
+ 3. If x is the base of a chain (i.e., has parent links) relink
+ x's parent and children to x's replacement (or null if none).
+*/
+
+#define unlink_large_chunk(M, X) {\
+ tchunkptr XP = X->parent;\
+ tchunkptr R;\
+ if (X->bk != X) {\
+ tchunkptr F = X->fd;\
+ R = X->bk;\
+ if (RTCHECK(ok_address(M, F))) {\
+ F->bk = R;\
+ R->fd = F;\
+ }\
+ else {\
+ CORRUPTION_ERROR_ACTION(M);\
+ }\
+ }\
+ else {\
+ tchunkptr* RP;\
+ if (((R = *(RP = &(X->child[1]))) != 0) ||\
+ ((R = *(RP = &(X->child[0]))) != 0)) {\
+ tchunkptr* CP;\
+ while ((*(CP = &(R->child[1])) != 0) ||\
+ (*(CP = &(R->child[0])) != 0)) {\
+ R = *(RP = CP);\
+ }\
+ if (RTCHECK(ok_address(M, RP)))\
+ *RP = 0;\
+ else {\
+ CORRUPTION_ERROR_ACTION(M);\
+ }\
+ }\
+ }\
+ if (XP != 0) {\
+ tbinptr* H = treebin_at(M, X->index);\
+ if (X == *H) {\
+ if ((*H = R) == 0) \
+ clear_treemap(M, X->index);\
+ }\
+ else if (RTCHECK(ok_address(M, XP))) {\
+ if (XP->child[0] == X) \
+ XP->child[0] = R;\
+ else \
+ XP->child[1] = R;\
+ }\
+ else\
+ CORRUPTION_ERROR_ACTION(M);\
+ if (R != 0) {\
+ if (RTCHECK(ok_address(M, R))) {\
+ tchunkptr C0, C1;\
+ R->parent = XP;\
+ if ((C0 = X->child[0]) != 0) {\
+ if (RTCHECK(ok_address(M, C0))) {\
+ R->child[0] = C0;\
+ C0->parent = R;\
+ }\
+ else\
+ CORRUPTION_ERROR_ACTION(M);\
+ }\
+ if ((C1 = X->child[1]) != 0) {\
+ if (RTCHECK(ok_address(M, C1))) {\
+ R->child[1] = C1;\
+ C1->parent = R;\
+ }\
+ else\
+ CORRUPTION_ERROR_ACTION(M);\
+ }\
+ }\
+ else\
+ CORRUPTION_ERROR_ACTION(M);\
+ }\
+ }\
+}
+
+/* Relays to large vs small bin operations */
+
+#define insert_chunk(M, P, S)\
+ if (is_small(S)) insert_small_chunk(M, P, S)\
+ else { tchunkptr TP = (tchunkptr)(P); insert_large_chunk(M, TP, S); }
+
+#define unlink_chunk(M, P, S)\
+ if (is_small(S)) unlink_small_chunk(M, P, S)\
+ else { tchunkptr TP = (tchunkptr)(P); unlink_large_chunk(M, TP); }
+
+
+/* Relays to internal calls to malloc/free from realloc, memalign etc */
+
+#if ONLY_MSPACES
+#define internal_malloc(m, b) mspace_malloc(m, b)
+#define internal_free(m, mem) mspace_free(m,mem);
+#else /* ONLY_MSPACES */
+#if MSPACES
+#define internal_malloc(m, b)\
+ (m == gm)? dlmalloc(b) : mspace_malloc(m, b)
+#define internal_free(m, mem)\
+ if (m == gm) dlfree(mem); else mspace_free(m,mem);
+#else /* MSPACES */
+#define internal_malloc(m, b) dlmalloc(b)
+#define internal_free(m, mem) dlfree(mem)
+#endif /* MSPACES */
+#endif /* ONLY_MSPACES */
+
+/* ----------------------- Direct-mmapping chunks ----------------------- */
+
+/*
+ Directly mmapped chunks are set up with an offset to the start of
+ the mmapped region stored in the prev_foot field of the chunk. This
+ allows reconstruction of the required argument to MUNMAP when freed,
+ and also allows adjustment of the returned chunk to meet alignment
+ requirements (especially in memalign). There is also enough space
+ allocated to hold a fake next chunk of size SIZE_T_SIZE to maintain
+ the PINUSE bit so frees can be checked.
+*/
+
+/* Malloc using mmap */
+static void *
+mmap_alloc(mstate m, size_t nb)
+{
+ size_t mmsize =
+ granularity_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
+ if (mmsize > nb) { /* Check for wrap around 0 */
+ char *mm = (char *) (DIRECT_MMAP(mmsize));
+ if (mm != CMFAIL) {
+ size_t offset = align_offset(chunk2mem(mm));
+ size_t psize = mmsize - offset - MMAP_FOOT_PAD;
+ mchunkptr p = (mchunkptr) (mm + offset);
+ p->prev_foot = offset | IS_MMAPPED_BIT;
+ (p)->head = (psize | CINUSE_BIT);
+ mark_inuse_foot(m, p, psize);
+ chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD;
+ chunk_plus_offset(p, psize + SIZE_T_SIZE)->head = 0;
+
+ if (mm < m->least_addr)
+ m->least_addr = mm;
+ if ((m->footprint += mmsize) > m->max_footprint)
+ m->max_footprint = m->footprint;
+ assert(is_aligned(chunk2mem(p)));
+ check_mmapped_chunk(m, p);
+ return chunk2mem(p);
+ }
+ }
+ return 0;
+}
+
+/* Realloc using mmap */
+static mchunkptr
+mmap_resize(mstate m, mchunkptr oldp, size_t nb)
+{
+ size_t oldsize = chunksize(oldp);
+ if (is_small(nb)) /* Can't shrink mmap regions below small size */
+ return 0;
+ /* Keep old chunk if big enough but not too big */
+ if (oldsize >= nb + SIZE_T_SIZE &&
+ (oldsize - nb) <= (mparams.granularity << 1))
+ return oldp;
+ else {
+ size_t offset = oldp->prev_foot & ~IS_MMAPPED_BIT;
+ size_t oldmmsize = oldsize + offset + MMAP_FOOT_PAD;
+ size_t newmmsize = granularity_align(nb + SIX_SIZE_T_SIZES +
+ CHUNK_ALIGN_MASK);
+ char *cp = (char *) CALL_MREMAP((char *) oldp - offset,
+ oldmmsize, newmmsize, 1);
+ if (cp != CMFAIL) {
+ mchunkptr newp = (mchunkptr) (cp + offset);
+ size_t psize = newmmsize - offset - MMAP_FOOT_PAD;
+ newp->head = (psize | CINUSE_BIT);
+ mark_inuse_foot(m, newp, psize);
+ chunk_plus_offset(newp, psize)->head = FENCEPOST_HEAD;
+ chunk_plus_offset(newp, psize + SIZE_T_SIZE)->head = 0;
+
+ if (cp < m->least_addr)
+ m->least_addr = cp;
+ if ((m->footprint += newmmsize - oldmmsize) > m->max_footprint)
+ m->max_footprint = m->footprint;
+ check_mmapped_chunk(m, newp);
+ return newp;
+ }
+ }
+ return 0;
+}
+
+/* -------------------------- mspace management -------------------------- */
+
+/* Initialize top chunk and its size */
+static void
+init_top(mstate m, mchunkptr p, size_t psize)
+{
+ /* Ensure alignment */
+ size_t offset = align_offset(chunk2mem(p));
+ p = (mchunkptr) ((char *) p + offset);
+ psize -= offset;
+
+ m->top = p;
+ m->topsize = psize;
+ p->head = psize | PINUSE_BIT;
+ /* set size of fake trailing chunk holding overhead space only once */
+ chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE;
+ m->trim_check = mparams.trim_threshold; /* reset on each update */
+}
+
+/* Initialize bins for a new mstate that is otherwise zeroed out */
+static void
+init_bins(mstate m)
+{
+ /* Establish circular links for smallbins */
+ bindex_t i;
+ for (i = 0; i < NSMALLBINS; ++i) {
+ sbinptr bin = smallbin_at(m, i);
+ bin->fd = bin->bk = bin;
+ }
+}
+
+#if PROCEED_ON_ERROR
+
+/* default corruption action */
+static void
+reset_on_error(mstate m)
+{
+ int i;
+ ++malloc_corruption_error_count;
+ /* Reinitialize fields to forget about all memory */
+ m->smallbins = m->treebins = 0;
+ m->dvsize = m->topsize = 0;
+ m->seg.base = 0;
+ m->seg.size = 0;
+ m->seg.next = 0;
+ m->top = m->dv = 0;
+ for (i = 0; i < NTREEBINS; ++i)
+ *treebin_at(m, i) = 0;
+ init_bins(m);
+}
+#endif /* PROCEED_ON_ERROR */
+
+/* Allocate chunk and prepend remainder with chunk in successor base. */
+static void *
+prepend_alloc(mstate m, char *newbase, char *oldbase, size_t nb)
+{
+ mchunkptr p = align_as_chunk(newbase);
+ mchunkptr oldfirst = align_as_chunk(oldbase);
+ size_t psize = (char *) oldfirst - (char *) p;
+ mchunkptr q = chunk_plus_offset(p, nb);
+ size_t qsize = psize - nb;
+ set_size_and_pinuse_of_inuse_chunk(m, p, nb);
+
+ assert((char *) oldfirst > (char *) q);
+ assert(pinuse(oldfirst));
+ assert(qsize >= MIN_CHUNK_SIZE);
+
+ /* consolidate remainder with first chunk of old base */
+ if (oldfirst == m->top) {
+ size_t tsize = m->topsize += qsize;
+ m->top = q;
+ q->head = tsize | PINUSE_BIT;
+ check_top_chunk(m, q);
+ } else if (oldfirst == m->dv) {
+ size_t dsize = m->dvsize += qsize;
+ m->dv = q;
+ set_size_and_pinuse_of_free_chunk(q, dsize);
+ } else {
+ if (!cinuse(oldfirst)) {
+ size_t nsize = chunksize(oldfirst);
+ unlink_chunk(m, oldfirst, nsize);
+ oldfirst = chunk_plus_offset(oldfirst, nsize);
+ qsize += nsize;
+ }
+ set_free_with_pinuse(q, qsize, oldfirst);
+ insert_chunk(m, q, qsize);
+ check_free_chunk(m, q);
+ }
+
+ check_malloced_chunk(m, chunk2mem(p), nb);
+ return chunk2mem(p);
+}
+
+
+/* Add a segment to hold a new noncontiguous region */
+static void
+add_segment(mstate m, char *tbase, size_t tsize, flag_t mmapped)
+{
+ /* Determine locations and sizes of segment, fenceposts, old top */
+ char *old_top = (char *) m->top;
+ msegmentptr oldsp = segment_holding(m, old_top);
+ char *old_end = oldsp->base + oldsp->size;
+ size_t ssize = pad_request(sizeof(struct malloc_segment));
+ char *rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
+ size_t offset = align_offset(chunk2mem(rawsp));
+ char *asp = rawsp + offset;
+ char *csp = (asp < (old_top + MIN_CHUNK_SIZE)) ? old_top : asp;
+ mchunkptr sp = (mchunkptr) csp;
+ msegmentptr ss = (msegmentptr) (chunk2mem(sp));
+ mchunkptr tnext = chunk_plus_offset(sp, ssize);
+ mchunkptr p = tnext;
+ int nfences = 0;
+
+ /* reset top to new space */
+ init_top(m, (mchunkptr) tbase, tsize - TOP_FOOT_SIZE);
+
+ /* Set up segment record */
+ assert(is_aligned(ss));
+ set_size_and_pinuse_of_inuse_chunk(m, sp, ssize);
+ *ss = m->seg; /* Push current record */
+ m->seg.base = tbase;
+ m->seg.size = tsize;
+ m->seg.sflags = mmapped;
+ m->seg.next = ss;
+
+ /* Insert trailing fenceposts */
+ for (;;) {
+ mchunkptr nextp = chunk_plus_offset(p, SIZE_T_SIZE);
+ p->head = FENCEPOST_HEAD;
+ ++nfences;
+ if ((char *) (&(nextp->head)) < old_end)
+ p = nextp;
+ else
+ break;
+ }
+ assert(nfences >= 2);
+
+ /* Insert the rest of old top into a bin as an ordinary free chunk */
+ if (csp != old_top) {
+ mchunkptr q = (mchunkptr) old_top;
+ size_t psize = csp - old_top;
+ mchunkptr tn = chunk_plus_offset(q, psize);
+ set_free_with_pinuse(q, psize, tn);
+ insert_chunk(m, q, psize);
+ }
+
+ check_top_chunk(m, m->top);
+}
+
+/* -------------------------- System allocation -------------------------- */
+
+/* Get memory from system using MORECORE or MMAP */
+static void *
+sys_alloc(mstate m, size_t nb)
+{
+ char *tbase = CMFAIL;
+ size_t tsize = 0;
+ flag_t mmap_flag = 0;
+
+ init_mparams();
+
+ /* Directly map large chunks */
+ if (use_mmap(m) && nb >= mparams.mmap_threshold) {
+ void *mem = mmap_alloc(m, nb);
+ if (mem != 0)
+ return mem;
+ }
+
+ /*
+ Try getting memory in any of three ways (in most-preferred to
+ least-preferred order):
+ 1. A call to MORECORE that can normally contiguously extend memory.
+ (disabled if not MORECORE_CONTIGUOUS or not HAVE_MORECORE or
+ or main space is mmapped or a previous contiguous call failed)
+ 2. A call to MMAP new space (disabled if not HAVE_MMAP).
+ Note that under the default settings, if MORECORE is unable to
+ fulfill a request, and HAVE_MMAP is true, then mmap is
+ used as a noncontiguous system allocator. This is a useful backup
+ strategy for systems with holes in address spaces -- in this case
+ sbrk cannot contiguously expand the heap, but mmap may be able to
+ find space.
+ 3. A call to MORECORE that cannot usually contiguously extend memory.
+ (disabled if not HAVE_MORECORE)
+ */
+
+ if (MORECORE_CONTIGUOUS && !use_noncontiguous(m)) {
+ char *br = CMFAIL;
+ msegmentptr ss =
+ (m->top == 0) ? 0 : segment_holding(m, (char *) m->top);
+ size_t asize = 0;
+ ACQUIRE_MORECORE_LOCK();
+
+ if (ss == 0) { /* First time through or recovery */
+ char *base = (char *) CALL_MORECORE(0);
+ if (base != CMFAIL) {
+ asize =
+ granularity_align(nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT +
+ SIZE_T_ONE);
+ /* Adjust to end on a page boundary */
+ if (!is_page_aligned(base))
+ asize += (page_align((size_t) base) - (size_t) base);
+ /* Can't call MORECORE if size is negative when treated as signed */
+ if (asize < HALF_MAX_SIZE_T &&
+ (br = (char *) (CALL_MORECORE(asize))) == base) {
+ tbase = base;
+ tsize = asize;
+ }
+ }
+ } else {
+ /* Subtract out existing available top space from MORECORE request. */
+ asize =
+ granularity_align(nb - m->topsize + TOP_FOOT_SIZE +
+ MALLOC_ALIGNMENT + SIZE_T_ONE);
+ /* Use mem here only if it did continuously extend old space */
+ if (asize < HALF_MAX_SIZE_T &&
+ (br =
+ (char *) (CALL_MORECORE(asize))) == ss->base + ss->size) {
+ tbase = br;
+ tsize = asize;
+ }
+ }
+
+ if (tbase == CMFAIL) { /* Cope with partial failure */
+ if (br != CMFAIL) { /* Try to use/extend the space we did get */
+ if (asize < HALF_MAX_SIZE_T &&
+ asize < nb + TOP_FOOT_SIZE + SIZE_T_ONE) {
+ size_t esize =
+ granularity_align(nb + TOP_FOOT_SIZE +
+ MALLOC_ALIGNMENT + SIZE_T_ONE -
+ asize);
+ if (esize < HALF_MAX_SIZE_T) {
+ char *end = (char *) CALL_MORECORE(esize);
+ if (end != CMFAIL)
+ asize += esize;
+ else { /* Can't use; try to release */
+ end = (char *) CALL_MORECORE(-asize);
+ br = CMFAIL;
+ }
+ }
+ }
+ }
+ if (br != CMFAIL) { /* Use the space we did get */
+ tbase = br;
+ tsize = asize;
+ } else
+ disable_contiguous(m); /* Don't try contiguous path in the future */
+ }
+
+ RELEASE_MORECORE_LOCK();
+ }
+
+ if (HAVE_MMAP && tbase == CMFAIL) { /* Try MMAP */
+ size_t req = nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT + SIZE_T_ONE;
+ size_t rsize = granularity_align(req);
+ if (rsize > nb) { /* Fail if wraps around zero */
+ char *mp = (char *) (CALL_MMAP(rsize));
+ if (mp != CMFAIL) {
+ tbase = mp;
+ tsize = rsize;
+ mmap_flag = IS_MMAPPED_BIT;
+ }
+ }
+ }
+
+ if (HAVE_MORECORE && tbase == CMFAIL) { /* Try noncontiguous MORECORE */
+ size_t asize =
+ granularity_align(nb + TOP_FOOT_SIZE + MALLOC_ALIGNMENT +
+ SIZE_T_ONE);
+ if (asize < HALF_MAX_SIZE_T) {
+ char *br = CMFAIL;
+ char *end = CMFAIL;
+ ACQUIRE_MORECORE_LOCK();
+ br = (char *) (CALL_MORECORE(asize));
+ end = (char *) (CALL_MORECORE(0));
+ RELEASE_MORECORE_LOCK();
+ if (br != CMFAIL && end != CMFAIL && br < end) {
+ size_t ssize = end - br;
+ if (ssize > nb + TOP_FOOT_SIZE) {
+ tbase = br;
+ tsize = ssize;
+ }
+ }
+ }
+ }
+
+ if (tbase != CMFAIL) {
+
+ if ((m->footprint += tsize) > m->max_footprint)
+ m->max_footprint = m->footprint;
+
+ if (!is_initialized(m)) { /* first-time initialization */
+ m->seg.base = m->least_addr = tbase;
+ m->seg.size = tsize;
+ m->seg.sflags = mmap_flag;
+ m->magic = mparams.magic;
+ init_bins(m);
+ if (is_global(m))
+ init_top(m, (mchunkptr) tbase, tsize - TOP_FOOT_SIZE);
+ else {
+ /* Offset top by embedded malloc_state */
+ mchunkptr mn = next_chunk(mem2chunk(m));
+ init_top(m, mn,
+ (size_t) ((tbase + tsize) - (char *) mn) -
+ TOP_FOOT_SIZE);
+ }
+ }
+
+ else {
+ /* Try to merge with an existing segment */
+ msegmentptr sp = &m->seg;
+ while (sp != 0 && tbase != sp->base + sp->size)
+ sp = sp->next;
+ if (sp != 0 && !is_extern_segment(sp) && (sp->sflags & IS_MMAPPED_BIT) == mmap_flag && segment_holds(sp, m->top)) { /* append */
+ sp->size += tsize;
+ init_top(m, m->top, m->topsize + tsize);
+ } else {
+ if (tbase < m->least_addr)
+ m->least_addr = tbase;
+ sp = &m->seg;
+ while (sp != 0 && sp->base != tbase + tsize)
+ sp = sp->next;
+ if (sp != 0 &&
+ !is_extern_segment(sp) &&
+ (sp->sflags & IS_MMAPPED_BIT) == mmap_flag) {
+ char *oldbase = sp->base;
+ sp->base = tbase;
+ sp->size += tsize;
+ return prepend_alloc(m, tbase, oldbase, nb);
+ } else
+ add_segment(m, tbase, tsize, mmap_flag);
+ }
+ }
+
+ if (nb < m->topsize) { /* Allocate from new or extended top space */
+ size_t rsize = m->topsize -= nb;
+ mchunkptr p = m->top;
+ mchunkptr r = m->top = chunk_plus_offset(p, nb);
+ r->head = rsize | PINUSE_BIT;
+ set_size_and_pinuse_of_inuse_chunk(m, p, nb);
+ check_top_chunk(m, m->top);
+ check_malloced_chunk(m, chunk2mem(p), nb);
+ return chunk2mem(p);
+ }
+ }
+
+ MALLOC_FAILURE_ACTION;
+ return 0;
+}
+
+/* ----------------------- system deallocation -------------------------- */
+
+/* Unmap and unlink any mmapped segments that don't contain used chunks */
+static size_t
+release_unused_segments(mstate m)
+{
+ size_t released = 0;
+ msegmentptr pred = &m->seg;
+ msegmentptr sp = pred->next;
+ while (sp != 0) {
+ char *base = sp->base;
+ size_t size = sp->size;
+ msegmentptr next = sp->next;
+ if (is_mmapped_segment(sp) && !is_extern_segment(sp)) {
+ mchunkptr p = align_as_chunk(base);
+ size_t psize = chunksize(p);
+ /* Can unmap if first chunk holds entire segment and not pinned */
+ if (!cinuse(p)
+ && (char *) p + psize >= base + size - TOP_FOOT_SIZE) {
+ tchunkptr tp = (tchunkptr) p;
+ assert(segment_holds(sp, (char *) sp));
+ if (p == m->dv) {
+ m->dv = 0;
+ m->dvsize = 0;
+ } else {
+ unlink_large_chunk(m, tp);
+ }
+ if (CALL_MUNMAP(base, size) == 0) {
+ released += size;
+ m->footprint -= size;
+ /* unlink obsoleted record */
+ sp = pred;
+ sp->next = next;
+ } else { /* back out if cannot unmap */
+ insert_large_chunk(m, tp, psize);
+ }
+ }
+ }
+ pred = sp;
+ sp = next;
+ }
+ return released;
+}
+
+static int
+sys_trim(mstate m, size_t pad)
+{
+ size_t released = 0;
+ if (pad < MAX_REQUEST && is_initialized(m)) {
+ pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead */
+
+ if (m->topsize > pad) {
+ /* Shrink top space in granularity-size units, keeping at least one */
+ size_t unit = mparams.granularity;
+ size_t extra = ((m->topsize - pad + (unit - SIZE_T_ONE)) / unit -
+ SIZE_T_ONE) * unit;
+ msegmentptr sp = segment_holding(m, (char *) m->top);
+
+ if (!is_extern_segment(sp)) {
+ if (is_mmapped_segment(sp)) {
+ if (HAVE_MMAP && sp->size >= extra && !has_segment_link(m, sp)) { /* can't shrink if pinned */
+ size_t newsize = sp->size - extra;
+ /* Prefer mremap, fall back to munmap */
+ if ((CALL_MREMAP(sp->base, sp->size, newsize, 0) !=
+ MFAIL)
+ || (CALL_MUNMAP(sp->base + newsize, extra) == 0)) {
+ released = extra;
+ }
+ }
+ } else if (HAVE_MORECORE) {
+ if (extra >= HALF_MAX_SIZE_T) /* Avoid wrapping negative */
+ extra = (HALF_MAX_SIZE_T) + SIZE_T_ONE - unit;
+ ACQUIRE_MORECORE_LOCK();
+ {
+ /* Make sure end of memory is where we last set it. */
+ char *old_br = (char *) (CALL_MORECORE(0));
+ if (old_br == sp->base + sp->size) {
+ char *rel_br = (char *) (CALL_MORECORE(-extra));
+ char *new_br = (char *) (CALL_MORECORE(0));
+ if (rel_br != CMFAIL && new_br < old_br)
+ released = old_br - new_br;
+ }
+ }
+ RELEASE_MORECORE_LOCK();
+ }
+ }
+
+ if (released != 0) {
+ sp->size -= released;
+ m->footprint -= released;
+ init_top(m, m->top, m->topsize - released);
+ check_top_chunk(m, m->top);
+ }
+ }
+
+ /* Unmap any unused mmapped segments */
+ if (HAVE_MMAP)
+ released += release_unused_segments(m);
+
+ /* On failure, disable autotrim to avoid repeated failed future calls */
+ if (released == 0)
+ m->trim_check = MAX_SIZE_T;
+ }
+
+ return (released != 0) ? 1 : 0;
+}
+
+/* ---------------------------- malloc support --------------------------- */
+
+/* allocate a large request from the best fitting chunk in a treebin */
+static void *
+tmalloc_large(mstate m, size_t nb)
+{
+ tchunkptr v = 0;
+ size_t rsize = -nb; /* Unsigned negation */
+ tchunkptr t;
+ bindex_t idx;
+ compute_tree_index(nb, idx);
+
+ if ((t = *treebin_at(m, idx)) != 0) {
+ /* Traverse tree for this bin looking for node with size == nb */
+ size_t sizebits = nb << leftshift_for_tree_index(idx);
+ tchunkptr rst = 0; /* The deepest untaken right subtree */
+ for (;;) {
+ tchunkptr rt;
+ size_t trem = chunksize(t) - nb;
+ if (trem < rsize) {
+ v = t;
+ if ((rsize = trem) == 0)
+ break;
+ }
+ rt = t->child[1];
+ t = t->child[(sizebits >> (SIZE_T_BITSIZE - SIZE_T_ONE)) & 1];
+ if (rt != 0 && rt != t)
+ rst = rt;
+ if (t == 0) {
+ t = rst; /* set t to least subtree holding sizes > nb */
+ break;
+ }
+ sizebits <<= 1;
+ }
+ }
+
+ if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */
+ binmap_t leftbits = left_bits(idx2bit(idx)) & m->treemap;
+ if (leftbits != 0) {
+ bindex_t i;
+ binmap_t leastbit = least_bit(leftbits);
+ compute_bit2idx(leastbit, i);
+ t = *treebin_at(m, i);
+ }
+ }
+
+ while (t != 0) { /* find smallest of tree or subtree */
+ size_t trem = chunksize(t) - nb;
+ if (trem < rsize) {
+ rsize = trem;
+ v = t;
+ }
+ t = leftmost_child(t);
+ }
+
+ /* If dv is a better fit, return 0 so malloc will use it */
+ if (v != 0 && rsize < (size_t) (m->dvsize - nb)) {
+ if (RTCHECK(ok_address(m, v))) { /* split */
+ mchunkptr r = chunk_plus_offset(v, nb);
+ assert(chunksize(v) == rsize + nb);
+ if (RTCHECK(ok_next(v, r))) {
+ unlink_large_chunk(m, v);
+ if (rsize < MIN_CHUNK_SIZE)
+ set_inuse_and_pinuse(m, v, (rsize + nb));
+ else {
+ set_size_and_pinuse_of_inuse_chunk(m, v, nb);
+ set_size_and_pinuse_of_free_chunk(r, rsize);
+ insert_chunk(m, r, rsize);
+ }
+ return chunk2mem(v);
+ }
+ }
+ CORRUPTION_ERROR_ACTION(m);
+ }
+ return 0;
+}
+
+/* allocate a small request from the best fitting chunk in a treebin */
+static void *
+tmalloc_small(mstate m, size_t nb)
+{
+ tchunkptr t, v;
+ size_t rsize;
+ bindex_t i;
+ binmap_t leastbit = least_bit(m->treemap);
+ compute_bit2idx(leastbit, i);
+
+ v = t = *treebin_at(m, i);
+ rsize = chunksize(t) - nb;
+
+ while ((t = leftmost_child(t)) != 0) {
+ size_t trem = chunksize(t) - nb;
+ if (trem < rsize) {
+ rsize = trem;
+ v = t;
+ }
+ }
+
+ if (RTCHECK(ok_address(m, v))) {
+ mchunkptr r = chunk_plus_offset(v, nb);
+ assert(chunksize(v) == rsize + nb);
+ if (RTCHECK(ok_next(v, r))) {
+ unlink_large_chunk(m, v);
+ if (rsize < MIN_CHUNK_SIZE)
+ set_inuse_and_pinuse(m, v, (rsize + nb));
+ else {
+ set_size_and_pinuse_of_inuse_chunk(m, v, nb);
+ set_size_and_pinuse_of_free_chunk(r, rsize);
+ replace_dv(m, r, rsize);
+ }
+ return chunk2mem(v);
+ }
+ }
+
+ CORRUPTION_ERROR_ACTION(m);
+ return 0;
+}
+
+/* --------------------------- realloc support --------------------------- */
+
+static void *
+internal_realloc(mstate m, void *oldmem, size_t bytes)
+{
+ if (bytes >= MAX_REQUEST) {
+ MALLOC_FAILURE_ACTION;
+ return 0;
+ }
+ if (!PREACTION(m)) {
+ mchunkptr oldp = mem2chunk(oldmem);
+ size_t oldsize = chunksize(oldp);
+ mchunkptr next = chunk_plus_offset(oldp, oldsize);
+ mchunkptr newp = 0;
+ void *extra = 0;
+
+ /* Try to either shrink or extend into top. Else malloc-copy-free */
+
+ if (RTCHECK(ok_address(m, oldp) && ok_cinuse(oldp) &&
+ ok_next(oldp, next) && ok_pinuse(next))) {
+ size_t nb = request2size(bytes);
+ if (is_mmapped(oldp))
+ newp = mmap_resize(m, oldp, nb);
+ else if (oldsize >= nb) { /* already big enough */
+ size_t rsize = oldsize - nb;
+ newp = oldp;
+ if (rsize >= MIN_CHUNK_SIZE) {
+ mchunkptr remainder = chunk_plus_offset(newp, nb);
+ set_inuse(m, newp, nb);
+ set_inuse(m, remainder, rsize);
+ extra = chunk2mem(remainder);
+ }
+ } else if (next == m->top && oldsize + m->topsize > nb) {
+ /* Expand into top */
+ size_t newsize = oldsize + m->topsize;
+ size_t newtopsize = newsize - nb;
+ mchunkptr newtop = chunk_plus_offset(oldp, nb);
+ set_inuse(m, oldp, nb);
+ newtop->head = newtopsize | PINUSE_BIT;
+ m->top = newtop;
+ m->topsize = newtopsize;
+ newp = oldp;
+ }
+ } else {
+ USAGE_ERROR_ACTION(m, oldmem);
+ POSTACTION(m);
+ return 0;
+ }
+
+ POSTACTION(m);
+
+ if (newp != 0) {
+ if (extra != 0) {
+ internal_free(m, extra);
+ }
+ check_inuse_chunk(m, newp);
+ return chunk2mem(newp);
+ } else {
+ void *newmem = internal_malloc(m, bytes);
+ if (newmem != 0) {
+ size_t oc = oldsize - overhead_for(oldp);
+ memcpy(newmem, oldmem, (oc < bytes) ? oc : bytes);
+ internal_free(m, oldmem);
+ }
+ return newmem;
+ }
+ }
+ return 0;
+}
+
+/* --------------------------- memalign support -------------------------- */
+
+static void *
+internal_memalign(mstate m, size_t alignment, size_t bytes)
+{
+ if (alignment <= MALLOC_ALIGNMENT) /* Can just use malloc */
+ return internal_malloc(m, bytes);
+ if (alignment < MIN_CHUNK_SIZE) /* must be at least a minimum chunk size */
+ alignment = MIN_CHUNK_SIZE;
+ if ((alignment & (alignment - SIZE_T_ONE)) != 0) { /* Ensure a power of 2 */
+ size_t a = MALLOC_ALIGNMENT << 1;
+ while (a < alignment)
+ a <<= 1;
+ alignment = a;
+ }
+
+ if (bytes >= MAX_REQUEST - alignment) {
+ if (m != 0) { /* Test isn't needed but avoids compiler warning */
+ MALLOC_FAILURE_ACTION;
+ }
+ } else {
+ size_t nb = request2size(bytes);
+ size_t req = nb + alignment + MIN_CHUNK_SIZE - CHUNK_OVERHEAD;
+ char *mem = (char *) internal_malloc(m, req);
+ if (mem != 0) {
+ void *leader = 0;
+ void *trailer = 0;
+ mchunkptr p = mem2chunk(mem);
+
+ if (PREACTION(m))
+ return 0;
+ if ((((size_t) (mem)) % alignment) != 0) { /* misaligned */
+ /*
+ Find an aligned spot inside chunk. Since we need to give
+ back leading space in a chunk of at least MIN_CHUNK_SIZE, if
+ the first calculation places us at a spot with less than
+ MIN_CHUNK_SIZE leader, we can move to the next aligned spot.
+ We've allocated enough total room so that this is always
+ possible.
+ */
+ char *br = (char *) mem2chunk((size_t) (((size_t) (mem +
+ alignment -
+ SIZE_T_ONE))
+ & -alignment));
+ char *pos =
+ ((size_t) (br - (char *) (p)) >=
+ MIN_CHUNK_SIZE) ? br : br + alignment;
+ mchunkptr newp = (mchunkptr) pos;
+ size_t leadsize = pos - (char *) (p);
+ size_t newsize = chunksize(p) - leadsize;
+
+ if (is_mmapped(p)) { /* For mmapped chunks, just adjust offset */
+ newp->prev_foot = p->prev_foot + leadsize;
+ newp->head = (newsize | CINUSE_BIT);
+ } else { /* Otherwise, give back leader, use the rest */
+ set_inuse(m, newp, newsize);
+ set_inuse(m, p, leadsize);
+ leader = chunk2mem(p);
+ }
+ p = newp;
+ }
+
+ /* Give back spare room at the end */
+ if (!is_mmapped(p)) {
+ size_t size = chunksize(p);
+ if (size > nb + MIN_CHUNK_SIZE) {
+ size_t remainder_size = size - nb;
+ mchunkptr remainder = chunk_plus_offset(p, nb);
+ set_inuse(m, p, nb);
+ set_inuse(m, remainder, remainder_size);
+ trailer = chunk2mem(remainder);
+ }
+ }
+
+ assert(chunksize(p) >= nb);
+ assert((((size_t) (chunk2mem(p))) % alignment) == 0);
+ check_inuse_chunk(m, p);
+ POSTACTION(m);
+ if (leader != 0) {
+ internal_free(m, leader);
+ }
+ if (trailer != 0) {
+ internal_free(m, trailer);
+ }
+ return chunk2mem(p);
+ }
+ }
+ return 0;
+}
+
+/* ------------------------ comalloc/coalloc support --------------------- */
+
+static void **
+ialloc(mstate m, size_t n_elements, size_t * sizes, int opts, void *chunks[])
+{
+ /*
+ This provides common support for independent_X routines, handling
+ all of the combinations that can result.
+
+ The opts arg has:
+ bit 0 set if all elements are same size (using sizes[0])
+ bit 1 set if elements should be zeroed
+ */
+
+ size_t element_size; /* chunksize of each element, if all same */
+ size_t contents_size; /* total size of elements */
+ size_t array_size; /* request size of pointer array */
+ void *mem; /* malloced aggregate space */
+ mchunkptr p; /* corresponding chunk */
+ size_t remainder_size; /* remaining bytes while splitting */
+ void **marray; /* either "chunks" or malloced ptr array */
+ mchunkptr array_chunk; /* chunk for malloced ptr array */
+ flag_t was_enabled; /* to disable mmap */
+ size_t size;
+ size_t i;
+
+ /* compute array length, if needed */
+ if (chunks != 0) {
+ if (n_elements == 0)
+ return chunks; /* nothing to do */
+ marray = chunks;
+ array_size = 0;
+ } else {
+ /* if empty req, must still return chunk representing empty array */
+ if (n_elements == 0)
+ return (void **) internal_malloc(m, 0);
+ marray = 0;
+ array_size = request2size(n_elements * (sizeof(void *)));
+ }
+
+ /* compute total element size */
+ if (opts & 0x1) { /* all-same-size */
+ element_size = request2size(*sizes);
+ contents_size = n_elements * element_size;
+ } else { /* add up all the sizes */
+ element_size = 0;
+ contents_size = 0;
+ for (i = 0; i != n_elements; ++i)
+ contents_size += request2size(sizes[i]);
+ }
+
+ size = contents_size + array_size;
+
+ /*
+ Allocate the aggregate chunk. First disable direct-mmapping so
+ malloc won't use it, since we would not be able to later
+ free/realloc space internal to a segregated mmap region.
+ */
+ was_enabled = use_mmap(m);
+ disable_mmap(m);
+ mem = internal_malloc(m, size - CHUNK_OVERHEAD);
+ if (was_enabled)
+ enable_mmap(m);
+ if (mem == 0)
+ return 0;
+
+ if (PREACTION(m))
+ return 0;
+ p = mem2chunk(mem);
+ remainder_size = chunksize(p);
+
+ assert(!is_mmapped(p));
+
+ if (opts & 0x2) { /* optionally clear the elements */
+ memset((size_t *) mem, 0, remainder_size - SIZE_T_SIZE - array_size);
+ }
+
+ /* If not provided, allocate the pointer array as final part of chunk */
+ if (marray == 0) {
+ size_t array_chunk_size;
+ array_chunk = chunk_plus_offset(p, contents_size);
+ array_chunk_size = remainder_size - contents_size;
+ marray = (void **) (chunk2mem(array_chunk));
+ set_size_and_pinuse_of_inuse_chunk(m, array_chunk, array_chunk_size);
+ remainder_size = contents_size;
+ }
+
+ /* split out elements */
+ for (i = 0;; ++i) {
+ marray[i] = chunk2mem(p);
+ if (i != n_elements - 1) {
+ if (element_size != 0)
+ size = element_size;
+ else
+ size = request2size(sizes[i]);
+ remainder_size -= size;
+ set_size_and_pinuse_of_inuse_chunk(m, p, size);
+ p = chunk_plus_offset(p, size);
+ } else { /* the final element absorbs any overallocation slop */
+ set_size_and_pinuse_of_inuse_chunk(m, p, remainder_size);
+ break;
+ }
+ }
+
+#if DEBUG
+ if (marray != chunks) {
+ /* final element must have exactly exhausted chunk */
+ if (element_size != 0) {
+ assert(remainder_size == element_size);
+ } else {
+ assert(remainder_size == request2size(sizes[i]));
+ }
+ check_inuse_chunk(m, mem2chunk(marray));
+ }
+ for (i = 0; i != n_elements; ++i)
+ check_inuse_chunk(m, mem2chunk(marray[i]));
+
+#endif /* DEBUG */
+
+ POSTACTION(m);
+ return marray;
+}
+
+
+/* -------------------------- public routines ---------------------------- */
+
+#if !ONLY_MSPACES
+
+void *
+dlmalloc(size_t bytes)
+{
+ /*
+ Basic algorithm:
+ If a small request (< 256 bytes minus per-chunk overhead):
+ 1. If one exists, use a remainderless chunk in associated smallbin.
+ (Remainderless means that there are too few excess bytes to
+ represent as a chunk.)
+ 2. If it is big enough, use the dv chunk, which is normally the
+ chunk adjacent to the one used for the most recent small request.
+ 3. If one exists, split the smallest available chunk in a bin,
+ saving remainder in dv.
+ 4. If it is big enough, use the top chunk.
+ 5. If available, get memory from system and use it
+ Otherwise, for a large request:
+ 1. Find the smallest available binned chunk that fits, and use it
+ if it is better fitting than dv chunk, splitting if necessary.
+ 2. If better fitting than any binned chunk, use the dv chunk.
+ 3. If it is big enough, use the top chunk.
+ 4. If request size >= mmap threshold, try to directly mmap this chunk.
+ 5. If available, get memory from system and use it
+
+ The ugly goto's here ensure that postaction occurs along all paths.
+ */
+
+ if (!PREACTION(gm)) {
+ void *mem;
+ size_t nb;
+ if (bytes <= MAX_SMALL_REQUEST) {
+ bindex_t idx;
+ binmap_t smallbits;
+ nb = (bytes < MIN_REQUEST) ? MIN_CHUNK_SIZE : pad_request(bytes);
+ idx = small_index(nb);
+ smallbits = gm->smallmap >> idx;
+
+ if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */
+ mchunkptr b, p;
+ idx += ~smallbits & 1; /* Uses next bin if idx empty */
+ b = smallbin_at(gm, idx);
+ p = b->fd;
+ assert(chunksize(p) == small_index2size(idx));
+ unlink_first_small_chunk(gm, b, p, idx);
+ set_inuse_and_pinuse(gm, p, small_index2size(idx));
+ mem = chunk2mem(p);
+ check_malloced_chunk(gm, mem, nb);
+ goto postaction;
+ }
+
+ else if (nb > gm->dvsize) {
+ if (smallbits != 0) { /* Use chunk in next nonempty smallbin */
+ mchunkptr b, p, r;
+ size_t rsize;
+ bindex_t i;
+ binmap_t leftbits =
+ (smallbits << idx) & left_bits(idx2bit(idx));
+ binmap_t leastbit = least_bit(leftbits);
+ compute_bit2idx(leastbit, i);
+ b = smallbin_at(gm, i);
+ p = b->fd;
+ assert(chunksize(p) == small_index2size(i));
+ unlink_first_small_chunk(gm, b, p, i);
+ rsize = small_index2size(i) - nb;
+ /* Fit here cannot be remainderless if 4byte sizes */
+ if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE)
+ set_inuse_and_pinuse(gm, p, small_index2size(i));
+ else {
+ set_size_and_pinuse_of_inuse_chunk(gm, p, nb);
+ r = chunk_plus_offset(p, nb);
+ set_size_and_pinuse_of_free_chunk(r, rsize);
+ replace_dv(gm, r, rsize);
+ }
+ mem = chunk2mem(p);
+ check_malloced_chunk(gm, mem, nb);
+ goto postaction;
+ }
+
+ else if (gm->treemap != 0
+ && (mem = tmalloc_small(gm, nb)) != 0) {
+ check_malloced_chunk(gm, mem, nb);
+ goto postaction;
+ }
+ }
+ } else if (bytes >= MAX_REQUEST)
+ nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */
+ else {
+ nb = pad_request(bytes);
+ if (gm->treemap != 0 && (mem = tmalloc_large(gm, nb)) != 0) {
+ check_malloced_chunk(gm, mem, nb);
+ goto postaction;
+ }
+ }
+
+ if (nb <= gm->dvsize) {
+ size_t rsize = gm->dvsize - nb;
+ mchunkptr p = gm->dv;
+ if (rsize >= MIN_CHUNK_SIZE) { /* split dv */
+ mchunkptr r = gm->dv = chunk_plus_offset(p, nb);
+ gm->dvsize = rsize;
+ set_size_and_pinuse_of_free_chunk(r, rsize);
+ set_size_and_pinuse_of_inuse_chunk(gm, p, nb);
+ } else { /* exhaust dv */
+ size_t dvs = gm->dvsize;
+ gm->dvsize = 0;
+ gm->dv = 0;
+ set_inuse_and_pinuse(gm, p, dvs);
+ }
+ mem = chunk2mem(p);
+ check_malloced_chunk(gm, mem, nb);
+ goto postaction;
+ }
+
+ else if (nb < gm->topsize) { /* Split top */
+ size_t rsize = gm->topsize -= nb;
+ mchunkptr p = gm->top;
+ mchunkptr r = gm->top = chunk_plus_offset(p, nb);
+ r->head = rsize | PINUSE_BIT;
+ set_size_and_pinuse_of_inuse_chunk(gm, p, nb);
+ mem = chunk2mem(p);
+ check_top_chunk(gm, gm->top);
+ check_malloced_chunk(gm, mem, nb);
+ goto postaction;
+ }
+
+ mem = sys_alloc(gm, nb);
+
+ postaction:
+ POSTACTION(gm);
+ return mem;
+ }
+
+ return 0;
+}
+
+void
+dlfree(void *mem)
+{
+ /*
+ Consolidate freed chunks with preceeding or succeeding bordering
+ free chunks, if they exist, and then place in a bin. Intermixed
+ with special cases for top, dv, mmapped chunks, and usage errors.
+ */
+
+ if (mem != 0) {
+ mchunkptr p = mem2chunk(mem);
+#if FOOTERS
+ mstate fm = get_mstate_for(p);
+ if (!ok_magic(fm)) {
+ USAGE_ERROR_ACTION(fm, p);
+ return;
+ }
+#else /* FOOTERS */
+#define fm gm
+#endif /* FOOTERS */
+ if (!PREACTION(fm)) {
+ check_inuse_chunk(fm, p);
+ if (RTCHECK(ok_address(fm, p) && ok_cinuse(p))) {
+ size_t psize = chunksize(p);
+ mchunkptr next = chunk_plus_offset(p, psize);
+ if (!pinuse(p)) {
+ size_t prevsize = p->prev_foot;
+ if ((prevsize & IS_MMAPPED_BIT) != 0) {
+ prevsize &= ~IS_MMAPPED_BIT;
+ psize += prevsize + MMAP_FOOT_PAD;
+ if (CALL_MUNMAP((char *) p - prevsize, psize) == 0)
+ fm->footprint -= psize;
+ goto postaction;
+ } else {
+ mchunkptr prev = chunk_minus_offset(p, prevsize);
+ psize += prevsize;
+ p = prev;
+ if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */
+ if (p != fm->dv) {
+ unlink_chunk(fm, p, prevsize);
+ } else if ((next->head & INUSE_BITS) ==
+ INUSE_BITS) {
+ fm->dvsize = psize;
+ set_free_with_pinuse(p, psize, next);
+ goto postaction;
+ }
+ } else
+ goto erroraction;
+ }
+ }
+
+ if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) {
+ if (!cinuse(next)) { /* consolidate forward */
+ if (next == fm->top) {
+ size_t tsize = fm->topsize += psize;
+ fm->top = p;
+ p->head = tsize | PINUSE_BIT;
+ if (p == fm->dv) {
+ fm->dv = 0;
+ fm->dvsize = 0;
+ }
+ if (should_trim(fm, tsize))
+ sys_trim(fm, 0);
+ goto postaction;
+ } else if (next == fm->dv) {
+ size_t dsize = fm->dvsize += psize;
+ fm->dv = p;
+ set_size_and_pinuse_of_free_chunk(p, dsize);
+ goto postaction;
+ } else {
+ size_t nsize = chunksize(next);
+ psize += nsize;
+ unlink_chunk(fm, next, nsize);
+ set_size_and_pinuse_of_free_chunk(p, psize);
+ if (p == fm->dv) {
+ fm->dvsize = psize;
+ goto postaction;
+ }
+ }
+ } else
+ set_free_with_pinuse(p, psize, next);
+ insert_chunk(fm, p, psize);
+ check_free_chunk(fm, p);
+ goto postaction;
+ }
+ }
+ erroraction:
+ USAGE_ERROR_ACTION(fm, p);
+ postaction:
+ POSTACTION(fm);
+ }
+ }
+#if !FOOTERS
+#undef fm
+#endif /* FOOTERS */
+}
+
+void *
+dlcalloc(size_t n_elements, size_t elem_size)
+{
+ void *mem;
+ size_t req = 0;
+ if (n_elements != 0) {
+ req = n_elements * elem_size;
+ if (((n_elements | elem_size) & ~(size_t) 0xffff) &&
+ (req / n_elements != elem_size))
+ req = MAX_SIZE_T; /* force downstream failure on overflow */
+ }
+ mem = dlmalloc(req);
+ if (mem != 0 && calloc_must_clear(mem2chunk(mem)))
+ memset(mem, 0, req);
+ return mem;
+}
+
+void *
+dlrealloc(void *oldmem, size_t bytes)
+{
+ if (oldmem == 0)
+ return dlmalloc(bytes);
+#ifdef REALLOC_ZERO_BYTES_FREES
+ if (bytes == 0) {
+ dlfree(oldmem);
+ return 0;
+ }
+#endif /* REALLOC_ZERO_BYTES_FREES */
+ else {
+#if ! FOOTERS
+ mstate m = gm;
+#else /* FOOTERS */
+ mstate m = get_mstate_for(mem2chunk(oldmem));
+ if (!ok_magic(m)) {
+ USAGE_ERROR_ACTION(m, oldmem);
+ return 0;
+ }
+#endif /* FOOTERS */
+ return internal_realloc(m, oldmem, bytes);
+ }
+}
+
+void *
+dlmemalign(size_t alignment, size_t bytes)
+{
+ return internal_memalign(gm, alignment, bytes);
+}
+
+void **
+dlindependent_calloc(size_t n_elements, size_t elem_size, void *chunks[])
+{
+ size_t sz = elem_size; /* serves as 1-element array */
+ return ialloc(gm, n_elements, &sz, 3, chunks);
+}
+
+void **
+dlindependent_comalloc(size_t n_elements, size_t sizes[], void *chunks[])
+{
+ return ialloc(gm, n_elements, sizes, 0, chunks);
+}
+
+void *
+dlvalloc(size_t bytes)
+{
+ size_t pagesz;
+ init_mparams();
+ pagesz = mparams.page_size;
+ return dlmemalign(pagesz, bytes);
+}
+
+void *
+dlpvalloc(size_t bytes)
+{
+ size_t pagesz;
+ init_mparams();
+ pagesz = mparams.page_size;
+ return dlmemalign(pagesz,
+ (bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE));
+}
+
+int
+dlmalloc_trim(size_t pad)
+{
+ int result = 0;
+ if (!PREACTION(gm)) {
+ result = sys_trim(gm, pad);
+ POSTACTION(gm);
+ }
+ return result;
+}
+
+size_t
+dlmalloc_footprint(void)
+{
+ return gm->footprint;
+}
+
+size_t
+dlmalloc_max_footprint(void)
+{
+ return gm->max_footprint;
+}
+
+#if !NO_MALLINFO
+struct mallinfo
+dlmallinfo(void)
+{
+ return internal_mallinfo(gm);
+}
+#endif /* NO_MALLINFO */
+
+void
+dlmalloc_stats()
+{
+ internal_malloc_stats(gm);
+}
+
+size_t
+dlmalloc_usable_size(void *mem)
+{
+ if (mem != 0) {
+ mchunkptr p = mem2chunk(mem);
+ if (cinuse(p))
+ return chunksize(p) - overhead_for(p);
+ }
+ return 0;
+}
+
+int
+dlmallopt(int param_number, int value)
+{
+ return change_mparam(param_number, value);
+}
+
+#endif /* !ONLY_MSPACES */
+
+/* ----------------------------- user mspaces ---------------------------- */
+
+#if MSPACES
+
+static mstate
+init_user_mstate(char *tbase, size_t tsize)
+{
+ size_t msize = pad_request(sizeof(struct malloc_state));
+ mchunkptr mn;
+ mchunkptr msp = align_as_chunk(tbase);
+ mstate m = (mstate) (chunk2mem(msp));
+ memset(m, 0, msize);
+ INITIAL_LOCK(&m->mutex);
+ msp->head = (msize | PINUSE_BIT | CINUSE_BIT);
+ m->seg.base = m->least_addr = tbase;
+ m->seg.size = m->footprint = m->max_footprint = tsize;
+ m->magic = mparams.magic;
+ m->mflags = mparams.default_mflags;
+ disable_contiguous(m);
+ init_bins(m);
+ mn = next_chunk(mem2chunk(m));
+ init_top(m, mn, (size_t) ((tbase + tsize) - (char *) mn) - TOP_FOOT_SIZE);
+ check_top_chunk(m, m->top);
+ return m;
+}
+
+mspace
+create_mspace(size_t capacity, int locked)
+{
+ mstate m = 0;
+ size_t msize = pad_request(sizeof(struct malloc_state));
+ init_mparams(); /* Ensure pagesize etc initialized */
+
+ if (capacity < (size_t) - (msize + TOP_FOOT_SIZE + mparams.page_size)) {
+ size_t rs = ((capacity == 0) ? mparams.granularity :
+ (capacity + TOP_FOOT_SIZE + msize));
+ size_t tsize = granularity_align(rs);
+ char *tbase = (char *) (CALL_MMAP(tsize));
+ if (tbase != CMFAIL) {
+ m = init_user_mstate(tbase, tsize);
+ m->seg.sflags = IS_MMAPPED_BIT;
+ set_lock(m, locked);
+ }
+ }
+ return (mspace) m;
+}
+
+mspace
+create_mspace_with_base(void *base, size_t capacity, int locked)
+{
+ mstate m = 0;
+ size_t msize = pad_request(sizeof(struct malloc_state));
+ init_mparams(); /* Ensure pagesize etc initialized */
+
+ if (capacity > msize + TOP_FOOT_SIZE &&
+ capacity < (size_t) - (msize + TOP_FOOT_SIZE + mparams.page_size)) {
+ m = init_user_mstate((char *) base, capacity);
+ m->seg.sflags = EXTERN_BIT;
+ set_lock(m, locked);
+ }
+ return (mspace) m;
+}
+
+size_t
+destroy_mspace(mspace msp)
+{
+ size_t freed = 0;
+ mstate ms = (mstate) msp;
+ if (ok_magic(ms)) {
+ msegmentptr sp = &ms->seg;
+ while (sp != 0) {
+ char *base = sp->base;
+ size_t size = sp->size;
+ flag_t flag = sp->sflags;
+ sp = sp->next;
+ if ((flag & IS_MMAPPED_BIT) && !(flag & EXTERN_BIT) &&
+ CALL_MUNMAP(base, size) == 0)
+ freed += size;
+ }
+ } else {
+ USAGE_ERROR_ACTION(ms, ms);
+ }
+ return freed;
+}
+
+/*
+ mspace versions of routines are near-clones of the global
+ versions. This is not so nice but better than the alternatives.
+*/
+
+
+void *
+mspace_malloc(mspace msp, size_t bytes)
+{
+ mstate ms = (mstate) msp;
+ if (!ok_magic(ms)) {
+ USAGE_ERROR_ACTION(ms, ms);
+ return 0;
+ }
+ if (!PREACTION(ms)) {
+ void *mem;
+ size_t nb;
+ if (bytes <= MAX_SMALL_REQUEST) {
+ bindex_t idx;
+ binmap_t smallbits;
+ nb = (bytes < MIN_REQUEST) ? MIN_CHUNK_SIZE : pad_request(bytes);
+ idx = small_index(nb);
+ smallbits = ms->smallmap >> idx;
+
+ if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */
+ mchunkptr b, p;
+ idx += ~smallbits & 1; /* Uses next bin if idx empty */
+ b = smallbin_at(ms, idx);
+ p = b->fd;
+ assert(chunksize(p) == small_index2size(idx));
+ unlink_first_small_chunk(ms, b, p, idx);
+ set_inuse_and_pinuse(ms, p, small_index2size(idx));
+ mem = chunk2mem(p);
+ check_malloced_chunk(ms, mem, nb);
+ goto postaction;
+ }
+
+ else if (nb > ms->dvsize) {
+ if (smallbits != 0) { /* Use chunk in next nonempty smallbin */
+ mchunkptr b, p, r;
+ size_t rsize;
+ bindex_t i;
+ binmap_t leftbits =
+ (smallbits << idx) & left_bits(idx2bit(idx));
+ binmap_t leastbit = least_bit(leftbits);
+ compute_bit2idx(leastbit, i);
+ b = smallbin_at(ms, i);
+ p = b->fd;
+ assert(chunksize(p) == small_index2size(i));
+ unlink_first_small_chunk(ms, b, p, i);
+ rsize = small_index2size(i) - nb;
+ /* Fit here cannot be remainderless if 4byte sizes */
+ if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE)
+ set_inuse_and_pinuse(ms, p, small_index2size(i));
+ else {
+ set_size_and_pinuse_of_inuse_chunk(ms, p, nb);
+ r = chunk_plus_offset(p, nb);
+ set_size_and_pinuse_of_free_chunk(r, rsize);
+ replace_dv(ms, r, rsize);
+ }
+ mem = chunk2mem(p);
+ check_malloced_chunk(ms, mem, nb);
+ goto postaction;
+ }
+
+ else if (ms->treemap != 0
+ && (mem = tmalloc_small(ms, nb)) != 0) {
+ check_malloced_chunk(ms, mem, nb);
+ goto postaction;
+ }
+ }
+ } else if (bytes >= MAX_REQUEST)
+ nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */
+ else {
+ nb = pad_request(bytes);
+ if (ms->treemap != 0 && (mem = tmalloc_large(ms, nb)) != 0) {
+ check_malloced_chunk(ms, mem, nb);
+ goto postaction;
+ }
+ }
+
+ if (nb <= ms->dvsize) {
+ size_t rsize = ms->dvsize - nb;
+ mchunkptr p = ms->dv;
+ if (rsize >= MIN_CHUNK_SIZE) { /* split dv */
+ mchunkptr r = ms->dv = chunk_plus_offset(p, nb);
+ ms->dvsize = rsize;
+ set_size_and_pinuse_of_free_chunk(r, rsize);
+ set_size_and_pinuse_of_inuse_chunk(ms, p, nb);
+ } else { /* exhaust dv */
+ size_t dvs = ms->dvsize;
+ ms->dvsize = 0;
+ ms->dv = 0;
+ set_inuse_and_pinuse(ms, p, dvs);
+ }
+ mem = chunk2mem(p);
+ check_malloced_chunk(ms, mem, nb);
+ goto postaction;
+ }
+
+ else if (nb < ms->topsize) { /* Split top */
+ size_t rsize = ms->topsize -= nb;
+ mchunkptr p = ms->top;
+ mchunkptr r = ms->top = chunk_plus_offset(p, nb);
+ r->head = rsize | PINUSE_BIT;
+ set_size_and_pinuse_of_inuse_chunk(ms, p, nb);
+ mem = chunk2mem(p);
+ check_top_chunk(ms, ms->top);
+ check_malloced_chunk(ms, mem, nb);
+ goto postaction;
+ }
+
+ mem = sys_alloc(ms, nb);
+
+ postaction:
+ POSTACTION(ms);
+ return mem;
+ }
+
+ return 0;
+}
+
+void
+mspace_free(mspace msp, void *mem)
+{
+ if (mem != 0) {
+ mchunkptr p = mem2chunk(mem);
+#if FOOTERS
+ mstate fm = get_mstate_for(p);
+#else /* FOOTERS */
+ mstate fm = (mstate) msp;
+#endif /* FOOTERS */
+ if (!ok_magic(fm)) {
+ USAGE_ERROR_ACTION(fm, p);
+ return;
+ }
+ if (!PREACTION(fm)) {
+ check_inuse_chunk(fm, p);
+ if (RTCHECK(ok_address(fm, p) && ok_cinuse(p))) {
+ size_t psize = chunksize(p);
+ mchunkptr next = chunk_plus_offset(p, psize);
+ if (!pinuse(p)) {
+ size_t prevsize = p->prev_foot;
+ if ((prevsize & IS_MMAPPED_BIT) != 0) {
+ prevsize &= ~IS_MMAPPED_BIT;
+ psize += prevsize + MMAP_FOOT_PAD;
+ if (CALL_MUNMAP((char *) p - prevsize, psize) == 0)
+ fm->footprint -= psize;
+ goto postaction;
+ } else {
+ mchunkptr prev = chunk_minus_offset(p, prevsize);
+ psize += prevsize;
+ p = prev;
+ if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */
+ if (p != fm->dv) {
+ unlink_chunk(fm, p, prevsize);
+ } else if ((next->head & INUSE_BITS) ==
+ INUSE_BITS) {
+ fm->dvsize = psize;
+ set_free_with_pinuse(p, psize, next);
+ goto postaction;
+ }
+ } else
+ goto erroraction;
+ }
+ }
+
+ if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) {
+ if (!cinuse(next)) { /* consolidate forward */
+ if (next == fm->top) {
+ size_t tsize = fm->topsize += psize;
+ fm->top = p;
+ p->head = tsize | PINUSE_BIT;
+ if (p == fm->dv) {
+ fm->dv = 0;
+ fm->dvsize = 0;
+ }
+ if (should_trim(fm, tsize))
+ sys_trim(fm, 0);
+ goto postaction;
+ } else if (next == fm->dv) {
+ size_t dsize = fm->dvsize += psize;
+ fm->dv = p;
+ set_size_and_pinuse_of_free_chunk(p, dsize);
+ goto postaction;
+ } else {
+ size_t nsize = chunksize(next);
+ psize += nsize;
+ unlink_chunk(fm, next, nsize);
+ set_size_and_pinuse_of_free_chunk(p, psize);
+ if (p == fm->dv) {
+ fm->dvsize = psize;
+ goto postaction;
+ }
+ }
+ } else
+ set_free_with_pinuse(p, psize, next);
+ insert_chunk(fm, p, psize);
+ check_free_chunk(fm, p);
+ goto postaction;
+ }
+ }
+ erroraction:
+ USAGE_ERROR_ACTION(fm, p);
+ postaction:
+ POSTACTION(fm);
+ }
+ }
+}
+
+void *
+mspace_calloc(mspace msp, size_t n_elements, size_t elem_size)
+{
+ void *mem;
+ size_t req = 0;
+ mstate ms = (mstate) msp;
+ if (!ok_magic(ms)) {
+ USAGE_ERROR_ACTION(ms, ms);
+ return 0;
+ }
+ if (n_elements != 0) {
+ req = n_elements * elem_size;
+ if (((n_elements | elem_size) & ~(size_t) 0xffff) &&
+ (req / n_elements != elem_size))
+ req = MAX_SIZE_T; /* force downstream failure on overflow */
+ }
+ mem = internal_malloc(ms, req);
+ if (mem != 0 && calloc_must_clear(mem2chunk(mem)))
+ memset(mem, 0, req);
+ return mem;
+}
+
+void *
+mspace_realloc(mspace msp, void *oldmem, size_t bytes)
+{
+ if (oldmem == 0)
+ return mspace_malloc(msp, bytes);
+#ifdef REALLOC_ZERO_BYTES_FREES
+ if (bytes == 0) {
+ mspace_free(msp, oldmem);
+ return 0;
+ }
+#endif /* REALLOC_ZERO_BYTES_FREES */
+ else {
+#if FOOTERS
+ mchunkptr p = mem2chunk(oldmem);
+ mstate ms = get_mstate_for(p);
+#else /* FOOTERS */
+ mstate ms = (mstate) msp;
+#endif /* FOOTERS */
+ if (!ok_magic(ms)) {
+ USAGE_ERROR_ACTION(ms, ms);
+ return 0;
+ }
+ return internal_realloc(ms, oldmem, bytes);
+ }
+}
+
+void *
+mspace_memalign(mspace msp, size_t alignment, size_t bytes)
+{
+ mstate ms = (mstate) msp;
+ if (!ok_magic(ms)) {
+ USAGE_ERROR_ACTION(ms, ms);
+ return 0;
+ }
+ return internal_memalign(ms, alignment, bytes);
+}
+
+void **
+mspace_independent_calloc(mspace msp, size_t n_elements,
+ size_t elem_size, void *chunks[])
+{
+ size_t sz = elem_size; /* serves as 1-element array */
+ mstate ms = (mstate) msp;
+ if (!ok_magic(ms)) {
+ USAGE_ERROR_ACTION(ms, ms);
+ return 0;
+ }
+ return ialloc(ms, n_elements, &sz, 3, chunks);
+}
+
+void **
+mspace_independent_comalloc(mspace msp, size_t n_elements,
+ size_t sizes[], void *chunks[])
+{
+ mstate ms = (mstate) msp;
+ if (!ok_magic(ms)) {
+ USAGE_ERROR_ACTION(ms, ms);
+ return 0;
+ }
+ return ialloc(ms, n_elements, sizes, 0, chunks);
+}
+
+int
+mspace_trim(mspace msp, size_t pad)
+{
+ int result = 0;
+ mstate ms = (mstate) msp;
+ if (ok_magic(ms)) {
+ if (!PREACTION(ms)) {
+ result = sys_trim(ms, pad);
+ POSTACTION(ms);
+ }
+ } else {
+ USAGE_ERROR_ACTION(ms, ms);
+ }
+ return result;
+}
+
+void
+mspace_malloc_stats(mspace msp)
+{
+ mstate ms = (mstate) msp;
+ if (ok_magic(ms)) {
+ internal_malloc_stats(ms);
+ } else {
+ USAGE_ERROR_ACTION(ms, ms);
+ }
+}
+
+size_t
+mspace_footprint(mspace msp)
+{
+ size_t result;
+ mstate ms = (mstate) msp;
+ if (ok_magic(ms)) {
+ result = ms->footprint;
+ }
+ USAGE_ERROR_ACTION(ms, ms);
+ return result;
+}
+
+
+size_t
+mspace_max_footprint(mspace msp)
+{
+ size_t result;
+ mstate ms = (mstate) msp;
+ if (ok_magic(ms)) {
+ result = ms->max_footprint;
+ }
+ USAGE_ERROR_ACTION(ms, ms);
+ return result;
+}
+
+
+#if !NO_MALLINFO
+struct mallinfo
+mspace_mallinfo(mspace msp)
+{
+ mstate ms = (mstate) msp;
+ if (!ok_magic(ms)) {
+ USAGE_ERROR_ACTION(ms, ms);
+ }
+ return internal_mallinfo(ms);
+}
+#endif /* NO_MALLINFO */
+
+int
+mspace_mallopt(int param_number, int value)
+{
+ return change_mparam(param_number, value);
+}
+
+#endif /* MSPACES */
+
+/* -------------------- Alternative MORECORE functions ------------------- */
+
+/*
+ Guidelines for creating a custom version of MORECORE:
+
+ * For best performance, MORECORE should allocate in multiples of pagesize.
+ * MORECORE may allocate more memory than requested. (Or even less,
+ but this will usually result in a malloc failure.)
+ * MORECORE must not allocate memory when given argument zero, but
+ instead return one past the end address of memory from previous
+ nonzero call.
+ * For best performance, consecutive calls to MORECORE with positive
+ arguments should return increasing addresses, indicating that
+ space has been contiguously extended.
+ * Even though consecutive calls to MORECORE need not return contiguous
+ addresses, it must be OK for malloc'ed chunks to span multiple
+ regions in those cases where they do happen to be contiguous.
+ * MORECORE need not handle negative arguments -- it may instead
+ just return MFAIL when given negative arguments.
+ Negative arguments are always multiples of pagesize. MORECORE
+ must not misinterpret negative args as large positive unsigned
+ args. You can suppress all such calls from even occurring by defining
+ MORECORE_CANNOT_TRIM,
+
+ As an example alternative MORECORE, here is a custom allocator
+ kindly contributed for pre-OSX macOS. It uses virtually but not
+ necessarily physically contiguous non-paged memory (locked in,
+ present and won't get swapped out). You can use it by uncommenting
+ this section, adding some #includes, and setting up the appropriate
+ defines above:
+
+ #define MORECORE osMoreCore
+
+ There is also a shutdown routine that should somehow be called for
+ cleanup upon program exit.
+
+ #define MAX_POOL_ENTRIES 100
+ #define MINIMUM_MORECORE_SIZE (64 * 1024U)
+ static int next_os_pool;
+ void *our_os_pools[MAX_POOL_ENTRIES];
+
+ void *osMoreCore(int size)
+ {
+ void *ptr = 0;
+ static void *sbrk_top = 0;
+
+ if (size > 0)
+ {
+ if (size < MINIMUM_MORECORE_SIZE)
+ size = MINIMUM_MORECORE_SIZE;
+ if (CurrentExecutionLevel() == kTaskLevel)
+ ptr = PoolAllocateResident(size + RM_PAGE_SIZE, 0);
+ if (ptr == 0)
+ {
+ return (void *) MFAIL;
+ }
+ // save ptrs so they can be freed during cleanup
+ our_os_pools[next_os_pool] = ptr;
+ next_os_pool++;
+ ptr = (void *) ((((size_t) ptr) + RM_PAGE_MASK) & ~RM_PAGE_MASK);
+ sbrk_top = (char *) ptr + size;
+ return ptr;
+ }
+ else if (size < 0)
+ {
+ // we don't currently support shrink behavior
+ return (void *) MFAIL;
+ }
+ else
+ {
+ return sbrk_top;
+ }
+ }
+
+ // cleanup any allocated memory pools
+ // called as last thing before shutting down driver
+
+ void osCleanupMem(void)
+ {
+ void **ptr;
+
+ for (ptr = our_os_pools; ptr < &our_os_pools[MAX_POOL_ENTRIES]; ptr++)
+ if (*ptr)
+ {
+ PoolDeallocate(*ptr);
+ *ptr = 0;
+ }
+ }
+
+*/
+
+
+/* -----------------------------------------------------------------------
+History:
+ V2.8.3 Thu Sep 22 11:16:32 2005 Doug Lea (dl at gee)
+ * Add max_footprint functions
+ * Ensure all appropriate literals are size_t
+ * Fix conditional compilation problem for some #define settings
+ * Avoid concatenating segments with the one provided
+ in create_mspace_with_base
+ * Rename some variables to avoid compiler shadowing warnings
+ * Use explicit lock initialization.
+ * Better handling of sbrk interference.
+ * Simplify and fix segment insertion, trimming and mspace_destroy
+ * Reinstate REALLOC_ZERO_BYTES_FREES option from 2.7.x
+ * Thanks especially to Dennis Flanagan for help on these.
+
+ V2.8.2 Sun Jun 12 16:01:10 2005 Doug Lea (dl at gee)
+ * Fix memalign brace error.
+
+ V2.8.1 Wed Jun 8 16:11:46 2005 Doug Lea (dl at gee)
+ * Fix improper #endif nesting in C++
+ * Add explicit casts needed for C++
+
+ V2.8.0 Mon May 30 14:09:02 2005 Doug Lea (dl at gee)
+ * Use trees for large bins
+ * Support mspaces
+ * Use segments to unify sbrk-based and mmap-based system allocation,
+ removing need for emulation on most platforms without sbrk.
+ * Default safety checks
+ * Optional footer checks. Thanks to William Robertson for the idea.
+ * Internal code refactoring
+ * Incorporate suggestions and platform-specific changes.
+ Thanks to Dennis Flanagan, Colin Plumb, Niall Douglas,
+ Aaron Bachmann, Emery Berger, and others.
+ * Speed up non-fastbin processing enough to remove fastbins.
+ * Remove useless cfree() to avoid conflicts with other apps.
+ * Remove internal memcpy, memset. Compilers handle builtins better.
+ * Remove some options that no one ever used and rename others.
+
+ V2.7.2 Sat Aug 17 09:07:30 2002 Doug Lea (dl at gee)
+ * Fix malloc_state bitmap array misdeclaration
+
+ V2.7.1 Thu Jul 25 10:58:03 2002 Doug Lea (dl at gee)
+ * Allow tuning of FIRST_SORTED_BIN_SIZE
+ * Use PTR_UINT as type for all ptr->int casts. Thanks to John Belmonte.
+ * Better detection and support for non-contiguousness of MORECORE.
+ Thanks to Andreas Mueller, Conal Walsh, and Wolfram Gloger
+ * Bypass most of malloc if no frees. Thanks To Emery Berger.
+ * Fix freeing of old top non-contiguous chunk im sysmalloc.
+ * Raised default trim and map thresholds to 256K.
+ * Fix mmap-related #defines. Thanks to Lubos Lunak.
+ * Fix copy macros; added LACKS_FCNTL_H. Thanks to Neal Walfield.
+ * Branch-free bin calculation
+ * Default trim and mmap thresholds now 256K.
+
+ V2.7.0 Sun Mar 11 14:14:06 2001 Doug Lea (dl at gee)
+ * Introduce independent_comalloc and independent_calloc.
+ Thanks to Michael Pachos for motivation and help.
+ * Make optional .h file available
+ * Allow > 2GB requests on 32bit systems.
+ * new WIN32 sbrk, mmap, munmap, lock code from <Walter@GeNeSys-e.de>.
+ Thanks also to Andreas Mueller <a.mueller at paradatec.de>,
+ and Anonymous.
+ * Allow override of MALLOC_ALIGNMENT (Thanks to Ruud Waij for
+ helping test this.)
+ * memalign: check alignment arg
+ * realloc: don't try to shift chunks backwards, since this
+ leads to more fragmentation in some programs and doesn't
+ seem to help in any others.
+ * Collect all cases in malloc requiring system memory into sysmalloc
+ * Use mmap as backup to sbrk
+ * Place all internal state in malloc_state
+ * Introduce fastbins (although similar to 2.5.1)
+ * Many minor tunings and cosmetic improvements
+ * Introduce USE_PUBLIC_MALLOC_WRAPPERS, USE_MALLOC_LOCK
+ * Introduce MALLOC_FAILURE_ACTION, MORECORE_CONTIGUOUS
+ Thanks to Tony E. Bennett <tbennett@nvidia.com> and others.
+ * Include errno.h to support default failure action.
+
+ V2.6.6 Sun Dec 5 07:42:19 1999 Doug Lea (dl at gee)
+ * return null for negative arguments
+ * Added Several WIN32 cleanups from Martin C. Fong <mcfong at yahoo.com>
+ * Add 'LACKS_SYS_PARAM_H' for those systems without 'sys/param.h'
+ (e.g. WIN32 platforms)
+ * Cleanup header file inclusion for WIN32 platforms
+ * Cleanup code to avoid Microsoft Visual C++ compiler complaints
+ * Add 'USE_DL_PREFIX' to quickly allow co-existence with existing
+ memory allocation routines
+ * Set 'malloc_getpagesize' for WIN32 platforms (needs more work)
+ * Use 'assert' rather than 'ASSERT' in WIN32 code to conform to
+ usage of 'assert' in non-WIN32 code
+ * Improve WIN32 'sbrk()' emulation's 'findRegion()' routine to
+ avoid infinite loop
+ * Always call 'fREe()' rather than 'free()'
+
+ V2.6.5 Wed Jun 17 15:57:31 1998 Doug Lea (dl at gee)
+ * Fixed ordering problem with boundary-stamping
+
+ V2.6.3 Sun May 19 08:17:58 1996 Doug Lea (dl at gee)
+ * Added pvalloc, as recommended by H.J. Liu
+ * Added 64bit pointer support mainly from Wolfram Gloger
+ * Added anonymously donated WIN32 sbrk emulation
+ * Malloc, calloc, getpagesize: add optimizations from Raymond Nijssen
+ * malloc_extend_top: fix mask error that caused wastage after
+ foreign sbrks
+ * Add linux mremap support code from HJ Liu
+
+ V2.6.2 Tue Dec 5 06:52:55 1995 Doug Lea (dl at gee)
+ * Integrated most documentation with the code.
+ * Add support for mmap, with help from
+ Wolfram Gloger (Gloger@lrz.uni-muenchen.de).
+ * Use last_remainder in more cases.
+ * Pack bins using idea from colin@nyx10.cs.du.edu
+ * Use ordered bins instead of best-fit threshhold
+ * Eliminate block-local decls to simplify tracing and debugging.
+ * Support another case of realloc via move into top
+ * Fix error occuring when initial sbrk_base not word-aligned.
+ * Rely on page size for units instead of SBRK_UNIT to
+ avoid surprises about sbrk alignment conventions.
+ * Add mallinfo, mallopt. Thanks to Raymond Nijssen
+ (raymond@es.ele.tue.nl) for the suggestion.
+ * Add `pad' argument to malloc_trim and top_pad mallopt parameter.
+ * More precautions for cases where other routines call sbrk,
+ courtesy of Wolfram Gloger (Gloger@lrz.uni-muenchen.de).
+ * Added macros etc., allowing use in linux libc from
+ H.J. Lu (hjl@gnu.ai.mit.edu)
+ * Inverted this history list
+
+ V2.6.1 Sat Dec 2 14:10:57 1995 Doug Lea (dl at gee)
+ * Re-tuned and fixed to behave more nicely with V2.6.0 changes.
+ * Removed all preallocation code since under current scheme
+ the work required to undo bad preallocations exceeds
+ the work saved in good cases for most test programs.
+ * No longer use return list or unconsolidated bins since
+ no scheme using them consistently outperforms those that don't
+ given above changes.
+ * Use best fit for very large chunks to prevent some worst-cases.
+ * Added some support for debugging
+
+ V2.6.0 Sat Nov 4 07:05:23 1995 Doug Lea (dl at gee)
+ * Removed footers when chunks are in use. Thanks to
+ Paul Wilson (wilson@cs.texas.edu) for the suggestion.
+
+ V2.5.4 Wed Nov 1 07:54:51 1995 Doug Lea (dl at gee)
+ * Added malloc_trim, with help from Wolfram Gloger
+ (wmglo@Dent.MED.Uni-Muenchen.DE).
+
+ V2.5.3 Tue Apr 26 10:16:01 1994 Doug Lea (dl at g)
+
+ V2.5.2 Tue Apr 5 16:20:40 1994 Doug Lea (dl at g)
+ * realloc: try to expand in both directions
+ * malloc: swap order of clean-bin strategy;
+ * realloc: only conditionally expand backwards
+ * Try not to scavenge used bins
+ * Use bin counts as a guide to preallocation
+ * Occasionally bin return list chunks in first scan
+ * Add a few optimizations from colin@nyx10.cs.du.edu
+
+ V2.5.1 Sat Aug 14 15:40:43 1993 Doug Lea (dl at g)
+ * faster bin computation & slightly different binning
+ * merged all consolidations to one part of malloc proper
+ (eliminating old malloc_find_space & malloc_clean_bin)
+ * Scan 2 returns chunks (not just 1)
+ * Propagate failure in realloc if malloc returns 0
+ * Add stuff to allow compilation on non-ANSI compilers
+ from kpv@research.att.com
+
+ V2.5 Sat Aug 7 07:41:59 1993 Doug Lea (dl at g.oswego.edu)
+ * removed potential for odd address access in prev_chunk
+ * removed dependency on getpagesize.h
+ * misc cosmetics and a bit more internal documentation
+ * anticosmetics: mangled names in macros to evade debugger strangeness
+ * tested on sparc, hp-700, dec-mips, rs6000
+ with gcc & native cc (hp, dec only) allowing
+ Detlefs & Zorn comparison study (in SIGPLAN Notices.)
+
+ Trial version Fri Aug 28 13:14:29 1992 Doug Lea (dl at g.oswego.edu)
+ * Based loosely on libg++-1.2X malloc. (It retains some of the overall
+ structure of old version, but most details differ.)
+
+*/
+
+#endif /* !HAVE_MALLOC */
+
+#ifdef HAVE_MALLOC
+#define real_malloc malloc
+#define real_calloc calloc
+#define real_realloc realloc
+#define real_free free
+#else
+#define real_malloc dlmalloc
+#define real_calloc dlcalloc
+#define real_realloc dlrealloc
+#define real_free dlfree
+#endif
+
+/* Memory functions used by SDL that can be replaced by the application */
+static struct
+{
+ SDL_malloc_func malloc_func;
+ SDL_calloc_func calloc_func;
+ SDL_realloc_func realloc_func;
+ SDL_free_func free_func;
+ SDL_atomic_t num_allocations;
+} s_mem = {
+ real_malloc, real_calloc, real_realloc, real_free, { 0 }
+};
+
+void SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
+ SDL_calloc_func *calloc_func,
+ SDL_realloc_func *realloc_func,
+ SDL_free_func *free_func)
+{
+ if (malloc_func) {
+ *malloc_func = s_mem.malloc_func;
+ }
+ if (calloc_func) {
+ *calloc_func = s_mem.calloc_func;
+ }
+ if (realloc_func) {
+ *realloc_func = s_mem.realloc_func;
+ }
+ if (free_func) {
+ *free_func = s_mem.free_func;
+ }
+}
+
+int SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
+ SDL_calloc_func calloc_func,
+ SDL_realloc_func realloc_func,
+ SDL_free_func free_func)
+{
+ if (!malloc_func) {
+ return SDL_InvalidParamError("malloc_func");
+ }
+ if (!calloc_func) {
+ return SDL_InvalidParamError("calloc_func");
+ }
+ if (!realloc_func) {
+ return SDL_InvalidParamError("realloc_func");
+ }
+ if (!free_func) {
+ return SDL_InvalidParamError("free_func");
+ }
+
+ s_mem.malloc_func = malloc_func;
+ s_mem.calloc_func = calloc_func;
+ s_mem.realloc_func = realloc_func;
+ s_mem.free_func = free_func;
+ return 0;
+}
+
+int SDL_GetNumAllocations(void)
+{
+ return SDL_AtomicGet(&s_mem.num_allocations);
+}
+
+void *SDL_malloc(size_t size)
+{
+ void *mem;
+
+ if (!size) {
+ size = 1;
+ }
+
+ mem = s_mem.malloc_func(size);
+ if (mem) {
+ SDL_AtomicIncRef(&s_mem.num_allocations);
+ }
+ return mem;
+}
+
+void *SDL_calloc(size_t nmemb, size_t size)
+{
+ void *mem;
+
+ if (!nmemb || !size) {
+ nmemb = 1;
+ size = 1;
+ }
+
+ mem = s_mem.calloc_func(nmemb, size);
+ if (mem) {
+ SDL_AtomicIncRef(&s_mem.num_allocations);
+ }
+ return mem;
+}
+
+void *SDL_realloc(void *ptr, size_t size)
+{
+ void *mem;
+
+ if (!ptr && !size) {
+ size = 1;
+ }
+
+ mem = s_mem.realloc_func(ptr, size);
+ if (mem && !ptr) {
+ SDL_AtomicIncRef(&s_mem.num_allocations);
+ }
+ return mem;
+}
+
+void SDL_free(void *ptr)
+{
+ if (!ptr) {
+ return;
+ }
+
+ s_mem.free_func(ptr);
+ (void)SDL_AtomicDecRef(&s_mem.num_allocations);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/stdlib/SDL_qsort.c b/src/3rdparty/SDL2/src/stdlib/SDL_qsort.c
new file mode 100644
index 0000000..700b9da
--- /dev/null
+++ b/src/3rdparty/SDL2/src/stdlib/SDL_qsort.c
@@ -0,0 +1,534 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
+#define SDL_DISABLE_ANALYZE_MACROS 1
+#endif
+
+#include "../SDL_internal.h"
+
+#include "SDL_stdinc.h"
+#include "SDL_assert.h"
+
+#if defined(HAVE_QSORT)
+void
+SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *))
+{
+ qsort(base, nmemb, size, compare);
+}
+
+#else
+
+#ifdef assert
+#undef assert
+#endif
+#define assert SDL_assert
+#ifdef malloc
+#undef malloc
+#endif
+#define malloc SDL_malloc
+#ifdef free
+#undef free
+#endif
+#define free SDL_free
+#ifdef memcpy
+#undef memcpy
+#endif
+#define memcpy SDL_memcpy
+#ifdef memmove
+#undef memmove
+#endif
+#define memmove SDL_memmove
+#ifdef qsortG
+#undef qsortG
+#endif
+#define qsortG SDL_qsort
+
+/*
+This code came from Gareth McCaughan, under the zlib license.
+Specifically this: https://www.mccaughan.org.uk/software/qsort.c-1.14
+
+Everything below this comment until the HAVE_QSORT #endif was from Gareth
+(any minor changes will be noted inline).
+
+Thank you to Gareth for relicensing this code under the zlib license for our
+benefit!
+
+--ryan.
+*/
+
+/* This is a drop-in replacement for the C library's |qsort()| routine.
+ *
+ * It is intended for use where you know or suspect that your
+ * platform's qsort is bad. If that isn't the case, then you
+ * should probably use the qsort your system gives you in preference
+ * to mine -- it will likely have been tested and tuned better.
+ *
+ * Features:
+ * - Median-of-three pivoting (and more)
+ * - Truncation and final polishing by a single insertion sort
+ * - Early truncation when no swaps needed in pivoting step
+ * - Explicit recursion, guaranteed not to overflow
+ * - A few little wrinkles stolen from the GNU |qsort()|.
+ * (For the avoidance of doubt, no code was stolen, only
+ * broad ideas.)
+ * - separate code for non-aligned / aligned / word-size objects
+ *
+ * Earlier releases of this code used an idiosyncratic licence
+ * I wrote myself, because I'm an idiot. The code is now released
+ * under the "zlib/libpng licence"; you will find the actual
+ * terms in the next comment. I request (but do not require)
+ * that if you make any changes beyond the name of the exported
+ * routine and reasonable tweaks to the TRUNC_* and
+ * PIVOT_THRESHOLD values, you modify the _ID string so as
+ * to make it clear that you have changed the code.
+ *
+ * If you find problems with this code, or find ways of
+ * making it significantly faster, please let me know!
+ * My e-mail address, valid as of early 2016 and for the
+ * foreseeable future, is
+ * gareth.mccaughan@pobox.com
+ * Thanks!
+ *
+ * Gareth McCaughan
+ */
+
+/* Copyright (c) 1998-2016 Gareth McCaughan
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any
+ * damages arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented;
+ * you must not claim that you wrote the original software.
+ * If you use this software in a product, an acknowledgment
+ * in the product documentation would be appreciated but
+ * is not required.
+ *
+ * 2. Altered source versions must be plainly marked as such,
+ * and must not be misrepresented as being the original software.
+ *
+ * 3. This notice may not be removed or altered from any source
+ * distribution.
+ */
+
+/* Revision history since release:
+ * 1998-03-19 v1.12 First release I have any records of.
+ * 2007-09-02 v1.13 Fix bug kindly reported by Dan Bodoh
+ * (premature termination of recursion).
+ * Add a few clarifying comments.
+ * Minor improvements to debug output.
+ * 2016-02-21 v1.14 Replace licence with 2-clause BSD,
+ * and clarify a couple of things in
+ * comments. No code changes.
+ */
+
+/* BEGIN SDL CHANGE ... commented this out with an #if 0 block. --ryan. */
+#if 0
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define DEBUG_QSORT
+
+static char _ID[]="<qsort.c gjm 1.14 2016-02-21>";
+#endif
+/* END SDL CHANGE ... commented this out with an #if 0 block. --ryan. */
+
+/* How many bytes are there per word? (Must be a power of 2,
+ * and must in fact equal sizeof(int).)
+ */
+#define WORD_BYTES sizeof(int)
+
+/* How big does our stack need to be? Answer: one entry per
+ * bit in a |size_t|.
+ */
+#define STACK_SIZE (8*sizeof(size_t))
+
+/* Different situations have slightly different requirements,
+ * and we make life epsilon easier by using different truncation
+ * points for the three different cases.
+ * So far, I have tuned TRUNC_words and guessed that the same
+ * value might work well for the other two cases. Of course
+ * what works well on my machine might work badly on yours.
+ */
+#define TRUNC_nonaligned 12
+#define TRUNC_aligned 12
+#define TRUNC_words 12*WORD_BYTES /* nb different meaning */
+
+/* We use a simple pivoting algorithm for shortish sub-arrays
+ * and a more complicated one for larger ones. The threshold
+ * is PIVOT_THRESHOLD.
+ */
+#define PIVOT_THRESHOLD 40
+
+typedef struct { char * first; char * last; } stack_entry;
+#define pushLeft {stack[stacktop].first=ffirst;stack[stacktop++].last=last;}
+#define pushRight {stack[stacktop].first=first;stack[stacktop++].last=llast;}
+#define doLeft {first=ffirst;llast=last;continue;}
+#define doRight {ffirst=first;last=llast;continue;}
+#define pop {if (--stacktop<0) break;\
+ first=ffirst=stack[stacktop].first;\
+ last=llast=stack[stacktop].last;\
+ continue;}
+
+/* Some comments on the implementation.
+ * 1. When we finish partitioning the array into "low"
+ * and "high", we forget entirely about short subarrays,
+ * because they'll be done later by insertion sort.
+ * Doing lots of little insertion sorts might be a win
+ * on large datasets for locality-of-reference reasons,
+ * but it makes the code much nastier and increases
+ * bookkeeping overhead.
+ * 2. We always save the shorter and get to work on the
+ * longer. This guarantees that every time we push
+ * an item onto the stack its size is <= 1/2 of that
+ * of its parent; so the stack can't need more than
+ * log_2(max-array-size) entries.
+ * 3. We choose a pivot by looking at the first, last
+ * and middle elements. We arrange them into order
+ * because it's easy to do that in conjunction with
+ * choosing the pivot, and it makes things a little
+ * easier in the partitioning step. Anyway, the pivot
+ * is the middle of these three. It's still possible
+ * to construct datasets where the algorithm takes
+ * time of order n^2, but it simply never happens in
+ * practice.
+ * 3' Newsflash: On further investigation I find that
+ * it's easy to construct datasets where median-of-3
+ * simply isn't good enough. So on large-ish subarrays
+ * we do a more sophisticated pivoting: we take three
+ * sets of 3 elements, find their medians, and then
+ * take the median of those.
+ * 4. We copy the pivot element to a separate place
+ * because that way we can always do our comparisons
+ * directly against a pointer to that separate place,
+ * and don't have to wonder "did we move the pivot
+ * element?". This makes the inner loop better.
+ * 5. It's possible to make the pivoting even more
+ * reliable by looking at more candidates when n
+ * is larger. (Taking this to its logical conclusion
+ * results in a variant of quicksort that doesn't
+ * have that n^2 worst case.) However, the overhead
+ * from the extra bookkeeping means that it's just
+ * not worth while.
+ * 6. This is pretty clean and portable code. Here are
+ * all the potential portability pitfalls and problems
+ * I know of:
+ * - In one place (the insertion sort) I construct
+ * a pointer that points just past the end of the
+ * supplied array, and assume that (a) it won't
+ * compare equal to any pointer within the array,
+ * and (b) it will compare equal to a pointer
+ * obtained by stepping off the end of the array.
+ * These might fail on some segmented architectures.
+ * - I assume that there are 8 bits in a |char| when
+ * computing the size of stack needed. This would
+ * fail on machines with 9-bit or 16-bit bytes.
+ * - I assume that if |((int)base&(sizeof(int)-1))==0|
+ * and |(size&(sizeof(int)-1))==0| then it's safe to
+ * get at array elements via |int*|s, and that if
+ * actually |size==sizeof(int)| as well then it's
+ * safe to treat the elements as |int|s. This might
+ * fail on systems that convert pointers to integers
+ * in non-standard ways.
+ * - I assume that |8*sizeof(size_t)<=INT_MAX|. This
+ * would be false on a machine with 8-bit |char|s,
+ * 16-bit |int|s and 4096-bit |size_t|s. :-)
+ */
+
+/* The recursion logic is the same in each case.
+ * We keep chopping up until we reach subarrays of size
+ * strictly less than Trunc; we leave these unsorted. */
+#define Recurse(Trunc) \
+ { size_t l=last-ffirst,r=llast-first; \
+ if (l<Trunc) { \
+ if (r>=Trunc) doRight \
+ else pop \
+ } \
+ else if (l<=r) { pushLeft; doRight } \
+ else if (r>=Trunc) { pushRight; doLeft }\
+ else doLeft \
+ }
+
+/* and so is the pivoting logic (note: last is inclusive): */
+#define Pivot(swapper,sz) \
+ if ((size_t)(last-first)>PIVOT_THRESHOLD*sz) mid=pivot_big(first,mid,last,sz,compare);\
+ else { \
+ if (compare(first,mid)<0) { \
+ if (compare(mid,last)>0) { \
+ swapper(mid,last); \
+ if (compare(first,mid)>0) swapper(first,mid);\
+ } \
+ } \
+ else { \
+ if (compare(mid,last)>0) swapper(first,last)\
+ else { \
+ swapper(first,mid); \
+ if (compare(mid,last)>0) swapper(mid,last);\
+ } \
+ } \
+ first+=sz; last-=sz; \
+ }
+
+#ifdef DEBUG_QSORT
+#include <stdio.h>
+#endif
+
+/* and so is the partitioning logic: */
+#define Partition(swapper,sz) { \
+ do { \
+ while (compare(first,pivot)<0) first+=sz; \
+ while (compare(pivot,last)<0) last-=sz; \
+ if (first<last) { \
+ swapper(first,last); \
+ first+=sz; last-=sz; } \
+ else if (first==last) { first+=sz; last-=sz; break; }\
+ } while (first<=last); \
+}
+
+/* and so is the pre-insertion-sort operation of putting
+ * the smallest element into place as a sentinel.
+ * Doing this makes the inner loop nicer. I got this
+ * idea from the GNU implementation of qsort().
+ * We find the smallest element from the first |nmemb|,
+ * or the first |limit|, whichever is smaller;
+ * therefore we must have ensured that the globally smallest
+ * element is in the first |limit|.
+ */
+#define PreInsertion(swapper,limit,sz) \
+ first=base; \
+ last=first + ((nmemb>limit ? limit : nmemb)-1)*sz;\
+ while (last!=base) { \
+ if (compare(first,last)>0) first=last; \
+ last-=sz; } \
+ if (first!=base) swapper(first,(char*)base);
+
+/* and so is the insertion sort, in the first two cases: */
+#define Insertion(swapper) \
+ last=((char*)base)+nmemb*size; \
+ for (first=((char*)base)+size;first!=last;first+=size) { \
+ char *test; \
+ /* Find the right place for |first|. \
+ * My apologies for var reuse. */ \
+ for (test=first-size;compare(test,first)>0;test-=size) ; \
+ test+=size; \
+ if (test!=first) { \
+ /* Shift everything in [test,first) \
+ * up by one, and place |first| \
+ * where |test| is. */ \
+ memcpy(pivot,first,size); \
+ memmove(test+size,test,first-test); \
+ memcpy(test,pivot,size); \
+ } \
+ }
+
+#define SWAP_nonaligned(a,b) { \
+ register char *aa=(a),*bb=(b); \
+ register size_t sz=size; \
+ do { register char t=*aa; *aa++=*bb; *bb++=t; } while (--sz); }
+
+#define SWAP_aligned(a,b) { \
+ register int *aa=(int*)(a),*bb=(int*)(b); \
+ register size_t sz=size; \
+ do { register int t=*aa;*aa++=*bb; *bb++=t; } while (sz-=WORD_BYTES); }
+
+#define SWAP_words(a,b) { \
+ register int t=*((int*)a); *((int*)a)=*((int*)b); *((int*)b)=t; }
+
+/* ---------------------------------------------------------------------- */
+
+static char * pivot_big(char *first, char *mid, char *last, size_t size,
+ int compare(const void *, const void *)) {
+ size_t d=(((last-first)/size)>>3)*size;
+#ifdef DEBUG_QSORT
+fprintf(stderr, "pivot_big: first=%p last=%p size=%lu n=%lu\n", first, (unsigned long)last, size, (unsigned long)((last-first+1)/size));
+#endif
+ char *m1,*m2,*m3;
+ { char *a=first, *b=first+d, *c=first+2*d;
+#ifdef DEBUG_QSORT
+fprintf(stderr,"< %d %d %d @ %p %p %p\n",*(int*)a,*(int*)b,*(int*)c, a,b,c);
+#endif
+ m1 = compare(a,b)<0 ?
+ (compare(b,c)<0 ? b : (compare(a,c)<0 ? c : a))
+ : (compare(a,c)<0 ? a : (compare(b,c)<0 ? c : b));
+ }
+ { char *a=mid-d, *b=mid, *c=mid+d;
+#ifdef DEBUG_QSORT
+fprintf(stderr,". %d %d %d @ %p %p %p\n",*(int*)a,*(int*)b,*(int*)c, a,b,c);
+#endif
+ m2 = compare(a,b)<0 ?
+ (compare(b,c)<0 ? b : (compare(a,c)<0 ? c : a))
+ : (compare(a,c)<0 ? a : (compare(b,c)<0 ? c : b));
+ }
+ { char *a=last-2*d, *b=last-d, *c=last;
+#ifdef DEBUG_QSORT
+fprintf(stderr,"> %d %d %d @ %p %p %p\n",*(int*)a,*(int*)b,*(int*)c, a,b,c);
+#endif
+ m3 = compare(a,b)<0 ?
+ (compare(b,c)<0 ? b : (compare(a,c)<0 ? c : a))
+ : (compare(a,c)<0 ? a : (compare(b,c)<0 ? c : b));
+ }
+#ifdef DEBUG_QSORT
+fprintf(stderr,"-> %d %d %d @ %p %p %p\n",*(int*)m1,*(int*)m2,*(int*)m3, m1,m2,m3);
+#endif
+ return compare(m1,m2)<0 ?
+ (compare(m2,m3)<0 ? m2 : (compare(m1,m3)<0 ? m3 : m1))
+ : (compare(m1,m3)<0 ? m1 : (compare(m2,m3)<0 ? m3 : m2));
+}
+
+/* ---------------------------------------------------------------------- */
+
+static void qsort_nonaligned(void *base, size_t nmemb, size_t size,
+ int (*compare)(const void *, const void *)) {
+
+ stack_entry stack[STACK_SIZE];
+ int stacktop=0;
+ char *first,*last;
+ char *pivot=malloc(size);
+ size_t trunc=TRUNC_nonaligned*size;
+ assert(pivot!=0);
+
+ first=(char*)base; last=first+(nmemb-1)*size;
+
+ if ((size_t)(last-first)>=trunc) {
+ char *ffirst=first, *llast=last;
+ while (1) {
+ /* Select pivot */
+ { char * mid=first+size*((last-first)/size >> 1);
+ Pivot(SWAP_nonaligned,size);
+ memcpy(pivot,mid,size);
+ }
+ /* Partition. */
+ Partition(SWAP_nonaligned,size);
+ /* Prepare to recurse/iterate. */
+ Recurse(trunc)
+ }
+ }
+ PreInsertion(SWAP_nonaligned,TRUNC_nonaligned,size);
+ Insertion(SWAP_nonaligned);
+ free(pivot);
+}
+
+static void qsort_aligned(void *base, size_t nmemb, size_t size,
+ int (*compare)(const void *, const void *)) {
+
+ stack_entry stack[STACK_SIZE];
+ int stacktop=0;
+ char *first,*last;
+ char *pivot=malloc(size);
+ size_t trunc=TRUNC_aligned*size;
+ assert(pivot!=0);
+
+ first=(char*)base; last=first+(nmemb-1)*size;
+
+ if ((size_t)(last-first)>=trunc) {
+ char *ffirst=first,*llast=last;
+ while (1) {
+ /* Select pivot */
+ { char * mid=first+size*((last-first)/size >> 1);
+ Pivot(SWAP_aligned,size);
+ memcpy(pivot,mid,size);
+ }
+ /* Partition. */
+ Partition(SWAP_aligned,size);
+ /* Prepare to recurse/iterate. */
+ Recurse(trunc)
+ }
+ }
+ PreInsertion(SWAP_aligned,TRUNC_aligned,size);
+ Insertion(SWAP_aligned);
+ free(pivot);
+}
+
+static void qsort_words(void *base, size_t nmemb,
+ int (*compare)(const void *, const void *)) {
+
+ stack_entry stack[STACK_SIZE];
+ int stacktop=0;
+ char *first,*last;
+ char *pivot=malloc(WORD_BYTES);
+ assert(pivot!=0);
+
+ first=(char*)base; last=first+(nmemb-1)*WORD_BYTES;
+
+ if (last-first>=TRUNC_words) {
+ char *ffirst=first, *llast=last;
+ while (1) {
+#ifdef DEBUG_QSORT
+fprintf(stderr,"Doing %d:%d: ",
+ (first-(char*)base)/WORD_BYTES,
+ (last-(char*)base)/WORD_BYTES);
+#endif
+ /* Select pivot */
+ { char * mid=first+WORD_BYTES*((last-first) / (2*WORD_BYTES));
+ Pivot(SWAP_words,WORD_BYTES);
+ *(int*)pivot=*(int*)mid;
+#ifdef DEBUG_QSORT
+fprintf(stderr,"pivot = %p = #%lu = %d\n", mid, (unsigned long)(((int*)mid)-((int*)base)), *(int*)mid);
+#endif
+ }
+ /* Partition. */
+ Partition(SWAP_words,WORD_BYTES);
+#ifdef DEBUG_QSORT
+fprintf(stderr, "after partitioning first=#%lu last=#%lu\n", (first-(char*)base)/4lu, (last-(char*)base)/4lu);
+#endif
+ /* Prepare to recurse/iterate. */
+ Recurse(TRUNC_words)
+ }
+ }
+ PreInsertion(SWAP_words,(TRUNC_words/WORD_BYTES),WORD_BYTES);
+ /* Now do insertion sort. */
+ last=((char*)base)+nmemb*WORD_BYTES;
+ for (first=((char*)base)+WORD_BYTES;first!=last;first+=WORD_BYTES) {
+ /* Find the right place for |first|. My apologies for var reuse */
+ int *pl=(int*)(first-WORD_BYTES),*pr=(int*)first;
+ *(int*)pivot=*(int*)first;
+ for (;compare(pl,pivot)>0;pr=pl,--pl) {
+ *pr=*pl; }
+ if (pr!=(int*)first) *pr=*(int*)pivot;
+ }
+ free(pivot);
+}
+
+/* ---------------------------------------------------------------------- */
+
+extern void qsortG(void *base, size_t nmemb, size_t size,
+ int (*compare)(const void *, const void *)) {
+
+ if (nmemb<=1) return;
+ if (((size_t)base|size)&(WORD_BYTES-1))
+ qsort_nonaligned(base,nmemb,size,compare);
+ else if (size!=WORD_BYTES)
+ qsort_aligned(base,nmemb,size,compare);
+ else
+ qsort_words(base,nmemb,compare);
+}
+
+
+#endif /* HAVE_QSORT */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/stdlib/SDL_stdlib.c b/src/3rdparty/SDL2/src/stdlib/SDL_stdlib.c
new file mode 100644
index 0000000..b36d83c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/stdlib/SDL_stdlib.c
@@ -0,0 +1,1131 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
+#define SDL_DISABLE_ANALYZE_MACROS 1
+#endif
+
+#include "../SDL_internal.h"
+
+/* This file contains portable stdlib functions for SDL */
+
+#include "SDL_stdinc.h"
+#include "../libm/math_libm.h"
+
+
+double
+SDL_atan(double x)
+{
+#if defined(HAVE_ATAN)
+ return atan(x);
+#else
+ return SDL_uclibc_atan(x);
+#endif
+}
+
+float
+SDL_atanf(float x)
+{
+#if defined(HAVE_ATANF)
+ return atanf(x);
+#else
+ return (float)SDL_atan((double)x);
+#endif
+}
+
+double
+SDL_atan2(double x, double y)
+{
+#if defined(HAVE_ATAN2)
+ return atan2(x, y);
+#else
+ return SDL_uclibc_atan2(x, y);
+#endif
+}
+
+float
+SDL_atan2f(float x, float y)
+{
+#if defined(HAVE_ATAN2F)
+ return atan2f(x, y);
+#else
+ return (float)SDL_atan2((double)x, (double)y);
+#endif
+}
+
+double
+SDL_acos(double val)
+{
+#if defined(HAVE_ACOS)
+ return acos(val);
+#else
+ double result;
+ if (val == -1.0) {
+ result = M_PI;
+ } else {
+ result = SDL_atan(SDL_sqrt(1.0 - val * val) / val);
+ if (result < 0.0)
+ {
+ result += M_PI;
+ }
+ }
+ return result;
+#endif
+}
+
+float
+SDL_acosf(float val)
+{
+#if defined(HAVE_ACOSF)
+ return acosf(val);
+#else
+ return (float)SDL_acos((double)val);
+#endif
+}
+
+double
+SDL_asin(double val)
+{
+#if defined(HAVE_ASIN)
+ return asin(val);
+#else
+ double result;
+ if (val == -1.0) {
+ result = -(M_PI / 2.0);
+ } else {
+ result = (M_PI / 2.0) - SDL_acos(val);
+ }
+ return result;
+#endif
+}
+
+float
+SDL_asinf(float val)
+{
+#if defined(HAVE_ASINF)
+ return asinf(val);
+#else
+ return (float)SDL_asin((double)val);
+#endif
+}
+
+double
+SDL_ceil(double x)
+{
+#if defined(HAVE_CEIL)
+ return ceil(x);
+#else
+ double integer = SDL_floor(x);
+ double fraction = x - integer;
+ if (fraction > 0.0) {
+ integer += 1.0;
+ }
+ return integer;
+#endif /* HAVE_CEIL */
+}
+
+float
+SDL_ceilf(float x)
+{
+#if defined(HAVE_CEILF)
+ return ceilf(x);
+#else
+ return (float)SDL_ceil((float)x);
+#endif
+}
+
+double
+SDL_copysign(double x, double y)
+{
+#if defined(HAVE_COPYSIGN)
+ return copysign(x, y);
+#elif defined(HAVE__COPYSIGN)
+ return _copysign(x, y);
+#elif defined(__WATCOMC__) && defined(__386__)
+ /* this is nasty as hell, but it works.. */
+ unsigned int *xi = (unsigned int *) &x,
+ *yi = (unsigned int *) &y;
+ xi[1] = (yi[1] & 0x80000000) | (xi[1] & 0x7fffffff);
+ return x;
+#else
+ return SDL_uclibc_copysign(x, y);
+#endif /* HAVE_COPYSIGN */
+}
+
+float
+SDL_copysignf(float x, float y)
+{
+#if defined(HAVE_COPYSIGNF)
+ return copysignf(x, y);
+#else
+ return (float)SDL_copysign((double)x, (double)y);
+#endif
+}
+
+double
+SDL_cos(double x)
+{
+#if defined(HAVE_COS)
+ return cos(x);
+#else
+ return SDL_uclibc_cos(x);
+#endif
+}
+
+float
+SDL_cosf(float x)
+{
+#if defined(HAVE_COSF)
+ return cosf(x);
+#else
+ return (float)SDL_cos((double)x);
+#endif
+}
+
+double
+SDL_fabs(double x)
+{
+#if defined(HAVE_FABS)
+ return fabs(x);
+#else
+ return SDL_uclibc_fabs(x);
+#endif
+}
+
+float
+SDL_fabsf(float x)
+{
+#if defined(HAVE_FABSF)
+ return fabsf(x);
+#else
+ return (float)SDL_fabs((double)x);
+#endif
+}
+
+double
+SDL_floor(double x)
+{
+#if defined(HAVE_FLOOR)
+ return floor(x);
+#else
+ return SDL_uclibc_floor(x);
+#endif
+}
+
+float
+SDL_floorf(float x)
+{
+#if defined(HAVE_FLOORF)
+ return floorf(x);
+#else
+ return (float)SDL_floor((double)x);
+#endif
+}
+
+double
+SDL_fmod(double x, double y)
+{
+#if defined(HAVE_FMOD)
+ return fmod(x, y);
+#else
+ return SDL_uclibc_fmod(x, y);
+#endif
+}
+
+float
+SDL_fmodf(float x, float y)
+{
+#if defined(HAVE_FMODF)
+ return fmodf(x, y);
+#else
+ return (float)SDL_fmod((double)x, (double)y);
+#endif
+}
+
+double
+SDL_log(double x)
+{
+#if defined(HAVE_LOG)
+ return log(x);
+#else
+ return SDL_uclibc_log(x);
+#endif
+}
+
+float
+SDL_logf(float x)
+{
+#if defined(HAVE_LOGF)
+ return logf(x);
+#else
+ return (float)SDL_log((double)x);
+#endif
+}
+
+double
+SDL_log10(double x)
+{
+#if defined(HAVE_LOG10)
+ return log10(x);
+#else
+ return SDL_uclibc_log10(x);
+#endif
+}
+
+float
+SDL_log10f(float x)
+{
+#if defined(HAVE_LOG10F)
+ return log10f(x);
+#else
+ return (float)SDL_log10((double)x);
+#endif
+}
+
+double
+SDL_pow(double x, double y)
+{
+#if defined(HAVE_POW)
+ return pow(x, y);
+#else
+ return SDL_uclibc_pow(x, y);
+#endif
+}
+
+float
+SDL_powf(float x, float y)
+{
+#if defined(HAVE_POWF)
+ return powf(x, y);
+#else
+ return (float)SDL_pow((double)x, (double)y);
+#endif
+}
+
+double
+SDL_scalbn(double x, int n)
+{
+#if defined(HAVE_SCALBN)
+ return scalbn(x, n);
+#elif defined(HAVE__SCALB)
+ return _scalb(x, n);
+#elif defined(HAVE_LIBC) && defined(HAVE_FLOAT_H) && (FLT_RADIX == 2)
+/* from scalbn(3): If FLT_RADIX equals 2 (which is
+ * usual), then scalbn() is equivalent to ldexp(3). */
+ return ldexp(x, n);
+#else
+ return SDL_uclibc_scalbn(x, n);
+#endif
+}
+
+float
+SDL_scalbnf(float x, int n)
+{
+#if defined(HAVE_SCALBNF)
+ return scalbnf(x, n);
+#else
+ return (float)SDL_scalbn((double)x, n);
+#endif
+}
+
+double
+SDL_sin(double x)
+{
+#if defined(HAVE_SIN)
+ return sin(x);
+#else
+ return SDL_uclibc_sin(x);
+#endif
+}
+
+float
+SDL_sinf(float x)
+{
+#if defined(HAVE_SINF)
+ return sinf(x);
+#else
+ return (float)SDL_sin((double)x);
+#endif
+}
+
+double
+SDL_sqrt(double x)
+{
+#if defined(HAVE_SQRT)
+ return sqrt(x);
+#else
+ return SDL_uclibc_sqrt(x);
+#endif
+}
+
+float
+SDL_sqrtf(float x)
+{
+#if defined(HAVE_SQRTF)
+ return sqrtf(x);
+#else
+ return (float)SDL_sqrt((double)x);
+#endif
+}
+
+double
+SDL_tan(double x)
+{
+#if defined(HAVE_TAN)
+ return tan(x);
+#else
+ return SDL_uclibc_tan(x);
+#endif
+}
+
+float
+SDL_tanf(float x)
+{
+#if defined(HAVE_TANF)
+ return tanf(x);
+#else
+ return (float)SDL_tan((double)x);
+#endif
+}
+
+int SDL_abs(int x)
+{
+#if defined(HAVE_ABS)
+ return abs(x);
+#else
+ return ((x) < 0 ? -(x) : (x));
+#endif
+}
+
+#if defined(HAVE_CTYPE_H)
+int SDL_isdigit(int x) { return isdigit(x); }
+int SDL_isspace(int x) { return isspace(x); }
+int SDL_toupper(int x) { return toupper(x); }
+int SDL_tolower(int x) { return tolower(x); }
+#else
+int SDL_isdigit(int x) { return ((x) >= '0') && ((x) <= '9'); }
+int SDL_isspace(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n') || ((x) == '\f') || ((x) == '\v'); }
+int SDL_toupper(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); }
+int SDL_tolower(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); }
+#endif
+
+
+#ifndef HAVE_LIBC
+/* These are some C runtime intrinsics that need to be defined */
+
+#if defined(_MSC_VER)
+
+#ifndef __FLTUSED__
+#define __FLTUSED__
+__declspec(selectany) int _fltused = 1;
+#endif
+
+/* The optimizer on Visual Studio 2005 and later generates memcpy() calls */
+#if (_MSC_VER >= 1400) && defined(_WIN64) && !defined(_DEBUG) && !(_MSC_VER >= 1900 && defined(_MT))
+#include <intrin.h>
+
+#pragma function(memcpy)
+void * memcpy ( void * destination, const void * source, size_t num )
+{
+ const Uint8 *src = (const Uint8 *)source;
+ Uint8 *dst = (Uint8 *)destination;
+ size_t i;
+
+ /* All WIN64 architectures have SSE, right? */
+ if (!((uintptr_t) src & 15) && !((uintptr_t) dst & 15)) {
+ __m128 values[4];
+ for (i = num / 64; i--;) {
+ _mm_prefetch(src, _MM_HINT_NTA);
+ values[0] = *(__m128 *) (src + 0);
+ values[1] = *(__m128 *) (src + 16);
+ values[2] = *(__m128 *) (src + 32);
+ values[3] = *(__m128 *) (src + 48);
+ _mm_stream_ps((float *) (dst + 0), values[0]);
+ _mm_stream_ps((float *) (dst + 16), values[1]);
+ _mm_stream_ps((float *) (dst + 32), values[2]);
+ _mm_stream_ps((float *) (dst + 48), values[3]);
+ src += 64;
+ dst += 64;
+ }
+ num &= 63;
+ }
+
+ while (num--) {
+ *dst++ = *src++;
+ }
+ return destination;
+}
+#endif /* _MSC_VER == 1600 && defined(_WIN64) && !defined(_DEBUG) */
+
+#ifdef _M_IX86
+
+/* Float to long */
+void
+__declspec(naked)
+_ftol()
+{
+ /* *INDENT-OFF* */
+ __asm {
+ push ebp
+ mov ebp,esp
+ sub esp,20h
+ and esp,0FFFFFFF0h
+ fld st(0)
+ fst dword ptr [esp+18h]
+ fistp qword ptr [esp+10h]
+ fild qword ptr [esp+10h]
+ mov edx,dword ptr [esp+18h]
+ mov eax,dword ptr [esp+10h]
+ test eax,eax
+ je integer_QnaN_or_zero
+arg_is_not_integer_QnaN:
+ fsubp st(1),st
+ test edx,edx
+ jns positive
+ fstp dword ptr [esp]
+ mov ecx,dword ptr [esp]
+ xor ecx,80000000h
+ add ecx,7FFFFFFFh
+ adc eax,0
+ mov edx,dword ptr [esp+14h]
+ adc edx,0
+ jmp localexit
+positive:
+ fstp dword ptr [esp]
+ mov ecx,dword ptr [esp]
+ add ecx,7FFFFFFFh
+ sbb eax,0
+ mov edx,dword ptr [esp+14h]
+ sbb edx,0
+ jmp localexit
+integer_QnaN_or_zero:
+ mov edx,dword ptr [esp+14h]
+ test edx,7FFFFFFFh
+ jne arg_is_not_integer_QnaN
+ fstp dword ptr [esp+18h]
+ fstp dword ptr [esp+18h]
+localexit:
+ leave
+ ret
+ }
+ /* *INDENT-ON* */
+}
+
+void
+_ftol2_sse()
+{
+ _ftol();
+}
+
+/* 64-bit math operators for 32-bit systems */
+void
+__declspec(naked)
+_allmul()
+{
+ /* *INDENT-OFF* */
+ __asm {
+ mov eax, dword ptr[esp+8]
+ mov ecx, dword ptr[esp+10h]
+ or ecx, eax
+ mov ecx, dword ptr[esp+0Ch]
+ jne hard
+ mov eax, dword ptr[esp+4]
+ mul ecx
+ ret 10h
+hard:
+ push ebx
+ mul ecx
+ mov ebx, eax
+ mov eax, dword ptr[esp+8]
+ mul dword ptr[esp+14h]
+ add ebx, eax
+ mov eax, dword ptr[esp+8]
+ mul ecx
+ add edx, ebx
+ pop ebx
+ ret 10h
+ }
+ /* *INDENT-ON* */
+}
+
+void
+__declspec(naked)
+_alldiv()
+{
+ /* *INDENT-OFF* */
+ __asm {
+ push edi
+ push esi
+ push ebx
+ xor edi,edi
+ mov eax,dword ptr [esp+14h]
+ or eax,eax
+ jge L1
+ inc edi
+ mov edx,dword ptr [esp+10h]
+ neg eax
+ neg edx
+ sbb eax,0
+ mov dword ptr [esp+14h],eax
+ mov dword ptr [esp+10h],edx
+L1:
+ mov eax,dword ptr [esp+1Ch]
+ or eax,eax
+ jge L2
+ inc edi
+ mov edx,dword ptr [esp+18h]
+ neg eax
+ neg edx
+ sbb eax,0
+ mov dword ptr [esp+1Ch],eax
+ mov dword ptr [esp+18h],edx
+L2:
+ or eax,eax
+ jne L3
+ mov ecx,dword ptr [esp+18h]
+ mov eax,dword ptr [esp+14h]
+ xor edx,edx
+ div ecx
+ mov ebx,eax
+ mov eax,dword ptr [esp+10h]
+ div ecx
+ mov edx,ebx
+ jmp L4
+L3:
+ mov ebx,eax
+ mov ecx,dword ptr [esp+18h]
+ mov edx,dword ptr [esp+14h]
+ mov eax,dword ptr [esp+10h]
+L5:
+ shr ebx,1
+ rcr ecx,1
+ shr edx,1
+ rcr eax,1
+ or ebx,ebx
+ jne L5
+ div ecx
+ mov esi,eax
+ mul dword ptr [esp+1Ch]
+ mov ecx,eax
+ mov eax,dword ptr [esp+18h]
+ mul esi
+ add edx,ecx
+ jb L6
+ cmp edx,dword ptr [esp+14h]
+ ja L6
+ jb L7
+ cmp eax,dword ptr [esp+10h]
+ jbe L7
+L6:
+ dec esi
+L7:
+ xor edx,edx
+ mov eax,esi
+L4:
+ dec edi
+ jne L8
+ neg edx
+ neg eax
+ sbb edx,0
+L8:
+ pop ebx
+ pop esi
+ pop edi
+ ret 10h
+ }
+ /* *INDENT-ON* */
+}
+
+void
+__declspec(naked)
+_aulldiv()
+{
+ /* *INDENT-OFF* */
+ __asm {
+ push ebx
+ push esi
+ mov eax,dword ptr [esp+18h]
+ or eax,eax
+ jne L1
+ mov ecx,dword ptr [esp+14h]
+ mov eax,dword ptr [esp+10h]
+ xor edx,edx
+ div ecx
+ mov ebx,eax
+ mov eax,dword ptr [esp+0Ch]
+ div ecx
+ mov edx,ebx
+ jmp L2
+L1:
+ mov ecx,eax
+ mov ebx,dword ptr [esp+14h]
+ mov edx,dword ptr [esp+10h]
+ mov eax,dword ptr [esp+0Ch]
+L3:
+ shr ecx,1
+ rcr ebx,1
+ shr edx,1
+ rcr eax,1
+ or ecx,ecx
+ jne L3
+ div ebx
+ mov esi,eax
+ mul dword ptr [esp+18h]
+ mov ecx,eax
+ mov eax,dword ptr [esp+14h]
+ mul esi
+ add edx,ecx
+ jb L4
+ cmp edx,dword ptr [esp+10h]
+ ja L4
+ jb L5
+ cmp eax,dword ptr [esp+0Ch]
+ jbe L5
+L4:
+ dec esi
+L5:
+ xor edx,edx
+ mov eax,esi
+L2:
+ pop esi
+ pop ebx
+ ret 10h
+ }
+ /* *INDENT-ON* */
+}
+
+void
+__declspec(naked)
+_allrem()
+{
+ /* *INDENT-OFF* */
+ __asm {
+ push ebx
+ push edi
+ xor edi,edi
+ mov eax,dword ptr [esp+10h]
+ or eax,eax
+ jge L1
+ inc edi
+ mov edx,dword ptr [esp+0Ch]
+ neg eax
+ neg edx
+ sbb eax,0
+ mov dword ptr [esp+10h],eax
+ mov dword ptr [esp+0Ch],edx
+L1:
+ mov eax,dword ptr [esp+18h]
+ or eax,eax
+ jge L2
+ mov edx,dword ptr [esp+14h]
+ neg eax
+ neg edx
+ sbb eax,0
+ mov dword ptr [esp+18h],eax
+ mov dword ptr [esp+14h],edx
+L2:
+ or eax,eax
+ jne L3
+ mov ecx,dword ptr [esp+14h]
+ mov eax,dword ptr [esp+10h]
+ xor edx,edx
+ div ecx
+ mov eax,dword ptr [esp+0Ch]
+ div ecx
+ mov eax,edx
+ xor edx,edx
+ dec edi
+ jns L4
+ jmp L8
+L3:
+ mov ebx,eax
+ mov ecx,dword ptr [esp+14h]
+ mov edx,dword ptr [esp+10h]
+ mov eax,dword ptr [esp+0Ch]
+L5:
+ shr ebx,1
+ rcr ecx,1
+ shr edx,1
+ rcr eax,1
+ or ebx,ebx
+ jne L5
+ div ecx
+ mov ecx,eax
+ mul dword ptr [esp+18h]
+ xchg eax,ecx
+ mul dword ptr [esp+14h]
+ add edx,ecx
+ jb L6
+ cmp edx,dword ptr [esp+10h]
+ ja L6
+ jb L7
+ cmp eax,dword ptr [esp+0Ch]
+ jbe L7
+L6:
+ sub eax,dword ptr [esp+14h]
+ sbb edx,dword ptr [esp+18h]
+L7:
+ sub eax,dword ptr [esp+0Ch]
+ sbb edx,dword ptr [esp+10h]
+ dec edi
+ jns L8
+L4:
+ neg edx
+ neg eax
+ sbb edx,0
+L8:
+ pop edi
+ pop ebx
+ ret 10h
+ }
+ /* *INDENT-ON* */
+}
+
+void
+__declspec(naked)
+_aullrem()
+{
+ /* *INDENT-OFF* */
+ __asm {
+ push ebx
+ mov eax,dword ptr [esp+14h]
+ or eax,eax
+ jne L1
+ mov ecx,dword ptr [esp+10h]
+ mov eax,dword ptr [esp+0Ch]
+ xor edx,edx
+ div ecx
+ mov eax,dword ptr [esp+8]
+ div ecx
+ mov eax,edx
+ xor edx,edx
+ jmp L2
+L1:
+ mov ecx,eax
+ mov ebx,dword ptr [esp+10h]
+ mov edx,dword ptr [esp+0Ch]
+ mov eax,dword ptr [esp+8]
+L3:
+ shr ecx,1
+ rcr ebx,1
+ shr edx,1
+ rcr eax,1
+ or ecx,ecx
+ jne L3
+ div ebx
+ mov ecx,eax
+ mul dword ptr [esp+14h]
+ xchg eax,ecx
+ mul dword ptr [esp+10h]
+ add edx,ecx
+ jb L4
+ cmp edx,dword ptr [esp+0Ch]
+ ja L4
+ jb L5
+ cmp eax,dword ptr [esp+8]
+ jbe L5
+L4:
+ sub eax,dword ptr [esp+10h]
+ sbb edx,dword ptr [esp+14h]
+L5:
+ sub eax,dword ptr [esp+8]
+ sbb edx,dword ptr [esp+0Ch]
+ neg edx
+ neg eax
+ sbb edx,0
+L2:
+ pop ebx
+ ret 10h
+ }
+ /* *INDENT-ON* */
+}
+
+void
+__declspec(naked)
+_alldvrm()
+{
+ /* *INDENT-OFF* */
+ __asm {
+ push edi
+ push esi
+ push ebp
+ xor edi,edi
+ xor ebp,ebp
+ mov eax,dword ptr [esp+14h]
+ or eax,eax
+ jge L1
+ inc edi
+ inc ebp
+ mov edx,dword ptr [esp+10h]
+ neg eax
+ neg edx
+ sbb eax,0
+ mov dword ptr [esp+14h],eax
+ mov dword ptr [esp+10h],edx
+L1:
+ mov eax,dword ptr [esp+1Ch]
+ or eax,eax
+ jge L2
+ inc edi
+ mov edx,dword ptr [esp+18h]
+ neg eax
+ neg edx
+ sbb eax,0
+ mov dword ptr [esp+1Ch],eax
+ mov dword ptr [esp+18h],edx
+L2:
+ or eax,eax
+ jne L3
+ mov ecx,dword ptr [esp+18h]
+ mov eax,dword ptr [esp+14h]
+ xor edx,edx
+ div ecx
+ mov ebx,eax
+ mov eax,dword ptr [esp+10h]
+ div ecx
+ mov esi,eax
+ mov eax,ebx
+ mul dword ptr [esp+18h]
+ mov ecx,eax
+ mov eax,esi
+ mul dword ptr [esp+18h]
+ add edx,ecx
+ jmp L4
+L3:
+ mov ebx,eax
+ mov ecx,dword ptr [esp+18h]
+ mov edx,dword ptr [esp+14h]
+ mov eax,dword ptr [esp+10h]
+L5:
+ shr ebx,1
+ rcr ecx,1
+ shr edx,1
+ rcr eax,1
+ or ebx,ebx
+ jne L5
+ div ecx
+ mov esi,eax
+ mul dword ptr [esp+1Ch]
+ mov ecx,eax
+ mov eax,dword ptr [esp+18h]
+ mul esi
+ add edx,ecx
+ jb L6
+ cmp edx,dword ptr [esp+14h]
+ ja L6
+ jb L7
+ cmp eax,dword ptr [esp+10h]
+ jbe L7
+L6:
+ dec esi
+ sub eax,dword ptr [esp+18h]
+ sbb edx,dword ptr [esp+1Ch]
+L7:
+ xor ebx,ebx
+L4:
+ sub eax,dword ptr [esp+10h]
+ sbb edx,dword ptr [esp+14h]
+ dec ebp
+ jns L9
+ neg edx
+ neg eax
+ sbb edx,0
+L9:
+ mov ecx,edx
+ mov edx,ebx
+ mov ebx,ecx
+ mov ecx,eax
+ mov eax,esi
+ dec edi
+ jne L8
+ neg edx
+ neg eax
+ sbb edx,0
+L8:
+ pop ebp
+ pop esi
+ pop edi
+ ret 10h
+ }
+ /* *INDENT-ON* */
+}
+
+void
+__declspec(naked)
+_aulldvrm()
+{
+ /* *INDENT-OFF* */
+ __asm {
+ push esi
+ mov eax,dword ptr [esp+14h]
+ or eax,eax
+ jne L1
+ mov ecx,dword ptr [esp+10h]
+ mov eax,dword ptr [esp+0Ch]
+ xor edx,edx
+ div ecx
+ mov ebx,eax
+ mov eax,dword ptr [esp+8]
+ div ecx
+ mov esi,eax
+ mov eax,ebx
+ mul dword ptr [esp+10h]
+ mov ecx,eax
+ mov eax,esi
+ mul dword ptr [esp+10h]
+ add edx,ecx
+ jmp L2
+L1:
+ mov ecx,eax
+ mov ebx,dword ptr [esp+10h]
+ mov edx,dword ptr [esp+0Ch]
+ mov eax,dword ptr [esp+8]
+L3:
+ shr ecx,1
+ rcr ebx,1
+ shr edx,1
+ rcr eax,1
+ or ecx,ecx
+ jne L3
+ div ebx
+ mov esi,eax
+ mul dword ptr [esp+14h]
+ mov ecx,eax
+ mov eax,dword ptr [esp+10h]
+ mul esi
+ add edx,ecx
+ jb L4
+ cmp edx,dword ptr [esp+0Ch]
+ ja L4
+ jb L5
+ cmp eax,dword ptr [esp+8]
+ jbe L5
+L4:
+ dec esi
+ sub eax,dword ptr [esp+10h]
+ sbb edx,dword ptr [esp+14h]
+L5:
+ xor ebx,ebx
+L2:
+ sub eax,dword ptr [esp+8]
+ sbb edx,dword ptr [esp+0Ch]
+ neg edx
+ neg eax
+ sbb edx,0
+ mov ecx,edx
+ mov edx,ebx
+ mov ebx,ecx
+ mov ecx,eax
+ mov eax,esi
+ pop esi
+ ret 10h
+ }
+ /* *INDENT-ON* */
+}
+
+void
+__declspec(naked)
+_allshl()
+{
+ /* *INDENT-OFF* */
+ __asm {
+ cmp cl,40h
+ jae RETZERO
+ cmp cl,20h
+ jae MORE32
+ shld edx,eax,cl
+ shl eax,cl
+ ret
+MORE32:
+ mov edx,eax
+ xor eax,eax
+ and cl,1Fh
+ shl edx,cl
+ ret
+RETZERO:
+ xor eax,eax
+ xor edx,edx
+ ret
+ }
+ /* *INDENT-ON* */
+}
+
+void
+__declspec(naked)
+_allshr()
+{
+ /* *INDENT-OFF* */
+ __asm {
+ cmp cl,3Fh
+ jae RETSIGN
+ cmp cl,20h
+ jae MORE32
+ shrd eax,edx,cl
+ sar edx,cl
+ ret
+MORE32:
+ mov eax,edx
+ sar edx,1Fh
+ and cl,1Fh
+ sar eax,cl
+ ret
+RETSIGN:
+ sar edx,1Fh
+ mov eax,edx
+ ret
+ }
+ /* *INDENT-ON* */
+}
+
+void
+__declspec(naked)
+_aullshr()
+{
+ /* *INDENT-OFF* */
+ __asm {
+ cmp cl,40h
+ jae RETZERO
+ cmp cl,20h
+ jae MORE32
+ shrd eax,edx,cl
+ shr edx,cl
+ ret
+MORE32:
+ mov eax,edx
+ xor edx,edx
+ and cl,1Fh
+ shr eax,cl
+ ret
+RETZERO:
+ xor eax,eax
+ xor edx,edx
+ ret
+ }
+ /* *INDENT-ON* */
+}
+
+#endif /* _M_IX86 */
+
+#endif /* MSC_VER */
+
+#endif /* !HAVE_LIBC */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/stdlib/SDL_string.c b/src/3rdparty/SDL2/src/stdlib/SDL_string.c
new file mode 100644
index 0000000..444ae6d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/stdlib/SDL_string.c
@@ -0,0 +1,1715 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#if defined(__clang_analyzer__)
+#define SDL_DISABLE_ANALYZE_MACROS 1
+#endif
+
+#include "../SDL_internal.h"
+
+/* This file contains portable string manipulation functions for SDL */
+
+#include "SDL_stdinc.h"
+
+#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOL) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOLL) || !defined(HAVE_STRTOULL) || !defined(HAVE_STRTOD)
+#define SDL_isupperhex(X) (((X) >= 'A') && ((X) <= 'F'))
+#define SDL_islowerhex(X) (((X) >= 'a') && ((X) <= 'f'))
+#endif
+
+#define UTF8_IsLeadByte(c) ((c) >= 0xC0 && (c) <= 0xF4)
+#define UTF8_IsTrailingByte(c) ((c) >= 0x80 && (c) <= 0xBF)
+
+static int UTF8_TrailingBytes(unsigned char c)
+{
+ if (c >= 0xC0 && c <= 0xDF)
+ return 1;
+ else if (c >= 0xE0 && c <= 0xEF)
+ return 2;
+ else if (c >= 0xF0 && c <= 0xF4)
+ return 3;
+ else
+ return 0;
+}
+
+#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOL)
+static size_t
+SDL_ScanLong(const char *text, int radix, long *valuep)
+{
+ const char *textstart = text;
+ long value = 0;
+ SDL_bool negative = SDL_FALSE;
+
+ if (*text == '-') {
+ negative = SDL_TRUE;
+ ++text;
+ }
+ if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
+ text += 2;
+ }
+ for (;;) {
+ int v;
+ if (SDL_isdigit((unsigned char) *text)) {
+ v = *text - '0';
+ } else if (radix == 16 && SDL_isupperhex(*text)) {
+ v = 10 + (*text - 'A');
+ } else if (radix == 16 && SDL_islowerhex(*text)) {
+ v = 10 + (*text - 'a');
+ } else {
+ break;
+ }
+ value *= radix;
+ value += v;
+ ++text;
+ }
+ if (valuep && text > textstart) {
+ if (negative && value) {
+ *valuep = -value;
+ } else {
+ *valuep = value;
+ }
+ }
+ return (text - textstart);
+}
+#endif
+
+#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD)
+static size_t
+SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep)
+{
+ const char *textstart = text;
+ unsigned long value = 0;
+
+ if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
+ text += 2;
+ }
+ for (;;) {
+ int v;
+ if (SDL_isdigit((unsigned char) *text)) {
+ v = *text - '0';
+ } else if (radix == 16 && SDL_isupperhex(*text)) {
+ v = 10 + (*text - 'A');
+ } else if (radix == 16 && SDL_islowerhex(*text)) {
+ v = 10 + (*text - 'a');
+ } else {
+ break;
+ }
+ value *= radix;
+ value += v;
+ ++text;
+ }
+ if (valuep && text > textstart) {
+ *valuep = value;
+ }
+ return (text - textstart);
+}
+#endif
+
+#ifndef HAVE_VSSCANF
+static size_t
+SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep)
+{
+ const char *textstart = text;
+ uintptr_t value = 0;
+
+ if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
+ text += 2;
+ }
+ for (;;) {
+ int v;
+ if (SDL_isdigit((unsigned char) *text)) {
+ v = *text - '0';
+ } else if (radix == 16 && SDL_isupperhex(*text)) {
+ v = 10 + (*text - 'A');
+ } else if (radix == 16 && SDL_islowerhex(*text)) {
+ v = 10 + (*text - 'a');
+ } else {
+ break;
+ }
+ value *= radix;
+ value += v;
+ ++text;
+ }
+ if (valuep && text > textstart) {
+ *valuep = value;
+ }
+ return (text - textstart);
+}
+#endif
+
+#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOLL)
+static size_t
+SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep)
+{
+ const char *textstart = text;
+ Sint64 value = 0;
+ SDL_bool negative = SDL_FALSE;
+
+ if (*text == '-') {
+ negative = SDL_TRUE;
+ ++text;
+ }
+ if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
+ text += 2;
+ }
+ for (;;) {
+ int v;
+ if (SDL_isdigit((unsigned char) *text)) {
+ v = *text - '0';
+ } else if (radix == 16 && SDL_isupperhex(*text)) {
+ v = 10 + (*text - 'A');
+ } else if (radix == 16 && SDL_islowerhex(*text)) {
+ v = 10 + (*text - 'a');
+ } else {
+ break;
+ }
+ value *= radix;
+ value += v;
+ ++text;
+ }
+ if (valuep && text > textstart) {
+ if (negative && value) {
+ *valuep = -value;
+ } else {
+ *valuep = value;
+ }
+ }
+ return (text - textstart);
+}
+#endif
+
+#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOULL)
+static size_t
+SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep)
+{
+ const char *textstart = text;
+ Uint64 value = 0;
+
+ if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
+ text += 2;
+ }
+ for (;;) {
+ int v;
+ if (SDL_isdigit((unsigned char) *text)) {
+ v = *text - '0';
+ } else if (radix == 16 && SDL_isupperhex(*text)) {
+ v = 10 + (*text - 'A');
+ } else if (radix == 16 && SDL_islowerhex(*text)) {
+ v = 10 + (*text - 'a');
+ } else {
+ break;
+ }
+ value *= radix;
+ value += v;
+ ++text;
+ }
+ if (valuep && text > textstart) {
+ *valuep = value;
+ }
+ return (text - textstart);
+}
+#endif
+
+#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOD)
+static size_t
+SDL_ScanFloat(const char *text, double *valuep)
+{
+ const char *textstart = text;
+ unsigned long lvalue = 0;
+ double value = 0.0;
+ SDL_bool negative = SDL_FALSE;
+
+ if (*text == '-') {
+ negative = SDL_TRUE;
+ ++text;
+ }
+ text += SDL_ScanUnsignedLong(text, 10, &lvalue);
+ value += lvalue;
+ if (*text == '.') {
+ int mult = 10;
+ ++text;
+ while (SDL_isdigit((unsigned char) *text)) {
+ lvalue = *text - '0';
+ value += (double) lvalue / mult;
+ mult *= 10;
+ ++text;
+ }
+ }
+ if (valuep && text > textstart) {
+ if (negative && value) {
+ *valuep = -value;
+ } else {
+ *valuep = value;
+ }
+ }
+ return (text - textstart);
+}
+#endif
+
+void *
+SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
+{
+#if defined(HAVE_MEMSET)
+ return memset(dst, c, len);
+#else
+ size_t left;
+ Uint32 *dstp4;
+ Uint8 *dstp1 = (Uint8 *) dst;
+ Uint32 value4 = (c | (c << 8) | (c << 16) | (c << 24));
+ Uint8 value1 = (Uint8) c;
+
+ /* The destination pointer needs to be aligned on a 4-byte boundary to
+ * execute a 32-bit set. Set first bytes manually if needed until it is
+ * aligned. */
+ while ((intptr_t)dstp1 & 0x3) {
+ if (len--) {
+ *dstp1++ = value1;
+ } else {
+ return dst;
+ }
+ }
+
+ dstp4 = (Uint32 *) dstp1;
+ left = (len % 4);
+ len /= 4;
+ while (len--) {
+ *dstp4++ = value4;
+ }
+
+ dstp1 = (Uint8 *) dstp4;
+ switch (left) {
+ case 3:
+ *dstp1++ = value1;
+ case 2:
+ *dstp1++ = value1;
+ case 1:
+ *dstp1++ = value1;
+ }
+
+ return dst;
+#endif /* HAVE_MEMSET */
+}
+
+void *
+SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
+{
+#ifdef __GNUC__
+ /* Presumably this is well tuned for speed.
+ On my machine this is twice as fast as the C code below.
+ */
+ return __builtin_memcpy(dst, src, len);
+#elif defined(HAVE_MEMCPY)
+ return memcpy(dst, src, len);
+#elif defined(HAVE_BCOPY)
+ bcopy(src, dst, len);
+ return dst;
+#else
+ /* GCC 4.9.0 with -O3 will generate movaps instructions with the loop
+ using Uint32* pointers, so we need to make sure the pointers are
+ aligned before we loop using them.
+ */
+ if (((intptr_t)src & 0x3) || ((intptr_t)dst & 0x3)) {
+ /* Do an unaligned byte copy */
+ Uint8 *srcp1 = (Uint8 *)src;
+ Uint8 *dstp1 = (Uint8 *)dst;
+
+ while (len--) {
+ *dstp1++ = *srcp1++;
+ }
+ } else {
+ size_t left = (len % 4);
+ Uint32 *srcp4, *dstp4;
+ Uint8 *srcp1, *dstp1;
+
+ srcp4 = (Uint32 *) src;
+ dstp4 = (Uint32 *) dst;
+ len /= 4;
+ while (len--) {
+ *dstp4++ = *srcp4++;
+ }
+
+ srcp1 = (Uint8 *) srcp4;
+ dstp1 = (Uint8 *) dstp4;
+ switch (left) {
+ case 3:
+ *dstp1++ = *srcp1++;
+ case 2:
+ *dstp1++ = *srcp1++;
+ case 1:
+ *dstp1++ = *srcp1++;
+ }
+ }
+ return dst;
+#endif /* __GNUC__ */
+}
+
+void *
+SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
+{
+#if defined(HAVE_MEMMOVE)
+ return memmove(dst, src, len);
+#else
+ char *srcp = (char *) src;
+ char *dstp = (char *) dst;
+
+ if (src < dst) {
+ srcp += len - 1;
+ dstp += len - 1;
+ while (len--) {
+ *dstp-- = *srcp--;
+ }
+ } else {
+ while (len--) {
+ *dstp++ = *srcp++;
+ }
+ }
+ return dst;
+#endif /* HAVE_MEMMOVE */
+}
+
+int
+SDL_memcmp(const void *s1, const void *s2, size_t len)
+{
+#if defined(HAVE_MEMCMP)
+ return memcmp(s1, s2, len);
+#else
+ char *s1p = (char *) s1;
+ char *s2p = (char *) s2;
+ while (len--) {
+ if (*s1p != *s2p) {
+ return (*s1p - *s2p);
+ }
+ ++s1p;
+ ++s2p;
+ }
+ return 0;
+#endif /* HAVE_MEMCMP */
+}
+
+size_t
+SDL_strlen(const char *string)
+{
+#if defined(HAVE_STRLEN)
+ return strlen(string);
+#else
+ size_t len = 0;
+ while (*string++) {
+ ++len;
+ }
+ return len;
+#endif /* HAVE_STRLEN */
+}
+
+size_t
+SDL_wcslen(const wchar_t * string)
+{
+#if defined(HAVE_WCSLEN)
+ return wcslen(string);
+#else
+ size_t len = 0;
+ while (*string++) {
+ ++len;
+ }
+ return len;
+#endif /* HAVE_WCSLEN */
+}
+
+size_t
+SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
+{
+#if defined(HAVE_WCSLCPY)
+ return wcslcpy(dst, src, maxlen);
+#else
+ size_t srclen = SDL_wcslen(src);
+ if (maxlen > 0) {
+ size_t len = SDL_min(srclen, maxlen - 1);
+ SDL_memcpy(dst, src, len * sizeof(wchar_t));
+ dst[len] = '\0';
+ }
+ return srclen;
+#endif /* HAVE_WCSLCPY */
+}
+
+size_t
+SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
+{
+#if defined(HAVE_WCSLCAT)
+ return wcslcat(dst, src, maxlen);
+#else
+ size_t dstlen = SDL_wcslen(dst);
+ size_t srclen = SDL_wcslen(src);
+ if (dstlen < maxlen) {
+ SDL_wcslcpy(dst + dstlen, src, maxlen - dstlen);
+ }
+ return dstlen + srclen;
+#endif /* HAVE_WCSLCAT */
+}
+
+int
+SDL_wcscmp(const wchar_t *str1, const wchar_t *str2)
+{
+#if defined(HAVE_WCSCMP)
+ return wcscmp(str1, str2);
+#else
+ while (*str1 && *str2) {
+ if (*str1 != *str2)
+ break;
+ ++str1;
+ ++str2;
+ }
+ return (int)(*str1 - *str2);
+#endif /* HAVE_WCSCMP */
+}
+
+size_t
+SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
+{
+#if defined(HAVE_STRLCPY)
+ return strlcpy(dst, src, maxlen);
+#else
+ size_t srclen = SDL_strlen(src);
+ if (maxlen > 0) {
+ size_t len = SDL_min(srclen, maxlen - 1);
+ SDL_memcpy(dst, src, len);
+ dst[len] = '\0';
+ }
+ return srclen;
+#endif /* HAVE_STRLCPY */
+}
+
+size_t
+SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
+{
+ size_t src_bytes = SDL_strlen(src);
+ size_t bytes = SDL_min(src_bytes, dst_bytes - 1);
+ size_t i = 0;
+ char trailing_bytes = 0;
+ if (bytes)
+ {
+ unsigned char c = (unsigned char)src[bytes - 1];
+ if (UTF8_IsLeadByte(c))
+ --bytes;
+ else if (UTF8_IsTrailingByte(c))
+ {
+ for (i = bytes - 1; i != 0; --i)
+ {
+ c = (unsigned char)src[i];
+ trailing_bytes = UTF8_TrailingBytes(c);
+ if (trailing_bytes)
+ {
+ if (bytes - i != trailing_bytes + 1)
+ bytes = i;
+
+ break;
+ }
+ }
+ }
+ SDL_memcpy(dst, src, bytes);
+ }
+ dst[bytes] = '\0';
+ return bytes;
+}
+
+size_t
+SDL_utf8strlen(const char *str)
+{
+ size_t retval = 0;
+ const char *p = str;
+ char ch;
+
+ while ((ch = *(p++))) {
+ /* if top two bits are 1 and 0, it's a continuation byte. */
+ if ((ch & 0xc0) != 0x80) {
+ retval++;
+ }
+ }
+
+ return retval;
+}
+
+size_t
+SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
+{
+#if defined(HAVE_STRLCAT)
+ return strlcat(dst, src, maxlen);
+#else
+ size_t dstlen = SDL_strlen(dst);
+ size_t srclen = SDL_strlen(src);
+ if (dstlen < maxlen) {
+ SDL_strlcpy(dst + dstlen, src, maxlen - dstlen);
+ }
+ return dstlen + srclen;
+#endif /* HAVE_STRLCAT */
+}
+
+char *
+SDL_strdup(const char *string)
+{
+ size_t len = SDL_strlen(string) + 1;
+ char *newstr = SDL_malloc(len);
+ if (newstr) {
+ SDL_memcpy(newstr, string, len);
+ }
+ return newstr;
+}
+
+char *
+SDL_strrev(char *string)
+{
+#if defined(HAVE__STRREV)
+ return _strrev(string);
+#else
+ size_t len = SDL_strlen(string);
+ char *a = &string[0];
+ char *b = &string[len - 1];
+ len /= 2;
+ while (len--) {
+ char c = *a;
+ *a++ = *b;
+ *b-- = c;
+ }
+ return string;
+#endif /* HAVE__STRREV */
+}
+
+char *
+SDL_strupr(char *string)
+{
+#if defined(HAVE__STRUPR)
+ return _strupr(string);
+#else
+ char *bufp = string;
+ while (*bufp) {
+ *bufp = SDL_toupper((unsigned char) *bufp);
+ ++bufp;
+ }
+ return string;
+#endif /* HAVE__STRUPR */
+}
+
+char *
+SDL_strlwr(char *string)
+{
+#if defined(HAVE__STRLWR)
+ return _strlwr(string);
+#else
+ char *bufp = string;
+ while (*bufp) {
+ *bufp = SDL_tolower((unsigned char) *bufp);
+ ++bufp;
+ }
+ return string;
+#endif /* HAVE__STRLWR */
+}
+
+char *
+SDL_strchr(const char *string, int c)
+{
+#ifdef HAVE_STRCHR
+ return SDL_const_cast(char*,strchr(string, c));
+#elif defined(HAVE_INDEX)
+ return SDL_const_cast(char*,index(string, c));
+#else
+ while (*string) {
+ if (*string == c) {
+ return (char *) string;
+ }
+ ++string;
+ }
+ return NULL;
+#endif /* HAVE_STRCHR */
+}
+
+char *
+SDL_strrchr(const char *string, int c)
+{
+#ifdef HAVE_STRRCHR
+ return SDL_const_cast(char*,strrchr(string, c));
+#elif defined(HAVE_RINDEX)
+ return SDL_const_cast(char*,rindex(string, c));
+#else
+ const char *bufp = string + SDL_strlen(string) - 1;
+ while (bufp >= string) {
+ if (*bufp == c) {
+ return (char *) bufp;
+ }
+ --bufp;
+ }
+ return NULL;
+#endif /* HAVE_STRRCHR */
+}
+
+char *
+SDL_strstr(const char *haystack, const char *needle)
+{
+#if defined(HAVE_STRSTR)
+ return SDL_const_cast(char*,strstr(haystack, needle));
+#else
+ size_t length = SDL_strlen(needle);
+ while (*haystack) {
+ if (SDL_strncmp(haystack, needle, length) == 0) {
+ return (char *) haystack;
+ }
+ ++haystack;
+ }
+ return NULL;
+#endif /* HAVE_STRSTR */
+}
+
+#if !defined(HAVE__LTOA) || !defined(HAVE__I64TOA) || \
+ !defined(HAVE__ULTOA) || !defined(HAVE__UI64TOA)
+static const char ntoa_table[] = {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
+ 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
+ 'U', 'V', 'W', 'X', 'Y', 'Z'
+};
+#endif /* ntoa() conversion table */
+
+char *
+SDL_itoa(int value, char *string, int radix)
+{
+#ifdef HAVE_ITOA
+ return itoa(value, string, radix);
+#else
+ return SDL_ltoa((long)value, string, radix);
+#endif /* HAVE_ITOA */
+}
+
+char *
+SDL_uitoa(unsigned int value, char *string, int radix)
+{
+#ifdef HAVE__UITOA
+ return _uitoa(value, string, radix);
+#else
+ return SDL_ultoa((unsigned long)value, string, radix);
+#endif /* HAVE__UITOA */
+}
+
+char *
+SDL_ltoa(long value, char *string, int radix)
+{
+#if defined(HAVE__LTOA)
+ return _ltoa(value, string, radix);
+#else
+ char *bufp = string;
+
+ if (value < 0) {
+ *bufp++ = '-';
+ SDL_ultoa(-value, bufp, radix);
+ } else {
+ SDL_ultoa(value, bufp, radix);
+ }
+
+ return string;
+#endif /* HAVE__LTOA */
+}
+
+char *
+SDL_ultoa(unsigned long value, char *string, int radix)
+{
+#if defined(HAVE__ULTOA)
+ return _ultoa(value, string, radix);
+#else
+ char *bufp = string;
+
+ if (value) {
+ while (value > 0) {
+ *bufp++ = ntoa_table[value % radix];
+ value /= radix;
+ }
+ } else {
+ *bufp++ = '0';
+ }
+ *bufp = '\0';
+
+ /* The numbers went into the string backwards. :) */
+ SDL_strrev(string);
+
+ return string;
+#endif /* HAVE__ULTOA */
+}
+
+char *
+SDL_lltoa(Sint64 value, char *string, int radix)
+{
+#if defined(HAVE__I64TOA)
+ return _i64toa(value, string, radix);
+#else
+ char *bufp = string;
+
+ if (value < 0) {
+ *bufp++ = '-';
+ SDL_ulltoa(-value, bufp, radix);
+ } else {
+ SDL_ulltoa(value, bufp, radix);
+ }
+
+ return string;
+#endif /* HAVE__I64TOA */
+}
+
+char *
+SDL_ulltoa(Uint64 value, char *string, int radix)
+{
+#if defined(HAVE__UI64TOA)
+ return _ui64toa(value, string, radix);
+#else
+ char *bufp = string;
+
+ if (value) {
+ while (value > 0) {
+ *bufp++ = ntoa_table[value % radix];
+ value /= radix;
+ }
+ } else {
+ *bufp++ = '0';
+ }
+ *bufp = '\0';
+
+ /* The numbers went into the string backwards. :) */
+ SDL_strrev(string);
+
+ return string;
+#endif /* HAVE__UI64TOA */
+}
+
+int SDL_atoi(const char *string)
+{
+#ifdef HAVE_ATOI
+ return atoi(string);
+#else
+ return SDL_strtol(string, NULL, 0);
+#endif /* HAVE_ATOI */
+}
+
+double SDL_atof(const char *string)
+{
+#ifdef HAVE_ATOF
+ return (double) atof(string);
+#else
+ return SDL_strtod(string, NULL);
+#endif /* HAVE_ATOF */
+}
+
+long
+SDL_strtol(const char *string, char **endp, int base)
+{
+#if defined(HAVE_STRTOL)
+ return strtol(string, endp, base);
+#else
+ size_t len;
+ long value = 0;
+
+ if (!base) {
+ if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
+ base = 16;
+ } else {
+ base = 10;
+ }
+ }
+
+ len = SDL_ScanLong(string, base, &value);
+ if (endp) {
+ *endp = (char *) string + len;
+ }
+ return value;
+#endif /* HAVE_STRTOL */
+}
+
+unsigned long
+SDL_strtoul(const char *string, char **endp, int base)
+{
+#if defined(HAVE_STRTOUL)
+ return strtoul(string, endp, base);
+#else
+ size_t len;
+ unsigned long value = 0;
+
+ if (!base) {
+ if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
+ base = 16;
+ } else {
+ base = 10;
+ }
+ }
+
+ len = SDL_ScanUnsignedLong(string, base, &value);
+ if (endp) {
+ *endp = (char *) string + len;
+ }
+ return value;
+#endif /* HAVE_STRTOUL */
+}
+
+Sint64
+SDL_strtoll(const char *string, char **endp, int base)
+{
+#if defined(HAVE_STRTOLL)
+ return strtoll(string, endp, base);
+#else
+ size_t len;
+ Sint64 value = 0;
+
+ if (!base) {
+ if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
+ base = 16;
+ } else {
+ base = 10;
+ }
+ }
+
+ len = SDL_ScanLongLong(string, base, &value);
+ if (endp) {
+ *endp = (char *) string + len;
+ }
+ return value;
+#endif /* HAVE_STRTOLL */
+}
+
+Uint64
+SDL_strtoull(const char *string, char **endp, int base)
+{
+#if defined(HAVE_STRTOULL)
+ return strtoull(string, endp, base);
+#else
+ size_t len;
+ Uint64 value = 0;
+
+ if (!base) {
+ if ((SDL_strlen(string) > 2) && (SDL_strncmp(string, "0x", 2) == 0)) {
+ base = 16;
+ } else {
+ base = 10;
+ }
+ }
+
+ len = SDL_ScanUnsignedLongLong(string, base, &value);
+ if (endp) {
+ *endp = (char *) string + len;
+ }
+ return value;
+#endif /* HAVE_STRTOULL */
+}
+
+double
+SDL_strtod(const char *string, char **endp)
+{
+#if defined(HAVE_STRTOD)
+ return strtod(string, endp);
+#else
+ size_t len;
+ double value = 0.0;
+
+ len = SDL_ScanFloat(string, &value);
+ if (endp) {
+ *endp = (char *) string + len;
+ }
+ return value;
+#endif /* HAVE_STRTOD */
+}
+
+int
+SDL_strcmp(const char *str1, const char *str2)
+{
+#if defined(HAVE_STRCMP)
+ return strcmp(str1, str2);
+#else
+ while (*str1 && *str2) {
+ if (*str1 != *str2)
+ break;
+ ++str1;
+ ++str2;
+ }
+ return (int)((unsigned char) *str1 - (unsigned char) *str2);
+#endif /* HAVE_STRCMP */
+}
+
+int
+SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
+{
+#if defined(HAVE_STRNCMP)
+ return strncmp(str1, str2, maxlen);
+#else
+ while (*str1 && *str2 && maxlen) {
+ if (*str1 != *str2)
+ break;
+ ++str1;
+ ++str2;
+ --maxlen;
+ }
+ if (!maxlen) {
+ return 0;
+ }
+ return (int) ((unsigned char) *str1 - (unsigned char) *str2);
+#endif /* HAVE_STRNCMP */
+}
+
+int
+SDL_strcasecmp(const char *str1, const char *str2)
+{
+#ifdef HAVE_STRCASECMP
+ return strcasecmp(str1, str2);
+#elif defined(HAVE__STRICMP)
+ return _stricmp(str1, str2);
+#else
+ char a = 0;
+ char b = 0;
+ while (*str1 && *str2) {
+ a = SDL_toupper((unsigned char) *str1);
+ b = SDL_toupper((unsigned char) *str2);
+ if (a != b)
+ break;
+ ++str1;
+ ++str2;
+ }
+ a = SDL_toupper(*str1);
+ b = SDL_toupper(*str2);
+ return (int) ((unsigned char) a - (unsigned char) b);
+#endif /* HAVE_STRCASECMP */
+}
+
+int
+SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
+{
+#ifdef HAVE_STRNCASECMP
+ return strncasecmp(str1, str2, maxlen);
+#elif defined(HAVE__STRNICMP)
+ return _strnicmp(str1, str2, maxlen);
+#else
+ char a = 0;
+ char b = 0;
+ while (*str1 && *str2 && maxlen) {
+ a = SDL_tolower((unsigned char) *str1);
+ b = SDL_tolower((unsigned char) *str2);
+ if (a != b)
+ break;
+ ++str1;
+ ++str2;
+ --maxlen;
+ }
+ if (maxlen == 0) {
+ return 0;
+ } else {
+ a = SDL_tolower((unsigned char) *str1);
+ b = SDL_tolower((unsigned char) *str2);
+ return (int) ((unsigned char) a - (unsigned char) b);
+ }
+#endif /* HAVE_STRNCASECMP */
+}
+
+int
+SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...)
+{
+ int rc;
+ va_list ap;
+ va_start(ap, fmt);
+ rc = SDL_vsscanf(text, fmt, ap);
+ va_end(ap);
+ return rc;
+}
+
+#ifdef HAVE_VSSCANF
+int
+SDL_vsscanf(const char *text, const char *fmt, va_list ap)
+{
+ return vsscanf(text, fmt, ap);
+}
+#else
+int
+SDL_vsscanf(const char *text, const char *fmt, va_list ap)
+{
+ int retval = 0;
+
+ if (!text || !*text) {
+ return -1;
+ }
+
+ while (*fmt) {
+ if (*fmt == ' ') {
+ while (SDL_isspace((unsigned char) *text)) {
+ ++text;
+ }
+ ++fmt;
+ continue;
+ }
+ if (*fmt == '%') {
+ SDL_bool done = SDL_FALSE;
+ long count = 0;
+ int radix = 10;
+ enum
+ {
+ DO_SHORT,
+ DO_INT,
+ DO_LONG,
+ DO_LONGLONG
+ } inttype = DO_INT;
+ size_t advance;
+ SDL_bool suppress = SDL_FALSE;
+
+ ++fmt;
+ if (*fmt == '%') {
+ if (*text == '%') {
+ ++text;
+ ++fmt;
+ continue;
+ }
+ break;
+ }
+ if (*fmt == '*') {
+ suppress = SDL_TRUE;
+ ++fmt;
+ }
+ fmt += SDL_ScanLong(fmt, 10, &count);
+
+ if (*fmt == 'c') {
+ if (!count) {
+ count = 1;
+ }
+ if (suppress) {
+ while (count--) {
+ ++text;
+ }
+ } else {
+ char *valuep = va_arg(ap, char *);
+ while (count--) {
+ *valuep++ = *text++;
+ }
+ ++retval;
+ }
+ continue;
+ }
+
+ while (SDL_isspace((unsigned char) *text)) {
+ ++text;
+ }
+
+ /* FIXME: implement more of the format specifiers */
+ while (!done) {
+ switch (*fmt) {
+ case '*':
+ suppress = SDL_TRUE;
+ break;
+ case 'h':
+ if (inttype > DO_SHORT) {
+ ++inttype;
+ }
+ break;
+ case 'l':
+ if (inttype < DO_LONGLONG) {
+ ++inttype;
+ }
+ break;
+ case 'I':
+ if (SDL_strncmp(fmt, "I64", 3) == 0) {
+ fmt += 2;
+ inttype = DO_LONGLONG;
+ }
+ break;
+ case 'i':
+ {
+ int index = 0;
+ if (text[index] == '-') {
+ ++index;
+ }
+ if (text[index] == '0') {
+ if (SDL_tolower((unsigned char) text[index + 1]) == 'x') {
+ radix = 16;
+ } else {
+ radix = 8;
+ }
+ }
+ }
+ /* Fall through to %d handling */
+ case 'd':
+ if (inttype == DO_LONGLONG) {
+ Sint64 value;
+ advance = SDL_ScanLongLong(text, radix, &value);
+ text += advance;
+ if (advance && !suppress) {
+ Sint64 *valuep = va_arg(ap, Sint64 *);
+ *valuep = value;
+ ++retval;
+ }
+ } else {
+ long value;
+ advance = SDL_ScanLong(text, radix, &value);
+ text += advance;
+ if (advance && !suppress) {
+ switch (inttype) {
+ case DO_SHORT:
+ {
+ short *valuep = va_arg(ap, short *);
+ *valuep = (short) value;
+ }
+ break;
+ case DO_INT:
+ {
+ int *valuep = va_arg(ap, int *);
+ *valuep = (int) value;
+ }
+ break;
+ case DO_LONG:
+ {
+ long *valuep = va_arg(ap, long *);
+ *valuep = value;
+ }
+ break;
+ case DO_LONGLONG:
+ /* Handled above */
+ break;
+ }
+ ++retval;
+ }
+ }
+ done = SDL_TRUE;
+ break;
+ case 'o':
+ if (radix == 10) {
+ radix = 8;
+ }
+ /* Fall through to unsigned handling */
+ case 'x':
+ case 'X':
+ if (radix == 10) {
+ radix = 16;
+ }
+ /* Fall through to unsigned handling */
+ case 'u':
+ if (inttype == DO_LONGLONG) {
+ Uint64 value = 0;
+ advance = SDL_ScanUnsignedLongLong(text, radix, &value);
+ text += advance;
+ if (advance && !suppress) {
+ Uint64 *valuep = va_arg(ap, Uint64 *);
+ *valuep = value;
+ ++retval;
+ }
+ } else {
+ unsigned long value = 0;
+ advance = SDL_ScanUnsignedLong(text, radix, &value);
+ text += advance;
+ if (advance && !suppress) {
+ switch (inttype) {
+ case DO_SHORT:
+ {
+ short *valuep = va_arg(ap, short *);
+ *valuep = (short) value;
+ }
+ break;
+ case DO_INT:
+ {
+ int *valuep = va_arg(ap, int *);
+ *valuep = (int) value;
+ }
+ break;
+ case DO_LONG:
+ {
+ long *valuep = va_arg(ap, long *);
+ *valuep = value;
+ }
+ break;
+ case DO_LONGLONG:
+ /* Handled above */
+ break;
+ }
+ ++retval;
+ }
+ }
+ done = SDL_TRUE;
+ break;
+ case 'p':
+ {
+ uintptr_t value = 0;
+ advance = SDL_ScanUintPtrT(text, 16, &value);
+ text += advance;
+ if (advance && !suppress) {
+ void **valuep = va_arg(ap, void **);
+ *valuep = (void *) value;
+ ++retval;
+ }
+ }
+ done = SDL_TRUE;
+ break;
+ case 'f':
+ {
+ double value;
+ advance = SDL_ScanFloat(text, &value);
+ text += advance;
+ if (advance && !suppress) {
+ float *valuep = va_arg(ap, float *);
+ *valuep = (float) value;
+ ++retval;
+ }
+ }
+ done = SDL_TRUE;
+ break;
+ case 's':
+ if (suppress) {
+ while (!SDL_isspace((unsigned char) *text)) {
+ ++text;
+ if (count) {
+ if (--count == 0) {
+ break;
+ }
+ }
+ }
+ } else {
+ char *valuep = va_arg(ap, char *);
+ while (!SDL_isspace((unsigned char) *text)) {
+ *valuep++ = *text++;
+ if (count) {
+ if (--count == 0) {
+ break;
+ }
+ }
+ }
+ *valuep = '\0';
+ ++retval;
+ }
+ done = SDL_TRUE;
+ break;
+ default:
+ done = SDL_TRUE;
+ break;
+ }
+ ++fmt;
+ }
+ continue;
+ }
+ if (*text == *fmt) {
+ ++text;
+ ++fmt;
+ continue;
+ }
+ /* Text didn't match format specifier */
+ break;
+ }
+
+ return retval;
+}
+#endif /* HAVE_VSSCANF */
+
+int
+SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+ va_list ap;
+ int retval;
+
+ va_start(ap, fmt);
+ retval = SDL_vsnprintf(text, maxlen, fmt, ap);
+ va_end(ap);
+
+ return retval;
+}
+
+#ifdef HAVE_VSNPRINTF
+int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
+{
+ if (!fmt) {
+ fmt = "";
+ }
+ return vsnprintf(text, maxlen, fmt, ap);
+}
+#else
+ /* FIXME: implement more of the format specifiers */
+typedef enum
+{
+ SDL_CASE_NOCHANGE,
+ SDL_CASE_LOWER,
+ SDL_CASE_UPPER
+} SDL_letter_case;
+
+typedef struct
+{
+ SDL_bool left_justify;
+ SDL_bool force_sign;
+ SDL_bool force_type;
+ SDL_bool pad_zeroes;
+ SDL_letter_case force_case;
+ int width;
+ int radix;
+ int precision;
+} SDL_FormatInfo;
+
+static size_t
+SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *string)
+{
+ size_t length = 0;
+ size_t slen;
+
+ if (string == NULL) {
+ string = "(null)";
+ }
+
+ if (info && info->width && (size_t)info->width > SDL_strlen(string)) {
+ char fill = info->pad_zeroes ? '0' : ' ';
+ size_t width = info->width - SDL_strlen(string);
+ while (width-- > 0 && maxlen > 0) {
+ *text++ = fill;
+ ++length;
+ --maxlen;
+ }
+ }
+
+ slen = SDL_strlcpy(text, string, maxlen);
+ length += SDL_min(slen, maxlen);
+
+ if (info) {
+ if (info->force_case == SDL_CASE_LOWER) {
+ SDL_strlwr(text);
+ } else if (info->force_case == SDL_CASE_UPPER) {
+ SDL_strupr(text);
+ }
+ }
+ return length;
+}
+
+static size_t
+SDL_PrintLong(char *text, size_t maxlen, SDL_FormatInfo *info, long value)
+{
+ char num[130];
+
+ SDL_ltoa(value, num, info ? info->radix : 10);
+ return SDL_PrintString(text, maxlen, info, num);
+}
+
+static size_t
+SDL_PrintUnsignedLong(char *text, size_t maxlen, SDL_FormatInfo *info, unsigned long value)
+{
+ char num[130];
+
+ SDL_ultoa(value, num, info ? info->radix : 10);
+ return SDL_PrintString(text, maxlen, info, num);
+}
+
+static size_t
+SDL_PrintLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Sint64 value)
+{
+ char num[130];
+
+ SDL_lltoa(value, num, info ? info->radix : 10);
+ return SDL_PrintString(text, maxlen, info, num);
+}
+
+static size_t
+SDL_PrintUnsignedLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Uint64 value)
+{
+ char num[130];
+
+ SDL_ulltoa(value, num, info ? info->radix : 10);
+ return SDL_PrintString(text, maxlen, info, num);
+}
+
+static size_t
+SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, double arg)
+{
+ int width;
+ size_t len;
+ size_t left = maxlen;
+ char *textstart = text;
+
+ if (arg) {
+ /* This isn't especially accurate, but hey, it's easy. :) */
+ unsigned long value;
+
+ if (arg < 0) {
+ if (left > 1) {
+ *text = '-';
+ --left;
+ }
+ ++text;
+ arg = -arg;
+ } else if (info->force_sign) {
+ if (left > 1) {
+ *text = '+';
+ --left;
+ }
+ ++text;
+ }
+ value = (unsigned long) arg;
+ len = SDL_PrintUnsignedLong(text, left, NULL, value);
+ if (len >= left) {
+ text += (left > 1) ? left - 1 : 0;
+ left = SDL_min(left, 1);
+ } else {
+ text += len;
+ left -= len;
+ }
+ arg -= value;
+ if (info->precision < 0) {
+ info->precision = 6;
+ }
+ if (info->force_type || info->precision > 0) {
+ int mult = 10;
+ if (left > 1) {
+ *text = '.';
+ --left;
+ }
+ ++text;
+ while (info->precision-- > 0) {
+ value = (unsigned long) (arg * mult);
+ len = SDL_PrintUnsignedLong(text, left, NULL, value);
+ if (len >= left) {
+ text += (left > 1) ? left - 1 : 0;
+ left = SDL_min(left, 1);
+ } else {
+ text += len;
+ left -= len;
+ }
+ arg -= (double) value / mult;
+ mult *= 10;
+ }
+ }
+ } else {
+ if (left > 1) {
+ *text = '0';
+ --left;
+ }
+ ++text;
+ if (info->force_type) {
+ if (left > 1) {
+ *text = '.';
+ --left;
+ }
+ ++text;
+ }
+ }
+
+ width = info->width - (int)(text - textstart);
+ if (width > 0) {
+ char fill = info->pad_zeroes ? '0' : ' ';
+ char *end = text+left-1;
+ len = (text - textstart);
+ for (len = (text - textstart); len--; ) {
+ if ((textstart+len+width) < end) {
+ *(textstart+len+width) = *(textstart+len);
+ }
+ }
+ len = (size_t)width;
+ if (len >= left) {
+ text += (left > 1) ? left - 1 : 0;
+ left = SDL_min(left, 1);
+ } else {
+ text += len;
+ left -= len;
+ }
+ while (len--) {
+ if (textstart+len < end) {
+ textstart[len] = fill;
+ }
+ }
+ }
+
+ return (text - textstart);
+}
+
+int
+SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
+{
+ size_t left = maxlen;
+ char *textstart = text;
+
+ if (!fmt) {
+ fmt = "";
+ }
+ while (*fmt && left > 1) {
+ if (*fmt == '%') {
+ SDL_bool done = SDL_FALSE;
+ size_t len = 0;
+ SDL_bool check_flag;
+ SDL_FormatInfo info;
+ enum
+ {
+ DO_INT,
+ DO_LONG,
+ DO_LONGLONG
+ } inttype = DO_INT;
+
+ SDL_zero(info);
+ info.radix = 10;
+ info.precision = -1;
+
+ check_flag = SDL_TRUE;
+ while (check_flag) {
+ ++fmt;
+ switch (*fmt) {
+ case '-':
+ info.left_justify = SDL_TRUE;
+ break;
+ case '+':
+ info.force_sign = SDL_TRUE;
+ break;
+ case '#':
+ info.force_type = SDL_TRUE;
+ break;
+ case '0':
+ info.pad_zeroes = SDL_TRUE;
+ break;
+ default:
+ check_flag = SDL_FALSE;
+ break;
+ }
+ }
+
+ if (*fmt >= '0' && *fmt <= '9') {
+ info.width = SDL_strtol(fmt, (char **)&fmt, 0);
+ }
+
+ if (*fmt == '.') {
+ ++fmt;
+ if (*fmt >= '0' && *fmt <= '9') {
+ info.precision = SDL_strtol(fmt, (char **)&fmt, 0);
+ } else {
+ info.precision = 0;
+ }
+ }
+
+ while (!done) {
+ switch (*fmt) {
+ case '%':
+ if (left > 1) {
+ *text = '%';
+ }
+ len = 1;
+ done = SDL_TRUE;
+ break;
+ case 'c':
+ /* char is promoted to int when passed through (...) */
+ if (left > 1) {
+ *text = (char) va_arg(ap, int);
+ }
+ len = 1;
+ done = SDL_TRUE;
+ break;
+ case 'h':
+ /* short is promoted to int when passed through (...) */
+ break;
+ case 'l':
+ if (inttype < DO_LONGLONG) {
+ ++inttype;
+ }
+ break;
+ case 'I':
+ if (SDL_strncmp(fmt, "I64", 3) == 0) {
+ fmt += 2;
+ inttype = DO_LONGLONG;
+ }
+ break;
+ case 'i':
+ case 'd':
+ switch (inttype) {
+ case DO_INT:
+ len = SDL_PrintLong(text, left, &info,
+ (long) va_arg(ap, int));
+ break;
+ case DO_LONG:
+ len = SDL_PrintLong(text, left, &info,
+ va_arg(ap, long));
+ break;
+ case DO_LONGLONG:
+ len = SDL_PrintLongLong(text, left, &info,
+ va_arg(ap, Sint64));
+ break;
+ }
+ done = SDL_TRUE;
+ break;
+ case 'p':
+ case 'x':
+ info.force_case = SDL_CASE_LOWER;
+ /* Fall through to 'X' handling */
+ case 'X':
+ if (info.force_case == SDL_CASE_NOCHANGE) {
+ info.force_case = SDL_CASE_UPPER;
+ }
+ if (info.radix == 10) {
+ info.radix = 16;
+ }
+ if (*fmt == 'p') {
+ inttype = DO_LONG;
+ }
+ /* Fall through to unsigned handling */
+ case 'o':
+ if (info.radix == 10) {
+ info.radix = 8;
+ }
+ /* Fall through to unsigned handling */
+ case 'u':
+ info.pad_zeroes = SDL_TRUE;
+ switch (inttype) {
+ case DO_INT:
+ len = SDL_PrintUnsignedLong(text, left, &info,
+ (unsigned long)
+ va_arg(ap, unsigned int));
+ break;
+ case DO_LONG:
+ len = SDL_PrintUnsignedLong(text, left, &info,
+ va_arg(ap, unsigned long));
+ break;
+ case DO_LONGLONG:
+ len = SDL_PrintUnsignedLongLong(text, left, &info,
+ va_arg(ap, Uint64));
+ break;
+ }
+ done = SDL_TRUE;
+ break;
+ case 'f':
+ len = SDL_PrintFloat(text, left, &info, va_arg(ap, double));
+ done = SDL_TRUE;
+ break;
+ case 'S':
+ {
+ /* In practice this is used on Windows for WCHAR strings */
+ wchar_t *wide_arg = va_arg(ap, wchar_t *);
+ char *arg = SDL_iconv_string("UTF-8", "UTF-16LE", (char *)(wide_arg), (SDL_wcslen(wide_arg)+1)*sizeof(*wide_arg));
+ len = SDL_PrintString(text, left, &info, arg);
+ SDL_free(arg);
+ done = SDL_TRUE;
+ }
+ break;
+ case 's':
+ len = SDL_PrintString(text, left, &info, va_arg(ap, char *));
+ done = SDL_TRUE;
+ break;
+ default:
+ done = SDL_TRUE;
+ break;
+ }
+ ++fmt;
+ }
+ if (len >= left) {
+ text += (left > 1) ? left - 1 : 0;
+ left = SDL_min(left, 1);
+ } else {
+ text += len;
+ left -= len;
+ }
+ } else {
+ *text++ = *fmt++;
+ --left;
+ }
+ }
+ if (left > 0) {
+ *text = '\0';
+ }
+ return (int)(text - textstart);
+}
+#endif /* HAVE_VSNPRINTF */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/test/SDL_test_assert.c b/src/3rdparty/SDL2/src/test/SDL_test_assert.c
new file mode 100644
index 0000000..4b57285
--- /dev/null
+++ b/src/3rdparty/SDL2/src/test/SDL_test_assert.c
@@ -0,0 +1,152 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+
+ Used by the test framework and test cases.
+
+*/
+
+#include "SDL_config.h"
+
+#include "SDL_test.h"
+
+/* Assert check message format */
+#define SDLTEST_ASSERT_CHECK_FORMAT "Assert '%s': %s"
+
+/* Assert summary message format */
+#define SDLTEST_ASSERT_SUMMARY_FORMAT "Assert Summary: Total=%d Passed=%d Failed=%d"
+
+/* ! \brief counts the failed asserts */
+static Uint32 SDLTest_AssertsFailed = 0;
+
+/* ! \brief counts the passed asserts */
+static Uint32 SDLTest_AssertsPassed = 0;
+
+/*
+ * Assert that logs and break execution flow on failures (i.e. for harness errors).
+ */
+void SDLTest_Assert(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...)
+{
+ va_list list;
+ char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
+
+ /* Print assert description into a buffer */
+ SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
+ va_start(list, assertDescription);
+ SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
+ va_end(list);
+
+ /* Log, then assert and break on failure */
+ SDL_assert((SDLTest_AssertCheck(assertCondition, "%s", logMessage)));
+}
+
+/*
+ * Assert that logs but does not break execution flow on failures (i.e. for test cases).
+ */
+int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...)
+{
+ va_list list;
+ char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
+
+ /* Print assert description into a buffer */
+ SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
+ va_start(list, assertDescription);
+ SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
+ va_end(list);
+
+ /* Log pass or fail message */
+ if (assertCondition == ASSERT_FAIL)
+ {
+ SDLTest_AssertsFailed++;
+ SDLTest_LogError(SDLTEST_ASSERT_CHECK_FORMAT, logMessage, "Failed");
+ }
+ else
+ {
+ SDLTest_AssertsPassed++;
+ SDLTest_Log(SDLTEST_ASSERT_CHECK_FORMAT, logMessage, "Passed");
+ }
+
+ return assertCondition;
+}
+
+/*
+ * Explicitly passing Assert that logs (i.e. for test cases).
+ */
+void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...)
+{
+ va_list list;
+ char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
+
+ /* Print assert description into a buffer */
+ SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
+ va_start(list, assertDescription);
+ SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
+ va_end(list);
+
+ /* Log pass message */
+ SDLTest_AssertsPassed++;
+ SDLTest_Log(SDLTEST_ASSERT_CHECK_FORMAT, logMessage, "Pass");
+}
+
+/*
+ * Resets the assert summary counters to zero.
+ */
+void SDLTest_ResetAssertSummary()
+{
+ SDLTest_AssertsPassed = 0;
+ SDLTest_AssertsFailed = 0;
+}
+
+/*
+ * Logs summary of all assertions (total, pass, fail) since last reset
+ * as INFO (failed==0) or ERROR (failed > 0).
+ */
+void SDLTest_LogAssertSummary()
+{
+ Uint32 totalAsserts = SDLTest_AssertsPassed + SDLTest_AssertsFailed;
+ if (SDLTest_AssertsFailed == 0)
+ {
+ SDLTest_Log(SDLTEST_ASSERT_SUMMARY_FORMAT, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
+ }
+ else
+ {
+ SDLTest_LogError(SDLTEST_ASSERT_SUMMARY_FORMAT, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
+ }
+}
+
+/*
+ * Converts the current assert state into a test result
+ */
+int SDLTest_AssertSummaryToTestResult()
+{
+ if (SDLTest_AssertsFailed > 0) {
+ return TEST_RESULT_FAILED;
+ } else {
+ if (SDLTest_AssertsPassed > 0) {
+ return TEST_RESULT_PASSED;
+ } else {
+ return TEST_RESULT_NO_ASSERT;
+ }
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/test/SDL_test_common.c b/src/3rdparty/SDL2/src/test/SDL_test_common.c
new file mode 100644
index 0000000..b7e294a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/test/SDL_test_common.c
@@ -0,0 +1,1783 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/* Ported from original test\common.c file. */
+
+#include "SDL_config.h"
+#include "SDL_test.h"
+
+#include <stdio.h>
+
+#define VIDEO_USAGE \
+"[--video driver] [--renderer driver] [--gldebug] [--info all|video|modes|render|event] [--log all|error|system|audio|video|render|input] [--display N] [--fullscreen | --fullscreen-desktop | --windows N] [--title title] [--icon icon.bmp] [--center | --position X,Y] [--geometry WxH] [--min-geometry WxH] [--max-geometry WxH] [--logical WxH] [--scale N] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab] [--allow-highdpi]"
+
+#define AUDIO_USAGE \
+"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
+
+static void SDL_snprintfcat(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ... )
+{
+ size_t length = SDL_strlen(text);
+ va_list ap;
+
+ va_start(ap, fmt);
+ text += length;
+ maxlen -= length;
+ SDL_vsnprintf(text, maxlen, fmt, ap);
+ va_end(ap);
+}
+
+SDLTest_CommonState *
+SDLTest_CommonCreateState(char **argv, Uint32 flags)
+{
+ int i;
+ SDLTest_CommonState *state;
+
+ /* Do this first so we catch all allocations */
+ for (i = 1; argv[i]; ++i) {
+ if (SDL_strcasecmp(argv[i], "--trackmem") == 0) {
+ SDLTest_TrackAllocations();
+ break;
+ }
+ }
+
+ state = (SDLTest_CommonState *)SDL_calloc(1, sizeof(*state));
+ if (!state) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ /* Initialize some defaults */
+ state->argv = argv;
+ state->flags = flags;
+ state->window_title = argv[0];
+ state->window_flags = 0;
+ state->window_x = SDL_WINDOWPOS_UNDEFINED;
+ state->window_y = SDL_WINDOWPOS_UNDEFINED;
+ state->window_w = DEFAULT_WINDOW_WIDTH;
+ state->window_h = DEFAULT_WINDOW_HEIGHT;
+ state->num_windows = 1;
+ state->audiospec.freq = 22050;
+ state->audiospec.format = AUDIO_S16;
+ state->audiospec.channels = 2;
+ state->audiospec.samples = 2048;
+
+ /* Set some very sane GL defaults */
+ state->gl_red_size = 3;
+ state->gl_green_size = 3;
+ state->gl_blue_size = 2;
+ state->gl_alpha_size = 0;
+ state->gl_buffer_size = 0;
+ state->gl_depth_size = 16;
+ state->gl_stencil_size = 0;
+ state->gl_double_buffer = 1;
+ state->gl_accum_red_size = 0;
+ state->gl_accum_green_size = 0;
+ state->gl_accum_blue_size = 0;
+ state->gl_accum_alpha_size = 0;
+ state->gl_stereo = 0;
+ state->gl_multisamplebuffers = 0;
+ state->gl_multisamplesamples = 0;
+ state->gl_retained_backing = 1;
+ state->gl_accelerated = -1;
+ state->gl_debug = 0;
+
+ return state;
+}
+
+int
+SDLTest_CommonArg(SDLTest_CommonState * state, int index)
+{
+ char **argv = state->argv;
+
+ if (SDL_strcasecmp(argv[index], "--video") == 0) {
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ state->videodriver = argv[index];
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "--renderer") == 0) {
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ state->renderdriver = argv[index];
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "--gldebug") == 0) {
+ state->gl_debug = 1;
+ return 1;
+ }
+ if (SDL_strcasecmp(argv[index], "--info") == 0) {
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ if (SDL_strcasecmp(argv[index], "all") == 0) {
+ state->verbose |=
+ (VERBOSE_VIDEO | VERBOSE_MODES | VERBOSE_RENDER |
+ VERBOSE_EVENT);
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "video") == 0) {
+ state->verbose |= VERBOSE_VIDEO;
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "modes") == 0) {
+ state->verbose |= VERBOSE_MODES;
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "render") == 0) {
+ state->verbose |= VERBOSE_RENDER;
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "event") == 0) {
+ state->verbose |= VERBOSE_EVENT;
+ return 2;
+ }
+ return -1;
+ }
+ if (SDL_strcasecmp(argv[index], "--log") == 0) {
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ if (SDL_strcasecmp(argv[index], "all") == 0) {
+ SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE);
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "error") == 0) {
+ SDL_LogSetPriority(SDL_LOG_CATEGORY_ERROR, SDL_LOG_PRIORITY_VERBOSE);
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "system") == 0) {
+ SDL_LogSetPriority(SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_PRIORITY_VERBOSE);
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "audio") == 0) {
+ SDL_LogSetPriority(SDL_LOG_CATEGORY_AUDIO, SDL_LOG_PRIORITY_VERBOSE);
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "video") == 0) {
+ SDL_LogSetPriority(SDL_LOG_CATEGORY_VIDEO, SDL_LOG_PRIORITY_VERBOSE);
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "render") == 0) {
+ SDL_LogSetPriority(SDL_LOG_CATEGORY_RENDER, SDL_LOG_PRIORITY_VERBOSE);
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "input") == 0) {
+ SDL_LogSetPriority(SDL_LOG_CATEGORY_INPUT, SDL_LOG_PRIORITY_VERBOSE);
+ return 2;
+ }
+ return -1;
+ }
+ if (SDL_strcasecmp(argv[index], "--display") == 0) {
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ state->display = SDL_atoi(argv[index]);
+ if (SDL_WINDOWPOS_ISUNDEFINED(state->window_x)) {
+ state->window_x = SDL_WINDOWPOS_UNDEFINED_DISPLAY(state->display);
+ state->window_y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(state->display);
+ }
+ if (SDL_WINDOWPOS_ISCENTERED(state->window_x)) {
+ state->window_x = SDL_WINDOWPOS_CENTERED_DISPLAY(state->display);
+ state->window_y = SDL_WINDOWPOS_CENTERED_DISPLAY(state->display);
+ }
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "--fullscreen") == 0) {
+ state->window_flags |= SDL_WINDOW_FULLSCREEN;
+ state->num_windows = 1;
+ return 1;
+ }
+ if (SDL_strcasecmp(argv[index], "--fullscreen-desktop") == 0) {
+ state->window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
+ state->num_windows = 1;
+ return 1;
+ }
+ if (SDL_strcasecmp(argv[index], "--allow-highdpi") == 0) {
+ state->window_flags |= SDL_WINDOW_ALLOW_HIGHDPI;
+ return 1;
+ }
+ if (SDL_strcasecmp(argv[index], "--windows") == 0) {
+ ++index;
+ if (!argv[index] || !SDL_isdigit(*argv[index])) {
+ return -1;
+ }
+ if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) {
+ state->num_windows = SDL_atoi(argv[index]);
+ }
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "--title") == 0) {
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ state->window_title = argv[index];
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "--icon") == 0) {
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ state->window_icon = argv[index];
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "--center") == 0) {
+ state->window_x = SDL_WINDOWPOS_CENTERED;
+ state->window_y = SDL_WINDOWPOS_CENTERED;
+ return 1;
+ }
+ if (SDL_strcasecmp(argv[index], "--position") == 0) {
+ char *x, *y;
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ x = argv[index];
+ y = argv[index];
+ while (*y && *y != ',') {
+ ++y;
+ }
+ if (!*y) {
+ return -1;
+ }
+ *y++ = '\0';
+ state->window_x = SDL_atoi(x);
+ state->window_y = SDL_atoi(y);
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "--geometry") == 0) {
+ char *w, *h;
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ w = argv[index];
+ h = argv[index];
+ while (*h && *h != 'x') {
+ ++h;
+ }
+ if (!*h) {
+ return -1;
+ }
+ *h++ = '\0';
+ state->window_w = SDL_atoi(w);
+ state->window_h = SDL_atoi(h);
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "--min-geometry") == 0) {
+ char *w, *h;
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ w = argv[index];
+ h = argv[index];
+ while (*h && *h != 'x') {
+ ++h;
+ }
+ if (!*h) {
+ return -1;
+ }
+ *h++ = '\0';
+ state->window_minW = SDL_atoi(w);
+ state->window_minH = SDL_atoi(h);
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "--max-geometry") == 0) {
+ char *w, *h;
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ w = argv[index];
+ h = argv[index];
+ while (*h && *h != 'x') {
+ ++h;
+ }
+ if (!*h) {
+ return -1;
+ }
+ *h++ = '\0';
+ state->window_maxW = SDL_atoi(w);
+ state->window_maxH = SDL_atoi(h);
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "--logical") == 0) {
+ char *w, *h;
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ w = argv[index];
+ h = argv[index];
+ while (*h && *h != 'x') {
+ ++h;
+ }
+ if (!*h) {
+ return -1;
+ }
+ *h++ = '\0';
+ state->logical_w = SDL_atoi(w);
+ state->logical_h = SDL_atoi(h);
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "--scale") == 0) {
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ state->scale = (float)SDL_atof(argv[index]);
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "--depth") == 0) {
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ state->depth = SDL_atoi(argv[index]);
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "--refresh") == 0) {
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ state->refresh_rate = SDL_atoi(argv[index]);
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "--vsync") == 0) {
+ state->render_flags |= SDL_RENDERER_PRESENTVSYNC;
+ return 1;
+ }
+ if (SDL_strcasecmp(argv[index], "--noframe") == 0) {
+ state->window_flags |= SDL_WINDOW_BORDERLESS;
+ return 1;
+ }
+ if (SDL_strcasecmp(argv[index], "--resize") == 0) {
+ state->window_flags |= SDL_WINDOW_RESIZABLE;
+ return 1;
+ }
+ if (SDL_strcasecmp(argv[index], "--minimize") == 0) {
+ state->window_flags |= SDL_WINDOW_MINIMIZED;
+ return 1;
+ }
+ if (SDL_strcasecmp(argv[index], "--maximize") == 0) {
+ state->window_flags |= SDL_WINDOW_MAXIMIZED;
+ return 1;
+ }
+ if (SDL_strcasecmp(argv[index], "--grab") == 0) {
+ state->window_flags |= SDL_WINDOW_INPUT_GRABBED;
+ return 1;
+ }
+ if (SDL_strcasecmp(argv[index], "--rate") == 0) {
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ state->audiospec.freq = SDL_atoi(argv[index]);
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "--format") == 0) {
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ if (SDL_strcasecmp(argv[index], "U8") == 0) {
+ state->audiospec.format = AUDIO_U8;
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "S8") == 0) {
+ state->audiospec.format = AUDIO_S8;
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "U16") == 0) {
+ state->audiospec.format = AUDIO_U16;
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "U16LE") == 0) {
+ state->audiospec.format = AUDIO_U16LSB;
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "U16BE") == 0) {
+ state->audiospec.format = AUDIO_U16MSB;
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "S16") == 0) {
+ state->audiospec.format = AUDIO_S16;
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "S16LE") == 0) {
+ state->audiospec.format = AUDIO_S16LSB;
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "S16BE") == 0) {
+ state->audiospec.format = AUDIO_S16MSB;
+ return 2;
+ }
+ return -1;
+ }
+ if (SDL_strcasecmp(argv[index], "--channels") == 0) {
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ state->audiospec.channels = (Uint8) SDL_atoi(argv[index]);
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "--samples") == 0) {
+ ++index;
+ if (!argv[index]) {
+ return -1;
+ }
+ state->audiospec.samples = (Uint16) SDL_atoi(argv[index]);
+ return 2;
+ }
+ if (SDL_strcasecmp(argv[index], "--trackmem") == 0) {
+ /* Already handled in SDLTest_CommonCreateState() */
+ return 1;
+ }
+ if ((SDL_strcasecmp(argv[index], "-h") == 0)
+ || (SDL_strcasecmp(argv[index], "--help") == 0)) {
+ /* Print the usage message */
+ return -1;
+ }
+ if (SDL_strcmp(argv[index], "-NSDocumentRevisionsDebugMode") == 0) {
+ /* Debug flag sent by Xcode */
+ return 2;
+ }
+ return 0;
+}
+
+const char *
+SDLTest_CommonUsage(SDLTest_CommonState * state)
+{
+ switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
+ case SDL_INIT_VIDEO:
+ return "[--trackmem] " VIDEO_USAGE;
+ case SDL_INIT_AUDIO:
+ return "[--trackmem] " AUDIO_USAGE;
+ case (SDL_INIT_VIDEO | SDL_INIT_AUDIO):
+ return "[--trackmem] " VIDEO_USAGE " " AUDIO_USAGE;
+ default:
+ return "[--trackmem]";
+ }
+}
+
+static void
+SDLTest_PrintRendererFlag(char *text, size_t maxlen, Uint32 flag)
+{
+ switch (flag) {
+ case SDL_RENDERER_SOFTWARE:
+ SDL_snprintfcat(text, maxlen, "Software");
+ break;
+ case SDL_RENDERER_ACCELERATED:
+ SDL_snprintfcat(text, maxlen, "Accelerated");
+ break;
+ case SDL_RENDERER_PRESENTVSYNC:
+ SDL_snprintfcat(text, maxlen, "PresentVSync");
+ break;
+ case SDL_RENDERER_TARGETTEXTURE:
+ SDL_snprintfcat(text, maxlen, "TargetTexturesSupported");
+ break;
+ default:
+ SDL_snprintfcat(text, maxlen, "0x%8.8x", flag);
+ break;
+ }
+}
+
+static void
+SDLTest_PrintPixelFormat(char *text, size_t maxlen, Uint32 format)
+{
+ switch (format) {
+ case SDL_PIXELFORMAT_UNKNOWN:
+ SDL_snprintfcat(text, maxlen, "Unknown");
+ break;
+ case SDL_PIXELFORMAT_INDEX1LSB:
+ SDL_snprintfcat(text, maxlen, "Index1LSB");
+ break;
+ case SDL_PIXELFORMAT_INDEX1MSB:
+ SDL_snprintfcat(text, maxlen, "Index1MSB");
+ break;
+ case SDL_PIXELFORMAT_INDEX4LSB:
+ SDL_snprintfcat(text, maxlen, "Index4LSB");
+ break;
+ case SDL_PIXELFORMAT_INDEX4MSB:
+ SDL_snprintfcat(text, maxlen, "Index4MSB");
+ break;
+ case SDL_PIXELFORMAT_INDEX8:
+ SDL_snprintfcat(text, maxlen, "Index8");
+ break;
+ case SDL_PIXELFORMAT_RGB332:
+ SDL_snprintfcat(text, maxlen, "RGB332");
+ break;
+ case SDL_PIXELFORMAT_RGB444:
+ SDL_snprintfcat(text, maxlen, "RGB444");
+ break;
+ case SDL_PIXELFORMAT_RGB555:
+ SDL_snprintfcat(text, maxlen, "RGB555");
+ break;
+ case SDL_PIXELFORMAT_BGR555:
+ SDL_snprintfcat(text, maxlen, "BGR555");
+ break;
+ case SDL_PIXELFORMAT_ARGB4444:
+ SDL_snprintfcat(text, maxlen, "ARGB4444");
+ break;
+ case SDL_PIXELFORMAT_ABGR4444:
+ SDL_snprintfcat(text, maxlen, "ABGR4444");
+ break;
+ case SDL_PIXELFORMAT_ARGB1555:
+ SDL_snprintfcat(text, maxlen, "ARGB1555");
+ break;
+ case SDL_PIXELFORMAT_ABGR1555:
+ SDL_snprintfcat(text, maxlen, "ABGR1555");
+ break;
+ case SDL_PIXELFORMAT_RGB565:
+ SDL_snprintfcat(text, maxlen, "RGB565");
+ break;
+ case SDL_PIXELFORMAT_BGR565:
+ SDL_snprintfcat(text, maxlen, "BGR565");
+ break;
+ case SDL_PIXELFORMAT_RGB24:
+ SDL_snprintfcat(text, maxlen, "RGB24");
+ break;
+ case SDL_PIXELFORMAT_BGR24:
+ SDL_snprintfcat(text, maxlen, "BGR24");
+ break;
+ case SDL_PIXELFORMAT_RGB888:
+ SDL_snprintfcat(text, maxlen, "RGB888");
+ break;
+ case SDL_PIXELFORMAT_BGR888:
+ SDL_snprintfcat(text, maxlen, "BGR888");
+ break;
+ case SDL_PIXELFORMAT_ARGB8888:
+ SDL_snprintfcat(text, maxlen, "ARGB8888");
+ break;
+ case SDL_PIXELFORMAT_RGBA8888:
+ SDL_snprintfcat(text, maxlen, "RGBA8888");
+ break;
+ case SDL_PIXELFORMAT_ABGR8888:
+ SDL_snprintfcat(text, maxlen, "ABGR8888");
+ break;
+ case SDL_PIXELFORMAT_BGRA8888:
+ SDL_snprintfcat(text, maxlen, "BGRA8888");
+ break;
+ case SDL_PIXELFORMAT_ARGB2101010:
+ SDL_snprintfcat(text, maxlen, "ARGB2101010");
+ break;
+ case SDL_PIXELFORMAT_YV12:
+ SDL_snprintfcat(text, maxlen, "YV12");
+ break;
+ case SDL_PIXELFORMAT_IYUV:
+ SDL_snprintfcat(text, maxlen, "IYUV");
+ break;
+ case SDL_PIXELFORMAT_YUY2:
+ SDL_snprintfcat(text, maxlen, "YUY2");
+ break;
+ case SDL_PIXELFORMAT_UYVY:
+ SDL_snprintfcat(text, maxlen, "UYVY");
+ break;
+ case SDL_PIXELFORMAT_YVYU:
+ SDL_snprintfcat(text, maxlen, "YVYU");
+ break;
+ case SDL_PIXELFORMAT_NV12:
+ SDL_snprintfcat(text, maxlen, "NV12");
+ break;
+ case SDL_PIXELFORMAT_NV21:
+ SDL_snprintfcat(text, maxlen, "NV21");
+ break;
+ default:
+ SDL_snprintfcat(text, maxlen, "0x%8.8x", format);
+ break;
+ }
+}
+
+static void
+SDLTest_PrintRenderer(SDL_RendererInfo * info)
+{
+ int i, count;
+ char text[1024];
+
+ SDL_Log(" Renderer %s:\n", info->name);
+
+ SDL_snprintf(text, sizeof(text), " Flags: 0x%8.8X", info->flags);
+ SDL_snprintfcat(text, sizeof(text), " (");
+ count = 0;
+ for (i = 0; i < sizeof(info->flags) * 8; ++i) {
+ Uint32 flag = (1 << i);
+ if (info->flags & flag) {
+ if (count > 0) {
+ SDL_snprintfcat(text, sizeof(text), " | ");
+ }
+ SDLTest_PrintRendererFlag(text, sizeof(text), flag);
+ ++count;
+ }
+ }
+ SDL_snprintfcat(text, sizeof(text), ")");
+ SDL_Log("%s\n", text);
+
+ SDL_snprintf(text, sizeof(text), " Texture formats (%d): ", info->num_texture_formats);
+ for (i = 0; i < (int) info->num_texture_formats; ++i) {
+ if (i > 0) {
+ SDL_snprintfcat(text, sizeof(text), ", ");
+ }
+ SDLTest_PrintPixelFormat(text, sizeof(text), info->texture_formats[i]);
+ }
+ SDL_Log("%s\n", text);
+
+ if (info->max_texture_width || info->max_texture_height) {
+ SDL_Log(" Max Texture Size: %dx%d\n",
+ info->max_texture_width, info->max_texture_height);
+ }
+}
+
+static SDL_Surface *
+SDLTest_LoadIcon(const char *file)
+{
+ SDL_Surface *icon;
+
+ /* Load the icon surface */
+ icon = SDL_LoadBMP(file);
+ if (icon == NULL) {
+ SDL_Log("Couldn't load %s: %s\n", file, SDL_GetError());
+ return (NULL);
+ }
+
+ if (icon->format->palette) {
+ /* Set the colorkey */
+ SDL_SetColorKey(icon, 1, *((Uint8 *) icon->pixels));
+ }
+
+ return (icon);
+}
+
+static SDL_HitTestResult SDLCALL
+SDLTest_ExampleHitTestCallback(SDL_Window *win, const SDL_Point *area, void *data)
+{
+ int w, h;
+ const int RESIZE_BORDER = 8;
+ const int DRAGGABLE_TITLE = 32;
+
+ /*SDL_Log("Hit test point %d,%d\n", area->x, area->y);*/
+
+ SDL_GetWindowSize(win, &w, &h);
+
+ if (area->x < RESIZE_BORDER) {
+ if (area->y < RESIZE_BORDER) {
+ SDL_Log("SDL_HITTEST_RESIZE_TOPLEFT\n");
+ return SDL_HITTEST_RESIZE_TOPLEFT;
+ } else if (area->y >= (h-RESIZE_BORDER)) {
+ SDL_Log("SDL_HITTEST_RESIZE_BOTTOMLEFT\n");
+ return SDL_HITTEST_RESIZE_BOTTOMLEFT;
+ } else {
+ SDL_Log("SDL_HITTEST_RESIZE_LEFT\n");
+ return SDL_HITTEST_RESIZE_LEFT;
+ }
+ } else if (area->x >= (w-RESIZE_BORDER)) {
+ if (area->y < RESIZE_BORDER) {
+ SDL_Log("SDL_HITTEST_RESIZE_TOPRIGHT\n");
+ return SDL_HITTEST_RESIZE_TOPRIGHT;
+ } else if (area->y >= (h-RESIZE_BORDER)) {
+ SDL_Log("SDL_HITTEST_RESIZE_BOTTOMRIGHT\n");
+ return SDL_HITTEST_RESIZE_BOTTOMRIGHT;
+ } else {
+ SDL_Log("SDL_HITTEST_RESIZE_RIGHT\n");
+ return SDL_HITTEST_RESIZE_RIGHT;
+ }
+ } else if (area->y >= (h-RESIZE_BORDER)) {
+ SDL_Log("SDL_HITTEST_RESIZE_BOTTOM\n");
+ return SDL_HITTEST_RESIZE_BOTTOM;
+ } else if (area->y < RESIZE_BORDER) {
+ SDL_Log("SDL_HITTEST_RESIZE_TOP\n");
+ return SDL_HITTEST_RESIZE_TOP;
+ } else if (area->y < DRAGGABLE_TITLE) {
+ SDL_Log("SDL_HITTEST_DRAGGABLE\n");
+ return SDL_HITTEST_DRAGGABLE;
+ }
+ return SDL_HITTEST_NORMAL;
+}
+
+SDL_bool
+SDLTest_CommonInit(SDLTest_CommonState * state)
+{
+ int i, j, m, n, w, h;
+ SDL_DisplayMode fullscreen_mode;
+ char text[1024];
+
+ if (state->flags & SDL_INIT_VIDEO) {
+ if (state->verbose & VERBOSE_VIDEO) {
+ n = SDL_GetNumVideoDrivers();
+ if (n == 0) {
+ SDL_Log("No built-in video drivers\n");
+ } else {
+ SDL_snprintf(text, sizeof(text), "Built-in video drivers:");
+ for (i = 0; i < n; ++i) {
+ if (i > 0) {
+ SDL_snprintfcat(text, sizeof(text), ",");
+ }
+ SDL_snprintfcat(text, sizeof(text), " %s", SDL_GetVideoDriver(i));
+ }
+ SDL_Log("%s\n", text);
+ }
+ }
+ if (SDL_VideoInit(state->videodriver) < 0) {
+ SDL_Log("Couldn't initialize video driver: %s\n",
+ SDL_GetError());
+ return SDL_FALSE;
+ }
+ if (state->verbose & VERBOSE_VIDEO) {
+ SDL_Log("Video driver: %s\n",
+ SDL_GetCurrentVideoDriver());
+ }
+
+ /* Upload GL settings */
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, state->gl_red_size);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, state->gl_green_size);
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, state->gl_blue_size);
+ SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, state->gl_alpha_size);
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, state->gl_double_buffer);
+ SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, state->gl_buffer_size);
+ SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, state->gl_depth_size);
+ SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, state->gl_stencil_size);
+ SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, state->gl_accum_red_size);
+ SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, state->gl_accum_green_size);
+ SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, state->gl_accum_blue_size);
+ SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, state->gl_accum_alpha_size);
+ SDL_GL_SetAttribute(SDL_GL_STEREO, state->gl_stereo);
+ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, state->gl_multisamplebuffers);
+ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, state->gl_multisamplesamples);
+ if (state->gl_accelerated >= 0) {
+ SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL,
+ state->gl_accelerated);
+ }
+ SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, state->gl_retained_backing);
+ if (state->gl_major_version) {
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, state->gl_major_version);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, state->gl_minor_version);
+ }
+ if (state->gl_debug) {
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
+ }
+ if (state->gl_profile_mask) {
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, state->gl_profile_mask);
+ }
+
+ if (state->verbose & VERBOSE_MODES) {
+ SDL_Rect bounds, usablebounds;
+ float hdpi = 0;
+ float vdpi = 0;
+ SDL_DisplayMode mode;
+ int bpp;
+ Uint32 Rmask, Gmask, Bmask, Amask;
+#if SDL_VIDEO_DRIVER_WINDOWS
+ int adapterIndex = 0;
+ int outputIndex = 0;
+#endif
+ n = SDL_GetNumVideoDisplays();
+ SDL_Log("Number of displays: %d\n", n);
+ for (i = 0; i < n; ++i) {
+ SDL_Log("Display %d: %s\n", i, SDL_GetDisplayName(i));
+
+ SDL_zero(bounds);
+ SDL_GetDisplayBounds(i, &bounds);
+
+ SDL_zero(usablebounds);
+ SDL_GetDisplayUsableBounds(i, &usablebounds);
+
+ SDL_GetDisplayDPI(i, NULL, &hdpi, &vdpi);
+
+ SDL_Log("Bounds: %dx%d at %d,%d\n", bounds.w, bounds.h, bounds.x, bounds.y);
+ SDL_Log("Usable bounds: %dx%d at %d,%d\n", usablebounds.w, usablebounds.h, usablebounds.x, usablebounds.y);
+ SDL_Log("DPI: %fx%f\n", hdpi, vdpi);
+
+ SDL_GetDesktopDisplayMode(i, &mode);
+ SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask,
+ &Bmask, &Amask);
+ SDL_Log(" Current mode: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
+ mode.w, mode.h, mode.refresh_rate, bpp,
+ SDL_GetPixelFormatName(mode.format));
+ if (Rmask || Gmask || Bmask) {
+ SDL_Log(" Red Mask = 0x%.8x\n", Rmask);
+ SDL_Log(" Green Mask = 0x%.8x\n", Gmask);
+ SDL_Log(" Blue Mask = 0x%.8x\n", Bmask);
+ if (Amask)
+ SDL_Log(" Alpha Mask = 0x%.8x\n", Amask);
+ }
+
+ /* Print available fullscreen video modes */
+ m = SDL_GetNumDisplayModes(i);
+ if (m == 0) {
+ SDL_Log("No available fullscreen video modes\n");
+ } else {
+ SDL_Log(" Fullscreen video modes:\n");
+ for (j = 0; j < m; ++j) {
+ SDL_GetDisplayMode(i, j, &mode);
+ SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
+ &Gmask, &Bmask, &Amask);
+ SDL_Log(" Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
+ j, mode.w, mode.h, mode.refresh_rate, bpp,
+ SDL_GetPixelFormatName(mode.format));
+ if (Rmask || Gmask || Bmask) {
+ SDL_Log(" Red Mask = 0x%.8x\n",
+ Rmask);
+ SDL_Log(" Green Mask = 0x%.8x\n",
+ Gmask);
+ SDL_Log(" Blue Mask = 0x%.8x\n",
+ Bmask);
+ if (Amask)
+ SDL_Log(" Alpha Mask = 0x%.8x\n",
+ Amask);
+ }
+ }
+ }
+
+#if SDL_VIDEO_DRIVER_WINDOWS
+ /* Print the D3D9 adapter index */
+ adapterIndex = SDL_Direct3D9GetAdapterIndex( i );
+ SDL_Log("D3D9 Adapter Index: %d", adapterIndex);
+
+ /* Print the DXGI adapter and output indices */
+ SDL_DXGIGetOutputInfo(i, &adapterIndex, &outputIndex);
+ SDL_Log("DXGI Adapter Index: %d Output Index: %d", adapterIndex, outputIndex);
+#endif
+ }
+ }
+
+ if (state->verbose & VERBOSE_RENDER) {
+ SDL_RendererInfo info;
+
+ n = SDL_GetNumRenderDrivers();
+ if (n == 0) {
+ SDL_Log("No built-in render drivers\n");
+ } else {
+ SDL_Log("Built-in render drivers:\n");
+ for (i = 0; i < n; ++i) {
+ SDL_GetRenderDriverInfo(i, &info);
+ SDLTest_PrintRenderer(&info);
+ }
+ }
+ }
+
+ SDL_zero(fullscreen_mode);
+ switch (state->depth) {
+ case 8:
+ fullscreen_mode.format = SDL_PIXELFORMAT_INDEX8;
+ break;
+ case 15:
+ fullscreen_mode.format = SDL_PIXELFORMAT_RGB555;
+ break;
+ case 16:
+ fullscreen_mode.format = SDL_PIXELFORMAT_RGB565;
+ break;
+ case 24:
+ fullscreen_mode.format = SDL_PIXELFORMAT_RGB24;
+ break;
+ default:
+ fullscreen_mode.format = SDL_PIXELFORMAT_RGB888;
+ break;
+ }
+ fullscreen_mode.refresh_rate = state->refresh_rate;
+
+ state->windows =
+ (SDL_Window **) SDL_calloc(state->num_windows,
+ sizeof(*state->windows));
+ state->renderers =
+ (SDL_Renderer **) SDL_calloc(state->num_windows,
+ sizeof(*state->renderers));
+ state->targets =
+ (SDL_Texture **) SDL_calloc(state->num_windows,
+ sizeof(*state->targets));
+ if (!state->windows || !state->renderers) {
+ SDL_Log("Out of memory!\n");
+ return SDL_FALSE;
+ }
+ for (i = 0; i < state->num_windows; ++i) {
+ char title[1024];
+
+ if (state->num_windows > 1) {
+ SDL_snprintf(title, SDL_arraysize(title), "%s %d",
+ state->window_title, i + 1);
+ } else {
+ SDL_strlcpy(title, state->window_title, SDL_arraysize(title));
+ }
+ state->windows[i] =
+ SDL_CreateWindow(title, state->window_x, state->window_y,
+ state->window_w, state->window_h,
+ state->window_flags);
+ if (!state->windows[i]) {
+ SDL_Log("Couldn't create window: %s\n",
+ SDL_GetError());
+ return SDL_FALSE;
+ }
+ if (state->window_minW || state->window_minH) {
+ SDL_SetWindowMinimumSize(state->windows[i], state->window_minW, state->window_minH);
+ }
+ if (state->window_maxW || state->window_maxH) {
+ SDL_SetWindowMaximumSize(state->windows[i], state->window_maxW, state->window_maxH);
+ }
+ SDL_GetWindowSize(state->windows[i], &w, &h);
+ if (!(state->window_flags & SDL_WINDOW_RESIZABLE) &&
+ (w != state->window_w || h != state->window_h)) {
+ printf("Window requested size %dx%d, got %dx%d\n", state->window_w, state->window_h, w, h);
+ state->window_w = w;
+ state->window_h = h;
+ }
+ if (SDL_SetWindowDisplayMode(state->windows[i], &fullscreen_mode) < 0) {
+ SDL_Log("Can't set up fullscreen display mode: %s\n",
+ SDL_GetError());
+ return SDL_FALSE;
+ }
+
+ /* Add resize/drag areas for windows that are borderless and resizable */
+ if ((state->window_flags & (SDL_WINDOW_RESIZABLE|SDL_WINDOW_BORDERLESS)) ==
+ (SDL_WINDOW_RESIZABLE|SDL_WINDOW_BORDERLESS)) {
+ SDL_SetWindowHitTest(state->windows[i], SDLTest_ExampleHitTestCallback, NULL);
+ }
+
+ if (state->window_icon) {
+ SDL_Surface *icon = SDLTest_LoadIcon(state->window_icon);
+ if (icon) {
+ SDL_SetWindowIcon(state->windows[i], icon);
+ SDL_FreeSurface(icon);
+ }
+ }
+
+ SDL_ShowWindow(state->windows[i]);
+
+ if (!state->skip_renderer
+ && (state->renderdriver
+ || !(state->window_flags & (SDL_WINDOW_OPENGL | SDL_WINDOW_VULKAN)))) {
+ m = -1;
+ if (state->renderdriver) {
+ SDL_RendererInfo info;
+ n = SDL_GetNumRenderDrivers();
+ for (j = 0; j < n; ++j) {
+ SDL_GetRenderDriverInfo(j, &info);
+ if (SDL_strcasecmp(info.name, state->renderdriver) ==
+ 0) {
+ m = j;
+ break;
+ }
+ }
+ if (m == -1) {
+ SDL_Log("Couldn't find render driver named %s",
+ state->renderdriver);
+ return SDL_FALSE;
+ }
+ }
+ state->renderers[i] = SDL_CreateRenderer(state->windows[i],
+ m, state->render_flags);
+ if (!state->renderers[i]) {
+ SDL_Log("Couldn't create renderer: %s\n",
+ SDL_GetError());
+ return SDL_FALSE;
+ }
+ if (state->logical_w && state->logical_h) {
+ SDL_RenderSetLogicalSize(state->renderers[i], state->logical_w, state->logical_h);
+ } else if (state->scale) {
+ SDL_RenderSetScale(state->renderers[i], state->scale, state->scale);
+ }
+ if (state->verbose & VERBOSE_RENDER) {
+ SDL_RendererInfo info;
+
+ SDL_Log("Current renderer:\n");
+ SDL_GetRendererInfo(state->renderers[i], &info);
+ SDLTest_PrintRenderer(&info);
+ }
+ }
+ }
+ }
+
+ if (state->flags & SDL_INIT_AUDIO) {
+ if (state->verbose & VERBOSE_AUDIO) {
+ n = SDL_GetNumAudioDrivers();
+ if (n == 0) {
+ SDL_Log("No built-in audio drivers\n");
+ } else {
+ SDL_snprintf(text, sizeof(text), "Built-in audio drivers:");
+ for (i = 0; i < n; ++i) {
+ if (i > 0) {
+ SDL_snprintfcat(text, sizeof(text), ",");
+ }
+ SDL_snprintfcat(text, sizeof(text), " %s", SDL_GetAudioDriver(i));
+ }
+ SDL_Log("%s\n", text);
+ }
+ }
+ if (SDL_AudioInit(state->audiodriver) < 0) {
+ SDL_Log("Couldn't initialize audio driver: %s\n",
+ SDL_GetError());
+ return SDL_FALSE;
+ }
+ if (state->verbose & VERBOSE_VIDEO) {
+ SDL_Log("Audio driver: %s\n",
+ SDL_GetCurrentAudioDriver());
+ }
+
+ if (SDL_OpenAudio(&state->audiospec, NULL) < 0) {
+ SDL_Log("Couldn't open audio: %s\n", SDL_GetError());
+ return SDL_FALSE;
+ }
+ }
+
+ return SDL_TRUE;
+}
+
+static const char *
+ControllerAxisName(const SDL_GameControllerAxis axis)
+{
+ switch (axis)
+ {
+#define AXIS_CASE(ax) case SDL_CONTROLLER_AXIS_##ax: return #ax
+ AXIS_CASE(INVALID);
+ AXIS_CASE(LEFTX);
+ AXIS_CASE(LEFTY);
+ AXIS_CASE(RIGHTX);
+ AXIS_CASE(RIGHTY);
+ AXIS_CASE(TRIGGERLEFT);
+ AXIS_CASE(TRIGGERRIGHT);
+#undef AXIS_CASE
+default: return "???";
+ }
+}
+
+static const char *
+ControllerButtonName(const SDL_GameControllerButton button)
+{
+ switch (button)
+ {
+#define BUTTON_CASE(btn) case SDL_CONTROLLER_BUTTON_##btn: return #btn
+ BUTTON_CASE(INVALID);
+ BUTTON_CASE(A);
+ BUTTON_CASE(B);
+ BUTTON_CASE(X);
+ BUTTON_CASE(Y);
+ BUTTON_CASE(BACK);
+ BUTTON_CASE(GUIDE);
+ BUTTON_CASE(START);
+ BUTTON_CASE(LEFTSTICK);
+ BUTTON_CASE(RIGHTSTICK);
+ BUTTON_CASE(LEFTSHOULDER);
+ BUTTON_CASE(RIGHTSHOULDER);
+ BUTTON_CASE(DPAD_UP);
+ BUTTON_CASE(DPAD_DOWN);
+ BUTTON_CASE(DPAD_LEFT);
+ BUTTON_CASE(DPAD_RIGHT);
+#undef BUTTON_CASE
+default: return "???";
+ }
+}
+
+static void
+SDLTest_PrintEvent(SDL_Event * event)
+{
+ if ((event->type == SDL_MOUSEMOTION) || (event->type == SDL_FINGERMOTION)) {
+ /* Mouse and finger motion are really spammy */
+ return;
+ }
+
+ switch (event->type) {
+ case SDL_WINDOWEVENT:
+ switch (event->window.event) {
+ case SDL_WINDOWEVENT_SHOWN:
+ SDL_Log("SDL EVENT: Window %d shown", event->window.windowID);
+ break;
+ case SDL_WINDOWEVENT_HIDDEN:
+ SDL_Log("SDL EVENT: Window %d hidden", event->window.windowID);
+ break;
+ case SDL_WINDOWEVENT_EXPOSED:
+ SDL_Log("SDL EVENT: Window %d exposed", event->window.windowID);
+ break;
+ case SDL_WINDOWEVENT_MOVED:
+ SDL_Log("SDL EVENT: Window %d moved to %d,%d",
+ event->window.windowID, event->window.data1,
+ event->window.data2);
+ break;
+ case SDL_WINDOWEVENT_RESIZED:
+ SDL_Log("SDL EVENT: Window %d resized to %dx%d",
+ event->window.windowID, event->window.data1,
+ event->window.data2);
+ break;
+ case SDL_WINDOWEVENT_SIZE_CHANGED:
+ SDL_Log("SDL EVENT: Window %d changed size to %dx%d",
+ event->window.windowID, event->window.data1,
+ event->window.data2);
+ break;
+ case SDL_WINDOWEVENT_MINIMIZED:
+ SDL_Log("SDL EVENT: Window %d minimized", event->window.windowID);
+ break;
+ case SDL_WINDOWEVENT_MAXIMIZED:
+ SDL_Log("SDL EVENT: Window %d maximized", event->window.windowID);
+ break;
+ case SDL_WINDOWEVENT_RESTORED:
+ SDL_Log("SDL EVENT: Window %d restored", event->window.windowID);
+ break;
+ case SDL_WINDOWEVENT_ENTER:
+ SDL_Log("SDL EVENT: Mouse entered window %d",
+ event->window.windowID);
+ break;
+ case SDL_WINDOWEVENT_LEAVE:
+ SDL_Log("SDL EVENT: Mouse left window %d", event->window.windowID);
+ break;
+ case SDL_WINDOWEVENT_FOCUS_GAINED:
+ SDL_Log("SDL EVENT: Window %d gained keyboard focus",
+ event->window.windowID);
+ break;
+ case SDL_WINDOWEVENT_FOCUS_LOST:
+ SDL_Log("SDL EVENT: Window %d lost keyboard focus",
+ event->window.windowID);
+ break;
+ case SDL_WINDOWEVENT_CLOSE:
+ SDL_Log("SDL EVENT: Window %d closed", event->window.windowID);
+ break;
+ case SDL_WINDOWEVENT_TAKE_FOCUS:
+ SDL_Log("SDL EVENT: Window %d take focus", event->window.windowID);
+ break;
+ case SDL_WINDOWEVENT_HIT_TEST:
+ SDL_Log("SDL EVENT: Window %d hit test", event->window.windowID);
+ break;
+ default:
+ SDL_Log("SDL EVENT: Window %d got unknown event 0x%4.4x",
+ event->window.windowID, event->window.event);
+ break;
+ }
+ break;
+ case SDL_KEYDOWN:
+ SDL_Log("SDL EVENT: Keyboard: key pressed in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
+ event->key.windowID,
+ event->key.keysym.scancode,
+ SDL_GetScancodeName(event->key.keysym.scancode),
+ event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
+ break;
+ case SDL_KEYUP:
+ SDL_Log("SDL EVENT: Keyboard: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
+ event->key.windowID,
+ event->key.keysym.scancode,
+ SDL_GetScancodeName(event->key.keysym.scancode),
+ event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
+ break;
+ case SDL_TEXTEDITING:
+ SDL_Log("SDL EVENT: Keyboard: text editing \"%s\" in window %d",
+ event->edit.text, event->edit.windowID);
+ break;
+ case SDL_TEXTINPUT:
+ SDL_Log("SDL EVENT: Keyboard: text input \"%s\" in window %d",
+ event->text.text, event->text.windowID);
+ break;
+ case SDL_KEYMAPCHANGED:
+ SDL_Log("SDL EVENT: Keymap changed");
+ break;
+ case SDL_MOUSEMOTION:
+ SDL_Log("SDL EVENT: Mouse: moved to %d,%d (%d,%d) in window %d",
+ event->motion.x, event->motion.y,
+ event->motion.xrel, event->motion.yrel,
+ event->motion.windowID);
+ break;
+ case SDL_MOUSEBUTTONDOWN:
+ SDL_Log("SDL EVENT: Mouse: button %d pressed at %d,%d with click count %d in window %d",
+ event->button.button, event->button.x, event->button.y, event->button.clicks,
+ event->button.windowID);
+ break;
+ case SDL_MOUSEBUTTONUP:
+ SDL_Log("SDL EVENT: Mouse: button %d released at %d,%d with click count %d in window %d",
+ event->button.button, event->button.x, event->button.y, event->button.clicks,
+ event->button.windowID);
+ break;
+ case SDL_MOUSEWHEEL:
+ SDL_Log("SDL EVENT: Mouse: wheel scrolled %d in x and %d in y (reversed: %d) in window %d",
+ event->wheel.x, event->wheel.y, event->wheel.direction, event->wheel.windowID);
+ break;
+ case SDL_JOYDEVICEADDED:
+ SDL_Log("SDL EVENT: Joystick index %d attached",
+ event->jdevice.which);
+ break;
+ case SDL_JOYDEVICEREMOVED:
+ SDL_Log("SDL EVENT: Joystick %d removed",
+ event->jdevice.which);
+ break;
+ case SDL_JOYBALLMOTION:
+ SDL_Log("SDL EVENT: Joystick %d: ball %d moved by %d,%d",
+ event->jball.which, event->jball.ball, event->jball.xrel,
+ event->jball.yrel);
+ break;
+ case SDL_JOYHATMOTION:
+ {
+ const char *position = "UNKNOWN";
+ switch (event->jhat.value) {
+ case SDL_HAT_CENTERED:
+ position = "CENTER";
+ break;
+ case SDL_HAT_UP:
+ position = "UP";
+ break;
+ case SDL_HAT_RIGHTUP:
+ position = "RIGHTUP";
+ break;
+ case SDL_HAT_RIGHT:
+ position = "RIGHT";
+ break;
+ case SDL_HAT_RIGHTDOWN:
+ position = "RIGHTDOWN";
+ break;
+ case SDL_HAT_DOWN:
+ position = "DOWN";
+ break;
+ case SDL_HAT_LEFTDOWN:
+ position = "LEFTDOWN";
+ break;
+ case SDL_HAT_LEFT:
+ position = "LEFT";
+ break;
+ case SDL_HAT_LEFTUP:
+ position = "LEFTUP";
+ break;
+ }
+ SDL_Log("SDL EVENT: Joystick %d: hat %d moved to %s", event->jhat.which,
+ event->jhat.hat, position);
+ }
+ break;
+ case SDL_JOYBUTTONDOWN:
+ SDL_Log("SDL EVENT: Joystick %d: button %d pressed",
+ event->jbutton.which, event->jbutton.button);
+ break;
+ case SDL_JOYBUTTONUP:
+ SDL_Log("SDL EVENT: Joystick %d: button %d released",
+ event->jbutton.which, event->jbutton.button);
+ break;
+ case SDL_CONTROLLERDEVICEADDED:
+ SDL_Log("SDL EVENT: Controller index %d attached",
+ event->cdevice.which);
+ break;
+ case SDL_CONTROLLERDEVICEREMOVED:
+ SDL_Log("SDL EVENT: Controller %d removed",
+ event->cdevice.which);
+ break;
+ case SDL_CONTROLLERAXISMOTION:
+ SDL_Log("SDL EVENT: Controller %d axis %d ('%s') value: %d",
+ event->caxis.which,
+ event->caxis.axis,
+ ControllerAxisName((SDL_GameControllerAxis)event->caxis.axis),
+ event->caxis.value);
+ break;
+ case SDL_CONTROLLERBUTTONDOWN:
+ SDL_Log("SDL EVENT: Controller %d button %d ('%s') down",
+ event->cbutton.which, event->cbutton.button,
+ ControllerButtonName((SDL_GameControllerButton)event->cbutton.button));
+ break;
+ case SDL_CONTROLLERBUTTONUP:
+ SDL_Log("SDL EVENT: Controller %d button %d ('%s') up",
+ event->cbutton.which, event->cbutton.button,
+ ControllerButtonName((SDL_GameControllerButton)event->cbutton.button));
+ break;
+ case SDL_CLIPBOARDUPDATE:
+ SDL_Log("SDL EVENT: Clipboard updated");
+ break;
+
+ case SDL_FINGERMOTION:
+ SDL_Log("SDL EVENT: Finger: motion touch=%ld, finger=%ld, x=%f, y=%f, dx=%f, dy=%f, pressure=%f",
+ (long) event->tfinger.touchId,
+ (long) event->tfinger.fingerId,
+ event->tfinger.x, event->tfinger.y,
+ event->tfinger.dx, event->tfinger.dy, event->tfinger.pressure);
+ break;
+ case SDL_FINGERDOWN:
+ case SDL_FINGERUP:
+ SDL_Log("SDL EVENT: Finger: %s touch=%ld, finger=%ld, x=%f, y=%f, dx=%f, dy=%f, pressure=%f",
+ (event->type == SDL_FINGERDOWN) ? "down" : "up",
+ (long) event->tfinger.touchId,
+ (long) event->tfinger.fingerId,
+ event->tfinger.x, event->tfinger.y,
+ event->tfinger.dx, event->tfinger.dy, event->tfinger.pressure);
+ break;
+ case SDL_DOLLARGESTURE:
+ SDL_Log("SDL_EVENT: Dollar gesture detect: %ld", (long) event->dgesture.gestureId);
+ break;
+ case SDL_DOLLARRECORD:
+ SDL_Log("SDL_EVENT: Dollar gesture record: %ld", (long) event->dgesture.gestureId);
+ break;
+ case SDL_MULTIGESTURE:
+ SDL_Log("SDL_EVENT: Multi gesture fingers: %d", event->mgesture.numFingers);
+ break;
+
+ case SDL_RENDER_DEVICE_RESET:
+ SDL_Log("SDL EVENT: render device reset");
+ break;
+ case SDL_RENDER_TARGETS_RESET:
+ SDL_Log("SDL EVENT: render targets reset");
+ break;
+
+ case SDL_APP_TERMINATING:
+ SDL_Log("SDL EVENT: App terminating");
+ break;
+ case SDL_APP_LOWMEMORY:
+ SDL_Log("SDL EVENT: App running low on memory");
+ break;
+ case SDL_APP_WILLENTERBACKGROUND:
+ SDL_Log("SDL EVENT: App will enter the background");
+ break;
+ case SDL_APP_DIDENTERBACKGROUND:
+ SDL_Log("SDL EVENT: App entered the background");
+ break;
+ case SDL_APP_WILLENTERFOREGROUND:
+ SDL_Log("SDL EVENT: App will enter the foreground");
+ break;
+ case SDL_APP_DIDENTERFOREGROUND:
+ SDL_Log("SDL EVENT: App entered the foreground");
+ break;
+
+ case SDL_QUIT:
+ SDL_Log("SDL EVENT: Quit requested");
+ break;
+ case SDL_USEREVENT:
+ SDL_Log("SDL EVENT: User event %d", event->user.code);
+ break;
+ default:
+ SDL_Log("Unknown event 0x%4.4x", event->type);
+ break;
+ }
+}
+
+static void
+SDLTest_ScreenShot(SDL_Renderer *renderer)
+{
+ SDL_Rect viewport;
+ SDL_Surface *surface;
+
+ if (!renderer) {
+ return;
+ }
+
+ SDL_RenderGetViewport(renderer, &viewport);
+ surface = SDL_CreateRGBSurface(0, viewport.w, viewport.h, 24,
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+ 0x00FF0000, 0x0000FF00, 0x000000FF,
+#else
+ 0x000000FF, 0x0000FF00, 0x00FF0000,
+#endif
+ 0x00000000);
+ if (!surface) {
+ SDL_Log("Couldn't create surface: %s\n", SDL_GetError());
+ return;
+ }
+
+ if (SDL_RenderReadPixels(renderer, NULL, surface->format->format,
+ surface->pixels, surface->pitch) < 0) {
+ SDL_Log("Couldn't read screen: %s\n", SDL_GetError());
+ SDL_free(surface);
+ return;
+ }
+
+ if (SDL_SaveBMP(surface, "screenshot.bmp") < 0) {
+ SDL_Log("Couldn't save screenshot.bmp: %s\n", SDL_GetError());
+ SDL_free(surface);
+ return;
+ }
+}
+
+static void
+FullscreenTo(int index, int windowId)
+{
+ Uint32 flags;
+ struct SDL_Rect rect = { 0, 0, 0, 0 };
+ SDL_Window *window = SDL_GetWindowFromID(windowId);
+ if (!window) {
+ return;
+ }
+
+ SDL_GetDisplayBounds( index, &rect );
+
+ flags = SDL_GetWindowFlags(window);
+ if (flags & SDL_WINDOW_FULLSCREEN) {
+ SDL_SetWindowFullscreen( window, SDL_FALSE );
+ SDL_Delay( 15 );
+ }
+
+ SDL_SetWindowPosition( window, rect.x, rect.y );
+ SDL_SetWindowFullscreen( window, SDL_TRUE );
+}
+
+void
+SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
+{
+ int i;
+ static SDL_MouseMotionEvent lastEvent;
+
+ if (state->verbose & VERBOSE_EVENT) {
+ SDLTest_PrintEvent(event);
+ }
+
+ switch (event->type) {
+ case SDL_WINDOWEVENT:
+ switch (event->window.event) {
+ case SDL_WINDOWEVENT_CLOSE:
+ {
+ SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
+ if (window) {
+ for (i = 0; i < state->num_windows; ++i) {
+ if (window == state->windows[i]) {
+ if (state->targets[i]) {
+ SDL_DestroyTexture(state->targets[i]);
+ state->targets[i] = NULL;
+ }
+ if (state->renderers[i]) {
+ SDL_DestroyRenderer(state->renderers[i]);
+ state->renderers[i] = NULL;
+ }
+ SDL_DestroyWindow(state->windows[i]);
+ state->windows[i] = NULL;
+ break;
+ }
+ }
+ }
+ }
+ break;
+ }
+ break;
+ case SDL_KEYDOWN: {
+ SDL_bool withControl = !!(event->key.keysym.mod & KMOD_CTRL);
+ SDL_bool withShift = !!(event->key.keysym.mod & KMOD_SHIFT);
+ SDL_bool withAlt = !!(event->key.keysym.mod & KMOD_ALT);
+
+ switch (event->key.keysym.sym) {
+ /* Add hotkeys here */
+ case SDLK_PRINTSCREEN: {
+ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
+ if (window) {
+ for (i = 0; i < state->num_windows; ++i) {
+ if (window == state->windows[i]) {
+ SDLTest_ScreenShot(state->renderers[i]);
+ }
+ }
+ }
+ }
+ break;
+ case SDLK_EQUALS:
+ if (withControl) {
+ /* Ctrl-+ double the size of the window */
+ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
+ if (window) {
+ int w, h;
+ SDL_GetWindowSize(window, &w, &h);
+ SDL_SetWindowSize(window, w*2, h*2);
+ }
+ }
+ break;
+ case SDLK_MINUS:
+ if (withControl) {
+ /* Ctrl-- half the size of the window */
+ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
+ if (window) {
+ int w, h;
+ SDL_GetWindowSize(window, &w, &h);
+ SDL_SetWindowSize(window, w/2, h/2);
+ }
+ }
+ break;
+ case SDLK_UP:
+ case SDLK_DOWN:
+ case SDLK_LEFT:
+ case SDLK_RIGHT:
+ if (withAlt) {
+ /* Alt-Up/Down/Left/Right switches between displays */
+ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
+ if (window) {
+ int currentIndex = SDL_GetWindowDisplayIndex(window);
+ int numDisplays = SDL_GetNumVideoDisplays();
+
+ if (currentIndex >= 0 && numDisplays >= 1) {
+ int dest;
+ if (event->key.keysym.sym == SDLK_UP || event->key.keysym.sym == SDLK_LEFT) {
+ dest = (currentIndex + numDisplays - 1) % numDisplays;
+ } else {
+ dest = (currentIndex + numDisplays + 1) % numDisplays;
+ }
+ SDL_Log("Centering on display %d\n", dest);
+ SDL_SetWindowPosition(window,
+ SDL_WINDOWPOS_CENTERED_DISPLAY(dest),
+ SDL_WINDOWPOS_CENTERED_DISPLAY(dest));
+ }
+ }
+ }
+ if (withShift) {
+ /* Shift-Up/Down/Left/Right shift the window by 100px */
+ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
+ if (window) {
+ const int delta = 100;
+ int x, y;
+ SDL_GetWindowPosition(window, &x, &y);
+
+ if (event->key.keysym.sym == SDLK_UP) y -= delta;
+ if (event->key.keysym.sym == SDLK_DOWN) y += delta;
+ if (event->key.keysym.sym == SDLK_LEFT) x -= delta;
+ if (event->key.keysym.sym == SDLK_RIGHT) x += delta;
+
+ SDL_Log("Setting position to (%d, %d)\n", x, y);
+ SDL_SetWindowPosition(window, x, y);
+ }
+ }
+ break;
+ case SDLK_o:
+ if (withControl) {
+ /* Ctrl-O (or Ctrl-Shift-O) changes window opacity. */
+ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
+ if (window) {
+ float opacity;
+ if (SDL_GetWindowOpacity(window, &opacity) == 0) {
+ if (withShift) {
+ opacity += 0.20f;
+ } else {
+ opacity -= 0.20f;
+ }
+ SDL_SetWindowOpacity(window, opacity);
+ }
+ }
+ }
+ break;
+
+ case SDLK_c:
+ if (withControl) {
+ /* Ctrl-C copy awesome text! */
+ SDL_SetClipboardText("SDL rocks!\nYou know it!");
+ printf("Copied text to clipboard\n");
+ }
+ if (withAlt) {
+ /* Alt-C toggle a render clip rectangle */
+ for (i = 0; i < state->num_windows; ++i) {
+ int w, h;
+ if (state->renderers[i]) {
+ SDL_Rect clip;
+ SDL_GetWindowSize(state->windows[i], &w, &h);
+ SDL_RenderGetClipRect(state->renderers[i], &clip);
+ if (SDL_RectEmpty(&clip)) {
+ clip.x = w/4;
+ clip.y = h/4;
+ clip.w = w/2;
+ clip.h = h/2;
+ SDL_RenderSetClipRect(state->renderers[i], &clip);
+ } else {
+ SDL_RenderSetClipRect(state->renderers[i], NULL);
+ }
+ }
+ }
+ }
+ if (withShift) {
+ SDL_Window *current_win = SDL_GetKeyboardFocus();
+ if (current_win) {
+ const SDL_bool shouldCapture = (SDL_GetWindowFlags(current_win) & SDL_WINDOW_MOUSE_CAPTURE) == 0;
+ const int rc = SDL_CaptureMouse(shouldCapture);
+ SDL_Log("%sapturing mouse %s!\n", shouldCapture ? "C" : "Unc", (rc == 0) ? "succeeded" : "failed");
+ }
+ }
+ break;
+ case SDLK_v:
+ if (withControl) {
+ /* Ctrl-V paste awesome text! */
+ char *text = SDL_GetClipboardText();
+ if (*text) {
+ printf("Clipboard: %s\n", text);
+ } else {
+ printf("Clipboard is empty\n");
+ }
+ SDL_free(text);
+ }
+ break;
+ case SDLK_g:
+ if (withControl) {
+ /* Ctrl-G toggle grab */
+ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
+ if (window) {
+ SDL_SetWindowGrab(window, !SDL_GetWindowGrab(window) ? SDL_TRUE : SDL_FALSE);
+ }
+ }
+ break;
+ case SDLK_m:
+ if (withControl) {
+ /* Ctrl-M maximize */
+ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
+ if (window) {
+ Uint32 flags = SDL_GetWindowFlags(window);
+ if (flags & SDL_WINDOW_MAXIMIZED) {
+ SDL_RestoreWindow(window);
+ } else {
+ SDL_MaximizeWindow(window);
+ }
+ }
+ }
+ break;
+ case SDLK_r:
+ if (withControl) {
+ /* Ctrl-R toggle mouse relative mode */
+ SDL_SetRelativeMouseMode(!SDL_GetRelativeMouseMode() ? SDL_TRUE : SDL_FALSE);
+ }
+ break;
+ case SDLK_z:
+ if (withControl) {
+ /* Ctrl-Z minimize */
+ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
+ if (window) {
+ SDL_MinimizeWindow(window);
+ }
+ }
+ break;
+ case SDLK_RETURN:
+ if (withControl) {
+ /* Ctrl-Enter toggle fullscreen */
+ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
+ if (window) {
+ Uint32 flags = SDL_GetWindowFlags(window);
+ if (flags & SDL_WINDOW_FULLSCREEN) {
+ SDL_SetWindowFullscreen(window, SDL_FALSE);
+ } else {
+ SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
+ }
+ }
+ } else if (withAlt) {
+ /* Alt-Enter toggle fullscreen desktop */
+ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
+ if (window) {
+ Uint32 flags = SDL_GetWindowFlags(window);
+ if (flags & SDL_WINDOW_FULLSCREEN) {
+ SDL_SetWindowFullscreen(window, SDL_FALSE);
+ } else {
+ SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
+ }
+ }
+ } else if (withShift) {
+ /* Shift-Enter toggle fullscreen desktop / fullscreen */
+ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
+ if (window) {
+ Uint32 flags = SDL_GetWindowFlags(window);
+ if ((flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
+ SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
+ } else {
+ SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
+ }
+ }
+ }
+
+ break;
+ case SDLK_b:
+ if (withControl) {
+ /* Ctrl-B toggle window border */
+ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
+ if (window) {
+ const Uint32 flags = SDL_GetWindowFlags(window);
+ const SDL_bool b = ((flags & SDL_WINDOW_BORDERLESS) != 0) ? SDL_TRUE : SDL_FALSE;
+ SDL_SetWindowBordered(window, b);
+ }
+ }
+ break;
+ case SDLK_a:
+ if (withControl) {
+ /* Ctrl-A reports absolute mouse position. */
+ int x, y;
+ const Uint32 mask = SDL_GetGlobalMouseState(&x, &y);
+ SDL_Log("ABSOLUTE MOUSE: (%d, %d)%s%s%s%s%s\n", x, y,
+ (mask & SDL_BUTTON_LMASK) ? " [LBUTTON]" : "",
+ (mask & SDL_BUTTON_MMASK) ? " [MBUTTON]" : "",
+ (mask & SDL_BUTTON_RMASK) ? " [RBUTTON]" : "",
+ (mask & SDL_BUTTON_X1MASK) ? " [X2BUTTON]" : "",
+ (mask & SDL_BUTTON_X2MASK) ? " [X2BUTTON]" : "");
+ }
+ break;
+ case SDLK_0:
+ if (withControl) {
+ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
+ SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Test Message", "You're awesome!", window);
+ }
+ break;
+ case SDLK_1:
+ if (withControl) {
+ FullscreenTo(0, event->key.windowID);
+ }
+ break;
+ case SDLK_2:
+ if (withControl) {
+ FullscreenTo(1, event->key.windowID);
+ }
+ break;
+ case SDLK_ESCAPE:
+ *done = 1;
+ break;
+ case SDLK_SPACE:
+ {
+ char message[256];
+ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
+
+ SDL_snprintf(message, sizeof(message), "(%i, %i), rel (%i, %i)\n", lastEvent.x, lastEvent.y, lastEvent.xrel, lastEvent.yrel);
+ SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Last mouse position", message, window);
+ break;
+ }
+ default:
+ break;
+ }
+ break;
+ }
+ case SDL_QUIT:
+ *done = 1;
+ break;
+ case SDL_MOUSEMOTION:
+ lastEvent = event->motion;
+ break;
+ }
+}
+
+void
+SDLTest_CommonQuit(SDLTest_CommonState * state)
+{
+ int i;
+
+ SDL_free(state->windows);
+ if (state->targets) {
+ for (i = 0; i < state->num_windows; ++i) {
+ if (state->targets[i]) {
+ SDL_DestroyTexture(state->targets[i]);
+ }
+ }
+ SDL_free(state->targets);
+ }
+ if (state->renderers) {
+ for (i = 0; i < state->num_windows; ++i) {
+ if (state->renderers[i]) {
+ SDL_DestroyRenderer(state->renderers[i]);
+ }
+ }
+ SDL_free(state->renderers);
+ }
+ if (state->flags & SDL_INIT_VIDEO) {
+ SDL_VideoQuit();
+ }
+ if (state->flags & SDL_INIT_AUDIO) {
+ SDL_AudioQuit();
+ }
+ SDL_free(state);
+ SDL_Quit();
+ SDLTest_LogAllocations();
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/test/SDL_test_compare.c b/src/3rdparty/SDL2/src/test/SDL_test_compare.c
new file mode 100644
index 0000000..d4e3e71
--- /dev/null
+++ b/src/3rdparty/SDL2/src/test/SDL_test_compare.c
@@ -0,0 +1,117 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+
+ Based on automated SDL_Surface tests originally written by Edgar Simo 'bobbens'.
+
+ Rewritten for test lib by Andreas Schiffler.
+
+*/
+
+#include "SDL_config.h"
+
+#include "SDL_test.h"
+
+
+/* Counter for _CompareSurface calls; used for filename creation when comparisons fail */
+static int _CompareSurfaceCount = 0;
+
+/* Compare surfaces */
+int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error)
+{
+ int ret;
+ int i,j;
+ int bpp, bpp_reference;
+ Uint8 *p, *p_reference;
+ int dist;
+ int sampleErrorX = 0, sampleErrorY = 0, sampleDist = 0;
+ Uint8 R, G, B, A;
+ Uint8 Rd, Gd, Bd, Ad;
+ char imageFilename[128];
+ char referenceFilename[128];
+
+ /* Validate input surfaces */
+ if (surface == NULL || referenceSurface == NULL) {
+ return -1;
+ }
+
+ /* Make sure surface size is the same. */
+ if ((surface->w != referenceSurface->w) || (surface->h != referenceSurface->h)) {
+ return -2;
+ }
+
+ /* Sanitize input value */
+ if (allowable_error<0) {
+ allowable_error = 0;
+ }
+
+ SDL_LockSurface( surface );
+ SDL_LockSurface( referenceSurface );
+
+ ret = 0;
+ bpp = surface->format->BytesPerPixel;
+ bpp_reference = referenceSurface->format->BytesPerPixel;
+ /* Compare image - should be same format. */
+ for (j=0; j<surface->h; j++) {
+ for (i=0; i<surface->w; i++) {
+ p = (Uint8 *)surface->pixels + j * surface->pitch + i * bpp;
+ p_reference = (Uint8 *)referenceSurface->pixels + j * referenceSurface->pitch + i * bpp_reference;
+
+ SDL_GetRGBA(*(Uint32*)p, surface->format, &R, &G, &B, &A);
+ SDL_GetRGBA(*(Uint32*)p_reference, referenceSurface->format, &Rd, &Gd, &Bd, &Ad);
+
+ dist = 0;
+ dist += (R-Rd)*(R-Rd);
+ dist += (G-Gd)*(G-Gd);
+ dist += (B-Bd)*(B-Bd);
+
+ /* Allow some difference in blending accuracy */
+ if (dist > allowable_error) {
+ ret++;
+ if (ret == 1) {
+ sampleErrorX = i;
+ sampleErrorY = j;
+ sampleDist = dist;
+ }
+ }
+ }
+ }
+
+ SDL_UnlockSurface( surface );
+ SDL_UnlockSurface( referenceSurface );
+
+ /* Save test image and reference for analysis on failures */
+ _CompareSurfaceCount++;
+ if (ret != 0) {
+ SDLTest_LogError("Comparison of pixels with allowable error of %i failed %i times.", allowable_error, ret);
+ SDLTest_LogError("First detected occurrence at position %i,%i with a squared RGB-difference of %i.", sampleErrorX, sampleErrorY, sampleDist);
+ SDL_snprintf(imageFilename, 127, "CompareSurfaces%04d_TestOutput.bmp", _CompareSurfaceCount);
+ SDL_SaveBMP(surface, imageFilename);
+ SDL_snprintf(referenceFilename, 127, "CompareSurfaces%04d_Reference.bmp", _CompareSurfaceCount);
+ SDL_SaveBMP(referenceSurface, referenceFilename);
+ SDLTest_LogError("Surfaces from failed comparison saved as '%s' and '%s'", imageFilename, referenceFilename);
+ }
+
+ return ret;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/test/SDL_test_crc32.c b/src/3rdparty/SDL2/src/test/SDL_test_crc32.c
new file mode 100644
index 0000000..ea6b0a8
--- /dev/null
+++ b/src/3rdparty/SDL2/src/test/SDL_test_crc32.c
@@ -0,0 +1,166 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+
+ Used by the test execution component.
+ Original source code contributed by A. Schiffler for GSOC project.
+
+*/
+
+#include "SDL_config.h"
+
+#include "SDL_test.h"
+
+
+int SDLTest_Crc32Init(SDLTest_Crc32Context *crcContext)
+{
+ int i,j;
+ CrcUint32 c;
+
+ /* Sanity check context pointer */
+ if (crcContext==NULL) {
+ return -1;
+ }
+
+ /*
+ * Build auxiliary table for parallel byte-at-a-time CRC-32
+ */
+#ifdef ORIGINAL_METHOD
+ for (i = 0; i < 256; ++i) {
+ for (c = i << 24, j = 8; j > 0; --j) {
+ c = c & 0x80000000 ? (c << 1) ^ CRC32_POLY : (c << 1);
+ }
+ crcContext->crc32_table[i] = c;
+ }
+#else
+ for (i=0; i<256; i++) {
+ c = i;
+ for (j=8; j>0; j--) {
+ if (c & 1) {
+ c = (c >> 1) ^ CRC32_POLY;
+ } else {
+ c >>= 1;
+ }
+ }
+ crcContext->crc32_table[i] = c;
+ }
+#endif
+
+ return 0;
+}
+
+/* Complete CRC32 calculation on a memory block */
+int SDLTest_Crc32Calc(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32)
+{
+ if (SDLTest_Crc32CalcStart(crcContext,crc32)) {
+ return -1;
+ }
+
+ if (SDLTest_Crc32CalcBuffer(crcContext, inBuf, inLen, crc32)) {
+ return -1;
+ }
+
+ if (SDLTest_Crc32CalcEnd(crcContext, crc32)) {
+ return -1;
+ }
+
+ return 0;
+}
+
+/* Start crc calculation */
+
+int SDLTest_Crc32CalcStart(SDLTest_Crc32Context * crcContext, CrcUint32 *crc32)
+{
+ /* Sanity check pointers */
+ if (crcContext==NULL) {
+ *crc32=0;
+ return -1;
+ }
+
+ /*
+ * Preload shift register, per CRC-32 spec
+ */
+ *crc32 = 0xffffffff;
+
+ return 0;
+}
+
+/* Finish crc calculation */
+
+int SDLTest_Crc32CalcEnd(SDLTest_Crc32Context * crcContext, CrcUint32 *crc32)
+{
+ /* Sanity check pointers */
+ if (crcContext==NULL) {
+ *crc32=0;
+ return -1;
+ }
+
+ /*
+ * Return complement, per CRC-32 spec
+ */
+ *crc32 = (~(*crc32));
+
+ return 0;
+}
+
+/* Include memory block in crc */
+
+int SDLTest_Crc32CalcBuffer(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32)
+{
+ CrcUint8 *p;
+ register CrcUint32 crc;
+
+ if (crcContext==NULL) {
+ *crc32=0;
+ return -1;
+ }
+
+ if (inBuf==NULL) {
+ return -1;
+ }
+
+ /*
+ * Calculate CRC from data
+ */
+ crc = *crc32;
+ for (p = inBuf; inLen > 0; ++p, --inLen) {
+#ifdef ORIGINAL_METHOD
+ crc = (crc << 8) ^ crcContext->crc32_table[(crc >> 24) ^ *p];
+#else
+ crc = ((crc >> 8) & 0x00FFFFFF) ^ crcContext->crc32_table[ (crc ^ *p) & 0xFF ];
+#endif
+ }
+ *crc32 = crc;
+
+ return 0;
+}
+
+int SDLTest_Crc32Done(SDLTest_Crc32Context * crcContext)
+{
+ if (crcContext==NULL) {
+ return -1;
+ }
+
+ return 0;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/test/SDL_test_font.c b/src/3rdparty/SDL2/src/test/SDL_test_font.c
new file mode 100644
index 0000000..7825cc6
--- /dev/null
+++ b/src/3rdparty/SDL2/src/test/SDL_test_font.c
@@ -0,0 +1,3250 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#include "SDL_test.h"
+
+/* ---- 8x8 font definition ---- */
+
+/* Originally part of SDL2_gfx */
+
+/* ZLIB (c) A. Schiffler 2012 */
+
+#define SDL_TESTFONTDATAMAX (8*256)
+
+static unsigned char SDLTest_FontData[SDL_TESTFONTDATAMAX] = {
+
+ /*
+ * 0 0x00 '^@'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 1 0x01 '^A'
+ */
+ 0x7e, /* 01111110 */
+ 0x81, /* 10000001 */
+ 0xa5, /* 10100101 */
+ 0x81, /* 10000001 */
+ 0xbd, /* 10111101 */
+ 0x99, /* 10011001 */
+ 0x81, /* 10000001 */
+ 0x7e, /* 01111110 */
+
+ /*
+ * 2 0x02 '^B'
+ */
+ 0x7e, /* 01111110 */
+ 0xff, /* 11111111 */
+ 0xdb, /* 11011011 */
+ 0xff, /* 11111111 */
+ 0xc3, /* 11000011 */
+ 0xe7, /* 11100111 */
+ 0xff, /* 11111111 */
+ 0x7e, /* 01111110 */
+
+ /*
+ * 3 0x03 '^C'
+ */
+ 0x6c, /* 01101100 */
+ 0xfe, /* 11111110 */
+ 0xfe, /* 11111110 */
+ 0xfe, /* 11111110 */
+ 0x7c, /* 01111100 */
+ 0x38, /* 00111000 */
+ 0x10, /* 00010000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 4 0x04 '^D'
+ */
+ 0x10, /* 00010000 */
+ 0x38, /* 00111000 */
+ 0x7c, /* 01111100 */
+ 0xfe, /* 11111110 */
+ 0x7c, /* 01111100 */
+ 0x38, /* 00111000 */
+ 0x10, /* 00010000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 5 0x05 '^E'
+ */
+ 0x38, /* 00111000 */
+ 0x7c, /* 01111100 */
+ 0x38, /* 00111000 */
+ 0xfe, /* 11111110 */
+ 0xfe, /* 11111110 */
+ 0xd6, /* 11010110 */
+ 0x10, /* 00010000 */
+ 0x38, /* 00111000 */
+
+ /*
+ * 6 0x06 '^F'
+ */
+ 0x10, /* 00010000 */
+ 0x38, /* 00111000 */
+ 0x7c, /* 01111100 */
+ 0xfe, /* 11111110 */
+ 0xfe, /* 11111110 */
+ 0x7c, /* 01111100 */
+ 0x10, /* 00010000 */
+ 0x38, /* 00111000 */
+
+ /*
+ * 7 0x07 '^G'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x18, /* 00011000 */
+ 0x3c, /* 00111100 */
+ 0x3c, /* 00111100 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 8 0x08 '^H'
+ */
+ 0xff, /* 11111111 */
+ 0xff, /* 11111111 */
+ 0xe7, /* 11100111 */
+ 0xc3, /* 11000011 */
+ 0xc3, /* 11000011 */
+ 0xe7, /* 11100111 */
+ 0xff, /* 11111111 */
+ 0xff, /* 11111111 */
+
+ /*
+ * 9 0x09 '^I'
+ */
+ 0x00, /* 00000000 */
+ 0x3c, /* 00111100 */
+ 0x66, /* 01100110 */
+ 0x42, /* 01000010 */
+ 0x42, /* 01000010 */
+ 0x66, /* 01100110 */
+ 0x3c, /* 00111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 10 0x0a '^J'
+ */
+ 0xff, /* 11111111 */
+ 0xc3, /* 11000011 */
+ 0x99, /* 10011001 */
+ 0xbd, /* 10111101 */
+ 0xbd, /* 10111101 */
+ 0x99, /* 10011001 */
+ 0xc3, /* 11000011 */
+ 0xff, /* 11111111 */
+
+ /*
+ * 11 0x0b '^K'
+ */
+ 0x0f, /* 00001111 */
+ 0x07, /* 00000111 */
+ 0x0f, /* 00001111 */
+ 0x7d, /* 01111101 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0x78, /* 01111000 */
+
+ /*
+ * 12 0x0c '^L'
+ */
+ 0x3c, /* 00111100 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x3c, /* 00111100 */
+ 0x18, /* 00011000 */
+ 0x7e, /* 01111110 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 13 0x0d '^M'
+ */
+ 0x3f, /* 00111111 */
+ 0x33, /* 00110011 */
+ 0x3f, /* 00111111 */
+ 0x30, /* 00110000 */
+ 0x30, /* 00110000 */
+ 0x70, /* 01110000 */
+ 0xf0, /* 11110000 */
+ 0xe0, /* 11100000 */
+
+ /*
+ * 14 0x0e '^N'
+ */
+ 0x7f, /* 01111111 */
+ 0x63, /* 01100011 */
+ 0x7f, /* 01111111 */
+ 0x63, /* 01100011 */
+ 0x63, /* 01100011 */
+ 0x67, /* 01100111 */
+ 0xe6, /* 11100110 */
+ 0xc0, /* 11000000 */
+
+ /*
+ * 15 0x0f '^O'
+ */
+ 0x18, /* 00011000 */
+ 0xdb, /* 11011011 */
+ 0x3c, /* 00111100 */
+ 0xe7, /* 11100111 */
+ 0xe7, /* 11100111 */
+ 0x3c, /* 00111100 */
+ 0xdb, /* 11011011 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 16 0x10 '^P'
+ */
+ 0x80, /* 10000000 */
+ 0xe0, /* 11100000 */
+ 0xf8, /* 11111000 */
+ 0xfe, /* 11111110 */
+ 0xf8, /* 11111000 */
+ 0xe0, /* 11100000 */
+ 0x80, /* 10000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 17 0x11 '^Q'
+ */
+ 0x02, /* 00000010 */
+ 0x0e, /* 00001110 */
+ 0x3e, /* 00111110 */
+ 0xfe, /* 11111110 */
+ 0x3e, /* 00111110 */
+ 0x0e, /* 00001110 */
+ 0x02, /* 00000010 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 18 0x12 '^R'
+ */
+ 0x18, /* 00011000 */
+ 0x3c, /* 00111100 */
+ 0x7e, /* 01111110 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x7e, /* 01111110 */
+ 0x3c, /* 00111100 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 19 0x13 '^S'
+ */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x00, /* 00000000 */
+ 0x66, /* 01100110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 20 0x14 '^T'
+ */
+ 0x7f, /* 01111111 */
+ 0xdb, /* 11011011 */
+ 0xdb, /* 11011011 */
+ 0x7b, /* 01111011 */
+ 0x1b, /* 00011011 */
+ 0x1b, /* 00011011 */
+ 0x1b, /* 00011011 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 21 0x15 '^U'
+ */
+ 0x3e, /* 00111110 */
+ 0x61, /* 01100001 */
+ 0x3c, /* 00111100 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x3c, /* 00111100 */
+ 0x86, /* 10000110 */
+ 0x7c, /* 01111100 */
+
+ /*
+ * 22 0x16 '^V'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x7e, /* 01111110 */
+ 0x7e, /* 01111110 */
+ 0x7e, /* 01111110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 23 0x17 '^W'
+ */
+ 0x18, /* 00011000 */
+ 0x3c, /* 00111100 */
+ 0x7e, /* 01111110 */
+ 0x18, /* 00011000 */
+ 0x7e, /* 01111110 */
+ 0x3c, /* 00111100 */
+ 0x18, /* 00011000 */
+ 0xff, /* 11111111 */
+
+ /*
+ * 24 0x18 '^X'
+ */
+ 0x18, /* 00011000 */
+ 0x3c, /* 00111100 */
+ 0x7e, /* 01111110 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 25 0x19 '^Y'
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x7e, /* 01111110 */
+ 0x3c, /* 00111100 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 26 0x1a '^Z'
+ */
+ 0x00, /* 00000000 */
+ 0x18, /* 00011000 */
+ 0x0c, /* 00001100 */
+ 0xfe, /* 11111110 */
+ 0x0c, /* 00001100 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 27 0x1b '^['
+ */
+ 0x00, /* 00000000 */
+ 0x30, /* 00110000 */
+ 0x60, /* 01100000 */
+ 0xfe, /* 11111110 */
+ 0x60, /* 01100000 */
+ 0x30, /* 00110000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 28 0x1c '^\'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xc0, /* 11000000 */
+ 0xc0, /* 11000000 */
+ 0xc0, /* 11000000 */
+ 0xfe, /* 11111110 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 29 0x1d '^]'
+ */
+ 0x00, /* 00000000 */
+ 0x24, /* 00100100 */
+ 0x66, /* 01100110 */
+ 0xff, /* 11111111 */
+ 0x66, /* 01100110 */
+ 0x24, /* 00100100 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 30 0x1e '^^'
+ */
+ 0x00, /* 00000000 */
+ 0x18, /* 00011000 */
+ 0x3c, /* 00111100 */
+ 0x7e, /* 01111110 */
+ 0xff, /* 11111111 */
+ 0xff, /* 11111111 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 31 0x1f '^_'
+ */
+ 0x00, /* 00000000 */
+ 0xff, /* 11111111 */
+ 0xff, /* 11111111 */
+ 0x7e, /* 01111110 */
+ 0x3c, /* 00111100 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 32 0x20 ' '
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 33 0x21 '!'
+ */
+ 0x18, /* 00011000 */
+ 0x3c, /* 00111100 */
+ 0x3c, /* 00111100 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 34 0x22 '"'
+ */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x24, /* 00100100 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 35 0x23 '#'
+ */
+ 0x6c, /* 01101100 */
+ 0x6c, /* 01101100 */
+ 0xfe, /* 11111110 */
+ 0x6c, /* 01101100 */
+ 0xfe, /* 11111110 */
+ 0x6c, /* 01101100 */
+ 0x6c, /* 01101100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 36 0x24 '$'
+ */
+ 0x18, /* 00011000 */
+ 0x3e, /* 00111110 */
+ 0x60, /* 01100000 */
+ 0x3c, /* 00111100 */
+ 0x06, /* 00000110 */
+ 0x7c, /* 01111100 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 37 0x25 '%'
+ */
+ 0x00, /* 00000000 */
+ 0xc6, /* 11000110 */
+ 0xcc, /* 11001100 */
+ 0x18, /* 00011000 */
+ 0x30, /* 00110000 */
+ 0x66, /* 01100110 */
+ 0xc6, /* 11000110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 38 0x26 '&'
+ */
+ 0x38, /* 00111000 */
+ 0x6c, /* 01101100 */
+ 0x38, /* 00111000 */
+ 0x76, /* 01110110 */
+ 0xdc, /* 11011100 */
+ 0xcc, /* 11001100 */
+ 0x76, /* 01110110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 39 0x27 '''
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x30, /* 00110000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 40 0x28 '('
+ */
+ 0x0c, /* 00001100 */
+ 0x18, /* 00011000 */
+ 0x30, /* 00110000 */
+ 0x30, /* 00110000 */
+ 0x30, /* 00110000 */
+ 0x18, /* 00011000 */
+ 0x0c, /* 00001100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 41 0x29 ')'
+ */
+ 0x30, /* 00110000 */
+ 0x18, /* 00011000 */
+ 0x0c, /* 00001100 */
+ 0x0c, /* 00001100 */
+ 0x0c, /* 00001100 */
+ 0x18, /* 00011000 */
+ 0x30, /* 00110000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 42 0x2a '*'
+ */
+ 0x00, /* 00000000 */
+ 0x66, /* 01100110 */
+ 0x3c, /* 00111100 */
+ 0xff, /* 11111111 */
+ 0x3c, /* 00111100 */
+ 0x66, /* 01100110 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 43 0x2b '+'
+ */
+ 0x00, /* 00000000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x7e, /* 01111110 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 44 0x2c ','
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x30, /* 00110000 */
+
+ /*
+ * 45 0x2d '-'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x7e, /* 01111110 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 46 0x2e '.'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 47 0x2f '/'
+ */
+ 0x06, /* 00000110 */
+ 0x0c, /* 00001100 */
+ 0x18, /* 00011000 */
+ 0x30, /* 00110000 */
+ 0x60, /* 01100000 */
+ 0xc0, /* 11000000 */
+ 0x80, /* 10000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 48 0x30 '0'
+ */
+ 0x38, /* 00111000 */
+ 0x6c, /* 01101100 */
+ 0xc6, /* 11000110 */
+ 0xd6, /* 11010110 */
+ 0xc6, /* 11000110 */
+ 0x6c, /* 01101100 */
+ 0x38, /* 00111000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 49 0x31 '1'
+ */
+ 0x18, /* 00011000 */
+ 0x38, /* 00111000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x7e, /* 01111110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 50 0x32 '2'
+ */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0x06, /* 00000110 */
+ 0x1c, /* 00011100 */
+ 0x30, /* 00110000 */
+ 0x66, /* 01100110 */
+ 0xfe, /* 11111110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 51 0x33 '3'
+ */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0x06, /* 00000110 */
+ 0x3c, /* 00111100 */
+ 0x06, /* 00000110 */
+ 0xc6, /* 11000110 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 52 0x34 '4'
+ */
+ 0x1c, /* 00011100 */
+ 0x3c, /* 00111100 */
+ 0x6c, /* 01101100 */
+ 0xcc, /* 11001100 */
+ 0xfe, /* 11111110 */
+ 0x0c, /* 00001100 */
+ 0x1e, /* 00011110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 53 0x35 '5'
+ */
+ 0xfe, /* 11111110 */
+ 0xc0, /* 11000000 */
+ 0xc0, /* 11000000 */
+ 0xfc, /* 11111100 */
+ 0x06, /* 00000110 */
+ 0xc6, /* 11000110 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 54 0x36 '6'
+ */
+ 0x38, /* 00111000 */
+ 0x60, /* 01100000 */
+ 0xc0, /* 11000000 */
+ 0xfc, /* 11111100 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 55 0x37 '7'
+ */
+ 0xfe, /* 11111110 */
+ 0xc6, /* 11000110 */
+ 0x0c, /* 00001100 */
+ 0x18, /* 00011000 */
+ 0x30, /* 00110000 */
+ 0x30, /* 00110000 */
+ 0x30, /* 00110000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 56 0x38 '8'
+ */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 57 0x39 '9'
+ */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x7e, /* 01111110 */
+ 0x06, /* 00000110 */
+ 0x0c, /* 00001100 */
+ 0x78, /* 01111000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 58 0x3a ':'
+ */
+ 0x00, /* 00000000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 59 0x3b ';'
+ */
+ 0x00, /* 00000000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x30, /* 00110000 */
+
+ /*
+ * 60 0x3c '<'
+ */
+ 0x06, /* 00000110 */
+ 0x0c, /* 00001100 */
+ 0x18, /* 00011000 */
+ 0x30, /* 00110000 */
+ 0x18, /* 00011000 */
+ 0x0c, /* 00001100 */
+ 0x06, /* 00000110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 61 0x3d '='
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x7e, /* 01111110 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x7e, /* 01111110 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 62 0x3e '>'
+ */
+ 0x60, /* 01100000 */
+ 0x30, /* 00110000 */
+ 0x18, /* 00011000 */
+ 0x0c, /* 00001100 */
+ 0x18, /* 00011000 */
+ 0x30, /* 00110000 */
+ 0x60, /* 01100000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 63 0x3f '?'
+ */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0x0c, /* 00001100 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 64 0x40 '@'
+ */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xde, /* 11011110 */
+ 0xde, /* 11011110 */
+ 0xde, /* 11011110 */
+ 0xc0, /* 11000000 */
+ 0x78, /* 01111000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 65 0x41 'A'
+ */
+ 0x38, /* 00111000 */
+ 0x6c, /* 01101100 */
+ 0xc6, /* 11000110 */
+ 0xfe, /* 11111110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 66 0x42 'B'
+ */
+ 0xfc, /* 11111100 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x7c, /* 01111100 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0xfc, /* 11111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 67 0x43 'C'
+ */
+ 0x3c, /* 00111100 */
+ 0x66, /* 01100110 */
+ 0xc0, /* 11000000 */
+ 0xc0, /* 11000000 */
+ 0xc0, /* 11000000 */
+ 0x66, /* 01100110 */
+ 0x3c, /* 00111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 68 0x44 'D'
+ */
+ 0xf8, /* 11111000 */
+ 0x6c, /* 01101100 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x6c, /* 01101100 */
+ 0xf8, /* 11111000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 69 0x45 'E'
+ */
+ 0xfe, /* 11111110 */
+ 0x62, /* 01100010 */
+ 0x68, /* 01101000 */
+ 0x78, /* 01111000 */
+ 0x68, /* 01101000 */
+ 0x62, /* 01100010 */
+ 0xfe, /* 11111110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 70 0x46 'F'
+ */
+ 0xfe, /* 11111110 */
+ 0x62, /* 01100010 */
+ 0x68, /* 01101000 */
+ 0x78, /* 01111000 */
+ 0x68, /* 01101000 */
+ 0x60, /* 01100000 */
+ 0xf0, /* 11110000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 71 0x47 'G'
+ */
+ 0x3c, /* 00111100 */
+ 0x66, /* 01100110 */
+ 0xc0, /* 11000000 */
+ 0xc0, /* 11000000 */
+ 0xce, /* 11001110 */
+ 0x66, /* 01100110 */
+ 0x3a, /* 00111010 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 72 0x48 'H'
+ */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xfe, /* 11111110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 73 0x49 'I'
+ */
+ 0x3c, /* 00111100 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x3c, /* 00111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 74 0x4a 'J'
+ */
+ 0x1e, /* 00011110 */
+ 0x0c, /* 00001100 */
+ 0x0c, /* 00001100 */
+ 0x0c, /* 00001100 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0x78, /* 01111000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 75 0x4b 'K'
+ */
+ 0xe6, /* 11100110 */
+ 0x66, /* 01100110 */
+ 0x6c, /* 01101100 */
+ 0x78, /* 01111000 */
+ 0x6c, /* 01101100 */
+ 0x66, /* 01100110 */
+ 0xe6, /* 11100110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 76 0x4c 'L'
+ */
+ 0xf0, /* 11110000 */
+ 0x60, /* 01100000 */
+ 0x60, /* 01100000 */
+ 0x60, /* 01100000 */
+ 0x62, /* 01100010 */
+ 0x66, /* 01100110 */
+ 0xfe, /* 11111110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 77 0x4d 'M'
+ */
+ 0xc6, /* 11000110 */
+ 0xee, /* 11101110 */
+ 0xfe, /* 11111110 */
+ 0xfe, /* 11111110 */
+ 0xd6, /* 11010110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 78 0x4e 'N'
+ */
+ 0xc6, /* 11000110 */
+ 0xe6, /* 11100110 */
+ 0xf6, /* 11110110 */
+ 0xde, /* 11011110 */
+ 0xce, /* 11001110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 79 0x4f 'O'
+ */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 80 0x50 'P'
+ */
+ 0xfc, /* 11111100 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x7c, /* 01111100 */
+ 0x60, /* 01100000 */
+ 0x60, /* 01100000 */
+ 0xf0, /* 11110000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 81 0x51 'Q'
+ */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xce, /* 11001110 */
+ 0x7c, /* 01111100 */
+ 0x0e, /* 00001110 */
+
+ /*
+ * 82 0x52 'R'
+ */
+ 0xfc, /* 11111100 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x7c, /* 01111100 */
+ 0x6c, /* 01101100 */
+ 0x66, /* 01100110 */
+ 0xe6, /* 11100110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 83 0x53 'S'
+ */
+ 0x3c, /* 00111100 */
+ 0x66, /* 01100110 */
+ 0x30, /* 00110000 */
+ 0x18, /* 00011000 */
+ 0x0c, /* 00001100 */
+ 0x66, /* 01100110 */
+ 0x3c, /* 00111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 84 0x54 'T'
+ */
+ 0x7e, /* 01111110 */
+ 0x7e, /* 01111110 */
+ 0x5a, /* 01011010 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x3c, /* 00111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 85 0x55 'U'
+ */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 86 0x56 'V'
+ */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x6c, /* 01101100 */
+ 0x38, /* 00111000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 87 0x57 'W'
+ */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xd6, /* 11010110 */
+ 0xd6, /* 11010110 */
+ 0xfe, /* 11111110 */
+ 0x6c, /* 01101100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 88 0x58 'X'
+ */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x6c, /* 01101100 */
+ 0x38, /* 00111000 */
+ 0x6c, /* 01101100 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 89 0x59 'Y'
+ */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x3c, /* 00111100 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x3c, /* 00111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 90 0x5a 'Z'
+ */
+ 0xfe, /* 11111110 */
+ 0xc6, /* 11000110 */
+ 0x8c, /* 10001100 */
+ 0x18, /* 00011000 */
+ 0x32, /* 00110010 */
+ 0x66, /* 01100110 */
+ 0xfe, /* 11111110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 91 0x5b '['
+ */
+ 0x3c, /* 00111100 */
+ 0x30, /* 00110000 */
+ 0x30, /* 00110000 */
+ 0x30, /* 00110000 */
+ 0x30, /* 00110000 */
+ 0x30, /* 00110000 */
+ 0x3c, /* 00111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 92 0x5c '\'
+ */
+ 0xc0, /* 11000000 */
+ 0x60, /* 01100000 */
+ 0x30, /* 00110000 */
+ 0x18, /* 00011000 */
+ 0x0c, /* 00001100 */
+ 0x06, /* 00000110 */
+ 0x02, /* 00000010 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 93 0x5d ']'
+ */
+ 0x3c, /* 00111100 */
+ 0x0c, /* 00001100 */
+ 0x0c, /* 00001100 */
+ 0x0c, /* 00001100 */
+ 0x0c, /* 00001100 */
+ 0x0c, /* 00001100 */
+ 0x3c, /* 00111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 94 0x5e '^'
+ */
+ 0x10, /* 00010000 */
+ 0x38, /* 00111000 */
+ 0x6c, /* 01101100 */
+ 0xc6, /* 11000110 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 95 0x5f '_'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xff, /* 11111111 */
+
+ /*
+ * 96 0x60 '`'
+ */
+ 0x30, /* 00110000 */
+ 0x18, /* 00011000 */
+ 0x0c, /* 00001100 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 97 0x61 'a'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x78, /* 01111000 */
+ 0x0c, /* 00001100 */
+ 0x7c, /* 01111100 */
+ 0xcc, /* 11001100 */
+ 0x76, /* 01110110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 98 0x62 'b'
+ */
+ 0xe0, /* 11100000 */
+ 0x60, /* 01100000 */
+ 0x7c, /* 01111100 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0xdc, /* 11011100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 99 0x63 'c'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xc0, /* 11000000 */
+ 0xc6, /* 11000110 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 100 0x64 'd'
+ */
+ 0x1c, /* 00011100 */
+ 0x0c, /* 00001100 */
+ 0x7c, /* 01111100 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0x76, /* 01110110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 101 0x65 'e'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xfe, /* 11111110 */
+ 0xc0, /* 11000000 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 102 0x66 'f'
+ */
+ 0x3c, /* 00111100 */
+ 0x66, /* 01100110 */
+ 0x60, /* 01100000 */
+ 0xf8, /* 11111000 */
+ 0x60, /* 01100000 */
+ 0x60, /* 01100000 */
+ 0xf0, /* 11110000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 103 0x67 'g'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x76, /* 01110110 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0x7c, /* 01111100 */
+ 0x0c, /* 00001100 */
+ 0xf8, /* 11111000 */
+
+ /*
+ * 104 0x68 'h'
+ */
+ 0xe0, /* 11100000 */
+ 0x60, /* 01100000 */
+ 0x6c, /* 01101100 */
+ 0x76, /* 01110110 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0xe6, /* 11100110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 105 0x69 'i'
+ */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+ 0x38, /* 00111000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x3c, /* 00111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 106 0x6a 'j'
+ */
+ 0x06, /* 00000110 */
+ 0x00, /* 00000000 */
+ 0x06, /* 00000110 */
+ 0x06, /* 00000110 */
+ 0x06, /* 00000110 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x3c, /* 00111100 */
+
+ /*
+ * 107 0x6b 'k'
+ */
+ 0xe0, /* 11100000 */
+ 0x60, /* 01100000 */
+ 0x66, /* 01100110 */
+ 0x6c, /* 01101100 */
+ 0x78, /* 01111000 */
+ 0x6c, /* 01101100 */
+ 0xe6, /* 11100110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 108 0x6c 'l'
+ */
+ 0x38, /* 00111000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x3c, /* 00111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 109 0x6d 'm'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xec, /* 11101100 */
+ 0xfe, /* 11111110 */
+ 0xd6, /* 11010110 */
+ 0xd6, /* 11010110 */
+ 0xd6, /* 11010110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 110 0x6e 'n'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xdc, /* 11011100 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 111 0x6f 'o'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 112 0x70 'p'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xdc, /* 11011100 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x7c, /* 01111100 */
+ 0x60, /* 01100000 */
+ 0xf0, /* 11110000 */
+
+ /*
+ * 113 0x71 'q'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x76, /* 01110110 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0x7c, /* 01111100 */
+ 0x0c, /* 00001100 */
+ 0x1e, /* 00011110 */
+
+ /*
+ * 114 0x72 'r'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xdc, /* 11011100 */
+ 0x76, /* 01110110 */
+ 0x60, /* 01100000 */
+ 0x60, /* 01100000 */
+ 0xf0, /* 11110000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 115 0x73 's'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x7e, /* 01111110 */
+ 0xc0, /* 11000000 */
+ 0x7c, /* 01111100 */
+ 0x06, /* 00000110 */
+ 0xfc, /* 11111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 116 0x74 't'
+ */
+ 0x30, /* 00110000 */
+ 0x30, /* 00110000 */
+ 0xfc, /* 11111100 */
+ 0x30, /* 00110000 */
+ 0x30, /* 00110000 */
+ 0x36, /* 00110110 */
+ 0x1c, /* 00011100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 117 0x75 'u'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0x76, /* 01110110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 118 0x76 'v'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x6c, /* 01101100 */
+ 0x38, /* 00111000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 119 0x77 'w'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xc6, /* 11000110 */
+ 0xd6, /* 11010110 */
+ 0xd6, /* 11010110 */
+ 0xfe, /* 11111110 */
+ 0x6c, /* 01101100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 120 0x78 'x'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xc6, /* 11000110 */
+ 0x6c, /* 01101100 */
+ 0x38, /* 00111000 */
+ 0x6c, /* 01101100 */
+ 0xc6, /* 11000110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 121 0x79 'y'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x7e, /* 01111110 */
+ 0x06, /* 00000110 */
+ 0xfc, /* 11111100 */
+
+ /*
+ * 122 0x7a 'z'
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x7e, /* 01111110 */
+ 0x4c, /* 01001100 */
+ 0x18, /* 00011000 */
+ 0x32, /* 00110010 */
+ 0x7e, /* 01111110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 123 0x7b '{'
+ */
+ 0x0e, /* 00001110 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x70, /* 01110000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x0e, /* 00001110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 124 0x7c '|'
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 125 0x7d '}'
+ */
+ 0x70, /* 01110000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x0e, /* 00001110 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x70, /* 01110000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 126 0x7e '~'
+ */
+ 0x76, /* 01110110 */
+ 0xdc, /* 11011100 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 127 0x7f ''
+ */
+ 0x00, /* 00000000 */
+ 0x10, /* 00010000 */
+ 0x38, /* 00111000 */
+ 0x6c, /* 01101100 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xfe, /* 11111110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 128 0x80 ''
+ */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xc0, /* 11000000 */
+ 0xc0, /* 11000000 */
+ 0xc6, /* 11000110 */
+ 0x7c, /* 01111100 */
+ 0x0c, /* 00001100 */
+ 0x78, /* 01111000 */
+
+ /*
+ * 129 0x81 ''
+ */
+ 0xcc, /* 11001100 */
+ 0x00, /* 00000000 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0x76, /* 01110110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 130 0x82 ''
+ */
+ 0x0c, /* 00001100 */
+ 0x18, /* 00011000 */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xfe, /* 11111110 */
+ 0xc0, /* 11000000 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 131 0x83 ''
+ */
+ 0x7c, /* 01111100 */
+ 0x82, /* 10000010 */
+ 0x78, /* 01111000 */
+ 0x0c, /* 00001100 */
+ 0x7c, /* 01111100 */
+ 0xcc, /* 11001100 */
+ 0x76, /* 01110110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 132 0x84 ''
+ */
+ 0xc6, /* 11000110 */
+ 0x00, /* 00000000 */
+ 0x78, /* 01111000 */
+ 0x0c, /* 00001100 */
+ 0x7c, /* 01111100 */
+ 0xcc, /* 11001100 */
+ 0x76, /* 01110110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 133 0x85 ''
+ */
+ 0x30, /* 00110000 */
+ 0x18, /* 00011000 */
+ 0x78, /* 01111000 */
+ 0x0c, /* 00001100 */
+ 0x7c, /* 01111100 */
+ 0xcc, /* 11001100 */
+ 0x76, /* 01110110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 134 0x86 ''
+ */
+ 0x30, /* 00110000 */
+ 0x30, /* 00110000 */
+ 0x78, /* 01111000 */
+ 0x0c, /* 00001100 */
+ 0x7c, /* 01111100 */
+ 0xcc, /* 11001100 */
+ 0x76, /* 01110110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 135 0x87 ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x7e, /* 01111110 */
+ 0xc0, /* 11000000 */
+ 0xc0, /* 11000000 */
+ 0x7e, /* 01111110 */
+ 0x0c, /* 00001100 */
+ 0x38, /* 00111000 */
+
+ /*
+ * 136 0x88 ''
+ */
+ 0x7c, /* 01111100 */
+ 0x82, /* 10000010 */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xfe, /* 11111110 */
+ 0xc0, /* 11000000 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 137 0x89 ''
+ */
+ 0xc6, /* 11000110 */
+ 0x00, /* 00000000 */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xfe, /* 11111110 */
+ 0xc0, /* 11000000 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 138 0x8a ''
+ */
+ 0x30, /* 00110000 */
+ 0x18, /* 00011000 */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xfe, /* 11111110 */
+ 0xc0, /* 11000000 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 139 0x8b ''
+ */
+ 0x66, /* 01100110 */
+ 0x00, /* 00000000 */
+ 0x38, /* 00111000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x3c, /* 00111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 140 0x8c ''
+ */
+ 0x7c, /* 01111100 */
+ 0x82, /* 10000010 */
+ 0x38, /* 00111000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x3c, /* 00111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 141 0x8d ''
+ */
+ 0x30, /* 00110000 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+ 0x38, /* 00111000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x3c, /* 00111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 142 0x8e ''
+ */
+ 0xc6, /* 11000110 */
+ 0x38, /* 00111000 */
+ 0x6c, /* 01101100 */
+ 0xc6, /* 11000110 */
+ 0xfe, /* 11111110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 143 0x8f ''
+ */
+ 0x38, /* 00111000 */
+ 0x6c, /* 01101100 */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xfe, /* 11111110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 144 0x90 ''
+ */
+ 0x18, /* 00011000 */
+ 0x30, /* 00110000 */
+ 0xfe, /* 11111110 */
+ 0xc0, /* 11000000 */
+ 0xf8, /* 11111000 */
+ 0xc0, /* 11000000 */
+ 0xfe, /* 11111110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 145 0x91 ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x7e, /* 01111110 */
+ 0x18, /* 00011000 */
+ 0x7e, /* 01111110 */
+ 0xd8, /* 11011000 */
+ 0x7e, /* 01111110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 146 0x92 ''
+ */
+ 0x3e, /* 00111110 */
+ 0x6c, /* 01101100 */
+ 0xcc, /* 11001100 */
+ 0xfe, /* 11111110 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0xce, /* 11001110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 147 0x93 ''
+ */
+ 0x7c, /* 01111100 */
+ 0x82, /* 10000010 */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 148 0x94 ''
+ */
+ 0xc6, /* 11000110 */
+ 0x00, /* 00000000 */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 149 0x95 ''
+ */
+ 0x30, /* 00110000 */
+ 0x18, /* 00011000 */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 150 0x96 ''
+ */
+ 0x78, /* 01111000 */
+ 0x84, /* 10000100 */
+ 0x00, /* 00000000 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0x76, /* 01110110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 151 0x97 ''
+ */
+ 0x60, /* 01100000 */
+ 0x30, /* 00110000 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0x76, /* 01110110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 152 0x98 ''
+ */
+ 0xc6, /* 11000110 */
+ 0x00, /* 00000000 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x7e, /* 01111110 */
+ 0x06, /* 00000110 */
+ 0xfc, /* 11111100 */
+
+ /*
+ * 153 0x99 ''
+ */
+ 0xc6, /* 11000110 */
+ 0x38, /* 00111000 */
+ 0x6c, /* 01101100 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x6c, /* 01101100 */
+ 0x38, /* 00111000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 154 0x9a ''
+ */
+ 0xc6, /* 11000110 */
+ 0x00, /* 00000000 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 155 0x9b ''
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x7e, /* 01111110 */
+ 0xc0, /* 11000000 */
+ 0xc0, /* 11000000 */
+ 0x7e, /* 01111110 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 156 0x9c ''
+ */
+ 0x38, /* 00111000 */
+ 0x6c, /* 01101100 */
+ 0x64, /* 01100100 */
+ 0xf0, /* 11110000 */
+ 0x60, /* 01100000 */
+ 0x66, /* 01100110 */
+ 0xfc, /* 11111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 157 0x9d ''
+ */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x3c, /* 00111100 */
+ 0x7e, /* 01111110 */
+ 0x18, /* 00011000 */
+ 0x7e, /* 01111110 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 158 0x9e ''
+ */
+ 0xf8, /* 11111000 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0xfa, /* 11111010 */
+ 0xc6, /* 11000110 */
+ 0xcf, /* 11001111 */
+ 0xc6, /* 11000110 */
+ 0xc7, /* 11000111 */
+
+ /*
+ * 159 0x9f ''
+ */
+ 0x0e, /* 00001110 */
+ 0x1b, /* 00011011 */
+ 0x18, /* 00011000 */
+ 0x3c, /* 00111100 */
+ 0x18, /* 00011000 */
+ 0xd8, /* 11011000 */
+ 0x70, /* 01110000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 160 0xa0 ''
+ */
+ 0x18, /* 00011000 */
+ 0x30, /* 00110000 */
+ 0x78, /* 01111000 */
+ 0x0c, /* 00001100 */
+ 0x7c, /* 01111100 */
+ 0xcc, /* 11001100 */
+ 0x76, /* 01110110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 161 0xa1 ''
+ */
+ 0x0c, /* 00001100 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+ 0x38, /* 00111000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x3c, /* 00111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 162 0xa2 ''
+ */
+ 0x0c, /* 00001100 */
+ 0x18, /* 00011000 */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 163 0xa3 ''
+ */
+ 0x18, /* 00011000 */
+ 0x30, /* 00110000 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0x76, /* 01110110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 164 0xa4 ''
+ */
+ 0x76, /* 01110110 */
+ 0xdc, /* 11011100 */
+ 0x00, /* 00000000 */
+ 0xdc, /* 11011100 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 165 0xa5 ''
+ */
+ 0x76, /* 01110110 */
+ 0xdc, /* 11011100 */
+ 0x00, /* 00000000 */
+ 0xe6, /* 11100110 */
+ 0xf6, /* 11110110 */
+ 0xde, /* 11011110 */
+ 0xce, /* 11001110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 166 0xa6 ''
+ */
+ 0x3c, /* 00111100 */
+ 0x6c, /* 01101100 */
+ 0x6c, /* 01101100 */
+ 0x3e, /* 00111110 */
+ 0x00, /* 00000000 */
+ 0x7e, /* 01111110 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 167 0xa7 ''
+ */
+ 0x38, /* 00111000 */
+ 0x6c, /* 01101100 */
+ 0x6c, /* 01101100 */
+ 0x38, /* 00111000 */
+ 0x00, /* 00000000 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 168 0xa8 ''
+ */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x30, /* 00110000 */
+ 0x63, /* 01100011 */
+ 0x3e, /* 00111110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 169 0xa9 ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xfe, /* 11111110 */
+ 0xc0, /* 11000000 */
+ 0xc0, /* 11000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 170 0xaa ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xfe, /* 11111110 */
+ 0x06, /* 00000110 */
+ 0x06, /* 00000110 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 171 0xab ''
+ */
+ 0x63, /* 01100011 */
+ 0xe6, /* 11100110 */
+ 0x6c, /* 01101100 */
+ 0x7e, /* 01111110 */
+ 0x33, /* 00110011 */
+ 0x66, /* 01100110 */
+ 0xcc, /* 11001100 */
+ 0x0f, /* 00001111 */
+
+ /*
+ * 172 0xac ''
+ */
+ 0x63, /* 01100011 */
+ 0xe6, /* 11100110 */
+ 0x6c, /* 01101100 */
+ 0x7a, /* 01111010 */
+ 0x36, /* 00110110 */
+ 0x6a, /* 01101010 */
+ 0xdf, /* 11011111 */
+ 0x06, /* 00000110 */
+
+ /*
+ * 173 0xad ''
+ */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x3c, /* 00111100 */
+ 0x3c, /* 00111100 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 174 0xae ''
+ */
+ 0x00, /* 00000000 */
+ 0x33, /* 00110011 */
+ 0x66, /* 01100110 */
+ 0xcc, /* 11001100 */
+ 0x66, /* 01100110 */
+ 0x33, /* 00110011 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 175 0xaf ''
+ */
+ 0x00, /* 00000000 */
+ 0xcc, /* 11001100 */
+ 0x66, /* 01100110 */
+ 0x33, /* 00110011 */
+ 0x66, /* 01100110 */
+ 0xcc, /* 11001100 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 176 0xb0 ''
+ */
+ 0x22, /* 00100010 */
+ 0x88, /* 10001000 */
+ 0x22, /* 00100010 */
+ 0x88, /* 10001000 */
+ 0x22, /* 00100010 */
+ 0x88, /* 10001000 */
+ 0x22, /* 00100010 */
+ 0x88, /* 10001000 */
+
+ /*
+ * 177 0xb1 ''
+ */
+ 0x55, /* 01010101 */
+ 0xaa, /* 10101010 */
+ 0x55, /* 01010101 */
+ 0xaa, /* 10101010 */
+ 0x55, /* 01010101 */
+ 0xaa, /* 10101010 */
+ 0x55, /* 01010101 */
+ 0xaa, /* 10101010 */
+
+ /*
+ * 178 0xb2 ''
+ */
+ 0x77, /* 01110111 */
+ 0xdd, /* 11011101 */
+ 0x77, /* 01110111 */
+ 0xdd, /* 11011101 */
+ 0x77, /* 01110111 */
+ 0xdd, /* 11011101 */
+ 0x77, /* 01110111 */
+ 0xdd, /* 11011101 */
+
+ /*
+ * 179 0xb3 ''
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 180 0xb4 ''
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0xf8, /* 11111000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 181 0xb5 ''
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0xf8, /* 11111000 */
+ 0x18, /* 00011000 */
+ 0xf8, /* 11111000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 182 0xb6 ''
+ */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0xf6, /* 11110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+
+ /*
+ * 183 0xb7 ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xfe, /* 11111110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+
+ /*
+ * 184 0xb8 ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xf8, /* 11111000 */
+ 0x18, /* 00011000 */
+ 0xf8, /* 11111000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 185 0xb9 ''
+ */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0xf6, /* 11110110 */
+ 0x06, /* 00000110 */
+ 0xf6, /* 11110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+
+ /*
+ * 186 0xba ''
+ */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+
+ /*
+ * 187 0xbb ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xfe, /* 11111110 */
+ 0x06, /* 00000110 */
+ 0xf6, /* 11110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+
+ /*
+ * 188 0xbc ''
+ */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0xf6, /* 11110110 */
+ 0x06, /* 00000110 */
+ 0xfe, /* 11111110 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 189 0xbd ''
+ */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0xfe, /* 11111110 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 190 0xbe ''
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0xf8, /* 11111000 */
+ 0x18, /* 00011000 */
+ 0xf8, /* 11111000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 191 0xbf ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xf8, /* 11111000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 192 0xc0 ''
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x1f, /* 00011111 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 193 0xc1 ''
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0xff, /* 11111111 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 194 0xc2 ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xff, /* 11111111 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 195 0xc3 ''
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x1f, /* 00011111 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 196 0xc4 ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xff, /* 11111111 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 197 0xc5 ''
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0xff, /* 11111111 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 198 0xc6 ''
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x1f, /* 00011111 */
+ 0x18, /* 00011000 */
+ 0x1f, /* 00011111 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 199 0xc7 ''
+ */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x37, /* 00110111 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+
+ /*
+ * 200 0xc8 ''
+ */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x37, /* 00110111 */
+ 0x30, /* 00110000 */
+ 0x3f, /* 00111111 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 201 0xc9 ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x3f, /* 00111111 */
+ 0x30, /* 00110000 */
+ 0x37, /* 00110111 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+
+ /*
+ * 202 0xca ''
+ */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0xf7, /* 11110111 */
+ 0x00, /* 00000000 */
+ 0xff, /* 11111111 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 203 0xcb ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xff, /* 11111111 */
+ 0x00, /* 00000000 */
+ 0xf7, /* 11110111 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+
+ /*
+ * 204 0xcc ''
+ */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x37, /* 00110111 */
+ 0x30, /* 00110000 */
+ 0x37, /* 00110111 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+
+ /*
+ * 205 0xcd ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xff, /* 11111111 */
+ 0x00, /* 00000000 */
+ 0xff, /* 11111111 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 206 0xce ''
+ */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0xf7, /* 11110111 */
+ 0x00, /* 00000000 */
+ 0xf7, /* 11110111 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+
+ /*
+ * 207 0xcf ''
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0xff, /* 11111111 */
+ 0x00, /* 00000000 */
+ 0xff, /* 11111111 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 208 0xd0 ''
+ */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0xff, /* 11111111 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 209 0xd1 ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xff, /* 11111111 */
+ 0x00, /* 00000000 */
+ 0xff, /* 11111111 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 210 0xd2 ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xff, /* 11111111 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+
+ /*
+ * 211 0xd3 ''
+ */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x3f, /* 00111111 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 212 0xd4 ''
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x1f, /* 00011111 */
+ 0x18, /* 00011000 */
+ 0x1f, /* 00011111 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 213 0xd5 ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x1f, /* 00011111 */
+ 0x18, /* 00011000 */
+ 0x1f, /* 00011111 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 214 0xd6 ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x3f, /* 00111111 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+
+ /*
+ * 215 0xd7 ''
+ */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0xff, /* 11111111 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+
+ /*
+ * 216 0xd8 ''
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0xff, /* 11111111 */
+ 0x18, /* 00011000 */
+ 0xff, /* 11111111 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 217 0xd9 ''
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0xf8, /* 11111000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 218 0xda ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x1f, /* 00011111 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 219 0xdb ''
+ */
+ 0xff, /* 11111111 */
+ 0xff, /* 11111111 */
+ 0xff, /* 11111111 */
+ 0xff, /* 11111111 */
+ 0xff, /* 11111111 */
+ 0xff, /* 11111111 */
+ 0xff, /* 11111111 */
+ 0xff, /* 11111111 */
+
+ /*
+ * 220 0xdc ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xff, /* 11111111 */
+ 0xff, /* 11111111 */
+ 0xff, /* 11111111 */
+ 0xff, /* 11111111 */
+
+ /*
+ * 221 0xdd ''
+ */
+ 0xf0, /* 11110000 */
+ 0xf0, /* 11110000 */
+ 0xf0, /* 11110000 */
+ 0xf0, /* 11110000 */
+ 0xf0, /* 11110000 */
+ 0xf0, /* 11110000 */
+ 0xf0, /* 11110000 */
+ 0xf0, /* 11110000 */
+
+ /*
+ * 222 0xde ''
+ */
+ 0x0f, /* 00001111 */
+ 0x0f, /* 00001111 */
+ 0x0f, /* 00001111 */
+ 0x0f, /* 00001111 */
+ 0x0f, /* 00001111 */
+ 0x0f, /* 00001111 */
+ 0x0f, /* 00001111 */
+ 0x0f, /* 00001111 */
+
+ /*
+ * 223 0xdf ''
+ */
+ 0xff, /* 11111111 */
+ 0xff, /* 11111111 */
+ 0xff, /* 11111111 */
+ 0xff, /* 11111111 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 224 0xe0 ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x76, /* 01110110 */
+ 0xdc, /* 11011100 */
+ 0xc8, /* 11001000 */
+ 0xdc, /* 11011100 */
+ 0x76, /* 01110110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 225 0xe1 ''
+ */
+ 0x78, /* 01111000 */
+ 0xcc, /* 11001100 */
+ 0xcc, /* 11001100 */
+ 0xd8, /* 11011000 */
+ 0xcc, /* 11001100 */
+ 0xc6, /* 11000110 */
+ 0xcc, /* 11001100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 226 0xe2 ''
+ */
+ 0xfe, /* 11111110 */
+ 0xc6, /* 11000110 */
+ 0xc0, /* 11000000 */
+ 0xc0, /* 11000000 */
+ 0xc0, /* 11000000 */
+ 0xc0, /* 11000000 */
+ 0xc0, /* 11000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 227 0xe3 ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0xfe, /* 11111110 */
+ 0x6c, /* 01101100 */
+ 0x6c, /* 01101100 */
+ 0x6c, /* 01101100 */
+ 0x6c, /* 01101100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 228 0xe4 ''
+ */
+ 0xfe, /* 11111110 */
+ 0xc6, /* 11000110 */
+ 0x60, /* 01100000 */
+ 0x30, /* 00110000 */
+ 0x60, /* 01100000 */
+ 0xc6, /* 11000110 */
+ 0xfe, /* 11111110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 229 0xe5 ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x7e, /* 01111110 */
+ 0xd8, /* 11011000 */
+ 0xd8, /* 11011000 */
+ 0xd8, /* 11011000 */
+ 0x70, /* 01110000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 230 0xe6 ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x7c, /* 01111100 */
+ 0xc0, /* 11000000 */
+
+ /*
+ * 231 0xe7 ''
+ */
+ 0x00, /* 00000000 */
+ 0x76, /* 01110110 */
+ 0xdc, /* 11011100 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 232 0xe8 ''
+ */
+ 0x7e, /* 01111110 */
+ 0x18, /* 00011000 */
+ 0x3c, /* 00111100 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x3c, /* 00111100 */
+ 0x18, /* 00011000 */
+ 0x7e, /* 01111110 */
+
+ /*
+ * 233 0xe9 ''
+ */
+ 0x38, /* 00111000 */
+ 0x6c, /* 01101100 */
+ 0xc6, /* 11000110 */
+ 0xfe, /* 11111110 */
+ 0xc6, /* 11000110 */
+ 0x6c, /* 01101100 */
+ 0x38, /* 00111000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 234 0xea ''
+ */
+ 0x38, /* 00111000 */
+ 0x6c, /* 01101100 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x6c, /* 01101100 */
+ 0x6c, /* 01101100 */
+ 0xee, /* 11101110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 235 0xeb ''
+ */
+ 0x0e, /* 00001110 */
+ 0x18, /* 00011000 */
+ 0x0c, /* 00001100 */
+ 0x3e, /* 00111110 */
+ 0x66, /* 01100110 */
+ 0x66, /* 01100110 */
+ 0x3c, /* 00111100 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 236 0xec ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x7e, /* 01111110 */
+ 0xdb, /* 11011011 */
+ 0xdb, /* 11011011 */
+ 0x7e, /* 01111110 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 237 0xed ''
+ */
+ 0x06, /* 00000110 */
+ 0x0c, /* 00001100 */
+ 0x7e, /* 01111110 */
+ 0xdb, /* 11011011 */
+ 0xdb, /* 11011011 */
+ 0x7e, /* 01111110 */
+ 0x60, /* 01100000 */
+ 0xc0, /* 11000000 */
+
+ /*
+ * 238 0xee ''
+ */
+ 0x1e, /* 00011110 */
+ 0x30, /* 00110000 */
+ 0x60, /* 01100000 */
+ 0x7e, /* 01111110 */
+ 0x60, /* 01100000 */
+ 0x30, /* 00110000 */
+ 0x1e, /* 00011110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 239 0xef ''
+ */
+ 0x00, /* 00000000 */
+ 0x7c, /* 01111100 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0xc6, /* 11000110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 240 0xf0 ''
+ */
+ 0x00, /* 00000000 */
+ 0xfe, /* 11111110 */
+ 0x00, /* 00000000 */
+ 0xfe, /* 11111110 */
+ 0x00, /* 00000000 */
+ 0xfe, /* 11111110 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 241 0xf1 ''
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x7e, /* 01111110 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+ 0x7e, /* 01111110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 242 0xf2 ''
+ */
+ 0x30, /* 00110000 */
+ 0x18, /* 00011000 */
+ 0x0c, /* 00001100 */
+ 0x18, /* 00011000 */
+ 0x30, /* 00110000 */
+ 0x00, /* 00000000 */
+ 0x7e, /* 01111110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 243 0xf3 ''
+ */
+ 0x0c, /* 00001100 */
+ 0x18, /* 00011000 */
+ 0x30, /* 00110000 */
+ 0x18, /* 00011000 */
+ 0x0c, /* 00001100 */
+ 0x00, /* 00000000 */
+ 0x7e, /* 01111110 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 244 0xf4 ''
+ */
+ 0x0e, /* 00001110 */
+ 0x1b, /* 00011011 */
+ 0x1b, /* 00011011 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+
+ /*
+ * 245 0xf5 ''
+ */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0xd8, /* 11011000 */
+ 0xd8, /* 11011000 */
+ 0x70, /* 01110000 */
+
+ /*
+ * 246 0xf6 ''
+ */
+ 0x00, /* 00000000 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+ 0x7e, /* 01111110 */
+ 0x00, /* 00000000 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 247 0xf7 ''
+ */
+ 0x00, /* 00000000 */
+ 0x76, /* 01110110 */
+ 0xdc, /* 11011100 */
+ 0x00, /* 00000000 */
+ 0x76, /* 01110110 */
+ 0xdc, /* 11011100 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 248 0xf8 ''
+ */
+ 0x38, /* 00111000 */
+ 0x6c, /* 01101100 */
+ 0x6c, /* 01101100 */
+ 0x38, /* 00111000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 249 0xf9 ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x18, /* 00011000 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 250 0xfa ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x18, /* 00011000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 251 0xfb ''
+ */
+ 0x0f, /* 00001111 */
+ 0x0c, /* 00001100 */
+ 0x0c, /* 00001100 */
+ 0x0c, /* 00001100 */
+ 0xec, /* 11101100 */
+ 0x6c, /* 01101100 */
+ 0x3c, /* 00111100 */
+ 0x1c, /* 00011100 */
+
+ /*
+ * 252 0xfc ''
+ */
+ 0x6c, /* 01101100 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x36, /* 00110110 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 253 0xfd ''
+ */
+ 0x78, /* 01111000 */
+ 0x0c, /* 00001100 */
+ 0x18, /* 00011000 */
+ 0x30, /* 00110000 */
+ 0x7c, /* 01111100 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 254 0xfe ''
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x3c, /* 00111100 */
+ 0x3c, /* 00111100 */
+ 0x3c, /* 00111100 */
+ 0x3c, /* 00111100 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+ /*
+ * 255 0xff ' '
+ */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+ 0x00, /* 00000000 */
+
+};
+
+
+/* ---- Character */
+
+/*!
+\brief Global cache for 8x8 pixel font textures created at runtime.
+*/
+static SDL_Texture *SDLTest_CharTextureCache[256];
+
+int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, char c)
+{
+ const Uint32 charWidth = FONT_CHARACTER_SIZE;
+ const Uint32 charHeight = FONT_CHARACTER_SIZE;
+ const Uint32 charSize = FONT_CHARACTER_SIZE;
+ SDL_Rect srect;
+ SDL_Rect drect;
+ int result;
+ Uint32 ix, iy;
+ const unsigned char *charpos;
+ Uint8 *curpos;
+ Uint8 patt, mask;
+ Uint8 *linepos;
+ Uint32 pitch;
+ SDL_Surface *character;
+ Uint32 ci;
+ Uint8 r, g, b, a;
+
+ /*
+ * Setup source rectangle
+ */
+ srect.x = 0;
+ srect.y = 0;
+ srect.w = charWidth;
+ srect.h = charHeight;
+
+ /*
+ * Setup destination rectangle
+ */
+ drect.x = x;
+ drect.y = y;
+ drect.w = charWidth;
+ drect.h = charHeight;
+
+ /* Character index in cache */
+ ci = (unsigned char)c;
+
+ /*
+ * Create new charWidth x charHeight bitmap surface if not already present.
+ */
+ if (SDLTest_CharTextureCache[ci] == NULL) {
+ /*
+ * Redraw character into surface
+ */
+ character = SDL_CreateRGBSurface(SDL_SWSURFACE,
+ charWidth, charHeight, 32,
+ 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
+ if (character == NULL) {
+ return (-1);
+ }
+
+ charpos = SDLTest_FontData + ci * charSize;
+ linepos = (Uint8 *)character->pixels;
+ pitch = character->pitch;
+
+ /*
+ * Drawing loop
+ */
+ patt = 0;
+ for (iy = 0; iy < charWidth; iy++) {
+ mask = 0x00;
+ curpos = linepos;
+ for (ix = 0; ix < charWidth; ix++) {
+ if (!(mask >>= 1)) {
+ patt = *charpos++;
+ mask = 0x80;
+ }
+ if (patt & mask) {
+ *(Uint32 *)curpos = 0xffffffff;
+ } else {
+ *(Uint32 *)curpos = 0;
+ }
+ curpos += 4;
+ }
+ linepos += pitch;
+ }
+
+ /* Convert temp surface into texture */
+ SDLTest_CharTextureCache[ci] = SDL_CreateTextureFromSurface(renderer, character);
+ SDL_FreeSurface(character);
+
+ /*
+ * Check pointer
+ */
+ if (SDLTest_CharTextureCache[ci] == NULL) {
+ return (-1);
+ }
+ }
+
+ /*
+ * Set color
+ */
+ result = 0;
+ result |= SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a);
+ result |= SDL_SetTextureColorMod(SDLTest_CharTextureCache[ci], r, g, b);
+ result |= SDL_SetTextureAlphaMod(SDLTest_CharTextureCache[ci], a);
+
+ /*
+ * Draw texture onto destination
+ */
+ result |= SDL_RenderCopy(renderer, SDLTest_CharTextureCache[ci], &srect, &drect);
+
+ return (result);
+}
+
+int SDLTest_DrawString(SDL_Renderer * renderer, int x, int y, const char *s)
+{
+ const Uint32 charWidth = FONT_CHARACTER_SIZE;
+ int result = 0;
+ int curx = x;
+ int cury = y;
+ const char *curchar = s;
+
+ while (*curchar && !result) {
+ result |= SDLTest_DrawCharacter(renderer, curx, cury, *curchar);
+ curx += charWidth;
+ curchar++;
+ }
+
+ return (result);
+}
+
+void SDLTest_CleanupTextDrawing(void)
+{
+ unsigned int i;
+ for (i = 0; i < SDL_arraysize(SDLTest_CharTextureCache); ++i) {
+ if (SDLTest_CharTextureCache[i]) {
+ SDL_DestroyTexture(SDLTest_CharTextureCache[i]);
+ SDLTest_CharTextureCache[i] = NULL;
+ }
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/test/SDL_test_fuzzer.c b/src/3rdparty/SDL2/src/test/SDL_test_fuzzer.c
new file mode 100644
index 0000000..eee56a9
--- /dev/null
+++ b/src/3rdparty/SDL2/src/test/SDL_test_fuzzer.c
@@ -0,0 +1,534 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+
+ Data generators for fuzzing test data in a reproducible way.
+
+*/
+
+#include "SDL_config.h"
+
+#include <limits.h>
+/* Visual Studio 2008 doesn't have stdint.h */
+#if defined(_MSC_VER) && _MSC_VER <= 1500
+#define UINT8_MAX _UI8_MAX
+#define UINT16_MAX _UI16_MAX
+#define UINT32_MAX _UI32_MAX
+#define INT64_MIN _I64_MIN
+#define INT64_MAX _I64_MAX
+#define UINT64_MAX _UI64_MAX
+#else
+#include <stdint.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <float.h>
+
+#include "SDL_test.h"
+
+/**
+ * Counter for fuzzer invocations
+ */
+static int fuzzerInvocationCounter = 0;
+
+/**
+ * Context for shared random number generator
+ */
+static SDLTest_RandomContext rndContext;
+
+/*
+ * Note: doxygen documentation markup for functions is in the header file.
+ */
+
+void
+SDLTest_FuzzerInit(Uint64 execKey)
+{
+ Uint32 a = (execKey >> 32) & 0x00000000FFFFFFFF;
+ Uint32 b = execKey & 0x00000000FFFFFFFF;
+ SDL_memset((void *)&rndContext, 0, sizeof(SDLTest_RandomContext));
+ SDLTest_RandomInit(&rndContext, a, b);
+ fuzzerInvocationCounter = 0;
+}
+
+int
+SDLTest_GetFuzzerInvocationCount()
+{
+ return fuzzerInvocationCounter;
+}
+
+Uint8
+SDLTest_RandomUint8()
+{
+ fuzzerInvocationCounter++;
+
+ return (Uint8) SDLTest_RandomInt(&rndContext) & 0x000000FF;
+}
+
+Sint8
+SDLTest_RandomSint8()
+{
+ fuzzerInvocationCounter++;
+
+ return (Sint8) SDLTest_RandomInt(&rndContext) & 0x000000FF;
+}
+
+Uint16
+SDLTest_RandomUint16()
+{
+ fuzzerInvocationCounter++;
+
+ return (Uint16) SDLTest_RandomInt(&rndContext) & 0x0000FFFF;
+}
+
+Sint16
+SDLTest_RandomSint16()
+{
+ fuzzerInvocationCounter++;
+
+ return (Sint16) SDLTest_RandomInt(&rndContext) & 0x0000FFFF;
+}
+
+Sint32
+SDLTest_RandomSint32()
+{
+ fuzzerInvocationCounter++;
+
+ return (Sint32) SDLTest_RandomInt(&rndContext);
+}
+
+Uint32
+SDLTest_RandomUint32()
+{
+ fuzzerInvocationCounter++;
+
+ return (Uint32) SDLTest_RandomInt(&rndContext);
+}
+
+Uint64
+SDLTest_RandomUint64()
+{
+ union {
+ Uint64 v64;
+ Uint32 v32[2];
+ } value;
+ value.v64 = 0;
+
+ fuzzerInvocationCounter++;
+
+ value.v32[0] = SDLTest_RandomSint32();
+ value.v32[1] = SDLTest_RandomSint32();
+
+ return value.v64;
+}
+
+Sint64
+SDLTest_RandomSint64()
+{
+ union {
+ Uint64 v64;
+ Uint32 v32[2];
+ } value;
+ value.v64 = 0;
+
+ fuzzerInvocationCounter++;
+
+ value.v32[0] = SDLTest_RandomSint32();
+ value.v32[1] = SDLTest_RandomSint32();
+
+ return (Sint64)value.v64;
+}
+
+
+
+Sint32
+SDLTest_RandomIntegerInRange(Sint32 pMin, Sint32 pMax)
+{
+ Sint64 min = pMin;
+ Sint64 max = pMax;
+ Sint64 temp;
+ Sint64 number;
+
+ if(pMin > pMax) {
+ temp = min;
+ min = max;
+ max = temp;
+ } else if(pMin == pMax) {
+ return (Sint32)min;
+ }
+
+ number = SDLTest_RandomUint32();
+ /* invocation count increment in preceeding call */
+
+ return (Sint32)((number % ((max + 1) - min)) + min);
+}
+
+/* !
+ * Generates a unsigned boundary value between the given boundaries.
+ * Boundary values are inclusive. See the examples below.
+ * If boundary2 < boundary1, the values are swapped.
+ * If boundary1 == boundary2, value of boundary1 will be returned
+ *
+ * Generating boundary values for Uint8:
+ * BoundaryValues(UINT8_MAX, 10, 20, True) -> [10,11,19,20]
+ * BoundaryValues(UINT8_MAX, 10, 20, False) -> [9,21]
+ * BoundaryValues(UINT8_MAX, 0, 15, True) -> [0, 1, 14, 15]
+ * BoundaryValues(UINT8_MAX, 0, 15, False) -> [16]
+ * BoundaryValues(UINT8_MAX, 0, 0xFF, False) -> [0], error set
+ *
+ * Generator works the same for other types of unsigned integers.
+ *
+ * \param maxValue The biggest value that is acceptable for this data type.
+ * For instance, for Uint8 -> 255, Uint16 -> 65536 etc.
+ * \param boundary1 defines lower boundary
+ * \param boundary2 defines upper boundary
+ * \param validDomain Generate only for valid domain (for the data type)
+ *
+ * \returns Returns a random boundary value for the domain or 0 in case of error
+ */
+static Uint64
+SDLTest_GenerateUnsignedBoundaryValues(const Uint64 maxValue, Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain)
+{
+ Uint64 b1, b2;
+ Uint64 delta;
+ Uint64 tempBuf[4];
+ Uint8 index;
+
+ /* Maybe swap */
+ if (boundary1 > boundary2) {
+ b1 = boundary2;
+ b2 = boundary1;
+ } else {
+ b1 = boundary1;
+ b2 = boundary2;
+ }
+
+ index = 0;
+ if (validDomain == SDL_TRUE) {
+ if (b1 == b2) {
+ return b1;
+ }
+
+ /* Generate up to 4 values within bounds */
+ delta = b2 - b1;
+ if (delta < 4) {
+ do {
+ tempBuf[index] = b1 + index;
+ index++;
+ } while (index < delta);
+ } else {
+ tempBuf[index] = b1;
+ index++;
+ tempBuf[index] = b1 + 1;
+ index++;
+ tempBuf[index] = b2 - 1;
+ index++;
+ tempBuf[index] = b2;
+ index++;
+ }
+ } else {
+ /* Generate up to 2 values outside of bounds */
+ if (b1 > 0) {
+ tempBuf[index] = b1 - 1;
+ index++;
+ }
+
+ if (b2 < maxValue) {
+ tempBuf[index] = b2 + 1;
+ index++;
+ }
+ }
+
+ if (index == 0) {
+ /* There are no valid boundaries */
+ SDL_Unsupported();
+ return 0;
+ }
+
+ return tempBuf[SDLTest_RandomUint8() % index];
+}
+
+
+Uint8
+SDLTest_RandomUint8BoundaryValue(Uint8 boundary1, Uint8 boundary2, SDL_bool validDomain)
+{
+ /* max value for Uint8 */
+ const Uint64 maxValue = UCHAR_MAX;
+ return (Uint8)SDLTest_GenerateUnsignedBoundaryValues(maxValue,
+ (Uint64) boundary1, (Uint64) boundary2,
+ validDomain);
+}
+
+Uint16
+SDLTest_RandomUint16BoundaryValue(Uint16 boundary1, Uint16 boundary2, SDL_bool validDomain)
+{
+ /* max value for Uint16 */
+ const Uint64 maxValue = USHRT_MAX;
+ return (Uint16)SDLTest_GenerateUnsignedBoundaryValues(maxValue,
+ (Uint64) boundary1, (Uint64) boundary2,
+ validDomain);
+}
+
+Uint32
+SDLTest_RandomUint32BoundaryValue(Uint32 boundary1, Uint32 boundary2, SDL_bool validDomain)
+{
+ /* max value for Uint32 */
+ #if ((ULONG_MAX) == (UINT_MAX))
+ const Uint64 maxValue = ULONG_MAX;
+ #else
+ const Uint64 maxValue = UINT_MAX;
+ #endif
+ return (Uint32)SDLTest_GenerateUnsignedBoundaryValues(maxValue,
+ (Uint64) boundary1, (Uint64) boundary2,
+ validDomain);
+}
+
+Uint64
+SDLTest_RandomUint64BoundaryValue(Uint64 boundary1, Uint64 boundary2, SDL_bool validDomain)
+{
+ /* max value for Uint64 */
+ const Uint64 maxValue = UINT64_MAX;
+ return SDLTest_GenerateUnsignedBoundaryValues(maxValue,
+ (Uint64) boundary1, (Uint64) boundary2,
+ validDomain);
+}
+
+/* !
+ * Generates a signed boundary value between the given boundaries.
+ * Boundary values are inclusive. See the examples below.
+ * If boundary2 < boundary1, the values are swapped.
+ * If boundary1 == boundary2, value of boundary1 will be returned
+ *
+ * Generating boundary values for Sint8:
+ * SignedBoundaryValues(SCHAR_MIN, SCHAR_MAX, -10, 20, True) -> [-10,-9,19,20]
+ * SignedBoundaryValues(SCHAR_MIN, SCHAR_MAX, -10, 20, False) -> [-11,21]
+ * SignedBoundaryValues(SCHAR_MIN, SCHAR_MAX, -30, -15, True) -> [-30, -29, -16, -15]
+ * SignedBoundaryValues(SCHAR_MIN, SCHAR_MAX, -127, 15, False) -> [16]
+ * SignedBoundaryValues(SCHAR_MIN, SCHAR_MAX, -127, 127, False) -> [0], error set
+ *
+ * Generator works the same for other types of signed integers.
+ *
+ * \param minValue The smallest value that is acceptable for this data type.
+ * For instance, for Uint8 -> -127, etc.
+ * \param maxValue The biggest value that is acceptable for this data type.
+ * For instance, for Uint8 -> 127, etc.
+ * \param boundary1 defines lower boundary
+ * \param boundary2 defines upper boundary
+ * \param validDomain Generate only for valid domain (for the data type)
+ *
+ * \returns Returns a random boundary value for the domain or 0 in case of error
+ */
+static Sint64
+SDLTest_GenerateSignedBoundaryValues(const Sint64 minValue, const Sint64 maxValue, Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain)
+{
+ Sint64 b1, b2;
+ Sint64 delta;
+ Sint64 tempBuf[4];
+ Uint8 index;
+
+ /* Maybe swap */
+ if (boundary1 > boundary2) {
+ b1 = boundary2;
+ b2 = boundary1;
+ } else {
+ b1 = boundary1;
+ b2 = boundary2;
+ }
+
+ index = 0;
+ if (validDomain == SDL_TRUE) {
+ if (b1 == b2) {
+ return b1;
+ }
+
+ /* Generate up to 4 values within bounds */
+ delta = b2 - b1;
+ if (delta < 4) {
+ do {
+ tempBuf[index] = b1 + index;
+ index++;
+ } while (index < delta);
+ } else {
+ tempBuf[index] = b1;
+ index++;
+ tempBuf[index] = b1 + 1;
+ index++;
+ tempBuf[index] = b2 - 1;
+ index++;
+ tempBuf[index] = b2;
+ index++;
+ }
+ } else {
+ /* Generate up to 2 values outside of bounds */
+ if (b1 > minValue) {
+ tempBuf[index] = b1 - 1;
+ index++;
+ }
+
+ if (b2 < maxValue) {
+ tempBuf[index] = b2 + 1;
+ index++;
+ }
+ }
+
+ if (index == 0) {
+ /* There are no valid boundaries */
+ SDL_Unsupported();
+ return minValue;
+ }
+
+ return tempBuf[SDLTest_RandomUint8() % index];
+}
+
+
+Sint8
+SDLTest_RandomSint8BoundaryValue(Sint8 boundary1, Sint8 boundary2, SDL_bool validDomain)
+{
+ /* min & max values for Sint8 */
+ const Sint64 maxValue = SCHAR_MAX;
+ const Sint64 minValue = SCHAR_MIN;
+ return (Sint8)SDLTest_GenerateSignedBoundaryValues(minValue, maxValue,
+ (Sint64) boundary1, (Sint64) boundary2,
+ validDomain);
+}
+
+Sint16
+SDLTest_RandomSint16BoundaryValue(Sint16 boundary1, Sint16 boundary2, SDL_bool validDomain)
+{
+ /* min & max values for Sint16 */
+ const Sint64 maxValue = SHRT_MAX;
+ const Sint64 minValue = SHRT_MIN;
+ return (Sint16)SDLTest_GenerateSignedBoundaryValues(minValue, maxValue,
+ (Sint64) boundary1, (Sint64) boundary2,
+ validDomain);
+}
+
+Sint32
+SDLTest_RandomSint32BoundaryValue(Sint32 boundary1, Sint32 boundary2, SDL_bool validDomain)
+{
+ /* min & max values for Sint32 */
+ #if ((ULONG_MAX) == (UINT_MAX))
+ const Sint64 maxValue = LONG_MAX;
+ const Sint64 minValue = LONG_MIN;
+ #else
+ const Sint64 maxValue = INT_MAX;
+ const Sint64 minValue = INT_MIN;
+ #endif
+ return (Sint32)SDLTest_GenerateSignedBoundaryValues(minValue, maxValue,
+ (Sint64) boundary1, (Sint64) boundary2,
+ validDomain);
+}
+
+Sint64
+SDLTest_RandomSint64BoundaryValue(Sint64 boundary1, Sint64 boundary2, SDL_bool validDomain)
+{
+ /* min & max values for Sint64 */
+ const Sint64 maxValue = INT64_MAX;
+ const Sint64 minValue = INT64_MIN;
+ return SDLTest_GenerateSignedBoundaryValues(minValue, maxValue,
+ boundary1, boundary2,
+ validDomain);
+}
+
+float
+SDLTest_RandomUnitFloat()
+{
+ return SDLTest_RandomUint32() / (float) UINT_MAX;
+}
+
+float
+SDLTest_RandomFloat()
+{
+ return (float) (SDLTest_RandomUnitDouble() * (double)2.0 * (double)FLT_MAX - (double)(FLT_MAX));
+}
+
+double
+SDLTest_RandomUnitDouble()
+{
+ return (double) (SDLTest_RandomUint64() >> 11) * (1.0/9007199254740992.0);
+}
+
+double
+SDLTest_RandomDouble()
+{
+ double r = 0.0;
+ double s = 1.0;
+ do {
+ s /= UINT_MAX + 1.0;
+ r += (double)SDLTest_RandomInt(&rndContext) * s;
+ } while (s > DBL_EPSILON);
+
+ fuzzerInvocationCounter++;
+
+ return r;
+}
+
+
+char *
+SDLTest_RandomAsciiString()
+{
+ return SDLTest_RandomAsciiStringWithMaximumLength(255);
+}
+
+char *
+SDLTest_RandomAsciiStringWithMaximumLength(int maxLength)
+{
+ int size;
+
+ if(maxLength < 1) {
+ SDL_InvalidParamError("maxLength");
+ return NULL;
+ }
+
+ size = (SDLTest_RandomUint32() % (maxLength + 1));
+
+ return SDLTest_RandomAsciiStringOfSize(size);
+}
+
+char *
+SDLTest_RandomAsciiStringOfSize(int size)
+{
+ char *string;
+ int counter;
+
+
+ if(size < 1) {
+ SDL_InvalidParamError("size");
+ return NULL;
+ }
+
+ string = (char *)SDL_malloc((size + 1) * sizeof(char));
+ if (string==NULL) {
+ return NULL;
+ }
+
+ for(counter = 0; counter < size; ++counter) {
+ string[counter] = (char)SDLTest_RandomIntegerInRange(32, 126);
+ }
+
+ string[counter] = '\0';
+
+ fuzzerInvocationCounter++;
+
+ return string;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/test/SDL_test_harness.c b/src/3rdparty/SDL2/src/test/SDL_test_harness.c
new file mode 100644
index 0000000..15021c6
--- /dev/null
+++ b/src/3rdparty/SDL2/src/test/SDL_test_harness.c
@@ -0,0 +1,680 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "SDL_config.h"
+
+#include "SDL_test.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+/* Invalid test name/description message format */
+#define SDLTEST_INVALID_NAME_FORMAT "(Invalid)"
+
+/* Log summary message format */
+#define SDLTEST_LOG_SUMMARY_FORMAT "%s Summary: Total=%d Passed=%d Failed=%d Skipped=%d"
+
+/* Final result message format */
+#define SDLTEST_FINAL_RESULT_FORMAT ">>> %s '%s': %s\n"
+
+/* ! \brief Timeout for single test case execution */
+static Uint32 SDLTest_TestCaseTimeout = 3600;
+
+/**
+* Generates a random run seed string for the harness. The generated seed
+* will contain alphanumeric characters (0-9A-Z).
+*
+* Note: The returned string needs to be deallocated by the caller.
+*
+* \param length The length of the seed string to generate
+*
+* \returns The generated seed string
+*/
+char *
+SDLTest_GenerateRunSeed(const int length)
+{
+ char *seed = NULL;
+ SDLTest_RandomContext randomContext;
+ int counter;
+
+ /* Sanity check input */
+ if (length <= 0) {
+ SDLTest_LogError("The length of the harness seed must be >0.");
+ return NULL;
+ }
+
+ /* Allocate output buffer */
+ seed = (char *)SDL_malloc((length + 1) * sizeof(char));
+ if (seed == NULL) {
+ SDLTest_LogError("SDL_malloc for run seed output buffer failed.");
+ SDL_Error(SDL_ENOMEM);
+ return NULL;
+ }
+
+ /* Generate a random string of alphanumeric characters */
+ SDLTest_RandomInitTime(&randomContext);
+ for (counter = 0; counter < length; counter++) {
+ unsigned int number = SDLTest_Random(&randomContext);
+ char ch = (char) (number % (91 - 48)) + 48;
+ if (ch >= 58 && ch <= 64) {
+ ch = 65;
+ }
+ seed[counter] = ch;
+ }
+ seed[length] = '\0';
+
+ return seed;
+}
+
+/**
+* Generates an execution key for the fuzzer.
+*
+* \param runSeed The run seed to use
+* \param suiteName The name of the test suite
+* \param testName The name of the test
+* \param iteration The iteration count
+*
+* \returns The generated execution key to initialize the fuzzer with.
+*
+*/
+static Uint64
+SDLTest_GenerateExecKey(const char *runSeed, char *suiteName, char *testName, int iteration)
+{
+ SDLTest_Md5Context md5Context;
+ Uint64 *keys;
+ char iterationString[16];
+ size_t runSeedLength;
+ size_t suiteNameLength;
+ size_t testNameLength;
+ size_t iterationStringLength;
+ size_t entireStringLength;
+ char *buffer;
+
+ if (runSeed == NULL || runSeed[0] == '\0') {
+ SDLTest_LogError("Invalid runSeed string.");
+ return -1;
+ }
+
+ if (suiteName == NULL || suiteName[0] == '\0') {
+ SDLTest_LogError("Invalid suiteName string.");
+ return -1;
+ }
+
+ if (testName == NULL || testName[0] == '\0') {
+ SDLTest_LogError("Invalid testName string.");
+ return -1;
+ }
+
+ if (iteration <= 0) {
+ SDLTest_LogError("Invalid iteration count.");
+ return -1;
+ }
+
+ /* Convert iteration number into a string */
+ SDL_memset(iterationString, 0, sizeof(iterationString));
+ SDL_snprintf(iterationString, sizeof(iterationString) - 1, "%d", iteration);
+
+ /* Combine the parameters into single string */
+ runSeedLength = SDL_strlen(runSeed);
+ suiteNameLength = SDL_strlen(suiteName);
+ testNameLength = SDL_strlen(testName);
+ iterationStringLength = SDL_strlen(iterationString);
+ entireStringLength = runSeedLength + suiteNameLength + testNameLength + iterationStringLength + 1;
+ buffer = (char *)SDL_malloc(entireStringLength);
+ if (buffer == NULL) {
+ SDLTest_LogError("Failed to allocate buffer for execKey generation.");
+ SDL_Error(SDL_ENOMEM);
+ return 0;
+ }
+ SDL_snprintf(buffer, entireStringLength, "%s%s%s%d", runSeed, suiteName, testName, iteration);
+
+ /* Hash string and use half of the digest as 64bit exec key */
+ SDLTest_Md5Init(&md5Context);
+ SDLTest_Md5Update(&md5Context, (unsigned char *)buffer, (unsigned int) entireStringLength);
+ SDLTest_Md5Final(&md5Context);
+ SDL_free(buffer);
+ keys = (Uint64 *)md5Context.digest;
+
+ return keys[0];
+}
+
+/**
+* \brief Set timeout handler for test.
+*
+* Note: SDL_Init(SDL_INIT_TIMER) will be called if it wasn't done so before.
+*
+* \param timeout Timeout interval in seconds.
+* \param callback Function that will be called after timeout has elapsed.
+*
+* \return Timer id or -1 on failure.
+*/
+static SDL_TimerID
+SDLTest_SetTestTimeout(int timeout, void (*callback)())
+{
+ Uint32 timeoutInMilliseconds;
+ SDL_TimerID timerID;
+
+ if (callback == NULL) {
+ SDLTest_LogError("Timeout callback can't be NULL");
+ return -1;
+ }
+
+ if (timeout < 0) {
+ SDLTest_LogError("Timeout value must be bigger than zero.");
+ return -1;
+ }
+
+ /* Init SDL timer if not initialized before */
+ if (SDL_WasInit(SDL_INIT_TIMER) == 0) {
+ if (SDL_InitSubSystem(SDL_INIT_TIMER)) {
+ SDLTest_LogError("Failed to init timer subsystem: %s", SDL_GetError());
+ return -1;
+ }
+ }
+
+ /* Set timer */
+ timeoutInMilliseconds = timeout * 1000;
+ timerID = SDL_AddTimer(timeoutInMilliseconds, (SDL_TimerCallback)callback, 0x0);
+ if (timerID == 0) {
+ SDLTest_LogError("Creation of SDL timer failed: %s", SDL_GetError());
+ return -1;
+ }
+
+ return timerID;
+}
+
+/**
+* \brief Timeout handler. Aborts test run and exits harness process.
+*/
+static SDL_NORETURN void
+SDLTest_BailOut()
+{
+ SDLTest_LogError("TestCaseTimeout timer expired. Aborting test run.");
+ exit(TEST_ABORTED); /* bail out from the test */
+}
+
+/**
+* \brief Execute a test using the given execution key.
+*
+* \param testSuite Suite containing the test case.
+* \param testCase Case to execute.
+* \param execKey Execution key for the fuzzer.
+* \param forceTestRun Force test to run even if test was disabled in suite.
+*
+* \returns Test case result.
+*/
+static int
+SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, const SDLTest_TestCaseReference *testCase, Uint64 execKey, SDL_bool forceTestRun)
+{
+ SDL_TimerID timer = 0;
+ int testCaseResult = 0;
+ int testResult = 0;
+ int fuzzerCount;
+
+ if (testSuite==NULL || testCase==NULL || testSuite->name==NULL || testCase->name==NULL)
+ {
+ SDLTest_LogError("Setup failure: testSuite or testCase references NULL");
+ return TEST_RESULT_SETUP_FAILURE;
+ }
+
+ if (!testCase->enabled && forceTestRun == SDL_FALSE)
+ {
+ SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Test", testCase->name, "Skipped (Disabled)");
+ return TEST_RESULT_SKIPPED;
+ }
+
+ /* Initialize fuzzer */
+ SDLTest_FuzzerInit(execKey);
+
+ /* Reset assert tracker */
+ SDLTest_ResetAssertSummary();
+
+ /* Set timeout timer */
+ timer = SDLTest_SetTestTimeout(SDLTest_TestCaseTimeout, SDLTest_BailOut);
+
+ /* Maybe run suite initalizer function */
+ if (testSuite->testSetUp) {
+ testSuite->testSetUp(0x0);
+ if (SDLTest_AssertSummaryToTestResult() == TEST_RESULT_FAILED) {
+ SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Suite Setup", testSuite->name, "Failed");
+ return TEST_RESULT_SETUP_FAILURE;
+ }
+ }
+
+ /* Run test case function */
+ testCaseResult = testCase->testCase(0x0);
+
+ /* Convert test execution result into harness result */
+ if (testCaseResult == TEST_SKIPPED) {
+ /* Test was programatically skipped */
+ testResult = TEST_RESULT_SKIPPED;
+ } else if (testCaseResult == TEST_STARTED) {
+ /* Test did not return a TEST_COMPLETED value; assume it failed */
+ testResult = TEST_RESULT_FAILED;
+ } else if (testCaseResult == TEST_ABORTED) {
+ /* Test was aborted early; assume it failed */
+ testResult = TEST_RESULT_FAILED;
+ } else {
+ /* Perform failure analysis based on asserts */
+ testResult = SDLTest_AssertSummaryToTestResult();
+ }
+
+ /* Maybe run suite cleanup function (ignore failed asserts) */
+ if (testSuite->testTearDown) {
+ testSuite->testTearDown(0x0);
+ }
+
+ /* Cancel timeout timer */
+ if (timer) {
+ SDL_RemoveTimer(timer);
+ }
+
+ /* Report on asserts and fuzzer usage */
+ fuzzerCount = SDLTest_GetFuzzerInvocationCount();
+ if (fuzzerCount > 0) {
+ SDLTest_Log("Fuzzer invocations: %d", fuzzerCount);
+ }
+
+ /* Final log based on test execution result */
+ if (testCaseResult == TEST_SKIPPED) {
+ /* Test was programatically skipped */
+ SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Test", testCase->name, "Skipped (Programmatically)");
+ } else if (testCaseResult == TEST_STARTED) {
+ /* Test did not return a TEST_COMPLETED value; assume it failed */
+ SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Test", testCase->name, "Failed (test started, but did not return TEST_COMPLETED)");
+ } else if (testCaseResult == TEST_ABORTED) {
+ /* Test was aborted early; assume it failed */
+ SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Test", testCase->name, "Failed (Aborted)");
+ } else {
+ SDLTest_LogAssertSummary();
+ }
+
+ return testResult;
+}
+
+/* Prints summary of all suites/tests contained in the given reference */
+#if 0
+static void SDLTest_LogTestSuiteSummary(SDLTest_TestSuiteReference *testSuites)
+{
+ int suiteCounter;
+ int testCounter;
+ SDLTest_TestSuiteReference *testSuite;
+ SDLTest_TestCaseReference *testCase;
+
+ /* Loop over all suites */
+ suiteCounter = 0;
+ while(&testSuites[suiteCounter]) {
+ testSuite=&testSuites[suiteCounter];
+ suiteCounter++;
+ SDLTest_Log("Test Suite %i - %s\n", suiteCounter,
+ (testSuite->name) ? testSuite->name : SDLTEST_INVALID_NAME_FORMAT);
+
+ /* Loop over all test cases */
+ testCounter = 0;
+ while(testSuite->testCases[testCounter])
+ {
+ testCase=(SDLTest_TestCaseReference *)testSuite->testCases[testCounter];
+ testCounter++;
+ SDLTest_Log(" Test Case %i - %s: %s", testCounter,
+ (testCase->name) ? testCase->name : SDLTEST_INVALID_NAME_FORMAT,
+ (testCase->description) ? testCase->description : SDLTEST_INVALID_NAME_FORMAT);
+ }
+ }
+}
+#endif
+
+/* Gets a timer value in seconds */
+static float GetClock()
+{
+ float currentClock = clock() / (float) CLOCKS_PER_SEC;
+ return currentClock;
+}
+
+/**
+* \brief Execute a test suite using the given run seed and execution key.
+*
+* The filter string is matched to the suite name (full comparison) to select a single suite,
+* or if no suite matches, it is matched to the test names (full comparison) to select a single test.
+*
+* \param testSuites Suites containing the test case.
+* \param userRunSeed Custom run seed provided by user, or NULL to autogenerate one.
+* \param userExecKey Custom execution key provided by user, or 0 to autogenerate one.
+* \param filter Filter specification. NULL disables. Case sensitive.
+* \param testIterations Number of iterations to run each test case.
+*
+* \returns Test run result; 0 when all tests passed, 1 if any tests failed.
+*/
+int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *userRunSeed, Uint64 userExecKey, const char *filter, int testIterations)
+{
+ int totalNumberOfTests = 0;
+ int failedNumberOfTests = 0;
+ int suiteCounter;
+ int testCounter;
+ int iterationCounter;
+ SDLTest_TestSuiteReference *testSuite;
+ const SDLTest_TestCaseReference *testCase;
+ const char *runSeed = NULL;
+ char *currentSuiteName;
+ char *currentTestName;
+ Uint64 execKey;
+ float runStartSeconds;
+ float suiteStartSeconds;
+ float testStartSeconds;
+ float runEndSeconds;
+ float suiteEndSeconds;
+ float testEndSeconds;
+ float runtime;
+ int suiteFilter = 0;
+ char *suiteFilterName = NULL;
+ int testFilter = 0;
+ char *testFilterName = NULL;
+ SDL_bool forceTestRun = SDL_FALSE;
+ int testResult = 0;
+ int runResult = 0;
+ Uint32 totalTestFailedCount = 0;
+ Uint32 totalTestPassedCount = 0;
+ Uint32 totalTestSkippedCount = 0;
+ Uint32 testFailedCount = 0;
+ Uint32 testPassedCount = 0;
+ Uint32 testSkippedCount = 0;
+ Uint32 countSum = 0;
+ const SDLTest_TestCaseReference **failedTests;
+
+ /* Sanitize test iterations */
+ if (testIterations < 1) {
+ testIterations = 1;
+ }
+
+ /* Generate run see if we don't have one already */
+ if (userRunSeed == NULL || userRunSeed[0] == '\0') {
+ runSeed = SDLTest_GenerateRunSeed(16);
+ if (runSeed == NULL) {
+ SDLTest_LogError("Generating a random seed failed");
+ return 2;
+ }
+ } else {
+ runSeed = userRunSeed;
+ }
+
+
+ /* Reset per-run counters */
+ totalTestFailedCount = 0;
+ totalTestPassedCount = 0;
+ totalTestSkippedCount = 0;
+
+ /* Take time - run start */
+ runStartSeconds = GetClock();
+
+ /* Log run with fuzzer parameters */
+ SDLTest_Log("::::: Test Run /w seed '%s' started\n", runSeed);
+
+ /* Count the total number of tests */
+ suiteCounter = 0;
+ while (testSuites[suiteCounter]) {
+ testSuite=(SDLTest_TestSuiteReference *)testSuites[suiteCounter];
+ suiteCounter++;
+ testCounter = 0;
+ while (testSuite->testCases[testCounter])
+ {
+ testCounter++;
+ totalNumberOfTests++;
+ }
+ }
+
+ /* Pre-allocate an array for tracking failed tests (potentially all test cases) */
+ failedTests = (const SDLTest_TestCaseReference **)SDL_malloc(totalNumberOfTests * sizeof(SDLTest_TestCaseReference *));
+ if (failedTests == NULL) {
+ SDLTest_LogError("Unable to allocate cache for failed tests");
+ SDL_Error(SDL_ENOMEM);
+ return -1;
+ }
+
+ /* Initialize filtering */
+ if (filter != NULL && filter[0] != '\0') {
+ /* Loop over all suites to check if we have a filter match */
+ suiteCounter = 0;
+ while (testSuites[suiteCounter] && suiteFilter == 0) {
+ testSuite=(SDLTest_TestSuiteReference *)testSuites[suiteCounter];
+ suiteCounter++;
+ if (testSuite->name != NULL && SDL_strcmp(filter, testSuite->name) == 0) {
+ /* Matched a suite name */
+ suiteFilter = 1;
+ suiteFilterName = testSuite->name;
+ SDLTest_Log("Filtering: running only suite '%s'", suiteFilterName);
+ break;
+ }
+
+ /* Within each suite, loop over all test cases to check if we have a filter match */
+ testCounter = 0;
+ while (testSuite->testCases[testCounter] && testFilter == 0)
+ {
+ testCase = testSuite->testCases[testCounter];
+ testCounter++;
+ if (testCase->name != NULL && SDL_strcmp(filter, testCase->name) == 0) {
+ /* Matched a test name */
+ suiteFilter = 1;
+ suiteFilterName = testSuite->name;
+ testFilter = 1;
+ testFilterName = testCase->name;
+ SDLTest_Log("Filtering: running only test '%s' in suite '%s'", testFilterName, suiteFilterName);
+ break;
+ }
+ }
+ }
+
+ if (suiteFilter == 0 && testFilter == 0) {
+ SDLTest_LogError("Filter '%s' did not match any test suite/case.", filter);
+ SDLTest_Log("Exit code: 2");
+ SDL_free((void *) failedTests);
+ return 2;
+ }
+ }
+
+ /* Loop over all suites */
+ suiteCounter = 0;
+ while(testSuites[suiteCounter]) {
+ testSuite=(SDLTest_TestSuiteReference *)testSuites[suiteCounter];
+ currentSuiteName = (char *)((testSuite->name) ? testSuite->name : SDLTEST_INVALID_NAME_FORMAT);
+ suiteCounter++;
+
+ /* Filter suite if flag set and we have a name */
+ if (suiteFilter == 1 && suiteFilterName != NULL && testSuite->name != NULL &&
+ SDL_strcmp(suiteFilterName, testSuite->name) != 0) {
+ /* Skip suite */
+ SDLTest_Log("===== Test Suite %i: '%s' skipped\n",
+ suiteCounter,
+ currentSuiteName);
+ } else {
+
+ /* Reset per-suite counters */
+ testFailedCount = 0;
+ testPassedCount = 0;
+ testSkippedCount = 0;
+
+ /* Take time - suite start */
+ suiteStartSeconds = GetClock();
+
+ /* Log suite started */
+ SDLTest_Log("===== Test Suite %i: '%s' started\n",
+ suiteCounter,
+ currentSuiteName);
+
+ /* Loop over all test cases */
+ testCounter = 0;
+ while(testSuite->testCases[testCounter])
+ {
+ testCase = testSuite->testCases[testCounter];
+ currentTestName = (char *)((testCase->name) ? testCase->name : SDLTEST_INVALID_NAME_FORMAT);
+ testCounter++;
+
+ /* Filter tests if flag set and we have a name */
+ if (testFilter == 1 && testFilterName != NULL && testCase->name != NULL &&
+ SDL_strcmp(testFilterName, testCase->name) != 0) {
+ /* Skip test */
+ SDLTest_Log("===== Test Case %i.%i: '%s' skipped\n",
+ suiteCounter,
+ testCounter,
+ currentTestName);
+ } else {
+ /* Override 'disabled' flag if we specified a test filter (i.e. force run for debugging) */
+ if (testFilter == 1 && !testCase->enabled) {
+ SDLTest_Log("Force run of disabled test since test filter was set");
+ forceTestRun = SDL_TRUE;
+ }
+
+ /* Take time - test start */
+ testStartSeconds = GetClock();
+
+ /* Log test started */
+ SDLTest_Log("----- Test Case %i.%i: '%s' started",
+ suiteCounter,
+ testCounter,
+ currentTestName);
+ if (testCase->description != NULL && testCase->description[0] != '\0') {
+ SDLTest_Log("Test Description: '%s'",
+ (testCase->description) ? testCase->description : SDLTEST_INVALID_NAME_FORMAT);
+ }
+
+ /* Loop over all iterations */
+ iterationCounter = 0;
+ while(iterationCounter < testIterations)
+ {
+ iterationCounter++;
+
+ if (userExecKey != 0) {
+ execKey = userExecKey;
+ } else {
+ execKey = SDLTest_GenerateExecKey(runSeed, testSuite->name, testCase->name, iterationCounter);
+ }
+
+ SDLTest_Log("Test Iteration %i: execKey %" SDL_PRIu64, iterationCounter, execKey);
+ testResult = SDLTest_RunTest(testSuite, testCase, execKey, forceTestRun);
+
+ if (testResult == TEST_RESULT_PASSED) {
+ testPassedCount++;
+ totalTestPassedCount++;
+ } else if (testResult == TEST_RESULT_SKIPPED) {
+ testSkippedCount++;
+ totalTestSkippedCount++;
+ } else {
+ testFailedCount++;
+ totalTestFailedCount++;
+ }
+ }
+
+ /* Take time - test end */
+ testEndSeconds = GetClock();
+ runtime = testEndSeconds - testStartSeconds;
+ if (runtime < 0.0f) runtime = 0.0f;
+
+ if (testIterations > 1) {
+ /* Log test runtime */
+ SDLTest_Log("Runtime of %i iterations: %.1f sec", testIterations, runtime);
+ SDLTest_Log("Average Test runtime: %.5f sec", runtime / (float)testIterations);
+ } else {
+ /* Log test runtime */
+ SDLTest_Log("Total Test runtime: %.1f sec", runtime);
+ }
+
+ /* Log final test result */
+ switch (testResult) {
+ case TEST_RESULT_PASSED:
+ SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Test", currentTestName, "Passed");
+ break;
+ case TEST_RESULT_FAILED:
+ SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Test", currentTestName, "Failed");
+ break;
+ case TEST_RESULT_NO_ASSERT:
+ SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT,"Test", currentTestName, "No Asserts");
+ break;
+ }
+
+ /* Collect failed test case references for repro-step display */
+ if (testResult == TEST_RESULT_FAILED) {
+ failedTests[failedNumberOfTests] = testCase;
+ failedNumberOfTests++;
+ }
+ }
+ }
+
+ /* Take time - suite end */
+ suiteEndSeconds = GetClock();
+ runtime = suiteEndSeconds - suiteStartSeconds;
+ if (runtime < 0.0f) runtime = 0.0f;
+
+ /* Log suite runtime */
+ SDLTest_Log("Total Suite runtime: %.1f sec", runtime);
+
+ /* Log summary and final Suite result */
+ countSum = testPassedCount + testFailedCount + testSkippedCount;
+ if (testFailedCount == 0)
+ {
+ SDLTest_Log(SDLTEST_LOG_SUMMARY_FORMAT, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount);
+ SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Suite", currentSuiteName, "Passed");
+ }
+ else
+ {
+ SDLTest_LogError(SDLTEST_LOG_SUMMARY_FORMAT, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount);
+ SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Suite", currentSuiteName, "Failed");
+ }
+
+ }
+ }
+
+ /* Take time - run end */
+ runEndSeconds = GetClock();
+ runtime = runEndSeconds - runStartSeconds;
+ if (runtime < 0.0f) runtime = 0.0f;
+
+ /* Log total runtime */
+ SDLTest_Log("Total Run runtime: %.1f sec", runtime);
+
+ /* Log summary and final run result */
+ countSum = totalTestPassedCount + totalTestFailedCount + totalTestSkippedCount;
+ if (totalTestFailedCount == 0)
+ {
+ runResult = 0;
+ SDLTest_Log(SDLTEST_LOG_SUMMARY_FORMAT, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount);
+ SDLTest_Log(SDLTEST_FINAL_RESULT_FORMAT, "Run /w seed", runSeed, "Passed");
+ }
+ else
+ {
+ runResult = 1;
+ SDLTest_LogError(SDLTEST_LOG_SUMMARY_FORMAT, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount);
+ SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Run /w seed", runSeed, "Failed");
+ }
+
+ /* Print repro steps for failed tests */
+ if (failedNumberOfTests > 0) {
+ SDLTest_Log("Harness input to repro failures:");
+ for (testCounter = 0; testCounter < failedNumberOfTests; testCounter++) {
+ SDLTest_Log(" --seed %s --filter %s", runSeed, failedTests[testCounter]->name);
+ }
+ }
+ SDL_free((void *) failedTests);
+
+ SDLTest_Log("Exit code: %d", runResult);
+ return runResult;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/test/SDL_test_imageBlit.c b/src/3rdparty/SDL2/src/test/SDL_test_imageBlit.c
new file mode 100644
index 0000000..f5c251a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/test/SDL_test_imageBlit.c
@@ -0,0 +1,1559 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#include "SDL_test.h"
+
+/* GIMP RGB C-Source image dump (blit.c) */
+
+static const SDLTest_SurfaceImage_t SDLTest_imageBlit = {
+ 80, 60, 3,
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0"
+ "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377"
+ "\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377"
+ "\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0"
+ "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0"
+ "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0"
+ "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0"
+ "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0"
+ "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0"
+ "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0"
+ "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377"
+ "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377"
+ "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377"
+ "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377"
+ "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377"
+ "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0"
+ "\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0"
+ "\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377"
+ "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0"
+ "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0"
+ "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0"
+ "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0"
+ "\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377"
+ "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0"
+ "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0"
+ "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0"
+ "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0"
+ "\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377"
+ "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0"
+ "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0"
+ "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0"
+ "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0"
+ "\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377"
+ "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0"
+ "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0"
+ "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0"
+ "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0"
+ "\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377"
+ "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0"
+ "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0"
+ "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0"
+ "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0"
+ "\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377"
+ "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0"
+ "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0"
+ "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0"
+ "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0"
+ "\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377"
+ "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0"
+ "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0"
+ "\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\0\0\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377"
+ "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377"
+ "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377"
+ "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377"
+ "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377"
+ "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377"
+ "\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377"
+ "\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377"
+ "\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377"
+ "\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377"
+ "\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377"
+ "\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377"
+ "\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377"
+ "\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0"
+ "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0"
+ "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0"
+ "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0"
+ "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0"
+ "\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0"
+ "\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0"
+ "\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0"
+ "\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0"
+ "\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0"
+ "\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0"
+ "\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0"
+ "\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377"
+ "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0"
+ "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377"
+ "\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0"
+ "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377"
+ "\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377"
+ "\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0"
+ "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0"
+ "\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377"
+ "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0"
+ "\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377"
+ "\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377"
+ "\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0"
+ "\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0"
+ "\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0"
+ "\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0"
+ "\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0"
+ "\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\0\377\377\0"
+ "\377\377\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377"
+ "\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0"
+ "\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0"
+ "\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377"
+ "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0",
+};
+
+/**
+ * \brief Returns the Blit test image as SDL_Surface.
+ */
+SDL_Surface *SDLTest_ImageBlit()
+{
+ SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
+ (void*)SDLTest_imageBlit.pixel_data,
+ SDLTest_imageBlit.width,
+ SDLTest_imageBlit.height,
+ SDLTest_imageBlit.bytes_per_pixel * 8,
+ SDLTest_imageBlit.width * SDLTest_imageBlit.bytes_per_pixel,
+#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ 0xff000000, /* Red bit mask. */
+ 0x00ff0000, /* Green bit mask. */
+ 0x0000ff00, /* Blue bit mask. */
+ 0x000000ff /* Alpha bit mask. */
+#else
+ 0x000000ff, /* Red bit mask. */
+ 0x0000ff00, /* Green bit mask. */
+ 0x00ff0000, /* Blue bit mask. */
+ 0xff000000 /* Alpha bit mask. */
+#endif
+ );
+ return surface;
+}
+
+static const SDLTest_SurfaceImage_t SDLTest_imageBlitColor = {
+ 80, 60, 3,
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\0\0\24\0\0\0\0\0\0"
+ "\0\0(\0\0(\0\0\0\0\0\0\0\0<\0\0<\0\0\0\0\0\0\0\0P\0\0P\0\0\0\0\0\0\0\0d\0"
+ "\0d\0\0\0\0\0\0\0\0x\0\0x\0\0\0\0\0\0\0\0\214\0\0\214\0\0\0\0\0\0\0\0\240"
+ "\0\0\240\0\0\0\0\0\0\0\0\264\0\0\264\0\0\0\0\0\0\0\0\310\0\0\310\0\0\0\0"
+ "\0\0\0\0\334\0\0\334\0\0\0\0\0\0\0\0\360\0\0\360\0\0\360\0\0\360\0\0\360"
+ "\0\0\360\0\0\360\0\0\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\0\0\24\0\0\24\0\0\0\0\0(\0\0"
+ "(\0\0(\0\0\0\0\0<\0\0<\0\0<\0\0\0\0\0P\0\0P\0\0P\0\0\0\0\0d\0\0d\0\0d\0\0"
+ "\0\0\0x\0\0x\0\0x\0\0\0\0\0\214\0\0\214\0\0\214\0\0\0\0\0\240\0\0\240\0\0"
+ "\240\0\0\0\0\0\264\0\0\264\0\0\264\0\0\0\0\0\310\0\0\310\0\0\310\0\0\0\0"
+ "\0\334\0\0\334\0\0\334\0\0\0\0\0\360\0\0\360\0\0\360\0\0\360\0\0\360\0\0"
+ "\360\0\0\360\0\0\360\0\0\360\0\0\360\0\0\360\0\0\360\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\0\0\24\0\0\24\0\0\0"
+ "\0\0(\0\0(\0\0(\0\0\0\0\0<\0\0<\0\0<\0\0\0\0\0P\0\0P\0\0P\0\0\0\0\0d\0\0"
+ "d\0\0d\0\0\0\0\0x\0\0x\0\0x\0\0\0\0\0\214\0\0\214\0\0\214\0\0\0\0\0\240\0"
+ "\0\240\0\0\240\0\0\0\0\0\264\0\0\264\0\0\264\0\0\0\0\0\310\0\0\310\0\0\310"
+ "\0\0\0\0\0\334\0\0\334\0\0\334\0\0\0\0\0\360\0\0\360\0\0\360\0\0\360\0\0"
+ "\360\0\0\360\0\0\360\0\0\360\0\0\360\0\0\360\0\0\360\0\0\360\0\0\360\0\0"
+ "\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\360\0\0\360\0\0\360\0\0\360\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0$\0\0$\0\0\0\0\0\0\0\0$\24\0"
+ "$\24\0\0\0\0\0\0\0$(\0$(\0\0\0\0\0\0\0$<\0$<\0\0\0\0\0\0\0$P\0$P\0\0\0\0"
+ "\0\0\0$d\0$d\0\0\0\0\0\0\0$x\0$x\0\0\0\0\0\0\0$\214\0$\214\0\0\0\0\0\0\0"
+ "$\240\0$\240\0\0\0\0\0\0\0$\264\0$\264\0\0\0\0\0\0\0$\310\0$\310\0\0\0\0"
+ "\0\0\0$\334\0$\334\0\0\0\0\0\0\0$\360\0$\360\0$\360\0$\360\0$\360\0$\360"
+ "\0$\360\0$\360\0\0\0\0\0\0\0\0\360\0\0\360\0\0\360\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0$\0\0$\0\0$\0\0\0\0\0$\24\0$\24\0$\24\0\0\0\0$(\0$(\0$(\0\0\0\0"
+ "$<\0$<\0$<\0\0\0\0$P\0$P\0$P\0\0\0\0$d\0$d\0$d\0\0\0\0$x\0$x\0$x\0\0\0\0"
+ "$\214\0$\214\0$\214\0\0\0\0$\240\0$\240\0$\240\0\0\0\0$\264\0$\264\0$\264"
+ "\0\0\0\0$\310\0$\310\0$\310\0\0\0\0$\334\0$\334\0$\334\0\0\0\0$\360\0$\360"
+ "\0$\360\0$\360\0$\360\0$\360\0$\360\0$\360\0$\360\0$\360\0$\360\0$\360\0"
+ "\0\0\0\0\360\0\0\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0$\0\0$\0\0$\0\0\0\0\0$\24\0"
+ "$\24\0$\24\0\0\0\0$(\0$(\0$(\0\0\0\0$<\0$<\0$<\0\0\0\0$P\0$P\0$P\0\0\0\0"
+ "$d\0$d\0$d\0\0\0\0$x\0$x\0$x\0\0\0\0$\214\0$\214\0$\214\0\0\0\0$\240\0$\240"
+ "\0$\240\0\0\0\0$\264\0$\264\0$\264\0\0\0\0$\310\0$\310\0$\310\0\0\0\0$\334"
+ "\0$\334\0$\334\0\0\0\0$\360\0$\360\0$\360\0$\360\0$\360\0$\360\0$\360\0$"
+ "\360\0$\360\0$\360\0$\360\0$\360\0$\360\0$\360\0\0\0\0\0\360\0\0\360\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0$\0\0$\0\0$\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0$\360\0$\360\0$\360\0$\360\0\0\0\0\0\360\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0$\0\0$\0\0$\0\0\0\0"
+ "\0\0\0\0H\0\0H\0\0\0\0\0\0\0\0H\24\0H\24\0\0\0\0\0\0\0H(\0H(\0\0\0\0\0\0"
+ "\0H<\0H<\0\0\0\0\0\0\0HP\0HP\0\0\0\0\0\0\0Hd\0Hd\0\0\0\0\0\0\0Hx\0Hx\0\0"
+ "\0\0\0\0\0H\214\0H\214\0\0\0\0\0\0\0H\240\0H\240\0\0\0\0\0\0\0H\264\0H\264"
+ "\0\0\0\0\0\0\0H\310\0H\310\0\0\0\0\0\0\0H\334\0H\334\0\0\0\0\0\0\0H\360\0"
+ "H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0\0\0\0\0\0\0$\360\0$\360"
+ "\0$\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0$\0\0$\0\0\0\0\0H\0\0H\0\0H\0\0\0\0\0H\24\0H\24\0H\24"
+ "\0\0\0\0H(\0H(\0H(\0\0\0\0H<\0H<\0H<\0\0\0\0HP\0HP\0HP\0\0\0\0Hd\0Hd\0Hd"
+ "\0\0\0\0Hx\0Hx\0Hx\0\0\0\0H\214\0H\214\0H\214\0\0\0\0H\240\0H\240\0H\240"
+ "\0\0\0\0H\264\0H\264\0H\264\0\0\0\0H\310\0H\310\0H\310\0\0\0\0H\334\0H\334"
+ "\0H\334\0\0\0\0H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0H"
+ "\360\0H\360\0H\360\0H\360\0\0\0\0$\360\0$\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0$\0\0$\0\0\0\0\0H\0\0"
+ "H\0\0H\0\0\0\0\0H\24\0H\24\0H\24\0\0\0\0H(\0H(\0H(\0\0\0\0H<\0H<\0H<\0\0"
+ "\0\0HP\0HP\0HP\0\0\0\0Hd\0Hd\0Hd\0\0\0\0Hx\0Hx\0Hx\0\0\0\0H\214\0H\214\0"
+ "H\214\0\0\0\0H\240\0H\240\0H\240\0\0\0\0H\264\0H\264\0H\264\0\0\0\0H\310"
+ "\0H\310\0H\310\0\0\0\0H\334\0H\334\0H\334\0\0\0\0H\360\0H\360\0H\360\0H\360"
+ "\0H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0H\360\0"
+ "\0\0\0$\360\0$\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0$\0\0\0\0\0H\0\0H\0\0H\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0H\360\0H\360\0H\360\0H\360\0\0\0\0$\360\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0H\0\0H\0\0H\0\0\0\0\0\0\0\0l\0\0l\0\0\0\0\0\0\0\0l\24\0l\24\0\0\0\0\0\0"
+ "\0l(\0l(\0\0\0\0\0\0\0l<\0l<\0\0\0\0\0\0\0lP\0lP\0\0\0\0\0\0\0ld\0ld\0\0"
+ "\0\0\0\0\0lx\0lx\0\0\0\0\0\0\0l\214\0l\214\0\0\0\0\0\0\0l\240\0l\240\0\0"
+ "\0\0\0\0\0l\264\0l\264\0\0\0\0\0\0\0l\310\0l\310\0\0\0\0\0\0\0l\334\0l\334"
+ "\0\0\0\0\0\0\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360\0\0"
+ "\0\0\0\0\0H\360\0H\360\0H\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0H\0\0H\0\0\0\0\0l\0\0l\0\0l\0\0"
+ "\0\0\0l\24\0l\24\0l\24\0\0\0\0l(\0l(\0l(\0\0\0\0l<\0l<\0l<\0\0\0\0lP\0lP"
+ "\0lP\0\0\0\0ld\0ld\0ld\0\0\0\0lx\0lx\0lx\0\0\0\0l\214\0l\214\0l\214\0\0\0"
+ "\0l\240\0l\240\0l\240\0\0\0\0l\264\0l\264\0l\264\0\0\0\0l\310\0l\310\0l\310"
+ "\0\0\0\0l\334\0l\334\0l\334\0\0\0\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360"
+ "\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360\0\0\0\0H\360\0H\360\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0H\0"
+ "\0H\0\0\0\0\0l\0\0l\0\0l\0\0\0\0\0l\24\0l\24\0l\24\0\0\0\0l(\0l(\0l(\0\0"
+ "\0\0l<\0l<\0l<\0\0\0\0lP\0lP\0lP\0\0\0\0ld\0ld\0ld\0\0\0\0lx\0lx\0lx\0\0"
+ "\0\0l\214\0l\214\0l\214\0\0\0\0l\240\0l\240\0l\240\0\0\0\0l\264\0l\264\0"
+ "l\264\0\0\0\0l\310\0l\310\0l\310\0\0\0\0l\334\0l\334\0l\334\0\0\0\0l\360"
+ "\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360\0l\360\0"
+ "l\360\0l\360\0l\360\0\0\0\0H\360\0H\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0H\0\0\0\0\0l\0\0l\0\0l\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0l\360\0l\360\0l\360\0l\360"
+ "\0\0\0\0H\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0l\0\0l\0\0l\0\0\0\0\0\0\0\0\220\0\0\220\0\0\0\0\0\0\0"
+ "\0\220\24\0\220\24\0\0\0\0\0\0\0\220(\0\220(\0\0\0\0\0\0\0\220<\0\220<\0"
+ "\0\0\0\0\0\0\220P\0\220P\0\0\0\0\0\0\0\220d\0\220d\0\0\0\0\0\0\0\220x\0\220"
+ "x\0\0\0\0\0\0\0\220\214\0\220\214\0\0\0\0\0\0\0\220\240\0\220\240\0\0\0\0"
+ "\0\0\0\220\264\0\220\264\0\0\0\0\0\0\0\220\310\0\220\310\0\0\0\0\0\0\0\220"
+ "\334\0\220\334\0\0\0\0\0\0\0\220\360\0\220\360\0\220\360\0\220\360\0\220"
+ "\360\0\220\360\0\220\360\0\220\360\0\0\0\0\0\0\0l\360\0l\360\0l\360\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0l\0\0l\0\0\0\0\0\220\0\0\220\0\0\220\0\0\0\0\0\220\24\0\220\24\0"
+ "\220\24\0\0\0\0\220(\0\220(\0\220(\0\0\0\0\220<\0\220<\0\220<\0\0\0\0\220"
+ "P\0\220P\0\220P\0\0\0\0\220d\0\220d\0\220d\0\0\0\0\220x\0\220x\0\220x\0\0"
+ "\0\0\220\214\0\220\214\0\220\214\0\0\0\0\220\240\0\220\240\0\220\240\0\0"
+ "\0\0\220\264\0\220\264\0\220\264\0\0\0\0\220\310\0\220\310\0\220\310\0\0"
+ "\0\0\220\334\0\220\334\0\220\334\0\0\0\0\220\360\0\220\360\0\220\360\0\220"
+ "\360\0\220\360\0\220\360\0\220\360\0\220\360\0\220\360\0\220\360\0\220\360"
+ "\0\220\360\0\0\0\0l\360\0l\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0l\0\0l\0\0\0\0\0\220\0\0\220\0\0\220"
+ "\0\0\0\0\0\220\24\0\220\24\0\220\24\0\0\0\0\220(\0\220(\0\220(\0\0\0\0\220"
+ "<\0\220<\0\220<\0\0\0\0\220P\0\220P\0\220P\0\0\0\0\220d\0\220d\0\220d\0\0"
+ "\0\0\220x\0\220x\0\220x\0\0\0\0\220\214\0\220\214\0\220\214\0\0\0\0\220\240"
+ "\0\220\240\0\220\240\0\0\0\0\220\264\0\220\264\0\220\264\0\0\0\0\220\310"
+ "\0\220\310\0\220\310\0\0\0\0\220\334\0\220\334\0\220\334\0\0\0\0\220\360"
+ "\0\220\360\0\220\360\0\220\360\0\220\360\0\220\360\0\220\360\0\220\360\0"
+ "\220\360\0\220\360\0\220\360\0\220\360\0\220\360\0\220\360\0\0\0\0l\360\0"
+ "l\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0l\0\0\0\0\0\220\0\0\220\0\0\220\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\220\360\0\220\360\0\220\360\0\220\360\0\0\0\0l\360"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\220\0\0\220\0\0\220\0\0\0\0\0\0\0\0\264\0\0\264\0\0\0\0\0\0\0\0"
+ "\264\24\0\264\24\0\0\0\0\0\0\0\264(\0\264(\0\0\0\0\0\0\0\264<\0\264<\0\0"
+ "\0\0\0\0\0\264P\0\264P\0\0\0\0\0\0\0\264d\0\264d\0\0\0\0\0\0\0\264x\0\264"
+ "x\0\0\0\0\0\0\0\264\214\0\264\214\0\0\0\0\0\0\0\264\240\0\264\240\0\0\0\0"
+ "\0\0\0\264\264\0\264\264\0\0\0\0\0\0\0\264\310\0\264\310\0\0\0\0\0\0\0\264"
+ "\334\0\264\334\0\0\0\0\0\0\0\264\360\0\264\360\0\264\360\0\264\360\0\264"
+ "\360\0\264\360\0\264\360\0\264\360\0\0\0\0\0\0\0\220\360\0\220\360\0\220"
+ "\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\220\0\0\220\0\0\0\0\0\264\0\0\264\0\0\264\0\0\0\0\0\264"
+ "\24\0\264\24\0\264\24\0\0\0\0\264(\0\264(\0\264(\0\0\0\0\264<\0\264<\0\264"
+ "<\0\0\0\0\264P\0\264P\0\264P\0\0\0\0\264d\0\264d\0\264d\0\0\0\0\264x\0\264"
+ "x\0\264x\0\0\0\0\264\214\0\264\214\0\264\214\0\0\0\0\264\240\0\264\240\0"
+ "\264\240\0\0\0\0\264\264\0\264\264\0\264\264\0\0\0\0\264\310\0\264\310\0"
+ "\264\310\0\0\0\0\264\334\0\264\334\0\264\334\0\0\0\0\264\360\0\264\360\0"
+ "\264\360\0\264\360\0\264\360\0\264\360\0\264\360\0\264\360\0\264\360\0\264"
+ "\360\0\264\360\0\264\360\0\0\0\0\220\360\0\220\360\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\220\0\0\220\0"
+ "\0\0\0\0\264\0\0\264\0\0\264\0\0\0\0\0\264\24\0\264\24\0\264\24\0\0\0\0\264"
+ "(\0\264(\0\264(\0\0\0\0\264<\0\264<\0\264<\0\0\0\0\264P\0\264P\0\264P\0\0"
+ "\0\0\264d\0\264d\0\264d\0\0\0\0\264x\0\264x\0\264x\0\0\0\0\264\214\0\264"
+ "\214\0\264\214\0\0\0\0\264\240\0\264\240\0\264\240\0\0\0\0\264\264\0\264"
+ "\264\0\264\264\0\0\0\0\264\310\0\264\310\0\264\310\0\0\0\0\264\334\0\264"
+ "\334\0\264\334\0\0\0\0\264\360\0\264\360\0\264\360\0\264\360\0\264\360\0"
+ "\264\360\0\264\360\0\264\360\0\264\360\0\264\360\0\264\360\0\264\360\0\264"
+ "\360\0\264\360\0\0\0\0\220\360\0\220\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\220\0\0\0\0\0\264\0\0\264\0\0"
+ "\264\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\264\360\0"
+ "\264\360\0\264\360\0\264\360\0\0\0\0\220\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\264\0\0\264\0\0\264"
+ "\0\0\0\0\0\0\0\0\330\0\0\330\0\0\0\0\0\0\0\0\330\24\0\330\24\0\0\0\0\0\0"
+ "\0\330(\0\330(\0\0\0\0\0\0\0\330<\0\330<\0\0\0\0\0\0\0\330P\0\330P\0\0\0"
+ "\0\0\0\0\330d\0\330d\0\0\0\0\0\0\0\330x\0\330x\0\0\0\0\0\0\0\330\214\0\330"
+ "\214\0\0\0\0\0\0\0\330\240\0\330\240\0\0\0\0\0\0\0\330\264\0\330\264\0\0"
+ "\0\0\0\0\0\330\310\0\330\310\0\0\0\0\0\0\0\330\334\0\330\334\0\0\0\0\0\0"
+ "\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0"
+ "\330\360\0\0\0\0\0\0\0\264\360\0\264\360\0\264\360\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\264\0\0"
+ "\264\0\0\0\0\0\330\0\0\330\0\0\330\0\0\0\0\0\330\24\0\330\24\0\330\24\0\0"
+ "\0\0\330(\0\330(\0\330(\0\0\0\0\330<\0\330<\0\330<\0\0\0\0\330P\0\330P\0"
+ "\330P\0\0\0\0\330d\0\330d\0\330d\0\0\0\0\330x\0\330x\0\330x\0\0\0\0\330\214"
+ "\0\330\214\0\330\214\0\0\0\0\330\240\0\330\240\0\330\240\0\0\0\0\330\264"
+ "\0\330\264\0\330\264\0\0\0\0\330\310\0\330\310\0\330\310\0\0\0\0\330\334"
+ "\0\330\334\0\330\334\0\0\0\0\330\360\0\330\360\0\330\360\0\330\360\0\330"
+ "\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360"
+ "\0\0\0\0\264\360\0\264\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\264\0\0\264\0\0\0\0\0\330\0\0\330\0\0"
+ "\330\0\0\0\0\0\330\24\0\330\24\0\330\24\0\0\0\0\330(\0\330(\0\330(\0\0\0"
+ "\0\330<\0\330<\0\330<\0\0\0\0\330P\0\330P\0\330P\0\0\0\0\330d\0\330d\0\330"
+ "d\0\0\0\0\330x\0\330x\0\330x\0\0\0\0\330\214\0\330\214\0\330\214\0\0\0\0"
+ "\330\240\0\330\240\0\330\240\0\0\0\0\330\264\0\330\264\0\330\264\0\0\0\0"
+ "\330\310\0\330\310\0\330\310\0\0\0\0\330\334\0\330\334\0\330\334\0\0\0\0"
+ "\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330"
+ "\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0\330\360\0\0\0\0"
+ "\264\360\0\264\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\264\0\0\0\0\0\330\0\0\330\0\0\330\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\330\360\0\330\360\0\330\360\0\330"
+ "\360\0\0\0\0\264\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\330\0\0\330\0\0\330\0\0\0\0\0\0\0\0\374\0\0"
+ "\374\0\0\0\0\0\0\0\0\374\24\0\374\24\0\0\0\0\0\0\0\374(\0\374(\0\0\0\0\0"
+ "\0\0\374<\0\374<\0\0\0\0\0\0\0\374P\0\374P\0\0\0\0\0\0\0\374d\0\374d\0\0"
+ "\0\0\0\0\0\374x\0\374x\0\0\0\0\0\0\0\374\214\0\374\214\0\0\0\0\0\0\0\374"
+ "\240\0\374\240\0\0\0\0\0\0\0\374\264\0\374\264\0\0\0\0\0\0\0\374\310\0\374"
+ "\310\0\0\0\0\0\0\0\374\334\0\374\334\0\0\0\0\0\0\0\374\360\0\374\360\0\374"
+ "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\330"
+ "\360\0\330\360\0\330\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\330\0\0\330\0\0\0\0\0\374\0\0\374"
+ "\0\0\374\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0\374(\0\374(\0"
+ "\0\0\0\374<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0\0\374d\0\374d"
+ "\0\374d\0\0\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374\214\0\374\214\0"
+ "\0\0\0\374\240\0\374\240\0\374\240\0\0\0\0\374\264\0\374\264\0\374\264\0"
+ "\0\0\0\374\310\0\374\310\0\374\310\0\0\0\0\374\334\0\374\334\0\374\334\0"
+ "\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360"
+ "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\330\360\0\330"
+ "\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\330\0\0\330\0\0\0\0\0\374\0\0\374\0\0\374\0\0\0\0\0\374\24\0"
+ "\374\24\0\374\24\0\0\0\0\374(\0\374(\0\374(\0\0\0\0\374<\0\374<\0\374<\0"
+ "\0\0\0\374P\0\374P\0\374P\0\0\0\0\374d\0\374d\0\374d\0\0\0\0\374x\0\374x"
+ "\0\374x\0\0\0\0\374\214\0\374\214\0\374\214\0\0\0\0\374\240\0\374\240\0\374"
+ "\240\0\0\0\0\374\264\0\374\264\0\374\264\0\0\0\0\374\310\0\374\310\0\374"
+ "\310\0\0\0\0\374\334\0\374\334\0\374\334\0\0\0\0\374\360\0\374\360\0\374"
+ "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360"
+ "\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\330\360\0\330\360\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\330"
+ "\0\0\0\0\0\374\0\0\374\0\0\374\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0"
+ "\374(\0\374(\0\374(\0\0\0\0\374<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374"
+ "P\0\0\0\0\374d\0\374d\0\374d\0\0\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0"
+ "\374\214\0\374\214\0\0\0\0\374\240\0\374\240\0\374\240\0\0\0\0\374\264\0"
+ "\374\264\0\374\264\0\0\0\0\374\310\0\374\310\0\374\310\0\0\0\0\374\334\0"
+ "\374\334\0\374\334\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360"
+ "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0"
+ "\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\330\360\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374"
+ "\0\0\374\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0\374(\0\374(\0"
+ "\0\0\0\374<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0\0\374d\0\374d"
+ "\0\374d\0\0\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374\214\0\374\214\0"
+ "\0\0\0\374\240\0\374\240\0\374\240\0\0\0\0\374\264\0\374\264\0\374\264\0"
+ "\0\0\0\374\310\0\374\310\0\374\310\0\0\0\0\374\334\0\374\334\0\374\334\0"
+ "\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360"
+ "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0"
+ "\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374\0\0\374"
+ "\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0\374(\0\374(\0\0\0\0\374"
+ "<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0\0\374d\0\374d\0\374d\0\0"
+ "\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374\214\0\374\214\0\0\0\0\374\240"
+ "\0\374\240\0\374\240\0\0\0\0\374\264\0\374\264\0\374\264\0\0\0\0\374\310"
+ "\0\374\310\0\374\310\0\0\0\0\374\334\0\374\334\0\374\334\0\0\0\0\374\360"
+ "\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360"
+ "\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\374\0\0\374\0\0\374\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0\374"
+ "(\0\374(\0\0\0\0\374<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0\0\374"
+ "d\0\374d\0\374d\0\0\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374\214\0\374"
+ "\214\0\0\0\0\374\240\0\374\240\0\374\240\0\0\0\0\374\264\0\374\264\0\374"
+ "\264\0\0\0\0\374\310\0\374\310\0\374\310\0\0\0\0\374\334\0\374\334\0\374"
+ "\334\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\374\334"
+ "\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\374\334\0\0"
+ "\0\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374\0\0\374\0\0\0\0"
+ "\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0\374(\0\374(\0\0\0\0\374<\0\374"
+ "<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0\0\374d\0\374d\0\374d\0\0\0\0\374"
+ "x\0\374x\0\374x\0\0\0\0\374\214\0\374\214\0\374\214\0\0\0\0\374\240\0\374"
+ "\240\0\374\240\0\0\0\0\374\264\0\374\264\0\374\264\0\0\0\0\374\310\0\374"
+ "\310\0\374\310\0\0\0\0\374\334\0\374\334\0\374\334\0\0\0\0\374\360\0\374"
+ "\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360\0\374"
+ "\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374"
+ "\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\374\0\0\374\0\0\374\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374"
+ "(\0\374(\0\374(\0\0\0\0\374<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0"
+ "\0\0\374d\0\374d\0\374d\0\0\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374"
+ "\214\0\374\214\0\0\0\0\374\240\0\374\240\0\374\240\0\0\0\0\374\264\0\374"
+ "\264\0\374\264\0\0\0\0\374\310\0\374\310\0\374\310\0\0\0\0\374\334\0\374"
+ "\334\0\374\334\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0"
+ "\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374"
+ "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\374\0\0\374\0\0\374\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0"
+ "\374(\0\374(\0\0\0\0\374<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0"
+ "\0\374d\0\374d\0\374d\0\0\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374\214"
+ "\0\374\214\0\0\0\0\374\240\0\374\240\0\374\240\0\0\0\0\374\264\0\374\264"
+ "\0\374\264\0\0\0\0\374\310\0\374\310\0\374\310\0\0\0\0\374\334\0\374\334"
+ "\0\374\334\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374"
+ "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360"
+ "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\374\0\0\374\0\0\374\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0\374"
+ "(\0\374(\0\0\0\0\374<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0\0\374"
+ "d\0\374d\0\374d\0\0\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374\214\0\374"
+ "\214\0\0\0\0\374\240\0\374\240\0\374\240\0\0\0\0\374\264\0\374\264\0\374"
+ "\264\0\0\0\0\374\310\0\374\310\0\374\310\0\0\0\0\374\334\0\374\334\0\374"
+ "\334\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0"
+ "\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0"
+ "\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374"
+ "\0\0\374\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0\374(\0\374(\0"
+ "\0\0\0\374<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0\0\374d\0\374d"
+ "\0\374d\0\0\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374\214\0\374\214\0"
+ "\0\0\0\374\240\0\374\240\0\374\240\0\0\0\0\374\264\0\374\264\0\374\264\0"
+ "\0\0\0\374\310\0\374\310\0\374\310\0\0\0\0\374\334\0\374\334\0\374\334\0"
+ "\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360"
+ "\0\374\360\0\374\360\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360"
+ "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374\0\0\374"
+ "\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0\374(\0\374(\0\0\0\0\374"
+ "<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0\0\374d\0\374d\0\374d\0\0"
+ "\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374\214\0\374\214\0\0\0\0\374\240"
+ "\0\374\240\0\374\240\0\0\0\0\374\264\0\374\264\0\374\264\0\0\0\0\374\310"
+ "\0\374\310\0\374\310\0\0\0\0\374\334\0\374\334\0\374\334\0\0\0\0\374\360"
+ "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0"
+ "\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374"
+ "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374\0\0\374"
+ "\0\0\0\0\0\374\24\0\374\24\0\374\24\0\0\0\0\374(\0\374(\0\374(\0\0\0\0\374"
+ "<\0\374<\0\374<\0\0\0\0\374P\0\374P\0\374P\0\0\0\0\374d\0\374d\0\374d\0\0"
+ "\0\0\374x\0\374x\0\374x\0\0\0\0\374\214\0\374\214\0\374\214\0\0\0\0\374\240"
+ "\0\374\240\0\374\240\0\0\0\0\374\264\0\374\264\0\374\264\0\0\0\0\374\310"
+ "\0\374\310\0\374\310\0\0\0\0\374\334\0\374\334\0\374\334\0\0\0\0\374\360"
+ "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0"
+ "\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374"
+ "\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374\0\0\0\0\0\0\0\0\374\24"
+ "\0\374\24\0\0\0\0\0\0\0\374(\0\374(\0\0\0\0\0\0\0\374<\0\374<\0\0\0\0\0\0"
+ "\0\374P\0\374P\0\0\0\0\0\0\0\374d\0\374d\0\0\0\0\0\0\0\374x\0\374x\0\0\0"
+ "\0\0\0\0\374\214\0\374\214\0\0\0\0\0\0\0\374\240\0\374\240\0\0\0\0\0\0\0"
+ "\374\264\0\374\264\0\0\0\0\0\0\0\374\310\0\374\310\0\0\0\0\0\0\0\374\334"
+ "\0\374\334\0\0\0\0\0\0\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\374\360\0"
+ "\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\0"
+ "\0\0\0\0\0\0\0\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374\0\0\0"
+ "\0\0\0\0\0\374\24\0\374\24\0\0\0\0\0\0\0\374(\0\374(\0\0\0\0\0\0\0\374<\0"
+ "\374<\0\0\0\0\0\0\0\374P\0\374P\0\0\0\0\0\0\0\374d\0\374d\0\0\0\0\0\0\0\374"
+ "x\0\374x\0\0\0\0\0\0\0\374\214\0\374\214\0\0\0\0\0\0\0\374\240\0\374\240"
+ "\0\0\0\0\0\0\0\374\264\0\374\264\0\0\0\0\0\0\0\374\310\0\374\310\0\0\0\0"
+ "\0\0\0\374\334\0\374\334\0\0\0\0\0\0\0\374\360\0\374\360\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374"
+ "\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374\0\0\0\0\0\0\0\0\374\24\0"
+ "\374\24\0\0\0\0\0\0\0\374(\0\374(\0\0\0\0\0\0\0\374<\0\374<\0\0\0\0\0\0\0"
+ "\374P\0\374P\0\0\0\0\0\0\0\374d\0\374d\0\0\0\0\0\0\0\374x\0\374x\0\0\0\0"
+ "\0\0\0\374\214\0\374\214\0\0\0\0\0\0\0\374\240\0\374\240\0\0\0\0\0\0\0\374"
+ "\264\0\374\264\0\0\0\0\0\0\0\374\310\0\374\310\0\0\0\0\0\0\0\374\334\0\374"
+ "\334\0\0\0\0\0\0\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\374\0\0\374\0\0\374\0\0\0\0\0\374\24\0\374\24\0\374\24\0"
+ "\0\0\0\374(\0\374(\0\374(\0\0\0\0\374<\0\374<\0\374<\0\0\0\0\374P\0\374P"
+ "\0\374P\0\0\0\0\374d\0\374d\0\374d\0\0\0\0\374x\0\374x\0\374x\0\0\0\0\374"
+ "\214\0\374\214\0\374\214\0\0\0\0\374\240\0\374\240\0\374\240\0\0\0\0\374"
+ "\264\0\374\264\0\374\264\0\0\0\0\374\310\0\374\310\0\374\310\0\0\0\0\374"
+ "\334\0\374\334\0\374\334\0\0\0\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\0\0\374\0\0\0\0\0\0\0\0"
+ "\374\24\0\374\24\0\0\0\0\0\0\0\374(\0\374(\0\0\0\0\0\0\0\374<\0\374<\0\0"
+ "\0\0\0\0\0\374P\0\374P\0\0\0\0\0\0\0\374d\0\374d\0\0\0\0\0\0\0\374x\0\374"
+ "x\0\0\0\0\0\0\0\374\214\0\374\214\0\0\0\0\0\0\0\374\240\0\374\240\0\0\0\0"
+ "\0\0\0\374\264\0\374\264\0\0\0\0\0\0\0\374\310\0\374\310\0\0\0\0\0\0\0\374"
+ "\334\0\374\334\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374"
+ "\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
+};
+
+/**
+ * \brief Returns the BlitColor test image as SDL_Surface.
+ */
+SDL_Surface *SDLTest_ImageBlitColor()
+{
+ SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
+ (void*)SDLTest_imageBlitColor.pixel_data,
+ SDLTest_imageBlitColor.width,
+ SDLTest_imageBlitColor.height,
+ SDLTest_imageBlitColor.bytes_per_pixel * 8,
+ SDLTest_imageBlitColor.width * SDLTest_imageBlitColor.bytes_per_pixel,
+#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ 0xff000000, /* Red bit mask. */
+ 0x00ff0000, /* Green bit mask. */
+ 0x0000ff00, /* Blue bit mask. */
+ 0x000000ff /* Alpha bit mask. */
+#else
+ 0x000000ff, /* Red bit mask. */
+ 0x0000ff00, /* Green bit mask. */
+ 0x00ff0000, /* Blue bit mask. */
+ 0xff000000 /* Alpha bit mask. */
+#endif
+ );
+ return surface;
+}
+
+static const SDLTest_SurfaceImage_t SDLTest_imageBlitAlpha = {
+ 80, 60, 3,
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0\24\24\0\20\20\0"
+ "\20\20\0""88\0""88\0**\0**\0ZZ\0ZZ\0==\0==\0yy\0yy\0II\0II\0\224\224\0\224"
+ "\224\0NN\0NN\0\254\254\0\254\254\0MM\0MM\0\302\302\0\302\302\0HH\0HH\0\324"
+ "\324\0\324\324\0>>\0>>\0\343\343\0\343\343\0""00\0""00\0\356\356\0\356\356"
+ "\0\40\40\0\40\40\0\367\367\0\367\367\0\16\16\0\16\16\0\374\374\0\374\374"
+ "\0\374\374\0\374\374\0\360\360\0\360\360\0\360\360\0\360\360\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\24\24\0\24\24\0\24\24\0\20\20\0""88\0""88\0""88\0**\0ff\0ff\0ff\0FF\0"
+ "\215\215\0\215\215\0\215\215\0UU\0\255\255\0\255\255\0\255\255\0[[\0\306"
+ "\306\0\306\306\0\306\306\0YY\0\331\331\0\331\331\0\331\331\0PP\0\350\350"
+ "\0\350\350\0\350\350\0DD\0\362\362\0\362\362\0\362\362\0""44\0\370\370\0"
+ "\370\370\0\370\370\0\"\"\0\374\374\0\374\374\0\374\374\0\16\16\0\376\376"
+ "\0\376\376\0\376\376\0\376\376\0\374\374\0\374\374\0\374\374\0\374\374\0"
+ "\360\360\0\360\360\0\360\360\0\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0\24\24\0\24\24\0\20\20\0""88\0"
+ """88\0""88\0**\0ff\0ff\0ff\0FF\0\226\226\0\226\226\0\215\215\0UU\0\271\271"
+ "\0\271\271\0\255\255\0[[\0\323\323\0\323\323\0\306\306\0YY\0\345\345\0\345"
+ "\345\0\331\331\0PP\0\360\360\0\360\360\0\350\350\0DD\0\370\370\0\370\370"
+ "\0\362\362\0""44\0\374\374\0\374\374\0\370\370\0\"\"\0\376\376\0\376\376"
+ "\0\374\374\0\16\16\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376"
+ "\376\0\374\374\0\374\374\0\374\374\0\374\374\0\360\360\0\360\360\0\360\360"
+ "\0\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24"
+ "\0\24\24\0\24\24\0\20\20\0""33\0""33\0""33\0&&\0OO\0OO\0OO\0""55\0``\0``"
+ "\0``\0::\0``\0``\0``\0""22\0WW\0WW\0WW\0''\0II\0II\0II\0\33\33\0""99\0""9"
+ "9\0""99\0\20\20\0))\0))\0))\0\10\10\0\33\33\0\33\33\0\33\33\0\3\3\0\17\17"
+ "\0\17\17\0\17\17\0\0\0\0\7\7\0\7\7\0\7\7\0\7\7\0\2\2\0\2\2\0\2\2\0\2\2\0"
+ "\16\16\0\16\16\0\16\16\0\16\16\0\360\360\0\360\360\0\360\360\0\360\360\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0\24\24\0\24\24\0\16\16"
+ "\0""33\0GG\0GG\0""00\0``\0\210\210\0\210\210\0TT\0\204\204\0\263\263\0\263"
+ "\263\0ee\0\222\222\0\315\315\0\312\312\0gg\0\216\216\0\331\331\0\327\327"
+ "\0cc\0\202\202\0\340\340\0\337\337\0YY\0qq\0\345\345\0\344\344\0NN\0^^\0"
+ "\352\352\0\352\352\0@@\0JJ\0\357\357\0\357\357\0""11\0""66\0\364\364\0\364"
+ "\364\0\40\40\0\"\"\0\371\371\0\371\371\0\16\16\0\16\16\0\375\375\0\375\375"
+ "\0\376\376\0\376\376\0\362\362\0\362\362\0\376\376\0\376\376\0\16\16\0\16"
+ "\16\0\360\360\0\360\360\0\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24"
+ "\24\0\24\24\0\22\22\0\24\24\0""88\0""88\0//\0BB\0pp\0pp\0UU\0ss\0\242\242"
+ "\0\242\242\0oo\0\230\230\0\306\306\0\306\306\0ww\0\265\265\0\335\335\0\335"
+ "\335\0ss\0\313\313\0\353\353\0\353\353\0ii\0\333\333\0\364\364\0\364\364"
+ "\0ZZ\0\351\351\0\371\371\0\371\371\0II\0\362\362\0\374\374\0\374\374\0""6"
+ "6\0\370\370\0\376\376\0\376\376\0\"\"\0\374\374\0\376\376\0\376\376\0\16"
+ "\16\0\376\376\0\376\376\0\376\376\0\376\376\0\375\375\0\376\376\0\376\376"
+ "\0\376\376\0\360\360\0\360\360\0\360\360\0\360\360\0\16\16\0\360\360\0\360"
+ "\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0\24\24\0\22\22\0\"\"\0""88\0"
+ """88\0//\0OO\0pp\0pp\0WW\0\203\203\0\242\242\0\242\242\0qq\0\256\256\0\312"
+ "\312\0\301\301\0||\0\313\313\0\342\342\0\325\325\0yy\0\336\336\0\360\360"
+ "\0\342\342\0mm\0\353\353\0\367\367\0\354\354\0\\\\\0\363\363\0\373\373\0"
+ "\362\362\0JJ\0\371\371\0\375\375\0\367\367\0""66\0\374\374\0\376\376\0\373"
+ "\373\0\"\"\0\376\376\0\376\376\0\375\375\0\16\16\0\376\376\0\376\376\0\376"
+ "\376\0\376\376\0\376\376\0\376\376\0\375\375\0\376\376\0\376\376\0\375\375"
+ "\0\360\360\0\374\374\0\360\360\0\376\376\0\16\16\0\360\360\0\360\360\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\24\24\0\22\22\0&&\0\"\"\0""88\0//\0PP\0HH\0gg\0NN"
+ "\0pp\0ee\0}}\0VV\0{{\0oo\0\202\202\0NN\0qq\0jj\0vv\0>>\0``\0\\\\\0cc\0,,"
+ "\0MM\0KK\0OO\0\35\35\0::\0""99\0;;\0\21\21\0**\0))\0**\0\10\10\0\33\33\0"
+ "\33\33\0\33\33\0\3\3\0\17\17\0\17\17\0\17\17\0\0\0\0\7\7\0\7\7\0\7\7\0\7"
+ "\7\0\2\2\0\2\2\0\2\2\0\2\2\0\16\16\0\16\16\0\16\16\0\16\16\0\360\360\0\360"
+ "\360\0\376\376\0\376\376\0\16\16\0\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\22\22"
+ "\0&&\0&&\0\"\"\0""66\0[[\0oo\0ee\0``\0\220\220\0\270\270\0\250\250\0xx\0"
+ "\250\250\0\327\327\0\311\311\0zz\0\246\246\0\341\341\0\325\325\0rr\0\230"
+ "\230\0\343\343\0\334\334\0gg\0\205\205\0\344\344\0\340\340\0[[\0rr\0\346"
+ "\346\0\344\344\0NN\0^^\0\352\352\0\352\352\0AA\0JJ\0\357\357\0\357\357\0"
+ """11\0""66\0\364\364\0\364\364\0\40\40\0\"\"\0\371\371\0\371\371\0\16\16"
+ "\0\16\16\0\375\375\0\375\375\0\376\376\0\376\376\0\362\362\0\362\362\0\376"
+ "\376\0\376\376\0\16\16\0\16\16\0\376\376\0\376\376\0\376\376\0\16\16\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\22\22\0&&\0&&\0\37\37\0;;\0``\0``\0HH\0qq\0\237\237"
+ "\0\237\237\0nn\0\227\227\0\306\306\0\306\306\0}}\0\254\254\0\334\334\0\334"
+ "\334\0}}\0\275\275\0\347\347\0\347\347\0vv\0\316\316\0\357\357\0\357\357"
+ "\0ii\0\334\334\0\365\365\0\365\365\0ZZ\0\351\351\0\371\371\0\371\371\0II"
+ "\0\362\362\0\374\374\0\374\374\0""66\0\370\370\0\376\376\0\376\376\0\"\""
+ "\0\374\374\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376\0\376\376\0\376"
+ "\376\0\375\375\0\376\376\0\376\376\0\376\376\0\360\360\0\360\360\0\360\360"
+ "\0\360\360\0\16\16\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "&&\0&&\0##\0--\0``\0``\0TT\0cc\0\237\237\0\231\231\0||\0\223\223\0\306\306"
+ "\0\301\301\0\217\217\0\267\267\0\336\336\0\322\322\0\220\220\0\317\317\0"
+ "\352\352\0\334\334\0\202\202\0\337\337\0\362\362\0\345\345\0qq\0\353\353"
+ "\0\370\370\0\354\354\0^^\0\363\363\0\373\373\0\362\362\0JJ\0\371\371\0\375"
+ "\375\0\367\367\0""66\0\374\374\0\376\376\0\373\373\0\"\"\0\376\376\0\376"
+ "\376\0\375\375\0\16\16\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376"
+ "\0\376\376\0\375\375\0\376\376\0\376\376\0\375\375\0\360\360\0\376\376\0"
+ "\360\360\0\376\376\0\16\16\0\376\376\0\376\376\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "&&\0##\0""77\0--\0``\0PP\0nn\0[[\0\222\222\0kk\0\211\211\0qq\0\231\231\0"
+ "ff\0\210\210\0uu\0\217\217\0UU\0vv\0ll\0zz\0@@\0aa\0]]\0dd\0,,\0MM\0KK\0"
+ "OO\0\35\35\0::\0""99\0;;\0\21\21\0**\0))\0**\0\10\10\0\33\33\0\33\33\0\33"
+ "\33\0\3\3\0\17\17\0\17\17\0\17\17\0\0\0\0\7\7\0\7\7\0\7\7\0\7\7\0\2\2\0\2"
+ "\2\0\2\2\0\2\2\0\16\16\0\16\16\0\16\16\0\16\16\0\360\360\0\360\360\0\376"
+ "\376\0\376\376\0\16\16\0\376\376\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0##\0""77\0""77"
+ "\0--\0UU\0zz\0\216\216\0ww\0}}\0\254\254\0\324\324\0\264\264\0\207\207\0"
+ "\266\266\0\345\345\0\316\316\0\177\177\0\254\254\0\346\346\0\326\326\0rr"
+ "\0\231\231\0\344\344\0\334\334\0gg\0\206\206\0\344\344\0\340\340\0[[\0rr"
+ "\0\346\346\0\344\344\0NN\0^^\0\352\352\0\352\352\0AA\0JJ\0\357\357\0\357"
+ "\357\0""11\0""66\0\364\364\0\364\364\0\40\40\0\"\"\0\371\371\0\371\371\0"
+ "\16\16\0\16\16\0\375\375\0\375\375\0\376\376\0\376\376\0\362\362\0\362\362"
+ "\0\376\376\0\376\376\0\16\16\0\16\16\0\376\376\0\376\376\0\376\376\0\16\16"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\22\22\0""77\0""77\0--\0CC\0~~\0~~\0\\\\\0||\0"
+ "\274\274\0\274\274\0||\0\235\235\0\325\325\0\325\325\0\204\204\0\256\256"
+ "\0\340\340\0\340\340\0\177\177\0\275\275\0\351\351\0\351\351\0vv\0\316\316"
+ "\0\360\360\0\360\360\0ii\0\334\334\0\365\365\0\365\365\0ZZ\0\351\351\0\371"
+ "\371\0\371\371\0II\0\362\362\0\374\374\0\374\374\0""66\0\370\370\0\376\376"
+ "\0\376\376\0\"\"\0\374\374\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376"
+ "\0\376\376\0\376\376\0\375\375\0\376\376\0\376\376\0\376\376\0\360\360\0"
+ "\360\360\0\360\360\0\360\360\0\16\16\0\376\376\0\376\376\0\16\16\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0&&\0""77\0""22\0--\0``\0vv\0pp\0gg\0\243\243\0\255\255"
+ "\0\225\225\0\231\231\0\311\311\0\314\314\0\235\235\0\271\271\0\337\337\0"
+ "\326\326\0\224\224\0\320\320\0\352\352\0\336\336\0\204\204\0\337\337\0\362"
+ "\362\0\345\345\0qq\0\353\353\0\370\370\0\354\354\0^^\0\363\363\0\373\373"
+ "\0\362\362\0JJ\0\371\371\0\375\375\0\367\367\0""66\0\374\374\0\376\376\0"
+ "\373\373\0\"\"\0\376\376\0\376\376\0\375\375\0\16\16\0\376\376\0\376\376"
+ "\0\376\376\0\376\376\0\376\376\0\376\376\0\375\375\0\376\376\0\376\376\0"
+ "\375\375\0\360\360\0\376\376\0\360\360\0\376\376\0\16\16\0\376\376\0\376"
+ "\376\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0&&\0##\0FF\0""99\0``\0PP\0\200\200\0dd\0\222"
+ "\222\0kk\0\222\222\0vv\0\231\231\0ff\0\213\213\0ww\0\217\217\0UU\0xx\0mm"
+ "\0zz\0@@\0bb\0]]\0dd\0,,\0MM\0KK\0OO\0\35\35\0::\0""99\0;;\0\21\21\0**\0"
+ "))\0**\0\10\10\0\33\33\0\33\33\0\33\33\0\3\3\0\17\17\0\17\17\0\17\17\0\0"
+ "\0\0\7\7\0\7\7\0\7\7\0\7\7\0\2\2\0\2\2\0\2\2\0\2\2\0\16\16\0\16\16\0\16\16"
+ "\0\16\16\0\360\360\0\360\360\0\376\376\0\376\376\0\16\16\0\376\376\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0##\0""77\0""77\0""99\0^^\0zz\0\216\216\0\201\201\0\203"
+ "\203\0\254\254\0\324\324\0\271\271\0\211\211\0\266\266\0\345\345\0\317\317"
+ "\0\200\200\0\254\254\0\346\346\0\326\326\0ss\0\231\231\0\344\344\0\334\334"
+ "\0gg\0\206\206\0\344\344\0\340\340\0[[\0rr\0\346\346\0\344\344\0NN\0^^\0"
+ "\352\352\0\352\352\0AA\0JJ\0\357\357\0\357\357\0""11\0""66\0\364\364\0\364"
+ "\364\0\40\40\0\"\"\0\371\371\0\371\371\0\16\16\0\16\16\0\375\375\0\375\375"
+ "\0\376\376\0\376\376\0\362\362\0\362\362\0\376\376\0\376\376\0\16\16\0\16"
+ "\16\0\376\376\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\22\22"
+ "\0""77\0""77\0--\0MM\0\210\210\0\210\210\0\\\\\0\202\202\0\302\302\0\302"
+ "\302\0||\0\240\240\0\330\330\0\330\330\0\204\204\0\257\257\0\341\341\0\341"
+ "\341\0\177\177\0\275\275\0\351\351\0\351\351\0vv\0\316\316\0\360\360\0\360"
+ "\360\0ii\0\334\334\0\365\365\0\365\365\0ZZ\0\351\351\0\371\371\0\371\371"
+ "\0II\0\362\362\0\374\374\0\374\374\0""66\0\370\370\0\376\376\0\376\376\0"
+ "\"\"\0\374\374\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376\0\376\376"
+ "\0\376\376\0\375\375\0\376\376\0\376\376\0\376\376\0\360\360\0\360\360\0"
+ "\360\360\0\360\360\0\16\16\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0&&\0""77\0""22\0--\0``\0vv\0xx\0kk\0\245\245\0\257\257\0\235\235"
+ "\0\234\234\0\312\312\0\315\315\0\241\241\0\272\272\0\337\337\0\326\326\0"
+ "\225\225\0\320\320\0\352\352\0\336\336\0\204\204\0\337\337\0\362\362\0\345"
+ "\345\0qq\0\353\353\0\370\370\0\354\354\0^^\0\363\363\0\373\373\0\362\362"
+ "\0JJ\0\371\371\0\375\375\0\367\367\0""66\0\374\374\0\376\376\0\373\373\0"
+ "\"\"\0\376\376\0\376\376\0\375\375\0\16\16\0\376\376\0\376\376\0\376\376"
+ "\0\376\376\0\376\376\0\376\376\0\375\375\0\376\376\0\376\376\0\375\375\0"
+ "\360\360\0\376\376\0\360\360\0\376\376\0\16\16\0\376\376\0\376\376\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0&&\0##\0FF\0""99\0``\0PP\0\200\200\0dd\0\222\222\0kk"
+ "\0\222\222\0vv\0\231\231\0ff\0\213\213\0ww\0\217\217\0UU\0xx\0mm\0zz\0@@"
+ "\0bb\0]]\0dd\0,,\0MM\0KK\0OO\0\35\35\0::\0""99\0;;\0\21\21\0**\0))\0**\0"
+ "\10\10\0\33\33\0\33\33\0\33\33\0\3\3\0\17\17\0\17\17\0\17\17\0\0\0\0\7\7"
+ "\0\7\7\0\7\7\0\7\7\0\2\2\0\2\2\0\2\2\0\2\2\0\16\16\0\16\16\0\16\16\0\16\16"
+ "\0\360\360\0\360\360\0\376\376\0\376\376\0\16\16\0\376\376\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0##\0""77\0""77\0""99\0^^\0zz\0\216\216\0\201\201\0\203\203\0"
+ "\254\254\0\324\324\0\271\271\0\211\211\0\266\266\0\345\345\0\317\317\0\200"
+ "\200\0\254\254\0\346\346\0\326\326\0ss\0\231\231\0\344\344\0\334\334\0gg"
+ "\0\206\206\0\344\344\0\340\340\0[[\0rr\0\346\346\0\344\344\0NN\0^^\0\352"
+ "\352\0\352\352\0AA\0JJ\0\357\357\0\357\357\0""11\0""66\0\364\364\0\364\364"
+ "\0\40\40\0\"\"\0\371\371\0\371\371\0\16\16\0\16\16\0\375\375\0\375\375\0"
+ "\376\376\0\376\376\0\362\362\0\362\362\0\376\376\0\376\376\0\16\16\0\16\16"
+ "\0\376\376\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\22\22\0"
+ """77\0""77\0--\0MM\0\210\210\0\210\210\0\\\\\0\202\202\0\302\302\0\302\302"
+ "\0||\0\240\240\0\330\330\0\330\330\0\204\204\0\257\257\0\341\341\0\341\341"
+ "\0\177\177\0\275\275\0\351\351\0\351\351\0vv\0\316\316\0\360\360\0\360\360"
+ "\0ii\0\334\334\0\365\365\0\365\365\0ZZ\0\351\351\0\371\371\0\371\371\0II"
+ "\0\362\362\0\374\374\0\374\374\0""66\0\370\370\0\376\376\0\376\376\0\"\""
+ "\0\374\374\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376\0\376\376\0\376"
+ "\376\0\375\375\0\376\376\0\376\376\0\376\376\0\360\360\0\360\360\0\360\360"
+ "\0\360\360\0\16\16\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "&&\0""77\0""22\0--\0``\0vv\0xx\0kk\0\245\245\0\257\257\0\235\235\0\234\234"
+ "\0\312\312\0\315\315\0\241\241\0\272\272\0\337\337\0\326\326\0\225\225\0"
+ "\320\320\0\352\352\0\336\336\0\204\204\0\337\337\0\362\362\0\345\345\0qq"
+ "\0\353\353\0\370\370\0\354\354\0^^\0\363\363\0\373\373\0\362\362\0JJ\0\371"
+ "\371\0\375\375\0\367\367\0""66\0\374\374\0\376\376\0\373\373\0\"\"\0\376"
+ "\376\0\376\376\0\375\375\0\16\16\0\376\376\0\376\376\0\376\376\0\376\376"
+ "\0\376\376\0\376\376\0\375\375\0\376\376\0\376\376\0\375\375\0\360\360\0"
+ "\376\376\0\360\360\0\376\376\0\16\16\0\376\376\0\376\376\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0&&\0##\0FF\0""99\0``\0PP\0\200\200\0dd\0\222\222\0kk\0\222\222"
+ "\0vv\0\231\231\0ff\0\213\213\0ww\0\217\217\0UU\0xx\0mm\0zz\0@@\0bb\0]]\0"
+ "dd\0,,\0MM\0KK\0OO\0\35\35\0::\0""99\0;;\0\21\21\0**\0))\0**\0\10\10\0\33"
+ "\33\0\33\33\0\33\33\0\3\3\0\17\17\0\17\17\0\17\17\0\0\0\0\7\7\0\7\7\0\7\7"
+ "\0\7\7\0\2\2\0\2\2\0\2\2\0\2\2\0\16\16\0\16\16\0\16\16\0\16\16\0\360\360"
+ "\0\360\360\0\376\376\0\376\376\0\16\16\0\376\376\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0##\0""77\0""77\0""99\0^^\0zz\0\216\216\0\201\201\0\203\203\0\254\254\0"
+ "\324\324\0\271\271\0\211\211\0\266\266\0\345\345\0\317\317\0\200\200\0\254"
+ "\254\0\346\346\0\326\326\0ss\0\231\231\0\344\344\0\334\334\0gg\0\206\206"
+ "\0\344\344\0\340\340\0[[\0rr\0\346\346\0\344\344\0NN\0^^\0\352\352\0\352"
+ "\352\0AA\0JJ\0\357\357\0\357\357\0""11\0""66\0\364\364\0\364\364\0\40\40"
+ "\0\"\"\0\371\371\0\371\371\0\16\16\0\16\16\0\375\375\0\375\375\0\376\376"
+ "\0\376\376\0\362\362\0\362\362\0\376\376\0\376\376\0\16\16\0\16\16\0\376"
+ "\376\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\22\22\0""77\0"
+ """77\0--\0MM\0\210\210\0\210\210\0\\\\\0\202\202\0\302\302\0\302\302\0||"
+ "\0\240\240\0\330\330\0\330\330\0\204\204\0\257\257\0\341\341\0\341\341\0"
+ "\177\177\0\275\275\0\351\351\0\351\351\0vv\0\316\316\0\360\360\0\360\360"
+ "\0ii\0\334\334\0\365\365\0\365\365\0ZZ\0\351\351\0\371\371\0\371\371\0II"
+ "\0\362\362\0\374\374\0\374\374\0""66\0\370\370\0\376\376\0\376\376\0\"\""
+ "\0\374\374\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376\0\376\376\0\376"
+ "\376\0\375\375\0\376\376\0\376\376\0\376\376\0\360\360\0\360\360\0\360\360"
+ "\0\360\360\0\16\16\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "&&\0""77\0""22\0--\0``\0vv\0xx\0kk\0\245\245\0\257\257\0\235\235\0\234\234"
+ "\0\312\312\0\315\315\0\241\241\0\272\272\0\337\337\0\326\326\0\225\225\0"
+ "\320\320\0\352\352\0\336\336\0\204\204\0\337\337\0\362\362\0\345\345\0qq"
+ "\0\353\353\0\370\370\0\354\354\0^^\0\363\363\0\373\373\0\362\362\0JJ\0\371"
+ "\371\0\375\375\0\367\367\0""66\0\374\374\0\376\376\0\373\373\0\"\"\0\376"
+ "\376\0\376\376\0\375\375\0\16\16\0\376\376\0\376\376\0\376\376\0\376\376"
+ "\0\376\376\0\376\376\0\375\375\0\376\376\0\376\376\0\375\375\0\360\360\0"
+ "\376\376\0\360\360\0\376\376\0\16\16\0\376\376\0\376\376\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0&&\0##\0FF\0""99\0``\0PP\0\200\200\0dd\0\222\222\0kk\0\222\222"
+ "\0vv\0\231\231\0ff\0\213\213\0ww\0\217\217\0UU\0xx\0mm\0zz\0@@\0bb\0]]\0"
+ "dd\0,,\0MM\0KK\0OO\0\35\35\0::\0""99\0;;\0\21\21\0**\0))\0**\0\10\10\0\33"
+ "\33\0\33\33\0\33\33\0\3\3\0\17\17\0\17\17\0\17\17\0\0\0\0\7\7\0\7\7\0\7\7"
+ "\0\7\7\0\2\2\0\2\2\0\2\2\0\2\2\0\16\16\0\16\16\0\16\16\0\16\16\0\360\360"
+ "\0\360\360\0\376\376\0\376\376\0\16\16\0\376\376\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0##\0""77\0""77\0""99\0^^\0zz\0\216\216\0\201\201\0\203\203\0\254\254\0"
+ "\324\324\0\271\271\0\211\211\0\266\266\0\345\345\0\317\317\0\200\200\0\254"
+ "\254\0\346\346\0\326\326\0ss\0\231\231\0\344\344\0\334\334\0gg\0\206\206"
+ "\0\344\344\0\340\340\0[[\0rr\0\346\346\0\344\344\0NN\0^^\0\352\352\0\352"
+ "\352\0AA\0JJ\0\357\357\0\357\357\0""11\0""66\0\364\364\0\364\364\0\40\40"
+ "\0\"\"\0\371\371\0\371\371\0\16\16\0\16\16\0\375\375\0\375\375\0\376\376"
+ "\0\376\376\0\362\362\0\362\362\0\376\376\0\376\376\0\16\16\0\16\16\0\376"
+ "\376\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\22\22\0""77\0"
+ """77\0--\0MM\0\210\210\0\210\210\0\\\\\0\202\202\0\302\302\0\302\302\0||"
+ "\0\240\240\0\330\330\0\330\330\0\204\204\0\257\257\0\341\341\0\341\341\0"
+ "\177\177\0\275\275\0\351\351\0\351\351\0vv\0\316\316\0\360\360\0\360\360"
+ "\0ii\0\334\334\0\365\365\0\365\365\0ZZ\0\351\351\0\371\371\0\371\371\0II"
+ "\0\362\362\0\374\374\0\374\374\0""66\0\370\370\0\376\376\0\376\376\0\"\""
+ "\0\374\374\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376\0\376\376\0\376"
+ "\376\0\375\375\0\376\376\0\376\376\0\376\376\0\360\360\0\360\360\0\360\360"
+ "\0\360\360\0\16\16\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "&&\0""77\0""22\0--\0``\0vv\0xx\0kk\0\245\245\0\257\257\0\235\235\0\234\234"
+ "\0\312\312\0\315\315\0\241\241\0\272\272\0\337\337\0\326\326\0\225\225\0"
+ "\320\320\0\352\352\0\336\336\0\204\204\0\337\337\0\362\362\0\345\345\0qq"
+ "\0\353\353\0\370\370\0\354\354\0^^\0\363\363\0\373\373\0\362\362\0JJ\0\371"
+ "\371\0\375\375\0\367\367\0""66\0\374\374\0\376\376\0\373\373\0\"\"\0\376"
+ "\376\0\376\376\0\375\375\0\16\16\0\376\376\0\376\376\0\376\376\0\376\376"
+ "\0\376\376\0\376\376\0\375\375\0\376\376\0\376\376\0\375\375\0\360\360\0"
+ "\376\376\0\360\360\0\376\376\0\16\16\0\376\376\0\376\376\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0&&\0##\0FF\0""99\0``\0PP\0\213\213\0mm\0\237\237\0uu\0\275\275"
+ "\0\232\232\0\306\306\0\204\204\0\331\331\0\272\272\0\336\336\0\205\205\0"
+ "\345\345\0\320\320\0\352\352\0{{\0\355\355\0\337\337\0\362\362\0mm\0\363"
+ "\363\0\353\353\0\370\370\0\\\\\0\367\367\0\363\363\0\373\373\0II\0\373\373"
+ "\0\371\371\0\375\375\0""66\0\375\375\0\374\374\0\376\376\0\"\"\0\376\376"
+ "\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376\0\376\376\0\376\376\0\376"
+ "\376\0\376\376\0\376\376\0\376\376\0\375\375\0\376\376\0\375\375\0\375\375"
+ "\0\360\360\0\360\360\0\376\376\0\376\376\0\16\16\0\376\376\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0##\0""77\0""77\0""99\0gg\0\205\205\0\205\205\0ww\0\224\224\0"
+ "\310\310\0\310\310\0\247\247\0\240\240\0\354\354\0\354\354\0\306\306\0\227"
+ "\227\0\372\372\0\372\372\0\325\325\0\205\205\0\375\375\0\375\375\0\342\342"
+ "\0rr\0\376\376\0\376\376\0\354\354\0^^\0\376\376\0\376\376\0\363\363\0JJ"
+ "\0\376\376\0\376\376\0\370\370\0""66\0\376\376\0\376\376\0\374\374\0\"\""
+ "\0\376\376\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376\0\376\376\0\376"
+ "\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\375\375"
+ "\0\376\376\0\376\376\0\376\376\0\362\362\0\376\376\0\376\376\0\376\376\0"
+ "\16\16\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\22\22\0""77\0""77\0""11\0>>\0~~\0~~\0bb"
+ "\0__\0\261\261\0\261\261\0\212\212\0``\0\277\277\0\277\277\0\230\230\0SS"
+ "\0\275\275\0\275\275\0\233\233\0@@\0\273\273\0\273\273\0\240\240\0//\0\274"
+ "\274\0\274\274\0\252\252\0!!\0\301\301\0\301\301\0\266\266\0\25\25\0\311"
+ "\311\0\311\311\0\303\303\0\14\14\0\324\324\0\324\324\0\322\322\0\6\6\0\342"
+ "\342\0\342\342\0\341\341\0\1\1\0\361\361\0\361\361\0\361\361\0\15\15\0\15"
+ "\15\0\15\15\0\15\15\0\362\362\0\362\362\0\362\362\0\360\360\0\16\16\0\16"
+ "\16\0\16\16\0\2\2\0\376\376\0\376\376\0\376\376\0\16\16\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0&&\0""77\0""77\0\34\34\0SS\0kk\0\206\206\0BB\0\214\214\0\232\232"
+ "\0\302\302\0YY\0\250\250\0\255\255\0\340\340\0XX\0\264\264\0\264\264\0\355"
+ "\355\0SS\0\265\265\0\266\266\0\364\364\0JJ\0\270\270\0\272\272\0\371\371"
+ "\0AA\0\277\277\0\300\300\0\374\374\0""66\0\310\310\0\311\311\0\375\375\0"
+ "**\0\324\324\0\324\324\0\376\376\0\34\34\0\341\341\0\342\342\0\376\376\0"
+ "\15\15\0\361\361\0\361\361\0\376\376\0\361\361\0\15\15\0\15\15\0\376\376"
+ "\0\15\15\0\361\361\0\361\361\0\373\373\0\362\362\0\15\15\0\16\16\0\376\376"
+ "\0\16\16\0\361\361\0\376\376\0\376\376\0\376\376\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0&&\0&&\0""77\0))\0SS\0SS\0kk\0DD\0\205\205\0}}\0\222\222\0WW\0\241\241"
+ "\0\230\230\0\245\245\0XX\0\261\261\0\252\252\0\261\261\0SS\0\264\264\0\263"
+ "\263\0\265\265\0JJ\0\270\270\0\271\271\0\272\272\0AA\0\276\276\0\300\300"
+ "\0\300\300\0""66\0\310\310\0\311\311\0\311\311\0**\0\324\324\0\324\324\0"
+ "\324\324\0\34\34\0\341\341\0\342\342\0\342\342\0\15\15\0\361\361\0\361\361"
+ "\0\361\361\0\361\361\0\15\15\0\15\15\0\15\15\0\15\15\0\361\361\0\361\361"
+ "\0\361\361\0\362\362\0\15\15\0\16\16\0\16\16\0\16\16\0\361\361\0\376\376"
+ "\0\376\376\0\376\376\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0&&\0&&\0&&\0))\0pp\0cc\0cc"
+ "\0QQ\0\261\261\0\244\244\0\244\244\0ll\0\335\335\0\323\323\0\323\323\0ww"
+ "\0\364\364\0\356\356\0\356\356\0ss\0\370\370\0\371\371\0\371\371\0ii\0\372"
+ "\372\0\375\375\0\375\375\0YY\0\374\374\0\376\376\0\376\376\0HH\0\375\375"
+ "\0\376\376\0\376\376\0""66\0\376\376\0\376\376\0\376\376\0\"\"\0\376\376"
+ "\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376\0\376\376\0\376\376\0\376"
+ "\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376"
+ "\0\375\375\0\376\376\0\376\376\0\376\376\0\361\361\0\376\376\0\376\376\0"
+ "\376\376\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0&&\0&&\0\40\40\0QQ\0pp\0pp\0KK"
+ "\0\215\215\0\261\261\0\261\261\0pp\0\274\274\0\337\337\0\337\337\0\200\200"
+ "\0\332\332\0\364\364\0\364\364\0}}\0\350\350\0\373\373\0\373\373\0oo\0\361"
+ "\361\0\375\375\0\375\375\0]]\0\367\367\0\376\376\0\376\376\0JJ\0\373\373"
+ "\0\376\376\0\376\376\0""66\0\375\375\0\376\376\0\376\376\0\"\"\0\376\376"
+ "\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376\0\376\376\0\376\376\0\376"
+ "\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376"
+ "\0\375\375\0\376\376\0\376\376\0\376\376\0\361\361\0\376\376\0\376\376\0"
+ "\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0&&\0&&\0\20\20\0""88\0WW\0pp\0"
+ "==\0ss\0\212\212\0\252\252\0dd\0\250\250\0\264\264\0\312\312\0rr\0\313\313"
+ "\0\315\315\0\331\331\0rr\0\340\340\0\331\331\0\340\340\0hh\0\355\355\0\341"
+ "\341\0\345\345\0YY\0\366\366\0\350\350\0\352\352\0HH\0\372\372\0\356\356"
+ "\0\357\357\0""66\0\375\375\0\364\364\0\364\364\0\"\"\0\376\376\0\371\371"
+ "\0\371\371\0\16\16\0\376\376\0\375\375\0\375\375\0\376\376\0\376\376\0\361"
+ "\361\0\362\362\0\376\376\0\376\376\0\16\16\0\16\16\0\376\376\0\375\375\0"
+ "\376\376\0\375\375\0\374\374\0\360\360\0\376\376\0\376\376\0\360\360\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\24\24\0\24\24\0&&\0\40\40\0""88\0""88\0WW\0BB\0ff"
+ "\0ZZ\0}}\0^^\0\226\226\0\201\201\0\241\241\0nn\0\301\301\0\246\246\0\277"
+ "\277\0rr\0\333\333\0\301\301\0\321\321\0ii\0\353\353\0\323\323\0\335\335"
+ "\0[[\0\365\365\0\341\341\0\346\346\0II\0\372\372\0\353\353\0\356\356\0""6"
+ "6\0\375\375\0\363\363\0\364\364\0\"\"\0\376\376\0\371\371\0\371\371\0\16"
+ "\16\0\376\376\0\375\375\0\375\375\0\376\376\0\376\376\0\361\361\0\361\361"
+ "\0\376\376\0\376\376\0\16\16\0\16\16\0\376\376\0\374\374\0\375\375\0\374"
+ "\374\0\374\374\0\361\361\0\376\376\0\360\360\0\360\360\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\24\24\0\24\24\0\24\24\0\40\40\0HH\0""88\0""88\0BB\0~~\0ff\0ff\0"
+ "^^\0\256\256\0\226\226\0\226\226\0qq\0\325\325\0\277\277\0\277\277\0ss\0"
+ "\350\350\0\331\331\0\331\331\0jj\0\363\363\0\353\353\0\353\353\0[[\0\371"
+ "\371\0\365\365\0\365\365\0II\0\374\374\0\372\372\0\372\372\0""66\0\375\375"
+ "\0\375\375\0\375\375\0\"\"\0\376\376\0\376\376\0\376\376\0\16\16\0\376\376"
+ "\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0"
+ "\376\376\0\376\376\0\376\376\0\376\376\0\374\374\0\374\374\0\374\374\0\376"
+ "\376\0\361\361\0\360\360\0\360\360\0\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\24\24\0\24\24\0\24\24\0\40\40\0HH\0HH\0""88\0BB\0~~\0~~\0ff\0^^\0\263"
+ "\263\0\263\263\0\231\231\0nn\0\330\330\0\330\330\0\274\274\0pp\0\353\353"
+ "\0\353\353\0\324\324\0hh\0\365\365\0\365\365\0\345\345\0ZZ\0\373\373\0\373"
+ "\373\0\361\361\0II\0\375\375\0\375\375\0\370\370\0""66\0\376\376\0\376\376"
+ "\0\374\374\0\"\"\0\376\376\0\376\376\0\376\376\0\16\16\0\376\376\0\376\376"
+ "\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0\376\376\0"
+ "\376\376\0\374\374\0\374\374\0\376\376\0\376\376\0\361\361\0\360\360\0\360"
+ "\360\0\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0\24\24\0\0\0"
+ "\0\0\0\0((\0HH\0\40\40\0\25\25\0QQ\0\207\207\0KK\0--\0}}\0\262\262\0bb\0"
+ """44\0\235\235\0\320\320\0ff\0""00\0\257\257\0\341\341\0cc\0))\0\272\272"
+ "\0\354\354\0ZZ\0\37\37\0\303\303\0\363\363\0OO\0\26\26\0\314\314\0\370\370"
+ "\0AA\0\15\15\0\326\326\0\373\373\0""22\0\6\6\0\343\343\0\375\375\0!!\0\1"
+ "\1\0\362\362\0\376\376\0\16\16\0\16\16\0\16\16\0\375\375\0\375\375\0\375"
+ "\375\0\376\376\0\362\362\0\360\360\0\361\361\0\376\376\0\14\14\0\0\0\0\0"
+ "\0\0\360\360\0\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24"
+ "\0\24\24\0\0\0\0\0\0\0((\0((\0\0\0\0\0\0\0<<\0<<\0\0\0\0\0\0\0PP\0PP\0\10"
+ "\10\0\4\4\0dd\0dd\0\14\14\0\6\6\0xx\0xx\0\14\14\0\5\5\0\214\214\0\214\214"
+ "\0\13\13\0\4\4\0\240\240\0\240\240\0\10\10\0\2\2\0\264\264\0\264\264\0\5"
+ "\5\0\1\1\0\310\310\0\310\310\0\3\3\0\0\0\0\334\334\0\334\334\0\1\1\0\0\0"
+ "\0\360\360\0\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\1\1\0\1\1\0\0\0\0\0\0\0\14"
+ "\14\0\14\14\0\0\0\0\0\0\0\360\360\0\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0\24\24\0\0\0\0\0\0\0((\0((\0\0\0\0\0\0"
+ "\0<<\0<<\0\0\0\0\0\0\0XX\0XX\0\0\0\0\0\0\0pp\0pp\0\0\0\0\0\0\0\204\204\0"
+ "\204\204\0\0\0\0\0\0\0\227\227\0\227\227\0\0\0\0\0\0\0\250\250\0\250\250"
+ "\0\0\0\0\0\0\0\271\271\0\271\271\0\0\0\0\0\0\0\313\313\0\313\313\0\0\0\0"
+ "\0\0\0\335\335\0\335\335\0\0\0\0\0\0\0\360\360\0\360\360\0\0\0\0\0\0\0\1"
+ "\1\0\1\1\0\0\0\0\0\0\0\14\14\0\14\14\0\0\0\0\0\0\0\360\360\0\360\360\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0"
+ "\24\24\0\24\24\0\0\0\0((\0((\0((\0\0\0\0<<\0HH\0HH\0\10\10\0PP\0dd\0dd\0"
+ "\14\14\0dd\0||\0||\0\14\14\0xx\0\221\221\0\221\221\0\13\13\0\214\214\0\243"
+ "\243\0\243\243\0\10\10\0\240\240\0\264\264\0\264\264\0\5\5\0\264\264\0\303"
+ "\303\0\303\303\0\3\3\0\310\310\0\322\322\0\322\322\0\1\1\0\334\334\0\341"
+ "\341\0\341\341\0\0\0\0\360\360\0\361\361\0\361\361\0\1\1\0\0\0\0\14\14\0"
+ "\14\14\0\14\14\0\0\0\0\360\360\0\360\360\0\360\360\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\24\24\0"
+ "\24\24\0\20\20\0\20\20\0""88\0""88\0**\0**\0ZZ\0ZZ\0==\0==\0yy\0yy\0II\0"
+ "II\0\224\224\0\224\224\0NN\0NN\0\254\254\0\254\254\0MM\0MM\0\302\302\0\302"
+ "\302\0HH\0HH\0\324\324\0\324\324\0>>\0>>\0\343\343\0\343\343\0""00\0""00"
+ "\0\356\356\0\356\356\0\40\40\0\40\40\0\367\367\0\367\367\0\16\16\0\16\16"
+ "\0\374\374\0\374\374\0\374\374\0\374\374\0\360\360\0\360\360\0\360\360\0"
+ "\360\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
+};
+
+/**
+ * \brief Returns the BlitAlpha test image as SDL_Surface.
+ */
+SDL_Surface *SDLTest_ImageBlitAlpha()
+{
+ SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
+ (void*)SDLTest_imageBlitAlpha.pixel_data,
+ SDLTest_imageBlitAlpha.width,
+ SDLTest_imageBlitAlpha.height,
+ SDLTest_imageBlitAlpha.bytes_per_pixel * 8,
+ SDLTest_imageBlitAlpha.width * SDLTest_imageBlitAlpha.bytes_per_pixel,
+#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ 0xff000000, /* Red bit mask. */
+ 0x00ff0000, /* Green bit mask. */
+ 0x0000ff00, /* Blue bit mask. */
+ 0x000000ff /* Alpha bit mask. */
+#else
+ 0x000000ff, /* Red bit mask. */
+ 0x0000ff00, /* Green bit mask. */
+ 0x00ff0000, /* Blue bit mask. */
+ 0xff000000 /* Alpha bit mask. */
+#endif
+ );
+ return surface;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/test/SDL_test_imageBlitBlend.c b/src/3rdparty/SDL2/src/test/SDL_test_imageBlitBlend.c
new file mode 100644
index 0000000..cf2d4af
--- /dev/null
+++ b/src/3rdparty/SDL2/src/test/SDL_test_imageBlitBlend.c
@@ -0,0 +1,2845 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#include "SDL_test.h"
+
+/* GIMP RGB C-Source image dump (alpha.c) */
+
+static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAdd = {
+ 80, 60, 3,
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0dd\0\310\310\0\310\310\0\310\310\0\310"
+ "\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310"
+ "\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0"
+ "\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310"
+ "\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310"
+ "\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0"
+ "\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310"
+ "\310\0dd\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0dd\0dd\0dd\0dd\0\310\310\0\310\310\0\310\310\0\310\310\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310"
+ "\0\310\310\0\310\310\0\310\310\0dd\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0dd\0\310\310\0\310\310\0\310\310\0\310\310"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\310\310\0\310\310\0\310\310\0\310\310\0dd\0dd\0dd"
+ "\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0dd\0\310\310\0\310\310\0"
+ "\310\310\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0\310"
+ "\310\0\310\310\0\310\310\0dd\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0"
+ "dd\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0"
+ "dd\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0dd\0\310\310\0\310\310\0\310\310"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\310\310\0\310\310\0\310\310\0dd\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd"
+ "\0\310\310\0\310\310\0\310\310\0\310\310\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310"
+ "\310\0\310\310\0\310\310\0\310\310\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0\310\310\0\310\310"
+ "\0\310\310\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310"
+ "\310\0\310\310\0\310\310\0\310\310\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\310\310\0\310\310\0\310"
+ "\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\310\310\0\310\310\0\310\310\0dd\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\310\310\0\310"
+ "\310\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\310\310\0\310\310\0\310\310\0dd\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310"
+ "\0\310\310\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0\310\310"
+ "\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\310\310\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\310\310\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0dd\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310"
+ "\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\310\310\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\310\310\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0dd\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\310\310\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\310\310\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0dd\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310"
+ "\310\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310"
+ "\310\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310"
+ "\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310"
+ "\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\310"
+ "\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0\310"
+ "\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\377\377\0\377\377\0\310\310"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\310\310\0\377\377\0\377\377\0\310\310\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\310\0\310\310"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0\310\310"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\310\310\0\310\310\0\310\310\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310"
+ "\0\310\310\0\310\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0dd\0\310\310\0\310\310\0\310\310\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310"
+ "\310\0\310\310\0\310\310\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\310\310\0\310\310\0dd\0\310\310\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\310\310\0"
+ "dd\0\310\310\0\310\310\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0\310\310\0\310\310\0\310\310\0\310\310"
+ "\0\377\377\0\377\377\0\377\377\0\310\310\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\310\310\0\377\377\0\377\377\0\377\377\0\310\310\0\310\310\0\310"
+ "\310\0\310\310\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0\310\310\0\377\377\0\310\310\0\310\310"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\310\310\0\310\310\0\377\377\0\310\310\0dd"
+ "\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0dd\0dd\0dd\0\310\310\0\377\377\0\377\377\0\310\310\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\310\310\0\377\377\0\377\377\0\310\310\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd"
+ "\0\0\0\0\0\0\0dd\0\377\377\0\310\310\0\310\310\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\310\310\0\310\310\0\377\377\0dd\0\0"
+ "\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0"
+ "\0\0dd\0dd\0\0\0\0\0\0\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0"
+ "dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0"
+ "dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0dd\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0"
+ "dd\0dd\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0\0\0\0"
+ "\0\0\0dd\0dd\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0\310\310\0\310\310\0\0\0\0"
+ "\0\0\0\310\310\0\310\310\0\0\0\0\0\0\0\310\310\0\310\310\0\0\0\0\0\0\0\310"
+ "\310\0\310\310\0\0\0\0\0\0\0\310\310\0\310\310\0\0\0\0\0\0\0\310\310\0\310"
+ "\310\0\0\0\0\0\0\0\310\310\0\310\310\0\0\0\0\0\0\0\310\310\0\310\310\0\0"
+ "\0\0\0\0\0\310\310\0\310\310\0\0\0\0\0\0\0\310\310\0\310\310\0\0\0\0\0\0"
+ "\0dd\0dd\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0\0\0\0dd\0dd\0dd\0\0\0\0dd\0\310\310\0\310"
+ "\310\0dd\0dd\0\310\310\0\310\310\0dd\0dd\0\310\310\0\310\310\0dd\0dd\0\310"
+ "\310\0\310\310\0dd\0dd\0\310\310\0\310\310\0dd\0dd\0\310\310\0\310\310\0"
+ "dd\0dd\0\310\310\0\310\310\0dd\0dd\0\310\310\0\310\310\0dd\0dd\0\310\310"
+ "\0\310\310\0dd\0dd\0\310\310\0\310\310\0dd\0dd\0\310\310\0\310\310\0dd\0"
+ "\0\0\0dd\0dd\0dd\0\0\0\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0dd\0\310\310\0\310\310\0\310\310\0\310"
+ "\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310"
+ "\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0"
+ "\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310"
+ "\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310"
+ "\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0"
+ "\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310\310\0\310"
+ "\310\0dd\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
+};
+
+/**
+ * \brief Returns the BlitBlendAdd test image as SDL_Surface.
+ */
+SDL_Surface *SDLTest_ImageBlitBlendAdd()
+{
+ SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
+ (void*)SDLTest_imageBlitBlendAdd.pixel_data,
+ SDLTest_imageBlitBlendAdd.width,
+ SDLTest_imageBlitBlendAdd.height,
+ SDLTest_imageBlitBlendAdd.bytes_per_pixel * 8,
+ SDLTest_imageBlitBlendAdd.width * SDLTest_imageBlitBlendAdd.bytes_per_pixel,
+#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ 0xff000000, /* Red bit mask. */
+ 0x00ff0000, /* Green bit mask. */
+ 0x0000ff00, /* Blue bit mask. */
+ 0x000000ff /* Alpha bit mask. */
+#else
+ 0x000000ff, /* Red bit mask. */
+ 0x0000ff00, /* Green bit mask. */
+ 0x00ff0000, /* Blue bit mask. */
+ 0xff000000 /* Alpha bit mask. */
+#endif
+ );
+ return surface;
+}
+
+static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlend = {
+ 80, 60, 3,
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0<<\0<<\0\240\240\0\240\240\0aa\0aa\0\240"
+ "\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0"
+ "aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240\240"
+ "\0\240\240\0aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0aa\0"
+ "aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240"
+ "\240\0\240\240\0\240\240\0dd\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0<<\0\240\240\0\240\240\0\240\240"
+ "\0aa\0\305\305\0\305\305\0\305\305\0ww\0\305\305\0\305\305\0\305\305\0ww"
+ "\0\305\305\0\305\305\0\305\305\0ww\0\305\305\0\305\305\0\305\305\0ww\0\305"
+ "\305\0\305\305\0\305\305\0ww\0\305\305\0\305\305\0\305\305\0ww\0\305\305"
+ "\0\305\305\0\305\305\0ww\0\305\305\0\305\305\0\305\305\0ww\0\305\305\0\305"
+ "\305\0\305\305\0ww\0\305\305\0\305\305\0\305\305\0ww\0\305\305\0\305\305"
+ "\0\305\305\0\305\305\0\240\240\0\240\240\0\240\240\0\240\240\0dd\0dd\0dd"
+ "\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0<<\0\240\240"
+ "\0\240\240\0\240\240\0aa\0\305\305\0\305\305\0\305\305\0ww\0\333\333\0\333"
+ "\333\0\305\305\0ww\0\333\333\0\333\333\0\305\305\0ww\0\333\333\0\333\333"
+ "\0\305\305\0ww\0\333\333\0\333\333\0\305\305\0ww\0\333\333\0\333\333\0\305"
+ "\305\0ww\0\333\333\0\333\333\0\305\305\0ww\0\333\333\0\333\333\0\305\305"
+ "\0ww\0\333\333\0\333\333\0\305\305\0ww\0\333\333\0\333\333\0\305\305\0ww"
+ "\0\333\333\0\333\333\0\305\305\0\305\305\0\305\305\0\305\305\0\240\240\0"
+ "\240\240\0\240\240\0\240\240\0dd\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0dd\0dd\0dd\0<<\0aa\0aa\0aa\0::\0HH\0HH\0HH\0++\0PP\0PP\0PP\0""00\0PP"
+ "\0PP\0PP\0""00\0PP\0PP\0PP\0""00\0PP\0PP\0PP\0""00\0PP\0PP\0PP\0""00\0PP"
+ "\0PP\0PP\0""00\0PP\0PP\0PP\0""00\0PP\0PP\0PP\0""00\0PP\0PP\0PP\0""00\0PP"
+ "\0PP\0PP\0PP\0HH\0HH\0HH\0HH\0aa\0aa\0aa\0aa\0dd\0dd\0dd\0dd\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0dd\0dd\0dd\0$$\0aa\0\305\305\0\305\305\0``\0\205\205\0\351\351\0"
+ "\351\351\0||\0\222\222\0\321\321\0\321\321\0\177\177\0\225\225\0\324\324"
+ "\0\321\321\0\177\177\0\225\225\0\324\324\0\321\321\0\177\177\0\225\225\0"
+ "\324\324\0\321\321\0\177\177\0\225\225\0\324\324\0\321\321\0\177\177\0\225"
+ "\225\0\324\324\0\321\321\0\177\177\0\225\225\0\324\324\0\321\321\0\177\177"
+ "\0\225\225\0\324\324\0\321\321\0\177\177\0\225\225\0\324\324\0\321\321\0"
+ "\177\177\0\225\225\0\324\324\0\321\321\0\222\222\0\222\222\0\321\321\0\314"
+ "\314\0\351\351\0\351\351\0\254\254\0\236\236\0\305\305\0\305\305\0aa\0<<"
+ "\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0<<\0dd\0\240\240\0\240\240\0aa\0\255\255"
+ "\0\322\322\0\322\322\0\177\177\0\315\315\0\343\343\0\343\343\0\211\211\0"
+ "\313\313\0\346\346\0\346\346\0\211\211\0\313\313\0\346\346\0\346\346\0\211"
+ "\211\0\313\313\0\346\346\0\346\346\0\211\211\0\313\313\0\346\346\0\346\346"
+ "\0\211\211\0\313\313\0\346\346\0\346\346\0\211\211\0\313\313\0\346\346\0"
+ "\346\346\0\211\211\0\313\313\0\346\346\0\346\346\0\211\211\0\313\313\0\346"
+ "\346\0\346\346\0\211\211\0\313\313\0\346\346\0\346\346\0\211\211\0\320\320"
+ "\0\327\327\0\327\327\0\322\322\0\276\276\0\322\322\0\322\322\0\305\305\0"
+ "yy\0\210\210\0\210\210\0dd\0<<\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0<<\0\210\210\0\240"
+ "\240\0\240\240\0aa\0\266\266\0\322\322\0\322\322\0\205\205\0\327\327\0\343"
+ "\343\0\343\343\0\215\215\0\346\346\0\357\357\0\331\331\0\222\222\0\347\347"
+ "\0\357\357\0\331\331\0\222\222\0\347\347\0\357\357\0\331\331\0\222\222\0"
+ "\347\347\0\357\357\0\331\331\0\222\222\0\347\347\0\357\357\0\331\331\0\222"
+ "\222\0\347\347\0\357\357\0\331\331\0\222\222\0\347\347\0\357\357\0\331\331"
+ "\0\222\222\0\347\347\0\357\357\0\331\331\0\222\222\0\347\347\0\357\357\0"
+ "\331\331\0\222\222\0\357\357\0\346\346\0\320\320\0\351\351\0\327\327\0\343"
+ "\343\0\276\276\0\333\333\0\322\322\0\266\266\0yy\0\240\240\0\210\210\0\240"
+ "\240\0<<\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0dd\0<<\0\240\240\0\210\210\0\240\240\0aa\0ww\0nn\0\177"
+ "\177\0MM\0SS\0OO\0SS\0""22\0WW\0TT\0XX\0""55\0UU\0UU\0XX\0""55\0UU\0UU\0"
+ "XX\0""55\0UU\0UU\0XX\0""55\0UU\0UU\0XX\0""55\0UU\0UU\0XX\0""55\0UU\0UU\0"
+ "XX\0""55\0UU\0UU\0XX\0""55\0UU\0UU\0XX\0""55\0UU\0XX\0TT\0TT\0LL\0OO\0SS"
+ "\0SS\0ss\0\177\177\0nn\0nn\0yy\0\210\210\0\240\240\0\240\240\0<<\0dd\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0<<"
+ "\0\240\240\0\240\240\0\210\210\0HH\0\205\205\0\351\351\0\333\333\0pp\0\225"
+ "\225\0\371\371\0\363\363\0\202\202\0\231\231\0\330\330\0\325\325\0\203\203"
+ "\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0"
+ "\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324"
+ "\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331"
+ "\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0"
+ "\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\325\325\0\231\231\0\231"
+ "\231\0\330\330\0\323\323\0\371\371\0\371\371\0\274\274\0\257\257\0\351\351"
+ "\0\351\351\0\205\205\0``\0\240\240\0\240\240\0\240\240\0<<\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0<<\0\240\240"
+ "\0\240\240\0RR\0\207\207\0\304\304\0\304\304\0nn\0\275\275\0\343\343\0\343"
+ "\343\0\205\205\0\324\324\0\352\352\0\352\352\0\214\214\0\316\316\0\352\352"
+ "\0\352\352\0\213\213\0\316\316\0\352\352\0\352\352\0\213\213\0\316\316\0"
+ "\352\352\0\352\352\0\213\213\0\316\316\0\352\352\0\352\352\0\213\213\0\316"
+ "\316\0\352\352\0\352\352\0\213\213\0\316\316\0\352\352\0\352\352\0\213\213"
+ "\0\316\316\0\352\352\0\352\352\0\213\213\0\316\316\0\352\352\0\352\352\0"
+ "\213\213\0\316\316\0\352\352\0\352\352\0\214\214\0\324\324\0\336\336\0\336"
+ "\336\0\331\331\0\310\310\0\343\343\0\343\343\0\325\325\0\217\217\0\254\254"
+ "\0\254\254\0\207\207\0aa\0\240\240\0\240\240\0<<\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0\240\240\0aa"
+ "\0\225\225\0\304\304\0\304\304\0\205\205\0\276\276\0\343\343\0\340\340\0"
+ "\222\222\0\333\333\0\352\352\0\351\351\0\226\226\0\347\347\0\362\362\0\333"
+ "\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361"
+ "\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0"
+ "\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351"
+ "\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230"
+ "\0\351\351\0\361\361\0\333\333\0\230\230\0\362\362\0\351\351\0\323\323\0"
+ "\366\366\0\336\336\0\351\351\0\304\304\0\351\351\0\343\343\0\304\304\0\217"
+ "\217\0\333\333\0\254\254\0\266\266\0aa\0\240\240\0\240\240\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0aa"
+ "\0\305\305\0\225\225\0\304\304\0ww\0\205\205\0ss\0\211\211\0RR\0VV\0PP\0"
+ "VV\0""33\0XX\0UU\0YY\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0"
+ "XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0"
+ "XX\0""66\0UU\0UU\0XX\0""66\0UU\0YY\0UU\0UU\0MM\0QQ\0UU\0UU\0ww\0\211\211"
+ "\0ww\0||\0\217\217\0\254\254\0\266\266\0\305\305\0aa\0\240\240\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0aa\0\305"
+ "\305\0\305\305\0\225\225\0UU\0\222\222\0\366\366\0\340\340\0tt\0\231\231"
+ "\0\375\375\0\364\364\0\203\203\0\231\231\0\331\331\0\326\326\0\203\203\0"
+ "\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203"
+ "\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324"
+ "\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0"
+ "\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331"
+ "\331\0\324\324\0\203\203\0\231\231\0\331\331\0\326\326\0\231\231\0\231\231"
+ "\0\331\331\0\324\324\0\373\373\0\375\375\0\300\300\0\263\263\0\361\361\0"
+ "\366\366\0\222\222\0mm\0\266\266\0\305\305\0\305\305\0aa\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0<<\0\305\305\0"
+ "\305\305\0``\0\214\214\0\321\321\0\321\321\0rr\0\277\277\0\346\346\0\346"
+ "\346\0\206\206\0\324\324\0\353\353\0\353\353\0\215\215\0\316\316\0\353\353"
+ "\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0"
+ "\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316"
+ "\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213"
+ "\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0"
+ "\213\213\0\316\316\0\353\353\0\353\353\0\215\215\0\324\324\0\337\337\0\337"
+ "\337\0\331\331\0\312\312\0\346\346\0\346\346\0\330\330\0\224\224\0\271\271"
+ "\0\271\271\0\217\217\0nn\0\305\305\0\305\305\0<<\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0\305\305\0ww"
+ "\0\225\225\0\304\304\0\314\314\0\222\222\0\277\277\0\343\343\0\342\342\0"
+ "\226\226\0\333\333\0\352\352\0\351\351\0\227\227\0\350\350\0\362\362\0\333"
+ "\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361"
+ "\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0"
+ "\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351"
+ "\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230"
+ "\0\351\351\0\361\361\0\333\333\0\230\230\0\362\362\0\351\351\0\323\323\0"
+ "\370\370\0\336\336\0\352\352\0\306\306\0\354\354\0\344\344\0\305\305\0\227"
+ "\227\0\343\343\0\254\254\0\266\266\0ww\0\305\305\0\240\240\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0aa"
+ "\0\333\333\0\236\236\0\304\304\0ww\0\210\210\0tt\0\211\211\0RR\0VV\0PP\0"
+ "VV\0""33\0XX\0UU\0YY\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0"
+ "XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0"
+ "XX\0""66\0UU\0UU\0XX\0""66\0UU\0YY\0UU\0UU\0MM\0QQ\0UU\0UU\0ww\0\211\211"
+ "\0ww\0}}\0\217\217\0\254\254\0\276\276\0\333\333\0aa\0\240\240\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0aa\0\305"
+ "\305\0\305\305\0\236\236\0XX\0\222\222\0\366\366\0\341\341\0tt\0\231\231"
+ "\0\375\375\0\364\364\0\203\203\0\231\231\0\331\331\0\326\326\0\203\203\0"
+ "\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203"
+ "\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324"
+ "\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0"
+ "\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331"
+ "\331\0\324\324\0\203\203\0\231\231\0\331\331\0\326\326\0\231\231\0\231\231"
+ "\0\331\331\0\324\324\0\373\373\0\375\375\0\300\300\0\263\263\0\361\361\0"
+ "\366\366\0\222\222\0pp\0\276\276\0\305\305\0\305\305\0aa\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0<<\0\305\305\0"
+ "\305\305\0``\0\217\217\0\324\324\0\324\324\0rr\0\300\300\0\347\347\0\347"
+ "\347\0\206\206\0\324\324\0\353\353\0\353\353\0\215\215\0\316\316\0\353\353"
+ "\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0"
+ "\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316"
+ "\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213"
+ "\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0"
+ "\213\213\0\316\316\0\353\353\0\353\353\0\215\215\0\324\324\0\337\337\0\337"
+ "\337\0\332\332\0\312\312\0\347\347\0\347\347\0\330\330\0\224\224\0\274\274"
+ "\0\274\274\0\222\222\0nn\0\305\305\0\305\305\0<<\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0\305\305\0ww"
+ "\0\225\225\0\304\304\0\314\314\0\225\225\0\300\300\0\344\344\0\342\342\0"
+ "\226\226\0\333\333\0\352\352\0\351\351\0\227\227\0\350\350\0\362\362\0\333"
+ "\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361"
+ "\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0"
+ "\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351"
+ "\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230"
+ "\0\351\351\0\361\361\0\333\333\0\230\230\0\362\362\0\351\351\0\323\323\0"
+ "\370\370\0\337\337\0\352\352\0\306\306\0\355\355\0\345\345\0\306\306\0\231"
+ "\231\0\343\343\0\254\254\0\266\266\0ww\0\305\305\0\240\240\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0aa"
+ "\0\333\333\0\236\236\0\304\304\0ww\0\210\210\0tt\0\211\211\0RR\0VV\0PP\0"
+ "VV\0""33\0XX\0UU\0YY\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0"
+ "XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0"
+ "XX\0""66\0UU\0UU\0XX\0""66\0UU\0YY\0UU\0UU\0MM\0QQ\0UU\0UU\0ww\0\211\211"
+ "\0ww\0}}\0\217\217\0\254\254\0\276\276\0\333\333\0aa\0\240\240\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0aa\0\305"
+ "\305\0\305\305\0\236\236\0XX\0\222\222\0\366\366\0\341\341\0tt\0\231\231"
+ "\0\375\375\0\364\364\0\203\203\0\231\231\0\331\331\0\326\326\0\203\203\0"
+ "\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203"
+ "\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324"
+ "\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0"
+ "\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331"
+ "\331\0\324\324\0\203\203\0\231\231\0\331\331\0\326\326\0\231\231\0\231\231"
+ "\0\331\331\0\324\324\0\373\373\0\375\375\0\300\300\0\263\263\0\361\361\0"
+ "\366\366\0\222\222\0pp\0\276\276\0\305\305\0\305\305\0aa\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0<<\0\305\305\0"
+ "\305\305\0``\0\217\217\0\324\324\0\324\324\0rr\0\300\300\0\347\347\0\347"
+ "\347\0\206\206\0\324\324\0\353\353\0\353\353\0\215\215\0\316\316\0\353\353"
+ "\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0"
+ "\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316"
+ "\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213"
+ "\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0"
+ "\213\213\0\316\316\0\353\353\0\353\353\0\215\215\0\324\324\0\337\337\0\337"
+ "\337\0\332\332\0\312\312\0\347\347\0\347\347\0\330\330\0\224\224\0\274\274"
+ "\0\274\274\0\222\222\0nn\0\305\305\0\305\305\0<<\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0\305\305\0ww"
+ "\0\225\225\0\304\304\0\314\314\0\225\225\0\300\300\0\344\344\0\342\342\0"
+ "\226\226\0\333\333\0\352\352\0\351\351\0\227\227\0\350\350\0\362\362\0\333"
+ "\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361"
+ "\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0"
+ "\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351"
+ "\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230"
+ "\0\351\351\0\361\361\0\333\333\0\230\230\0\362\362\0\351\351\0\323\323\0"
+ "\370\370\0\337\337\0\352\352\0\306\306\0\355\355\0\345\345\0\306\306\0\231"
+ "\231\0\343\343\0\254\254\0\266\266\0ww\0\305\305\0\240\240\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0aa"
+ "\0\333\333\0\236\236\0\304\304\0ww\0\210\210\0tt\0\211\211\0RR\0VV\0PP\0"
+ "VV\0""33\0XX\0UU\0YY\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0"
+ "XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0"
+ "XX\0""66\0UU\0UU\0XX\0""66\0UU\0YY\0UU\0UU\0MM\0QQ\0UU\0UU\0ww\0\211\211"
+ "\0ww\0}}\0\217\217\0\254\254\0\276\276\0\333\333\0aa\0\240\240\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0aa\0\305"
+ "\305\0\305\305\0\236\236\0XX\0\222\222\0\366\366\0\341\341\0tt\0\231\231"
+ "\0\375\375\0\364\364\0\203\203\0\231\231\0\331\331\0\326\326\0\203\203\0"
+ "\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203"
+ "\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324"
+ "\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0"
+ "\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331"
+ "\331\0\324\324\0\203\203\0\231\231\0\331\331\0\326\326\0\231\231\0\231\231"
+ "\0\331\331\0\324\324\0\373\373\0\375\375\0\300\300\0\263\263\0\361\361\0"
+ "\366\366\0\222\222\0pp\0\276\276\0\305\305\0\305\305\0aa\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0<<\0\305\305\0"
+ "\305\305\0``\0\217\217\0\324\324\0\324\324\0rr\0\300\300\0\347\347\0\347"
+ "\347\0\206\206\0\324\324\0\353\353\0\353\353\0\215\215\0\316\316\0\353\353"
+ "\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0"
+ "\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316"
+ "\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213"
+ "\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0"
+ "\213\213\0\316\316\0\353\353\0\353\353\0\215\215\0\324\324\0\337\337\0\337"
+ "\337\0\332\332\0\312\312\0\347\347\0\347\347\0\330\330\0\224\224\0\274\274"
+ "\0\274\274\0\222\222\0nn\0\305\305\0\305\305\0<<\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0\305\305\0ww"
+ "\0\225\225\0\304\304\0\314\314\0\225\225\0\300\300\0\344\344\0\342\342\0"
+ "\226\226\0\333\333\0\352\352\0\351\351\0\227\227\0\350\350\0\362\362\0\333"
+ "\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361"
+ "\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0"
+ "\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351"
+ "\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230"
+ "\0\351\351\0\361\361\0\333\333\0\230\230\0\362\362\0\351\351\0\323\323\0"
+ "\370\370\0\337\337\0\352\352\0\306\306\0\355\355\0\345\345\0\306\306\0\231"
+ "\231\0\343\343\0\254\254\0\266\266\0ww\0\305\305\0\240\240\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0aa"
+ "\0\333\333\0\236\236\0\304\304\0ww\0\210\210\0tt\0\211\211\0RR\0VV\0PP\0"
+ "VV\0""33\0XX\0UU\0YY\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0"
+ "XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0XX\0""66\0UU\0UU\0"
+ "XX\0""66\0UU\0UU\0XX\0""66\0UU\0YY\0UU\0UU\0MM\0QQ\0UU\0UU\0ww\0\211\211"
+ "\0ww\0}}\0\217\217\0\254\254\0\276\276\0\333\333\0aa\0\240\240\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0aa\0\305"
+ "\305\0\305\305\0\236\236\0XX\0\222\222\0\366\366\0\341\341\0tt\0\231\231"
+ "\0\375\375\0\364\364\0\203\203\0\231\231\0\331\331\0\326\326\0\203\203\0"
+ "\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203"
+ "\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0\324\324"
+ "\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331\331\0"
+ "\324\324\0\203\203\0\231\231\0\331\331\0\324\324\0\203\203\0\231\231\0\331"
+ "\331\0\324\324\0\203\203\0\231\231\0\331\331\0\326\326\0\231\231\0\231\231"
+ "\0\331\331\0\324\324\0\373\373\0\375\375\0\300\300\0\263\263\0\361\361\0"
+ "\366\366\0\222\222\0pp\0\276\276\0\305\305\0\305\305\0aa\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0<<\0\305\305\0"
+ "\305\305\0``\0\217\217\0\324\324\0\324\324\0rr\0\300\300\0\347\347\0\347"
+ "\347\0\206\206\0\324\324\0\353\353\0\353\353\0\215\215\0\316\316\0\353\353"
+ "\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0"
+ "\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213\0\316"
+ "\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0\213\213"
+ "\0\316\316\0\353\353\0\353\353\0\213\213\0\316\316\0\353\353\0\353\353\0"
+ "\213\213\0\316\316\0\353\353\0\353\353\0\215\215\0\324\324\0\337\337\0\337"
+ "\337\0\332\332\0\312\312\0\347\347\0\347\347\0\330\330\0\224\224\0\274\274"
+ "\0\274\274\0\222\222\0nn\0\305\305\0\305\305\0<<\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0\305\305\0ww"
+ "\0\225\225\0\304\304\0\314\314\0\225\225\0\300\300\0\344\344\0\342\342\0"
+ "\226\226\0\333\333\0\352\352\0\351\351\0\227\227\0\350\350\0\362\362\0\333"
+ "\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361"
+ "\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351\351\0"
+ "\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230\0\351"
+ "\351\0\361\361\0\333\333\0\230\230\0\351\351\0\361\361\0\333\333\0\230\230"
+ "\0\351\351\0\361\361\0\333\333\0\230\230\0\362\362\0\351\351\0\323\323\0"
+ "\370\370\0\337\337\0\352\352\0\306\306\0\355\355\0\345\345\0\306\306\0\231"
+ "\231\0\343\343\0\254\254\0\266\266\0ww\0\305\305\0\240\240\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0aa"
+ "\0\333\333\0\236\236\0\304\304\0ww\0\340\340\0\300\300\0\343\343\0\210\210"
+ "\0\354\354\0\333\333\0\352\352\0\215\215\0\361\361\0\350\350\0\362\362\0"
+ "\223\223\0\351\351\0\351\351\0\361\361\0\223\223\0\351\351\0\351\351\0\361"
+ "\361\0\223\223\0\351\351\0\351\351\0\361\361\0\223\223\0\351\351\0\351\351"
+ "\0\361\361\0\223\223\0\351\351\0\351\351\0\361\361\0\223\223\0\351\351\0"
+ "\351\351\0\361\361\0\223\223\0\351\351\0\351\351\0\361\361\0\223\223\0\351"
+ "\351\0\351\351\0\361\361\0\223\223\0\351\351\0\362\362\0\351\351\0\351\351"
+ "\0\323\323\0\336\336\0\351\351\0\351\351\0\304\304\0\343\343\0\305\305\0"
+ "\317\317\0\217\217\0\254\254\0\276\276\0\333\333\0aa\0\240\240\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0aa\0\305"
+ "\305\0\305\305\0\236\236\0\222\222\0\361\361\0\361\361\0\316\316\0\230\230"
+ "\0\373\373\0\373\373\0\344\344\0\231\231\0\375\375\0\375\375\0\357\357\0"
+ "\231\231\0\375\375\0\375\375\0\347\347\0\231\231\0\375\375\0\375\375\0\347"
+ "\347\0\231\231\0\375\375\0\375\375\0\347\347\0\231\231\0\375\375\0\375\375"
+ "\0\347\347\0\231\231\0\375\375\0\375\375\0\347\347\0\231\231\0\375\375\0"
+ "\375\375\0\347\347\0\231\231\0\375\375\0\375\375\0\347\347\0\231\231\0\375"
+ "\375\0\375\375\0\347\347\0\231\231\0\375\375\0\375\375\0\360\360\0\373\373"
+ "\0\375\375\0\375\375\0\347\347\0\367\367\0\373\373\0\373\373\0\326\326\0"
+ "\351\351\0\361\361\0\361\361\0\271\271\0\276\276\0\305\305\0\305\305\0aa"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0<<\0\305\305\0\305\305\0\236\236\0HH\0\271\271\0\271\271\0\224\224\0VV"
+ "\0\277\277\0\277\277\0\251\251\0DD\0\252\252\0\252\252\0\235\235\0FF\0\253"
+ "\253\0\253\253\0\224\224\0EE\0\253\253\0\253\253\0\224\224\0EE\0\253\253"
+ "\0\253\253\0\224\224\0EE\0\253\253\0\253\253\0\224\224\0EE\0\253\253\0\253"
+ "\253\0\224\224\0EE\0\253\253\0\253\253\0\224\224\0EE\0\253\253\0\253\253"
+ "\0\224\224\0EE\0\253\253\0\253\253\0\224\224\0EE\0\253\253\0\253\253\0\235"
+ "\235\0rr\0uu\0uu\0^^\0\272\272\0\277\277\0\277\277\0\230\230\0\205\205\0"
+ "\222\222\0\222\222\0MM\0\266\266\0\305\305\0\305\305\0<<\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0\305"
+ "\305\0\305\305\0RR\0\236\236\0\254\254\0\361\361\0VV\0\267\267\0\263\263"
+ "\0\356\356\0ee\0\247\247\0\244\244\0\356\356\0^^\0\251\251\0\247\247\0\365"
+ "\365\0bb\0\242\242\0\247\247\0\365\365\0bb\0\242\242\0\247\247\0\365\365"
+ "\0bb\0\242\242\0\247\247\0\365\365\0bb\0\242\242\0\247\247\0\365\365\0bb"
+ "\0\242\242\0\247\247\0\365\365\0bb\0\242\242\0\247\247\0\365\365\0bb\0\242"
+ "\242\0\247\247\0\365\365\0bb\0\242\242\0\247\247\0\365\365\0\252\252\0ee"
+ "\0jj\0\345\345\0tt\0\246\246\0\251\251\0\321\321\0\272\272\0ff\0\222\222"
+ "\0\322\322\0ww\0\210\210\0\305\305\0\305\305\0\240\240\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0\240\240"
+ "\0\305\305\0``\0\236\236\0\236\236\0\254\254\0VV\0\264\264\0\254\254\0\261"
+ "\261\0dd\0\246\246\0\240\240\0\243\243\0^^\0\251\251\0\246\246\0\246\246"
+ "\0bb\0\242\242\0\246\246\0\246\246\0bb\0\242\242\0\246\246\0\246\246\0bb"
+ "\0\242\242\0\246\246\0\246\246\0bb\0\242\242\0\246\246\0\246\246\0bb\0\242"
+ "\242\0\246\246\0\246\246\0bb\0\242\242\0\246\246\0\246\246\0bb\0\242\242"
+ "\0\246\246\0\246\246\0bb\0\242\242\0\246\246\0\246\246\0\251\251\0dd\0hh"
+ "\0hh\0pp\0\243\243\0\240\240\0\236\236\0\264\264\0cc\0\177\177\0ww\0ww\0"
+ "\225\225\0\305\305\0\240\240\0\240\240\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\240\240\0\240\240\0\240\240\0``"
+ "\0\351\351\0\333\333\0\333\333\0||\0\366\366\0\361\361\0\361\361\0\211\211"
+ "\0\373\373\0\371\371\0\371\371\0\221\221\0\375\375\0\374\374\0\374\374\0"
+ "\224\224\0\365\365\0\374\374\0\374\374\0\224\224\0\365\365\0\374\374\0\374"
+ "\374\0\224\224\0\365\365\0\374\374\0\374\374\0\224\224\0\365\365\0\374\374"
+ "\0\374\374\0\224\224\0\365\365\0\374\374\0\374\374\0\224\224\0\365\365\0"
+ "\374\374\0\374\374\0\224\224\0\365\365\0\374\374\0\374\374\0\224\224\0\365"
+ "\365\0\374\374\0\374\374\0\375\375\0\356\356\0\371\371\0\371\371\0\372\372"
+ "\0\340\340\0\361\361\0\361\361\0\364\364\0\307\307\0\333\333\0\333\333\0"
+ "\351\351\0\225\225\0\240\240\0\240\240\0\240\240\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\240\240\0\240\240"
+ "\0aa\0\304\304\0\351\351\0\351\351\0\205\205\0\340\340\0\366\366\0\366\366"
+ "\0\222\222\0\355\355\0\373\373\0\373\373\0\227\227\0\364\364\0\375\375\0"
+ "\375\375\0\230\230\0\360\360\0\375\375\0\375\375\0\230\230\0\360\360\0\375"
+ "\375\0\375\375\0\230\230\0\360\360\0\375\375\0\375\375\0\230\230\0\360\360"
+ "\0\375\375\0\375\375\0\230\230\0\360\360\0\375\375\0\375\375\0\230\230\0"
+ "\360\360\0\375\375\0\375\375\0\230\230\0\360\360\0\375\375\0\375\375\0\230"
+ "\230\0\360\360\0\375\375\0\375\375\0\373\373\0\356\356\0\373\373\0\373\373"
+ "\0\367\367\0\340\340\0\364\364\0\364\364\0\354\354\0\304\304\0\351\351\0"
+ "\351\351\0\322\322\0\210\210\0\240\240\0\240\240\0dd\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0\240\240\0\240"
+ "\240\0<<\0\240\240\0\305\305\0\351\351\0ww\0\320\320\0\301\301\0\324\324"
+ "\0\211\211\0\345\345\0\316\316\0\324\324\0\217\217\0\356\356\0\323\323\0"
+ "\326\326\0\223\223\0\354\354\0\323\323\0\326\326\0\223\223\0\354\354\0\323"
+ "\323\0\326\326\0\223\223\0\354\354\0\323\323\0\326\326\0\223\223\0\354\354"
+ "\0\323\323\0\326\326\0\223\223\0\354\354\0\323\323\0\326\326\0\223\223\0"
+ "\354\354\0\323\323\0\326\326\0\223\223\0\354\354\0\323\323\0\326\326\0\223"
+ "\223\0\354\354\0\323\323\0\326\326\0\362\362\0\344\344\0\261\261\0\272\272"
+ "\0\364\364\0\340\340\0\225\225\0\205\205\0\340\340\0\276\276\0\351\351\0"
+ "\266\266\0\240\240\0dd\0\240\240\0\240\240\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0\240\240\0aa\0\240"
+ "\240\0\240\240\0\305\305\0ww\0\305\305\0\240\240\0\266\266\0\205\205\0\333"
+ "\333\0\266\266\0\304\304\0\215\215\0\352\352\0\305\305\0\314\314\0\222\222"
+ "\0\352\352\0\305\305\0\314\314\0\222\222\0\352\352\0\305\305\0\314\314\0"
+ "\222\222\0\352\352\0\305\305\0\314\314\0\222\222\0\352\352\0\305\305\0\314"
+ "\314\0\222\222\0\352\352\0\305\305\0\314\314\0\222\222\0\352\352\0\305\305"
+ "\0\314\314\0\222\222\0\352\352\0\305\305\0\314\314\0\222\222\0\352\352\0"
+ "\305\305\0\314\314\0\361\361\0\335\335\0\242\242\0\236\236\0\333\333\0\312"
+ "\312\0ii\0aa\0\305\305\0\255\255\0\266\266\0\240\240\0\240\240\0\210\210"
+ "\0\240\240\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0aa\0\305\305\0\240\240\0\240\240\0ww\0\333"
+ "\333\0\305\305\0\305\305\0\205\205\0\351\351\0\333\333\0\333\333\0\217\217"
+ "\0\363\363\0\351\351\0\351\351\0\223\223\0\357\357\0\351\351\0\351\351\0"
+ "\223\223\0\357\357\0\351\351\0\351\351\0\223\223\0\357\357\0\351\351\0\351"
+ "\351\0\223\223\0\357\357\0\351\351\0\351\351\0\223\223\0\357\357\0\351\351"
+ "\0\351\351\0\223\223\0\357\357\0\351\351\0\351\351\0\223\223\0\357\357\0"
+ "\351\351\0\351\351\0\223\223\0\357\357\0\351\351\0\351\351\0\363\363\0\345"
+ "\345\0\333\333\0\333\333\0\340\340\0\312\312\0\305\305\0\305\305\0\322\322"
+ "\0\255\255\0\240\240\0\240\240\0\305\305\0\210\210\0dd\0dd\0dd\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd"
+ "\0dd\0dd\0aa\0\305\305\0\305\305\0\240\240\0ww\0\333\333\0\333\333\0\305"
+ "\305\0\205\205\0\355\355\0\355\355\0\336\336\0\215\215\0\364\364\0\364\364"
+ "\0\335\335\0\215\215\0\364\364\0\364\364\0\335\335\0\215\215\0\364\364\0"
+ "\364\364\0\335\335\0\215\215\0\364\364\0\364\364\0\335\335\0\215\215\0\364"
+ "\364\0\364\364\0\335\335\0\215\215\0\364\364\0\364\364\0\335\335\0\215\215"
+ "\0\364\364\0\364\364\0\335\335\0\215\215\0\364\364\0\364\364\0\335\335\0"
+ "\215\215\0\364\364\0\364\364\0\335\335\0\351\351\0\355\355\0\355\355\0\312"
+ "\312\0\305\305\0\322\322\0\322\322\0\255\255\0\240\240\0\305\305\0\305\305"
+ "\0\210\210\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0dd\0\305\305\0aa"
+ "\0""11\0\225\225\0\351\351\0\205\205\0HH\0\254\254\0\333\333\0ww\0BB\0\264"
+ "\264\0\340\340\0nn\0BB\0\264\264\0\340\340\0nn\0BB\0\264\264\0\340\340\0"
+ "nn\0BB\0\264\264\0\340\340\0nn\0BB\0\264\264\0\340\340\0nn\0BB\0\264\264"
+ "\0\340\340\0nn\0BB\0\264\264\0\340\340\0nn\0BB\0\264\264\0\340\340\0nn\0"
+ "BB\0\264\264\0\340\340\0nn\0nn\0\205\205\0\314\314\0\266\266\0\304\304\0"
+ "\351\351\0\236\236\0yy\0\210\210\0\305\305\0<<\0\0\0\0\0\0\0dd\0dd\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0"
+ "\0dd\0dd\0\25\25\0\14\14\0dd\0dd\0\25\25\0\14\14\0dd\0dd\0\25\25\0\14\14"
+ "\0dd\0dd\0\25\25\0\14\14\0dd\0dd\0\25\25\0\14\14\0dd\0dd\0\25\25\0\14\14"
+ "\0dd\0dd\0\25\25\0\14\14\0dd\0dd\0\25\25\0\14\14\0dd\0dd\0\25\25\0\14\14"
+ "\0dd\0dd\0\25\25\0\25\25\0\0\0\0\0\0\0$$\0$$\0\0\0\0\0\0\0<<\0<<\0\0\0\0"
+ "\0\0\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0dd\0dd\0"
+ "\0\0\0\0\0\0dd\0dd\0\0\0\0\0\0\0yy\0yy\0\0\0\0\0\0\0yy\0yy\0\0\0\0\0\0\0"
+ "yy\0yy\0\0\0\0\0\0\0yy\0yy\0\0\0\0\0\0\0yy\0yy\0\0\0\0\0\0\0yy\0yy\0\0\0"
+ "\0\0\0\0yy\0yy\0\0\0\0\0\0\0yy\0yy\0\0\0\0\0\0\0yy\0yy\0\0\0\0\0\0\0yy\0"
+ "yy\0\0\0\0\0\0\0$$\0$$\0\0\0\0\0\0\0<<\0<<\0\0\0\0\0\0\0dd\0dd\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0dd\0dd\0dd\0\0\0\0dd\0dd\0dd\0\0\0\0dd"
+ "\0\210\210\0\210\210\0\25\25\0dd\0\210\210\0\210\210\0\25\25\0dd\0\210\210"
+ "\0\210\210\0\25\25\0dd\0\210\210\0\210\210\0\25\25\0dd\0\210\210\0\210\210"
+ "\0\25\25\0dd\0\210\210\0\210\210\0\25\25\0dd\0\210\210\0\210\210\0\25\25"
+ "\0dd\0\210\210\0\210\210\0\25\25\0dd\0\210\210\0\210\210\0\25\25\0dd\0\210"
+ "\210\0\210\210\0\25\25\0dd\0\210\210\0\210\210\0$$\0\0\0\0<<\0<<\0<<\0\0"
+ "\0\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0dd\0dd\0<<\0<<\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0aa\0"
+ "aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240"
+ "\240\0aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240"
+ "\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0"
+ "aa\0aa\0\240\240\0\240\240\0aa\0aa\0\240\240\0\240\240\0\240\240\0\240\240"
+ "\0dd\0dd\0dd\0dd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
+};
+
+/**
+ * \brief Returns the BlitBlend test image as SDL_Surface.
+ */
+SDL_Surface *SDLTest_ImageBlitBlend()
+{
+ SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
+ (void*)SDLTest_imageBlitBlend.pixel_data,
+ SDLTest_imageBlitBlend.width,
+ SDLTest_imageBlitBlend.height,
+ SDLTest_imageBlitBlend.bytes_per_pixel * 8,
+ SDLTest_imageBlitBlend.width * SDLTest_imageBlitBlend.bytes_per_pixel,
+#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ 0xff000000, /* Red bit mask. */
+ 0x00ff0000, /* Green bit mask. */
+ 0x0000ff00, /* Blue bit mask. */
+ 0x000000ff /* Alpha bit mask. */
+#else
+ 0x000000ff, /* Red bit mask. */
+ 0x0000ff00, /* Green bit mask. */
+ 0x00ff0000, /* Blue bit mask. */
+ 0xff000000 /* Alpha bit mask. */
+#endif
+ );
+ return surface;
+}
+
+static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendMod = {
+ 80, 60, 3,
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
+};
+
+/**
+ * \brief Returns the BlitBlendMod test image as SDL_Surface.
+ */
+SDL_Surface *SDLTest_ImageBlitBlendMod()
+{
+ SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
+ (void*)SDLTest_imageBlitBlendMod.pixel_data,
+ SDLTest_imageBlitBlendMod.width,
+ SDLTest_imageBlitBlendMod.height,
+ SDLTest_imageBlitBlendMod.bytes_per_pixel * 8,
+ SDLTest_imageBlitBlendMod.width * SDLTest_imageBlitBlendMod.bytes_per_pixel,
+#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ 0xff000000, /* Red bit mask. */
+ 0x00ff0000, /* Green bit mask. */
+ 0x0000ff00, /* Blue bit mask. */
+ 0x000000ff /* Alpha bit mask. */
+#else
+ 0x000000ff, /* Red bit mask. */
+ 0x0000ff00, /* Green bit mask. */
+ 0x00ff0000, /* Blue bit mask. */
+ 0xff000000 /* Alpha bit mask. */
+#endif
+ );
+ return surface;
+}
+
+static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendNone = {
+ 80, 60, 3,
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\0\0\0\0\0\0\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\0"
+ "\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\377\0\0\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\377\0\0\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\0\0\0\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\0\0\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0"
+ "\377\377\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377"
+ "\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377\377\0\377\377"
+ "\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\0\0\0\377\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0\0\0\0\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\0\0\0\377\377\0\377"
+ "\377\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\377\377\0\377\377\0"
+ "\377\377\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\0\0\0\0\0\0\377\377\0\377\377\0\377\377\0\377"
+ "\377\0\377\377\0\377\377\0\377\377\0\377\377\0\0\0\0\0\0\0\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377",
+};
+
+/**
+ * \brief Returns the BlitBlendNone test image as SDL_Surface.
+ */
+SDL_Surface *SDLTest_ImageBlitBlendNone()
+{
+ SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
+ (void*)SDLTest_imageBlitBlendNone.pixel_data,
+ SDLTest_imageBlitBlendNone.width,
+ SDLTest_imageBlitBlendNone.height,
+ SDLTest_imageBlitBlendNone.bytes_per_pixel * 8,
+ SDLTest_imageBlitBlendNone.width * SDLTest_imageBlitBlendNone.bytes_per_pixel,
+#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ 0xff000000, /* Red bit mask. */
+ 0x00ff0000, /* Green bit mask. */
+ 0x0000ff00, /* Blue bit mask. */
+ 0x000000ff /* Alpha bit mask. */
+#else
+ 0x000000ff, /* Red bit mask. */
+ 0x0000ff00, /* Green bit mask. */
+ 0x00ff0000, /* Blue bit mask. */
+ 0xff000000 /* Alpha bit mask. */
+#endif
+ );
+ return surface;
+}
+
+static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAll = {
+ 80, 60, 3,
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\4\0\0\4\0\0\0\0\0\0\0"
+ "\0\11\0\0\11\0\0\0\0\0\0\0\0\16\0\0\16\0\0\0\0\0\0\0\0\11\0\0\11\0\0\0\0"
+ "\0\0\0\0\14\0\0\14\0\0\0\0\0\0\0\0\17\0\0\17\0\0\0\0\0\0\0\0\21\0\0\21\0"
+ "\0\0\0\0\0\0\0K\0\0K\0\0\0\0\0\0\0\0T\0\0T\0\0\0\0\0\0\0\0^\0\0^\0\0\0\0"
+ "\0\0\0\0g\0\0g\0\0\0\0\0\0\0\0\317\0\0\317\0\0\317\0\0\317\0\0\317\0\0\317"
+ "\0\0\317\0\0\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\4\0\0\4\0\0\4\0\0\0\0\0\11\0\0\11\0\0\11"
+ "\0\0\0\0\0\16\0\0\16\0\0\16\0\0\0\0\0\22\0\0\22\0\0\11\0\0\0\0\0\14\0\0\14"
+ "\0\0\14\0\0\0\0\0\17\0\0\17\0\0\17\0\0\0\0\0\21\0\0\21\0\0\21\0\0\0\0\0\24"
+ "\0\0\24\0\0K\0\0\0\0\0T\0\0T\0\0T\0\0\0\0\0^\0\0^\0\0^\0\0\0\0\0g\0\0g\0"
+ "\0g\0\0\0\0\0q\0\0q\0\0\317\0\0\317\0\0\317\0\0\317\0\0\317\0\0\317\0\0\317"
+ "\0\0\317\0\0\317\0\0\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\4\0\0\4\0\0\4\0\0\0\0\0\11\0\0\11\0\0\11\0\0\0\0\0"
+ "\16\0\0\16\0\0\16\0\0\0\0\0\22\0\0\22\0\0\22\0\0\0\0\0\14\0\0\14\0\0\14\0"
+ "\0\0\0\0\17\0\0\17\0\0\17\0\0\0\0\0\21\0\0\21\0\0\21\0\0\0\0\0\24\0\0\24"
+ "\0\0\24\0\0\0\0\0T\0\0T\0\0T\0\0\0\0\0^\0\0^\0\0^\0\0\0\0\0g\0\0g\0\0g\0"
+ "\0\0\0\0q\0\0q\0\0q\0\0\317\0\0\317\0\0\317\0\0\317\0\0\317\0\0\317\0\0\317"
+ "\0\0\317\0\0\317\0\0\317\0\0\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\4\0\0\4\0\0\4\0\0\0\0\0\10\0\0\10\0\0\10\0\0\0\0\0\15"
+ "\0\0\15\0\0\15\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\16\0\0\16\0\0\16\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0J\0\0J\0\0J\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\317"
+ "\0\0\317\0\0\317\0\0\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\1\0\0\0\0\0\0\0\0\1\0\0\1\0\0\1\0\0\1"
+ "\0\0\4\0\0\4\0\0\0\0\0\0\0\0\7\0\0\7\0\0\0\0\0\0\0\0&\0\0&\0\0\32\0\0\32"
+ "\0\0&\0\0&\0\0&\0\0&\0\0C\0\0C\0\0\0\0\0\0\0\0^\0\0^\0\0\0\0\0\0\0\17\251"
+ "\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0\0\0\0\0"
+ "\0\0\0\317\0\0\317\0\0\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\6\2\0\6\2\0\0\1\0\0\0\0\0\1\0\0\1\0\0\1\0\0\1\0\0\1\0\0\1\0\0"
+ "\17\0\0\0\0\0\4\0\0\11\0\0\11\0\0\0\0\6+\0\6+\0\0&\0\0\32\0\0&\0\0&\0\0&"
+ "\0\0&\0\0""5\0\0""5\0\2\210\0\0\0\0\0C\0\0|\0\0|\0\0\0\0\17\251\0\17\251"
+ "\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251"
+ "\0$\360\0$\360\0\0\0\0\0\317\0\0\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1"
+ "\0\0\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\1\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\6\2\0\6\2\0\6\2\0\0\0\0\0\1\0\0\1\0\0\1\0\0\1\0\0\1\0\0\1"
+ "\0\0\1\0\0\0\0\0\17\0\0\17\0\0\4\0\0\0\0\6+\0\6+\0\6+\0\0\32\0\0&\0\0&\0"
+ "\0&\0\0&\0\0""5\0\0""5\0\0""5\0\0\0\0\2\210\0\2\210\0\0C\0\0\0\0\17\251\0"
+ "\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0\17\251\0"
+ "\17\251\0\17\251\0$\360\0$\360\0$\360\0\0\0\0\0\317\0\0\317\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\1\0\0\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "$\360\0$\360\0$\360\0$\360\0\0\0\0\0\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0"
+ "\0\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\14\1\0\14\1\0\14\1"
+ "\0\14\1\0\15\1\0\15\1\0\0\0\0\0\0\0\14\2\0\14\2\0\14\2\0\14\2\0\16\2\0\16"
+ "\2\0\0\0\0\0\0\0\14!\0\14!\0\14!\0\14!\0\17(\0\17(\0\0\0\0\0\0\0\14+\0\14"
+ "+\0\14+\0\14+\0\20""9\0\20""9\0\0\0\0\0\0\0\36\215\0\36\215\0\36\215\0\36"
+ "\215\0(\264\0(\264\0\0\0\0\0\0\0\36\251\0\36\251\0\36\251\0\36\251\0\36\251"
+ "\0\36\251\0\36\251\0\36\251\0\0\0\0\0\0\0$\360\0$\360\0$\360\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\1\0\0\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\36\3"
+ "\0\36\3\0\14\1\0\14\1\0\15\1\0\15\1\0\15\1\0\0\0\0\14\2\0\14\2\0\14\2\0\14"
+ "\2\0\16\2\0\16\2\0\16\2\0\0\0\0\14\3\0\14\3\0\14!\0\14!\0\17(\0\17(\0\17"
+ "(\0\0\0\0\14+\0\14+\0\14+\0\14+\0\20""9\0\20""9\0\20""9\0\0\0\0\14""7\0\14"
+ """7\0\36\215\0\36\215\0(\264\0(\264\0(\264\0\0\0\0\36\251\0\36\251\0\36\251"
+ "\0\36\251\0\36\251\0\36\251\0\36\251\0\36\251\0\36\251\0\36\251\0H\360\0"
+ "H\360\0\0\0\0$\360\0$\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\1\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\36\3\0\36\3\0\36\3\0\14\1\0\15\1\0\15\1\0\15\1"
+ "\0\0\0\0\14\2\0\14\2\0\14\2\0\14\2\0\16\2\0\16\2\0\16\2\0\0\0\0\14\3\0\14"
+ "\3\0\14\3\0\14!\0\17(\0\17(\0\17(\0\0\0\0\14+\0\14+\0\14+\0\14+\0\20""9\0"
+ "\20""9\0\20""9\0\0\0\0\14""7\0\14""7\0\14""7\0\36\215\0(\264\0(\264\0(\264"
+ "\0\0\0\0\36\251\0\36\251\0\36\251\0\36\251\0\36\251\0\36\251\0\36\251\0\36"
+ "\251\0\36\251\0\36\251\0\36\251\0H\360\0H\360\0H\360\0\0\0\0$\360\0$\360"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\13\1\0\13\1\0\13\1\0\13\1\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\11!\0"
+ "\11!\0\11!\0\11!\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\23n\0\23n\0\23n\0\23n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0H\360\0H\360\0H\360\0H\360\0\0\0\0$\360\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\1\0\1\1\0\0\0\0\0\0\0\0\0\0\0\0\0\25\0\0\25\0\0\25\0\0\27\0"
+ "\0\13\0\0\13\0\0\1\0\0\11\0\0\4\0\0\4\0\0\0\0\0\0\0\0\25\3\0\25\3\0\0\0\0"
+ "\0\0\0\25\3\0\25\3\0\25\3\0\25\3\0\3\1\0\3\1\0\2\1\0\7\5\0\7\3\0\7\3\0\0"
+ "\0\0\0\0\0\25""4\0\25""4\0\0\0\0\0\0\0\25""4\0\25""4\0\25""4\0\25""4\0\20"
+ "\35\0\20\35\0\11\22\0\23F\0\34""6\0\34""6\0\0\0\0\0\0\0L\317\0L\317\0L\317"
+ "\0L\317\0L\317\0L\317\0L\317\0L\317\0\0\0\0\0\0\0""2\317\0""2\317\0""2\317"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\1\0\0\0\0\0\0\0\0\0\0\25\0\0\25"
+ "\0\0\25\0\0\4\0\0\5\0\0\2\0\0\1\0\0\4\0\0\14\0\0\14\0\0\0\0\0\37\7\0\37\7"
+ "\0\25\3\0\0\0\0\25\3\0\25\3\0\25\3\0\25\3\0\37\6\0\37\6\0\15\4\0\11\3\0\7"
+ "\3\0\14\10\0\14\10\0\0\0\0\25\16\0\25\16\0\25""4\0\0\0\0\25""4\0\25""4\0"
+ "\25""4\0\25""4\0&Q\0&Q\0&Q\0\31""5\0\34""6\0&j\0&j\0\0\0\0""5q\0""5q\0L\317"
+ "\0L\317\0L\317\0L\317\0L\317\0L\317\0L\317\0L\317\0L\317\0L\317\0\0\0\0""2"
+ "\317\0""2\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\1\1\0\0\0\0\0\0\0\25\0"
+ "\0\25\0\0\25\0\0\31\1\0\5\0\0\5\0\0\2\0\0\4\0\0\14\0\0\14\0\0\0\0\0\37\7"
+ "\0\37\7\0\37\7\0\0\0\0\25\3\0\25\3\0\25\3\0\25\3\0\37\6\0\37\6\0\37\6\0\11"
+ "\3\0\16\6\0\16\6\0\7\3\0\0\0\0\25\16\0\25\16\0\25\16\0\0\0\0\25""4\0\25""4"
+ "\0\25""4\0\25""4\0&Q\0&Q\0&Q\0\31""5\0+X\0+X\0\34""6\0\0\0\0""5q\0""5q\0"
+ """5q\0L\317\0L\317\0L\317\0L\317\0L\317\0L\317\0L\317\0L\317\0L\317\0L\317"
+ "\0L\317\0\0\0\0""2\317\0""2\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\0\0\0\0"
+ "\0\0\0\0\25\0\0\25\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0L\317\0L\317\0L\317\0L\317"
+ "\0\0\0\0""2\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0e\4\0e\4\0\0\0\0\0\0\0e\11\0e\11\0\0\0\0\0\0\0e\16\0e\16\0\0\0\0\0\0"
+ "\0G\11\0G\11\0\0\0\0\0\0\0G\14\0G\14\0\0\0\0\0\0\0G\17\0G\17\0\0\0\0\0\0"
+ "\0G\21\0G\21\0\0\0\0\0\0\0GK\0GK\0\0\0\0\0\0\0GT\0GT\0\0\0\0\0\0\0G^\0G^"
+ "\0\0\0\0\0\0\0Gg\0Gg\0\0\0\0\0\0\0e\317\0e\317\0e\317\0e\317\0e\317\0e\317"
+ "\0e\317\0e\317\0\0\0\0\0\0\0L\317\0L\317\0L\317\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\1\0\0\0\0\0\0\0\0e\4\0e\4\0e\4\0\0\0\0e\11\0e\11\0e\11\0\0\0"
+ "\0e\16\0e\16\0e\16\0\0\0\0e\22\0e\22\0G\11\0\0\0\0G\14\0G\14\0G\14\0\0\0"
+ "\0G\17\0G\17\0G\17\0\0\0\0G\21\0G\21\0G\21\0\0\0\0G\24\0G\24\0GK\0\0\0\0"
+ "GT\0GT\0GT\0\0\0\0G^\0G^\0G^\0\0\0\0Gg\0Gg\0Gg\0\0\0\0Gq\0Gq\0e\317\0e\317"
+ "\0e\317\0e\317\0e\317\0e\317\0e\317\0e\317\0e\317\0e\317\0\0\0\0L\317\0L"
+ "\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\0\0e\4\0e\4\0e\4\0\0\0"
+ "\0e\11\0e\11\0e\11\0\0\0\0e\16\0e\16\0e\16\0\0\0\0e\22\0e\22\0e\22\0\0\0"
+ "\0G\14\0G\14\0G\14\0\0\0\0G\17\0G\17\0G\17\0\0\0\0G\21\0G\21\0G\21\0\0\0"
+ "\0G\24\0G\24\0G\24\0\0\0\0GT\0GT\0GT\0\0\0\0G^\0G^\0G^\0\0\0\0Gg\0Gg\0Gg"
+ "\0\0\0\0Gq\0Gq\0Gq\0e\317\0e\317\0e\317\0e\317\0e\317\0e\317\0e\317\0e\317"
+ "\0e\317\0e\317\0e\317\0\0\0\0L\317\0L\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0e\4\0e\4\0e\4\0\0\0\0b\10\0b\10\0b\10\0\0\0\0b\15\0b\15\0b\15\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0<\16\0<\16\0<\16\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0""2J\0""2J\0""2J\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0e\317\0e\317\0e\317\0e"
+ "\317\0\0\0\0L\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\216\1\0c\0\0c\0\0\0\0\0"
+ "`\0\0c\0\0c\0\0\2\0\0c\1\0i\0\0i\0\0\0\0\0\0\0\0e\0\0e\0\0\0\0\0\0\0\0{\1"
+ "\0{\1\0f\0\0f\0\0z\1\0z\1\0z\1\0z\1\0)\4\0)\4\0\0\0\0\0\0\0Q\7\0Q\7\0\0\0"
+ "\0\0\0\0{&\0{&\0W\32\0W\32\0z&\0z&\0z&\0z&\0IC\0IC\0\0\0\0\0\0\0X^\0X^\0"
+ "\0\0\0\0\0\0\261\251\0\261\251\0\261\251\0\261\251\0\261\251\0\261\251\0"
+ "\261\251\0\261\251\0\0\0\0\0\0\0e\317\0e\317\0e\317\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\216\1\0c\0\0`\0\0\2\0\0c\0\0c\0\0c\0\0\12\0\0k\1\0i\0\0"
+ "\0\0\0\11\0\0i\0\0i\0\0\0\0\0\256\2\0\256\2\0{\1\0f\0\0z\1\0z\1\0z\1\0z\1"
+ "\0\221\1\0\221\1\0\221\17\0\0\0\0)\4\0c\11\0c\11\0\0\0\0\256+\0\256+\0{&"
+ "\0W\32\0z&\0z&\0z&\0z&\0\2415\0\2415\0\243\210\0\0\0\0IC\0{|\0{|\0\0\0\0"
+ "\261\251\0\261\251\0\261\251\0\261\251\0\261\251\0\261\251\0\261\251\0\261"
+ "\251\0\261\251\0\261\251\0\264\360\0\264\360\0\0\0\0e\317\0e\317\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\216\1\0\216\1\0`\0\0\2\0\0c\0\0c\0\0c\0\0\12\0\0"
+ "k\1\0k\1\0\0\0\0\11\0\0i\0\0i\0\0\0\0\0\256\2\0\256\2\0\256\2\0f\0\0z\1\0"
+ "z\1\0z\1\0z\1\0\221\1\0\221\1\0\221\1\0\0\0\0\221\17\0\221\17\0)\4\0\0\0"
+ "\0\256+\0\256+\0\256+\0W\32\0z&\0z&\0z&\0z&\0\2415\0\2415\0\2415\0\0\0\0"
+ "\243\210\0\243\210\0IC\0\0\0\0\261\251\0\261\251\0\261\251\0\261\251\0\261"
+ "\251\0\261\251\0\261\251\0\261\251\0\261\251\0\261\251\0\261\251\0\264\360"
+ "\0\264\360\0\264\360\0\0\0\0e\317\0e\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\216\1"
+ "\0\211\1\0c\0\0\2\0\0c\0\0c\0\0k\0\0\12\0\0k\1\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\264\360\0\264\360"
+ "\0\264\360\0\264\360\0\0\0\0e\317\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\211\1\0\216\1"
+ "\0c\0\0\2\0\0c\0\0k\0\0q\0\0\20\0\0\0\0\0\0\0\0\322\1\0\322\1\0\322\1\0\322"
+ "\1\0\346\1\0\346\1\0\0\0\0\0\0\0\322\2\0\322\2\0\322\2\0\322\2\0\363\2\0"
+ "\363\2\0\0\0\0\0\0\0\322!\0\322!\0\322!\0\322!\0\371(\0\371(\0\0\0\0\0\0"
+ "\0\322+\0\322+\0\322+\0\322+\0\3719\0\3719\0\0\0\0\0\0\0\325\215\0\325\215"
+ "\0\325\215\0\325\215\0\374\264\0\374\264\0\0\0\0\0\0\0\325\251\0\325\251"
+ "\0\325\251\0\325\251\0\325\251\0\325\251\0\325\251\0\325\251\0\0\0\0\0\0"
+ "\0\264\360\0\264\360\0\264\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\211\1\0\216"
+ "\1\0c\0\0\2\0\0f\0\0m\0\0m\0\0\0\0\0\325\3\0\325\3\0\322\1\0\322\1\0\346"
+ "\1\0\346\1\0\346\1\0\0\0\0\322\2\0\322\2\0\322\2\0\322\2\0\363\2\0\363\2"
+ "\0\363\2\0\0\0\0\322\3\0\322\3\0\322!\0\322!\0\371(\0\371(\0\371(\0\0\0\0"
+ "\322+\0\322+\0\322+\0\322+\0\3719\0\3719\0\3719\0\0\0\0\3227\0\3227\0\325"
+ "\215\0\325\215\0\374\264\0\374\264\0\374\264\0\0\0\0\325\251\0\325\251\0"
+ "\325\251\0\325\251\0\325\251\0\325\251\0\325\251\0\325\251\0\325\251\0\325"
+ "\251\0\330\360\0\330\360\0\0\0\0\264\360\0\264\360\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\216\1\0\216\1\0c\0\0\10\0\0m\0\0m\0\0\0\0\0\325\3\0\325\3\0\325"
+ "\3\0\322\1\0\346\1\0\346\1\0\346\1\0\0\0\0\322\2\0\322\2\0\322\2\0\322\2"
+ "\0\363\2\0\363\2\0\363\2\0\0\0\0\322\3\0\322\3\0\322\3\0\322!\0\371(\0\371"
+ "(\0\371(\0\0\0\0\322+\0\322+\0\322+\0\322+\0\3719\0\3719\0\3719\0\0\0\0\322"
+ "7\0\3227\0\3227\0\325\215\0\374\264\0\374\264\0\374\264\0\0\0\0\325\251\0"
+ "\325\251\0\325\251\0\325\251\0\325\251\0\325\251\0\325\251\0\325\251\0\325"
+ "\251\0\325\251\0\325\251\0\330\360\0\330\360\0\330\360\0\0\0\0\264\360\0"
+ "\264\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\216\1\0\216\1\0i\0\0\10\0\0m\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\275\1\0\275\1\0\275\1\0"
+ "\275\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\244!\0\244!\0\244!\0\244!\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\213n\0\213n\0\213n\0\213n\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\330\360\0\330\360\0\330\360\0\330"
+ "\360\0\0\0\0\264\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\216\1\0\224\1\0i\0\0\10\0"
+ "\0\0\0\0\0\0\0\325\3\0\325\3\0\325\3\0\351\3\0\365\1\0\365\1\0\14\0\0\313"
+ "\2\0#\2\0#\2\0\0\0\0\0\0\0\371\37\0\371\37\0\0\0\0\0\0\0\371\37\0\371\37"
+ "\0\371\37\0\371\37\0.\17\0.\17\0#\14\0\304-\0Y!\0Y!\0\0\0\0\0\0\0\371p\0"
+ "\371p\0\0\0\0\0\0\0\371p\0\371p\0\371p\0\371p\0O>\0O>\0""3(\0\247\227\0\211"
+ "s\0\211s\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0"
+ "\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\330\360\0\330\360\0\330\360\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\4\0\0\224\1\0i\0\0\0\0\0\0\0\0\325\3\0\325"
+ "\3\0\325\3\0\17\2\0\"\2\0!\0\0\35\0\0#\2\0\342\4\0\342\4\0\0\0\0\371\37\0"
+ "\371\37\0\371\37\0\0\0\0\371\37\0\371\37\0\371\37\0\371\37\0\3775\0\3775"
+ "\0\374%\0\304\34\0Y!\0\373C\0\373C\0\0\0\0\371p\0\371p\0\371p\0\0\0\0\371"
+ "p\0\371p\0\371p\0\371p\0\377\256\0\377\256\0\377\256\0\247q\0\211s\0\375"
+ "\342\0\375\342\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0"
+ "\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\0"
+ "\0\0\330\360\0\330\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\12\0\0\224\1\0\0\0"
+ "\0\0\0\0\325\3\0\325\3\0\325\3\0\344\5\0\"\2\0\"\2\0\200\0\0#\2\0\342\4\0"
+ "\342\4\0\0\0\0\371\37\0\371\37\0\371\37\0\0\0\0\371\37\0\371\37\0\371\37"
+ "\0\371\37\0\3775\0\3775\0\3775\0\304\34\0\3732\0\3732\0Y!\0\0\0\0\371p\0"
+ "\371p\0\371p\0\0\0\0\371p\0\371p\0\371p\0\371p\0\377\256\0\377\256\0\377"
+ "\256\0\247q\0\375\274\0\375\274\0\211s\0\0\0\0\374\360\0\374\360\0\374\360"
+ "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0"
+ "\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\330\360\0\330\360\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\12\0\0\0\0\0i\0\0\0\0\0\325\3\0\325\3\0\344\5\0\344\5"
+ "\0\"\2\0\36\1\0""4\2\0#\2\0\342\4\0\0\0\0\371\37\0\371\37\0\371\37\0\0\0"
+ "\0\371\37\0\371\37\0\371\37\0\371\37\0\3775\0\3775\0\3775\0\307)\0\3732\0"
+ "\3732\0\3732\0\0\0\0\371p\0\371p\0\371p\0\0\0\0\371p\0\371p\0\371p\0\371"
+ "p\0\377\256\0\377\256\0\377\256\0\247q\0\375\274\0\375\274\0\375\274\0\0"
+ "\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360"
+ "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0"
+ "\374\360\0\374\360\0\0\0\0\330\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\12\0\0"
+ "\10\0\0\0\0\0\325\3\0\344\5\0\344\5\0\344\5\0\340\4\0\367\11\0\364\3\0#\2"
+ "\0\0\0\0\371\37\0\371\37\0\371\37\0\0\0\0\371\37\0\371\37\0\371\37\0\371"
+ "\37\0\3775\0\3775\0\3775\0\307)\0\376G\0\3732\0\3732\0\0\0\0\371p\0\371p"
+ "\0\371p\0\0\0\0\371p\0\371p\0\371p\0\371p\0\377\256\0\377\256\0\377\256\0"
+ "\247q\0\375\274\0\375\274\0\375\274\0\0\0\0\374\360\0\374\360\0\374\360\0"
+ "\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374"
+ "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\12\0\0\10\0\0\0\0\0\0\0\0\17\2\0\17"
+ "\2\0\17\2\0\323\2\0\352\7\0\347\2\0\26\1\0\0\0\0\371\37\0\371\37\0\371\37"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0/\26\0/\26\0/\26\0\0\0\0""7\36\0""6\25\0"
+ """6\25\0\0\0\0\371p\0\371p\0\371p\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0O>\0O>\0"
+ "O>\0\0\0\0VK\0VK\0VK\0\0\0\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0\0\12\0"
+ "\0\10\0\0\0\0\0\17\2\0\17\2\0\344\5\0\15\1\0\352\7\0\352\7\0\347\2\0\0\0"
+ "\0\371\37\0\371\37\0\371\37\0\0\0\0\0\0\0\0\0\0\362\4\0\0\0\0/\26\0/\26\0"
+ "\3775\0$\21\0""7\36\0""7\36\0\3672\0\0\0\0\371p\0\371p\0\371p\0\0\0\0\0\0"
+ "\0\0\0\0\370A\0\0\0\0O>\0O>\0\377\256\0""3(\0VK\0VK\0\372\264\0\0\0\0\374"
+ "\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\341\271\0\0\0\0\374\360"
+ "\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\343\350\0\0\0\0\374\360\0\374"
+ "\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0\0\5\0\0\10\0\0\0\0"
+ "\0\17\2\0\17\2\0\17\2\0\15\1\0\352\7\0\352\7\0\347\2\0\0\0\0\371\37\0\371"
+ "\37\0\371\37\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0/\26\0/\26\0/\26\0$\21\0""7\36"
+ "\0""7\36\0""6\25\0\0\0\0\371p\0\371p\0\371p\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0O>\0O>\0O>\0""3(\0VK\0VK\0VK\0\0\0\0\374\360\0\374\360\0\374\360\0\374"
+ "\360\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\5\0\0\5\0\0\5\0\0\0\0\0\344\5\0\344\5\0\344\5\0\316\4\0\367"
+ "\11\0\367\11\0\364\3\0\0\0\0\371\37\0\371\37\0\371\37\0\0\0\0\371\37\0\371"
+ "\37\0\371\37\0\371\37\0\3775\0\3775\0\3775\0\307)\0\376G\0\376G\0\3732\0"
+ "\0\0\0\371p\0\371p\0\371p\0\0\0\0\371p\0\371p\0\371p\0\371p\0\377\256\0\377"
+ "\256\0\377\256\0\247q\0\375\274\0\375\274\0\375\274\0\0\0\0\374\360\0\374"
+ "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360"
+ "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0"
+ "\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5"
+ "\0\0\5\0\0\5\0\0\17\2\0\344\5\0\344\5\0\316\4\0\345\11\0\367\11\0\364\3\0"
+ "\0\0\0\371\37\0\371\37\0\371\37\0\0\0\0\371\37\0\371\37\0\371\37\0\371\37"
+ "\0\3775\0\3775\0\3775\0\307)\0\376G\0\376G\0\3732\0\0\0\0\371p\0\371p\0\371"
+ "p\0\0\0\0\371p\0\371p\0\371p\0\371p\0\377\256\0\377\256\0\377\256\0\247q"
+ "\0\375\274\0\375\274\0\375\274\0\0\0\0\374\360\0\374\360\0\374\360\0\374"
+ "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360"
+ "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0"
+ "\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0\0\5\0\0\0\0\0\17\2"
+ "\0\344\5\0\344\5\0\15\1\0$\6\0$\6\0#\2\0\0\0\0\371\37\0\371\37\0\371\37\0"
+ "\0\0\0\371\37\0\371\37\0\371\37\0\371\37\0\3775\0/\26\0/\26\0\307)\0\376"
+ "G\0[/\0Y!\0\0\0\0\371p\0\371p\0\371p\0\0\0\0\371p\0\371p\0\371p\0\371p\0"
+ "\377\256\0O>\0O>\0\247q\0\375\274\0\211s\0\211s\0\0\0\0\374\360\0\374\360"
+ "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0"
+ "\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0"
+ "\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0\0"
+ "\5\0\0\17\2\0\17\2\0\344\5\0\316\4\0$\6\0$\6\0#\2\0\0\0\0\371\37\0\371\37"
+ "\0\371\37\0\0\0\0\371\37\0\371\37\0\371\37\0\371\37\0\3775\0/\26\0/\26\0"
+ "\307)\0\376G\0[/\0Y!\0\0\0\0\371p\0\371p\0\371p\0\0\0\0\371p\0\371p\0\371"
+ "p\0\371p\0\377\256\0O>\0O>\0\247q\0\375\274\0\211s\0\211s\0\0\0\0\374\360"
+ "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0"
+ "\374\360\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0"
+ "\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\5\0\0\24\2\0\17\2\0\17\2\0\316\4\0\345\11\0$\6\0#\2\0\0\0\0\371"
+ "\37\0\371\37\0\371\37\0\0\0\0\371\37\0\371\37\0\371\37\0\371\37\0\3775\0"
+ "\3775\0\3775\0\307)\0\376G\0\376G\0\3732\0\0\0\0\371p\0\371p\0\371p\0\0\0"
+ "\0\371p\0\371p\0\371p\0\371p\0\377\256\0\377\256\0\377\256\0\247q\0\375\274"
+ "\0\375\274\0\375\274\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374"
+ "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360"
+ "\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0"
+ "\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0\0\24\2\0\24"
+ "\2\0\17\2\0\316\4\0\345\11\0\342\3\0#\2\0\0\0\0\371\37\0\371\37\0\371\37"
+ "\0\0\0\0\371\37\0\371\37\0\371\37\0\371\37\0\3775\0\3775\0\3775\0\307)\0"
+ "\376G\0\3732\0\3732\0\0\0\0\371p\0\371p\0\371p\0\0\0\0\371p\0\371p\0\371"
+ "p\0\371p\0\377\256\0\377\256\0\377\256\0\247q\0\375\274\0\375\274\0\375\274"
+ "\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374"
+ "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360"
+ "\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\17\2\0\24\2\0\5\0\0\0\0\0\27\5\0\342\3\0\313"
+ "\1\0\0\0\0\371\37\0\371\37\0\0\0\0\0\0\0\0\0\0\371\37\0\0\0\0\0\0\0/\26\0"
+ "\3775\0\371\37\0\302\30\0\3716\0Y!\0#\14\0\0\0\0\371p\0\371p\0\0\0\0\0\0"
+ "\0\0\0\0\371p\0\0\0\0\0\0\0O>\0\377\256\0\371p\0\243I\0\371\224\0\211s\0"
+ """3(\0\0\0\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360\0\374"
+ "\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0"
+ "\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\17\2\0\17\2\0\0\0\0\0\0\0\26\1\0\26\1\0\0\0\0\0\0\0\371"
+ "\37\0\371\37\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0/\26\0/\26\0\0\0\0\0\0"
+ "\0""6\25\0""6\25\0\0\0\0\0\0\0\371p\0\371p\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0O>\0O>\0\0\0\0\0\0\0VK\0VK\0\0\0\0\0\0\0\374\360\0\374\360\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374"
+ "\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\17\2\0\17\2\0\0\0\0\0\0\0\26\1\0\26\1\0\0\0\0\0\0"
+ "\0\371\37\0\371\37\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0/\26\0/\26\0\0\0"
+ "\0\0\0\0""6\25\0""6\25\0\0\0\0\0\0\0\371p\0\371p\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0O>\0O>\0\0\0\0\0\0\0VK\0VK\0\0\0\0\0\0\0\374\360\0\374\360"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0"
+ "\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\17\2\0\17\2\0\16\0\0\0\0\0\26\1\0\26\1\0\26"
+ "\1\0\0\0\0\371\37\0\371\37\0\371\37\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0/\26\0"
+ "/\26\0.\17\0\0\0\0""6\25\0""6\25\0""6\25\0\0\0\0\371p\0\371p\0\371p\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0O>\0O>\0O>\0\0\0\0VK\0VK\0VK\0\0\0\0\374\360\0"
+ "\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\374\360\0\374\360"
+ "\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\16\0\0\16\0\0\14\0\0\14"
+ "\0\0#\2\0#\2\0\0\0\0\0\0\0\371\37\0\371\37\0\0\0\0\0\0\0\371\37\0\371\37"
+ "\0\371\37\0\371\37\0.\17\0.\17\0#\14\0#\14\0Y!\0Y!\0\0\0\0\0\0\0\371p\0\371"
+ "p\0\0\0\0\0\0\0\371p\0\371p\0\371p\0\371p\0O>\0O>\0""3(\0""3(\0\211s\0\211"
+ "s\0\0\0\0\0\0\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360\0\374\360"
+ "\0\374\360\0\374\360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
+};
+
+/**
+ * \brief Returns the BlitBlendAll test image as SDL_Surface.
+ */
+SDL_Surface *SDLTest_ImageBlitBlendAll()
+{
+ SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
+ (void*)SDLTest_imageBlitBlendAll.pixel_data,
+ SDLTest_imageBlitBlendAll.width,
+ SDLTest_imageBlitBlendAll.height,
+ SDLTest_imageBlitBlendAll.bytes_per_pixel * 8,
+ SDLTest_imageBlitBlendAll.width * SDLTest_imageBlitBlendAll.bytes_per_pixel,
+#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ 0xff000000, /* Red bit mask. */
+ 0x00ff0000, /* Green bit mask. */
+ 0x0000ff00, /* Blue bit mask. */
+ 0x000000ff /* Alpha bit mask. */
+#else
+ 0x000000ff, /* Red bit mask. */
+ 0x0000ff00, /* Green bit mask. */
+ 0x00ff0000, /* Blue bit mask. */
+ 0xff000000 /* Alpha bit mask. */
+#endif
+ );
+ return surface;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/test/SDL_test_imageFace.c b/src/3rdparty/SDL2/src/test/SDL_test_imageFace.c
new file mode 100644
index 0000000..9b43637
--- /dev/null
+++ b/src/3rdparty/SDL2/src/test/SDL_test_imageFace.c
@@ -0,0 +1,247 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#include "SDL_test.h"
+
+/* GIMP RGBA C-Source image dump (face.c) */
+
+static const SDLTest_SurfaceImage_t SDLTest_imageFace = {
+ 32, 32, 4,
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\0"
+ "\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0"
+ "\0\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\0\0\0\377\0\0\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\0\0\0\377\0\0\0\377\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\0\0\0\377\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\0\0\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\0\0\0\377\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\0\0\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\0\0\0\377\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\0\0\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\0\0\0\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\0\0\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\0\0\0\377\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\0\0\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\0\0\0\377\0\0\0\377"
+ "\377\377\377\0\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\0\0\0\377\0\0\0\377\377\377\377\0\0\0\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\0\0\0\377\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\0\0\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\0\0\0\377\0\0\0"
+ "\377\0\0\0\377\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\0\0\0\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\0\0\0\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\0\0\0\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\0\0\0\377\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\0\0\0\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\0\0\0"
+ "\377\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\0\0\0"
+ "\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\0"
+ "\0\0\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\0\0\0\377\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\0\0\0\377\377\377\0\377\377\377\0\377\0\0\0\377\0\0\0\377"
+ "\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\0\0\0\377\0\0\0\377\0\0"
+ "\0\377\377\377\0\377\377\377\0\377\0\0\0\377\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\0\0\0\377\377\377\0\377\377\377\0\377\0\0\0\377\0\0\0\377\0\0\0\377"
+ "\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0"
+ "\0\0\377\0\0\0\377\377\377\0\377\377\377\0\377\0\0\0\377\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\0\0\0\377\377\377\0\377\377"
+ "\377\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0"
+ "\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\377\377\0\377\377\377\0\377\0\0\0"
+ "\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\0\0\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\0\0\0\377\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\0\0\0\377\0\0\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\0\0\0\377\0\0\0\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\0\0\0\377\0\0\0\377\0\0\0\377\0\0"
+ "\0\377\0\0\0\377\0\0\0\377\0\0\0\377\0\0\0\377\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0",
+};
+
+/**
+ * \brief Returns the Face test image as SDL_Surface.
+ */
+SDL_Surface *SDLTest_ImageFace()
+{
+ SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
+ (void*)SDLTest_imageFace.pixel_data,
+ SDLTest_imageFace.width,
+ SDLTest_imageFace.height,
+ SDLTest_imageFace.bytes_per_pixel * 8,
+ SDLTest_imageFace.width * SDLTest_imageFace.bytes_per_pixel,
+#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ 0xff000000, /* Red bit mask. */
+ 0x00ff0000, /* Green bit mask. */
+ 0x0000ff00, /* Blue bit mask. */
+ 0x000000ff /* Alpha bit mask. */
+#else
+ 0x000000ff, /* Red bit mask. */
+ 0x0000ff00, /* Green bit mask. */
+ 0x00ff0000, /* Blue bit mask. */
+ 0xff000000 /* Alpha bit mask. */
+#endif
+ );
+ return surface;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/test/SDL_test_imagePrimitives.c b/src/3rdparty/SDL2/src/test/SDL_test_imagePrimitives.c
new file mode 100644
index 0000000..17597c6
--- /dev/null
+++ b/src/3rdparty/SDL2/src/test/SDL_test_imagePrimitives.c
@@ -0,0 +1,514 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#include "SDL_test.h"
+
+/* GIMP RGB C-Source image dump (primitives.c) */
+
+static const SDLTest_SurfaceImage_t SDLTest_imagePrimitives = {
+ 80, 60, 3,
+ "\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15"
+ "I\310\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310"
+ "\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310\0"
+ "\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310\0\0\0\15I\310\0\0"
+ "\0\5ii\0\0\0\5ii\0\0\0\3\1\1\0\0\0\5\2\1\0\0\0\7\3\2\0\0\0\11\4\3\0\0\0\13"
+ "\5\3\0\0\0\15\6\4\0\0\0\17\7\5\0\0\0\21\10\5\0\0\0\23\11\6\0\0\0\25\12\7"
+ "\0\0\0\27\13\7\0\0\0\31\14\10\0\0\0\33\15\11\0\0\0\35\16\11\0\0\0\37\17\12"
+ "\0\0\0!\20\13\0\0\0#\21\13\0\0\0%\22\14\0\0\0'\23\15\15I\310)\24\15\15I\310"
+ "+\25\16\15I\310-\26\17\15I\310/\27\17\15I\3101\30\20\15I\3103\31\21\15I\310"
+ "5\32\21\15I\3107\33\22\15I\3109\34\23\15I\310;\35\23\15I\310=\36\24\15I\310"
+ "?\37\25\15I\310A\40\25\15I\310C!\26\15I\310E\"\27\15I\310G#\27\15I\310I$"
+ "\30\15I\310K%\31\15I\310M&\31\5iiO'\32\0\0\0\0\0\0\5ii\0\0\0\10\4\2\0\0\0"
+ "\14\6\4\0\0\0\20\10\5\0\0\0\24\12\6\0\0\0\30\14\10\0\0\0\34\16\11\0\0\0\40"
+ "\20\12\0\0\0$\22\14\0\0\0(\24\15\0\0\0,\26\16\0\0\0""0\30\20\0\0\0""4\32"
+ "\21\0\0\0""8\34\22\0\0\0<\36\24\0\0\0@\40\25\0\0\0D\"\26\0\0\0H$\30\0\0\0"
+ "L&\31\0\0\0P(\32\15I\310T*\34\15I\310X,\35\15I\310\\.\36\15I\310`0\40\15"
+ "I\310d2!\15I\310h4\"\15I\310l6$\15I\310p8%\15I\310t:&\15I\310x<(\15I\310"
+ "|>)\15I\310\200@*\15I\310\204B,\15I\310\210D-\15I\310\214F.\15I\310\220H"
+ "0\15I\310\224J1\15I\310\230L2\5ii\234N4\15I\310\0\0\0\0\0\0\0\0\0\5ii\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\5ii"
+ "\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\5ii\15I\310\15I\310\15I\310\15I\310"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\5ii\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\5ii\15I\310\15I\310\15I\310"
+ "\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5ii\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\5ii\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\5ii\15I\310\15I\310"
+ "\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\5ii\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310"
+ "\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d"
+ "\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\5ii\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\5ii\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d"
+ "\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310"
+ "\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\5ii\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310"
+ "\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310"
+ "\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310"
+ "\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d"
+ "\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310"
+ "\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d"
+ "\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310"
+ "\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310"
+ "\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310"
+ "\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5"
+ "ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d"
+ "\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310"
+ "\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d"
+ "\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310"
+ "\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310"
+ "\15I\310\15I\310\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0"
+ "\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0"
+ "\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0"
+ "\0\377\0\0\377\0\0\377\0\0\377\0\5ii\0\377\0\0\377\0\0\377\0\0\377\0\0\377"
+ "\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0""77\5\0\377\0\0\377\0\0\377\0"
+ "\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\5ii\0\377\0\0\377\0\0\377"
+ "\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377"
+ "\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377"
+ "\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\377\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5"
+ "ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d"
+ "\310\0d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310"
+ "\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310"
+ "\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310"
+ "\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310"
+ "\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310"
+ "\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5i"
+ "i\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310"
+ "\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310"
+ "\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\15I\310\15I\310\15I\310\15I\310"
+ "\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\310\0d\310\0d\5ii\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310"
+ "\0d\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310"
+ "\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\310\0d\310\0d\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d77\5\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\5ii\310\0d\310\0d\15I\310\15I\310\15I\310"
+ "\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\310\0d\5ii\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d77\5\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\5ii\310\0d\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15"
+ "I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\5ii\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d7"
+ "7\5\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0"
+ "d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310"
+ "\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\310\0d\5ii\15I\310\15I\310"
+ "\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0""77\5\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\5ii\15I\310\15I\310\15I\310\15I\310"
+ "\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0""77\5\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\5ii\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310"
+ "\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5ii\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0""77\5\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\5ii\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0""77\5\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\5ii\15I\310"
+ "\15I\310\15I\310\15I\310\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5"
+ "ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0""77\5\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\5ii\15I\310\15I\310\15I\310"
+ "\15I\310\15I\310\0\0\0\0\0\0\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0""77\5\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\5ii\15I\310\15I\310\15I\310\15I\310\0\0\0\0"
+ "\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0""77\5\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\5ii\15I\310\15I\310\15I\310\0\0\0\0\0\0\5ii\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0""77\5\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\5ii"
+ "\15I\310\15I\310\0\0\0\5ii\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0""77\5\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\5ii\15I\310\5ii\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\0\0\0\0""77\5\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I\310\15I"
+ "\310\15I\310\15I\310\15I\310\15I\310\5ii",
+};
+
+/**
+ * \brief Returns the Primitives test image as SDL_Surface.
+ */
+SDL_Surface *SDLTest_ImagePrimitives()
+{
+ SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
+ (void*)SDLTest_imagePrimitives.pixel_data,
+ SDLTest_imagePrimitives.width,
+ SDLTest_imagePrimitives.height,
+ SDLTest_imagePrimitives.bytes_per_pixel * 8,
+ SDLTest_imagePrimitives.width * SDLTest_imagePrimitives.bytes_per_pixel,
+#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ 0xff000000, /* Red bit mask. */
+ 0x00ff0000, /* Green bit mask. */
+ 0x0000ff00, /* Blue bit mask. */
+ 0x000000ff /* Alpha bit mask. */
+#else
+ 0x000000ff, /* Red bit mask. */
+ 0x0000ff00, /* Green bit mask. */
+ 0x00ff0000, /* Blue bit mask. */
+ 0xff000000 /* Alpha bit mask. */
+#endif
+ );
+ return surface;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/test/SDL_test_imagePrimitivesBlend.c b/src/3rdparty/SDL2/src/test/SDL_test_imagePrimitivesBlend.c
new file mode 100644
index 0000000..aa50662
--- /dev/null
+++ b/src/3rdparty/SDL2/src/test/SDL_test_imagePrimitivesBlend.c
@@ -0,0 +1,696 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#include "SDL_test.h"
+
+/* GIMP RGB C-Source image dump (alpha.c) */
+
+static const SDLTest_SurfaceImage_t SDLTest_imagePrimitivesBlend = {
+ 80, 60, 3,
+ "\260e\15\222\356/\37\313\15\36\330\17K\3745D\3471\0\20\0D\3502D\3502<\321"
+ ",\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\0-\0\377\377"
+ "\377\377\377\377\311\324\311\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\0H\0\377\377\377\377\377\377\256\307\256\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\0c\0\377\377\377\377\377\377"
+ "\223\300\223\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\0~\0\377\377\377\377\377\377x\277x\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\0\231\0\377\377\377\377\377\377]\303]\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\0\264\0\377\377\377\377\377"
+ "\377B\316B\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\0"
+ "\317\0\377\377\377\377\377\377'\335'\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\0\352\0\377\377\377#\262\6\260d\15\260e\15\224\357"
+ "/&\262\6\34\300\5.\314\22\40\315\12[\3747M\332/\27\331\12\27\331\12K\374"
+ "5K\3745K\3745D\3471D\3471D\3471D\3471D\3471D\3502D\3502D\3502D\3502D\350"
+ "2D\3502D\3502D\3502D\3502D\3502\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377,\372\27\273\3465\327"
+ "Q.\260d\15\213\213\40\241\3601\200\366*=\265\13?\301\25s\375<Y\316-X\320"
+ "-!\315\13]\3749]\3749O\3321O\3321P\3342P\3342P\3342\371\377\364\371\377\364"
+ "\371\377\364\371\377\364\371\377\364\362\375\360\362\375\360\362\375\360"
+ "\362\375\360\362\375\360D\3471D\3471D\3471D\3502D\3502D\3502D\3502D\3502"
+ "D\3502D\3502D\3502D\3502D\3502D\3502D\3502D\3502D\3502D\3502D\3502D\3502"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "K\3745&\262\6\213\213\40\11\2\0\260`\15\241~#m}\11\273\363AQ\247\15S\266"
+ "\31\212\373@e\302,\4\33\2s\375<\\\3161M\260*\\\3202X\320-\366\377\354\364"
+ "\377\352O\3321\3""5\2O\3321O\3321<\261&P\3342P\3342S\3655\377\377\377\377"
+ "\377\377\14Z\14\377\377\377\377\377\377\234\302\231\371\377\364\362\375\360"
+ "\367\377\365\362\375\360\362\375\360\13t\13\362\375\360\362\375\360\177\275"
+ "~\362\375\360\362\375\360\370\377\366\362\375\360\377\377\377\14\220\14\377"
+ "\377\377D\3502\"\267\33D\3502D\3502K\3779D\3502D\3502\3\233\2D\3502D\350"
+ "2\34\303\26D\3502D\3502L\377:D\3502D\3502\3\264\2D\3502D\3502\25\323\22\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\14\341\14\377\377"
+ "\377\377\377\377\40\353\40\377\377\377D\3471\34\300\5e\247\33\356\336?\277"
+ "f)\260P\17\260i\16\356\336?\331\353C\274\363GQ\247\15\243\370Cp\270)\212"
+ "\373@h\3021h\3042c\304+\364\377\336\\\3161\\\3161\\\3202\\\3202\\\3202\377"
+ "\377\377\364\377\352\364\377\352\346\371\342\346\371\342O\3321O\3321P\334"
+ "2P\3342P\3342P\3342P\3342P\3342\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\362\375\360\362\375\360\362\375\360\362\375\360\362\375"
+ "\360\362\375\360\362\375\360\362\375\360\362\375\360\362\375\360\362\375"
+ "\360\362\375\360\362\375\360\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377D\3502D\3502D\3502D\3502D\3502D\3502D\3502D\3502D\3502D\3502D\3502\40"
+ "\315\12=\265\13f\230\14\237y\15\274Y\17\327Q.\260X\14\243\177$\220\214\""
+ "\215\235*\274\363G\177\252+\243\370Cu\2661p\270)\367\377\324h\3021h\3021"
+ "h\3042\364\377\336\364\377\336\335\364\323\\\3161\\\3161\\\3202\\\3202\\"
+ "\3202\377\377\377\377\377\377\364\377\352\364\377\352\346\371\342\346\371"
+ "\342\346\371\342\346\371\342O\3321P\3342P\3342P\3342P\3342P\3342P\3342P\334"
+ "2\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\362\375\360\362\375\360"
+ "\362\375\360\362\375\360\362\375\360\362\375\360\362\375\360\362\375\360"
+ "\362\375\360\362\375\360\362\375\360\362\375\360\362\375\360\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\6\0\4[\3747?\301\25N\241\14\331\353C\243\177$\275Z\21\377\254W\260Q\17\30"
+ "\26\7\370\343N\201\210\16|\213-\274\363G\200\2521\202\263+\243\370Cu\266"
+ "1\12&\4\367\377\324h\3021S\241)h\3042h\3042\377\377\377\364\377\336\335\364"
+ "\323\24M\23\\\3161\\\3202C\245(\\\3202\\\3202\377\377\377\377\377\377\377"
+ "\377\377\30l\30\346\371\342\346\371\342\207\273\205\346\371\342\346\371\342"
+ "\361\377\355\377\377\377P\3342\7t\4P\3342P\3342/\260\"P\3342P\3342^\377@"
+ "\377\377\377\377\377\377\30\242\30\377\377\377\377\377\377d\306d\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\30\275\30\377\377\377"
+ "\377\377\377K\322K\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\30\330\30\362\375\360\362\375\3601\3431\362\375\360\362\375\360\377"
+ "\377\377\362\375\360D\3502M\332/s\375<>\265\14\177\252+\201\210\16\245\204"
+ "*\377\314U\312\\,\224'\11\260i\17\244\210\40\232\2211\331\353J\215\2351\377"
+ "\377\276\200\2521\200\2542\375\377\310u\2661t\2702t\2702\367\377\324\325"
+ "\355\305h\3021h\3042h\3042\377\377\377\377\377\377\364\377\336\335\364\323"
+ "\335\364\323\335\364\323\\\3202\\\3202\\\3202\\\3202\\\3202\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\346\371\342\346\371\342\346"
+ "\371\342\346\371\342\346\371\342\346\371\342\346\371\342\377\377\377\377"
+ "\377\377P\3342P\3342P\3342P\3342P\3342P\3342P\3342P\3342\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\27\331\12Y\316-h\3021\243\370Cg\230\15\230\224\"\245"
+ "\204*\377\314U\310J\21\327Q.\260b\21\245\2041\370\343N\230\2242\331\353J"
+ "\214\2402\377\377\276\200\2521\200\2542\375\377\310\317\344\266u\2661t\270"
+ "2\377\377\377\367\377\324\325\355\305h\3021h\3042h\3042h\3042\377\377\377"
+ "\377\377\377\364\377\336\335\364\323\335\364\323\335\364\323\335\364\323"
+ "\\\3202\\\3202\\\3202\\\3202\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\346\371\342\346\371"
+ "\342\346\371\342\346\371\342\346\371\342\346\371\342\377\377\377\377\377"
+ "\377\377\377\377\377\377\377P\3342P\3342P\3342P\3342P\3342P\3342P\3342P\334"
+ "2\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377K\3745!\315\13d\304,p\270)\177\252+\23\13\6\232\2211\245\204"
+ "1\347\270O\377\277Y\324<\22\265V\24\377\330Q\244\210\40#(\13\230\224\"\331"
+ "\353Ju\211.\377\377\276\200\2521\210\273:\200\2542\375\377\310\20""3\6u\266"
+ "1t\2702\271\307\271\367\377\324\325\355\305\341\377\321h\3021h\3042\16L\7"
+ "h\3042\377\377\377\242\300\242\377\377\377\335\364\323\355\377\343\335\364"
+ "\323\335\364\323\14f\7\\\3202\\\3202>\250*\\\3202\377\377\377\377\377\377"
+ "\377\377\377\377\377\377$\231$\377\377\377\377\377\377s\303s\377\377\377"
+ "\346\371\342\376\377\372\346\371\342\346\371\342\40\257\37\346\371\342\346"
+ "\371\342\\\316\\\377\377\377\377\377\377\377\377\377\377\377\377P\3342\13"
+ "\262\7P\3342P\3342*\327%P\3342P\3342o\377Q\377\377\377\377\377\377$\352$"
+ "\377\377\377\377\377\377K\3745]\3749s\375<\212\373@\243\370C\274\363G\331"
+ "\353J\370\343N\377\330Q\377\314U\377\277Y\377\260\\\224(\11\260|\36\245\204"
+ "1\377\377\250\232\2211\230\224\"\215\2351\214\2402\377\377\276\312\332\250"
+ "\200\2521\200\2542\377\377\377\317\344\266u\2661t\2702t\2702\377\377\377"
+ "\377\377\377\325\355\305\325\355\305\325\355\305h\3042h\3042h\3042\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\335\364\323\335\364\323\335\364"
+ "\323\335\364\323\335\364\323\\\3202\\\3202\\\3202\\\3202\\\3202\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\346\371\342\346\371\342"
+ "\346\371\342\346\371\342\346\371\342\346\371\342\346\371\342\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377P\3342P\3342"
+ "P\3342P\3342\377\377\377K\3745O\3321\\\3161h\3021t\2702~\254'\214\240%\377"
+ "\377\262\370\343N\377\330Q\262x1\277l1\312`1\327R.\260X\23\377\330Q\244\210"
+ "2\377\377\250\230\2242\377\377\262\215\2351\214\2402\377\377\377\312\332"
+ "\250\200\2521\200\2542\377\377\377\375\377\310\317\344\266u\2661t\2702t\270"
+ "2\377\377\377\377\377\377\325\355\305\325\355\305\325\355\305h\3042h\304"
+ "2h\3042h\3042\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\335\364\323\335\364\323\335\364\323\335\364\323\377\377\377\\\3202\\\320"
+ "2\\\3202\\\3202\\\3202\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\346\371\342\346\371\342\346\371\342\346"
+ "\371\342\346\371\342\346\371\342\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377D\3471O\3321\21\7\11c\304+\367\377\324o\2520\200\252"
+ "1\214\2402\235\226'\377\377\250\377\330Q!\20\11\277l1\310d2\266?\33\224("
+ "\11\260|\36\257\217;\377\377\250\232\2211\34$\11\377\377\262\215\2351q\206"
+ "0\377\377\377\312\332\250\217\303@\200\2542\200\25420Z0\317\344\266\317\344"
+ "\266X\2260t\2702t\2702\377\377\377\377\377\377\325\355\305(l%\325\355\305"
+ "\325\355\305K\2410h\3042h\3042\377\377\377\377\377\377\377\377\3770\2200"
+ "\377\377\377\377\377\377t\274p\335\364\323\335\364\323\373\377\361\377\377"
+ "\377\377\377\377\21\213\11\\\3202\\\3202<\274/\\\3202\377\377\377\377\377"
+ "\377\377\377\377\377\377\3770\3060\377\377\377\377\377\377V\330V\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\3770\3410\346\371\342\346"
+ "\371\342>\352>\346\371\342\377\377\377D\3471P\3342\364\377\352s\375<h\302"
+ "1t\2702~\254'\377\377\276\215\2351\230\2242\244\210\40\377\377\234\262x1"
+ "\277l1\310W\32\377\260\\\327T1\260|2\377\330Q\244\2102\377\377\250\232\221"
+ "1\230\2242\377\377\262\215\2351\214\2402\377\377\377\377\377\276\312\332"
+ "\250\200\2542\200\2542\377\377\377\375\377\310\317\344\266\317\344\266t\270"
+ "2t\2702t\2702\377\377\377\377\377\377\377\377\377\325\355\305\325\355\305"
+ "\325\355\305h\3042h\3042h\3042h\3042\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\335\364\323\335\364\323\335\364\323"
+ "\335\364\323\335\364\323\377\377\377\377\377\377\\\3202\\\3202\\\3202\\\320"
+ "2\\\3202\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377D\3471P\3342\364\377\352\\\3161h\3042\367"
+ "\377\324u\2661\200\2542\214\240%\377\377\262\232\2211\244\2102\377\377\234"
+ "\262x1\274p2\377\337\207\377\260\\\327T1\227/\14\377\377\234\245\2041\244"
+ "\2102\307\300\213\230\2242\377\377\377\377\377\262\215\2351\214\2402\377"
+ "\377\377\377\377\276\312\332\250\200\2542\200\2542\377\377\377\377\377\377"
+ "\317\344\266\317\344\266\317\344\266t\2702t\2702\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\325\355\305\325\355\305\325\355\305\377\377\377"
+ "h\3042h\3042h\3042h\3042\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\335\364\323\335\364\323\335\364\323"
+ "\335\364\323\377\377\377\377\377\377\377\377\377\\\3202\\\3202\\\3202\\\320"
+ "2\\\3202\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377<\0<D\3502\371\377\364N\3221\\\3202\364\377"
+ "\336l\3035t\2702\375\377\310\36\22\13\214\2402\377\377\262\214\2012\244\210"
+ "2\377\377\234\274\177;\274p2\377\337\207/\24\13\324X2\227/\14\222l3\307\260"
+ "|\244\2102\377\377\270\232\2211\230\2242<Q<\310\316\231\215\2351o\2065\377"
+ "\377\377\377\377\276\341\377\277\200\2521\200\2542\36H\13\377\377\377\377"
+ "\377\377\213\260}\317\344\266t\2702\221\366Ot\2702\377\377\377<\207<\377"
+ "\377\377\377\377\377}\270v\325\355\305\325\355\305\371\377\351\377\377\377"
+ "h\3042\30|\13h\3042\377\377\377|\306|\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377<\275<\335\364\323\335\364\323_\317]\335\364\323"
+ "\335\364\323\377\377\377\377\377\377\377\377\377\25\260\13\\\3202\\\3202"
+ ">\3369\\\3202\377\377\377\377\377\377\377\377\377\377\377\377D\3502\371\377"
+ "\364O\3321\\\3202\364\377\336h\3042\367\377\324u\2661\200\2542\377\377\276"
+ "\215\2351\230\2242\307\300\213\244\2102\377\377\234\262x1\274p2\377\337\207"
+ "\312`1\324E\30\327T1\260|2\377\377\234\245\2041\244\2102\377\377\250\232"
+ "\2211\230\2242\377\377\377\310\316\231\215\2351\214\2402\377\377\377\377"
+ "\377\377\312\332\250\312\332\250\200\2542\200\2542\377\377\377\377\377\377"
+ "\317\344\266\317\344\266\317\344\266t\2702t\2702t\2702\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\325\355\305\325\355\305\325\355"
+ "\305\377\377\377h\3042h\3042h\3042h\3042\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\335\364\323\335\364\323\335\364\323\335\364\323\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\\\3202\\\3202\\\3202\377\377\377D\3502\371\377"
+ "\364O\3321\377\377\377\\\3161h\3042\367\377\324t\2702\375\377\310\200\252"
+ "1\377\377\377\215\2351\230\2242\377\377\250\244\2102\377\377\234\262x1\274"
+ "p2\316\214_\310d2\377\310|\327T1\227/\14\377\377\377\307\260|\244\2102\377"
+ "\377\377\307\300\213\230\2242\230\2242\377\377\377\310\316\231\214\2402\214"
+ "\2402\377\377\377\377\377\377\312\332\250\312\332\250\200\2542\200\2542\377"
+ "\377\377\377\377\377\377\377\377\317\344\266\317\344\266\317\344\266t\270"
+ "2t\2702t\2702\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\325\355\305\325\355\305\325\355\305\377\377\377\377\377\377h\3042h\3042"
+ "h\3042\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\335\364\323\335\364"
+ "\323\335\364\323\335\364\323\377\377\377\377\377\377\377\377\377\377\377"
+ "\377D\3502\371\377\364R\3344\364\377\352\\\3161H\22Hh\3021\377\377\377o\244"
+ "2\200\2542\312\332\250\226\245<\377\377\262\230\2242H-/\245\2041\377\377"
+ "\377\233i5\274p2\277l1\331sC\377\310|\324X2*\15\3\260|2\377\377\234\206s"
+ "7\244\2102\377\377\250\340\337\244\230\2242\377\377\377Hc2\310\316\231\214"
+ "\2402n\211:\377\377\377\377\377\377\353\377\311\312\332\250\200\2542$T\16"
+ "\377\377\377\377\377\377\236\277\236\377\377\377\317\344\266\367\377\336"
+ "\377\377\377t\2702\40n\16t\2702\377\377\377\212\303\212\377\377\377\377\377"
+ "\377\377\377\377\325\355\305\325\355\305<\2477\377\377\377\377\377\377O\276"
+ "Ah\3042h\3042\237\377i\377\377\377\377\377\377H\317H\377\377\377\377\377"
+ "\377c\335c\377\377\377\377\377\377\377\377\377\377\377\377\335\364\323>\337"
+ ";\335\364\323\377\377\377D\3502\362\375\360P\3342\346\371\342\\\3202\364"
+ "\377\336h\3042\367\377\324t\2702\375\377\310\200\2542\377\377\276\214\240"
+ "2\377\377\262\232\2211\377\377\377\245\2041\377\377\377\262x1\377\377\377"
+ "\277l1\310d2\312`1\324X2\327T1\260|2\377\377\377\307\260|\244\2102\377\377"
+ "\377\307\300\213\232\2211\230\2242\377\377\377\377\377\262\310\316\231\214"
+ "\2402\214\2402\377\377\377\377\377\377\312\332\250\312\332\250\200\2542\200"
+ "\2542\200\2542\377\377\377\377\377\377\377\377\377\317\344\266\317\344\266"
+ "\317\344\266\377\377\377t\2702t\2702t\2702\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\325\355\305\325\355\305\325\355\305\325\355"
+ "\305\377\377\377\377\377\377h\3042h\3042h\3042h\3042\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377D\3502\362\375\360P\3342\346\371\342\\\3202\335"
+ "\364\323h\3042\325\355\305t\2702\317\344\266\377\377\377\200\2521\377\377"
+ "\377\215\2351\377\377\377\232\2211\377\377\377\245\2041\377\377\377\262x"
+ "1\377\377\377\277l1\377\377\377\312`1\377\310|\327T1\227/\14\377\377\377"
+ "\307\260|\244\2102\244\2102\377\377\377\307\300\213\230\2242\230\2242\377"
+ "\377\377\310\316\231\310\316\231\214\2402\214\2402\377\377\377\377\377\377"
+ "\312\332\250\312\332\250\377\377\377\200\2542\200\2542\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\317\344\266\317\344\266\377\377\377\377\377"
+ "\377t\2702t\2702\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\325\355\305\325\355\305\325\355\305\377\377"
+ "\377\377\377\377\377\377\377h\3042h\3042h\3042\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377D\3502\362\375\360"
+ "T\11TO\3321\377\377\377Z\3002\377\377\377h\3042\377\377\334t\2702\375\377"
+ "\310*\30\20\312\332\250\214\2402\262\260\214\230\2242\307\300\213\377\377"
+ "\377\245\2041\377\377\377:\35\20\377\377\377\277l1\316\264w\310d2\377\310"
+ "|\356qL\227/\14\260|2TZ3\307\260|\244\2102\274\302\274\307\300\213\307\300"
+ "\213\273\301U\377\377\377\377\377\377A^2\310\316\231\214\2402o\216B\377\377"
+ "\377\377\377\377\366\377\324\312\332\250\312\332\250*a\20\200\2542\377\377"
+ "\377\230\301\230\377\377\377\377\377\377\377\377\353\317\344\266\317\344"
+ "\266T\253Tt\2702t\2702]\265I\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377T\306T\377\377\377\325\355\305l\324i\325\355\305\377\377"
+ "\377\377\377\377\377\377\377h\3042\"\254\20h\3042h\3042b\353b\377\377\377"
+ "\377\377\377D\3502\362\375\360\377\377\377O\3321\377\377\377\\\3202\364\377"
+ "\336h\3042\325\355\305t\2702\317\344\266\377\377\377\200\2521\377\377\377"
+ "\214\2402\377\377\262\230\2242\307\300\213\244\2102\307\260|\377\377\377"
+ "\262x1\377\377\377\274p2\377\337\207\310d2\377\310|\324X2\333bB\260|2\377"
+ "\377\377\307\260|\244\2102\244\2102\377\377\377\307\300\213\232\2211\230"
+ "\2242\377\377\377\377\377\377\310\316\231\310\316\231\214\2402\214\2402\377"
+ "\377\377\377\377\377\377\377\377\312\332\250\312\332\250\200\2542\200\254"
+ "2\200\2542\377\377\377\377\377\377\377\377\377\377\377\377\317\344\266\317"
+ "\344\266\317\344\266\377\377\377t\2702t\2702t\2702\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\325\355\305"
+ "\325\355\305\325\355\305\325\355\305\377\377\377\377\377\377\377\377\377"
+ "h\3042h\3042\377\377\377\377\377\377D\3471\377\377\377P\3342\364\377\352"
+ "\\\3202\335\364\323\377\377\377h\3021\377\377\377t\2702\375\377\310\200\254"
+ "2\312\332\250\377\377\377\215\2351\377\377\377\230\2242\377\377\250\244\210"
+ "2\307\260|\377\377\377\262x1\377\377\377\274p2\377\337\207\310d2\323xQ\324"
+ "X2\327T1\227/\14\260|2\377\377\234\307\260|\244\2102\377\377\377\377\377"
+ "\377\307\300\213\230\2242\230\2242\377\377\377\377\377\377\310\316\231\310"
+ "\316\231\214\2402\214\2402\377\377\377\377\377\377\377\377\377\312\332\250"
+ "\312\332\250\377\377\377\200\2542\200\2542\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\317\344\266\317\344\266\377\377\377\377\377"
+ "\377t\2702t\2702t\2702\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\325\355\305\325\355\305\325"
+ "\355\305\377\377\377\377\377\377`\0`\377\377\377D\3471\371\366\371P\3342"
+ "\346\371\342\377\377\377\\\3161\377\377\377'\24\22\325\355\305t\2702\276"
+ "\310\251\377\377\377\200\2542\377\377\316\214\2402\310\316\231`6`\230\224"
+ "2\377\377\250\222u<\307\260|\377\377\377\315\214L\377\377\377\274p2M,#\310"
+ "d2\312`1\306\304\306\324X2\333bB\325\242W\377\377\377\307\260|=9\22\244\210"
+ "2\377\377\377\227\234w\307\300\213\230\2242\307\322a\377\377\377\377\377"
+ "\377Km9\310\316\231\214\2402r\226K\377\377\377\377\377\377\377\377\377\312"
+ "\332\250\312\332\250`\242`\200\2542\200\2542\224\306\224\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\317\344\266M\250D\317\344\266\377\377\377"
+ "\203\322\203t\2702t\2702\301\377\177\377\377\377\377\377\377`\330`\377\377"
+ "\377\377\377\377r\344r\377\377\377\377\377\377\377\377\377\325\355\305\377"
+ "\377\377\377\377\377D\3502\371\377\364P\3342\346\371\342\377\377\377\\\320"
+ "2\364\377\336h\3042\325\355\305\377\377\377t\2702\317\344\266\200\2542\312"
+ "\332\250\377\377\377\214\2402\310\316\231\230\2242\307\300\213\377\377\377"
+ "\244\2102\307\260|\377\377\377\200U0\220^\377\7\4/\227U[\246]\377\255Q1\377"
+ "\242y\10\3/\306M@\6\4/{^\377mVvmVv\6\5/h\\\377h\\\377\\U\204\12\12\360\5"
+ "\5/VX\377VX\377\12\12\360LR\221\12\12\360\5\6/\214\2402\377\377\377\377\377"
+ "\377\377\377\377\312\332\250\312\332\250\377\377\377\200\2542\200\2542\200"
+ "\2542\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\317\344"
+ "\266\317\344\266\317\344\266\377\377\377\377\377\377t\2702t\2702\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377D\3502\362\375\360P\3342\346\371"
+ "\342\377\377\377\\\3202\335\364\323\377\377\377h\3042\367\377\324t\2702\317"
+ "\344\266\377\377\377\200\2542\312\332\250\377\377\377\214\2402\377\377\262"
+ "\230\2242\307\300\213\377\377\377\244\2102\307\260|{^\377\200U0\220^\377"
+ "\7\4/\227U[\246]\377\7\3/\377\242y\236\37""2\306M0\210%\14T-2{^\377mVv\6"
+ "\5/\6\5/h\\\377\\U\204\\U\204\5\5/\5\5/VX\377VX\377LR\221LR\221\377\377\377"
+ "\214\2402\214\2402\377\377\377\377\377\377\377\377\377\312\332\250\312\332"
+ "\250\312\332\250\377\377\377\200\2542\200\2542\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\317\344\266\317\344\266\377"
+ "\377\377\377\377\377t\2702t\2702t\2702\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377D\3502\365\375\363\377\377"
+ "\377O\3321l\22l\\\3202\335\364\323\357\346\357h\3042\325\355\305\377\377"
+ "\377t\2702\317\344\266l-l\200\2521\377\377\377\204\211=\310\316\231\377\377"
+ "\377\262\243L\307\300\213\377\377\377E&\25mVv{^\377ySB\220^\377\7\4/\275"
+ "t\201\246]\377\7\3/I\37!\277Z\377\10\3/\237YQ\6\4/{^\377\236\213\247mVv\6"
+ "\5/,-lh\\\377\\U\204dow\5\5/\5\5/\222\251\377VX\377\310\316\231T{@\377\377"
+ "\377\214\2402w\240V\377\377\377\377\377\377\377\377\377\377\377\377\312\332"
+ "\250U\231G\377\377\377\200\2542q\270\\\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377l\317l\317\344\266\317\344\266z\330v\377\377\377"
+ "\377\377\377\323\377\221t\2702t\2702l\352l\377\377\377\377\377\377\377\377"
+ "\377D\3502\362\375\360\377\377\377P\3342\346\371\342\377\377\377\\\3202\364"
+ "\377\336h\3042\325\355\305\377\377\377t\2702\317\344\266\377\377\377\200"
+ "\2542\312\332\250\377\377\377\214\2402\310\316\231\377\377\377\230\2242\307"
+ "\300\213\377\377\377\6\5/mVv{^\377\200U0\220^\377\7\4/\227U[\246]\377\7\3"
+ "/\255RN\277Z\377\10\3/\306M@\6\4/{^\377{^\377mVv\6\5/\6\5/h\\\377h\\\377"
+ "\\U\204\12\12\360\5\5/\12\12\360\377\377\377\377\377\377\310\316\231\310"
+ "\316\231\377\377\377\214\2402\214\2402\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\312\332\250\312\332\250\377\377\377\200\2542\200\2542\200\254"
+ "2\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\317\344\266\317\344\266\317\344\266\377\377\377\377\377\377t\2702t\2702"
+ "\377\377\377\377\377\377D\3502\362\375\360\377\377\377P\3342\346\371\342"
+ "\377\377\377\\\3202\335\364\323\377\377\377h\3042\325\355\305\377\377\377"
+ "t\2702\317\344\266\377\377\377\200\2542\312\332\250\377\377\377\214\2402"
+ "\310\316\231\377\377\377\230\2242\307\300\213h\\\377\6\5/mVv{^\377\200U0"
+ "\220^\377\7\4/\227U[\246]\377\7\3/\255RN\277Z\377\10\3/\306M@\6\4/\6\4/{"
+ "^\377mVvmVv\6\5/\12\12\360h\\\377\\U\204\\U\204\5\5/\230\2242\377\377\377"
+ "\377\377\377\377\377\377\310\316\231\310\316\231\377\377\377\214\2402\214"
+ "\2402\377\377\377\377\377\377\377\377\377\377\377\377\312\332\250\312\332"
+ "\250\377\377\377\377\377\377\200\2542\200\2542\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\317\344\266\317"
+ "\344\266\377\377\377\377\377\377\377\377\377\377\377\377D\3502q\10p\377\377"
+ "\377P\3342\335\350\332\377\377\377\\\3202\351\366\337\377\377\377h\3042d"
+ "!\\\377\377\377t\2702\277\302\252\377\377\377\200\2542\343\345\301\377\377"
+ "\377\214\2402^2H\377\377\377\230\2242\257\235\204h\\\377\6\5/\223o\234{^"
+ "\377\6\4/<\36""1\377\252\215j)2\211XK\377\250\203\202$2\337~c\377\242y\236"
+ "\37""2]#\26\306M@\6\4/ym\274{^\377mVvELn\6\5/h\\\37703x\\U\204\307\300\213"
+ "\204\226\\\230\2242\377\377\377\377\377\377\377\377\377\310\316\231^\212"
+ "H\377\377\377\214\2402}\256b\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\312\332\250_\251O\377\377\377\377\377\377y\310j\200\2542\377\377\377"
+ "\377\377\377\377\377\377\377\377\377x\341x\377\377\377\377\377\377\177\350"
+ "|\317\344\266\377\377\377\377\377\377D\3502\362\375\360\377\377\377P\334"
+ "2\346\371\342\377\377\377\\\3202\335\364\323\377\377\377\377\377\377h\304"
+ "2\325\355\305\377\377\377t\2702\317\344\266\377\377\377\200\2542\312\332"
+ "\250\377\377\377\214\2402\310\316\231\377\377\377\230\2242\\U\204h\\\377"
+ "\6\5/mVv{^\377\6\4/\12\12\360\201Vi\220^\377\7\4/\227U[\246]\377\7\3/\255"
+ "RN\277Z\377\10\3/\306M@\6\4/\12\12\360{^\377mVvmVv\6\5/\12\12\360h\\\377"
+ "\377\377\377\307\300\213\377\377\377\230\2242\230\2242\377\377\377\377\377"
+ "\377\377\377\377\310\316\231\310\316\231\377\377\377\214\2402\214\2402\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\312\332\250\312\332\250\312"
+ "\332\250\377\377\377\200\2542\200\2542\200\2542\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377D\350"
+ "2\362\375\360\377\377\377P\3342\377\377\377\346\371\342\377\377\377\\\320"
+ "2\335\364\323\377\377\377h\3042\325\355\305\377\377\377t\2702\317\344\266"
+ "\377\377\377\200\2542\377\377\377\312\332\250\377\377\377\214\2402\310\316"
+ "\231\377\377\377\5\5/\\U\204h\\\377\6\5/mVv{^\377\6\4/\12\12\360\201Vi\220"
+ "^\377\7\4/\227U[\246]\377\7\3/\255RN\277Z\377\10\3/\306M@\6\4/\6\4/{^\377"
+ "\12\12\360mVv\6\5/\6\5/\377\377\377\377\377\377\307\300\213\307\300\213\377"
+ "\377\377\230\2242\377\377\377\377\377\377\377\377\377\377\377\377\310\316"
+ "\231\310\316\231\377\377\377\214\2402\214\2402\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\312\332\250\312\332\250\377\377\377\377"
+ "\377\377\200\2542\200\2542\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\204\0\204\377\377\377D\3502\355\364\353\377\377\377\377\377\377Y\335;\346"
+ "\371\342\377\377\377/\26\31\335\364\323\377\377\377k\255<\325\355\305\377"
+ "\377\377\377\377\377t\2702\317\344\266\2046\204\200\2542\312\332\250\340"
+ "\317\340\214\2402\310\316\231\377\377\377VX\377\5\5//\33Dh\\\377\6\5/tVz"
+ "{^\377\6\4/=0\377\201Vi\220^\377\3\1\30\227U[\246]\377?6U\255RN\277Z\377"
+ "\337]s\306M0\306M@\3\2\30{^\377{^\377yv}mVv\244\2102\377\377\377\377\377"
+ "\377\377\377\377gyG\307\300\213\230\2242\212\242h\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\310\316\231g\230O\377\377\377\214\2402\205\274q"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377h\270V\312\332"
+ "\250\377\377\377\222\344\222\200\2542\200\2542\377\377\377\377\377\377\377"
+ "\377\377\377\377\377D\3502\362\375\360\377\377\377\377\377\377P\3342\346"
+ "\371\342\377\377\377\\\3202\335\364\323\377\377\377\377\377\377h\3042\325"
+ "\355\305\377\377\377t\2702\317\344\266\377\377\377\377\377\377\200\2542\312"
+ "\332\250\377\377\377\214\2402\310\316\231VX\377\12\12\360\5\5/\\U\204h\\"
+ "\377\6\5/mVv{^\377\6\4/\12\12\360\201Vi\220^\377\7\4/\227U[\246]\377\7\3"
+ "/\255RN\255RN\277Z\377\10\3/\306M@\6\4/\12\12\360{^\377\12\12\360\307\260"
+ "|\244\2102\244\2102\377\377\377\377\377\377\377\377\377\307\300\213\377\377"
+ "\377\230\2242\230\2242\377\377\377\377\377\377\377\377\377\377\377\377\310"
+ "\316\231\377\377\377\377\377\377\214\2402\214\2402\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\312\332\250\312\332\250\377\377\377"
+ "\377\377\377\200\2542\200\2542\377\377\377\377\377\377D\3502\377\377\377"
+ "\362\375\360\377\377\377P\3342\346\371\342\377\377\377\\\3202\377\377\377"
+ "\335\364\323\377\377\377h\3042\325\355\305\377\377\377\377\377\377t\2702"
+ "\317\344\266\377\377\377\200\2542\312\332\250\377\377\377\377\377\377\214"
+ "\2402LR\221VX\377\5\5/\\U\204\12\12\360h\\\377\6\5/mVv{^\377\6\4/\12\12\360"
+ "\201Vi\220^\377\7\4/\227U[\246]\377\7\3/\7\3/\255RN\277Z\377\10\3/\306M@"
+ "\6\4/\6\4/{^\377\377\377\377\307\260|\377\377\377\244\2102\377\377\377\377"
+ "\377\377\377\377\377\307\300\213\307\300\213\377\377\377\230\2242\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\310\316\231\310\316\231\377\377"
+ "\377\377\377\377\214\2402\214\2402\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\312\332\250\312\332\250\377\377\377\377\377\377\377"
+ "\377\377\377\377\377D\3502\377\377\377\362\375\360\377\377\377-\17\34\346"
+ "\371\342\377\377\377\363\346\363\\\3202\335\364\323\377\377\377h\3042\377"
+ "\377\377x)o\377\377\377t\2702\301\276\255\377\377\377\377\377\377\243\273"
+ "U\312\332\250\377\377\377O-\34\12\12\360LR\221gU\333\5\5/\\U\204<)\377h\\"
+ "\377\6\5/=!B{^\377\6\4/A2\306\201Vi\220^\377I9q\227U[\246]\377]-\220\7\3"
+ "/\255RN\245q\304\10\3/\306M0\377\236\221\6\4/\377\377\377\220\231\220\307"
+ "\260|\307\260|\226\227m\244\2102\377\377\377\377\377\377\377\377\377\307"
+ "\300\213p\207N\230\2242\230\2242\254\316\254\377\377\377\377\377\377\377"
+ "\377\377\310\316\231\310\316\231\220\317\220\377\377\377\214\2402\216\316"
+ "\200\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377r\310^\312"
+ "\332\250\377\377\377\377\377\377\377\377\377D\3502\362\375\360\377\377\377"
+ "P\3342\377\377\377\346\371\342\377\377\377\\\3202\335\364\323\377\377\377"
+ "\377\377\377h\3042\325\355\305\377\377\377\377\377\377t\2702\317\344\266"
+ "\377\377\377\200\2542\377\377\377\312\332\250\377\377\377\5\6/LR\221\12\12"
+ "\360VX\377\5\5/\\U\204h\\\377\12\12\360\6\5/mVv{^\377\6\4/\12\12\360\201"
+ "Vi\220^\377\7\4/\227U[\12\12\360\246]\377\7\3/\255RN\277Z\377\277Z\377\10"
+ "\3/\306M@\260|2\260|2\377\377\377\377\377\377\307\260|\377\377\377\244\210"
+ "2\377\377\377\377\377\377\377\377\377\377\377\377\307\300\213\377\377\377"
+ "\230\2242\230\2242\377\377\377\377\377\377\377\377\377\377\377\377\310\316"
+ "\231\310\316\231\377\377\377\377\377\377\214\2402\214\2402\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377D\3502\362\375\360\377\377\377P\3342\377\377\377\346\371\342\377"
+ "\377\377\\\3202\377\377\377\335\364\323\377\377\377h\3042\325\355\305\377"
+ "\377\377\377\377\377t\2702\317\344\266\377\377\377\377\377\377\200\2542\312"
+ "\332\250\377\377\377\12\12\360\5\6/LR\221VX\377\12\12\360\5\5/\\U\204h\\"
+ "\377\6\5/\12\12\360mVv{^\377\6\4/\12\12\360\201Vi\220^\377\7\4/\227U[\227"
+ "U[\246]\377\7\3/\255RN\12\12\360\277Z\377\10\3/\333bB\377\377\377\260|2\377"
+ "\377\377\377\377\377\307\260|\307\260|\244\2102\244\2102\377\377\377\377"
+ "\377\377\377\377\377\307\300\213\307\300\213\377\377\377\230\2242\230\224"
+ "2\377\377\377\377\377\377\377\377\377\377\377\377\310\316\231\310\316\231"
+ "\377\377\377\377\377\377\214\2402\214\2402\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377)\10\36\362\375\360\377\377\377\370"
+ "\356\370P\3342\346\371\342\377\377\377\377\377\377\\\3202\207\"\201\377\377"
+ "\377\377\377\377p\250D\325\355\305\377\377\377\377\377\377t\2702\317\344"
+ "\266\234?\234\200\2542\377\377\377\274\260\244FS\377\5\6/;#\377LR\221VX\377"
+ "\3\1\34\12\12\360\\U\204{^\330\6\5/\12\12\360\257\203\270{^\377\6\4/\6\4"
+ "\222\201Vi\220^\377P@d\12\12\360\227U[\370\244\377\7\3/\255RNi./\277Z\377"
+ "\324X2\264\202w\333bB\260|2\377\377\377\377\377\377\377\377\377yvK\377\377"
+ "\377\244\2102\236\247|\377\377\377\377\377\377\377\377\377\307\300\213\307"
+ "\300\213\234\306\234\230\2242\377\377\377\256\330\256\377\377\377\377\377"
+ "\377\377\377\377\310\316\231\310\316\231\234\341\234\377\377\377\214\240"
+ "2\232\343\223\377\377\377\377\377\377\377\377\377\377\377\377D\3502\362\375"
+ "\360\377\377\377\377\377\377P\3342\346\371\342\377\377\377\377\377\377\\"
+ "\3202\335\364\323\377\377\377\377\377\377h\3042\325\355\305\377\377\377\377"
+ "\377\377t\2702\317\344\266\377\377\377\377\377\377\200\2542\312\332\250\12"
+ "\12\360FS\377\5\6/LR\221\12\12\360RW\255\3\5\35\6\11\224ZT\\d[\261\3\4\35"
+ "\6\11\224lVTw]\264\4\4\35\6\11\224\200VN\214]\270\4\3\35\6\11\224\226UG\242"
+ "\\\274\4\3\35\4\3\35\254R@\377\377\311\203U\36\203U\36\323a:my\36my\36\377"
+ "\377\276\377\377\276\243\255X\243\255X\236\371\236e\204\36\236\371\236\374"
+ "\377\273\236\371\236\236\371\236\234\275`\236\371\236^\220\36^\220\36\236"
+ "\371\236\352\377\267\352\377\267\236\371\236\236\371\236\310\316\231\310"
+ "\316\231\377\377\377\377\377\377\214\2402\377\377\377\377\377\377\377\377"
+ "\377D\3502\362\375\360\377\377\377\377\377\377P\3342\346\371\342\377\377"
+ "\377\377\377\377\\\3202\377\377\377\335\364\323\377\377\377h\3042\377\377"
+ "\377\325\355\305\377\377\377t\2702\377\377\377\317\344\266\377\377\377\377"
+ "\377\377\200\2542<L\237FS\377\12\12\360\5\6/LR\221\6\11\224RW\255\3\5\35"
+ "ZT\\\6\11\224d[\261\3\4\35\6\11\224lVTw]\264\4\4\35\6\11\224\200VN\214]\270"
+ "\4\3\35\4\3\35\226UG\242\\\274\6\11\224\4\3\35\304wB\377\377\311\377\377"
+ "\311\203U\36\323a:\236\371\236my\36\236\371\236\377\377\276\236\371\236\243"
+ "\255X\236\371\236e\204\36e\204\36\374\377\273\374\377\273\236\371\236\234"
+ "\275`\234\275`\236\371\236^\220\36^\220\36\236\371\236\352\377\267\352\377"
+ "\267\377\377\377\377\377\377\310\316\231\310\316\231\377\377\377\250\0\250"
+ "\377\377\377\377\377\377F\3375\362\375\360\377\377\377\377\377\377P\3342"
+ "\377\377\377\227\32\224\377\377\377\\\3202\362\340\362\335\364\323\377\377"
+ "\377\377\377\377h\3042\325\355\305\2506\250\377\377\377t\2702\304\272\262"
+ "\377\377\377\377\377\377\257\300a\12\12\360<L\237.\32\250\5\6/\12\12\360"
+ "jSzRW\255\6\11\224D+^ZT\\\6\11\224A&t\3\4\35lVTP9\235w]\264\4\4\35YG\347"
+ "\200VN\214]\270\3\4a\4\3\35\226UG\244y\257\6\11\224{a\36\377\322\246\236"
+ "\371\236\377\377\311V6\23\323a:\323a:\223\231y\236\371\236\377\377\276\377"
+ "\377\377\243\255X\243\255Xh\270he\204\36\236\371\236\272\322\253\374\377"
+ "\273\236\371\236\377\377\350\236\371\236\236\371\236=y\23\236\371\236\236"
+ "\371\236\262\344\262\377\377\377\377\377\377\377\377\377\310\316\231\377"
+ "\377\377\377\377\377\377\377\377D\3502\362\375\360\377\377\377\377\377\377"
+ "P\3342\377\377\377\346\371\342\377\377\377\377\377\377\\\3202\335\364\323"
+ "\377\377\377\377\377\377h\3042\325\355\305\377\377\377\377\377\377t\2702"
+ "\377\377\377\317\344\266\377\377\377\377\377\377\5\6/<L\237\12\12\360FS\377"
+ "\5\6/\6\11\224JQbRW\255\6\11\224\3\5\35ZT\\d[\261\6\11\224\3\4\35lVT\6\11"
+ "\224w]\264\4\4\35\6\11\224\200VN\214]\270\6\11\224\4\3\35\226UG\242\\\274"
+ "\377\377\306{a\36\304wB\304wB\377\377\311\203U\36\203U\36\323a:my\36my\36"
+ "\377\377\276\377\377\276\236\371\236\243\255X\236\371\236e\204\36e\204\36"
+ "\236\371\236\374\377\273\236\371\236\234\275`\234\275`\236\371\236^\220\36"
+ "^\220\36\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377D\3502\362\375\360\377\377\377\377\377\377"
+ "P\3342\377\377\377\346\371\342\377\377\377\377\377\377\\\3202\335\364\323"
+ "\377\377\377\377\377\377h\3042\377\377\377\325\355\305\377\377\377\377\377"
+ "\377t\2702\317\344\266\377\377\377\377\377\377\5\6/\12\12\360<L\237FS\377"
+ "\12\12\360\3\5\35JQb\6\11\224RW\255\3\5\35\6\11\224ZT\\d[\261\6\11\224\3"
+ "\4\35lVT\6\11\224w]\264\4\4\35\6\11\224\200VN\214]\270\6\11\224\4\3\35\226"
+ "UG\236\371\236\377\377\306{a\36\236\371\236\304wB\377\377\311\236\371\236"
+ "\203U\36\323a:\236\371\236my\36\236\371\236\377\377\276\236\371\236\243\255"
+ "X\243\255X\236\371\236e\204\36\236\371\236\374\377\273\374\377\273\236\371"
+ "\236\234\275`\234\275`\236\371\236\230\2242\230\2242\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377J\3508\377\377\377\362"
+ "\375\360\264\22\264\377\377\377P\3342\340\340\335\377\377\377\377\377\377"
+ "u\325K\377\377\377\335\364\323\264-\264\377\377\377h\3042\315\305\301\377"
+ "\377\377\377\377\377\240\307^\377\377\377\317\344\266\264H\264\12\12\360"
+ "\5\6/aL\245\12\12\360FS\377E(\323\3\5\35JQb\4\3hRW\255\3\5\35O2\241ZT\\d"
+ "[\261X>\346\3\4\35lVT\4\4hw]\264\4\4\35aK\244\200VN\214]\270kZ\371\4\3\35"
+ "\270\212Io\225o\377\377\306{a\36\253\300\253\304wB\377\377\311\377\377\377"
+ "\203U\36\323a:\224D(my\36\236\371\236\307\316\266\377\377\276\236\371\236"
+ "\377\377\343\236\371\236e\204\36Gk\25\236\371\236\374\377\273\260\334\260"
+ "\236\371\236\234\275`\377\377\377\377\377\377\230\2242k\207#\377\377\377"
+ "\377\377\377\377\377\377\377\377\377D\3502\377\377\377\362\375\360\377\377"
+ "\377\377\377\377P\3342\346\371\342\377\377\377\377\377\377\\\3202\377\377"
+ "\377\335\364\323\377\377\377\377\377\377h\3042\377\377\377\325\355\305\377"
+ "\377\377\377\377\377t\2702\317\344\266\377\377\3778L\377\12\12\360\5\6/<"
+ "L\237\12\12\360BR\252\3\5\35\6\11\224JQbRW\255\6\11\224\3\5\35ZT\\\6\11\224"
+ "d[\261\6\11\224\3\4\35lVT\6\11\224w]\264\4\4\35\6\11\224\200VN\214]\270\6"
+ "\11\224tm\36\270\212I\270\212I\377\377\306{a\36{a\36\304wB\236\371\236\377"
+ "\377\311\203U\36\236\371\236\323a:my\36my\36\236\371\236\377\377\276\236"
+ "\371\236\243\255X\243\255X\236\371\236e\204\36\236\371\236\374\377\273\374"
+ "\377\273\236\371\236\307\300\213\307\300\213\377\377\377\377\377\377\230"
+ "\2242\377\377\377\377\377\377\377\377\377D\3502\377\377\377\362\375\360\377"
+ "\377\377\377\377\377P\3342\377\377\377\346\371\342\377\377\377\377\377\377"
+ "\\\3202\335\364\323\377\377\377\377\377\377\377\377\377h\3042\325\355\305"
+ "\377\377\377\377\377\377t\2702\377\377\377\317\344\2668L\377\12\12\360\5"
+ "\6/\12\12\360<L\237BR\252\6\11\224\3\5\35JQb\6\11\224RW\255\6\11\224\3\5"
+ "\35ZT\\\6\11\224d[\261\3\4\35\6\11\224lVT\6\11\224w]\264\4\4\35\6\11\224"
+ "\200VN\214]\270\236\371\236tm\36\236\371\236\270\212I\377\377\306\236\371"
+ "\236{a\36\304wB\236\371\236\377\377\311\203U\36\203U\36\323a:\236\371\236"
+ "my\36\236\371\236\377\377\276\377\377\276\236\371\236\243\255X\236\371\236"
+ "e\204\36e\204\36\236\371\236\374\377\273\377\377\377\377\377\377\307\300"
+ "\213\307\300\213\377\377\377\377\377\377\377\377\377\377\377\3773\10%\377"
+ "\377\377\362\375\360\372\356\372\377\377\377P\3342\377\377\377\346\371\342"
+ "\377\377\377\300$\300\\\3202\377\377\377\327\317\316\377\377\377\377\377"
+ "\377\220\317Z\377\377\377\325\355\305\300?\300\377\377\377t\2702\312\267"
+ "\270\12\12\3608L\377F#\377\5\6/<L\237\4\3oBR\252\6\11\224K)[JQb\6\11\224"
+ "\243\204\376\3\5\35\6\11\224C&E\6\11\224d[\261_@l\6\11\224lVTkP\371w]\264"
+ "\4\4\35\4\5o\200VN\377\377\302\262\276\262tm\36\236\371\236\377\360\302\377"
+ "\377\306\236\371\236\\A\26\304wB\304wB\322\312\302\236\371\236\203U\36\377"
+ "\355\310\323a:my\36R]\26\236\371\236\377\377\276\270\326\270\243\255X\236"
+ "\371\236\377\377\377e\204\36\236\371\236\300\341\300\377\377\377\377\377"
+ "\377\305\353\305\307\300\213\377\377\377\377\377\377\377\377\377D\3502\377"
+ "\377\377\362\375\360\377\377\377\377\377\377P\3342\377\377\377\346\371\342"
+ "\377\377\377\377\377\377\\\3202\377\377\377\335\364\323\377\377\377\377\377"
+ "\377h\3042\377\377\377\325\355\305\377\377\377\377\377\377t\2702\377\377"
+ "\3770E\254\12\12\3608L\377\5\6/\12\12\360:Lj\6\11\224BR\252\3\5\35\6\11\224"
+ "JQb\6\11\224RW\255\3\5\35\6\11\224ZT\\\6\11\224d[\261\3\4\35\6\11\224lVT"
+ "\6\11\224w]\264\4\4\35\6\11\224\255\235Q\377\377\302\377\377\302tm\36\236"
+ "\371\236\270\212I\377\377\306\377\377\306{a\36\236\371\236\304wB\377\377"
+ "\311\377\377\311\203U\36\236\371\236\323a:\236\371\236my\36\236\371\236\377"
+ "\377\276\236\371\236\243\255X\243\255X\236\371\236e\204\36\244\2102\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377D\3502\377\377\377\362\375\360\377\377\377\377\377\377P\3342\377\377"
+ "\377\346\371\342\377\377\377\377\377\377\377\377\377\\\3202\335\364\323\377"
+ "\377\377\377\377\377\377\377\377h\3042\325\355\305\377\377\377\377\377\377"
+ "\377\377\377t\2702\317\344\266\377\377\377\377\377\377\377\377\377\200\254"
+ "2\236\371\236\222\326p\332\377\264\236\371\236V\234\36\236\371\236\226\312"
+ "g\352\377\267\236\371\236^\220\36\236\371\236\234\275`\374\377\273\236\371"
+ "\236e\204\36\236\371\236\243\255X\377\377\276\236\371\236my\36\236\371\236"
+ "\255\235Q\236\371\236\377\377\302tm\36\236\371\236\270\212I\236\371\236\377"
+ "\377\306{a\36\236\371\236\304wB\236\371\236\377\377\311\203U\36\203U\36\323"
+ "a:\236\371\236my\36\236\371\236\377\377\276\377\377\276\236\371\236\243\255"
+ "X\236\371\236\377\377\377\244\2102\377\377\377\377\377\377\377\377\377\314"
+ "\0\314\377\377\377\377\377\377H\3377\377\377\377\362\375\360\377\377\377"
+ "\377\377\377\377\377\377@\27(\346\371\342\377\377\377\367\340\367\377\377"
+ "\377\\\3202\377\377\377\335\364\323\377\377\377\3146\314h\3042\377\377\377"
+ "\322\301\306\377\377\377\377\377\377\255\314k\377\377\377\317\344\266\314"
+ "Q\314\377\377\377\200\2542\256\300\256\222\326p\236\371\236\377\377\377\236"
+ "\371\236V\234\36xUR\236\371\236\352\377\267\262\273\262^\220\36\234\275`"
+ "\377\377\377\374\377\273\236\371\236PE\30\236\371\236\243\255X\342\300\305"
+ "\236\371\236my\36\377\377\377\255\235Q\236\371\236\314\242\233tm\36\236\371"
+ "\236\304\237\240\236\371\236\377\377\306\377\340\256{a\36\304wB~\270~\377"
+ "\377\311\236\371\236\273\254\244\323a:\323a:\377\377\303my\36\236\371\236"
+ "\314\330\230\236\371\236\243\255X\313\332\302\377\377\377\244\2102\377\377"
+ "\355\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377D\3502\362"
+ "\375\360\377\377\377\377\377\377\377\377\377P\3342\377\377\377\346\371\342"
+ "\377\377\377\377\377\377\\\3202\377\377\377\335\364\323\377\377\377\377\377"
+ "\377h\3042\377\377\377\325\355\305\377\377\377\377\377\377\377\377\377t\270"
+ "2\317\344\266\377\377\377\377\377\377\377\377\377O\247\36\236\371\236\222"
+ "\326p\332\377\264\236\371\236V\234\36\236\371\236\226\312g\236\371\236\352"
+ "\377\267\236\371\236^\220\36\234\275`\236\371\236\374\377\273\236\371\236"
+ "e\204\36\236\371\236\243\255X\377\377\276\236\371\236my\36\236\371\236\255"
+ "\235Q\236\371\236\377\377\302tm\36\236\371\236\270\212I\236\371\236\377\377"
+ "\306\236\371\236{a\36\304wB\304wB\377\377\311\236\371\236\203U\36\236\371"
+ "\236\323a:\236\371\236my\36\236\371\236\377\377\276\377\377\276\377\377\377"
+ "\307\260|\377\377\377\377\377\377\244\2102\377\377\377\377\377\377\377\377"
+ "\377\377\377\377D\3502\362\375\360\377\377\377\377\377\377\377\377\377P\334"
+ "2\377\377\377\346\371\342\377\377\377\377\377\377\\\3202\377\377\377\335"
+ "\364\323\377\377\377\377\377\377\377\377\377h\3042\377\377\377\325\355\305"
+ "\377\377\377\377\377\377t\2702\377\377\377\317\344\266\377\377\377\377\377"
+ "\377\236\371\236O\247\36\222\326p\236\371\236\332\377\264\236\371\236V\234"
+ "\36\236\371\236\226\312g\236\371\236\352\377\267^\220\36\236\371\236\234"
+ "\275`\236\371\236\374\377\273\236\371\236e\204\36\236\371\236\243\255X\377"
+ "\377\276\236\371\236my\36\236\371\236\255\235Q\236\371\236\377\377\302tm"
+ "\36tm\36\270\212I\236\371\236\377\377\306\236\371\236{a\36\236\371\236\304"
+ "wB\377\377\311\377\377\311\203U\36\236\371\236\323a:\236\371\236my\36\236"
+ "\371\236\236\371\236\377\377\377\377\377\377\307\260|\307\260|\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377D\3502\362\375\360\330\22"
+ "\330\377\377\377\377\377\377]\306B\377\377\377\346\371\342\377\377\377\377"
+ "\377\377\377\377\377M$*\335\364\323\377\377\377\366\324\366\377\377\377h"
+ "\3042\377\377\377\325\355\305\377\377\377\330H\330\377\377\377t\2702\321"
+ "\264\300\377\377\377\377\377\377\352\377\352O\247\36\236\371\236{S^\236\371"
+ "\236\332\377\264\266\274\266V\234\36\226\312g\377\377\377\352\377\267\236"
+ "\371\236OG\31\236\371\236\234\275`\274\274\274\374\377\273\236\371\236\336"
+ "\325\227\243\255X\236\371\236\330\231\240\236\371\236my\36\302\300\302\255"
+ "\235Q\236\371\236\377\377\377\236\371\236tm\36\233a=\236\371\236\377\377"
+ "\306\310\314\310{a\36\236\371\236\377\377\351\236\371\236\377\377\311nE\31"
+ "\203U\36\323a:\326\304\276my\36my\36\377\377\377\377\377\377\377\377\377"
+ "\330\352\330\307\260|\377\377\377\377\377\377\377\377\377\377\377\377D\350"
+ "2\377\377\377\362\375\360\377\377\377\377\377\377P\3342\377\377\377\346\371"
+ "\342\377\377\377\377\377\377\377\377\377\\\3202\377\377\377\335\364\323\377"
+ "\377\377\377\377\377\377\377\377h\3042\325\355\305\377\377\377\377\377\377"
+ "\377\377\377t\2702\377\377\377\317\344\266\377\377\377\377\377\377\377\377"
+ "\377\200\2542\377\377\377\312\332\250\377\377\377\377\377\377\214\2402\377"
+ "\377\377\310\316\231\377\377\377\377\377\377\377\377\377\230\2242\377\377"
+ "\377\307\300\213\377\377\377\377\377\377\244\2102\377\377\377\307\260|\377"
+ "\377\377\377\377\377\377\377\377\260|2\377\377\377\312\237n\377\377\377\377"
+ "\377\377\377\377\377\274p2\316\214_\316\214_\377\377\377\377\377\377\310"
+ "d2\377\377\377\323xQ\377\377\377\377\377\377\377\377\377\324X2\377\377\377"
+ "\333bB\377\377\377\260|2\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377D\3502\377\377\377\362\375"
+ "\360\377\377\377\377\377\377P\3342\377\377\377\346\371\342\377\377\377\377"
+ "\377\377\377\377\377\\\3202\377\377\377\335\364\323\377\377\377\377\377\377"
+ "\377\377\377h\3042\377\377\377\325\355\305\377\377\377\377\377\377\377\377"
+ "\377t\2702\317\344\266\377\377\377\377\377\377\377\377\377\200\2542\377\377"
+ "\377\312\332\250\377\377\377\377\377\377\377\377\377\214\2402\377\377\377"
+ "\310\316\231\377\377\377\377\377\377\377\377\377\230\2242\377\377\377\307"
+ "\300\213\377\377\377\377\377\377\244\2102\377\377\377\307\260|\377\377\377"
+ "\377\377\377\377\377\377\260|2\377\377\377\312\237n\377\377\377\377\377\377"
+ "\377\377\377\274p2\377\377\377\316\214_\377\377\377\377\377\377\310d2\310"
+ "d2\323xQ\377\377\377\377\377\377\377\377\377\324X2\377\377\377\333bB\377"
+ "\377\377\260|2\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\344\11\344D\3502\377\377\377\360\354\357\377\377\377\377\377"
+ "\377\377\377\377P\3342\377\377\377\315#\312\377\377\377\377\377\377s\262"
+ "Q\377\377\377\335\364\323\377\377\377\377\377\377\377\377\377\\0,\377\377"
+ "\377\325\355\305\367\313\367\377\377\377\377\377\377\274\321z\377\377\377"
+ "\317\344\266\344Z\344\377\377\377\377\377\377\246\217v\377\377\377\312\332"
+ "\250\377\377\377\377\377\377\377\377\377}I,\377\377\377\310\316\231\361\277"
+ "\361\377\377\377\230\2242\377\377\377\307\300\213\377\377\377\344\220\344"
+ "\377\377\377\244\2102\356\301\356\307\260|\377\377\377\377\377\377\377\377"
+ "\377\260|2\344\253\344\312\237n\377\377\377\353\312\353\377\377\377\274p"
+ "2\377\377\377\316\214_\377\377\377\344\306\344\377\377\377\310d2\340\276"
+ "\310\323xQ\377\377\377\377\377\377\324X2\324X2\303V;\333bB\260|2\337\340"
+ "\325\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377D\3502\377"
+ "\377\377\362\375\360\377\377\377\377\377\377\377\377\377P\3342\377\377\377"
+ "\346\371\342\377\377\377\377\377\377\377\377\377\\\3202\377\377\377\335\364"
+ "\323\377\377\377\377\377\377\377\377\377h\3042\377\377\377\325\355\305\377"
+ "\377\377\377\377\377\377\377\377t\2702\317\344\266\377\377\377\377\377\377"
+ "\377\377\377\200\2542\377\377\377\312\332\250\377\377\377\377\377\377\377"
+ "\377\377\214\2402\377\377\377\310\316\231\377\377\377\377\377\377\377\377"
+ "\377\230\2242\377\377\377\307\300\213\377\377\377\377\377\377\377\377\377"
+ "\244\2102\377\377\377\307\260|\377\377\377\377\377\377\377\377\377\260|2"
+ "\377\377\377\312\237n\377\377\377\377\377\377\377\377\377\274p2\377\377\377"
+ "\316\214_\377\377\377\377\377\377\377\377\377\310d2\377\377\377\323xQ\377"
+ "\377\377\377\377\377\377\377\377\324X2\377\377\377\333bB\377\377\377\260"
+ "|2\377\377\377\377\377\377\377\377\377\377\377\377D\3502\377\377\377\362"
+ "\375\360\377\377\377\377\377\377\377\377\377P\3342\377\377\377\346\371\342"
+ "\377\377\377\377\377\377\377\377\377\\\3202\377\377\377\335\364\323\377\377"
+ "\377\377\377\377\377\377\377h\3042\377\377\377\325\355\305\377\377\377\377"
+ "\377\377\377\377\377t\2702\377\377\377\317\344\266\377\377\377\377\377\377"
+ "\377\377\377\200\2542\377\377\377\312\332\250\377\377\377\377\377\377\377"
+ "\377\377\214\2402\377\377\377\310\316\231\377\377\377\377\377\377\377\377"
+ "\377\230\2242\377\377\377\307\300\213\377\377\377\377\377\377\377\377\377"
+ "\244\2102\377\377\377\307\260|\377\377\377\377\377\377\377\377\377\260|2"
+ "\377\377\377\312\237n\377\377\377\377\377\377\377\377\377\274p2\377\377\377"
+ "\316\214_\377\377\377\377\377\377\377\377\377\310d2\377\377\377\323xQ\377"
+ "\377\377\377\377\377\377\377\377\324X2\377\377\377\333bB\377\377\377",
+};
+
+/**
+ * \brief Returns the PrimitivesBlend test image as SDL_Surface.
+ */
+SDL_Surface *SDLTest_ImagePrimitivesBlend()
+{
+ SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
+ (void*)SDLTest_imagePrimitivesBlend.pixel_data,
+ SDLTest_imagePrimitivesBlend.width,
+ SDLTest_imagePrimitivesBlend.height,
+ SDLTest_imagePrimitivesBlend.bytes_per_pixel * 8,
+ SDLTest_imagePrimitivesBlend.width * SDLTest_imagePrimitivesBlend.bytes_per_pixel,
+#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+ 0xff000000, /* Red bit mask. */
+ 0x00ff0000, /* Green bit mask. */
+ 0x0000ff00, /* Blue bit mask. */
+ 0x000000ff /* Alpha bit mask. */
+#else
+ 0x000000ff, /* Red bit mask. */
+ 0x0000ff00, /* Green bit mask. */
+ 0x00ff0000, /* Blue bit mask. */
+ 0xff000000 /* Alpha bit mask. */
+#endif
+ );
+ return surface;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/test/SDL_test_log.c b/src/3rdparty/SDL2/src/test/SDL_test_log.c
new file mode 100644
index 0000000..5d6ff24
--- /dev/null
+++ b/src/3rdparty/SDL2/src/test/SDL_test_log.c
@@ -0,0 +1,118 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+
+ Used by the test framework and test cases.
+
+*/
+
+/* quiet windows compiler warnings */
+#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
+# define _CRT_SECURE_NO_WARNINGS
+#endif
+
+#include "SDL_config.h"
+
+#include <stdarg.h> /* va_list */
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+#include "SDL.h"
+
+#include "SDL_test.h"
+
+/* work around compiler warning on older GCCs. */
+#if (defined(__GNUC__) && (__GNUC__ <= 2))
+static size_t
+strftime_gcc2_workaround(char *s, size_t max, const char *fmt, const struct tm *tm)
+{
+ return strftime(s, max, fmt, tm);
+}
+#ifdef strftime
+#undef strftime
+#endif
+#define strftime strftime_gcc2_workaround
+#endif
+
+/* !
+ * Converts unix timestamp to its ascii representation in localtime
+ *
+ * Note: Uses a static buffer internally, so the return value
+ * isn't valid after the next call of this function. If you
+ * want to retain the return value, make a copy of it.
+ *
+ * \param timestamp A Timestamp, i.e. time(0)
+ *
+ * \return Ascii representation of the timestamp in localtime in the format '08/23/01 14:55:02'
+ */
+static char *SDLTest_TimestampToString(const time_t timestamp)
+{
+ time_t copy;
+ static char buffer[64];
+ struct tm *local;
+
+ SDL_memset(buffer, 0, sizeof(buffer));
+ copy = timestamp;
+ local = localtime(&copy);
+ strftime(buffer, sizeof(buffer), "%x %X", local);
+
+ return buffer;
+}
+
+/*
+ * Prints given message with a timestamp in the TEST category and INFO priority.
+ */
+void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+ va_list list;
+ char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
+
+ /* Print log message into a buffer */
+ SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
+ va_start(list, fmt);
+ SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
+ va_end(list);
+
+ /* Log with timestamp and newline */
+ SDL_LogMessage(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_INFO, " %s: %s", SDLTest_TimestampToString(time(0)), logMessage);
+}
+
+/*
+ * Prints given message with a timestamp in the TEST category and the ERROR priority.
+ */
+void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
+{
+ va_list list;
+ char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
+
+ /* Print log message into a buffer */
+ SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
+ va_start(list, fmt);
+ SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
+ va_end(list);
+
+ /* Log with timestamp and newline */
+ SDL_LogMessage(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_ERROR, "%s: %s", SDLTest_TimestampToString(time(0)), logMessage);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/test/SDL_test_md5.c b/src/3rdparty/SDL2/src/test/SDL_test_md5.c
new file mode 100644
index 0000000..c0d05a4
--- /dev/null
+++ b/src/3rdparty/SDL2/src/test/SDL_test_md5.c
@@ -0,0 +1,338 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ ***********************************************************************
+ ** RSA Data Security, Inc. MD5 Message-Digest Algorithm **
+ ** Created: 2/17/90 RLR **
+ ** Revised: 1/91 SRD,AJ,BSK,JT Reference C ver., 7/10 constant corr. **
+ ***********************************************************************
+ */
+
+/*
+ ***********************************************************************
+ ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
+ ** **
+ ** License to copy and use this software is granted provided that **
+ ** it is identified as the "RSA Data Security, Inc. MD5 Message- **
+ ** Digest Algorithm" in all material mentioning or referencing this **
+ ** software or this function. **
+ ** **
+ ** License is also granted to make and use derivative works **
+ ** provided that such works are identified as "derived from the RSA **
+ ** Data Security, Inc. MD5 Message-Digest Algorithm" in all **
+ ** material mentioning or referencing the derived work. **
+ ** **
+ ** RSA Data Security, Inc. makes no representations concerning **
+ ** either the merchantability of this software or the suitability **
+ ** of this software for any particular purpose. It is provided "as **
+ ** is" without express or implied warranty of any kind. **
+ ** **
+ ** These notices must be retained in any copies of any part of this **
+ ** documentation and/or software. **
+ ***********************************************************************
+ */
+
+#include "SDL_config.h"
+
+#include "SDL_test.h"
+
+/* Forward declaration of static helper function */
+static void SDLTest_Md5Transform(MD5UINT4 * buf, MD5UINT4 * in);
+
+static unsigned char MD5PADDING[64] = {
+ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+/* F, G, H and I are basic MD5 functions */
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define I(x, y, z) ((y) ^ ((x) | (~z)))
+
+/* ROTATE_LEFT rotates x left n bits */
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+
+/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
+
+/* Rotation is separate from addition to prevent recomputation */
+#define FF(a, b, c, d, x, s, ac) \
+ {(a) += F ((b), (c), (d)) + (x) + (MD5UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define GG(a, b, c, d, x, s, ac) \
+ {(a) += G ((b), (c), (d)) + (x) + (MD5UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define HH(a, b, c, d, x, s, ac) \
+ {(a) += H ((b), (c), (d)) + (x) + (MD5UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define II(a, b, c, d, x, s, ac) \
+ {(a) += I ((b), (c), (d)) + (x) + (MD5UINT4)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+
+/*
+ The routine MD5Init initializes the message-digest context
+ mdContext. All fields are set to zero.
+*/
+
+void SDLTest_Md5Init(SDLTest_Md5Context * mdContext)
+{
+ if (mdContext==NULL) return;
+
+ mdContext->i[0] = mdContext->i[1] = (MD5UINT4) 0;
+
+ /*
+ * Load magic initialization constants.
+ */
+ mdContext->buf[0] = (MD5UINT4) 0x67452301;
+ mdContext->buf[1] = (MD5UINT4) 0xefcdab89;
+ mdContext->buf[2] = (MD5UINT4) 0x98badcfe;
+ mdContext->buf[3] = (MD5UINT4) 0x10325476;
+}
+
+/*
+ The routine MD5Update updates the message-digest context to
+ account for the presence of each of the characters inBuf[0..inLen-1]
+ in the message whose digest is being computed.
+*/
+
+void SDLTest_Md5Update(SDLTest_Md5Context * mdContext, unsigned char *inBuf,
+ unsigned int inLen)
+{
+ MD5UINT4 in[16];
+ int mdi;
+ unsigned int i, ii;
+
+ if (mdContext == NULL) return;
+ if (inBuf == NULL || inLen < 1) return;
+
+ /*
+ * compute number of bytes mod 64
+ */
+ mdi = (int) ((mdContext->i[0] >> 3) & 0x3F);
+
+ /*
+ * update number of bits
+ */
+ if ((mdContext->i[0] + ((MD5UINT4) inLen << 3)) < mdContext->i[0])
+ mdContext->i[1]++;
+ mdContext->i[0] += ((MD5UINT4) inLen << 3);
+ mdContext->i[1] += ((MD5UINT4) inLen >> 29);
+
+ while (inLen--) {
+ /*
+ * add new character to buffer, increment mdi
+ */
+ mdContext->in[mdi++] = *inBuf++;
+
+ /*
+ * transform if necessary
+ */
+ if (mdi == 0x40) {
+ for (i = 0, ii = 0; i < 16; i++, ii += 4)
+ in[i] = (((MD5UINT4) mdContext->in[ii + 3]) << 24) |
+ (((MD5UINT4) mdContext->in[ii + 2]) << 16) |
+ (((MD5UINT4) mdContext->in[ii + 1]) << 8) |
+ ((MD5UINT4) mdContext->in[ii]);
+ SDLTest_Md5Transform(mdContext->buf, in);
+ mdi = 0;
+ }
+ }
+}
+
+/*
+ The routine MD5Final terminates the message-digest computation and
+ ends with the desired message digest in mdContext->digest[0...15].
+*/
+
+void SDLTest_Md5Final(SDLTest_Md5Context * mdContext)
+{
+ MD5UINT4 in[16];
+ int mdi;
+ unsigned int i, ii;
+ unsigned int padLen;
+
+ if (mdContext == NULL) return;
+
+ /*
+ * save number of bits
+ */
+ in[14] = mdContext->i[0];
+ in[15] = mdContext->i[1];
+
+ /*
+ * compute number of bytes mod 64
+ */
+ mdi = (int) ((mdContext->i[0] >> 3) & 0x3F);
+
+ /*
+ * pad out to 56 mod 64
+ */
+ padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
+ SDLTest_Md5Update(mdContext, MD5PADDING, padLen);
+
+ /*
+ * append length in bits and transform
+ */
+ for (i = 0, ii = 0; i < 14; i++, ii += 4)
+ in[i] = (((MD5UINT4) mdContext->in[ii + 3]) << 24) |
+ (((MD5UINT4) mdContext->in[ii + 2]) << 16) |
+ (((MD5UINT4) mdContext->in[ii + 1]) << 8) |
+ ((MD5UINT4) mdContext->in[ii]);
+ SDLTest_Md5Transform(mdContext->buf, in);
+
+ /*
+ * store buffer in digest
+ */
+ for (i = 0, ii = 0; i < 4; i++, ii += 4) {
+ mdContext->digest[ii] = (unsigned char) (mdContext->buf[i] & 0xFF);
+ mdContext->digest[ii + 1] =
+ (unsigned char) ((mdContext->buf[i] >> 8) & 0xFF);
+ mdContext->digest[ii + 2] =
+ (unsigned char) ((mdContext->buf[i] >> 16) & 0xFF);
+ mdContext->digest[ii + 3] =
+ (unsigned char) ((mdContext->buf[i] >> 24) & 0xFF);
+ }
+}
+
+/* Basic MD5 step. Transforms buf based on in.
+ */
+static void SDLTest_Md5Transform(MD5UINT4 * buf, MD5UINT4 * in)
+{
+ MD5UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
+
+ /*
+ * Round 1
+ */
+#define S11 7
+#define S12 12
+#define S13 17
+#define S14 22
+ FF(a, b, c, d, in[0], S11, 3614090360u); /* 1 */
+ FF(d, a, b, c, in[1], S12, 3905402710u); /* 2 */
+ FF(c, d, a, b, in[2], S13, 606105819u); /* 3 */
+ FF(b, c, d, a, in[3], S14, 3250441966u); /* 4 */
+ FF(a, b, c, d, in[4], S11, 4118548399u); /* 5 */
+ FF(d, a, b, c, in[5], S12, 1200080426u); /* 6 */
+ FF(c, d, a, b, in[6], S13, 2821735955u); /* 7 */
+ FF(b, c, d, a, in[7], S14, 4249261313u); /* 8 */
+ FF(a, b, c, d, in[8], S11, 1770035416u); /* 9 */
+ FF(d, a, b, c, in[9], S12, 2336552879u); /* 10 */
+ FF(c, d, a, b, in[10], S13, 4294925233u); /* 11 */
+ FF(b, c, d, a, in[11], S14, 2304563134u); /* 12 */
+ FF(a, b, c, d, in[12], S11, 1804603682u); /* 13 */
+ FF(d, a, b, c, in[13], S12, 4254626195u); /* 14 */
+ FF(c, d, a, b, in[14], S13, 2792965006u); /* 15 */
+ FF(b, c, d, a, in[15], S14, 1236535329u); /* 16 */
+
+ /*
+ * Round 2
+ */
+#define S21 5
+#define S22 9
+#define S23 14
+#define S24 20
+ GG(a, b, c, d, in[1], S21, 4129170786u); /* 17 */
+ GG(d, a, b, c, in[6], S22, 3225465664u); /* 18 */
+ GG(c, d, a, b, in[11], S23, 643717713u); /* 19 */
+ GG(b, c, d, a, in[0], S24, 3921069994u); /* 20 */
+ GG(a, b, c, d, in[5], S21, 3593408605u); /* 21 */
+ GG(d, a, b, c, in[10], S22, 38016083u); /* 22 */
+ GG(c, d, a, b, in[15], S23, 3634488961u); /* 23 */
+ GG(b, c, d, a, in[4], S24, 3889429448u); /* 24 */
+ GG(a, b, c, d, in[9], S21, 568446438u); /* 25 */
+ GG(d, a, b, c, in[14], S22, 3275163606u); /* 26 */
+ GG(c, d, a, b, in[3], S23, 4107603335u); /* 27 */
+ GG(b, c, d, a, in[8], S24, 1163531501u); /* 28 */
+ GG(a, b, c, d, in[13], S21, 2850285829u); /* 29 */
+ GG(d, a, b, c, in[2], S22, 4243563512u); /* 30 */
+ GG(c, d, a, b, in[7], S23, 1735328473u); /* 31 */
+ GG(b, c, d, a, in[12], S24, 2368359562u); /* 32 */
+
+ /*
+ * Round 3
+ */
+#define S31 4
+#define S32 11
+#define S33 16
+#define S34 23
+ HH(a, b, c, d, in[5], S31, 4294588738u); /* 33 */
+ HH(d, a, b, c, in[8], S32, 2272392833u); /* 34 */
+ HH(c, d, a, b, in[11], S33, 1839030562u); /* 35 */
+ HH(b, c, d, a, in[14], S34, 4259657740u); /* 36 */
+ HH(a, b, c, d, in[1], S31, 2763975236u); /* 37 */
+ HH(d, a, b, c, in[4], S32, 1272893353u); /* 38 */
+ HH(c, d, a, b, in[7], S33, 4139469664u); /* 39 */
+ HH(b, c, d, a, in[10], S34, 3200236656u); /* 40 */
+ HH(a, b, c, d, in[13], S31, 681279174u); /* 41 */
+ HH(d, a, b, c, in[0], S32, 3936430074u); /* 42 */
+ HH(c, d, a, b, in[3], S33, 3572445317u); /* 43 */
+ HH(b, c, d, a, in[6], S34, 76029189u); /* 44 */
+ HH(a, b, c, d, in[9], S31, 3654602809u); /* 45 */
+ HH(d, a, b, c, in[12], S32, 3873151461u); /* 46 */
+ HH(c, d, a, b, in[15], S33, 530742520u); /* 47 */
+ HH(b, c, d, a, in[2], S34, 3299628645u); /* 48 */
+
+ /*
+ * Round 4
+ */
+#define S41 6
+#define S42 10
+#define S43 15
+#define S44 21
+ II(a, b, c, d, in[0], S41, 4096336452u); /* 49 */
+ II(d, a, b, c, in[7], S42, 1126891415u); /* 50 */
+ II(c, d, a, b, in[14], S43, 2878612391u); /* 51 */
+ II(b, c, d, a, in[5], S44, 4237533241u); /* 52 */
+ II(a, b, c, d, in[12], S41, 1700485571u); /* 53 */
+ II(d, a, b, c, in[3], S42, 2399980690u); /* 54 */
+ II(c, d, a, b, in[10], S43, 4293915773u); /* 55 */
+ II(b, c, d, a, in[1], S44, 2240044497u); /* 56 */
+ II(a, b, c, d, in[8], S41, 1873313359u); /* 57 */
+ II(d, a, b, c, in[15], S42, 4264355552u); /* 58 */
+ II(c, d, a, b, in[6], S43, 2734768916u); /* 59 */
+ II(b, c, d, a, in[13], S44, 1309151649u); /* 60 */
+ II(a, b, c, d, in[4], S41, 4149444226u); /* 61 */
+ II(d, a, b, c, in[11], S42, 3174756917u); /* 62 */
+ II(c, d, a, b, in[2], S43, 718787259u); /* 63 */
+ II(b, c, d, a, in[9], S44, 3951481745u); /* 64 */
+
+ buf[0] += a;
+ buf[1] += b;
+ buf[2] += c;
+ buf[3] += d;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/test/SDL_test_memory.c b/src/3rdparty/SDL2/src/test/SDL_test_memory.c
new file mode 100644
index 0000000..6ce72f6
--- /dev/null
+++ b/src/3rdparty/SDL2/src/test/SDL_test_memory.c
@@ -0,0 +1,274 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+#include "SDL_assert.h"
+#include "SDL_stdinc.h"
+#include "SDL_log.h"
+#include "SDL_test_crc32.h"
+#include "SDL_test_memory.h"
+
+#ifdef HAVE_LIBUNWIND_H
+#include <libunwind.h>
+#endif
+
+/* This is a simple tracking allocator to demonstrate the use of SDL's
+ memory allocation replacement functionality.
+
+ It gets slow with large numbers of allocations and shouldn't be used
+ for production code.
+*/
+
+typedef struct SDL_tracked_allocation
+{
+ void *mem;
+ size_t size;
+ Uint64 stack[10];
+ char stack_names[10][256];
+ struct SDL_tracked_allocation *next;
+} SDL_tracked_allocation;
+
+static SDLTest_Crc32Context s_crc32_context;
+static SDL_malloc_func SDL_malloc_orig = NULL;
+static SDL_calloc_func SDL_calloc_orig = NULL;
+static SDL_realloc_func SDL_realloc_orig = NULL;
+static SDL_free_func SDL_free_orig = NULL;
+static int s_previous_allocations = 0;
+static SDL_tracked_allocation *s_tracked_allocations[256];
+
+static unsigned int get_allocation_bucket(void *mem)
+{
+ CrcUint32 crc_value;
+ unsigned int index;
+ SDLTest_Crc32Calc(&s_crc32_context, (CrcUint8 *)&mem, sizeof(mem), &crc_value);
+ index = (crc_value & (SDL_arraysize(s_tracked_allocations) - 1));
+ return index;
+}
+
+static SDL_bool SDL_IsAllocationTracked(void *mem)
+{
+ SDL_tracked_allocation *entry;
+ int index = get_allocation_bucket(mem);
+ for (entry = s_tracked_allocations[index]; entry; entry = entry->next) {
+ if (mem == entry->mem) {
+ return SDL_TRUE;
+ }
+ }
+ return SDL_FALSE;
+}
+
+static void SDL_TrackAllocation(void *mem, size_t size)
+{
+ SDL_tracked_allocation *entry;
+ int index = get_allocation_bucket(mem);
+
+ if (SDL_IsAllocationTracked(mem)) {
+ return;
+ }
+ entry = (SDL_tracked_allocation *)SDL_malloc_orig(sizeof(*entry));
+ if (!entry) {
+ return;
+ }
+ entry->mem = mem;
+ entry->size = size;
+
+ /* Generate the stack trace for the allocation */
+ SDL_zero(entry->stack);
+#ifdef HAVE_LIBUNWIND_H
+ {
+ int stack_index;
+ unw_cursor_t cursor;
+ unw_context_t context;
+
+ unw_getcontext(&context);
+ unw_init_local(&cursor, &context);
+
+ stack_index = 0;
+ while (unw_step(&cursor) > 0) {
+ unw_word_t offset, pc;
+ char sym[256];
+
+ unw_get_reg(&cursor, UNW_REG_IP, &pc);
+ entry->stack[stack_index] = pc;
+
+ if (unw_get_proc_name(&cursor, sym, sizeof(sym), &offset) == 0) {
+ snprintf(entry->stack_names[stack_index], sizeof(entry->stack_names[stack_index]), "%s+0x%llx", sym, offset);
+ }
+ ++stack_index;
+
+ if (stack_index == SDL_arraysize(entry->stack)) {
+ break;
+ }
+ }
+ }
+#endif /* HAVE_LIBUNWIND_H */
+
+ entry->next = s_tracked_allocations[index];
+ s_tracked_allocations[index] = entry;
+}
+
+static void SDL_UntrackAllocation(void *mem)
+{
+ SDL_tracked_allocation *entry, *prev;
+ int index = get_allocation_bucket(mem);
+
+ prev = NULL;
+ for (entry = s_tracked_allocations[index]; entry; entry = entry->next) {
+ if (mem == entry->mem) {
+ if (prev) {
+ prev->next = entry->next;
+ } else {
+ s_tracked_allocations[index] = entry->next;
+ }
+ SDL_free_orig(entry);
+ return;
+ }
+ prev = entry;
+ }
+}
+
+static void * SDLCALL SDLTest_TrackedMalloc(size_t size)
+{
+ void *mem;
+
+ mem = SDL_malloc_orig(size);
+ if (mem) {
+ SDL_TrackAllocation(mem, size);
+ }
+ return mem;
+}
+
+static void * SDLCALL SDLTest_TrackedCalloc(size_t nmemb, size_t size)
+{
+ void *mem;
+
+ mem = SDL_calloc_orig(nmemb, size);
+ if (mem) {
+ SDL_TrackAllocation(mem, nmemb * size);
+ }
+ return mem;
+}
+
+static void * SDLCALL SDLTest_TrackedRealloc(void *ptr, size_t size)
+{
+ void *mem;
+
+ SDL_assert(!ptr || SDL_IsAllocationTracked(ptr));
+ mem = SDL_realloc_orig(ptr, size);
+ if (mem && mem != ptr) {
+ if (ptr) {
+ SDL_UntrackAllocation(ptr);
+ }
+ SDL_TrackAllocation(mem, size);
+ }
+ return mem;
+}
+
+static void SDLCALL SDLTest_TrackedFree(void *ptr)
+{
+ if (!ptr) {
+ return;
+ }
+
+ if (!s_previous_allocations) {
+ SDL_assert(SDL_IsAllocationTracked(ptr));
+ }
+ SDL_UntrackAllocation(ptr);
+ SDL_free_orig(ptr);
+}
+
+int SDLTest_TrackAllocations()
+{
+ if (SDL_malloc_orig) {
+ return 0;
+ }
+
+ SDLTest_Crc32Init(&s_crc32_context);
+
+ s_previous_allocations = SDL_GetNumAllocations();
+ if (s_previous_allocations != 0) {
+ SDL_Log("SDLTest_TrackAllocations(): There are %d previous allocations, disabling free() validation", s_previous_allocations);
+ }
+
+ SDL_GetMemoryFunctions(&SDL_malloc_orig,
+ &SDL_calloc_orig,
+ &SDL_realloc_orig,
+ &SDL_free_orig);
+
+ SDL_SetMemoryFunctions(SDLTest_TrackedMalloc,
+ SDLTest_TrackedCalloc,
+ SDLTest_TrackedRealloc,
+ SDLTest_TrackedFree);
+ return 0;
+}
+
+void SDLTest_LogAllocations()
+{
+ char *message = NULL;
+ size_t message_size = 0;
+ char line[128], *tmp;
+ SDL_tracked_allocation *entry;
+ int index, count, stack_index;
+ Uint64 total_allocated;
+
+ if (!SDL_malloc_orig) {
+ return;
+ }
+
+#define ADD_LINE() \
+ message_size += (SDL_strlen(line) + 1); \
+ tmp = (char *)SDL_realloc_orig(message, message_size); \
+ if (!tmp) { \
+ return; \
+ } \
+ message = tmp; \
+ SDL_strlcat(message, line, message_size)
+
+ SDL_strlcpy(line, "Memory allocations:\n", sizeof(line));
+ ADD_LINE();
+ SDL_strlcpy(line, "Expect 2 allocations from within SDL_GetErrBuf()\n", sizeof(line));
+ ADD_LINE();
+
+ count = 0;
+ total_allocated = 0;
+ for (index = 0; index < SDL_arraysize(s_tracked_allocations); ++index) {
+ for (entry = s_tracked_allocations[index]; entry; entry = entry->next) {
+ SDL_snprintf(line, sizeof(line), "Allocation %d: %d bytes\n", count, (int)entry->size);
+ ADD_LINE();
+ /* Start at stack index 1 to skip our tracking functions */
+ for (stack_index = 1; stack_index < SDL_arraysize(entry->stack); ++stack_index) {
+ if (!entry->stack[stack_index]) {
+ break;
+ }
+ SDL_snprintf(line, sizeof(line), "\t0x%"SDL_PRIx64": %s\n", entry->stack[stack_index], entry->stack_names[stack_index]);
+ ADD_LINE();
+ }
+ total_allocated += entry->size;
+ ++count;
+ }
+ }
+ SDL_snprintf(line, sizeof(line), "Total: %.2f Kb in %d allocations\n", (float)total_allocated / 1024, count);
+ ADD_LINE();
+#undef ADD_LINE
+
+ SDL_Log("%s", message);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/test/SDL_test_random.c b/src/3rdparty/SDL2/src/test/SDL_test_random.c
new file mode 100644
index 0000000..9e0f1df
--- /dev/null
+++ b/src/3rdparty/SDL2/src/test/SDL_test_random.c
@@ -0,0 +1,96 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+
+ A portable "32-bit Multiply with carry" random number generator.
+
+ Used by the fuzzer component.
+ Original source code contributed by A. Schiffler for GSOC project.
+
+*/
+
+#include "SDL_config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+
+#include "SDL_test.h"
+
+/* Initialize random number generator with two integer variables */
+
+void SDLTest_RandomInit(SDLTest_RandomContext * rndContext, unsigned int xi, unsigned int ci)
+{
+ if (rndContext==NULL) return;
+
+ /*
+ * Choose a value for 'a' from this list
+ * 1791398085 1929682203 1683268614 1965537969 1675393560
+ * 1967773755 1517746329 1447497129 1655692410 1606218150
+ * 2051013963 1075433238 1557985959 1781943330 1893513180
+ * 1631296680 2131995753 2083801278 1873196400 1554115554
+ */
+ rndContext->a = 1655692410;
+ rndContext->x = 30903;
+ rndContext->c = 0;
+ if (xi != 0) {
+ rndContext->x = xi;
+ }
+ rndContext->c = ci;
+ rndContext->ah = rndContext->a >> 16;
+ rndContext->al = rndContext->a & 65535;
+}
+
+/* Initialize random number generator from system time */
+
+void SDLTest_RandomInitTime(SDLTest_RandomContext * rndContext)
+{
+ int a, b;
+
+ if (rndContext==NULL) return;
+
+ srand((unsigned int)time(NULL));
+ a=rand();
+ srand((unsigned int)clock());
+ b=rand();
+ SDLTest_RandomInit(rndContext, a, b);
+}
+
+/* Returns random numbers */
+
+unsigned int SDLTest_Random(SDLTest_RandomContext * rndContext)
+{
+ unsigned int xh, xl;
+
+ if (rndContext==NULL) return -1;
+
+ xh = rndContext->x >> 16, xl = rndContext->x & 65535;
+ rndContext->x = rndContext->x * rndContext->a + rndContext->c;
+ rndContext->c =
+ xh * rndContext->ah + ((xh * rndContext->al) >> 16) +
+ ((xl * rndContext->ah) >> 16);
+ if (xl * rndContext->al >= (~rndContext->c + 1))
+ rndContext->c++;
+ return (rndContext->x);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/SDL_systhread.h b/src/3rdparty/SDL2/src/thread/SDL_systhread.h
new file mode 100644
index 0000000..1862b23
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/SDL_systhread.h
@@ -0,0 +1,70 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* These are functions that need to be implemented by a port of SDL */
+
+#ifndef SDL_systhread_h_
+#define SDL_systhread_h_
+
+#include "SDL_thread.h"
+#include "SDL_thread_c.h"
+
+/* This function creates a thread, passing args to SDL_RunThread(),
+ saves a system-dependent thread id in thread->id, and returns 0
+ on success.
+*/
+#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
+extern int SDL_SYS_CreateThread(SDL_Thread * thread, void *args,
+ pfnSDL_CurrentBeginThread pfnBeginThread,
+ pfnSDL_CurrentEndThread pfnEndThread);
+#else
+extern int SDL_SYS_CreateThread(SDL_Thread * thread, void *args);
+#endif
+
+/* This function does any necessary setup in the child thread */
+extern void SDL_SYS_SetupThread(const char *name);
+
+/* This function sets the current thread priority */
+extern int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority);
+
+/* This function waits for the thread to finish and frees any data
+ allocated by SDL_SYS_CreateThread()
+ */
+extern void SDL_SYS_WaitThread(SDL_Thread * thread);
+
+/* Mark thread as cleaned up as soon as it exits, without joining. */
+extern void SDL_SYS_DetachThread(SDL_Thread * thread);
+
+/* Get the thread local storage for this thread */
+extern SDL_TLSData *SDL_SYS_GetTLSData(void);
+
+/* Set the thread local storage for this thread */
+extern int SDL_SYS_SetTLSData(SDL_TLSData *data);
+
+/* This is for internal SDL use, so we don't need #ifdefs everywhere. */
+extern SDL_Thread *
+SDL_CreateThreadInternal(int (SDLCALL * fn) (void *), const char *name,
+ const size_t stacksize, void *data);
+
+#endif /* SDL_systhread_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/SDL_thread.c b/src/3rdparty/SDL2/src/thread/SDL_thread.c
new file mode 100644
index 0000000..84b72d5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/SDL_thread.c
@@ -0,0 +1,503 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* System independent thread management routines for SDL */
+
+#include "SDL_assert.h"
+#include "SDL_thread.h"
+#include "SDL_thread_c.h"
+#include "SDL_systhread.h"
+#include "SDL_hints.h"
+#include "../SDL_error_c.h"
+
+
+SDL_TLSID
+SDL_TLSCreate()
+{
+ static SDL_atomic_t SDL_tls_id;
+ return SDL_AtomicIncRef(&SDL_tls_id)+1;
+}
+
+void *
+SDL_TLSGet(SDL_TLSID id)
+{
+ SDL_TLSData *storage;
+
+ storage = SDL_SYS_GetTLSData();
+ if (!storage || id == 0 || id > storage->limit) {
+ return NULL;
+ }
+ return storage->array[id-1].data;
+}
+
+int
+SDL_TLSSet(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void *))
+{
+ SDL_TLSData *storage;
+
+ if (id == 0) {
+ return SDL_InvalidParamError("id");
+ }
+
+ storage = SDL_SYS_GetTLSData();
+ if (!storage || (id > storage->limit)) {
+ unsigned int i, oldlimit, newlimit;
+
+ oldlimit = storage ? storage->limit : 0;
+ newlimit = (id + TLS_ALLOC_CHUNKSIZE);
+ storage = (SDL_TLSData *)SDL_realloc(storage, sizeof(*storage)+(newlimit-1)*sizeof(storage->array[0]));
+ if (!storage) {
+ return SDL_OutOfMemory();
+ }
+ storage->limit = newlimit;
+ for (i = oldlimit; i < newlimit; ++i) {
+ storage->array[i].data = NULL;
+ storage->array[i].destructor = NULL;
+ }
+ if (SDL_SYS_SetTLSData(storage) != 0) {
+ return -1;
+ }
+ }
+
+ storage->array[id-1].data = SDL_const_cast(void*, value);
+ storage->array[id-1].destructor = destructor;
+ return 0;
+}
+
+static void
+SDL_TLSCleanup()
+{
+ SDL_TLSData *storage;
+
+ storage = SDL_SYS_GetTLSData();
+ if (storage) {
+ unsigned int i;
+ for (i = 0; i < storage->limit; ++i) {
+ if (storage->array[i].destructor) {
+ storage->array[i].destructor(storage->array[i].data);
+ }
+ }
+ SDL_SYS_SetTLSData(NULL);
+ SDL_free(storage);
+ }
+}
+
+
+/* This is a generic implementation of thread-local storage which doesn't
+ require additional OS support.
+
+ It is not especially efficient and doesn't clean up thread-local storage
+ as threads exit. If there is a real OS that doesn't support thread-local
+ storage this implementation should be improved to be production quality.
+*/
+
+typedef struct SDL_TLSEntry {
+ SDL_threadID thread;
+ SDL_TLSData *storage;
+ struct SDL_TLSEntry *next;
+} SDL_TLSEntry;
+
+static SDL_mutex *SDL_generic_TLS_mutex;
+static SDL_TLSEntry *SDL_generic_TLS;
+
+
+SDL_TLSData *
+SDL_Generic_GetTLSData(void)
+{
+ SDL_threadID thread = SDL_ThreadID();
+ SDL_TLSEntry *entry;
+ SDL_TLSData *storage = NULL;
+
+#if !SDL_THREADS_DISABLED
+ if (!SDL_generic_TLS_mutex) {
+ static SDL_SpinLock tls_lock;
+ SDL_AtomicLock(&tls_lock);
+ if (!SDL_generic_TLS_mutex) {
+ SDL_mutex *mutex = SDL_CreateMutex();
+ SDL_MemoryBarrierRelease();
+ SDL_generic_TLS_mutex = mutex;
+ if (!SDL_generic_TLS_mutex) {
+ SDL_AtomicUnlock(&tls_lock);
+ return NULL;
+ }
+ }
+ SDL_AtomicUnlock(&tls_lock);
+ }
+#endif /* SDL_THREADS_DISABLED */
+
+ SDL_MemoryBarrierAcquire();
+ SDL_LockMutex(SDL_generic_TLS_mutex);
+ for (entry = SDL_generic_TLS; entry; entry = entry->next) {
+ if (entry->thread == thread) {
+ storage = entry->storage;
+ break;
+ }
+ }
+#if !SDL_THREADS_DISABLED
+ SDL_UnlockMutex(SDL_generic_TLS_mutex);
+#endif
+
+ return storage;
+}
+
+int
+SDL_Generic_SetTLSData(SDL_TLSData *storage)
+{
+ SDL_threadID thread = SDL_ThreadID();
+ SDL_TLSEntry *prev, *entry;
+
+ /* SDL_Generic_GetTLSData() is always called first, so we can assume SDL_generic_TLS_mutex */
+ SDL_LockMutex(SDL_generic_TLS_mutex);
+ prev = NULL;
+ for (entry = SDL_generic_TLS; entry; entry = entry->next) {
+ if (entry->thread == thread) {
+ if (storage) {
+ entry->storage = storage;
+ } else {
+ if (prev) {
+ prev->next = entry->next;
+ } else {
+ SDL_generic_TLS = entry->next;
+ }
+ SDL_free(entry);
+ }
+ break;
+ }
+ prev = entry;
+ }
+ if (!entry) {
+ entry = (SDL_TLSEntry *)SDL_malloc(sizeof(*entry));
+ if (entry) {
+ entry->thread = thread;
+ entry->storage = storage;
+ entry->next = SDL_generic_TLS;
+ SDL_generic_TLS = entry;
+ }
+ }
+ SDL_UnlockMutex(SDL_generic_TLS_mutex);
+
+ if (!entry) {
+ return SDL_OutOfMemory();
+ }
+ return 0;
+}
+
+/* Routine to get the thread-specific error variable */
+SDL_error *
+SDL_GetErrBuf(void)
+{
+ static SDL_SpinLock tls_lock;
+ static SDL_bool tls_being_created;
+ static SDL_TLSID tls_errbuf;
+ static SDL_error SDL_global_errbuf;
+ const SDL_error *ALLOCATION_IN_PROGRESS = (SDL_error *)-1;
+ SDL_error *errbuf;
+
+ /* tls_being_created is there simply to prevent recursion if SDL_TLSCreate() fails.
+ It also means it's possible for another thread to also use SDL_global_errbuf,
+ but that's very unlikely and hopefully won't cause issues.
+ */
+ if (!tls_errbuf && !tls_being_created) {
+ SDL_AtomicLock(&tls_lock);
+ if (!tls_errbuf) {
+ SDL_TLSID slot;
+ tls_being_created = SDL_TRUE;
+ slot = SDL_TLSCreate();
+ tls_being_created = SDL_FALSE;
+ SDL_MemoryBarrierRelease();
+ tls_errbuf = slot;
+ }
+ SDL_AtomicUnlock(&tls_lock);
+ }
+ if (!tls_errbuf) {
+ return &SDL_global_errbuf;
+ }
+
+ SDL_MemoryBarrierAcquire();
+ errbuf = (SDL_error *)SDL_TLSGet(tls_errbuf);
+ if (errbuf == ALLOCATION_IN_PROGRESS) {
+ return &SDL_global_errbuf;
+ }
+ if (!errbuf) {
+ /* Mark that we're in the middle of allocating our buffer */
+ SDL_TLSSet(tls_errbuf, ALLOCATION_IN_PROGRESS, NULL);
+ errbuf = (SDL_error *)SDL_malloc(sizeof(*errbuf));
+ if (!errbuf) {
+ SDL_TLSSet(tls_errbuf, NULL, NULL);
+ return &SDL_global_errbuf;
+ }
+ SDL_zerop(errbuf);
+ SDL_TLSSet(tls_errbuf, errbuf, SDL_free);
+ }
+ return errbuf;
+}
+
+
+/* Arguments and callback to setup and run the user thread function */
+typedef struct
+{
+ int (SDLCALL * func) (void *);
+ void *data;
+ SDL_Thread *info;
+ SDL_sem *wait;
+} thread_args;
+
+void
+SDL_RunThread(void *data)
+{
+ thread_args *args = (thread_args *) data;
+ int (SDLCALL * userfunc) (void *) = args->func;
+ void *userdata = args->data;
+ SDL_Thread *thread = args->info;
+ int *statusloc = &thread->status;
+
+ /* Perform any system-dependent setup - this function may not fail */
+ SDL_SYS_SetupThread(thread->name);
+
+ /* Get the thread id */
+ thread->threadid = SDL_ThreadID();
+
+ /* Wake up the parent thread */
+ SDL_SemPost(args->wait);
+
+ /* Run the function */
+ *statusloc = userfunc(userdata);
+
+ /* Clean up thread-local storage */
+ SDL_TLSCleanup();
+
+ /* Mark us as ready to be joined (or detached) */
+ if (!SDL_AtomicCAS(&thread->state, SDL_THREAD_STATE_ALIVE, SDL_THREAD_STATE_ZOMBIE)) {
+ /* Clean up if something already detached us. */
+ if (SDL_AtomicCAS(&thread->state, SDL_THREAD_STATE_DETACHED, SDL_THREAD_STATE_CLEANED)) {
+ if (thread->name) {
+ SDL_free(thread->name);
+ }
+ SDL_free(thread);
+ }
+ }
+}
+
+#ifdef SDL_CreateThread
+#undef SDL_CreateThread
+#endif
+#if SDL_DYNAMIC_API
+#define SDL_CreateThread SDL_CreateThread_REAL
+#endif
+
+#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
+static SDL_Thread *
+SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *),
+ const char *name, const size_t stacksize, void *data,
+ pfnSDL_CurrentBeginThread pfnBeginThread,
+ pfnSDL_CurrentEndThread pfnEndThread)
+#else
+static SDL_Thread *
+SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *),
+ const char *name, const size_t stacksize, void *data)
+#endif
+{
+ SDL_Thread *thread;
+ thread_args *args;
+ int ret;
+
+ /* Allocate memory for the thread info structure */
+ thread = (SDL_Thread *) SDL_malloc(sizeof(*thread));
+ if (thread == NULL) {
+ SDL_OutOfMemory();
+ return (NULL);
+ }
+ SDL_zerop(thread);
+ thread->status = -1;
+ SDL_AtomicSet(&thread->state, SDL_THREAD_STATE_ALIVE);
+
+ /* Set up the arguments for the thread */
+ if (name != NULL) {
+ thread->name = SDL_strdup(name);
+ if (thread->name == NULL) {
+ SDL_OutOfMemory();
+ SDL_free(thread);
+ return (NULL);
+ }
+ }
+
+ /* Set up the arguments for the thread */
+ args = (thread_args *) SDL_malloc(sizeof(*args));
+ if (args == NULL) {
+ SDL_OutOfMemory();
+ if (thread->name) {
+ SDL_free(thread->name);
+ }
+ SDL_free(thread);
+ return (NULL);
+ }
+ args->func = fn;
+ args->data = data;
+ args->info = thread;
+ args->wait = SDL_CreateSemaphore(0);
+ if (args->wait == NULL) {
+ if (thread->name) {
+ SDL_free(thread->name);
+ }
+ SDL_free(thread);
+ SDL_free(args);
+ return (NULL);
+ }
+
+ thread->stacksize = stacksize;
+
+ /* Create the thread and go! */
+#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
+ ret = SDL_SYS_CreateThread(thread, args, pfnBeginThread, pfnEndThread);
+#else
+ ret = SDL_SYS_CreateThread(thread, args);
+#endif
+ if (ret >= 0) {
+ /* Wait for the thread function to use arguments */
+ SDL_SemWait(args->wait);
+ } else {
+ /* Oops, failed. Gotta free everything */
+ if (thread->name) {
+ SDL_free(thread->name);
+ }
+ SDL_free(thread);
+ thread = NULL;
+ }
+ SDL_DestroySemaphore(args->wait);
+ SDL_free(args);
+
+ /* Everything is running now */
+ return (thread);
+}
+
+#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
+DECLSPEC SDL_Thread *SDLCALL
+SDL_CreateThread(int (SDLCALL * fn) (void *),
+ const char *name, void *data,
+ pfnSDL_CurrentBeginThread pfnBeginThread,
+ pfnSDL_CurrentEndThread pfnEndThread)
+#else
+DECLSPEC SDL_Thread *SDLCALL
+SDL_CreateThread(int (SDLCALL * fn) (void *),
+ const char *name, void *data)
+#endif
+{
+ /* !!! FIXME: in 2.1, just make stackhint part of the usual API. */
+ const char *stackhint = SDL_GetHint(SDL_HINT_THREAD_STACK_SIZE);
+ size_t stacksize = 0;
+
+ /* If the SDL_HINT_THREAD_STACK_SIZE exists, use it */
+ if (stackhint != NULL) {
+ char *endp = NULL;
+ const Sint64 hintval = SDL_strtoll(stackhint, &endp, 10);
+ if ((*stackhint != '\0') && (*endp == '\0')) { /* a valid number? */
+ if (hintval > 0) { /* reject bogus values. */
+ stacksize = (size_t) hintval;
+ }
+ }
+ }
+
+#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
+ return SDL_CreateThreadWithStackSize(fn, name, stacksize, data, pfnBeginThread, pfnEndThread);
+#else
+ return SDL_CreateThreadWithStackSize(fn, name, stacksize, data);
+#endif
+}
+
+SDL_Thread *
+SDL_CreateThreadInternal(int (SDLCALL * fn) (void *), const char *name,
+ const size_t stacksize, void *data) {
+#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
+ return SDL_CreateThreadWithStackSize(fn, name, stacksize, data, NULL, NULL);
+#else
+ return SDL_CreateThreadWithStackSize(fn, name, stacksize, data);
+#endif
+}
+
+SDL_threadID
+SDL_GetThreadID(SDL_Thread * thread)
+{
+ SDL_threadID id;
+
+ if (thread) {
+ id = thread->threadid;
+ } else {
+ id = SDL_ThreadID();
+ }
+ return id;
+}
+
+const char *
+SDL_GetThreadName(SDL_Thread * thread)
+{
+ if (thread) {
+ return thread->name;
+ } else {
+ return NULL;
+ }
+}
+
+int
+SDL_SetThreadPriority(SDL_ThreadPriority priority)
+{
+ return SDL_SYS_SetThreadPriority(priority);
+}
+
+void
+SDL_WaitThread(SDL_Thread * thread, int *status)
+{
+ if (thread) {
+ SDL_SYS_WaitThread(thread);
+ if (status) {
+ *status = thread->status;
+ }
+ if (thread->name) {
+ SDL_free(thread->name);
+ }
+ SDL_free(thread);
+ }
+}
+
+void
+SDL_DetachThread(SDL_Thread * thread)
+{
+ if (!thread) {
+ return;
+ }
+
+ /* Grab dibs if the state is alive+joinable. */
+ if (SDL_AtomicCAS(&thread->state, SDL_THREAD_STATE_ALIVE, SDL_THREAD_STATE_DETACHED)) {
+ SDL_SYS_DetachThread(thread);
+ } else {
+ /* all other states are pretty final, see where we landed. */
+ const int thread_state = SDL_AtomicGet(&thread->state);
+ if ((thread_state == SDL_THREAD_STATE_DETACHED) || (thread_state == SDL_THREAD_STATE_CLEANED)) {
+ return; /* already detached (you shouldn't call this twice!) */
+ } else if (thread_state == SDL_THREAD_STATE_ZOMBIE) {
+ SDL_WaitThread(thread, NULL); /* already done, clean it up. */
+ } else {
+ SDL_assert(0 && "Unexpected thread state");
+ }
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/SDL_thread_c.h b/src/3rdparty/SDL2/src/thread/SDL_thread_c.h
new file mode 100644
index 0000000..b68f90e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/SDL_thread_c.h
@@ -0,0 +1,95 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#ifndef SDL_thread_c_h_
+#define SDL_thread_c_h_
+
+#include "SDL_thread.h"
+
+/* Need the definitions of SYS_ThreadHandle */
+#if SDL_THREADS_DISABLED
+#include "generic/SDL_systhread_c.h"
+#elif SDL_THREAD_PTHREAD
+#include "pthread/SDL_systhread_c.h"
+#elif SDL_THREAD_WINDOWS
+#include "windows/SDL_systhread_c.h"
+#elif SDL_THREAD_PSP
+#include "psp/SDL_systhread_c.h"
+#elif SDL_THREAD_STDCPP
+#include "stdcpp/SDL_systhread_c.h"
+#else
+#error Need thread implementation for this platform
+#include "generic/SDL_systhread_c.h"
+#endif
+#include "../SDL_error_c.h"
+
+typedef enum SDL_ThreadState
+{
+ SDL_THREAD_STATE_ALIVE,
+ SDL_THREAD_STATE_DETACHED,
+ SDL_THREAD_STATE_ZOMBIE,
+ SDL_THREAD_STATE_CLEANED,
+} SDL_ThreadState;
+
+/* This is the system-independent thread info structure */
+struct SDL_Thread
+{
+ SDL_threadID threadid;
+ SYS_ThreadHandle handle;
+ int status;
+ SDL_atomic_t state; /* SDL_THREAD_STATE_* */
+ SDL_error errbuf;
+ char *name;
+ size_t stacksize; /* 0 for default, >0 for user-specified stack size. */
+ void *data;
+};
+
+/* This is the function called to run a thread */
+extern void SDL_RunThread(void *data);
+
+/* This is the system-independent thread local storage structure */
+typedef struct {
+ unsigned int limit;
+ struct {
+ void *data;
+ void (SDLCALL *destructor)(void*);
+ } array[1];
+} SDL_TLSData;
+
+/* This is how many TLS entries we allocate at once */
+#define TLS_ALLOC_CHUNKSIZE 4
+
+/* Get cross-platform, slow, thread local storage for this thread.
+ This is only intended as a fallback if getting real thread-local
+ storage fails or isn't supported on this platform.
+ */
+extern SDL_TLSData *SDL_Generic_GetTLSData(void);
+
+/* Set cross-platform, slow, thread local storage for this thread.
+ This is only intended as a fallback if getting real thread-local
+ storage fails or isn't supported on this platform.
+ */
+extern int SDL_Generic_SetTLSData(SDL_TLSData *data);
+
+#endif /* SDL_thread_c_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/generic/SDL_syscond.c b/src/3rdparty/SDL2/src/thread/generic/SDL_syscond.c
new file mode 100644
index 0000000..34b9893
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/generic/SDL_syscond.c
@@ -0,0 +1,220 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+/* An implementation of condition variables using semaphores and mutexes */
+/*
+ This implementation borrows heavily from the BeOS condition variable
+ implementation, written by Christopher Tate and Owen Smith. Thanks!
+ */
+
+#include "SDL_thread.h"
+
+struct SDL_cond
+{
+ SDL_mutex *lock;
+ int waiting;
+ int signals;
+ SDL_sem *wait_sem;
+ SDL_sem *wait_done;
+};
+
+/* Create a condition variable */
+SDL_cond *
+SDL_CreateCond(void)
+{
+ SDL_cond *cond;
+
+ cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
+ if (cond) {
+ cond->lock = SDL_CreateMutex();
+ cond->wait_sem = SDL_CreateSemaphore(0);
+ cond->wait_done = SDL_CreateSemaphore(0);
+ cond->waiting = cond->signals = 0;
+ if (!cond->lock || !cond->wait_sem || !cond->wait_done) {
+ SDL_DestroyCond(cond);
+ cond = NULL;
+ }
+ } else {
+ SDL_OutOfMemory();
+ }
+ return (cond);
+}
+
+/* Destroy a condition variable */
+void
+SDL_DestroyCond(SDL_cond * cond)
+{
+ if (cond) {
+ if (cond->wait_sem) {
+ SDL_DestroySemaphore(cond->wait_sem);
+ }
+ if (cond->wait_done) {
+ SDL_DestroySemaphore(cond->wait_done);
+ }
+ if (cond->lock) {
+ SDL_DestroyMutex(cond->lock);
+ }
+ SDL_free(cond);
+ }
+}
+
+/* Restart one of the threads that are waiting on the condition variable */
+int
+SDL_CondSignal(SDL_cond * cond)
+{
+ if (!cond) {
+ return SDL_SetError("Passed a NULL condition variable");
+ }
+
+ /* If there are waiting threads not already signalled, then
+ signal the condition and wait for the thread to respond.
+ */
+ SDL_LockMutex(cond->lock);
+ if (cond->waiting > cond->signals) {
+ ++cond->signals;
+ SDL_SemPost(cond->wait_sem);
+ SDL_UnlockMutex(cond->lock);
+ SDL_SemWait(cond->wait_done);
+ } else {
+ SDL_UnlockMutex(cond->lock);
+ }
+
+ return 0;
+}
+
+/* Restart all threads that are waiting on the condition variable */
+int
+SDL_CondBroadcast(SDL_cond * cond)
+{
+ if (!cond) {
+ return SDL_SetError("Passed a NULL condition variable");
+ }
+
+ /* If there are waiting threads not already signalled, then
+ signal the condition and wait for the thread to respond.
+ */
+ SDL_LockMutex(cond->lock);
+ if (cond->waiting > cond->signals) {
+ int i, num_waiting;
+
+ num_waiting = (cond->waiting - cond->signals);
+ cond->signals = cond->waiting;
+ for (i = 0; i < num_waiting; ++i) {
+ SDL_SemPost(cond->wait_sem);
+ }
+ /* Now all released threads are blocked here, waiting for us.
+ Collect them all (and win fabulous prizes!) :-)
+ */
+ SDL_UnlockMutex(cond->lock);
+ for (i = 0; i < num_waiting; ++i) {
+ SDL_SemWait(cond->wait_done);
+ }
+ } else {
+ SDL_UnlockMutex(cond->lock);
+ }
+
+ return 0;
+}
+
+/* Wait on the condition variable for at most 'ms' milliseconds.
+ The mutex must be locked before entering this function!
+ The mutex is unlocked during the wait, and locked again after the wait.
+
+Typical use:
+
+Thread A:
+ SDL_LockMutex(lock);
+ while ( ! condition ) {
+ SDL_CondWait(cond, lock);
+ }
+ SDL_UnlockMutex(lock);
+
+Thread B:
+ SDL_LockMutex(lock);
+ ...
+ condition = true;
+ ...
+ SDL_CondSignal(cond);
+ SDL_UnlockMutex(lock);
+ */
+int
+SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
+{
+ int retval;
+
+ if (!cond) {
+ return SDL_SetError("Passed a NULL condition variable");
+ }
+
+ /* Obtain the protection mutex, and increment the number of waiters.
+ This allows the signal mechanism to only perform a signal if there
+ are waiting threads.
+ */
+ SDL_LockMutex(cond->lock);
+ ++cond->waiting;
+ SDL_UnlockMutex(cond->lock);
+
+ /* Unlock the mutex, as is required by condition variable semantics */
+ SDL_UnlockMutex(mutex);
+
+ /* Wait for a signal */
+ if (ms == SDL_MUTEX_MAXWAIT) {
+ retval = SDL_SemWait(cond->wait_sem);
+ } else {
+ retval = SDL_SemWaitTimeout(cond->wait_sem, ms);
+ }
+
+ /* Let the signaler know we have completed the wait, otherwise
+ the signaler can race ahead and get the condition semaphore
+ if we are stopped between the mutex unlock and semaphore wait,
+ giving a deadlock. See the following URL for details:
+ http://web.archive.org/web/20010914175514/http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html#Workshop
+ */
+ SDL_LockMutex(cond->lock);
+ if (cond->signals > 0) {
+ /* If we timed out, we need to eat a condition signal */
+ if (retval > 0) {
+ SDL_SemWait(cond->wait_sem);
+ }
+ /* We always notify the signal thread that we are done */
+ SDL_SemPost(cond->wait_done);
+
+ /* Signal handshake complete */
+ --cond->signals;
+ }
+ --cond->waiting;
+ SDL_UnlockMutex(cond->lock);
+
+ /* Lock the mutex, as is required by condition variable semantics */
+ SDL_LockMutex(mutex);
+
+ return retval;
+}
+
+/* Wait on the condition variable forever */
+int
+SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
+{
+ return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/generic/SDL_sysmutex.c b/src/3rdparty/SDL2/src/thread/generic/SDL_sysmutex.c
new file mode 100644
index 0000000..df78ca9
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/generic/SDL_sysmutex.c
@@ -0,0 +1,165 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+/* An implementation of mutexes using semaphores */
+
+#include "SDL_thread.h"
+#include "SDL_systhread_c.h"
+
+
+struct SDL_mutex
+{
+ int recursive;
+ SDL_threadID owner;
+ SDL_sem *sem;
+};
+
+/* Create a mutex */
+SDL_mutex *
+SDL_CreateMutex(void)
+{
+ SDL_mutex *mutex;
+
+ /* Allocate mutex memory */
+ mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex));
+ if (mutex) {
+ /* Create the mutex semaphore, with initial value 1 */
+ mutex->sem = SDL_CreateSemaphore(1);
+ mutex->recursive = 0;
+ mutex->owner = 0;
+ if (!mutex->sem) {
+ SDL_free(mutex);
+ mutex = NULL;
+ }
+ } else {
+ SDL_OutOfMemory();
+ }
+ return mutex;
+}
+
+/* Free the mutex */
+void
+SDL_DestroyMutex(SDL_mutex * mutex)
+{
+ if (mutex) {
+ if (mutex->sem) {
+ SDL_DestroySemaphore(mutex->sem);
+ }
+ SDL_free(mutex);
+ }
+}
+
+/* Lock the mutex */
+int
+SDL_LockMutex(SDL_mutex * mutex)
+{
+#if SDL_THREADS_DISABLED
+ return 0;
+#else
+ SDL_threadID this_thread;
+
+ if (mutex == NULL) {
+ return SDL_SetError("Passed a NULL mutex");
+ }
+
+ this_thread = SDL_ThreadID();
+ if (mutex->owner == this_thread) {
+ ++mutex->recursive;
+ } else {
+ /* The order of operations is important.
+ We set the locking thread id after we obtain the lock
+ so unlocks from other threads will fail.
+ */
+ SDL_SemWait(mutex->sem);
+ mutex->owner = this_thread;
+ mutex->recursive = 0;
+ }
+
+ return 0;
+#endif /* SDL_THREADS_DISABLED */
+}
+
+/* try Lock the mutex */
+int
+SDL_TryLockMutex(SDL_mutex * mutex)
+{
+#if SDL_THREADS_DISABLED
+ return 0;
+#else
+ int retval = 0;
+ SDL_threadID this_thread;
+
+ if (mutex == NULL) {
+ return SDL_SetError("Passed a NULL mutex");
+ }
+
+ this_thread = SDL_ThreadID();
+ if (mutex->owner == this_thread) {
+ ++mutex->recursive;
+ } else {
+ /* The order of operations is important.
+ We set the locking thread id after we obtain the lock
+ so unlocks from other threads will fail.
+ */
+ retval = SDL_SemWait(mutex->sem);
+ if (retval == 0) {
+ mutex->owner = this_thread;
+ mutex->recursive = 0;
+ }
+ }
+
+ return retval;
+#endif /* SDL_THREADS_DISABLED */
+}
+
+/* Unlock the mutex */
+int
+SDL_mutexV(SDL_mutex * mutex)
+{
+#if SDL_THREADS_DISABLED
+ return 0;
+#else
+ if (mutex == NULL) {
+ return SDL_SetError("Passed a NULL mutex");
+ }
+
+ /* If we don't own the mutex, we can't unlock it */
+ if (SDL_ThreadID() != mutex->owner) {
+ return SDL_SetError("mutex not owned by this thread");
+ }
+
+ if (mutex->recursive) {
+ --mutex->recursive;
+ } else {
+ /* The order of operations is important.
+ First reset the owner so another thread doesn't lock
+ the mutex and set the ownership before we reset it,
+ then release the lock semaphore.
+ */
+ mutex->owner = 0;
+ SDL_SemPost(mutex->sem);
+ }
+ return 0;
+#endif /* SDL_THREADS_DISABLED */
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/generic/SDL_sysmutex_c.h b/src/3rdparty/SDL2/src/thread/generic/SDL_sysmutex_c.h
new file mode 100644
index 0000000..2979437
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/generic/SDL_sysmutex_c.h
@@ -0,0 +1,22 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/generic/SDL_syssem.c b/src/3rdparty/SDL2/src/thread/generic/SDL_syssem.c
new file mode 100644
index 0000000..30ff824
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/generic/SDL_syssem.c
@@ -0,0 +1,217 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+/* An implementation of semaphores using mutexes and condition variables */
+
+#include "SDL_timer.h"
+#include "SDL_thread.h"
+#include "SDL_systhread_c.h"
+
+
+#if SDL_THREADS_DISABLED
+
+SDL_sem *
+SDL_CreateSemaphore(Uint32 initial_value)
+{
+ SDL_SetError("SDL not built with thread support");
+ return (SDL_sem *) 0;
+}
+
+void
+SDL_DestroySemaphore(SDL_sem * sem)
+{
+}
+
+int
+SDL_SemTryWait(SDL_sem * sem)
+{
+ return SDL_SetError("SDL not built with thread support");
+}
+
+int
+SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
+{
+ return SDL_SetError("SDL not built with thread support");
+}
+
+int
+SDL_SemWait(SDL_sem * sem)
+{
+ return SDL_SetError("SDL not built with thread support");
+}
+
+Uint32
+SDL_SemValue(SDL_sem * sem)
+{
+ return 0;
+}
+
+int
+SDL_SemPost(SDL_sem * sem)
+{
+ return SDL_SetError("SDL not built with thread support");
+}
+
+#else
+
+struct SDL_semaphore
+{
+ Uint32 count;
+ Uint32 waiters_count;
+ SDL_mutex *count_lock;
+ SDL_cond *count_nonzero;
+};
+
+SDL_sem *
+SDL_CreateSemaphore(Uint32 initial_value)
+{
+ SDL_sem *sem;
+
+ sem = (SDL_sem *) SDL_malloc(sizeof(*sem));
+ if (!sem) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ sem->count = initial_value;
+ sem->waiters_count = 0;
+
+ sem->count_lock = SDL_CreateMutex();
+ sem->count_nonzero = SDL_CreateCond();
+ if (!sem->count_lock || !sem->count_nonzero) {
+ SDL_DestroySemaphore(sem);
+ return NULL;
+ }
+
+ return sem;
+}
+
+/* WARNING:
+ You cannot call this function when another thread is using the semaphore.
+*/
+void
+SDL_DestroySemaphore(SDL_sem * sem)
+{
+ if (sem) {
+ sem->count = 0xFFFFFFFF;
+ while (sem->waiters_count > 0) {
+ SDL_CondSignal(sem->count_nonzero);
+ SDL_Delay(10);
+ }
+ SDL_DestroyCond(sem->count_nonzero);
+ if (sem->count_lock) {
+ SDL_LockMutex(sem->count_lock);
+ SDL_UnlockMutex(sem->count_lock);
+ SDL_DestroyMutex(sem->count_lock);
+ }
+ SDL_free(sem);
+ }
+}
+
+int
+SDL_SemTryWait(SDL_sem * sem)
+{
+ int retval;
+
+ if (!sem) {
+ return SDL_SetError("Passed a NULL semaphore");
+ }
+
+ retval = SDL_MUTEX_TIMEDOUT;
+ SDL_LockMutex(sem->count_lock);
+ if (sem->count > 0) {
+ --sem->count;
+ retval = 0;
+ }
+ SDL_UnlockMutex(sem->count_lock);
+
+ return retval;
+}
+
+int
+SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
+{
+ int retval;
+
+ if (!sem) {
+ return SDL_SetError("Passed a NULL semaphore");
+ }
+
+ /* A timeout of 0 is an easy case */
+ if (timeout == 0) {
+ return SDL_SemTryWait(sem);
+ }
+
+ SDL_LockMutex(sem->count_lock);
+ ++sem->waiters_count;
+ retval = 0;
+ while ((sem->count == 0) && (retval != SDL_MUTEX_TIMEDOUT)) {
+ retval = SDL_CondWaitTimeout(sem->count_nonzero,
+ sem->count_lock, timeout);
+ }
+ --sem->waiters_count;
+ if (retval == 0) {
+ --sem->count;
+ }
+ SDL_UnlockMutex(sem->count_lock);
+
+ return retval;
+}
+
+int
+SDL_SemWait(SDL_sem * sem)
+{
+ return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
+}
+
+Uint32
+SDL_SemValue(SDL_sem * sem)
+{
+ Uint32 value;
+
+ value = 0;
+ if (sem) {
+ SDL_LockMutex(sem->count_lock);
+ value = sem->count;
+ SDL_UnlockMutex(sem->count_lock);
+ }
+ return value;
+}
+
+int
+SDL_SemPost(SDL_sem * sem)
+{
+ if (!sem) {
+ return SDL_SetError("Passed a NULL semaphore");
+ }
+
+ SDL_LockMutex(sem->count_lock);
+ if (sem->waiters_count > 0) {
+ SDL_CondSignal(sem->count_nonzero);
+ }
+ ++sem->count;
+ SDL_UnlockMutex(sem->count_lock);
+
+ return 0;
+}
+
+#endif /* SDL_THREADS_DISABLED */
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/generic/SDL_systhread.c b/src/3rdparty/SDL2/src/thread/generic/SDL_systhread.c
new file mode 100644
index 0000000..7a19b78
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/generic/SDL_systhread.c
@@ -0,0 +1,71 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+/* Thread management routines for SDL */
+
+#include "SDL_thread.h"
+#include "../SDL_systhread.h"
+
+#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
+int
+SDL_SYS_CreateThread(SDL_Thread * thread, void *args,
+ pfnSDL_CurrentBeginThread pfnBeginThread,
+ pfnSDL_CurrentEndThread pfnEndThread)
+#else
+int
+SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
+#endif /* SDL_PASSED_BEGINTHREAD_ENDTHREAD */
+{
+ return SDL_SetError("Threads are not supported on this platform");
+}
+
+void
+SDL_SYS_SetupThread(const char *name)
+{
+ return;
+}
+
+SDL_threadID
+SDL_ThreadID(void)
+{
+ return (0);
+}
+
+int
+SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
+{
+ return (0);
+}
+
+void
+SDL_SYS_WaitThread(SDL_Thread * thread)
+{
+ return;
+}
+
+void
+SDL_SYS_DetachThread(SDL_Thread * thread)
+{
+ return;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/generic/SDL_systhread_c.h b/src/3rdparty/SDL2/src/thread/generic/SDL_systhread_c.h
new file mode 100644
index 0000000..13db579
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/generic/SDL_systhread_c.h
@@ -0,0 +1,26 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+/* Stub until we implement threads on this platform */
+typedef int SYS_ThreadHandle;
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/generic/SDL_systls.c b/src/3rdparty/SDL2/src/thread/generic/SDL_systls.c
new file mode 100644
index 0000000..241862e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/generic/SDL_systls.c
@@ -0,0 +1,38 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+#include "../SDL_thread_c.h"
+
+
+SDL_TLSData *
+SDL_SYS_GetTLSData(void)
+{
+ return SDL_Generic_GetTLSData();
+}
+
+int
+SDL_SYS_SetTLSData(SDL_TLSData *data)
+{
+ return SDL_Generic_SetTLSData(data);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/psp/SDL_syscond.c b/src/3rdparty/SDL2/src/thread/psp/SDL_syscond.c
new file mode 100644
index 0000000..4ed73e0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/psp/SDL_syscond.c
@@ -0,0 +1,224 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_THREAD_PSP
+
+/* An implementation of condition variables using semaphores and mutexes */
+/*
+ This implementation borrows heavily from the BeOS condition variable
+ implementation, written by Christopher Tate and Owen Smith. Thanks!
+ */
+
+#include "SDL_thread.h"
+
+struct SDL_cond
+{
+ SDL_mutex *lock;
+ int waiting;
+ int signals;
+ SDL_sem *wait_sem;
+ SDL_sem *wait_done;
+};
+
+/* Create a condition variable */
+SDL_cond *
+SDL_CreateCond(void)
+{
+ SDL_cond *cond;
+
+ cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
+ if (cond) {
+ cond->lock = SDL_CreateMutex();
+ cond->wait_sem = SDL_CreateSemaphore(0);
+ cond->wait_done = SDL_CreateSemaphore(0);
+ cond->waiting = cond->signals = 0;
+ if (!cond->lock || !cond->wait_sem || !cond->wait_done) {
+ SDL_DestroyCond(cond);
+ cond = NULL;
+ }
+ } else {
+ SDL_OutOfMemory();
+ }
+ return (cond);
+}
+
+/* Destroy a condition variable */
+void
+SDL_DestroyCond(SDL_cond * cond)
+{
+ if (cond) {
+ if (cond->wait_sem) {
+ SDL_DestroySemaphore(cond->wait_sem);
+ }
+ if (cond->wait_done) {
+ SDL_DestroySemaphore(cond->wait_done);
+ }
+ if (cond->lock) {
+ SDL_DestroyMutex(cond->lock);
+ }
+ SDL_free(cond);
+ }
+}
+
+/* Restart one of the threads that are waiting on the condition variable */
+int
+SDL_CondSignal(SDL_cond * cond)
+{
+ if (!cond) {
+ return SDL_SetError("Passed a NULL condition variable");
+ }
+
+ /* If there are waiting threads not already signalled, then
+ signal the condition and wait for the thread to respond.
+ */
+ SDL_LockMutex(cond->lock);
+ if (cond->waiting > cond->signals) {
+ ++cond->signals;
+ SDL_SemPost(cond->wait_sem);
+ SDL_UnlockMutex(cond->lock);
+ SDL_SemWait(cond->wait_done);
+ } else {
+ SDL_UnlockMutex(cond->lock);
+ }
+
+ return 0;
+}
+
+/* Restart all threads that are waiting on the condition variable */
+int
+SDL_CondBroadcast(SDL_cond * cond)
+{
+ if (!cond) {
+ return SDL_SetError("Passed a NULL condition variable");
+ }
+
+ /* If there are waiting threads not already signalled, then
+ signal the condition and wait for the thread to respond.
+ */
+ SDL_LockMutex(cond->lock);
+ if (cond->waiting > cond->signals) {
+ int i, num_waiting;
+
+ num_waiting = (cond->waiting - cond->signals);
+ cond->signals = cond->waiting;
+ for (i = 0; i < num_waiting; ++i) {
+ SDL_SemPost(cond->wait_sem);
+ }
+ /* Now all released threads are blocked here, waiting for us.
+ Collect them all (and win fabulous prizes!) :-)
+ */
+ SDL_UnlockMutex(cond->lock);
+ for (i = 0; i < num_waiting; ++i) {
+ SDL_SemWait(cond->wait_done);
+ }
+ } else {
+ SDL_UnlockMutex(cond->lock);
+ }
+
+ return 0;
+}
+
+/* Wait on the condition variable for at most 'ms' milliseconds.
+ The mutex must be locked before entering this function!
+ The mutex is unlocked during the wait, and locked again after the wait.
+
+Typical use:
+
+Thread A:
+ SDL_LockMutex(lock);
+ while ( ! condition ) {
+ SDL_CondWait(cond, lock);
+ }
+ SDL_UnlockMutex(lock);
+
+Thread B:
+ SDL_LockMutex(lock);
+ ...
+ condition = true;
+ ...
+ SDL_CondSignal(cond);
+ SDL_UnlockMutex(lock);
+ */
+int
+SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
+{
+ int retval;
+
+ if (!cond) {
+ return SDL_SetError("Passed a NULL condition variable");
+ }
+
+ /* Obtain the protection mutex, and increment the number of waiters.
+ This allows the signal mechanism to only perform a signal if there
+ are waiting threads.
+ */
+ SDL_LockMutex(cond->lock);
+ ++cond->waiting;
+ SDL_UnlockMutex(cond->lock);
+
+ /* Unlock the mutex, as is required by condition variable semantics */
+ SDL_UnlockMutex(mutex);
+
+ /* Wait for a signal */
+ if (ms == SDL_MUTEX_MAXWAIT) {
+ retval = SDL_SemWait(cond->wait_sem);
+ } else {
+ retval = SDL_SemWaitTimeout(cond->wait_sem, ms);
+ }
+
+ /* Let the signaler know we have completed the wait, otherwise
+ the signaler can race ahead and get the condition semaphore
+ if we are stopped between the mutex unlock and semaphore wait,
+ giving a deadlock. See the following URL for details:
+ http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue40.html
+ */
+ SDL_LockMutex(cond->lock);
+ if (cond->signals > 0) {
+ /* If we timed out, we need to eat a condition signal */
+ if (retval > 0) {
+ SDL_SemWait(cond->wait_sem);
+ }
+ /* We always notify the signal thread that we are done */
+ SDL_SemPost(cond->wait_done);
+
+ /* Signal handshake complete */
+ --cond->signals;
+ }
+ --cond->waiting;
+ SDL_UnlockMutex(cond->lock);
+
+ /* Lock the mutex, as is required by condition variable semantics */
+ SDL_LockMutex(mutex);
+
+ return retval;
+}
+
+/* Wait on the condition variable forever */
+int
+SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
+{
+ return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT);
+}
+
+#endif /* SDL_THREAD_PSP */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/psp/SDL_sysmutex.c b/src/3rdparty/SDL2/src/thread/psp/SDL_sysmutex.c
new file mode 100644
index 0000000..e2db5eb
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/psp/SDL_sysmutex.c
@@ -0,0 +1,136 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_THREAD_PSP
+
+/* An implementation of mutexes using semaphores */
+
+#include "SDL_thread.h"
+#include "SDL_systhread_c.h"
+
+
+struct SDL_mutex
+{
+ int recursive;
+ SDL_threadID owner;
+ SDL_sem *sem;
+};
+
+/* Create a mutex */
+SDL_mutex *
+SDL_CreateMutex(void)
+{
+ SDL_mutex *mutex;
+
+ /* Allocate mutex memory */
+ mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex));
+ if (mutex) {
+ /* Create the mutex semaphore, with initial value 1 */
+ mutex->sem = SDL_CreateSemaphore(1);
+ mutex->recursive = 0;
+ mutex->owner = 0;
+ if (!mutex->sem) {
+ SDL_free(mutex);
+ mutex = NULL;
+ }
+ } else {
+ SDL_OutOfMemory();
+ }
+ return mutex;
+}
+
+/* Free the mutex */
+void
+SDL_DestroyMutex(SDL_mutex * mutex)
+{
+ if (mutex) {
+ if (mutex->sem) {
+ SDL_DestroySemaphore(mutex->sem);
+ }
+ SDL_free(mutex);
+ }
+}
+
+/* Lock the semaphore */
+int
+SDL_mutexP(SDL_mutex * mutex)
+{
+#if SDL_THREADS_DISABLED
+ return 0;
+#else
+ SDL_threadID this_thread;
+
+ if (mutex == NULL) {
+ return SDL_SetError("Passed a NULL mutex");
+ }
+
+ this_thread = SDL_ThreadID();
+ if (mutex->owner == this_thread) {
+ ++mutex->recursive;
+ } else {
+ /* The order of operations is important.
+ We set the locking thread id after we obtain the lock
+ so unlocks from other threads will fail.
+ */
+ SDL_SemWait(mutex->sem);
+ mutex->owner = this_thread;
+ mutex->recursive = 0;
+ }
+
+ return 0;
+#endif /* SDL_THREADS_DISABLED */
+}
+
+/* Unlock the mutex */
+int
+SDL_mutexV(SDL_mutex * mutex)
+{
+#if SDL_THREADS_DISABLED
+ return 0;
+#else
+ if (mutex == NULL) {
+ return SDL_SetError("Passed a NULL mutex");
+ }
+
+ /* If we don't own the mutex, we can't unlock it */
+ if (SDL_ThreadID() != mutex->owner) {
+ return SDL_SetError("mutex not owned by this thread");
+ }
+
+ if (mutex->recursive) {
+ --mutex->recursive;
+ } else {
+ /* The order of operations is important.
+ First reset the owner so another thread doesn't lock
+ the mutex and set the ownership before we reset it,
+ then release the lock semaphore.
+ */
+ mutex->owner = 0;
+ SDL_SemPost(mutex->sem);
+ }
+ return 0;
+#endif /* SDL_THREADS_DISABLED */
+}
+
+#endif /* SDL_THREAD_PSP */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/psp/SDL_sysmutex_c.h b/src/3rdparty/SDL2/src/thread/psp/SDL_sysmutex_c.h
new file mode 100644
index 0000000..2979437
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/psp/SDL_sysmutex_c.h
@@ -0,0 +1,22 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/psp/SDL_syssem.c b/src/3rdparty/SDL2/src/thread/psp/SDL_syssem.c
new file mode 100644
index 0000000..0c36434
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/psp/SDL_syssem.c
@@ -0,0 +1,161 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_THREAD_PSP
+
+/* Semaphore functions for the PSP. */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "SDL_error.h"
+#include "SDL_thread.h"
+
+#include <pspthreadman.h>
+#include <pspkerror.h>
+
+struct SDL_semaphore {
+ SceUID semid;
+};
+
+
+/* Create a semaphore */
+SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
+{
+ SDL_sem *sem;
+
+ sem = (SDL_sem *) malloc(sizeof(*sem));
+ if (sem != NULL) {
+ /* TODO: Figure out the limit on the maximum value. */
+ sem->semid = sceKernelCreateSema("SDL sema", 0, initial_value, 255, NULL);
+ if (sem->semid < 0) {
+ SDL_SetError("Couldn't create semaphore");
+ free(sem);
+ sem = NULL;
+ }
+ } else {
+ SDL_OutOfMemory();
+ }
+
+ return sem;
+}
+
+/* Free the semaphore */
+void SDL_DestroySemaphore(SDL_sem *sem)
+{
+ if (sem != NULL) {
+ if (sem->semid > 0) {
+ sceKernelDeleteSema(sem->semid);
+ sem->semid = 0;
+ }
+
+ free(sem);
+ }
+}
+
+/* TODO: This routine is a bit overloaded.
+ * If the timeout is 0 then just poll the semaphore; if it's SDL_MUTEX_MAXWAIT, pass
+ * NULL to sceKernelWaitSema() so that it waits indefinitely; and if the timeout
+ * is specified, convert it to microseconds. */
+int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
+{
+ Uint32 *pTimeout;
+ int res;
+
+ if (sem == NULL) {
+ SDL_SetError("Passed a NULL sem");
+ return 0;
+ }
+
+ if (timeout == 0) {
+ res = sceKernelPollSema(sem->semid, 1);
+ if (res < 0) {
+ return SDL_MUTEX_TIMEDOUT;
+ }
+ return 0;
+ }
+
+ if (timeout == SDL_MUTEX_MAXWAIT) {
+ pTimeout = NULL;
+ } else {
+ timeout *= 1000; /* Convert to microseconds. */
+ pTimeout = &timeout;
+ }
+
+ res = sceKernelWaitSema(sem->semid, 1, pTimeout);
+ switch (res) {
+ case SCE_KERNEL_ERROR_OK:
+ return 0;
+ case SCE_KERNEL_ERROR_WAIT_TIMEOUT:
+ return SDL_MUTEX_TIMEDOUT;
+ default:
+ return SDL_SetError("sceKernelWaitSema() failed");
+ }
+}
+
+int SDL_SemTryWait(SDL_sem *sem)
+{
+ return SDL_SemWaitTimeout(sem, 0);
+}
+
+int SDL_SemWait(SDL_sem *sem)
+{
+ return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
+}
+
+/* Returns the current count of the semaphore */
+Uint32 SDL_SemValue(SDL_sem *sem)
+{
+ SceKernelSemaInfo info;
+
+ if (sem == NULL) {
+ SDL_SetError("Passed a NULL sem");
+ return 0;
+ }
+
+ if (sceKernelReferSemaStatus(sem->semid, &info) >= 0) {
+ return info.currentCount;
+ }
+
+ return 0;
+}
+
+int SDL_SemPost(SDL_sem *sem)
+{
+ int res;
+
+ if (sem == NULL) {
+ return SDL_SetError("Passed a NULL sem");
+ }
+
+ res = sceKernelSignalSema(sem->semid, 1);
+ if (res < 0) {
+ return SDL_SetError("sceKernelSignalSema() failed");
+ }
+
+ return 0;
+}
+
+#endif /* SDL_THREAD_PSP */
+
+/* vim: ts=4 sw=4
+ */
diff --git a/src/3rdparty/SDL2/src/thread/psp/SDL_systhread.c b/src/3rdparty/SDL2/src/thread/psp/SDL_systhread.c
new file mode 100644
index 0000000..9286be5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/psp/SDL_systhread.c
@@ -0,0 +1,112 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_THREAD_PSP
+
+/* PSP thread management routines for SDL */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "SDL_error.h"
+#include "SDL_thread.h"
+#include "../SDL_systhread.h"
+#include "../SDL_thread_c.h"
+#include <pspkerneltypes.h>
+#include <pspthreadman.h>
+
+
+static int ThreadEntry(SceSize args, void *argp)
+{
+ SDL_RunThread(*(void **) argp);
+ return 0;
+}
+
+int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
+{
+ SceKernelThreadInfo status;
+ int priority = 32;
+
+ /* Set priority of new thread to the same as the current thread */
+ status.size = sizeof(SceKernelThreadInfo);
+ if (sceKernelReferThreadStatus(sceKernelGetThreadId(), &status) == 0) {
+ priority = status.currentPriority;
+ }
+
+ thread->handle = sceKernelCreateThread(thread->name, ThreadEntry,
+ priority, thread->stacksize ? ((int) thread->stacksize) : 0x8000,
+ PSP_THREAD_ATTR_VFPU, NULL);
+ if (thread->handle < 0) {
+ return SDL_SetError("sceKernelCreateThread() failed");
+ }
+
+ sceKernelStartThread(thread->handle, 4, &args);
+ return 0;
+}
+
+void SDL_SYS_SetupThread(const char *name)
+{
+ /* Do nothing. */
+}
+
+SDL_threadID SDL_ThreadID(void)
+{
+ return (SDL_threadID) sceKernelGetThreadId();
+}
+
+void SDL_SYS_WaitThread(SDL_Thread *thread)
+{
+ sceKernelWaitThreadEnd(thread->handle, NULL);
+ sceKernelDeleteThread(thread->handle);
+}
+
+void SDL_SYS_DetachThread(SDL_Thread *thread)
+{
+ /* !!! FIXME: is this correct? */
+ sceKernelDeleteThread(thread->handle);
+}
+
+void SDL_SYS_KillThread(SDL_Thread *thread)
+{
+ sceKernelTerminateDeleteThread(thread->handle);
+}
+
+int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
+{
+ int value;
+
+ if (priority == SDL_THREAD_PRIORITY_LOW) {
+ value = 19;
+ } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
+ value = -20;
+ } else {
+ value = 0;
+ }
+
+ return sceKernelChangeThreadPriority(sceKernelGetThreadId(),value);
+
+}
+
+#endif /* SDL_THREAD_PSP */
+
+/* vim: ts=4 sw=4
+ */
diff --git a/src/3rdparty/SDL2/src/thread/psp/SDL_systhread_c.h b/src/3rdparty/SDL2/src/thread/psp/SDL_systhread_c.h
new file mode 100644
index 0000000..ea26f81
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/psp/SDL_systhread_c.h
@@ -0,0 +1,24 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include <pspkerneltypes.h>
+
+typedef SceUID SYS_ThreadHandle;
diff --git a/src/3rdparty/SDL2/src/thread/pthread/SDL_syscond.c b/src/3rdparty/SDL2/src/thread/pthread/SDL_syscond.c
new file mode 100644
index 0000000..d235780
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/pthread/SDL_syscond.c
@@ -0,0 +1,158 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include <sys/time.h>
+#include <time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <pthread.h>
+
+#include "SDL_thread.h"
+#include "SDL_sysmutex_c.h"
+
+struct SDL_cond
+{
+ pthread_cond_t cond;
+};
+
+/* Create a condition variable */
+SDL_cond *
+SDL_CreateCond(void)
+{
+ SDL_cond *cond;
+
+ cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
+ if (cond) {
+ if (pthread_cond_init(&cond->cond, NULL) != 0) {
+ SDL_SetError("pthread_cond_init() failed");
+ SDL_free(cond);
+ cond = NULL;
+ }
+ }
+ return (cond);
+}
+
+/* Destroy a condition variable */
+void
+SDL_DestroyCond(SDL_cond * cond)
+{
+ if (cond) {
+ pthread_cond_destroy(&cond->cond);
+ SDL_free(cond);
+ }
+}
+
+/* Restart one of the threads that are waiting on the condition variable */
+int
+SDL_CondSignal(SDL_cond * cond)
+{
+ int retval;
+
+ if (!cond) {
+ return SDL_SetError("Passed a NULL condition variable");
+ }
+
+ retval = 0;
+ if (pthread_cond_signal(&cond->cond) != 0) {
+ return SDL_SetError("pthread_cond_signal() failed");
+ }
+ return retval;
+}
+
+/* Restart all threads that are waiting on the condition variable */
+int
+SDL_CondBroadcast(SDL_cond * cond)
+{
+ int retval;
+
+ if (!cond) {
+ return SDL_SetError("Passed a NULL condition variable");
+ }
+
+ retval = 0;
+ if (pthread_cond_broadcast(&cond->cond) != 0) {
+ return SDL_SetError("pthread_cond_broadcast() failed");
+ }
+ return retval;
+}
+
+int
+SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
+{
+ int retval;
+#ifndef HAVE_CLOCK_GETTIME
+ struct timeval delta;
+#endif
+ struct timespec abstime;
+
+ if (!cond) {
+ return SDL_SetError("Passed a NULL condition variable");
+ }
+
+#ifdef HAVE_CLOCK_GETTIME
+ clock_gettime(CLOCK_REALTIME, &abstime);
+
+ abstime.tv_nsec += (ms % 1000) * 1000000;
+ abstime.tv_sec += ms / 1000;
+#else
+ gettimeofday(&delta, NULL);
+
+ abstime.tv_sec = delta.tv_sec + (ms / 1000);
+ abstime.tv_nsec = (delta.tv_usec + (ms % 1000) * 1000) * 1000;
+#endif
+ if (abstime.tv_nsec > 1000000000) {
+ abstime.tv_sec += 1;
+ abstime.tv_nsec -= 1000000000;
+ }
+
+ tryagain:
+ retval = pthread_cond_timedwait(&cond->cond, &mutex->id, &abstime);
+ switch (retval) {
+ case EINTR:
+ goto tryagain;
+ /* break; -Wunreachable-code-break */
+ case ETIMEDOUT:
+ retval = SDL_MUTEX_TIMEDOUT;
+ break;
+ case 0:
+ break;
+ default:
+ retval = SDL_SetError("pthread_cond_timedwait() failed");
+ }
+ return retval;
+}
+
+/* Wait on the condition variable, unlocking the provided mutex.
+ The mutex must be locked before entering this function!
+ */
+int
+SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
+{
+ if (!cond) {
+ return SDL_SetError("Passed a NULL condition variable");
+ } else if (pthread_cond_wait(&cond->cond, &mutex->id) != 0) {
+ return SDL_SetError("pthread_cond_wait() failed");
+ }
+ return 0;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/pthread/SDL_sysmutex.c b/src/3rdparty/SDL2/src/thread/pthread/SDL_sysmutex.c
new file mode 100644
index 0000000..e7b5b5c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/pthread/SDL_sysmutex.c
@@ -0,0 +1,192 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include <errno.h>
+#include <pthread.h>
+
+#include "SDL_thread.h"
+
+#if !SDL_THREAD_PTHREAD_RECURSIVE_MUTEX && \
+ !SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP
+#define FAKE_RECURSIVE_MUTEX 1
+#endif
+
+struct SDL_mutex
+{
+ pthread_mutex_t id;
+#if FAKE_RECURSIVE_MUTEX
+ int recursive;
+ pthread_t owner;
+#endif
+};
+
+SDL_mutex *
+SDL_CreateMutex(void)
+{
+ SDL_mutex *mutex;
+ pthread_mutexattr_t attr;
+
+ /* Allocate the structure */
+ mutex = (SDL_mutex *) SDL_calloc(1, sizeof(*mutex));
+ if (mutex) {
+ pthread_mutexattr_init(&attr);
+#if SDL_THREAD_PTHREAD_RECURSIVE_MUTEX
+ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+#elif SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP
+ pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
+#else
+ /* No extra attributes necessary */
+#endif
+ if (pthread_mutex_init(&mutex->id, &attr) != 0) {
+ SDL_SetError("pthread_mutex_init() failed");
+ SDL_free(mutex);
+ mutex = NULL;
+ }
+ } else {
+ SDL_OutOfMemory();
+ }
+ return (mutex);
+}
+
+void
+SDL_DestroyMutex(SDL_mutex * mutex)
+{
+ if (mutex) {
+ pthread_mutex_destroy(&mutex->id);
+ SDL_free(mutex);
+ }
+}
+
+/* Lock the mutex */
+int
+SDL_LockMutex(SDL_mutex * mutex)
+{
+#if FAKE_RECURSIVE_MUTEX
+ pthread_t this_thread;
+#endif
+
+ if (mutex == NULL) {
+ return SDL_SetError("Passed a NULL mutex");
+ }
+
+#if FAKE_RECURSIVE_MUTEX
+ this_thread = pthread_self();
+ if (mutex->owner == this_thread) {
+ ++mutex->recursive;
+ } else {
+ /* The order of operations is important.
+ We set the locking thread id after we obtain the lock
+ so unlocks from other threads will fail.
+ */
+ if (pthread_mutex_lock(&mutex->id) == 0) {
+ mutex->owner = this_thread;
+ mutex->recursive = 0;
+ } else {
+ return SDL_SetError("pthread_mutex_lock() failed");
+ }
+ }
+#else
+ if (pthread_mutex_lock(&mutex->id) != 0) {
+ return SDL_SetError("pthread_mutex_lock() failed");
+ }
+#endif
+ return 0;
+}
+
+int
+SDL_TryLockMutex(SDL_mutex * mutex)
+{
+ int retval;
+#if FAKE_RECURSIVE_MUTEX
+ pthread_t this_thread;
+#endif
+
+ if (mutex == NULL) {
+ return SDL_SetError("Passed a NULL mutex");
+ }
+
+ retval = 0;
+#if FAKE_RECURSIVE_MUTEX
+ this_thread = pthread_self();
+ if (mutex->owner == this_thread) {
+ ++mutex->recursive;
+ } else {
+ /* The order of operations is important.
+ We set the locking thread id after we obtain the lock
+ so unlocks from other threads will fail.
+ */
+ if (pthread_mutex_trylock(&mutex->id) == 0) {
+ mutex->owner = this_thread;
+ mutex->recursive = 0;
+ } else if (errno == EBUSY) {
+ retval = SDL_MUTEX_TIMEDOUT;
+ } else {
+ retval = SDL_SetError("pthread_mutex_trylock() failed");
+ }
+ }
+#else
+ if (pthread_mutex_trylock(&mutex->id) != 0) {
+ if (errno == EBUSY) {
+ retval = SDL_MUTEX_TIMEDOUT;
+ } else {
+ retval = SDL_SetError("pthread_mutex_trylock() failed");
+ }
+ }
+#endif
+ return retval;
+}
+
+int
+SDL_UnlockMutex(SDL_mutex * mutex)
+{
+ if (mutex == NULL) {
+ return SDL_SetError("Passed a NULL mutex");
+ }
+
+#if FAKE_RECURSIVE_MUTEX
+ /* We can only unlock the mutex if we own it */
+ if (pthread_self() == mutex->owner) {
+ if (mutex->recursive) {
+ --mutex->recursive;
+ } else {
+ /* The order of operations is important.
+ First reset the owner so another thread doesn't lock
+ the mutex and set the ownership before we reset it,
+ then release the lock semaphore.
+ */
+ mutex->owner = 0;
+ pthread_mutex_unlock(&mutex->id);
+ }
+ } else {
+ return SDL_SetError("mutex not owned by this thread");
+ }
+
+#else
+ if (pthread_mutex_unlock(&mutex->id) != 0) {
+ return SDL_SetError("pthread_mutex_unlock() failed");
+ }
+#endif /* FAKE_RECURSIVE_MUTEX */
+
+ return 0;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/pthread/SDL_sysmutex_c.h b/src/3rdparty/SDL2/src/thread/pthread/SDL_sysmutex_c.h
new file mode 100644
index 0000000..27ac1da
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/pthread/SDL_sysmutex_c.h
@@ -0,0 +1,32 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_mutex_c_h_
+#define SDL_mutex_c_h_
+
+struct SDL_mutex
+{
+ pthread_mutex_t id;
+};
+
+#endif /* SDL_mutex_c_h_ */
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/pthread/SDL_syssem.c b/src/3rdparty/SDL2/src/thread/pthread/SDL_syssem.c
new file mode 100644
index 0000000..bdebf13
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/pthread/SDL_syssem.c
@@ -0,0 +1,209 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include <errno.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <sys/time.h>
+#include <time.h>
+
+#include "SDL_thread.h"
+#include "SDL_timer.h"
+
+/* Wrapper around POSIX 1003.1b semaphores */
+
+#if defined(__MACOSX__) || defined(__IPHONEOS__)
+/* Mac OS X doesn't support sem_getvalue() as of version 10.4 */
+#include "../generic/SDL_syssem.c"
+#else
+
+struct SDL_semaphore
+{
+ sem_t sem;
+};
+
+/* Create a semaphore, initialized with value */
+SDL_sem *
+SDL_CreateSemaphore(Uint32 initial_value)
+{
+ SDL_sem *sem = (SDL_sem *) SDL_malloc(sizeof(SDL_sem));
+ if (sem) {
+ if (sem_init(&sem->sem, 0, initial_value) < 0) {
+ SDL_SetError("sem_init() failed");
+ SDL_free(sem);
+ sem = NULL;
+ }
+ } else {
+ SDL_OutOfMemory();
+ }
+ return sem;
+}
+
+void
+SDL_DestroySemaphore(SDL_sem * sem)
+{
+ if (sem) {
+ sem_destroy(&sem->sem);
+ SDL_free(sem);
+ }
+}
+
+int
+SDL_SemTryWait(SDL_sem * sem)
+{
+ int retval;
+
+ if (!sem) {
+ return SDL_SetError("Passed a NULL semaphore");
+ }
+ retval = SDL_MUTEX_TIMEDOUT;
+ if (sem_trywait(&sem->sem) == 0) {
+ retval = 0;
+ }
+ return retval;
+}
+
+int
+SDL_SemWait(SDL_sem * sem)
+{
+ int retval;
+
+ if (!sem) {
+ return SDL_SetError("Passed a NULL semaphore");
+ }
+
+ do {
+ retval = sem_wait(&sem->sem);
+ } while (retval < 0 && errno == EINTR);
+
+ if (retval < 0) {
+ retval = SDL_SetError("sem_wait() failed");
+ }
+ return retval;
+}
+
+int
+SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
+{
+ int retval;
+#ifdef HAVE_SEM_TIMEDWAIT
+#ifndef HAVE_CLOCK_GETTIME
+ struct timeval now;
+#endif
+ struct timespec ts_timeout;
+#else
+ Uint32 end;
+#endif
+
+ if (!sem) {
+ return SDL_SetError("Passed a NULL semaphore");
+ }
+
+ /* Try the easy cases first */
+ if (timeout == 0) {
+ return SDL_SemTryWait(sem);
+ }
+ if (timeout == SDL_MUTEX_MAXWAIT) {
+ return SDL_SemWait(sem);
+ }
+
+#ifdef HAVE_SEM_TIMEDWAIT
+ /* Setup the timeout. sem_timedwait doesn't wait for
+ * a lapse of time, but until we reach a certain time.
+ * This time is now plus the timeout.
+ */
+#ifdef HAVE_CLOCK_GETTIME
+ clock_gettime(CLOCK_REALTIME, &ts_timeout);
+
+ /* Add our timeout to current time */
+ ts_timeout.tv_nsec += (timeout % 1000) * 1000000;
+ ts_timeout.tv_sec += timeout / 1000;
+#else
+ gettimeofday(&now, NULL);
+
+ /* Add our timeout to current time */
+ ts_timeout.tv_sec = now.tv_sec + (timeout / 1000);
+ ts_timeout.tv_nsec = (now.tv_usec + (timeout % 1000) * 1000) * 1000;
+#endif
+
+ /* Wrap the second if needed */
+ if (ts_timeout.tv_nsec > 1000000000) {
+ ts_timeout.tv_sec += 1;
+ ts_timeout.tv_nsec -= 1000000000;
+ }
+
+ /* Wait. */
+ do {
+ retval = sem_timedwait(&sem->sem, &ts_timeout);
+ } while (retval < 0 && errno == EINTR);
+
+ if (retval < 0) {
+ if (errno == ETIMEDOUT) {
+ retval = SDL_MUTEX_TIMEDOUT;
+ } else {
+ SDL_SetError("sem_timedwait returned an error: %s", strerror(errno));
+ }
+ }
+#else
+ end = SDL_GetTicks() + timeout;
+ while ((retval = SDL_SemTryWait(sem)) == SDL_MUTEX_TIMEDOUT) {
+ if (SDL_TICKS_PASSED(SDL_GetTicks(), end)) {
+ break;
+ }
+ SDL_Delay(1);
+ }
+#endif /* HAVE_SEM_TIMEDWAIT */
+
+ return retval;
+}
+
+Uint32
+SDL_SemValue(SDL_sem * sem)
+{
+ int ret = 0;
+ if (sem) {
+ sem_getvalue(&sem->sem, &ret);
+ if (ret < 0) {
+ ret = 0;
+ }
+ }
+ return (Uint32) ret;
+}
+
+int
+SDL_SemPost(SDL_sem * sem)
+{
+ int retval;
+
+ if (!sem) {
+ return SDL_SetError("Passed a NULL semaphore");
+ }
+
+ retval = sem_post(&sem->sem);
+ if (retval < 0) {
+ SDL_SetError("sem_post() failed");
+ }
+ return retval;
+}
+
+#endif /* __MACOSX__ */
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/pthread/SDL_systhread.c b/src/3rdparty/SDL2/src/thread/pthread/SDL_systhread.c
new file mode 100644
index 0000000..0354840
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/pthread/SDL_systhread.c
@@ -0,0 +1,246 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#include <pthread.h>
+
+#if HAVE_PTHREAD_NP_H
+#include <pthread_np.h>
+#endif
+
+#include <signal.h>
+
+#ifdef __LINUX__
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#endif /* __LINUX__ */
+
+#if defined(__LINUX__) || defined(__MACOSX__) || defined(__IPHONEOS__)
+#include <dlfcn.h>
+#ifndef RTLD_DEFAULT
+#define RTLD_DEFAULT NULL
+#endif
+#endif
+
+#include "SDL_platform.h"
+#include "SDL_thread.h"
+#include "../SDL_thread_c.h"
+#include "../SDL_systhread.h"
+#ifdef __ANDROID__
+#include "../../core/android/SDL_android.h"
+#endif
+
+#ifdef __HAIKU__
+#include <kernel/OS.h>
+#endif
+
+#include "SDL_assert.h"
+
+#ifndef __NACL__
+/* List of signals to mask in the subthreads */
+static const int sig_list[] = {
+ SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
+ SIGVTALRM, SIGPROF, 0
+};
+#endif
+
+static void *
+RunThread(void *data)
+{
+#ifdef __ANDROID__
+ Android_JNI_SetupThread();
+#endif
+ SDL_RunThread(data);
+ return NULL;
+}
+
+#if defined(__MACOSX__) || defined(__IPHONEOS__)
+static SDL_bool checked_setname = SDL_FALSE;
+static int (*ppthread_setname_np)(const char*) = NULL;
+#elif defined(__LINUX__)
+static SDL_bool checked_setname = SDL_FALSE;
+static int (*ppthread_setname_np)(pthread_t, const char*) = NULL;
+#endif
+int
+SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
+{
+ pthread_attr_t type;
+
+ /* do this here before any threads exist, so there's no race condition. */
+ #if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__)
+ if (!checked_setname) {
+ void *fn = dlsym(RTLD_DEFAULT, "pthread_setname_np");
+ #if defined(__MACOSX__) || defined(__IPHONEOS__)
+ ppthread_setname_np = (int(*)(const char*)) fn;
+ #elif defined(__LINUX__)
+ ppthread_setname_np = (int(*)(pthread_t, const char*)) fn;
+ #endif
+ checked_setname = SDL_TRUE;
+ }
+ #endif
+
+ /* Set the thread attributes */
+ if (pthread_attr_init(&type) != 0) {
+ return SDL_SetError("Couldn't initialize pthread attributes");
+ }
+ pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
+
+ /* Set caller-requested stack size. Otherwise: use the system default. */
+ if (thread->stacksize) {
+ pthread_attr_setstacksize(&type, (size_t) thread->stacksize);
+ }
+
+ /* Create the thread and go! */
+ if (pthread_create(&thread->handle, &type, RunThread, args) != 0) {
+ return SDL_SetError("Not enough resources to create thread");
+ }
+
+ return 0;
+}
+
+void
+SDL_SYS_SetupThread(const char *name)
+{
+#if !defined(__NACL__)
+ int i;
+ sigset_t mask;
+#endif /* !__NACL__ */
+
+ if (name != NULL) {
+ #if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__)
+ SDL_assert(checked_setname);
+ if (ppthread_setname_np != NULL) {
+ #if defined(__MACOSX__) || defined(__IPHONEOS__)
+ ppthread_setname_np(name);
+ #elif defined(__LINUX__)
+ ppthread_setname_np(pthread_self(), name);
+ #endif
+ }
+ #elif HAVE_PTHREAD_SETNAME_NP
+ #if defined(__NETBSD__)
+ pthread_setname_np(pthread_self(), "%s", name);
+ #else
+ pthread_setname_np(pthread_self(), name);
+ #endif
+ #elif HAVE_PTHREAD_SET_NAME_NP
+ pthread_set_name_np(pthread_self(), name);
+ #elif defined(__HAIKU__)
+ /* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */
+ char namebuf[B_OS_NAME_LENGTH];
+ SDL_snprintf(namebuf, sizeof (namebuf), "%s", name);
+ namebuf[sizeof (namebuf) - 1] = '\0';
+ rename_thread(find_thread(NULL), namebuf);
+ #endif
+ }
+
+ /* NativeClient does not yet support signals.*/
+#if !defined(__NACL__)
+ /* Mask asynchronous signals for this thread */
+ sigemptyset(&mask);
+ for (i = 0; sig_list[i]; ++i) {
+ sigaddset(&mask, sig_list[i]);
+ }
+ pthread_sigmask(SIG_BLOCK, &mask, 0);
+#endif /* !__NACL__ */
+
+
+#ifdef PTHREAD_CANCEL_ASYNCHRONOUS
+ /* Allow ourselves to be asynchronously cancelled */
+ {
+ int oldstate;
+ pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
+ }
+#endif
+}
+
+SDL_threadID
+SDL_ThreadID(void)
+{
+ return ((SDL_threadID) pthread_self());
+}
+
+int
+SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
+{
+#if __NACL__
+ /* FIXME: Setting thread priority does not seem to be supported in NACL */
+ return 0;
+#elif __LINUX__
+ int value;
+
+ if (priority == SDL_THREAD_PRIORITY_LOW) {
+ value = 19;
+ } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
+ value = -20;
+ } else {
+ value = 0;
+ }
+ if (setpriority(PRIO_PROCESS, syscall(SYS_gettid), value) < 0) {
+ /* Note that this fails if you're trying to set high priority
+ and you don't have root permission. BUT DON'T RUN AS ROOT!
+
+ You can grant the ability to increase thread priority by
+ running the following command on your application binary:
+ sudo setcap 'cap_sys_nice=eip' <application>
+ */
+ return SDL_SetError("setpriority() failed");
+ }
+ return 0;
+#else
+ struct sched_param sched;
+ int policy;
+ pthread_t thread = pthread_self();
+
+ if (pthread_getschedparam(thread, &policy, &sched) != 0) {
+ return SDL_SetError("pthread_getschedparam() failed");
+ }
+ if (priority == SDL_THREAD_PRIORITY_LOW) {
+ sched.sched_priority = sched_get_priority_min(policy);
+ } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
+ sched.sched_priority = sched_get_priority_max(policy);
+ } else {
+ int min_priority = sched_get_priority_min(policy);
+ int max_priority = sched_get_priority_max(policy);
+ sched.sched_priority = (min_priority + (max_priority - min_priority) / 2);
+ }
+ if (pthread_setschedparam(thread, policy, &sched) != 0) {
+ return SDL_SetError("pthread_setschedparam() failed");
+ }
+ return 0;
+#endif /* linux */
+}
+
+void
+SDL_SYS_WaitThread(SDL_Thread * thread)
+{
+ pthread_join(thread->handle, 0);
+}
+
+void
+SDL_SYS_DetachThread(SDL_Thread * thread)
+{
+ pthread_detach(thread->handle);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/pthread/SDL_systhread_c.h b/src/3rdparty/SDL2/src/thread/pthread/SDL_systhread_c.h
new file mode 100644
index 0000000..898c219
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/pthread/SDL_systhread_c.h
@@ -0,0 +1,27 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include <pthread.h>
+
+typedef pthread_t SYS_ThreadHandle;
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/pthread/SDL_systls.c b/src/3rdparty/SDL2/src/thread/pthread/SDL_systls.c
new file mode 100644
index 0000000..c580595
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/pthread/SDL_systls.c
@@ -0,0 +1,70 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+#include "SDL_thread.h"
+#include "../SDL_systhread.h"
+#include "../SDL_thread_c.h"
+
+#include <pthread.h>
+
+
+#define INVALID_PTHREAD_KEY ((pthread_key_t)-1)
+
+static pthread_key_t thread_local_storage = INVALID_PTHREAD_KEY;
+static SDL_bool generic_local_storage = SDL_FALSE;
+
+SDL_TLSData *
+SDL_SYS_GetTLSData(void)
+{
+ if (thread_local_storage == INVALID_PTHREAD_KEY && !generic_local_storage) {
+ static SDL_SpinLock lock;
+ SDL_AtomicLock(&lock);
+ if (thread_local_storage == INVALID_PTHREAD_KEY && !generic_local_storage) {
+ pthread_key_t storage;
+ if (pthread_key_create(&storage, NULL) == 0) {
+ SDL_MemoryBarrierRelease();
+ thread_local_storage = storage;
+ } else {
+ generic_local_storage = SDL_TRUE;
+ }
+ }
+ SDL_AtomicUnlock(&lock);
+ }
+ if (generic_local_storage) {
+ return SDL_Generic_GetTLSData();
+ }
+ SDL_MemoryBarrierAcquire();
+ return (SDL_TLSData *)pthread_getspecific(thread_local_storage);
+}
+
+int
+SDL_SYS_SetTLSData(SDL_TLSData *data)
+{
+ if (generic_local_storage) {
+ return SDL_Generic_SetTLSData(data);
+ }
+ if (pthread_setspecific(thread_local_storage, data) != 0) {
+ return SDL_SetError("pthread_setspecific() failed");
+ }
+ return 0;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/stdcpp/SDL_syscond.cpp b/src/3rdparty/SDL2/src/thread/stdcpp/SDL_syscond.cpp
new file mode 100644
index 0000000..32c7c4b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/stdcpp/SDL_syscond.cpp
@@ -0,0 +1,164 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+extern "C" {
+#include "SDL_thread.h"
+}
+
+#include <chrono>
+#include <condition_variable>
+#include <ratio>
+#include <system_error>
+
+#include "SDL_sysmutex_c.h"
+
+struct SDL_cond
+{
+ std::condition_variable_any cpp_cond;
+};
+
+/* Create a condition variable */
+extern "C"
+SDL_cond *
+SDL_CreateCond(void)
+{
+ /* Allocate and initialize the condition variable */
+ try {
+ SDL_cond * cond = new SDL_cond;
+ return cond;
+ } catch (std::system_error & ex) {
+ SDL_SetError("unable to create a C++ condition variable: code=%d; %s", ex.code(), ex.what());
+ return NULL;
+ } catch (std::bad_alloc &) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+}
+
+/* Destroy a condition variable */
+extern "C"
+void
+SDL_DestroyCond(SDL_cond * cond)
+{
+ if (cond) {
+ delete cond;
+ }
+}
+
+/* Restart one of the threads that are waiting on the condition variable */
+extern "C"
+int
+SDL_CondSignal(SDL_cond * cond)
+{
+ if (!cond) {
+ SDL_SetError("Passed a NULL condition variable");
+ return -1;
+ }
+
+ cond->cpp_cond.notify_one();
+ return 0;
+}
+
+/* Restart all threads that are waiting on the condition variable */
+extern "C"
+int
+SDL_CondBroadcast(SDL_cond * cond)
+{
+ if (!cond) {
+ SDL_SetError("Passed a NULL condition variable");
+ return -1;
+ }
+
+ cond->cpp_cond.notify_all();
+ return 0;
+}
+
+/* Wait on the condition variable for at most 'ms' milliseconds.
+ The mutex must be locked before entering this function!
+ The mutex is unlocked during the wait, and locked again after the wait.
+
+Typical use:
+
+Thread A:
+ SDL_LockMutex(lock);
+ while ( ! condition ) {
+ SDL_CondWait(cond, lock);
+ }
+ SDL_UnlockMutex(lock);
+
+Thread B:
+ SDL_LockMutex(lock);
+ ...
+ condition = true;
+ ...
+ SDL_CondSignal(cond);
+ SDL_UnlockMutex(lock);
+ */
+extern "C"
+int
+SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
+{
+ if (!cond) {
+ SDL_SetError("Passed a NULL condition variable");
+ return -1;
+ }
+
+ if (!mutex) {
+ SDL_SetError("Passed a NULL mutex variable");
+ return -1;
+ }
+
+ try {
+ std::unique_lock<std::recursive_mutex> cpp_lock(mutex->cpp_mutex, std::adopt_lock_t());
+ if (ms == SDL_MUTEX_MAXWAIT) {
+ cond->cpp_cond.wait(
+ cpp_lock
+ );
+ cpp_lock.release();
+ return 0;
+ } else {
+ auto wait_result = cond->cpp_cond.wait_for(
+ cpp_lock,
+ std::chrono::duration<Uint32, std::milli>(ms)
+ );
+ cpp_lock.release();
+ if (wait_result == std::cv_status::timeout) {
+ return SDL_MUTEX_TIMEDOUT;
+ } else {
+ return 0;
+ }
+ }
+ } catch (std::system_error & ex) {
+ SDL_SetError("unable to wait on a C++ condition variable: code=%d; %s", ex.code(), ex.what());
+ return -1;
+ }
+}
+
+/* Wait on the condition variable forever */
+extern "C"
+int
+SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
+{
+ return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/stdcpp/SDL_sysmutex.cpp b/src/3rdparty/SDL2/src/thread/stdcpp/SDL_sysmutex.cpp
new file mode 100644
index 0000000..667d36b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/stdcpp/SDL_sysmutex.cpp
@@ -0,0 +1,111 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+extern "C" {
+#include "SDL_thread.h"
+#include "SDL_systhread_c.h"
+#include "SDL_log.h"
+}
+
+#include <system_error>
+
+#include "SDL_sysmutex_c.h"
+#include <Windows.h>
+
+
+/* Create a mutex */
+extern "C"
+SDL_mutex *
+SDL_CreateMutex(void)
+{
+ /* Allocate and initialize the mutex */
+ try {
+ SDL_mutex * mutex = new SDL_mutex;
+ return mutex;
+ } catch (std::system_error & ex) {
+ SDL_SetError("unable to create a C++ mutex: code=%d; %s", ex.code(), ex.what());
+ return NULL;
+ } catch (std::bad_alloc &) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+}
+
+/* Free the mutex */
+extern "C"
+void
+SDL_DestroyMutex(SDL_mutex * mutex)
+{
+ if (mutex) {
+ delete mutex;
+ }
+}
+
+/* Lock the semaphore */
+extern "C"
+int
+SDL_mutexP(SDL_mutex * mutex)
+{
+ if (mutex == NULL) {
+ SDL_SetError("Passed a NULL mutex");
+ return -1;
+ }
+
+ try {
+ mutex->cpp_mutex.lock();
+ return 0;
+ } catch (std::system_error & ex) {
+ SDL_SetError("unable to lock a C++ mutex: code=%d; %s", ex.code(), ex.what());
+ return -1;
+ }
+}
+
+/* TryLock the mutex */
+int
+SDL_TryLockMutex(SDL_mutex * mutex)
+{
+ int retval = 0;
+ if (mutex == NULL) {
+ return SDL_SetError("Passed a NULL mutex");
+ }
+
+ if (mutex->cpp_mutex.try_lock() == false) {
+ retval = SDL_MUTEX_TIMEDOUT;
+ }
+ return retval;
+}
+
+/* Unlock the mutex */
+extern "C"
+int
+SDL_mutexV(SDL_mutex * mutex)
+{
+ if (mutex == NULL) {
+ SDL_SetError("Passed a NULL mutex");
+ return -1;
+ }
+
+ mutex->cpp_mutex.unlock();
+ return 0;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/stdcpp/SDL_sysmutex_c.h b/src/3rdparty/SDL2/src/thread/stdcpp/SDL_sysmutex_c.h
new file mode 100644
index 0000000..000288f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/stdcpp/SDL_sysmutex_c.h
@@ -0,0 +1,30 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#include <mutex>
+
+struct SDL_mutex
+{
+ std::recursive_mutex cpp_mutex;
+};
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/stdcpp/SDL_systhread.cpp b/src/3rdparty/SDL2/src/thread/stdcpp/SDL_systhread.cpp
new file mode 100644
index 0000000..3020f1c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/stdcpp/SDL_systhread.cpp
@@ -0,0 +1,168 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+/* Thread management routines for SDL */
+
+extern "C" {
+#include "SDL_thread.h"
+#include "../SDL_thread_c.h"
+#include "../SDL_systhread.h"
+#include "SDL_log.h"
+}
+
+#include <mutex>
+#include <thread>
+#include <system_error>
+
+#ifdef __WINRT__
+#include <Windows.h>
+#endif
+
+static void
+RunThread(void *args)
+{
+ SDL_RunThread(args);
+}
+
+extern "C"
+int
+SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
+{
+ try {
+ // !!! FIXME: no way to set a thread stack size here.
+ std::thread cpp_thread(RunThread, args);
+ thread->handle = (void *) new std::thread(std::move(cpp_thread));
+ return 0;
+ } catch (std::system_error & ex) {
+ SDL_SetError("unable to start a C++ thread: code=%d; %s", ex.code(), ex.what());
+ return -1;
+ } catch (std::bad_alloc &) {
+ SDL_OutOfMemory();
+ return -1;
+ }
+}
+
+extern "C"
+void
+SDL_SYS_SetupThread(const char *name)
+{
+ // Make sure a thread ID gets assigned ASAP, for debugging purposes:
+ SDL_ThreadID();
+ return;
+}
+
+extern "C"
+SDL_threadID
+SDL_ThreadID(void)
+{
+#ifdef __WINRT__
+ return GetCurrentThreadId();
+#else
+ // HACK: Mimick a thread ID, if one isn't otherwise available.
+ static thread_local SDL_threadID current_thread_id = 0;
+ static SDL_threadID next_thread_id = 1;
+ static std::mutex next_thread_id_mutex;
+
+ if (current_thread_id == 0) {
+ std::lock_guard<std::mutex> lock(next_thread_id_mutex);
+ current_thread_id = next_thread_id;
+ ++next_thread_id;
+ }
+
+ return current_thread_id;
+#endif
+}
+
+extern "C"
+int
+SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
+{
+ // Thread priorities do not look to be settable via C++11's thread
+ // interface, at least as of this writing (Nov 2012). std::thread does
+ // provide access to the OS' native handle, however, and some form of
+ // priority-setting could, in theory, be done through this interface.
+ //
+ // WinRT: UPDATE (Aug 20, 2013): thread priorities cannot be changed
+ // on WinRT, at least not for any thread that's already been created.
+ // WinRT threads appear to be based off of the WinRT class,
+ // ThreadPool, more info on which can be found at:
+ // http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.threading.threadpool.aspx
+ //
+ // For compatibility sake, 0 will be returned here.
+ return (0);
+}
+
+extern "C"
+void
+SDL_SYS_WaitThread(SDL_Thread * thread)
+{
+ if ( ! thread) {
+ return;
+ }
+
+ try {
+ std::thread * cpp_thread = (std::thread *) thread->handle;
+ if (cpp_thread->joinable()) {
+ cpp_thread->join();
+ }
+ } catch (std::system_error &) {
+ // An error occurred when joining the thread. SDL_WaitThread does not,
+ // however, seem to provide a means to report errors to its callers
+ // though!
+ }
+}
+
+extern "C"
+void
+SDL_SYS_DetachThread(SDL_Thread * thread)
+{
+ if ( ! thread) {
+ return;
+ }
+
+ try {
+ std::thread * cpp_thread = (std::thread *) thread->handle;
+ if (cpp_thread->joinable()) {
+ cpp_thread->detach();
+ }
+ } catch (std::system_error &) {
+ // An error occurred when detaching the thread. SDL_DetachThread does not,
+ // however, seem to provide a means to report errors to its callers
+ // though!
+ }
+}
+
+extern "C"
+SDL_TLSData *
+SDL_SYS_GetTLSData(void)
+{
+ return SDL_Generic_GetTLSData();
+}
+
+extern "C"
+int
+SDL_SYS_SetTLSData(SDL_TLSData *data)
+{
+ return SDL_Generic_SetTLSData(data);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/stdcpp/SDL_systhread_c.h b/src/3rdparty/SDL2/src/thread/stdcpp/SDL_systhread_c.h
new file mode 100644
index 0000000..ee4764d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/stdcpp/SDL_systhread_c.h
@@ -0,0 +1,26 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+/* For a thread handle, use a void pointer to a std::thread */
+typedef void * SYS_ThreadHandle;
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/windows/SDL_sysmutex.c b/src/3rdparty/SDL2/src/thread/windows/SDL_sysmutex.c
new file mode 100644
index 0000000..119e62b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/windows/SDL_sysmutex.c
@@ -0,0 +1,110 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_THREAD_WINDOWS
+
+/* Mutex functions using the Win32 API */
+
+#include "../../core/windows/SDL_windows.h"
+
+#include "SDL_mutex.h"
+
+
+struct SDL_mutex
+{
+ CRITICAL_SECTION cs;
+};
+
+/* Create a mutex */
+SDL_mutex *
+SDL_CreateMutex(void)
+{
+ SDL_mutex *mutex;
+
+ /* Allocate mutex memory */
+ mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex));
+ if (mutex) {
+ /* Initialize */
+ /* On SMP systems, a non-zero spin count generally helps performance */
+#if __WINRT__
+ InitializeCriticalSectionEx(&mutex->cs, 2000, 0);
+#else
+ InitializeCriticalSectionAndSpinCount(&mutex->cs, 2000);
+#endif
+ } else {
+ SDL_OutOfMemory();
+ }
+ return (mutex);
+}
+
+/* Free the mutex */
+void
+SDL_DestroyMutex(SDL_mutex * mutex)
+{
+ if (mutex) {
+ DeleteCriticalSection(&mutex->cs);
+ SDL_free(mutex);
+ }
+}
+
+/* Lock the mutex */
+int
+SDL_LockMutex(SDL_mutex * mutex)
+{
+ if (mutex == NULL) {
+ return SDL_SetError("Passed a NULL mutex");
+ }
+
+ EnterCriticalSection(&mutex->cs);
+ return (0);
+}
+
+/* TryLock the mutex */
+int
+SDL_TryLockMutex(SDL_mutex * mutex)
+{
+ int retval = 0;
+ if (mutex == NULL) {
+ return SDL_SetError("Passed a NULL mutex");
+ }
+
+ if (TryEnterCriticalSection(&mutex->cs) == 0) {
+ retval = SDL_MUTEX_TIMEDOUT;
+ }
+ return retval;
+}
+
+/* Unlock the mutex */
+int
+SDL_UnlockMutex(SDL_mutex * mutex)
+{
+ if (mutex == NULL) {
+ return SDL_SetError("Passed a NULL mutex");
+ }
+
+ LeaveCriticalSection(&mutex->cs);
+ return (0);
+}
+
+#endif /* SDL_THREAD_WINDOWS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/windows/SDL_syssem.c b/src/3rdparty/SDL2/src/thread/windows/SDL_syssem.c
new file mode 100644
index 0000000..dcb36fa
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/windows/SDL_syssem.c
@@ -0,0 +1,152 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_THREAD_WINDOWS
+
+/* Semaphore functions using the Win32 API */
+
+#include "../../core/windows/SDL_windows.h"
+
+#include "SDL_thread.h"
+
+struct SDL_semaphore
+{
+ HANDLE id;
+ LONG count;
+};
+
+
+/* Create a semaphore */
+SDL_sem *
+SDL_CreateSemaphore(Uint32 initial_value)
+{
+ SDL_sem *sem;
+
+ /* Allocate sem memory */
+ sem = (SDL_sem *) SDL_malloc(sizeof(*sem));
+ if (sem) {
+ /* Create the semaphore, with max value 32K */
+#if __WINRT__
+ sem->id = CreateSemaphoreEx(NULL, initial_value, 32 * 1024, NULL, 0, SEMAPHORE_ALL_ACCESS);
+#else
+ sem->id = CreateSemaphore(NULL, initial_value, 32 * 1024, NULL);
+#endif
+ sem->count = initial_value;
+ if (!sem->id) {
+ SDL_SetError("Couldn't create semaphore");
+ SDL_free(sem);
+ sem = NULL;
+ }
+ } else {
+ SDL_OutOfMemory();
+ }
+ return (sem);
+}
+
+/* Free the semaphore */
+void
+SDL_DestroySemaphore(SDL_sem * sem)
+{
+ if (sem) {
+ if (sem->id) {
+ CloseHandle(sem->id);
+ sem->id = 0;
+ }
+ SDL_free(sem);
+ }
+}
+
+int
+SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
+{
+ int retval;
+ DWORD dwMilliseconds;
+
+ if (!sem) {
+ return SDL_SetError("Passed a NULL sem");
+ }
+
+ if (timeout == SDL_MUTEX_MAXWAIT) {
+ dwMilliseconds = INFINITE;
+ } else {
+ dwMilliseconds = (DWORD) timeout;
+ }
+ switch (WaitForSingleObjectEx(sem->id, dwMilliseconds, FALSE)) {
+ case WAIT_OBJECT_0:
+ InterlockedDecrement(&sem->count);
+ retval = 0;
+ break;
+ case WAIT_TIMEOUT:
+ retval = SDL_MUTEX_TIMEDOUT;
+ break;
+ default:
+ retval = SDL_SetError("WaitForSingleObject() failed");
+ break;
+ }
+ return retval;
+}
+
+int
+SDL_SemTryWait(SDL_sem * sem)
+{
+ return SDL_SemWaitTimeout(sem, 0);
+}
+
+int
+SDL_SemWait(SDL_sem * sem)
+{
+ return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
+}
+
+/* Returns the current count of the semaphore */
+Uint32
+SDL_SemValue(SDL_sem * sem)
+{
+ if (!sem) {
+ SDL_SetError("Passed a NULL sem");
+ return 0;
+ }
+ return (Uint32)sem->count;
+}
+
+int
+SDL_SemPost(SDL_sem * sem)
+{
+ if (!sem) {
+ return SDL_SetError("Passed a NULL sem");
+ }
+ /* Increase the counter in the first place, because
+ * after a successful release the semaphore may
+ * immediately get destroyed by another thread which
+ * is waiting for this semaphore.
+ */
+ InterlockedIncrement(&sem->count);
+ if (ReleaseSemaphore(sem->id, 1, NULL) == FALSE) {
+ InterlockedDecrement(&sem->count); /* restore */
+ return SDL_SetError("ReleaseSemaphore() failed");
+ }
+ return 0;
+}
+
+#endif /* SDL_THREAD_WINDOWS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/windows/SDL_systhread.c b/src/3rdparty/SDL2/src/thread/windows/SDL_systhread.c
new file mode 100644
index 0000000..90036c9
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/windows/SDL_systhread.c
@@ -0,0 +1,258 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_THREAD_WINDOWS
+
+/* Win32 thread management routines for SDL */
+
+#include "SDL_hints.h"
+#include "SDL_thread.h"
+#include "../SDL_thread_c.h"
+#include "../SDL_systhread.h"
+#include "SDL_systhread_c.h"
+
+#ifndef SDL_PASSED_BEGINTHREAD_ENDTHREAD
+/* We'll use the C library from this DLL */
+#include <process.h>
+
+#ifndef STACK_SIZE_PARAM_IS_A_RESERVATION
+#define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
+#endif
+
+/* Cygwin gcc-3 ... MingW64 (even with a i386 host) does this like MSVC. */
+#if (defined(__MINGW32__) && (__GNUC__ < 4))
+typedef unsigned long (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
+ unsigned (__stdcall *func)(void *), void *arg,
+ unsigned, unsigned *threadID);
+typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
+
+#elif defined(__WATCOMC__)
+/* This is for Watcom targets except OS2 */
+#if __WATCOMC__ < 1240
+#define __watcall
+#endif
+typedef unsigned long (__watcall * pfnSDL_CurrentBeginThread) (void *,
+ unsigned,
+ unsigned
+ (__stdcall *
+ func) (void
+ *),
+ void *arg,
+ unsigned,
+ unsigned
+ *threadID);
+typedef void (__watcall * pfnSDL_CurrentEndThread) (unsigned code);
+
+#else
+typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
+ unsigned (__stdcall *
+ func) (void
+ *),
+ void *arg, unsigned,
+ unsigned *threadID);
+typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
+#endif
+#endif /* !SDL_PASSED_BEGINTHREAD_ENDTHREAD */
+
+
+typedef struct ThreadStartParms
+{
+ void *args;
+ pfnSDL_CurrentEndThread pfnCurrentEndThread;
+} tThreadStartParms, *pThreadStartParms;
+
+static DWORD
+RunThread(void *data)
+{
+ pThreadStartParms pThreadParms = (pThreadStartParms) data;
+ pfnSDL_CurrentEndThread pfnEndThread = pThreadParms->pfnCurrentEndThread;
+ void *args = pThreadParms->args;
+ SDL_free(pThreadParms);
+ SDL_RunThread(args);
+ if (pfnEndThread != NULL)
+ pfnEndThread(0);
+ return (0);
+}
+
+static DWORD WINAPI
+RunThreadViaCreateThread(LPVOID data)
+{
+ return RunThread(data);
+}
+
+static unsigned __stdcall
+RunThreadViaBeginThreadEx(void *data)
+{
+ return (unsigned) RunThread(data);
+}
+
+#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
+int
+SDL_SYS_CreateThread(SDL_Thread * thread, void *args,
+ pfnSDL_CurrentBeginThread pfnBeginThread,
+ pfnSDL_CurrentEndThread pfnEndThread)
+{
+#elif defined(__CYGWIN__) || defined(__WINRT__)
+int
+SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
+{
+ pfnSDL_CurrentBeginThread pfnBeginThread = NULL;
+ pfnSDL_CurrentEndThread pfnEndThread = NULL;
+#else
+int
+SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
+{
+ pfnSDL_CurrentBeginThread pfnBeginThread = (pfnSDL_CurrentBeginThread)_beginthreadex;
+ pfnSDL_CurrentEndThread pfnEndThread = (pfnSDL_CurrentEndThread)_endthreadex;
+#endif /* SDL_PASSED_BEGINTHREAD_ENDTHREAD */
+ pThreadStartParms pThreadParms =
+ (pThreadStartParms) SDL_malloc(sizeof(tThreadStartParms));
+ const DWORD flags = thread->stacksize ? STACK_SIZE_PARAM_IS_A_RESERVATION : 0;
+ if (!pThreadParms) {
+ return SDL_OutOfMemory();
+ }
+ /* Save the function which we will have to call to clear the RTL of calling app! */
+ pThreadParms->pfnCurrentEndThread = pfnEndThread;
+ /* Also save the real parameters we have to pass to thread function */
+ pThreadParms->args = args;
+
+ /* thread->stacksize == 0 means "system default", same as win32 expects */
+ if (pfnBeginThread) {
+ unsigned threadid = 0;
+ thread->handle = (SYS_ThreadHandle)
+ ((size_t) pfnBeginThread(NULL, (unsigned int) thread->stacksize,
+ RunThreadViaBeginThreadEx,
+ pThreadParms, flags, &threadid));
+ } else {
+ DWORD threadid = 0;
+ thread->handle = CreateThread(NULL, thread->stacksize,
+ RunThreadViaCreateThread,
+ pThreadParms, flags, &threadid);
+ }
+ if (thread->handle == NULL) {
+ return SDL_SetError("Not enough resources to create thread");
+ }
+ return 0;
+}
+
+#pragma pack(push,8)
+typedef struct tagTHREADNAME_INFO
+{
+ DWORD dwType; /* must be 0x1000 */
+ LPCSTR szName; /* pointer to name (in user addr space) */
+ DWORD dwThreadID; /* thread ID (-1=caller thread) */
+ DWORD dwFlags; /* reserved for future use, must be zero */
+} THREADNAME_INFO;
+#pragma pack(pop)
+
+
+typedef HRESULT (WINAPI *pfnSetThreadDescription)(HANDLE, PCWSTR);
+
+void
+SDL_SYS_SetupThread(const char *name)
+{
+ if (name != NULL) {
+ #ifndef __WINRT__ /* !!! FIXME: There's no LoadLibrary() in WinRT; don't know if SetThreadDescription is available there at all at the moment. */
+ static pfnSetThreadDescription pSetThreadDescription = NULL;
+ static HMODULE kernel32 = 0;
+
+ if (!kernel32) {
+ kernel32 = LoadLibraryW(L"kernel32.dll");
+ if (kernel32) {
+ pSetThreadDescription = (pfnSetThreadDescription) GetProcAddress(kernel32, "SetThreadDescription");
+ }
+ }
+
+ if (pSetThreadDescription != NULL) {
+ WCHAR *strw = WIN_UTF8ToString(name);
+ if (strw) {
+ pSetThreadDescription(GetCurrentThread(), strw);
+ SDL_free(strw);
+ }
+ }
+ #endif
+
+ /* Presumably some version of Visual Studio will understand SetThreadDescription(),
+ but we still need to deal with older OSes and debuggers. Set it with the arcane
+ exception magic, too. */
+
+ if (IsDebuggerPresent()) {
+ THREADNAME_INFO inf;
+
+ /* C# and friends will try to catch this Exception, let's avoid it. */
+ if (SDL_GetHintBoolean(SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, SDL_TRUE)) {
+ return;
+ }
+
+ /* This magic tells the debugger to name a thread if it's listening. */
+ SDL_zero(inf);
+ inf.dwType = 0x1000;
+ inf.szName = name;
+ inf.dwThreadID = (DWORD) -1;
+ inf.dwFlags = 0;
+
+ /* The debugger catches this, renames the thread, continues on. */
+ RaiseException(0x406D1388, 0, sizeof(inf) / sizeof(ULONG), (const ULONG_PTR*) &inf);
+ }
+ }
+}
+
+SDL_threadID
+SDL_ThreadID(void)
+{
+ return ((SDL_threadID) GetCurrentThreadId());
+}
+
+int
+SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
+{
+ int value;
+
+ if (priority == SDL_THREAD_PRIORITY_LOW) {
+ value = THREAD_PRIORITY_LOWEST;
+ } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
+ value = THREAD_PRIORITY_HIGHEST;
+ } else {
+ value = THREAD_PRIORITY_NORMAL;
+ }
+ if (!SetThreadPriority(GetCurrentThread(), value)) {
+ return WIN_SetError("SetThreadPriority()");
+ }
+ return 0;
+}
+
+void
+SDL_SYS_WaitThread(SDL_Thread * thread)
+{
+ WaitForSingleObjectEx(thread->handle, INFINITE, FALSE);
+ CloseHandle(thread->handle);
+}
+
+void
+SDL_SYS_DetachThread(SDL_Thread * thread)
+{
+ CloseHandle(thread->handle);
+}
+
+#endif /* SDL_THREAD_WINDOWS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/windows/SDL_systhread_c.h b/src/3rdparty/SDL2/src/thread/windows/SDL_systhread_c.h
new file mode 100644
index 0000000..65d5a1b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/windows/SDL_systhread_c.h
@@ -0,0 +1,32 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_systhread_c_h_
+#define SDL_systhread_c_h_
+
+#include "../../core/windows/SDL_windows.h"
+
+typedef HANDLE SYS_ThreadHandle;
+
+#endif /* SDL_systhread_c_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/thread/windows/SDL_systls.c b/src/3rdparty/SDL2/src/thread/windows/SDL_systls.c
new file mode 100644
index 0000000..888fd74
--- /dev/null
+++ b/src/3rdparty/SDL2/src/thread/windows/SDL_systls.c
@@ -0,0 +1,72 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_THREAD_WINDOWS
+
+#include "../../core/windows/SDL_windows.h"
+
+#include "SDL_thread.h"
+#include "../SDL_thread_c.h"
+
+static DWORD thread_local_storage = TLS_OUT_OF_INDEXES;
+static SDL_bool generic_local_storage = SDL_FALSE;
+
+SDL_TLSData *
+SDL_SYS_GetTLSData(void)
+{
+ if (thread_local_storage == TLS_OUT_OF_INDEXES && !generic_local_storage) {
+ static SDL_SpinLock lock;
+ SDL_AtomicLock(&lock);
+ if (thread_local_storage == TLS_OUT_OF_INDEXES && !generic_local_storage) {
+ DWORD storage = TlsAlloc();
+ if (storage != TLS_OUT_OF_INDEXES) {
+ SDL_MemoryBarrierRelease();
+ thread_local_storage = storage;
+ } else {
+ generic_local_storage = SDL_TRUE;
+ }
+ }
+ SDL_AtomicUnlock(&lock);
+ }
+ if (generic_local_storage) {
+ return SDL_Generic_GetTLSData();
+ }
+ SDL_MemoryBarrierAcquire();
+ return (SDL_TLSData *)TlsGetValue(thread_local_storage);
+}
+
+int
+SDL_SYS_SetTLSData(SDL_TLSData *data)
+{
+ if (generic_local_storage) {
+ return SDL_Generic_SetTLSData(data);
+ }
+ if (!TlsSetValue(thread_local_storage, data)) {
+ return SDL_SetError("TlsSetValue() failed");
+ }
+ return 0;
+}
+
+#endif /* SDL_THREAD_WINDOWS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/timer/SDL_timer.c b/src/3rdparty/SDL2/src/timer/SDL_timer.c
new file mode 100644
index 0000000..f4a13f4
--- /dev/null
+++ b/src/3rdparty/SDL2/src/timer/SDL_timer.c
@@ -0,0 +1,373 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "SDL_timer.h"
+#include "SDL_timer_c.h"
+#include "SDL_atomic.h"
+#include "SDL_cpuinfo.h"
+#include "../thread/SDL_systhread.h"
+
+/* #define DEBUG_TIMERS */
+
+typedef struct _SDL_Timer
+{
+ int timerID;
+ SDL_TimerCallback callback;
+ void *param;
+ Uint32 interval;
+ Uint32 scheduled;
+ SDL_atomic_t canceled;
+ struct _SDL_Timer *next;
+} SDL_Timer;
+
+typedef struct _SDL_TimerMap
+{
+ int timerID;
+ SDL_Timer *timer;
+ struct _SDL_TimerMap *next;
+} SDL_TimerMap;
+
+/* The timers are kept in a sorted list */
+typedef struct {
+ /* Data used by the main thread */
+ SDL_Thread *thread;
+ SDL_atomic_t nextID;
+ SDL_TimerMap *timermap;
+ SDL_mutex *timermap_lock;
+
+ /* Padding to separate cache lines between threads */
+ char cache_pad[SDL_CACHELINE_SIZE];
+
+ /* Data used to communicate with the timer thread */
+ SDL_SpinLock lock;
+ SDL_sem *sem;
+ SDL_Timer *pending;
+ SDL_Timer *freelist;
+ SDL_atomic_t active;
+
+ /* List of timers - this is only touched by the timer thread */
+ SDL_Timer *timers;
+} SDL_TimerData;
+
+static SDL_TimerData SDL_timer_data;
+
+/* The idea here is that any thread might add a timer, but a single
+ * thread manages the active timer queue, sorted by scheduling time.
+ *
+ * Timers are removed by simply setting a canceled flag
+ */
+
+static void
+SDL_AddTimerInternal(SDL_TimerData *data, SDL_Timer *timer)
+{
+ SDL_Timer *prev, *curr;
+
+ prev = NULL;
+ for (curr = data->timers; curr; prev = curr, curr = curr->next) {
+ if ((Sint32)(timer->scheduled-curr->scheduled) < 0) {
+ break;
+ }
+ }
+
+ /* Insert the timer here! */
+ if (prev) {
+ prev->next = timer;
+ } else {
+ data->timers = timer;
+ }
+ timer->next = curr;
+}
+
+static int SDLCALL
+SDL_TimerThread(void *_data)
+{
+ SDL_TimerData *data = (SDL_TimerData *)_data;
+ SDL_Timer *pending;
+ SDL_Timer *current;
+ SDL_Timer *freelist_head = NULL;
+ SDL_Timer *freelist_tail = NULL;
+ Uint32 tick, now, interval, delay;
+
+ /* Threaded timer loop:
+ * 1. Queue timers added by other threads
+ * 2. Handle any timers that should dispatch this cycle
+ * 3. Wait until next dispatch time or new timer arrives
+ */
+ for ( ; ; ) {
+ /* Pending and freelist maintenance */
+ SDL_AtomicLock(&data->lock);
+ {
+ /* Get any timers ready to be queued */
+ pending = data->pending;
+ data->pending = NULL;
+
+ /* Make any unused timer structures available */
+ if (freelist_head) {
+ freelist_tail->next = data->freelist;
+ data->freelist = freelist_head;
+ }
+ }
+ SDL_AtomicUnlock(&data->lock);
+
+ /* Sort the pending timers into our list */
+ while (pending) {
+ current = pending;
+ pending = pending->next;
+ SDL_AddTimerInternal(data, current);
+ }
+ freelist_head = NULL;
+ freelist_tail = NULL;
+
+ /* Check to see if we're still running, after maintenance */
+ if (!SDL_AtomicGet(&data->active)) {
+ break;
+ }
+
+ /* Initial delay if there are no timers */
+ delay = SDL_MUTEX_MAXWAIT;
+
+ tick = SDL_GetTicks();
+
+ /* Process all the pending timers for this tick */
+ while (data->timers) {
+ current = data->timers;
+
+ if ((Sint32)(tick-current->scheduled) < 0) {
+ /* Scheduled for the future, wait a bit */
+ delay = (current->scheduled - tick);
+ break;
+ }
+
+ /* We're going to do something with this timer */
+ data->timers = current->next;
+
+ if (SDL_AtomicGet(&current->canceled)) {
+ interval = 0;
+ } else {
+ interval = current->callback(current->interval, current->param);
+ }
+
+ if (interval > 0) {
+ /* Reschedule this timer */
+ current->interval = interval;
+ current->scheduled = tick + interval;
+ SDL_AddTimerInternal(data, current);
+ } else {
+ if (!freelist_head) {
+ freelist_head = current;
+ }
+ if (freelist_tail) {
+ freelist_tail->next = current;
+ }
+ freelist_tail = current;
+
+ SDL_AtomicSet(&current->canceled, 1);
+ }
+ }
+
+ /* Adjust the delay based on processing time */
+ now = SDL_GetTicks();
+ interval = (now - tick);
+ if (interval > delay) {
+ delay = 0;
+ } else {
+ delay -= interval;
+ }
+
+ /* Note that each time a timer is added, this will return
+ immediately, but we process the timers added all at once.
+ That's okay, it just means we run through the loop a few
+ extra times.
+ */
+ SDL_SemWaitTimeout(data->sem, delay);
+ }
+ return 0;
+}
+
+int
+SDL_TimerInit(void)
+{
+ SDL_TimerData *data = &SDL_timer_data;
+
+ if (!SDL_AtomicGet(&data->active)) {
+ const char *name = "SDLTimer";
+ data->timermap_lock = SDL_CreateMutex();
+ if (!data->timermap_lock) {
+ return -1;
+ }
+
+ data->sem = SDL_CreateSemaphore(0);
+ if (!data->sem) {
+ SDL_DestroyMutex(data->timermap_lock);
+ return -1;
+ }
+
+ SDL_AtomicSet(&data->active, 1);
+
+ /* Timer threads use a callback into the app, so we can't set a limited stack size here. */
+ data->thread = SDL_CreateThreadInternal(SDL_TimerThread, name, 0, data);
+ if (!data->thread) {
+ SDL_TimerQuit();
+ return -1;
+ }
+
+ SDL_AtomicSet(&data->nextID, 1);
+ }
+ return 0;
+}
+
+void
+SDL_TimerQuit(void)
+{
+ SDL_TimerData *data = &SDL_timer_data;
+ SDL_Timer *timer;
+ SDL_TimerMap *entry;
+
+ if (SDL_AtomicCAS(&data->active, 1, 0)) { /* active? Move to inactive. */
+ /* Shutdown the timer thread */
+ if (data->thread) {
+ SDL_SemPost(data->sem);
+ SDL_WaitThread(data->thread, NULL);
+ data->thread = NULL;
+ }
+
+ SDL_DestroySemaphore(data->sem);
+ data->sem = NULL;
+
+ /* Clean up the timer entries */
+ while (data->timers) {
+ timer = data->timers;
+ data->timers = timer->next;
+ SDL_free(timer);
+ }
+ while (data->freelist) {
+ timer = data->freelist;
+ data->freelist = timer->next;
+ SDL_free(timer);
+ }
+ while (data->timermap) {
+ entry = data->timermap;
+ data->timermap = entry->next;
+ SDL_free(entry);
+ }
+
+ SDL_DestroyMutex(data->timermap_lock);
+ data->timermap_lock = NULL;
+ }
+}
+
+SDL_TimerID
+SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param)
+{
+ SDL_TimerData *data = &SDL_timer_data;
+ SDL_Timer *timer;
+ SDL_TimerMap *entry;
+
+ SDL_AtomicLock(&data->lock);
+ if (!SDL_AtomicGet(&data->active)) {
+ if (SDL_TimerInit() < 0) {
+ SDL_AtomicUnlock(&data->lock);
+ return 0;
+ }
+ }
+
+ timer = data->freelist;
+ if (timer) {
+ data->freelist = timer->next;
+ }
+ SDL_AtomicUnlock(&data->lock);
+
+ if (timer) {
+ SDL_RemoveTimer(timer->timerID);
+ } else {
+ timer = (SDL_Timer *)SDL_malloc(sizeof(*timer));
+ if (!timer) {
+ SDL_OutOfMemory();
+ return 0;
+ }
+ }
+ timer->timerID = SDL_AtomicIncRef(&data->nextID);
+ timer->callback = callback;
+ timer->param = param;
+ timer->interval = interval;
+ timer->scheduled = SDL_GetTicks() + interval;
+ SDL_AtomicSet(&timer->canceled, 0);
+
+ entry = (SDL_TimerMap *)SDL_malloc(sizeof(*entry));
+ if (!entry) {
+ SDL_free(timer);
+ SDL_OutOfMemory();
+ return 0;
+ }
+ entry->timer = timer;
+ entry->timerID = timer->timerID;
+
+ SDL_LockMutex(data->timermap_lock);
+ entry->next = data->timermap;
+ data->timermap = entry;
+ SDL_UnlockMutex(data->timermap_lock);
+
+ /* Add the timer to the pending list for the timer thread */
+ SDL_AtomicLock(&data->lock);
+ timer->next = data->pending;
+ data->pending = timer;
+ SDL_AtomicUnlock(&data->lock);
+
+ /* Wake up the timer thread if necessary */
+ SDL_SemPost(data->sem);
+
+ return entry->timerID;
+}
+
+SDL_bool
+SDL_RemoveTimer(SDL_TimerID id)
+{
+ SDL_TimerData *data = &SDL_timer_data;
+ SDL_TimerMap *prev, *entry;
+ SDL_bool canceled = SDL_FALSE;
+
+ /* Find the timer */
+ SDL_LockMutex(data->timermap_lock);
+ prev = NULL;
+ for (entry = data->timermap; entry; prev = entry, entry = entry->next) {
+ if (entry->timerID == id) {
+ if (prev) {
+ prev->next = entry->next;
+ } else {
+ data->timermap = entry->next;
+ }
+ break;
+ }
+ }
+ SDL_UnlockMutex(data->timermap_lock);
+
+ if (entry) {
+ if (!SDL_AtomicGet(&entry->timer->canceled)) {
+ SDL_AtomicSet(&entry->timer->canceled, 1);
+ canceled = SDL_TRUE;
+ }
+ SDL_free(entry);
+ }
+ return canceled;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/timer/SDL_timer_c.h b/src/3rdparty/SDL2/src/timer/SDL_timer_c.h
new file mode 100644
index 0000000..f83bdde
--- /dev/null
+++ b/src/3rdparty/SDL2/src/timer/SDL_timer_c.h
@@ -0,0 +1,34 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* Useful functions and variables from SDL_timer.c */
+#include "SDL_timer.h"
+
+#define ROUND_RESOLUTION(X) \
+ (((X+TIMER_RESOLUTION-1)/TIMER_RESOLUTION)*TIMER_RESOLUTION)
+
+extern void SDL_TicksInit(void);
+extern void SDL_TicksQuit(void);
+extern int SDL_TimerInit(void);
+extern void SDL_TimerQuit(void);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/timer/dummy/SDL_systimer.c b/src/3rdparty/SDL2/src/timer/dummy/SDL_systimer.c
new file mode 100644
index 0000000..aff145b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/timer/dummy/SDL_systimer.c
@@ -0,0 +1,75 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if defined(SDL_TIMER_DUMMY) || defined(SDL_TIMERS_DISABLED)
+
+#include "SDL_timer.h"
+
+static SDL_bool ticks_started = SDL_FALSE;
+
+void
+SDL_TicksInit(void)
+{
+ if (ticks_started) {
+ return;
+ }
+ ticks_started = SDL_TRUE;
+}
+
+void
+SDL_TicksQuit(void)
+{
+ ticks_started = SDL_FALSE;
+}
+
+Uint32
+SDL_GetTicks(void)
+{
+ if (!ticks_started) {
+ SDL_TicksInit();
+ }
+
+ SDL_Unsupported();
+ return 0;
+}
+
+Uint64
+SDL_GetPerformanceCounter(void)
+{
+ return SDL_GetTicks();
+}
+
+Uint64
+SDL_GetPerformanceFrequency(void)
+{
+ return 1000;
+}
+
+void
+SDL_Delay(Uint32 ms)
+{
+ SDL_Unsupported();
+}
+
+#endif /* SDL_TIMER_DUMMY || SDL_TIMERS_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/timer/haiku/SDL_systimer.c b/src/3rdparty/SDL2/src/timer/haiku/SDL_systimer.c
new file mode 100644
index 0000000..16f49c0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/timer/haiku/SDL_systimer.c
@@ -0,0 +1,80 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_TIMER_HAIKU
+
+#include <kernel/OS.h>
+
+#include "SDL_timer.h"
+
+static bigtime_t start;
+static SDL_bool ticks_started = SDL_FALSE;
+
+void
+SDL_TicksInit(void)
+{
+ if (ticks_started) {
+ return;
+ }
+ ticks_started = SDL_TRUE;
+
+ /* Set first ticks value */
+ start = system_time();
+}
+
+void
+SDL_TicksQuit(void)
+{
+ ticks_started = SDL_FALSE;
+}
+
+Uint32
+SDL_GetTicks(void)
+{
+ if (!ticks_started) {
+ SDL_TicksInit();
+ }
+
+ return ((system_time() - start) / 1000);
+}
+
+Uint64
+SDL_GetPerformanceCounter(void)
+{
+ return system_time();
+}
+
+Uint64
+SDL_GetPerformanceFrequency(void)
+{
+ return 1000000;
+}
+
+void
+SDL_Delay(Uint32 ms)
+{
+ snooze(ms * 1000);
+}
+
+#endif /* SDL_TIMER_HAIKU */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/timer/psp/SDL_systimer.c b/src/3rdparty/SDL2/src/timer/psp/SDL_systimer.c
new file mode 100644
index 0000000..e39d800
--- /dev/null
+++ b/src/3rdparty/SDL2/src/timer/psp/SDL_systimer.c
@@ -0,0 +1,91 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_TIMERS_PSP
+
+#include "SDL_thread.h"
+#include "SDL_timer.h"
+#include "SDL_error.h"
+#include "../SDL_timer_c.h"
+#include <stdlib.h>
+#include <time.h>
+#include <sys/time.h>
+#include <pspthreadman.h>
+
+static struct timeval start;
+static SDL_bool ticks_started = SDL_FALSE;
+
+void
+SDL_TicksInit(void)
+{
+ if (ticks_started) {
+ return;
+ }
+ ticks_started = SDL_TRUE;
+
+ gettimeofday(&start, NULL);
+}
+
+void
+SDL_TicksQuit(void)
+{
+ ticks_started = SDL_FALSE;
+}
+
+Uint32 SDL_GetTicks(void)
+{
+ if (!ticks_started) {
+ SDL_TicksInit();
+ }
+
+ struct timeval now;
+ Uint32 ticks;
+
+ gettimeofday(&now, NULL);
+ ticks=(now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000;
+ return(ticks);
+}
+
+Uint64
+SDL_GetPerformanceCounter(void)
+{
+ return SDL_GetTicks();
+}
+
+Uint64
+SDL_GetPerformanceFrequency(void)
+{
+ return 1000;
+}
+
+void SDL_Delay(Uint32 ms)
+{
+ const Uint32 max_delay = 0xffffffffUL / 1000;
+ if(ms > max_delay)
+ ms = max_delay;
+ sceKernelDelayThreadCB(ms * 1000);
+}
+
+#endif /* SDL_TIMERS_PSP */
+
+/* vim: ts=4 sw=4
+ */
diff --git a/src/3rdparty/SDL2/src/timer/unix/SDL_systimer.c b/src/3rdparty/SDL2/src/timer/unix/SDL_systimer.c
new file mode 100644
index 0000000..5045996
--- /dev/null
+++ b/src/3rdparty/SDL2/src/timer/unix/SDL_systimer.c
@@ -0,0 +1,232 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_TIMER_UNIX
+
+#include <stdio.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include "SDL_timer.h"
+#include "SDL_assert.h"
+#include "../SDL_timer_c.h"
+
+/* The clock_gettime provides monotonous time, so we should use it if
+ it's available. The clock_gettime function is behind ifdef
+ for __USE_POSIX199309
+ Tommi Kyntola (tommi.kyntola@ray.fi) 27/09/2005
+*/
+/* Reworked monotonic clock to not assume the current system has one
+ as not all linux kernels provide a monotonic clock (yeah recent ones
+ probably do)
+ Also added OS X Monotonic clock support
+ Based on work in https://github.com/ThomasHabets/monotonic_clock
+ */
+#if HAVE_NANOSLEEP || HAVE_CLOCK_GETTIME
+#include <time.h>
+#endif
+#ifdef __APPLE__
+#include <mach/mach_time.h>
+#endif
+
+/* Use CLOCK_MONOTONIC_RAW, if available, which is not subject to adjustment by NTP */
+#if HAVE_CLOCK_GETTIME
+#ifdef CLOCK_MONOTONIC_RAW
+#define SDL_MONOTONIC_CLOCK CLOCK_MONOTONIC_RAW
+#else
+#define SDL_MONOTONIC_CLOCK CLOCK_MONOTONIC
+#endif
+#endif
+
+/* The first ticks value of the application */
+#if HAVE_CLOCK_GETTIME
+static struct timespec start_ts;
+#elif defined(__APPLE__)
+static uint64_t start_mach;
+mach_timebase_info_data_t mach_base_info;
+#endif
+static SDL_bool has_monotonic_time = SDL_FALSE;
+static struct timeval start_tv;
+static SDL_bool ticks_started = SDL_FALSE;
+
+void
+SDL_TicksInit(void)
+{
+ if (ticks_started) {
+ return;
+ }
+ ticks_started = SDL_TRUE;
+
+ /* Set first ticks value */
+#if HAVE_CLOCK_GETTIME
+ if (clock_gettime(SDL_MONOTONIC_CLOCK, &start_ts) == 0) {
+ has_monotonic_time = SDL_TRUE;
+ } else
+#elif defined(__APPLE__)
+ kern_return_t ret = mach_timebase_info(&mach_base_info);
+ if (ret == 0) {
+ has_monotonic_time = SDL_TRUE;
+ start_mach = mach_absolute_time();
+ } else
+#endif
+ {
+ gettimeofday(&start_tv, NULL);
+ }
+}
+
+void
+SDL_TicksQuit(void)
+{
+ ticks_started = SDL_FALSE;
+}
+
+Uint32
+SDL_GetTicks(void)
+{
+ Uint32 ticks;
+ if (!ticks_started) {
+ SDL_TicksInit();
+ }
+
+ if (has_monotonic_time) {
+#if HAVE_CLOCK_GETTIME
+ struct timespec now;
+ clock_gettime(SDL_MONOTONIC_CLOCK, &now);
+ ticks = (now.tv_sec - start_ts.tv_sec) * 1000 + (now.tv_nsec -
+ start_ts.tv_nsec) / 1000000;
+#elif defined(__APPLE__)
+ uint64_t now = mach_absolute_time();
+ ticks = (Uint32)((((now - start_mach) * mach_base_info.numer) / mach_base_info.denom) / 1000000);
+#else
+ SDL_assert(SDL_FALSE);
+ ticks = 0;
+#endif
+ } else {
+ struct timeval now;
+
+ gettimeofday(&now, NULL);
+ ticks = (Uint32)((now.tv_sec - start_tv.tv_sec) * 1000 + (now.tv_usec - start_tv.tv_usec) / 1000);
+ }
+ return (ticks);
+}
+
+Uint64
+SDL_GetPerformanceCounter(void)
+{
+ Uint64 ticks;
+ if (!ticks_started) {
+ SDL_TicksInit();
+ }
+
+ if (has_monotonic_time) {
+#if HAVE_CLOCK_GETTIME
+ struct timespec now;
+
+ clock_gettime(SDL_MONOTONIC_CLOCK, &now);
+ ticks = now.tv_sec;
+ ticks *= 1000000000;
+ ticks += now.tv_nsec;
+#elif defined(__APPLE__)
+ ticks = mach_absolute_time();
+#else
+ SDL_assert(SDL_FALSE);
+ ticks = 0;
+#endif
+ } else {
+ struct timeval now;
+
+ gettimeofday(&now, NULL);
+ ticks = now.tv_sec;
+ ticks *= 1000000;
+ ticks += now.tv_usec;
+ }
+ return (ticks);
+}
+
+Uint64
+SDL_GetPerformanceFrequency(void)
+{
+ if (!ticks_started) {
+ SDL_TicksInit();
+ }
+
+ if (has_monotonic_time) {
+#if HAVE_CLOCK_GETTIME
+ return 1000000000;
+#elif defined(__APPLE__)
+ Uint64 freq = mach_base_info.denom;
+ freq *= 1000000000;
+ freq /= mach_base_info.numer;
+ return freq;
+#endif
+ }
+
+ return 1000000;
+}
+
+void
+SDL_Delay(Uint32 ms)
+{
+ int was_error;
+
+#if HAVE_NANOSLEEP
+ struct timespec elapsed, tv;
+#else
+ struct timeval tv;
+ Uint32 then, now, elapsed;
+#endif
+
+ /* Set the timeout interval */
+#if HAVE_NANOSLEEP
+ elapsed.tv_sec = ms / 1000;
+ elapsed.tv_nsec = (ms % 1000) * 1000000;
+#else
+ then = SDL_GetTicks();
+#endif
+ do {
+ errno = 0;
+
+#if HAVE_NANOSLEEP
+ tv.tv_sec = elapsed.tv_sec;
+ tv.tv_nsec = elapsed.tv_nsec;
+ was_error = nanosleep(&tv, &elapsed);
+#else
+ /* Calculate the time interval left (in case of interrupt) */
+ now = SDL_GetTicks();
+ elapsed = (now - then);
+ then = now;
+ if (elapsed >= ms) {
+ break;
+ }
+ ms -= elapsed;
+ tv.tv_sec = ms / 1000;
+ tv.tv_usec = (ms % 1000) * 1000;
+
+ was_error = select(0, NULL, NULL, NULL, &tv);
+#endif /* HAVE_NANOSLEEP */
+ } while (was_error && (errno == EINTR));
+}
+
+#endif /* SDL_TIMER_UNIX */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/timer/windows/SDL_systimer.c b/src/3rdparty/SDL2/src/timer/windows/SDL_systimer.c
new file mode 100644
index 0000000..3f5413b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/timer/windows/SDL_systimer.c
@@ -0,0 +1,200 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifdef SDL_TIMER_WINDOWS
+
+#include "../../core/windows/SDL_windows.h"
+#include <mmsystem.h>
+
+#include "SDL_timer.h"
+#include "SDL_hints.h"
+
+
+/* The first (low-resolution) ticks value of the application */
+static DWORD start = 0;
+static BOOL ticks_started = FALSE;
+
+/* Store if a high-resolution performance counter exists on the system */
+static BOOL hires_timer_available;
+/* The first high-resolution ticks value of the application */
+static LARGE_INTEGER hires_start_ticks;
+/* The number of ticks per second of the high-resolution performance counter */
+static LARGE_INTEGER hires_ticks_per_second;
+
+static void
+SDL_SetSystemTimerResolution(const UINT uPeriod)
+{
+#ifndef __WINRT__
+ static UINT timer_period = 0;
+
+ if (uPeriod != timer_period) {
+ if (timer_period) {
+ timeEndPeriod(timer_period);
+ }
+
+ timer_period = uPeriod;
+
+ if (timer_period) {
+ timeBeginPeriod(timer_period);
+ }
+ }
+#endif
+}
+
+static void SDLCALL
+SDL_TimerResolutionChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+{
+ UINT uPeriod;
+
+ /* Unless the hint says otherwise, let's have good sleep precision */
+ if (hint && *hint) {
+ uPeriod = SDL_atoi(hint);
+ } else {
+ uPeriod = 1;
+ }
+ if (uPeriod || oldValue != hint) {
+ SDL_SetSystemTimerResolution(uPeriod);
+ }
+}
+
+void
+SDL_TicksInit(void)
+{
+ if (ticks_started) {
+ return;
+ }
+ ticks_started = SDL_TRUE;
+
+ /* if we didn't set a precision, set it high. This affects lots of things
+ on Windows besides the SDL timers, like audio callbacks, etc. */
+ SDL_AddHintCallback(SDL_HINT_TIMER_RESOLUTION,
+ SDL_TimerResolutionChanged, NULL);
+
+ /* Set first ticks value */
+ /* QueryPerformanceCounter has had problems in the past, but lots of games
+ use it, so we'll rely on it here.
+ */
+ if (QueryPerformanceFrequency(&hires_ticks_per_second) == TRUE) {
+ hires_timer_available = TRUE;
+ QueryPerformanceCounter(&hires_start_ticks);
+ } else {
+ hires_timer_available = FALSE;
+#ifndef __WINRT__
+ start = timeGetTime();
+#endif /* __WINRT__ */
+ }
+}
+
+void
+SDL_TicksQuit(void)
+{
+ SDL_DelHintCallback(SDL_HINT_TIMER_RESOLUTION,
+ SDL_TimerResolutionChanged, NULL);
+
+ SDL_SetSystemTimerResolution(0); /* always release our timer resolution request. */
+
+ start = 0;
+ ticks_started = SDL_FALSE;
+}
+
+Uint32
+SDL_GetTicks(void)
+{
+ DWORD now = 0;
+ LARGE_INTEGER hires_now;
+
+ if (!ticks_started) {
+ SDL_TicksInit();
+ }
+
+ if (hires_timer_available) {
+ QueryPerformanceCounter(&hires_now);
+
+ hires_now.QuadPart -= hires_start_ticks.QuadPart;
+ hires_now.QuadPart *= 1000;
+ hires_now.QuadPart /= hires_ticks_per_second.QuadPart;
+
+ return (DWORD) hires_now.QuadPart;
+ } else {
+#ifndef __WINRT__
+ now = timeGetTime();
+#endif /* __WINRT__ */
+ }
+
+ return (now - start);
+}
+
+Uint64
+SDL_GetPerformanceCounter(void)
+{
+ LARGE_INTEGER counter;
+
+ if (!QueryPerformanceCounter(&counter)) {
+ return SDL_GetTicks();
+ }
+ return counter.QuadPart;
+}
+
+Uint64
+SDL_GetPerformanceFrequency(void)
+{
+ LARGE_INTEGER frequency;
+
+ if (!QueryPerformanceFrequency(&frequency)) {
+ return 1000;
+ }
+ return frequency.QuadPart;
+}
+
+void
+SDL_Delay(Uint32 ms)
+{
+ /* Sleep() is not publicly available to apps in early versions of WinRT.
+ *
+ * Visual C++ 2013 Update 4 re-introduced Sleep() for Windows 8.1 and
+ * Windows Phone 8.1.
+ *
+ * Use the compiler version to determine availability.
+ *
+ * NOTE #1: _MSC_FULL_VER == 180030723 for Visual C++ 2013 Update 3.
+ * NOTE #2: Visual C++ 2013, when compiling for Windows 8.0 and
+ * Windows Phone 8.0, uses the Visual C++ 2012 compiler to build
+ * apps and libraries.
+ */
+#if defined(__WINRT__) && defined(_MSC_FULL_VER) && (_MSC_FULL_VER <= 180030723)
+ static HANDLE mutex = 0;
+ if (!mutex) {
+ mutex = CreateEventEx(0, 0, 0, EVENT_ALL_ACCESS);
+ }
+ WaitForSingleObjectEx(mutex, ms, FALSE);
+#else
+ if (!ticks_started) {
+ SDL_TicksInit();
+ }
+
+ Sleep(ms);
+#endif
+}
+
+#endif /* SDL_TIMER_WINDOWS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_RLEaccel.c b/src/3rdparty/SDL2/src/video/SDL_RLEaccel.c
new file mode 100644
index 0000000..661cb1f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_RLEaccel.c
@@ -0,0 +1,1581 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/*
+ * RLE encoding for software colorkey and alpha-channel acceleration
+ *
+ * Original version by Sam Lantinga
+ *
+ * Mattias Engdegrd (Yorick): Rewrite. New encoding format, encoder and
+ * decoder. Added per-surface alpha blitter. Added per-pixel alpha
+ * format, encoder and blitter.
+ *
+ * Many thanks to Xark and johns for hints, benchmarks and useful comments
+ * leading to this code.
+ *
+ * Welcome to Macro Mayhem.
+ */
+
+/*
+ * The encoding translates the image data to a stream of segments of the form
+ *
+ * <skip> <run> <data>
+ *
+ * where <skip> is the number of transparent pixels to skip,
+ * <run> is the number of opaque pixels to blit,
+ * and <data> are the pixels themselves.
+ *
+ * This basic structure is used both for colorkeyed surfaces, used for simple
+ * binary transparency and for per-surface alpha blending, and for surfaces
+ * with per-pixel alpha. The details differ, however:
+ *
+ * Encoding of colorkeyed surfaces:
+ *
+ * Encoded pixels always have the same format as the target surface.
+ * <skip> and <run> are unsigned 8 bit integers, except for 32 bit depth
+ * where they are 16 bit. This makes the pixel data aligned at all times.
+ * Segments never wrap around from one scan line to the next.
+ *
+ * The end of the sequence is marked by a zero <skip>,<run> pair at the *
+ * beginning of a line.
+ *
+ * Encoding of surfaces with per-pixel alpha:
+ *
+ * The sequence begins with a struct RLEDestFormat describing the target
+ * pixel format, to provide reliable un-encoding.
+ *
+ * Each scan line is encoded twice: First all completely opaque pixels,
+ * encoded in the target format as described above, and then all
+ * partially transparent (translucent) pixels (where 1 <= alpha <= 254),
+ * in the following 32-bit format:
+ *
+ * For 32-bit targets, each pixel has the target RGB format but with
+ * the alpha value occupying the highest 8 bits. The <skip> and <run>
+ * counts are 16 bit.
+ *
+ * For 16-bit targets, each pixel has the target RGB format, but with
+ * the middle component (usually green) shifted 16 steps to the left,
+ * and the hole filled with the 5 most significant bits of the alpha value.
+ * i.e. if the target has the format rrrrrggggggbbbbb,
+ * the encoded pixel will be 00000gggggg00000rrrrr0aaaaabbbbb.
+ * The <skip> and <run> counts are 8 bit for the opaque lines, 16 bit
+ * for the translucent lines. Two padding bytes may be inserted
+ * before each translucent line to keep them 32-bit aligned.
+ *
+ * The end of the sequence is marked by a zero <skip>,<run> pair at the
+ * beginning of an opaque line.
+ */
+
+#include "SDL_video.h"
+#include "SDL_sysvideo.h"
+#include "SDL_blit.h"
+#include "SDL_RLEaccel_c.h"
+
+#ifndef MIN
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#endif
+
+#define PIXEL_COPY(to, from, len, bpp) \
+ SDL_memcpy(to, from, (size_t)(len) * (bpp))
+
+/*
+ * Various colorkey blit methods, for opaque and per-surface alpha
+ */
+
+#define OPAQUE_BLIT(to, from, length, bpp, alpha) \
+ PIXEL_COPY(to, from, length, bpp)
+
+/*
+ * For 32bpp pixels on the form 0x00rrggbb:
+ * If we treat the middle component separately, we can process the two
+ * remaining in parallel. This is safe to do because of the gap to the left
+ * of each component, so the bits from the multiplication don't collide.
+ * This can be used for any RGB permutation of course.
+ */
+#define ALPHA_BLIT32_888(to, from, length, bpp, alpha) \
+ do { \
+ int i; \
+ Uint32 *src = (Uint32 *)(from); \
+ Uint32 *dst = (Uint32 *)(to); \
+ for (i = 0; i < (int)(length); i++) { \
+ Uint32 s = *src++; \
+ Uint32 d = *dst; \
+ Uint32 s1 = s & 0xff00ff; \
+ Uint32 d1 = d & 0xff00ff; \
+ d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \
+ s &= 0xff00; \
+ d &= 0xff00; \
+ d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
+ *dst++ = d1 | d; \
+ } \
+ } while (0)
+
+/*
+ * For 16bpp pixels we can go a step further: put the middle component
+ * in the high 16 bits of a 32 bit word, and process all three RGB
+ * components at the same time. Since the smallest gap is here just
+ * 5 bits, we have to scale alpha down to 5 bits as well.
+ */
+#define ALPHA_BLIT16_565(to, from, length, bpp, alpha) \
+ do { \
+ int i; \
+ Uint16 *src = (Uint16 *)(from); \
+ Uint16 *dst = (Uint16 *)(to); \
+ Uint32 ALPHA = alpha >> 3; \
+ for(i = 0; i < (int)(length); i++) { \
+ Uint32 s = *src++; \
+ Uint32 d = *dst; \
+ s = (s | s << 16) & 0x07e0f81f; \
+ d = (d | d << 16) & 0x07e0f81f; \
+ d += (s - d) * ALPHA >> 5; \
+ d &= 0x07e0f81f; \
+ *dst++ = (Uint16)(d | d >> 16); \
+ } \
+ } while(0)
+
+#define ALPHA_BLIT16_555(to, from, length, bpp, alpha) \
+ do { \
+ int i; \
+ Uint16 *src = (Uint16 *)(from); \
+ Uint16 *dst = (Uint16 *)(to); \
+ Uint32 ALPHA = alpha >> 3; \
+ for(i = 0; i < (int)(length); i++) { \
+ Uint32 s = *src++; \
+ Uint32 d = *dst; \
+ s = (s | s << 16) & 0x03e07c1f; \
+ d = (d | d << 16) & 0x03e07c1f; \
+ d += (s - d) * ALPHA >> 5; \
+ d &= 0x03e07c1f; \
+ *dst++ = (Uint16)(d | d >> 16); \
+ } \
+ } while(0)
+
+/*
+ * The general slow catch-all function, for remaining depths and formats
+ */
+#define ALPHA_BLIT_ANY(to, from, length, bpp, alpha) \
+ do { \
+ int i; \
+ Uint8 *src = from; \
+ Uint8 *dst = to; \
+ for (i = 0; i < (int)(length); i++) { \
+ Uint32 s, d; \
+ unsigned rs, gs, bs, rd, gd, bd; \
+ switch (bpp) { \
+ case 2: \
+ s = *(Uint16 *)src; \
+ d = *(Uint16 *)dst; \
+ break; \
+ case 3: \
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { \
+ s = (src[0] << 16) | (src[1] << 8) | src[2]; \
+ d = (dst[0] << 16) | (dst[1] << 8) | dst[2]; \
+ } else { \
+ s = (src[2] << 16) | (src[1] << 8) | src[0]; \
+ d = (dst[2] << 16) | (dst[1] << 8) | dst[0]; \
+ } \
+ break; \
+ case 4: \
+ s = *(Uint32 *)src; \
+ d = *(Uint32 *)dst; \
+ break; \
+ } \
+ RGB_FROM_PIXEL(s, fmt, rs, gs, bs); \
+ RGB_FROM_PIXEL(d, fmt, rd, gd, bd); \
+ rd += (rs - rd) * alpha >> 8; \
+ gd += (gs - gd) * alpha >> 8; \
+ bd += (bs - bd) * alpha >> 8; \
+ PIXEL_FROM_RGB(d, fmt, rd, gd, bd); \
+ switch (bpp) { \
+ case 2: \
+ *(Uint16 *)dst = (Uint16)d; \
+ break; \
+ case 3: \
+ if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { \
+ dst[0] = (Uint8)(d >> 16); \
+ dst[1] = (Uint8)(d >> 8); \
+ dst[2] = (Uint8)(d); \
+ } else { \
+ dst[0] = (Uint8)d; \
+ dst[1] = (Uint8)(d >> 8); \
+ dst[2] = (Uint8)(d >> 16); \
+ } \
+ break; \
+ case 4: \
+ *(Uint32 *)dst = d; \
+ break; \
+ } \
+ src += bpp; \
+ dst += bpp; \
+ } \
+ } while(0)
+
+/*
+ * Special case: 50% alpha (alpha=128)
+ * This is treated specially because it can be optimized very well, and
+ * since it is good for many cases of semi-translucency.
+ * The theory is to do all three components at the same time:
+ * First zero the lowest bit of each component, which gives us room to
+ * add them. Then shift right and add the sum of the lowest bits.
+ */
+#define ALPHA_BLIT32_888_50(to, from, length, bpp, alpha) \
+ do { \
+ int i; \
+ Uint32 *src = (Uint32 *)(from); \
+ Uint32 *dst = (Uint32 *)(to); \
+ for(i = 0; i < (int)(length); i++) { \
+ Uint32 s = *src++; \
+ Uint32 d = *dst; \
+ *dst++ = (((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) \
+ + (s & d & 0x00010101); \
+ } \
+ } while(0)
+
+/*
+ * For 16bpp, we can actually blend two pixels in parallel, if we take
+ * care to shift before we add, not after.
+ */
+
+/* helper: blend a single 16 bit pixel at 50% */
+#define BLEND16_50(dst, src, mask) \
+ do { \
+ Uint32 s = *src++; \
+ Uint32 d = *dst; \
+ *dst++ = (Uint16)((((s & mask) + (d & mask)) >> 1) + \
+ (s & d & (~mask & 0xffff))); \
+ } while(0)
+
+/* basic 16bpp blender. mask is the pixels to keep when adding. */
+#define ALPHA_BLIT16_50(to, from, length, bpp, alpha, mask) \
+ do { \
+ unsigned n = (length); \
+ Uint16 *src = (Uint16 *)(from); \
+ Uint16 *dst = (Uint16 *)(to); \
+ if (((uintptr_t)src ^ (uintptr_t)dst) & 3) { \
+ /* source and destination not in phase, blit one by one */ \
+ while (n--) \
+ BLEND16_50(dst, src, mask); \
+ } else { \
+ if ((uintptr_t)src & 3) { \
+ /* first odd pixel */ \
+ BLEND16_50(dst, src, mask); \
+ n--; \
+ } \
+ for (; n > 1; n -= 2) { \
+ Uint32 s = *(Uint32 *)src; \
+ Uint32 d = *(Uint32 *)dst; \
+ *(Uint32 *)dst = ((s & (mask | mask << 16)) >> 1) \
+ + ((d & (mask | mask << 16)) >> 1) \
+ + (s & d & (~(mask | mask << 16))); \
+ src += 2; \
+ dst += 2; \
+ } \
+ if (n) \
+ BLEND16_50(dst, src, mask); /* last odd pixel */ \
+ } \
+ } while(0)
+
+#define ALPHA_BLIT16_565_50(to, from, length, bpp, alpha) \
+ ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xf7de)
+
+#define ALPHA_BLIT16_555_50(to, from, length, bpp, alpha) \
+ ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xfbde)
+
+#define CHOOSE_BLIT(blitter, alpha, fmt) \
+ do { \
+ if (alpha == 255) { \
+ switch (fmt->BytesPerPixel) { \
+ case 1: blitter(1, Uint8, OPAQUE_BLIT); break; \
+ case 2: blitter(2, Uint8, OPAQUE_BLIT); break; \
+ case 3: blitter(3, Uint8, OPAQUE_BLIT); break; \
+ case 4: blitter(4, Uint16, OPAQUE_BLIT); break; \
+ } \
+ } else { \
+ switch (fmt->BytesPerPixel) { \
+ case 1: \
+ /* No 8bpp alpha blitting */ \
+ break; \
+ \
+ case 2: \
+ switch (fmt->Rmask | fmt->Gmask | fmt->Bmask) { \
+ case 0xffff: \
+ if (fmt->Gmask == 0x07e0 \
+ || fmt->Rmask == 0x07e0 \
+ || fmt->Bmask == 0x07e0) { \
+ if (alpha == 128) { \
+ blitter(2, Uint8, ALPHA_BLIT16_565_50); \
+ } else { \
+ blitter(2, Uint8, ALPHA_BLIT16_565); \
+ } \
+ } else \
+ goto general16; \
+ break; \
+ \
+ case 0x7fff: \
+ if (fmt->Gmask == 0x03e0 \
+ || fmt->Rmask == 0x03e0 \
+ || fmt->Bmask == 0x03e0) { \
+ if (alpha == 128) { \
+ blitter(2, Uint8, ALPHA_BLIT16_555_50); \
+ } else { \
+ blitter(2, Uint8, ALPHA_BLIT16_555); \
+ } \
+ break; \
+ } else \
+ goto general16; \
+ break; \
+ \
+ default: \
+ general16: \
+ blitter(2, Uint8, ALPHA_BLIT_ANY); \
+ } \
+ break; \
+ \
+ case 3: \
+ blitter(3, Uint8, ALPHA_BLIT_ANY); \
+ break; \
+ \
+ case 4: \
+ if ((fmt->Rmask | fmt->Gmask | fmt->Bmask) == 0x00ffffff \
+ && (fmt->Gmask == 0xff00 || fmt->Rmask == 0xff00 \
+ || fmt->Bmask == 0xff00)) { \
+ if (alpha == 128) { \
+ blitter(4, Uint16, ALPHA_BLIT32_888_50); \
+ } else { \
+ blitter(4, Uint16, ALPHA_BLIT32_888); \
+ } \
+ } else \
+ blitter(4, Uint16, ALPHA_BLIT_ANY); \
+ break; \
+ } \
+ } \
+ } while(0)
+
+/*
+ * Set a pixel value using the given format, except that the alpha value is
+ * placed in the top byte. This is the format used for RLE with alpha.
+ */
+#define RLEPIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a) \
+{ \
+ Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \
+ ((g>>fmt->Gloss)<<fmt->Gshift)| \
+ ((b>>fmt->Bloss)<<fmt->Bshift)| \
+ (a<<24); \
+}
+
+/*
+ * This takes care of the case when the surface is clipped on the left and/or
+ * right. Top clipping has already been taken care of.
+ */
+static void
+RLEClipBlit(int w, Uint8 * srcbuf, SDL_Surface * surf_dst,
+ Uint8 * dstbuf, SDL_Rect * srcrect, unsigned alpha)
+{
+ SDL_PixelFormat *fmt = surf_dst->format;
+
+#define RLECLIPBLIT(bpp, Type, do_blit) \
+ do { \
+ int linecount = srcrect->h; \
+ int ofs = 0; \
+ int left = srcrect->x; \
+ int right = left + srcrect->w; \
+ dstbuf -= left * bpp; \
+ for (;;) { \
+ int run; \
+ ofs += *(Type *)srcbuf; \
+ run = ((Type *)srcbuf)[1]; \
+ srcbuf += 2 * sizeof(Type); \
+ if (run) { \
+ /* clip to left and right borders */ \
+ if (ofs < right) { \
+ int start = 0; \
+ int len = run; \
+ int startcol; \
+ if (left - ofs > 0) { \
+ start = left - ofs; \
+ len -= start; \
+ if (len <= 0) \
+ goto nocopy ## bpp ## do_blit; \
+ } \
+ startcol = ofs + start; \
+ if (len > right - startcol) \
+ len = right - startcol; \
+ do_blit(dstbuf + startcol * bpp, srcbuf + start * bpp, \
+ len, bpp, alpha); \
+ } \
+ nocopy ## bpp ## do_blit: \
+ srcbuf += run * bpp; \
+ ofs += run; \
+ } else if (!ofs) \
+ break; \
+ \
+ if (ofs == w) { \
+ ofs = 0; \
+ dstbuf += surf_dst->pitch; \
+ if (!--linecount) \
+ break; \
+ } \
+ } \
+ } while(0)
+
+ CHOOSE_BLIT(RLECLIPBLIT, alpha, fmt);
+
+#undef RLECLIPBLIT
+
+}
+
+
+/* blit a colorkeyed RLE surface */
+int SDLCALL
+SDL_RLEBlit(SDL_Surface * surf_src, SDL_Rect * srcrect,
+ SDL_Surface * surf_dst, SDL_Rect * dstrect)
+{
+ Uint8 *dstbuf;
+ Uint8 *srcbuf;
+ int x, y;
+ int w = surf_src->w;
+ unsigned alpha;
+
+ /* Lock the destination if necessary */
+ if (SDL_MUSTLOCK(surf_dst)) {
+ if (SDL_LockSurface(surf_dst) < 0) {
+ return (-1);
+ }
+ }
+
+ /* Set up the source and destination pointers */
+ x = dstrect->x;
+ y = dstrect->y;
+ dstbuf = (Uint8 *) surf_dst->pixels
+ + y * surf_dst->pitch + x * surf_src->format->BytesPerPixel;
+ srcbuf = (Uint8 *) surf_src->map->data;
+
+ {
+ /* skip lines at the top if necessary */
+ int vskip = srcrect->y;
+ int ofs = 0;
+ if (vskip) {
+
+#define RLESKIP(bpp, Type) \
+ for(;;) { \
+ int run; \
+ ofs += *(Type *)srcbuf; \
+ run = ((Type *)srcbuf)[1]; \
+ srcbuf += sizeof(Type) * 2; \
+ if(run) { \
+ srcbuf += run * bpp; \
+ ofs += run; \
+ } else if(!ofs) \
+ goto done; \
+ if(ofs == w) { \
+ ofs = 0; \
+ if(!--vskip) \
+ break; \
+ } \
+ }
+
+ switch (surf_src->format->BytesPerPixel) {
+ case 1:
+ RLESKIP(1, Uint8);
+ break;
+ case 2:
+ RLESKIP(2, Uint8);
+ break;
+ case 3:
+ RLESKIP(3, Uint8);
+ break;
+ case 4:
+ RLESKIP(4, Uint16);
+ break;
+ }
+
+#undef RLESKIP
+
+ }
+ }
+
+ alpha = surf_src->map->info.a;
+ /* if left or right edge clipping needed, call clip blit */
+ if (srcrect->x || srcrect->w != surf_src->w) {
+ RLEClipBlit(w, srcbuf, surf_dst, dstbuf, srcrect, alpha);
+ } else {
+ SDL_PixelFormat *fmt = surf_src->format;
+
+#define RLEBLIT(bpp, Type, do_blit) \
+ do { \
+ int linecount = srcrect->h; \
+ int ofs = 0; \
+ for(;;) { \
+ unsigned run; \
+ ofs += *(Type *)srcbuf; \
+ run = ((Type *)srcbuf)[1]; \
+ srcbuf += 2 * sizeof(Type); \
+ if(run) { \
+ do_blit(dstbuf + ofs * bpp, srcbuf, run, bpp, alpha); \
+ srcbuf += run * bpp; \
+ ofs += run; \
+ } else if(!ofs) \
+ break; \
+ if(ofs == w) { \
+ ofs = 0; \
+ dstbuf += surf_dst->pitch; \
+ if(!--linecount) \
+ break; \
+ } \
+ } \
+ } while(0)
+
+ CHOOSE_BLIT(RLEBLIT, alpha, fmt);
+
+#undef RLEBLIT
+ }
+
+ done:
+ /* Unlock the destination if necessary */
+ if (SDL_MUSTLOCK(surf_dst)) {
+ SDL_UnlockSurface(surf_dst);
+ }
+ return (0);
+}
+
+#undef OPAQUE_BLIT
+
+/*
+ * Per-pixel blitting macros for translucent pixels:
+ * These use the same techniques as the per-surface blitting macros
+ */
+
+/*
+ * For 32bpp pixels, we have made sure the alpha is stored in the top
+ * 8 bits, so proceed as usual
+ */
+#define BLIT_TRANSL_888(src, dst) \
+ do { \
+ Uint32 s = src; \
+ Uint32 d = dst; \
+ unsigned alpha = s >> 24; \
+ Uint32 s1 = s & 0xff00ff; \
+ Uint32 d1 = d & 0xff00ff; \
+ d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \
+ s &= 0xff00; \
+ d &= 0xff00; \
+ d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
+ dst = d1 | d | 0xff000000; \
+ } while(0)
+
+/*
+ * For 16bpp pixels, we have stored the 5 most significant alpha bits in
+ * bits 5-10. As before, we can process all 3 RGB components at the same time.
+ */
+#define BLIT_TRANSL_565(src, dst) \
+ do { \
+ Uint32 s = src; \
+ Uint32 d = dst; \
+ unsigned alpha = (s & 0x3e0) >> 5; \
+ s &= 0x07e0f81f; \
+ d = (d | d << 16) & 0x07e0f81f; \
+ d += (s - d) * alpha >> 5; \
+ d &= 0x07e0f81f; \
+ dst = (Uint16)(d | d >> 16); \
+ } while(0)
+
+#define BLIT_TRANSL_555(src, dst) \
+ do { \
+ Uint32 s = src; \
+ Uint32 d = dst; \
+ unsigned alpha = (s & 0x3e0) >> 5; \
+ s &= 0x03e07c1f; \
+ d = (d | d << 16) & 0x03e07c1f; \
+ d += (s - d) * alpha >> 5; \
+ d &= 0x03e07c1f; \
+ dst = (Uint16)(d | d >> 16); \
+ } while(0)
+
+/* used to save the destination format in the encoding. Designed to be
+ macro-compatible with SDL_PixelFormat but without the unneeded fields */
+typedef struct
+{
+ Uint8 BytesPerPixel;
+ Uint8 padding[3];
+ Uint32 Rmask;
+ Uint32 Gmask;
+ Uint32 Bmask;
+ Uint32 Amask;
+ Uint8 Rloss;
+ Uint8 Gloss;
+ Uint8 Bloss;
+ Uint8 Aloss;
+ Uint8 Rshift;
+ Uint8 Gshift;
+ Uint8 Bshift;
+ Uint8 Ashift;
+} RLEDestFormat;
+
+/* blit a pixel-alpha RLE surface clipped at the right and/or left edges */
+static void
+RLEAlphaClipBlit(int w, Uint8 * srcbuf, SDL_Surface * surf_dst,
+ Uint8 * dstbuf, SDL_Rect * srcrect)
+{
+ SDL_PixelFormat *df = surf_dst->format;
+ /*
+ * clipped blitter: Ptype is the destination pixel type,
+ * Ctype the translucent count type, and do_blend the macro
+ * to blend one pixel.
+ */
+#define RLEALPHACLIPBLIT(Ptype, Ctype, do_blend) \
+ do { \
+ int linecount = srcrect->h; \
+ int left = srcrect->x; \
+ int right = left + srcrect->w; \
+ dstbuf -= left * sizeof(Ptype); \
+ do { \
+ int ofs = 0; \
+ /* blit opaque pixels on one line */ \
+ do { \
+ unsigned run; \
+ ofs += ((Ctype *)srcbuf)[0]; \
+ run = ((Ctype *)srcbuf)[1]; \
+ srcbuf += 2 * sizeof(Ctype); \
+ if(run) { \
+ /* clip to left and right borders */ \
+ int cofs = ofs; \
+ int crun = run; \
+ if(left - cofs > 0) { \
+ crun -= left - cofs; \
+ cofs = left; \
+ } \
+ if(crun > right - cofs) \
+ crun = right - cofs; \
+ if(crun > 0) \
+ PIXEL_COPY(dstbuf + cofs * sizeof(Ptype), \
+ srcbuf + (cofs - ofs) * sizeof(Ptype), \
+ (unsigned)crun, sizeof(Ptype)); \
+ srcbuf += run * sizeof(Ptype); \
+ ofs += run; \
+ } else if(!ofs) \
+ return; \
+ } while(ofs < w); \
+ /* skip padding if necessary */ \
+ if(sizeof(Ptype) == 2) \
+ srcbuf += (uintptr_t)srcbuf & 2; \
+ /* blit translucent pixels on the same line */ \
+ ofs = 0; \
+ do { \
+ unsigned run; \
+ ofs += ((Uint16 *)srcbuf)[0]; \
+ run = ((Uint16 *)srcbuf)[1]; \
+ srcbuf += 4; \
+ if(run) { \
+ /* clip to left and right borders */ \
+ int cofs = ofs; \
+ int crun = run; \
+ if(left - cofs > 0) { \
+ crun -= left - cofs; \
+ cofs = left; \
+ } \
+ if(crun > right - cofs) \
+ crun = right - cofs; \
+ if(crun > 0) { \
+ Ptype *dst = (Ptype *)dstbuf + cofs; \
+ Uint32 *src = (Uint32 *)srcbuf + (cofs - ofs); \
+ int i; \
+ for(i = 0; i < crun; i++) \
+ do_blend(src[i], dst[i]); \
+ } \
+ srcbuf += run * 4; \
+ ofs += run; \
+ } \
+ } while(ofs < w); \
+ dstbuf += surf_dst->pitch; \
+ } while(--linecount); \
+ } while(0)
+
+ switch (df->BytesPerPixel) {
+ case 2:
+ if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0)
+ RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_565);
+ else
+ RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_555);
+ break;
+ case 4:
+ RLEALPHACLIPBLIT(Uint32, Uint16, BLIT_TRANSL_888);
+ break;
+ }
+}
+
+/* blit a pixel-alpha RLE surface */
+int SDLCALL
+SDL_RLEAlphaBlit(SDL_Surface * surf_src, SDL_Rect * srcrect,
+ SDL_Surface * surf_dst, SDL_Rect * dstrect)
+{
+ int x, y;
+ int w = surf_src->w;
+ Uint8 *srcbuf, *dstbuf;
+ SDL_PixelFormat *df = surf_dst->format;
+
+ /* Lock the destination if necessary */
+ if (SDL_MUSTLOCK(surf_dst)) {
+ if (SDL_LockSurface(surf_dst) < 0) {
+ return -1;
+ }
+ }
+
+ x = dstrect->x;
+ y = dstrect->y;
+ dstbuf = (Uint8 *) surf_dst->pixels + y * surf_dst->pitch + x * df->BytesPerPixel;
+ srcbuf = (Uint8 *) surf_src->map->data + sizeof(RLEDestFormat);
+
+ {
+ /* skip lines at the top if necessary */
+ int vskip = srcrect->y;
+ if (vskip) {
+ int ofs;
+ if (df->BytesPerPixel == 2) {
+ /* the 16/32 interleaved format */
+ do {
+ /* skip opaque line */
+ ofs = 0;
+ do {
+ int run;
+ ofs += srcbuf[0];
+ run = srcbuf[1];
+ srcbuf += 2;
+ if (run) {
+ srcbuf += 2 * run;
+ ofs += run;
+ } else if (!ofs)
+ goto done;
+ } while (ofs < w);
+
+ /* skip padding */
+ srcbuf += (uintptr_t) srcbuf & 2;
+
+ /* skip translucent line */
+ ofs = 0;
+ do {
+ int run;
+ ofs += ((Uint16 *) srcbuf)[0];
+ run = ((Uint16 *) srcbuf)[1];
+ srcbuf += 4 * (run + 1);
+ ofs += run;
+ } while (ofs < w);
+ } while (--vskip);
+ } else {
+ /* the 32/32 interleaved format */
+ vskip <<= 1; /* opaque and translucent have same format */
+ do {
+ ofs = 0;
+ do {
+ int run;
+ ofs += ((Uint16 *) srcbuf)[0];
+ run = ((Uint16 *) srcbuf)[1];
+ srcbuf += 4;
+ if (run) {
+ srcbuf += 4 * run;
+ ofs += run;
+ } else if (!ofs)
+ goto done;
+ } while (ofs < w);
+ } while (--vskip);
+ }
+ }
+ }
+
+ /* if left or right edge clipping needed, call clip blit */
+ if (srcrect->x || srcrect->w != surf_src->w) {
+ RLEAlphaClipBlit(w, srcbuf, surf_dst, dstbuf, srcrect);
+ } else {
+
+ /*
+ * non-clipped blitter. Ptype is the destination pixel type,
+ * Ctype the translucent count type, and do_blend the
+ * macro to blend one pixel.
+ */
+#define RLEALPHABLIT(Ptype, Ctype, do_blend) \
+ do { \
+ int linecount = srcrect->h; \
+ do { \
+ int ofs = 0; \
+ /* blit opaque pixels on one line */ \
+ do { \
+ unsigned run; \
+ ofs += ((Ctype *)srcbuf)[0]; \
+ run = ((Ctype *)srcbuf)[1]; \
+ srcbuf += 2 * sizeof(Ctype); \
+ if(run) { \
+ PIXEL_COPY(dstbuf + ofs * sizeof(Ptype), srcbuf, \
+ run, sizeof(Ptype)); \
+ srcbuf += run * sizeof(Ptype); \
+ ofs += run; \
+ } else if(!ofs) \
+ goto done; \
+ } while(ofs < w); \
+ /* skip padding if necessary */ \
+ if(sizeof(Ptype) == 2) \
+ srcbuf += (uintptr_t)srcbuf & 2; \
+ /* blit translucent pixels on the same line */ \
+ ofs = 0; \
+ do { \
+ unsigned run; \
+ ofs += ((Uint16 *)srcbuf)[0]; \
+ run = ((Uint16 *)srcbuf)[1]; \
+ srcbuf += 4; \
+ if(run) { \
+ Ptype *dst = (Ptype *)dstbuf + ofs; \
+ unsigned i; \
+ for(i = 0; i < run; i++) { \
+ Uint32 src = *(Uint32 *)srcbuf; \
+ do_blend(src, *dst); \
+ srcbuf += 4; \
+ dst++; \
+ } \
+ ofs += run; \
+ } \
+ } while(ofs < w); \
+ dstbuf += surf_dst->pitch; \
+ } while(--linecount); \
+ } while(0)
+
+ switch (df->BytesPerPixel) {
+ case 2:
+ if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0
+ || df->Bmask == 0x07e0)
+ RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_565);
+ else
+ RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_555);
+ break;
+ case 4:
+ RLEALPHABLIT(Uint32, Uint16, BLIT_TRANSL_888);
+ break;
+ }
+ }
+
+ done:
+ /* Unlock the destination if necessary */
+ if (SDL_MUSTLOCK(surf_dst)) {
+ SDL_UnlockSurface(surf_dst);
+ }
+ return 0;
+}
+
+/*
+ * Auxiliary functions:
+ * The encoding functions take 32bpp rgb + a, and
+ * return the number of bytes copied to the destination.
+ * The decoding functions copy to 32bpp rgb + a, and
+ * return the number of bytes copied from the source.
+ * These are only used in the encoder and un-RLE code and are therefore not
+ * highly optimised.
+ */
+
+/* encode 32bpp rgb + a into 16bpp rgb, losing alpha */
+static int
+copy_opaque_16(void *dst, Uint32 * src, int n,
+ SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
+{
+ int i;
+ Uint16 *d = dst;
+ for (i = 0; i < n; i++) {
+ unsigned r, g, b;
+ RGB_FROM_PIXEL(*src, sfmt, r, g, b);
+ PIXEL_FROM_RGB(*d, dfmt, r, g, b);
+ src++;
+ d++;
+ }
+ return n * 2;
+}
+
+/* decode opaque pixels from 16bpp to 32bpp rgb + a */
+static int
+uncopy_opaque_16(Uint32 * dst, void *src, int n,
+ RLEDestFormat * sfmt, SDL_PixelFormat * dfmt)
+{
+ int i;
+ Uint16 *s = src;
+ unsigned alpha = dfmt->Amask ? 255 : 0;
+ for (i = 0; i < n; i++) {
+ unsigned r, g, b;
+ RGB_FROM_PIXEL(*s, sfmt, r, g, b);
+ PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, alpha);
+ s++;
+ dst++;
+ }
+ return n * 2;
+}
+
+
+
+/* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 565 */
+static int
+copy_transl_565(void *dst, Uint32 * src, int n,
+ SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
+{
+ int i;
+ Uint32 *d = dst;
+ for (i = 0; i < n; i++) {
+ unsigned r, g, b, a;
+ Uint16 pix;
+ RGBA_FROM_8888(*src, sfmt, r, g, b, a);
+ PIXEL_FROM_RGB(pix, dfmt, r, g, b);
+ *d = ((pix & 0x7e0) << 16) | (pix & 0xf81f) | ((a << 2) & 0x7e0);
+ src++;
+ d++;
+ }
+ return n * 4;
+}
+
+/* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 555 */
+static int
+copy_transl_555(void *dst, Uint32 * src, int n,
+ SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
+{
+ int i;
+ Uint32 *d = dst;
+ for (i = 0; i < n; i++) {
+ unsigned r, g, b, a;
+ Uint16 pix;
+ RGBA_FROM_8888(*src, sfmt, r, g, b, a);
+ PIXEL_FROM_RGB(pix, dfmt, r, g, b);
+ *d = ((pix & 0x3e0) << 16) | (pix & 0xfc1f) | ((a << 2) & 0x3e0);
+ src++;
+ d++;
+ }
+ return n * 4;
+}
+
+/* decode translucent pixels from 32bpp GORAB to 32bpp rgb + a */
+static int
+uncopy_transl_16(Uint32 * dst, void *src, int n,
+ RLEDestFormat * sfmt, SDL_PixelFormat * dfmt)
+{
+ int i;
+ Uint32 *s = src;
+ for (i = 0; i < n; i++) {
+ unsigned r, g, b, a;
+ Uint32 pix = *s++;
+ a = (pix & 0x3e0) >> 2;
+ pix = (pix & ~0x3e0) | pix >> 16;
+ RGB_FROM_PIXEL(pix, sfmt, r, g, b);
+ PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);
+ dst++;
+ }
+ return n * 4;
+}
+
+/* encode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */
+static int
+copy_32(void *dst, Uint32 * src, int n,
+ SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
+{
+ int i;
+ Uint32 *d = dst;
+ for (i = 0; i < n; i++) {
+ unsigned r, g, b, a;
+ RGBA_FROM_8888(*src, sfmt, r, g, b, a);
+ RLEPIXEL_FROM_RGBA(*d, dfmt, r, g, b, a);
+ d++;
+ src++;
+ }
+ return n * 4;
+}
+
+/* decode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */
+static int
+uncopy_32(Uint32 * dst, void *src, int n,
+ RLEDestFormat * sfmt, SDL_PixelFormat * dfmt)
+{
+ int i;
+ Uint32 *s = src;
+ for (i = 0; i < n; i++) {
+ unsigned r, g, b, a;
+ Uint32 pixel = *s++;
+ RGB_FROM_PIXEL(pixel, sfmt, r, g, b);
+ a = pixel >> 24;
+ PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);
+ dst++;
+ }
+ return n * 4;
+}
+
+#define ISOPAQUE(pixel, fmt) ((((pixel) & fmt->Amask) >> fmt->Ashift) == 255)
+
+#define ISTRANSL(pixel, fmt) \
+ ((unsigned)((((pixel) & fmt->Amask) >> fmt->Ashift) - 1U) < 254U)
+
+/* convert surface to be quickly alpha-blittable onto dest, if possible */
+static int
+RLEAlphaSurface(SDL_Surface * surface)
+{
+ SDL_Surface *dest;
+ SDL_PixelFormat *df;
+ int maxsize = 0;
+ int max_opaque_run;
+ int max_transl_run = 65535;
+ unsigned masksum;
+ Uint8 *rlebuf, *dst;
+ int (*copy_opaque) (void *, Uint32 *, int,
+ SDL_PixelFormat *, SDL_PixelFormat *);
+ int (*copy_transl) (void *, Uint32 *, int,
+ SDL_PixelFormat *, SDL_PixelFormat *);
+
+ dest = surface->map->dst;
+ if (!dest)
+ return -1;
+ df = dest->format;
+ if (surface->format->BitsPerPixel != 32)
+ return -1; /* only 32bpp source supported */
+
+ /* find out whether the destination is one we support,
+ and determine the max size of the encoded result */
+ masksum = df->Rmask | df->Gmask | df->Bmask;
+ switch (df->BytesPerPixel) {
+ case 2:
+ /* 16bpp: only support 565 and 555 formats */
+ switch (masksum) {
+ case 0xffff:
+ if (df->Gmask == 0x07e0
+ || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) {
+ copy_opaque = copy_opaque_16;
+ copy_transl = copy_transl_565;
+ } else
+ return -1;
+ break;
+ case 0x7fff:
+ if (df->Gmask == 0x03e0
+ || df->Rmask == 0x03e0 || df->Bmask == 0x03e0) {
+ copy_opaque = copy_opaque_16;
+ copy_transl = copy_transl_555;
+ } else
+ return -1;
+ break;
+ default:
+ return -1;
+ }
+ max_opaque_run = 255; /* runs stored as bytes */
+
+ /* worst case is alternating opaque and translucent pixels,
+ with room for alignment padding between lines */
+ maxsize = surface->h * (2 + (4 + 2) * (surface->w + 1)) + 2;
+ break;
+ case 4:
+ if (masksum != 0x00ffffff)
+ return -1; /* requires unused high byte */
+ copy_opaque = copy_32;
+ copy_transl = copy_32;
+ max_opaque_run = 255; /* runs stored as short ints */
+
+ /* worst case is alternating opaque and translucent pixels */
+ maxsize = surface->h * 2 * 4 * (surface->w + 1) + 4;
+ break;
+ default:
+ return -1; /* anything else unsupported right now */
+ }
+
+ maxsize += sizeof(RLEDestFormat);
+ rlebuf = (Uint8 *) SDL_malloc(maxsize);
+ if (!rlebuf) {
+ return SDL_OutOfMemory();
+ }
+ {
+ /* save the destination format so we can undo the encoding later */
+ RLEDestFormat *r = (RLEDestFormat *) rlebuf;
+ r->BytesPerPixel = df->BytesPerPixel;
+ r->Rmask = df->Rmask;
+ r->Gmask = df->Gmask;
+ r->Bmask = df->Bmask;
+ r->Amask = df->Amask;
+ r->Rloss = df->Rloss;
+ r->Gloss = df->Gloss;
+ r->Bloss = df->Bloss;
+ r->Aloss = df->Aloss;
+ r->Rshift = df->Rshift;
+ r->Gshift = df->Gshift;
+ r->Bshift = df->Bshift;
+ r->Ashift = df->Ashift;
+ }
+ dst = rlebuf + sizeof(RLEDestFormat);
+
+ /* Do the actual encoding */
+ {
+ int x, y;
+ int h = surface->h, w = surface->w;
+ SDL_PixelFormat *sf = surface->format;
+ Uint32 *src = (Uint32 *) surface->pixels;
+ Uint8 *lastline = dst; /* end of last non-blank line */
+
+ /* opaque counts are 8 or 16 bits, depending on target depth */
+#define ADD_OPAQUE_COUNTS(n, m) \
+ if(df->BytesPerPixel == 4) { \
+ ((Uint16 *)dst)[0] = n; \
+ ((Uint16 *)dst)[1] = m; \
+ dst += 4; \
+ } else { \
+ dst[0] = n; \
+ dst[1] = m; \
+ dst += 2; \
+ }
+
+ /* translucent counts are always 16 bit */
+#define ADD_TRANSL_COUNTS(n, m) \
+ (((Uint16 *)dst)[0] = n, ((Uint16 *)dst)[1] = m, dst += 4)
+
+ for (y = 0; y < h; y++) {
+ int runstart, skipstart;
+ int blankline = 0;
+ /* First encode all opaque pixels of a scan line */
+ x = 0;
+ do {
+ int run, skip, len;
+ skipstart = x;
+ while (x < w && !ISOPAQUE(src[x], sf))
+ x++;
+ runstart = x;
+ while (x < w && ISOPAQUE(src[x], sf))
+ x++;
+ skip = runstart - skipstart;
+ if (skip == w)
+ blankline = 1;
+ run = x - runstart;
+ while (skip > max_opaque_run) {
+ ADD_OPAQUE_COUNTS(max_opaque_run, 0);
+ skip -= max_opaque_run;
+ }
+ len = MIN(run, max_opaque_run);
+ ADD_OPAQUE_COUNTS(skip, len);
+ dst += copy_opaque(dst, src + runstart, len, sf, df);
+ runstart += len;
+ run -= len;
+ while (run) {
+ len = MIN(run, max_opaque_run);
+ ADD_OPAQUE_COUNTS(0, len);
+ dst += copy_opaque(dst, src + runstart, len, sf, df);
+ runstart += len;
+ run -= len;
+ }
+ } while (x < w);
+
+ /* Make sure the next output address is 32-bit aligned */
+ dst += (uintptr_t) dst & 2;
+
+ /* Next, encode all translucent pixels of the same scan line */
+ x = 0;
+ do {
+ int run, skip, len;
+ skipstart = x;
+ while (x < w && !ISTRANSL(src[x], sf))
+ x++;
+ runstart = x;
+ while (x < w && ISTRANSL(src[x], sf))
+ x++;
+ skip = runstart - skipstart;
+ blankline &= (skip == w);
+ run = x - runstart;
+ while (skip > max_transl_run) {
+ ADD_TRANSL_COUNTS(max_transl_run, 0);
+ skip -= max_transl_run;
+ }
+ len = MIN(run, max_transl_run);
+ ADD_TRANSL_COUNTS(skip, len);
+ dst += copy_transl(dst, src + runstart, len, sf, df);
+ runstart += len;
+ run -= len;
+ while (run) {
+ len = MIN(run, max_transl_run);
+ ADD_TRANSL_COUNTS(0, len);
+ dst += copy_transl(dst, src + runstart, len, sf, df);
+ runstart += len;
+ run -= len;
+ }
+ if (!blankline)
+ lastline = dst;
+ } while (x < w);
+
+ src += surface->pitch >> 2;
+ }
+ dst = lastline; /* back up past trailing blank lines */
+ ADD_OPAQUE_COUNTS(0, 0);
+ }
+
+#undef ADD_OPAQUE_COUNTS
+#undef ADD_TRANSL_COUNTS
+
+ /* Now that we have it encoded, release the original pixels */
+ if (!(surface->flags & SDL_PREALLOC)) {
+ SDL_free(surface->pixels);
+ surface->pixels = NULL;
+ }
+
+ /* realloc the buffer to release unused memory */
+ {
+ Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
+ if (!p)
+ p = rlebuf;
+ surface->map->data = p;
+ }
+
+ return 0;
+}
+
+static Uint32
+getpix_8(Uint8 * srcbuf)
+{
+ return *srcbuf;
+}
+
+static Uint32
+getpix_16(Uint8 * srcbuf)
+{
+ return *(Uint16 *) srcbuf;
+}
+
+static Uint32
+getpix_24(Uint8 * srcbuf)
+{
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+ return srcbuf[0] + (srcbuf[1] << 8) + (srcbuf[2] << 16);
+#else
+ return (srcbuf[0] << 16) + (srcbuf[1] << 8) + srcbuf[2];
+#endif
+}
+
+static Uint32
+getpix_32(Uint8 * srcbuf)
+{
+ return *(Uint32 *) srcbuf;
+}
+
+typedef Uint32(*getpix_func) (Uint8 *);
+
+static const getpix_func getpixes[4] = {
+ getpix_8, getpix_16, getpix_24, getpix_32
+};
+
+static int
+RLEColorkeySurface(SDL_Surface * surface)
+{
+ Uint8 *rlebuf, *dst;
+ int maxn;
+ int y;
+ Uint8 *srcbuf, *lastline;
+ int maxsize = 0;
+ const int bpp = surface->format->BytesPerPixel;
+ getpix_func getpix;
+ Uint32 ckey, rgbmask;
+ int w, h;
+
+ /* calculate the worst case size for the compressed surface */
+ switch (bpp) {
+ case 1:
+ /* worst case is alternating opaque and transparent pixels,
+ starting with an opaque pixel */
+ maxsize = surface->h * 3 * (surface->w / 2 + 1) + 2;
+ break;
+ case 2:
+ case 3:
+ /* worst case is solid runs, at most 255 pixels wide */
+ maxsize = surface->h * (2 * (surface->w / 255 + 1)
+ + surface->w * bpp) + 2;
+ break;
+ case 4:
+ /* worst case is solid runs, at most 65535 pixels wide */
+ maxsize = surface->h * (4 * (surface->w / 65535 + 1)
+ + surface->w * 4) + 4;
+ break;
+
+ default:
+ return -1;
+ }
+
+ rlebuf = (Uint8 *) SDL_malloc(maxsize);
+ if (rlebuf == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ /* Set up the conversion */
+ srcbuf = (Uint8 *) surface->pixels;
+ maxn = bpp == 4 ? 65535 : 255;
+ dst = rlebuf;
+ rgbmask = ~surface->format->Amask;
+ ckey = surface->map->info.colorkey & rgbmask;
+ lastline = dst;
+ getpix = getpixes[bpp - 1];
+ w = surface->w;
+ h = surface->h;
+
+#define ADD_COUNTS(n, m) \
+ if(bpp == 4) { \
+ ((Uint16 *)dst)[0] = n; \
+ ((Uint16 *)dst)[1] = m; \
+ dst += 4; \
+ } else { \
+ dst[0] = n; \
+ dst[1] = m; \
+ dst += 2; \
+ }
+
+ for (y = 0; y < h; y++) {
+ int x = 0;
+ int blankline = 0;
+ do {
+ int run, skip, len;
+ int runstart;
+ int skipstart = x;
+
+ /* find run of transparent, then opaque pixels */
+ while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) == ckey)
+ x++;
+ runstart = x;
+ while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) != ckey)
+ x++;
+ skip = runstart - skipstart;
+ if (skip == w)
+ blankline = 1;
+ run = x - runstart;
+
+ /* encode segment */
+ while (skip > maxn) {
+ ADD_COUNTS(maxn, 0);
+ skip -= maxn;
+ }
+ len = MIN(run, maxn);
+ ADD_COUNTS(skip, len);
+ SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
+ dst += len * bpp;
+ run -= len;
+ runstart += len;
+ while (run) {
+ len = MIN(run, maxn);
+ ADD_COUNTS(0, len);
+ SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
+ dst += len * bpp;
+ runstart += len;
+ run -= len;
+ }
+ if (!blankline)
+ lastline = dst;
+ } while (x < w);
+
+ srcbuf += surface->pitch;
+ }
+ dst = lastline; /* back up bast trailing blank lines */
+ ADD_COUNTS(0, 0);
+
+#undef ADD_COUNTS
+
+ /* Now that we have it encoded, release the original pixels */
+ if (!(surface->flags & SDL_PREALLOC)) {
+ SDL_free(surface->pixels);
+ surface->pixels = NULL;
+ }
+
+ /* realloc the buffer to release unused memory */
+ {
+ /* If realloc returns NULL, the original block is left intact */
+ Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
+ if (!p)
+ p = rlebuf;
+ surface->map->data = p;
+ }
+
+ return 0;
+}
+
+int
+SDL_RLESurface(SDL_Surface * surface)
+{
+ int flags;
+
+ /* Clear any previous RLE conversion */
+ if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
+ SDL_UnRLESurface(surface, 1);
+ }
+
+ /* We don't support RLE encoding of bitmaps */
+ if (surface->format->BitsPerPixel < 8) {
+ return -1;
+ }
+
+ /* Make sure the pixels are available */
+ if (!surface->pixels) {
+ return -1;
+ }
+
+ /* If we don't have colorkey or blending, nothing to do... */
+ flags = surface->map->info.flags;
+ if (!(flags & (SDL_COPY_COLORKEY | SDL_COPY_BLEND))) {
+ return -1;
+ }
+
+ /* Pass on combinations not supported */
+ if ((flags & SDL_COPY_MODULATE_COLOR) ||
+ ((flags & SDL_COPY_MODULATE_ALPHA) && surface->format->Amask) ||
+ (flags & (SDL_COPY_ADD | SDL_COPY_MOD)) ||
+ (flags & SDL_COPY_NEAREST)) {
+ return -1;
+ }
+
+ /* Encode and set up the blit */
+ if (!surface->format->Amask || !(flags & SDL_COPY_BLEND)) {
+ if (!surface->map->identity) {
+ return -1;
+ }
+ if (RLEColorkeySurface(surface) < 0) {
+ return -1;
+ }
+ surface->map->blit = SDL_RLEBlit;
+ surface->map->info.flags |= SDL_COPY_RLE_COLORKEY;
+ } else {
+ if (RLEAlphaSurface(surface) < 0) {
+ return -1;
+ }
+ surface->map->blit = SDL_RLEAlphaBlit;
+ surface->map->info.flags |= SDL_COPY_RLE_ALPHAKEY;
+ }
+
+ /* The surface is now accelerated */
+ surface->flags |= SDL_RLEACCEL;
+
+ return (0);
+}
+
+/*
+ * Un-RLE a surface with pixel alpha
+ * This may not give back exactly the image before RLE-encoding; all
+ * completely transparent pixels will be lost, and color and alpha depth
+ * may have been reduced (when encoding for 16bpp targets).
+ */
+static SDL_bool
+UnRLEAlpha(SDL_Surface * surface)
+{
+ Uint8 *srcbuf;
+ Uint32 *dst;
+ SDL_PixelFormat *sf = surface->format;
+ RLEDestFormat *df = surface->map->data;
+ int (*uncopy_opaque) (Uint32 *, void *, int,
+ RLEDestFormat *, SDL_PixelFormat *);
+ int (*uncopy_transl) (Uint32 *, void *, int,
+ RLEDestFormat *, SDL_PixelFormat *);
+ int w = surface->w;
+ int bpp = df->BytesPerPixel;
+
+ if (bpp == 2) {
+ uncopy_opaque = uncopy_opaque_16;
+ uncopy_transl = uncopy_transl_16;
+ } else {
+ uncopy_opaque = uncopy_transl = uncopy_32;
+ }
+
+ surface->pixels = SDL_malloc(surface->h * surface->pitch);
+ if (!surface->pixels) {
+ return (SDL_FALSE);
+ }
+ /* fill background with transparent pixels */
+ SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
+
+ dst = surface->pixels;
+ srcbuf = (Uint8 *) (df + 1);
+ for (;;) {
+ /* copy opaque pixels */
+ int ofs = 0;
+ do {
+ unsigned run;
+ if (bpp == 2) {
+ ofs += srcbuf[0];
+ run = srcbuf[1];
+ srcbuf += 2;
+ } else {
+ ofs += ((Uint16 *) srcbuf)[0];
+ run = ((Uint16 *) srcbuf)[1];
+ srcbuf += 4;
+ }
+ if (run) {
+ srcbuf += uncopy_opaque(dst + ofs, srcbuf, run, df, sf);
+ ofs += run;
+ } else if (!ofs)
+ return (SDL_TRUE);
+ } while (ofs < w);
+
+ /* skip padding if needed */
+ if (bpp == 2)
+ srcbuf += (uintptr_t) srcbuf & 2;
+
+ /* copy translucent pixels */
+ ofs = 0;
+ do {
+ unsigned run;
+ ofs += ((Uint16 *) srcbuf)[0];
+ run = ((Uint16 *) srcbuf)[1];
+ srcbuf += 4;
+ if (run) {
+ srcbuf += uncopy_transl(dst + ofs, srcbuf, run, df, sf);
+ ofs += run;
+ }
+ } while (ofs < w);
+ dst += surface->pitch >> 2;
+ }
+ /* Make the compiler happy */
+ return (SDL_TRUE);
+}
+
+void
+SDL_UnRLESurface(SDL_Surface * surface, int recode)
+{
+ if (surface->flags & SDL_RLEACCEL) {
+ surface->flags &= ~SDL_RLEACCEL;
+
+ if (recode && !(surface->flags & SDL_PREALLOC)) {
+ if (surface->map->info.flags & SDL_COPY_RLE_COLORKEY) {
+ SDL_Rect full;
+
+ /* re-create the original surface */
+ surface->pixels = SDL_malloc(surface->h * surface->pitch);
+ if (!surface->pixels) {
+ /* Oh crap... */
+ surface->flags |= SDL_RLEACCEL;
+ return;
+ }
+
+ /* fill it with the background color */
+ SDL_FillRect(surface, NULL, surface->map->info.colorkey);
+
+ /* now render the encoded surface */
+ full.x = full.y = 0;
+ full.w = surface->w;
+ full.h = surface->h;
+ SDL_RLEBlit(surface, &full, surface, &full);
+ } else {
+ if (!UnRLEAlpha(surface)) {
+ /* Oh crap... */
+ surface->flags |= SDL_RLEACCEL;
+ return;
+ }
+ }
+ }
+ surface->map->info.flags &=
+ ~(SDL_COPY_RLE_COLORKEY | SDL_COPY_RLE_ALPHAKEY);
+
+ SDL_free(surface->map->data);
+ surface->map->data = NULL;
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_RLEaccel_c.h b/src/3rdparty/SDL2/src/video/SDL_RLEaccel_c.h
new file mode 100644
index 0000000..fe41835
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_RLEaccel_c.h
@@ -0,0 +1,31 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* Useful functions and variables from SDL_RLEaccel.c */
+
+extern int SDL_RLESurface(SDL_Surface * surface);
+extern int SDLCALL SDL_RLEBlit (SDL_Surface * src, SDL_Rect * srcrect,
+ SDL_Surface * dst, SDL_Rect * dstrect);
+extern int SDLCALL SDL_RLEAlphaBlit(SDL_Surface * src, SDL_Rect * srcrect,
+ SDL_Surface * dst, SDL_Rect * dstrect);
+extern void SDL_UnRLESurface(SDL_Surface * surface, int recode);
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_blit.c b/src/3rdparty/SDL2/src/video/SDL_blit.c
new file mode 100644
index 0000000..0d4e2fd
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_blit.c
@@ -0,0 +1,296 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "SDL_video.h"
+#include "SDL_sysvideo.h"
+#include "SDL_blit.h"
+#include "SDL_blit_auto.h"
+#include "SDL_blit_copy.h"
+#include "SDL_blit_slow.h"
+#include "SDL_RLEaccel_c.h"
+#include "SDL_pixels_c.h"
+
+/* The general purpose software blit routine */
+static int SDLCALL
+SDL_SoftBlit(SDL_Surface * src, SDL_Rect * srcrect,
+ SDL_Surface * dst, SDL_Rect * dstrect)
+{
+ int okay;
+ int src_locked;
+ int dst_locked;
+
+ /* Everything is okay at the beginning... */
+ okay = 1;
+
+ /* Lock the destination if it's in hardware */
+ dst_locked = 0;
+ if (SDL_MUSTLOCK(dst)) {
+ if (SDL_LockSurface(dst) < 0) {
+ okay = 0;
+ } else {
+ dst_locked = 1;
+ }
+ }
+ /* Lock the source if it's in hardware */
+ src_locked = 0;
+ if (SDL_MUSTLOCK(src)) {
+ if (SDL_LockSurface(src) < 0) {
+ okay = 0;
+ } else {
+ src_locked = 1;
+ }
+ }
+
+ /* Set up source and destination buffer pointers, and BLIT! */
+ if (okay && !SDL_RectEmpty(srcrect)) {
+ SDL_BlitFunc RunBlit;
+ SDL_BlitInfo *info = &src->map->info;
+
+ /* Set up the blit information */
+ info->src = (Uint8 *) src->pixels +
+ (Uint16) srcrect->y * src->pitch +
+ (Uint16) srcrect->x * info->src_fmt->BytesPerPixel;
+ info->src_w = srcrect->w;
+ info->src_h = srcrect->h;
+ info->src_pitch = src->pitch;
+ info->src_skip =
+ info->src_pitch - info->src_w * info->src_fmt->BytesPerPixel;
+ info->dst =
+ (Uint8 *) dst->pixels + (Uint16) dstrect->y * dst->pitch +
+ (Uint16) dstrect->x * info->dst_fmt->BytesPerPixel;
+ info->dst_w = dstrect->w;
+ info->dst_h = dstrect->h;
+ info->dst_pitch = dst->pitch;
+ info->dst_skip =
+ info->dst_pitch - info->dst_w * info->dst_fmt->BytesPerPixel;
+ RunBlit = (SDL_BlitFunc) src->map->data;
+
+ /* Run the actual software blit */
+ RunBlit(info);
+ }
+
+ /* We need to unlock the surfaces if they're locked */
+ if (dst_locked) {
+ SDL_UnlockSurface(dst);
+ }
+ if (src_locked) {
+ SDL_UnlockSurface(src);
+ }
+ /* Blit is done! */
+ return (okay ? 0 : -1);
+}
+
+#ifdef __MACOSX__
+#include <sys/sysctl.h>
+
+static SDL_bool
+SDL_UseAltivecPrefetch()
+{
+ const char key[] = "hw.l3cachesize";
+ u_int64_t result = 0;
+ size_t typeSize = sizeof(result);
+
+ if (sysctlbyname(key, &result, &typeSize, NULL, 0) == 0 && result > 0) {
+ return SDL_TRUE;
+ } else {
+ return SDL_FALSE;
+ }
+}
+#else
+static SDL_bool
+SDL_UseAltivecPrefetch()
+{
+ /* Just guess G4 */
+ return SDL_TRUE;
+}
+#endif /* __MACOSX__ */
+
+static SDL_BlitFunc
+SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags,
+ SDL_BlitFuncEntry * entries)
+{
+ int i, flagcheck;
+ static Uint32 features = 0xffffffff;
+
+ /* Get the available CPU features */
+ if (features == 0xffffffff) {
+ const char *override = SDL_getenv("SDL_BLIT_CPU_FEATURES");
+
+ features = SDL_CPU_ANY;
+
+ /* Allow an override for testing .. */
+ if (override) {
+ SDL_sscanf(override, "%u", &features);
+ } else {
+ if (SDL_HasMMX()) {
+ features |= SDL_CPU_MMX;
+ }
+ if (SDL_Has3DNow()) {
+ features |= SDL_CPU_3DNOW;
+ }
+ if (SDL_HasSSE()) {
+ features |= SDL_CPU_SSE;
+ }
+ if (SDL_HasSSE2()) {
+ features |= SDL_CPU_SSE2;
+ }
+ if (SDL_HasAltiVec()) {
+ if (SDL_UseAltivecPrefetch()) {
+ features |= SDL_CPU_ALTIVEC_PREFETCH;
+ } else {
+ features |= SDL_CPU_ALTIVEC_NOPREFETCH;
+ }
+ }
+ }
+ }
+
+ for (i = 0; entries[i].func; ++i) {
+ /* Check for matching pixel formats */
+ if (src_format != entries[i].src_format) {
+ continue;
+ }
+ if (dst_format != entries[i].dst_format) {
+ continue;
+ }
+
+ /* Check modulation flags */
+ flagcheck =
+ (flags & (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA));
+ if ((flagcheck & entries[i].flags) != flagcheck) {
+ continue;
+ }
+
+ /* Check blend flags */
+ flagcheck =
+ (flags &
+ (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD));
+ if ((flagcheck & entries[i].flags) != flagcheck) {
+ continue;
+ }
+
+ /* Check colorkey flag */
+ flagcheck = (flags & SDL_COPY_COLORKEY);
+ if ((flagcheck & entries[i].flags) != flagcheck) {
+ continue;
+ }
+
+ /* Check scaling flags */
+ flagcheck = (flags & SDL_COPY_NEAREST);
+ if ((flagcheck & entries[i].flags) != flagcheck) {
+ continue;
+ }
+
+ /* Check CPU features */
+ flagcheck = entries[i].cpu;
+ if ((flagcheck & features) != flagcheck) {
+ continue;
+ }
+
+ /* We found the best one! */
+ return entries[i].func;
+ }
+ return NULL;
+}
+
+/* Figure out which of many blit routines to set up on a surface */
+int
+SDL_CalculateBlit(SDL_Surface * surface)
+{
+ SDL_BlitFunc blit = NULL;
+ SDL_BlitMap *map = surface->map;
+ SDL_Surface *dst = map->dst;
+
+ /* We don't currently support blitting to < 8 bpp surfaces */
+ if (dst->format->BitsPerPixel < 8) {
+ SDL_InvalidateMap(map);
+ return SDL_SetError("Blit combination not supported");
+ }
+
+ /* Clean everything out to start */
+ if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
+ SDL_UnRLESurface(surface, 1);
+ }
+ map->blit = SDL_SoftBlit;
+ map->info.src_fmt = surface->format;
+ map->info.src_pitch = surface->pitch;
+ map->info.dst_fmt = dst->format;
+ map->info.dst_pitch = dst->pitch;
+
+ /* See if we can do RLE acceleration */
+ if (map->info.flags & SDL_COPY_RLE_DESIRED) {
+ if (SDL_RLESurface(surface) == 0) {
+ return 0;
+ }
+ }
+
+ /* Choose a standard blit function */
+ if (map->identity && !(map->info.flags & ~SDL_COPY_RLE_DESIRED)) {
+ blit = SDL_BlitCopy;
+ } else if (surface->format->Rloss > 8 || dst->format->Rloss > 8) {
+ /* Greater than 8 bits per channel not supported yet */
+ SDL_InvalidateMap(map);
+ return SDL_SetError("Blit combination not supported");
+ } else if (surface->format->BitsPerPixel < 8 &&
+ SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
+ blit = SDL_CalculateBlit0(surface);
+ } else if (surface->format->BytesPerPixel == 1 &&
+ SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
+ blit = SDL_CalculateBlit1(surface);
+ } else if (map->info.flags & SDL_COPY_BLEND) {
+ blit = SDL_CalculateBlitA(surface);
+ } else {
+ blit = SDL_CalculateBlitN(surface);
+ }
+ if (blit == NULL) {
+ Uint32 src_format = surface->format->format;
+ Uint32 dst_format = dst->format->format;
+
+ blit =
+ SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags,
+ SDL_GeneratedBlitFuncTable);
+ }
+#ifndef TEST_SLOW_BLIT
+ if (blit == NULL)
+#endif
+ {
+ Uint32 src_format = surface->format->format;
+ Uint32 dst_format = dst->format->format;
+
+ if (!SDL_ISPIXELFORMAT_INDEXED(src_format) &&
+ !SDL_ISPIXELFORMAT_FOURCC(src_format) &&
+ !SDL_ISPIXELFORMAT_INDEXED(dst_format) &&
+ !SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
+ blit = SDL_Blit_Slow;
+ }
+ }
+ map->data = blit;
+
+ /* Make sure we have a blit function */
+ if (blit == NULL) {
+ SDL_InvalidateMap(map);
+ return SDL_SetError("Blit combination not supported");
+ }
+
+ return 0;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_blit.h b/src/3rdparty/SDL2/src/video/SDL_blit.h
new file mode 100644
index 0000000..ca10534
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_blit.h
@@ -0,0 +1,553 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#ifndef SDL_blit_h_
+#define SDL_blit_h_
+
+#include "SDL_cpuinfo.h"
+#include "SDL_endian.h"
+#include "SDL_surface.h"
+
+/* Table to do pixel byte expansion */
+extern Uint8* SDL_expand_byte[9];
+
+/* SDL blit copy flags */
+#define SDL_COPY_MODULATE_COLOR 0x00000001
+#define SDL_COPY_MODULATE_ALPHA 0x00000002
+#define SDL_COPY_BLEND 0x00000010
+#define SDL_COPY_ADD 0x00000020
+#define SDL_COPY_MOD 0x00000040
+#define SDL_COPY_COLORKEY 0x00000100
+#define SDL_COPY_NEAREST 0x00000200
+#define SDL_COPY_RLE_DESIRED 0x00001000
+#define SDL_COPY_RLE_COLORKEY 0x00002000
+#define SDL_COPY_RLE_ALPHAKEY 0x00004000
+#define SDL_COPY_RLE_MASK (SDL_COPY_RLE_DESIRED|SDL_COPY_RLE_COLORKEY|SDL_COPY_RLE_ALPHAKEY)
+
+/* SDL blit CPU flags */
+#define SDL_CPU_ANY 0x00000000
+#define SDL_CPU_MMX 0x00000001
+#define SDL_CPU_3DNOW 0x00000002
+#define SDL_CPU_SSE 0x00000004
+#define SDL_CPU_SSE2 0x00000008
+#define SDL_CPU_ALTIVEC_PREFETCH 0x00000010
+#define SDL_CPU_ALTIVEC_NOPREFETCH 0x00000020
+
+typedef struct
+{
+ Uint8 *src;
+ int src_w, src_h;
+ int src_pitch;
+ int src_skip;
+ Uint8 *dst;
+ int dst_w, dst_h;
+ int dst_pitch;
+ int dst_skip;
+ SDL_PixelFormat *src_fmt;
+ SDL_PixelFormat *dst_fmt;
+ Uint8 *table;
+ int flags;
+ Uint32 colorkey;
+ Uint8 r, g, b, a;
+} SDL_BlitInfo;
+
+typedef void (*SDL_BlitFunc) (SDL_BlitInfo *info);
+
+
+typedef struct
+{
+ Uint32 src_format;
+ Uint32 dst_format;
+ int flags;
+ int cpu;
+ SDL_BlitFunc func;
+} SDL_BlitFuncEntry;
+
+/* Blit mapping definition */
+typedef struct SDL_BlitMap
+{
+ SDL_Surface *dst;
+ int identity;
+ SDL_blit blit;
+ void *data;
+ SDL_BlitInfo info;
+
+ /* the version count matches the destination; mismatch indicates
+ an invalid mapping */
+ Uint32 dst_palette_version;
+ Uint32 src_palette_version;
+} SDL_BlitMap;
+
+/* Functions found in SDL_blit.c */
+extern int SDL_CalculateBlit(SDL_Surface * surface);
+
+/* Functions found in SDL_blit_*.c */
+extern SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface * surface);
+extern SDL_BlitFunc SDL_CalculateBlit1(SDL_Surface * surface);
+extern SDL_BlitFunc SDL_CalculateBlitN(SDL_Surface * surface);
+extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface * surface);
+
+/*
+ * Useful macros for blitting routines
+ */
+
+#if defined(__GNUC__)
+#define DECLARE_ALIGNED(t,v,a) t __attribute__((aligned(a))) v
+#elif defined(_MSC_VER)
+#define DECLARE_ALIGNED(t,v,a) __declspec(align(a)) t v
+#else
+#define DECLARE_ALIGNED(t,v,a) t v
+#endif
+
+/* Load pixel of the specified format from a buffer and get its R-G-B values */
+#define RGB_FROM_PIXEL(Pixel, fmt, r, g, b) \
+{ \
+ r = SDL_expand_byte[fmt->Rloss][((Pixel&fmt->Rmask)>>fmt->Rshift)]; \
+ g = SDL_expand_byte[fmt->Gloss][((Pixel&fmt->Gmask)>>fmt->Gshift)]; \
+ b = SDL_expand_byte[fmt->Bloss][((Pixel&fmt->Bmask)>>fmt->Bshift)]; \
+}
+#define RGB_FROM_RGB565(Pixel, r, g, b) \
+ { \
+ r = SDL_expand_byte[3][((Pixel&0xF800)>>11)]; \
+ g = SDL_expand_byte[2][((Pixel&0x07E0)>>5)]; \
+ b = SDL_expand_byte[3][(Pixel&0x001F)]; \
+}
+#define RGB_FROM_RGB555(Pixel, r, g, b) \
+{ \
+ r = SDL_expand_byte[3][((Pixel&0x7C00)>>10)]; \
+ g = SDL_expand_byte[3][((Pixel&0x03E0)>>5)]; \
+ b = SDL_expand_byte[3][(Pixel&0x001F)]; \
+}
+#define RGB_FROM_RGB888(Pixel, r, g, b) \
+{ \
+ r = ((Pixel&0xFF0000)>>16); \
+ g = ((Pixel&0xFF00)>>8); \
+ b = (Pixel&0xFF); \
+}
+#define RETRIEVE_RGB_PIXEL(buf, bpp, Pixel) \
+do { \
+ switch (bpp) { \
+ case 1: \
+ Pixel = *((Uint8 *)(buf)); \
+ break; \
+ \
+ case 2: \
+ Pixel = *((Uint16 *)(buf)); \
+ break; \
+ \
+ case 3: { \
+ Uint8 *B = (Uint8 *)(buf); \
+ if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
+ Pixel = B[0] + (B[1] << 8) + (B[2] << 16); \
+ } else { \
+ Pixel = (B[0] << 16) + (B[1] << 8) + B[2]; \
+ } \
+ } \
+ break; \
+ \
+ case 4: \
+ Pixel = *((Uint32 *)(buf)); \
+ break; \
+ \
+ default: \
+ Pixel = 0; /* stop gcc complaints */ \
+ break; \
+ } \
+} while (0)
+
+#define DISEMBLE_RGB(buf, bpp, fmt, Pixel, r, g, b) \
+do { \
+ switch (bpp) { \
+ case 1: \
+ Pixel = *((Uint8 *)(buf)); \
+ RGB_FROM_PIXEL(Pixel, fmt, r, g, b); \
+ break; \
+ \
+ case 2: \
+ Pixel = *((Uint16 *)(buf)); \
+ RGB_FROM_PIXEL(Pixel, fmt, r, g, b); \
+ break; \
+ \
+ case 3: { \
+ Pixel = 0; \
+ if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
+ r = *((buf)+fmt->Rshift/8); \
+ g = *((buf)+fmt->Gshift/8); \
+ b = *((buf)+fmt->Bshift/8); \
+ } else { \
+ r = *((buf)+2-fmt->Rshift/8); \
+ g = *((buf)+2-fmt->Gshift/8); \
+ b = *((buf)+2-fmt->Bshift/8); \
+ } \
+ } \
+ break; \
+ \
+ case 4: \
+ Pixel = *((Uint32 *)(buf)); \
+ RGB_FROM_PIXEL(Pixel, fmt, r, g, b); \
+ break; \
+ \
+ default: \
+ /* stop gcc complaints */ \
+ Pixel = 0; \
+ r = g = b = 0; \
+ break; \
+ } \
+} while (0)
+
+/* Assemble R-G-B values into a specified pixel format and store them */
+#define PIXEL_FROM_RGB(Pixel, fmt, r, g, b) \
+{ \
+ Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \
+ ((g>>fmt->Gloss)<<fmt->Gshift)| \
+ ((b>>fmt->Bloss)<<fmt->Bshift)| \
+ fmt->Amask; \
+}
+#define RGB565_FROM_RGB(Pixel, r, g, b) \
+{ \
+ Pixel = ((r>>3)<<11)|((g>>2)<<5)|(b>>3); \
+}
+#define RGB555_FROM_RGB(Pixel, r, g, b) \
+{ \
+ Pixel = ((r>>3)<<10)|((g>>3)<<5)|(b>>3); \
+}
+#define RGB888_FROM_RGB(Pixel, r, g, b) \
+{ \
+ Pixel = (r<<16)|(g<<8)|b; \
+}
+#define ARGB8888_FROM_RGBA(Pixel, r, g, b, a) \
+{ \
+ Pixel = (a<<24)|(r<<16)|(g<<8)|b; \
+}
+#define RGBA8888_FROM_RGBA(Pixel, r, g, b, a) \
+{ \
+ Pixel = (r<<24)|(g<<16)|(b<<8)|a; \
+}
+#define ABGR8888_FROM_RGBA(Pixel, r, g, b, a) \
+{ \
+ Pixel = (a<<24)|(b<<16)|(g<<8)|r; \
+}
+#define BGRA8888_FROM_RGBA(Pixel, r, g, b, a) \
+{ \
+ Pixel = (b<<24)|(g<<16)|(r<<8)|a; \
+}
+#define ARGB2101010_FROM_RGBA(Pixel, r, g, b, a) \
+{ \
+ r = r ? ((r << 2) | 0x3) : 0; \
+ g = g ? ((g << 2) | 0x3) : 0; \
+ b = b ? ((b << 2) | 0x3) : 0; \
+ a = (a * 3) / 255; \
+ Pixel = (a<<30)|(r<<20)|(g<<10)|b; \
+}
+#define ASSEMBLE_RGB(buf, bpp, fmt, r, g, b) \
+{ \
+ switch (bpp) { \
+ case 1: { \
+ Uint8 Pixel; \
+ \
+ PIXEL_FROM_RGB(Pixel, fmt, r, g, b); \
+ *((Uint8 *)(buf)) = Pixel; \
+ } \
+ break; \
+ \
+ case 2: { \
+ Uint16 Pixel; \
+ \
+ PIXEL_FROM_RGB(Pixel, fmt, r, g, b); \
+ *((Uint16 *)(buf)) = Pixel; \
+ } \
+ break; \
+ \
+ case 3: { \
+ if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
+ *((buf)+fmt->Rshift/8) = r; \
+ *((buf)+fmt->Gshift/8) = g; \
+ *((buf)+fmt->Bshift/8) = b; \
+ } else { \
+ *((buf)+2-fmt->Rshift/8) = r; \
+ *((buf)+2-fmt->Gshift/8) = g; \
+ *((buf)+2-fmt->Bshift/8) = b; \
+ } \
+ } \
+ break; \
+ \
+ case 4: { \
+ Uint32 Pixel; \
+ \
+ PIXEL_FROM_RGB(Pixel, fmt, r, g, b); \
+ *((Uint32 *)(buf)) = Pixel; \
+ } \
+ break; \
+ } \
+}
+
+/* FIXME: Should we rescale alpha into 0..255 here? */
+#define RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a) \
+{ \
+ r = SDL_expand_byte[fmt->Rloss][((Pixel&fmt->Rmask)>>fmt->Rshift)]; \
+ g = SDL_expand_byte[fmt->Gloss][((Pixel&fmt->Gmask)>>fmt->Gshift)]; \
+ b = SDL_expand_byte[fmt->Bloss][((Pixel&fmt->Bmask)>>fmt->Bshift)]; \
+ a = SDL_expand_byte[fmt->Aloss][((Pixel&fmt->Amask)>>fmt->Ashift)]; \
+}
+#define RGBA_FROM_8888(Pixel, fmt, r, g, b, a) \
+{ \
+ r = (Pixel&fmt->Rmask)>>fmt->Rshift; \
+ g = (Pixel&fmt->Gmask)>>fmt->Gshift; \
+ b = (Pixel&fmt->Bmask)>>fmt->Bshift; \
+ a = (Pixel&fmt->Amask)>>fmt->Ashift; \
+}
+#define RGBA_FROM_RGBA8888(Pixel, r, g, b, a) \
+{ \
+ r = (Pixel>>24); \
+ g = ((Pixel>>16)&0xFF); \
+ b = ((Pixel>>8)&0xFF); \
+ a = (Pixel&0xFF); \
+}
+#define RGBA_FROM_ARGB8888(Pixel, r, g, b, a) \
+{ \
+ r = ((Pixel>>16)&0xFF); \
+ g = ((Pixel>>8)&0xFF); \
+ b = (Pixel&0xFF); \
+ a = (Pixel>>24); \
+}
+#define RGBA_FROM_ABGR8888(Pixel, r, g, b, a) \
+{ \
+ r = (Pixel&0xFF); \
+ g = ((Pixel>>8)&0xFF); \
+ b = ((Pixel>>16)&0xFF); \
+ a = (Pixel>>24); \
+}
+#define RGBA_FROM_BGRA8888(Pixel, r, g, b, a) \
+{ \
+ r = ((Pixel>>8)&0xFF); \
+ g = ((Pixel>>16)&0xFF); \
+ b = (Pixel>>24); \
+ a = (Pixel&0xFF); \
+}
+#define RGBA_FROM_ARGB2101010(Pixel, r, g, b, a) \
+{ \
+ r = ((Pixel>>22)&0xFF); \
+ g = ((Pixel>>12)&0xFF); \
+ b = ((Pixel>>2)&0xFF); \
+ a = SDL_expand_byte[6][(Pixel>>30)]; \
+}
+#define DISEMBLE_RGBA(buf, bpp, fmt, Pixel, r, g, b, a) \
+do { \
+ switch (bpp) { \
+ case 1: \
+ Pixel = *((Uint8 *)(buf)); \
+ RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a); \
+ break; \
+ \
+ case 2: \
+ Pixel = *((Uint16 *)(buf)); \
+ RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a); \
+ break; \
+ \
+ case 3: { \
+ Pixel = 0; \
+ if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
+ r = *((buf)+fmt->Rshift/8); \
+ g = *((buf)+fmt->Gshift/8); \
+ b = *((buf)+fmt->Bshift/8); \
+ } else { \
+ r = *((buf)+2-fmt->Rshift/8); \
+ g = *((buf)+2-fmt->Gshift/8); \
+ b = *((buf)+2-fmt->Bshift/8); \
+ } \
+ a = 0xFF; \
+ } \
+ break; \
+ \
+ case 4: \
+ Pixel = *((Uint32 *)(buf)); \
+ RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a); \
+ break; \
+ \
+ default: \
+ /* stop gcc complaints */ \
+ Pixel = 0; \
+ r = g = b = a = 0; \
+ break; \
+ } \
+} while (0)
+
+/* FIXME: this isn't correct, especially for Alpha (maximum != 255) */
+#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a) \
+{ \
+ Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \
+ ((g>>fmt->Gloss)<<fmt->Gshift)| \
+ ((b>>fmt->Bloss)<<fmt->Bshift)| \
+ ((a>>fmt->Aloss)<<fmt->Ashift); \
+}
+#define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a) \
+{ \
+ switch (bpp) { \
+ case 1: { \
+ Uint8 _pixel; \
+ \
+ PIXEL_FROM_RGBA(_pixel, fmt, r, g, b, a); \
+ *((Uint8 *)(buf)) = _pixel; \
+ } \
+ break; \
+ \
+ case 2: { \
+ Uint16 _pixel; \
+ \
+ PIXEL_FROM_RGBA(_pixel, fmt, r, g, b, a); \
+ *((Uint16 *)(buf)) = _pixel; \
+ } \
+ break; \
+ \
+ case 3: { \
+ if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { \
+ *((buf)+fmt->Rshift/8) = r; \
+ *((buf)+fmt->Gshift/8) = g; \
+ *((buf)+fmt->Bshift/8) = b; \
+ } else { \
+ *((buf)+2-fmt->Rshift/8) = r; \
+ *((buf)+2-fmt->Gshift/8) = g; \
+ *((buf)+2-fmt->Bshift/8) = b; \
+ } \
+ } \
+ break; \
+ \
+ case 4: { \
+ Uint32 _pixel; \
+ \
+ PIXEL_FROM_RGBA(_pixel, fmt, r, g, b, a); \
+ *((Uint32 *)(buf)) = _pixel; \
+ } \
+ break; \
+ } \
+}
+
+/* Blend the RGB values of two pixels with an alpha value */
+#define ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB) \
+do { \
+ dR = (Uint8)((((int)(sR-dR)*(int)A)/255)+dR); \
+ dG = (Uint8)((((int)(sG-dG)*(int)A)/255)+dG); \
+ dB = (Uint8)((((int)(sB-dB)*(int)A)/255)+dB); \
+} while(0)
+
+
+/* Blend the RGBA values of two pixels */
+#define ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA) \
+do { \
+ dR = (Uint8)((((int)(sR-dR)*(int)sA)/255)+dR); \
+ dG = (Uint8)((((int)(sG-dG)*(int)sA)/255)+dG); \
+ dB = (Uint8)((((int)(sB-dB)*(int)sA)/255)+dB); \
+ dA = (Uint8)((int)sA+dA-((int)sA*dA)/255); \
+} while(0)
+
+
+/* This is a very useful loop for optimizing blitters */
+#if defined(_MSC_VER) && (_MSC_VER == 1300)
+/* There's a bug in the Visual C++ 7 optimizer when compiling this code */
+#else
+#define USE_DUFFS_LOOP
+#endif
+#ifdef USE_DUFFS_LOOP
+
+/* 8-times unrolled loop */
+#define DUFFS_LOOP8(pixel_copy_increment, width) \
+{ int n = (width+7)/8; \
+ switch (width & 7) { \
+ case 0: do { pixel_copy_increment; /* fallthrough */ \
+ case 7: pixel_copy_increment; /* fallthrough */ \
+ case 6: pixel_copy_increment; /* fallthrough */ \
+ case 5: pixel_copy_increment; /* fallthrough */ \
+ case 4: pixel_copy_increment; /* fallthrough */ \
+ case 3: pixel_copy_increment; /* fallthrough */ \
+ case 2: pixel_copy_increment; /* fallthrough */ \
+ case 1: pixel_copy_increment; /* fallthrough */ \
+ } while ( --n > 0 ); \
+ } \
+}
+
+/* 4-times unrolled loop */
+#define DUFFS_LOOP4(pixel_copy_increment, width) \
+{ int n = (width+3)/4; \
+ switch (width & 3) { \
+ case 0: do { pixel_copy_increment; /* fallthrough */ \
+ case 3: pixel_copy_increment; /* fallthrough */ \
+ case 2: pixel_copy_increment; /* fallthrough */ \
+ case 1: pixel_copy_increment; /* fallthrough */ \
+ } while (--n > 0); \
+ } \
+}
+
+/* Use the 8-times version of the loop by default */
+#define DUFFS_LOOP(pixel_copy_increment, width) \
+ DUFFS_LOOP8(pixel_copy_increment, width)
+
+/* Special version of Duff's device for even more optimization */
+#define DUFFS_LOOP_124(pixel_copy_increment1, \
+ pixel_copy_increment2, \
+ pixel_copy_increment4, width) \
+{ int n = width; \
+ if (n & 1) { \
+ pixel_copy_increment1; n -= 1; \
+ } \
+ if (n & 2) { \
+ pixel_copy_increment2; n -= 2; \
+ } \
+ if (n & 4) { \
+ pixel_copy_increment4; n -= 4; \
+ } \
+ if (n) { \
+ n /= 8; \
+ do { \
+ pixel_copy_increment4; \
+ pixel_copy_increment4; \
+ } while (--n > 0); \
+ } \
+}
+
+#else
+
+/* Don't use Duff's device to unroll loops */
+#define DUFFS_LOOP(pixel_copy_increment, width) \
+{ int n; \
+ for ( n=width; n > 0; --n ) { \
+ pixel_copy_increment; \
+ } \
+}
+#define DUFFS_LOOP8(pixel_copy_increment, width) \
+ DUFFS_LOOP(pixel_copy_increment, width)
+#define DUFFS_LOOP4(pixel_copy_increment, width) \
+ DUFFS_LOOP(pixel_copy_increment, width)
+#define DUFFS_LOOP_124(pixel_copy_increment1, \
+ pixel_copy_increment2, \
+ pixel_copy_increment4, width) \
+ DUFFS_LOOP(pixel_copy_increment1, width)
+
+#endif /* USE_DUFFS_LOOP */
+
+/* Prevent Visual C++ 6.0 from printing out stupid warnings */
+#if defined(_MSC_VER) && (_MSC_VER >= 600)
+#pragma warning(disable: 4550)
+#endif
+
+#endif /* SDL_blit_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_blit_0.c b/src/3rdparty/SDL2/src/video/SDL_blit_0.c
new file mode 100644
index 0000000..b5c8efb
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_blit_0.c
@@ -0,0 +1,483 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "SDL_video.h"
+#include "SDL_blit.h"
+
+/* Functions to blit from bitmaps to other surfaces */
+
+static void
+BlitBto1(SDL_BlitInfo * info)
+{
+ int c;
+ int width, height;
+ Uint8 *src, *map, *dst;
+ int srcskip, dstskip;
+
+ /* Set up some basic variables */
+ width = info->dst_w;
+ height = info->dst_h;
+ src = info->src;
+ srcskip = info->src_skip;
+ dst = info->dst;
+ dstskip = info->dst_skip;
+ map = info->table;
+ srcskip += width - (width + 7) / 8;
+
+ if (map) {
+ while (height--) {
+ Uint8 byte = 0, bit;
+ for (c = 0; c < width; ++c) {
+ if ((c & 7) == 0) {
+ byte = *src++;
+ }
+ bit = (byte & 0x80) >> 7;
+ if (1) {
+ *dst = map[bit];
+ }
+ dst++;
+ byte <<= 1;
+ }
+ src += srcskip;
+ dst += dstskip;
+ }
+ } else {
+ while (height--) {
+ Uint8 byte = 0, bit;
+ for (c = 0; c < width; ++c) {
+ if ((c & 7) == 0) {
+ byte = *src++;
+ }
+ bit = (byte & 0x80) >> 7;
+ if (1) {
+ *dst = bit;
+ }
+ dst++;
+ byte <<= 1;
+ }
+ src += srcskip;
+ dst += dstskip;
+ }
+ }
+}
+
+static void
+BlitBto2(SDL_BlitInfo * info)
+{
+ int c;
+ int width, height;
+ Uint8 *src;
+ Uint16 *map, *dst;
+ int srcskip, dstskip;
+
+ /* Set up some basic variables */
+ width = info->dst_w;
+ height = info->dst_h;
+ src = info->src;
+ srcskip = info->src_skip;
+ dst = (Uint16 *) info->dst;
+ dstskip = info->dst_skip / 2;
+ map = (Uint16 *) info->table;
+ srcskip += width - (width + 7) / 8;
+
+ while (height--) {
+ Uint8 byte = 0, bit;
+ for (c = 0; c < width; ++c) {
+ if ((c & 7) == 0) {
+ byte = *src++;
+ }
+ bit = (byte & 0x80) >> 7;
+ if (1) {
+ *dst = map[bit];
+ }
+ byte <<= 1;
+ dst++;
+ }
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+static void
+BlitBto3(SDL_BlitInfo * info)
+{
+ int c, o;
+ int width, height;
+ Uint8 *src, *map, *dst;
+ int srcskip, dstskip;
+
+ /* Set up some basic variables */
+ width = info->dst_w;
+ height = info->dst_h;
+ src = info->src;
+ srcskip = info->src_skip;
+ dst = info->dst;
+ dstskip = info->dst_skip;
+ map = info->table;
+ srcskip += width - (width + 7) / 8;
+
+ while (height--) {
+ Uint8 byte = 0, bit;
+ for (c = 0; c < width; ++c) {
+ if ((c & 7) == 0) {
+ byte = *src++;
+ }
+ bit = (byte & 0x80) >> 7;
+ if (1) {
+ o = bit * 4;
+ dst[0] = map[o++];
+ dst[1] = map[o++];
+ dst[2] = map[o++];
+ }
+ byte <<= 1;
+ dst += 3;
+ }
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+static void
+BlitBto4(SDL_BlitInfo * info)
+{
+ int width, height;
+ Uint8 *src;
+ Uint32 *map, *dst;
+ int srcskip, dstskip;
+ int c;
+
+ /* Set up some basic variables */
+ width = info->dst_w;
+ height = info->dst_h;
+ src = info->src;
+ srcskip = info->src_skip;
+ dst = (Uint32 *) info->dst;
+ dstskip = info->dst_skip / 4;
+ map = (Uint32 *) info->table;
+ srcskip += width - (width + 7) / 8;
+
+ while (height--) {
+ Uint8 byte = 0, bit;
+ for (c = 0; c < width; ++c) {
+ if ((c & 7) == 0) {
+ byte = *src++;
+ }
+ bit = (byte & 0x80) >> 7;
+ if (1) {
+ *dst = map[bit];
+ }
+ byte <<= 1;
+ dst++;
+ }
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+static void
+BlitBto1Key(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ Uint8 *dst = info->dst;
+ int srcskip = info->src_skip;
+ int dstskip = info->dst_skip;
+ Uint32 ckey = info->colorkey;
+ Uint8 *palmap = info->table;
+ int c;
+
+ /* Set up some basic variables */
+ srcskip += width - (width + 7) / 8;
+
+ if (palmap) {
+ while (height--) {
+ Uint8 byte = 0, bit;
+ for (c = 0; c < width; ++c) {
+ if ((c & 7) == 0) {
+ byte = *src++;
+ }
+ bit = (byte & 0x80) >> 7;
+ if (bit != ckey) {
+ *dst = palmap[bit];
+ }
+ dst++;
+ byte <<= 1;
+ }
+ src += srcskip;
+ dst += dstskip;
+ }
+ } else {
+ while (height--) {
+ Uint8 byte = 0, bit;
+ for (c = 0; c < width; ++c) {
+ if ((c & 7) == 0) {
+ byte = *src++;
+ }
+ bit = (byte & 0x80) >> 7;
+ if (bit != ckey) {
+ *dst = bit;
+ }
+ dst++;
+ byte <<= 1;
+ }
+ src += srcskip;
+ dst += dstskip;
+ }
+ }
+}
+
+static void
+BlitBto2Key(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ Uint16 *dstp = (Uint16 *) info->dst;
+ int srcskip = info->src_skip;
+ int dstskip = info->dst_skip;
+ Uint32 ckey = info->colorkey;
+ Uint8 *palmap = info->table;
+ int c;
+
+ /* Set up some basic variables */
+ srcskip += width - (width + 7) / 8;
+ dstskip /= 2;
+
+ while (height--) {
+ Uint8 byte = 0, bit;
+ for (c = 0; c < width; ++c) {
+ if ((c & 7) == 0) {
+ byte = *src++;
+ }
+ bit = (byte & 0x80) >> 7;
+ if (bit != ckey) {
+ *dstp = ((Uint16 *) palmap)[bit];
+ }
+ byte <<= 1;
+ dstp++;
+ }
+ src += srcskip;
+ dstp += dstskip;
+ }
+}
+
+static void
+BlitBto3Key(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ Uint8 *dst = info->dst;
+ int srcskip = info->src_skip;
+ int dstskip = info->dst_skip;
+ Uint32 ckey = info->colorkey;
+ Uint8 *palmap = info->table;
+ int c;
+
+ /* Set up some basic variables */
+ srcskip += width - (width + 7) / 8;
+
+ while (height--) {
+ Uint8 byte = 0, bit;
+ for (c = 0; c < width; ++c) {
+ if ((c & 7) == 0) {
+ byte = *src++;
+ }
+ bit = (byte & 0x80) >> 7;
+ if (bit != ckey) {
+ SDL_memcpy(dst, &palmap[bit * 4], 3);
+ }
+ byte <<= 1;
+ dst += 3;
+ }
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+static void
+BlitBto4Key(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ Uint32 *dstp = (Uint32 *) info->dst;
+ int srcskip = info->src_skip;
+ int dstskip = info->dst_skip;
+ Uint32 ckey = info->colorkey;
+ Uint8 *palmap = info->table;
+ int c;
+
+ /* Set up some basic variables */
+ srcskip += width - (width + 7) / 8;
+ dstskip /= 4;
+
+ while (height--) {
+ Uint8 byte = 0, bit;
+ for (c = 0; c < width; ++c) {
+ if ((c & 7) == 0) {
+ byte = *src++;
+ }
+ bit = (byte & 0x80) >> 7;
+ if (bit != ckey) {
+ *dstp = ((Uint32 *) palmap)[bit];
+ }
+ byte <<= 1;
+ dstp++;
+ }
+ src += srcskip;
+ dstp += dstskip;
+ }
+}
+
+static void
+BlitBtoNAlpha(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ Uint8 *dst = info->dst;
+ int srcskip = info->src_skip;
+ int dstskip = info->dst_skip;
+ const SDL_Color *srcpal = info->src_fmt->palette->colors;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ int dstbpp;
+ int c;
+ Uint32 pixel;
+ unsigned sR, sG, sB;
+ unsigned dR, dG, dB, dA;
+ const unsigned A = info->a;
+
+ /* Set up some basic variables */
+ dstbpp = dstfmt->BytesPerPixel;
+ srcskip += width - (width + 7) / 8;
+
+ while (height--) {
+ Uint8 byte = 0, bit;
+ for (c = 0; c < width; ++c) {
+ if ((c & 7) == 0) {
+ byte = *src++;
+ }
+ bit = (byte & 0x80) >> 7;
+ if (1) {
+ sR = srcpal[bit].r;
+ sG = srcpal[bit].g;
+ sB = srcpal[bit].b;
+ DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
+ ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
+ ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
+ }
+ byte <<= 1;
+ dst += dstbpp;
+ }
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+static void
+BlitBtoNAlphaKey(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ Uint8 *dst = info->dst;
+ int srcskip = info->src_skip;
+ int dstskip = info->dst_skip;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_Color *srcpal = srcfmt->palette->colors;
+ int dstbpp;
+ int c;
+ Uint32 pixel;
+ unsigned sR, sG, sB;
+ unsigned dR, dG, dB, dA;
+ const unsigned A = info->a;
+ Uint32 ckey = info->colorkey;
+
+ /* Set up some basic variables */
+ dstbpp = dstfmt->BytesPerPixel;
+ srcskip += width - (width + 7) / 8;
+
+ while (height--) {
+ Uint8 byte = 0, bit;
+ for (c = 0; c < width; ++c) {
+ if ((c & 7) == 0) {
+ byte = *src++;
+ }
+ bit = (byte & 0x80) >> 7;
+ if (bit != ckey) {
+ sR = srcpal[bit].r;
+ sG = srcpal[bit].g;
+ sB = srcpal[bit].b;
+ DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
+ ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
+ ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
+ }
+ byte <<= 1;
+ dst += dstbpp;
+ }
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+static const SDL_BlitFunc bitmap_blit[] = {
+ (SDL_BlitFunc) NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4
+};
+
+static const SDL_BlitFunc colorkey_blit[] = {
+ (SDL_BlitFunc) NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key
+};
+
+SDL_BlitFunc
+SDL_CalculateBlit0(SDL_Surface * surface)
+{
+ int which;
+
+ if (surface->format->BitsPerPixel != 1) {
+ /* We don't support sub 8-bit packed pixel modes */
+ return (SDL_BlitFunc) NULL;
+ }
+ if (surface->map->dst->format->BitsPerPixel < 8) {
+ which = 0;
+ } else {
+ which = surface->map->dst->format->BytesPerPixel;
+ }
+ switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
+ case 0:
+ return bitmap_blit[which];
+
+ case SDL_COPY_COLORKEY:
+ return colorkey_blit[which];
+
+ case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
+ return which >= 2 ? BlitBtoNAlpha : (SDL_BlitFunc) NULL;
+
+ case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
+ return which >= 2 ? BlitBtoNAlphaKey : (SDL_BlitFunc) NULL;
+ }
+ return (SDL_BlitFunc) NULL;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_blit_1.c b/src/3rdparty/SDL2/src/video/SDL_blit_1.c
new file mode 100644
index 0000000..b7c5412
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_blit_1.c
@@ -0,0 +1,552 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "SDL_video.h"
+#include "SDL_blit.h"
+#include "SDL_sysvideo.h"
+#include "SDL_endian.h"
+
+/* Functions to blit from 8-bit surfaces to other surfaces */
+
+static void
+Blit1to1(SDL_BlitInfo * info)
+{
+#ifndef USE_DUFFS_LOOP
+ int c;
+#endif
+ int width, height;
+ Uint8 *src, *map, *dst;
+ int srcskip, dstskip;
+
+ /* Set up some basic variables */
+ width = info->dst_w;
+ height = info->dst_h;
+ src = info->src;
+ srcskip = info->src_skip;
+ dst = info->dst;
+ dstskip = info->dst_skip;
+ map = info->table;
+
+ while (height--) {
+#ifdef USE_DUFFS_LOOP
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ *dst = map[*src];
+ }
+ dst++;
+ src++;
+ , width);
+ /* *INDENT-ON* */
+#else
+ for (c = width; c; --c) {
+ *dst = map[*src];
+ dst++;
+ src++;
+ }
+#endif
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+/* This is now endian dependent */
+#ifndef USE_DUFFS_LOOP
+# if ( SDL_BYTEORDER == SDL_LIL_ENDIAN )
+# define HI 1
+# define LO 0
+# else /* ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) */
+# define HI 0
+# define LO 1
+# endif
+#endif
+static void
+Blit1to2(SDL_BlitInfo * info)
+{
+#ifndef USE_DUFFS_LOOP
+ int c;
+#endif
+ int width, height;
+ Uint8 *src, *dst;
+ Uint16 *map;
+ int srcskip, dstskip;
+
+ /* Set up some basic variables */
+ width = info->dst_w;
+ height = info->dst_h;
+ src = info->src;
+ srcskip = info->src_skip;
+ dst = info->dst;
+ dstskip = info->dst_skip;
+ map = (Uint16 *) info->table;
+
+#ifdef USE_DUFFS_LOOP
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ *(Uint16 *)dst = map[*src++];
+ dst += 2;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+#else
+ /* Memory align at 4-byte boundary, if necessary */
+ if ((long) dst & 0x03) {
+ /* Don't do anything if width is 0 */
+ if (width == 0) {
+ return;
+ }
+ --width;
+
+ while (height--) {
+ /* Perform copy alignment */
+ *(Uint16 *) dst = map[*src++];
+ dst += 2;
+
+ /* Copy in 4 pixel chunks */
+ for (c = width / 4; c; --c) {
+ *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
+ src += 2;
+ dst += 4;
+ *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
+ src += 2;
+ dst += 4;
+ }
+ /* Get any leftovers */
+ switch (width & 3) {
+ case 3:
+ *(Uint16 *) dst = map[*src++];
+ dst += 2;
+ case 2:
+ *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
+ src += 2;
+ dst += 4;
+ break;
+ case 1:
+ *(Uint16 *) dst = map[*src++];
+ dst += 2;
+ break;
+ }
+ src += srcskip;
+ dst += dstskip;
+ }
+ } else {
+ while (height--) {
+ /* Copy in 4 pixel chunks */
+ for (c = width / 4; c; --c) {
+ *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
+ src += 2;
+ dst += 4;
+ *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
+ src += 2;
+ dst += 4;
+ }
+ /* Get any leftovers */
+ switch (width & 3) {
+ case 3:
+ *(Uint16 *) dst = map[*src++];
+ dst += 2;
+ case 2:
+ *(Uint32 *) dst = (map[src[HI]] << 16) | (map[src[LO]]);
+ src += 2;
+ dst += 4;
+ break;
+ case 1:
+ *(Uint16 *) dst = map[*src++];
+ dst += 2;
+ break;
+ }
+ src += srcskip;
+ dst += dstskip;
+ }
+ }
+#endif /* USE_DUFFS_LOOP */
+}
+
+static void
+Blit1to3(SDL_BlitInfo * info)
+{
+#ifndef USE_DUFFS_LOOP
+ int c;
+#endif
+ int o;
+ int width, height;
+ Uint8 *src, *map, *dst;
+ int srcskip, dstskip;
+
+ /* Set up some basic variables */
+ width = info->dst_w;
+ height = info->dst_h;
+ src = info->src;
+ srcskip = info->src_skip;
+ dst = info->dst;
+ dstskip = info->dst_skip;
+ map = info->table;
+
+ while (height--) {
+#ifdef USE_DUFFS_LOOP
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ o = *src * 4;
+ dst[0] = map[o++];
+ dst[1] = map[o++];
+ dst[2] = map[o++];
+ }
+ src++;
+ dst += 3;
+ , width);
+ /* *INDENT-ON* */
+#else
+ for (c = width; c; --c) {
+ o = *src * 4;
+ dst[0] = map[o++];
+ dst[1] = map[o++];
+ dst[2] = map[o++];
+ src++;
+ dst += 3;
+ }
+#endif /* USE_DUFFS_LOOP */
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+static void
+Blit1to4(SDL_BlitInfo * info)
+{
+#ifndef USE_DUFFS_LOOP
+ int c;
+#endif
+ int width, height;
+ Uint8 *src;
+ Uint32 *map, *dst;
+ int srcskip, dstskip;
+
+ /* Set up some basic variables */
+ width = info->dst_w;
+ height = info->dst_h;
+ src = info->src;
+ srcskip = info->src_skip;
+ dst = (Uint32 *) info->dst;
+ dstskip = info->dst_skip / 4;
+ map = (Uint32 *) info->table;
+
+ while (height--) {
+#ifdef USE_DUFFS_LOOP
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ *dst++ = map[*src++];
+ , width);
+ /* *INDENT-ON* */
+#else
+ for (c = width / 4; c; --c) {
+ *dst++ = map[*src++];
+ *dst++ = map[*src++];
+ *dst++ = map[*src++];
+ *dst++ = map[*src++];
+ }
+ switch (width & 3) {
+ case 3:
+ *dst++ = map[*src++];
+ case 2:
+ *dst++ = map[*src++];
+ case 1:
+ *dst++ = map[*src++];
+ }
+#endif /* USE_DUFFS_LOOP */
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+static void
+Blit1to1Key(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = info->dst;
+ int dstskip = info->dst_skip;
+ Uint8 *palmap = info->table;
+ Uint32 ckey = info->colorkey;
+
+ if (palmap) {
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ if ( *src != ckey ) {
+ *dst = palmap[*src];
+ }
+ dst++;
+ src++;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+ } else {
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ if ( *src != ckey ) {
+ *dst = *src;
+ }
+ dst++;
+ src++;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+ }
+}
+
+static void
+Blit1to2Key(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint16 *dstp = (Uint16 *) info->dst;
+ int dstskip = info->dst_skip;
+ Uint16 *palmap = (Uint16 *) info->table;
+ Uint32 ckey = info->colorkey;
+
+ /* Set up some basic variables */
+ dstskip /= 2;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ if ( *src != ckey ) {
+ *dstp=palmap[*src];
+ }
+ src++;
+ dstp++;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dstp += dstskip;
+ }
+}
+
+static void
+Blit1to3Key(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = info->dst;
+ int dstskip = info->dst_skip;
+ Uint8 *palmap = info->table;
+ Uint32 ckey = info->colorkey;
+ int o;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ if ( *src != ckey ) {
+ o = *src * 4;
+ dst[0] = palmap[o++];
+ dst[1] = palmap[o++];
+ dst[2] = palmap[o++];
+ }
+ src++;
+ dst += 3;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+static void
+Blit1to4Key(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint32 *dstp = (Uint32 *) info->dst;
+ int dstskip = info->dst_skip;
+ Uint32 *palmap = (Uint32 *) info->table;
+ Uint32 ckey = info->colorkey;
+
+ /* Set up some basic variables */
+ dstskip /= 4;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ if ( *src != ckey ) {
+ *dstp = palmap[*src];
+ }
+ src++;
+ dstp++;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dstp += dstskip;
+ }
+}
+
+static void
+Blit1toNAlpha(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = info->dst;
+ int dstskip = info->dst_skip;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_Color *srcpal = info->src_fmt->palette->colors;
+ int dstbpp;
+ Uint32 pixel;
+ unsigned sR, sG, sB;
+ unsigned dR, dG, dB, dA;
+ const unsigned A = info->a;
+
+ /* Set up some basic variables */
+ dstbpp = dstfmt->BytesPerPixel;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP4(
+ {
+ sR = srcpal[*src].r;
+ sG = srcpal[*src].g;
+ sB = srcpal[*src].b;
+ DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
+ ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
+ ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
+ src++;
+ dst += dstbpp;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+static void
+Blit1toNAlphaKey(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = info->dst;
+ int dstskip = info->dst_skip;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ const SDL_Color *srcpal = info->src_fmt->palette->colors;
+ Uint32 ckey = info->colorkey;
+ int dstbpp;
+ Uint32 pixel;
+ unsigned sR, sG, sB;
+ unsigned dR, dG, dB, dA;
+ const unsigned A = info->a;
+
+ /* Set up some basic variables */
+ dstbpp = dstfmt->BytesPerPixel;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ if ( *src != ckey ) {
+ sR = srcpal[*src].r;
+ sG = srcpal[*src].g;
+ sB = srcpal[*src].b;
+ DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
+ ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
+ ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
+ }
+ src++;
+ dst += dstbpp;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+static const SDL_BlitFunc one_blit[] = {
+ (SDL_BlitFunc) NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4
+};
+
+static const SDL_BlitFunc one_blitkey[] = {
+ (SDL_BlitFunc) NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key
+};
+
+SDL_BlitFunc
+SDL_CalculateBlit1(SDL_Surface * surface)
+{
+ int which;
+ SDL_PixelFormat *dstfmt;
+
+ dstfmt = surface->map->dst->format;
+ if (dstfmt->BitsPerPixel < 8) {
+ which = 0;
+ } else {
+ which = dstfmt->BytesPerPixel;
+ }
+ switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
+ case 0:
+ return one_blit[which];
+
+ case SDL_COPY_COLORKEY:
+ return one_blitkey[which];
+
+ case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
+ /* Supporting 8bpp->8bpp alpha is doable but requires lots of
+ tables which consume space and takes time to precompute,
+ so is better left to the user */
+ return which >= 2 ? Blit1toNAlpha : (SDL_BlitFunc) NULL;
+
+ case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
+ return which >= 2 ? Blit1toNAlphaKey : (SDL_BlitFunc) NULL;
+ }
+ return (SDL_BlitFunc) NULL;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_blit_A.c b/src/3rdparty/SDL2/src/video/SDL_blit_A.c
new file mode 100644
index 0000000..1e9c9d8
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_blit_A.c
@@ -0,0 +1,1388 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "SDL_video.h"
+#include "SDL_blit.h"
+
+/* Functions to perform alpha blended blitting */
+
+/* N->1 blending with per-surface alpha */
+static void
+BlitNto1SurfaceAlpha(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = info->dst;
+ int dstskip = info->dst_skip;
+ Uint8 *palmap = info->table;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ int srcbpp = srcfmt->BytesPerPixel;
+ Uint32 Pixel;
+ unsigned sR, sG, sB;
+ unsigned dR, dG, dB;
+ const unsigned A = info->a;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP4(
+ {
+ DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
+ dR = dstfmt->palette->colors[*dst].r;
+ dG = dstfmt->palette->colors[*dst].g;
+ dB = dstfmt->palette->colors[*dst].b;
+ ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB);
+ dR &= 0xff;
+ dG &= 0xff;
+ dB &= 0xff;
+ /* Pack RGB into 8bit pixel */
+ if ( palmap == NULL ) {
+ *dst =((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0));
+ } else {
+ *dst = palmap[((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0))];
+ }
+ dst++;
+ src += srcbpp;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+/* N->1 blending with pixel alpha */
+static void
+BlitNto1PixelAlpha(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = info->dst;
+ int dstskip = info->dst_skip;
+ Uint8 *palmap = info->table;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ int srcbpp = srcfmt->BytesPerPixel;
+ Uint32 Pixel;
+ unsigned sR, sG, sB, sA;
+ unsigned dR, dG, dB;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP4(
+ {
+ DISEMBLE_RGBA(src,srcbpp,srcfmt,Pixel,sR,sG,sB,sA);
+ dR = dstfmt->palette->colors[*dst].r;
+ dG = dstfmt->palette->colors[*dst].g;
+ dB = dstfmt->palette->colors[*dst].b;
+ ALPHA_BLEND_RGB(sR, sG, sB, sA, dR, dG, dB);
+ dR &= 0xff;
+ dG &= 0xff;
+ dB &= 0xff;
+ /* Pack RGB into 8bit pixel */
+ if ( palmap == NULL ) {
+ *dst =((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0));
+ } else {
+ *dst = palmap[((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0))];
+ }
+ dst++;
+ src += srcbpp;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+/* colorkeyed N->1 blending with per-surface alpha */
+static void
+BlitNto1SurfaceAlphaKey(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = info->dst;
+ int dstskip = info->dst_skip;
+ Uint8 *palmap = info->table;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ int srcbpp = srcfmt->BytesPerPixel;
+ Uint32 ckey = info->colorkey;
+ Uint32 Pixel;
+ unsigned sR, sG, sB;
+ unsigned dR, dG, dB;
+ const unsigned A = info->a;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
+ if ( Pixel != ckey ) {
+ dR = dstfmt->palette->colors[*dst].r;
+ dG = dstfmt->palette->colors[*dst].g;
+ dB = dstfmt->palette->colors[*dst].b;
+ ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB);
+ dR &= 0xff;
+ dG &= 0xff;
+ dB &= 0xff;
+ /* Pack RGB into 8bit pixel */
+ if ( palmap == NULL ) {
+ *dst =((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0));
+ } else {
+ *dst = palmap[((dR>>5)<<(3+2))|((dG>>5)<<(2))|((dB>>6)<<(0))];
+ }
+ }
+ dst++;
+ src += srcbpp;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+#ifdef __MMX__
+
+/* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
+static void
+BlitRGBtoRGBSurfaceAlpha128MMX(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint32 *srcp = (Uint32 *) info->src;
+ int srcskip = info->src_skip >> 2;
+ Uint32 *dstp = (Uint32 *) info->dst;
+ int dstskip = info->dst_skip >> 2;
+ Uint32 dalpha = info->dst_fmt->Amask;
+
+ __m64 src1, src2, dst1, dst2, lmask, hmask, dsta;
+
+ hmask = _mm_set_pi32(0x00fefefe, 0x00fefefe); /* alpha128 mask -> hmask */
+ lmask = _mm_set_pi32(0x00010101, 0x00010101); /* !alpha128 mask -> lmask */
+ dsta = _mm_set_pi32(dalpha, dalpha); /* dst alpha mask -> dsta */
+
+ while (height--) {
+ int n = width;
+ if (n & 1) {
+ Uint32 s = *srcp++;
+ Uint32 d = *dstp;
+ *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1)
+ + (s & d & 0x00010101)) | dalpha;
+ n--;
+ }
+
+ for (n >>= 1; n > 0; --n) {
+ dst1 = *(__m64 *) dstp; /* 2 x dst -> dst1(ARGBARGB) */
+ dst2 = dst1; /* 2 x dst -> dst2(ARGBARGB) */
+
+ src1 = *(__m64 *) srcp; /* 2 x src -> src1(ARGBARGB) */
+ src2 = src1; /* 2 x src -> src2(ARGBARGB) */
+
+ dst2 = _mm_and_si64(dst2, hmask); /* dst & mask -> dst2 */
+ src2 = _mm_and_si64(src2, hmask); /* src & mask -> src2 */
+ src2 = _mm_add_pi32(src2, dst2); /* dst2 + src2 -> src2 */
+ src2 = _mm_srli_pi32(src2, 1); /* src2 >> 1 -> src2 */
+
+ dst1 = _mm_and_si64(dst1, src1); /* src & dst -> dst1 */
+ dst1 = _mm_and_si64(dst1, lmask); /* dst1 & !mask -> dst1 */
+ dst1 = _mm_add_pi32(dst1, src2); /* src2 + dst1 -> dst1 */
+ dst1 = _mm_or_si64(dst1, dsta); /* dsta(full alpha) | dst1 -> dst1 */
+
+ *(__m64 *) dstp = dst1; /* dst1 -> 2 x dst pixels */
+ dstp += 2;
+ srcp += 2;
+ }
+
+ srcp += srcskip;
+ dstp += dstskip;
+ }
+ _mm_empty();
+}
+
+/* fast RGB888->(A)RGB888 blending with surface alpha */
+static void
+BlitRGBtoRGBSurfaceAlphaMMX(SDL_BlitInfo * info)
+{
+ SDL_PixelFormat *df = info->dst_fmt;
+ Uint32 chanmask;
+ unsigned alpha = info->a;
+
+ if (alpha == 128 && (df->Rmask | df->Gmask | df->Bmask) == 0x00FFFFFF) {
+ /* only call a128 version when R,G,B occupy lower bits */
+ BlitRGBtoRGBSurfaceAlpha128MMX(info);
+ } else {
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint32 *srcp = (Uint32 *) info->src;
+ int srcskip = info->src_skip >> 2;
+ Uint32 *dstp = (Uint32 *) info->dst;
+ int dstskip = info->dst_skip >> 2;
+ Uint32 dalpha = df->Amask;
+ Uint32 amult;
+
+ __m64 src1, src2, dst1, dst2, mm_alpha, mm_zero, dsta;
+
+ mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */
+ /* form the alpha mult */
+ amult = alpha | (alpha << 8);
+ amult = amult | (amult << 16);
+ chanmask =
+ (0xff << df->Rshift) | (0xff << df->
+ Gshift) | (0xff << df->Bshift);
+ mm_alpha = _mm_set_pi32(0, amult & chanmask); /* 0000AAAA -> mm_alpha, minus 1 chan */
+ mm_alpha = _mm_unpacklo_pi8(mm_alpha, mm_zero); /* 0A0A0A0A -> mm_alpha, minus 1 chan */
+ /* at this point mm_alpha can be 000A0A0A or 0A0A0A00 or another combo */
+ dsta = _mm_set_pi32(dalpha, dalpha); /* dst alpha mask -> dsta */
+
+ while (height--) {
+ int n = width;
+ if (n & 1) {
+ /* One Pixel Blend */
+ src2 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src2 (0000ARGB) */
+ src2 = _mm_unpacklo_pi8(src2, mm_zero); /* 0A0R0G0B -> src2 */
+
+ dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB) */
+ dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */
+
+ src2 = _mm_sub_pi16(src2, dst1); /* src2 - dst2 -> src2 */
+ src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
+ src2 = _mm_srli_pi16(src2, 8); /* src2 >> 8 -> src2 */
+ dst1 = _mm_add_pi8(src2, dst1); /* src2 + dst1 -> dst1 */
+
+ dst1 = _mm_packs_pu16(dst1, mm_zero); /* 0000ARGB -> dst1 */
+ dst1 = _mm_or_si64(dst1, dsta); /* dsta | dst1 -> dst1 */
+ *dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */
+
+ ++srcp;
+ ++dstp;
+
+ n--;
+ }
+
+ for (n >>= 1; n > 0; --n) {
+ /* Two Pixels Blend */
+ src1 = *(__m64 *) srcp; /* 2 x src -> src1(ARGBARGB) */
+ src2 = src1; /* 2 x src -> src2(ARGBARGB) */
+ src1 = _mm_unpacklo_pi8(src1, mm_zero); /* low - 0A0R0G0B -> src1 */
+ src2 = _mm_unpackhi_pi8(src2, mm_zero); /* high - 0A0R0G0B -> src2 */
+
+ dst1 = *(__m64 *) dstp; /* 2 x dst -> dst1(ARGBARGB) */
+ dst2 = dst1; /* 2 x dst -> dst2(ARGBARGB) */
+ dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* low - 0A0R0G0B -> dst1 */
+ dst2 = _mm_unpackhi_pi8(dst2, mm_zero); /* high - 0A0R0G0B -> dst2 */
+
+ src1 = _mm_sub_pi16(src1, dst1); /* src1 - dst1 -> src1 */
+ src1 = _mm_mullo_pi16(src1, mm_alpha); /* src1 * alpha -> src1 */
+ src1 = _mm_srli_pi16(src1, 8); /* src1 >> 8 -> src1 */
+ dst1 = _mm_add_pi8(src1, dst1); /* src1 + dst1(dst1) -> dst1 */
+
+ src2 = _mm_sub_pi16(src2, dst2); /* src2 - dst2 -> src2 */
+ src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
+ src2 = _mm_srli_pi16(src2, 8); /* src2 >> 8 -> src2 */
+ dst2 = _mm_add_pi8(src2, dst2); /* src2 + dst2(dst2) -> dst2 */
+
+ dst1 = _mm_packs_pu16(dst1, dst2); /* 0A0R0G0B(res1), 0A0R0G0B(res2) -> dst1(ARGBARGB) */
+ dst1 = _mm_or_si64(dst1, dsta); /* dsta | dst1 -> dst1 */
+
+ *(__m64 *) dstp = dst1; /* dst1 -> 2 x pixel */
+
+ srcp += 2;
+ dstp += 2;
+ }
+ srcp += srcskip;
+ dstp += dstskip;
+ }
+ _mm_empty();
+ }
+}
+
+/* fast ARGB888->(A)RGB888 blending with pixel alpha */
+static void
+BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint32 *srcp = (Uint32 *) info->src;
+ int srcskip = info->src_skip >> 2;
+ Uint32 *dstp = (Uint32 *) info->dst;
+ int dstskip = info->dst_skip >> 2;
+ SDL_PixelFormat *sf = info->src_fmt;
+ Uint32 amask = sf->Amask;
+ Uint32 ashift = sf->Ashift;
+ Uint64 multmask, multmask2;
+
+ __m64 src1, dst1, mm_alpha, mm_zero, mm_alpha2;
+
+ mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */
+ multmask = 0x00FF;
+ multmask <<= (ashift * 2);
+ multmask2 = 0x00FF00FF00FF00FFULL;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP4({
+ Uint32 alpha = *srcp & amask;
+ if (alpha == 0) {
+ /* do nothing */
+ } else if (alpha == amask) {
+ *dstp = *srcp;
+ } else {
+ src1 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src1 (0000ARGB) */
+ src1 = _mm_unpacklo_pi8(src1, mm_zero); /* 0A0R0G0B -> src1 */
+
+ dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB) */
+ dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */
+
+ mm_alpha = _mm_cvtsi32_si64(alpha); /* alpha -> mm_alpha (0000000A) */
+ mm_alpha = _mm_srli_si64(mm_alpha, ashift); /* mm_alpha >> ashift -> mm_alpha(0000000A) */
+ mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */
+ mm_alpha2 = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha2 */
+ mm_alpha = _mm_or_si64(mm_alpha2, *(__m64 *) & multmask); /* 0F0A0A0A -> mm_alpha */
+ mm_alpha2 = _mm_xor_si64(mm_alpha2, *(__m64 *) & multmask2); /* 255 - mm_alpha -> mm_alpha */
+
+ /* blend */
+ src1 = _mm_mullo_pi16(src1, mm_alpha);
+ src1 = _mm_srli_pi16(src1, 8);
+ dst1 = _mm_mullo_pi16(dst1, mm_alpha2);
+ dst1 = _mm_srli_pi16(dst1, 8);
+ dst1 = _mm_add_pi16(src1, dst1);
+ dst1 = _mm_packs_pu16(dst1, mm_zero);
+
+ *dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */
+ }
+ ++srcp;
+ ++dstp;
+ }, width);
+ /* *INDENT-ON* */
+ srcp += srcskip;
+ dstp += dstskip;
+ }
+ _mm_empty();
+}
+
+#endif /* __MMX__ */
+
+/* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
+static void
+BlitRGBtoRGBSurfaceAlpha128(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint32 *srcp = (Uint32 *) info->src;
+ int srcskip = info->src_skip >> 2;
+ Uint32 *dstp = (Uint32 *) info->dst;
+ int dstskip = info->dst_skip >> 2;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP4({
+ Uint32 s = *srcp++;
+ Uint32 d = *dstp;
+ *dstp++ = ((((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1)
+ + (s & d & 0x00010101)) | 0xff000000;
+ }, width);
+ /* *INDENT-ON* */
+ srcp += srcskip;
+ dstp += dstskip;
+ }
+}
+
+/* fast RGB888->(A)RGB888 blending with surface alpha */
+static void
+BlitRGBtoRGBSurfaceAlpha(SDL_BlitInfo * info)
+{
+ unsigned alpha = info->a;
+ if (alpha == 128) {
+ BlitRGBtoRGBSurfaceAlpha128(info);
+ } else {
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint32 *srcp = (Uint32 *) info->src;
+ int srcskip = info->src_skip >> 2;
+ Uint32 *dstp = (Uint32 *) info->dst;
+ int dstskip = info->dst_skip >> 2;
+ Uint32 s;
+ Uint32 d;
+ Uint32 s1;
+ Uint32 d1;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP4({
+ s = *srcp;
+ d = *dstp;
+ s1 = s & 0xff00ff;
+ d1 = d & 0xff00ff;
+ d1 = (d1 + ((s1 - d1) * alpha >> 8))
+ & 0xff00ff;
+ s &= 0xff00;
+ d &= 0xff00;
+ d = (d + ((s - d) * alpha >> 8)) & 0xff00;
+ *dstp = d1 | d | 0xff000000;
+ ++srcp;
+ ++dstp;
+ }, width);
+ /* *INDENT-ON* */
+ srcp += srcskip;
+ dstp += dstskip;
+ }
+ }
+}
+
+/* fast ARGB888->(A)RGB888 blending with pixel alpha */
+static void
+BlitRGBtoRGBPixelAlpha(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint32 *srcp = (Uint32 *) info->src;
+ int srcskip = info->src_skip >> 2;
+ Uint32 *dstp = (Uint32 *) info->dst;
+ int dstskip = info->dst_skip >> 2;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP4({
+ Uint32 dalpha;
+ Uint32 d;
+ Uint32 s1;
+ Uint32 d1;
+ Uint32 s = *srcp;
+ Uint32 alpha = s >> 24;
+ /* FIXME: Here we special-case opaque alpha since the
+ compositioning used (>>8 instead of /255) doesn't handle
+ it correctly. Also special-case alpha=0 for speed?
+ Benchmark this! */
+ if (alpha) {
+ if (alpha == SDL_ALPHA_OPAQUE) {
+ *dstp = *srcp;
+ } else {
+ /*
+ * take out the middle component (green), and process
+ * the other two in parallel. One multiply less.
+ */
+ d = *dstp;
+ dalpha = d >> 24;
+ s1 = s & 0xff00ff;
+ d1 = d & 0xff00ff;
+ d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff;
+ s &= 0xff00;
+ d &= 0xff00;
+ d = (d + ((s - d) * alpha >> 8)) & 0xff00;
+ dalpha = alpha + (dalpha * (alpha ^ 0xFF) >> 8);
+ *dstp = d1 | d | (dalpha << 24);
+ }
+ }
+ ++srcp;
+ ++dstp;
+ }, width);
+ /* *INDENT-ON* */
+ srcp += srcskip;
+ dstp += dstskip;
+ }
+}
+
+#ifdef __3dNOW__
+/* fast (as in MMX with prefetch) ARGB888->(A)RGB888 blending with pixel alpha */
+static void
+BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint32 *srcp = (Uint32 *) info->src;
+ int srcskip = info->src_skip >> 2;
+ Uint32 *dstp = (Uint32 *) info->dst;
+ int dstskip = info->dst_skip >> 2;
+ SDL_PixelFormat *sf = info->src_fmt;
+ Uint32 amask = sf->Amask;
+ Uint32 ashift = sf->Ashift;
+ Uint64 multmask, multmask2;
+
+ __m64 src1, dst1, mm_alpha, mm_zero, mm_alpha2;
+
+ mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */
+ multmask = 0x00FF;
+ multmask <<= (ashift * 2);
+ multmask2 = 0x00FF00FF00FF00FFULL;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP4({
+ Uint32 alpha;
+
+ _m_prefetch(srcp + 16);
+ _m_prefetch(dstp + 16);
+
+ alpha = *srcp & amask;
+ if (alpha == 0) {
+ /* do nothing */
+ } else if (alpha == amask) {
+ *dstp = *srcp;
+ } else {
+ src1 = _mm_cvtsi32_si64(*srcp); /* src(ARGB) -> src1 (0000ARGB) */
+ src1 = _mm_unpacklo_pi8(src1, mm_zero); /* 0A0R0G0B -> src1 */
+
+ dst1 = _mm_cvtsi32_si64(*dstp); /* dst(ARGB) -> dst1 (0000ARGB) */
+ dst1 = _mm_unpacklo_pi8(dst1, mm_zero); /* 0A0R0G0B -> dst1 */
+
+ mm_alpha = _mm_cvtsi32_si64(alpha); /* alpha -> mm_alpha (0000000A) */
+ mm_alpha = _mm_srli_si64(mm_alpha, ashift); /* mm_alpha >> ashift -> mm_alpha(0000000A) */
+ mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */
+ mm_alpha2 = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha2 */
+ mm_alpha = _mm_or_si64(mm_alpha2, *(__m64 *) & multmask); /* 0F0A0A0A -> mm_alpha */
+ mm_alpha2 = _mm_xor_si64(mm_alpha2, *(__m64 *) & multmask2); /* 255 - mm_alpha -> mm_alpha */
+
+
+ /* blend */
+ src1 = _mm_mullo_pi16(src1, mm_alpha);
+ src1 = _mm_srli_pi16(src1, 8);
+ dst1 = _mm_mullo_pi16(dst1, mm_alpha2);
+ dst1 = _mm_srli_pi16(dst1, 8);
+ dst1 = _mm_add_pi16(src1, dst1);
+ dst1 = _mm_packs_pu16(dst1, mm_zero);
+
+ *dstp = _mm_cvtsi64_si32(dst1); /* dst1 -> pixel */
+ }
+ ++srcp;
+ ++dstp;
+ }, width);
+ /* *INDENT-ON* */
+ srcp += srcskip;
+ dstp += dstskip;
+ }
+ _mm_empty();
+}
+
+#endif /* __3dNOW__ */
+
+/* 16bpp special case for per-surface alpha=50%: blend 2 pixels in parallel */
+
+/* blend a single 16 bit pixel at 50% */
+#define BLEND16_50(d, s, mask) \
+ ((((s & mask) + (d & mask)) >> 1) + (s & d & (~mask & 0xffff)))
+
+/* blend two 16 bit pixels at 50% */
+#define BLEND2x16_50(d, s, mask) \
+ (((s & (mask | mask << 16)) >> 1) + ((d & (mask | mask << 16)) >> 1) \
+ + (s & d & (~(mask | mask << 16))))
+
+static void
+Blit16to16SurfaceAlpha128(SDL_BlitInfo * info, Uint16 mask)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint16 *srcp = (Uint16 *) info->src;
+ int srcskip = info->src_skip >> 1;
+ Uint16 *dstp = (Uint16 *) info->dst;
+ int dstskip = info->dst_skip >> 1;
+
+ while (height--) {
+ if (((uintptr_t) srcp ^ (uintptr_t) dstp) & 2) {
+ /*
+ * Source and destination not aligned, pipeline it.
+ * This is mostly a win for big blits but no loss for
+ * small ones
+ */
+ Uint32 prev_sw;
+ int w = width;
+
+ /* handle odd destination */
+ if ((uintptr_t) dstp & 2) {
+ Uint16 d = *dstp, s = *srcp;
+ *dstp = BLEND16_50(d, s, mask);
+ dstp++;
+ srcp++;
+ w--;
+ }
+ srcp++; /* srcp is now 32-bit aligned */
+
+ /* bootstrap pipeline with first halfword */
+ prev_sw = ((Uint32 *) srcp)[-1];
+
+ while (w > 1) {
+ Uint32 sw, dw, s;
+ sw = *(Uint32 *) srcp;
+ dw = *(Uint32 *) dstp;
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ s = (prev_sw << 16) + (sw >> 16);
+#else
+ s = (prev_sw >> 16) + (sw << 16);
+#endif
+ prev_sw = sw;
+ *(Uint32 *) dstp = BLEND2x16_50(dw, s, mask);
+ dstp += 2;
+ srcp += 2;
+ w -= 2;
+ }
+
+ /* final pixel if any */
+ if (w) {
+ Uint16 d = *dstp, s;
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ s = (Uint16) prev_sw;
+#else
+ s = (Uint16) (prev_sw >> 16);
+#endif
+ *dstp = BLEND16_50(d, s, mask);
+ srcp++;
+ dstp++;
+ }
+ srcp += srcskip - 1;
+ dstp += dstskip;
+ } else {
+ /* source and destination are aligned */
+ int w = width;
+
+ /* first odd pixel? */
+ if ((uintptr_t) srcp & 2) {
+ Uint16 d = *dstp, s = *srcp;
+ *dstp = BLEND16_50(d, s, mask);
+ srcp++;
+ dstp++;
+ w--;
+ }
+ /* srcp and dstp are now 32-bit aligned */
+
+ while (w > 1) {
+ Uint32 sw = *(Uint32 *) srcp;
+ Uint32 dw = *(Uint32 *) dstp;
+ *(Uint32 *) dstp = BLEND2x16_50(dw, sw, mask);
+ srcp += 2;
+ dstp += 2;
+ w -= 2;
+ }
+
+ /* last odd pixel? */
+ if (w) {
+ Uint16 d = *dstp, s = *srcp;
+ *dstp = BLEND16_50(d, s, mask);
+ srcp++;
+ dstp++;
+ }
+ srcp += srcskip;
+ dstp += dstskip;
+ }
+ }
+}
+
+#ifdef __MMX__
+
+/* fast RGB565->RGB565 blending with surface alpha */
+static void
+Blit565to565SurfaceAlphaMMX(SDL_BlitInfo * info)
+{
+ unsigned alpha = info->a;
+ if (alpha == 128) {
+ Blit16to16SurfaceAlpha128(info, 0xf7de);
+ } else {
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint16 *srcp = (Uint16 *) info->src;
+ int srcskip = info->src_skip >> 1;
+ Uint16 *dstp = (Uint16 *) info->dst;
+ int dstskip = info->dst_skip >> 1;
+ Uint32 s, d;
+
+ __m64 src1, dst1, src2, dst2, gmask, bmask, mm_res, mm_alpha;
+
+ alpha &= ~(1 + 2 + 4); /* cut alpha to get the exact same behaviour */
+ mm_alpha = _mm_set_pi32(0, alpha); /* 0000000A -> mm_alpha */
+ alpha >>= 3; /* downscale alpha to 5 bits */
+
+ mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */
+ mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */
+ /* position alpha to allow for mullo and mulhi on diff channels
+ to reduce the number of operations */
+ mm_alpha = _mm_slli_si64(mm_alpha, 3);
+
+ /* Setup the 565 color channel masks */
+ gmask = _mm_set_pi32(0x07E007E0, 0x07E007E0); /* MASKGREEN -> gmask */
+ bmask = _mm_set_pi32(0x001F001F, 0x001F001F); /* MASKBLUE -> bmask */
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP_124(
+ {
+ s = *srcp++;
+ d = *dstp;
+ /*
+ * shift out the middle component (green) to
+ * the high 16 bits, and process all three RGB
+ * components at the same time.
+ */
+ s = (s | s << 16) & 0x07e0f81f;
+ d = (d | d << 16) & 0x07e0f81f;
+ d += (s - d) * alpha >> 5;
+ d &= 0x07e0f81f;
+ *dstp++ = (Uint16)(d | d >> 16);
+ },{
+ s = *srcp++;
+ d = *dstp;
+ /*
+ * shift out the middle component (green) to
+ * the high 16 bits, and process all three RGB
+ * components at the same time.
+ */
+ s = (s | s << 16) & 0x07e0f81f;
+ d = (d | d << 16) & 0x07e0f81f;
+ d += (s - d) * alpha >> 5;
+ d &= 0x07e0f81f;
+ *dstp++ = (Uint16)(d | d >> 16);
+ s = *srcp++;
+ d = *dstp;
+ /*
+ * shift out the middle component (green) to
+ * the high 16 bits, and process all three RGB
+ * components at the same time.
+ */
+ s = (s | s << 16) & 0x07e0f81f;
+ d = (d | d << 16) & 0x07e0f81f;
+ d += (s - d) * alpha >> 5;
+ d &= 0x07e0f81f;
+ *dstp++ = (Uint16)(d | d >> 16);
+ },{
+ src1 = *(__m64*)srcp; /* 4 src pixels -> src1 */
+ dst1 = *(__m64*)dstp; /* 4 dst pixels -> dst1 */
+
+ /* red */
+ src2 = src1;
+ src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 [000r 000r 000r 000r] */
+
+ dst2 = dst1;
+ dst2 = _mm_srli_pi16(dst2, 11); /* dst2 >> 11 -> dst2 [000r 000r 000r 000r] */
+
+ /* blend */
+ src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */
+ src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
+ src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 */
+ dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */
+ dst2 = _mm_slli_pi16(dst2, 11); /* dst2 << 11 -> dst2 */
+
+ mm_res = dst2; /* RED -> mm_res */
+
+ /* green -- process the bits in place */
+ src2 = src1;
+ src2 = _mm_and_si64(src2, gmask); /* src & MASKGREEN -> src2 */
+
+ dst2 = dst1;
+ dst2 = _mm_and_si64(dst2, gmask); /* dst & MASKGREEN -> dst2 */
+
+ /* blend */
+ src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */
+ src2 = _mm_mulhi_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
+ src2 = _mm_slli_pi16(src2, 5); /* src2 << 5 -> src2 */
+ dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */
+
+ mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN -> mm_res */
+
+ /* blue */
+ src2 = src1;
+ src2 = _mm_and_si64(src2, bmask); /* src & MASKBLUE -> src2[000b 000b 000b 000b] */
+
+ dst2 = dst1;
+ dst2 = _mm_and_si64(dst2, bmask); /* dst & MASKBLUE -> dst2[000b 000b 000b 000b] */
+
+ /* blend */
+ src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */
+ src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
+ src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 */
+ dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */
+ dst2 = _mm_and_si64(dst2, bmask); /* dst2 & MASKBLUE -> dst2 */
+
+ mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN | BLUE -> mm_res */
+
+ *(__m64*)dstp = mm_res; /* mm_res -> 4 dst pixels */
+
+ srcp += 4;
+ dstp += 4;
+ }, width);
+ /* *INDENT-ON* */
+ srcp += srcskip;
+ dstp += dstskip;
+ }
+ _mm_empty();
+ }
+}
+
+/* fast RGB555->RGB555 blending with surface alpha */
+static void
+Blit555to555SurfaceAlphaMMX(SDL_BlitInfo * info)
+{
+ unsigned alpha = info->a;
+ if (alpha == 128) {
+ Blit16to16SurfaceAlpha128(info, 0xfbde);
+ } else {
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint16 *srcp = (Uint16 *) info->src;
+ int srcskip = info->src_skip >> 1;
+ Uint16 *dstp = (Uint16 *) info->dst;
+ int dstskip = info->dst_skip >> 1;
+ Uint32 s, d;
+
+ __m64 src1, dst1, src2, dst2, rmask, gmask, bmask, mm_res, mm_alpha;
+
+ alpha &= ~(1 + 2 + 4); /* cut alpha to get the exact same behaviour */
+ mm_alpha = _mm_set_pi32(0, alpha); /* 0000000A -> mm_alpha */
+ alpha >>= 3; /* downscale alpha to 5 bits */
+
+ mm_alpha = _mm_unpacklo_pi16(mm_alpha, mm_alpha); /* 00000A0A -> mm_alpha */
+ mm_alpha = _mm_unpacklo_pi32(mm_alpha, mm_alpha); /* 0A0A0A0A -> mm_alpha */
+ /* position alpha to allow for mullo and mulhi on diff channels
+ to reduce the number of operations */
+ mm_alpha = _mm_slli_si64(mm_alpha, 3);
+
+ /* Setup the 555 color channel masks */
+ rmask = _mm_set_pi32(0x7C007C00, 0x7C007C00); /* MASKRED -> rmask */
+ gmask = _mm_set_pi32(0x03E003E0, 0x03E003E0); /* MASKGREEN -> gmask */
+ bmask = _mm_set_pi32(0x001F001F, 0x001F001F); /* MASKBLUE -> bmask */
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP_124(
+ {
+ s = *srcp++;
+ d = *dstp;
+ /*
+ * shift out the middle component (green) to
+ * the high 16 bits, and process all three RGB
+ * components at the same time.
+ */
+ s = (s | s << 16) & 0x03e07c1f;
+ d = (d | d << 16) & 0x03e07c1f;
+ d += (s - d) * alpha >> 5;
+ d &= 0x03e07c1f;
+ *dstp++ = (Uint16)(d | d >> 16);
+ },{
+ s = *srcp++;
+ d = *dstp;
+ /*
+ * shift out the middle component (green) to
+ * the high 16 bits, and process all three RGB
+ * components at the same time.
+ */
+ s = (s | s << 16) & 0x03e07c1f;
+ d = (d | d << 16) & 0x03e07c1f;
+ d += (s - d) * alpha >> 5;
+ d &= 0x03e07c1f;
+ *dstp++ = (Uint16)(d | d >> 16);
+ s = *srcp++;
+ d = *dstp;
+ /*
+ * shift out the middle component (green) to
+ * the high 16 bits, and process all three RGB
+ * components at the same time.
+ */
+ s = (s | s << 16) & 0x03e07c1f;
+ d = (d | d << 16) & 0x03e07c1f;
+ d += (s - d) * alpha >> 5;
+ d &= 0x03e07c1f;
+ *dstp++ = (Uint16)(d | d >> 16);
+ },{
+ src1 = *(__m64*)srcp; /* 4 src pixels -> src1 */
+ dst1 = *(__m64*)dstp; /* 4 dst pixels -> dst1 */
+
+ /* red -- process the bits in place */
+ src2 = src1;
+ src2 = _mm_and_si64(src2, rmask); /* src & MASKRED -> src2 */
+
+ dst2 = dst1;
+ dst2 = _mm_and_si64(dst2, rmask); /* dst & MASKRED -> dst2 */
+
+ /* blend */
+ src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */
+ src2 = _mm_mulhi_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
+ src2 = _mm_slli_pi16(src2, 5); /* src2 << 5 -> src2 */
+ dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */
+ dst2 = _mm_and_si64(dst2, rmask); /* dst2 & MASKRED -> dst2 */
+
+ mm_res = dst2; /* RED -> mm_res */
+
+ /* green -- process the bits in place */
+ src2 = src1;
+ src2 = _mm_and_si64(src2, gmask); /* src & MASKGREEN -> src2 */
+
+ dst2 = dst1;
+ dst2 = _mm_and_si64(dst2, gmask); /* dst & MASKGREEN -> dst2 */
+
+ /* blend */
+ src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */
+ src2 = _mm_mulhi_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
+ src2 = _mm_slli_pi16(src2, 5); /* src2 << 5 -> src2 */
+ dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */
+
+ mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN -> mm_res */
+
+ /* blue */
+ src2 = src1; /* src -> src2 */
+ src2 = _mm_and_si64(src2, bmask); /* src & MASKBLUE -> src2[000b 000b 000b 000b] */
+
+ dst2 = dst1; /* dst -> dst2 */
+ dst2 = _mm_and_si64(dst2, bmask); /* dst & MASKBLUE -> dst2[000b 000b 000b 000b] */
+
+ /* blend */
+ src2 = _mm_sub_pi16(src2, dst2);/* src - dst -> src2 */
+ src2 = _mm_mullo_pi16(src2, mm_alpha); /* src2 * alpha -> src2 */
+ src2 = _mm_srli_pi16(src2, 11); /* src2 >> 11 -> src2 */
+ dst2 = _mm_add_pi16(src2, dst2); /* src2 + dst2 -> dst2 */
+ dst2 = _mm_and_si64(dst2, bmask); /* dst2 & MASKBLUE -> dst2 */
+
+ mm_res = _mm_or_si64(mm_res, dst2); /* RED | GREEN | BLUE -> mm_res */
+
+ *(__m64*)dstp = mm_res; /* mm_res -> 4 dst pixels */
+
+ srcp += 4;
+ dstp += 4;
+ }, width);
+ /* *INDENT-ON* */
+ srcp += srcskip;
+ dstp += dstskip;
+ }
+ _mm_empty();
+ }
+}
+
+#endif /* __MMX__ */
+
+/* fast RGB565->RGB565 blending with surface alpha */
+static void
+Blit565to565SurfaceAlpha(SDL_BlitInfo * info)
+{
+ unsigned alpha = info->a;
+ if (alpha == 128) {
+ Blit16to16SurfaceAlpha128(info, 0xf7de);
+ } else {
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint16 *srcp = (Uint16 *) info->src;
+ int srcskip = info->src_skip >> 1;
+ Uint16 *dstp = (Uint16 *) info->dst;
+ int dstskip = info->dst_skip >> 1;
+ alpha >>= 3; /* downscale alpha to 5 bits */
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP4({
+ Uint32 s = *srcp++;
+ Uint32 d = *dstp;
+ /*
+ * shift out the middle component (green) to
+ * the high 16 bits, and process all three RGB
+ * components at the same time.
+ */
+ s = (s | s << 16) & 0x07e0f81f;
+ d = (d | d << 16) & 0x07e0f81f;
+ d += (s - d) * alpha >> 5;
+ d &= 0x07e0f81f;
+ *dstp++ = (Uint16)(d | d >> 16);
+ }, width);
+ /* *INDENT-ON* */
+ srcp += srcskip;
+ dstp += dstskip;
+ }
+ }
+}
+
+/* fast RGB555->RGB555 blending with surface alpha */
+static void
+Blit555to555SurfaceAlpha(SDL_BlitInfo * info)
+{
+ unsigned alpha = info->a; /* downscale alpha to 5 bits */
+ if (alpha == 128) {
+ Blit16to16SurfaceAlpha128(info, 0xfbde);
+ } else {
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint16 *srcp = (Uint16 *) info->src;
+ int srcskip = info->src_skip >> 1;
+ Uint16 *dstp = (Uint16 *) info->dst;
+ int dstskip = info->dst_skip >> 1;
+ alpha >>= 3; /* downscale alpha to 5 bits */
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP4({
+ Uint32 s = *srcp++;
+ Uint32 d = *dstp;
+ /*
+ * shift out the middle component (green) to
+ * the high 16 bits, and process all three RGB
+ * components at the same time.
+ */
+ s = (s | s << 16) & 0x03e07c1f;
+ d = (d | d << 16) & 0x03e07c1f;
+ d += (s - d) * alpha >> 5;
+ d &= 0x03e07c1f;
+ *dstp++ = (Uint16)(d | d >> 16);
+ }, width);
+ /* *INDENT-ON* */
+ srcp += srcskip;
+ dstp += dstskip;
+ }
+ }
+}
+
+/* fast ARGB8888->RGB565 blending with pixel alpha */
+static void
+BlitARGBto565PixelAlpha(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint32 *srcp = (Uint32 *) info->src;
+ int srcskip = info->src_skip >> 2;
+ Uint16 *dstp = (Uint16 *) info->dst;
+ int dstskip = info->dst_skip >> 1;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP4({
+ Uint32 s = *srcp;
+ unsigned alpha = s >> 27; /* downscale alpha to 5 bits */
+ /* FIXME: Here we special-case opaque alpha since the
+ compositioning used (>>8 instead of /255) doesn't handle
+ it correctly. Also special-case alpha=0 for speed?
+ Benchmark this! */
+ if(alpha) {
+ if(alpha == (SDL_ALPHA_OPAQUE >> 3)) {
+ *dstp = (Uint16)((s >> 8 & 0xf800) + (s >> 5 & 0x7e0) + (s >> 3 & 0x1f));
+ } else {
+ Uint32 d = *dstp;
+ /*
+ * convert source and destination to G0RAB65565
+ * and blend all components at the same time
+ */
+ s = ((s & 0xfc00) << 11) + (s >> 8 & 0xf800)
+ + (s >> 3 & 0x1f);
+ d = (d | d << 16) & 0x07e0f81f;
+ d += (s - d) * alpha >> 5;
+ d &= 0x07e0f81f;
+ *dstp = (Uint16)(d | d >> 16);
+ }
+ }
+ srcp++;
+ dstp++;
+ }, width);
+ /* *INDENT-ON* */
+ srcp += srcskip;
+ dstp += dstskip;
+ }
+}
+
+/* fast ARGB8888->RGB555 blending with pixel alpha */
+static void
+BlitARGBto555PixelAlpha(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint32 *srcp = (Uint32 *) info->src;
+ int srcskip = info->src_skip >> 2;
+ Uint16 *dstp = (Uint16 *) info->dst;
+ int dstskip = info->dst_skip >> 1;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP4({
+ unsigned alpha;
+ Uint32 s = *srcp;
+ alpha = s >> 27; /* downscale alpha to 5 bits */
+ /* FIXME: Here we special-case opaque alpha since the
+ compositioning used (>>8 instead of /255) doesn't handle
+ it correctly. Also special-case alpha=0 for speed?
+ Benchmark this! */
+ if(alpha) {
+ if(alpha == (SDL_ALPHA_OPAQUE >> 3)) {
+ *dstp = (Uint16)((s >> 9 & 0x7c00) + (s >> 6 & 0x3e0) + (s >> 3 & 0x1f));
+ } else {
+ Uint32 d = *dstp;
+ /*
+ * convert source and destination to G0RAB65565
+ * and blend all components at the same time
+ */
+ s = ((s & 0xf800) << 10) + (s >> 9 & 0x7c00)
+ + (s >> 3 & 0x1f);
+ d = (d | d << 16) & 0x03e07c1f;
+ d += (s - d) * alpha >> 5;
+ d &= 0x03e07c1f;
+ *dstp = (Uint16)(d | d >> 16);
+ }
+ }
+ srcp++;
+ dstp++;
+ }, width);
+ /* *INDENT-ON* */
+ srcp += srcskip;
+ dstp += dstskip;
+ }
+}
+
+/* General (slow) N->N blending with per-surface alpha */
+static void
+BlitNtoNSurfaceAlpha(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = info->dst;
+ int dstskip = info->dst_skip;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ int srcbpp = srcfmt->BytesPerPixel;
+ int dstbpp = dstfmt->BytesPerPixel;
+ Uint32 Pixel;
+ unsigned sR, sG, sB;
+ unsigned dR, dG, dB, dA;
+ const unsigned sA = info->a;
+
+ if (sA) {
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP4(
+ {
+ DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
+ DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA);
+ ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA);
+ ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
+ src += srcbpp;
+ dst += dstbpp;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+ }
+}
+
+/* General (slow) colorkeyed N->N blending with per-surface alpha */
+static void
+BlitNtoNSurfaceAlphaKey(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = info->dst;
+ int dstskip = info->dst_skip;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ Uint32 ckey = info->colorkey;
+ int srcbpp = srcfmt->BytesPerPixel;
+ int dstbpp = dstfmt->BytesPerPixel;
+ Uint32 Pixel;
+ unsigned sR, sG, sB;
+ unsigned dR, dG, dB, dA;
+ const unsigned sA = info->a;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP4(
+ {
+ RETRIEVE_RGB_PIXEL(src, srcbpp, Pixel);
+ if(sA && Pixel != ckey) {
+ RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB);
+ DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA);
+ ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA);
+ ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
+ }
+ src += srcbpp;
+ dst += dstbpp;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+/* General (slow) N->N blending with pixel alpha */
+static void
+BlitNtoNPixelAlpha(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = info->dst;
+ int dstskip = info->dst_skip;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ int srcbpp;
+ int dstbpp;
+ Uint32 Pixel;
+ unsigned sR, sG, sB, sA;
+ unsigned dR, dG, dB, dA;
+
+ /* Set up some basic variables */
+ srcbpp = srcfmt->BytesPerPixel;
+ dstbpp = dstfmt->BytesPerPixel;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP4(
+ {
+ DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA);
+ if(sA) {
+ DISEMBLE_RGBA(dst, dstbpp, dstfmt, Pixel, dR, dG, dB, dA);
+ ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA);
+ ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
+ }
+ src += srcbpp;
+ dst += dstbpp;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+
+SDL_BlitFunc
+SDL_CalculateBlitA(SDL_Surface * surface)
+{
+ SDL_PixelFormat *sf = surface->format;
+ SDL_PixelFormat *df = surface->map->dst->format;
+
+ switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
+ case SDL_COPY_BLEND:
+ /* Per-pixel alpha blits */
+ switch (df->BytesPerPixel) {
+ case 1:
+ return BlitNto1PixelAlpha;
+
+ case 2:
+ if (sf->BytesPerPixel == 4 && sf->Amask == 0xff000000
+ && sf->Gmask == 0xff00
+ && ((sf->Rmask == 0xff && df->Rmask == 0x1f)
+ || (sf->Bmask == 0xff && df->Bmask == 0x1f))) {
+ if (df->Gmask == 0x7e0)
+ return BlitARGBto565PixelAlpha;
+ else if (df->Gmask == 0x3e0)
+ return BlitARGBto555PixelAlpha;
+ }
+ return BlitNtoNPixelAlpha;
+
+ case 4:
+ if (sf->Rmask == df->Rmask
+ && sf->Gmask == df->Gmask
+ && sf->Bmask == df->Bmask && sf->BytesPerPixel == 4) {
+#if defined(__MMX__) || defined(__3dNOW__)
+ if (sf->Rshift % 8 == 0
+ && sf->Gshift % 8 == 0
+ && sf->Bshift % 8 == 0
+ && sf->Ashift % 8 == 0 && sf->Aloss == 0) {
+#ifdef __3dNOW__
+ if (SDL_Has3DNow())
+ return BlitRGBtoRGBPixelAlphaMMX3DNOW;
+#endif
+#ifdef __MMX__
+ if (SDL_HasMMX())
+ return BlitRGBtoRGBPixelAlphaMMX;
+#endif
+ }
+#endif /* __MMX__ || __3dNOW__ */
+ if (sf->Amask == 0xff000000) {
+ return BlitRGBtoRGBPixelAlpha;
+ }
+ }
+ return BlitNtoNPixelAlpha;
+
+ case 3:
+ default:
+ break;
+ }
+ return BlitNtoNPixelAlpha;
+
+ case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
+ if (sf->Amask == 0) {
+ /* Per-surface alpha blits */
+ switch (df->BytesPerPixel) {
+ case 1:
+ return BlitNto1SurfaceAlpha;
+
+ case 2:
+ if (surface->map->identity) {
+ if (df->Gmask == 0x7e0) {
+#ifdef __MMX__
+ if (SDL_HasMMX())
+ return Blit565to565SurfaceAlphaMMX;
+ else
+#endif
+ return Blit565to565SurfaceAlpha;
+ } else if (df->Gmask == 0x3e0) {
+#ifdef __MMX__
+ if (SDL_HasMMX())
+ return Blit555to555SurfaceAlphaMMX;
+ else
+#endif
+ return Blit555to555SurfaceAlpha;
+ }
+ }
+ return BlitNtoNSurfaceAlpha;
+
+ case 4:
+ if (sf->Rmask == df->Rmask
+ && sf->Gmask == df->Gmask
+ && sf->Bmask == df->Bmask && sf->BytesPerPixel == 4) {
+#ifdef __MMX__
+ if (sf->Rshift % 8 == 0
+ && sf->Gshift % 8 == 0
+ && sf->Bshift % 8 == 0 && SDL_HasMMX())
+ return BlitRGBtoRGBSurfaceAlphaMMX;
+#endif
+ if ((sf->Rmask | sf->Gmask | sf->Bmask) == 0xffffff) {
+ return BlitRGBtoRGBSurfaceAlpha;
+ }
+ }
+ return BlitNtoNSurfaceAlpha;
+
+ case 3:
+ default:
+ return BlitNtoNSurfaceAlpha;
+ }
+ }
+ break;
+
+ case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
+ if (sf->Amask == 0) {
+ if (df->BytesPerPixel == 1) {
+ return BlitNto1SurfaceAlphaKey;
+ } else {
+ return BlitNtoNSurfaceAlphaKey;
+ }
+ }
+ break;
+ }
+
+ return NULL;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_blit_N.c b/src/3rdparty/SDL2/src/video/SDL_blit_N.c
new file mode 100644
index 0000000..441cd9a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_blit_N.c
@@ -0,0 +1,2647 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "SDL_video.h"
+#include "SDL_endian.h"
+#include "SDL_cpuinfo.h"
+#include "SDL_blit.h"
+
+#include "SDL_assert.h"
+
+/* Functions to blit from N-bit surfaces to other surfaces */
+
+#if SDL_ALTIVEC_BLITTERS
+#ifdef HAVE_ALTIVEC_H
+#include <altivec.h>
+#endif
+#ifdef __MACOSX__
+#include <sys/sysctl.h>
+static size_t
+GetL3CacheSize(void)
+{
+ const char key[] = "hw.l3cachesize";
+ u_int64_t result = 0;
+ size_t typeSize = sizeof(result);
+
+
+ int err = sysctlbyname(key, &result, &typeSize, NULL, 0);
+ if (0 != err)
+ return 0;
+
+ return result;
+}
+#else
+static size_t
+GetL3CacheSize(void)
+{
+ /* XXX: Just guess G4 */
+ return 2097152;
+}
+#endif /* __MACOSX__ */
+
+#if (defined(__MACOSX__) && (__GNUC__ < 4))
+#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
+ (vector unsigned char) ( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p )
+#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
+ (vector unsigned short) ( a,b,c,d,e,f,g,h )
+#else
+#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
+ (vector unsigned char) { a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p }
+#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
+ (vector unsigned short) { a,b,c,d,e,f,g,h }
+#endif
+
+#define UNALIGNED_PTR(x) (((size_t) x) & 0x0000000F)
+#define VSWIZZLE32(a,b,c,d) (vector unsigned char) \
+ ( 0x00+a, 0x00+b, 0x00+c, 0x00+d, \
+ 0x04+a, 0x04+b, 0x04+c, 0x04+d, \
+ 0x08+a, 0x08+b, 0x08+c, 0x08+d, \
+ 0x0C+a, 0x0C+b, 0x0C+c, 0x0C+d )
+
+#define MAKE8888(dstfmt, r, g, b, a) \
+ ( ((r<<dstfmt->Rshift)&dstfmt->Rmask) | \
+ ((g<<dstfmt->Gshift)&dstfmt->Gmask) | \
+ ((b<<dstfmt->Bshift)&dstfmt->Bmask) | \
+ ((a<<dstfmt->Ashift)&dstfmt->Amask) )
+
+/*
+ * Data Stream Touch...Altivec cache prefetching.
+ *
+ * Don't use this on a G5...however, the speed boost is very significant
+ * on a G4.
+ */
+#define DST_CHAN_SRC 1
+#define DST_CHAN_DEST 2
+
+/* macro to set DST control word value... */
+#define DST_CTRL(size, count, stride) \
+ (((size) << 24) | ((count) << 16) | (stride))
+
+#define VEC_ALIGNER(src) ((UNALIGNED_PTR(src)) \
+ ? vec_lvsl(0, src) \
+ : vec_add(vec_lvsl(8, src), vec_splat_u8(8)))
+
+/* Calculate the permute vector used for 32->32 swizzling */
+static vector unsigned char
+calc_swizzle32(const SDL_PixelFormat * srcfmt, const SDL_PixelFormat * dstfmt)
+{
+ /*
+ * We have to assume that the bits that aren't used by other
+ * colors is alpha, and it's one complete byte, since some formats
+ * leave alpha with a zero mask, but we should still swizzle the bits.
+ */
+ /* ARGB */
+ const static const struct SDL_PixelFormat default_pixel_format = {
+ 0, NULL, 0, 0,
+ {0, 0},
+ 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000,
+ 0, 0, 0, 0,
+ 16, 8, 0, 24,
+ 0, NULL
+ };
+ const vector unsigned char plus = VECUINT8_LITERAL(0x00, 0x00, 0x00, 0x00,
+ 0x04, 0x04, 0x04, 0x04,
+ 0x08, 0x08, 0x08, 0x08,
+ 0x0C, 0x0C, 0x0C,
+ 0x0C);
+ vector unsigned char vswiz;
+ vector unsigned int srcvec;
+ Uint32 rmask, gmask, bmask, amask;
+
+ if (!srcfmt) {
+ srcfmt = &default_pixel_format;
+ }
+ if (!dstfmt) {
+ dstfmt = &default_pixel_format;
+ }
+
+#define RESHIFT(X) (3 - ((X) >> 3))
+ rmask = RESHIFT(srcfmt->Rshift) << (dstfmt->Rshift);
+ gmask = RESHIFT(srcfmt->Gshift) << (dstfmt->Gshift);
+ bmask = RESHIFT(srcfmt->Bshift) << (dstfmt->Bshift);
+
+ /* Use zero for alpha if either surface doesn't have alpha */
+ if (dstfmt->Amask) {
+ amask =
+ ((srcfmt->Amask) ? RESHIFT(srcfmt->
+ Ashift) : 0x10) << (dstfmt->Ashift);
+ } else {
+ amask =
+ 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^
+ 0xFFFFFFFF);
+ }
+#undef RESHIFT
+
+ ((unsigned int *) (char *) &srcvec)[0] = (rmask | gmask | bmask | amask);
+ vswiz = vec_add(plus, (vector unsigned char) vec_splat(srcvec, 0));
+ return (vswiz);
+}
+
+static void Blit_RGB888_RGB565(SDL_BlitInfo * info);
+static void
+Blit_RGB888_RGB565Altivec(SDL_BlitInfo * info)
+{
+ int height = info->dst_h;
+ Uint8 *src = (Uint8 *) info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = (Uint8 *) info->dst;
+ int dstskip = info->dst_skip;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ vector unsigned char valpha = vec_splat_u8(0);
+ vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL);
+ vector unsigned char vgmerge = VECUINT8_LITERAL(0x00, 0x02, 0x00, 0x06,
+ 0x00, 0x0a, 0x00, 0x0e,
+ 0x00, 0x12, 0x00, 0x16,
+ 0x00, 0x1a, 0x00, 0x1e);
+ vector unsigned short v1 = vec_splat_u16(1);
+ vector unsigned short v3 = vec_splat_u16(3);
+ vector unsigned short v3f =
+ VECUINT16_LITERAL(0x003f, 0x003f, 0x003f, 0x003f,
+ 0x003f, 0x003f, 0x003f, 0x003f);
+ vector unsigned short vfc =
+ VECUINT16_LITERAL(0x00fc, 0x00fc, 0x00fc, 0x00fc,
+ 0x00fc, 0x00fc, 0x00fc, 0x00fc);
+ vector unsigned short vf800 = (vector unsigned short) vec_splat_u8(-7);
+ vf800 = vec_sl(vf800, vec_splat_u16(8));
+
+ while (height--) {
+ vector unsigned char valigner;
+ vector unsigned char voverflow;
+ vector unsigned char vsrc;
+
+ int width = info->dst_w;
+ int extrawidth;
+
+ /* do scalar until we can align... */
+#define ONE_PIXEL_BLEND(condition, widthvar) \
+ while (condition) { \
+ Uint32 Pixel; \
+ unsigned sR, sG, sB, sA; \
+ DISEMBLE_RGBA((Uint8 *)src, 4, srcfmt, Pixel, \
+ sR, sG, sB, sA); \
+ *(Uint16 *)(dst) = (((sR << 8) & 0x0000F800) | \
+ ((sG << 3) & 0x000007E0) | \
+ ((sB >> 3) & 0x0000001F)); \
+ dst += 2; \
+ src += 4; \
+ widthvar--; \
+ }
+
+ ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
+
+ /* After all that work, here's the vector part! */
+ extrawidth = (width % 8); /* trailing unaligned stores */
+ width -= extrawidth;
+ vsrc = vec_ld(0, src);
+ valigner = VEC_ALIGNER(src);
+
+ while (width) {
+ vector unsigned short vpixel, vrpixel, vgpixel, vbpixel;
+ vector unsigned int vsrc1, vsrc2;
+ vector unsigned char vdst;
+
+ voverflow = vec_ld(15, src);
+ vsrc = vec_perm(vsrc, voverflow, valigner);
+ vsrc1 = (vector unsigned int) vec_perm(vsrc, valpha, vpermute);
+ src += 16;
+ vsrc = voverflow;
+ voverflow = vec_ld(15, src);
+ vsrc = vec_perm(vsrc, voverflow, valigner);
+ vsrc2 = (vector unsigned int) vec_perm(vsrc, valpha, vpermute);
+ /* 1555 */
+ vpixel = (vector unsigned short) vec_packpx(vsrc1, vsrc2);
+ vgpixel = (vector unsigned short) vec_perm(vsrc1, vsrc2, vgmerge);
+ vgpixel = vec_and(vgpixel, vfc);
+ vgpixel = vec_sl(vgpixel, v3);
+ vrpixel = vec_sl(vpixel, v1);
+ vrpixel = vec_and(vrpixel, vf800);
+ vbpixel = vec_and(vpixel, v3f);
+ vdst =
+ vec_or((vector unsigned char) vrpixel,
+ (vector unsigned char) vgpixel);
+ /* 565 */
+ vdst = vec_or(vdst, (vector unsigned char) vbpixel);
+ vec_st(vdst, 0, dst);
+
+ width -= 8;
+ src += 16;
+ dst += 16;
+ vsrc = voverflow;
+ }
+
+ SDL_assert(width == 0);
+
+ /* do scalar until we can align... */
+ ONE_PIXEL_BLEND((extrawidth), extrawidth);
+#undef ONE_PIXEL_BLEND
+
+ src += srcskip; /* move to next row, accounting for pitch. */
+ dst += dstskip;
+ }
+
+
+}
+
+static void
+Blit_RGB565_32Altivec(SDL_BlitInfo * info)
+{
+ int height = info->dst_h;
+ Uint8 *src = (Uint8 *) info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = (Uint8 *) info->dst;
+ int dstskip = info->dst_skip;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ unsigned alpha;
+ vector unsigned char valpha;
+ vector unsigned char vpermute;
+ vector unsigned short vf800;
+ vector unsigned int v8 = vec_splat_u32(8);
+ vector unsigned int v16 = vec_add(v8, v8);
+ vector unsigned short v2 = vec_splat_u16(2);
+ vector unsigned short v3 = vec_splat_u16(3);
+ /*
+ 0x10 - 0x1f is the alpha
+ 0x00 - 0x0e evens are the red
+ 0x01 - 0x0f odds are zero
+ */
+ vector unsigned char vredalpha1 = VECUINT8_LITERAL(0x10, 0x00, 0x01, 0x01,
+ 0x10, 0x02, 0x01, 0x01,
+ 0x10, 0x04, 0x01, 0x01,
+ 0x10, 0x06, 0x01,
+ 0x01);
+ vector unsigned char vredalpha2 =
+ (vector unsigned
+ char) (vec_add((vector unsigned int) vredalpha1, vec_sl(v8, v16))
+ );
+ /*
+ 0x00 - 0x0f is ARxx ARxx ARxx ARxx
+ 0x11 - 0x0f odds are blue
+ */
+ vector unsigned char vblue1 = VECUINT8_LITERAL(0x00, 0x01, 0x02, 0x11,
+ 0x04, 0x05, 0x06, 0x13,
+ 0x08, 0x09, 0x0a, 0x15,
+ 0x0c, 0x0d, 0x0e, 0x17);
+ vector unsigned char vblue2 =
+ (vector unsigned char) (vec_add((vector unsigned int) vblue1, v8)
+ );
+ /*
+ 0x00 - 0x0f is ARxB ARxB ARxB ARxB
+ 0x10 - 0x0e evens are green
+ */
+ vector unsigned char vgreen1 = VECUINT8_LITERAL(0x00, 0x01, 0x10, 0x03,
+ 0x04, 0x05, 0x12, 0x07,
+ 0x08, 0x09, 0x14, 0x0b,
+ 0x0c, 0x0d, 0x16, 0x0f);
+ vector unsigned char vgreen2 =
+ (vector unsigned
+ char) (vec_add((vector unsigned int) vgreen1, vec_sl(v8, v8))
+ );
+
+ SDL_assert(srcfmt->BytesPerPixel == 2);
+ SDL_assert(dstfmt->BytesPerPixel == 4);
+
+ vf800 = (vector unsigned short) vec_splat_u8(-7);
+ vf800 = vec_sl(vf800, vec_splat_u16(8));
+
+ if (dstfmt->Amask && info->a) {
+ ((unsigned char *) &valpha)[0] = alpha = info->a;
+ valpha = vec_splat(valpha, 0);
+ } else {
+ alpha = 0;
+ valpha = vec_splat_u8(0);
+ }
+
+ vpermute = calc_swizzle32(NULL, dstfmt);
+ while (height--) {
+ vector unsigned char valigner;
+ vector unsigned char voverflow;
+ vector unsigned char vsrc;
+
+ int width = info->dst_w;
+ int extrawidth;
+
+ /* do scalar until we can align... */
+#define ONE_PIXEL_BLEND(condition, widthvar) \
+ while (condition) { \
+ unsigned sR, sG, sB; \
+ unsigned short Pixel = *((unsigned short *)src); \
+ sR = (Pixel >> 8) & 0xf8; \
+ sG = (Pixel >> 3) & 0xfc; \
+ sB = (Pixel << 3) & 0xf8; \
+ ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \
+ src += 2; \
+ dst += 4; \
+ widthvar--; \
+ }
+ ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
+
+ /* After all that work, here's the vector part! */
+ extrawidth = (width % 8); /* trailing unaligned stores */
+ width -= extrawidth;
+ vsrc = vec_ld(0, src);
+ valigner = VEC_ALIGNER(src);
+
+ while (width) {
+ vector unsigned short vR, vG, vB;
+ vector unsigned char vdst1, vdst2;
+
+ voverflow = vec_ld(15, src);
+ vsrc = vec_perm(vsrc, voverflow, valigner);
+
+ vR = vec_and((vector unsigned short) vsrc, vf800);
+ vB = vec_sl((vector unsigned short) vsrc, v3);
+ vG = vec_sl(vB, v2);
+
+ vdst1 =
+ (vector unsigned char) vec_perm((vector unsigned char) vR,
+ valpha, vredalpha1);
+ vdst1 = vec_perm(vdst1, (vector unsigned char) vB, vblue1);
+ vdst1 = vec_perm(vdst1, (vector unsigned char) vG, vgreen1);
+ vdst1 = vec_perm(vdst1, valpha, vpermute);
+ vec_st(vdst1, 0, dst);
+
+ vdst2 =
+ (vector unsigned char) vec_perm((vector unsigned char) vR,
+ valpha, vredalpha2);
+ vdst2 = vec_perm(vdst2, (vector unsigned char) vB, vblue2);
+ vdst2 = vec_perm(vdst2, (vector unsigned char) vG, vgreen2);
+ vdst2 = vec_perm(vdst2, valpha, vpermute);
+ vec_st(vdst2, 16, dst);
+
+ width -= 8;
+ dst += 32;
+ src += 16;
+ vsrc = voverflow;
+ }
+
+ SDL_assert(width == 0);
+
+
+ /* do scalar until we can align... */
+ ONE_PIXEL_BLEND((extrawidth), extrawidth);
+#undef ONE_PIXEL_BLEND
+
+ src += srcskip; /* move to next row, accounting for pitch. */
+ dst += dstskip;
+ }
+
+}
+
+
+static void
+Blit_RGB555_32Altivec(SDL_BlitInfo * info)
+{
+ int height = info->dst_h;
+ Uint8 *src = (Uint8 *) info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = (Uint8 *) info->dst;
+ int dstskip = info->dst_skip;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ unsigned alpha;
+ vector unsigned char valpha;
+ vector unsigned char vpermute;
+ vector unsigned short vf800;
+ vector unsigned int v8 = vec_splat_u32(8);
+ vector unsigned int v16 = vec_add(v8, v8);
+ vector unsigned short v1 = vec_splat_u16(1);
+ vector unsigned short v3 = vec_splat_u16(3);
+ /*
+ 0x10 - 0x1f is the alpha
+ 0x00 - 0x0e evens are the red
+ 0x01 - 0x0f odds are zero
+ */
+ vector unsigned char vredalpha1 = VECUINT8_LITERAL(0x10, 0x00, 0x01, 0x01,
+ 0x10, 0x02, 0x01, 0x01,
+ 0x10, 0x04, 0x01, 0x01,
+ 0x10, 0x06, 0x01,
+ 0x01);
+ vector unsigned char vredalpha2 =
+ (vector unsigned
+ char) (vec_add((vector unsigned int) vredalpha1, vec_sl(v8, v16))
+ );
+ /*
+ 0x00 - 0x0f is ARxx ARxx ARxx ARxx
+ 0x11 - 0x0f odds are blue
+ */
+ vector unsigned char vblue1 = VECUINT8_LITERAL(0x00, 0x01, 0x02, 0x11,
+ 0x04, 0x05, 0x06, 0x13,
+ 0x08, 0x09, 0x0a, 0x15,
+ 0x0c, 0x0d, 0x0e, 0x17);
+ vector unsigned char vblue2 =
+ (vector unsigned char) (vec_add((vector unsigned int) vblue1, v8)
+ );
+ /*
+ 0x00 - 0x0f is ARxB ARxB ARxB ARxB
+ 0x10 - 0x0e evens are green
+ */
+ vector unsigned char vgreen1 = VECUINT8_LITERAL(0x00, 0x01, 0x10, 0x03,
+ 0x04, 0x05, 0x12, 0x07,
+ 0x08, 0x09, 0x14, 0x0b,
+ 0x0c, 0x0d, 0x16, 0x0f);
+ vector unsigned char vgreen2 =
+ (vector unsigned
+ char) (vec_add((vector unsigned int) vgreen1, vec_sl(v8, v8))
+ );
+
+ SDL_assert(srcfmt->BytesPerPixel == 2);
+ SDL_assert(dstfmt->BytesPerPixel == 4);
+
+ vf800 = (vector unsigned short) vec_splat_u8(-7);
+ vf800 = vec_sl(vf800, vec_splat_u16(8));
+
+ if (dstfmt->Amask && info->a) {
+ ((unsigned char *) &valpha)[0] = alpha = info->a;
+ valpha = vec_splat(valpha, 0);
+ } else {
+ alpha = 0;
+ valpha = vec_splat_u8(0);
+ }
+
+ vpermute = calc_swizzle32(NULL, dstfmt);
+ while (height--) {
+ vector unsigned char valigner;
+ vector unsigned char voverflow;
+ vector unsigned char vsrc;
+
+ int width = info->dst_w;
+ int extrawidth;
+
+ /* do scalar until we can align... */
+#define ONE_PIXEL_BLEND(condition, widthvar) \
+ while (condition) { \
+ unsigned sR, sG, sB; \
+ unsigned short Pixel = *((unsigned short *)src); \
+ sR = (Pixel >> 7) & 0xf8; \
+ sG = (Pixel >> 2) & 0xf8; \
+ sB = (Pixel << 3) & 0xf8; \
+ ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \
+ src += 2; \
+ dst += 4; \
+ widthvar--; \
+ }
+ ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
+
+ /* After all that work, here's the vector part! */
+ extrawidth = (width % 8); /* trailing unaligned stores */
+ width -= extrawidth;
+ vsrc = vec_ld(0, src);
+ valigner = VEC_ALIGNER(src);
+
+ while (width) {
+ vector unsigned short vR, vG, vB;
+ vector unsigned char vdst1, vdst2;
+
+ voverflow = vec_ld(15, src);
+ vsrc = vec_perm(vsrc, voverflow, valigner);
+
+ vR = vec_and(vec_sl((vector unsigned short) vsrc, v1), vf800);
+ vB = vec_sl((vector unsigned short) vsrc, v3);
+ vG = vec_sl(vB, v3);
+
+ vdst1 =
+ (vector unsigned char) vec_perm((vector unsigned char) vR,
+ valpha, vredalpha1);
+ vdst1 = vec_perm(vdst1, (vector unsigned char) vB, vblue1);
+ vdst1 = vec_perm(vdst1, (vector unsigned char) vG, vgreen1);
+ vdst1 = vec_perm(vdst1, valpha, vpermute);
+ vec_st(vdst1, 0, dst);
+
+ vdst2 =
+ (vector unsigned char) vec_perm((vector unsigned char) vR,
+ valpha, vredalpha2);
+ vdst2 = vec_perm(vdst2, (vector unsigned char) vB, vblue2);
+ vdst2 = vec_perm(vdst2, (vector unsigned char) vG, vgreen2);
+ vdst2 = vec_perm(vdst2, valpha, vpermute);
+ vec_st(vdst2, 16, dst);
+
+ width -= 8;
+ dst += 32;
+ src += 16;
+ vsrc = voverflow;
+ }
+
+ SDL_assert(width == 0);
+
+
+ /* do scalar until we can align... */
+ ONE_PIXEL_BLEND((extrawidth), extrawidth);
+#undef ONE_PIXEL_BLEND
+
+ src += srcskip; /* move to next row, accounting for pitch. */
+ dst += dstskip;
+ }
+
+}
+
+static void BlitNtoNKey(SDL_BlitInfo * info);
+static void BlitNtoNKeyCopyAlpha(SDL_BlitInfo * info);
+static void
+Blit32to32KeyAltivec(SDL_BlitInfo * info)
+{
+ int height = info->dst_h;
+ Uint32 *srcp = (Uint32 *) info->src;
+ int srcskip = info->src_skip / 4;
+ Uint32 *dstp = (Uint32 *) info->dst;
+ int dstskip = info->dst_skip / 4;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ int srcbpp = srcfmt->BytesPerPixel;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ int dstbpp = dstfmt->BytesPerPixel;
+ int copy_alpha = (srcfmt->Amask && dstfmt->Amask);
+ unsigned alpha = dstfmt->Amask ? info->a : 0;
+ Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
+ Uint32 ckey = info->colorkey;
+ vector unsigned int valpha;
+ vector unsigned char vpermute;
+ vector unsigned char vzero;
+ vector unsigned int vckey;
+ vector unsigned int vrgbmask;
+ vpermute = calc_swizzle32(srcfmt, dstfmt);
+ if (info->dst_w < 16) {
+ if (copy_alpha) {
+ BlitNtoNKeyCopyAlpha(info);
+ } else {
+ BlitNtoNKey(info);
+ }
+ return;
+ }
+ vzero = vec_splat_u8(0);
+ if (alpha) {
+ ((unsigned char *) &valpha)[0] = (unsigned char) alpha;
+ valpha =
+ (vector unsigned int) vec_splat((vector unsigned char) valpha, 0);
+ } else {
+ valpha = (vector unsigned int) vzero;
+ }
+ ckey &= rgbmask;
+ ((unsigned int *) (char *) &vckey)[0] = ckey;
+ vckey = vec_splat(vckey, 0);
+ ((unsigned int *) (char *) &vrgbmask)[0] = rgbmask;
+ vrgbmask = vec_splat(vrgbmask, 0);
+
+ while (height--) {
+#define ONE_PIXEL_BLEND(condition, widthvar) \
+ if (copy_alpha) { \
+ while (condition) { \
+ Uint32 Pixel; \
+ unsigned sR, sG, sB, sA; \
+ DISEMBLE_RGBA((Uint8 *)srcp, srcbpp, srcfmt, Pixel, \
+ sR, sG, sB, sA); \
+ if ( (Pixel & rgbmask) != ckey ) { \
+ ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \
+ sR, sG, sB, sA); \
+ } \
+ dstp = (Uint32 *) (((Uint8 *) dstp) + dstbpp); \
+ srcp = (Uint32 *) (((Uint8 *) srcp) + srcbpp); \
+ widthvar--; \
+ } \
+ } else { \
+ while (condition) { \
+ Uint32 Pixel; \
+ unsigned sR, sG, sB; \
+ RETRIEVE_RGB_PIXEL((Uint8 *)srcp, srcbpp, Pixel); \
+ if ( Pixel != ckey ) { \
+ RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); \
+ ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \
+ sR, sG, sB, alpha); \
+ } \
+ dstp = (Uint32 *) (((Uint8 *)dstp) + dstbpp); \
+ srcp = (Uint32 *) (((Uint8 *)srcp) + srcbpp); \
+ widthvar--; \
+ } \
+ }
+ int width = info->dst_w;
+ ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
+ SDL_assert(width > 0);
+ if (width > 0) {
+ int extrawidth = (width % 4);
+ vector unsigned char valigner = VEC_ALIGNER(srcp);
+ vector unsigned int vs = vec_ld(0, srcp);
+ width -= extrawidth;
+ SDL_assert(width >= 4);
+ while (width) {
+ vector unsigned char vsel;
+ vector unsigned int vd;
+ vector unsigned int voverflow = vec_ld(15, srcp);
+ /* load the source vec */
+ vs = vec_perm(vs, voverflow, valigner);
+ /* vsel is set for items that match the key */
+ vsel = (vector unsigned char) vec_and(vs, vrgbmask);
+ vsel = (vector unsigned char) vec_cmpeq(vs, vckey);
+ /* permute the src vec to the dest format */
+ vs = vec_perm(vs, valpha, vpermute);
+ /* load the destination vec */
+ vd = vec_ld(0, dstp);
+ /* select the source and dest into vs */
+ vd = (vector unsigned int) vec_sel((vector unsigned char) vs,
+ (vector unsigned char) vd,
+ vsel);
+
+ vec_st(vd, 0, dstp);
+ srcp += 4;
+ width -= 4;
+ dstp += 4;
+ vs = voverflow;
+ }
+ ONE_PIXEL_BLEND((extrawidth), extrawidth);
+#undef ONE_PIXEL_BLEND
+ srcp += srcskip;
+ dstp += dstskip;
+ }
+ }
+}
+
+/* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */
+/* Use this on a G5 */
+static void
+ConvertAltivec32to32_noprefetch(SDL_BlitInfo * info)
+{
+ int height = info->dst_h;
+ Uint32 *src = (Uint32 *) info->src;
+ int srcskip = info->src_skip / 4;
+ Uint32 *dst = (Uint32 *) info->dst;
+ int dstskip = info->dst_skip / 4;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ vector unsigned int vzero = vec_splat_u32(0);
+ vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
+ if (dstfmt->Amask && !srcfmt->Amask) {
+ if (info->a) {
+ vector unsigned char valpha;
+ ((unsigned char *) &valpha)[0] = info->a;
+ vzero = (vector unsigned int) vec_splat(valpha, 0);
+ }
+ }
+
+ SDL_assert(srcfmt->BytesPerPixel == 4);
+ SDL_assert(dstfmt->BytesPerPixel == 4);
+
+ while (height--) {
+ vector unsigned char valigner;
+ vector unsigned int vbits;
+ vector unsigned int voverflow;
+ Uint32 bits;
+ Uint8 r, g, b, a;
+
+ int width = info->dst_w;
+ int extrawidth;
+
+ /* do scalar until we can align... */
+ while ((UNALIGNED_PTR(dst)) && (width)) {
+ bits = *(src++);
+ RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
+ if(!srcfmt->Amask)
+ a = info->a;
+ *(dst++) = MAKE8888(dstfmt, r, g, b, a);
+ width--;
+ }
+
+ /* After all that work, here's the vector part! */
+ extrawidth = (width % 4);
+ width -= extrawidth;
+ valigner = VEC_ALIGNER(src);
+ vbits = vec_ld(0, src);
+
+ while (width) {
+ voverflow = vec_ld(15, src);
+ src += 4;
+ width -= 4;
+ vbits = vec_perm(vbits, voverflow, valigner); /* src is ready. */
+ vbits = vec_perm(vbits, vzero, vpermute); /* swizzle it. */
+ vec_st(vbits, 0, dst); /* store it back out. */
+ dst += 4;
+ vbits = voverflow;
+ }
+
+ SDL_assert(width == 0);
+
+ /* cover pixels at the end of the row that didn't fit in 16 bytes. */
+ while (extrawidth) {
+ bits = *(src++); /* max 7 pixels, don't bother with prefetch. */
+ RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
+ if(!srcfmt->Amask)
+ a = info->a;
+ *(dst++) = MAKE8888(dstfmt, r, g, b, a);
+ extrawidth--;
+ }
+
+ src += srcskip;
+ dst += dstskip;
+ }
+
+}
+
+/* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */
+/* Use this on a G4 */
+static void
+ConvertAltivec32to32_prefetch(SDL_BlitInfo * info)
+{
+ const int scalar_dst_lead = sizeof(Uint32) * 4;
+ const int vector_dst_lead = sizeof(Uint32) * 16;
+
+ int height = info->dst_h;
+ Uint32 *src = (Uint32 *) info->src;
+ int srcskip = info->src_skip / 4;
+ Uint32 *dst = (Uint32 *) info->dst;
+ int dstskip = info->dst_skip / 4;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ vector unsigned int vzero = vec_splat_u32(0);
+ vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
+ if (dstfmt->Amask && !srcfmt->Amask) {
+ if (info->a) {
+ vector unsigned char valpha;
+ ((unsigned char *) &valpha)[0] = info->a;
+ vzero = (vector unsigned int) vec_splat(valpha, 0);
+ }
+ }
+
+ SDL_assert(srcfmt->BytesPerPixel == 4);
+ SDL_assert(dstfmt->BytesPerPixel == 4);
+
+ while (height--) {
+ vector unsigned char valigner;
+ vector unsigned int vbits;
+ vector unsigned int voverflow;
+ Uint32 bits;
+ Uint8 r, g, b, a;
+
+ int width = info->dst_w;
+ int extrawidth;
+
+ /* do scalar until we can align... */
+ while ((UNALIGNED_PTR(dst)) && (width)) {
+ vec_dstt(src + scalar_dst_lead, DST_CTRL(2, 32, 1024),
+ DST_CHAN_SRC);
+ vec_dstst(dst + scalar_dst_lead, DST_CTRL(2, 32, 1024),
+ DST_CHAN_DEST);
+ bits = *(src++);
+ RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
+ if(!srcfmt->Amask)
+ a = info->a;
+ *(dst++) = MAKE8888(dstfmt, r, g, b, a);
+ width--;
+ }
+
+ /* After all that work, here's the vector part! */
+ extrawidth = (width % 4);
+ width -= extrawidth;
+ valigner = VEC_ALIGNER(src);
+ vbits = vec_ld(0, src);
+
+ while (width) {
+ vec_dstt(src + vector_dst_lead, DST_CTRL(2, 32, 1024),
+ DST_CHAN_SRC);
+ vec_dstst(dst + vector_dst_lead, DST_CTRL(2, 32, 1024),
+ DST_CHAN_DEST);
+ voverflow = vec_ld(15, src);
+ src += 4;
+ width -= 4;
+ vbits = vec_perm(vbits, voverflow, valigner); /* src is ready. */
+ vbits = vec_perm(vbits, vzero, vpermute); /* swizzle it. */
+ vec_st(vbits, 0, dst); /* store it back out. */
+ dst += 4;
+ vbits = voverflow;
+ }
+
+ SDL_assert(width == 0);
+
+ /* cover pixels at the end of the row that didn't fit in 16 bytes. */
+ while (extrawidth) {
+ bits = *(src++); /* max 7 pixels, don't bother with prefetch. */
+ RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
+ if(!srcfmt->Amask)
+ a = info->a;
+ *(dst++) = MAKE8888(dstfmt, r, g, b, a);
+ extrawidth--;
+ }
+
+ src += srcskip;
+ dst += dstskip;
+ }
+
+ vec_dss(DST_CHAN_SRC);
+ vec_dss(DST_CHAN_DEST);
+}
+
+static Uint32
+GetBlitFeatures(void)
+{
+ static Uint32 features = 0xffffffff;
+ if (features == 0xffffffff) {
+ /* Provide an override for testing .. */
+ char *override = SDL_getenv("SDL_ALTIVEC_BLIT_FEATURES");
+ if (override) {
+ features = 0;
+ SDL_sscanf(override, "%u", &features);
+ } else {
+ features = (0
+ /* Feature 1 is has-MMX */
+ | ((SDL_HasMMX())? 1 : 0)
+ /* Feature 2 is has-AltiVec */
+ | ((SDL_HasAltiVec())? 2 : 0)
+ /* Feature 4 is dont-use-prefetch */
+ /* !!!! FIXME: Check for G5 or later, not the cache size! Always prefetch on a G4. */
+ | ((GetL3CacheSize() == 0) ? 4 : 0)
+ );
+ }
+ }
+ return features;
+}
+
+#if __MWERKS__
+#pragma altivec_model off
+#endif
+#else
+/* Feature 1 is has-MMX */
+#define GetBlitFeatures() ((Uint32)(SDL_HasMMX() ? 1 : 0))
+#endif
+
+/* This is now endian dependent */
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+#define HI 1
+#define LO 0
+#else /* SDL_BYTEORDER == SDL_BIG_ENDIAN */
+#define HI 0
+#define LO 1
+#endif
+
+/* Special optimized blit for RGB 8-8-8 --> RGB 3-3-2 */
+#define RGB888_RGB332(dst, src) { \
+ dst = (Uint8)((((src)&0x00E00000)>>16)| \
+ (((src)&0x0000E000)>>11)| \
+ (((src)&0x000000C0)>>6)); \
+}
+static void
+Blit_RGB888_index8(SDL_BlitInfo * info)
+{
+#ifndef USE_DUFFS_LOOP
+ int c;
+#endif
+ int width, height;
+ Uint32 *src;
+ const Uint8 *map;
+ Uint8 *dst;
+ int srcskip, dstskip;
+
+ /* Set up some basic variables */
+ width = info->dst_w;
+ height = info->dst_h;
+ src = (Uint32 *) info->src;
+ srcskip = info->src_skip / 4;
+ dst = info->dst;
+ dstskip = info->dst_skip;
+ map = info->table;
+
+ if (map == NULL) {
+ while (height--) {
+#ifdef USE_DUFFS_LOOP
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ RGB888_RGB332(*dst++, *src);
+ , width);
+ /* *INDENT-ON* */
+#else
+ for (c = width / 4; c; --c) {
+ /* Pack RGB into 8bit pixel */
+ ++src;
+ RGB888_RGB332(*dst++, *src);
+ ++src;
+ RGB888_RGB332(*dst++, *src);
+ ++src;
+ RGB888_RGB332(*dst++, *src);
+ ++src;
+ }
+ switch (width & 3) {
+ case 3:
+ RGB888_RGB332(*dst++, *src);
+ ++src;
+ case 2:
+ RGB888_RGB332(*dst++, *src);
+ ++src;
+ case 1:
+ RGB888_RGB332(*dst++, *src);
+ ++src;
+ }
+#endif /* USE_DUFFS_LOOP */
+ src += srcskip;
+ dst += dstskip;
+ }
+ } else {
+ int Pixel;
+
+ while (height--) {
+#ifdef USE_DUFFS_LOOP
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ RGB888_RGB332(Pixel, *src);
+ *dst++ = map[Pixel];
+ ++src;
+ , width);
+ /* *INDENT-ON* */
+#else
+ for (c = width / 4; c; --c) {
+ /* Pack RGB into 8bit pixel */
+ RGB888_RGB332(Pixel, *src);
+ *dst++ = map[Pixel];
+ ++src;
+ RGB888_RGB332(Pixel, *src);
+ *dst++ = map[Pixel];
+ ++src;
+ RGB888_RGB332(Pixel, *src);
+ *dst++ = map[Pixel];
+ ++src;
+ RGB888_RGB332(Pixel, *src);
+ *dst++ = map[Pixel];
+ ++src;
+ }
+ switch (width & 3) {
+ case 3:
+ RGB888_RGB332(Pixel, *src);
+ *dst++ = map[Pixel];
+ ++src;
+ case 2:
+ RGB888_RGB332(Pixel, *src);
+ *dst++ = map[Pixel];
+ ++src;
+ case 1:
+ RGB888_RGB332(Pixel, *src);
+ *dst++ = map[Pixel];
+ ++src;
+ }
+#endif /* USE_DUFFS_LOOP */
+ src += srcskip;
+ dst += dstskip;
+ }
+ }
+}
+
+/* Special optimized blit for RGB 10-10-10 --> RGB 3-3-2 */
+#define RGB101010_RGB332(dst, src) { \
+ dst = (Uint8)((((src)&0x38000000)>>22)| \
+ (((src)&0x000E0000)>>15)| \
+ (((src)&0x00000300)>>8)); \
+}
+static void
+Blit_RGB101010_index8(SDL_BlitInfo * info)
+{
+#ifndef USE_DUFFS_LOOP
+ int c;
+#endif
+ int width, height;
+ Uint32 *src;
+ const Uint8 *map;
+ Uint8 *dst;
+ int srcskip, dstskip;
+
+ /* Set up some basic variables */
+ width = info->dst_w;
+ height = info->dst_h;
+ src = (Uint32 *) info->src;
+ srcskip = info->src_skip / 4;
+ dst = info->dst;
+ dstskip = info->dst_skip;
+ map = info->table;
+
+ if (map == NULL) {
+ while (height--) {
+#ifdef USE_DUFFS_LOOP
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ RGB101010_RGB332(*dst++, *src);
+ , width);
+ /* *INDENT-ON* */
+#else
+ for (c = width / 4; c; --c) {
+ /* Pack RGB into 8bit pixel */
+ ++src;
+ RGB101010_RGB332(*dst++, *src);
+ ++src;
+ RGB101010_RGB332(*dst++, *src);
+ ++src;
+ RGB101010_RGB332(*dst++, *src);
+ ++src;
+ }
+ switch (width & 3) {
+ case 3:
+ RGB101010_RGB332(*dst++, *src);
+ ++src;
+ case 2:
+ RGB101010_RGB332(*dst++, *src);
+ ++src;
+ case 1:
+ RGB101010_RGB332(*dst++, *src);
+ ++src;
+ }
+#endif /* USE_DUFFS_LOOP */
+ src += srcskip;
+ dst += dstskip;
+ }
+ } else {
+ int Pixel;
+
+ while (height--) {
+#ifdef USE_DUFFS_LOOP
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ RGB101010_RGB332(Pixel, *src);
+ *dst++ = map[Pixel];
+ ++src;
+ , width);
+ /* *INDENT-ON* */
+#else
+ for (c = width / 4; c; --c) {
+ /* Pack RGB into 8bit pixel */
+ RGB101010_RGB332(Pixel, *src);
+ *dst++ = map[Pixel];
+ ++src;
+ RGB101010_RGB332(Pixel, *src);
+ *dst++ = map[Pixel];
+ ++src;
+ RGB101010_RGB332(Pixel, *src);
+ *dst++ = map[Pixel];
+ ++src;
+ RGB101010_RGB332(Pixel, *src);
+ *dst++ = map[Pixel];
+ ++src;
+ }
+ switch (width & 3) {
+ case 3:
+ RGB101010_RGB332(Pixel, *src);
+ *dst++ = map[Pixel];
+ ++src;
+ case 2:
+ RGB101010_RGB332(Pixel, *src);
+ *dst++ = map[Pixel];
+ ++src;
+ case 1:
+ RGB101010_RGB332(Pixel, *src);
+ *dst++ = map[Pixel];
+ ++src;
+ }
+#endif /* USE_DUFFS_LOOP */
+ src += srcskip;
+ dst += dstskip;
+ }
+ }
+}
+
+/* Special optimized blit for RGB 8-8-8 --> RGB 5-5-5 */
+#define RGB888_RGB555(dst, src) { \
+ *(Uint16 *)(dst) = (Uint16)((((*src)&0x00F80000)>>9)| \
+ (((*src)&0x0000F800)>>6)| \
+ (((*src)&0x000000F8)>>3)); \
+}
+#ifndef USE_DUFFS_LOOP
+#define RGB888_RGB555_TWO(dst, src) { \
+ *(Uint32 *)(dst) = (((((src[HI])&0x00F80000)>>9)| \
+ (((src[HI])&0x0000F800)>>6)| \
+ (((src[HI])&0x000000F8)>>3))<<16)| \
+ (((src[LO])&0x00F80000)>>9)| \
+ (((src[LO])&0x0000F800)>>6)| \
+ (((src[LO])&0x000000F8)>>3); \
+}
+#endif
+static void
+Blit_RGB888_RGB555(SDL_BlitInfo * info)
+{
+#ifndef USE_DUFFS_LOOP
+ int c;
+#endif
+ int width, height;
+ Uint32 *src;
+ Uint16 *dst;
+ int srcskip, dstskip;
+
+ /* Set up some basic variables */
+ width = info->dst_w;
+ height = info->dst_h;
+ src = (Uint32 *) info->src;
+ srcskip = info->src_skip / 4;
+ dst = (Uint16 *) info->dst;
+ dstskip = info->dst_skip / 2;
+
+#ifdef USE_DUFFS_LOOP
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ RGB888_RGB555(dst, src);
+ ++src;
+ ++dst;
+ , width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+#else
+ /* Memory align at 4-byte boundary, if necessary */
+ if ((long) dst & 0x03) {
+ /* Don't do anything if width is 0 */
+ if (width == 0) {
+ return;
+ }
+ --width;
+
+ while (height--) {
+ /* Perform copy alignment */
+ RGB888_RGB555(dst, src);
+ ++src;
+ ++dst;
+
+ /* Copy in 4 pixel chunks */
+ for (c = width / 4; c; --c) {
+ RGB888_RGB555_TWO(dst, src);
+ src += 2;
+ dst += 2;
+ RGB888_RGB555_TWO(dst, src);
+ src += 2;
+ dst += 2;
+ }
+ /* Get any leftovers */
+ switch (width & 3) {
+ case 3:
+ RGB888_RGB555(dst, src);
+ ++src;
+ ++dst;
+ case 2:
+ RGB888_RGB555_TWO(dst, src);
+ src += 2;
+ dst += 2;
+ break;
+ case 1:
+ RGB888_RGB555(dst, src);
+ ++src;
+ ++dst;
+ break;
+ }
+ src += srcskip;
+ dst += dstskip;
+ }
+ } else {
+ while (height--) {
+ /* Copy in 4 pixel chunks */
+ for (c = width / 4; c; --c) {
+ RGB888_RGB555_TWO(dst, src);
+ src += 2;
+ dst += 2;
+ RGB888_RGB555_TWO(dst, src);
+ src += 2;
+ dst += 2;
+ }
+ /* Get any leftovers */
+ switch (width & 3) {
+ case 3:
+ RGB888_RGB555(dst, src);
+ ++src;
+ ++dst;
+ case 2:
+ RGB888_RGB555_TWO(dst, src);
+ src += 2;
+ dst += 2;
+ break;
+ case 1:
+ RGB888_RGB555(dst, src);
+ ++src;
+ ++dst;
+ break;
+ }
+ src += srcskip;
+ dst += dstskip;
+ }
+ }
+#endif /* USE_DUFFS_LOOP */
+}
+
+/* Special optimized blit for RGB 8-8-8 --> RGB 5-6-5 */
+#define RGB888_RGB565(dst, src) { \
+ *(Uint16 *)(dst) = (Uint16)((((*src)&0x00F80000)>>8)| \
+ (((*src)&0x0000FC00)>>5)| \
+ (((*src)&0x000000F8)>>3)); \
+}
+#ifndef USE_DUFFS_LOOP
+#define RGB888_RGB565_TWO(dst, src) { \
+ *(Uint32 *)(dst) = (((((src[HI])&0x00F80000)>>8)| \
+ (((src[HI])&0x0000FC00)>>5)| \
+ (((src[HI])&0x000000F8)>>3))<<16)| \
+ (((src[LO])&0x00F80000)>>8)| \
+ (((src[LO])&0x0000FC00)>>5)| \
+ (((src[LO])&0x000000F8)>>3); \
+}
+#endif
+static void
+Blit_RGB888_RGB565(SDL_BlitInfo * info)
+{
+#ifndef USE_DUFFS_LOOP
+ int c;
+#endif
+ int width, height;
+ Uint32 *src;
+ Uint16 *dst;
+ int srcskip, dstskip;
+
+ /* Set up some basic variables */
+ width = info->dst_w;
+ height = info->dst_h;
+ src = (Uint32 *) info->src;
+ srcskip = info->src_skip / 4;
+ dst = (Uint16 *) info->dst;
+ dstskip = info->dst_skip / 2;
+
+#ifdef USE_DUFFS_LOOP
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ RGB888_RGB565(dst, src);
+ ++src;
+ ++dst;
+ , width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+#else
+ /* Memory align at 4-byte boundary, if necessary */
+ if ((long) dst & 0x03) {
+ /* Don't do anything if width is 0 */
+ if (width == 0) {
+ return;
+ }
+ --width;
+
+ while (height--) {
+ /* Perform copy alignment */
+ RGB888_RGB565(dst, src);
+ ++src;
+ ++dst;
+
+ /* Copy in 4 pixel chunks */
+ for (c = width / 4; c; --c) {
+ RGB888_RGB565_TWO(dst, src);
+ src += 2;
+ dst += 2;
+ RGB888_RGB565_TWO(dst, src);
+ src += 2;
+ dst += 2;
+ }
+ /* Get any leftovers */
+ switch (width & 3) {
+ case 3:
+ RGB888_RGB565(dst, src);
+ ++src;
+ ++dst;
+ case 2:
+ RGB888_RGB565_TWO(dst, src);
+ src += 2;
+ dst += 2;
+ break;
+ case 1:
+ RGB888_RGB565(dst, src);
+ ++src;
+ ++dst;
+ break;
+ }
+ src += srcskip;
+ dst += dstskip;
+ }
+ } else {
+ while (height--) {
+ /* Copy in 4 pixel chunks */
+ for (c = width / 4; c; --c) {
+ RGB888_RGB565_TWO(dst, src);
+ src += 2;
+ dst += 2;
+ RGB888_RGB565_TWO(dst, src);
+ src += 2;
+ dst += 2;
+ }
+ /* Get any leftovers */
+ switch (width & 3) {
+ case 3:
+ RGB888_RGB565(dst, src);
+ ++src;
+ ++dst;
+ case 2:
+ RGB888_RGB565_TWO(dst, src);
+ src += 2;
+ dst += 2;
+ break;
+ case 1:
+ RGB888_RGB565(dst, src);
+ ++src;
+ ++dst;
+ break;
+ }
+ src += srcskip;
+ dst += dstskip;
+ }
+ }
+#endif /* USE_DUFFS_LOOP */
+}
+
+
+/* Special optimized blit for RGB 5-6-5 --> 32-bit RGB surfaces */
+#define RGB565_32(dst, src, map) (map[src[LO]*2] + map[src[HI]*2+1])
+static void
+Blit_RGB565_32(SDL_BlitInfo * info, const Uint32 * map)
+{
+#ifndef USE_DUFFS_LOOP
+ int c;
+#endif
+ int width, height;
+ Uint8 *src;
+ Uint32 *dst;
+ int srcskip, dstskip;
+
+ /* Set up some basic variables */
+ width = info->dst_w;
+ height = info->dst_h;
+ src = (Uint8 *) info->src;
+ srcskip = info->src_skip;
+ dst = (Uint32 *) info->dst;
+ dstskip = info->dst_skip / 4;
+
+#ifdef USE_DUFFS_LOOP
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ *dst++ = RGB565_32(dst, src, map);
+ src += 2;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+#else
+ while (height--) {
+ /* Copy in 4 pixel chunks */
+ for (c = width / 4; c; --c) {
+ *dst++ = RGB565_32(dst, src, map);
+ src += 2;
+ *dst++ = RGB565_32(dst, src, map);
+ src += 2;
+ *dst++ = RGB565_32(dst, src, map);
+ src += 2;
+ *dst++ = RGB565_32(dst, src, map);
+ src += 2;
+ }
+ /* Get any leftovers */
+ switch (width & 3) {
+ case 3:
+ *dst++ = RGB565_32(dst, src, map);
+ src += 2;
+ case 2:
+ *dst++ = RGB565_32(dst, src, map);
+ src += 2;
+ case 1:
+ *dst++ = RGB565_32(dst, src, map);
+ src += 2;
+ break;
+ }
+ src += srcskip;
+ dst += dstskip;
+ }
+#endif /* USE_DUFFS_LOOP */
+}
+
+/* Special optimized blit for RGB 5-6-5 --> ARGB 8-8-8-8 */
+static const Uint32 RGB565_ARGB8888_LUT[512] = {
+ 0x00000000, 0xff000000, 0x00000008, 0xff002000,
+ 0x00000010, 0xff004000, 0x00000018, 0xff006100,
+ 0x00000020, 0xff008100, 0x00000029, 0xff00a100,
+ 0x00000031, 0xff00c200, 0x00000039, 0xff00e200,
+ 0x00000041, 0xff080000, 0x0000004a, 0xff082000,
+ 0x00000052, 0xff084000, 0x0000005a, 0xff086100,
+ 0x00000062, 0xff088100, 0x0000006a, 0xff08a100,
+ 0x00000073, 0xff08c200, 0x0000007b, 0xff08e200,
+ 0x00000083, 0xff100000, 0x0000008b, 0xff102000,
+ 0x00000094, 0xff104000, 0x0000009c, 0xff106100,
+ 0x000000a4, 0xff108100, 0x000000ac, 0xff10a100,
+ 0x000000b4, 0xff10c200, 0x000000bd, 0xff10e200,
+ 0x000000c5, 0xff180000, 0x000000cd, 0xff182000,
+ 0x000000d5, 0xff184000, 0x000000de, 0xff186100,
+ 0x000000e6, 0xff188100, 0x000000ee, 0xff18a100,
+ 0x000000f6, 0xff18c200, 0x000000ff, 0xff18e200,
+ 0x00000400, 0xff200000, 0x00000408, 0xff202000,
+ 0x00000410, 0xff204000, 0x00000418, 0xff206100,
+ 0x00000420, 0xff208100, 0x00000429, 0xff20a100,
+ 0x00000431, 0xff20c200, 0x00000439, 0xff20e200,
+ 0x00000441, 0xff290000, 0x0000044a, 0xff292000,
+ 0x00000452, 0xff294000, 0x0000045a, 0xff296100,
+ 0x00000462, 0xff298100, 0x0000046a, 0xff29a100,
+ 0x00000473, 0xff29c200, 0x0000047b, 0xff29e200,
+ 0x00000483, 0xff310000, 0x0000048b, 0xff312000,
+ 0x00000494, 0xff314000, 0x0000049c, 0xff316100,
+ 0x000004a4, 0xff318100, 0x000004ac, 0xff31a100,
+ 0x000004b4, 0xff31c200, 0x000004bd, 0xff31e200,
+ 0x000004c5, 0xff390000, 0x000004cd, 0xff392000,
+ 0x000004d5, 0xff394000, 0x000004de, 0xff396100,
+ 0x000004e6, 0xff398100, 0x000004ee, 0xff39a100,
+ 0x000004f6, 0xff39c200, 0x000004ff, 0xff39e200,
+ 0x00000800, 0xff410000, 0x00000808, 0xff412000,
+ 0x00000810, 0xff414000, 0x00000818, 0xff416100,
+ 0x00000820, 0xff418100, 0x00000829, 0xff41a100,
+ 0x00000831, 0xff41c200, 0x00000839, 0xff41e200,
+ 0x00000841, 0xff4a0000, 0x0000084a, 0xff4a2000,
+ 0x00000852, 0xff4a4000, 0x0000085a, 0xff4a6100,
+ 0x00000862, 0xff4a8100, 0x0000086a, 0xff4aa100,
+ 0x00000873, 0xff4ac200, 0x0000087b, 0xff4ae200,
+ 0x00000883, 0xff520000, 0x0000088b, 0xff522000,
+ 0x00000894, 0xff524000, 0x0000089c, 0xff526100,
+ 0x000008a4, 0xff528100, 0x000008ac, 0xff52a100,
+ 0x000008b4, 0xff52c200, 0x000008bd, 0xff52e200,
+ 0x000008c5, 0xff5a0000, 0x000008cd, 0xff5a2000,
+ 0x000008d5, 0xff5a4000, 0x000008de, 0xff5a6100,
+ 0x000008e6, 0xff5a8100, 0x000008ee, 0xff5aa100,
+ 0x000008f6, 0xff5ac200, 0x000008ff, 0xff5ae200,
+ 0x00000c00, 0xff620000, 0x00000c08, 0xff622000,
+ 0x00000c10, 0xff624000, 0x00000c18, 0xff626100,
+ 0x00000c20, 0xff628100, 0x00000c29, 0xff62a100,
+ 0x00000c31, 0xff62c200, 0x00000c39, 0xff62e200,
+ 0x00000c41, 0xff6a0000, 0x00000c4a, 0xff6a2000,
+ 0x00000c52, 0xff6a4000, 0x00000c5a, 0xff6a6100,
+ 0x00000c62, 0xff6a8100, 0x00000c6a, 0xff6aa100,
+ 0x00000c73, 0xff6ac200, 0x00000c7b, 0xff6ae200,
+ 0x00000c83, 0xff730000, 0x00000c8b, 0xff732000,
+ 0x00000c94, 0xff734000, 0x00000c9c, 0xff736100,
+ 0x00000ca4, 0xff738100, 0x00000cac, 0xff73a100,
+ 0x00000cb4, 0xff73c200, 0x00000cbd, 0xff73e200,
+ 0x00000cc5, 0xff7b0000, 0x00000ccd, 0xff7b2000,
+ 0x00000cd5, 0xff7b4000, 0x00000cde, 0xff7b6100,
+ 0x00000ce6, 0xff7b8100, 0x00000cee, 0xff7ba100,
+ 0x00000cf6, 0xff7bc200, 0x00000cff, 0xff7be200,
+ 0x00001000, 0xff830000, 0x00001008, 0xff832000,
+ 0x00001010, 0xff834000, 0x00001018, 0xff836100,
+ 0x00001020, 0xff838100, 0x00001029, 0xff83a100,
+ 0x00001031, 0xff83c200, 0x00001039, 0xff83e200,
+ 0x00001041, 0xff8b0000, 0x0000104a, 0xff8b2000,
+ 0x00001052, 0xff8b4000, 0x0000105a, 0xff8b6100,
+ 0x00001062, 0xff8b8100, 0x0000106a, 0xff8ba100,
+ 0x00001073, 0xff8bc200, 0x0000107b, 0xff8be200,
+ 0x00001083, 0xff940000, 0x0000108b, 0xff942000,
+ 0x00001094, 0xff944000, 0x0000109c, 0xff946100,
+ 0x000010a4, 0xff948100, 0x000010ac, 0xff94a100,
+ 0x000010b4, 0xff94c200, 0x000010bd, 0xff94e200,
+ 0x000010c5, 0xff9c0000, 0x000010cd, 0xff9c2000,
+ 0x000010d5, 0xff9c4000, 0x000010de, 0xff9c6100,
+ 0x000010e6, 0xff9c8100, 0x000010ee, 0xff9ca100,
+ 0x000010f6, 0xff9cc200, 0x000010ff, 0xff9ce200,
+ 0x00001400, 0xffa40000, 0x00001408, 0xffa42000,
+ 0x00001410, 0xffa44000, 0x00001418, 0xffa46100,
+ 0x00001420, 0xffa48100, 0x00001429, 0xffa4a100,
+ 0x00001431, 0xffa4c200, 0x00001439, 0xffa4e200,
+ 0x00001441, 0xffac0000, 0x0000144a, 0xffac2000,
+ 0x00001452, 0xffac4000, 0x0000145a, 0xffac6100,
+ 0x00001462, 0xffac8100, 0x0000146a, 0xffaca100,
+ 0x00001473, 0xffacc200, 0x0000147b, 0xfface200,
+ 0x00001483, 0xffb40000, 0x0000148b, 0xffb42000,
+ 0x00001494, 0xffb44000, 0x0000149c, 0xffb46100,
+ 0x000014a4, 0xffb48100, 0x000014ac, 0xffb4a100,
+ 0x000014b4, 0xffb4c200, 0x000014bd, 0xffb4e200,
+ 0x000014c5, 0xffbd0000, 0x000014cd, 0xffbd2000,
+ 0x000014d5, 0xffbd4000, 0x000014de, 0xffbd6100,
+ 0x000014e6, 0xffbd8100, 0x000014ee, 0xffbda100,
+ 0x000014f6, 0xffbdc200, 0x000014ff, 0xffbde200,
+ 0x00001800, 0xffc50000, 0x00001808, 0xffc52000,
+ 0x00001810, 0xffc54000, 0x00001818, 0xffc56100,
+ 0x00001820, 0xffc58100, 0x00001829, 0xffc5a100,
+ 0x00001831, 0xffc5c200, 0x00001839, 0xffc5e200,
+ 0x00001841, 0xffcd0000, 0x0000184a, 0xffcd2000,
+ 0x00001852, 0xffcd4000, 0x0000185a, 0xffcd6100,
+ 0x00001862, 0xffcd8100, 0x0000186a, 0xffcda100,
+ 0x00001873, 0xffcdc200, 0x0000187b, 0xffcde200,
+ 0x00001883, 0xffd50000, 0x0000188b, 0xffd52000,
+ 0x00001894, 0xffd54000, 0x0000189c, 0xffd56100,
+ 0x000018a4, 0xffd58100, 0x000018ac, 0xffd5a100,
+ 0x000018b4, 0xffd5c200, 0x000018bd, 0xffd5e200,
+ 0x000018c5, 0xffde0000, 0x000018cd, 0xffde2000,
+ 0x000018d5, 0xffde4000, 0x000018de, 0xffde6100,
+ 0x000018e6, 0xffde8100, 0x000018ee, 0xffdea100,
+ 0x000018f6, 0xffdec200, 0x000018ff, 0xffdee200,
+ 0x00001c00, 0xffe60000, 0x00001c08, 0xffe62000,
+ 0x00001c10, 0xffe64000, 0x00001c18, 0xffe66100,
+ 0x00001c20, 0xffe68100, 0x00001c29, 0xffe6a100,
+ 0x00001c31, 0xffe6c200, 0x00001c39, 0xffe6e200,
+ 0x00001c41, 0xffee0000, 0x00001c4a, 0xffee2000,
+ 0x00001c52, 0xffee4000, 0x00001c5a, 0xffee6100,
+ 0x00001c62, 0xffee8100, 0x00001c6a, 0xffeea100,
+ 0x00001c73, 0xffeec200, 0x00001c7b, 0xffeee200,
+ 0x00001c83, 0xfff60000, 0x00001c8b, 0xfff62000,
+ 0x00001c94, 0xfff64000, 0x00001c9c, 0xfff66100,
+ 0x00001ca4, 0xfff68100, 0x00001cac, 0xfff6a100,
+ 0x00001cb4, 0xfff6c200, 0x00001cbd, 0xfff6e200,
+ 0x00001cc5, 0xffff0000, 0x00001ccd, 0xffff2000,
+ 0x00001cd5, 0xffff4000, 0x00001cde, 0xffff6100,
+ 0x00001ce6, 0xffff8100, 0x00001cee, 0xffffa100,
+ 0x00001cf6, 0xffffc200, 0x00001cff, 0xffffe200
+};
+
+static void
+Blit_RGB565_ARGB8888(SDL_BlitInfo * info)
+{
+ Blit_RGB565_32(info, RGB565_ARGB8888_LUT);
+}
+
+/* Special optimized blit for RGB 5-6-5 --> ABGR 8-8-8-8 */
+static const Uint32 RGB565_ABGR8888_LUT[512] = {
+ 0xff000000, 0x00000000, 0xff080000, 0x00002000,
+ 0xff100000, 0x00004000, 0xff180000, 0x00006100,
+ 0xff200000, 0x00008100, 0xff290000, 0x0000a100,
+ 0xff310000, 0x0000c200, 0xff390000, 0x0000e200,
+ 0xff410000, 0x00000008, 0xff4a0000, 0x00002008,
+ 0xff520000, 0x00004008, 0xff5a0000, 0x00006108,
+ 0xff620000, 0x00008108, 0xff6a0000, 0x0000a108,
+ 0xff730000, 0x0000c208, 0xff7b0000, 0x0000e208,
+ 0xff830000, 0x00000010, 0xff8b0000, 0x00002010,
+ 0xff940000, 0x00004010, 0xff9c0000, 0x00006110,
+ 0xffa40000, 0x00008110, 0xffac0000, 0x0000a110,
+ 0xffb40000, 0x0000c210, 0xffbd0000, 0x0000e210,
+ 0xffc50000, 0x00000018, 0xffcd0000, 0x00002018,
+ 0xffd50000, 0x00004018, 0xffde0000, 0x00006118,
+ 0xffe60000, 0x00008118, 0xffee0000, 0x0000a118,
+ 0xfff60000, 0x0000c218, 0xffff0000, 0x0000e218,
+ 0xff000400, 0x00000020, 0xff080400, 0x00002020,
+ 0xff100400, 0x00004020, 0xff180400, 0x00006120,
+ 0xff200400, 0x00008120, 0xff290400, 0x0000a120,
+ 0xff310400, 0x0000c220, 0xff390400, 0x0000e220,
+ 0xff410400, 0x00000029, 0xff4a0400, 0x00002029,
+ 0xff520400, 0x00004029, 0xff5a0400, 0x00006129,
+ 0xff620400, 0x00008129, 0xff6a0400, 0x0000a129,
+ 0xff730400, 0x0000c229, 0xff7b0400, 0x0000e229,
+ 0xff830400, 0x00000031, 0xff8b0400, 0x00002031,
+ 0xff940400, 0x00004031, 0xff9c0400, 0x00006131,
+ 0xffa40400, 0x00008131, 0xffac0400, 0x0000a131,
+ 0xffb40400, 0x0000c231, 0xffbd0400, 0x0000e231,
+ 0xffc50400, 0x00000039, 0xffcd0400, 0x00002039,
+ 0xffd50400, 0x00004039, 0xffde0400, 0x00006139,
+ 0xffe60400, 0x00008139, 0xffee0400, 0x0000a139,
+ 0xfff60400, 0x0000c239, 0xffff0400, 0x0000e239,
+ 0xff000800, 0x00000041, 0xff080800, 0x00002041,
+ 0xff100800, 0x00004041, 0xff180800, 0x00006141,
+ 0xff200800, 0x00008141, 0xff290800, 0x0000a141,
+ 0xff310800, 0x0000c241, 0xff390800, 0x0000e241,
+ 0xff410800, 0x0000004a, 0xff4a0800, 0x0000204a,
+ 0xff520800, 0x0000404a, 0xff5a0800, 0x0000614a,
+ 0xff620800, 0x0000814a, 0xff6a0800, 0x0000a14a,
+ 0xff730800, 0x0000c24a, 0xff7b0800, 0x0000e24a,
+ 0xff830800, 0x00000052, 0xff8b0800, 0x00002052,
+ 0xff940800, 0x00004052, 0xff9c0800, 0x00006152,
+ 0xffa40800, 0x00008152, 0xffac0800, 0x0000a152,
+ 0xffb40800, 0x0000c252, 0xffbd0800, 0x0000e252,
+ 0xffc50800, 0x0000005a, 0xffcd0800, 0x0000205a,
+ 0xffd50800, 0x0000405a, 0xffde0800, 0x0000615a,
+ 0xffe60800, 0x0000815a, 0xffee0800, 0x0000a15a,
+ 0xfff60800, 0x0000c25a, 0xffff0800, 0x0000e25a,
+ 0xff000c00, 0x00000062, 0xff080c00, 0x00002062,
+ 0xff100c00, 0x00004062, 0xff180c00, 0x00006162,
+ 0xff200c00, 0x00008162, 0xff290c00, 0x0000a162,
+ 0xff310c00, 0x0000c262, 0xff390c00, 0x0000e262,
+ 0xff410c00, 0x0000006a, 0xff4a0c00, 0x0000206a,
+ 0xff520c00, 0x0000406a, 0xff5a0c00, 0x0000616a,
+ 0xff620c00, 0x0000816a, 0xff6a0c00, 0x0000a16a,
+ 0xff730c00, 0x0000c26a, 0xff7b0c00, 0x0000e26a,
+ 0xff830c00, 0x00000073, 0xff8b0c00, 0x00002073,
+ 0xff940c00, 0x00004073, 0xff9c0c00, 0x00006173,
+ 0xffa40c00, 0x00008173, 0xffac0c00, 0x0000a173,
+ 0xffb40c00, 0x0000c273, 0xffbd0c00, 0x0000e273,
+ 0xffc50c00, 0x0000007b, 0xffcd0c00, 0x0000207b,
+ 0xffd50c00, 0x0000407b, 0xffde0c00, 0x0000617b,
+ 0xffe60c00, 0x0000817b, 0xffee0c00, 0x0000a17b,
+ 0xfff60c00, 0x0000c27b, 0xffff0c00, 0x0000e27b,
+ 0xff001000, 0x00000083, 0xff081000, 0x00002083,
+ 0xff101000, 0x00004083, 0xff181000, 0x00006183,
+ 0xff201000, 0x00008183, 0xff291000, 0x0000a183,
+ 0xff311000, 0x0000c283, 0xff391000, 0x0000e283,
+ 0xff411000, 0x0000008b, 0xff4a1000, 0x0000208b,
+ 0xff521000, 0x0000408b, 0xff5a1000, 0x0000618b,
+ 0xff621000, 0x0000818b, 0xff6a1000, 0x0000a18b,
+ 0xff731000, 0x0000c28b, 0xff7b1000, 0x0000e28b,
+ 0xff831000, 0x00000094, 0xff8b1000, 0x00002094,
+ 0xff941000, 0x00004094, 0xff9c1000, 0x00006194,
+ 0xffa41000, 0x00008194, 0xffac1000, 0x0000a194,
+ 0xffb41000, 0x0000c294, 0xffbd1000, 0x0000e294,
+ 0xffc51000, 0x0000009c, 0xffcd1000, 0x0000209c,
+ 0xffd51000, 0x0000409c, 0xffde1000, 0x0000619c,
+ 0xffe61000, 0x0000819c, 0xffee1000, 0x0000a19c,
+ 0xfff61000, 0x0000c29c, 0xffff1000, 0x0000e29c,
+ 0xff001400, 0x000000a4, 0xff081400, 0x000020a4,
+ 0xff101400, 0x000040a4, 0xff181400, 0x000061a4,
+ 0xff201400, 0x000081a4, 0xff291400, 0x0000a1a4,
+ 0xff311400, 0x0000c2a4, 0xff391400, 0x0000e2a4,
+ 0xff411400, 0x000000ac, 0xff4a1400, 0x000020ac,
+ 0xff521400, 0x000040ac, 0xff5a1400, 0x000061ac,
+ 0xff621400, 0x000081ac, 0xff6a1400, 0x0000a1ac,
+ 0xff731400, 0x0000c2ac, 0xff7b1400, 0x0000e2ac,
+ 0xff831400, 0x000000b4, 0xff8b1400, 0x000020b4,
+ 0xff941400, 0x000040b4, 0xff9c1400, 0x000061b4,
+ 0xffa41400, 0x000081b4, 0xffac1400, 0x0000a1b4,
+ 0xffb41400, 0x0000c2b4, 0xffbd1400, 0x0000e2b4,
+ 0xffc51400, 0x000000bd, 0xffcd1400, 0x000020bd,
+ 0xffd51400, 0x000040bd, 0xffde1400, 0x000061bd,
+ 0xffe61400, 0x000081bd, 0xffee1400, 0x0000a1bd,
+ 0xfff61400, 0x0000c2bd, 0xffff1400, 0x0000e2bd,
+ 0xff001800, 0x000000c5, 0xff081800, 0x000020c5,
+ 0xff101800, 0x000040c5, 0xff181800, 0x000061c5,
+ 0xff201800, 0x000081c5, 0xff291800, 0x0000a1c5,
+ 0xff311800, 0x0000c2c5, 0xff391800, 0x0000e2c5,
+ 0xff411800, 0x000000cd, 0xff4a1800, 0x000020cd,
+ 0xff521800, 0x000040cd, 0xff5a1800, 0x000061cd,
+ 0xff621800, 0x000081cd, 0xff6a1800, 0x0000a1cd,
+ 0xff731800, 0x0000c2cd, 0xff7b1800, 0x0000e2cd,
+ 0xff831800, 0x000000d5, 0xff8b1800, 0x000020d5,
+ 0xff941800, 0x000040d5, 0xff9c1800, 0x000061d5,
+ 0xffa41800, 0x000081d5, 0xffac1800, 0x0000a1d5,
+ 0xffb41800, 0x0000c2d5, 0xffbd1800, 0x0000e2d5,
+ 0xffc51800, 0x000000de, 0xffcd1800, 0x000020de,
+ 0xffd51800, 0x000040de, 0xffde1800, 0x000061de,
+ 0xffe61800, 0x000081de, 0xffee1800, 0x0000a1de,
+ 0xfff61800, 0x0000c2de, 0xffff1800, 0x0000e2de,
+ 0xff001c00, 0x000000e6, 0xff081c00, 0x000020e6,
+ 0xff101c00, 0x000040e6, 0xff181c00, 0x000061e6,
+ 0xff201c00, 0x000081e6, 0xff291c00, 0x0000a1e6,
+ 0xff311c00, 0x0000c2e6, 0xff391c00, 0x0000e2e6,
+ 0xff411c00, 0x000000ee, 0xff4a1c00, 0x000020ee,
+ 0xff521c00, 0x000040ee, 0xff5a1c00, 0x000061ee,
+ 0xff621c00, 0x000081ee, 0xff6a1c00, 0x0000a1ee,
+ 0xff731c00, 0x0000c2ee, 0xff7b1c00, 0x0000e2ee,
+ 0xff831c00, 0x000000f6, 0xff8b1c00, 0x000020f6,
+ 0xff941c00, 0x000040f6, 0xff9c1c00, 0x000061f6,
+ 0xffa41c00, 0x000081f6, 0xffac1c00, 0x0000a1f6,
+ 0xffb41c00, 0x0000c2f6, 0xffbd1c00, 0x0000e2f6,
+ 0xffc51c00, 0x000000ff, 0xffcd1c00, 0x000020ff,
+ 0xffd51c00, 0x000040ff, 0xffde1c00, 0x000061ff,
+ 0xffe61c00, 0x000081ff, 0xffee1c00, 0x0000a1ff,
+ 0xfff61c00, 0x0000c2ff, 0xffff1c00, 0x0000e2ff
+};
+
+static void
+Blit_RGB565_ABGR8888(SDL_BlitInfo * info)
+{
+ Blit_RGB565_32(info, RGB565_ABGR8888_LUT);
+}
+
+/* Special optimized blit for RGB 5-6-5 --> RGBA 8-8-8-8 */
+static const Uint32 RGB565_RGBA8888_LUT[512] = {
+ 0x000000ff, 0x00000000, 0x000008ff, 0x00200000,
+ 0x000010ff, 0x00400000, 0x000018ff, 0x00610000,
+ 0x000020ff, 0x00810000, 0x000029ff, 0x00a10000,
+ 0x000031ff, 0x00c20000, 0x000039ff, 0x00e20000,
+ 0x000041ff, 0x08000000, 0x00004aff, 0x08200000,
+ 0x000052ff, 0x08400000, 0x00005aff, 0x08610000,
+ 0x000062ff, 0x08810000, 0x00006aff, 0x08a10000,
+ 0x000073ff, 0x08c20000, 0x00007bff, 0x08e20000,
+ 0x000083ff, 0x10000000, 0x00008bff, 0x10200000,
+ 0x000094ff, 0x10400000, 0x00009cff, 0x10610000,
+ 0x0000a4ff, 0x10810000, 0x0000acff, 0x10a10000,
+ 0x0000b4ff, 0x10c20000, 0x0000bdff, 0x10e20000,
+ 0x0000c5ff, 0x18000000, 0x0000cdff, 0x18200000,
+ 0x0000d5ff, 0x18400000, 0x0000deff, 0x18610000,
+ 0x0000e6ff, 0x18810000, 0x0000eeff, 0x18a10000,
+ 0x0000f6ff, 0x18c20000, 0x0000ffff, 0x18e20000,
+ 0x000400ff, 0x20000000, 0x000408ff, 0x20200000,
+ 0x000410ff, 0x20400000, 0x000418ff, 0x20610000,
+ 0x000420ff, 0x20810000, 0x000429ff, 0x20a10000,
+ 0x000431ff, 0x20c20000, 0x000439ff, 0x20e20000,
+ 0x000441ff, 0x29000000, 0x00044aff, 0x29200000,
+ 0x000452ff, 0x29400000, 0x00045aff, 0x29610000,
+ 0x000462ff, 0x29810000, 0x00046aff, 0x29a10000,
+ 0x000473ff, 0x29c20000, 0x00047bff, 0x29e20000,
+ 0x000483ff, 0x31000000, 0x00048bff, 0x31200000,
+ 0x000494ff, 0x31400000, 0x00049cff, 0x31610000,
+ 0x0004a4ff, 0x31810000, 0x0004acff, 0x31a10000,
+ 0x0004b4ff, 0x31c20000, 0x0004bdff, 0x31e20000,
+ 0x0004c5ff, 0x39000000, 0x0004cdff, 0x39200000,
+ 0x0004d5ff, 0x39400000, 0x0004deff, 0x39610000,
+ 0x0004e6ff, 0x39810000, 0x0004eeff, 0x39a10000,
+ 0x0004f6ff, 0x39c20000, 0x0004ffff, 0x39e20000,
+ 0x000800ff, 0x41000000, 0x000808ff, 0x41200000,
+ 0x000810ff, 0x41400000, 0x000818ff, 0x41610000,
+ 0x000820ff, 0x41810000, 0x000829ff, 0x41a10000,
+ 0x000831ff, 0x41c20000, 0x000839ff, 0x41e20000,
+ 0x000841ff, 0x4a000000, 0x00084aff, 0x4a200000,
+ 0x000852ff, 0x4a400000, 0x00085aff, 0x4a610000,
+ 0x000862ff, 0x4a810000, 0x00086aff, 0x4aa10000,
+ 0x000873ff, 0x4ac20000, 0x00087bff, 0x4ae20000,
+ 0x000883ff, 0x52000000, 0x00088bff, 0x52200000,
+ 0x000894ff, 0x52400000, 0x00089cff, 0x52610000,
+ 0x0008a4ff, 0x52810000, 0x0008acff, 0x52a10000,
+ 0x0008b4ff, 0x52c20000, 0x0008bdff, 0x52e20000,
+ 0x0008c5ff, 0x5a000000, 0x0008cdff, 0x5a200000,
+ 0x0008d5ff, 0x5a400000, 0x0008deff, 0x5a610000,
+ 0x0008e6ff, 0x5a810000, 0x0008eeff, 0x5aa10000,
+ 0x0008f6ff, 0x5ac20000, 0x0008ffff, 0x5ae20000,
+ 0x000c00ff, 0x62000000, 0x000c08ff, 0x62200000,
+ 0x000c10ff, 0x62400000, 0x000c18ff, 0x62610000,
+ 0x000c20ff, 0x62810000, 0x000c29ff, 0x62a10000,
+ 0x000c31ff, 0x62c20000, 0x000c39ff, 0x62e20000,
+ 0x000c41ff, 0x6a000000, 0x000c4aff, 0x6a200000,
+ 0x000c52ff, 0x6a400000, 0x000c5aff, 0x6a610000,
+ 0x000c62ff, 0x6a810000, 0x000c6aff, 0x6aa10000,
+ 0x000c73ff, 0x6ac20000, 0x000c7bff, 0x6ae20000,
+ 0x000c83ff, 0x73000000, 0x000c8bff, 0x73200000,
+ 0x000c94ff, 0x73400000, 0x000c9cff, 0x73610000,
+ 0x000ca4ff, 0x73810000, 0x000cacff, 0x73a10000,
+ 0x000cb4ff, 0x73c20000, 0x000cbdff, 0x73e20000,
+ 0x000cc5ff, 0x7b000000, 0x000ccdff, 0x7b200000,
+ 0x000cd5ff, 0x7b400000, 0x000cdeff, 0x7b610000,
+ 0x000ce6ff, 0x7b810000, 0x000ceeff, 0x7ba10000,
+ 0x000cf6ff, 0x7bc20000, 0x000cffff, 0x7be20000,
+ 0x001000ff, 0x83000000, 0x001008ff, 0x83200000,
+ 0x001010ff, 0x83400000, 0x001018ff, 0x83610000,
+ 0x001020ff, 0x83810000, 0x001029ff, 0x83a10000,
+ 0x001031ff, 0x83c20000, 0x001039ff, 0x83e20000,
+ 0x001041ff, 0x8b000000, 0x00104aff, 0x8b200000,
+ 0x001052ff, 0x8b400000, 0x00105aff, 0x8b610000,
+ 0x001062ff, 0x8b810000, 0x00106aff, 0x8ba10000,
+ 0x001073ff, 0x8bc20000, 0x00107bff, 0x8be20000,
+ 0x001083ff, 0x94000000, 0x00108bff, 0x94200000,
+ 0x001094ff, 0x94400000, 0x00109cff, 0x94610000,
+ 0x0010a4ff, 0x94810000, 0x0010acff, 0x94a10000,
+ 0x0010b4ff, 0x94c20000, 0x0010bdff, 0x94e20000,
+ 0x0010c5ff, 0x9c000000, 0x0010cdff, 0x9c200000,
+ 0x0010d5ff, 0x9c400000, 0x0010deff, 0x9c610000,
+ 0x0010e6ff, 0x9c810000, 0x0010eeff, 0x9ca10000,
+ 0x0010f6ff, 0x9cc20000, 0x0010ffff, 0x9ce20000,
+ 0x001400ff, 0xa4000000, 0x001408ff, 0xa4200000,
+ 0x001410ff, 0xa4400000, 0x001418ff, 0xa4610000,
+ 0x001420ff, 0xa4810000, 0x001429ff, 0xa4a10000,
+ 0x001431ff, 0xa4c20000, 0x001439ff, 0xa4e20000,
+ 0x001441ff, 0xac000000, 0x00144aff, 0xac200000,
+ 0x001452ff, 0xac400000, 0x00145aff, 0xac610000,
+ 0x001462ff, 0xac810000, 0x00146aff, 0xaca10000,
+ 0x001473ff, 0xacc20000, 0x00147bff, 0xace20000,
+ 0x001483ff, 0xb4000000, 0x00148bff, 0xb4200000,
+ 0x001494ff, 0xb4400000, 0x00149cff, 0xb4610000,
+ 0x0014a4ff, 0xb4810000, 0x0014acff, 0xb4a10000,
+ 0x0014b4ff, 0xb4c20000, 0x0014bdff, 0xb4e20000,
+ 0x0014c5ff, 0xbd000000, 0x0014cdff, 0xbd200000,
+ 0x0014d5ff, 0xbd400000, 0x0014deff, 0xbd610000,
+ 0x0014e6ff, 0xbd810000, 0x0014eeff, 0xbda10000,
+ 0x0014f6ff, 0xbdc20000, 0x0014ffff, 0xbde20000,
+ 0x001800ff, 0xc5000000, 0x001808ff, 0xc5200000,
+ 0x001810ff, 0xc5400000, 0x001818ff, 0xc5610000,
+ 0x001820ff, 0xc5810000, 0x001829ff, 0xc5a10000,
+ 0x001831ff, 0xc5c20000, 0x001839ff, 0xc5e20000,
+ 0x001841ff, 0xcd000000, 0x00184aff, 0xcd200000,
+ 0x001852ff, 0xcd400000, 0x00185aff, 0xcd610000,
+ 0x001862ff, 0xcd810000, 0x00186aff, 0xcda10000,
+ 0x001873ff, 0xcdc20000, 0x00187bff, 0xcde20000,
+ 0x001883ff, 0xd5000000, 0x00188bff, 0xd5200000,
+ 0x001894ff, 0xd5400000, 0x00189cff, 0xd5610000,
+ 0x0018a4ff, 0xd5810000, 0x0018acff, 0xd5a10000,
+ 0x0018b4ff, 0xd5c20000, 0x0018bdff, 0xd5e20000,
+ 0x0018c5ff, 0xde000000, 0x0018cdff, 0xde200000,
+ 0x0018d5ff, 0xde400000, 0x0018deff, 0xde610000,
+ 0x0018e6ff, 0xde810000, 0x0018eeff, 0xdea10000,
+ 0x0018f6ff, 0xdec20000, 0x0018ffff, 0xdee20000,
+ 0x001c00ff, 0xe6000000, 0x001c08ff, 0xe6200000,
+ 0x001c10ff, 0xe6400000, 0x001c18ff, 0xe6610000,
+ 0x001c20ff, 0xe6810000, 0x001c29ff, 0xe6a10000,
+ 0x001c31ff, 0xe6c20000, 0x001c39ff, 0xe6e20000,
+ 0x001c41ff, 0xee000000, 0x001c4aff, 0xee200000,
+ 0x001c52ff, 0xee400000, 0x001c5aff, 0xee610000,
+ 0x001c62ff, 0xee810000, 0x001c6aff, 0xeea10000,
+ 0x001c73ff, 0xeec20000, 0x001c7bff, 0xeee20000,
+ 0x001c83ff, 0xf6000000, 0x001c8bff, 0xf6200000,
+ 0x001c94ff, 0xf6400000, 0x001c9cff, 0xf6610000,
+ 0x001ca4ff, 0xf6810000, 0x001cacff, 0xf6a10000,
+ 0x001cb4ff, 0xf6c20000, 0x001cbdff, 0xf6e20000,
+ 0x001cc5ff, 0xff000000, 0x001ccdff, 0xff200000,
+ 0x001cd5ff, 0xff400000, 0x001cdeff, 0xff610000,
+ 0x001ce6ff, 0xff810000, 0x001ceeff, 0xffa10000,
+ 0x001cf6ff, 0xffc20000, 0x001cffff, 0xffe20000,
+};
+
+static void
+Blit_RGB565_RGBA8888(SDL_BlitInfo * info)
+{
+ Blit_RGB565_32(info, RGB565_RGBA8888_LUT);
+}
+
+/* Special optimized blit for RGB 5-6-5 --> BGRA 8-8-8-8 */
+static const Uint32 RGB565_BGRA8888_LUT[512] = {
+ 0x00000000, 0x000000ff, 0x08000000, 0x002000ff,
+ 0x10000000, 0x004000ff, 0x18000000, 0x006100ff,
+ 0x20000000, 0x008100ff, 0x29000000, 0x00a100ff,
+ 0x31000000, 0x00c200ff, 0x39000000, 0x00e200ff,
+ 0x41000000, 0x000008ff, 0x4a000000, 0x002008ff,
+ 0x52000000, 0x004008ff, 0x5a000000, 0x006108ff,
+ 0x62000000, 0x008108ff, 0x6a000000, 0x00a108ff,
+ 0x73000000, 0x00c208ff, 0x7b000000, 0x00e208ff,
+ 0x83000000, 0x000010ff, 0x8b000000, 0x002010ff,
+ 0x94000000, 0x004010ff, 0x9c000000, 0x006110ff,
+ 0xa4000000, 0x008110ff, 0xac000000, 0x00a110ff,
+ 0xb4000000, 0x00c210ff, 0xbd000000, 0x00e210ff,
+ 0xc5000000, 0x000018ff, 0xcd000000, 0x002018ff,
+ 0xd5000000, 0x004018ff, 0xde000000, 0x006118ff,
+ 0xe6000000, 0x008118ff, 0xee000000, 0x00a118ff,
+ 0xf6000000, 0x00c218ff, 0xff000000, 0x00e218ff,
+ 0x00040000, 0x000020ff, 0x08040000, 0x002020ff,
+ 0x10040000, 0x004020ff, 0x18040000, 0x006120ff,
+ 0x20040000, 0x008120ff, 0x29040000, 0x00a120ff,
+ 0x31040000, 0x00c220ff, 0x39040000, 0x00e220ff,
+ 0x41040000, 0x000029ff, 0x4a040000, 0x002029ff,
+ 0x52040000, 0x004029ff, 0x5a040000, 0x006129ff,
+ 0x62040000, 0x008129ff, 0x6a040000, 0x00a129ff,
+ 0x73040000, 0x00c229ff, 0x7b040000, 0x00e229ff,
+ 0x83040000, 0x000031ff, 0x8b040000, 0x002031ff,
+ 0x94040000, 0x004031ff, 0x9c040000, 0x006131ff,
+ 0xa4040000, 0x008131ff, 0xac040000, 0x00a131ff,
+ 0xb4040000, 0x00c231ff, 0xbd040000, 0x00e231ff,
+ 0xc5040000, 0x000039ff, 0xcd040000, 0x002039ff,
+ 0xd5040000, 0x004039ff, 0xde040000, 0x006139ff,
+ 0xe6040000, 0x008139ff, 0xee040000, 0x00a139ff,
+ 0xf6040000, 0x00c239ff, 0xff040000, 0x00e239ff,
+ 0x00080000, 0x000041ff, 0x08080000, 0x002041ff,
+ 0x10080000, 0x004041ff, 0x18080000, 0x006141ff,
+ 0x20080000, 0x008141ff, 0x29080000, 0x00a141ff,
+ 0x31080000, 0x00c241ff, 0x39080000, 0x00e241ff,
+ 0x41080000, 0x00004aff, 0x4a080000, 0x00204aff,
+ 0x52080000, 0x00404aff, 0x5a080000, 0x00614aff,
+ 0x62080000, 0x00814aff, 0x6a080000, 0x00a14aff,
+ 0x73080000, 0x00c24aff, 0x7b080000, 0x00e24aff,
+ 0x83080000, 0x000052ff, 0x8b080000, 0x002052ff,
+ 0x94080000, 0x004052ff, 0x9c080000, 0x006152ff,
+ 0xa4080000, 0x008152ff, 0xac080000, 0x00a152ff,
+ 0xb4080000, 0x00c252ff, 0xbd080000, 0x00e252ff,
+ 0xc5080000, 0x00005aff, 0xcd080000, 0x00205aff,
+ 0xd5080000, 0x00405aff, 0xde080000, 0x00615aff,
+ 0xe6080000, 0x00815aff, 0xee080000, 0x00a15aff,
+ 0xf6080000, 0x00c25aff, 0xff080000, 0x00e25aff,
+ 0x000c0000, 0x000062ff, 0x080c0000, 0x002062ff,
+ 0x100c0000, 0x004062ff, 0x180c0000, 0x006162ff,
+ 0x200c0000, 0x008162ff, 0x290c0000, 0x00a162ff,
+ 0x310c0000, 0x00c262ff, 0x390c0000, 0x00e262ff,
+ 0x410c0000, 0x00006aff, 0x4a0c0000, 0x00206aff,
+ 0x520c0000, 0x00406aff, 0x5a0c0000, 0x00616aff,
+ 0x620c0000, 0x00816aff, 0x6a0c0000, 0x00a16aff,
+ 0x730c0000, 0x00c26aff, 0x7b0c0000, 0x00e26aff,
+ 0x830c0000, 0x000073ff, 0x8b0c0000, 0x002073ff,
+ 0x940c0000, 0x004073ff, 0x9c0c0000, 0x006173ff,
+ 0xa40c0000, 0x008173ff, 0xac0c0000, 0x00a173ff,
+ 0xb40c0000, 0x00c273ff, 0xbd0c0000, 0x00e273ff,
+ 0xc50c0000, 0x00007bff, 0xcd0c0000, 0x00207bff,
+ 0xd50c0000, 0x00407bff, 0xde0c0000, 0x00617bff,
+ 0xe60c0000, 0x00817bff, 0xee0c0000, 0x00a17bff,
+ 0xf60c0000, 0x00c27bff, 0xff0c0000, 0x00e27bff,
+ 0x00100000, 0x000083ff, 0x08100000, 0x002083ff,
+ 0x10100000, 0x004083ff, 0x18100000, 0x006183ff,
+ 0x20100000, 0x008183ff, 0x29100000, 0x00a183ff,
+ 0x31100000, 0x00c283ff, 0x39100000, 0x00e283ff,
+ 0x41100000, 0x00008bff, 0x4a100000, 0x00208bff,
+ 0x52100000, 0x00408bff, 0x5a100000, 0x00618bff,
+ 0x62100000, 0x00818bff, 0x6a100000, 0x00a18bff,
+ 0x73100000, 0x00c28bff, 0x7b100000, 0x00e28bff,
+ 0x83100000, 0x000094ff, 0x8b100000, 0x002094ff,
+ 0x94100000, 0x004094ff, 0x9c100000, 0x006194ff,
+ 0xa4100000, 0x008194ff, 0xac100000, 0x00a194ff,
+ 0xb4100000, 0x00c294ff, 0xbd100000, 0x00e294ff,
+ 0xc5100000, 0x00009cff, 0xcd100000, 0x00209cff,
+ 0xd5100000, 0x00409cff, 0xde100000, 0x00619cff,
+ 0xe6100000, 0x00819cff, 0xee100000, 0x00a19cff,
+ 0xf6100000, 0x00c29cff, 0xff100000, 0x00e29cff,
+ 0x00140000, 0x0000a4ff, 0x08140000, 0x0020a4ff,
+ 0x10140000, 0x0040a4ff, 0x18140000, 0x0061a4ff,
+ 0x20140000, 0x0081a4ff, 0x29140000, 0x00a1a4ff,
+ 0x31140000, 0x00c2a4ff, 0x39140000, 0x00e2a4ff,
+ 0x41140000, 0x0000acff, 0x4a140000, 0x0020acff,
+ 0x52140000, 0x0040acff, 0x5a140000, 0x0061acff,
+ 0x62140000, 0x0081acff, 0x6a140000, 0x00a1acff,
+ 0x73140000, 0x00c2acff, 0x7b140000, 0x00e2acff,
+ 0x83140000, 0x0000b4ff, 0x8b140000, 0x0020b4ff,
+ 0x94140000, 0x0040b4ff, 0x9c140000, 0x0061b4ff,
+ 0xa4140000, 0x0081b4ff, 0xac140000, 0x00a1b4ff,
+ 0xb4140000, 0x00c2b4ff, 0xbd140000, 0x00e2b4ff,
+ 0xc5140000, 0x0000bdff, 0xcd140000, 0x0020bdff,
+ 0xd5140000, 0x0040bdff, 0xde140000, 0x0061bdff,
+ 0xe6140000, 0x0081bdff, 0xee140000, 0x00a1bdff,
+ 0xf6140000, 0x00c2bdff, 0xff140000, 0x00e2bdff,
+ 0x00180000, 0x0000c5ff, 0x08180000, 0x0020c5ff,
+ 0x10180000, 0x0040c5ff, 0x18180000, 0x0061c5ff,
+ 0x20180000, 0x0081c5ff, 0x29180000, 0x00a1c5ff,
+ 0x31180000, 0x00c2c5ff, 0x39180000, 0x00e2c5ff,
+ 0x41180000, 0x0000cdff, 0x4a180000, 0x0020cdff,
+ 0x52180000, 0x0040cdff, 0x5a180000, 0x0061cdff,
+ 0x62180000, 0x0081cdff, 0x6a180000, 0x00a1cdff,
+ 0x73180000, 0x00c2cdff, 0x7b180000, 0x00e2cdff,
+ 0x83180000, 0x0000d5ff, 0x8b180000, 0x0020d5ff,
+ 0x94180000, 0x0040d5ff, 0x9c180000, 0x0061d5ff,
+ 0xa4180000, 0x0081d5ff, 0xac180000, 0x00a1d5ff,
+ 0xb4180000, 0x00c2d5ff, 0xbd180000, 0x00e2d5ff,
+ 0xc5180000, 0x0000deff, 0xcd180000, 0x0020deff,
+ 0xd5180000, 0x0040deff, 0xde180000, 0x0061deff,
+ 0xe6180000, 0x0081deff, 0xee180000, 0x00a1deff,
+ 0xf6180000, 0x00c2deff, 0xff180000, 0x00e2deff,
+ 0x001c0000, 0x0000e6ff, 0x081c0000, 0x0020e6ff,
+ 0x101c0000, 0x0040e6ff, 0x181c0000, 0x0061e6ff,
+ 0x201c0000, 0x0081e6ff, 0x291c0000, 0x00a1e6ff,
+ 0x311c0000, 0x00c2e6ff, 0x391c0000, 0x00e2e6ff,
+ 0x411c0000, 0x0000eeff, 0x4a1c0000, 0x0020eeff,
+ 0x521c0000, 0x0040eeff, 0x5a1c0000, 0x0061eeff,
+ 0x621c0000, 0x0081eeff, 0x6a1c0000, 0x00a1eeff,
+ 0x731c0000, 0x00c2eeff, 0x7b1c0000, 0x00e2eeff,
+ 0x831c0000, 0x0000f6ff, 0x8b1c0000, 0x0020f6ff,
+ 0x941c0000, 0x0040f6ff, 0x9c1c0000, 0x0061f6ff,
+ 0xa41c0000, 0x0081f6ff, 0xac1c0000, 0x00a1f6ff,
+ 0xb41c0000, 0x00c2f6ff, 0xbd1c0000, 0x00e2f6ff,
+ 0xc51c0000, 0x0000ffff, 0xcd1c0000, 0x0020ffff,
+ 0xd51c0000, 0x0040ffff, 0xde1c0000, 0x0061ffff,
+ 0xe61c0000, 0x0081ffff, 0xee1c0000, 0x00a1ffff,
+ 0xf61c0000, 0x00c2ffff, 0xff1c0000, 0x00e2ffff
+};
+
+static void
+Blit_RGB565_BGRA8888(SDL_BlitInfo * info)
+{
+ Blit_RGB565_32(info, RGB565_BGRA8888_LUT);
+}
+
+static void
+BlitNto1(SDL_BlitInfo * info)
+{
+#ifndef USE_DUFFS_LOOP
+ int c;
+#endif
+ int width, height;
+ Uint8 *src;
+ const Uint8 *map;
+ Uint8 *dst;
+ int srcskip, dstskip;
+ int srcbpp;
+ Uint32 Pixel;
+ int sR, sG, sB;
+ SDL_PixelFormat *srcfmt;
+
+ /* Set up some basic variables */
+ width = info->dst_w;
+ height = info->dst_h;
+ src = info->src;
+ srcskip = info->src_skip;
+ dst = info->dst;
+ dstskip = info->dst_skip;
+ map = info->table;
+ srcfmt = info->src_fmt;
+ srcbpp = srcfmt->BytesPerPixel;
+
+ if (map == NULL) {
+ while (height--) {
+#ifdef USE_DUFFS_LOOP
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel,
+ sR, sG, sB);
+ if ( 1 ) {
+ /* Pack RGB into 8bit pixel */
+ *dst = ((sR>>5)<<(3+2))|
+ ((sG>>5)<<(2)) |
+ ((sB>>6)<<(0)) ;
+ }
+ dst++;
+ src += srcbpp;
+ , width);
+ /* *INDENT-ON* */
+#else
+ for (c = width; c; --c) {
+ DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
+ if (1) {
+ /* Pack RGB into 8bit pixel */
+ *dst = ((sR >> 5) << (3 + 2)) |
+ ((sG >> 5) << (2)) | ((sB >> 6) << (0));
+ }
+ dst++;
+ src += srcbpp;
+ }
+#endif
+ src += srcskip;
+ dst += dstskip;
+ }
+ } else {
+ while (height--) {
+#ifdef USE_DUFFS_LOOP
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel,
+ sR, sG, sB);
+ if ( 1 ) {
+ /* Pack RGB into 8bit pixel */
+ *dst = map[((sR>>5)<<(3+2))|
+ ((sG>>5)<<(2)) |
+ ((sB>>6)<<(0)) ];
+ }
+ dst++;
+ src += srcbpp;
+ , width);
+ /* *INDENT-ON* */
+#else
+ for (c = width; c; --c) {
+ DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
+ if (1) {
+ /* Pack RGB into 8bit pixel */
+ *dst = map[((sR >> 5) << (3 + 2)) |
+ ((sG >> 5) << (2)) | ((sB >> 6) << (0))];
+ }
+ dst++;
+ src += srcbpp;
+ }
+#endif /* USE_DUFFS_LOOP */
+ src += srcskip;
+ dst += dstskip;
+ }
+ }
+}
+
+/* blits 32 bit RGB<->RGBA with both surfaces having the same R,G,B fields */
+static void
+Blit4to4MaskAlpha(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint32 *src = (Uint32 *) info->src;
+ int srcskip = info->src_skip;
+ Uint32 *dst = (Uint32 *) info->dst;
+ int dstskip = info->dst_skip;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+
+ if (dstfmt->Amask) {
+ /* RGB->RGBA, SET_ALPHA */
+ Uint32 mask = (info->a >> dstfmt->Aloss) << dstfmt->Ashift;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ *dst = *src | mask;
+ ++dst;
+ ++src;
+ },
+ width);
+ /* *INDENT-ON* */
+ src = (Uint32 *) ((Uint8 *) src + srcskip);
+ dst = (Uint32 *) ((Uint8 *) dst + dstskip);
+ }
+ } else {
+ /* RGBA->RGB, NO_ALPHA */
+ Uint32 mask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ *dst = *src & mask;
+ ++dst;
+ ++src;
+ },
+ width);
+ /* *INDENT-ON* */
+ src = (Uint32 *) ((Uint8 *) src + srcskip);
+ dst = (Uint32 *) ((Uint8 *) dst + dstskip);
+ }
+ }
+}
+
+/* blits 32 bit RGBA<->RGBA with both surfaces having the same R,G,B,A fields */
+static void
+Blit4to4CopyAlpha(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint32 *src = (Uint32 *) info->src;
+ int srcskip = info->src_skip;
+ Uint32 *dst = (Uint32 *) info->dst;
+ int dstskip = info->dst_skip;
+
+ /* RGBA->RGBA, COPY_ALPHA */
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ *dst = *src;
+ ++dst;
+ ++src;
+ },
+ width);
+ /* *INDENT-ON* */
+ src = (Uint32 *) ((Uint8 *) src + srcskip);
+ dst = (Uint32 *) ((Uint8 *) dst + dstskip);
+ }
+}
+
+static void
+BlitNtoN(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = info->dst;
+ int dstskip = info->dst_skip;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ int srcbpp = srcfmt->BytesPerPixel;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ int dstbpp = dstfmt->BytesPerPixel;
+ unsigned alpha = dstfmt->Amask ? info->a : 0;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ Uint32 Pixel;
+ unsigned sR;
+ unsigned sG;
+ unsigned sB;
+ DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
+ ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, alpha);
+ dst += dstbpp;
+ src += srcbpp;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+static void
+BlitNtoNCopyAlpha(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = info->dst;
+ int dstskip = info->dst_skip;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ int srcbpp = srcfmt->BytesPerPixel;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ int dstbpp = dstfmt->BytesPerPixel;
+ int c;
+
+ while (height--) {
+ for (c = width; c; --c) {
+ Uint32 Pixel;
+ unsigned sR, sG, sB, sA;
+ DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA);
+ ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, sA);
+ dst += dstbpp;
+ src += srcbpp;
+ }
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+static void
+BlitNto1Key(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = info->dst;
+ int dstskip = info->dst_skip;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ const Uint8 *palmap = info->table;
+ Uint32 ckey = info->colorkey;
+ Uint32 rgbmask = ~srcfmt->Amask;
+ int srcbpp;
+ Uint32 Pixel;
+ unsigned sR, sG, sB;
+
+ /* Set up some basic variables */
+ srcbpp = srcfmt->BytesPerPixel;
+ ckey &= rgbmask;
+
+ if (palmap == NULL) {
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel,
+ sR, sG, sB);
+ if ( (Pixel & rgbmask) != ckey ) {
+ /* Pack RGB into 8bit pixel */
+ *dst = (Uint8)(((sR>>5)<<(3+2))|
+ ((sG>>5)<<(2)) |
+ ((sB>>6)<<(0)));
+ }
+ dst++;
+ src += srcbpp;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+ } else {
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel,
+ sR, sG, sB);
+ if ( (Pixel & rgbmask) != ckey ) {
+ /* Pack RGB into 8bit pixel */
+ *dst = (Uint8)palmap[((sR>>5)<<(3+2))|
+ ((sG>>5)<<(2)) |
+ ((sB>>6)<<(0)) ];
+ }
+ dst++;
+ src += srcbpp;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+ }
+}
+
+static void
+Blit2to2Key(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint16 *srcp = (Uint16 *) info->src;
+ int srcskip = info->src_skip;
+ Uint16 *dstp = (Uint16 *) info->dst;
+ int dstskip = info->dst_skip;
+ Uint32 ckey = info->colorkey;
+ Uint32 rgbmask = ~info->src_fmt->Amask;
+
+ /* Set up some basic variables */
+ srcskip /= 2;
+ dstskip /= 2;
+ ckey &= rgbmask;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ if ( (*srcp & rgbmask) != ckey ) {
+ *dstp = *srcp;
+ }
+ dstp++;
+ srcp++;
+ },
+ width);
+ /* *INDENT-ON* */
+ srcp += srcskip;
+ dstp += dstskip;
+ }
+}
+
+static void
+BlitNtoNKey(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = info->dst;
+ int dstskip = info->dst_skip;
+ Uint32 ckey = info->colorkey;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ int srcbpp = srcfmt->BytesPerPixel;
+ int dstbpp = dstfmt->BytesPerPixel;
+ unsigned alpha = dstfmt->Amask ? info->a : 0;
+ Uint32 rgbmask = ~srcfmt->Amask;
+
+ /* Set up some basic variables */
+ ckey &= rgbmask;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ Uint32 Pixel;
+ unsigned sR;
+ unsigned sG;
+ unsigned sB;
+ RETRIEVE_RGB_PIXEL(src, srcbpp, Pixel);
+ if ( (Pixel & rgbmask) != ckey ) {
+ RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB);
+ ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, alpha);
+ }
+ dst += dstbpp;
+ src += srcbpp;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+static void
+BlitNtoNKeyCopyAlpha(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = info->dst;
+ int dstskip = info->dst_skip;
+ Uint32 ckey = info->colorkey;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ Uint32 rgbmask = ~srcfmt->Amask;
+
+ Uint8 srcbpp;
+ Uint8 dstbpp;
+ Uint32 Pixel;
+ unsigned sR, sG, sB, sA;
+
+ /* Set up some basic variables */
+ srcbpp = srcfmt->BytesPerPixel;
+ dstbpp = dstfmt->BytesPerPixel;
+ ckey &= rgbmask;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA);
+ if ( (Pixel & rgbmask) != ckey ) {
+ ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, sA);
+ }
+ dst += dstbpp;
+ src += srcbpp;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+/* Special optimized blit for ARGB 2-10-10-10 --> RGBA */
+static void
+Blit2101010toN(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = info->dst;
+ int dstskip = info->dst_skip;
+ SDL_PixelFormat *dstfmt = info->dst_fmt;
+ int dstbpp = dstfmt->BytesPerPixel;
+ Uint32 Pixel;
+ unsigned sR, sG, sB, sA;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ Pixel = *(Uint32 *)src;
+ RGBA_FROM_ARGB2101010(Pixel, sR, sG, sB, sA);
+ ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, sA);
+ dst += dstbpp;
+ src += 4;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+/* Special optimized blit for RGBA --> ARGB 2-10-10-10 */
+static void
+BlitNto2101010(SDL_BlitInfo * info)
+{
+ int width = info->dst_w;
+ int height = info->dst_h;
+ Uint8 *src = info->src;
+ int srcskip = info->src_skip;
+ Uint8 *dst = info->dst;
+ int dstskip = info->dst_skip;
+ SDL_PixelFormat *srcfmt = info->src_fmt;
+ int srcbpp = srcfmt->BytesPerPixel;
+ Uint32 Pixel;
+ unsigned sR, sG, sB, sA;
+
+ while (height--) {
+ /* *INDENT-OFF* */
+ DUFFS_LOOP(
+ {
+ DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA);
+ ARGB2101010_FROM_RGBA(Pixel, sR, sG, sB, sA);
+ *(Uint32 *)dst = Pixel;
+ dst += 4;
+ src += srcbpp;
+ },
+ width);
+ /* *INDENT-ON* */
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+/* Normal N to N optimized blitters */
+#define NO_ALPHA 1
+#define SET_ALPHA 2
+#define COPY_ALPHA 4
+struct blit_table
+{
+ Uint32 srcR, srcG, srcB;
+ int dstbpp;
+ Uint32 dstR, dstG, dstB;
+ Uint32 blit_features;
+ SDL_BlitFunc blitfunc;
+ Uint32 alpha; /* bitwise NO_ALPHA, SET_ALPHA, COPY_ALPHA */
+};
+static const struct blit_table normal_blit_1[] = {
+ /* Default for 8-bit RGB source, never optimized */
+ {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
+};
+
+static const struct blit_table normal_blit_2[] = {
+#if SDL_ALTIVEC_BLITTERS
+ /* has-altivec */
+ {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00000000, 0x00000000, 0x00000000,
+ 2, Blit_RGB565_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
+ {0x00007C00, 0x000003E0, 0x0000001F, 4, 0x00000000, 0x00000000, 0x00000000,
+ 2, Blit_RGB555_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
+#endif
+ {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00FF0000, 0x0000FF00, 0x000000FF,
+ 0, Blit_RGB565_ARGB8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
+ {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x000000FF, 0x0000FF00, 0x00FF0000,
+ 0, Blit_RGB565_ABGR8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
+ {0x0000F800, 0x000007E0, 0x0000001F, 4, 0xFF000000, 0x00FF0000, 0x0000FF00,
+ 0, Blit_RGB565_RGBA8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
+ {0x0000F800, 0x000007E0, 0x0000001F, 4, 0x0000FF00, 0x00FF0000, 0xFF000000,
+ 0, Blit_RGB565_BGRA8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
+
+ /* Default for 16-bit RGB source, used if no other blitter matches */
+ {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
+};
+
+static const struct blit_table normal_blit_3[] = {
+ /* Default for 24-bit RGB source, never optimized */
+ {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
+};
+
+static const struct blit_table normal_blit_4[] = {
+#if SDL_ALTIVEC_BLITTERS
+ /* has-altivec | dont-use-prefetch */
+ {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000, 0x00000000,
+ 6, ConvertAltivec32to32_noprefetch, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
+ /* has-altivec */
+ {0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000, 0x00000000,
+ 2, ConvertAltivec32to32_prefetch, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
+ /* has-altivec */
+ {0x00000000, 0x00000000, 0x00000000, 2, 0x0000F800, 0x000007E0, 0x0000001F,
+ 2, Blit_RGB888_RGB565Altivec, NO_ALPHA},
+#endif
+ {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000F800, 0x000007E0, 0x0000001F,
+ 0, Blit_RGB888_RGB565, NO_ALPHA},
+ {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x00007C00, 0x000003E0, 0x0000001F,
+ 0, Blit_RGB888_RGB555, NO_ALPHA},
+ /* Default for 32-bit RGB source, used if no other blitter matches */
+ {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
+};
+
+static const struct blit_table *const normal_blit[] = {
+ normal_blit_1, normal_blit_2, normal_blit_3, normal_blit_4
+};
+
+/* Mask matches table, or table entry is zero */
+#define MASKOK(x, y) (((x) == (y)) || ((y) == 0x00000000))
+
+SDL_BlitFunc
+SDL_CalculateBlitN(SDL_Surface * surface)
+{
+ SDL_PixelFormat *srcfmt;
+ SDL_PixelFormat *dstfmt;
+ const struct blit_table *table;
+ int which;
+ SDL_BlitFunc blitfun;
+
+ /* Set up data for choosing the blit */
+ srcfmt = surface->format;
+ dstfmt = surface->map->dst->format;
+
+ /* We don't support destinations less than 8-bits */
+ if (dstfmt->BitsPerPixel < 8) {
+ return (NULL);
+ }
+
+ switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
+ case 0:
+ blitfun = NULL;
+ if (dstfmt->BitsPerPixel == 8) {
+ if ((srcfmt->BytesPerPixel == 4) &&
+ (srcfmt->Rmask == 0x00FF0000) &&
+ (srcfmt->Gmask == 0x0000FF00) &&
+ (srcfmt->Bmask == 0x000000FF)) {
+ blitfun = Blit_RGB888_index8;
+ } else if ((srcfmt->BytesPerPixel == 4) &&
+ (srcfmt->Rmask == 0x3FF00000) &&
+ (srcfmt->Gmask == 0x000FFC00) &&
+ (srcfmt->Bmask == 0x000003FF)) {
+ blitfun = Blit_RGB101010_index8;
+ } else {
+ blitfun = BlitNto1;
+ }
+ } else {
+ /* Now the meat, choose the blitter we want */
+ int a_need = NO_ALPHA;
+ if (dstfmt->Amask)
+ a_need = srcfmt->Amask ? COPY_ALPHA : SET_ALPHA;
+ table = normal_blit[srcfmt->BytesPerPixel - 1];
+ for (which = 0; table[which].dstbpp; ++which) {
+ if (MASKOK(srcfmt->Rmask, table[which].srcR) &&
+ MASKOK(srcfmt->Gmask, table[which].srcG) &&
+ MASKOK(srcfmt->Bmask, table[which].srcB) &&
+ MASKOK(dstfmt->Rmask, table[which].dstR) &&
+ MASKOK(dstfmt->Gmask, table[which].dstG) &&
+ MASKOK(dstfmt->Bmask, table[which].dstB) &&
+ dstfmt->BytesPerPixel == table[which].dstbpp &&
+ (a_need & table[which].alpha) == a_need &&
+ ((table[which].blit_features & GetBlitFeatures()) ==
+ table[which].blit_features))
+ break;
+ }
+ blitfun = table[which].blitfunc;
+
+ if (blitfun == BlitNtoN) { /* default C fallback catch-all. Slow! */
+ if (srcfmt->format == SDL_PIXELFORMAT_ARGB2101010) {
+ blitfun = Blit2101010toN;
+ } else if (dstfmt->format == SDL_PIXELFORMAT_ARGB2101010) {
+ blitfun = BlitNto2101010;
+ } else if (srcfmt->BytesPerPixel == 4 &&
+ dstfmt->BytesPerPixel == 4 &&
+ srcfmt->Rmask == dstfmt->Rmask &&
+ srcfmt->Gmask == dstfmt->Gmask &&
+ srcfmt->Bmask == dstfmt->Bmask) {
+ if (a_need == COPY_ALPHA) {
+ if (srcfmt->Amask == dstfmt->Amask) {
+ /* Fastpath C fallback: 32bit RGBA<->RGBA blit with matching RGBA */
+ blitfun = Blit4to4CopyAlpha;
+ } else {
+ blitfun = BlitNtoNCopyAlpha;
+ }
+ } else {
+ /* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */
+ blitfun = Blit4to4MaskAlpha;
+ }
+ } else if (a_need == COPY_ALPHA) {
+ blitfun = BlitNtoNCopyAlpha;
+ }
+ }
+ }
+ return (blitfun);
+
+ case SDL_COPY_COLORKEY:
+ /* colorkey blit: Here we don't have too many options, mostly
+ because RLE is the preferred fast way to deal with this.
+ If a particular case turns out to be useful we'll add it. */
+
+ if (srcfmt->BytesPerPixel == 2 && surface->map->identity)
+ return Blit2to2Key;
+ else if (dstfmt->BytesPerPixel == 1)
+ return BlitNto1Key;
+ else {
+#if SDL_ALTIVEC_BLITTERS
+ if ((srcfmt->BytesPerPixel == 4) && (dstfmt->BytesPerPixel == 4)
+ && SDL_HasAltiVec()) {
+ return Blit32to32KeyAltivec;
+ } else
+#endif
+ if (srcfmt->Amask && dstfmt->Amask) {
+ return BlitNtoNKeyCopyAlpha;
+ } else {
+ return BlitNtoNKey;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_blit_auto.c b/src/3rdparty/SDL2/src/video/SDL_blit_auto.c
new file mode 100644
index 0000000..d9d266f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_blit_auto.c
@@ -0,0 +1,7419 @@
+/* DO NOT EDIT! This file is generated by sdlgenblit.pl */
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* *INDENT-OFF* */
+
+#include "SDL_video.h"
+#include "SDL_blit.h"
+#include "SDL_blit_auto.h"
+
+static void SDL_Blit_RGB888_RGB888_Scale(SDL_BlitInfo *info)
+{
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ *dst = *src;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_RGB888_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_RGB888_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_RGB888_Modulate(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ pixel = *src;
+ R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_BGR888_Scale(SDL_BlitInfo *info)
+{
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
+ pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_BGR888_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_BGR888_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_BGR888_Modulate(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ pixel = *src;
+ R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
+ *dst = pixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_BGR888_Modulate_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_BGR888_Modulate_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_ARGB8888_Scale(SDL_BlitInfo *info)
+{
+ Uint32 pixel;
+ Uint32 R, G, B, A;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
+ pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_ARGB8888_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_ARGB8888_Modulate(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 pixel;
+ Uint32 R, G, B, A;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ pixel = *src;
+ R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ A = (A * modulateA) / 255;
+ }
+ pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 pixel;
+ Uint32 R, G, B, A;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ A = (A * modulateA) / 255;
+ }
+ pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGB888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_RGB888_Scale(SDL_BlitInfo *info)
+{
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
+ pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_RGB888_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_RGB888_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_RGB888_Modulate(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ pixel = *src;
+ B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_BGR888_Scale(SDL_BlitInfo *info)
+{
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ *dst = *src;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_BGR888_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_BGR888_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_BGR888_Modulate(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ pixel = *src;
+ B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
+ *dst = pixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_BGR888_Modulate_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_BGR888_Modulate_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_ARGB8888_Scale(SDL_BlitInfo *info)
+{
+ Uint32 pixel;
+ Uint32 R, G, B, A;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
+ pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_ARGB8888_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_ARGB8888_Modulate(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 pixel;
+ Uint32 R, G, B, A;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ pixel = *src;
+ B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ A = (A * modulateA) / 255;
+ }
+ pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 pixel;
+ Uint32 R, G, B, A;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ A = (A * modulateA) / 255;
+ }
+ pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGR888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_RGB888_Scale(SDL_BlitInfo *info)
+{
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
+ pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_RGB888_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_RGB888_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_RGB888_Modulate(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ pixel = *src;
+ R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_BGR888_Scale(SDL_BlitInfo *info)
+{
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
+ pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_BGR888_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_BGR888_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_BGR888_Modulate(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ pixel = *src;
+ R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
+ *dst = pixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_BGR888_Modulate_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_BGR888_Modulate_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_ARGB8888_Scale(SDL_BlitInfo *info)
+{
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ *dst = *src;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_ARGB8888_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_ARGB8888_Modulate(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 pixel;
+ Uint32 R, G, B, A;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ pixel = *src;
+ R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = (Uint8)(pixel >> 24);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ A = (A * modulateA) / 255;
+ }
+ pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 pixel;
+ Uint32 R, G, B, A;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = (Uint8)(pixel >> 24);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ A = (A * modulateA) / 255;
+ }
+ pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_RGB888_Scale(SDL_BlitInfo *info)
+{
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8);
+ pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_RGB888_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_RGB888_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_RGB888_Modulate(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ pixel = *src;
+ R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_BGR888_Scale(SDL_BlitInfo *info)
+{
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8);
+ pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_BGR888_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_BGR888_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_BGR888_Modulate(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ pixel = *src;
+ R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
+ *dst = pixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_BGR888_Modulate_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_BGR888_Modulate_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_ARGB8888_Scale(SDL_BlitInfo *info)
+{
+ Uint32 pixel;
+ Uint32 R, G, B, A;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel;
+ pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_ARGB8888_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_ARGB8888_Modulate(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 pixel;
+ Uint32 R, G, B, A;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ pixel = *src;
+ R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ A = (A * modulateA) / 255;
+ }
+ pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 pixel;
+ Uint32 R, G, B, A;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ A = (A * modulateA) / 255;
+ }
+ pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_RGBA8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_RGB888_Scale(SDL_BlitInfo *info)
+{
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
+ pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_RGB888_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_RGB888_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_RGB888_Modulate(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ pixel = *src;
+ B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_BGR888_Scale(SDL_BlitInfo *info)
+{
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
+ pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_BGR888_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_BGR888_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_BGR888_Modulate(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ pixel = *src;
+ B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
+ *dst = pixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_BGR888_Modulate_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_BGR888_Modulate_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_ARGB8888_Scale(SDL_BlitInfo *info)
+{
+ Uint32 pixel;
+ Uint32 R, G, B, A;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = (Uint8)(pixel >> 24);
+ pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_ARGB8888_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_ARGB8888_Modulate(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 pixel;
+ Uint32 R, G, B, A;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ pixel = *src;
+ B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = (Uint8)(pixel >> 24);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ A = (A * modulateA) / 255;
+ }
+ pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 pixel;
+ Uint32 R, G, B, A;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = (Uint8)(pixel >> 24);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ A = (A * modulateA) / 255;
+ }
+ pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_ABGR8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_RGB888_Scale(SDL_BlitInfo *info)
+{
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8);
+ pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_RGB888_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_RGB888_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_RGB888_Modulate(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ pixel = *src;
+ B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_BGR888_Scale(SDL_BlitInfo *info)
+{
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8);
+ pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_BGR888_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_BGR888_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_BGR888_Modulate(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ pixel = *src;
+ B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
+ *dst = pixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_BGR888_Modulate_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ Uint32 pixel;
+ Uint32 R, G, B;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_BGR888_Modulate_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_ARGB8888_Scale(SDL_BlitInfo *info)
+{
+ Uint32 pixel;
+ Uint32 R, G, B, A;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel;
+ pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_ARGB8888_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_ARGB8888_Modulate(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 pixel;
+ Uint32 R, G, B, A;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ pixel = *src;
+ B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ A = (A * modulateA) / 255;
+ }
+ pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 pixel;
+ Uint32 R, G, B, A;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ pixel = *src;
+ B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ R = (R * modulateR) / 255;
+ G = (G * modulateG) / 255;
+ B = (B * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ A = (A * modulateA) / 255;
+ }
+ pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
+ *dst = pixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+
+ while (info->dst_h--) {
+ Uint32 *src = (Uint32 *)info->src;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+}
+
+static void SDL_Blit_BGRA8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint32 *src = 0;
+ Uint32 *dst = (Uint32 *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
+ }
+ srcpixel = *src;
+ srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
+ dstpixel = *dst;
+ dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR; if (dstR > 255) dstR = 255;
+ dstG = srcG + dstG; if (dstG > 255) dstG = 255;
+ dstB = srcB + dstB; if (dstB > 255) dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
+ *dst = dstpixel;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[] = {
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Scale },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Blend },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Blend_Scale },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Modulate },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Modulate_Scale },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Modulate_Blend },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Modulate_Blend_Scale },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Scale },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Blend },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Blend_Scale },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Modulate },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Modulate_Scale },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Modulate_Blend },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Modulate_Blend_Scale },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Scale },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Blend },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Blend_Scale },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Modulate },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Modulate_Scale },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Modulate_Blend },
+ { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Modulate_Blend_Scale },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Scale },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Blend },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Blend_Scale },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Modulate },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Modulate_Scale },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Modulate_Blend },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Modulate_Blend_Scale },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Scale },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Blend },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Blend_Scale },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Modulate },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Modulate_Scale },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Modulate_Blend },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Modulate_Blend_Scale },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Scale },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Blend },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Blend_Scale },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Modulate },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Modulate_Scale },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Modulate_Blend },
+ { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Modulate_Blend_Scale },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Scale },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Blend },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Blend_Scale },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Modulate },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Modulate_Scale },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Modulate_Blend },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Modulate_Blend_Scale },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Scale },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Blend },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Blend_Scale },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Modulate },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Modulate_Scale },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Modulate_Blend },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Modulate_Blend_Scale },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Scale },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Blend },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Blend_Scale },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Modulate },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Modulate_Scale },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend },
+ { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend_Scale },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Scale },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Blend },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Blend_Scale },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Modulate },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Modulate_Scale },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Modulate_Blend },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Modulate_Blend_Scale },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Scale },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Blend },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Blend_Scale },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Modulate },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Modulate_Scale },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Modulate_Blend },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Modulate_Blend_Scale },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Scale },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Blend },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Blend_Scale },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Modulate },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Modulate_Scale },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Modulate_Blend },
+ { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Modulate_Blend_Scale },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Scale },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Blend },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Blend_Scale },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Modulate },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Modulate_Scale },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Modulate_Blend },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Modulate_Blend_Scale },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Scale },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Blend },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Blend_Scale },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Modulate },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Modulate_Scale },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Modulate_Blend },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Modulate_Blend_Scale },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Scale },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Blend },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Blend_Scale },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Modulate },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Modulate_Scale },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Modulate_Blend },
+ { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Modulate_Blend_Scale },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Scale },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Blend },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Blend_Scale },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Modulate },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Modulate_Scale },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Modulate_Blend },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Modulate_Blend_Scale },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Scale },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Blend },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Blend_Scale },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Modulate },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Modulate_Scale },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Modulate_Blend },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Modulate_Blend_Scale },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Scale },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Blend },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Blend_Scale },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Modulate },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Modulate_Scale },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Modulate_Blend },
+ { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Modulate_Blend_Scale },
+ { 0, 0, 0, 0, NULL }
+};
+
+/* *INDENT-ON* */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_blit_auto.h b/src/3rdparty/SDL2/src/video/SDL_blit_auto.h
new file mode 100644
index 0000000..41a6a32
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_blit_auto.h
@@ -0,0 +1,30 @@
+/* DO NOT EDIT! This file is generated by sdlgenblit.pl */
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* *INDENT-OFF* */
+
+extern SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[];
+
+/* *INDENT-ON* */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_blit_copy.c b/src/3rdparty/SDL2/src/video/SDL_blit_copy.c
new file mode 100644
index 0000000..e862898
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_blit_copy.c
@@ -0,0 +1,162 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "SDL_video.h"
+#include "SDL_blit.h"
+#include "SDL_blit_copy.h"
+
+
+#ifdef __SSE__
+/* This assumes 16-byte aligned src and dst */
+static SDL_INLINE void
+SDL_memcpySSE(Uint8 * dst, const Uint8 * src, int len)
+{
+ int i;
+
+ __m128 values[4];
+ for (i = len / 64; i--;) {
+ _mm_prefetch(src, _MM_HINT_NTA);
+ values[0] = *(__m128 *) (src + 0);
+ values[1] = *(__m128 *) (src + 16);
+ values[2] = *(__m128 *) (src + 32);
+ values[3] = *(__m128 *) (src + 48);
+ _mm_stream_ps((float *) (dst + 0), values[0]);
+ _mm_stream_ps((float *) (dst + 16), values[1]);
+ _mm_stream_ps((float *) (dst + 32), values[2]);
+ _mm_stream_ps((float *) (dst + 48), values[3]);
+ src += 64;
+ dst += 64;
+ }
+
+ if (len & 63)
+ SDL_memcpy(dst, src, len & 63);
+}
+#endif /* __SSE__ */
+
+#ifdef __MMX__
+#ifdef _MSC_VER
+#pragma warning(disable:4799)
+#endif
+static SDL_INLINE void
+SDL_memcpyMMX(Uint8 * dst, const Uint8 * src, int len)
+{
+ const int remain = (len & 63);
+ int i;
+
+ __m64* d64 = (__m64*)dst;
+ __m64* s64 = (__m64*)src;
+
+ for(i= len / 64; i--;) {
+ d64[0] = s64[0];
+ d64[1] = s64[1];
+ d64[2] = s64[2];
+ d64[3] = s64[3];
+ d64[4] = s64[4];
+ d64[5] = s64[5];
+ d64[6] = s64[6];
+ d64[7] = s64[7];
+
+ d64 += 8;
+ s64 += 8;
+ }
+
+ if (remain)
+ {
+ const int skip = len - remain;
+ SDL_memcpy(dst + skip, src + skip, remain);
+ }
+}
+#endif /* __MMX__ */
+
+void
+SDL_BlitCopy(SDL_BlitInfo * info)
+{
+ SDL_bool overlap;
+ Uint8 *src, *dst;
+ int w, h;
+ int srcskip, dstskip;
+
+ w = info->dst_w * info->dst_fmt->BytesPerPixel;
+ h = info->dst_h;
+ src = info->src;
+ dst = info->dst;
+ srcskip = info->src_pitch;
+ dstskip = info->dst_pitch;
+
+ /* Properly handle overlapping blits */
+ if (src < dst) {
+ overlap = (dst < (src + h*srcskip));
+ } else {
+ overlap = (src < (dst + h*dstskip));
+ }
+ if (overlap) {
+ if ( dst < src ) {
+ while ( h-- ) {
+ SDL_memmove(dst, src, w);
+ src += srcskip;
+ dst += dstskip;
+ }
+ } else {
+ src += ((h-1) * srcskip);
+ dst += ((h-1) * dstskip);
+ while ( h-- ) {
+ SDL_memmove(dst, src, w);
+ src -= srcskip;
+ dst -= dstskip;
+ }
+ }
+ return;
+ }
+
+#ifdef __SSE__
+ if (SDL_HasSSE() &&
+ !((uintptr_t) src & 15) && !(srcskip & 15) &&
+ !((uintptr_t) dst & 15) && !(dstskip & 15)) {
+ while (h--) {
+ SDL_memcpySSE(dst, src, w);
+ src += srcskip;
+ dst += dstskip;
+ }
+ return;
+ }
+#endif
+
+#ifdef __MMX__
+ if (SDL_HasMMX() && !(srcskip & 7) && !(dstskip & 7)) {
+ while (h--) {
+ SDL_memcpyMMX(dst, src, w);
+ src += srcskip;
+ dst += dstskip;
+ }
+ _mm_empty();
+ return;
+ }
+#endif
+
+ while (h--) {
+ SDL_memcpy(dst, src, w);
+ src += srcskip;
+ dst += dstskip;
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_blit_copy.h b/src/3rdparty/SDL2/src/video/SDL_blit_copy.h
new file mode 100644
index 0000000..4665179
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_blit_copy.h
@@ -0,0 +1,24 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+void SDL_BlitCopy(SDL_BlitInfo * info);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_blit_slow.c b/src/3rdparty/SDL2/src/video/SDL_blit_slow.c
new file mode 100644
index 0000000..20ca8ab
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_blit_slow.c
@@ -0,0 +1,164 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "SDL_video.h"
+#include "SDL_blit.h"
+#include "SDL_blit_slow.h"
+
+/* The ONE TRUE BLITTER
+ * This puppy has to handle all the unoptimized cases - yes, it's slow.
+ */
+void
+SDL_Blit_Slow(SDL_BlitInfo * info)
+{
+ const int flags = info->flags;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+ const Uint32 modulateA = info->a;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+ Uint32 dstR, dstG, dstB, dstA;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+ SDL_PixelFormat *src_fmt = info->src_fmt;
+ SDL_PixelFormat *dst_fmt = info->dst_fmt;
+ int srcbpp = src_fmt->BytesPerPixel;
+ int dstbpp = dst_fmt->BytesPerPixel;
+ Uint32 rgbmask = ~src_fmt->Amask;
+ Uint32 ckey = info->colorkey & rgbmask;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ Uint8 *src = 0;
+ Uint8 *dst = (Uint8 *) info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src =
+ (info->src + (srcy * info->src_pitch) + (srcx * srcbpp));
+ }
+ if (src_fmt->Amask) {
+ DISEMBLE_RGBA(src, srcbpp, src_fmt, srcpixel, srcR, srcG,
+ srcB, srcA);
+ } else {
+ DISEMBLE_RGB(src, srcbpp, src_fmt, srcpixel, srcR, srcG,
+ srcB);
+ srcA = 0xFF;
+ }
+ if (flags & SDL_COPY_COLORKEY) {
+ /* srcpixel isn't set for 24 bpp */
+ if (srcbpp == 3) {
+ srcpixel = (srcR << src_fmt->Rshift) |
+ (srcG << src_fmt->Gshift) | (srcB << src_fmt->Bshift);
+ }
+ if ((srcpixel & rgbmask) == ckey) {
+ posx += incx;
+ dst += dstbpp;
+ continue;
+ }
+ }
+ if (dst_fmt->Amask) {
+ DISEMBLE_RGBA(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG,
+ dstB, dstA);
+ } else {
+ DISEMBLE_RGB(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG,
+ dstB);
+ dstA = 0xFF;
+ }
+
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ srcR = (srcR * modulateR) / 255;
+ srcG = (srcG * modulateG) / 255;
+ srcB = (srcB * modulateB) / 255;
+ }
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ srcA = (srcA * modulateA) / 255;
+ }
+ if (flags & (SDL_COPY_BLEND | SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (srcA < 255) {
+ srcR = (srcR * srcA) / 255;
+ srcG = (srcG * srcA) / 255;
+ srcB = (srcB * srcA) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD)) {
+ case 0:
+ dstR = srcR;
+ dstG = srcG;
+ dstB = srcB;
+ dstA = srcA;
+ break;
+ case SDL_COPY_BLEND:
+ dstR = srcR + ((255 - srcA) * dstR) / 255;
+ dstG = srcG + ((255 - srcA) * dstG) / 255;
+ dstB = srcB + ((255 - srcA) * dstB) / 255;
+ dstA = srcA + ((255 - srcA) * dstA) / 255;
+ break;
+ case SDL_COPY_ADD:
+ dstR = srcR + dstR;
+ if (dstR > 255)
+ dstR = 255;
+ dstG = srcG + dstG;
+ if (dstG > 255)
+ dstG = 255;
+ dstB = srcB + dstB;
+ if (dstB > 255)
+ dstB = 255;
+ break;
+ case SDL_COPY_MOD:
+ dstR = (srcR * dstR) / 255;
+ dstG = (srcG * dstG) / 255;
+ dstB = (srcB * dstB) / 255;
+ break;
+ }
+ if (dst_fmt->Amask) {
+ ASSEMBLE_RGBA(dst, dstbpp, dst_fmt, dstR, dstG, dstB, dstA);
+ } else {
+ ASSEMBLE_RGB(dst, dstbpp, dst_fmt, dstR, dstG, dstB);
+ }
+ posx += incx;
+ dst += dstbpp;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_blit_slow.h b/src/3rdparty/SDL2/src/video/SDL_blit_slow.h
new file mode 100644
index 0000000..02d360a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_blit_slow.h
@@ -0,0 +1,25 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+extern void SDL_Blit_Slow(SDL_BlitInfo * info);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_bmp.c b/src/3rdparty/SDL2/src/video/SDL_bmp.c
new file mode 100644
index 0000000..ba908a6
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_bmp.c
@@ -0,0 +1,702 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/*
+ Code to load and save surfaces in Windows BMP format.
+
+ Why support BMP format? Well, it's a native format for Windows, and
+ most image processing programs can read and write it. It would be nice
+ to be able to have at least one image format that we can natively load
+ and save, and since PNG is so complex that it would bloat the library,
+ BMP is a good alternative.
+
+ This code currently supports Win32 DIBs in uncompressed 8 and 24 bpp.
+*/
+
+#include "SDL_hints.h"
+#include "SDL_video.h"
+#include "SDL_assert.h"
+#include "SDL_endian.h"
+#include "SDL_pixels_c.h"
+
+#define SAVE_32BIT_BMP
+
+/* Compression encodings for BMP files */
+#ifndef BI_RGB
+#define BI_RGB 0
+#define BI_RLE8 1
+#define BI_RLE4 2
+#define BI_BITFIELDS 3
+#endif
+
+/* Logical color space values for BMP files */
+#ifndef LCS_WINDOWS_COLOR_SPACE
+/* 0x57696E20 == "Win " */
+#define LCS_WINDOWS_COLOR_SPACE 0x57696E20
+#endif
+
+static void CorrectAlphaChannel(SDL_Surface *surface)
+{
+ /* Check to see if there is any alpha channel data */
+ SDL_bool hasAlpha = SDL_FALSE;
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ int alphaChannelOffset = 0;
+#else
+ int alphaChannelOffset = 3;
+#endif
+ Uint8 *alpha = ((Uint8*)surface->pixels) + alphaChannelOffset;
+ Uint8 *end = alpha + surface->h * surface->pitch;
+
+ while (alpha < end) {
+ if (*alpha != 0) {
+ hasAlpha = SDL_TRUE;
+ break;
+ }
+ alpha += 4;
+ }
+
+ if (!hasAlpha) {
+ alpha = ((Uint8*)surface->pixels) + alphaChannelOffset;
+ while (alpha < end) {
+ *alpha = SDL_ALPHA_OPAQUE;
+ alpha += 4;
+ }
+ }
+}
+
+SDL_Surface *
+SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
+{
+ SDL_bool was_error;
+ Sint64 fp_offset = 0;
+ int bmpPitch;
+ int i, pad;
+ SDL_Surface *surface;
+ Uint32 Rmask = 0;
+ Uint32 Gmask = 0;
+ Uint32 Bmask = 0;
+ Uint32 Amask = 0;
+ SDL_Palette *palette;
+ Uint8 *bits;
+ Uint8 *top, *end;
+ SDL_bool topDown;
+ int ExpandBMP;
+ SDL_bool haveRGBMasks = SDL_FALSE;
+ SDL_bool haveAlphaMask = SDL_FALSE;
+ SDL_bool correctAlpha = SDL_FALSE;
+
+ /* The Win32 BMP file header (14 bytes) */
+ char magic[2];
+ /* Uint32 bfSize = 0; */
+ /* Uint16 bfReserved1 = 0; */
+ /* Uint16 bfReserved2 = 0; */
+ Uint32 bfOffBits = 0;
+
+ /* The Win32 BITMAPINFOHEADER struct (40 bytes) */
+ Uint32 biSize = 0;
+ Sint32 biWidth = 0;
+ Sint32 biHeight = 0;
+ /* Uint16 biPlanes = 0; */
+ Uint16 biBitCount = 0;
+ Uint32 biCompression = 0;
+ /* Uint32 biSizeImage = 0; */
+ /* Sint32 biXPelsPerMeter = 0; */
+ /* Sint32 biYPelsPerMeter = 0; */
+ Uint32 biClrUsed = 0;
+ /* Uint32 biClrImportant = 0; */
+
+ (void) haveRGBMasks;
+ (void) haveAlphaMask;
+
+ /* Make sure we are passed a valid data source */
+ surface = NULL;
+ was_error = SDL_FALSE;
+ if (src == NULL) {
+ was_error = SDL_TRUE;
+ goto done;
+ }
+
+ /* Read in the BMP file header */
+ fp_offset = SDL_RWtell(src);
+ SDL_ClearError();
+ if (SDL_RWread(src, magic, 1, 2) != 2) {
+ SDL_Error(SDL_EFREAD);
+ was_error = SDL_TRUE;
+ goto done;
+ }
+ if (SDL_strncmp(magic, "BM", 2) != 0) {
+ SDL_SetError("File is not a Windows BMP file");
+ was_error = SDL_TRUE;
+ goto done;
+ }
+ /* bfSize = */ SDL_ReadLE32(src);
+ /* bfReserved1 = */ SDL_ReadLE16(src);
+ /* bfReserved2 = */ SDL_ReadLE16(src);
+ bfOffBits = SDL_ReadLE32(src);
+
+ /* Read the Win32 BITMAPINFOHEADER */
+ biSize = SDL_ReadLE32(src);
+ if (biSize == 12) { /* really old BITMAPCOREHEADER */
+ biWidth = (Uint32) SDL_ReadLE16(src);
+ biHeight = (Uint32) SDL_ReadLE16(src);
+ /* biPlanes = */ SDL_ReadLE16(src);
+ biBitCount = SDL_ReadLE16(src);
+ biCompression = BI_RGB;
+ } else if (biSize >= 40) { /* some version of BITMAPINFOHEADER */
+ Uint32 headerSize;
+ biWidth = SDL_ReadLE32(src);
+ biHeight = SDL_ReadLE32(src);
+ /* biPlanes = */ SDL_ReadLE16(src);
+ biBitCount = SDL_ReadLE16(src);
+ biCompression = SDL_ReadLE32(src);
+ /* biSizeImage = */ SDL_ReadLE32(src);
+ /* biXPelsPerMeter = */ SDL_ReadLE32(src);
+ /* biYPelsPerMeter = */ SDL_ReadLE32(src);
+ biClrUsed = SDL_ReadLE32(src);
+ /* biClrImportant = */ SDL_ReadLE32(src);
+
+ /* 64 == BITMAPCOREHEADER2, an incompatible OS/2 2.x extension. Skip this stuff for now. */
+ if (biSize == 64) {
+ /* ignore these extra fields. */
+ if (biCompression == BI_BITFIELDS) {
+ /* this value is actually huffman compression in this variant. */
+ SDL_SetError("Compressed BMP files not supported");
+ was_error = SDL_TRUE;
+ goto done;
+ }
+ } else {
+ /* This is complicated. If compression is BI_BITFIELDS, then
+ we have 3 DWORDS that specify the RGB masks. This is either
+ stored here in an BITMAPV2INFOHEADER (which only differs in
+ that it adds these RGB masks) and biSize >= 52, or we've got
+ these masks stored in the exact same place, but strictly
+ speaking, this is the bmiColors field in BITMAPINFO immediately
+ following the legacy v1 info header, just past biSize. */
+ if (biCompression == BI_BITFIELDS) {
+ haveRGBMasks = SDL_TRUE;
+ Rmask = SDL_ReadLE32(src);
+ Gmask = SDL_ReadLE32(src);
+ Bmask = SDL_ReadLE32(src);
+
+ /* ...v3 adds an alpha mask. */
+ if (biSize >= 56) { /* BITMAPV3INFOHEADER; adds alpha mask */
+ haveAlphaMask = SDL_TRUE;
+ Amask = SDL_ReadLE32(src);
+ }
+ } else {
+ /* the mask fields are ignored for v2+ headers if not BI_BITFIELD. */
+ if (biSize >= 52) { /* BITMAPV2INFOHEADER; adds RGB masks */
+ /*Rmask = */ SDL_ReadLE32(src);
+ /*Gmask = */ SDL_ReadLE32(src);
+ /*Bmask = */ SDL_ReadLE32(src);
+ }
+ if (biSize >= 56) { /* BITMAPV3INFOHEADER; adds alpha mask */
+ /*Amask = */ SDL_ReadLE32(src);
+ }
+ }
+
+ /* Insert other fields here; Wikipedia and MSDN say we're up to
+ v5 of this header, but we ignore those for now (they add gamma,
+ color spaces, etc). Ignoring the weird OS/2 2.x format, we
+ currently parse up to v3 correctly (hopefully!). */
+ }
+
+ /* skip any header bytes we didn't handle... */
+ headerSize = (Uint32) (SDL_RWtell(src) - (fp_offset + 14));
+ if (biSize > headerSize) {
+ SDL_RWseek(src, (biSize - headerSize), RW_SEEK_CUR);
+ }
+ }
+ if (biHeight < 0) {
+ topDown = SDL_TRUE;
+ biHeight = -biHeight;
+ } else {
+ topDown = SDL_FALSE;
+ }
+
+ /* Check for read error */
+ if (SDL_strcmp(SDL_GetError(), "") != 0) {
+ was_error = SDL_TRUE;
+ goto done;
+ }
+
+ /* Expand 1 and 4 bit bitmaps to 8 bits per pixel */
+ switch (biBitCount) {
+ case 1:
+ case 4:
+ ExpandBMP = biBitCount;
+ biBitCount = 8;
+ break;
+ default:
+ ExpandBMP = 0;
+ break;
+ }
+
+ /* We don't support any BMP compression right now */
+ switch (biCompression) {
+ case BI_RGB:
+ /* If there are no masks, use the defaults */
+ SDL_assert(!haveRGBMasks);
+ SDL_assert(!haveAlphaMask);
+ /* Default values for the BMP format */
+ switch (biBitCount) {
+ case 15:
+ case 16:
+ Rmask = 0x7C00;
+ Gmask = 0x03E0;
+ Bmask = 0x001F;
+ break;
+ case 24:
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ Rmask = 0x000000FF;
+ Gmask = 0x0000FF00;
+ Bmask = 0x00FF0000;
+#else
+ Rmask = 0x00FF0000;
+ Gmask = 0x0000FF00;
+ Bmask = 0x000000FF;
+#endif
+ break;
+ case 32:
+ /* We don't know if this has alpha channel or not */
+ correctAlpha = SDL_TRUE;
+ Amask = 0xFF000000;
+ Rmask = 0x00FF0000;
+ Gmask = 0x0000FF00;
+ Bmask = 0x000000FF;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case BI_BITFIELDS:
+ break; /* we handled this in the info header. */
+
+ default:
+ SDL_SetError("Compressed BMP files not supported");
+ was_error = SDL_TRUE;
+ goto done;
+ }
+
+ /* Create a compatible surface, note that the colors are RGB ordered */
+ surface =
+ SDL_CreateRGBSurface(0, biWidth, biHeight, biBitCount, Rmask, Gmask,
+ Bmask, Amask);
+ if (surface == NULL) {
+ was_error = SDL_TRUE;
+ goto done;
+ }
+
+ /* Load the palette, if any */
+ palette = (surface->format)->palette;
+ if (palette) {
+ SDL_assert(biBitCount <= 8);
+ if (biClrUsed == 0) {
+ biClrUsed = 1 << biBitCount;
+ }
+ if ((int) biClrUsed > palette->ncolors) {
+ SDL_Color *colors;
+ int ncolors = biClrUsed;
+ colors =
+ (SDL_Color *) SDL_realloc(palette->colors,
+ ncolors *
+ sizeof(*palette->colors));
+ if (!colors) {
+ SDL_OutOfMemory();
+ was_error = SDL_TRUE;
+ goto done;
+ }
+ palette->ncolors = ncolors;
+ palette->colors = colors;
+ } else if ((int) biClrUsed < palette->ncolors) {
+ palette->ncolors = biClrUsed;
+ }
+ if (biSize == 12) {
+ for (i = 0; i < (int) biClrUsed; ++i) {
+ SDL_RWread(src, &palette->colors[i].b, 1, 1);
+ SDL_RWread(src, &palette->colors[i].g, 1, 1);
+ SDL_RWread(src, &palette->colors[i].r, 1, 1);
+ palette->colors[i].a = SDL_ALPHA_OPAQUE;
+ }
+ } else {
+ for (i = 0; i < (int) biClrUsed; ++i) {
+ SDL_RWread(src, &palette->colors[i].b, 1, 1);
+ SDL_RWread(src, &palette->colors[i].g, 1, 1);
+ SDL_RWread(src, &palette->colors[i].r, 1, 1);
+ SDL_RWread(src, &palette->colors[i].a, 1, 1);
+
+ /* According to Microsoft documentation, the fourth element
+ is reserved and must be zero, so we shouldn't treat it as
+ alpha.
+ */
+ palette->colors[i].a = SDL_ALPHA_OPAQUE;
+ }
+ }
+ }
+
+ /* Read the surface pixels. Note that the bmp image is upside down */
+ if (SDL_RWseek(src, fp_offset + bfOffBits, RW_SEEK_SET) < 0) {
+ SDL_Error(SDL_EFSEEK);
+ was_error = SDL_TRUE;
+ goto done;
+ }
+ top = (Uint8 *)surface->pixels;
+ end = (Uint8 *)surface->pixels+(surface->h*surface->pitch);
+ switch (ExpandBMP) {
+ case 1:
+ bmpPitch = (biWidth + 7) >> 3;
+ pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0);
+ break;
+ case 4:
+ bmpPitch = (biWidth + 1) >> 1;
+ pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0);
+ break;
+ default:
+ pad = ((surface->pitch % 4) ? (4 - (surface->pitch % 4)) : 0);
+ break;
+ }
+ if (topDown) {
+ bits = top;
+ } else {
+ bits = end - surface->pitch;
+ }
+ while (bits >= top && bits < end) {
+ switch (ExpandBMP) {
+ case 1:
+ case 4:{
+ Uint8 pixel = 0;
+ int shift = (8 - ExpandBMP);
+ for (i = 0; i < surface->w; ++i) {
+ if (i % (8 / ExpandBMP) == 0) {
+ if (!SDL_RWread(src, &pixel, 1, 1)) {
+ SDL_SetError("Error reading from BMP");
+ was_error = SDL_TRUE;
+ goto done;
+ }
+ }
+ *(bits + i) = (pixel >> shift);
+ pixel <<= ExpandBMP;
+ }
+ }
+ break;
+
+ default:
+ if (SDL_RWread(src, bits, 1, surface->pitch)
+ != surface->pitch) {
+ SDL_Error(SDL_EFREAD);
+ was_error = SDL_TRUE;
+ goto done;
+ }
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ /* Byte-swap the pixels if needed. Note that the 24bpp
+ case has already been taken care of above. */
+ switch (biBitCount) {
+ case 15:
+ case 16:{
+ Uint16 *pix = (Uint16 *) bits;
+ for (i = 0; i < surface->w; i++)
+ pix[i] = SDL_Swap16(pix[i]);
+ break;
+ }
+
+ case 32:{
+ Uint32 *pix = (Uint32 *) bits;
+ for (i = 0; i < surface->w; i++)
+ pix[i] = SDL_Swap32(pix[i]);
+ break;
+ }
+ }
+#endif
+ break;
+ }
+ /* Skip padding bytes, ugh */
+ if (pad) {
+ Uint8 padbyte;
+ for (i = 0; i < pad; ++i) {
+ SDL_RWread(src, &padbyte, 1, 1);
+ }
+ }
+ if (topDown) {
+ bits += surface->pitch;
+ } else {
+ bits -= surface->pitch;
+ }
+ }
+ if (correctAlpha) {
+ CorrectAlphaChannel(surface);
+ }
+ done:
+ if (was_error) {
+ if (src) {
+ SDL_RWseek(src, fp_offset, RW_SEEK_SET);
+ }
+ SDL_FreeSurface(surface);
+ surface = NULL;
+ }
+ if (freesrc && src) {
+ SDL_RWclose(src);
+ }
+ return (surface);
+}
+
+int
+SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
+{
+ Sint64 fp_offset;
+ int i, pad;
+ SDL_Surface *surface;
+ Uint8 *bits;
+ SDL_bool save32bit = SDL_FALSE;
+ SDL_bool saveLegacyBMP = SDL_FALSE;
+
+ /* The Win32 BMP file header (14 bytes) */
+ char magic[2] = { 'B', 'M' };
+ Uint32 bfSize;
+ Uint16 bfReserved1;
+ Uint16 bfReserved2;
+ Uint32 bfOffBits;
+
+ /* The Win32 BITMAPINFOHEADER struct (40 bytes) */
+ Uint32 biSize;
+ Sint32 biWidth;
+ Sint32 biHeight;
+ Uint16 biPlanes;
+ Uint16 biBitCount;
+ Uint32 biCompression;
+ Uint32 biSizeImage;
+ Sint32 biXPelsPerMeter;
+ Sint32 biYPelsPerMeter;
+ Uint32 biClrUsed;
+ Uint32 biClrImportant;
+
+ /* The additional header members from the Win32 BITMAPV4HEADER struct (108 bytes in total) */
+ Uint32 bV4RedMask = 0;
+ Uint32 bV4GreenMask = 0;
+ Uint32 bV4BlueMask = 0;
+ Uint32 bV4AlphaMask = 0;
+ Uint32 bV4CSType = 0;
+ Sint32 bV4Endpoints[3 * 3] = {0};
+ Uint32 bV4GammaRed = 0;
+ Uint32 bV4GammaGreen = 0;
+ Uint32 bV4GammaBlue = 0;
+
+ /* Make sure we have somewhere to save */
+ surface = NULL;
+ if (dst) {
+#ifdef SAVE_32BIT_BMP
+ /* We can save alpha information in a 32-bit BMP */
+ if (saveme->format->BitsPerPixel >= 8 && (saveme->format->Amask ||
+ saveme->map->info.flags & SDL_COPY_COLORKEY)) {
+ save32bit = SDL_TRUE;
+ }
+#endif /* SAVE_32BIT_BMP */
+
+ if (saveme->format->palette && !save32bit) {
+ if (saveme->format->BitsPerPixel == 8) {
+ surface = saveme;
+ } else {
+ SDL_SetError("%d bpp BMP files not supported",
+ saveme->format->BitsPerPixel);
+ }
+ } else if ((saveme->format->BitsPerPixel == 24) && !save32bit &&
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+ (saveme->format->Rmask == 0x00FF0000) &&
+ (saveme->format->Gmask == 0x0000FF00) &&
+ (saveme->format->Bmask == 0x000000FF)
+#else
+ (saveme->format->Rmask == 0x000000FF) &&
+ (saveme->format->Gmask == 0x0000FF00) &&
+ (saveme->format->Bmask == 0x00FF0000)
+#endif
+ ) {
+ surface = saveme;
+ } else {
+ SDL_PixelFormat format;
+
+ /* If the surface has a colorkey or alpha channel we'll save a
+ 32-bit BMP with alpha channel, otherwise save a 24-bit BMP. */
+ if (save32bit) {
+ SDL_InitFormat(&format, SDL_PIXELFORMAT_BGRA32);
+ } else {
+ SDL_InitFormat(&format, SDL_PIXELFORMAT_BGR24);
+ }
+ surface = SDL_ConvertSurface(saveme, &format, 0);
+ if (!surface) {
+ SDL_SetError("Couldn't convert image to %d bpp",
+ format.BitsPerPixel);
+ }
+ }
+ } else {
+ /* Set no error here because it may overwrite a more useful message from
+ SDL_RWFromFile() if SDL_SaveBMP_RW() is called from SDL_SaveBMP(). */
+ return -1;
+ }
+
+ if (save32bit) {
+ saveLegacyBMP = SDL_GetHintBoolean(SDL_HINT_BMP_SAVE_LEGACY_FORMAT, SDL_FALSE);
+ }
+
+ if (surface && (SDL_LockSurface(surface) == 0)) {
+ const int bw = surface->w * surface->format->BytesPerPixel;
+
+ /* Set the BMP file header values */
+ bfSize = 0; /* We'll write this when we're done */
+ bfReserved1 = 0;
+ bfReserved2 = 0;
+ bfOffBits = 0; /* We'll write this when we're done */
+
+ /* Write the BMP file header values */
+ fp_offset = SDL_RWtell(dst);
+ SDL_ClearError();
+ SDL_RWwrite(dst, magic, 2, 1);
+ SDL_WriteLE32(dst, bfSize);
+ SDL_WriteLE16(dst, bfReserved1);
+ SDL_WriteLE16(dst, bfReserved2);
+ SDL_WriteLE32(dst, bfOffBits);
+
+ /* Set the BMP info values */
+ biSize = 40;
+ biWidth = surface->w;
+ biHeight = surface->h;
+ biPlanes = 1;
+ biBitCount = surface->format->BitsPerPixel;
+ biCompression = BI_RGB;
+ biSizeImage = surface->h * surface->pitch;
+ biXPelsPerMeter = 0;
+ biYPelsPerMeter = 0;
+ if (surface->format->palette) {
+ biClrUsed = surface->format->palette->ncolors;
+ } else {
+ biClrUsed = 0;
+ }
+ biClrImportant = 0;
+
+ /* Set the BMP info values for the version 4 header */
+ if (save32bit && !saveLegacyBMP) {
+ biSize = 108;
+ biCompression = BI_BITFIELDS;
+ /* The BMP format is always little endian, these masks stay the same */
+ bV4RedMask = 0x00ff0000;
+ bV4GreenMask = 0x0000ff00;
+ bV4BlueMask = 0x000000ff;
+ bV4AlphaMask = 0xff000000;
+ bV4CSType = LCS_WINDOWS_COLOR_SPACE;
+ bV4GammaRed = 0;
+ bV4GammaGreen = 0;
+ bV4GammaBlue = 0;
+ }
+
+ /* Write the BMP info values */
+ SDL_WriteLE32(dst, biSize);
+ SDL_WriteLE32(dst, biWidth);
+ SDL_WriteLE32(dst, biHeight);
+ SDL_WriteLE16(dst, biPlanes);
+ SDL_WriteLE16(dst, biBitCount);
+ SDL_WriteLE32(dst, biCompression);
+ SDL_WriteLE32(dst, biSizeImage);
+ SDL_WriteLE32(dst, biXPelsPerMeter);
+ SDL_WriteLE32(dst, biYPelsPerMeter);
+ SDL_WriteLE32(dst, biClrUsed);
+ SDL_WriteLE32(dst, biClrImportant);
+
+ /* Write the BMP info values for the version 4 header */
+ if (save32bit && !saveLegacyBMP) {
+ SDL_WriteLE32(dst, bV4RedMask);
+ SDL_WriteLE32(dst, bV4GreenMask);
+ SDL_WriteLE32(dst, bV4BlueMask);
+ SDL_WriteLE32(dst, bV4AlphaMask);
+ SDL_WriteLE32(dst, bV4CSType);
+ for (i = 0; i < 3 * 3; i++) {
+ SDL_WriteLE32(dst, bV4Endpoints[i]);
+ }
+ SDL_WriteLE32(dst, bV4GammaRed);
+ SDL_WriteLE32(dst, bV4GammaGreen);
+ SDL_WriteLE32(dst, bV4GammaBlue);
+ }
+
+ /* Write the palette (in BGR color order) */
+ if (surface->format->palette) {
+ SDL_Color *colors;
+ int ncolors;
+
+ colors = surface->format->palette->colors;
+ ncolors = surface->format->palette->ncolors;
+ for (i = 0; i < ncolors; ++i) {
+ SDL_RWwrite(dst, &colors[i].b, 1, 1);
+ SDL_RWwrite(dst, &colors[i].g, 1, 1);
+ SDL_RWwrite(dst, &colors[i].r, 1, 1);
+ SDL_RWwrite(dst, &colors[i].a, 1, 1);
+ }
+ }
+
+ /* Write the bitmap offset */
+ bfOffBits = (Uint32)(SDL_RWtell(dst) - fp_offset);
+ if (SDL_RWseek(dst, fp_offset + 10, RW_SEEK_SET) < 0) {
+ SDL_Error(SDL_EFSEEK);
+ }
+ SDL_WriteLE32(dst, bfOffBits);
+ if (SDL_RWseek(dst, fp_offset + bfOffBits, RW_SEEK_SET) < 0) {
+ SDL_Error(SDL_EFSEEK);
+ }
+
+ /* Write the bitmap image upside down */
+ bits = (Uint8 *) surface->pixels + (surface->h * surface->pitch);
+ pad = ((bw % 4) ? (4 - (bw % 4)) : 0);
+ while (bits > (Uint8 *) surface->pixels) {
+ bits -= surface->pitch;
+ if (SDL_RWwrite(dst, bits, 1, bw) != bw) {
+ SDL_Error(SDL_EFWRITE);
+ break;
+ }
+ if (pad) {
+ const Uint8 padbyte = 0;
+ for (i = 0; i < pad; ++i) {
+ SDL_RWwrite(dst, &padbyte, 1, 1);
+ }
+ }
+ }
+
+ /* Write the BMP file size */
+ bfSize = (Uint32)(SDL_RWtell(dst) - fp_offset);
+ if (SDL_RWseek(dst, fp_offset + 2, RW_SEEK_SET) < 0) {
+ SDL_Error(SDL_EFSEEK);
+ }
+ SDL_WriteLE32(dst, bfSize);
+ if (SDL_RWseek(dst, fp_offset + bfSize, RW_SEEK_SET) < 0) {
+ SDL_Error(SDL_EFSEEK);
+ }
+
+ /* Close it up.. */
+ SDL_UnlockSurface(surface);
+ if (surface != saveme) {
+ SDL_FreeSurface(surface);
+ }
+ }
+
+ if (freedst && dst) {
+ SDL_RWclose(dst);
+ }
+ return ((SDL_strcmp(SDL_GetError(), "") == 0) ? 0 : -1);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_clipboard.c b/src/3rdparty/SDL2/src/video/SDL_clipboard.c
new file mode 100644
index 0000000..0dd6a05
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_clipboard.c
@@ -0,0 +1,90 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "SDL_clipboard.h"
+#include "SDL_sysvideo.h"
+
+
+int
+SDL_SetClipboardText(const char *text)
+{
+ SDL_VideoDevice *_this = SDL_GetVideoDevice();
+
+ if (!_this) {
+ return SDL_SetError("Video subsystem must be initialized to set clipboard text");
+ }
+
+ if (!text) {
+ text = "";
+ }
+ if (_this->SetClipboardText) {
+ return _this->SetClipboardText(_this, text);
+ } else {
+ SDL_free(_this->clipboard_text);
+ _this->clipboard_text = SDL_strdup(text);
+ return 0;
+ }
+}
+
+char *
+SDL_GetClipboardText(void)
+{
+ SDL_VideoDevice *_this = SDL_GetVideoDevice();
+
+ if (!_this) {
+ SDL_SetError("Video subsystem must be initialized to get clipboard text");
+ return SDL_strdup("");
+ }
+
+ if (_this->GetClipboardText) {
+ return _this->GetClipboardText(_this);
+ } else {
+ const char *text = _this->clipboard_text;
+ if (!text) {
+ text = "";
+ }
+ return SDL_strdup(text);
+ }
+}
+
+SDL_bool
+SDL_HasClipboardText(void)
+{
+ SDL_VideoDevice *_this = SDL_GetVideoDevice();
+
+ if (!_this) {
+ SDL_SetError("Video subsystem must be initialized to check clipboard text");
+ return SDL_FALSE;
+ }
+
+ if (_this->HasClipboardText) {
+ return _this->HasClipboardText(_this);
+ } else {
+ if (_this->clipboard_text && _this->clipboard_text[0] != '\0') {
+ return SDL_TRUE;
+ } else {
+ return SDL_FALSE;
+ }
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_egl.c b/src/3rdparty/SDL2/src/video/SDL_egl.c
new file mode 100644
index 0000000..0daf98a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_egl.c
@@ -0,0 +1,838 @@
+/*
+ * Simple DirectMedia Layer
+ * Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+#include "../SDL_internal.h"
+
+#if SDL_VIDEO_OPENGL_EGL
+
+#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
+#include "../core/windows/SDL_windows.h"
+#endif
+#if SDL_VIDEO_DRIVER_ANDROID
+#include <android/native_window.h>
+#endif
+
+#include "SDL_sysvideo.h"
+#include "SDL_log.h"
+#include "SDL_egl_c.h"
+#include "SDL_loadso.h"
+#include "SDL_hints.h"
+
+#ifdef EGL_KHR_create_context
+/* EGL_OPENGL_ES3_BIT_KHR was added in version 13 of the extension. */
+#ifndef EGL_OPENGL_ES3_BIT_KHR
+#define EGL_OPENGL_ES3_BIT_KHR 0x00000040
+#endif
+#endif /* EGL_KHR_create_context */
+
+#if SDL_VIDEO_DRIVER_RPI
+/* Raspbian places the OpenGL ES/EGL binaries in a non standard path */
+#define DEFAULT_EGL ( vc4 ? "libEGL.so.1" : "libbrcmEGL.so" )
+#define DEFAULT_OGL_ES2 ( vc4 ? "libGLESv2.so.2" : "libbrcmGLESv2.so" )
+#define ALT_EGL "libEGL.so"
+#define ALT_OGL_ES2 "libGLESv2.so"
+#define DEFAULT_OGL_ES_PVR ( vc4 ? "libGLES_CM.so.1" : "libbrcmGLESv2.so" )
+#define DEFAULT_OGL_ES ( vc4 ? "libGLESv1_CM.so.1" : "libbrcmGLESv2.so" )
+
+#elif SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_VIVANTE
+/* Android */
+#define DEFAULT_EGL "libEGL.so"
+#define DEFAULT_OGL_ES2 "libGLESv2.so"
+#define DEFAULT_OGL_ES_PVR "libGLES_CM.so"
+#define DEFAULT_OGL_ES "libGLESv1_CM.so"
+
+#elif SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
+/* EGL AND OpenGL ES support via ANGLE */
+#define DEFAULT_EGL "libEGL.dll"
+#define DEFAULT_OGL_ES2 "libGLESv2.dll"
+#define DEFAULT_OGL_ES_PVR "libGLES_CM.dll"
+#define DEFAULT_OGL_ES "libGLESv1_CM.dll"
+
+#elif SDL_VIDEO_DRIVER_COCOA
+/* EGL AND OpenGL ES support via ANGLE */
+#define DEFAULT_EGL "libEGL.dylib"
+#define DEFAULT_OGL_ES2 "libGLESv2.dylib"
+#define DEFAULT_OGL_ES_PVR "libGLES_CM.dylib" //???
+#define DEFAULT_OGL_ES "libGLESv1_CM.dylib" //???
+
+#else
+/* Desktop Linux */
+#define DEFAULT_OGL "libGL.so.1"
+#define DEFAULT_EGL "libEGL.so.1"
+#define DEFAULT_OGL_ES2 "libGLESv2.so.2"
+#define DEFAULT_OGL_ES_PVR "libGLES_CM.so.1"
+#define DEFAULT_OGL_ES "libGLESv1_CM.so.1"
+#endif /* SDL_VIDEO_DRIVER_RPI */
+
+#ifdef SDL_VIDEO_STATIC_ANGLE
+#define LOAD_FUNC(NAME) \
+_this->egl_data->NAME = (void *)NAME;
+#else
+#define LOAD_FUNC(NAME) \
+_this->egl_data->NAME = SDL_LoadFunction(_this->egl_data->dll_handle, #NAME); \
+if (!_this->egl_data->NAME) \
+{ \
+ return SDL_SetError("Could not retrieve EGL function " #NAME); \
+}
+#endif
+
+static const char * SDL_EGL_GetErrorName(EGLint eglErrorCode)
+{
+#define SDL_EGL_ERROR_TRANSLATE(e) case e: return #e;
+ switch (eglErrorCode) {
+ SDL_EGL_ERROR_TRANSLATE(EGL_SUCCESS);
+ SDL_EGL_ERROR_TRANSLATE(EGL_NOT_INITIALIZED);
+ SDL_EGL_ERROR_TRANSLATE(EGL_BAD_ACCESS);
+ SDL_EGL_ERROR_TRANSLATE(EGL_BAD_ALLOC);
+ SDL_EGL_ERROR_TRANSLATE(EGL_BAD_ATTRIBUTE);
+ SDL_EGL_ERROR_TRANSLATE(EGL_BAD_CONTEXT);
+ SDL_EGL_ERROR_TRANSLATE(EGL_BAD_CONFIG);
+ SDL_EGL_ERROR_TRANSLATE(EGL_BAD_CURRENT_SURFACE);
+ SDL_EGL_ERROR_TRANSLATE(EGL_BAD_DISPLAY);
+ SDL_EGL_ERROR_TRANSLATE(EGL_BAD_SURFACE);
+ SDL_EGL_ERROR_TRANSLATE(EGL_BAD_MATCH);
+ SDL_EGL_ERROR_TRANSLATE(EGL_BAD_PARAMETER);
+ SDL_EGL_ERROR_TRANSLATE(EGL_BAD_NATIVE_PIXMAP);
+ SDL_EGL_ERROR_TRANSLATE(EGL_BAD_NATIVE_WINDOW);
+ SDL_EGL_ERROR_TRANSLATE(EGL_CONTEXT_LOST);
+ }
+ return "";
+}
+
+int SDL_EGL_SetErrorEx(const char * message, const char * eglFunctionName, EGLint eglErrorCode)
+{
+ const char * errorText = SDL_EGL_GetErrorName(eglErrorCode);
+ char altErrorText[32];
+ if (errorText[0] == '\0') {
+ /* An unknown-to-SDL error code was reported. Report its hexadecimal value, instead of its name. */
+ SDL_snprintf(altErrorText, SDL_arraysize(altErrorText), "0x%x", (unsigned int)eglErrorCode);
+ errorText = altErrorText;
+ }
+ return SDL_SetError("%s (call to %s failed, reporting an error of %s)", message, eglFunctionName, errorText);
+}
+
+/* EGL implementation of SDL OpenGL ES support */
+typedef enum {
+ SDL_EGL_DISPLAY_EXTENSION,
+ SDL_EGL_CLIENT_EXTENSION
+} SDL_EGL_ExtensionType;
+
+static SDL_bool SDL_EGL_HasExtension(_THIS, SDL_EGL_ExtensionType type, const char *ext)
+{
+ size_t ext_len;
+ const char *ext_override;
+ const char *egl_extstr;
+ const char *ext_start;
+
+ /* Invalid extensions can be rejected early */
+ if (ext == NULL || *ext == 0 || SDL_strchr(ext, ' ') != NULL) {
+ /* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "SDL_EGL_HasExtension: Invalid EGL extension"); */
+ return SDL_FALSE;
+ }
+
+ /* Extensions can be masked with an environment variable.
+ * Unlike the OpenGL override, this will use the set bits of an integer
+ * to disable the extension.
+ * Bit Action
+ * 0 If set, the display extension is masked and not present to SDL.
+ * 1 If set, the client extension is masked and not present to SDL.
+ */
+ ext_override = SDL_getenv(ext);
+ if (ext_override != NULL) {
+ int disable_ext = SDL_atoi(ext_override);
+ if (disable_ext & 0x01 && type == SDL_EGL_DISPLAY_EXTENSION) {
+ return SDL_FALSE;
+ } else if (disable_ext & 0x02 && type == SDL_EGL_CLIENT_EXTENSION) {
+ return SDL_FALSE;
+ }
+ }
+
+ ext_len = SDL_strlen(ext);
+ switch (type) {
+ case SDL_EGL_DISPLAY_EXTENSION:
+ egl_extstr = _this->egl_data->eglQueryString(_this->egl_data->egl_display, EGL_EXTENSIONS);
+ break;
+ case SDL_EGL_CLIENT_EXTENSION:
+ /* EGL_EXT_client_extensions modifies eglQueryString to return client extensions
+ * if EGL_NO_DISPLAY is passed. Implementations without it are required to return NULL.
+ * This behavior is included in EGL 1.5.
+ */
+ egl_extstr = _this->egl_data->eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
+ break;
+ default:
+ /* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "SDL_EGL_HasExtension: Invalid extension type"); */
+ return SDL_FALSE;
+ }
+
+ if (egl_extstr != NULL) {
+ ext_start = egl_extstr;
+
+ while (*ext_start) {
+ ext_start = SDL_strstr(ext_start, ext);
+ if (ext_start == NULL) {
+ return SDL_FALSE;
+ }
+ /* Check if the match is not just a substring of one of the extensions */
+ if (ext_start == egl_extstr || *(ext_start - 1) == ' ') {
+ if (ext_start[ext_len] == ' ' || ext_start[ext_len] == 0) {
+ return SDL_TRUE;
+ }
+ }
+ /* If the search stopped in the middle of an extension, skip to the end of it */
+ ext_start += ext_len;
+ while (*ext_start != ' ' && *ext_start != 0) {
+ ext_start++;
+ }
+ }
+ }
+
+ return SDL_FALSE;
+}
+
+void *
+SDL_EGL_GetProcAddress(_THIS, const char *proc)
+{
+ static char procname[1024];
+ void *retval;
+
+ /* eglGetProcAddress is busted on Android http://code.google.com/p/android/issues/detail?id=7681 */
+#if !defined(SDL_VIDEO_DRIVER_ANDROID)
+ if (_this->egl_data->eglGetProcAddress) {
+ retval = _this->egl_data->eglGetProcAddress(proc);
+ if (retval) {
+ return retval;
+ }
+ }
+#endif
+
+ retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, proc);
+ if (!retval && SDL_strlen(proc) <= 1022) {
+ procname[0] = '_';
+ SDL_strlcpy(procname + 1, proc, 1022);
+ retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, procname);
+ }
+ return retval;
+}
+
+void
+SDL_EGL_UnloadLibrary(_THIS)
+{
+ if (_this->egl_data) {
+ if (_this->egl_data->egl_display) {
+ _this->egl_data->eglTerminate(_this->egl_data->egl_display);
+ _this->egl_data->egl_display = NULL;
+ }
+
+ if (_this->egl_data->dll_handle) {
+ SDL_UnloadObject(_this->egl_data->dll_handle);
+ _this->egl_data->dll_handle = NULL;
+ }
+ if (_this->egl_data->egl_dll_handle) {
+ SDL_UnloadObject(_this->egl_data->egl_dll_handle);
+ _this->egl_data->egl_dll_handle = NULL;
+ }
+
+ SDL_free(_this->egl_data);
+ _this->egl_data = NULL;
+ }
+}
+
+int
+SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_display, EGLenum platform)
+{
+ void *dll_handle = NULL, *egl_dll_handle = NULL; /* The naming is counter intuitive, but hey, I just work here -- Gabriel */
+ const char *path = NULL;
+ int egl_version_major = 0, egl_version_minor = 0;
+#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
+ const char *d3dcompiler;
+#endif
+#if SDL_VIDEO_DRIVER_RPI
+ SDL_bool vc4 = (0 == access("/sys/module/vc4/", F_OK));
+#endif
+
+ if (_this->egl_data) {
+ return SDL_SetError("EGL context already created");
+ }
+
+ _this->egl_data = (struct SDL_EGL_VideoData *) SDL_calloc(1, sizeof(SDL_EGL_VideoData));
+ if (!_this->egl_data) {
+ return SDL_OutOfMemory();
+ }
+
+#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
+ d3dcompiler = SDL_GetHint(SDL_HINT_VIDEO_WIN_D3DCOMPILER);
+ if (!d3dcompiler) {
+ if (WIN_IsWindowsVistaOrGreater()) {
+ d3dcompiler = "d3dcompiler_46.dll";
+ } else {
+ d3dcompiler = "d3dcompiler_43.dll";
+ }
+ }
+ if (SDL_strcasecmp(d3dcompiler, "none") != 0) {
+ if (SDL_LoadObject(d3dcompiler) == NULL) {
+ SDL_ClearError();
+ }
+ }
+#endif
+
+#ifndef SDL_VIDEO_STATIC_ANGLE
+ /* A funny thing, loading EGL.so first does not work on the Raspberry, so we load libGL* first */
+ path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
+ if (path != NULL) {
+ egl_dll_handle = SDL_LoadObject(path);
+ }
+
+ if (egl_dll_handle == NULL) {
+ if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
+ if (_this->gl_config.major_version > 1) {
+ path = DEFAULT_OGL_ES2;
+ egl_dll_handle = SDL_LoadObject(path);
+#ifdef ALT_OGL_ES2
+ if (egl_dll_handle == NULL && !vc4) {
+ path = ALT_OGL_ES2;
+ egl_dll_handle = SDL_LoadObject(path);
+ }
+#endif
+
+ } else {
+ path = DEFAULT_OGL_ES;
+ egl_dll_handle = SDL_LoadObject(path);
+ if (egl_dll_handle == NULL) {
+ path = DEFAULT_OGL_ES_PVR;
+ egl_dll_handle = SDL_LoadObject(path);
+ }
+#ifdef ALT_OGL_ES2
+ if (egl_dll_handle == NULL && !vc4) {
+ path = ALT_OGL_ES2;
+ egl_dll_handle = SDL_LoadObject(path);
+ }
+#endif
+ }
+ }
+#ifdef DEFAULT_OGL
+ else {
+ path = DEFAULT_OGL;
+ egl_dll_handle = SDL_LoadObject(path);
+ }
+#endif
+ }
+ _this->egl_data->egl_dll_handle = egl_dll_handle;
+
+ if (egl_dll_handle == NULL) {
+ return SDL_SetError("Could not initialize OpenGL / GLES library");
+ }
+
+ /* Loading libGL* in the previous step took care of loading libEGL.so, but we future proof by double checking */
+ if (egl_path != NULL) {
+ dll_handle = SDL_LoadObject(egl_path);
+ }
+ /* Try loading a EGL symbol, if it does not work try the default library paths */
+ if (dll_handle == NULL || SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) {
+ if (dll_handle != NULL) {
+ SDL_UnloadObject(dll_handle);
+ }
+ path = SDL_getenv("SDL_VIDEO_EGL_DRIVER");
+ if (path == NULL) {
+ path = DEFAULT_EGL;
+ }
+ dll_handle = SDL_LoadObject(path);
+
+#ifdef ALT_EGL
+ if (dll_handle == NULL && !vc4) {
+ path = ALT_EGL;
+ dll_handle = SDL_LoadObject(path);
+ }
+#endif
+
+ if (dll_handle == NULL || SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) {
+ if (dll_handle != NULL) {
+ SDL_UnloadObject(dll_handle);
+ }
+ return SDL_SetError("Could not load EGL library");
+ }
+ SDL_ClearError();
+ }
+#endif
+
+ _this->egl_data->dll_handle = dll_handle;
+
+ /* Load new function pointers */
+ LOAD_FUNC(eglGetDisplay);
+ LOAD_FUNC(eglInitialize);
+ LOAD_FUNC(eglTerminate);
+ LOAD_FUNC(eglGetProcAddress);
+ LOAD_FUNC(eglChooseConfig);
+ LOAD_FUNC(eglGetConfigAttrib);
+ LOAD_FUNC(eglCreateContext);
+ LOAD_FUNC(eglDestroyContext);
+ LOAD_FUNC(eglCreatePbufferSurface);
+ LOAD_FUNC(eglCreateWindowSurface);
+ LOAD_FUNC(eglDestroySurface);
+ LOAD_FUNC(eglMakeCurrent);
+ LOAD_FUNC(eglSwapBuffers);
+ LOAD_FUNC(eglSwapInterval);
+ LOAD_FUNC(eglWaitNative);
+ LOAD_FUNC(eglWaitGL);
+ LOAD_FUNC(eglBindAPI);
+ LOAD_FUNC(eglQueryString);
+ LOAD_FUNC(eglGetError);
+
+ if (_this->egl_data->eglQueryString) {
+ /* EGL 1.5 allows querying for client version */
+ const char *egl_version = _this->egl_data->eglQueryString(EGL_NO_DISPLAY, EGL_VERSION);
+ if (egl_version != NULL) {
+ if (SDL_sscanf(egl_version, "%d.%d", &egl_version_major, &egl_version_minor) != 2) {
+ egl_version_major = 0;
+ egl_version_minor = 0;
+ SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "Could not parse EGL version string: %s", egl_version);
+ }
+ }
+ }
+
+ if (egl_version_major == 1 && egl_version_minor == 5) {
+ LOAD_FUNC(eglGetPlatformDisplay);
+ }
+
+ _this->egl_data->egl_display = EGL_NO_DISPLAY;
+#if !defined(__WINRT__)
+ if (platform) {
+ if (egl_version_major == 1 && egl_version_minor == 5) {
+ _this->egl_data->egl_display = _this->egl_data->eglGetPlatformDisplay(platform, (void *)(size_t)native_display, NULL);
+ } else {
+ if (SDL_EGL_HasExtension(_this, SDL_EGL_CLIENT_EXTENSION, "EGL_EXT_platform_base")) {
+ _this->egl_data->eglGetPlatformDisplayEXT = SDL_EGL_GetProcAddress(_this, "eglGetPlatformDisplayEXT");
+ if (_this->egl_data->eglGetPlatformDisplayEXT) {
+ _this->egl_data->egl_display = _this->egl_data->eglGetPlatformDisplayEXT(platform, (void *)(size_t)native_display, NULL);
+ }
+ }
+ }
+ }
+ /* Try the implementation-specific eglGetDisplay even if eglGetPlatformDisplay fails */
+ if (_this->egl_data->egl_display == EGL_NO_DISPLAY) {
+ _this->egl_data->egl_display = _this->egl_data->eglGetDisplay(native_display);
+ }
+ if (_this->egl_data->egl_display == EGL_NO_DISPLAY) {
+ return SDL_SetError("Could not get EGL display");
+ }
+
+ if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
+ return SDL_SetError("Could not initialize EGL");
+ }
+#endif
+
+ if (path) {
+ SDL_strlcpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path) - 1);
+ } else {
+ *_this->gl_config.driver_path = '\0';
+ }
+
+ return 0;
+}
+
+int
+SDL_EGL_ChooseConfig(_THIS)
+{
+/* 64 seems nice. */
+ EGLint attribs[64];
+ EGLint found_configs = 0, value;
+#ifdef SDL_VIDEO_DRIVER_KMSDRM
+ /* Intel EGL on KMS/DRM (al least) returns invalid configs that confuse the bitdiff search used */
+ /* later in this function, so we simply use the first one when using the KMSDRM driver for now. */
+ EGLConfig configs[1];
+#else
+ /* 128 seems even nicer here */
+ EGLConfig configs[128];
+#endif
+ int i, j, best_bitdiff = -1, bitdiff;
+
+ if (!_this->egl_data) {
+ /* The EGL library wasn't loaded, SDL_GetError() should have info */
+ return -1;
+ }
+
+ /* Get a valid EGL configuration */
+ i = 0;
+ attribs[i++] = EGL_RED_SIZE;
+ attribs[i++] = _this->gl_config.red_size;
+ attribs[i++] = EGL_GREEN_SIZE;
+ attribs[i++] = _this->gl_config.green_size;
+ attribs[i++] = EGL_BLUE_SIZE;
+ attribs[i++] = _this->gl_config.blue_size;
+
+ if (_this->gl_config.alpha_size) {
+ attribs[i++] = EGL_ALPHA_SIZE;
+ attribs[i++] = _this->gl_config.alpha_size;
+ }
+
+ if (_this->gl_config.buffer_size) {
+ attribs[i++] = EGL_BUFFER_SIZE;
+ attribs[i++] = _this->gl_config.buffer_size;
+ }
+
+ attribs[i++] = EGL_DEPTH_SIZE;
+ attribs[i++] = _this->gl_config.depth_size;
+
+ if (_this->gl_config.stencil_size) {
+ attribs[i++] = EGL_STENCIL_SIZE;
+ attribs[i++] = _this->gl_config.stencil_size;
+ }
+
+ if (_this->gl_config.multisamplebuffers) {
+ attribs[i++] = EGL_SAMPLE_BUFFERS;
+ attribs[i++] = _this->gl_config.multisamplebuffers;
+ }
+
+ if (_this->gl_config.multisamplesamples) {
+ attribs[i++] = EGL_SAMPLES;
+ attribs[i++] = _this->gl_config.multisamplesamples;
+ }
+
+ attribs[i++] = EGL_RENDERABLE_TYPE;
+ if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
+#ifdef EGL_KHR_create_context
+ if (_this->gl_config.major_version >= 3 &&
+ SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_create_context")) {
+ attribs[i++] = EGL_OPENGL_ES3_BIT_KHR;
+ } else
+#endif
+ if (_this->gl_config.major_version >= 2) {
+ attribs[i++] = EGL_OPENGL_ES2_BIT;
+ } else {
+ attribs[i++] = EGL_OPENGL_ES_BIT;
+ }
+ _this->egl_data->eglBindAPI(EGL_OPENGL_ES_API);
+ } else {
+ attribs[i++] = EGL_OPENGL_BIT;
+ _this->egl_data->eglBindAPI(EGL_OPENGL_API);
+ }
+
+ if (_this->egl_data->egl_surfacetype) {
+ attribs[i++] = EGL_SURFACE_TYPE;
+ attribs[i++] = _this->egl_data->egl_surfacetype;
+ }
+
+ attribs[i++] = EGL_NONE;
+
+ if (_this->egl_data->eglChooseConfig(_this->egl_data->egl_display,
+ attribs,
+ configs, SDL_arraysize(configs),
+ &found_configs) == EGL_FALSE ||
+ found_configs == 0) {
+ return SDL_EGL_SetError("Couldn't find matching EGL config", "eglChooseConfig");
+ }
+
+ /* eglChooseConfig returns a number of configurations that match or exceed the requested attribs. */
+ /* From those, we select the one that matches our requirements more closely via a makeshift algorithm */
+
+ for (i = 0; i < found_configs; i++ ) {
+ bitdiff = 0;
+ for (j = 0; j < SDL_arraysize(attribs) - 1; j += 2) {
+ if (attribs[j] == EGL_NONE) {
+ break;
+ }
+
+ if ( attribs[j+1] != EGL_DONT_CARE && (
+ attribs[j] == EGL_RED_SIZE ||
+ attribs[j] == EGL_GREEN_SIZE ||
+ attribs[j] == EGL_BLUE_SIZE ||
+ attribs[j] == EGL_ALPHA_SIZE ||
+ attribs[j] == EGL_DEPTH_SIZE ||
+ attribs[j] == EGL_STENCIL_SIZE)) {
+ _this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display, configs[i], attribs[j], &value);
+ bitdiff += value - attribs[j + 1]; /* value is always >= attrib */
+ }
+ }
+
+ if (bitdiff < best_bitdiff || best_bitdiff == -1) {
+ _this->egl_data->egl_config = configs[i];
+
+ best_bitdiff = bitdiff;
+ }
+
+ if (bitdiff == 0) {
+ break; /* we found an exact match! */
+ }
+ }
+
+ return 0;
+}
+
+SDL_GLContext
+SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
+{
+ /* max 14 values plus terminator. */
+ EGLint attribs[15];
+ int attr = 0;
+
+ EGLContext egl_context, share_context = EGL_NO_CONTEXT;
+ EGLint profile_mask = _this->gl_config.profile_mask;
+ EGLint major_version = _this->gl_config.major_version;
+ EGLint minor_version = _this->gl_config.minor_version;
+ SDL_bool profile_es = (profile_mask == SDL_GL_CONTEXT_PROFILE_ES);
+
+ if (!_this->egl_data) {
+ /* The EGL library wasn't loaded, SDL_GetError() should have info */
+ return NULL;
+ }
+
+ if (_this->gl_config.share_with_current_context) {
+ share_context = (EGLContext)SDL_GL_GetCurrentContext();
+ }
+
+ /* Set the context version and other attributes. */
+ if ((major_version < 3 || (minor_version == 0 && profile_es)) &&
+ _this->gl_config.flags == 0 &&
+ (profile_mask == 0 || profile_es)) {
+ /* Create a context without using EGL_KHR_create_context attribs.
+ * When creating a GLES context without EGL_KHR_create_context we can
+ * only specify the major version. When creating a desktop GL context
+ * we can't specify any version, so we only try in that case when the
+ * version is less than 3.0 (matches SDL's GLX/WGL behavior.)
+ */
+ if (profile_es) {
+ attribs[attr++] = EGL_CONTEXT_CLIENT_VERSION;
+ attribs[attr++] = SDL_max(major_version, 1);
+ }
+ } else {
+#ifdef EGL_KHR_create_context
+ /* The Major/minor version, context profiles, and context flags can
+ * only be specified when this extension is available.
+ */
+ if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_create_context")) {
+ attribs[attr++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
+ attribs[attr++] = major_version;
+ attribs[attr++] = EGL_CONTEXT_MINOR_VERSION_KHR;
+ attribs[attr++] = minor_version;
+
+ /* SDL profile bits match EGL profile bits. */
+ if (profile_mask != 0 && profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
+ attribs[attr++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
+ attribs[attr++] = profile_mask;
+ }
+
+ /* SDL flags match EGL flags. */
+ if (_this->gl_config.flags != 0) {
+ attribs[attr++] = EGL_CONTEXT_FLAGS_KHR;
+ attribs[attr++] = _this->gl_config.flags;
+ }
+ } else
+#endif /* EGL_KHR_create_context */
+ {
+ SDL_SetError("Could not create EGL context (context attributes are not supported)");
+ return NULL;
+ }
+ }
+
+ if (_this->gl_config.no_error) {
+#ifdef EGL_KHR_create_context_no_error
+ if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_create_context_no_error")) {
+ attribs[attr++] = EGL_CONTEXT_OPENGL_NO_ERROR_KHR;
+ attribs[attr++] = _this->gl_config.no_error;
+ } else
+#endif
+ {
+ SDL_SetError("EGL implementation does not support no_error contexts");
+ return NULL;
+ }
+ }
+
+ attribs[attr++] = EGL_NONE;
+
+ /* Bind the API */
+ if (profile_es) {
+ _this->egl_data->eglBindAPI(EGL_OPENGL_ES_API);
+ } else {
+ _this->egl_data->eglBindAPI(EGL_OPENGL_API);
+ }
+
+ egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display,
+ _this->egl_data->egl_config,
+ share_context, attribs);
+
+ if (egl_context == EGL_NO_CONTEXT) {
+ SDL_EGL_SetError("Could not create EGL context", "eglCreateContext");
+ return NULL;
+ }
+
+ _this->egl_data->egl_swapinterval = 0;
+
+ if (SDL_EGL_MakeCurrent(_this, egl_surface, egl_context) < 0) {
+ /* Save the SDL error set by SDL_EGL_MakeCurrent */
+ char errorText[1024];
+ SDL_strlcpy(errorText, SDL_GetError(), SDL_arraysize(errorText));
+
+ /* Delete the context, which may alter the value returned by SDL_GetError() */
+ SDL_EGL_DeleteContext(_this, egl_context);
+
+ /* Restore the SDL error */
+ SDL_SetError("%s", errorText);
+
+ return NULL;
+ }
+
+ return (SDL_GLContext) egl_context;
+}
+
+int
+SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context)
+{
+ EGLContext egl_context = (EGLContext) context;
+
+ if (!_this->egl_data) {
+ return SDL_SetError("OpenGL not initialized");
+ }
+
+ /* The android emulator crashes badly if you try to eglMakeCurrent
+ * with a valid context and invalid surface, so we have to check for both here.
+ */
+ if (!egl_context || !egl_surface) {
+ _this->egl_data->eglMakeCurrent(_this->egl_data->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ } else {
+ if (!_this->egl_data->eglMakeCurrent(_this->egl_data->egl_display,
+ egl_surface, egl_surface, egl_context)) {
+ return SDL_EGL_SetError("Unable to make EGL context current", "eglMakeCurrent");
+ }
+ }
+
+ return 0;
+}
+
+int
+SDL_EGL_SetSwapInterval(_THIS, int interval)
+{
+ EGLBoolean status;
+
+ if (!_this->egl_data) {
+ return SDL_SetError("EGL not initialized");
+ }
+
+ status = _this->egl_data->eglSwapInterval(_this->egl_data->egl_display, interval);
+ if (status == EGL_TRUE) {
+ _this->egl_data->egl_swapinterval = interval;
+ return 0;
+ }
+
+ return SDL_EGL_SetError("Unable to set the EGL swap interval", "eglSwapInterval");
+}
+
+int
+SDL_EGL_GetSwapInterval(_THIS)
+{
+ if (!_this->egl_data) {
+ SDL_SetError("EGL not initialized");
+ return 0;
+ }
+
+ return _this->egl_data->egl_swapinterval;
+}
+
+int
+SDL_EGL_SwapBuffers(_THIS, EGLSurface egl_surface)
+{
+ if (!_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, egl_surface)) {
+ return SDL_EGL_SetError("unable to show color buffer in an OS-native window", "eglSwapBuffers");
+ }
+ return 0;
+}
+
+void
+SDL_EGL_DeleteContext(_THIS, SDL_GLContext context)
+{
+ EGLContext egl_context = (EGLContext) context;
+
+ /* Clean up GLES and EGL */
+ if (!_this->egl_data) {
+ return;
+ }
+
+ if (egl_context != NULL && egl_context != EGL_NO_CONTEXT) {
+ SDL_EGL_MakeCurrent(_this, NULL, NULL);
+ _this->egl_data->eglDestroyContext(_this->egl_data->egl_display, egl_context);
+ }
+
+}
+
+EGLSurface *
+SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
+{
+ /* max 2 values plus terminator. */
+ EGLint attribs[3];
+ int attr = 0;
+
+ EGLSurface * surface;
+
+ if (SDL_EGL_ChooseConfig(_this) != 0) {
+ return EGL_NO_SURFACE;
+ }
+
+#if SDL_VIDEO_DRIVER_ANDROID
+ {
+ /* Android docs recommend doing this!
+ * Ref: http://developer.android.com/reference/android/app/NativeActivity.html
+ */
+ EGLint format;
+ _this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display,
+ _this->egl_data->egl_config,
+ EGL_NATIVE_VISUAL_ID, &format);
+
+ ANativeWindow_setBuffersGeometry(nw, 0, 0, format);
+ }
+#endif
+ if (_this->gl_config.framebuffer_srgb_capable) {
+#ifdef EGL_KHR_gl_colorspace
+ if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_gl_colorspace")) {
+ attribs[attr++] = EGL_GL_COLORSPACE_KHR;
+ attribs[attr++] = EGL_GL_COLORSPACE_SRGB_KHR;
+ } else
+#endif
+ {
+ SDL_SetError("EGL implementation does not support sRGB system framebuffers");
+ return EGL_NO_SURFACE;
+ }
+ }
+
+ attribs[attr++] = EGL_NONE;
+
+ surface = _this->egl_data->eglCreateWindowSurface(
+ _this->egl_data->egl_display,
+ _this->egl_data->egl_config,
+ nw, &attribs[0]);
+ if (surface == EGL_NO_SURFACE) {
+ SDL_EGL_SetError("unable to create an EGL window surface", "eglCreateWindowSurface");
+ }
+ return surface;
+}
+
+void
+SDL_EGL_DestroySurface(_THIS, EGLSurface egl_surface)
+{
+ if (!_this->egl_data) {
+ return;
+ }
+
+ if (egl_surface != EGL_NO_SURFACE) {
+ _this->egl_data->eglDestroySurface(_this->egl_data->egl_display, egl_surface);
+ }
+}
+
+#endif /* SDL_VIDEO_OPENGL_EGL */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/video/SDL_egl_c.h b/src/3rdparty/SDL2/src/video/SDL_egl_c.h
new file mode 100644
index 0000000..80b1319
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_egl_c.h
@@ -0,0 +1,149 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#ifndef SDL_egl_h_
+#define SDL_egl_h_
+
+#if SDL_VIDEO_OPENGL_EGL
+
+#include "SDL_egl.h"
+
+#include "SDL_sysvideo.h"
+
+typedef struct SDL_EGL_VideoData
+{
+ void *egl_dll_handle, *dll_handle;
+ EGLDisplay egl_display;
+ EGLConfig egl_config;
+ int egl_swapinterval;
+ int egl_surfacetype;
+
+ EGLDisplay(EGLAPIENTRY *eglGetDisplay) (NativeDisplayType display);
+ EGLDisplay(EGLAPIENTRY *eglGetPlatformDisplay) (EGLenum platform,
+ void *native_display,
+ const EGLint *attrib_list);
+ EGLDisplay(EGLAPIENTRY *eglGetPlatformDisplayEXT) (EGLenum platform,
+ void *native_display,
+ const EGLint *attrib_list);
+ EGLBoolean(EGLAPIENTRY *eglInitialize) (EGLDisplay dpy, EGLint * major,
+ EGLint * minor);
+ EGLBoolean(EGLAPIENTRY *eglTerminate) (EGLDisplay dpy);
+
+ void *(EGLAPIENTRY *eglGetProcAddress) (const char * procName);
+
+ EGLBoolean(EGLAPIENTRY *eglChooseConfig) (EGLDisplay dpy,
+ const EGLint * attrib_list,
+ EGLConfig * configs,
+ EGLint config_size, EGLint * num_config);
+
+ EGLContext(EGLAPIENTRY *eglCreateContext) (EGLDisplay dpy,
+ EGLConfig config,
+ EGLContext share_list,
+ const EGLint * attrib_list);
+
+ EGLBoolean(EGLAPIENTRY *eglDestroyContext) (EGLDisplay dpy, EGLContext ctx);
+
+ EGLSurface(EGLAPIENTRY *eglCreatePbufferSurface)(EGLDisplay dpy, EGLConfig config,
+ EGLint const* attrib_list);
+
+ EGLSurface(EGLAPIENTRY *eglCreateWindowSurface) (EGLDisplay dpy,
+ EGLConfig config,
+ NativeWindowType window,
+ const EGLint * attrib_list);
+ EGLBoolean(EGLAPIENTRY *eglDestroySurface) (EGLDisplay dpy, EGLSurface surface);
+
+ EGLBoolean(EGLAPIENTRY *eglMakeCurrent) (EGLDisplay dpy, EGLSurface draw,
+ EGLSurface read, EGLContext ctx);
+
+ EGLBoolean(EGLAPIENTRY *eglSwapBuffers) (EGLDisplay dpy, EGLSurface draw);
+
+ EGLBoolean(EGLAPIENTRY *eglSwapInterval) (EGLDisplay dpy, EGLint interval);
+
+ const char *(EGLAPIENTRY *eglQueryString) (EGLDisplay dpy, EGLint name);
+
+ EGLBoolean(EGLAPIENTRY *eglGetConfigAttrib) (EGLDisplay dpy, EGLConfig config,
+ EGLint attribute, EGLint * value);
+
+ EGLBoolean(EGLAPIENTRY *eglWaitNative) (EGLint engine);
+
+ EGLBoolean(EGLAPIENTRY *eglWaitGL)(void);
+
+ EGLBoolean(EGLAPIENTRY *eglBindAPI)(EGLenum);
+
+ EGLint(EGLAPIENTRY *eglGetError)(void);
+
+} SDL_EGL_VideoData;
+
+/* OpenGLES functions */
+extern int SDL_EGL_GetAttribute(_THIS, SDL_GLattr attrib, int *value);
+/* SDL_EGL_LoadLibrary can get a display for a specific platform (EGL_PLATFORM_*)
+ * or, if 0 is passed, let the implementation decide.
+ */
+extern int SDL_EGL_LoadLibrary(_THIS, const char *path, NativeDisplayType native_display, EGLenum platform);
+extern void *SDL_EGL_GetProcAddress(_THIS, const char *proc);
+extern void SDL_EGL_UnloadLibrary(_THIS);
+extern int SDL_EGL_ChooseConfig(_THIS);
+extern int SDL_EGL_SetSwapInterval(_THIS, int interval);
+extern int SDL_EGL_GetSwapInterval(_THIS);
+extern void SDL_EGL_DeleteContext(_THIS, SDL_GLContext context);
+extern EGLSurface *SDL_EGL_CreateSurface(_THIS, NativeWindowType nw);
+extern void SDL_EGL_DestroySurface(_THIS, EGLSurface egl_surface);
+
+/* These need to be wrapped to get the surface for the window by the platform GLES implementation */
+extern SDL_GLContext SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface);
+extern int SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context);
+extern int SDL_EGL_SwapBuffers(_THIS, EGLSurface egl_surface);
+
+/* SDL Error-reporting */
+extern int SDL_EGL_SetErrorEx(const char * message, const char * eglFunctionName, EGLint eglErrorCode);
+#define SDL_EGL_SetError(message, eglFunctionName) SDL_EGL_SetErrorEx(message, eglFunctionName, _this->egl_data->eglGetError())
+
+/* A few of useful macros */
+
+#define SDL_EGL_SwapWindow_impl(BACKEND) int \
+BACKEND ## _GLES_SwapWindow(_THIS, SDL_Window * window) \
+{\
+ return SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);\
+}
+
+#define SDL_EGL_MakeCurrent_impl(BACKEND) int \
+BACKEND ## _GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) \
+{\
+ if (window && context) { \
+ return SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context); \
+ }\
+ else {\
+ return SDL_EGL_MakeCurrent(_this, NULL, NULL);\
+ }\
+}
+
+#define SDL_EGL_CreateContext_impl(BACKEND) SDL_GLContext \
+BACKEND ## _GLES_CreateContext(_THIS, SDL_Window * window) \
+{\
+ return SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);\
+}
+
+#endif /* SDL_VIDEO_OPENGL_EGL */
+
+#endif /* SDL_egl_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_fillrect.c b/src/3rdparty/SDL2/src/video/SDL_fillrect.c
new file mode 100644
index 0000000..63f5fcb
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_fillrect.c
@@ -0,0 +1,343 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "SDL_video.h"
+#include "SDL_blit.h"
+
+
+#ifdef __SSE__
+/* *INDENT-OFF* */
+
+#ifdef _MSC_VER
+#define SSE_BEGIN \
+ __m128 c128; \
+ c128.m128_u32[0] = color; \
+ c128.m128_u32[1] = color; \
+ c128.m128_u32[2] = color; \
+ c128.m128_u32[3] = color;
+#else
+#define SSE_BEGIN \
+ __m128 c128; \
+ DECLARE_ALIGNED(Uint32, cccc[4], 16); \
+ cccc[0] = color; \
+ cccc[1] = color; \
+ cccc[2] = color; \
+ cccc[3] = color; \
+ c128 = *(__m128 *)cccc;
+#endif
+
+#define SSE_WORK \
+ for (i = n / 64; i--;) { \
+ _mm_stream_ps((float *)(p+0), c128); \
+ _mm_stream_ps((float *)(p+16), c128); \
+ _mm_stream_ps((float *)(p+32), c128); \
+ _mm_stream_ps((float *)(p+48), c128); \
+ p += 64; \
+ }
+
+#define SSE_END
+
+#define DEFINE_SSE_FILLRECT(bpp, type) \
+static void \
+SDL_FillRect##bpp##SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h) \
+{ \
+ int i, n; \
+ Uint8 *p = NULL; \
+ \
+ SSE_BEGIN; \
+ \
+ while (h--) { \
+ n = w * bpp; \
+ p = pixels; \
+ \
+ if (n > 63) { \
+ int adjust = 16 - ((uintptr_t)p & 15); \
+ if (adjust < 16) { \
+ n -= adjust; \
+ adjust /= bpp; \
+ while (adjust--) { \
+ *((type *)p) = (type)color; \
+ p += bpp; \
+ } \
+ } \
+ SSE_WORK; \
+ } \
+ if (n & 63) { \
+ int remainder = (n & 63); \
+ remainder /= bpp; \
+ while (remainder--) { \
+ *((type *)p) = (type)color; \
+ p += bpp; \
+ } \
+ } \
+ pixels += pitch; \
+ } \
+ \
+ SSE_END; \
+}
+
+static void
+SDL_FillRect1SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
+{
+ int i, n;
+
+ SSE_BEGIN;
+ while (h--) {
+ Uint8 *p = pixels;
+ n = w;
+
+ if (n > 63) {
+ int adjust = 16 - ((uintptr_t)p & 15);
+ if (adjust) {
+ n -= adjust;
+ SDL_memset(p, color, adjust);
+ p += adjust;
+ }
+ SSE_WORK;
+ }
+ if (n & 63) {
+ int remainder = (n & 63);
+ SDL_memset(p, color, remainder);
+ }
+ pixels += pitch;
+ }
+
+ SSE_END;
+}
+/* DEFINE_SSE_FILLRECT(1, Uint8) */
+DEFINE_SSE_FILLRECT(2, Uint16)
+DEFINE_SSE_FILLRECT(4, Uint32)
+
+/* *INDENT-ON* */
+#endif /* __SSE__ */
+
+static void
+SDL_FillRect1(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
+{
+ int n;
+ Uint8 *p = NULL;
+
+ while (h--) {
+ n = w;
+ p = pixels;
+
+ if (n > 3) {
+ switch ((uintptr_t) p & 3) {
+ case 1:
+ *p++ = (Uint8) color;
+ --n; /* fallthrough */
+ case 2:
+ *p++ = (Uint8) color;
+ --n; /* fallthrough */
+ case 3:
+ *p++ = (Uint8) color;
+ --n; /* fallthrough */
+ }
+ SDL_memset4(p, color, (n >> 2));
+ }
+ if (n & 3) {
+ p += (n & ~3);
+ switch (n & 3) {
+ case 3:
+ *p++ = (Uint8) color; /* fallthrough */
+ case 2:
+ *p++ = (Uint8) color; /* fallthrough */
+ case 1:
+ *p++ = (Uint8) color; /* fallthrough */
+ }
+ }
+ pixels += pitch;
+ }
+}
+
+static void
+SDL_FillRect2(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
+{
+ int n;
+ Uint16 *p = NULL;
+
+ while (h--) {
+ n = w;
+ p = (Uint16 *) pixels;
+
+ if (n > 1) {
+ if ((uintptr_t) p & 2) {
+ *p++ = (Uint16) color;
+ --n;
+ }
+ SDL_memset4(p, color, (n >> 1));
+ }
+ if (n & 1) {
+ p[n - 1] = (Uint16) color;
+ }
+ pixels += pitch;
+ }
+}
+
+static void
+SDL_FillRect3(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
+{
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+ Uint8 b1 = (Uint8) (color & 0xFF);
+ Uint8 b2 = (Uint8) ((color >> 8) & 0xFF);
+ Uint8 b3 = (Uint8) ((color >> 16) & 0xFF);
+#elif SDL_BYTEORDER == SDL_BIG_ENDIAN
+ Uint8 b1 = (Uint8) ((color >> 16) & 0xFF);
+ Uint8 b2 = (Uint8) ((color >> 8) & 0xFF);
+ Uint8 b3 = (Uint8) (color & 0xFF);
+#endif
+ int n;
+ Uint8 *p = NULL;
+
+ while (h--) {
+ n = w;
+ p = pixels;
+
+ while (n--) {
+ *p++ = b1;
+ *p++ = b2;
+ *p++ = b3;
+ }
+ pixels += pitch;
+ }
+}
+
+static void
+SDL_FillRect4(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
+{
+ while (h--) {
+ SDL_memset4(pixels, color, w);
+ pixels += pitch;
+ }
+}
+
+/*
+ * This function performs a fast fill of the given rectangle with 'color'
+ */
+int
+SDL_FillRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color)
+{
+ SDL_Rect clipped;
+ Uint8 *pixels;
+
+ if (!dst) {
+ return SDL_SetError("Passed NULL destination surface");
+ }
+
+ /* This function doesn't work on surfaces < 8 bpp */
+ if (dst->format->BitsPerPixel < 8) {
+ return SDL_SetError("SDL_FillRect(): Unsupported surface format");
+ }
+
+ /* If 'rect' == NULL, then fill the whole surface */
+ if (rect) {
+ /* Perform clipping */
+ if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
+ return 0;
+ }
+ rect = &clipped;
+ } else {
+ rect = &dst->clip_rect;
+ /* Don't attempt to fill if the surface's clip_rect is empty */
+ if (SDL_RectEmpty(rect)) {
+ return 0;
+ }
+ }
+
+ /* Perform software fill */
+ if (!dst->pixels) {
+ return SDL_SetError("SDL_FillRect(): You must lock the surface");
+ }
+
+ pixels = (Uint8 *) dst->pixels + rect->y * dst->pitch +
+ rect->x * dst->format->BytesPerPixel;
+
+ switch (dst->format->BytesPerPixel) {
+ case 1:
+ {
+ color |= (color << 8);
+ color |= (color << 16);
+#ifdef __SSE__
+ if (SDL_HasSSE()) {
+ SDL_FillRect1SSE(pixels, dst->pitch, color, rect->w, rect->h);
+ break;
+ }
+#endif
+ SDL_FillRect1(pixels, dst->pitch, color, rect->w, rect->h);
+ break;
+ }
+
+ case 2:
+ {
+ color |= (color << 16);
+#ifdef __SSE__
+ if (SDL_HasSSE()) {
+ SDL_FillRect2SSE(pixels, dst->pitch, color, rect->w, rect->h);
+ break;
+ }
+#endif
+ SDL_FillRect2(pixels, dst->pitch, color, rect->w, rect->h);
+ break;
+ }
+
+ case 3:
+ /* 24-bit RGB is a slow path, at least for now. */
+ {
+ SDL_FillRect3(pixels, dst->pitch, color, rect->w, rect->h);
+ break;
+ }
+
+ case 4:
+ {
+#ifdef __SSE__
+ if (SDL_HasSSE()) {
+ SDL_FillRect4SSE(pixels, dst->pitch, color, rect->w, rect->h);
+ break;
+ }
+#endif
+ SDL_FillRect4(pixels, dst->pitch, color, rect->w, rect->h);
+ break;
+ }
+ }
+
+ /* We're done! */
+ return 0;
+}
+
+int
+SDL_FillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
+ Uint32 color)
+{
+ int i;
+ int status = 0;
+
+ if (!rects) {
+ return SDL_SetError("SDL_FillRects() passed NULL rects");
+ }
+
+ for (i = 0; i < count; ++i) {
+ status += SDL_FillRect(dst, &rects[i], color);
+ }
+ return status;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_pixels.c b/src/3rdparty/SDL2/src/video/SDL_pixels.c
new file mode 100644
index 0000000..2e26395
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_pixels.c
@@ -0,0 +1,1125 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* General (mostly internal) pixel/color manipulation routines for SDL */
+
+#include "SDL_endian.h"
+#include "SDL_video.h"
+#include "SDL_sysvideo.h"
+#include "SDL_blit.h"
+#include "SDL_pixels_c.h"
+#include "SDL_RLEaccel_c.h"
+
+
+/* Lookup tables to expand partial bytes to the full 0..255 range */
+
+static Uint8 lookup_0[] = {
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
+};
+
+static Uint8 lookup_1[] = {
+0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 255
+};
+
+static Uint8 lookup_2[] = {
+0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, 129, 133, 137, 141, 145, 149, 153, 157, 161, 165, 170, 174, 178, 182, 186, 190, 194, 198, 202, 206, 210, 214, 218, 222, 226, 230, 234, 238, 242, 246, 250, 255
+};
+
+static Uint8 lookup_3[] = {
+0, 8, 16, 24, 32, 41, 49, 57, 65, 74, 82, 90, 98, 106, 115, 123, 131, 139, 148, 156, 164, 172, 180, 189, 197, 205, 213, 222, 230, 238, 246, 255
+};
+
+static Uint8 lookup_4[] = {
+0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255
+};
+
+static Uint8 lookup_5[] = {
+0, 36, 72, 109, 145, 182, 218, 255
+};
+
+static Uint8 lookup_6[] = {
+0, 85, 170, 255
+};
+
+static Uint8 lookup_7[] = {
+0, 255
+};
+
+static Uint8 lookup_8[] = {
+255
+};
+
+Uint8* SDL_expand_byte[9] = {
+ lookup_0,
+ lookup_1,
+ lookup_2,
+ lookup_3,
+ lookup_4,
+ lookup_5,
+ lookup_6,
+ lookup_7,
+ lookup_8
+};
+
+/* Helper functions */
+
+const char*
+SDL_GetPixelFormatName(Uint32 format)
+{
+ switch (format) {
+#define CASE(X) case X: return #X;
+ CASE(SDL_PIXELFORMAT_INDEX1LSB)
+ CASE(SDL_PIXELFORMAT_INDEX1MSB)
+ CASE(SDL_PIXELFORMAT_INDEX4LSB)
+ CASE(SDL_PIXELFORMAT_INDEX4MSB)
+ CASE(SDL_PIXELFORMAT_INDEX8)
+ CASE(SDL_PIXELFORMAT_RGB332)
+ CASE(SDL_PIXELFORMAT_RGB444)
+ CASE(SDL_PIXELFORMAT_RGB555)
+ CASE(SDL_PIXELFORMAT_BGR555)
+ CASE(SDL_PIXELFORMAT_ARGB4444)
+ CASE(SDL_PIXELFORMAT_RGBA4444)
+ CASE(SDL_PIXELFORMAT_ABGR4444)
+ CASE(SDL_PIXELFORMAT_BGRA4444)
+ CASE(SDL_PIXELFORMAT_ARGB1555)
+ CASE(SDL_PIXELFORMAT_RGBA5551)
+ CASE(SDL_PIXELFORMAT_ABGR1555)
+ CASE(SDL_PIXELFORMAT_BGRA5551)
+ CASE(SDL_PIXELFORMAT_RGB565)
+ CASE(SDL_PIXELFORMAT_BGR565)
+ CASE(SDL_PIXELFORMAT_RGB24)
+ CASE(SDL_PIXELFORMAT_BGR24)
+ CASE(SDL_PIXELFORMAT_RGB888)
+ CASE(SDL_PIXELFORMAT_RGBX8888)
+ CASE(SDL_PIXELFORMAT_BGR888)
+ CASE(SDL_PIXELFORMAT_BGRX8888)
+ CASE(SDL_PIXELFORMAT_ARGB8888)
+ CASE(SDL_PIXELFORMAT_RGBA8888)
+ CASE(SDL_PIXELFORMAT_ABGR8888)
+ CASE(SDL_PIXELFORMAT_BGRA8888)
+ CASE(SDL_PIXELFORMAT_ARGB2101010)
+ CASE(SDL_PIXELFORMAT_YV12)
+ CASE(SDL_PIXELFORMAT_IYUV)
+ CASE(SDL_PIXELFORMAT_YUY2)
+ CASE(SDL_PIXELFORMAT_UYVY)
+ CASE(SDL_PIXELFORMAT_YVYU)
+ CASE(SDL_PIXELFORMAT_NV12)
+ CASE(SDL_PIXELFORMAT_NV21)
+#undef CASE
+ default:
+ return "SDL_PIXELFORMAT_UNKNOWN";
+ }
+}
+
+SDL_bool
+SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 * Rmask,
+ Uint32 * Gmask, Uint32 * Bmask, Uint32 * Amask)
+{
+ Uint32 masks[4];
+
+ /* This function doesn't work with FourCC pixel formats */
+ if (SDL_ISPIXELFORMAT_FOURCC(format)) {
+ SDL_SetError("FOURCC pixel formats are not supported");
+ return SDL_FALSE;
+ }
+
+ /* Initialize the values here */
+ if (SDL_BYTESPERPIXEL(format) <= 2) {
+ *bpp = SDL_BITSPERPIXEL(format);
+ } else {
+ *bpp = SDL_BYTESPERPIXEL(format) * 8;
+ }
+ *Rmask = *Gmask = *Bmask = *Amask = 0;
+
+ if (format == SDL_PIXELFORMAT_RGB24) {
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ *Rmask = 0x00FF0000;
+ *Gmask = 0x0000FF00;
+ *Bmask = 0x000000FF;
+#else
+ *Rmask = 0x000000FF;
+ *Gmask = 0x0000FF00;
+ *Bmask = 0x00FF0000;
+#endif
+ return SDL_TRUE;
+ }
+
+ if (format == SDL_PIXELFORMAT_BGR24) {
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ *Rmask = 0x000000FF;
+ *Gmask = 0x0000FF00;
+ *Bmask = 0x00FF0000;
+#else
+ *Rmask = 0x00FF0000;
+ *Gmask = 0x0000FF00;
+ *Bmask = 0x000000FF;
+#endif
+ return SDL_TRUE;
+ }
+
+ if (SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED8 &&
+ SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED16 &&
+ SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED32) {
+ /* Not a format that uses masks */
+ return SDL_TRUE;
+ }
+
+ switch (SDL_PIXELLAYOUT(format)) {
+ case SDL_PACKEDLAYOUT_332:
+ masks[0] = 0x00000000;
+ masks[1] = 0x000000E0;
+ masks[2] = 0x0000001C;
+ masks[3] = 0x00000003;
+ break;
+ case SDL_PACKEDLAYOUT_4444:
+ masks[0] = 0x0000F000;
+ masks[1] = 0x00000F00;
+ masks[2] = 0x000000F0;
+ masks[3] = 0x0000000F;
+ break;
+ case SDL_PACKEDLAYOUT_1555:
+ masks[0] = 0x00008000;
+ masks[1] = 0x00007C00;
+ masks[2] = 0x000003E0;
+ masks[3] = 0x0000001F;
+ break;
+ case SDL_PACKEDLAYOUT_5551:
+ masks[0] = 0x0000F800;
+ masks[1] = 0x000007C0;
+ masks[2] = 0x0000003E;
+ masks[3] = 0x00000001;
+ break;
+ case SDL_PACKEDLAYOUT_565:
+ masks[0] = 0x00000000;
+ masks[1] = 0x0000F800;
+ masks[2] = 0x000007E0;
+ masks[3] = 0x0000001F;
+ break;
+ case SDL_PACKEDLAYOUT_8888:
+ masks[0] = 0xFF000000;
+ masks[1] = 0x00FF0000;
+ masks[2] = 0x0000FF00;
+ masks[3] = 0x000000FF;
+ break;
+ case SDL_PACKEDLAYOUT_2101010:
+ masks[0] = 0xC0000000;
+ masks[1] = 0x3FF00000;
+ masks[2] = 0x000FFC00;
+ masks[3] = 0x000003FF;
+ break;
+ case SDL_PACKEDLAYOUT_1010102:
+ masks[0] = 0xFFC00000;
+ masks[1] = 0x003FF000;
+ masks[2] = 0x00000FFC;
+ masks[3] = 0x00000003;
+ break;
+ default:
+ SDL_SetError("Unknown pixel format");
+ return SDL_FALSE;
+ }
+
+ switch (SDL_PIXELORDER(format)) {
+ case SDL_PACKEDORDER_XRGB:
+ *Rmask = masks[1];
+ *Gmask = masks[2];
+ *Bmask = masks[3];
+ break;
+ case SDL_PACKEDORDER_RGBX:
+ *Rmask = masks[0];
+ *Gmask = masks[1];
+ *Bmask = masks[2];
+ break;
+ case SDL_PACKEDORDER_ARGB:
+ *Amask = masks[0];
+ *Rmask = masks[1];
+ *Gmask = masks[2];
+ *Bmask = masks[3];
+ break;
+ case SDL_PACKEDORDER_RGBA:
+ *Rmask = masks[0];
+ *Gmask = masks[1];
+ *Bmask = masks[2];
+ *Amask = masks[3];
+ break;
+ case SDL_PACKEDORDER_XBGR:
+ *Bmask = masks[1];
+ *Gmask = masks[2];
+ *Rmask = masks[3];
+ break;
+ case SDL_PACKEDORDER_BGRX:
+ *Bmask = masks[0];
+ *Gmask = masks[1];
+ *Rmask = masks[2];
+ break;
+ case SDL_PACKEDORDER_BGRA:
+ *Bmask = masks[0];
+ *Gmask = masks[1];
+ *Rmask = masks[2];
+ *Amask = masks[3];
+ break;
+ case SDL_PACKEDORDER_ABGR:
+ *Amask = masks[0];
+ *Bmask = masks[1];
+ *Gmask = masks[2];
+ *Rmask = masks[3];
+ break;
+ default:
+ SDL_SetError("Unknown pixel format");
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
+}
+
+Uint32
+SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask,
+ Uint32 Amask)
+{
+ switch (bpp) {
+ case 1:
+ /* SDL defaults to MSB ordering */
+ return SDL_PIXELFORMAT_INDEX1MSB;
+ case 4:
+ /* SDL defaults to MSB ordering */
+ return SDL_PIXELFORMAT_INDEX4MSB;
+ case 8:
+ if (Rmask == 0) {
+ return SDL_PIXELFORMAT_INDEX8;
+ }
+ if (Rmask == 0xE0 &&
+ Gmask == 0x1C &&
+ Bmask == 0x03 &&
+ Amask == 0x00) {
+ return SDL_PIXELFORMAT_RGB332;
+ }
+ break;
+ case 12:
+ if (Rmask == 0) {
+ return SDL_PIXELFORMAT_RGB444;
+ }
+ if (Rmask == 0x0F00 &&
+ Gmask == 0x00F0 &&
+ Bmask == 0x000F &&
+ Amask == 0x0000) {
+ return SDL_PIXELFORMAT_RGB444;
+ }
+ break;
+ case 15:
+ if (Rmask == 0) {
+ return SDL_PIXELFORMAT_RGB555;
+ }
+ /* fallthrough */
+ case 16:
+ if (Rmask == 0) {
+ return SDL_PIXELFORMAT_RGB565;
+ }
+ if (Rmask == 0x7C00 &&
+ Gmask == 0x03E0 &&
+ Bmask == 0x001F &&
+ Amask == 0x0000) {
+ return SDL_PIXELFORMAT_RGB555;
+ }
+ if (Rmask == 0x001F &&
+ Gmask == 0x03E0 &&
+ Bmask == 0x7C00 &&
+ Amask == 0x0000) {
+ return SDL_PIXELFORMAT_BGR555;
+ }
+ if (Rmask == 0x0F00 &&
+ Gmask == 0x00F0 &&
+ Bmask == 0x000F &&
+ Amask == 0xF000) {
+ return SDL_PIXELFORMAT_ARGB4444;
+ }
+ if (Rmask == 0xF000 &&
+ Gmask == 0x0F00 &&
+ Bmask == 0x00F0 &&
+ Amask == 0x000F) {
+ return SDL_PIXELFORMAT_RGBA4444;
+ }
+ if (Rmask == 0x000F &&
+ Gmask == 0x00F0 &&
+ Bmask == 0x0F00 &&
+ Amask == 0xF000) {
+ return SDL_PIXELFORMAT_ABGR4444;
+ }
+ if (Rmask == 0x00F0 &&
+ Gmask == 0x0F00 &&
+ Bmask == 0xF000 &&
+ Amask == 0x000F) {
+ return SDL_PIXELFORMAT_BGRA4444;
+ }
+ if (Rmask == 0x7C00 &&
+ Gmask == 0x03E0 &&
+ Bmask == 0x001F &&
+ Amask == 0x8000) {
+ return SDL_PIXELFORMAT_ARGB1555;
+ }
+ if (Rmask == 0xF800 &&
+ Gmask == 0x07C0 &&
+ Bmask == 0x003E &&
+ Amask == 0x0001) {
+ return SDL_PIXELFORMAT_RGBA5551;
+ }
+ if (Rmask == 0x001F &&
+ Gmask == 0x03E0 &&
+ Bmask == 0x7C00 &&
+ Amask == 0x8000) {
+ return SDL_PIXELFORMAT_ABGR1555;
+ }
+ if (Rmask == 0x003E &&
+ Gmask == 0x07C0 &&
+ Bmask == 0xF800 &&
+ Amask == 0x0001) {
+ return SDL_PIXELFORMAT_BGRA5551;
+ }
+ if (Rmask == 0xF800 &&
+ Gmask == 0x07E0 &&
+ Bmask == 0x001F &&
+ Amask == 0x0000) {
+ return SDL_PIXELFORMAT_RGB565;
+ }
+ if (Rmask == 0x001F &&
+ Gmask == 0x07E0 &&
+ Bmask == 0xF800 &&
+ Amask == 0x0000) {
+ return SDL_PIXELFORMAT_BGR565;
+ }
+ if (Rmask == 0x003F &&
+ Gmask == 0x07C0 &&
+ Bmask == 0xF800 &&
+ Amask == 0x0000) {
+ /* Technically this would be BGR556, but Witek says this works in bug 3158 */
+ return SDL_PIXELFORMAT_RGB565;
+ }
+ break;
+ case 24:
+ switch (Rmask) {
+ case 0:
+ case 0x00FF0000:
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ return SDL_PIXELFORMAT_RGB24;
+#else
+ return SDL_PIXELFORMAT_BGR24;
+#endif
+ case 0x000000FF:
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ return SDL_PIXELFORMAT_BGR24;
+#else
+ return SDL_PIXELFORMAT_RGB24;
+#endif
+ }
+ case 32:
+ if (Rmask == 0) {
+ return SDL_PIXELFORMAT_RGB888;
+ }
+ if (Rmask == 0x00FF0000 &&
+ Gmask == 0x0000FF00 &&
+ Bmask == 0x000000FF &&
+ Amask == 0x00000000) {
+ return SDL_PIXELFORMAT_RGB888;
+ }
+ if (Rmask == 0xFF000000 &&
+ Gmask == 0x00FF0000 &&
+ Bmask == 0x0000FF00 &&
+ Amask == 0x00000000) {
+ return SDL_PIXELFORMAT_RGBX8888;
+ }
+ if (Rmask == 0x000000FF &&
+ Gmask == 0x0000FF00 &&
+ Bmask == 0x00FF0000 &&
+ Amask == 0x00000000) {
+ return SDL_PIXELFORMAT_BGR888;
+ }
+ if (Rmask == 0x0000FF00 &&
+ Gmask == 0x00FF0000 &&
+ Bmask == 0xFF000000 &&
+ Amask == 0x00000000) {
+ return SDL_PIXELFORMAT_BGRX8888;
+ }
+ if (Rmask == 0x00FF0000 &&
+ Gmask == 0x0000FF00 &&
+ Bmask == 0x000000FF &&
+ Amask == 0xFF000000) {
+ return SDL_PIXELFORMAT_ARGB8888;
+ }
+ if (Rmask == 0xFF000000 &&
+ Gmask == 0x00FF0000 &&
+ Bmask == 0x0000FF00 &&
+ Amask == 0x000000FF) {
+ return SDL_PIXELFORMAT_RGBA8888;
+ }
+ if (Rmask == 0x000000FF &&
+ Gmask == 0x0000FF00 &&
+ Bmask == 0x00FF0000 &&
+ Amask == 0xFF000000) {
+ return SDL_PIXELFORMAT_ABGR8888;
+ }
+ if (Rmask == 0x0000FF00 &&
+ Gmask == 0x00FF0000 &&
+ Bmask == 0xFF000000 &&
+ Amask == 0x000000FF) {
+ return SDL_PIXELFORMAT_BGRA8888;
+ }
+ if (Rmask == 0x3FF00000 &&
+ Gmask == 0x000FFC00 &&
+ Bmask == 0x000003FF &&
+ Amask == 0xC0000000) {
+ return SDL_PIXELFORMAT_ARGB2101010;
+ }
+ }
+ return SDL_PIXELFORMAT_UNKNOWN;
+}
+
+static SDL_PixelFormat *formats;
+static SDL_SpinLock formats_lock = 0;
+
+SDL_PixelFormat *
+SDL_AllocFormat(Uint32 pixel_format)
+{
+ SDL_PixelFormat *format;
+
+ SDL_AtomicLock(&formats_lock);
+
+ /* Look it up in our list of previously allocated formats */
+ for (format = formats; format; format = format->next) {
+ if (pixel_format == format->format) {
+ ++format->refcount;
+ SDL_AtomicUnlock(&formats_lock);
+ return format;
+ }
+ }
+
+ /* Allocate an empty pixel format structure, and initialize it */
+ format = SDL_malloc(sizeof(*format));
+ if (format == NULL) {
+ SDL_AtomicUnlock(&formats_lock);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ if (SDL_InitFormat(format, pixel_format) < 0) {
+ SDL_AtomicUnlock(&formats_lock);
+ SDL_free(format);
+ SDL_InvalidParamError("format");
+ return NULL;
+ }
+
+ if (!SDL_ISPIXELFORMAT_INDEXED(pixel_format)) {
+ /* Cache the RGB formats */
+ format->next = formats;
+ formats = format;
+ }
+
+ SDL_AtomicUnlock(&formats_lock);
+
+ return format;
+}
+
+int
+SDL_InitFormat(SDL_PixelFormat * format, Uint32 pixel_format)
+{
+ int bpp;
+ Uint32 Rmask, Gmask, Bmask, Amask;
+ Uint32 mask;
+
+ if (!SDL_PixelFormatEnumToMasks(pixel_format, &bpp,
+ &Rmask, &Gmask, &Bmask, &Amask)) {
+ return -1;
+ }
+
+ /* Set up the format */
+ SDL_zerop(format);
+ format->format = pixel_format;
+ format->BitsPerPixel = bpp;
+ format->BytesPerPixel = (bpp + 7) / 8;
+
+ format->Rmask = Rmask;
+ format->Rshift = 0;
+ format->Rloss = 8;
+ if (Rmask) {
+ for (mask = Rmask; !(mask & 0x01); mask >>= 1)
+ ++format->Rshift;
+ for (; (mask & 0x01); mask >>= 1)
+ --format->Rloss;
+ }
+
+ format->Gmask = Gmask;
+ format->Gshift = 0;
+ format->Gloss = 8;
+ if (Gmask) {
+ for (mask = Gmask; !(mask & 0x01); mask >>= 1)
+ ++format->Gshift;
+ for (; (mask & 0x01); mask >>= 1)
+ --format->Gloss;
+ }
+
+ format->Bmask = Bmask;
+ format->Bshift = 0;
+ format->Bloss = 8;
+ if (Bmask) {
+ for (mask = Bmask; !(mask & 0x01); mask >>= 1)
+ ++format->Bshift;
+ for (; (mask & 0x01); mask >>= 1)
+ --format->Bloss;
+ }
+
+ format->Amask = Amask;
+ format->Ashift = 0;
+ format->Aloss = 8;
+ if (Amask) {
+ for (mask = Amask; !(mask & 0x01); mask >>= 1)
+ ++format->Ashift;
+ for (; (mask & 0x01); mask >>= 1)
+ --format->Aloss;
+ }
+
+ format->palette = NULL;
+ format->refcount = 1;
+ format->next = NULL;
+
+ return 0;
+}
+
+void
+SDL_FreeFormat(SDL_PixelFormat *format)
+{
+ SDL_PixelFormat *prev;
+
+ if (!format) {
+ SDL_InvalidParamError("format");
+ return;
+ }
+
+ SDL_AtomicLock(&formats_lock);
+
+ if (--format->refcount > 0) {
+ SDL_AtomicUnlock(&formats_lock);
+ return;
+ }
+
+ /* Remove this format from our list */
+ if (format == formats) {
+ formats = format->next;
+ } else if (formats) {
+ for (prev = formats; prev->next; prev = prev->next) {
+ if (prev->next == format) {
+ prev->next = format->next;
+ break;
+ }
+ }
+ }
+
+ SDL_AtomicUnlock(&formats_lock);
+
+ if (format->palette) {
+ SDL_FreePalette(format->palette);
+ }
+ SDL_free(format);
+}
+
+SDL_Palette *
+SDL_AllocPalette(int ncolors)
+{
+ SDL_Palette *palette;
+
+ /* Input validation */
+ if (ncolors < 1) {
+ SDL_InvalidParamError("ncolors");
+ return NULL;
+ }
+
+ palette = (SDL_Palette *) SDL_malloc(sizeof(*palette));
+ if (!palette) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ palette->colors =
+ (SDL_Color *) SDL_malloc(ncolors * sizeof(*palette->colors));
+ if (!palette->colors) {
+ SDL_free(palette);
+ return NULL;
+ }
+ palette->ncolors = ncolors;
+ palette->version = 1;
+ palette->refcount = 1;
+
+ SDL_memset(palette->colors, 0xFF, ncolors * sizeof(*palette->colors));
+
+ return palette;
+}
+
+int
+SDL_SetPixelFormatPalette(SDL_PixelFormat * format, SDL_Palette *palette)
+{
+ if (!format) {
+ return SDL_SetError("SDL_SetPixelFormatPalette() passed NULL format");
+ }
+
+ if (palette && palette->ncolors > (1 << format->BitsPerPixel)) {
+ return SDL_SetError("SDL_SetPixelFormatPalette() passed a palette that doesn't match the format");
+ }
+
+ if (format->palette == palette) {
+ return 0;
+ }
+
+ if (format->palette) {
+ SDL_FreePalette(format->palette);
+ }
+
+ format->palette = palette;
+
+ if (format->palette) {
+ ++format->palette->refcount;
+ }
+
+ return 0;
+}
+
+int
+SDL_SetPaletteColors(SDL_Palette * palette, const SDL_Color * colors,
+ int firstcolor, int ncolors)
+{
+ int status = 0;
+
+ /* Verify the parameters */
+ if (!palette) {
+ return -1;
+ }
+ if (ncolors > (palette->ncolors - firstcolor)) {
+ ncolors = (palette->ncolors - firstcolor);
+ status = -1;
+ }
+
+ if (colors != (palette->colors + firstcolor)) {
+ SDL_memcpy(palette->colors + firstcolor, colors,
+ ncolors * sizeof(*colors));
+ }
+ ++palette->version;
+ if (!palette->version) {
+ palette->version = 1;
+ }
+
+ return status;
+}
+
+void
+SDL_FreePalette(SDL_Palette * palette)
+{
+ if (!palette) {
+ SDL_InvalidParamError("palette");
+ return;
+ }
+ if (--palette->refcount > 0) {
+ return;
+ }
+ SDL_free(palette->colors);
+ SDL_free(palette);
+}
+
+/*
+ * Calculate an 8-bit (3 red, 3 green, 2 blue) dithered palette of colors
+ */
+void
+SDL_DitherColors(SDL_Color * colors, int bpp)
+{
+ int i;
+ if (bpp != 8)
+ return; /* only 8bpp supported right now */
+
+ for (i = 0; i < 256; i++) {
+ int r, g, b;
+ /* map each bit field to the full [0, 255] interval,
+ so 0 is mapped to (0, 0, 0) and 255 to (255, 255, 255) */
+ r = i & 0xe0;
+ r |= r >> 3 | r >> 6;
+ colors[i].r = r;
+ g = (i << 3) & 0xe0;
+ g |= g >> 3 | g >> 6;
+ colors[i].g = g;
+ b = i & 0x3;
+ b |= b << 2;
+ b |= b << 4;
+ colors[i].b = b;
+ colors[i].a = SDL_ALPHA_OPAQUE;
+ }
+}
+
+/*
+ * Match an RGB value to a particular palette index
+ */
+Uint8
+SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ /* Do colorspace distance matching */
+ unsigned int smallest;
+ unsigned int distance;
+ int rd, gd, bd, ad;
+ int i;
+ Uint8 pixel = 0;
+
+ smallest = ~0;
+ for (i = 0; i < pal->ncolors; ++i) {
+ rd = pal->colors[i].r - r;
+ gd = pal->colors[i].g - g;
+ bd = pal->colors[i].b - b;
+ ad = pal->colors[i].a - a;
+ distance = (rd * rd) + (gd * gd) + (bd * bd) + (ad * ad);
+ if (distance < smallest) {
+ pixel = i;
+ if (distance == 0) { /* Perfect match! */
+ break;
+ }
+ smallest = distance;
+ }
+ }
+ return (pixel);
+}
+
+/* Find the opaque pixel value corresponding to an RGB triple */
+Uint32
+SDL_MapRGB(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b)
+{
+ if (format->palette == NULL) {
+ return (r >> format->Rloss) << format->Rshift
+ | (g >> format->Gloss) << format->Gshift
+ | (b >> format->Bloss) << format->Bshift | format->Amask;
+ } else {
+ return SDL_FindColor(format->palette, r, g, b, SDL_ALPHA_OPAQUE);
+ }
+}
+
+/* Find the pixel value corresponding to an RGBA quadruple */
+Uint32
+SDL_MapRGBA(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b,
+ Uint8 a)
+{
+ if (format->palette == NULL) {
+ return (r >> format->Rloss) << format->Rshift
+ | (g >> format->Gloss) << format->Gshift
+ | (b >> format->Bloss) << format->Bshift
+ | ((a >> format->Aloss) << format->Ashift & format->Amask);
+ } else {
+ return SDL_FindColor(format->palette, r, g, b, a);
+ }
+}
+
+void
+SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat * format, Uint8 * r, Uint8 * g,
+ Uint8 * b)
+{
+ if (format->palette == NULL) {
+ unsigned v;
+ v = (pixel & format->Rmask) >> format->Rshift;
+ *r = SDL_expand_byte[format->Rloss][v];
+ v = (pixel & format->Gmask) >> format->Gshift;
+ *g = SDL_expand_byte[format->Gloss][v];
+ v = (pixel & format->Bmask) >> format->Bshift;
+ *b = SDL_expand_byte[format->Bloss][v];
+ } else {
+ if (pixel < (unsigned)format->palette->ncolors) {
+ *r = format->palette->colors[pixel].r;
+ *g = format->palette->colors[pixel].g;
+ *b = format->palette->colors[pixel].b;
+ } else {
+ *r = *g = *b = 0;
+ }
+ }
+}
+
+void
+SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format,
+ Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a)
+{
+ if (format->palette == NULL) {
+ unsigned v;
+ v = (pixel & format->Rmask) >> format->Rshift;
+ *r = SDL_expand_byte[format->Rloss][v];
+ v = (pixel & format->Gmask) >> format->Gshift;
+ *g = SDL_expand_byte[format->Gloss][v];
+ v = (pixel & format->Bmask) >> format->Bshift;
+ *b = SDL_expand_byte[format->Bloss][v];
+ v = (pixel & format->Amask) >> format->Ashift;
+ *a = SDL_expand_byte[format->Aloss][v];
+ } else {
+ if (pixel < (unsigned)format->palette->ncolors) {
+ *r = format->palette->colors[pixel].r;
+ *g = format->palette->colors[pixel].g;
+ *b = format->palette->colors[pixel].b;
+ *a = format->palette->colors[pixel].a;
+ } else {
+ *r = *g = *b = *a = 0;
+ }
+ }
+}
+
+/* Map from Palette to Palette */
+static Uint8 *
+Map1to1(SDL_Palette * src, SDL_Palette * dst, int *identical)
+{
+ Uint8 *map;
+ int i;
+
+ if (identical) {
+ if (src->ncolors <= dst->ncolors) {
+ /* If an identical palette, no need to map */
+ if (src == dst
+ ||
+ (SDL_memcmp
+ (src->colors, dst->colors,
+ src->ncolors * sizeof(SDL_Color)) == 0)) {
+ *identical = 1;
+ return (NULL);
+ }
+ }
+ *identical = 0;
+ }
+ map = (Uint8 *) SDL_malloc(src->ncolors);
+ if (map == NULL) {
+ SDL_OutOfMemory();
+ return (NULL);
+ }
+ for (i = 0; i < src->ncolors; ++i) {
+ map[i] = SDL_FindColor(dst,
+ src->colors[i].r, src->colors[i].g,
+ src->colors[i].b, src->colors[i].a);
+ }
+ return (map);
+}
+
+/* Map from Palette to BitField */
+static Uint8 *
+Map1toN(SDL_PixelFormat * src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod,
+ SDL_PixelFormat * dst)
+{
+ Uint8 *map;
+ int i;
+ int bpp;
+ SDL_Palette *pal = src->palette;
+
+ bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel);
+ map = (Uint8 *) SDL_malloc(pal->ncolors * bpp);
+ if (map == NULL) {
+ SDL_OutOfMemory();
+ return (NULL);
+ }
+
+ /* We memory copy to the pixel map so the endianness is preserved */
+ for (i = 0; i < pal->ncolors; ++i) {
+ Uint8 R = (Uint8) ((pal->colors[i].r * Rmod) / 255);
+ Uint8 G = (Uint8) ((pal->colors[i].g * Gmod) / 255);
+ Uint8 B = (Uint8) ((pal->colors[i].b * Bmod) / 255);
+ Uint8 A = (Uint8) ((pal->colors[i].a * Amod) / 255);
+ ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst, R, G, B, A);
+ }
+ return (map);
+}
+
+/* Map from BitField to Dithered-Palette to Palette */
+static Uint8 *
+MapNto1(SDL_PixelFormat * src, SDL_PixelFormat * dst, int *identical)
+{
+ /* Generate a 256 color dither palette */
+ SDL_Palette dithered;
+ SDL_Color colors[256];
+ SDL_Palette *pal = dst->palette;
+
+ dithered.ncolors = 256;
+ SDL_DitherColors(colors, 8);
+ dithered.colors = colors;
+ return (Map1to1(&dithered, pal, identical));
+}
+
+SDL_BlitMap *
+SDL_AllocBlitMap(void)
+{
+ SDL_BlitMap *map;
+
+ /* Allocate the empty map */
+ map = (SDL_BlitMap *) SDL_calloc(1, sizeof(*map));
+ if (map == NULL) {
+ SDL_OutOfMemory();
+ return (NULL);
+ }
+ map->info.r = 0xFF;
+ map->info.g = 0xFF;
+ map->info.b = 0xFF;
+ map->info.a = 0xFF;
+
+ /* It's ready to go */
+ return (map);
+}
+
+void
+SDL_InvalidateMap(SDL_BlitMap * map)
+{
+ if (!map) {
+ return;
+ }
+ if (map->dst) {
+ /* Release our reference to the surface - see the note below */
+ if (--map->dst->refcount <= 0) {
+ SDL_FreeSurface(map->dst);
+ }
+ }
+ map->dst = NULL;
+ map->src_palette_version = 0;
+ map->dst_palette_version = 0;
+ SDL_free(map->info.table);
+ map->info.table = NULL;
+}
+
+int
+SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst)
+{
+ SDL_PixelFormat *srcfmt;
+ SDL_PixelFormat *dstfmt;
+ SDL_BlitMap *map;
+
+ /* Clear out any previous mapping */
+ map = src->map;
+ if ((src->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
+ SDL_UnRLESurface(src, 1);
+ }
+ SDL_InvalidateMap(map);
+
+ /* Figure out what kind of mapping we're doing */
+ map->identity = 0;
+ srcfmt = src->format;
+ dstfmt = dst->format;
+ if (SDL_ISPIXELFORMAT_INDEXED(srcfmt->format)) {
+ if (SDL_ISPIXELFORMAT_INDEXED(dstfmt->format)) {
+ /* Palette --> Palette */
+ map->info.table =
+ Map1to1(srcfmt->palette, dstfmt->palette, &map->identity);
+ if (!map->identity) {
+ if (map->info.table == NULL) {
+ return (-1);
+ }
+ }
+ if (srcfmt->BitsPerPixel != dstfmt->BitsPerPixel)
+ map->identity = 0;
+ } else {
+ /* Palette --> BitField */
+ map->info.table =
+ Map1toN(srcfmt, src->map->info.r, src->map->info.g,
+ src->map->info.b, src->map->info.a, dstfmt);
+ if (map->info.table == NULL) {
+ return (-1);
+ }
+ }
+ } else {
+ if (SDL_ISPIXELFORMAT_INDEXED(dstfmt->format)) {
+ /* BitField --> Palette */
+ map->info.table = MapNto1(srcfmt, dstfmt, &map->identity);
+ if (!map->identity) {
+ if (map->info.table == NULL) {
+ return (-1);
+ }
+ }
+ map->identity = 0; /* Don't optimize to copy */
+ } else {
+ /* BitField --> BitField */
+ if (srcfmt == dstfmt) {
+ map->identity = 1;
+ }
+ }
+ }
+
+ map->dst = dst;
+
+ if (map->dst) {
+ /* Keep a reference to this surface so it doesn't get deleted
+ while we're still pointing at it.
+
+ A better method would be for the destination surface to keep
+ track of surfaces that are mapped to it and automatically
+ invalidate them when it is freed, but this will do for now.
+ */
+ ++map->dst->refcount;
+ }
+
+ if (dstfmt->palette) {
+ map->dst_palette_version = dstfmt->palette->version;
+ } else {
+ map->dst_palette_version = 0;
+ }
+
+ if (srcfmt->palette) {
+ map->src_palette_version = srcfmt->palette->version;
+ } else {
+ map->src_palette_version = 0;
+ }
+
+ /* Choose your blitters wisely */
+ return (SDL_CalculateBlit(src));
+}
+
+void
+SDL_FreeBlitMap(SDL_BlitMap * map)
+{
+ if (map) {
+ SDL_InvalidateMap(map);
+ SDL_free(map);
+ }
+}
+
+void
+SDL_CalculateGammaRamp(float gamma, Uint16 * ramp)
+{
+ int i;
+
+ /* Input validation */
+ if (gamma < 0.0f ) {
+ SDL_InvalidParamError("gamma");
+ return;
+ }
+ if (ramp == NULL) {
+ SDL_InvalidParamError("ramp");
+ return;
+ }
+
+ /* 0.0 gamma is all black */
+ if (gamma == 0.0f) {
+ SDL_memset(ramp, 0, 256 * sizeof(Uint16));
+ return;
+ } else if (gamma == 1.0f) {
+ /* 1.0 gamma is identity */
+ for (i = 0; i < 256; ++i) {
+ ramp[i] = (i << 8) | i;
+ }
+ return;
+ } else {
+ /* Calculate a real gamma ramp */
+ int value;
+ gamma = 1.0f / gamma;
+ for (i = 0; i < 256; ++i) {
+ value =
+ (int) (SDL_pow((double) i / 256.0, gamma) * 65535.0 + 0.5);
+ if (value > 65535) {
+ value = 65535;
+ }
+ ramp[i] = (Uint16) value;
+ }
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_pixels_c.h b/src/3rdparty/SDL2/src/video/SDL_pixels_c.h
new file mode 100644
index 0000000..900f0b0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_pixels_c.h
@@ -0,0 +1,40 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* Useful functions and variables from SDL_pixel.c */
+
+#include "SDL_blit.h"
+
+/* Pixel format functions */
+extern int SDL_InitFormat(SDL_PixelFormat * format, Uint32 pixel_format);
+
+/* Blit mapping functions */
+extern SDL_BlitMap *SDL_AllocBlitMap(void);
+extern void SDL_InvalidateMap(SDL_BlitMap * map);
+extern int SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst);
+extern void SDL_FreeBlitMap(SDL_BlitMap * map);
+
+/* Miscellaneous functions */
+extern void SDL_DitherColors(SDL_Color * colors, int bpp);
+extern Uint8 SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_rect.c b/src/3rdparty/SDL2/src/video/SDL_rect.c
new file mode 100644
index 0000000..8c6ff2d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_rect.c
@@ -0,0 +1,531 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "SDL_rect.h"
+#include "SDL_rect_c.h"
+#include "SDL_assert.h"
+
+SDL_bool
+SDL_HasIntersection(const SDL_Rect * A, const SDL_Rect * B)
+{
+ int Amin, Amax, Bmin, Bmax;
+
+ if (!A) {
+ SDL_InvalidParamError("A");
+ return SDL_FALSE;
+ }
+
+ if (!B) {
+ SDL_InvalidParamError("B");
+ return SDL_FALSE;
+ }
+
+ /* Special cases for empty rects */
+ if (SDL_RectEmpty(A) || SDL_RectEmpty(B)) {
+ return SDL_FALSE;
+ }
+
+ /* Horizontal intersection */
+ Amin = A->x;
+ Amax = Amin + A->w;
+ Bmin = B->x;
+ Bmax = Bmin + B->w;
+ if (Bmin > Amin)
+ Amin = Bmin;
+ if (Bmax < Amax)
+ Amax = Bmax;
+ if (Amax <= Amin)
+ return SDL_FALSE;
+
+ /* Vertical intersection */
+ Amin = A->y;
+ Amax = Amin + A->h;
+ Bmin = B->y;
+ Bmax = Bmin + B->h;
+ if (Bmin > Amin)
+ Amin = Bmin;
+ if (Bmax < Amax)
+ Amax = Bmax;
+ if (Amax <= Amin)
+ return SDL_FALSE;
+
+ return SDL_TRUE;
+}
+
+SDL_bool
+SDL_IntersectRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result)
+{
+ int Amin, Amax, Bmin, Bmax;
+
+ if (!A) {
+ SDL_InvalidParamError("A");
+ return SDL_FALSE;
+ }
+
+ if (!B) {
+ SDL_InvalidParamError("B");
+ return SDL_FALSE;
+ }
+
+ if (!result) {
+ SDL_InvalidParamError("result");
+ return SDL_FALSE;
+ }
+
+ /* Special cases for empty rects */
+ if (SDL_RectEmpty(A) || SDL_RectEmpty(B)) {
+ result->w = 0;
+ result->h = 0;
+ return SDL_FALSE;
+ }
+
+ /* Horizontal intersection */
+ Amin = A->x;
+ Amax = Amin + A->w;
+ Bmin = B->x;
+ Bmax = Bmin + B->w;
+ if (Bmin > Amin)
+ Amin = Bmin;
+ result->x = Amin;
+ if (Bmax < Amax)
+ Amax = Bmax;
+ result->w = Amax - Amin;
+
+ /* Vertical intersection */
+ Amin = A->y;
+ Amax = Amin + A->h;
+ Bmin = B->y;
+ Bmax = Bmin + B->h;
+ if (Bmin > Amin)
+ Amin = Bmin;
+ result->y = Amin;
+ if (Bmax < Amax)
+ Amax = Bmax;
+ result->h = Amax - Amin;
+
+ return !SDL_RectEmpty(result);
+}
+
+void
+SDL_UnionRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result)
+{
+ int Amin, Amax, Bmin, Bmax;
+
+ if (!A) {
+ SDL_InvalidParamError("A");
+ return;
+ }
+
+ if (!B) {
+ SDL_InvalidParamError("B");
+ return;
+ }
+
+ if (!result) {
+ SDL_InvalidParamError("result");
+ return;
+ }
+
+ /* Special cases for empty Rects */
+ if (SDL_RectEmpty(A)) {
+ if (SDL_RectEmpty(B)) {
+ /* A and B empty */
+ return;
+ } else {
+ /* A empty, B not empty */
+ *result = *B;
+ return;
+ }
+ } else {
+ if (SDL_RectEmpty(B)) {
+ /* A not empty, B empty */
+ *result = *A;
+ return;
+ }
+ }
+
+ /* Horizontal union */
+ Amin = A->x;
+ Amax = Amin + A->w;
+ Bmin = B->x;
+ Bmax = Bmin + B->w;
+ if (Bmin < Amin)
+ Amin = Bmin;
+ result->x = Amin;
+ if (Bmax > Amax)
+ Amax = Bmax;
+ result->w = Amax - Amin;
+
+ /* Vertical union */
+ Amin = A->y;
+ Amax = Amin + A->h;
+ Bmin = B->y;
+ Bmax = Bmin + B->h;
+ if (Bmin < Amin)
+ Amin = Bmin;
+ result->y = Amin;
+ if (Bmax > Amax)
+ Amax = Bmax;
+ result->h = Amax - Amin;
+}
+
+SDL_bool
+SDL_EnclosePoints(const SDL_Point * points, int count, const SDL_Rect * clip,
+ SDL_Rect * result)
+{
+ int minx = 0;
+ int miny = 0;
+ int maxx = 0;
+ int maxy = 0;
+ int x, y, i;
+
+ if (!points) {
+ SDL_InvalidParamError("points");
+ return SDL_FALSE;
+ }
+
+ if (count < 1) {
+ SDL_InvalidParamError("count");
+ return SDL_FALSE;
+ }
+
+ if (clip) {
+ SDL_bool added = SDL_FALSE;
+ const int clip_minx = clip->x;
+ const int clip_miny = clip->y;
+ const int clip_maxx = clip->x+clip->w-1;
+ const int clip_maxy = clip->y+clip->h-1;
+
+ /* Special case for empty rectangle */
+ if (SDL_RectEmpty(clip)) {
+ return SDL_FALSE;
+ }
+
+ for (i = 0; i < count; ++i) {
+ x = points[i].x;
+ y = points[i].y;
+
+ if (x < clip_minx || x > clip_maxx ||
+ y < clip_miny || y > clip_maxy) {
+ continue;
+ }
+ if (!added) {
+ /* Special case: if no result was requested, we are done */
+ if (result == NULL) {
+ return SDL_TRUE;
+ }
+
+ /* First point added */
+ minx = maxx = x;
+ miny = maxy = y;
+ added = SDL_TRUE;
+ continue;
+ }
+ if (x < minx) {
+ minx = x;
+ } else if (x > maxx) {
+ maxx = x;
+ }
+ if (y < miny) {
+ miny = y;
+ } else if (y > maxy) {
+ maxy = y;
+ }
+ }
+ if (!added) {
+ return SDL_FALSE;
+ }
+ } else {
+ /* Special case: if no result was requested, we are done */
+ if (result == NULL) {
+ return SDL_TRUE;
+ }
+
+ /* No clipping, always add the first point */
+ minx = maxx = points[0].x;
+ miny = maxy = points[0].y;
+
+ for (i = 1; i < count; ++i) {
+ x = points[i].x;
+ y = points[i].y;
+
+ if (x < minx) {
+ minx = x;
+ } else if (x > maxx) {
+ maxx = x;
+ }
+ if (y < miny) {
+ miny = y;
+ } else if (y > maxy) {
+ maxy = y;
+ }
+ }
+ }
+
+ if (result) {
+ result->x = minx;
+ result->y = miny;
+ result->w = (maxx-minx)+1;
+ result->h = (maxy-miny)+1;
+ }
+ return SDL_TRUE;
+}
+
+/* Use the Cohen-Sutherland algorithm for line clipping */
+#define CODE_BOTTOM 1
+#define CODE_TOP 2
+#define CODE_LEFT 4
+#define CODE_RIGHT 8
+
+static int
+ComputeOutCode(const SDL_Rect * rect, int x, int y)
+{
+ int code = 0;
+ if (y < rect->y) {
+ code |= CODE_TOP;
+ } else if (y >= rect->y + rect->h) {
+ code |= CODE_BOTTOM;
+ }
+ if (x < rect->x) {
+ code |= CODE_LEFT;
+ } else if (x >= rect->x + rect->w) {
+ code |= CODE_RIGHT;
+ }
+ return code;
+}
+
+SDL_bool
+SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2,
+ int *Y2)
+{
+ int x = 0;
+ int y = 0;
+ int x1, y1;
+ int x2, y2;
+ int rectx1;
+ int recty1;
+ int rectx2;
+ int recty2;
+ int outcode1, outcode2;
+
+ if (!rect) {
+ SDL_InvalidParamError("rect");
+ return SDL_FALSE;
+ }
+
+ if (!X1) {
+ SDL_InvalidParamError("X1");
+ return SDL_FALSE;
+ }
+
+ if (!Y1) {
+ SDL_InvalidParamError("Y1");
+ return SDL_FALSE;
+ }
+
+ if (!X2) {
+ SDL_InvalidParamError("X2");
+ return SDL_FALSE;
+ }
+
+ if (!Y2) {
+ SDL_InvalidParamError("Y2");
+ return SDL_FALSE;
+ }
+
+ /* Special case for empty rect */
+ if (SDL_RectEmpty(rect)) {
+ return SDL_FALSE;
+ }
+
+ x1 = *X1;
+ y1 = *Y1;
+ x2 = *X2;
+ y2 = *Y2;
+ rectx1 = rect->x;
+ recty1 = rect->y;
+ rectx2 = rect->x + rect->w - 1;
+ recty2 = rect->y + rect->h - 1;
+
+ /* Check to see if entire line is inside rect */
+ if (x1 >= rectx1 && x1 <= rectx2 && x2 >= rectx1 && x2 <= rectx2 &&
+ y1 >= recty1 && y1 <= recty2 && y2 >= recty1 && y2 <= recty2) {
+ return SDL_TRUE;
+ }
+
+ /* Check to see if entire line is to one side of rect */
+ if ((x1 < rectx1 && x2 < rectx1) || (x1 > rectx2 && x2 > rectx2) ||
+ (y1 < recty1 && y2 < recty1) || (y1 > recty2 && y2 > recty2)) {
+ return SDL_FALSE;
+ }
+
+ if (y1 == y2) {
+ /* Horizontal line, easy to clip */
+ if (x1 < rectx1) {
+ *X1 = rectx1;
+ } else if (x1 > rectx2) {
+ *X1 = rectx2;
+ }
+ if (x2 < rectx1) {
+ *X2 = rectx1;
+ } else if (x2 > rectx2) {
+ *X2 = rectx2;
+ }
+ return SDL_TRUE;
+ }
+
+ if (x1 == x2) {
+ /* Vertical line, easy to clip */
+ if (y1 < recty1) {
+ *Y1 = recty1;
+ } else if (y1 > recty2) {
+ *Y1 = recty2;
+ }
+ if (y2 < recty1) {
+ *Y2 = recty1;
+ } else if (y2 > recty2) {
+ *Y2 = recty2;
+ }
+ return SDL_TRUE;
+ }
+
+ /* More complicated Cohen-Sutherland algorithm */
+ outcode1 = ComputeOutCode(rect, x1, y1);
+ outcode2 = ComputeOutCode(rect, x2, y2);
+ while (outcode1 || outcode2) {
+ if (outcode1 & outcode2) {
+ return SDL_FALSE;
+ }
+
+ if (outcode1) {
+ if (outcode1 & CODE_TOP) {
+ y = recty1;
+ x = x1 + ((x2 - x1) * (y - y1)) / (y2 - y1);
+ } else if (outcode1 & CODE_BOTTOM) {
+ y = recty2;
+ x = x1 + ((x2 - x1) * (y - y1)) / (y2 - y1);
+ } else if (outcode1 & CODE_LEFT) {
+ x = rectx1;
+ y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1);
+ } else if (outcode1 & CODE_RIGHT) {
+ x = rectx2;
+ y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1);
+ }
+ x1 = x;
+ y1 = y;
+ outcode1 = ComputeOutCode(rect, x, y);
+ } else {
+ if (outcode2 & CODE_TOP) {
+ y = recty1;
+ x = x1 + ((x2 - x1) * (y - y1)) / (y2 - y1);
+ } else if (outcode2 & CODE_BOTTOM) {
+ y = recty2;
+ x = x1 + ((x2 - x1) * (y - y1)) / (y2 - y1);
+ } else if (outcode2 & CODE_LEFT) {
+ /* If this assertion ever fires, here's the static analysis that warned about it:
+ http://buildbot.libsdl.org/sdl-static-analysis/sdl-macosx-static-analysis/sdl-macosx-static-analysis-1101/report-b0d01a.html#EndPath */
+ SDL_assert(x2 != x1); /* if equal: division by zero. */
+ x = rectx1;
+ y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1);
+ } else if (outcode2 & CODE_RIGHT) {
+ /* If this assertion ever fires, here's the static analysis that warned about it:
+ http://buildbot.libsdl.org/sdl-static-analysis/sdl-macosx-static-analysis/sdl-macosx-static-analysis-1101/report-39b114.html#EndPath */
+ SDL_assert(x2 != x1); /* if equal: division by zero. */
+ x = rectx2;
+ y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1);
+ }
+ x2 = x;
+ y2 = y;
+ outcode2 = ComputeOutCode(rect, x, y);
+ }
+ }
+ *X1 = x1;
+ *Y1 = y1;
+ *X2 = x2;
+ *Y2 = y2;
+ return SDL_TRUE;
+}
+
+SDL_bool
+SDL_GetSpanEnclosingRect(int width, int height,
+ int numrects, const SDL_Rect * rects, SDL_Rect *span)
+{
+ int i;
+ int span_y1, span_y2;
+ int rect_y1, rect_y2;
+
+ if (width < 1) {
+ SDL_InvalidParamError("width");
+ return SDL_FALSE;
+ }
+
+ if (height < 1) {
+ SDL_InvalidParamError("height");
+ return SDL_FALSE;
+ }
+
+ if (!rects) {
+ SDL_InvalidParamError("rects");
+ return SDL_FALSE;
+ }
+
+ if (!span) {
+ SDL_InvalidParamError("span");
+ return SDL_FALSE;
+ }
+
+ if (numrects < 1) {
+ SDL_InvalidParamError("numrects");
+ return SDL_FALSE;
+ }
+
+ /* Initialize to empty rect */
+ span_y1 = height;
+ span_y2 = 0;
+
+ for (i = 0; i < numrects; ++i) {
+ rect_y1 = rects[i].y;
+ rect_y2 = rect_y1 + rects[i].h;
+
+ /* Clip out of bounds rectangles, and expand span rect */
+ if (rect_y1 < 0) {
+ span_y1 = 0;
+ } else if (rect_y1 < span_y1) {
+ span_y1 = rect_y1;
+ }
+ if (rect_y2 > height) {
+ span_y2 = height;
+ } else if (rect_y2 > span_y2) {
+ span_y2 = rect_y2;
+ }
+ }
+ if (span_y2 > span_y1) {
+ span->x = 0;
+ span->y = span_y1;
+ span->w = width;
+ span->h = (span_y2 - span_y1);
+ return SDL_TRUE;
+ }
+ return SDL_FALSE;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_rect_c.h b/src/3rdparty/SDL2/src/video/SDL_rect_c.h
new file mode 100644
index 0000000..d67e493
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_rect_c.h
@@ -0,0 +1,25 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+extern SDL_bool SDL_GetSpanEnclosingRect(int width, int height, int numrects, const SDL_Rect * rects, SDL_Rect *span);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_shape.c b/src/3rdparty/SDL2/src/video/SDL_shape.c
new file mode 100644
index 0000000..6f029bc
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_shape.c
@@ -0,0 +1,309 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "SDL.h"
+#include "SDL_assert.h"
+#include "SDL_video.h"
+#include "SDL_sysvideo.h"
+#include "SDL_pixels.h"
+#include "SDL_surface.h"
+#include "SDL_shape.h"
+#include "SDL_shape_internals.h"
+
+SDL_Window*
+SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags)
+{
+ SDL_Window *result = NULL;
+ result = SDL_CreateWindow(title,-1000,-1000,w,h,(flags | SDL_WINDOW_BORDERLESS) & (~SDL_WINDOW_FULLSCREEN) & (~SDL_WINDOW_RESIZABLE) /* & (~SDL_WINDOW_SHOWN) */);
+ if(result != NULL) {
+ if (SDL_GetVideoDevice()->shape_driver.CreateShaper == NULL) {
+ SDL_DestroyWindow(result);
+ return NULL;
+ }
+ result->shaper = SDL_GetVideoDevice()->shape_driver.CreateShaper(result);
+ if(result->shaper != NULL) {
+ result->shaper->userx = x;
+ result->shaper->usery = y;
+ result->shaper->mode.mode = ShapeModeDefault;
+ result->shaper->mode.parameters.binarizationCutoff = 1;
+ result->shaper->hasshape = SDL_FALSE;
+ return result;
+ }
+ else {
+ SDL_DestroyWindow(result);
+ return NULL;
+ }
+ }
+ else
+ return NULL;
+}
+
+SDL_bool
+SDL_IsShapedWindow(const SDL_Window *window)
+{
+ if(window == NULL)
+ return SDL_FALSE;
+ else
+ return (SDL_bool)(window->shaper != NULL);
+}
+
+/* REQUIRES that bitmap point to a w-by-h bitmap with ppb pixels-per-byte. */
+void
+SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb)
+{
+ int x = 0;
+ int y = 0;
+ Uint8 r = 0,g = 0,b = 0,alpha = 0;
+ Uint8* pixel = NULL;
+ Uint32 pixel_value = 0,mask_value = 0;
+ int bytes_per_scanline = (shape->w + (ppb - 1)) / ppb;
+ Uint8 *bitmap_scanline;
+ SDL_Color key;
+ if(SDL_MUSTLOCK(shape))
+ SDL_LockSurface(shape);
+ for(y = 0;y<shape->h;y++) {
+ bitmap_scanline = bitmap + y * bytes_per_scanline;
+ for(x=0;x<shape->w;x++) {
+ alpha = 0;
+ pixel_value = 0;
+ pixel = (Uint8 *)(shape->pixels) + (y*shape->pitch) + (x*shape->format->BytesPerPixel);
+ switch(shape->format->BytesPerPixel) {
+ case(1):
+ pixel_value = *(Uint8*)pixel;
+ break;
+ case(2):
+ pixel_value = *(Uint16*)pixel;
+ break;
+ case(3):
+ pixel_value = *(Uint32*)pixel & (~shape->format->Amask);
+ break;
+ case(4):
+ pixel_value = *(Uint32*)pixel;
+ break;
+ }
+ SDL_GetRGBA(pixel_value,shape->format,&r,&g,&b,&alpha);
+ switch(mode.mode) {
+ case(ShapeModeDefault):
+ mask_value = (alpha >= 1 ? 1 : 0);
+ break;
+ case(ShapeModeBinarizeAlpha):
+ mask_value = (alpha >= mode.parameters.binarizationCutoff ? 1 : 0);
+ break;
+ case(ShapeModeReverseBinarizeAlpha):
+ mask_value = (alpha <= mode.parameters.binarizationCutoff ? 1 : 0);
+ break;
+ case(ShapeModeColorKey):
+ key = mode.parameters.colorKey;
+ mask_value = ((key.r != r || key.g != g || key.b != b) ? 1 : 0);
+ break;
+ }
+ bitmap_scanline[x / ppb] |= mask_value << (x % ppb);
+ }
+ }
+ if(SDL_MUSTLOCK(shape))
+ SDL_UnlockSurface(shape);
+}
+
+static SDL_ShapeTree*
+RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_Rect dimensions) {
+ int x = 0,y = 0;
+ Uint8* pixel = NULL;
+ Uint32 pixel_value = 0;
+ Uint8 r = 0,g = 0,b = 0,a = 0;
+ SDL_bool pixel_opaque = SDL_FALSE;
+ int last_opaque = -1;
+ SDL_Color key;
+ SDL_ShapeTree* result = (SDL_ShapeTree*)SDL_malloc(sizeof(SDL_ShapeTree));
+ SDL_Rect next = {0,0,0,0};
+
+ for(y=dimensions.y;y<dimensions.y + dimensions.h;y++) {
+ for(x=dimensions.x;x<dimensions.x + dimensions.w;x++) {
+ pixel_value = 0;
+ pixel = (Uint8 *)(mask->pixels) + (y*mask->pitch) + (x*mask->format->BytesPerPixel);
+ switch(mask->format->BytesPerPixel) {
+ case(1):
+ pixel_value = *(Uint8*)pixel;
+ break;
+ case(2):
+ pixel_value = *(Uint16*)pixel;
+ break;
+ case(3):
+ pixel_value = *(Uint32*)pixel & (~mask->format->Amask);
+ break;
+ case(4):
+ pixel_value = *(Uint32*)pixel;
+ break;
+ }
+ SDL_GetRGBA(pixel_value,mask->format,&r,&g,&b,&a);
+ switch(mode.mode) {
+ case(ShapeModeDefault):
+ pixel_opaque = (a >= 1 ? SDL_TRUE : SDL_FALSE);
+ break;
+ case(ShapeModeBinarizeAlpha):
+ pixel_opaque = (a >= mode.parameters.binarizationCutoff ? SDL_TRUE : SDL_FALSE);
+ break;
+ case(ShapeModeReverseBinarizeAlpha):
+ pixel_opaque = (a <= mode.parameters.binarizationCutoff ? SDL_TRUE : SDL_FALSE);
+ break;
+ case(ShapeModeColorKey):
+ key = mode.parameters.colorKey;
+ pixel_opaque = ((key.r != r || key.g != g || key.b != b) ? SDL_TRUE : SDL_FALSE);
+ break;
+ }
+ if(last_opaque == -1)
+ last_opaque = pixel_opaque;
+ if(last_opaque != pixel_opaque) {
+ const int halfwidth = dimensions.w / 2;
+ const int halfheight = dimensions.h / 2;
+
+ result->kind = QuadShape;
+
+ next.x = dimensions.x;
+ next.y = dimensions.y;
+ next.w = halfwidth;
+ next.h = halfheight;
+ result->data.children.upleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
+
+ next.x = dimensions.x + halfwidth;
+ next.w = dimensions.w - halfwidth;
+ result->data.children.upright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
+
+ next.x = dimensions.x;
+ next.w = halfwidth;
+ next.y = dimensions.y + halfheight;
+ next.h = dimensions.h - halfheight;
+ result->data.children.downleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
+
+ next.x = dimensions.x + halfwidth;
+ next.w = dimensions.w - halfwidth;
+ result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
+
+ return result;
+ }
+ }
+ }
+
+
+ /* If we never recursed, all the pixels in this quadrant have the same "value". */
+ result->kind = (last_opaque == SDL_TRUE ? OpaqueShape : TransparentShape);
+ result->data.shape = dimensions;
+ return result;
+}
+
+SDL_ShapeTree*
+SDL_CalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* shape)
+{
+ SDL_Rect dimensions;
+ SDL_ShapeTree* result = NULL;
+
+ dimensions.x = 0;
+ dimensions.y = 0;
+ dimensions.w = shape->w;
+ dimensions.h = shape->h;
+
+ if(SDL_MUSTLOCK(shape))
+ SDL_LockSurface(shape);
+ result = RecursivelyCalculateShapeTree(mode,shape,dimensions);
+ if(SDL_MUSTLOCK(shape))
+ SDL_UnlockSurface(shape);
+ return result;
+}
+
+void
+SDL_TraverseShapeTree(SDL_ShapeTree *tree,SDL_TraversalFunction function,void* closure)
+{
+ SDL_assert(tree != NULL);
+ if(tree->kind == QuadShape) {
+ SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upleft,function,closure);
+ SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upright,function,closure);
+ SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downleft,function,closure);
+ SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downright,function,closure);
+ }
+ else
+ function(tree,closure);
+}
+
+void
+SDL_FreeShapeTree(SDL_ShapeTree** shape_tree)
+{
+ if((*shape_tree)->kind == QuadShape) {
+ SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.upleft);
+ SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.upright);
+ SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.downleft);
+ SDL_FreeShapeTree((SDL_ShapeTree **)(char*)&(*shape_tree)->data.children.downright);
+ }
+ SDL_free(*shape_tree);
+ *shape_tree = NULL;
+}
+
+int
+SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode)
+{
+ int result;
+ if(window == NULL || !SDL_IsShapedWindow(window))
+ /* The window given was not a shapeable window. */
+ return SDL_NONSHAPEABLE_WINDOW;
+ if(shape == NULL)
+ /* Invalid shape argument. */
+ return SDL_INVALID_SHAPE_ARGUMENT;
+
+ if(shape_mode != NULL)
+ window->shaper->mode = *shape_mode;
+ result = SDL_GetVideoDevice()->shape_driver.SetWindowShape(window->shaper,shape,shape_mode);
+ window->shaper->hasshape = SDL_TRUE;
+ if(window->shaper->userx != 0 && window->shaper->usery != 0) {
+ SDL_SetWindowPosition(window,window->shaper->userx,window->shaper->usery);
+ window->shaper->userx = 0;
+ window->shaper->usery = 0;
+ }
+ return result;
+}
+
+static SDL_bool
+SDL_WindowHasAShape(SDL_Window *window)
+{
+ if (window == NULL || !SDL_IsShapedWindow(window))
+ return SDL_FALSE;
+ return window->shaper->hasshape;
+}
+
+int
+SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shape_mode)
+{
+ if(window != NULL && SDL_IsShapedWindow(window)) {
+ if(shape_mode == NULL) {
+ if(SDL_WindowHasAShape(window))
+ /* The window given has a shape. */
+ return 0;
+ else
+ /* The window given is shapeable but lacks a shape. */
+ return SDL_WINDOW_LACKS_SHAPE;
+ }
+ else {
+ *shape_mode = window->shaper->mode;
+ return 0;
+ }
+ }
+ else
+ /* The window given is not a valid shapeable window. */
+ return SDL_NONSHAPEABLE_WINDOW;
+}
diff --git a/src/3rdparty/SDL2/src/video/SDL_shape_internals.h b/src/3rdparty/SDL2/src/video/SDL_shape_internals.h
new file mode 100644
index 0000000..3af175c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_shape_internals.h
@@ -0,0 +1,69 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#ifndef SDL_shape_internals_h_
+#define SDL_shape_internals_h_
+
+#include "SDL_rect.h"
+#include "SDL_shape.h"
+#include "SDL_surface.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+/* *INDENT-OFF* */
+extern "C" {
+/* *INDENT-ON* */
+#endif
+
+typedef struct {
+ struct SDL_ShapeTree *upleft,*upright,*downleft,*downright;
+} SDL_QuadTreeChildren;
+
+typedef union {
+ SDL_QuadTreeChildren children;
+ SDL_Rect shape;
+} SDL_ShapeUnion;
+
+typedef enum { QuadShape,TransparentShape,OpaqueShape } SDL_ShapeKind;
+
+typedef struct {
+ SDL_ShapeKind kind;
+ SDL_ShapeUnion data;
+} SDL_ShapeTree;
+
+typedef void(*SDL_TraversalFunction)(SDL_ShapeTree*,void*);
+
+extern void SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb);
+extern SDL_ShapeTree* SDL_CalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* shape);
+extern void SDL_TraverseShapeTree(SDL_ShapeTree *tree,SDL_TraversalFunction function,void* closure);
+extern void SDL_FreeShapeTree(SDL_ShapeTree** shape_tree);
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+/* *INDENT-OFF* */
+}
+/* *INDENT-ON* */
+#endif
+#include "close_code.h"
+
+#endif
diff --git a/src/3rdparty/SDL2/src/video/SDL_stretch.c b/src/3rdparty/SDL2/src/video/SDL_stretch.c
new file mode 100644
index 0000000..8cc6bf3
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_stretch.c
@@ -0,0 +1,353 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* This a stretch blit implementation based on ideas given to me by
+ Tomasz Cejner - thanks! :)
+
+ April 27, 2000 - Sam Lantinga
+*/
+
+#include "SDL_video.h"
+#include "SDL_blit.h"
+
+/* This isn't ready for general consumption yet - it should be folded
+ into the general blitting mechanism.
+*/
+
+#if ((defined(_MSC_VER) && defined(_M_IX86)) || \
+ (defined(__WATCOMC__) && defined(__386__)) || \
+ (defined(__GNUC__) && defined(__i386__))) && SDL_ASSEMBLY_ROUTINES
+/* There's a bug with gcc 4.4.1 and -O2 where srcp doesn't get the correct
+ * value after the first scanline. FIXME? */
+/* #define USE_ASM_STRETCH */
+#endif
+
+#ifdef USE_ASM_STRETCH
+
+#ifdef HAVE_MPROTECT
+#include <sys/types.h>
+#include <sys/mman.h>
+#endif
+#ifdef __GNUC__
+#define PAGE_ALIGNED __attribute__((__aligned__(4096)))
+#else
+#define PAGE_ALIGNED
+#endif
+
+#if defined(_M_IX86) || defined(__i386__) || defined(__386__)
+#define PREFIX16 0x66
+#define STORE_BYTE 0xAA
+#define STORE_WORD 0xAB
+#define LOAD_BYTE 0xAC
+#define LOAD_WORD 0xAD
+#define RETURN 0xC3
+#else
+#error Need assembly opcodes for this architecture
+#endif
+
+static unsigned char copy_row[4096] PAGE_ALIGNED;
+
+static int
+generate_rowbytes(int src_w, int dst_w, int bpp)
+{
+ static struct
+ {
+ int bpp;
+ int src_w;
+ int dst_w;
+ int status;
+ } last;
+
+ int i;
+ int pos, inc;
+ unsigned char *eip, *fence;
+ unsigned char load, store;
+
+ /* See if we need to regenerate the copy buffer */
+ if ((src_w == last.src_w) && (dst_w == last.dst_w) && (bpp == last.bpp)) {
+ return (last.status);
+ }
+ last.bpp = bpp;
+ last.src_w = src_w;
+ last.dst_w = dst_w;
+ last.status = -1;
+
+ switch (bpp) {
+ case 1:
+ load = LOAD_BYTE;
+ store = STORE_BYTE;
+ break;
+ case 2:
+ case 4:
+ load = LOAD_WORD;
+ store = STORE_WORD;
+ break;
+ default:
+ return SDL_SetError("ASM stretch of %d bytes isn't supported", bpp);
+ }
+#ifdef HAVE_MPROTECT
+ /* Make the code writeable */
+ if (mprotect(copy_row, sizeof(copy_row), PROT_READ | PROT_WRITE) < 0) {
+ return SDL_SetError("Couldn't make copy buffer writeable");
+ }
+#endif
+ pos = 0x10000;
+ inc = (src_w << 16) / dst_w;
+ eip = copy_row;
+ fence = copy_row + sizeof(copy_row)-2;
+ for (i = 0; i < dst_w; ++i) {
+ while (pos >= 0x10000L) {
+ if (eip == fence) {
+ return -1;
+ }
+ if (bpp == 2) {
+ *eip++ = PREFIX16;
+ }
+ *eip++ = load;
+ pos -= 0x10000L;
+ }
+ if (eip == fence) {
+ return -1;
+ }
+ if (bpp == 2) {
+ *eip++ = PREFIX16;
+ }
+ *eip++ = store;
+ pos += inc;
+ }
+ *eip++ = RETURN;
+
+#ifdef HAVE_MPROTECT
+ /* Make the code executable but not writeable */
+ if (mprotect(copy_row, sizeof(copy_row), PROT_READ | PROT_EXEC) < 0) {
+ return SDL_SetError("Couldn't make copy buffer executable");
+ }
+#endif
+ last.status = 0;
+ return (0);
+}
+
+#endif /* USE_ASM_STRETCH */
+
+#define DEFINE_COPY_ROW(name, type) \
+static void name(type *src, int src_w, type *dst, int dst_w) \
+{ \
+ int i; \
+ int pos, inc; \
+ type pixel = 0; \
+ \
+ pos = 0x10000; \
+ inc = (src_w << 16) / dst_w; \
+ for ( i=dst_w; i>0; --i ) { \
+ while ( pos >= 0x10000L ) { \
+ pixel = *src++; \
+ pos -= 0x10000L; \
+ } \
+ *dst++ = pixel; \
+ pos += inc; \
+ } \
+}
+/* *INDENT-OFF* */
+DEFINE_COPY_ROW(copy_row1, Uint8)
+DEFINE_COPY_ROW(copy_row2, Uint16)
+DEFINE_COPY_ROW(copy_row4, Uint32)
+/* *INDENT-ON* */
+
+/* The ASM code doesn't handle 24-bpp stretch blits */
+static void
+copy_row3(Uint8 * src, int src_w, Uint8 * dst, int dst_w)
+{
+ int i;
+ int pos, inc;
+ Uint8 pixel[3] = { 0, 0, 0 };
+
+ pos = 0x10000;
+ inc = (src_w << 16) / dst_w;
+ for (i = dst_w; i > 0; --i) {
+ while (pos >= 0x10000L) {
+ pixel[0] = *src++;
+ pixel[1] = *src++;
+ pixel[2] = *src++;
+ pos -= 0x10000L;
+ }
+ *dst++ = pixel[0];
+ *dst++ = pixel[1];
+ *dst++ = pixel[2];
+ pos += inc;
+ }
+}
+
+/* Perform a stretch blit between two surfaces of the same format.
+ NOTE: This function is not safe to call from multiple threads!
+*/
+int
+SDL_SoftStretch(SDL_Surface * src, const SDL_Rect * srcrect,
+ SDL_Surface * dst, const SDL_Rect * dstrect)
+{
+ int src_locked;
+ int dst_locked;
+ int pos, inc;
+ int dst_maxrow;
+ int src_row, dst_row;
+ Uint8 *srcp = NULL;
+ Uint8 *dstp;
+ SDL_Rect full_src;
+ SDL_Rect full_dst;
+#ifdef USE_ASM_STRETCH
+ SDL_bool use_asm = SDL_TRUE;
+#ifdef __GNUC__
+ int u1, u2;
+#endif
+#endif /* USE_ASM_STRETCH */
+ const int bpp = dst->format->BytesPerPixel;
+
+ if (src->format->format != dst->format->format) {
+ return SDL_SetError("Only works with same format surfaces");
+ }
+
+ /* Verify the blit rectangles */
+ if (srcrect) {
+ if ((srcrect->x < 0) || (srcrect->y < 0) ||
+ ((srcrect->x + srcrect->w) > src->w) ||
+ ((srcrect->y + srcrect->h) > src->h)) {
+ return SDL_SetError("Invalid source blit rectangle");
+ }
+ } else {
+ full_src.x = 0;
+ full_src.y = 0;
+ full_src.w = src->w;
+ full_src.h = src->h;
+ srcrect = &full_src;
+ }
+ if (dstrect) {
+ if ((dstrect->x < 0) || (dstrect->y < 0) ||
+ ((dstrect->x + dstrect->w) > dst->w) ||
+ ((dstrect->y + dstrect->h) > dst->h)) {
+ return SDL_SetError("Invalid destination blit rectangle");
+ }
+ } else {
+ full_dst.x = 0;
+ full_dst.y = 0;
+ full_dst.w = dst->w;
+ full_dst.h = dst->h;
+ dstrect = &full_dst;
+ }
+
+ /* Lock the destination if it's in hardware */
+ dst_locked = 0;
+ if (SDL_MUSTLOCK(dst)) {
+ if (SDL_LockSurface(dst) < 0) {
+ return SDL_SetError("Unable to lock destination surface");
+ }
+ dst_locked = 1;
+ }
+ /* Lock the source if it's in hardware */
+ src_locked = 0;
+ if (SDL_MUSTLOCK(src)) {
+ if (SDL_LockSurface(src) < 0) {
+ if (dst_locked) {
+ SDL_UnlockSurface(dst);
+ }
+ return SDL_SetError("Unable to lock source surface");
+ }
+ src_locked = 1;
+ }
+
+ /* Set up the data... */
+ pos = 0x10000;
+ inc = (srcrect->h << 16) / dstrect->h;
+ src_row = srcrect->y;
+ dst_row = dstrect->y;
+
+#ifdef USE_ASM_STRETCH
+ /* Write the opcodes for this stretch */
+ if ((bpp == 3) || (generate_rowbytes(srcrect->w, dstrect->w, bpp) < 0)) {
+ use_asm = SDL_FALSE;
+ }
+#endif
+
+ /* Perform the stretch blit */
+ for (dst_maxrow = dst_row + dstrect->h; dst_row < dst_maxrow; ++dst_row) {
+ dstp = (Uint8 *) dst->pixels + (dst_row * dst->pitch)
+ + (dstrect->x * bpp);
+ while (pos >= 0x10000L) {
+ srcp = (Uint8 *) src->pixels + (src_row * src->pitch)
+ + (srcrect->x * bpp);
+ ++src_row;
+ pos -= 0x10000L;
+ }
+#ifdef USE_ASM_STRETCH
+ if (use_asm) {
+#ifdef __GNUC__
+ __asm__ __volatile__("call *%4":"=&D"(u1), "=&S"(u2)
+ :"0"(dstp), "1"(srcp), "r"(copy_row)
+ :"memory");
+#elif defined(_MSC_VER) || defined(__WATCOMC__)
+ /* *INDENT-OFF* */
+ {
+ void *code = copy_row;
+ __asm {
+ push edi
+ push esi
+ mov edi, dstp
+ mov esi, srcp
+ call dword ptr code
+ pop esi
+ pop edi
+ }
+ }
+ /* *INDENT-ON* */
+#else
+#error Need inline assembly for this compiler
+#endif
+ } else
+#endif
+ switch (bpp) {
+ case 1:
+ copy_row1(srcp, srcrect->w, dstp, dstrect->w);
+ break;
+ case 2:
+ copy_row2((Uint16 *) srcp, srcrect->w,
+ (Uint16 *) dstp, dstrect->w);
+ break;
+ case 3:
+ copy_row3(srcp, srcrect->w, dstp, dstrect->w);
+ break;
+ case 4:
+ copy_row4((Uint32 *) srcp, srcrect->w,
+ (Uint32 *) dstp, dstrect->w);
+ break;
+ }
+ pos += inc;
+ }
+
+ /* We need to unlock the surfaces if they're locked */
+ if (dst_locked) {
+ SDL_UnlockSurface(dst);
+ }
+ if (src_locked) {
+ SDL_UnlockSurface(src);
+ }
+ return (0);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_surface.c b/src/3rdparty/SDL2/src/video/SDL_surface.c
new file mode 100644
index 0000000..719f831
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_surface.c
@@ -0,0 +1,1232 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "SDL_video.h"
+#include "SDL_sysvideo.h"
+#include "SDL_blit.h"
+#include "SDL_RLEaccel_c.h"
+#include "SDL_pixels_c.h"
+#include "SDL_yuv_c.h"
+
+
+/* Check to make sure we can safely check multiplication of surface w and pitch and it won't overflow size_t */
+SDL_COMPILE_TIME_ASSERT(surface_size_assumptions,
+ sizeof(int) == sizeof(Sint32) && sizeof(size_t) >= sizeof(Sint32));
+
+/* Public routines */
+
+/*
+ * Calculate the pad-aligned scanline width of a surface
+ */
+int
+SDL_CalculatePitch(Uint32 format, int width)
+{
+ int pitch;
+
+ /* Surface should be 4-byte aligned for speed */
+ pitch = width * SDL_BYTESPERPIXEL(format);
+ switch (SDL_BITSPERPIXEL(format)) {
+ case 1:
+ pitch = (pitch + 7) / 8;
+ break;
+ case 4:
+ pitch = (pitch + 1) / 2;
+ break;
+ default:
+ break;
+ }
+ pitch = (pitch + 3) & ~3; /* 4-byte aligning */
+ return pitch;
+}
+
+/*
+ * Create an empty RGB surface of the appropriate depth using the given
+ * enum SDL_PIXELFORMAT_* format
+ */
+SDL_Surface *
+SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth,
+ Uint32 format)
+{
+ SDL_Surface *surface;
+
+ /* The flags are no longer used, make the compiler happy */
+ (void)flags;
+
+ /* Allocate the surface */
+ surface = (SDL_Surface *) SDL_calloc(1, sizeof(*surface));
+ if (surface == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ surface->format = SDL_AllocFormat(format);
+ if (!surface->format) {
+ SDL_FreeSurface(surface);
+ return NULL;
+ }
+ surface->w = width;
+ surface->h = height;
+ surface->pitch = SDL_CalculatePitch(format, width);
+ SDL_SetClipRect(surface, NULL);
+
+ if (SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
+ SDL_Palette *palette =
+ SDL_AllocPalette((1 << surface->format->BitsPerPixel));
+ if (!palette) {
+ SDL_FreeSurface(surface);
+ return NULL;
+ }
+ if (palette->ncolors == 2) {
+ /* Create a black and white bitmap palette */
+ palette->colors[0].r = 0xFF;
+ palette->colors[0].g = 0xFF;
+ palette->colors[0].b = 0xFF;
+ palette->colors[1].r = 0x00;
+ palette->colors[1].g = 0x00;
+ palette->colors[1].b = 0x00;
+ }
+ SDL_SetSurfacePalette(surface, palette);
+ SDL_FreePalette(palette);
+ }
+
+ /* Get the pixels */
+ if (surface->w && surface->h) {
+ /* Assumptions checked in surface_size_assumptions assert above */
+ Sint64 size = ((Sint64)surface->h * surface->pitch);
+ if (size < 0 || size > SDL_MAX_SINT32) {
+ /* Overflow... */
+ SDL_FreeSurface(surface);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ surface->pixels = SDL_malloc((size_t)size);
+ if (!surface->pixels) {
+ SDL_FreeSurface(surface);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ /* This is important for bitmaps */
+ SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
+ }
+
+ /* Allocate an empty mapping */
+ surface->map = SDL_AllocBlitMap();
+ if (!surface->map) {
+ SDL_FreeSurface(surface);
+ return NULL;
+ }
+
+ /* By default surface with an alpha mask are set up for blending */
+ if (surface->format->Amask) {
+ SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
+ }
+
+ /* The surface is ready to go */
+ surface->refcount = 1;
+ return surface;
+}
+
+/*
+ * Create an empty RGB surface of the appropriate depth
+ */
+SDL_Surface *
+SDL_CreateRGBSurface(Uint32 flags,
+ int width, int height, int depth,
+ Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
+{
+ Uint32 format;
+
+ /* Get the pixel format */
+ format = SDL_MasksToPixelFormatEnum(depth, Rmask, Gmask, Bmask, Amask);
+ if (format == SDL_PIXELFORMAT_UNKNOWN) {
+ SDL_SetError("Unknown pixel format");
+ return NULL;
+ }
+
+ return SDL_CreateRGBSurfaceWithFormat(flags, width, height, depth, format);
+}
+
+/*
+ * Create an RGB surface from an existing memory buffer
+ */
+SDL_Surface *
+SDL_CreateRGBSurfaceFrom(void *pixels,
+ int width, int height, int depth, int pitch,
+ Uint32 Rmask, Uint32 Gmask, Uint32 Bmask,
+ Uint32 Amask)
+{
+ SDL_Surface *surface;
+
+ surface = SDL_CreateRGBSurface(0, 0, 0, depth, Rmask, Gmask, Bmask, Amask);
+ if (surface != NULL) {
+ surface->flags |= SDL_PREALLOC;
+ surface->pixels = pixels;
+ surface->w = width;
+ surface->h = height;
+ surface->pitch = pitch;
+ SDL_SetClipRect(surface, NULL);
+ }
+ return surface;
+}
+
+/*
+ * Create an RGB surface from an existing memory buffer using the given given
+ * enum SDL_PIXELFORMAT_* format
+ */
+SDL_Surface *
+SDL_CreateRGBSurfaceWithFormatFrom(void *pixels,
+ int width, int height, int depth, int pitch,
+ Uint32 format)
+{
+ SDL_Surface *surface;
+
+ surface = SDL_CreateRGBSurfaceWithFormat(0, 0, 0, depth, format);
+ if (surface != NULL) {
+ surface->flags |= SDL_PREALLOC;
+ surface->pixels = pixels;
+ surface->w = width;
+ surface->h = height;
+ surface->pitch = pitch;
+ SDL_SetClipRect(surface, NULL);
+ }
+ return surface;
+}
+
+int
+SDL_SetSurfacePalette(SDL_Surface * surface, SDL_Palette * palette)
+{
+ if (!surface) {
+ return SDL_SetError("SDL_SetSurfacePalette() passed a NULL surface");
+ }
+ if (SDL_SetPixelFormatPalette(surface->format, palette) < 0) {
+ return -1;
+ }
+ SDL_InvalidateMap(surface->map);
+
+ return 0;
+}
+
+int
+SDL_SetSurfaceRLE(SDL_Surface * surface, int flag)
+{
+ int flags;
+
+ if (!surface) {
+ return -1;
+ }
+
+ flags = surface->map->info.flags;
+ if (flag) {
+ surface->map->info.flags |= SDL_COPY_RLE_DESIRED;
+ } else {
+ surface->map->info.flags &= ~SDL_COPY_RLE_DESIRED;
+ }
+ if (surface->map->info.flags != flags) {
+ SDL_InvalidateMap(surface->map);
+ }
+ return 0;
+}
+
+int
+SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key)
+{
+ int flags;
+
+ if (!surface) {
+ return SDL_InvalidParamError("surface");
+ }
+
+ if (surface->format->palette && key >= ((Uint32) surface->format->palette->ncolors)) {
+ return SDL_InvalidParamError("key");
+ }
+
+ if (flag & SDL_RLEACCEL) {
+ SDL_SetSurfaceRLE(surface, 1);
+ }
+
+ flags = surface->map->info.flags;
+ if (flag) {
+ surface->map->info.flags |= SDL_COPY_COLORKEY;
+ surface->map->info.colorkey = key;
+ if (surface->format->palette) {
+ surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_TRANSPARENT;
+ ++surface->format->palette->version;
+ if (!surface->format->palette->version) {
+ surface->format->palette->version = 1;
+ }
+ }
+ } else {
+ if (surface->format->palette) {
+ surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_OPAQUE;
+ ++surface->format->palette->version;
+ if (!surface->format->palette->version) {
+ surface->format->palette->version = 1;
+ }
+ }
+ surface->map->info.flags &= ~SDL_COPY_COLORKEY;
+ }
+ if (surface->map->info.flags != flags) {
+ SDL_InvalidateMap(surface->map);
+ }
+
+ return 0;
+}
+
+int
+SDL_GetColorKey(SDL_Surface * surface, Uint32 * key)
+{
+ if (!surface) {
+ return SDL_InvalidParamError("surface");
+ }
+
+ if (!(surface->map->info.flags & SDL_COPY_COLORKEY)) {
+ return SDL_SetError("Surface doesn't have a colorkey");
+ }
+
+ if (key) {
+ *key = surface->map->info.colorkey;
+ }
+ return 0;
+}
+
+/* This is a fairly slow function to switch from colorkey to alpha */
+static void
+SDL_ConvertColorkeyToAlpha(SDL_Surface * surface)
+{
+ int x, y;
+
+ if (!surface) {
+ return;
+ }
+
+ if (!(surface->map->info.flags & SDL_COPY_COLORKEY) ||
+ !surface->format->Amask) {
+ return;
+ }
+
+ SDL_LockSurface(surface);
+
+ switch (surface->format->BytesPerPixel) {
+ case 2:
+ {
+ Uint16 *row, *spot;
+ Uint16 ckey = (Uint16) surface->map->info.colorkey;
+ Uint16 mask = (Uint16) (~surface->format->Amask);
+
+ /* Ignore alpha in colorkey comparison */
+ ckey &= mask;
+ row = (Uint16 *) surface->pixels;
+ for (y = surface->h; y--;) {
+ spot = row;
+ for (x = surface->w; x--;) {
+ if ((*spot & mask) == ckey) {
+ *spot &= mask;
+ }
+ ++spot;
+ }
+ row += surface->pitch / 2;
+ }
+ }
+ break;
+ case 3:
+ /* FIXME */
+ break;
+ case 4:
+ {
+ Uint32 *row, *spot;
+ Uint32 ckey = surface->map->info.colorkey;
+ Uint32 mask = ~surface->format->Amask;
+
+ /* Ignore alpha in colorkey comparison */
+ ckey &= mask;
+ row = (Uint32 *) surface->pixels;
+ for (y = surface->h; y--;) {
+ spot = row;
+ for (x = surface->w; x--;) {
+ if ((*spot & mask) == ckey) {
+ *spot &= mask;
+ }
+ ++spot;
+ }
+ row += surface->pitch / 4;
+ }
+ }
+ break;
+ }
+
+ SDL_UnlockSurface(surface);
+
+ SDL_SetColorKey(surface, 0, 0);
+ SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
+}
+
+int
+SDL_SetSurfaceColorMod(SDL_Surface * surface, Uint8 r, Uint8 g, Uint8 b)
+{
+ int flags;
+
+ if (!surface) {
+ return -1;
+ }
+
+ surface->map->info.r = r;
+ surface->map->info.g = g;
+ surface->map->info.b = b;
+
+ flags = surface->map->info.flags;
+ if (r != 0xFF || g != 0xFF || b != 0xFF) {
+ surface->map->info.flags |= SDL_COPY_MODULATE_COLOR;
+ } else {
+ surface->map->info.flags &= ~SDL_COPY_MODULATE_COLOR;
+ }
+ if (surface->map->info.flags != flags) {
+ SDL_InvalidateMap(surface->map);
+ }
+ return 0;
+}
+
+
+int
+SDL_GetSurfaceColorMod(SDL_Surface * surface, Uint8 * r, Uint8 * g, Uint8 * b)
+{
+ if (!surface) {
+ return -1;
+ }
+
+ if (r) {
+ *r = surface->map->info.r;
+ }
+ if (g) {
+ *g = surface->map->info.g;
+ }
+ if (b) {
+ *b = surface->map->info.b;
+ }
+ return 0;
+}
+
+int
+SDL_SetSurfaceAlphaMod(SDL_Surface * surface, Uint8 alpha)
+{
+ int flags;
+
+ if (!surface) {
+ return -1;
+ }
+
+ surface->map->info.a = alpha;
+
+ flags = surface->map->info.flags;
+ if (alpha != 0xFF) {
+ surface->map->info.flags |= SDL_COPY_MODULATE_ALPHA;
+ } else {
+ surface->map->info.flags &= ~SDL_COPY_MODULATE_ALPHA;
+ }
+ if (surface->map->info.flags != flags) {
+ SDL_InvalidateMap(surface->map);
+ }
+ return 0;
+}
+
+int
+SDL_GetSurfaceAlphaMod(SDL_Surface * surface, Uint8 * alpha)
+{
+ if (!surface) {
+ return -1;
+ }
+
+ if (alpha) {
+ *alpha = surface->map->info.a;
+ }
+ return 0;
+}
+
+int
+SDL_SetSurfaceBlendMode(SDL_Surface * surface, SDL_BlendMode blendMode)
+{
+ int flags, status;
+
+ if (!surface) {
+ return -1;
+ }
+
+ status = 0;
+ flags = surface->map->info.flags;
+ surface->map->info.flags &=
+ ~(SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD);
+ switch (blendMode) {
+ case SDL_BLENDMODE_NONE:
+ break;
+ case SDL_BLENDMODE_BLEND:
+ surface->map->info.flags |= SDL_COPY_BLEND;
+ break;
+ case SDL_BLENDMODE_ADD:
+ surface->map->info.flags |= SDL_COPY_ADD;
+ break;
+ case SDL_BLENDMODE_MOD:
+ surface->map->info.flags |= SDL_COPY_MOD;
+ break;
+ default:
+ status = SDL_Unsupported();
+ break;
+ }
+
+ if (surface->map->info.flags != flags) {
+ SDL_InvalidateMap(surface->map);
+ }
+
+ return status;
+}
+
+int
+SDL_GetSurfaceBlendMode(SDL_Surface * surface, SDL_BlendMode *blendMode)
+{
+ if (!surface) {
+ return -1;
+ }
+
+ if (!blendMode) {
+ return 0;
+ }
+
+ switch (surface->map->
+ info.flags & (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ *blendMode = SDL_BLENDMODE_BLEND;
+ break;
+ case SDL_COPY_ADD:
+ *blendMode = SDL_BLENDMODE_ADD;
+ break;
+ case SDL_COPY_MOD:
+ *blendMode = SDL_BLENDMODE_MOD;
+ break;
+ default:
+ *blendMode = SDL_BLENDMODE_NONE;
+ break;
+ }
+ return 0;
+}
+
+SDL_bool
+SDL_SetClipRect(SDL_Surface * surface, const SDL_Rect * rect)
+{
+ SDL_Rect full_rect;
+
+ /* Don't do anything if there's no surface to act on */
+ if (!surface) {
+ return SDL_FALSE;
+ }
+
+ /* Set up the full surface rectangle */
+ full_rect.x = 0;
+ full_rect.y = 0;
+ full_rect.w = surface->w;
+ full_rect.h = surface->h;
+
+ /* Set the clipping rectangle */
+ if (!rect) {
+ surface->clip_rect = full_rect;
+ return SDL_TRUE;
+ }
+ return SDL_IntersectRect(rect, &full_rect, &surface->clip_rect);
+}
+
+void
+SDL_GetClipRect(SDL_Surface * surface, SDL_Rect * rect)
+{
+ if (surface && rect) {
+ *rect = surface->clip_rect;
+ }
+}
+
+/*
+ * Set up a blit between two surfaces -- split into three parts:
+ * The upper part, SDL_UpperBlit(), performs clipping and rectangle
+ * verification. The lower part is a pointer to a low level
+ * accelerated blitting function.
+ *
+ * These parts are separated out and each used internally by this
+ * library in the optimimum places. They are exported so that if
+ * you know exactly what you are doing, you can optimize your code
+ * by calling the one(s) you need.
+ */
+int
+SDL_LowerBlit(SDL_Surface * src, SDL_Rect * srcrect,
+ SDL_Surface * dst, SDL_Rect * dstrect)
+{
+ /* Check to make sure the blit mapping is valid */
+ if ((src->map->dst != dst) ||
+ (dst->format->palette &&
+ src->map->dst_palette_version != dst->format->palette->version) ||
+ (src->format->palette &&
+ src->map->src_palette_version != src->format->palette->version)) {
+ if (SDL_MapSurface(src, dst) < 0) {
+ return (-1);
+ }
+ /* just here for debugging */
+/* printf */
+/* ("src = 0x%08X src->flags = %08X src->map->info.flags = %08x\ndst = 0x%08X dst->flags = %08X dst->map->info.flags = %08X\nsrc->map->blit = 0x%08x\n", */
+/* src, dst->flags, src->map->info.flags, dst, dst->flags, */
+/* dst->map->info.flags, src->map->blit); */
+ }
+ return (src->map->blit(src, srcrect, dst, dstrect));
+}
+
+
+int
+SDL_UpperBlit(SDL_Surface * src, const SDL_Rect * srcrect,
+ SDL_Surface * dst, SDL_Rect * dstrect)
+{
+ SDL_Rect fulldst;
+ int srcx, srcy, w, h;
+
+ /* Make sure the surfaces aren't locked */
+ if (!src || !dst) {
+ return SDL_SetError("SDL_UpperBlit: passed a NULL surface");
+ }
+ if (src->locked || dst->locked) {
+ return SDL_SetError("Surfaces must not be locked during blit");
+ }
+
+ /* If the destination rectangle is NULL, use the entire dest surface */
+ if (dstrect == NULL) {
+ fulldst.x = fulldst.y = 0;
+ fulldst.w = dst->w;
+ fulldst.h = dst->h;
+ dstrect = &fulldst;
+ }
+
+ /* clip the source rectangle to the source surface */
+ if (srcrect) {
+ int maxw, maxh;
+
+ srcx = srcrect->x;
+ w = srcrect->w;
+ if (srcx < 0) {
+ w += srcx;
+ dstrect->x -= srcx;
+ srcx = 0;
+ }
+ maxw = src->w - srcx;
+ if (maxw < w)
+ w = maxw;
+
+ srcy = srcrect->y;
+ h = srcrect->h;
+ if (srcy < 0) {
+ h += srcy;
+ dstrect->y -= srcy;
+ srcy = 0;
+ }
+ maxh = src->h - srcy;
+ if (maxh < h)
+ h = maxh;
+
+ } else {
+ srcx = srcy = 0;
+ w = src->w;
+ h = src->h;
+ }
+
+ /* clip the destination rectangle against the clip rectangle */
+ {
+ SDL_Rect *clip = &dst->clip_rect;
+ int dx, dy;
+
+ dx = clip->x - dstrect->x;
+ if (dx > 0) {
+ w -= dx;
+ dstrect->x += dx;
+ srcx += dx;
+ }
+ dx = dstrect->x + w - clip->x - clip->w;
+ if (dx > 0)
+ w -= dx;
+
+ dy = clip->y - dstrect->y;
+ if (dy > 0) {
+ h -= dy;
+ dstrect->y += dy;
+ srcy += dy;
+ }
+ dy = dstrect->y + h - clip->y - clip->h;
+ if (dy > 0)
+ h -= dy;
+ }
+
+ /* Switch back to a fast blit if we were previously stretching */
+ if (src->map->info.flags & SDL_COPY_NEAREST) {
+ src->map->info.flags &= ~SDL_COPY_NEAREST;
+ SDL_InvalidateMap(src->map);
+ }
+
+ if (w > 0 && h > 0) {
+ SDL_Rect sr;
+ sr.x = srcx;
+ sr.y = srcy;
+ sr.w = dstrect->w = w;
+ sr.h = dstrect->h = h;
+ return SDL_LowerBlit(src, &sr, dst, dstrect);
+ }
+ dstrect->w = dstrect->h = 0;
+ return 0;
+}
+
+int
+SDL_UpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect,
+ SDL_Surface * dst, SDL_Rect * dstrect)
+{
+ double src_x0, src_y0, src_x1, src_y1;
+ double dst_x0, dst_y0, dst_x1, dst_y1;
+ SDL_Rect final_src, final_dst;
+ double scaling_w, scaling_h;
+ int src_w, src_h;
+ int dst_w, dst_h;
+
+ /* Make sure the surfaces aren't locked */
+ if (!src || !dst) {
+ return SDL_SetError("SDL_UpperBlitScaled: passed a NULL surface");
+ }
+ if (src->locked || dst->locked) {
+ return SDL_SetError("Surfaces must not be locked during blit");
+ }
+
+ if (NULL == srcrect) {
+ src_w = src->w;
+ src_h = src->h;
+ } else {
+ src_w = srcrect->w;
+ src_h = srcrect->h;
+ }
+
+ if (NULL == dstrect) {
+ dst_w = dst->w;
+ dst_h = dst->h;
+ } else {
+ dst_w = dstrect->w;
+ dst_h = dstrect->h;
+ }
+
+ if (dst_w == src_w && dst_h == src_h) {
+ /* No scaling, defer to regular blit */
+ return SDL_BlitSurface(src, srcrect, dst, dstrect);
+ }
+
+ scaling_w = (double)dst_w / src_w;
+ scaling_h = (double)dst_h / src_h;
+
+ if (NULL == dstrect) {
+ dst_x0 = 0;
+ dst_y0 = 0;
+ dst_x1 = dst_w - 1;
+ dst_y1 = dst_h - 1;
+ } else {
+ dst_x0 = dstrect->x;
+ dst_y0 = dstrect->y;
+ dst_x1 = dst_x0 + dst_w - 1;
+ dst_y1 = dst_y0 + dst_h - 1;
+ }
+
+ if (NULL == srcrect) {
+ src_x0 = 0;
+ src_y0 = 0;
+ src_x1 = src_w - 1;
+ src_y1 = src_h - 1;
+ } else {
+ src_x0 = srcrect->x;
+ src_y0 = srcrect->y;
+ src_x1 = src_x0 + src_w - 1;
+ src_y1 = src_y0 + src_h - 1;
+
+ /* Clip source rectangle to the source surface */
+
+ if (src_x0 < 0) {
+ dst_x0 -= src_x0 * scaling_w;
+ src_x0 = 0;
+ }
+
+ if (src_x1 >= src->w) {
+ dst_x1 -= (src_x1 - src->w + 1) * scaling_w;
+ src_x1 = src->w - 1;
+ }
+
+ if (src_y0 < 0) {
+ dst_y0 -= src_y0 * scaling_h;
+ src_y0 = 0;
+ }
+
+ if (src_y1 >= src->h) {
+ dst_y1 -= (src_y1 - src->h + 1) * scaling_h;
+ src_y1 = src->h - 1;
+ }
+ }
+
+ /* Clip destination rectangle to the clip rectangle */
+
+ /* Translate to clip space for easier calculations */
+ dst_x0 -= dst->clip_rect.x;
+ dst_x1 -= dst->clip_rect.x;
+ dst_y0 -= dst->clip_rect.y;
+ dst_y1 -= dst->clip_rect.y;
+
+ if (dst_x0 < 0) {
+ src_x0 -= dst_x0 / scaling_w;
+ dst_x0 = 0;
+ }
+
+ if (dst_x1 >= dst->clip_rect.w) {
+ src_x1 -= (dst_x1 - dst->clip_rect.w + 1) / scaling_w;
+ dst_x1 = dst->clip_rect.w - 1;
+ }
+
+ if (dst_y0 < 0) {
+ src_y0 -= dst_y0 / scaling_h;
+ dst_y0 = 0;
+ }
+
+ if (dst_y1 >= dst->clip_rect.h) {
+ src_y1 -= (dst_y1 - dst->clip_rect.h + 1) / scaling_h;
+ dst_y1 = dst->clip_rect.h - 1;
+ }
+
+ /* Translate back to surface coordinates */
+ dst_x0 += dst->clip_rect.x;
+ dst_x1 += dst->clip_rect.x;
+ dst_y0 += dst->clip_rect.y;
+ dst_y1 += dst->clip_rect.y;
+
+ final_src.x = (int)SDL_floor(src_x0 + 0.5);
+ final_src.y = (int)SDL_floor(src_y0 + 0.5);
+ final_src.w = (int)SDL_floor(src_x1 + 1 + 0.5) - (int)SDL_floor(src_x0 + 0.5);
+ final_src.h = (int)SDL_floor(src_y1 + 1 + 0.5) - (int)SDL_floor(src_y0 + 0.5);
+
+ final_dst.x = (int)SDL_floor(dst_x0 + 0.5);
+ final_dst.y = (int)SDL_floor(dst_y0 + 0.5);
+ final_dst.w = (int)SDL_floor(dst_x1 - dst_x0 + 1.5);
+ final_dst.h = (int)SDL_floor(dst_y1 - dst_y0 + 1.5);
+
+ if (final_dst.w < 0)
+ final_dst.w = 0;
+ if (final_dst.h < 0)
+ final_dst.h = 0;
+
+ if (dstrect)
+ *dstrect = final_dst;
+
+ if (final_dst.w == 0 || final_dst.h == 0 ||
+ final_src.w <= 0 || final_src.h <= 0) {
+ /* No-op. */
+ return 0;
+ }
+
+ return SDL_LowerBlitScaled(src, &final_src, dst, &final_dst);
+}
+
+/**
+ * This is a semi-private blit function and it performs low-level surface
+ * scaled blitting only.
+ */
+int
+SDL_LowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect,
+ SDL_Surface * dst, SDL_Rect * dstrect)
+{
+ static const Uint32 complex_copy_flags = (
+ SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA |
+ SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD |
+ SDL_COPY_COLORKEY
+ );
+
+ if (!(src->map->info.flags & SDL_COPY_NEAREST)) {
+ src->map->info.flags |= SDL_COPY_NEAREST;
+ SDL_InvalidateMap(src->map);
+ }
+
+ if ( !(src->map->info.flags & complex_copy_flags) &&
+ src->format->format == dst->format->format &&
+ !SDL_ISPIXELFORMAT_INDEXED(src->format->format) ) {
+ return SDL_SoftStretch( src, srcrect, dst, dstrect );
+ } else {
+ return SDL_LowerBlit( src, srcrect, dst, dstrect );
+ }
+}
+
+/*
+ * Lock a surface to directly access the pixels
+ */
+int
+SDL_LockSurface(SDL_Surface * surface)
+{
+ if (!surface->locked) {
+ /* Perform the lock */
+ if (surface->flags & SDL_RLEACCEL) {
+ SDL_UnRLESurface(surface, 1);
+ surface->flags |= SDL_RLEACCEL; /* save accel'd state */
+ }
+ }
+
+ /* Increment the surface lock count, for recursive locks */
+ ++surface->locked;
+
+ /* Ready to go.. */
+ return (0);
+}
+
+/*
+ * Unlock a previously locked surface
+ */
+void
+SDL_UnlockSurface(SDL_Surface * surface)
+{
+ /* Only perform an unlock if we are locked */
+ if (!surface->locked || (--surface->locked > 0)) {
+ return;
+ }
+
+ /* Update RLE encoded surface with new data */
+ if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
+ surface->flags &= ~SDL_RLEACCEL; /* stop lying */
+ SDL_RLESurface(surface);
+ }
+}
+
+/*
+ * Creates a new surface identical to the existing surface
+ */
+SDL_Surface *
+SDL_DuplicateSurface(SDL_Surface * surface)
+{
+ return SDL_ConvertSurface(surface, surface->format, surface->flags);
+}
+
+/*
+ * Convert a surface into the specified pixel format.
+ */
+SDL_Surface *
+SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
+ Uint32 flags)
+{
+ SDL_Surface *convert;
+ Uint32 copy_flags;
+ SDL_Color copy_color;
+ SDL_Rect bounds;
+
+ if (!surface) {
+ SDL_InvalidParamError("surface");
+ return NULL;
+ }
+ if (!format) {
+ SDL_InvalidParamError("format");
+ return NULL;
+ }
+
+ /* Check for empty destination palette! (results in empty image) */
+ if (format->palette != NULL) {
+ int i;
+ for (i = 0; i < format->palette->ncolors; ++i) {
+ if ((format->palette->colors[i].r != 0xFF) ||
+ (format->palette->colors[i].g != 0xFF) ||
+ (format->palette->colors[i].b != 0xFF))
+ break;
+ }
+ if (i == format->palette->ncolors) {
+ SDL_SetError("Empty destination palette");
+ return (NULL);
+ }
+ }
+
+ /* Create a new surface with the desired format */
+ convert = SDL_CreateRGBSurface(flags, surface->w, surface->h,
+ format->BitsPerPixel, format->Rmask,
+ format->Gmask, format->Bmask,
+ format->Amask);
+ if (convert == NULL) {
+ return (NULL);
+ }
+
+ /* Copy the palette if any */
+ if (format->palette && convert->format->palette) {
+ SDL_memcpy(convert->format->palette->colors,
+ format->palette->colors,
+ format->palette->ncolors * sizeof(SDL_Color));
+ convert->format->palette->ncolors = format->palette->ncolors;
+ }
+
+ /* Save the original copy flags */
+ copy_flags = surface->map->info.flags;
+ copy_color.r = surface->map->info.r;
+ copy_color.g = surface->map->info.g;
+ copy_color.b = surface->map->info.b;
+ copy_color.a = surface->map->info.a;
+ surface->map->info.r = 0xFF;
+ surface->map->info.g = 0xFF;
+ surface->map->info.b = 0xFF;
+ surface->map->info.a = 0xFF;
+ surface->map->info.flags = 0;
+ SDL_InvalidateMap(surface->map);
+
+ /* Copy over the image data */
+ bounds.x = 0;
+ bounds.y = 0;
+ bounds.w = surface->w;
+ bounds.h = surface->h;
+ SDL_LowerBlit(surface, &bounds, convert, &bounds);
+
+ /* Clean up the original surface, and update converted surface */
+ convert->map->info.r = copy_color.r;
+ convert->map->info.g = copy_color.g;
+ convert->map->info.b = copy_color.b;
+ convert->map->info.a = copy_color.a;
+ convert->map->info.flags =
+ (copy_flags &
+ ~(SDL_COPY_COLORKEY | SDL_COPY_BLEND
+ | SDL_COPY_RLE_DESIRED | SDL_COPY_RLE_COLORKEY |
+ SDL_COPY_RLE_ALPHAKEY));
+ surface->map->info.r = copy_color.r;
+ surface->map->info.g = copy_color.g;
+ surface->map->info.b = copy_color.b;
+ surface->map->info.a = copy_color.a;
+ surface->map->info.flags = copy_flags;
+ SDL_InvalidateMap(surface->map);
+ if (copy_flags & SDL_COPY_COLORKEY) {
+ SDL_bool set_colorkey_by_color = SDL_FALSE;
+
+ if (surface->format->palette) {
+ if (format->palette &&
+ surface->format->palette->ncolors <= format->palette->ncolors &&
+ (SDL_memcmp(surface->format->palette->colors, format->palette->colors,
+ surface->format->palette->ncolors * sizeof(SDL_Color)) == 0)) {
+ /* The palette is identical, just set the same colorkey */
+ SDL_SetColorKey(convert, 1, surface->map->info.colorkey);
+ } else if (format->Amask) {
+ /* The alpha was set in the destination from the palette */
+ } else {
+ set_colorkey_by_color = SDL_TRUE;
+ }
+ } else {
+ set_colorkey_by_color = SDL_TRUE;
+ }
+
+ if (set_colorkey_by_color) {
+ SDL_Surface *tmp;
+ SDL_Surface *tmp2;
+ int converted_colorkey = 0;
+
+ /* Create a dummy surface to get the colorkey converted */
+ tmp = SDL_CreateRGBSurface(0, 1, 1,
+ surface->format->BitsPerPixel, surface->format->Rmask,
+ surface->format->Gmask, surface->format->Bmask,
+ surface->format->Amask);
+
+ /* Share the palette, if any */
+ if (surface->format->palette) {
+ SDL_SetSurfacePalette(tmp, surface->format->palette);
+ }
+
+ SDL_FillRect(tmp, NULL, surface->map->info.colorkey);
+
+ tmp->map->info.flags &= ~SDL_COPY_COLORKEY;
+
+ /* Convertion of the colorkey */
+ tmp2 = SDL_ConvertSurface(tmp, format, 0);
+
+ /* Get the converted colorkey */
+ SDL_memcpy(&converted_colorkey, tmp2->pixels, tmp2->format->BytesPerPixel);
+
+ SDL_FreeSurface(tmp);
+ SDL_FreeSurface(tmp2);
+
+ /* Set the converted colorkey on the new surface */
+ SDL_SetColorKey(convert, 1, converted_colorkey);
+
+ /* This is needed when converting for 3D texture upload */
+ SDL_ConvertColorkeyToAlpha(convert);
+ }
+ }
+ SDL_SetClipRect(convert, &surface->clip_rect);
+
+ /* Enable alpha blending by default if the new surface has an
+ * alpha channel or alpha modulation */
+ if ((surface->format->Amask && format->Amask) ||
+ (copy_flags & SDL_COPY_MODULATE_ALPHA)) {
+ SDL_SetSurfaceBlendMode(convert, SDL_BLENDMODE_BLEND);
+ }
+ if ((copy_flags & SDL_COPY_RLE_DESIRED) || (flags & SDL_RLEACCEL)) {
+ SDL_SetSurfaceRLE(convert, SDL_RLEACCEL);
+ }
+
+ /* We're ready to go! */
+ return (convert);
+}
+
+SDL_Surface *
+SDL_ConvertSurfaceFormat(SDL_Surface * surface, Uint32 pixel_format,
+ Uint32 flags)
+{
+ SDL_PixelFormat *fmt;
+ SDL_Surface *convert = NULL;
+
+ fmt = SDL_AllocFormat(pixel_format);
+ if (fmt) {
+ convert = SDL_ConvertSurface(surface, fmt, flags);
+ SDL_FreeFormat(fmt);
+ }
+ return convert;
+}
+
+/*
+ * Create a surface on the stack for quick blit operations
+ */
+static SDL_INLINE SDL_bool
+SDL_CreateSurfaceOnStack(int width, int height, Uint32 pixel_format,
+ void * pixels, int pitch, SDL_Surface * surface,
+ SDL_PixelFormat * format, SDL_BlitMap * blitmap)
+{
+ if (SDL_ISPIXELFORMAT_INDEXED(pixel_format)) {
+ SDL_SetError("Indexed pixel formats not supported");
+ return SDL_FALSE;
+ }
+ if (SDL_InitFormat(format, pixel_format) < 0) {
+ return SDL_FALSE;
+ }
+
+ SDL_zerop(surface);
+ surface->flags = SDL_PREALLOC;
+ surface->format = format;
+ surface->pixels = pixels;
+ surface->w = width;
+ surface->h = height;
+ surface->pitch = pitch;
+ /* We don't actually need to set up the clip rect for our purposes */
+ /* SDL_SetClipRect(surface, NULL); */
+
+ /* Allocate an empty mapping */
+ SDL_zerop(blitmap);
+ blitmap->info.r = 0xFF;
+ blitmap->info.g = 0xFF;
+ blitmap->info.b = 0xFF;
+ blitmap->info.a = 0xFF;
+ surface->map = blitmap;
+
+ /* The surface is ready to go */
+ surface->refcount = 1;
+ return SDL_TRUE;
+}
+
+/*
+ * Copy a block of pixels of one format to another format
+ */
+int SDL_ConvertPixels(int width, int height,
+ Uint32 src_format, const void * src, int src_pitch,
+ Uint32 dst_format, void * dst, int dst_pitch)
+{
+ SDL_Surface src_surface, dst_surface;
+ SDL_PixelFormat src_fmt, dst_fmt;
+ SDL_BlitMap src_blitmap, dst_blitmap;
+ SDL_Rect rect;
+ void *nonconst_src = (void *) src;
+
+ /* Check to make sure we are blitting somewhere, so we don't crash */
+ if (!dst) {
+ return SDL_InvalidParamError("dst");
+ }
+ if (!dst_pitch) {
+ return SDL_InvalidParamError("dst_pitch");
+ }
+
+ if (SDL_ISPIXELFORMAT_FOURCC(src_format) && SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
+ return SDL_ConvertPixels_YUV_to_YUV(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
+ } else if (SDL_ISPIXELFORMAT_FOURCC(src_format)) {
+ return SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
+ } else if (SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
+ return SDL_ConvertPixels_RGB_to_YUV(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
+ }
+
+ /* Fast path for same format copy */
+ if (src_format == dst_format) {
+ int i;
+ const int bpp = SDL_BYTESPERPIXEL(src_format);
+ width *= bpp;
+ for (i = height; i--;) {
+ SDL_memcpy(dst, src, width);
+ src = (const Uint8*)src + src_pitch;
+ dst = (Uint8*)dst + dst_pitch;
+ }
+ return 0;
+ }
+
+ if (!SDL_CreateSurfaceOnStack(width, height, src_format, nonconst_src,
+ src_pitch,
+ &src_surface, &src_fmt, &src_blitmap)) {
+ return -1;
+ }
+ if (!SDL_CreateSurfaceOnStack(width, height, dst_format, dst, dst_pitch,
+ &dst_surface, &dst_fmt, &dst_blitmap)) {
+ return -1;
+ }
+
+ /* Set up the rect and go! */
+ rect.x = 0;
+ rect.y = 0;
+ rect.w = width;
+ rect.h = height;
+ return SDL_LowerBlit(&src_surface, &rect, &dst_surface, &rect);
+}
+
+/*
+ * Free a surface created by the above function.
+ */
+void
+SDL_FreeSurface(SDL_Surface * surface)
+{
+ if (surface == NULL) {
+ return;
+ }
+ if (surface->flags & SDL_DONTFREE) {
+ return;
+ }
+ SDL_InvalidateMap(surface->map);
+
+ if (--surface->refcount > 0) {
+ return;
+ }
+ while (surface->locked > 0) {
+ SDL_UnlockSurface(surface);
+ }
+ if (surface->flags & SDL_RLEACCEL) {
+ SDL_UnRLESurface(surface, 0);
+ }
+ if (surface->format) {
+ SDL_SetSurfacePalette(surface, NULL);
+ SDL_FreeFormat(surface->format);
+ surface->format = NULL;
+ }
+ if (!(surface->flags & SDL_PREALLOC)) {
+ SDL_free(surface->pixels);
+ }
+ if (surface->map) {
+ SDL_FreeBlitMap(surface->map);
+ }
+ SDL_free(surface);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_sysvideo.h b/src/3rdparty/SDL2/src/video/SDL_sysvideo.h
new file mode 100644
index 0000000..9df71c9
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_sysvideo.h
@@ -0,0 +1,459 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#ifndef SDL_sysvideo_h_
+#define SDL_sysvideo_h_
+
+#include "SDL_messagebox.h"
+#include "SDL_shape.h"
+#include "SDL_thread.h"
+
+#include "SDL_vulkan_internal.h"
+
+/* The SDL video driver */
+
+typedef struct SDL_WindowShaper SDL_WindowShaper;
+typedef struct SDL_ShapeDriver SDL_ShapeDriver;
+typedef struct SDL_VideoDisplay SDL_VideoDisplay;
+typedef struct SDL_VideoDevice SDL_VideoDevice;
+
+/* Define the SDL window-shaper structure */
+struct SDL_WindowShaper
+{
+ /* The window associated with the shaper */
+ SDL_Window *window;
+
+ /* The user's specified coordinates for the window, for once we give it a shape. */
+ Uint32 userx,usery;
+
+ /* The parameters for shape calculation. */
+ SDL_WindowShapeMode mode;
+
+ /* Has this window been assigned a shape? */
+ SDL_bool hasshape;
+
+ void *driverdata;
+};
+
+/* Define the SDL shape driver structure */
+struct SDL_ShapeDriver
+{
+ SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
+ int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
+ int (*ResizeWindowShape)(SDL_Window *window);
+};
+
+typedef struct SDL_WindowUserData
+{
+ char *name;
+ void *data;
+ struct SDL_WindowUserData *next;
+} SDL_WindowUserData;
+
+/* Define the SDL window structure, corresponding to toplevel windows */
+struct SDL_Window
+{
+ const void *magic;
+ Uint32 id;
+ char *title;
+ SDL_Surface *icon;
+ int x, y;
+ int w, h;
+ int min_w, min_h;
+ int max_w, max_h;
+ Uint32 flags;
+ Uint32 last_fullscreen_flags;
+
+ /* Stored position and size for windowed mode */
+ SDL_Rect windowed;
+
+ SDL_DisplayMode fullscreen_mode;
+
+ float opacity;
+
+ float brightness;
+ Uint16 *gamma;
+ Uint16 *saved_gamma; /* (just offset into gamma) */
+
+ SDL_Surface *surface;
+ SDL_bool surface_valid;
+
+ SDL_bool is_hiding;
+ SDL_bool is_destroying;
+ SDL_bool is_dropping; /* drag/drop in progress, expecting SDL_SendDropComplete(). */
+
+ SDL_WindowShaper *shaper;
+
+ SDL_HitTest hit_test;
+ void *hit_test_data;
+
+ SDL_WindowUserData *data;
+
+ void *driverdata;
+
+ SDL_Window *prev;
+ SDL_Window *next;
+};
+#define FULLSCREEN_VISIBLE(W) \
+ (((W)->flags & SDL_WINDOW_FULLSCREEN) && \
+ ((W)->flags & SDL_WINDOW_SHOWN) && \
+ !((W)->flags & SDL_WINDOW_MINIMIZED))
+
+/*
+ * Define the SDL display structure This corresponds to physical monitors
+ * attached to the system.
+ */
+struct SDL_VideoDisplay
+{
+ char *name;
+ int max_display_modes;
+ int num_display_modes;
+ SDL_DisplayMode *display_modes;
+ SDL_DisplayMode desktop_mode;
+ SDL_DisplayMode current_mode;
+
+ SDL_Window *fullscreen_window;
+
+ SDL_VideoDevice *device;
+
+ void *driverdata;
+};
+
+/* Forward declaration */
+struct SDL_SysWMinfo;
+
+/* Define the SDL video driver structure */
+#define _THIS SDL_VideoDevice *_this
+
+struct SDL_VideoDevice
+{
+ /* * * */
+ /* The name of this video driver */
+ const char *name;
+
+ /* * * */
+ /* Initialization/Query functions */
+
+ /*
+ * Initialize the native video subsystem, filling in the list of
+ * displays for this driver, returning 0 or -1 if there's an error.
+ */
+ int (*VideoInit) (_THIS);
+
+ /*
+ * Reverse the effects VideoInit() -- called if VideoInit() fails or
+ * if the application is shutting down the video subsystem.
+ */
+ void (*VideoQuit) (_THIS);
+
+ /*
+ * Reinitialize the touch devices -- called if an unknown touch ID occurs.
+ */
+ void (*ResetTouch) (_THIS);
+
+ /* * * */
+ /*
+ * Display functions
+ */
+
+ /*
+ * Get the bounds of a display
+ */
+ int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
+
+ /*
+ * Get the dots/pixels-per-inch of a display
+ */
+ int (*GetDisplayDPI) (_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi);
+
+ /*
+ * Get the usable bounds of a display (bounds minus menubar or whatever)
+ */
+ int (*GetDisplayUsableBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
+
+ /*
+ * Get a list of the available display modes for a display.
+ */
+ void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
+
+ /*
+ * Setting the display mode is independent of creating windows, so
+ * when the display mode is changed, all existing windows should have
+ * their data updated accordingly, including the display surfaces
+ * associated with them.
+ */
+ int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
+
+ /* * * */
+ /*
+ * Window functions
+ */
+ int (*CreateSDLWindow) (_THIS, SDL_Window * window);
+ int (*CreateSDLWindowFrom) (_THIS, SDL_Window * window, const void *data);
+ void (*SetWindowTitle) (_THIS, SDL_Window * window);
+ void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
+ void (*SetWindowPosition) (_THIS, SDL_Window * window);
+ void (*SetWindowSize) (_THIS, SDL_Window * window);
+ void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
+ void (*SetWindowMaximumSize) (_THIS, SDL_Window * window);
+ int (*GetWindowBordersSize) (_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right);
+ int (*SetWindowOpacity) (_THIS, SDL_Window * window, float opacity);
+ int (*SetWindowModalFor) (_THIS, SDL_Window * modal_window, SDL_Window * parent_window);
+ int (*SetWindowInputFocus) (_THIS, SDL_Window * window);
+ void (*ShowWindow) (_THIS, SDL_Window * window);
+ void (*HideWindow) (_THIS, SDL_Window * window);
+ void (*RaiseWindow) (_THIS, SDL_Window * window);
+ void (*MaximizeWindow) (_THIS, SDL_Window * window);
+ void (*MinimizeWindow) (_THIS, SDL_Window * window);
+ void (*RestoreWindow) (_THIS, SDL_Window * window);
+ void (*SetWindowBordered) (_THIS, SDL_Window * window, SDL_bool bordered);
+ void (*SetWindowResizable) (_THIS, SDL_Window * window, SDL_bool resizable);
+ void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
+ int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
+ int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
+ void (*SetWindowGrab) (_THIS, SDL_Window * window, SDL_bool grabbed);
+ void (*DestroyWindow) (_THIS, SDL_Window * window);
+ int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
+ int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects);
+ void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
+ void (*OnWindowEnter) (_THIS, SDL_Window * window);
+
+ /* * * */
+ /*
+ * Shaped-window functions
+ */
+ SDL_ShapeDriver shape_driver;
+
+ /* Get some platform dependent window information */
+ SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
+ struct SDL_SysWMinfo * info);
+
+ /* * * */
+ /*
+ * OpenGL support
+ */
+ int (*GL_LoadLibrary) (_THIS, const char *path);
+ void *(*GL_GetProcAddress) (_THIS, const char *proc);
+ void (*GL_UnloadLibrary) (_THIS);
+ SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
+ int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
+ void (*GL_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h);
+ int (*GL_SetSwapInterval) (_THIS, int interval);
+ int (*GL_GetSwapInterval) (_THIS);
+ int (*GL_SwapWindow) (_THIS, SDL_Window * window);
+ void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
+ void (*GL_DefaultProfileConfig) (_THIS, int *mask, int *major, int *minor);
+
+ /* * * */
+ /*
+ * Vulkan support
+ */
+ int (*Vulkan_LoadLibrary) (_THIS, const char *path);
+ void (*Vulkan_UnloadLibrary) (_THIS);
+ SDL_bool (*Vulkan_GetInstanceExtensions) (_THIS, SDL_Window *window, unsigned *count, const char **names);
+ SDL_bool (*Vulkan_CreateSurface) (_THIS, SDL_Window *window, VkInstance instance, VkSurfaceKHR *surface);
+ void (*Vulkan_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h);
+
+ /* * * */
+ /*
+ * Event manager functions
+ */
+ void (*PumpEvents) (_THIS);
+
+ /* Suspend the screensaver */
+ void (*SuspendScreenSaver) (_THIS);
+
+ /* Text input */
+ void (*StartTextInput) (_THIS);
+ void (*StopTextInput) (_THIS);
+ void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
+
+ /* Screen keyboard */
+ SDL_bool (*HasScreenKeyboardSupport) (_THIS);
+ void (*ShowScreenKeyboard) (_THIS, SDL_Window *window);
+ void (*HideScreenKeyboard) (_THIS, SDL_Window *window);
+ SDL_bool (*IsScreenKeyboardShown) (_THIS, SDL_Window *window);
+
+ /* Clipboard */
+ int (*SetClipboardText) (_THIS, const char *text);
+ char * (*GetClipboardText) (_THIS);
+ SDL_bool (*HasClipboardText) (_THIS);
+
+ /* MessageBox */
+ int (*ShowMessageBox) (_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid);
+
+ /* Hit-testing */
+ int (*SetWindowHitTest)(SDL_Window * window, SDL_bool enabled);
+
+ /* * * */
+ /* Data common to all drivers */
+ SDL_bool is_dummy;
+ SDL_bool suspend_screensaver;
+ int num_displays;
+ SDL_VideoDisplay *displays;
+ SDL_Window *windows;
+ SDL_Window *grabbed_window;
+ Uint8 window_magic;
+ Uint32 next_object_id;
+ char *clipboard_text;
+
+ /* * * */
+ /* Data used by the GL drivers */
+ struct
+ {
+ int red_size;
+ int green_size;
+ int blue_size;
+ int alpha_size;
+ int depth_size;
+ int buffer_size;
+ int stencil_size;
+ int double_buffer;
+ int accum_red_size;
+ int accum_green_size;
+ int accum_blue_size;
+ int accum_alpha_size;
+ int stereo;
+ int multisamplebuffers;
+ int multisamplesamples;
+ int accelerated;
+ int major_version;
+ int minor_version;
+ int flags;
+ int profile_mask;
+ int share_with_current_context;
+ int release_behavior;
+ int reset_notification;
+ int framebuffer_srgb_capable;
+ int no_error;
+ int retained_backing;
+ int driver_loaded;
+ char driver_path[256];
+ void *dll_handle;
+ } gl_config;
+
+ /* * * */
+ /* Cache current GL context; don't call the OS when it hasn't changed. */
+ /* We have the global pointers here so Cocoa continues to work the way
+ it always has, and the thread-local storage for the general case.
+ */
+ SDL_Window *current_glwin;
+ SDL_GLContext current_glctx;
+ SDL_TLSID current_glwin_tls;
+ SDL_TLSID current_glctx_tls;
+
+ /* * * */
+ /* Data used by the Vulkan drivers */
+ struct
+ {
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
+ PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties;
+ int loader_loaded;
+ char loader_path[256];
+ void *loader_handle;
+ } vulkan_config;
+
+ /* * * */
+ /* Data private to this driver */
+ void *driverdata;
+ struct SDL_GLDriverData *gl_data;
+
+#if SDL_VIDEO_OPENGL_EGL
+ struct SDL_EGL_VideoData *egl_data;
+#endif
+
+#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
+ struct SDL_PrivateGLESData *gles_data;
+#endif
+
+ /* * * */
+ /* The function used to dispose of this structure */
+ void (*free) (_THIS);
+};
+
+typedef struct VideoBootStrap
+{
+ const char *name;
+ const char *desc;
+ int (*available) (void);
+ SDL_VideoDevice *(*create) (int devindex);
+} VideoBootStrap;
+
+/* Not all of these are available in a given build. Use #ifdefs, etc. */
+extern VideoBootStrap COCOA_bootstrap;
+extern VideoBootStrap X11_bootstrap;
+extern VideoBootStrap MIR_bootstrap;
+extern VideoBootStrap DirectFB_bootstrap;
+extern VideoBootStrap WINDOWS_bootstrap;
+extern VideoBootStrap WINRT_bootstrap;
+extern VideoBootStrap HAIKU_bootstrap;
+extern VideoBootStrap PND_bootstrap;
+extern VideoBootStrap UIKIT_bootstrap;
+extern VideoBootStrap Android_bootstrap;
+extern VideoBootStrap PSP_bootstrap;
+extern VideoBootStrap RPI_bootstrap;
+extern VideoBootStrap KMSDRM_bootstrap;
+extern VideoBootStrap DUMMY_bootstrap;
+extern VideoBootStrap Wayland_bootstrap;
+extern VideoBootStrap NACL_bootstrap;
+extern VideoBootStrap VIVANTE_bootstrap;
+extern VideoBootStrap Emscripten_bootstrap;
+extern VideoBootStrap QNX_bootstrap;
+
+extern SDL_VideoDevice *SDL_GetVideoDevice(void);
+extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
+extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
+extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
+extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
+extern void *SDL_GetDisplayDriverData( int displayIndex );
+
+extern void SDL_GL_DeduceMaxSupportedESProfile(int* major, int* minor);
+
+extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
+extern SDL_bool SDL_HasWindows(void);
+
+extern void SDL_OnWindowShown(SDL_Window * window);
+extern void SDL_OnWindowHidden(SDL_Window * window);
+extern void SDL_OnWindowResized(SDL_Window * window);
+extern void SDL_OnWindowMinimized(SDL_Window * window);
+extern void SDL_OnWindowRestored(SDL_Window * window);
+extern void SDL_OnWindowEnter(SDL_Window * window);
+extern void SDL_OnWindowLeave(SDL_Window * window);
+extern void SDL_OnWindowFocusGained(SDL_Window * window);
+extern void SDL_OnWindowFocusLost(SDL_Window * window);
+extern void SDL_UpdateWindowGrab(SDL_Window * window);
+extern SDL_Window * SDL_GetFocusWindow(void);
+
+extern SDL_bool SDL_ShouldAllowTopmost(void);
+
+extern float SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches);
+
+extern void SDL_OnApplicationWillTerminate(void);
+extern void SDL_OnApplicationDidReceiveMemoryWarning(void);
+extern void SDL_OnApplicationWillResignActive(void);
+extern void SDL_OnApplicationDidEnterBackground(void);
+extern void SDL_OnApplicationWillEnterForeground(void);
+extern void SDL_OnApplicationDidBecomeActive(void);
+
+#endif /* SDL_sysvideo_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_video.c b/src/3rdparty/SDL2/src/video/SDL_video.c
new file mode 100644
index 0000000..8cf195d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_video.c
@@ -0,0 +1,4077 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* The high-level video driver subsystem */
+
+#include "SDL.h"
+#include "SDL_video.h"
+#include "SDL_sysvideo.h"
+#include "SDL_blit.h"
+#include "SDL_pixels_c.h"
+#include "SDL_rect_c.h"
+#include "../events/SDL_events_c.h"
+#include "../timer/SDL_timer_c.h"
+
+#include "SDL_syswm.h"
+
+#if SDL_VIDEO_OPENGL
+#include "SDL_opengl.h"
+#endif /* SDL_VIDEO_OPENGL */
+
+#if SDL_VIDEO_OPENGL_ES
+#include "SDL_opengles.h"
+#endif /* SDL_VIDEO_OPENGL_ES */
+
+/* GL and GLES2 headers conflict on Linux 32 bits */
+#if SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL
+#include "SDL_opengles2.h"
+#endif /* SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL */
+
+#if !SDL_VIDEO_OPENGL
+#ifndef GL_CONTEXT_RELEASE_BEHAVIOR_KHR
+#define GL_CONTEXT_RELEASE_BEHAVIOR_KHR 0x82FB
+#endif
+#endif
+
+#ifdef __EMSCRIPTEN__
+#include <emscripten.h>
+#endif
+
+/* Available video drivers */
+static VideoBootStrap *bootstrap[] = {
+#if SDL_VIDEO_DRIVER_COCOA
+ &COCOA_bootstrap,
+#endif
+#if SDL_VIDEO_DRIVER_X11
+ &X11_bootstrap,
+#endif
+#if SDL_VIDEO_DRIVER_MIR
+ &MIR_bootstrap,
+#endif
+#if SDL_VIDEO_DRIVER_WAYLAND
+ &Wayland_bootstrap,
+#endif
+#if SDL_VIDEO_DRIVER_VIVANTE
+ &VIVANTE_bootstrap,
+#endif
+#if SDL_VIDEO_DRIVER_DIRECTFB
+ &DirectFB_bootstrap,
+#endif
+#if SDL_VIDEO_DRIVER_WINDOWS
+ &WINDOWS_bootstrap,
+#endif
+#if SDL_VIDEO_DRIVER_WINRT
+ &WINRT_bootstrap,
+#endif
+#if SDL_VIDEO_DRIVER_HAIKU
+ &HAIKU_bootstrap,
+#endif
+#if SDL_VIDEO_DRIVER_PANDORA
+ &PND_bootstrap,
+#endif
+#if SDL_VIDEO_DRIVER_UIKIT
+ &UIKIT_bootstrap,
+#endif
+#if SDL_VIDEO_DRIVER_ANDROID
+ &Android_bootstrap,
+#endif
+#if SDL_VIDEO_DRIVER_PSP
+ &PSP_bootstrap,
+#endif
+#if SDL_VIDEO_DRIVER_KMSDRM
+ &KMSDRM_bootstrap,
+#endif
+#if SDL_VIDEO_DRIVER_RPI
+ &RPI_bootstrap,
+#endif
+#if SDL_VIDEO_DRIVER_NACL
+ &NACL_bootstrap,
+#endif
+#if SDL_VIDEO_DRIVER_EMSCRIPTEN
+ &Emscripten_bootstrap,
+#endif
+#if SDL_VIDEO_DRIVER_QNX
+ &QNX_bootstrap,
+#endif
+#if SDL_VIDEO_DRIVER_DUMMY
+ &DUMMY_bootstrap,
+#endif
+ NULL
+};
+
+static SDL_VideoDevice *_this = NULL;
+
+#define CHECK_WINDOW_MAGIC(window, retval) \
+ if (!_this) { \
+ SDL_UninitializedVideo(); \
+ return retval; \
+ } \
+ SDL_assert(window && window->magic == &_this->window_magic); \
+ if (!window || window->magic != &_this->window_magic) { \
+ SDL_SetError("Invalid window"); \
+ return retval; \
+ }
+
+#define CHECK_DISPLAY_INDEX(displayIndex, retval) \
+ if (!_this) { \
+ SDL_UninitializedVideo(); \
+ return retval; \
+ } \
+ SDL_assert(_this->displays != NULL); \
+ SDL_assert(displayIndex >= 0 && displayIndex < _this->num_displays); \
+ if (displayIndex < 0 || displayIndex >= _this->num_displays) { \
+ SDL_SetError("displayIndex must be in the range 0 - %d", \
+ _this->num_displays - 1); \
+ return retval; \
+ }
+
+#define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN)
+
+#ifdef __MACOSX__
+/* Support for Mac OS X fullscreen spaces */
+extern SDL_bool Cocoa_IsWindowInFullscreenSpace(SDL_Window * window);
+extern SDL_bool Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state);
+#endif
+
+
+/* Support for framebuffer emulation using an accelerated renderer */
+
+#define SDL_WINDOWTEXTUREDATA "_SDL_WindowTextureData"
+
+typedef struct {
+ SDL_Renderer *renderer;
+ SDL_Texture *texture;
+ void *pixels;
+ int pitch;
+ int bytes_per_pixel;
+} SDL_WindowTextureData;
+
+static SDL_bool
+ShouldUseTextureFramebuffer()
+{
+ const char *hint;
+
+ /* If there's no native framebuffer support then there's no option */
+ if (!_this->CreateWindowFramebuffer) {
+ return SDL_TRUE;
+ }
+
+ /* If this is the dummy driver there is no texture support */
+ if (_this->is_dummy) {
+ return SDL_FALSE;
+ }
+
+ /* If the user has specified a software renderer we can't use a
+ texture framebuffer, or renderer creation will go recursive.
+ */
+ hint = SDL_GetHint(SDL_HINT_RENDER_DRIVER);
+ if (hint && SDL_strcasecmp(hint, "software") == 0) {
+ return SDL_FALSE;
+ }
+
+ /* See if the user or application wants a specific behavior */
+ hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
+ if (hint) {
+ if (*hint == '0' || SDL_strcasecmp(hint, "false") == 0) {
+ return SDL_FALSE;
+ } else {
+ return SDL_TRUE;
+ }
+ }
+
+ /* Each platform has different performance characteristics */
+#if defined(__WIN32__)
+ /* GDI BitBlt() is way faster than Direct3D dynamic textures right now.
+ */
+ return SDL_FALSE;
+
+#elif defined(__MACOSX__)
+ /* Mac OS X uses OpenGL as the native fast path (for cocoa and X11) */
+ return SDL_TRUE;
+
+#elif defined(__LINUX__)
+ /* Properly configured OpenGL drivers are faster than MIT-SHM */
+#if SDL_VIDEO_OPENGL
+ /* Ugh, find a way to cache this value! */
+ {
+ SDL_Window *window;
+ SDL_GLContext context;
+ SDL_bool hasAcceleratedOpenGL = SDL_FALSE;
+
+ window = SDL_CreateWindow("OpenGL test", -32, -32, 32, 32, SDL_WINDOW_OPENGL|SDL_WINDOW_HIDDEN);
+ if (window) {
+ context = SDL_GL_CreateContext(window);
+ if (context) {
+ const GLubyte *(APIENTRY * glGetStringFunc) (GLenum);
+ const char *vendor = NULL;
+
+ glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
+ if (glGetStringFunc) {
+ vendor = (const char *) glGetStringFunc(GL_VENDOR);
+ }
+ /* Add more vendors here at will... */
+ if (vendor &&
+ (SDL_strstr(vendor, "ATI Technologies") ||
+ SDL_strstr(vendor, "NVIDIA"))) {
+ hasAcceleratedOpenGL = SDL_TRUE;
+ }
+ SDL_GL_DeleteContext(context);
+ }
+ SDL_DestroyWindow(window);
+ }
+ return hasAcceleratedOpenGL;
+ }
+#elif SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
+ /* Let's be optimistic about this! */
+ return SDL_TRUE;
+#else
+ return SDL_FALSE;
+#endif
+
+#else
+ /* Play it safe, assume that if there is a framebuffer driver that it's
+ optimized for the current platform.
+ */
+ return SDL_FALSE;
+#endif
+}
+
+static int
+SDL_CreateWindowTexture(SDL_VideoDevice *unused, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
+{
+ SDL_WindowTextureData *data;
+
+ data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
+ if (!data) {
+ SDL_Renderer *renderer = NULL;
+ int i;
+ const char *hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
+
+ /* Check to see if there's a specific driver requested */
+ if (hint && *hint != '0' && *hint != '1' &&
+ SDL_strcasecmp(hint, "true") != 0 &&
+ SDL_strcasecmp(hint, "false") != 0 &&
+ SDL_strcasecmp(hint, "software") != 0) {
+ for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) {
+ SDL_RendererInfo info;
+ SDL_GetRenderDriverInfo(i, &info);
+ if (SDL_strcasecmp(info.name, hint) == 0) {
+ renderer = SDL_CreateRenderer(window, i, 0);
+ break;
+ }
+ }
+ }
+
+ if (!renderer) {
+ for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) {
+ SDL_RendererInfo info;
+ SDL_GetRenderDriverInfo(i, &info);
+ if (SDL_strcmp(info.name, "software") != 0) {
+ renderer = SDL_CreateRenderer(window, i, 0);
+ if (renderer) {
+ break;
+ }
+ }
+ }
+ }
+ if (!renderer) {
+ return SDL_SetError("No hardware accelerated renderers available");
+ }
+
+ /* Create the data after we successfully create the renderer (bug #1116) */
+ data = (SDL_WindowTextureData *)SDL_calloc(1, sizeof(*data));
+ if (!data) {
+ SDL_DestroyRenderer(renderer);
+ return SDL_OutOfMemory();
+ }
+ SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, data);
+
+ data->renderer = renderer;
+ }
+
+ /* Free any old texture and pixel data */
+ if (data->texture) {
+ SDL_DestroyTexture(data->texture);
+ data->texture = NULL;
+ }
+ SDL_free(data->pixels);
+ data->pixels = NULL;
+
+ {
+ SDL_RendererInfo info;
+ Uint32 i;
+
+ if (SDL_GetRendererInfo(data->renderer, &info) < 0) {
+ return -1;
+ }
+
+ /* Find the first format without an alpha channel */
+ *format = info.texture_formats[0];
+
+ for (i = 0; i < info.num_texture_formats; ++i) {
+ if (!SDL_ISPIXELFORMAT_FOURCC(info.texture_formats[i]) &&
+ !SDL_ISPIXELFORMAT_ALPHA(info.texture_formats[i])) {
+ *format = info.texture_formats[i];
+ break;
+ }
+ }
+ }
+
+ data->texture = SDL_CreateTexture(data->renderer, *format,
+ SDL_TEXTUREACCESS_STREAMING,
+ window->w, window->h);
+ if (!data->texture) {
+ return -1;
+ }
+
+ /* Create framebuffer data */
+ data->bytes_per_pixel = SDL_BYTESPERPIXEL(*format);
+ data->pitch = (((window->w * data->bytes_per_pixel) + 3) & ~3);
+
+ {
+ /* Make static analysis happy about potential malloc(0) calls. */
+ const size_t allocsize = window->h * data->pitch;
+ data->pixels = SDL_malloc((allocsize > 0) ? allocsize : 1);
+ if (!data->pixels) {
+ return SDL_OutOfMemory();
+ }
+ }
+
+ *pixels = data->pixels;
+ *pitch = data->pitch;
+
+ /* Make sure we're not double-scaling the viewport */
+ SDL_RenderSetViewport(data->renderer, NULL);
+
+ return 0;
+}
+
+static int
+SDL_UpdateWindowTexture(SDL_VideoDevice *unused, SDL_Window * window, const SDL_Rect * rects, int numrects)
+{
+ SDL_WindowTextureData *data;
+ SDL_Rect rect;
+ void *src;
+
+ data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
+ if (!data || !data->texture) {
+ return SDL_SetError("No window texture data");
+ }
+
+ /* Update a single rect that contains subrects for best DMA performance */
+ if (SDL_GetSpanEnclosingRect(window->w, window->h, numrects, rects, &rect)) {
+ src = (void *)((Uint8 *)data->pixels +
+ rect.y * data->pitch +
+ rect.x * data->bytes_per_pixel);
+ if (SDL_UpdateTexture(data->texture, &rect, src, data->pitch) < 0) {
+ return -1;
+ }
+
+ if (SDL_RenderCopy(data->renderer, data->texture, NULL, NULL) < 0) {
+ return -1;
+ }
+
+ SDL_RenderPresent(data->renderer);
+ }
+ return 0;
+}
+
+static void
+SDL_DestroyWindowTexture(SDL_VideoDevice *unused, SDL_Window * window)
+{
+ SDL_WindowTextureData *data;
+
+ data = SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, NULL);
+ if (!data) {
+ return;
+ }
+ if (data->texture) {
+ SDL_DestroyTexture(data->texture);
+ }
+ if (data->renderer) {
+ SDL_DestroyRenderer(data->renderer);
+ }
+ SDL_free(data->pixels);
+ SDL_free(data);
+}
+
+
+static int
+cmpmodes(const void *A, const void *B)
+{
+ const SDL_DisplayMode *a = (const SDL_DisplayMode *) A;
+ const SDL_DisplayMode *b = (const SDL_DisplayMode *) B;
+ if (a == b) {
+ return 0;
+ } else if (a->w != b->w) {
+ return b->w - a->w;
+ } else if (a->h != b->h) {
+ return b->h - a->h;
+ } else if (SDL_BITSPERPIXEL(a->format) != SDL_BITSPERPIXEL(b->format)) {
+ return SDL_BITSPERPIXEL(b->format) - SDL_BITSPERPIXEL(a->format);
+ } else if (SDL_PIXELLAYOUT(a->format) != SDL_PIXELLAYOUT(b->format)) {
+ return SDL_PIXELLAYOUT(b->format) - SDL_PIXELLAYOUT(a->format);
+ } else if (a->refresh_rate != b->refresh_rate) {
+ return b->refresh_rate - a->refresh_rate;
+ }
+ return 0;
+}
+
+static int
+SDL_UninitializedVideo()
+{
+ return SDL_SetError("Video subsystem has not been initialized");
+}
+
+int
+SDL_GetNumVideoDrivers(void)
+{
+ return SDL_arraysize(bootstrap) - 1;
+}
+
+const char *
+SDL_GetVideoDriver(int index)
+{
+ if (index >= 0 && index < SDL_GetNumVideoDrivers()) {
+ return bootstrap[index]->name;
+ }
+ return NULL;
+}
+
+/*
+ * Initialize the video and event subsystems -- determine native pixel format
+ */
+int
+SDL_VideoInit(const char *driver_name)
+{
+ SDL_VideoDevice *video;
+ int index;
+ int i;
+
+ /* Check to make sure we don't overwrite '_this' */
+ if (_this != NULL) {
+ SDL_VideoQuit();
+ }
+
+#if !SDL_TIMERS_DISABLED
+ SDL_TicksInit();
+#endif
+
+ /* Start the event loop */
+ if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0 ||
+ SDL_KeyboardInit() < 0 ||
+ SDL_MouseInit() < 0 ||
+ SDL_TouchInit() < 0) {
+ return -1;
+ }
+
+ /* Select the proper video driver */
+ index = 0;
+ video = NULL;
+ if (driver_name == NULL) {
+ driver_name = SDL_getenv("SDL_VIDEODRIVER");
+ }
+ if (driver_name != NULL) {
+ for (i = 0; bootstrap[i]; ++i) {
+ if (SDL_strncasecmp(bootstrap[i]->name, driver_name, SDL_strlen(driver_name)) == 0) {
+ if (bootstrap[i]->available()) {
+ video = bootstrap[i]->create(index);
+ break;
+ }
+ }
+ }
+ } else {
+ for (i = 0; bootstrap[i]; ++i) {
+ if (bootstrap[i]->available()) {
+ video = bootstrap[i]->create(index);
+ if (video != NULL) {
+ break;
+ }
+ }
+ }
+ }
+ if (video == NULL) {
+ if (driver_name) {
+ return SDL_SetError("%s not available", driver_name);
+ }
+ return SDL_SetError("No available video device");
+ }
+ _this = video;
+ _this->name = bootstrap[i]->name;
+ _this->next_object_id = 1;
+
+
+ /* Set some very sane GL defaults */
+ _this->gl_config.driver_loaded = 0;
+ _this->gl_config.dll_handle = NULL;
+ SDL_GL_ResetAttributes();
+
+ _this->current_glwin_tls = SDL_TLSCreate();
+ _this->current_glctx_tls = SDL_TLSCreate();
+
+ /* Initialize the video subsystem */
+ if (_this->VideoInit(_this) < 0) {
+ SDL_VideoQuit();
+ return -1;
+ }
+
+ /* Make sure some displays were added */
+ if (_this->num_displays == 0) {
+ SDL_VideoQuit();
+ return SDL_SetError("The video driver did not add any displays");
+ }
+
+ /* Add the renderer framebuffer emulation if desired */
+ if (ShouldUseTextureFramebuffer()) {
+ _this->CreateWindowFramebuffer = SDL_CreateWindowTexture;
+ _this->UpdateWindowFramebuffer = SDL_UpdateWindowTexture;
+ _this->DestroyWindowFramebuffer = SDL_DestroyWindowTexture;
+ }
+
+ /* Disable the screen saver by default. This is a change from <= 2.0.1,
+ but most things using SDL are games or media players; you wouldn't
+ want a screensaver to trigger if you're playing exclusively with a
+ joystick, or passively watching a movie. Things that use SDL but
+ function more like a normal desktop app should explicitly reenable the
+ screensaver. */
+ if (!SDL_GetHintBoolean(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, SDL_FALSE)) {
+ SDL_DisableScreenSaver();
+ }
+
+ /* If we don't use a screen keyboard, turn on text input by default,
+ otherwise programs that expect to get text events without enabling
+ UNICODE input won't get any events.
+
+ Actually, come to think of it, you needed to call SDL_EnableUNICODE(1)
+ in SDL 1.2 before you got text input events. Hmm...
+ */
+ if (!SDL_HasScreenKeyboardSupport()) {
+ SDL_StartTextInput();
+ }
+
+ /* We're ready to go! */
+ return 0;
+}
+
+const char *
+SDL_GetCurrentVideoDriver()
+{
+ if (!_this) {
+ SDL_UninitializedVideo();
+ return NULL;
+ }
+ return _this->name;
+}
+
+SDL_VideoDevice *
+SDL_GetVideoDevice(void)
+{
+ return _this;
+}
+
+int
+SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode)
+{
+ SDL_VideoDisplay display;
+
+ SDL_zero(display);
+ if (desktop_mode) {
+ display.desktop_mode = *desktop_mode;
+ }
+ display.current_mode = display.desktop_mode;
+
+ return SDL_AddVideoDisplay(&display);
+}
+
+int
+SDL_AddVideoDisplay(const SDL_VideoDisplay * display)
+{
+ SDL_VideoDisplay *displays;
+ int index = -1;
+
+ displays =
+ SDL_realloc(_this->displays,
+ (_this->num_displays + 1) * sizeof(*displays));
+ if (displays) {
+ index = _this->num_displays++;
+ displays[index] = *display;
+ displays[index].device = _this;
+ _this->displays = displays;
+
+ if (display->name) {
+ displays[index].name = SDL_strdup(display->name);
+ } else {
+ char name[32];
+
+ SDL_itoa(index, name, 10);
+ displays[index].name = SDL_strdup(name);
+ }
+ } else {
+ SDL_OutOfMemory();
+ }
+ return index;
+}
+
+int
+SDL_GetNumVideoDisplays(void)
+{
+ if (!_this) {
+ SDL_UninitializedVideo();
+ return 0;
+ }
+ return _this->num_displays;
+}
+
+static int
+SDL_GetIndexOfDisplay(SDL_VideoDisplay *display)
+{
+ int displayIndex;
+
+ for (displayIndex = 0; displayIndex < _this->num_displays; ++displayIndex) {
+ if (display == &_this->displays[displayIndex]) {
+ return displayIndex;
+ }
+ }
+
+ /* Couldn't find the display, just use index 0 */
+ return 0;
+}
+
+void *
+SDL_GetDisplayDriverData(int displayIndex)
+{
+ CHECK_DISPLAY_INDEX(displayIndex, NULL);
+
+ return _this->displays[displayIndex].driverdata;
+}
+
+const char *
+SDL_GetDisplayName(int displayIndex)
+{
+ CHECK_DISPLAY_INDEX(displayIndex, NULL);
+
+ return _this->displays[displayIndex].name;
+}
+
+int
+SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect)
+{
+ CHECK_DISPLAY_INDEX(displayIndex, -1);
+
+ if (rect) {
+ SDL_VideoDisplay *display = &_this->displays[displayIndex];
+
+ if (_this->GetDisplayBounds) {
+ if (_this->GetDisplayBounds(_this, display, rect) == 0) {
+ return 0;
+ }
+ }
+
+ /* Assume that the displays are left to right */
+ if (displayIndex == 0) {
+ rect->x = 0;
+ rect->y = 0;
+ } else {
+ SDL_GetDisplayBounds(displayIndex-1, rect);
+ rect->x += rect->w;
+ }
+ rect->w = display->current_mode.w;
+ rect->h = display->current_mode.h;
+ }
+ return 0; /* !!! FIXME: should this be an error if (rect==NULL) ? */
+}
+
+int SDL_GetDisplayUsableBounds(int displayIndex, SDL_Rect * rect)
+{
+ CHECK_DISPLAY_INDEX(displayIndex, -1);
+
+ if (rect) {
+ SDL_VideoDisplay *display = &_this->displays[displayIndex];
+
+ if (_this->GetDisplayUsableBounds) {
+ if (_this->GetDisplayUsableBounds(_this, display, rect) == 0) {
+ return 0;
+ }
+ }
+
+ /* Oh well, just give the entire display bounds. */
+ return SDL_GetDisplayBounds(displayIndex, rect);
+ }
+ return 0; /* !!! FIXME: should this be an error if (rect==NULL) ? */
+}
+
+int
+SDL_GetDisplayDPI(int displayIndex, float * ddpi, float * hdpi, float * vdpi)
+{
+ SDL_VideoDisplay *display;
+
+ CHECK_DISPLAY_INDEX(displayIndex, -1);
+
+ display = &_this->displays[displayIndex];
+
+ if (_this->GetDisplayDPI) {
+ if (_this->GetDisplayDPI(_this, display, ddpi, hdpi, vdpi) == 0) {
+ return 0;
+ }
+ } else {
+ return SDL_Unsupported();
+ }
+
+ return -1;
+}
+
+SDL_bool
+SDL_AddDisplayMode(SDL_VideoDisplay * display, const SDL_DisplayMode * mode)
+{
+ SDL_DisplayMode *modes;
+ int i, nmodes;
+
+ /* Make sure we don't already have the mode in the list */
+ modes = display->display_modes;
+ nmodes = display->num_display_modes;
+ for (i = 0; i < nmodes; ++i) {
+ if (cmpmodes(mode, &modes[i]) == 0) {
+ return SDL_FALSE;
+ }
+ }
+
+ /* Go ahead and add the new mode */
+ if (nmodes == display->max_display_modes) {
+ modes =
+ SDL_realloc(modes,
+ (display->max_display_modes + 32) * sizeof(*modes));
+ if (!modes) {
+ return SDL_FALSE;
+ }
+ display->display_modes = modes;
+ display->max_display_modes += 32;
+ }
+ modes[nmodes] = *mode;
+ display->num_display_modes++;
+
+ /* Re-sort video modes */
+ SDL_qsort(display->display_modes, display->num_display_modes,
+ sizeof(SDL_DisplayMode), cmpmodes);
+
+ return SDL_TRUE;
+}
+
+static int
+SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display)
+{
+ if (!display->num_display_modes && _this->GetDisplayModes) {
+ _this->GetDisplayModes(_this, display);
+ SDL_qsort(display->display_modes, display->num_display_modes,
+ sizeof(SDL_DisplayMode), cmpmodes);
+ }
+ return display->num_display_modes;
+}
+
+int
+SDL_GetNumDisplayModes(int displayIndex)
+{
+ CHECK_DISPLAY_INDEX(displayIndex, -1);
+
+ return SDL_GetNumDisplayModesForDisplay(&_this->displays[displayIndex]);
+}
+
+int
+SDL_GetDisplayMode(int displayIndex, int index, SDL_DisplayMode * mode)
+{
+ SDL_VideoDisplay *display;
+
+ CHECK_DISPLAY_INDEX(displayIndex, -1);
+
+ display = &_this->displays[displayIndex];
+ if (index < 0 || index >= SDL_GetNumDisplayModesForDisplay(display)) {
+ return SDL_SetError("index must be in the range of 0 - %d",
+ SDL_GetNumDisplayModesForDisplay(display) - 1);
+ }
+ if (mode) {
+ *mode = display->display_modes[index];
+ }
+ return 0;
+}
+
+int
+SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode * mode)
+{
+ SDL_VideoDisplay *display;
+
+ CHECK_DISPLAY_INDEX(displayIndex, -1);
+
+ display = &_this->displays[displayIndex];
+ if (mode) {
+ *mode = display->desktop_mode;
+ }
+ return 0;
+}
+
+int
+SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode * mode)
+{
+ SDL_VideoDisplay *display;
+
+ CHECK_DISPLAY_INDEX(displayIndex, -1);
+
+ display = &_this->displays[displayIndex];
+ if (mode) {
+ *mode = display->current_mode;
+ }
+ return 0;
+}
+
+static SDL_DisplayMode *
+SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display,
+ const SDL_DisplayMode * mode,
+ SDL_DisplayMode * closest)
+{
+ Uint32 target_format;
+ int target_refresh_rate;
+ int i;
+ SDL_DisplayMode *current, *match;
+
+ if (!mode || !closest) {
+ SDL_SetError("Missing desired mode or closest mode parameter");
+ return NULL;
+ }
+
+ /* Default to the desktop format */
+ if (mode->format) {
+ target_format = mode->format;
+ } else {
+ target_format = display->desktop_mode.format;
+ }
+
+ /* Default to the desktop refresh rate */
+ if (mode->refresh_rate) {
+ target_refresh_rate = mode->refresh_rate;
+ } else {
+ target_refresh_rate = display->desktop_mode.refresh_rate;
+ }
+
+ match = NULL;
+ for (i = 0; i < SDL_GetNumDisplayModesForDisplay(display); ++i) {
+ current = &display->display_modes[i];
+
+ if (current->w && (current->w < mode->w)) {
+ /* Out of sorted modes large enough here */
+ break;
+ }
+ if (current->h && (current->h < mode->h)) {
+ if (current->w && (current->w == mode->w)) {
+ /* Out of sorted modes large enough here */
+ break;
+ }
+ /* Wider, but not tall enough, due to a different
+ aspect ratio. This mode must be skipped, but closer
+ modes may still follow. */
+ continue;
+ }
+ if (!match || current->w < match->w || current->h < match->h) {
+ match = current;
+ continue;
+ }
+ if (current->format != match->format) {
+ /* Sorted highest depth to lowest */
+ if (current->format == target_format ||
+ (SDL_BITSPERPIXEL(current->format) >=
+ SDL_BITSPERPIXEL(target_format)
+ && SDL_PIXELTYPE(current->format) ==
+ SDL_PIXELTYPE(target_format))) {
+ match = current;
+ }
+ continue;
+ }
+ if (current->refresh_rate != match->refresh_rate) {
+ /* Sorted highest refresh to lowest */
+ if (current->refresh_rate >= target_refresh_rate) {
+ match = current;
+ }
+ }
+ }
+ if (match) {
+ if (match->format) {
+ closest->format = match->format;
+ } else {
+ closest->format = mode->format;
+ }
+ if (match->w && match->h) {
+ closest->w = match->w;
+ closest->h = match->h;
+ } else {
+ closest->w = mode->w;
+ closest->h = mode->h;
+ }
+ if (match->refresh_rate) {
+ closest->refresh_rate = match->refresh_rate;
+ } else {
+ closest->refresh_rate = mode->refresh_rate;
+ }
+ closest->driverdata = match->driverdata;
+
+ /*
+ * Pick some reasonable defaults if the app and driver don't
+ * care
+ */
+ if (!closest->format) {
+ closest->format = SDL_PIXELFORMAT_RGB888;
+ }
+ if (!closest->w) {
+ closest->w = 640;
+ }
+ if (!closest->h) {
+ closest->h = 480;
+ }
+ return closest;
+ }
+ return NULL;
+}
+
+SDL_DisplayMode *
+SDL_GetClosestDisplayMode(int displayIndex,
+ const SDL_DisplayMode * mode,
+ SDL_DisplayMode * closest)
+{
+ SDL_VideoDisplay *display;
+
+ CHECK_DISPLAY_INDEX(displayIndex, NULL);
+
+ display = &_this->displays[displayIndex];
+ return SDL_GetClosestDisplayModeForDisplay(display, mode, closest);
+}
+
+static int
+SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode)
+{
+ SDL_DisplayMode display_mode;
+ SDL_DisplayMode current_mode;
+
+ if (mode) {
+ display_mode = *mode;
+
+ /* Default to the current mode */
+ if (!display_mode.format) {
+ display_mode.format = display->current_mode.format;
+ }
+ if (!display_mode.w) {
+ display_mode.w = display->current_mode.w;
+ }
+ if (!display_mode.h) {
+ display_mode.h = display->current_mode.h;
+ }
+ if (!display_mode.refresh_rate) {
+ display_mode.refresh_rate = display->current_mode.refresh_rate;
+ }
+
+ /* Get a good video mode, the closest one possible */
+ if (!SDL_GetClosestDisplayModeForDisplay(display, &display_mode, &display_mode)) {
+ return SDL_SetError("No video mode large enough for %dx%d",
+ display_mode.w, display_mode.h);
+ }
+ } else {
+ display_mode = display->desktop_mode;
+ }
+
+ /* See if there's anything left to do */
+ current_mode = display->current_mode;
+ if (SDL_memcmp(&display_mode, &current_mode, sizeof(display_mode)) == 0) {
+ return 0;
+ }
+
+ /* Actually change the display mode */
+ if (!_this->SetDisplayMode) {
+ return SDL_SetError("Video driver doesn't support changing display mode");
+ }
+ if (_this->SetDisplayMode(_this, display, &display_mode) < 0) {
+ return -1;
+ }
+ display->current_mode = display_mode;
+ return 0;
+}
+
+int
+SDL_GetWindowDisplayIndex(SDL_Window * window)
+{
+ int displayIndex;
+ int i, dist;
+ int closest = -1;
+ int closest_dist = 0x7FFFFFFF;
+ SDL_Point center;
+ SDL_Point delta;
+ SDL_Rect rect;
+
+ CHECK_WINDOW_MAGIC(window, -1);
+
+ if (SDL_WINDOWPOS_ISUNDEFINED(window->x) ||
+ SDL_WINDOWPOS_ISCENTERED(window->x)) {
+ displayIndex = (window->x & 0xFFFF);
+ if (displayIndex >= _this->num_displays) {
+ displayIndex = 0;
+ }
+ return displayIndex;
+ }
+ if (SDL_WINDOWPOS_ISUNDEFINED(window->y) ||
+ SDL_WINDOWPOS_ISCENTERED(window->y)) {
+ displayIndex = (window->y & 0xFFFF);
+ if (displayIndex >= _this->num_displays) {
+ displayIndex = 0;
+ }
+ return displayIndex;
+ }
+
+ /* Find the display containing the window */
+ for (i = 0; i < _this->num_displays; ++i) {
+ SDL_VideoDisplay *display = &_this->displays[i];
+
+ if (display->fullscreen_window == window) {
+ return i;
+ }
+ }
+ center.x = window->x + window->w / 2;
+ center.y = window->y + window->h / 2;
+ for (i = 0; i < _this->num_displays; ++i) {
+ SDL_GetDisplayBounds(i, &rect);
+ if (SDL_EnclosePoints(&center, 1, &rect, NULL)) {
+ return i;
+ }
+
+ delta.x = center.x - (rect.x + rect.w / 2);
+ delta.y = center.y - (rect.y + rect.h / 2);
+ dist = (delta.x*delta.x + delta.y*delta.y);
+ if (dist < closest_dist) {
+ closest = i;
+ closest_dist = dist;
+ }
+ }
+ if (closest < 0) {
+ SDL_SetError("Couldn't find any displays");
+ }
+ return closest;
+}
+
+SDL_VideoDisplay *
+SDL_GetDisplayForWindow(SDL_Window *window)
+{
+ int displayIndex = SDL_GetWindowDisplayIndex(window);
+ if (displayIndex >= 0) {
+ return &_this->displays[displayIndex];
+ } else {
+ return NULL;
+ }
+}
+
+int
+SDL_SetWindowDisplayMode(SDL_Window * window, const SDL_DisplayMode * mode)
+{
+ CHECK_WINDOW_MAGIC(window, -1);
+
+ if (mode) {
+ window->fullscreen_mode = *mode;
+ } else {
+ SDL_zero(window->fullscreen_mode);
+ }
+
+ if (FULLSCREEN_VISIBLE(window) && (window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
+ SDL_DisplayMode fullscreen_mode;
+ if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
+ SDL_SetDisplayModeForDisplay(SDL_GetDisplayForWindow(window), &fullscreen_mode);
+ }
+ }
+ return 0;
+}
+
+int
+SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode)
+{
+ SDL_DisplayMode fullscreen_mode;
+ SDL_VideoDisplay *display;
+
+ CHECK_WINDOW_MAGIC(window, -1);
+
+ if (!mode) {
+ return SDL_InvalidParamError("mode");
+ }
+
+ fullscreen_mode = window->fullscreen_mode;
+ if (!fullscreen_mode.w) {
+ fullscreen_mode.w = window->windowed.w;
+ }
+ if (!fullscreen_mode.h) {
+ fullscreen_mode.h = window->windowed.h;
+ }
+
+ display = SDL_GetDisplayForWindow(window);
+
+ /* if in desktop size mode, just return the size of the desktop */
+ if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
+ fullscreen_mode = display->desktop_mode;
+ } else if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window),
+ &fullscreen_mode,
+ &fullscreen_mode)) {
+ return SDL_SetError("Couldn't find display mode match");
+ }
+
+ if (mode) {
+ *mode = fullscreen_mode;
+ }
+ return 0;
+}
+
+Uint32
+SDL_GetWindowPixelFormat(SDL_Window * window)
+{
+ SDL_VideoDisplay *display;
+
+ CHECK_WINDOW_MAGIC(window, SDL_PIXELFORMAT_UNKNOWN);
+
+ display = SDL_GetDisplayForWindow(window);
+ return display->current_mode.format;
+}
+
+static void
+SDL_RestoreMousePosition(SDL_Window *window)
+{
+ int x, y;
+
+ if (window == SDL_GetMouseFocus()) {
+ SDL_GetMouseState(&x, &y);
+ SDL_WarpMouseInWindow(window, x, y);
+ }
+}
+
+#if __WINRT__
+extern Uint32 WINRT_DetectWindowFlags(SDL_Window * window);
+#endif
+
+static int
+SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
+{
+ SDL_VideoDisplay *display;
+ SDL_Window *other;
+
+ CHECK_WINDOW_MAGIC(window,-1);
+
+ /* if we are in the process of hiding don't go back to fullscreen */
+ if (window->is_hiding && fullscreen) {
+ return 0;
+ }
+
+#ifdef __MACOSX__
+ /* if the window is going away and no resolution change is necessary,
+ do nothing, or else we may trigger an ugly double-transition
+ */
+ if (SDL_strcmp(_this->name, "cocoa") == 0) { /* don't do this for X11, etc */
+ if (window->is_destroying && (window->last_fullscreen_flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN_DESKTOP)
+ return 0;
+
+ /* If we're switching between a fullscreen Space and "normal" fullscreen, we need to get back to normal first. */
+ if (fullscreen && ((window->last_fullscreen_flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN_DESKTOP) && ((window->flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN)) {
+ if (!Cocoa_SetWindowFullscreenSpace(window, SDL_FALSE)) {
+ return -1;
+ }
+ } else if (fullscreen && ((window->last_fullscreen_flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN) && ((window->flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN_DESKTOP)) {
+ display = SDL_GetDisplayForWindow(window);
+ SDL_SetDisplayModeForDisplay(display, NULL);
+ if (_this->SetWindowFullscreen) {
+ _this->SetWindowFullscreen(_this, window, display, SDL_FALSE);
+ }
+ }
+
+ if (Cocoa_SetWindowFullscreenSpace(window, fullscreen)) {
+ if (Cocoa_IsWindowInFullscreenSpace(window) != fullscreen) {
+ return -1;
+ }
+ window->last_fullscreen_flags = window->flags;
+ return 0;
+ }
+ }
+#elif __WINRT__ && (NTDDI_VERSION < NTDDI_WIN10)
+ /* HACK: WinRT 8.x apps can't choose whether or not they are fullscreen
+ or not. The user can choose this, via OS-provided UI, but this can't
+ be set programmatically.
+
+ Just look at what SDL's WinRT video backend code detected with regards
+ to fullscreen (being active, or not), and figure out a return/error code
+ from that.
+ */
+ if (fullscreen == !(WINRT_DetectWindowFlags(window) & FULLSCREEN_MASK)) {
+ /* Uh oh, either:
+ 1. fullscreen was requested, and we're already windowed
+ 2. windowed-mode was requested, and we're already fullscreen
+
+ WinRT 8.x can't resolve either programmatically, so we're
+ giving up.
+ */
+ return -1;
+ } else {
+ /* Whatever was requested, fullscreen or windowed mode, is already
+ in-place.
+ */
+ return 0;
+ }
+#endif
+
+ display = SDL_GetDisplayForWindow(window);
+
+ if (fullscreen) {
+ /* Hide any other fullscreen windows */
+ if (display->fullscreen_window &&
+ display->fullscreen_window != window) {
+ SDL_MinimizeWindow(display->fullscreen_window);
+ }
+ }
+
+ /* See if anything needs to be done now */
+ if ((display->fullscreen_window == window) == fullscreen) {
+ if ((window->last_fullscreen_flags & FULLSCREEN_MASK) == (window->flags & FULLSCREEN_MASK)) {
+ return 0;
+ }
+ }
+
+ /* See if there are any fullscreen windows */
+ for (other = _this->windows; other; other = other->next) {
+ SDL_bool setDisplayMode = SDL_FALSE;
+
+ if (other == window) {
+ setDisplayMode = fullscreen;
+ } else if (FULLSCREEN_VISIBLE(other) &&
+ SDL_GetDisplayForWindow(other) == display) {
+ setDisplayMode = SDL_TRUE;
+ }
+
+ if (setDisplayMode) {
+ SDL_DisplayMode fullscreen_mode;
+
+ SDL_zero(fullscreen_mode);
+
+ if (SDL_GetWindowDisplayMode(other, &fullscreen_mode) == 0) {
+ SDL_bool resized = SDL_TRUE;
+
+ if (other->w == fullscreen_mode.w && other->h == fullscreen_mode.h) {
+ resized = SDL_FALSE;
+ }
+
+ /* only do the mode change if we want exclusive fullscreen */
+ if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
+ if (SDL_SetDisplayModeForDisplay(display, &fullscreen_mode) < 0) {
+ return -1;
+ }
+ } else {
+ if (SDL_SetDisplayModeForDisplay(display, NULL) < 0) {
+ return -1;
+ }
+ }
+
+ if (_this->SetWindowFullscreen) {
+ _this->SetWindowFullscreen(_this, other, display, SDL_TRUE);
+ }
+ display->fullscreen_window = other;
+
+ /* Generate a mode change event here */
+ if (resized) {
+ SDL_SendWindowEvent(other, SDL_WINDOWEVENT_RESIZED,
+ fullscreen_mode.w, fullscreen_mode.h);
+ } else {
+ SDL_OnWindowResized(other);
+ }
+
+ SDL_RestoreMousePosition(other);
+
+ window->last_fullscreen_flags = window->flags;
+ return 0;
+ }
+ }
+ }
+
+ /* Nope, restore the desktop mode */
+ SDL_SetDisplayModeForDisplay(display, NULL);
+
+ if (_this->SetWindowFullscreen) {
+ _this->SetWindowFullscreen(_this, window, display, SDL_FALSE);
+ }
+ display->fullscreen_window = NULL;
+
+ /* Generate a mode change event here */
+ SDL_OnWindowResized(window);
+
+ /* Restore the cursor position */
+ SDL_RestoreMousePosition(window);
+
+ window->last_fullscreen_flags = window->flags;
+ return 0;
+}
+
+#define CREATE_FLAGS \
+ (SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_ALWAYS_ON_TOP | SDL_WINDOW_SKIP_TASKBAR | SDL_WINDOW_POPUP_MENU | SDL_WINDOW_UTILITY | SDL_WINDOW_TOOLTIP | SDL_WINDOW_VULKAN)
+
+static void
+SDL_FinishWindowCreation(SDL_Window *window, Uint32 flags)
+{
+ if (flags & SDL_WINDOW_MAXIMIZED) {
+ SDL_MaximizeWindow(window);
+ }
+ if (flags & SDL_WINDOW_MINIMIZED) {
+ SDL_MinimizeWindow(window);
+ }
+ if (flags & SDL_WINDOW_FULLSCREEN) {
+ SDL_SetWindowFullscreen(window, flags);
+ }
+ if (flags & SDL_WINDOW_INPUT_GRABBED) {
+ SDL_SetWindowGrab(window, SDL_TRUE);
+ }
+ if (!(flags & SDL_WINDOW_HIDDEN)) {
+ SDL_ShowWindow(window);
+ }
+}
+
+SDL_Window *
+SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
+{
+ SDL_Window *window;
+
+ if (!_this) {
+ /* Initialize the video system if needed */
+ if (SDL_VideoInit(NULL) < 0) {
+ return NULL;
+ }
+ }
+
+ if ((((flags & SDL_WINDOW_UTILITY) != 0) + ((flags & SDL_WINDOW_TOOLTIP) != 0) + ((flags & SDL_WINDOW_POPUP_MENU) != 0)) > 1) {
+ SDL_SetError("Conflicting window flags specified");
+ return NULL;
+ }
+
+ /* Some platforms can't create zero-sized windows */
+ if (w < 1) {
+ w = 1;
+ }
+ if (h < 1) {
+ h = 1;
+ }
+
+ /* Some platforms blow up if the windows are too large. Raise it later? */
+ if ((w > 16384) || (h > 16384)) {
+ SDL_SetError("Window is too large.");
+ return NULL;
+ }
+
+ /* Some platforms have OpenGL enabled by default */
+#if (SDL_VIDEO_OPENGL && __MACOSX__) || __IPHONEOS__ || __ANDROID__ || __NACL__
+ if (!_this->is_dummy && !(flags & SDL_WINDOW_VULKAN)) {
+ flags |= SDL_WINDOW_OPENGL;
+ }
+#endif
+ if (flags & SDL_WINDOW_OPENGL) {
+ if (!_this->GL_CreateContext) {
+ SDL_SetError("No OpenGL support in video driver");
+ return NULL;
+ }
+ if (SDL_GL_LoadLibrary(NULL) < 0) {
+ return NULL;
+ }
+ }
+
+ if (flags & SDL_WINDOW_VULKAN) {
+ if (!_this->Vulkan_CreateSurface) {
+ SDL_SetError("Vulkan support is either not configured in SDL "
+ "or not available in video driver");
+ return NULL;
+ }
+ if (flags & SDL_WINDOW_OPENGL) {
+ SDL_SetError("Vulkan and OpenGL not supported on same window");
+ return NULL;
+ }
+ if (SDL_Vulkan_LoadLibrary(NULL) < 0) {
+ return NULL;
+ }
+ }
+
+ /* Unless the user has specified the high-DPI disabling hint, respect the
+ * SDL_WINDOW_ALLOW_HIGHDPI flag.
+ */
+ if (flags & SDL_WINDOW_ALLOW_HIGHDPI) {
+ if (SDL_GetHintBoolean(SDL_HINT_VIDEO_HIGHDPI_DISABLED, SDL_FALSE)) {
+ flags &= ~SDL_WINDOW_ALLOW_HIGHDPI;
+ }
+ }
+
+ window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
+ if (!window) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ window->magic = &_this->window_magic;
+ window->id = _this->next_object_id++;
+ window->x = x;
+ window->y = y;
+ window->w = w;
+ window->h = h;
+ if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISUNDEFINED(y) ||
+ SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ int displayIndex;
+ SDL_Rect bounds;
+
+ displayIndex = SDL_GetIndexOfDisplay(display);
+ SDL_GetDisplayBounds(displayIndex, &bounds);
+ if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISCENTERED(x)) {
+ window->x = bounds.x + (bounds.w - w) / 2;
+ }
+ if (SDL_WINDOWPOS_ISUNDEFINED(y) || SDL_WINDOWPOS_ISCENTERED(y)) {
+ window->y = bounds.y + (bounds.h - h) / 2;
+ }
+ }
+ window->windowed.x = window->x;
+ window->windowed.y = window->y;
+ window->windowed.w = window->w;
+ window->windowed.h = window->h;
+
+ if (flags & SDL_WINDOW_FULLSCREEN) {
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ int displayIndex;
+ SDL_Rect bounds;
+
+ displayIndex = SDL_GetIndexOfDisplay(display);
+ SDL_GetDisplayBounds(displayIndex, &bounds);
+
+ window->x = bounds.x;
+ window->y = bounds.y;
+ window->w = bounds.w;
+ window->h = bounds.h;
+ }
+
+ window->flags = ((flags & CREATE_FLAGS) | SDL_WINDOW_HIDDEN);
+ window->last_fullscreen_flags = window->flags;
+ window->opacity = 1.0f;
+ window->brightness = 1.0f;
+ window->next = _this->windows;
+ window->is_destroying = SDL_FALSE;
+
+ if (_this->windows) {
+ _this->windows->prev = window;
+ }
+ _this->windows = window;
+
+ if (_this->CreateSDLWindow && _this->CreateSDLWindow(_this, window) < 0) {
+ SDL_DestroyWindow(window);
+ return NULL;
+ }
+
+#if __WINRT__ && (NTDDI_VERSION < NTDDI_WIN10)
+ /* HACK: WinRT 8.x apps can't choose whether or not they are fullscreen
+ or not. The user can choose this, via OS-provided UI, but this can't
+ be set programmatically.
+
+ Just look at what SDL's WinRT video backend code detected with regards
+ to fullscreen (being active, or not), and figure out a return/error code
+ from that.
+ */
+ flags = window->flags;
+#endif
+
+ if (title) {
+ SDL_SetWindowTitle(window, title);
+ }
+ SDL_FinishWindowCreation(window, flags);
+
+ /* If the window was created fullscreen, make sure the mode code matches */
+ SDL_UpdateFullscreenMode(window, FULLSCREEN_VISIBLE(window));
+
+ return window;
+}
+
+SDL_Window *
+SDL_CreateWindowFrom(const void *data)
+{
+ SDL_Window *window;
+
+ if (!_this) {
+ SDL_UninitializedVideo();
+ return NULL;
+ }
+ if (!_this->CreateSDLWindowFrom) {
+ SDL_Unsupported();
+ return NULL;
+ }
+ window = (SDL_Window *)SDL_calloc(1, sizeof(*window));
+ if (!window) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ window->magic = &_this->window_magic;
+ window->id = _this->next_object_id++;
+ window->flags = SDL_WINDOW_FOREIGN;
+ window->last_fullscreen_flags = window->flags;
+ window->is_destroying = SDL_FALSE;
+ window->opacity = 1.0f;
+ window->brightness = 1.0f;
+ window->next = _this->windows;
+ if (_this->windows) {
+ _this->windows->prev = window;
+ }
+ _this->windows = window;
+
+ if (_this->CreateSDLWindowFrom(_this, window, data) < 0) {
+ SDL_DestroyWindow(window);
+ return NULL;
+ }
+ return window;
+}
+
+int
+SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
+{
+ SDL_bool loaded_opengl = SDL_FALSE;
+
+ if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
+ return SDL_SetError("No OpenGL support in video driver");
+ }
+
+ if (window->flags & SDL_WINDOW_FOREIGN) {
+ /* Can't destroy and re-create foreign windows, hrm */
+ flags |= SDL_WINDOW_FOREIGN;
+ } else {
+ flags &= ~SDL_WINDOW_FOREIGN;
+ }
+
+ /* Restore video mode, etc. */
+ SDL_HideWindow(window);
+
+ /* Tear down the old native window */
+ if (window->surface) {
+ window->surface->flags &= ~SDL_DONTFREE;
+ SDL_FreeSurface(window->surface);
+ window->surface = NULL;
+ }
+ if (_this->DestroyWindowFramebuffer) {
+ _this->DestroyWindowFramebuffer(_this, window);
+ }
+ if (_this->DestroyWindow && !(flags & SDL_WINDOW_FOREIGN)) {
+ _this->DestroyWindow(_this, window);
+ }
+
+ if ((window->flags & SDL_WINDOW_OPENGL) != (flags & SDL_WINDOW_OPENGL)) {
+ if (flags & SDL_WINDOW_OPENGL) {
+ if (SDL_GL_LoadLibrary(NULL) < 0) {
+ return -1;
+ }
+ loaded_opengl = SDL_TRUE;
+ } else {
+ SDL_GL_UnloadLibrary();
+ }
+ }
+
+ if ((window->flags & SDL_WINDOW_VULKAN) != (flags & SDL_WINDOW_VULKAN)) {
+ SDL_SetError("Can't change SDL_WINDOW_VULKAN window flag");
+ return -1;
+ }
+
+ if ((window->flags & SDL_WINDOW_VULKAN) && (flags & SDL_WINDOW_OPENGL)) {
+ SDL_SetError("Vulkan and OpenGL not supported on same window");
+ return -1;
+ }
+
+ window->flags = ((flags & CREATE_FLAGS) | SDL_WINDOW_HIDDEN);
+ window->last_fullscreen_flags = window->flags;
+ window->is_destroying = SDL_FALSE;
+
+ if (_this->CreateSDLWindow && !(flags & SDL_WINDOW_FOREIGN)) {
+ if (_this->CreateSDLWindow(_this, window) < 0) {
+ if (loaded_opengl) {
+ SDL_GL_UnloadLibrary();
+ window->flags &= ~SDL_WINDOW_OPENGL;
+ }
+ return -1;
+ }
+ }
+
+ if (flags & SDL_WINDOW_FOREIGN) {
+ window->flags |= SDL_WINDOW_FOREIGN;
+ }
+
+ if (_this->SetWindowTitle && window->title) {
+ _this->SetWindowTitle(_this, window);
+ }
+
+ if (_this->SetWindowIcon && window->icon) {
+ _this->SetWindowIcon(_this, window, window->icon);
+ }
+
+ if (window->hit_test) {
+ _this->SetWindowHitTest(window, SDL_TRUE);
+ }
+
+ SDL_FinishWindowCreation(window, flags);
+
+ return 0;
+}
+
+SDL_bool
+SDL_HasWindows(void)
+{
+ return (_this && _this->windows != NULL);
+}
+
+Uint32
+SDL_GetWindowID(SDL_Window * window)
+{
+ CHECK_WINDOW_MAGIC(window, 0);
+
+ return window->id;
+}
+
+SDL_Window *
+SDL_GetWindowFromID(Uint32 id)
+{
+ SDL_Window *window;
+
+ if (!_this) {
+ return NULL;
+ }
+ for (window = _this->windows; window; window = window->next) {
+ if (window->id == id) {
+ return window;
+ }
+ }
+ return NULL;
+}
+
+Uint32
+SDL_GetWindowFlags(SDL_Window * window)
+{
+ CHECK_WINDOW_MAGIC(window, 0);
+
+ return window->flags;
+}
+
+void
+SDL_SetWindowTitle(SDL_Window * window, const char *title)
+{
+ CHECK_WINDOW_MAGIC(window,);
+
+ if (title == window->title) {
+ return;
+ }
+ SDL_free(window->title);
+
+ window->title = SDL_strdup(title ? title : "");
+
+ if (_this->SetWindowTitle) {
+ _this->SetWindowTitle(_this, window);
+ }
+}
+
+const char *
+SDL_GetWindowTitle(SDL_Window * window)
+{
+ CHECK_WINDOW_MAGIC(window, "");
+
+ return window->title ? window->title : "";
+}
+
+void
+SDL_SetWindowIcon(SDL_Window * window, SDL_Surface * icon)
+{
+ CHECK_WINDOW_MAGIC(window,);
+
+ if (!icon) {
+ return;
+ }
+
+ SDL_FreeSurface(window->icon);
+
+ /* Convert the icon into ARGB8888 */
+ window->icon = SDL_ConvertSurfaceFormat(icon, SDL_PIXELFORMAT_ARGB8888, 0);
+ if (!window->icon) {
+ return;
+ }
+
+ if (_this->SetWindowIcon) {
+ _this->SetWindowIcon(_this, window, window->icon);
+ }
+}
+
+void*
+SDL_SetWindowData(SDL_Window * window, const char *name, void *userdata)
+{
+ SDL_WindowUserData *prev, *data;
+
+ CHECK_WINDOW_MAGIC(window, NULL);
+
+ /* Input validation */
+ if (name == NULL || name[0] == '\0') {
+ SDL_InvalidParamError("name");
+ return NULL;
+ }
+
+ /* See if the named data already exists */
+ prev = NULL;
+ for (data = window->data; data; prev = data, data = data->next) {
+ if (data->name && SDL_strcmp(data->name, name) == 0) {
+ void *last_value = data->data;
+
+ if (userdata) {
+ /* Set the new value */
+ data->data = userdata;
+ } else {
+ /* Delete this value */
+ if (prev) {
+ prev->next = data->next;
+ } else {
+ window->data = data->next;
+ }
+ SDL_free(data->name);
+ SDL_free(data);
+ }
+ return last_value;
+ }
+ }
+
+ /* Add new data to the window */
+ if (userdata) {
+ data = (SDL_WindowUserData *)SDL_malloc(sizeof(*data));
+ data->name = SDL_strdup(name);
+ data->data = userdata;
+ data->next = window->data;
+ window->data = data;
+ }
+ return NULL;
+}
+
+void *
+SDL_GetWindowData(SDL_Window * window, const char *name)
+{
+ SDL_WindowUserData *data;
+
+ CHECK_WINDOW_MAGIC(window, NULL);
+
+ /* Input validation */
+ if (name == NULL || name[0] == '\0') {
+ SDL_InvalidParamError("name");
+ return NULL;
+ }
+
+ for (data = window->data; data; data = data->next) {
+ if (data->name && SDL_strcmp(data->name, name) == 0) {
+ return data->data;
+ }
+ }
+ return NULL;
+}
+
+void
+SDL_SetWindowPosition(SDL_Window * window, int x, int y)
+{
+ CHECK_WINDOW_MAGIC(window,);
+
+ if (SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
+ int displayIndex = (x & 0xFFFF);
+ SDL_Rect bounds;
+ if (displayIndex >= _this->num_displays) {
+ displayIndex = 0;
+ }
+
+ SDL_zero(bounds);
+
+ SDL_GetDisplayBounds(displayIndex, &bounds);
+ if (SDL_WINDOWPOS_ISCENTERED(x)) {
+ x = bounds.x + (bounds.w - window->w) / 2;
+ }
+ if (SDL_WINDOWPOS_ISCENTERED(y)) {
+ y = bounds.y + (bounds.h - window->h) / 2;
+ }
+ }
+
+ if ((window->flags & SDL_WINDOW_FULLSCREEN)) {
+ if (!SDL_WINDOWPOS_ISUNDEFINED(x)) {
+ window->windowed.x = x;
+ }
+ if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
+ window->windowed.y = y;
+ }
+ } else {
+ if (!SDL_WINDOWPOS_ISUNDEFINED(x)) {
+ window->x = x;
+ }
+ if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
+ window->y = y;
+ }
+
+ if (_this->SetWindowPosition) {
+ _this->SetWindowPosition(_this, window);
+ }
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
+ }
+}
+
+void
+SDL_GetWindowPosition(SDL_Window * window, int *x, int *y)
+{
+ CHECK_WINDOW_MAGIC(window,);
+
+ /* Fullscreen windows are always at their display's origin */
+ if (window->flags & SDL_WINDOW_FULLSCREEN) {
+ int displayIndex;
+
+ if (x) {
+ *x = 0;
+ }
+ if (y) {
+ *y = 0;
+ }
+
+ /* Find the window's monitor and update to the
+ monitor offset. */
+ displayIndex = SDL_GetWindowDisplayIndex(window);
+ if (displayIndex >= 0) {
+ SDL_Rect bounds;
+
+ SDL_zero(bounds);
+
+ SDL_GetDisplayBounds(displayIndex, &bounds);
+ if (x) {
+ *x = bounds.x;
+ }
+ if (y) {
+ *y = bounds.y;
+ }
+ }
+ } else {
+ if (x) {
+ *x = window->x;
+ }
+ if (y) {
+ *y = window->y;
+ }
+ }
+}
+
+void
+SDL_SetWindowBordered(SDL_Window * window, SDL_bool bordered)
+{
+ CHECK_WINDOW_MAGIC(window,);
+ if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+ const int want = (bordered != SDL_FALSE); /* normalize the flag. */
+ const int have = ((window->flags & SDL_WINDOW_BORDERLESS) == 0);
+ if ((want != have) && (_this->SetWindowBordered)) {
+ if (want) {
+ window->flags &= ~SDL_WINDOW_BORDERLESS;
+ } else {
+ window->flags |= SDL_WINDOW_BORDERLESS;
+ }
+ _this->SetWindowBordered(_this, window, (SDL_bool) want);
+ }
+ }
+}
+
+void
+SDL_SetWindowResizable(SDL_Window * window, SDL_bool resizable)
+{
+ CHECK_WINDOW_MAGIC(window,);
+ if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+ const int want = (resizable != SDL_FALSE); /* normalize the flag. */
+ const int have = ((window->flags & SDL_WINDOW_RESIZABLE) != 0);
+ if ((want != have) && (_this->SetWindowResizable)) {
+ if (want) {
+ window->flags |= SDL_WINDOW_RESIZABLE;
+ } else {
+ window->flags &= ~SDL_WINDOW_RESIZABLE;
+ }
+ _this->SetWindowResizable(_this, window, (SDL_bool) want);
+ }
+ }
+}
+
+void
+SDL_SetWindowSize(SDL_Window * window, int w, int h)
+{
+ CHECK_WINDOW_MAGIC(window,);
+ if (w <= 0) {
+ SDL_InvalidParamError("w");
+ return;
+ }
+ if (h <= 0) {
+ SDL_InvalidParamError("h");
+ return;
+ }
+
+ /* Make sure we don't exceed any window size limits */
+ if (window->min_w && w < window->min_w) {
+ w = window->min_w;
+ }
+ if (window->max_w && w > window->max_w) {
+ w = window->max_w;
+ }
+ if (window->min_h && h < window->min_h) {
+ h = window->min_h;
+ }
+ if (window->max_h && h > window->max_h) {
+ h = window->max_h;
+ }
+
+ window->windowed.w = w;
+ window->windowed.h = h;
+
+ if (window->flags & SDL_WINDOW_FULLSCREEN) {
+ if (FULLSCREEN_VISIBLE(window) && (window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
+ window->last_fullscreen_flags = 0;
+ SDL_UpdateFullscreenMode(window, SDL_TRUE);
+ }
+ } else {
+ window->w = w;
+ window->h = h;
+ if (_this->SetWindowSize) {
+ _this->SetWindowSize(_this, window);
+ }
+ if (window->w == w && window->h == h) {
+ /* We didn't get a SDL_WINDOWEVENT_RESIZED event (by design) */
+ SDL_OnWindowResized(window);
+ }
+ }
+}
+
+void
+SDL_GetWindowSize(SDL_Window * window, int *w, int *h)
+{
+ CHECK_WINDOW_MAGIC(window,);
+ if (w) {
+ *w = window->w;
+ }
+ if (h) {
+ *h = window->h;
+ }
+}
+
+int
+SDL_GetWindowBordersSize(SDL_Window * window, int *top, int *left, int *bottom, int *right)
+{
+ int dummy = 0;
+
+ if (!top) { top = &dummy; }
+ if (!left) { left = &dummy; }
+ if (!right) { right = &dummy; }
+ if (!bottom) { bottom = &dummy; }
+
+ /* Always initialize, so applications don't have to care */
+ *top = *left = *bottom = *right = 0;
+
+ CHECK_WINDOW_MAGIC(window, -1);
+
+ if (!_this->GetWindowBordersSize) {
+ return SDL_Unsupported();
+ }
+
+ return _this->GetWindowBordersSize(_this, window, top, left, bottom, right);
+}
+
+void
+SDL_SetWindowMinimumSize(SDL_Window * window, int min_w, int min_h)
+{
+ CHECK_WINDOW_MAGIC(window,);
+ if (min_w <= 0) {
+ SDL_InvalidParamError("min_w");
+ return;
+ }
+ if (min_h <= 0) {
+ SDL_InvalidParamError("min_h");
+ return;
+ }
+
+ if ((window->max_w && min_w >= window->max_w) ||
+ (window->max_h && min_h >= window->max_h)) {
+ SDL_SetError("SDL_SetWindowMinimumSize(): Tried to set minimum size larger than maximum size");
+ return;
+ }
+
+ window->min_w = min_w;
+ window->min_h = min_h;
+
+ if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+ if (_this->SetWindowMinimumSize) {
+ _this->SetWindowMinimumSize(_this, window);
+ }
+ /* Ensure that window is not smaller than minimal size */
+ SDL_SetWindowSize(window, SDL_max(window->w, window->min_w), SDL_max(window->h, window->min_h));
+ }
+}
+
+void
+SDL_GetWindowMinimumSize(SDL_Window * window, int *min_w, int *min_h)
+{
+ CHECK_WINDOW_MAGIC(window,);
+ if (min_w) {
+ *min_w = window->min_w;
+ }
+ if (min_h) {
+ *min_h = window->min_h;
+ }
+}
+
+void
+SDL_SetWindowMaximumSize(SDL_Window * window, int max_w, int max_h)
+{
+ CHECK_WINDOW_MAGIC(window,);
+ if (max_w <= 0) {
+ SDL_InvalidParamError("max_w");
+ return;
+ }
+ if (max_h <= 0) {
+ SDL_InvalidParamError("max_h");
+ return;
+ }
+
+ if (max_w <= window->min_w || max_h <= window->min_h) {
+ SDL_SetError("SDL_SetWindowMaximumSize(): Tried to set maximum size smaller than minimum size");
+ return;
+ }
+
+ window->max_w = max_w;
+ window->max_h = max_h;
+
+ if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+ if (_this->SetWindowMaximumSize) {
+ _this->SetWindowMaximumSize(_this, window);
+ }
+ /* Ensure that window is not larger than maximal size */
+ SDL_SetWindowSize(window, SDL_min(window->w, window->max_w), SDL_min(window->h, window->max_h));
+ }
+}
+
+void
+SDL_GetWindowMaximumSize(SDL_Window * window, int *max_w, int *max_h)
+{
+ CHECK_WINDOW_MAGIC(window,);
+ if (max_w) {
+ *max_w = window->max_w;
+ }
+ if (max_h) {
+ *max_h = window->max_h;
+ }
+}
+
+void
+SDL_ShowWindow(SDL_Window * window)
+{
+ CHECK_WINDOW_MAGIC(window,);
+
+ if (window->flags & SDL_WINDOW_SHOWN) {
+ return;
+ }
+
+ if (_this->ShowWindow) {
+ _this->ShowWindow(_this, window);
+ }
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0);
+}
+
+void
+SDL_HideWindow(SDL_Window * window)
+{
+ CHECK_WINDOW_MAGIC(window,);
+
+ if (!(window->flags & SDL_WINDOW_SHOWN)) {
+ return;
+ }
+
+ window->is_hiding = SDL_TRUE;
+ SDL_UpdateFullscreenMode(window, SDL_FALSE);
+
+ if (_this->HideWindow) {
+ _this->HideWindow(_this, window);
+ }
+ window->is_hiding = SDL_FALSE;
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
+}
+
+void
+SDL_RaiseWindow(SDL_Window * window)
+{
+ CHECK_WINDOW_MAGIC(window,);
+
+ if (!(window->flags & SDL_WINDOW_SHOWN)) {
+ return;
+ }
+ if (_this->RaiseWindow) {
+ _this->RaiseWindow(_this, window);
+ }
+}
+
+void
+SDL_MaximizeWindow(SDL_Window * window)
+{
+ CHECK_WINDOW_MAGIC(window,);
+
+ if (window->flags & SDL_WINDOW_MAXIMIZED) {
+ return;
+ }
+
+ /* !!! FIXME: should this check if the window is resizable? */
+
+ if (_this->MaximizeWindow) {
+ _this->MaximizeWindow(_this, window);
+ }
+}
+
+void
+SDL_MinimizeWindow(SDL_Window * window)
+{
+ CHECK_WINDOW_MAGIC(window,);
+
+ if (window->flags & SDL_WINDOW_MINIMIZED) {
+ return;
+ }
+
+ SDL_UpdateFullscreenMode(window, SDL_FALSE);
+
+ if (_this->MinimizeWindow) {
+ _this->MinimizeWindow(_this, window);
+ }
+}
+
+void
+SDL_RestoreWindow(SDL_Window * window)
+{
+ CHECK_WINDOW_MAGIC(window,);
+
+ if (!(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
+ return;
+ }
+
+ if (_this->RestoreWindow) {
+ _this->RestoreWindow(_this, window);
+ }
+}
+
+int
+SDL_SetWindowFullscreen(SDL_Window * window, Uint32 flags)
+{
+ Uint32 oldflags;
+ CHECK_WINDOW_MAGIC(window, -1);
+
+ flags &= FULLSCREEN_MASK;
+
+ if (flags == (window->flags & FULLSCREEN_MASK)) {
+ return 0;
+ }
+
+ /* clear the previous flags and OR in the new ones */
+ oldflags = window->flags & FULLSCREEN_MASK;
+ window->flags &= ~FULLSCREEN_MASK;
+ window->flags |= flags;
+
+ if (SDL_UpdateFullscreenMode(window, FULLSCREEN_VISIBLE(window)) == 0) {
+ return 0;
+ }
+
+ window->flags &= ~FULLSCREEN_MASK;
+ window->flags |= oldflags;
+ return -1;
+}
+
+static SDL_Surface *
+SDL_CreateWindowFramebuffer(SDL_Window * window)
+{
+ Uint32 format;
+ void *pixels;
+ int pitch;
+ int bpp;
+ Uint32 Rmask, Gmask, Bmask, Amask;
+
+ if (!_this->CreateWindowFramebuffer || !_this->UpdateWindowFramebuffer) {
+ return NULL;
+ }
+
+ if (_this->CreateWindowFramebuffer(_this, window, &format, &pixels, &pitch) < 0) {
+ return NULL;
+ }
+
+ if (!SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
+ return NULL;
+ }
+
+ return SDL_CreateRGBSurfaceFrom(pixels, window->w, window->h, bpp, pitch, Rmask, Gmask, Bmask, Amask);
+}
+
+SDL_Surface *
+SDL_GetWindowSurface(SDL_Window * window)
+{
+ CHECK_WINDOW_MAGIC(window, NULL);
+
+ if (!window->surface_valid) {
+ if (window->surface) {
+ window->surface->flags &= ~SDL_DONTFREE;
+ SDL_FreeSurface(window->surface);
+ }
+ window->surface = SDL_CreateWindowFramebuffer(window);
+ if (window->surface) {
+ window->surface_valid = SDL_TRUE;
+ window->surface->flags |= SDL_DONTFREE;
+ }
+ }
+ return window->surface;
+}
+
+int
+SDL_UpdateWindowSurface(SDL_Window * window)
+{
+ SDL_Rect full_rect;
+
+ CHECK_WINDOW_MAGIC(window, -1);
+
+ full_rect.x = 0;
+ full_rect.y = 0;
+ full_rect.w = window->w;
+ full_rect.h = window->h;
+ return SDL_UpdateWindowSurfaceRects(window, &full_rect, 1);
+}
+
+int
+SDL_UpdateWindowSurfaceRects(SDL_Window * window, const SDL_Rect * rects,
+ int numrects)
+{
+ CHECK_WINDOW_MAGIC(window, -1);
+
+ if (!window->surface_valid) {
+ return SDL_SetError("Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface");
+ }
+
+ return _this->UpdateWindowFramebuffer(_this, window, rects, numrects);
+}
+
+int
+SDL_SetWindowBrightness(SDL_Window * window, float brightness)
+{
+ Uint16 ramp[256];
+ int status;
+
+ CHECK_WINDOW_MAGIC(window, -1);
+
+ SDL_CalculateGammaRamp(brightness, ramp);
+ status = SDL_SetWindowGammaRamp(window, ramp, ramp, ramp);
+ if (status == 0) {
+ window->brightness = brightness;
+ }
+ return status;
+}
+
+float
+SDL_GetWindowBrightness(SDL_Window * window)
+{
+ CHECK_WINDOW_MAGIC(window, 1.0f);
+
+ return window->brightness;
+}
+
+int
+SDL_SetWindowOpacity(SDL_Window * window, float opacity)
+{
+ int retval;
+ CHECK_WINDOW_MAGIC(window, -1);
+
+ if (!_this->SetWindowOpacity) {
+ return SDL_Unsupported();
+ }
+
+ if (opacity < 0.0f) {
+ opacity = 0.0f;
+ } else if (opacity > 1.0f) {
+ opacity = 1.0f;
+ }
+
+ retval = _this->SetWindowOpacity(_this, window, opacity);
+ if (retval == 0) {
+ window->opacity = opacity;
+ }
+
+ return retval;
+}
+
+int
+SDL_GetWindowOpacity(SDL_Window * window, float * out_opacity)
+{
+ CHECK_WINDOW_MAGIC(window, -1);
+
+ if (out_opacity) {
+ *out_opacity = window->opacity;
+ }
+
+ return 0;
+}
+
+int
+SDL_SetWindowModalFor(SDL_Window * modal_window, SDL_Window * parent_window)
+{
+ CHECK_WINDOW_MAGIC(modal_window, -1);
+ CHECK_WINDOW_MAGIC(parent_window, -1);
+
+ if (!_this->SetWindowModalFor) {
+ return SDL_Unsupported();
+ }
+
+ return _this->SetWindowModalFor(_this, modal_window, parent_window);
+}
+
+int
+SDL_SetWindowInputFocus(SDL_Window * window)
+{
+ CHECK_WINDOW_MAGIC(window, -1);
+
+ if (!_this->SetWindowInputFocus) {
+ return SDL_Unsupported();
+ }
+
+ return _this->SetWindowInputFocus(_this, window);
+}
+
+
+int
+SDL_SetWindowGammaRamp(SDL_Window * window, const Uint16 * red,
+ const Uint16 * green,
+ const Uint16 * blue)
+{
+ CHECK_WINDOW_MAGIC(window, -1);
+
+ if (!_this->SetWindowGammaRamp) {
+ return SDL_Unsupported();
+ }
+
+ if (!window->gamma) {
+ if (SDL_GetWindowGammaRamp(window, NULL, NULL, NULL) < 0) {
+ return -1;
+ }
+ SDL_assert(window->gamma != NULL);
+ }
+
+ if (red) {
+ SDL_memcpy(&window->gamma[0*256], red, 256*sizeof(Uint16));
+ }
+ if (green) {
+ SDL_memcpy(&window->gamma[1*256], green, 256*sizeof(Uint16));
+ }
+ if (blue) {
+ SDL_memcpy(&window->gamma[2*256], blue, 256*sizeof(Uint16));
+ }
+ if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
+ return _this->SetWindowGammaRamp(_this, window, window->gamma);
+ } else {
+ return 0;
+ }
+}
+
+int
+SDL_GetWindowGammaRamp(SDL_Window * window, Uint16 * red,
+ Uint16 * green,
+ Uint16 * blue)
+{
+ CHECK_WINDOW_MAGIC(window, -1);
+
+ if (!window->gamma) {
+ int i;
+
+ window->gamma = (Uint16 *)SDL_malloc(256*6*sizeof(Uint16));
+ if (!window->gamma) {
+ return SDL_OutOfMemory();
+ }
+ window->saved_gamma = window->gamma + 3*256;
+
+ if (_this->GetWindowGammaRamp) {
+ if (_this->GetWindowGammaRamp(_this, window, window->gamma) < 0) {
+ return -1;
+ }
+ } else {
+ /* Create an identity gamma ramp */
+ for (i = 0; i < 256; ++i) {
+ Uint16 value = (Uint16)((i << 8) | i);
+
+ window->gamma[0*256+i] = value;
+ window->gamma[1*256+i] = value;
+ window->gamma[2*256+i] = value;
+ }
+ }
+ SDL_memcpy(window->saved_gamma, window->gamma, 3*256*sizeof(Uint16));
+ }
+
+ if (red) {
+ SDL_memcpy(red, &window->gamma[0*256], 256*sizeof(Uint16));
+ }
+ if (green) {
+ SDL_memcpy(green, &window->gamma[1*256], 256*sizeof(Uint16));
+ }
+ if (blue) {
+ SDL_memcpy(blue, &window->gamma[2*256], 256*sizeof(Uint16));
+ }
+ return 0;
+}
+
+void
+SDL_UpdateWindowGrab(SDL_Window * window)
+{
+ SDL_Window *grabbed_window;
+ SDL_bool grabbed;
+ if ((SDL_GetMouse()->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) &&
+ (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
+ grabbed = SDL_TRUE;
+ } else {
+ grabbed = SDL_FALSE;
+ }
+
+ grabbed_window = _this->grabbed_window;
+ if (grabbed) {
+ if (grabbed_window && (grabbed_window != window)) {
+ /* stealing a grab from another window! */
+ grabbed_window->flags &= ~SDL_WINDOW_INPUT_GRABBED;
+ if (_this->SetWindowGrab) {
+ _this->SetWindowGrab(_this, grabbed_window, SDL_FALSE);
+ }
+ }
+ _this->grabbed_window = window;
+ } else if (grabbed_window == window) {
+ _this->grabbed_window = NULL; /* ungrabbing. */
+ }
+
+ if (_this->SetWindowGrab) {
+ _this->SetWindowGrab(_this, window, grabbed);
+ }
+}
+
+void
+SDL_SetWindowGrab(SDL_Window * window, SDL_bool grabbed)
+{
+ CHECK_WINDOW_MAGIC(window,);
+
+ if (!!grabbed == !!(window->flags & SDL_WINDOW_INPUT_GRABBED)) {
+ return;
+ }
+ if (grabbed) {
+ window->flags |= SDL_WINDOW_INPUT_GRABBED;
+ } else {
+ window->flags &= ~SDL_WINDOW_INPUT_GRABBED;
+ }
+ SDL_UpdateWindowGrab(window);
+}
+
+SDL_bool
+SDL_GetWindowGrab(SDL_Window * window)
+{
+ CHECK_WINDOW_MAGIC(window, SDL_FALSE);
+ SDL_assert(!_this->grabbed_window || ((_this->grabbed_window->flags & SDL_WINDOW_INPUT_GRABBED) != 0));
+ return window == _this->grabbed_window;
+}
+
+SDL_Window *
+SDL_GetGrabbedWindow(void)
+{
+ SDL_assert(!_this->grabbed_window || ((_this->grabbed_window->flags & SDL_WINDOW_INPUT_GRABBED) != 0));
+ return _this->grabbed_window;
+}
+
+void
+SDL_OnWindowShown(SDL_Window * window)
+{
+ SDL_OnWindowRestored(window);
+}
+
+void
+SDL_OnWindowHidden(SDL_Window * window)
+{
+ SDL_UpdateFullscreenMode(window, SDL_FALSE);
+}
+
+void
+SDL_OnWindowResized(SDL_Window * window)
+{
+ window->surface_valid = SDL_FALSE;
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h);
+}
+
+void
+SDL_OnWindowMinimized(SDL_Window * window)
+{
+ SDL_UpdateFullscreenMode(window, SDL_FALSE);
+}
+
+void
+SDL_OnWindowRestored(SDL_Window * window)
+{
+ /*
+ * FIXME: Is this fine to just remove this, or should it be preserved just
+ * for the fullscreen case? In principle it seems like just hiding/showing
+ * windows shouldn't affect the stacking order; maybe the right fix is to
+ * re-decouple OnWindowShown and OnWindowRestored.
+ */
+ /*SDL_RaiseWindow(window);*/
+
+ if (FULLSCREEN_VISIBLE(window)) {
+ SDL_UpdateFullscreenMode(window, SDL_TRUE);
+ }
+}
+
+void
+SDL_OnWindowEnter(SDL_Window * window)
+{
+ if (_this->OnWindowEnter) {
+ _this->OnWindowEnter(_this, window);
+ }
+}
+
+void
+SDL_OnWindowLeave(SDL_Window * window)
+{
+}
+
+void
+SDL_OnWindowFocusGained(SDL_Window * window)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ if (window->gamma && _this->SetWindowGammaRamp) {
+ _this->SetWindowGammaRamp(_this, window, window->gamma);
+ }
+
+ if (mouse && mouse->relative_mode) {
+ SDL_SetMouseFocus(window);
+ SDL_WarpMouseInWindow(window, window->w/2, window->h/2);
+ }
+
+ SDL_UpdateWindowGrab(window);
+}
+
+static SDL_bool
+ShouldMinimizeOnFocusLoss(SDL_Window * window)
+{
+ if (!(window->flags & SDL_WINDOW_FULLSCREEN) || window->is_destroying) {
+ return SDL_FALSE;
+ }
+
+#ifdef __MACOSX__
+ if (SDL_strcmp(_this->name, "cocoa") == 0) { /* don't do this for X11, etc */
+ if (Cocoa_IsWindowInFullscreenSpace(window)) {
+ return SDL_FALSE;
+ }
+ }
+#endif
+
+ return SDL_GetHintBoolean(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, SDL_TRUE);
+}
+
+void
+SDL_OnWindowFocusLost(SDL_Window * window)
+{
+ if (window->gamma && _this->SetWindowGammaRamp) {
+ _this->SetWindowGammaRamp(_this, window, window->saved_gamma);
+ }
+
+ SDL_UpdateWindowGrab(window);
+
+ if (ShouldMinimizeOnFocusLoss(window)) {
+ SDL_MinimizeWindow(window);
+ }
+}
+
+/* !!! FIXME: is this different than SDL_GetKeyboardFocus()?
+ !!! FIXME: Also, SDL_GetKeyboardFocus() is O(1), this isn't. */
+SDL_Window *
+SDL_GetFocusWindow(void)
+{
+ SDL_Window *window;
+
+ if (!_this) {
+ return NULL;
+ }
+ for (window = _this->windows; window; window = window->next) {
+ if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
+ return window;
+ }
+ }
+ return NULL;
+}
+
+void
+SDL_DestroyWindow(SDL_Window * window)
+{
+ SDL_VideoDisplay *display;
+
+ CHECK_WINDOW_MAGIC(window,);
+
+ window->is_destroying = SDL_TRUE;
+
+ /* Restore video mode, etc. */
+ SDL_HideWindow(window);
+
+ /* Make sure this window no longer has focus */
+ if (SDL_GetKeyboardFocus() == window) {
+ SDL_SetKeyboardFocus(NULL);
+ }
+ if (SDL_GetMouseFocus() == window) {
+ SDL_SetMouseFocus(NULL);
+ }
+
+ /* make no context current if this is the current context window. */
+ if (window->flags & SDL_WINDOW_OPENGL) {
+ if (_this->current_glwin == window) {
+ SDL_GL_MakeCurrent(window, NULL);
+ }
+ }
+
+ if (window->surface) {
+ window->surface->flags &= ~SDL_DONTFREE;
+ SDL_FreeSurface(window->surface);
+ }
+ if (_this->DestroyWindowFramebuffer) {
+ _this->DestroyWindowFramebuffer(_this, window);
+ }
+ if (_this->DestroyWindow) {
+ _this->DestroyWindow(_this, window);
+ }
+ if (window->flags & SDL_WINDOW_OPENGL) {
+ SDL_GL_UnloadLibrary();
+ }
+ if (window->flags & SDL_WINDOW_VULKAN) {
+ SDL_Vulkan_UnloadLibrary();
+ }
+
+ display = SDL_GetDisplayForWindow(window);
+ if (display->fullscreen_window == window) {
+ display->fullscreen_window = NULL;
+ }
+
+ /* Now invalidate magic */
+ window->magic = NULL;
+
+ /* Free memory associated with the window */
+ SDL_free(window->title);
+ SDL_FreeSurface(window->icon);
+ SDL_free(window->gamma);
+ while (window->data) {
+ SDL_WindowUserData *data = window->data;
+
+ window->data = data->next;
+ SDL_free(data->name);
+ SDL_free(data);
+ }
+
+ /* Unlink the window from the list */
+ if (window->next) {
+ window->next->prev = window->prev;
+ }
+ if (window->prev) {
+ window->prev->next = window->next;
+ } else {
+ _this->windows = window->next;
+ }
+
+ SDL_free(window);
+}
+
+SDL_bool
+SDL_IsScreenSaverEnabled()
+{
+ if (!_this) {
+ return SDL_TRUE;
+ }
+ return _this->suspend_screensaver ? SDL_FALSE : SDL_TRUE;
+}
+
+void
+SDL_EnableScreenSaver()
+{
+ if (!_this) {
+ return;
+ }
+ if (!_this->suspend_screensaver) {
+ return;
+ }
+ _this->suspend_screensaver = SDL_FALSE;
+ if (_this->SuspendScreenSaver) {
+ _this->SuspendScreenSaver(_this);
+ }
+}
+
+void
+SDL_DisableScreenSaver()
+{
+ if (!_this) {
+ return;
+ }
+ if (_this->suspend_screensaver) {
+ return;
+ }
+ _this->suspend_screensaver = SDL_TRUE;
+ if (_this->SuspendScreenSaver) {
+ _this->SuspendScreenSaver(_this);
+ }
+}
+
+void
+SDL_VideoQuit(void)
+{
+ int i, j;
+
+ if (!_this) {
+ return;
+ }
+
+ /* Halt event processing before doing anything else */
+ SDL_TouchQuit();
+ SDL_MouseQuit();
+ SDL_KeyboardQuit();
+ SDL_QuitSubSystem(SDL_INIT_EVENTS);
+
+ SDL_EnableScreenSaver();
+
+ /* Clean up the system video */
+ while (_this->windows) {
+ SDL_DestroyWindow(_this->windows);
+ }
+ _this->VideoQuit(_this);
+
+ for (i = 0; i < _this->num_displays; ++i) {
+ SDL_VideoDisplay *display = &_this->displays[i];
+ for (j = display->num_display_modes; j--;) {
+ SDL_free(display->display_modes[j].driverdata);
+ display->display_modes[j].driverdata = NULL;
+ }
+ SDL_free(display->display_modes);
+ display->display_modes = NULL;
+ SDL_free(display->desktop_mode.driverdata);
+ display->desktop_mode.driverdata = NULL;
+ SDL_free(display->driverdata);
+ display->driverdata = NULL;
+ }
+ if (_this->displays) {
+ for (i = 0; i < _this->num_displays; ++i) {
+ SDL_free(_this->displays[i].name);
+ }
+ SDL_free(_this->displays);
+ _this->displays = NULL;
+ _this->num_displays = 0;
+ }
+ SDL_free(_this->clipboard_text);
+ _this->clipboard_text = NULL;
+ _this->free(_this);
+ _this = NULL;
+}
+
+int
+SDL_GL_LoadLibrary(const char *path)
+{
+ int retval;
+
+ if (!_this) {
+ return SDL_UninitializedVideo();
+ }
+ if (_this->gl_config.driver_loaded) {
+ if (path && SDL_strcmp(path, _this->gl_config.driver_path) != 0) {
+ return SDL_SetError("OpenGL library already loaded");
+ }
+ retval = 0;
+ } else {
+ if (!_this->GL_LoadLibrary) {
+ return SDL_SetError("No dynamic GL support in video driver");
+ }
+ retval = _this->GL_LoadLibrary(_this, path);
+ }
+ if (retval == 0) {
+ ++_this->gl_config.driver_loaded;
+ } else {
+ if (_this->GL_UnloadLibrary) {
+ _this->GL_UnloadLibrary(_this);
+ }
+ }
+ return (retval);
+}
+
+void *
+SDL_GL_GetProcAddress(const char *proc)
+{
+ void *func;
+
+ if (!_this) {
+ SDL_UninitializedVideo();
+ return NULL;
+ }
+ func = NULL;
+ if (_this->GL_GetProcAddress) {
+ if (_this->gl_config.driver_loaded) {
+ func = _this->GL_GetProcAddress(_this, proc);
+ } else {
+ SDL_SetError("No GL driver has been loaded");
+ }
+ } else {
+ SDL_SetError("No dynamic GL support in video driver");
+ }
+ return func;
+}
+
+void
+SDL_GL_UnloadLibrary(void)
+{
+ if (!_this) {
+ SDL_UninitializedVideo();
+ return;
+ }
+ if (_this->gl_config.driver_loaded > 0) {
+ if (--_this->gl_config.driver_loaded > 0) {
+ return;
+ }
+ if (_this->GL_UnloadLibrary) {
+ _this->GL_UnloadLibrary(_this);
+ }
+ }
+}
+
+#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
+static SDL_INLINE SDL_bool
+isAtLeastGL3(const char *verstr)
+{
+ return (verstr && (SDL_atoi(verstr) >= 3));
+}
+#endif
+
+SDL_bool
+SDL_GL_ExtensionSupported(const char *extension)
+{
+#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
+ const GLubyte *(APIENTRY * glGetStringFunc) (GLenum);
+ const char *extensions;
+ const char *start;
+ const char *where, *terminator;
+
+ /* Extension names should not have spaces. */
+ where = SDL_strchr(extension, ' ');
+ if (where || *extension == '\0') {
+ return SDL_FALSE;
+ }
+ /* See if there's an environment variable override */
+ start = SDL_getenv(extension);
+ if (start && *start == '0') {
+ return SDL_FALSE;
+ }
+
+ /* Lookup the available extensions */
+
+ glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
+ if (!glGetStringFunc) {
+ return SDL_FALSE;
+ }
+
+ if (isAtLeastGL3((const char *) glGetStringFunc(GL_VERSION))) {
+ const GLubyte *(APIENTRY * glGetStringiFunc) (GLenum, GLuint);
+ void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
+ GLint num_exts = 0;
+ GLint i;
+
+ glGetStringiFunc = SDL_GL_GetProcAddress("glGetStringi");
+ glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
+ if ((!glGetStringiFunc) || (!glGetIntegervFunc)) {
+ return SDL_FALSE;
+ }
+
+ #ifndef GL_NUM_EXTENSIONS
+ #define GL_NUM_EXTENSIONS 0x821D
+ #endif
+ glGetIntegervFunc(GL_NUM_EXTENSIONS, &num_exts);
+ for (i = 0; i < num_exts; i++) {
+ const char *thisext = (const char *) glGetStringiFunc(GL_EXTENSIONS, i);
+ if (SDL_strcmp(thisext, extension) == 0) {
+ return SDL_TRUE;
+ }
+ }
+
+ return SDL_FALSE;
+ }
+
+ /* Try the old way with glGetString(GL_EXTENSIONS) ... */
+
+ extensions = (const char *) glGetStringFunc(GL_EXTENSIONS);
+ if (!extensions) {
+ return SDL_FALSE;
+ }
+ /*
+ * It takes a bit of care to be fool-proof about parsing the OpenGL
+ * extensions string. Don't be fooled by sub-strings, etc.
+ */
+
+ start = extensions;
+
+ for (;;) {
+ where = SDL_strstr(start, extension);
+ if (!where)
+ break;
+
+ terminator = where + SDL_strlen(extension);
+ if (where == extensions || *(where - 1) == ' ')
+ if (*terminator == ' ' || *terminator == '\0')
+ return SDL_TRUE;
+
+ start = terminator;
+ }
+ return SDL_FALSE;
+#else
+ return SDL_FALSE;
+#endif
+}
+
+/* Deduce supported ES profile versions from the supported
+ ARB_ES*_compatibility extensions. There is no direct query.
+
+ This is normally only called when the OpenGL driver supports
+ {GLX,WGL}_EXT_create_context_es2_profile.
+ */
+void
+SDL_GL_DeduceMaxSupportedESProfile(int* major, int* minor)
+{
+/* THIS REQUIRES AN EXISTING GL CONTEXT THAT HAS BEEN MADE CURRENT. */
+/* Please refer to https://bugzilla.libsdl.org/show_bug.cgi?id=3725 for discussion. */
+#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
+ /* XXX This is fragile; it will break in the event of release of
+ * new versions of OpenGL ES.
+ */
+ if (SDL_GL_ExtensionSupported("GL_ARB_ES3_2_compatibility")) {
+ *major = 3;
+ *minor = 2;
+ } else if (SDL_GL_ExtensionSupported("GL_ARB_ES3_1_compatibility")) {
+ *major = 3;
+ *minor = 1;
+ } else if (SDL_GL_ExtensionSupported("GL_ARB_ES3_compatibility")) {
+ *major = 3;
+ *minor = 0;
+ } else {
+ *major = 2;
+ *minor = 0;
+ }
+#endif
+}
+
+void
+SDL_GL_ResetAttributes()
+{
+ if (!_this) {
+ return;
+ }
+
+ _this->gl_config.red_size = 3;
+ _this->gl_config.green_size = 3;
+ _this->gl_config.blue_size = 2;
+ _this->gl_config.alpha_size = 0;
+ _this->gl_config.buffer_size = 0;
+ _this->gl_config.depth_size = 16;
+ _this->gl_config.stencil_size = 0;
+ _this->gl_config.double_buffer = 1;
+ _this->gl_config.accum_red_size = 0;
+ _this->gl_config.accum_green_size = 0;
+ _this->gl_config.accum_blue_size = 0;
+ _this->gl_config.accum_alpha_size = 0;
+ _this->gl_config.stereo = 0;
+ _this->gl_config.multisamplebuffers = 0;
+ _this->gl_config.multisamplesamples = 0;
+ _this->gl_config.retained_backing = 1;
+ _this->gl_config.accelerated = -1; /* accelerated or not, both are fine */
+
+ if (_this->GL_DefaultProfileConfig) {
+ _this->GL_DefaultProfileConfig(_this, &_this->gl_config.profile_mask,
+ &_this->gl_config.major_version,
+ &_this->gl_config.minor_version);
+ } else {
+#if SDL_VIDEO_OPENGL
+ _this->gl_config.major_version = 2;
+ _this->gl_config.minor_version = 1;
+ _this->gl_config.profile_mask = 0;
+#elif SDL_VIDEO_OPENGL_ES2
+ _this->gl_config.major_version = 2;
+ _this->gl_config.minor_version = 0;
+ _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
+#elif SDL_VIDEO_OPENGL_ES
+ _this->gl_config.major_version = 1;
+ _this->gl_config.minor_version = 1;
+ _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
+#endif
+ }
+
+ _this->gl_config.flags = 0;
+ _this->gl_config.framebuffer_srgb_capable = 0;
+ _this->gl_config.no_error = 0;
+ _this->gl_config.release_behavior = SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH;
+ _this->gl_config.reset_notification = SDL_GL_CONTEXT_RESET_NO_NOTIFICATION;
+
+ _this->gl_config.share_with_current_context = 0;
+}
+
+int
+SDL_GL_SetAttribute(SDL_GLattr attr, int value)
+{
+#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
+ int retval;
+
+ if (!_this) {
+ return SDL_UninitializedVideo();
+ }
+ retval = 0;
+ switch (attr) {
+ case SDL_GL_RED_SIZE:
+ _this->gl_config.red_size = value;
+ break;
+ case SDL_GL_GREEN_SIZE:
+ _this->gl_config.green_size = value;
+ break;
+ case SDL_GL_BLUE_SIZE:
+ _this->gl_config.blue_size = value;
+ break;
+ case SDL_GL_ALPHA_SIZE:
+ _this->gl_config.alpha_size = value;
+ break;
+ case SDL_GL_DOUBLEBUFFER:
+ _this->gl_config.double_buffer = value;
+ break;
+ case SDL_GL_BUFFER_SIZE:
+ _this->gl_config.buffer_size = value;
+ break;
+ case SDL_GL_DEPTH_SIZE:
+ _this->gl_config.depth_size = value;
+ break;
+ case SDL_GL_STENCIL_SIZE:
+ _this->gl_config.stencil_size = value;
+ break;
+ case SDL_GL_ACCUM_RED_SIZE:
+ _this->gl_config.accum_red_size = value;
+ break;
+ case SDL_GL_ACCUM_GREEN_SIZE:
+ _this->gl_config.accum_green_size = value;
+ break;
+ case SDL_GL_ACCUM_BLUE_SIZE:
+ _this->gl_config.accum_blue_size = value;
+ break;
+ case SDL_GL_ACCUM_ALPHA_SIZE:
+ _this->gl_config.accum_alpha_size = value;
+ break;
+ case SDL_GL_STEREO:
+ _this->gl_config.stereo = value;
+ break;
+ case SDL_GL_MULTISAMPLEBUFFERS:
+ _this->gl_config.multisamplebuffers = value;
+ break;
+ case SDL_GL_MULTISAMPLESAMPLES:
+ _this->gl_config.multisamplesamples = value;
+ break;
+ case SDL_GL_ACCELERATED_VISUAL:
+ _this->gl_config.accelerated = value;
+ break;
+ case SDL_GL_RETAINED_BACKING:
+ _this->gl_config.retained_backing = value;
+ break;
+ case SDL_GL_CONTEXT_MAJOR_VERSION:
+ _this->gl_config.major_version = value;
+ break;
+ case SDL_GL_CONTEXT_MINOR_VERSION:
+ _this->gl_config.minor_version = value;
+ break;
+ case SDL_GL_CONTEXT_EGL:
+ /* FIXME: SDL_GL_CONTEXT_EGL to be deprecated in SDL 2.1 */
+ if (value != 0) {
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
+ } else {
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0);
+ };
+ break;
+ case SDL_GL_CONTEXT_FLAGS:
+ if (value & ~(SDL_GL_CONTEXT_DEBUG_FLAG |
+ SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG |
+ SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG |
+ SDL_GL_CONTEXT_RESET_ISOLATION_FLAG)) {
+ retval = SDL_SetError("Unknown OpenGL context flag %d", value);
+ break;
+ }
+ _this->gl_config.flags = value;
+ break;
+ case SDL_GL_CONTEXT_PROFILE_MASK:
+ if (value != 0 &&
+ value != SDL_GL_CONTEXT_PROFILE_CORE &&
+ value != SDL_GL_CONTEXT_PROFILE_COMPATIBILITY &&
+ value != SDL_GL_CONTEXT_PROFILE_ES) {
+ retval = SDL_SetError("Unknown OpenGL context profile %d", value);
+ break;
+ }
+ _this->gl_config.profile_mask = value;
+ break;
+ case SDL_GL_SHARE_WITH_CURRENT_CONTEXT:
+ _this->gl_config.share_with_current_context = value;
+ break;
+ case SDL_GL_FRAMEBUFFER_SRGB_CAPABLE:
+ _this->gl_config.framebuffer_srgb_capable = value;
+ break;
+ case SDL_GL_CONTEXT_RELEASE_BEHAVIOR:
+ _this->gl_config.release_behavior = value;
+ break;
+ case SDL_GL_CONTEXT_RESET_NOTIFICATION:
+ _this->gl_config.reset_notification = value;
+ break;
+ case SDL_GL_CONTEXT_NO_ERROR:
+ _this->gl_config.no_error = value;
+ break;
+ default:
+ retval = SDL_SetError("Unknown OpenGL attribute");
+ break;
+ }
+ return retval;
+#else
+ return SDL_Unsupported();
+#endif /* SDL_VIDEO_OPENGL */
+}
+
+int
+SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
+{
+#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
+ GLenum (APIENTRY *glGetErrorFunc) (void);
+ GLenum attrib = 0;
+ GLenum error = 0;
+
+ /*
+ * Some queries in Core Profile desktop OpenGL 3+ contexts require
+ * glGetFramebufferAttachmentParameteriv instead of glGetIntegerv. Note that
+ * the enums we use for the former function don't exist in OpenGL ES 2, and
+ * the function itself doesn't exist prior to OpenGL 3 and OpenGL ES 2.
+ */
+#if SDL_VIDEO_OPENGL
+ const GLubyte *(APIENTRY *glGetStringFunc) (GLenum name);
+ void (APIENTRY *glGetFramebufferAttachmentParameterivFunc) (GLenum target, GLenum attachment, GLenum pname, GLint* params);
+ GLenum attachment = GL_BACK_LEFT;
+ GLenum attachmentattrib = 0;
+#endif
+
+ if (!value) {
+ return SDL_InvalidParamError("value");
+ }
+
+ /* Clear value in any case */
+ *value = 0;
+
+ if (!_this) {
+ return SDL_UninitializedVideo();
+ }
+
+ switch (attr) {
+ case SDL_GL_RED_SIZE:
+#if SDL_VIDEO_OPENGL
+ attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE;
+#endif
+ attrib = GL_RED_BITS;
+ break;
+ case SDL_GL_BLUE_SIZE:
+#if SDL_VIDEO_OPENGL
+ attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE;
+#endif
+ attrib = GL_BLUE_BITS;
+ break;
+ case SDL_GL_GREEN_SIZE:
+#if SDL_VIDEO_OPENGL
+ attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE;
+#endif
+ attrib = GL_GREEN_BITS;
+ break;
+ case SDL_GL_ALPHA_SIZE:
+#if SDL_VIDEO_OPENGL
+ attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE;
+#endif
+ attrib = GL_ALPHA_BITS;
+ break;
+ case SDL_GL_DOUBLEBUFFER:
+#if SDL_VIDEO_OPENGL
+ attrib = GL_DOUBLEBUFFER;
+ break;
+#else
+ /* OpenGL ES 1.0 and above specifications have EGL_SINGLE_BUFFER */
+ /* parameter which switches double buffer to single buffer. OpenGL ES */
+ /* SDL driver must set proper value after initialization */
+ *value = _this->gl_config.double_buffer;
+ return 0;
+#endif
+ case SDL_GL_DEPTH_SIZE:
+#if SDL_VIDEO_OPENGL
+ attachment = GL_DEPTH;
+ attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE;
+#endif
+ attrib = GL_DEPTH_BITS;
+ break;
+ case SDL_GL_STENCIL_SIZE:
+#if SDL_VIDEO_OPENGL
+ attachment = GL_STENCIL;
+ attachmentattrib = GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE;
+#endif
+ attrib = GL_STENCIL_BITS;
+ break;
+#if SDL_VIDEO_OPENGL
+ case SDL_GL_ACCUM_RED_SIZE:
+ attrib = GL_ACCUM_RED_BITS;
+ break;
+ case SDL_GL_ACCUM_GREEN_SIZE:
+ attrib = GL_ACCUM_GREEN_BITS;
+ break;
+ case SDL_GL_ACCUM_BLUE_SIZE:
+ attrib = GL_ACCUM_BLUE_BITS;
+ break;
+ case SDL_GL_ACCUM_ALPHA_SIZE:
+ attrib = GL_ACCUM_ALPHA_BITS;
+ break;
+ case SDL_GL_STEREO:
+ attrib = GL_STEREO;
+ break;
+#else
+ case SDL_GL_ACCUM_RED_SIZE:
+ case SDL_GL_ACCUM_GREEN_SIZE:
+ case SDL_GL_ACCUM_BLUE_SIZE:
+ case SDL_GL_ACCUM_ALPHA_SIZE:
+ case SDL_GL_STEREO:
+ /* none of these are supported in OpenGL ES */
+ *value = 0;
+ return 0;
+#endif
+ case SDL_GL_MULTISAMPLEBUFFERS:
+ attrib = GL_SAMPLE_BUFFERS;
+ break;
+ case SDL_GL_MULTISAMPLESAMPLES:
+ attrib = GL_SAMPLES;
+ break;
+ case SDL_GL_CONTEXT_RELEASE_BEHAVIOR:
+#if SDL_VIDEO_OPENGL
+ attrib = GL_CONTEXT_RELEASE_BEHAVIOR;
+#else
+ attrib = GL_CONTEXT_RELEASE_BEHAVIOR_KHR;
+#endif
+ break;
+ case SDL_GL_BUFFER_SIZE:
+ {
+ int rsize = 0, gsize = 0, bsize = 0, asize = 0;
+
+ /* There doesn't seem to be a single flag in OpenGL for this! */
+ if (SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &rsize) < 0) {
+ return -1;
+ }
+ if (SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &gsize) < 0) {
+ return -1;
+ }
+ if (SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &bsize) < 0) {
+ return -1;
+ }
+ if (SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &asize) < 0) {
+ return -1;
+ }
+
+ *value = rsize + gsize + bsize + asize;
+ return 0;
+ }
+ case SDL_GL_ACCELERATED_VISUAL:
+ {
+ /* FIXME: How do we get this information? */
+ *value = (_this->gl_config.accelerated != 0);
+ return 0;
+ }
+ case SDL_GL_RETAINED_BACKING:
+ {
+ *value = _this->gl_config.retained_backing;
+ return 0;
+ }
+ case SDL_GL_CONTEXT_MAJOR_VERSION:
+ {
+ *value = _this->gl_config.major_version;
+ return 0;
+ }
+ case SDL_GL_CONTEXT_MINOR_VERSION:
+ {
+ *value = _this->gl_config.minor_version;
+ return 0;
+ }
+ case SDL_GL_CONTEXT_EGL:
+ /* FIXME: SDL_GL_CONTEXT_EGL to be deprecated in SDL 2.1 */
+ {
+ if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
+ *value = 1;
+ }
+ else {
+ *value = 0;
+ }
+ return 0;
+ }
+ case SDL_GL_CONTEXT_FLAGS:
+ {
+ *value = _this->gl_config.flags;
+ return 0;
+ }
+ case SDL_GL_CONTEXT_PROFILE_MASK:
+ {
+ *value = _this->gl_config.profile_mask;
+ return 0;
+ }
+ case SDL_GL_SHARE_WITH_CURRENT_CONTEXT:
+ {
+ *value = _this->gl_config.share_with_current_context;
+ return 0;
+ }
+ case SDL_GL_FRAMEBUFFER_SRGB_CAPABLE:
+ {
+ *value = _this->gl_config.framebuffer_srgb_capable;
+ return 0;
+ }
+ case SDL_GL_CONTEXT_NO_ERROR:
+ {
+ *value = _this->gl_config.no_error;
+ return 0;
+ }
+ default:
+ return SDL_SetError("Unknown OpenGL attribute");
+ }
+
+#if SDL_VIDEO_OPENGL
+ glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
+ if (!glGetStringFunc) {
+ return -1;
+ }
+
+ if (attachmentattrib && isAtLeastGL3((const char *) glGetStringFunc(GL_VERSION))) {
+ glGetFramebufferAttachmentParameterivFunc = SDL_GL_GetProcAddress("glGetFramebufferAttachmentParameteriv");
+
+ if (glGetFramebufferAttachmentParameterivFunc) {
+ glGetFramebufferAttachmentParameterivFunc(GL_FRAMEBUFFER, attachment, attachmentattrib, (GLint *) value);
+ } else {
+ return -1;
+ }
+ } else
+#endif
+ {
+ void (APIENTRY *glGetIntegervFunc) (GLenum pname, GLint * params);
+ glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
+ if (glGetIntegervFunc) {
+ glGetIntegervFunc(attrib, (GLint *) value);
+ } else {
+ return -1;
+ }
+ }
+
+ glGetErrorFunc = SDL_GL_GetProcAddress("glGetError");
+ if (!glGetErrorFunc) {
+ return -1;
+ }
+
+ error = glGetErrorFunc();
+ if (error != GL_NO_ERROR) {
+ if (error == GL_INVALID_ENUM) {
+ return SDL_SetError("OpenGL error: GL_INVALID_ENUM");
+ } else if (error == GL_INVALID_VALUE) {
+ return SDL_SetError("OpenGL error: GL_INVALID_VALUE");
+ }
+ return SDL_SetError("OpenGL error: %08X", error);
+ }
+ return 0;
+#else
+ return SDL_Unsupported();
+#endif /* SDL_VIDEO_OPENGL */
+}
+
+SDL_GLContext
+SDL_GL_CreateContext(SDL_Window * window)
+{
+ SDL_GLContext ctx = NULL;
+ CHECK_WINDOW_MAGIC(window, NULL);
+
+ if (!(window->flags & SDL_WINDOW_OPENGL)) {
+ SDL_SetError("The specified window isn't an OpenGL window");
+ return NULL;
+ }
+
+ ctx = _this->GL_CreateContext(_this, window);
+
+ /* Creating a context is assumed to make it current in the SDL driver. */
+ if (ctx) {
+ _this->current_glwin = window;
+ _this->current_glctx = ctx;
+ SDL_TLSSet(_this->current_glwin_tls, window, NULL);
+ SDL_TLSSet(_this->current_glctx_tls, ctx, NULL);
+ }
+ return ctx;
+}
+
+int
+SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext ctx)
+{
+ int retval;
+
+ if (window == SDL_GL_GetCurrentWindow() &&
+ ctx == SDL_GL_GetCurrentContext()) {
+ /* We're already current. */
+ return 0;
+ }
+
+ if (!ctx) {
+ window = NULL;
+ } else {
+ CHECK_WINDOW_MAGIC(window, -1);
+
+ if (!(window->flags & SDL_WINDOW_OPENGL)) {
+ return SDL_SetError("The specified window isn't an OpenGL window");
+ }
+ }
+
+ retval = _this->GL_MakeCurrent(_this, window, ctx);
+ if (retval == 0) {
+ _this->current_glwin = window;
+ _this->current_glctx = ctx;
+ SDL_TLSSet(_this->current_glwin_tls, window, NULL);
+ SDL_TLSSet(_this->current_glctx_tls, ctx, NULL);
+ }
+ return retval;
+}
+
+SDL_Window *
+SDL_GL_GetCurrentWindow(void)
+{
+ if (!_this) {
+ SDL_UninitializedVideo();
+ return NULL;
+ }
+ return (SDL_Window *)SDL_TLSGet(_this->current_glwin_tls);
+}
+
+SDL_GLContext
+SDL_GL_GetCurrentContext(void)
+{
+ if (!_this) {
+ SDL_UninitializedVideo();
+ return NULL;
+ }
+ return (SDL_GLContext)SDL_TLSGet(_this->current_glctx_tls);
+}
+
+void SDL_GL_GetDrawableSize(SDL_Window * window, int *w, int *h)
+{
+ CHECK_WINDOW_MAGIC(window,);
+
+ if (_this->GL_GetDrawableSize) {
+ _this->GL_GetDrawableSize(_this, window, w, h);
+ } else {
+ SDL_GetWindowSize(window, w, h);
+ }
+}
+
+int
+SDL_GL_SetSwapInterval(int interval)
+{
+ if (!_this) {
+ return SDL_UninitializedVideo();
+ } else if (SDL_GL_GetCurrentContext() == NULL) {
+ return SDL_SetError("No OpenGL context has been made current");
+ } else if (_this->GL_SetSwapInterval) {
+ return _this->GL_SetSwapInterval(_this, interval);
+ } else {
+ return SDL_SetError("Setting the swap interval is not supported");
+ }
+}
+
+int
+SDL_GL_GetSwapInterval(void)
+{
+ if (!_this) {
+ return 0;
+ } else if (SDL_GL_GetCurrentContext() == NULL) {
+ return 0;
+ } else if (_this->GL_GetSwapInterval) {
+ return _this->GL_GetSwapInterval(_this);
+ } else {
+ return 0;
+ }
+}
+
+void
+SDL_GL_SwapWindow(SDL_Window * window)
+{
+ CHECK_WINDOW_MAGIC(window,);
+
+ if (!(window->flags & SDL_WINDOW_OPENGL)) {
+ SDL_SetError("The specified window isn't an OpenGL window");
+ return;
+ }
+
+ if (SDL_GL_GetCurrentWindow() != window) {
+ SDL_SetError("The specified window has not been made current");
+ return;
+ }
+
+ _this->GL_SwapWindow(_this, window);
+}
+
+void
+SDL_GL_DeleteContext(SDL_GLContext context)
+{
+ if (!_this || !context) {
+ return;
+ }
+
+ if (SDL_GL_GetCurrentContext() == context) {
+ SDL_GL_MakeCurrent(NULL, NULL);
+ }
+
+ _this->GL_DeleteContext(_this, context);
+}
+
+#if 0 /* FIXME */
+/*
+ * Utility function used by SDL_WM_SetIcon(); flags & 1 for color key, flags
+ * & 2 for alpha channel.
+ */
+static void
+CreateMaskFromColorKeyOrAlpha(SDL_Surface * icon, Uint8 * mask, int flags)
+{
+ int x, y;
+ Uint32 colorkey;
+#define SET_MASKBIT(icon, x, y, mask) \
+ mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8)))
+
+ colorkey = icon->format->colorkey;
+ switch (icon->format->BytesPerPixel) {
+ case 1:
+ {
+ Uint8 *pixels;
+ for (y = 0; y < icon->h; ++y) {
+ pixels = (Uint8 *) icon->pixels + y * icon->pitch;
+ for (x = 0; x < icon->w; ++x) {
+ if (*pixels++ == colorkey) {
+ SET_MASKBIT(icon, x, y, mask);
+ }
+ }
+ }
+ }
+ break;
+
+ case 2:
+ {
+ Uint16 *pixels;
+ for (y = 0; y < icon->h; ++y) {
+ pixels = (Uint16 *) icon->pixels + y * icon->pitch / 2;
+ for (x = 0; x < icon->w; ++x) {
+ if ((flags & 1) && *pixels == colorkey) {
+ SET_MASKBIT(icon, x, y, mask);
+ } else if ((flags & 2)
+ && (*pixels & icon->format->Amask) == 0) {
+ SET_MASKBIT(icon, x, y, mask);
+ }
+ pixels++;
+ }
+ }
+ }
+ break;
+
+ case 4:
+ {
+ Uint32 *pixels;
+ for (y = 0; y < icon->h; ++y) {
+ pixels = (Uint32 *) icon->pixels + y * icon->pitch / 4;
+ for (x = 0; x < icon->w; ++x) {
+ if ((flags & 1) && *pixels == colorkey) {
+ SET_MASKBIT(icon, x, y, mask);
+ } else if ((flags & 2)
+ && (*pixels & icon->format->Amask) == 0) {
+ SET_MASKBIT(icon, x, y, mask);
+ }
+ pixels++;
+ }
+ }
+ }
+ break;
+ }
+}
+
+/*
+ * Sets the window manager icon for the display window.
+ */
+void
+SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask)
+{
+ if (icon && _this->SetIcon) {
+ /* Generate a mask if necessary, and create the icon! */
+ if (mask == NULL) {
+ int mask_len = icon->h * (icon->w + 7) / 8;
+ int flags = 0;
+ mask = (Uint8 *) SDL_malloc(mask_len);
+ if (mask == NULL) {
+ return;
+ }
+ SDL_memset(mask, ~0, mask_len);
+ if (icon->flags & SDL_SRCCOLORKEY)
+ flags |= 1;
+ if (icon->flags & SDL_SRCALPHA)
+ flags |= 2;
+ if (flags) {
+ CreateMaskFromColorKeyOrAlpha(icon, mask, flags);
+ }
+ _this->SetIcon(_this, icon, mask);
+ SDL_free(mask);
+ } else {
+ _this->SetIcon(_this, icon, mask);
+ }
+ }
+}
+#endif
+
+SDL_bool
+SDL_GetWindowWMInfo(SDL_Window * window, struct SDL_SysWMinfo *info)
+{
+ CHECK_WINDOW_MAGIC(window, SDL_FALSE);
+
+ if (!info) {
+ SDL_InvalidParamError("info");
+ return SDL_FALSE;
+ }
+ info->subsystem = SDL_SYSWM_UNKNOWN;
+
+ if (!_this->GetWindowWMInfo) {
+ SDL_Unsupported();
+ return SDL_FALSE;
+ }
+ return (_this->GetWindowWMInfo(_this, window, info));
+}
+
+void
+SDL_StartTextInput(void)
+{
+ SDL_Window *window;
+
+ /* First, enable text events */
+ SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE);
+ SDL_EventState(SDL_TEXTEDITING, SDL_ENABLE);
+
+ /* Then show the on-screen keyboard, if any */
+ window = SDL_GetFocusWindow();
+ if (window && _this && _this->ShowScreenKeyboard) {
+ _this->ShowScreenKeyboard(_this, window);
+ }
+
+ /* Finally start the text input system */
+ if (_this && _this->StartTextInput) {
+ _this->StartTextInput(_this);
+ }
+}
+
+SDL_bool
+SDL_IsTextInputActive(void)
+{
+ return (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE);
+}
+
+void
+SDL_StopTextInput(void)
+{
+ SDL_Window *window;
+
+ /* Stop the text input system */
+ if (_this && _this->StopTextInput) {
+ _this->StopTextInput(_this);
+ }
+
+ /* Hide the on-screen keyboard, if any */
+ window = SDL_GetFocusWindow();
+ if (window && _this && _this->HideScreenKeyboard) {
+ _this->HideScreenKeyboard(_this, window);
+ }
+
+ /* Finally disable text events */
+ SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);
+ SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE);
+}
+
+void
+SDL_SetTextInputRect(SDL_Rect *rect)
+{
+ if (_this && _this->SetTextInputRect) {
+ _this->SetTextInputRect(_this, rect);
+ }
+}
+
+SDL_bool
+SDL_HasScreenKeyboardSupport(void)
+{
+ if (_this && _this->HasScreenKeyboardSupport) {
+ return _this->HasScreenKeyboardSupport(_this);
+ }
+ return SDL_FALSE;
+}
+
+SDL_bool
+SDL_IsScreenKeyboardShown(SDL_Window *window)
+{
+ if (window && _this && _this->IsScreenKeyboardShown) {
+ return _this->IsScreenKeyboardShown(_this, window);
+ }
+ return SDL_FALSE;
+}
+
+#if SDL_VIDEO_DRIVER_ANDROID
+#include "android/SDL_androidmessagebox.h"
+#endif
+#if SDL_VIDEO_DRIVER_WINDOWS
+#include "windows/SDL_windowsmessagebox.h"
+#endif
+#if SDL_VIDEO_DRIVER_WINRT
+#include "winrt/SDL_winrtmessagebox.h"
+#endif
+#if SDL_VIDEO_DRIVER_COCOA
+#include "cocoa/SDL_cocoamessagebox.h"
+#endif
+#if SDL_VIDEO_DRIVER_UIKIT
+#include "uikit/SDL_uikitmessagebox.h"
+#endif
+#if SDL_VIDEO_DRIVER_X11
+#include "x11/SDL_x11messagebox.h"
+#endif
+
+
+#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT || SDL_VIDEO_DRIVER_COCOA || SDL_VIDEO_DRIVER_UIKIT || SDL_VIDEO_DRIVER_X11
+static SDL_bool SDL_MessageboxValidForDriver(const SDL_MessageBoxData *messageboxdata, SDL_SYSWM_TYPE drivertype)
+{
+ SDL_SysWMinfo info;
+ SDL_Window *window = messageboxdata->window;
+
+ if (!window) {
+ return SDL_TRUE;
+ }
+
+ SDL_VERSION(&info.version);
+ if (!SDL_GetWindowWMInfo(window, &info)) {
+ return SDL_TRUE;
+ } else {
+ return (info.subsystem == drivertype);
+ }
+}
+#endif
+
+int
+SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
+{
+ int dummybutton;
+ int retval = -1;
+ SDL_bool relative_mode;
+ int show_cursor_prev;
+ SDL_bool mouse_captured;
+ SDL_Window *current_window;
+
+ if (!messageboxdata) {
+ return SDL_InvalidParamError("messageboxdata");
+ }
+
+ current_window = SDL_GetKeyboardFocus();
+ mouse_captured = current_window && ((SDL_GetWindowFlags(current_window) & SDL_WINDOW_MOUSE_CAPTURE) != 0);
+ relative_mode = SDL_GetRelativeMouseMode();
+ SDL_CaptureMouse(SDL_FALSE);
+ SDL_SetRelativeMouseMode(SDL_FALSE);
+ show_cursor_prev = SDL_ShowCursor(1);
+ SDL_ResetKeyboard();
+
+ if (!buttonid) {
+ buttonid = &dummybutton;
+ }
+
+ if (_this && _this->ShowMessageBox) {
+ retval = _this->ShowMessageBox(_this, messageboxdata, buttonid);
+ }
+
+ /* It's completely fine to call this function before video is initialized */
+#if SDL_VIDEO_DRIVER_ANDROID
+ if (retval == -1 &&
+ Android_ShowMessageBox(messageboxdata, buttonid) == 0) {
+ retval = 0;
+ }
+#endif
+#if SDL_VIDEO_DRIVER_WINDOWS
+ if (retval == -1 &&
+ SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_WINDOWS) &&
+ WIN_ShowMessageBox(messageboxdata, buttonid) == 0) {
+ retval = 0;
+ }
+#endif
+#if SDL_VIDEO_DRIVER_WINRT
+ if (retval == -1 &&
+ SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_WINRT) &&
+ WINRT_ShowMessageBox(messageboxdata, buttonid) == 0) {
+ retval = 0;
+ }
+#endif
+#if SDL_VIDEO_DRIVER_COCOA
+ if (retval == -1 &&
+ SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_COCOA) &&
+ Cocoa_ShowMessageBox(messageboxdata, buttonid) == 0) {
+ retval = 0;
+ }
+#endif
+#if SDL_VIDEO_DRIVER_UIKIT
+ if (retval == -1 &&
+ SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_UIKIT) &&
+ UIKit_ShowMessageBox(messageboxdata, buttonid) == 0) {
+ retval = 0;
+ }
+#endif
+#if SDL_VIDEO_DRIVER_X11
+ if (retval == -1 &&
+ SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_X11) &&
+ X11_ShowMessageBox(messageboxdata, buttonid) == 0) {
+ retval = 0;
+ }
+#endif
+ if (retval == -1) {
+ SDL_SetError("No message system available");
+ }
+
+ if (current_window) {
+ SDL_RaiseWindow(current_window);
+ if (mouse_captured) {
+ SDL_CaptureMouse(SDL_TRUE);
+ }
+ }
+
+ SDL_ShowCursor(show_cursor_prev);
+ SDL_SetRelativeMouseMode(relative_mode);
+
+ return retval;
+}
+
+int
+SDL_ShowSimpleMessageBox(Uint32 flags, const char *title, const char *message, SDL_Window *window)
+{
+#ifdef __EMSCRIPTEN__
+ /* !!! FIXME: propose a browser API for this, get this #ifdef out of here? */
+ /* Web browsers don't (currently) have an API for a custom message box
+ that can block, but for the most common case (SDL_ShowSimpleMessageBox),
+ we can use the standard Javascript alert() function. */
+ EM_ASM_({
+ alert(UTF8ToString($0) + "\n\n" + UTF8ToString($1));
+ }, title, message);
+ return 0;
+#else
+ SDL_MessageBoxData data;
+ SDL_MessageBoxButtonData button;
+
+ SDL_zero(data);
+ data.flags = flags;
+ data.title = title;
+ data.message = message;
+ data.numbuttons = 1;
+ data.buttons = &button;
+ data.window = window;
+
+ SDL_zero(button);
+ button.flags |= SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
+ button.flags |= SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
+ button.text = "OK";
+
+ return SDL_ShowMessageBox(&data, NULL);
+#endif
+}
+
+SDL_bool
+SDL_ShouldAllowTopmost(void)
+{
+ return SDL_GetHintBoolean(SDL_HINT_ALLOW_TOPMOST, SDL_TRUE);
+}
+
+int
+SDL_SetWindowHitTest(SDL_Window * window, SDL_HitTest callback, void *userdata)
+{
+ CHECK_WINDOW_MAGIC(window, -1);
+
+ if (!_this->SetWindowHitTest) {
+ return SDL_Unsupported();
+ } else if (_this->SetWindowHitTest(window, callback != NULL) == -1) {
+ return -1;
+ }
+
+ window->hit_test = callback;
+ window->hit_test_data = userdata;
+
+ return 0;
+}
+
+float
+SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches)
+{
+ float den2 = hinches * hinches + vinches * vinches;
+ if (den2 <= 0.0f) {
+ return 0.0f;
+ }
+
+ return (float)(SDL_sqrt((double)hpix * (double)hpix + (double)vpix * (double)vpix) /
+ SDL_sqrt((double)den2));
+}
+
+/*
+ * Functions used by iOS application delegates
+ */
+void SDL_OnApplicationWillTerminate(void)
+{
+ SDL_SendAppEvent(SDL_APP_TERMINATING);
+}
+
+void SDL_OnApplicationDidReceiveMemoryWarning(void)
+{
+ SDL_SendAppEvent(SDL_APP_LOWMEMORY);
+}
+
+void SDL_OnApplicationWillResignActive(void)
+{
+ if (_this) {
+ SDL_Window *window;
+ for (window = _this->windows; window != NULL; window = window->next) {
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
+ }
+ }
+ SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
+}
+
+void SDL_OnApplicationDidEnterBackground(void)
+{
+ SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
+}
+
+void SDL_OnApplicationWillEnterForeground(void)
+{
+ SDL_SendAppEvent(SDL_APP_WILLENTERFOREGROUND);
+}
+
+void SDL_OnApplicationDidBecomeActive(void)
+{
+ SDL_SendAppEvent(SDL_APP_DIDENTERFOREGROUND);
+
+ if (_this) {
+ SDL_Window *window;
+ for (window = _this->windows; window != NULL; window = window->next) {
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
+ }
+ }
+}
+
+#define NOT_A_VULKAN_WINDOW "The specified window isn't a Vulkan window"
+
+int SDL_Vulkan_LoadLibrary(const char *path)
+{
+ int retval;
+ if (!_this) {
+ SDL_UninitializedVideo();
+ return -1;
+ }
+ if (_this->vulkan_config.loader_loaded) {
+ if (path && SDL_strcmp(path, _this->vulkan_config.loader_path) != 0) {
+ return SDL_SetError("Vulkan loader library already loaded");
+ }
+ retval = 0;
+ } else {
+ if (!_this->Vulkan_LoadLibrary) {
+ return SDL_SetError("No Vulkan support in video driver");
+ }
+ retval = _this->Vulkan_LoadLibrary(_this, path);
+ }
+ if (retval == 0) {
+ _this->vulkan_config.loader_loaded++;
+ }
+ return retval;
+}
+
+void *SDL_Vulkan_GetVkGetInstanceProcAddr(void)
+{
+ if (!_this) {
+ SDL_UninitializedVideo();
+ return NULL;
+ }
+ if (!_this->vulkan_config.loader_loaded) {
+ SDL_SetError("No Vulkan loader has been loaded");
+ return NULL;
+ }
+ return _this->vulkan_config.vkGetInstanceProcAddr;
+}
+
+void SDL_Vulkan_UnloadLibrary(void)
+{
+ if (!_this) {
+ SDL_UninitializedVideo();
+ return;
+ }
+ if (_this->vulkan_config.loader_loaded > 0) {
+ if (--_this->vulkan_config.loader_loaded > 0) {
+ return;
+ }
+ if (_this->Vulkan_UnloadLibrary) {
+ _this->Vulkan_UnloadLibrary(_this);
+ }
+ }
+}
+
+SDL_bool SDL_Vulkan_GetInstanceExtensions(SDL_Window *window, unsigned *count, const char **names)
+{
+ CHECK_WINDOW_MAGIC(window, SDL_FALSE);
+
+ if (!(window->flags & SDL_WINDOW_VULKAN)) {
+ SDL_SetError(NOT_A_VULKAN_WINDOW);
+ return SDL_FALSE;
+ }
+
+ if (!count) {
+ SDL_InvalidParamError("count");
+ return SDL_FALSE;
+ }
+
+ return _this->Vulkan_GetInstanceExtensions(_this, window, count, names);
+}
+
+SDL_bool SDL_Vulkan_CreateSurface(SDL_Window *window,
+ VkInstance instance,
+ VkSurfaceKHR *surface)
+{
+ CHECK_WINDOW_MAGIC(window, SDL_FALSE);
+
+ if (!(window->flags & SDL_WINDOW_VULKAN)) {
+ SDL_SetError(NOT_A_VULKAN_WINDOW);
+ return SDL_FALSE;
+ }
+
+ if (!instance) {
+ SDL_InvalidParamError("instance");
+ return SDL_FALSE;
+ }
+
+ if (!surface) {
+ SDL_InvalidParamError("surface");
+ return SDL_FALSE;
+ }
+
+ return _this->Vulkan_CreateSurface(_this, window, instance, surface);
+}
+
+void SDL_Vulkan_GetDrawableSize(SDL_Window * window, int *w, int *h)
+{
+ CHECK_WINDOW_MAGIC(window,);
+
+ if (_this->Vulkan_GetDrawableSize) {
+ _this->Vulkan_GetDrawableSize(_this, window, w, h);
+ } else {
+ SDL_GetWindowSize(window, w, h);
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_vulkan_internal.h b/src/3rdparty/SDL2/src/video/SDL_vulkan_internal.h
new file mode 100644
index 0000000..cdf464e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_vulkan_internal.h
@@ -0,0 +1,91 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#ifndef SDL_vulkan_internal_h_
+#define SDL_vulkan_internal_h_
+
+#include "../SDL_internal.h"
+
+#include "SDL_stdinc.h"
+
+#if defined(SDL_LOADSO_DISABLED)
+#undef SDL_VIDEO_VULKAN
+#define SDL_VIDEO_VULKAN 0
+#endif
+
+#if SDL_VIDEO_VULKAN
+
+#if SDL_VIDEO_DRIVER_ANDROID
+#define VK_USE_PLATFORM_ANDROID_KHR
+#endif
+#if SDL_VIDEO_DRIVER_COCOA
+#define VK_USE_PLATFORM_MACOS_MVK
+#endif
+#if SDL_VIDEO_DRIVER_MIR
+#define VK_USE_PLATFORM_MIR_KHR
+#endif
+#if SDL_VIDEO_DRIVER_UIKIT
+#define VK_USE_PLATFORM_IOS_MVK
+#endif
+#if SDL_VIDEO_DRIVER_WAYLAND
+#define VK_USE_PLATFORM_WAYLAND_KHR
+#include "wayland/SDL_waylanddyn.h"
+#endif
+#if SDL_VIDEO_DRIVER_WINDOWS
+#define VK_USE_PLATFORM_WIN32_KHR
+#include "../core/windows/SDL_windows.h"
+#endif
+#if SDL_VIDEO_DRIVER_X11
+#define VK_USE_PLATFORM_XLIB_KHR
+#define VK_USE_PLATFORM_XCB_KHR
+#endif
+
+#define VK_NO_PROTOTYPES
+#include "./khronos/vulkan/vulkan.h"
+
+#include "SDL_vulkan.h"
+
+
+extern const char *SDL_Vulkan_GetResultString(VkResult result);
+
+extern VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList(
+ PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties,
+ Uint32 *extensionCount); /* free returned list with SDL_free */
+
+/* Implements functionality of SDL_Vulkan_GetInstanceExtensions for a list of
+ * names passed in nameCount and names. */
+extern SDL_bool SDL_Vulkan_GetInstanceExtensions_Helper(unsigned *userCount,
+ const char **userNames,
+ unsigned nameCount,
+ const char *const *names);
+
+#else
+
+/* No SDL Vulkan support, just include the header for typedefs */
+#include "SDL_vulkan.h"
+
+typedef void (*PFN_vkGetInstanceProcAddr) (void);
+typedef int (*PFN_vkEnumerateInstanceExtensionProperties) (void);
+
+#endif /* SDL_VIDEO_VULKAN */
+
+#endif /* SDL_vulkan_internal_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_vulkan_utils.c b/src/3rdparty/SDL2/src/video/SDL_vulkan_utils.c
new file mode 100644
index 0000000..d4cbed4
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_vulkan_utils.c
@@ -0,0 +1,172 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "SDL_vulkan_internal.h"
+#include "SDL_error.h"
+
+#if SDL_VIDEO_VULKAN
+
+const char *SDL_Vulkan_GetResultString(VkResult result)
+{
+ switch((int)result)
+ {
+ case VK_SUCCESS:
+ return "VK_SUCCESS";
+ case VK_NOT_READY:
+ return "VK_NOT_READY";
+ case VK_TIMEOUT:
+ return "VK_TIMEOUT";
+ case VK_EVENT_SET:
+ return "VK_EVENT_SET";
+ case VK_EVENT_RESET:
+ return "VK_EVENT_RESET";
+ case VK_INCOMPLETE:
+ return "VK_INCOMPLETE";
+ case VK_ERROR_OUT_OF_HOST_MEMORY:
+ return "VK_ERROR_OUT_OF_HOST_MEMORY";
+ case VK_ERROR_OUT_OF_DEVICE_MEMORY:
+ return "VK_ERROR_OUT_OF_DEVICE_MEMORY";
+ case VK_ERROR_INITIALIZATION_FAILED:
+ return "VK_ERROR_INITIALIZATION_FAILED";
+ case VK_ERROR_DEVICE_LOST:
+ return "VK_ERROR_DEVICE_LOST";
+ case VK_ERROR_MEMORY_MAP_FAILED:
+ return "VK_ERROR_MEMORY_MAP_FAILED";
+ case VK_ERROR_LAYER_NOT_PRESENT:
+ return "VK_ERROR_LAYER_NOT_PRESENT";
+ case VK_ERROR_EXTENSION_NOT_PRESENT:
+ return "VK_ERROR_EXTENSION_NOT_PRESENT";
+ case VK_ERROR_FEATURE_NOT_PRESENT:
+ return "VK_ERROR_FEATURE_NOT_PRESENT";
+ case VK_ERROR_INCOMPATIBLE_DRIVER:
+ return "VK_ERROR_INCOMPATIBLE_DRIVER";
+ case VK_ERROR_TOO_MANY_OBJECTS:
+ return "VK_ERROR_TOO_MANY_OBJECTS";
+ case VK_ERROR_FORMAT_NOT_SUPPORTED:
+ return "VK_ERROR_FORMAT_NOT_SUPPORTED";
+ case VK_ERROR_FRAGMENTED_POOL:
+ return "VK_ERROR_FRAGMENTED_POOL";
+ case VK_ERROR_SURFACE_LOST_KHR:
+ return "VK_ERROR_SURFACE_LOST_KHR";
+ case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR:
+ return "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR";
+ case VK_SUBOPTIMAL_KHR:
+ return "VK_SUBOPTIMAL_KHR";
+ case VK_ERROR_OUT_OF_DATE_KHR:
+ return "VK_ERROR_OUT_OF_DATE_KHR";
+ case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR:
+ return "VK_ERROR_INCOMPATIBLE_DISPLAY_KHR";
+ case VK_ERROR_VALIDATION_FAILED_EXT:
+ return "VK_ERROR_VALIDATION_FAILED_EXT";
+ case VK_ERROR_OUT_OF_POOL_MEMORY_KHR:
+ return "VK_ERROR_OUT_OF_POOL_MEMORY_KHR";
+ case VK_ERROR_INVALID_SHADER_NV:
+ return "VK_ERROR_INVALID_SHADER_NV";
+ case VK_RESULT_MAX_ENUM:
+ case VK_RESULT_RANGE_SIZE:
+ break;
+ }
+ if(result < 0)
+ return "VK_ERROR_<Unknown>";
+ return "VK_<Unknown>";
+}
+
+VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList(
+ PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties,
+ Uint32 *extensionCount)
+{
+ Uint32 count = 0;
+ VkResult result = vkEnumerateInstanceExtensionProperties(NULL, &count, NULL);
+ VkExtensionProperties *retval;
+ if(result == VK_ERROR_INCOMPATIBLE_DRIVER)
+ {
+ /* Avoid the ERR_MAX_STRLEN limit by passing part of the message
+ * as a string argument.
+ */
+ SDL_SetError(
+ "You probably don't have a working Vulkan driver installed. %s %s %s(%d)",
+ "Getting Vulkan extensions failed:",
+ "vkEnumerateInstanceExtensionProperties returned",
+ SDL_Vulkan_GetResultString(result),
+ (int)result);
+ return NULL;
+ }
+ else if(result != VK_SUCCESS)
+ {
+ SDL_SetError(
+ "Getting Vulkan extensions failed: vkEnumerateInstanceExtensionProperties returned "
+ "%s(%d)",
+ SDL_Vulkan_GetResultString(result),
+ (int)result);
+ return NULL;
+ }
+ if(count == 0)
+ {
+ retval = SDL_calloc(1, sizeof(VkExtensionProperties)); // so we can return non-null
+ }
+ else
+ {
+ retval = SDL_calloc(count, sizeof(VkExtensionProperties));
+ }
+ if(!retval)
+ {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ result = vkEnumerateInstanceExtensionProperties(NULL, &count, retval);
+ if(result != VK_SUCCESS)
+ {
+ SDL_SetError(
+ "Getting Vulkan extensions failed: vkEnumerateInstanceExtensionProperties returned "
+ "%s(%d)",
+ SDL_Vulkan_GetResultString(result),
+ (int)result);
+ SDL_free(retval);
+ return NULL;
+ }
+ *extensionCount = count;
+ return retval;
+}
+
+SDL_bool SDL_Vulkan_GetInstanceExtensions_Helper(unsigned *userCount,
+ const char **userNames,
+ unsigned nameCount,
+ const char *const *names)
+{
+ if (userNames) {
+ unsigned i;
+
+ if (*userCount < nameCount) {
+ SDL_SetError("Output array for SDL_Vulkan_GetInstanceExtensions needs to be at least %d big", nameCount);
+ return SDL_FALSE;
+ }
+ for (i = 0; i < nameCount; i++) {
+ userNames[i] = names[i];
+ }
+ }
+ *userCount = nameCount;
+ return SDL_TRUE;
+}
+
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_yuv.c b/src/3rdparty/SDL2/src/video/SDL_yuv.c
new file mode 100644
index 0000000..50910a5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_yuv.c
@@ -0,0 +1,1834 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+#include "SDL_endian.h"
+#include "SDL_video.h"
+#include "SDL_pixels_c.h"
+
+#include "yuv2rgb/yuv_rgb.h"
+
+#define SDL_YUV_SD_THRESHOLD 576
+
+
+static SDL_YUV_CONVERSION_MODE SDL_YUV_ConversionMode = SDL_YUV_CONVERSION_BT601;
+
+
+void SDL_SetYUVConversionMode(SDL_YUV_CONVERSION_MODE mode)
+{
+ SDL_YUV_ConversionMode = mode;
+}
+
+SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionMode()
+{
+ return SDL_YUV_ConversionMode;
+}
+
+SDL_YUV_CONVERSION_MODE SDL_GetYUVConversionModeForResolution(int width, int height)
+{
+ SDL_YUV_CONVERSION_MODE mode = SDL_GetYUVConversionMode();
+ if (mode == SDL_YUV_CONVERSION_AUTOMATIC) {
+ if (height <= SDL_YUV_SD_THRESHOLD) {
+ mode = SDL_YUV_CONVERSION_BT601;
+ } else {
+ mode = SDL_YUV_CONVERSION_BT709;
+ }
+ }
+ return mode;
+}
+
+static int GetYUVConversionType(int width, int height, YCbCrType *yuv_type)
+{
+ switch (SDL_GetYUVConversionModeForResolution(width, height)) {
+ case SDL_YUV_CONVERSION_JPEG:
+ *yuv_type = YCBCR_JPEG;
+ break;
+ case SDL_YUV_CONVERSION_BT601:
+ *yuv_type = YCBCR_601;
+ break;
+ case SDL_YUV_CONVERSION_BT709:
+ *yuv_type = YCBCR_709;
+ break;
+ default:
+ return SDL_SetError("Unexpected YUV conversion mode");
+ }
+ return 0;
+}
+
+static SDL_bool IsPlanar2x2Format(Uint32 format)
+{
+ return (format == SDL_PIXELFORMAT_YV12 ||
+ format == SDL_PIXELFORMAT_IYUV ||
+ format == SDL_PIXELFORMAT_NV12 ||
+ format == SDL_PIXELFORMAT_NV21);
+}
+
+static SDL_bool IsPacked4Format(Uint32 format)
+{
+ return (format == SDL_PIXELFORMAT_YUY2 ||
+ format == SDL_PIXELFORMAT_UYVY ||
+ format == SDL_PIXELFORMAT_YVYU);
+}
+
+static int GetYUVPlanes(int width, int height, Uint32 format, const void *yuv, int yuv_pitch,
+ const Uint8 **y, const Uint8 **u, const Uint8 **v, Uint32 *y_stride, Uint32 *uv_stride)
+{
+ const Uint8 *planes[3] = { NULL, NULL, NULL };
+ int pitches[3] = { 0, 0, 0 };
+
+ switch (format) {
+ case SDL_PIXELFORMAT_YV12:
+ case SDL_PIXELFORMAT_IYUV:
+ pitches[0] = yuv_pitch;
+ pitches[1] = (pitches[0] + 1) / 2;
+ pitches[2] = (pitches[0] + 1) / 2;
+ planes[0] = (const Uint8 *)yuv;
+ planes[1] = planes[0] + pitches[0] * height;
+ planes[2] = planes[1] + pitches[1] * ((height + 1) / 2);
+ break;
+ case SDL_PIXELFORMAT_YUY2:
+ case SDL_PIXELFORMAT_UYVY:
+ case SDL_PIXELFORMAT_YVYU:
+ pitches[0] = yuv_pitch;
+ planes[0] = (const Uint8 *)yuv;
+ break;
+ case SDL_PIXELFORMAT_NV12:
+ case SDL_PIXELFORMAT_NV21:
+ pitches[0] = yuv_pitch;
+ pitches[1] = 2 * ((pitches[0] + 1) / 2);
+ planes[0] = (const Uint8 *)yuv;
+ planes[1] = planes[0] + pitches[0] * height;
+ break;
+ default:
+ return SDL_SetError("GetYUVPlanes(): Unsupported YUV format: %s", SDL_GetPixelFormatName(format));
+ }
+
+ switch (format) {
+ case SDL_PIXELFORMAT_YV12:
+ *y = planes[0];
+ *y_stride = pitches[0];
+ *v = planes[1];
+ *u = planes[2];
+ *uv_stride = pitches[1];
+ break;
+ case SDL_PIXELFORMAT_IYUV:
+ *y = planes[0];
+ *y_stride = pitches[0];
+ *v = planes[2];
+ *u = planes[1];
+ *uv_stride = pitches[1];
+ break;
+ case SDL_PIXELFORMAT_YUY2:
+ *y = planes[0];
+ *y_stride = pitches[0];
+ *v = *y + 3;
+ *u = *y + 1;
+ *uv_stride = pitches[0];
+ break;
+ case SDL_PIXELFORMAT_UYVY:
+ *y = planes[0] + 1;
+ *y_stride = pitches[0];
+ *v = *y + 1;
+ *u = *y - 1;
+ *uv_stride = pitches[0];
+ break;
+ case SDL_PIXELFORMAT_YVYU:
+ *y = planes[0];
+ *y_stride = pitches[0];
+ *v = *y + 1;
+ *u = *y + 3;
+ *uv_stride = pitches[0];
+ break;
+ case SDL_PIXELFORMAT_NV12:
+ *y = planes[0];
+ *y_stride = pitches[0];
+ *u = planes[1];
+ *v = *u + 1;
+ *uv_stride = pitches[1];
+ break;
+ case SDL_PIXELFORMAT_NV21:
+ *y = planes[0];
+ *y_stride = pitches[0];
+ *v = planes[1];
+ *u = *v + 1;
+ *uv_stride = pitches[1];
+ break;
+ default:
+ /* Should have caught this above */
+ return SDL_SetError("GetYUVPlanes[2]: Unsupported YUV format: %s", SDL_GetPixelFormatName(format));
+ }
+ return 0;
+}
+
+static SDL_bool yuv_rgb_sse(
+ Uint32 src_format, Uint32 dst_format,
+ Uint32 width, Uint32 height,
+ const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride,
+ Uint8 *rgb, Uint32 rgb_stride,
+ YCbCrType yuv_type)
+{
+#ifdef __SSE2__
+ if (!SDL_HasSSE2()) {
+ return SDL_FALSE;
+ }
+
+ if (src_format == SDL_PIXELFORMAT_YV12 ||
+ src_format == SDL_PIXELFORMAT_IYUV) {
+
+ switch (dst_format) {
+ case SDL_PIXELFORMAT_RGB565:
+ yuv420_rgb565_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_RGB24:
+ yuv420_rgb24_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_RGBX8888:
+ case SDL_PIXELFORMAT_RGBA8888:
+ yuv420_rgba_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_BGRX8888:
+ case SDL_PIXELFORMAT_BGRA8888:
+ yuv420_bgra_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_RGB888:
+ case SDL_PIXELFORMAT_ARGB8888:
+ yuv420_argb_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_BGR888:
+ case SDL_PIXELFORMAT_ABGR8888:
+ yuv420_abgr_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ default:
+ break;
+ }
+ }
+
+ if (src_format == SDL_PIXELFORMAT_YUY2 ||
+ src_format == SDL_PIXELFORMAT_UYVY ||
+ src_format == SDL_PIXELFORMAT_YVYU) {
+
+ switch (dst_format) {
+ case SDL_PIXELFORMAT_RGB565:
+ yuv422_rgb565_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_RGB24:
+ yuv422_rgb24_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_RGBX8888:
+ case SDL_PIXELFORMAT_RGBA8888:
+ yuv422_rgba_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_BGRX8888:
+ case SDL_PIXELFORMAT_BGRA8888:
+ yuv422_bgra_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_RGB888:
+ case SDL_PIXELFORMAT_ARGB8888:
+ yuv422_argb_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_BGR888:
+ case SDL_PIXELFORMAT_ABGR8888:
+ yuv422_abgr_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ default:
+ break;
+ }
+ }
+
+ if (src_format == SDL_PIXELFORMAT_NV12 ||
+ src_format == SDL_PIXELFORMAT_NV21) {
+
+ switch (dst_format) {
+ case SDL_PIXELFORMAT_RGB565:
+ yuvnv12_rgb565_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_RGB24:
+ yuvnv12_rgb24_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_RGBX8888:
+ case SDL_PIXELFORMAT_RGBA8888:
+ yuvnv12_rgba_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_BGRX8888:
+ case SDL_PIXELFORMAT_BGRA8888:
+ yuvnv12_bgra_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_RGB888:
+ case SDL_PIXELFORMAT_ARGB8888:
+ yuvnv12_argb_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_BGR888:
+ case SDL_PIXELFORMAT_ABGR8888:
+ yuvnv12_abgr_sseu(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ default:
+ break;
+ }
+ }
+#endif
+ return SDL_FALSE;
+}
+
+static SDL_bool yuv_rgb_std(
+ Uint32 src_format, Uint32 dst_format,
+ Uint32 width, Uint32 height,
+ const Uint8 *y, const Uint8 *u, const Uint8 *v, Uint32 y_stride, Uint32 uv_stride,
+ Uint8 *rgb, Uint32 rgb_stride,
+ YCbCrType yuv_type)
+{
+ if (src_format == SDL_PIXELFORMAT_YV12 ||
+ src_format == SDL_PIXELFORMAT_IYUV) {
+
+ switch (dst_format) {
+ case SDL_PIXELFORMAT_RGB565:
+ yuv420_rgb565_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_RGB24:
+ yuv420_rgb24_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_RGBX8888:
+ case SDL_PIXELFORMAT_RGBA8888:
+ yuv420_rgba_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_BGRX8888:
+ case SDL_PIXELFORMAT_BGRA8888:
+ yuv420_bgra_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_RGB888:
+ case SDL_PIXELFORMAT_ARGB8888:
+ yuv420_argb_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_BGR888:
+ case SDL_PIXELFORMAT_ABGR8888:
+ yuv420_abgr_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ default:
+ break;
+ }
+ }
+
+ if (src_format == SDL_PIXELFORMAT_YUY2 ||
+ src_format == SDL_PIXELFORMAT_UYVY ||
+ src_format == SDL_PIXELFORMAT_YVYU) {
+
+ switch (dst_format) {
+ case SDL_PIXELFORMAT_RGB565:
+ yuv422_rgb565_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_RGB24:
+ yuv422_rgb24_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_RGBX8888:
+ case SDL_PIXELFORMAT_RGBA8888:
+ yuv422_rgba_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_BGRX8888:
+ case SDL_PIXELFORMAT_BGRA8888:
+ yuv422_bgra_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_RGB888:
+ case SDL_PIXELFORMAT_ARGB8888:
+ yuv422_argb_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_BGR888:
+ case SDL_PIXELFORMAT_ABGR8888:
+ yuv422_abgr_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ default:
+ break;
+ }
+ }
+
+ if (src_format == SDL_PIXELFORMAT_NV12 ||
+ src_format == SDL_PIXELFORMAT_NV21) {
+
+ switch (dst_format) {
+ case SDL_PIXELFORMAT_RGB565:
+ yuvnv12_rgb565_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_RGB24:
+ yuvnv12_rgb24_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_RGBX8888:
+ case SDL_PIXELFORMAT_RGBA8888:
+ yuvnv12_rgba_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_BGRX8888:
+ case SDL_PIXELFORMAT_BGRA8888:
+ yuvnv12_bgra_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_RGB888:
+ case SDL_PIXELFORMAT_ARGB8888:
+ yuvnv12_argb_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ case SDL_PIXELFORMAT_BGR888:
+ case SDL_PIXELFORMAT_ABGR8888:
+ yuvnv12_abgr_std(width, height, y, u, v, y_stride, uv_stride, rgb, rgb_stride, yuv_type);
+ return SDL_TRUE;
+ default:
+ break;
+ }
+ }
+ return SDL_FALSE;
+}
+
+int
+SDL_ConvertPixels_YUV_to_RGB(int width, int height,
+ Uint32 src_format, const void *src, int src_pitch,
+ Uint32 dst_format, void *dst, int dst_pitch)
+{
+ const Uint8 *y = NULL;
+ const Uint8 *u = NULL;
+ const Uint8 *v = NULL;
+ Uint32 y_stride = 0;
+ Uint32 uv_stride = 0;
+ YCbCrType yuv_type = YCBCR_601;
+
+ if (GetYUVPlanes(width, height, src_format, src, src_pitch, &y, &u, &v, &y_stride, &uv_stride) < 0) {
+ return -1;
+ }
+
+ if (GetYUVConversionType(width, height, &yuv_type) < 0) {
+ return -1;
+ }
+
+ if (yuv_rgb_sse(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8*)dst, dst_pitch, yuv_type)) {
+ return 0;
+ }
+
+ if (yuv_rgb_std(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8*)dst, dst_pitch, yuv_type)) {
+ return 0;
+ }
+
+ /* No fast path for the RGB format, instead convert using an intermediate buffer */
+ if (dst_format != SDL_PIXELFORMAT_ARGB8888) {
+ int ret;
+ void *tmp;
+ int tmp_pitch = (width * sizeof(Uint32));
+
+ tmp = SDL_malloc(tmp_pitch * height);
+ if (tmp == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ /* convert src/src_format to tmp/ARGB8888 */
+ ret = SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, tmp, tmp_pitch);
+ if (ret < 0) {
+ SDL_free(tmp);
+ return ret;
+ }
+
+ /* convert tmp/ARGB8888 to dst/RGB */
+ ret = SDL_ConvertPixels(width, height, SDL_PIXELFORMAT_ARGB8888, tmp, tmp_pitch, dst_format, dst, dst_pitch);
+ SDL_free(tmp);
+ return ret;
+ }
+
+ return SDL_SetError("Unsupported YUV conversion");
+}
+
+struct RGB2YUVFactors
+{
+ int y_offset;
+ float y[3]; /* Rfactor, Gfactor, Bfactor */
+ float u[3]; /* Rfactor, Gfactor, Bfactor */
+ float v[3]; /* Rfactor, Gfactor, Bfactor */
+};
+
+static int
+SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch)
+{
+ const int src_pitch_x_2 = src_pitch * 2;
+ const int height_half = height / 2;
+ const int height_remainder = (height & 0x1);
+ const int width_half = width / 2;
+ const int width_remainder = (width & 0x1);
+ int i, j;
+
+ static struct RGB2YUVFactors RGB2YUVFactorTables[SDL_YUV_CONVERSION_BT709 + 1] =
+ {
+ /* ITU-T T.871 (JPEG) */
+ {
+ 0,
+ { 0.2990f, 0.5870f, 0.1140f },
+ { -0.1687f, -0.3313f, 0.5000f },
+ { 0.5000f, -0.4187f, -0.0813f },
+ },
+ /* ITU-R BT.601-7 */
+ {
+ 16,
+ { 0.2568f, 0.5041f, 0.0979f },
+ { -0.1482f, -0.2910f, 0.4392f },
+ { 0.4392f, -0.3678f, -0.0714f },
+ },
+ /* ITU-R BT.709-6 */
+ {
+ 16,
+ { 0.1826f, 0.6142f, 0.0620f },
+ {-0.1006f, -0.3386f, 0.4392f },
+ { 0.4392f, -0.3989f, -0.0403f },
+ },
+ };
+ const struct RGB2YUVFactors *cvt = &RGB2YUVFactorTables[SDL_GetYUVConversionModeForResolution(width, height)];
+
+#define MAKE_Y(r, g, b) (Uint8)((int)(cvt->y[0] * (r) + cvt->y[1] * (g) + cvt->y[2] * (b) + 0.5f) + cvt->y_offset)
+#define MAKE_U(r, g, b) (Uint8)((int)(cvt->u[0] * (r) + cvt->u[1] * (g) + cvt->u[2] * (b) + 0.5f) + 128)
+#define MAKE_V(r, g, b) (Uint8)((int)(cvt->v[0] * (r) + cvt->v[1] * (g) + cvt->v[2] * (b) + 0.5f) + 128)
+
+#define READ_2x2_PIXELS \
+ const Uint32 p1 = ((const Uint32 *)curr_row)[2 * i]; \
+ const Uint32 p2 = ((const Uint32 *)curr_row)[2 * i + 1]; \
+ const Uint32 p3 = ((const Uint32 *)next_row)[2 * i]; \
+ const Uint32 p4 = ((const Uint32 *)next_row)[2 * i + 1]; \
+ const Uint32 r = ((p1 & 0x00ff0000) + (p2 & 0x00ff0000) + (p3 & 0x00ff0000) + (p4 & 0x00ff0000)) >> 18; \
+ const Uint32 g = ((p1 & 0x0000ff00) + (p2 & 0x0000ff00) + (p3 & 0x0000ff00) + (p4 & 0x0000ff00)) >> 10; \
+ const Uint32 b = ((p1 & 0x000000ff) + (p2 & 0x000000ff) + (p3 & 0x000000ff) + (p4 & 0x000000ff)) >> 2; \
+
+#define READ_2x1_PIXELS \
+ const Uint32 p1 = ((const Uint32 *)curr_row)[2 * i]; \
+ const Uint32 p2 = ((const Uint32 *)next_row)[2 * i]; \
+ const Uint32 r = ((p1 & 0x00ff0000) + (p2 & 0x00ff0000)) >> 17; \
+ const Uint32 g = ((p1 & 0x0000ff00) + (p2 & 0x0000ff00)) >> 9; \
+ const Uint32 b = ((p1 & 0x000000ff) + (p2 & 0x000000ff)) >> 1; \
+
+#define READ_1x2_PIXELS \
+ const Uint32 p1 = ((const Uint32 *)curr_row)[2 * i]; \
+ const Uint32 p2 = ((const Uint32 *)curr_row)[2 * i + 1]; \
+ const Uint32 r = ((p1 & 0x00ff0000) + (p2 & 0x00ff0000)) >> 17; \
+ const Uint32 g = ((p1 & 0x0000ff00) + (p2 & 0x0000ff00)) >> 9; \
+ const Uint32 b = ((p1 & 0x000000ff) + (p2 & 0x000000ff)) >> 1; \
+
+#define READ_1x1_PIXEL \
+ const Uint32 p = ((const Uint32 *)curr_row)[2 * i]; \
+ const Uint32 r = (p & 0x00ff0000) >> 16; \
+ const Uint32 g = (p & 0x0000ff00) >> 8; \
+ const Uint32 b = (p & 0x000000ff); \
+
+#define READ_TWO_RGB_PIXELS \
+ const Uint32 p = ((const Uint32 *)curr_row)[2 * i]; \
+ const Uint32 r = (p & 0x00ff0000) >> 16; \
+ const Uint32 g = (p & 0x0000ff00) >> 8; \
+ const Uint32 b = (p & 0x000000ff); \
+ const Uint32 p1 = ((const Uint32 *)curr_row)[2 * i + 1]; \
+ const Uint32 r1 = (p1 & 0x00ff0000) >> 16; \
+ const Uint32 g1 = (p1 & 0x0000ff00) >> 8; \
+ const Uint32 b1 = (p1 & 0x000000ff); \
+ const Uint32 R = (r + r1)/2; \
+ const Uint32 G = (g + g1)/2; \
+ const Uint32 B = (b + b1)/2; \
+
+#define READ_ONE_RGB_PIXEL READ_1x1_PIXEL
+
+ switch (dst_format)
+ {
+ case SDL_PIXELFORMAT_YV12:
+ case SDL_PIXELFORMAT_IYUV:
+ case SDL_PIXELFORMAT_NV12:
+ case SDL_PIXELFORMAT_NV21:
+ {
+ const Uint8 *curr_row, *next_row;
+
+ Uint8 *plane_y;
+ Uint8 *plane_u;
+ Uint8 *plane_v;
+ Uint8 *plane_interleaved_uv;
+ Uint32 y_stride, uv_stride, y_skip, uv_skip;
+
+ GetYUVPlanes(width, height, dst_format, dst, dst_pitch,
+ (const Uint8 **)&plane_y, (const Uint8 **)&plane_u, (const Uint8 **)&plane_v,
+ &y_stride, &uv_stride);
+ plane_interleaved_uv = (plane_y + height * y_stride);
+ y_skip = (y_stride - width);
+
+ curr_row = (const Uint8*)src;
+
+ /* Write Y plane */
+ for (j = 0; j < height; j++) {
+ for (i = 0; i < width; i++) {
+ const Uint32 p1 = ((const Uint32 *)curr_row)[i];
+ const Uint32 r = (p1 & 0x00ff0000) >> 16;
+ const Uint32 g = (p1 & 0x0000ff00) >> 8;
+ const Uint32 b = (p1 & 0x000000ff);
+ *plane_y++ = MAKE_Y(r, g, b);
+ }
+ plane_y += y_skip;
+ curr_row += src_pitch;
+ }
+
+ curr_row = (const Uint8*)src;
+ next_row = (const Uint8*)src;
+ next_row += src_pitch;
+
+ if (dst_format == SDL_PIXELFORMAT_YV12 || dst_format == SDL_PIXELFORMAT_IYUV)
+ {
+ /* Write UV planes, not interleaved */
+ uv_skip = (uv_stride - (width + 1)/2);
+ for (j = 0; j < height_half; j++) {
+ for (i = 0; i < width_half; i++) {
+ READ_2x2_PIXELS;
+ *plane_u++ = MAKE_U(r, g, b);
+ *plane_v++ = MAKE_V(r, g, b);
+ }
+ if (width_remainder) {
+ READ_2x1_PIXELS;
+ *plane_u++ = MAKE_U(r, g, b);
+ *plane_v++ = MAKE_V(r, g, b);
+ }
+ plane_u += uv_skip;
+ plane_v += uv_skip;
+ curr_row += src_pitch_x_2;
+ next_row += src_pitch_x_2;
+ }
+ if (height_remainder) {
+ for (i = 0; i < width_half; i++) {
+ READ_1x2_PIXELS;
+ *plane_u++ = MAKE_U(r, g, b);
+ *plane_v++ = MAKE_V(r, g, b);
+ }
+ if (width_remainder) {
+ READ_1x1_PIXEL;
+ *plane_u++ = MAKE_U(r, g, b);
+ *plane_v++ = MAKE_V(r, g, b);
+ }
+ plane_u += uv_skip;
+ plane_v += uv_skip;
+ }
+ }
+ else if (dst_format == SDL_PIXELFORMAT_NV12)
+ {
+ uv_skip = (uv_stride - ((width + 1)/2)*2);
+ for (j = 0; j < height_half; j++) {
+ for (i = 0; i < width_half; i++) {
+ READ_2x2_PIXELS;
+ *plane_interleaved_uv++ = MAKE_U(r, g, b);
+ *plane_interleaved_uv++ = MAKE_V(r, g, b);
+ }
+ if (width_remainder) {
+ READ_2x1_PIXELS;
+ *plane_interleaved_uv++ = MAKE_U(r, g, b);
+ *plane_interleaved_uv++ = MAKE_V(r, g, b);
+ }
+ plane_interleaved_uv += uv_skip;
+ curr_row += src_pitch_x_2;
+ next_row += src_pitch_x_2;
+ }
+ if (height_remainder) {
+ for (i = 0; i < width_half; i++) {
+ READ_1x2_PIXELS;
+ *plane_interleaved_uv++ = MAKE_U(r, g, b);
+ *plane_interleaved_uv++ = MAKE_V(r, g, b);
+ }
+ if (width_remainder) {
+ READ_1x1_PIXEL;
+ *plane_interleaved_uv++ = MAKE_U(r, g, b);
+ *plane_interleaved_uv++ = MAKE_V(r, g, b);
+ }
+ }
+ }
+ else /* dst_format == SDL_PIXELFORMAT_NV21 */
+ {
+ uv_skip = (uv_stride - ((width + 1)/2)*2);
+ for (j = 0; j < height_half; j++) {
+ for (i = 0; i < width_half; i++) {
+ READ_2x2_PIXELS;
+ *plane_interleaved_uv++ = MAKE_V(r, g, b);
+ *plane_interleaved_uv++ = MAKE_U(r, g, b);
+ }
+ if (width_remainder) {
+ READ_2x1_PIXELS;
+ *plane_interleaved_uv++ = MAKE_V(r, g, b);
+ *plane_interleaved_uv++ = MAKE_U(r, g, b);
+ }
+ plane_interleaved_uv += uv_skip;
+ curr_row += src_pitch_x_2;
+ next_row += src_pitch_x_2;
+ }
+ if (height_remainder) {
+ for (i = 0; i < width_half; i++) {
+ READ_1x2_PIXELS;
+ *plane_interleaved_uv++ = MAKE_V(r, g, b);
+ *plane_interleaved_uv++ = MAKE_U(r, g, b);
+ }
+ if (width_remainder) {
+ READ_1x1_PIXEL;
+ *plane_interleaved_uv++ = MAKE_V(r, g, b);
+ *plane_interleaved_uv++ = MAKE_U(r, g, b);
+ }
+ }
+ }
+ }
+ break;
+
+ case SDL_PIXELFORMAT_YUY2:
+ case SDL_PIXELFORMAT_UYVY:
+ case SDL_PIXELFORMAT_YVYU:
+ {
+ const Uint8 *curr_row = (const Uint8*) src;
+ Uint8 *plane = (Uint8*) dst;
+ const int row_size = (4 * ((width + 1) / 2));
+ int plane_skip;
+
+ if (dst_pitch < row_size) {
+ return SDL_SetError("Destination pitch is too small, expected at least %d\n", row_size);
+ }
+ plane_skip = (dst_pitch - row_size);
+
+ /* Write YUV plane, packed */
+ if (dst_format == SDL_PIXELFORMAT_YUY2)
+ {
+ for (j = 0; j < height; j++) {
+ for (i = 0; i < width_half; i++) {
+ READ_TWO_RGB_PIXELS;
+ /* Y U Y1 V */
+ *plane++ = MAKE_Y(r, g, b);
+ *plane++ = MAKE_U(R, G, B);
+ *plane++ = MAKE_Y(r1, g1, b1);
+ *plane++ = MAKE_V(R, G, B);
+ }
+ if (width_remainder) {
+ READ_ONE_RGB_PIXEL;
+ /* Y U Y V */
+ *plane++ = MAKE_Y(r, g, b);
+ *plane++ = MAKE_U(r, g, b);
+ *plane++ = MAKE_Y(r, g, b);
+ *plane++ = MAKE_V(r, g, b);
+ }
+ plane += plane_skip;
+ curr_row += src_pitch;
+ }
+ }
+ else if (dst_format == SDL_PIXELFORMAT_UYVY)
+ {
+ for (j = 0; j < height; j++) {
+ for (i = 0; i < width_half; i++) {
+ READ_TWO_RGB_PIXELS;
+ /* U Y V Y1 */
+ *plane++ = MAKE_U(R, G, B);
+ *plane++ = MAKE_Y(r, g, b);
+ *plane++ = MAKE_V(R, G, B);
+ *plane++ = MAKE_Y(r1, g1, b1);
+ }
+ if (width_remainder) {
+ READ_ONE_RGB_PIXEL;
+ /* U Y V Y */
+ *plane++ = MAKE_U(r, g, b);
+ *plane++ = MAKE_Y(r, g, b);
+ *plane++ = MAKE_V(r, g, b);
+ *plane++ = MAKE_Y(r, g, b);
+ }
+ plane += plane_skip;
+ curr_row += src_pitch;
+ }
+ }
+ else if (dst_format == SDL_PIXELFORMAT_YVYU)
+ {
+ for (j = 0; j < height; j++) {
+ for (i = 0; i < width_half; i++) {
+ READ_TWO_RGB_PIXELS;
+ /* Y V Y1 U */
+ *plane++ = MAKE_Y(r, g, b);
+ *plane++ = MAKE_V(R, G, B);
+ *plane++ = MAKE_Y(r1, g1, b1);
+ *plane++ = MAKE_U(R, G, B);
+ }
+ if (width_remainder) {
+ READ_ONE_RGB_PIXEL;
+ /* Y V Y U */
+ *plane++ = MAKE_Y(r, g, b);
+ *plane++ = MAKE_V(r, g, b);
+ *plane++ = MAKE_Y(r, g, b);
+ *plane++ = MAKE_U(r, g, b);
+ }
+ plane += plane_skip;
+ curr_row += src_pitch;
+ }
+ }
+ }
+ break;
+
+ default:
+ return SDL_SetError("Unsupported YUV destination format: %s", SDL_GetPixelFormatName(dst_format));
+ }
+#undef MAKE_Y
+#undef MAKE_U
+#undef MAKE_V
+#undef READ_2x2_PIXELS
+#undef READ_2x1_PIXELS
+#undef READ_1x2_PIXELS
+#undef READ_1x1_PIXEL
+#undef READ_TWO_RGB_PIXELS
+#undef READ_ONE_RGB_PIXEL
+ return 0;
+}
+
+int
+SDL_ConvertPixels_RGB_to_YUV(int width, int height,
+ Uint32 src_format, const void *src, int src_pitch,
+ Uint32 dst_format, void *dst, int dst_pitch)
+{
+#if 0 /* Doesn't handle odd widths */
+ /* RGB24 to FOURCC */
+ if (src_format == SDL_PIXELFORMAT_RGB24) {
+ Uint8 *y;
+ Uint8 *u;
+ Uint8 *v;
+ Uint32 y_stride;
+ Uint32 uv_stride;
+ YCbCrType yuv_type;
+
+ if (GetYUVPlanes(width, height, dst_format, dst, dst_pitch, (const Uint8 **)&y, (const Uint8 **)&u, (const Uint8 **)&v, &y_stride, &uv_stride) < 0) {
+ return -1;
+ }
+
+ if (GetYUVConversionType(width, height, &yuv_type) < 0) {
+ return -1;
+ }
+
+ rgb24_yuv420_std(width, height, src, src_pitch, y, u, v, y_stride, uv_stride, yuv_type);
+ return 0;
+ }
+#endif
+
+ /* ARGB8888 to FOURCC */
+ if (src_format == SDL_PIXELFORMAT_ARGB8888) {
+ return SDL_ConvertPixels_ARGB8888_to_YUV(width, height, src, src_pitch, dst_format, dst, dst_pitch);
+ }
+
+ /* not ARGB8888 to FOURCC : need an intermediate conversion */
+ {
+ int ret;
+ void *tmp;
+ int tmp_pitch = (width * sizeof(Uint32));
+
+ tmp = SDL_malloc(tmp_pitch * height);
+ if (tmp == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ /* convert src/src_format to tmp/ARGB8888 */
+ ret = SDL_ConvertPixels(width, height, src_format, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, tmp, tmp_pitch);
+ if (ret == -1) {
+ SDL_free(tmp);
+ return ret;
+ }
+
+ /* convert tmp/ARGB8888 to dst/FOURCC */
+ ret = SDL_ConvertPixels_ARGB8888_to_YUV(width, height, tmp, tmp_pitch, dst_format, dst, dst_pitch);
+ SDL_free(tmp);
+ return ret;
+ }
+}
+
+static int
+SDL_ConvertPixels_YUV_to_YUV_Copy(int width, int height, Uint32 format,
+ const void *src, int src_pitch, void *dst, int dst_pitch)
+{
+ int i;
+
+ if (IsPlanar2x2Format(format)) {
+ /* Y plane */
+ for (i = height; i--;) {
+ SDL_memcpy(dst, src, width);
+ src = (const Uint8*)src + src_pitch;
+ dst = (Uint8*)dst + dst_pitch;
+ }
+
+ if (format == SDL_PIXELFORMAT_YV12 || format == SDL_PIXELFORMAT_IYUV) {
+ /* U and V planes are a quarter the size of the Y plane, rounded up */
+ width = (width + 1) / 2;
+ height = (height + 1) / 2;
+ src_pitch = (src_pitch + 1) / 2;
+ dst_pitch = (dst_pitch + 1) / 2;
+ for (i = height * 2; i--;) {
+ SDL_memcpy(dst, src, width);
+ src = (const Uint8*)src + src_pitch;
+ dst = (Uint8*)dst + dst_pitch;
+ }
+ } else if (format == SDL_PIXELFORMAT_NV12 || format == SDL_PIXELFORMAT_NV21) {
+ /* U/V plane is half the height of the Y plane, rounded up */
+ height = (height + 1) / 2;
+ width = ((width + 1) / 2)*2;
+ src_pitch = ((src_pitch + 1) / 2)*2;
+ dst_pitch = ((dst_pitch + 1) / 2)*2;
+ for (i = height; i--;) {
+ SDL_memcpy(dst, src, width);
+ src = (const Uint8*)src + src_pitch;
+ dst = (Uint8*)dst + dst_pitch;
+ }
+ }
+ return 0;
+ }
+
+ if (IsPacked4Format(format)) {
+ /* Packed planes */
+ width = 4 * ((width + 1) / 2);
+ for (i = height; i--;) {
+ SDL_memcpy(dst, src, width);
+ src = (const Uint8*)src + src_pitch;
+ dst = (Uint8*)dst + dst_pitch;
+ }
+ return 0;
+ }
+
+ return SDL_SetError("SDL_ConvertPixels_YUV_to_YUV_Copy: Unsupported YUV format: %s", SDL_GetPixelFormatName(format));
+}
+
+static int
+SDL_ConvertPixels_SwapUVPlanes(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
+{
+ int y;
+ const int UVwidth = (width + 1)/2;
+ const int UVheight = (height + 1)/2;
+
+ /* Skip the Y plane */
+ src = (const Uint8 *)src + height * src_pitch;
+ dst = (Uint8 *)dst + height * dst_pitch;
+
+ if (src == dst) {
+ int UVpitch = (dst_pitch + 1)/2;
+ Uint8 *tmp;
+ Uint8 *row1 = dst;
+ Uint8 *row2 = (Uint8 *)dst + UVheight * UVpitch;
+
+ /* Allocate a temporary row for the swap */
+ tmp = (Uint8 *)SDL_malloc(UVwidth);
+ if (!tmp) {
+ return SDL_OutOfMemory();
+ }
+ for (y = 0; y < UVheight; ++y) {
+ SDL_memcpy(tmp, row1, UVwidth);
+ SDL_memcpy(row1, row2, UVwidth);
+ SDL_memcpy(row2, tmp, UVwidth);
+ row1 += UVpitch;
+ row2 += UVpitch;
+ }
+ SDL_free(tmp);
+ } else {
+ const Uint8 *srcUV;
+ Uint8 *dstUV;
+ int srcUVPitch = ((src_pitch + 1)/2);
+ int dstUVPitch = ((dst_pitch + 1)/2);
+
+ /* Copy the first plane */
+ srcUV = (const Uint8 *)src;
+ dstUV = (Uint8 *)dst + UVheight * dstUVPitch;
+ for (y = 0; y < UVheight; ++y) {
+ SDL_memcpy(dstUV, srcUV, UVwidth);
+ srcUV += srcUVPitch;
+ dstUV += dstUVPitch;
+ }
+
+ /* Copy the second plane */
+ dstUV = (Uint8 *)dst;
+ for (y = 0; y < UVheight; ++y) {
+ SDL_memcpy(dstUV, srcUV, UVwidth);
+ srcUV += srcUVPitch;
+ dstUV += dstUVPitch;
+ }
+ }
+ return 0;
+}
+
+static int
+SDL_ConvertPixels_PackUVPlanes_to_NV(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, SDL_bool reverseUV)
+{
+ int x, y;
+ const int UVwidth = (width + 1)/2;
+ const int UVheight = (height + 1)/2;
+ const int srcUVPitch = ((src_pitch + 1)/2);
+ const int srcUVPitchLeft = srcUVPitch - UVwidth;
+ const int dstUVPitch = ((dst_pitch + 1)/2)*2;
+ const int dstUVPitchLeft = dstUVPitch - UVwidth*2;
+ const Uint8 *src1, *src2;
+ Uint8 *dstUV;
+ Uint8 *tmp = NULL;
+#ifdef __SSE2__
+ const SDL_bool use_SSE2 = SDL_HasSSE2();
+#endif
+
+ /* Skip the Y plane */
+ src = (const Uint8 *)src + height * src_pitch;
+ dst = (Uint8 *)dst + height * dst_pitch;
+
+ if (src == dst) {
+ /* Need to make a copy of the buffer so we don't clobber it while converting */
+ tmp = (Uint8 *)SDL_malloc(2*UVheight*srcUVPitch);
+ if (!tmp) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memcpy(tmp, src, 2*UVheight*srcUVPitch);
+ src = tmp;
+ }
+
+ if (reverseUV) {
+ src2 = (const Uint8 *)src;
+ src1 = src2 + UVheight * srcUVPitch;
+ } else {
+ src1 = (const Uint8 *)src;
+ src2 = src1 + UVheight * srcUVPitch;
+ }
+ dstUV = (Uint8 *)dst;
+
+ y = UVheight;
+ while (y--) {
+ x = UVwidth;
+#ifdef __SSE2__
+ if (use_SSE2) {
+ while (x >= 16) {
+ __m128i u = _mm_loadu_si128((__m128i *)src1);
+ __m128i v = _mm_loadu_si128((__m128i *)src2);
+ __m128i uv1 = _mm_unpacklo_epi8(u, v);
+ __m128i uv2 = _mm_unpackhi_epi8(u, v);
+ _mm_storeu_si128((__m128i*)dstUV, uv1);
+ _mm_storeu_si128((__m128i*)(dstUV + 16), uv2);
+ src1 += 16;
+ src2 += 16;
+ dstUV += 32;
+ x -= 16;
+ }
+ }
+#endif
+ while (x--) {
+ *dstUV++ = *src1++;
+ *dstUV++ = *src2++;
+ }
+ src1 += srcUVPitchLeft;
+ src2 += srcUVPitchLeft;
+ dstUV += dstUVPitchLeft;
+ }
+
+ if (tmp) {
+ SDL_free(tmp);
+ }
+ return 0;
+}
+
+static int
+SDL_ConvertPixels_SplitNV_to_UVPlanes(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, SDL_bool reverseUV)
+{
+ int x, y;
+ const int UVwidth = (width + 1)/2;
+ const int UVheight = (height + 1)/2;
+ const int srcUVPitch = ((src_pitch + 1)/2)*2;
+ const int srcUVPitchLeft = srcUVPitch - UVwidth*2;
+ const int dstUVPitch = ((dst_pitch + 1)/2);
+ const int dstUVPitchLeft = dstUVPitch - UVwidth;
+ const Uint8 *srcUV;
+ Uint8 *dst1, *dst2;
+ Uint8 *tmp = NULL;
+#ifdef __SSE2__
+ const SDL_bool use_SSE2 = SDL_HasSSE2();
+#endif
+
+ /* Skip the Y plane */
+ src = (const Uint8 *)src + height * src_pitch;
+ dst = (Uint8 *)dst + height * dst_pitch;
+
+ if (src == dst) {
+ /* Need to make a copy of the buffer so we don't clobber it while converting */
+ tmp = (Uint8 *)SDL_malloc(UVheight*srcUVPitch);
+ if (!tmp) {
+ return SDL_OutOfMemory();
+ }
+ SDL_memcpy(tmp, src, UVheight*srcUVPitch);
+ src = tmp;
+ }
+
+ if (reverseUV) {
+ dst2 = (Uint8 *)dst;
+ dst1 = dst2 + UVheight * dstUVPitch;
+ } else {
+ dst1 = (Uint8 *)dst;
+ dst2 = dst1 + UVheight * dstUVPitch;
+ }
+ srcUV = (const Uint8 *)src;
+
+ y = UVheight;
+ while (y--) {
+ x = UVwidth;
+#ifdef __SSE2__
+ if (use_SSE2) {
+ __m128i mask = _mm_set1_epi16(0x00FF);
+ while (x >= 16) {
+ __m128i uv1 = _mm_loadu_si128((__m128i*)srcUV);
+ __m128i uv2 = _mm_loadu_si128((__m128i*)(srcUV+16));
+ __m128i u1 = _mm_and_si128(uv1, mask);
+ __m128i u2 = _mm_and_si128(uv2, mask);
+ __m128i u = _mm_packus_epi16(u1, u2);
+ __m128i v1 = _mm_srli_epi16(uv1, 8);
+ __m128i v2 = _mm_srli_epi16(uv2, 8);
+ __m128i v = _mm_packus_epi16(v1, v2);
+ _mm_storeu_si128((__m128i*)dst1, u);
+ _mm_storeu_si128((__m128i*)dst2, v);
+ srcUV += 32;
+ dst1 += 16;
+ dst2 += 16;
+ x -= 16;
+ }
+ }
+#endif
+ while (x--) {
+ *dst1++ = *srcUV++;
+ *dst2++ = *srcUV++;
+ }
+ srcUV += srcUVPitchLeft;
+ dst1 += dstUVPitchLeft;
+ dst2 += dstUVPitchLeft;
+ }
+
+ if (tmp) {
+ SDL_free(tmp);
+ }
+ return 0;
+}
+
+static int
+SDL_ConvertPixels_SwapNV(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
+{
+ int x, y;
+ const int UVwidth = (width + 1)/2;
+ const int UVheight = (height + 1)/2;
+ const int srcUVPitch = ((src_pitch + 1)/2)*2;
+ const int srcUVPitchLeft = (srcUVPitch - UVwidth*2)/sizeof(Uint16);
+ const int dstUVPitch = ((dst_pitch + 1)/2)*2;
+ const int dstUVPitchLeft = (dstUVPitch - UVwidth*2)/sizeof(Uint16);
+ const Uint16 *srcUV;
+ Uint16 *dstUV;
+#ifdef __SSE2__
+ const SDL_bool use_SSE2 = SDL_HasSSE2();
+#endif
+
+ /* Skip the Y plane */
+ src = (const Uint8 *)src + height * src_pitch;
+ dst = (Uint8 *)dst + height * dst_pitch;
+
+ srcUV = (const Uint16 *)src;
+ dstUV = (Uint16 *)dst;
+ y = UVheight;
+ while (y--) {
+ x = UVwidth;
+#ifdef __SSE2__
+ if (use_SSE2) {
+ while (x >= 8) {
+ __m128i uv = _mm_loadu_si128((__m128i*)srcUV);
+ __m128i v = _mm_slli_epi16(uv, 8);
+ __m128i u = _mm_srli_epi16(uv, 8);
+ __m128i vu = _mm_or_si128(v, u);
+ _mm_storeu_si128((__m128i*)dstUV, vu);
+ srcUV += 8;
+ dstUV += 8;
+ x -= 8;
+ }
+ }
+#endif
+ while (x--) {
+ *dstUV++ = SDL_Swap16(*srcUV++);
+ }
+ srcUV += srcUVPitchLeft;
+ dstUV += dstUVPitchLeft;
+ }
+ return 0;
+}
+
+static int
+SDL_ConvertPixels_Planar2x2_to_Planar2x2(int width, int height,
+ Uint32 src_format, const void *src, int src_pitch,
+ Uint32 dst_format, void *dst, int dst_pitch)
+{
+ if (src != dst) {
+ /* Copy Y plane */
+ int i;
+ const Uint8 *srcY = (const Uint8 *)src;
+ Uint8 *dstY = (Uint8 *)dst;
+ for (i = height; i--; ) {
+ SDL_memcpy(dstY, srcY, width);
+ srcY += src_pitch;
+ dstY += dst_pitch;
+ }
+ }
+
+ switch (src_format) {
+ case SDL_PIXELFORMAT_YV12:
+ switch (dst_format) {
+ case SDL_PIXELFORMAT_IYUV:
+ return SDL_ConvertPixels_SwapUVPlanes(width, height, src, src_pitch, dst, dst_pitch);
+ case SDL_PIXELFORMAT_NV12:
+ return SDL_ConvertPixels_PackUVPlanes_to_NV(width, height, src, src_pitch, dst, dst_pitch, SDL_TRUE);
+ case SDL_PIXELFORMAT_NV21:
+ return SDL_ConvertPixels_PackUVPlanes_to_NV(width, height, src, src_pitch, dst, dst_pitch, SDL_FALSE);
+ default:
+ break;
+ }
+ break;
+ case SDL_PIXELFORMAT_IYUV:
+ switch (dst_format) {
+ case SDL_PIXELFORMAT_YV12:
+ return SDL_ConvertPixels_SwapUVPlanes(width, height, src, src_pitch, dst, dst_pitch);
+ case SDL_PIXELFORMAT_NV12:
+ return SDL_ConvertPixels_PackUVPlanes_to_NV(width, height, src, src_pitch, dst, dst_pitch, SDL_FALSE);
+ case SDL_PIXELFORMAT_NV21:
+ return SDL_ConvertPixels_PackUVPlanes_to_NV(width, height, src, src_pitch, dst, dst_pitch, SDL_TRUE);
+ default:
+ break;
+ }
+ break;
+ case SDL_PIXELFORMAT_NV12:
+ switch (dst_format) {
+ case SDL_PIXELFORMAT_YV12:
+ return SDL_ConvertPixels_SplitNV_to_UVPlanes(width, height, src, src_pitch, dst, dst_pitch, SDL_TRUE);
+ case SDL_PIXELFORMAT_IYUV:
+ return SDL_ConvertPixels_SplitNV_to_UVPlanes(width, height, src, src_pitch, dst, dst_pitch, SDL_FALSE);
+ case SDL_PIXELFORMAT_NV21:
+ return SDL_ConvertPixels_SwapNV(width, height, src, src_pitch, dst, dst_pitch);
+ default:
+ break;
+ }
+ break;
+ case SDL_PIXELFORMAT_NV21:
+ switch (dst_format) {
+ case SDL_PIXELFORMAT_YV12:
+ return SDL_ConvertPixels_SplitNV_to_UVPlanes(width, height, src, src_pitch, dst, dst_pitch, SDL_FALSE);
+ case SDL_PIXELFORMAT_IYUV:
+ return SDL_ConvertPixels_SplitNV_to_UVPlanes(width, height, src, src_pitch, dst, dst_pitch, SDL_TRUE);
+ case SDL_PIXELFORMAT_NV12:
+ return SDL_ConvertPixels_SwapNV(width, height, src, src_pitch, dst, dst_pitch);
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+ return SDL_SetError("SDL_ConvertPixels_Planar2x2_to_Planar2x2: Unsupported YUV conversion: %s -> %s", SDL_GetPixelFormatName(src_format), SDL_GetPixelFormatName(dst_format));
+}
+
+#define PACKED4_TO_PACKED4_ROW_SSE2(shuffle) \
+ while (x >= 4) { \
+ __m128i yuv = _mm_loadu_si128((__m128i*)srcYUV); \
+ __m128i lo = _mm_unpacklo_epi8(yuv, _mm_setzero_si128()); \
+ __m128i hi = _mm_unpackhi_epi8(yuv, _mm_setzero_si128()); \
+ lo = _mm_shufflelo_epi16(lo, shuffle); \
+ lo = _mm_shufflehi_epi16(lo, shuffle); \
+ hi = _mm_shufflelo_epi16(hi, shuffle); \
+ hi = _mm_shufflehi_epi16(hi, shuffle); \
+ yuv = _mm_packus_epi16(lo, hi); \
+ _mm_storeu_si128((__m128i*)dstYUV, yuv); \
+ srcYUV += 16; \
+ dstYUV += 16; \
+ x -= 4; \
+ } \
+
+static int
+SDL_ConvertPixels_YUY2_to_UYVY(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
+{
+ int x, y;
+ const int YUVwidth = (width + 1)/2;
+ const int srcYUVPitchLeft = (src_pitch - YUVwidth*4);
+ const int dstYUVPitchLeft = (dst_pitch - YUVwidth*4);
+ const Uint8 *srcYUV = (const Uint8 *)src;
+ Uint8 *dstYUV = (Uint8 *)dst;
+#ifdef __SSE2__
+ const SDL_bool use_SSE2 = SDL_HasSSE2();
+#endif
+
+ y = height;
+ while (y--) {
+ x = YUVwidth;
+#ifdef __SSE2__
+ if (use_SSE2) {
+ PACKED4_TO_PACKED4_ROW_SSE2(_MM_SHUFFLE(2, 3, 0, 1));
+ }
+#endif
+ while (x--) {
+ Uint8 Y1, U, Y2, V;
+
+ Y1 = srcYUV[0];
+ U = srcYUV[1];
+ Y2 = srcYUV[2];
+ V = srcYUV[3];
+ srcYUV += 4;
+
+ dstYUV[0] = U;
+ dstYUV[1] = Y1;
+ dstYUV[2] = V;
+ dstYUV[3] = Y2;
+ dstYUV += 4;
+ }
+ srcYUV += srcYUVPitchLeft;
+ dstYUV += dstYUVPitchLeft;
+ }
+ return 0;
+}
+
+static int
+SDL_ConvertPixels_YUY2_to_YVYU(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
+{
+ int x, y;
+ const int YUVwidth = (width + 1)/2;
+ const int srcYUVPitchLeft = (src_pitch - YUVwidth*4);
+ const int dstYUVPitchLeft = (dst_pitch - YUVwidth*4);
+ const Uint8 *srcYUV = (const Uint8 *)src;
+ Uint8 *dstYUV = (Uint8 *)dst;
+#ifdef __SSE2__
+ const SDL_bool use_SSE2 = SDL_HasSSE2();
+#endif
+
+ y = height;
+ while (y--) {
+ x = YUVwidth;
+#ifdef __SSE2__
+ if (use_SSE2) {
+ PACKED4_TO_PACKED4_ROW_SSE2(_MM_SHUFFLE(1, 2, 3, 0));
+ }
+#endif
+ while (x--) {
+ Uint8 Y1, U, Y2, V;
+
+ Y1 = srcYUV[0];
+ U = srcYUV[1];
+ Y2 = srcYUV[2];
+ V = srcYUV[3];
+ srcYUV += 4;
+
+ dstYUV[0] = Y1;
+ dstYUV[1] = V;
+ dstYUV[2] = Y2;
+ dstYUV[3] = U;
+ dstYUV += 4;
+ }
+ srcYUV += srcYUVPitchLeft;
+ dstYUV += dstYUVPitchLeft;
+ }
+ return 0;
+}
+
+static int
+SDL_ConvertPixels_UYVY_to_YUY2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
+{
+ int x, y;
+ const int YUVwidth = (width + 1)/2;
+ const int srcYUVPitchLeft = (src_pitch - YUVwidth*4);
+ const int dstYUVPitchLeft = (dst_pitch - YUVwidth*4);
+ const Uint8 *srcYUV = (const Uint8 *)src;
+ Uint8 *dstYUV = (Uint8 *)dst;
+#ifdef __SSE2__
+ const SDL_bool use_SSE2 = SDL_HasSSE2();
+#endif
+
+ y = height;
+ while (y--) {
+ x = YUVwidth;
+#ifdef __SSE2__
+ if (use_SSE2) {
+ PACKED4_TO_PACKED4_ROW_SSE2(_MM_SHUFFLE(2, 3, 0, 1));
+ }
+#endif
+ while (x--) {
+ Uint8 Y1, U, Y2, V;
+
+ U = srcYUV[0];
+ Y1 = srcYUV[1];
+ V = srcYUV[2];
+ Y2 = srcYUV[3];
+ srcYUV += 4;
+
+ dstYUV[0] = Y1;
+ dstYUV[1] = U;
+ dstYUV[2] = Y2;
+ dstYUV[3] = V;
+ dstYUV += 4;
+ }
+ srcYUV += srcYUVPitchLeft;
+ dstYUV += dstYUVPitchLeft;
+ }
+ return 0;
+}
+
+static int
+SDL_ConvertPixels_UYVY_to_YVYU(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
+{
+ int x, y;
+ const int YUVwidth = (width + 1)/2;
+ const int srcYUVPitchLeft = (src_pitch - YUVwidth*4);
+ const int dstYUVPitchLeft = (dst_pitch - YUVwidth*4);
+ const Uint8 *srcYUV = (const Uint8 *)src;
+ Uint8 *dstYUV = (Uint8 *)dst;
+#ifdef __SSE2__
+ const SDL_bool use_SSE2 = SDL_HasSSE2();
+#endif
+
+ y = height;
+ while (y--) {
+ x = YUVwidth;
+#ifdef __SSE2__
+ if (use_SSE2) {
+ PACKED4_TO_PACKED4_ROW_SSE2(_MM_SHUFFLE(0, 3, 2, 1));
+ }
+#endif
+ while (x--) {
+ Uint8 Y1, U, Y2, V;
+
+ U = srcYUV[0];
+ Y1 = srcYUV[1];
+ V = srcYUV[2];
+ Y2 = srcYUV[3];
+ srcYUV += 4;
+
+ dstYUV[0] = Y1;
+ dstYUV[1] = V;
+ dstYUV[2] = Y2;
+ dstYUV[3] = U;
+ dstYUV += 4;
+ }
+ srcYUV += srcYUVPitchLeft;
+ dstYUV += dstYUVPitchLeft;
+ }
+ return 0;
+}
+
+static int
+SDL_ConvertPixels_YVYU_to_YUY2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
+{
+ int x, y;
+ const int YUVwidth = (width + 1)/2;
+ const int srcYUVPitchLeft = (src_pitch - YUVwidth*4);
+ const int dstYUVPitchLeft = (dst_pitch - YUVwidth*4);
+ const Uint8 *srcYUV = (const Uint8 *)src;
+ Uint8 *dstYUV = (Uint8 *)dst;
+#ifdef __SSE2__
+ const SDL_bool use_SSE2 = SDL_HasSSE2();
+#endif
+
+ y = height;
+ while (y--) {
+ x = YUVwidth;
+#ifdef __SSE2__
+ if (use_SSE2) {
+ PACKED4_TO_PACKED4_ROW_SSE2(_MM_SHUFFLE(1, 2, 3, 0));
+ }
+#endif
+ while (x--) {
+ Uint8 Y1, U, Y2, V;
+
+ Y1 = srcYUV[0];
+ V = srcYUV[1];
+ Y2 = srcYUV[2];
+ U = srcYUV[3];
+ srcYUV += 4;
+
+ dstYUV[0] = Y1;
+ dstYUV[1] = U;
+ dstYUV[2] = Y2;
+ dstYUV[3] = V;
+ dstYUV += 4;
+ }
+ srcYUV += srcYUVPitchLeft;
+ dstYUV += dstYUVPitchLeft;
+ }
+ return 0;
+}
+
+static int
+SDL_ConvertPixels_YVYU_to_UYVY(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
+{
+ int x, y;
+ const int YUVwidth = (width + 1)/2;
+ const int srcYUVPitchLeft = (src_pitch - YUVwidth*4);
+ const int dstYUVPitchLeft = (dst_pitch - YUVwidth*4);
+ const Uint8 *srcYUV = (const Uint8 *)src;
+ Uint8 *dstYUV = (Uint8 *)dst;
+#ifdef __SSE2__
+ const SDL_bool use_SSE2 = SDL_HasSSE2();
+#endif
+
+ y = height;
+ while (y--) {
+ x = YUVwidth;
+#ifdef __SSE2__
+ if (use_SSE2) {
+ PACKED4_TO_PACKED4_ROW_SSE2(_MM_SHUFFLE(2, 1, 0, 3));
+ }
+#endif
+ while (x--) {
+ Uint8 Y1, U, Y2, V;
+
+ Y1 = srcYUV[0];
+ V = srcYUV[1];
+ Y2 = srcYUV[2];
+ U = srcYUV[3];
+ srcYUV += 4;
+
+ dstYUV[0] = U;
+ dstYUV[1] = Y1;
+ dstYUV[2] = V;
+ dstYUV[3] = Y2;
+ dstYUV += 4;
+ }
+ srcYUV += srcYUVPitchLeft;
+ dstYUV += dstYUVPitchLeft;
+ }
+ return 0;
+}
+
+static int
+SDL_ConvertPixels_Packed4_to_Packed4(int width, int height,
+ Uint32 src_format, const void *src, int src_pitch,
+ Uint32 dst_format, void *dst, int dst_pitch)
+{
+ switch (src_format) {
+ case SDL_PIXELFORMAT_YUY2:
+ switch (dst_format) {
+ case SDL_PIXELFORMAT_UYVY:
+ return SDL_ConvertPixels_YUY2_to_UYVY(width, height, src, src_pitch, dst, dst_pitch);
+ case SDL_PIXELFORMAT_YVYU:
+ return SDL_ConvertPixels_YUY2_to_YVYU(width, height, src, src_pitch, dst, dst_pitch);
+ default:
+ break;
+ }
+ break;
+ case SDL_PIXELFORMAT_UYVY:
+ switch (dst_format) {
+ case SDL_PIXELFORMAT_YUY2:
+ return SDL_ConvertPixels_UYVY_to_YUY2(width, height, src, src_pitch, dst, dst_pitch);
+ case SDL_PIXELFORMAT_YVYU:
+ return SDL_ConvertPixels_UYVY_to_YVYU(width, height, src, src_pitch, dst, dst_pitch);
+ default:
+ break;
+ }
+ break;
+ case SDL_PIXELFORMAT_YVYU:
+ switch (dst_format) {
+ case SDL_PIXELFORMAT_YUY2:
+ return SDL_ConvertPixels_YVYU_to_YUY2(width, height, src, src_pitch, dst, dst_pitch);
+ case SDL_PIXELFORMAT_UYVY:
+ return SDL_ConvertPixels_YVYU_to_UYVY(width, height, src, src_pitch, dst, dst_pitch);
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+ return SDL_SetError("SDL_ConvertPixels_Packed4_to_Packed4: Unsupported YUV conversion: %s -> %s", SDL_GetPixelFormatName(src_format), SDL_GetPixelFormatName(dst_format));
+}
+
+static int
+SDL_ConvertPixels_Planar2x2_to_Packed4(int width, int height,
+ Uint32 src_format, const void *src, int src_pitch,
+ Uint32 dst_format, void *dst, int dst_pitch)
+{
+ int x, y;
+ const Uint8 *srcY1, *srcY2, *srcU, *srcV;
+ Uint32 srcY_pitch, srcUV_pitch;
+ Uint32 srcY_pitch_left, srcUV_pitch_left, srcUV_pixel_stride;
+ Uint8 *dstY1, *dstY2, *dstU1, *dstU2, *dstV1, *dstV2;
+ Uint32 dstY_pitch, dstUV_pitch;
+ Uint32 dst_pitch_left;
+
+ if (src == dst) {
+ return SDL_SetError("Can't change YUV plane types in-place");
+ }
+
+ if (GetYUVPlanes(width, height, src_format, src, src_pitch,
+ &srcY1, &srcU, &srcV, &srcY_pitch, &srcUV_pitch) < 0) {
+ return -1;
+ }
+ srcY2 = srcY1 + srcY_pitch;
+ srcY_pitch_left = (srcY_pitch - width);
+
+ if (src_format == SDL_PIXELFORMAT_NV12 || src_format == SDL_PIXELFORMAT_NV21) {
+ srcUV_pixel_stride = 2;
+ srcUV_pitch_left = (srcUV_pitch - 2*((width + 1)/2));
+ } else {
+ srcUV_pixel_stride = 1;
+ srcUV_pitch_left = (srcUV_pitch - ((width + 1)/2));
+ }
+
+ if (GetYUVPlanes(width, height, dst_format, dst, dst_pitch,
+ (const Uint8 **)&dstY1, (const Uint8 **)&dstU1, (const Uint8 **)&dstV1,
+ &dstY_pitch, &dstUV_pitch) < 0) {
+ return -1;
+ }
+ dstY2 = dstY1 + dstY_pitch;
+ dstU2 = dstU1 + dstUV_pitch;
+ dstV2 = dstV1 + dstUV_pitch;
+ dst_pitch_left = (dstY_pitch - 4*((width + 1)/2));
+
+ /* Copy 2x2 blocks of pixels at a time */
+ for (y = 0; y < (height - 1); y += 2) {
+ for (x = 0; x < (width - 1); x += 2) {
+ /* Row 1 */
+ *dstY1 = *srcY1++;
+ dstY1 += 2;
+ *dstY1 = *srcY1++;
+ dstY1 += 2;
+ *dstU1 = *srcU;
+ *dstV1 = *srcV;
+
+ /* Row 2 */
+ *dstY2 = *srcY2++;
+ dstY2 += 2;
+ *dstY2 = *srcY2++;
+ dstY2 += 2;
+ *dstU2 = *srcU;
+ *dstV2 = *srcV;
+
+ srcU += srcUV_pixel_stride;
+ srcV += srcUV_pixel_stride;
+ dstU1 += 4;
+ dstU2 += 4;
+ dstV1 += 4;
+ dstV2 += 4;
+ }
+
+ /* Last column */
+ if (x == (width - 1)) {
+ /* Row 1 */
+ *dstY1 = *srcY1;
+ dstY1 += 2;
+ *dstY1 = *srcY1++;
+ dstY1 += 2;
+ *dstU1 = *srcU;
+ *dstV1 = *srcV;
+
+ /* Row 2 */
+ *dstY2 = *srcY2;
+ dstY2 += 2;
+ *dstY2 = *srcY2++;
+ dstY2 += 2;
+ *dstU2 = *srcU;
+ *dstV2 = *srcV;
+
+ srcU += srcUV_pixel_stride;
+ srcV += srcUV_pixel_stride;
+ dstU1 += 4;
+ dstU2 += 4;
+ dstV1 += 4;
+ dstV2 += 4;
+ }
+
+ srcY1 += srcY_pitch_left + srcY_pitch;
+ srcY2 += srcY_pitch_left + srcY_pitch;
+ srcU += srcUV_pitch_left;
+ srcV += srcUV_pitch_left;
+ dstY1 += dst_pitch_left + dstY_pitch;
+ dstY2 += dst_pitch_left + dstY_pitch;
+ dstU1 += dst_pitch_left + dstUV_pitch;
+ dstU2 += dst_pitch_left + dstUV_pitch;
+ dstV1 += dst_pitch_left + dstUV_pitch;
+ dstV2 += dst_pitch_left + dstUV_pitch;
+ }
+
+ /* Last row */
+ if (y == (height - 1)) {
+ for (x = 0; x < (width - 1); x += 2) {
+ /* Row 1 */
+ *dstY1 = *srcY1++;
+ dstY1 += 2;
+ *dstY1 = *srcY1++;
+ dstY1 += 2;
+ *dstU1 = *srcU;
+ *dstV1 = *srcV;
+
+ srcU += srcUV_pixel_stride;
+ srcV += srcUV_pixel_stride;
+ dstU1 += 4;
+ dstV1 += 4;
+ }
+
+ /* Last column */
+ if (x == (width - 1)) {
+ /* Row 1 */
+ *dstY1 = *srcY1;
+ dstY1 += 2;
+ *dstY1 = *srcY1++;
+ dstY1 += 2;
+ *dstU1 = *srcU;
+ *dstV1 = *srcV;
+
+ srcU += srcUV_pixel_stride;
+ srcV += srcUV_pixel_stride;
+ dstU1 += 4;
+ dstV1 += 4;
+ }
+ }
+ return 0;
+}
+
+static int
+SDL_ConvertPixels_Packed4_to_Planar2x2(int width, int height,
+ Uint32 src_format, const void *src, int src_pitch,
+ Uint32 dst_format, void *dst, int dst_pitch)
+{
+ int x, y;
+ const Uint8 *srcY1, *srcY2, *srcU1, *srcU2, *srcV1, *srcV2;
+ Uint32 srcY_pitch, srcUV_pitch;
+ Uint32 src_pitch_left;
+ Uint8 *dstY1, *dstY2, *dstU, *dstV;
+ Uint32 dstY_pitch, dstUV_pitch;
+ Uint32 dstY_pitch_left, dstUV_pitch_left, dstUV_pixel_stride;
+
+ if (src == dst) {
+ return SDL_SetError("Can't change YUV plane types in-place");
+ }
+
+ if (GetYUVPlanes(width, height, src_format, src, src_pitch,
+ &srcY1, &srcU1, &srcV1, &srcY_pitch, &srcUV_pitch) < 0) {
+ return -1;
+ }
+ srcY2 = srcY1 + srcY_pitch;
+ srcU2 = srcU1 + srcUV_pitch;
+ srcV2 = srcV1 + srcUV_pitch;
+ src_pitch_left = (srcY_pitch - 4*((width + 1)/2));
+
+ if (GetYUVPlanes(width, height, dst_format, dst, dst_pitch,
+ (const Uint8 **)&dstY1, (const Uint8 **)&dstU, (const Uint8 **)&dstV,
+ &dstY_pitch, &dstUV_pitch) < 0) {
+ return -1;
+ }
+ dstY2 = dstY1 + dstY_pitch;
+ dstY_pitch_left = (dstY_pitch - width);
+
+ if (dst_format == SDL_PIXELFORMAT_NV12 || dst_format == SDL_PIXELFORMAT_NV21) {
+ dstUV_pixel_stride = 2;
+ dstUV_pitch_left = (dstUV_pitch - 2*((width + 1)/2));
+ } else {
+ dstUV_pixel_stride = 1;
+ dstUV_pitch_left = (dstUV_pitch - ((width + 1)/2));
+ }
+
+ /* Copy 2x2 blocks of pixels at a time */
+ for (y = 0; y < (height - 1); y += 2) {
+ for (x = 0; x < (width - 1); x += 2) {
+ /* Row 1 */
+ *dstY1++ = *srcY1;
+ srcY1 += 2;
+ *dstY1++ = *srcY1;
+ srcY1 += 2;
+
+ /* Row 2 */
+ *dstY2++ = *srcY2;
+ srcY2 += 2;
+ *dstY2++ = *srcY2;
+ srcY2 += 2;
+
+ *dstU = (Uint8)(((Uint32)*srcU1 + *srcU2)/2);
+ *dstV = (Uint8)(((Uint32)*srcV1 + *srcV2)/2);
+
+ srcU1 += 4;
+ srcU2 += 4;
+ srcV1 += 4;
+ srcV2 += 4;
+ dstU += dstUV_pixel_stride;
+ dstV += dstUV_pixel_stride;
+ }
+
+ /* Last column */
+ if (x == (width - 1)) {
+ /* Row 1 */
+ *dstY1 = *srcY1;
+ srcY1 += 2;
+ *dstY1++ = *srcY1;
+ srcY1 += 2;
+
+ /* Row 2 */
+ *dstY2 = *srcY2;
+ srcY2 += 2;
+ *dstY2++ = *srcY2;
+ srcY2 += 2;
+
+ *dstU = (Uint8)(((Uint32)*srcU1 + *srcU2)/2);
+ *dstV = (Uint8)(((Uint32)*srcV1 + *srcV2)/2);
+
+ srcU1 += 4;
+ srcU2 += 4;
+ srcV1 += 4;
+ srcV2 += 4;
+ dstU += dstUV_pixel_stride;
+ dstV += dstUV_pixel_stride;
+ }
+
+ srcY1 += src_pitch_left + srcY_pitch;
+ srcY2 += src_pitch_left + srcY_pitch;
+ srcU1 += src_pitch_left + srcUV_pitch;
+ srcU2 += src_pitch_left + srcUV_pitch;
+ srcV1 += src_pitch_left + srcUV_pitch;
+ srcV2 += src_pitch_left + srcUV_pitch;
+ dstY1 += dstY_pitch_left + dstY_pitch;
+ dstY2 += dstY_pitch_left + dstY_pitch;
+ dstU += dstUV_pitch_left;
+ dstV += dstUV_pitch_left;
+ }
+
+ /* Last row */
+ if (y == (height - 1)) {
+ for (x = 0; x < (width - 1); x += 2) {
+ *dstY1++ = *srcY1;
+ srcY1 += 2;
+ *dstY1++ = *srcY1;
+ srcY1 += 2;
+
+ *dstU = *srcU1;
+ *dstV = *srcV1;
+
+ srcU1 += 4;
+ srcV1 += 4;
+ dstU += dstUV_pixel_stride;
+ dstV += dstUV_pixel_stride;
+ }
+
+ /* Last column */
+ if (x == (width - 1)) {
+ *dstY1 = *srcY1;
+ *dstU = *srcU1;
+ *dstV = *srcV1;
+ }
+ }
+ return 0;
+}
+
+int
+SDL_ConvertPixels_YUV_to_YUV(int width, int height,
+ Uint32 src_format, const void *src, int src_pitch,
+ Uint32 dst_format, void *dst, int dst_pitch)
+{
+ if (src_format == dst_format) {
+ if (src == dst) {
+ /* Nothing to do */
+ return 0;
+ }
+ return SDL_ConvertPixels_YUV_to_YUV_Copy(width, height, src_format, src, src_pitch, dst, dst_pitch);
+ }
+
+ if (IsPlanar2x2Format(src_format) && IsPlanar2x2Format(dst_format)) {
+ return SDL_ConvertPixels_Planar2x2_to_Planar2x2(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
+ } else if (IsPacked4Format(src_format) && IsPacked4Format(dst_format)) {
+ return SDL_ConvertPixels_Packed4_to_Packed4(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
+ } else if (IsPlanar2x2Format(src_format) && IsPacked4Format(dst_format)) {
+ return SDL_ConvertPixels_Planar2x2_to_Packed4(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
+ } else if (IsPacked4Format(src_format) && IsPlanar2x2Format(dst_format)) {
+ return SDL_ConvertPixels_Packed4_to_Planar2x2(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
+ } else {
+ return SDL_SetError("SDL_ConvertPixels_YUV_to_YUV: Unsupported YUV conversion: %s -> %s", SDL_GetPixelFormatName(src_format), SDL_GetPixelFormatName(dst_format));
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/SDL_yuv_c.h b/src/3rdparty/SDL2/src/video/SDL_yuv_c.h
new file mode 100644
index 0000000..6fe02b0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/SDL_yuv_c.h
@@ -0,0 +1,30 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+
+/* YUV conversion functions */
+
+extern int SDL_ConvertPixels_YUV_to_RGB(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch);
+extern int SDL_ConvertPixels_RGB_to_YUV(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch);
+extern int SDL_ConvertPixels_YUV_to_YUV(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidclipboard.c b/src/3rdparty/SDL2/src/video/android/SDL_androidclipboard.c
new file mode 100644
index 0000000..c913af5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidclipboard.c
@@ -0,0 +1,48 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_ANDROID
+
+#include "SDL_androidvideo.h"
+#include "SDL_androidclipboard.h"
+#include "../../core/android/SDL_android.h"
+
+int
+Android_SetClipboardText(_THIS, const char *text)
+{
+ return Android_JNI_SetClipboardText(text);
+}
+
+char *
+Android_GetClipboardText(_THIS)
+{
+ return Android_JNI_GetClipboardText();
+}
+
+SDL_bool Android_HasClipboardText(_THIS)
+{
+ return Android_JNI_HasClipboardText();
+}
+
+#endif /* SDL_VIDEO_DRIVER_ANDROID */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidclipboard.h b/src/3rdparty/SDL2/src/video/android/SDL_androidclipboard.h
new file mode 100644
index 0000000..7f48b0e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidclipboard.h
@@ -0,0 +1,32 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_androidclipboard_h_
+#define SDL_androidclipboard_h_
+
+extern int Android_SetClipboardText(_THIS, const char *text);
+extern char *Android_GetClipboardText(_THIS);
+extern SDL_bool Android_HasClipboardText(_THIS);
+
+#endif /* SDL_androidclipboard_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidevents.c b/src/3rdparty/SDL2/src/video/android/SDL_androidevents.c
new file mode 100644
index 0000000..6cf9af2
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidevents.c
@@ -0,0 +1,123 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_ANDROID
+
+/* We're going to do this by default */
+#define SDL_ANDROID_BLOCK_ON_PAUSE 1
+
+#include "SDL_androidevents.h"
+#include "SDL_events.h"
+#include "SDL_androidwindow.h"
+
+#if !SDL_AUDIO_DISABLED
+/* Can't include sysaudio "../../audio/android/SDL_androidaudio.h"
+ * because of THIS redefinition */
+extern void ANDROIDAUDIO_ResumeDevices(void);
+extern void ANDROIDAUDIO_PauseDevices(void);
+#else
+static void ANDROIDAUDIO_ResumeDevices(void) {}
+static void ANDROIDAUDIO_PauseDevices(void) {}
+#endif
+
+static void
+android_egl_context_restore()
+{
+ SDL_Event event;
+ SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
+ if (SDL_GL_MakeCurrent(Android_Window, (SDL_GLContext) data->egl_context) < 0) {
+ /* The context is no longer valid, create a new one */
+ data->egl_context = (EGLContext) SDL_GL_CreateContext(Android_Window);
+ SDL_GL_MakeCurrent(Android_Window, (SDL_GLContext) data->egl_context);
+ event.type = SDL_RENDER_DEVICE_RESET;
+ SDL_PushEvent(&event);
+ }
+}
+
+static void
+android_egl_context_backup()
+{
+ /* Keep a copy of the EGL Context so we can try to restore it when we resume */
+ SDL_WindowData *data = (SDL_WindowData *) Android_Window->driverdata;
+ data->egl_context = SDL_GL_GetCurrentContext();
+ /* We need to do this so the EGLSurface can be freed */
+ SDL_GL_MakeCurrent(Android_Window, NULL);
+}
+
+void
+Android_PumpEvents(_THIS)
+{
+ static int isPaused = 0;
+#if SDL_ANDROID_BLOCK_ON_PAUSE
+ static int isPausing = 0;
+#endif
+ /* No polling necessary */
+
+ /*
+ * Android_ResumeSem and Android_PauseSem are signaled from Java_org_libsdl_app_SDLActivity_nativePause and Java_org_libsdl_app_SDLActivity_nativeResume
+ * When the pause semaphore is signaled, if SDL_ANDROID_BLOCK_ON_PAUSE is defined the event loop will block until the resume signal is emitted.
+ */
+
+#if SDL_ANDROID_BLOCK_ON_PAUSE
+ if (isPaused && !isPausing) {
+ /* Make sure this is the last thing we do before pausing */
+ android_egl_context_backup();
+ ANDROIDAUDIO_PauseDevices();
+ if(SDL_SemWait(Android_ResumeSem) == 0) {
+#else
+ if (isPaused) {
+ if(SDL_SemTryWait(Android_ResumeSem) == 0) {
+#endif
+ isPaused = 0;
+ ANDROIDAUDIO_ResumeDevices();
+ /* Restore the GL Context from here, as this operation is thread dependent */
+ if (!SDL_HasEvent(SDL_QUIT)) {
+ android_egl_context_restore();
+ }
+ }
+ }
+ else {
+#if SDL_ANDROID_BLOCK_ON_PAUSE
+ if( isPausing || SDL_SemTryWait(Android_PauseSem) == 0 ) {
+ /* We've been signaled to pause, but before we block ourselves,
+ we need to make sure that certain key events have reached the app */
+ if (SDL_HasEvent(SDL_WINDOWEVENT) || SDL_HasEvent(SDL_APP_WILLENTERBACKGROUND) || SDL_HasEvent(SDL_APP_DIDENTERBACKGROUND) ) {
+ isPausing = 1;
+ }
+ else {
+ isPausing = 0;
+ isPaused = 1;
+ }
+ }
+#else
+ if(SDL_SemTryWait(Android_PauseSem) == 0) {
+ android_egl_context_backup();
+ ANDROIDAUDIO_PauseDevices();
+ isPaused = 1;
+ }
+#endif
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_ANDROID */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidevents.h b/src/3rdparty/SDL2/src/video/android/SDL_androidevents.h
new file mode 100644
index 0000000..00e7427
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidevents.h
@@ -0,0 +1,27 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "SDL_androidvideo.h"
+
+extern void Android_PumpEvents(_THIS);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidgl.c b/src/3rdparty/SDL2/src/video/android/SDL_androidgl.c
new file mode 100644
index 0000000..859b46e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidgl.c
@@ -0,0 +1,62 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_ANDROID
+
+/* Android SDL video driver implementation */
+
+#include "SDL_video.h"
+#include "../SDL_egl_c.h"
+#include "SDL_androidwindow.h"
+
+#include "SDL_androidvideo.h"
+#include "SDL_androidgl.h"
+#include "../../core/android/SDL_android.h"
+
+#include <android/log.h>
+
+#include <dlfcn.h>
+
+SDL_EGL_CreateContext_impl(Android)
+SDL_EGL_MakeCurrent_impl(Android)
+
+int
+Android_GLES_SwapWindow(_THIS, SDL_Window * window)
+{
+ /* The following two calls existed in the original Java code
+ * If you happen to have a device that's affected by their removal,
+ * please report to Bugzilla. -- Gabriel
+ */
+
+ /*_this->egl_data->eglWaitNative(EGL_CORE_NATIVE_ENGINE);
+ _this->egl_data->eglWaitGL();*/
+ return SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
+}
+
+int
+Android_GLES_LoadLibrary(_THIS, const char *path) {
+ return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) 0, 0);
+}
+
+#endif /* SDL_VIDEO_DRIVER_ANDROID */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidgl.h b/src/3rdparty/SDL2/src/video/android/SDL_androidgl.h
new file mode 100644
index 0000000..1dab5a6
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidgl.h
@@ -0,0 +1,34 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_androidgl_h_
+#define SDL_androidgl_h_
+
+SDL_GLContext Android_GLES_CreateContext(_THIS, SDL_Window * window);
+int Android_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+int Android_GLES_SwapWindow(_THIS, SDL_Window * window);
+int Android_GLES_LoadLibrary(_THIS, const char *path);
+
+
+#endif /* SDL_androidgl_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidkeyboard.c b/src/3rdparty/SDL2/src/video/android/SDL_androidkeyboard.c
new file mode 100644
index 0000000..6c94cac
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidkeyboard.c
@@ -0,0 +1,391 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_ANDROID
+
+#include <android/log.h>
+
+#include "../../events/SDL_events_c.h"
+
+#include "SDL_androidkeyboard.h"
+
+#include "../../core/android/SDL_android.h"
+
+void Android_InitKeyboard(void)
+{
+ SDL_Keycode keymap[SDL_NUM_SCANCODES];
+
+ /* Add default scancode to key mapping */
+ SDL_GetDefaultKeymap(keymap);
+ SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
+}
+
+static SDL_Scancode Android_Keycodes[] = {
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_UNKNOWN */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SOFT_LEFT */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SOFT_RIGHT */
+ SDL_SCANCODE_AC_HOME, /* AKEYCODE_HOME */
+ SDL_SCANCODE_AC_BACK, /* AKEYCODE_BACK */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CALL */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ENDCALL */
+ SDL_SCANCODE_0, /* AKEYCODE_0 */
+ SDL_SCANCODE_1, /* AKEYCODE_1 */
+ SDL_SCANCODE_2, /* AKEYCODE_2 */
+ SDL_SCANCODE_3, /* AKEYCODE_3 */
+ SDL_SCANCODE_4, /* AKEYCODE_4 */
+ SDL_SCANCODE_5, /* AKEYCODE_5 */
+ SDL_SCANCODE_6, /* AKEYCODE_6 */
+ SDL_SCANCODE_7, /* AKEYCODE_7 */
+ SDL_SCANCODE_8, /* AKEYCODE_8 */
+ SDL_SCANCODE_9, /* AKEYCODE_9 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STAR */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_POUND */
+ SDL_SCANCODE_UP, /* AKEYCODE_DPAD_UP */
+ SDL_SCANCODE_DOWN, /* AKEYCODE_DPAD_DOWN */
+ SDL_SCANCODE_LEFT, /* AKEYCODE_DPAD_LEFT */
+ SDL_SCANCODE_RIGHT, /* AKEYCODE_DPAD_RIGHT */
+ SDL_SCANCODE_SELECT, /* AKEYCODE_DPAD_CENTER */
+ SDL_SCANCODE_VOLUMEUP, /* AKEYCODE_VOLUME_UP */
+ SDL_SCANCODE_VOLUMEDOWN, /* AKEYCODE_VOLUME_DOWN */
+ SDL_SCANCODE_POWER, /* AKEYCODE_POWER */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CAMERA */
+ SDL_SCANCODE_CLEAR, /* AKEYCODE_CLEAR */
+ SDL_SCANCODE_A, /* AKEYCODE_A */
+ SDL_SCANCODE_B, /* AKEYCODE_B */
+ SDL_SCANCODE_C, /* AKEYCODE_C */
+ SDL_SCANCODE_D, /* AKEYCODE_D */
+ SDL_SCANCODE_E, /* AKEYCODE_E */
+ SDL_SCANCODE_F, /* AKEYCODE_F */
+ SDL_SCANCODE_G, /* AKEYCODE_G */
+ SDL_SCANCODE_H, /* AKEYCODE_H */
+ SDL_SCANCODE_I, /* AKEYCODE_I */
+ SDL_SCANCODE_J, /* AKEYCODE_J */
+ SDL_SCANCODE_K, /* AKEYCODE_K */
+ SDL_SCANCODE_L, /* AKEYCODE_L */
+ SDL_SCANCODE_M, /* AKEYCODE_M */
+ SDL_SCANCODE_N, /* AKEYCODE_N */
+ SDL_SCANCODE_O, /* AKEYCODE_O */
+ SDL_SCANCODE_P, /* AKEYCODE_P */
+ SDL_SCANCODE_Q, /* AKEYCODE_Q */
+ SDL_SCANCODE_R, /* AKEYCODE_R */
+ SDL_SCANCODE_S, /* AKEYCODE_S */
+ SDL_SCANCODE_T, /* AKEYCODE_T */
+ SDL_SCANCODE_U, /* AKEYCODE_U */
+ SDL_SCANCODE_V, /* AKEYCODE_V */
+ SDL_SCANCODE_W, /* AKEYCODE_W */
+ SDL_SCANCODE_X, /* AKEYCODE_X */
+ SDL_SCANCODE_Y, /* AKEYCODE_Y */
+ SDL_SCANCODE_Z, /* AKEYCODE_Z */
+ SDL_SCANCODE_COMMA, /* AKEYCODE_COMMA */
+ SDL_SCANCODE_PERIOD, /* AKEYCODE_PERIOD */
+ SDL_SCANCODE_LALT, /* AKEYCODE_ALT_LEFT */
+ SDL_SCANCODE_RALT, /* AKEYCODE_ALT_RIGHT */
+ SDL_SCANCODE_LSHIFT, /* AKEYCODE_SHIFT_LEFT */
+ SDL_SCANCODE_RSHIFT, /* AKEYCODE_SHIFT_RIGHT */
+ SDL_SCANCODE_TAB, /* AKEYCODE_TAB */
+ SDL_SCANCODE_SPACE, /* AKEYCODE_SPACE */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SYM */
+ SDL_SCANCODE_WWW, /* AKEYCODE_EXPLORER */
+ SDL_SCANCODE_MAIL, /* AKEYCODE_ENVELOPE */
+ SDL_SCANCODE_RETURN, /* AKEYCODE_ENTER */
+ SDL_SCANCODE_BACKSPACE, /* AKEYCODE_DEL */
+ SDL_SCANCODE_GRAVE, /* AKEYCODE_GRAVE */
+ SDL_SCANCODE_MINUS, /* AKEYCODE_MINUS */
+ SDL_SCANCODE_EQUALS, /* AKEYCODE_EQUALS */
+ SDL_SCANCODE_LEFTBRACKET, /* AKEYCODE_LEFT_BRACKET */
+ SDL_SCANCODE_RIGHTBRACKET, /* AKEYCODE_RIGHT_BRACKET */
+ SDL_SCANCODE_BACKSLASH, /* AKEYCODE_BACKSLASH */
+ SDL_SCANCODE_SEMICOLON, /* AKEYCODE_SEMICOLON */
+ SDL_SCANCODE_APOSTROPHE, /* AKEYCODE_APOSTROPHE */
+ SDL_SCANCODE_SLASH, /* AKEYCODE_SLASH */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_AT */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NUM */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_HEADSETHOOK */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_FOCUS */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PLUS */
+ SDL_SCANCODE_MENU, /* AKEYCODE_MENU */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NOTIFICATION */
+ SDL_SCANCODE_AC_SEARCH, /* AKEYCODE_SEARCH */
+ SDL_SCANCODE_AUDIOPLAY, /* AKEYCODE_MEDIA_PLAY_PAUSE */
+ SDL_SCANCODE_AUDIOSTOP, /* AKEYCODE_MEDIA_STOP */
+ SDL_SCANCODE_AUDIONEXT, /* AKEYCODE_MEDIA_NEXT */
+ SDL_SCANCODE_AUDIOPREV, /* AKEYCODE_MEDIA_PREVIOUS */
+ SDL_SCANCODE_AUDIOREWIND, /* AKEYCODE_MEDIA_REWIND */
+ SDL_SCANCODE_AUDIOFASTFORWARD, /* AKEYCODE_MEDIA_FAST_FORWARD */
+ SDL_SCANCODE_MUTE, /* AKEYCODE_MUTE */
+ SDL_SCANCODE_PAGEUP, /* AKEYCODE_PAGE_UP */
+ SDL_SCANCODE_PAGEDOWN, /* AKEYCODE_PAGE_DOWN */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PICTSYMBOLS */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SWITCH_CHARSET */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_A */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_B */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_C */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_X */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_Y */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_Z */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_L1 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_R1 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_L2 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_R2 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_THUMBL */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_THUMBR */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_START */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_SELECT */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_MODE */
+ SDL_SCANCODE_ESCAPE, /* AKEYCODE_ESCAPE */
+ SDL_SCANCODE_DELETE, /* AKEYCODE_FORWARD_DEL */
+ SDL_SCANCODE_LCTRL, /* AKEYCODE_CTRL_LEFT */
+ SDL_SCANCODE_RCTRL, /* AKEYCODE_CTRL_RIGHT */
+ SDL_SCANCODE_CAPSLOCK, /* AKEYCODE_CAPS_LOCK */
+ SDL_SCANCODE_SCROLLLOCK, /* AKEYCODE_SCROLL_LOCK */
+ SDL_SCANCODE_LGUI, /* AKEYCODE_META_LEFT */
+ SDL_SCANCODE_RGUI, /* AKEYCODE_META_RIGHT */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_FUNCTION */
+ SDL_SCANCODE_PRINTSCREEN, /* AKEYCODE_SYSRQ */
+ SDL_SCANCODE_PAUSE, /* AKEYCODE_BREAK */
+ SDL_SCANCODE_HOME, /* AKEYCODE_MOVE_HOME */
+ SDL_SCANCODE_END, /* AKEYCODE_MOVE_END */
+ SDL_SCANCODE_INSERT, /* AKEYCODE_INSERT */
+ SDL_SCANCODE_AC_FORWARD, /* AKEYCODE_FORWARD */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_PLAY */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_PAUSE */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_CLOSE */
+ SDL_SCANCODE_EJECT, /* AKEYCODE_MEDIA_EJECT */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_RECORD */
+ SDL_SCANCODE_F1, /* AKEYCODE_F1 */
+ SDL_SCANCODE_F2, /* AKEYCODE_F2 */
+ SDL_SCANCODE_F3, /* AKEYCODE_F3 */
+ SDL_SCANCODE_F4, /* AKEYCODE_F4 */
+ SDL_SCANCODE_F5, /* AKEYCODE_F5 */
+ SDL_SCANCODE_F6, /* AKEYCODE_F6 */
+ SDL_SCANCODE_F7, /* AKEYCODE_F7 */
+ SDL_SCANCODE_F8, /* AKEYCODE_F8 */
+ SDL_SCANCODE_F9, /* AKEYCODE_F9 */
+ SDL_SCANCODE_F10, /* AKEYCODE_F10 */
+ SDL_SCANCODE_F11, /* AKEYCODE_F11 */
+ SDL_SCANCODE_F12, /* AKEYCODE_F12 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NUM_LOCK */
+ SDL_SCANCODE_KP_0, /* AKEYCODE_NUMPAD_0 */
+ SDL_SCANCODE_KP_1, /* AKEYCODE_NUMPAD_1 */
+ SDL_SCANCODE_KP_2, /* AKEYCODE_NUMPAD_2 */
+ SDL_SCANCODE_KP_3, /* AKEYCODE_NUMPAD_3 */
+ SDL_SCANCODE_KP_4, /* AKEYCODE_NUMPAD_4 */
+ SDL_SCANCODE_KP_5, /* AKEYCODE_NUMPAD_5 */
+ SDL_SCANCODE_KP_6, /* AKEYCODE_NUMPAD_6 */
+ SDL_SCANCODE_KP_7, /* AKEYCODE_NUMPAD_7 */
+ SDL_SCANCODE_KP_8, /* AKEYCODE_NUMPAD_8 */
+ SDL_SCANCODE_KP_9, /* AKEYCODE_NUMPAD_9 */
+ SDL_SCANCODE_KP_DIVIDE, /* AKEYCODE_NUMPAD_DIVIDE */
+ SDL_SCANCODE_KP_MULTIPLY, /* AKEYCODE_NUMPAD_MULTIPLY */
+ SDL_SCANCODE_KP_MINUS, /* AKEYCODE_NUMPAD_SUBTRACT */
+ SDL_SCANCODE_KP_PLUS, /* AKEYCODE_NUMPAD_ADD */
+ SDL_SCANCODE_KP_PERIOD, /* AKEYCODE_NUMPAD_DOT */
+ SDL_SCANCODE_KP_COMMA, /* AKEYCODE_NUMPAD_COMMA */
+ SDL_SCANCODE_KP_ENTER, /* AKEYCODE_NUMPAD_ENTER */
+ SDL_SCANCODE_KP_EQUALS, /* AKEYCODE_NUMPAD_EQUALS */
+ SDL_SCANCODE_KP_LEFTPAREN, /* AKEYCODE_NUMPAD_LEFT_PAREN */
+ SDL_SCANCODE_KP_RIGHTPAREN, /* AKEYCODE_NUMPAD_RIGHT_PAREN */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_VOLUME_MUTE */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_INFO */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CHANNEL_UP */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CHANNEL_DOWN */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ZOOM_IN */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ZOOM_OUT */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_WINDOW */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_GUIDE */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DVR */
+ SDL_SCANCODE_AC_BOOKMARKS, /* AKEYCODE_BOOKMARK */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CAPTIONS */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SETTINGS */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_POWER */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STB_POWER */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STB_INPUT */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_AVR_POWER */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_AVR_INPUT */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PROG_RED */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PROG_GREEN */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PROG_YELLOW */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PROG_BLUE */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_APP_SWITCH */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_1 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_2 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_3 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_4 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_5 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_6 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_7 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_8 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_9 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_10 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_11 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_12 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_13 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_14 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_15 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_BUTTON_16 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_LANGUAGE_SWITCH */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MANNER_MODE */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_3D_MODE */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CONTACTS */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_CALENDAR */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MUSIC */
+ SDL_SCANCODE_CALCULATOR, /* AKEYCODE_CALCULATOR */
+ SDL_SCANCODE_LANG5, /* AKEYCODE_ZENKAKU_HANKAKU */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_EISU */
+ SDL_SCANCODE_INTERNATIONAL5, /* AKEYCODE_MUHENKAN */
+ SDL_SCANCODE_INTERNATIONAL4, /* AKEYCODE_HENKAN */
+ SDL_SCANCODE_LANG3, /* AKEYCODE_KATAKANA_HIRAGANA */
+ SDL_SCANCODE_INTERNATIONAL3, /* AKEYCODE_YEN */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_RO */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_KANA */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ASSIST */
+ SDL_SCANCODE_BRIGHTNESSDOWN, /* AKEYCODE_BRIGHTNESS_DOWN */
+ SDL_SCANCODE_BRIGHTNESSUP, /* AKEYCODE_BRIGHTNESS_UP */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_AUDIO_TRACK */
+ SDL_SCANCODE_SLEEP, /* AKEYCODE_SLEEP */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_WAKEUP */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_PAIRING */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_TOP_MENU */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_11 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_12 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_LAST_CHANNEL */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_DATA_SERVICE */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_VOICE_ASSIST */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_RADIO_SERVICE */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_TELETEXT */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_NUMBER_ENTRY */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_TERRESTRIAL_ANALOG */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_TERRESTRIAL_DIGITAL */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_SATELLITE */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_SATELLITE_BS */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_SATELLITE_CS */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_SATELLITE_SERVICE */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_NETWORK */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_ANTENNA_CABLE */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_HDMI_1 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_HDMI_2 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_HDMI_3 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_HDMI_4 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_COMPOSITE_1 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_COMPOSITE_2 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_COMPONENT_1 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_COMPONENT_2 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_INPUT_VGA_1 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_AUDIO_DESCRIPTION */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_UP */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_ZOOM_MODE */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_CONTENTS_MENU */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_MEDIA_CONTEXT_MENU */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_TV_TIMER_PROGRAMMING */
+ SDL_SCANCODE_HELP, /* AKEYCODE_HELP */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NAVIGATE_PREVIOUS */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NAVIGATE_NEXT */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NAVIGATE_IN */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_NAVIGATE_OUT */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STEM_PRIMARY */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STEM_1 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STEM_2 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_STEM_3 */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DPAD_UP_LEFT */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DPAD_DOWN_LEFT */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DPAD_UP_RIGHT */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_DPAD_DOWN_RIGHT */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_SKIP_FORWARD */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_SKIP_BACKWARD */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_STEP_FORWARD */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_STEP_BACKWARD */
+ SDL_SCANCODE_UNKNOWN, /* AKEYCODE_SOFT_SLEEP */
+ SDL_SCANCODE_CUT, /* AKEYCODE_CUT */
+ SDL_SCANCODE_COPY, /* AKEYCODE_COPY */
+ SDL_SCANCODE_PASTE, /* AKEYCODE_PASTE */
+};
+
+static SDL_Scancode
+TranslateKeycode(int keycode)
+{
+ SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
+
+ if (keycode < SDL_arraysize(Android_Keycodes)) {
+ scancode = Android_Keycodes[keycode];
+ }
+ if (scancode == SDL_SCANCODE_UNKNOWN) {
+ __android_log_print(ANDROID_LOG_INFO, "SDL", "Unknown keycode %d", keycode);
+ }
+ return scancode;
+}
+
+int
+Android_OnKeyDown(int keycode)
+{
+ return SDL_SendKeyboardKey(SDL_PRESSED, TranslateKeycode(keycode));
+}
+
+int
+Android_OnKeyUp(int keycode)
+{
+ return SDL_SendKeyboardKey(SDL_RELEASED, TranslateKeycode(keycode));
+}
+
+SDL_bool
+Android_HasScreenKeyboardSupport(_THIS)
+{
+ return SDL_TRUE;
+}
+
+SDL_bool
+Android_IsScreenKeyboardShown(_THIS, SDL_Window * window)
+{
+ return Android_JNI_IsScreenKeyboardShown();
+}
+
+void
+Android_StartTextInput(_THIS)
+{
+ SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
+ Android_JNI_ShowTextInput(&videodata->textRect);
+}
+
+void
+Android_StopTextInput(_THIS)
+{
+ Android_JNI_HideTextInput();
+}
+
+void
+Android_SetTextInputRect(_THIS, SDL_Rect *rect)
+{
+ SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
+
+ if (!rect) {
+ SDL_InvalidParamError("rect");
+ return;
+ }
+
+ videodata->textRect = *rect;
+}
+
+#endif /* SDL_VIDEO_DRIVER_ANDROID */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidkeyboard.h b/src/3rdparty/SDL2/src/video/android/SDL_androidkeyboard.h
new file mode 100644
index 0000000..a1a10f5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidkeyboard.h
@@ -0,0 +1,36 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "SDL_androidvideo.h"
+
+extern void Android_InitKeyboard(void);
+extern int Android_OnKeyDown(int keycode);
+extern int Android_OnKeyUp(int keycode);
+
+extern SDL_bool Android_HasScreenKeyboardSupport(_THIS);
+extern SDL_bool Android_IsScreenKeyboardShown(_THIS, SDL_Window * window);
+
+extern void Android_StartTextInput(_THIS);
+extern void Android_StopTextInput(_THIS);
+extern void Android_SetTextInputRect(_THIS, SDL_Rect *rect);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidmessagebox.c b/src/3rdparty/SDL2/src/video/android/SDL_androidmessagebox.c
new file mode 100644
index 0000000..1716024
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidmessagebox.c
@@ -0,0 +1,37 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_ANDROID
+
+#include "SDL_messagebox.h"
+#include "SDL_androidmessagebox.h"
+#include "../../core/android/SDL_android.h"
+
+int
+Android_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
+{
+ return Android_JNI_ShowMessageBox(messageboxdata, buttonid);
+}
+
+#endif /* SDL_VIDEO_DRIVER_ANDROID */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidmessagebox.h b/src/3rdparty/SDL2/src/video/android/SDL_androidmessagebox.h
new file mode 100644
index 0000000..2c3a44f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidmessagebox.h
@@ -0,0 +1,29 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_ANDROID
+
+extern int Android_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
+
+#endif /* SDL_VIDEO_DRIVER_ANDROID */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidmouse.c b/src/3rdparty/SDL2/src/video/android/SDL_androidmouse.c
new file mode 100644
index 0000000..1c075fb
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidmouse.c
@@ -0,0 +1,117 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_ANDROID
+
+#include "SDL_androidmouse.h"
+
+#include "SDL_events.h"
+#include "../../events/SDL_mouse_c.h"
+
+#include "../../core/android/SDL_android.h"
+
+/* See Android's MotionEvent class for constants */
+#define ACTION_DOWN 0
+#define ACTION_UP 1
+#define ACTION_MOVE 2
+#define ACTION_HOVER_MOVE 7
+#define ACTION_SCROLL 8
+#define BUTTON_PRIMARY 1
+#define BUTTON_SECONDARY 2
+#define BUTTON_TERTIARY 4
+#define BUTTON_BACK 8
+#define BUTTON_FORWARD 16
+
+/* Last known Android mouse button state (includes all buttons) */
+static int last_state;
+
+void
+Android_InitMouse(void)
+{
+ last_state = 0;
+}
+
+/* Translate Android mouse button state to SDL mouse button */
+static Uint8
+TranslateButton(int state)
+{
+ if (state & BUTTON_PRIMARY) {
+ return SDL_BUTTON_LEFT;
+ } else if (state & BUTTON_SECONDARY) {
+ return SDL_BUTTON_RIGHT;
+ } else if (state & BUTTON_TERTIARY) {
+ return SDL_BUTTON_MIDDLE;
+ } else if (state & BUTTON_FORWARD) {
+ return SDL_BUTTON_X1;
+ } else if (state & BUTTON_BACK) {
+ return SDL_BUTTON_X2;
+ } else {
+ return 0;
+ }
+}
+
+void
+Android_OnMouse(int state, int action, float x, float y)
+{
+ int changes;
+ Uint8 button;
+
+ if (!Android_Window) {
+ return;
+ }
+
+ switch(action) {
+ case ACTION_DOWN:
+ changes = state & ~last_state;
+ button = TranslateButton(changes);
+ last_state = state;
+ SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
+ SDL_SendMouseButton(Android_Window, 0, SDL_PRESSED, button);
+ break;
+
+ case ACTION_UP:
+ changes = last_state & ~state;
+ button = TranslateButton(changes);
+ last_state = state;
+ SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
+ SDL_SendMouseButton(Android_Window, 0, SDL_RELEASED, button);
+ break;
+
+ case ACTION_MOVE:
+ case ACTION_HOVER_MOVE:
+ SDL_SendMouseMotion(Android_Window, 0, 0, x, y);
+ break;
+
+ case ACTION_SCROLL:
+ SDL_SendMouseWheel(Android_Window, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
+ break;
+
+ default:
+ break;
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_ANDROID */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidmouse.h b/src/3rdparty/SDL2/src/video/android/SDL_androidmouse.h
new file mode 100644
index 0000000..f201fad
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidmouse.h
@@ -0,0 +1,32 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_androidmouse_h_
+#define SDL_androidmouse_h_
+
+#include "SDL_androidvideo.h"
+
+extern void Android_InitMouse(void);
+extern void Android_OnMouse( int button, int action, float x, float y);
+
+#endif /* SDL_androidmouse_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidtouch.c b/src/3rdparty/SDL2/src/video/android/SDL_androidtouch.c
new file mode 100644
index 0000000..5c3e4aa
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidtouch.c
@@ -0,0 +1,151 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_ANDROID
+
+#include <android/log.h>
+
+#include "SDL_hints.h"
+#include "SDL_events.h"
+#include "SDL_log.h"
+#include "SDL_androidtouch.h"
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_touch_c.h"
+#include "../../core/android/SDL_android.h"
+
+#define ACTION_DOWN 0
+#define ACTION_UP 1
+#define ACTION_MOVE 2
+#define ACTION_CANCEL 3
+#define ACTION_OUTSIDE 4
+#define ACTION_POINTER_DOWN 5
+#define ACTION_POINTER_UP 6
+
+static void Android_GetWindowCoordinates(float x, float y,
+ int *window_x, int *window_y)
+{
+ int window_w, window_h;
+
+ SDL_GetWindowSize(Android_Window, &window_w, &window_h);
+ *window_x = (int)(x * window_w);
+ *window_y = (int)(y * window_h);
+}
+
+static SDL_bool separate_mouse_and_touch = SDL_FALSE;
+
+static void SDLCALL
+SeparateEventsHintWatcher(void *userdata, const char *name,
+ const char *oldValue, const char *newValue)
+{
+ separate_mouse_and_touch = (newValue && (SDL_strcmp(newValue, "1") == 0));
+
+ Android_JNI_SetSeparateMouseAndTouch(separate_mouse_and_touch);
+}
+
+void Android_InitTouch(void)
+{
+ int i;
+ int* ids;
+ const int number = Android_JNI_GetTouchDeviceIds(&ids);
+
+ SDL_AddHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH,
+ SeparateEventsHintWatcher, NULL);
+
+ if (0 < number) {
+ for (i = 0; i < number; ++i) {
+ SDL_AddTouch((SDL_TouchID) ids[i], ""); /* no error handling */
+ }
+ SDL_free(ids);
+ }
+}
+
+void Android_QuitTouch(void)
+{
+ SDL_DelHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH,
+ SeparateEventsHintWatcher, NULL);
+ separate_mouse_and_touch = SDL_FALSE;
+}
+
+void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
+{
+ SDL_TouchID touchDeviceId = 0;
+ SDL_FingerID fingerId = 0;
+ int window_x, window_y;
+ static SDL_FingerID pointerFingerID = 0;
+
+ if (!Android_Window) {
+ return;
+ }
+
+ touchDeviceId = (SDL_TouchID)touch_device_id_in;
+ if (SDL_AddTouch(touchDeviceId, "") < 0) {
+ SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__);
+ }
+
+ fingerId = (SDL_FingerID)pointer_finger_id_in;
+ switch (action) {
+ case ACTION_DOWN:
+ /* Primary pointer down */
+ if (!separate_mouse_and_touch) {
+ Android_GetWindowCoordinates(x, y, &window_x, &window_y);
+ /* send moved event */
+ SDL_SendMouseMotion(Android_Window, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
+ /* send mouse down event */
+ SDL_SendMouseButton(Android_Window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
+ }
+ pointerFingerID = fingerId;
+ case ACTION_POINTER_DOWN:
+ /* Non primary pointer down */
+ SDL_SendTouch(touchDeviceId, fingerId, SDL_TRUE, x, y, p);
+ break;
+
+ case ACTION_MOVE:
+ if (!pointerFingerID) {
+ if (!separate_mouse_and_touch) {
+ Android_GetWindowCoordinates(x, y, &window_x, &window_y);
+ /* send moved event */
+ SDL_SendMouseMotion(Android_Window, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
+ }
+ }
+ SDL_SendTouchMotion(touchDeviceId, fingerId, x, y, p);
+ break;
+
+ case ACTION_UP:
+ /* Primary pointer up */
+ if (!separate_mouse_and_touch) {
+ /* send mouse up */
+ SDL_SendMouseButton(Android_Window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
+ }
+ pointerFingerID = (SDL_FingerID) 0;
+ case ACTION_POINTER_UP:
+ /* Non primary pointer up */
+ SDL_SendTouch(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
+ break;
+
+ default:
+ break;
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_ANDROID */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidtouch.h b/src/3rdparty/SDL2/src/video/android/SDL_androidtouch.h
new file mode 100644
index 0000000..e10be4f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidtouch.h
@@ -0,0 +1,29 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "SDL_androidvideo.h"
+
+extern void Android_InitTouch(void);
+extern void Android_QuitTouch(void);
+extern void Android_OnTouch( int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidvideo.c b/src/3rdparty/SDL2/src/video/android/SDL_androidvideo.c
new file mode 100644
index 0000000..357f5cf
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidvideo.c
@@ -0,0 +1,254 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_ANDROID
+
+/* Android SDL video driver implementation
+*/
+
+#include "SDL_video.h"
+#include "SDL_mouse.h"
+#include "../SDL_sysvideo.h"
+#include "../SDL_pixels_c.h"
+#include "../../events/SDL_events_c.h"
+#include "../../events/SDL_windowevents_c.h"
+
+#include "SDL_androidvideo.h"
+#include "SDL_androidgl.h"
+#include "SDL_androidclipboard.h"
+#include "SDL_androidevents.h"
+#include "SDL_androidkeyboard.h"
+#include "SDL_androidmouse.h"
+#include "SDL_androidtouch.h"
+#include "SDL_androidwindow.h"
+#include "SDL_androidvulkan.h"
+
+#define ANDROID_VID_DRIVER_NAME "Android"
+
+/* Initialization/Query functions */
+static int Android_VideoInit(_THIS);
+static void Android_VideoQuit(_THIS);
+int Android_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi);
+
+#include "../SDL_egl_c.h"
+#define Android_GLES_GetProcAddress SDL_EGL_GetProcAddress
+#define Android_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
+#define Android_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
+#define Android_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
+#define Android_GLES_DeleteContext SDL_EGL_DeleteContext
+
+/* Android driver bootstrap functions */
+
+
+/* These are filled in with real values in Android_SetScreenResolution on init (before SDL_main()) */
+int Android_ScreenWidth = 0;
+int Android_ScreenHeight = 0;
+Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
+static int Android_ScreenRate = 0;
+
+SDL_sem *Android_PauseSem = NULL, *Android_ResumeSem = NULL;
+
+/* Currently only one window */
+SDL_Window *Android_Window = NULL;
+
+static int
+Android_Available(void)
+{
+ return 1;
+}
+
+static void
+Android_SuspendScreenSaver(_THIS)
+{
+ Android_JNI_SuspendScreenSaver(_this->suspend_screensaver);
+}
+
+static void
+Android_DeleteDevice(SDL_VideoDevice * device)
+{
+ SDL_free(device->driverdata);
+ SDL_free(device);
+}
+
+static SDL_VideoDevice *
+Android_CreateDevice(int devindex)
+{
+ SDL_VideoDevice *device;
+ SDL_VideoData *data;
+
+ /* Initialize all variables that we clean on shutdown */
+ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (!device) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ data = (SDL_VideoData*) SDL_calloc(1, sizeof(SDL_VideoData));
+ if (!data) {
+ SDL_OutOfMemory();
+ SDL_free(device);
+ return NULL;
+ }
+
+ device->driverdata = data;
+
+ /* Set the function pointers */
+ device->VideoInit = Android_VideoInit;
+ device->VideoQuit = Android_VideoQuit;
+ device->PumpEvents = Android_PumpEvents;
+
+ device->GetDisplayDPI = Android_GetDisplayDPI;
+
+ device->CreateSDLWindow = Android_CreateWindow;
+ device->SetWindowTitle = Android_SetWindowTitle;
+ device->SetWindowFullscreen = Android_SetWindowFullscreen;
+ device->DestroyWindow = Android_DestroyWindow;
+ device->GetWindowWMInfo = Android_GetWindowWMInfo;
+
+ device->free = Android_DeleteDevice;
+
+ /* GL pointers */
+ device->GL_LoadLibrary = Android_GLES_LoadLibrary;
+ device->GL_GetProcAddress = Android_GLES_GetProcAddress;
+ device->GL_UnloadLibrary = Android_GLES_UnloadLibrary;
+ device->GL_CreateContext = Android_GLES_CreateContext;
+ device->GL_MakeCurrent = Android_GLES_MakeCurrent;
+ device->GL_SetSwapInterval = Android_GLES_SetSwapInterval;
+ device->GL_GetSwapInterval = Android_GLES_GetSwapInterval;
+ device->GL_SwapWindow = Android_GLES_SwapWindow;
+ device->GL_DeleteContext = Android_GLES_DeleteContext;
+
+#if SDL_VIDEO_VULKAN
+ device->Vulkan_LoadLibrary = Android_Vulkan_LoadLibrary;
+ device->Vulkan_UnloadLibrary = Android_Vulkan_UnloadLibrary;
+ device->Vulkan_GetInstanceExtensions = Android_Vulkan_GetInstanceExtensions;
+ device->Vulkan_CreateSurface = Android_Vulkan_CreateSurface;
+#endif
+
+ /* Screensaver */
+ device->SuspendScreenSaver = Android_SuspendScreenSaver;
+
+ /* Text input */
+ device->StartTextInput = Android_StartTextInput;
+ device->StopTextInput = Android_StopTextInput;
+ device->SetTextInputRect = Android_SetTextInputRect;
+
+ /* Screen keyboard */
+ device->HasScreenKeyboardSupport = Android_HasScreenKeyboardSupport;
+ device->IsScreenKeyboardShown = Android_IsScreenKeyboardShown;
+
+ /* Clipboard */
+ device->SetClipboardText = Android_SetClipboardText;
+ device->GetClipboardText = Android_GetClipboardText;
+ device->HasClipboardText = Android_HasClipboardText;
+
+ return device;
+}
+
+VideoBootStrap Android_bootstrap = {
+ ANDROID_VID_DRIVER_NAME, "SDL Android video driver",
+ Android_Available, Android_CreateDevice
+};
+
+
+int
+Android_VideoInit(_THIS)
+{
+ SDL_DisplayMode mode;
+
+ mode.format = Android_ScreenFormat;
+ mode.w = Android_ScreenWidth;
+ mode.h = Android_ScreenHeight;
+ mode.refresh_rate = Android_ScreenRate;
+ mode.driverdata = NULL;
+ if (SDL_AddBasicVideoDisplay(&mode) < 0) {
+ return -1;
+ }
+
+ SDL_AddDisplayMode(&_this->displays[0], &mode);
+
+ Android_InitKeyboard();
+
+ Android_InitTouch();
+
+ Android_InitMouse();
+
+ /* We're done! */
+ return 0;
+}
+
+void
+Android_VideoQuit(_THIS)
+{
+ Android_QuitTouch();
+}
+
+int
+Android_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi)
+{
+ return Android_JNI_GetDisplayDPI(ddpi, hdpi, vdpi);
+}
+
+void
+Android_SetScreenResolution(int width, int height, Uint32 format, float rate)
+{
+ SDL_VideoDevice* device;
+ SDL_VideoDisplay *display;
+ Android_ScreenWidth = width;
+ Android_ScreenHeight = height;
+ Android_ScreenFormat = format;
+ Android_ScreenRate = rate;
+
+ /*
+ Update the resolution of the desktop mode, so that the window
+ can be properly resized. The screen resolution change can for
+ example happen when the Activity enters or exits immersive mode,
+ which can happen after VideoInit().
+ */
+ device = SDL_GetVideoDevice();
+ if (device && device->num_displays > 0)
+ {
+ display = &device->displays[0];
+ display->desktop_mode.format = Android_ScreenFormat;
+ display->desktop_mode.w = Android_ScreenWidth;
+ display->desktop_mode.h = Android_ScreenHeight;
+ display->desktop_mode.refresh_rate = Android_ScreenRate;
+ }
+
+ if (Android_Window) {
+ /* Force the current mode to match the resize otherwise the SDL_WINDOWEVENT_RESTORED event
+ * will fall back to the old mode */
+ display = SDL_GetDisplayForWindow(Android_Window);
+
+ display->display_modes[0].format = format;
+ display->display_modes[0].w = width;
+ display->display_modes[0].h = height;
+ display->display_modes[0].refresh_rate = rate;
+ display->current_mode = display->display_modes[0];
+
+ SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESIZED, width, height);
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_ANDROID */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidvideo.h b/src/3rdparty/SDL2/src/video/android/SDL_androidvideo.h
new file mode 100644
index 0000000..a62c983
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidvideo.h
@@ -0,0 +1,49 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_androidvideo_h_
+#define SDL_androidvideo_h_
+
+#include "SDL_mutex.h"
+#include "SDL_rect.h"
+#include "../SDL_sysvideo.h"
+
+/* Called by the JNI layer when the screen changes size or format */
+extern void Android_SetScreenResolution(int width, int height, Uint32 format, float rate);
+
+/* Private display data */
+
+typedef struct SDL_VideoData
+{
+ SDL_Rect textRect;
+} SDL_VideoData;
+
+extern int Android_ScreenWidth;
+extern int Android_ScreenHeight;
+extern Uint32 Android_ScreenFormat;
+extern SDL_sem *Android_PauseSem, *Android_ResumeSem;
+extern SDL_Window *Android_Window;
+
+
+#endif /* SDL_androidvideo_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidvulkan.c b/src/3rdparty/SDL2/src/video/android/SDL_androidvulkan.c
new file mode 100644
index 0000000..e013034
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidvulkan.c
@@ -0,0 +1,175 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ * @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's
+ * SDL_x11vulkan.c.
+ */
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_ANDROID
+
+#include "SDL_androidvideo.h"
+#include "SDL_androidwindow.h"
+#include "SDL_assert.h"
+
+#include "SDL_loadso.h"
+#include "SDL_androidvulkan.h"
+#include "SDL_syswm.h"
+
+int Android_Vulkan_LoadLibrary(_THIS, const char *path)
+{
+ VkExtensionProperties *extensions = NULL;
+ Uint32 i, extensionCount = 0;
+ SDL_bool hasSurfaceExtension = SDL_FALSE;
+ SDL_bool hasAndroidSurfaceExtension = SDL_FALSE;
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
+ if(_this->vulkan_config.loader_handle)
+ return SDL_SetError("Vulkan already loaded");
+
+ /* Load the Vulkan loader library */
+ if(!path)
+ path = SDL_getenv("SDL_VULKAN_LIBRARY");
+ if(!path)
+ path = "libvulkan.so";
+ _this->vulkan_config.loader_handle = SDL_LoadObject(path);
+ if(!_this->vulkan_config.loader_handle)
+ return -1;
+ SDL_strlcpy(_this->vulkan_config.loader_path, path,
+ SDL_arraysize(_this->vulkan_config.loader_path));
+ vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction(
+ _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr");
+ if(!vkGetInstanceProcAddr)
+ goto fail;
+ _this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr;
+ _this->vulkan_config.vkEnumerateInstanceExtensionProperties =
+ (void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)(
+ VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties");
+ if(!_this->vulkan_config.vkEnumerateInstanceExtensionProperties)
+ goto fail;
+ extensions = SDL_Vulkan_CreateInstanceExtensionsList(
+ (PFN_vkEnumerateInstanceExtensionProperties)
+ _this->vulkan_config.vkEnumerateInstanceExtensionProperties,
+ &extensionCount);
+ if(!extensions)
+ goto fail;
+ for(i = 0; i < extensionCount; i++)
+ {
+ if(SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
+ hasSurfaceExtension = SDL_TRUE;
+ else if(SDL_strcmp(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
+ hasAndroidSurfaceExtension = SDL_TRUE;
+ }
+ SDL_free(extensions);
+ if(!hasSurfaceExtension)
+ {
+ SDL_SetError("Installed Vulkan doesn't implement the "
+ VK_KHR_SURFACE_EXTENSION_NAME " extension");
+ goto fail;
+ }
+ else if(!hasAndroidSurfaceExtension)
+ {
+ SDL_SetError("Installed Vulkan doesn't implement the "
+ VK_KHR_ANDROID_SURFACE_EXTENSION_NAME "extension");
+ goto fail;
+ }
+ return 0;
+
+fail:
+ SDL_UnloadObject(_this->vulkan_config.loader_handle);
+ _this->vulkan_config.loader_handle = NULL;
+ return -1;
+}
+
+void Android_Vulkan_UnloadLibrary(_THIS)
+{
+ if(_this->vulkan_config.loader_handle)
+ {
+ SDL_UnloadObject(_this->vulkan_config.loader_handle);
+ _this->vulkan_config.loader_handle = NULL;
+ }
+}
+
+SDL_bool Android_Vulkan_GetInstanceExtensions(_THIS,
+ SDL_Window *window,
+ unsigned *count,
+ const char **names)
+{
+ static const char *const extensionsForAndroid[] = {
+ VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_ANDROID_SURFACE_EXTENSION_NAME
+ };
+ if(!_this->vulkan_config.loader_handle)
+ {
+ SDL_SetError("Vulkan is not loaded");
+ return SDL_FALSE;
+ }
+ return SDL_Vulkan_GetInstanceExtensions_Helper(
+ count, names, SDL_arraysize(extensionsForAndroid),
+ extensionsForAndroid);
+}
+
+SDL_bool Android_Vulkan_CreateSurface(_THIS,
+ SDL_Window *window,
+ VkInstance instance,
+ VkSurfaceKHR *surface)
+{
+ SDL_WindowData *windowData = (SDL_WindowData *)window->driverdata;
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
+ (PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr;
+ PFN_vkCreateAndroidSurfaceKHR vkCreateAndroidSurfaceKHR =
+ (PFN_vkCreateAndroidSurfaceKHR)vkGetInstanceProcAddr(
+ (VkInstance)instance,
+ "vkCreateAndroidSurfaceKHR");
+ VkAndroidSurfaceCreateInfoKHR createInfo;
+ VkResult result;
+
+ if(!_this->vulkan_config.loader_handle)
+ {
+ SDL_SetError("Vulkan is not loaded");
+ return SDL_FALSE;
+ }
+
+ if(!vkCreateAndroidSurfaceKHR)
+ {
+ SDL_SetError(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME
+ " extension is not enabled in the Vulkan instance.");
+ return SDL_FALSE;
+ }
+ SDL_zero(createInfo);
+ createInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
+ createInfo.pNext = NULL;
+ createInfo.flags = 0;
+ createInfo.window = windowData->native_window;
+ result = vkCreateAndroidSurfaceKHR(instance, &createInfo,
+ NULL, surface);
+ if(result != VK_SUCCESS)
+ {
+ SDL_SetError("vkCreateAndroidSurfaceKHR failed: %s",
+ SDL_Vulkan_GetResultString(result));
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
+}
+
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidvulkan.h b/src/3rdparty/SDL2/src/video/android/SDL_androidvulkan.h
new file mode 100644
index 0000000..2634c61
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidvulkan.h
@@ -0,0 +1,52 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ * @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's
+ * SDL_x11vulkan.h.
+ */
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_androidvulkan_h_
+#define SDL_androidvulkan_h_
+
+#include "../SDL_vulkan_internal.h"
+#include "../SDL_sysvideo.h"
+
+#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_ANDROID
+
+int Android_Vulkan_LoadLibrary(_THIS, const char *path);
+void Android_Vulkan_UnloadLibrary(_THIS);
+SDL_bool Android_Vulkan_GetInstanceExtensions(_THIS,
+ SDL_Window *window,
+ unsigned *count,
+ const char **names);
+SDL_bool Android_Vulkan_CreateSurface(_THIS,
+ SDL_Window *window,
+ VkInstance instance,
+ VkSurfaceKHR *surface);
+
+#endif
+
+#endif /* SDL_androidvulkan_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidwindow.c b/src/3rdparty/SDL2/src/video/android/SDL_androidwindow.c
new file mode 100644
index 0000000..f1cbf58
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidwindow.c
@@ -0,0 +1,152 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_ANDROID
+
+#include "SDL_syswm.h"
+#include "../SDL_sysvideo.h"
+#include "../../events/SDL_keyboard_c.h"
+#include "../../events/SDL_mouse_c.h"
+
+#include "SDL_androidvideo.h"
+#include "SDL_androidwindow.h"
+#include "SDL_hints.h"
+
+int
+Android_CreateWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data;
+
+ if (Android_Window) {
+ return SDL_SetError("Android only supports one window");
+ }
+
+ Android_PauseSem = SDL_CreateSemaphore(0);
+ Android_ResumeSem = SDL_CreateSemaphore(0);
+
+ /* Set orientation */
+ Android_JNI_SetOrientation(window->w, window->h, window->flags & SDL_WINDOW_RESIZABLE, SDL_GetHint(SDL_HINT_ORIENTATIONS));
+
+ /* Adjust the window data to match the screen */
+ window->x = 0;
+ window->y = 0;
+ window->w = Android_ScreenWidth;
+ window->h = Android_ScreenHeight;
+
+ window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */
+ window->flags &= ~SDL_WINDOW_HIDDEN;
+ window->flags |= SDL_WINDOW_SHOWN; /* only one window on Android */
+ window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
+
+ /* One window, it always has focus */
+ SDL_SetMouseFocus(window);
+ SDL_SetKeyboardFocus(window);
+
+ data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
+ if (!data) {
+ return SDL_OutOfMemory();
+ }
+
+ data->native_window = Android_JNI_GetNativeWindow();
+
+ if (!data->native_window) {
+ SDL_free(data);
+ return SDL_SetError("Could not fetch native window");
+ }
+
+ /* Do not create EGLSurface for Vulkan window since it will then make the window
+ incompatible with vkCreateAndroidSurfaceKHR */
+ if ((window->flags & SDL_WINDOW_VULKAN) == 0) {
+ data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);
+
+ if (data->egl_surface == EGL_NO_SURFACE) {
+ ANativeWindow_release(data->native_window);
+ SDL_free(data);
+ return SDL_SetError("Could not create GLES window surface");
+ }
+ }
+
+ window->driverdata = data;
+ Android_Window = window;
+
+ return 0;
+}
+
+void
+Android_SetWindowTitle(_THIS, SDL_Window * window)
+{
+ Android_JNI_SetActivityTitle(window->title);
+}
+
+void
+Android_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
+{
+ Android_JNI_SetWindowStyle(fullscreen);
+}
+
+void
+Android_DestroyWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data;
+
+ if (window == Android_Window) {
+ Android_Window = NULL;
+ if (Android_PauseSem) SDL_DestroySemaphore(Android_PauseSem);
+ if (Android_ResumeSem) SDL_DestroySemaphore(Android_ResumeSem);
+ Android_PauseSem = NULL;
+ Android_ResumeSem = NULL;
+
+ if(window->driverdata) {
+ data = (SDL_WindowData *) window->driverdata;
+ if (data->egl_surface != EGL_NO_SURFACE) {
+ SDL_EGL_DestroySurface(_this, data->egl_surface);
+ }
+ if (data->native_window) {
+ ANativeWindow_release(data->native_window);
+ }
+ SDL_free(window->driverdata);
+ window->driverdata = NULL;
+ }
+ }
+}
+
+SDL_bool
+Android_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+
+ if (info->version.major == SDL_MAJOR_VERSION &&
+ info->version.minor == SDL_MINOR_VERSION) {
+ info->subsystem = SDL_SYSWM_ANDROID;
+ info->info.android.window = data->native_window;
+ info->info.android.surface = data->egl_surface;
+ return SDL_TRUE;
+ } else {
+ SDL_SetError("Application not compiled with SDL %d.%d",
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+ return SDL_FALSE;
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_ANDROID */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/android/SDL_androidwindow.h b/src/3rdparty/SDL2/src/video/android/SDL_androidwindow.h
new file mode 100644
index 0000000..df99567
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/android/SDL_androidwindow.h
@@ -0,0 +1,45 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_androidwindow_h_
+#define SDL_androidwindow_h_
+
+#include "../../core/android/SDL_android.h"
+#include "../SDL_egl_c.h"
+
+extern int Android_CreateWindow(_THIS, SDL_Window * window);
+extern void Android_SetWindowTitle(_THIS, SDL_Window * window);
+extern void Android_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
+extern void Android_DestroyWindow(_THIS, SDL_Window * window);
+extern SDL_bool Android_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo * info);
+
+typedef struct
+{
+ EGLSurface egl_surface;
+ EGLContext egl_context; /* We use this to preserve the context when losing focus */
+ ANativeWindow* native_window;
+
+} SDL_WindowData;
+
+#endif /* SDL_androidwindow_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaclipboard.h b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaclipboard.h
new file mode 100644
index 0000000..54e4c88
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaclipboard.h
@@ -0,0 +1,36 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_cocoaclipboard_h_
+#define SDL_cocoaclipboard_h_
+
+/* Forward declaration */
+struct SDL_VideoData;
+
+extern int Cocoa_SetClipboardText(_THIS, const char *text);
+extern char *Cocoa_GetClipboardText(_THIS);
+extern SDL_bool Cocoa_HasClipboardText(_THIS);
+extern void Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data);
+
+#endif /* SDL_cocoaclipboard_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaclipboard.m b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaclipboard.m
new file mode 100644
index 0000000..9c96634
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaclipboard.m
@@ -0,0 +1,103 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_COCOA
+
+#include "SDL_cocoavideo.h"
+#include "../../events/SDL_clipboardevents_c.h"
+
+int
+Cocoa_SetClipboardText(_THIS, const char *text)
+{ @autoreleasepool
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+ NSPasteboard *pasteboard;
+ NSString *format = NSPasteboardTypeString;
+
+ pasteboard = [NSPasteboard generalPasteboard];
+ data->clipboard_count = [pasteboard declareTypes:[NSArray arrayWithObject:format] owner:nil];
+ [pasteboard setString:[NSString stringWithUTF8String:text] forType:format];
+
+ return 0;
+}}
+
+char *
+Cocoa_GetClipboardText(_THIS)
+{ @autoreleasepool
+{
+ NSPasteboard *pasteboard;
+ NSString *format = NSPasteboardTypeString;
+ NSString *available;
+ char *text;
+
+ pasteboard = [NSPasteboard generalPasteboard];
+ available = [pasteboard availableTypeFromArray:[NSArray arrayWithObject:format]];
+ if ([available isEqualToString:format]) {
+ NSString* string;
+ const char *utf8;
+
+ string = [pasteboard stringForType:format];
+ if (string == nil) {
+ utf8 = "";
+ } else {
+ utf8 = [string UTF8String];
+ }
+ text = SDL_strdup(utf8);
+ } else {
+ text = SDL_strdup("");
+ }
+
+ return text;
+}}
+
+SDL_bool
+Cocoa_HasClipboardText(_THIS)
+{
+ SDL_bool result = SDL_FALSE;
+ char *text = Cocoa_GetClipboardText(_this);
+ if (text) {
+ result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
+ SDL_free(text);
+ }
+ return result;
+}
+
+void
+Cocoa_CheckClipboardUpdate(struct SDL_VideoData * data)
+{ @autoreleasepool
+{
+ NSPasteboard *pasteboard;
+ NSInteger count;
+
+ pasteboard = [NSPasteboard generalPasteboard];
+ count = [pasteboard changeCount];
+ if (count != data->clipboard_count) {
+ if (data->clipboard_count) {
+ SDL_SendClipboardUpdate();
+ }
+ data->clipboard_count = count;
+ }
+}}
+
+#endif /* SDL_VIDEO_DRIVER_COCOA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaevents.h b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaevents.h
new file mode 100644
index 0000000..986168e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaevents.h
@@ -0,0 +1,32 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_cocoaevents_h_
+#define SDL_cocoaevents_h_
+
+extern void Cocoa_RegisterApp(void);
+extern void Cocoa_PumpEvents(_THIS);
+extern void Cocoa_SuspendScreenSaver(_THIS);
+
+#endif /* SDL_cocoaevents_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaevents.m b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaevents.m
new file mode 100644
index 0000000..38f4ba6
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaevents.m
@@ -0,0 +1,483 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_COCOA
+#include "SDL_timer.h"
+
+#include "SDL_cocoavideo.h"
+#include "../../events/SDL_events_c.h"
+#include "SDL_assert.h"
+#include "SDL_hints.h"
+
+/* This define was added in the 10.9 SDK. */
+#ifndef kIOPMAssertPreventUserIdleDisplaySleep
+#define kIOPMAssertPreventUserIdleDisplaySleep kIOPMAssertionTypePreventUserIdleDisplaySleep
+#endif
+
+@interface SDLApplication : NSApplication
+
+- (void)terminate:(id)sender;
+- (void)sendEvent:(NSEvent *)theEvent;
+
++ (void)registerUserDefaults;
+
+@end
+
+@implementation SDLApplication
+
+// Override terminate to handle Quit and System Shutdown smoothly.
+- (void)terminate:(id)sender
+{
+ SDL_SendQuit();
+}
+
+static SDL_bool s_bShouldHandleEventsInSDLApplication = SDL_FALSE;
+
+static void Cocoa_DispatchEvent(NSEvent *theEvent)
+{
+ SDL_VideoDevice *_this = SDL_GetVideoDevice();
+
+ switch ([theEvent type]) {
+ case NSEventTypeLeftMouseDown:
+ case NSEventTypeOtherMouseDown:
+ case NSEventTypeRightMouseDown:
+ case NSEventTypeLeftMouseUp:
+ case NSEventTypeOtherMouseUp:
+ case NSEventTypeRightMouseUp:
+ case NSEventTypeLeftMouseDragged:
+ case NSEventTypeRightMouseDragged:
+ case NSEventTypeOtherMouseDragged: /* usually middle mouse dragged */
+ case NSEventTypeMouseMoved:
+ case NSEventTypeScrollWheel:
+ Cocoa_HandleMouseEvent(_this, theEvent);
+ break;
+ case NSEventTypeKeyDown:
+ case NSEventTypeKeyUp:
+ case NSEventTypeFlagsChanged:
+ Cocoa_HandleKeyEvent(_this, theEvent);
+ break;
+ default:
+ break;
+ }
+}
+
+// Dispatch events here so that we can handle events caught by
+// nextEventMatchingMask in SDL, as well as events caught by other
+// processes (such as CEF) that are passed down to NSApp.
+- (void)sendEvent:(NSEvent *)theEvent
+{
+ if (s_bShouldHandleEventsInSDLApplication) {
+ Cocoa_DispatchEvent(theEvent);
+ }
+
+ [super sendEvent:theEvent];
+}
+
++ (void)registerUserDefaults
+{
+ NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys:
+ [NSNumber numberWithBool:NO], @"AppleMomentumScrollSupported",
+ [NSNumber numberWithBool:NO], @"ApplePressAndHoldEnabled",
+ [NSNumber numberWithBool:YES], @"ApplePersistenceIgnoreState",
+ nil];
+ [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
+ [appDefaults release];
+}
+
+@end // SDLApplication
+
+/* setAppleMenu disappeared from the headers in 10.4 */
+@interface NSApplication(NSAppleMenu)
+- (void)setAppleMenu:(NSMenu *)menu;
+@end
+
+@interface SDLAppDelegate : NSObject <NSApplicationDelegate> {
+@public
+ BOOL seenFirstActivate;
+}
+
+- (id)init;
+@end
+
+@implementation SDLAppDelegate : NSObject
+- (id)init
+{
+ self = [super init];
+ if (self) {
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+
+ seenFirstActivate = NO;
+
+ [center addObserver:self
+ selector:@selector(windowWillClose:)
+ name:NSWindowWillCloseNotification
+ object:nil];
+
+ [center addObserver:self
+ selector:@selector(focusSomeWindow:)
+ name:NSApplicationDidBecomeActiveNotification
+ object:nil];
+ }
+
+ return self;
+}
+
+- (void)dealloc
+{
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+
+ [center removeObserver:self name:NSWindowWillCloseNotification object:nil];
+ [center removeObserver:self name:NSApplicationDidBecomeActiveNotification object:nil];
+
+ [super dealloc];
+}
+
+- (void)windowWillClose:(NSNotification *)notification;
+{
+ NSWindow *win = (NSWindow*)[notification object];
+
+ if (![win isKeyWindow]) {
+ return;
+ }
+
+ /* HACK: Make the next window in the z-order key when the key window is
+ * closed. The custom event loop and/or windowing code we have seems to
+ * prevent the normal behavior: https://bugzilla.libsdl.org/show_bug.cgi?id=1825
+ */
+
+ /* +[NSApp orderedWindows] never includes the 'About' window, but we still
+ * want to try its list first since the behavior in other apps is to only
+ * make the 'About' window key if no other windows are on-screen.
+ */
+ for (NSWindow *window in [NSApp orderedWindows]) {
+ if (window != win && [window canBecomeKeyWindow]) {
+ if (![window isOnActiveSpace]) {
+ continue;
+ }
+ [window makeKeyAndOrderFront:self];
+ return;
+ }
+ }
+
+ /* If a window wasn't found above, iterate through all visible windows in
+ * the active Space in z-order (including the 'About' window, if it's shown)
+ * and make the first one key.
+ */
+ for (NSNumber *num in [NSWindow windowNumbersWithOptions:0]) {
+ NSWindow *window = [NSApp windowWithWindowNumber:[num integerValue]];
+ if (window && window != win && [window canBecomeKeyWindow]) {
+ [window makeKeyAndOrderFront:self];
+ return;
+ }
+ }
+}
+
+- (void)focusSomeWindow:(NSNotification *)aNotification
+{
+ /* HACK: Ignore the first call. The application gets a
+ * applicationDidBecomeActive: a little bit after the first window is
+ * created, and if we don't ignore it, a window that has been created with
+ * SDL_WINDOW_MINIMIZED will ~immediately be restored.
+ */
+ if (!seenFirstActivate) {
+ seenFirstActivate = YES;
+ return;
+ }
+
+ SDL_VideoDevice *device = SDL_GetVideoDevice();
+ if (device && device->windows) {
+ SDL_Window *window = device->windows;
+ int i;
+ for (i = 0; i < device->num_displays; ++i) {
+ SDL_Window *fullscreen_window = device->displays[i].fullscreen_window;
+ if (fullscreen_window) {
+ if (fullscreen_window->flags & SDL_WINDOW_MINIMIZED) {
+ SDL_RestoreWindow(fullscreen_window);
+ }
+ return;
+ }
+ }
+
+ if (window->flags & SDL_WINDOW_MINIMIZED) {
+ SDL_RestoreWindow(window);
+ } else {
+ SDL_RaiseWindow(window);
+ }
+ }
+}
+
+- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
+{
+ return (BOOL)SDL_SendDropFile(NULL, [filename UTF8String]) && SDL_SendDropComplete(NULL);
+}
+
+- (void)applicationDidFinishLaunching:(NSNotification *)notification
+{
+ /* The menu bar of SDL apps which don't have the typical .app bundle
+ * structure fails to work the first time a window is created (until it's
+ * de-focused and re-focused), if this call is in Cocoa_RegisterApp instead
+ * of here. https://bugzilla.libsdl.org/show_bug.cgi?id=3051
+ */
+ if (!SDL_GetHintBoolean(SDL_HINT_MAC_BACKGROUND_APP, SDL_FALSE)) {
+ [NSApp activateIgnoringOtherApps:YES];
+ }
+
+ /* If we call this before NSApp activation, macOS might print a complaint
+ * about ApplePersistenceIgnoreState. */
+ [SDLApplication registerUserDefaults];
+}
+@end
+
+static SDLAppDelegate *appDelegate = nil;
+
+static NSString *
+GetApplicationName(void)
+{
+ NSString *appName;
+
+ /* Determine the application name */
+ appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
+ if (!appName) {
+ appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
+ }
+
+ if (![appName length]) {
+ appName = [[NSProcessInfo processInfo] processName];
+ }
+
+ return appName;
+}
+
+static void
+CreateApplicationMenus(void)
+{
+ NSString *appName;
+ NSString *title;
+ NSMenu *appleMenu;
+ NSMenu *serviceMenu;
+ NSMenu *windowMenu;
+ NSMenu *viewMenu;
+ NSMenuItem *menuItem;
+ NSMenu *mainMenu;
+
+ if (NSApp == nil) {
+ return;
+ }
+
+ mainMenu = [[NSMenu alloc] init];
+
+ /* Create the main menu bar */
+ [NSApp setMainMenu:mainMenu];
+
+ [mainMenu release]; /* we're done with it, let NSApp own it. */
+ mainMenu = nil;
+
+ /* Create the application menu */
+ appName = GetApplicationName();
+ appleMenu = [[NSMenu alloc] initWithTitle:@""];
+
+ /* Add menu items */
+ title = [@"About " stringByAppendingString:appName];
+ [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
+
+ [appleMenu addItem:[NSMenuItem separatorItem]];
+
+ [appleMenu addItemWithTitle:@"Preferences…" action:nil keyEquivalent:@","];
+
+ [appleMenu addItem:[NSMenuItem separatorItem]];
+
+ serviceMenu = [[NSMenu alloc] initWithTitle:@""];
+ menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Services" action:nil keyEquivalent:@""];
+ [menuItem setSubmenu:serviceMenu];
+
+ [NSApp setServicesMenu:serviceMenu];
+ [serviceMenu release];
+
+ [appleMenu addItem:[NSMenuItem separatorItem]];
+
+ title = [@"Hide " stringByAppendingString:appName];
+ [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
+
+ menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
+ [menuItem setKeyEquivalentModifierMask:(NSEventModifierFlagOption|NSEventModifierFlagCommand)];
+
+ [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
+
+ [appleMenu addItem:[NSMenuItem separatorItem]];
+
+ title = [@"Quit " stringByAppendingString:appName];
+ [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
+
+ /* Put menu into the menubar */
+ menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
+ [menuItem setSubmenu:appleMenu];
+ [[NSApp mainMenu] addItem:menuItem];
+ [menuItem release];
+
+ /* Tell the application object that this is now the application menu */
+ [NSApp setAppleMenu:appleMenu];
+ [appleMenu release];
+
+
+ /* Create the window menu */
+ windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
+
+ /* Add menu items */
+ [windowMenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
+
+ [windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
+
+ /* Put menu into the menubar */
+ menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
+ [menuItem setSubmenu:windowMenu];
+ [[NSApp mainMenu] addItem:menuItem];
+ [menuItem release];
+
+ /* Tell the application object that this is now the window menu */
+ [NSApp setWindowsMenu:windowMenu];
+ [windowMenu release];
+
+
+ /* Add the fullscreen view toggle menu option, if supported */
+ if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) {
+ /* Create the view menu */
+ viewMenu = [[NSMenu alloc] initWithTitle:@"View"];
+
+ /* Add menu items */
+ menuItem = [viewMenu addItemWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
+ [menuItem setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand];
+
+ /* Put menu into the menubar */
+ menuItem = [[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""];
+ [menuItem setSubmenu:viewMenu];
+ [[NSApp mainMenu] addItem:menuItem];
+ [menuItem release];
+
+ [viewMenu release];
+ }
+}
+
+void
+Cocoa_RegisterApp(void)
+{ @autoreleasepool
+{
+ /* This can get called more than once! Be careful what you initialize! */
+
+ if (NSApp == nil) {
+ [SDLApplication sharedApplication];
+ SDL_assert(NSApp != nil);
+
+ s_bShouldHandleEventsInSDLApplication = SDL_TRUE;
+
+ if (!SDL_GetHintBoolean(SDL_HINT_MAC_BACKGROUND_APP, SDL_FALSE)) {
+ [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
+ }
+
+ if ([NSApp mainMenu] == nil) {
+ CreateApplicationMenus();
+ }
+ [NSApp finishLaunching];
+ if ([NSApp delegate]) {
+ /* The SDL app delegate calls this in didFinishLaunching if it's
+ * attached to the NSApp, otherwise we need to call it manually.
+ */
+ [SDLApplication registerUserDefaults];
+ }
+ }
+ if (NSApp && !appDelegate) {
+ appDelegate = [[SDLAppDelegate alloc] init];
+
+ /* If someone else has an app delegate, it means we can't turn a
+ * termination into SDL_Quit, and we can't handle application:openFile:
+ */
+ if (![NSApp delegate]) {
+ [(NSApplication *)NSApp setDelegate:appDelegate];
+ } else {
+ appDelegate->seenFirstActivate = YES;
+ }
+ }
+}}
+
+void
+Cocoa_PumpEvents(_THIS)
+{ @autoreleasepool
+{
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+ /* Update activity every 30 seconds to prevent screensaver */
+ SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
+ if (_this->suspend_screensaver && !data->screensaver_use_iopm) {
+ Uint32 now = SDL_GetTicks();
+ if (!data->screensaver_activity ||
+ SDL_TICKS_PASSED(now, data->screensaver_activity + 30000)) {
+ UpdateSystemActivity(UsrActivity);
+ data->screensaver_activity = now;
+ }
+ }
+#endif
+
+ for ( ; ; ) {
+ NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
+ if ( event == nil ) {
+ break;
+ }
+
+ if (!s_bShouldHandleEventsInSDLApplication) {
+ Cocoa_DispatchEvent(event);
+ }
+
+ // Pass events down to SDLApplication to be handled in sendEvent:
+ [NSApp sendEvent:event];
+ }
+}}
+
+void
+Cocoa_SuspendScreenSaver(_THIS)
+{ @autoreleasepool
+{
+ SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
+
+ if (!data->screensaver_use_iopm) {
+ return;
+ }
+
+ if (data->screensaver_assertion) {
+ IOPMAssertionRelease(data->screensaver_assertion);
+ data->screensaver_assertion = 0;
+ }
+
+ if (_this->suspend_screensaver) {
+ /* FIXME: this should ideally describe the real reason why the game
+ * called SDL_DisableScreenSaver. Note that the name is only meant to be
+ * seen by OS X power users. there's an additional optional human-readable
+ * (localized) reason parameter which we don't set.
+ */
+ NSString *name = [GetApplicationName() stringByAppendingString:@" using SDL_DisableScreenSaver"];
+ IOPMAssertionCreateWithDescription(kIOPMAssertPreventUserIdleDisplaySleep,
+ (CFStringRef) name,
+ NULL, NULL, NULL, 0, NULL,
+ &data->screensaver_assertion);
+ }
+}}
+
+#endif /* SDL_VIDEO_DRIVER_COCOA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoakeyboard.h b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoakeyboard.h
new file mode 100644
index 0000000..7d89523
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoakeyboard.h
@@ -0,0 +1,36 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_cocoakeyboard_h_
+#define SDL_cocoakeyboard_h_
+
+extern void Cocoa_InitKeyboard(_THIS);
+extern void Cocoa_HandleKeyEvent(_THIS, NSEvent * event);
+extern void Cocoa_QuitKeyboard(_THIS);
+
+extern void Cocoa_StartTextInput(_THIS);
+extern void Cocoa_StopTextInput(_THIS);
+extern void Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect);
+
+#endif /* SDL_cocoakeyboard_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoakeyboard.m b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoakeyboard.m
new file mode 100644
index 0000000..8436047
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoakeyboard.m
@@ -0,0 +1,720 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_COCOA
+
+#include "SDL_cocoavideo.h"
+
+#include "../../events/SDL_events_c.h"
+#include "../../events/SDL_keyboard_c.h"
+#include "../../events/scancodes_darwin.h"
+
+#include <Carbon/Carbon.h>
+#include <IOKit/hid/IOHIDLib.h>
+
+/*#define DEBUG_IME NSLog */
+#define DEBUG_IME(...)
+
+@interface SDLTranslatorResponder : NSView <NSTextInputClient> {
+ NSString *_markedText;
+ NSRange _markedRange;
+ NSRange _selectedRange;
+ SDL_Rect _inputRect;
+}
+- (void)doCommandBySelector:(SEL)myselector;
+- (void)setInputRect:(SDL_Rect *)rect;
+@end
+
+@implementation SDLTranslatorResponder
+
+- (void)setInputRect:(SDL_Rect *)rect
+{
+ _inputRect = *rect;
+}
+
+- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange
+{
+ /* TODO: Make use of replacementRange? */
+
+ const char *str;
+
+ DEBUG_IME(@"insertText: %@", aString);
+
+ /* Could be NSString or NSAttributedString, so we have
+ * to test and convert it before return as SDL event */
+ if ([aString isKindOfClass: [NSAttributedString class]]) {
+ str = [[aString string] UTF8String];
+ } else {
+ str = [aString UTF8String];
+ }
+
+ SDL_SendKeyboardText(str);
+}
+
+- (void)doCommandBySelector:(SEL)myselector
+{
+ /* No need to do anything since we are not using Cocoa
+ selectors to handle special keys, instead we use SDL
+ key events to do the same job.
+ */
+}
+
+- (BOOL)hasMarkedText
+{
+ return _markedText != nil;
+}
+
+- (NSRange)markedRange
+{
+ return _markedRange;
+}
+
+- (NSRange)selectedRange
+{
+ return _selectedRange;
+}
+
+- (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange
+{
+ if ([aString isKindOfClass:[NSAttributedString class]]) {
+ aString = [aString string];
+ }
+
+ if ([aString length] == 0) {
+ [self unmarkText];
+ return;
+ }
+
+ if (_markedText != aString) {
+ [_markedText release];
+ _markedText = [aString retain];
+ }
+
+ _selectedRange = selectedRange;
+ _markedRange = NSMakeRange(0, [aString length]);
+
+ SDL_SendEditingText([aString UTF8String],
+ (int) selectedRange.location, (int) selectedRange.length);
+
+ DEBUG_IME(@"setMarkedText: %@, (%d, %d)", _markedText,
+ selRange.location, selRange.length);
+}
+
+- (void)unmarkText
+{
+ [_markedText release];
+ _markedText = nil;
+
+ SDL_SendEditingText("", 0, 0);
+}
+
+- (NSRect)firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange
+{
+ NSWindow *window = [self window];
+ NSRect contentRect = [window contentRectForFrameRect:[window frame]];
+ float windowHeight = contentRect.size.height;
+ NSRect rect = NSMakeRect(_inputRect.x, windowHeight - _inputRect.y - _inputRect.h,
+ _inputRect.w, _inputRect.h);
+
+ if (actualRange) {
+ *actualRange = aRange;
+ }
+
+ DEBUG_IME(@"firstRectForCharacterRange: (%d, %d): windowHeight = %g, rect = %@",
+ aRange.location, aRange.length, windowHeight,
+ NSStringFromRect(rect));
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+ if (![window respondsToSelector:@selector(convertRectToScreen:)]) {
+ rect.origin = [window convertBaseToScreen:rect.origin];
+ } else
+#endif
+ {
+ rect = [window convertRectToScreen:rect];
+ }
+
+ return rect;
+}
+
+- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange
+{
+ DEBUG_IME(@"attributedSubstringFromRange: (%d, %d)", aRange.location, aRange.length);
+ return nil;
+}
+
+- (NSInteger)conversationIdentifier
+{
+ return (NSInteger) self;
+}
+
+/* This method returns the index for character that is
+ * nearest to thePoint. thPoint is in screen coordinate system.
+ */
+- (NSUInteger)characterIndexForPoint:(NSPoint)thePoint
+{
+ DEBUG_IME(@"characterIndexForPoint: (%g, %g)", thePoint.x, thePoint.y);
+ return 0;
+}
+
+/* This method is the key to attribute extension.
+ * We could add new attributes through this method.
+ * NSInputServer examines the return value of this
+ * method & constructs appropriate attributed string.
+ */
+- (NSArray *)validAttributesForMarkedText
+{
+ return [NSArray array];
+}
+
+@end
+
+/*------------------------------------------------------------------------------
+Set up a HID callback to properly detect Caps Lock up/down events.
+Derived from:
+http://stackoverflow.com/questions/7190852/using-iohidmanager-to-get-modifier-key-events
+*/
+
+static IOHIDManagerRef s_hidManager = NULL;
+
+static void
+HIDCallback(void *context, IOReturn result, void *sender, IOHIDValueRef value)
+{
+ if (context != s_hidManager) {
+ /* An old callback, ignore it (related to bug 2157 below) */
+ return;
+ }
+
+ IOHIDElementRef elem = IOHIDValueGetElement(value);
+ if (IOHIDElementGetUsagePage(elem) != kHIDPage_KeyboardOrKeypad
+ || IOHIDElementGetUsage(elem) != kHIDUsage_KeyboardCapsLock) {
+ return;
+ }
+ CFIndex pressed = IOHIDValueGetIntegerValue(value);
+ SDL_SendKeyboardKey(pressed ? SDL_PRESSED : SDL_RELEASED, SDL_SCANCODE_CAPSLOCK);
+}
+
+static CFDictionaryRef
+CreateHIDDeviceMatchingDictionary(UInt32 usagePage, UInt32 usage)
+{
+ CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault,
+ 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+ if (dict) {
+ CFNumberRef number = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usagePage);
+ if (number) {
+ CFDictionarySetValue(dict, CFSTR(kIOHIDDeviceUsagePageKey), number);
+ CFRelease(number);
+ number = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage);
+ if (number) {
+ CFDictionarySetValue(dict, CFSTR(kIOHIDDeviceUsageKey), number);
+ CFRelease(number);
+ return dict;
+ }
+ }
+ CFRelease(dict);
+ }
+ return NULL;
+}
+
+static void
+QuitHIDCallback()
+{
+ if (!s_hidManager) {
+ return;
+ }
+
+#if 0 /* Releasing here causes a crash on Mac OS X 10.10 and earlier,
+ * so just leak it for now. See bug 2157 for details.
+ */
+ IOHIDManagerUnscheduleFromRunLoop(s_hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
+ IOHIDManagerRegisterInputValueCallback(s_hidManager, NULL, NULL);
+ IOHIDManagerClose(s_hidManager, 0);
+
+ CFRelease(s_hidManager);
+#endif
+ s_hidManager = NULL;
+}
+
+static void
+InitHIDCallback()
+{
+ s_hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
+ if (!s_hidManager) {
+ return;
+ }
+ CFDictionaryRef keyboard = NULL, keypad = NULL;
+ CFArrayRef matches = NULL;
+ keyboard = CreateHIDDeviceMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard);
+ if (!keyboard) {
+ goto fail;
+ }
+ keypad = CreateHIDDeviceMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Keypad);
+ if (!keypad) {
+ goto fail;
+ }
+ CFDictionaryRef matchesList[] = { keyboard, keypad };
+ matches = CFArrayCreate(kCFAllocatorDefault, (const void **)matchesList, 2, NULL);
+ if (!matches) {
+ goto fail;
+ }
+ IOHIDManagerSetDeviceMatchingMultiple(s_hidManager, matches);
+ IOHIDManagerRegisterInputValueCallback(s_hidManager, HIDCallback, s_hidManager);
+ IOHIDManagerScheduleWithRunLoop(s_hidManager, CFRunLoopGetMain(), kCFRunLoopDefaultMode);
+ if (IOHIDManagerOpen(s_hidManager, kIOHIDOptionsTypeNone) == kIOReturnSuccess) {
+ goto cleanup;
+ }
+
+fail:
+ QuitHIDCallback();
+
+cleanup:
+ if (matches) {
+ CFRelease(matches);
+ }
+ if (keypad) {
+ CFRelease(keypad);
+ }
+ if (keyboard) {
+ CFRelease(keyboard);
+ }
+}
+
+/* This is a helper function for HandleModifierSide. This
+ * function reverts back to behavior before the distinction between
+ * sides was made.
+ */
+static void
+HandleNonDeviceModifier(unsigned int device_independent_mask,
+ unsigned int oldMods,
+ unsigned int newMods,
+ SDL_Scancode scancode)
+{
+ unsigned int oldMask, newMask;
+
+ /* Isolate just the bits we care about in the depedent bits so we can
+ * figure out what changed
+ */
+ oldMask = oldMods & device_independent_mask;
+ newMask = newMods & device_independent_mask;
+
+ if (oldMask && oldMask != newMask) {
+ SDL_SendKeyboardKey(SDL_RELEASED, scancode);
+ } else if (newMask && oldMask != newMask) {
+ SDL_SendKeyboardKey(SDL_PRESSED, scancode);
+ }
+}
+
+/* This is a helper function for HandleModifierSide.
+ * This function sets the actual SDL_PrivateKeyboard event.
+ */
+static void
+HandleModifierOneSide(unsigned int oldMods, unsigned int newMods,
+ SDL_Scancode scancode,
+ unsigned int sided_device_dependent_mask)
+{
+ unsigned int old_dep_mask, new_dep_mask;
+
+ /* Isolate just the bits we care about in the depedent bits so we can
+ * figure out what changed
+ */
+ old_dep_mask = oldMods & sided_device_dependent_mask;
+ new_dep_mask = newMods & sided_device_dependent_mask;
+
+ /* We now know that this side bit flipped. But we don't know if
+ * it went pressed to released or released to pressed, so we must
+ * find out which it is.
+ */
+ if (new_dep_mask && old_dep_mask != new_dep_mask) {
+ SDL_SendKeyboardKey(SDL_PRESSED, scancode);
+ } else {
+ SDL_SendKeyboardKey(SDL_RELEASED, scancode);
+ }
+}
+
+/* This is a helper function for DoSidedModifiers.
+ * This function will figure out if the modifier key is the left or right side,
+ * e.g. left-shift vs right-shift.
+ */
+static void
+HandleModifierSide(int device_independent_mask,
+ unsigned int oldMods, unsigned int newMods,
+ SDL_Scancode left_scancode,
+ SDL_Scancode right_scancode,
+ unsigned int left_device_dependent_mask,
+ unsigned int right_device_dependent_mask)
+{
+ unsigned int device_dependent_mask = (left_device_dependent_mask |
+ right_device_dependent_mask);
+ unsigned int diff_mod;
+
+ /* On the basis that the device independent mask is set, but there are
+ * no device dependent flags set, we'll assume that we can't detect this
+ * keyboard and revert to the unsided behavior.
+ */
+ if ((device_dependent_mask & newMods) == 0) {
+ /* Revert to the old behavior */
+ HandleNonDeviceModifier(device_independent_mask, oldMods, newMods, left_scancode);
+ return;
+ }
+
+ /* XOR the previous state against the new state to see if there's a change */
+ diff_mod = (device_dependent_mask & oldMods) ^
+ (device_dependent_mask & newMods);
+ if (diff_mod) {
+ /* A change in state was found. Isolate the left and right bits
+ * to handle them separately just in case the values can simulataneously
+ * change or if the bits don't both exist.
+ */
+ if (left_device_dependent_mask & diff_mod) {
+ HandleModifierOneSide(oldMods, newMods, left_scancode, left_device_dependent_mask);
+ }
+ if (right_device_dependent_mask & diff_mod) {
+ HandleModifierOneSide(oldMods, newMods, right_scancode, right_device_dependent_mask);
+ }
+ }
+}
+
+/* This is a helper function for DoSidedModifiers.
+ * This function will release a key press in the case that
+ * it is clear that the modifier has been released (i.e. one side
+ * can't still be down).
+ */
+static void
+ReleaseModifierSide(unsigned int device_independent_mask,
+ unsigned int oldMods, unsigned int newMods,
+ SDL_Scancode left_scancode,
+ SDL_Scancode right_scancode,
+ unsigned int left_device_dependent_mask,
+ unsigned int right_device_dependent_mask)
+{
+ unsigned int device_dependent_mask = (left_device_dependent_mask |
+ right_device_dependent_mask);
+
+ /* On the basis that the device independent mask is set, but there are
+ * no device dependent flags set, we'll assume that we can't detect this
+ * keyboard and revert to the unsided behavior.
+ */
+ if ((device_dependent_mask & oldMods) == 0) {
+ /* In this case, we can't detect the keyboard, so use the left side
+ * to represent both, and release it.
+ */
+ SDL_SendKeyboardKey(SDL_RELEASED, left_scancode);
+ return;
+ }
+
+ /*
+ * This could have been done in an if-else case because at this point,
+ * we know that all keys have been released when calling this function.
+ * But I'm being paranoid so I want to handle each separately,
+ * so I hope this doesn't cause other problems.
+ */
+ if ( left_device_dependent_mask & oldMods ) {
+ SDL_SendKeyboardKey(SDL_RELEASED, left_scancode);
+ }
+ if ( right_device_dependent_mask & oldMods ) {
+ SDL_SendKeyboardKey(SDL_RELEASED, right_scancode);
+ }
+}
+
+/* This function will handle the modifier keys and also determine the
+ * correct side of the key.
+ */
+static void
+DoSidedModifiers(unsigned short scancode,
+ unsigned int oldMods, unsigned int newMods)
+{
+ /* Set up arrays for the key syms for the left and right side. */
+ const SDL_Scancode left_mapping[] = {
+ SDL_SCANCODE_LSHIFT,
+ SDL_SCANCODE_LCTRL,
+ SDL_SCANCODE_LALT,
+ SDL_SCANCODE_LGUI
+ };
+ const SDL_Scancode right_mapping[] = {
+ SDL_SCANCODE_RSHIFT,
+ SDL_SCANCODE_RCTRL,
+ SDL_SCANCODE_RALT,
+ SDL_SCANCODE_RGUI
+ };
+ /* Set up arrays for the device dependent masks with indices that
+ * correspond to the _mapping arrays
+ */
+ const unsigned int left_device_mapping[] = { NX_DEVICELSHIFTKEYMASK, NX_DEVICELCTLKEYMASK, NX_DEVICELALTKEYMASK, NX_DEVICELCMDKEYMASK };
+ const unsigned int right_device_mapping[] = { NX_DEVICERSHIFTKEYMASK, NX_DEVICERCTLKEYMASK, NX_DEVICERALTKEYMASK, NX_DEVICERCMDKEYMASK };
+
+ unsigned int i, bit;
+
+ /* Iterate through the bits, testing each against the old modifiers */
+ for (i = 0, bit = NSEventModifierFlagShift; bit <= NSEventModifierFlagCommand; bit <<= 1, ++i) {
+ unsigned int oldMask, newMask;
+
+ oldMask = oldMods & bit;
+ newMask = newMods & bit;
+
+ /* If the bit is set, we must always examine it because the left
+ * and right side keys may alternate or both may be pressed.
+ */
+ if (newMask) {
+ HandleModifierSide(bit, oldMods, newMods,
+ left_mapping[i], right_mapping[i],
+ left_device_mapping[i], right_device_mapping[i]);
+ }
+ /* If the state changed from pressed to unpressed, we must examine
+ * the device dependent bits to release the correct keys.
+ */
+ else if (oldMask && oldMask != newMask) {
+ ReleaseModifierSide(bit, oldMods, newMods,
+ left_mapping[i], right_mapping[i],
+ left_device_mapping[i], right_device_mapping[i]);
+ }
+ }
+}
+
+static void
+HandleModifiers(_THIS, unsigned short scancode, unsigned int modifierFlags)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
+ if (modifierFlags == data->modifierFlags) {
+ return;
+ }
+
+ DoSidedModifiers(scancode, data->modifierFlags, modifierFlags);
+ data->modifierFlags = modifierFlags;
+}
+
+static void
+UpdateKeymap(SDL_VideoData *data, SDL_bool send_event)
+{
+ TISInputSourceRef key_layout;
+ const void *chr_data;
+ int i;
+ SDL_Scancode scancode;
+ SDL_Keycode keymap[SDL_NUM_SCANCODES];
+
+ /* See if the keymap needs to be updated */
+ key_layout = TISCopyCurrentKeyboardLayoutInputSource();
+ if (key_layout == data->key_layout) {
+ return;
+ }
+ data->key_layout = key_layout;
+
+ SDL_GetDefaultKeymap(keymap);
+
+ /* Try Unicode data first */
+ CFDataRef uchrDataRef = TISGetInputSourceProperty(key_layout, kTISPropertyUnicodeKeyLayoutData);
+ if (uchrDataRef) {
+ chr_data = CFDataGetBytePtr(uchrDataRef);
+ } else {
+ goto cleanup;
+ }
+
+ if (chr_data) {
+ UInt32 keyboard_type = LMGetKbdType();
+ OSStatus err;
+
+ for (i = 0; i < SDL_arraysize(darwin_scancode_table); i++) {
+ UniChar s[8];
+ UniCharCount len;
+ UInt32 dead_key_state;
+
+ /* Make sure this scancode is a valid character scancode */
+ scancode = darwin_scancode_table[i];
+ if (scancode == SDL_SCANCODE_UNKNOWN ||
+ (keymap[scancode] & SDLK_SCANCODE_MASK)) {
+ continue;
+ }
+
+ dead_key_state = 0;
+ err = UCKeyTranslate ((UCKeyboardLayout *) chr_data,
+ i, kUCKeyActionDown,
+ 0, keyboard_type,
+ kUCKeyTranslateNoDeadKeysMask,
+ &dead_key_state, 8, &len, s);
+ if (err != noErr) {
+ continue;
+ }
+
+ if (len > 0 && s[0] != 0x10) {
+ keymap[scancode] = s[0];
+ }
+ }
+ SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
+ if (send_event) {
+ SDL_SendKeymapChangedEvent();
+ }
+ return;
+ }
+
+cleanup:
+ CFRelease(key_layout);
+}
+
+void
+Cocoa_InitKeyboard(_THIS)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
+ UpdateKeymap(data, SDL_FALSE);
+
+ /* Set our own names for the platform-dependent but layout-independent keys */
+ /* This key is NumLock on the MacBook keyboard. :) */
+ /*SDL_SetScancodeName(SDL_SCANCODE_NUMLOCKCLEAR, "Clear");*/
+ SDL_SetScancodeName(SDL_SCANCODE_LALT, "Left Option");
+ SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Command");
+ SDL_SetScancodeName(SDL_SCANCODE_RALT, "Right Option");
+ SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Command");
+
+ data->modifierFlags = [NSEvent modifierFlags];
+ SDL_ToggleModState(KMOD_CAPS, (data->modifierFlags & NSEventModifierFlagCapsLock) != 0);
+
+ InitHIDCallback();
+}
+
+void
+Cocoa_StartTextInput(_THIS)
+{ @autoreleasepool
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+ SDL_Window *window = SDL_GetKeyboardFocus();
+ NSWindow *nswindow = nil;
+ if (window) {
+ nswindow = ((SDL_WindowData*)window->driverdata)->nswindow;
+ }
+
+ NSView *parentView = [nswindow contentView];
+
+ /* We only keep one field editor per process, since only the front most
+ * window can receive text input events, so it make no sense to keep more
+ * than one copy. When we switched to another window and requesting for
+ * text input, simply remove the field editor from its superview then add
+ * it to the front most window's content view */
+ if (!data->fieldEdit) {
+ data->fieldEdit =
+ [[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)];
+ }
+
+ if (![[data->fieldEdit superview] isEqual:parentView]) {
+ /* DEBUG_IME(@"add fieldEdit to window contentView"); */
+ [data->fieldEdit removeFromSuperview];
+ [parentView addSubview: data->fieldEdit];
+ [nswindow makeFirstResponder: data->fieldEdit];
+ }
+}}
+
+void
+Cocoa_StopTextInput(_THIS)
+{ @autoreleasepool
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
+ if (data && data->fieldEdit) {
+ [data->fieldEdit removeFromSuperview];
+ [data->fieldEdit release];
+ data->fieldEdit = nil;
+ }
+}}
+
+void
+Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
+ if (!rect) {
+ SDL_InvalidParamError("rect");
+ return;
+ }
+
+ [data->fieldEdit setInputRect:rect];
+}
+
+void
+Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
+{
+ SDL_VideoData *data = _this ? ((SDL_VideoData *) _this->driverdata) : NULL;
+ if (!data) {
+ return; /* can happen when returning from fullscreen Space on shutdown */
+ }
+
+ unsigned short scancode = [event keyCode];
+ SDL_Scancode code;
+#if 0
+ const char *text;
+#endif
+
+ if ((scancode == 10 || scancode == 50) && KBGetLayoutType(LMGetKbdType()) == kKeyboardISO) {
+ /* see comments in SDL_cocoakeys.h */
+ scancode = 60 - scancode;
+ }
+
+ if (scancode < SDL_arraysize(darwin_scancode_table)) {
+ code = darwin_scancode_table[scancode];
+ } else {
+ /* Hmm, does this ever happen? If so, need to extend the keymap... */
+ code = SDL_SCANCODE_UNKNOWN;
+ }
+
+ switch ([event type]) {
+ case NSEventTypeKeyDown:
+ if (![event isARepeat]) {
+ /* See if we need to rebuild the keyboard layout */
+ UpdateKeymap(data, SDL_TRUE);
+ }
+
+ SDL_SendKeyboardKey(SDL_PRESSED, code);
+#if 1
+ if (code == SDL_SCANCODE_UNKNOWN) {
+ fprintf(stderr, "The key you just pressed is not recognized by SDL. To help get this fixed, report this to the SDL forums/mailing list <https://discourse.libsdl.org/> or to Christian Walther <cwalther@gmx.ch>. Mac virtual key code is %d.\n", scancode);
+ }
+#endif
+ if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
+ /* FIXME CW 2007-08-16: only send those events to the field editor for which we actually want text events, not e.g. esc or function keys. Arrow keys in particular seem to produce crashes sometimes. */
+ [data->fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]];
+#if 0
+ text = [[event characters] UTF8String];
+ if(text && *text) {
+ SDL_SendKeyboardText(text);
+ [data->fieldEdit setString:@""];
+ }
+#endif
+ }
+ break;
+ case NSEventTypeKeyUp:
+ SDL_SendKeyboardKey(SDL_RELEASED, code);
+ break;
+ case NSEventTypeFlagsChanged:
+ /* FIXME CW 2007-08-14: check if this whole mess that takes up half of this file is really necessary */
+ HandleModifiers(_this, scancode, [event modifierFlags]);
+ break;
+ default: /* just to avoid compiler warnings */
+ break;
+ }
+}
+
+void
+Cocoa_QuitKeyboard(_THIS)
+{
+ QuitHIDCallback();
+}
+
+#endif /* SDL_VIDEO_DRIVER_COCOA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamessagebox.h b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamessagebox.h
new file mode 100644
index 0000000..74a815a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamessagebox.h
@@ -0,0 +1,29 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_COCOA
+
+extern int Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
+
+#endif /* SDL_VIDEO_DRIVER_COCOA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamessagebox.m b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamessagebox.m
new file mode 100644
index 0000000..a98237f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamessagebox.m
@@ -0,0 +1,145 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_COCOA
+
+#include "SDL_events.h"
+#include "SDL_timer.h"
+#include "SDL_messagebox.h"
+#include "SDL_cocoavideo.h"
+
+@interface SDLMessageBoxPresenter : NSObject {
+@public
+ NSInteger clicked;
+ NSWindow *nswindow;
+}
+- (id) initWithParentWindow:(SDL_Window *)window;
+- (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
+@end
+
+@implementation SDLMessageBoxPresenter
+- (id) initWithParentWindow:(SDL_Window *)window
+{
+ self = [super init];
+ if (self) {
+ clicked = -1;
+
+ /* Retain the NSWindow because we'll show the alert later on the main thread */
+ if (window) {
+ nswindow = [((SDL_WindowData *) window->driverdata)->nswindow retain];
+ } else {
+ nswindow = NULL;
+ }
+ }
+
+ return self;
+}
+
+- (void)showAlert:(NSAlert*)alert
+{
+ if (nswindow) {
+#ifdef MAC_OS_X_VERSION_10_9
+ if ([alert respondsToSelector:@selector(beginSheetModalForWindow:completionHandler:)]) {
+ [alert beginSheetModalForWindow:nswindow completionHandler:^(NSModalResponse returnCode) {
+ clicked = returnCode;
+ }];
+ } else
+#endif
+ {
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
+ [alert beginSheetModalForWindow:nswindow modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
+#endif
+ }
+
+ while (clicked < 0) {
+ SDL_PumpEvents();
+ SDL_Delay(100);
+ }
+
+ [nswindow release];
+ } else {
+ clicked = [alert runModal];
+ }
+}
+
+- (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
+{
+ clicked = returnCode;
+}
+
+@end
+
+
+/* Display a Cocoa message box */
+int
+Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
+{ @autoreleasepool
+{
+ Cocoa_RegisterApp();
+
+ NSAlert* alert = [[[NSAlert alloc] init] autorelease];
+
+ if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
+ [alert setAlertStyle:NSAlertStyleCritical];
+ } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
+ [alert setAlertStyle:NSAlertStyleWarning];
+ } else {
+ [alert setAlertStyle:NSAlertStyleInformational];
+ }
+
+ [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
+ [alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
+
+ const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
+ int i;
+ for (i = 0; i < messageboxdata->numbuttons; ++i) {
+ NSButton *button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]];
+ if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
+ [button setKeyEquivalent:@"\r"];
+ } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
+ [button setKeyEquivalent:@"\033"];
+ } else {
+ [button setKeyEquivalent:@""];
+ }
+ }
+
+ SDLMessageBoxPresenter* presenter = [[[SDLMessageBoxPresenter alloc] initWithParentWindow:messageboxdata->window] autorelease];
+
+ [presenter performSelectorOnMainThread:@selector(showAlert:)
+ withObject:alert
+ waitUntilDone:YES];
+
+ int returnValue = 0;
+ NSInteger clicked = presenter->clicked;
+ if (clicked >= NSAlertFirstButtonReturn) {
+ clicked -= NSAlertFirstButtonReturn;
+ *buttonid = buttons[clicked].buttonid;
+ } else {
+ returnValue = SDL_SetError("Did not get a valid `clicked button' id: %ld", (long)clicked);
+ }
+
+ return returnValue;
+}}
+
+#endif /* SDL_VIDEO_DRIVER_COCOA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoametalview.h b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoametalview.h
new file mode 100644
index 0000000..c0a582f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoametalview.h
@@ -0,0 +1,63 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+/*
+ * @author Mark Callow, www.edgewise-consulting.com.
+ *
+ * Thanks to Alex Szpakowski, @slime73 on GitHub, for his gist showing
+ * how to add a CAMetalLayer backed view.
+ */
+
+#ifndef SDL_cocoametalview_h_
+#define SDL_cocoametalview_h_
+
+#import "../SDL_sysvideo.h"
+#import "SDL_cocoawindow.h"
+
+#if SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_RENDER_METAL)
+
+#import <Cocoa/Cocoa.h>
+#import <Metal/Metal.h>
+#import <QuartzCore/CAMetalLayer.h>
+
+#define METALVIEW_TAG 255
+
+@interface SDL_cocoametalview : NSView {
+ NSInteger _tag;
+}
+
+- (instancetype)initWithFrame:(NSRect)frame
+ scale:(CGFloat)scale;
+
+/* Override superclass tag so this class can set it. */
+@property (assign, readonly) NSInteger tag;
+
+@end
+
+SDL_cocoametalview* Cocoa_Mtl_AddMetalView(SDL_Window* window);
+
+void Cocoa_Mtl_GetDrawableSize(SDL_Window * window, int * w, int * h);
+
+#endif /* SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_RENDER_METAL) */
+
+#endif /* SDL_cocoametalview_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoametalview.m b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoametalview.m
new file mode 100644
index 0000000..e9c08a0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoametalview.m
@@ -0,0 +1,135 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+/*
+ * @author Mark Callow, www.edgewise-consulting.com.
+ *
+ * Thanks to Alex Szpakowski, @slime73 on GitHub, for his gist showing
+ * how to add a CAMetalLayer backed view.
+ */
+
+#import "SDL_cocoametalview.h"
+
+#if SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_RENDER_METAL)
+
+#include "SDL_assert.h"
+
+@implementation SDL_cocoametalview
+
+/* The synthesized getter should be called by super's viewWithTag. */
+@synthesize tag = _tag;
+
+/* Return a Metal-compatible layer. */
++ (Class)layerClass
+{
+ return NSClassFromString(@"CAMetalLayer");
+}
+
+/* Indicate the view wants to draw using a backing layer instead of drawRect. */
+- (BOOL)wantsUpdateLayer
+{
+ return YES;
+}
+
+/* When the wantsLayer property is set to YES, this method will be invoked to
+ * return a layer instance.
+ */
+- (CALayer*)makeBackingLayer
+{
+ return [self.class.layerClass layer];
+}
+
+- (instancetype)initWithFrame:(NSRect)frame
+ scale:(CGFloat)scale
+{
+ if ((self = [super initWithFrame:frame])) {
+ _tag = METALVIEW_TAG;
+ self.wantsLayer = YES;
+
+ /* Allow resize. */
+ self.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
+
+ /* Set the desired scale. The default drawableSize of a CAMetalLayer
+ * is its bounds x its scale so nothing further needs to be done.
+ */
+ self.layer.contentsScale = scale;
+ }
+
+ return self;
+}
+
+/* Set the size of the metal drawables when the view is resized. */
+- (void)resizeWithOldSuperviewSize:(NSSize)oldSize
+{
+ [super resizeWithOldSuperviewSize:oldSize];
+}
+
+@end
+
+SDL_cocoametalview*
+Cocoa_Mtl_AddMetalView(SDL_Window* window)
+{
+ SDL_WindowData* data = (__bridge SDL_WindowData *)window->driverdata;
+ NSView *view = data->nswindow.contentView;
+ CGFloat scale = 1.0;
+
+ if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
+ /* Set the scale to the natural scale factor of the screen - then
+ * the backing dimensions of the Metal view will match the pixel
+ * dimensions of the screen rather than the dimensions in points
+ * yielding high resolution on retine displays.
+ *
+ * N.B. In order for backingScaleFactor to be > 1,
+ * NSHighResolutionCapable must be set to true in the app's Info.plist.
+ */
+ NSWindow* nswindow = data->nswindow;
+ if ([nswindow.screen respondsToSelector:@selector(backingScaleFactor)])
+ scale = data->nswindow.screen.backingScaleFactor;
+ }
+
+ SDL_cocoametalview *metalview
+ = [[SDL_cocoametalview alloc] initWithFrame:view.frame scale:scale];
+ [view addSubview:metalview];
+ return metalview;
+}
+
+void
+Cocoa_Mtl_GetDrawableSize(SDL_Window * window, int * w, int * h)
+{
+ SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
+ NSView *view = data->nswindow.contentView;
+ SDL_cocoametalview* metalview = [view viewWithTag:METALVIEW_TAG];
+ if (metalview) {
+ CAMetalLayer *layer = (CAMetalLayer*)metalview.layer;
+ assert(layer != NULL);
+ if (w) {
+ *w = layer.drawableSize.width;
+ }
+ if (h) {
+ *h = layer.drawableSize.height;
+ }
+ } else {
+ SDL_GetWindowSize(window, w, h);
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_COCOA && (SDL_VIDEO_VULKAN || SDL_VIDEO_RENDER_METAL) */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamodes.h b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamodes.h
new file mode 100644
index 0000000..05482e8
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamodes.h
@@ -0,0 +1,46 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_cocoamodes_h_
+#define SDL_cocoamodes_h_
+
+typedef struct
+{
+ CGDirectDisplayID display;
+} SDL_DisplayData;
+
+typedef struct
+{
+ CGDisplayModeRef moderef;
+} SDL_DisplayModeData;
+
+extern void Cocoa_InitModes(_THIS);
+extern int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
+extern int Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
+extern void Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
+extern int Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hpdi, float * vdpi);
+extern int Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
+extern void Cocoa_QuitModes(_THIS);
+
+#endif /* SDL_cocoamodes_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamodes.m b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamodes.m
new file mode 100644
index 0000000..97ccd94
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamodes.m
@@ -0,0 +1,490 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+#include "SDL_assert.h"
+
+#if SDL_VIDEO_DRIVER_COCOA
+
+#include "SDL_cocoavideo.h"
+
+/* We need this for IODisplayCreateInfoDictionary and kIODisplayOnlyPreferredName */
+#include <IOKit/graphics/IOGraphicsLib.h>
+
+/* We need this for CVDisplayLinkGetNominalOutputVideoRefreshPeriod */
+#include <CoreVideo/CVBase.h>
+#include <CoreVideo/CVDisplayLink.h>
+
+/* we need this for ShowMenuBar() and HideMenuBar(). */
+#include <Carbon/Carbon.h>
+
+/* This gets us MAC_OS_X_VERSION_MIN_REQUIRED... */
+#include <AvailabilityMacros.h>
+
+
+static void
+Cocoa_ToggleMenuBar(const BOOL show)
+{
+ /* !!! FIXME: keep an eye on this.
+ * ShowMenuBar/HideMenuBar is officially unavailable for 64-bit binaries.
+ * It happens to work, as of 10.7, but we're going to see if
+ * we can just simply do without it on newer OSes...
+ */
+#if (MAC_OS_X_VERSION_MIN_REQUIRED < 1070) && !defined(__LP64__)
+ if (show) {
+ ShowMenuBar();
+ } else {
+ HideMenuBar();
+ }
+#endif
+}
+
+static int
+CG_SetError(const char *prefix, CGDisplayErr result)
+{
+ const char *error;
+
+ switch (result) {
+ case kCGErrorFailure:
+ error = "kCGErrorFailure";
+ break;
+ case kCGErrorIllegalArgument:
+ error = "kCGErrorIllegalArgument";
+ break;
+ case kCGErrorInvalidConnection:
+ error = "kCGErrorInvalidConnection";
+ break;
+ case kCGErrorInvalidContext:
+ error = "kCGErrorInvalidContext";
+ break;
+ case kCGErrorCannotComplete:
+ error = "kCGErrorCannotComplete";
+ break;
+ case kCGErrorNotImplemented:
+ error = "kCGErrorNotImplemented";
+ break;
+ case kCGErrorRangeCheck:
+ error = "kCGErrorRangeCheck";
+ break;
+ case kCGErrorTypeCheck:
+ error = "kCGErrorTypeCheck";
+ break;
+ case kCGErrorInvalidOperation:
+ error = "kCGErrorInvalidOperation";
+ break;
+ case kCGErrorNoneAvailable:
+ error = "kCGErrorNoneAvailable";
+ break;
+ default:
+ error = "Unknown Error";
+ break;
+ }
+ return SDL_SetError("%s: %s", prefix, error);
+}
+
+static SDL_bool
+GetDisplayMode(_THIS, CGDisplayModeRef vidmode, CVDisplayLinkRef link, SDL_DisplayMode *mode)
+{
+ SDL_DisplayModeData *data;
+ int width = 0;
+ int height = 0;
+ int bpp = 0;
+ int refreshRate = 0;
+ CFStringRef fmt;
+
+ data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
+ if (!data) {
+ return SDL_FALSE;
+ }
+ data->moderef = vidmode;
+
+ fmt = CGDisplayModeCopyPixelEncoding(vidmode);
+ width = (int) CGDisplayModeGetWidth(vidmode);
+ height = (int) CGDisplayModeGetHeight(vidmode);
+ refreshRate = (int) (CGDisplayModeGetRefreshRate(vidmode) + 0.5);
+
+ if (CFStringCompare(fmt, CFSTR(IO32BitDirectPixels),
+ kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
+ bpp = 32;
+ } else if (CFStringCompare(fmt, CFSTR(IO16BitDirectPixels),
+ kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
+ bpp = 16;
+ } else if (CFStringCompare(fmt, CFSTR(kIO30BitDirectPixels),
+ kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
+ bpp = 30;
+ } else {
+ bpp = 0; /* ignore 8-bit and such for now. */
+ }
+
+ CFRelease(fmt);
+
+ /* CGDisplayModeGetRefreshRate returns 0 for many non-CRT displays. */
+ if (refreshRate == 0 && link != NULL) {
+ CVTime time = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(link);
+ if ((time.flags & kCVTimeIsIndefinite) == 0 && time.timeValue != 0) {
+ refreshRate = (int) ((time.timeScale / (double) time.timeValue) + 0.5);
+ }
+ }
+
+ mode->format = SDL_PIXELFORMAT_UNKNOWN;
+ switch (bpp) {
+ case 16:
+ mode->format = SDL_PIXELFORMAT_ARGB1555;
+ break;
+ case 30:
+ mode->format = SDL_PIXELFORMAT_ARGB2101010;
+ break;
+ case 32:
+ mode->format = SDL_PIXELFORMAT_ARGB8888;
+ break;
+ case 8: /* We don't support palettized modes now */
+ default: /* Totally unrecognizable bit depth. */
+ SDL_free(data);
+ return SDL_FALSE;
+ }
+ mode->w = width;
+ mode->h = height;
+ mode->refresh_rate = refreshRate;
+ mode->driverdata = data;
+ return SDL_TRUE;
+}
+
+static const char *
+Cocoa_GetDisplayName(CGDirectDisplayID displayID)
+{
+ CFDictionaryRef deviceInfo = IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName);
+ NSDictionary *localizedNames = [(NSDictionary *)deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]];
+ const char* displayName = NULL;
+
+ if ([localizedNames count] > 0) {
+ displayName = SDL_strdup([[localizedNames objectForKey:[[localizedNames allKeys] objectAtIndex:0]] UTF8String]);
+ }
+ CFRelease(deviceInfo);
+ return displayName;
+}
+
+void
+Cocoa_InitModes(_THIS)
+{ @autoreleasepool
+{
+ CGDisplayErr result;
+ CGDirectDisplayID *displays;
+ CGDisplayCount numDisplays;
+ int pass, i;
+
+ result = CGGetOnlineDisplayList(0, NULL, &numDisplays);
+ if (result != kCGErrorSuccess) {
+ CG_SetError("CGGetOnlineDisplayList()", result);
+ return;
+ }
+ displays = SDL_stack_alloc(CGDirectDisplayID, numDisplays);
+ result = CGGetOnlineDisplayList(numDisplays, displays, &numDisplays);
+ if (result != kCGErrorSuccess) {
+ CG_SetError("CGGetOnlineDisplayList()", result);
+ SDL_stack_free(displays);
+ return;
+ }
+
+ /* Pick up the primary display in the first pass, then get the rest */
+ for (pass = 0; pass < 2; ++pass) {
+ for (i = 0; i < numDisplays; ++i) {
+ SDL_VideoDisplay display;
+ SDL_DisplayData *displaydata;
+ SDL_DisplayMode mode;
+ CGDisplayModeRef moderef = NULL;
+ CVDisplayLinkRef link = NULL;
+
+ if (pass == 0) {
+ if (!CGDisplayIsMain(displays[i])) {
+ continue;
+ }
+ } else {
+ if (CGDisplayIsMain(displays[i])) {
+ continue;
+ }
+ }
+
+ if (CGDisplayMirrorsDisplay(displays[i]) != kCGNullDirectDisplay) {
+ continue;
+ }
+
+ moderef = CGDisplayCopyDisplayMode(displays[i]);
+
+ if (!moderef) {
+ continue;
+ }
+
+ displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata));
+ if (!displaydata) {
+ CGDisplayModeRelease(moderef);
+ continue;
+ }
+ displaydata->display = displays[i];
+
+ CVDisplayLinkCreateWithCGDisplay(displays[i], &link);
+
+ SDL_zero(display);
+ /* this returns a stddup'ed string */
+ display.name = (char *)Cocoa_GetDisplayName(displays[i]);
+ if (!GetDisplayMode(_this, moderef, link, &mode)) {
+ CVDisplayLinkRelease(link);
+ CGDisplayModeRelease(moderef);
+ SDL_free(display.name);
+ SDL_free(displaydata);
+ continue;
+ }
+
+ CVDisplayLinkRelease(link);
+
+ display.desktop_mode = mode;
+ display.current_mode = mode;
+ display.driverdata = displaydata;
+ SDL_AddVideoDisplay(&display);
+ SDL_free(display.name);
+ }
+ }
+ SDL_stack_free(displays);
+}}
+
+int
+Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
+{
+ SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
+ CGRect cgrect;
+
+ cgrect = CGDisplayBounds(displaydata->display);
+ rect->x = (int)cgrect.origin.x;
+ rect->y = (int)cgrect.origin.y;
+ rect->w = (int)cgrect.size.width;
+ rect->h = (int)cgrect.size.height;
+ return 0;
+}
+
+int
+Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
+{
+ SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
+ const CGDirectDisplayID cgdisplay = displaydata->display;
+ NSArray *screens = [NSScreen screens];
+ NSScreen *screen = nil;
+
+ /* !!! FIXME: maybe track the NSScreen in SDL_DisplayData? */
+ for (NSScreen *i in screens) {
+ const CGDirectDisplayID thisDisplay = (CGDirectDisplayID) [[[i deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue];
+ if (thisDisplay == cgdisplay) {
+ screen = i;
+ break;
+ }
+ }
+
+ SDL_assert(screen != nil); /* didn't find it?! */
+ if (screen == nil) {
+ return -1;
+ }
+
+ const CGRect cgrect = CGDisplayBounds(cgdisplay);
+ const NSRect frame = [screen visibleFrame];
+
+ // !!! FIXME: I assume -[NSScreen visibleFrame] is relative to the origin of the screen in question and not the whole desktop.
+ // !!! FIXME: The math vs CGDisplayBounds might be incorrect if that's not the case, though. Check this.
+ rect->x = (int)(cgrect.origin.x + frame.origin.x);
+ rect->y = (int)(cgrect.origin.y + frame.origin.y);
+ rect->w = (int)frame.size.width;
+ rect->h = (int)frame.size.height;
+
+ return 0;
+}
+
+int
+Cocoa_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi)
+{
+ const float MM_IN_INCH = 25.4f;
+
+ SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
+
+ CGSize displaySize = CGDisplayScreenSize(data->display);
+ int pixelWidth = (int) CGDisplayPixelsWide(data->display);
+ int pixelHeight = (int) CGDisplayPixelsHigh(data->display);
+
+ if (ddpi) {
+ *ddpi = SDL_ComputeDiagonalDPI(pixelWidth, pixelHeight, displaySize.width / MM_IN_INCH, displaySize.height / MM_IN_INCH);
+ }
+ if (hdpi) {
+ *hdpi = pixelWidth * MM_IN_INCH / displaySize.width;
+ }
+ if (vdpi) {
+ *vdpi = pixelHeight * MM_IN_INCH / displaySize.height;
+ }
+
+ return 0;
+}
+
+void
+Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
+{
+ SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
+ CVDisplayLinkRef link = NULL;
+ CGDisplayModeRef desktopmoderef;
+ SDL_DisplayMode desktopmode;
+ CFArrayRef modes;
+
+ CVDisplayLinkCreateWithCGDisplay(data->display, &link);
+
+ desktopmoderef = CGDisplayCopyDisplayMode(data->display);
+
+ /* CopyAllDisplayModes won't always contain the desktop display mode (if
+ * NULL is passed in) - for example on a retina 15" MBP, System Preferences
+ * allows choosing 1920x1200 but it's not in the list. AddDisplayMode makes
+ * sure there are no duplicates so it's safe to always add the desktop mode
+ * even in cases where it is in the CopyAllDisplayModes list.
+ */
+ if (desktopmoderef && GetDisplayMode(_this, desktopmoderef, link, &desktopmode)) {
+ if (!SDL_AddDisplayMode(display, &desktopmode)) {
+ CGDisplayModeRelease(desktopmoderef);
+ SDL_free(desktopmode.driverdata);
+ }
+ } else {
+ CGDisplayModeRelease(desktopmoderef);
+ }
+
+ modes = CGDisplayCopyAllDisplayModes(data->display, NULL);
+
+ if (modes) {
+ CFIndex i;
+ const CFIndex count = CFArrayGetCount(modes);
+
+ for (i = 0; i < count; i++) {
+ CGDisplayModeRef moderef = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i);
+ SDL_DisplayMode mode;
+
+ if (GetDisplayMode(_this, moderef, link, &mode)) {
+ if (SDL_AddDisplayMode(display, &mode)) {
+ CGDisplayModeRetain(moderef);
+ } else {
+ SDL_free(mode.driverdata);
+ }
+ }
+ }
+
+ CFRelease(modes);
+ }
+
+ CVDisplayLinkRelease(link);
+}
+
+int
+Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
+{
+ SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
+ SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
+ CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken;
+ CGError result;
+
+ /* Fade to black to hide resolution-switching flicker */
+ if (CGAcquireDisplayFadeReservation(5, &fade_token) == kCGErrorSuccess) {
+ CGDisplayFade(fade_token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, TRUE);
+ }
+
+ if (data == display->desktop_mode.driverdata) {
+ /* Restoring desktop mode */
+ CGDisplaySetDisplayMode(displaydata->display, data->moderef, NULL);
+
+ if (CGDisplayIsMain(displaydata->display)) {
+ CGReleaseAllDisplays();
+ } else {
+ CGDisplayRelease(displaydata->display);
+ }
+
+ if (CGDisplayIsMain(displaydata->display)) {
+ Cocoa_ToggleMenuBar(YES);
+ }
+ } else {
+ /* Put up the blanking window (a window above all other windows) */
+ if (CGDisplayIsMain(displaydata->display)) {
+ /* If we don't capture all displays, Cocoa tries to rearrange windows... *sigh* */
+ result = CGCaptureAllDisplays();
+ } else {
+ result = CGDisplayCapture(displaydata->display);
+ }
+ if (result != kCGErrorSuccess) {
+ CG_SetError("CGDisplayCapture()", result);
+ goto ERR_NO_CAPTURE;
+ }
+
+ /* Do the physical switch */
+ result = CGDisplaySetDisplayMode(displaydata->display, data->moderef, NULL);
+ if (result != kCGErrorSuccess) {
+ CG_SetError("CGDisplaySwitchToMode()", result);
+ goto ERR_NO_SWITCH;
+ }
+
+ /* Hide the menu bar so it doesn't intercept events */
+ if (CGDisplayIsMain(displaydata->display)) {
+ Cocoa_ToggleMenuBar(NO);
+ }
+ }
+
+ /* Fade in again (asynchronously) */
+ if (fade_token != kCGDisplayFadeReservationInvalidToken) {
+ CGDisplayFade(fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
+ CGReleaseDisplayFadeReservation(fade_token);
+ }
+
+ return 0;
+
+ /* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */
+ERR_NO_SWITCH:
+ CGDisplayRelease(displaydata->display);
+ERR_NO_CAPTURE:
+ if (fade_token != kCGDisplayFadeReservationInvalidToken) {
+ CGDisplayFade (fade_token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, FALSE);
+ CGReleaseDisplayFadeReservation(fade_token);
+ }
+ return -1;
+}
+
+void
+Cocoa_QuitModes(_THIS)
+{
+ int i, j;
+
+ for (i = 0; i < _this->num_displays; ++i) {
+ SDL_VideoDisplay *display = &_this->displays[i];
+ SDL_DisplayModeData *mode;
+
+ if (display->current_mode.driverdata != display->desktop_mode.driverdata) {
+ Cocoa_SetDisplayMode(_this, display, &display->desktop_mode);
+ }
+
+ mode = (SDL_DisplayModeData *) display->desktop_mode.driverdata;
+ CGDisplayModeRelease(mode->moderef);
+
+ for (j = 0; j < display->num_display_modes; j++) {
+ mode = (SDL_DisplayModeData*) display->display_modes[j].driverdata;
+ CGDisplayModeRelease(mode->moderef);
+ }
+
+ }
+ Cocoa_ToggleMenuBar(YES);
+}
+
+#endif /* SDL_VIDEO_DRIVER_COCOA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamouse.h b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamouse.h
new file mode 100644
index 0000000..b79a3cf
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamouse.h
@@ -0,0 +1,52 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_cocoamouse_h_
+#define SDL_cocoamouse_h_
+
+#include "SDL_cocoavideo.h"
+
+extern void Cocoa_InitMouse(_THIS);
+extern void Cocoa_HandleMouseEvent(_THIS, NSEvent * event);
+extern void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent * event);
+extern void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y);
+extern void Cocoa_QuitMouse(_THIS);
+
+typedef struct {
+ /* Wether we've seen a cursor warp since the last move event. */
+ SDL_bool seenWarp;
+ /* What location our last cursor warp was to. */
+ CGFloat lastWarpX;
+ CGFloat lastWarpY;
+ /* What location we last saw the cursor move to. */
+ CGFloat lastMoveX;
+ CGFloat lastMoveY;
+ void *tapdata;
+} SDL_MouseData;
+
+@interface NSCursor (InvisibleCursor)
++ (NSCursor *)invisibleCursor;
+@end
+
+#endif /* SDL_cocoamouse_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamouse.m b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamouse.m
new file mode 100644
index 0000000..029a318
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamouse.m
@@ -0,0 +1,467 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_COCOA
+
+#include "SDL_assert.h"
+#include "SDL_events.h"
+#include "SDL_cocoamouse.h"
+#include "SDL_cocoamousetap.h"
+#include "SDL_cocoavideo.h"
+
+#include "../../events/SDL_mouse_c.h"
+
+/* #define DEBUG_COCOAMOUSE */
+
+#ifdef DEBUG_COCOAMOUSE
+#define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
+#else
+#define DLog(...) do { } while (0)
+#endif
+
+@implementation NSCursor (InvisibleCursor)
++ (NSCursor *)invisibleCursor
+{
+ static NSCursor *invisibleCursor = NULL;
+ if (!invisibleCursor) {
+ /* RAW 16x16 transparent GIF */
+ static unsigned char cursorBytes[] = {
+ 0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x10, 0x00, 0x10, 0x00, 0x80,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xF9, 0x04,
+ 0x01, 0x00, 0x00, 0x01, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x10,
+ 0x00, 0x10, 0x00, 0x00, 0x02, 0x0E, 0x8C, 0x8F, 0xA9, 0xCB, 0xED,
+ 0x0F, 0xA3, 0x9C, 0xB4, 0xDA, 0x8B, 0xB3, 0x3E, 0x05, 0x00, 0x3B
+ };
+
+ NSData *cursorData = [NSData dataWithBytesNoCopy:&cursorBytes[0]
+ length:sizeof(cursorBytes)
+ freeWhenDone:NO];
+ NSImage *cursorImage = [[[NSImage alloc] initWithData:cursorData] autorelease];
+ invisibleCursor = [[NSCursor alloc] initWithImage:cursorImage
+ hotSpot:NSZeroPoint];
+ }
+
+ return invisibleCursor;
+}
+@end
+
+
+static SDL_Cursor *
+Cocoa_CreateDefaultCursor()
+{ @autoreleasepool
+{
+ NSCursor *nscursor;
+ SDL_Cursor *cursor = NULL;
+
+ nscursor = [NSCursor arrowCursor];
+
+ if (nscursor) {
+ cursor = SDL_calloc(1, sizeof(*cursor));
+ if (cursor) {
+ cursor->driverdata = nscursor;
+ [nscursor retain];
+ }
+ }
+
+ return cursor;
+}}
+
+static SDL_Cursor *
+Cocoa_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
+{ @autoreleasepool
+{
+ NSImage *nsimage;
+ NSCursor *nscursor = NULL;
+ SDL_Cursor *cursor = NULL;
+
+ nsimage = Cocoa_CreateImage(surface);
+ if (nsimage) {
+ nscursor = [[NSCursor alloc] initWithImage: nsimage hotSpot: NSMakePoint(hot_x, hot_y)];
+ }
+
+ if (nscursor) {
+ cursor = SDL_calloc(1, sizeof(*cursor));
+ if (cursor) {
+ cursor->driverdata = nscursor;
+ } else {
+ [nscursor release];
+ }
+ }
+
+ return cursor;
+}}
+
+static SDL_Cursor *
+Cocoa_CreateSystemCursor(SDL_SystemCursor id)
+{ @autoreleasepool
+{
+ NSCursor *nscursor = NULL;
+ SDL_Cursor *cursor = NULL;
+
+ switch(id) {
+ case SDL_SYSTEM_CURSOR_ARROW:
+ nscursor = [NSCursor arrowCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_IBEAM:
+ nscursor = [NSCursor IBeamCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_WAIT:
+ nscursor = [NSCursor arrowCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_CROSSHAIR:
+ nscursor = [NSCursor crosshairCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_WAITARROW:
+ nscursor = [NSCursor arrowCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_SIZENWSE:
+ case SDL_SYSTEM_CURSOR_SIZENESW:
+ nscursor = [NSCursor closedHandCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_SIZEWE:
+ nscursor = [NSCursor resizeLeftRightCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_SIZENS:
+ nscursor = [NSCursor resizeUpDownCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_SIZEALL:
+ nscursor = [NSCursor closedHandCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_NO:
+ nscursor = [NSCursor operationNotAllowedCursor];
+ break;
+ case SDL_SYSTEM_CURSOR_HAND:
+ nscursor = [NSCursor pointingHandCursor];
+ break;
+ default:
+ SDL_assert(!"Unknown system cursor");
+ return NULL;
+ }
+
+ if (nscursor) {
+ cursor = SDL_calloc(1, sizeof(*cursor));
+ if (cursor) {
+ /* We'll free it later, so retain it here */
+ [nscursor retain];
+ cursor->driverdata = nscursor;
+ }
+ }
+
+ return cursor;
+}}
+
+static void
+Cocoa_FreeCursor(SDL_Cursor * cursor)
+{ @autoreleasepool
+{
+ NSCursor *nscursor = (NSCursor *)cursor->driverdata;
+
+ [nscursor release];
+ SDL_free(cursor);
+}}
+
+static int
+Cocoa_ShowCursor(SDL_Cursor * cursor)
+{ @autoreleasepool
+{
+ SDL_VideoDevice *device = SDL_GetVideoDevice();
+ SDL_Window *window = (device ? device->windows : NULL);
+ for (; window != NULL; window = window->next) {
+ SDL_WindowData *driverdata = (SDL_WindowData *)window->driverdata;
+ if (driverdata) {
+ [driverdata->nswindow performSelectorOnMainThread:@selector(invalidateCursorRectsForView:)
+ withObject:[driverdata->nswindow contentView]
+ waitUntilDone:NO];
+ }
+ }
+ return 0;
+}}
+
+static SDL_Window *
+SDL_FindWindowAtPoint(const int x, const int y)
+{
+ const SDL_Point pt = { x, y };
+ SDL_Window *i;
+ for (i = SDL_GetVideoDevice()->windows; i; i = i->next) {
+ const SDL_Rect r = { i->x, i->y, i->w, i->h };
+ if (SDL_PointInRect(&pt, &r)) {
+ return i;
+ }
+ }
+
+ return NULL;
+}
+
+static int
+Cocoa_WarpMouseGlobal(int x, int y)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ if (mouse->focus) {
+ SDL_WindowData *data = (SDL_WindowData *) mouse->focus->driverdata;
+ if ([data->listener isMoving]) {
+ DLog("Postponing warp, window being moved.");
+ [data->listener setPendingMoveX:x Y:y];
+ return 0;
+ }
+ }
+ const CGPoint point = CGPointMake((float)x, (float)y);
+
+ Cocoa_HandleMouseWarp(point.x, point.y);
+
+ CGWarpMouseCursorPosition(point);
+
+ /* CGWarpMouse causes a short delay by default, which is preventable by
+ * Calling this directly after. CGSetLocalEventsSuppressionInterval can also
+ * prevent it, but it's deprecated as of OS X 10.6.
+ */
+ if (!mouse->relative_mode) {
+ CGAssociateMouseAndMouseCursorPosition(YES);
+ }
+
+ /* CGWarpMouseCursorPosition doesn't generate a window event, unlike our
+ * other implementations' APIs. Send what's appropriate.
+ */
+ if (!mouse->relative_mode) {
+ SDL_Window *win = SDL_FindWindowAtPoint(x, y);
+ SDL_SetMouseFocus(win);
+ if (win) {
+ SDL_assert(win == mouse->focus);
+ SDL_SendMouseMotion(win, mouse->mouseID, 0, x - win->x, y - win->y);
+ }
+ }
+
+ return 0;
+}
+
+static void
+Cocoa_WarpMouse(SDL_Window * window, int x, int y)
+{
+ Cocoa_WarpMouseGlobal(x + window->x, y + window->y);
+}
+
+static int
+Cocoa_SetRelativeMouseMode(SDL_bool enabled)
+{
+ /* We will re-apply the relative mode when the window gets focus, if it
+ * doesn't have focus right now.
+ */
+ SDL_Window *window = SDL_GetMouseFocus();
+ if (!window) {
+ return 0;
+ }
+
+ /* We will re-apply the relative mode when the window finishes being moved,
+ * if it is being moved right now.
+ */
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ if ([data->listener isMoving]) {
+ return 0;
+ }
+
+ CGError result;
+ if (enabled) {
+ DLog("Turning on.");
+ result = CGAssociateMouseAndMouseCursorPosition(NO);
+ } else {
+ DLog("Turning off.");
+ result = CGAssociateMouseAndMouseCursorPosition(YES);
+ }
+ if (result != kCGErrorSuccess) {
+ return SDL_SetError("CGAssociateMouseAndMouseCursorPosition() failed");
+ }
+
+ /* The hide/unhide calls are redundant most of the time, but they fix
+ * https://bugzilla.libsdl.org/show_bug.cgi?id=2550
+ */
+ if (enabled) {
+ [NSCursor hide];
+ } else {
+ [NSCursor unhide];
+ }
+ return 0;
+}
+
+static int
+Cocoa_CaptureMouse(SDL_Window *window)
+{
+ /* our Cocoa event code already tracks the mouse outside the window,
+ so all we have to do here is say "okay" and do what we always do. */
+ return 0;
+}
+
+static Uint32
+Cocoa_GetGlobalMouseState(int *x, int *y)
+{
+ const NSUInteger cocoaButtons = [NSEvent pressedMouseButtons];
+ const NSPoint cocoaLocation = [NSEvent mouseLocation];
+ Uint32 retval = 0;
+
+ for (NSScreen *screen in [NSScreen screens]) {
+ NSRect frame = [screen frame];
+ if (NSMouseInRect(cocoaLocation, frame, NO)) {
+ *x = (int) cocoaLocation.x;
+ *y = (int) ((frame.origin.y + frame.size.height) - cocoaLocation.y);
+ break;
+ }
+ }
+
+ retval |= (cocoaButtons & (1 << 0)) ? SDL_BUTTON_LMASK : 0;
+ retval |= (cocoaButtons & (1 << 1)) ? SDL_BUTTON_RMASK : 0;
+ retval |= (cocoaButtons & (1 << 2)) ? SDL_BUTTON_MMASK : 0;
+ retval |= (cocoaButtons & (1 << 3)) ? SDL_BUTTON_X1MASK : 0;
+ retval |= (cocoaButtons & (1 << 4)) ? SDL_BUTTON_X2MASK : 0;
+
+ return retval;
+}
+
+void
+Cocoa_InitMouse(_THIS)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ mouse->driverdata = SDL_calloc(1, sizeof(SDL_MouseData));
+
+ mouse->CreateCursor = Cocoa_CreateCursor;
+ mouse->CreateSystemCursor = Cocoa_CreateSystemCursor;
+ mouse->ShowCursor = Cocoa_ShowCursor;
+ mouse->FreeCursor = Cocoa_FreeCursor;
+ mouse->WarpMouse = Cocoa_WarpMouse;
+ mouse->WarpMouseGlobal = Cocoa_WarpMouseGlobal;
+ mouse->SetRelativeMouseMode = Cocoa_SetRelativeMouseMode;
+ mouse->CaptureMouse = Cocoa_CaptureMouse;
+ mouse->GetGlobalMouseState = Cocoa_GetGlobalMouseState;
+
+ SDL_SetDefaultCursor(Cocoa_CreateDefaultCursor());
+
+ Cocoa_InitMouseEventTap(mouse->driverdata);
+
+ SDL_MouseData *driverdata = (SDL_MouseData*)mouse->driverdata;
+ const NSPoint location = [NSEvent mouseLocation];
+ driverdata->lastMoveX = location.x;
+ driverdata->lastMoveY = location.y;
+}
+
+void
+Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
+{
+ switch ([event type]) {
+ case NSEventTypeMouseMoved:
+ case NSEventTypeLeftMouseDragged:
+ case NSEventTypeRightMouseDragged:
+ case NSEventTypeOtherMouseDragged:
+ break;
+
+ default:
+ /* Ignore any other events. */
+ return;
+ }
+
+ SDL_Mouse *mouse = SDL_GetMouse();
+ SDL_MouseData *driverdata = (SDL_MouseData*)mouse->driverdata;
+ if (!driverdata) {
+ return; /* can happen when returning from fullscreen Space on shutdown */
+ }
+
+ const SDL_bool seenWarp = driverdata->seenWarp;
+ driverdata->seenWarp = NO;
+
+ const NSPoint location = [NSEvent mouseLocation];
+ const CGFloat lastMoveX = driverdata->lastMoveX;
+ const CGFloat lastMoveY = driverdata->lastMoveY;
+ driverdata->lastMoveX = location.x;
+ driverdata->lastMoveY = location.y;
+ DLog("Last seen mouse: (%g, %g)", location.x, location.y);
+
+ /* Non-relative movement is handled in -[Cocoa_WindowListener mouseMoved:] */
+ if (!mouse->relative_mode) {
+ return;
+ }
+
+ /* Ignore events that aren't inside the client area (i.e. title bar.) */
+ if ([event window]) {
+ NSRect windowRect = [[[event window] contentView] frame];
+ if (!NSMouseInRect([event locationInWindow], windowRect, NO)) {
+ return;
+ }
+ }
+
+ float deltaX = [event deltaX];
+ float deltaY = [event deltaY];
+
+ if (seenWarp) {
+ deltaX += (lastMoveX - driverdata->lastWarpX);
+ deltaY += ((CGDisplayPixelsHigh(kCGDirectMainDisplay) - lastMoveY) - driverdata->lastWarpY);
+
+ DLog("Motion was (%g, %g), offset to (%g, %g)", [event deltaX], [event deltaY], deltaX, deltaY);
+ }
+
+ SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, (int)deltaX, (int)deltaY);
+}
+
+void
+Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ CGFloat x = -[event deltaX];
+ CGFloat y = [event deltaY];
+ SDL_MouseWheelDirection direction = SDL_MOUSEWHEEL_NORMAL;
+
+ if ([event respondsToSelector:@selector(isDirectionInvertedFromDevice)]) {
+ if ([event isDirectionInvertedFromDevice] == YES) {
+ direction = SDL_MOUSEWHEEL_FLIPPED;
+ }
+ }
+
+ SDL_SendMouseWheel(window, mouse->mouseID, x, y, direction);
+}
+
+void
+Cocoa_HandleMouseWarp(CGFloat x, CGFloat y)
+{
+ /* This makes Cocoa_HandleMouseEvent ignore the delta caused by the warp,
+ * since it gets included in the next movement event.
+ */
+ SDL_MouseData *driverdata = (SDL_MouseData*)SDL_GetMouse()->driverdata;
+ driverdata->lastWarpX = x;
+ driverdata->lastWarpY = y;
+ driverdata->seenWarp = SDL_TRUE;
+
+ DLog("(%g, %g)", x, y);
+}
+
+void
+Cocoa_QuitMouse(_THIS)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ if (mouse) {
+ if (mouse->driverdata) {
+ Cocoa_QuitMouseEventTap(((SDL_MouseData*)mouse->driverdata));
+ }
+
+ SDL_free(mouse->driverdata);
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_COCOA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamousetap.h b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamousetap.h
new file mode 100644
index 0000000..40ce386
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamousetap.h
@@ -0,0 +1,34 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_cocoamousetap_h_
+#define SDL_cocoamousetap_h_
+
+#include "SDL_cocoamouse.h"
+
+extern void Cocoa_InitMouseEventTap(SDL_MouseData *driverdata);
+extern void Cocoa_EnableMouseEventTap(SDL_MouseData *driverdata, SDL_bool enabled);
+extern void Cocoa_QuitMouseEventTap(SDL_MouseData *driverdata);
+
+#endif /* SDL_cocoamousetap_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamousetap.m b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamousetap.m
new file mode 100644
index 0000000..3c4fcf2
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoamousetap.m
@@ -0,0 +1,279 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_COCOA
+
+#include "SDL_cocoamousetap.h"
+
+/* Event taps are forbidden in the Mac App Store, so we can only enable this
+ * code if your app doesn't need to ship through the app store.
+ * This code makes it so that a grabbed cursor cannot "leak" a mouse click
+ * past the edge of the window if moving the cursor too fast.
+ */
+#if SDL_MAC_NO_SANDBOX
+
+#include "SDL_keyboard.h"
+#include "SDL_cocoavideo.h"
+#include "../../thread/SDL_systhread.h"
+
+#include "../../events/SDL_mouse_c.h"
+
+typedef struct {
+ CFMachPortRef tap;
+ CFRunLoopRef runloop;
+ CFRunLoopSourceRef runloopSource;
+ SDL_Thread *thread;
+ SDL_sem *runloopStartedSemaphore;
+} SDL_MouseEventTapData;
+
+static const CGEventMask movementEventsMask =
+ CGEventMaskBit(kCGEventLeftMouseDragged)
+ | CGEventMaskBit(kCGEventRightMouseDragged)
+ | CGEventMaskBit(kCGEventMouseMoved);
+
+static const CGEventMask allGrabbedEventsMask =
+ CGEventMaskBit(kCGEventLeftMouseDown) | CGEventMaskBit(kCGEventLeftMouseUp)
+ | CGEventMaskBit(kCGEventRightMouseDown) | CGEventMaskBit(kCGEventRightMouseUp)
+ | CGEventMaskBit(kCGEventOtherMouseDown) | CGEventMaskBit(kCGEventOtherMouseUp)
+ | CGEventMaskBit(kCGEventLeftMouseDragged) | CGEventMaskBit(kCGEventRightMouseDragged)
+ | CGEventMaskBit(kCGEventMouseMoved);
+
+static CGEventRef
+Cocoa_MouseTapCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon)
+{
+ SDL_MouseEventTapData *tapdata = (SDL_MouseEventTapData*)refcon;
+ SDL_Mouse *mouse = SDL_GetMouse();
+ SDL_Window *window = SDL_GetKeyboardFocus();
+ NSWindow *nswindow;
+ NSRect windowRect;
+ CGPoint eventLocation;
+
+ switch (type) {
+ case kCGEventTapDisabledByTimeout:
+ {
+ CGEventTapEnable(tapdata->tap, true);
+ return NULL;
+ }
+ case kCGEventTapDisabledByUserInput:
+ {
+ return NULL;
+ }
+ default:
+ break;
+ }
+
+
+ if (!window || !mouse) {
+ return event;
+ }
+
+ if (mouse->relative_mode) {
+ return event;
+ }
+
+ if (!(window->flags & SDL_WINDOW_INPUT_GRABBED)) {
+ return event;
+ }
+
+ /* This is the same coordinate system as Cocoa uses. */
+ nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
+ eventLocation = CGEventGetUnflippedLocation(event);
+ windowRect = [nswindow contentRectForFrameRect:[nswindow frame]];
+
+ if (!NSMouseInRect(NSPointFromCGPoint(eventLocation), windowRect, NO)) {
+
+ /* This is in CGs global screenspace coordinate system, which has a
+ * flipped Y.
+ */
+ CGPoint newLocation = CGEventGetLocation(event);
+
+ if (eventLocation.x < NSMinX(windowRect)) {
+ newLocation.x = NSMinX(windowRect);
+ } else if (eventLocation.x >= NSMaxX(windowRect)) {
+ newLocation.x = NSMaxX(windowRect) - 1.0;
+ }
+
+ if (eventLocation.y <= NSMinY(windowRect)) {
+ newLocation.y -= (NSMinY(windowRect) - eventLocation.y + 1);
+ } else if (eventLocation.y > NSMaxY(windowRect)) {
+ newLocation.y += (eventLocation.y - NSMaxY(windowRect));
+ }
+
+ CGWarpMouseCursorPosition(newLocation);
+ CGAssociateMouseAndMouseCursorPosition(YES);
+
+ if ((CGEventMaskBit(type) & movementEventsMask) == 0) {
+ /* For click events, we just constrain the event to the window, so
+ * no other app receives the click event. We can't due the same to
+ * movement events, since they mean that our warp cursor above
+ * behaves strangely.
+ */
+ CGEventSetLocation(event, newLocation);
+ }
+ }
+
+ return event;
+}
+
+static void
+SemaphorePostCallback(CFRunLoopTimerRef timer, void *info)
+{
+ SDL_SemPost((SDL_sem*)info);
+}
+
+static int
+Cocoa_MouseTapThread(void *data)
+{
+ SDL_MouseEventTapData *tapdata = (SDL_MouseEventTapData*)data;
+
+ /* Tap was created on main thread but we own it now. */
+ CFMachPortRef eventTap = tapdata->tap;
+ if (eventTap) {
+ /* Try to create a runloop source we can schedule. */
+ CFRunLoopSourceRef runloopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
+ if (runloopSource) {
+ tapdata->runloopSource = runloopSource;
+ } else {
+ CFRelease(eventTap);
+ SDL_SemPost(tapdata->runloopStartedSemaphore);
+ /* TODO: Both here and in the return below, set some state in
+ * tapdata to indicate that initialization failed, which we should
+ * check in InitMouseEventTap, after we move the semaphore check
+ * from Quit to Init.
+ */
+ return 1;
+ }
+ } else {
+ SDL_SemPost(tapdata->runloopStartedSemaphore);
+ return 1;
+ }
+
+ tapdata->runloop = CFRunLoopGetCurrent();
+ CFRunLoopAddSource(tapdata->runloop, tapdata->runloopSource, kCFRunLoopCommonModes);
+ CFRunLoopTimerContext context = {.info = tapdata->runloopStartedSemaphore};
+ /* We signal the runloop started semaphore *after* the run loop has started, indicating it's safe to CFRunLoopStop it. */
+ CFRunLoopTimerRef timer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent(), 0, 0, 0, &SemaphorePostCallback, &context);
+ CFRunLoopAddTimer(tapdata->runloop, timer, kCFRunLoopCommonModes);
+ CFRelease(timer);
+
+ /* Run the event loop to handle events in the event tap. */
+ CFRunLoopRun();
+ /* Make sure this is signaled so that SDL_QuitMouseEventTap knows it can safely SDL_WaitThread for us. */
+ if (SDL_SemValue(tapdata->runloopStartedSemaphore) < 1) {
+ SDL_SemPost(tapdata->runloopStartedSemaphore);
+ }
+ CFRunLoopRemoveSource(tapdata->runloop, tapdata->runloopSource, kCFRunLoopCommonModes);
+
+ /* Clean up. */
+ CGEventTapEnable(tapdata->tap, false);
+ CFRelease(tapdata->runloopSource);
+ CFRelease(tapdata->tap);
+ tapdata->runloopSource = NULL;
+ tapdata->tap = NULL;
+
+ return 0;
+}
+
+void
+Cocoa_InitMouseEventTap(SDL_MouseData* driverdata)
+{
+ SDL_MouseEventTapData *tapdata;
+ driverdata->tapdata = SDL_calloc(1, sizeof(SDL_MouseEventTapData));
+ tapdata = (SDL_MouseEventTapData*)driverdata->tapdata;
+
+ tapdata->runloopStartedSemaphore = SDL_CreateSemaphore(0);
+ if (tapdata->runloopStartedSemaphore) {
+ tapdata->tap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap,
+ kCGEventTapOptionDefault, allGrabbedEventsMask,
+ &Cocoa_MouseTapCallback, tapdata);
+ if (tapdata->tap) {
+ /* Tap starts disabled, until app requests mouse grab */
+ CGEventTapEnable(tapdata->tap, false);
+ tapdata->thread = SDL_CreateThreadInternal(&Cocoa_MouseTapThread, "Event Tap Loop", 512 * 1024, tapdata);
+ if (tapdata->thread) {
+ /* Success - early out. Ownership transferred to thread. */
+ return;
+ }
+ CFRelease(tapdata->tap);
+ }
+ SDL_DestroySemaphore(tapdata->runloopStartedSemaphore);
+ }
+ SDL_free(driverdata->tapdata);
+ driverdata->tapdata = NULL;
+}
+
+void
+Cocoa_EnableMouseEventTap(SDL_MouseData *driverdata, SDL_bool enabled)
+{
+ SDL_MouseEventTapData *tapdata = (SDL_MouseEventTapData*)driverdata->tapdata;
+ if (tapdata && tapdata->tap)
+ {
+ CGEventTapEnable(tapdata->tap, !!enabled);
+ }
+}
+
+void
+Cocoa_QuitMouseEventTap(SDL_MouseData *driverdata)
+{
+ SDL_MouseEventTapData *tapdata = (SDL_MouseEventTapData*)driverdata->tapdata;
+ int status;
+
+ /* Ensure that the runloop has been started first.
+ * TODO: Move this to InitMouseEventTap, check for error conditions that can
+ * happen in Cocoa_MouseTapThread, and fall back to the non-EventTap way of
+ * grabbing the mouse if it fails to Init.
+ */
+ status = SDL_SemWaitTimeout(tapdata->runloopStartedSemaphore, 5000);
+ if (status > -1) {
+ /* Then stop it, which will cause Cocoa_MouseTapThread to return. */
+ CFRunLoopStop(tapdata->runloop);
+ /* And then wait for Cocoa_MouseTapThread to finish cleaning up. It
+ * releases some of the pointers in tapdata. */
+ SDL_WaitThread(tapdata->thread, &status);
+ }
+
+ SDL_free(driverdata->tapdata);
+ driverdata->tapdata = NULL;
+}
+
+#else /* SDL_MAC_NO_SANDBOX */
+
+void
+Cocoa_InitMouseEventTap(SDL_MouseData *unused)
+{
+}
+
+void
+Cocoa_EnableMouseEventTap(SDL_MouseData *driverdata, SDL_bool enabled)
+{
+}
+
+void
+Cocoa_QuitMouseEventTap(SDL_MouseData *driverdata)
+{
+}
+
+#endif /* !SDL_MAC_NO_SANDBOX */
+
+#endif /* SDL_VIDEO_DRIVER_COCOA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaopengl.h b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaopengl.h
new file mode 100644
index 0000000..81ca5ed
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaopengl.h
@@ -0,0 +1,68 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_cocoaopengl_h_
+#define SDL_cocoaopengl_h_
+
+#if SDL_VIDEO_OPENGL_CGL
+
+#include "SDL_atomic.h"
+#import <Cocoa/Cocoa.h>
+
+struct SDL_GLDriverData
+{
+ int initialized;
+};
+
+@interface SDLOpenGLContext : NSOpenGLContext {
+ SDL_atomic_t dirty;
+ SDL_Window *window;
+}
+
+- (id)initWithFormat:(NSOpenGLPixelFormat *)format
+ shareContext:(NSOpenGLContext *)share;
+- (void)scheduleUpdate;
+- (void)updateIfNeeded;
+- (void)setWindow:(SDL_Window *)window;
+
+@end
+
+
+/* OpenGL functions */
+extern int Cocoa_GL_LoadLibrary(_THIS, const char *path);
+extern void *Cocoa_GL_GetProcAddress(_THIS, const char *proc);
+extern void Cocoa_GL_UnloadLibrary(_THIS);
+extern SDL_GLContext Cocoa_GL_CreateContext(_THIS, SDL_Window * window);
+extern int Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window,
+ SDL_GLContext context);
+extern void Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window,
+ int * w, int * h);
+extern int Cocoa_GL_SetSwapInterval(_THIS, int interval);
+extern int Cocoa_GL_GetSwapInterval(_THIS);
+extern int Cocoa_GL_SwapWindow(_THIS, SDL_Window * window);
+extern void Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context);
+
+#endif /* SDL_VIDEO_OPENGL_CGL */
+
+#endif /* SDL_cocoaopengl_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaopengl.m b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaopengl.m
new file mode 100644
index 0000000..5f18a2e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaopengl.m
@@ -0,0 +1,428 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+/* NSOpenGL implementation of SDL OpenGL support */
+
+#if SDL_VIDEO_OPENGL_CGL
+#include "SDL_cocoavideo.h"
+#include "SDL_cocoaopengl.h"
+#include "SDL_cocoaopengles.h"
+
+#include <OpenGL/CGLTypes.h>
+#include <OpenGL/OpenGL.h>
+#include <OpenGL/CGLRenderers.h>
+
+#include "SDL_loadso.h"
+#include "SDL_opengl.h"
+
+#define DEFAULT_OPENGL "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
+
+@implementation SDLOpenGLContext : NSOpenGLContext
+
+- (id)initWithFormat:(NSOpenGLPixelFormat *)format
+ shareContext:(NSOpenGLContext *)share
+{
+ self = [super initWithFormat:format shareContext:share];
+ if (self) {
+ SDL_AtomicSet(&self->dirty, 0);
+ self->window = NULL;
+ }
+ return self;
+}
+
+- (void)scheduleUpdate
+{
+ SDL_AtomicAdd(&self->dirty, 1);
+}
+
+/* This should only be called on the thread on which a user is using the context. */
+- (void)updateIfNeeded
+{
+ int value = SDL_AtomicSet(&self->dirty, 0);
+ if (value > 0) {
+ /* We call the real underlying update here, since -[SDLOpenGLContext update] just calls us. */
+ [super update];
+ }
+}
+
+/* This should only be called on the thread on which a user is using the context. */
+- (void)update
+{
+ /* This ensures that regular 'update' calls clear the atomic dirty flag. */
+ [self scheduleUpdate];
+ [self updateIfNeeded];
+}
+
+/* Updates the drawable for the contexts and manages related state. */
+- (void)setWindow:(SDL_Window *)newWindow
+{
+ if (self->window) {
+ SDL_WindowData *oldwindowdata = (SDL_WindowData *)self->window->driverdata;
+
+ /* Make sure to remove us from the old window's context list, or we'll get scheduled updates from it too. */
+ NSMutableArray *contexts = oldwindowdata->nscontexts;
+ @synchronized (contexts) {
+ [contexts removeObject:self];
+ }
+ }
+
+ self->window = newWindow;
+
+ if (newWindow) {
+ SDL_WindowData *windowdata = (SDL_WindowData *)newWindow->driverdata;
+
+ /* Now sign up for scheduled updates for the new window. */
+ NSMutableArray *contexts = windowdata->nscontexts;
+ @synchronized (contexts) {
+ [contexts addObject:self];
+ }
+
+ if ([self view] != [windowdata->nswindow contentView]) {
+ [self setView:[windowdata->nswindow contentView]];
+ if (self == [NSOpenGLContext currentContext]) {
+ [self update];
+ } else {
+ [self scheduleUpdate];
+ }
+ }
+ } else {
+ [self clearDrawable];
+ if (self == [NSOpenGLContext currentContext]) {
+ [self update];
+ } else {
+ [self scheduleUpdate];
+ }
+ }
+}
+
+@end
+
+
+int
+Cocoa_GL_LoadLibrary(_THIS, const char *path)
+{
+ /* Load the OpenGL library */
+ if (path == NULL) {
+ path = SDL_getenv("SDL_OPENGL_LIBRARY");
+ }
+ if (path == NULL) {
+ path = DEFAULT_OPENGL;
+ }
+ _this->gl_config.dll_handle = SDL_LoadObject(path);
+ if (!_this->gl_config.dll_handle) {
+ return -1;
+ }
+ SDL_strlcpy(_this->gl_config.driver_path, path,
+ SDL_arraysize(_this->gl_config.driver_path));
+ return 0;
+}
+
+void *
+Cocoa_GL_GetProcAddress(_THIS, const char *proc)
+{
+ return SDL_LoadFunction(_this->gl_config.dll_handle, proc);
+}
+
+void
+Cocoa_GL_UnloadLibrary(_THIS)
+{
+ SDL_UnloadObject(_this->gl_config.dll_handle);
+ _this->gl_config.dll_handle = NULL;
+}
+
+SDL_GLContext
+Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
+{ @autoreleasepool
+{
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
+ SDL_bool lion_or_later = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
+ NSOpenGLPixelFormatAttribute attr[32];
+ NSOpenGLPixelFormat *fmt;
+ SDLOpenGLContext *context;
+ NSOpenGLContext *share_context = nil;
+ int i = 0;
+ const char *glversion;
+ int glversion_major;
+ int glversion_minor;
+
+ if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
+#if SDL_VIDEO_OPENGL_EGL
+ /* Switch to EGL based functions */
+ Cocoa_GL_UnloadLibrary(_this);
+ _this->GL_LoadLibrary = Cocoa_GLES_LoadLibrary;
+ _this->GL_GetProcAddress = Cocoa_GLES_GetProcAddress;
+ _this->GL_UnloadLibrary = Cocoa_GLES_UnloadLibrary;
+ _this->GL_CreateContext = Cocoa_GLES_CreateContext;
+ _this->GL_MakeCurrent = Cocoa_GLES_MakeCurrent;
+ _this->GL_SetSwapInterval = Cocoa_GLES_SetSwapInterval;
+ _this->GL_GetSwapInterval = Cocoa_GLES_GetSwapInterval;
+ _this->GL_SwapWindow = Cocoa_GLES_SwapWindow;
+ _this->GL_DeleteContext = Cocoa_GLES_DeleteContext;
+
+ if (Cocoa_GLES_LoadLibrary(_this, NULL) != 0) {
+ return NULL;
+ }
+ return Cocoa_GLES_CreateContext(_this, window);
+#else
+ SDL_SetError("SDL not configured with EGL support");
+ return NULL;
+#endif
+ }
+ if ((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) && !lion_or_later) {
+ SDL_SetError ("OpenGL Core Profile is not supported on this platform version");
+ return NULL;
+ }
+
+ attr[i++] = NSOpenGLPFAAllowOfflineRenderers;
+
+ /* specify a profile if we're on Lion (10.7) or later. */
+ if (lion_or_later) {
+ NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
+ if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
+ profile = NSOpenGLProfileVersion3_2Core;
+ }
+ attr[i++] = NSOpenGLPFAOpenGLProfile;
+ attr[i++] = profile;
+ }
+
+ attr[i++] = NSOpenGLPFAColorSize;
+ attr[i++] = SDL_BYTESPERPIXEL(display->current_mode.format)*8;
+
+ attr[i++] = NSOpenGLPFADepthSize;
+ attr[i++] = _this->gl_config.depth_size;
+
+ if (_this->gl_config.double_buffer) {
+ attr[i++] = NSOpenGLPFADoubleBuffer;
+ }
+
+ if (_this->gl_config.stereo) {
+ attr[i++] = NSOpenGLPFAStereo;
+ }
+
+ if (_this->gl_config.stencil_size) {
+ attr[i++] = NSOpenGLPFAStencilSize;
+ attr[i++] = _this->gl_config.stencil_size;
+ }
+
+ if ((_this->gl_config.accum_red_size +
+ _this->gl_config.accum_green_size +
+ _this->gl_config.accum_blue_size +
+ _this->gl_config.accum_alpha_size) > 0) {
+ attr[i++] = NSOpenGLPFAAccumSize;
+ attr[i++] = _this->gl_config.accum_red_size + _this->gl_config.accum_green_size + _this->gl_config.accum_blue_size + _this->gl_config.accum_alpha_size;
+ }
+
+ if (_this->gl_config.multisamplebuffers) {
+ attr[i++] = NSOpenGLPFASampleBuffers;
+ attr[i++] = _this->gl_config.multisamplebuffers;
+ }
+
+ if (_this->gl_config.multisamplesamples) {
+ attr[i++] = NSOpenGLPFASamples;
+ attr[i++] = _this->gl_config.multisamplesamples;
+ attr[i++] = NSOpenGLPFANoRecovery;
+ }
+
+ if (_this->gl_config.accelerated >= 0) {
+ if (_this->gl_config.accelerated) {
+ attr[i++] = NSOpenGLPFAAccelerated;
+ } else {
+ attr[i++] = NSOpenGLPFARendererID;
+ attr[i++] = kCGLRendererGenericFloatID;
+ }
+ }
+
+ attr[i++] = NSOpenGLPFAScreenMask;
+ attr[i++] = CGDisplayIDToOpenGLDisplayMask(displaydata->display);
+ attr[i] = 0;
+
+ fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
+ if (fmt == nil) {
+ SDL_SetError("Failed creating OpenGL pixel format");
+ return NULL;
+ }
+
+ if (_this->gl_config.share_with_current_context) {
+ share_context = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
+ }
+
+ context = [[SDLOpenGLContext alloc] initWithFormat:fmt shareContext:share_context];
+
+ [fmt release];
+
+ if (context == nil) {
+ SDL_SetError("Failed creating OpenGL context");
+ return NULL;
+ }
+
+ if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) {
+ Cocoa_GL_DeleteContext(_this, context);
+ SDL_SetError("Failed making OpenGL context current");
+ return NULL;
+ }
+
+ if (_this->gl_config.major_version < 3 &&
+ _this->gl_config.profile_mask == 0 &&
+ _this->gl_config.flags == 0) {
+ /* This is a legacy profile, so to match other backends, we're done. */
+ } else {
+ const GLubyte *(APIENTRY * glGetStringFunc)(GLenum);
+
+ glGetStringFunc = (const GLubyte *(APIENTRY *)(GLenum)) SDL_GL_GetProcAddress("glGetString");
+ if (!glGetStringFunc) {
+ Cocoa_GL_DeleteContext(_this, context);
+ SDL_SetError ("Failed getting OpenGL glGetString entry point");
+ return NULL;
+ }
+
+ glversion = (const char *)glGetStringFunc(GL_VERSION);
+ if (glversion == NULL) {
+ Cocoa_GL_DeleteContext(_this, context);
+ SDL_SetError ("Failed getting OpenGL context version");
+ return NULL;
+ }
+
+ if (SDL_sscanf(glversion, "%d.%d", &glversion_major, &glversion_minor) != 2) {
+ Cocoa_GL_DeleteContext(_this, context);
+ SDL_SetError ("Failed parsing OpenGL context version");
+ return NULL;
+ }
+
+ if ((glversion_major < _this->gl_config.major_version) ||
+ ((glversion_major == _this->gl_config.major_version) && (glversion_minor < _this->gl_config.minor_version))) {
+ Cocoa_GL_DeleteContext(_this, context);
+ SDL_SetError ("Failed creating OpenGL context at version requested");
+ return NULL;
+ }
+
+ /* In the future we'll want to do this, but to match other platforms
+ we'll leave the OpenGL version the way it is for now
+ */
+ /*_this->gl_config.major_version = glversion_major;*/
+ /*_this->gl_config.minor_version = glversion_minor;*/
+ }
+ return context;
+}}
+
+int
+Cocoa_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
+{ @autoreleasepool
+{
+ if (context) {
+ SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
+ [nscontext setWindow:window];
+ [nscontext updateIfNeeded];
+ [nscontext makeCurrentContext];
+ } else {
+ [NSOpenGLContext clearCurrentContext];
+ }
+
+ return 0;
+}}
+
+void
+Cocoa_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
+{
+ SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
+ NSView *contentView = [windata->nswindow contentView];
+ NSRect viewport = [contentView bounds];
+
+ /* This gives us the correct viewport for a Retina-enabled view, only
+ * supported on 10.7+. */
+ if ([contentView respondsToSelector:@selector(convertRectToBacking:)]) {
+ viewport = [contentView convertRectToBacking:viewport];
+ }
+
+ if (w) {
+ *w = viewport.size.width;
+ }
+
+ if (h) {
+ *h = viewport.size.height;
+ }
+}
+
+int
+Cocoa_GL_SetSwapInterval(_THIS, int interval)
+{ @autoreleasepool
+{
+ NSOpenGLContext *nscontext;
+ GLint value;
+ int status;
+
+ if (interval < 0) { /* no extension for this on Mac OS X at the moment. */
+ return SDL_SetError("Late swap tearing currently unsupported");
+ }
+
+ nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
+ if (nscontext != nil) {
+ value = interval;
+ [nscontext setValues:&value forParameter:NSOpenGLCPSwapInterval];
+ status = 0;
+ } else {
+ status = SDL_SetError("No current OpenGL context");
+ }
+
+ return status;
+}}
+
+int
+Cocoa_GL_GetSwapInterval(_THIS)
+{ @autoreleasepool
+{
+ NSOpenGLContext *nscontext;
+ GLint value;
+ int status = 0;
+
+ nscontext = (NSOpenGLContext*)SDL_GL_GetCurrentContext();
+ if (nscontext != nil) {
+ [nscontext getValues:&value forParameter:NSOpenGLCPSwapInterval];
+ status = (int)value;
+ }
+
+ return status;
+}}
+
+int
+Cocoa_GL_SwapWindow(_THIS, SDL_Window * window)
+{ @autoreleasepool
+{
+ SDLOpenGLContext* nscontext = (SDLOpenGLContext*)SDL_GL_GetCurrentContext();
+ [nscontext flushBuffer];
+ [nscontext updateIfNeeded];
+ return 0;
+}}
+
+void
+Cocoa_GL_DeleteContext(_THIS, SDL_GLContext context)
+{ @autoreleasepool
+{
+ SDLOpenGLContext *nscontext = (SDLOpenGLContext *)context;
+
+ [nscontext setWindow:NULL];
+ [nscontext release];
+}}
+
+#endif /* SDL_VIDEO_OPENGL_CGL */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaopengles.h b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaopengles.h
new file mode 100644
index 0000000..fc7f5c0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaopengles.h
@@ -0,0 +1,49 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_cocoaopengles_h_
+#define SDL_cocoaopengles_h_
+
+#if SDL_VIDEO_OPENGL_EGL
+
+#include "../SDL_sysvideo.h"
+#include "../SDL_egl_c.h"
+
+/* OpenGLES functions */
+#define Cocoa_GLES_GetAttribute SDL_EGL_GetAttribute
+#define Cocoa_GLES_GetProcAddress SDL_EGL_GetProcAddress
+#define Cocoa_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
+#define Cocoa_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
+#define Cocoa_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
+
+extern int Cocoa_GLES_LoadLibrary(_THIS, const char *path);
+extern SDL_GLContext Cocoa_GLES_CreateContext(_THIS, SDL_Window * window);
+extern int Cocoa_GLES_SwapWindow(_THIS, SDL_Window * window);
+extern int Cocoa_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+extern void Cocoa_GLES_DeleteContext(_THIS, SDL_GLContext context);
+extern int Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window);
+
+#endif /* SDL_VIDEO_OPENGL_EGL */
+
+#endif /* SDL_cocoaopengles_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaopengles.m b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaopengles.m
new file mode 100644
index 0000000..e0a05a1
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoaopengles.m
@@ -0,0 +1,132 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_COCOA && SDL_VIDEO_OPENGL_EGL
+
+#include "SDL_cocoavideo.h"
+#include "SDL_cocoaopengles.h"
+#include "SDL_cocoaopengl.h"
+#include "SDL_log.h"
+
+/* EGL implementation of SDL OpenGL support */
+
+int
+Cocoa_GLES_LoadLibrary(_THIS, const char *path) {
+
+ /* If the profile requested is not GL ES, switch over to WIN_GL functions */
+ if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
+#if SDL_VIDEO_OPENGL_CGL
+ Cocoa_GLES_UnloadLibrary(_this);
+ _this->GL_LoadLibrary = Cocoa_GL_LoadLibrary;
+ _this->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
+ _this->GL_UnloadLibrary = Cocoa_GL_UnloadLibrary;
+ _this->GL_CreateContext = Cocoa_GL_CreateContext;
+ _this->GL_MakeCurrent = Cocoa_GL_MakeCurrent;
+ _this->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
+ _this->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval;
+ _this->GL_SwapWindow = Cocoa_GL_SwapWindow;
+ _this->GL_DeleteContext = Cocoa_GL_DeleteContext;
+ return Cocoa_GL_LoadLibrary(_this, path);
+#else
+ return SDL_SetError("SDL not configured with OpenGL/CGL support");
+#endif
+ }
+
+ if (_this->egl_data == NULL) {
+ return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, 0);
+ }
+
+ return 0;
+}
+
+SDL_GLContext
+Cocoa_GLES_CreateContext(_THIS, SDL_Window * window)
+{
+ SDL_GLContext context;
+ SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+
+#if SDL_VIDEO_OPENGL_CGL
+ if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
+ /* Switch to CGL based functions */
+ Cocoa_GLES_UnloadLibrary(_this);
+ _this->GL_LoadLibrary = Cocoa_GL_LoadLibrary;
+ _this->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
+ _this->GL_UnloadLibrary = Cocoa_GL_UnloadLibrary;
+ _this->GL_CreateContext = Cocoa_GL_CreateContext;
+ _this->GL_MakeCurrent = Cocoa_GL_MakeCurrent;
+ _this->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
+ _this->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval;
+ _this->GL_SwapWindow = Cocoa_GL_SwapWindow;
+ _this->GL_DeleteContext = Cocoa_GL_DeleteContext;
+
+ if (Cocoa_GL_LoadLibrary(_this, NULL) != 0) {
+ return NULL;
+ }
+
+ return Cocoa_GL_CreateContext(_this, window);
+ }
+#endif
+
+ context = SDL_EGL_CreateContext(_this, data->egl_surface);
+ return context;
+}
+
+void
+Cocoa_GLES_DeleteContext(_THIS, SDL_GLContext context)
+{
+ SDL_EGL_DeleteContext(_this, context);
+ Cocoa_GLES_UnloadLibrary(_this);
+}
+
+SDL_EGL_SwapWindow_impl(Cocoa)
+SDL_EGL_MakeCurrent_impl(Cocoa)
+
+int
+Cocoa_GLES_SetupWindow(_THIS, SDL_Window * window)
+{
+ /* The current context is lost in here; save it and reset it. */
+ SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
+ SDL_Window *current_win = SDL_GL_GetCurrentWindow();
+ SDL_GLContext current_ctx = SDL_GL_GetCurrentContext();
+
+
+ if (_this->egl_data == NULL) {
+ if (SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, 0) < 0) {
+ SDL_EGL_UnloadLibrary(_this);
+ return -1;
+ }
+ }
+
+ /* Create the GLES window surface */
+ NSView* v = windowdata->nswindow.contentView;
+ windowdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType)[v layer]);
+
+ if (windowdata->egl_surface == EGL_NO_SURFACE) {
+ return SDL_SetError("Could not create GLES window surface");
+ }
+
+ return Cocoa_GLES_MakeCurrent(_this, current_win, current_ctx);
+}
+
+#endif /* SDL_VIDEO_DRIVER_COCOA && SDL_VIDEO_OPENGL_EGL */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoashape.h b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoashape.h
new file mode 100644
index 0000000..da1b5eb
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoashape.h
@@ -0,0 +1,45 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_cocoashape_h_
+#define SDL_cocoashape_h_
+
+#include "SDL_stdinc.h"
+#include "SDL_video.h"
+#include "SDL_shape.h"
+#include "../SDL_shape_internals.h"
+
+typedef struct {
+ NSGraphicsContext* context;
+ SDL_bool saved;
+
+ SDL_ShapeTree* shape;
+} SDL_ShapeData;
+
+extern SDL_WindowShaper* Cocoa_CreateShaper(SDL_Window* window);
+extern int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
+extern int Cocoa_ResizeWindowShape(SDL_Window *window);
+
+#endif /* SDL_cocoashape_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoashape.m b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoashape.m
new file mode 100644
index 0000000..7a2f04f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoashape.m
@@ -0,0 +1,113 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_COCOA
+
+#include "SDL_cocoavideo.h"
+#include "SDL_shape.h"
+#include "SDL_cocoashape.h"
+#include "../SDL_sysvideo.h"
+#include "SDL_assert.h"
+
+SDL_WindowShaper*
+Cocoa_CreateShaper(SDL_Window* window)
+{
+ SDL_WindowData* windata = (SDL_WindowData*)window->driverdata;
+ [windata->nswindow setOpaque:NO];
+
+ [windata->nswindow setStyleMask:NSWindowStyleMaskBorderless];
+
+ SDL_WindowShaper* result = result = malloc(sizeof(SDL_WindowShaper));
+ result->window = window;
+ result->mode.mode = ShapeModeDefault;
+ result->mode.parameters.binarizationCutoff = 1;
+ result->userx = result->usery = 0;
+ window->shaper = result;
+
+ SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData));
+ result->driverdata = data;
+ data->context = [windata->nswindow graphicsContext];
+ data->saved = SDL_FALSE;
+ data->shape = NULL;
+
+ int resized_properly = Cocoa_ResizeWindowShape(window);
+ SDL_assert(resized_properly == 0);
+ return result;
+}
+
+typedef struct {
+ NSView* view;
+ NSBezierPath* path;
+ SDL_Window* window;
+} SDL_CocoaClosure;
+
+void
+ConvertRects(SDL_ShapeTree* tree, void* closure)
+{
+ SDL_CocoaClosure* data = (SDL_CocoaClosure*)closure;
+ if(tree->kind == OpaqueShape) {
+ NSRect rect = NSMakeRect(tree->data.shape.x,data->window->h - tree->data.shape.y,tree->data.shape.w,tree->data.shape.h);
+ [data->path appendBezierPathWithRect:[data->view convertRect:rect toView:nil]];
+ }
+}
+
+int
+Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode)
+{ @autoreleasepool
+{
+ SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
+ SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata;
+ SDL_CocoaClosure closure;
+ if(data->saved == SDL_TRUE) {
+ [data->context restoreGraphicsState];
+ data->saved = SDL_FALSE;
+ }
+
+ /*[data->context saveGraphicsState];*/
+ /*data->saved = SDL_TRUE;*/
+ [NSGraphicsContext setCurrentContext:data->context];
+
+ [[NSColor clearColor] set];
+ NSRectFill([[windata->nswindow contentView] frame]);
+ data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
+
+ closure.view = [windata->nswindow contentView];
+ closure.path = [NSBezierPath bezierPath];
+ closure.window = shaper->window;
+ SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
+ [closure.path addClip];
+
+ return 0;
+}}
+
+int
+Cocoa_ResizeWindowShape(SDL_Window *window)
+{
+ SDL_ShapeData* data = window->shaper->driverdata;
+ SDL_assert(data != NULL);
+ return 0;
+}
+
+#endif /* SDL_VIDEO_DRIVER_COCOA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoavideo.h b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoavideo.h
new file mode 100644
index 0000000..05bbd34
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoavideo.h
@@ -0,0 +1,118 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_cocoavideo_h_
+#define SDL_cocoavideo_h_
+
+#include "SDL_opengl.h"
+
+#include <ApplicationServices/ApplicationServices.h>
+#include <IOKit/pwr_mgt/IOPMLib.h>
+#include <Cocoa/Cocoa.h>
+
+#include "SDL_keycode.h"
+#include "../SDL_sysvideo.h"
+
+#include "SDL_cocoaclipboard.h"
+#include "SDL_cocoaevents.h"
+#include "SDL_cocoakeyboard.h"
+#include "SDL_cocoamodes.h"
+#include "SDL_cocoamouse.h"
+#include "SDL_cocoaopengl.h"
+#include "SDL_cocoawindow.h"
+
+#ifndef MAC_OS_X_VERSION_10_12
+#define DECLARE_EVENT(name) static const NSEventType NSEventType##name = NS##name
+DECLARE_EVENT(LeftMouseDown);
+DECLARE_EVENT(LeftMouseUp);
+DECLARE_EVENT(RightMouseDown);
+DECLARE_EVENT(RightMouseUp);
+DECLARE_EVENT(OtherMouseDown);
+DECLARE_EVENT(OtherMouseUp);
+DECLARE_EVENT(MouseMoved);
+DECLARE_EVENT(LeftMouseDragged);
+DECLARE_EVENT(RightMouseDragged);
+DECLARE_EVENT(OtherMouseDragged);
+DECLARE_EVENT(ScrollWheel);
+DECLARE_EVENT(KeyDown);
+DECLARE_EVENT(KeyUp);
+DECLARE_EVENT(FlagsChanged);
+#undef DECLARE_EVENT
+
+static const NSEventMask NSEventMaskAny = NSAnyEventMask;
+
+#define DECLARE_MODIFIER_FLAG(name) static const NSUInteger NSEventModifierFlag##name = NS##name##KeyMask
+DECLARE_MODIFIER_FLAG(Shift);
+DECLARE_MODIFIER_FLAG(Control);
+DECLARE_MODIFIER_FLAG(Command);
+DECLARE_MODIFIER_FLAG(NumericPad);
+DECLARE_MODIFIER_FLAG(Help);
+DECLARE_MODIFIER_FLAG(Function);
+#undef DECLARE_MODIFIER_FLAG
+static const NSUInteger NSEventModifierFlagCapsLock = NSAlphaShiftKeyMask;
+static const NSUInteger NSEventModifierFlagOption = NSAlternateKeyMask;
+
+#define DECLARE_WINDOW_MASK(name) static const unsigned int NSWindowStyleMask##name = NS##name##WindowMask
+DECLARE_WINDOW_MASK(Borderless);
+DECLARE_WINDOW_MASK(Titled);
+DECLARE_WINDOW_MASK(Closable);
+DECLARE_WINDOW_MASK(Miniaturizable);
+DECLARE_WINDOW_MASK(Resizable);
+DECLARE_WINDOW_MASK(TexturedBackground);
+DECLARE_WINDOW_MASK(UnifiedTitleAndToolbar);
+DECLARE_WINDOW_MASK(FullScreen);
+/*DECLARE_WINDOW_MASK(FullSizeContentView);*/ /* Not used, fails compile on older SDKs */
+static const unsigned int NSWindowStyleMaskUtilityWindow = NSUtilityWindowMask;
+static const unsigned int NSWindowStyleMaskDocModalWindow = NSDocModalWindowMask;
+static const unsigned int NSWindowStyleMaskHUDWindow = NSHUDWindowMask;
+#undef DECLARE_WINDOW_MASK
+
+#define DECLARE_ALERT_STYLE(name) static const NSUInteger NSAlertStyle##name = NS##name##AlertStyle
+DECLARE_ALERT_STYLE(Warning);
+DECLARE_ALERT_STYLE(Informational);
+DECLARE_ALERT_STYLE(Critical);
+#undef DECLARE_ALERT_STYLE
+#endif
+
+/* Private display data */
+
+@class SDLTranslatorResponder;
+
+typedef struct SDL_VideoData
+{
+ int allow_spaces;
+ unsigned int modifierFlags;
+ void *key_layout;
+ SDLTranslatorResponder *fieldEdit;
+ NSInteger clipboard_count;
+ Uint32 screensaver_activity;
+ BOOL screensaver_use_iopm;
+ IOPMAssertionID screensaver_assertion;
+
+} SDL_VideoData;
+
+/* Utility functions */
+extern NSImage * Cocoa_CreateImage(SDL_Surface * surface);
+
+#endif /* SDL_cocoavideo_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoavideo.m b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoavideo.m
new file mode 100644
index 0000000..545dc1e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoavideo.m
@@ -0,0 +1,253 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_COCOA
+
+#include "SDL.h"
+#include "SDL_endian.h"
+#include "SDL_cocoavideo.h"
+#include "SDL_cocoashape.h"
+#include "SDL_cocoavulkan.h"
+#include "SDL_assert.h"
+
+/* Initialization/Query functions */
+static int Cocoa_VideoInit(_THIS);
+static void Cocoa_VideoQuit(_THIS);
+
+/* Cocoa driver bootstrap functions */
+
+static int
+Cocoa_Available(void)
+{
+ return (1);
+}
+
+static void
+Cocoa_DeleteDevice(SDL_VideoDevice * device)
+{
+ SDL_free(device->driverdata);
+ SDL_free(device);
+}
+
+static SDL_VideoDevice *
+Cocoa_CreateDevice(int devindex)
+{
+ SDL_VideoDevice *device;
+ SDL_VideoData *data;
+
+ Cocoa_RegisterApp();
+
+ /* Initialize all variables that we clean on shutdown */
+ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (device) {
+ data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
+ } else {
+ data = NULL;
+ }
+ if (!data) {
+ SDL_OutOfMemory();
+ SDL_free(device);
+ return NULL;
+ }
+ device->driverdata = data;
+
+ /* Set the function pointers */
+ device->VideoInit = Cocoa_VideoInit;
+ device->VideoQuit = Cocoa_VideoQuit;
+ device->GetDisplayBounds = Cocoa_GetDisplayBounds;
+ device->GetDisplayUsableBounds = Cocoa_GetDisplayUsableBounds;
+ device->GetDisplayDPI = Cocoa_GetDisplayDPI;
+ device->GetDisplayModes = Cocoa_GetDisplayModes;
+ device->SetDisplayMode = Cocoa_SetDisplayMode;
+ device->PumpEvents = Cocoa_PumpEvents;
+ device->SuspendScreenSaver = Cocoa_SuspendScreenSaver;
+
+ device->CreateSDLWindow = Cocoa_CreateWindow;
+ device->CreateSDLWindowFrom = Cocoa_CreateWindowFrom;
+ device->SetWindowTitle = Cocoa_SetWindowTitle;
+ device->SetWindowIcon = Cocoa_SetWindowIcon;
+ device->SetWindowPosition = Cocoa_SetWindowPosition;
+ device->SetWindowSize = Cocoa_SetWindowSize;
+ device->SetWindowMinimumSize = Cocoa_SetWindowMinimumSize;
+ device->SetWindowMaximumSize = Cocoa_SetWindowMaximumSize;
+ device->SetWindowOpacity = Cocoa_SetWindowOpacity;
+ device->ShowWindow = Cocoa_ShowWindow;
+ device->HideWindow = Cocoa_HideWindow;
+ device->RaiseWindow = Cocoa_RaiseWindow;
+ device->MaximizeWindow = Cocoa_MaximizeWindow;
+ device->MinimizeWindow = Cocoa_MinimizeWindow;
+ device->RestoreWindow = Cocoa_RestoreWindow;
+ device->SetWindowBordered = Cocoa_SetWindowBordered;
+ device->SetWindowResizable = Cocoa_SetWindowResizable;
+ device->SetWindowFullscreen = Cocoa_SetWindowFullscreen;
+ device->SetWindowGammaRamp = Cocoa_SetWindowGammaRamp;
+ device->GetWindowGammaRamp = Cocoa_GetWindowGammaRamp;
+ device->SetWindowGrab = Cocoa_SetWindowGrab;
+ device->DestroyWindow = Cocoa_DestroyWindow;
+ device->GetWindowWMInfo = Cocoa_GetWindowWMInfo;
+ device->SetWindowHitTest = Cocoa_SetWindowHitTest;
+
+ device->shape_driver.CreateShaper = Cocoa_CreateShaper;
+ device->shape_driver.SetWindowShape = Cocoa_SetWindowShape;
+ device->shape_driver.ResizeWindowShape = Cocoa_ResizeWindowShape;
+
+#if SDL_VIDEO_OPENGL_CGL
+ device->GL_LoadLibrary = Cocoa_GL_LoadLibrary;
+ device->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
+ device->GL_UnloadLibrary = Cocoa_GL_UnloadLibrary;
+ device->GL_CreateContext = Cocoa_GL_CreateContext;
+ device->GL_MakeCurrent = Cocoa_GL_MakeCurrent;
+ device->GL_GetDrawableSize = Cocoa_GL_GetDrawableSize;
+ device->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
+ device->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval;
+ device->GL_SwapWindow = Cocoa_GL_SwapWindow;
+ device->GL_DeleteContext = Cocoa_GL_DeleteContext;
+#elif SDL_VIDEO_OPENGL_EGL
+ device->GL_LoadLibrary = Cocoa_GLES_LoadLibrary;
+ device->GL_GetProcAddress = Cocoa_GLES_GetProcAddress;
+ device->GL_UnloadLibrary = Cocoa_GLES_UnloadLibrary;
+ device->GL_CreateContext = Cocoa_GLES_CreateContext;
+ device->GL_MakeCurrent = Cocoa_GLES_MakeCurrent;
+ device->GL_SetSwapInterval = Cocoa_GLES_SetSwapInterval;
+ device->GL_GetSwapInterval = Cocoa_GLES_GetSwapInterval;
+ device->GL_SwapWindow = Cocoa_GLES_SwapWindow;
+ device->GL_DeleteContext = Cocoa_GLES_DeleteContext;
+#endif
+
+#if SDL_VIDEO_VULKAN
+ device->Vulkan_LoadLibrary = Cocoa_Vulkan_LoadLibrary;
+ device->Vulkan_UnloadLibrary = Cocoa_Vulkan_UnloadLibrary;
+ device->Vulkan_GetInstanceExtensions = Cocoa_Vulkan_GetInstanceExtensions;
+ device->Vulkan_CreateSurface = Cocoa_Vulkan_CreateSurface;
+ device->Vulkan_GetDrawableSize = Cocoa_Vulkan_GetDrawableSize;
+#endif
+
+ device->StartTextInput = Cocoa_StartTextInput;
+ device->StopTextInput = Cocoa_StopTextInput;
+ device->SetTextInputRect = Cocoa_SetTextInputRect;
+
+ device->SetClipboardText = Cocoa_SetClipboardText;
+ device->GetClipboardText = Cocoa_GetClipboardText;
+ device->HasClipboardText = Cocoa_HasClipboardText;
+
+ device->free = Cocoa_DeleteDevice;
+
+ return device;
+}
+
+VideoBootStrap COCOA_bootstrap = {
+ "cocoa", "SDL Cocoa video driver",
+ Cocoa_Available, Cocoa_CreateDevice
+};
+
+
+int
+Cocoa_VideoInit(_THIS)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
+ Cocoa_InitModes(_this);
+ Cocoa_InitKeyboard(_this);
+ Cocoa_InitMouse(_this);
+
+ data->allow_spaces = ((floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) && SDL_GetHintBoolean(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, SDL_TRUE));
+
+ /* The IOPM assertion API can disable the screensaver as of 10.7. */
+ data->screensaver_use_iopm = floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6;
+
+ return 0;
+}
+
+void
+Cocoa_VideoQuit(_THIS)
+{
+ Cocoa_QuitModes(_this);
+ Cocoa_QuitKeyboard(_this);
+ Cocoa_QuitMouse(_this);
+}
+
+/* This function assumes that it's called from within an autorelease pool */
+NSImage *
+Cocoa_CreateImage(SDL_Surface * surface)
+{
+ SDL_Surface *converted;
+ NSBitmapImageRep *imgrep;
+ Uint8 *pixels;
+ int i;
+ NSImage *img;
+
+ converted = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA32, 0);
+ if (!converted) {
+ return nil;
+ }
+
+ imgrep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL
+ pixelsWide: converted->w
+ pixelsHigh: converted->h
+ bitsPerSample: 8
+ samplesPerPixel: 4
+ hasAlpha: YES
+ isPlanar: NO
+ colorSpaceName: NSDeviceRGBColorSpace
+ bytesPerRow: converted->pitch
+ bitsPerPixel: converted->format->BitsPerPixel] autorelease];
+ if (imgrep == nil) {
+ SDL_FreeSurface(converted);
+ return nil;
+ }
+
+ /* Copy the pixels */
+ pixels = [imgrep bitmapData];
+ SDL_memcpy(pixels, converted->pixels, converted->h * converted->pitch);
+ SDL_FreeSurface(converted);
+
+ /* Premultiply the alpha channel */
+ for (i = (surface->h * surface->w); i--; ) {
+ Uint8 alpha = pixels[3];
+ pixels[0] = (Uint8)(((Uint16)pixels[0] * alpha) / 255);
+ pixels[1] = (Uint8)(((Uint16)pixels[1] * alpha) / 255);
+ pixels[2] = (Uint8)(((Uint16)pixels[2] * alpha) / 255);
+ pixels += 4;
+ }
+
+ img = [[[NSImage alloc] initWithSize: NSMakeSize(surface->w, surface->h)] autorelease];
+ if (img != nil) {
+ [img addRepresentation: imgrep];
+ }
+ return img;
+}
+
+/*
+ * Mac OS X log support.
+ *
+ * This doesn't really have aything to do with the interfaces of the SDL video
+ * subsystem, but we need to stuff this into an Objective-C source code file.
+ */
+
+void SDL_NSLog(const char *text)
+{
+ NSLog(@"%s", text);
+}
+
+#endif /* SDL_VIDEO_DRIVER_COCOA */
+
+/* vim: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoavulkan.h b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoavulkan.h
new file mode 100644
index 0000000..a49c148
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoavulkan.h
@@ -0,0 +1,55 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ * @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's
+ * SDL_x11vulkan.h.
+ */
+
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_cocoavulkan_h_
+#define SDL_cocoavulkan_h_
+
+#include "../SDL_vulkan_internal.h"
+#include "../SDL_sysvideo.h"
+
+#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_COCOA
+
+int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path);
+void Cocoa_Vulkan_UnloadLibrary(_THIS);
+SDL_bool Cocoa_Vulkan_GetInstanceExtensions(_THIS,
+ SDL_Window *window,
+ unsigned *count,
+ const char **names);
+SDL_bool Cocoa_Vulkan_CreateSurface(_THIS,
+ SDL_Window *window,
+ VkInstance instance,
+ VkSurfaceKHR *surface);
+
+void Cocoa_Vulkan_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h);
+
+#endif
+
+#endif /* SDL_cocoavulkan_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoavulkan.m b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoavulkan.m
new file mode 100644
index 0000000..2cf55bb
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoavulkan.m
@@ -0,0 +1,231 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ * @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's
+ * SDL_x11vulkan.c.
+ */
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_COCOA
+
+#include "SDL_cocoavideo.h"
+#include "SDL_cocoawindow.h"
+#include "SDL_assert.h"
+
+#include "SDL_loadso.h"
+#include "SDL_cocoametalview.h"
+#include "SDL_cocoavulkan.h"
+#include "SDL_syswm.h"
+
+#include <dlfcn.h>
+
+const char* defaultPaths[] = {
+ "vulkan.framework/vulkan",
+ "libvulkan.1.dylib",
+ "MoltenVK.framework/MoltenVK",
+ "libMoltenVK.dylib"
+};
+
+/* Since libSDL is most likely a .dylib, need RTLD_DEFAULT not RTLD_SELF. */
+#define DEFAULT_HANDLE RTLD_DEFAULT
+
+int Cocoa_Vulkan_LoadLibrary(_THIS, const char *path)
+{
+ VkExtensionProperties *extensions = NULL;
+ Uint32 extensionCount = 0;
+ SDL_bool hasSurfaceExtension = SDL_FALSE;
+ SDL_bool hasMacOSSurfaceExtension = SDL_FALSE;
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
+
+ if (_this->vulkan_config.loader_handle) {
+ SDL_SetError("Vulkan/MoltenVK already loaded");
+ return -1;
+ }
+
+ /* Load the Vulkan loader library */
+ if (!path) {
+ path = SDL_getenv("SDL_VULKAN_LIBRARY");
+ }
+
+ if (!path) {
+ /* MoltenVK framework, currently, v0.17.0, has a static library and is
+ * the recommended way to use the package. There is likely no object to
+ * load. */
+ vkGetInstanceProcAddr =
+ (PFN_vkGetInstanceProcAddr)dlsym(DEFAULT_HANDLE,
+ "vkGetInstanceProcAddr");
+ }
+
+ if (vkGetInstanceProcAddr) {
+ _this->vulkan_config.loader_handle = DEFAULT_HANDLE;
+ } else {
+ const char** paths;
+ int numPaths;
+ int i;
+
+ if (path) {
+ paths = &path;
+ numPaths = 1;
+ } else {
+ /* Look for framework or .dylib packaged with the application
+ * instead. */
+ paths = defaultPaths;
+ numPaths = SDL_arraysize(defaultPaths);
+ }
+
+ for (i=0; i < numPaths; i++) {
+ _this->vulkan_config.loader_handle = SDL_LoadObject(paths[i]);
+ if (_this->vulkan_config.loader_handle)
+ break;
+ else
+ continue;
+ }
+ if (i == numPaths)
+ return -1;
+
+ SDL_strlcpy(_this->vulkan_config.loader_path, paths[i],
+ SDL_arraysize(_this->vulkan_config.loader_path));
+ vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction(
+ _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr");
+ }
+
+ if (!vkGetInstanceProcAddr) {
+ SDL_SetError("Failed to find %s in either executable or %s: %s",
+ "vkGetInstanceProcAddr",
+ _this->vulkan_config.loader_path,
+ (const char *) dlerror());
+ goto fail;
+ }
+
+ _this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr;
+ _this->vulkan_config.vkEnumerateInstanceExtensionProperties =
+ (void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)(
+ VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties");
+ if (!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) {
+ goto fail;
+ }
+ extensions = SDL_Vulkan_CreateInstanceExtensionsList(
+ (PFN_vkEnumerateInstanceExtensionProperties)
+ _this->vulkan_config.vkEnumerateInstanceExtensionProperties,
+ &extensionCount);
+ if (!extensions) {
+ goto fail;
+ }
+ for (Uint32 i = 0; i < extensionCount; i++) {
+ if (SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) {
+ hasSurfaceExtension = SDL_TRUE;
+ } else if (SDL_strcmp(VK_MVK_MACOS_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) {
+ hasMacOSSurfaceExtension = SDL_TRUE;
+ }
+ }
+ SDL_free(extensions);
+ if (!hasSurfaceExtension) {
+ SDL_SetError("Installed MoltenVK/Vulkan doesn't implement the "
+ VK_KHR_SURFACE_EXTENSION_NAME " extension");
+ goto fail;
+ } else if (!hasMacOSSurfaceExtension) {
+ SDL_SetError("Installed MoltenVK/Vulkan doesn't implement the "
+ VK_MVK_MACOS_SURFACE_EXTENSION_NAME "extension");
+ goto fail;
+ }
+ return 0;
+
+fail:
+ SDL_UnloadObject(_this->vulkan_config.loader_handle);
+ _this->vulkan_config.loader_handle = NULL;
+ return -1;
+}
+
+void Cocoa_Vulkan_UnloadLibrary(_THIS)
+{
+ if (_this->vulkan_config.loader_handle) {
+ if (_this->vulkan_config.loader_handle != DEFAULT_HANDLE) {
+ SDL_UnloadObject(_this->vulkan_config.loader_handle);
+ }
+ _this->vulkan_config.loader_handle = NULL;
+ }
+}
+
+SDL_bool Cocoa_Vulkan_GetInstanceExtensions(_THIS,
+ SDL_Window *window,
+ unsigned *count,
+ const char **names)
+{
+ static const char *const extensionsForCocoa[] = {
+ VK_KHR_SURFACE_EXTENSION_NAME, VK_MVK_MACOS_SURFACE_EXTENSION_NAME
+ };
+ if (!_this->vulkan_config.loader_handle) {
+ SDL_SetError("Vulkan is not loaded");
+ return SDL_FALSE;
+ }
+ return SDL_Vulkan_GetInstanceExtensions_Helper(
+ count, names, SDL_arraysize(extensionsForCocoa),
+ extensionsForCocoa);
+}
+
+SDL_bool Cocoa_Vulkan_CreateSurface(_THIS,
+ SDL_Window *window,
+ VkInstance instance,
+ VkSurfaceKHR *surface)
+{
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
+ (PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr;
+ PFN_vkCreateMacOSSurfaceMVK vkCreateMacOSSurfaceMVK =
+ (PFN_vkCreateMacOSSurfaceMVK)vkGetInstanceProcAddr(
+ (VkInstance)instance,
+ "vkCreateMacOSSurfaceMVK");
+ VkMacOSSurfaceCreateInfoMVK createInfo = {};
+ VkResult result;
+
+ if (!_this->vulkan_config.loader_handle) {
+ SDL_SetError("Vulkan is not loaded");
+ return SDL_FALSE;
+ }
+
+ if (!vkCreateMacOSSurfaceMVK) {
+ SDL_SetError(VK_MVK_MACOS_SURFACE_EXTENSION_NAME
+ " extension is not enabled in the Vulkan instance.");
+ return SDL_FALSE;
+ }
+ createInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
+ createInfo.pNext = NULL;
+ createInfo.flags = 0;
+ createInfo.pView = Cocoa_Mtl_AddMetalView(window);
+ result = vkCreateMacOSSurfaceMVK(instance, &createInfo,
+ NULL, surface);
+ if (result != VK_SUCCESS) {
+ SDL_SetError("vkCreateMacOSSurfaceMVK failed: %s",
+ SDL_Vulkan_GetResultString(result));
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
+}
+
+void Cocoa_Vulkan_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h)
+{
+ Cocoa_Mtl_GetDrawableSize(window, w, h);
+}
+
+#endif
+
+/* vim: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoawindow.h b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoawindow.h
new file mode 100644
index 0000000..df6f173
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoawindow.h
@@ -0,0 +1,154 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_cocoawindow_h_
+#define SDL_cocoawindow_h_
+
+#import <Cocoa/Cocoa.h>
+
+#if SDL_VIDEO_OPENGL_EGL
+#include "../SDL_egl_c.h"
+#endif
+
+typedef struct SDL_WindowData SDL_WindowData;
+
+typedef enum
+{
+ PENDING_OPERATION_NONE,
+ PENDING_OPERATION_ENTER_FULLSCREEN,
+ PENDING_OPERATION_LEAVE_FULLSCREEN,
+ PENDING_OPERATION_MINIMIZE
+} PendingWindowOperation;
+
+@interface Cocoa_WindowListener : NSResponder <NSWindowDelegate> {
+ SDL_WindowData *_data;
+ BOOL observingVisible;
+ BOOL wasCtrlLeft;
+ BOOL wasVisible;
+ BOOL isFullscreenSpace;
+ BOOL inFullscreenTransition;
+ PendingWindowOperation pendingWindowOperation;
+ BOOL isMoving;
+ int pendingWindowWarpX, pendingWindowWarpY;
+ BOOL isDragAreaRunning;
+}
+
+-(void) listen:(SDL_WindowData *) data;
+-(void) pauseVisibleObservation;
+-(void) resumeVisibleObservation;
+-(BOOL) setFullscreenSpace:(BOOL) state;
+-(BOOL) isInFullscreenSpace;
+-(BOOL) isInFullscreenSpaceTransition;
+-(void) addPendingWindowOperation:(PendingWindowOperation) operation;
+-(void) close;
+
+-(BOOL) isMoving;
+-(void) setPendingMoveX:(int)x Y:(int)y;
+-(void) windowDidFinishMoving;
+
+/* Window delegate functionality */
+-(BOOL) windowShouldClose:(id) sender;
+-(void) windowDidExpose:(NSNotification *) aNotification;
+-(void) windowDidMove:(NSNotification *) aNotification;
+-(void) windowDidResize:(NSNotification *) aNotification;
+-(void) windowDidMiniaturize:(NSNotification *) aNotification;
+-(void) windowDidDeminiaturize:(NSNotification *) aNotification;
+-(void) windowDidBecomeKey:(NSNotification *) aNotification;
+-(void) windowDidResignKey:(NSNotification *) aNotification;
+-(void) windowDidChangeBackingProperties:(NSNotification *) aNotification;
+-(void) windowWillEnterFullScreen:(NSNotification *) aNotification;
+-(void) windowDidEnterFullScreen:(NSNotification *) aNotification;
+-(void) windowWillExitFullScreen:(NSNotification *) aNotification;
+-(void) windowDidExitFullScreen:(NSNotification *) aNotification;
+-(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions;
+
+/* See if event is in a drag area, toggle on window dragging. */
+-(BOOL) processHitTest:(NSEvent *)theEvent;
+
+/* Window event handling */
+-(void) mouseDown:(NSEvent *) theEvent;
+-(void) rightMouseDown:(NSEvent *) theEvent;
+-(void) otherMouseDown:(NSEvent *) theEvent;
+-(void) mouseUp:(NSEvent *) theEvent;
+-(void) rightMouseUp:(NSEvent *) theEvent;
+-(void) otherMouseUp:(NSEvent *) theEvent;
+-(void) mouseMoved:(NSEvent *) theEvent;
+-(void) mouseDragged:(NSEvent *) theEvent;
+-(void) rightMouseDragged:(NSEvent *) theEvent;
+-(void) otherMouseDragged:(NSEvent *) theEvent;
+-(void) scrollWheel:(NSEvent *) theEvent;
+-(void) touchesBeganWithEvent:(NSEvent *) theEvent;
+-(void) touchesMovedWithEvent:(NSEvent *) theEvent;
+-(void) touchesEndedWithEvent:(NSEvent *) theEvent;
+-(void) touchesCancelledWithEvent:(NSEvent *) theEvent;
+
+/* Touch event handling */
+-(void) handleTouches:(NSTouchPhase) phase withEvent:(NSEvent*) theEvent;
+
+@end
+/* *INDENT-ON* */
+
+@class SDLOpenGLContext;
+
+struct SDL_WindowData
+{
+ SDL_Window *window;
+ NSWindow *nswindow;
+ NSMutableArray *nscontexts;
+ SDL_bool created;
+ SDL_bool inWindowMove;
+ Cocoa_WindowListener *listener;
+ struct SDL_VideoData *videodata;
+#if SDL_VIDEO_OPENGL_EGL
+ EGLSurface egl_surface;
+#endif
+};
+
+extern int Cocoa_CreateWindow(_THIS, SDL_Window * window);
+extern int Cocoa_CreateWindowFrom(_THIS, SDL_Window * window,
+ const void *data);
+extern void Cocoa_SetWindowTitle(_THIS, SDL_Window * window);
+extern void Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
+extern void Cocoa_SetWindowPosition(_THIS, SDL_Window * window);
+extern void Cocoa_SetWindowSize(_THIS, SDL_Window * window);
+extern void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window);
+extern void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window);
+extern int Cocoa_SetWindowOpacity(_THIS, SDL_Window * window, float opacity);
+extern void Cocoa_ShowWindow(_THIS, SDL_Window * window);
+extern void Cocoa_HideWindow(_THIS, SDL_Window * window);
+extern void Cocoa_RaiseWindow(_THIS, SDL_Window * window);
+extern void Cocoa_MaximizeWindow(_THIS, SDL_Window * window);
+extern void Cocoa_MinimizeWindow(_THIS, SDL_Window * window);
+extern void Cocoa_RestoreWindow(_THIS, SDL_Window * window);
+extern void Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
+extern void Cocoa_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
+extern void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
+extern int Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
+extern int Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
+extern void Cocoa_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
+extern void Cocoa_DestroyWindow(_THIS, SDL_Window * window);
+extern SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info);
+extern int Cocoa_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
+
+#endif /* SDL_cocoawindow_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoawindow.m b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoawindow.m
new file mode 100644
index 0000000..b1a5b46
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/cocoa/SDL_cocoawindow.m
@@ -0,0 +1,1877 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_COCOA
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
+# error SDL for Mac OS X must be built with a 10.7 SDK or above.
+#endif /* MAC_OS_X_VERSION_MAX_ALLOWED < 1070 */
+
+#include "SDL_syswm.h"
+#include "SDL_timer.h" /* For SDL_GetTicks() */
+#include "SDL_hints.h"
+#include "../SDL_sysvideo.h"
+#include "../../events/SDL_keyboard_c.h"
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_touch_c.h"
+#include "../../events/SDL_windowevents_c.h"
+#include "../../events/SDL_dropevents_c.h"
+#include "SDL_cocoavideo.h"
+#include "SDL_cocoashape.h"
+#include "SDL_cocoamouse.h"
+#include "SDL_cocoamousetap.h"
+#include "SDL_cocoaopengl.h"
+#include "SDL_cocoaopengles.h"
+#include "SDL_assert.h"
+
+/* #define DEBUG_COCOAWINDOW */
+
+#ifdef DEBUG_COCOAWINDOW
+#define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
+#else
+#define DLog(...) do { } while (0)
+#endif
+
+
+#define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN)
+
+
+@interface SDLWindow : NSWindow <NSDraggingDestination>
+/* These are needed for borderless/fullscreen windows */
+- (BOOL)canBecomeKeyWindow;
+- (BOOL)canBecomeMainWindow;
+- (void)sendEvent:(NSEvent *)event;
+- (void)doCommandBySelector:(SEL)aSelector;
+
+/* Handle drag-and-drop of files onto the SDL window. */
+- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
+- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
+- (BOOL)wantsPeriodicDraggingUpdates;
+- (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
+
+- (SDL_Window*)findSDLWindow;
+@end
+
+@implementation SDLWindow
+
+- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
+{
+ /* Only allow using the macOS native fullscreen toggle menubar item if the
+ * window is resizable and not in a SDL fullscreen mode.
+ */
+ if ([menuItem action] == @selector(toggleFullScreen:)) {
+ SDL_Window *window = [self findSDLWindow];
+ if (window == NULL) {
+ return NO;
+ } else if ((window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_FULLSCREEN_DESKTOP)) != 0) {
+ return NO;
+ } else if ((window->flags & SDL_WINDOW_RESIZABLE) == 0) {
+ return NO;
+ }
+ }
+ return [super validateMenuItem:menuItem];
+}
+
+- (BOOL)canBecomeKeyWindow
+{
+ return YES;
+}
+
+- (BOOL)canBecomeMainWindow
+{
+ return YES;
+}
+
+- (void)sendEvent:(NSEvent *)event
+{
+ [super sendEvent:event];
+
+ if ([event type] != NSEventTypeLeftMouseUp) {
+ return;
+ }
+
+ id delegate = [self delegate];
+ if (![delegate isKindOfClass:[Cocoa_WindowListener class]]) {
+ return;
+ }
+
+ if ([delegate isMoving]) {
+ [delegate windowDidFinishMoving];
+ }
+}
+
+/* We'll respond to selectors by doing nothing so we don't beep.
+ * The escape key gets converted to a "cancel" selector, etc.
+ */
+- (void)doCommandBySelector:(SEL)aSelector
+{
+ /*NSLog(@"doCommandBySelector: %@\n", NSStringFromSelector(aSelector));*/
+}
+
+- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
+{
+ if (([sender draggingSourceOperationMask] & NSDragOperationGeneric) == NSDragOperationGeneric) {
+ return NSDragOperationGeneric;
+ }
+
+ return NSDragOperationNone; /* no idea what to do with this, reject it. */
+}
+
+- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
+{ @autoreleasepool
+{
+ NSPasteboard *pasteboard = [sender draggingPasteboard];
+ NSArray *types = [NSArray arrayWithObject:NSFilenamesPboardType];
+ NSString *desiredType = [pasteboard availableTypeFromArray:types];
+ SDL_Window *sdlwindow = [self findSDLWindow];
+
+ if (desiredType == nil) {
+ return NO; /* can't accept anything that's being dropped here. */
+ }
+
+ NSData *data = [pasteboard dataForType:desiredType];
+ if (data == nil) {
+ return NO;
+ }
+
+ SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
+ NSArray *array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
+
+ for (NSString *path in array) {
+ NSURL *fileURL = [NSURL fileURLWithPath:path];
+ NSNumber *isAlias = nil;
+
+ [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
+
+ /* If the URL is an alias, resolve it. */
+ if ([isAlias boolValue]) {
+ NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
+ NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
+ if (bookmark != nil) {
+ NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
+ options:opts
+ relativeToURL:nil
+ bookmarkDataIsStale:nil
+ error:nil];
+
+ if (resolvedURL != nil) {
+ fileURL = resolvedURL;
+ }
+ }
+ }
+
+ if (!SDL_SendDropFile(sdlwindow, [[fileURL path] UTF8String])) {
+ return NO;
+ }
+ }
+
+ SDL_SendDropComplete(sdlwindow);
+ return YES;
+}}
+
+- (BOOL)wantsPeriodicDraggingUpdates
+{
+ return NO;
+}
+
+- (SDL_Window*)findSDLWindow
+{
+ SDL_Window *sdlwindow = NULL;
+ SDL_VideoDevice *_this = SDL_GetVideoDevice();
+
+ /* !!! FIXME: is there a better way to do this? */
+ if (_this) {
+ for (sdlwindow = _this->windows; sdlwindow; sdlwindow = sdlwindow->next) {
+ NSWindow *nswindow = ((SDL_WindowData *) sdlwindow->driverdata)->nswindow;
+ if (nswindow == self) {
+ break;
+ }
+ }
+ }
+
+ return sdlwindow;
+}
+
+@end
+
+
+static Uint32 s_moveHack;
+
+static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r)
+{
+ r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
+}
+
+static void
+ScheduleContextUpdates(SDL_WindowData *data)
+{
+ NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
+ NSMutableArray *contexts = data->nscontexts;
+ @synchronized (contexts) {
+ for (SDLOpenGLContext *context in contexts) {
+ if (context == currentContext) {
+ [context update];
+ } else {
+ [context scheduleUpdate];
+ }
+ }
+ }
+}
+
+/* !!! FIXME: this should use a hint callback. */
+static int
+GetHintCtrlClickEmulateRightClick()
+{
+ return SDL_GetHintBoolean(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, SDL_FALSE);
+}
+
+static NSUInteger
+GetWindowStyle(SDL_Window * window)
+{
+ NSUInteger style = 0;
+
+ if (window->flags & SDL_WINDOW_FULLSCREEN) {
+ style = NSWindowStyleMaskBorderless;
+ } else {
+ if (window->flags & SDL_WINDOW_BORDERLESS) {
+ style = NSWindowStyleMaskBorderless;
+ } else {
+ style = (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable);
+ }
+ if (window->flags & SDL_WINDOW_RESIZABLE) {
+ style |= NSWindowStyleMaskResizable;
+ }
+ }
+ return style;
+}
+
+static SDL_bool
+SetWindowStyle(SDL_Window * window, NSUInteger style)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ NSWindow *nswindow = data->nswindow;
+
+ /* The view responder chain gets messed with during setStyleMask */
+ if ([[nswindow contentView] nextResponder] == data->listener) {
+ [[nswindow contentView] setNextResponder:nil];
+ }
+
+ [nswindow setStyleMask:style];
+
+ /* The view responder chain gets messed with during setStyleMask */
+ if ([[nswindow contentView] nextResponder] != data->listener) {
+ [[nswindow contentView] setNextResponder:data->listener];
+ }
+
+ return SDL_TRUE;
+}
+
+
+@implementation Cocoa_WindowListener
+
+- (void)listen:(SDL_WindowData *)data
+{
+ NSNotificationCenter *center;
+ NSWindow *window = data->nswindow;
+ NSView *view = [window contentView];
+
+ _data = data;
+ observingVisible = YES;
+ wasCtrlLeft = NO;
+ wasVisible = [window isVisible];
+ isFullscreenSpace = NO;
+ inFullscreenTransition = NO;
+ pendingWindowOperation = PENDING_OPERATION_NONE;
+ isMoving = NO;
+ isDragAreaRunning = NO;
+
+ center = [NSNotificationCenter defaultCenter];
+
+ if ([window delegate] != nil) {
+ [center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
+ [center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
+ [center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
+ [center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
+ [center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
+ [center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
+ [center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
+ [center addObserver:self selector:@selector(windowDidChangeBackingProperties:) name:NSWindowDidChangeBackingPropertiesNotification object:window];
+ [center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window];
+ [center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window];
+ [center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window];
+ [center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window];
+ [center addObserver:self selector:@selector(windowDidFailToEnterFullScreen:) name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
+ [center addObserver:self selector:@selector(windowDidFailToExitFullScreen:) name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
+ } else {
+ [window setDelegate:self];
+ }
+
+ /* Haven't found a delegate / notification that triggers when the window is
+ * ordered out (is not visible any more). You can be ordered out without
+ * minimizing, so DidMiniaturize doesn't work. (e.g. -[NSWindow orderOut:])
+ */
+ [window addObserver:self
+ forKeyPath:@"visible"
+ options:NSKeyValueObservingOptionNew
+ context:NULL];
+
+ [window setNextResponder:self];
+ [window setAcceptsMouseMovedEvents:YES];
+
+ [view setNextResponder:self];
+
+ [view setAcceptsTouchEvents:YES];
+}
+
+- (void)observeValueForKeyPath:(NSString *)keyPath
+ ofObject:(id)object
+ change:(NSDictionary *)change
+ context:(void *)context
+{
+ if (!observingVisible) {
+ return;
+ }
+
+ if (object == _data->nswindow && [keyPath isEqualToString:@"visible"]) {
+ int newVisibility = [[change objectForKey:@"new"] intValue];
+ if (newVisibility) {
+ SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
+ } else {
+ SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
+ }
+ }
+}
+
+-(void) pauseVisibleObservation
+{
+ observingVisible = NO;
+ wasVisible = [_data->nswindow isVisible];
+}
+
+-(void) resumeVisibleObservation
+{
+ BOOL isVisible = [_data->nswindow isVisible];
+ observingVisible = YES;
+ if (wasVisible != isVisible) {
+ if (isVisible) {
+ SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
+ } else {
+ SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
+ }
+
+ wasVisible = isVisible;
+ }
+}
+
+-(BOOL) setFullscreenSpace:(BOOL) state
+{
+ SDL_Window *window = _data->window;
+ NSWindow *nswindow = _data->nswindow;
+ SDL_VideoData *videodata = ((SDL_WindowData *) window->driverdata)->videodata;
+
+ if (!videodata->allow_spaces) {
+ return NO; /* Spaces are forcibly disabled. */
+ } else if (state && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP)) {
+ return NO; /* we only allow you to make a Space on FULLSCREEN_DESKTOP windows. */
+ } else if (!state && ((window->last_fullscreen_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP)) {
+ return NO; /* we only handle leaving the Space on windows that were previously FULLSCREEN_DESKTOP. */
+ } else if (state == isFullscreenSpace) {
+ return YES; /* already there. */
+ }
+
+ if (inFullscreenTransition) {
+ if (state) {
+ [self addPendingWindowOperation:PENDING_OPERATION_ENTER_FULLSCREEN];
+ } else {
+ [self addPendingWindowOperation:PENDING_OPERATION_LEAVE_FULLSCREEN];
+ }
+ return YES;
+ }
+ inFullscreenTransition = YES;
+
+ /* you need to be FullScreenPrimary, or toggleFullScreen doesn't work. Unset it again in windowDidExitFullScreen. */
+ [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
+ [nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
+ return YES;
+}
+
+-(BOOL) isInFullscreenSpace
+{
+ return isFullscreenSpace;
+}
+
+-(BOOL) isInFullscreenSpaceTransition
+{
+ return inFullscreenTransition;
+}
+
+-(void) addPendingWindowOperation:(PendingWindowOperation) operation
+{
+ pendingWindowOperation = operation;
+}
+
+- (void)close
+{
+ NSNotificationCenter *center;
+ NSWindow *window = _data->nswindow;
+ NSView *view = [window contentView];
+
+ center = [NSNotificationCenter defaultCenter];
+
+ if ([window delegate] != self) {
+ [center removeObserver:self name:NSWindowDidExposeNotification object:window];
+ [center removeObserver:self name:NSWindowDidMoveNotification object:window];
+ [center removeObserver:self name:NSWindowDidResizeNotification object:window];
+ [center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
+ [center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
+ [center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
+ [center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
+ [center removeObserver:self name:NSWindowDidChangeBackingPropertiesNotification object:window];
+ [center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window];
+ [center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window];
+ [center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window];
+ [center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window];
+ [center removeObserver:self name:@"NSWindowDidFailToEnterFullScreenNotification" object:window];
+ [center removeObserver:self name:@"NSWindowDidFailToExitFullScreenNotification" object:window];
+ } else {
+ [window setDelegate:nil];
+ }
+
+ [window removeObserver:self forKeyPath:@"visible"];
+
+ if ([window nextResponder] == self) {
+ [window setNextResponder:nil];
+ }
+ if ([view nextResponder] == self) {
+ [view setNextResponder:nil];
+ }
+}
+
+- (BOOL)isMoving
+{
+ return isMoving;
+}
+
+-(void) setPendingMoveX:(int)x Y:(int)y
+{
+ pendingWindowWarpX = x;
+ pendingWindowWarpY = y;
+}
+
+- (void)windowDidFinishMoving
+{
+ if ([self isMoving]) {
+ isMoving = NO;
+
+ SDL_Mouse *mouse = SDL_GetMouse();
+ if (pendingWindowWarpX != INT_MAX && pendingWindowWarpY != INT_MAX) {
+ mouse->WarpMouseGlobal(pendingWindowWarpX, pendingWindowWarpY);
+ pendingWindowWarpX = pendingWindowWarpY = INT_MAX;
+ }
+ if (mouse->relative_mode && !mouse->relative_mode_warp && mouse->focus == _data->window) {
+ mouse->SetRelativeMouseMode(SDL_TRUE);
+ }
+ }
+}
+
+- (BOOL)windowShouldClose:(id)sender
+{
+ SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
+ return NO;
+}
+
+- (void)windowDidExpose:(NSNotification *)aNotification
+{
+ SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
+}
+
+- (void)windowWillMove:(NSNotification *)aNotification
+{
+ if ([_data->nswindow isKindOfClass:[SDLWindow class]]) {
+ pendingWindowWarpX = pendingWindowWarpY = INT_MAX;
+ isMoving = YES;
+ }
+}
+
+- (void)windowDidMove:(NSNotification *)aNotification
+{
+ int x, y;
+ SDL_Window *window = _data->window;
+ NSWindow *nswindow = _data->nswindow;
+ BOOL fullscreen = window->flags & FULLSCREEN_MASK;
+ NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
+ ConvertNSRect([nswindow screen], fullscreen, &rect);
+
+ if (inFullscreenTransition) {
+ /* We'll take care of this at the end of the transition */
+ return;
+ }
+
+ if (s_moveHack) {
+ SDL_bool blockMove = ((SDL_GetTicks() - s_moveHack) < 500);
+
+ s_moveHack = 0;
+
+ if (blockMove) {
+ /* Cocoa is adjusting the window in response to a mode change */
+ rect.origin.x = window->x;
+ rect.origin.y = window->y;
+ ConvertNSRect([nswindow screen], fullscreen, &rect);
+ [nswindow setFrameOrigin:rect.origin];
+ return;
+ }
+ }
+
+ x = (int)rect.origin.x;
+ y = (int)rect.origin.y;
+
+ ScheduleContextUpdates(_data);
+
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
+}
+
+- (void)windowDidResize:(NSNotification *)aNotification
+{
+ if (inFullscreenTransition) {
+ /* We'll take care of this at the end of the transition */
+ return;
+ }
+
+ SDL_Window *window = _data->window;
+ NSWindow *nswindow = _data->nswindow;
+ int x, y, w, h;
+ NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
+ ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
+ x = (int)rect.origin.x;
+ y = (int)rect.origin.y;
+ w = (int)rect.size.width;
+ h = (int)rect.size.height;
+
+ if (SDL_IsShapedWindow(window)) {
+ Cocoa_ResizeWindowShape(window);
+ }
+
+ ScheduleContextUpdates(_data);
+
+ /* The window can move during a resize event, such as when maximizing
+ or resizing from a corner */
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
+
+ const BOOL zoomed = [nswindow isZoomed];
+ if (!zoomed) {
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
+ } else if (zoomed) {
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
+ }
+}
+
+- (void)windowDidMiniaturize:(NSNotification *)aNotification
+{
+ SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
+}
+
+- (void)windowDidDeminiaturize:(NSNotification *)aNotification
+{
+ SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
+}
+
+- (void)windowDidBecomeKey:(NSNotification *)aNotification
+{
+ SDL_Window *window = _data->window;
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ /* We're going to get keyboard events, since we're key. */
+ /* This needs to be done before restoring the relative mouse mode. */
+ SDL_SetKeyboardFocus(window);
+
+ if (mouse->relative_mode && !mouse->relative_mode_warp && ![self isMoving]) {
+ mouse->SetRelativeMouseMode(SDL_TRUE);
+ }
+
+ /* If we just gained focus we need the updated mouse position */
+ if (!mouse->relative_mode) {
+ NSPoint point;
+ int x, y;
+
+ point = [_data->nswindow mouseLocationOutsideOfEventStream];
+ x = (int)point.x;
+ y = (int)(window->h - point.y);
+
+ if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
+ SDL_SendMouseMotion(window, 0, 0, x, y);
+ }
+ }
+
+ /* Check to see if someone updated the clipboard */
+ Cocoa_CheckClipboardUpdate(_data->videodata);
+
+ if ((isFullscreenSpace) && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)) {
+ [NSMenu setMenuBarVisible:NO];
+ }
+
+ const unsigned int newflags = [NSEvent modifierFlags] & NSEventModifierFlagCapsLock;
+ _data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSEventModifierFlagCapsLock) | newflags;
+ SDL_ToggleModState(KMOD_CAPS, newflags != 0);
+}
+
+- (void)windowDidResignKey:(NSNotification *)aNotification
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ if (mouse->relative_mode && !mouse->relative_mode_warp) {
+ mouse->SetRelativeMouseMode(SDL_FALSE);
+ }
+
+ /* Some other window will get mouse events, since we're not key. */
+ if (SDL_GetMouseFocus() == _data->window) {
+ SDL_SetMouseFocus(NULL);
+ }
+
+ /* Some other window will get keyboard events, since we're not key. */
+ if (SDL_GetKeyboardFocus() == _data->window) {
+ SDL_SetKeyboardFocus(NULL);
+ }
+
+ if (isFullscreenSpace) {
+ [NSMenu setMenuBarVisible:YES];
+ }
+}
+
+- (void)windowDidChangeBackingProperties:(NSNotification *)aNotification
+{
+ NSNumber *oldscale = [[aNotification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey];
+
+ if (inFullscreenTransition) {
+ return;
+ }
+
+ if ([oldscale doubleValue] != [_data->nswindow backingScaleFactor]) {
+ /* Force a resize event when the backing scale factor changes. */
+ _data->window->w = 0;
+ _data->window->h = 0;
+ [self windowDidResize:aNotification];
+ }
+}
+
+- (void)windowWillEnterFullScreen:(NSNotification *)aNotification
+{
+ SDL_Window *window = _data->window;
+
+ SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));
+
+ isFullscreenSpace = YES;
+ inFullscreenTransition = YES;
+}
+
+- (void)windowDidFailToEnterFullScreen:(NSNotification *)aNotification
+{
+ SDL_Window *window = _data->window;
+
+ if (window->is_destroying) {
+ return;
+ }
+
+ SetWindowStyle(window, GetWindowStyle(window));
+
+ isFullscreenSpace = NO;
+ inFullscreenTransition = NO;
+
+ [self windowDidExitFullScreen:nil];
+}
+
+- (void)windowDidEnterFullScreen:(NSNotification *)aNotification
+{
+ SDL_Window *window = _data->window;
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ NSWindow *nswindow = data->nswindow;
+
+ inFullscreenTransition = NO;
+
+ if (pendingWindowOperation == PENDING_OPERATION_LEAVE_FULLSCREEN) {
+ pendingWindowOperation = PENDING_OPERATION_NONE;
+ [self setFullscreenSpace:NO];
+ } else {
+ /* Unset the resizable flag.
+ This is a workaround for https://bugzilla.libsdl.org/show_bug.cgi?id=3697
+ */
+ SetWindowStyle(window, [nswindow styleMask] & (~NSWindowStyleMaskResizable));
+
+ if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
+ [NSMenu setMenuBarVisible:NO];
+ }
+
+ pendingWindowOperation = PENDING_OPERATION_NONE;
+ /* Force the size change event in case it was delivered earlier
+ while the window was still animating into place.
+ */
+ window->w = 0;
+ window->h = 0;
+ [self windowDidMove:aNotification];
+ [self windowDidResize:aNotification];
+ }
+}
+
+- (void)windowWillExitFullScreen:(NSNotification *)aNotification
+{
+ SDL_Window *window = _data->window;
+
+ isFullscreenSpace = NO;
+ inFullscreenTransition = YES;
+
+ /* As of OS X 10.11, the window seems to need to be resizable when exiting
+ a Space, in order for it to resize back to its windowed-mode size.
+ */
+ SetWindowStyle(window, GetWindowStyle(window) | NSWindowStyleMaskResizable);
+}
+
+- (void)windowDidFailToExitFullScreen:(NSNotification *)aNotification
+{
+ SDL_Window *window = _data->window;
+
+ if (window->is_destroying) {
+ return;
+ }
+
+ SetWindowStyle(window, (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable));
+
+ isFullscreenSpace = YES;
+ inFullscreenTransition = NO;
+
+ [self windowDidEnterFullScreen:nil];
+}
+
+- (void)windowDidExitFullScreen:(NSNotification *)aNotification
+{
+ SDL_Window *window = _data->window;
+ NSWindow *nswindow = _data->nswindow;
+
+ inFullscreenTransition = NO;
+
+ SetWindowStyle(window, GetWindowStyle(window));
+
+ [nswindow setLevel:kCGNormalWindowLevel];
+
+ if (pendingWindowOperation == PENDING_OPERATION_ENTER_FULLSCREEN) {
+ pendingWindowOperation = PENDING_OPERATION_NONE;
+ [self setFullscreenSpace:YES];
+ } else if (pendingWindowOperation == PENDING_OPERATION_MINIMIZE) {
+ pendingWindowOperation = PENDING_OPERATION_NONE;
+ [nswindow miniaturize:nil];
+ } else {
+ /* Adjust the fullscreen toggle button and readd menu now that we're here. */
+ if (window->flags & SDL_WINDOW_RESIZABLE) {
+ /* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */
+ [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
+ } else {
+ [nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
+ }
+ [NSMenu setMenuBarVisible:YES];
+
+ pendingWindowOperation = PENDING_OPERATION_NONE;
+
+#if 0
+/* This fixed bug 3719, which is that changing window size while fullscreen
+ doesn't take effect when leaving fullscreen, but introduces bug 3809,
+ which is that a maximized window doesn't go back to normal size when
+ restored, so this code is disabled until we can properly handle the
+ beginning and end of maximize and restore.
+ */
+ /* Restore windowed size and position in case it changed while fullscreen */
+ {
+ NSRect rect;
+ rect.origin.x = window->windowed.x;
+ rect.origin.y = window->windowed.y;
+ rect.size.width = window->windowed.w;
+ rect.size.height = window->windowed.h;
+ ConvertNSRect([nswindow screen], NO, &rect);
+
+ s_moveHack = 0;
+ [nswindow setContentSize:rect.size];
+ [nswindow setFrameOrigin:rect.origin];
+ s_moveHack = SDL_GetTicks();
+ }
+#endif /* 0 */
+
+ /* Force the size change event in case it was delivered earlier
+ while the window was still animating into place.
+ */
+ window->w = 0;
+ window->h = 0;
+ [self windowDidMove:aNotification];
+ [self windowDidResize:aNotification];
+
+ /* FIXME: Why does the window get hidden? */
+ if (window->flags & SDL_WINDOW_SHOWN) {
+ Cocoa_ShowWindow(SDL_GetVideoDevice(), window);
+ }
+ }
+}
+
+-(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
+{
+ if ((_data->window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
+ return NSApplicationPresentationFullScreen | NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
+ } else {
+ return proposedOptions;
+ }
+}
+
+
+/* We'll respond to key events by doing nothing so we don't beep.
+ * We could handle key messages here, but we lose some in the NSApp dispatch,
+ * where they get converted to action messages, etc.
+ */
+- (void)flagsChanged:(NSEvent *)theEvent
+{
+ /*Cocoa_HandleKeyEvent(SDL_GetVideoDevice(), theEvent);*/
+}
+- (void)keyDown:(NSEvent *)theEvent
+{
+ /*Cocoa_HandleKeyEvent(SDL_GetVideoDevice(), theEvent);*/
+}
+- (void)keyUp:(NSEvent *)theEvent
+{
+ /*Cocoa_HandleKeyEvent(SDL_GetVideoDevice(), theEvent);*/
+}
+
+/* We'll respond to selectors by doing nothing so we don't beep.
+ * The escape key gets converted to a "cancel" selector, etc.
+ */
+- (void)doCommandBySelector:(SEL)aSelector
+{
+ /*NSLog(@"doCommandBySelector: %@\n", NSStringFromSelector(aSelector));*/
+}
+
+- (BOOL)processHitTest:(NSEvent *)theEvent
+{
+ SDL_assert(isDragAreaRunning == [_data->nswindow isMovableByWindowBackground]);
+
+ if (_data->window->hit_test) { /* if no hit-test, skip this. */
+ const NSPoint location = [theEvent locationInWindow];
+ const SDL_Point point = { (int) location.x, _data->window->h - (((int) location.y)-1) };
+ const SDL_HitTestResult rc = _data->window->hit_test(_data->window, &point, _data->window->hit_test_data);
+ if (rc == SDL_HITTEST_DRAGGABLE) {
+ if (!isDragAreaRunning) {
+ isDragAreaRunning = YES;
+ [_data->nswindow setMovableByWindowBackground:YES];
+ }
+ return YES; /* dragging! */
+ }
+ }
+
+ if (isDragAreaRunning) {
+ isDragAreaRunning = NO;
+ [_data->nswindow setMovableByWindowBackground:NO];
+ return YES; /* was dragging, drop event. */
+ }
+
+ return NO; /* not a special area, carry on. */
+}
+
+- (void)mouseDown:(NSEvent *)theEvent
+{
+ int button;
+ int clicks;
+
+ /* Ignore events that aren't inside the client area (i.e. title bar.) */
+ if ([theEvent window]) {
+ NSRect windowRect = [[[theEvent window] contentView] frame];
+ if (!NSMouseInRect([theEvent locationInWindow], windowRect, NO)) {
+ return;
+ }
+ }
+
+ if ([self processHitTest:theEvent]) {
+ SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
+ return; /* dragging, drop event. */
+ }
+
+ switch ([theEvent buttonNumber]) {
+ case 0:
+ if (([theEvent modifierFlags] & NSEventModifierFlagControl) &&
+ GetHintCtrlClickEmulateRightClick()) {
+ wasCtrlLeft = YES;
+ button = SDL_BUTTON_RIGHT;
+ } else {
+ wasCtrlLeft = NO;
+ button = SDL_BUTTON_LEFT;
+ }
+ break;
+ case 1:
+ button = SDL_BUTTON_RIGHT;
+ break;
+ case 2:
+ button = SDL_BUTTON_MIDDLE;
+ break;
+ default:
+ button = (int) [theEvent buttonNumber] + 1;
+ break;
+ }
+
+ clicks = (int) [theEvent clickCount];
+ SDL_SendMouseButtonClicks(_data->window, 0, SDL_PRESSED, button, clicks);
+}
+
+- (void)rightMouseDown:(NSEvent *)theEvent
+{
+ [self mouseDown:theEvent];
+}
+
+- (void)otherMouseDown:(NSEvent *)theEvent
+{
+ [self mouseDown:theEvent];
+}
+
+- (void)mouseUp:(NSEvent *)theEvent
+{
+ int button;
+ int clicks;
+
+ if ([self processHitTest:theEvent]) {
+ SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
+ return; /* stopped dragging, drop event. */
+ }
+
+ switch ([theEvent buttonNumber]) {
+ case 0:
+ if (wasCtrlLeft) {
+ button = SDL_BUTTON_RIGHT;
+ wasCtrlLeft = NO;
+ } else {
+ button = SDL_BUTTON_LEFT;
+ }
+ break;
+ case 1:
+ button = SDL_BUTTON_RIGHT;
+ break;
+ case 2:
+ button = SDL_BUTTON_MIDDLE;
+ break;
+ default:
+ button = (int) [theEvent buttonNumber] + 1;
+ break;
+ }
+
+ clicks = (int) [theEvent clickCount];
+ SDL_SendMouseButtonClicks(_data->window, 0, SDL_RELEASED, button, clicks);
+}
+
+- (void)rightMouseUp:(NSEvent *)theEvent
+{
+ [self mouseUp:theEvent];
+}
+
+- (void)otherMouseUp:(NSEvent *)theEvent
+{
+ [self mouseUp:theEvent];
+}
+
+- (void)mouseMoved:(NSEvent *)theEvent
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ SDL_Window *window = _data->window;
+ NSPoint point;
+ int x, y;
+
+ if ([self processHitTest:theEvent]) {
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
+ return; /* dragging, drop event. */
+ }
+
+ if (mouse->relative_mode) {
+ return;
+ }
+
+ point = [theEvent locationInWindow];
+ x = (int)point.x;
+ y = (int)(window->h - point.y);
+
+ if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
+ if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
+ if (x < 0) {
+ x = 0;
+ } else if (x >= window->w) {
+ x = window->w - 1;
+ }
+ if (y < 0) {
+ y = 0;
+ } else if (y >= window->h) {
+ y = window->h - 1;
+ }
+
+#if !SDL_MAC_NO_SANDBOX
+ CGPoint cgpoint;
+
+ /* When SDL_MAC_NO_SANDBOX is set, this is handled by
+ * SDL_cocoamousetap.m.
+ */
+
+ cgpoint.x = window->x + x;
+ cgpoint.y = window->y + y;
+
+ CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
+ CGAssociateMouseAndMouseCursorPosition(YES);
+
+ Cocoa_HandleMouseWarp(cgpoint.x, cgpoint.y);
+#endif
+ }
+ }
+ SDL_SendMouseMotion(window, 0, 0, x, y);
+}
+
+- (void)mouseDragged:(NSEvent *)theEvent
+{
+ [self mouseMoved:theEvent];
+}
+
+- (void)rightMouseDragged:(NSEvent *)theEvent
+{
+ [self mouseMoved:theEvent];
+}
+
+- (void)otherMouseDragged:(NSEvent *)theEvent
+{
+ [self mouseMoved:theEvent];
+}
+
+- (void)scrollWheel:(NSEvent *)theEvent
+{
+ Cocoa_HandleMouseWheel(_data->window, theEvent);
+}
+
+- (void)touchesBeganWithEvent:(NSEvent *) theEvent
+{
+ NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
+ int existingTouchCount = 0;
+
+ for (NSTouch* touch in touches) {
+ if ([touch phase] != NSTouchPhaseBegan) {
+ existingTouchCount++;
+ }
+ }
+ if (existingTouchCount == 0) {
+ SDL_TouchID touchID = (SDL_TouchID)(intptr_t)[[touches anyObject] device];
+ int numFingers = SDL_GetNumTouchFingers(touchID);
+ DLog("Reset Lost Fingers: %d", numFingers);
+ for (--numFingers; numFingers >= 0; --numFingers) {
+ SDL_Finger* finger = SDL_GetTouchFinger(touchID, numFingers);
+ SDL_SendTouch(touchID, finger->id, SDL_FALSE, 0, 0, 0);
+ }
+ }
+
+ DLog("Began Fingers: %lu .. existing: %d", (unsigned long)[touches count], existingTouchCount);
+ [self handleTouches:NSTouchPhaseBegan withEvent:theEvent];
+}
+
+- (void)touchesMovedWithEvent:(NSEvent *) theEvent
+{
+ [self handleTouches:NSTouchPhaseMoved withEvent:theEvent];
+}
+
+- (void)touchesEndedWithEvent:(NSEvent *) theEvent
+{
+ [self handleTouches:NSTouchPhaseEnded withEvent:theEvent];
+}
+
+- (void)touchesCancelledWithEvent:(NSEvent *) theEvent
+{
+ [self handleTouches:NSTouchPhaseCancelled withEvent:theEvent];
+}
+
+- (void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
+{
+ NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
+
+ for (NSTouch *touch in touches) {
+ const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device];
+ if (SDL_AddTouch(touchId, "") < 0) {
+ return;
+ }
+
+ const SDL_FingerID fingerId = (SDL_FingerID)(intptr_t)[touch identity];
+ float x = [touch normalizedPosition].x;
+ float y = [touch normalizedPosition].y;
+ /* Make the origin the upper left instead of the lower left */
+ y = 1.0f - y;
+
+ switch (phase) {
+ case NSTouchPhaseBegan:
+ SDL_SendTouch(touchId, fingerId, SDL_TRUE, x, y, 1.0f);
+ break;
+ case NSTouchPhaseEnded:
+ case NSTouchPhaseCancelled:
+ SDL_SendTouch(touchId, fingerId, SDL_FALSE, x, y, 1.0f);
+ break;
+ case NSTouchPhaseMoved:
+ SDL_SendTouchMotion(touchId, fingerId, x, y, 1.0f);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+@end
+
+@interface SDLView : NSView {
+ SDL_Window *_sdlWindow;
+}
+
+- (void)setSDLWindow:(SDL_Window*)window;
+
+/* The default implementation doesn't pass rightMouseDown to responder chain */
+- (void)rightMouseDown:(NSEvent *)theEvent;
+- (BOOL)mouseDownCanMoveWindow;
+- (void)drawRect:(NSRect)dirtyRect;
+- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent;
+@end
+
+@implementation SDLView
+- (void)setSDLWindow:(SDL_Window*)window
+{
+ _sdlWindow = window;
+}
+
+- (void)drawRect:(NSRect)dirtyRect
+{
+ /* Force the graphics context to clear to black so we don't get a flash of
+ white until the app is ready to draw. In practice on modern macOS, this
+ only gets called for window creation and other extraordinary events. */
+ [[NSColor blackColor] setFill];
+ NSRectFill(dirtyRect);
+ SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0);
+}
+
+- (void)rightMouseDown:(NSEvent *)theEvent
+{
+ [[self nextResponder] rightMouseDown:theEvent];
+}
+
+- (BOOL)mouseDownCanMoveWindow
+{
+ /* Always say YES, but this doesn't do anything until we call
+ -[NSWindow setMovableByWindowBackground:YES], which we ninja-toggle
+ during mouse events when we're using a drag area. */
+ return YES;
+}
+
+- (void)resetCursorRects
+{
+ [super resetCursorRects];
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ if (mouse->cursor_shown && mouse->cur_cursor && !mouse->relative_mode) {
+ [self addCursorRect:[self bounds]
+ cursor:mouse->cur_cursor->driverdata];
+ } else {
+ [self addCursorRect:[self bounds]
+ cursor:[NSCursor invisibleCursor]];
+ }
+}
+
+- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
+{
+ if (SDL_GetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH)) {
+ return SDL_GetHintBoolean(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, SDL_FALSE);
+ } else {
+ return SDL_GetHintBoolean("SDL_MAC_MOUSE_FOCUS_CLICKTHROUGH", SDL_FALSE);
+ }
+}
+@end
+
+static int
+SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
+{ @autoreleasepool
+{
+ SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
+ SDL_WindowData *data;
+
+ /* Allocate the window data */
+ window->driverdata = data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
+ if (!data) {
+ return SDL_OutOfMemory();
+ }
+ data->window = window;
+ data->nswindow = nswindow;
+ data->created = created;
+ data->videodata = videodata;
+ data->nscontexts = [[NSMutableArray alloc] init];
+
+ /* Create an event listener for the window */
+ data->listener = [[Cocoa_WindowListener alloc] init];
+
+ /* Fill in the SDL window with the window data */
+ {
+ NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
+ ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
+ window->x = (int)rect.origin.x;
+ window->y = (int)rect.origin.y;
+ window->w = (int)rect.size.width;
+ window->h = (int)rect.size.height;
+ }
+
+ /* Set up the listener after we create the view */
+ [data->listener listen:data];
+
+ if ([nswindow isVisible]) {
+ window->flags |= SDL_WINDOW_SHOWN;
+ } else {
+ window->flags &= ~SDL_WINDOW_SHOWN;
+ }
+
+ {
+ unsigned long style = [nswindow styleMask];
+
+ if (style == NSWindowStyleMaskBorderless) {
+ window->flags |= SDL_WINDOW_BORDERLESS;
+ } else {
+ window->flags &= ~SDL_WINDOW_BORDERLESS;
+ }
+ if (style & NSWindowStyleMaskResizable) {
+ window->flags |= SDL_WINDOW_RESIZABLE;
+ } else {
+ window->flags &= ~SDL_WINDOW_RESIZABLE;
+ }
+ }
+
+ /* isZoomed always returns true if the window is not resizable */
+ if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
+ window->flags |= SDL_WINDOW_MAXIMIZED;
+ } else {
+ window->flags &= ~SDL_WINDOW_MAXIMIZED;
+ }
+
+ if ([nswindow isMiniaturized]) {
+ window->flags |= SDL_WINDOW_MINIMIZED;
+ } else {
+ window->flags &= ~SDL_WINDOW_MINIMIZED;
+ }
+
+ if ([nswindow isKeyWindow]) {
+ window->flags |= SDL_WINDOW_INPUT_FOCUS;
+ SDL_SetKeyboardFocus(data->window);
+ }
+
+ /* Prevents the window's "window device" from being destroyed when it is
+ * hidden. See http://www.mikeash.com/pyblog/nsopenglcontext-and-one-shot.html
+ */
+ [nswindow setOneShot:NO];
+
+ /* All done! */
+ window->driverdata = data;
+ return 0;
+}}
+
+int
+Cocoa_CreateWindow(_THIS, SDL_Window * window)
+{ @autoreleasepool
+{
+ SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
+ NSWindow *nswindow;
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ NSRect rect;
+ SDL_Rect bounds;
+ NSUInteger style;
+ NSArray *screens = [NSScreen screens];
+
+ Cocoa_GetDisplayBounds(_this, display, &bounds);
+ rect.origin.x = window->x;
+ rect.origin.y = window->y;
+ rect.size.width = window->w;
+ rect.size.height = window->h;
+ ConvertNSRect([screens objectAtIndex:0], (window->flags & FULLSCREEN_MASK), &rect);
+
+ style = GetWindowStyle(window);
+
+ /* Figure out which screen to place this window */
+ NSScreen *screen = nil;
+ for (NSScreen *candidate in screens) {
+ NSRect screenRect = [candidate frame];
+ if (rect.origin.x >= screenRect.origin.x &&
+ rect.origin.x < screenRect.origin.x + screenRect.size.width &&
+ rect.origin.y >= screenRect.origin.y &&
+ rect.origin.y < screenRect.origin.y + screenRect.size.height) {
+ screen = candidate;
+ rect.origin.x -= screenRect.origin.x;
+ rect.origin.y -= screenRect.origin.y;
+ }
+ }
+
+ @try {
+ nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
+ }
+ @catch (NSException *e) {
+ return SDL_SetError("%s", [[e reason] UTF8String]);
+ }
+
+ if (videodata->allow_spaces) {
+ SDL_assert(floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6);
+ SDL_assert([nswindow respondsToSelector:@selector(toggleFullScreen:)]);
+ /* we put FULLSCREEN_DESKTOP windows in their own Space, without a toggle button or menubar, later */
+ if (window->flags & SDL_WINDOW_RESIZABLE) {
+ /* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */
+ [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
+ }
+ }
+
+ /* Create a default view for this window */
+ rect = [nswindow contentRectForFrameRect:[nswindow frame]];
+ SDLView *contentView = [[SDLView alloc] initWithFrame:rect];
+ [contentView setSDLWindow:window];
+
+ if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
+ if ([contentView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
+ [contentView setWantsBestResolutionOpenGLSurface:YES];
+ }
+ }
+#if SDL_VIDEO_OPENGL_ES2
+#if SDL_VIDEO_OPENGL_EGL
+ if ((window->flags & SDL_WINDOW_OPENGL) &&
+ _this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
+ [contentView setWantsLayer:TRUE];
+ }
+#endif /* SDL_VIDEO_OPENGL_EGL */
+#endif /* SDL_VIDEO_OPENGL_ES2 */
+ [nswindow setContentView:contentView];
+ [contentView release];
+
+ /* Allow files and folders to be dragged onto the window by users */
+ [nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
+
+ if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
+ [nswindow release];
+ return -1;
+ }
+
+ if (!(window->flags & SDL_WINDOW_OPENGL)) {
+ return 0;
+ }
+
+ /* The rest of this macro mess is for OpenGL or OpenGL ES windows */
+#if SDL_VIDEO_OPENGL_ES2
+ if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
+#if SDL_VIDEO_OPENGL_EGL
+ if (Cocoa_GLES_SetupWindow(_this, window) < 0) {
+ Cocoa_DestroyWindow(_this, window);
+ return -1;
+ }
+ return 0;
+#else
+ return SDL_SetError("Could not create GLES window surface (EGL support not configured)");
+#endif /* SDL_VIDEO_OPENGL_EGL */
+ }
+#endif /* SDL_VIDEO_OPENGL_ES2 */
+ return 0;
+}}
+
+int
+Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
+{ @autoreleasepool
+{
+ NSWindow *nswindow = (NSWindow *) data;
+ NSString *title;
+
+ /* Query the title from the existing window */
+ title = [nswindow title];
+ if (title) {
+ window->title = SDL_strdup([title UTF8String]);
+ }
+
+ return SetupWindowData(_this, window, nswindow, SDL_FALSE);
+}}
+
+void
+Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
+{ @autoreleasepool
+{
+ const char *title = window->title ? window->title : "";
+ NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
+ NSString *string = [[NSString alloc] initWithUTF8String:title];
+ [nswindow setTitle:string];
+ [string release];
+}}
+
+void
+Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
+{ @autoreleasepool
+{
+ NSImage *nsimage = Cocoa_CreateImage(icon);
+
+ if (nsimage) {
+ [NSApp setApplicationIconImage:nsimage];
+ }
+}}
+
+void
+Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
+{ @autoreleasepool
+{
+ SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
+ NSWindow *nswindow = windata->nswindow;
+ NSRect rect;
+ Uint32 moveHack;
+
+ rect.origin.x = window->x;
+ rect.origin.y = window->y;
+ rect.size.width = window->w;
+ rect.size.height = window->h;
+ ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
+
+ moveHack = s_moveHack;
+ s_moveHack = 0;
+ [nswindow setFrameOrigin:rect.origin];
+ s_moveHack = moveHack;
+
+ ScheduleContextUpdates(windata);
+}}
+
+void
+Cocoa_SetWindowSize(_THIS, SDL_Window * window)
+{ @autoreleasepool
+{
+ SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
+ NSWindow *nswindow = windata->nswindow;
+ NSRect rect;
+ Uint32 moveHack;
+
+ /* Cocoa will resize the window from the bottom-left rather than the
+ * top-left when -[nswindow setContentSize:] is used, so we must set the
+ * entire frame based on the new size, in order to preserve the position.
+ */
+ rect.origin.x = window->x;
+ rect.origin.y = window->y;
+ rect.size.width = window->w;
+ rect.size.height = window->h;
+ ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
+
+ moveHack = s_moveHack;
+ s_moveHack = 0;
+ [nswindow setFrame:[nswindow frameRectForContentRect:rect] display:YES];
+ s_moveHack = moveHack;
+
+ ScheduleContextUpdates(windata);
+}}
+
+void
+Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
+{ @autoreleasepool
+{
+ SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
+
+ NSSize minSize;
+ minSize.width = window->min_w;
+ minSize.height = window->min_h;
+
+ [windata->nswindow setContentMinSize:minSize];
+}}
+
+void
+Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
+{ @autoreleasepool
+{
+ SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
+
+ NSSize maxSize;
+ maxSize.width = window->max_w;
+ maxSize.height = window->max_h;
+
+ [windata->nswindow setContentMaxSize:maxSize];
+}}
+
+void
+Cocoa_ShowWindow(_THIS, SDL_Window * window)
+{ @autoreleasepool
+{
+ SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
+ NSWindow *nswindow = windowData->nswindow;
+
+ if (![nswindow isMiniaturized]) {
+ [windowData->listener pauseVisibleObservation];
+ [nswindow makeKeyAndOrderFront:nil];
+ [windowData->listener resumeVisibleObservation];
+ }
+}}
+
+void
+Cocoa_HideWindow(_THIS, SDL_Window * window)
+{ @autoreleasepool
+{
+ NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
+
+ [nswindow orderOut:nil];
+}}
+
+void
+Cocoa_RaiseWindow(_THIS, SDL_Window * window)
+{ @autoreleasepool
+{
+ SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
+ NSWindow *nswindow = windowData->nswindow;
+
+ /* makeKeyAndOrderFront: has the side-effect of deminiaturizing and showing
+ a minimized or hidden window, so check for that before showing it.
+ */
+ [windowData->listener pauseVisibleObservation];
+ if (![nswindow isMiniaturized] && [nswindow isVisible]) {
+ [NSApp activateIgnoringOtherApps:YES];
+ [nswindow makeKeyAndOrderFront:nil];
+ }
+ [windowData->listener resumeVisibleObservation];
+}}
+
+void
+Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
+{ @autoreleasepool
+{
+ SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
+ NSWindow *nswindow = windata->nswindow;
+
+ [nswindow zoom:nil];
+
+ ScheduleContextUpdates(windata);
+}}
+
+void
+Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
+{ @autoreleasepool
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ NSWindow *nswindow = data->nswindow;
+
+ if ([data->listener isInFullscreenSpaceTransition]) {
+ [data->listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
+ } else {
+ [nswindow miniaturize:nil];
+ }
+}}
+
+void
+Cocoa_RestoreWindow(_THIS, SDL_Window * window)
+{ @autoreleasepool
+{
+ NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
+
+ if ([nswindow isMiniaturized]) {
+ [nswindow deminiaturize:nil];
+ } else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
+ [nswindow zoom:nil];
+ }
+}}
+
+void
+Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
+{ @autoreleasepool
+{
+ if (SetWindowStyle(window, GetWindowStyle(window))) {
+ if (bordered) {
+ Cocoa_SetWindowTitle(_this, window); /* this got blanked out. */
+ }
+ }
+}}
+
+void
+Cocoa_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable)
+{ @autoreleasepool
+{
+ /* Don't set this if we're in a space!
+ * The window will get permanently stuck if resizable is false.
+ * -flibit
+ */
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Cocoa_WindowListener *listener = data->listener;
+ if (![listener isInFullscreenSpace]) {
+ SetWindowStyle(window, GetWindowStyle(window));
+ }
+}}
+
+void
+Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
+{ @autoreleasepool
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ NSWindow *nswindow = data->nswindow;
+ NSRect rect;
+
+ /* The view responder chain gets messed with during setStyleMask */
+ if ([[nswindow contentView] nextResponder] == data->listener) {
+ [[nswindow contentView] setNextResponder:nil];
+ }
+
+ if (fullscreen) {
+ SDL_Rect bounds;
+
+ Cocoa_GetDisplayBounds(_this, display, &bounds);
+ rect.origin.x = bounds.x;
+ rect.origin.y = bounds.y;
+ rect.size.width = bounds.w;
+ rect.size.height = bounds.h;
+ ConvertNSRect([nswindow screen], fullscreen, &rect);
+
+ /* Hack to fix origin on Mac OS X 10.4 */
+ NSRect screenRect = [[nswindow screen] frame];
+ if (screenRect.size.height >= 1.0f) {
+ rect.origin.y += (screenRect.size.height - rect.size.height);
+ }
+
+ [nswindow setStyleMask:NSWindowStyleMaskBorderless];
+ } else {
+ rect.origin.x = window->windowed.x;
+ rect.origin.y = window->windowed.y;
+ rect.size.width = window->windowed.w;
+ rect.size.height = window->windowed.h;
+ ConvertNSRect([nswindow screen], fullscreen, &rect);
+
+ [nswindow setStyleMask:GetWindowStyle(window)];
+
+ /* Hack to restore window decorations on Mac OS X 10.10 */
+ NSRect frameRect = [nswindow frame];
+ [nswindow setFrame:NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width + 1, frameRect.size.height) display:NO];
+ [nswindow setFrame:frameRect display:NO];
+ }
+
+ /* The view responder chain gets messed with during setStyleMask */
+ if ([[nswindow contentView] nextResponder] != data->listener) {
+ [[nswindow contentView] setNextResponder:data->listener];
+ }
+
+ s_moveHack = 0;
+ [nswindow setContentSize:rect.size];
+ [nswindow setFrameOrigin:rect.origin];
+ s_moveHack = SDL_GetTicks();
+
+ /* When the window style changes the title is cleared */
+ if (!fullscreen) {
+ Cocoa_SetWindowTitle(_this, window);
+ }
+
+ if (SDL_ShouldAllowTopmost() && fullscreen) {
+ /* OpenGL is rendering to the window, so make it visible! */
+ [nswindow setLevel:CGShieldingWindowLevel()];
+ } else {
+ [nswindow setLevel:kCGNormalWindowLevel];
+ }
+
+ if ([nswindow isVisible] || fullscreen) {
+ [data->listener pauseVisibleObservation];
+ [nswindow makeKeyAndOrderFront:nil];
+ [data->listener resumeVisibleObservation];
+ }
+
+ ScheduleContextUpdates(data);
+}}
+
+int
+Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
+{
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ CGDirectDisplayID display_id = ((SDL_DisplayData *)display->driverdata)->display;
+ const uint32_t tableSize = 256;
+ CGGammaValue redTable[tableSize];
+ CGGammaValue greenTable[tableSize];
+ CGGammaValue blueTable[tableSize];
+ uint32_t i;
+ float inv65535 = 1.0f / 65535.0f;
+
+ /* Extract gamma values into separate tables, convert to floats between 0.0 and 1.0 */
+ for (i = 0; i < 256; i++) {
+ redTable[i] = ramp[0*256+i] * inv65535;
+ greenTable[i] = ramp[1*256+i] * inv65535;
+ blueTable[i] = ramp[2*256+i] * inv65535;
+ }
+
+ if (CGSetDisplayTransferByTable(display_id, tableSize,
+ redTable, greenTable, blueTable) != CGDisplayNoErr) {
+ return SDL_SetError("CGSetDisplayTransferByTable()");
+ }
+ return 0;
+}
+
+int
+Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
+{
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ CGDirectDisplayID display_id = ((SDL_DisplayData *)display->driverdata)->display;
+ const uint32_t tableSize = 256;
+ CGGammaValue redTable[tableSize];
+ CGGammaValue greenTable[tableSize];
+ CGGammaValue blueTable[tableSize];
+ uint32_t i, tableCopied;
+
+ if (CGGetDisplayTransferByTable(display_id, tableSize,
+ redTable, greenTable, blueTable, &tableCopied) != CGDisplayNoErr) {
+ return SDL_SetError("CGGetDisplayTransferByTable()");
+ }
+
+ for (i = 0; i < tableCopied; i++) {
+ ramp[0*256+i] = (Uint16)(redTable[i] * 65535.0f);
+ ramp[1*256+i] = (Uint16)(greenTable[i] * 65535.0f);
+ ramp[2*256+i] = (Uint16)(blueTable[i] * 65535.0f);
+ }
+ return 0;
+}
+
+void
+Cocoa_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+
+ /* Enable or disable the event tap as necessary */
+ Cocoa_EnableMouseEventTap(mouse->driverdata, grabbed);
+
+ /* Move the cursor to the nearest point in the window */
+ if (grabbed && data && ![data->listener isMoving]) {
+ int x, y;
+ CGPoint cgpoint;
+
+ SDL_GetMouseState(&x, &y);
+ cgpoint.x = window->x + x;
+ cgpoint.y = window->y + y;
+
+ Cocoa_HandleMouseWarp(cgpoint.x, cgpoint.y);
+
+ DLog("Returning cursor to (%g, %g)", cgpoint.x, cgpoint.y);
+ CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
+ }
+
+ if ( data && (window->flags & SDL_WINDOW_FULLSCREEN) ) {
+ if (SDL_ShouldAllowTopmost() && (window->flags & SDL_WINDOW_INPUT_FOCUS)
+ && ![data->listener isInFullscreenSpace]) {
+ /* OpenGL is rendering to the window, so make it visible! */
+ /* Doing this in 10.11 while in a Space breaks things (bug #3152) */
+ [data->nswindow setLevel:CGShieldingWindowLevel()];
+ } else {
+ [data->nswindow setLevel:kCGNormalWindowLevel];
+ }
+ }
+}
+
+void
+Cocoa_DestroyWindow(_THIS, SDL_Window * window)
+{ @autoreleasepool
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+
+ if (data) {
+ if ([data->listener isInFullscreenSpace]) {
+ [NSMenu setMenuBarVisible:YES];
+ }
+ [data->listener close];
+ [data->listener release];
+ if (data->created) {
+ [data->nswindow close];
+ }
+
+ NSArray *contexts = [[data->nscontexts copy] autorelease];
+ for (SDLOpenGLContext *context in contexts) {
+ /* Calling setWindow:NULL causes the context to remove itself from the context list. */
+ [context setWindow:NULL];
+ }
+ [data->nscontexts release];
+
+ SDL_free(data);
+ }
+ window->driverdata = NULL;
+}}
+
+SDL_bool
+Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
+{
+ NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
+
+ if (info->version.major <= SDL_MAJOR_VERSION) {
+ info->subsystem = SDL_SYSWM_COCOA;
+ info->info.cocoa.window = nswindow;
+ return SDL_TRUE;
+ } else {
+ SDL_SetError("Application not compiled with SDL %d.%d",
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+ return SDL_FALSE;
+ }
+}
+
+SDL_bool
+Cocoa_IsWindowInFullscreenSpace(SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+
+ if ([data->listener isInFullscreenSpace]) {
+ return SDL_TRUE;
+ } else {
+ return SDL_FALSE;
+ }
+}
+
+SDL_bool
+Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
+{ @autoreleasepool
+{
+ SDL_bool succeeded = SDL_FALSE;
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+
+ if ([data->listener setFullscreenSpace:(state ? YES : NO)]) {
+ const int maxattempts = 3;
+ int attempt = 0;
+ while (++attempt <= maxattempts) {
+ /* Wait for the transition to complete, so application changes
+ take effect properly (e.g. setting the window size, etc.)
+ */
+ const int limit = 10000;
+ int count = 0;
+ while ([data->listener isInFullscreenSpaceTransition]) {
+ if ( ++count == limit ) {
+ /* Uh oh, transition isn't completing. Should we assert? */
+ break;
+ }
+ SDL_Delay(1);
+ SDL_PumpEvents();
+ }
+ if ([data->listener isInFullscreenSpace] == (state ? YES : NO))
+ break;
+ /* Try again, the last attempt was interrupted by user gestures */
+ if (![data->listener setFullscreenSpace:(state ? YES : NO)])
+ break; /* ??? */
+ }
+ /* Return TRUE to prevent non-space fullscreen logic from running */
+ succeeded = SDL_TRUE;
+ }
+
+ return succeeded;
+}}
+
+int
+Cocoa_SetWindowHitTest(SDL_Window * window, SDL_bool enabled)
+{
+ return 0; /* just succeed, the real work is done elsewhere. */
+}
+
+int
+Cocoa_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ [data->nswindow setAlphaValue:opacity];
+ return 0;
+}
+
+#endif /* SDL_VIDEO_DRIVER_COCOA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_WM.c b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_WM.c
new file mode 100644
index 0000000..d9d0c3a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_WM.c
@@ -0,0 +1,413 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_DIRECTFB
+
+#include "SDL_DirectFB_video.h"
+#include "SDL_DirectFB_window.h"
+
+#include "../../events/SDL_windowevents_c.h"
+
+#define COLOR_EXPAND(col) col.r, col.g, col.b, col.a
+
+static DFB_Theme theme_std = {
+ 4, 4, 8, 8,
+ {255, 200, 200, 200},
+ 24,
+ {255, 0, 0, 255},
+ 16,
+ {255, 255, 255, 255},
+ "/usr/share/fonts/truetype/freefont/FreeSans.ttf",
+ {255, 255, 0, 0},
+ {255, 255, 255, 0},
+};
+
+static DFB_Theme theme_none = {
+ 0, 0, 0, 0,
+ {0, 0, 0, 0},
+ 0,
+ {0, 0, 0, 0},
+ 0,
+ {0, 0, 0, 0},
+ NULL
+};
+
+static void
+DrawTriangle(IDirectFBSurface * s, int down, int x, int y, int w)
+{
+ int x1, x2, x3;
+ int y1, y2, y3;
+
+ if (down) {
+ x1 = x + w / 2;
+ x2 = x;
+ x3 = x + w;
+ y1 = y + w;
+ y2 = y;
+ y3 = y;
+ } else {
+ x1 = x + w / 2;
+ x2 = x;
+ x3 = x + w;
+ y1 = y;
+ y2 = y + w;
+ y3 = y + w;
+ }
+ s->FillTriangle(s, x1, y1, x2, y2, x3, y3);
+}
+
+static void
+LoadFont(_THIS, SDL_Window * window)
+{
+ SDL_DFB_DEVICEDATA(_this);
+ SDL_DFB_WINDOWDATA(window);
+
+ if (windata->font != NULL) {
+ SDL_DFB_RELEASE(windata->font);
+ windata->font = NULL;
+ SDL_DFB_CHECK(windata->window_surface->SetFont(windata->window_surface, windata->font));
+ }
+
+ if (windata->theme.font != NULL)
+ {
+ DFBFontDescription fdesc;
+
+ SDL_zero(fdesc);
+ fdesc.flags = DFDESC_HEIGHT;
+ fdesc.height = windata->theme.font_size;
+ SDL_DFB_CHECK(devdata->
+ dfb->CreateFont(devdata->dfb, windata->theme.font,
+ &fdesc, &windata->font));
+ SDL_DFB_CHECK(windata->window_surface->SetFont(windata->window_surface, windata->font));
+ }
+}
+
+static void
+DrawCraption(_THIS, IDirectFBSurface * s, int x, int y, char *text)
+{
+ DFBSurfaceTextFlags flags;
+
+ flags = DSTF_CENTER | DSTF_TOP;
+
+ s->DrawString(s, text, -1, x, y, flags);
+}
+
+void
+DirectFB_WM_RedrawLayout(_THIS, SDL_Window * window)
+{
+ SDL_DFB_WINDOWDATA(window);
+ IDirectFBSurface *s = windata->window_surface;
+ DFB_Theme *t = &windata->theme;
+ int i;
+ int d = (t->caption_size - t->font_size) / 2;
+ int x, y, w;
+
+
+ if (!windata->is_managed || (window->flags & SDL_WINDOW_FULLSCREEN))
+ return;
+
+ SDL_DFB_CHECK(s->SetSrcBlendFunction(s, DSBF_ONE));
+ SDL_DFB_CHECK(s->SetDstBlendFunction(s, DSBF_ZERO));
+ SDL_DFB_CHECK(s->SetDrawingFlags(s, DSDRAW_NOFX));
+ SDL_DFB_CHECK(s->SetBlittingFlags(s, DSBLIT_NOFX));
+
+ LoadFont(_this, window);
+ /* s->SetDrawingFlags(s, DSDRAW_BLEND); */
+ s->SetColor(s, COLOR_EXPAND(t->frame_color));
+ /* top */
+ for (i = 0; i < t->top_size; i++)
+ s->DrawLine(s, 0, i, windata->size.w, i);
+ /* bottom */
+ for (i = windata->size.h - t->bottom_size; i < windata->size.h; i++)
+ s->DrawLine(s, 0, i, windata->size.w, i);
+ /* left */
+ for (i = 0; i < t->left_size; i++)
+ s->DrawLine(s, i, 0, i, windata->size.h);
+ /* right */
+ for (i = windata->size.w - t->right_size; i < windata->size.w; i++)
+ s->DrawLine(s, i, 0, i, windata->size.h);
+ /* Caption */
+ s->SetColor(s, COLOR_EXPAND(t->caption_color));
+ s->FillRectangle(s, t->left_size, t->top_size, windata->client.w,
+ t->caption_size);
+ /* Close Button */
+ w = t->caption_size;
+ x = windata->size.w - t->right_size - w + d;
+ y = t->top_size + d;
+ s->SetColor(s, COLOR_EXPAND(t->close_color));
+ DrawTriangle(s, 1, x, y, w - 2 * d);
+ /* Max Button */
+ s->SetColor(s, COLOR_EXPAND(t->max_color));
+ DrawTriangle(s, window->flags & SDL_WINDOW_MAXIMIZED ? 1 : 0, x - w,
+ y, w - 2 * d);
+
+ /* Caption */
+ if (*window->title) {
+ s->SetColor(s, COLOR_EXPAND(t->font_color));
+ DrawCraption(_this, s, (x - w) / 2, t->top_size + d, window->title);
+ }
+ /* Icon */
+ if (windata->icon) {
+ DFBRectangle dr;
+
+ dr.x = t->left_size + d;
+ dr.y = t->top_size + d;
+ dr.w = w - 2 * d;
+ dr.h = w - 2 * d;
+ s->SetBlittingFlags(s, DSBLIT_BLEND_ALPHACHANNEL);
+
+ s->StretchBlit(s, windata->icon, NULL, &dr);
+ }
+ windata->wm_needs_redraw = 0;
+}
+
+DFBResult
+DirectFB_WM_GetClientSize(_THIS, SDL_Window * window, int *cw, int *ch)
+{
+ SDL_DFB_WINDOWDATA(window);
+ IDirectFBWindow *dfbwin = windata->dfbwin;
+
+ SDL_DFB_CHECK(dfbwin->GetSize(dfbwin, cw, ch));
+ dfbwin->GetSize(dfbwin, cw, ch);
+ *cw -= windata->theme.left_size + windata->theme.right_size;
+ *ch -=
+ windata->theme.top_size + windata->theme.caption_size +
+ windata->theme.bottom_size;
+ return DFB_OK;
+}
+
+void
+DirectFB_WM_AdjustWindowLayout(SDL_Window * window, int flags, int w, int h)
+{
+ SDL_DFB_WINDOWDATA(window);
+
+ if (!windata->is_managed)
+ windata->theme = theme_none;
+ else if (flags & SDL_WINDOW_BORDERLESS)
+ /* desc.caps |= DWCAPS_NODECORATION;) */
+ windata->theme = theme_none;
+ else if (flags & SDL_WINDOW_FULLSCREEN) {
+ windata->theme = theme_none;
+ } else if (flags & SDL_WINDOW_MAXIMIZED) {
+ windata->theme = theme_std;
+ windata->theme.left_size = 0;
+ windata->theme.right_size = 0;
+ windata->theme.top_size = 0;
+ windata->theme.bottom_size = 0;
+ } else {
+ windata->theme = theme_std;
+ }
+
+ windata->client.x = windata->theme.left_size;
+ windata->client.y = windata->theme.top_size + windata->theme.caption_size;
+ windata->client.w = w;
+ windata->client.h = h;
+ windata->size.w =
+ w + windata->theme.left_size + windata->theme.right_size;
+ windata->size.h =
+ h + windata->theme.top_size +
+ windata->theme.caption_size + windata->theme.bottom_size;
+}
+
+
+enum
+{
+ WM_POS_NONE = 0x00,
+ WM_POS_CAPTION = 0x01,
+ WM_POS_CLOSE = 0x02,
+ WM_POS_MAX = 0x04,
+ WM_POS_LEFT = 0x08,
+ WM_POS_RIGHT = 0x10,
+ WM_POS_TOP = 0x20,
+ WM_POS_BOTTOM = 0x40,
+};
+
+static int
+WMIsClient(DFB_WindowData * p, int x, int y)
+{
+ x -= p->client.x;
+ y -= p->client.y;
+ if (x < 0 || y < 0)
+ return 0;
+ if (x >= p->client.w || y >= p->client.h)
+ return 0;
+ return 1;
+}
+
+static int
+WMPos(DFB_WindowData * p, int x, int y)
+{
+ int pos = WM_POS_NONE;
+
+ if (!WMIsClient(p, x, y)) {
+ if (y < p->theme.top_size) {
+ pos |= WM_POS_TOP;
+ } else if (y < p->client.y) {
+ if (x <
+ p->size.w - p->theme.right_size - 2 * p->theme.caption_size) {
+ pos |= WM_POS_CAPTION;
+ } else if (x <
+ p->size.w - p->theme.right_size -
+ p->theme.caption_size) {
+ pos |= WM_POS_MAX;
+ } else {
+ pos |= WM_POS_CLOSE;
+ }
+ } else if (y >= p->size.h - p->theme.bottom_size) {
+ pos |= WM_POS_BOTTOM;
+ }
+ if (x < p->theme.left_size) {
+ pos |= WM_POS_LEFT;
+ } else if (x >= p->size.w - p->theme.right_size) {
+ pos |= WM_POS_RIGHT;
+ }
+ }
+ return pos;
+}
+
+int
+DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window, DFBWindowEvent * evt)
+{
+ SDL_DFB_DEVICEDATA(_this);
+ SDL_DFB_WINDOWDATA(window);
+ DFB_WindowData *gwindata = ((devdata->grabbed_window) ? (DFB_WindowData *) ((devdata->grabbed_window)->driverdata) : NULL);
+ IDirectFBWindow *dfbwin = windata->dfbwin;
+ DFBWindowOptions wopts;
+
+ if (!windata->is_managed)
+ return 0;
+
+ SDL_DFB_CHECK(dfbwin->GetOptions(dfbwin, &wopts));
+
+ switch (evt->type) {
+ case DWET_BUTTONDOWN:
+ if (evt->buttons & DIBM_LEFT) {
+ int pos = WMPos(windata, evt->x, evt->y);
+ switch (pos) {
+ case WM_POS_NONE:
+ return 0;
+ case WM_POS_CLOSE:
+ windata->wm_grab = WM_POS_NONE;
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_CLOSE, 0,
+ 0);
+ return 1;
+ case WM_POS_MAX:
+ windata->wm_grab = WM_POS_NONE;
+ if (window->flags & SDL_WINDOW_MAXIMIZED) {
+ SDL_RestoreWindow(window);
+ } else {
+ SDL_MaximizeWindow(window);
+ }
+ return 1;
+ case WM_POS_CAPTION:
+ if (!(wopts & DWOP_KEEP_STACKING)) {
+ DirectFB_RaiseWindow(_this, window);
+ }
+ if (window->flags & SDL_WINDOW_MAXIMIZED)
+ return 1;
+ /* fall through */
+ default:
+ windata->wm_grab = pos;
+ if (gwindata != NULL)
+ SDL_DFB_CHECK(gwindata->dfbwin->UngrabPointer(gwindata->dfbwin));
+ SDL_DFB_CHECK(dfbwin->GrabPointer(dfbwin));
+ windata->wm_lastx = evt->cx;
+ windata->wm_lasty = evt->cy;
+ }
+ }
+ return 1;
+ case DWET_BUTTONUP:
+ if (!windata->wm_grab)
+ return 0;
+ if (!(evt->buttons & DIBM_LEFT)) {
+ if (windata->wm_grab & (WM_POS_RIGHT | WM_POS_BOTTOM)) {
+ int dx = evt->cx - windata->wm_lastx;
+ int dy = evt->cy - windata->wm_lasty;
+
+ if (!(wopts & DWOP_KEEP_SIZE)) {
+ int cw, ch;
+ if ((windata->wm_grab & (WM_POS_BOTTOM | WM_POS_RIGHT)) == WM_POS_BOTTOM)
+ dx = 0;
+ else if ((windata->wm_grab & (WM_POS_BOTTOM | WM_POS_RIGHT)) == WM_POS_RIGHT)
+ dy = 0;
+ SDL_DFB_CHECK(dfbwin->GetSize(dfbwin, &cw, &ch));
+
+ /* necessary to trigger an event - ugly */
+ SDL_DFB_CHECK(dfbwin->DisableEvents(dfbwin, DWET_ALL));
+ SDL_DFB_CHECK(dfbwin->Resize(dfbwin, cw + dx + 1, ch + dy));
+ SDL_DFB_CHECK(dfbwin->EnableEvents(dfbwin, DWET_ALL));
+
+ SDL_DFB_CHECK(dfbwin->Resize(dfbwin, cw + dx, ch + dy));
+ }
+ }
+ SDL_DFB_CHECK(dfbwin->UngrabPointer(dfbwin));
+ if (gwindata != NULL)
+ SDL_DFB_CHECK(gwindata->dfbwin->GrabPointer(gwindata->dfbwin));
+ windata->wm_grab = WM_POS_NONE;
+ return 1;
+ }
+ break;
+ case DWET_MOTION:
+ if (!windata->wm_grab)
+ return 0;
+ if (evt->buttons & DIBM_LEFT) {
+ int dx = evt->cx - windata->wm_lastx;
+ int dy = evt->cy - windata->wm_lasty;
+
+ if (windata->wm_grab & WM_POS_CAPTION) {
+ if (!(wopts & DWOP_KEEP_POSITION))
+ SDL_DFB_CHECK(dfbwin->Move(dfbwin, dx, dy));
+ }
+ if (windata->wm_grab & (WM_POS_RIGHT | WM_POS_BOTTOM)) {
+ if (!(wopts & DWOP_KEEP_SIZE)) {
+ int cw, ch;
+
+ /* Make sure all events are disabled for this operation ! */
+ SDL_DFB_CHECK(dfbwin->DisableEvents(dfbwin, DWET_ALL));
+
+ if ((windata->wm_grab & (WM_POS_BOTTOM | WM_POS_RIGHT)) == WM_POS_BOTTOM)
+ dx = 0;
+ else if ((windata->wm_grab & (WM_POS_BOTTOM | WM_POS_RIGHT)) == WM_POS_RIGHT)
+ dy = 0;
+
+ SDL_DFB_CHECK(dfbwin->GetSize(dfbwin, &cw, &ch));
+ SDL_DFB_CHECK(dfbwin->Resize(dfbwin, cw + dx, ch + dy));
+
+ SDL_DFB_CHECK(dfbwin->EnableEvents(dfbwin, DWET_ALL));
+ }
+ }
+ windata->wm_lastx = evt->cx;
+ windata->wm_lasty = evt->cy;
+ return 1;
+ }
+ break;
+ case DWET_KEYDOWN:
+ break;
+ case DWET_KEYUP:
+ break;
+ default:
+ ;
+ }
+ return 0;
+}
+
+#endif /* SDL_VIDEO_DRIVER_DIRECTFB */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_WM.h b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_WM.h
new file mode 100644
index 0000000..98d943f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_WM.h
@@ -0,0 +1,56 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_directfb_wm_h_
+#define SDL_directfb_wm_h_
+
+#include "SDL_DirectFB_video.h"
+
+typedef struct _DFB_Theme DFB_Theme;
+struct _DFB_Theme
+{
+ int left_size;
+ int right_size;
+ int top_size;
+ int bottom_size;
+ DFBColor frame_color;
+ int caption_size;
+ DFBColor caption_color;
+ int font_size;
+ DFBColor font_color;
+ char *font;
+ DFBColor close_color;
+ DFBColor max_color;
+};
+
+extern void DirectFB_WM_AdjustWindowLayout(SDL_Window * window, int flags, int w, int h);
+extern void DirectFB_WM_RedrawLayout(_THIS, SDL_Window * window);
+
+extern int DirectFB_WM_ProcessEvent(_THIS, SDL_Window * window,
+ DFBWindowEvent * evt);
+
+extern DFBResult DirectFB_WM_GetClientSize(_THIS, SDL_Window * window,
+ int *cw, int *ch);
+
+
+#endif /* SDL_directfb_wm_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_dyn.c b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_dyn.c
new file mode 100644
index 0000000..12cf21a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_dyn.c
@@ -0,0 +1,117 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_DIRECTFB
+
+#include "SDL_DirectFB_video.h"
+#include "SDL_DirectFB_dyn.h"
+
+#ifdef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC
+#include "SDL_name.h"
+#include "SDL_loadso.h"
+
+#define DFB_SYM(ret, name, args, al, func) ret (*name) args;
+static struct _SDL_DirectFB_Symbols
+{
+ DFB_SYMS
+ const unsigned int *directfb_major_version;
+ const unsigned int *directfb_minor_version;
+ const unsigned int *directfb_micro_version;
+} SDL_DirectFB_Symbols;
+#undef DFB_SYM
+
+#define DFB_SYM(ret, name, args, al, func) ret name args { func SDL_DirectFB_Symbols.name al ; }
+DFB_SYMS
+#undef DFB_SYM
+
+static void *handle = NULL;
+
+int
+SDL_DirectFB_LoadLibrary(void)
+{
+ int retval = 0;
+
+ if (handle == NULL) {
+ handle = SDL_LoadObject(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC);
+ if (handle != NULL) {
+ retval = 1;
+#define DFB_SYM(ret, name, args, al, func) if (!(SDL_DirectFB_Symbols.name = SDL_LoadFunction(handle, # name))) retval = 0;
+ DFB_SYMS
+#undef DFB_SYM
+ if (!
+ (SDL_DirectFB_Symbols.directfb_major_version =
+ SDL_LoadFunction(handle, "directfb_major_version")))
+ retval = 0;
+ if (!
+ (SDL_DirectFB_Symbols.directfb_minor_version =
+ SDL_LoadFunction(handle, "directfb_minor_version")))
+ retval = 0;
+ if (!
+ (SDL_DirectFB_Symbols.directfb_micro_version =
+ SDL_LoadFunction(handle, "directfb_micro_version")))
+ retval = 0;
+ }
+ }
+ if (retval) {
+ const char *stemp = DirectFBCheckVersion(DIRECTFB_MAJOR_VERSION,
+ DIRECTFB_MINOR_VERSION,
+ DIRECTFB_MICRO_VERSION);
+ /* Version Check */
+ if (stemp != NULL) {
+ fprintf(stderr,
+ "DirectFB Lib: Version mismatch. Compiled: %d.%d.%d Library %d.%d.%d\n",
+ DIRECTFB_MAJOR_VERSION, DIRECTFB_MINOR_VERSION,
+ DIRECTFB_MICRO_VERSION,
+ *SDL_DirectFB_Symbols.directfb_major_version,
+ *SDL_DirectFB_Symbols.directfb_minor_version,
+ *SDL_DirectFB_Symbols.directfb_micro_version);
+ retval = 0;
+ }
+ }
+ if (!retval)
+ SDL_DirectFB_UnLoadLibrary();
+ return retval;
+}
+
+void
+SDL_DirectFB_UnLoadLibrary(void)
+{
+ if (handle != NULL) {
+ SDL_UnloadObject(handle);
+ handle = NULL;
+ }
+}
+
+#else
+int
+SDL_DirectFB_LoadLibrary(void)
+{
+ return 1;
+}
+
+void
+SDL_DirectFB_UnLoadLibrary(void)
+{
+}
+#endif
+
+#endif /* SDL_VIDEO_DRIVER_DIRECTFB */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_dyn.h b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_dyn.h
new file mode 100644
index 0000000..1a370c6
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_dyn.h
@@ -0,0 +1,41 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_DirectFB_dyn_h_
+#define SDL_DirectFB_dyn_h_
+
+#define DFB_SYMS \
+ DFB_SYM(DFBResult, DirectFBError, (const char *msg, DFBResult result), (msg, result), return) \
+ DFB_SYM(DFBResult, DirectFBErrorFatal, (const char *msg, DFBResult result), (msg, result), return) \
+ DFB_SYM(const char *, DirectFBErrorString, (DFBResult result), (result), return) \
+ DFB_SYM(const char *, DirectFBUsageString, ( void ), (), return) \
+ DFB_SYM(DFBResult, DirectFBInit, (int *argc, char *(*argv[]) ), (argc, argv), return) \
+ DFB_SYM(DFBResult, DirectFBSetOption, (const char *name, const char *value), (name, value), return) \
+ DFB_SYM(DFBResult, DirectFBCreate, (IDirectFB **interface), (interface), return) \
+ DFB_SYM(const char *, DirectFBCheckVersion, (unsigned int required_major, unsigned int required_minor, unsigned int required_micro), \
+ (required_major, required_minor, required_micro), return)
+
+int SDL_DirectFB_LoadLibrary(void);
+void SDL_DirectFB_UnLoadLibrary(void);
+
+#endif /* SDL_DirectFB_dyn_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_events.c b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_events.c
new file mode 100644
index 0000000..27cf19f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_events.c
@@ -0,0 +1,748 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_DIRECTFB
+
+/* Handle the event stream, converting DirectFB input events into SDL events */
+
+#include "SDL_DirectFB_video.h"
+#include "SDL_DirectFB_window.h"
+#include "SDL_DirectFB_modes.h"
+
+#include "SDL_syswm.h"
+
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_keyboard_c.h"
+#include "../../events/SDL_windowevents_c.h"
+#include "../../events/SDL_events_c.h"
+#include "../../events/scancodes_linux.h"
+#include "../../events/scancodes_xfree86.h"
+
+#include "SDL_DirectFB_events.h"
+
+#if USE_MULTI_API
+#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, id, relative, x, y, p)
+#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, id, state, button)
+#define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(id, state, scancode)
+#define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(id, text)
+#else
+#define SDL_SendMouseMotion_ex(w, id, relative, x, y, p) SDL_SendMouseMotion(w, id, relative, x, y)
+#define SDL_SendMouseButton_ex(w, id, state, button) SDL_SendMouseButton(w, id, state, button)
+#define SDL_SendKeyboardKey_ex(id, state, scancode) SDL_SendKeyboardKey(state, scancode)
+#define SDL_SendKeyboardText_ex(id, text) SDL_SendKeyboardText(text)
+#endif
+
+typedef struct _cb_data cb_data;
+struct _cb_data
+{
+ DFB_DeviceData *devdata;
+ int sys_ids;
+ int sys_kbd;
+};
+
+/* The translation tables from a DirectFB keycode to a SDL keysym */
+static SDL_Scancode oskeymap[256];
+
+
+static SDL_Keysym *DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt,
+ SDL_Keysym * keysym, Uint32 *unicode);
+static SDL_Keysym *DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
+ SDL_Keysym * keysym, Uint32 *unicode);
+
+static void DirectFB_InitOSKeymap(_THIS, SDL_Scancode * keypmap, int numkeys);
+static int DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button);
+
+static void UnicodeToUtf8( Uint16 w , char *utf8buf)
+{
+ unsigned char *utf8s = (unsigned char *) utf8buf;
+
+ if ( w < 0x0080 ) {
+ utf8s[0] = ( unsigned char ) w;
+ utf8s[1] = 0;
+ }
+ else if ( w < 0x0800 ) {
+ utf8s[0] = 0xc0 | (( w ) >> 6 );
+ utf8s[1] = 0x80 | (( w ) & 0x3f );
+ utf8s[2] = 0;
+ }
+ else {
+ utf8s[0] = 0xe0 | (( w ) >> 12 );
+ utf8s[1] = 0x80 | (( ( w ) >> 6 ) & 0x3f );
+ utf8s[2] = 0x80 | (( w ) & 0x3f );
+ utf8s[3] = 0;
+ }
+}
+
+static void
+FocusAllMice(_THIS, SDL_Window *window)
+{
+#if USE_MULTI_API
+ SDL_DFB_DEVICEDATA(_this);
+ int index;
+
+ for (index = 0; index < devdata->num_mice; index++)
+ SDL_SetMouseFocus(devdata->mouse_id[index], id);
+#else
+ SDL_SetMouseFocus(window);
+#endif
+}
+
+
+static void
+FocusAllKeyboards(_THIS, SDL_Window *window)
+{
+#if USE_MULTI_API
+ SDL_DFB_DEVICEDATA(_this);
+ int index;
+
+ for (index = 0; index < devdata->num_keyboard; index++)
+ SDL_SetKeyboardFocus(index, id);
+#else
+ SDL_SetKeyboardFocus(window);
+#endif
+}
+
+static void
+MotionAllMice(_THIS, int x, int y)
+{
+#if USE_MULTI_API
+ SDL_DFB_DEVICEDATA(_this);
+ int index;
+
+ for (index = 0; index < devdata->num_mice; index++) {
+ SDL_Mouse *mouse = SDL_GetMouse(index);
+ mouse->x = mouse->last_x = x;
+ mouse->y = mouse->last_y = y;
+ /* SDL_SendMouseMotion(devdata->mouse_id[index], 0, x, y, 0); */
+ }
+#endif
+}
+
+static int
+KbdIndex(_THIS, int id)
+{
+ SDL_DFB_DEVICEDATA(_this);
+ int index;
+
+ for (index = 0; index < devdata->num_keyboard; index++) {
+ if (devdata->keyboard[index].id == id)
+ return index;
+ }
+ return -1;
+}
+
+static int
+ClientXY(DFB_WindowData * p, int *x, int *y)
+{
+ int cx, cy;
+
+ cx = *x;
+ cy = *y;
+
+ cx -= p->client.x;
+ cy -= p->client.y;
+
+ if (cx < 0 || cy < 0)
+ return 0;
+ if (cx >= p->client.w || cy >= p->client.h)
+ return 0;
+ *x = cx;
+ *y = cy;
+ return 1;
+}
+
+static void
+ProcessWindowEvent(_THIS, SDL_Window *sdlwin, DFBWindowEvent * evt)
+{
+ SDL_DFB_DEVICEDATA(_this);
+ SDL_DFB_WINDOWDATA(sdlwin);
+ SDL_Keysym keysym;
+ Uint32 unicode;
+ char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
+
+ if (evt->clazz == DFEC_WINDOW) {
+ switch (evt->type) {
+ case DWET_BUTTONDOWN:
+ if (ClientXY(windata, &evt->x, &evt->y)) {
+ if (!devdata->use_linux_input) {
+ SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0, evt->x,
+ evt->y, 0);
+ SDL_SendMouseButton_ex(sdlwin, devdata->mouse_id[0],
+ SDL_PRESSED,
+ DirectFB_TranslateButton
+ (evt->button));
+ } else {
+ MotionAllMice(_this, evt->x, evt->y);
+ }
+ }
+ break;
+ case DWET_BUTTONUP:
+ if (ClientXY(windata, &evt->x, &evt->y)) {
+ if (!devdata->use_linux_input) {
+ SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0, evt->x,
+ evt->y, 0);
+ SDL_SendMouseButton_ex(sdlwin, devdata->mouse_id[0],
+ SDL_RELEASED,
+ DirectFB_TranslateButton
+ (evt->button));
+ } else {
+ MotionAllMice(_this, evt->x, evt->y);
+ }
+ }
+ break;
+ case DWET_MOTION:
+ if (ClientXY(windata, &evt->x, &evt->y)) {
+ if (!devdata->use_linux_input) {
+ if (!(sdlwin->flags & SDL_WINDOW_INPUT_GRABBED))
+ SDL_SendMouseMotion_ex(sdlwin, devdata->mouse_id[0], 0,
+ evt->x, evt->y, 0);
+ } else {
+ /* relative movements are not exact!
+ * This code should limit the number of events sent.
+ * However it kills MAME axis recognition ... */
+ static int cnt = 0;
+ if (1 && ++cnt > 20) {
+ MotionAllMice(_this, evt->x, evt->y);
+ cnt = 0;
+ }
+ }
+ if (!(sdlwin->flags & SDL_WINDOW_MOUSE_FOCUS))
+ SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_ENTER, 0,
+ 0);
+ }
+ break;
+ case DWET_KEYDOWN:
+ if (!devdata->use_linux_input) {
+ DirectFB_TranslateKey(_this, evt, &keysym, &unicode);
+ /* printf("Scancode %d %d %d\n", keysym.scancode, evt->key_code, evt->key_id); */
+ SDL_SendKeyboardKey_ex(0, SDL_PRESSED, keysym.scancode);
+ if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
+ SDL_zero(text);
+ UnicodeToUtf8(unicode, text);
+ if (*text) {
+ SDL_SendKeyboardText_ex(0, text);
+ }
+ }
+ }
+ break;
+ case DWET_KEYUP:
+ if (!devdata->use_linux_input) {
+ DirectFB_TranslateKey(_this, evt, &keysym, &unicode);
+ SDL_SendKeyboardKey_ex(0, SDL_RELEASED, keysym.scancode);
+ }
+ break;
+ case DWET_POSITION:
+ if (ClientXY(windata, &evt->x, &evt->y)) {
+ SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_MOVED,
+ evt->x, evt->y);
+ }
+ break;
+ case DWET_POSITION_SIZE:
+ if (ClientXY(windata, &evt->x, &evt->y)) {
+ SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_MOVED,
+ evt->x, evt->y);
+ }
+ /* fall throught */
+ case DWET_SIZE:
+ /* FIXME: what about < 0 */
+ evt->w -= (windata->theme.right_size + windata->theme.left_size);
+ evt->h -=
+ (windata->theme.top_size + windata->theme.bottom_size +
+ windata->theme.caption_size);
+ SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_RESIZED,
+ evt->w, evt->h);
+ break;
+ case DWET_CLOSE:
+ SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_CLOSE, 0, 0);
+ break;
+ case DWET_GOTFOCUS:
+ DirectFB_SetContext(_this, sdlwin);
+ FocusAllKeyboards(_this, sdlwin);
+ SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_FOCUS_GAINED,
+ 0, 0);
+ break;
+ case DWET_LOSTFOCUS:
+ SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
+ FocusAllKeyboards(_this, 0);
+ break;
+ case DWET_ENTER:
+ /* SDL_DirectFB_ReshowCursor(_this, 0); */
+ FocusAllMice(_this, sdlwin);
+ /* FIXME: when do we really enter ? */
+ if (ClientXY(windata, &evt->x, &evt->y))
+ MotionAllMice(_this, evt->x, evt->y);
+ SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_ENTER, 0, 0);
+ break;
+ case DWET_LEAVE:
+ SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_LEAVE, 0, 0);
+ FocusAllMice(_this, 0);
+ /* SDL_DirectFB_ReshowCursor(_this, 1); */
+ break;
+ default:
+ ;
+ }
+ } else
+ printf("Event Clazz %d\n", evt->clazz);
+}
+
+static void
+ProcessInputEvent(_THIS, DFBInputEvent * ievt)
+{
+ SDL_DFB_DEVICEDATA(_this);
+ SDL_Keysym keysym;
+ int kbd_idx;
+ Uint32 unicode;
+ char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
+
+ if (!devdata->use_linux_input) {
+ if (ievt->type == DIET_AXISMOTION) {
+ if ((devdata->grabbed_window != NULL) && (ievt->flags & DIEF_AXISREL)) {
+ if (ievt->axis == DIAI_X)
+ SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1,
+ ievt->axisrel, 0, 0);
+ else if (ievt->axis == DIAI_Y)
+ SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, 0,
+ ievt->axisrel, 0);
+ }
+ }
+ } else {
+ static int last_x, last_y;
+
+ switch (ievt->type) {
+ case DIET_AXISMOTION:
+ if (ievt->flags & DIEF_AXISABS) {
+ if (ievt->axis == DIAI_X)
+ last_x = ievt->axisabs;
+ else if (ievt->axis == DIAI_Y)
+ last_y = ievt->axisabs;
+ if (!(ievt->flags & DIEF_FOLLOW)) {
+#if USE_MULTI_API
+ SDL_Mouse *mouse = SDL_GetMouse(ievt->device_id);
+ SDL_Window *window = SDL_GetWindowFromID(mouse->focus);
+#else
+ SDL_Window *window = devdata->grabbed_window;
+#endif
+ if (window) {
+ DFB_WindowData *windata =
+ (DFB_WindowData *) window->driverdata;
+ int x, y;
+
+ windata->dfbwin->GetPosition(windata->dfbwin, &x, &y);
+ SDL_SendMouseMotion_ex(window, ievt->device_id, 0,
+ last_x - (x +
+ windata->client.x),
+ last_y - (y +
+ windata->client.y), 0);
+ } else {
+ SDL_SendMouseMotion_ex(window, ievt->device_id, 0, last_x,
+ last_y, 0);
+ }
+ }
+ } else if (ievt->flags & DIEF_AXISREL) {
+ if (ievt->axis == DIAI_X)
+ SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1,
+ ievt->axisrel, 0, 0);
+ else if (ievt->axis == DIAI_Y)
+ SDL_SendMouseMotion_ex(devdata->grabbed_window, ievt->device_id, 1, 0,
+ ievt->axisrel, 0);
+ }
+ break;
+ case DIET_KEYPRESS:
+ kbd_idx = KbdIndex(_this, ievt->device_id);
+ DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym, &unicode);
+ /* printf("Scancode %d %d %d\n", keysym.scancode, evt->key_code, evt->key_id); */
+ SDL_SendKeyboardKey_ex(kbd_idx, SDL_PRESSED, keysym.scancode);
+ if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
+ SDL_zero(text);
+ UnicodeToUtf8(unicode, text);
+ if (*text) {
+ SDL_SendKeyboardText_ex(kbd_idx, text);
+ }
+ }
+ break;
+ case DIET_KEYRELEASE:
+ kbd_idx = KbdIndex(_this, ievt->device_id);
+ DirectFB_TranslateKeyInputEvent(_this, ievt, &keysym, &unicode);
+ SDL_SendKeyboardKey_ex(kbd_idx, SDL_RELEASED, keysym.scancode);
+ break;
+ case DIET_BUTTONPRESS:
+ if (ievt->buttons & DIBM_LEFT)
+ SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 1);
+ if (ievt->buttons & DIBM_MIDDLE)
+ SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 2);
+ if (ievt->buttons & DIBM_RIGHT)
+ SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_PRESSED, 3);
+ break;
+ case DIET_BUTTONRELEASE:
+ if (!(ievt->buttons & DIBM_LEFT))
+ SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 1);
+ if (!(ievt->buttons & DIBM_MIDDLE))
+ SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 2);
+ if (!(ievt->buttons & DIBM_RIGHT))
+ SDL_SendMouseButton_ex(devdata->grabbed_window, ievt->device_id, SDL_RELEASED, 3);
+ break;
+ default:
+ break; /* please gcc */
+ }
+ }
+}
+
+void
+DirectFB_PumpEventsWindow(_THIS)
+{
+ SDL_DFB_DEVICEDATA(_this);
+ DFBInputEvent ievt;
+ SDL_Window *w;
+
+ for (w = devdata->firstwin; w != NULL; w = w->next) {
+ SDL_DFB_WINDOWDATA(w);
+ DFBWindowEvent evt;
+
+ while (windata->eventbuffer->GetEvent(windata->eventbuffer,
+ DFB_EVENT(&evt)) == DFB_OK) {
+ if (!DirectFB_WM_ProcessEvent(_this, w, &evt)) {
+ /* Send a SDL_SYSWMEVENT if the application wants them */
+ if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
+ SDL_SysWMmsg wmmsg;
+ SDL_VERSION(&wmmsg.version);
+ wmmsg.subsystem = SDL_SYSWM_DIRECTFB;
+ wmmsg.msg.dfb.event.window = evt;
+ SDL_SendSysWMEvent(&wmmsg);
+ }
+ ProcessWindowEvent(_this, w, &evt);
+ }
+ }
+ }
+
+ /* Now get relative events in case we need them */
+ while (devdata->events->GetEvent(devdata->events,
+ DFB_EVENT(&ievt)) == DFB_OK) {
+
+ if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
+ SDL_SysWMmsg wmmsg;
+ SDL_VERSION(&wmmsg.version);
+ wmmsg.subsystem = SDL_SYSWM_DIRECTFB;
+ wmmsg.msg.dfb.event.input = ievt;
+ SDL_SendSysWMEvent(&wmmsg);
+ }
+ ProcessInputEvent(_this, &ievt);
+ }
+}
+
+void
+DirectFB_InitOSKeymap(_THIS, SDL_Scancode * keymap, int numkeys)
+{
+ int i;
+
+ /* Initialize the DirectFB key translation table */
+ for (i = 0; i < numkeys; ++i)
+ keymap[i] = SDL_SCANCODE_UNKNOWN;
+
+ keymap[DIKI_A - DIKI_UNKNOWN] = SDL_SCANCODE_A;
+ keymap[DIKI_B - DIKI_UNKNOWN] = SDL_SCANCODE_B;
+ keymap[DIKI_C - DIKI_UNKNOWN] = SDL_SCANCODE_C;
+ keymap[DIKI_D - DIKI_UNKNOWN] = SDL_SCANCODE_D;
+ keymap[DIKI_E - DIKI_UNKNOWN] = SDL_SCANCODE_E;
+ keymap[DIKI_F - DIKI_UNKNOWN] = SDL_SCANCODE_F;
+ keymap[DIKI_G - DIKI_UNKNOWN] = SDL_SCANCODE_G;
+ keymap[DIKI_H - DIKI_UNKNOWN] = SDL_SCANCODE_H;
+ keymap[DIKI_I - DIKI_UNKNOWN] = SDL_SCANCODE_I;
+ keymap[DIKI_J - DIKI_UNKNOWN] = SDL_SCANCODE_J;
+ keymap[DIKI_K - DIKI_UNKNOWN] = SDL_SCANCODE_K;
+ keymap[DIKI_L - DIKI_UNKNOWN] = SDL_SCANCODE_L;
+ keymap[DIKI_M - DIKI_UNKNOWN] = SDL_SCANCODE_M;
+ keymap[DIKI_N - DIKI_UNKNOWN] = SDL_SCANCODE_N;
+ keymap[DIKI_O - DIKI_UNKNOWN] = SDL_SCANCODE_O;
+ keymap[DIKI_P - DIKI_UNKNOWN] = SDL_SCANCODE_P;
+ keymap[DIKI_Q - DIKI_UNKNOWN] = SDL_SCANCODE_Q;
+ keymap[DIKI_R - DIKI_UNKNOWN] = SDL_SCANCODE_R;
+ keymap[DIKI_S - DIKI_UNKNOWN] = SDL_SCANCODE_S;
+ keymap[DIKI_T - DIKI_UNKNOWN] = SDL_SCANCODE_T;
+ keymap[DIKI_U - DIKI_UNKNOWN] = SDL_SCANCODE_U;
+ keymap[DIKI_V - DIKI_UNKNOWN] = SDL_SCANCODE_V;
+ keymap[DIKI_W - DIKI_UNKNOWN] = SDL_SCANCODE_W;
+ keymap[DIKI_X - DIKI_UNKNOWN] = SDL_SCANCODE_X;
+ keymap[DIKI_Y - DIKI_UNKNOWN] = SDL_SCANCODE_Y;
+ keymap[DIKI_Z - DIKI_UNKNOWN] = SDL_SCANCODE_Z;
+
+ keymap[DIKI_0 - DIKI_UNKNOWN] = SDL_SCANCODE_0;
+ keymap[DIKI_1 - DIKI_UNKNOWN] = SDL_SCANCODE_1;
+ keymap[DIKI_2 - DIKI_UNKNOWN] = SDL_SCANCODE_2;
+ keymap[DIKI_3 - DIKI_UNKNOWN] = SDL_SCANCODE_3;
+ keymap[DIKI_4 - DIKI_UNKNOWN] = SDL_SCANCODE_4;
+ keymap[DIKI_5 - DIKI_UNKNOWN] = SDL_SCANCODE_5;
+ keymap[DIKI_6 - DIKI_UNKNOWN] = SDL_SCANCODE_6;
+ keymap[DIKI_7 - DIKI_UNKNOWN] = SDL_SCANCODE_7;
+ keymap[DIKI_8 - DIKI_UNKNOWN] = SDL_SCANCODE_8;
+ keymap[DIKI_9 - DIKI_UNKNOWN] = SDL_SCANCODE_9;
+
+ keymap[DIKI_F1 - DIKI_UNKNOWN] = SDL_SCANCODE_F1;
+ keymap[DIKI_F2 - DIKI_UNKNOWN] = SDL_SCANCODE_F2;
+ keymap[DIKI_F3 - DIKI_UNKNOWN] = SDL_SCANCODE_F3;
+ keymap[DIKI_F4 - DIKI_UNKNOWN] = SDL_SCANCODE_F4;
+ keymap[DIKI_F5 - DIKI_UNKNOWN] = SDL_SCANCODE_F5;
+ keymap[DIKI_F6 - DIKI_UNKNOWN] = SDL_SCANCODE_F6;
+ keymap[DIKI_F7 - DIKI_UNKNOWN] = SDL_SCANCODE_F7;
+ keymap[DIKI_F8 - DIKI_UNKNOWN] = SDL_SCANCODE_F8;
+ keymap[DIKI_F9 - DIKI_UNKNOWN] = SDL_SCANCODE_F9;
+ keymap[DIKI_F10 - DIKI_UNKNOWN] = SDL_SCANCODE_F10;
+ keymap[DIKI_F11 - DIKI_UNKNOWN] = SDL_SCANCODE_F11;
+ keymap[DIKI_F12 - DIKI_UNKNOWN] = SDL_SCANCODE_F12;
+
+ keymap[DIKI_ESCAPE - DIKI_UNKNOWN] = SDL_SCANCODE_ESCAPE;
+ keymap[DIKI_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_LEFT;
+ keymap[DIKI_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_RIGHT;
+ keymap[DIKI_UP - DIKI_UNKNOWN] = SDL_SCANCODE_UP;
+ keymap[DIKI_DOWN - DIKI_UNKNOWN] = SDL_SCANCODE_DOWN;
+ keymap[DIKI_CONTROL_L - DIKI_UNKNOWN] = SDL_SCANCODE_LCTRL;
+ keymap[DIKI_CONTROL_R - DIKI_UNKNOWN] = SDL_SCANCODE_RCTRL;
+ keymap[DIKI_SHIFT_L - DIKI_UNKNOWN] = SDL_SCANCODE_LSHIFT;
+ keymap[DIKI_SHIFT_R - DIKI_UNKNOWN] = SDL_SCANCODE_RSHIFT;
+ keymap[DIKI_ALT_L - DIKI_UNKNOWN] = SDL_SCANCODE_LALT;
+ keymap[DIKI_ALT_R - DIKI_UNKNOWN] = SDL_SCANCODE_RALT;
+ keymap[DIKI_META_L - DIKI_UNKNOWN] = SDL_SCANCODE_LGUI;
+ keymap[DIKI_META_R - DIKI_UNKNOWN] = SDL_SCANCODE_RGUI;
+ keymap[DIKI_SUPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
+ keymap[DIKI_SUPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
+ /* FIXME:Do we read hyper keys ?
+ * keymap[DIKI_HYPER_L - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
+ * keymap[DIKI_HYPER_R - DIKI_UNKNOWN] = SDL_SCANCODE_APPLICATION;
+ */
+ keymap[DIKI_TAB - DIKI_UNKNOWN] = SDL_SCANCODE_TAB;
+ keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDL_SCANCODE_RETURN;
+ keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDL_SCANCODE_SPACE;
+ keymap[DIKI_BACKSPACE - DIKI_UNKNOWN] = SDL_SCANCODE_BACKSPACE;
+ keymap[DIKI_INSERT - DIKI_UNKNOWN] = SDL_SCANCODE_INSERT;
+ keymap[DIKI_DELETE - DIKI_UNKNOWN] = SDL_SCANCODE_DELETE;
+ keymap[DIKI_HOME - DIKI_UNKNOWN] = SDL_SCANCODE_HOME;
+ keymap[DIKI_END - DIKI_UNKNOWN] = SDL_SCANCODE_END;
+ keymap[DIKI_PAGE_UP - DIKI_UNKNOWN] = SDL_SCANCODE_PAGEUP;
+ keymap[DIKI_PAGE_DOWN - DIKI_UNKNOWN] = SDL_SCANCODE_PAGEDOWN;
+ keymap[DIKI_CAPS_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_CAPSLOCK;
+ keymap[DIKI_NUM_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_NUMLOCKCLEAR;
+ keymap[DIKI_SCROLL_LOCK - DIKI_UNKNOWN] = SDL_SCANCODE_SCROLLLOCK;
+ keymap[DIKI_PRINT - DIKI_UNKNOWN] = SDL_SCANCODE_PRINTSCREEN;
+ keymap[DIKI_PAUSE - DIKI_UNKNOWN] = SDL_SCANCODE_PAUSE;
+
+ keymap[DIKI_KP_EQUAL - DIKI_UNKNOWN] = SDL_SCANCODE_KP_EQUALS;
+ keymap[DIKI_KP_DECIMAL - DIKI_UNKNOWN] = SDL_SCANCODE_KP_PERIOD;
+ keymap[DIKI_KP_0 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_0;
+ keymap[DIKI_KP_1 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_1;
+ keymap[DIKI_KP_2 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_2;
+ keymap[DIKI_KP_3 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_3;
+ keymap[DIKI_KP_4 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_4;
+ keymap[DIKI_KP_5 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_5;
+ keymap[DIKI_KP_6 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_6;
+ keymap[DIKI_KP_7 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_7;
+ keymap[DIKI_KP_8 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_8;
+ keymap[DIKI_KP_9 - DIKI_UNKNOWN] = SDL_SCANCODE_KP_9;
+ keymap[DIKI_KP_DIV - DIKI_UNKNOWN] = SDL_SCANCODE_KP_DIVIDE;
+ keymap[DIKI_KP_MULT - DIKI_UNKNOWN] = SDL_SCANCODE_KP_MULTIPLY;
+ keymap[DIKI_KP_MINUS - DIKI_UNKNOWN] = SDL_SCANCODE_KP_MINUS;
+ keymap[DIKI_KP_PLUS - DIKI_UNKNOWN] = SDL_SCANCODE_KP_PLUS;
+ keymap[DIKI_KP_ENTER - DIKI_UNKNOWN] = SDL_SCANCODE_KP_ENTER;
+
+ keymap[DIKI_QUOTE_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_GRAVE; /* TLDE */
+ keymap[DIKI_MINUS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_MINUS; /* AE11 */
+ keymap[DIKI_EQUALS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_EQUALS; /* AE12 */
+ keymap[DIKI_BRACKET_LEFT - DIKI_UNKNOWN] = SDL_SCANCODE_RIGHTBRACKET; /* AD11 */
+ keymap[DIKI_BRACKET_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_LEFTBRACKET; /* AD12 */
+ keymap[DIKI_BACKSLASH - DIKI_UNKNOWN] = SDL_SCANCODE_BACKSLASH; /* BKSL */
+ keymap[DIKI_SEMICOLON - DIKI_UNKNOWN] = SDL_SCANCODE_SEMICOLON; /* AC10 */
+ keymap[DIKI_QUOTE_RIGHT - DIKI_UNKNOWN] = SDL_SCANCODE_APOSTROPHE; /* AC11 */
+ keymap[DIKI_COMMA - DIKI_UNKNOWN] = SDL_SCANCODE_COMMA; /* AB08 */
+ keymap[DIKI_PERIOD - DIKI_UNKNOWN] = SDL_SCANCODE_PERIOD; /* AB09 */
+ keymap[DIKI_SLASH - DIKI_UNKNOWN] = SDL_SCANCODE_SLASH; /* AB10 */
+ keymap[DIKI_LESS_SIGN - DIKI_UNKNOWN] = SDL_SCANCODE_NONUSBACKSLASH; /* 103rd */
+
+}
+
+static SDL_Keysym *
+DirectFB_TranslateKey(_THIS, DFBWindowEvent * evt, SDL_Keysym * keysym, Uint32 *unicode)
+{
+ SDL_DFB_DEVICEDATA(_this);
+ int kbd_idx = 0; /* Window events lag the device source KbdIndex(_this, evt->device_id); */
+ DFB_KeyboardData *kbd = &devdata->keyboard[kbd_idx];
+
+ keysym->scancode = SDL_SCANCODE_UNKNOWN;
+
+ if (kbd->map && evt->key_code >= kbd->map_adjust &&
+ evt->key_code < kbd->map_size + kbd->map_adjust)
+ keysym->scancode = kbd->map[evt->key_code - kbd->map_adjust];
+
+ if (keysym->scancode == SDL_SCANCODE_UNKNOWN ||
+ devdata->keyboard[kbd_idx].is_generic) {
+ if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap))
+ keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
+ else
+ keysym->scancode = SDL_SCANCODE_UNKNOWN;
+ }
+
+ *unicode =
+ (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
+ if (*unicode == 0 &&
+ (evt->key_symbol > 0 && evt->key_symbol < 255))
+ *unicode = evt->key_symbol;
+
+ return keysym;
+}
+
+static SDL_Keysym *
+DirectFB_TranslateKeyInputEvent(_THIS, DFBInputEvent * evt,
+ SDL_Keysym * keysym, Uint32 *unicode)
+{
+ SDL_DFB_DEVICEDATA(_this);
+ int kbd_idx = KbdIndex(_this, evt->device_id);
+ DFB_KeyboardData *kbd = &devdata->keyboard[kbd_idx];
+
+ keysym->scancode = SDL_SCANCODE_UNKNOWN;
+
+ if (kbd->map && evt->key_code >= kbd->map_adjust &&
+ evt->key_code < kbd->map_size + kbd->map_adjust)
+ keysym->scancode = kbd->map[evt->key_code - kbd->map_adjust];
+
+ if (keysym->scancode == SDL_SCANCODE_UNKNOWN || devdata->keyboard[kbd_idx].is_generic) {
+ if (evt->key_id - DIKI_UNKNOWN < SDL_arraysize(oskeymap))
+ keysym->scancode = oskeymap[evt->key_id - DIKI_UNKNOWN];
+ else
+ keysym->scancode = SDL_SCANCODE_UNKNOWN;
+ }
+
+ *unicode =
+ (DFB_KEY_TYPE(evt->key_symbol) == DIKT_UNICODE) ? evt->key_symbol : 0;
+ if (*unicode == 0 &&
+ (evt->key_symbol > 0 && evt->key_symbol < 255))
+ *unicode = evt->key_symbol;
+
+ return keysym;
+}
+
+static int
+DirectFB_TranslateButton(DFBInputDeviceButtonIdentifier button)
+{
+ switch (button) {
+ case DIBI_LEFT:
+ return 1;
+ case DIBI_MIDDLE:
+ return 2;
+ case DIBI_RIGHT:
+ return 3;
+ default:
+ return 0;
+ }
+}
+
+static DFBEnumerationResult
+EnumKeyboards(DFBInputDeviceID device_id,
+ DFBInputDeviceDescription desc, void *callbackdata)
+{
+ cb_data *cb = callbackdata;
+ DFB_DeviceData *devdata = cb->devdata;
+#if USE_MULTI_API
+ SDL_Keyboard keyboard;
+#endif
+ SDL_Keycode keymap[SDL_NUM_SCANCODES];
+
+ if (!cb->sys_kbd) {
+ if (cb->sys_ids) {
+ if (device_id >= 0x10)
+ return DFENUM_OK;
+ } else {
+ if (device_id < 0x10)
+ return DFENUM_OK;
+ }
+ } else {
+ if (device_id != DIDID_KEYBOARD)
+ return DFENUM_OK;
+ }
+
+ if ((desc.caps & DIDTF_KEYBOARD)) {
+#if USE_MULTI_API
+ SDL_zero(keyboard);
+ SDL_AddKeyboard(&keyboard, devdata->num_keyboard);
+#endif
+ devdata->keyboard[devdata->num_keyboard].id = device_id;
+ devdata->keyboard[devdata->num_keyboard].is_generic = 0;
+ if (!strncmp("X11", desc.name, 3))
+ {
+ devdata->keyboard[devdata->num_keyboard].map = xfree86_scancode_table2;
+ devdata->keyboard[devdata->num_keyboard].map_size = SDL_arraysize(xfree86_scancode_table2);
+ devdata->keyboard[devdata->num_keyboard].map_adjust = 8;
+ } else {
+ devdata->keyboard[devdata->num_keyboard].map = linux_scancode_table;
+ devdata->keyboard[devdata->num_keyboard].map_size = SDL_arraysize(linux_scancode_table);
+ devdata->keyboard[devdata->num_keyboard].map_adjust = 0;
+ }
+
+ SDL_DFB_LOG("Keyboard %d - %s\n", device_id, desc.name);
+
+ SDL_GetDefaultKeymap(keymap);
+#if USE_MULTI_API
+ SDL_SetKeymap(devdata->num_keyboard, 0, keymap, SDL_NUM_SCANCODES);
+#else
+ SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
+#endif
+ devdata->num_keyboard++;
+
+ if (cb->sys_kbd)
+ return DFENUM_CANCEL;
+ }
+ return DFENUM_OK;
+}
+
+void
+DirectFB_InitKeyboard(_THIS)
+{
+ SDL_DFB_DEVICEDATA(_this);
+ cb_data cb;
+
+ DirectFB_InitOSKeymap(_this, &oskeymap[0], SDL_arraysize(oskeymap));
+
+ devdata->num_keyboard = 0;
+ cb.devdata = devdata;
+
+ if (devdata->use_linux_input) {
+ cb.sys_kbd = 0;
+ cb.sys_ids = 0;
+ SDL_DFB_CHECK(devdata->dfb->
+ EnumInputDevices(devdata->dfb, EnumKeyboards, &cb));
+ if (devdata->num_keyboard == 0) {
+ cb.sys_ids = 1;
+ SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb,
+ EnumKeyboards,
+ &cb));
+ }
+ } else {
+ cb.sys_kbd = 1;
+ SDL_DFB_CHECK(devdata->dfb->EnumInputDevices(devdata->dfb,
+ EnumKeyboards,
+ &cb));
+ }
+}
+
+void
+DirectFB_QuitKeyboard(_THIS)
+{
+ /* SDL_DFB_DEVICEDATA(_this); */
+}
+
+#endif /* SDL_VIDEO_DRIVER_DIRECTFB */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_events.h b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_events.h
new file mode 100644
index 0000000..ccbdb0a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_events.h
@@ -0,0 +1,34 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_DirectFB_events_h_
+#define SDL_DirectFB_events_h_
+
+#include "../SDL_sysvideo.h"
+
+/* Functions to be exported */
+extern void DirectFB_InitKeyboard(_THIS);
+extern void DirectFB_QuitKeyboard(_THIS);
+extern void DirectFB_PumpEventsWindow(_THIS);
+
+#endif /* SDL_DirectFB_events_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_modes.c b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_modes.c
new file mode 100644
index 0000000..a3b8b45
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_modes.c
@@ -0,0 +1,414 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_DIRECTFB
+
+#include "SDL_DirectFB_video.h"
+#include "SDL_DirectFB_modes.h"
+
+#define DFB_MAX_MODES 200
+
+struct screen_callback_t
+{
+ int numscreens;
+ DFBScreenID screenid[DFB_MAX_SCREENS];
+ DFBDisplayLayerID gralayer[DFB_MAX_SCREENS];
+ DFBDisplayLayerID vidlayer[DFB_MAX_SCREENS];
+ int aux; /* auxiliary integer for callbacks */
+};
+
+struct modes_callback_t
+{
+ int nummodes;
+ SDL_DisplayMode *modelist;
+};
+
+static DFBEnumerationResult
+EnumModesCallback(int width, int height, int bpp, void *data)
+{
+ struct modes_callback_t *modedata = (struct modes_callback_t *) data;
+ SDL_DisplayMode mode;
+
+ mode.w = width;
+ mode.h = height;
+ mode.refresh_rate = 0;
+ mode.driverdata = NULL;
+ mode.format = SDL_PIXELFORMAT_UNKNOWN;
+
+ if (modedata->nummodes < DFB_MAX_MODES) {
+ modedata->modelist[modedata->nummodes++] = mode;
+ }
+
+ return DFENUM_OK;
+}
+
+static DFBEnumerationResult
+EnumScreensCallback(DFBScreenID screen_id, DFBScreenDescription desc,
+ void *callbackdata)
+{
+ struct screen_callback_t *devdata = (struct screen_callback_t *) callbackdata;
+
+ devdata->screenid[devdata->numscreens++] = screen_id;
+ return DFENUM_OK;
+}
+
+static DFBEnumerationResult
+EnumLayersCallback(DFBDisplayLayerID layer_id, DFBDisplayLayerDescription desc,
+ void *callbackdata)
+{
+ struct screen_callback_t *devdata = (struct screen_callback_t *) callbackdata;
+
+ if (desc.caps & DLCAPS_SURFACE) {
+ if ((desc.type & DLTF_GRAPHICS) && (desc.type & DLTF_VIDEO)) {
+ if (devdata->vidlayer[devdata->aux] == -1)
+ devdata->vidlayer[devdata->aux] = layer_id;
+ } else if (desc.type & DLTF_GRAPHICS) {
+ if (devdata->gralayer[devdata->aux] == -1)
+ devdata->gralayer[devdata->aux] = layer_id;
+ }
+ }
+ return DFENUM_OK;
+}
+
+static void
+CheckSetDisplayMode(_THIS, SDL_VideoDisplay * display, DFB_DisplayData * data, SDL_DisplayMode * mode)
+{
+ SDL_DFB_DEVICEDATA(_this);
+ DFBDisplayLayerConfig config;
+ DFBDisplayLayerConfigFlags failed;
+
+ SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
+ DLSCL_ADMINISTRATIVE));
+ config.width = mode->w;
+ config.height = mode->h;
+ config.pixelformat = DirectFB_SDLToDFBPixelFormat(mode->format);
+ config.flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT;
+ if (devdata->use_yuv_underlays) {
+ config.flags |= DLCONF_OPTIONS;
+ config.options = DLOP_ALPHACHANNEL;
+ }
+ failed = 0;
+ data->layer->TestConfiguration(data->layer, &config, &failed);
+ SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
+ DLSCL_SHARED));
+ if (failed == 0)
+ {
+ SDL_AddDisplayMode(display, mode);
+ SDL_DFB_LOG("Mode %d x %d Added\n", mode->w, mode->h);
+ }
+ else
+ SDL_DFB_ERR("Mode %d x %d not available: %x\n", mode->w,
+ mode->h, failed);
+
+ return;
+ error:
+ return;
+}
+
+
+void
+DirectFB_SetContext(_THIS, SDL_Window *window)
+{
+#if (DFB_VERSION_ATLEAST(1,0,0))
+ /* FIXME: does not work on 1.0/1.2 with radeon driver
+ * the approach did work with the matrox driver
+ * This has simply no effect.
+ */
+
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
+
+ /* FIXME: should we handle the error */
+ if (dispdata->vidIDinuse)
+ SDL_DFB_CHECK(dispdata->vidlayer->SwitchContext(dispdata->vidlayer,
+ DFB_TRUE));
+#endif
+}
+
+void
+DirectFB_InitModes(_THIS)
+{
+ SDL_DFB_DEVICEDATA(_this);
+ IDirectFBDisplayLayer *layer = NULL;
+ SDL_VideoDisplay display;
+ DFB_DisplayData *dispdata = NULL;
+ SDL_DisplayMode mode;
+ DFBGraphicsDeviceDescription caps;
+ DFBDisplayLayerConfig dlc;
+ struct screen_callback_t *screencbdata;
+
+ int tcw[DFB_MAX_SCREENS];
+ int tch[DFB_MAX_SCREENS];
+ int i;
+ DFBResult ret;
+
+ SDL_DFB_ALLOC_CLEAR(screencbdata, sizeof(*screencbdata));
+
+ screencbdata->numscreens = 0;
+
+ for (i = 0; i < DFB_MAX_SCREENS; i++) {
+ screencbdata->gralayer[i] = -1;
+ screencbdata->vidlayer[i] = -1;
+ }
+
+ SDL_DFB_CHECKERR(devdata->dfb->EnumScreens(devdata->dfb, &EnumScreensCallback,
+ screencbdata));
+
+ for (i = 0; i < screencbdata->numscreens; i++) {
+ IDirectFBScreen *screen;
+
+ SDL_DFB_CHECKERR(devdata->dfb->GetScreen(devdata->dfb,
+ screencbdata->screenid
+ [i], &screen));
+
+ screencbdata->aux = i;
+ SDL_DFB_CHECKERR(screen->EnumDisplayLayers(screen, &EnumLayersCallback,
+ screencbdata));
+ screen->GetSize(screen, &tcw[i], &tch[i]);
+
+ screen->Release(screen);
+ }
+
+ /* Query card capabilities */
+
+ devdata->dfb->GetDeviceDescription(devdata->dfb, &caps);
+
+ for (i = 0; i < screencbdata->numscreens; i++) {
+ SDL_DFB_CHECKERR(devdata->dfb->GetDisplayLayer(devdata->dfb,
+ screencbdata->gralayer
+ [i], &layer));
+
+ SDL_DFB_CHECKERR(layer->SetCooperativeLevel(layer,
+ DLSCL_ADMINISTRATIVE));
+ layer->EnableCursor(layer, 1);
+ SDL_DFB_CHECKERR(layer->SetCursorOpacity(layer, 0xC0));
+
+ if (devdata->use_yuv_underlays) {
+ dlc.flags = DLCONF_PIXELFORMAT | DLCONF_OPTIONS;
+ dlc.pixelformat = DSPF_ARGB;
+ dlc.options = DLOP_ALPHACHANNEL;
+
+ ret = layer->SetConfiguration(layer, &dlc);
+ if (ret != DFB_OK) {
+ /* try AiRGB if the previous failed */
+ dlc.pixelformat = DSPF_AiRGB;
+ SDL_DFB_CHECKERR(layer->SetConfiguration(layer, &dlc));
+ }
+ }
+
+ /* Query layer configuration to determine the current mode and pixelformat */
+ dlc.flags = DLCONF_ALL;
+ SDL_DFB_CHECKERR(layer->GetConfiguration(layer, &dlc));
+
+ mode.format = DirectFB_DFBToSDLPixelFormat(dlc.pixelformat);
+
+ if (mode.format == SDL_PIXELFORMAT_UNKNOWN) {
+ SDL_DFB_ERR("Unknown dfb pixelformat %x !\n", dlc.pixelformat);
+ goto error;
+ }
+
+ mode.w = dlc.width;
+ mode.h = dlc.height;
+ mode.refresh_rate = 0;
+ mode.driverdata = NULL;
+
+ SDL_DFB_ALLOC_CLEAR(dispdata, sizeof(*dispdata));
+
+ dispdata->layer = layer;
+ dispdata->pixelformat = dlc.pixelformat;
+ dispdata->cw = tcw[i];
+ dispdata->ch = tch[i];
+
+ /* YUV - Video layer */
+
+ dispdata->vidID = screencbdata->vidlayer[i];
+ dispdata->vidIDinuse = 0;
+
+ SDL_zero(display);
+
+ display.desktop_mode = mode;
+ display.current_mode = mode;
+ display.driverdata = dispdata;
+
+#if (DFB_VERSION_ATLEAST(1,2,0))
+ dlc.flags =
+ DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT |
+ DLCONF_OPTIONS;
+ ret = layer->SetConfiguration(layer, &dlc);
+#endif
+
+ SDL_DFB_CHECKERR(layer->SetCooperativeLevel(layer, DLSCL_SHARED));
+
+ SDL_AddVideoDisplay(&display);
+ }
+ SDL_DFB_FREE(screencbdata);
+ return;
+ error:
+ /* FIXME: Cleanup not complete, Free existing displays */
+ SDL_DFB_FREE(dispdata);
+ SDL_DFB_RELEASE(layer);
+ return;
+}
+
+void
+DirectFB_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
+{
+ SDL_DFB_DEVICEDATA(_this);
+ DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
+ SDL_DisplayMode mode;
+ struct modes_callback_t data;
+ int i;
+
+ data.nummodes = 0;
+ /* Enumerate the available fullscreen modes */
+ SDL_DFB_CALLOC(data.modelist, DFB_MAX_MODES, sizeof(SDL_DisplayMode));
+ SDL_DFB_CHECKERR(devdata->dfb->EnumVideoModes(devdata->dfb,
+ EnumModesCallback, &data));
+
+ for (i = 0; i < data.nummodes; ++i) {
+ mode = data.modelist[i];
+
+ mode.format = SDL_PIXELFORMAT_ARGB8888;
+ CheckSetDisplayMode(_this, display, dispdata, &mode);
+ mode.format = SDL_PIXELFORMAT_RGB888;
+ CheckSetDisplayMode(_this, display, dispdata, &mode);
+ mode.format = SDL_PIXELFORMAT_RGB24;
+ CheckSetDisplayMode(_this, display, dispdata, &mode);
+ mode.format = SDL_PIXELFORMAT_RGB565;
+ CheckSetDisplayMode(_this, display, dispdata, &mode);
+ mode.format = SDL_PIXELFORMAT_INDEX8;
+ CheckSetDisplayMode(_this, display, dispdata, &mode);
+ }
+
+ SDL_DFB_FREE(data.modelist);
+error:
+ return;
+}
+
+int
+DirectFB_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
+{
+ /*
+ * FIXME: video mode switch is currently broken for 1.2.0
+ *
+ */
+
+ SDL_DFB_DEVICEDATA(_this);
+ DFB_DisplayData *data = (DFB_DisplayData *) display->driverdata;
+ DFBDisplayLayerConfig config, rconfig;
+ DFBDisplayLayerConfigFlags fail = 0;
+
+ SDL_DFB_CHECKERR(data->layer->SetCooperativeLevel(data->layer,
+ DLSCL_ADMINISTRATIVE));
+
+ SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &config));
+ config.flags = DLCONF_WIDTH | DLCONF_HEIGHT;
+ if (mode->format != SDL_PIXELFORMAT_UNKNOWN) {
+ config.flags |= DLCONF_PIXELFORMAT;
+ config.pixelformat = DirectFB_SDLToDFBPixelFormat(mode->format);
+ data->pixelformat = config.pixelformat;
+ }
+ config.width = mode->w;
+ config.height = mode->h;
+
+ if (devdata->use_yuv_underlays) {
+ config.flags |= DLCONF_OPTIONS;
+ config.options = DLOP_ALPHACHANNEL;
+ }
+
+ data->layer->TestConfiguration(data->layer, &config, &fail);
+
+ if (fail &
+ (DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT |
+ DLCONF_OPTIONS)) {
+ SDL_DFB_ERR("Error setting mode %dx%d-%x\n", mode->w, mode->h,
+ mode->format);
+ return -1;
+ }
+
+ config.flags &= ~fail;
+ SDL_DFB_CHECKERR(data->layer->SetConfiguration(data->layer, &config));
+#if (DFB_VERSION_ATLEAST(1,2,0))
+ /* Need to call this twice ! */
+ SDL_DFB_CHECKERR(data->layer->SetConfiguration(data->layer, &config));
+#endif
+
+ /* Double check */
+ SDL_DFB_CHECKERR(data->layer->GetConfiguration(data->layer, &rconfig));
+ SDL_DFB_CHECKERR(data->
+ layer->SetCooperativeLevel(data->layer, DLSCL_SHARED));
+
+ if ((config.width != rconfig.width) || (config.height != rconfig.height)
+ || ((mode->format != SDL_PIXELFORMAT_UNKNOWN)
+ && (config.pixelformat != rconfig.pixelformat))) {
+ SDL_DFB_ERR("Error setting mode %dx%d-%x\n", mode->w, mode->h,
+ mode->format);
+ return -1;
+ }
+
+ data->pixelformat = rconfig.pixelformat;
+ data->cw = config.width;
+ data->ch = config.height;
+ display->current_mode = *mode;
+
+ return 0;
+ error:
+ return -1;
+}
+
+void
+DirectFB_QuitModes(_THIS)
+{
+ SDL_DisplayMode tmode;
+ int i;
+
+ for (i = 0; i < _this->num_displays; ++i) {
+ SDL_VideoDisplay *display = &_this->displays[i];
+ DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
+
+ SDL_GetDesktopDisplayMode(i, &tmode);
+ tmode.format = SDL_PIXELFORMAT_UNKNOWN;
+ DirectFB_SetDisplayMode(_this, display, &tmode);
+
+ SDL_GetDesktopDisplayMode(i, &tmode);
+ DirectFB_SetDisplayMode(_this, display, &tmode);
+
+ if (dispdata->layer) {
+ SDL_DFB_CHECK(dispdata->
+ layer->SetCooperativeLevel(dispdata->layer,
+ DLSCL_ADMINISTRATIVE));
+ SDL_DFB_CHECK(dispdata->
+ layer->SetCursorOpacity(dispdata->layer, 0x00));
+ SDL_DFB_CHECK(dispdata->
+ layer->SetCooperativeLevel(dispdata->layer,
+ DLSCL_SHARED));
+ }
+
+ SDL_DFB_RELEASE(dispdata->layer);
+ SDL_DFB_RELEASE(dispdata->vidlayer);
+
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_DIRECTFB */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_modes.h b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_modes.h
new file mode 100644
index 0000000..75d8bbf
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_modes.h
@@ -0,0 +1,59 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_directfb_modes_h_
+#define SDL_directfb_modes_h_
+
+#include <directfb.h>
+
+#include "../SDL_sysvideo.h"
+
+#define SDL_DFB_DISPLAYDATA(win) DFB_DisplayData *dispdata = ((win) ? (DFB_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata : NULL)
+
+typedef struct _DFB_DisplayData DFB_DisplayData;
+struct _DFB_DisplayData
+{
+ IDirectFBDisplayLayer *layer;
+ DFBSurfacePixelFormat pixelformat;
+ /* FIXME: support for multiple video layer.
+ * However, I do not know any card supporting
+ * more than one
+ */
+ DFBDisplayLayerID vidID;
+ IDirectFBDisplayLayer *vidlayer;
+
+ int vidIDinuse;
+
+ int cw;
+ int ch;
+};
+
+
+extern void DirectFB_InitModes(_THIS);
+extern void DirectFB_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
+extern int DirectFB_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
+extern void DirectFB_QuitModes(_THIS);
+
+extern void DirectFB_SetContext(_THIS, SDL_Window *window);
+
+#endif /* SDL_directfb_modes_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_mouse.c b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_mouse.c
new file mode 100644
index 0000000..a2b3e41
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_mouse.c
@@ -0,0 +1,389 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_DIRECTFB
+
+#include "SDL_assert.h"
+
+#include "SDL_DirectFB_video.h"
+#include "SDL_DirectFB_mouse.h"
+#include "SDL_DirectFB_modes.h"
+#include "SDL_DirectFB_window.h"
+
+#include "../SDL_sysvideo.h"
+#include "../../events/SDL_mouse_c.h"
+
+static SDL_Cursor *DirectFB_CreateDefaultCursor(void);
+static SDL_Cursor *DirectFB_CreateCursor(SDL_Surface * surface,
+ int hot_x, int hot_y);
+static int DirectFB_ShowCursor(SDL_Cursor * cursor);
+static void DirectFB_FreeCursor(SDL_Cursor * cursor);
+static void DirectFB_WarpMouse(SDL_Window * window, int x, int y);
+
+static const char *arrow[] = {
+ /* pixels */
+ "X ",
+ "XX ",
+ "X.X ",
+ "X..X ",
+ "X...X ",
+ "X....X ",
+ "X.....X ",
+ "X......X ",
+ "X.......X ",
+ "X........X ",
+ "X.....XXXXX ",
+ "X..X..X ",
+ "X.X X..X ",
+ "XX X..X ",
+ "X X..X ",
+ " X..X ",
+ " X..X ",
+ " X..X ",
+ " XX ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+};
+
+static SDL_Cursor *
+DirectFB_CreateDefaultCursor(void)
+{
+ SDL_VideoDevice *dev = SDL_GetVideoDevice();
+
+ SDL_DFB_DEVICEDATA(dev);
+ DFB_CursorData *curdata;
+ DFBSurfaceDescription dsc;
+ SDL_Cursor *cursor;
+ Uint32 *dest;
+ int pitch, i, j;
+
+ SDL_DFB_ALLOC_CLEAR( cursor, sizeof(*cursor));
+ SDL_DFB_ALLOC_CLEAR(curdata, sizeof(*curdata));
+
+ dsc.flags =
+ DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
+ dsc.caps = DSCAPS_VIDEOONLY;
+ dsc.width = 32;
+ dsc.height = 32;
+ dsc.pixelformat = DSPF_ARGB;
+
+ SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc,
+ &curdata->surf));
+ curdata->hotx = 0;
+ curdata->hoty = 0;
+ cursor->driverdata = curdata;
+
+ SDL_DFB_CHECKERR(curdata->surf->Lock(curdata->surf, DSLF_WRITE,
+ (void *) &dest, &pitch));
+
+ /* Relies on the fact that this is only called with ARGB surface. */
+ for (i = 0; i < 32; i++)
+ {
+ for (j = 0; j < 32; j++)
+ {
+ switch (arrow[i][j])
+ {
+ case ' ': dest[j] = 0x00000000; break;
+ case '.': dest[j] = 0xffffffff; break;
+ case 'X': dest[j] = 0xff000000; break;
+ }
+ }
+ dest += (pitch >> 2);
+ }
+
+ curdata->surf->Unlock(curdata->surf);
+ return cursor;
+ error:
+ return NULL;
+}
+
+/* Create a cursor from a surface */
+static SDL_Cursor *
+DirectFB_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
+{
+ SDL_VideoDevice *dev = SDL_GetVideoDevice();
+
+ SDL_DFB_DEVICEDATA(dev);
+ DFB_CursorData *curdata;
+ DFBSurfaceDescription dsc;
+ SDL_Cursor *cursor;
+ Uint32 *dest;
+ Uint32 *p;
+ int pitch, i;
+
+ SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
+ SDL_assert(surface->pitch == surface->w * 4);
+
+ SDL_DFB_ALLOC_CLEAR( cursor, sizeof(*cursor));
+ SDL_DFB_ALLOC_CLEAR(curdata, sizeof(*curdata));
+
+ dsc.flags =
+ DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
+ dsc.caps = DSCAPS_VIDEOONLY;
+ dsc.width = surface->w;
+ dsc.height = surface->h;
+ dsc.pixelformat = DSPF_ARGB;
+
+ SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc,
+ &curdata->surf));
+ curdata->hotx = hot_x;
+ curdata->hoty = hot_y;
+ cursor->driverdata = curdata;
+
+ SDL_DFB_CHECKERR(curdata->surf->Lock(curdata->surf, DSLF_WRITE,
+ (void *) &dest, &pitch));
+
+ p = surface->pixels;
+ for (i = 0; i < surface->h; i++)
+ memcpy((char *) dest + i * pitch,
+ (char *) p + i * surface->pitch, 4 * surface->w);
+
+ curdata->surf->Unlock(curdata->surf);
+ return cursor;
+ error:
+ return NULL;
+}
+
+/* Show the specified cursor, or hide if cursor is NULL */
+static int
+DirectFB_ShowCursor(SDL_Cursor * cursor)
+{
+ SDL_DFB_CURSORDATA(cursor);
+ SDL_Window *window;
+
+ window = SDL_GetFocusWindow();
+ if (!window)
+ return -1;
+ else {
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+
+ if (display) {
+ DFB_DisplayData *dispdata =
+ (DFB_DisplayData *) display->driverdata;
+ DFB_WindowData *windata = (DFB_WindowData *) window->driverdata;
+
+ if (cursor)
+ SDL_DFB_CHECKERR(windata->dfbwin->
+ SetCursorShape(windata->dfbwin,
+ curdata->surf, curdata->hotx,
+ curdata->hoty));
+
+ SDL_DFB_CHECKERR(dispdata->layer->
+ SetCooperativeLevel(dispdata->layer,
+ DLSCL_ADMINISTRATIVE));
+ SDL_DFB_CHECKERR(dispdata->layer->
+ SetCursorOpacity(dispdata->layer,
+ cursor ? 0xC0 : 0x00));
+ SDL_DFB_CHECKERR(dispdata->layer->
+ SetCooperativeLevel(dispdata->layer,
+ DLSCL_SHARED));
+ }
+ }
+
+ return 0;
+ error:
+ return -1;
+}
+
+/* Free a window manager cursor */
+static void
+DirectFB_FreeCursor(SDL_Cursor * cursor)
+{
+ SDL_DFB_CURSORDATA(cursor);
+
+ SDL_DFB_RELEASE(curdata->surf);
+ SDL_DFB_FREE(cursor->driverdata);
+ SDL_DFB_FREE(cursor);
+}
+
+/* Warp the mouse to (x,y) */
+static void
+DirectFB_WarpMouse(SDL_Window * window, int x, int y)
+{
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
+ DFB_WindowData *windata = (DFB_WindowData *) window->driverdata;
+ int cx, cy;
+
+ SDL_DFB_CHECKERR(windata->dfbwin->GetPosition(windata->dfbwin, &cx, &cy));
+ SDL_DFB_CHECKERR(dispdata->layer->WarpCursor(dispdata->layer,
+ cx + x + windata->client.x,
+ cy + y + windata->client.y));
+
+ error:
+ return;
+}
+
+#if USE_MULTI_API
+
+static void DirectFB_MoveCursor(SDL_Cursor * cursor);
+static void DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_Window * window,
+ int x, int y);
+static void DirectFB_FreeMouse(SDL_Mouse * mouse);
+
+static int id_mask;
+
+static DFBEnumerationResult
+EnumMice(DFBInputDeviceID device_id, DFBInputDeviceDescription desc,
+ void *callbackdata)
+{
+ DFB_DeviceData *devdata = callbackdata;
+
+ if ((desc.type & DIDTF_MOUSE) && (device_id & id_mask)) {
+ SDL_Mouse mouse;
+
+ SDL_zero(mouse);
+ mouse.id = device_id;
+ mouse.CreateCursor = DirectFB_CreateCursor;
+ mouse.ShowCursor = DirectFB_ShowCursor;
+ mouse.MoveCursor = DirectFB_MoveCursor;
+ mouse.FreeCursor = DirectFB_FreeCursor;
+ mouse.WarpMouse = DirectFB_WarpMouse;
+ mouse.FreeMouse = DirectFB_FreeMouse;
+ mouse.cursor_shown = 1;
+
+ SDL_AddMouse(&mouse, desc.name, 0, 0, 1);
+ devdata->mouse_id[devdata->num_mice++] = device_id;
+ }
+ return DFENUM_OK;
+}
+
+void
+DirectFB_InitMouse(_THIS)
+{
+ SDL_DFB_DEVICEDATA(_this);
+
+ devdata->num_mice = 0;
+ if (devdata->use_linux_input) {
+ /* try non-core devices first */
+ id_mask = 0xF0;
+ devdata->dfb->EnumInputDevices(devdata->dfb, EnumMice, devdata);
+ if (devdata->num_mice == 0) {
+ /* try core devices */
+ id_mask = 0x0F;
+ devdata->dfb->EnumInputDevices(devdata->dfb, EnumMice, devdata);
+ }
+ }
+ if (devdata->num_mice == 0) {
+ SDL_Mouse mouse;
+
+ SDL_zero(mouse);
+ mouse.CreateCursor = DirectFB_CreateCursor;
+ mouse.ShowCursor = DirectFB_ShowCursor;
+ mouse.MoveCursor = DirectFB_MoveCursor;
+ mouse.FreeCursor = DirectFB_FreeCursor;
+ mouse.WarpMouse = DirectFB_WarpMouse;
+ mouse.FreeMouse = DirectFB_FreeMouse;
+ mouse.cursor_shown = 1;
+
+ SDL_AddMouse(&mouse, "Mouse", 0, 0, 1);
+ devdata->num_mice = 1;
+ }
+}
+
+void
+DirectFB_QuitMouse(_THIS)
+{
+ SDL_DFB_DEVICEDATA(_this);
+
+ if (devdata->use_linux_input) {
+ SDL_MouseQuit();
+ } else {
+ SDL_DelMouse(0);
+ }
+}
+
+
+/* This is called when a mouse motion event occurs */
+static void
+DirectFB_MoveCursor(SDL_Cursor * cursor)
+{
+
+}
+
+/* Warp the mouse to (x,y) */
+static void
+DirectFB_WarpMouse(SDL_Mouse * mouse, SDL_Window * window, int x, int y)
+{
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
+ DFB_WindowData *windata = (DFB_WindowData *) window->driverdata;
+ DFBResult ret;
+ int cx, cy;
+
+ SDL_DFB_CHECKERR(windata->dfbwin->GetPosition(windata->dfbwin, &cx, &cy));
+ SDL_DFB_CHECKERR(dispdata->layer->WarpCursor(dispdata->layer,
+ cx + x + windata->client.x,
+ cy + y + windata->client.y));
+
+ error:
+ return;
+}
+
+/* Free the mouse when it's time */
+static void
+DirectFB_FreeMouse(SDL_Mouse * mouse)
+{
+ /* nothing yet */
+}
+
+#else /* USE_MULTI_API */
+
+void
+DirectFB_InitMouse(_THIS)
+{
+ SDL_DFB_DEVICEDATA(_this);
+
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ mouse->CreateCursor = DirectFB_CreateCursor;
+ mouse->ShowCursor = DirectFB_ShowCursor;
+ mouse->WarpMouse = DirectFB_WarpMouse;
+ mouse->FreeCursor = DirectFB_FreeCursor;
+
+ SDL_SetDefaultCursor(DirectFB_CreateDefaultCursor());
+
+ devdata->num_mice = 1;
+}
+
+void
+DirectFB_QuitMouse(_THIS)
+{
+}
+
+
+#endif
+
+#endif /* SDL_VIDEO_DRIVER_DIRECTFB */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_mouse.h b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_mouse.h
new file mode 100644
index 0000000..e1236a0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_mouse.h
@@ -0,0 +1,44 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_DirectFB_mouse_h_
+#define SDL_DirectFB_mouse_h_
+
+#include <directfb.h>
+
+#include "../SDL_sysvideo.h"
+
+typedef struct _DFB_CursorData DFB_CursorData;
+struct _DFB_CursorData
+{
+ IDirectFBSurface *surf;
+ int hotx;
+ int hoty;
+};
+
+#define SDL_DFB_CURSORDATA(curs) DFB_CursorData *curdata = (DFB_CursorData *) ((curs) ? (curs)->driverdata : NULL)
+
+extern void DirectFB_InitMouse(_THIS);
+extern void DirectFB_QuitMouse(_THIS);
+
+#endif /* SDL_DirectFB_mouse_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_opengl.c b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_opengl.c
new file mode 100644
index 0000000..93d2fde
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_opengl.c
@@ -0,0 +1,332 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_DIRECTFB
+
+#include "SDL_DirectFB_video.h"
+
+#if SDL_DIRECTFB_OPENGL
+
+#include "SDL_DirectFB_opengl.h"
+#include "SDL_DirectFB_window.h"
+
+#include <directfbgl.h>
+#include "SDL_loadso.h"
+#endif
+
+#if SDL_DIRECTFB_OPENGL
+
+struct SDL_GLDriverData
+{
+ int gl_active; /* to stop switching drivers while we have a valid context */
+ int initialized;
+ DirectFB_GLContext *firstgl; /* linked list */
+
+ /* OpenGL */
+ void (*glFinish) (void);
+ void (*glFlush) (void);
+};
+
+#define OPENGL_REQUIRS_DLOPEN
+#if defined(OPENGL_REQUIRS_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
+#include <dlfcn.h>
+#define GL_LoadObject(X) dlopen(X, (RTLD_NOW|RTLD_GLOBAL))
+#define GL_LoadFunction dlsym
+#define GL_UnloadObject dlclose
+#else
+#define GL_LoadObject SDL_LoadObject
+#define GL_LoadFunction SDL_LoadFunction
+#define GL_UnloadObject SDL_UnloadObject
+#endif
+
+static void DirectFB_GL_UnloadLibrary(_THIS);
+
+int
+DirectFB_GL_Initialize(_THIS)
+{
+ if (_this->gl_data) {
+ return 0;
+ }
+
+ _this->gl_data =
+ (struct SDL_GLDriverData *) SDL_calloc(1,
+ sizeof(struct
+ SDL_GLDriverData));
+ if (!_this->gl_data) {
+ return SDL_OutOfMemory();
+ }
+ _this->gl_data->initialized = 0;
+
+ ++_this->gl_data->initialized;
+ _this->gl_data->firstgl = NULL;
+
+ if (DirectFB_GL_LoadLibrary(_this, NULL) < 0) {
+ return -1;
+ }
+
+ /* Initialize extensions */
+ /* FIXME needed?
+ * X11_GL_InitExtensions(_this);
+ */
+
+ return 0;
+}
+
+void
+DirectFB_GL_Shutdown(_THIS)
+{
+ if (!_this->gl_data || (--_this->gl_data->initialized > 0)) {
+ return;
+ }
+
+ DirectFB_GL_UnloadLibrary(_this);
+
+ SDL_free(_this->gl_data);
+ _this->gl_data = NULL;
+}
+
+int
+DirectFB_GL_LoadLibrary(_THIS, const char *path)
+{
+ void *handle = NULL;
+
+ SDL_DFB_DEBUG("Loadlibrary : %s\n", path);
+
+ if (_this->gl_data->gl_active) {
+ return SDL_SetError("OpenGL context already created");
+ }
+
+
+ if (path == NULL) {
+ path = SDL_getenv("SDL_OPENGL_LIBRARY");
+ if (path == NULL) {
+ path = "libGL.so.1";
+ }
+ }
+
+ handle = GL_LoadObject(path);
+ if (handle == NULL) {
+ SDL_DFB_ERR("Library not found: %s\n", path);
+ /* SDL_LoadObject() will call SDL_SetError() for us. */
+ return -1;
+ }
+
+ SDL_DFB_DEBUG("Loaded library: %s\n", path);
+
+ _this->gl_config.dll_handle = handle;
+ if (path) {
+ SDL_strlcpy(_this->gl_config.driver_path, path,
+ SDL_arraysize(_this->gl_config.driver_path));
+ } else {
+ *_this->gl_config.driver_path = '\0';
+ }
+
+ _this->gl_data->glFinish = DirectFB_GL_GetProcAddress(_this, "glFinish");
+ _this->gl_data->glFlush = DirectFB_GL_GetProcAddress(_this, "glFlush");
+
+ return 0;
+}
+
+static void
+DirectFB_GL_UnloadLibrary(_THIS)
+{
+ #if 0
+ int ret = GL_UnloadObject(_this->gl_config.dll_handle);
+ if (ret)
+ SDL_DFB_ERR("Error #%d trying to unload library.\n", ret);
+ _this->gl_config.dll_handle = NULL;
+#endif
+ /* Free OpenGL memory */
+ SDL_free(_this->gl_data);
+ _this->gl_data = NULL;
+}
+
+void *
+DirectFB_GL_GetProcAddress(_THIS, const char *proc)
+{
+ void *handle;
+
+ handle = _this->gl_config.dll_handle;
+ return GL_LoadFunction(handle, proc);
+}
+
+SDL_GLContext
+DirectFB_GL_CreateContext(_THIS, SDL_Window * window)
+{
+ SDL_DFB_WINDOWDATA(window);
+ DirectFB_GLContext *context;
+
+ SDL_DFB_ALLOC_CLEAR(context, sizeof(DirectFB_GLContext));
+
+ SDL_DFB_CHECKERR(windata->surface->GetGL(windata->surface,
+ &context->context));
+
+ if (!context->context)
+ return NULL;
+
+ context->is_locked = 0;
+ context->sdl_window = window;
+
+ context->next = _this->gl_data->firstgl;
+ _this->gl_data->firstgl = context;
+
+ SDL_DFB_CHECK(context->context->Unlock(context->context));
+
+ if (DirectFB_GL_MakeCurrent(_this, window, context) < 0) {
+ DirectFB_GL_DeleteContext(_this, context);
+ return NULL;
+ }
+
+ return context;
+
+ error:
+ return NULL;
+}
+
+int
+DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
+{
+ DirectFB_GLContext *ctx = (DirectFB_GLContext *) context;
+ DirectFB_GLContext *p;
+
+ for (p = _this->gl_data->firstgl; p; p = p->next)
+ {
+ if (p->is_locked) {
+ SDL_DFB_CHECKERR(p->context->Unlock(p->context));
+ p->is_locked = 0;
+ }
+
+ }
+
+ if (ctx != NULL) {
+ SDL_DFB_CHECKERR(ctx->context->Lock(ctx->context));
+ ctx->is_locked = 1;
+ }
+
+ return 0;
+ error:
+ return -1;
+}
+
+int
+DirectFB_GL_SetSwapInterval(_THIS, int interval)
+{
+ return SDL_Unsupported();
+}
+
+int
+DirectFB_GL_GetSwapInterval(_THIS)
+{
+ return 0;
+}
+
+int
+DirectFB_GL_SwapWindow(_THIS, SDL_Window * window)
+{
+ SDL_DFB_WINDOWDATA(window);
+ DirectFB_GLContext *p;
+
+#if 0
+ if (devdata->glFinish)
+ devdata->glFinish();
+ else if (devdata->glFlush)
+ devdata->glFlush();
+#endif
+
+ for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
+ if (p->sdl_window == window && p->is_locked)
+ {
+ SDL_DFB_CHECKERR(p->context->Unlock(p->context));
+ p->is_locked = 0;
+ }
+
+ SDL_DFB_CHECKERR(windata->window_surface->Flip(windata->window_surface,NULL, DSFLIP_PIPELINE |DSFLIP_BLIT | DSFLIP_ONSYNC ));
+ return 0;
+ error:
+ return -1;
+}
+
+void
+DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context)
+{
+ DirectFB_GLContext *ctx = (DirectFB_GLContext *) context;
+ DirectFB_GLContext *p;
+
+ if (ctx->is_locked)
+ SDL_DFB_CHECK(ctx->context->Unlock(ctx->context));
+ SDL_DFB_RELEASE(ctx->context);
+
+ for (p = _this->gl_data->firstgl; p && p->next != ctx; p = p->next)
+ ;
+ if (p)
+ p->next = ctx->next;
+ else
+ _this->gl_data->firstgl = ctx->next;
+
+ SDL_DFB_FREE(ctx);
+}
+
+void
+DirectFB_GL_FreeWindowContexts(_THIS, SDL_Window * window)
+{
+ DirectFB_GLContext *p;
+
+ for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
+ if (p->sdl_window == window)
+ {
+ if (p->is_locked)
+ SDL_DFB_CHECK(p->context->Unlock(p->context));
+ SDL_DFB_RELEASE(p->context);
+ }
+}
+
+void
+DirectFB_GL_ReAllocWindowContexts(_THIS, SDL_Window * window)
+{
+ DirectFB_GLContext *p;
+
+ for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
+ if (p->sdl_window == window)
+ {
+ SDL_DFB_WINDOWDATA(window);
+ SDL_DFB_CHECK(windata->surface->GetGL(windata->surface,
+ &p->context));
+ if (p->is_locked)
+ SDL_DFB_CHECK(p->context->Lock(p->context));
+ }
+}
+
+void
+DirectFB_GL_DestroyWindowContexts(_THIS, SDL_Window * window)
+{
+ DirectFB_GLContext *p;
+
+ for (p = _this->gl_data->firstgl; p != NULL; p = p->next)
+ if (p->sdl_window == window)
+ DirectFB_GL_DeleteContext(_this, p);
+}
+
+#endif
+
+#endif /* SDL_VIDEO_DRIVER_DIRECTFB */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_opengl.h b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_opengl.h
new file mode 100644
index 0000000..9463e1b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_opengl.h
@@ -0,0 +1,64 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+
+#ifndef SDL_directfb_opengl_h_
+#define SDL_directfb_opengl_h_
+
+#include "SDL_DirectFB_video.h"
+
+#if SDL_DIRECTFB_OPENGL
+
+#include "SDL_opengl.h"
+
+typedef struct _DirectFB_GLContext DirectFB_GLContext;
+struct _DirectFB_GLContext
+{
+ IDirectFBGL *context;
+ DirectFB_GLContext *next;
+
+ SDL_Window *sdl_window;
+ int is_locked;
+};
+
+/* OpenGL functions */
+extern int DirectFB_GL_Initialize(_THIS);
+extern void DirectFB_GL_Shutdown(_THIS);
+
+extern int DirectFB_GL_LoadLibrary(_THIS, const char *path);
+extern void *DirectFB_GL_GetProcAddress(_THIS, const char *proc);
+extern SDL_GLContext DirectFB_GL_CreateContext(_THIS, SDL_Window * window);
+extern int DirectFB_GL_MakeCurrent(_THIS, SDL_Window * window,
+ SDL_GLContext context);
+extern int DirectFB_GL_SetSwapInterval(_THIS, int interval);
+extern int DirectFB_GL_GetSwapInterval(_THIS);
+extern int DirectFB_GL_SwapWindow(_THIS, SDL_Window * window);
+extern void DirectFB_GL_DeleteContext(_THIS, SDL_GLContext context);
+
+extern void DirectFB_GL_FreeWindowContexts(_THIS, SDL_Window * window);
+extern void DirectFB_GL_ReAllocWindowContexts(_THIS, SDL_Window * window);
+extern void DirectFB_GL_DestroyWindowContexts(_THIS, SDL_Window * window);
+
+#endif /* SDL_DIRECTFB_OPENGL */
+
+#endif /* SDL_directfb_opengl_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_render.c b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_render.c
new file mode 100644
index 0000000..4054f73
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_render.c
@@ -0,0 +1,1335 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_DIRECTFB
+#include "SDL_DirectFB_window.h"
+#include "SDL_DirectFB_modes.h"
+
+#include "SDL_syswm.h"
+#include "SDL_DirectFB_shape.h"
+
+#include "../SDL_sysvideo.h"
+#include "../../render/SDL_sysrender.h"
+
+#ifndef DFB_VERSION_ATLEAST
+
+#define DFB_VERSIONNUM(X, Y, Z) \
+ ((X)*1000 + (Y)*100 + (Z))
+
+#define DFB_COMPILEDVERSION \
+ DFB_VERSIONNUM(DIRECTFB_MAJOR_VERSION, DIRECTFB_MINOR_VERSION, DIRECTFB_MICRO_VERSION)
+
+#define DFB_VERSION_ATLEAST(X, Y, Z) \
+ (DFB_COMPILEDVERSION >= DFB_VERSIONNUM(X, Y, Z))
+
+#define SDL_DFB_CHECK(x) x
+
+#endif
+
+/* the following is not yet tested ... */
+#define USE_DISPLAY_PALETTE (0)
+
+
+#define SDL_DFB_RENDERERDATA(rend) DirectFB_RenderData *renddata = ((rend) ? (DirectFB_RenderData *) (rend)->driverdata : NULL)
+
+
+/* DirectFB renderer implementation */
+
+static SDL_Renderer *DirectFB_CreateRenderer(SDL_Window * window,
+ Uint32 flags);
+static void DirectFB_ActivateRenderer(SDL_Renderer * renderer);
+static int DirectFB_CreateTexture(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static int DirectFB_QueryTexturePixels(SDL_Renderer * renderer,
+ SDL_Texture * texture,
+ void **pixels, int *pitch);
+static int DirectFB_SetTexturePalette(SDL_Renderer * renderer,
+ SDL_Texture * texture,
+ const SDL_Color * colors,
+ int firstcolor, int ncolors);
+static int DirectFB_GetTexturePalette(SDL_Renderer * renderer,
+ SDL_Texture * texture,
+ SDL_Color * colors,
+ int firstcolor, int ncolors);
+static int DirectFB_SetTextureAlphaMod(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static int DirectFB_SetTextureColorMod(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static int DirectFB_SetTextureBlendMode(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static int DirectFB_SetTextureScaleMode(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static int DirectFB_UpdateTexture(SDL_Renderer * renderer,
+ SDL_Texture * texture,
+ const SDL_Rect * rect,
+ const void *pixels, int pitch);
+static int DirectFB_LockTexture(SDL_Renderer * renderer,
+ SDL_Texture * texture,
+ const SDL_Rect * rect,
+ void **pixels, int *pitch);
+static void DirectFB_UnlockTexture(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static void DirectFB_DirtyTexture(SDL_Renderer * renderer,
+ SDL_Texture * texture, int numrects,
+ const SDL_Rect * rects);
+static int DirectFB_SetDrawBlendMode(SDL_Renderer * renderer);
+static int DirectFB_RenderDrawPoints(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count);
+static int DirectFB_RenderDrawLines(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count);
+static int DirectFB_RenderDrawRects(SDL_Renderer * renderer,
+ const SDL_Rect ** rects, int count);
+static int DirectFB_RenderFillRects(SDL_Renderer * renderer,
+ const SDL_FRect * rects, int count);
+static int DirectFB_RenderCopy(SDL_Renderer * renderer,
+ SDL_Texture * texture,
+ const SDL_Rect * srcrect,
+ const SDL_FRect * dstrect);
+static void DirectFB_RenderPresent(SDL_Renderer * renderer);
+static void DirectFB_DestroyTexture(SDL_Renderer * renderer,
+ SDL_Texture * texture);
+static void DirectFB_DestroyRenderer(SDL_Renderer * renderer);
+static int DirectFB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 format, void * pixels, int pitch);
+static int DirectFB_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 format, const void * pixels, int pitch);
+static int DirectFB_UpdateViewport(SDL_Renderer * renderer);
+static int DirectFB_UpdateClipRect(SDL_Renderer * renderer);
+static int DirectFB_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture);
+
+static int PrepareDraw(SDL_Renderer * renderer);
+
+
+#define SDL_DFB_WINDOWSURFACE(win) IDirectFBSurface *destsurf = ((DFB_WindowData *) ((win)->driverdata))->surface;
+
+SDL_RenderDriver DirectFB_RenderDriver = {
+ DirectFB_CreateRenderer,
+ {
+ "directfb",
+ (SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
+ /* (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
+ SDL_TEXTUREMODULATE_ALPHA),
+ (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND |
+ SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
+ (SDL_SCALEMODE_NONE | SDL_SCALEMODE_FAST |
+ SDL_SCALEMODE_SLOW | SDL_SCALEMODE_BEST), */
+ 0,
+ {
+ /* formats filled in later */
+ },
+ 0,
+ 0}
+};
+
+typedef struct
+{
+ SDL_Window *window;
+ DFBSurfaceFlipFlags flipflags;
+ int size_changed;
+ int lastBlendMode;
+ DFBSurfaceBlittingFlags blitFlags;
+ DFBSurfaceDrawingFlags drawFlags;
+ IDirectFBSurface* target;
+} DirectFB_RenderData;
+
+typedef struct
+{
+ IDirectFBSurface *surface;
+ Uint32 format;
+ void *pixels;
+ int pitch;
+ IDirectFBPalette *palette;
+ int isDirty;
+
+ SDL_VideoDisplay *display; /* only for yuv textures */
+
+#if (DFB_VERSION_ATLEAST(1,2,0))
+ DFBSurfaceRenderOptions render_options;
+#endif
+} DirectFB_TextureData;
+
+static SDL_INLINE void
+SDLtoDFBRect(const SDL_Rect * sr, DFBRectangle * dr)
+{
+ dr->x = sr->x;
+ dr->y = sr->y;
+ dr->h = sr->h;
+ dr->w = sr->w;
+}
+static SDL_INLINE void
+SDLtoDFBRect_Float(const SDL_FRect * sr, DFBRectangle * dr)
+{
+ dr->x = sr->x;
+ dr->y = sr->y;
+ dr->h = sr->h;
+ dr->w = sr->w;
+}
+
+
+static int
+TextureHasAlpha(DirectFB_TextureData * data)
+{
+ /* Drawing primitive ? */
+ if (!data)
+ return 0;
+
+ return (DFB_PIXELFORMAT_HAS_ALPHA(DirectFB_SDLToDFBPixelFormat(data->format)) ? 1 : 0);
+#if 0
+ switch (data->format) {
+ case SDL_PIXELFORMAT_INDEX4LSB:
+ case SDL_PIXELFORMAT_INDEX4MSB:
+ case SDL_PIXELFORMAT_ARGB4444:
+ case SDL_PIXELFORMAT_ARGB1555:
+ case SDL_PIXELFORMAT_ARGB8888:
+ case SDL_PIXELFORMAT_RGBA8888:
+ case SDL_PIXELFORMAT_ABGR8888:
+ case SDL_PIXELFORMAT_BGRA8888:
+ case SDL_PIXELFORMAT_ARGB2101010:
+ return 1;
+ default:
+ return 0;
+ }
+#endif
+}
+
+static SDL_INLINE IDirectFBSurface *get_dfb_surface(SDL_Window *window)
+{
+ SDL_SysWMinfo wm_info;
+ SDL_memset(&wm_info, 0, sizeof(SDL_SysWMinfo));
+
+ SDL_VERSION(&wm_info.version);
+ if (!SDL_GetWindowWMInfo(window, &wm_info)) {
+ return NULL;
+ }
+
+ return wm_info.info.dfb.surface;
+}
+
+static SDL_INLINE IDirectFBWindow *get_dfb_window(SDL_Window *window)
+{
+ SDL_SysWMinfo wm_info;
+ SDL_memset(&wm_info, 0, sizeof(SDL_SysWMinfo));
+
+ SDL_VERSION(&wm_info.version);
+ if (!SDL_GetWindowWMInfo(window, &wm_info)) {
+ return NULL;
+ }
+
+ return wm_info.info.dfb.window;
+}
+
+static void
+SetBlendMode(DirectFB_RenderData * data, int blendMode,
+ DirectFB_TextureData * source)
+{
+ IDirectFBSurface *destsurf = data->target;
+
+ /* FIXME: check for format change */
+ if (1 || data->lastBlendMode != blendMode) {
+ switch (blendMode) {
+ case SDL_BLENDMODE_NONE:
+ /**< No blending */
+ data->blitFlags = DSBLIT_NOFX;
+ data->drawFlags = DSDRAW_NOFX;
+ SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ONE));
+ SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ZERO));
+ break;
+#if 0
+ case SDL_BLENDMODE_MASK:
+ data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
+ data->drawFlags = DSDRAW_BLEND;
+ SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA));
+ SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_INVSRCALPHA));
+ break;
+#endif
+ case SDL_BLENDMODE_BLEND:
+ data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
+ data->drawFlags = DSDRAW_BLEND;
+ SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA));
+ SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_INVSRCALPHA));
+ break;
+ case SDL_BLENDMODE_ADD:
+ data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
+ data->drawFlags = DSDRAW_BLEND;
+ /* FIXME: SRCALPHA kills performance on radeon ...
+ * It will be cheaper to copy the surface to a temporary surface and premultiply
+ */
+ if (source && TextureHasAlpha(source))
+ SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_SRCALPHA));
+ else
+ SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ONE));
+ SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_ONE));
+ break;
+ case SDL_BLENDMODE_MOD:
+ data->blitFlags = DSBLIT_BLEND_ALPHACHANNEL;
+ data->drawFlags = DSDRAW_BLEND;
+ SDL_DFB_CHECK(destsurf->SetSrcBlendFunction(destsurf, DSBF_ZERO));
+ SDL_DFB_CHECK(destsurf->SetDstBlendFunction(destsurf, DSBF_SRCCOLOR));
+
+ break;
+ }
+ data->lastBlendMode = blendMode;
+ }
+}
+
+static int
+DisplayPaletteChanged(void *userdata, SDL_Palette * palette)
+{
+#if USE_DISPLAY_PALETTE
+ DirectFB_RenderData *data = (DirectFB_RenderData *) userdata;
+ SDL_DFB_WINDOWSURFACE(data->window);
+ IDirectFBPalette *surfpal;
+
+ int i;
+ int ncolors;
+ DFBColor entries[256];
+
+ SDL_DFB_CHECKERR(destsurf->GetPalette(destsurf, &surfpal));
+
+ /* FIXME: number of colors */
+ ncolors = (palette->ncolors < 256 ? palette->ncolors : 256);
+
+ for (i = 0; i < ncolors; ++i) {
+ entries[i].r = palette->colors[i].r;
+ entries[i].g = palette->colors[i].g;
+ entries[i].b = palette->colors[i].b;
+ entries[i].a = palette->colors[i].a;
+ }
+ SDL_DFB_CHECKERR(surfpal->SetEntries(surfpal, entries, ncolors, 0));
+ return 0;
+ error:
+#else
+ SDL_Unsupported();
+#endif
+ return -1;
+}
+
+static void
+DirectFB_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
+{
+ SDL_DFB_RENDERERDATA(renderer);
+
+ if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
+ /* Rebind the context to the window area and update matrices */
+ /* SDL_CurrentContext = NULL; */
+ /* data->updateSize = SDL_TRUE; */
+ renddata->size_changed = SDL_TRUE;
+ }
+}
+
+static int
+DirectFB_RenderClear(SDL_Renderer * renderer)
+{
+ DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
+ IDirectFBSurface *destsurf = data->target;
+
+ DirectFB_ActivateRenderer(renderer);
+
+ PrepareDraw(renderer);
+
+ destsurf->Clear(destsurf, renderer->r, renderer->g, renderer->b, renderer->a);
+
+ return 0;
+}
+
+SDL_Renderer *
+DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags)
+{
+ IDirectFBSurface *winsurf = get_dfb_surface(window);
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ SDL_Renderer *renderer = NULL;
+ DirectFB_RenderData *data = NULL;
+ DFBSurfaceCapabilities scaps;
+
+ if (!winsurf) {
+ return NULL;
+ }
+
+ SDL_DFB_ALLOC_CLEAR(renderer, sizeof(*renderer));
+ SDL_DFB_ALLOC_CLEAR(data, sizeof(*data));
+
+ renderer->WindowEvent = DirectFB_WindowEvent;
+ renderer->CreateTexture = DirectFB_CreateTexture;
+ renderer->SetTextureAlphaMod = DirectFB_SetTextureAlphaMod;
+ renderer->SetTextureColorMod = DirectFB_SetTextureColorMod;
+ renderer->SetTextureBlendMode = DirectFB_SetTextureBlendMode;
+ renderer->UpdateTexture = DirectFB_UpdateTexture;
+ renderer->LockTexture = DirectFB_LockTexture;
+ renderer->RenderClear = DirectFB_RenderClear;
+ renderer->UnlockTexture = DirectFB_UnlockTexture;
+ renderer->RenderDrawPoints = DirectFB_RenderDrawPoints;
+ renderer->RenderDrawLines = DirectFB_RenderDrawLines;
+ /* SetDrawColor - no needed */
+ renderer->RenderFillRects = DirectFB_RenderFillRects;
+
+ renderer->RenderCopy = DirectFB_RenderCopy;
+ renderer->RenderPresent = DirectFB_RenderPresent;
+
+ /* FIXME: Yet to be tested */
+ renderer->RenderReadPixels = DirectFB_RenderReadPixels;
+ /* renderer->RenderWritePixels = DirectFB_RenderWritePixels; */
+
+ renderer->DestroyTexture = DirectFB_DestroyTexture;
+ renderer->DestroyRenderer = DirectFB_DestroyRenderer;
+ renderer->UpdateViewport = DirectFB_UpdateViewport;
+ renderer->UpdateClipRect = DirectFB_UpdateClipRect;
+ renderer->SetRenderTarget = DirectFB_SetRenderTarget;
+
+#if 0
+ renderer->QueryTexturePixels = DirectFB_QueryTexturePixels;
+ renderer->SetTexturePalette = DirectFB_SetTexturePalette;
+ renderer->GetTexturePalette = DirectFB_GetTexturePalette;
+ renderer->SetTextureScaleMode = DirectFB_SetTextureScaleMode;
+ renderer->DirtyTexture = DirectFB_DirtyTexture;
+ renderer->SetDrawBlendMode = DirectFB_SetDrawBlendMode;
+ renderer->RenderDrawRects = DirectFB_RenderDrawRects;
+#endif
+
+ renderer->info = DirectFB_RenderDriver.info;
+ renderer->window = window; /* SDL window */
+ renderer->driverdata = data;
+
+ renderer->info.flags =
+ SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
+
+ data->window = window;
+ data->target = winsurf;
+
+ data->flipflags = DSFLIP_PIPELINE | DSFLIP_BLIT;
+
+ if (flags & SDL_RENDERER_PRESENTVSYNC) {
+ data->flipflags |= DSFLIP_WAITFORSYNC | DSFLIP_ONSYNC;
+ renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
+ } else
+ data->flipflags |= DSFLIP_ONSYNC;
+
+ SDL_DFB_CHECKERR(winsurf->GetCapabilities(winsurf, &scaps));
+
+#if 0
+ if (scaps & DSCAPS_DOUBLE)
+ renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
+ else if (scaps & DSCAPS_TRIPLE)
+ renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
+ else
+ renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
+#endif
+
+ DirectFB_SetSupportedPixelFormats(&renderer->info);
+
+#if 0
+ /* Set up a palette watch on the display palette */
+ if (display-> palette) {
+ SDL_AddPaletteWatch(display->palette, DisplayPaletteChanged, data);
+ }
+#endif
+
+ return renderer;
+
+ error:
+ SDL_DFB_FREE(renderer);
+ SDL_DFB_FREE(data);
+ return NULL;
+}
+
+static void
+DirectFB_ActivateRenderer(SDL_Renderer * renderer)
+{
+ SDL_DFB_RENDERERDATA(renderer);
+ SDL_Window *window = renderer->window;
+ SDL_DFB_WINDOWDATA(window);
+
+ if (renddata->size_changed /* || windata->wm_needs_redraw */) {
+ renddata->size_changed = SDL_FALSE;
+ }
+}
+
+
+static int
+DirectFB_AcquireVidLayer(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ SDL_Window *window = renderer->window;
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ SDL_DFB_DEVICEDATA(display->device);
+ DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
+ DirectFB_TextureData *data = texture->driverdata;
+ DFBDisplayLayerConfig layconf;
+ DFBResult ret;
+
+ if (devdata->use_yuv_direct && (dispdata->vidID >= 0)
+ && (!dispdata->vidIDinuse)
+ && SDL_ISPIXELFORMAT_FOURCC(data->format)) {
+ layconf.flags =
+ DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT |
+ DLCONF_SURFACE_CAPS;
+ layconf.width = texture->w;
+ layconf.height = texture->h;
+ layconf.pixelformat = DirectFB_SDLToDFBPixelFormat(data->format);
+ layconf.surface_caps = DSCAPS_VIDEOONLY | DSCAPS_DOUBLE;
+
+ SDL_DFB_CHECKERR(devdata->dfb->GetDisplayLayer(devdata->dfb,
+ dispdata->vidID,
+ &dispdata->vidlayer));
+ SDL_DFB_CHECKERR(dispdata->
+ vidlayer->SetCooperativeLevel(dispdata->vidlayer,
+ DLSCL_EXCLUSIVE));
+
+ if (devdata->use_yuv_underlays) {
+ ret = dispdata->vidlayer->SetLevel(dispdata->vidlayer, -1);
+ if (ret != DFB_OK)
+ SDL_DFB_DEBUG("Underlay Setlevel not supported\n");
+ }
+ SDL_DFB_CHECKERR(dispdata->
+ vidlayer->SetConfiguration(dispdata->vidlayer,
+ &layconf));
+ SDL_DFB_CHECKERR(dispdata->
+ vidlayer->GetSurface(dispdata->vidlayer,
+ &data->surface));
+ dispdata->vidIDinuse = 1;
+ data->display = display;
+ return 0;
+ }
+ return 1;
+ error:
+ if (dispdata->vidlayer) {
+ SDL_DFB_RELEASE(data->surface);
+ SDL_DFB_CHECKERR(dispdata->
+ vidlayer->SetCooperativeLevel(dispdata->vidlayer,
+ DLSCL_ADMINISTRATIVE));
+ SDL_DFB_RELEASE(dispdata->vidlayer);
+ }
+ return 1;
+}
+
+static int
+DirectFB_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ SDL_Window *window = renderer->window;
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ SDL_DFB_DEVICEDATA(display->device);
+ DirectFB_TextureData *data;
+ DFBSurfaceDescription dsc;
+ DFBSurfacePixelFormat pixelformat;
+
+ DirectFB_ActivateRenderer(renderer);
+
+ SDL_DFB_ALLOC_CLEAR(data, sizeof(*data));
+ texture->driverdata = data;
+
+ /* find the right pixelformat */
+ pixelformat = DirectFB_SDLToDFBPixelFormat(texture->format);
+ if (pixelformat == DSPF_UNKNOWN) {
+ SDL_SetError("Unknown pixel format %d", data->format);
+ goto error;
+ }
+
+ data->format = texture->format;
+ data->pitch = texture->w * DFB_BYTES_PER_PIXEL(pixelformat);
+
+ if (DirectFB_AcquireVidLayer(renderer, texture) != 0) {
+ /* fill surface description */
+ dsc.flags =
+ DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
+ dsc.width = texture->w;
+ dsc.height = texture->h;
+ if(texture->format == SDL_PIXELFORMAT_YV12 ||
+ texture->format == SDL_PIXELFORMAT_IYUV) {
+ /* dfb has problems with odd sizes -make them even internally */
+ dsc.width += (dsc.width % 2);
+ dsc.height += (dsc.height % 2);
+ }
+ /* <1.2 Never use DSCAPS_VIDEOONLY here. It kills performance
+ * No DSCAPS_SYSTEMONLY either - let dfb decide
+ * 1.2: DSCAPS_SYSTEMONLY boosts performance by factor ~8
+ * Depends on other settings as well. Let dfb decide.
+ */
+ dsc.caps = DSCAPS_PREMULTIPLIED;
+#if 0
+ if (texture->access == SDL_TEXTUREACCESS_STREAMING)
+ dsc.caps |= DSCAPS_SYSTEMONLY;
+ else
+ dsc.caps |= DSCAPS_VIDEOONLY;
+#endif
+
+ dsc.pixelformat = pixelformat;
+ data->pixels = NULL;
+
+ /* Create the surface */
+ SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc,
+ &data->surface));
+ if (SDL_ISPIXELFORMAT_INDEXED(data->format)
+ && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
+#if 1
+ SDL_DFB_CHECKERR(data->surface->GetPalette(data->surface, &data->palette));
+#else
+ /* DFB has issues with blitting LUT8 surfaces.
+ * Creating a new palette does not help.
+ */
+ DFBPaletteDescription pal_desc;
+ pal_desc.flags = DPDESC_SIZE; /* | DPDESC_ENTRIES */
+ pal_desc.size = 256;
+ SDL_DFB_CHECKERR(devdata->dfb->CreatePalette(devdata->dfb, &pal_desc,&data->palette));
+ SDL_DFB_CHECKERR(data->surface->SetPalette(data->surface, data->palette));
+#endif
+ }
+
+ }
+#if (DFB_VERSION_ATLEAST(1,2,0))
+ data->render_options = DSRO_NONE;
+#endif
+ if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
+ /* 3 plane YUVs return 1 bpp, but we need more space for other planes */
+ if(texture->format == SDL_PIXELFORMAT_YV12 ||
+ texture->format == SDL_PIXELFORMAT_IYUV) {
+ SDL_DFB_ALLOC_CLEAR(data->pixels, (texture->h * data->pitch + ((texture->h + texture->h % 2) * (data->pitch + data->pitch % 2) * 2) / 4));
+ } else {
+ SDL_DFB_ALLOC_CLEAR(data->pixels, texture->h * data->pitch);
+ }
+ }
+
+ return 0;
+
+ error:
+ SDL_DFB_RELEASE(data->palette);
+ SDL_DFB_RELEASE(data->surface);
+ SDL_DFB_FREE(texture->driverdata);
+ return -1;
+}
+
+static int
+DirectFB_QueryTexturePixels(SDL_Renderer * renderer,
+ SDL_Texture * texture, void **pixels, int *pitch)
+{
+ DirectFB_TextureData *texturedata =
+ (DirectFB_TextureData *) texture->driverdata;
+
+ if (texturedata->display) {
+ return -1;
+ } else {
+ *pixels = texturedata->pixels;
+ *pitch = texturedata->pitch;
+ }
+ return 0;
+}
+
+static int
+DirectFB_SetTexturePalette(SDL_Renderer * renderer,
+ SDL_Texture * texture,
+ const SDL_Color * colors, int firstcolor,
+ int ncolors)
+{
+ DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
+ if (SDL_ISPIXELFORMAT_INDEXED(data->format)
+ && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
+ DFBColor entries[256];
+ int i;
+
+ if (ncolors > 256)
+ ncolors = 256;
+
+ for (i = 0; i < ncolors; ++i) {
+ entries[i].r = colors[i].r;
+ entries[i].g = colors[i].g;
+ entries[i].b = colors[i].b;
+ entries[i].a = 0xff;
+ }
+ SDL_DFB_CHECKERR(data->
+ palette->SetEntries(data->palette, entries, ncolors, firstcolor));
+ return 0;
+ } else {
+ return SDL_SetError("YUV textures don't have a palette");
+ }
+ error:
+ return -1;
+}
+
+static int
+DirectFB_GetTexturePalette(SDL_Renderer * renderer,
+ SDL_Texture * texture, SDL_Color * colors,
+ int firstcolor, int ncolors)
+{
+ DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
+
+ if (SDL_ISPIXELFORMAT_INDEXED(data->format)
+ && !SDL_ISPIXELFORMAT_FOURCC(data->format)) {
+ DFBColor entries[256];
+ int i;
+
+ SDL_DFB_CHECKERR(data->
+ palette->GetEntries(data->palette, entries, ncolors,
+ firstcolor));
+
+ for (i = 0; i < ncolors; ++i) {
+ colors[i].r = entries[i].r;
+ colors[i].g = entries[i].g;
+ colors[i].b = entries[i].b;
+ colors[i].a = SDL_ALPHA_OPAQUE;
+ }
+ return 0;
+ } else {
+ return SDL_SetError("YUV textures don't have a palette");
+ }
+ error:
+ return -1;
+}
+
+static int
+DirectFB_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ return 0;
+}
+
+static int
+DirectFB_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ return 0;
+}
+
+static int
+DirectFB_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ switch (texture->blendMode) {
+ case SDL_BLENDMODE_NONE:
+ /* case SDL_BLENDMODE_MASK: */
+ case SDL_BLENDMODE_BLEND:
+ case SDL_BLENDMODE_ADD:
+ case SDL_BLENDMODE_MOD:
+ return 0;
+ default:
+ texture->blendMode = SDL_BLENDMODE_NONE;
+ return SDL_Unsupported();
+ }
+}
+
+static int
+DirectFB_SetDrawBlendMode(SDL_Renderer * renderer)
+{
+ switch (renderer->blendMode) {
+ case SDL_BLENDMODE_NONE:
+ /* case SDL_BLENDMODE_MASK: */
+ case SDL_BLENDMODE_BLEND:
+ case SDL_BLENDMODE_ADD:
+ case SDL_BLENDMODE_MOD:
+ return 0;
+ default:
+ renderer->blendMode = SDL_BLENDMODE_NONE;
+ return SDL_Unsupported();
+ }
+}
+
+#if 0
+static int
+DirectFB_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+#if (DFB_VERSION_ATLEAST(1,2,0))
+
+ DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
+
+ switch (texture->scaleMode) {
+ case SDL_SCALEMODE_NONE:
+ case SDL_SCALEMODE_FAST:
+ data->render_options = DSRO_NONE;
+ break;
+ case SDL_SCALEMODE_SLOW:
+ data->render_options = DSRO_SMOOTH_UPSCALE | DSRO_SMOOTH_DOWNSCALE;
+ break;
+ case SDL_SCALEMODE_BEST:
+ data->render_options =
+ DSRO_SMOOTH_UPSCALE | DSRO_SMOOTH_DOWNSCALE | DSRO_ANTIALIAS;
+ break;
+ default:
+ data->render_options = DSRO_NONE;
+ texture->scaleMode = SDL_SCALEMODE_NONE;
+ return SDL_Unsupported();
+ }
+#endif
+ return 0;
+}
+#endif
+
+static int
+DirectFB_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, const void *pixels, int pitch)
+{
+ DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
+ Uint8 *dpixels;
+ int dpitch;
+ Uint8 *src, *dst;
+ int row;
+ size_t length;
+ int bpp = DFB_BYTES_PER_PIXEL(DirectFB_SDLToDFBPixelFormat(texture->format));
+ /* FIXME: SDL_BYTESPERPIXEL(texture->format) broken for yuv yv12 3 planes */
+
+ DirectFB_ActivateRenderer(renderer);
+
+ if ((texture->format == SDL_PIXELFORMAT_YV12) ||
+ (texture->format == SDL_PIXELFORMAT_IYUV)) {
+ bpp = 1;
+ }
+
+ SDL_DFB_CHECKERR(data->surface->Lock(data->surface,
+ DSLF_WRITE | DSLF_READ,
+ ((void **) &dpixels), &dpitch));
+ src = (Uint8 *) pixels;
+ dst = (Uint8 *) dpixels + rect->y * dpitch + rect->x * bpp;
+ length = rect->w * bpp;
+ for (row = 0; row < rect->h; ++row) {
+ SDL_memcpy(dst, src, length);
+ src += pitch;
+ dst += dpitch;
+ }
+ /* copy other planes for 3 plane formats */
+ if ((texture->format == SDL_PIXELFORMAT_YV12) ||
+ (texture->format == SDL_PIXELFORMAT_IYUV)) {
+ src = (Uint8 *) pixels + texture->h * pitch;
+ dst = (Uint8 *) dpixels + texture->h * dpitch + rect->y * dpitch / 4 + rect->x * bpp / 2;
+ for (row = 0; row < rect->h / 2 + (rect->h & 1); ++row) {
+ SDL_memcpy(dst, src, length / 2);
+ src += pitch / 2;
+ dst += dpitch / 2;
+ }
+ src = (Uint8 *) pixels + texture->h * pitch + texture->h * pitch / 4;
+ dst = (Uint8 *) dpixels + texture->h * dpitch + texture->h * dpitch / 4 + rect->y * dpitch / 4 + rect->x * bpp / 2;
+ for (row = 0; row < rect->h / 2 + (rect->h & 1); ++row) {
+ SDL_memcpy(dst, src, length / 2);
+ src += pitch / 2;
+ dst += dpitch / 2;
+ }
+ }
+ SDL_DFB_CHECKERR(data->surface->Unlock(data->surface));
+ data->isDirty = 0;
+ return 0;
+ error:
+ return 1;
+
+}
+
+static int
+DirectFB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * rect, void **pixels, int *pitch)
+{
+ DirectFB_TextureData *texturedata =
+ (DirectFB_TextureData *) texture->driverdata;
+
+ DirectFB_ActivateRenderer(renderer);
+
+#if 0
+ if (markDirty) {
+ SDL_AddDirtyRect(&texturedata->dirty, rect);
+ }
+#endif
+
+ if (texturedata->display) {
+ void *fdata;
+ int fpitch;
+
+ SDL_DFB_CHECKERR(texturedata->surface->Lock(texturedata->surface,
+ DSLF_WRITE | DSLF_READ,
+ &fdata, &fpitch));
+ *pitch = fpitch;
+ *pixels = fdata;
+ } else {
+ *pixels =
+ (void *) ((Uint8 *) texturedata->pixels +
+ rect->y * texturedata->pitch +
+ rect->x * DFB_BYTES_PER_PIXEL(DirectFB_SDLToDFBPixelFormat(texture->format)));
+ *pitch = texturedata->pitch;
+ texturedata->isDirty = 1;
+ }
+ return 0;
+
+ error:
+ return -1;
+}
+
+static void
+DirectFB_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ DirectFB_TextureData *texturedata =
+ (DirectFB_TextureData *) texture->driverdata;
+
+ DirectFB_ActivateRenderer(renderer);
+
+ if (texturedata->display) {
+ SDL_DFB_CHECK(texturedata->surface->Unlock(texturedata->surface));
+ texturedata->pixels = NULL;
+ }
+}
+
+#if 0
+static void
+DirectFB_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+ int numrects, const SDL_Rect * rects)
+{
+ DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
+ int i;
+
+ for (i = 0; i < numrects; ++i) {
+ SDL_AddDirtyRect(&data->dirty, &rects[i]);
+ }
+}
+#endif
+
+static int DirectFB_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
+ DirectFB_TextureData *tex_data = NULL;
+
+ DirectFB_ActivateRenderer(renderer);
+ if (texture) {
+ tex_data = (DirectFB_TextureData *) texture->driverdata;
+ data->target = tex_data->surface;
+ } else {
+ data->target = get_dfb_surface(data->window);
+ }
+ data->lastBlendMode = 0;
+ return 0;
+}
+
+
+static int
+PrepareDraw(SDL_Renderer * renderer)
+{
+ DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
+ IDirectFBSurface *destsurf = data->target;
+
+ Uint8 r, g, b, a;
+
+ r = renderer->r;
+ g = renderer->g;
+ b = renderer->b;
+ a = renderer->a;
+
+ SetBlendMode(data, renderer->blendMode, NULL);
+ SDL_DFB_CHECKERR(destsurf->SetDrawingFlags(destsurf, data->drawFlags));
+
+ switch (renderer->blendMode) {
+ case SDL_BLENDMODE_NONE:
+ /* case SDL_BLENDMODE_MASK: */
+ case SDL_BLENDMODE_BLEND:
+ break;
+ case SDL_BLENDMODE_ADD:
+ case SDL_BLENDMODE_MOD:
+ r = ((int) r * (int) a) / 255;
+ g = ((int) g * (int) a) / 255;
+ b = ((int) b * (int) a) / 255;
+ a = 255;
+ break;
+ }
+
+ SDL_DFB_CHECKERR(destsurf->SetColor(destsurf, r, g, b, a));
+ return 0;
+ error:
+ return -1;
+}
+
+static int DirectFB_RenderDrawPoints(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count)
+{
+ DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
+ IDirectFBSurface *destsurf = data->target;
+ DFBRegion clip_region;
+ int i;
+
+ DirectFB_ActivateRenderer(renderer);
+
+ PrepareDraw(renderer);
+ destsurf->GetClip(destsurf, &clip_region);
+ for (i=0; i < count; i++) {
+ int x = points[i].x + clip_region.x1;
+ int y = points[i].y + clip_region.y1;
+ SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, x, y, x, y));
+ }
+ return 0;
+ error:
+ return -1;
+}
+
+static int DirectFB_RenderDrawLines(SDL_Renderer * renderer,
+ const SDL_FPoint * points, int count)
+{
+ DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
+ IDirectFBSurface *destsurf = data->target;
+ DFBRegion clip_region;
+ int i;
+
+ DirectFB_ActivateRenderer(renderer);
+
+ PrepareDraw(renderer);
+ /* Use antialiasing when available */
+#if (DFB_VERSION_ATLEAST(1,2,0))
+ SDL_DFB_CHECKERR(destsurf->SetRenderOptions(destsurf, DSRO_ANTIALIAS));
+#endif
+
+ destsurf->GetClip(destsurf, &clip_region);
+ for (i=0; i < count - 1; i++) {
+ int x1 = points[i].x + clip_region.x1;
+ int y1 = points[i].y + clip_region.y1;
+ int x2 = points[i + 1].x + clip_region.x1;
+ int y2 = points[i + 1].y + clip_region.y1;
+ SDL_DFB_CHECKERR(destsurf->DrawLine(destsurf, x1, y1, x2, y2));
+ }
+
+ return 0;
+ error:
+ return -1;
+}
+
+static int
+DirectFB_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
+{
+ DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
+ IDirectFBSurface *destsurf = data->target;
+ DFBRegion clip_region;
+ int i;
+
+ DirectFB_ActivateRenderer(renderer);
+
+ PrepareDraw(renderer);
+
+ destsurf->GetClip(destsurf, &clip_region);
+ for (i=0; i<count; i++) {
+ SDL_Rect dst = {rects[i]->x, rects[i]->y, rects[i]->w, rects[i]->h};
+ dst.x += clip_region.x1;
+ dst.y += clip_region.y1;
+ SDL_DFB_CHECKERR(destsurf->DrawRectangle(destsurf, dst.x, dst.y,
+ dst.w, dst.h));
+ }
+
+ return 0;
+ error:
+ return -1;
+}
+
+static int
+DirectFB_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects, int count)
+{
+ DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
+ IDirectFBSurface *destsurf = data->target;
+ DFBRegion clip_region;
+ int i;
+
+ DirectFB_ActivateRenderer(renderer);
+
+ PrepareDraw(renderer);
+
+ destsurf->GetClip(destsurf, &clip_region);
+ for (i=0; i<count; i++) {
+ SDL_Rect dst = {rects[i].x, rects[i].y, rects[i].w, rects[i].h};
+ dst.x += clip_region.x1;
+ dst.y += clip_region.y1;
+ SDL_DFB_CHECKERR(destsurf->FillRectangle(destsurf, dst.x, dst.y,
+ dst.w, dst.h));
+ }
+
+ return 0;
+ error:
+ return -1;
+}
+
+static int
+DirectFB_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
+ const SDL_Rect * srcrect, const SDL_FRect * dstrect)
+{
+ DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
+ IDirectFBSurface *destsurf = data->target;
+ DirectFB_TextureData *texturedata =
+ (DirectFB_TextureData *) texture->driverdata;
+ Uint8 alpha, r, g, b;
+ DFBRegion clip_region;
+ DFBRectangle sr, dr;
+
+ DirectFB_ActivateRenderer(renderer);
+
+ SDLtoDFBRect(srcrect, &sr);
+ SDLtoDFBRect_Float(dstrect, &dr);
+
+ destsurf->GetClip(destsurf, &clip_region);
+ dr.x += clip_region.x1;
+ dr.y += clip_region.y1;
+
+ if (texturedata->display) {
+ int px, py;
+ SDL_Window *window = renderer->window;
+ IDirectFBWindow *dfbwin = get_dfb_window(window);
+ SDL_DFB_WINDOWDATA(window);
+ SDL_VideoDisplay *display = texturedata->display;
+ DFB_DisplayData *dispdata = (DFB_DisplayData *) display->driverdata;
+
+ SDL_DFB_CHECKERR(dispdata->
+ vidlayer->SetSourceRectangle(dispdata->vidlayer,
+ sr.x, sr.y, sr.w, sr.h));
+ dfbwin->GetPosition(dfbwin, &px, &py);
+ px += windata->client.x;
+ py += windata->client.y;
+ SDL_DFB_CHECKERR(dispdata->
+ vidlayer->SetScreenRectangle(dispdata->vidlayer,
+ px + dr.x,
+ py + dr.y,
+ dr.w,
+ dr.h));
+ } else {
+ DFBSurfaceBlittingFlags flags = 0;
+
+#if 0
+ if (texturedata->dirty.list) {
+ SDL_DirtyRect *dirty;
+ void *pixels;
+ int bpp = DFB_BYTES_PER_PIXEL(DirectFB_SDLToDFBPixelFormat(texture->format));
+ int pitch = texturedata->pitch;
+
+ for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
+ SDL_Rect *rect = &dirty->rect;
+ pixels =
+ (void *) ((Uint8 *) texturedata->pixels +
+ rect->y * pitch + rect->x * bpp);
+ DirectFB_UpdateTexture(renderer, texture, rect,
+ pixels,
+ texturedata->pitch);
+ }
+ SDL_ClearDirtyRects(&texturedata->dirty);
+ }
+#endif
+ if (texturedata->isDirty)
+ {
+ SDL_Rect rect;
+
+ rect.x = 0;
+ rect.y = 0;
+ rect.w = texture->w;
+ rect.h = texture->h;
+
+ DirectFB_UpdateTexture(renderer, texture, &rect, texturedata->pixels, texturedata->pitch);
+ }
+
+ alpha = r = g = b = 0xff;
+ if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA){
+ alpha = texture->a;
+ flags |= DSBLIT_BLEND_COLORALPHA;
+ }
+
+ if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
+ r = texture->r;
+ g = texture->g;
+ b = texture->b;
+ flags |= DSBLIT_COLORIZE;
+ }
+ SDL_DFB_CHECKERR(destsurf->
+ SetColor(destsurf, r, g, b, alpha));
+
+ /* ???? flags |= DSBLIT_SRC_PREMULTCOLOR; */
+
+ SetBlendMode(data, texture->blendMode, texturedata);
+
+ SDL_DFB_CHECKERR(destsurf->SetBlittingFlags(destsurf,
+ data->blitFlags | flags));
+
+#if (DFB_VERSION_ATLEAST(1,2,0))
+ SDL_DFB_CHECKERR(destsurf->SetRenderOptions(destsurf,
+ texturedata->
+ render_options));
+#endif
+
+ if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
+ SDL_DFB_CHECKERR(destsurf->Blit(destsurf,
+ texturedata->surface,
+ &sr, dr.x, dr.y));
+ } else {
+ SDL_DFB_CHECKERR(destsurf->StretchBlit(destsurf,
+ texturedata->surface,
+ &sr, &dr));
+ }
+ }
+ return 0;
+ error:
+ return -1;
+}
+
+static void
+DirectFB_RenderPresent(SDL_Renderer * renderer)
+{
+ DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
+ SDL_Window *window = renderer->window;
+ SDL_DFB_WINDOWDATA(window);
+ SDL_ShapeData *shape_data = (window->shaper ? window->shaper->driverdata : NULL);
+
+ DirectFB_ActivateRenderer(renderer);
+
+ if (shape_data && shape_data->surface) {
+ /* saturate the window surface alpha channel */
+ SDL_DFB_CHECK(windata->window_surface->SetSrcBlendFunction(windata->window_surface, DSBF_ONE));
+ SDL_DFB_CHECK(windata->window_surface->SetDstBlendFunction(windata->window_surface, DSBF_ONE));
+ SDL_DFB_CHECK(windata->window_surface->SetDrawingFlags(windata->window_surface, DSDRAW_BLEND));
+ SDL_DFB_CHECK(windata->window_surface->SetColor(windata->window_surface, 0, 0, 0, 0xff));
+ SDL_DFB_CHECK(windata->window_surface->FillRectangle(windata->window_surface, 0,0, windata->size.w, windata->size.h));
+
+ /* blit the mask */
+ SDL_DFB_CHECK(windata->surface->SetSrcBlendFunction(windata->surface, DSBF_DESTCOLOR));
+ SDL_DFB_CHECK(windata->surface->SetDstBlendFunction(windata->surface, DSBF_ZERO));
+ SDL_DFB_CHECK(windata->surface->SetBlittingFlags(windata->surface, DSBLIT_BLEND_ALPHACHANNEL));
+#if (DFB_VERSION_ATLEAST(1,2,0))
+ SDL_DFB_CHECK(windata->surface->SetRenderOptions(windata->surface, DSRO_NONE));
+#endif
+ SDL_DFB_CHECK(windata->surface->Blit(windata->surface, shape_data->surface, NULL, 0, 0));
+ }
+
+ /* Send the data to the display */
+ SDL_DFB_CHECK(windata->window_surface->Flip(windata->window_surface, NULL,
+ data->flipflags));
+}
+
+static void
+DirectFB_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
+{
+ DirectFB_TextureData *data = (DirectFB_TextureData *) texture->driverdata;
+
+ DirectFB_ActivateRenderer(renderer);
+
+ if (!data) {
+ return;
+ }
+ SDL_DFB_RELEASE(data->palette);
+ SDL_DFB_RELEASE(data->surface);
+ if (data->display) {
+ DFB_DisplayData *dispdata =
+ (DFB_DisplayData *) data->display->driverdata;
+ dispdata->vidIDinuse = 0;
+ /* FIXME: Shouldn't we reset the cooperative level */
+ SDL_DFB_CHECK(dispdata->vidlayer->SetCooperativeLevel(dispdata->vidlayer,
+ DLSCL_ADMINISTRATIVE));
+ SDL_DFB_RELEASE(dispdata->vidlayer);
+ }
+ SDL_DFB_FREE(data->pixels);
+ SDL_free(data);
+ texture->driverdata = NULL;
+}
+
+static void
+DirectFB_DestroyRenderer(SDL_Renderer * renderer)
+{
+ DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(data->window);
+#if 0
+ if (display->palette) {
+ SDL_DelPaletteWatch(display->palette, DisplayPaletteChanged, data);
+ }
+#endif
+
+ SDL_free(data);
+ SDL_free(renderer);
+}
+
+static int
+DirectFB_UpdateViewport(SDL_Renderer * renderer)
+{
+ DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
+ IDirectFBSurface *winsurf = data->target;
+ DFBRegion dreg;
+
+ dreg.x1 = renderer->viewport.x;
+ dreg.y1 = renderer->viewport.y;
+ dreg.x2 = dreg.x1 + renderer->viewport.w - 1;
+ dreg.y2 = dreg.y1 + renderer->viewport.h - 1;
+
+ winsurf->SetClip(winsurf, &dreg);
+ return 0;
+}
+
+static int
+DirectFB_UpdateClipRect(SDL_Renderer * renderer)
+{
+ const SDL_Rect *rect = &renderer->clip_rect;
+ DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
+ IDirectFBSurface *destsurf = get_dfb_surface(data->window);
+ DFBRegion region;
+
+ if (!SDL_RectEmpty(rect)) {
+ region.x1 = rect->x;
+ region.x2 = rect->x + rect->w;
+ region.y1 = rect->y;
+ region.y2 = rect->y + rect->h;
+ SDL_DFB_CHECKERR(destsurf->SetClip(destsurf, &region));
+ } else {
+ SDL_DFB_CHECKERR(destsurf->SetClip(destsurf, NULL));
+ }
+ return 0;
+ error:
+ return -1;
+}
+
+static int
+DirectFB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 format, void * pixels, int pitch)
+{
+ Uint32 sdl_format;
+ unsigned char* laypixels;
+ int laypitch;
+ DFBSurfacePixelFormat dfb_format;
+ DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
+ IDirectFBSurface *winsurf = data->target;
+
+ DirectFB_ActivateRenderer(renderer);
+
+ winsurf->GetPixelFormat(winsurf, &dfb_format);
+ sdl_format = DirectFB_DFBToSDLPixelFormat(dfb_format);
+ winsurf->Lock(winsurf, DSLF_READ, (void **) &laypixels, &laypitch);
+
+ laypixels += (rect->y * laypitch + rect->x * SDL_BYTESPERPIXEL(sdl_format) );
+ SDL_ConvertPixels(rect->w, rect->h,
+ sdl_format, laypixels, laypitch,
+ format, pixels, pitch);
+
+ winsurf->Unlock(winsurf);
+
+ return 0;
+}
+
+#if 0
+static int
+DirectFB_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
+ Uint32 format, const void * pixels, int pitch)
+{
+ SDL_Window *window = renderer->window;
+ SDL_DFB_WINDOWDATA(window);
+ Uint32 sdl_format;
+ unsigned char* laypixels;
+ int laypitch;
+ DFBSurfacePixelFormat dfb_format;
+
+ SDL_DFB_CHECK(windata->surface->GetPixelFormat(windata->surface, &dfb_format));
+ sdl_format = DirectFB_DFBToSDLPixelFormat(dfb_format);
+
+ SDL_DFB_CHECK(windata->surface->Lock(windata->surface, DSLF_WRITE, (void **) &laypixels, &laypitch));
+
+ laypixels += (rect->y * laypitch + rect->x * SDL_BYTESPERPIXEL(sdl_format) );
+ SDL_ConvertPixels(rect->w, rect->h,
+ format, pixels, pitch,
+ sdl_format, laypixels, laypitch);
+
+ SDL_DFB_CHECK(windata->surface->Unlock(windata->surface));
+
+ return 0;
+}
+#endif
+
+#endif /* SDL_VIDEO_DRIVER_DIRECTFB */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_render.h b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_render.h
new file mode 100644
index 0000000..bc3c075
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_render.h
@@ -0,0 +1,25 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+
+/* SDL surface based renderer implementation */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_shape.c b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_shape.c
new file mode 100644
index 0000000..3655931
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_shape.c
@@ -0,0 +1,131 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_DIRECTFB
+
+#include "SDL_assert.h"
+#include "SDL_DirectFB_video.h"
+#include "SDL_DirectFB_shape.h"
+#include "SDL_DirectFB_window.h"
+
+#include "../SDL_shape_internals.h"
+
+SDL_WindowShaper*
+DirectFB_CreateShaper(SDL_Window* window) {
+ SDL_WindowShaper* result = NULL;
+ SDL_ShapeData* data;
+ int resized_properly;
+
+ result = malloc(sizeof(SDL_WindowShaper));
+ result->window = window;
+ result->mode.mode = ShapeModeDefault;
+ result->mode.parameters.binarizationCutoff = 1;
+ result->userx = result->usery = 0;
+ data = SDL_malloc(sizeof(SDL_ShapeData));
+ result->driverdata = data;
+ data->surface = NULL;
+ window->shaper = result;
+ resized_properly = DirectFB_ResizeWindowShape(window);
+ SDL_assert(resized_properly == 0);
+
+ return result;
+}
+
+int
+DirectFB_ResizeWindowShape(SDL_Window* window) {
+ SDL_ShapeData* data = window->shaper->driverdata;
+ SDL_assert(data != NULL);
+
+ if (window->x != -1000)
+ {
+ window->shaper->userx = window->x;
+ window->shaper->usery = window->y;
+ }
+ SDL_SetWindowPosition(window,-1000,-1000);
+
+ return 0;
+}
+
+int
+DirectFB_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
+
+ if(shaper == NULL || shape == NULL || shaper->driverdata == NULL)
+ return -1;
+ if(shape->format->Amask == 0 && SDL_SHAPEMODEALPHA(shape_mode->mode))
+ return -2;
+ if(shape->w != shaper->window->w || shape->h != shaper->window->h)
+ return -3;
+
+ {
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(shaper->window);
+ SDL_DFB_DEVICEDATA(display->device);
+ Uint32 *pixels;
+ Sint32 pitch;
+ Uint32 h,w;
+ Uint8 *src, *bitmap;
+ DFBSurfaceDescription dsc;
+
+ SDL_ShapeData *data = shaper->driverdata;
+
+ SDL_DFB_RELEASE(data->surface);
+
+ dsc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
+ dsc.width = shape->w;
+ dsc.height = shape->h;
+ dsc.caps = DSCAPS_PREMULTIPLIED;
+ dsc.pixelformat = DSPF_ARGB;
+
+ SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc, &data->surface));
+
+ /* Assume that shaper->alphacutoff already has a value, because SDL_SetWindowShape() should have given it one. */
+ SDL_DFB_ALLOC_CLEAR(bitmap, shape->w * shape->h);
+ SDL_CalculateShapeBitmap(shaper->mode,shape,bitmap,1);
+
+ src = bitmap;
+
+ SDL_DFB_CHECK(data->surface->Lock(data->surface, DSLF_WRITE | DSLF_READ, (void **) &pixels, &pitch));
+
+ h = shaper->window->h;
+ while (h--) {
+ for (w = 0; w < shaper->window->w; w++) {
+ if (*src)
+ pixels[w] = 0xFFFFFFFF;
+ else
+ pixels[w] = 0;
+ src++;
+
+ }
+ pixels += (pitch >> 2);
+ }
+ SDL_DFB_CHECK(data->surface->Unlock(data->surface));
+ SDL_DFB_FREE(bitmap);
+
+ /* FIXME: Need to call this here - Big ?? */
+ DirectFB_WM_RedrawLayout(SDL_GetDisplayForWindow(shaper->window)->device, shaper->window);
+ }
+
+ return 0;
+error:
+ return -1;
+}
+
+#endif /* SDL_VIDEO_DRIVER_DIRECTFB */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_shape.h b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_shape.h
new file mode 100644
index 0000000..f0a418d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_shape.h
@@ -0,0 +1,38 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_DirectFB_shape_h_
+#define SDL_DirectFB_shape_h_
+
+#include <directfb.h>
+
+#include "../SDL_sysvideo.h"
+#include "SDL_shape.h"
+
+typedef struct {
+ IDirectFBSurface *surface;
+} SDL_ShapeData;
+
+extern SDL_WindowShaper* DirectFB_CreateShaper(SDL_Window* window);
+extern int DirectFB_ResizeWindowShape(SDL_Window* window);
+extern int DirectFB_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode);
+
+#endif /* SDL_DirectFB_shape_h_ */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_video.c b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_video.c
new file mode 100644
index 0000000..45fa81d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_video.c
@@ -0,0 +1,418 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_DIRECTFB
+
+/*
+ * #include "SDL_DirectFB_keyboard.h"
+ */
+#include "SDL_DirectFB_modes.h"
+#include "SDL_DirectFB_opengl.h"
+#include "SDL_DirectFB_window.h"
+#include "SDL_DirectFB_WM.h"
+
+
+/* DirectFB video driver implementation.
+*/
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+#include <directfb.h>
+#include <directfb_version.h>
+#include <directfb_strings.h>
+
+#include "SDL_video.h"
+#include "SDL_mouse.h"
+#include "../SDL_sysvideo.h"
+#include "../SDL_pixels_c.h"
+#include "../../events/SDL_events_c.h"
+#include "SDL_DirectFB_video.h"
+#include "SDL_DirectFB_events.h"
+#include "SDL_DirectFB_render.h"
+#include "SDL_DirectFB_mouse.h"
+#include "SDL_DirectFB_shape.h"
+
+
+#include "SDL_DirectFB_dyn.h"
+
+/* Initialization/Query functions */
+static int DirectFB_VideoInit(_THIS);
+static void DirectFB_VideoQuit(_THIS);
+
+static int DirectFB_Available(void);
+static SDL_VideoDevice *DirectFB_CreateDevice(int devindex);
+
+VideoBootStrap DirectFB_bootstrap = {
+ "directfb", "DirectFB",
+ DirectFB_Available, DirectFB_CreateDevice
+};
+
+static const DirectFBSurfaceDrawingFlagsNames(drawing_flags);
+static const DirectFBSurfaceBlittingFlagsNames(blitting_flags);
+static const DirectFBAccelerationMaskNames(acceleration_mask);
+
+/* DirectFB driver bootstrap functions */
+
+static int
+DirectFB_Available(void)
+{
+ if (!SDL_DirectFB_LoadLibrary())
+ return 0;
+ SDL_DirectFB_UnLoadLibrary();
+ return 1;
+}
+
+static void
+DirectFB_DeleteDevice(SDL_VideoDevice * device)
+{
+ SDL_DirectFB_UnLoadLibrary();
+ SDL_DFB_FREE(device->driverdata);
+ SDL_DFB_FREE(device);
+}
+
+static SDL_VideoDevice *
+DirectFB_CreateDevice(int devindex)
+{
+ SDL_VideoDevice *device;
+
+ if (!SDL_DirectFB_LoadLibrary()) {
+ return NULL;
+ }
+
+ /* Initialize all variables that we clean on shutdown */
+ SDL_DFB_ALLOC_CLEAR(device, sizeof(SDL_VideoDevice));
+
+ /* Set the function pointers */
+ device->VideoInit = DirectFB_VideoInit;
+ device->VideoQuit = DirectFB_VideoQuit;
+ device->GetDisplayModes = DirectFB_GetDisplayModes;
+ device->SetDisplayMode = DirectFB_SetDisplayMode;
+ device->PumpEvents = DirectFB_PumpEventsWindow;
+ device->CreateSDLWindow = DirectFB_CreateWindow;
+ device->CreateSDLWindowFrom = DirectFB_CreateWindowFrom;
+ device->SetWindowTitle = DirectFB_SetWindowTitle;
+ device->SetWindowIcon = DirectFB_SetWindowIcon;
+ device->SetWindowPosition = DirectFB_SetWindowPosition;
+ device->SetWindowSize = DirectFB_SetWindowSize;
+ device->SetWindowOpacity = DirectFB_SetWindowOpacity;
+ device->ShowWindow = DirectFB_ShowWindow;
+ device->HideWindow = DirectFB_HideWindow;
+ device->RaiseWindow = DirectFB_RaiseWindow;
+ device->MaximizeWindow = DirectFB_MaximizeWindow;
+ device->MinimizeWindow = DirectFB_MinimizeWindow;
+ device->RestoreWindow = DirectFB_RestoreWindow;
+ device->SetWindowGrab = DirectFB_SetWindowGrab;
+ device->DestroyWindow = DirectFB_DestroyWindow;
+ device->GetWindowWMInfo = DirectFB_GetWindowWMInfo;
+
+ /* !!! FIXME: implement SetWindowBordered */
+
+#if SDL_DIRECTFB_OPENGL
+ device->GL_LoadLibrary = DirectFB_GL_LoadLibrary;
+ device->GL_GetProcAddress = DirectFB_GL_GetProcAddress;
+ device->GL_MakeCurrent = DirectFB_GL_MakeCurrent;
+
+ device->GL_CreateContext = DirectFB_GL_CreateContext;
+ device->GL_SetSwapInterval = DirectFB_GL_SetSwapInterval;
+ device->GL_GetSwapInterval = DirectFB_GL_GetSwapInterval;
+ device->GL_SwapWindow = DirectFB_GL_SwapWindow;
+ device->GL_DeleteContext = DirectFB_GL_DeleteContext;
+
+#endif
+
+ /* Shaped window support */
+ device->shape_driver.CreateShaper = DirectFB_CreateShaper;
+ device->shape_driver.SetWindowShape = DirectFB_SetWindowShape;
+ device->shape_driver.ResizeWindowShape = DirectFB_ResizeWindowShape;
+
+ device->free = DirectFB_DeleteDevice;
+
+ return device;
+ error:
+ if (device)
+ SDL_free(device);
+ return (0);
+}
+
+static void
+DirectFB_DeviceInformation(IDirectFB * dfb)
+{
+ DFBGraphicsDeviceDescription desc;
+ int n;
+
+ dfb->GetDeviceDescription(dfb, &desc);
+
+ SDL_DFB_LOG( "DirectFB Device Information");
+ SDL_DFB_LOG( "===========================");
+ SDL_DFB_LOG( "Name: %s", desc.name);
+ SDL_DFB_LOG( "Vendor: %s", desc.vendor);
+ SDL_DFB_LOG( "Driver Name: %s", desc.driver.name);
+ SDL_DFB_LOG( "Driver Vendor: %s", desc.driver.vendor);
+ SDL_DFB_LOG( "Driver Version: %d.%d", desc.driver.major,
+ desc.driver.minor);
+
+ SDL_DFB_LOG( "Video memory: %d", desc.video_memory);
+
+ SDL_DFB_LOG( "Blitting flags:");
+ for (n = 0; blitting_flags[n].flag; n++) {
+ if (desc.blitting_flags & blitting_flags[n].flag)
+ SDL_DFB_LOG( " %s", blitting_flags[n].name);
+ }
+
+ SDL_DFB_LOG( "Drawing flags:");
+ for (n = 0; drawing_flags[n].flag; n++) {
+ if (desc.drawing_flags & drawing_flags[n].flag)
+ SDL_DFB_LOG( " %s", drawing_flags[n].name);
+ }
+
+
+ SDL_DFB_LOG( "Acceleration flags:");
+ for (n = 0; acceleration_mask[n].mask; n++) {
+ if (desc.acceleration_mask & acceleration_mask[n].mask)
+ SDL_DFB_LOG( " %s", acceleration_mask[n].name);
+ }
+
+
+}
+
+static int readBoolEnv(const char *env_name, int def_val)
+{
+ char *stemp;
+
+ stemp = SDL_getenv(env_name);
+ if (stemp)
+ return atoi(stemp);
+ else
+ return def_val;
+}
+
+static int
+DirectFB_VideoInit(_THIS)
+{
+ IDirectFB *dfb = NULL;
+ DFB_DeviceData *devdata = NULL;
+ DFBResult ret;
+
+ SDL_DFB_ALLOC_CLEAR(devdata, sizeof(*devdata));
+
+ SDL_DFB_CHECKERR(DirectFBInit(NULL, NULL));
+
+ /* avoid switching to the framebuffer when we
+ * are running X11 */
+ ret = readBoolEnv(DFBENV_USE_X11_CHECK , 1);
+ if (ret) {
+ if (SDL_getenv("DISPLAY"))
+ DirectFBSetOption("system", "x11");
+ else
+ DirectFBSetOption("disable-module", "x11input");
+ }
+
+ devdata->use_linux_input = readBoolEnv(DFBENV_USE_LINUX_INPUT, 1); /* default: on */
+
+ if (!devdata->use_linux_input)
+ {
+ SDL_DFB_LOG("Disabling linux input\n");
+ DirectFBSetOption("disable-module", "linux_input");
+ }
+
+ SDL_DFB_CHECKERR(DirectFBCreate(&dfb));
+
+ DirectFB_DeviceInformation(dfb);
+
+ devdata->use_yuv_underlays = readBoolEnv(DFBENV_USE_YUV_UNDERLAY, 0); /* default: off */
+ devdata->use_yuv_direct = readBoolEnv(DFBENV_USE_YUV_DIRECT, 0); /* default is off! */
+
+ /* Create global Eventbuffer for axis events */
+ if (devdata->use_linux_input) {
+ SDL_DFB_CHECKERR(dfb->CreateInputEventBuffer(dfb, DICAPS_ALL,
+ DFB_TRUE,
+ &devdata->events));
+ } else {
+ SDL_DFB_CHECKERR(dfb->CreateInputEventBuffer(dfb, DICAPS_AXES
+ /* DICAPS_ALL */ ,
+ DFB_TRUE,
+ &devdata->events));
+ }
+
+ /* simple window manager support */
+ devdata->has_own_wm = readBoolEnv(DFBENV_USE_WM, 0);
+
+ devdata->initialized = 1;
+
+ devdata->dfb = dfb;
+ devdata->firstwin = NULL;
+ devdata->grabbed_window = NULL;
+
+ _this->driverdata = devdata;
+
+ DirectFB_InitModes(_this);
+
+#if SDL_DIRECTFB_OPENGL
+ DirectFB_GL_Initialize(_this);
+#endif
+
+ DirectFB_InitMouse(_this);
+ DirectFB_InitKeyboard(_this);
+
+ return 0;
+
+
+ error:
+ SDL_DFB_FREE(devdata);
+ SDL_DFB_RELEASE(dfb);
+ return -1;
+}
+
+static void
+DirectFB_VideoQuit(_THIS)
+{
+ DFB_DeviceData *devdata = (DFB_DeviceData *) _this->driverdata;
+
+ DirectFB_QuitModes(_this);
+ DirectFB_QuitKeyboard(_this);
+ DirectFB_QuitMouse(_this);
+
+ devdata->events->Reset(devdata->events);
+ SDL_DFB_RELEASE(devdata->events);
+ SDL_DFB_RELEASE(devdata->dfb);
+
+#if SDL_DIRECTFB_OPENGL
+ DirectFB_GL_Shutdown(_this);
+#endif
+
+ devdata->initialized = 0;
+}
+
+/* DirectFB driver general support functions */
+
+static const struct {
+ DFBSurfacePixelFormat dfb;
+ Uint32 sdl;
+} pixelformat_tab[] =
+{
+ { DSPF_RGB32, SDL_PIXELFORMAT_RGB888 }, /* 24 bit RGB (4 byte, nothing@24, red 8@16, green 8@8, blue 8@0) */
+ { DSPF_ARGB, SDL_PIXELFORMAT_ARGB8888 }, /* 32 bit ARGB (4 byte, alpha 8@24, red 8@16, green 8@8, blue 8@0) */
+ { DSPF_RGB16, SDL_PIXELFORMAT_RGB565 }, /* 16 bit RGB (2 byte, red 5@11, green 6@5, blue 5@0) */
+ { DSPF_RGB332, SDL_PIXELFORMAT_RGB332 }, /* 8 bit RGB (1 byte, red 3@5, green 3@2, blue 2@0) */
+ { DSPF_ARGB4444, SDL_PIXELFORMAT_ARGB4444 }, /* 16 bit ARGB (2 byte, alpha 4@12, red 4@8, green 4@4, blue 4@0) */
+ { DSPF_ARGB1555, SDL_PIXELFORMAT_ARGB1555 }, /* 16 bit ARGB (2 byte, alpha 1@15, red 5@10, green 5@5, blue 5@0) */
+ { DSPF_RGB24, SDL_PIXELFORMAT_RGB24 }, /* 24 bit RGB (3 byte, red 8@16, green 8@8, blue 8@0) */
+ { DSPF_RGB444, SDL_PIXELFORMAT_RGB444 }, /* 16 bit RGB (2 byte, nothing @12, red 4@8, green 4@4, blue 4@0) */
+ { DSPF_YV12, SDL_PIXELFORMAT_YV12 }, /* 12 bit YUV (8 bit Y plane followed by 8 bit quarter size V/U planes) */
+ { DSPF_I420,SDL_PIXELFORMAT_IYUV }, /* 12 bit YUV (8 bit Y plane followed by 8 bit quarter size U/V planes) */
+ { DSPF_YUY2, SDL_PIXELFORMAT_YUY2 }, /* 16 bit YUV (4 byte/ 2 pixel, macropixel contains CbYCrY [31:0]) */
+ { DSPF_UYVY, SDL_PIXELFORMAT_UYVY }, /* 16 bit YUV (4 byte/ 2 pixel, macropixel contains YCbYCr [31:0]) */
+ { DSPF_RGB555, SDL_PIXELFORMAT_RGB555 }, /* 16 bit RGB (2 byte, nothing @15, red 5@10, green 5@5, blue 5@0) */
+#if (ENABLE_LUT8)
+ { DSPF_LUT8, SDL_PIXELFORMAT_INDEX8 }, /* 8 bit LUT (8 bit color and alpha lookup from palette) */
+#endif
+
+#if (DFB_VERSION_ATLEAST(1,2,0))
+ { DSPF_BGR555, SDL_PIXELFORMAT_BGR555 }, /* 16 bit BGR (2 byte, nothing @15, blue 5@10, green 5@5, red 5@0) */
+#else
+ { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR555 },
+#endif
+
+ /* Pfff ... nonmatching formats follow */
+
+ { DSPF_ALUT44, SDL_PIXELFORMAT_UNKNOWN }, /* 8 bit ALUT (1 byte, alpha 4@4, color lookup 4@0) */
+ { DSPF_A8, SDL_PIXELFORMAT_UNKNOWN }, /* 8 bit alpha (1 byte, alpha 8@0), e.g. anti-aliased glyphs */
+ { DSPF_AiRGB, SDL_PIXELFORMAT_UNKNOWN }, /* 32 bit ARGB (4 byte, inv. alpha 8@24, red 8@16, green 8@8, blue 8@0) */
+ { DSPF_A1, SDL_PIXELFORMAT_UNKNOWN }, /* 1 bit alpha (1 byte/ 8 pixel, most significant bit used first) */
+ { DSPF_NV12, SDL_PIXELFORMAT_UNKNOWN }, /* 12 bit YUV (8 bit Y plane followed by one 16 bit quarter size CbCr [15:0] plane) */
+ { DSPF_NV16, SDL_PIXELFORMAT_UNKNOWN }, /* 16 bit YUV (8 bit Y plane followed by one 16 bit half width CbCr [15:0] plane) */
+ { DSPF_ARGB2554, SDL_PIXELFORMAT_UNKNOWN }, /* 16 bit ARGB (2 byte, alpha 2@14, red 5@9, green 5@4, blue 4@0) */
+ { DSPF_NV21, SDL_PIXELFORMAT_UNKNOWN }, /* 12 bit YUV (8 bit Y plane followed by one 16 bit quarter size CrCb [15:0] plane) */
+ { DSPF_AYUV, SDL_PIXELFORMAT_UNKNOWN }, /* 32 bit AYUV (4 byte, alpha 8@24, Y 8@16, Cb 8@8, Cr 8@0) */
+ { DSPF_A4, SDL_PIXELFORMAT_UNKNOWN }, /* 4 bit alpha (1 byte/ 2 pixel, more significant nibble used first) */
+ { DSPF_ARGB1666, SDL_PIXELFORMAT_UNKNOWN }, /* 1 bit alpha (3 byte/ alpha 1@18, red 6@16, green 6@6, blue 6@0) */
+ { DSPF_ARGB6666, SDL_PIXELFORMAT_UNKNOWN }, /* 6 bit alpha (3 byte/ alpha 6@18, red 6@16, green 6@6, blue 6@0) */
+ { DSPF_RGB18, SDL_PIXELFORMAT_UNKNOWN }, /* 6 bit RGB (3 byte/ red 6@16, green 6@6, blue 6@0) */
+ { DSPF_LUT2, SDL_PIXELFORMAT_UNKNOWN }, /* 2 bit LUT (1 byte/ 4 pixel, 2 bit color and alpha lookup from palette) */
+
+#if (DFB_VERSION_ATLEAST(1,3,0))
+ { DSPF_RGBA4444, SDL_PIXELFORMAT_UNKNOWN }, /* 16 bit RGBA (2 byte, red 4@12, green 4@8, blue 4@4, alpha 4@0) */
+#endif
+
+#if (DFB_VERSION_ATLEAST(1,4,3))
+ { DSPF_RGBA5551, SDL_PIXELFORMAT_UNKNOWN }, /* 16 bit RGBA (2 byte, red 5@11, green 5@6, blue 5@1, alpha 1@0) */
+ { DSPF_YUV444P, SDL_PIXELFORMAT_UNKNOWN }, /* 24 bit full YUV planar (8 bit Y plane followed by an 8 bit Cb and an 8 bit Cr plane) */
+ { DSPF_ARGB8565, SDL_PIXELFORMAT_UNKNOWN }, /* 24 bit ARGB (3 byte, alpha 8@16, red 5@11, green 6@5, blue 5@0) */
+ { DSPF_AVYU, SDL_PIXELFORMAT_UNKNOWN }, /* 32 bit AVYU 4:4:4 (4 byte, alpha 8@24, Cr 8@16, Y 8@8, Cb 8@0) */
+ { DSPF_VYU, SDL_PIXELFORMAT_UNKNOWN }, /* 24 bit VYU 4:4:4 (3 byte, Cr 8@16, Y 8@8, Cb 8@0) */
+#endif
+
+ { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX1LSB },
+ { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX1MSB },
+ { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX4LSB },
+ { DSPF_UNKNOWN, SDL_PIXELFORMAT_INDEX4MSB },
+ { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR24 },
+ { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR888 },
+ { DSPF_UNKNOWN, SDL_PIXELFORMAT_RGBA8888 },
+ { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR8888 },
+ { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGRA8888 },
+ { DSPF_UNKNOWN, SDL_PIXELFORMAT_ARGB2101010 },
+ { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR4444 },
+ { DSPF_UNKNOWN, SDL_PIXELFORMAT_ABGR1555 },
+ { DSPF_UNKNOWN, SDL_PIXELFORMAT_BGR565 },
+ { DSPF_UNKNOWN, SDL_PIXELFORMAT_YVYU }, /**< Packed mode: Y0+V0+Y1+U0 (1 pla */
+};
+
+Uint32
+DirectFB_DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat)
+{
+ int i;
+
+ for (i=0; pixelformat_tab[i].dfb != DSPF_UNKNOWN; i++)
+ if (pixelformat_tab[i].dfb == pixelformat)
+ {
+ return pixelformat_tab[i].sdl;
+ }
+ return SDL_PIXELFORMAT_UNKNOWN;
+}
+
+DFBSurfacePixelFormat
+DirectFB_SDLToDFBPixelFormat(Uint32 format)
+{
+ int i;
+
+ for (i=0; pixelformat_tab[i].dfb != DSPF_UNKNOWN; i++)
+ if (pixelformat_tab[i].sdl == format)
+ {
+ return pixelformat_tab[i].dfb;
+ }
+ return DSPF_UNKNOWN;
+}
+
+void DirectFB_SetSupportedPixelFormats(SDL_RendererInfo* ri)
+{
+ int i, j;
+
+ for (i=0, j=0; pixelformat_tab[i].dfb != DSPF_UNKNOWN; i++)
+ if (pixelformat_tab[i].sdl != SDL_PIXELFORMAT_UNKNOWN)
+ ri->texture_formats[j++] = pixelformat_tab[i].sdl;
+ ri->num_texture_formats = j;
+}
+
+#endif /* SDL_VIDEO_DRIVER_DIRECTFB */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_video.h b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_video.h
new file mode 100644
index 0000000..f019031
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_video.h
@@ -0,0 +1,170 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_DirectFB_video_h_
+#define SDL_DirectFB_video_h_
+
+#include <directfb.h>
+#include <directfb_version.h>
+
+#include "../SDL_sysvideo.h"
+#include "SDL_scancode.h"
+#include "SDL_render.h"
+
+#include "SDL_log.h"
+
+#define DFB_VERSIONNUM(X, Y, Z) \
+ ((X)*1000 + (Y)*100 + (Z))
+
+#define DFB_COMPILEDVERSION \
+ DFB_VERSIONNUM(DIRECTFB_MAJOR_VERSION, DIRECTFB_MINOR_VERSION, DIRECTFB_MICRO_VERSION)
+
+#define DFB_VERSION_ATLEAST(X, Y, Z) \
+ (DFB_COMPILEDVERSION >= DFB_VERSIONNUM(X, Y, Z))
+
+#if (DFB_VERSION_ATLEAST(1,0,0))
+#ifdef SDL_VIDEO_OPENGL
+#define SDL_DIRECTFB_OPENGL 1
+#endif
+#else
+#error "SDL_DIRECTFB: Please compile against libdirectfb version >= 1.0.0"
+#endif
+
+/* Set below to 1 to compile with (old) multi mice/keyboard api. Code left in
+ * in case we see this again ...
+ */
+
+#define USE_MULTI_API (0)
+
+/* Support for LUT8/INDEX8 pixel format.
+ * This is broken in DirectFB 1.4.3. It works in 1.4.0 and 1.4.5
+ * occurred.
+ */
+
+#if (DFB_COMPILEDVERSION == DFB_VERSIONNUM(1, 4, 3))
+#define ENABLE_LUT8 (0)
+#else
+#define ENABLE_LUT8 (1)
+#endif
+
+#define DIRECTFB_DEBUG 1
+
+#define DFBENV_USE_YUV_UNDERLAY "SDL_DIRECTFB_YUV_UNDERLAY" /* Default: off */
+#define DFBENV_USE_YUV_DIRECT "SDL_DIRECTFB_YUV_DIRECT" /* Default: off */
+#define DFBENV_USE_X11_CHECK "SDL_DIRECTFB_X11_CHECK" /* Default: on */
+#define DFBENV_USE_LINUX_INPUT "SDL_DIRECTFB_LINUX_INPUT" /* Default: on */
+#define DFBENV_USE_WM "SDL_DIRECTFB_WM" /* Default: off */
+
+#define SDL_DFB_RELEASE(x) do { if ( (x) != NULL ) { SDL_DFB_CHECK(x->Release(x)); x = NULL; } } while (0)
+#define SDL_DFB_FREE(x) do { SDL_free((x)); (x) = NULL; } while (0)
+#define SDL_DFB_UNLOCK(x) do { if ( (x) != NULL ) { x->Unlock(x); } } while (0)
+
+#define SDL_DFB_CONTEXT "SDL_DirectFB"
+
+#define SDL_DFB_ERR(x...) SDL_LogError(SDL_LOG_CATEGORY_ERROR, x)
+
+#if (DIRECTFB_DEBUG)
+#define SDL_DFB_LOG(x...) SDL_LogInfo(SDL_LOG_CATEGORY_VIDEO, x)
+
+#define SDL_DFB_DEBUG(x...) SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, x)
+
+static SDL_INLINE DFBResult sdl_dfb_check(DFBResult ret, const char *src_file, int src_line) {
+ if (ret != DFB_OK) {
+ SDL_DFB_LOG("%s (%d):%s", src_file, src_line, DirectFBErrorString (ret) );
+ SDL_SetError("%s:%s", SDL_DFB_CONTEXT, DirectFBErrorString (ret) );
+ }
+ return ret;
+}
+
+#define SDL_DFB_CHECK(x...) do { sdl_dfb_check( x, __FILE__, __LINE__); } while (0)
+#define SDL_DFB_CHECKERR(x...) do { if ( sdl_dfb_check( x, __FILE__, __LINE__) != DFB_OK ) goto error; } while (0)
+
+#else
+
+#define SDL_DFB_CHECK(x...) x
+#define SDL_DFB_CHECKERR(x...) do { if (x != DFB_OK ) goto error; } while (0)
+#define SDL_DFB_LOG(x...) do {} while (0)
+#define SDL_DFB_DEBUG(x...) do {} while (0)
+
+#endif
+
+
+#define SDL_DFB_CALLOC(r, n, s) \
+ do { \
+ r = SDL_calloc (n, s); \
+ if (!(r)) { \
+ SDL_DFB_ERR("Out of memory"); \
+ SDL_OutOfMemory(); \
+ goto error; \
+ } \
+ } while (0)
+
+#define SDL_DFB_ALLOC_CLEAR(r, s) SDL_DFB_CALLOC(r, 1, s)
+
+/* Private display data */
+
+#define SDL_DFB_DEVICEDATA(dev) DFB_DeviceData *devdata = (dev ? (DFB_DeviceData *) ((dev)->driverdata) : NULL)
+
+#define DFB_MAX_SCREENS 10
+
+typedef struct _DFB_KeyboardData DFB_KeyboardData;
+struct _DFB_KeyboardData
+{
+ const SDL_Scancode *map; /* keyboard scancode map */
+ int map_size; /* size of map */
+ int map_adjust; /* index adjust */
+ int is_generic; /* generic keyboard */
+ int id;
+};
+
+typedef struct _DFB_DeviceData DFB_DeviceData;
+struct _DFB_DeviceData
+{
+ int initialized;
+
+ IDirectFB *dfb;
+ int num_mice;
+ int mouse_id[0x100];
+ int num_keyboard;
+ DFB_KeyboardData keyboard[10];
+ SDL_Window *firstwin;
+
+ int use_yuv_underlays;
+ int use_yuv_direct;
+ int use_linux_input;
+ int has_own_wm;
+
+
+ /* window grab */
+ SDL_Window *grabbed_window;
+
+ /* global events */
+ IDirectFBEventBuffer *events;
+};
+
+Uint32 DirectFB_DFBToSDLPixelFormat(DFBSurfacePixelFormat pixelformat);
+DFBSurfacePixelFormat DirectFB_SDLToDFBPixelFormat(Uint32 format);
+void DirectFB_SetSupportedPixelFormats(SDL_RendererInfo *ri);
+
+
+#endif /* SDL_DirectFB_video_h_ */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_window.c b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_window.c
new file mode 100644
index 0000000..55171ed
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_window.c
@@ -0,0 +1,565 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_DIRECTFB
+
+#include "SDL_DirectFB_video.h"
+#include "SDL_DirectFB_modes.h"
+#include "SDL_DirectFB_window.h"
+#include "SDL_DirectFB_shape.h"
+
+#if SDL_DIRECTFB_OPENGL
+#include "SDL_DirectFB_opengl.h"
+#endif
+
+#include "SDL_syswm.h"
+
+#include "../SDL_pixels_c.h"
+
+int
+DirectFB_CreateWindow(_THIS, SDL_Window * window)
+{
+ SDL_DFB_DEVICEDATA(_this);
+ SDL_DFB_DISPLAYDATA(window);
+ DFB_WindowData *windata = NULL;
+ DFBWindowOptions wopts;
+ DFBWindowDescription desc;
+ int x, y;
+ int bshaped = 0;
+
+ SDL_DFB_ALLOC_CLEAR(window->driverdata, sizeof(DFB_WindowData));
+ SDL_memset(&desc, 0, sizeof(DFBWindowDescription));
+ windata = (DFB_WindowData *) window->driverdata;
+
+ windata->is_managed = devdata->has_own_wm;
+#if 1
+ SDL_DFB_CHECKERR(devdata->dfb->SetCooperativeLevel(devdata->dfb,
+ DFSCL_NORMAL));
+ SDL_DFB_CHECKERR(dispdata->layer->SetCooperativeLevel(dispdata->layer,
+ DLSCL_ADMINISTRATIVE));
+#endif
+ /* FIXME ... ughh, ugly */
+ if (window->x == -1000 && window->y == -1000)
+ bshaped = 1;
+
+ /* Fill the window description. */
+ x = window->x;
+ y = window->y;
+
+ DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
+
+ /* Create Window */
+ desc.caps = 0;
+ desc.flags =
+ DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_POSX | DWDESC_POSY | DWDESC_SURFACE_CAPS;
+
+ if (bshaped) {
+ desc.flags |= DWDESC_CAPS;
+ desc.caps |= DWCAPS_ALPHACHANNEL;
+ }
+ else
+ {
+ desc.flags |= DWDESC_PIXELFORMAT;
+ }
+
+ if (!(window->flags & SDL_WINDOW_BORDERLESS))
+ desc.caps |= DWCAPS_NODECORATION;
+
+ desc.posx = x;
+ desc.posy = y;
+ desc.width = windata->size.w;
+ desc.height = windata->size.h;
+ desc.pixelformat = dispdata->pixelformat;
+ desc.surface_caps = DSCAPS_PREMULTIPLIED;
+#if DIRECTFB_MAJOR_VERSION == 1 && DIRECTFB_MINOR_VERSION >= 6
+ if (window->flags & SDL_WINDOW_OPENGL) {
+ desc.surface_caps |= DSCAPS_GL;
+ }
+#endif
+
+ /* Create the window. */
+ SDL_DFB_CHECKERR(dispdata->layer->CreateWindow(dispdata->layer, &desc,
+ &windata->dfbwin));
+
+ /* Set Options */
+ SDL_DFB_CHECK(windata->dfbwin->GetOptions(windata->dfbwin, &wopts));
+
+ /* explicit rescaling of surface */
+ wopts |= DWOP_SCALE;
+ if (window->flags & SDL_WINDOW_RESIZABLE) {
+ wopts &= ~DWOP_KEEP_SIZE;
+ }
+ else {
+ wopts |= DWOP_KEEP_SIZE;
+ }
+
+ if (window->flags & SDL_WINDOW_FULLSCREEN) {
+ wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_STACKING | DWOP_KEEP_SIZE;
+ SDL_DFB_CHECK(windata->dfbwin->SetStackingClass(windata->dfbwin, DWSC_UPPER));
+ }
+
+ if (bshaped) {
+ wopts |= DWOP_SHAPED | DWOP_ALPHACHANNEL;
+ wopts &= ~DWOP_OPAQUE_REGION;
+ }
+
+ SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
+
+ /* See what we got */
+ SDL_DFB_CHECK(DirectFB_WM_GetClientSize
+ (_this, window, &window->w, &window->h));
+
+ /* Get the window's surface. */
+ SDL_DFB_CHECKERR(windata->dfbwin->GetSurface(windata->dfbwin,
+ &windata->window_surface));
+
+ /* And get a subsurface for rendering */
+ SDL_DFB_CHECKERR(windata->window_surface->
+ GetSubSurface(windata->window_surface, &windata->client,
+ &windata->surface));
+
+ SDL_DFB_CHECK(windata->dfbwin->SetOpacity(windata->dfbwin, 0xFF));
+
+ /* Create Eventbuffer */
+
+ SDL_DFB_CHECKERR(windata->dfbwin->CreateEventBuffer(windata->dfbwin,
+ &windata->
+ eventbuffer));
+ SDL_DFB_CHECKERR(windata->dfbwin->
+ EnableEvents(windata->dfbwin, DWET_ALL));
+
+ /* Create a font */
+ /* FIXME: once during Video_Init */
+ windata->font = NULL;
+
+ /* Make it the top most window. */
+ SDL_DFB_CHECK(windata->dfbwin->RaiseToTop(windata->dfbwin));
+
+ /* remember parent */
+ /* windata->sdlwin = window; */
+
+ /* Add to list ... */
+
+ windata->next = devdata->firstwin;
+ windata->opacity = 0xFF;
+ devdata->firstwin = window;
+
+ /* Draw Frame */
+ DirectFB_WM_RedrawLayout(_this, window);
+
+ return 0;
+ error:
+ SDL_DFB_RELEASE(windata->surface);
+ SDL_DFB_RELEASE(windata->dfbwin);
+ return -1;
+}
+
+int
+DirectFB_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
+{
+ return SDL_Unsupported();
+}
+
+void
+DirectFB_SetWindowTitle(_THIS, SDL_Window * window)
+{
+ SDL_DFB_WINDOWDATA(window);
+
+ if (windata->is_managed) {
+ windata->wm_needs_redraw = 1;
+ DirectFB_WM_RedrawLayout(_this, window);
+ } else {
+ SDL_Unsupported();
+ }
+}
+
+void
+DirectFB_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
+{
+ SDL_DFB_DEVICEDATA(_this);
+ SDL_DFB_WINDOWDATA(window);
+ SDL_Surface *surface = NULL;
+
+ if (icon) {
+ SDL_PixelFormat format;
+ DFBSurfaceDescription dsc;
+ Uint32 *dest;
+ Uint32 *p;
+ int pitch, i;
+
+ /* Convert the icon to ARGB for modern window managers */
+ SDL_InitFormat(&format, SDL_PIXELFORMAT_ARGB8888);
+ surface = SDL_ConvertSurface(icon, &format, 0);
+ if (!surface) {
+ return;
+ }
+ dsc.flags =
+ DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_CAPS;
+ dsc.caps = DSCAPS_VIDEOONLY;
+ dsc.width = surface->w;
+ dsc.height = surface->h;
+ dsc.pixelformat = DSPF_ARGB;
+
+ SDL_DFB_CHECKERR(devdata->dfb->CreateSurface(devdata->dfb, &dsc,
+ &windata->icon));
+
+ SDL_DFB_CHECKERR(windata->icon->Lock(windata->icon, DSLF_WRITE,
+ (void *) &dest, &pitch));
+
+ p = surface->pixels;
+ for (i = 0; i < surface->h; i++)
+ memcpy((char *) dest + i * pitch,
+ (char *) p + i * surface->pitch, 4 * surface->w);
+
+ SDL_DFB_CHECK(windata->icon->Unlock(windata->icon));
+ SDL_FreeSurface(surface);
+ } else {
+ SDL_DFB_RELEASE(windata->icon);
+ }
+ return;
+ error:
+ SDL_FreeSurface(surface);
+ SDL_DFB_RELEASE(windata->icon);
+ return;
+}
+
+void
+DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
+{
+ SDL_DFB_WINDOWDATA(window);
+ int x, y;
+
+ x = window->x;
+ y = window->y;
+
+ DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
+ SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, x, y));
+}
+
+void
+DirectFB_SetWindowSize(_THIS, SDL_Window * window)
+{
+ SDL_DFB_WINDOWDATA(window);
+
+ if(SDL_IsShapedWindow(window))
+ DirectFB_ResizeWindowShape(window);
+
+ if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+ int cw;
+ int ch;
+
+ /* Make sure all events are disabled for this operation ! */
+ SDL_DFB_CHECKERR(windata->dfbwin->DisableEvents(windata->dfbwin,
+ DWET_ALL));
+ SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize(_this, window, &cw, &ch));
+
+ if (cw != window->w || ch != window->h) {
+
+ DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
+ SDL_DFB_CHECKERR(windata->dfbwin->Resize(windata->dfbwin,
+ windata->size.w,
+ windata->size.h));
+ }
+
+ SDL_DFB_CHECKERR(DirectFB_WM_GetClientSize
+ (_this, window, &window->w, &window->h));
+ DirectFB_AdjustWindowSurface(window);
+
+ SDL_DFB_CHECKERR(windata->dfbwin->EnableEvents(windata->dfbwin,
+ DWET_ALL));
+
+ }
+ return;
+ error:
+ SDL_DFB_CHECK(windata->dfbwin->EnableEvents(windata->dfbwin, DWET_ALL));
+ return;
+}
+
+void
+DirectFB_ShowWindow(_THIS, SDL_Window * window)
+{
+ SDL_DFB_WINDOWDATA(window);
+
+ SDL_DFB_CHECK(windata->dfbwin->SetOpacity(windata->dfbwin, windata->opacity));
+
+}
+
+void
+DirectFB_HideWindow(_THIS, SDL_Window * window)
+{
+ SDL_DFB_WINDOWDATA(window);
+
+ SDL_DFB_CHECK(windata->dfbwin->GetOpacity(windata->dfbwin, &windata->opacity));
+ SDL_DFB_CHECK(windata->dfbwin->SetOpacity(windata->dfbwin, 0));
+}
+
+void
+DirectFB_RaiseWindow(_THIS, SDL_Window * window)
+{
+ SDL_DFB_WINDOWDATA(window);
+
+ SDL_DFB_CHECK(windata->dfbwin->RaiseToTop(windata->dfbwin));
+ SDL_DFB_CHECK(windata->dfbwin->RequestFocus(windata->dfbwin));
+}
+
+void
+DirectFB_MaximizeWindow(_THIS, SDL_Window * window)
+{
+ SDL_DFB_WINDOWDATA(window);
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ DFBWindowOptions wopts;
+
+ SDL_DFB_CHECK(windata->dfbwin->GetPosition(windata->dfbwin,
+ &windata->restore.x, &windata->restore.y));
+ SDL_DFB_CHECK(windata->dfbwin->GetSize(windata->dfbwin, &windata->restore.w,
+ &windata->restore.h));
+
+ DirectFB_WM_AdjustWindowLayout(window, window->flags | SDL_WINDOW_MAXIMIZED, display->current_mode.w, display->current_mode.h) ;
+
+ SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, 0, 0));
+ SDL_DFB_CHECK(windata->dfbwin->Resize(windata->dfbwin,
+ display->current_mode.w, display->current_mode.h));
+
+ /* Set Options */
+ SDL_DFB_CHECK(windata->dfbwin->GetOptions(windata->dfbwin, &wopts));
+ wopts |= DWOP_KEEP_SIZE | DWOP_KEEP_POSITION;
+ SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
+}
+
+void
+DirectFB_MinimizeWindow(_THIS, SDL_Window * window)
+{
+ /* FIXME: Size to 32x32 ? */
+
+ SDL_Unsupported();
+}
+
+void
+DirectFB_RestoreWindow(_THIS, SDL_Window * window)
+{
+ SDL_DFB_WINDOWDATA(window);
+ DFBWindowOptions wopts;
+
+ /* Set Options */
+ SDL_DFB_CHECK(windata->dfbwin->GetOptions(windata->dfbwin, &wopts));
+ wopts &= ~(DWOP_KEEP_SIZE | DWOP_KEEP_POSITION);
+ SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
+
+ /* Window layout */
+ DirectFB_WM_AdjustWindowLayout(window, window->flags & ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED),
+ windata->restore.w, windata->restore.h);
+ SDL_DFB_CHECK(windata->dfbwin->Resize(windata->dfbwin, windata->restore.w,
+ windata->restore.h));
+ SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, windata->restore.x,
+ windata->restore.y));
+
+ if (!(window->flags & SDL_WINDOW_RESIZABLE))
+ wopts |= DWOP_KEEP_SIZE;
+
+ if (window->flags & SDL_WINDOW_FULLSCREEN)
+ wopts |= DWOP_KEEP_POSITION | DWOP_KEEP_SIZE;
+ SDL_DFB_CHECK(windata->dfbwin->SetOptions(windata->dfbwin, wopts));
+
+
+}
+
+void
+DirectFB_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
+{
+ SDL_DFB_DEVICEDATA(_this);
+ SDL_DFB_WINDOWDATA(window);
+ DFB_WindowData *gwindata = ((devdata->grabbed_window) ? (DFB_WindowData *) ((devdata->grabbed_window)->driverdata) : NULL);
+
+ if ((window->flags & SDL_WINDOW_INPUT_GRABBED)) {
+ if (gwindata != NULL)
+ {
+ SDL_DFB_CHECK(gwindata->dfbwin->UngrabPointer(gwindata->dfbwin));
+ SDL_DFB_CHECK(gwindata->dfbwin->UngrabKeyboard(gwindata->dfbwin));
+ }
+ SDL_DFB_CHECK(windata->dfbwin->GrabPointer(windata->dfbwin));
+ SDL_DFB_CHECK(windata->dfbwin->GrabKeyboard(windata->dfbwin));
+ devdata->grabbed_window = window;
+ } else {
+ SDL_DFB_CHECK(windata->dfbwin->UngrabPointer(windata->dfbwin));
+ SDL_DFB_CHECK(windata->dfbwin->UngrabKeyboard(windata->dfbwin));
+ devdata->grabbed_window = NULL;
+ }
+}
+
+void
+DirectFB_DestroyWindow(_THIS, SDL_Window * window)
+{
+ SDL_DFB_DEVICEDATA(_this);
+ SDL_DFB_WINDOWDATA(window);
+ DFB_WindowData *p;
+
+ /* Some cleanups */
+ SDL_DFB_CHECK(windata->dfbwin->UngrabPointer(windata->dfbwin));
+ SDL_DFB_CHECK(windata->dfbwin->UngrabKeyboard(windata->dfbwin));
+
+#if SDL_DIRECTFB_OPENGL
+ DirectFB_GL_DestroyWindowContexts(_this, window);
+#endif
+
+ if (window->shaper)
+ {
+ SDL_ShapeData *data = window->shaper->driverdata;
+ SDL_DFB_CHECK(data->surface->ReleaseSource(data->surface));
+ SDL_DFB_RELEASE(data->surface);
+ SDL_DFB_FREE(data);
+ SDL_DFB_FREE(window->shaper);
+ }
+
+ SDL_DFB_CHECK(windata->window_surface->SetFont(windata->window_surface, NULL));
+ SDL_DFB_CHECK(windata->surface->ReleaseSource(windata->surface));
+ SDL_DFB_CHECK(windata->window_surface->ReleaseSource(windata->window_surface));
+ SDL_DFB_RELEASE(windata->icon);
+ SDL_DFB_RELEASE(windata->font);
+ SDL_DFB_RELEASE(windata->eventbuffer);
+ SDL_DFB_RELEASE(windata->surface);
+ SDL_DFB_RELEASE(windata->window_surface);
+
+ SDL_DFB_RELEASE(windata->dfbwin);
+
+ /* Remove from list ... */
+
+ p = devdata->firstwin->driverdata;
+
+ while (p && p->next != window)
+ p = (p->next ? p->next->driverdata : NULL);
+ if (p)
+ p->next = windata->next;
+ else
+ devdata->firstwin = windata->next;
+ SDL_free(windata);
+ return;
+}
+
+SDL_bool
+DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
+ struct SDL_SysWMinfo * info)
+{
+ const Uint32 version = ((((Uint32) info->version.major) * 1000000) +
+ (((Uint32) info->version.minor) * 10000) +
+ (((Uint32) info->version.patch)));
+
+ SDL_DFB_DEVICEDATA(_this);
+ SDL_DFB_WINDOWDATA(window);
+
+ /* Before 2.0.6, it was possible to build an SDL with DirectFB support
+ (SDL_SysWMinfo will be large enough to hold DirectFB info), but build
+ your app against SDL headers that didn't have DirectFB support
+ (SDL_SysWMinfo could be smaller than DirectFB needs. This would lead
+ to an app properly using SDL_GetWindowWMInfo() but we'd accidentally
+ overflow memory on the stack or heap. To protect against this, we've
+ padded out the struct unconditionally in the headers and DirectFB will
+ just return an error for older apps using this function. Those apps
+ will need to be recompiled against newer headers or not use DirectFB,
+ maybe by forcing SDL_VIDEODRIVER=x11. */
+ if (version < 2000006) {
+ info->subsystem = SDL_SYSWM_UNKNOWN;
+ SDL_SetError("Version must be 2.0.6 or newer");
+ return SDL_FALSE;
+ }
+
+ if (info->version.major == SDL_MAJOR_VERSION &&
+ info->version.minor == SDL_MINOR_VERSION) {
+ info->subsystem = SDL_SYSWM_DIRECTFB;
+ info->info.dfb.dfb = devdata->dfb;
+ info->info.dfb.window = windata->dfbwin;
+ info->info.dfb.surface = windata->surface;
+ return SDL_TRUE;
+ } else {
+ SDL_SetError("Application not compiled with SDL %d.%d",
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+ return SDL_FALSE;
+ }
+}
+
+void
+DirectFB_AdjustWindowSurface(SDL_Window * window)
+{
+ SDL_DFB_WINDOWDATA(window);
+ int adjust = windata->wm_needs_redraw;
+ int cw, ch;
+
+ DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
+
+ SDL_DFB_CHECKERR(windata->
+ window_surface->GetSize(windata->window_surface, &cw,
+ &ch));
+ if (cw != windata->size.w || ch != windata->size.h) {
+ adjust = 1;
+ }
+
+ if (adjust) {
+#if SDL_DIRECTFB_OPENGL
+ DirectFB_GL_FreeWindowContexts(SDL_GetVideoDevice(), window);
+#endif
+
+#if (DFB_VERSION_ATLEAST(1,2,1))
+ SDL_DFB_CHECKERR(windata->dfbwin->ResizeSurface(windata->dfbwin,
+ windata->size.w,
+ windata->size.h));
+ SDL_DFB_CHECKERR(windata->surface->MakeSubSurface(windata->surface,
+ windata->
+ window_surface,
+ &windata->client));
+#else
+ DFBWindowOptions opts;
+
+ SDL_DFB_CHECKERR(windata->dfbwin->GetOptions(windata->dfbwin, &opts));
+ /* recreate subsurface */
+ SDL_DFB_RELEASE(windata->surface);
+
+ if (opts & DWOP_SCALE)
+ SDL_DFB_CHECKERR(windata->dfbwin->ResizeSurface(windata->dfbwin,
+ windata->size.w,
+ windata->size.h));
+ SDL_DFB_CHECKERR(windata->window_surface->
+ GetSubSurface(windata->window_surface,
+ &windata->client, &windata->surface));
+#endif
+ DirectFB_WM_RedrawLayout(SDL_GetVideoDevice(), window);
+
+#if SDL_DIRECTFB_OPENGL
+ DirectFB_GL_ReAllocWindowContexts(SDL_GetVideoDevice(), window);
+#endif
+ }
+ error:
+ return;
+}
+
+int
+DirectFB_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
+{
+ const Uint8 alpha = (Uint8) ((unsigned int) (opacity * 255.0f));
+ SDL_DFB_WINDOWDATA(window);
+ SDL_DFB_CHECKERR(windata->dfbwin->SetOpacity(windata->dfbwin, alpha));
+ windata->opacity = alpha;
+ return 0;
+
+error:
+ return -1;
+}
+
+#endif /* SDL_VIDEO_DRIVER_DIRECTFB */
diff --git a/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_window.h b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_window.h
new file mode 100644
index 0000000..f03aab2
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/directfb/SDL_DirectFB_window.h
@@ -0,0 +1,82 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_directfb_window_h_
+#define SDL_directfb_window_h_
+
+#include "SDL_DirectFB_video.h"
+#include "SDL_DirectFB_WM.h"
+
+#define SDL_DFB_WINDOWDATA(win) DFB_WindowData *windata = ((win) ? (DFB_WindowData *) ((win)->driverdata) : NULL)
+
+typedef struct _DFB_WindowData DFB_WindowData;
+struct _DFB_WindowData
+{
+ IDirectFBSurface *window_surface; /* window surface */
+ IDirectFBSurface *surface; /* client drawing surface */
+ IDirectFBWindow *dfbwin;
+ IDirectFBEventBuffer *eventbuffer;
+ /* SDL_Window *sdlwin; */
+ SDL_Window *next;
+ Uint8 opacity;
+ DFBRectangle client;
+ DFBDimension size;
+ DFBRectangle restore;
+
+ /* WM extras */
+ int is_managed;
+ int wm_needs_redraw;
+ IDirectFBSurface *icon;
+ IDirectFBFont *font;
+ DFB_Theme theme;
+
+ /* WM moving and sizing */
+ int wm_grab;
+ int wm_lastx;
+ int wm_lasty;
+};
+
+extern int DirectFB_CreateWindow(_THIS, SDL_Window * window);
+extern int DirectFB_CreateWindowFrom(_THIS, SDL_Window * window,
+ const void *data);
+extern void DirectFB_SetWindowTitle(_THIS, SDL_Window * window);
+extern void DirectFB_SetWindowIcon(_THIS, SDL_Window * window,
+ SDL_Surface * icon);
+
+extern void DirectFB_SetWindowPosition(_THIS, SDL_Window * window);
+extern void DirectFB_SetWindowSize(_THIS, SDL_Window * window);
+extern void DirectFB_ShowWindow(_THIS, SDL_Window * window);
+extern void DirectFB_HideWindow(_THIS, SDL_Window * window);
+extern void DirectFB_RaiseWindow(_THIS, SDL_Window * window);
+extern void DirectFB_MaximizeWindow(_THIS, SDL_Window * window);
+extern void DirectFB_MinimizeWindow(_THIS, SDL_Window * window);
+extern void DirectFB_RestoreWindow(_THIS, SDL_Window * window);
+extern void DirectFB_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
+extern void DirectFB_DestroyWindow(_THIS, SDL_Window * window);
+extern SDL_bool DirectFB_GetWindowWMInfo(_THIS, SDL_Window * window,
+ struct SDL_SysWMinfo *info);
+
+extern void DirectFB_AdjustWindowSurface(SDL_Window * window);
+extern int DirectFB_SetWindowOpacity(_THIS, SDL_Window * window, float opacity);
+
+#endif /* SDL_directfb_window_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/dummy/SDL_nullevents.c b/src/3rdparty/SDL2/src/video/dummy/SDL_nullevents.c
new file mode 100644
index 0000000..e9918bd
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/dummy/SDL_nullevents.c
@@ -0,0 +1,41 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_DUMMY
+
+/* Being a null driver, there's no event stream. We just define stubs for
+ most of the API. */
+
+#include "../../events/SDL_events_c.h"
+
+#include "SDL_nullvideo.h"
+#include "SDL_nullevents_c.h"
+
+void
+DUMMY_PumpEvents(_THIS)
+{
+ /* do nothing. */
+}
+
+#endif /* SDL_VIDEO_DRIVER_DUMMY */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/dummy/SDL_nullevents_c.h b/src/3rdparty/SDL2/src/video/dummy/SDL_nullevents_c.h
new file mode 100644
index 0000000..a5636be
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/dummy/SDL_nullevents_c.h
@@ -0,0 +1,27 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#include "SDL_nullvideo.h"
+
+extern void DUMMY_PumpEvents(_THIS);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/dummy/SDL_nullframebuffer.c b/src/3rdparty/SDL2/src/video/dummy/SDL_nullframebuffer.c
new file mode 100644
index 0000000..64c7781
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/dummy/SDL_nullframebuffer.c
@@ -0,0 +1,89 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_DUMMY
+
+#include "../SDL_sysvideo.h"
+#include "SDL_nullframebuffer_c.h"
+
+
+#define DUMMY_SURFACE "_SDL_DummySurface"
+
+int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
+{
+ SDL_Surface *surface;
+ const Uint32 surface_format = SDL_PIXELFORMAT_RGB888;
+ int w, h;
+ int bpp;
+ Uint32 Rmask, Gmask, Bmask, Amask;
+
+ /* Free the old framebuffer surface */
+ surface = (SDL_Surface *) SDL_GetWindowData(window, DUMMY_SURFACE);
+ SDL_FreeSurface(surface);
+
+ /* Create a new one */
+ SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
+ SDL_GetWindowSize(window, &w, &h);
+ surface = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
+ if (!surface) {
+ return -1;
+ }
+
+ /* Save the info and return! */
+ SDL_SetWindowData(window, DUMMY_SURFACE, surface);
+ *format = surface_format;
+ *pixels = surface->pixels;
+ *pitch = surface->pitch;
+ return 0;
+}
+
+int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects)
+{
+ static int frame_number;
+ SDL_Surface *surface;
+
+ surface = (SDL_Surface *) SDL_GetWindowData(window, DUMMY_SURFACE);
+ if (!surface) {
+ return SDL_SetError("Couldn't find dummy surface for window");
+ }
+
+ /* Send the data to the display */
+ if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
+ char file[128];
+ SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp",
+ SDL_GetWindowID(window), ++frame_number);
+ SDL_SaveBMP(surface, file);
+ }
+ return 0;
+}
+
+void SDL_DUMMY_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
+{
+ SDL_Surface *surface;
+
+ surface = (SDL_Surface *) SDL_SetWindowData(window, DUMMY_SURFACE, NULL);
+ SDL_FreeSurface(surface);
+}
+
+#endif /* SDL_VIDEO_DRIVER_DUMMY */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/dummy/SDL_nullframebuffer_c.h b/src/3rdparty/SDL2/src/video/dummy/SDL_nullframebuffer_c.h
new file mode 100644
index 0000000..5d6b7ae
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/dummy/SDL_nullframebuffer_c.h
@@ -0,0 +1,27 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+extern int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
+extern int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects);
+extern void SDL_DUMMY_DestroyWindowFramebuffer(_THIS, SDL_Window * window);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/dummy/SDL_nullvideo.c b/src/3rdparty/SDL2/src/video/dummy/SDL_nullvideo.c
new file mode 100644
index 0000000..317faf4
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/dummy/SDL_nullvideo.c
@@ -0,0 +1,144 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_DUMMY
+
+/* Dummy SDL video driver implementation; this is just enough to make an
+ * SDL-based application THINK it's got a working video driver, for
+ * applications that call SDL_Init(SDL_INIT_VIDEO) when they don't need it,
+ * and also for use as a collection of stubs when porting SDL to a new
+ * platform for which you haven't yet written a valid video driver.
+ *
+ * This is also a great way to determine bottlenecks: if you think that SDL
+ * is a performance problem for a given platform, enable this driver, and
+ * then see if your application runs faster without video overhead.
+ *
+ * Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion
+ * of this was cut-and-pasted from Stephane Peter's work in the AAlib
+ * SDL video driver. Renamed to "DUMMY" by Sam Lantinga.
+ */
+
+#include "SDL_video.h"
+#include "SDL_mouse.h"
+#include "../SDL_sysvideo.h"
+#include "../SDL_pixels_c.h"
+#include "../../events/SDL_events_c.h"
+
+#include "SDL_nullvideo.h"
+#include "SDL_nullevents_c.h"
+#include "SDL_nullframebuffer_c.h"
+
+#define DUMMYVID_DRIVER_NAME "dummy"
+
+/* Initialization/Query functions */
+static int DUMMY_VideoInit(_THIS);
+static int DUMMY_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
+static void DUMMY_VideoQuit(_THIS);
+
+/* DUMMY driver bootstrap functions */
+
+static int
+DUMMY_Available(void)
+{
+ const char *envr = SDL_getenv("SDL_VIDEODRIVER");
+ if ((envr) && (SDL_strcmp(envr, DUMMYVID_DRIVER_NAME) == 0)) {
+ return (1);
+ }
+
+ return (0);
+}
+
+static void
+DUMMY_DeleteDevice(SDL_VideoDevice * device)
+{
+ SDL_free(device);
+}
+
+static SDL_VideoDevice *
+DUMMY_CreateDevice(int devindex)
+{
+ SDL_VideoDevice *device;
+
+ /* Initialize all variables that we clean on shutdown */
+ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (!device) {
+ SDL_OutOfMemory();
+ return (0);
+ }
+ device->is_dummy = SDL_TRUE;
+
+ /* Set the function pointers */
+ device->VideoInit = DUMMY_VideoInit;
+ device->VideoQuit = DUMMY_VideoQuit;
+ device->SetDisplayMode = DUMMY_SetDisplayMode;
+ device->PumpEvents = DUMMY_PumpEvents;
+ device->CreateWindowFramebuffer = SDL_DUMMY_CreateWindowFramebuffer;
+ device->UpdateWindowFramebuffer = SDL_DUMMY_UpdateWindowFramebuffer;
+ device->DestroyWindowFramebuffer = SDL_DUMMY_DestroyWindowFramebuffer;
+
+ device->free = DUMMY_DeleteDevice;
+
+ return device;
+}
+
+VideoBootStrap DUMMY_bootstrap = {
+ DUMMYVID_DRIVER_NAME, "SDL dummy video driver",
+ DUMMY_Available, DUMMY_CreateDevice
+};
+
+
+int
+DUMMY_VideoInit(_THIS)
+{
+ SDL_DisplayMode mode;
+
+ /* Use a fake 32-bpp desktop mode */
+ mode.format = SDL_PIXELFORMAT_RGB888;
+ mode.w = 1024;
+ mode.h = 768;
+ mode.refresh_rate = 0;
+ mode.driverdata = NULL;
+ if (SDL_AddBasicVideoDisplay(&mode) < 0) {
+ return -1;
+ }
+
+ SDL_zero(mode);
+ SDL_AddDisplayMode(&_this->displays[0], &mode);
+
+ /* We're done! */
+ return 0;
+}
+
+static int
+DUMMY_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
+{
+ return 0;
+}
+
+void
+DUMMY_VideoQuit(_THIS)
+{
+}
+
+#endif /* SDL_VIDEO_DRIVER_DUMMY */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/dummy/SDL_nullvideo.h b/src/3rdparty/SDL2/src/video/dummy/SDL_nullvideo.h
new file mode 100644
index 0000000..c770349
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/dummy/SDL_nullvideo.h
@@ -0,0 +1,30 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_nullvideo_h_
+#define SDL_nullvideo_h_
+
+#include "../SDL_sysvideo.h"
+
+#endif /* SDL_nullvideo_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenevents.c b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenevents.c
new file mode 100644
index 0000000..14bc240
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenevents.c
@@ -0,0 +1,716 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_EMSCRIPTEN
+
+#include <emscripten/html5.h>
+
+#include "../../events/SDL_events_c.h"
+#include "../../events/SDL_keyboard_c.h"
+#include "../../events/SDL_touch_c.h"
+
+#include "SDL_emscriptenevents.h"
+#include "SDL_emscriptenvideo.h"
+
+#include "SDL_hints.h"
+
+#define FULLSCREEN_MASK ( SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN )
+
+/*
+.keyCode to scancode
+https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent
+https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
+*/
+static const SDL_Scancode emscripten_scancode_table[] = {
+ /* 0 */ SDL_SCANCODE_UNKNOWN,
+ /* 1 */ SDL_SCANCODE_UNKNOWN,
+ /* 2 */ SDL_SCANCODE_UNKNOWN,
+ /* 3 */ SDL_SCANCODE_CANCEL,
+ /* 4 */ SDL_SCANCODE_UNKNOWN,
+ /* 5 */ SDL_SCANCODE_UNKNOWN,
+ /* 6 */ SDL_SCANCODE_HELP,
+ /* 7 */ SDL_SCANCODE_UNKNOWN,
+ /* 8 */ SDL_SCANCODE_BACKSPACE,
+ /* 9 */ SDL_SCANCODE_TAB,
+ /* 10 */ SDL_SCANCODE_UNKNOWN,
+ /* 11 */ SDL_SCANCODE_UNKNOWN,
+ /* 12 */ SDL_SCANCODE_UNKNOWN,
+ /* 13 */ SDL_SCANCODE_RETURN,
+ /* 14 */ SDL_SCANCODE_UNKNOWN,
+ /* 15 */ SDL_SCANCODE_UNKNOWN,
+ /* 16 */ SDL_SCANCODE_LSHIFT,
+ /* 17 */ SDL_SCANCODE_LCTRL,
+ /* 18 */ SDL_SCANCODE_LALT,
+ /* 19 */ SDL_SCANCODE_PAUSE,
+ /* 20 */ SDL_SCANCODE_CAPSLOCK,
+ /* 21 */ SDL_SCANCODE_UNKNOWN,
+ /* 22 */ SDL_SCANCODE_UNKNOWN,
+ /* 23 */ SDL_SCANCODE_UNKNOWN,
+ /* 24 */ SDL_SCANCODE_UNKNOWN,
+ /* 25 */ SDL_SCANCODE_UNKNOWN,
+ /* 26 */ SDL_SCANCODE_UNKNOWN,
+ /* 27 */ SDL_SCANCODE_ESCAPE,
+ /* 28 */ SDL_SCANCODE_UNKNOWN,
+ /* 29 */ SDL_SCANCODE_UNKNOWN,
+ /* 30 */ SDL_SCANCODE_UNKNOWN,
+ /* 31 */ SDL_SCANCODE_UNKNOWN,
+ /* 32 */ SDL_SCANCODE_SPACE,
+ /* 33 */ SDL_SCANCODE_PAGEUP,
+ /* 34 */ SDL_SCANCODE_PAGEDOWN,
+ /* 35 */ SDL_SCANCODE_END,
+ /* 36 */ SDL_SCANCODE_HOME,
+ /* 37 */ SDL_SCANCODE_LEFT,
+ /* 38 */ SDL_SCANCODE_UP,
+ /* 39 */ SDL_SCANCODE_RIGHT,
+ /* 40 */ SDL_SCANCODE_DOWN,
+ /* 41 */ SDL_SCANCODE_UNKNOWN,
+ /* 42 */ SDL_SCANCODE_UNKNOWN,
+ /* 43 */ SDL_SCANCODE_UNKNOWN,
+ /* 44 */ SDL_SCANCODE_UNKNOWN,
+ /* 45 */ SDL_SCANCODE_INSERT,
+ /* 46 */ SDL_SCANCODE_DELETE,
+ /* 47 */ SDL_SCANCODE_UNKNOWN,
+ /* 48 */ SDL_SCANCODE_0,
+ /* 49 */ SDL_SCANCODE_1,
+ /* 50 */ SDL_SCANCODE_2,
+ /* 51 */ SDL_SCANCODE_3,
+ /* 52 */ SDL_SCANCODE_4,
+ /* 53 */ SDL_SCANCODE_5,
+ /* 54 */ SDL_SCANCODE_6,
+ /* 55 */ SDL_SCANCODE_7,
+ /* 56 */ SDL_SCANCODE_8,
+ /* 57 */ SDL_SCANCODE_9,
+ /* 58 */ SDL_SCANCODE_UNKNOWN,
+ /* 59 */ SDL_SCANCODE_SEMICOLON,
+ /* 60 */ SDL_SCANCODE_UNKNOWN,
+ /* 61 */ SDL_SCANCODE_EQUALS,
+ /* 62 */ SDL_SCANCODE_UNKNOWN,
+ /* 63 */ SDL_SCANCODE_UNKNOWN,
+ /* 64 */ SDL_SCANCODE_UNKNOWN,
+ /* 65 */ SDL_SCANCODE_A,
+ /* 66 */ SDL_SCANCODE_B,
+ /* 67 */ SDL_SCANCODE_C,
+ /* 68 */ SDL_SCANCODE_D,
+ /* 69 */ SDL_SCANCODE_E,
+ /* 70 */ SDL_SCANCODE_F,
+ /* 71 */ SDL_SCANCODE_G,
+ /* 72 */ SDL_SCANCODE_H,
+ /* 73 */ SDL_SCANCODE_I,
+ /* 74 */ SDL_SCANCODE_J,
+ /* 75 */ SDL_SCANCODE_K,
+ /* 76 */ SDL_SCANCODE_L,
+ /* 77 */ SDL_SCANCODE_M,
+ /* 78 */ SDL_SCANCODE_N,
+ /* 79 */ SDL_SCANCODE_O,
+ /* 80 */ SDL_SCANCODE_P,
+ /* 81 */ SDL_SCANCODE_Q,
+ /* 82 */ SDL_SCANCODE_R,
+ /* 83 */ SDL_SCANCODE_S,
+ /* 84 */ SDL_SCANCODE_T,
+ /* 85 */ SDL_SCANCODE_U,
+ /* 86 */ SDL_SCANCODE_V,
+ /* 87 */ SDL_SCANCODE_W,
+ /* 88 */ SDL_SCANCODE_X,
+ /* 89 */ SDL_SCANCODE_Y,
+ /* 90 */ SDL_SCANCODE_Z,
+ /* 91 */ SDL_SCANCODE_LGUI,
+ /* 92 */ SDL_SCANCODE_UNKNOWN,
+ /* 93 */ SDL_SCANCODE_APPLICATION,
+ /* 94 */ SDL_SCANCODE_UNKNOWN,
+ /* 95 */ SDL_SCANCODE_UNKNOWN,
+ /* 96 */ SDL_SCANCODE_KP_0,
+ /* 97 */ SDL_SCANCODE_KP_1,
+ /* 98 */ SDL_SCANCODE_KP_2,
+ /* 99 */ SDL_SCANCODE_KP_3,
+ /* 100 */ SDL_SCANCODE_KP_4,
+ /* 101 */ SDL_SCANCODE_KP_5,
+ /* 102 */ SDL_SCANCODE_KP_6,
+ /* 103 */ SDL_SCANCODE_KP_7,
+ /* 104 */ SDL_SCANCODE_KP_8,
+ /* 105 */ SDL_SCANCODE_KP_9,
+ /* 106 */ SDL_SCANCODE_KP_MULTIPLY,
+ /* 107 */ SDL_SCANCODE_KP_PLUS,
+ /* 108 */ SDL_SCANCODE_UNKNOWN,
+ /* 109 */ SDL_SCANCODE_KP_MINUS,
+ /* 110 */ SDL_SCANCODE_KP_PERIOD,
+ /* 111 */ SDL_SCANCODE_KP_DIVIDE,
+ /* 112 */ SDL_SCANCODE_F1,
+ /* 113 */ SDL_SCANCODE_F2,
+ /* 114 */ SDL_SCANCODE_F3,
+ /* 115 */ SDL_SCANCODE_F4,
+ /* 116 */ SDL_SCANCODE_F5,
+ /* 117 */ SDL_SCANCODE_F6,
+ /* 118 */ SDL_SCANCODE_F7,
+ /* 119 */ SDL_SCANCODE_F8,
+ /* 120 */ SDL_SCANCODE_F9,
+ /* 121 */ SDL_SCANCODE_F10,
+ /* 122 */ SDL_SCANCODE_F11,
+ /* 123 */ SDL_SCANCODE_F12,
+ /* 124 */ SDL_SCANCODE_F13,
+ /* 125 */ SDL_SCANCODE_F14,
+ /* 126 */ SDL_SCANCODE_F15,
+ /* 127 */ SDL_SCANCODE_F16,
+ /* 128 */ SDL_SCANCODE_F17,
+ /* 129 */ SDL_SCANCODE_F18,
+ /* 130 */ SDL_SCANCODE_F19,
+ /* 131 */ SDL_SCANCODE_F20,
+ /* 132 */ SDL_SCANCODE_F21,
+ /* 133 */ SDL_SCANCODE_F22,
+ /* 134 */ SDL_SCANCODE_F23,
+ /* 135 */ SDL_SCANCODE_F24,
+ /* 136 */ SDL_SCANCODE_UNKNOWN,
+ /* 137 */ SDL_SCANCODE_UNKNOWN,
+ /* 138 */ SDL_SCANCODE_UNKNOWN,
+ /* 139 */ SDL_SCANCODE_UNKNOWN,
+ /* 140 */ SDL_SCANCODE_UNKNOWN,
+ /* 141 */ SDL_SCANCODE_UNKNOWN,
+ /* 142 */ SDL_SCANCODE_UNKNOWN,
+ /* 143 */ SDL_SCANCODE_UNKNOWN,
+ /* 144 */ SDL_SCANCODE_NUMLOCKCLEAR,
+ /* 145 */ SDL_SCANCODE_SCROLLLOCK,
+ /* 146 */ SDL_SCANCODE_UNKNOWN,
+ /* 147 */ SDL_SCANCODE_UNKNOWN,
+ /* 148 */ SDL_SCANCODE_UNKNOWN,
+ /* 149 */ SDL_SCANCODE_UNKNOWN,
+ /* 150 */ SDL_SCANCODE_UNKNOWN,
+ /* 151 */ SDL_SCANCODE_UNKNOWN,
+ /* 152 */ SDL_SCANCODE_UNKNOWN,
+ /* 153 */ SDL_SCANCODE_UNKNOWN,
+ /* 154 */ SDL_SCANCODE_UNKNOWN,
+ /* 155 */ SDL_SCANCODE_UNKNOWN,
+ /* 156 */ SDL_SCANCODE_UNKNOWN,
+ /* 157 */ SDL_SCANCODE_UNKNOWN,
+ /* 158 */ SDL_SCANCODE_UNKNOWN,
+ /* 159 */ SDL_SCANCODE_UNKNOWN,
+ /* 160 */ SDL_SCANCODE_UNKNOWN,
+ /* 161 */ SDL_SCANCODE_UNKNOWN,
+ /* 162 */ SDL_SCANCODE_UNKNOWN,
+ /* 163 */ SDL_SCANCODE_UNKNOWN,
+ /* 164 */ SDL_SCANCODE_UNKNOWN,
+ /* 165 */ SDL_SCANCODE_UNKNOWN,
+ /* 166 */ SDL_SCANCODE_UNKNOWN,
+ /* 167 */ SDL_SCANCODE_UNKNOWN,
+ /* 168 */ SDL_SCANCODE_UNKNOWN,
+ /* 169 */ SDL_SCANCODE_UNKNOWN,
+ /* 170 */ SDL_SCANCODE_UNKNOWN,
+ /* 171 */ SDL_SCANCODE_UNKNOWN,
+ /* 172 */ SDL_SCANCODE_UNKNOWN,
+ /* 173 */ SDL_SCANCODE_MINUS, /*FX*/
+ /* 174 */ SDL_SCANCODE_VOLUMEDOWN, /*IE, Chrome*/
+ /* 175 */ SDL_SCANCODE_VOLUMEUP, /*IE, Chrome*/
+ /* 176 */ SDL_SCANCODE_AUDIONEXT, /*IE, Chrome*/
+ /* 177 */ SDL_SCANCODE_AUDIOPREV, /*IE, Chrome*/
+ /* 178 */ SDL_SCANCODE_UNKNOWN,
+ /* 179 */ SDL_SCANCODE_AUDIOPLAY, /*IE, Chrome*/
+ /* 180 */ SDL_SCANCODE_UNKNOWN,
+ /* 181 */ SDL_SCANCODE_AUDIOMUTE, /*FX*/
+ /* 182 */ SDL_SCANCODE_VOLUMEDOWN, /*FX*/
+ /* 183 */ SDL_SCANCODE_VOLUMEUP, /*FX*/
+ /* 184 */ SDL_SCANCODE_UNKNOWN,
+ /* 185 */ SDL_SCANCODE_UNKNOWN,
+ /* 186 */ SDL_SCANCODE_SEMICOLON, /*IE, Chrome, D3E legacy*/
+ /* 187 */ SDL_SCANCODE_EQUALS, /*IE, Chrome, D3E legacy*/
+ /* 188 */ SDL_SCANCODE_COMMA,
+ /* 189 */ SDL_SCANCODE_MINUS, /*IE, Chrome, D3E legacy*/
+ /* 190 */ SDL_SCANCODE_PERIOD,
+ /* 191 */ SDL_SCANCODE_SLASH,
+ /* 192 */ SDL_SCANCODE_GRAVE, /*FX, D3E legacy (SDL_SCANCODE_APOSTROPHE in IE/Chrome)*/
+ /* 193 */ SDL_SCANCODE_UNKNOWN,
+ /* 194 */ SDL_SCANCODE_UNKNOWN,
+ /* 195 */ SDL_SCANCODE_UNKNOWN,
+ /* 196 */ SDL_SCANCODE_UNKNOWN,
+ /* 197 */ SDL_SCANCODE_UNKNOWN,
+ /* 198 */ SDL_SCANCODE_UNKNOWN,
+ /* 199 */ SDL_SCANCODE_UNKNOWN,
+ /* 200 */ SDL_SCANCODE_UNKNOWN,
+ /* 201 */ SDL_SCANCODE_UNKNOWN,
+ /* 202 */ SDL_SCANCODE_UNKNOWN,
+ /* 203 */ SDL_SCANCODE_UNKNOWN,
+ /* 204 */ SDL_SCANCODE_UNKNOWN,
+ /* 205 */ SDL_SCANCODE_UNKNOWN,
+ /* 206 */ SDL_SCANCODE_UNKNOWN,
+ /* 207 */ SDL_SCANCODE_UNKNOWN,
+ /* 208 */ SDL_SCANCODE_UNKNOWN,
+ /* 209 */ SDL_SCANCODE_UNKNOWN,
+ /* 210 */ SDL_SCANCODE_UNKNOWN,
+ /* 211 */ SDL_SCANCODE_UNKNOWN,
+ /* 212 */ SDL_SCANCODE_UNKNOWN,
+ /* 213 */ SDL_SCANCODE_UNKNOWN,
+ /* 214 */ SDL_SCANCODE_UNKNOWN,
+ /* 215 */ SDL_SCANCODE_UNKNOWN,
+ /* 216 */ SDL_SCANCODE_UNKNOWN,
+ /* 217 */ SDL_SCANCODE_UNKNOWN,
+ /* 218 */ SDL_SCANCODE_UNKNOWN,
+ /* 219 */ SDL_SCANCODE_LEFTBRACKET,
+ /* 220 */ SDL_SCANCODE_BACKSLASH,
+ /* 221 */ SDL_SCANCODE_RIGHTBRACKET,
+ /* 222 */ SDL_SCANCODE_APOSTROPHE, /*FX, D3E legacy*/
+};
+
+
+/* "borrowed" from SDL_windowsevents.c */
+static int
+Emscripten_ConvertUTF32toUTF8(Uint32 codepoint, char * text)
+{
+ if (codepoint <= 0x7F) {
+ text[0] = (char) codepoint;
+ text[1] = '\0';
+ } else if (codepoint <= 0x7FF) {
+ text[0] = 0xC0 | (char) ((codepoint >> 6) & 0x1F);
+ text[1] = 0x80 | (char) (codepoint & 0x3F);
+ text[2] = '\0';
+ } else if (codepoint <= 0xFFFF) {
+ text[0] = 0xE0 | (char) ((codepoint >> 12) & 0x0F);
+ text[1] = 0x80 | (char) ((codepoint >> 6) & 0x3F);
+ text[2] = 0x80 | (char) (codepoint & 0x3F);
+ text[3] = '\0';
+ } else if (codepoint <= 0x10FFFF) {
+ text[0] = 0xF0 | (char) ((codepoint >> 18) & 0x0F);
+ text[1] = 0x80 | (char) ((codepoint >> 12) & 0x3F);
+ text[2] = 0x80 | (char) ((codepoint >> 6) & 0x3F);
+ text[3] = 0x80 | (char) (codepoint & 0x3F);
+ text[4] = '\0';
+ } else {
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
+}
+
+static EM_BOOL
+Emscripten_HandlePointerLockChange(int eventType, const EmscriptenPointerlockChangeEvent *changeEvent, void *userData)
+{
+ SDL_WindowData *window_data = (SDL_WindowData *) userData;
+ /* keep track of lock losses, so we can regrab if/when appropriate. */
+ window_data->has_pointer_lock = changeEvent->isActive;
+ return 0;
+}
+
+
+static EM_BOOL
+Emscripten_HandleMouseMove(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
+{
+ SDL_WindowData *window_data = userData;
+ const int isPointerLocked = window_data->has_pointer_lock;
+ int mx, my;
+ static double residualx = 0, residualy = 0;
+
+ /* rescale (in case canvas is being scaled)*/
+ double client_w, client_h, xscale, yscale;
+ emscripten_get_element_css_size(NULL, &client_w, &client_h);
+ xscale = window_data->window->w / client_w;
+ yscale = window_data->window->h / client_h;
+
+ if (isPointerLocked) {
+ residualx += mouseEvent->movementX * xscale;
+ residualy += mouseEvent->movementY * yscale;
+ /* Let slow sub-pixel motion accumulate. Don't lose it. */
+ mx = residualx;
+ residualx -= mx;
+ my = residualy;
+ residualy -= my;
+ } else {
+ mx = mouseEvent->canvasX * xscale;
+ my = mouseEvent->canvasY * yscale;
+ }
+
+ SDL_SendMouseMotion(window_data->window, 0, isPointerLocked, mx, my);
+ return 0;
+}
+
+static EM_BOOL
+Emscripten_HandleMouseButton(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
+{
+ SDL_WindowData *window_data = userData;
+ Uint8 sdl_button;
+ Uint8 sdl_button_state;
+ SDL_EventType sdl_event_type;
+
+ switch (mouseEvent->button) {
+ case 0:
+ sdl_button = SDL_BUTTON_LEFT;
+ break;
+ case 1:
+ sdl_button = SDL_BUTTON_MIDDLE;
+ break;
+ case 2:
+ sdl_button = SDL_BUTTON_RIGHT;
+ break;
+ default:
+ return 0;
+ }
+
+ if (eventType == EMSCRIPTEN_EVENT_MOUSEDOWN) {
+ if (SDL_GetMouse()->relative_mode && !window_data->has_pointer_lock) {
+ emscripten_request_pointerlock(NULL, 0); /* try to regrab lost pointer lock. */
+ }
+ sdl_button_state = SDL_PRESSED;
+ sdl_event_type = SDL_MOUSEBUTTONDOWN;
+ } else {
+ sdl_button_state = SDL_RELEASED;
+ sdl_event_type = SDL_MOUSEBUTTONUP;
+ }
+ SDL_SendMouseButton(window_data->window, 0, sdl_button_state, sdl_button);
+ return SDL_GetEventState(sdl_event_type) == SDL_ENABLE;
+}
+
+static EM_BOOL
+Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
+{
+ SDL_WindowData *window_data = userData;
+
+ int mx = mouseEvent->canvasX, my = mouseEvent->canvasY;
+ const int isPointerLocked = window_data->has_pointer_lock;
+
+ if (!isPointerLocked) {
+ /* rescale (in case canvas is being scaled)*/
+ double client_w, client_h;
+ emscripten_get_element_css_size(NULL, &client_w, &client_h);
+
+ mx = mx * (window_data->window->w / client_w);
+ my = my * (window_data->window->h / client_h);
+ SDL_SendMouseMotion(window_data->window, 0, isPointerLocked, mx, my);
+ }
+
+ SDL_SetMouseFocus(eventType == EMSCRIPTEN_EVENT_MOUSEENTER ? window_data->window : NULL);
+ return SDL_GetEventState(SDL_WINDOWEVENT) == SDL_ENABLE;
+}
+
+static EM_BOOL
+Emscripten_HandleWheel(int eventType, const EmscriptenWheelEvent *wheelEvent, void *userData)
+{
+ SDL_WindowData *window_data = userData;
+ SDL_SendMouseWheel(window_data->window, 0, (float)wheelEvent->deltaX, (float)-wheelEvent->deltaY, SDL_MOUSEWHEEL_NORMAL);
+ return SDL_GetEventState(SDL_MOUSEWHEEL) == SDL_ENABLE;
+}
+
+static EM_BOOL
+Emscripten_HandleFocus(int eventType, const EmscriptenFocusEvent *wheelEvent, void *userData)
+{
+ SDL_WindowData *window_data = userData;
+ /* If the user switches away while keys are pressed (such as
+ * via Alt+Tab), key release events won't be received. */
+ if (eventType == EMSCRIPTEN_EVENT_BLUR) {
+ SDL_ResetKeyboard();
+ }
+
+
+ SDL_SendWindowEvent(window_data->window, eventType == EMSCRIPTEN_EVENT_FOCUS ? SDL_WINDOWEVENT_FOCUS_GAINED : SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
+ return SDL_GetEventState(SDL_WINDOWEVENT) == SDL_ENABLE;
+}
+
+static EM_BOOL
+Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
+{
+ SDL_WindowData *window_data = userData;
+ int i;
+ double client_w, client_h;
+ int preventDefault = 0;
+
+ SDL_TouchID deviceId = 1;
+ if (SDL_AddTouch(deviceId, "") < 0) {
+ return 0;
+ }
+
+ emscripten_get_element_css_size(NULL, &client_w, &client_h);
+
+ for (i = 0; i < touchEvent->numTouches; i++) {
+ SDL_FingerID id;
+ float x, y;
+ int mx, my;
+
+ if (!touchEvent->touches[i].isChanged)
+ continue;
+
+ id = touchEvent->touches[i].identifier;
+ x = touchEvent->touches[i].canvasX / client_w;
+ y = touchEvent->touches[i].canvasY / client_h;
+
+ mx = x * window_data->window->w;
+ my = y * window_data->window->h;
+
+ if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) {
+ if (!window_data->finger_touching) {
+ window_data->finger_touching = SDL_TRUE;
+ window_data->first_finger = id;
+ SDL_SendMouseMotion(window_data->window, SDL_TOUCH_MOUSEID, 0, mx, my);
+ SDL_SendMouseButton(window_data->window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
+ }
+ SDL_SendTouch(deviceId, id, SDL_TRUE, x, y, 1.0f);
+
+ if (!preventDefault && SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
+ preventDefault = 1;
+ }
+ } else if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) {
+ if ((window_data->finger_touching) && (window_data->first_finger == id)) {
+ SDL_SendMouseMotion(window_data->window, SDL_TOUCH_MOUSEID, 0, mx, my);
+ }
+ SDL_SendTouchMotion(deviceId, id, x, y, 1.0f);
+
+ if (!preventDefault && SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
+ preventDefault = 1;
+ }
+ } else {
+ if ((window_data->finger_touching) && (window_data->first_finger == id)) {
+ SDL_SendMouseButton(window_data->window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
+ window_data->finger_touching = SDL_FALSE;
+ }
+ SDL_SendTouch(deviceId, id, SDL_FALSE, x, y, 1.0f);
+
+ if (!preventDefault && SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
+ preventDefault = 1;
+ }
+ }
+ }
+
+ return preventDefault;
+}
+
+static EM_BOOL
+Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData)
+{
+ Uint32 scancode;
+ SDL_bool prevent_default;
+ SDL_bool is_nav_key;
+
+ /* .keyCode is deprecated, but still the most reliable way to get keys */
+ if (keyEvent->keyCode < SDL_arraysize(emscripten_scancode_table)) {
+ scancode = emscripten_scancode_table[keyEvent->keyCode];
+
+ if (scancode != SDL_SCANCODE_UNKNOWN) {
+
+ if (keyEvent->location == DOM_KEY_LOCATION_RIGHT) {
+ switch (scancode) {
+ case SDL_SCANCODE_LSHIFT:
+ scancode = SDL_SCANCODE_RSHIFT;
+ break;
+ case SDL_SCANCODE_LCTRL:
+ scancode = SDL_SCANCODE_RCTRL;
+ break;
+ case SDL_SCANCODE_LALT:
+ scancode = SDL_SCANCODE_RALT;
+ break;
+ case SDL_SCANCODE_LGUI:
+ scancode = SDL_SCANCODE_RGUI;
+ break;
+ }
+ }
+ SDL_SendKeyboardKey(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_PRESSED : SDL_RELEASED, scancode);
+ }
+ }
+
+ prevent_default = SDL_GetEventState(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_KEYDOWN : SDL_KEYUP) == SDL_ENABLE;
+
+ /* if TEXTINPUT events are enabled we can't prevent keydown or we won't get keypress
+ * we need to ALWAYS prevent backspace and tab otherwise chrome takes action and does bad navigation UX
+ */
+ is_nav_key = keyEvent->keyCode == 8 /* backspace */ ||
+ keyEvent->keyCode == 9 /* tab */ ||
+ keyEvent->keyCode == 37 /* left */ ||
+ keyEvent->keyCode == 38 /* up */ ||
+ keyEvent->keyCode == 39 /* right */ ||
+ keyEvent->keyCode == 40 /* down */;
+
+ if (eventType == EMSCRIPTEN_EVENT_KEYDOWN && SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE && !is_nav_key)
+ prevent_default = SDL_FALSE;
+
+ return prevent_default;
+}
+
+static EM_BOOL
+Emscripten_HandleKeyPress(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData)
+{
+ char text[5];
+ if (Emscripten_ConvertUTF32toUTF8(keyEvent->charCode, text)) {
+ SDL_SendKeyboardText(text);
+ }
+ return SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE;
+}
+
+static EM_BOOL
+Emscripten_HandleFullscreenChange(int eventType, const EmscriptenFullscreenChangeEvent *fullscreenChangeEvent, void *userData)
+{
+ SDL_WindowData *window_data = userData;
+ if(fullscreenChangeEvent->isFullscreen)
+ {
+ window_data->window->flags |= window_data->requested_fullscreen_mode;
+
+ window_data->requested_fullscreen_mode = 0;
+
+ if(!window_data->requested_fullscreen_mode)
+ window_data->window->flags |= SDL_WINDOW_FULLSCREEN; /*we didn't reqest fullscreen*/
+ }
+ else
+ {
+ window_data->window->flags &= ~FULLSCREEN_MASK;
+ }
+
+ return 0;
+}
+
+static EM_BOOL
+Emscripten_HandleResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData)
+{
+ SDL_WindowData *window_data = userData;
+
+ /* update pixel ratio */
+ if (window_data->window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
+ window_data->pixel_ratio = emscripten_get_device_pixel_ratio();
+ }
+
+ if(!(window_data->window->flags & FULLSCREEN_MASK))
+ {
+ /* this will only work if the canvas size is set through css */
+ if(window_data->window->flags & SDL_WINDOW_RESIZABLE)
+ {
+ double w = window_data->window->w;
+ double h = window_data->window->h;
+
+ if(window_data->external_size) {
+ emscripten_get_element_css_size(NULL, &w, &h);
+ }
+
+ emscripten_set_canvas_size(w * window_data->pixel_ratio, h * window_data->pixel_ratio);
+
+ /* set_canvas_size unsets this */
+ if (!window_data->external_size && window_data->pixel_ratio != 1.0f) {
+ emscripten_set_element_css_size(NULL, w, h);
+ }
+
+ SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, w, h);
+ }
+ }
+
+ return 0;
+}
+
+EM_BOOL
+Emscripten_HandleCanvasResize(int eventType, const void *reserved, void *userData)
+{
+ /*this is used during fullscreen changes*/
+ SDL_WindowData *window_data = userData;
+
+ if(window_data->fullscreen_resize)
+ {
+ double css_w, css_h;
+ emscripten_get_element_css_size(NULL, &css_w, &css_h);
+ SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, css_w, css_h);
+ }
+
+ return 0;
+}
+
+static EM_BOOL
+Emscripten_HandleVisibilityChange(int eventType, const EmscriptenVisibilityChangeEvent *visEvent, void *userData)
+{
+ SDL_WindowData *window_data = userData;
+ SDL_SendWindowEvent(window_data->window, visEvent->hidden ? SDL_WINDOWEVENT_HIDDEN : SDL_WINDOWEVENT_SHOWN, 0, 0);
+ return 0;
+}
+
+void
+Emscripten_RegisterEventHandlers(SDL_WindowData *data)
+{
+ const char *keyElement;
+
+ /* There is only one window and that window is the canvas */
+ emscripten_set_mousemove_callback("#canvas", data, 0, Emscripten_HandleMouseMove);
+
+ emscripten_set_mousedown_callback("#canvas", data, 0, Emscripten_HandleMouseButton);
+ emscripten_set_mouseup_callback("#document", data, 0, Emscripten_HandleMouseButton);
+
+ emscripten_set_mouseenter_callback("#canvas", data, 0, Emscripten_HandleMouseFocus);
+ emscripten_set_mouseleave_callback("#canvas", data, 0, Emscripten_HandleMouseFocus);
+
+ emscripten_set_wheel_callback("#canvas", data, 0, Emscripten_HandleWheel);
+
+ emscripten_set_focus_callback("#window", data, 0, Emscripten_HandleFocus);
+ emscripten_set_blur_callback("#window", data, 0, Emscripten_HandleFocus);
+
+ emscripten_set_touchstart_callback("#canvas", data, 0, Emscripten_HandleTouch);
+ emscripten_set_touchend_callback("#canvas", data, 0, Emscripten_HandleTouch);
+ emscripten_set_touchmove_callback("#canvas", data, 0, Emscripten_HandleTouch);
+ emscripten_set_touchcancel_callback("#canvas", data, 0, Emscripten_HandleTouch);
+
+ emscripten_set_pointerlockchange_callback("#document", data, 0, Emscripten_HandlePointerLockChange);
+
+ /* Keyboard events are awkward */
+ keyElement = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
+ if (!keyElement) keyElement = "#window";
+
+ emscripten_set_keydown_callback(keyElement, data, 0, Emscripten_HandleKey);
+ emscripten_set_keyup_callback(keyElement, data, 0, Emscripten_HandleKey);
+ emscripten_set_keypress_callback(keyElement, data, 0, Emscripten_HandleKeyPress);
+
+ emscripten_set_fullscreenchange_callback("#document", data, 0, Emscripten_HandleFullscreenChange);
+
+ emscripten_set_resize_callback("#window", data, 0, Emscripten_HandleResize);
+
+ emscripten_set_visibilitychange_callback(data, 0, Emscripten_HandleVisibilityChange);
+}
+
+void
+Emscripten_UnregisterEventHandlers(SDL_WindowData *data)
+{
+ const char *target;
+
+ /* only works due to having one window */
+ emscripten_set_mousemove_callback("#canvas", NULL, 0, NULL);
+
+ emscripten_set_mousedown_callback("#canvas", NULL, 0, NULL);
+ emscripten_set_mouseup_callback("#document", NULL, 0, NULL);
+
+ emscripten_set_mouseenter_callback("#canvas", NULL, 0, NULL);
+ emscripten_set_mouseleave_callback("#canvas", NULL, 0, NULL);
+
+ emscripten_set_wheel_callback("#canvas", NULL, 0, NULL);
+
+ emscripten_set_focus_callback("#window", NULL, 0, NULL);
+ emscripten_set_blur_callback("#window", NULL, 0, NULL);
+
+ emscripten_set_touchstart_callback("#canvas", NULL, 0, NULL);
+ emscripten_set_touchend_callback("#canvas", NULL, 0, NULL);
+ emscripten_set_touchmove_callback("#canvas", NULL, 0, NULL);
+ emscripten_set_touchcancel_callback("#canvas", NULL, 0, NULL);
+
+ emscripten_set_pointerlockchange_callback("#document", NULL, 0, NULL);
+
+ target = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
+ if (!target) {
+ target = "#window";
+ }
+
+ emscripten_set_keydown_callback(target, NULL, 0, NULL);
+ emscripten_set_keyup_callback(target, NULL, 0, NULL);
+ emscripten_set_keypress_callback(target, NULL, 0, NULL);
+
+ emscripten_set_fullscreenchange_callback("#document", NULL, 0, NULL);
+
+ emscripten_set_resize_callback("#window", NULL, 0, NULL);
+
+ emscripten_set_visibilitychange_callback(NULL, 0, NULL);
+}
+
+#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenevents.h b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenevents.h
new file mode 100644
index 0000000..3a4e058
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenevents.h
@@ -0,0 +1,40 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+
+#ifndef SDL_emscriptenevents_h_
+#define SDL_emscriptenevents_h_
+
+#include "SDL_emscriptenvideo.h"
+
+extern void
+Emscripten_RegisterEventHandlers(SDL_WindowData *data);
+
+extern void
+Emscripten_UnregisterEventHandlers(SDL_WindowData *data);
+
+extern EM_BOOL
+Emscripten_HandleCanvasResize(int eventType, const void *reserved, void *userData);
+
+#endif /* SDL_emscriptenevents_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenframebuffer.c b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenframebuffer.c
new file mode 100644
index 0000000..bfdec3b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenframebuffer.c
@@ -0,0 +1,178 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_EMSCRIPTEN
+
+#include "SDL_emscriptenvideo.h"
+#include "SDL_emscriptenframebuffer.h"
+
+
+int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
+{
+ SDL_Surface *surface;
+ const Uint32 surface_format = SDL_PIXELFORMAT_BGR888;
+ int w, h;
+ int bpp;
+ Uint32 Rmask, Gmask, Bmask, Amask;
+
+ /* Free the old framebuffer surface */
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ surface = data->surface;
+ SDL_FreeSurface(surface);
+
+ /* Create a new one */
+ SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
+ SDL_GetWindowSize(window, &w, &h);
+
+ surface = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
+ if (!surface) {
+ return -1;
+ }
+
+ /* Save the info and return! */
+ data->surface = surface;
+ *format = surface_format;
+ *pixels = surface->pixels;
+ *pitch = surface->pitch;
+ return 0;
+}
+
+int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects)
+{
+ SDL_Surface *surface;
+
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ surface = data->surface;
+ if (!surface) {
+ return SDL_SetError("Couldn't find framebuffer surface for window");
+ }
+
+ /* Send the data to the display */
+
+ EM_ASM_INT({
+ var w = $0;
+ var h = $1;
+ var pixels = $2;
+
+ if (!Module['SDL2']) Module['SDL2'] = {};
+ var SDL2 = Module['SDL2'];
+ if (SDL2.ctxCanvas !== Module['canvas']) {
+ SDL2.ctx = Module['createContext'](Module['canvas'], false, true);
+ SDL2.ctxCanvas = Module['canvas'];
+ }
+ if (SDL2.w !== w || SDL2.h !== h || SDL2.imageCtx !== SDL2.ctx) {
+ SDL2.image = SDL2.ctx.createImageData(w, h);
+ SDL2.w = w;
+ SDL2.h = h;
+ SDL2.imageCtx = SDL2.ctx;
+ }
+ var data = SDL2.image.data;
+ var src = pixels >> 2;
+ var dst = 0;
+ var num;
+ if (typeof CanvasPixelArray !== 'undefined' && data instanceof CanvasPixelArray) {
+ // IE10/IE11: ImageData objects are backed by the deprecated CanvasPixelArray,
+ // not UInt8ClampedArray. These don't have buffers, so we need to revert
+ // to copying a byte at a time. We do the undefined check because modern
+ // browsers do not define CanvasPixelArray anymore.
+ num = data.length;
+ while (dst < num) {
+ var val = HEAP32[src]; // This is optimized. Instead, we could do {{{ makeGetValue('buffer', 'dst', 'i32') }}};
+ data[dst ] = val & 0xff;
+ data[dst+1] = (val >> 8) & 0xff;
+ data[dst+2] = (val >> 16) & 0xff;
+ data[dst+3] = 0xff;
+ src++;
+ dst += 4;
+ }
+ } else {
+ if (SDL2.data32Data !== data) {
+ SDL2.data32 = new Int32Array(data.buffer);
+ SDL2.data8 = new Uint8Array(data.buffer);
+ }
+ var data32 = SDL2.data32;
+ num = data32.length;
+ // logically we need to do
+ // while (dst < num) {
+ // data32[dst++] = HEAP32[src++] | 0xff000000
+ // }
+ // the following code is faster though, because
+ // .set() is almost free - easily 10x faster due to
+ // native memcpy efficiencies, and the remaining loop
+ // just stores, not load + store, so it is faster
+ data32.set(HEAP32.subarray(src, src + num));
+ var data8 = SDL2.data8;
+ var i = 3;
+ var j = i + 4*num;
+ if (num % 8 == 0) {
+ // unrolling gives big speedups
+ while (i < j) {
+ data8[i] = 0xff;
+ i = i + 4 | 0;
+ data8[i] = 0xff;
+ i = i + 4 | 0;
+ data8[i] = 0xff;
+ i = i + 4 | 0;
+ data8[i] = 0xff;
+ i = i + 4 | 0;
+ data8[i] = 0xff;
+ i = i + 4 | 0;
+ data8[i] = 0xff;
+ i = i + 4 | 0;
+ data8[i] = 0xff;
+ i = i + 4 | 0;
+ data8[i] = 0xff;
+ i = i + 4 | 0;
+ }
+ } else {
+ while (i < j) {
+ data8[i] = 0xff;
+ i = i + 4 | 0;
+ }
+ }
+ }
+
+ SDL2.ctx.putImageData(SDL2.image, 0, 0);
+ return 0;
+ }, surface->w, surface->h, surface->pixels);
+
+ /*if (SDL_getenv("SDL_VIDEO_Emscripten_SAVE_FRAMES")) {
+ static int frame_number = 0;
+ char file[128];
+ SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp",
+ SDL_GetWindowID(window), ++frame_number);
+ SDL_SaveBMP(surface, file);
+ }*/
+ return 0;
+}
+
+void Emscripten_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+
+ SDL_FreeSurface(data->surface);
+ data->surface = NULL;
+}
+
+#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenframebuffer.h b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenframebuffer.h
new file mode 100644
index 0000000..49a215a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenframebuffer.h
@@ -0,0 +1,32 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_emscriptenframebuffer_h_
+#define SDL_emscriptenframebuffer_h_
+
+extern int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
+extern int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects);
+extern void Emscripten_DestroyWindowFramebuffer(_THIS, SDL_Window * window);
+
+#endif /* SDL_emscriptenframebuffer_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenmouse.c b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenmouse.c
new file mode 100644
index 0000000..490f5b0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenmouse.c
@@ -0,0 +1,274 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_EMSCRIPTEN
+
+#include <emscripten/emscripten.h>
+#include <emscripten/html5.h>
+
+#include "SDL_emscriptenmouse.h"
+
+#include "../../events/SDL_mouse_c.h"
+#include "SDL_assert.h"
+
+static SDL_Cursor*
+Emscripten_CreateCursorFromString(const char* cursor_str, SDL_bool is_custom)
+{
+ SDL_Cursor* cursor;
+ Emscripten_CursorData *curdata;
+
+ cursor = SDL_calloc(1, sizeof(SDL_Cursor));
+ if (cursor) {
+ curdata = (Emscripten_CursorData *) SDL_calloc(1, sizeof(*curdata));
+ if (!curdata) {
+ SDL_OutOfMemory();
+ SDL_free(cursor);
+ return NULL;
+ }
+
+ curdata->system_cursor = cursor_str;
+ curdata->is_custom = is_custom;
+ cursor->driverdata = curdata;
+ }
+ else {
+ SDL_OutOfMemory();
+ }
+
+ return cursor;
+}
+
+static SDL_Cursor*
+Emscripten_CreateDefaultCursor()
+{
+ return Emscripten_CreateCursorFromString("default", SDL_FALSE);
+}
+
+static SDL_Cursor*
+Emscripten_CreateCursor(SDL_Surface* surface, int hot_x, int hot_y)
+{
+ const char *cursor_url = NULL;
+ SDL_Surface *conv_surf;
+
+ conv_surf = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ABGR8888, 0);
+
+ if (!conv_surf) {
+ return NULL;
+ }
+
+ cursor_url = (const char *)EM_ASM_INT({
+ var w = $0;
+ var h = $1;
+ var hot_x = $2;
+ var hot_y = $3;
+ var pixels = $4;
+
+ var canvas = document.createElement("canvas");
+ canvas.width = w;
+ canvas.height = h;
+
+ var ctx = canvas.getContext("2d");
+
+ var image = ctx.createImageData(w, h);
+ var data = image.data;
+ var src = pixels >> 2;
+ var dst = 0;
+ var num;
+ if (typeof CanvasPixelArray !== 'undefined' && data instanceof CanvasPixelArray) {
+ // IE10/IE11: ImageData objects are backed by the deprecated CanvasPixelArray,
+ // not UInt8ClampedArray. These don't have buffers, so we need to revert
+ // to copying a byte at a time. We do the undefined check because modern
+ // browsers do not define CanvasPixelArray anymore.
+ num = data.length;
+ while (dst < num) {
+ var val = HEAP32[src]; // This is optimized. Instead, we could do {{{ makeGetValue('buffer', 'dst', 'i32') }}};
+ data[dst ] = val & 0xff;
+ data[dst+1] = (val >> 8) & 0xff;
+ data[dst+2] = (val >> 16) & 0xff;
+ data[dst+3] = (val >> 24) & 0xff;
+ src++;
+ dst += 4;
+ }
+ } else {
+ var data32 = new Int32Array(data.buffer);
+ num = data32.length;
+ data32.set(HEAP32.subarray(src, src + num));
+ }
+
+ ctx.putImageData(image, 0, 0);
+ var url = hot_x === 0 && hot_y === 0
+ ? "url(" + canvas.toDataURL() + "), auto"
+ : "url(" + canvas.toDataURL() + ") " + hot_x + " " + hot_y + ", auto";
+
+ var urlBuf = _malloc(url.length + 1);
+ stringToUTF8(url, urlBuf, url.length + 1);
+
+ return urlBuf;
+ }, surface->w, surface->h, hot_x, hot_y, conv_surf->pixels);
+
+ SDL_FreeSurface(conv_surf);
+
+ return Emscripten_CreateCursorFromString(cursor_url, SDL_TRUE);
+}
+
+static SDL_Cursor*
+Emscripten_CreateSystemCursor(SDL_SystemCursor id)
+{
+ const char *cursor_name = NULL;
+
+ switch(id) {
+ case SDL_SYSTEM_CURSOR_ARROW:
+ cursor_name = "default";
+ break;
+ case SDL_SYSTEM_CURSOR_IBEAM:
+ cursor_name = "text";
+ break;
+ case SDL_SYSTEM_CURSOR_WAIT:
+ cursor_name = "wait";
+ break;
+ case SDL_SYSTEM_CURSOR_CROSSHAIR:
+ cursor_name = "crosshair";
+ break;
+ case SDL_SYSTEM_CURSOR_WAITARROW:
+ cursor_name = "progress";
+ break;
+ case SDL_SYSTEM_CURSOR_SIZENWSE:
+ cursor_name = "nwse-resize";
+ break;
+ case SDL_SYSTEM_CURSOR_SIZENESW:
+ cursor_name = "nesw-resize";
+ break;
+ case SDL_SYSTEM_CURSOR_SIZEWE:
+ cursor_name = "ew-resize";
+ break;
+ case SDL_SYSTEM_CURSOR_SIZENS:
+ cursor_name = "ns-resize";
+ break;
+ case SDL_SYSTEM_CURSOR_SIZEALL:
+ break;
+ case SDL_SYSTEM_CURSOR_NO:
+ cursor_name = "not-allowed";
+ break;
+ case SDL_SYSTEM_CURSOR_HAND:
+ cursor_name = "pointer";
+ break;
+ default:
+ SDL_assert(0);
+ return NULL;
+ }
+
+ return Emscripten_CreateCursorFromString(cursor_name, SDL_FALSE);
+}
+
+static void
+Emscripten_FreeCursor(SDL_Cursor* cursor)
+{
+ Emscripten_CursorData *curdata;
+ if (cursor) {
+ curdata = (Emscripten_CursorData *) cursor->driverdata;
+
+ if (curdata != NULL) {
+ if (curdata->is_custom) {
+ SDL_free((char *)curdata->system_cursor);
+ }
+ SDL_free(cursor->driverdata);
+ }
+
+ SDL_free(cursor);
+ }
+}
+
+static int
+Emscripten_ShowCursor(SDL_Cursor* cursor)
+{
+ Emscripten_CursorData *curdata;
+ if (SDL_GetMouseFocus() != NULL) {
+ if(cursor && cursor->driverdata) {
+ curdata = (Emscripten_CursorData *) cursor->driverdata;
+
+ if(curdata->system_cursor) {
+ EM_ASM_INT({
+ if (Module['canvas']) {
+ Module['canvas'].style['cursor'] = Module['Pointer_stringify']($0);
+ }
+ return 0;
+ }, curdata->system_cursor);
+ }
+ }
+ else {
+ EM_ASM(
+ if (Module['canvas']) {
+ Module['canvas'].style['cursor'] = 'none';
+ }
+ );
+ }
+ }
+ return 0;
+}
+
+static void
+Emscripten_WarpMouse(SDL_Window* window, int x, int y)
+{
+ SDL_Unsupported();
+}
+
+static int
+Emscripten_SetRelativeMouseMode(SDL_bool enabled)
+{
+ /* TODO: pointer lock isn't actually enabled yet */
+ if(enabled) {
+ if(emscripten_request_pointerlock(NULL, 1) >= EMSCRIPTEN_RESULT_SUCCESS) {
+ return 0;
+ }
+ } else {
+ if(emscripten_exit_pointerlock() >= EMSCRIPTEN_RESULT_SUCCESS) {
+ return 0;
+ }
+ }
+ return -1;
+}
+
+void
+Emscripten_InitMouse()
+{
+ SDL_Mouse* mouse = SDL_GetMouse();
+
+ mouse->CreateCursor = Emscripten_CreateCursor;
+ mouse->ShowCursor = Emscripten_ShowCursor;
+ mouse->FreeCursor = Emscripten_FreeCursor;
+ mouse->WarpMouse = Emscripten_WarpMouse;
+ mouse->CreateSystemCursor = Emscripten_CreateSystemCursor;
+ mouse->SetRelativeMouseMode = Emscripten_SetRelativeMouseMode;
+
+ SDL_SetDefaultCursor(Emscripten_CreateDefaultCursor());
+}
+
+void
+Emscripten_FiniMouse()
+{
+}
+
+#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenmouse.h b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenmouse.h
new file mode 100644
index 0000000..d6cd492
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenmouse.h
@@ -0,0 +1,42 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+
+#ifndef SDL_emscriptenmouse_h_
+#define SDL_emscriptenmouse_h_
+
+#include "SDL_stdinc.h"
+
+typedef struct _Emscripten_CursorData
+{
+ const char *system_cursor;
+ SDL_bool is_custom;
+} Emscripten_CursorData;
+
+extern void
+Emscripten_InitMouse();
+
+extern void
+Emscripten_FiniMouse();
+
+#endif /* SDL_emscriptenmouse_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenopengles.c b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenopengles.c
new file mode 100644
index 0000000..a6609ed
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenopengles.c
@@ -0,0 +1,119 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_EMSCRIPTEN && SDL_VIDEO_OPENGL_EGL
+
+#include <emscripten/emscripten.h>
+#include <GLES2/gl2.h>
+
+#include "SDL_emscriptenvideo.h"
+#include "SDL_emscriptenopengles.h"
+
+#define LOAD_FUNC(NAME) _this->egl_data->NAME = NAME;
+
+/* EGL implementation of SDL OpenGL support */
+
+int
+Emscripten_GLES_LoadLibrary(_THIS, const char *path) {
+ /*we can't load EGL dynamically*/
+ _this->egl_data = (struct SDL_EGL_VideoData *) SDL_calloc(1, sizeof(SDL_EGL_VideoData));
+ if (!_this->egl_data) {
+ return SDL_OutOfMemory();
+ }
+
+ /* Emscripten forces you to manually cast eglGetProcAddress to the real
+ function type; grep for "__eglMustCastToProperFunctionPointerType" in
+ Emscripten's egl.h for details. */
+ _this->egl_data->eglGetProcAddress = (void *(EGLAPIENTRY *)(const char *)) eglGetProcAddress;
+
+ LOAD_FUNC(eglGetDisplay);
+ LOAD_FUNC(eglInitialize);
+ LOAD_FUNC(eglTerminate);
+ LOAD_FUNC(eglChooseConfig);
+ LOAD_FUNC(eglGetConfigAttrib);
+ LOAD_FUNC(eglCreateContext);
+ LOAD_FUNC(eglDestroyContext);
+ LOAD_FUNC(eglCreateWindowSurface);
+ LOAD_FUNC(eglDestroySurface);
+ LOAD_FUNC(eglMakeCurrent);
+ LOAD_FUNC(eglSwapBuffers);
+ LOAD_FUNC(eglSwapInterval);
+ LOAD_FUNC(eglWaitNative);
+ LOAD_FUNC(eglWaitGL);
+ LOAD_FUNC(eglBindAPI);
+
+ _this->egl_data->egl_display = _this->egl_data->eglGetDisplay(EGL_DEFAULT_DISPLAY);
+ if (!_this->egl_data->egl_display) {
+ return SDL_SetError("Could not get EGL display");
+ }
+
+ if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
+ return SDL_SetError("Could not initialize EGL");
+ }
+
+ if (path) {
+ SDL_strlcpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path) - 1);
+ } else {
+ *_this->gl_config.driver_path = '\0';
+ }
+
+ return 0;
+}
+
+void
+Emscripten_GLES_DeleteContext(_THIS, SDL_GLContext context)
+{
+ /*
+ WebGL contexts can't actually be deleted, so we need to reset it.
+ ES2 renderer resets state on init anyway, clearing the canvas should be enough
+ */
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+
+ SDL_EGL_DeleteContext(_this, context);
+}
+
+SDL_EGL_CreateContext_impl(Emscripten)
+SDL_EGL_SwapWindow_impl(Emscripten)
+SDL_EGL_MakeCurrent_impl(Emscripten)
+
+void
+Emscripten_GLES_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
+{
+ SDL_WindowData *data;
+ if (window->driverdata) {
+ data = (SDL_WindowData *) window->driverdata;
+
+ if (w) {
+ *w = window->w * data->pixel_ratio;
+ }
+
+ if (h) {
+ *h = window->h * data->pixel_ratio;
+ }
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN && SDL_VIDEO_OPENGL_EGL */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenopengles.h b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenopengles.h
new file mode 100644
index 0000000..fbd93cb
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenopengles.h
@@ -0,0 +1,49 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_emscriptenopengles_h_
+#define SDL_emscriptenopengles_h_
+
+#if SDL_VIDEO_DRIVER_EMSCRIPTEN && SDL_VIDEO_OPENGL_EGL
+
+#include "../SDL_sysvideo.h"
+#include "../SDL_egl_c.h"
+
+/* OpenGLES functions */
+#define Emscripten_GLES_GetAttribute SDL_EGL_GetAttribute
+#define Emscripten_GLES_GetProcAddress SDL_EGL_GetProcAddress
+#define Emscripten_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
+#define Emscripten_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
+#define Emscripten_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
+
+extern int Emscripten_GLES_LoadLibrary(_THIS, const char *path);
+extern void Emscripten_GLES_DeleteContext(_THIS, SDL_GLContext context);
+extern SDL_GLContext Emscripten_GLES_CreateContext(_THIS, SDL_Window * window);
+extern int Emscripten_GLES_SwapWindow(_THIS, SDL_Window * window);
+extern int Emscripten_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+extern void Emscripten_GLES_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h);
+
+#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN && SDL_VIDEO_OPENGL_EGL */
+
+#endif /* SDL_emscriptenopengles_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenvideo.c b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenvideo.c
new file mode 100644
index 0000000..cbb933d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenvideo.c
@@ -0,0 +1,354 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_EMSCRIPTEN
+
+#include "SDL_video.h"
+#include "SDL_mouse.h"
+#include "SDL_hints.h"
+#include "../SDL_sysvideo.h"
+#include "../SDL_pixels_c.h"
+#include "../SDL_egl_c.h"
+#include "../../events/SDL_events_c.h"
+
+#include "SDL_emscriptenvideo.h"
+#include "SDL_emscriptenopengles.h"
+#include "SDL_emscriptenframebuffer.h"
+#include "SDL_emscriptenevents.h"
+#include "SDL_emscriptenmouse.h"
+
+#define EMSCRIPTENVID_DRIVER_NAME "emscripten"
+
+/* Initialization/Query functions */
+static int Emscripten_VideoInit(_THIS);
+static int Emscripten_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
+static void Emscripten_VideoQuit(_THIS);
+
+static int Emscripten_CreateWindow(_THIS, SDL_Window * window);
+static void Emscripten_SetWindowSize(_THIS, SDL_Window * window);
+static void Emscripten_DestroyWindow(_THIS, SDL_Window * window);
+static void Emscripten_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
+static void Emscripten_PumpEvents(_THIS);
+static void Emscripten_SetWindowTitle(_THIS, SDL_Window * window);
+
+
+/* Emscripten driver bootstrap functions */
+
+static int
+Emscripten_Available(void)
+{
+ return (1);
+}
+
+static void
+Emscripten_DeleteDevice(SDL_VideoDevice * device)
+{
+ SDL_free(device);
+}
+
+static SDL_VideoDevice *
+Emscripten_CreateDevice(int devindex)
+{
+ SDL_VideoDevice *device;
+
+ /* Initialize all variables that we clean on shutdown */
+ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (!device) {
+ SDL_OutOfMemory();
+ return (0);
+ }
+
+ /* Firefox sends blur event which would otherwise prevent full screen
+ * when the user clicks to allow full screen.
+ * See https://bugzilla.mozilla.org/show_bug.cgi?id=1144964
+ */
+ SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
+
+ /* Set the function pointers */
+ device->VideoInit = Emscripten_VideoInit;
+ device->VideoQuit = Emscripten_VideoQuit;
+ device->SetDisplayMode = Emscripten_SetDisplayMode;
+
+
+ device->PumpEvents = Emscripten_PumpEvents;
+
+ device->CreateSDLWindow = Emscripten_CreateWindow;
+ device->SetWindowTitle = Emscripten_SetWindowTitle;
+ /*device->SetWindowIcon = Emscripten_SetWindowIcon;
+ device->SetWindowPosition = Emscripten_SetWindowPosition;*/
+ device->SetWindowSize = Emscripten_SetWindowSize;
+ /*device->ShowWindow = Emscripten_ShowWindow;
+ device->HideWindow = Emscripten_HideWindow;
+ device->RaiseWindow = Emscripten_RaiseWindow;
+ device->MaximizeWindow = Emscripten_MaximizeWindow;
+ device->MinimizeWindow = Emscripten_MinimizeWindow;
+ device->RestoreWindow = Emscripten_RestoreWindow;
+ device->SetWindowGrab = Emscripten_SetWindowGrab;*/
+ device->DestroyWindow = Emscripten_DestroyWindow;
+ device->SetWindowFullscreen = Emscripten_SetWindowFullscreen;
+
+ device->CreateWindowFramebuffer = Emscripten_CreateWindowFramebuffer;
+ device->UpdateWindowFramebuffer = Emscripten_UpdateWindowFramebuffer;
+ device->DestroyWindowFramebuffer = Emscripten_DestroyWindowFramebuffer;
+
+#if SDL_VIDEO_OPENGL_EGL
+ device->GL_LoadLibrary = Emscripten_GLES_LoadLibrary;
+ device->GL_GetProcAddress = Emscripten_GLES_GetProcAddress;
+ device->GL_UnloadLibrary = Emscripten_GLES_UnloadLibrary;
+ device->GL_CreateContext = Emscripten_GLES_CreateContext;
+ device->GL_MakeCurrent = Emscripten_GLES_MakeCurrent;
+ device->GL_SetSwapInterval = Emscripten_GLES_SetSwapInterval;
+ device->GL_GetSwapInterval = Emscripten_GLES_GetSwapInterval;
+ device->GL_SwapWindow = Emscripten_GLES_SwapWindow;
+ device->GL_DeleteContext = Emscripten_GLES_DeleteContext;
+ device->GL_GetDrawableSize = Emscripten_GLES_GetDrawableSize;
+#endif
+
+ device->free = Emscripten_DeleteDevice;
+
+ return device;
+}
+
+VideoBootStrap Emscripten_bootstrap = {
+ EMSCRIPTENVID_DRIVER_NAME, "SDL emscripten video driver",
+ Emscripten_Available, Emscripten_CreateDevice
+};
+
+
+int
+Emscripten_VideoInit(_THIS)
+{
+ SDL_DisplayMode mode;
+
+ /* Use a fake 32-bpp desktop mode */
+ mode.format = SDL_PIXELFORMAT_RGB888;
+
+ mode.w = EM_ASM_INT_V({
+ return screen.width;
+ });
+
+ mode.h = EM_ASM_INT_V({
+ return screen.height;
+ });
+
+ mode.refresh_rate = 0;
+ mode.driverdata = NULL;
+ if (SDL_AddBasicVideoDisplay(&mode) < 0) {
+ return -1;
+ }
+
+ SDL_zero(mode);
+ SDL_AddDisplayMode(&_this->displays[0], &mode);
+
+ Emscripten_InitMouse();
+
+ /* We're done! */
+ return 0;
+}
+
+static int
+Emscripten_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
+{
+ /* can't do this */
+ return 0;
+}
+
+static void
+Emscripten_VideoQuit(_THIS)
+{
+ Emscripten_FiniMouse();
+}
+
+static void
+Emscripten_PumpEvents(_THIS)
+{
+ /* do nothing. */
+}
+
+static int
+Emscripten_CreateWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *wdata;
+ double scaled_w, scaled_h;
+ double css_w, css_h;
+
+ /* Allocate window internal data */
+ wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
+ if (wdata == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
+ wdata->pixel_ratio = emscripten_get_device_pixel_ratio();
+ } else {
+ wdata->pixel_ratio = 1.0f;
+ }
+
+ scaled_w = SDL_floor(window->w * wdata->pixel_ratio);
+ scaled_h = SDL_floor(window->h * wdata->pixel_ratio);
+
+ emscripten_set_canvas_size(scaled_w, scaled_h);
+
+ emscripten_get_element_css_size(NULL, &css_w, &css_h);
+
+ wdata->external_size = SDL_floor(css_w) != scaled_w || SDL_floor(css_h) != scaled_h;
+
+ if ((window->flags & SDL_WINDOW_RESIZABLE) && wdata->external_size) {
+ /* external css has resized us */
+ scaled_w = css_w * wdata->pixel_ratio;
+ scaled_h = css_h * wdata->pixel_ratio;
+
+ emscripten_set_canvas_size(scaled_w, scaled_h);
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, css_w, css_h);
+ }
+
+ /* if the size is not being controlled by css, we need to scale down for hidpi */
+ if (!wdata->external_size) {
+ if (wdata->pixel_ratio != 1.0f) {
+ /*scale canvas down*/
+ emscripten_set_element_css_size(NULL, window->w, window->h);
+ }
+ }
+
+#if SDL_VIDEO_OPENGL_EGL
+ if (window->flags & SDL_WINDOW_OPENGL) {
+ if (!_this->egl_data) {
+ if (SDL_GL_LoadLibrary(NULL) < 0) {
+ return -1;
+ }
+ }
+ wdata->egl_surface = SDL_EGL_CreateSurface(_this, 0);
+
+ if (wdata->egl_surface == EGL_NO_SURFACE) {
+ return SDL_SetError("Could not create GLES window surface");
+ }
+ }
+#endif
+
+ wdata->window = window;
+
+ /* Setup driver data for this window */
+ window->driverdata = wdata;
+
+ /* One window, it always has focus */
+ SDL_SetMouseFocus(window);
+ SDL_SetKeyboardFocus(window);
+
+ Emscripten_RegisterEventHandlers(wdata);
+
+ /* Window has been successfully created */
+ return 0;
+}
+
+static void Emscripten_SetWindowSize(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data;
+
+ if (window->driverdata) {
+ data = (SDL_WindowData *) window->driverdata;
+ /* update pixel ratio */
+ if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
+ data->pixel_ratio = emscripten_get_device_pixel_ratio();
+ }
+ emscripten_set_canvas_size(window->w * data->pixel_ratio, window->h * data->pixel_ratio);
+
+ /*scale canvas down*/
+ if (!data->external_size && data->pixel_ratio != 1.0f) {
+ emscripten_set_element_css_size(NULL, window->w, window->h);
+ }
+ }
+}
+
+static void
+Emscripten_DestroyWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data;
+
+ if(window->driverdata) {
+ data = (SDL_WindowData *) window->driverdata;
+
+ Emscripten_UnregisterEventHandlers(data);
+#if SDL_VIDEO_OPENGL_EGL
+ if (data->egl_surface != EGL_NO_SURFACE) {
+ SDL_EGL_DestroySurface(_this, data->egl_surface);
+ data->egl_surface = EGL_NO_SURFACE;
+ }
+#endif
+ SDL_free(window->driverdata);
+ window->driverdata = NULL;
+ }
+}
+
+static void
+Emscripten_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
+{
+ SDL_WindowData *data;
+ if(window->driverdata) {
+ data = (SDL_WindowData *) window->driverdata;
+
+ if(fullscreen) {
+ EmscriptenFullscreenStrategy strategy;
+ SDL_bool is_desktop_fullscreen = (window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP;
+ int res;
+
+ strategy.scaleMode = is_desktop_fullscreen ? EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH : EMSCRIPTEN_FULLSCREEN_SCALE_ASPECT;
+
+ if(!is_desktop_fullscreen) {
+ strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_NONE;
+ } else if(window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
+ strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_HIDEF;
+ } else {
+ strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF;
+ }
+
+ strategy.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT;
+
+ strategy.canvasResizedCallback = Emscripten_HandleCanvasResize;
+ strategy.canvasResizedCallbackUserData = data;
+
+ data->requested_fullscreen_mode = window->flags & (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN);
+ data->fullscreen_resize = is_desktop_fullscreen;
+
+ res = emscripten_request_fullscreen_strategy(NULL, 1, &strategy);
+ if(res != EMSCRIPTEN_RESULT_SUCCESS && res != EMSCRIPTEN_RESULT_DEFERRED) {
+ /* unset flags, fullscreen failed */
+ window->flags &= ~(SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN);
+ }
+ }
+ else
+ emscripten_exit_fullscreen();
+ }
+}
+
+static void
+Emscripten_SetWindowTitle(_THIS, SDL_Window * window) {
+ EM_ASM_INT({
+ if (typeof Module['setWindowTitle'] !== 'undefined') {
+ Module['setWindowTitle'](Module['Pointer_stringify']($0));
+ }
+ return 0;
+ }, window->title);
+}
+
+#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenvideo.h b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenvideo.h
new file mode 100644
index 0000000..c2001b0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/emscripten/SDL_emscriptenvideo.h
@@ -0,0 +1,58 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_emscriptenvideo_h_
+#define SDL_emscriptenvideo_h_
+
+#include "../SDL_sysvideo.h"
+#include "../../events/SDL_touch_c.h"
+#include <emscripten/emscripten.h>
+#include <emscripten/html5.h>
+
+#if SDL_VIDEO_OPENGL_EGL
+#include <EGL/egl.h>
+#endif
+
+typedef struct SDL_WindowData
+{
+#if SDL_VIDEO_OPENGL_EGL
+ EGLSurface egl_surface;
+#endif
+ SDL_Window *window;
+ SDL_Surface *surface;
+
+ float pixel_ratio;
+
+ SDL_bool external_size;
+
+ int requested_fullscreen_mode;
+ SDL_bool fullscreen_resize;
+
+ SDL_bool finger_touching; /* for mapping touch events to mice */
+ SDL_FingerID first_finger;
+
+ SDL_bool has_pointer_lock;
+} SDL_WindowData;
+
+#endif /* SDL_emscriptenvideo_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/haiku/SDL_BWin.h b/src/3rdparty/SDL2/src/video/haiku/SDL_BWin.h
new file mode 100644
index 0000000..3e61888
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/haiku/SDL_BWin.h
@@ -0,0 +1,679 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_BWin_h_
+#define SDL_BWin_h_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "../../SDL_internal.h"
+#include "SDL.h"
+#include "SDL_syswm.h"
+#include "SDL_bframebuffer.h"
+
+#ifdef __cplusplus
+}
+#endif
+
+#include <stdio.h>
+#include <AppKit.h>
+#include <InterfaceKit.h>
+#include <game/DirectWindow.h>
+#if SDL_VIDEO_OPENGL
+#include <opengl/GLView.h>
+#endif
+#include "SDL_events.h"
+#include "../../main/haiku/SDL_BApp.h"
+
+
+enum WinCommands {
+ BWIN_MOVE_WINDOW,
+ BWIN_RESIZE_WINDOW,
+ BWIN_SHOW_WINDOW,
+ BWIN_HIDE_WINDOW,
+ BWIN_MAXIMIZE_WINDOW,
+ BWIN_MINIMIZE_WINDOW,
+ BWIN_RESTORE_WINDOW,
+ BWIN_SET_TITLE,
+ BWIN_SET_BORDERED,
+ BWIN_SET_RESIZABLE,
+ BWIN_FULLSCREEN
+};
+
+
+class SDL_BWin:public BDirectWindow
+{
+ public:
+ /* Constructor/Destructor */
+ SDL_BWin(BRect bounds, window_look look, uint32 flags)
+ : BDirectWindow(bounds, "Untitled", look, B_NORMAL_WINDOW_FEEL, flags)
+ {
+ _last_buttons = 0;
+
+#if SDL_VIDEO_OPENGL
+ _SDL_GLView = NULL;
+ _gl_type = 0;
+#endif
+ _shown = false;
+ _inhibit_resize = false;
+ _mouse_focused = false;
+ _prev_frame = NULL;
+
+ /* Handle framebuffer stuff */
+ _connected = _connection_disabled = false;
+ _buffer_created = _buffer_dirty = false;
+ _trash_window_buffer = false;
+ _buffer_locker = new BLocker();
+ _bitmap = NULL;
+ _clips = NULL;
+
+#ifdef DRAWTHREAD
+ _draw_thread_id = spawn_thread(BE_DrawThread, "drawing_thread",
+ B_NORMAL_PRIORITY, (void*) this);
+ resume_thread(_draw_thread_id);
+#endif
+ }
+
+ virtual ~ SDL_BWin()
+ {
+ Lock();
+ _connection_disabled = true;
+ int32 result;
+
+#if SDL_VIDEO_OPENGL
+ if (_SDL_GLView) {
+ _SDL_GLView->UnlockGL();
+ RemoveChild(_SDL_GLView); /* Why was this outside the if
+ statement before? */
+ }
+
+#endif
+ Unlock();
+#if SDL_VIDEO_OPENGL
+ if (_SDL_GLView) {
+ delete _SDL_GLView;
+ }
+#endif
+
+ delete _prev_frame;
+
+ /* Clean up framebuffer stuff */
+ _buffer_locker->Lock();
+#ifdef DRAWTHREAD
+ wait_for_thread(_draw_thread_id, &result);
+#endif
+ free(_clips);
+ delete _buffer_locker;
+ }
+
+
+ /* * * * * OpenGL functionality * * * * */
+#if SDL_VIDEO_OPENGL
+ virtual BGLView *CreateGLView(Uint32 gl_flags) {
+ Lock();
+ if (_SDL_GLView == NULL) {
+ _SDL_GLView = new BGLView(Bounds(), "SDL GLView",
+ B_FOLLOW_ALL_SIDES,
+ (B_WILL_DRAW | B_FRAME_EVENTS),
+ gl_flags);
+ _gl_type = gl_flags;
+ }
+ AddChild(_SDL_GLView);
+ _SDL_GLView->EnableDirectMode(true);
+ _SDL_GLView->LockGL(); /* "New" GLViews are created */
+ Unlock();
+ return (_SDL_GLView);
+ }
+
+ virtual void RemoveGLView() {
+ Lock();
+ if(_SDL_GLView) {
+ _SDL_GLView->UnlockGL();
+ RemoveChild(_SDL_GLView);
+ }
+ Unlock();
+ }
+
+ virtual void SwapBuffers(void) {
+ _SDL_GLView->UnlockGL();
+ _SDL_GLView->LockGL();
+ _SDL_GLView->SwapBuffers();
+ }
+#endif
+
+ /* * * * * Framebuffering* * * * */
+ virtual void DirectConnected(direct_buffer_info *info) {
+ if(!_connected && _connection_disabled) {
+ return;
+ }
+
+ /* Determine if the pixel buffer is usable after this update */
+ _trash_window_buffer = _trash_window_buffer
+ || ((info->buffer_state & B_BUFFER_RESIZED)
+ || (info->buffer_state & B_BUFFER_RESET)
+ || (info->driver_state == B_MODE_CHANGED));
+ LockBuffer();
+
+ switch(info->buffer_state & B_DIRECT_MODE_MASK) {
+ case B_DIRECT_START:
+ _connected = true;
+
+ case B_DIRECT_MODIFY:
+ if(_clips) {
+ free(_clips);
+ _clips = NULL;
+ }
+
+ _num_clips = info->clip_list_count;
+ _clips = (clipping_rect *)malloc(_num_clips*sizeof(clipping_rect));
+ if(_clips) {
+ memcpy(_clips, info->clip_list,
+ _num_clips*sizeof(clipping_rect));
+
+ _bits = (uint8*) info->bits;
+ _row_bytes = info->bytes_per_row;
+ _bounds = info->window_bounds;
+ _bytes_per_px = info->bits_per_pixel / 8;
+ _buffer_dirty = true;
+ }
+ break;
+
+ case B_DIRECT_STOP:
+ _connected = false;
+ break;
+ }
+#if SDL_VIDEO_OPENGL
+ if(_SDL_GLView) {
+ _SDL_GLView->DirectConnected(info);
+ }
+#endif
+
+
+ /* Call the base object directconnected */
+ BDirectWindow::DirectConnected(info);
+
+ UnlockBuffer();
+
+ }
+
+
+
+
+ /* * * * * Event sending * * * * */
+ /* Hook functions */
+ virtual void FrameMoved(BPoint origin) {
+ /* Post a message to the BApp so that it can handle the window event */
+ BMessage msg(BAPP_WINDOW_MOVED);
+ msg.AddInt32("window-x", (int)origin.x);
+ msg.AddInt32("window-y", (int)origin.y);
+ _PostWindowEvent(msg);
+
+ /* Perform normal hook operations */
+ BDirectWindow::FrameMoved(origin);
+ }
+
+ virtual void FrameResized(float width, float height) {
+ /* Post a message to the BApp so that it can handle the window event */
+ BMessage msg(BAPP_WINDOW_RESIZED);
+
+ msg.AddInt32("window-w", (int)width + 1);
+ msg.AddInt32("window-h", (int)height + 1);
+ _PostWindowEvent(msg);
+
+ /* Perform normal hook operations */
+ BDirectWindow::FrameResized(width, height);
+ }
+
+ virtual bool QuitRequested() {
+ BMessage msg(BAPP_WINDOW_CLOSE_REQUESTED);
+ _PostWindowEvent(msg);
+
+ /* We won't allow a quit unless asked by DestroyWindow() */
+ return false;
+ }
+
+ virtual void WindowActivated(bool active) {
+ BMessage msg(BAPP_KEYBOARD_FOCUS); /* Mouse focus sold separately */
+ msg.AddBool("focusGained", active);
+ _PostWindowEvent(msg);
+ }
+
+ virtual void Zoom(BPoint origin,
+ float width,
+ float height) {
+ BMessage msg(BAPP_MAXIMIZE); /* Closest thing to maximization Haiku has */
+ _PostWindowEvent(msg);
+
+ /* Before the window zooms, record its size */
+ if( !_prev_frame )
+ _prev_frame = new BRect(Frame());
+
+ /* Perform normal hook operations */
+ BDirectWindow::Zoom(origin, width, height);
+ }
+
+ /* Member functions */
+ virtual void Show() {
+ while(IsHidden()) {
+ BDirectWindow::Show();
+ }
+ _shown = true;
+
+ BMessage msg(BAPP_SHOW);
+ _PostWindowEvent(msg);
+ }
+
+ virtual void Hide() {
+ BDirectWindow::Hide();
+ _shown = false;
+
+ BMessage msg(BAPP_HIDE);
+ _PostWindowEvent(msg);
+ }
+
+ virtual void Minimize(bool minimize) {
+ BDirectWindow::Minimize(minimize);
+ int32 minState = (minimize ? BAPP_MINIMIZE : BAPP_RESTORE);
+
+ BMessage msg(minState);
+ _PostWindowEvent(msg);
+ }
+
+
+ /* BView message interruption */
+ virtual void DispatchMessage(BMessage * msg, BHandler * target)
+ {
+ BPoint where; /* Used by mouse moved */
+ int32 buttons; /* Used for mouse button events */
+ int32 key; /* Used for key events */
+
+ switch (msg->what) {
+ case B_MOUSE_MOVED:
+ int32 transit;
+ if (msg->FindPoint("where", &where) == B_OK
+ && msg->FindInt32("be:transit", &transit) == B_OK) {
+ _MouseMotionEvent(where, transit);
+ }
+
+ /* FIXME: Apparently a button press/release event might be dropped
+ if made before before a different button is released. Does
+ B_MOUSE_MOVED have the data needed to check if a mouse button
+ state has changed? */
+ if (msg->FindInt32("buttons", &buttons) == B_OK) {
+ _MouseButtonEvent(buttons);
+ }
+ break;
+
+ case B_MOUSE_DOWN:
+ case B_MOUSE_UP:
+ /* _MouseButtonEvent() detects any and all buttons that may have
+ changed state, as well as that button's new state */
+ if (msg->FindInt32("buttons", &buttons) == B_OK) {
+ _MouseButtonEvent(buttons);
+ }
+ break;
+
+ case B_MOUSE_WHEEL_CHANGED:
+ float x, y;
+ if (msg->FindFloat("be:wheel_delta_x", &x) == B_OK
+ && msg->FindFloat("be:wheel_delta_y", &y) == B_OK) {
+ _MouseWheelEvent((int)x, (int)y);
+ }
+ break;
+
+ case B_KEY_DOWN:
+ {
+ int32 i = 0;
+ int8 byte;
+ int8 bytes[4] = { 0, 0, 0, 0 };
+ while (i < 4 && msg->FindInt8("byte", i, &byte) == B_OK) {
+ bytes[i] = byte;
+ i++;
+ }
+ if (msg->FindInt32("key", &key) == B_OK) {
+ _KeyEvent((SDL_Scancode)key, &bytes[0], i, SDL_PRESSED);
+ }
+ }
+ break;
+
+ case B_UNMAPPED_KEY_DOWN: /* modifier keys are unmapped */
+ if (msg->FindInt32("key", &key) == B_OK) {
+ _KeyEvent((SDL_Scancode)key, NULL, 0, SDL_PRESSED);
+ }
+ break;
+
+ case B_KEY_UP:
+ case B_UNMAPPED_KEY_UP: /* modifier keys are unmapped */
+ if (msg->FindInt32("key", &key) == B_OK) {
+ _KeyEvent(key, NULL, 0, SDL_RELEASED);
+ }
+ break;
+
+ default:
+ /* move it after switch{} so it's always handled
+ that way we keep Haiku features like:
+ - CTRL+Q to close window (and other shortcuts)
+ - PrintScreen to make screenshot into /boot/home
+ - etc.. */
+ /* BDirectWindow::DispatchMessage(msg, target); */
+ break;
+ }
+
+ BDirectWindow::DispatchMessage(msg, target);
+ }
+
+ /* Handle command messages */
+ virtual void MessageReceived(BMessage* message) {
+ switch (message->what) {
+ /* Handle commands from SDL */
+ case BWIN_SET_TITLE:
+ _SetTitle(message);
+ break;
+ case BWIN_MOVE_WINDOW:
+ _MoveTo(message);
+ break;
+ case BWIN_RESIZE_WINDOW:
+ _ResizeTo(message);
+ break;
+ case BWIN_SET_BORDERED:
+ _SetBordered(message);
+ break;
+ case BWIN_SET_RESIZABLE:
+ _SetResizable(message);
+ break;
+ case BWIN_SHOW_WINDOW:
+ Show();
+ break;
+ case BWIN_HIDE_WINDOW:
+ Hide();
+ break;
+ case BWIN_MAXIMIZE_WINDOW:
+ BWindow::Zoom();
+ break;
+ case BWIN_MINIMIZE_WINDOW:
+ Minimize(true);
+ break;
+ case BWIN_RESTORE_WINDOW:
+ _Restore();
+ break;
+ case BWIN_FULLSCREEN:
+ _SetFullScreen(message);
+ break;
+ default:
+ /* Perform normal message handling */
+ BDirectWindow::MessageReceived(message);
+ break;
+ }
+
+ }
+
+
+
+ /* Accessor methods */
+ bool IsShown() { return _shown; }
+ int32 GetID() { return _id; }
+ uint32 GetRowBytes() { return _row_bytes; }
+ int32 GetFbX() { return _bounds.left; }
+ int32 GetFbY() { return _bounds.top; }
+ bool ConnectionEnabled() { return !_connection_disabled; }
+ bool Connected() { return _connected; }
+ clipping_rect *GetClips() { return _clips; }
+ int32 GetNumClips() { return _num_clips; }
+ uint8* GetBufferPx() { return _bits; }
+ int32 GetBytesPerPx() { return _bytes_per_px; }
+ bool CanTrashWindowBuffer() { return _trash_window_buffer; }
+ bool BufferExists() { return _buffer_created; }
+ bool BufferIsDirty() { return _buffer_dirty; }
+ BBitmap *GetBitmap() { return _bitmap; }
+#if SDL_VIDEO_OPENGL
+ BGLView *GetGLView() { return _SDL_GLView; }
+ Uint32 GetGLType() { return _gl_type; }
+#endif
+
+ /* Setter methods */
+ void SetID(int32 id) { _id = id; }
+ void SetBufferExists(bool bufferExists) { _buffer_created = bufferExists; }
+ void LockBuffer() { _buffer_locker->Lock(); }
+ void UnlockBuffer() { _buffer_locker->Unlock(); }
+ void SetBufferDirty(bool bufferDirty) { _buffer_dirty = bufferDirty; }
+ void SetTrashBuffer(bool trash) { _trash_window_buffer = trash; }
+ void SetBitmap(BBitmap *bitmap) { _bitmap = bitmap; }
+
+
+private:
+ /* Event redirection */
+ void _MouseMotionEvent(BPoint &where, int32 transit) {
+ if(transit == B_EXITED_VIEW) {
+ /* Change mouse focus */
+ if(_mouse_focused) {
+ _MouseFocusEvent(false);
+ }
+ } else {
+ /* Change mouse focus */
+ if (!_mouse_focused) {
+ _MouseFocusEvent(true);
+ }
+ BMessage msg(BAPP_MOUSE_MOVED);
+ msg.AddInt32("x", (int)where.x);
+ msg.AddInt32("y", (int)where.y);
+
+ _PostWindowEvent(msg);
+ }
+ }
+
+ void _MouseFocusEvent(bool focusGained) {
+ _mouse_focused = focusGained;
+ BMessage msg(BAPP_MOUSE_FOCUS);
+ msg.AddBool("focusGained", focusGained);
+ _PostWindowEvent(msg);
+
+/* FIXME: Why were these here?
+ if false: be_app->SetCursor(B_HAND_CURSOR);
+ if true: SDL_SetCursor(NULL); */
+ }
+
+ void _MouseButtonEvent(int32 buttons) {
+ int32 buttonStateChange = buttons ^ _last_buttons;
+
+ /* Make sure at least one button has changed state */
+ if( !(buttonStateChange) ) {
+ return;
+ }
+
+ /* Add any mouse button events */
+ if(buttonStateChange & B_PRIMARY_MOUSE_BUTTON) {
+ _SendMouseButton(SDL_BUTTON_LEFT, buttons &
+ B_PRIMARY_MOUSE_BUTTON);
+ }
+ if(buttonStateChange & B_SECONDARY_MOUSE_BUTTON) {
+ _SendMouseButton(SDL_BUTTON_RIGHT, buttons &
+ B_PRIMARY_MOUSE_BUTTON);
+ }
+ if(buttonStateChange & B_TERTIARY_MOUSE_BUTTON) {
+ _SendMouseButton(SDL_BUTTON_MIDDLE, buttons &
+ B_PRIMARY_MOUSE_BUTTON);
+ }
+
+ _last_buttons = buttons;
+ }
+
+ void _SendMouseButton(int32 button, int32 state) {
+ BMessage msg(BAPP_MOUSE_BUTTON);
+ msg.AddInt32("button-id", button);
+ msg.AddInt32("button-state", state);
+ _PostWindowEvent(msg);
+ }
+
+ void _MouseWheelEvent(int32 x, int32 y) {
+ /* Create a message to pass along to the BeApp thread */
+ BMessage msg(BAPP_MOUSE_WHEEL);
+ msg.AddInt32("xticks", x);
+ msg.AddInt32("yticks", y);
+ _PostWindowEvent(msg);
+ }
+
+ void _KeyEvent(int32 keyCode, const int8 *keyUtf8, const ssize_t & len, int32 keyState) {
+ /* Create a message to pass along to the BeApp thread */
+ BMessage msg(BAPP_KEY);
+ msg.AddInt32("key-state", keyState);
+ msg.AddInt32("key-scancode", keyCode);
+ if (keyUtf8 != NULL) {
+ msg.AddData("key-utf8", B_INT8_TYPE, (const void*)keyUtf8, len);
+ }
+ be_app->PostMessage(&msg);
+ }
+
+ void _RepaintEvent() {
+ /* Force a repaint: Call the SDL exposed event */
+ BMessage msg(BAPP_REPAINT);
+ _PostWindowEvent(msg);
+ }
+ void _PostWindowEvent(BMessage &msg) {
+ msg.AddInt32("window-id", _id);
+ be_app->PostMessage(&msg);
+ }
+
+ /* Command methods (functions called upon by SDL) */
+ void _SetTitle(BMessage *msg) {
+ const char *title;
+ if(
+ msg->FindString("window-title", &title) != B_OK
+ ) {
+ return;
+ }
+ SetTitle(title);
+ }
+
+ void _MoveTo(BMessage *msg) {
+ int32 x, y;
+ if(
+ msg->FindInt32("window-x", &x) != B_OK ||
+ msg->FindInt32("window-y", &y) != B_OK
+ ) {
+ return;
+ }
+ MoveTo(x, y);
+ }
+
+ void _ResizeTo(BMessage *msg) {
+ int32 w, h;
+ if(
+ msg->FindInt32("window-w", &w) != B_OK ||
+ msg->FindInt32("window-h", &h) != B_OK
+ ) {
+ return;
+ }
+ ResizeTo(w, h);
+ }
+
+ void _SetBordered(BMessage *msg) {
+ bool bEnabled;
+ if(msg->FindBool("window-border", &bEnabled) != B_OK) {
+ return;
+ }
+ SetLook(bEnabled ? B_TITLED_WINDOW_LOOK : B_NO_BORDER_WINDOW_LOOK);
+ }
+
+ void _SetResizable(BMessage *msg) {
+ bool bEnabled;
+ if(msg->FindBool("window-resizable", &bEnabled) != B_OK) {
+ return;
+ }
+ if (bEnabled) {
+ SetFlags(Flags() & ~(B_NOT_RESIZABLE | B_NOT_ZOOMABLE));
+ } else {
+ SetFlags(Flags() | (B_NOT_RESIZABLE | B_NOT_ZOOMABLE));
+ }
+ }
+
+ void _Restore() {
+ if(IsMinimized()) {
+ Minimize(false);
+ } else if(IsHidden()) {
+ Show();
+ } else if(_prev_frame != NULL) { /* Zoomed */
+ MoveTo(_prev_frame->left, _prev_frame->top);
+ ResizeTo(_prev_frame->Width(), _prev_frame->Height());
+ }
+ }
+
+ void _SetFullScreen(BMessage *msg) {
+ bool fullscreen;
+ if(
+ msg->FindBool("fullscreen", &fullscreen) != B_OK
+ ) {
+ return;
+ }
+ SetFullScreen(fullscreen);
+ }
+
+ /* Members */
+#if SDL_VIDEO_OPENGL
+ BGLView * _SDL_GLView;
+ Uint32 _gl_type;
+#endif
+
+ int32 _last_buttons;
+ int32 _id; /* Window id used by SDL_BApp */
+ bool _mouse_focused; /* Does this window have mouse focus? */
+ bool _shown;
+ bool _inhibit_resize;
+
+ BRect *_prev_frame; /* Previous position and size of the window */
+
+ /* Framebuffer members */
+ bool _connected,
+ _connection_disabled,
+ _buffer_created,
+ _buffer_dirty,
+ _trash_window_buffer;
+ uint8 *_bits;
+ uint32 _row_bytes;
+ clipping_rect _bounds;
+ BLocker *_buffer_locker;
+ clipping_rect *_clips;
+ int32 _num_clips;
+ int32 _bytes_per_px;
+ thread_id _draw_thread_id;
+
+ BBitmap *_bitmap;
+};
+
+
+/* FIXME:
+ * An explanation of framebuffer flags.
+ *
+ * _connected - Original variable used to let the drawing thread know
+ * when changes are being made to the other framebuffer
+ * members.
+ * _connection_disabled - Used to signal to the drawing thread that the window
+ * is closing, and the thread should exit.
+ * _buffer_created - True if the current buffer is valid
+ * _buffer_dirty - True if the window should be redrawn.
+ * _trash_window_buffer - True if the window buffer needs to be trashed partway
+ * through a draw cycle. Occurs when the previous
+ * buffer provided by DirectConnected() is invalidated.
+ */
+#endif /* SDL_BWin_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/haiku/SDL_bclipboard.cc b/src/3rdparty/SDL2/src/video/haiku/SDL_bclipboard.cc
new file mode 100644
index 0000000..e7d01b9
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/haiku/SDL_bclipboard.cc
@@ -0,0 +1,95 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_HAIKU
+
+/* BWindow based clipboard implementation */
+
+#include <unistd.h>
+#include <TypeConstants.h>
+
+#include "SDL_BWin.h"
+#include "SDL_timer.h"
+#include "../SDL_sysvideo.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int BE_SetClipboardText(_THIS, const char *text) {
+ BMessage *clip = NULL;
+ if(be_clipboard->Lock()) {
+ be_clipboard->Clear();
+ if((clip = be_clipboard->Data())) {
+ /* Presumably the string of characters is ascii-format */
+ ssize_t asciiLength = 0;
+ for(; text[asciiLength] != 0; ++asciiLength) {}
+ clip->AddData("text/plain", B_MIME_TYPE, text, asciiLength);
+ be_clipboard->Commit();
+ }
+ be_clipboard->Unlock();
+ }
+ return 0;
+}
+
+char *BE_GetClipboardText(_THIS) {
+ BMessage *clip = NULL;
+ const char *text = NULL;
+ ssize_t length;
+ char *result;
+ if(be_clipboard->Lock()) {
+ if((clip = be_clipboard->Data())) {
+ /* Presumably the string of characters is ascii-format */
+ clip->FindData("text/plain", B_MIME_TYPE, (const void**)&text,
+ &length);
+ }
+ be_clipboard->Unlock();
+ }
+
+ if (!text) {
+ result = SDL_strdup("");
+ } else {
+ /* Copy the data and pass on to SDL */
+ result = (char *)SDL_malloc((length + 1) * sizeof(char));
+ SDL_strlcpy(result, text, length + 1);
+ }
+
+ return result;
+}
+
+SDL_bool BE_HasClipboardText(_THIS) {
+ SDL_bool result = SDL_FALSE;
+ char *text = BE_GetClipboardText(_this);
+ if (text) {
+ result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
+ SDL_free(text);
+ }
+ return result;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SDL_VIDEO_DRIVER_HAIKU */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/haiku/SDL_bclipboard.h b/src/3rdparty/SDL2/src/video/haiku/SDL_bclipboard.h
new file mode 100644
index 0000000..2f7a1c2
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/haiku/SDL_bclipboard.h
@@ -0,0 +1,33 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_BCLIPBOARD_H
+#define SDL_BCLIPBOARD_H
+
+extern int BE_SetClipboardText(_THIS, const char *text);
+extern char *BE_GetClipboardText(_THIS);
+extern SDL_bool BE_HasClipboardText(_THIS);
+
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/haiku/SDL_bevents.cc b/src/3rdparty/SDL2/src/video/haiku/SDL_bevents.cc
new file mode 100644
index 0000000..c716731
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/haiku/SDL_bevents.cc
@@ -0,0 +1,41 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_HAIKU
+
+#include "SDL_bevents.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void BE_PumpEvents(_THIS) {
+ /* Since the event thread is its own thread, this isn't really necessary */
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SDL_VIDEO_DRIVER_HAIKU */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/haiku/SDL_bevents.h b/src/3rdparty/SDL2/src/video/haiku/SDL_bevents.h
new file mode 100644
index 0000000..3c090c8
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/haiku/SDL_bevents.h
@@ -0,0 +1,39 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_BEVENTS_H
+#define SDL_BEVENTS_H
+
+#include "../SDL_sysvideo.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void BE_PumpEvents(_THIS);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/haiku/SDL_bframebuffer.cc b/src/3rdparty/SDL2/src/video/haiku/SDL_bframebuffer.cc
new file mode 100644
index 0000000..f53c500
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/haiku/SDL_bframebuffer.cc
@@ -0,0 +1,259 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_HAIKU
+
+#include "SDL_bframebuffer.h"
+
+#include <AppKit.h>
+#include <InterfaceKit.h>
+#include "SDL_bmodes.h"
+#include "SDL_BWin.h"
+
+#include "../../main/haiku/SDL_BApp.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef DRAWTHREAD
+static int32 BE_UpdateOnce(SDL_Window *window);
+#endif
+
+static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
+ return ((SDL_BWin*)(window->driverdata));
+}
+
+static SDL_INLINE SDL_BApp *_GetBeApp() {
+ return ((SDL_BApp*)be_app);
+}
+
+int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,
+ Uint32 * format,
+ void ** pixels, int *pitch) {
+ SDL_BWin *bwin = _ToBeWin(window);
+ BScreen bscreen;
+ if(!bscreen.IsValid()) {
+ return -1;
+ }
+
+ while(!bwin->Connected()) { snooze(100); }
+
+ /* Make sure we have exclusive access to frame buffer data */
+ bwin->LockBuffer();
+
+ /* format */
+ display_mode bmode;
+ bscreen.GetMode(&bmode);
+ int32 bpp = BE_ColorSpaceToBitsPerPixel(bmode.space);
+ *format = BE_BPPToSDLPxFormat(bpp);
+
+ /* Create the new bitmap object */
+ BBitmap *bitmap = bwin->GetBitmap();
+
+ if(bitmap) {
+ delete bitmap;
+ }
+ bitmap = new BBitmap(bwin->Bounds(), (color_space)bmode.space,
+ false, /* Views not accepted */
+ true); /* Contiguous memory required */
+
+ if(bitmap->InitCheck() != B_OK) {
+ delete bitmap;
+ return SDL_SetError("Could not initialize back buffer!");
+ }
+
+
+ bwin->SetBitmap(bitmap);
+
+ /* Set the pixel pointer */
+ *pixels = bitmap->Bits();
+
+ /* pitch = width of window, in bytes */
+ *pitch = bitmap->BytesPerRow();
+
+ bwin->SetBufferExists(true);
+ bwin->SetTrashBuffer(false);
+ bwin->UnlockBuffer();
+ return 0;
+}
+
+
+
+int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
+ const SDL_Rect * rects, int numrects) {
+ if(!window)
+ return 0;
+
+ SDL_BWin *bwin = _ToBeWin(window);
+
+#ifdef DRAWTHREAD
+ bwin->LockBuffer();
+ bwin->SetBufferDirty(true);
+ bwin->UnlockBuffer();
+#else
+ bwin->SetBufferDirty(true);
+ BE_UpdateOnce(window);
+#endif
+
+ return 0;
+}
+
+int32 BE_DrawThread(void *data) {
+ SDL_BWin *bwin = (SDL_BWin*)data;
+
+ BScreen bscreen;
+ if(!bscreen.IsValid()) {
+ return -1;
+ }
+
+ while(bwin->ConnectionEnabled()) {
+ if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) {
+ bwin->LockBuffer();
+ BBitmap *bitmap = NULL;
+ bitmap = bwin->GetBitmap();
+ int32 windowPitch = bitmap->BytesPerRow();
+ int32 bufferPitch = bwin->GetRowBytes();
+ uint8 *windowpx;
+ uint8 *bufferpx;
+
+ int32 BPP = bwin->GetBytesPerPx();
+ int32 windowSub = bwin->GetFbX() * BPP +
+ bwin->GetFbY() * windowPitch;
+ clipping_rect *clips = bwin->GetClips();
+ int32 numClips = bwin->GetNumClips();
+ int i, y;
+
+ /* Blit each clipping rectangle */
+ bscreen.WaitForRetrace();
+ for(i = 0; i < numClips; ++i) {
+ /* Get addresses of the start of each clipping rectangle */
+ int32 width = clips[i].right - clips[i].left + 1;
+ int32 height = clips[i].bottom - clips[i].top + 1;
+ bufferpx = bwin->GetBufferPx() +
+ clips[i].top * bufferPitch + clips[i].left * BPP;
+ windowpx = (uint8*)bitmap->Bits() +
+ clips[i].top * windowPitch + clips[i].left * BPP -
+ windowSub;
+
+ /* Copy each row of pixels from the window buffer into the frame
+ buffer */
+ for(y = 0; y < height; ++y)
+ {
+
+ if(bwin->CanTrashWindowBuffer()) {
+ goto escape; /* Break out before the buffer is killed */
+ }
+
+ memcpy(bufferpx, windowpx, width * BPP);
+ bufferpx += bufferPitch;
+ windowpx += windowPitch;
+ }
+ }
+
+ bwin->SetBufferDirty(false);
+escape:
+ bwin->UnlockBuffer();
+ } else {
+ snooze(16000);
+ }
+ }
+
+ return B_OK;
+}
+
+void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window) {
+ SDL_BWin *bwin = _ToBeWin(window);
+
+ bwin->LockBuffer();
+
+ /* Free and clear the window buffer */
+ BBitmap *bitmap = bwin->GetBitmap();
+ delete bitmap;
+ bwin->SetBitmap(NULL);
+ bwin->SetBufferExists(false);
+ bwin->UnlockBuffer();
+}
+
+
+/*
+ * TODO:
+ * This was written to test if certain errors were caused by threading issues.
+ * The specific issues have since become rare enough that they may have been
+ * solved, but I doubt it- they were pretty sporadic before now.
+ */
+#ifndef DRAWTHREAD
+static int32 BE_UpdateOnce(SDL_Window *window) {
+ SDL_BWin *bwin = _ToBeWin(window);
+ BScreen bscreen;
+ if(!bscreen.IsValid()) {
+ return -1;
+ }
+
+ if(bwin->ConnectionEnabled() && bwin->Connected()) {
+ bwin->LockBuffer();
+ int32 windowPitch = window->surface->pitch;
+ int32 bufferPitch = bwin->GetRowBytes();
+ uint8 *windowpx;
+ uint8 *bufferpx;
+
+ int32 BPP = bwin->GetBytesPerPx();
+ uint8 *windowBaseAddress = (uint8*)window->surface->pixels;
+ int32 windowSub = bwin->GetFbX() * BPP +
+ bwin->GetFbY() * windowPitch;
+ clipping_rect *clips = bwin->GetClips();
+ int32 numClips = bwin->GetNumClips();
+ int i, y;
+
+ /* Blit each clipping rectangle */
+ bscreen.WaitForRetrace();
+ for(i = 0; i < numClips; ++i) {
+ /* Get addresses of the start of each clipping rectangle */
+ int32 width = clips[i].right - clips[i].left + 1;
+ int32 height = clips[i].bottom - clips[i].top + 1;
+ bufferpx = bwin->GetBufferPx() +
+ clips[i].top * bufferPitch + clips[i].left * BPP;
+ windowpx = windowBaseAddress +
+ clips[i].top * windowPitch + clips[i].left * BPP - windowSub;
+
+ /* Copy each row of pixels from the window buffer into the frame
+ buffer */
+ for(y = 0; y < height; ++y)
+ {
+ memcpy(bufferpx, windowpx, width * BPP);
+ bufferpx += bufferPitch;
+ windowpx += windowPitch;
+ }
+ }
+ bwin->UnlockBuffer();
+ }
+ return 0;
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SDL_VIDEO_DRIVER_HAIKU */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/haiku/SDL_bframebuffer.h b/src/3rdparty/SDL2/src/video/haiku/SDL_bframebuffer.h
new file mode 100644
index 0000000..ce0fc62
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/haiku/SDL_bframebuffer.h
@@ -0,0 +1,47 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_BFRAMEBUFFER_H
+#define SDL_BFRAMEBUFFER_H
+#include <SupportDefs.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define DRAWTHREAD
+
+#include "../SDL_sysvideo.h"
+
+extern int BE_CreateWindowFramebuffer(_THIS, SDL_Window * window,
+ Uint32 * format,
+ void ** pixels, int *pitch);
+extern int BE_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
+ const SDL_Rect * rects, int numrects);
+extern void BE_DestroyWindowFramebuffer(_THIS, SDL_Window * window);
+extern int32 BE_DrawThread(void *data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/haiku/SDL_bkeyboard.cc b/src/3rdparty/SDL2/src/video/haiku/SDL_bkeyboard.cc
new file mode 100644
index 0000000..5c72ecf
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/haiku/SDL_bkeyboard.cc
@@ -0,0 +1,190 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_HAIKU
+
+#include <SupportDefs.h>
+#include <support/UTF8.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "SDL_events.h"
+#include "SDL_keycode.h"
+
+#include "SDL_bkeyboard.h"
+
+
+#define KEYMAP_SIZE 128
+
+
+static SDL_Scancode keymap[KEYMAP_SIZE];
+static int8 keystate[KEYMAP_SIZE];
+
+void BE_InitOSKeymap(void) {
+ for( uint i = 0; i < SDL_TABLESIZE(keymap); ++i ) {
+ keymap[i] = SDL_SCANCODE_UNKNOWN;
+ }
+
+ for( uint i = 0; i < KEYMAP_SIZE; ++i ) {
+ keystate[i] = SDL_RELEASED;
+ }
+
+ keymap[0x01] = SDL_GetScancodeFromKey(SDLK_ESCAPE);
+ keymap[B_F1_KEY] = SDL_GetScancodeFromKey(SDLK_F1);
+ keymap[B_F2_KEY] = SDL_GetScancodeFromKey(SDLK_F2);
+ keymap[B_F3_KEY] = SDL_GetScancodeFromKey(SDLK_F3);
+ keymap[B_F4_KEY] = SDL_GetScancodeFromKey(SDLK_F4);
+ keymap[B_F5_KEY] = SDL_GetScancodeFromKey(SDLK_F5);
+ keymap[B_F6_KEY] = SDL_GetScancodeFromKey(SDLK_F6);
+ keymap[B_F7_KEY] = SDL_GetScancodeFromKey(SDLK_F7);
+ keymap[B_F8_KEY] = SDL_GetScancodeFromKey(SDLK_F8);
+ keymap[B_F9_KEY] = SDL_GetScancodeFromKey(SDLK_F9);
+ keymap[B_F10_KEY] = SDL_GetScancodeFromKey(SDLK_F10);
+ keymap[B_F11_KEY] = SDL_GetScancodeFromKey(SDLK_F11);
+ keymap[B_F12_KEY] = SDL_GetScancodeFromKey(SDLK_F12);
+ keymap[B_PRINT_KEY] = SDL_GetScancodeFromKey(SDLK_PRINTSCREEN);
+ keymap[B_SCROLL_KEY] = SDL_GetScancodeFromKey(SDLK_SCROLLLOCK);
+ keymap[B_PAUSE_KEY] = SDL_GetScancodeFromKey(SDLK_PAUSE);
+ keymap[0x11] = SDL_GetScancodeFromKey(SDLK_BACKQUOTE);
+ keymap[0x12] = SDL_GetScancodeFromKey(SDLK_1);
+ keymap[0x13] = SDL_GetScancodeFromKey(SDLK_2);
+ keymap[0x14] = SDL_GetScancodeFromKey(SDLK_3);
+ keymap[0x15] = SDL_GetScancodeFromKey(SDLK_4);
+ keymap[0x16] = SDL_GetScancodeFromKey(SDLK_5);
+ keymap[0x17] = SDL_GetScancodeFromKey(SDLK_6);
+ keymap[0x18] = SDL_GetScancodeFromKey(SDLK_7);
+ keymap[0x19] = SDL_GetScancodeFromKey(SDLK_8);
+ keymap[0x1a] = SDL_GetScancodeFromKey(SDLK_9);
+ keymap[0x1b] = SDL_GetScancodeFromKey(SDLK_0);
+ keymap[0x1c] = SDL_GetScancodeFromKey(SDLK_MINUS);
+ keymap[0x1d] = SDL_GetScancodeFromKey(SDLK_EQUALS);
+ keymap[0x1e] = SDL_GetScancodeFromKey(SDLK_BACKSPACE);
+ keymap[0x1f] = SDL_GetScancodeFromKey(SDLK_INSERT);
+ keymap[0x20] = SDL_GetScancodeFromKey(SDLK_HOME);
+ keymap[0x21] = SDL_GetScancodeFromKey(SDLK_PAGEUP);
+ keymap[0x22] = SDL_GetScancodeFromKey(SDLK_NUMLOCKCLEAR);
+ keymap[0x23] = SDL_GetScancodeFromKey(SDLK_KP_DIVIDE);
+ keymap[0x24] = SDL_GetScancodeFromKey(SDLK_KP_MULTIPLY);
+ keymap[0x25] = SDL_GetScancodeFromKey(SDLK_KP_MINUS);
+ keymap[0x26] = SDL_GetScancodeFromKey(SDLK_TAB);
+ keymap[0x27] = SDL_GetScancodeFromKey(SDLK_q);
+ keymap[0x28] = SDL_GetScancodeFromKey(SDLK_w);
+ keymap[0x29] = SDL_GetScancodeFromKey(SDLK_e);
+ keymap[0x2a] = SDL_GetScancodeFromKey(SDLK_r);
+ keymap[0x2b] = SDL_GetScancodeFromKey(SDLK_t);
+ keymap[0x2c] = SDL_GetScancodeFromKey(SDLK_y);
+ keymap[0x2d] = SDL_GetScancodeFromKey(SDLK_u);
+ keymap[0x2e] = SDL_GetScancodeFromKey(SDLK_i);
+ keymap[0x2f] = SDL_GetScancodeFromKey(SDLK_o);
+ keymap[0x30] = SDL_GetScancodeFromKey(SDLK_p);
+ keymap[0x31] = SDL_GetScancodeFromKey(SDLK_LEFTBRACKET);
+ keymap[0x32] = SDL_GetScancodeFromKey(SDLK_RIGHTBRACKET);
+ keymap[0x33] = SDL_GetScancodeFromKey(SDLK_BACKSLASH);
+ keymap[0x34] = SDL_GetScancodeFromKey(SDLK_DELETE);
+ keymap[0x35] = SDL_GetScancodeFromKey(SDLK_END);
+ keymap[0x36] = SDL_GetScancodeFromKey(SDLK_PAGEDOWN);
+ keymap[0x37] = SDL_GetScancodeFromKey(SDLK_KP_7);
+ keymap[0x38] = SDL_GetScancodeFromKey(SDLK_KP_8);
+ keymap[0x39] = SDL_GetScancodeFromKey(SDLK_KP_9);
+ keymap[0x3a] = SDL_GetScancodeFromKey(SDLK_KP_PLUS);
+ keymap[0x3b] = SDL_GetScancodeFromKey(SDLK_CAPSLOCK);
+ keymap[0x3c] = SDL_GetScancodeFromKey(SDLK_a);
+ keymap[0x3d] = SDL_GetScancodeFromKey(SDLK_s);
+ keymap[0x3e] = SDL_GetScancodeFromKey(SDLK_d);
+ keymap[0x3f] = SDL_GetScancodeFromKey(SDLK_f);
+ keymap[0x40] = SDL_GetScancodeFromKey(SDLK_g);
+ keymap[0x41] = SDL_GetScancodeFromKey(SDLK_h);
+ keymap[0x42] = SDL_GetScancodeFromKey(SDLK_j);
+ keymap[0x43] = SDL_GetScancodeFromKey(SDLK_k);
+ keymap[0x44] = SDL_GetScancodeFromKey(SDLK_l);
+ keymap[0x45] = SDL_GetScancodeFromKey(SDLK_SEMICOLON);
+ keymap[0x46] = SDL_GetScancodeFromKey(SDLK_QUOTE);
+ keymap[0x47] = SDL_GetScancodeFromKey(SDLK_RETURN);
+ keymap[0x48] = SDL_GetScancodeFromKey(SDLK_KP_4);
+ keymap[0x49] = SDL_GetScancodeFromKey(SDLK_KP_5);
+ keymap[0x4a] = SDL_GetScancodeFromKey(SDLK_KP_6);
+ keymap[0x4b] = SDL_GetScancodeFromKey(SDLK_LSHIFT);
+ keymap[0x4c] = SDL_GetScancodeFromKey(SDLK_z);
+ keymap[0x4d] = SDL_GetScancodeFromKey(SDLK_x);
+ keymap[0x4e] = SDL_GetScancodeFromKey(SDLK_c);
+ keymap[0x4f] = SDL_GetScancodeFromKey(SDLK_v);
+ keymap[0x50] = SDL_GetScancodeFromKey(SDLK_b);
+ keymap[0x51] = SDL_GetScancodeFromKey(SDLK_n);
+ keymap[0x52] = SDL_GetScancodeFromKey(SDLK_m);
+ keymap[0x53] = SDL_GetScancodeFromKey(SDLK_COMMA);
+ keymap[0x54] = SDL_GetScancodeFromKey(SDLK_PERIOD);
+ keymap[0x55] = SDL_GetScancodeFromKey(SDLK_SLASH);
+ keymap[0x56] = SDL_GetScancodeFromKey(SDLK_RSHIFT);
+ keymap[0x57] = SDL_GetScancodeFromKey(SDLK_UP);
+ keymap[0x58] = SDL_GetScancodeFromKey(SDLK_KP_1);
+ keymap[0x59] = SDL_GetScancodeFromKey(SDLK_KP_2);
+ keymap[0x5a] = SDL_GetScancodeFromKey(SDLK_KP_3);
+ keymap[0x5b] = SDL_GetScancodeFromKey(SDLK_KP_ENTER);
+ keymap[0x5c] = SDL_GetScancodeFromKey(SDLK_LCTRL);
+ keymap[0x5d] = SDL_GetScancodeFromKey(SDLK_LALT);
+ keymap[0x5e] = SDL_GetScancodeFromKey(SDLK_SPACE);
+ keymap[0x5f] = SDL_GetScancodeFromKey(SDLK_RALT);
+ keymap[0x60] = SDL_GetScancodeFromKey(SDLK_RCTRL);
+ keymap[0x61] = SDL_GetScancodeFromKey(SDLK_LEFT);
+ keymap[0x62] = SDL_GetScancodeFromKey(SDLK_DOWN);
+ keymap[0x63] = SDL_GetScancodeFromKey(SDLK_RIGHT);
+ keymap[0x64] = SDL_GetScancodeFromKey(SDLK_KP_0);
+ keymap[0x65] = SDL_GetScancodeFromKey(SDLK_KP_PERIOD);
+ keymap[0x66] = SDL_GetScancodeFromKey(SDLK_LGUI);
+ keymap[0x67] = SDL_GetScancodeFromKey(SDLK_RGUI);
+ keymap[0x68] = SDL_GetScancodeFromKey(SDLK_MENU);
+ keymap[0x69] = SDL_GetScancodeFromKey(SDLK_2); /* SDLK_EURO */
+ keymap[0x6a] = SDL_GetScancodeFromKey(SDLK_KP_EQUALS);
+ keymap[0x6b] = SDL_GetScancodeFromKey(SDLK_POWER);
+}
+
+SDL_Scancode BE_GetScancodeFromBeKey(int32 bkey) {
+ if(bkey > 0 && bkey < (int32)SDL_TABLESIZE(keymap)) {
+ return keymap[bkey];
+ } else {
+ return SDL_SCANCODE_UNKNOWN;
+ }
+}
+
+int8 BE_GetKeyState(int32 bkey) {
+ if(bkey > 0 && bkey < KEYMAP_SIZE) {
+ return keystate[bkey];
+ } else {
+ return SDL_RELEASED;
+ }
+}
+
+void BE_SetKeyState(int32 bkey, int8 state) {
+ if(bkey > 0 && bkey < KEYMAP_SIZE) {
+ keystate[bkey] = state;
+ }
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SDL_VIDEO_DRIVER_HAIKU */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/haiku/SDL_bkeyboard.h b/src/3rdparty/SDL2/src/video/haiku/SDL_bkeyboard.h
new file mode 100644
index 0000000..9620c9b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/haiku/SDL_bkeyboard.h
@@ -0,0 +1,44 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_BKEYBOARD_H
+#define SDL_BKEYBOARD_H
+
+#include <SupportDefs.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "../../../include/SDL_keyboard.h"
+
+extern void BE_InitOSKeymap(void);
+extern SDL_Scancode BE_GetScancodeFromBeKey(int32 bkey);
+extern int8 BE_GetKeyState(int32 bkey);
+extern void BE_SetKeyState(int32 bkey, int8 state);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/haiku/SDL_bmodes.cc b/src/3rdparty/SDL2/src/video/haiku/SDL_bmodes.cc
new file mode 100644
index 0000000..1105342
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/haiku/SDL_bmodes.cc
@@ -0,0 +1,333 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_HAIKU
+
+#include <AppKit.h>
+#include <InterfaceKit.h>
+#include "SDL_bmodes.h"
+#include "SDL_BWin.h"
+
+#if SDL_VIDEO_OPENGL
+#include "SDL_bopengl.h"
+#endif
+
+#include "../../main/haiku/SDL_BApp.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#define WRAP_BMODE 1 /* FIXME: Some debate as to whether this is necessary */
+
+#if WRAP_BMODE
+/* This wrapper is here so that the driverdata can be freed without freeing
+ the display_mode structure */
+struct SDL_DisplayModeData {
+ display_mode *bmode;
+};
+#endif
+
+static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
+ return ((SDL_BWin*)(window->driverdata));
+}
+
+static SDL_INLINE SDL_BApp *_GetBeApp() {
+ return ((SDL_BApp*)be_app);
+}
+
+static SDL_INLINE display_mode * _ExtractBMode(SDL_DisplayMode *mode) {
+#if WRAP_BMODE
+ return ((SDL_DisplayModeData*)mode->driverdata)->bmode;
+#else
+ return (display_mode*)(mode->driverdata);
+#endif
+}
+
+/* Copied from haiku/trunk/src/preferences/screen/ScreenMode.cpp */
+static float get_refresh_rate(display_mode &mode) {
+ return float(mode.timing.pixel_clock * 1000)
+ / float(mode.timing.h_total * mode.timing.v_total);
+}
+
+
+#if 0
+/* TODO:
+ * This is a useful debugging tool. Uncomment and insert into code as needed.
+ */
+void _SpoutModeData(display_mode *bmode) {
+ printf("BMode:\n");
+ printf("\tw,h = (%i,%i)\n", bmode->virtual_width, bmode->virtual_height);
+ printf("\th,v = (%i,%i)\n", bmode->h_display_start,
+ bmode->v_display_start);
+ if(bmode->flags) {
+ printf("\tFlags:\n");
+ if(bmode->flags & B_SCROLL) {
+ printf("\t\tB_SCROLL\n");
+ }
+ if(bmode->flags & B_8_BIT_DAC) {
+ printf("\t\tB_8_BIT_DAC\n");
+ }
+ if(bmode->flags & B_HARDWARE_CURSOR) {
+ printf("\t\tB_HARDWARE_CURSOR\n");
+ }
+ if(bmode->flags & B_PARALLEL_ACCESS) {
+ printf("\t\tB_PARALLEL_ACCESS\n");
+ }
+ if(bmode->flags & B_DPMS) {
+ printf("\t\tB_DPMS\n");
+ }
+ if(bmode->flags & B_IO_FB_NA) {
+ printf("\t\tB_IO_FB_NA\n");
+ }
+ }
+ printf("\tTiming:\n");
+ printf("\t\tpx clock: %i\n", bmode->timing.pixel_clock);
+ printf("\t\th - display: %i sync start: %i sync end: %i total: %i\n",
+ bmode->timing.h_display, bmode->timing.h_sync_start,
+ bmode->timing.h_sync_end, bmode->timing.h_total);
+ printf("\t\tv - display: %i sync start: %i sync end: %i total: %i\n",
+ bmode->timing.v_display, bmode->timing.v_sync_start,
+ bmode->timing.v_sync_end, bmode->timing.v_total);
+ if(bmode->timing.flags) {
+ printf("\t\tFlags:\n");
+ if(bmode->timing.flags & B_BLANK_PEDESTAL) {
+ printf("\t\t\tB_BLANK_PEDESTAL\n");
+ }
+ if(bmode->timing.flags & B_TIMING_INTERLACED) {
+ printf("\t\t\tB_TIMING_INTERLACED\n");
+ }
+ if(bmode->timing.flags & B_POSITIVE_HSYNC) {
+ printf("\t\t\tB_POSITIVE_HSYNC\n");
+ }
+ if(bmode->timing.flags & B_POSITIVE_VSYNC) {
+ printf("\t\t\tB_POSITIVE_VSYNC\n");
+ }
+ if(bmode->timing.flags & B_SYNC_ON_GREEN) {
+ printf("\t\t\tB_SYNC_ON_GREEN\n");
+ }
+ }
+}
+#endif
+
+
+
+int32 BE_ColorSpaceToBitsPerPixel(uint32 colorspace)
+{
+ int bitsperpixel;
+
+ bitsperpixel = 0;
+ switch (colorspace) {
+ case B_CMAP8:
+ bitsperpixel = 8;
+ break;
+ case B_RGB15:
+ case B_RGBA15:
+ case B_RGB15_BIG:
+ case B_RGBA15_BIG:
+ bitsperpixel = 15;
+ break;
+ case B_RGB16:
+ case B_RGB16_BIG:
+ bitsperpixel = 16;
+ break;
+ case B_RGB32:
+ case B_RGBA32:
+ case B_RGB32_BIG:
+ case B_RGBA32_BIG:
+ bitsperpixel = 32;
+ break;
+ default:
+ break;
+ }
+ return(bitsperpixel);
+}
+
+int32 BE_BPPToSDLPxFormat(int32 bpp) {
+ /* Translation taken from SDL_windowsmodes.c */
+ switch (bpp) {
+ case 32:
+ return SDL_PIXELFORMAT_RGB888;
+ break;
+ case 24: /* May not be supported by Haiku */
+ return SDL_PIXELFORMAT_RGB24;
+ break;
+ case 16:
+ return SDL_PIXELFORMAT_RGB565;
+ break;
+ case 15:
+ return SDL_PIXELFORMAT_RGB555;
+ break;
+ case 8:
+ return SDL_PIXELFORMAT_INDEX8;
+ break;
+ case 4: /* May not be supported by Haiku */
+ return SDL_PIXELFORMAT_INDEX4LSB;
+ break;
+ }
+
+ /* May never get here, but safer and needed to shut up compiler */
+ SDL_SetError("Invalid bpp value");
+ return 0;
+}
+
+static void _BDisplayModeToSdlDisplayMode(display_mode *bmode,
+ SDL_DisplayMode *mode) {
+ mode->w = bmode->virtual_width;
+ mode->h = bmode->virtual_height;
+ mode->refresh_rate = (int)get_refresh_rate(*bmode);
+
+#if WRAP_BMODE
+ SDL_DisplayModeData *data = (SDL_DisplayModeData*)SDL_calloc(1,
+ sizeof(SDL_DisplayModeData));
+ data->bmode = bmode;
+
+ mode->driverdata = data;
+
+#else
+
+ mode->driverdata = bmode;
+#endif
+
+ /* Set the format */
+ int32 bpp = BE_ColorSpaceToBitsPerPixel(bmode->space);
+ mode->format = BE_BPPToSDLPxFormat(bpp);
+}
+
+/* Later, there may be more than one monitor available */
+static void _AddDisplay(BScreen *screen) {
+ SDL_VideoDisplay display;
+ SDL_DisplayMode *mode = (SDL_DisplayMode*)SDL_calloc(1,
+ sizeof(SDL_DisplayMode));
+ display_mode *bmode = (display_mode*)SDL_calloc(1, sizeof(display_mode));
+ screen->GetMode(bmode);
+
+ _BDisplayModeToSdlDisplayMode(bmode, mode);
+
+ SDL_zero(display);
+ display.desktop_mode = *mode;
+ display.current_mode = *mode;
+
+ SDL_AddVideoDisplay(&display);
+}
+
+/*
+ * Functions called by SDL
+ */
+
+int BE_InitModes(_THIS) {
+ BScreen screen;
+
+ /* TODO: When Haiku supports multiple display screens, call
+ _AddDisplayScreen() for each of them. */
+ _AddDisplay(&screen);
+ return 0;
+}
+
+int BE_QuitModes(_THIS) {
+ /* FIXME: Nothing really needs to be done here at the moment? */
+ return 0;
+}
+
+
+int BE_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) {
+ BScreen bscreen;
+ BRect rc = bscreen.Frame();
+ rect->x = (int)rc.left;
+ rect->y = (int)rc.top;
+ rect->w = (int)rc.Width() + 1;
+ rect->h = (int)rc.Height() + 1;
+ return 0;
+}
+
+void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display) {
+ /* Get the current screen */
+ BScreen bscreen;
+
+ /* Iterate through all of the modes */
+ SDL_DisplayMode mode;
+ display_mode this_bmode;
+ display_mode *bmodes;
+ uint32 count, i;
+
+ /* Get graphics-hardware supported modes */
+ bscreen.GetModeList(&bmodes, &count);
+ bscreen.GetMode(&this_bmode);
+
+ for(i = 0; i < count; ++i) {
+ // FIXME: Apparently there are errors with colorspace changes
+ if (bmodes[i].space == this_bmode.space) {
+ _BDisplayModeToSdlDisplayMode(&bmodes[i], &mode);
+ SDL_AddDisplayMode(display, &mode);
+ }
+ }
+ free(bmodes);
+}
+
+
+int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){
+ /* Get the current screen */
+ BScreen bscreen;
+ if(!bscreen.IsValid()) {
+ printf(__FILE__": %d - ERROR: BAD SCREEN\n", __LINE__);
+ }
+
+ /* Set the mode using the driver data */
+ display_mode *bmode = _ExtractBMode(mode);
+
+
+ /* FIXME: Is the first option always going to be the right one? */
+ uint32 c = 0, i;
+ display_mode *bmode_list;
+ bscreen.GetModeList(&bmode_list, &c);
+ for(i = 0; i < c; ++i) {
+ if( bmode_list[i].space == bmode->space &&
+ bmode_list[i].virtual_width == bmode->virtual_width &&
+ bmode_list[i].virtual_height == bmode->virtual_height ) {
+ bmode = &bmode_list[i];
+ break;
+ }
+ }
+
+ if(bscreen.SetMode(bmode) != B_OK) {
+ return SDL_SetError("Bad video mode");
+ }
+
+ free(bmode_list);
+
+#if SDL_VIDEO_OPENGL
+ /* FIXME: Is there some way to reboot the OpenGL context? This doesn't
+ help */
+// BE_GL_RebootContexts(_this);
+#endif
+
+ return 0;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SDL_VIDEO_DRIVER_HAIKU */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/haiku/SDL_bmodes.h b/src/3rdparty/SDL2/src/video/haiku/SDL_bmodes.h
new file mode 100644
index 0000000..38f4b58
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/haiku/SDL_bmodes.h
@@ -0,0 +1,48 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_BMODES_H
+#define SDL_BMODES_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "../SDL_sysvideo.h"
+
+extern int32 BE_ColorSpaceToBitsPerPixel(uint32 colorspace);
+extern int32 BE_BPPToSDLPxFormat(int32 bpp);
+
+extern int BE_InitModes(_THIS);
+extern int BE_QuitModes(_THIS);
+extern int BE_GetDisplayBounds(_THIS, SDL_VideoDisplay *display,
+ SDL_Rect *rect);
+extern void BE_GetDisplayModes(_THIS, SDL_VideoDisplay *display);
+extern int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display,
+ SDL_DisplayMode *mode);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/haiku/SDL_bopengl.cc b/src/3rdparty/SDL2/src/video/haiku/SDL_bopengl.cc
new file mode 100644
index 0000000..3456932
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/haiku/SDL_bopengl.cc
@@ -0,0 +1,176 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_HAIKU && SDL_VIDEO_OPENGL
+
+#include "SDL_bopengl.h"
+
+#include <unistd.h>
+#include <KernelKit.h>
+#include <OpenGLKit.h>
+#include "SDL_BWin.h"
+#include "../../main/haiku/SDL_BApp.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
+ return ((SDL_BWin*)(window->driverdata));
+}
+
+static SDL_INLINE SDL_BApp *_GetBeApp() {
+ return ((SDL_BApp*)be_app);
+}
+
+/* Passing a NULL path means load pointers from the application */
+int BE_GL_LoadLibrary(_THIS, const char *path)
+{
+/* FIXME: Is this working correctly? */
+ image_info info;
+ int32 cookie = 0;
+ while (get_next_image_info(0, &cookie, &info) == B_OK) {
+ void *location = NULL;
+ if( get_image_symbol(info.id, "glBegin", B_SYMBOL_TYPE_ANY,
+ &location) == B_OK) {
+
+ _this->gl_config.dll_handle = (void *) (size_t) info.id;
+ _this->gl_config.driver_loaded = 1;
+ SDL_strlcpy(_this->gl_config.driver_path, "libGL.so",
+ SDL_arraysize(_this->gl_config.driver_path));
+ }
+ }
+ return 0;
+}
+
+void *BE_GL_GetProcAddress(_THIS, const char *proc)
+{
+ if (_this->gl_config.dll_handle != NULL) {
+ void *location = NULL;
+ status_t err;
+ if ((err =
+ get_image_symbol((image_id) (size_t) _this->gl_config.dll_handle,
+ proc, B_SYMBOL_TYPE_ANY,
+ &location)) == B_OK) {
+ return location;
+ } else {
+ SDL_SetError("Couldn't find OpenGL symbol");
+ return NULL;
+ }
+ } else {
+ SDL_SetError("OpenGL library not loaded");
+ return NULL;
+ }
+}
+
+
+
+
+int BE_GL_SwapWindow(_THIS, SDL_Window * window) {
+ _ToBeWin(window)->SwapBuffers();
+ return 0;
+}
+
+int BE_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) {
+ SDL_BWin* win = (SDL_BWin*)context;
+ _GetBeApp()->SetCurrentContext(win ? win->GetGLView() : NULL);
+ return 0;
+}
+
+
+SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window) {
+ /* FIXME: Not sure what flags should be included here; may want to have
+ most of them */
+ SDL_BWin *bwin = _ToBeWin(window);
+ Uint32 gl_flags = BGL_RGB;
+ if (_this->gl_config.alpha_size) {
+ gl_flags |= BGL_ALPHA;
+ }
+ if (_this->gl_config.depth_size) {
+ gl_flags |= BGL_DEPTH;
+ }
+ if (_this->gl_config.stencil_size) {
+ gl_flags |= BGL_STENCIL;
+ }
+ if (_this->gl_config.double_buffer) {
+ gl_flags |= BGL_DOUBLE;
+ } else {
+ gl_flags |= BGL_SINGLE;
+ }
+ if (_this->gl_config.accum_red_size ||
+ _this->gl_config.accum_green_size ||
+ _this->gl_config.accum_blue_size ||
+ _this->gl_config.accum_alpha_size) {
+ gl_flags |= BGL_ACCUM;
+ }
+ bwin->CreateGLView(gl_flags);
+ return (SDL_GLContext)(bwin);
+}
+
+void BE_GL_DeleteContext(_THIS, SDL_GLContext context) {
+ /* Currently, automatically unlocks the view */
+ ((SDL_BWin*)context)->RemoveGLView();
+}
+
+
+int BE_GL_SetSwapInterval(_THIS, int interval) {
+ /* TODO: Implement this, if necessary? */
+ return SDL_Unsupported();
+}
+
+int BE_GL_GetSwapInterval(_THIS) {
+ /* TODO: Implement this, if necessary? */
+ return 0;
+}
+
+
+void BE_GL_UnloadLibrary(_THIS) {
+ /* TODO: Implement this, if necessary? */
+}
+
+
+/* FIXME: This function is meant to clear the OpenGL context when the video
+ mode changes (see SDL_bmodes.cc), but it doesn't seem to help, and is not
+ currently in use. */
+void BE_GL_RebootContexts(_THIS) {
+ SDL_Window *window = _this->windows;
+ while(window) {
+ SDL_BWin *bwin = _ToBeWin(window);
+ if(bwin->GetGLView()) {
+ bwin->LockLooper();
+ bwin->RemoveGLView();
+ bwin->CreateGLView(bwin->GetGLType());
+ bwin->UnlockLooper();
+ }
+ window = window->next;
+ }
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SDL_VIDEO_DRIVER_HAIKU && SDL_VIDEO_OPENGL */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/haiku/SDL_bopengl.h b/src/3rdparty/SDL2/src/video/haiku/SDL_bopengl.h
new file mode 100644
index 0000000..bc0798c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/haiku/SDL_bopengl.h
@@ -0,0 +1,55 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_BOPENGL_H
+#define SDL_BOPENGL_H
+
+#if SDL_VIDEO_DRIVER_HAIKU && SDL_VIDEO_OPENGL
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "../SDL_sysvideo.h"
+
+
+extern int BE_GL_LoadLibrary(_THIS, const char *path); /* FIXME */
+extern void *BE_GL_GetProcAddress(_THIS, const char *proc); /* FIXME */
+extern void BE_GL_UnloadLibrary(_THIS); /* TODO */
+extern int BE_GL_MakeCurrent(_THIS, SDL_Window * window,
+ SDL_GLContext context);
+extern int BE_GL_SetSwapInterval(_THIS, int interval); /* TODO */
+extern int BE_GL_GetSwapInterval(_THIS); /* TODO */
+extern int BE_GL_SwapWindow(_THIS, SDL_Window * window);
+extern SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window);
+extern void BE_GL_DeleteContext(_THIS, SDL_GLContext context);
+
+extern void BE_GL_RebootContexts(_THIS);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SDL_VIDEO_DRIVER_HAIKU && SDL_VIDEO_OPENGL */
+
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/haiku/SDL_bvideo.cc b/src/3rdparty/SDL2/src/video/haiku/SDL_bvideo.cc
new file mode 100644
index 0000000..afe20e3
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/haiku/SDL_bvideo.cc
@@ -0,0 +1,178 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_HAIKU
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "SDL_bkeyboard.h"
+#include "SDL_bwindow.h"
+#include "SDL_bclipboard.h"
+#include "SDL_bvideo.h"
+#include "SDL_bopengl.h"
+#include "SDL_bmodes.h"
+#include "SDL_bframebuffer.h"
+#include "SDL_bevents.h"
+
+/* FIXME: Undefined functions */
+// #define BE_PumpEvents NULL
+ #define BE_StartTextInput NULL
+ #define BE_StopTextInput NULL
+ #define BE_SetTextInputRect NULL
+
+// #define BE_DeleteDevice NULL
+
+/* End undefined functions */
+
+static SDL_VideoDevice *
+BE_CreateDevice(int devindex)
+{
+ SDL_VideoDevice *device;
+ /*SDL_VideoData *data;*/
+
+ /* Initialize all variables that we clean on shutdown */
+ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+
+ device->driverdata = NULL; /* FIXME: Is this the cause of some of the
+ SDL_Quit() errors? */
+
+/* TODO: Figure out if any initialization needs to go here */
+
+ /* Set the function pointers */
+ device->VideoInit = BE_VideoInit;
+ device->VideoQuit = BE_VideoQuit;
+ device->GetDisplayBounds = BE_GetDisplayBounds;
+ device->GetDisplayModes = BE_GetDisplayModes;
+ device->SetDisplayMode = BE_SetDisplayMode;
+ device->PumpEvents = BE_PumpEvents;
+
+ device->CreateSDLWindow = BE_CreateWindow;
+ device->CreateSDLWindowFrom = BE_CreateWindowFrom;
+ device->SetWindowTitle = BE_SetWindowTitle;
+ device->SetWindowIcon = BE_SetWindowIcon;
+ device->SetWindowPosition = BE_SetWindowPosition;
+ device->SetWindowSize = BE_SetWindowSize;
+ device->ShowWindow = BE_ShowWindow;
+ device->HideWindow = BE_HideWindow;
+ device->RaiseWindow = BE_RaiseWindow;
+ device->MaximizeWindow = BE_MaximizeWindow;
+ device->MinimizeWindow = BE_MinimizeWindow;
+ device->RestoreWindow = BE_RestoreWindow;
+ device->SetWindowBordered = BE_SetWindowBordered;
+ device->SetWindowResizable = BE_SetWindowResizable;
+ device->SetWindowFullscreen = BE_SetWindowFullscreen;
+ device->SetWindowGammaRamp = BE_SetWindowGammaRamp;
+ device->GetWindowGammaRamp = BE_GetWindowGammaRamp;
+ device->SetWindowGrab = BE_SetWindowGrab;
+ device->DestroyWindow = BE_DestroyWindow;
+ device->GetWindowWMInfo = BE_GetWindowWMInfo;
+ device->CreateWindowFramebuffer = BE_CreateWindowFramebuffer;
+ device->UpdateWindowFramebuffer = BE_UpdateWindowFramebuffer;
+ device->DestroyWindowFramebuffer = BE_DestroyWindowFramebuffer;
+
+ device->shape_driver.CreateShaper = NULL;
+ device->shape_driver.SetWindowShape = NULL;
+ device->shape_driver.ResizeWindowShape = NULL;
+
+#if SDL_VIDEO_OPENGL
+ device->GL_LoadLibrary = BE_GL_LoadLibrary;
+ device->GL_GetProcAddress = BE_GL_GetProcAddress;
+ device->GL_UnloadLibrary = BE_GL_UnloadLibrary;
+ device->GL_CreateContext = BE_GL_CreateContext;
+ device->GL_MakeCurrent = BE_GL_MakeCurrent;
+ device->GL_SetSwapInterval = BE_GL_SetSwapInterval;
+ device->GL_GetSwapInterval = BE_GL_GetSwapInterval;
+ device->GL_SwapWindow = BE_GL_SwapWindow;
+ device->GL_DeleteContext = BE_GL_DeleteContext;
+#endif
+
+ device->StartTextInput = BE_StartTextInput;
+ device->StopTextInput = BE_StopTextInput;
+ device->SetTextInputRect = BE_SetTextInputRect;
+
+ device->SetClipboardText = BE_SetClipboardText;
+ device->GetClipboardText = BE_GetClipboardText;
+ device->HasClipboardText = BE_HasClipboardText;
+
+ device->free = BE_DeleteDevice;
+
+ return device;
+}
+
+VideoBootStrap HAIKU_bootstrap = {
+ "haiku", "Haiku graphics",
+ BE_Available, BE_CreateDevice
+};
+
+void BE_DeleteDevice(SDL_VideoDevice * device)
+{
+ SDL_free(device->driverdata);
+ SDL_free(device);
+}
+
+int BE_VideoInit(_THIS)
+{
+ /* Initialize the Be Application for appserver interaction */
+ if (SDL_InitBeApp() < 0) {
+ return -1;
+ }
+
+ /* Initialize video modes */
+ BE_InitModes(_this);
+
+ /* Init the keymap */
+ BE_InitOSKeymap();
+
+
+#if SDL_VIDEO_OPENGL
+ /* testgl application doesn't load library, just tries to load symbols */
+ /* is it correct? if so we have to load library here */
+ BE_GL_LoadLibrary(_this, NULL);
+#endif
+
+ /* We're done! */
+ return (0);
+}
+
+int BE_Available(void)
+{
+ return (1);
+}
+
+void BE_VideoQuit(_THIS)
+{
+
+ BE_QuitModes(_this);
+
+ SDL_QuitBeApp();
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SDL_VIDEO_DRIVER_HAIKU */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/haiku/SDL_bvideo.h b/src/3rdparty/SDL2/src/video/haiku/SDL_bvideo.h
new file mode 100644
index 0000000..0e28220
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/haiku/SDL_bvideo.h
@@ -0,0 +1,44 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef BVIDEO_H
+#define BVIDEO_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "../../main/haiku/SDL_BeApp.h"
+#include "../SDL_sysvideo.h"
+
+
+extern void BE_VideoQuit(_THIS);
+extern int BE_VideoInit(_THIS);
+extern void BE_DeleteDevice(_THIS);
+extern int BE_Available(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/haiku/SDL_bwindow.cc b/src/3rdparty/SDL2/src/video/haiku/SDL_bwindow.cc
new file mode 100644
index 0000000..0931abe
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/haiku/SDL_bwindow.cc
@@ -0,0 +1,233 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_HAIKU
+#include "../SDL_sysvideo.h"
+
+#include "SDL_BWin.h"
+#include <new>
+
+/* Define a path to window's BWIN data */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
+ return ((SDL_BWin*)(window->driverdata));
+}
+
+static SDL_INLINE SDL_BApp *_GetBeApp() {
+ return ((SDL_BApp*)be_app);
+}
+
+static int _InitWindow(_THIS, SDL_Window *window) {
+ uint32 flags = 0;
+ window_look look = B_TITLED_WINDOW_LOOK;
+
+ BRect bounds(
+ window->x,
+ window->y,
+ window->x + window->w - 1, //BeWindows have an off-by-one px w/h thing
+ window->y + window->h - 1
+ );
+
+ if(window->flags & SDL_WINDOW_FULLSCREEN) {
+ /* TODO: Add support for this flag */
+ printf(__FILE__": %d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",__LINE__);
+ }
+ if(window->flags & SDL_WINDOW_OPENGL) {
+ /* TODO: Add support for this flag */
+ }
+ if(!(window->flags & SDL_WINDOW_RESIZABLE)) {
+ flags |= B_NOT_RESIZABLE | B_NOT_ZOOMABLE;
+ }
+ if(window->flags & SDL_WINDOW_BORDERLESS) {
+ look = B_NO_BORDER_WINDOW_LOOK;
+ }
+
+ SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds, look, flags);
+ if(bwin == NULL)
+ return -1;
+
+ window->driverdata = bwin;
+ int32 winID = _GetBeApp()->GetID(window);
+ bwin->SetID(winID);
+
+ return 0;
+}
+
+int BE_CreateWindow(_THIS, SDL_Window *window) {
+ if (_InitWindow(_this, window) < 0) {
+ return -1;
+ }
+
+ /* Start window loop */
+ _ToBeWin(window)->Show();
+ return 0;
+}
+
+int BE_CreateWindowFrom(_THIS, SDL_Window * window, const void *data) {
+
+ SDL_BWin *otherBWin = (SDL_BWin*)data;
+ if(!otherBWin->LockLooper())
+ return -1;
+
+ /* Create the new window and initialize its members */
+ window->x = (int)otherBWin->Frame().left;
+ window->y = (int)otherBWin->Frame().top;
+ window->w = (int)otherBWin->Frame().Width();
+ window->h = (int)otherBWin->Frame().Height();
+
+ /* Set SDL flags */
+ if(!(otherBWin->Flags() & B_NOT_RESIZABLE)) {
+ window->flags |= SDL_WINDOW_RESIZABLE;
+ }
+
+ /* If we are out of memory, return the error code */
+ if (_InitWindow(_this, window) < 0) {
+ return -1;
+ }
+
+ /* TODO: Add any other SDL-supported window attributes here */
+ _ToBeWin(window)->SetTitle(otherBWin->Title());
+
+ /* Start window loop and unlock the other window */
+ _ToBeWin(window)->Show();
+
+ otherBWin->UnlockLooper();
+ return 0;
+}
+
+void BE_SetWindowTitle(_THIS, SDL_Window * window) {
+ BMessage msg(BWIN_SET_TITLE);
+ msg.AddString("window-title", window->title);
+ _ToBeWin(window)->PostMessage(&msg);
+}
+
+void BE_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) {
+ /* FIXME: Icons not supported by Haiku */
+}
+
+void BE_SetWindowPosition(_THIS, SDL_Window * window) {
+ BMessage msg(BWIN_MOVE_WINDOW);
+ msg.AddInt32("window-x", window->x);
+ msg.AddInt32("window-y", window->y);
+ _ToBeWin(window)->PostMessage(&msg);
+}
+
+void BE_SetWindowSize(_THIS, SDL_Window * window) {
+ BMessage msg(BWIN_RESIZE_WINDOW);
+ msg.AddInt32("window-w", window->w - 1);
+ msg.AddInt32("window-h", window->h - 1);
+ _ToBeWin(window)->PostMessage(&msg);
+}
+
+void BE_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered) {
+ BMessage msg(BWIN_SET_BORDERED);
+ msg.AddBool("window-border", bordered != SDL_FALSE);
+ _ToBeWin(window)->PostMessage(&msg);
+}
+
+void BE_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable) {
+ BMessage msg(BWIN_SET_RESIZABLE);
+ msg.AddBool("window-resizable", resizable != SDL_FALSE);
+ _ToBeWin(window)->PostMessage(&msg);
+}
+
+void BE_ShowWindow(_THIS, SDL_Window * window) {
+ BMessage msg(BWIN_SHOW_WINDOW);
+ _ToBeWin(window)->PostMessage(&msg);
+}
+
+void BE_HideWindow(_THIS, SDL_Window * window) {
+ BMessage msg(BWIN_HIDE_WINDOW);
+ _ToBeWin(window)->PostMessage(&msg);
+}
+
+void BE_RaiseWindow(_THIS, SDL_Window * window) {
+ BMessage msg(BWIN_SHOW_WINDOW); /* Activate this window and move to front */
+ _ToBeWin(window)->PostMessage(&msg);
+}
+
+void BE_MaximizeWindow(_THIS, SDL_Window * window) {
+ BMessage msg(BWIN_MAXIMIZE_WINDOW);
+ _ToBeWin(window)->PostMessage(&msg);
+}
+
+void BE_MinimizeWindow(_THIS, SDL_Window * window) {
+ BMessage msg(BWIN_MINIMIZE_WINDOW);
+ _ToBeWin(window)->PostMessage(&msg);
+}
+
+void BE_RestoreWindow(_THIS, SDL_Window * window) {
+ BMessage msg(BWIN_RESTORE_WINDOW);
+ _ToBeWin(window)->PostMessage(&msg);
+}
+
+void BE_SetWindowFullscreen(_THIS, SDL_Window * window,
+ SDL_VideoDisplay * display, SDL_bool fullscreen) {
+ /* Haiku tracks all video display information */
+ BMessage msg(BWIN_FULLSCREEN);
+ msg.AddBool("fullscreen", fullscreen);
+ _ToBeWin(window)->PostMessage(&msg);
+
+}
+
+int BE_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) {
+ /* FIXME: Not Haiku supported */
+ return -1;
+}
+
+int BE_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) {
+ /* FIXME: Not Haiku supported */
+ return -1;
+}
+
+
+void BE_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed) {
+ /* TODO: Implement this! */
+}
+
+void BE_DestroyWindow(_THIS, SDL_Window * window) {
+ _ToBeWin(window)->LockLooper(); /* This MUST be locked */
+ _GetBeApp()->ClearID(_ToBeWin(window));
+ _ToBeWin(window)->Quit();
+ window->driverdata = NULL;
+}
+
+SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window,
+ struct SDL_SysWMinfo *info) {
+ /* FIXME: What is the point of this? What information should be included? */
+ return SDL_FALSE;
+}
+
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SDL_VIDEO_DRIVER_HAIKU */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/haiku/SDL_bwindow.h b/src/3rdparty/SDL2/src/video/haiku/SDL_bwindow.h
new file mode 100644
index 0000000..100ffed
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/haiku/SDL_bwindow.h
@@ -0,0 +1,55 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_BWINDOW_H
+#define SDL_BWINDOW_H
+
+
+#include "../SDL_sysvideo.h"
+
+
+extern int BE_CreateWindow(_THIS, SDL_Window *window);
+extern int BE_CreateWindowFrom(_THIS, SDL_Window * window, const void *data);
+extern void BE_SetWindowTitle(_THIS, SDL_Window * window);
+extern void BE_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
+extern void BE_SetWindowPosition(_THIS, SDL_Window * window);
+extern void BE_SetWindowSize(_THIS, SDL_Window * window);
+extern void BE_ShowWindow(_THIS, SDL_Window * window);
+extern void BE_HideWindow(_THIS, SDL_Window * window);
+extern void BE_RaiseWindow(_THIS, SDL_Window * window);
+extern void BE_MaximizeWindow(_THIS, SDL_Window * window);
+extern void BE_MinimizeWindow(_THIS, SDL_Window * window);
+extern void BE_RestoreWindow(_THIS, SDL_Window * window);
+extern void BE_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
+extern void BE_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
+extern void BE_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
+extern int BE_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
+extern int BE_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
+extern void BE_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
+extern void BE_DestroyWindow(_THIS, SDL_Window * window);
+extern SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window,
+ struct SDL_SysWMinfo *info);
+
+
+
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/khronos/EGL/egl.h b/src/3rdparty/SDL2/src/video/khronos/EGL/egl.h
new file mode 100644
index 0000000..93a2187
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/khronos/EGL/egl.h
@@ -0,0 +1,303 @@
+#ifndef __egl_h_
+#define __egl_h_ 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+** Copyright (c) 2013-2017 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+/*
+** This header is generated from the Khronos OpenGL / OpenGL ES XML
+** API Registry. The current version of the Registry, generator scripts
+** used to make the header, and the header can be found at
+** http://www.khronos.org/registry/egl
+**
+** Khronos $Git commit SHA1: a732b061e7 $ on $Git commit date: 2017-06-17 23:27:53 +0100 $
+*/
+
+#include <EGL/eglplatform.h>
+
+/* Generated on date 20170627 */
+
+/* Generated C header for:
+ * API: egl
+ * Versions considered: .*
+ * Versions emitted: .*
+ * Default extensions included: None
+ * Additional extensions included: _nomatch_^
+ * Extensions removed: _nomatch_^
+ */
+
+#ifndef EGL_VERSION_1_0
+#define EGL_VERSION_1_0 1
+typedef unsigned int EGLBoolean;
+typedef void *EGLDisplay;
+#include <KHR/khrplatform.h>
+#include <EGL/eglplatform.h>
+typedef void *EGLConfig;
+typedef void *EGLSurface;
+typedef void *EGLContext;
+typedef void (*__eglMustCastToProperFunctionPointerType)(void);
+#define EGL_ALPHA_SIZE 0x3021
+#define EGL_BAD_ACCESS 0x3002
+#define EGL_BAD_ALLOC 0x3003
+#define EGL_BAD_ATTRIBUTE 0x3004
+#define EGL_BAD_CONFIG 0x3005
+#define EGL_BAD_CONTEXT 0x3006
+#define EGL_BAD_CURRENT_SURFACE 0x3007
+#define EGL_BAD_DISPLAY 0x3008
+#define EGL_BAD_MATCH 0x3009
+#define EGL_BAD_NATIVE_PIXMAP 0x300A
+#define EGL_BAD_NATIVE_WINDOW 0x300B
+#define EGL_BAD_PARAMETER 0x300C
+#define EGL_BAD_SURFACE 0x300D
+#define EGL_BLUE_SIZE 0x3022
+#define EGL_BUFFER_SIZE 0x3020
+#define EGL_CONFIG_CAVEAT 0x3027
+#define EGL_CONFIG_ID 0x3028
+#define EGL_CORE_NATIVE_ENGINE 0x305B
+#define EGL_DEPTH_SIZE 0x3025
+#define EGL_DONT_CARE EGL_CAST(EGLint,-1)
+#define EGL_DRAW 0x3059
+#define EGL_EXTENSIONS 0x3055
+#define EGL_FALSE 0
+#define EGL_GREEN_SIZE 0x3023
+#define EGL_HEIGHT 0x3056
+#define EGL_LARGEST_PBUFFER 0x3058
+#define EGL_LEVEL 0x3029
+#define EGL_MAX_PBUFFER_HEIGHT 0x302A
+#define EGL_MAX_PBUFFER_PIXELS 0x302B
+#define EGL_MAX_PBUFFER_WIDTH 0x302C
+#define EGL_NATIVE_RENDERABLE 0x302D
+#define EGL_NATIVE_VISUAL_ID 0x302E
+#define EGL_NATIVE_VISUAL_TYPE 0x302F
+#define EGL_NONE 0x3038
+#define EGL_NON_CONFORMANT_CONFIG 0x3051
+#define EGL_NOT_INITIALIZED 0x3001
+#define EGL_NO_CONTEXT EGL_CAST(EGLContext,0)
+#define EGL_NO_DISPLAY EGL_CAST(EGLDisplay,0)
+#define EGL_NO_SURFACE EGL_CAST(EGLSurface,0)
+#define EGL_PBUFFER_BIT 0x0001
+#define EGL_PIXMAP_BIT 0x0002
+#define EGL_READ 0x305A
+#define EGL_RED_SIZE 0x3024
+#define EGL_SAMPLES 0x3031
+#define EGL_SAMPLE_BUFFERS 0x3032
+#define EGL_SLOW_CONFIG 0x3050
+#define EGL_STENCIL_SIZE 0x3026
+#define EGL_SUCCESS 0x3000
+#define EGL_SURFACE_TYPE 0x3033
+#define EGL_TRANSPARENT_BLUE_VALUE 0x3035
+#define EGL_TRANSPARENT_GREEN_VALUE 0x3036
+#define EGL_TRANSPARENT_RED_VALUE 0x3037
+#define EGL_TRANSPARENT_RGB 0x3052
+#define EGL_TRANSPARENT_TYPE 0x3034
+#define EGL_TRUE 1
+#define EGL_VENDOR 0x3053
+#define EGL_VERSION 0x3054
+#define EGL_WIDTH 0x3057
+#define EGL_WINDOW_BIT 0x0004
+EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig (EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
+EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers (EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target);
+EGLAPI EGLContext EGLAPIENTRY eglCreateContext (EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferSurface (EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurface (EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface (EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext (EGLDisplay dpy, EGLContext ctx);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface (EGLDisplay dpy, EGLSurface surface);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib (EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs (EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
+EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay (void);
+EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface (EGLint readdraw);
+EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay (EGLNativeDisplayType display_id);
+EGLAPI EGLint EGLAPIENTRY eglGetError (void);
+EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress (const char *procname);
+EGLAPI EGLBoolean EGLAPIENTRY eglInitialize (EGLDisplay dpy, EGLint *major, EGLint *minor);
+EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent (EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext (EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value);
+EGLAPI const char *EGLAPIENTRY eglQueryString (EGLDisplay dpy, EGLint name);
+EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers (EGLDisplay dpy, EGLSurface surface);
+EGLAPI EGLBoolean EGLAPIENTRY eglTerminate (EGLDisplay dpy);
+EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL (void);
+EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative (EGLint engine);
+#endif /* EGL_VERSION_1_0 */
+
+#ifndef EGL_VERSION_1_1
+#define EGL_VERSION_1_1 1
+#define EGL_BACK_BUFFER 0x3084
+#define EGL_BIND_TO_TEXTURE_RGB 0x3039
+#define EGL_BIND_TO_TEXTURE_RGBA 0x303A
+#define EGL_CONTEXT_LOST 0x300E
+#define EGL_MIN_SWAP_INTERVAL 0x303B
+#define EGL_MAX_SWAP_INTERVAL 0x303C
+#define EGL_MIPMAP_TEXTURE 0x3082
+#define EGL_MIPMAP_LEVEL 0x3083
+#define EGL_NO_TEXTURE 0x305C
+#define EGL_TEXTURE_2D 0x305F
+#define EGL_TEXTURE_FORMAT 0x3080
+#define EGL_TEXTURE_RGB 0x305D
+#define EGL_TEXTURE_RGBA 0x305E
+#define EGL_TEXTURE_TARGET 0x3081
+EGLAPI EGLBoolean EGLAPIENTRY eglBindTexImage (EGLDisplay dpy, EGLSurface surface, EGLint buffer);
+EGLAPI EGLBoolean EGLAPIENTRY eglReleaseTexImage (EGLDisplay dpy, EGLSurface surface, EGLint buffer);
+EGLAPI EGLBoolean EGLAPIENTRY eglSurfaceAttrib (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value);
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval (EGLDisplay dpy, EGLint interval);
+#endif /* EGL_VERSION_1_1 */
+
+#ifndef EGL_VERSION_1_2
+#define EGL_VERSION_1_2 1
+typedef unsigned int EGLenum;
+typedef void *EGLClientBuffer;
+#define EGL_ALPHA_FORMAT 0x3088
+#define EGL_ALPHA_FORMAT_NONPRE 0x308B
+#define EGL_ALPHA_FORMAT_PRE 0x308C
+#define EGL_ALPHA_MASK_SIZE 0x303E
+#define EGL_BUFFER_PRESERVED 0x3094
+#define EGL_BUFFER_DESTROYED 0x3095
+#define EGL_CLIENT_APIS 0x308D
+#define EGL_COLORSPACE 0x3087
+#define EGL_COLORSPACE_sRGB 0x3089
+#define EGL_COLORSPACE_LINEAR 0x308A
+#define EGL_COLOR_BUFFER_TYPE 0x303F
+#define EGL_CONTEXT_CLIENT_TYPE 0x3097
+#define EGL_DISPLAY_SCALING 10000
+#define EGL_HORIZONTAL_RESOLUTION 0x3090
+#define EGL_LUMINANCE_BUFFER 0x308F
+#define EGL_LUMINANCE_SIZE 0x303D
+#define EGL_OPENGL_ES_BIT 0x0001
+#define EGL_OPENVG_BIT 0x0002
+#define EGL_OPENGL_ES_API 0x30A0
+#define EGL_OPENVG_API 0x30A1
+#define EGL_OPENVG_IMAGE 0x3096
+#define EGL_PIXEL_ASPECT_RATIO 0x3092
+#define EGL_RENDERABLE_TYPE 0x3040
+#define EGL_RENDER_BUFFER 0x3086
+#define EGL_RGB_BUFFER 0x308E
+#define EGL_SINGLE_BUFFER 0x3085
+#define EGL_SWAP_BEHAVIOR 0x3093
+#define EGL_UNKNOWN EGL_CAST(EGLint,-1)
+#define EGL_VERTICAL_RESOLUTION 0x3091
+EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI (EGLenum api);
+EGLAPI EGLenum EGLAPIENTRY eglQueryAPI (void);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferFromClientBuffer (EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglReleaseThread (void);
+EGLAPI EGLBoolean EGLAPIENTRY eglWaitClient (void);
+#endif /* EGL_VERSION_1_2 */
+
+#ifndef EGL_VERSION_1_3
+#define EGL_VERSION_1_3 1
+#define EGL_CONFORMANT 0x3042
+#define EGL_CONTEXT_CLIENT_VERSION 0x3098
+#define EGL_MATCH_NATIVE_PIXMAP 0x3041
+#define EGL_OPENGL_ES2_BIT 0x0004
+#define EGL_VG_ALPHA_FORMAT 0x3088
+#define EGL_VG_ALPHA_FORMAT_NONPRE 0x308B
+#define EGL_VG_ALPHA_FORMAT_PRE 0x308C
+#define EGL_VG_ALPHA_FORMAT_PRE_BIT 0x0040
+#define EGL_VG_COLORSPACE 0x3087
+#define EGL_VG_COLORSPACE_sRGB 0x3089
+#define EGL_VG_COLORSPACE_LINEAR 0x308A
+#define EGL_VG_COLORSPACE_LINEAR_BIT 0x0020
+#endif /* EGL_VERSION_1_3 */
+
+#ifndef EGL_VERSION_1_4
+#define EGL_VERSION_1_4 1
+#define EGL_DEFAULT_DISPLAY EGL_CAST(EGLNativeDisplayType,0)
+#define EGL_MULTISAMPLE_RESOLVE_BOX_BIT 0x0200
+#define EGL_MULTISAMPLE_RESOLVE 0x3099
+#define EGL_MULTISAMPLE_RESOLVE_DEFAULT 0x309A
+#define EGL_MULTISAMPLE_RESOLVE_BOX 0x309B
+#define EGL_OPENGL_API 0x30A2
+#define EGL_OPENGL_BIT 0x0008
+#define EGL_SWAP_BEHAVIOR_PRESERVED_BIT 0x0400
+EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext (void);
+#endif /* EGL_VERSION_1_4 */
+
+#ifndef EGL_VERSION_1_5
+#define EGL_VERSION_1_5 1
+typedef void *EGLSync;
+typedef intptr_t EGLAttrib;
+typedef khronos_utime_nanoseconds_t EGLTime;
+typedef void *EGLImage;
+#define EGL_CONTEXT_MAJOR_VERSION 0x3098
+#define EGL_CONTEXT_MINOR_VERSION 0x30FB
+#define EGL_CONTEXT_OPENGL_PROFILE_MASK 0x30FD
+#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY 0x31BD
+#define EGL_NO_RESET_NOTIFICATION 0x31BE
+#define EGL_LOSE_CONTEXT_ON_RESET 0x31BF
+#define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT 0x00000001
+#define EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT 0x00000002
+#define EGL_CONTEXT_OPENGL_DEBUG 0x31B0
+#define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE 0x31B1
+#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS 0x31B2
+#define EGL_OPENGL_ES3_BIT 0x00000040
+#define EGL_CL_EVENT_HANDLE 0x309C
+#define EGL_SYNC_CL_EVENT 0x30FE
+#define EGL_SYNC_CL_EVENT_COMPLETE 0x30FF
+#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE 0x30F0
+#define EGL_SYNC_TYPE 0x30F7
+#define EGL_SYNC_STATUS 0x30F1
+#define EGL_SYNC_CONDITION 0x30F8
+#define EGL_SIGNALED 0x30F2
+#define EGL_UNSIGNALED 0x30F3
+#define EGL_SYNC_FLUSH_COMMANDS_BIT 0x0001
+#define EGL_FOREVER 0xFFFFFFFFFFFFFFFFull
+#define EGL_TIMEOUT_EXPIRED 0x30F5
+#define EGL_CONDITION_SATISFIED 0x30F6
+#define EGL_NO_SYNC EGL_CAST(EGLSync,0)
+#define EGL_SYNC_FENCE 0x30F9
+#define EGL_GL_COLORSPACE 0x309D
+#define EGL_GL_COLORSPACE_SRGB 0x3089
+#define EGL_GL_COLORSPACE_LINEAR 0x308A
+#define EGL_GL_RENDERBUFFER 0x30B9
+#define EGL_GL_TEXTURE_2D 0x30B1
+#define EGL_GL_TEXTURE_LEVEL 0x30BC
+#define EGL_GL_TEXTURE_3D 0x30B2
+#define EGL_GL_TEXTURE_ZOFFSET 0x30BD
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x30B3
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x30B4
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x30B5
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x30B6
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x30B7
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x30B8
+#define EGL_IMAGE_PRESERVED 0x30D2
+#define EGL_NO_IMAGE EGL_CAST(EGLImage,0)
+EGLAPI EGLSync EGLAPIENTRY eglCreateSync (EGLDisplay dpy, EGLenum type, const EGLAttrib *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroySync (EGLDisplay dpy, EGLSync sync);
+EGLAPI EGLint EGLAPIENTRY eglClientWaitSync (EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttrib (EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib *value);
+EGLAPI EGLImage EGLAPIENTRY eglCreateImage (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImage (EGLDisplay dpy, EGLImage image);
+EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplay (EGLenum platform, void *native_display, const EGLAttrib *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformWindowSurface (EGLDisplay dpy, EGLConfig config, void *native_window, const EGLAttrib *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformPixmapSurface (EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLAttrib *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglWaitSync (EGLDisplay dpy, EGLSync sync, EGLint flags);
+#endif /* EGL_VERSION_1_5 */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/3rdparty/SDL2/src/video/khronos/EGL/eglext.h b/src/3rdparty/SDL2/src/video/khronos/EGL/eglext.h
new file mode 100644
index 0000000..d2def03
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/khronos/EGL/eglext.h
@@ -0,0 +1,1241 @@
+#ifndef __eglext_h_
+#define __eglext_h_ 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+** Copyright (c) 2013-2017 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+/*
+** This header is generated from the Khronos OpenGL / OpenGL ES XML
+** API Registry. The current version of the Registry, generator scripts
+** used to make the header, and the header can be found at
+** http://www.khronos.org/registry/egl
+**
+** Khronos $Git commit SHA1: a732b061e7 $ on $Git commit date: 2017-06-17 23:27:53 +0100 $
+*/
+
+#include <EGL/eglplatform.h>
+
+#define EGL_EGLEXT_VERSION 20170627
+
+/* Generated C header for:
+ * API: egl
+ * Versions considered: .*
+ * Versions emitted: _nomatch_^
+ * Default extensions included: egl
+ * Additional extensions included: _nomatch_^
+ * Extensions removed: _nomatch_^
+ */
+
+#ifndef EGL_KHR_cl_event
+#define EGL_KHR_cl_event 1
+#define EGL_CL_EVENT_HANDLE_KHR 0x309C
+#define EGL_SYNC_CL_EVENT_KHR 0x30FE
+#define EGL_SYNC_CL_EVENT_COMPLETE_KHR 0x30FF
+#endif /* EGL_KHR_cl_event */
+
+#ifndef EGL_KHR_cl_event2
+#define EGL_KHR_cl_event2 1
+typedef void *EGLSyncKHR;
+typedef intptr_t EGLAttribKHR;
+typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESYNC64KHRPROC) (EGLDisplay dpy, EGLenum type, const EGLAttribKHR *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateSync64KHR (EGLDisplay dpy, EGLenum type, const EGLAttribKHR *attrib_list);
+#endif
+#endif /* EGL_KHR_cl_event2 */
+
+#ifndef EGL_KHR_client_get_all_proc_addresses
+#define EGL_KHR_client_get_all_proc_addresses 1
+#endif /* EGL_KHR_client_get_all_proc_addresses */
+
+#ifndef EGL_KHR_config_attribs
+#define EGL_KHR_config_attribs 1
+#define EGL_CONFORMANT_KHR 0x3042
+#define EGL_VG_COLORSPACE_LINEAR_BIT_KHR 0x0020
+#define EGL_VG_ALPHA_FORMAT_PRE_BIT_KHR 0x0040
+#endif /* EGL_KHR_config_attribs */
+
+#ifndef EGL_KHR_context_flush_control
+#define EGL_KHR_context_flush_control 1
+#define EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR 0
+#define EGL_CONTEXT_RELEASE_BEHAVIOR_KHR 0x2097
+#define EGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_KHR 0x2098
+#endif /* EGL_KHR_context_flush_control */
+
+#ifndef EGL_KHR_create_context
+#define EGL_KHR_create_context 1
+#define EGL_CONTEXT_MAJOR_VERSION_KHR 0x3098
+#define EGL_CONTEXT_MINOR_VERSION_KHR 0x30FB
+#define EGL_CONTEXT_FLAGS_KHR 0x30FC
+#define EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR 0x30FD
+#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR 0x31BD
+#define EGL_NO_RESET_NOTIFICATION_KHR 0x31BE
+#define EGL_LOSE_CONTEXT_ON_RESET_KHR 0x31BF
+#define EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR 0x00000001
+#define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR 0x00000002
+#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR 0x00000004
+#define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR 0x00000001
+#define EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR 0x00000002
+#define EGL_OPENGL_ES3_BIT_KHR 0x00000040
+#endif /* EGL_KHR_create_context */
+
+#ifndef EGL_KHR_create_context_no_error
+#define EGL_KHR_create_context_no_error 1
+#define EGL_CONTEXT_OPENGL_NO_ERROR_KHR 0x31B3
+#endif /* EGL_KHR_create_context_no_error */
+
+#ifndef EGL_KHR_debug
+#define EGL_KHR_debug 1
+typedef void *EGLLabelKHR;
+typedef void *EGLObjectKHR;
+typedef void (EGLAPIENTRY *EGLDEBUGPROCKHR)(EGLenum error,const char *command,EGLint messageType,EGLLabelKHR threadLabel,EGLLabelKHR objectLabel,const char* message);
+#define EGL_OBJECT_THREAD_KHR 0x33B0
+#define EGL_OBJECT_DISPLAY_KHR 0x33B1
+#define EGL_OBJECT_CONTEXT_KHR 0x33B2
+#define EGL_OBJECT_SURFACE_KHR 0x33B3
+#define EGL_OBJECT_IMAGE_KHR 0x33B4
+#define EGL_OBJECT_SYNC_KHR 0x33B5
+#define EGL_OBJECT_STREAM_KHR 0x33B6
+#define EGL_DEBUG_MSG_CRITICAL_KHR 0x33B9
+#define EGL_DEBUG_MSG_ERROR_KHR 0x33BA
+#define EGL_DEBUG_MSG_WARN_KHR 0x33BB
+#define EGL_DEBUG_MSG_INFO_KHR 0x33BC
+#define EGL_DEBUG_CALLBACK_KHR 0x33B8
+typedef EGLint (EGLAPIENTRYP PFNEGLDEBUGMESSAGECONTROLKHRPROC) (EGLDEBUGPROCKHR callback, const EGLAttrib *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDEBUGKHRPROC) (EGLint attribute, EGLAttrib *value);
+typedef EGLint (EGLAPIENTRYP PFNEGLLABELOBJECTKHRPROC) (EGLDisplay display, EGLenum objectType, EGLObjectKHR object, EGLLabelKHR label);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLint EGLAPIENTRY eglDebugMessageControlKHR (EGLDEBUGPROCKHR callback, const EGLAttrib *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryDebugKHR (EGLint attribute, EGLAttrib *value);
+EGLAPI EGLint EGLAPIENTRY eglLabelObjectKHR (EGLDisplay display, EGLenum objectType, EGLObjectKHR object, EGLLabelKHR label);
+#endif
+#endif /* EGL_KHR_debug */
+
+#ifndef EGL_KHR_display_reference
+#define EGL_KHR_display_reference 1
+#define EGL_TRACK_REFERENCES_KHR 0x3352
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDISPLAYATTRIBKHRPROC) (EGLDisplay dpy, EGLint name, EGLAttrib *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryDisplayAttribKHR (EGLDisplay dpy, EGLint name, EGLAttrib *value);
+#endif
+#endif /* EGL_KHR_display_reference */
+
+#ifndef EGL_KHR_fence_sync
+#define EGL_KHR_fence_sync 1
+typedef khronos_utime_nanoseconds_t EGLTimeKHR;
+#ifdef KHRONOS_SUPPORT_INT64
+#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR 0x30F0
+#define EGL_SYNC_CONDITION_KHR 0x30F8
+#define EGL_SYNC_FENCE_KHR 0x30F9
+typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESYNCKHRPROC) (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync);
+typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateSyncKHR (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncKHR (EGLDisplay dpy, EGLSyncKHR sync);
+EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncKHR (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribKHR (EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value);
+#endif
+#endif /* KHRONOS_SUPPORT_INT64 */
+#endif /* EGL_KHR_fence_sync */
+
+#ifndef EGL_KHR_get_all_proc_addresses
+#define EGL_KHR_get_all_proc_addresses 1
+#endif /* EGL_KHR_get_all_proc_addresses */
+
+#ifndef EGL_KHR_gl_colorspace
+#define EGL_KHR_gl_colorspace 1
+#define EGL_GL_COLORSPACE_KHR 0x309D
+#define EGL_GL_COLORSPACE_SRGB_KHR 0x3089
+#define EGL_GL_COLORSPACE_LINEAR_KHR 0x308A
+#endif /* EGL_KHR_gl_colorspace */
+
+#ifndef EGL_KHR_gl_renderbuffer_image
+#define EGL_KHR_gl_renderbuffer_image 1
+#define EGL_GL_RENDERBUFFER_KHR 0x30B9
+#endif /* EGL_KHR_gl_renderbuffer_image */
+
+#ifndef EGL_KHR_gl_texture_2D_image
+#define EGL_KHR_gl_texture_2D_image 1
+#define EGL_GL_TEXTURE_2D_KHR 0x30B1
+#define EGL_GL_TEXTURE_LEVEL_KHR 0x30BC
+#endif /* EGL_KHR_gl_texture_2D_image */
+
+#ifndef EGL_KHR_gl_texture_3D_image
+#define EGL_KHR_gl_texture_3D_image 1
+#define EGL_GL_TEXTURE_3D_KHR 0x30B2
+#define EGL_GL_TEXTURE_ZOFFSET_KHR 0x30BD
+#endif /* EGL_KHR_gl_texture_3D_image */
+
+#ifndef EGL_KHR_gl_texture_cubemap_image
+#define EGL_KHR_gl_texture_cubemap_image 1
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR 0x30B3
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR 0x30B4
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR 0x30B5
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR 0x30B6
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR 0x30B7
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR 0x30B8
+#endif /* EGL_KHR_gl_texture_cubemap_image */
+
+#ifndef EGL_KHR_image
+#define EGL_KHR_image 1
+typedef void *EGLImageKHR;
+#define EGL_NATIVE_PIXMAP_KHR 0x30B0
+#define EGL_NO_IMAGE_KHR EGL_CAST(EGLImageKHR,0)
+typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGLImageKHR image);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLImageKHR EGLAPIENTRY eglCreateImageKHR (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImageKHR (EGLDisplay dpy, EGLImageKHR image);
+#endif
+#endif /* EGL_KHR_image */
+
+#ifndef EGL_KHR_image_base
+#define EGL_KHR_image_base 1
+#define EGL_IMAGE_PRESERVED_KHR 0x30D2
+#endif /* EGL_KHR_image_base */
+
+#ifndef EGL_KHR_image_pixmap
+#define EGL_KHR_image_pixmap 1
+#endif /* EGL_KHR_image_pixmap */
+
+#ifndef EGL_KHR_lock_surface
+#define EGL_KHR_lock_surface 1
+#define EGL_READ_SURFACE_BIT_KHR 0x0001
+#define EGL_WRITE_SURFACE_BIT_KHR 0x0002
+#define EGL_LOCK_SURFACE_BIT_KHR 0x0080
+#define EGL_OPTIMAL_FORMAT_BIT_KHR 0x0100
+#define EGL_MATCH_FORMAT_KHR 0x3043
+#define EGL_FORMAT_RGB_565_EXACT_KHR 0x30C0
+#define EGL_FORMAT_RGB_565_KHR 0x30C1
+#define EGL_FORMAT_RGBA_8888_EXACT_KHR 0x30C2
+#define EGL_FORMAT_RGBA_8888_KHR 0x30C3
+#define EGL_MAP_PRESERVE_PIXELS_KHR 0x30C4
+#define EGL_LOCK_USAGE_HINT_KHR 0x30C5
+#define EGL_BITMAP_POINTER_KHR 0x30C6
+#define EGL_BITMAP_PITCH_KHR 0x30C7
+#define EGL_BITMAP_ORIGIN_KHR 0x30C8
+#define EGL_BITMAP_PIXEL_RED_OFFSET_KHR 0x30C9
+#define EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR 0x30CA
+#define EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR 0x30CB
+#define EGL_BITMAP_PIXEL_ALPHA_OFFSET_KHR 0x30CC
+#define EGL_BITMAP_PIXEL_LUMINANCE_OFFSET_KHR 0x30CD
+#define EGL_LOWER_LEFT_KHR 0x30CE
+#define EGL_UPPER_LEFT_KHR 0x30CF
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLLOCKSURFACEKHRPROC) (EGLDisplay dpy, EGLSurface surface, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLUNLOCKSURFACEKHRPROC) (EGLDisplay dpy, EGLSurface surface);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglLockSurfaceKHR (EGLDisplay dpy, EGLSurface surface, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglUnlockSurfaceKHR (EGLDisplay dpy, EGLSurface surface);
+#endif
+#endif /* EGL_KHR_lock_surface */
+
+#ifndef EGL_KHR_lock_surface2
+#define EGL_KHR_lock_surface2 1
+#define EGL_BITMAP_PIXEL_SIZE_KHR 0x3110
+#endif /* EGL_KHR_lock_surface2 */
+
+#ifndef EGL_KHR_lock_surface3
+#define EGL_KHR_lock_surface3 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSURFACE64KHRPROC) (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLAttribKHR *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface64KHR (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLAttribKHR *value);
+#endif
+#endif /* EGL_KHR_lock_surface3 */
+
+#ifndef EGL_KHR_mutable_render_buffer
+#define EGL_KHR_mutable_render_buffer 1
+#define EGL_MUTABLE_RENDER_BUFFER_BIT_KHR 0x1000
+#endif /* EGL_KHR_mutable_render_buffer */
+
+#ifndef EGL_KHR_no_config_context
+#define EGL_KHR_no_config_context 1
+#define EGL_NO_CONFIG_KHR EGL_CAST(EGLConfig,0)
+#endif /* EGL_KHR_no_config_context */
+
+#ifndef EGL_KHR_partial_update
+#define EGL_KHR_partial_update 1
+#define EGL_BUFFER_AGE_KHR 0x313D
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSETDAMAGEREGIONKHRPROC) (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSetDamageRegionKHR (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
+#endif
+#endif /* EGL_KHR_partial_update */
+
+#ifndef EGL_KHR_platform_android
+#define EGL_KHR_platform_android 1
+#define EGL_PLATFORM_ANDROID_KHR 0x3141
+#endif /* EGL_KHR_platform_android */
+
+#ifndef EGL_KHR_platform_gbm
+#define EGL_KHR_platform_gbm 1
+#define EGL_PLATFORM_GBM_KHR 0x31D7
+#endif /* EGL_KHR_platform_gbm */
+
+#ifndef EGL_KHR_platform_wayland
+#define EGL_KHR_platform_wayland 1
+#define EGL_PLATFORM_WAYLAND_KHR 0x31D8
+#endif /* EGL_KHR_platform_wayland */
+
+#ifndef EGL_KHR_platform_x11
+#define EGL_KHR_platform_x11 1
+#define EGL_PLATFORM_X11_KHR 0x31D5
+#define EGL_PLATFORM_X11_SCREEN_KHR 0x31D6
+#endif /* EGL_KHR_platform_x11 */
+
+#ifndef EGL_KHR_reusable_sync
+#define EGL_KHR_reusable_sync 1
+#ifdef KHRONOS_SUPPORT_INT64
+#define EGL_SYNC_STATUS_KHR 0x30F1
+#define EGL_SIGNALED_KHR 0x30F2
+#define EGL_UNSIGNALED_KHR 0x30F3
+#define EGL_TIMEOUT_EXPIRED_KHR 0x30F5
+#define EGL_CONDITION_SATISFIED_KHR 0x30F6
+#define EGL_SYNC_TYPE_KHR 0x30F7
+#define EGL_SYNC_REUSABLE_KHR 0x30FA
+#define EGL_SYNC_FLUSH_COMMANDS_BIT_KHR 0x0001
+#define EGL_FOREVER_KHR 0xFFFFFFFFFFFFFFFFull
+#define EGL_NO_SYNC_KHR EGL_CAST(EGLSyncKHR,0)
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncKHR (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode);
+#endif
+#endif /* KHRONOS_SUPPORT_INT64 */
+#endif /* EGL_KHR_reusable_sync */
+
+#ifndef EGL_KHR_stream
+#define EGL_KHR_stream 1
+typedef void *EGLStreamKHR;
+typedef khronos_uint64_t EGLuint64KHR;
+#ifdef KHRONOS_SUPPORT_INT64
+#define EGL_NO_STREAM_KHR EGL_CAST(EGLStreamKHR,0)
+#define EGL_CONSUMER_LATENCY_USEC_KHR 0x3210
+#define EGL_PRODUCER_FRAME_KHR 0x3212
+#define EGL_CONSUMER_FRAME_KHR 0x3213
+#define EGL_STREAM_STATE_KHR 0x3214
+#define EGL_STREAM_STATE_CREATED_KHR 0x3215
+#define EGL_STREAM_STATE_CONNECTING_KHR 0x3216
+#define EGL_STREAM_STATE_EMPTY_KHR 0x3217
+#define EGL_STREAM_STATE_NEW_FRAME_AVAILABLE_KHR 0x3218
+#define EGL_STREAM_STATE_OLD_FRAME_AVAILABLE_KHR 0x3219
+#define EGL_STREAM_STATE_DISCONNECTED_KHR 0x321A
+#define EGL_BAD_STREAM_KHR 0x321B
+#define EGL_BAD_STATE_KHR 0x321C
+typedef EGLStreamKHR (EGLAPIENTRYP PFNEGLCREATESTREAMKHRPROC) (EGLDisplay dpy, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSTREAMKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMATTRIBKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint *value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMU64KHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLuint64KHR *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLStreamKHR EGLAPIENTRY eglCreateStreamKHR (EGLDisplay dpy, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroyStreamKHR (EGLDisplay dpy, EGLStreamKHR stream);
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamAttribKHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamKHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamu64KHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLuint64KHR *value);
+#endif
+#endif /* KHRONOS_SUPPORT_INT64 */
+#endif /* EGL_KHR_stream */
+
+#ifndef EGL_KHR_stream_attrib
+#define EGL_KHR_stream_attrib 1
+#ifdef KHRONOS_SUPPORT_INT64
+typedef EGLStreamKHR (EGLAPIENTRYP PFNEGLCREATESTREAMATTRIBKHRPROC) (EGLDisplay dpy, const EGLAttrib *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSETSTREAMATTRIBKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLAttrib value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMATTRIBKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLAttrib *value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERACQUIREATTRIBKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERRELEASEATTRIBKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLStreamKHR EGLAPIENTRY eglCreateStreamAttribKHR (EGLDisplay dpy, const EGLAttrib *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglSetStreamAttribKHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLAttrib value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamAttribKHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLAttrib *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerAcquireAttribKHR (EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerReleaseAttribKHR (EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
+#endif
+#endif /* KHRONOS_SUPPORT_INT64 */
+#endif /* EGL_KHR_stream_attrib */
+
+#ifndef EGL_KHR_stream_consumer_gltexture
+#define EGL_KHR_stream_consumer_gltexture 1
+#ifdef EGL_KHR_stream
+#define EGL_CONSUMER_ACQUIRE_TIMEOUT_USEC_KHR 0x321E
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERGLTEXTUREEXTERNALKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERACQUIREKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERRELEASEKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerGLTextureExternalKHR (EGLDisplay dpy, EGLStreamKHR stream);
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerAcquireKHR (EGLDisplay dpy, EGLStreamKHR stream);
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerReleaseKHR (EGLDisplay dpy, EGLStreamKHR stream);
+#endif
+#endif /* EGL_KHR_stream */
+#endif /* EGL_KHR_stream_consumer_gltexture */
+
+#ifndef EGL_KHR_stream_cross_process_fd
+#define EGL_KHR_stream_cross_process_fd 1
+typedef int EGLNativeFileDescriptorKHR;
+#ifdef EGL_KHR_stream
+#define EGL_NO_FILE_DESCRIPTOR_KHR EGL_CAST(EGLNativeFileDescriptorKHR,-1)
+typedef EGLNativeFileDescriptorKHR (EGLAPIENTRYP PFNEGLGETSTREAMFILEDESCRIPTORKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream);
+typedef EGLStreamKHR (EGLAPIENTRYP PFNEGLCREATESTREAMFROMFILEDESCRIPTORKHRPROC) (EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLNativeFileDescriptorKHR EGLAPIENTRY eglGetStreamFileDescriptorKHR (EGLDisplay dpy, EGLStreamKHR stream);
+EGLAPI EGLStreamKHR EGLAPIENTRY eglCreateStreamFromFileDescriptorKHR (EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor);
+#endif
+#endif /* EGL_KHR_stream */
+#endif /* EGL_KHR_stream_cross_process_fd */
+
+#ifndef EGL_KHR_stream_fifo
+#define EGL_KHR_stream_fifo 1
+#ifdef EGL_KHR_stream
+#define EGL_STREAM_FIFO_LENGTH_KHR 0x31FC
+#define EGL_STREAM_TIME_NOW_KHR 0x31FD
+#define EGL_STREAM_TIME_CONSUMER_KHR 0x31FE
+#define EGL_STREAM_TIME_PRODUCER_KHR 0x31FF
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMTIMEKHRPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLTimeKHR *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamTimeKHR (EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLTimeKHR *value);
+#endif
+#endif /* EGL_KHR_stream */
+#endif /* EGL_KHR_stream_fifo */
+
+#ifndef EGL_KHR_stream_producer_aldatalocator
+#define EGL_KHR_stream_producer_aldatalocator 1
+#ifdef EGL_KHR_stream
+#endif /* EGL_KHR_stream */
+#endif /* EGL_KHR_stream_producer_aldatalocator */
+
+#ifndef EGL_KHR_stream_producer_eglsurface
+#define EGL_KHR_stream_producer_eglsurface 1
+#ifdef EGL_KHR_stream
+#define EGL_STREAM_BIT_KHR 0x0800
+typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATESTREAMPRODUCERSURFACEKHRPROC) (EGLDisplay dpy, EGLConfig config, EGLStreamKHR stream, const EGLint *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSurface EGLAPIENTRY eglCreateStreamProducerSurfaceKHR (EGLDisplay dpy, EGLConfig config, EGLStreamKHR stream, const EGLint *attrib_list);
+#endif
+#endif /* EGL_KHR_stream */
+#endif /* EGL_KHR_stream_producer_eglsurface */
+
+#ifndef EGL_KHR_surfaceless_context
+#define EGL_KHR_surfaceless_context 1
+#endif /* EGL_KHR_surfaceless_context */
+
+#ifndef EGL_KHR_swap_buffers_with_damage
+#define EGL_KHR_swap_buffers_with_damage 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSWITHDAMAGEKHRPROC) (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffersWithDamageKHR (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
+#endif
+#endif /* EGL_KHR_swap_buffers_with_damage */
+
+#ifndef EGL_KHR_vg_parent_image
+#define EGL_KHR_vg_parent_image 1
+#define EGL_VG_PARENT_IMAGE_KHR 0x30BA
+#endif /* EGL_KHR_vg_parent_image */
+
+#ifndef EGL_KHR_wait_sync
+#define EGL_KHR_wait_sync 1
+typedef EGLint (EGLAPIENTRYP PFNEGLWAITSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLint EGLAPIENTRY eglWaitSyncKHR (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags);
+#endif
+#endif /* EGL_KHR_wait_sync */
+
+#ifndef EGL_ANDROID_blob_cache
+#define EGL_ANDROID_blob_cache 1
+typedef khronos_ssize_t EGLsizeiANDROID;
+typedef void (*EGLSetBlobFuncANDROID) (const void *key, EGLsizeiANDROID keySize, const void *value, EGLsizeiANDROID valueSize);
+typedef EGLsizeiANDROID (*EGLGetBlobFuncANDROID) (const void *key, EGLsizeiANDROID keySize, void *value, EGLsizeiANDROID valueSize);
+typedef void (EGLAPIENTRYP PFNEGLSETBLOBCACHEFUNCSANDROIDPROC) (EGLDisplay dpy, EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI void EGLAPIENTRY eglSetBlobCacheFuncsANDROID (EGLDisplay dpy, EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get);
+#endif
+#endif /* EGL_ANDROID_blob_cache */
+
+#ifndef EGL_ANDROID_create_native_client_buffer
+#define EGL_ANDROID_create_native_client_buffer 1
+#define EGL_NATIVE_BUFFER_USAGE_ANDROID 0x3143
+#define EGL_NATIVE_BUFFER_USAGE_PROTECTED_BIT_ANDROID 0x00000001
+#define EGL_NATIVE_BUFFER_USAGE_RENDERBUFFER_BIT_ANDROID 0x00000002
+#define EGL_NATIVE_BUFFER_USAGE_TEXTURE_BIT_ANDROID 0x00000004
+typedef EGLClientBuffer (EGLAPIENTRYP PFNEGLCREATENATIVECLIENTBUFFERANDROIDPROC) (const EGLint *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLClientBuffer EGLAPIENTRY eglCreateNativeClientBufferANDROID (const EGLint *attrib_list);
+#endif
+#endif /* EGL_ANDROID_create_native_client_buffer */
+
+#ifndef EGL_ANDROID_framebuffer_target
+#define EGL_ANDROID_framebuffer_target 1
+#define EGL_FRAMEBUFFER_TARGET_ANDROID 0x3147
+#endif /* EGL_ANDROID_framebuffer_target */
+
+#ifndef EGL_ANDROID_front_buffer_auto_refresh
+#define EGL_ANDROID_front_buffer_auto_refresh 1
+#define EGL_FRONT_BUFFER_AUTO_REFRESH_ANDROID 0x314C
+#endif /* EGL_ANDROID_front_buffer_auto_refresh */
+
+#ifndef EGL_ANDROID_image_native_buffer
+#define EGL_ANDROID_image_native_buffer 1
+#define EGL_NATIVE_BUFFER_ANDROID 0x3140
+#endif /* EGL_ANDROID_image_native_buffer */
+
+#ifndef EGL_ANDROID_native_fence_sync
+#define EGL_ANDROID_native_fence_sync 1
+#define EGL_SYNC_NATIVE_FENCE_ANDROID 0x3144
+#define EGL_SYNC_NATIVE_FENCE_FD_ANDROID 0x3145
+#define EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID 0x3146
+#define EGL_NO_NATIVE_FENCE_FD_ANDROID -1
+typedef EGLint (EGLAPIENTRYP PFNEGLDUPNATIVEFENCEFDANDROIDPROC) (EGLDisplay dpy, EGLSyncKHR sync);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLint EGLAPIENTRY eglDupNativeFenceFDANDROID (EGLDisplay dpy, EGLSyncKHR sync);
+#endif
+#endif /* EGL_ANDROID_native_fence_sync */
+
+#ifndef EGL_ANDROID_presentation_time
+#define EGL_ANDROID_presentation_time 1
+typedef khronos_stime_nanoseconds_t EGLnsecsANDROID;
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLPRESENTATIONTIMEANDROIDPROC) (EGLDisplay dpy, EGLSurface surface, EGLnsecsANDROID time);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglPresentationTimeANDROID (EGLDisplay dpy, EGLSurface surface, EGLnsecsANDROID time);
+#endif
+#endif /* EGL_ANDROID_presentation_time */
+
+#ifndef EGL_ANDROID_recordable
+#define EGL_ANDROID_recordable 1
+#define EGL_RECORDABLE_ANDROID 0x3142
+#endif /* EGL_ANDROID_recordable */
+
+#ifndef EGL_ANGLE_d3d_share_handle_client_buffer
+#define EGL_ANGLE_d3d_share_handle_client_buffer 1
+#define EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE 0x3200
+#endif /* EGL_ANGLE_d3d_share_handle_client_buffer */
+
+#ifndef EGL_ANGLE_device_d3d
+#define EGL_ANGLE_device_d3d 1
+#define EGL_D3D9_DEVICE_ANGLE 0x33A0
+#define EGL_D3D11_DEVICE_ANGLE 0x33A1
+#endif /* EGL_ANGLE_device_d3d */
+
+#ifndef EGL_ANGLE_query_surface_pointer
+#define EGL_ANGLE_query_surface_pointer 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSURFACEPOINTERANGLEPROC) (EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurfacePointerANGLE (EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value);
+#endif
+#endif /* EGL_ANGLE_query_surface_pointer */
+
+#ifndef EGL_ANGLE_surface_d3d_texture_2d_share_handle
+#define EGL_ANGLE_surface_d3d_texture_2d_share_handle 1
+#endif /* EGL_ANGLE_surface_d3d_texture_2d_share_handle */
+
+#ifndef EGL_ANGLE_window_fixed_size
+#define EGL_ANGLE_window_fixed_size 1
+#define EGL_FIXED_SIZE_ANGLE 0x3201
+#endif /* EGL_ANGLE_window_fixed_size */
+
+#ifndef EGL_ARM_implicit_external_sync
+#define EGL_ARM_implicit_external_sync 1
+#define EGL_SYNC_PRIOR_COMMANDS_IMPLICIT_EXTERNAL_ARM 0x328A
+#endif /* EGL_ARM_implicit_external_sync */
+
+#ifndef EGL_ARM_pixmap_multisample_discard
+#define EGL_ARM_pixmap_multisample_discard 1
+#define EGL_DISCARD_SAMPLES_ARM 0x3286
+#endif /* EGL_ARM_pixmap_multisample_discard */
+
+#ifndef EGL_EXT_bind_to_front
+#define EGL_EXT_bind_to_front 1
+#define EGL_FRONT_BUFFER_EXT 0x3464
+#endif /* EGL_EXT_bind_to_front */
+
+#ifndef EGL_EXT_buffer_age
+#define EGL_EXT_buffer_age 1
+#define EGL_BUFFER_AGE_EXT 0x313D
+#endif /* EGL_EXT_buffer_age */
+
+#ifndef EGL_EXT_client_extensions
+#define EGL_EXT_client_extensions 1
+#endif /* EGL_EXT_client_extensions */
+
+#ifndef EGL_EXT_compositor
+#define EGL_EXT_compositor 1
+#define EGL_PRIMARY_COMPOSITOR_CONTEXT_EXT 0x3460
+#define EGL_EXTERNAL_REF_ID_EXT 0x3461
+#define EGL_COMPOSITOR_DROP_NEWEST_FRAME_EXT 0x3462
+#define EGL_COMPOSITOR_KEEP_NEWEST_FRAME_EXT 0x3463
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOMPOSITORSETCONTEXTLISTEXTPROC) (const EGLint *external_ref_ids, EGLint num_entries);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOMPOSITORSETCONTEXTATTRIBUTESEXTPROC) (EGLint external_ref_id, const EGLint *context_attributes, EGLint num_entries);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOMPOSITORSETWINDOWLISTEXTPROC) (EGLint external_ref_id, const EGLint *external_win_ids, EGLint num_entries);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOMPOSITORSETWINDOWATTRIBUTESEXTPROC) (EGLint external_win_id, const EGLint *window_attributes, EGLint num_entries);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOMPOSITORBINDTEXWINDOWEXTPROC) (EGLint external_win_id);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOMPOSITORSETSIZEEXTPROC) (EGLint external_win_id, EGLint width, EGLint height);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLCOMPOSITORSWAPPOLICYEXTPROC) (EGLint external_win_id, EGLint policy);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglCompositorSetContextListEXT (const EGLint *external_ref_ids, EGLint num_entries);
+EGLAPI EGLBoolean EGLAPIENTRY eglCompositorSetContextAttributesEXT (EGLint external_ref_id, const EGLint *context_attributes, EGLint num_entries);
+EGLAPI EGLBoolean EGLAPIENTRY eglCompositorSetWindowListEXT (EGLint external_ref_id, const EGLint *external_win_ids, EGLint num_entries);
+EGLAPI EGLBoolean EGLAPIENTRY eglCompositorSetWindowAttributesEXT (EGLint external_win_id, const EGLint *window_attributes, EGLint num_entries);
+EGLAPI EGLBoolean EGLAPIENTRY eglCompositorBindTexWindowEXT (EGLint external_win_id);
+EGLAPI EGLBoolean EGLAPIENTRY eglCompositorSetSizeEXT (EGLint external_win_id, EGLint width, EGLint height);
+EGLAPI EGLBoolean EGLAPIENTRY eglCompositorSwapPolicyEXT (EGLint external_win_id, EGLint policy);
+#endif
+#endif /* EGL_EXT_compositor */
+
+#ifndef EGL_EXT_create_context_robustness
+#define EGL_EXT_create_context_robustness 1
+#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT 0x30BF
+#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT 0x3138
+#define EGL_NO_RESET_NOTIFICATION_EXT 0x31BE
+#define EGL_LOSE_CONTEXT_ON_RESET_EXT 0x31BF
+#endif /* EGL_EXT_create_context_robustness */
+
+#ifndef EGL_EXT_device_base
+#define EGL_EXT_device_base 1
+typedef void *EGLDeviceEXT;
+#define EGL_NO_DEVICE_EXT EGL_CAST(EGLDeviceEXT,0)
+#define EGL_BAD_DEVICE_EXT 0x322B
+#define EGL_DEVICE_EXT 0x322C
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDEVICEATTRIBEXTPROC) (EGLDeviceEXT device, EGLint attribute, EGLAttrib *value);
+typedef const char *(EGLAPIENTRYP PFNEGLQUERYDEVICESTRINGEXTPROC) (EGLDeviceEXT device, EGLint name);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDEVICESEXTPROC) (EGLint max_devices, EGLDeviceEXT *devices, EGLint *num_devices);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDISPLAYATTRIBEXTPROC) (EGLDisplay dpy, EGLint attribute, EGLAttrib *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryDeviceAttribEXT (EGLDeviceEXT device, EGLint attribute, EGLAttrib *value);
+EGLAPI const char *EGLAPIENTRY eglQueryDeviceStringEXT (EGLDeviceEXT device, EGLint name);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryDevicesEXT (EGLint max_devices, EGLDeviceEXT *devices, EGLint *num_devices);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryDisplayAttribEXT (EGLDisplay dpy, EGLint attribute, EGLAttrib *value);
+#endif
+#endif /* EGL_EXT_device_base */
+
+#ifndef EGL_EXT_device_drm
+#define EGL_EXT_device_drm 1
+#define EGL_DRM_DEVICE_FILE_EXT 0x3233
+#endif /* EGL_EXT_device_drm */
+
+#ifndef EGL_EXT_device_enumeration
+#define EGL_EXT_device_enumeration 1
+#endif /* EGL_EXT_device_enumeration */
+
+#ifndef EGL_EXT_device_openwf
+#define EGL_EXT_device_openwf 1
+#define EGL_OPENWF_DEVICE_ID_EXT 0x3237
+#endif /* EGL_EXT_device_openwf */
+
+#ifndef EGL_EXT_device_query
+#define EGL_EXT_device_query 1
+#endif /* EGL_EXT_device_query */
+
+#ifndef EGL_EXT_gl_colorspace_bt2020_linear
+#define EGL_EXT_gl_colorspace_bt2020_linear 1
+#define EGL_GL_COLORSPACE_BT2020_LINEAR_EXT 0x333F
+#endif /* EGL_EXT_gl_colorspace_bt2020_linear */
+
+#ifndef EGL_EXT_gl_colorspace_bt2020_pq
+#define EGL_EXT_gl_colorspace_bt2020_pq 1
+#define EGL_GL_COLORSPACE_BT2020_PQ_EXT 0x3340
+#endif /* EGL_EXT_gl_colorspace_bt2020_pq */
+
+#ifndef EGL_EXT_gl_colorspace_display_p3
+#define EGL_EXT_gl_colorspace_display_p3 1
+#define EGL_GL_COLORSPACE_DISPLAY_P3_EXT 0x3363
+#endif /* EGL_EXT_gl_colorspace_display_p3 */
+
+#ifndef EGL_EXT_gl_colorspace_display_p3_linear
+#define EGL_EXT_gl_colorspace_display_p3_linear 1
+#define EGL_GL_COLORSPACE_DISPLAY_P3_LINEAR_EXT 0x3362
+#endif /* EGL_EXT_gl_colorspace_display_p3_linear */
+
+#ifndef EGL_EXT_gl_colorspace_scrgb
+#define EGL_EXT_gl_colorspace_scrgb 1
+#define EGL_GL_COLORSPACE_SCRGB_EXT 0x3351
+#endif /* EGL_EXT_gl_colorspace_scrgb */
+
+#ifndef EGL_EXT_gl_colorspace_scrgb_linear
+#define EGL_EXT_gl_colorspace_scrgb_linear 1
+#define EGL_GL_COLORSPACE_SCRGB_LINEAR_EXT 0x3350
+#endif /* EGL_EXT_gl_colorspace_scrgb_linear */
+
+#ifndef EGL_EXT_image_dma_buf_import
+#define EGL_EXT_image_dma_buf_import 1
+#define EGL_LINUX_DMA_BUF_EXT 0x3270
+#define EGL_LINUX_DRM_FOURCC_EXT 0x3271
+#define EGL_DMA_BUF_PLANE0_FD_EXT 0x3272
+#define EGL_DMA_BUF_PLANE0_OFFSET_EXT 0x3273
+#define EGL_DMA_BUF_PLANE0_PITCH_EXT 0x3274
+#define EGL_DMA_BUF_PLANE1_FD_EXT 0x3275
+#define EGL_DMA_BUF_PLANE1_OFFSET_EXT 0x3276
+#define EGL_DMA_BUF_PLANE1_PITCH_EXT 0x3277
+#define EGL_DMA_BUF_PLANE2_FD_EXT 0x3278
+#define EGL_DMA_BUF_PLANE2_OFFSET_EXT 0x3279
+#define EGL_DMA_BUF_PLANE2_PITCH_EXT 0x327A
+#define EGL_YUV_COLOR_SPACE_HINT_EXT 0x327B
+#define EGL_SAMPLE_RANGE_HINT_EXT 0x327C
+#define EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT 0x327D
+#define EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT 0x327E
+#define EGL_ITU_REC601_EXT 0x327F
+#define EGL_ITU_REC709_EXT 0x3280
+#define EGL_ITU_REC2020_EXT 0x3281
+#define EGL_YUV_FULL_RANGE_EXT 0x3282
+#define EGL_YUV_NARROW_RANGE_EXT 0x3283
+#define EGL_YUV_CHROMA_SITING_0_EXT 0x3284
+#define EGL_YUV_CHROMA_SITING_0_5_EXT 0x3285
+#endif /* EGL_EXT_image_dma_buf_import */
+
+#ifndef EGL_EXT_image_dma_buf_import_modifiers
+#define EGL_EXT_image_dma_buf_import_modifiers 1
+#define EGL_DMA_BUF_PLANE3_FD_EXT 0x3440
+#define EGL_DMA_BUF_PLANE3_OFFSET_EXT 0x3441
+#define EGL_DMA_BUF_PLANE3_PITCH_EXT 0x3442
+#define EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT 0x3443
+#define EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT 0x3444
+#define EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT 0x3445
+#define EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT 0x3446
+#define EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT 0x3447
+#define EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT 0x3448
+#define EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT 0x3449
+#define EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT 0x344A
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDMABUFFORMATSEXTPROC) (EGLDisplay dpy, EGLint max_formats, EGLint *formats, EGLint *num_formats);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDMABUFMODIFIERSEXTPROC) (EGLDisplay dpy, EGLint format, EGLint max_modifiers, EGLuint64KHR *modifiers, EGLBoolean *external_only, EGLint *num_modifiers);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryDmaBufFormatsEXT (EGLDisplay dpy, EGLint max_formats, EGLint *formats, EGLint *num_formats);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryDmaBufModifiersEXT (EGLDisplay dpy, EGLint format, EGLint max_modifiers, EGLuint64KHR *modifiers, EGLBoolean *external_only, EGLint *num_modifiers);
+#endif
+#endif /* EGL_EXT_image_dma_buf_import_modifiers */
+
+#ifndef EGL_EXT_image_implicit_sync_control
+#define EGL_EXT_image_implicit_sync_control 1
+#define EGL_IMPORT_SYNC_TYPE_EXT 0x3470
+#define EGL_IMPORT_IMPLICIT_SYNC_EXT 0x3471
+#define EGL_IMPORT_EXPLICIT_SYNC_EXT 0x3472
+#endif /* EGL_EXT_image_implicit_sync_control */
+
+#ifndef EGL_EXT_multiview_window
+#define EGL_EXT_multiview_window 1
+#define EGL_MULTIVIEW_VIEW_COUNT_EXT 0x3134
+#endif /* EGL_EXT_multiview_window */
+
+#ifndef EGL_EXT_output_base
+#define EGL_EXT_output_base 1
+typedef void *EGLOutputLayerEXT;
+typedef void *EGLOutputPortEXT;
+#define EGL_NO_OUTPUT_LAYER_EXT EGL_CAST(EGLOutputLayerEXT,0)
+#define EGL_NO_OUTPUT_PORT_EXT EGL_CAST(EGLOutputPortEXT,0)
+#define EGL_BAD_OUTPUT_LAYER_EXT 0x322D
+#define EGL_BAD_OUTPUT_PORT_EXT 0x322E
+#define EGL_SWAP_INTERVAL_EXT 0x322F
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETOUTPUTLAYERSEXTPROC) (EGLDisplay dpy, const EGLAttrib *attrib_list, EGLOutputLayerEXT *layers, EGLint max_layers, EGLint *num_layers);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETOUTPUTPORTSEXTPROC) (EGLDisplay dpy, const EGLAttrib *attrib_list, EGLOutputPortEXT *ports, EGLint max_ports, EGLint *num_ports);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLOUTPUTLAYERATTRIBEXTPROC) (EGLDisplay dpy, EGLOutputLayerEXT layer, EGLint attribute, EGLAttrib value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYOUTPUTLAYERATTRIBEXTPROC) (EGLDisplay dpy, EGLOutputLayerEXT layer, EGLint attribute, EGLAttrib *value);
+typedef const char *(EGLAPIENTRYP PFNEGLQUERYOUTPUTLAYERSTRINGEXTPROC) (EGLDisplay dpy, EGLOutputLayerEXT layer, EGLint name);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLOUTPUTPORTATTRIBEXTPROC) (EGLDisplay dpy, EGLOutputPortEXT port, EGLint attribute, EGLAttrib value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYOUTPUTPORTATTRIBEXTPROC) (EGLDisplay dpy, EGLOutputPortEXT port, EGLint attribute, EGLAttrib *value);
+typedef const char *(EGLAPIENTRYP PFNEGLQUERYOUTPUTPORTSTRINGEXTPROC) (EGLDisplay dpy, EGLOutputPortEXT port, EGLint name);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglGetOutputLayersEXT (EGLDisplay dpy, const EGLAttrib *attrib_list, EGLOutputLayerEXT *layers, EGLint max_layers, EGLint *num_layers);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetOutputPortsEXT (EGLDisplay dpy, const EGLAttrib *attrib_list, EGLOutputPortEXT *ports, EGLint max_ports, EGLint *num_ports);
+EGLAPI EGLBoolean EGLAPIENTRY eglOutputLayerAttribEXT (EGLDisplay dpy, EGLOutputLayerEXT layer, EGLint attribute, EGLAttrib value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryOutputLayerAttribEXT (EGLDisplay dpy, EGLOutputLayerEXT layer, EGLint attribute, EGLAttrib *value);
+EGLAPI const char *EGLAPIENTRY eglQueryOutputLayerStringEXT (EGLDisplay dpy, EGLOutputLayerEXT layer, EGLint name);
+EGLAPI EGLBoolean EGLAPIENTRY eglOutputPortAttribEXT (EGLDisplay dpy, EGLOutputPortEXT port, EGLint attribute, EGLAttrib value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryOutputPortAttribEXT (EGLDisplay dpy, EGLOutputPortEXT port, EGLint attribute, EGLAttrib *value);
+EGLAPI const char *EGLAPIENTRY eglQueryOutputPortStringEXT (EGLDisplay dpy, EGLOutputPortEXT port, EGLint name);
+#endif
+#endif /* EGL_EXT_output_base */
+
+#ifndef EGL_EXT_output_drm
+#define EGL_EXT_output_drm 1
+#define EGL_DRM_CRTC_EXT 0x3234
+#define EGL_DRM_PLANE_EXT 0x3235
+#define EGL_DRM_CONNECTOR_EXT 0x3236
+#endif /* EGL_EXT_output_drm */
+
+#ifndef EGL_EXT_output_openwf
+#define EGL_EXT_output_openwf 1
+#define EGL_OPENWF_PIPELINE_ID_EXT 0x3238
+#define EGL_OPENWF_PORT_ID_EXT 0x3239
+#endif /* EGL_EXT_output_openwf */
+
+#ifndef EGL_EXT_pixel_format_float
+#define EGL_EXT_pixel_format_float 1
+#define EGL_COLOR_COMPONENT_TYPE_EXT 0x3339
+#define EGL_COLOR_COMPONENT_TYPE_FIXED_EXT 0x333A
+#define EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT 0x333B
+#endif /* EGL_EXT_pixel_format_float */
+
+#ifndef EGL_EXT_platform_base
+#define EGL_EXT_platform_base 1
+typedef EGLDisplay (EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC) (EGLenum platform, void *native_display, const EGLint *attrib_list);
+typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC) (EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list);
+typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPLATFORMPIXMAPSURFACEEXTPROC) (EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLint *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplayEXT (EGLenum platform, void *native_display, const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformWindowSurfaceEXT (EGLDisplay dpy, EGLConfig config, void *native_window, const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePlatformPixmapSurfaceEXT (EGLDisplay dpy, EGLConfig config, void *native_pixmap, const EGLint *attrib_list);
+#endif
+#endif /* EGL_EXT_platform_base */
+
+#ifndef EGL_EXT_platform_device
+#define EGL_EXT_platform_device 1
+#define EGL_PLATFORM_DEVICE_EXT 0x313F
+#endif /* EGL_EXT_platform_device */
+
+#ifndef EGL_EXT_platform_wayland
+#define EGL_EXT_platform_wayland 1
+#define EGL_PLATFORM_WAYLAND_EXT 0x31D8
+#endif /* EGL_EXT_platform_wayland */
+
+#ifndef EGL_EXT_platform_x11
+#define EGL_EXT_platform_x11 1
+#define EGL_PLATFORM_X11_EXT 0x31D5
+#define EGL_PLATFORM_X11_SCREEN_EXT 0x31D6
+#endif /* EGL_EXT_platform_x11 */
+
+#ifndef EGL_EXT_protected_content
+#define EGL_EXT_protected_content 1
+#define EGL_PROTECTED_CONTENT_EXT 0x32C0
+#endif /* EGL_EXT_protected_content */
+
+#ifndef EGL_EXT_protected_surface
+#define EGL_EXT_protected_surface 1
+#endif /* EGL_EXT_protected_surface */
+
+#ifndef EGL_EXT_stream_consumer_egloutput
+#define EGL_EXT_stream_consumer_egloutput 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMEROUTPUTEXTPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLOutputLayerEXT layer);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerOutputEXT (EGLDisplay dpy, EGLStreamKHR stream, EGLOutputLayerEXT layer);
+#endif
+#endif /* EGL_EXT_stream_consumer_egloutput */
+
+#ifndef EGL_EXT_surface_CTA861_3_metadata
+#define EGL_EXT_surface_CTA861_3_metadata 1
+#define EGL_CTA861_3_MAX_CONTENT_LIGHT_LEVEL_EXT 0x3360
+#define EGL_CTA861_3_MAX_FRAME_AVERAGE_LEVEL_EXT 0x3361
+#endif /* EGL_EXT_surface_CTA861_3_metadata */
+
+#ifndef EGL_EXT_surface_SMPTE2086_metadata
+#define EGL_EXT_surface_SMPTE2086_metadata 1
+#define EGL_SMPTE2086_DISPLAY_PRIMARY_RX_EXT 0x3341
+#define EGL_SMPTE2086_DISPLAY_PRIMARY_RY_EXT 0x3342
+#define EGL_SMPTE2086_DISPLAY_PRIMARY_GX_EXT 0x3343
+#define EGL_SMPTE2086_DISPLAY_PRIMARY_GY_EXT 0x3344
+#define EGL_SMPTE2086_DISPLAY_PRIMARY_BX_EXT 0x3345
+#define EGL_SMPTE2086_DISPLAY_PRIMARY_BY_EXT 0x3346
+#define EGL_SMPTE2086_WHITE_POINT_X_EXT 0x3347
+#define EGL_SMPTE2086_WHITE_POINT_Y_EXT 0x3348
+#define EGL_SMPTE2086_MAX_LUMINANCE_EXT 0x3349
+#define EGL_SMPTE2086_MIN_LUMINANCE_EXT 0x334A
+#define EGL_METADATA_SCALING_EXT 50000
+#endif /* EGL_EXT_surface_SMPTE2086_metadata */
+
+#ifndef EGL_EXT_swap_buffers_with_damage
+#define EGL_EXT_swap_buffers_with_damage 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC) (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffersWithDamageEXT (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
+#endif
+#endif /* EGL_EXT_swap_buffers_with_damage */
+
+#ifndef EGL_EXT_yuv_surface
+#define EGL_EXT_yuv_surface 1
+#define EGL_YUV_ORDER_EXT 0x3301
+#define EGL_YUV_NUMBER_OF_PLANES_EXT 0x3311
+#define EGL_YUV_SUBSAMPLE_EXT 0x3312
+#define EGL_YUV_DEPTH_RANGE_EXT 0x3317
+#define EGL_YUV_CSC_STANDARD_EXT 0x330A
+#define EGL_YUV_PLANE_BPP_EXT 0x331A
+#define EGL_YUV_BUFFER_EXT 0x3300
+#define EGL_YUV_ORDER_YUV_EXT 0x3302
+#define EGL_YUV_ORDER_YVU_EXT 0x3303
+#define EGL_YUV_ORDER_YUYV_EXT 0x3304
+#define EGL_YUV_ORDER_UYVY_EXT 0x3305
+#define EGL_YUV_ORDER_YVYU_EXT 0x3306
+#define EGL_YUV_ORDER_VYUY_EXT 0x3307
+#define EGL_YUV_ORDER_AYUV_EXT 0x3308
+#define EGL_YUV_SUBSAMPLE_4_2_0_EXT 0x3313
+#define EGL_YUV_SUBSAMPLE_4_2_2_EXT 0x3314
+#define EGL_YUV_SUBSAMPLE_4_4_4_EXT 0x3315
+#define EGL_YUV_DEPTH_RANGE_LIMITED_EXT 0x3318
+#define EGL_YUV_DEPTH_RANGE_FULL_EXT 0x3319
+#define EGL_YUV_CSC_STANDARD_601_EXT 0x330B
+#define EGL_YUV_CSC_STANDARD_709_EXT 0x330C
+#define EGL_YUV_CSC_STANDARD_2020_EXT 0x330D
+#define EGL_YUV_PLANE_BPP_0_EXT 0x331B
+#define EGL_YUV_PLANE_BPP_8_EXT 0x331C
+#define EGL_YUV_PLANE_BPP_10_EXT 0x331D
+#endif /* EGL_EXT_yuv_surface */
+
+#ifndef EGL_HI_clientpixmap
+#define EGL_HI_clientpixmap 1
+struct EGLClientPixmapHI {
+ void *pData;
+ EGLint iWidth;
+ EGLint iHeight;
+ EGLint iStride;
+};
+#define EGL_CLIENT_PIXMAP_POINTER_HI 0x8F74
+typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPIXMAPSURFACEHIPROC) (EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI *pixmap);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurfaceHI (EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI *pixmap);
+#endif
+#endif /* EGL_HI_clientpixmap */
+
+#ifndef EGL_HI_colorformats
+#define EGL_HI_colorformats 1
+#define EGL_COLOR_FORMAT_HI 0x8F70
+#define EGL_COLOR_RGB_HI 0x8F71
+#define EGL_COLOR_RGBA_HI 0x8F72
+#define EGL_COLOR_ARGB_HI 0x8F73
+#endif /* EGL_HI_colorformats */
+
+#ifndef EGL_IMG_context_priority
+#define EGL_IMG_context_priority 1
+#define EGL_CONTEXT_PRIORITY_LEVEL_IMG 0x3100
+#define EGL_CONTEXT_PRIORITY_HIGH_IMG 0x3101
+#define EGL_CONTEXT_PRIORITY_MEDIUM_IMG 0x3102
+#define EGL_CONTEXT_PRIORITY_LOW_IMG 0x3103
+#endif /* EGL_IMG_context_priority */
+
+#ifndef EGL_IMG_image_plane_attribs
+#define EGL_IMG_image_plane_attribs 1
+#define EGL_NATIVE_BUFFER_MULTIPLANE_SEPARATE_IMG 0x3105
+#define EGL_NATIVE_BUFFER_PLANE_OFFSET_IMG 0x3106
+#endif /* EGL_IMG_image_plane_attribs */
+
+#ifndef EGL_MESA_drm_image
+#define EGL_MESA_drm_image 1
+#define EGL_DRM_BUFFER_FORMAT_MESA 0x31D0
+#define EGL_DRM_BUFFER_USE_MESA 0x31D1
+#define EGL_DRM_BUFFER_FORMAT_ARGB32_MESA 0x31D2
+#define EGL_DRM_BUFFER_MESA 0x31D3
+#define EGL_DRM_BUFFER_STRIDE_MESA 0x31D4
+#define EGL_DRM_BUFFER_USE_SCANOUT_MESA 0x00000001
+#define EGL_DRM_BUFFER_USE_SHARE_MESA 0x00000002
+typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEDRMIMAGEMESAPROC) (EGLDisplay dpy, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDRMIMAGEMESAPROC) (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLImageKHR EGLAPIENTRY eglCreateDRMImageMESA (EGLDisplay dpy, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglExportDRMImageMESA (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride);
+#endif
+#endif /* EGL_MESA_drm_image */
+
+#ifndef EGL_MESA_image_dma_buf_export
+#define EGL_MESA_image_dma_buf_export 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDMABUFIMAGEQUERYMESAPROC) (EGLDisplay dpy, EGLImageKHR image, int *fourcc, int *num_planes, EGLuint64KHR *modifiers);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDMABUFIMAGEMESAPROC) (EGLDisplay dpy, EGLImageKHR image, int *fds, EGLint *strides, EGLint *offsets);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglExportDMABUFImageQueryMESA (EGLDisplay dpy, EGLImageKHR image, int *fourcc, int *num_planes, EGLuint64KHR *modifiers);
+EGLAPI EGLBoolean EGLAPIENTRY eglExportDMABUFImageMESA (EGLDisplay dpy, EGLImageKHR image, int *fds, EGLint *strides, EGLint *offsets);
+#endif
+#endif /* EGL_MESA_image_dma_buf_export */
+
+#ifndef EGL_MESA_platform_gbm
+#define EGL_MESA_platform_gbm 1
+#define EGL_PLATFORM_GBM_MESA 0x31D7
+#endif /* EGL_MESA_platform_gbm */
+
+#ifndef EGL_MESA_platform_surfaceless
+#define EGL_MESA_platform_surfaceless 1
+#define EGL_PLATFORM_SURFACELESS_MESA 0x31DD
+#endif /* EGL_MESA_platform_surfaceless */
+
+#ifndef EGL_NOK_swap_region
+#define EGL_NOK_swap_region 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSREGIONNOKPROC) (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint *rects);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffersRegionNOK (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint *rects);
+#endif
+#endif /* EGL_NOK_swap_region */
+
+#ifndef EGL_NOK_swap_region2
+#define EGL_NOK_swap_region2 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSREGION2NOKPROC) (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint *rects);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffersRegion2NOK (EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint *rects);
+#endif
+#endif /* EGL_NOK_swap_region2 */
+
+#ifndef EGL_NOK_texture_from_pixmap
+#define EGL_NOK_texture_from_pixmap 1
+#define EGL_Y_INVERTED_NOK 0x307F
+#endif /* EGL_NOK_texture_from_pixmap */
+
+#ifndef EGL_NV_3dvision_surface
+#define EGL_NV_3dvision_surface 1
+#define EGL_AUTO_STEREO_NV 0x3136
+#endif /* EGL_NV_3dvision_surface */
+
+#ifndef EGL_NV_coverage_sample
+#define EGL_NV_coverage_sample 1
+#define EGL_COVERAGE_BUFFERS_NV 0x30E0
+#define EGL_COVERAGE_SAMPLES_NV 0x30E1
+#endif /* EGL_NV_coverage_sample */
+
+#ifndef EGL_NV_coverage_sample_resolve
+#define EGL_NV_coverage_sample_resolve 1
+#define EGL_COVERAGE_SAMPLE_RESOLVE_NV 0x3131
+#define EGL_COVERAGE_SAMPLE_RESOLVE_DEFAULT_NV 0x3132
+#define EGL_COVERAGE_SAMPLE_RESOLVE_NONE_NV 0x3133
+#endif /* EGL_NV_coverage_sample_resolve */
+
+#ifndef EGL_NV_cuda_event
+#define EGL_NV_cuda_event 1
+#define EGL_CUDA_EVENT_HANDLE_NV 0x323B
+#define EGL_SYNC_CUDA_EVENT_NV 0x323C
+#define EGL_SYNC_CUDA_EVENT_COMPLETE_NV 0x323D
+#endif /* EGL_NV_cuda_event */
+
+#ifndef EGL_NV_depth_nonlinear
+#define EGL_NV_depth_nonlinear 1
+#define EGL_DEPTH_ENCODING_NV 0x30E2
+#define EGL_DEPTH_ENCODING_NONE_NV 0
+#define EGL_DEPTH_ENCODING_NONLINEAR_NV 0x30E3
+#endif /* EGL_NV_depth_nonlinear */
+
+#ifndef EGL_NV_device_cuda
+#define EGL_NV_device_cuda 1
+#define EGL_CUDA_DEVICE_NV 0x323A
+#endif /* EGL_NV_device_cuda */
+
+#ifndef EGL_NV_native_query
+#define EGL_NV_native_query 1
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYNATIVEDISPLAYNVPROC) (EGLDisplay dpy, EGLNativeDisplayType *display_id);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYNATIVEWINDOWNVPROC) (EGLDisplay dpy, EGLSurface surf, EGLNativeWindowType *window);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYNATIVEPIXMAPNVPROC) (EGLDisplay dpy, EGLSurface surf, EGLNativePixmapType *pixmap);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryNativeDisplayNV (EGLDisplay dpy, EGLNativeDisplayType *display_id);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryNativeWindowNV (EGLDisplay dpy, EGLSurface surf, EGLNativeWindowType *window);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryNativePixmapNV (EGLDisplay dpy, EGLSurface surf, EGLNativePixmapType *pixmap);
+#endif
+#endif /* EGL_NV_native_query */
+
+#ifndef EGL_NV_post_convert_rounding
+#define EGL_NV_post_convert_rounding 1
+#endif /* EGL_NV_post_convert_rounding */
+
+#ifndef EGL_NV_post_sub_buffer
+#define EGL_NV_post_sub_buffer 1
+#define EGL_POST_SUB_BUFFER_SUPPORTED_NV 0x30BE
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLPOSTSUBBUFFERNVPROC) (EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, EGLint width, EGLint height);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglPostSubBufferNV (EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, EGLint width, EGLint height);
+#endif
+#endif /* EGL_NV_post_sub_buffer */
+
+#ifndef EGL_NV_robustness_video_memory_purge
+#define EGL_NV_robustness_video_memory_purge 1
+#define EGL_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV 0x334C
+#endif /* EGL_NV_robustness_video_memory_purge */
+
+#ifndef EGL_NV_stream_consumer_gltexture_yuv
+#define EGL_NV_stream_consumer_gltexture_yuv 1
+#define EGL_YUV_PLANE0_TEXTURE_UNIT_NV 0x332C
+#define EGL_YUV_PLANE1_TEXTURE_UNIT_NV 0x332D
+#define EGL_YUV_PLANE2_TEXTURE_UNIT_NV 0x332E
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERGLTEXTUREEXTERNALATTRIBSNVPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLAttrib *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerGLTextureExternalAttribsNV (EGLDisplay dpy, EGLStreamKHR stream, EGLAttrib *attrib_list);
+#endif
+#endif /* EGL_NV_stream_consumer_gltexture_yuv */
+
+#ifndef EGL_NV_stream_cross_display
+#define EGL_NV_stream_cross_display 1
+#define EGL_STREAM_CROSS_DISPLAY_NV 0x334E
+#endif /* EGL_NV_stream_cross_display */
+
+#ifndef EGL_NV_stream_cross_object
+#define EGL_NV_stream_cross_object 1
+#define EGL_STREAM_CROSS_OBJECT_NV 0x334D
+#endif /* EGL_NV_stream_cross_object */
+
+#ifndef EGL_NV_stream_cross_partition
+#define EGL_NV_stream_cross_partition 1
+#define EGL_STREAM_CROSS_PARTITION_NV 0x323F
+#endif /* EGL_NV_stream_cross_partition */
+
+#ifndef EGL_NV_stream_cross_process
+#define EGL_NV_stream_cross_process 1
+#define EGL_STREAM_CROSS_PROCESS_NV 0x3245
+#endif /* EGL_NV_stream_cross_process */
+
+#ifndef EGL_NV_stream_cross_system
+#define EGL_NV_stream_cross_system 1
+#define EGL_STREAM_CROSS_SYSTEM_NV 0x334F
+#endif /* EGL_NV_stream_cross_system */
+
+#ifndef EGL_NV_stream_fifo_next
+#define EGL_NV_stream_fifo_next 1
+#define EGL_PENDING_FRAME_NV 0x3329
+#define EGL_STREAM_TIME_PENDING_NV 0x332A
+#endif /* EGL_NV_stream_fifo_next */
+
+#ifndef EGL_NV_stream_fifo_synchronous
+#define EGL_NV_stream_fifo_synchronous 1
+#define EGL_STREAM_FIFO_SYNCHRONOUS_NV 0x3336
+#endif /* EGL_NV_stream_fifo_synchronous */
+
+#ifndef EGL_NV_stream_frame_limits
+#define EGL_NV_stream_frame_limits 1
+#define EGL_PRODUCER_MAX_FRAME_HINT_NV 0x3337
+#define EGL_CONSUMER_MAX_FRAME_HINT_NV 0x3338
+#endif /* EGL_NV_stream_frame_limits */
+
+#ifndef EGL_NV_stream_metadata
+#define EGL_NV_stream_metadata 1
+#define EGL_MAX_STREAM_METADATA_BLOCKS_NV 0x3250
+#define EGL_MAX_STREAM_METADATA_BLOCK_SIZE_NV 0x3251
+#define EGL_MAX_STREAM_METADATA_TOTAL_SIZE_NV 0x3252
+#define EGL_PRODUCER_METADATA_NV 0x3253
+#define EGL_CONSUMER_METADATA_NV 0x3254
+#define EGL_PENDING_METADATA_NV 0x3328
+#define EGL_METADATA0_SIZE_NV 0x3255
+#define EGL_METADATA1_SIZE_NV 0x3256
+#define EGL_METADATA2_SIZE_NV 0x3257
+#define EGL_METADATA3_SIZE_NV 0x3258
+#define EGL_METADATA0_TYPE_NV 0x3259
+#define EGL_METADATA1_TYPE_NV 0x325A
+#define EGL_METADATA2_TYPE_NV 0x325B
+#define EGL_METADATA3_TYPE_NV 0x325C
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDISPLAYATTRIBNVPROC) (EGLDisplay dpy, EGLint attribute, EGLAttrib *value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSETSTREAMMETADATANVPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLint n, EGLint offset, EGLint size, const void *data);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMMETADATANVPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum name, EGLint n, EGLint offset, EGLint size, void *data);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryDisplayAttribNV (EGLDisplay dpy, EGLint attribute, EGLAttrib *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglSetStreamMetadataNV (EGLDisplay dpy, EGLStreamKHR stream, EGLint n, EGLint offset, EGLint size, const void *data);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamMetadataNV (EGLDisplay dpy, EGLStreamKHR stream, EGLenum name, EGLint n, EGLint offset, EGLint size, void *data);
+#endif
+#endif /* EGL_NV_stream_metadata */
+
+#ifndef EGL_NV_stream_remote
+#define EGL_NV_stream_remote 1
+#define EGL_STREAM_STATE_INITIALIZING_NV 0x3240
+#define EGL_STREAM_TYPE_NV 0x3241
+#define EGL_STREAM_PROTOCOL_NV 0x3242
+#define EGL_STREAM_ENDPOINT_NV 0x3243
+#define EGL_STREAM_LOCAL_NV 0x3244
+#define EGL_STREAM_PRODUCER_NV 0x3247
+#define EGL_STREAM_CONSUMER_NV 0x3248
+#define EGL_STREAM_PROTOCOL_FD_NV 0x3246
+#endif /* EGL_NV_stream_remote */
+
+#ifndef EGL_NV_stream_reset
+#define EGL_NV_stream_reset 1
+#define EGL_SUPPORT_RESET_NV 0x3334
+#define EGL_SUPPORT_REUSE_NV 0x3335
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLRESETSTREAMNVPROC) (EGLDisplay dpy, EGLStreamKHR stream);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglResetStreamNV (EGLDisplay dpy, EGLStreamKHR stream);
+#endif
+#endif /* EGL_NV_stream_reset */
+
+#ifndef EGL_NV_stream_socket
+#define EGL_NV_stream_socket 1
+#define EGL_STREAM_PROTOCOL_SOCKET_NV 0x324B
+#define EGL_SOCKET_HANDLE_NV 0x324C
+#define EGL_SOCKET_TYPE_NV 0x324D
+#endif /* EGL_NV_stream_socket */
+
+#ifndef EGL_NV_stream_socket_inet
+#define EGL_NV_stream_socket_inet 1
+#define EGL_SOCKET_TYPE_INET_NV 0x324F
+#endif /* EGL_NV_stream_socket_inet */
+
+#ifndef EGL_NV_stream_socket_unix
+#define EGL_NV_stream_socket_unix 1
+#define EGL_SOCKET_TYPE_UNIX_NV 0x324E
+#endif /* EGL_NV_stream_socket_unix */
+
+#ifndef EGL_NV_stream_sync
+#define EGL_NV_stream_sync 1
+#define EGL_SYNC_NEW_FRAME_NV 0x321F
+typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESTREAMSYNCNVPROC) (EGLDisplay dpy, EGLStreamKHR stream, EGLenum type, const EGLint *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateStreamSyncNV (EGLDisplay dpy, EGLStreamKHR stream, EGLenum type, const EGLint *attrib_list);
+#endif
+#endif /* EGL_NV_stream_sync */
+
+#ifndef EGL_NV_sync
+#define EGL_NV_sync 1
+typedef void *EGLSyncNV;
+typedef khronos_utime_nanoseconds_t EGLTimeNV;
+#ifdef KHRONOS_SUPPORT_INT64
+#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_NV 0x30E6
+#define EGL_SYNC_STATUS_NV 0x30E7
+#define EGL_SIGNALED_NV 0x30E8
+#define EGL_UNSIGNALED_NV 0x30E9
+#define EGL_SYNC_FLUSH_COMMANDS_BIT_NV 0x0001
+#define EGL_FOREVER_NV 0xFFFFFFFFFFFFFFFFull
+#define EGL_ALREADY_SIGNALED_NV 0x30EA
+#define EGL_TIMEOUT_EXPIRED_NV 0x30EB
+#define EGL_CONDITION_SATISFIED_NV 0x30EC
+#define EGL_SYNC_TYPE_NV 0x30ED
+#define EGL_SYNC_CONDITION_NV 0x30EE
+#define EGL_SYNC_FENCE_NV 0x30EF
+#define EGL_NO_SYNC_NV EGL_CAST(EGLSyncNV,0)
+typedef EGLSyncNV (EGLAPIENTRYP PFNEGLCREATEFENCESYNCNVPROC) (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCNVPROC) (EGLSyncNV sync);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLFENCENVPROC) (EGLSyncNV sync);
+typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCNVPROC) (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCNVPROC) (EGLSyncNV sync, EGLenum mode);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBNVPROC) (EGLSyncNV sync, EGLint attribute, EGLint *value);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSyncNV EGLAPIENTRY eglCreateFenceSyncNV (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncNV (EGLSyncNV sync);
+EGLAPI EGLBoolean EGLAPIENTRY eglFenceNV (EGLSyncNV sync);
+EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncNV (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout);
+EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncNV (EGLSyncNV sync, EGLenum mode);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribNV (EGLSyncNV sync, EGLint attribute, EGLint *value);
+#endif
+#endif /* KHRONOS_SUPPORT_INT64 */
+#endif /* EGL_NV_sync */
+
+#ifndef EGL_NV_system_time
+#define EGL_NV_system_time 1
+typedef khronos_utime_nanoseconds_t EGLuint64NV;
+#ifdef KHRONOS_SUPPORT_INT64
+typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMEFREQUENCYNVPROC) (void);
+typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMENVPROC) (void);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLuint64NV EGLAPIENTRY eglGetSystemTimeFrequencyNV (void);
+EGLAPI EGLuint64NV EGLAPIENTRY eglGetSystemTimeNV (void);
+#endif
+#endif /* KHRONOS_SUPPORT_INT64 */
+#endif /* EGL_NV_system_time */
+
+#ifndef EGL_TIZEN_image_native_buffer
+#define EGL_TIZEN_image_native_buffer 1
+#define EGL_NATIVE_BUFFER_TIZEN 0x32A0
+#endif /* EGL_TIZEN_image_native_buffer */
+
+#ifndef EGL_TIZEN_image_native_surface
+#define EGL_TIZEN_image_native_surface 1
+#define EGL_NATIVE_SURFACE_TIZEN 0x32A1
+#endif /* EGL_TIZEN_image_native_surface */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/3rdparty/SDL2/src/video/khronos/EGL/eglplatform.h b/src/3rdparty/SDL2/src/video/khronos/EGL/eglplatform.h
new file mode 100644
index 0000000..c77c333
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/khronos/EGL/eglplatform.h
@@ -0,0 +1,132 @@
+#ifndef __eglplatform_h_
+#define __eglplatform_h_
+
+/*
+** Copyright (c) 2007-2016 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+
+/* Platform-specific types and definitions for egl.h
+ * $Revision: 30994 $ on $Date: 2015-04-30 13:36:48 -0700 (Thu, 30 Apr 2015) $
+ *
+ * Adopters may modify khrplatform.h and this file to suit their platform.
+ * You are encouraged to submit all modifications to the Khronos group so that
+ * they can be included in future versions of this file. Please submit changes
+ * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla)
+ * by filing a bug against product "EGL" component "Registry".
+ */
+
+#include <KHR/khrplatform.h>
+
+/* Macros used in EGL function prototype declarations.
+ *
+ * EGL functions should be prototyped as:
+ *
+ * EGLAPI return-type EGLAPIENTRY eglFunction(arguments);
+ * typedef return-type (EXPAPIENTRYP PFNEGLFUNCTIONPROC) (arguments);
+ *
+ * KHRONOS_APICALL and KHRONOS_APIENTRY are defined in KHR/khrplatform.h
+ */
+
+#ifndef EGLAPI
+#define EGLAPI KHRONOS_APICALL
+#endif
+
+#ifndef EGLAPIENTRY
+#define EGLAPIENTRY KHRONOS_APIENTRY
+#endif
+#define EGLAPIENTRYP EGLAPIENTRY*
+
+/* The types NativeDisplayType, NativeWindowType, and NativePixmapType
+ * are aliases of window-system-dependent types, such as X Display * or
+ * Windows Device Context. They must be defined in platform-specific
+ * code below. The EGL-prefixed versions of Native*Type are the same
+ * types, renamed in EGL 1.3 so all types in the API start with "EGL".
+ *
+ * Khronos STRONGLY RECOMMENDS that you use the default definitions
+ * provided below, since these changes affect both binary and source
+ * portability of applications using EGL running on different EGL
+ * implementations.
+ */
+
+#if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN 1
+#endif
+#include <windows.h>
+
+typedef HDC EGLNativeDisplayType;
+typedef HBITMAP EGLNativePixmapType;
+typedef HWND EGLNativeWindowType;
+
+#elif defined(__APPLE__) || defined(__WINSCW__) || defined(__SYMBIAN32__) /* Symbian */
+
+typedef int EGLNativeDisplayType;
+typedef void *EGLNativeWindowType;
+typedef void *EGLNativePixmapType;
+
+#elif defined(__ANDROID__) || defined(ANDROID)
+
+struct ANativeWindow;
+struct egl_native_pixmap_t;
+
+typedef struct ANativeWindow* EGLNativeWindowType;
+typedef struct egl_native_pixmap_t* EGLNativePixmapType;
+typedef void* EGLNativeDisplayType;
+
+#elif defined(__unix__)
+
+/* X11 (tentative) */
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+typedef Display *EGLNativeDisplayType;
+typedef Pixmap EGLNativePixmapType;
+typedef Window EGLNativeWindowType;
+
+#else
+#error "Platform not recognized"
+#endif
+
+/* EGL 1.2 types, renamed for consistency in EGL 1.3 */
+typedef EGLNativeDisplayType NativeDisplayType;
+typedef EGLNativePixmapType NativePixmapType;
+typedef EGLNativeWindowType NativeWindowType;
+
+
+/* Define EGLint. This must be a signed integral type large enough to contain
+ * all legal attribute names and values passed into and out of EGL, whether
+ * their type is boolean, bitmask, enumerant (symbolic constant), integer,
+ * handle, or other. While in general a 32-bit integer will suffice, if
+ * handles are 64 bit types, then EGLint should be defined as a signed 64-bit
+ * integer type.
+ */
+typedef khronos_int32_t EGLint;
+
+
+/* C++ / C typecast macros for special EGL handle values */
+#if defined(__cplusplus)
+#define EGL_CAST(type, value) (static_cast<type>(value))
+#else
+#define EGL_CAST(type, value) ((type) (value))
+#endif
+
+#endif /* __eglplatform_h */
diff --git a/src/3rdparty/SDL2/src/video/khronos/GLES2/gl2.h b/src/3rdparty/SDL2/src/video/khronos/GLES2/gl2.h
new file mode 100644
index 0000000..8ba1642
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/khronos/GLES2/gl2.h
@@ -0,0 +1,675 @@
+#ifndef __gl2_h_
+#define __gl2_h_ 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+** Copyright (c) 2013-2017 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+/*
+** This header is generated from the Khronos OpenGL / OpenGL ES XML
+** API Registry. The current version of the Registry, generator scripts
+** used to make the header, and the header can be found at
+** https://github.com/KhronosGroup/OpenGL-Registry
+*/
+
+#include <GLES2/gl2platform.h>
+
+#ifndef GL_APIENTRYP
+#define GL_APIENTRYP GL_APIENTRY*
+#endif
+
+#ifndef GL_GLES_PROTOTYPES
+#define GL_GLES_PROTOTYPES 1
+#endif
+
+/* Generated on date 20170817 */
+
+/* Generated C header for:
+ * API: gles2
+ * Profile: common
+ * Versions considered: 2\.[0-9]
+ * Versions emitted: .*
+ * Default extensions included: None
+ * Additional extensions included: _nomatch_^
+ * Extensions removed: _nomatch_^
+ */
+
+#ifndef GL_ES_VERSION_2_0
+#define GL_ES_VERSION_2_0 1
+#include <KHR/khrplatform.h>
+typedef khronos_int8_t GLbyte;
+typedef khronos_float_t GLclampf;
+typedef khronos_int32_t GLfixed;
+typedef short GLshort;
+typedef unsigned short GLushort;
+typedef void GLvoid;
+typedef struct __GLsync *GLsync;
+typedef khronos_int64_t GLint64;
+typedef khronos_uint64_t GLuint64;
+typedef unsigned int GLenum;
+typedef unsigned int GLuint;
+typedef char GLchar;
+typedef khronos_float_t GLfloat;
+typedef khronos_ssize_t GLsizeiptr;
+typedef khronos_intptr_t GLintptr;
+typedef unsigned int GLbitfield;
+typedef int GLint;
+typedef unsigned char GLboolean;
+typedef int GLsizei;
+typedef khronos_uint8_t GLubyte;
+#define GL_DEPTH_BUFFER_BIT 0x00000100
+#define GL_STENCIL_BUFFER_BIT 0x00000400
+#define GL_COLOR_BUFFER_BIT 0x00004000
+#define GL_FALSE 0
+#define GL_TRUE 1
+#define GL_POINTS 0x0000
+#define GL_LINES 0x0001
+#define GL_LINE_LOOP 0x0002
+#define GL_LINE_STRIP 0x0003
+#define GL_TRIANGLES 0x0004
+#define GL_TRIANGLE_STRIP 0x0005
+#define GL_TRIANGLE_FAN 0x0006
+#define GL_ZERO 0
+#define GL_ONE 1
+#define GL_SRC_COLOR 0x0300
+#define GL_ONE_MINUS_SRC_COLOR 0x0301
+#define GL_SRC_ALPHA 0x0302
+#define GL_ONE_MINUS_SRC_ALPHA 0x0303
+#define GL_DST_ALPHA 0x0304
+#define GL_ONE_MINUS_DST_ALPHA 0x0305
+#define GL_DST_COLOR 0x0306
+#define GL_ONE_MINUS_DST_COLOR 0x0307
+#define GL_SRC_ALPHA_SATURATE 0x0308
+#define GL_FUNC_ADD 0x8006
+#define GL_BLEND_EQUATION 0x8009
+#define GL_BLEND_EQUATION_RGB 0x8009
+#define GL_BLEND_EQUATION_ALPHA 0x883D
+#define GL_FUNC_SUBTRACT 0x800A
+#define GL_FUNC_REVERSE_SUBTRACT 0x800B
+#define GL_BLEND_DST_RGB 0x80C8
+#define GL_BLEND_SRC_RGB 0x80C9
+#define GL_BLEND_DST_ALPHA 0x80CA
+#define GL_BLEND_SRC_ALPHA 0x80CB
+#define GL_CONSTANT_COLOR 0x8001
+#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002
+#define GL_CONSTANT_ALPHA 0x8003
+#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004
+#define GL_BLEND_COLOR 0x8005
+#define GL_ARRAY_BUFFER 0x8892
+#define GL_ELEMENT_ARRAY_BUFFER 0x8893
+#define GL_ARRAY_BUFFER_BINDING 0x8894
+#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895
+#define GL_STREAM_DRAW 0x88E0
+#define GL_STATIC_DRAW 0x88E4
+#define GL_DYNAMIC_DRAW 0x88E8
+#define GL_BUFFER_SIZE 0x8764
+#define GL_BUFFER_USAGE 0x8765
+#define GL_CURRENT_VERTEX_ATTRIB 0x8626
+#define GL_FRONT 0x0404
+#define GL_BACK 0x0405
+#define GL_FRONT_AND_BACK 0x0408
+#define GL_TEXTURE_2D 0x0DE1
+#define GL_CULL_FACE 0x0B44
+#define GL_BLEND 0x0BE2
+#define GL_DITHER 0x0BD0
+#define GL_STENCIL_TEST 0x0B90
+#define GL_DEPTH_TEST 0x0B71
+#define GL_SCISSOR_TEST 0x0C11
+#define GL_POLYGON_OFFSET_FILL 0x8037
+#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E
+#define GL_SAMPLE_COVERAGE 0x80A0
+#define GL_NO_ERROR 0
+#define GL_INVALID_ENUM 0x0500
+#define GL_INVALID_VALUE 0x0501
+#define GL_INVALID_OPERATION 0x0502
+#define GL_OUT_OF_MEMORY 0x0505
+#define GL_CW 0x0900
+#define GL_CCW 0x0901
+#define GL_LINE_WIDTH 0x0B21
+#define GL_ALIASED_POINT_SIZE_RANGE 0x846D
+#define GL_ALIASED_LINE_WIDTH_RANGE 0x846E
+#define GL_CULL_FACE_MODE 0x0B45
+#define GL_FRONT_FACE 0x0B46
+#define GL_DEPTH_RANGE 0x0B70
+#define GL_DEPTH_WRITEMASK 0x0B72
+#define GL_DEPTH_CLEAR_VALUE 0x0B73
+#define GL_DEPTH_FUNC 0x0B74
+#define GL_STENCIL_CLEAR_VALUE 0x0B91
+#define GL_STENCIL_FUNC 0x0B92
+#define GL_STENCIL_FAIL 0x0B94
+#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95
+#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96
+#define GL_STENCIL_REF 0x0B97
+#define GL_STENCIL_VALUE_MASK 0x0B93
+#define GL_STENCIL_WRITEMASK 0x0B98
+#define GL_STENCIL_BACK_FUNC 0x8800
+#define GL_STENCIL_BACK_FAIL 0x8801
+#define GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802
+#define GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803
+#define GL_STENCIL_BACK_REF 0x8CA3
+#define GL_STENCIL_BACK_VALUE_MASK 0x8CA4
+#define GL_STENCIL_BACK_WRITEMASK 0x8CA5
+#define GL_VIEWPORT 0x0BA2
+#define GL_SCISSOR_BOX 0x0C10
+#define GL_COLOR_CLEAR_VALUE 0x0C22
+#define GL_COLOR_WRITEMASK 0x0C23
+#define GL_UNPACK_ALIGNMENT 0x0CF5
+#define GL_PACK_ALIGNMENT 0x0D05
+#define GL_MAX_TEXTURE_SIZE 0x0D33
+#define GL_MAX_VIEWPORT_DIMS 0x0D3A
+#define GL_SUBPIXEL_BITS 0x0D50
+#define GL_RED_BITS 0x0D52
+#define GL_GREEN_BITS 0x0D53
+#define GL_BLUE_BITS 0x0D54
+#define GL_ALPHA_BITS 0x0D55
+#define GL_DEPTH_BITS 0x0D56
+#define GL_STENCIL_BITS 0x0D57
+#define GL_POLYGON_OFFSET_UNITS 0x2A00
+#define GL_POLYGON_OFFSET_FACTOR 0x8038
+#define GL_TEXTURE_BINDING_2D 0x8069
+#define GL_SAMPLE_BUFFERS 0x80A8
+#define GL_SAMPLES 0x80A9
+#define GL_SAMPLE_COVERAGE_VALUE 0x80AA
+#define GL_SAMPLE_COVERAGE_INVERT 0x80AB
+#define GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2
+#define GL_COMPRESSED_TEXTURE_FORMATS 0x86A3
+#define GL_DONT_CARE 0x1100
+#define GL_FASTEST 0x1101
+#define GL_NICEST 0x1102
+#define GL_GENERATE_MIPMAP_HINT 0x8192
+#define GL_BYTE 0x1400
+#define GL_UNSIGNED_BYTE 0x1401
+#define GL_SHORT 0x1402
+#define GL_UNSIGNED_SHORT 0x1403
+#define GL_INT 0x1404
+#define GL_UNSIGNED_INT 0x1405
+#define GL_FLOAT 0x1406
+#define GL_FIXED 0x140C
+#define GL_DEPTH_COMPONENT 0x1902
+#define GL_ALPHA 0x1906
+#define GL_RGB 0x1907
+#define GL_RGBA 0x1908
+#define GL_LUMINANCE 0x1909
+#define GL_LUMINANCE_ALPHA 0x190A
+#define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
+#define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
+#define GL_UNSIGNED_SHORT_5_6_5 0x8363
+#define GL_FRAGMENT_SHADER 0x8B30
+#define GL_VERTEX_SHADER 0x8B31
+#define GL_MAX_VERTEX_ATTRIBS 0x8869
+#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB
+#define GL_MAX_VARYING_VECTORS 0x8DFC
+#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D
+#define GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C
+#define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872
+#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD
+#define GL_SHADER_TYPE 0x8B4F
+#define GL_DELETE_STATUS 0x8B80
+#define GL_LINK_STATUS 0x8B82
+#define GL_VALIDATE_STATUS 0x8B83
+#define GL_ATTACHED_SHADERS 0x8B85
+#define GL_ACTIVE_UNIFORMS 0x8B86
+#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87
+#define GL_ACTIVE_ATTRIBUTES 0x8B89
+#define GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A
+#define GL_SHADING_LANGUAGE_VERSION 0x8B8C
+#define GL_CURRENT_PROGRAM 0x8B8D
+#define GL_NEVER 0x0200
+#define GL_LESS 0x0201
+#define GL_EQUAL 0x0202
+#define GL_LEQUAL 0x0203
+#define GL_GREATER 0x0204
+#define GL_NOTEQUAL 0x0205
+#define GL_GEQUAL 0x0206
+#define GL_ALWAYS 0x0207
+#define GL_KEEP 0x1E00
+#define GL_REPLACE 0x1E01
+#define GL_INCR 0x1E02
+#define GL_DECR 0x1E03
+#define GL_INVERT 0x150A
+#define GL_INCR_WRAP 0x8507
+#define GL_DECR_WRAP 0x8508
+#define GL_VENDOR 0x1F00
+#define GL_RENDERER 0x1F01
+#define GL_VERSION 0x1F02
+#define GL_EXTENSIONS 0x1F03
+#define GL_NEAREST 0x2600
+#define GL_LINEAR 0x2601
+#define GL_NEAREST_MIPMAP_NEAREST 0x2700
+#define GL_LINEAR_MIPMAP_NEAREST 0x2701
+#define GL_NEAREST_MIPMAP_LINEAR 0x2702
+#define GL_LINEAR_MIPMAP_LINEAR 0x2703
+#define GL_TEXTURE_MAG_FILTER 0x2800
+#define GL_TEXTURE_MIN_FILTER 0x2801
+#define GL_TEXTURE_WRAP_S 0x2802
+#define GL_TEXTURE_WRAP_T 0x2803
+#define GL_TEXTURE 0x1702
+#define GL_TEXTURE_CUBE_MAP 0x8513
+#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
+#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
+#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
+#define GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C
+#define GL_TEXTURE0 0x84C0
+#define GL_TEXTURE1 0x84C1
+#define GL_TEXTURE2 0x84C2
+#define GL_TEXTURE3 0x84C3
+#define GL_TEXTURE4 0x84C4
+#define GL_TEXTURE5 0x84C5
+#define GL_TEXTURE6 0x84C6
+#define GL_TEXTURE7 0x84C7
+#define GL_TEXTURE8 0x84C8
+#define GL_TEXTURE9 0x84C9
+#define GL_TEXTURE10 0x84CA
+#define GL_TEXTURE11 0x84CB
+#define GL_TEXTURE12 0x84CC
+#define GL_TEXTURE13 0x84CD
+#define GL_TEXTURE14 0x84CE
+#define GL_TEXTURE15 0x84CF
+#define GL_TEXTURE16 0x84D0
+#define GL_TEXTURE17 0x84D1
+#define GL_TEXTURE18 0x84D2
+#define GL_TEXTURE19 0x84D3
+#define GL_TEXTURE20 0x84D4
+#define GL_TEXTURE21 0x84D5
+#define GL_TEXTURE22 0x84D6
+#define GL_TEXTURE23 0x84D7
+#define GL_TEXTURE24 0x84D8
+#define GL_TEXTURE25 0x84D9
+#define GL_TEXTURE26 0x84DA
+#define GL_TEXTURE27 0x84DB
+#define GL_TEXTURE28 0x84DC
+#define GL_TEXTURE29 0x84DD
+#define GL_TEXTURE30 0x84DE
+#define GL_TEXTURE31 0x84DF
+#define GL_ACTIVE_TEXTURE 0x84E0
+#define GL_REPEAT 0x2901
+#define GL_CLAMP_TO_EDGE 0x812F
+#define GL_MIRRORED_REPEAT 0x8370
+#define GL_FLOAT_VEC2 0x8B50
+#define GL_FLOAT_VEC3 0x8B51
+#define GL_FLOAT_VEC4 0x8B52
+#define GL_INT_VEC2 0x8B53
+#define GL_INT_VEC3 0x8B54
+#define GL_INT_VEC4 0x8B55
+#define GL_BOOL 0x8B56
+#define GL_BOOL_VEC2 0x8B57
+#define GL_BOOL_VEC3 0x8B58
+#define GL_BOOL_VEC4 0x8B59
+#define GL_FLOAT_MAT2 0x8B5A
+#define GL_FLOAT_MAT3 0x8B5B
+#define GL_FLOAT_MAT4 0x8B5C
+#define GL_SAMPLER_2D 0x8B5E
+#define GL_SAMPLER_CUBE 0x8B60
+#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
+#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
+#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624
+#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625
+#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A
+#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645
+#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F
+#define GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A
+#define GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B
+#define GL_COMPILE_STATUS 0x8B81
+#define GL_INFO_LOG_LENGTH 0x8B84
+#define GL_SHADER_SOURCE_LENGTH 0x8B88
+#define GL_SHADER_COMPILER 0x8DFA
+#define GL_SHADER_BINARY_FORMATS 0x8DF8
+#define GL_NUM_SHADER_BINARY_FORMATS 0x8DF9
+#define GL_LOW_FLOAT 0x8DF0
+#define GL_MEDIUM_FLOAT 0x8DF1
+#define GL_HIGH_FLOAT 0x8DF2
+#define GL_LOW_INT 0x8DF3
+#define GL_MEDIUM_INT 0x8DF4
+#define GL_HIGH_INT 0x8DF5
+#define GL_FRAMEBUFFER 0x8D40
+#define GL_RENDERBUFFER 0x8D41
+#define GL_RGBA4 0x8056
+#define GL_RGB5_A1 0x8057
+#define GL_RGB565 0x8D62
+#define GL_DEPTH_COMPONENT16 0x81A5
+#define GL_STENCIL_INDEX8 0x8D48
+#define GL_RENDERBUFFER_WIDTH 0x8D42
+#define GL_RENDERBUFFER_HEIGHT 0x8D43
+#define GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44
+#define GL_RENDERBUFFER_RED_SIZE 0x8D50
+#define GL_RENDERBUFFER_GREEN_SIZE 0x8D51
+#define GL_RENDERBUFFER_BLUE_SIZE 0x8D52
+#define GL_RENDERBUFFER_ALPHA_SIZE 0x8D53
+#define GL_RENDERBUFFER_DEPTH_SIZE 0x8D54
+#define GL_RENDERBUFFER_STENCIL_SIZE 0x8D55
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3
+#define GL_COLOR_ATTACHMENT0 0x8CE0
+#define GL_DEPTH_ATTACHMENT 0x8D00
+#define GL_STENCIL_ATTACHMENT 0x8D20
+#define GL_NONE 0
+#define GL_FRAMEBUFFER_COMPLETE 0x8CD5
+#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6
+#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7
+#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9
+#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD
+#define GL_FRAMEBUFFER_BINDING 0x8CA6
+#define GL_RENDERBUFFER_BINDING 0x8CA7
+#define GL_MAX_RENDERBUFFER_SIZE 0x84E8
+#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506
+typedef void (GL_APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
+typedef void (GL_APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
+typedef void (GL_APIENTRYP PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar *name);
+typedef void (GL_APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer);
+typedef void (GL_APIENTRYP PFNGLBINDFRAMEBUFFERPROC) (GLenum target, GLuint framebuffer);
+typedef void (GL_APIENTRYP PFNGLBINDRENDERBUFFERPROC) (GLenum target, GLuint renderbuffer);
+typedef void (GL_APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture);
+typedef void (GL_APIENTRYP PFNGLBLENDCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
+typedef void (GL_APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode);
+typedef void (GL_APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha);
+typedef void (GL_APIENTRYP PFNGLBLENDFUNCPROC) (GLenum sfactor, GLenum dfactor);
+typedef void (GL_APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
+typedef void (GL_APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
+typedef void (GL_APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
+typedef GLenum (GL_APIENTRYP PFNGLCHECKFRAMEBUFFERSTATUSPROC) (GLenum target);
+typedef void (GL_APIENTRYP PFNGLCLEARPROC) (GLbitfield mask);
+typedef void (GL_APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
+typedef void (GL_APIENTRYP PFNGLCLEARDEPTHFPROC) (GLfloat d);
+typedef void (GL_APIENTRYP PFNGLCLEARSTENCILPROC) (GLint s);
+typedef void (GL_APIENTRYP PFNGLCOLORMASKPROC) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
+typedef void (GL_APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader);
+typedef void (GL_APIENTRYP PFNGLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
+typedef void (GL_APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data);
+typedef void (GL_APIENTRYP PFNGLCOPYTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+typedef void (GL_APIENTRYP PFNGLCOPYTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef GLuint (GL_APIENTRYP PFNGLCREATEPROGRAMPROC) (void);
+typedef GLuint (GL_APIENTRYP PFNGLCREATESHADERPROC) (GLenum type);
+typedef void (GL_APIENTRYP PFNGLCULLFACEPROC) (GLenum mode);
+typedef void (GL_APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
+typedef void (GL_APIENTRYP PFNGLDELETEFRAMEBUFFERSPROC) (GLsizei n, const GLuint *framebuffers);
+typedef void (GL_APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program);
+typedef void (GL_APIENTRYP PFNGLDELETERENDERBUFFERSPROC) (GLsizei n, const GLuint *renderbuffers);
+typedef void (GL_APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader);
+typedef void (GL_APIENTRYP PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures);
+typedef void (GL_APIENTRYP PFNGLDEPTHFUNCPROC) (GLenum func);
+typedef void (GL_APIENTRYP PFNGLDEPTHMASKPROC) (GLboolean flag);
+typedef void (GL_APIENTRYP PFNGLDEPTHRANGEFPROC) (GLfloat n, GLfloat f);
+typedef void (GL_APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader);
+typedef void (GL_APIENTRYP PFNGLDISABLEPROC) (GLenum cap);
+typedef void (GL_APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index);
+typedef void (GL_APIENTRYP PFNGLDRAWARRAYSPROC) (GLenum mode, GLint first, GLsizei count);
+typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices);
+typedef void (GL_APIENTRYP PFNGLENABLEPROC) (GLenum cap);
+typedef void (GL_APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index);
+typedef void (GL_APIENTRYP PFNGLFINISHPROC) (void);
+typedef void (GL_APIENTRYP PFNGLFLUSHPROC) (void);
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFERPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+typedef void (GL_APIENTRYP PFNGLFRONTFACEPROC) (GLenum mode);
+typedef void (GL_APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
+typedef void (GL_APIENTRYP PFNGLGENERATEMIPMAPPROC) (GLenum target);
+typedef void (GL_APIENTRYP PFNGLGENFRAMEBUFFERSPROC) (GLsizei n, GLuint *framebuffers);
+typedef void (GL_APIENTRYP PFNGLGENRENDERBUFFERSPROC) (GLsizei n, GLuint *renderbuffers);
+typedef void (GL_APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures);
+typedef void (GL_APIENTRYP PFNGLGETACTIVEATTRIBPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
+typedef void (GL_APIENTRYP PFNGLGETACTIVEUNIFORMPROC) (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
+typedef void (GL_APIENTRYP PFNGLGETATTACHEDSHADERSPROC) (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders);
+typedef GLint (GL_APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name);
+typedef void (GL_APIENTRYP PFNGLGETBOOLEANVPROC) (GLenum pname, GLboolean *data);
+typedef void (GL_APIENTRYP PFNGLGETBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef GLenum (GL_APIENTRYP PFNGLGETERRORPROC) (void);
+typedef void (GL_APIENTRYP PFNGLGETFLOATVPROC) (GLenum pname, GLfloat *data);
+typedef void (GL_APIENTRYP PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) (GLenum target, GLenum attachment, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *data);
+typedef void (GL_APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+typedef void (GL_APIENTRYP PFNGLGETRENDERBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+typedef void (GL_APIENTRYP PFNGLGETSHADERPRECISIONFORMATPROC) (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision);
+typedef void (GL_APIENTRYP PFNGLGETSHADERSOURCEPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source);
+typedef const GLubyte *(GL_APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
+typedef void (GL_APIENTRYP PFNGLGETTEXPARAMETERFVPROC) (GLenum target, GLenum pname, GLfloat *params);
+typedef void (GL_APIENTRYP PFNGLGETTEXPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLGETUNIFORMFVPROC) (GLuint program, GLint location, GLfloat *params);
+typedef void (GL_APIENTRYP PFNGLGETUNIFORMIVPROC) (GLuint program, GLint location, GLint *params);
+typedef GLint (GL_APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name);
+typedef void (GL_APIENTRYP PFNGLGETVERTEXATTRIBFVPROC) (GLuint index, GLenum pname, GLfloat *params);
+typedef void (GL_APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, void **pointer);
+typedef void (GL_APIENTRYP PFNGLHINTPROC) (GLenum target, GLenum mode);
+typedef GLboolean (GL_APIENTRYP PFNGLISBUFFERPROC) (GLuint buffer);
+typedef GLboolean (GL_APIENTRYP PFNGLISENABLEDPROC) (GLenum cap);
+typedef GLboolean (GL_APIENTRYP PFNGLISFRAMEBUFFERPROC) (GLuint framebuffer);
+typedef GLboolean (GL_APIENTRYP PFNGLISPROGRAMPROC) (GLuint program);
+typedef GLboolean (GL_APIENTRYP PFNGLISRENDERBUFFERPROC) (GLuint renderbuffer);
+typedef GLboolean (GL_APIENTRYP PFNGLISSHADERPROC) (GLuint shader);
+typedef GLboolean (GL_APIENTRYP PFNGLISTEXTUREPROC) (GLuint texture);
+typedef void (GL_APIENTRYP PFNGLLINEWIDTHPROC) (GLfloat width);
+typedef void (GL_APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program);
+typedef void (GL_APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param);
+typedef void (GL_APIENTRYP PFNGLPOLYGONOFFSETPROC) (GLfloat factor, GLfloat units);
+typedef void (GL_APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
+typedef void (GL_APIENTRYP PFNGLRELEASESHADERCOMPILERPROC) (void);
+typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEPROC) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLSAMPLECOVERAGEPROC) (GLfloat value, GLboolean invert);
+typedef void (GL_APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLSHADERBINARYPROC) (GLsizei count, const GLuint *shaders, GLenum binaryformat, const void *binary, GLsizei length);
+typedef void (GL_APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
+typedef void (GL_APIENTRYP PFNGLSTENCILFUNCPROC) (GLenum func, GLint ref, GLuint mask);
+typedef void (GL_APIENTRYP PFNGLSTENCILFUNCSEPARATEPROC) (GLenum face, GLenum func, GLint ref, GLuint mask);
+typedef void (GL_APIENTRYP PFNGLSTENCILMASKPROC) (GLuint mask);
+typedef void (GL_APIENTRYP PFNGLSTENCILMASKSEPARATEPROC) (GLenum face, GLuint mask);
+typedef void (GL_APIENTRYP PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum zpass);
+typedef void (GL_APIENTRYP PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
+typedef void (GL_APIENTRYP PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (GL_APIENTRYP PFNGLTEXPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat param);
+typedef void (GL_APIENTRYP PFNGLTEXPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params);
+typedef void (GL_APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
+typedef void (GL_APIENTRYP PFNGLTEXPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (GL_APIENTRYP PFNGLTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
+typedef void (GL_APIENTRYP PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0);
+typedef void (GL_APIENTRYP PFNGLUNIFORM1FVPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0);
+typedef void (GL_APIENTRYP PFNGLUNIFORM1IVPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, GLfloat v1);
+typedef void (GL_APIENTRYP PFNGLUNIFORM2FVPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORM2IPROC) (GLint location, GLint v0, GLint v1);
+typedef void (GL_APIENTRYP PFNGLUNIFORM2IVPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORM3FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+typedef void (GL_APIENTRYP PFNGLUNIFORM3FVPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORM3IPROC) (GLint location, GLint v0, GLint v1, GLint v2);
+typedef void (GL_APIENTRYP PFNGLUNIFORM3IVPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORM4FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+typedef void (GL_APIENTRYP PFNGLUNIFORM4FVPROC) (GLint location, GLsizei count, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORM4IPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+typedef void (GL_APIENTRYP PFNGLUNIFORM4IVPROC) (GLint location, GLsizei count, const GLint *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORMMATRIX2FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program);
+typedef void (GL_APIENTRYP PFNGLVALIDATEPROGRAMPROC) (GLuint program);
+typedef void (GL_APIENTRYP PFNGLVERTEXATTRIB1FPROC) (GLuint index, GLfloat x);
+typedef void (GL_APIENTRYP PFNGLVERTEXATTRIB1FVPROC) (GLuint index, const GLfloat *v);
+typedef void (GL_APIENTRYP PFNGLVERTEXATTRIB2FPROC) (GLuint index, GLfloat x, GLfloat y);
+typedef void (GL_APIENTRYP PFNGLVERTEXATTRIB2FVPROC) (GLuint index, const GLfloat *v);
+typedef void (GL_APIENTRYP PFNGLVERTEXATTRIB3FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z);
+typedef void (GL_APIENTRYP PFNGLVERTEXATTRIB3FVPROC) (GLuint index, const GLfloat *v);
+typedef void (GL_APIENTRYP PFNGLVERTEXATTRIB4FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+typedef void (GL_APIENTRYP PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat *v);
+typedef void (GL_APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
+typedef void (GL_APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
+#if GL_GLES_PROTOTYPES
+GL_APICALL void GL_APIENTRY glActiveTexture (GLenum texture);
+GL_APICALL void GL_APIENTRY glAttachShader (GLuint program, GLuint shader);
+GL_APICALL void GL_APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar *name);
+GL_APICALL void GL_APIENTRY glBindBuffer (GLenum target, GLuint buffer);
+GL_APICALL void GL_APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer);
+GL_APICALL void GL_APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer);
+GL_APICALL void GL_APIENTRY glBindTexture (GLenum target, GLuint texture);
+GL_APICALL void GL_APIENTRY glBlendColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
+GL_APICALL void GL_APIENTRY glBlendEquation (GLenum mode);
+GL_APICALL void GL_APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha);
+GL_APICALL void GL_APIENTRY glBlendFunc (GLenum sfactor, GLenum dfactor);
+GL_APICALL void GL_APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
+GL_APICALL void GL_APIENTRY glBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
+GL_APICALL void GL_APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
+GL_APICALL GLenum GL_APIENTRY glCheckFramebufferStatus (GLenum target);
+GL_APICALL void GL_APIENTRY glClear (GLbitfield mask);
+GL_APICALL void GL_APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
+GL_APICALL void GL_APIENTRY glClearDepthf (GLfloat d);
+GL_APICALL void GL_APIENTRY glClearStencil (GLint s);
+GL_APICALL void GL_APIENTRY glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
+GL_APICALL void GL_APIENTRY glCompileShader (GLuint shader);
+GL_APICALL void GL_APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
+GL_APICALL void GL_APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data);
+GL_APICALL void GL_APIENTRY glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
+GL_APICALL void GL_APIENTRY glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+GL_APICALL GLuint GL_APIENTRY glCreateProgram (void);
+GL_APICALL GLuint GL_APIENTRY glCreateShader (GLenum type);
+GL_APICALL void GL_APIENTRY glCullFace (GLenum mode);
+GL_APICALL void GL_APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers);
+GL_APICALL void GL_APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint *framebuffers);
+GL_APICALL void GL_APIENTRY glDeleteProgram (GLuint program);
+GL_APICALL void GL_APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint *renderbuffers);
+GL_APICALL void GL_APIENTRY glDeleteShader (GLuint shader);
+GL_APICALL void GL_APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures);
+GL_APICALL void GL_APIENTRY glDepthFunc (GLenum func);
+GL_APICALL void GL_APIENTRY glDepthMask (GLboolean flag);
+GL_APICALL void GL_APIENTRY glDepthRangef (GLfloat n, GLfloat f);
+GL_APICALL void GL_APIENTRY glDetachShader (GLuint program, GLuint shader);
+GL_APICALL void GL_APIENTRY glDisable (GLenum cap);
+GL_APICALL void GL_APIENTRY glDisableVertexAttribArray (GLuint index);
+GL_APICALL void GL_APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count);
+GL_APICALL void GL_APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices);
+GL_APICALL void GL_APIENTRY glEnable (GLenum cap);
+GL_APICALL void GL_APIENTRY glEnableVertexAttribArray (GLuint index);
+GL_APICALL void GL_APIENTRY glFinish (void);
+GL_APICALL void GL_APIENTRY glFlush (void);
+GL_APICALL void GL_APIENTRY glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
+GL_APICALL void GL_APIENTRY glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
+GL_APICALL void GL_APIENTRY glFrontFace (GLenum mode);
+GL_APICALL void GL_APIENTRY glGenBuffers (GLsizei n, GLuint *buffers);
+GL_APICALL void GL_APIENTRY glGenerateMipmap (GLenum target);
+GL_APICALL void GL_APIENTRY glGenFramebuffers (GLsizei n, GLuint *framebuffers);
+GL_APICALL void GL_APIENTRY glGenRenderbuffers (GLsizei n, GLuint *renderbuffers);
+GL_APICALL void GL_APIENTRY glGenTextures (GLsizei n, GLuint *textures);
+GL_APICALL void GL_APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
+GL_APICALL void GL_APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
+GL_APICALL void GL_APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders);
+GL_APICALL GLint GL_APIENTRY glGetAttribLocation (GLuint program, const GLchar *name);
+GL_APICALL void GL_APIENTRY glGetBooleanv (GLenum pname, GLboolean *data);
+GL_APICALL void GL_APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params);
+GL_APICALL GLenum GL_APIENTRY glGetError (void);
+GL_APICALL void GL_APIENTRY glGetFloatv (GLenum pname, GLfloat *data);
+GL_APICALL void GL_APIENTRY glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glGetIntegerv (GLenum pname, GLint *data);
+GL_APICALL void GL_APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+GL_APICALL void GL_APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+GL_APICALL void GL_APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision);
+GL_APICALL void GL_APIENTRY glGetShaderSource (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source);
+GL_APICALL const GLubyte *GL_APIENTRY glGetString (GLenum name);
+GL_APICALL void GL_APIENTRY glGetTexParameterfv (GLenum target, GLenum pname, GLfloat *params);
+GL_APICALL void GL_APIENTRY glGetTexParameteriv (GLenum target, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat *params);
+GL_APICALL void GL_APIENTRY glGetUniformiv (GLuint program, GLint location, GLint *params);
+GL_APICALL GLint GL_APIENTRY glGetUniformLocation (GLuint program, const GLchar *name);
+GL_APICALL void GL_APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat *params);
+GL_APICALL void GL_APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, void **pointer);
+GL_APICALL void GL_APIENTRY glHint (GLenum target, GLenum mode);
+GL_APICALL GLboolean GL_APIENTRY glIsBuffer (GLuint buffer);
+GL_APICALL GLboolean GL_APIENTRY glIsEnabled (GLenum cap);
+GL_APICALL GLboolean GL_APIENTRY glIsFramebuffer (GLuint framebuffer);
+GL_APICALL GLboolean GL_APIENTRY glIsProgram (GLuint program);
+GL_APICALL GLboolean GL_APIENTRY glIsRenderbuffer (GLuint renderbuffer);
+GL_APICALL GLboolean GL_APIENTRY glIsShader (GLuint shader);
+GL_APICALL GLboolean GL_APIENTRY glIsTexture (GLuint texture);
+GL_APICALL void GL_APIENTRY glLineWidth (GLfloat width);
+GL_APICALL void GL_APIENTRY glLinkProgram (GLuint program);
+GL_APICALL void GL_APIENTRY glPixelStorei (GLenum pname, GLint param);
+GL_APICALL void GL_APIENTRY glPolygonOffset (GLfloat factor, GLfloat units);
+GL_APICALL void GL_APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
+GL_APICALL void GL_APIENTRY glReleaseShaderCompiler (void);
+GL_APICALL void GL_APIENTRY glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glSampleCoverage (GLfloat value, GLboolean invert);
+GL_APICALL void GL_APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glShaderBinary (GLsizei count, const GLuint *shaders, GLenum binaryformat, const void *binary, GLsizei length);
+GL_APICALL void GL_APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
+GL_APICALL void GL_APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask);
+GL_APICALL void GL_APIENTRY glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask);
+GL_APICALL void GL_APIENTRY glStencilMask (GLuint mask);
+GL_APICALL void GL_APIENTRY glStencilMaskSeparate (GLenum face, GLuint mask);
+GL_APICALL void GL_APIENTRY glStencilOp (GLenum fail, GLenum zfail, GLenum zpass);
+GL_APICALL void GL_APIENTRY glStencilOpSeparate (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
+GL_APICALL void GL_APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
+GL_APICALL void GL_APIENTRY glTexParameterf (GLenum target, GLenum pname, GLfloat param);
+GL_APICALL void GL_APIENTRY glTexParameterfv (GLenum target, GLenum pname, const GLfloat *params);
+GL_APICALL void GL_APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param);
+GL_APICALL void GL_APIENTRY glTexParameteriv (GLenum target, GLenum pname, const GLint *params);
+GL_APICALL void GL_APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
+GL_APICALL void GL_APIENTRY glUniform1f (GLint location, GLfloat v0);
+GL_APICALL void GL_APIENTRY glUniform1fv (GLint location, GLsizei count, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glUniform1i (GLint location, GLint v0);
+GL_APICALL void GL_APIENTRY glUniform1iv (GLint location, GLsizei count, const GLint *value);
+GL_APICALL void GL_APIENTRY glUniform2f (GLint location, GLfloat v0, GLfloat v1);
+GL_APICALL void GL_APIENTRY glUniform2fv (GLint location, GLsizei count, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glUniform2i (GLint location, GLint v0, GLint v1);
+GL_APICALL void GL_APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint *value);
+GL_APICALL void GL_APIENTRY glUniform3f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+GL_APICALL void GL_APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glUniform3i (GLint location, GLint v0, GLint v1, GLint v2);
+GL_APICALL void GL_APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint *value);
+GL_APICALL void GL_APIENTRY glUniform4f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+GL_APICALL void GL_APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glUniform4i (GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+GL_APICALL void GL_APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint *value);
+GL_APICALL void GL_APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glUseProgram (GLuint program);
+GL_APICALL void GL_APIENTRY glValidateProgram (GLuint program);
+GL_APICALL void GL_APIENTRY glVertexAttrib1f (GLuint index, GLfloat x);
+GL_APICALL void GL_APIENTRY glVertexAttrib1fv (GLuint index, const GLfloat *v);
+GL_APICALL void GL_APIENTRY glVertexAttrib2f (GLuint index, GLfloat x, GLfloat y);
+GL_APICALL void GL_APIENTRY glVertexAttrib2fv (GLuint index, const GLfloat *v);
+GL_APICALL void GL_APIENTRY glVertexAttrib3f (GLuint index, GLfloat x, GLfloat y, GLfloat z);
+GL_APICALL void GL_APIENTRY glVertexAttrib3fv (GLuint index, const GLfloat *v);
+GL_APICALL void GL_APIENTRY glVertexAttrib4f (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
+GL_APICALL void GL_APIENTRY glVertexAttrib4fv (GLuint index, const GLfloat *v);
+GL_APICALL void GL_APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
+GL_APICALL void GL_APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height);
+#endif
+#endif /* GL_ES_VERSION_2_0 */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/3rdparty/SDL2/src/video/khronos/GLES2/gl2ext.h b/src/3rdparty/SDL2/src/video/khronos/GLES2/gl2ext.h
new file mode 100644
index 0000000..4e1488c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/khronos/GLES2/gl2ext.h
@@ -0,0 +1,3505 @@
+#ifndef __gl2ext_h_
+#define __gl2ext_h_ 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+** Copyright (c) 2013-2017 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+/*
+** This header is generated from the Khronos OpenGL / OpenGL ES XML
+** API Registry. The current version of the Registry, generator scripts
+** used to make the header, and the header can be found at
+** https://github.com/KhronosGroup/OpenGL-Registry
+*/
+
+#ifndef GL_APIENTRYP
+#define GL_APIENTRYP GL_APIENTRY*
+#endif
+
+/* Generated on date 20170817 */
+
+/* Generated C header for:
+ * API: gles2
+ * Profile: common
+ * Versions considered: 2\.[0-9]
+ * Versions emitted: _nomatch_^
+ * Default extensions included: gles2
+ * Additional extensions included: _nomatch_^
+ * Extensions removed: _nomatch_^
+ */
+
+#ifndef GL_KHR_blend_equation_advanced
+#define GL_KHR_blend_equation_advanced 1
+#define GL_MULTIPLY_KHR 0x9294
+#define GL_SCREEN_KHR 0x9295
+#define GL_OVERLAY_KHR 0x9296
+#define GL_DARKEN_KHR 0x9297
+#define GL_LIGHTEN_KHR 0x9298
+#define GL_COLORDODGE_KHR 0x9299
+#define GL_COLORBURN_KHR 0x929A
+#define GL_HARDLIGHT_KHR 0x929B
+#define GL_SOFTLIGHT_KHR 0x929C
+#define GL_DIFFERENCE_KHR 0x929E
+#define GL_EXCLUSION_KHR 0x92A0
+#define GL_HSL_HUE_KHR 0x92AD
+#define GL_HSL_SATURATION_KHR 0x92AE
+#define GL_HSL_COLOR_KHR 0x92AF
+#define GL_HSL_LUMINOSITY_KHR 0x92B0
+typedef void (GL_APIENTRYP PFNGLBLENDBARRIERKHRPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glBlendBarrierKHR (void);
+#endif
+#endif /* GL_KHR_blend_equation_advanced */
+
+#ifndef GL_KHR_blend_equation_advanced_coherent
+#define GL_KHR_blend_equation_advanced_coherent 1
+#define GL_BLEND_ADVANCED_COHERENT_KHR 0x9285
+#endif /* GL_KHR_blend_equation_advanced_coherent */
+
+#ifndef GL_KHR_context_flush_control
+#define GL_KHR_context_flush_control 1
+#define GL_CONTEXT_RELEASE_BEHAVIOR_KHR 0x82FB
+#define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_KHR 0x82FC
+#endif /* GL_KHR_context_flush_control */
+
+#ifndef GL_KHR_debug
+#define GL_KHR_debug 1
+typedef void (GL_APIENTRY *GLDEBUGPROCKHR)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
+#define GL_SAMPLER 0x82E6
+#define GL_DEBUG_OUTPUT_SYNCHRONOUS_KHR 0x8242
+#define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_KHR 0x8243
+#define GL_DEBUG_CALLBACK_FUNCTION_KHR 0x8244
+#define GL_DEBUG_CALLBACK_USER_PARAM_KHR 0x8245
+#define GL_DEBUG_SOURCE_API_KHR 0x8246
+#define GL_DEBUG_SOURCE_WINDOW_SYSTEM_KHR 0x8247
+#define GL_DEBUG_SOURCE_SHADER_COMPILER_KHR 0x8248
+#define GL_DEBUG_SOURCE_THIRD_PARTY_KHR 0x8249
+#define GL_DEBUG_SOURCE_APPLICATION_KHR 0x824A
+#define GL_DEBUG_SOURCE_OTHER_KHR 0x824B
+#define GL_DEBUG_TYPE_ERROR_KHR 0x824C
+#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_KHR 0x824D
+#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_KHR 0x824E
+#define GL_DEBUG_TYPE_PORTABILITY_KHR 0x824F
+#define GL_DEBUG_TYPE_PERFORMANCE_KHR 0x8250
+#define GL_DEBUG_TYPE_OTHER_KHR 0x8251
+#define GL_DEBUG_TYPE_MARKER_KHR 0x8268
+#define GL_DEBUG_TYPE_PUSH_GROUP_KHR 0x8269
+#define GL_DEBUG_TYPE_POP_GROUP_KHR 0x826A
+#define GL_DEBUG_SEVERITY_NOTIFICATION_KHR 0x826B
+#define GL_MAX_DEBUG_GROUP_STACK_DEPTH_KHR 0x826C
+#define GL_DEBUG_GROUP_STACK_DEPTH_KHR 0x826D
+#define GL_BUFFER_KHR 0x82E0
+#define GL_SHADER_KHR 0x82E1
+#define GL_PROGRAM_KHR 0x82E2
+#define GL_VERTEX_ARRAY_KHR 0x8074
+#define GL_QUERY_KHR 0x82E3
+#define GL_PROGRAM_PIPELINE_KHR 0x82E4
+#define GL_SAMPLER_KHR 0x82E6
+#define GL_MAX_LABEL_LENGTH_KHR 0x82E8
+#define GL_MAX_DEBUG_MESSAGE_LENGTH_KHR 0x9143
+#define GL_MAX_DEBUG_LOGGED_MESSAGES_KHR 0x9144
+#define GL_DEBUG_LOGGED_MESSAGES_KHR 0x9145
+#define GL_DEBUG_SEVERITY_HIGH_KHR 0x9146
+#define GL_DEBUG_SEVERITY_MEDIUM_KHR 0x9147
+#define GL_DEBUG_SEVERITY_LOW_KHR 0x9148
+#define GL_DEBUG_OUTPUT_KHR 0x92E0
+#define GL_CONTEXT_FLAG_DEBUG_BIT_KHR 0x00000002
+#define GL_STACK_OVERFLOW_KHR 0x0503
+#define GL_STACK_UNDERFLOW_KHR 0x0504
+typedef void (GL_APIENTRYP PFNGLDEBUGMESSAGECONTROLKHRPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
+typedef void (GL_APIENTRYP PFNGLDEBUGMESSAGEINSERTKHRPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf);
+typedef void (GL_APIENTRYP PFNGLDEBUGMESSAGECALLBACKKHRPROC) (GLDEBUGPROCKHR callback, const void *userParam);
+typedef GLuint (GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC) (GLuint count, GLsizei bufSize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog);
+typedef void (GL_APIENTRYP PFNGLPUSHDEBUGGROUPKHRPROC) (GLenum source, GLuint id, GLsizei length, const GLchar *message);
+typedef void (GL_APIENTRYP PFNGLPOPDEBUGGROUPKHRPROC) (void);
+typedef void (GL_APIENTRYP PFNGLOBJECTLABELKHRPROC) (GLenum identifier, GLuint name, GLsizei length, const GLchar *label);
+typedef void (GL_APIENTRYP PFNGLGETOBJECTLABELKHRPROC) (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label);
+typedef void (GL_APIENTRYP PFNGLOBJECTPTRLABELKHRPROC) (const void *ptr, GLsizei length, const GLchar *label);
+typedef void (GL_APIENTRYP PFNGLGETOBJECTPTRLABELKHRPROC) (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label);
+typedef void (GL_APIENTRYP PFNGLGETPOINTERVKHRPROC) (GLenum pname, void **params);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDebugMessageControlKHR (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
+GL_APICALL void GL_APIENTRY glDebugMessageInsertKHR (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf);
+GL_APICALL void GL_APIENTRY glDebugMessageCallbackKHR (GLDEBUGPROCKHR callback, const void *userParam);
+GL_APICALL GLuint GL_APIENTRY glGetDebugMessageLogKHR (GLuint count, GLsizei bufSize, GLenum *sources, GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, GLchar *messageLog);
+GL_APICALL void GL_APIENTRY glPushDebugGroupKHR (GLenum source, GLuint id, GLsizei length, const GLchar *message);
+GL_APICALL void GL_APIENTRY glPopDebugGroupKHR (void);
+GL_APICALL void GL_APIENTRY glObjectLabelKHR (GLenum identifier, GLuint name, GLsizei length, const GLchar *label);
+GL_APICALL void GL_APIENTRY glGetObjectLabelKHR (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei *length, GLchar *label);
+GL_APICALL void GL_APIENTRY glObjectPtrLabelKHR (const void *ptr, GLsizei length, const GLchar *label);
+GL_APICALL void GL_APIENTRY glGetObjectPtrLabelKHR (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label);
+GL_APICALL void GL_APIENTRY glGetPointervKHR (GLenum pname, void **params);
+#endif
+#endif /* GL_KHR_debug */
+
+#ifndef GL_KHR_no_error
+#define GL_KHR_no_error 1
+#define GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR 0x00000008
+#endif /* GL_KHR_no_error */
+
+#ifndef GL_KHR_parallel_shader_compile
+#define GL_KHR_parallel_shader_compile 1
+#define GL_MAX_SHADER_COMPILER_THREADS_KHR 0x91B0
+#define GL_COMPLETION_STATUS_KHR 0x91B1
+typedef void (GL_APIENTRYP PFNGLMAXSHADERCOMPILERTHREADSKHRPROC) (GLuint count);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glMaxShaderCompilerThreadsKHR (GLuint count);
+#endif
+#endif /* GL_KHR_parallel_shader_compile */
+
+#ifndef GL_KHR_robust_buffer_access_behavior
+#define GL_KHR_robust_buffer_access_behavior 1
+#endif /* GL_KHR_robust_buffer_access_behavior */
+
+#ifndef GL_KHR_robustness
+#define GL_KHR_robustness 1
+#define GL_CONTEXT_ROBUST_ACCESS_KHR 0x90F3
+#define GL_LOSE_CONTEXT_ON_RESET_KHR 0x8252
+#define GL_GUILTY_CONTEXT_RESET_KHR 0x8253
+#define GL_INNOCENT_CONTEXT_RESET_KHR 0x8254
+#define GL_UNKNOWN_CONTEXT_RESET_KHR 0x8255
+#define GL_RESET_NOTIFICATION_STRATEGY_KHR 0x8256
+#define GL_NO_RESET_NOTIFICATION_KHR 0x8261
+#define GL_CONTEXT_LOST_KHR 0x0507
+typedef GLenum (GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC) (void);
+typedef void (GL_APIENTRYP PFNGLREADNPIXELSKHRPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void *data);
+typedef void (GL_APIENTRYP PFNGLGETNUNIFORMFVKHRPROC) (GLuint program, GLint location, GLsizei bufSize, GLfloat *params);
+typedef void (GL_APIENTRYP PFNGLGETNUNIFORMIVKHRPROC) (GLuint program, GLint location, GLsizei bufSize, GLint *params);
+typedef void (GL_APIENTRYP PFNGLGETNUNIFORMUIVKHRPROC) (GLuint program, GLint location, GLsizei bufSize, GLuint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL GLenum GL_APIENTRY glGetGraphicsResetStatusKHR (void);
+GL_APICALL void GL_APIENTRY glReadnPixelsKHR (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void *data);
+GL_APICALL void GL_APIENTRY glGetnUniformfvKHR (GLuint program, GLint location, GLsizei bufSize, GLfloat *params);
+GL_APICALL void GL_APIENTRY glGetnUniformivKHR (GLuint program, GLint location, GLsizei bufSize, GLint *params);
+GL_APICALL void GL_APIENTRY glGetnUniformuivKHR (GLuint program, GLint location, GLsizei bufSize, GLuint *params);
+#endif
+#endif /* GL_KHR_robustness */
+
+#ifndef GL_KHR_texture_compression_astc_hdr
+#define GL_KHR_texture_compression_astc_hdr 1
+#define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0
+#define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1
+#define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2
+#define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3
+#define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4
+#define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5
+#define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6
+#define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7
+#define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8
+#define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9
+#define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA
+#define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB
+#define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC
+#define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD
+#endif /* GL_KHR_texture_compression_astc_hdr */
+
+#ifndef GL_KHR_texture_compression_astc_ldr
+#define GL_KHR_texture_compression_astc_ldr 1
+#endif /* GL_KHR_texture_compression_astc_ldr */
+
+#ifndef GL_KHR_texture_compression_astc_sliced_3d
+#define GL_KHR_texture_compression_astc_sliced_3d 1
+#endif /* GL_KHR_texture_compression_astc_sliced_3d */
+
+#ifndef GL_OES_EGL_image
+#define GL_OES_EGL_image 1
+typedef void *GLeglImageOES;
+typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image);
+typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image);
+GL_APICALL void GL_APIENTRY glEGLImageTargetRenderbufferStorageOES (GLenum target, GLeglImageOES image);
+#endif
+#endif /* GL_OES_EGL_image */
+
+#ifndef GL_OES_EGL_image_external
+#define GL_OES_EGL_image_external 1
+#define GL_TEXTURE_EXTERNAL_OES 0x8D65
+#define GL_TEXTURE_BINDING_EXTERNAL_OES 0x8D67
+#define GL_REQUIRED_TEXTURE_IMAGE_UNITS_OES 0x8D68
+#define GL_SAMPLER_EXTERNAL_OES 0x8D66
+#endif /* GL_OES_EGL_image_external */
+
+#ifndef GL_OES_EGL_image_external_essl3
+#define GL_OES_EGL_image_external_essl3 1
+#endif /* GL_OES_EGL_image_external_essl3 */
+
+#ifndef GL_OES_compressed_ETC1_RGB8_sub_texture
+#define GL_OES_compressed_ETC1_RGB8_sub_texture 1
+#endif /* GL_OES_compressed_ETC1_RGB8_sub_texture */
+
+#ifndef GL_OES_compressed_ETC1_RGB8_texture
+#define GL_OES_compressed_ETC1_RGB8_texture 1
+#define GL_ETC1_RGB8_OES 0x8D64
+#endif /* GL_OES_compressed_ETC1_RGB8_texture */
+
+#ifndef GL_OES_compressed_paletted_texture
+#define GL_OES_compressed_paletted_texture 1
+#define GL_PALETTE4_RGB8_OES 0x8B90
+#define GL_PALETTE4_RGBA8_OES 0x8B91
+#define GL_PALETTE4_R5_G6_B5_OES 0x8B92
+#define GL_PALETTE4_RGBA4_OES 0x8B93
+#define GL_PALETTE4_RGB5_A1_OES 0x8B94
+#define GL_PALETTE8_RGB8_OES 0x8B95
+#define GL_PALETTE8_RGBA8_OES 0x8B96
+#define GL_PALETTE8_R5_G6_B5_OES 0x8B97
+#define GL_PALETTE8_RGBA4_OES 0x8B98
+#define GL_PALETTE8_RGB5_A1_OES 0x8B99
+#endif /* GL_OES_compressed_paletted_texture */
+
+#ifndef GL_OES_copy_image
+#define GL_OES_copy_image 1
+typedef void (GL_APIENTRYP PFNGLCOPYIMAGESUBDATAOESPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glCopyImageSubDataOES (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth);
+#endif
+#endif /* GL_OES_copy_image */
+
+#ifndef GL_OES_depth24
+#define GL_OES_depth24 1
+#define GL_DEPTH_COMPONENT24_OES 0x81A6
+#endif /* GL_OES_depth24 */
+
+#ifndef GL_OES_depth32
+#define GL_OES_depth32 1
+#define GL_DEPTH_COMPONENT32_OES 0x81A7
+#endif /* GL_OES_depth32 */
+
+#ifndef GL_OES_depth_texture
+#define GL_OES_depth_texture 1
+#endif /* GL_OES_depth_texture */
+
+#ifndef GL_OES_draw_buffers_indexed
+#define GL_OES_draw_buffers_indexed 1
+#define GL_MIN 0x8007
+#define GL_MAX 0x8008
+typedef void (GL_APIENTRYP PFNGLENABLEIOESPROC) (GLenum target, GLuint index);
+typedef void (GL_APIENTRYP PFNGLDISABLEIOESPROC) (GLenum target, GLuint index);
+typedef void (GL_APIENTRYP PFNGLBLENDEQUATIONIOESPROC) (GLuint buf, GLenum mode);
+typedef void (GL_APIENTRYP PFNGLBLENDEQUATIONSEPARATEIOESPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha);
+typedef void (GL_APIENTRYP PFNGLBLENDFUNCIOESPROC) (GLuint buf, GLenum src, GLenum dst);
+typedef void (GL_APIENTRYP PFNGLBLENDFUNCSEPARATEIOESPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+typedef void (GL_APIENTRYP PFNGLCOLORMASKIOESPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a);
+typedef GLboolean (GL_APIENTRYP PFNGLISENABLEDIOESPROC) (GLenum target, GLuint index);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glEnableiOES (GLenum target, GLuint index);
+GL_APICALL void GL_APIENTRY glDisableiOES (GLenum target, GLuint index);
+GL_APICALL void GL_APIENTRY glBlendEquationiOES (GLuint buf, GLenum mode);
+GL_APICALL void GL_APIENTRY glBlendEquationSeparateiOES (GLuint buf, GLenum modeRGB, GLenum modeAlpha);
+GL_APICALL void GL_APIENTRY glBlendFunciOES (GLuint buf, GLenum src, GLenum dst);
+GL_APICALL void GL_APIENTRY glBlendFuncSeparateiOES (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+GL_APICALL void GL_APIENTRY glColorMaskiOES (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a);
+GL_APICALL GLboolean GL_APIENTRY glIsEnablediOES (GLenum target, GLuint index);
+#endif
+#endif /* GL_OES_draw_buffers_indexed */
+
+#ifndef GL_OES_draw_elements_base_vertex
+#define GL_OES_draw_elements_base_vertex 1
+typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXOESPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
+typedef void (GL_APIENTRYP PFNGLDRAWRANGEELEMENTSBASEVERTEXOESPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLint basevertex);
+typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXOESPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex);
+typedef void (GL_APIENTRYP PFNGLMULTIDRAWELEMENTSBASEVERTEXEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei primcount, const GLint *basevertex);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDrawElementsBaseVertexOES (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
+GL_APICALL void GL_APIENTRY glDrawRangeElementsBaseVertexOES (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLint basevertex);
+GL_APICALL void GL_APIENTRY glDrawElementsInstancedBaseVertexOES (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex);
+GL_APICALL void GL_APIENTRY glMultiDrawElementsBaseVertexEXT (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei primcount, const GLint *basevertex);
+#endif
+#endif /* GL_OES_draw_elements_base_vertex */
+
+#ifndef GL_OES_element_index_uint
+#define GL_OES_element_index_uint 1
+#endif /* GL_OES_element_index_uint */
+
+#ifndef GL_OES_fbo_render_mipmap
+#define GL_OES_fbo_render_mipmap 1
+#endif /* GL_OES_fbo_render_mipmap */
+
+#ifndef GL_OES_fragment_precision_high
+#define GL_OES_fragment_precision_high 1
+#endif /* GL_OES_fragment_precision_high */
+
+#ifndef GL_OES_geometry_point_size
+#define GL_OES_geometry_point_size 1
+#endif /* GL_OES_geometry_point_size */
+
+#ifndef GL_OES_geometry_shader
+#define GL_OES_geometry_shader 1
+#define GL_GEOMETRY_SHADER_OES 0x8DD9
+#define GL_GEOMETRY_SHADER_BIT_OES 0x00000004
+#define GL_GEOMETRY_LINKED_VERTICES_OUT_OES 0x8916
+#define GL_GEOMETRY_LINKED_INPUT_TYPE_OES 0x8917
+#define GL_GEOMETRY_LINKED_OUTPUT_TYPE_OES 0x8918
+#define GL_GEOMETRY_SHADER_INVOCATIONS_OES 0x887F
+#define GL_LAYER_PROVOKING_VERTEX_OES 0x825E
+#define GL_LINES_ADJACENCY_OES 0x000A
+#define GL_LINE_STRIP_ADJACENCY_OES 0x000B
+#define GL_TRIANGLES_ADJACENCY_OES 0x000C
+#define GL_TRIANGLE_STRIP_ADJACENCY_OES 0x000D
+#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_OES 0x8DDF
+#define GL_MAX_GEOMETRY_UNIFORM_BLOCKS_OES 0x8A2C
+#define GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_OES 0x8A32
+#define GL_MAX_GEOMETRY_INPUT_COMPONENTS_OES 0x9123
+#define GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_OES 0x9124
+#define GL_MAX_GEOMETRY_OUTPUT_VERTICES_OES 0x8DE0
+#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_OES 0x8DE1
+#define GL_MAX_GEOMETRY_SHADER_INVOCATIONS_OES 0x8E5A
+#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_OES 0x8C29
+#define GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_OES 0x92CF
+#define GL_MAX_GEOMETRY_ATOMIC_COUNTERS_OES 0x92D5
+#define GL_MAX_GEOMETRY_IMAGE_UNIFORMS_OES 0x90CD
+#define GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_OES 0x90D7
+#define GL_FIRST_VERTEX_CONVENTION_OES 0x8E4D
+#define GL_LAST_VERTEX_CONVENTION_OES 0x8E4E
+#define GL_UNDEFINED_VERTEX_OES 0x8260
+#define GL_PRIMITIVES_GENERATED_OES 0x8C87
+#define GL_FRAMEBUFFER_DEFAULT_LAYERS_OES 0x9312
+#define GL_MAX_FRAMEBUFFER_LAYERS_OES 0x9317
+#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_OES 0x8DA8
+#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED_OES 0x8DA7
+#define GL_REFERENCED_BY_GEOMETRY_SHADER_OES 0x9309
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTUREOESPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glFramebufferTextureOES (GLenum target, GLenum attachment, GLuint texture, GLint level);
+#endif
+#endif /* GL_OES_geometry_shader */
+
+#ifndef GL_OES_get_program_binary
+#define GL_OES_get_program_binary 1
+#define GL_PROGRAM_BINARY_LENGTH_OES 0x8741
+#define GL_NUM_PROGRAM_BINARY_FORMATS_OES 0x87FE
+#define GL_PROGRAM_BINARY_FORMATS_OES 0x87FF
+typedef void (GL_APIENTRYP PFNGLGETPROGRAMBINARYOESPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, void *binary);
+typedef void (GL_APIENTRYP PFNGLPROGRAMBINARYOESPROC) (GLuint program, GLenum binaryFormat, const void *binary, GLint length);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glGetProgramBinaryOES (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, void *binary);
+GL_APICALL void GL_APIENTRY glProgramBinaryOES (GLuint program, GLenum binaryFormat, const void *binary, GLint length);
+#endif
+#endif /* GL_OES_get_program_binary */
+
+#ifndef GL_OES_gpu_shader5
+#define GL_OES_gpu_shader5 1
+#endif /* GL_OES_gpu_shader5 */
+
+#ifndef GL_OES_mapbuffer
+#define GL_OES_mapbuffer 1
+#define GL_WRITE_ONLY_OES 0x88B9
+#define GL_BUFFER_ACCESS_OES 0x88BB
+#define GL_BUFFER_MAPPED_OES 0x88BC
+#define GL_BUFFER_MAP_POINTER_OES 0x88BD
+typedef void *(GL_APIENTRYP PFNGLMAPBUFFEROESPROC) (GLenum target, GLenum access);
+typedef GLboolean (GL_APIENTRYP PFNGLUNMAPBUFFEROESPROC) (GLenum target);
+typedef void (GL_APIENTRYP PFNGLGETBUFFERPOINTERVOESPROC) (GLenum target, GLenum pname, void **params);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void *GL_APIENTRY glMapBufferOES (GLenum target, GLenum access);
+GL_APICALL GLboolean GL_APIENTRY glUnmapBufferOES (GLenum target);
+GL_APICALL void GL_APIENTRY glGetBufferPointervOES (GLenum target, GLenum pname, void **params);
+#endif
+#endif /* GL_OES_mapbuffer */
+
+#ifndef GL_OES_packed_depth_stencil
+#define GL_OES_packed_depth_stencil 1
+#define GL_DEPTH_STENCIL_OES 0x84F9
+#define GL_UNSIGNED_INT_24_8_OES 0x84FA
+#define GL_DEPTH24_STENCIL8_OES 0x88F0
+#endif /* GL_OES_packed_depth_stencil */
+
+#ifndef GL_OES_primitive_bounding_box
+#define GL_OES_primitive_bounding_box 1
+#define GL_PRIMITIVE_BOUNDING_BOX_OES 0x92BE
+typedef void (GL_APIENTRYP PFNGLPRIMITIVEBOUNDINGBOXOESPROC) (GLfloat minX, GLfloat minY, GLfloat minZ, GLfloat minW, GLfloat maxX, GLfloat maxY, GLfloat maxZ, GLfloat maxW);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glPrimitiveBoundingBoxOES (GLfloat minX, GLfloat minY, GLfloat minZ, GLfloat minW, GLfloat maxX, GLfloat maxY, GLfloat maxZ, GLfloat maxW);
+#endif
+#endif /* GL_OES_primitive_bounding_box */
+
+#ifndef GL_OES_required_internalformat
+#define GL_OES_required_internalformat 1
+#define GL_ALPHA8_OES 0x803C
+#define GL_DEPTH_COMPONENT16_OES 0x81A5
+#define GL_LUMINANCE4_ALPHA4_OES 0x8043
+#define GL_LUMINANCE8_ALPHA8_OES 0x8045
+#define GL_LUMINANCE8_OES 0x8040
+#define GL_RGBA4_OES 0x8056
+#define GL_RGB5_A1_OES 0x8057
+#define GL_RGB565_OES 0x8D62
+#define GL_RGB8_OES 0x8051
+#define GL_RGBA8_OES 0x8058
+#define GL_RGB10_EXT 0x8052
+#define GL_RGB10_A2_EXT 0x8059
+#endif /* GL_OES_required_internalformat */
+
+#ifndef GL_OES_rgb8_rgba8
+#define GL_OES_rgb8_rgba8 1
+#endif /* GL_OES_rgb8_rgba8 */
+
+#ifndef GL_OES_sample_shading
+#define GL_OES_sample_shading 1
+#define GL_SAMPLE_SHADING_OES 0x8C36
+#define GL_MIN_SAMPLE_SHADING_VALUE_OES 0x8C37
+typedef void (GL_APIENTRYP PFNGLMINSAMPLESHADINGOESPROC) (GLfloat value);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glMinSampleShadingOES (GLfloat value);
+#endif
+#endif /* GL_OES_sample_shading */
+
+#ifndef GL_OES_sample_variables
+#define GL_OES_sample_variables 1
+#endif /* GL_OES_sample_variables */
+
+#ifndef GL_OES_shader_image_atomic
+#define GL_OES_shader_image_atomic 1
+#endif /* GL_OES_shader_image_atomic */
+
+#ifndef GL_OES_shader_io_blocks
+#define GL_OES_shader_io_blocks 1
+#endif /* GL_OES_shader_io_blocks */
+
+#ifndef GL_OES_shader_multisample_interpolation
+#define GL_OES_shader_multisample_interpolation 1
+#define GL_MIN_FRAGMENT_INTERPOLATION_OFFSET_OES 0x8E5B
+#define GL_MAX_FRAGMENT_INTERPOLATION_OFFSET_OES 0x8E5C
+#define GL_FRAGMENT_INTERPOLATION_OFFSET_BITS_OES 0x8E5D
+#endif /* GL_OES_shader_multisample_interpolation */
+
+#ifndef GL_OES_standard_derivatives
+#define GL_OES_standard_derivatives 1
+#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES 0x8B8B
+#endif /* GL_OES_standard_derivatives */
+
+#ifndef GL_OES_stencil1
+#define GL_OES_stencil1 1
+#define GL_STENCIL_INDEX1_OES 0x8D46
+#endif /* GL_OES_stencil1 */
+
+#ifndef GL_OES_stencil4
+#define GL_OES_stencil4 1
+#define GL_STENCIL_INDEX4_OES 0x8D47
+#endif /* GL_OES_stencil4 */
+
+#ifndef GL_OES_surfaceless_context
+#define GL_OES_surfaceless_context 1
+#define GL_FRAMEBUFFER_UNDEFINED_OES 0x8219
+#endif /* GL_OES_surfaceless_context */
+
+#ifndef GL_OES_tessellation_point_size
+#define GL_OES_tessellation_point_size 1
+#endif /* GL_OES_tessellation_point_size */
+
+#ifndef GL_OES_tessellation_shader
+#define GL_OES_tessellation_shader 1
+#define GL_PATCHES_OES 0x000E
+#define GL_PATCH_VERTICES_OES 0x8E72
+#define GL_TESS_CONTROL_OUTPUT_VERTICES_OES 0x8E75
+#define GL_TESS_GEN_MODE_OES 0x8E76
+#define GL_TESS_GEN_SPACING_OES 0x8E77
+#define GL_TESS_GEN_VERTEX_ORDER_OES 0x8E78
+#define GL_TESS_GEN_POINT_MODE_OES 0x8E79
+#define GL_ISOLINES_OES 0x8E7A
+#define GL_QUADS_OES 0x0007
+#define GL_FRACTIONAL_ODD_OES 0x8E7B
+#define GL_FRACTIONAL_EVEN_OES 0x8E7C
+#define GL_MAX_PATCH_VERTICES_OES 0x8E7D
+#define GL_MAX_TESS_GEN_LEVEL_OES 0x8E7E
+#define GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS_OES 0x8E7F
+#define GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS_OES 0x8E80
+#define GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS_OES 0x8E81
+#define GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS_OES 0x8E82
+#define GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS_OES 0x8E83
+#define GL_MAX_TESS_PATCH_COMPONENTS_OES 0x8E84
+#define GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS_OES 0x8E85
+#define GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS_OES 0x8E86
+#define GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS_OES 0x8E89
+#define GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS_OES 0x8E8A
+#define GL_MAX_TESS_CONTROL_INPUT_COMPONENTS_OES 0x886C
+#define GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS_OES 0x886D
+#define GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS_OES 0x8E1E
+#define GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS_OES 0x8E1F
+#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS_OES 0x92CD
+#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS_OES 0x92CE
+#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS_OES 0x92D3
+#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS_OES 0x92D4
+#define GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS_OES 0x90CB
+#define GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS_OES 0x90CC
+#define GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS_OES 0x90D8
+#define GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS_OES 0x90D9
+#define GL_PRIMITIVE_RESTART_FOR_PATCHES_SUPPORTED_OES 0x8221
+#define GL_IS_PER_PATCH_OES 0x92E7
+#define GL_REFERENCED_BY_TESS_CONTROL_SHADER_OES 0x9307
+#define GL_REFERENCED_BY_TESS_EVALUATION_SHADER_OES 0x9308
+#define GL_TESS_CONTROL_SHADER_OES 0x8E88
+#define GL_TESS_EVALUATION_SHADER_OES 0x8E87
+#define GL_TESS_CONTROL_SHADER_BIT_OES 0x00000008
+#define GL_TESS_EVALUATION_SHADER_BIT_OES 0x00000010
+typedef void (GL_APIENTRYP PFNGLPATCHPARAMETERIOESPROC) (GLenum pname, GLint value);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glPatchParameteriOES (GLenum pname, GLint value);
+#endif
+#endif /* GL_OES_tessellation_shader */
+
+#ifndef GL_OES_texture_3D
+#define GL_OES_texture_3D 1
+#define GL_TEXTURE_WRAP_R_OES 0x8072
+#define GL_TEXTURE_3D_OES 0x806F
+#define GL_TEXTURE_BINDING_3D_OES 0x806A
+#define GL_MAX_3D_TEXTURE_SIZE_OES 0x8073
+#define GL_SAMPLER_3D_OES 0x8B5F
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_OES 0x8CD4
+typedef void (GL_APIENTRYP PFNGLTEXIMAGE3DOESPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
+typedef void (GL_APIENTRYP PFNGLTEXSUBIMAGE3DOESPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
+typedef void (GL_APIENTRYP PFNGLCOPYTEXSUBIMAGE3DOESPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DOESPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data);
+typedef void (GL_APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DOESPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data);
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE3DOESPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glTexImage3DOES (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels);
+GL_APICALL void GL_APIENTRY glTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels);
+GL_APICALL void GL_APIENTRY glCopyTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glCompressedTexImage3DOES (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void *data);
+GL_APICALL void GL_APIENTRY glCompressedTexSubImage3DOES (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data);
+GL_APICALL void GL_APIENTRY glFramebufferTexture3DOES (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset);
+#endif
+#endif /* GL_OES_texture_3D */
+
+#ifndef GL_OES_texture_border_clamp
+#define GL_OES_texture_border_clamp 1
+#define GL_TEXTURE_BORDER_COLOR_OES 0x1004
+#define GL_CLAMP_TO_BORDER_OES 0x812D
+typedef void (GL_APIENTRYP PFNGLTEXPARAMETERIIVOESPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (GL_APIENTRYP PFNGLTEXPARAMETERIUIVOESPROC) (GLenum target, GLenum pname, const GLuint *params);
+typedef void (GL_APIENTRYP PFNGLGETTEXPARAMETERIIVOESPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLGETTEXPARAMETERIUIVOESPROC) (GLenum target, GLenum pname, GLuint *params);
+typedef void (GL_APIENTRYP PFNGLSAMPLERPARAMETERIIVOESPROC) (GLuint sampler, GLenum pname, const GLint *param);
+typedef void (GL_APIENTRYP PFNGLSAMPLERPARAMETERIUIVOESPROC) (GLuint sampler, GLenum pname, const GLuint *param);
+typedef void (GL_APIENTRYP PFNGLGETSAMPLERPARAMETERIIVOESPROC) (GLuint sampler, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLGETSAMPLERPARAMETERIUIVOESPROC) (GLuint sampler, GLenum pname, GLuint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glTexParameterIivOES (GLenum target, GLenum pname, const GLint *params);
+GL_APICALL void GL_APIENTRY glTexParameterIuivOES (GLenum target, GLenum pname, const GLuint *params);
+GL_APICALL void GL_APIENTRY glGetTexParameterIivOES (GLenum target, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glGetTexParameterIuivOES (GLenum target, GLenum pname, GLuint *params);
+GL_APICALL void GL_APIENTRY glSamplerParameterIivOES (GLuint sampler, GLenum pname, const GLint *param);
+GL_APICALL void GL_APIENTRY glSamplerParameterIuivOES (GLuint sampler, GLenum pname, const GLuint *param);
+GL_APICALL void GL_APIENTRY glGetSamplerParameterIivOES (GLuint sampler, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glGetSamplerParameterIuivOES (GLuint sampler, GLenum pname, GLuint *params);
+#endif
+#endif /* GL_OES_texture_border_clamp */
+
+#ifndef GL_OES_texture_buffer
+#define GL_OES_texture_buffer 1
+#define GL_TEXTURE_BUFFER_OES 0x8C2A
+#define GL_TEXTURE_BUFFER_BINDING_OES 0x8C2A
+#define GL_MAX_TEXTURE_BUFFER_SIZE_OES 0x8C2B
+#define GL_TEXTURE_BINDING_BUFFER_OES 0x8C2C
+#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING_OES 0x8C2D
+#define GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT_OES 0x919F
+#define GL_SAMPLER_BUFFER_OES 0x8DC2
+#define GL_INT_SAMPLER_BUFFER_OES 0x8DD0
+#define GL_UNSIGNED_INT_SAMPLER_BUFFER_OES 0x8DD8
+#define GL_IMAGE_BUFFER_OES 0x9051
+#define GL_INT_IMAGE_BUFFER_OES 0x905C
+#define GL_UNSIGNED_INT_IMAGE_BUFFER_OES 0x9067
+#define GL_TEXTURE_BUFFER_OFFSET_OES 0x919D
+#define GL_TEXTURE_BUFFER_SIZE_OES 0x919E
+typedef void (GL_APIENTRYP PFNGLTEXBUFFEROESPROC) (GLenum target, GLenum internalformat, GLuint buffer);
+typedef void (GL_APIENTRYP PFNGLTEXBUFFERRANGEOESPROC) (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glTexBufferOES (GLenum target, GLenum internalformat, GLuint buffer);
+GL_APICALL void GL_APIENTRY glTexBufferRangeOES (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size);
+#endif
+#endif /* GL_OES_texture_buffer */
+
+#ifndef GL_OES_texture_compression_astc
+#define GL_OES_texture_compression_astc 1
+#define GL_COMPRESSED_RGBA_ASTC_3x3x3_OES 0x93C0
+#define GL_COMPRESSED_RGBA_ASTC_4x3x3_OES 0x93C1
+#define GL_COMPRESSED_RGBA_ASTC_4x4x3_OES 0x93C2
+#define GL_COMPRESSED_RGBA_ASTC_4x4x4_OES 0x93C3
+#define GL_COMPRESSED_RGBA_ASTC_5x4x4_OES 0x93C4
+#define GL_COMPRESSED_RGBA_ASTC_5x5x4_OES 0x93C5
+#define GL_COMPRESSED_RGBA_ASTC_5x5x5_OES 0x93C6
+#define GL_COMPRESSED_RGBA_ASTC_6x5x5_OES 0x93C7
+#define GL_COMPRESSED_RGBA_ASTC_6x6x5_OES 0x93C8
+#define GL_COMPRESSED_RGBA_ASTC_6x6x6_OES 0x93C9
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES 0x93E0
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES 0x93E1
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES 0x93E2
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES 0x93E3
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES 0x93E4
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES 0x93E5
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES 0x93E6
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES 0x93E7
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES 0x93E8
+#define GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES 0x93E9
+#endif /* GL_OES_texture_compression_astc */
+
+#ifndef GL_OES_texture_cube_map_array
+#define GL_OES_texture_cube_map_array 1
+#define GL_TEXTURE_CUBE_MAP_ARRAY_OES 0x9009
+#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY_OES 0x900A
+#define GL_SAMPLER_CUBE_MAP_ARRAY_OES 0x900C
+#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_OES 0x900D
+#define GL_INT_SAMPLER_CUBE_MAP_ARRAY_OES 0x900E
+#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_OES 0x900F
+#define GL_IMAGE_CUBE_MAP_ARRAY_OES 0x9054
+#define GL_INT_IMAGE_CUBE_MAP_ARRAY_OES 0x905F
+#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY_OES 0x906A
+#endif /* GL_OES_texture_cube_map_array */
+
+#ifndef GL_OES_texture_float
+#define GL_OES_texture_float 1
+#endif /* GL_OES_texture_float */
+
+#ifndef GL_OES_texture_float_linear
+#define GL_OES_texture_float_linear 1
+#endif /* GL_OES_texture_float_linear */
+
+#ifndef GL_OES_texture_half_float
+#define GL_OES_texture_half_float 1
+#define GL_HALF_FLOAT_OES 0x8D61
+#endif /* GL_OES_texture_half_float */
+
+#ifndef GL_OES_texture_half_float_linear
+#define GL_OES_texture_half_float_linear 1
+#endif /* GL_OES_texture_half_float_linear */
+
+#ifndef GL_OES_texture_npot
+#define GL_OES_texture_npot 1
+#endif /* GL_OES_texture_npot */
+
+#ifndef GL_OES_texture_stencil8
+#define GL_OES_texture_stencil8 1
+#define GL_STENCIL_INDEX_OES 0x1901
+#define GL_STENCIL_INDEX8_OES 0x8D48
+#endif /* GL_OES_texture_stencil8 */
+
+#ifndef GL_OES_texture_storage_multisample_2d_array
+#define GL_OES_texture_storage_multisample_2d_array 1
+#define GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES 0x9102
+#define GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY_OES 0x9105
+#define GL_SAMPLER_2D_MULTISAMPLE_ARRAY_OES 0x910B
+#define GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY_OES 0x910C
+#define GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY_OES 0x910D
+typedef void (GL_APIENTRYP PFNGLTEXSTORAGE3DMULTISAMPLEOESPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glTexStorage3DMultisampleOES (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations);
+#endif
+#endif /* GL_OES_texture_storage_multisample_2d_array */
+
+#ifndef GL_OES_texture_view
+#define GL_OES_texture_view 1
+#define GL_TEXTURE_VIEW_MIN_LEVEL_OES 0x82DB
+#define GL_TEXTURE_VIEW_NUM_LEVELS_OES 0x82DC
+#define GL_TEXTURE_VIEW_MIN_LAYER_OES 0x82DD
+#define GL_TEXTURE_VIEW_NUM_LAYERS_OES 0x82DE
+#define GL_TEXTURE_IMMUTABLE_LEVELS 0x82DF
+typedef void (GL_APIENTRYP PFNGLTEXTUREVIEWOESPROC) (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glTextureViewOES (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers);
+#endif
+#endif /* GL_OES_texture_view */
+
+#ifndef GL_OES_vertex_array_object
+#define GL_OES_vertex_array_object 1
+#define GL_VERTEX_ARRAY_BINDING_OES 0x85B5
+typedef void (GL_APIENTRYP PFNGLBINDVERTEXARRAYOESPROC) (GLuint array);
+typedef void (GL_APIENTRYP PFNGLDELETEVERTEXARRAYSOESPROC) (GLsizei n, const GLuint *arrays);
+typedef void (GL_APIENTRYP PFNGLGENVERTEXARRAYSOESPROC) (GLsizei n, GLuint *arrays);
+typedef GLboolean (GL_APIENTRYP PFNGLISVERTEXARRAYOESPROC) (GLuint array);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glBindVertexArrayOES (GLuint array);
+GL_APICALL void GL_APIENTRY glDeleteVertexArraysOES (GLsizei n, const GLuint *arrays);
+GL_APICALL void GL_APIENTRY glGenVertexArraysOES (GLsizei n, GLuint *arrays);
+GL_APICALL GLboolean GL_APIENTRY glIsVertexArrayOES (GLuint array);
+#endif
+#endif /* GL_OES_vertex_array_object */
+
+#ifndef GL_OES_vertex_half_float
+#define GL_OES_vertex_half_float 1
+#endif /* GL_OES_vertex_half_float */
+
+#ifndef GL_OES_vertex_type_10_10_10_2
+#define GL_OES_vertex_type_10_10_10_2 1
+#define GL_UNSIGNED_INT_10_10_10_2_OES 0x8DF6
+#define GL_INT_10_10_10_2_OES 0x8DF7
+#endif /* GL_OES_vertex_type_10_10_10_2 */
+
+#ifndef GL_OES_viewport_array
+#define GL_OES_viewport_array 1
+#define GL_MAX_VIEWPORTS_OES 0x825B
+#define GL_VIEWPORT_SUBPIXEL_BITS_OES 0x825C
+#define GL_VIEWPORT_BOUNDS_RANGE_OES 0x825D
+#define GL_VIEWPORT_INDEX_PROVOKING_VERTEX_OES 0x825F
+typedef void (GL_APIENTRYP PFNGLVIEWPORTARRAYVOESPROC) (GLuint first, GLsizei count, const GLfloat *v);
+typedef void (GL_APIENTRYP PFNGLVIEWPORTINDEXEDFOESPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h);
+typedef void (GL_APIENTRYP PFNGLVIEWPORTINDEXEDFVOESPROC) (GLuint index, const GLfloat *v);
+typedef void (GL_APIENTRYP PFNGLSCISSORARRAYVOESPROC) (GLuint first, GLsizei count, const GLint *v);
+typedef void (GL_APIENTRYP PFNGLSCISSORINDEXEDOESPROC) (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLSCISSORINDEXEDVOESPROC) (GLuint index, const GLint *v);
+typedef void (GL_APIENTRYP PFNGLDEPTHRANGEARRAYFVOESPROC) (GLuint first, GLsizei count, const GLfloat *v);
+typedef void (GL_APIENTRYP PFNGLDEPTHRANGEINDEXEDFOESPROC) (GLuint index, GLfloat n, GLfloat f);
+typedef void (GL_APIENTRYP PFNGLGETFLOATI_VOESPROC) (GLenum target, GLuint index, GLfloat *data);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glViewportArrayvOES (GLuint first, GLsizei count, const GLfloat *v);
+GL_APICALL void GL_APIENTRY glViewportIndexedfOES (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h);
+GL_APICALL void GL_APIENTRY glViewportIndexedfvOES (GLuint index, const GLfloat *v);
+GL_APICALL void GL_APIENTRY glScissorArrayvOES (GLuint first, GLsizei count, const GLint *v);
+GL_APICALL void GL_APIENTRY glScissorIndexedOES (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glScissorIndexedvOES (GLuint index, const GLint *v);
+GL_APICALL void GL_APIENTRY glDepthRangeArrayfvOES (GLuint first, GLsizei count, const GLfloat *v);
+GL_APICALL void GL_APIENTRY glDepthRangeIndexedfOES (GLuint index, GLfloat n, GLfloat f);
+GL_APICALL void GL_APIENTRY glGetFloati_vOES (GLenum target, GLuint index, GLfloat *data);
+#endif
+#endif /* GL_OES_viewport_array */
+
+#ifndef GL_AMD_compressed_3DC_texture
+#define GL_AMD_compressed_3DC_texture 1
+#define GL_3DC_X_AMD 0x87F9
+#define GL_3DC_XY_AMD 0x87FA
+#endif /* GL_AMD_compressed_3DC_texture */
+
+#ifndef GL_AMD_compressed_ATC_texture
+#define GL_AMD_compressed_ATC_texture 1
+#define GL_ATC_RGB_AMD 0x8C92
+#define GL_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93
+#define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE
+#endif /* GL_AMD_compressed_ATC_texture */
+
+#ifndef GL_AMD_performance_monitor
+#define GL_AMD_performance_monitor 1
+#define GL_COUNTER_TYPE_AMD 0x8BC0
+#define GL_COUNTER_RANGE_AMD 0x8BC1
+#define GL_UNSIGNED_INT64_AMD 0x8BC2
+#define GL_PERCENTAGE_AMD 0x8BC3
+#define GL_PERFMON_RESULT_AVAILABLE_AMD 0x8BC4
+#define GL_PERFMON_RESULT_SIZE_AMD 0x8BC5
+#define GL_PERFMON_RESULT_AMD 0x8BC6
+typedef void (GL_APIENTRYP PFNGLGETPERFMONITORGROUPSAMDPROC) (GLint *numGroups, GLsizei groupsSize, GLuint *groups);
+typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERSAMDPROC) (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters);
+typedef void (GL_APIENTRYP PFNGLGETPERFMONITORGROUPSTRINGAMDPROC) (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString);
+typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERSTRINGAMDPROC) (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString);
+typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERINFOAMDPROC) (GLuint group, GLuint counter, GLenum pname, void *data);
+typedef void (GL_APIENTRYP PFNGLGENPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors);
+typedef void (GL_APIENTRYP PFNGLDELETEPERFMONITORSAMDPROC) (GLsizei n, GLuint *monitors);
+typedef void (GL_APIENTRYP PFNGLSELECTPERFMONITORCOUNTERSAMDPROC) (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *counterList);
+typedef void (GL_APIENTRYP PFNGLBEGINPERFMONITORAMDPROC) (GLuint monitor);
+typedef void (GL_APIENTRYP PFNGLENDPERFMONITORAMDPROC) (GLuint monitor);
+typedef void (GL_APIENTRYP PFNGLGETPERFMONITORCOUNTERDATAAMDPROC) (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glGetPerfMonitorGroupsAMD (GLint *numGroups, GLsizei groupsSize, GLuint *groups);
+GL_APICALL void GL_APIENTRY glGetPerfMonitorCountersAMD (GLuint group, GLint *numCounters, GLint *maxActiveCounters, GLsizei counterSize, GLuint *counters);
+GL_APICALL void GL_APIENTRY glGetPerfMonitorGroupStringAMD (GLuint group, GLsizei bufSize, GLsizei *length, GLchar *groupString);
+GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterStringAMD (GLuint group, GLuint counter, GLsizei bufSize, GLsizei *length, GLchar *counterString);
+GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterInfoAMD (GLuint group, GLuint counter, GLenum pname, void *data);
+GL_APICALL void GL_APIENTRY glGenPerfMonitorsAMD (GLsizei n, GLuint *monitors);
+GL_APICALL void GL_APIENTRY glDeletePerfMonitorsAMD (GLsizei n, GLuint *monitors);
+GL_APICALL void GL_APIENTRY glSelectPerfMonitorCountersAMD (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint *counterList);
+GL_APICALL void GL_APIENTRY glBeginPerfMonitorAMD (GLuint monitor);
+GL_APICALL void GL_APIENTRY glEndPerfMonitorAMD (GLuint monitor);
+GL_APICALL void GL_APIENTRY glGetPerfMonitorCounterDataAMD (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint *data, GLint *bytesWritten);
+#endif
+#endif /* GL_AMD_performance_monitor */
+
+#ifndef GL_AMD_program_binary_Z400
+#define GL_AMD_program_binary_Z400 1
+#define GL_Z400_BINARY_AMD 0x8740
+#endif /* GL_AMD_program_binary_Z400 */
+
+#ifndef GL_ANDROID_extension_pack_es31a
+#define GL_ANDROID_extension_pack_es31a 1
+#endif /* GL_ANDROID_extension_pack_es31a */
+
+#ifndef GL_ANGLE_depth_texture
+#define GL_ANGLE_depth_texture 1
+#endif /* GL_ANGLE_depth_texture */
+
+#ifndef GL_ANGLE_framebuffer_blit
+#define GL_ANGLE_framebuffer_blit 1
+#define GL_READ_FRAMEBUFFER_ANGLE 0x8CA8
+#define GL_DRAW_FRAMEBUFFER_ANGLE 0x8CA9
+#define GL_DRAW_FRAMEBUFFER_BINDING_ANGLE 0x8CA6
+#define GL_READ_FRAMEBUFFER_BINDING_ANGLE 0x8CAA
+typedef void (GL_APIENTRYP PFNGLBLITFRAMEBUFFERANGLEPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glBlitFramebufferANGLE (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+#endif
+#endif /* GL_ANGLE_framebuffer_blit */
+
+#ifndef GL_ANGLE_framebuffer_multisample
+#define GL_ANGLE_framebuffer_multisample 1
+#define GL_RENDERBUFFER_SAMPLES_ANGLE 0x8CAB
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_ANGLE 0x8D56
+#define GL_MAX_SAMPLES_ANGLE 0x8D57
+typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEANGLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleANGLE (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+#endif
+#endif /* GL_ANGLE_framebuffer_multisample */
+
+#ifndef GL_ANGLE_instanced_arrays
+#define GL_ANGLE_instanced_arrays 1
+#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE 0x88FE
+typedef void (GL_APIENTRYP PFNGLDRAWARRAYSINSTANCEDANGLEPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount);
+typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSINSTANCEDANGLEPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
+typedef void (GL_APIENTRYP PFNGLVERTEXATTRIBDIVISORANGLEPROC) (GLuint index, GLuint divisor);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDrawArraysInstancedANGLE (GLenum mode, GLint first, GLsizei count, GLsizei primcount);
+GL_APICALL void GL_APIENTRY glDrawElementsInstancedANGLE (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
+GL_APICALL void GL_APIENTRY glVertexAttribDivisorANGLE (GLuint index, GLuint divisor);
+#endif
+#endif /* GL_ANGLE_instanced_arrays */
+
+#ifndef GL_ANGLE_pack_reverse_row_order
+#define GL_ANGLE_pack_reverse_row_order 1
+#define GL_PACK_REVERSE_ROW_ORDER_ANGLE 0x93A4
+#endif /* GL_ANGLE_pack_reverse_row_order */
+
+#ifndef GL_ANGLE_program_binary
+#define GL_ANGLE_program_binary 1
+#define GL_PROGRAM_BINARY_ANGLE 0x93A6
+#endif /* GL_ANGLE_program_binary */
+
+#ifndef GL_ANGLE_texture_compression_dxt3
+#define GL_ANGLE_texture_compression_dxt3 1
+#define GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE 0x83F2
+#endif /* GL_ANGLE_texture_compression_dxt3 */
+
+#ifndef GL_ANGLE_texture_compression_dxt5
+#define GL_ANGLE_texture_compression_dxt5 1
+#define GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE 0x83F3
+#endif /* GL_ANGLE_texture_compression_dxt5 */
+
+#ifndef GL_ANGLE_texture_usage
+#define GL_ANGLE_texture_usage 1
+#define GL_TEXTURE_USAGE_ANGLE 0x93A2
+#define GL_FRAMEBUFFER_ATTACHMENT_ANGLE 0x93A3
+#endif /* GL_ANGLE_texture_usage */
+
+#ifndef GL_ANGLE_translated_shader_source
+#define GL_ANGLE_translated_shader_source 1
+#define GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE 0x93A0
+typedef void (GL_APIENTRYP PFNGLGETTRANSLATEDSHADERSOURCEANGLEPROC) (GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glGetTranslatedShaderSourceANGLE (GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source);
+#endif
+#endif /* GL_ANGLE_translated_shader_source */
+
+#ifndef GL_APPLE_clip_distance
+#define GL_APPLE_clip_distance 1
+#define GL_MAX_CLIP_DISTANCES_APPLE 0x0D32
+#define GL_CLIP_DISTANCE0_APPLE 0x3000
+#define GL_CLIP_DISTANCE1_APPLE 0x3001
+#define GL_CLIP_DISTANCE2_APPLE 0x3002
+#define GL_CLIP_DISTANCE3_APPLE 0x3003
+#define GL_CLIP_DISTANCE4_APPLE 0x3004
+#define GL_CLIP_DISTANCE5_APPLE 0x3005
+#define GL_CLIP_DISTANCE6_APPLE 0x3006
+#define GL_CLIP_DISTANCE7_APPLE 0x3007
+#endif /* GL_APPLE_clip_distance */
+
+#ifndef GL_APPLE_color_buffer_packed_float
+#define GL_APPLE_color_buffer_packed_float 1
+#endif /* GL_APPLE_color_buffer_packed_float */
+
+#ifndef GL_APPLE_copy_texture_levels
+#define GL_APPLE_copy_texture_levels 1
+typedef void (GL_APIENTRYP PFNGLCOPYTEXTURELEVELSAPPLEPROC) (GLuint destinationTexture, GLuint sourceTexture, GLint sourceBaseLevel, GLsizei sourceLevelCount);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glCopyTextureLevelsAPPLE (GLuint destinationTexture, GLuint sourceTexture, GLint sourceBaseLevel, GLsizei sourceLevelCount);
+#endif
+#endif /* GL_APPLE_copy_texture_levels */
+
+#ifndef GL_APPLE_framebuffer_multisample
+#define GL_APPLE_framebuffer_multisample 1
+#define GL_RENDERBUFFER_SAMPLES_APPLE 0x8CAB
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_APPLE 0x8D56
+#define GL_MAX_SAMPLES_APPLE 0x8D57
+#define GL_READ_FRAMEBUFFER_APPLE 0x8CA8
+#define GL_DRAW_FRAMEBUFFER_APPLE 0x8CA9
+#define GL_DRAW_FRAMEBUFFER_BINDING_APPLE 0x8CA6
+#define GL_READ_FRAMEBUFFER_BINDING_APPLE 0x8CAA
+typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEAPPLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLRESOLVEMULTISAMPLEFRAMEBUFFERAPPLEPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleAPPLE (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glResolveMultisampleFramebufferAPPLE (void);
+#endif
+#endif /* GL_APPLE_framebuffer_multisample */
+
+#ifndef GL_APPLE_rgb_422
+#define GL_APPLE_rgb_422 1
+#define GL_RGB_422_APPLE 0x8A1F
+#define GL_UNSIGNED_SHORT_8_8_APPLE 0x85BA
+#define GL_UNSIGNED_SHORT_8_8_REV_APPLE 0x85BB
+#define GL_RGB_RAW_422_APPLE 0x8A51
+#endif /* GL_APPLE_rgb_422 */
+
+#ifndef GL_APPLE_sync
+#define GL_APPLE_sync 1
+#define GL_SYNC_OBJECT_APPLE 0x8A53
+#define GL_MAX_SERVER_WAIT_TIMEOUT_APPLE 0x9111
+#define GL_OBJECT_TYPE_APPLE 0x9112
+#define GL_SYNC_CONDITION_APPLE 0x9113
+#define GL_SYNC_STATUS_APPLE 0x9114
+#define GL_SYNC_FLAGS_APPLE 0x9115
+#define GL_SYNC_FENCE_APPLE 0x9116
+#define GL_SYNC_GPU_COMMANDS_COMPLETE_APPLE 0x9117
+#define GL_UNSIGNALED_APPLE 0x9118
+#define GL_SIGNALED_APPLE 0x9119
+#define GL_ALREADY_SIGNALED_APPLE 0x911A
+#define GL_TIMEOUT_EXPIRED_APPLE 0x911B
+#define GL_CONDITION_SATISFIED_APPLE 0x911C
+#define GL_WAIT_FAILED_APPLE 0x911D
+#define GL_SYNC_FLUSH_COMMANDS_BIT_APPLE 0x00000001
+#define GL_TIMEOUT_IGNORED_APPLE 0xFFFFFFFFFFFFFFFFull
+typedef GLsync (GL_APIENTRYP PFNGLFENCESYNCAPPLEPROC) (GLenum condition, GLbitfield flags);
+typedef GLboolean (GL_APIENTRYP PFNGLISSYNCAPPLEPROC) (GLsync sync);
+typedef void (GL_APIENTRYP PFNGLDELETESYNCAPPLEPROC) (GLsync sync);
+typedef GLenum (GL_APIENTRYP PFNGLCLIENTWAITSYNCAPPLEPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout);
+typedef void (GL_APIENTRYP PFNGLWAITSYNCAPPLEPROC) (GLsync sync, GLbitfield flags, GLuint64 timeout);
+typedef void (GL_APIENTRYP PFNGLGETINTEGER64VAPPLEPROC) (GLenum pname, GLint64 *params);
+typedef void (GL_APIENTRYP PFNGLGETSYNCIVAPPLEPROC) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL GLsync GL_APIENTRY glFenceSyncAPPLE (GLenum condition, GLbitfield flags);
+GL_APICALL GLboolean GL_APIENTRY glIsSyncAPPLE (GLsync sync);
+GL_APICALL void GL_APIENTRY glDeleteSyncAPPLE (GLsync sync);
+GL_APICALL GLenum GL_APIENTRY glClientWaitSyncAPPLE (GLsync sync, GLbitfield flags, GLuint64 timeout);
+GL_APICALL void GL_APIENTRY glWaitSyncAPPLE (GLsync sync, GLbitfield flags, GLuint64 timeout);
+GL_APICALL void GL_APIENTRY glGetInteger64vAPPLE (GLenum pname, GLint64 *params);
+GL_APICALL void GL_APIENTRY glGetSyncivAPPLE (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values);
+#endif
+#endif /* GL_APPLE_sync */
+
+#ifndef GL_APPLE_texture_format_BGRA8888
+#define GL_APPLE_texture_format_BGRA8888 1
+#define GL_BGRA_EXT 0x80E1
+#define GL_BGRA8_EXT 0x93A1
+#endif /* GL_APPLE_texture_format_BGRA8888 */
+
+#ifndef GL_APPLE_texture_max_level
+#define GL_APPLE_texture_max_level 1
+#define GL_TEXTURE_MAX_LEVEL_APPLE 0x813D
+#endif /* GL_APPLE_texture_max_level */
+
+#ifndef GL_APPLE_texture_packed_float
+#define GL_APPLE_texture_packed_float 1
+#define GL_UNSIGNED_INT_10F_11F_11F_REV_APPLE 0x8C3B
+#define GL_UNSIGNED_INT_5_9_9_9_REV_APPLE 0x8C3E
+#define GL_R11F_G11F_B10F_APPLE 0x8C3A
+#define GL_RGB9_E5_APPLE 0x8C3D
+#endif /* GL_APPLE_texture_packed_float */
+
+#ifndef GL_ARM_mali_program_binary
+#define GL_ARM_mali_program_binary 1
+#define GL_MALI_PROGRAM_BINARY_ARM 0x8F61
+#endif /* GL_ARM_mali_program_binary */
+
+#ifndef GL_ARM_mali_shader_binary
+#define GL_ARM_mali_shader_binary 1
+#define GL_MALI_SHADER_BINARY_ARM 0x8F60
+#endif /* GL_ARM_mali_shader_binary */
+
+#ifndef GL_ARM_rgba8
+#define GL_ARM_rgba8 1
+#endif /* GL_ARM_rgba8 */
+
+#ifndef GL_ARM_shader_framebuffer_fetch
+#define GL_ARM_shader_framebuffer_fetch 1
+#define GL_FETCH_PER_SAMPLE_ARM 0x8F65
+#define GL_FRAGMENT_SHADER_FRAMEBUFFER_FETCH_MRT_ARM 0x8F66
+#endif /* GL_ARM_shader_framebuffer_fetch */
+
+#ifndef GL_ARM_shader_framebuffer_fetch_depth_stencil
+#define GL_ARM_shader_framebuffer_fetch_depth_stencil 1
+#endif /* GL_ARM_shader_framebuffer_fetch_depth_stencil */
+
+#ifndef GL_DMP_program_binary
+#define GL_DMP_program_binary 1
+#define GL_SMAPHS30_PROGRAM_BINARY_DMP 0x9251
+#define GL_SMAPHS_PROGRAM_BINARY_DMP 0x9252
+#define GL_DMP_PROGRAM_BINARY_DMP 0x9253
+#endif /* GL_DMP_program_binary */
+
+#ifndef GL_DMP_shader_binary
+#define GL_DMP_shader_binary 1
+#define GL_SHADER_BINARY_DMP 0x9250
+#endif /* GL_DMP_shader_binary */
+
+#ifndef GL_EXT_EGL_image_array
+#define GL_EXT_EGL_image_array 1
+#endif /* GL_EXT_EGL_image_array */
+
+#ifndef GL_EXT_YUV_target
+#define GL_EXT_YUV_target 1
+#define GL_SAMPLER_EXTERNAL_2D_Y2Y_EXT 0x8BE7
+#endif /* GL_EXT_YUV_target */
+
+#ifndef GL_EXT_base_instance
+#define GL_EXT_base_instance 1
+typedef void (GL_APIENTRYP PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEEXTPROC) (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance);
+typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEINSTANCEEXTPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance);
+typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEEXTPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDrawArraysInstancedBaseInstanceEXT (GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance);
+GL_APICALL void GL_APIENTRY glDrawElementsInstancedBaseInstanceEXT (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLuint baseinstance);
+GL_APICALL void GL_APIENTRY glDrawElementsInstancedBaseVertexBaseInstanceEXT (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance);
+#endif
+#endif /* GL_EXT_base_instance */
+
+#ifndef GL_EXT_blend_func_extended
+#define GL_EXT_blend_func_extended 1
+#define GL_SRC1_COLOR_EXT 0x88F9
+#define GL_SRC1_ALPHA_EXT 0x8589
+#define GL_ONE_MINUS_SRC1_COLOR_EXT 0x88FA
+#define GL_ONE_MINUS_SRC1_ALPHA_EXT 0x88FB
+#define GL_SRC_ALPHA_SATURATE_EXT 0x0308
+#define GL_LOCATION_INDEX_EXT 0x930F
+#define GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT 0x88FC
+typedef void (GL_APIENTRYP PFNGLBINDFRAGDATALOCATIONINDEXEDEXTPROC) (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name);
+typedef void (GL_APIENTRYP PFNGLBINDFRAGDATALOCATIONEXTPROC) (GLuint program, GLuint color, const GLchar *name);
+typedef GLint (GL_APIENTRYP PFNGLGETPROGRAMRESOURCELOCATIONINDEXEXTPROC) (GLuint program, GLenum programInterface, const GLchar *name);
+typedef GLint (GL_APIENTRYP PFNGLGETFRAGDATAINDEXEXTPROC) (GLuint program, const GLchar *name);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glBindFragDataLocationIndexedEXT (GLuint program, GLuint colorNumber, GLuint index, const GLchar *name);
+GL_APICALL void GL_APIENTRY glBindFragDataLocationEXT (GLuint program, GLuint color, const GLchar *name);
+GL_APICALL GLint GL_APIENTRY glGetProgramResourceLocationIndexEXT (GLuint program, GLenum programInterface, const GLchar *name);
+GL_APICALL GLint GL_APIENTRY glGetFragDataIndexEXT (GLuint program, const GLchar *name);
+#endif
+#endif /* GL_EXT_blend_func_extended */
+
+#ifndef GL_EXT_blend_minmax
+#define GL_EXT_blend_minmax 1
+#define GL_MIN_EXT 0x8007
+#define GL_MAX_EXT 0x8008
+#endif /* GL_EXT_blend_minmax */
+
+#ifndef GL_EXT_buffer_storage
+#define GL_EXT_buffer_storage 1
+#define GL_MAP_READ_BIT 0x0001
+#define GL_MAP_WRITE_BIT 0x0002
+#define GL_MAP_PERSISTENT_BIT_EXT 0x0040
+#define GL_MAP_COHERENT_BIT_EXT 0x0080
+#define GL_DYNAMIC_STORAGE_BIT_EXT 0x0100
+#define GL_CLIENT_STORAGE_BIT_EXT 0x0200
+#define GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT_EXT 0x00004000
+#define GL_BUFFER_IMMUTABLE_STORAGE_EXT 0x821F
+#define GL_BUFFER_STORAGE_FLAGS_EXT 0x8220
+typedef void (GL_APIENTRYP PFNGLBUFFERSTORAGEEXTPROC) (GLenum target, GLsizeiptr size, const void *data, GLbitfield flags);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glBufferStorageEXT (GLenum target, GLsizeiptr size, const void *data, GLbitfield flags);
+#endif
+#endif /* GL_EXT_buffer_storage */
+
+#ifndef GL_EXT_clear_texture
+#define GL_EXT_clear_texture 1
+typedef void (GL_APIENTRYP PFNGLCLEARTEXIMAGEEXTPROC) (GLuint texture, GLint level, GLenum format, GLenum type, const void *data);
+typedef void (GL_APIENTRYP PFNGLCLEARTEXSUBIMAGEEXTPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *data);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glClearTexImageEXT (GLuint texture, GLint level, GLenum format, GLenum type, const void *data);
+GL_APICALL void GL_APIENTRY glClearTexSubImageEXT (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *data);
+#endif
+#endif /* GL_EXT_clear_texture */
+
+#ifndef GL_EXT_clip_control
+#define GL_EXT_clip_control 1
+#define GL_LOWER_LEFT_EXT 0x8CA1
+#define GL_UPPER_LEFT_EXT 0x8CA2
+#define GL_NEGATIVE_ONE_TO_ONE_EXT 0x935E
+#define GL_ZERO_TO_ONE_EXT 0x935F
+#define GL_CLIP_ORIGIN_EXT 0x935C
+#define GL_CLIP_DEPTH_MODE_EXT 0x935D
+typedef void (GL_APIENTRYP PFNGLCLIPCONTROLEXTPROC) (GLenum origin, GLenum depth);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glClipControlEXT (GLenum origin, GLenum depth);
+#endif
+#endif /* GL_EXT_clip_control */
+
+#ifndef GL_EXT_clip_cull_distance
+#define GL_EXT_clip_cull_distance 1
+#define GL_MAX_CLIP_DISTANCES_EXT 0x0D32
+#define GL_MAX_CULL_DISTANCES_EXT 0x82F9
+#define GL_MAX_COMBINED_CLIP_AND_CULL_DISTANCES_EXT 0x82FA
+#define GL_CLIP_DISTANCE0_EXT 0x3000
+#define GL_CLIP_DISTANCE1_EXT 0x3001
+#define GL_CLIP_DISTANCE2_EXT 0x3002
+#define GL_CLIP_DISTANCE3_EXT 0x3003
+#define GL_CLIP_DISTANCE4_EXT 0x3004
+#define GL_CLIP_DISTANCE5_EXT 0x3005
+#define GL_CLIP_DISTANCE6_EXT 0x3006
+#define GL_CLIP_DISTANCE7_EXT 0x3007
+#endif /* GL_EXT_clip_cull_distance */
+
+#ifndef GL_EXT_color_buffer_float
+#define GL_EXT_color_buffer_float 1
+#endif /* GL_EXT_color_buffer_float */
+
+#ifndef GL_EXT_color_buffer_half_float
+#define GL_EXT_color_buffer_half_float 1
+#define GL_RGBA16F_EXT 0x881A
+#define GL_RGB16F_EXT 0x881B
+#define GL_RG16F_EXT 0x822F
+#define GL_R16F_EXT 0x822D
+#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT 0x8211
+#define GL_UNSIGNED_NORMALIZED_EXT 0x8C17
+#endif /* GL_EXT_color_buffer_half_float */
+
+#ifndef GL_EXT_conservative_depth
+#define GL_EXT_conservative_depth 1
+#endif /* GL_EXT_conservative_depth */
+
+#ifndef GL_EXT_copy_image
+#define GL_EXT_copy_image 1
+typedef void (GL_APIENTRYP PFNGLCOPYIMAGESUBDATAEXTPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glCopyImageSubDataEXT (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth);
+#endif
+#endif /* GL_EXT_copy_image */
+
+#ifndef GL_EXT_debug_label
+#define GL_EXT_debug_label 1
+#define GL_PROGRAM_PIPELINE_OBJECT_EXT 0x8A4F
+#define GL_PROGRAM_OBJECT_EXT 0x8B40
+#define GL_SHADER_OBJECT_EXT 0x8B48
+#define GL_BUFFER_OBJECT_EXT 0x9151
+#define GL_QUERY_OBJECT_EXT 0x9153
+#define GL_VERTEX_ARRAY_OBJECT_EXT 0x9154
+#define GL_TRANSFORM_FEEDBACK 0x8E22
+typedef void (GL_APIENTRYP PFNGLLABELOBJECTEXTPROC) (GLenum type, GLuint object, GLsizei length, const GLchar *label);
+typedef void (GL_APIENTRYP PFNGLGETOBJECTLABELEXTPROC) (GLenum type, GLuint object, GLsizei bufSize, GLsizei *length, GLchar *label);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glLabelObjectEXT (GLenum type, GLuint object, GLsizei length, const GLchar *label);
+GL_APICALL void GL_APIENTRY glGetObjectLabelEXT (GLenum type, GLuint object, GLsizei bufSize, GLsizei *length, GLchar *label);
+#endif
+#endif /* GL_EXT_debug_label */
+
+#ifndef GL_EXT_debug_marker
+#define GL_EXT_debug_marker 1
+typedef void (GL_APIENTRYP PFNGLINSERTEVENTMARKEREXTPROC) (GLsizei length, const GLchar *marker);
+typedef void (GL_APIENTRYP PFNGLPUSHGROUPMARKEREXTPROC) (GLsizei length, const GLchar *marker);
+typedef void (GL_APIENTRYP PFNGLPOPGROUPMARKEREXTPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glInsertEventMarkerEXT (GLsizei length, const GLchar *marker);
+GL_APICALL void GL_APIENTRY glPushGroupMarkerEXT (GLsizei length, const GLchar *marker);
+GL_APICALL void GL_APIENTRY glPopGroupMarkerEXT (void);
+#endif
+#endif /* GL_EXT_debug_marker */
+
+#ifndef GL_EXT_discard_framebuffer
+#define GL_EXT_discard_framebuffer 1
+#define GL_COLOR_EXT 0x1800
+#define GL_DEPTH_EXT 0x1801
+#define GL_STENCIL_EXT 0x1802
+typedef void (GL_APIENTRYP PFNGLDISCARDFRAMEBUFFEREXTPROC) (GLenum target, GLsizei numAttachments, const GLenum *attachments);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDiscardFramebufferEXT (GLenum target, GLsizei numAttachments, const GLenum *attachments);
+#endif
+#endif /* GL_EXT_discard_framebuffer */
+
+#ifndef GL_EXT_disjoint_timer_query
+#define GL_EXT_disjoint_timer_query 1
+#define GL_QUERY_COUNTER_BITS_EXT 0x8864
+#define GL_CURRENT_QUERY_EXT 0x8865
+#define GL_QUERY_RESULT_EXT 0x8866
+#define GL_QUERY_RESULT_AVAILABLE_EXT 0x8867
+#define GL_TIME_ELAPSED_EXT 0x88BF
+#define GL_TIMESTAMP_EXT 0x8E28
+#define GL_GPU_DISJOINT_EXT 0x8FBB
+typedef void (GL_APIENTRYP PFNGLGENQUERIESEXTPROC) (GLsizei n, GLuint *ids);
+typedef void (GL_APIENTRYP PFNGLDELETEQUERIESEXTPROC) (GLsizei n, const GLuint *ids);
+typedef GLboolean (GL_APIENTRYP PFNGLISQUERYEXTPROC) (GLuint id);
+typedef void (GL_APIENTRYP PFNGLBEGINQUERYEXTPROC) (GLenum target, GLuint id);
+typedef void (GL_APIENTRYP PFNGLENDQUERYEXTPROC) (GLenum target);
+typedef void (GL_APIENTRYP PFNGLQUERYCOUNTEREXTPROC) (GLuint id, GLenum target);
+typedef void (GL_APIENTRYP PFNGLGETQUERYIVEXTPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLGETQUERYOBJECTIVEXTPROC) (GLuint id, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLGETQUERYOBJECTUIVEXTPROC) (GLuint id, GLenum pname, GLuint *params);
+typedef void (GL_APIENTRYP PFNGLGETQUERYOBJECTI64VEXTPROC) (GLuint id, GLenum pname, GLint64 *params);
+typedef void (GL_APIENTRYP PFNGLGETQUERYOBJECTUI64VEXTPROC) (GLuint id, GLenum pname, GLuint64 *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glGenQueriesEXT (GLsizei n, GLuint *ids);
+GL_APICALL void GL_APIENTRY glDeleteQueriesEXT (GLsizei n, const GLuint *ids);
+GL_APICALL GLboolean GL_APIENTRY glIsQueryEXT (GLuint id);
+GL_APICALL void GL_APIENTRY glBeginQueryEXT (GLenum target, GLuint id);
+GL_APICALL void GL_APIENTRY glEndQueryEXT (GLenum target);
+GL_APICALL void GL_APIENTRY glQueryCounterEXT (GLuint id, GLenum target);
+GL_APICALL void GL_APIENTRY glGetQueryivEXT (GLenum target, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glGetQueryObjectivEXT (GLuint id, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glGetQueryObjectuivEXT (GLuint id, GLenum pname, GLuint *params);
+GL_APICALL void GL_APIENTRY glGetQueryObjecti64vEXT (GLuint id, GLenum pname, GLint64 *params);
+GL_APICALL void GL_APIENTRY glGetQueryObjectui64vEXT (GLuint id, GLenum pname, GLuint64 *params);
+#endif
+#endif /* GL_EXT_disjoint_timer_query */
+
+#ifndef GL_EXT_draw_buffers
+#define GL_EXT_draw_buffers 1
+#define GL_MAX_COLOR_ATTACHMENTS_EXT 0x8CDF
+#define GL_MAX_DRAW_BUFFERS_EXT 0x8824
+#define GL_DRAW_BUFFER0_EXT 0x8825
+#define GL_DRAW_BUFFER1_EXT 0x8826
+#define GL_DRAW_BUFFER2_EXT 0x8827
+#define GL_DRAW_BUFFER3_EXT 0x8828
+#define GL_DRAW_BUFFER4_EXT 0x8829
+#define GL_DRAW_BUFFER5_EXT 0x882A
+#define GL_DRAW_BUFFER6_EXT 0x882B
+#define GL_DRAW_BUFFER7_EXT 0x882C
+#define GL_DRAW_BUFFER8_EXT 0x882D
+#define GL_DRAW_BUFFER9_EXT 0x882E
+#define GL_DRAW_BUFFER10_EXT 0x882F
+#define GL_DRAW_BUFFER11_EXT 0x8830
+#define GL_DRAW_BUFFER12_EXT 0x8831
+#define GL_DRAW_BUFFER13_EXT 0x8832
+#define GL_DRAW_BUFFER14_EXT 0x8833
+#define GL_DRAW_BUFFER15_EXT 0x8834
+#define GL_COLOR_ATTACHMENT0_EXT 0x8CE0
+#define GL_COLOR_ATTACHMENT1_EXT 0x8CE1
+#define GL_COLOR_ATTACHMENT2_EXT 0x8CE2
+#define GL_COLOR_ATTACHMENT3_EXT 0x8CE3
+#define GL_COLOR_ATTACHMENT4_EXT 0x8CE4
+#define GL_COLOR_ATTACHMENT5_EXT 0x8CE5
+#define GL_COLOR_ATTACHMENT6_EXT 0x8CE6
+#define GL_COLOR_ATTACHMENT7_EXT 0x8CE7
+#define GL_COLOR_ATTACHMENT8_EXT 0x8CE8
+#define GL_COLOR_ATTACHMENT9_EXT 0x8CE9
+#define GL_COLOR_ATTACHMENT10_EXT 0x8CEA
+#define GL_COLOR_ATTACHMENT11_EXT 0x8CEB
+#define GL_COLOR_ATTACHMENT12_EXT 0x8CEC
+#define GL_COLOR_ATTACHMENT13_EXT 0x8CED
+#define GL_COLOR_ATTACHMENT14_EXT 0x8CEE
+#define GL_COLOR_ATTACHMENT15_EXT 0x8CEF
+typedef void (GL_APIENTRYP PFNGLDRAWBUFFERSEXTPROC) (GLsizei n, const GLenum *bufs);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDrawBuffersEXT (GLsizei n, const GLenum *bufs);
+#endif
+#endif /* GL_EXT_draw_buffers */
+
+#ifndef GL_EXT_draw_buffers_indexed
+#define GL_EXT_draw_buffers_indexed 1
+typedef void (GL_APIENTRYP PFNGLENABLEIEXTPROC) (GLenum target, GLuint index);
+typedef void (GL_APIENTRYP PFNGLDISABLEIEXTPROC) (GLenum target, GLuint index);
+typedef void (GL_APIENTRYP PFNGLBLENDEQUATIONIEXTPROC) (GLuint buf, GLenum mode);
+typedef void (GL_APIENTRYP PFNGLBLENDEQUATIONSEPARATEIEXTPROC) (GLuint buf, GLenum modeRGB, GLenum modeAlpha);
+typedef void (GL_APIENTRYP PFNGLBLENDFUNCIEXTPROC) (GLuint buf, GLenum src, GLenum dst);
+typedef void (GL_APIENTRYP PFNGLBLENDFUNCSEPARATEIEXTPROC) (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+typedef void (GL_APIENTRYP PFNGLCOLORMASKIEXTPROC) (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a);
+typedef GLboolean (GL_APIENTRYP PFNGLISENABLEDIEXTPROC) (GLenum target, GLuint index);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glEnableiEXT (GLenum target, GLuint index);
+GL_APICALL void GL_APIENTRY glDisableiEXT (GLenum target, GLuint index);
+GL_APICALL void GL_APIENTRY glBlendEquationiEXT (GLuint buf, GLenum mode);
+GL_APICALL void GL_APIENTRY glBlendEquationSeparateiEXT (GLuint buf, GLenum modeRGB, GLenum modeAlpha);
+GL_APICALL void GL_APIENTRY glBlendFunciEXT (GLuint buf, GLenum src, GLenum dst);
+GL_APICALL void GL_APIENTRY glBlendFuncSeparateiEXT (GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
+GL_APICALL void GL_APIENTRY glColorMaskiEXT (GLuint index, GLboolean r, GLboolean g, GLboolean b, GLboolean a);
+GL_APICALL GLboolean GL_APIENTRY glIsEnablediEXT (GLenum target, GLuint index);
+#endif
+#endif /* GL_EXT_draw_buffers_indexed */
+
+#ifndef GL_EXT_draw_elements_base_vertex
+#define GL_EXT_draw_elements_base_vertex 1
+typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXEXTPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
+typedef void (GL_APIENTRYP PFNGLDRAWRANGEELEMENTSBASEVERTEXEXTPROC) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLint basevertex);
+typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXEXTPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDrawElementsBaseVertexEXT (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
+GL_APICALL void GL_APIENTRY glDrawRangeElementsBaseVertexEXT (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLint basevertex);
+GL_APICALL void GL_APIENTRY glDrawElementsInstancedBaseVertexEXT (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex);
+#endif
+#endif /* GL_EXT_draw_elements_base_vertex */
+
+#ifndef GL_EXT_draw_instanced
+#define GL_EXT_draw_instanced 1
+typedef void (GL_APIENTRYP PFNGLDRAWARRAYSINSTANCEDEXTPROC) (GLenum mode, GLint start, GLsizei count, GLsizei primcount);
+typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSINSTANCEDEXTPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDrawArraysInstancedEXT (GLenum mode, GLint start, GLsizei count, GLsizei primcount);
+GL_APICALL void GL_APIENTRY glDrawElementsInstancedEXT (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
+#endif
+#endif /* GL_EXT_draw_instanced */
+
+#ifndef GL_EXT_draw_transform_feedback
+#define GL_EXT_draw_transform_feedback 1
+typedef void (GL_APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKEXTPROC) (GLenum mode, GLuint id);
+typedef void (GL_APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDEXTPROC) (GLenum mode, GLuint id, GLsizei instancecount);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDrawTransformFeedbackEXT (GLenum mode, GLuint id);
+GL_APICALL void GL_APIENTRY glDrawTransformFeedbackInstancedEXT (GLenum mode, GLuint id, GLsizei instancecount);
+#endif
+#endif /* GL_EXT_draw_transform_feedback */
+
+#ifndef GL_EXT_external_buffer
+#define GL_EXT_external_buffer 1
+typedef void *GLeglClientBufferEXT;
+typedef void (GL_APIENTRYP PFNGLBUFFERSTORAGEEXTERNALEXTPROC) (GLenum target, GLintptr offset, GLsizeiptr size, GLeglClientBufferEXT clientBuffer, GLbitfield flags);
+typedef void (GL_APIENTRYP PFNGLNAMEDBUFFERSTORAGEEXTERNALEXTPROC) (GLuint buffer, GLintptr offset, GLsizeiptr size, GLeglClientBufferEXT clientBuffer, GLbitfield flags);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glBufferStorageExternalEXT (GLenum target, GLintptr offset, GLsizeiptr size, GLeglClientBufferEXT clientBuffer, GLbitfield flags);
+GL_APICALL void GL_APIENTRY glNamedBufferStorageExternalEXT (GLuint buffer, GLintptr offset, GLsizeiptr size, GLeglClientBufferEXT clientBuffer, GLbitfield flags);
+#endif
+#endif /* GL_EXT_external_buffer */
+
+#ifndef GL_EXT_float_blend
+#define GL_EXT_float_blend 1
+#endif /* GL_EXT_float_blend */
+
+#ifndef GL_EXT_geometry_point_size
+#define GL_EXT_geometry_point_size 1
+#endif /* GL_EXT_geometry_point_size */
+
+#ifndef GL_EXT_geometry_shader
+#define GL_EXT_geometry_shader 1
+#define GL_GEOMETRY_SHADER_EXT 0x8DD9
+#define GL_GEOMETRY_SHADER_BIT_EXT 0x00000004
+#define GL_GEOMETRY_LINKED_VERTICES_OUT_EXT 0x8916
+#define GL_GEOMETRY_LINKED_INPUT_TYPE_EXT 0x8917
+#define GL_GEOMETRY_LINKED_OUTPUT_TYPE_EXT 0x8918
+#define GL_GEOMETRY_SHADER_INVOCATIONS_EXT 0x887F
+#define GL_LAYER_PROVOKING_VERTEX_EXT 0x825E
+#define GL_LINES_ADJACENCY_EXT 0x000A
+#define GL_LINE_STRIP_ADJACENCY_EXT 0x000B
+#define GL_TRIANGLES_ADJACENCY_EXT 0x000C
+#define GL_TRIANGLE_STRIP_ADJACENCY_EXT 0x000D
+#define GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT 0x8DDF
+#define GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT 0x8A2C
+#define GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT 0x8A32
+#define GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT 0x9123
+#define GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT 0x9124
+#define GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT 0x8DE0
+#define GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT 0x8DE1
+#define GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT 0x8E5A
+#define GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT 0x8C29
+#define GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT 0x92CF
+#define GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT 0x92D5
+#define GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT 0x90CD
+#define GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT 0x90D7
+#define GL_FIRST_VERTEX_CONVENTION_EXT 0x8E4D
+#define GL_LAST_VERTEX_CONVENTION_EXT 0x8E4E
+#define GL_UNDEFINED_VERTEX_EXT 0x8260
+#define GL_PRIMITIVES_GENERATED_EXT 0x8C87
+#define GL_FRAMEBUFFER_DEFAULT_LAYERS_EXT 0x9312
+#define GL_MAX_FRAMEBUFFER_LAYERS_EXT 0x9317
+#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS_EXT 0x8DA8
+#define GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT 0x8DA7
+#define GL_REFERENCED_BY_GEOMETRY_SHADER_EXT 0x9309
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTUREEXTPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glFramebufferTextureEXT (GLenum target, GLenum attachment, GLuint texture, GLint level);
+#endif
+#endif /* GL_EXT_geometry_shader */
+
+#ifndef GL_EXT_gpu_shader5
+#define GL_EXT_gpu_shader5 1
+#endif /* GL_EXT_gpu_shader5 */
+
+#ifndef GL_EXT_instanced_arrays
+#define GL_EXT_instanced_arrays 1
+#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_EXT 0x88FE
+typedef void (GL_APIENTRYP PFNGLVERTEXATTRIBDIVISOREXTPROC) (GLuint index, GLuint divisor);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glVertexAttribDivisorEXT (GLuint index, GLuint divisor);
+#endif
+#endif /* GL_EXT_instanced_arrays */
+
+#ifndef GL_EXT_map_buffer_range
+#define GL_EXT_map_buffer_range 1
+#define GL_MAP_READ_BIT_EXT 0x0001
+#define GL_MAP_WRITE_BIT_EXT 0x0002
+#define GL_MAP_INVALIDATE_RANGE_BIT_EXT 0x0004
+#define GL_MAP_INVALIDATE_BUFFER_BIT_EXT 0x0008
+#define GL_MAP_FLUSH_EXPLICIT_BIT_EXT 0x0010
+#define GL_MAP_UNSYNCHRONIZED_BIT_EXT 0x0020
+typedef void *(GL_APIENTRYP PFNGLMAPBUFFERRANGEEXTPROC) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access);
+typedef void (GL_APIENTRYP PFNGLFLUSHMAPPEDBUFFERRANGEEXTPROC) (GLenum target, GLintptr offset, GLsizeiptr length);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void *GL_APIENTRY glMapBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access);
+GL_APICALL void GL_APIENTRY glFlushMappedBufferRangeEXT (GLenum target, GLintptr offset, GLsizeiptr length);
+#endif
+#endif /* GL_EXT_map_buffer_range */
+
+#ifndef GL_EXT_memory_object
+#define GL_EXT_memory_object 1
+#define GL_TEXTURE_TILING_EXT 0x9580
+#define GL_DEDICATED_MEMORY_OBJECT_EXT 0x9581
+#define GL_PROTECTED_MEMORY_OBJECT_EXT 0x959B
+#define GL_NUM_TILING_TYPES_EXT 0x9582
+#define GL_TILING_TYPES_EXT 0x9583
+#define GL_OPTIMAL_TILING_EXT 0x9584
+#define GL_LINEAR_TILING_EXT 0x9585
+#define GL_NUM_DEVICE_UUIDS_EXT 0x9596
+#define GL_DEVICE_UUID_EXT 0x9597
+#define GL_DRIVER_UUID_EXT 0x9598
+#define GL_UUID_SIZE_EXT 16
+typedef void (GL_APIENTRYP PFNGLGETUNSIGNEDBYTEVEXTPROC) (GLenum pname, GLubyte *data);
+typedef void (GL_APIENTRYP PFNGLGETUNSIGNEDBYTEI_VEXTPROC) (GLenum target, GLuint index, GLubyte *data);
+typedef void (GL_APIENTRYP PFNGLDELETEMEMORYOBJECTSEXTPROC) (GLsizei n, const GLuint *memoryObjects);
+typedef GLboolean (GL_APIENTRYP PFNGLISMEMORYOBJECTEXTPROC) (GLuint memoryObject);
+typedef void (GL_APIENTRYP PFNGLCREATEMEMORYOBJECTSEXTPROC) (GLsizei n, GLuint *memoryObjects);
+typedef void (GL_APIENTRYP PFNGLMEMORYOBJECTPARAMETERIVEXTPROC) (GLuint memoryObject, GLenum pname, const GLint *params);
+typedef void (GL_APIENTRYP PFNGLGETMEMORYOBJECTPARAMETERIVEXTPROC) (GLuint memoryObject, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLTEXSTORAGEMEM2DEXTPROC) (GLenum target, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLuint memory, GLuint64 offset);
+typedef void (GL_APIENTRYP PFNGLTEXSTORAGEMEM2DMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations, GLuint memory, GLuint64 offset);
+typedef void (GL_APIENTRYP PFNGLTEXSTORAGEMEM3DEXTPROC) (GLenum target, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLuint memory, GLuint64 offset);
+typedef void (GL_APIENTRYP PFNGLTEXSTORAGEMEM3DMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations, GLuint memory, GLuint64 offset);
+typedef void (GL_APIENTRYP PFNGLBUFFERSTORAGEMEMEXTPROC) (GLenum target, GLsizeiptr size, GLuint memory, GLuint64 offset);
+typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGEMEM2DEXTPROC) (GLuint texture, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLuint memory, GLuint64 offset);
+typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGEMEM2DMULTISAMPLEEXTPROC) (GLuint texture, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations, GLuint memory, GLuint64 offset);
+typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGEMEM3DEXTPROC) (GLuint texture, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLuint memory, GLuint64 offset);
+typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGEMEM3DMULTISAMPLEEXTPROC) (GLuint texture, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations, GLuint memory, GLuint64 offset);
+typedef void (GL_APIENTRYP PFNGLNAMEDBUFFERSTORAGEMEMEXTPROC) (GLuint buffer, GLsizeiptr size, GLuint memory, GLuint64 offset);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glGetUnsignedBytevEXT (GLenum pname, GLubyte *data);
+GL_APICALL void GL_APIENTRY glGetUnsignedBytei_vEXT (GLenum target, GLuint index, GLubyte *data);
+GL_APICALL void GL_APIENTRY glDeleteMemoryObjectsEXT (GLsizei n, const GLuint *memoryObjects);
+GL_APICALL GLboolean GL_APIENTRY glIsMemoryObjectEXT (GLuint memoryObject);
+GL_APICALL void GL_APIENTRY glCreateMemoryObjectsEXT (GLsizei n, GLuint *memoryObjects);
+GL_APICALL void GL_APIENTRY glMemoryObjectParameterivEXT (GLuint memoryObject, GLenum pname, const GLint *params);
+GL_APICALL void GL_APIENTRY glGetMemoryObjectParameterivEXT (GLuint memoryObject, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glTexStorageMem2DEXT (GLenum target, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLuint memory, GLuint64 offset);
+GL_APICALL void GL_APIENTRY glTexStorageMem2DMultisampleEXT (GLenum target, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations, GLuint memory, GLuint64 offset);
+GL_APICALL void GL_APIENTRY glTexStorageMem3DEXT (GLenum target, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLuint memory, GLuint64 offset);
+GL_APICALL void GL_APIENTRY glTexStorageMem3DMultisampleEXT (GLenum target, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations, GLuint memory, GLuint64 offset);
+GL_APICALL void GL_APIENTRY glBufferStorageMemEXT (GLenum target, GLsizeiptr size, GLuint memory, GLuint64 offset);
+GL_APICALL void GL_APIENTRY glTextureStorageMem2DEXT (GLuint texture, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLuint memory, GLuint64 offset);
+GL_APICALL void GL_APIENTRY glTextureStorageMem2DMultisampleEXT (GLuint texture, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height, GLboolean fixedSampleLocations, GLuint memory, GLuint64 offset);
+GL_APICALL void GL_APIENTRY glTextureStorageMem3DEXT (GLuint texture, GLsizei levels, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLuint memory, GLuint64 offset);
+GL_APICALL void GL_APIENTRY glTextureStorageMem3DMultisampleEXT (GLuint texture, GLsizei samples, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedSampleLocations, GLuint memory, GLuint64 offset);
+GL_APICALL void GL_APIENTRY glNamedBufferStorageMemEXT (GLuint buffer, GLsizeiptr size, GLuint memory, GLuint64 offset);
+#endif
+#endif /* GL_EXT_memory_object */
+
+#ifndef GL_EXT_memory_object_fd
+#define GL_EXT_memory_object_fd 1
+#define GL_HANDLE_TYPE_OPAQUE_FD_EXT 0x9586
+typedef void (GL_APIENTRYP PFNGLIMPORTMEMORYFDEXTPROC) (GLuint memory, GLuint64 size, GLenum handleType, GLint fd);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glImportMemoryFdEXT (GLuint memory, GLuint64 size, GLenum handleType, GLint fd);
+#endif
+#endif /* GL_EXT_memory_object_fd */
+
+#ifndef GL_EXT_memory_object_win32
+#define GL_EXT_memory_object_win32 1
+#define GL_HANDLE_TYPE_OPAQUE_WIN32_EXT 0x9587
+#define GL_HANDLE_TYPE_OPAQUE_WIN32_KMT_EXT 0x9588
+#define GL_DEVICE_LUID_EXT 0x9599
+#define GL_DEVICE_NODE_MASK_EXT 0x959A
+#define GL_LUID_SIZE_EXT 8
+#define GL_HANDLE_TYPE_D3D12_TILEPOOL_EXT 0x9589
+#define GL_HANDLE_TYPE_D3D12_RESOURCE_EXT 0x958A
+#define GL_HANDLE_TYPE_D3D11_IMAGE_EXT 0x958B
+#define GL_HANDLE_TYPE_D3D11_IMAGE_KMT_EXT 0x958C
+typedef void (GL_APIENTRYP PFNGLIMPORTMEMORYWIN32HANDLEEXTPROC) (GLuint memory, GLuint64 size, GLenum handleType, void *handle);
+typedef void (GL_APIENTRYP PFNGLIMPORTMEMORYWIN32NAMEEXTPROC) (GLuint memory, GLuint64 size, GLenum handleType, const void *name);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glImportMemoryWin32HandleEXT (GLuint memory, GLuint64 size, GLenum handleType, void *handle);
+GL_APICALL void GL_APIENTRY glImportMemoryWin32NameEXT (GLuint memory, GLuint64 size, GLenum handleType, const void *name);
+#endif
+#endif /* GL_EXT_memory_object_win32 */
+
+#ifndef GL_EXT_multi_draw_arrays
+#define GL_EXT_multi_draw_arrays 1
+typedef void (GL_APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount);
+typedef void (GL_APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei primcount);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glMultiDrawArraysEXT (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount);
+GL_APICALL void GL_APIENTRY glMultiDrawElementsEXT (GLenum mode, const GLsizei *count, GLenum type, const void *const*indices, GLsizei primcount);
+#endif
+#endif /* GL_EXT_multi_draw_arrays */
+
+#ifndef GL_EXT_multi_draw_indirect
+#define GL_EXT_multi_draw_indirect 1
+typedef void (GL_APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTEXTPROC) (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride);
+typedef void (GL_APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTEXTPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glMultiDrawArraysIndirectEXT (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride);
+GL_APICALL void GL_APIENTRY glMultiDrawElementsIndirectEXT (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride);
+#endif
+#endif /* GL_EXT_multi_draw_indirect */
+
+#ifndef GL_EXT_multisampled_compatibility
+#define GL_EXT_multisampled_compatibility 1
+#define GL_MULTISAMPLE_EXT 0x809D
+#define GL_SAMPLE_ALPHA_TO_ONE_EXT 0x809F
+#endif /* GL_EXT_multisampled_compatibility */
+
+#ifndef GL_EXT_multisampled_render_to_texture
+#define GL_EXT_multisampled_render_to_texture 1
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT 0x8D6C
+#define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56
+#define GL_MAX_SAMPLES_EXT 0x8D57
+typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleEXT (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glFramebufferTexture2DMultisampleEXT (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples);
+#endif
+#endif /* GL_EXT_multisampled_render_to_texture */
+
+#ifndef GL_EXT_multiview_draw_buffers
+#define GL_EXT_multiview_draw_buffers 1
+#define GL_COLOR_ATTACHMENT_EXT 0x90F0
+#define GL_MULTIVIEW_EXT 0x90F1
+#define GL_DRAW_BUFFER_EXT 0x0C01
+#define GL_READ_BUFFER_EXT 0x0C02
+#define GL_MAX_MULTIVIEW_BUFFERS_EXT 0x90F2
+typedef void (GL_APIENTRYP PFNGLREADBUFFERINDEXEDEXTPROC) (GLenum src, GLint index);
+typedef void (GL_APIENTRYP PFNGLDRAWBUFFERSINDEXEDEXTPROC) (GLint n, const GLenum *location, const GLint *indices);
+typedef void (GL_APIENTRYP PFNGLGETINTEGERI_VEXTPROC) (GLenum target, GLuint index, GLint *data);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glReadBufferIndexedEXT (GLenum src, GLint index);
+GL_APICALL void GL_APIENTRY glDrawBuffersIndexedEXT (GLint n, const GLenum *location, const GLint *indices);
+GL_APICALL void GL_APIENTRY glGetIntegeri_vEXT (GLenum target, GLuint index, GLint *data);
+#endif
+#endif /* GL_EXT_multiview_draw_buffers */
+
+#ifndef GL_EXT_occlusion_query_boolean
+#define GL_EXT_occlusion_query_boolean 1
+#define GL_ANY_SAMPLES_PASSED_EXT 0x8C2F
+#define GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT 0x8D6A
+#endif /* GL_EXT_occlusion_query_boolean */
+
+#ifndef GL_EXT_polygon_offset_clamp
+#define GL_EXT_polygon_offset_clamp 1
+#define GL_POLYGON_OFFSET_CLAMP_EXT 0x8E1B
+typedef void (GL_APIENTRYP PFNGLPOLYGONOFFSETCLAMPEXTPROC) (GLfloat factor, GLfloat units, GLfloat clamp);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glPolygonOffsetClampEXT (GLfloat factor, GLfloat units, GLfloat clamp);
+#endif
+#endif /* GL_EXT_polygon_offset_clamp */
+
+#ifndef GL_EXT_post_depth_coverage
+#define GL_EXT_post_depth_coverage 1
+#endif /* GL_EXT_post_depth_coverage */
+
+#ifndef GL_EXT_primitive_bounding_box
+#define GL_EXT_primitive_bounding_box 1
+#define GL_PRIMITIVE_BOUNDING_BOX_EXT 0x92BE
+typedef void (GL_APIENTRYP PFNGLPRIMITIVEBOUNDINGBOXEXTPROC) (GLfloat minX, GLfloat minY, GLfloat minZ, GLfloat minW, GLfloat maxX, GLfloat maxY, GLfloat maxZ, GLfloat maxW);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glPrimitiveBoundingBoxEXT (GLfloat minX, GLfloat minY, GLfloat minZ, GLfloat minW, GLfloat maxX, GLfloat maxY, GLfloat maxZ, GLfloat maxW);
+#endif
+#endif /* GL_EXT_primitive_bounding_box */
+
+#ifndef GL_EXT_protected_textures
+#define GL_EXT_protected_textures 1
+#define GL_CONTEXT_FLAG_PROTECTED_CONTENT_BIT_EXT 0x00000010
+#define GL_TEXTURE_PROTECTED_EXT 0x8BFA
+#endif /* GL_EXT_protected_textures */
+
+#ifndef GL_EXT_pvrtc_sRGB
+#define GL_EXT_pvrtc_sRGB 1
+#define GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT 0x8A54
+#define GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT 0x8A55
+#define GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT 0x8A56
+#define GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT 0x8A57
+#define GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV2_IMG 0x93F0
+#define GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV2_IMG 0x93F1
+#endif /* GL_EXT_pvrtc_sRGB */
+
+#ifndef GL_EXT_raster_multisample
+#define GL_EXT_raster_multisample 1
+#define GL_RASTER_MULTISAMPLE_EXT 0x9327
+#define GL_RASTER_SAMPLES_EXT 0x9328
+#define GL_MAX_RASTER_SAMPLES_EXT 0x9329
+#define GL_RASTER_FIXED_SAMPLE_LOCATIONS_EXT 0x932A
+#define GL_MULTISAMPLE_RASTERIZATION_ALLOWED_EXT 0x932B
+#define GL_EFFECTIVE_RASTER_SAMPLES_EXT 0x932C
+typedef void (GL_APIENTRYP PFNGLRASTERSAMPLESEXTPROC) (GLuint samples, GLboolean fixedsamplelocations);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glRasterSamplesEXT (GLuint samples, GLboolean fixedsamplelocations);
+#endif
+#endif /* GL_EXT_raster_multisample */
+
+#ifndef GL_EXT_read_format_bgra
+#define GL_EXT_read_format_bgra 1
+#define GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT 0x8365
+#define GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT 0x8366
+#endif /* GL_EXT_read_format_bgra */
+
+#ifndef GL_EXT_render_snorm
+#define GL_EXT_render_snorm 1
+#define GL_R8_SNORM 0x8F94
+#define GL_RG8_SNORM 0x8F95
+#define GL_RGBA8_SNORM 0x8F97
+#define GL_R16_SNORM_EXT 0x8F98
+#define GL_RG16_SNORM_EXT 0x8F99
+#define GL_RGBA16_SNORM_EXT 0x8F9B
+#endif /* GL_EXT_render_snorm */
+
+#ifndef GL_EXT_robustness
+#define GL_EXT_robustness 1
+#define GL_GUILTY_CONTEXT_RESET_EXT 0x8253
+#define GL_INNOCENT_CONTEXT_RESET_EXT 0x8254
+#define GL_UNKNOWN_CONTEXT_RESET_EXT 0x8255
+#define GL_CONTEXT_ROBUST_ACCESS_EXT 0x90F3
+#define GL_RESET_NOTIFICATION_STRATEGY_EXT 0x8256
+#define GL_LOSE_CONTEXT_ON_RESET_EXT 0x8252
+#define GL_NO_RESET_NOTIFICATION_EXT 0x8261
+typedef GLenum (GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSEXTPROC) (void);
+typedef void (GL_APIENTRYP PFNGLREADNPIXELSEXTPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void *data);
+typedef void (GL_APIENTRYP PFNGLGETNUNIFORMFVEXTPROC) (GLuint program, GLint location, GLsizei bufSize, GLfloat *params);
+typedef void (GL_APIENTRYP PFNGLGETNUNIFORMIVEXTPROC) (GLuint program, GLint location, GLsizei bufSize, GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL GLenum GL_APIENTRY glGetGraphicsResetStatusEXT (void);
+GL_APICALL void GL_APIENTRY glReadnPixelsEXT (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei bufSize, void *data);
+GL_APICALL void GL_APIENTRY glGetnUniformfvEXT (GLuint program, GLint location, GLsizei bufSize, GLfloat *params);
+GL_APICALL void GL_APIENTRY glGetnUniformivEXT (GLuint program, GLint location, GLsizei bufSize, GLint *params);
+#endif
+#endif /* GL_EXT_robustness */
+
+#ifndef GL_EXT_sRGB
+#define GL_EXT_sRGB 1
+#define GL_SRGB_EXT 0x8C40
+#define GL_SRGB_ALPHA_EXT 0x8C42
+#define GL_SRGB8_ALPHA8_EXT 0x8C43
+#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT 0x8210
+#endif /* GL_EXT_sRGB */
+
+#ifndef GL_EXT_sRGB_write_control
+#define GL_EXT_sRGB_write_control 1
+#define GL_FRAMEBUFFER_SRGB_EXT 0x8DB9
+#endif /* GL_EXT_sRGB_write_control */
+
+#ifndef GL_EXT_semaphore
+#define GL_EXT_semaphore 1
+#define GL_LAYOUT_GENERAL_EXT 0x958D
+#define GL_LAYOUT_COLOR_ATTACHMENT_EXT 0x958E
+#define GL_LAYOUT_DEPTH_STENCIL_ATTACHMENT_EXT 0x958F
+#define GL_LAYOUT_DEPTH_STENCIL_READ_ONLY_EXT 0x9590
+#define GL_LAYOUT_SHADER_READ_ONLY_EXT 0x9591
+#define GL_LAYOUT_TRANSFER_SRC_EXT 0x9592
+#define GL_LAYOUT_TRANSFER_DST_EXT 0x9593
+typedef void (GL_APIENTRYP PFNGLGENSEMAPHORESEXTPROC) (GLsizei n, GLuint *semaphores);
+typedef void (GL_APIENTRYP PFNGLDELETESEMAPHORESEXTPROC) (GLsizei n, const GLuint *semaphores);
+typedef GLboolean (GL_APIENTRYP PFNGLISSEMAPHOREEXTPROC) (GLuint semaphore);
+typedef void (GL_APIENTRYP PFNGLSEMAPHOREPARAMETERUI64VEXTPROC) (GLuint semaphore, GLenum pname, const GLuint64 *params);
+typedef void (GL_APIENTRYP PFNGLGETSEMAPHOREPARAMETERUI64VEXTPROC) (GLuint semaphore, GLenum pname, GLuint64 *params);
+typedef void (GL_APIENTRYP PFNGLWAITSEMAPHOREEXTPROC) (GLuint semaphore, GLuint numBufferBarriers, const GLuint *buffers, GLuint numTextureBarriers, const GLuint *textures, const GLenum *srcLayouts);
+typedef void (GL_APIENTRYP PFNGLSIGNALSEMAPHOREEXTPROC) (GLuint semaphore, GLuint numBufferBarriers, const GLuint *buffers, GLuint numTextureBarriers, const GLuint *textures, const GLenum *dstLayouts);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glGenSemaphoresEXT (GLsizei n, GLuint *semaphores);
+GL_APICALL void GL_APIENTRY glDeleteSemaphoresEXT (GLsizei n, const GLuint *semaphores);
+GL_APICALL GLboolean GL_APIENTRY glIsSemaphoreEXT (GLuint semaphore);
+GL_APICALL void GL_APIENTRY glSemaphoreParameterui64vEXT (GLuint semaphore, GLenum pname, const GLuint64 *params);
+GL_APICALL void GL_APIENTRY glGetSemaphoreParameterui64vEXT (GLuint semaphore, GLenum pname, GLuint64 *params);
+GL_APICALL void GL_APIENTRY glWaitSemaphoreEXT (GLuint semaphore, GLuint numBufferBarriers, const GLuint *buffers, GLuint numTextureBarriers, const GLuint *textures, const GLenum *srcLayouts);
+GL_APICALL void GL_APIENTRY glSignalSemaphoreEXT (GLuint semaphore, GLuint numBufferBarriers, const GLuint *buffers, GLuint numTextureBarriers, const GLuint *textures, const GLenum *dstLayouts);
+#endif
+#endif /* GL_EXT_semaphore */
+
+#ifndef GL_EXT_semaphore_fd
+#define GL_EXT_semaphore_fd 1
+typedef void (GL_APIENTRYP PFNGLIMPORTSEMAPHOREFDEXTPROC) (GLuint semaphore, GLenum handleType, GLint fd);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glImportSemaphoreFdEXT (GLuint semaphore, GLenum handleType, GLint fd);
+#endif
+#endif /* GL_EXT_semaphore_fd */
+
+#ifndef GL_EXT_semaphore_win32
+#define GL_EXT_semaphore_win32 1
+#define GL_HANDLE_TYPE_D3D12_FENCE_EXT 0x9594
+#define GL_D3D12_FENCE_VALUE_EXT 0x9595
+typedef void (GL_APIENTRYP PFNGLIMPORTSEMAPHOREWIN32HANDLEEXTPROC) (GLuint semaphore, GLenum handleType, void *handle);
+typedef void (GL_APIENTRYP PFNGLIMPORTSEMAPHOREWIN32NAMEEXTPROC) (GLuint semaphore, GLenum handleType, const void *name);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glImportSemaphoreWin32HandleEXT (GLuint semaphore, GLenum handleType, void *handle);
+GL_APICALL void GL_APIENTRY glImportSemaphoreWin32NameEXT (GLuint semaphore, GLenum handleType, const void *name);
+#endif
+#endif /* GL_EXT_semaphore_win32 */
+
+#ifndef GL_EXT_separate_shader_objects
+#define GL_EXT_separate_shader_objects 1
+#define GL_ACTIVE_PROGRAM_EXT 0x8259
+#define GL_VERTEX_SHADER_BIT_EXT 0x00000001
+#define GL_FRAGMENT_SHADER_BIT_EXT 0x00000002
+#define GL_ALL_SHADER_BITS_EXT 0xFFFFFFFF
+#define GL_PROGRAM_SEPARABLE_EXT 0x8258
+#define GL_PROGRAM_PIPELINE_BINDING_EXT 0x825A
+typedef void (GL_APIENTRYP PFNGLACTIVESHADERPROGRAMEXTPROC) (GLuint pipeline, GLuint program);
+typedef void (GL_APIENTRYP PFNGLBINDPROGRAMPIPELINEEXTPROC) (GLuint pipeline);
+typedef GLuint (GL_APIENTRYP PFNGLCREATESHADERPROGRAMVEXTPROC) (GLenum type, GLsizei count, const GLchar **strings);
+typedef void (GL_APIENTRYP PFNGLDELETEPROGRAMPIPELINESEXTPROC) (GLsizei n, const GLuint *pipelines);
+typedef void (GL_APIENTRYP PFNGLGENPROGRAMPIPELINESEXTPROC) (GLsizei n, GLuint *pipelines);
+typedef void (GL_APIENTRYP PFNGLGETPROGRAMPIPELINEINFOLOGEXTPROC) (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+typedef void (GL_APIENTRYP PFNGLGETPROGRAMPIPELINEIVEXTPROC) (GLuint pipeline, GLenum pname, GLint *params);
+typedef GLboolean (GL_APIENTRYP PFNGLISPROGRAMPIPELINEEXTPROC) (GLuint pipeline);
+typedef void (GL_APIENTRYP PFNGLPROGRAMPARAMETERIEXTPROC) (GLuint program, GLenum pname, GLint value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1FEXTPROC) (GLuint program, GLint location, GLfloat v0);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1IEXTPROC) (GLuint program, GLint location, GLint v0);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4FEXTPROC) (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4FVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4IEXTPROC) (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4IVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLint *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLUSEPROGRAMSTAGESEXTPROC) (GLuint pipeline, GLbitfield stages, GLuint program);
+typedef void (GL_APIENTRYP PFNGLVALIDATEPROGRAMPIPELINEEXTPROC) (GLuint pipeline);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1UIEXTPROC) (GLuint program, GLint location, GLuint v0);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4UIEXTPROC) (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4UIVEXTPROC) (GLuint program, GLint location, GLsizei count, const GLuint *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMMATRIX2X4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X2FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMMATRIX3X4FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMMATRIX4X3FVEXTPROC) (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glActiveShaderProgramEXT (GLuint pipeline, GLuint program);
+GL_APICALL void GL_APIENTRY glBindProgramPipelineEXT (GLuint pipeline);
+GL_APICALL GLuint GL_APIENTRY glCreateShaderProgramvEXT (GLenum type, GLsizei count, const GLchar **strings);
+GL_APICALL void GL_APIENTRY glDeleteProgramPipelinesEXT (GLsizei n, const GLuint *pipelines);
+GL_APICALL void GL_APIENTRY glGenProgramPipelinesEXT (GLsizei n, GLuint *pipelines);
+GL_APICALL void GL_APIENTRY glGetProgramPipelineInfoLogEXT (GLuint pipeline, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+GL_APICALL void GL_APIENTRY glGetProgramPipelineivEXT (GLuint pipeline, GLenum pname, GLint *params);
+GL_APICALL GLboolean GL_APIENTRY glIsProgramPipelineEXT (GLuint pipeline);
+GL_APICALL void GL_APIENTRY glProgramParameteriEXT (GLuint program, GLenum pname, GLint value);
+GL_APICALL void GL_APIENTRY glProgramUniform1fEXT (GLuint program, GLint location, GLfloat v0);
+GL_APICALL void GL_APIENTRY glProgramUniform1fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniform1iEXT (GLuint program, GLint location, GLint v0);
+GL_APICALL void GL_APIENTRY glProgramUniform1ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GL_APICALL void GL_APIENTRY glProgramUniform2fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1);
+GL_APICALL void GL_APIENTRY glProgramUniform2fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniform2iEXT (GLuint program, GLint location, GLint v0, GLint v1);
+GL_APICALL void GL_APIENTRY glProgramUniform2ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GL_APICALL void GL_APIENTRY glProgramUniform3fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
+GL_APICALL void GL_APIENTRY glProgramUniform3fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniform3iEXT (GLuint program, GLint location, GLint v0, GLint v1, GLint v2);
+GL_APICALL void GL_APIENTRY glProgramUniform3ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GL_APICALL void GL_APIENTRY glProgramUniform4fEXT (GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
+GL_APICALL void GL_APIENTRY glProgramUniform4fvEXT (GLuint program, GLint location, GLsizei count, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniform4iEXT (GLuint program, GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
+GL_APICALL void GL_APIENTRY glProgramUniform4ivEXT (GLuint program, GLint location, GLsizei count, const GLint *value);
+GL_APICALL void GL_APIENTRY glProgramUniformMatrix2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniformMatrix3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniformMatrix4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glUseProgramStagesEXT (GLuint pipeline, GLbitfield stages, GLuint program);
+GL_APICALL void GL_APIENTRY glValidateProgramPipelineEXT (GLuint pipeline);
+GL_APICALL void GL_APIENTRY glProgramUniform1uiEXT (GLuint program, GLint location, GLuint v0);
+GL_APICALL void GL_APIENTRY glProgramUniform2uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1);
+GL_APICALL void GL_APIENTRY glProgramUniform3uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2);
+GL_APICALL void GL_APIENTRY glProgramUniform4uiEXT (GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
+GL_APICALL void GL_APIENTRY glProgramUniform1uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GL_APICALL void GL_APIENTRY glProgramUniform2uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GL_APICALL void GL_APIENTRY glProgramUniform3uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GL_APICALL void GL_APIENTRY glProgramUniform4uivEXT (GLuint program, GLint location, GLsizei count, const GLuint *value);
+GL_APICALL void GL_APIENTRY glProgramUniformMatrix2x3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniformMatrix3x2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniformMatrix2x4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniformMatrix4x2fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniformMatrix3x4fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glProgramUniformMatrix4x3fvEXT (GLuint program, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+#endif
+#endif /* GL_EXT_separate_shader_objects */
+
+#ifndef GL_EXT_shader_framebuffer_fetch
+#define GL_EXT_shader_framebuffer_fetch 1
+#define GL_FRAGMENT_SHADER_DISCARDS_SAMPLES_EXT 0x8A52
+#endif /* GL_EXT_shader_framebuffer_fetch */
+
+#ifndef GL_EXT_shader_group_vote
+#define GL_EXT_shader_group_vote 1
+#endif /* GL_EXT_shader_group_vote */
+
+#ifndef GL_EXT_shader_implicit_conversions
+#define GL_EXT_shader_implicit_conversions 1
+#endif /* GL_EXT_shader_implicit_conversions */
+
+#ifndef GL_EXT_shader_integer_mix
+#define GL_EXT_shader_integer_mix 1
+#endif /* GL_EXT_shader_integer_mix */
+
+#ifndef GL_EXT_shader_io_blocks
+#define GL_EXT_shader_io_blocks 1
+#endif /* GL_EXT_shader_io_blocks */
+
+#ifndef GL_EXT_shader_non_constant_global_initializers
+#define GL_EXT_shader_non_constant_global_initializers 1
+#endif /* GL_EXT_shader_non_constant_global_initializers */
+
+#ifndef GL_EXT_shader_pixel_local_storage
+#define GL_EXT_shader_pixel_local_storage 1
+#define GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT 0x8F63
+#define GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_SIZE_EXT 0x8F67
+#define GL_SHADER_PIXEL_LOCAL_STORAGE_EXT 0x8F64
+#endif /* GL_EXT_shader_pixel_local_storage */
+
+#ifndef GL_EXT_shader_pixel_local_storage2
+#define GL_EXT_shader_pixel_local_storage2 1
+#define GL_MAX_SHADER_COMBINED_LOCAL_STORAGE_FAST_SIZE_EXT 0x9650
+#define GL_MAX_SHADER_COMBINED_LOCAL_STORAGE_SIZE_EXT 0x9651
+#define GL_FRAMEBUFFER_INCOMPLETE_INSUFFICIENT_SHADER_COMBINED_LOCAL_STORAGE_EXT 0x9652
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERPIXELLOCALSTORAGESIZEEXTPROC) (GLuint target, GLsizei size);
+typedef GLsizei (GL_APIENTRYP PFNGLGETFRAMEBUFFERPIXELLOCALSTORAGESIZEEXTPROC) (GLuint target);
+typedef void (GL_APIENTRYP PFNGLCLEARPIXELLOCALSTORAGEUIEXTPROC) (GLsizei offset, GLsizei n, const GLuint *values);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glFramebufferPixelLocalStorageSizeEXT (GLuint target, GLsizei size);
+GL_APICALL GLsizei GL_APIENTRY glGetFramebufferPixelLocalStorageSizeEXT (GLuint target);
+GL_APICALL void GL_APIENTRY glClearPixelLocalStorageuiEXT (GLsizei offset, GLsizei n, const GLuint *values);
+#endif
+#endif /* GL_EXT_shader_pixel_local_storage2 */
+
+#ifndef GL_EXT_shader_texture_lod
+#define GL_EXT_shader_texture_lod 1
+#endif /* GL_EXT_shader_texture_lod */
+
+#ifndef GL_EXT_shadow_samplers
+#define GL_EXT_shadow_samplers 1
+#define GL_TEXTURE_COMPARE_MODE_EXT 0x884C
+#define GL_TEXTURE_COMPARE_FUNC_EXT 0x884D
+#define GL_COMPARE_REF_TO_TEXTURE_EXT 0x884E
+#define GL_SAMPLER_2D_SHADOW_EXT 0x8B62
+#endif /* GL_EXT_shadow_samplers */
+
+#ifndef GL_EXT_sparse_texture
+#define GL_EXT_sparse_texture 1
+#define GL_TEXTURE_SPARSE_EXT 0x91A6
+#define GL_VIRTUAL_PAGE_SIZE_INDEX_EXT 0x91A7
+#define GL_NUM_SPARSE_LEVELS_EXT 0x91AA
+#define GL_NUM_VIRTUAL_PAGE_SIZES_EXT 0x91A8
+#define GL_VIRTUAL_PAGE_SIZE_X_EXT 0x9195
+#define GL_VIRTUAL_PAGE_SIZE_Y_EXT 0x9196
+#define GL_VIRTUAL_PAGE_SIZE_Z_EXT 0x9197
+#define GL_TEXTURE_2D_ARRAY 0x8C1A
+#define GL_TEXTURE_3D 0x806F
+#define GL_MAX_SPARSE_TEXTURE_SIZE_EXT 0x9198
+#define GL_MAX_SPARSE_3D_TEXTURE_SIZE_EXT 0x9199
+#define GL_MAX_SPARSE_ARRAY_TEXTURE_LAYERS_EXT 0x919A
+#define GL_SPARSE_TEXTURE_FULL_ARRAY_CUBE_MIPMAPS_EXT 0x91A9
+typedef void (GL_APIENTRYP PFNGLTEXPAGECOMMITMENTEXTPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLboolean commit);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glTexPageCommitmentEXT (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLboolean commit);
+#endif
+#endif /* GL_EXT_sparse_texture */
+
+#ifndef GL_EXT_sparse_texture2
+#define GL_EXT_sparse_texture2 1
+#endif /* GL_EXT_sparse_texture2 */
+
+#ifndef GL_EXT_tessellation_point_size
+#define GL_EXT_tessellation_point_size 1
+#endif /* GL_EXT_tessellation_point_size */
+
+#ifndef GL_EXT_tessellation_shader
+#define GL_EXT_tessellation_shader 1
+#define GL_PATCHES_EXT 0x000E
+#define GL_PATCH_VERTICES_EXT 0x8E72
+#define GL_TESS_CONTROL_OUTPUT_VERTICES_EXT 0x8E75
+#define GL_TESS_GEN_MODE_EXT 0x8E76
+#define GL_TESS_GEN_SPACING_EXT 0x8E77
+#define GL_TESS_GEN_VERTEX_ORDER_EXT 0x8E78
+#define GL_TESS_GEN_POINT_MODE_EXT 0x8E79
+#define GL_ISOLINES_EXT 0x8E7A
+#define GL_QUADS_EXT 0x0007
+#define GL_FRACTIONAL_ODD_EXT 0x8E7B
+#define GL_FRACTIONAL_EVEN_EXT 0x8E7C
+#define GL_MAX_PATCH_VERTICES_EXT 0x8E7D
+#define GL_MAX_TESS_GEN_LEVEL_EXT 0x8E7E
+#define GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS_EXT 0x8E7F
+#define GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS_EXT 0x8E80
+#define GL_MAX_TESS_CONTROL_TEXTURE_IMAGE_UNITS_EXT 0x8E81
+#define GL_MAX_TESS_EVALUATION_TEXTURE_IMAGE_UNITS_EXT 0x8E82
+#define GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS_EXT 0x8E83
+#define GL_MAX_TESS_PATCH_COMPONENTS_EXT 0x8E84
+#define GL_MAX_TESS_CONTROL_TOTAL_OUTPUT_COMPONENTS_EXT 0x8E85
+#define GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS_EXT 0x8E86
+#define GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS_EXT 0x8E89
+#define GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS_EXT 0x8E8A
+#define GL_MAX_TESS_CONTROL_INPUT_COMPONENTS_EXT 0x886C
+#define GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS_EXT 0x886D
+#define GL_MAX_COMBINED_TESS_CONTROL_UNIFORM_COMPONENTS_EXT 0x8E1E
+#define GL_MAX_COMBINED_TESS_EVALUATION_UNIFORM_COMPONENTS_EXT 0x8E1F
+#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTER_BUFFERS_EXT 0x92CD
+#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTER_BUFFERS_EXT 0x92CE
+#define GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS_EXT 0x92D3
+#define GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS_EXT 0x92D4
+#define GL_MAX_TESS_CONTROL_IMAGE_UNIFORMS_EXT 0x90CB
+#define GL_MAX_TESS_EVALUATION_IMAGE_UNIFORMS_EXT 0x90CC
+#define GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS_EXT 0x90D8
+#define GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS_EXT 0x90D9
+#define GL_PRIMITIVE_RESTART_FOR_PATCHES_SUPPORTED 0x8221
+#define GL_IS_PER_PATCH_EXT 0x92E7
+#define GL_REFERENCED_BY_TESS_CONTROL_SHADER_EXT 0x9307
+#define GL_REFERENCED_BY_TESS_EVALUATION_SHADER_EXT 0x9308
+#define GL_TESS_CONTROL_SHADER_EXT 0x8E88
+#define GL_TESS_EVALUATION_SHADER_EXT 0x8E87
+#define GL_TESS_CONTROL_SHADER_BIT_EXT 0x00000008
+#define GL_TESS_EVALUATION_SHADER_BIT_EXT 0x00000010
+typedef void (GL_APIENTRYP PFNGLPATCHPARAMETERIEXTPROC) (GLenum pname, GLint value);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glPatchParameteriEXT (GLenum pname, GLint value);
+#endif
+#endif /* GL_EXT_tessellation_shader */
+
+#ifndef GL_EXT_texture_border_clamp
+#define GL_EXT_texture_border_clamp 1
+#define GL_TEXTURE_BORDER_COLOR_EXT 0x1004
+#define GL_CLAMP_TO_BORDER_EXT 0x812D
+typedef void (GL_APIENTRYP PFNGLTEXPARAMETERIIVEXTPROC) (GLenum target, GLenum pname, const GLint *params);
+typedef void (GL_APIENTRYP PFNGLTEXPARAMETERIUIVEXTPROC) (GLenum target, GLenum pname, const GLuint *params);
+typedef void (GL_APIENTRYP PFNGLGETTEXPARAMETERIIVEXTPROC) (GLenum target, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLGETTEXPARAMETERIUIVEXTPROC) (GLenum target, GLenum pname, GLuint *params);
+typedef void (GL_APIENTRYP PFNGLSAMPLERPARAMETERIIVEXTPROC) (GLuint sampler, GLenum pname, const GLint *param);
+typedef void (GL_APIENTRYP PFNGLSAMPLERPARAMETERIUIVEXTPROC) (GLuint sampler, GLenum pname, const GLuint *param);
+typedef void (GL_APIENTRYP PFNGLGETSAMPLERPARAMETERIIVEXTPROC) (GLuint sampler, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLGETSAMPLERPARAMETERIUIVEXTPROC) (GLuint sampler, GLenum pname, GLuint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glTexParameterIivEXT (GLenum target, GLenum pname, const GLint *params);
+GL_APICALL void GL_APIENTRY glTexParameterIuivEXT (GLenum target, GLenum pname, const GLuint *params);
+GL_APICALL void GL_APIENTRY glGetTexParameterIivEXT (GLenum target, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glGetTexParameterIuivEXT (GLenum target, GLenum pname, GLuint *params);
+GL_APICALL void GL_APIENTRY glSamplerParameterIivEXT (GLuint sampler, GLenum pname, const GLint *param);
+GL_APICALL void GL_APIENTRY glSamplerParameterIuivEXT (GLuint sampler, GLenum pname, const GLuint *param);
+GL_APICALL void GL_APIENTRY glGetSamplerParameterIivEXT (GLuint sampler, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glGetSamplerParameterIuivEXT (GLuint sampler, GLenum pname, GLuint *params);
+#endif
+#endif /* GL_EXT_texture_border_clamp */
+
+#ifndef GL_EXT_texture_buffer
+#define GL_EXT_texture_buffer 1
+#define GL_TEXTURE_BUFFER_EXT 0x8C2A
+#define GL_TEXTURE_BUFFER_BINDING_EXT 0x8C2A
+#define GL_MAX_TEXTURE_BUFFER_SIZE_EXT 0x8C2B
+#define GL_TEXTURE_BINDING_BUFFER_EXT 0x8C2C
+#define GL_TEXTURE_BUFFER_DATA_STORE_BINDING_EXT 0x8C2D
+#define GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT_EXT 0x919F
+#define GL_SAMPLER_BUFFER_EXT 0x8DC2
+#define GL_INT_SAMPLER_BUFFER_EXT 0x8DD0
+#define GL_UNSIGNED_INT_SAMPLER_BUFFER_EXT 0x8DD8
+#define GL_IMAGE_BUFFER_EXT 0x9051
+#define GL_INT_IMAGE_BUFFER_EXT 0x905C
+#define GL_UNSIGNED_INT_IMAGE_BUFFER_EXT 0x9067
+#define GL_TEXTURE_BUFFER_OFFSET_EXT 0x919D
+#define GL_TEXTURE_BUFFER_SIZE_EXT 0x919E
+typedef void (GL_APIENTRYP PFNGLTEXBUFFEREXTPROC) (GLenum target, GLenum internalformat, GLuint buffer);
+typedef void (GL_APIENTRYP PFNGLTEXBUFFERRANGEEXTPROC) (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glTexBufferEXT (GLenum target, GLenum internalformat, GLuint buffer);
+GL_APICALL void GL_APIENTRY glTexBufferRangeEXT (GLenum target, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizeiptr size);
+#endif
+#endif /* GL_EXT_texture_buffer */
+
+#ifndef GL_EXT_texture_compression_astc_decode_mode
+#define GL_EXT_texture_compression_astc_decode_mode 1
+#define GL_TEXTURE_ASTC_DECODE_PRECISION_EXT 0x8F69
+#endif /* GL_EXT_texture_compression_astc_decode_mode */
+
+#ifndef GL_EXT_texture_compression_bptc
+#define GL_EXT_texture_compression_bptc 1
+#define GL_COMPRESSED_RGBA_BPTC_UNORM_EXT 0x8E8C
+#define GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT 0x8E8D
+#define GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT 0x8E8E
+#define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT 0x8E8F
+#endif /* GL_EXT_texture_compression_bptc */
+
+#ifndef GL_EXT_texture_compression_dxt1
+#define GL_EXT_texture_compression_dxt1 1
+#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
+#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
+#endif /* GL_EXT_texture_compression_dxt1 */
+
+#ifndef GL_EXT_texture_compression_rgtc
+#define GL_EXT_texture_compression_rgtc 1
+#define GL_COMPRESSED_RED_RGTC1_EXT 0x8DBB
+#define GL_COMPRESSED_SIGNED_RED_RGTC1_EXT 0x8DBC
+#define GL_COMPRESSED_RED_GREEN_RGTC2_EXT 0x8DBD
+#define GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT 0x8DBE
+#endif /* GL_EXT_texture_compression_rgtc */
+
+#ifndef GL_EXT_texture_compression_s3tc
+#define GL_EXT_texture_compression_s3tc 1
+#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
+#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
+#endif /* GL_EXT_texture_compression_s3tc */
+
+#ifndef GL_EXT_texture_compression_s3tc_srgb
+#define GL_EXT_texture_compression_s3tc_srgb 1
+#define GL_COMPRESSED_SRGB_S3TC_DXT1_EXT 0x8C4C
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT 0x8C4D
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT 0x8C4E
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT 0x8C4F
+#endif /* GL_EXT_texture_compression_s3tc_srgb */
+
+#ifndef GL_EXT_texture_cube_map_array
+#define GL_EXT_texture_cube_map_array 1
+#define GL_TEXTURE_CUBE_MAP_ARRAY_EXT 0x9009
+#define GL_TEXTURE_BINDING_CUBE_MAP_ARRAY_EXT 0x900A
+#define GL_SAMPLER_CUBE_MAP_ARRAY_EXT 0x900C
+#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_EXT 0x900D
+#define GL_INT_SAMPLER_CUBE_MAP_ARRAY_EXT 0x900E
+#define GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_EXT 0x900F
+#define GL_IMAGE_CUBE_MAP_ARRAY_EXT 0x9054
+#define GL_INT_IMAGE_CUBE_MAP_ARRAY_EXT 0x905F
+#define GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY_EXT 0x906A
+#endif /* GL_EXT_texture_cube_map_array */
+
+#ifndef GL_EXT_texture_filter_anisotropic
+#define GL_EXT_texture_filter_anisotropic 1
+#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
+#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
+#endif /* GL_EXT_texture_filter_anisotropic */
+
+#ifndef GL_EXT_texture_filter_minmax
+#define GL_EXT_texture_filter_minmax 1
+#endif /* GL_EXT_texture_filter_minmax */
+
+#ifndef GL_EXT_texture_format_BGRA8888
+#define GL_EXT_texture_format_BGRA8888 1
+#endif /* GL_EXT_texture_format_BGRA8888 */
+
+#ifndef GL_EXT_texture_norm16
+#define GL_EXT_texture_norm16 1
+#define GL_R16_EXT 0x822A
+#define GL_RG16_EXT 0x822C
+#define GL_RGBA16_EXT 0x805B
+#define GL_RGB16_EXT 0x8054
+#define GL_RGB16_SNORM_EXT 0x8F9A
+#endif /* GL_EXT_texture_norm16 */
+
+#ifndef GL_EXT_texture_rg
+#define GL_EXT_texture_rg 1
+#define GL_RED_EXT 0x1903
+#define GL_RG_EXT 0x8227
+#define GL_R8_EXT 0x8229
+#define GL_RG8_EXT 0x822B
+#endif /* GL_EXT_texture_rg */
+
+#ifndef GL_EXT_texture_sRGB_R8
+#define GL_EXT_texture_sRGB_R8 1
+#define GL_SR8_EXT 0x8FBD
+#endif /* GL_EXT_texture_sRGB_R8 */
+
+#ifndef GL_EXT_texture_sRGB_RG8
+#define GL_EXT_texture_sRGB_RG8 1
+#define GL_SRG8_EXT 0x8FBE
+#endif /* GL_EXT_texture_sRGB_RG8 */
+
+#ifndef GL_EXT_texture_sRGB_decode
+#define GL_EXT_texture_sRGB_decode 1
+#define GL_TEXTURE_SRGB_DECODE_EXT 0x8A48
+#define GL_DECODE_EXT 0x8A49
+#define GL_SKIP_DECODE_EXT 0x8A4A
+#endif /* GL_EXT_texture_sRGB_decode */
+
+#ifndef GL_EXT_texture_storage
+#define GL_EXT_texture_storage 1
+#define GL_TEXTURE_IMMUTABLE_FORMAT_EXT 0x912F
+#define GL_ALPHA8_EXT 0x803C
+#define GL_LUMINANCE8_EXT 0x8040
+#define GL_LUMINANCE8_ALPHA8_EXT 0x8045
+#define GL_RGBA32F_EXT 0x8814
+#define GL_RGB32F_EXT 0x8815
+#define GL_ALPHA32F_EXT 0x8816
+#define GL_LUMINANCE32F_EXT 0x8818
+#define GL_LUMINANCE_ALPHA32F_EXT 0x8819
+#define GL_ALPHA16F_EXT 0x881C
+#define GL_LUMINANCE16F_EXT 0x881E
+#define GL_LUMINANCE_ALPHA16F_EXT 0x881F
+#define GL_R32F_EXT 0x822E
+#define GL_RG32F_EXT 0x8230
+typedef void (GL_APIENTRYP PFNGLTEXSTORAGE1DEXTPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+typedef void (GL_APIENTRYP PFNGLTEXSTORAGE2DEXTPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLTEXSTORAGE3DEXTPROC) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGE1DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGE2DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLTEXTURESTORAGE3DEXTPROC) (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glTexStorage1DEXT (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+GL_APICALL void GL_APIENTRY glTexStorage2DEXT (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glTexStorage3DEXT (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+GL_APICALL void GL_APIENTRY glTextureStorage1DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width);
+GL_APICALL void GL_APIENTRY glTextureStorage2DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glTextureStorage3DEXT (GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
+#endif
+#endif /* GL_EXT_texture_storage */
+
+#ifndef GL_EXT_texture_type_2_10_10_10_REV
+#define GL_EXT_texture_type_2_10_10_10_REV 1
+#define GL_UNSIGNED_INT_2_10_10_10_REV_EXT 0x8368
+#endif /* GL_EXT_texture_type_2_10_10_10_REV */
+
+#ifndef GL_EXT_texture_view
+#define GL_EXT_texture_view 1
+#define GL_TEXTURE_VIEW_MIN_LEVEL_EXT 0x82DB
+#define GL_TEXTURE_VIEW_NUM_LEVELS_EXT 0x82DC
+#define GL_TEXTURE_VIEW_MIN_LAYER_EXT 0x82DD
+#define GL_TEXTURE_VIEW_NUM_LAYERS_EXT 0x82DE
+typedef void (GL_APIENTRYP PFNGLTEXTUREVIEWEXTPROC) (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glTextureViewEXT (GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers);
+#endif
+#endif /* GL_EXT_texture_view */
+
+#ifndef GL_EXT_unpack_subimage
+#define GL_EXT_unpack_subimage 1
+#define GL_UNPACK_ROW_LENGTH_EXT 0x0CF2
+#define GL_UNPACK_SKIP_ROWS_EXT 0x0CF3
+#define GL_UNPACK_SKIP_PIXELS_EXT 0x0CF4
+#endif /* GL_EXT_unpack_subimage */
+
+#ifndef GL_EXT_win32_keyed_mutex
+#define GL_EXT_win32_keyed_mutex 1
+typedef GLboolean (GL_APIENTRYP PFNGLACQUIREKEYEDMUTEXWIN32EXTPROC) (GLuint memory, GLuint64 key, GLuint timeout);
+typedef GLboolean (GL_APIENTRYP PFNGLRELEASEKEYEDMUTEXWIN32EXTPROC) (GLuint memory, GLuint64 key);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL GLboolean GL_APIENTRY glAcquireKeyedMutexWin32EXT (GLuint memory, GLuint64 key, GLuint timeout);
+GL_APICALL GLboolean GL_APIENTRY glReleaseKeyedMutexWin32EXT (GLuint memory, GLuint64 key);
+#endif
+#endif /* GL_EXT_win32_keyed_mutex */
+
+#ifndef GL_EXT_window_rectangles
+#define GL_EXT_window_rectangles 1
+#define GL_INCLUSIVE_EXT 0x8F10
+#define GL_EXCLUSIVE_EXT 0x8F11
+#define GL_WINDOW_RECTANGLE_EXT 0x8F12
+#define GL_WINDOW_RECTANGLE_MODE_EXT 0x8F13
+#define GL_MAX_WINDOW_RECTANGLES_EXT 0x8F14
+#define GL_NUM_WINDOW_RECTANGLES_EXT 0x8F15
+typedef void (GL_APIENTRYP PFNGLWINDOWRECTANGLESEXTPROC) (GLenum mode, GLsizei count, const GLint *box);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glWindowRectanglesEXT (GLenum mode, GLsizei count, const GLint *box);
+#endif
+#endif /* GL_EXT_window_rectangles */
+
+#ifndef GL_FJ_shader_binary_GCCSO
+#define GL_FJ_shader_binary_GCCSO 1
+#define GL_GCCSO_SHADER_BINARY_FJ 0x9260
+#endif /* GL_FJ_shader_binary_GCCSO */
+
+#ifndef GL_IMG_bindless_texture
+#define GL_IMG_bindless_texture 1
+typedef GLuint64 (GL_APIENTRYP PFNGLGETTEXTUREHANDLEIMGPROC) (GLuint texture);
+typedef GLuint64 (GL_APIENTRYP PFNGLGETTEXTURESAMPLERHANDLEIMGPROC) (GLuint texture, GLuint sampler);
+typedef void (GL_APIENTRYP PFNGLUNIFORMHANDLEUI64IMGPROC) (GLint location, GLuint64 value);
+typedef void (GL_APIENTRYP PFNGLUNIFORMHANDLEUI64VIMGPROC) (GLint location, GLsizei count, const GLuint64 *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64IMGPROC) (GLuint program, GLint location, GLuint64 value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64VIMGPROC) (GLuint program, GLint location, GLsizei count, const GLuint64 *values);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL GLuint64 GL_APIENTRY glGetTextureHandleIMG (GLuint texture);
+GL_APICALL GLuint64 GL_APIENTRY glGetTextureSamplerHandleIMG (GLuint texture, GLuint sampler);
+GL_APICALL void GL_APIENTRY glUniformHandleui64IMG (GLint location, GLuint64 value);
+GL_APICALL void GL_APIENTRY glUniformHandleui64vIMG (GLint location, GLsizei count, const GLuint64 *value);
+GL_APICALL void GL_APIENTRY glProgramUniformHandleui64IMG (GLuint program, GLint location, GLuint64 value);
+GL_APICALL void GL_APIENTRY glProgramUniformHandleui64vIMG (GLuint program, GLint location, GLsizei count, const GLuint64 *values);
+#endif
+#endif /* GL_IMG_bindless_texture */
+
+#ifndef GL_IMG_framebuffer_downsample
+#define GL_IMG_framebuffer_downsample 1
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_AND_DOWNSAMPLE_IMG 0x913C
+#define GL_NUM_DOWNSAMPLE_SCALES_IMG 0x913D
+#define GL_DOWNSAMPLE_SCALES_IMG 0x913E
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SCALE_IMG 0x913F
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DDOWNSAMPLEIMGPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint xscale, GLint yscale);
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERDOWNSAMPLEIMGPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer, GLint xscale, GLint yscale);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glFramebufferTexture2DDownsampleIMG (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint xscale, GLint yscale);
+GL_APICALL void GL_APIENTRY glFramebufferTextureLayerDownsampleIMG (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer, GLint xscale, GLint yscale);
+#endif
+#endif /* GL_IMG_framebuffer_downsample */
+
+#ifndef GL_IMG_multisampled_render_to_texture
+#define GL_IMG_multisampled_render_to_texture 1
+#define GL_RENDERBUFFER_SAMPLES_IMG 0x9133
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_IMG 0x9134
+#define GL_MAX_SAMPLES_IMG 0x9135
+#define GL_TEXTURE_SAMPLES_IMG 0x9136
+typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMGPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMGPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleIMG (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glFramebufferTexture2DMultisampleIMG (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples);
+#endif
+#endif /* GL_IMG_multisampled_render_to_texture */
+
+#ifndef GL_IMG_program_binary
+#define GL_IMG_program_binary 1
+#define GL_SGX_PROGRAM_BINARY_IMG 0x9130
+#endif /* GL_IMG_program_binary */
+
+#ifndef GL_IMG_read_format
+#define GL_IMG_read_format 1
+#define GL_BGRA_IMG 0x80E1
+#define GL_UNSIGNED_SHORT_4_4_4_4_REV_IMG 0x8365
+#endif /* GL_IMG_read_format */
+
+#ifndef GL_IMG_shader_binary
+#define GL_IMG_shader_binary 1
+#define GL_SGX_BINARY_IMG 0x8C0A
+#endif /* GL_IMG_shader_binary */
+
+#ifndef GL_IMG_texture_compression_pvrtc
+#define GL_IMG_texture_compression_pvrtc 1
+#define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00
+#define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01
+#define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02
+#define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03
+#endif /* GL_IMG_texture_compression_pvrtc */
+
+#ifndef GL_IMG_texture_compression_pvrtc2
+#define GL_IMG_texture_compression_pvrtc2 1
+#define GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG 0x9137
+#define GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG 0x9138
+#endif /* GL_IMG_texture_compression_pvrtc2 */
+
+#ifndef GL_IMG_texture_filter_cubic
+#define GL_IMG_texture_filter_cubic 1
+#define GL_CUBIC_IMG 0x9139
+#define GL_CUBIC_MIPMAP_NEAREST_IMG 0x913A
+#define GL_CUBIC_MIPMAP_LINEAR_IMG 0x913B
+#endif /* GL_IMG_texture_filter_cubic */
+
+#ifndef GL_INTEL_conservative_rasterization
+#define GL_INTEL_conservative_rasterization 1
+#define GL_CONSERVATIVE_RASTERIZATION_INTEL 0x83FE
+#endif /* GL_INTEL_conservative_rasterization */
+
+#ifndef GL_INTEL_framebuffer_CMAA
+#define GL_INTEL_framebuffer_CMAA 1
+typedef void (GL_APIENTRYP PFNGLAPPLYFRAMEBUFFERATTACHMENTCMAAINTELPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glApplyFramebufferAttachmentCMAAINTEL (void);
+#endif
+#endif /* GL_INTEL_framebuffer_CMAA */
+
+#ifndef GL_INTEL_performance_query
+#define GL_INTEL_performance_query 1
+#define GL_PERFQUERY_SINGLE_CONTEXT_INTEL 0x00000000
+#define GL_PERFQUERY_GLOBAL_CONTEXT_INTEL 0x00000001
+#define GL_PERFQUERY_WAIT_INTEL 0x83FB
+#define GL_PERFQUERY_FLUSH_INTEL 0x83FA
+#define GL_PERFQUERY_DONOT_FLUSH_INTEL 0x83F9
+#define GL_PERFQUERY_COUNTER_EVENT_INTEL 0x94F0
+#define GL_PERFQUERY_COUNTER_DURATION_NORM_INTEL 0x94F1
+#define GL_PERFQUERY_COUNTER_DURATION_RAW_INTEL 0x94F2
+#define GL_PERFQUERY_COUNTER_THROUGHPUT_INTEL 0x94F3
+#define GL_PERFQUERY_COUNTER_RAW_INTEL 0x94F4
+#define GL_PERFQUERY_COUNTER_TIMESTAMP_INTEL 0x94F5
+#define GL_PERFQUERY_COUNTER_DATA_UINT32_INTEL 0x94F8
+#define GL_PERFQUERY_COUNTER_DATA_UINT64_INTEL 0x94F9
+#define GL_PERFQUERY_COUNTER_DATA_FLOAT_INTEL 0x94FA
+#define GL_PERFQUERY_COUNTER_DATA_DOUBLE_INTEL 0x94FB
+#define GL_PERFQUERY_COUNTER_DATA_BOOL32_INTEL 0x94FC
+#define GL_PERFQUERY_QUERY_NAME_LENGTH_MAX_INTEL 0x94FD
+#define GL_PERFQUERY_COUNTER_NAME_LENGTH_MAX_INTEL 0x94FE
+#define GL_PERFQUERY_COUNTER_DESC_LENGTH_MAX_INTEL 0x94FF
+#define GL_PERFQUERY_GPA_EXTENDED_COUNTERS_INTEL 0x9500
+typedef void (GL_APIENTRYP PFNGLBEGINPERFQUERYINTELPROC) (GLuint queryHandle);
+typedef void (GL_APIENTRYP PFNGLCREATEPERFQUERYINTELPROC) (GLuint queryId, GLuint *queryHandle);
+typedef void (GL_APIENTRYP PFNGLDELETEPERFQUERYINTELPROC) (GLuint queryHandle);
+typedef void (GL_APIENTRYP PFNGLENDPERFQUERYINTELPROC) (GLuint queryHandle);
+typedef void (GL_APIENTRYP PFNGLGETFIRSTPERFQUERYIDINTELPROC) (GLuint *queryId);
+typedef void (GL_APIENTRYP PFNGLGETNEXTPERFQUERYIDINTELPROC) (GLuint queryId, GLuint *nextQueryId);
+typedef void (GL_APIENTRYP PFNGLGETPERFCOUNTERINFOINTELPROC) (GLuint queryId, GLuint counterId, GLuint counterNameLength, GLchar *counterName, GLuint counterDescLength, GLchar *counterDesc, GLuint *counterOffset, GLuint *counterDataSize, GLuint *counterTypeEnum, GLuint *counterDataTypeEnum, GLuint64 *rawCounterMaxValue);
+typedef void (GL_APIENTRYP PFNGLGETPERFQUERYDATAINTELPROC) (GLuint queryHandle, GLuint flags, GLsizei dataSize, GLvoid *data, GLuint *bytesWritten);
+typedef void (GL_APIENTRYP PFNGLGETPERFQUERYIDBYNAMEINTELPROC) (GLchar *queryName, GLuint *queryId);
+typedef void (GL_APIENTRYP PFNGLGETPERFQUERYINFOINTELPROC) (GLuint queryId, GLuint queryNameLength, GLchar *queryName, GLuint *dataSize, GLuint *noCounters, GLuint *noInstances, GLuint *capsMask);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glBeginPerfQueryINTEL (GLuint queryHandle);
+GL_APICALL void GL_APIENTRY glCreatePerfQueryINTEL (GLuint queryId, GLuint *queryHandle);
+GL_APICALL void GL_APIENTRY glDeletePerfQueryINTEL (GLuint queryHandle);
+GL_APICALL void GL_APIENTRY glEndPerfQueryINTEL (GLuint queryHandle);
+GL_APICALL void GL_APIENTRY glGetFirstPerfQueryIdINTEL (GLuint *queryId);
+GL_APICALL void GL_APIENTRY glGetNextPerfQueryIdINTEL (GLuint queryId, GLuint *nextQueryId);
+GL_APICALL void GL_APIENTRY glGetPerfCounterInfoINTEL (GLuint queryId, GLuint counterId, GLuint counterNameLength, GLchar *counterName, GLuint counterDescLength, GLchar *counterDesc, GLuint *counterOffset, GLuint *counterDataSize, GLuint *counterTypeEnum, GLuint *counterDataTypeEnum, GLuint64 *rawCounterMaxValue);
+GL_APICALL void GL_APIENTRY glGetPerfQueryDataINTEL (GLuint queryHandle, GLuint flags, GLsizei dataSize, GLvoid *data, GLuint *bytesWritten);
+GL_APICALL void GL_APIENTRY glGetPerfQueryIdByNameINTEL (GLchar *queryName, GLuint *queryId);
+GL_APICALL void GL_APIENTRY glGetPerfQueryInfoINTEL (GLuint queryId, GLuint queryNameLength, GLchar *queryName, GLuint *dataSize, GLuint *noCounters, GLuint *noInstances, GLuint *capsMask);
+#endif
+#endif /* GL_INTEL_performance_query */
+
+#ifndef GL_MESA_shader_integer_functions
+#define GL_MESA_shader_integer_functions 1
+#endif /* GL_MESA_shader_integer_functions */
+
+#ifndef GL_NVX_blend_equation_advanced_multi_draw_buffers
+#define GL_NVX_blend_equation_advanced_multi_draw_buffers 1
+#endif /* GL_NVX_blend_equation_advanced_multi_draw_buffers */
+
+#ifndef GL_NV_bindless_texture
+#define GL_NV_bindless_texture 1
+typedef GLuint64 (GL_APIENTRYP PFNGLGETTEXTUREHANDLENVPROC) (GLuint texture);
+typedef GLuint64 (GL_APIENTRYP PFNGLGETTEXTURESAMPLERHANDLENVPROC) (GLuint texture, GLuint sampler);
+typedef void (GL_APIENTRYP PFNGLMAKETEXTUREHANDLERESIDENTNVPROC) (GLuint64 handle);
+typedef void (GL_APIENTRYP PFNGLMAKETEXTUREHANDLENONRESIDENTNVPROC) (GLuint64 handle);
+typedef GLuint64 (GL_APIENTRYP PFNGLGETIMAGEHANDLENVPROC) (GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format);
+typedef void (GL_APIENTRYP PFNGLMAKEIMAGEHANDLERESIDENTNVPROC) (GLuint64 handle, GLenum access);
+typedef void (GL_APIENTRYP PFNGLMAKEIMAGEHANDLENONRESIDENTNVPROC) (GLuint64 handle);
+typedef void (GL_APIENTRYP PFNGLUNIFORMHANDLEUI64NVPROC) (GLint location, GLuint64 value);
+typedef void (GL_APIENTRYP PFNGLUNIFORMHANDLEUI64VNVPROC) (GLint location, GLsizei count, const GLuint64 *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64NVPROC) (GLuint program, GLint location, GLuint64 value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORMHANDLEUI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64 *values);
+typedef GLboolean (GL_APIENTRYP PFNGLISTEXTUREHANDLERESIDENTNVPROC) (GLuint64 handle);
+typedef GLboolean (GL_APIENTRYP PFNGLISIMAGEHANDLERESIDENTNVPROC) (GLuint64 handle);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL GLuint64 GL_APIENTRY glGetTextureHandleNV (GLuint texture);
+GL_APICALL GLuint64 GL_APIENTRY glGetTextureSamplerHandleNV (GLuint texture, GLuint sampler);
+GL_APICALL void GL_APIENTRY glMakeTextureHandleResidentNV (GLuint64 handle);
+GL_APICALL void GL_APIENTRY glMakeTextureHandleNonResidentNV (GLuint64 handle);
+GL_APICALL GLuint64 GL_APIENTRY glGetImageHandleNV (GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format);
+GL_APICALL void GL_APIENTRY glMakeImageHandleResidentNV (GLuint64 handle, GLenum access);
+GL_APICALL void GL_APIENTRY glMakeImageHandleNonResidentNV (GLuint64 handle);
+GL_APICALL void GL_APIENTRY glUniformHandleui64NV (GLint location, GLuint64 value);
+GL_APICALL void GL_APIENTRY glUniformHandleui64vNV (GLint location, GLsizei count, const GLuint64 *value);
+GL_APICALL void GL_APIENTRY glProgramUniformHandleui64NV (GLuint program, GLint location, GLuint64 value);
+GL_APICALL void GL_APIENTRY glProgramUniformHandleui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64 *values);
+GL_APICALL GLboolean GL_APIENTRY glIsTextureHandleResidentNV (GLuint64 handle);
+GL_APICALL GLboolean GL_APIENTRY glIsImageHandleResidentNV (GLuint64 handle);
+#endif
+#endif /* GL_NV_bindless_texture */
+
+#ifndef GL_NV_blend_equation_advanced
+#define GL_NV_blend_equation_advanced 1
+#define GL_BLEND_OVERLAP_NV 0x9281
+#define GL_BLEND_PREMULTIPLIED_SRC_NV 0x9280
+#define GL_BLUE_NV 0x1905
+#define GL_COLORBURN_NV 0x929A
+#define GL_COLORDODGE_NV 0x9299
+#define GL_CONJOINT_NV 0x9284
+#define GL_CONTRAST_NV 0x92A1
+#define GL_DARKEN_NV 0x9297
+#define GL_DIFFERENCE_NV 0x929E
+#define GL_DISJOINT_NV 0x9283
+#define GL_DST_ATOP_NV 0x928F
+#define GL_DST_IN_NV 0x928B
+#define GL_DST_NV 0x9287
+#define GL_DST_OUT_NV 0x928D
+#define GL_DST_OVER_NV 0x9289
+#define GL_EXCLUSION_NV 0x92A0
+#define GL_GREEN_NV 0x1904
+#define GL_HARDLIGHT_NV 0x929B
+#define GL_HARDMIX_NV 0x92A9
+#define GL_HSL_COLOR_NV 0x92AF
+#define GL_HSL_HUE_NV 0x92AD
+#define GL_HSL_LUMINOSITY_NV 0x92B0
+#define GL_HSL_SATURATION_NV 0x92AE
+#define GL_INVERT_OVG_NV 0x92B4
+#define GL_INVERT_RGB_NV 0x92A3
+#define GL_LIGHTEN_NV 0x9298
+#define GL_LINEARBURN_NV 0x92A5
+#define GL_LINEARDODGE_NV 0x92A4
+#define GL_LINEARLIGHT_NV 0x92A7
+#define GL_MINUS_CLAMPED_NV 0x92B3
+#define GL_MINUS_NV 0x929F
+#define GL_MULTIPLY_NV 0x9294
+#define GL_OVERLAY_NV 0x9296
+#define GL_PINLIGHT_NV 0x92A8
+#define GL_PLUS_CLAMPED_ALPHA_NV 0x92B2
+#define GL_PLUS_CLAMPED_NV 0x92B1
+#define GL_PLUS_DARKER_NV 0x9292
+#define GL_PLUS_NV 0x9291
+#define GL_RED_NV 0x1903
+#define GL_SCREEN_NV 0x9295
+#define GL_SOFTLIGHT_NV 0x929C
+#define GL_SRC_ATOP_NV 0x928E
+#define GL_SRC_IN_NV 0x928A
+#define GL_SRC_NV 0x9286
+#define GL_SRC_OUT_NV 0x928C
+#define GL_SRC_OVER_NV 0x9288
+#define GL_UNCORRELATED_NV 0x9282
+#define GL_VIVIDLIGHT_NV 0x92A6
+#define GL_XOR_NV 0x1506
+typedef void (GL_APIENTRYP PFNGLBLENDPARAMETERINVPROC) (GLenum pname, GLint value);
+typedef void (GL_APIENTRYP PFNGLBLENDBARRIERNVPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glBlendParameteriNV (GLenum pname, GLint value);
+GL_APICALL void GL_APIENTRY glBlendBarrierNV (void);
+#endif
+#endif /* GL_NV_blend_equation_advanced */
+
+#ifndef GL_NV_blend_equation_advanced_coherent
+#define GL_NV_blend_equation_advanced_coherent 1
+#define GL_BLEND_ADVANCED_COHERENT_NV 0x9285
+#endif /* GL_NV_blend_equation_advanced_coherent */
+
+#ifndef GL_NV_blend_minmax_factor
+#define GL_NV_blend_minmax_factor 1
+#define GL_FACTOR_MIN_AMD 0x901C
+#define GL_FACTOR_MAX_AMD 0x901D
+#endif /* GL_NV_blend_minmax_factor */
+
+#ifndef GL_NV_conditional_render
+#define GL_NV_conditional_render 1
+#define GL_QUERY_WAIT_NV 0x8E13
+#define GL_QUERY_NO_WAIT_NV 0x8E14
+#define GL_QUERY_BY_REGION_WAIT_NV 0x8E15
+#define GL_QUERY_BY_REGION_NO_WAIT_NV 0x8E16
+typedef void (GL_APIENTRYP PFNGLBEGINCONDITIONALRENDERNVPROC) (GLuint id, GLenum mode);
+typedef void (GL_APIENTRYP PFNGLENDCONDITIONALRENDERNVPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glBeginConditionalRenderNV (GLuint id, GLenum mode);
+GL_APICALL void GL_APIENTRY glEndConditionalRenderNV (void);
+#endif
+#endif /* GL_NV_conditional_render */
+
+#ifndef GL_NV_conservative_raster
+#define GL_NV_conservative_raster 1
+#define GL_CONSERVATIVE_RASTERIZATION_NV 0x9346
+#define GL_SUBPIXEL_PRECISION_BIAS_X_BITS_NV 0x9347
+#define GL_SUBPIXEL_PRECISION_BIAS_Y_BITS_NV 0x9348
+#define GL_MAX_SUBPIXEL_PRECISION_BIAS_BITS_NV 0x9349
+typedef void (GL_APIENTRYP PFNGLSUBPIXELPRECISIONBIASNVPROC) (GLuint xbits, GLuint ybits);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glSubpixelPrecisionBiasNV (GLuint xbits, GLuint ybits);
+#endif
+#endif /* GL_NV_conservative_raster */
+
+#ifndef GL_NV_conservative_raster_pre_snap_triangles
+#define GL_NV_conservative_raster_pre_snap_triangles 1
+#define GL_CONSERVATIVE_RASTER_MODE_NV 0x954D
+#define GL_CONSERVATIVE_RASTER_MODE_POST_SNAP_NV 0x954E
+#define GL_CONSERVATIVE_RASTER_MODE_PRE_SNAP_TRIANGLES_NV 0x954F
+typedef void (GL_APIENTRYP PFNGLCONSERVATIVERASTERPARAMETERINVPROC) (GLenum pname, GLint param);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glConservativeRasterParameteriNV (GLenum pname, GLint param);
+#endif
+#endif /* GL_NV_conservative_raster_pre_snap_triangles */
+
+#ifndef GL_NV_copy_buffer
+#define GL_NV_copy_buffer 1
+#define GL_COPY_READ_BUFFER_NV 0x8F36
+#define GL_COPY_WRITE_BUFFER_NV 0x8F37
+typedef void (GL_APIENTRYP PFNGLCOPYBUFFERSUBDATANVPROC) (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glCopyBufferSubDataNV (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
+#endif
+#endif /* GL_NV_copy_buffer */
+
+#ifndef GL_NV_coverage_sample
+#define GL_NV_coverage_sample 1
+#define GL_COVERAGE_COMPONENT_NV 0x8ED0
+#define GL_COVERAGE_COMPONENT4_NV 0x8ED1
+#define GL_COVERAGE_ATTACHMENT_NV 0x8ED2
+#define GL_COVERAGE_BUFFERS_NV 0x8ED3
+#define GL_COVERAGE_SAMPLES_NV 0x8ED4
+#define GL_COVERAGE_ALL_FRAGMENTS_NV 0x8ED5
+#define GL_COVERAGE_EDGE_FRAGMENTS_NV 0x8ED6
+#define GL_COVERAGE_AUTOMATIC_NV 0x8ED7
+#define GL_COVERAGE_BUFFER_BIT_NV 0x00008000
+typedef void (GL_APIENTRYP PFNGLCOVERAGEMASKNVPROC) (GLboolean mask);
+typedef void (GL_APIENTRYP PFNGLCOVERAGEOPERATIONNVPROC) (GLenum operation);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glCoverageMaskNV (GLboolean mask);
+GL_APICALL void GL_APIENTRY glCoverageOperationNV (GLenum operation);
+#endif
+#endif /* GL_NV_coverage_sample */
+
+#ifndef GL_NV_depth_nonlinear
+#define GL_NV_depth_nonlinear 1
+#define GL_DEPTH_COMPONENT16_NONLINEAR_NV 0x8E2C
+#endif /* GL_NV_depth_nonlinear */
+
+#ifndef GL_NV_draw_buffers
+#define GL_NV_draw_buffers 1
+#define GL_MAX_DRAW_BUFFERS_NV 0x8824
+#define GL_DRAW_BUFFER0_NV 0x8825
+#define GL_DRAW_BUFFER1_NV 0x8826
+#define GL_DRAW_BUFFER2_NV 0x8827
+#define GL_DRAW_BUFFER3_NV 0x8828
+#define GL_DRAW_BUFFER4_NV 0x8829
+#define GL_DRAW_BUFFER5_NV 0x882A
+#define GL_DRAW_BUFFER6_NV 0x882B
+#define GL_DRAW_BUFFER7_NV 0x882C
+#define GL_DRAW_BUFFER8_NV 0x882D
+#define GL_DRAW_BUFFER9_NV 0x882E
+#define GL_DRAW_BUFFER10_NV 0x882F
+#define GL_DRAW_BUFFER11_NV 0x8830
+#define GL_DRAW_BUFFER12_NV 0x8831
+#define GL_DRAW_BUFFER13_NV 0x8832
+#define GL_DRAW_BUFFER14_NV 0x8833
+#define GL_DRAW_BUFFER15_NV 0x8834
+#define GL_COLOR_ATTACHMENT0_NV 0x8CE0
+#define GL_COLOR_ATTACHMENT1_NV 0x8CE1
+#define GL_COLOR_ATTACHMENT2_NV 0x8CE2
+#define GL_COLOR_ATTACHMENT3_NV 0x8CE3
+#define GL_COLOR_ATTACHMENT4_NV 0x8CE4
+#define GL_COLOR_ATTACHMENT5_NV 0x8CE5
+#define GL_COLOR_ATTACHMENT6_NV 0x8CE6
+#define GL_COLOR_ATTACHMENT7_NV 0x8CE7
+#define GL_COLOR_ATTACHMENT8_NV 0x8CE8
+#define GL_COLOR_ATTACHMENT9_NV 0x8CE9
+#define GL_COLOR_ATTACHMENT10_NV 0x8CEA
+#define GL_COLOR_ATTACHMENT11_NV 0x8CEB
+#define GL_COLOR_ATTACHMENT12_NV 0x8CEC
+#define GL_COLOR_ATTACHMENT13_NV 0x8CED
+#define GL_COLOR_ATTACHMENT14_NV 0x8CEE
+#define GL_COLOR_ATTACHMENT15_NV 0x8CEF
+typedef void (GL_APIENTRYP PFNGLDRAWBUFFERSNVPROC) (GLsizei n, const GLenum *bufs);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDrawBuffersNV (GLsizei n, const GLenum *bufs);
+#endif
+#endif /* GL_NV_draw_buffers */
+
+#ifndef GL_NV_draw_instanced
+#define GL_NV_draw_instanced 1
+typedef void (GL_APIENTRYP PFNGLDRAWARRAYSINSTANCEDNVPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount);
+typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSINSTANCEDNVPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDrawArraysInstancedNV (GLenum mode, GLint first, GLsizei count, GLsizei primcount);
+GL_APICALL void GL_APIENTRY glDrawElementsInstancedNV (GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
+#endif
+#endif /* GL_NV_draw_instanced */
+
+#ifndef GL_NV_draw_vulkan_image
+#define GL_NV_draw_vulkan_image 1
+typedef void (GL_APIENTRY *GLVULKANPROCNV)(void);
+typedef void (GL_APIENTRYP PFNGLDRAWVKIMAGENVPROC) (GLuint64 vkImage, GLuint sampler, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1, GLfloat z, GLfloat s0, GLfloat t0, GLfloat s1, GLfloat t1);
+typedef GLVULKANPROCNV (GL_APIENTRYP PFNGLGETVKPROCADDRNVPROC) (const GLchar *name);
+typedef void (GL_APIENTRYP PFNGLWAITVKSEMAPHORENVPROC) (GLuint64 vkSemaphore);
+typedef void (GL_APIENTRYP PFNGLSIGNALVKSEMAPHORENVPROC) (GLuint64 vkSemaphore);
+typedef void (GL_APIENTRYP PFNGLSIGNALVKFENCENVPROC) (GLuint64 vkFence);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDrawVkImageNV (GLuint64 vkImage, GLuint sampler, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1, GLfloat z, GLfloat s0, GLfloat t0, GLfloat s1, GLfloat t1);
+GL_APICALL GLVULKANPROCNV GL_APIENTRY glGetVkProcAddrNV (const GLchar *name);
+GL_APICALL void GL_APIENTRY glWaitVkSemaphoreNV (GLuint64 vkSemaphore);
+GL_APICALL void GL_APIENTRY glSignalVkSemaphoreNV (GLuint64 vkSemaphore);
+GL_APICALL void GL_APIENTRY glSignalVkFenceNV (GLuint64 vkFence);
+#endif
+#endif /* GL_NV_draw_vulkan_image */
+
+#ifndef GL_NV_explicit_attrib_location
+#define GL_NV_explicit_attrib_location 1
+#endif /* GL_NV_explicit_attrib_location */
+
+#ifndef GL_NV_fbo_color_attachments
+#define GL_NV_fbo_color_attachments 1
+#define GL_MAX_COLOR_ATTACHMENTS_NV 0x8CDF
+#endif /* GL_NV_fbo_color_attachments */
+
+#ifndef GL_NV_fence
+#define GL_NV_fence 1
+#define GL_ALL_COMPLETED_NV 0x84F2
+#define GL_FENCE_STATUS_NV 0x84F3
+#define GL_FENCE_CONDITION_NV 0x84F4
+typedef void (GL_APIENTRYP PFNGLDELETEFENCESNVPROC) (GLsizei n, const GLuint *fences);
+typedef void (GL_APIENTRYP PFNGLGENFENCESNVPROC) (GLsizei n, GLuint *fences);
+typedef GLboolean (GL_APIENTRYP PFNGLISFENCENVPROC) (GLuint fence);
+typedef GLboolean (GL_APIENTRYP PFNGLTESTFENCENVPROC) (GLuint fence);
+typedef void (GL_APIENTRYP PFNGLGETFENCEIVNVPROC) (GLuint fence, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLFINISHFENCENVPROC) (GLuint fence);
+typedef void (GL_APIENTRYP PFNGLSETFENCENVPROC) (GLuint fence, GLenum condition);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glDeleteFencesNV (GLsizei n, const GLuint *fences);
+GL_APICALL void GL_APIENTRY glGenFencesNV (GLsizei n, GLuint *fences);
+GL_APICALL GLboolean GL_APIENTRY glIsFenceNV (GLuint fence);
+GL_APICALL GLboolean GL_APIENTRY glTestFenceNV (GLuint fence);
+GL_APICALL void GL_APIENTRY glGetFenceivNV (GLuint fence, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glFinishFenceNV (GLuint fence);
+GL_APICALL void GL_APIENTRY glSetFenceNV (GLuint fence, GLenum condition);
+#endif
+#endif /* GL_NV_fence */
+
+#ifndef GL_NV_fill_rectangle
+#define GL_NV_fill_rectangle 1
+#define GL_FILL_RECTANGLE_NV 0x933C
+#endif /* GL_NV_fill_rectangle */
+
+#ifndef GL_NV_fragment_coverage_to_color
+#define GL_NV_fragment_coverage_to_color 1
+#define GL_FRAGMENT_COVERAGE_TO_COLOR_NV 0x92DD
+#define GL_FRAGMENT_COVERAGE_COLOR_NV 0x92DE
+typedef void (GL_APIENTRYP PFNGLFRAGMENTCOVERAGECOLORNVPROC) (GLuint color);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glFragmentCoverageColorNV (GLuint color);
+#endif
+#endif /* GL_NV_fragment_coverage_to_color */
+
+#ifndef GL_NV_fragment_shader_interlock
+#define GL_NV_fragment_shader_interlock 1
+#endif /* GL_NV_fragment_shader_interlock */
+
+#ifndef GL_NV_framebuffer_blit
+#define GL_NV_framebuffer_blit 1
+#define GL_READ_FRAMEBUFFER_NV 0x8CA8
+#define GL_DRAW_FRAMEBUFFER_NV 0x8CA9
+#define GL_DRAW_FRAMEBUFFER_BINDING_NV 0x8CA6
+#define GL_READ_FRAMEBUFFER_BINDING_NV 0x8CAA
+typedef void (GL_APIENTRYP PFNGLBLITFRAMEBUFFERNVPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glBlitFramebufferNV (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+#endif
+#endif /* GL_NV_framebuffer_blit */
+
+#ifndef GL_NV_framebuffer_mixed_samples
+#define GL_NV_framebuffer_mixed_samples 1
+#define GL_COVERAGE_MODULATION_TABLE_NV 0x9331
+#define GL_COLOR_SAMPLES_NV 0x8E20
+#define GL_DEPTH_SAMPLES_NV 0x932D
+#define GL_STENCIL_SAMPLES_NV 0x932E
+#define GL_MIXED_DEPTH_SAMPLES_SUPPORTED_NV 0x932F
+#define GL_MIXED_STENCIL_SAMPLES_SUPPORTED_NV 0x9330
+#define GL_COVERAGE_MODULATION_NV 0x9332
+#define GL_COVERAGE_MODULATION_TABLE_SIZE_NV 0x9333
+typedef void (GL_APIENTRYP PFNGLCOVERAGEMODULATIONTABLENVPROC) (GLsizei n, const GLfloat *v);
+typedef void (GL_APIENTRYP PFNGLGETCOVERAGEMODULATIONTABLENVPROC) (GLsizei bufsize, GLfloat *v);
+typedef void (GL_APIENTRYP PFNGLCOVERAGEMODULATIONNVPROC) (GLenum components);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glCoverageModulationTableNV (GLsizei n, const GLfloat *v);
+GL_APICALL void GL_APIENTRY glGetCoverageModulationTableNV (GLsizei bufsize, GLfloat *v);
+GL_APICALL void GL_APIENTRY glCoverageModulationNV (GLenum components);
+#endif
+#endif /* GL_NV_framebuffer_mixed_samples */
+
+#ifndef GL_NV_framebuffer_multisample
+#define GL_NV_framebuffer_multisample 1
+#define GL_RENDERBUFFER_SAMPLES_NV 0x8CAB
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_NV 0x8D56
+#define GL_MAX_SAMPLES_NV 0x8D57
+typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLENVPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleNV (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+#endif
+#endif /* GL_NV_framebuffer_multisample */
+
+#ifndef GL_NV_generate_mipmap_sRGB
+#define GL_NV_generate_mipmap_sRGB 1
+#endif /* GL_NV_generate_mipmap_sRGB */
+
+#ifndef GL_NV_geometry_shader_passthrough
+#define GL_NV_geometry_shader_passthrough 1
+#endif /* GL_NV_geometry_shader_passthrough */
+
+#ifndef GL_NV_gpu_shader5
+#define GL_NV_gpu_shader5 1
+typedef khronos_int64_t GLint64EXT;
+typedef khronos_uint64_t GLuint64EXT;
+#define GL_INT64_NV 0x140E
+#define GL_UNSIGNED_INT64_NV 0x140F
+#define GL_INT8_NV 0x8FE0
+#define GL_INT8_VEC2_NV 0x8FE1
+#define GL_INT8_VEC3_NV 0x8FE2
+#define GL_INT8_VEC4_NV 0x8FE3
+#define GL_INT16_NV 0x8FE4
+#define GL_INT16_VEC2_NV 0x8FE5
+#define GL_INT16_VEC3_NV 0x8FE6
+#define GL_INT16_VEC4_NV 0x8FE7
+#define GL_INT64_VEC2_NV 0x8FE9
+#define GL_INT64_VEC3_NV 0x8FEA
+#define GL_INT64_VEC4_NV 0x8FEB
+#define GL_UNSIGNED_INT8_NV 0x8FEC
+#define GL_UNSIGNED_INT8_VEC2_NV 0x8FED
+#define GL_UNSIGNED_INT8_VEC3_NV 0x8FEE
+#define GL_UNSIGNED_INT8_VEC4_NV 0x8FEF
+#define GL_UNSIGNED_INT16_NV 0x8FF0
+#define GL_UNSIGNED_INT16_VEC2_NV 0x8FF1
+#define GL_UNSIGNED_INT16_VEC3_NV 0x8FF2
+#define GL_UNSIGNED_INT16_VEC4_NV 0x8FF3
+#define GL_UNSIGNED_INT64_VEC2_NV 0x8FF5
+#define GL_UNSIGNED_INT64_VEC3_NV 0x8FF6
+#define GL_UNSIGNED_INT64_VEC4_NV 0x8FF7
+#define GL_FLOAT16_NV 0x8FF8
+#define GL_FLOAT16_VEC2_NV 0x8FF9
+#define GL_FLOAT16_VEC3_NV 0x8FFA
+#define GL_FLOAT16_VEC4_NV 0x8FFB
+#define GL_PATCHES 0x000E
+typedef void (GL_APIENTRYP PFNGLUNIFORM1I64NVPROC) (GLint location, GLint64EXT x);
+typedef void (GL_APIENTRYP PFNGLUNIFORM2I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y);
+typedef void (GL_APIENTRYP PFNGLUNIFORM3I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z);
+typedef void (GL_APIENTRYP PFNGLUNIFORM4I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
+typedef void (GL_APIENTRYP PFNGLUNIFORM1I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORM2I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORM3I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORM4I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORM1UI64NVPROC) (GLint location, GLuint64EXT x);
+typedef void (GL_APIENTRYP PFNGLUNIFORM2UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y);
+typedef void (GL_APIENTRYP PFNGLUNIFORM3UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
+typedef void (GL_APIENTRYP PFNGLUNIFORM4UI64NVPROC) (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
+typedef void (GL_APIENTRYP PFNGLUNIFORM1UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORM2UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORM3UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORM4UI64VNVPROC) (GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (GL_APIENTRYP PFNGLGETUNIFORMI64VNVPROC) (GLuint program, GLint location, GLint64EXT *params);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1I64NVPROC) (GLuint program, GLint location, GLint64EXT x);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4I64NVPROC) (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4I64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4UI64NVPROC) (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM1UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM2UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM3UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+typedef void (GL_APIENTRYP PFNGLPROGRAMUNIFORM4UI64VNVPROC) (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glUniform1i64NV (GLint location, GLint64EXT x);
+GL_APICALL void GL_APIENTRY glUniform2i64NV (GLint location, GLint64EXT x, GLint64EXT y);
+GL_APICALL void GL_APIENTRY glUniform3i64NV (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z);
+GL_APICALL void GL_APIENTRY glUniform4i64NV (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
+GL_APICALL void GL_APIENTRY glUniform1i64vNV (GLint location, GLsizei count, const GLint64EXT *value);
+GL_APICALL void GL_APIENTRY glUniform2i64vNV (GLint location, GLsizei count, const GLint64EXT *value);
+GL_APICALL void GL_APIENTRY glUniform3i64vNV (GLint location, GLsizei count, const GLint64EXT *value);
+GL_APICALL void GL_APIENTRY glUniform4i64vNV (GLint location, GLsizei count, const GLint64EXT *value);
+GL_APICALL void GL_APIENTRY glUniform1ui64NV (GLint location, GLuint64EXT x);
+GL_APICALL void GL_APIENTRY glUniform2ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y);
+GL_APICALL void GL_APIENTRY glUniform3ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
+GL_APICALL void GL_APIENTRY glUniform4ui64NV (GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
+GL_APICALL void GL_APIENTRY glUniform1ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value);
+GL_APICALL void GL_APIENTRY glUniform2ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value);
+GL_APICALL void GL_APIENTRY glUniform3ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value);
+GL_APICALL void GL_APIENTRY glUniform4ui64vNV (GLint location, GLsizei count, const GLuint64EXT *value);
+GL_APICALL void GL_APIENTRY glGetUniformi64vNV (GLuint program, GLint location, GLint64EXT *params);
+GL_APICALL void GL_APIENTRY glProgramUniform1i64NV (GLuint program, GLint location, GLint64EXT x);
+GL_APICALL void GL_APIENTRY glProgramUniform2i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y);
+GL_APICALL void GL_APIENTRY glProgramUniform3i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z);
+GL_APICALL void GL_APIENTRY glProgramUniform4i64NV (GLuint program, GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
+GL_APICALL void GL_APIENTRY glProgramUniform1i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+GL_APICALL void GL_APIENTRY glProgramUniform2i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+GL_APICALL void GL_APIENTRY glProgramUniform3i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+GL_APICALL void GL_APIENTRY glProgramUniform4i64vNV (GLuint program, GLint location, GLsizei count, const GLint64EXT *value);
+GL_APICALL void GL_APIENTRY glProgramUniform1ui64NV (GLuint program, GLint location, GLuint64EXT x);
+GL_APICALL void GL_APIENTRY glProgramUniform2ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y);
+GL_APICALL void GL_APIENTRY glProgramUniform3ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z);
+GL_APICALL void GL_APIENTRY glProgramUniform4ui64NV (GLuint program, GLint location, GLuint64EXT x, GLuint64EXT y, GLuint64EXT z, GLuint64EXT w);
+GL_APICALL void GL_APIENTRY glProgramUniform1ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+GL_APICALL void GL_APIENTRY glProgramUniform2ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+GL_APICALL void GL_APIENTRY glProgramUniform3ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+GL_APICALL void GL_APIENTRY glProgramUniform4ui64vNV (GLuint program, GLint location, GLsizei count, const GLuint64EXT *value);
+#endif
+#endif /* GL_NV_gpu_shader5 */
+
+#ifndef GL_NV_image_formats
+#define GL_NV_image_formats 1
+#endif /* GL_NV_image_formats */
+
+#ifndef GL_NV_instanced_arrays
+#define GL_NV_instanced_arrays 1
+#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_NV 0x88FE
+typedef void (GL_APIENTRYP PFNGLVERTEXATTRIBDIVISORNVPROC) (GLuint index, GLuint divisor);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glVertexAttribDivisorNV (GLuint index, GLuint divisor);
+#endif
+#endif /* GL_NV_instanced_arrays */
+
+#ifndef GL_NV_internalformat_sample_query
+#define GL_NV_internalformat_sample_query 1
+#define GL_TEXTURE_2D_MULTISAMPLE 0x9100
+#define GL_TEXTURE_2D_MULTISAMPLE_ARRAY 0x9102
+#define GL_MULTISAMPLES_NV 0x9371
+#define GL_SUPERSAMPLE_SCALE_X_NV 0x9372
+#define GL_SUPERSAMPLE_SCALE_Y_NV 0x9373
+#define GL_CONFORMANT_NV 0x9374
+typedef void (GL_APIENTRYP PFNGLGETINTERNALFORMATSAMPLEIVNVPROC) (GLenum target, GLenum internalformat, GLsizei samples, GLenum pname, GLsizei bufSize, GLint *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glGetInternalformatSampleivNV (GLenum target, GLenum internalformat, GLsizei samples, GLenum pname, GLsizei bufSize, GLint *params);
+#endif
+#endif /* GL_NV_internalformat_sample_query */
+
+#ifndef GL_NV_non_square_matrices
+#define GL_NV_non_square_matrices 1
+#define GL_FLOAT_MAT2x3_NV 0x8B65
+#define GL_FLOAT_MAT2x4_NV 0x8B66
+#define GL_FLOAT_MAT3x2_NV 0x8B67
+#define GL_FLOAT_MAT3x4_NV 0x8B68
+#define GL_FLOAT_MAT4x2_NV 0x8B69
+#define GL_FLOAT_MAT4x3_NV 0x8B6A
+typedef void (GL_APIENTRYP PFNGLUNIFORMMATRIX2X3FVNVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORMMATRIX3X2FVNVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORMMATRIX2X4FVNVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORMMATRIX4X2FVNVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORMMATRIX3X4FVNVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLUNIFORMMATRIX4X3FVNVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glUniformMatrix2x3fvNV (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glUniformMatrix3x2fvNV (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glUniformMatrix2x4fvNV (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glUniformMatrix4x2fvNV (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glUniformMatrix3x4fvNV (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glUniformMatrix4x3fvNV (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
+#endif
+#endif /* GL_NV_non_square_matrices */
+
+#ifndef GL_NV_path_rendering
+#define GL_NV_path_rendering 1
+#define GL_PATH_FORMAT_SVG_NV 0x9070
+#define GL_PATH_FORMAT_PS_NV 0x9071
+#define GL_STANDARD_FONT_NAME_NV 0x9072
+#define GL_SYSTEM_FONT_NAME_NV 0x9073
+#define GL_FILE_NAME_NV 0x9074
+#define GL_PATH_STROKE_WIDTH_NV 0x9075
+#define GL_PATH_END_CAPS_NV 0x9076
+#define GL_PATH_INITIAL_END_CAP_NV 0x9077
+#define GL_PATH_TERMINAL_END_CAP_NV 0x9078
+#define GL_PATH_JOIN_STYLE_NV 0x9079
+#define GL_PATH_MITER_LIMIT_NV 0x907A
+#define GL_PATH_DASH_CAPS_NV 0x907B
+#define GL_PATH_INITIAL_DASH_CAP_NV 0x907C
+#define GL_PATH_TERMINAL_DASH_CAP_NV 0x907D
+#define GL_PATH_DASH_OFFSET_NV 0x907E
+#define GL_PATH_CLIENT_LENGTH_NV 0x907F
+#define GL_PATH_FILL_MODE_NV 0x9080
+#define GL_PATH_FILL_MASK_NV 0x9081
+#define GL_PATH_FILL_COVER_MODE_NV 0x9082
+#define GL_PATH_STROKE_COVER_MODE_NV 0x9083
+#define GL_PATH_STROKE_MASK_NV 0x9084
+#define GL_COUNT_UP_NV 0x9088
+#define GL_COUNT_DOWN_NV 0x9089
+#define GL_PATH_OBJECT_BOUNDING_BOX_NV 0x908A
+#define GL_CONVEX_HULL_NV 0x908B
+#define GL_BOUNDING_BOX_NV 0x908D
+#define GL_TRANSLATE_X_NV 0x908E
+#define GL_TRANSLATE_Y_NV 0x908F
+#define GL_TRANSLATE_2D_NV 0x9090
+#define GL_TRANSLATE_3D_NV 0x9091
+#define GL_AFFINE_2D_NV 0x9092
+#define GL_AFFINE_3D_NV 0x9094
+#define GL_TRANSPOSE_AFFINE_2D_NV 0x9096
+#define GL_TRANSPOSE_AFFINE_3D_NV 0x9098
+#define GL_UTF8_NV 0x909A
+#define GL_UTF16_NV 0x909B
+#define GL_BOUNDING_BOX_OF_BOUNDING_BOXES_NV 0x909C
+#define GL_PATH_COMMAND_COUNT_NV 0x909D
+#define GL_PATH_COORD_COUNT_NV 0x909E
+#define GL_PATH_DASH_ARRAY_COUNT_NV 0x909F
+#define GL_PATH_COMPUTED_LENGTH_NV 0x90A0
+#define GL_PATH_FILL_BOUNDING_BOX_NV 0x90A1
+#define GL_PATH_STROKE_BOUNDING_BOX_NV 0x90A2
+#define GL_SQUARE_NV 0x90A3
+#define GL_ROUND_NV 0x90A4
+#define GL_TRIANGULAR_NV 0x90A5
+#define GL_BEVEL_NV 0x90A6
+#define GL_MITER_REVERT_NV 0x90A7
+#define GL_MITER_TRUNCATE_NV 0x90A8
+#define GL_SKIP_MISSING_GLYPH_NV 0x90A9
+#define GL_USE_MISSING_GLYPH_NV 0x90AA
+#define GL_PATH_ERROR_POSITION_NV 0x90AB
+#define GL_ACCUM_ADJACENT_PAIRS_NV 0x90AD
+#define GL_ADJACENT_PAIRS_NV 0x90AE
+#define GL_FIRST_TO_REST_NV 0x90AF
+#define GL_PATH_GEN_MODE_NV 0x90B0
+#define GL_PATH_GEN_COEFF_NV 0x90B1
+#define GL_PATH_GEN_COMPONENTS_NV 0x90B3
+#define GL_PATH_STENCIL_FUNC_NV 0x90B7
+#define GL_PATH_STENCIL_REF_NV 0x90B8
+#define GL_PATH_STENCIL_VALUE_MASK_NV 0x90B9
+#define GL_PATH_STENCIL_DEPTH_OFFSET_FACTOR_NV 0x90BD
+#define GL_PATH_STENCIL_DEPTH_OFFSET_UNITS_NV 0x90BE
+#define GL_PATH_COVER_DEPTH_FUNC_NV 0x90BF
+#define GL_PATH_DASH_OFFSET_RESET_NV 0x90B4
+#define GL_MOVE_TO_RESETS_NV 0x90B5
+#define GL_MOVE_TO_CONTINUES_NV 0x90B6
+#define GL_CLOSE_PATH_NV 0x00
+#define GL_MOVE_TO_NV 0x02
+#define GL_RELATIVE_MOVE_TO_NV 0x03
+#define GL_LINE_TO_NV 0x04
+#define GL_RELATIVE_LINE_TO_NV 0x05
+#define GL_HORIZONTAL_LINE_TO_NV 0x06
+#define GL_RELATIVE_HORIZONTAL_LINE_TO_NV 0x07
+#define GL_VERTICAL_LINE_TO_NV 0x08
+#define GL_RELATIVE_VERTICAL_LINE_TO_NV 0x09
+#define GL_QUADRATIC_CURVE_TO_NV 0x0A
+#define GL_RELATIVE_QUADRATIC_CURVE_TO_NV 0x0B
+#define GL_CUBIC_CURVE_TO_NV 0x0C
+#define GL_RELATIVE_CUBIC_CURVE_TO_NV 0x0D
+#define GL_SMOOTH_QUADRATIC_CURVE_TO_NV 0x0E
+#define GL_RELATIVE_SMOOTH_QUADRATIC_CURVE_TO_NV 0x0F
+#define GL_SMOOTH_CUBIC_CURVE_TO_NV 0x10
+#define GL_RELATIVE_SMOOTH_CUBIC_CURVE_TO_NV 0x11
+#define GL_SMALL_CCW_ARC_TO_NV 0x12
+#define GL_RELATIVE_SMALL_CCW_ARC_TO_NV 0x13
+#define GL_SMALL_CW_ARC_TO_NV 0x14
+#define GL_RELATIVE_SMALL_CW_ARC_TO_NV 0x15
+#define GL_LARGE_CCW_ARC_TO_NV 0x16
+#define GL_RELATIVE_LARGE_CCW_ARC_TO_NV 0x17
+#define GL_LARGE_CW_ARC_TO_NV 0x18
+#define GL_RELATIVE_LARGE_CW_ARC_TO_NV 0x19
+#define GL_RESTART_PATH_NV 0xF0
+#define GL_DUP_FIRST_CUBIC_CURVE_TO_NV 0xF2
+#define GL_DUP_LAST_CUBIC_CURVE_TO_NV 0xF4
+#define GL_RECT_NV 0xF6
+#define GL_CIRCULAR_CCW_ARC_TO_NV 0xF8
+#define GL_CIRCULAR_CW_ARC_TO_NV 0xFA
+#define GL_CIRCULAR_TANGENT_ARC_TO_NV 0xFC
+#define GL_ARC_TO_NV 0xFE
+#define GL_RELATIVE_ARC_TO_NV 0xFF
+#define GL_BOLD_BIT_NV 0x01
+#define GL_ITALIC_BIT_NV 0x02
+#define GL_GLYPH_WIDTH_BIT_NV 0x01
+#define GL_GLYPH_HEIGHT_BIT_NV 0x02
+#define GL_GLYPH_HORIZONTAL_BEARING_X_BIT_NV 0x04
+#define GL_GLYPH_HORIZONTAL_BEARING_Y_BIT_NV 0x08
+#define GL_GLYPH_HORIZONTAL_BEARING_ADVANCE_BIT_NV 0x10
+#define GL_GLYPH_VERTICAL_BEARING_X_BIT_NV 0x20
+#define GL_GLYPH_VERTICAL_BEARING_Y_BIT_NV 0x40
+#define GL_GLYPH_VERTICAL_BEARING_ADVANCE_BIT_NV 0x80
+#define GL_GLYPH_HAS_KERNING_BIT_NV 0x100
+#define GL_FONT_X_MIN_BOUNDS_BIT_NV 0x00010000
+#define GL_FONT_Y_MIN_BOUNDS_BIT_NV 0x00020000
+#define GL_FONT_X_MAX_BOUNDS_BIT_NV 0x00040000
+#define GL_FONT_Y_MAX_BOUNDS_BIT_NV 0x00080000
+#define GL_FONT_UNITS_PER_EM_BIT_NV 0x00100000
+#define GL_FONT_ASCENDER_BIT_NV 0x00200000
+#define GL_FONT_DESCENDER_BIT_NV 0x00400000
+#define GL_FONT_HEIGHT_BIT_NV 0x00800000
+#define GL_FONT_MAX_ADVANCE_WIDTH_BIT_NV 0x01000000
+#define GL_FONT_MAX_ADVANCE_HEIGHT_BIT_NV 0x02000000
+#define GL_FONT_UNDERLINE_POSITION_BIT_NV 0x04000000
+#define GL_FONT_UNDERLINE_THICKNESS_BIT_NV 0x08000000
+#define GL_FONT_HAS_KERNING_BIT_NV 0x10000000
+#define GL_ROUNDED_RECT_NV 0xE8
+#define GL_RELATIVE_ROUNDED_RECT_NV 0xE9
+#define GL_ROUNDED_RECT2_NV 0xEA
+#define GL_RELATIVE_ROUNDED_RECT2_NV 0xEB
+#define GL_ROUNDED_RECT4_NV 0xEC
+#define GL_RELATIVE_ROUNDED_RECT4_NV 0xED
+#define GL_ROUNDED_RECT8_NV 0xEE
+#define GL_RELATIVE_ROUNDED_RECT8_NV 0xEF
+#define GL_RELATIVE_RECT_NV 0xF7
+#define GL_FONT_GLYPHS_AVAILABLE_NV 0x9368
+#define GL_FONT_TARGET_UNAVAILABLE_NV 0x9369
+#define GL_FONT_UNAVAILABLE_NV 0x936A
+#define GL_FONT_UNINTELLIGIBLE_NV 0x936B
+#define GL_CONIC_CURVE_TO_NV 0x1A
+#define GL_RELATIVE_CONIC_CURVE_TO_NV 0x1B
+#define GL_FONT_NUM_GLYPH_INDICES_BIT_NV 0x20000000
+#define GL_STANDARD_FONT_FORMAT_NV 0x936C
+#define GL_PATH_PROJECTION_NV 0x1701
+#define GL_PATH_MODELVIEW_NV 0x1700
+#define GL_PATH_MODELVIEW_STACK_DEPTH_NV 0x0BA3
+#define GL_PATH_MODELVIEW_MATRIX_NV 0x0BA6
+#define GL_PATH_MAX_MODELVIEW_STACK_DEPTH_NV 0x0D36
+#define GL_PATH_TRANSPOSE_MODELVIEW_MATRIX_NV 0x84E3
+#define GL_PATH_PROJECTION_STACK_DEPTH_NV 0x0BA4
+#define GL_PATH_PROJECTION_MATRIX_NV 0x0BA7
+#define GL_PATH_MAX_PROJECTION_STACK_DEPTH_NV 0x0D38
+#define GL_PATH_TRANSPOSE_PROJECTION_MATRIX_NV 0x84E4
+#define GL_FRAGMENT_INPUT_NV 0x936D
+typedef GLuint (GL_APIENTRYP PFNGLGENPATHSNVPROC) (GLsizei range);
+typedef void (GL_APIENTRYP PFNGLDELETEPATHSNVPROC) (GLuint path, GLsizei range);
+typedef GLboolean (GL_APIENTRYP PFNGLISPATHNVPROC) (GLuint path);
+typedef void (GL_APIENTRYP PFNGLPATHCOMMANDSNVPROC) (GLuint path, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const void *coords);
+typedef void (GL_APIENTRYP PFNGLPATHCOORDSNVPROC) (GLuint path, GLsizei numCoords, GLenum coordType, const void *coords);
+typedef void (GL_APIENTRYP PFNGLPATHSUBCOMMANDSNVPROC) (GLuint path, GLsizei commandStart, GLsizei commandsToDelete, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const void *coords);
+typedef void (GL_APIENTRYP PFNGLPATHSUBCOORDSNVPROC) (GLuint path, GLsizei coordStart, GLsizei numCoords, GLenum coordType, const void *coords);
+typedef void (GL_APIENTRYP PFNGLPATHSTRINGNVPROC) (GLuint path, GLenum format, GLsizei length, const void *pathString);
+typedef void (GL_APIENTRYP PFNGLPATHGLYPHSNVPROC) (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLsizei numGlyphs, GLenum type, const void *charcodes, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale);
+typedef void (GL_APIENTRYP PFNGLPATHGLYPHRANGENVPROC) (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLuint firstGlyph, GLsizei numGlyphs, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale);
+typedef void (GL_APIENTRYP PFNGLWEIGHTPATHSNVPROC) (GLuint resultPath, GLsizei numPaths, const GLuint *paths, const GLfloat *weights);
+typedef void (GL_APIENTRYP PFNGLCOPYPATHNVPROC) (GLuint resultPath, GLuint srcPath);
+typedef void (GL_APIENTRYP PFNGLINTERPOLATEPATHSNVPROC) (GLuint resultPath, GLuint pathA, GLuint pathB, GLfloat weight);
+typedef void (GL_APIENTRYP PFNGLTRANSFORMPATHNVPROC) (GLuint resultPath, GLuint srcPath, GLenum transformType, const GLfloat *transformValues);
+typedef void (GL_APIENTRYP PFNGLPATHPARAMETERIVNVPROC) (GLuint path, GLenum pname, const GLint *value);
+typedef void (GL_APIENTRYP PFNGLPATHPARAMETERINVPROC) (GLuint path, GLenum pname, GLint value);
+typedef void (GL_APIENTRYP PFNGLPATHPARAMETERFVNVPROC) (GLuint path, GLenum pname, const GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLPATHPARAMETERFNVPROC) (GLuint path, GLenum pname, GLfloat value);
+typedef void (GL_APIENTRYP PFNGLPATHDASHARRAYNVPROC) (GLuint path, GLsizei dashCount, const GLfloat *dashArray);
+typedef void (GL_APIENTRYP PFNGLPATHSTENCILFUNCNVPROC) (GLenum func, GLint ref, GLuint mask);
+typedef void (GL_APIENTRYP PFNGLPATHSTENCILDEPTHOFFSETNVPROC) (GLfloat factor, GLfloat units);
+typedef void (GL_APIENTRYP PFNGLSTENCILFILLPATHNVPROC) (GLuint path, GLenum fillMode, GLuint mask);
+typedef void (GL_APIENTRYP PFNGLSTENCILSTROKEPATHNVPROC) (GLuint path, GLint reference, GLuint mask);
+typedef void (GL_APIENTRYP PFNGLSTENCILFILLPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum fillMode, GLuint mask, GLenum transformType, const GLfloat *transformValues);
+typedef void (GL_APIENTRYP PFNGLSTENCILSTROKEPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLint reference, GLuint mask, GLenum transformType, const GLfloat *transformValues);
+typedef void (GL_APIENTRYP PFNGLPATHCOVERDEPTHFUNCNVPROC) (GLenum func);
+typedef void (GL_APIENTRYP PFNGLCOVERFILLPATHNVPROC) (GLuint path, GLenum coverMode);
+typedef void (GL_APIENTRYP PFNGLCOVERSTROKEPATHNVPROC) (GLuint path, GLenum coverMode);
+typedef void (GL_APIENTRYP PFNGLCOVERFILLPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues);
+typedef void (GL_APIENTRYP PFNGLCOVERSTROKEPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues);
+typedef void (GL_APIENTRYP PFNGLGETPATHPARAMETERIVNVPROC) (GLuint path, GLenum pname, GLint *value);
+typedef void (GL_APIENTRYP PFNGLGETPATHPARAMETERFVNVPROC) (GLuint path, GLenum pname, GLfloat *value);
+typedef void (GL_APIENTRYP PFNGLGETPATHCOMMANDSNVPROC) (GLuint path, GLubyte *commands);
+typedef void (GL_APIENTRYP PFNGLGETPATHCOORDSNVPROC) (GLuint path, GLfloat *coords);
+typedef void (GL_APIENTRYP PFNGLGETPATHDASHARRAYNVPROC) (GLuint path, GLfloat *dashArray);
+typedef void (GL_APIENTRYP PFNGLGETPATHMETRICSNVPROC) (GLbitfield metricQueryMask, GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLsizei stride, GLfloat *metrics);
+typedef void (GL_APIENTRYP PFNGLGETPATHMETRICRANGENVPROC) (GLbitfield metricQueryMask, GLuint firstPathName, GLsizei numPaths, GLsizei stride, GLfloat *metrics);
+typedef void (GL_APIENTRYP PFNGLGETPATHSPACINGNVPROC) (GLenum pathListMode, GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLfloat advanceScale, GLfloat kerningScale, GLenum transformType, GLfloat *returnedSpacing);
+typedef GLboolean (GL_APIENTRYP PFNGLISPOINTINFILLPATHNVPROC) (GLuint path, GLuint mask, GLfloat x, GLfloat y);
+typedef GLboolean (GL_APIENTRYP PFNGLISPOINTINSTROKEPATHNVPROC) (GLuint path, GLfloat x, GLfloat y);
+typedef GLfloat (GL_APIENTRYP PFNGLGETPATHLENGTHNVPROC) (GLuint path, GLsizei startSegment, GLsizei numSegments);
+typedef GLboolean (GL_APIENTRYP PFNGLPOINTALONGPATHNVPROC) (GLuint path, GLsizei startSegment, GLsizei numSegments, GLfloat distance, GLfloat *x, GLfloat *y, GLfloat *tangentX, GLfloat *tangentY);
+typedef void (GL_APIENTRYP PFNGLMATRIXLOAD3X2FNVPROC) (GLenum matrixMode, const GLfloat *m);
+typedef void (GL_APIENTRYP PFNGLMATRIXLOAD3X3FNVPROC) (GLenum matrixMode, const GLfloat *m);
+typedef void (GL_APIENTRYP PFNGLMATRIXLOADTRANSPOSE3X3FNVPROC) (GLenum matrixMode, const GLfloat *m);
+typedef void (GL_APIENTRYP PFNGLMATRIXMULT3X2FNVPROC) (GLenum matrixMode, const GLfloat *m);
+typedef void (GL_APIENTRYP PFNGLMATRIXMULT3X3FNVPROC) (GLenum matrixMode, const GLfloat *m);
+typedef void (GL_APIENTRYP PFNGLMATRIXMULTTRANSPOSE3X3FNVPROC) (GLenum matrixMode, const GLfloat *m);
+typedef void (GL_APIENTRYP PFNGLSTENCILTHENCOVERFILLPATHNVPROC) (GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode);
+typedef void (GL_APIENTRYP PFNGLSTENCILTHENCOVERSTROKEPATHNVPROC) (GLuint path, GLint reference, GLuint mask, GLenum coverMode);
+typedef void (GL_APIENTRYP PFNGLSTENCILTHENCOVERFILLPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum fillMode, GLuint mask, GLenum coverMode, GLenum transformType, const GLfloat *transformValues);
+typedef void (GL_APIENTRYP PFNGLSTENCILTHENCOVERSTROKEPATHINSTANCEDNVPROC) (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLint reference, GLuint mask, GLenum coverMode, GLenum transformType, const GLfloat *transformValues);
+typedef GLenum (GL_APIENTRYP PFNGLPATHGLYPHINDEXRANGENVPROC) (GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLuint pathParameterTemplate, GLfloat emScale, GLuint baseAndCount[2]);
+typedef GLenum (GL_APIENTRYP PFNGLPATHGLYPHINDEXARRAYNVPROC) (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLuint firstGlyphIndex, GLsizei numGlyphs, GLuint pathParameterTemplate, GLfloat emScale);
+typedef GLenum (GL_APIENTRYP PFNGLPATHMEMORYGLYPHINDEXARRAYNVPROC) (GLuint firstPathName, GLenum fontTarget, GLsizeiptr fontSize, const void *fontData, GLsizei faceIndex, GLuint firstGlyphIndex, GLsizei numGlyphs, GLuint pathParameterTemplate, GLfloat emScale);
+typedef void (GL_APIENTRYP PFNGLPROGRAMPATHFRAGMENTINPUTGENNVPROC) (GLuint program, GLint location, GLenum genMode, GLint components, const GLfloat *coeffs);
+typedef void (GL_APIENTRYP PFNGLGETPROGRAMRESOURCEFVNVPROC) (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLfloat *params);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL GLuint GL_APIENTRY glGenPathsNV (GLsizei range);
+GL_APICALL void GL_APIENTRY glDeletePathsNV (GLuint path, GLsizei range);
+GL_APICALL GLboolean GL_APIENTRY glIsPathNV (GLuint path);
+GL_APICALL void GL_APIENTRY glPathCommandsNV (GLuint path, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const void *coords);
+GL_APICALL void GL_APIENTRY glPathCoordsNV (GLuint path, GLsizei numCoords, GLenum coordType, const void *coords);
+GL_APICALL void GL_APIENTRY glPathSubCommandsNV (GLuint path, GLsizei commandStart, GLsizei commandsToDelete, GLsizei numCommands, const GLubyte *commands, GLsizei numCoords, GLenum coordType, const void *coords);
+GL_APICALL void GL_APIENTRY glPathSubCoordsNV (GLuint path, GLsizei coordStart, GLsizei numCoords, GLenum coordType, const void *coords);
+GL_APICALL void GL_APIENTRY glPathStringNV (GLuint path, GLenum format, GLsizei length, const void *pathString);
+GL_APICALL void GL_APIENTRY glPathGlyphsNV (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLsizei numGlyphs, GLenum type, const void *charcodes, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale);
+GL_APICALL void GL_APIENTRY glPathGlyphRangeNV (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLuint firstGlyph, GLsizei numGlyphs, GLenum handleMissingGlyphs, GLuint pathParameterTemplate, GLfloat emScale);
+GL_APICALL void GL_APIENTRY glWeightPathsNV (GLuint resultPath, GLsizei numPaths, const GLuint *paths, const GLfloat *weights);
+GL_APICALL void GL_APIENTRY glCopyPathNV (GLuint resultPath, GLuint srcPath);
+GL_APICALL void GL_APIENTRY glInterpolatePathsNV (GLuint resultPath, GLuint pathA, GLuint pathB, GLfloat weight);
+GL_APICALL void GL_APIENTRY glTransformPathNV (GLuint resultPath, GLuint srcPath, GLenum transformType, const GLfloat *transformValues);
+GL_APICALL void GL_APIENTRY glPathParameterivNV (GLuint path, GLenum pname, const GLint *value);
+GL_APICALL void GL_APIENTRY glPathParameteriNV (GLuint path, GLenum pname, GLint value);
+GL_APICALL void GL_APIENTRY glPathParameterfvNV (GLuint path, GLenum pname, const GLfloat *value);
+GL_APICALL void GL_APIENTRY glPathParameterfNV (GLuint path, GLenum pname, GLfloat value);
+GL_APICALL void GL_APIENTRY glPathDashArrayNV (GLuint path, GLsizei dashCount, const GLfloat *dashArray);
+GL_APICALL void GL_APIENTRY glPathStencilFuncNV (GLenum func, GLint ref, GLuint mask);
+GL_APICALL void GL_APIENTRY glPathStencilDepthOffsetNV (GLfloat factor, GLfloat units);
+GL_APICALL void GL_APIENTRY glStencilFillPathNV (GLuint path, GLenum fillMode, GLuint mask);
+GL_APICALL void GL_APIENTRY glStencilStrokePathNV (GLuint path, GLint reference, GLuint mask);
+GL_APICALL void GL_APIENTRY glStencilFillPathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum fillMode, GLuint mask, GLenum transformType, const GLfloat *transformValues);
+GL_APICALL void GL_APIENTRY glStencilStrokePathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLint reference, GLuint mask, GLenum transformType, const GLfloat *transformValues);
+GL_APICALL void GL_APIENTRY glPathCoverDepthFuncNV (GLenum func);
+GL_APICALL void GL_APIENTRY glCoverFillPathNV (GLuint path, GLenum coverMode);
+GL_APICALL void GL_APIENTRY glCoverStrokePathNV (GLuint path, GLenum coverMode);
+GL_APICALL void GL_APIENTRY glCoverFillPathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues);
+GL_APICALL void GL_APIENTRY glCoverStrokePathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum coverMode, GLenum transformType, const GLfloat *transformValues);
+GL_APICALL void GL_APIENTRY glGetPathParameterivNV (GLuint path, GLenum pname, GLint *value);
+GL_APICALL void GL_APIENTRY glGetPathParameterfvNV (GLuint path, GLenum pname, GLfloat *value);
+GL_APICALL void GL_APIENTRY glGetPathCommandsNV (GLuint path, GLubyte *commands);
+GL_APICALL void GL_APIENTRY glGetPathCoordsNV (GLuint path, GLfloat *coords);
+GL_APICALL void GL_APIENTRY glGetPathDashArrayNV (GLuint path, GLfloat *dashArray);
+GL_APICALL void GL_APIENTRY glGetPathMetricsNV (GLbitfield metricQueryMask, GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLsizei stride, GLfloat *metrics);
+GL_APICALL void GL_APIENTRY glGetPathMetricRangeNV (GLbitfield metricQueryMask, GLuint firstPathName, GLsizei numPaths, GLsizei stride, GLfloat *metrics);
+GL_APICALL void GL_APIENTRY glGetPathSpacingNV (GLenum pathListMode, GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLfloat advanceScale, GLfloat kerningScale, GLenum transformType, GLfloat *returnedSpacing);
+GL_APICALL GLboolean GL_APIENTRY glIsPointInFillPathNV (GLuint path, GLuint mask, GLfloat x, GLfloat y);
+GL_APICALL GLboolean GL_APIENTRY glIsPointInStrokePathNV (GLuint path, GLfloat x, GLfloat y);
+GL_APICALL GLfloat GL_APIENTRY glGetPathLengthNV (GLuint path, GLsizei startSegment, GLsizei numSegments);
+GL_APICALL GLboolean GL_APIENTRY glPointAlongPathNV (GLuint path, GLsizei startSegment, GLsizei numSegments, GLfloat distance, GLfloat *x, GLfloat *y, GLfloat *tangentX, GLfloat *tangentY);
+GL_APICALL void GL_APIENTRY glMatrixLoad3x2fNV (GLenum matrixMode, const GLfloat *m);
+GL_APICALL void GL_APIENTRY glMatrixLoad3x3fNV (GLenum matrixMode, const GLfloat *m);
+GL_APICALL void GL_APIENTRY glMatrixLoadTranspose3x3fNV (GLenum matrixMode, const GLfloat *m);
+GL_APICALL void GL_APIENTRY glMatrixMult3x2fNV (GLenum matrixMode, const GLfloat *m);
+GL_APICALL void GL_APIENTRY glMatrixMult3x3fNV (GLenum matrixMode, const GLfloat *m);
+GL_APICALL void GL_APIENTRY glMatrixMultTranspose3x3fNV (GLenum matrixMode, const GLfloat *m);
+GL_APICALL void GL_APIENTRY glStencilThenCoverFillPathNV (GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode);
+GL_APICALL void GL_APIENTRY glStencilThenCoverStrokePathNV (GLuint path, GLint reference, GLuint mask, GLenum coverMode);
+GL_APICALL void GL_APIENTRY glStencilThenCoverFillPathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLenum fillMode, GLuint mask, GLenum coverMode, GLenum transformType, const GLfloat *transformValues);
+GL_APICALL void GL_APIENTRY glStencilThenCoverStrokePathInstancedNV (GLsizei numPaths, GLenum pathNameType, const void *paths, GLuint pathBase, GLint reference, GLuint mask, GLenum coverMode, GLenum transformType, const GLfloat *transformValues);
+GL_APICALL GLenum GL_APIENTRY glPathGlyphIndexRangeNV (GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLuint pathParameterTemplate, GLfloat emScale, GLuint baseAndCount[2]);
+GL_APICALL GLenum GL_APIENTRY glPathGlyphIndexArrayNV (GLuint firstPathName, GLenum fontTarget, const void *fontName, GLbitfield fontStyle, GLuint firstGlyphIndex, GLsizei numGlyphs, GLuint pathParameterTemplate, GLfloat emScale);
+GL_APICALL GLenum GL_APIENTRY glPathMemoryGlyphIndexArrayNV (GLuint firstPathName, GLenum fontTarget, GLsizeiptr fontSize, const void *fontData, GLsizei faceIndex, GLuint firstGlyphIndex, GLsizei numGlyphs, GLuint pathParameterTemplate, GLfloat emScale);
+GL_APICALL void GL_APIENTRY glProgramPathFragmentInputGenNV (GLuint program, GLint location, GLenum genMode, GLint components, const GLfloat *coeffs);
+GL_APICALL void GL_APIENTRY glGetProgramResourcefvNV (GLuint program, GLenum programInterface, GLuint index, GLsizei propCount, const GLenum *props, GLsizei bufSize, GLsizei *length, GLfloat *params);
+#endif
+#endif /* GL_NV_path_rendering */
+
+#ifndef GL_NV_path_rendering_shared_edge
+#define GL_NV_path_rendering_shared_edge 1
+#define GL_SHARED_EDGE_NV 0xC0
+#endif /* GL_NV_path_rendering_shared_edge */
+
+#ifndef GL_NV_pixel_buffer_object
+#define GL_NV_pixel_buffer_object 1
+#define GL_PIXEL_PACK_BUFFER_NV 0x88EB
+#define GL_PIXEL_UNPACK_BUFFER_NV 0x88EC
+#define GL_PIXEL_PACK_BUFFER_BINDING_NV 0x88ED
+#define GL_PIXEL_UNPACK_BUFFER_BINDING_NV 0x88EF
+#endif /* GL_NV_pixel_buffer_object */
+
+#ifndef GL_NV_polygon_mode
+#define GL_NV_polygon_mode 1
+#define GL_POLYGON_MODE_NV 0x0B40
+#define GL_POLYGON_OFFSET_POINT_NV 0x2A01
+#define GL_POLYGON_OFFSET_LINE_NV 0x2A02
+#define GL_POINT_NV 0x1B00
+#define GL_LINE_NV 0x1B01
+#define GL_FILL_NV 0x1B02
+typedef void (GL_APIENTRYP PFNGLPOLYGONMODENVPROC) (GLenum face, GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glPolygonModeNV (GLenum face, GLenum mode);
+#endif
+#endif /* GL_NV_polygon_mode */
+
+#ifndef GL_NV_read_buffer
+#define GL_NV_read_buffer 1
+#define GL_READ_BUFFER_NV 0x0C02
+typedef void (GL_APIENTRYP PFNGLREADBUFFERNVPROC) (GLenum mode);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glReadBufferNV (GLenum mode);
+#endif
+#endif /* GL_NV_read_buffer */
+
+#ifndef GL_NV_read_buffer_front
+#define GL_NV_read_buffer_front 1
+#endif /* GL_NV_read_buffer_front */
+
+#ifndef GL_NV_read_depth
+#define GL_NV_read_depth 1
+#endif /* GL_NV_read_depth */
+
+#ifndef GL_NV_read_depth_stencil
+#define GL_NV_read_depth_stencil 1
+#endif /* GL_NV_read_depth_stencil */
+
+#ifndef GL_NV_read_stencil
+#define GL_NV_read_stencil 1
+#endif /* GL_NV_read_stencil */
+
+#ifndef GL_NV_sRGB_formats
+#define GL_NV_sRGB_formats 1
+#define GL_SLUMINANCE_NV 0x8C46
+#define GL_SLUMINANCE_ALPHA_NV 0x8C44
+#define GL_SRGB8_NV 0x8C41
+#define GL_SLUMINANCE8_NV 0x8C47
+#define GL_SLUMINANCE8_ALPHA8_NV 0x8C45
+#define GL_COMPRESSED_SRGB_S3TC_DXT1_NV 0x8C4C
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV 0x8C4D
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_NV 0x8C4E
+#define GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_NV 0x8C4F
+#define GL_ETC1_SRGB8_NV 0x88EE
+#endif /* GL_NV_sRGB_formats */
+
+#ifndef GL_NV_sample_locations
+#define GL_NV_sample_locations 1
+#define GL_SAMPLE_LOCATION_SUBPIXEL_BITS_NV 0x933D
+#define GL_SAMPLE_LOCATION_PIXEL_GRID_WIDTH_NV 0x933E
+#define GL_SAMPLE_LOCATION_PIXEL_GRID_HEIGHT_NV 0x933F
+#define GL_PROGRAMMABLE_SAMPLE_LOCATION_TABLE_SIZE_NV 0x9340
+#define GL_SAMPLE_LOCATION_NV 0x8E50
+#define GL_PROGRAMMABLE_SAMPLE_LOCATION_NV 0x9341
+#define GL_FRAMEBUFFER_PROGRAMMABLE_SAMPLE_LOCATIONS_NV 0x9342
+#define GL_FRAMEBUFFER_SAMPLE_LOCATION_PIXEL_GRID_NV 0x9343
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERSAMPLELOCATIONSFVNVPROC) (GLenum target, GLuint start, GLsizei count, const GLfloat *v);
+typedef void (GL_APIENTRYP PFNGLNAMEDFRAMEBUFFERSAMPLELOCATIONSFVNVPROC) (GLuint framebuffer, GLuint start, GLsizei count, const GLfloat *v);
+typedef void (GL_APIENTRYP PFNGLRESOLVEDEPTHVALUESNVPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glFramebufferSampleLocationsfvNV (GLenum target, GLuint start, GLsizei count, const GLfloat *v);
+GL_APICALL void GL_APIENTRY glNamedFramebufferSampleLocationsfvNV (GLuint framebuffer, GLuint start, GLsizei count, const GLfloat *v);
+GL_APICALL void GL_APIENTRY glResolveDepthValuesNV (void);
+#endif
+#endif /* GL_NV_sample_locations */
+
+#ifndef GL_NV_sample_mask_override_coverage
+#define GL_NV_sample_mask_override_coverage 1
+#endif /* GL_NV_sample_mask_override_coverage */
+
+#ifndef GL_NV_shader_atomic_fp16_vector
+#define GL_NV_shader_atomic_fp16_vector 1
+#endif /* GL_NV_shader_atomic_fp16_vector */
+
+#ifndef GL_NV_shader_noperspective_interpolation
+#define GL_NV_shader_noperspective_interpolation 1
+#endif /* GL_NV_shader_noperspective_interpolation */
+
+#ifndef GL_NV_shadow_samplers_array
+#define GL_NV_shadow_samplers_array 1
+#define GL_SAMPLER_2D_ARRAY_SHADOW_NV 0x8DC4
+#endif /* GL_NV_shadow_samplers_array */
+
+#ifndef GL_NV_shadow_samplers_cube
+#define GL_NV_shadow_samplers_cube 1
+#define GL_SAMPLER_CUBE_SHADOW_NV 0x8DC5
+#endif /* GL_NV_shadow_samplers_cube */
+
+#ifndef GL_NV_texture_border_clamp
+#define GL_NV_texture_border_clamp 1
+#define GL_TEXTURE_BORDER_COLOR_NV 0x1004
+#define GL_CLAMP_TO_BORDER_NV 0x812D
+#endif /* GL_NV_texture_border_clamp */
+
+#ifndef GL_NV_texture_compression_s3tc_update
+#define GL_NV_texture_compression_s3tc_update 1
+#endif /* GL_NV_texture_compression_s3tc_update */
+
+#ifndef GL_NV_texture_npot_2D_mipmap
+#define GL_NV_texture_npot_2D_mipmap 1
+#endif /* GL_NV_texture_npot_2D_mipmap */
+
+#ifndef GL_NV_viewport_array
+#define GL_NV_viewport_array 1
+#define GL_MAX_VIEWPORTS_NV 0x825B
+#define GL_VIEWPORT_SUBPIXEL_BITS_NV 0x825C
+#define GL_VIEWPORT_BOUNDS_RANGE_NV 0x825D
+#define GL_VIEWPORT_INDEX_PROVOKING_VERTEX_NV 0x825F
+typedef void (GL_APIENTRYP PFNGLVIEWPORTARRAYVNVPROC) (GLuint first, GLsizei count, const GLfloat *v);
+typedef void (GL_APIENTRYP PFNGLVIEWPORTINDEXEDFNVPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h);
+typedef void (GL_APIENTRYP PFNGLVIEWPORTINDEXEDFVNVPROC) (GLuint index, const GLfloat *v);
+typedef void (GL_APIENTRYP PFNGLSCISSORARRAYVNVPROC) (GLuint first, GLsizei count, const GLint *v);
+typedef void (GL_APIENTRYP PFNGLSCISSORINDEXEDNVPROC) (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height);
+typedef void (GL_APIENTRYP PFNGLSCISSORINDEXEDVNVPROC) (GLuint index, const GLint *v);
+typedef void (GL_APIENTRYP PFNGLDEPTHRANGEARRAYFVNVPROC) (GLuint first, GLsizei count, const GLfloat *v);
+typedef void (GL_APIENTRYP PFNGLDEPTHRANGEINDEXEDFNVPROC) (GLuint index, GLfloat n, GLfloat f);
+typedef void (GL_APIENTRYP PFNGLGETFLOATI_VNVPROC) (GLenum target, GLuint index, GLfloat *data);
+typedef void (GL_APIENTRYP PFNGLENABLEINVPROC) (GLenum target, GLuint index);
+typedef void (GL_APIENTRYP PFNGLDISABLEINVPROC) (GLenum target, GLuint index);
+typedef GLboolean (GL_APIENTRYP PFNGLISENABLEDINVPROC) (GLenum target, GLuint index);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glViewportArrayvNV (GLuint first, GLsizei count, const GLfloat *v);
+GL_APICALL void GL_APIENTRY glViewportIndexedfNV (GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h);
+GL_APICALL void GL_APIENTRY glViewportIndexedfvNV (GLuint index, const GLfloat *v);
+GL_APICALL void GL_APIENTRY glScissorArrayvNV (GLuint first, GLsizei count, const GLint *v);
+GL_APICALL void GL_APIENTRY glScissorIndexedNV (GLuint index, GLint left, GLint bottom, GLsizei width, GLsizei height);
+GL_APICALL void GL_APIENTRY glScissorIndexedvNV (GLuint index, const GLint *v);
+GL_APICALL void GL_APIENTRY glDepthRangeArrayfvNV (GLuint first, GLsizei count, const GLfloat *v);
+GL_APICALL void GL_APIENTRY glDepthRangeIndexedfNV (GLuint index, GLfloat n, GLfloat f);
+GL_APICALL void GL_APIENTRY glGetFloati_vNV (GLenum target, GLuint index, GLfloat *data);
+GL_APICALL void GL_APIENTRY glEnableiNV (GLenum target, GLuint index);
+GL_APICALL void GL_APIENTRY glDisableiNV (GLenum target, GLuint index);
+GL_APICALL GLboolean GL_APIENTRY glIsEnablediNV (GLenum target, GLuint index);
+#endif
+#endif /* GL_NV_viewport_array */
+
+#ifndef GL_NV_viewport_array2
+#define GL_NV_viewport_array2 1
+#endif /* GL_NV_viewport_array2 */
+
+#ifndef GL_NV_viewport_swizzle
+#define GL_NV_viewport_swizzle 1
+#define GL_VIEWPORT_SWIZZLE_POSITIVE_X_NV 0x9350
+#define GL_VIEWPORT_SWIZZLE_NEGATIVE_X_NV 0x9351
+#define GL_VIEWPORT_SWIZZLE_POSITIVE_Y_NV 0x9352
+#define GL_VIEWPORT_SWIZZLE_NEGATIVE_Y_NV 0x9353
+#define GL_VIEWPORT_SWIZZLE_POSITIVE_Z_NV 0x9354
+#define GL_VIEWPORT_SWIZZLE_NEGATIVE_Z_NV 0x9355
+#define GL_VIEWPORT_SWIZZLE_POSITIVE_W_NV 0x9356
+#define GL_VIEWPORT_SWIZZLE_NEGATIVE_W_NV 0x9357
+#define GL_VIEWPORT_SWIZZLE_X_NV 0x9358
+#define GL_VIEWPORT_SWIZZLE_Y_NV 0x9359
+#define GL_VIEWPORT_SWIZZLE_Z_NV 0x935A
+#define GL_VIEWPORT_SWIZZLE_W_NV 0x935B
+typedef void (GL_APIENTRYP PFNGLVIEWPORTSWIZZLENVPROC) (GLuint index, GLenum swizzlex, GLenum swizzley, GLenum swizzlez, GLenum swizzlew);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glViewportSwizzleNV (GLuint index, GLenum swizzlex, GLenum swizzley, GLenum swizzlez, GLenum swizzlew);
+#endif
+#endif /* GL_NV_viewport_swizzle */
+
+#ifndef GL_OVR_multiview
+#define GL_OVR_multiview 1
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_OVR 0x9630
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_OVR 0x9632
+#define GL_MAX_VIEWS_OVR 0x9631
+#define GL_FRAMEBUFFER_INCOMPLETE_VIEW_TARGETS_OVR 0x9633
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVRPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint baseViewIndex, GLsizei numViews);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glFramebufferTextureMultiviewOVR (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint baseViewIndex, GLsizei numViews);
+#endif
+#endif /* GL_OVR_multiview */
+
+#ifndef GL_OVR_multiview2
+#define GL_OVR_multiview2 1
+#endif /* GL_OVR_multiview2 */
+
+#ifndef GL_OVR_multiview_multisampled_render_to_texture
+#define GL_OVR_multiview_multisampled_render_to_texture 1
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTUREMULTISAMPLEMULTIVIEWOVRPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLsizei samples, GLint baseViewIndex, GLsizei numViews);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glFramebufferTextureMultisampleMultiviewOVR (GLenum target, GLenum attachment, GLuint texture, GLint level, GLsizei samples, GLint baseViewIndex, GLsizei numViews);
+#endif
+#endif /* GL_OVR_multiview_multisampled_render_to_texture */
+
+#ifndef GL_QCOM_alpha_test
+#define GL_QCOM_alpha_test 1
+#define GL_ALPHA_TEST_QCOM 0x0BC0
+#define GL_ALPHA_TEST_FUNC_QCOM 0x0BC1
+#define GL_ALPHA_TEST_REF_QCOM 0x0BC2
+typedef void (GL_APIENTRYP PFNGLALPHAFUNCQCOMPROC) (GLenum func, GLclampf ref);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glAlphaFuncQCOM (GLenum func, GLclampf ref);
+#endif
+#endif /* GL_QCOM_alpha_test */
+
+#ifndef GL_QCOM_binning_control
+#define GL_QCOM_binning_control 1
+#define GL_BINNING_CONTROL_HINT_QCOM 0x8FB0
+#define GL_CPU_OPTIMIZED_QCOM 0x8FB1
+#define GL_GPU_OPTIMIZED_QCOM 0x8FB2
+#define GL_RENDER_DIRECT_TO_FRAMEBUFFER_QCOM 0x8FB3
+#endif /* GL_QCOM_binning_control */
+
+#ifndef GL_QCOM_driver_control
+#define GL_QCOM_driver_control 1
+typedef void (GL_APIENTRYP PFNGLGETDRIVERCONTROLSQCOMPROC) (GLint *num, GLsizei size, GLuint *driverControls);
+typedef void (GL_APIENTRYP PFNGLGETDRIVERCONTROLSTRINGQCOMPROC) (GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString);
+typedef void (GL_APIENTRYP PFNGLENABLEDRIVERCONTROLQCOMPROC) (GLuint driverControl);
+typedef void (GL_APIENTRYP PFNGLDISABLEDRIVERCONTROLQCOMPROC) (GLuint driverControl);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glGetDriverControlsQCOM (GLint *num, GLsizei size, GLuint *driverControls);
+GL_APICALL void GL_APIENTRY glGetDriverControlStringQCOM (GLuint driverControl, GLsizei bufSize, GLsizei *length, GLchar *driverControlString);
+GL_APICALL void GL_APIENTRY glEnableDriverControlQCOM (GLuint driverControl);
+GL_APICALL void GL_APIENTRY glDisableDriverControlQCOM (GLuint driverControl);
+#endif
+#endif /* GL_QCOM_driver_control */
+
+#ifndef GL_QCOM_extended_get
+#define GL_QCOM_extended_get 1
+#define GL_TEXTURE_WIDTH_QCOM 0x8BD2
+#define GL_TEXTURE_HEIGHT_QCOM 0x8BD3
+#define GL_TEXTURE_DEPTH_QCOM 0x8BD4
+#define GL_TEXTURE_INTERNAL_FORMAT_QCOM 0x8BD5
+#define GL_TEXTURE_FORMAT_QCOM 0x8BD6
+#define GL_TEXTURE_TYPE_QCOM 0x8BD7
+#define GL_TEXTURE_IMAGE_VALID_QCOM 0x8BD8
+#define GL_TEXTURE_NUM_LEVELS_QCOM 0x8BD9
+#define GL_TEXTURE_TARGET_QCOM 0x8BDA
+#define GL_TEXTURE_OBJECT_VALID_QCOM 0x8BDB
+#define GL_STATE_RESTORE 0x8BDC
+typedef void (GL_APIENTRYP PFNGLEXTGETTEXTURESQCOMPROC) (GLuint *textures, GLint maxTextures, GLint *numTextures);
+typedef void (GL_APIENTRYP PFNGLEXTGETBUFFERSQCOMPROC) (GLuint *buffers, GLint maxBuffers, GLint *numBuffers);
+typedef void (GL_APIENTRYP PFNGLEXTGETRENDERBUFFERSQCOMPROC) (GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers);
+typedef void (GL_APIENTRYP PFNGLEXTGETFRAMEBUFFERSQCOMPROC) (GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers);
+typedef void (GL_APIENTRYP PFNGLEXTGETTEXLEVELPARAMETERIVQCOMPROC) (GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params);
+typedef void (GL_APIENTRYP PFNGLEXTTEXOBJECTSTATEOVERRIDEIQCOMPROC) (GLenum target, GLenum pname, GLint param);
+typedef void (GL_APIENTRYP PFNGLEXTGETTEXSUBIMAGEQCOMPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, void *texels);
+typedef void (GL_APIENTRYP PFNGLEXTGETBUFFERPOINTERVQCOMPROC) (GLenum target, void **params);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glExtGetTexturesQCOM (GLuint *textures, GLint maxTextures, GLint *numTextures);
+GL_APICALL void GL_APIENTRY glExtGetBuffersQCOM (GLuint *buffers, GLint maxBuffers, GLint *numBuffers);
+GL_APICALL void GL_APIENTRY glExtGetRenderbuffersQCOM (GLuint *renderbuffers, GLint maxRenderbuffers, GLint *numRenderbuffers);
+GL_APICALL void GL_APIENTRY glExtGetFramebuffersQCOM (GLuint *framebuffers, GLint maxFramebuffers, GLint *numFramebuffers);
+GL_APICALL void GL_APIENTRY glExtGetTexLevelParameterivQCOM (GLuint texture, GLenum face, GLint level, GLenum pname, GLint *params);
+GL_APICALL void GL_APIENTRY glExtTexObjectStateOverrideiQCOM (GLenum target, GLenum pname, GLint param);
+GL_APICALL void GL_APIENTRY glExtGetTexSubImageQCOM (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, void *texels);
+GL_APICALL void GL_APIENTRY glExtGetBufferPointervQCOM (GLenum target, void **params);
+#endif
+#endif /* GL_QCOM_extended_get */
+
+#ifndef GL_QCOM_extended_get2
+#define GL_QCOM_extended_get2 1
+typedef void (GL_APIENTRYP PFNGLEXTGETSHADERSQCOMPROC) (GLuint *shaders, GLint maxShaders, GLint *numShaders);
+typedef void (GL_APIENTRYP PFNGLEXTGETPROGRAMSQCOMPROC) (GLuint *programs, GLint maxPrograms, GLint *numPrograms);
+typedef GLboolean (GL_APIENTRYP PFNGLEXTISPROGRAMBINARYQCOMPROC) (GLuint program);
+typedef void (GL_APIENTRYP PFNGLEXTGETPROGRAMBINARYSOURCEQCOMPROC) (GLuint program, GLenum shadertype, GLchar *source, GLint *length);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glExtGetShadersQCOM (GLuint *shaders, GLint maxShaders, GLint *numShaders);
+GL_APICALL void GL_APIENTRY glExtGetProgramsQCOM (GLuint *programs, GLint maxPrograms, GLint *numPrograms);
+GL_APICALL GLboolean GL_APIENTRY glExtIsProgramBinaryQCOM (GLuint program);
+GL_APICALL void GL_APIENTRY glExtGetProgramBinarySourceQCOM (GLuint program, GLenum shadertype, GLchar *source, GLint *length);
+#endif
+#endif /* GL_QCOM_extended_get2 */
+
+#ifndef GL_QCOM_framebuffer_foveated
+#define GL_QCOM_framebuffer_foveated 1
+#define GL_FOVEATION_ENABLE_BIT_QCOM 0x00000001
+#define GL_FOVEATION_SCALED_BIN_METHOD_BIT_QCOM 0x00000002
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERFOVEATIONCONFIGQCOMPROC) (GLuint framebuffer, GLuint numLayers, GLuint focalPointsPerLayer, GLuint requestedFeatures, GLuint *providedFeatures);
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERFOVEATIONPARAMETERSQCOMPROC) (GLuint framebuffer, GLuint layer, GLuint focalPoint, GLfloat focalX, GLfloat focalY, GLfloat gainX, GLfloat gainY, GLfloat foveaArea);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glFramebufferFoveationConfigQCOM (GLuint framebuffer, GLuint numLayers, GLuint focalPointsPerLayer, GLuint requestedFeatures, GLuint *providedFeatures);
+GL_APICALL void GL_APIENTRY glFramebufferFoveationParametersQCOM (GLuint framebuffer, GLuint layer, GLuint focalPoint, GLfloat focalX, GLfloat focalY, GLfloat gainX, GLfloat gainY, GLfloat foveaArea);
+#endif
+#endif /* GL_QCOM_framebuffer_foveated */
+
+#ifndef GL_QCOM_perfmon_global_mode
+#define GL_QCOM_perfmon_global_mode 1
+#define GL_PERFMON_GLOBAL_MODE_QCOM 0x8FA0
+#endif /* GL_QCOM_perfmon_global_mode */
+
+#ifndef GL_QCOM_shader_framebuffer_fetch_noncoherent
+#define GL_QCOM_shader_framebuffer_fetch_noncoherent 1
+#define GL_FRAMEBUFFER_FETCH_NONCOHERENT_QCOM 0x96A2
+typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERFETCHBARRIERQCOMPROC) (void);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glFramebufferFetchBarrierQCOM (void);
+#endif
+#endif /* GL_QCOM_shader_framebuffer_fetch_noncoherent */
+
+#ifndef GL_QCOM_tiled_rendering
+#define GL_QCOM_tiled_rendering 1
+#define GL_COLOR_BUFFER_BIT0_QCOM 0x00000001
+#define GL_COLOR_BUFFER_BIT1_QCOM 0x00000002
+#define GL_COLOR_BUFFER_BIT2_QCOM 0x00000004
+#define GL_COLOR_BUFFER_BIT3_QCOM 0x00000008
+#define GL_COLOR_BUFFER_BIT4_QCOM 0x00000010
+#define GL_COLOR_BUFFER_BIT5_QCOM 0x00000020
+#define GL_COLOR_BUFFER_BIT6_QCOM 0x00000040
+#define GL_COLOR_BUFFER_BIT7_QCOM 0x00000080
+#define GL_DEPTH_BUFFER_BIT0_QCOM 0x00000100
+#define GL_DEPTH_BUFFER_BIT1_QCOM 0x00000200
+#define GL_DEPTH_BUFFER_BIT2_QCOM 0x00000400
+#define GL_DEPTH_BUFFER_BIT3_QCOM 0x00000800
+#define GL_DEPTH_BUFFER_BIT4_QCOM 0x00001000
+#define GL_DEPTH_BUFFER_BIT5_QCOM 0x00002000
+#define GL_DEPTH_BUFFER_BIT6_QCOM 0x00004000
+#define GL_DEPTH_BUFFER_BIT7_QCOM 0x00008000
+#define GL_STENCIL_BUFFER_BIT0_QCOM 0x00010000
+#define GL_STENCIL_BUFFER_BIT1_QCOM 0x00020000
+#define GL_STENCIL_BUFFER_BIT2_QCOM 0x00040000
+#define GL_STENCIL_BUFFER_BIT3_QCOM 0x00080000
+#define GL_STENCIL_BUFFER_BIT4_QCOM 0x00100000
+#define GL_STENCIL_BUFFER_BIT5_QCOM 0x00200000
+#define GL_STENCIL_BUFFER_BIT6_QCOM 0x00400000
+#define GL_STENCIL_BUFFER_BIT7_QCOM 0x00800000
+#define GL_MULTISAMPLE_BUFFER_BIT0_QCOM 0x01000000
+#define GL_MULTISAMPLE_BUFFER_BIT1_QCOM 0x02000000
+#define GL_MULTISAMPLE_BUFFER_BIT2_QCOM 0x04000000
+#define GL_MULTISAMPLE_BUFFER_BIT3_QCOM 0x08000000
+#define GL_MULTISAMPLE_BUFFER_BIT4_QCOM 0x10000000
+#define GL_MULTISAMPLE_BUFFER_BIT5_QCOM 0x20000000
+#define GL_MULTISAMPLE_BUFFER_BIT6_QCOM 0x40000000
+#define GL_MULTISAMPLE_BUFFER_BIT7_QCOM 0x80000000
+typedef void (GL_APIENTRYP PFNGLSTARTTILINGQCOMPROC) (GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask);
+typedef void (GL_APIENTRYP PFNGLENDTILINGQCOMPROC) (GLbitfield preserveMask);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glStartTilingQCOM (GLuint x, GLuint y, GLuint width, GLuint height, GLbitfield preserveMask);
+GL_APICALL void GL_APIENTRY glEndTilingQCOM (GLbitfield preserveMask);
+#endif
+#endif /* GL_QCOM_tiled_rendering */
+
+#ifndef GL_QCOM_writeonly_rendering
+#define GL_QCOM_writeonly_rendering 1
+#define GL_WRITEONLY_RENDERING_QCOM 0x8823
+#endif /* GL_QCOM_writeonly_rendering */
+
+#ifndef GL_VIV_shader_binary
+#define GL_VIV_shader_binary 1
+#define GL_SHADER_BINARY_VIV 0x8FC4
+#endif /* GL_VIV_shader_binary */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/3rdparty/SDL2/src/video/khronos/GLES2/gl2platform.h b/src/3rdparty/SDL2/src/video/khronos/GLES2/gl2platform.h
new file mode 100644
index 0000000..eb318dc
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/khronos/GLES2/gl2platform.h
@@ -0,0 +1,38 @@
+#ifndef __gl2platform_h_
+#define __gl2platform_h_
+
+/*
+** Copyright (c) 2017 The Khronos Group Inc.
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+/* Platform-specific types and definitions for OpenGL ES 2.X gl2.h
+ *
+ * Adopters may modify khrplatform.h and this file to suit their platform.
+ * Please contribute modifications back to Khronos as pull requests on the
+ * public github repository:
+ * https://github.com/KhronosGroup/OpenGL-Registry
+ */
+
+#include <KHR/khrplatform.h>
+
+#ifndef GL_APICALL
+#define GL_APICALL KHRONOS_APICALL
+#endif
+
+#ifndef GL_APIENTRY
+#define GL_APIENTRY KHRONOS_APIENTRY
+#endif
+
+#endif /* __gl2platform_h_ */
diff --git a/src/3rdparty/SDL2/src/video/khronos/KHR/khrplatform.h b/src/3rdparty/SDL2/src/video/khronos/KHR/khrplatform.h
new file mode 100644
index 0000000..1ad3554
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/khronos/KHR/khrplatform.h
@@ -0,0 +1,284 @@
+#ifndef __khrplatform_h_
+#define __khrplatform_h_
+
+/*
+** Copyright (c) 2008-2009 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+
+/* Khronos platform-specific types and definitions.
+ *
+ * $Revision: 32517 $ on $Date: 2016-03-11 02:41:19 -0800 (Fri, 11 Mar 2016) $
+ *
+ * Adopters may modify this file to suit their platform. Adopters are
+ * encouraged to submit platform specific modifications to the Khronos
+ * group so that they can be included in future versions of this file.
+ * Please submit changes by sending them to the public Khronos Bugzilla
+ * (http://khronos.org/bugzilla) by filing a bug against product
+ * "Khronos (general)" component "Registry".
+ *
+ * A predefined template which fills in some of the bug fields can be
+ * reached using http://tinyurl.com/khrplatform-h-bugreport, but you
+ * must create a Bugzilla login first.
+ *
+ *
+ * See the Implementer's Guidelines for information about where this file
+ * should be located on your system and for more details of its use:
+ * http://www.khronos.org/registry/implementers_guide.pdf
+ *
+ * This file should be included as
+ * #include <KHR/khrplatform.h>
+ * by Khronos client API header files that use its types and defines.
+ *
+ * The types in khrplatform.h should only be used to define API-specific types.
+ *
+ * Types defined in khrplatform.h:
+ * khronos_int8_t signed 8 bit
+ * khronos_uint8_t unsigned 8 bit
+ * khronos_int16_t signed 16 bit
+ * khronos_uint16_t unsigned 16 bit
+ * khronos_int32_t signed 32 bit
+ * khronos_uint32_t unsigned 32 bit
+ * khronos_int64_t signed 64 bit
+ * khronos_uint64_t unsigned 64 bit
+ * khronos_intptr_t signed same number of bits as a pointer
+ * khronos_uintptr_t unsigned same number of bits as a pointer
+ * khronos_ssize_t signed size
+ * khronos_usize_t unsigned size
+ * khronos_float_t signed 32 bit floating point
+ * khronos_time_ns_t unsigned 64 bit time in nanoseconds
+ * khronos_utime_nanoseconds_t unsigned time interval or absolute time in
+ * nanoseconds
+ * khronos_stime_nanoseconds_t signed time interval in nanoseconds
+ * khronos_boolean_enum_t enumerated boolean type. This should
+ * only be used as a base type when a client API's boolean type is
+ * an enum. Client APIs which use an integer or other type for
+ * booleans cannot use this as the base type for their boolean.
+ *
+ * Tokens defined in khrplatform.h:
+ *
+ * KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
+ *
+ * KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
+ * KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
+ *
+ * Calling convention macros defined in this file:
+ * KHRONOS_APICALL
+ * KHRONOS_APIENTRY
+ * KHRONOS_APIATTRIBUTES
+ *
+ * These may be used in function prototypes as:
+ *
+ * KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
+ * int arg1,
+ * int arg2) KHRONOS_APIATTRIBUTES;
+ */
+
+/*-------------------------------------------------------------------------
+ * Definition of KHRONOS_APICALL
+ *-------------------------------------------------------------------------
+ * This precedes the return type of the function in the function prototype.
+ */
+#if defined(_WIN32) && !defined(__SCITECH_SNAP__)
+# define KHRONOS_APICALL __declspec(dllimport)
+#elif defined (__SYMBIAN32__)
+# define KHRONOS_APICALL IMPORT_C
+#elif defined(__ANDROID__)
+# define KHRONOS_APICALL __attribute__((visibility("default")))
+#else
+# define KHRONOS_APICALL
+#endif
+
+/*-------------------------------------------------------------------------
+ * Definition of KHRONOS_APIENTRY
+ *-------------------------------------------------------------------------
+ * This follows the return type of the function and precedes the function
+ * name in the function prototype.
+ */
+#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
+ /* Win32 but not WinCE */
+# define KHRONOS_APIENTRY __stdcall
+#else
+# define KHRONOS_APIENTRY
+#endif
+
+/*-------------------------------------------------------------------------
+ * Definition of KHRONOS_APIATTRIBUTES
+ *-------------------------------------------------------------------------
+ * This follows the closing parenthesis of the function prototype arguments.
+ */
+#if defined (__ARMCC_2__)
+#define KHRONOS_APIATTRIBUTES __softfp
+#else
+#define KHRONOS_APIATTRIBUTES
+#endif
+
+/*-------------------------------------------------------------------------
+ * basic type definitions
+ *-----------------------------------------------------------------------*/
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
+
+
+/*
+ * Using <stdint.h>
+ */
+#include <stdint.h>
+typedef int32_t khronos_int32_t;
+typedef uint32_t khronos_uint32_t;
+typedef int64_t khronos_int64_t;
+typedef uint64_t khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif defined(__VMS ) || defined(__sgi)
+
+/*
+ * Using <inttypes.h>
+ */
+#include <inttypes.h>
+typedef int32_t khronos_int32_t;
+typedef uint32_t khronos_uint32_t;
+typedef int64_t khronos_int64_t;
+typedef uint64_t khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
+
+/*
+ * Win32
+ */
+typedef __int32 khronos_int32_t;
+typedef unsigned __int32 khronos_uint32_t;
+typedef __int64 khronos_int64_t;
+typedef unsigned __int64 khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif defined(__sun__) || defined(__digital__)
+
+/*
+ * Sun or Digital
+ */
+typedef int khronos_int32_t;
+typedef unsigned int khronos_uint32_t;
+#if defined(__arch64__) || defined(_LP64)
+typedef long int khronos_int64_t;
+typedef unsigned long int khronos_uint64_t;
+#else
+typedef long long int khronos_int64_t;
+typedef unsigned long long int khronos_uint64_t;
+#endif /* __arch64__ */
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif 0
+
+/*
+ * Hypothetical platform with no float or int64 support
+ */
+typedef int khronos_int32_t;
+typedef unsigned int khronos_uint32_t;
+#define KHRONOS_SUPPORT_INT64 0
+#define KHRONOS_SUPPORT_FLOAT 0
+
+#else
+
+/*
+ * Generic fallback
+ */
+#include <stdint.h>
+typedef int32_t khronos_int32_t;
+typedef uint32_t khronos_uint32_t;
+typedef int64_t khronos_int64_t;
+typedef uint64_t khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#endif
+
+
+/*
+ * Types that are (so far) the same on all platforms
+ */
+typedef signed char khronos_int8_t;
+typedef unsigned char khronos_uint8_t;
+typedef signed short int khronos_int16_t;
+typedef unsigned short int khronos_uint16_t;
+
+/*
+ * Types that differ between LLP64 and LP64 architectures - in LLP64,
+ * pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
+ * to be the only LLP64 architecture in current use.
+ */
+#ifdef _WIN64
+typedef signed long long int khronos_intptr_t;
+typedef unsigned long long int khronos_uintptr_t;
+typedef signed long long int khronos_ssize_t;
+typedef unsigned long long int khronos_usize_t;
+#else
+typedef signed long int khronos_intptr_t;
+typedef unsigned long int khronos_uintptr_t;
+typedef signed long int khronos_ssize_t;
+typedef unsigned long int khronos_usize_t;
+#endif
+
+#if KHRONOS_SUPPORT_FLOAT
+/*
+ * Float type
+ */
+typedef float khronos_float_t;
+#endif
+
+#if KHRONOS_SUPPORT_INT64
+/* Time types
+ *
+ * These types can be used to represent a time interval in nanoseconds or
+ * an absolute Unadjusted System Time. Unadjusted System Time is the number
+ * of nanoseconds since some arbitrary system event (e.g. since the last
+ * time the system booted). The Unadjusted System Time is an unsigned
+ * 64 bit value that wraps back to 0 every 584 years. Time intervals
+ * may be either signed or unsigned.
+ */
+typedef khronos_uint64_t khronos_utime_nanoseconds_t;
+typedef khronos_int64_t khronos_stime_nanoseconds_t;
+#endif
+
+/*
+ * Dummy value used to pad enum types to 32 bits.
+ */
+#ifndef KHRONOS_MAX_ENUM
+#define KHRONOS_MAX_ENUM 0x7FFFFFFF
+#endif
+
+/*
+ * Enumerated boolean type
+ *
+ * Values other than zero should be considered to be true. Therefore
+ * comparisons should not be made against KHRONOS_TRUE.
+ */
+typedef enum {
+ KHRONOS_FALSE = 0,
+ KHRONOS_TRUE = 1,
+ KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
+} khronos_boolean_enum_t;
+
+#endif /* __khrplatform_h_ */
diff --git a/src/3rdparty/SDL2/src/video/khronos/vulkan/vk_platform.h b/src/3rdparty/SDL2/src/video/khronos/vulkan/vk_platform.h
new file mode 100644
index 0000000..72f8049
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/khronos/vulkan/vk_platform.h
@@ -0,0 +1,120 @@
+//
+// File: vk_platform.h
+//
+/*
+** Copyright (c) 2014-2017 The Khronos Group Inc.
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+
+#ifndef VK_PLATFORM_H_
+#define VK_PLATFORM_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif // __cplusplus
+
+/*
+***************************************************************************************************
+* Platform-specific directives and type declarations
+***************************************************************************************************
+*/
+
+/* Platform-specific calling convention macros.
+ *
+ * Platforms should define these so that Vulkan clients call Vulkan commands
+ * with the same calling conventions that the Vulkan implementation expects.
+ *
+ * VKAPI_ATTR - Placed before the return type in function declarations.
+ * Useful for C++11 and GCC/Clang-style function attribute syntax.
+ * VKAPI_CALL - Placed after the return type in function declarations.
+ * Useful for MSVC-style calling convention syntax.
+ * VKAPI_PTR - Placed between the '(' and '*' in function pointer types.
+ *
+ * Function declaration: VKAPI_ATTR void VKAPI_CALL vkCommand(void);
+ * Function pointer type: typedef void (VKAPI_PTR *PFN_vkCommand)(void);
+ */
+#if defined(_WIN32)
+ // On Windows, Vulkan commands use the stdcall convention
+ #define VKAPI_ATTR
+ #define VKAPI_CALL __stdcall
+ #define VKAPI_PTR VKAPI_CALL
+#elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH < 7
+ #error "Vulkan isn't supported for the 'armeabi' NDK ABI"
+#elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7 && defined(__ARM_32BIT_STATE)
+ // On Android 32-bit ARM targets, Vulkan functions use the "hardfloat"
+ // calling convention, i.e. float parameters are passed in registers. This
+ // is true even if the rest of the application passes floats on the stack,
+ // as it does by default when compiling for the armeabi-v7a NDK ABI.
+ #define VKAPI_ATTR __attribute__((pcs("aapcs-vfp")))
+ #define VKAPI_CALL
+ #define VKAPI_PTR VKAPI_ATTR
+#else
+ // On other platforms, use the default calling convention
+ #define VKAPI_ATTR
+ #define VKAPI_CALL
+ #define VKAPI_PTR
+#endif
+
+#include <stddef.h>
+
+#if !defined(VK_NO_STDINT_H)
+ #if defined(_MSC_VER) && (_MSC_VER < 1600)
+ typedef signed __int8 int8_t;
+ typedef unsigned __int8 uint8_t;
+ typedef signed __int16 int16_t;
+ typedef unsigned __int16 uint16_t;
+ typedef signed __int32 int32_t;
+ typedef unsigned __int32 uint32_t;
+ typedef signed __int64 int64_t;
+ typedef unsigned __int64 uint64_t;
+ #else
+ #include <stdint.h>
+ #endif
+#endif // !defined(VK_NO_STDINT_H)
+
+#ifdef __cplusplus
+} // extern "C"
+#endif // __cplusplus
+
+// Platform-specific headers required by platform window system extensions.
+// These are enabled prior to #including "vulkan.h". The same enable then
+// controls inclusion of the extension interfaces in vulkan.h.
+
+#ifdef VK_USE_PLATFORM_ANDROID_KHR
+#include <android/native_window.h>
+#endif
+
+#ifdef VK_USE_PLATFORM_MIR_KHR
+#include <mir_toolkit/client_types.h>
+#endif
+
+#ifdef VK_USE_PLATFORM_WAYLAND_KHR
+#include <wayland-client.h>
+#endif
+
+#ifdef VK_USE_PLATFORM_WIN32_KHR
+#include <windows.h>
+#endif
+
+#ifdef VK_USE_PLATFORM_XLIB_KHR
+#include <X11/Xlib.h>
+#endif
+
+#ifdef VK_USE_PLATFORM_XCB_KHR
+#include <xcb/xcb.h>
+#endif
+
+#endif
diff --git a/src/3rdparty/SDL2/src/video/khronos/vulkan/vulkan.h b/src/3rdparty/SDL2/src/video/khronos/vulkan/vulkan.h
new file mode 100644
index 0000000..04495fa
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/khronos/vulkan/vulkan.h
@@ -0,0 +1,6458 @@
+#ifndef VULKAN_H_
+#define VULKAN_H_ 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+** Copyright (c) 2015-2017 The Khronos Group Inc.
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+/*
+** This header is generated from the Khronos Vulkan XML API Registry.
+**
+*/
+
+
+#define VK_VERSION_1_0 1
+#include "./vk_platform.h"
+
+#define VK_MAKE_VERSION(major, minor, patch) \
+ (((major) << 22) | ((minor) << 12) | (patch))
+
+// DEPRECATED: This define has been removed. Specific version defines (e.g. VK_API_VERSION_1_0), or the VK_MAKE_VERSION macro, should be used instead.
+//#define VK_API_VERSION VK_MAKE_VERSION(1, 0, 0) // Patch version should always be set to 0
+
+// Vulkan 1.0 version number
+#define VK_API_VERSION_1_0 VK_MAKE_VERSION(1, 0, 0)// Patch version should always be set to 0
+
+#define VK_VERSION_MAJOR(version) ((uint32_t)(version) >> 22)
+#define VK_VERSION_MINOR(version) (((uint32_t)(version) >> 12) & 0x3ff)
+#define VK_VERSION_PATCH(version) ((uint32_t)(version) & 0xfff)
+// Version of this file
+#define VK_HEADER_VERSION 59
+
+
+#define VK_NULL_HANDLE 0
+
+
+
+#define VK_DEFINE_HANDLE(object) typedef struct object##_T* object;
+
+
+#if !defined(VK_DEFINE_NON_DISPATCHABLE_HANDLE)
+#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
+ #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object;
+#else
+ #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
+#endif
+#endif
+
+
+
+typedef uint32_t VkFlags;
+typedef uint32_t VkBool32;
+typedef uint64_t VkDeviceSize;
+typedef uint32_t VkSampleMask;
+
+VK_DEFINE_HANDLE(VkInstance)
+VK_DEFINE_HANDLE(VkPhysicalDevice)
+VK_DEFINE_HANDLE(VkDevice)
+VK_DEFINE_HANDLE(VkQueue)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSemaphore)
+VK_DEFINE_HANDLE(VkCommandBuffer)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkFence)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDeviceMemory)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkBuffer)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkImage)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkEvent)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkQueryPool)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkBufferView)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkImageView)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkShaderModule)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkPipelineCache)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkPipelineLayout)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkRenderPass)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkPipeline)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorSetLayout)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSampler)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorPool)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorSet)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkFramebuffer)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkCommandPool)
+
+#define VK_LOD_CLAMP_NONE 1000.0f
+#define VK_REMAINING_MIP_LEVELS (~0U)
+#define VK_REMAINING_ARRAY_LAYERS (~0U)
+#define VK_WHOLE_SIZE (~0ULL)
+#define VK_ATTACHMENT_UNUSED (~0U)
+#define VK_TRUE 1
+#define VK_FALSE 0
+#define VK_QUEUE_FAMILY_IGNORED (~0U)
+#define VK_SUBPASS_EXTERNAL (~0U)
+#define VK_MAX_PHYSICAL_DEVICE_NAME_SIZE 256
+#define VK_UUID_SIZE 16
+#define VK_MAX_MEMORY_TYPES 32
+#define VK_MAX_MEMORY_HEAPS 16
+#define VK_MAX_EXTENSION_NAME_SIZE 256
+#define VK_MAX_DESCRIPTION_SIZE 256
+
+
+typedef enum VkPipelineCacheHeaderVersion {
+ VK_PIPELINE_CACHE_HEADER_VERSION_ONE = 1,
+ VK_PIPELINE_CACHE_HEADER_VERSION_BEGIN_RANGE = VK_PIPELINE_CACHE_HEADER_VERSION_ONE,
+ VK_PIPELINE_CACHE_HEADER_VERSION_END_RANGE = VK_PIPELINE_CACHE_HEADER_VERSION_ONE,
+ VK_PIPELINE_CACHE_HEADER_VERSION_RANGE_SIZE = (VK_PIPELINE_CACHE_HEADER_VERSION_ONE - VK_PIPELINE_CACHE_HEADER_VERSION_ONE + 1),
+ VK_PIPELINE_CACHE_HEADER_VERSION_MAX_ENUM = 0x7FFFFFFF
+} VkPipelineCacheHeaderVersion;
+
+typedef enum VkResult {
+ VK_SUCCESS = 0,
+ VK_NOT_READY = 1,
+ VK_TIMEOUT = 2,
+ VK_EVENT_SET = 3,
+ VK_EVENT_RESET = 4,
+ VK_INCOMPLETE = 5,
+ VK_ERROR_OUT_OF_HOST_MEMORY = -1,
+ VK_ERROR_OUT_OF_DEVICE_MEMORY = -2,
+ VK_ERROR_INITIALIZATION_FAILED = -3,
+ VK_ERROR_DEVICE_LOST = -4,
+ VK_ERROR_MEMORY_MAP_FAILED = -5,
+ VK_ERROR_LAYER_NOT_PRESENT = -6,
+ VK_ERROR_EXTENSION_NOT_PRESENT = -7,
+ VK_ERROR_FEATURE_NOT_PRESENT = -8,
+ VK_ERROR_INCOMPATIBLE_DRIVER = -9,
+ VK_ERROR_TOO_MANY_OBJECTS = -10,
+ VK_ERROR_FORMAT_NOT_SUPPORTED = -11,
+ VK_ERROR_FRAGMENTED_POOL = -12,
+ VK_ERROR_SURFACE_LOST_KHR = -1000000000,
+ VK_ERROR_NATIVE_WINDOW_IN_USE_KHR = -1000000001,
+ VK_SUBOPTIMAL_KHR = 1000001003,
+ VK_ERROR_OUT_OF_DATE_KHR = -1000001004,
+ VK_ERROR_INCOMPATIBLE_DISPLAY_KHR = -1000003001,
+ VK_ERROR_VALIDATION_FAILED_EXT = -1000011001,
+ VK_ERROR_INVALID_SHADER_NV = -1000012000,
+ VK_ERROR_OUT_OF_POOL_MEMORY_KHR = -1000069000,
+ VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR = -1000072003,
+ VK_RESULT_BEGIN_RANGE = VK_ERROR_FRAGMENTED_POOL,
+ VK_RESULT_END_RANGE = VK_INCOMPLETE,
+ VK_RESULT_RANGE_SIZE = (VK_INCOMPLETE - VK_ERROR_FRAGMENTED_POOL + 1),
+ VK_RESULT_MAX_ENUM = 0x7FFFFFFF
+} VkResult;
+
+typedef enum VkStructureType {
+ VK_STRUCTURE_TYPE_APPLICATION_INFO = 0,
+ VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO = 1,
+ VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO = 2,
+ VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO = 3,
+ VK_STRUCTURE_TYPE_SUBMIT_INFO = 4,
+ VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO = 5,
+ VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE = 6,
+ VK_STRUCTURE_TYPE_BIND_SPARSE_INFO = 7,
+ VK_STRUCTURE_TYPE_FENCE_CREATE_INFO = 8,
+ VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO = 9,
+ VK_STRUCTURE_TYPE_EVENT_CREATE_INFO = 10,
+ VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO = 11,
+ VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO = 12,
+ VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO = 13,
+ VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO = 14,
+ VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO = 15,
+ VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO = 16,
+ VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO = 17,
+ VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO = 18,
+ VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO = 19,
+ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO = 20,
+ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO = 21,
+ VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO = 22,
+ VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO = 23,
+ VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO = 24,
+ VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO = 25,
+ VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO = 26,
+ VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO = 27,
+ VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO = 28,
+ VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO = 29,
+ VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO = 30,
+ VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO = 31,
+ VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO = 32,
+ VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO = 33,
+ VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO = 34,
+ VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET = 35,
+ VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET = 36,
+ VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO = 37,
+ VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO = 38,
+ VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO = 39,
+ VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO = 40,
+ VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO = 41,
+ VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO = 42,
+ VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO = 43,
+ VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER = 44,
+ VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER = 45,
+ VK_STRUCTURE_TYPE_MEMORY_BARRIER = 46,
+ VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO = 47,
+ VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO = 48,
+ VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR = 1000001000,
+ VK_STRUCTURE_TYPE_PRESENT_INFO_KHR = 1000001001,
+ VK_STRUCTURE_TYPE_DISPLAY_MODE_CREATE_INFO_KHR = 1000002000,
+ VK_STRUCTURE_TYPE_DISPLAY_SURFACE_CREATE_INFO_KHR = 1000002001,
+ VK_STRUCTURE_TYPE_DISPLAY_PRESENT_INFO_KHR = 1000003000,
+ VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR = 1000004000,
+ VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR = 1000005000,
+ VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR = 1000006000,
+ VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR = 1000007000,
+ VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR = 1000008000,
+ VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR = 1000009000,
+ VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT = 1000011000,
+ VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_RASTERIZATION_ORDER_AMD = 1000018000,
+ VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_NAME_INFO_EXT = 1000022000,
+ VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_TAG_INFO_EXT = 1000022001,
+ VK_STRUCTURE_TYPE_DEBUG_MARKER_MARKER_INFO_EXT = 1000022002,
+ VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_IMAGE_CREATE_INFO_NV = 1000026000,
+ VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV = 1000026001,
+ VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV = 1000026002,
+ VK_STRUCTURE_TYPE_TEXTURE_LOD_GATHER_FORMAT_PROPERTIES_AMD = 1000041000,
+ VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO_KHX = 1000053000,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHX = 1000053001,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHX = 1000053002,
+ VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO_NV = 1000056000,
+ VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_NV = 1000056001,
+ VK_STRUCTURE_TYPE_IMPORT_MEMORY_WIN32_HANDLE_INFO_NV = 1000057000,
+ VK_STRUCTURE_TYPE_EXPORT_MEMORY_WIN32_HANDLE_INFO_NV = 1000057001,
+ VK_STRUCTURE_TYPE_WIN32_KEYED_MUTEX_ACQUIRE_RELEASE_INFO_NV = 1000058000,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR = 1000059000,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR = 1000059001,
+ VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2_KHR = 1000059002,
+ VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2_KHR = 1000059003,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2_KHR = 1000059004,
+ VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2_KHR = 1000059005,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2_KHR = 1000059006,
+ VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2_KHR = 1000059007,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SPARSE_IMAGE_FORMAT_INFO_2_KHR = 1000059008,
+ VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO_KHX = 1000060000,
+ VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHX = 1000060001,
+ VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO_KHX = 1000060002,
+ VK_STRUCTURE_TYPE_DEVICE_GROUP_RENDER_PASS_BEGIN_INFO_KHX = 1000060003,
+ VK_STRUCTURE_TYPE_DEVICE_GROUP_COMMAND_BUFFER_BEGIN_INFO_KHX = 1000060004,
+ VK_STRUCTURE_TYPE_DEVICE_GROUP_SUBMIT_INFO_KHX = 1000060005,
+ VK_STRUCTURE_TYPE_DEVICE_GROUP_BIND_SPARSE_INFO_KHX = 1000060006,
+ VK_STRUCTURE_TYPE_DEVICE_GROUP_PRESENT_CAPABILITIES_KHX = 1000060007,
+ VK_STRUCTURE_TYPE_IMAGE_SWAPCHAIN_CREATE_INFO_KHX = 1000060008,
+ VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_SWAPCHAIN_INFO_KHX = 1000060009,
+ VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHX = 1000060010,
+ VK_STRUCTURE_TYPE_DEVICE_GROUP_PRESENT_INFO_KHX = 1000060011,
+ VK_STRUCTURE_TYPE_DEVICE_GROUP_SWAPCHAIN_CREATE_INFO_KHX = 1000060012,
+ VK_STRUCTURE_TYPE_VALIDATION_FLAGS_EXT = 1000061000,
+ VK_STRUCTURE_TYPE_VI_SURFACE_CREATE_INFO_NN = 1000062000,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES_KHX = 1000070000,
+ VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO_KHX = 1000070001,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO_KHR = 1000071000,
+ VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES_KHR = 1000071001,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_BUFFER_INFO_KHR = 1000071002,
+ VK_STRUCTURE_TYPE_EXTERNAL_BUFFER_PROPERTIES_KHR = 1000071003,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR = 1000071004,
+ VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR = 1000072000,
+ VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO_KHR = 1000072001,
+ VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR = 1000072002,
+ VK_STRUCTURE_TYPE_IMPORT_MEMORY_WIN32_HANDLE_INFO_KHR = 1000073000,
+ VK_STRUCTURE_TYPE_EXPORT_MEMORY_WIN32_HANDLE_INFO_KHR = 1000073001,
+ VK_STRUCTURE_TYPE_MEMORY_WIN32_HANDLE_PROPERTIES_KHR = 1000073002,
+ VK_STRUCTURE_TYPE_MEMORY_GET_WIN32_HANDLE_INFO_KHR = 1000073003,
+ VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR = 1000074000,
+ VK_STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR = 1000074001,
+ VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR = 1000074002,
+ VK_STRUCTURE_TYPE_WIN32_KEYED_MUTEX_ACQUIRE_RELEASE_INFO_KHR = 1000075000,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO_KHR = 1000076000,
+ VK_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_PROPERTIES_KHR = 1000076001,
+ VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO_KHR = 1000077000,
+ VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_WIN32_HANDLE_INFO_KHR = 1000078000,
+ VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_WIN32_HANDLE_INFO_KHR = 1000078001,
+ VK_STRUCTURE_TYPE_D3D12_FENCE_SUBMIT_INFO_KHR = 1000078002,
+ VK_STRUCTURE_TYPE_SEMAPHORE_GET_WIN32_HANDLE_INFO_KHR = 1000078003,
+ VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR = 1000079000,
+ VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR = 1000079001,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR = 1000080000,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR = 1000083000,
+ VK_STRUCTURE_TYPE_PRESENT_REGIONS_KHR = 1000084000,
+ VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO_KHR = 1000085000,
+ VK_STRUCTURE_TYPE_OBJECT_TABLE_CREATE_INFO_NVX = 1000086000,
+ VK_STRUCTURE_TYPE_INDIRECT_COMMANDS_LAYOUT_CREATE_INFO_NVX = 1000086001,
+ VK_STRUCTURE_TYPE_CMD_PROCESS_COMMANDS_INFO_NVX = 1000086002,
+ VK_STRUCTURE_TYPE_CMD_RESERVE_SPACE_FOR_COMMANDS_INFO_NVX = 1000086003,
+ VK_STRUCTURE_TYPE_DEVICE_GENERATED_COMMANDS_LIMITS_NVX = 1000086004,
+ VK_STRUCTURE_TYPE_DEVICE_GENERATED_COMMANDS_FEATURES_NVX = 1000086005,
+ VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_W_SCALING_STATE_CREATE_INFO_NV = 1000087000,
+ VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_EXT = 1000090000,
+ VK_STRUCTURE_TYPE_DISPLAY_POWER_INFO_EXT = 1000091000,
+ VK_STRUCTURE_TYPE_DEVICE_EVENT_INFO_EXT = 1000091001,
+ VK_STRUCTURE_TYPE_DISPLAY_EVENT_INFO_EXT = 1000091002,
+ VK_STRUCTURE_TYPE_SWAPCHAIN_COUNTER_CREATE_INFO_EXT = 1000091003,
+ VK_STRUCTURE_TYPE_PRESENT_TIMES_INFO_GOOGLE = 1000092000,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PER_VIEW_ATTRIBUTES_PROPERTIES_NVX = 1000097000,
+ VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SWIZZLE_STATE_CREATE_INFO_NV = 1000098000,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT = 1000099000,
+ VK_STRUCTURE_TYPE_PIPELINE_DISCARD_RECTANGLE_STATE_CREATE_INFO_EXT = 1000099001,
+ VK_STRUCTURE_TYPE_HDR_METADATA_EXT = 1000105000,
+ VK_STRUCTURE_TYPE_SHARED_PRESENT_SURFACE_CAPABILITIES_KHR = 1000111000,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO_KHR = 1000112000,
+ VK_STRUCTURE_TYPE_EXTERNAL_FENCE_PROPERTIES_KHR = 1000112001,
+ VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO_KHR = 1000113000,
+ VK_STRUCTURE_TYPE_IMPORT_FENCE_WIN32_HANDLE_INFO_KHR = 1000114000,
+ VK_STRUCTURE_TYPE_EXPORT_FENCE_WIN32_HANDLE_INFO_KHR = 1000114001,
+ VK_STRUCTURE_TYPE_FENCE_GET_WIN32_HANDLE_INFO_KHR = 1000114002,
+ VK_STRUCTURE_TYPE_IMPORT_FENCE_FD_INFO_KHR = 1000115000,
+ VK_STRUCTURE_TYPE_FENCE_GET_FD_INFO_KHR = 1000115001,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SURFACE_INFO_2_KHR = 1000119000,
+ VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_KHR = 1000119001,
+ VK_STRUCTURE_TYPE_SURFACE_FORMAT_2_KHR = 1000119002,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR = 1000120000,
+ VK_STRUCTURE_TYPE_IOS_SURFACE_CREATE_INFO_MVK = 1000122000,
+ VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK = 1000123000,
+ VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR = 1000127000,
+ VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR = 1000127001,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT = 1000130000,
+ VK_STRUCTURE_TYPE_SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT = 1000130001,
+ VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2_KHR = 1000146000,
+ VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2_KHR = 1000146001,
+ VK_STRUCTURE_TYPE_IMAGE_SPARSE_MEMORY_REQUIREMENTS_INFO_2_KHR = 1000146002,
+ VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR = 1000146003,
+ VK_STRUCTURE_TYPE_SPARSE_IMAGE_MEMORY_REQUIREMENTS_2_KHR = 1000146004,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT = 1000148000,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_PROPERTIES_EXT = 1000148001,
+ VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_ADVANCED_STATE_CREATE_INFO_EXT = 1000148002,
+ VK_STRUCTURE_TYPE_PIPELINE_COVERAGE_TO_COLOR_STATE_CREATE_INFO_NV = 1000149000,
+ VK_STRUCTURE_TYPE_PIPELINE_COVERAGE_MODULATION_STATE_CREATE_INFO_NV = 1000152000,
+ VK_STRUCTURE_TYPE_BEGIN_RANGE = VK_STRUCTURE_TYPE_APPLICATION_INFO,
+ VK_STRUCTURE_TYPE_END_RANGE = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO,
+ VK_STRUCTURE_TYPE_RANGE_SIZE = (VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO - VK_STRUCTURE_TYPE_APPLICATION_INFO + 1),
+ VK_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF
+} VkStructureType;
+
+typedef enum VkSystemAllocationScope {
+ VK_SYSTEM_ALLOCATION_SCOPE_COMMAND = 0,
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT = 1,
+ VK_SYSTEM_ALLOCATION_SCOPE_CACHE = 2,
+ VK_SYSTEM_ALLOCATION_SCOPE_DEVICE = 3,
+ VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE = 4,
+ VK_SYSTEM_ALLOCATION_SCOPE_BEGIN_RANGE = VK_SYSTEM_ALLOCATION_SCOPE_COMMAND,
+ VK_SYSTEM_ALLOCATION_SCOPE_END_RANGE = VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE,
+ VK_SYSTEM_ALLOCATION_SCOPE_RANGE_SIZE = (VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE - VK_SYSTEM_ALLOCATION_SCOPE_COMMAND + 1),
+ VK_SYSTEM_ALLOCATION_SCOPE_MAX_ENUM = 0x7FFFFFFF
+} VkSystemAllocationScope;
+
+typedef enum VkInternalAllocationType {
+ VK_INTERNAL_ALLOCATION_TYPE_EXECUTABLE = 0,
+ VK_INTERNAL_ALLOCATION_TYPE_BEGIN_RANGE = VK_INTERNAL_ALLOCATION_TYPE_EXECUTABLE,
+ VK_INTERNAL_ALLOCATION_TYPE_END_RANGE = VK_INTERNAL_ALLOCATION_TYPE_EXECUTABLE,
+ VK_INTERNAL_ALLOCATION_TYPE_RANGE_SIZE = (VK_INTERNAL_ALLOCATION_TYPE_EXECUTABLE - VK_INTERNAL_ALLOCATION_TYPE_EXECUTABLE + 1),
+ VK_INTERNAL_ALLOCATION_TYPE_MAX_ENUM = 0x7FFFFFFF
+} VkInternalAllocationType;
+
+typedef enum VkFormat {
+ VK_FORMAT_UNDEFINED = 0,
+ VK_FORMAT_R4G4_UNORM_PACK8 = 1,
+ VK_FORMAT_R4G4B4A4_UNORM_PACK16 = 2,
+ VK_FORMAT_B4G4R4A4_UNORM_PACK16 = 3,
+ VK_FORMAT_R5G6B5_UNORM_PACK16 = 4,
+ VK_FORMAT_B5G6R5_UNORM_PACK16 = 5,
+ VK_FORMAT_R5G5B5A1_UNORM_PACK16 = 6,
+ VK_FORMAT_B5G5R5A1_UNORM_PACK16 = 7,
+ VK_FORMAT_A1R5G5B5_UNORM_PACK16 = 8,
+ VK_FORMAT_R8_UNORM = 9,
+ VK_FORMAT_R8_SNORM = 10,
+ VK_FORMAT_R8_USCALED = 11,
+ VK_FORMAT_R8_SSCALED = 12,
+ VK_FORMAT_R8_UINT = 13,
+ VK_FORMAT_R8_SINT = 14,
+ VK_FORMAT_R8_SRGB = 15,
+ VK_FORMAT_R8G8_UNORM = 16,
+ VK_FORMAT_R8G8_SNORM = 17,
+ VK_FORMAT_R8G8_USCALED = 18,
+ VK_FORMAT_R8G8_SSCALED = 19,
+ VK_FORMAT_R8G8_UINT = 20,
+ VK_FORMAT_R8G8_SINT = 21,
+ VK_FORMAT_R8G8_SRGB = 22,
+ VK_FORMAT_R8G8B8_UNORM = 23,
+ VK_FORMAT_R8G8B8_SNORM = 24,
+ VK_FORMAT_R8G8B8_USCALED = 25,
+ VK_FORMAT_R8G8B8_SSCALED = 26,
+ VK_FORMAT_R8G8B8_UINT = 27,
+ VK_FORMAT_R8G8B8_SINT = 28,
+ VK_FORMAT_R8G8B8_SRGB = 29,
+ VK_FORMAT_B8G8R8_UNORM = 30,
+ VK_FORMAT_B8G8R8_SNORM = 31,
+ VK_FORMAT_B8G8R8_USCALED = 32,
+ VK_FORMAT_B8G8R8_SSCALED = 33,
+ VK_FORMAT_B8G8R8_UINT = 34,
+ VK_FORMAT_B8G8R8_SINT = 35,
+ VK_FORMAT_B8G8R8_SRGB = 36,
+ VK_FORMAT_R8G8B8A8_UNORM = 37,
+ VK_FORMAT_R8G8B8A8_SNORM = 38,
+ VK_FORMAT_R8G8B8A8_USCALED = 39,
+ VK_FORMAT_R8G8B8A8_SSCALED = 40,
+ VK_FORMAT_R8G8B8A8_UINT = 41,
+ VK_FORMAT_R8G8B8A8_SINT = 42,
+ VK_FORMAT_R8G8B8A8_SRGB = 43,
+ VK_FORMAT_B8G8R8A8_UNORM = 44,
+ VK_FORMAT_B8G8R8A8_SNORM = 45,
+ VK_FORMAT_B8G8R8A8_USCALED = 46,
+ VK_FORMAT_B8G8R8A8_SSCALED = 47,
+ VK_FORMAT_B8G8R8A8_UINT = 48,
+ VK_FORMAT_B8G8R8A8_SINT = 49,
+ VK_FORMAT_B8G8R8A8_SRGB = 50,
+ VK_FORMAT_A8B8G8R8_UNORM_PACK32 = 51,
+ VK_FORMAT_A8B8G8R8_SNORM_PACK32 = 52,
+ VK_FORMAT_A8B8G8R8_USCALED_PACK32 = 53,
+ VK_FORMAT_A8B8G8R8_SSCALED_PACK32 = 54,
+ VK_FORMAT_A8B8G8R8_UINT_PACK32 = 55,
+ VK_FORMAT_A8B8G8R8_SINT_PACK32 = 56,
+ VK_FORMAT_A8B8G8R8_SRGB_PACK32 = 57,
+ VK_FORMAT_A2R10G10B10_UNORM_PACK32 = 58,
+ VK_FORMAT_A2R10G10B10_SNORM_PACK32 = 59,
+ VK_FORMAT_A2R10G10B10_USCALED_PACK32 = 60,
+ VK_FORMAT_A2R10G10B10_SSCALED_PACK32 = 61,
+ VK_FORMAT_A2R10G10B10_UINT_PACK32 = 62,
+ VK_FORMAT_A2R10G10B10_SINT_PACK32 = 63,
+ VK_FORMAT_A2B10G10R10_UNORM_PACK32 = 64,
+ VK_FORMAT_A2B10G10R10_SNORM_PACK32 = 65,
+ VK_FORMAT_A2B10G10R10_USCALED_PACK32 = 66,
+ VK_FORMAT_A2B10G10R10_SSCALED_PACK32 = 67,
+ VK_FORMAT_A2B10G10R10_UINT_PACK32 = 68,
+ VK_FORMAT_A2B10G10R10_SINT_PACK32 = 69,
+ VK_FORMAT_R16_UNORM = 70,
+ VK_FORMAT_R16_SNORM = 71,
+ VK_FORMAT_R16_USCALED = 72,
+ VK_FORMAT_R16_SSCALED = 73,
+ VK_FORMAT_R16_UINT = 74,
+ VK_FORMAT_R16_SINT = 75,
+ VK_FORMAT_R16_SFLOAT = 76,
+ VK_FORMAT_R16G16_UNORM = 77,
+ VK_FORMAT_R16G16_SNORM = 78,
+ VK_FORMAT_R16G16_USCALED = 79,
+ VK_FORMAT_R16G16_SSCALED = 80,
+ VK_FORMAT_R16G16_UINT = 81,
+ VK_FORMAT_R16G16_SINT = 82,
+ VK_FORMAT_R16G16_SFLOAT = 83,
+ VK_FORMAT_R16G16B16_UNORM = 84,
+ VK_FORMAT_R16G16B16_SNORM = 85,
+ VK_FORMAT_R16G16B16_USCALED = 86,
+ VK_FORMAT_R16G16B16_SSCALED = 87,
+ VK_FORMAT_R16G16B16_UINT = 88,
+ VK_FORMAT_R16G16B16_SINT = 89,
+ VK_FORMAT_R16G16B16_SFLOAT = 90,
+ VK_FORMAT_R16G16B16A16_UNORM = 91,
+ VK_FORMAT_R16G16B16A16_SNORM = 92,
+ VK_FORMAT_R16G16B16A16_USCALED = 93,
+ VK_FORMAT_R16G16B16A16_SSCALED = 94,
+ VK_FORMAT_R16G16B16A16_UINT = 95,
+ VK_FORMAT_R16G16B16A16_SINT = 96,
+ VK_FORMAT_R16G16B16A16_SFLOAT = 97,
+ VK_FORMAT_R32_UINT = 98,
+ VK_FORMAT_R32_SINT = 99,
+ VK_FORMAT_R32_SFLOAT = 100,
+ VK_FORMAT_R32G32_UINT = 101,
+ VK_FORMAT_R32G32_SINT = 102,
+ VK_FORMAT_R32G32_SFLOAT = 103,
+ VK_FORMAT_R32G32B32_UINT = 104,
+ VK_FORMAT_R32G32B32_SINT = 105,
+ VK_FORMAT_R32G32B32_SFLOAT = 106,
+ VK_FORMAT_R32G32B32A32_UINT = 107,
+ VK_FORMAT_R32G32B32A32_SINT = 108,
+ VK_FORMAT_R32G32B32A32_SFLOAT = 109,
+ VK_FORMAT_R64_UINT = 110,
+ VK_FORMAT_R64_SINT = 111,
+ VK_FORMAT_R64_SFLOAT = 112,
+ VK_FORMAT_R64G64_UINT = 113,
+ VK_FORMAT_R64G64_SINT = 114,
+ VK_FORMAT_R64G64_SFLOAT = 115,
+ VK_FORMAT_R64G64B64_UINT = 116,
+ VK_FORMAT_R64G64B64_SINT = 117,
+ VK_FORMAT_R64G64B64_SFLOAT = 118,
+ VK_FORMAT_R64G64B64A64_UINT = 119,
+ VK_FORMAT_R64G64B64A64_SINT = 120,
+ VK_FORMAT_R64G64B64A64_SFLOAT = 121,
+ VK_FORMAT_B10G11R11_UFLOAT_PACK32 = 122,
+ VK_FORMAT_E5B9G9R9_UFLOAT_PACK32 = 123,
+ VK_FORMAT_D16_UNORM = 124,
+ VK_FORMAT_X8_D24_UNORM_PACK32 = 125,
+ VK_FORMAT_D32_SFLOAT = 126,
+ VK_FORMAT_S8_UINT = 127,
+ VK_FORMAT_D16_UNORM_S8_UINT = 128,
+ VK_FORMAT_D24_UNORM_S8_UINT = 129,
+ VK_FORMAT_D32_SFLOAT_S8_UINT = 130,
+ VK_FORMAT_BC1_RGB_UNORM_BLOCK = 131,
+ VK_FORMAT_BC1_RGB_SRGB_BLOCK = 132,
+ VK_FORMAT_BC1_RGBA_UNORM_BLOCK = 133,
+ VK_FORMAT_BC1_RGBA_SRGB_BLOCK = 134,
+ VK_FORMAT_BC2_UNORM_BLOCK = 135,
+ VK_FORMAT_BC2_SRGB_BLOCK = 136,
+ VK_FORMAT_BC3_UNORM_BLOCK = 137,
+ VK_FORMAT_BC3_SRGB_BLOCK = 138,
+ VK_FORMAT_BC4_UNORM_BLOCK = 139,
+ VK_FORMAT_BC4_SNORM_BLOCK = 140,
+ VK_FORMAT_BC5_UNORM_BLOCK = 141,
+ VK_FORMAT_BC5_SNORM_BLOCK = 142,
+ VK_FORMAT_BC6H_UFLOAT_BLOCK = 143,
+ VK_FORMAT_BC6H_SFLOAT_BLOCK = 144,
+ VK_FORMAT_BC7_UNORM_BLOCK = 145,
+ VK_FORMAT_BC7_SRGB_BLOCK = 146,
+ VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK = 147,
+ VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK = 148,
+ VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK = 149,
+ VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK = 150,
+ VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK = 151,
+ VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK = 152,
+ VK_FORMAT_EAC_R11_UNORM_BLOCK = 153,
+ VK_FORMAT_EAC_R11_SNORM_BLOCK = 154,
+ VK_FORMAT_EAC_R11G11_UNORM_BLOCK = 155,
+ VK_FORMAT_EAC_R11G11_SNORM_BLOCK = 156,
+ VK_FORMAT_ASTC_4x4_UNORM_BLOCK = 157,
+ VK_FORMAT_ASTC_4x4_SRGB_BLOCK = 158,
+ VK_FORMAT_ASTC_5x4_UNORM_BLOCK = 159,
+ VK_FORMAT_ASTC_5x4_SRGB_BLOCK = 160,
+ VK_FORMAT_ASTC_5x5_UNORM_BLOCK = 161,
+ VK_FORMAT_ASTC_5x5_SRGB_BLOCK = 162,
+ VK_FORMAT_ASTC_6x5_UNORM_BLOCK = 163,
+ VK_FORMAT_ASTC_6x5_SRGB_BLOCK = 164,
+ VK_FORMAT_ASTC_6x6_UNORM_BLOCK = 165,
+ VK_FORMAT_ASTC_6x6_SRGB_BLOCK = 166,
+ VK_FORMAT_ASTC_8x5_UNORM_BLOCK = 167,
+ VK_FORMAT_ASTC_8x5_SRGB_BLOCK = 168,
+ VK_FORMAT_ASTC_8x6_UNORM_BLOCK = 169,
+ VK_FORMAT_ASTC_8x6_SRGB_BLOCK = 170,
+ VK_FORMAT_ASTC_8x8_UNORM_BLOCK = 171,
+ VK_FORMAT_ASTC_8x8_SRGB_BLOCK = 172,
+ VK_FORMAT_ASTC_10x5_UNORM_BLOCK = 173,
+ VK_FORMAT_ASTC_10x5_SRGB_BLOCK = 174,
+ VK_FORMAT_ASTC_10x6_UNORM_BLOCK = 175,
+ VK_FORMAT_ASTC_10x6_SRGB_BLOCK = 176,
+ VK_FORMAT_ASTC_10x8_UNORM_BLOCK = 177,
+ VK_FORMAT_ASTC_10x8_SRGB_BLOCK = 178,
+ VK_FORMAT_ASTC_10x10_UNORM_BLOCK = 179,
+ VK_FORMAT_ASTC_10x10_SRGB_BLOCK = 180,
+ VK_FORMAT_ASTC_12x10_UNORM_BLOCK = 181,
+ VK_FORMAT_ASTC_12x10_SRGB_BLOCK = 182,
+ VK_FORMAT_ASTC_12x12_UNORM_BLOCK = 183,
+ VK_FORMAT_ASTC_12x12_SRGB_BLOCK = 184,
+ VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG = 1000054000,
+ VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG = 1000054001,
+ VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG = 1000054002,
+ VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG = 1000054003,
+ VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG = 1000054004,
+ VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG = 1000054005,
+ VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG = 1000054006,
+ VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG = 1000054007,
+ VK_FORMAT_BEGIN_RANGE = VK_FORMAT_UNDEFINED,
+ VK_FORMAT_END_RANGE = VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
+ VK_FORMAT_RANGE_SIZE = (VK_FORMAT_ASTC_12x12_SRGB_BLOCK - VK_FORMAT_UNDEFINED + 1),
+ VK_FORMAT_MAX_ENUM = 0x7FFFFFFF
+} VkFormat;
+
+typedef enum VkImageType {
+ VK_IMAGE_TYPE_1D = 0,
+ VK_IMAGE_TYPE_2D = 1,
+ VK_IMAGE_TYPE_3D = 2,
+ VK_IMAGE_TYPE_BEGIN_RANGE = VK_IMAGE_TYPE_1D,
+ VK_IMAGE_TYPE_END_RANGE = VK_IMAGE_TYPE_3D,
+ VK_IMAGE_TYPE_RANGE_SIZE = (VK_IMAGE_TYPE_3D - VK_IMAGE_TYPE_1D + 1),
+ VK_IMAGE_TYPE_MAX_ENUM = 0x7FFFFFFF
+} VkImageType;
+
+typedef enum VkImageTiling {
+ VK_IMAGE_TILING_OPTIMAL = 0,
+ VK_IMAGE_TILING_LINEAR = 1,
+ VK_IMAGE_TILING_BEGIN_RANGE = VK_IMAGE_TILING_OPTIMAL,
+ VK_IMAGE_TILING_END_RANGE = VK_IMAGE_TILING_LINEAR,
+ VK_IMAGE_TILING_RANGE_SIZE = (VK_IMAGE_TILING_LINEAR - VK_IMAGE_TILING_OPTIMAL + 1),
+ VK_IMAGE_TILING_MAX_ENUM = 0x7FFFFFFF
+} VkImageTiling;
+
+typedef enum VkPhysicalDeviceType {
+ VK_PHYSICAL_DEVICE_TYPE_OTHER = 0,
+ VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU = 1,
+ VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU = 2,
+ VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU = 3,
+ VK_PHYSICAL_DEVICE_TYPE_CPU = 4,
+ VK_PHYSICAL_DEVICE_TYPE_BEGIN_RANGE = VK_PHYSICAL_DEVICE_TYPE_OTHER,
+ VK_PHYSICAL_DEVICE_TYPE_END_RANGE = VK_PHYSICAL_DEVICE_TYPE_CPU,
+ VK_PHYSICAL_DEVICE_TYPE_RANGE_SIZE = (VK_PHYSICAL_DEVICE_TYPE_CPU - VK_PHYSICAL_DEVICE_TYPE_OTHER + 1),
+ VK_PHYSICAL_DEVICE_TYPE_MAX_ENUM = 0x7FFFFFFF
+} VkPhysicalDeviceType;
+
+typedef enum VkQueryType {
+ VK_QUERY_TYPE_OCCLUSION = 0,
+ VK_QUERY_TYPE_PIPELINE_STATISTICS = 1,
+ VK_QUERY_TYPE_TIMESTAMP = 2,
+ VK_QUERY_TYPE_BEGIN_RANGE = VK_QUERY_TYPE_OCCLUSION,
+ VK_QUERY_TYPE_END_RANGE = VK_QUERY_TYPE_TIMESTAMP,
+ VK_QUERY_TYPE_RANGE_SIZE = (VK_QUERY_TYPE_TIMESTAMP - VK_QUERY_TYPE_OCCLUSION + 1),
+ VK_QUERY_TYPE_MAX_ENUM = 0x7FFFFFFF
+} VkQueryType;
+
+typedef enum VkSharingMode {
+ VK_SHARING_MODE_EXCLUSIVE = 0,
+ VK_SHARING_MODE_CONCURRENT = 1,
+ VK_SHARING_MODE_BEGIN_RANGE = VK_SHARING_MODE_EXCLUSIVE,
+ VK_SHARING_MODE_END_RANGE = VK_SHARING_MODE_CONCURRENT,
+ VK_SHARING_MODE_RANGE_SIZE = (VK_SHARING_MODE_CONCURRENT - VK_SHARING_MODE_EXCLUSIVE + 1),
+ VK_SHARING_MODE_MAX_ENUM = 0x7FFFFFFF
+} VkSharingMode;
+
+typedef enum VkImageLayout {
+ VK_IMAGE_LAYOUT_UNDEFINED = 0,
+ VK_IMAGE_LAYOUT_GENERAL = 1,
+ VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL = 2,
+ VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL = 3,
+ VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL = 4,
+ VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL = 5,
+ VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL = 6,
+ VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL = 7,
+ VK_IMAGE_LAYOUT_PREINITIALIZED = 8,
+ VK_IMAGE_LAYOUT_PRESENT_SRC_KHR = 1000001002,
+ VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR = 1000111000,
+ VK_IMAGE_LAYOUT_BEGIN_RANGE = VK_IMAGE_LAYOUT_UNDEFINED,
+ VK_IMAGE_LAYOUT_END_RANGE = VK_IMAGE_LAYOUT_PREINITIALIZED,
+ VK_IMAGE_LAYOUT_RANGE_SIZE = (VK_IMAGE_LAYOUT_PREINITIALIZED - VK_IMAGE_LAYOUT_UNDEFINED + 1),
+ VK_IMAGE_LAYOUT_MAX_ENUM = 0x7FFFFFFF
+} VkImageLayout;
+
+typedef enum VkImageViewType {
+ VK_IMAGE_VIEW_TYPE_1D = 0,
+ VK_IMAGE_VIEW_TYPE_2D = 1,
+ VK_IMAGE_VIEW_TYPE_3D = 2,
+ VK_IMAGE_VIEW_TYPE_CUBE = 3,
+ VK_IMAGE_VIEW_TYPE_1D_ARRAY = 4,
+ VK_IMAGE_VIEW_TYPE_2D_ARRAY = 5,
+ VK_IMAGE_VIEW_TYPE_CUBE_ARRAY = 6,
+ VK_IMAGE_VIEW_TYPE_BEGIN_RANGE = VK_IMAGE_VIEW_TYPE_1D,
+ VK_IMAGE_VIEW_TYPE_END_RANGE = VK_IMAGE_VIEW_TYPE_CUBE_ARRAY,
+ VK_IMAGE_VIEW_TYPE_RANGE_SIZE = (VK_IMAGE_VIEW_TYPE_CUBE_ARRAY - VK_IMAGE_VIEW_TYPE_1D + 1),
+ VK_IMAGE_VIEW_TYPE_MAX_ENUM = 0x7FFFFFFF
+} VkImageViewType;
+
+typedef enum VkComponentSwizzle {
+ VK_COMPONENT_SWIZZLE_IDENTITY = 0,
+ VK_COMPONENT_SWIZZLE_ZERO = 1,
+ VK_COMPONENT_SWIZZLE_ONE = 2,
+ VK_COMPONENT_SWIZZLE_R = 3,
+ VK_COMPONENT_SWIZZLE_G = 4,
+ VK_COMPONENT_SWIZZLE_B = 5,
+ VK_COMPONENT_SWIZZLE_A = 6,
+ VK_COMPONENT_SWIZZLE_BEGIN_RANGE = VK_COMPONENT_SWIZZLE_IDENTITY,
+ VK_COMPONENT_SWIZZLE_END_RANGE = VK_COMPONENT_SWIZZLE_A,
+ VK_COMPONENT_SWIZZLE_RANGE_SIZE = (VK_COMPONENT_SWIZZLE_A - VK_COMPONENT_SWIZZLE_IDENTITY + 1),
+ VK_COMPONENT_SWIZZLE_MAX_ENUM = 0x7FFFFFFF
+} VkComponentSwizzle;
+
+typedef enum VkVertexInputRate {
+ VK_VERTEX_INPUT_RATE_VERTEX = 0,
+ VK_VERTEX_INPUT_RATE_INSTANCE = 1,
+ VK_VERTEX_INPUT_RATE_BEGIN_RANGE = VK_VERTEX_INPUT_RATE_VERTEX,
+ VK_VERTEX_INPUT_RATE_END_RANGE = VK_VERTEX_INPUT_RATE_INSTANCE,
+ VK_VERTEX_INPUT_RATE_RANGE_SIZE = (VK_VERTEX_INPUT_RATE_INSTANCE - VK_VERTEX_INPUT_RATE_VERTEX + 1),
+ VK_VERTEX_INPUT_RATE_MAX_ENUM = 0x7FFFFFFF
+} VkVertexInputRate;
+
+typedef enum VkPrimitiveTopology {
+ VK_PRIMITIVE_TOPOLOGY_POINT_LIST = 0,
+ VK_PRIMITIVE_TOPOLOGY_LINE_LIST = 1,
+ VK_PRIMITIVE_TOPOLOGY_LINE_STRIP = 2,
+ VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST = 3,
+ VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP = 4,
+ VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN = 5,
+ VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY = 6,
+ VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY = 7,
+ VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY = 8,
+ VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY = 9,
+ VK_PRIMITIVE_TOPOLOGY_PATCH_LIST = 10,
+ VK_PRIMITIVE_TOPOLOGY_BEGIN_RANGE = VK_PRIMITIVE_TOPOLOGY_POINT_LIST,
+ VK_PRIMITIVE_TOPOLOGY_END_RANGE = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
+ VK_PRIMITIVE_TOPOLOGY_RANGE_SIZE = (VK_PRIMITIVE_TOPOLOGY_PATCH_LIST - VK_PRIMITIVE_TOPOLOGY_POINT_LIST + 1),
+ VK_PRIMITIVE_TOPOLOGY_MAX_ENUM = 0x7FFFFFFF
+} VkPrimitiveTopology;
+
+typedef enum VkPolygonMode {
+ VK_POLYGON_MODE_FILL = 0,
+ VK_POLYGON_MODE_LINE = 1,
+ VK_POLYGON_MODE_POINT = 2,
+ VK_POLYGON_MODE_FILL_RECTANGLE_NV = 1000153000,
+ VK_POLYGON_MODE_BEGIN_RANGE = VK_POLYGON_MODE_FILL,
+ VK_POLYGON_MODE_END_RANGE = VK_POLYGON_MODE_POINT,
+ VK_POLYGON_MODE_RANGE_SIZE = (VK_POLYGON_MODE_POINT - VK_POLYGON_MODE_FILL + 1),
+ VK_POLYGON_MODE_MAX_ENUM = 0x7FFFFFFF
+} VkPolygonMode;
+
+typedef enum VkFrontFace {
+ VK_FRONT_FACE_COUNTER_CLOCKWISE = 0,
+ VK_FRONT_FACE_CLOCKWISE = 1,
+ VK_FRONT_FACE_BEGIN_RANGE = VK_FRONT_FACE_COUNTER_CLOCKWISE,
+ VK_FRONT_FACE_END_RANGE = VK_FRONT_FACE_CLOCKWISE,
+ VK_FRONT_FACE_RANGE_SIZE = (VK_FRONT_FACE_CLOCKWISE - VK_FRONT_FACE_COUNTER_CLOCKWISE + 1),
+ VK_FRONT_FACE_MAX_ENUM = 0x7FFFFFFF
+} VkFrontFace;
+
+typedef enum VkCompareOp {
+ VK_COMPARE_OP_NEVER = 0,
+ VK_COMPARE_OP_LESS = 1,
+ VK_COMPARE_OP_EQUAL = 2,
+ VK_COMPARE_OP_LESS_OR_EQUAL = 3,
+ VK_COMPARE_OP_GREATER = 4,
+ VK_COMPARE_OP_NOT_EQUAL = 5,
+ VK_COMPARE_OP_GREATER_OR_EQUAL = 6,
+ VK_COMPARE_OP_ALWAYS = 7,
+ VK_COMPARE_OP_BEGIN_RANGE = VK_COMPARE_OP_NEVER,
+ VK_COMPARE_OP_END_RANGE = VK_COMPARE_OP_ALWAYS,
+ VK_COMPARE_OP_RANGE_SIZE = (VK_COMPARE_OP_ALWAYS - VK_COMPARE_OP_NEVER + 1),
+ VK_COMPARE_OP_MAX_ENUM = 0x7FFFFFFF
+} VkCompareOp;
+
+typedef enum VkStencilOp {
+ VK_STENCIL_OP_KEEP = 0,
+ VK_STENCIL_OP_ZERO = 1,
+ VK_STENCIL_OP_REPLACE = 2,
+ VK_STENCIL_OP_INCREMENT_AND_CLAMP = 3,
+ VK_STENCIL_OP_DECREMENT_AND_CLAMP = 4,
+ VK_STENCIL_OP_INVERT = 5,
+ VK_STENCIL_OP_INCREMENT_AND_WRAP = 6,
+ VK_STENCIL_OP_DECREMENT_AND_WRAP = 7,
+ VK_STENCIL_OP_BEGIN_RANGE = VK_STENCIL_OP_KEEP,
+ VK_STENCIL_OP_END_RANGE = VK_STENCIL_OP_DECREMENT_AND_WRAP,
+ VK_STENCIL_OP_RANGE_SIZE = (VK_STENCIL_OP_DECREMENT_AND_WRAP - VK_STENCIL_OP_KEEP + 1),
+ VK_STENCIL_OP_MAX_ENUM = 0x7FFFFFFF
+} VkStencilOp;
+
+typedef enum VkLogicOp {
+ VK_LOGIC_OP_CLEAR = 0,
+ VK_LOGIC_OP_AND = 1,
+ VK_LOGIC_OP_AND_REVERSE = 2,
+ VK_LOGIC_OP_COPY = 3,
+ VK_LOGIC_OP_AND_INVERTED = 4,
+ VK_LOGIC_OP_NO_OP = 5,
+ VK_LOGIC_OP_XOR = 6,
+ VK_LOGIC_OP_OR = 7,
+ VK_LOGIC_OP_NOR = 8,
+ VK_LOGIC_OP_EQUIVALENT = 9,
+ VK_LOGIC_OP_INVERT = 10,
+ VK_LOGIC_OP_OR_REVERSE = 11,
+ VK_LOGIC_OP_COPY_INVERTED = 12,
+ VK_LOGIC_OP_OR_INVERTED = 13,
+ VK_LOGIC_OP_NAND = 14,
+ VK_LOGIC_OP_SET = 15,
+ VK_LOGIC_OP_BEGIN_RANGE = VK_LOGIC_OP_CLEAR,
+ VK_LOGIC_OP_END_RANGE = VK_LOGIC_OP_SET,
+ VK_LOGIC_OP_RANGE_SIZE = (VK_LOGIC_OP_SET - VK_LOGIC_OP_CLEAR + 1),
+ VK_LOGIC_OP_MAX_ENUM = 0x7FFFFFFF
+} VkLogicOp;
+
+typedef enum VkBlendFactor {
+ VK_BLEND_FACTOR_ZERO = 0,
+ VK_BLEND_FACTOR_ONE = 1,
+ VK_BLEND_FACTOR_SRC_COLOR = 2,
+ VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR = 3,
+ VK_BLEND_FACTOR_DST_COLOR = 4,
+ VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR = 5,
+ VK_BLEND_FACTOR_SRC_ALPHA = 6,
+ VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA = 7,
+ VK_BLEND_FACTOR_DST_ALPHA = 8,
+ VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA = 9,
+ VK_BLEND_FACTOR_CONSTANT_COLOR = 10,
+ VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR = 11,
+ VK_BLEND_FACTOR_CONSTANT_ALPHA = 12,
+ VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA = 13,
+ VK_BLEND_FACTOR_SRC_ALPHA_SATURATE = 14,
+ VK_BLEND_FACTOR_SRC1_COLOR = 15,
+ VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR = 16,
+ VK_BLEND_FACTOR_SRC1_ALPHA = 17,
+ VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA = 18,
+ VK_BLEND_FACTOR_BEGIN_RANGE = VK_BLEND_FACTOR_ZERO,
+ VK_BLEND_FACTOR_END_RANGE = VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA,
+ VK_BLEND_FACTOR_RANGE_SIZE = (VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA - VK_BLEND_FACTOR_ZERO + 1),
+ VK_BLEND_FACTOR_MAX_ENUM = 0x7FFFFFFF
+} VkBlendFactor;
+
+typedef enum VkBlendOp {
+ VK_BLEND_OP_ADD = 0,
+ VK_BLEND_OP_SUBTRACT = 1,
+ VK_BLEND_OP_REVERSE_SUBTRACT = 2,
+ VK_BLEND_OP_MIN = 3,
+ VK_BLEND_OP_MAX = 4,
+ VK_BLEND_OP_ZERO_EXT = 1000148000,
+ VK_BLEND_OP_SRC_EXT = 1000148001,
+ VK_BLEND_OP_DST_EXT = 1000148002,
+ VK_BLEND_OP_SRC_OVER_EXT = 1000148003,
+ VK_BLEND_OP_DST_OVER_EXT = 1000148004,
+ VK_BLEND_OP_SRC_IN_EXT = 1000148005,
+ VK_BLEND_OP_DST_IN_EXT = 1000148006,
+ VK_BLEND_OP_SRC_OUT_EXT = 1000148007,
+ VK_BLEND_OP_DST_OUT_EXT = 1000148008,
+ VK_BLEND_OP_SRC_ATOP_EXT = 1000148009,
+ VK_BLEND_OP_DST_ATOP_EXT = 1000148010,
+ VK_BLEND_OP_XOR_EXT = 1000148011,
+ VK_BLEND_OP_MULTIPLY_EXT = 1000148012,
+ VK_BLEND_OP_SCREEN_EXT = 1000148013,
+ VK_BLEND_OP_OVERLAY_EXT = 1000148014,
+ VK_BLEND_OP_DARKEN_EXT = 1000148015,
+ VK_BLEND_OP_LIGHTEN_EXT = 1000148016,
+ VK_BLEND_OP_COLORDODGE_EXT = 1000148017,
+ VK_BLEND_OP_COLORBURN_EXT = 1000148018,
+ VK_BLEND_OP_HARDLIGHT_EXT = 1000148019,
+ VK_BLEND_OP_SOFTLIGHT_EXT = 1000148020,
+ VK_BLEND_OP_DIFFERENCE_EXT = 1000148021,
+ VK_BLEND_OP_EXCLUSION_EXT = 1000148022,
+ VK_BLEND_OP_INVERT_EXT = 1000148023,
+ VK_BLEND_OP_INVERT_RGB_EXT = 1000148024,
+ VK_BLEND_OP_LINEARDODGE_EXT = 1000148025,
+ VK_BLEND_OP_LINEARBURN_EXT = 1000148026,
+ VK_BLEND_OP_VIVIDLIGHT_EXT = 1000148027,
+ VK_BLEND_OP_LINEARLIGHT_EXT = 1000148028,
+ VK_BLEND_OP_PINLIGHT_EXT = 1000148029,
+ VK_BLEND_OP_HARDMIX_EXT = 1000148030,
+ VK_BLEND_OP_HSL_HUE_EXT = 1000148031,
+ VK_BLEND_OP_HSL_SATURATION_EXT = 1000148032,
+ VK_BLEND_OP_HSL_COLOR_EXT = 1000148033,
+ VK_BLEND_OP_HSL_LUMINOSITY_EXT = 1000148034,
+ VK_BLEND_OP_PLUS_EXT = 1000148035,
+ VK_BLEND_OP_PLUS_CLAMPED_EXT = 1000148036,
+ VK_BLEND_OP_PLUS_CLAMPED_ALPHA_EXT = 1000148037,
+ VK_BLEND_OP_PLUS_DARKER_EXT = 1000148038,
+ VK_BLEND_OP_MINUS_EXT = 1000148039,
+ VK_BLEND_OP_MINUS_CLAMPED_EXT = 1000148040,
+ VK_BLEND_OP_CONTRAST_EXT = 1000148041,
+ VK_BLEND_OP_INVERT_OVG_EXT = 1000148042,
+ VK_BLEND_OP_RED_EXT = 1000148043,
+ VK_BLEND_OP_GREEN_EXT = 1000148044,
+ VK_BLEND_OP_BLUE_EXT = 1000148045,
+ VK_BLEND_OP_BEGIN_RANGE = VK_BLEND_OP_ADD,
+ VK_BLEND_OP_END_RANGE = VK_BLEND_OP_MAX,
+ VK_BLEND_OP_RANGE_SIZE = (VK_BLEND_OP_MAX - VK_BLEND_OP_ADD + 1),
+ VK_BLEND_OP_MAX_ENUM = 0x7FFFFFFF
+} VkBlendOp;
+
+typedef enum VkDynamicState {
+ VK_DYNAMIC_STATE_VIEWPORT = 0,
+ VK_DYNAMIC_STATE_SCISSOR = 1,
+ VK_DYNAMIC_STATE_LINE_WIDTH = 2,
+ VK_DYNAMIC_STATE_DEPTH_BIAS = 3,
+ VK_DYNAMIC_STATE_BLEND_CONSTANTS = 4,
+ VK_DYNAMIC_STATE_DEPTH_BOUNDS = 5,
+ VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK = 6,
+ VK_DYNAMIC_STATE_STENCIL_WRITE_MASK = 7,
+ VK_DYNAMIC_STATE_STENCIL_REFERENCE = 8,
+ VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV = 1000087000,
+ VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT = 1000099000,
+ VK_DYNAMIC_STATE_BEGIN_RANGE = VK_DYNAMIC_STATE_VIEWPORT,
+ VK_DYNAMIC_STATE_END_RANGE = VK_DYNAMIC_STATE_STENCIL_REFERENCE,
+ VK_DYNAMIC_STATE_RANGE_SIZE = (VK_DYNAMIC_STATE_STENCIL_REFERENCE - VK_DYNAMIC_STATE_VIEWPORT + 1),
+ VK_DYNAMIC_STATE_MAX_ENUM = 0x7FFFFFFF
+} VkDynamicState;
+
+typedef enum VkFilter {
+ VK_FILTER_NEAREST = 0,
+ VK_FILTER_LINEAR = 1,
+ VK_FILTER_CUBIC_IMG = 1000015000,
+ VK_FILTER_BEGIN_RANGE = VK_FILTER_NEAREST,
+ VK_FILTER_END_RANGE = VK_FILTER_LINEAR,
+ VK_FILTER_RANGE_SIZE = (VK_FILTER_LINEAR - VK_FILTER_NEAREST + 1),
+ VK_FILTER_MAX_ENUM = 0x7FFFFFFF
+} VkFilter;
+
+typedef enum VkSamplerMipmapMode {
+ VK_SAMPLER_MIPMAP_MODE_NEAREST = 0,
+ VK_SAMPLER_MIPMAP_MODE_LINEAR = 1,
+ VK_SAMPLER_MIPMAP_MODE_BEGIN_RANGE = VK_SAMPLER_MIPMAP_MODE_NEAREST,
+ VK_SAMPLER_MIPMAP_MODE_END_RANGE = VK_SAMPLER_MIPMAP_MODE_LINEAR,
+ VK_SAMPLER_MIPMAP_MODE_RANGE_SIZE = (VK_SAMPLER_MIPMAP_MODE_LINEAR - VK_SAMPLER_MIPMAP_MODE_NEAREST + 1),
+ VK_SAMPLER_MIPMAP_MODE_MAX_ENUM = 0x7FFFFFFF
+} VkSamplerMipmapMode;
+
+typedef enum VkSamplerAddressMode {
+ VK_SAMPLER_ADDRESS_MODE_REPEAT = 0,
+ VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT = 1,
+ VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE = 2,
+ VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER = 3,
+ VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE = 4,
+ VK_SAMPLER_ADDRESS_MODE_BEGIN_RANGE = VK_SAMPLER_ADDRESS_MODE_REPEAT,
+ VK_SAMPLER_ADDRESS_MODE_END_RANGE = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
+ VK_SAMPLER_ADDRESS_MODE_RANGE_SIZE = (VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER - VK_SAMPLER_ADDRESS_MODE_REPEAT + 1),
+ VK_SAMPLER_ADDRESS_MODE_MAX_ENUM = 0x7FFFFFFF
+} VkSamplerAddressMode;
+
+typedef enum VkBorderColor {
+ VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK = 0,
+ VK_BORDER_COLOR_INT_TRANSPARENT_BLACK = 1,
+ VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK = 2,
+ VK_BORDER_COLOR_INT_OPAQUE_BLACK = 3,
+ VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE = 4,
+ VK_BORDER_COLOR_INT_OPAQUE_WHITE = 5,
+ VK_BORDER_COLOR_BEGIN_RANGE = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,
+ VK_BORDER_COLOR_END_RANGE = VK_BORDER_COLOR_INT_OPAQUE_WHITE,
+ VK_BORDER_COLOR_RANGE_SIZE = (VK_BORDER_COLOR_INT_OPAQUE_WHITE - VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK + 1),
+ VK_BORDER_COLOR_MAX_ENUM = 0x7FFFFFFF
+} VkBorderColor;
+
+typedef enum VkDescriptorType {
+ VK_DESCRIPTOR_TYPE_SAMPLER = 0,
+ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER = 1,
+ VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE = 2,
+ VK_DESCRIPTOR_TYPE_STORAGE_IMAGE = 3,
+ VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER = 4,
+ VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER = 5,
+ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER = 6,
+ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER = 7,
+ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC = 8,
+ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC = 9,
+ VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT = 10,
+ VK_DESCRIPTOR_TYPE_BEGIN_RANGE = VK_DESCRIPTOR_TYPE_SAMPLER,
+ VK_DESCRIPTOR_TYPE_END_RANGE = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
+ VK_DESCRIPTOR_TYPE_RANGE_SIZE = (VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT - VK_DESCRIPTOR_TYPE_SAMPLER + 1),
+ VK_DESCRIPTOR_TYPE_MAX_ENUM = 0x7FFFFFFF
+} VkDescriptorType;
+
+typedef enum VkAttachmentLoadOp {
+ VK_ATTACHMENT_LOAD_OP_LOAD = 0,
+ VK_ATTACHMENT_LOAD_OP_CLEAR = 1,
+ VK_ATTACHMENT_LOAD_OP_DONT_CARE = 2,
+ VK_ATTACHMENT_LOAD_OP_BEGIN_RANGE = VK_ATTACHMENT_LOAD_OP_LOAD,
+ VK_ATTACHMENT_LOAD_OP_END_RANGE = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
+ VK_ATTACHMENT_LOAD_OP_RANGE_SIZE = (VK_ATTACHMENT_LOAD_OP_DONT_CARE - VK_ATTACHMENT_LOAD_OP_LOAD + 1),
+ VK_ATTACHMENT_LOAD_OP_MAX_ENUM = 0x7FFFFFFF
+} VkAttachmentLoadOp;
+
+typedef enum VkAttachmentStoreOp {
+ VK_ATTACHMENT_STORE_OP_STORE = 0,
+ VK_ATTACHMENT_STORE_OP_DONT_CARE = 1,
+ VK_ATTACHMENT_STORE_OP_BEGIN_RANGE = VK_ATTACHMENT_STORE_OP_STORE,
+ VK_ATTACHMENT_STORE_OP_END_RANGE = VK_ATTACHMENT_STORE_OP_DONT_CARE,
+ VK_ATTACHMENT_STORE_OP_RANGE_SIZE = (VK_ATTACHMENT_STORE_OP_DONT_CARE - VK_ATTACHMENT_STORE_OP_STORE + 1),
+ VK_ATTACHMENT_STORE_OP_MAX_ENUM = 0x7FFFFFFF
+} VkAttachmentStoreOp;
+
+typedef enum VkPipelineBindPoint {
+ VK_PIPELINE_BIND_POINT_GRAPHICS = 0,
+ VK_PIPELINE_BIND_POINT_COMPUTE = 1,
+ VK_PIPELINE_BIND_POINT_BEGIN_RANGE = VK_PIPELINE_BIND_POINT_GRAPHICS,
+ VK_PIPELINE_BIND_POINT_END_RANGE = VK_PIPELINE_BIND_POINT_COMPUTE,
+ VK_PIPELINE_BIND_POINT_RANGE_SIZE = (VK_PIPELINE_BIND_POINT_COMPUTE - VK_PIPELINE_BIND_POINT_GRAPHICS + 1),
+ VK_PIPELINE_BIND_POINT_MAX_ENUM = 0x7FFFFFFF
+} VkPipelineBindPoint;
+
+typedef enum VkCommandBufferLevel {
+ VK_COMMAND_BUFFER_LEVEL_PRIMARY = 0,
+ VK_COMMAND_BUFFER_LEVEL_SECONDARY = 1,
+ VK_COMMAND_BUFFER_LEVEL_BEGIN_RANGE = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
+ VK_COMMAND_BUFFER_LEVEL_END_RANGE = VK_COMMAND_BUFFER_LEVEL_SECONDARY,
+ VK_COMMAND_BUFFER_LEVEL_RANGE_SIZE = (VK_COMMAND_BUFFER_LEVEL_SECONDARY - VK_COMMAND_BUFFER_LEVEL_PRIMARY + 1),
+ VK_COMMAND_BUFFER_LEVEL_MAX_ENUM = 0x7FFFFFFF
+} VkCommandBufferLevel;
+
+typedef enum VkIndexType {
+ VK_INDEX_TYPE_UINT16 = 0,
+ VK_INDEX_TYPE_UINT32 = 1,
+ VK_INDEX_TYPE_BEGIN_RANGE = VK_INDEX_TYPE_UINT16,
+ VK_INDEX_TYPE_END_RANGE = VK_INDEX_TYPE_UINT32,
+ VK_INDEX_TYPE_RANGE_SIZE = (VK_INDEX_TYPE_UINT32 - VK_INDEX_TYPE_UINT16 + 1),
+ VK_INDEX_TYPE_MAX_ENUM = 0x7FFFFFFF
+} VkIndexType;
+
+typedef enum VkSubpassContents {
+ VK_SUBPASS_CONTENTS_INLINE = 0,
+ VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS = 1,
+ VK_SUBPASS_CONTENTS_BEGIN_RANGE = VK_SUBPASS_CONTENTS_INLINE,
+ VK_SUBPASS_CONTENTS_END_RANGE = VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS,
+ VK_SUBPASS_CONTENTS_RANGE_SIZE = (VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS - VK_SUBPASS_CONTENTS_INLINE + 1),
+ VK_SUBPASS_CONTENTS_MAX_ENUM = 0x7FFFFFFF
+} VkSubpassContents;
+
+typedef enum VkObjectType {
+ VK_OBJECT_TYPE_UNKNOWN = 0,
+ VK_OBJECT_TYPE_INSTANCE = 1,
+ VK_OBJECT_TYPE_PHYSICAL_DEVICE = 2,
+ VK_OBJECT_TYPE_DEVICE = 3,
+ VK_OBJECT_TYPE_QUEUE = 4,
+ VK_OBJECT_TYPE_SEMAPHORE = 5,
+ VK_OBJECT_TYPE_COMMAND_BUFFER = 6,
+ VK_OBJECT_TYPE_FENCE = 7,
+ VK_OBJECT_TYPE_DEVICE_MEMORY = 8,
+ VK_OBJECT_TYPE_BUFFER = 9,
+ VK_OBJECT_TYPE_IMAGE = 10,
+ VK_OBJECT_TYPE_EVENT = 11,
+ VK_OBJECT_TYPE_QUERY_POOL = 12,
+ VK_OBJECT_TYPE_BUFFER_VIEW = 13,
+ VK_OBJECT_TYPE_IMAGE_VIEW = 14,
+ VK_OBJECT_TYPE_SHADER_MODULE = 15,
+ VK_OBJECT_TYPE_PIPELINE_CACHE = 16,
+ VK_OBJECT_TYPE_PIPELINE_LAYOUT = 17,
+ VK_OBJECT_TYPE_RENDER_PASS = 18,
+ VK_OBJECT_TYPE_PIPELINE = 19,
+ VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT = 20,
+ VK_OBJECT_TYPE_SAMPLER = 21,
+ VK_OBJECT_TYPE_DESCRIPTOR_POOL = 22,
+ VK_OBJECT_TYPE_DESCRIPTOR_SET = 23,
+ VK_OBJECT_TYPE_FRAMEBUFFER = 24,
+ VK_OBJECT_TYPE_COMMAND_POOL = 25,
+ VK_OBJECT_TYPE_SURFACE_KHR = 1000000000,
+ VK_OBJECT_TYPE_SWAPCHAIN_KHR = 1000001000,
+ VK_OBJECT_TYPE_DISPLAY_KHR = 1000002000,
+ VK_OBJECT_TYPE_DISPLAY_MODE_KHR = 1000002001,
+ VK_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT = 1000011000,
+ VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_KHR = 1000085000,
+ VK_OBJECT_TYPE_OBJECT_TABLE_NVX = 1000086000,
+ VK_OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_NVX = 1000086001,
+ VK_OBJECT_TYPE_BEGIN_RANGE = VK_OBJECT_TYPE_UNKNOWN,
+ VK_OBJECT_TYPE_END_RANGE = VK_OBJECT_TYPE_COMMAND_POOL,
+ VK_OBJECT_TYPE_RANGE_SIZE = (VK_OBJECT_TYPE_COMMAND_POOL - VK_OBJECT_TYPE_UNKNOWN + 1),
+ VK_OBJECT_TYPE_MAX_ENUM = 0x7FFFFFFF
+} VkObjectType;
+
+typedef VkFlags VkInstanceCreateFlags;
+
+typedef enum VkFormatFeatureFlagBits {
+ VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT = 0x00000001,
+ VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT = 0x00000002,
+ VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT = 0x00000004,
+ VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT = 0x00000008,
+ VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT = 0x00000010,
+ VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT = 0x00000020,
+ VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT = 0x00000040,
+ VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT = 0x00000080,
+ VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT = 0x00000100,
+ VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT = 0x00000200,
+ VK_FORMAT_FEATURE_BLIT_SRC_BIT = 0x00000400,
+ VK_FORMAT_FEATURE_BLIT_DST_BIT = 0x00000800,
+ VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT = 0x00001000,
+ VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG = 0x00002000,
+ VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR = 0x00004000,
+ VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR = 0x00008000,
+ VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT = 0x00010000,
+ VK_FORMAT_FEATURE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkFormatFeatureFlagBits;
+typedef VkFlags VkFormatFeatureFlags;
+
+typedef enum VkImageUsageFlagBits {
+ VK_IMAGE_USAGE_TRANSFER_SRC_BIT = 0x00000001,
+ VK_IMAGE_USAGE_TRANSFER_DST_BIT = 0x00000002,
+ VK_IMAGE_USAGE_SAMPLED_BIT = 0x00000004,
+ VK_IMAGE_USAGE_STORAGE_BIT = 0x00000008,
+ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT = 0x00000010,
+ VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT = 0x00000020,
+ VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT = 0x00000040,
+ VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT = 0x00000080,
+ VK_IMAGE_USAGE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkImageUsageFlagBits;
+typedef VkFlags VkImageUsageFlags;
+
+typedef enum VkImageCreateFlagBits {
+ VK_IMAGE_CREATE_SPARSE_BINDING_BIT = 0x00000001,
+ VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT = 0x00000002,
+ VK_IMAGE_CREATE_SPARSE_ALIASED_BIT = 0x00000004,
+ VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT = 0x00000008,
+ VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT = 0x00000010,
+ VK_IMAGE_CREATE_BIND_SFR_BIT_KHX = 0x00000040,
+ VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR = 0x00000020,
+ VK_IMAGE_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkImageCreateFlagBits;
+typedef VkFlags VkImageCreateFlags;
+
+typedef enum VkSampleCountFlagBits {
+ VK_SAMPLE_COUNT_1_BIT = 0x00000001,
+ VK_SAMPLE_COUNT_2_BIT = 0x00000002,
+ VK_SAMPLE_COUNT_4_BIT = 0x00000004,
+ VK_SAMPLE_COUNT_8_BIT = 0x00000008,
+ VK_SAMPLE_COUNT_16_BIT = 0x00000010,
+ VK_SAMPLE_COUNT_32_BIT = 0x00000020,
+ VK_SAMPLE_COUNT_64_BIT = 0x00000040,
+ VK_SAMPLE_COUNT_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkSampleCountFlagBits;
+typedef VkFlags VkSampleCountFlags;
+
+typedef enum VkQueueFlagBits {
+ VK_QUEUE_GRAPHICS_BIT = 0x00000001,
+ VK_QUEUE_COMPUTE_BIT = 0x00000002,
+ VK_QUEUE_TRANSFER_BIT = 0x00000004,
+ VK_QUEUE_SPARSE_BINDING_BIT = 0x00000008,
+ VK_QUEUE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkQueueFlagBits;
+typedef VkFlags VkQueueFlags;
+
+typedef enum VkMemoryPropertyFlagBits {
+ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT = 0x00000001,
+ VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT = 0x00000002,
+ VK_MEMORY_PROPERTY_HOST_COHERENT_BIT = 0x00000004,
+ VK_MEMORY_PROPERTY_HOST_CACHED_BIT = 0x00000008,
+ VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT = 0x00000010,
+ VK_MEMORY_PROPERTY_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkMemoryPropertyFlagBits;
+typedef VkFlags VkMemoryPropertyFlags;
+
+typedef enum VkMemoryHeapFlagBits {
+ VK_MEMORY_HEAP_DEVICE_LOCAL_BIT = 0x00000001,
+ VK_MEMORY_HEAP_MULTI_INSTANCE_BIT_KHX = 0x00000002,
+ VK_MEMORY_HEAP_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkMemoryHeapFlagBits;
+typedef VkFlags VkMemoryHeapFlags;
+typedef VkFlags VkDeviceCreateFlags;
+typedef VkFlags VkDeviceQueueCreateFlags;
+
+typedef enum VkPipelineStageFlagBits {
+ VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT = 0x00000001,
+ VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT = 0x00000002,
+ VK_PIPELINE_STAGE_VERTEX_INPUT_BIT = 0x00000004,
+ VK_PIPELINE_STAGE_VERTEX_SHADER_BIT = 0x00000008,
+ VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT = 0x00000010,
+ VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT = 0x00000020,
+ VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT = 0x00000040,
+ VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT = 0x00000080,
+ VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT = 0x00000100,
+ VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT = 0x00000200,
+ VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT = 0x00000400,
+ VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT = 0x00000800,
+ VK_PIPELINE_STAGE_TRANSFER_BIT = 0x00001000,
+ VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT = 0x00002000,
+ VK_PIPELINE_STAGE_HOST_BIT = 0x00004000,
+ VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT = 0x00008000,
+ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT = 0x00010000,
+ VK_PIPELINE_STAGE_COMMAND_PROCESS_BIT_NVX = 0x00020000,
+ VK_PIPELINE_STAGE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkPipelineStageFlagBits;
+typedef VkFlags VkPipelineStageFlags;
+typedef VkFlags VkMemoryMapFlags;
+
+typedef enum VkImageAspectFlagBits {
+ VK_IMAGE_ASPECT_COLOR_BIT = 0x00000001,
+ VK_IMAGE_ASPECT_DEPTH_BIT = 0x00000002,
+ VK_IMAGE_ASPECT_STENCIL_BIT = 0x00000004,
+ VK_IMAGE_ASPECT_METADATA_BIT = 0x00000008,
+ VK_IMAGE_ASPECT_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkImageAspectFlagBits;
+typedef VkFlags VkImageAspectFlags;
+
+typedef enum VkSparseImageFormatFlagBits {
+ VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT = 0x00000001,
+ VK_SPARSE_IMAGE_FORMAT_ALIGNED_MIP_SIZE_BIT = 0x00000002,
+ VK_SPARSE_IMAGE_FORMAT_NONSTANDARD_BLOCK_SIZE_BIT = 0x00000004,
+ VK_SPARSE_IMAGE_FORMAT_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkSparseImageFormatFlagBits;
+typedef VkFlags VkSparseImageFormatFlags;
+
+typedef enum VkSparseMemoryBindFlagBits {
+ VK_SPARSE_MEMORY_BIND_METADATA_BIT = 0x00000001,
+ VK_SPARSE_MEMORY_BIND_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkSparseMemoryBindFlagBits;
+typedef VkFlags VkSparseMemoryBindFlags;
+
+typedef enum VkFenceCreateFlagBits {
+ VK_FENCE_CREATE_SIGNALED_BIT = 0x00000001,
+ VK_FENCE_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkFenceCreateFlagBits;
+typedef VkFlags VkFenceCreateFlags;
+typedef VkFlags VkSemaphoreCreateFlags;
+typedef VkFlags VkEventCreateFlags;
+typedef VkFlags VkQueryPoolCreateFlags;
+
+typedef enum VkQueryPipelineStatisticFlagBits {
+ VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT = 0x00000001,
+ VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT = 0x00000002,
+ VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT = 0x00000004,
+ VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT = 0x00000008,
+ VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT = 0x00000010,
+ VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT = 0x00000020,
+ VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT = 0x00000040,
+ VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT = 0x00000080,
+ VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT = 0x00000100,
+ VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT = 0x00000200,
+ VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT = 0x00000400,
+ VK_QUERY_PIPELINE_STATISTIC_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkQueryPipelineStatisticFlagBits;
+typedef VkFlags VkQueryPipelineStatisticFlags;
+
+typedef enum VkQueryResultFlagBits {
+ VK_QUERY_RESULT_64_BIT = 0x00000001,
+ VK_QUERY_RESULT_WAIT_BIT = 0x00000002,
+ VK_QUERY_RESULT_WITH_AVAILABILITY_BIT = 0x00000004,
+ VK_QUERY_RESULT_PARTIAL_BIT = 0x00000008,
+ VK_QUERY_RESULT_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkQueryResultFlagBits;
+typedef VkFlags VkQueryResultFlags;
+
+typedef enum VkBufferCreateFlagBits {
+ VK_BUFFER_CREATE_SPARSE_BINDING_BIT = 0x00000001,
+ VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT = 0x00000002,
+ VK_BUFFER_CREATE_SPARSE_ALIASED_BIT = 0x00000004,
+ VK_BUFFER_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkBufferCreateFlagBits;
+typedef VkFlags VkBufferCreateFlags;
+
+typedef enum VkBufferUsageFlagBits {
+ VK_BUFFER_USAGE_TRANSFER_SRC_BIT = 0x00000001,
+ VK_BUFFER_USAGE_TRANSFER_DST_BIT = 0x00000002,
+ VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT = 0x00000004,
+ VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT = 0x00000008,
+ VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT = 0x00000010,
+ VK_BUFFER_USAGE_STORAGE_BUFFER_BIT = 0x00000020,
+ VK_BUFFER_USAGE_INDEX_BUFFER_BIT = 0x00000040,
+ VK_BUFFER_USAGE_VERTEX_BUFFER_BIT = 0x00000080,
+ VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT = 0x00000100,
+ VK_BUFFER_USAGE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkBufferUsageFlagBits;
+typedef VkFlags VkBufferUsageFlags;
+typedef VkFlags VkBufferViewCreateFlags;
+typedef VkFlags VkImageViewCreateFlags;
+typedef VkFlags VkShaderModuleCreateFlags;
+typedef VkFlags VkPipelineCacheCreateFlags;
+
+typedef enum VkPipelineCreateFlagBits {
+ VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT = 0x00000001,
+ VK_PIPELINE_CREATE_ALLOW_DERIVATIVES_BIT = 0x00000002,
+ VK_PIPELINE_CREATE_DERIVATIVE_BIT = 0x00000004,
+ VK_PIPELINE_CREATE_VIEW_INDEX_FROM_DEVICE_INDEX_BIT_KHX = 0x00000008,
+ VK_PIPELINE_CREATE_DISPATCH_BASE_KHX = 0x00000010,
+ VK_PIPELINE_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkPipelineCreateFlagBits;
+typedef VkFlags VkPipelineCreateFlags;
+typedef VkFlags VkPipelineShaderStageCreateFlags;
+
+typedef enum VkShaderStageFlagBits {
+ VK_SHADER_STAGE_VERTEX_BIT = 0x00000001,
+ VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT = 0x00000002,
+ VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT = 0x00000004,
+ VK_SHADER_STAGE_GEOMETRY_BIT = 0x00000008,
+ VK_SHADER_STAGE_FRAGMENT_BIT = 0x00000010,
+ VK_SHADER_STAGE_COMPUTE_BIT = 0x00000020,
+ VK_SHADER_STAGE_ALL_GRAPHICS = 0x0000001F,
+ VK_SHADER_STAGE_ALL = 0x7FFFFFFF,
+ VK_SHADER_STAGE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkShaderStageFlagBits;
+typedef VkFlags VkPipelineVertexInputStateCreateFlags;
+typedef VkFlags VkPipelineInputAssemblyStateCreateFlags;
+typedef VkFlags VkPipelineTessellationStateCreateFlags;
+typedef VkFlags VkPipelineViewportStateCreateFlags;
+typedef VkFlags VkPipelineRasterizationStateCreateFlags;
+
+typedef enum VkCullModeFlagBits {
+ VK_CULL_MODE_NONE = 0,
+ VK_CULL_MODE_FRONT_BIT = 0x00000001,
+ VK_CULL_MODE_BACK_BIT = 0x00000002,
+ VK_CULL_MODE_FRONT_AND_BACK = 0x00000003,
+ VK_CULL_MODE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkCullModeFlagBits;
+typedef VkFlags VkCullModeFlags;
+typedef VkFlags VkPipelineMultisampleStateCreateFlags;
+typedef VkFlags VkPipelineDepthStencilStateCreateFlags;
+typedef VkFlags VkPipelineColorBlendStateCreateFlags;
+
+typedef enum VkColorComponentFlagBits {
+ VK_COLOR_COMPONENT_R_BIT = 0x00000001,
+ VK_COLOR_COMPONENT_G_BIT = 0x00000002,
+ VK_COLOR_COMPONENT_B_BIT = 0x00000004,
+ VK_COLOR_COMPONENT_A_BIT = 0x00000008,
+ VK_COLOR_COMPONENT_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkColorComponentFlagBits;
+typedef VkFlags VkColorComponentFlags;
+typedef VkFlags VkPipelineDynamicStateCreateFlags;
+typedef VkFlags VkPipelineLayoutCreateFlags;
+typedef VkFlags VkShaderStageFlags;
+typedef VkFlags VkSamplerCreateFlags;
+
+typedef enum VkDescriptorSetLayoutCreateFlagBits {
+ VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR = 0x00000001,
+ VK_DESCRIPTOR_SET_LAYOUT_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkDescriptorSetLayoutCreateFlagBits;
+typedef VkFlags VkDescriptorSetLayoutCreateFlags;
+
+typedef enum VkDescriptorPoolCreateFlagBits {
+ VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT = 0x00000001,
+ VK_DESCRIPTOR_POOL_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkDescriptorPoolCreateFlagBits;
+typedef VkFlags VkDescriptorPoolCreateFlags;
+typedef VkFlags VkDescriptorPoolResetFlags;
+typedef VkFlags VkFramebufferCreateFlags;
+typedef VkFlags VkRenderPassCreateFlags;
+
+typedef enum VkAttachmentDescriptionFlagBits {
+ VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT = 0x00000001,
+ VK_ATTACHMENT_DESCRIPTION_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkAttachmentDescriptionFlagBits;
+typedef VkFlags VkAttachmentDescriptionFlags;
+
+typedef enum VkSubpassDescriptionFlagBits {
+ VK_SUBPASS_DESCRIPTION_PER_VIEW_ATTRIBUTES_BIT_NVX = 0x00000001,
+ VK_SUBPASS_DESCRIPTION_PER_VIEW_POSITION_X_ONLY_BIT_NVX = 0x00000002,
+ VK_SUBPASS_DESCRIPTION_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkSubpassDescriptionFlagBits;
+typedef VkFlags VkSubpassDescriptionFlags;
+
+typedef enum VkAccessFlagBits {
+ VK_ACCESS_INDIRECT_COMMAND_READ_BIT = 0x00000001,
+ VK_ACCESS_INDEX_READ_BIT = 0x00000002,
+ VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT = 0x00000004,
+ VK_ACCESS_UNIFORM_READ_BIT = 0x00000008,
+ VK_ACCESS_INPUT_ATTACHMENT_READ_BIT = 0x00000010,
+ VK_ACCESS_SHADER_READ_BIT = 0x00000020,
+ VK_ACCESS_SHADER_WRITE_BIT = 0x00000040,
+ VK_ACCESS_COLOR_ATTACHMENT_READ_BIT = 0x00000080,
+ VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT = 0x00000100,
+ VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT = 0x00000200,
+ VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT = 0x00000400,
+ VK_ACCESS_TRANSFER_READ_BIT = 0x00000800,
+ VK_ACCESS_TRANSFER_WRITE_BIT = 0x00001000,
+ VK_ACCESS_HOST_READ_BIT = 0x00002000,
+ VK_ACCESS_HOST_WRITE_BIT = 0x00004000,
+ VK_ACCESS_MEMORY_READ_BIT = 0x00008000,
+ VK_ACCESS_MEMORY_WRITE_BIT = 0x00010000,
+ VK_ACCESS_COMMAND_PROCESS_READ_BIT_NVX = 0x00020000,
+ VK_ACCESS_COMMAND_PROCESS_WRITE_BIT_NVX = 0x00040000,
+ VK_ACCESS_COLOR_ATTACHMENT_READ_NONCOHERENT_BIT_EXT = 0x00080000,
+ VK_ACCESS_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkAccessFlagBits;
+typedef VkFlags VkAccessFlags;
+
+typedef enum VkDependencyFlagBits {
+ VK_DEPENDENCY_BY_REGION_BIT = 0x00000001,
+ VK_DEPENDENCY_VIEW_LOCAL_BIT_KHX = 0x00000002,
+ VK_DEPENDENCY_DEVICE_GROUP_BIT_KHX = 0x00000004,
+ VK_DEPENDENCY_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkDependencyFlagBits;
+typedef VkFlags VkDependencyFlags;
+
+typedef enum VkCommandPoolCreateFlagBits {
+ VK_COMMAND_POOL_CREATE_TRANSIENT_BIT = 0x00000001,
+ VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT = 0x00000002,
+ VK_COMMAND_POOL_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkCommandPoolCreateFlagBits;
+typedef VkFlags VkCommandPoolCreateFlags;
+
+typedef enum VkCommandPoolResetFlagBits {
+ VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT = 0x00000001,
+ VK_COMMAND_POOL_RESET_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkCommandPoolResetFlagBits;
+typedef VkFlags VkCommandPoolResetFlags;
+
+typedef enum VkCommandBufferUsageFlagBits {
+ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT = 0x00000001,
+ VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT = 0x00000002,
+ VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT = 0x00000004,
+ VK_COMMAND_BUFFER_USAGE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkCommandBufferUsageFlagBits;
+typedef VkFlags VkCommandBufferUsageFlags;
+
+typedef enum VkQueryControlFlagBits {
+ VK_QUERY_CONTROL_PRECISE_BIT = 0x00000001,
+ VK_QUERY_CONTROL_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkQueryControlFlagBits;
+typedef VkFlags VkQueryControlFlags;
+
+typedef enum VkCommandBufferResetFlagBits {
+ VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT = 0x00000001,
+ VK_COMMAND_BUFFER_RESET_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkCommandBufferResetFlagBits;
+typedef VkFlags VkCommandBufferResetFlags;
+
+typedef enum VkStencilFaceFlagBits {
+ VK_STENCIL_FACE_FRONT_BIT = 0x00000001,
+ VK_STENCIL_FACE_BACK_BIT = 0x00000002,
+ VK_STENCIL_FRONT_AND_BACK = 0x00000003,
+ VK_STENCIL_FACE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
+} VkStencilFaceFlagBits;
+typedef VkFlags VkStencilFaceFlags;
+
+typedef struct VkApplicationInfo {
+ VkStructureType sType;
+ const void* pNext;
+ const char* pApplicationName;
+ uint32_t applicationVersion;
+ const char* pEngineName;
+ uint32_t engineVersion;
+ uint32_t apiVersion;
+} VkApplicationInfo;
+
+typedef struct VkInstanceCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkInstanceCreateFlags flags;
+ const VkApplicationInfo* pApplicationInfo;
+ uint32_t enabledLayerCount;
+ const char* const* ppEnabledLayerNames;
+ uint32_t enabledExtensionCount;
+ const char* const* ppEnabledExtensionNames;
+} VkInstanceCreateInfo;
+
+typedef void* (VKAPI_PTR *PFN_vkAllocationFunction)(
+ void* pUserData,
+ size_t size,
+ size_t alignment,
+ VkSystemAllocationScope allocationScope);
+
+typedef void* (VKAPI_PTR *PFN_vkReallocationFunction)(
+ void* pUserData,
+ void* pOriginal,
+ size_t size,
+ size_t alignment,
+ VkSystemAllocationScope allocationScope);
+
+typedef void (VKAPI_PTR *PFN_vkFreeFunction)(
+ void* pUserData,
+ void* pMemory);
+
+typedef void (VKAPI_PTR *PFN_vkInternalAllocationNotification)(
+ void* pUserData,
+ size_t size,
+ VkInternalAllocationType allocationType,
+ VkSystemAllocationScope allocationScope);
+
+typedef void (VKAPI_PTR *PFN_vkInternalFreeNotification)(
+ void* pUserData,
+ size_t size,
+ VkInternalAllocationType allocationType,
+ VkSystemAllocationScope allocationScope);
+
+typedef struct VkAllocationCallbacks {
+ void* pUserData;
+ PFN_vkAllocationFunction pfnAllocation;
+ PFN_vkReallocationFunction pfnReallocation;
+ PFN_vkFreeFunction pfnFree;
+ PFN_vkInternalAllocationNotification pfnInternalAllocation;
+ PFN_vkInternalFreeNotification pfnInternalFree;
+} VkAllocationCallbacks;
+
+typedef struct VkPhysicalDeviceFeatures {
+ VkBool32 robustBufferAccess;
+ VkBool32 fullDrawIndexUint32;
+ VkBool32 imageCubeArray;
+ VkBool32 independentBlend;
+ VkBool32 geometryShader;
+ VkBool32 tessellationShader;
+ VkBool32 sampleRateShading;
+ VkBool32 dualSrcBlend;
+ VkBool32 logicOp;
+ VkBool32 multiDrawIndirect;
+ VkBool32 drawIndirectFirstInstance;
+ VkBool32 depthClamp;
+ VkBool32 depthBiasClamp;
+ VkBool32 fillModeNonSolid;
+ VkBool32 depthBounds;
+ VkBool32 wideLines;
+ VkBool32 largePoints;
+ VkBool32 alphaToOne;
+ VkBool32 multiViewport;
+ VkBool32 samplerAnisotropy;
+ VkBool32 textureCompressionETC2;
+ VkBool32 textureCompressionASTC_LDR;
+ VkBool32 textureCompressionBC;
+ VkBool32 occlusionQueryPrecise;
+ VkBool32 pipelineStatisticsQuery;
+ VkBool32 vertexPipelineStoresAndAtomics;
+ VkBool32 fragmentStoresAndAtomics;
+ VkBool32 shaderTessellationAndGeometryPointSize;
+ VkBool32 shaderImageGatherExtended;
+ VkBool32 shaderStorageImageExtendedFormats;
+ VkBool32 shaderStorageImageMultisample;
+ VkBool32 shaderStorageImageReadWithoutFormat;
+ VkBool32 shaderStorageImageWriteWithoutFormat;
+ VkBool32 shaderUniformBufferArrayDynamicIndexing;
+ VkBool32 shaderSampledImageArrayDynamicIndexing;
+ VkBool32 shaderStorageBufferArrayDynamicIndexing;
+ VkBool32 shaderStorageImageArrayDynamicIndexing;
+ VkBool32 shaderClipDistance;
+ VkBool32 shaderCullDistance;
+ VkBool32 shaderFloat64;
+ VkBool32 shaderInt64;
+ VkBool32 shaderInt16;
+ VkBool32 shaderResourceResidency;
+ VkBool32 shaderResourceMinLod;
+ VkBool32 sparseBinding;
+ VkBool32 sparseResidencyBuffer;
+ VkBool32 sparseResidencyImage2D;
+ VkBool32 sparseResidencyImage3D;
+ VkBool32 sparseResidency2Samples;
+ VkBool32 sparseResidency4Samples;
+ VkBool32 sparseResidency8Samples;
+ VkBool32 sparseResidency16Samples;
+ VkBool32 sparseResidencyAliased;
+ VkBool32 variableMultisampleRate;
+ VkBool32 inheritedQueries;
+} VkPhysicalDeviceFeatures;
+
+typedef struct VkFormatProperties {
+ VkFormatFeatureFlags linearTilingFeatures;
+ VkFormatFeatureFlags optimalTilingFeatures;
+ VkFormatFeatureFlags bufferFeatures;
+} VkFormatProperties;
+
+typedef struct VkExtent3D {
+ uint32_t width;
+ uint32_t height;
+ uint32_t depth;
+} VkExtent3D;
+
+typedef struct VkImageFormatProperties {
+ VkExtent3D maxExtent;
+ uint32_t maxMipLevels;
+ uint32_t maxArrayLayers;
+ VkSampleCountFlags sampleCounts;
+ VkDeviceSize maxResourceSize;
+} VkImageFormatProperties;
+
+typedef struct VkPhysicalDeviceLimits {
+ uint32_t maxImageDimension1D;
+ uint32_t maxImageDimension2D;
+ uint32_t maxImageDimension3D;
+ uint32_t maxImageDimensionCube;
+ uint32_t maxImageArrayLayers;
+ uint32_t maxTexelBufferElements;
+ uint32_t maxUniformBufferRange;
+ uint32_t maxStorageBufferRange;
+ uint32_t maxPushConstantsSize;
+ uint32_t maxMemoryAllocationCount;
+ uint32_t maxSamplerAllocationCount;
+ VkDeviceSize bufferImageGranularity;
+ VkDeviceSize sparseAddressSpaceSize;
+ uint32_t maxBoundDescriptorSets;
+ uint32_t maxPerStageDescriptorSamplers;
+ uint32_t maxPerStageDescriptorUniformBuffers;
+ uint32_t maxPerStageDescriptorStorageBuffers;
+ uint32_t maxPerStageDescriptorSampledImages;
+ uint32_t maxPerStageDescriptorStorageImages;
+ uint32_t maxPerStageDescriptorInputAttachments;
+ uint32_t maxPerStageResources;
+ uint32_t maxDescriptorSetSamplers;
+ uint32_t maxDescriptorSetUniformBuffers;
+ uint32_t maxDescriptorSetUniformBuffersDynamic;
+ uint32_t maxDescriptorSetStorageBuffers;
+ uint32_t maxDescriptorSetStorageBuffersDynamic;
+ uint32_t maxDescriptorSetSampledImages;
+ uint32_t maxDescriptorSetStorageImages;
+ uint32_t maxDescriptorSetInputAttachments;
+ uint32_t maxVertexInputAttributes;
+ uint32_t maxVertexInputBindings;
+ uint32_t maxVertexInputAttributeOffset;
+ uint32_t maxVertexInputBindingStride;
+ uint32_t maxVertexOutputComponents;
+ uint32_t maxTessellationGenerationLevel;
+ uint32_t maxTessellationPatchSize;
+ uint32_t maxTessellationControlPerVertexInputComponents;
+ uint32_t maxTessellationControlPerVertexOutputComponents;
+ uint32_t maxTessellationControlPerPatchOutputComponents;
+ uint32_t maxTessellationControlTotalOutputComponents;
+ uint32_t maxTessellationEvaluationInputComponents;
+ uint32_t maxTessellationEvaluationOutputComponents;
+ uint32_t maxGeometryShaderInvocations;
+ uint32_t maxGeometryInputComponents;
+ uint32_t maxGeometryOutputComponents;
+ uint32_t maxGeometryOutputVertices;
+ uint32_t maxGeometryTotalOutputComponents;
+ uint32_t maxFragmentInputComponents;
+ uint32_t maxFragmentOutputAttachments;
+ uint32_t maxFragmentDualSrcAttachments;
+ uint32_t maxFragmentCombinedOutputResources;
+ uint32_t maxComputeSharedMemorySize;
+ uint32_t maxComputeWorkGroupCount[3];
+ uint32_t maxComputeWorkGroupInvocations;
+ uint32_t maxComputeWorkGroupSize[3];
+ uint32_t subPixelPrecisionBits;
+ uint32_t subTexelPrecisionBits;
+ uint32_t mipmapPrecisionBits;
+ uint32_t maxDrawIndexedIndexValue;
+ uint32_t maxDrawIndirectCount;
+ float maxSamplerLodBias;
+ float maxSamplerAnisotropy;
+ uint32_t maxViewports;
+ uint32_t maxViewportDimensions[2];
+ float viewportBoundsRange[2];
+ uint32_t viewportSubPixelBits;
+ size_t minMemoryMapAlignment;
+ VkDeviceSize minTexelBufferOffsetAlignment;
+ VkDeviceSize minUniformBufferOffsetAlignment;
+ VkDeviceSize minStorageBufferOffsetAlignment;
+ int32_t minTexelOffset;
+ uint32_t maxTexelOffset;
+ int32_t minTexelGatherOffset;
+ uint32_t maxTexelGatherOffset;
+ float minInterpolationOffset;
+ float maxInterpolationOffset;
+ uint32_t subPixelInterpolationOffsetBits;
+ uint32_t maxFramebufferWidth;
+ uint32_t maxFramebufferHeight;
+ uint32_t maxFramebufferLayers;
+ VkSampleCountFlags framebufferColorSampleCounts;
+ VkSampleCountFlags framebufferDepthSampleCounts;
+ VkSampleCountFlags framebufferStencilSampleCounts;
+ VkSampleCountFlags framebufferNoAttachmentsSampleCounts;
+ uint32_t maxColorAttachments;
+ VkSampleCountFlags sampledImageColorSampleCounts;
+ VkSampleCountFlags sampledImageIntegerSampleCounts;
+ VkSampleCountFlags sampledImageDepthSampleCounts;
+ VkSampleCountFlags sampledImageStencilSampleCounts;
+ VkSampleCountFlags storageImageSampleCounts;
+ uint32_t maxSampleMaskWords;
+ VkBool32 timestampComputeAndGraphics;
+ float timestampPeriod;
+ uint32_t maxClipDistances;
+ uint32_t maxCullDistances;
+ uint32_t maxCombinedClipAndCullDistances;
+ uint32_t discreteQueuePriorities;
+ float pointSizeRange[2];
+ float lineWidthRange[2];
+ float pointSizeGranularity;
+ float lineWidthGranularity;
+ VkBool32 strictLines;
+ VkBool32 standardSampleLocations;
+ VkDeviceSize optimalBufferCopyOffsetAlignment;
+ VkDeviceSize optimalBufferCopyRowPitchAlignment;
+ VkDeviceSize nonCoherentAtomSize;
+} VkPhysicalDeviceLimits;
+
+typedef struct VkPhysicalDeviceSparseProperties {
+ VkBool32 residencyStandard2DBlockShape;
+ VkBool32 residencyStandard2DMultisampleBlockShape;
+ VkBool32 residencyStandard3DBlockShape;
+ VkBool32 residencyAlignedMipSize;
+ VkBool32 residencyNonResidentStrict;
+} VkPhysicalDeviceSparseProperties;
+
+typedef struct VkPhysicalDeviceProperties {
+ uint32_t apiVersion;
+ uint32_t driverVersion;
+ uint32_t vendorID;
+ uint32_t deviceID;
+ VkPhysicalDeviceType deviceType;
+ char deviceName[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE];
+ uint8_t pipelineCacheUUID[VK_UUID_SIZE];
+ VkPhysicalDeviceLimits limits;
+ VkPhysicalDeviceSparseProperties sparseProperties;
+} VkPhysicalDeviceProperties;
+
+typedef struct VkQueueFamilyProperties {
+ VkQueueFlags queueFlags;
+ uint32_t queueCount;
+ uint32_t timestampValidBits;
+ VkExtent3D minImageTransferGranularity;
+} VkQueueFamilyProperties;
+
+typedef struct VkMemoryType {
+ VkMemoryPropertyFlags propertyFlags;
+ uint32_t heapIndex;
+} VkMemoryType;
+
+typedef struct VkMemoryHeap {
+ VkDeviceSize size;
+ VkMemoryHeapFlags flags;
+} VkMemoryHeap;
+
+typedef struct VkPhysicalDeviceMemoryProperties {
+ uint32_t memoryTypeCount;
+ VkMemoryType memoryTypes[VK_MAX_MEMORY_TYPES];
+ uint32_t memoryHeapCount;
+ VkMemoryHeap memoryHeaps[VK_MAX_MEMORY_HEAPS];
+} VkPhysicalDeviceMemoryProperties;
+
+typedef void (VKAPI_PTR *PFN_vkVoidFunction)(void);
+typedef struct VkDeviceQueueCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkDeviceQueueCreateFlags flags;
+ uint32_t queueFamilyIndex;
+ uint32_t queueCount;
+ const float* pQueuePriorities;
+} VkDeviceQueueCreateInfo;
+
+typedef struct VkDeviceCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkDeviceCreateFlags flags;
+ uint32_t queueCreateInfoCount;
+ const VkDeviceQueueCreateInfo* pQueueCreateInfos;
+ uint32_t enabledLayerCount;
+ const char* const* ppEnabledLayerNames;
+ uint32_t enabledExtensionCount;
+ const char* const* ppEnabledExtensionNames;
+ const VkPhysicalDeviceFeatures* pEnabledFeatures;
+} VkDeviceCreateInfo;
+
+typedef struct VkExtensionProperties {
+ char extensionName[VK_MAX_EXTENSION_NAME_SIZE];
+ uint32_t specVersion;
+} VkExtensionProperties;
+
+typedef struct VkLayerProperties {
+ char layerName[VK_MAX_EXTENSION_NAME_SIZE];
+ uint32_t specVersion;
+ uint32_t implementationVersion;
+ char description[VK_MAX_DESCRIPTION_SIZE];
+} VkLayerProperties;
+
+typedef struct VkSubmitInfo {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t waitSemaphoreCount;
+ const VkSemaphore* pWaitSemaphores;
+ const VkPipelineStageFlags* pWaitDstStageMask;
+ uint32_t commandBufferCount;
+ const VkCommandBuffer* pCommandBuffers;
+ uint32_t signalSemaphoreCount;
+ const VkSemaphore* pSignalSemaphores;
+} VkSubmitInfo;
+
+typedef struct VkMemoryAllocateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkDeviceSize allocationSize;
+ uint32_t memoryTypeIndex;
+} VkMemoryAllocateInfo;
+
+typedef struct VkMappedMemoryRange {
+ VkStructureType sType;
+ const void* pNext;
+ VkDeviceMemory memory;
+ VkDeviceSize offset;
+ VkDeviceSize size;
+} VkMappedMemoryRange;
+
+typedef struct VkMemoryRequirements {
+ VkDeviceSize size;
+ VkDeviceSize alignment;
+ uint32_t memoryTypeBits;
+} VkMemoryRequirements;
+
+typedef struct VkSparseImageFormatProperties {
+ VkImageAspectFlags aspectMask;
+ VkExtent3D imageGranularity;
+ VkSparseImageFormatFlags flags;
+} VkSparseImageFormatProperties;
+
+typedef struct VkSparseImageMemoryRequirements {
+ VkSparseImageFormatProperties formatProperties;
+ uint32_t imageMipTailFirstLod;
+ VkDeviceSize imageMipTailSize;
+ VkDeviceSize imageMipTailOffset;
+ VkDeviceSize imageMipTailStride;
+} VkSparseImageMemoryRequirements;
+
+typedef struct VkSparseMemoryBind {
+ VkDeviceSize resourceOffset;
+ VkDeviceSize size;
+ VkDeviceMemory memory;
+ VkDeviceSize memoryOffset;
+ VkSparseMemoryBindFlags flags;
+} VkSparseMemoryBind;
+
+typedef struct VkSparseBufferMemoryBindInfo {
+ VkBuffer buffer;
+ uint32_t bindCount;
+ const VkSparseMemoryBind* pBinds;
+} VkSparseBufferMemoryBindInfo;
+
+typedef struct VkSparseImageOpaqueMemoryBindInfo {
+ VkImage image;
+ uint32_t bindCount;
+ const VkSparseMemoryBind* pBinds;
+} VkSparseImageOpaqueMemoryBindInfo;
+
+typedef struct VkImageSubresource {
+ VkImageAspectFlags aspectMask;
+ uint32_t mipLevel;
+ uint32_t arrayLayer;
+} VkImageSubresource;
+
+typedef struct VkOffset3D {
+ int32_t x;
+ int32_t y;
+ int32_t z;
+} VkOffset3D;
+
+typedef struct VkSparseImageMemoryBind {
+ VkImageSubresource subresource;
+ VkOffset3D offset;
+ VkExtent3D extent;
+ VkDeviceMemory memory;
+ VkDeviceSize memoryOffset;
+ VkSparseMemoryBindFlags flags;
+} VkSparseImageMemoryBind;
+
+typedef struct VkSparseImageMemoryBindInfo {
+ VkImage image;
+ uint32_t bindCount;
+ const VkSparseImageMemoryBind* pBinds;
+} VkSparseImageMemoryBindInfo;
+
+typedef struct VkBindSparseInfo {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t waitSemaphoreCount;
+ const VkSemaphore* pWaitSemaphores;
+ uint32_t bufferBindCount;
+ const VkSparseBufferMemoryBindInfo* pBufferBinds;
+ uint32_t imageOpaqueBindCount;
+ const VkSparseImageOpaqueMemoryBindInfo* pImageOpaqueBinds;
+ uint32_t imageBindCount;
+ const VkSparseImageMemoryBindInfo* pImageBinds;
+ uint32_t signalSemaphoreCount;
+ const VkSemaphore* pSignalSemaphores;
+} VkBindSparseInfo;
+
+typedef struct VkFenceCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkFenceCreateFlags flags;
+} VkFenceCreateInfo;
+
+typedef struct VkSemaphoreCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkSemaphoreCreateFlags flags;
+} VkSemaphoreCreateInfo;
+
+typedef struct VkEventCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkEventCreateFlags flags;
+} VkEventCreateInfo;
+
+typedef struct VkQueryPoolCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkQueryPoolCreateFlags flags;
+ VkQueryType queryType;
+ uint32_t queryCount;
+ VkQueryPipelineStatisticFlags pipelineStatistics;
+} VkQueryPoolCreateInfo;
+
+typedef struct VkBufferCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkBufferCreateFlags flags;
+ VkDeviceSize size;
+ VkBufferUsageFlags usage;
+ VkSharingMode sharingMode;
+ uint32_t queueFamilyIndexCount;
+ const uint32_t* pQueueFamilyIndices;
+} VkBufferCreateInfo;
+
+typedef struct VkBufferViewCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkBufferViewCreateFlags flags;
+ VkBuffer buffer;
+ VkFormat format;
+ VkDeviceSize offset;
+ VkDeviceSize range;
+} VkBufferViewCreateInfo;
+
+typedef struct VkImageCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkImageCreateFlags flags;
+ VkImageType imageType;
+ VkFormat format;
+ VkExtent3D extent;
+ uint32_t mipLevels;
+ uint32_t arrayLayers;
+ VkSampleCountFlagBits samples;
+ VkImageTiling tiling;
+ VkImageUsageFlags usage;
+ VkSharingMode sharingMode;
+ uint32_t queueFamilyIndexCount;
+ const uint32_t* pQueueFamilyIndices;
+ VkImageLayout initialLayout;
+} VkImageCreateInfo;
+
+typedef struct VkSubresourceLayout {
+ VkDeviceSize offset;
+ VkDeviceSize size;
+ VkDeviceSize rowPitch;
+ VkDeviceSize arrayPitch;
+ VkDeviceSize depthPitch;
+} VkSubresourceLayout;
+
+typedef struct VkComponentMapping {
+ VkComponentSwizzle r;
+ VkComponentSwizzle g;
+ VkComponentSwizzle b;
+ VkComponentSwizzle a;
+} VkComponentMapping;
+
+typedef struct VkImageSubresourceRange {
+ VkImageAspectFlags aspectMask;
+ uint32_t baseMipLevel;
+ uint32_t levelCount;
+ uint32_t baseArrayLayer;
+ uint32_t layerCount;
+} VkImageSubresourceRange;
+
+typedef struct VkImageViewCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkImageViewCreateFlags flags;
+ VkImage image;
+ VkImageViewType viewType;
+ VkFormat format;
+ VkComponentMapping components;
+ VkImageSubresourceRange subresourceRange;
+} VkImageViewCreateInfo;
+
+typedef struct VkShaderModuleCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkShaderModuleCreateFlags flags;
+ size_t codeSize;
+ const uint32_t* pCode;
+} VkShaderModuleCreateInfo;
+
+typedef struct VkPipelineCacheCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineCacheCreateFlags flags;
+ size_t initialDataSize;
+ const void* pInitialData;
+} VkPipelineCacheCreateInfo;
+
+typedef struct VkSpecializationMapEntry {
+ uint32_t constantID;
+ uint32_t offset;
+ size_t size;
+} VkSpecializationMapEntry;
+
+typedef struct VkSpecializationInfo {
+ uint32_t mapEntryCount;
+ const VkSpecializationMapEntry* pMapEntries;
+ size_t dataSize;
+ const void* pData;
+} VkSpecializationInfo;
+
+typedef struct VkPipelineShaderStageCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineShaderStageCreateFlags flags;
+ VkShaderStageFlagBits stage;
+ VkShaderModule module;
+ const char* pName;
+ const VkSpecializationInfo* pSpecializationInfo;
+} VkPipelineShaderStageCreateInfo;
+
+typedef struct VkVertexInputBindingDescription {
+ uint32_t binding;
+ uint32_t stride;
+ VkVertexInputRate inputRate;
+} VkVertexInputBindingDescription;
+
+typedef struct VkVertexInputAttributeDescription {
+ uint32_t location;
+ uint32_t binding;
+ VkFormat format;
+ uint32_t offset;
+} VkVertexInputAttributeDescription;
+
+typedef struct VkPipelineVertexInputStateCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineVertexInputStateCreateFlags flags;
+ uint32_t vertexBindingDescriptionCount;
+ const VkVertexInputBindingDescription* pVertexBindingDescriptions;
+ uint32_t vertexAttributeDescriptionCount;
+ const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
+} VkPipelineVertexInputStateCreateInfo;
+
+typedef struct VkPipelineInputAssemblyStateCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineInputAssemblyStateCreateFlags flags;
+ VkPrimitiveTopology topology;
+ VkBool32 primitiveRestartEnable;
+} VkPipelineInputAssemblyStateCreateInfo;
+
+typedef struct VkPipelineTessellationStateCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineTessellationStateCreateFlags flags;
+ uint32_t patchControlPoints;
+} VkPipelineTessellationStateCreateInfo;
+
+typedef struct VkViewport {
+ float x;
+ float y;
+ float width;
+ float height;
+ float minDepth;
+ float maxDepth;
+} VkViewport;
+
+typedef struct VkOffset2D {
+ int32_t x;
+ int32_t y;
+} VkOffset2D;
+
+typedef struct VkExtent2D {
+ uint32_t width;
+ uint32_t height;
+} VkExtent2D;
+
+typedef struct VkRect2D {
+ VkOffset2D offset;
+ VkExtent2D extent;
+} VkRect2D;
+
+typedef struct VkPipelineViewportStateCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineViewportStateCreateFlags flags;
+ uint32_t viewportCount;
+ const VkViewport* pViewports;
+ uint32_t scissorCount;
+ const VkRect2D* pScissors;
+} VkPipelineViewportStateCreateInfo;
+
+typedef struct VkPipelineRasterizationStateCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineRasterizationStateCreateFlags flags;
+ VkBool32 depthClampEnable;
+ VkBool32 rasterizerDiscardEnable;
+ VkPolygonMode polygonMode;
+ VkCullModeFlags cullMode;
+ VkFrontFace frontFace;
+ VkBool32 depthBiasEnable;
+ float depthBiasConstantFactor;
+ float depthBiasClamp;
+ float depthBiasSlopeFactor;
+ float lineWidth;
+} VkPipelineRasterizationStateCreateInfo;
+
+typedef struct VkPipelineMultisampleStateCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineMultisampleStateCreateFlags flags;
+ VkSampleCountFlagBits rasterizationSamples;
+ VkBool32 sampleShadingEnable;
+ float minSampleShading;
+ const VkSampleMask* pSampleMask;
+ VkBool32 alphaToCoverageEnable;
+ VkBool32 alphaToOneEnable;
+} VkPipelineMultisampleStateCreateInfo;
+
+typedef struct VkStencilOpState {
+ VkStencilOp failOp;
+ VkStencilOp passOp;
+ VkStencilOp depthFailOp;
+ VkCompareOp compareOp;
+ uint32_t compareMask;
+ uint32_t writeMask;
+ uint32_t reference;
+} VkStencilOpState;
+
+typedef struct VkPipelineDepthStencilStateCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineDepthStencilStateCreateFlags flags;
+ VkBool32 depthTestEnable;
+ VkBool32 depthWriteEnable;
+ VkCompareOp depthCompareOp;
+ VkBool32 depthBoundsTestEnable;
+ VkBool32 stencilTestEnable;
+ VkStencilOpState front;
+ VkStencilOpState back;
+ float minDepthBounds;
+ float maxDepthBounds;
+} VkPipelineDepthStencilStateCreateInfo;
+
+typedef struct VkPipelineColorBlendAttachmentState {
+ VkBool32 blendEnable;
+ VkBlendFactor srcColorBlendFactor;
+ VkBlendFactor dstColorBlendFactor;
+ VkBlendOp colorBlendOp;
+ VkBlendFactor srcAlphaBlendFactor;
+ VkBlendFactor dstAlphaBlendFactor;
+ VkBlendOp alphaBlendOp;
+ VkColorComponentFlags colorWriteMask;
+} VkPipelineColorBlendAttachmentState;
+
+typedef struct VkPipelineColorBlendStateCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineColorBlendStateCreateFlags flags;
+ VkBool32 logicOpEnable;
+ VkLogicOp logicOp;
+ uint32_t attachmentCount;
+ const VkPipelineColorBlendAttachmentState* pAttachments;
+ float blendConstants[4];
+} VkPipelineColorBlendStateCreateInfo;
+
+typedef struct VkPipelineDynamicStateCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineDynamicStateCreateFlags flags;
+ uint32_t dynamicStateCount;
+ const VkDynamicState* pDynamicStates;
+} VkPipelineDynamicStateCreateInfo;
+
+typedef struct VkGraphicsPipelineCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineCreateFlags flags;
+ uint32_t stageCount;
+ const VkPipelineShaderStageCreateInfo* pStages;
+ const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
+ const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
+ const VkPipelineTessellationStateCreateInfo* pTessellationState;
+ const VkPipelineViewportStateCreateInfo* pViewportState;
+ const VkPipelineRasterizationStateCreateInfo* pRasterizationState;
+ const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
+ const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
+ const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
+ const VkPipelineDynamicStateCreateInfo* pDynamicState;
+ VkPipelineLayout layout;
+ VkRenderPass renderPass;
+ uint32_t subpass;
+ VkPipeline basePipelineHandle;
+ int32_t basePipelineIndex;
+} VkGraphicsPipelineCreateInfo;
+
+typedef struct VkComputePipelineCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineCreateFlags flags;
+ VkPipelineShaderStageCreateInfo stage;
+ VkPipelineLayout layout;
+ VkPipeline basePipelineHandle;
+ int32_t basePipelineIndex;
+} VkComputePipelineCreateInfo;
+
+typedef struct VkPushConstantRange {
+ VkShaderStageFlags stageFlags;
+ uint32_t offset;
+ uint32_t size;
+} VkPushConstantRange;
+
+typedef struct VkPipelineLayoutCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineLayoutCreateFlags flags;
+ uint32_t setLayoutCount;
+ const VkDescriptorSetLayout* pSetLayouts;
+ uint32_t pushConstantRangeCount;
+ const VkPushConstantRange* pPushConstantRanges;
+} VkPipelineLayoutCreateInfo;
+
+typedef struct VkSamplerCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkSamplerCreateFlags flags;
+ VkFilter magFilter;
+ VkFilter minFilter;
+ VkSamplerMipmapMode mipmapMode;
+ VkSamplerAddressMode addressModeU;
+ VkSamplerAddressMode addressModeV;
+ VkSamplerAddressMode addressModeW;
+ float mipLodBias;
+ VkBool32 anisotropyEnable;
+ float maxAnisotropy;
+ VkBool32 compareEnable;
+ VkCompareOp compareOp;
+ float minLod;
+ float maxLod;
+ VkBorderColor borderColor;
+ VkBool32 unnormalizedCoordinates;
+} VkSamplerCreateInfo;
+
+typedef struct VkDescriptorSetLayoutBinding {
+ uint32_t binding;
+ VkDescriptorType descriptorType;
+ uint32_t descriptorCount;
+ VkShaderStageFlags stageFlags;
+ const VkSampler* pImmutableSamplers;
+} VkDescriptorSetLayoutBinding;
+
+typedef struct VkDescriptorSetLayoutCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkDescriptorSetLayoutCreateFlags flags;
+ uint32_t bindingCount;
+ const VkDescriptorSetLayoutBinding* pBindings;
+} VkDescriptorSetLayoutCreateInfo;
+
+typedef struct VkDescriptorPoolSize {
+ VkDescriptorType type;
+ uint32_t descriptorCount;
+} VkDescriptorPoolSize;
+
+typedef struct VkDescriptorPoolCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkDescriptorPoolCreateFlags flags;
+ uint32_t maxSets;
+ uint32_t poolSizeCount;
+ const VkDescriptorPoolSize* pPoolSizes;
+} VkDescriptorPoolCreateInfo;
+
+typedef struct VkDescriptorSetAllocateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkDescriptorPool descriptorPool;
+ uint32_t descriptorSetCount;
+ const VkDescriptorSetLayout* pSetLayouts;
+} VkDescriptorSetAllocateInfo;
+
+typedef struct VkDescriptorImageInfo {
+ VkSampler sampler;
+ VkImageView imageView;
+ VkImageLayout imageLayout;
+} VkDescriptorImageInfo;
+
+typedef struct VkDescriptorBufferInfo {
+ VkBuffer buffer;
+ VkDeviceSize offset;
+ VkDeviceSize range;
+} VkDescriptorBufferInfo;
+
+typedef struct VkWriteDescriptorSet {
+ VkStructureType sType;
+ const void* pNext;
+ VkDescriptorSet dstSet;
+ uint32_t dstBinding;
+ uint32_t dstArrayElement;
+ uint32_t descriptorCount;
+ VkDescriptorType descriptorType;
+ const VkDescriptorImageInfo* pImageInfo;
+ const VkDescriptorBufferInfo* pBufferInfo;
+ const VkBufferView* pTexelBufferView;
+} VkWriteDescriptorSet;
+
+typedef struct VkCopyDescriptorSet {
+ VkStructureType sType;
+ const void* pNext;
+ VkDescriptorSet srcSet;
+ uint32_t srcBinding;
+ uint32_t srcArrayElement;
+ VkDescriptorSet dstSet;
+ uint32_t dstBinding;
+ uint32_t dstArrayElement;
+ uint32_t descriptorCount;
+} VkCopyDescriptorSet;
+
+typedef struct VkFramebufferCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkFramebufferCreateFlags flags;
+ VkRenderPass renderPass;
+ uint32_t attachmentCount;
+ const VkImageView* pAttachments;
+ uint32_t width;
+ uint32_t height;
+ uint32_t layers;
+} VkFramebufferCreateInfo;
+
+typedef struct VkAttachmentDescription {
+ VkAttachmentDescriptionFlags flags;
+ VkFormat format;
+ VkSampleCountFlagBits samples;
+ VkAttachmentLoadOp loadOp;
+ VkAttachmentStoreOp storeOp;
+ VkAttachmentLoadOp stencilLoadOp;
+ VkAttachmentStoreOp stencilStoreOp;
+ VkImageLayout initialLayout;
+ VkImageLayout finalLayout;
+} VkAttachmentDescription;
+
+typedef struct VkAttachmentReference {
+ uint32_t attachment;
+ VkImageLayout layout;
+} VkAttachmentReference;
+
+typedef struct VkSubpassDescription {
+ VkSubpassDescriptionFlags flags;
+ VkPipelineBindPoint pipelineBindPoint;
+ uint32_t inputAttachmentCount;
+ const VkAttachmentReference* pInputAttachments;
+ uint32_t colorAttachmentCount;
+ const VkAttachmentReference* pColorAttachments;
+ const VkAttachmentReference* pResolveAttachments;
+ const VkAttachmentReference* pDepthStencilAttachment;
+ uint32_t preserveAttachmentCount;
+ const uint32_t* pPreserveAttachments;
+} VkSubpassDescription;
+
+typedef struct VkSubpassDependency {
+ uint32_t srcSubpass;
+ uint32_t dstSubpass;
+ VkPipelineStageFlags srcStageMask;
+ VkPipelineStageFlags dstStageMask;
+ VkAccessFlags srcAccessMask;
+ VkAccessFlags dstAccessMask;
+ VkDependencyFlags dependencyFlags;
+} VkSubpassDependency;
+
+typedef struct VkRenderPassCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkRenderPassCreateFlags flags;
+ uint32_t attachmentCount;
+ const VkAttachmentDescription* pAttachments;
+ uint32_t subpassCount;
+ const VkSubpassDescription* pSubpasses;
+ uint32_t dependencyCount;
+ const VkSubpassDependency* pDependencies;
+} VkRenderPassCreateInfo;
+
+typedef struct VkCommandPoolCreateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkCommandPoolCreateFlags flags;
+ uint32_t queueFamilyIndex;
+} VkCommandPoolCreateInfo;
+
+typedef struct VkCommandBufferAllocateInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkCommandPool commandPool;
+ VkCommandBufferLevel level;
+ uint32_t commandBufferCount;
+} VkCommandBufferAllocateInfo;
+
+typedef struct VkCommandBufferInheritanceInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkRenderPass renderPass;
+ uint32_t subpass;
+ VkFramebuffer framebuffer;
+ VkBool32 occlusionQueryEnable;
+ VkQueryControlFlags queryFlags;
+ VkQueryPipelineStatisticFlags pipelineStatistics;
+} VkCommandBufferInheritanceInfo;
+
+typedef struct VkCommandBufferBeginInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkCommandBufferUsageFlags flags;
+ const VkCommandBufferInheritanceInfo* pInheritanceInfo;
+} VkCommandBufferBeginInfo;
+
+typedef struct VkBufferCopy {
+ VkDeviceSize srcOffset;
+ VkDeviceSize dstOffset;
+ VkDeviceSize size;
+} VkBufferCopy;
+
+typedef struct VkImageSubresourceLayers {
+ VkImageAspectFlags aspectMask;
+ uint32_t mipLevel;
+ uint32_t baseArrayLayer;
+ uint32_t layerCount;
+} VkImageSubresourceLayers;
+
+typedef struct VkImageCopy {
+ VkImageSubresourceLayers srcSubresource;
+ VkOffset3D srcOffset;
+ VkImageSubresourceLayers dstSubresource;
+ VkOffset3D dstOffset;
+ VkExtent3D extent;
+} VkImageCopy;
+
+typedef struct VkImageBlit {
+ VkImageSubresourceLayers srcSubresource;
+ VkOffset3D srcOffsets[2];
+ VkImageSubresourceLayers dstSubresource;
+ VkOffset3D dstOffsets[2];
+} VkImageBlit;
+
+typedef struct VkBufferImageCopy {
+ VkDeviceSize bufferOffset;
+ uint32_t bufferRowLength;
+ uint32_t bufferImageHeight;
+ VkImageSubresourceLayers imageSubresource;
+ VkOffset3D imageOffset;
+ VkExtent3D imageExtent;
+} VkBufferImageCopy;
+
+typedef union VkClearColorValue {
+ float float32[4];
+ int32_t int32[4];
+ uint32_t uint32[4];
+} VkClearColorValue;
+
+typedef struct VkClearDepthStencilValue {
+ float depth;
+ uint32_t stencil;
+} VkClearDepthStencilValue;
+
+typedef union VkClearValue {
+ VkClearColorValue color;
+ VkClearDepthStencilValue depthStencil;
+} VkClearValue;
+
+typedef struct VkClearAttachment {
+ VkImageAspectFlags aspectMask;
+ uint32_t colorAttachment;
+ VkClearValue clearValue;
+} VkClearAttachment;
+
+typedef struct VkClearRect {
+ VkRect2D rect;
+ uint32_t baseArrayLayer;
+ uint32_t layerCount;
+} VkClearRect;
+
+typedef struct VkImageResolve {
+ VkImageSubresourceLayers srcSubresource;
+ VkOffset3D srcOffset;
+ VkImageSubresourceLayers dstSubresource;
+ VkOffset3D dstOffset;
+ VkExtent3D extent;
+} VkImageResolve;
+
+typedef struct VkMemoryBarrier {
+ VkStructureType sType;
+ const void* pNext;
+ VkAccessFlags srcAccessMask;
+ VkAccessFlags dstAccessMask;
+} VkMemoryBarrier;
+
+typedef struct VkBufferMemoryBarrier {
+ VkStructureType sType;
+ const void* pNext;
+ VkAccessFlags srcAccessMask;
+ VkAccessFlags dstAccessMask;
+ uint32_t srcQueueFamilyIndex;
+ uint32_t dstQueueFamilyIndex;
+ VkBuffer buffer;
+ VkDeviceSize offset;
+ VkDeviceSize size;
+} VkBufferMemoryBarrier;
+
+typedef struct VkImageMemoryBarrier {
+ VkStructureType sType;
+ const void* pNext;
+ VkAccessFlags srcAccessMask;
+ VkAccessFlags dstAccessMask;
+ VkImageLayout oldLayout;
+ VkImageLayout newLayout;
+ uint32_t srcQueueFamilyIndex;
+ uint32_t dstQueueFamilyIndex;
+ VkImage image;
+ VkImageSubresourceRange subresourceRange;
+} VkImageMemoryBarrier;
+
+typedef struct VkRenderPassBeginInfo {
+ VkStructureType sType;
+ const void* pNext;
+ VkRenderPass renderPass;
+ VkFramebuffer framebuffer;
+ VkRect2D renderArea;
+ uint32_t clearValueCount;
+ const VkClearValue* pClearValues;
+} VkRenderPassBeginInfo;
+
+typedef struct VkDispatchIndirectCommand {
+ uint32_t x;
+ uint32_t y;
+ uint32_t z;
+} VkDispatchIndirectCommand;
+
+typedef struct VkDrawIndexedIndirectCommand {
+ uint32_t indexCount;
+ uint32_t instanceCount;
+ uint32_t firstIndex;
+ int32_t vertexOffset;
+ uint32_t firstInstance;
+} VkDrawIndexedIndirectCommand;
+
+typedef struct VkDrawIndirectCommand {
+ uint32_t vertexCount;
+ uint32_t instanceCount;
+ uint32_t firstVertex;
+ uint32_t firstInstance;
+} VkDrawIndirectCommand;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkCreateInstance)(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance);
+typedef void (VKAPI_PTR *PFN_vkDestroyInstance)(VkInstance instance, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkEnumeratePhysicalDevices)(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices);
+typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceFeatures)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures);
+typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceFormatProperties)(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties);
+typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceImageFormatProperties)(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties);
+typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceProperties)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties);
+typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceQueueFamilyProperties)(VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties* pQueueFamilyProperties);
+typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceMemoryProperties)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties);
+typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_vkGetInstanceProcAddr)(VkInstance instance, const char* pName);
+typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_vkGetDeviceProcAddr)(VkDevice device, const char* pName);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateDevice)(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice);
+typedef void (VKAPI_PTR *PFN_vkDestroyDevice)(VkDevice device, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkEnumerateInstanceExtensionProperties)(const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties);
+typedef VkResult (VKAPI_PTR *PFN_vkEnumerateDeviceExtensionProperties)(VkPhysicalDevice physicalDevice, const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties);
+typedef VkResult (VKAPI_PTR *PFN_vkEnumerateInstanceLayerProperties)(uint32_t* pPropertyCount, VkLayerProperties* pProperties);
+typedef VkResult (VKAPI_PTR *PFN_vkEnumerateDeviceLayerProperties)(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkLayerProperties* pProperties);
+typedef void (VKAPI_PTR *PFN_vkGetDeviceQueue)(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue);
+typedef VkResult (VKAPI_PTR *PFN_vkQueueSubmit)(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence);
+typedef VkResult (VKAPI_PTR *PFN_vkQueueWaitIdle)(VkQueue queue);
+typedef VkResult (VKAPI_PTR *PFN_vkDeviceWaitIdle)(VkDevice device);
+typedef VkResult (VKAPI_PTR *PFN_vkAllocateMemory)(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory);
+typedef void (VKAPI_PTR *PFN_vkFreeMemory)(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkMapMemory)(VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags, void** ppData);
+typedef void (VKAPI_PTR *PFN_vkUnmapMemory)(VkDevice device, VkDeviceMemory memory);
+typedef VkResult (VKAPI_PTR *PFN_vkFlushMappedMemoryRanges)(VkDevice device, uint32_t memoryRangeCount, const VkMappedMemoryRange* pMemoryRanges);
+typedef VkResult (VKAPI_PTR *PFN_vkInvalidateMappedMemoryRanges)(VkDevice device, uint32_t memoryRangeCount, const VkMappedMemoryRange* pMemoryRanges);
+typedef void (VKAPI_PTR *PFN_vkGetDeviceMemoryCommitment)(VkDevice device, VkDeviceMemory memory, VkDeviceSize* pCommittedMemoryInBytes);
+typedef VkResult (VKAPI_PTR *PFN_vkBindBufferMemory)(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, VkDeviceSize memoryOffset);
+typedef VkResult (VKAPI_PTR *PFN_vkBindImageMemory)(VkDevice device, VkImage image, VkDeviceMemory memory, VkDeviceSize memoryOffset);
+typedef void (VKAPI_PTR *PFN_vkGetBufferMemoryRequirements)(VkDevice device, VkBuffer buffer, VkMemoryRequirements* pMemoryRequirements);
+typedef void (VKAPI_PTR *PFN_vkGetImageMemoryRequirements)(VkDevice device, VkImage image, VkMemoryRequirements* pMemoryRequirements);
+typedef void (VKAPI_PTR *PFN_vkGetImageSparseMemoryRequirements)(VkDevice device, VkImage image, uint32_t* pSparseMemoryRequirementCount, VkSparseImageMemoryRequirements* pSparseMemoryRequirements);
+typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceSparseImageFormatProperties)(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pPropertyCount, VkSparseImageFormatProperties* pProperties);
+typedef VkResult (VKAPI_PTR *PFN_vkQueueBindSparse)(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, VkFence fence);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateFence)(VkDevice device, const VkFenceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence);
+typedef void (VKAPI_PTR *PFN_vkDestroyFence)(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkResetFences)(VkDevice device, uint32_t fenceCount, const VkFence* pFences);
+typedef VkResult (VKAPI_PTR *PFN_vkGetFenceStatus)(VkDevice device, VkFence fence);
+typedef VkResult (VKAPI_PTR *PFN_vkWaitForFences)(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateSemaphore)(VkDevice device, const VkSemaphoreCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSemaphore* pSemaphore);
+typedef void (VKAPI_PTR *PFN_vkDestroySemaphore)(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateEvent)(VkDevice device, const VkEventCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkEvent* pEvent);
+typedef void (VKAPI_PTR *PFN_vkDestroyEvent)(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkGetEventStatus)(VkDevice device, VkEvent event);
+typedef VkResult (VKAPI_PTR *PFN_vkSetEvent)(VkDevice device, VkEvent event);
+typedef VkResult (VKAPI_PTR *PFN_vkResetEvent)(VkDevice device, VkEvent event);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateQueryPool)(VkDevice device, const VkQueryPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkQueryPool* pQueryPool);
+typedef void (VKAPI_PTR *PFN_vkDestroyQueryPool)(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkGetQueryPoolResults)(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount, size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateBuffer)(VkDevice device, const VkBufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer);
+typedef void (VKAPI_PTR *PFN_vkDestroyBuffer)(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateBufferView)(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBufferView* pView);
+typedef void (VKAPI_PTR *PFN_vkDestroyBufferView)(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateImage)(VkDevice device, const VkImageCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImage* pImage);
+typedef void (VKAPI_PTR *PFN_vkDestroyImage)(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator);
+typedef void (VKAPI_PTR *PFN_vkGetImageSubresourceLayout)(VkDevice device, VkImage image, const VkImageSubresource* pSubresource, VkSubresourceLayout* pLayout);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateImageView)(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImageView* pView);
+typedef void (VKAPI_PTR *PFN_vkDestroyImageView)(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateShaderModule)(VkDevice device, const VkShaderModuleCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule);
+typedef void (VKAPI_PTR *PFN_vkDestroyShaderModule)(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkCreatePipelineCache)(VkDevice device, const VkPipelineCacheCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineCache* pPipelineCache);
+typedef void (VKAPI_PTR *PFN_vkDestroyPipelineCache)(VkDevice device, VkPipelineCache pipelineCache, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkGetPipelineCacheData)(VkDevice device, VkPipelineCache pipelineCache, size_t* pDataSize, void* pData);
+typedef VkResult (VKAPI_PTR *PFN_vkMergePipelineCaches)(VkDevice device, VkPipelineCache dstCache, uint32_t srcCacheCount, const VkPipelineCache* pSrcCaches);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateGraphicsPipelines)(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, const VkGraphicsPipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateComputePipelines)(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, const VkComputePipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines);
+typedef void (VKAPI_PTR *PFN_vkDestroyPipeline)(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkCreatePipelineLayout)(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout);
+typedef void (VKAPI_PTR *PFN_vkDestroyPipelineLayout)(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateSampler)(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSampler* pSampler);
+typedef void (VKAPI_PTR *PFN_vkDestroySampler)(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateDescriptorSetLayout)(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorSetLayout* pSetLayout);
+typedef void (VKAPI_PTR *PFN_vkDestroyDescriptorSetLayout)(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateDescriptorPool)(VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorPool* pDescriptorPool);
+typedef void (VKAPI_PTR *PFN_vkDestroyDescriptorPool)(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkResetDescriptorPool)(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags);
+typedef VkResult (VKAPI_PTR *PFN_vkAllocateDescriptorSets)(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets);
+typedef VkResult (VKAPI_PTR *PFN_vkFreeDescriptorSets)(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount, const VkDescriptorSet* pDescriptorSets);
+typedef void (VKAPI_PTR *PFN_vkUpdateDescriptorSets)(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pDescriptorCopies);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateFramebuffer)(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFramebuffer* pFramebuffer);
+typedef void (VKAPI_PTR *PFN_vkDestroyFramebuffer)(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateRenderPass)(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass);
+typedef void (VKAPI_PTR *PFN_vkDestroyRenderPass)(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator);
+typedef void (VKAPI_PTR *PFN_vkGetRenderAreaGranularity)(VkDevice device, VkRenderPass renderPass, VkExtent2D* pGranularity);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateCommandPool)(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool);
+typedef void (VKAPI_PTR *PFN_vkDestroyCommandPool)(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkResetCommandPool)(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags);
+typedef VkResult (VKAPI_PTR *PFN_vkAllocateCommandBuffers)(VkDevice device, const VkCommandBufferAllocateInfo* pAllocateInfo, VkCommandBuffer* pCommandBuffers);
+typedef void (VKAPI_PTR *PFN_vkFreeCommandBuffers)(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers);
+typedef VkResult (VKAPI_PTR *PFN_vkBeginCommandBuffer)(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo);
+typedef VkResult (VKAPI_PTR *PFN_vkEndCommandBuffer)(VkCommandBuffer commandBuffer);
+typedef VkResult (VKAPI_PTR *PFN_vkResetCommandBuffer)(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags);
+typedef void (VKAPI_PTR *PFN_vkCmdBindPipeline)(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline);
+typedef void (VKAPI_PTR *PFN_vkCmdSetViewport)(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount, const VkViewport* pViewports);
+typedef void (VKAPI_PTR *PFN_vkCmdSetScissor)(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D* pScissors);
+typedef void (VKAPI_PTR *PFN_vkCmdSetLineWidth)(VkCommandBuffer commandBuffer, float lineWidth);
+typedef void (VKAPI_PTR *PFN_vkCmdSetDepthBias)(VkCommandBuffer commandBuffer, float depthBiasConstantFactor, float depthBiasClamp, float depthBiasSlopeFactor);
+typedef void (VKAPI_PTR *PFN_vkCmdSetBlendConstants)(VkCommandBuffer commandBuffer, const float blendConstants[4]);
+typedef void (VKAPI_PTR *PFN_vkCmdSetDepthBounds)(VkCommandBuffer commandBuffer, float minDepthBounds, float maxDepthBounds);
+typedef void (VKAPI_PTR *PFN_vkCmdSetStencilCompareMask)(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t compareMask);
+typedef void (VKAPI_PTR *PFN_vkCmdSetStencilWriteMask)(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t writeMask);
+typedef void (VKAPI_PTR *PFN_vkCmdSetStencilReference)(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t reference);
+typedef void (VKAPI_PTR *PFN_vkCmdBindDescriptorSets)(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, uint32_t firstSet, uint32_t descriptorSetCount, const VkDescriptorSet* pDescriptorSets, uint32_t dynamicOffsetCount, const uint32_t* pDynamicOffsets);
+typedef void (VKAPI_PTR *PFN_vkCmdBindIndexBuffer)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType);
+typedef void (VKAPI_PTR *PFN_vkCmdBindVertexBuffers)(VkCommandBuffer commandBuffer, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers, const VkDeviceSize* pOffsets);
+typedef void (VKAPI_PTR *PFN_vkCmdDraw)(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance);
+typedef void (VKAPI_PTR *PFN_vkCmdDrawIndexed)(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance);
+typedef void (VKAPI_PTR *PFN_vkCmdDrawIndirect)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride);
+typedef void (VKAPI_PTR *PFN_vkCmdDrawIndexedIndirect)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride);
+typedef void (VKAPI_PTR *PFN_vkCmdDispatch)(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ);
+typedef void (VKAPI_PTR *PFN_vkCmdDispatchIndirect)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset);
+typedef void (VKAPI_PTR *PFN_vkCmdCopyBuffer)(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferCopy* pRegions);
+typedef void (VKAPI_PTR *PFN_vkCmdCopyImage)(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy* pRegions);
+typedef void (VKAPI_PTR *PFN_vkCmdBlitImage)(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageBlit* pRegions, VkFilter filter);
+typedef void (VKAPI_PTR *PFN_vkCmdCopyBufferToImage)(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkBufferImageCopy* pRegions);
+typedef void (VKAPI_PTR *PFN_vkCmdCopyImageToBuffer)(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy* pRegions);
+typedef void (VKAPI_PTR *PFN_vkCmdUpdateBuffer)(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const void* pData);
+typedef void (VKAPI_PTR *PFN_vkCmdFillBuffer)(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data);
+typedef void (VKAPI_PTR *PFN_vkCmdClearColorImage)(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearColorValue* pColor, uint32_t rangeCount, const VkImageSubresourceRange* pRanges);
+typedef void (VKAPI_PTR *PFN_vkCmdClearDepthStencilImage)(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue* pDepthStencil, uint32_t rangeCount, const VkImageSubresourceRange* pRanges);
+typedef void (VKAPI_PTR *PFN_vkCmdClearAttachments)(VkCommandBuffer commandBuffer, uint32_t attachmentCount, const VkClearAttachment* pAttachments, uint32_t rectCount, const VkClearRect* pRects);
+typedef void (VKAPI_PTR *PFN_vkCmdResolveImage)(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageResolve* pRegions);
+typedef void (VKAPI_PTR *PFN_vkCmdSetEvent)(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask);
+typedef void (VKAPI_PTR *PFN_vkCmdResetEvent)(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask);
+typedef void (VKAPI_PTR *PFN_vkCmdWaitEvents)(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers);
+typedef void (VKAPI_PTR *PFN_vkCmdPipelineBarrier)(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers);
+typedef void (VKAPI_PTR *PFN_vkCmdBeginQuery)(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t query, VkQueryControlFlags flags);
+typedef void (VKAPI_PTR *PFN_vkCmdEndQuery)(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t query);
+typedef void (VKAPI_PTR *PFN_vkCmdResetQueryPool)(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount);
+typedef void (VKAPI_PTR *PFN_vkCmdWriteTimestamp)(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t query);
+typedef void (VKAPI_PTR *PFN_vkCmdCopyQueryPoolResults)(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize stride, VkQueryResultFlags flags);
+typedef void (VKAPI_PTR *PFN_vkCmdPushConstants)(VkCommandBuffer commandBuffer, VkPipelineLayout layout, VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size, const void* pValues);
+typedef void (VKAPI_PTR *PFN_vkCmdBeginRenderPass)(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, VkSubpassContents contents);
+typedef void (VKAPI_PTR *PFN_vkCmdNextSubpass)(VkCommandBuffer commandBuffer, VkSubpassContents contents);
+typedef void (VKAPI_PTR *PFN_vkCmdEndRenderPass)(VkCommandBuffer commandBuffer);
+typedef void (VKAPI_PTR *PFN_vkCmdExecuteCommands)(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(
+ const VkInstanceCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkInstance* pInstance);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(
+ VkInstance instance,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices(
+ VkInstance instance,
+ uint32_t* pPhysicalDeviceCount,
+ VkPhysicalDevice* pPhysicalDevices);
+
+VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFeatures(
+ VkPhysicalDevice physicalDevice,
+ VkPhysicalDeviceFeatures* pFeatures);
+
+VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFormatProperties(
+ VkPhysicalDevice physicalDevice,
+ VkFormat format,
+ VkFormatProperties* pFormatProperties);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceImageFormatProperties(
+ VkPhysicalDevice physicalDevice,
+ VkFormat format,
+ VkImageType type,
+ VkImageTiling tiling,
+ VkImageUsageFlags usage,
+ VkImageCreateFlags flags,
+ VkImageFormatProperties* pImageFormatProperties);
+
+VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties(
+ VkPhysicalDevice physicalDevice,
+ VkPhysicalDeviceProperties* pProperties);
+
+VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceQueueFamilyProperties(
+ VkPhysicalDevice physicalDevice,
+ uint32_t* pQueueFamilyPropertyCount,
+ VkQueueFamilyProperties* pQueueFamilyProperties);
+
+VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMemoryProperties(
+ VkPhysicalDevice physicalDevice,
+ VkPhysicalDeviceMemoryProperties* pMemoryProperties);
+
+VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(
+ VkInstance instance,
+ const char* pName);
+
+VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(
+ VkDevice device,
+ const char* pName);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(
+ VkPhysicalDevice physicalDevice,
+ const VkDeviceCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkDevice* pDevice);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(
+ VkDevice device,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
+ const char* pLayerName,
+ uint32_t* pPropertyCount,
+ VkExtensionProperties* pProperties);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
+ VkPhysicalDevice physicalDevice,
+ const char* pLayerName,
+ uint32_t* pPropertyCount,
+ VkExtensionProperties* pProperties);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
+ uint32_t* pPropertyCount,
+ VkLayerProperties* pProperties);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
+ VkPhysicalDevice physicalDevice,
+ uint32_t* pPropertyCount,
+ VkLayerProperties* pProperties);
+
+VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(
+ VkDevice device,
+ uint32_t queueFamilyIndex,
+ uint32_t queueIndex,
+ VkQueue* pQueue);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(
+ VkQueue queue,
+ uint32_t submitCount,
+ const VkSubmitInfo* pSubmits,
+ VkFence fence);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle(
+ VkQueue queue);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle(
+ VkDevice device);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkAllocateMemory(
+ VkDevice device,
+ const VkMemoryAllocateInfo* pAllocateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkDeviceMemory* pMemory);
+
+VKAPI_ATTR void VKAPI_CALL vkFreeMemory(
+ VkDevice device,
+ VkDeviceMemory memory,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory(
+ VkDevice device,
+ VkDeviceMemory memory,
+ VkDeviceSize offset,
+ VkDeviceSize size,
+ VkMemoryMapFlags flags,
+ void** ppData);
+
+VKAPI_ATTR void VKAPI_CALL vkUnmapMemory(
+ VkDevice device,
+ VkDeviceMemory memory);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkFlushMappedMemoryRanges(
+ VkDevice device,
+ uint32_t memoryRangeCount,
+ const VkMappedMemoryRange* pMemoryRanges);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkInvalidateMappedMemoryRanges(
+ VkDevice device,
+ uint32_t memoryRangeCount,
+ const VkMappedMemoryRange* pMemoryRanges);
+
+VKAPI_ATTR void VKAPI_CALL vkGetDeviceMemoryCommitment(
+ VkDevice device,
+ VkDeviceMemory memory,
+ VkDeviceSize* pCommittedMemoryInBytes);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkBindBufferMemory(
+ VkDevice device,
+ VkBuffer buffer,
+ VkDeviceMemory memory,
+ VkDeviceSize memoryOffset);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory(
+ VkDevice device,
+ VkImage image,
+ VkDeviceMemory memory,
+ VkDeviceSize memoryOffset);
+
+VKAPI_ATTR void VKAPI_CALL vkGetBufferMemoryRequirements(
+ VkDevice device,
+ VkBuffer buffer,
+ VkMemoryRequirements* pMemoryRequirements);
+
+VKAPI_ATTR void VKAPI_CALL vkGetImageMemoryRequirements(
+ VkDevice device,
+ VkImage image,
+ VkMemoryRequirements* pMemoryRequirements);
+
+VKAPI_ATTR void VKAPI_CALL vkGetImageSparseMemoryRequirements(
+ VkDevice device,
+ VkImage image,
+ uint32_t* pSparseMemoryRequirementCount,
+ VkSparseImageMemoryRequirements* pSparseMemoryRequirements);
+
+VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceSparseImageFormatProperties(
+ VkPhysicalDevice physicalDevice,
+ VkFormat format,
+ VkImageType type,
+ VkSampleCountFlagBits samples,
+ VkImageUsageFlags usage,
+ VkImageTiling tiling,
+ uint32_t* pPropertyCount,
+ VkSparseImageFormatProperties* pProperties);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse(
+ VkQueue queue,
+ uint32_t bindInfoCount,
+ const VkBindSparseInfo* pBindInfo,
+ VkFence fence);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateFence(
+ VkDevice device,
+ const VkFenceCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkFence* pFence);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyFence(
+ VkDevice device,
+ VkFence fence,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkResetFences(
+ VkDevice device,
+ uint32_t fenceCount,
+ const VkFence* pFences);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus(
+ VkDevice device,
+ VkFence fence);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences(
+ VkDevice device,
+ uint32_t fenceCount,
+ const VkFence* pFences,
+ VkBool32 waitAll,
+ uint64_t timeout);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore(
+ VkDevice device,
+ const VkSemaphoreCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkSemaphore* pSemaphore);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore(
+ VkDevice device,
+ VkSemaphore semaphore,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateEvent(
+ VkDevice device,
+ const VkEventCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkEvent* pEvent);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyEvent(
+ VkDevice device,
+ VkEvent event,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetEventStatus(
+ VkDevice device,
+ VkEvent event);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent(
+ VkDevice device,
+ VkEvent event);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkResetEvent(
+ VkDevice device,
+ VkEvent event);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateQueryPool(
+ VkDevice device,
+ const VkQueryPoolCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkQueryPool* pQueryPool);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(
+ VkDevice device,
+ VkQueryPool queryPool,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(
+ VkDevice device,
+ VkQueryPool queryPool,
+ uint32_t firstQuery,
+ uint32_t queryCount,
+ size_t dataSize,
+ void* pData,
+ VkDeviceSize stride,
+ VkQueryResultFlags flags);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateBuffer(
+ VkDevice device,
+ const VkBufferCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkBuffer* pBuffer);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer(
+ VkDevice device,
+ VkBuffer buffer,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateBufferView(
+ VkDevice device,
+ const VkBufferViewCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkBufferView* pView);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView(
+ VkDevice device,
+ VkBufferView bufferView,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage(
+ VkDevice device,
+ const VkImageCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkImage* pImage);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyImage(
+ VkDevice device,
+ VkImage image,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR void VKAPI_CALL vkGetImageSubresourceLayout(
+ VkDevice device,
+ VkImage image,
+ const VkImageSubresource* pSubresource,
+ VkSubresourceLayout* pLayout);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateImageView(
+ VkDevice device,
+ const VkImageViewCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkImageView* pView);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyImageView(
+ VkDevice device,
+ VkImageView imageView,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule(
+ VkDevice device,
+ const VkShaderModuleCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkShaderModule* pShaderModule);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule(
+ VkDevice device,
+ VkShaderModule shaderModule,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache(
+ VkDevice device,
+ const VkPipelineCacheCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkPipelineCache* pPipelineCache);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache(
+ VkDevice device,
+ VkPipelineCache pipelineCache,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData(
+ VkDevice device,
+ VkPipelineCache pipelineCache,
+ size_t* pDataSize,
+ void* pData);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches(
+ VkDevice device,
+ VkPipelineCache dstCache,
+ uint32_t srcCacheCount,
+ const VkPipelineCache* pSrcCaches);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines(
+ VkDevice device,
+ VkPipelineCache pipelineCache,
+ uint32_t createInfoCount,
+ const VkGraphicsPipelineCreateInfo* pCreateInfos,
+ const VkAllocationCallbacks* pAllocator,
+ VkPipeline* pPipelines);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines(
+ VkDevice device,
+ VkPipelineCache pipelineCache,
+ uint32_t createInfoCount,
+ const VkComputePipelineCreateInfo* pCreateInfos,
+ const VkAllocationCallbacks* pAllocator,
+ VkPipeline* pPipelines);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline(
+ VkDevice device,
+ VkPipeline pipeline,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout(
+ VkDevice device,
+ const VkPipelineLayoutCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkPipelineLayout* pPipelineLayout);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout(
+ VkDevice device,
+ VkPipelineLayout pipelineLayout,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateSampler(
+ VkDevice device,
+ const VkSamplerCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkSampler* pSampler);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroySampler(
+ VkDevice device,
+ VkSampler sampler,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorSetLayout(
+ VkDevice device,
+ const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkDescriptorSetLayout* pSetLayout);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout(
+ VkDevice device,
+ VkDescriptorSetLayout descriptorSetLayout,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorPool(
+ VkDevice device,
+ const VkDescriptorPoolCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkDescriptorPool* pDescriptorPool);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool(
+ VkDevice device,
+ VkDescriptorPool descriptorPool,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool(
+ VkDevice device,
+ VkDescriptorPool descriptorPool,
+ VkDescriptorPoolResetFlags flags);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets(
+ VkDevice device,
+ const VkDescriptorSetAllocateInfo* pAllocateInfo,
+ VkDescriptorSet* pDescriptorSets);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkFreeDescriptorSets(
+ VkDevice device,
+ VkDescriptorPool descriptorPool,
+ uint32_t descriptorSetCount,
+ const VkDescriptorSet* pDescriptorSets);
+
+VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSets(
+ VkDevice device,
+ uint32_t descriptorWriteCount,
+ const VkWriteDescriptorSet* pDescriptorWrites,
+ uint32_t descriptorCopyCount,
+ const VkCopyDescriptorSet* pDescriptorCopies);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateFramebuffer(
+ VkDevice device,
+ const VkFramebufferCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkFramebuffer* pFramebuffer);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer(
+ VkDevice device,
+ VkFramebuffer framebuffer,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(
+ VkDevice device,
+ const VkRenderPassCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkRenderPass* pRenderPass);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass(
+ VkDevice device,
+ VkRenderPass renderPass,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR void VKAPI_CALL vkGetRenderAreaGranularity(
+ VkDevice device,
+ VkRenderPass renderPass,
+ VkExtent2D* pGranularity);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(
+ VkDevice device,
+ const VkCommandPoolCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkCommandPool* pCommandPool);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(
+ VkDevice device,
+ VkCommandPool commandPool,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(
+ VkDevice device,
+ VkCommandPool commandPool,
+ VkCommandPoolResetFlags flags);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(
+ VkDevice device,
+ const VkCommandBufferAllocateInfo* pAllocateInfo,
+ VkCommandBuffer* pCommandBuffers);
+
+VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers(
+ VkDevice device,
+ VkCommandPool commandPool,
+ uint32_t commandBufferCount,
+ const VkCommandBuffer* pCommandBuffers);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer(
+ VkCommandBuffer commandBuffer,
+ const VkCommandBufferBeginInfo* pBeginInfo);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer(
+ VkCommandBuffer commandBuffer);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer(
+ VkCommandBuffer commandBuffer,
+ VkCommandBufferResetFlags flags);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline(
+ VkCommandBuffer commandBuffer,
+ VkPipelineBindPoint pipelineBindPoint,
+ VkPipeline pipeline);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
+ VkCommandBuffer commandBuffer,
+ uint32_t firstViewport,
+ uint32_t viewportCount,
+ const VkViewport* pViewports);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
+ VkCommandBuffer commandBuffer,
+ uint32_t firstScissor,
+ uint32_t scissorCount,
+ const VkRect2D* pScissors);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth(
+ VkCommandBuffer commandBuffer,
+ float lineWidth);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias(
+ VkCommandBuffer commandBuffer,
+ float depthBiasConstantFactor,
+ float depthBiasClamp,
+ float depthBiasSlopeFactor);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants(
+ VkCommandBuffer commandBuffer,
+ const float blendConstants[4]);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds(
+ VkCommandBuffer commandBuffer,
+ float minDepthBounds,
+ float maxDepthBounds);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask(
+ VkCommandBuffer commandBuffer,
+ VkStencilFaceFlags faceMask,
+ uint32_t compareMask);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask(
+ VkCommandBuffer commandBuffer,
+ VkStencilFaceFlags faceMask,
+ uint32_t writeMask);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference(
+ VkCommandBuffer commandBuffer,
+ VkStencilFaceFlags faceMask,
+ uint32_t reference);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdBindDescriptorSets(
+ VkCommandBuffer commandBuffer,
+ VkPipelineBindPoint pipelineBindPoint,
+ VkPipelineLayout layout,
+ uint32_t firstSet,
+ uint32_t descriptorSetCount,
+ const VkDescriptorSet* pDescriptorSets,
+ uint32_t dynamicOffsetCount,
+ const uint32_t* pDynamicOffsets);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(
+ VkCommandBuffer commandBuffer,
+ VkBuffer buffer,
+ VkDeviceSize offset,
+ VkIndexType indexType);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers(
+ VkCommandBuffer commandBuffer,
+ uint32_t firstBinding,
+ uint32_t bindingCount,
+ const VkBuffer* pBuffers,
+ const VkDeviceSize* pOffsets);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdDraw(
+ VkCommandBuffer commandBuffer,
+ uint32_t vertexCount,
+ uint32_t instanceCount,
+ uint32_t firstVertex,
+ uint32_t firstInstance);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexed(
+ VkCommandBuffer commandBuffer,
+ uint32_t indexCount,
+ uint32_t instanceCount,
+ uint32_t firstIndex,
+ int32_t vertexOffset,
+ uint32_t firstInstance);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirect(
+ VkCommandBuffer commandBuffer,
+ VkBuffer buffer,
+ VkDeviceSize offset,
+ uint32_t drawCount,
+ uint32_t stride);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirect(
+ VkCommandBuffer commandBuffer,
+ VkBuffer buffer,
+ VkDeviceSize offset,
+ uint32_t drawCount,
+ uint32_t stride);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdDispatch(
+ VkCommandBuffer commandBuffer,
+ uint32_t groupCountX,
+ uint32_t groupCountY,
+ uint32_t groupCountZ);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect(
+ VkCommandBuffer commandBuffer,
+ VkBuffer buffer,
+ VkDeviceSize offset);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdCopyBuffer(
+ VkCommandBuffer commandBuffer,
+ VkBuffer srcBuffer,
+ VkBuffer dstBuffer,
+ uint32_t regionCount,
+ const VkBufferCopy* pRegions);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage(
+ VkCommandBuffer commandBuffer,
+ VkImage srcImage,
+ VkImageLayout srcImageLayout,
+ VkImage dstImage,
+ VkImageLayout dstImageLayout,
+ uint32_t regionCount,
+ const VkImageCopy* pRegions);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage(
+ VkCommandBuffer commandBuffer,
+ VkImage srcImage,
+ VkImageLayout srcImageLayout,
+ VkImage dstImage,
+ VkImageLayout dstImageLayout,
+ uint32_t regionCount,
+ const VkImageBlit* pRegions,
+ VkFilter filter);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage(
+ VkCommandBuffer commandBuffer,
+ VkBuffer srcBuffer,
+ VkImage dstImage,
+ VkImageLayout dstImageLayout,
+ uint32_t regionCount,
+ const VkBufferImageCopy* pRegions);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer(
+ VkCommandBuffer commandBuffer,
+ VkImage srcImage,
+ VkImageLayout srcImageLayout,
+ VkBuffer dstBuffer,
+ uint32_t regionCount,
+ const VkBufferImageCopy* pRegions);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdUpdateBuffer(
+ VkCommandBuffer commandBuffer,
+ VkBuffer dstBuffer,
+ VkDeviceSize dstOffset,
+ VkDeviceSize dataSize,
+ const void* pData);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdFillBuffer(
+ VkCommandBuffer commandBuffer,
+ VkBuffer dstBuffer,
+ VkDeviceSize dstOffset,
+ VkDeviceSize size,
+ uint32_t data);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage(
+ VkCommandBuffer commandBuffer,
+ VkImage image,
+ VkImageLayout imageLayout,
+ const VkClearColorValue* pColor,
+ uint32_t rangeCount,
+ const VkImageSubresourceRange* pRanges);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage(
+ VkCommandBuffer commandBuffer,
+ VkImage image,
+ VkImageLayout imageLayout,
+ const VkClearDepthStencilValue* pDepthStencil,
+ uint32_t rangeCount,
+ const VkImageSubresourceRange* pRanges);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments(
+ VkCommandBuffer commandBuffer,
+ uint32_t attachmentCount,
+ const VkClearAttachment* pAttachments,
+ uint32_t rectCount,
+ const VkClearRect* pRects);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage(
+ VkCommandBuffer commandBuffer,
+ VkImage srcImage,
+ VkImageLayout srcImageLayout,
+ VkImage dstImage,
+ VkImageLayout dstImageLayout,
+ uint32_t regionCount,
+ const VkImageResolve* pRegions);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent(
+ VkCommandBuffer commandBuffer,
+ VkEvent event,
+ VkPipelineStageFlags stageMask);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent(
+ VkCommandBuffer commandBuffer,
+ VkEvent event,
+ VkPipelineStageFlags stageMask);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(
+ VkCommandBuffer commandBuffer,
+ uint32_t eventCount,
+ const VkEvent* pEvents,
+ VkPipelineStageFlags srcStageMask,
+ VkPipelineStageFlags dstStageMask,
+ uint32_t memoryBarrierCount,
+ const VkMemoryBarrier* pMemoryBarriers,
+ uint32_t bufferMemoryBarrierCount,
+ const VkBufferMemoryBarrier* pBufferMemoryBarriers,
+ uint32_t imageMemoryBarrierCount,
+ const VkImageMemoryBarrier* pImageMemoryBarriers);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier(
+ VkCommandBuffer commandBuffer,
+ VkPipelineStageFlags srcStageMask,
+ VkPipelineStageFlags dstStageMask,
+ VkDependencyFlags dependencyFlags,
+ uint32_t memoryBarrierCount,
+ const VkMemoryBarrier* pMemoryBarriers,
+ uint32_t bufferMemoryBarrierCount,
+ const VkBufferMemoryBarrier* pBufferMemoryBarriers,
+ uint32_t imageMemoryBarrierCount,
+ const VkImageMemoryBarrier* pImageMemoryBarriers);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery(
+ VkCommandBuffer commandBuffer,
+ VkQueryPool queryPool,
+ uint32_t query,
+ VkQueryControlFlags flags);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery(
+ VkCommandBuffer commandBuffer,
+ VkQueryPool queryPool,
+ uint32_t query);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdResetQueryPool(
+ VkCommandBuffer commandBuffer,
+ VkQueryPool queryPool,
+ uint32_t firstQuery,
+ uint32_t queryCount);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp(
+ VkCommandBuffer commandBuffer,
+ VkPipelineStageFlagBits pipelineStage,
+ VkQueryPool queryPool,
+ uint32_t query);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults(
+ VkCommandBuffer commandBuffer,
+ VkQueryPool queryPool,
+ uint32_t firstQuery,
+ uint32_t queryCount,
+ VkBuffer dstBuffer,
+ VkDeviceSize dstOffset,
+ VkDeviceSize stride,
+ VkQueryResultFlags flags);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdPushConstants(
+ VkCommandBuffer commandBuffer,
+ VkPipelineLayout layout,
+ VkShaderStageFlags stageFlags,
+ uint32_t offset,
+ uint32_t size,
+ const void* pValues);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass(
+ VkCommandBuffer commandBuffer,
+ const VkRenderPassBeginInfo* pRenderPassBegin,
+ VkSubpassContents contents);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass(
+ VkCommandBuffer commandBuffer,
+ VkSubpassContents contents);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass(
+ VkCommandBuffer commandBuffer);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands(
+ VkCommandBuffer commandBuffer,
+ uint32_t commandBufferCount,
+ const VkCommandBuffer* pCommandBuffers);
+#endif
+
+#define VK_KHR_surface 1
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSurfaceKHR)
+
+#define VK_KHR_SURFACE_SPEC_VERSION 25
+#define VK_KHR_SURFACE_EXTENSION_NAME "VK_KHR_surface"
+#define VK_COLORSPACE_SRGB_NONLINEAR_KHR VK_COLOR_SPACE_SRGB_NONLINEAR_KHR
+
+
+typedef enum VkColorSpaceKHR {
+ VK_COLOR_SPACE_SRGB_NONLINEAR_KHR = 0,
+ VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT = 1000104001,
+ VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT = 1000104002,
+ VK_COLOR_SPACE_DCI_P3_LINEAR_EXT = 1000104003,
+ VK_COLOR_SPACE_DCI_P3_NONLINEAR_EXT = 1000104004,
+ VK_COLOR_SPACE_BT709_LINEAR_EXT = 1000104005,
+ VK_COLOR_SPACE_BT709_NONLINEAR_EXT = 1000104006,
+ VK_COLOR_SPACE_BT2020_LINEAR_EXT = 1000104007,
+ VK_COLOR_SPACE_HDR10_ST2084_EXT = 1000104008,
+ VK_COLOR_SPACE_DOLBYVISION_EXT = 1000104009,
+ VK_COLOR_SPACE_HDR10_HLG_EXT = 1000104010,
+ VK_COLOR_SPACE_ADOBERGB_LINEAR_EXT = 1000104011,
+ VK_COLOR_SPACE_ADOBERGB_NONLINEAR_EXT = 1000104012,
+ VK_COLOR_SPACE_PASS_THROUGH_EXT = 1000104013,
+ VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT = 1000104014,
+ VK_COLOR_SPACE_BEGIN_RANGE_KHR = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
+ VK_COLOR_SPACE_END_RANGE_KHR = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
+ VK_COLOR_SPACE_RANGE_SIZE_KHR = (VK_COLOR_SPACE_SRGB_NONLINEAR_KHR - VK_COLOR_SPACE_SRGB_NONLINEAR_KHR + 1),
+ VK_COLOR_SPACE_MAX_ENUM_KHR = 0x7FFFFFFF
+} VkColorSpaceKHR;
+
+typedef enum VkPresentModeKHR {
+ VK_PRESENT_MODE_IMMEDIATE_KHR = 0,
+ VK_PRESENT_MODE_MAILBOX_KHR = 1,
+ VK_PRESENT_MODE_FIFO_KHR = 2,
+ VK_PRESENT_MODE_FIFO_RELAXED_KHR = 3,
+ VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR = 1000111000,
+ VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR = 1000111001,
+ VK_PRESENT_MODE_BEGIN_RANGE_KHR = VK_PRESENT_MODE_IMMEDIATE_KHR,
+ VK_PRESENT_MODE_END_RANGE_KHR = VK_PRESENT_MODE_FIFO_RELAXED_KHR,
+ VK_PRESENT_MODE_RANGE_SIZE_KHR = (VK_PRESENT_MODE_FIFO_RELAXED_KHR - VK_PRESENT_MODE_IMMEDIATE_KHR + 1),
+ VK_PRESENT_MODE_MAX_ENUM_KHR = 0x7FFFFFFF
+} VkPresentModeKHR;
+
+
+typedef enum VkSurfaceTransformFlagBitsKHR {
+ VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR = 0x00000001,
+ VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR = 0x00000002,
+ VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR = 0x00000004,
+ VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR = 0x00000008,
+ VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR = 0x00000010,
+ VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR = 0x00000020,
+ VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR = 0x00000040,
+ VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR = 0x00000080,
+ VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR = 0x00000100,
+ VK_SURFACE_TRANSFORM_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
+} VkSurfaceTransformFlagBitsKHR;
+typedef VkFlags VkSurfaceTransformFlagsKHR;
+
+typedef enum VkCompositeAlphaFlagBitsKHR {
+ VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR = 0x00000001,
+ VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR = 0x00000002,
+ VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR = 0x00000004,
+ VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR = 0x00000008,
+ VK_COMPOSITE_ALPHA_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
+} VkCompositeAlphaFlagBitsKHR;
+typedef VkFlags VkCompositeAlphaFlagsKHR;
+
+typedef struct VkSurfaceCapabilitiesKHR {
+ uint32_t minImageCount;
+ uint32_t maxImageCount;
+ VkExtent2D currentExtent;
+ VkExtent2D minImageExtent;
+ VkExtent2D maxImageExtent;
+ uint32_t maxImageArrayLayers;
+ VkSurfaceTransformFlagsKHR supportedTransforms;
+ VkSurfaceTransformFlagBitsKHR currentTransform;
+ VkCompositeAlphaFlagsKHR supportedCompositeAlpha;
+ VkImageUsageFlags supportedUsageFlags;
+} VkSurfaceCapabilitiesKHR;
+
+typedef struct VkSurfaceFormatKHR {
+ VkFormat format;
+ VkColorSpaceKHR colorSpace;
+} VkSurfaceFormatKHR;
+
+
+typedef void (VKAPI_PTR *PFN_vkDestroySurfaceKHR)(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfaceSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, VkSurfaceKHR surface, VkBool32* pSupported);
+typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR)(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR* pSurfaceCapabilities);
+typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfaceFormatsKHR)(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t* pSurfaceFormatCount, VkSurfaceFormatKHR* pSurfaceFormats);
+typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfacePresentModesKHR)(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t* pPresentModeCount, VkPresentModeKHR* pPresentModes);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(
+ VkInstance instance,
+ VkSurfaceKHR surface,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(
+ VkPhysicalDevice physicalDevice,
+ uint32_t queueFamilyIndex,
+ VkSurfaceKHR surface,
+ VkBool32* pSupported);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
+ VkPhysicalDevice physicalDevice,
+ VkSurfaceKHR surface,
+ VkSurfaceCapabilitiesKHR* pSurfaceCapabilities);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR(
+ VkPhysicalDevice physicalDevice,
+ VkSurfaceKHR surface,
+ uint32_t* pSurfaceFormatCount,
+ VkSurfaceFormatKHR* pSurfaceFormats);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR(
+ VkPhysicalDevice physicalDevice,
+ VkSurfaceKHR surface,
+ uint32_t* pPresentModeCount,
+ VkPresentModeKHR* pPresentModes);
+#endif
+
+#define VK_KHR_swapchain 1
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSwapchainKHR)
+
+#define VK_KHR_SWAPCHAIN_SPEC_VERSION 68
+#define VK_KHR_SWAPCHAIN_EXTENSION_NAME "VK_KHR_swapchain"
+
+
+typedef enum VkSwapchainCreateFlagBitsKHR {
+ VK_SWAPCHAIN_CREATE_BIND_SFR_BIT_KHX = 0x00000001,
+ VK_SWAPCHAIN_CREATE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
+} VkSwapchainCreateFlagBitsKHR;
+typedef VkFlags VkSwapchainCreateFlagsKHR;
+
+typedef struct VkSwapchainCreateInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkSwapchainCreateFlagsKHR flags;
+ VkSurfaceKHR surface;
+ uint32_t minImageCount;
+ VkFormat imageFormat;
+ VkColorSpaceKHR imageColorSpace;
+ VkExtent2D imageExtent;
+ uint32_t imageArrayLayers;
+ VkImageUsageFlags imageUsage;
+ VkSharingMode imageSharingMode;
+ uint32_t queueFamilyIndexCount;
+ const uint32_t* pQueueFamilyIndices;
+ VkSurfaceTransformFlagBitsKHR preTransform;
+ VkCompositeAlphaFlagBitsKHR compositeAlpha;
+ VkPresentModeKHR presentMode;
+ VkBool32 clipped;
+ VkSwapchainKHR oldSwapchain;
+} VkSwapchainCreateInfoKHR;
+
+typedef struct VkPresentInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t waitSemaphoreCount;
+ const VkSemaphore* pWaitSemaphores;
+ uint32_t swapchainCount;
+ const VkSwapchainKHR* pSwapchains;
+ const uint32_t* pImageIndices;
+ VkResult* pResults;
+} VkPresentInfoKHR;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkCreateSwapchainKHR)(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain);
+typedef void (VKAPI_PTR *PFN_vkDestroySwapchainKHR)(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainImagesKHR)(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pSwapchainImageCount, VkImage* pSwapchainImages);
+typedef VkResult (VKAPI_PTR *PFN_vkAcquireNextImageKHR)(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, VkSemaphore semaphore, VkFence fence, uint32_t* pImageIndex);
+typedef VkResult (VKAPI_PTR *PFN_vkQueuePresentKHR)(VkQueue queue, const VkPresentInfoKHR* pPresentInfo);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
+ VkDevice device,
+ const VkSwapchainCreateInfoKHR* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkSwapchainKHR* pSwapchain);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR(
+ VkDevice device,
+ VkSwapchainKHR swapchain,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(
+ VkDevice device,
+ VkSwapchainKHR swapchain,
+ uint32_t* pSwapchainImageCount,
+ VkImage* pSwapchainImages);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
+ VkDevice device,
+ VkSwapchainKHR swapchain,
+ uint64_t timeout,
+ VkSemaphore semaphore,
+ VkFence fence,
+ uint32_t* pImageIndex);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR(
+ VkQueue queue,
+ const VkPresentInfoKHR* pPresentInfo);
+#endif
+
+#define VK_KHR_display 1
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDisplayKHR)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDisplayModeKHR)
+
+#define VK_KHR_DISPLAY_SPEC_VERSION 21
+#define VK_KHR_DISPLAY_EXTENSION_NAME "VK_KHR_display"
+
+
+typedef enum VkDisplayPlaneAlphaFlagBitsKHR {
+ VK_DISPLAY_PLANE_ALPHA_OPAQUE_BIT_KHR = 0x00000001,
+ VK_DISPLAY_PLANE_ALPHA_GLOBAL_BIT_KHR = 0x00000002,
+ VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_BIT_KHR = 0x00000004,
+ VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_PREMULTIPLIED_BIT_KHR = 0x00000008,
+ VK_DISPLAY_PLANE_ALPHA_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
+} VkDisplayPlaneAlphaFlagBitsKHR;
+typedef VkFlags VkDisplayPlaneAlphaFlagsKHR;
+typedef VkFlags VkDisplayModeCreateFlagsKHR;
+typedef VkFlags VkDisplaySurfaceCreateFlagsKHR;
+
+typedef struct VkDisplayPropertiesKHR {
+ VkDisplayKHR display;
+ const char* displayName;
+ VkExtent2D physicalDimensions;
+ VkExtent2D physicalResolution;
+ VkSurfaceTransformFlagsKHR supportedTransforms;
+ VkBool32 planeReorderPossible;
+ VkBool32 persistentContent;
+} VkDisplayPropertiesKHR;
+
+typedef struct VkDisplayModeParametersKHR {
+ VkExtent2D visibleRegion;
+ uint32_t refreshRate;
+} VkDisplayModeParametersKHR;
+
+typedef struct VkDisplayModePropertiesKHR {
+ VkDisplayModeKHR displayMode;
+ VkDisplayModeParametersKHR parameters;
+} VkDisplayModePropertiesKHR;
+
+typedef struct VkDisplayModeCreateInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkDisplayModeCreateFlagsKHR flags;
+ VkDisplayModeParametersKHR parameters;
+} VkDisplayModeCreateInfoKHR;
+
+typedef struct VkDisplayPlaneCapabilitiesKHR {
+ VkDisplayPlaneAlphaFlagsKHR supportedAlpha;
+ VkOffset2D minSrcPosition;
+ VkOffset2D maxSrcPosition;
+ VkExtent2D minSrcExtent;
+ VkExtent2D maxSrcExtent;
+ VkOffset2D minDstPosition;
+ VkOffset2D maxDstPosition;
+ VkExtent2D minDstExtent;
+ VkExtent2D maxDstExtent;
+} VkDisplayPlaneCapabilitiesKHR;
+
+typedef struct VkDisplayPlanePropertiesKHR {
+ VkDisplayKHR currentDisplay;
+ uint32_t currentStackIndex;
+} VkDisplayPlanePropertiesKHR;
+
+typedef struct VkDisplaySurfaceCreateInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkDisplaySurfaceCreateFlagsKHR flags;
+ VkDisplayModeKHR displayMode;
+ uint32_t planeIndex;
+ uint32_t planeStackIndex;
+ VkSurfaceTransformFlagBitsKHR transform;
+ float globalAlpha;
+ VkDisplayPlaneAlphaFlagBitsKHR alphaMode;
+ VkExtent2D imageExtent;
+} VkDisplaySurfaceCreateInfoKHR;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceDisplayPropertiesKHR)(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkDisplayPropertiesKHR* pProperties);
+typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR)(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkDisplayPlanePropertiesKHR* pProperties);
+typedef VkResult (VKAPI_PTR *PFN_vkGetDisplayPlaneSupportedDisplaysKHR)(VkPhysicalDevice physicalDevice, uint32_t planeIndex, uint32_t* pDisplayCount, VkDisplayKHR* pDisplays);
+typedef VkResult (VKAPI_PTR *PFN_vkGetDisplayModePropertiesKHR)(VkPhysicalDevice physicalDevice, VkDisplayKHR display, uint32_t* pPropertyCount, VkDisplayModePropertiesKHR* pProperties);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateDisplayModeKHR)(VkPhysicalDevice physicalDevice, VkDisplayKHR display, const VkDisplayModeCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDisplayModeKHR* pMode);
+typedef VkResult (VKAPI_PTR *PFN_vkGetDisplayPlaneCapabilitiesKHR)(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, uint32_t planeIndex, VkDisplayPlaneCapabilitiesKHR* pCapabilities);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateDisplayPlaneSurfaceKHR)(VkInstance instance, const VkDisplaySurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPropertiesKHR(
+ VkPhysicalDevice physicalDevice,
+ uint32_t* pPropertyCount,
+ VkDisplayPropertiesKHR* pProperties);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPlanePropertiesKHR(
+ VkPhysicalDevice physicalDevice,
+ uint32_t* pPropertyCount,
+ VkDisplayPlanePropertiesKHR* pProperties);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneSupportedDisplaysKHR(
+ VkPhysicalDevice physicalDevice,
+ uint32_t planeIndex,
+ uint32_t* pDisplayCount,
+ VkDisplayKHR* pDisplays);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayModePropertiesKHR(
+ VkPhysicalDevice physicalDevice,
+ VkDisplayKHR display,
+ uint32_t* pPropertyCount,
+ VkDisplayModePropertiesKHR* pProperties);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayModeKHR(
+ VkPhysicalDevice physicalDevice,
+ VkDisplayKHR display,
+ const VkDisplayModeCreateInfoKHR* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkDisplayModeKHR* pMode);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneCapabilitiesKHR(
+ VkPhysicalDevice physicalDevice,
+ VkDisplayModeKHR mode,
+ uint32_t planeIndex,
+ VkDisplayPlaneCapabilitiesKHR* pCapabilities);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayPlaneSurfaceKHR(
+ VkInstance instance,
+ const VkDisplaySurfaceCreateInfoKHR* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkSurfaceKHR* pSurface);
+#endif
+
+#define VK_KHR_display_swapchain 1
+#define VK_KHR_DISPLAY_SWAPCHAIN_SPEC_VERSION 9
+#define VK_KHR_DISPLAY_SWAPCHAIN_EXTENSION_NAME "VK_KHR_display_swapchain"
+
+typedef struct VkDisplayPresentInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkRect2D srcRect;
+ VkRect2D dstRect;
+ VkBool32 persistent;
+} VkDisplayPresentInfoKHR;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkCreateSharedSwapchainsKHR)(VkDevice device, uint32_t swapchainCount, const VkSwapchainCreateInfoKHR* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchains);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateSharedSwapchainsKHR(
+ VkDevice device,
+ uint32_t swapchainCount,
+ const VkSwapchainCreateInfoKHR* pCreateInfos,
+ const VkAllocationCallbacks* pAllocator,
+ VkSwapchainKHR* pSwapchains);
+#endif
+
+#ifdef VK_USE_PLATFORM_XLIB_KHR
+#define VK_KHR_xlib_surface 1
+#include <X11/Xlib.h>
+
+#define VK_KHR_XLIB_SURFACE_SPEC_VERSION 6
+#define VK_KHR_XLIB_SURFACE_EXTENSION_NAME "VK_KHR_xlib_surface"
+
+typedef VkFlags VkXlibSurfaceCreateFlagsKHR;
+
+typedef struct VkXlibSurfaceCreateInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkXlibSurfaceCreateFlagsKHR flags;
+ Display* dpy;
+ Window window;
+} VkXlibSurfaceCreateInfoKHR;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkCreateXlibSurfaceKHR)(VkInstance instance, const VkXlibSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
+typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, Display* dpy, VisualID visualID);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(
+ VkInstance instance,
+ const VkXlibSurfaceCreateInfoKHR* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkSurfaceKHR* pSurface);
+
+VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR(
+ VkPhysicalDevice physicalDevice,
+ uint32_t queueFamilyIndex,
+ Display* dpy,
+ VisualID visualID);
+#endif
+#endif /* VK_USE_PLATFORM_XLIB_KHR */
+
+#ifdef VK_USE_PLATFORM_XCB_KHR
+#define VK_KHR_xcb_surface 1
+#include <xcb/xcb.h>
+
+#define VK_KHR_XCB_SURFACE_SPEC_VERSION 6
+#define VK_KHR_XCB_SURFACE_EXTENSION_NAME "VK_KHR_xcb_surface"
+
+typedef VkFlags VkXcbSurfaceCreateFlagsKHR;
+
+typedef struct VkXcbSurfaceCreateInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkXcbSurfaceCreateFlagsKHR flags;
+ xcb_connection_t* connection;
+ xcb_window_t window;
+} VkXcbSurfaceCreateInfoKHR;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkCreateXcbSurfaceKHR)(VkInstance instance, const VkXcbSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
+typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, xcb_connection_t* connection, xcb_visualid_t visual_id);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR(
+ VkInstance instance,
+ const VkXcbSurfaceCreateInfoKHR* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkSurfaceKHR* pSurface);
+
+VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentationSupportKHR(
+ VkPhysicalDevice physicalDevice,
+ uint32_t queueFamilyIndex,
+ xcb_connection_t* connection,
+ xcb_visualid_t visual_id);
+#endif
+#endif /* VK_USE_PLATFORM_XCB_KHR */
+
+#ifdef VK_USE_PLATFORM_WAYLAND_KHR
+#define VK_KHR_wayland_surface 1
+#include <wayland-client.h>
+
+#define VK_KHR_WAYLAND_SURFACE_SPEC_VERSION 6
+#define VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME "VK_KHR_wayland_surface"
+
+typedef VkFlags VkWaylandSurfaceCreateFlagsKHR;
+
+typedef struct VkWaylandSurfaceCreateInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkWaylandSurfaceCreateFlagsKHR flags;
+ struct wl_display* display;
+ struct wl_surface* surface;
+} VkWaylandSurfaceCreateInfoKHR;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkCreateWaylandSurfaceKHR)(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
+typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, struct wl_display* display);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(
+ VkInstance instance,
+ const VkWaylandSurfaceCreateInfoKHR* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkSurfaceKHR* pSurface);
+
+VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWaylandPresentationSupportKHR(
+ VkPhysicalDevice physicalDevice,
+ uint32_t queueFamilyIndex,
+ struct wl_display* display);
+#endif
+#endif /* VK_USE_PLATFORM_WAYLAND_KHR */
+
+#ifdef VK_USE_PLATFORM_MIR_KHR
+#define VK_KHR_mir_surface 1
+#include <mir_toolkit/client_types.h>
+
+#define VK_KHR_MIR_SURFACE_SPEC_VERSION 4
+#define VK_KHR_MIR_SURFACE_EXTENSION_NAME "VK_KHR_mir_surface"
+
+typedef VkFlags VkMirSurfaceCreateFlagsKHR;
+
+typedef struct VkMirSurfaceCreateInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkMirSurfaceCreateFlagsKHR flags;
+ MirConnection* connection;
+ MirSurface* mirSurface;
+} VkMirSurfaceCreateInfoKHR;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkCreateMirSurfaceKHR)(VkInstance instance, const VkMirSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
+typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceMirPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, MirConnection* connection);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateMirSurfaceKHR(
+ VkInstance instance,
+ const VkMirSurfaceCreateInfoKHR* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkSurfaceKHR* pSurface);
+
+VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceMirPresentationSupportKHR(
+ VkPhysicalDevice physicalDevice,
+ uint32_t queueFamilyIndex,
+ MirConnection* connection);
+#endif
+#endif /* VK_USE_PLATFORM_MIR_KHR */
+
+#ifdef VK_USE_PLATFORM_ANDROID_KHR
+#define VK_KHR_android_surface 1
+#include <android/native_window.h>
+
+#define VK_KHR_ANDROID_SURFACE_SPEC_VERSION 6
+#define VK_KHR_ANDROID_SURFACE_EXTENSION_NAME "VK_KHR_android_surface"
+
+typedef VkFlags VkAndroidSurfaceCreateFlagsKHR;
+
+typedef struct VkAndroidSurfaceCreateInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkAndroidSurfaceCreateFlagsKHR flags;
+ ANativeWindow* window;
+} VkAndroidSurfaceCreateInfoKHR;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkCreateAndroidSurfaceKHR)(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR(
+ VkInstance instance,
+ const VkAndroidSurfaceCreateInfoKHR* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkSurfaceKHR* pSurface);
+#endif
+#endif /* VK_USE_PLATFORM_ANDROID_KHR */
+
+#ifdef VK_USE_PLATFORM_WIN32_KHR
+#define VK_KHR_win32_surface 1
+#include <windows.h>
+
+#define VK_KHR_WIN32_SURFACE_SPEC_VERSION 6
+#define VK_KHR_WIN32_SURFACE_EXTENSION_NAME "VK_KHR_win32_surface"
+
+typedef VkFlags VkWin32SurfaceCreateFlagsKHR;
+
+typedef struct VkWin32SurfaceCreateInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkWin32SurfaceCreateFlagsKHR flags;
+ HINSTANCE hinstance;
+ HWND hwnd;
+} VkWin32SurfaceCreateInfoKHR;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkCreateWin32SurfaceKHR)(VkInstance instance, const VkWin32SurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
+typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(
+ VkInstance instance,
+ const VkWin32SurfaceCreateInfoKHR* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkSurfaceKHR* pSurface);
+
+VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWin32PresentationSupportKHR(
+ VkPhysicalDevice physicalDevice,
+ uint32_t queueFamilyIndex);
+#endif
+#endif /* VK_USE_PLATFORM_WIN32_KHR */
+
+#define VK_KHR_sampler_mirror_clamp_to_edge 1
+#define VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_SPEC_VERSION 1
+#define VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME "VK_KHR_sampler_mirror_clamp_to_edge"
+
+
+#define VK_KHR_get_physical_device_properties2 1
+#define VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_SPEC_VERSION 1
+#define VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME "VK_KHR_get_physical_device_properties2"
+
+typedef struct VkPhysicalDeviceFeatures2KHR {
+ VkStructureType sType;
+ void* pNext;
+ VkPhysicalDeviceFeatures features;
+} VkPhysicalDeviceFeatures2KHR;
+
+typedef struct VkPhysicalDeviceProperties2KHR {
+ VkStructureType sType;
+ void* pNext;
+ VkPhysicalDeviceProperties properties;
+} VkPhysicalDeviceProperties2KHR;
+
+typedef struct VkFormatProperties2KHR {
+ VkStructureType sType;
+ void* pNext;
+ VkFormatProperties formatProperties;
+} VkFormatProperties2KHR;
+
+typedef struct VkImageFormatProperties2KHR {
+ VkStructureType sType;
+ void* pNext;
+ VkImageFormatProperties imageFormatProperties;
+} VkImageFormatProperties2KHR;
+
+typedef struct VkPhysicalDeviceImageFormatInfo2KHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkFormat format;
+ VkImageType type;
+ VkImageTiling tiling;
+ VkImageUsageFlags usage;
+ VkImageCreateFlags flags;
+} VkPhysicalDeviceImageFormatInfo2KHR;
+
+typedef struct VkQueueFamilyProperties2KHR {
+ VkStructureType sType;
+ void* pNext;
+ VkQueueFamilyProperties queueFamilyProperties;
+} VkQueueFamilyProperties2KHR;
+
+typedef struct VkPhysicalDeviceMemoryProperties2KHR {
+ VkStructureType sType;
+ void* pNext;
+ VkPhysicalDeviceMemoryProperties memoryProperties;
+} VkPhysicalDeviceMemoryProperties2KHR;
+
+typedef struct VkSparseImageFormatProperties2KHR {
+ VkStructureType sType;
+ void* pNext;
+ VkSparseImageFormatProperties properties;
+} VkSparseImageFormatProperties2KHR;
+
+typedef struct VkPhysicalDeviceSparseImageFormatInfo2KHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkFormat format;
+ VkImageType type;
+ VkSampleCountFlagBits samples;
+ VkImageUsageFlags usage;
+ VkImageTiling tiling;
+} VkPhysicalDeviceSparseImageFormatInfo2KHR;
+
+
+typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceFeatures2KHR)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures2KHR* pFeatures);
+typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceProperties2KHR)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties2KHR* pProperties);
+typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceFormatProperties2KHR)(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties2KHR* pFormatProperties);
+typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceImageFormatProperties2KHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2KHR* pImageFormatInfo, VkImageFormatProperties2KHR* pImageFormatProperties);
+typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceQueueFamilyProperties2KHR)(VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties2KHR* pQueueFamilyProperties);
+typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceMemoryProperties2KHR)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties2KHR* pMemoryProperties);
+typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceSparseImageFormatProperties2KHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSparseImageFormatInfo2KHR* pFormatInfo, uint32_t* pPropertyCount, VkSparseImageFormatProperties2KHR* pProperties);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFeatures2KHR(
+ VkPhysicalDevice physicalDevice,
+ VkPhysicalDeviceFeatures2KHR* pFeatures);
+
+VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties2KHR(
+ VkPhysicalDevice physicalDevice,
+ VkPhysicalDeviceProperties2KHR* pProperties);
+
+VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFormatProperties2KHR(
+ VkPhysicalDevice physicalDevice,
+ VkFormat format,
+ VkFormatProperties2KHR* pFormatProperties);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceImageFormatProperties2KHR(
+ VkPhysicalDevice physicalDevice,
+ const VkPhysicalDeviceImageFormatInfo2KHR* pImageFormatInfo,
+ VkImageFormatProperties2KHR* pImageFormatProperties);
+
+VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceQueueFamilyProperties2KHR(
+ VkPhysicalDevice physicalDevice,
+ uint32_t* pQueueFamilyPropertyCount,
+ VkQueueFamilyProperties2KHR* pQueueFamilyProperties);
+
+VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMemoryProperties2KHR(
+ VkPhysicalDevice physicalDevice,
+ VkPhysicalDeviceMemoryProperties2KHR* pMemoryProperties);
+
+VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceSparseImageFormatProperties2KHR(
+ VkPhysicalDevice physicalDevice,
+ const VkPhysicalDeviceSparseImageFormatInfo2KHR* pFormatInfo,
+ uint32_t* pPropertyCount,
+ VkSparseImageFormatProperties2KHR* pProperties);
+#endif
+
+#define VK_KHR_shader_draw_parameters 1
+#define VK_KHR_SHADER_DRAW_PARAMETERS_SPEC_VERSION 1
+#define VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME "VK_KHR_shader_draw_parameters"
+
+
+#define VK_KHR_maintenance1 1
+#define VK_KHR_MAINTENANCE1_SPEC_VERSION 1
+#define VK_KHR_MAINTENANCE1_EXTENSION_NAME "VK_KHR_maintenance1"
+
+typedef VkFlags VkCommandPoolTrimFlagsKHR;
+
+typedef void (VKAPI_PTR *PFN_vkTrimCommandPoolKHR)(VkDevice device, VkCommandPool commandPool, VkCommandPoolTrimFlagsKHR flags);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR void VKAPI_CALL vkTrimCommandPoolKHR(
+ VkDevice device,
+ VkCommandPool commandPool,
+ VkCommandPoolTrimFlagsKHR flags);
+#endif
+
+#define VK_KHR_external_memory_capabilities 1
+#define VK_LUID_SIZE_KHR 8
+#define VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_SPEC_VERSION 1
+#define VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME "VK_KHR_external_memory_capabilities"
+
+
+typedef enum VkExternalMemoryHandleTypeFlagBitsKHR {
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR = 0x00000001,
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR = 0x00000002,
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR = 0x00000004,
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT_KHR = 0x00000008,
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_KMT_BIT_KHR = 0x00000010,
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP_BIT_KHR = 0x00000020,
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE_BIT_KHR = 0x00000040,
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
+} VkExternalMemoryHandleTypeFlagBitsKHR;
+typedef VkFlags VkExternalMemoryHandleTypeFlagsKHR;
+
+typedef enum VkExternalMemoryFeatureFlagBitsKHR {
+ VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT_KHR = 0x00000001,
+ VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHR = 0x00000002,
+ VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHR = 0x00000004,
+ VK_EXTERNAL_MEMORY_FEATURE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
+} VkExternalMemoryFeatureFlagBitsKHR;
+typedef VkFlags VkExternalMemoryFeatureFlagsKHR;
+
+typedef struct VkExternalMemoryPropertiesKHR {
+ VkExternalMemoryFeatureFlagsKHR externalMemoryFeatures;
+ VkExternalMemoryHandleTypeFlagsKHR exportFromImportedHandleTypes;
+ VkExternalMemoryHandleTypeFlagsKHR compatibleHandleTypes;
+} VkExternalMemoryPropertiesKHR;
+
+typedef struct VkPhysicalDeviceExternalImageFormatInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkExternalMemoryHandleTypeFlagBitsKHR handleType;
+} VkPhysicalDeviceExternalImageFormatInfoKHR;
+
+typedef struct VkExternalImageFormatPropertiesKHR {
+ VkStructureType sType;
+ void* pNext;
+ VkExternalMemoryPropertiesKHR externalMemoryProperties;
+} VkExternalImageFormatPropertiesKHR;
+
+typedef struct VkPhysicalDeviceExternalBufferInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkBufferCreateFlags flags;
+ VkBufferUsageFlags usage;
+ VkExternalMemoryHandleTypeFlagBitsKHR handleType;
+} VkPhysicalDeviceExternalBufferInfoKHR;
+
+typedef struct VkExternalBufferPropertiesKHR {
+ VkStructureType sType;
+ void* pNext;
+ VkExternalMemoryPropertiesKHR externalMemoryProperties;
+} VkExternalBufferPropertiesKHR;
+
+typedef struct VkPhysicalDeviceIDPropertiesKHR {
+ VkStructureType sType;
+ void* pNext;
+ uint8_t deviceUUID[VK_UUID_SIZE];
+ uint8_t driverUUID[VK_UUID_SIZE];
+ uint8_t deviceLUID[VK_LUID_SIZE_KHR];
+ uint32_t deviceNodeMask;
+ VkBool32 deviceLUIDValid;
+} VkPhysicalDeviceIDPropertiesKHR;
+
+
+typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceExternalBufferPropertiesKHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalBufferInfoKHR* pExternalBufferInfo, VkExternalBufferPropertiesKHR* pExternalBufferProperties);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalBufferPropertiesKHR(
+ VkPhysicalDevice physicalDevice,
+ const VkPhysicalDeviceExternalBufferInfoKHR* pExternalBufferInfo,
+ VkExternalBufferPropertiesKHR* pExternalBufferProperties);
+#endif
+
+#define VK_KHR_external_memory 1
+#define VK_KHR_EXTERNAL_MEMORY_SPEC_VERSION 1
+#define VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME "VK_KHR_external_memory"
+#define VK_QUEUE_FAMILY_EXTERNAL_KHR (~0U-1)
+
+typedef struct VkExternalMemoryImageCreateInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkExternalMemoryHandleTypeFlagsKHR handleTypes;
+} VkExternalMemoryImageCreateInfoKHR;
+
+typedef struct VkExternalMemoryBufferCreateInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkExternalMemoryHandleTypeFlagsKHR handleTypes;
+} VkExternalMemoryBufferCreateInfoKHR;
+
+typedef struct VkExportMemoryAllocateInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkExternalMemoryHandleTypeFlagsKHR handleTypes;
+} VkExportMemoryAllocateInfoKHR;
+
+
+
+#ifdef VK_USE_PLATFORM_WIN32_KHR
+#define VK_KHR_external_memory_win32 1
+#define VK_KHR_EXTERNAL_MEMORY_WIN32_SPEC_VERSION 1
+#define VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME "VK_KHR_external_memory_win32"
+
+typedef struct VkImportMemoryWin32HandleInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkExternalMemoryHandleTypeFlagBitsKHR handleType;
+ HANDLE handle;
+ LPCWSTR name;
+} VkImportMemoryWin32HandleInfoKHR;
+
+typedef struct VkExportMemoryWin32HandleInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ const SECURITY_ATTRIBUTES* pAttributes;
+ DWORD dwAccess;
+ LPCWSTR name;
+} VkExportMemoryWin32HandleInfoKHR;
+
+typedef struct VkMemoryWin32HandlePropertiesKHR {
+ VkStructureType sType;
+ void* pNext;
+ uint32_t memoryTypeBits;
+} VkMemoryWin32HandlePropertiesKHR;
+
+typedef struct VkMemoryGetWin32HandleInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkDeviceMemory memory;
+ VkExternalMemoryHandleTypeFlagBitsKHR handleType;
+} VkMemoryGetWin32HandleInfoKHR;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryWin32HandleKHR)(VkDevice device, const VkMemoryGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle);
+typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryWin32HandlePropertiesKHR)(VkDevice device, VkExternalMemoryHandleTypeFlagBitsKHR handleType, HANDLE handle, VkMemoryWin32HandlePropertiesKHR* pMemoryWin32HandleProperties);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleKHR(
+ VkDevice device,
+ const VkMemoryGetWin32HandleInfoKHR* pGetWin32HandleInfo,
+ HANDLE* pHandle);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandlePropertiesKHR(
+ VkDevice device,
+ VkExternalMemoryHandleTypeFlagBitsKHR handleType,
+ HANDLE handle,
+ VkMemoryWin32HandlePropertiesKHR* pMemoryWin32HandleProperties);
+#endif
+#endif /* VK_USE_PLATFORM_WIN32_KHR */
+
+#define VK_KHR_external_memory_fd 1
+#define VK_KHR_EXTERNAL_MEMORY_FD_SPEC_VERSION 1
+#define VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME "VK_KHR_external_memory_fd"
+
+typedef struct VkImportMemoryFdInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkExternalMemoryHandleTypeFlagBitsKHR handleType;
+ int fd;
+} VkImportMemoryFdInfoKHR;
+
+typedef struct VkMemoryFdPropertiesKHR {
+ VkStructureType sType;
+ void* pNext;
+ uint32_t memoryTypeBits;
+} VkMemoryFdPropertiesKHR;
+
+typedef struct VkMemoryGetFdInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkDeviceMemory memory;
+ VkExternalMemoryHandleTypeFlagBitsKHR handleType;
+} VkMemoryGetFdInfoKHR;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryFdKHR)(VkDevice device, const VkMemoryGetFdInfoKHR* pGetFdInfo, int* pFd);
+typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryFdPropertiesKHR)(VkDevice device, VkExternalMemoryHandleTypeFlagBitsKHR handleType, int fd, VkMemoryFdPropertiesKHR* pMemoryFdProperties);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryFdKHR(
+ VkDevice device,
+ const VkMemoryGetFdInfoKHR* pGetFdInfo,
+ int* pFd);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryFdPropertiesKHR(
+ VkDevice device,
+ VkExternalMemoryHandleTypeFlagBitsKHR handleType,
+ int fd,
+ VkMemoryFdPropertiesKHR* pMemoryFdProperties);
+#endif
+
+#ifdef VK_USE_PLATFORM_WIN32_KHR
+#define VK_KHR_win32_keyed_mutex 1
+#define VK_KHR_WIN32_KEYED_MUTEX_SPEC_VERSION 1
+#define VK_KHR_WIN32_KEYED_MUTEX_EXTENSION_NAME "VK_KHR_win32_keyed_mutex"
+
+typedef struct VkWin32KeyedMutexAcquireReleaseInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t acquireCount;
+ const VkDeviceMemory* pAcquireSyncs;
+ const uint64_t* pAcquireKeys;
+ const uint32_t* pAcquireTimeouts;
+ uint32_t releaseCount;
+ const VkDeviceMemory* pReleaseSyncs;
+ const uint64_t* pReleaseKeys;
+} VkWin32KeyedMutexAcquireReleaseInfoKHR;
+
+
+#endif /* VK_USE_PLATFORM_WIN32_KHR */
+
+#define VK_KHR_external_semaphore_capabilities 1
+#define VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_SPEC_VERSION 1
+#define VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME "VK_KHR_external_semaphore_capabilities"
+
+
+typedef enum VkExternalSemaphoreHandleTypeFlagBitsKHR {
+ VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR = 0x00000001,
+ VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR = 0x00000002,
+ VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR = 0x00000004,
+ VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT_KHR = 0x00000008,
+ VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR = 0x00000010,
+ VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
+} VkExternalSemaphoreHandleTypeFlagBitsKHR;
+typedef VkFlags VkExternalSemaphoreHandleTypeFlagsKHR;
+
+typedef enum VkExternalSemaphoreFeatureFlagBitsKHR {
+ VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR = 0x00000001,
+ VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR = 0x00000002,
+ VK_EXTERNAL_SEMAPHORE_FEATURE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
+} VkExternalSemaphoreFeatureFlagBitsKHR;
+typedef VkFlags VkExternalSemaphoreFeatureFlagsKHR;
+
+typedef struct VkPhysicalDeviceExternalSemaphoreInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkExternalSemaphoreHandleTypeFlagBitsKHR handleType;
+} VkPhysicalDeviceExternalSemaphoreInfoKHR;
+
+typedef struct VkExternalSemaphorePropertiesKHR {
+ VkStructureType sType;
+ void* pNext;
+ VkExternalSemaphoreHandleTypeFlagsKHR exportFromImportedHandleTypes;
+ VkExternalSemaphoreHandleTypeFlagsKHR compatibleHandleTypes;
+ VkExternalSemaphoreFeatureFlagsKHR externalSemaphoreFeatures;
+} VkExternalSemaphorePropertiesKHR;
+
+
+typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalSemaphoreInfoKHR* pExternalSemaphoreInfo, VkExternalSemaphorePropertiesKHR* pExternalSemaphoreProperties);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalSemaphorePropertiesKHR(
+ VkPhysicalDevice physicalDevice,
+ const VkPhysicalDeviceExternalSemaphoreInfoKHR* pExternalSemaphoreInfo,
+ VkExternalSemaphorePropertiesKHR* pExternalSemaphoreProperties);
+#endif
+
+#define VK_KHR_external_semaphore 1
+#define VK_KHR_EXTERNAL_SEMAPHORE_SPEC_VERSION 1
+#define VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME "VK_KHR_external_semaphore"
+
+
+typedef enum VkSemaphoreImportFlagBitsKHR {
+ VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR = 0x00000001,
+ VK_SEMAPHORE_IMPORT_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
+} VkSemaphoreImportFlagBitsKHR;
+typedef VkFlags VkSemaphoreImportFlagsKHR;
+
+typedef struct VkExportSemaphoreCreateInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkExternalSemaphoreHandleTypeFlagsKHR handleTypes;
+} VkExportSemaphoreCreateInfoKHR;
+
+
+
+#ifdef VK_USE_PLATFORM_WIN32_KHR
+#define VK_KHR_external_semaphore_win32 1
+#define VK_KHR_EXTERNAL_SEMAPHORE_WIN32_SPEC_VERSION 1
+#define VK_KHR_EXTERNAL_SEMAPHORE_WIN32_EXTENSION_NAME "VK_KHR_external_semaphore_win32"
+
+typedef struct VkImportSemaphoreWin32HandleInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkSemaphore semaphore;
+ VkSemaphoreImportFlagsKHR flags;
+ VkExternalSemaphoreHandleTypeFlagBitsKHR handleType;
+ HANDLE handle;
+ LPCWSTR name;
+} VkImportSemaphoreWin32HandleInfoKHR;
+
+typedef struct VkExportSemaphoreWin32HandleInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ const SECURITY_ATTRIBUTES* pAttributes;
+ DWORD dwAccess;
+ LPCWSTR name;
+} VkExportSemaphoreWin32HandleInfoKHR;
+
+typedef struct VkD3D12FenceSubmitInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t waitSemaphoreValuesCount;
+ const uint64_t* pWaitSemaphoreValues;
+ uint32_t signalSemaphoreValuesCount;
+ const uint64_t* pSignalSemaphoreValues;
+} VkD3D12FenceSubmitInfoKHR;
+
+typedef struct VkSemaphoreGetWin32HandleInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkSemaphore semaphore;
+ VkExternalSemaphoreHandleTypeFlagBitsKHR handleType;
+} VkSemaphoreGetWin32HandleInfoKHR;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkImportSemaphoreWin32HandleKHR)(VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR* pImportSemaphoreWin32HandleInfo);
+typedef VkResult (VKAPI_PTR *PFN_vkGetSemaphoreWin32HandleKHR)(VkDevice device, const VkSemaphoreGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkImportSemaphoreWin32HandleKHR(
+ VkDevice device,
+ const VkImportSemaphoreWin32HandleInfoKHR* pImportSemaphoreWin32HandleInfo);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetSemaphoreWin32HandleKHR(
+ VkDevice device,
+ const VkSemaphoreGetWin32HandleInfoKHR* pGetWin32HandleInfo,
+ HANDLE* pHandle);
+#endif
+#endif /* VK_USE_PLATFORM_WIN32_KHR */
+
+#define VK_KHR_external_semaphore_fd 1
+#define VK_KHR_EXTERNAL_SEMAPHORE_FD_SPEC_VERSION 1
+#define VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME "VK_KHR_external_semaphore_fd"
+
+typedef struct VkImportSemaphoreFdInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkSemaphore semaphore;
+ VkSemaphoreImportFlagsKHR flags;
+ VkExternalSemaphoreHandleTypeFlagBitsKHR handleType;
+ int fd;
+} VkImportSemaphoreFdInfoKHR;
+
+typedef struct VkSemaphoreGetFdInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkSemaphore semaphore;
+ VkExternalSemaphoreHandleTypeFlagBitsKHR handleType;
+} VkSemaphoreGetFdInfoKHR;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkImportSemaphoreFdKHR)(VkDevice device, const VkImportSemaphoreFdInfoKHR* pImportSemaphoreFdInfo);
+typedef VkResult (VKAPI_PTR *PFN_vkGetSemaphoreFdKHR)(VkDevice device, const VkSemaphoreGetFdInfoKHR* pGetFdInfo, int* pFd);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkImportSemaphoreFdKHR(
+ VkDevice device,
+ const VkImportSemaphoreFdInfoKHR* pImportSemaphoreFdInfo);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetSemaphoreFdKHR(
+ VkDevice device,
+ const VkSemaphoreGetFdInfoKHR* pGetFdInfo,
+ int* pFd);
+#endif
+
+#define VK_KHR_push_descriptor 1
+#define VK_KHR_PUSH_DESCRIPTOR_SPEC_VERSION 1
+#define VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME "VK_KHR_push_descriptor"
+
+typedef struct VkPhysicalDevicePushDescriptorPropertiesKHR {
+ VkStructureType sType;
+ void* pNext;
+ uint32_t maxPushDescriptors;
+} VkPhysicalDevicePushDescriptorPropertiesKHR;
+
+
+typedef void (VKAPI_PTR *PFN_vkCmdPushDescriptorSetKHR)(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, uint32_t set, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR void VKAPI_CALL vkCmdPushDescriptorSetKHR(
+ VkCommandBuffer commandBuffer,
+ VkPipelineBindPoint pipelineBindPoint,
+ VkPipelineLayout layout,
+ uint32_t set,
+ uint32_t descriptorWriteCount,
+ const VkWriteDescriptorSet* pDescriptorWrites);
+#endif
+
+#define VK_KHR_16bit_storage 1
+#define VK_KHR_16BIT_STORAGE_SPEC_VERSION 1
+#define VK_KHR_16BIT_STORAGE_EXTENSION_NAME "VK_KHR_16bit_storage"
+
+typedef struct VkPhysicalDevice16BitStorageFeaturesKHR {
+ VkStructureType sType;
+ void* pNext;
+ VkBool32 storageBuffer16BitAccess;
+ VkBool32 uniformAndStorageBuffer16BitAccess;
+ VkBool32 storagePushConstant16;
+ VkBool32 storageInputOutput16;
+} VkPhysicalDevice16BitStorageFeaturesKHR;
+
+
+
+#define VK_KHR_incremental_present 1
+#define VK_KHR_INCREMENTAL_PRESENT_SPEC_VERSION 1
+#define VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME "VK_KHR_incremental_present"
+
+typedef struct VkRectLayerKHR {
+ VkOffset2D offset;
+ VkExtent2D extent;
+ uint32_t layer;
+} VkRectLayerKHR;
+
+typedef struct VkPresentRegionKHR {
+ uint32_t rectangleCount;
+ const VkRectLayerKHR* pRectangles;
+} VkPresentRegionKHR;
+
+typedef struct VkPresentRegionsKHR {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t swapchainCount;
+ const VkPresentRegionKHR* pRegions;
+} VkPresentRegionsKHR;
+
+
+
+#define VK_KHR_descriptor_update_template 1
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorUpdateTemplateKHR)
+
+#define VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_SPEC_VERSION 1
+#define VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME "VK_KHR_descriptor_update_template"
+
+
+typedef enum VkDescriptorUpdateTemplateTypeKHR {
+ VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR = 0,
+ VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR = 1,
+ VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_BEGIN_RANGE_KHR = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR,
+ VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_END_RANGE_KHR = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR,
+ VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_RANGE_SIZE_KHR = (VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR - VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR + 1),
+ VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_MAX_ENUM_KHR = 0x7FFFFFFF
+} VkDescriptorUpdateTemplateTypeKHR;
+
+typedef VkFlags VkDescriptorUpdateTemplateCreateFlagsKHR;
+
+typedef struct VkDescriptorUpdateTemplateEntryKHR {
+ uint32_t dstBinding;
+ uint32_t dstArrayElement;
+ uint32_t descriptorCount;
+ VkDescriptorType descriptorType;
+ size_t offset;
+ size_t stride;
+} VkDescriptorUpdateTemplateEntryKHR;
+
+typedef struct VkDescriptorUpdateTemplateCreateInfoKHR {
+ VkStructureType sType;
+ void* pNext;
+ VkDescriptorUpdateTemplateCreateFlagsKHR flags;
+ uint32_t descriptorUpdateEntryCount;
+ const VkDescriptorUpdateTemplateEntryKHR* pDescriptorUpdateEntries;
+ VkDescriptorUpdateTemplateTypeKHR templateType;
+ VkDescriptorSetLayout descriptorSetLayout;
+ VkPipelineBindPoint pipelineBindPoint;
+ VkPipelineLayout pipelineLayout;
+ uint32_t set;
+} VkDescriptorUpdateTemplateCreateInfoKHR;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkCreateDescriptorUpdateTemplateKHR)(VkDevice device, const VkDescriptorUpdateTemplateCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorUpdateTemplateKHR* pDescriptorUpdateTemplate);
+typedef void (VKAPI_PTR *PFN_vkDestroyDescriptorUpdateTemplateKHR)(VkDevice device, VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, const VkAllocationCallbacks* pAllocator);
+typedef void (VKAPI_PTR *PFN_vkUpdateDescriptorSetWithTemplateKHR)(VkDevice device, VkDescriptorSet descriptorSet, VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, const void* pData);
+typedef void (VKAPI_PTR *PFN_vkCmdPushDescriptorSetWithTemplateKHR)(VkCommandBuffer commandBuffer, VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, VkPipelineLayout layout, uint32_t set, const void* pData);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorUpdateTemplateKHR(
+ VkDevice device,
+ const VkDescriptorUpdateTemplateCreateInfoKHR* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkDescriptorUpdateTemplateKHR* pDescriptorUpdateTemplate);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorUpdateTemplateKHR(
+ VkDevice device,
+ VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSetWithTemplateKHR(
+ VkDevice device,
+ VkDescriptorSet descriptorSet,
+ VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
+ const void* pData);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdPushDescriptorSetWithTemplateKHR(
+ VkCommandBuffer commandBuffer,
+ VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
+ VkPipelineLayout layout,
+ uint32_t set,
+ const void* pData);
+#endif
+
+#define VK_KHR_shared_presentable_image 1
+#define VK_KHR_SHARED_PRESENTABLE_IMAGE_SPEC_VERSION 1
+#define VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME "VK_KHR_shared_presentable_image"
+
+typedef struct VkSharedPresentSurfaceCapabilitiesKHR {
+ VkStructureType sType;
+ void* pNext;
+ VkImageUsageFlags sharedPresentSupportedUsageFlags;
+} VkSharedPresentSurfaceCapabilitiesKHR;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainStatusKHR)(VkDevice device, VkSwapchainKHR swapchain);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainStatusKHR(
+ VkDevice device,
+ VkSwapchainKHR swapchain);
+#endif
+
+#define VK_KHR_external_fence_capabilities 1
+#define VK_KHR_EXTERNAL_FENCE_CAPABILITIES_SPEC_VERSION 1
+#define VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME "VK_KHR_external_fence_capabilities"
+
+
+typedef enum VkExternalFenceHandleTypeFlagBitsKHR {
+ VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR = 0x00000001,
+ VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR = 0x00000002,
+ VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR = 0x00000004,
+ VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR = 0x00000008,
+ VK_EXTERNAL_FENCE_HANDLE_TYPE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
+} VkExternalFenceHandleTypeFlagBitsKHR;
+typedef VkFlags VkExternalFenceHandleTypeFlagsKHR;
+
+typedef enum VkExternalFenceFeatureFlagBitsKHR {
+ VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR = 0x00000001,
+ VK_EXTERNAL_FENCE_FEATURE_IMPORTABLE_BIT_KHR = 0x00000002,
+ VK_EXTERNAL_FENCE_FEATURE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
+} VkExternalFenceFeatureFlagBitsKHR;
+typedef VkFlags VkExternalFenceFeatureFlagsKHR;
+
+typedef struct VkPhysicalDeviceExternalFenceInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkExternalFenceHandleTypeFlagBitsKHR handleType;
+} VkPhysicalDeviceExternalFenceInfoKHR;
+
+typedef struct VkExternalFencePropertiesKHR {
+ VkStructureType sType;
+ void* pNext;
+ VkExternalFenceHandleTypeFlagsKHR exportFromImportedHandleTypes;
+ VkExternalFenceHandleTypeFlagsKHR compatibleHandleTypes;
+ VkExternalFenceFeatureFlagsKHR externalFenceFeatures;
+} VkExternalFencePropertiesKHR;
+
+
+typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalFenceInfoKHR* pExternalFenceInfo, VkExternalFencePropertiesKHR* pExternalFenceProperties);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalFencePropertiesKHR(
+ VkPhysicalDevice physicalDevice,
+ const VkPhysicalDeviceExternalFenceInfoKHR* pExternalFenceInfo,
+ VkExternalFencePropertiesKHR* pExternalFenceProperties);
+#endif
+
+#define VK_KHR_external_fence 1
+#define VK_KHR_EXTERNAL_FENCE_SPEC_VERSION 1
+#define VK_KHR_EXTERNAL_FENCE_EXTENSION_NAME "VK_KHR_external_fence"
+
+
+typedef enum VkFenceImportFlagBitsKHR {
+ VK_FENCE_IMPORT_TEMPORARY_BIT_KHR = 0x00000001,
+ VK_FENCE_IMPORT_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF
+} VkFenceImportFlagBitsKHR;
+typedef VkFlags VkFenceImportFlagsKHR;
+
+typedef struct VkExportFenceCreateInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkExternalFenceHandleTypeFlagsKHR handleTypes;
+} VkExportFenceCreateInfoKHR;
+
+
+
+#ifdef VK_USE_PLATFORM_WIN32_KHR
+#define VK_KHR_external_fence_win32 1
+#define VK_KHR_EXTERNAL_FENCE_WIN32_SPEC_VERSION 1
+#define VK_KHR_EXTERNAL_FENCE_WIN32_EXTENSION_NAME "VK_KHR_external_fence_win32"
+
+typedef struct VkImportFenceWin32HandleInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkFence fence;
+ VkFenceImportFlagsKHR flags;
+ VkExternalFenceHandleTypeFlagBitsKHR handleType;
+ HANDLE handle;
+ LPCWSTR name;
+} VkImportFenceWin32HandleInfoKHR;
+
+typedef struct VkExportFenceWin32HandleInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ const SECURITY_ATTRIBUTES* pAttributes;
+ DWORD dwAccess;
+ LPCWSTR name;
+} VkExportFenceWin32HandleInfoKHR;
+
+typedef struct VkFenceGetWin32HandleInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkFence fence;
+ VkExternalFenceHandleTypeFlagBitsKHR handleType;
+} VkFenceGetWin32HandleInfoKHR;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkImportFenceWin32HandleKHR)(VkDevice device, const VkImportFenceWin32HandleInfoKHR* pImportFenceWin32HandleInfo);
+typedef VkResult (VKAPI_PTR *PFN_vkGetFenceWin32HandleKHR)(VkDevice device, const VkFenceGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkImportFenceWin32HandleKHR(
+ VkDevice device,
+ const VkImportFenceWin32HandleInfoKHR* pImportFenceWin32HandleInfo);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceWin32HandleKHR(
+ VkDevice device,
+ const VkFenceGetWin32HandleInfoKHR* pGetWin32HandleInfo,
+ HANDLE* pHandle);
+#endif
+#endif /* VK_USE_PLATFORM_WIN32_KHR */
+
+#define VK_KHR_external_fence_fd 1
+#define VK_KHR_EXTERNAL_FENCE_FD_SPEC_VERSION 1
+#define VK_KHR_EXTERNAL_FENCE_FD_EXTENSION_NAME "VK_KHR_external_fence_fd"
+
+typedef struct VkImportFenceFdInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkFence fence;
+ VkFenceImportFlagsKHR flags;
+ VkExternalFenceHandleTypeFlagBitsKHR handleType;
+ int fd;
+} VkImportFenceFdInfoKHR;
+
+typedef struct VkFenceGetFdInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkFence fence;
+ VkExternalFenceHandleTypeFlagBitsKHR handleType;
+} VkFenceGetFdInfoKHR;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkImportFenceFdKHR)(VkDevice device, const VkImportFenceFdInfoKHR* pImportFenceFdInfo);
+typedef VkResult (VKAPI_PTR *PFN_vkGetFenceFdKHR)(VkDevice device, const VkFenceGetFdInfoKHR* pGetFdInfo, int* pFd);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkImportFenceFdKHR(
+ VkDevice device,
+ const VkImportFenceFdInfoKHR* pImportFenceFdInfo);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceFdKHR(
+ VkDevice device,
+ const VkFenceGetFdInfoKHR* pGetFdInfo,
+ int* pFd);
+#endif
+
+#define VK_KHR_get_surface_capabilities2 1
+#define VK_KHR_GET_SURFACE_CAPABILITIES_2_SPEC_VERSION 1
+#define VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME "VK_KHR_get_surface_capabilities2"
+
+typedef struct VkPhysicalDeviceSurfaceInfo2KHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkSurfaceKHR surface;
+} VkPhysicalDeviceSurfaceInfo2KHR;
+
+typedef struct VkSurfaceCapabilities2KHR {
+ VkStructureType sType;
+ void* pNext;
+ VkSurfaceCapabilitiesKHR surfaceCapabilities;
+} VkSurfaceCapabilities2KHR;
+
+typedef struct VkSurfaceFormat2KHR {
+ VkStructureType sType;
+ void* pNext;
+ VkSurfaceFormatKHR surfaceFormat;
+} VkSurfaceFormat2KHR;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, VkSurfaceCapabilities2KHR* pSurfaceCapabilities);
+typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfaceFormats2KHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, uint32_t* pSurfaceFormatCount, VkSurfaceFormat2KHR* pSurfaceFormats);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilities2KHR(
+ VkPhysicalDevice physicalDevice,
+ const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
+ VkSurfaceCapabilities2KHR* pSurfaceCapabilities);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormats2KHR(
+ VkPhysicalDevice physicalDevice,
+ const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
+ uint32_t* pSurfaceFormatCount,
+ VkSurfaceFormat2KHR* pSurfaceFormats);
+#endif
+
+#define VK_KHR_variable_pointers 1
+#define VK_KHR_VARIABLE_POINTERS_SPEC_VERSION 1
+#define VK_KHR_VARIABLE_POINTERS_EXTENSION_NAME "VK_KHR_variable_pointers"
+
+typedef struct VkPhysicalDeviceVariablePointerFeaturesKHR {
+ VkStructureType sType;
+ void* pNext;
+ VkBool32 variablePointersStorageBuffer;
+ VkBool32 variablePointers;
+} VkPhysicalDeviceVariablePointerFeaturesKHR;
+
+
+
+#define VK_KHR_dedicated_allocation 1
+#define VK_KHR_DEDICATED_ALLOCATION_SPEC_VERSION 3
+#define VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME "VK_KHR_dedicated_allocation"
+
+typedef struct VkMemoryDedicatedRequirementsKHR {
+ VkStructureType sType;
+ void* pNext;
+ VkBool32 prefersDedicatedAllocation;
+ VkBool32 requiresDedicatedAllocation;
+} VkMemoryDedicatedRequirementsKHR;
+
+typedef struct VkMemoryDedicatedAllocateInfoKHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkImage image;
+ VkBuffer buffer;
+} VkMemoryDedicatedAllocateInfoKHR;
+
+
+
+#define VK_KHR_storage_buffer_storage_class 1
+#define VK_KHR_STORAGE_BUFFER_STORAGE_CLASS_SPEC_VERSION 1
+#define VK_KHR_STORAGE_BUFFER_STORAGE_CLASS_EXTENSION_NAME "VK_KHR_storage_buffer_storage_class"
+
+
+#define VK_KHR_relaxed_block_layout 1
+#define VK_KHR_RELAXED_BLOCK_LAYOUT_SPEC_VERSION 1
+#define VK_KHR_RELAXED_BLOCK_LAYOUT_EXTENSION_NAME "VK_KHR_relaxed_block_layout"
+
+
+#define VK_KHR_get_memory_requirements2 1
+#define VK_KHR_GET_MEMORY_REQUIREMENTS_2_SPEC_VERSION 1
+#define VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME "VK_KHR_get_memory_requirements2"
+
+typedef struct VkBufferMemoryRequirementsInfo2KHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkBuffer buffer;
+} VkBufferMemoryRequirementsInfo2KHR;
+
+typedef struct VkImageMemoryRequirementsInfo2KHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkImage image;
+} VkImageMemoryRequirementsInfo2KHR;
+
+typedef struct VkImageSparseMemoryRequirementsInfo2KHR {
+ VkStructureType sType;
+ const void* pNext;
+ VkImage image;
+} VkImageSparseMemoryRequirementsInfo2KHR;
+
+typedef struct VkMemoryRequirements2KHR {
+ VkStructureType sType;
+ void* pNext;
+ VkMemoryRequirements memoryRequirements;
+} VkMemoryRequirements2KHR;
+
+typedef struct VkSparseImageMemoryRequirements2KHR {
+ VkStructureType sType;
+ void* pNext;
+ VkSparseImageMemoryRequirements memoryRequirements;
+} VkSparseImageMemoryRequirements2KHR;
+
+
+typedef void (VKAPI_PTR *PFN_vkGetImageMemoryRequirements2KHR)(VkDevice device, const VkImageMemoryRequirementsInfo2KHR* pInfo, VkMemoryRequirements2KHR* pMemoryRequirements);
+typedef void (VKAPI_PTR *PFN_vkGetBufferMemoryRequirements2KHR)(VkDevice device, const VkBufferMemoryRequirementsInfo2KHR* pInfo, VkMemoryRequirements2KHR* pMemoryRequirements);
+typedef void (VKAPI_PTR *PFN_vkGetImageSparseMemoryRequirements2KHR)(VkDevice device, const VkImageSparseMemoryRequirementsInfo2KHR* pInfo, uint32_t* pSparseMemoryRequirementCount, VkSparseImageMemoryRequirements2KHR* pSparseMemoryRequirements);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR void VKAPI_CALL vkGetImageMemoryRequirements2KHR(
+ VkDevice device,
+ const VkImageMemoryRequirementsInfo2KHR* pInfo,
+ VkMemoryRequirements2KHR* pMemoryRequirements);
+
+VKAPI_ATTR void VKAPI_CALL vkGetBufferMemoryRequirements2KHR(
+ VkDevice device,
+ const VkBufferMemoryRequirementsInfo2KHR* pInfo,
+ VkMemoryRequirements2KHR* pMemoryRequirements);
+
+VKAPI_ATTR void VKAPI_CALL vkGetImageSparseMemoryRequirements2KHR(
+ VkDevice device,
+ const VkImageSparseMemoryRequirementsInfo2KHR* pInfo,
+ uint32_t* pSparseMemoryRequirementCount,
+ VkSparseImageMemoryRequirements2KHR* pSparseMemoryRequirements);
+#endif
+
+#define VK_EXT_debug_report 1
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDebugReportCallbackEXT)
+
+#define VK_EXT_DEBUG_REPORT_SPEC_VERSION 8
+#define VK_EXT_DEBUG_REPORT_EXTENSION_NAME "VK_EXT_debug_report"
+#define VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT
+#define VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT_EXT
+
+
+typedef enum VkDebugReportObjectTypeEXT {
+ VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT = 0,
+ VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT = 1,
+ VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT = 2,
+ VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT = 3,
+ VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT = 4,
+ VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT = 5,
+ VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT = 6,
+ VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT = 7,
+ VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT = 8,
+ VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT = 9,
+ VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT = 10,
+ VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT = 11,
+ VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT = 12,
+ VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT = 13,
+ VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT = 14,
+ VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT = 15,
+ VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT = 16,
+ VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT = 17,
+ VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT = 18,
+ VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT = 19,
+ VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT = 20,
+ VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT = 21,
+ VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT = 22,
+ VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT = 23,
+ VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT = 24,
+ VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT = 25,
+ VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT = 26,
+ VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT = 27,
+ VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT_EXT = 28,
+ VK_DEBUG_REPORT_OBJECT_TYPE_DISPLAY_KHR_EXT = 29,
+ VK_DEBUG_REPORT_OBJECT_TYPE_DISPLAY_MODE_KHR_EXT = 30,
+ VK_DEBUG_REPORT_OBJECT_TYPE_OBJECT_TABLE_NVX_EXT = 31,
+ VK_DEBUG_REPORT_OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_NVX_EXT = 32,
+ VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_KHR_EXT = 1000085000,
+ VK_DEBUG_REPORT_OBJECT_TYPE_BEGIN_RANGE_EXT = VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,
+ VK_DEBUG_REPORT_OBJECT_TYPE_END_RANGE_EXT = VK_DEBUG_REPORT_OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_NVX_EXT,
+ VK_DEBUG_REPORT_OBJECT_TYPE_RANGE_SIZE_EXT = (VK_DEBUG_REPORT_OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_NVX_EXT - VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT + 1),
+ VK_DEBUG_REPORT_OBJECT_TYPE_MAX_ENUM_EXT = 0x7FFFFFFF
+} VkDebugReportObjectTypeEXT;
+
+
+typedef enum VkDebugReportFlagBitsEXT {
+ VK_DEBUG_REPORT_INFORMATION_BIT_EXT = 0x00000001,
+ VK_DEBUG_REPORT_WARNING_BIT_EXT = 0x00000002,
+ VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT = 0x00000004,
+ VK_DEBUG_REPORT_ERROR_BIT_EXT = 0x00000008,
+ VK_DEBUG_REPORT_DEBUG_BIT_EXT = 0x00000010,
+ VK_DEBUG_REPORT_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF
+} VkDebugReportFlagBitsEXT;
+typedef VkFlags VkDebugReportFlagsEXT;
+
+typedef VkBool32 (VKAPI_PTR *PFN_vkDebugReportCallbackEXT)(
+ VkDebugReportFlagsEXT flags,
+ VkDebugReportObjectTypeEXT objectType,
+ uint64_t object,
+ size_t location,
+ int32_t messageCode,
+ const char* pLayerPrefix,
+ const char* pMessage,
+ void* pUserData);
+
+typedef struct VkDebugReportCallbackCreateInfoEXT {
+ VkStructureType sType;
+ const void* pNext;
+ VkDebugReportFlagsEXT flags;
+ PFN_vkDebugReportCallbackEXT pfnCallback;
+ void* pUserData;
+} VkDebugReportCallbackCreateInfoEXT;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkCreateDebugReportCallbackEXT)(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugReportCallbackEXT* pCallback);
+typedef void (VKAPI_PTR *PFN_vkDestroyDebugReportCallbackEXT)(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks* pAllocator);
+typedef void (VKAPI_PTR *PFN_vkDebugReportMessageEXT)(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, uint64_t object, size_t location, int32_t messageCode, const char* pLayerPrefix, const char* pMessage);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
+ VkInstance instance,
+ const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkDebugReportCallbackEXT* pCallback);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
+ VkInstance instance,
+ VkDebugReportCallbackEXT callback,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
+ VkInstance instance,
+ VkDebugReportFlagsEXT flags,
+ VkDebugReportObjectTypeEXT objectType,
+ uint64_t object,
+ size_t location,
+ int32_t messageCode,
+ const char* pLayerPrefix,
+ const char* pMessage);
+#endif
+
+#define VK_NV_glsl_shader 1
+#define VK_NV_GLSL_SHADER_SPEC_VERSION 1
+#define VK_NV_GLSL_SHADER_EXTENSION_NAME "VK_NV_glsl_shader"
+
+
+#define VK_EXT_depth_range_unrestricted 1
+#define VK_EXT_DEPTH_RANGE_UNRESTRICTED_SPEC_VERSION 1
+#define VK_EXT_DEPTH_RANGE_UNRESTRICTED_EXTENSION_NAME "VK_EXT_depth_range_unrestricted"
+
+
+#define VK_IMG_filter_cubic 1
+#define VK_IMG_FILTER_CUBIC_SPEC_VERSION 1
+#define VK_IMG_FILTER_CUBIC_EXTENSION_NAME "VK_IMG_filter_cubic"
+
+
+#define VK_AMD_rasterization_order 1
+#define VK_AMD_RASTERIZATION_ORDER_SPEC_VERSION 1
+#define VK_AMD_RASTERIZATION_ORDER_EXTENSION_NAME "VK_AMD_rasterization_order"
+
+
+typedef enum VkRasterizationOrderAMD {
+ VK_RASTERIZATION_ORDER_STRICT_AMD = 0,
+ VK_RASTERIZATION_ORDER_RELAXED_AMD = 1,
+ VK_RASTERIZATION_ORDER_BEGIN_RANGE_AMD = VK_RASTERIZATION_ORDER_STRICT_AMD,
+ VK_RASTERIZATION_ORDER_END_RANGE_AMD = VK_RASTERIZATION_ORDER_RELAXED_AMD,
+ VK_RASTERIZATION_ORDER_RANGE_SIZE_AMD = (VK_RASTERIZATION_ORDER_RELAXED_AMD - VK_RASTERIZATION_ORDER_STRICT_AMD + 1),
+ VK_RASTERIZATION_ORDER_MAX_ENUM_AMD = 0x7FFFFFFF
+} VkRasterizationOrderAMD;
+
+typedef struct VkPipelineRasterizationStateRasterizationOrderAMD {
+ VkStructureType sType;
+ const void* pNext;
+ VkRasterizationOrderAMD rasterizationOrder;
+} VkPipelineRasterizationStateRasterizationOrderAMD;
+
+
+
+#define VK_AMD_shader_trinary_minmax 1
+#define VK_AMD_SHADER_TRINARY_MINMAX_SPEC_VERSION 1
+#define VK_AMD_SHADER_TRINARY_MINMAX_EXTENSION_NAME "VK_AMD_shader_trinary_minmax"
+
+
+#define VK_AMD_shader_explicit_vertex_parameter 1
+#define VK_AMD_SHADER_EXPLICIT_VERTEX_PARAMETER_SPEC_VERSION 1
+#define VK_AMD_SHADER_EXPLICIT_VERTEX_PARAMETER_EXTENSION_NAME "VK_AMD_shader_explicit_vertex_parameter"
+
+
+#define VK_EXT_debug_marker 1
+#define VK_EXT_DEBUG_MARKER_SPEC_VERSION 4
+#define VK_EXT_DEBUG_MARKER_EXTENSION_NAME "VK_EXT_debug_marker"
+
+typedef struct VkDebugMarkerObjectNameInfoEXT {
+ VkStructureType sType;
+ const void* pNext;
+ VkDebugReportObjectTypeEXT objectType;
+ uint64_t object;
+ const char* pObjectName;
+} VkDebugMarkerObjectNameInfoEXT;
+
+typedef struct VkDebugMarkerObjectTagInfoEXT {
+ VkStructureType sType;
+ const void* pNext;
+ VkDebugReportObjectTypeEXT objectType;
+ uint64_t object;
+ uint64_t tagName;
+ size_t tagSize;
+ const void* pTag;
+} VkDebugMarkerObjectTagInfoEXT;
+
+typedef struct VkDebugMarkerMarkerInfoEXT {
+ VkStructureType sType;
+ const void* pNext;
+ const char* pMarkerName;
+ float color[4];
+} VkDebugMarkerMarkerInfoEXT;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkDebugMarkerSetObjectTagEXT)(VkDevice device, const VkDebugMarkerObjectTagInfoEXT* pTagInfo);
+typedef VkResult (VKAPI_PTR *PFN_vkDebugMarkerSetObjectNameEXT)(VkDevice device, const VkDebugMarkerObjectNameInfoEXT* pNameInfo);
+typedef void (VKAPI_PTR *PFN_vkCmdDebugMarkerBeginEXT)(VkCommandBuffer commandBuffer, const VkDebugMarkerMarkerInfoEXT* pMarkerInfo);
+typedef void (VKAPI_PTR *PFN_vkCmdDebugMarkerEndEXT)(VkCommandBuffer commandBuffer);
+typedef void (VKAPI_PTR *PFN_vkCmdDebugMarkerInsertEXT)(VkCommandBuffer commandBuffer, const VkDebugMarkerMarkerInfoEXT* pMarkerInfo);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkDebugMarkerSetObjectTagEXT(
+ VkDevice device,
+ const VkDebugMarkerObjectTagInfoEXT* pTagInfo);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkDebugMarkerSetObjectNameEXT(
+ VkDevice device,
+ const VkDebugMarkerObjectNameInfoEXT* pNameInfo);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdDebugMarkerBeginEXT(
+ VkCommandBuffer commandBuffer,
+ const VkDebugMarkerMarkerInfoEXT* pMarkerInfo);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdDebugMarkerEndEXT(
+ VkCommandBuffer commandBuffer);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdDebugMarkerInsertEXT(
+ VkCommandBuffer commandBuffer,
+ const VkDebugMarkerMarkerInfoEXT* pMarkerInfo);
+#endif
+
+#define VK_AMD_gcn_shader 1
+#define VK_AMD_GCN_SHADER_SPEC_VERSION 1
+#define VK_AMD_GCN_SHADER_EXTENSION_NAME "VK_AMD_gcn_shader"
+
+
+#define VK_NV_dedicated_allocation 1
+#define VK_NV_DEDICATED_ALLOCATION_SPEC_VERSION 1
+#define VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME "VK_NV_dedicated_allocation"
+
+typedef struct VkDedicatedAllocationImageCreateInfoNV {
+ VkStructureType sType;
+ const void* pNext;
+ VkBool32 dedicatedAllocation;
+} VkDedicatedAllocationImageCreateInfoNV;
+
+typedef struct VkDedicatedAllocationBufferCreateInfoNV {
+ VkStructureType sType;
+ const void* pNext;
+ VkBool32 dedicatedAllocation;
+} VkDedicatedAllocationBufferCreateInfoNV;
+
+typedef struct VkDedicatedAllocationMemoryAllocateInfoNV {
+ VkStructureType sType;
+ const void* pNext;
+ VkImage image;
+ VkBuffer buffer;
+} VkDedicatedAllocationMemoryAllocateInfoNV;
+
+
+
+#define VK_AMD_draw_indirect_count 1
+#define VK_AMD_DRAW_INDIRECT_COUNT_SPEC_VERSION 1
+#define VK_AMD_DRAW_INDIRECT_COUNT_EXTENSION_NAME "VK_AMD_draw_indirect_count"
+
+typedef void (VKAPI_PTR *PFN_vkCmdDrawIndirectCountAMD)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, uint32_t stride);
+typedef void (VKAPI_PTR *PFN_vkCmdDrawIndexedIndirectCountAMD)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, uint32_t stride);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirectCountAMD(
+ VkCommandBuffer commandBuffer,
+ VkBuffer buffer,
+ VkDeviceSize offset,
+ VkBuffer countBuffer,
+ VkDeviceSize countBufferOffset,
+ uint32_t maxDrawCount,
+ uint32_t stride);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirectCountAMD(
+ VkCommandBuffer commandBuffer,
+ VkBuffer buffer,
+ VkDeviceSize offset,
+ VkBuffer countBuffer,
+ VkDeviceSize countBufferOffset,
+ uint32_t maxDrawCount,
+ uint32_t stride);
+#endif
+
+#define VK_AMD_negative_viewport_height 1
+#define VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_SPEC_VERSION 1
+#define VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_EXTENSION_NAME "VK_AMD_negative_viewport_height"
+
+
+#define VK_AMD_gpu_shader_half_float 1
+#define VK_AMD_GPU_SHADER_HALF_FLOAT_SPEC_VERSION 1
+#define VK_AMD_GPU_SHADER_HALF_FLOAT_EXTENSION_NAME "VK_AMD_gpu_shader_half_float"
+
+
+#define VK_AMD_shader_ballot 1
+#define VK_AMD_SHADER_BALLOT_SPEC_VERSION 1
+#define VK_AMD_SHADER_BALLOT_EXTENSION_NAME "VK_AMD_shader_ballot"
+
+
+#define VK_AMD_texture_gather_bias_lod 1
+#define VK_AMD_TEXTURE_GATHER_BIAS_LOD_SPEC_VERSION 1
+#define VK_AMD_TEXTURE_GATHER_BIAS_LOD_EXTENSION_NAME "VK_AMD_texture_gather_bias_lod"
+
+typedef struct VkTextureLODGatherFormatPropertiesAMD {
+ VkStructureType sType;
+ void* pNext;
+ VkBool32 supportsTextureGatherLODBiasAMD;
+} VkTextureLODGatherFormatPropertiesAMD;
+
+
+
+#define VK_KHX_multiview 1
+#define VK_KHX_MULTIVIEW_SPEC_VERSION 1
+#define VK_KHX_MULTIVIEW_EXTENSION_NAME "VK_KHX_multiview"
+
+typedef struct VkRenderPassMultiviewCreateInfoKHX {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t subpassCount;
+ const uint32_t* pViewMasks;
+ uint32_t dependencyCount;
+ const int32_t* pViewOffsets;
+ uint32_t correlationMaskCount;
+ const uint32_t* pCorrelationMasks;
+} VkRenderPassMultiviewCreateInfoKHX;
+
+typedef struct VkPhysicalDeviceMultiviewFeaturesKHX {
+ VkStructureType sType;
+ void* pNext;
+ VkBool32 multiview;
+ VkBool32 multiviewGeometryShader;
+ VkBool32 multiviewTessellationShader;
+} VkPhysicalDeviceMultiviewFeaturesKHX;
+
+typedef struct VkPhysicalDeviceMultiviewPropertiesKHX {
+ VkStructureType sType;
+ void* pNext;
+ uint32_t maxMultiviewViewCount;
+ uint32_t maxMultiviewInstanceIndex;
+} VkPhysicalDeviceMultiviewPropertiesKHX;
+
+
+
+#define VK_IMG_format_pvrtc 1
+#define VK_IMG_FORMAT_PVRTC_SPEC_VERSION 1
+#define VK_IMG_FORMAT_PVRTC_EXTENSION_NAME "VK_IMG_format_pvrtc"
+
+
+#define VK_NV_external_memory_capabilities 1
+#define VK_NV_EXTERNAL_MEMORY_CAPABILITIES_SPEC_VERSION 1
+#define VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME "VK_NV_external_memory_capabilities"
+
+
+typedef enum VkExternalMemoryHandleTypeFlagBitsNV {
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_NV = 0x00000001,
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_NV = 0x00000002,
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_IMAGE_BIT_NV = 0x00000004,
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_IMAGE_KMT_BIT_NV = 0x00000008,
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_FLAG_BITS_MAX_ENUM_NV = 0x7FFFFFFF
+} VkExternalMemoryHandleTypeFlagBitsNV;
+typedef VkFlags VkExternalMemoryHandleTypeFlagsNV;
+
+typedef enum VkExternalMemoryFeatureFlagBitsNV {
+ VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT_NV = 0x00000001,
+ VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_NV = 0x00000002,
+ VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_NV = 0x00000004,
+ VK_EXTERNAL_MEMORY_FEATURE_FLAG_BITS_MAX_ENUM_NV = 0x7FFFFFFF
+} VkExternalMemoryFeatureFlagBitsNV;
+typedef VkFlags VkExternalMemoryFeatureFlagsNV;
+
+typedef struct VkExternalImageFormatPropertiesNV {
+ VkImageFormatProperties imageFormatProperties;
+ VkExternalMemoryFeatureFlagsNV externalMemoryFeatures;
+ VkExternalMemoryHandleTypeFlagsNV exportFromImportedHandleTypes;
+ VkExternalMemoryHandleTypeFlagsNV compatibleHandleTypes;
+} VkExternalImageFormatPropertiesNV;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceExternalImageFormatPropertiesNV)(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkExternalMemoryHandleTypeFlagsNV externalHandleType, VkExternalImageFormatPropertiesNV* pExternalImageFormatProperties);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceExternalImageFormatPropertiesNV(
+ VkPhysicalDevice physicalDevice,
+ VkFormat format,
+ VkImageType type,
+ VkImageTiling tiling,
+ VkImageUsageFlags usage,
+ VkImageCreateFlags flags,
+ VkExternalMemoryHandleTypeFlagsNV externalHandleType,
+ VkExternalImageFormatPropertiesNV* pExternalImageFormatProperties);
+#endif
+
+#define VK_NV_external_memory 1
+#define VK_NV_EXTERNAL_MEMORY_SPEC_VERSION 1
+#define VK_NV_EXTERNAL_MEMORY_EXTENSION_NAME "VK_NV_external_memory"
+
+typedef struct VkExternalMemoryImageCreateInfoNV {
+ VkStructureType sType;
+ const void* pNext;
+ VkExternalMemoryHandleTypeFlagsNV handleTypes;
+} VkExternalMemoryImageCreateInfoNV;
+
+typedef struct VkExportMemoryAllocateInfoNV {
+ VkStructureType sType;
+ const void* pNext;
+ VkExternalMemoryHandleTypeFlagsNV handleTypes;
+} VkExportMemoryAllocateInfoNV;
+
+
+
+#ifdef VK_USE_PLATFORM_WIN32_KHR
+#define VK_NV_external_memory_win32 1
+#define VK_NV_EXTERNAL_MEMORY_WIN32_SPEC_VERSION 1
+#define VK_NV_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME "VK_NV_external_memory_win32"
+
+typedef struct VkImportMemoryWin32HandleInfoNV {
+ VkStructureType sType;
+ const void* pNext;
+ VkExternalMemoryHandleTypeFlagsNV handleType;
+ HANDLE handle;
+} VkImportMemoryWin32HandleInfoNV;
+
+typedef struct VkExportMemoryWin32HandleInfoNV {
+ VkStructureType sType;
+ const void* pNext;
+ const SECURITY_ATTRIBUTES* pAttributes;
+ DWORD dwAccess;
+} VkExportMemoryWin32HandleInfoNV;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryWin32HandleNV)(VkDevice device, VkDeviceMemory memory, VkExternalMemoryHandleTypeFlagsNV handleType, HANDLE* pHandle);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleNV(
+ VkDevice device,
+ VkDeviceMemory memory,
+ VkExternalMemoryHandleTypeFlagsNV handleType,
+ HANDLE* pHandle);
+#endif
+#endif /* VK_USE_PLATFORM_WIN32_KHR */
+
+#ifdef VK_USE_PLATFORM_WIN32_KHR
+#define VK_NV_win32_keyed_mutex 1
+#define VK_NV_WIN32_KEYED_MUTEX_SPEC_VERSION 1
+#define VK_NV_WIN32_KEYED_MUTEX_EXTENSION_NAME "VK_NV_win32_keyed_mutex"
+
+typedef struct VkWin32KeyedMutexAcquireReleaseInfoNV {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t acquireCount;
+ const VkDeviceMemory* pAcquireSyncs;
+ const uint64_t* pAcquireKeys;
+ const uint32_t* pAcquireTimeoutMilliseconds;
+ uint32_t releaseCount;
+ const VkDeviceMemory* pReleaseSyncs;
+ const uint64_t* pReleaseKeys;
+} VkWin32KeyedMutexAcquireReleaseInfoNV;
+
+
+#endif /* VK_USE_PLATFORM_WIN32_KHR */
+
+#define VK_KHX_device_group 1
+#define VK_MAX_DEVICE_GROUP_SIZE_KHX 32
+#define VK_KHX_DEVICE_GROUP_SPEC_VERSION 1
+#define VK_KHX_DEVICE_GROUP_EXTENSION_NAME "VK_KHX_device_group"
+
+
+typedef enum VkPeerMemoryFeatureFlagBitsKHX {
+ VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT_KHX = 0x00000001,
+ VK_PEER_MEMORY_FEATURE_COPY_DST_BIT_KHX = 0x00000002,
+ VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT_KHX = 0x00000004,
+ VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT_KHX = 0x00000008,
+ VK_PEER_MEMORY_FEATURE_FLAG_BITS_MAX_ENUM_KHX = 0x7FFFFFFF
+} VkPeerMemoryFeatureFlagBitsKHX;
+typedef VkFlags VkPeerMemoryFeatureFlagsKHX;
+
+typedef enum VkMemoryAllocateFlagBitsKHX {
+ VK_MEMORY_ALLOCATE_DEVICE_MASK_BIT_KHX = 0x00000001,
+ VK_MEMORY_ALLOCATE_FLAG_BITS_MAX_ENUM_KHX = 0x7FFFFFFF
+} VkMemoryAllocateFlagBitsKHX;
+typedef VkFlags VkMemoryAllocateFlagsKHX;
+
+typedef enum VkDeviceGroupPresentModeFlagBitsKHX {
+ VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHX = 0x00000001,
+ VK_DEVICE_GROUP_PRESENT_MODE_REMOTE_BIT_KHX = 0x00000002,
+ VK_DEVICE_GROUP_PRESENT_MODE_SUM_BIT_KHX = 0x00000004,
+ VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_MULTI_DEVICE_BIT_KHX = 0x00000008,
+ VK_DEVICE_GROUP_PRESENT_MODE_FLAG_BITS_MAX_ENUM_KHX = 0x7FFFFFFF
+} VkDeviceGroupPresentModeFlagBitsKHX;
+typedef VkFlags VkDeviceGroupPresentModeFlagsKHX;
+
+typedef struct VkMemoryAllocateFlagsInfoKHX {
+ VkStructureType sType;
+ const void* pNext;
+ VkMemoryAllocateFlagsKHX flags;
+ uint32_t deviceMask;
+} VkMemoryAllocateFlagsInfoKHX;
+
+typedef struct VkBindBufferMemoryInfoKHX {
+ VkStructureType sType;
+ const void* pNext;
+ VkBuffer buffer;
+ VkDeviceMemory memory;
+ VkDeviceSize memoryOffset;
+ uint32_t deviceIndexCount;
+ const uint32_t* pDeviceIndices;
+} VkBindBufferMemoryInfoKHX;
+
+typedef struct VkBindImageMemoryInfoKHX {
+ VkStructureType sType;
+ const void* pNext;
+ VkImage image;
+ VkDeviceMemory memory;
+ VkDeviceSize memoryOffset;
+ uint32_t deviceIndexCount;
+ const uint32_t* pDeviceIndices;
+ uint32_t SFRRectCount;
+ const VkRect2D* pSFRRects;
+} VkBindImageMemoryInfoKHX;
+
+typedef struct VkDeviceGroupRenderPassBeginInfoKHX {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t deviceMask;
+ uint32_t deviceRenderAreaCount;
+ const VkRect2D* pDeviceRenderAreas;
+} VkDeviceGroupRenderPassBeginInfoKHX;
+
+typedef struct VkDeviceGroupCommandBufferBeginInfoKHX {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t deviceMask;
+} VkDeviceGroupCommandBufferBeginInfoKHX;
+
+typedef struct VkDeviceGroupSubmitInfoKHX {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t waitSemaphoreCount;
+ const uint32_t* pWaitSemaphoreDeviceIndices;
+ uint32_t commandBufferCount;
+ const uint32_t* pCommandBufferDeviceMasks;
+ uint32_t signalSemaphoreCount;
+ const uint32_t* pSignalSemaphoreDeviceIndices;
+} VkDeviceGroupSubmitInfoKHX;
+
+typedef struct VkDeviceGroupBindSparseInfoKHX {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t resourceDeviceIndex;
+ uint32_t memoryDeviceIndex;
+} VkDeviceGroupBindSparseInfoKHX;
+
+typedef struct VkDeviceGroupPresentCapabilitiesKHX {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t presentMask[VK_MAX_DEVICE_GROUP_SIZE_KHX];
+ VkDeviceGroupPresentModeFlagsKHX modes;
+} VkDeviceGroupPresentCapabilitiesKHX;
+
+typedef struct VkImageSwapchainCreateInfoKHX {
+ VkStructureType sType;
+ const void* pNext;
+ VkSwapchainKHR swapchain;
+} VkImageSwapchainCreateInfoKHX;
+
+typedef struct VkBindImageMemorySwapchainInfoKHX {
+ VkStructureType sType;
+ const void* pNext;
+ VkSwapchainKHR swapchain;
+ uint32_t imageIndex;
+} VkBindImageMemorySwapchainInfoKHX;
+
+typedef struct VkAcquireNextImageInfoKHX {
+ VkStructureType sType;
+ const void* pNext;
+ VkSwapchainKHR swapchain;
+ uint64_t timeout;
+ VkSemaphore semaphore;
+ VkFence fence;
+ uint32_t deviceMask;
+} VkAcquireNextImageInfoKHX;
+
+typedef struct VkDeviceGroupPresentInfoKHX {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t swapchainCount;
+ const uint32_t* pDeviceMasks;
+ VkDeviceGroupPresentModeFlagBitsKHX mode;
+} VkDeviceGroupPresentInfoKHX;
+
+typedef struct VkDeviceGroupSwapchainCreateInfoKHX {
+ VkStructureType sType;
+ const void* pNext;
+ VkDeviceGroupPresentModeFlagsKHX modes;
+} VkDeviceGroupSwapchainCreateInfoKHX;
+
+
+typedef void (VKAPI_PTR *PFN_vkGetDeviceGroupPeerMemoryFeaturesKHX)(VkDevice device, uint32_t heapIndex, uint32_t localDeviceIndex, uint32_t remoteDeviceIndex, VkPeerMemoryFeatureFlagsKHX* pPeerMemoryFeatures);
+typedef VkResult (VKAPI_PTR *PFN_vkBindBufferMemory2KHX)(VkDevice device, uint32_t bindInfoCount, const VkBindBufferMemoryInfoKHX* pBindInfos);
+typedef VkResult (VKAPI_PTR *PFN_vkBindImageMemory2KHX)(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfoKHX* pBindInfos);
+typedef void (VKAPI_PTR *PFN_vkCmdSetDeviceMaskKHX)(VkCommandBuffer commandBuffer, uint32_t deviceMask);
+typedef VkResult (VKAPI_PTR *PFN_vkGetDeviceGroupPresentCapabilitiesKHX)(VkDevice device, VkDeviceGroupPresentCapabilitiesKHX* pDeviceGroupPresentCapabilities);
+typedef VkResult (VKAPI_PTR *PFN_vkGetDeviceGroupSurfacePresentModesKHX)(VkDevice device, VkSurfaceKHR surface, VkDeviceGroupPresentModeFlagsKHX* pModes);
+typedef VkResult (VKAPI_PTR *PFN_vkAcquireNextImage2KHX)(VkDevice device, const VkAcquireNextImageInfoKHX* pAcquireInfo, uint32_t* pImageIndex);
+typedef void (VKAPI_PTR *PFN_vkCmdDispatchBaseKHX)(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ);
+typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDevicePresentRectanglesKHX)(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t* pRectCount, VkRect2D* pRects);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR void VKAPI_CALL vkGetDeviceGroupPeerMemoryFeaturesKHX(
+ VkDevice device,
+ uint32_t heapIndex,
+ uint32_t localDeviceIndex,
+ uint32_t remoteDeviceIndex,
+ VkPeerMemoryFeatureFlagsKHX* pPeerMemoryFeatures);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkBindBufferMemory2KHX(
+ VkDevice device,
+ uint32_t bindInfoCount,
+ const VkBindBufferMemoryInfoKHX* pBindInfos);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory2KHX(
+ VkDevice device,
+ uint32_t bindInfoCount,
+ const VkBindImageMemoryInfoKHX* pBindInfos);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdSetDeviceMaskKHX(
+ VkCommandBuffer commandBuffer,
+ uint32_t deviceMask);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupPresentCapabilitiesKHX(
+ VkDevice device,
+ VkDeviceGroupPresentCapabilitiesKHX* pDeviceGroupPresentCapabilities);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupSurfacePresentModesKHX(
+ VkDevice device,
+ VkSurfaceKHR surface,
+ VkDeviceGroupPresentModeFlagsKHX* pModes);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImage2KHX(
+ VkDevice device,
+ const VkAcquireNextImageInfoKHX* pAcquireInfo,
+ uint32_t* pImageIndex);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdDispatchBaseKHX(
+ VkCommandBuffer commandBuffer,
+ uint32_t baseGroupX,
+ uint32_t baseGroupY,
+ uint32_t baseGroupZ,
+ uint32_t groupCountX,
+ uint32_t groupCountY,
+ uint32_t groupCountZ);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDevicePresentRectanglesKHX(
+ VkPhysicalDevice physicalDevice,
+ VkSurfaceKHR surface,
+ uint32_t* pRectCount,
+ VkRect2D* pRects);
+#endif
+
+#define VK_EXT_validation_flags 1
+#define VK_EXT_VALIDATION_FLAGS_SPEC_VERSION 1
+#define VK_EXT_VALIDATION_FLAGS_EXTENSION_NAME "VK_EXT_validation_flags"
+
+
+typedef enum VkValidationCheckEXT {
+ VK_VALIDATION_CHECK_ALL_EXT = 0,
+ VK_VALIDATION_CHECK_SHADERS_EXT = 1,
+ VK_VALIDATION_CHECK_BEGIN_RANGE_EXT = VK_VALIDATION_CHECK_ALL_EXT,
+ VK_VALIDATION_CHECK_END_RANGE_EXT = VK_VALIDATION_CHECK_SHADERS_EXT,
+ VK_VALIDATION_CHECK_RANGE_SIZE_EXT = (VK_VALIDATION_CHECK_SHADERS_EXT - VK_VALIDATION_CHECK_ALL_EXT + 1),
+ VK_VALIDATION_CHECK_MAX_ENUM_EXT = 0x7FFFFFFF
+} VkValidationCheckEXT;
+
+typedef struct VkValidationFlagsEXT {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t disabledValidationCheckCount;
+ VkValidationCheckEXT* pDisabledValidationChecks;
+} VkValidationFlagsEXT;
+
+
+
+#ifdef VK_USE_PLATFORM_VI_NN
+#define VK_NN_vi_surface 1
+#define VK_NN_VI_SURFACE_SPEC_VERSION 1
+#define VK_NN_VI_SURFACE_EXTENSION_NAME "VK_NN_vi_surface"
+
+typedef VkFlags VkViSurfaceCreateFlagsNN;
+
+typedef struct VkViSurfaceCreateInfoNN {
+ VkStructureType sType;
+ const void* pNext;
+ VkViSurfaceCreateFlagsNN flags;
+ void* window;
+} VkViSurfaceCreateInfoNN;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkCreateViSurfaceNN)(VkInstance instance, const VkViSurfaceCreateInfoNN* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateViSurfaceNN(
+ VkInstance instance,
+ const VkViSurfaceCreateInfoNN* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkSurfaceKHR* pSurface);
+#endif
+#endif /* VK_USE_PLATFORM_VI_NN */
+
+#define VK_EXT_shader_subgroup_ballot 1
+#define VK_EXT_SHADER_SUBGROUP_BALLOT_SPEC_VERSION 1
+#define VK_EXT_SHADER_SUBGROUP_BALLOT_EXTENSION_NAME "VK_EXT_shader_subgroup_ballot"
+
+
+#define VK_EXT_shader_subgroup_vote 1
+#define VK_EXT_SHADER_SUBGROUP_VOTE_SPEC_VERSION 1
+#define VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME "VK_EXT_shader_subgroup_vote"
+
+
+#define VK_KHX_device_group_creation 1
+#define VK_KHX_DEVICE_GROUP_CREATION_SPEC_VERSION 1
+#define VK_KHX_DEVICE_GROUP_CREATION_EXTENSION_NAME "VK_KHX_device_group_creation"
+
+typedef struct VkPhysicalDeviceGroupPropertiesKHX {
+ VkStructureType sType;
+ void* pNext;
+ uint32_t physicalDeviceCount;
+ VkPhysicalDevice physicalDevices[VK_MAX_DEVICE_GROUP_SIZE_KHX];
+ VkBool32 subsetAllocation;
+} VkPhysicalDeviceGroupPropertiesKHX;
+
+typedef struct VkDeviceGroupDeviceCreateInfoKHX {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t physicalDeviceCount;
+ const VkPhysicalDevice* pPhysicalDevices;
+} VkDeviceGroupDeviceCreateInfoKHX;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkEnumeratePhysicalDeviceGroupsKHX)(VkInstance instance, uint32_t* pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupPropertiesKHX* pPhysicalDeviceGroupProperties);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDeviceGroupsKHX(
+ VkInstance instance,
+ uint32_t* pPhysicalDeviceGroupCount,
+ VkPhysicalDeviceGroupPropertiesKHX* pPhysicalDeviceGroupProperties);
+#endif
+
+#define VK_NVX_device_generated_commands 1
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkObjectTableNVX)
+VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkIndirectCommandsLayoutNVX)
+
+#define VK_NVX_DEVICE_GENERATED_COMMANDS_SPEC_VERSION 3
+#define VK_NVX_DEVICE_GENERATED_COMMANDS_EXTENSION_NAME "VK_NVX_device_generated_commands"
+
+
+typedef enum VkIndirectCommandsTokenTypeNVX {
+ VK_INDIRECT_COMMANDS_TOKEN_TYPE_PIPELINE_NVX = 0,
+ VK_INDIRECT_COMMANDS_TOKEN_TYPE_DESCRIPTOR_SET_NVX = 1,
+ VK_INDIRECT_COMMANDS_TOKEN_TYPE_INDEX_BUFFER_NVX = 2,
+ VK_INDIRECT_COMMANDS_TOKEN_TYPE_VERTEX_BUFFER_NVX = 3,
+ VK_INDIRECT_COMMANDS_TOKEN_TYPE_PUSH_CONSTANT_NVX = 4,
+ VK_INDIRECT_COMMANDS_TOKEN_TYPE_DRAW_INDEXED_NVX = 5,
+ VK_INDIRECT_COMMANDS_TOKEN_TYPE_DRAW_NVX = 6,
+ VK_INDIRECT_COMMANDS_TOKEN_TYPE_DISPATCH_NVX = 7,
+ VK_INDIRECT_COMMANDS_TOKEN_TYPE_BEGIN_RANGE_NVX = VK_INDIRECT_COMMANDS_TOKEN_TYPE_PIPELINE_NVX,
+ VK_INDIRECT_COMMANDS_TOKEN_TYPE_END_RANGE_NVX = VK_INDIRECT_COMMANDS_TOKEN_TYPE_DISPATCH_NVX,
+ VK_INDIRECT_COMMANDS_TOKEN_TYPE_RANGE_SIZE_NVX = (VK_INDIRECT_COMMANDS_TOKEN_TYPE_DISPATCH_NVX - VK_INDIRECT_COMMANDS_TOKEN_TYPE_PIPELINE_NVX + 1),
+ VK_INDIRECT_COMMANDS_TOKEN_TYPE_MAX_ENUM_NVX = 0x7FFFFFFF
+} VkIndirectCommandsTokenTypeNVX;
+
+typedef enum VkObjectEntryTypeNVX {
+ VK_OBJECT_ENTRY_TYPE_DESCRIPTOR_SET_NVX = 0,
+ VK_OBJECT_ENTRY_TYPE_PIPELINE_NVX = 1,
+ VK_OBJECT_ENTRY_TYPE_INDEX_BUFFER_NVX = 2,
+ VK_OBJECT_ENTRY_TYPE_VERTEX_BUFFER_NVX = 3,
+ VK_OBJECT_ENTRY_TYPE_PUSH_CONSTANT_NVX = 4,
+ VK_OBJECT_ENTRY_TYPE_BEGIN_RANGE_NVX = VK_OBJECT_ENTRY_TYPE_DESCRIPTOR_SET_NVX,
+ VK_OBJECT_ENTRY_TYPE_END_RANGE_NVX = VK_OBJECT_ENTRY_TYPE_PUSH_CONSTANT_NVX,
+ VK_OBJECT_ENTRY_TYPE_RANGE_SIZE_NVX = (VK_OBJECT_ENTRY_TYPE_PUSH_CONSTANT_NVX - VK_OBJECT_ENTRY_TYPE_DESCRIPTOR_SET_NVX + 1),
+ VK_OBJECT_ENTRY_TYPE_MAX_ENUM_NVX = 0x7FFFFFFF
+} VkObjectEntryTypeNVX;
+
+
+typedef enum VkIndirectCommandsLayoutUsageFlagBitsNVX {
+ VK_INDIRECT_COMMANDS_LAYOUT_USAGE_UNORDERED_SEQUENCES_BIT_NVX = 0x00000001,
+ VK_INDIRECT_COMMANDS_LAYOUT_USAGE_SPARSE_SEQUENCES_BIT_NVX = 0x00000002,
+ VK_INDIRECT_COMMANDS_LAYOUT_USAGE_EMPTY_EXECUTIONS_BIT_NVX = 0x00000004,
+ VK_INDIRECT_COMMANDS_LAYOUT_USAGE_INDEXED_SEQUENCES_BIT_NVX = 0x00000008,
+ VK_INDIRECT_COMMANDS_LAYOUT_USAGE_FLAG_BITS_MAX_ENUM_NVX = 0x7FFFFFFF
+} VkIndirectCommandsLayoutUsageFlagBitsNVX;
+typedef VkFlags VkIndirectCommandsLayoutUsageFlagsNVX;
+
+typedef enum VkObjectEntryUsageFlagBitsNVX {
+ VK_OBJECT_ENTRY_USAGE_GRAPHICS_BIT_NVX = 0x00000001,
+ VK_OBJECT_ENTRY_USAGE_COMPUTE_BIT_NVX = 0x00000002,
+ VK_OBJECT_ENTRY_USAGE_FLAG_BITS_MAX_ENUM_NVX = 0x7FFFFFFF
+} VkObjectEntryUsageFlagBitsNVX;
+typedef VkFlags VkObjectEntryUsageFlagsNVX;
+
+typedef struct VkDeviceGeneratedCommandsFeaturesNVX {
+ VkStructureType sType;
+ const void* pNext;
+ VkBool32 computeBindingPointSupport;
+} VkDeviceGeneratedCommandsFeaturesNVX;
+
+typedef struct VkDeviceGeneratedCommandsLimitsNVX {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t maxIndirectCommandsLayoutTokenCount;
+ uint32_t maxObjectEntryCounts;
+ uint32_t minSequenceCountBufferOffsetAlignment;
+ uint32_t minSequenceIndexBufferOffsetAlignment;
+ uint32_t minCommandsTokenBufferOffsetAlignment;
+} VkDeviceGeneratedCommandsLimitsNVX;
+
+typedef struct VkIndirectCommandsTokenNVX {
+ VkIndirectCommandsTokenTypeNVX tokenType;
+ VkBuffer buffer;
+ VkDeviceSize offset;
+} VkIndirectCommandsTokenNVX;
+
+typedef struct VkIndirectCommandsLayoutTokenNVX {
+ VkIndirectCommandsTokenTypeNVX tokenType;
+ uint32_t bindingUnit;
+ uint32_t dynamicCount;
+ uint32_t divisor;
+} VkIndirectCommandsLayoutTokenNVX;
+
+typedef struct VkIndirectCommandsLayoutCreateInfoNVX {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineBindPoint pipelineBindPoint;
+ VkIndirectCommandsLayoutUsageFlagsNVX flags;
+ uint32_t tokenCount;
+ const VkIndirectCommandsLayoutTokenNVX* pTokens;
+} VkIndirectCommandsLayoutCreateInfoNVX;
+
+typedef struct VkCmdProcessCommandsInfoNVX {
+ VkStructureType sType;
+ const void* pNext;
+ VkObjectTableNVX objectTable;
+ VkIndirectCommandsLayoutNVX indirectCommandsLayout;
+ uint32_t indirectCommandsTokenCount;
+ const VkIndirectCommandsTokenNVX* pIndirectCommandsTokens;
+ uint32_t maxSequencesCount;
+ VkCommandBuffer targetCommandBuffer;
+ VkBuffer sequencesCountBuffer;
+ VkDeviceSize sequencesCountOffset;
+ VkBuffer sequencesIndexBuffer;
+ VkDeviceSize sequencesIndexOffset;
+} VkCmdProcessCommandsInfoNVX;
+
+typedef struct VkCmdReserveSpaceForCommandsInfoNVX {
+ VkStructureType sType;
+ const void* pNext;
+ VkObjectTableNVX objectTable;
+ VkIndirectCommandsLayoutNVX indirectCommandsLayout;
+ uint32_t maxSequencesCount;
+} VkCmdReserveSpaceForCommandsInfoNVX;
+
+typedef struct VkObjectTableCreateInfoNVX {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t objectCount;
+ const VkObjectEntryTypeNVX* pObjectEntryTypes;
+ const uint32_t* pObjectEntryCounts;
+ const VkObjectEntryUsageFlagsNVX* pObjectEntryUsageFlags;
+ uint32_t maxUniformBuffersPerDescriptor;
+ uint32_t maxStorageBuffersPerDescriptor;
+ uint32_t maxStorageImagesPerDescriptor;
+ uint32_t maxSampledImagesPerDescriptor;
+ uint32_t maxPipelineLayouts;
+} VkObjectTableCreateInfoNVX;
+
+typedef struct VkObjectTableEntryNVX {
+ VkObjectEntryTypeNVX type;
+ VkObjectEntryUsageFlagsNVX flags;
+} VkObjectTableEntryNVX;
+
+typedef struct VkObjectTablePipelineEntryNVX {
+ VkObjectEntryTypeNVX type;
+ VkObjectEntryUsageFlagsNVX flags;
+ VkPipeline pipeline;
+} VkObjectTablePipelineEntryNVX;
+
+typedef struct VkObjectTableDescriptorSetEntryNVX {
+ VkObjectEntryTypeNVX type;
+ VkObjectEntryUsageFlagsNVX flags;
+ VkPipelineLayout pipelineLayout;
+ VkDescriptorSet descriptorSet;
+} VkObjectTableDescriptorSetEntryNVX;
+
+typedef struct VkObjectTableVertexBufferEntryNVX {
+ VkObjectEntryTypeNVX type;
+ VkObjectEntryUsageFlagsNVX flags;
+ VkBuffer buffer;
+} VkObjectTableVertexBufferEntryNVX;
+
+typedef struct VkObjectTableIndexBufferEntryNVX {
+ VkObjectEntryTypeNVX type;
+ VkObjectEntryUsageFlagsNVX flags;
+ VkBuffer buffer;
+ VkIndexType indexType;
+} VkObjectTableIndexBufferEntryNVX;
+
+typedef struct VkObjectTablePushConstantEntryNVX {
+ VkObjectEntryTypeNVX type;
+ VkObjectEntryUsageFlagsNVX flags;
+ VkPipelineLayout pipelineLayout;
+ VkShaderStageFlags stageFlags;
+} VkObjectTablePushConstantEntryNVX;
+
+
+typedef void (VKAPI_PTR *PFN_vkCmdProcessCommandsNVX)(VkCommandBuffer commandBuffer, const VkCmdProcessCommandsInfoNVX* pProcessCommandsInfo);
+typedef void (VKAPI_PTR *PFN_vkCmdReserveSpaceForCommandsNVX)(VkCommandBuffer commandBuffer, const VkCmdReserveSpaceForCommandsInfoNVX* pReserveSpaceInfo);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateIndirectCommandsLayoutNVX)(VkDevice device, const VkIndirectCommandsLayoutCreateInfoNVX* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkIndirectCommandsLayoutNVX* pIndirectCommandsLayout);
+typedef void (VKAPI_PTR *PFN_vkDestroyIndirectCommandsLayoutNVX)(VkDevice device, VkIndirectCommandsLayoutNVX indirectCommandsLayout, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkCreateObjectTableNVX)(VkDevice device, const VkObjectTableCreateInfoNVX* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkObjectTableNVX* pObjectTable);
+typedef void (VKAPI_PTR *PFN_vkDestroyObjectTableNVX)(VkDevice device, VkObjectTableNVX objectTable, const VkAllocationCallbacks* pAllocator);
+typedef VkResult (VKAPI_PTR *PFN_vkRegisterObjectsNVX)(VkDevice device, VkObjectTableNVX objectTable, uint32_t objectCount, const VkObjectTableEntryNVX* const* ppObjectTableEntries, const uint32_t* pObjectIndices);
+typedef VkResult (VKAPI_PTR *PFN_vkUnregisterObjectsNVX)(VkDevice device, VkObjectTableNVX objectTable, uint32_t objectCount, const VkObjectEntryTypeNVX* pObjectEntryTypes, const uint32_t* pObjectIndices);
+typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceGeneratedCommandsPropertiesNVX)(VkPhysicalDevice physicalDevice, VkDeviceGeneratedCommandsFeaturesNVX* pFeatures, VkDeviceGeneratedCommandsLimitsNVX* pLimits);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR void VKAPI_CALL vkCmdProcessCommandsNVX(
+ VkCommandBuffer commandBuffer,
+ const VkCmdProcessCommandsInfoNVX* pProcessCommandsInfo);
+
+VKAPI_ATTR void VKAPI_CALL vkCmdReserveSpaceForCommandsNVX(
+ VkCommandBuffer commandBuffer,
+ const VkCmdReserveSpaceForCommandsInfoNVX* pReserveSpaceInfo);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateIndirectCommandsLayoutNVX(
+ VkDevice device,
+ const VkIndirectCommandsLayoutCreateInfoNVX* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkIndirectCommandsLayoutNVX* pIndirectCommandsLayout);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyIndirectCommandsLayoutNVX(
+ VkDevice device,
+ VkIndirectCommandsLayoutNVX indirectCommandsLayout,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateObjectTableNVX(
+ VkDevice device,
+ const VkObjectTableCreateInfoNVX* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkObjectTableNVX* pObjectTable);
+
+VKAPI_ATTR void VKAPI_CALL vkDestroyObjectTableNVX(
+ VkDevice device,
+ VkObjectTableNVX objectTable,
+ const VkAllocationCallbacks* pAllocator);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkRegisterObjectsNVX(
+ VkDevice device,
+ VkObjectTableNVX objectTable,
+ uint32_t objectCount,
+ const VkObjectTableEntryNVX* const* ppObjectTableEntries,
+ const uint32_t* pObjectIndices);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkUnregisterObjectsNVX(
+ VkDevice device,
+ VkObjectTableNVX objectTable,
+ uint32_t objectCount,
+ const VkObjectEntryTypeNVX* pObjectEntryTypes,
+ const uint32_t* pObjectIndices);
+
+VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceGeneratedCommandsPropertiesNVX(
+ VkPhysicalDevice physicalDevice,
+ VkDeviceGeneratedCommandsFeaturesNVX* pFeatures,
+ VkDeviceGeneratedCommandsLimitsNVX* pLimits);
+#endif
+
+#define VK_NV_clip_space_w_scaling 1
+#define VK_NV_CLIP_SPACE_W_SCALING_SPEC_VERSION 1
+#define VK_NV_CLIP_SPACE_W_SCALING_EXTENSION_NAME "VK_NV_clip_space_w_scaling"
+
+typedef struct VkViewportWScalingNV {
+ float xcoeff;
+ float ycoeff;
+} VkViewportWScalingNV;
+
+typedef struct VkPipelineViewportWScalingStateCreateInfoNV {
+ VkStructureType sType;
+ const void* pNext;
+ VkBool32 viewportWScalingEnable;
+ uint32_t viewportCount;
+ const VkViewportWScalingNV* pViewportWScalings;
+} VkPipelineViewportWScalingStateCreateInfoNV;
+
+
+typedef void (VKAPI_PTR *PFN_vkCmdSetViewportWScalingNV)(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount, const VkViewportWScalingNV* pViewportWScalings);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR void VKAPI_CALL vkCmdSetViewportWScalingNV(
+ VkCommandBuffer commandBuffer,
+ uint32_t firstViewport,
+ uint32_t viewportCount,
+ const VkViewportWScalingNV* pViewportWScalings);
+#endif
+
+#define VK_EXT_direct_mode_display 1
+#define VK_EXT_DIRECT_MODE_DISPLAY_SPEC_VERSION 1
+#define VK_EXT_DIRECT_MODE_DISPLAY_EXTENSION_NAME "VK_EXT_direct_mode_display"
+
+typedef VkResult (VKAPI_PTR *PFN_vkReleaseDisplayEXT)(VkPhysicalDevice physicalDevice, VkDisplayKHR display);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkReleaseDisplayEXT(
+ VkPhysicalDevice physicalDevice,
+ VkDisplayKHR display);
+#endif
+
+#ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT
+#define VK_EXT_acquire_xlib_display 1
+#include <X11/extensions/Xrandr.h>
+
+#define VK_EXT_ACQUIRE_XLIB_DISPLAY_SPEC_VERSION 1
+#define VK_EXT_ACQUIRE_XLIB_DISPLAY_EXTENSION_NAME "VK_EXT_acquire_xlib_display"
+
+typedef VkResult (VKAPI_PTR *PFN_vkAcquireXlibDisplayEXT)(VkPhysicalDevice physicalDevice, Display* dpy, VkDisplayKHR display);
+typedef VkResult (VKAPI_PTR *PFN_vkGetRandROutputDisplayEXT)(VkPhysicalDevice physicalDevice, Display* dpy, RROutput rrOutput, VkDisplayKHR* pDisplay);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkAcquireXlibDisplayEXT(
+ VkPhysicalDevice physicalDevice,
+ Display* dpy,
+ VkDisplayKHR display);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetRandROutputDisplayEXT(
+ VkPhysicalDevice physicalDevice,
+ Display* dpy,
+ RROutput rrOutput,
+ VkDisplayKHR* pDisplay);
+#endif
+#endif /* VK_USE_PLATFORM_XLIB_XRANDR_EXT */
+
+#define VK_EXT_display_surface_counter 1
+#define VK_EXT_DISPLAY_SURFACE_COUNTER_SPEC_VERSION 1
+#define VK_EXT_DISPLAY_SURFACE_COUNTER_EXTENSION_NAME "VK_EXT_display_surface_counter"
+#define VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES2_EXT VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_EXT
+
+
+typedef enum VkSurfaceCounterFlagBitsEXT {
+ VK_SURFACE_COUNTER_VBLANK_EXT = 0x00000001,
+ VK_SURFACE_COUNTER_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF
+} VkSurfaceCounterFlagBitsEXT;
+typedef VkFlags VkSurfaceCounterFlagsEXT;
+
+typedef struct VkSurfaceCapabilities2EXT {
+ VkStructureType sType;
+ void* pNext;
+ uint32_t minImageCount;
+ uint32_t maxImageCount;
+ VkExtent2D currentExtent;
+ VkExtent2D minImageExtent;
+ VkExtent2D maxImageExtent;
+ uint32_t maxImageArrayLayers;
+ VkSurfaceTransformFlagsKHR supportedTransforms;
+ VkSurfaceTransformFlagBitsKHR currentTransform;
+ VkCompositeAlphaFlagsKHR supportedCompositeAlpha;
+ VkImageUsageFlags supportedUsageFlags;
+ VkSurfaceCounterFlagsEXT supportedSurfaceCounters;
+} VkSurfaceCapabilities2EXT;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfaceCapabilities2EXT)(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilities2EXT* pSurfaceCapabilities);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilities2EXT(
+ VkPhysicalDevice physicalDevice,
+ VkSurfaceKHR surface,
+ VkSurfaceCapabilities2EXT* pSurfaceCapabilities);
+#endif
+
+#define VK_EXT_display_control 1
+#define VK_EXT_DISPLAY_CONTROL_SPEC_VERSION 1
+#define VK_EXT_DISPLAY_CONTROL_EXTENSION_NAME "VK_EXT_display_control"
+
+
+typedef enum VkDisplayPowerStateEXT {
+ VK_DISPLAY_POWER_STATE_OFF_EXT = 0,
+ VK_DISPLAY_POWER_STATE_SUSPEND_EXT = 1,
+ VK_DISPLAY_POWER_STATE_ON_EXT = 2,
+ VK_DISPLAY_POWER_STATE_BEGIN_RANGE_EXT = VK_DISPLAY_POWER_STATE_OFF_EXT,
+ VK_DISPLAY_POWER_STATE_END_RANGE_EXT = VK_DISPLAY_POWER_STATE_ON_EXT,
+ VK_DISPLAY_POWER_STATE_RANGE_SIZE_EXT = (VK_DISPLAY_POWER_STATE_ON_EXT - VK_DISPLAY_POWER_STATE_OFF_EXT + 1),
+ VK_DISPLAY_POWER_STATE_MAX_ENUM_EXT = 0x7FFFFFFF
+} VkDisplayPowerStateEXT;
+
+typedef enum VkDeviceEventTypeEXT {
+ VK_DEVICE_EVENT_TYPE_DISPLAY_HOTPLUG_EXT = 0,
+ VK_DEVICE_EVENT_TYPE_BEGIN_RANGE_EXT = VK_DEVICE_EVENT_TYPE_DISPLAY_HOTPLUG_EXT,
+ VK_DEVICE_EVENT_TYPE_END_RANGE_EXT = VK_DEVICE_EVENT_TYPE_DISPLAY_HOTPLUG_EXT,
+ VK_DEVICE_EVENT_TYPE_RANGE_SIZE_EXT = (VK_DEVICE_EVENT_TYPE_DISPLAY_HOTPLUG_EXT - VK_DEVICE_EVENT_TYPE_DISPLAY_HOTPLUG_EXT + 1),
+ VK_DEVICE_EVENT_TYPE_MAX_ENUM_EXT = 0x7FFFFFFF
+} VkDeviceEventTypeEXT;
+
+typedef enum VkDisplayEventTypeEXT {
+ VK_DISPLAY_EVENT_TYPE_FIRST_PIXEL_OUT_EXT = 0,
+ VK_DISPLAY_EVENT_TYPE_BEGIN_RANGE_EXT = VK_DISPLAY_EVENT_TYPE_FIRST_PIXEL_OUT_EXT,
+ VK_DISPLAY_EVENT_TYPE_END_RANGE_EXT = VK_DISPLAY_EVENT_TYPE_FIRST_PIXEL_OUT_EXT,
+ VK_DISPLAY_EVENT_TYPE_RANGE_SIZE_EXT = (VK_DISPLAY_EVENT_TYPE_FIRST_PIXEL_OUT_EXT - VK_DISPLAY_EVENT_TYPE_FIRST_PIXEL_OUT_EXT + 1),
+ VK_DISPLAY_EVENT_TYPE_MAX_ENUM_EXT = 0x7FFFFFFF
+} VkDisplayEventTypeEXT;
+
+typedef struct VkDisplayPowerInfoEXT {
+ VkStructureType sType;
+ const void* pNext;
+ VkDisplayPowerStateEXT powerState;
+} VkDisplayPowerInfoEXT;
+
+typedef struct VkDeviceEventInfoEXT {
+ VkStructureType sType;
+ const void* pNext;
+ VkDeviceEventTypeEXT deviceEvent;
+} VkDeviceEventInfoEXT;
+
+typedef struct VkDisplayEventInfoEXT {
+ VkStructureType sType;
+ const void* pNext;
+ VkDisplayEventTypeEXT displayEvent;
+} VkDisplayEventInfoEXT;
+
+typedef struct VkSwapchainCounterCreateInfoEXT {
+ VkStructureType sType;
+ const void* pNext;
+ VkSurfaceCounterFlagsEXT surfaceCounters;
+} VkSwapchainCounterCreateInfoEXT;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkDisplayPowerControlEXT)(VkDevice device, VkDisplayKHR display, const VkDisplayPowerInfoEXT* pDisplayPowerInfo);
+typedef VkResult (VKAPI_PTR *PFN_vkRegisterDeviceEventEXT)(VkDevice device, const VkDeviceEventInfoEXT* pDeviceEventInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence);
+typedef VkResult (VKAPI_PTR *PFN_vkRegisterDisplayEventEXT)(VkDevice device, VkDisplayKHR display, const VkDisplayEventInfoEXT* pDisplayEventInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence);
+typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainCounterEXT)(VkDevice device, VkSwapchainKHR swapchain, VkSurfaceCounterFlagBitsEXT counter, uint64_t* pCounterValue);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkDisplayPowerControlEXT(
+ VkDevice device,
+ VkDisplayKHR display,
+ const VkDisplayPowerInfoEXT* pDisplayPowerInfo);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkRegisterDeviceEventEXT(
+ VkDevice device,
+ const VkDeviceEventInfoEXT* pDeviceEventInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkFence* pFence);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkRegisterDisplayEventEXT(
+ VkDevice device,
+ VkDisplayKHR display,
+ const VkDisplayEventInfoEXT* pDisplayEventInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkFence* pFence);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainCounterEXT(
+ VkDevice device,
+ VkSwapchainKHR swapchain,
+ VkSurfaceCounterFlagBitsEXT counter,
+ uint64_t* pCounterValue);
+#endif
+
+#define VK_GOOGLE_display_timing 1
+#define VK_GOOGLE_DISPLAY_TIMING_SPEC_VERSION 1
+#define VK_GOOGLE_DISPLAY_TIMING_EXTENSION_NAME "VK_GOOGLE_display_timing"
+
+typedef struct VkRefreshCycleDurationGOOGLE {
+ uint64_t refreshDuration;
+} VkRefreshCycleDurationGOOGLE;
+
+typedef struct VkPastPresentationTimingGOOGLE {
+ uint32_t presentID;
+ uint64_t desiredPresentTime;
+ uint64_t actualPresentTime;
+ uint64_t earliestPresentTime;
+ uint64_t presentMargin;
+} VkPastPresentationTimingGOOGLE;
+
+typedef struct VkPresentTimeGOOGLE {
+ uint32_t presentID;
+ uint64_t desiredPresentTime;
+} VkPresentTimeGOOGLE;
+
+typedef struct VkPresentTimesInfoGOOGLE {
+ VkStructureType sType;
+ const void* pNext;
+ uint32_t swapchainCount;
+ const VkPresentTimeGOOGLE* pTimes;
+} VkPresentTimesInfoGOOGLE;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkGetRefreshCycleDurationGOOGLE)(VkDevice device, VkSwapchainKHR swapchain, VkRefreshCycleDurationGOOGLE* pDisplayTimingProperties);
+typedef VkResult (VKAPI_PTR *PFN_vkGetPastPresentationTimingGOOGLE)(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pPresentationTimingCount, VkPastPresentationTimingGOOGLE* pPresentationTimings);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkGetRefreshCycleDurationGOOGLE(
+ VkDevice device,
+ VkSwapchainKHR swapchain,
+ VkRefreshCycleDurationGOOGLE* pDisplayTimingProperties);
+
+VKAPI_ATTR VkResult VKAPI_CALL vkGetPastPresentationTimingGOOGLE(
+ VkDevice device,
+ VkSwapchainKHR swapchain,
+ uint32_t* pPresentationTimingCount,
+ VkPastPresentationTimingGOOGLE* pPresentationTimings);
+#endif
+
+#define VK_NV_sample_mask_override_coverage 1
+#define VK_NV_SAMPLE_MASK_OVERRIDE_COVERAGE_SPEC_VERSION 1
+#define VK_NV_SAMPLE_MASK_OVERRIDE_COVERAGE_EXTENSION_NAME "VK_NV_sample_mask_override_coverage"
+
+
+#define VK_NV_geometry_shader_passthrough 1
+#define VK_NV_GEOMETRY_SHADER_PASSTHROUGH_SPEC_VERSION 1
+#define VK_NV_GEOMETRY_SHADER_PASSTHROUGH_EXTENSION_NAME "VK_NV_geometry_shader_passthrough"
+
+
+#define VK_NV_viewport_array2 1
+#define VK_NV_VIEWPORT_ARRAY2_SPEC_VERSION 1
+#define VK_NV_VIEWPORT_ARRAY2_EXTENSION_NAME "VK_NV_viewport_array2"
+
+
+#define VK_NVX_multiview_per_view_attributes 1
+#define VK_NVX_MULTIVIEW_PER_VIEW_ATTRIBUTES_SPEC_VERSION 1
+#define VK_NVX_MULTIVIEW_PER_VIEW_ATTRIBUTES_EXTENSION_NAME "VK_NVX_multiview_per_view_attributes"
+
+typedef struct VkPhysicalDeviceMultiviewPerViewAttributesPropertiesNVX {
+ VkStructureType sType;
+ void* pNext;
+ VkBool32 perViewPositionAllComponents;
+} VkPhysicalDeviceMultiviewPerViewAttributesPropertiesNVX;
+
+
+
+#define VK_NV_viewport_swizzle 1
+#define VK_NV_VIEWPORT_SWIZZLE_SPEC_VERSION 1
+#define VK_NV_VIEWPORT_SWIZZLE_EXTENSION_NAME "VK_NV_viewport_swizzle"
+
+
+typedef enum VkViewportCoordinateSwizzleNV {
+ VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_X_NV = 0,
+ VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_X_NV = 1,
+ VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_Y_NV = 2,
+ VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_Y_NV = 3,
+ VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_Z_NV = 4,
+ VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_Z_NV = 5,
+ VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_W_NV = 6,
+ VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_W_NV = 7,
+ VK_VIEWPORT_COORDINATE_SWIZZLE_BEGIN_RANGE_NV = VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_X_NV,
+ VK_VIEWPORT_COORDINATE_SWIZZLE_END_RANGE_NV = VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_W_NV,
+ VK_VIEWPORT_COORDINATE_SWIZZLE_RANGE_SIZE_NV = (VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_W_NV - VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_X_NV + 1),
+ VK_VIEWPORT_COORDINATE_SWIZZLE_MAX_ENUM_NV = 0x7FFFFFFF
+} VkViewportCoordinateSwizzleNV;
+
+typedef VkFlags VkPipelineViewportSwizzleStateCreateFlagsNV;
+
+typedef struct VkViewportSwizzleNV {
+ VkViewportCoordinateSwizzleNV x;
+ VkViewportCoordinateSwizzleNV y;
+ VkViewportCoordinateSwizzleNV z;
+ VkViewportCoordinateSwizzleNV w;
+} VkViewportSwizzleNV;
+
+typedef struct VkPipelineViewportSwizzleStateCreateInfoNV {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineViewportSwizzleStateCreateFlagsNV flags;
+ uint32_t viewportCount;
+ const VkViewportSwizzleNV* pViewportSwizzles;
+} VkPipelineViewportSwizzleStateCreateInfoNV;
+
+
+
+#define VK_EXT_discard_rectangles 1
+#define VK_EXT_DISCARD_RECTANGLES_SPEC_VERSION 1
+#define VK_EXT_DISCARD_RECTANGLES_EXTENSION_NAME "VK_EXT_discard_rectangles"
+
+
+typedef enum VkDiscardRectangleModeEXT {
+ VK_DISCARD_RECTANGLE_MODE_INCLUSIVE_EXT = 0,
+ VK_DISCARD_RECTANGLE_MODE_EXCLUSIVE_EXT = 1,
+ VK_DISCARD_RECTANGLE_MODE_BEGIN_RANGE_EXT = VK_DISCARD_RECTANGLE_MODE_INCLUSIVE_EXT,
+ VK_DISCARD_RECTANGLE_MODE_END_RANGE_EXT = VK_DISCARD_RECTANGLE_MODE_EXCLUSIVE_EXT,
+ VK_DISCARD_RECTANGLE_MODE_RANGE_SIZE_EXT = (VK_DISCARD_RECTANGLE_MODE_EXCLUSIVE_EXT - VK_DISCARD_RECTANGLE_MODE_INCLUSIVE_EXT + 1),
+ VK_DISCARD_RECTANGLE_MODE_MAX_ENUM_EXT = 0x7FFFFFFF
+} VkDiscardRectangleModeEXT;
+
+typedef VkFlags VkPipelineDiscardRectangleStateCreateFlagsEXT;
+
+typedef struct VkPhysicalDeviceDiscardRectanglePropertiesEXT {
+ VkStructureType sType;
+ void* pNext;
+ uint32_t maxDiscardRectangles;
+} VkPhysicalDeviceDiscardRectanglePropertiesEXT;
+
+typedef struct VkPipelineDiscardRectangleStateCreateInfoEXT {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineDiscardRectangleStateCreateFlagsEXT flags;
+ VkDiscardRectangleModeEXT discardRectangleMode;
+ uint32_t discardRectangleCount;
+ const VkRect2D* pDiscardRectangles;
+} VkPipelineDiscardRectangleStateCreateInfoEXT;
+
+
+typedef void (VKAPI_PTR *PFN_vkCmdSetDiscardRectangleEXT)(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle, uint32_t discardRectangleCount, const VkRect2D* pDiscardRectangles);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR void VKAPI_CALL vkCmdSetDiscardRectangleEXT(
+ VkCommandBuffer commandBuffer,
+ uint32_t firstDiscardRectangle,
+ uint32_t discardRectangleCount,
+ const VkRect2D* pDiscardRectangles);
+#endif
+
+#define VK_EXT_swapchain_colorspace 1
+#define VK_EXT_SWAPCHAIN_COLOR_SPACE_SPEC_VERSION 3
+#define VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME "VK_EXT_swapchain_colorspace"
+
+
+#define VK_EXT_hdr_metadata 1
+#define VK_EXT_HDR_METADATA_SPEC_VERSION 1
+#define VK_EXT_HDR_METADATA_EXTENSION_NAME "VK_EXT_hdr_metadata"
+
+typedef struct VkXYColorEXT {
+ float x;
+ float y;
+} VkXYColorEXT;
+
+typedef struct VkHdrMetadataEXT {
+ VkStructureType sType;
+ const void* pNext;
+ VkXYColorEXT displayPrimaryRed;
+ VkXYColorEXT displayPrimaryGreen;
+ VkXYColorEXT displayPrimaryBlue;
+ VkXYColorEXT whitePoint;
+ float maxLuminance;
+ float minLuminance;
+ float maxContentLightLevel;
+ float maxFrameAverageLightLevel;
+} VkHdrMetadataEXT;
+
+
+typedef void (VKAPI_PTR *PFN_vkSetHdrMetadataEXT)(VkDevice device, uint32_t swapchainCount, const VkSwapchainKHR* pSwapchains, const VkHdrMetadataEXT* pMetadata);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR void VKAPI_CALL vkSetHdrMetadataEXT(
+ VkDevice device,
+ uint32_t swapchainCount,
+ const VkSwapchainKHR* pSwapchains,
+ const VkHdrMetadataEXT* pMetadata);
+#endif
+
+#ifdef VK_USE_PLATFORM_IOS_MVK
+#define VK_MVK_ios_surface 1
+#define VK_MVK_IOS_SURFACE_SPEC_VERSION 2
+#define VK_MVK_IOS_SURFACE_EXTENSION_NAME "VK_MVK_ios_surface"
+
+typedef VkFlags VkIOSSurfaceCreateFlagsMVK;
+
+typedef struct VkIOSSurfaceCreateInfoMVK {
+ VkStructureType sType;
+ const void* pNext;
+ VkIOSSurfaceCreateFlagsMVK flags;
+ const void* pView;
+} VkIOSSurfaceCreateInfoMVK;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkCreateIOSSurfaceMVK)(VkInstance instance, const VkIOSSurfaceCreateInfoMVK* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateIOSSurfaceMVK(
+ VkInstance instance,
+ const VkIOSSurfaceCreateInfoMVK* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkSurfaceKHR* pSurface);
+#endif
+#endif /* VK_USE_PLATFORM_IOS_MVK */
+
+#ifdef VK_USE_PLATFORM_MACOS_MVK
+#define VK_MVK_macos_surface 1
+#define VK_MVK_MACOS_SURFACE_SPEC_VERSION 2
+#define VK_MVK_MACOS_SURFACE_EXTENSION_NAME "VK_MVK_macos_surface"
+
+typedef VkFlags VkMacOSSurfaceCreateFlagsMVK;
+
+typedef struct VkMacOSSurfaceCreateInfoMVK {
+ VkStructureType sType;
+ const void* pNext;
+ VkMacOSSurfaceCreateFlagsMVK flags;
+ const void* pView;
+} VkMacOSSurfaceCreateInfoMVK;
+
+
+typedef VkResult (VKAPI_PTR *PFN_vkCreateMacOSSurfaceMVK)(VkInstance instance, const VkMacOSSurfaceCreateInfoMVK* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface);
+
+#ifndef VK_NO_PROTOTYPES
+VKAPI_ATTR VkResult VKAPI_CALL vkCreateMacOSSurfaceMVK(
+ VkInstance instance,
+ const VkMacOSSurfaceCreateInfoMVK* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkSurfaceKHR* pSurface);
+#endif
+#endif /* VK_USE_PLATFORM_MACOS_MVK */
+
+#define VK_EXT_sampler_filter_minmax 1
+#define VK_EXT_SAMPLER_FILTER_MINMAX_SPEC_VERSION 1
+#define VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME "VK_EXT_sampler_filter_minmax"
+
+
+typedef enum VkSamplerReductionModeEXT {
+ VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT = 0,
+ VK_SAMPLER_REDUCTION_MODE_MIN_EXT = 1,
+ VK_SAMPLER_REDUCTION_MODE_MAX_EXT = 2,
+ VK_SAMPLER_REDUCTION_MODE_BEGIN_RANGE_EXT = VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT,
+ VK_SAMPLER_REDUCTION_MODE_END_RANGE_EXT = VK_SAMPLER_REDUCTION_MODE_MAX_EXT,
+ VK_SAMPLER_REDUCTION_MODE_RANGE_SIZE_EXT = (VK_SAMPLER_REDUCTION_MODE_MAX_EXT - VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT + 1),
+ VK_SAMPLER_REDUCTION_MODE_MAX_ENUM_EXT = 0x7FFFFFFF
+} VkSamplerReductionModeEXT;
+
+typedef struct VkSamplerReductionModeCreateInfoEXT {
+ VkStructureType sType;
+ const void* pNext;
+ VkSamplerReductionModeEXT reductionMode;
+} VkSamplerReductionModeCreateInfoEXT;
+
+typedef struct VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT {
+ VkStructureType sType;
+ void* pNext;
+ VkBool32 filterMinmaxSingleComponentFormats;
+ VkBool32 filterMinmaxImageComponentMapping;
+} VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT;
+
+
+
+#define VK_AMD_gpu_shader_int16 1
+#define VK_AMD_GPU_SHADER_INT16_SPEC_VERSION 1
+#define VK_AMD_GPU_SHADER_INT16_EXTENSION_NAME "VK_AMD_gpu_shader_int16"
+
+
+#define VK_AMD_mixed_attachment_samples 1
+#define VK_AMD_MIXED_ATTACHMENT_SAMPLES_SPEC_VERSION 1
+#define VK_AMD_MIXED_ATTACHMENT_SAMPLES_EXTENSION_NAME "VK_AMD_mixed_attachment_samples"
+
+
+#define VK_EXT_shader_stencil_export 1
+#define VK_EXT_SHADER_STENCIL_EXPORT_SPEC_VERSION 1
+#define VK_EXT_SHADER_STENCIL_EXPORT_EXTENSION_NAME "VK_EXT_shader_stencil_export"
+
+
+#define VK_EXT_blend_operation_advanced 1
+#define VK_EXT_BLEND_OPERATION_ADVANCED_SPEC_VERSION 2
+#define VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME "VK_EXT_blend_operation_advanced"
+
+
+typedef enum VkBlendOverlapEXT {
+ VK_BLEND_OVERLAP_UNCORRELATED_EXT = 0,
+ VK_BLEND_OVERLAP_DISJOINT_EXT = 1,
+ VK_BLEND_OVERLAP_CONJOINT_EXT = 2,
+ VK_BLEND_OVERLAP_BEGIN_RANGE_EXT = VK_BLEND_OVERLAP_UNCORRELATED_EXT,
+ VK_BLEND_OVERLAP_END_RANGE_EXT = VK_BLEND_OVERLAP_CONJOINT_EXT,
+ VK_BLEND_OVERLAP_RANGE_SIZE_EXT = (VK_BLEND_OVERLAP_CONJOINT_EXT - VK_BLEND_OVERLAP_UNCORRELATED_EXT + 1),
+ VK_BLEND_OVERLAP_MAX_ENUM_EXT = 0x7FFFFFFF
+} VkBlendOverlapEXT;
+
+typedef struct VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT {
+ VkStructureType sType;
+ void* pNext;
+ VkBool32 advancedBlendCoherentOperations;
+} VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT;
+
+typedef struct VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT {
+ VkStructureType sType;
+ void* pNext;
+ uint32_t advancedBlendMaxColorAttachments;
+ VkBool32 advancedBlendIndependentBlend;
+ VkBool32 advancedBlendNonPremultipliedSrcColor;
+ VkBool32 advancedBlendNonPremultipliedDstColor;
+ VkBool32 advancedBlendCorrelatedOverlap;
+ VkBool32 advancedBlendAllOperations;
+} VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT;
+
+typedef struct VkPipelineColorBlendAdvancedStateCreateInfoEXT {
+ VkStructureType sType;
+ const void* pNext;
+ VkBool32 srcPremultiplied;
+ VkBool32 dstPremultiplied;
+ VkBlendOverlapEXT blendOverlap;
+} VkPipelineColorBlendAdvancedStateCreateInfoEXT;
+
+
+
+#define VK_NV_fragment_coverage_to_color 1
+#define VK_NV_FRAGMENT_COVERAGE_TO_COLOR_SPEC_VERSION 1
+#define VK_NV_FRAGMENT_COVERAGE_TO_COLOR_EXTENSION_NAME "VK_NV_fragment_coverage_to_color"
+
+typedef VkFlags VkPipelineCoverageToColorStateCreateFlagsNV;
+
+typedef struct VkPipelineCoverageToColorStateCreateInfoNV {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineCoverageToColorStateCreateFlagsNV flags;
+ VkBool32 coverageToColorEnable;
+ uint32_t coverageToColorLocation;
+} VkPipelineCoverageToColorStateCreateInfoNV;
+
+
+
+#define VK_NV_framebuffer_mixed_samples 1
+#define VK_NV_FRAMEBUFFER_MIXED_SAMPLES_SPEC_VERSION 1
+#define VK_NV_FRAMEBUFFER_MIXED_SAMPLES_EXTENSION_NAME "VK_NV_framebuffer_mixed_samples"
+
+
+typedef enum VkCoverageModulationModeNV {
+ VK_COVERAGE_MODULATION_MODE_NONE_NV = 0,
+ VK_COVERAGE_MODULATION_MODE_RGB_NV = 1,
+ VK_COVERAGE_MODULATION_MODE_ALPHA_NV = 2,
+ VK_COVERAGE_MODULATION_MODE_RGBA_NV = 3,
+ VK_COVERAGE_MODULATION_MODE_BEGIN_RANGE_NV = VK_COVERAGE_MODULATION_MODE_NONE_NV,
+ VK_COVERAGE_MODULATION_MODE_END_RANGE_NV = VK_COVERAGE_MODULATION_MODE_RGBA_NV,
+ VK_COVERAGE_MODULATION_MODE_RANGE_SIZE_NV = (VK_COVERAGE_MODULATION_MODE_RGBA_NV - VK_COVERAGE_MODULATION_MODE_NONE_NV + 1),
+ VK_COVERAGE_MODULATION_MODE_MAX_ENUM_NV = 0x7FFFFFFF
+} VkCoverageModulationModeNV;
+
+typedef VkFlags VkPipelineCoverageModulationStateCreateFlagsNV;
+
+typedef struct VkPipelineCoverageModulationStateCreateInfoNV {
+ VkStructureType sType;
+ const void* pNext;
+ VkPipelineCoverageModulationStateCreateFlagsNV flags;
+ VkCoverageModulationModeNV coverageModulationMode;
+ VkBool32 coverageModulationTableEnable;
+ uint32_t coverageModulationTableCount;
+ const float* pCoverageModulationTable;
+} VkPipelineCoverageModulationStateCreateInfoNV;
+
+
+
+#define VK_NV_fill_rectangle 1
+#define VK_NV_FILL_RECTANGLE_SPEC_VERSION 1
+#define VK_NV_FILL_RECTANGLE_EXTENSION_NAME "VK_NV_fill_rectangle"
+
+
+#define VK_EXT_post_depth_coverage 1
+#define VK_EXT_POST_DEPTH_COVERAGE_SPEC_VERSION 1
+#define VK_EXT_POST_DEPTH_COVERAGE_EXTENSION_NAME "VK_EXT_post_depth_coverage"
+
+
+#define VK_EXT_shader_viewport_index_layer 1
+#define VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_SPEC_VERSION 1
+#define VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME "VK_EXT_shader_viewport_index_layer"
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmdyn.c b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmdyn.c
new file mode 100644
index 0000000..c79f372
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmdyn.c
@@ -0,0 +1,171 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_KMSDRM
+
+#define DEBUG_DYNAMIC_KMSDRM 0
+
+#include "SDL_kmsdrmdyn.h"
+
+#if DEBUG_DYNAMIC_KMSDRM
+#include "SDL_log.h"
+#endif
+
+#ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC
+
+#include "SDL_name.h"
+#include "SDL_loadso.h"
+
+typedef struct
+{
+ void *lib;
+ const char *libname;
+} kmsdrmdynlib;
+
+#ifndef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC
+#define SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC NULL
+#endif
+#ifndef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM
+#define SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM NULL
+#endif
+
+static kmsdrmdynlib kmsdrmlibs[] = {
+ {NULL, SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC},
+ {NULL, SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM}
+};
+
+static void *
+KMSDRM_GetSym(const char *fnname, int *pHasModule)
+{
+ int i;
+ void *fn = NULL;
+ for (i = 0; i < SDL_TABLESIZE(kmsdrmlibs); i++) {
+ if (kmsdrmlibs[i].lib != NULL) {
+ fn = SDL_LoadFunction(kmsdrmlibs[i].lib, fnname);
+ if (fn != NULL)
+ break;
+ }
+ }
+
+#if DEBUG_DYNAMIC_KMSDRM
+ if (fn != NULL)
+ SDL_Log("KMSDRM: Found '%s' in %s (%p)\n", fnname, kmsdrmlibs[i].libname, fn);
+ else
+ SDL_Log("KMSDRM: Symbol '%s' NOT FOUND!\n", fnname);
+#endif
+
+ if (fn == NULL)
+ *pHasModule = 0; /* kill this module. */
+
+ return fn;
+}
+
+#endif /* SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC */
+
+/* Define all the function pointers and wrappers... */
+#define SDL_KMSDRM_MODULE(modname) int SDL_KMSDRM_HAVE_##modname = 0;
+#define SDL_KMSDRM_SYM(rc,fn,params) SDL_DYNKMSDRMFN_##fn KMSDRM_##fn = NULL;
+#define SDL_KMSDRM_SYM_CONST(type,name) SDL_DYNKMSDRMCONST_##name KMSDRM_##name = NULL;
+#include "SDL_kmsdrmsym.h"
+
+static int kmsdrm_load_refcount = 0;
+
+void
+SDL_KMSDRM_UnloadSymbols(void)
+{
+ /* Don't actually unload if more than one module is using the libs... */
+ if (kmsdrm_load_refcount > 0) {
+ if (--kmsdrm_load_refcount == 0) {
+#ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC
+ int i;
+#endif
+
+ /* set all the function pointers to NULL. */
+#define SDL_KMSDRM_MODULE(modname) SDL_KMSDRM_HAVE_##modname = 0;
+#define SDL_KMSDRM_SYM(rc,fn,params) KMSDRM_##fn = NULL;
+#define SDL_KMSDRM_SYM_CONST(type,name) KMSDRM_##name = NULL;
+#include "SDL_kmsdrmsym.h"
+
+
+#ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC
+ for (i = 0; i < SDL_TABLESIZE(kmsdrmlibs); i++) {
+ if (kmsdrmlibs[i].lib != NULL) {
+ SDL_UnloadObject(kmsdrmlibs[i].lib);
+ kmsdrmlibs[i].lib = NULL;
+ }
+ }
+#endif
+ }
+ }
+}
+
+/* returns non-zero if all needed symbols were loaded. */
+int
+SDL_KMSDRM_LoadSymbols(void)
+{
+ int rc = 1; /* always succeed if not using Dynamic KMSDRM stuff. */
+
+ /* deal with multiple modules needing these symbols... */
+ if (kmsdrm_load_refcount++ == 0) {
+#ifdef SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC
+ int i;
+ int *thismod = NULL;
+ for (i = 0; i < SDL_TABLESIZE(kmsdrmlibs); i++) {
+ if (kmsdrmlibs[i].libname != NULL) {
+ kmsdrmlibs[i].lib = SDL_LoadObject(kmsdrmlibs[i].libname);
+ }
+ }
+
+#define SDL_KMSDRM_MODULE(modname) SDL_KMSDRM_HAVE_##modname = 1; /* default yes */
+#include "SDL_kmsdrmsym.h"
+
+#define SDL_KMSDRM_MODULE(modname) thismod = &SDL_KMSDRM_HAVE_##modname;
+#define SDL_KMSDRM_SYM(rc,fn,params) KMSDRM_##fn = (SDL_DYNKMSDRMFN_##fn) KMSDRM_GetSym(#fn,thismod);
+#define SDL_KMSDRM_SYM_CONST(type,name) KMSDRM_##name = *(SDL_DYNKMSDRMCONST_##name*) KMSDRM_GetSym(#name,thismod);
+#include "SDL_kmsdrmsym.h"
+
+ if ((SDL_KMSDRM_HAVE_LIBDRM) && (SDL_KMSDRM_HAVE_GBM)) {
+ /* all required symbols loaded. */
+ SDL_ClearError();
+ } else {
+ /* in case something got loaded... */
+ SDL_KMSDRM_UnloadSymbols();
+ rc = 0;
+ }
+
+#else /* no dynamic KMSDRM */
+
+#define SDL_KMSDRM_MODULE(modname) SDL_KMSDRM_HAVE_##modname = 1; /* default yes */
+#define SDL_KMSDRM_SYM(rc,fn,params) KMSDRM_##fn = fn;
+#define SDL_KMSDRM_SYM_CONST(type,name) KMSDRM_##name = name;
+#include "SDL_kmsdrmsym.h"
+
+#endif
+ }
+
+ return rc;
+}
+
+#endif /* SDL_VIDEO_DRIVER_KMSDRM */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmdyn.h b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmdyn.h
new file mode 100644
index 0000000..578b088
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmdyn.h
@@ -0,0 +1,53 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_kmsdrmdyn_h_
+#define SDL_kmsdrmdyn_h_
+
+#include "../../SDL_internal.h"
+
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+#include <gbm.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int SDL_KMSDRM_LoadSymbols(void);
+void SDL_KMSDRM_UnloadSymbols(void);
+
+/* Declare all the function pointers and wrappers... */
+#define SDL_KMSDRM_SYM(rc,fn,params) \
+ typedef rc (*SDL_DYNKMSDRMFN_##fn) params; \
+ extern SDL_DYNKMSDRMFN_##fn KMSDRM_##fn;
+#define SDL_KMSDRM_SYM_CONST(type, name) \
+ typedef type SDL_DYNKMSDRMCONST_##name; \
+ extern SDL_DYNKMSDRMCONST_##name KMSDRM_##name;
+#include "SDL_kmsdrmsym.h"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SDL_kmsdrmdyn_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmevents.c b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmevents.c
new file mode 100644
index 0000000..5a611f6
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmevents.c
@@ -0,0 +1,42 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_KMSDRM
+
+#include "SDL_kmsdrmvideo.h"
+#include "SDL_kmsdrmevents.h"
+
+#ifdef SDL_INPUT_LINUXEV
+#include "../../core/linux/SDL_evdev.h"
+#endif
+
+void KMSDRM_PumpEvents(_THIS)
+{
+#ifdef SDL_INPUT_LINUXEV
+ SDL_EVDEV_Poll();
+#endif
+
+}
+
+#endif /* SDL_VIDEO_DRIVER_KMSDRM */
+
diff --git a/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmevents.h b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmevents.h
new file mode 100644
index 0000000..3b88c28
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmevents.h
@@ -0,0 +1,31 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_kmsdrmevents_h_
+#define SDL_kmsdrmevents_h_
+
+extern void KMSDRM_PumpEvents(_THIS);
+extern void KMSDRM_EventInit(_THIS);
+extern void KMSDRM_EventQuit(_THIS);
+
+#endif /* SDL_kmsdrmevents_h_ */
diff --git a/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmmouse.c b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmmouse.c
new file mode 100644
index 0000000..e23dd13
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmmouse.c
@@ -0,0 +1,501 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_KMSDRM
+
+#include "SDL_kmsdrmvideo.h"
+#include "SDL_kmsdrmmouse.h"
+#include "SDL_kmsdrmdyn.h"
+
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/default_cursor.h"
+
+static SDL_Cursor *KMSDRM_CreateDefaultCursor(void);
+static SDL_Cursor *KMSDRM_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y);
+static int KMSDRM_ShowCursor(SDL_Cursor * cursor);
+static void KMSDRM_MoveCursor(SDL_Cursor * cursor);
+static void KMSDRM_FreeCursor(SDL_Cursor * cursor);
+static void KMSDRM_WarpMouse(SDL_Window * window, int x, int y);
+static int KMSDRM_WarpMouseGlobal(int x, int y);
+
+static SDL_Cursor *
+KMSDRM_CreateDefaultCursor(void)
+{
+ return SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH, DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY);
+}
+
+/* Evaluate if a given cursor size is supported or not. Notably, current Intel gfx only support 64x64 and up. */
+static SDL_bool
+KMSDRM_IsCursorSizeSupported (int w, int h, uint32_t bo_format) {
+
+ SDL_VideoDevice *dev = SDL_GetVideoDevice();
+ SDL_VideoData *vdata = ((SDL_VideoData *)dev->driverdata);
+ int ret;
+ uint32_t bo_handle;
+ struct gbm_bo *bo = KMSDRM_gbm_bo_create(vdata->gbm, w, h, bo_format,
+ GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
+
+ if (bo == NULL) {
+ SDL_SetError("Could not create GBM cursor BO width size %dx%d for size testing", w, h);
+ goto cleanup;
+ }
+
+ bo_handle = KMSDRM_gbm_bo_get_handle(bo).u32;
+ ret = KMSDRM_drmModeSetCursor(vdata->drm_fd, vdata->crtc_id, bo_handle, w, h);
+
+ if (ret) {
+ goto cleanup;
+ }
+ else {
+ KMSDRM_gbm_bo_destroy(bo);
+ return SDL_TRUE;
+ }
+
+cleanup:
+ if (bo != NULL) {
+ KMSDRM_gbm_bo_destroy(bo);
+ }
+ return SDL_FALSE;
+}
+
+/* Create a cursor from a surface */
+static SDL_Cursor *
+KMSDRM_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
+{
+ SDL_VideoDevice *dev = SDL_GetVideoDevice();
+ SDL_VideoData *vdata = ((SDL_VideoData *)dev->driverdata);
+ SDL_PixelFormat *pixlfmt = surface->format;
+ KMSDRM_CursorData *curdata;
+ SDL_Cursor *cursor;
+ SDL_bool cursor_supported = SDL_FALSE;
+ int i, ret, usable_cursor_w, usable_cursor_h;
+ uint32_t bo_format, bo_stride;
+ char *buffer = NULL;
+ size_t bufsize;
+
+ switch(pixlfmt->format) {
+ case SDL_PIXELFORMAT_RGB332:
+ bo_format = GBM_FORMAT_RGB332;
+ break;
+ case SDL_PIXELFORMAT_ARGB4444:
+ bo_format = GBM_FORMAT_ARGB4444;
+ break;
+ case SDL_PIXELFORMAT_RGBA4444:
+ bo_format = GBM_FORMAT_RGBA4444;
+ break;
+ case SDL_PIXELFORMAT_ABGR4444:
+ bo_format = GBM_FORMAT_ABGR4444;
+ break;
+ case SDL_PIXELFORMAT_BGRA4444:
+ bo_format = GBM_FORMAT_BGRA4444;
+ break;
+ case SDL_PIXELFORMAT_ARGB1555:
+ bo_format = GBM_FORMAT_ARGB1555;
+ break;
+ case SDL_PIXELFORMAT_RGBA5551:
+ bo_format = GBM_FORMAT_RGBA5551;
+ break;
+ case SDL_PIXELFORMAT_ABGR1555:
+ bo_format = GBM_FORMAT_ABGR1555;
+ break;
+ case SDL_PIXELFORMAT_BGRA5551:
+ bo_format = GBM_FORMAT_BGRA5551;
+ break;
+ case SDL_PIXELFORMAT_RGB565:
+ bo_format = GBM_FORMAT_RGB565;
+ break;
+ case SDL_PIXELFORMAT_BGR565:
+ bo_format = GBM_FORMAT_BGR565;
+ break;
+ case SDL_PIXELFORMAT_RGB888:
+ case SDL_PIXELFORMAT_RGB24:
+ bo_format = GBM_FORMAT_RGB888;
+ break;
+ case SDL_PIXELFORMAT_BGR888:
+ case SDL_PIXELFORMAT_BGR24:
+ bo_format = GBM_FORMAT_BGR888;
+ break;
+ case SDL_PIXELFORMAT_RGBX8888:
+ bo_format = GBM_FORMAT_RGBX8888;
+ break;
+ case SDL_PIXELFORMAT_BGRX8888:
+ bo_format = GBM_FORMAT_BGRX8888;
+ break;
+ case SDL_PIXELFORMAT_ARGB8888:
+ bo_format = GBM_FORMAT_ARGB8888;
+ break;
+ case SDL_PIXELFORMAT_RGBA8888:
+ bo_format = GBM_FORMAT_RGBA8888;
+ break;
+ case SDL_PIXELFORMAT_ABGR8888:
+ bo_format = GBM_FORMAT_ABGR8888;
+ break;
+ case SDL_PIXELFORMAT_BGRA8888:
+ bo_format = GBM_FORMAT_BGRA8888;
+ break;
+ case SDL_PIXELFORMAT_ARGB2101010:
+ bo_format = GBM_FORMAT_ARGB2101010;
+ break;
+ default:
+ SDL_SetError("Unsupported pixel format for cursor");
+ return NULL;
+ }
+
+ if (!KMSDRM_gbm_device_is_format_supported(vdata->gbm, bo_format, GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE)) {
+ SDL_SetError("Unsupported pixel format for cursor");
+ return NULL;
+ }
+
+ cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
+ if (cursor == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ curdata = (KMSDRM_CursorData *) SDL_calloc(1, sizeof(*curdata));
+ if (curdata == NULL) {
+ SDL_OutOfMemory();
+ SDL_free(cursor);
+ return NULL;
+ }
+
+ /* We have to know beforehand if a cursor with the same size as the surface is supported.
+ * If it's not, we have to find an usable cursor size and use an intermediate and clean buffer.
+ * If we can't find a cursor size supported by the hardware, we won't go on trying to
+ * call SDL_SetCursor() later. */
+
+ usable_cursor_w = surface->w;
+ usable_cursor_h = surface->h;
+
+ while (usable_cursor_w <= MAX_CURSOR_W && usable_cursor_h <= MAX_CURSOR_H) {
+ if (KMSDRM_IsCursorSizeSupported(usable_cursor_w, usable_cursor_h, bo_format)) {
+ cursor_supported = SDL_TRUE;
+ break;
+ }
+ usable_cursor_w += usable_cursor_w;
+ usable_cursor_h += usable_cursor_h;
+ }
+
+ if (!cursor_supported) {
+ SDL_SetError("Could not find a cursor size supported by the kernel driver");
+ goto cleanup;
+ }
+
+ curdata->hot_x = hot_x;
+ curdata->hot_y = hot_y;
+ curdata->w = usable_cursor_w;
+ curdata->h = usable_cursor_h;
+
+ curdata->bo = KMSDRM_gbm_bo_create(vdata->gbm, usable_cursor_w, usable_cursor_h, bo_format,
+ GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
+
+ if (curdata->bo == NULL) {
+ SDL_SetError("Could not create GBM cursor BO");
+ goto cleanup;
+ }
+
+ bo_stride = KMSDRM_gbm_bo_get_stride(curdata->bo);
+ bufsize = bo_stride * curdata->h;
+
+ if (surface->pitch != bo_stride) {
+ /* pitch doesn't match stride, must be copied to temp buffer */
+ buffer = SDL_malloc(bufsize);
+ if (buffer == NULL) {
+ SDL_OutOfMemory();
+ goto cleanup;
+ }
+
+ if (SDL_MUSTLOCK(surface)) {
+ if (SDL_LockSurface(surface) < 0) {
+ /* Could not lock surface */
+ goto cleanup;
+ }
+ }
+
+ /* Clean the whole temporary buffer */
+ SDL_memset(buffer, 0x00, bo_stride * curdata->h);
+
+ /* Copy to temporary buffer */
+ for (i = 0; i < surface->h; i++) {
+ SDL_memcpy(buffer + (i * bo_stride),
+ ((char *)surface->pixels) + (i * surface->pitch),
+ surface->w * pixlfmt->BytesPerPixel);
+ }
+
+ if (SDL_MUSTLOCK(surface)) {
+ SDL_UnlockSurface(surface);
+ }
+
+ if (KMSDRM_gbm_bo_write(curdata->bo, buffer, bufsize)) {
+ SDL_SetError("Could not write to GBM cursor BO");
+ goto cleanup;
+ }
+
+ /* Free temporary buffer */
+ SDL_free(buffer);
+ buffer = NULL;
+ } else {
+ /* surface matches BO format */
+ if (SDL_MUSTLOCK(surface)) {
+ if (SDL_LockSurface(surface) < 0) {
+ /* Could not lock surface */
+ goto cleanup;
+ }
+ }
+
+ ret = KMSDRM_gbm_bo_write(curdata->bo, surface->pixels, bufsize);
+
+ if (SDL_MUSTLOCK(surface)) {
+ SDL_UnlockSurface(surface);
+ }
+
+ if (ret) {
+ SDL_SetError("Could not write to GBM cursor BO");
+ goto cleanup;
+ }
+ }
+
+ cursor->driverdata = curdata;
+
+ return cursor;
+
+cleanup:
+ if (buffer != NULL) {
+ SDL_free(buffer);
+ }
+ if (cursor != NULL) {
+ SDL_free(cursor);
+ }
+ if (curdata != NULL) {
+ if (curdata->bo != NULL) {
+ KMSDRM_gbm_bo_destroy(curdata->bo);
+ }
+ SDL_free(curdata);
+ }
+ return NULL;
+}
+
+/* Show the specified cursor, or hide if cursor is NULL */
+static int
+KMSDRM_ShowCursor(SDL_Cursor * cursor)
+{
+ SDL_VideoDevice *dev = SDL_GetVideoDevice();
+ SDL_VideoData *vdata = ((SDL_VideoData *)dev->driverdata);
+ SDL_Mouse *mouse;
+ KMSDRM_CursorData *curdata;
+ SDL_VideoDisplay *display = NULL;
+ SDL_DisplayData *ddata = NULL;
+ int ret;
+ uint32_t bo_handle;
+
+ mouse = SDL_GetMouse();
+ if (mouse == NULL) {
+ return SDL_SetError("No mouse.");
+ }
+
+ if (mouse->focus != NULL) {
+ display = SDL_GetDisplayForWindow(mouse->focus);
+ if (display != NULL) {
+ ddata = (SDL_DisplayData*) display->driverdata;
+ }
+ }
+
+ if (cursor == NULL) {
+ /* Hide current cursor */
+ if ( mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) {
+ curdata = (KMSDRM_CursorData *) mouse->cur_cursor->driverdata;
+
+ if (curdata->crtc_id != 0) {
+ ret = KMSDRM_drmModeSetCursor(vdata->drm_fd, curdata->crtc_id, 0, 0, 0);
+ if (ret) {
+ SDL_SetError("Could not hide current cursor with drmModeSetCursor().");
+ return ret;
+ }
+ /* Mark previous cursor as not-displayed */
+ curdata->crtc_id = 0;
+
+ return 0;
+ }
+ }
+ /* otherwise if possible, hide global cursor */
+ if (ddata != NULL && ddata->crtc_id != 0) {
+ ret = KMSDRM_drmModeSetCursor(vdata->drm_fd, ddata->crtc_id, 0, 0, 0);
+ if (ret) {
+ SDL_SetError("Could not hide display's cursor with drmModeSetCursor().");
+ return ret;
+ }
+ return 0;
+ }
+
+ return SDL_SetError("Couldn't find cursor to hide.");
+ }
+ /* If cursor != NULL, show new cursor on display */
+ if (display == NULL) {
+ return SDL_SetError("Could not get display for mouse.");
+ }
+ if (ddata == NULL) {
+ return SDL_SetError("Could not get display driverdata.");
+ }
+
+ curdata = (KMSDRM_CursorData *) cursor->driverdata;
+ if (curdata == NULL || curdata->bo == NULL) {
+ return SDL_SetError("Cursor not initialized properly.");
+ }
+
+ bo_handle = KMSDRM_gbm_bo_get_handle(curdata->bo).u32;
+ if (curdata->hot_x == 0 && curdata->hot_y == 0) {
+ ret = KMSDRM_drmModeSetCursor(vdata->drm_fd, ddata->crtc_id, bo_handle,
+ curdata->w, curdata->h);
+ } else {
+ ret = KMSDRM_drmModeSetCursor2(vdata->drm_fd, ddata->crtc_id, bo_handle,
+ curdata->w, curdata->h,
+ curdata->hot_x, curdata->hot_y);
+ }
+ if (ret) {
+ SDL_SetError("drmModeSetCursor failed.");
+ return ret;
+ }
+
+ curdata->crtc_id = ddata->crtc_id;
+
+ return 0;
+}
+
+/* Free a window manager cursor */
+static void
+KMSDRM_FreeCursor(SDL_Cursor * cursor)
+{
+ KMSDRM_CursorData *curdata;
+ int drm_fd;
+
+ if (cursor != NULL) {
+ curdata = (KMSDRM_CursorData *) cursor->driverdata;
+
+ if (curdata != NULL) {
+ if (curdata->bo != NULL) {
+ if (curdata->crtc_id != 0) {
+ drm_fd = KMSDRM_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->bo));
+ /* Hide the cursor if previously shown on a CRTC */
+ KMSDRM_drmModeSetCursor(drm_fd, curdata->crtc_id, 0, 0, 0);
+ curdata->crtc_id = 0;
+ }
+ KMSDRM_gbm_bo_destroy(curdata->bo);
+ curdata->bo = NULL;
+ }
+ SDL_free(cursor->driverdata);
+ }
+ SDL_free(cursor);
+ }
+}
+
+/* Warp the mouse to (x,y) */
+static void
+KMSDRM_WarpMouse(SDL_Window * window, int x, int y)
+{
+ /* Only one global/fullscreen window is supported */
+ KMSDRM_WarpMouseGlobal(x, y);
+}
+
+/* Warp the mouse to (x,y) */
+static int
+KMSDRM_WarpMouseGlobal(int x, int y)
+{
+ KMSDRM_CursorData *curdata;
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ if (mouse != NULL && mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) {
+ /* Update internal mouse position. */
+ SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 0, x, y);
+
+ /* And now update the cursor graphic position on screen. */
+ curdata = (KMSDRM_CursorData *) mouse->cur_cursor->driverdata;
+ if (curdata->bo != NULL) {
+
+ if (curdata->crtc_id != 0) {
+ int ret, drm_fd;
+ drm_fd = KMSDRM_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->bo));
+ ret = KMSDRM_drmModeMoveCursor(drm_fd, curdata->crtc_id, x, y);
+
+ if (ret) {
+ SDL_SetError("drmModeMoveCursor() failed.");
+ }
+
+ return ret;
+ } else {
+ return SDL_SetError("Cursor is not currently shown.");
+ }
+ } else {
+ return SDL_SetError("Cursor not initialized properly.");
+ }
+ } else {
+ return SDL_SetError("No mouse or current cursor.");
+ }
+}
+
+void
+KMSDRM_InitMouse(_THIS)
+{
+ /* FIXME: Using UDEV it should be possible to scan all mice
+ * but there's no point in doing so as there's no multimice support...yet!
+ */
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ mouse->CreateCursor = KMSDRM_CreateCursor;
+ mouse->ShowCursor = KMSDRM_ShowCursor;
+ mouse->MoveCursor = KMSDRM_MoveCursor;
+ mouse->FreeCursor = KMSDRM_FreeCursor;
+ mouse->WarpMouse = KMSDRM_WarpMouse;
+ mouse->WarpMouseGlobal = KMSDRM_WarpMouseGlobal;
+
+ SDL_SetDefaultCursor(KMSDRM_CreateDefaultCursor());
+}
+
+void
+KMSDRM_QuitMouse(_THIS)
+{
+ /* TODO: ? */
+}
+
+/* This is called when a mouse motion event occurs */
+static void
+KMSDRM_MoveCursor(SDL_Cursor * cursor)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ KMSDRM_CursorData *curdata;
+ int drm_fd, ret;
+
+ /* We must NOT call SDL_SendMouseMotion() here or we will enter recursivity!
+ That's why we move the cursor graphic ONLY. */
+ if (mouse != NULL && mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) {
+ curdata = (KMSDRM_CursorData *) mouse->cur_cursor->driverdata;
+ drm_fd = KMSDRM_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->bo));
+ ret = KMSDRM_drmModeMoveCursor(drm_fd, curdata->crtc_id, mouse->x, mouse->y);
+
+ if (ret) {
+ SDL_SetError("drmModeMoveCursor() failed.");
+ }
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_KMSDRM */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmmouse.h b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmmouse.h
new file mode 100644
index 0000000..754417d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmmouse.h
@@ -0,0 +1,45 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_KMSDRM_mouse_h_
+#define SDL_KMSDRM_mouse_h_
+
+#include <gbm.h>
+
+#define MAX_CURSOR_W 512
+#define MAX_CURSOR_H 512
+
+typedef struct _KMSDRM_CursorData
+{
+ struct gbm_bo *bo;
+ uint32_t crtc_id;
+ int hot_x, hot_y;
+ int w, h;
+} KMSDRM_CursorData;
+
+extern void KMSDRM_InitMouse(_THIS);
+extern void KMSDRM_QuitMouse(_THIS);
+
+#endif /* SDL_KMSDRM_mouse_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmopengles.c b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmopengles.c
new file mode 100644
index 0000000..7a0b079
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmopengles.c
@@ -0,0 +1,189 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_KMSDRM && SDL_VIDEO_OPENGL_EGL
+
+#include "SDL_log.h"
+
+#include "SDL_kmsdrmvideo.h"
+#include "SDL_kmsdrmopengles.h"
+#include "SDL_kmsdrmdyn.h"
+
+#ifndef EGL_PLATFORM_GBM_MESA
+#define EGL_PLATFORM_GBM_MESA 0x31D7
+#endif
+
+/* EGL implementation of SDL OpenGL support */
+
+int
+KMSDRM_GLES_LoadLibrary(_THIS, const char *path) {
+ return SDL_EGL_LoadLibrary(_this, path, ((SDL_VideoData *)_this->driverdata)->gbm, EGL_PLATFORM_GBM_MESA);
+}
+
+SDL_EGL_CreateContext_impl(KMSDRM)
+
+SDL_bool
+KMSDRM_GLES_SetupCrtc(_THIS, SDL_Window * window) {
+ SDL_WindowData *wdata = ((SDL_WindowData *) window->driverdata);
+ SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
+ SDL_VideoData *vdata = ((SDL_VideoData *)_this->driverdata);
+ KMSDRM_FBInfo *fb_info;
+
+ if (!(_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, wdata->egl_surface))) {
+ SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "eglSwapBuffers failed on CRTC setup");
+ return SDL_FALSE;
+ }
+
+ wdata->next_bo = KMSDRM_gbm_surface_lock_front_buffer(wdata->gs);
+ if (wdata->next_bo == NULL) {
+ SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not lock GBM surface front buffer on CRTC setup");
+ return SDL_FALSE;
+ }
+
+ fb_info = KMSDRM_FBFromBO(_this, wdata->next_bo);
+ if (fb_info == NULL) {
+ return SDL_FALSE;
+ }
+
+ if(KMSDRM_drmModeSetCrtc(vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id,
+ 0, 0, &vdata->saved_conn_id, 1, &displaydata->cur_mode) != 0) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "Could not set up CRTC to a GBM buffer");
+ return SDL_FALSE;
+
+ }
+
+ wdata->crtc_ready = SDL_TRUE;
+ return SDL_TRUE;
+}
+
+int KMSDRM_GLES_SetSwapInterval(_THIS, int interval) {
+ if (!_this->egl_data) {
+ return SDL_SetError("EGL not initialized");
+ }
+
+ if (interval == 0 || interval == 1) {
+ _this->egl_data->egl_swapinterval = interval;
+ } else {
+ return SDL_SetError("Only swap intervals of 0 or 1 are supported");
+ }
+
+ return 0;
+}
+
+int
+KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window) {
+ SDL_WindowData *wdata = ((SDL_WindowData *) window->driverdata);
+ SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
+ SDL_VideoData *vdata = ((SDL_VideoData *)_this->driverdata);
+ KMSDRM_FBInfo *fb_info;
+ int ret;
+
+ /* Do we still need to wait for a flip? */
+ int timeout = 0;
+ if (_this->egl_data->egl_swapinterval == 1) {
+ timeout = -1;
+ }
+ if (!KMSDRM_WaitPageFlip(_this, wdata, timeout)) {
+ return 0;
+ }
+
+ /* Release previously displayed buffer (which is now the backbuffer) and lock a new one */
+ if (wdata->next_bo != NULL) {
+ KMSDRM_gbm_surface_release_buffer(wdata->gs, wdata->current_bo);
+ /* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Released GBM surface %p", (void *)wdata->next_bo); */
+
+ wdata->current_bo = wdata->next_bo;
+ wdata->next_bo = NULL;
+ }
+
+ if (!(_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, wdata->egl_surface))) {
+ SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "eglSwapBuffers failed.");
+ return 0;
+ }
+
+ if (wdata->current_bo == NULL) {
+ wdata->current_bo = KMSDRM_gbm_surface_lock_front_buffer(wdata->gs);
+ if (wdata->current_bo == NULL) {
+ return 0;
+ }
+ }
+
+ wdata->next_bo = KMSDRM_gbm_surface_lock_front_buffer(wdata->gs);
+ if (wdata->next_bo == NULL) {
+ SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not lock GBM surface front buffer");
+ return 0;
+ /* } else {
+ SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Locked GBM surface %p", (void *)wdata->next_bo); */
+ }
+
+ fb_info = KMSDRM_FBFromBO(_this, wdata->next_bo);
+ if (fb_info == NULL) {
+ return 0;
+ }
+ if (_this->egl_data->egl_swapinterval == 0) {
+ /* Swap buffers instantly, possible tearing */
+ /* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "drmModeSetCrtc(%d, %u, %u, 0, 0, &%u, 1, &%ux%u@%u)",
+ vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id, vdata->saved_conn_id,
+ displaydata->cur_mode.hdisplay, displaydata->cur_mode.vdisplay, displaydata->cur_mode.vrefresh); */
+ ret = KMSDRM_drmModeSetCrtc(vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id,
+ 0, 0, &vdata->saved_conn_id, 1, &displaydata->cur_mode);
+ if(ret != 0) {
+ SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not pageflip with drmModeSetCrtc: %d", ret);
+ }
+ } else {
+ /* Queue page flip at vsync */
+
+ /* Have we already setup the CRTC to one of the GBM buffers? Do so if we have not,
+ or FlipPage won't work in some cases. */
+ if (!wdata->crtc_ready) {
+ if(!KMSDRM_GLES_SetupCrtc(_this, window)) {
+ SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not set up CRTC for doing vsync-ed pageflips");
+ return 0;
+ }
+ }
+
+ /* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "drmModePageFlip(%d, %u, %u, DRM_MODE_PAGE_FLIP_EVENT, &wdata->waiting_for_flip)",
+ vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id); */
+ ret = KMSDRM_drmModePageFlip(vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id,
+ DRM_MODE_PAGE_FLIP_EVENT, &wdata->waiting_for_flip);
+ if (ret == 0) {
+ wdata->waiting_for_flip = SDL_TRUE;
+ } else {
+ SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not queue pageflip: %d", ret);
+ }
+
+ /* Wait immediately for vsync (as if we only had two buffers), for low input-lag scenarios.
+ Run your SDL2 program with "SDL_KMSDRM_DOUBLE_BUFFER=1 <program_name>" to enable this. */
+ if (wdata->double_buffer) {
+ KMSDRM_WaitPageFlip(_this, wdata, -1);
+ }
+ }
+
+ return 0;
+}
+
+SDL_EGL_MakeCurrent_impl(KMSDRM)
+
+#endif /* SDL_VIDEO_DRIVER_KMSDRM && SDL_VIDEO_OPENGL_EGL */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmopengles.h b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmopengles.h
new file mode 100644
index 0000000..d0a7bfa
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmopengles.h
@@ -0,0 +1,48 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_kmsdrmopengles_h_
+#define SDL_kmsdrmopengles_h_
+
+#if SDL_VIDEO_DRIVER_KMSDRM && SDL_VIDEO_OPENGL_EGL
+
+#include "../SDL_sysvideo.h"
+#include "../SDL_egl_c.h"
+
+/* OpenGLES functions */
+#define KMSDRM_GLES_GetAttribute SDL_EGL_GetAttribute
+#define KMSDRM_GLES_GetProcAddress SDL_EGL_GetProcAddress
+#define KMSDRM_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
+#define KMSDRM_GLES_DeleteContext SDL_EGL_DeleteContext
+#define KMSDRM_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
+
+extern int KMSDRM_GLES_SetSwapInterval(_THIS, int interval);
+extern int KMSDRM_GLES_LoadLibrary(_THIS, const char *path);
+extern SDL_GLContext KMSDRM_GLES_CreateContext(_THIS, SDL_Window * window);
+extern int KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window);
+extern int KMSDRM_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+
+#endif /* SDL_VIDEO_DRIVER_KMSDRM && SDL_VIDEO_OPENGL_EGL */
+
+#endif /* SDL_kmsdrmopengles_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmsym.h b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmsym.h
new file mode 100644
index 0000000..3ab2318
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmsym.h
@@ -0,0 +1,99 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/* *INDENT-OFF* */
+
+#ifndef SDL_KMSDRM_MODULE
+#define SDL_KMSDRM_MODULE(modname)
+#endif
+
+#ifndef SDL_KMSDRM_SYM
+#define SDL_KMSDRM_SYM(rc,fn,params)
+#endif
+
+#ifndef SDL_KMSDRM_SYM_CONST
+#define SDL_KMSDRM_SYM_CONST(type, name)
+#endif
+
+
+SDL_KMSDRM_MODULE(LIBDRM)
+SDL_KMSDRM_SYM(void,drmModeFreeResources,(drmModeResPtr ptr))
+SDL_KMSDRM_SYM(void,drmModeFreeFB,(drmModeFBPtr ptr))
+SDL_KMSDRM_SYM(void,drmModeFreeCrtc,(drmModeCrtcPtr ptr))
+SDL_KMSDRM_SYM(void,drmModeFreeConnector,(drmModeConnectorPtr ptr))
+SDL_KMSDRM_SYM(void,drmModeFreeEncoder,(drmModeEncoderPtr ptr))
+SDL_KMSDRM_SYM(drmModeResPtr,drmModeGetResources,(int fd))
+SDL_KMSDRM_SYM(int,drmModeAddFB,(int fd, uint32_t width, uint32_t height, uint8_t depth,
+ uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
+ uint32_t *buf_id))
+SDL_KMSDRM_SYM(int,drmModeRmFB,(int fd, uint32_t bufferId))
+SDL_KMSDRM_SYM(drmModeFBPtr,drmModeGetFB,(int fd, uint32_t buf))
+SDL_KMSDRM_SYM(drmModeCrtcPtr,drmModeGetCrtc,(int fd, uint32_t crtcId))
+SDL_KMSDRM_SYM(int,drmModeSetCrtc,(int fd, uint32_t crtcId, uint32_t bufferId,
+ uint32_t x, uint32_t y, uint32_t *connectors, int count,
+ drmModeModeInfoPtr mode))
+SDL_KMSDRM_SYM(int,drmModeSetCursor,(int fd, uint32_t crtcId, uint32_t bo_handle,
+ uint32_t width, uint32_t height))
+SDL_KMSDRM_SYM(int,drmModeSetCursor2,(int fd, uint32_t crtcId, uint32_t bo_handle,
+ uint32_t width, uint32_t height,
+ int32_t hot_x, int32_t hot_y))
+SDL_KMSDRM_SYM(int,drmModeMoveCursor,(int fd, uint32_t crtcId, int x, int y))
+SDL_KMSDRM_SYM(drmModeEncoderPtr,drmModeGetEncoder,(int fd, uint32_t encoder_id))
+SDL_KMSDRM_SYM(drmModeConnectorPtr,drmModeGetConnector,(int fd, uint32_t connector_id))
+SDL_KMSDRM_SYM(int,drmHandleEvent,(int fd,drmEventContextPtr evctx))
+SDL_KMSDRM_SYM(int,drmModePageFlip,(int fd, uint32_t crtc_id, uint32_t fb_id,
+ uint32_t flags, void *user_data))
+
+
+SDL_KMSDRM_MODULE(GBM)
+SDL_KMSDRM_SYM(int,gbm_device_get_fd,(struct gbm_device *gbm))
+SDL_KMSDRM_SYM(int,gbm_device_is_format_supported,(struct gbm_device *gbm,
+ uint32_t format, uint32_t usage))
+SDL_KMSDRM_SYM(void,gbm_device_destroy,(struct gbm_device *gbm))
+SDL_KMSDRM_SYM(struct gbm_device *,gbm_create_device,(int fd))
+SDL_KMSDRM_SYM(unsigned int,gbm_bo_get_width,(struct gbm_bo *bo))
+SDL_KMSDRM_SYM(unsigned int,gbm_bo_get_height,(struct gbm_bo *bo))
+SDL_KMSDRM_SYM(uint32_t,gbm_bo_get_stride,(struct gbm_bo *bo))
+SDL_KMSDRM_SYM(union gbm_bo_handle,gbm_bo_get_handle,(struct gbm_bo *bo))
+SDL_KMSDRM_SYM(int,gbm_bo_write,(struct gbm_bo *bo, const void *buf, size_t count))
+SDL_KMSDRM_SYM(struct gbm_device *,gbm_bo_get_device,(struct gbm_bo *bo))
+SDL_KMSDRM_SYM(void,gbm_bo_set_user_data,(struct gbm_bo *bo, void *data,
+ void (*destroy_user_data)(struct gbm_bo *, void *)))
+SDL_KMSDRM_SYM(void *,gbm_bo_get_user_data,(struct gbm_bo *bo))
+SDL_KMSDRM_SYM(void,gbm_bo_destroy,(struct gbm_bo *bo))
+SDL_KMSDRM_SYM(struct gbm_bo *,gbm_bo_create,(struct gbm_device *gbm,
+ uint32_t width, uint32_t height,
+ uint32_t format, uint32_t usage))
+SDL_KMSDRM_SYM(struct gbm_surface *,gbm_surface_create,(struct gbm_device *gbm,
+ uint32_t width, uint32_t height,
+ uint32_t format, uint32_t flags))
+SDL_KMSDRM_SYM(void,gbm_surface_destroy,(struct gbm_surface *surf))
+SDL_KMSDRM_SYM(struct gbm_bo *,gbm_surface_lock_front_buffer,(struct gbm_surface *surf))
+SDL_KMSDRM_SYM(void,gbm_surface_release_buffer,(struct gbm_surface *surf, struct gbm_bo *bo))
+
+
+#undef SDL_KMSDRM_MODULE
+#undef SDL_KMSDRM_SYM
+#undef SDL_KMSDRM_SYM_CONST
+
+/* *INDENT-ON* */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmvideo.c
new file mode 100644
index 0000000..7855eed
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -0,0 +1,664 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_KMSDRM
+
+/* SDL internals */
+#include "../SDL_sysvideo.h"
+#include "SDL_syswm.h"
+#include "SDL_log.h"
+#include "SDL_hints.h"
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_keyboard_c.h"
+
+#ifdef SDL_INPUT_LINUXEV
+#include "../../core/linux/SDL_evdev.h"
+#endif
+
+/* KMS/DRM declarations */
+#include "SDL_kmsdrmvideo.h"
+#include "SDL_kmsdrmevents.h"
+#include "SDL_kmsdrmopengles.h"
+#include "SDL_kmsdrmmouse.h"
+#include "SDL_kmsdrmdyn.h"
+
+#define KMSDRM_DRI_CARD_0 "/dev/dri/card0"
+
+static int
+KMSDRM_Available(void)
+{
+ int available = 0;
+
+ int drm_fd = open(KMSDRM_DRI_CARD_0, O_RDWR | O_CLOEXEC);
+ if (drm_fd >= 0) {
+ if (SDL_KMSDRM_LoadSymbols()) {
+ drmModeRes *resources = KMSDRM_drmModeGetResources(drm_fd);
+ if (resources != NULL) {
+ available = 1;
+ KMSDRM_drmModeFreeResources(resources);
+ }
+ SDL_KMSDRM_UnloadSymbols();
+ }
+ close(drm_fd);
+ }
+
+ return available;
+}
+
+static void
+KMSDRM_Destroy(SDL_VideoDevice * device)
+{
+ if (device->driverdata != NULL) {
+ SDL_free(device->driverdata);
+ device->driverdata = NULL;
+ }
+
+ SDL_free(device);
+ SDL_KMSDRM_UnloadSymbols();
+}
+
+static SDL_VideoDevice *
+KMSDRM_Create(int devindex)
+{
+ SDL_VideoDevice *device;
+ SDL_VideoData *vdata;
+
+ if (devindex < 0 || devindex > 99) {
+ SDL_SetError("devindex (%d) must be between 0 and 99.\n", devindex);
+ return NULL;
+ }
+
+ if (!SDL_KMSDRM_LoadSymbols()) {
+ return NULL;
+ }
+
+ /* Initialize SDL_VideoDevice structure */
+ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (device == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ /* Initialize internal data */
+ vdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
+ if (vdata == NULL) {
+ SDL_OutOfMemory();
+ goto cleanup;
+ }
+ vdata->devindex = devindex;
+ vdata->drm_fd = -1;
+
+ device->driverdata = vdata;
+
+ /* Setup amount of available displays and current display */
+ device->num_displays = 0;
+
+ /* Set device free function */
+ device->free = KMSDRM_Destroy;
+
+ /* Setup all functions which we can handle */
+ device->VideoInit = KMSDRM_VideoInit;
+ device->VideoQuit = KMSDRM_VideoQuit;
+ device->GetDisplayModes = KMSDRM_GetDisplayModes;
+ device->SetDisplayMode = KMSDRM_SetDisplayMode;
+ device->CreateSDLWindow = KMSDRM_CreateWindow;
+ device->CreateSDLWindowFrom = KMSDRM_CreateWindowFrom;
+ device->SetWindowTitle = KMSDRM_SetWindowTitle;
+ device->SetWindowIcon = KMSDRM_SetWindowIcon;
+ device->SetWindowPosition = KMSDRM_SetWindowPosition;
+ device->SetWindowSize = KMSDRM_SetWindowSize;
+ device->ShowWindow = KMSDRM_ShowWindow;
+ device->HideWindow = KMSDRM_HideWindow;
+ device->RaiseWindow = KMSDRM_RaiseWindow;
+ device->MaximizeWindow = KMSDRM_MaximizeWindow;
+ device->MinimizeWindow = KMSDRM_MinimizeWindow;
+ device->RestoreWindow = KMSDRM_RestoreWindow;
+ device->SetWindowGrab = KMSDRM_SetWindowGrab;
+ device->DestroyWindow = KMSDRM_DestroyWindow;
+ device->GetWindowWMInfo = KMSDRM_GetWindowWMInfo;
+#if SDL_VIDEO_OPENGL_EGL
+ device->GL_LoadLibrary = KMSDRM_GLES_LoadLibrary;
+ device->GL_GetProcAddress = KMSDRM_GLES_GetProcAddress;
+ device->GL_UnloadLibrary = KMSDRM_GLES_UnloadLibrary;
+ device->GL_CreateContext = KMSDRM_GLES_CreateContext;
+ device->GL_MakeCurrent = KMSDRM_GLES_MakeCurrent;
+ device->GL_SetSwapInterval = KMSDRM_GLES_SetSwapInterval;
+ device->GL_GetSwapInterval = KMSDRM_GLES_GetSwapInterval;
+ device->GL_SwapWindow = KMSDRM_GLES_SwapWindow;
+ device->GL_DeleteContext = KMSDRM_GLES_DeleteContext;
+#endif
+
+ device->PumpEvents = KMSDRM_PumpEvents;
+
+ return device;
+
+cleanup:
+ if (device != NULL)
+ SDL_free(device);
+ if (vdata != NULL)
+ SDL_free(vdata);
+ return NULL;
+}
+
+VideoBootStrap KMSDRM_bootstrap = {
+ "KMSDRM",
+ "KMS/DRM Video Driver",
+ KMSDRM_Available,
+ KMSDRM_Create
+};
+
+
+static void
+KMSDRM_FBDestroyCallback(struct gbm_bo *bo, void *data)
+{
+ KMSDRM_FBInfo *fb_info = (KMSDRM_FBInfo *)data;
+
+ if (fb_info && fb_info->drm_fd > 0 && fb_info->fb_id != 0) {
+ KMSDRM_drmModeRmFB(fb_info->drm_fd, fb_info->fb_id);
+ SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Delete DRM FB %u", fb_info->fb_id);
+ }
+
+ free(fb_info);
+}
+
+KMSDRM_FBInfo *
+KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo)
+{
+ uint32_t w, h, stride, handle;
+ int ret;
+ SDL_VideoData *vdata = ((SDL_VideoData *)_this->driverdata);
+ KMSDRM_FBInfo *fb_info;
+
+ fb_info = (KMSDRM_FBInfo *)KMSDRM_gbm_bo_get_user_data(bo);
+ if (fb_info != NULL) {
+ /* Have a previously used framebuffer, return it */
+ return fb_info;
+ }
+
+ /* Here a new DRM FB must be created */
+ fb_info = (KMSDRM_FBInfo *)SDL_calloc(1, sizeof(KMSDRM_FBInfo));
+ if (fb_info == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ fb_info->drm_fd = vdata->drm_fd;
+
+ w = KMSDRM_gbm_bo_get_width(bo);
+ h = KMSDRM_gbm_bo_get_height(bo);
+ stride = KMSDRM_gbm_bo_get_stride(bo);
+ handle = KMSDRM_gbm_bo_get_handle(bo).u32;
+
+ ret = KMSDRM_drmModeAddFB(vdata->drm_fd, w, h, 24, 32, stride, handle, &fb_info->fb_id);
+ if (ret < 0) {
+ free(fb_info);
+ return NULL;
+ }
+ SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "New DRM FB (%u): %ux%u, stride %u from BO %p", fb_info->fb_id, w, h, stride, (void *)bo);
+
+ /* Associate our DRM framebuffer with this buffer object */
+ KMSDRM_gbm_bo_set_user_data(bo, fb_info, KMSDRM_FBDestroyCallback);
+ return fb_info;
+}
+
+SDL_bool
+KMSDRM_WaitPageFlip(_THIS, SDL_WindowData *wdata, int timeout) {
+ SDL_VideoData *vdata = ((SDL_VideoData *)_this->driverdata);
+
+ while (wdata->waiting_for_flip) {
+ vdata->drm_pollfd.revents = 0;
+ if (poll(&vdata->drm_pollfd, 1, timeout) < 0) {
+ SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "DRM poll error");
+ return SDL_FALSE;
+ }
+
+ if (vdata->drm_pollfd.revents & (POLLHUP | POLLERR)) {
+ SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "DRM poll hup or error");
+ return SDL_FALSE;
+ }
+
+ if (vdata->drm_pollfd.revents & POLLIN) {
+ /* Page flip? If so, drmHandleEvent will unset wdata->waiting_for_flip */
+ KMSDRM_drmHandleEvent(vdata->drm_fd, &vdata->drm_evctx);
+ } else {
+ /* Timed out and page flip didn't happen */
+ SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Dropping frame while waiting_for_flip");
+ return SDL_FALSE;
+ }
+ }
+ return SDL_TRUE;
+}
+
+static void
+KMSDRM_FlipHandler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, void *data)
+{
+ *((SDL_bool *) data) = SDL_FALSE;
+}
+
+
+/*****************************************************************************/
+/* SDL Video and Display initialization/handling functions */
+/* _this is a SDL_VideoDevice * */
+/*****************************************************************************/
+int
+KMSDRM_VideoInit(_THIS)
+{
+ int i;
+ int ret = 0;
+ char *devname;
+ SDL_VideoData *vdata = ((SDL_VideoData *)_this->driverdata);
+ drmModeRes *resources = NULL;
+ drmModeConnector *connector = NULL;
+ drmModeEncoder *encoder = NULL;
+ SDL_DisplayMode current_mode;
+ SDL_VideoDisplay display;
+
+ /* Allocate display internal data */
+ SDL_DisplayData *data = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
+ if (data == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "KMSDRM_VideoInit()");
+
+ /* Open /dev/dri/cardNN */
+ devname = (char *) SDL_calloc(1, 16);
+ if (devname == NULL) {
+ ret = SDL_OutOfMemory();
+ goto cleanup;
+ }
+ SDL_snprintf(devname, 16, "/dev/dri/card%d", vdata->devindex);
+ vdata->drm_fd = open(devname, O_RDWR | O_CLOEXEC);
+ SDL_free(devname);
+
+ if (vdata->drm_fd < 0) {
+ ret = SDL_SetError("Could not open /dev/dri/card%d.", vdata->devindex);
+ goto cleanup;
+ }
+ SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Opened DRM FD (%d)", vdata->drm_fd);
+
+ vdata->gbm = KMSDRM_gbm_create_device(vdata->drm_fd);
+ if (vdata->gbm == NULL) {
+ ret = SDL_SetError("Couldn't create gbm device.");
+ goto cleanup;
+ }
+
+ /* Find the first available connector with modes */
+ resources = KMSDRM_drmModeGetResources(vdata->drm_fd);
+ if (!resources) {
+ ret = SDL_SetError("drmModeGetResources(%d) failed", vdata->drm_fd);
+ goto cleanup;
+ }
+
+ for (i = 0; i < resources->count_connectors; i++) {
+ connector = KMSDRM_drmModeGetConnector(vdata->drm_fd, resources->connectors[i]);
+ if (connector == NULL)
+ continue;
+
+ if (connector->connection == DRM_MODE_CONNECTED &&
+ connector->count_modes > 0) {
+ SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Found connector %d with %d modes.",
+ connector->connector_id, connector->count_modes);
+ vdata->saved_conn_id = connector->connector_id;
+ break;
+ }
+
+ KMSDRM_drmModeFreeConnector(connector);
+ connector = NULL;
+ }
+
+ if (i == resources->count_connectors) {
+ ret = SDL_SetError("No currently active connector found.");
+ goto cleanup;
+ }
+
+ for (i = 0; i < resources->count_encoders; i++) {
+ encoder = KMSDRM_drmModeGetEncoder(vdata->drm_fd, resources->encoders[i]);
+
+ if (encoder == NULL)
+ continue;
+
+ if (encoder->encoder_id == connector->encoder_id) {
+ SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Found encoder %d.", encoder->encoder_id);
+ data->encoder_id = encoder->encoder_id;
+ break;
+ }
+
+ KMSDRM_drmModeFreeEncoder(encoder);
+ encoder = NULL;
+ }
+
+ if (i == resources->count_encoders) {
+ ret = SDL_SetError("No connected encoder found.");
+ goto cleanup;
+ }
+
+ vdata->saved_crtc = KMSDRM_drmModeGetCrtc(vdata->drm_fd, encoder->crtc_id);
+ if (vdata->saved_crtc == NULL) {
+ ret = SDL_SetError("No CRTC found.");
+ goto cleanup;
+ }
+ SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Saved crtc_id %u, fb_id %u, (%u,%u), %ux%u",
+ vdata->saved_crtc->crtc_id, vdata->saved_crtc->buffer_id, vdata->saved_crtc->x,
+ vdata->saved_crtc->y, vdata->saved_crtc->width, vdata->saved_crtc->height);
+ data->crtc_id = encoder->crtc_id;
+ data->cur_mode = vdata->saved_crtc->mode;
+ vdata->crtc_id = encoder->crtc_id;
+
+ SDL_zero(current_mode);
+
+ current_mode.w = vdata->saved_crtc->mode.hdisplay;
+ current_mode.h = vdata->saved_crtc->mode.vdisplay;
+ current_mode.refresh_rate = vdata->saved_crtc->mode.vrefresh;
+
+ /* FIXME ?
+ drmModeFB *fb = drmModeGetFB(vdata->drm_fd, vdata->saved_crtc->buffer_id);
+ current_mode.format = drmToSDLPixelFormat(fb->bpp, fb->depth);
+ drmModeFreeFB(fb);
+ */
+ current_mode.format = SDL_PIXELFORMAT_ARGB8888;
+
+ current_mode.driverdata = NULL;
+
+ SDL_zero(display);
+ display.desktop_mode = current_mode;
+ display.current_mode = current_mode;
+
+ display.driverdata = data;
+ /* SDL_VideoQuit will later SDL_free(display.driverdata) */
+ SDL_AddVideoDisplay(&display);
+
+ /* Setup page flip handler */
+ vdata->drm_pollfd.fd = vdata->drm_fd;
+ vdata->drm_pollfd.events = POLLIN;
+ vdata->drm_evctx.version = DRM_EVENT_CONTEXT_VERSION;
+ vdata->drm_evctx.page_flip_handler = KMSDRM_FlipHandler;
+
+#ifdef SDL_INPUT_LINUXEV
+ SDL_EVDEV_Init();
+#endif
+
+ KMSDRM_InitMouse(_this);
+
+cleanup:
+ if (encoder != NULL)
+ KMSDRM_drmModeFreeEncoder(encoder);
+ if (connector != NULL)
+ KMSDRM_drmModeFreeConnector(connector);
+ if (resources != NULL)
+ KMSDRM_drmModeFreeResources(resources);
+
+ if (ret != 0) {
+ /* Error (complete) cleanup */
+ SDL_free(data);
+ if(vdata->saved_crtc != NULL) {
+ KMSDRM_drmModeFreeCrtc(vdata->saved_crtc);
+ vdata->saved_crtc = NULL;
+ }
+ if (vdata->gbm != NULL) {
+ KMSDRM_gbm_device_destroy(vdata->gbm);
+ vdata->gbm = NULL;
+ }
+ if (vdata->drm_fd >= 0) {
+ close(vdata->drm_fd);
+ vdata->drm_fd = -1;
+ }
+ }
+ return ret;
+}
+
+void
+KMSDRM_VideoQuit(_THIS)
+{
+ SDL_VideoData *vdata = ((SDL_VideoData *)_this->driverdata);
+
+ SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "KMSDRM_VideoQuit()");
+
+ if (_this->gl_config.driver_loaded) {
+ SDL_GL_UnloadLibrary();
+ }
+
+ if(vdata->saved_crtc != NULL) {
+ if(vdata->drm_fd > 0 && vdata->saved_conn_id > 0) {
+ /* Restore saved CRTC settings */
+ drmModeCrtc *crtc = vdata->saved_crtc;
+ if(KMSDRM_drmModeSetCrtc(vdata->drm_fd, crtc->crtc_id, crtc->buffer_id,
+ crtc->x, crtc->y, &vdata->saved_conn_id, 1,
+ &crtc->mode) != 0) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "Could not restore original CRTC mode");
+ }
+ }
+ KMSDRM_drmModeFreeCrtc(vdata->saved_crtc);
+ vdata->saved_crtc = NULL;
+ }
+ if (vdata->gbm != NULL) {
+ KMSDRM_gbm_device_destroy(vdata->gbm);
+ vdata->gbm = NULL;
+ }
+ if (vdata->drm_fd >= 0) {
+ close(vdata->drm_fd);
+ SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Closed DRM FD %d", vdata->drm_fd);
+ vdata->drm_fd = -1;
+ }
+#ifdef SDL_INPUT_LINUXEV
+ SDL_EVDEV_Quit();
+#endif
+}
+
+void
+KMSDRM_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
+{
+ /* Only one display mode available, the current one */
+ SDL_AddDisplayMode(display, &display->current_mode);
+}
+
+int
+KMSDRM_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
+{
+ return 0;
+}
+
+int
+KMSDRM_CreateWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *wdata;
+ SDL_VideoDisplay *display;
+ SDL_VideoData *vdata = ((SDL_VideoData *)_this->driverdata);
+ Uint32 surface_fmt, surface_flags;
+
+ /* Allocate window internal data */
+ wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
+ if (wdata == NULL) {
+ SDL_OutOfMemory();
+ goto error;
+ }
+
+ wdata->waiting_for_flip = SDL_FALSE;
+ display = SDL_GetDisplayForWindow(window);
+
+ /* Windows have one size for now */
+ window->w = display->desktop_mode.w;
+ window->h = display->desktop_mode.h;
+
+ /* Maybe you didn't ask for a fullscreen OpenGL window, but that's what you get */
+ window->flags |= (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL);
+
+ surface_fmt = GBM_FORMAT_XRGB8888;
+ surface_flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
+
+ if (!KMSDRM_gbm_device_is_format_supported(vdata->gbm, surface_fmt, surface_flags)) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "GBM surface format not supported. Trying anyway.");
+ }
+ wdata->gs = KMSDRM_gbm_surface_create(vdata->gbm, window->w, window->h, surface_fmt, surface_flags);
+
+#if SDL_VIDEO_OPENGL_EGL
+ if (!_this->egl_data) {
+ if (SDL_GL_LoadLibrary(NULL) < 0) {
+ goto error;
+ }
+ }
+ wdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) wdata->gs);
+
+ if (wdata->egl_surface == EGL_NO_SURFACE) {
+ SDL_SetError("Could not create EGL window surface");
+ goto error;
+ }
+#endif /* SDL_VIDEO_OPENGL_EGL */
+
+ /* In case we want low-latency, double-buffer video, we take note here */
+ wdata->double_buffer = SDL_FALSE;
+ if (SDL_GetHintBoolean(SDL_HINT_VIDEO_DOUBLE_BUFFER, SDL_FALSE)) {
+ wdata->double_buffer = SDL_TRUE;
+ }
+
+ /* Window is created, but we have yet to set up CRTC to one of the GBM buffers if we want
+ drmModePageFlip to work, and we can't do it until EGL is completely setup, because we
+ need to do eglSwapBuffers so we can get a valid GBM buffer object to call
+ drmModeSetCrtc on it. */
+ wdata->crtc_ready = SDL_FALSE;
+
+ /* Setup driver data for this window */
+ window->driverdata = wdata;
+
+ /* One window, it always has focus */
+ SDL_SetMouseFocus(window);
+ SDL_SetKeyboardFocus(window);
+
+ /* Window has been successfully created */
+ return 0;
+
+error:
+ if (wdata != NULL) {
+#if SDL_VIDEO_OPENGL_EGL
+ if (wdata->egl_surface != EGL_NO_SURFACE)
+ SDL_EGL_DestroySurface(_this, wdata->egl_surface);
+#endif /* SDL_VIDEO_OPENGL_EGL */
+ if (wdata->gs != NULL)
+ KMSDRM_gbm_surface_destroy(wdata->gs);
+ SDL_free(wdata);
+ }
+ return -1;
+}
+
+void
+KMSDRM_DestroyWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ if(data) {
+ /* Wait for any pending page flips and unlock buffer */
+ KMSDRM_WaitPageFlip(_this, data, -1);
+ if (data->next_bo != NULL) {
+ KMSDRM_gbm_surface_release_buffer(data->gs, data->next_bo);
+ data->next_bo = NULL;
+ }
+ if (data->current_bo != NULL) {
+ KMSDRM_gbm_surface_release_buffer(data->gs, data->current_bo);
+ data->current_bo = NULL;
+ }
+#if SDL_VIDEO_OPENGL_EGL
+ SDL_EGL_MakeCurrent(_this, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ if (data->egl_surface != EGL_NO_SURFACE) {
+ SDL_EGL_DestroySurface(_this, data->egl_surface);
+ }
+#endif /* SDL_VIDEO_OPENGL_EGL */
+ if (data->gs != NULL) {
+ KMSDRM_gbm_surface_destroy(data->gs);
+ data->gs = NULL;
+ }
+ SDL_free(data);
+ window->driverdata = NULL;
+ }
+}
+
+int
+KMSDRM_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
+{
+ return -1;
+}
+
+void
+KMSDRM_SetWindowTitle(_THIS, SDL_Window * window)
+{
+}
+void
+KMSDRM_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
+{
+}
+void
+KMSDRM_SetWindowPosition(_THIS, SDL_Window * window)
+{
+}
+void
+KMSDRM_SetWindowSize(_THIS, SDL_Window * window)
+{
+}
+void
+KMSDRM_ShowWindow(_THIS, SDL_Window * window)
+{
+}
+void
+KMSDRM_HideWindow(_THIS, SDL_Window * window)
+{
+}
+void
+KMSDRM_RaiseWindow(_THIS, SDL_Window * window)
+{
+}
+void
+KMSDRM_MaximizeWindow(_THIS, SDL_Window * window)
+{
+}
+void
+KMSDRM_MinimizeWindow(_THIS, SDL_Window * window)
+{
+}
+void
+KMSDRM_RestoreWindow(_THIS, SDL_Window * window)
+{
+}
+void
+KMSDRM_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
+{
+
+}
+
+/*****************************************************************************/
+/* SDL Window Manager function */
+/*****************************************************************************/
+SDL_bool
+KMSDRM_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
+{
+ if (info->version.major <= SDL_MAJOR_VERSION) {
+ return SDL_TRUE;
+ } else {
+ SDL_SetError("application not compiled with SDL %d.%d\n",
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+ return SDL_FALSE;
+ }
+
+ /* Failed to get window manager information */
+ return SDL_FALSE;
+}
+
+#endif /* SDL_VIDEO_DRIVER_KMSDRM */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmvideo.h b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmvideo.h
new file mode 100644
index 0000000..5f00f0e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/kmsdrm/SDL_kmsdrmvideo.h
@@ -0,0 +1,124 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef __SDL_KMSDRMVIDEO_H__
+#define __SDL_KMSDRMVIDEO_H__
+
+#include "../SDL_sysvideo.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <poll.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+#include <gbm.h>
+#if SDL_VIDEO_OPENGL_EGL
+#include <EGL/egl.h>
+#endif
+
+typedef struct SDL_VideoData
+{
+ int devindex; /* device index that was passed on creation */
+ int drm_fd; /* DRM file desc */
+ struct gbm_device *gbm;
+ drmEventContext drm_evctx; /* DRM event context */
+ struct pollfd drm_pollfd; /* pollfd containing DRM file desc */
+ drmModeCrtc *saved_crtc; /* Saved CRTC to restore on quit */
+ uint32_t saved_conn_id; /* Saved DRM connector ID */
+ uint32_t crtc_id; /* CRTC in use */
+} SDL_VideoData;
+
+
+typedef struct SDL_DisplayData
+{
+ uint32_t encoder_id;
+ uint32_t crtc_id;
+ drmModeModeInfo cur_mode;
+} SDL_DisplayData;
+
+
+typedef struct SDL_WindowData
+{
+ struct gbm_surface *gs;
+ struct gbm_bo *current_bo;
+ struct gbm_bo *next_bo;
+ SDL_bool waiting_for_flip;
+ SDL_bool crtc_ready;
+ SDL_bool double_buffer;
+#if SDL_VIDEO_OPENGL_EGL
+ EGLSurface egl_surface;
+#endif
+} SDL_WindowData;
+
+typedef struct KMSDRM_FBInfo
+{
+ int drm_fd; /* DRM file desc */
+ uint32_t fb_id; /* DRM framebuffer ID */
+} KMSDRM_FBInfo;
+
+/* Helper functions */
+KMSDRM_FBInfo *KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo);
+SDL_bool KMSDRM_WaitPageFlip(_THIS, SDL_WindowData *wdata, int timeout);
+
+/****************************************************************************/
+/* SDL_VideoDevice functions declaration */
+/****************************************************************************/
+
+/* Display and window functions */
+int KMSDRM_VideoInit(_THIS);
+void KMSDRM_VideoQuit(_THIS);
+void KMSDRM_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
+int KMSDRM_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
+int KMSDRM_CreateWindow(_THIS, SDL_Window * window);
+int KMSDRM_CreateWindowFrom(_THIS, SDL_Window * window, const void *data);
+void KMSDRM_SetWindowTitle(_THIS, SDL_Window * window);
+void KMSDRM_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
+void KMSDRM_SetWindowPosition(_THIS, SDL_Window * window);
+void KMSDRM_SetWindowSize(_THIS, SDL_Window * window);
+void KMSDRM_ShowWindow(_THIS, SDL_Window * window);
+void KMSDRM_HideWindow(_THIS, SDL_Window * window);
+void KMSDRM_RaiseWindow(_THIS, SDL_Window * window);
+void KMSDRM_MaximizeWindow(_THIS, SDL_Window * window);
+void KMSDRM_MinimizeWindow(_THIS, SDL_Window * window);
+void KMSDRM_RestoreWindow(_THIS, SDL_Window * window);
+void KMSDRM_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
+void KMSDRM_DestroyWindow(_THIS, SDL_Window * window);
+
+/* Window manager function */
+SDL_bool KMSDRM_GetWindowWMInfo(_THIS, SDL_Window * window,
+ struct SDL_SysWMinfo *info);
+
+/* OpenGL/OpenGL ES functions */
+int KMSDRM_GLES_LoadLibrary(_THIS, const char *path);
+void *KMSDRM_GLES_GetProcAddress(_THIS, const char *proc);
+void KMSDRM_GLES_UnloadLibrary(_THIS);
+SDL_GLContext KMSDRM_GLES_CreateContext(_THIS, SDL_Window * window);
+int KMSDRM_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+int KMSDRM_GLES_SetSwapInterval(_THIS, int interval);
+int KMSDRM_GLES_GetSwapInterval(_THIS);
+int KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window);
+void KMSDRM_GLES_DeleteContext(_THIS, SDL_GLContext context);
+
+#endif /* __SDL_KMSDRMVIDEO_H__ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/mir/SDL_mirdyn.c b/src/3rdparty/SDL2/src/video/mir/SDL_mirdyn.c
new file mode 100644
index 0000000..71dc73c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/mir/SDL_mirdyn.c
@@ -0,0 +1,170 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_MIR
+
+#define DEBUG_DYNAMIC_MIR 0
+
+#include "SDL_mirdyn.h"
+
+#if DEBUG_DYNAMIC_MIR
+#include "SDL_log.h"
+#endif
+
+#ifdef SDL_VIDEO_DRIVER_MIR_DYNAMIC
+
+#include "SDL_name.h"
+#include "SDL_loadso.h"
+
+typedef struct
+{
+ void *lib;
+ const char *libname;
+} mirdynlib;
+
+#ifndef SDL_VIDEO_DRIVER_MIR_DYNAMIC
+#define SDL_VIDEO_DRIVER_MIR_DYNAMIC NULL
+#endif
+#ifndef SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON
+#define SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON NULL
+#endif
+
+static mirdynlib mirlibs[] = {
+ {NULL, SDL_VIDEO_DRIVER_MIR_DYNAMIC},
+ {NULL, SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON}
+};
+
+static void *
+MIR_GetSym(const char *fnname, int *pHasModule)
+{
+ int i;
+ void *fn = NULL;
+ for (i = 0; i < SDL_TABLESIZE(mirlibs); i++) {
+ if (mirlibs[i].lib != NULL) {
+ fn = SDL_LoadFunction(mirlibs[i].lib, fnname);
+ if (fn != NULL)
+ break;
+ }
+ }
+
+#if DEBUG_DYNAMIC_MIR
+ if (fn != NULL)
+ SDL_Log("MIR: Found '%s' in %s (%p)\n", fnname, mirlibs[i].libname, fn);
+ else
+ SDL_Log("MIR: Symbol '%s' NOT FOUND!\n", fnname);
+#endif
+
+ if (fn == NULL)
+ *pHasModule = 0; /* kill this module. */
+
+ return fn;
+}
+
+#endif /* SDL_VIDEO_DRIVER_MIR_DYNAMIC */
+
+/* Define all the function pointers and wrappers... */
+#define SDL_MIR_MODULE(modname) int SDL_MIR_HAVE_##modname = 0;
+#define SDL_MIR_SYM(rc,fn,params) SDL_DYNMIRFN_##fn MIR_##fn = NULL;
+#define SDL_MIR_SYM_CONST(type,name) SDL_DYMMIRCONST_##name MIR_##name = NULL;
+#include "SDL_mirsym.h"
+
+static int mir_load_refcount = 0;
+
+void
+SDL_MIR_UnloadSymbols(void)
+{
+ /* Don't actually unload if more than one module is using the libs... */
+ if (mir_load_refcount > 0) {
+ if (--mir_load_refcount == 0) {
+#ifdef SDL_VIDEO_DRIVER_MIR_DYNAMIC
+ int i;
+#endif
+
+ /* set all the function pointers to NULL. */
+#define SDL_MIR_MODULE(modname) SDL_MIR_HAVE_##modname = 0;
+#define SDL_MIR_SYM(rc,fn,params) MIR_##fn = NULL;
+#define SDL_MIR_SYM_CONST(type,name) MIR_##name = NULL;
+#include "SDL_mirsym.h"
+
+
+#ifdef SDL_VIDEO_DRIVER_MIR_DYNAMIC
+ for (i = 0; i < SDL_TABLESIZE(mirlibs); i++) {
+ if (mirlibs[i].lib != NULL) {
+ SDL_UnloadObject(mirlibs[i].lib);
+ mirlibs[i].lib = NULL;
+ }
+ }
+#endif
+ }
+ }
+}
+
+/* returns non-zero if all needed symbols were loaded. */
+int
+SDL_MIR_LoadSymbols(void)
+{
+ int rc = 1; /* always succeed if not using Dynamic MIR stuff. */
+
+ /* deal with multiple modules (dga, wayland, mir, etc) needing these symbols... */
+ if (mir_load_refcount++ == 0) {
+#ifdef SDL_VIDEO_DRIVER_MIR_DYNAMIC
+ int i;
+ int *thismod = NULL;
+ for (i = 0; i < SDL_TABLESIZE(mirlibs); i++) {
+ if (mirlibs[i].libname != NULL) {
+ mirlibs[i].lib = SDL_LoadObject(mirlibs[i].libname);
+ }
+ }
+
+#define SDL_MIR_MODULE(modname) SDL_MIR_HAVE_##modname = 1; /* default yes */
+#include "SDL_mirsym.h"
+
+#define SDL_MIR_MODULE(modname) thismod = &SDL_MIR_HAVE_##modname;
+#define SDL_MIR_SYM(rc,fn,params) MIR_##fn = (SDL_DYNMIRFN_##fn) MIR_GetSym(#fn,thismod);
+#define SDL_MIR_SYM_CONST(type,name) MIR_##name = *(SDL_DYMMIRCONST_##name*) MIR_GetSym(#name,thismod);
+#include "SDL_mirsym.h"
+
+ if ((SDL_MIR_HAVE_MIR_CLIENT) && (SDL_MIR_HAVE_XKBCOMMON)) {
+ /* all required symbols loaded. */
+ SDL_ClearError();
+ } else {
+ /* in case something got loaded... */
+ SDL_MIR_UnloadSymbols();
+ rc = 0;
+ }
+
+#else /* no dynamic MIR */
+
+#define SDL_MIR_MODULE(modname) SDL_MIR_HAVE_##modname = 1; /* default yes */
+#define SDL_MIR_SYM(rc,fn,params) MIR_##fn = fn;
+#define SDL_MIR_SYM_CONST(type,name) MIR_##name = name;
+#include "SDL_mirsym.h"
+
+#endif
+ }
+
+ return rc;
+}
+
+#endif /* SDL_VIDEO_DRIVER_MIR */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/mir/SDL_mirdyn.h b/src/3rdparty/SDL2/src/video/mir/SDL_mirdyn.h
new file mode 100644
index 0000000..32364aa
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/mir/SDL_mirdyn.h
@@ -0,0 +1,53 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_mirdyn_h_
+#define SDL_mirdyn_h_
+
+#include "../../SDL_internal.h"
+
+#include <EGL/egl.h>
+#include <mir_toolkit/mir_client_library.h>
+#include <xkbcommon/xkbcommon.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int SDL_MIR_LoadSymbols(void);
+void SDL_MIR_UnloadSymbols(void);
+
+/* Declare all the function pointers and wrappers... */
+#define SDL_MIR_SYM(rc,fn,params) \
+ typedef rc (*SDL_DYNMIRFN_##fn) params; \
+ extern SDL_DYNMIRFN_##fn MIR_##fn;
+#define SDL_MIR_SYM_CONST(type, name) \
+ typedef type SDL_DYMMIRCONST_##name; \
+ extern SDL_DYMMIRCONST_##name MIR_##name;
+#include "SDL_mirsym.h"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !defined SDL_mirdyn_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/mir/SDL_mirevents.c b/src/3rdparty/SDL2/src/video/mir/SDL_mirevents.c
new file mode 100644
index 0000000..df92799
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/mir/SDL_mirevents.c
@@ -0,0 +1,321 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_MIR
+
+#include "../../events/SDL_events_c.h"
+#include "../../events/SDL_keyboard_c.h"
+#include "../../events/SDL_touch_c.h"
+#include "../../events/scancodes_xfree86.h"
+
+#include "SDL_mirevents.h"
+#include "SDL_mirwindow.h"
+
+#include <xkbcommon/xkbcommon.h>
+
+#include "SDL_mirdyn.h"
+
+static void
+HandleKeyText(int32_t key_code)
+{
+ char text[8];
+ int size = 0;
+
+ size = MIR_xkb_keysym_to_utf8(key_code, text, sizeof text);
+
+ if (size > 0) {
+ text[size] = '\0';
+ SDL_SendKeyboardText(text);
+ }
+}
+
+/* FIXME
+ Mir still needs to implement its IM API, for now we assume
+ a single key press produces a character.
+*/
+static void
+HandleKeyEvent(MirKeyboardEvent const* key_event, SDL_Window* window)
+{
+ xkb_keysym_t key_code;
+ Uint8 key_state;
+ int event_scancode;
+ uint32_t sdl_scancode = SDL_SCANCODE_UNKNOWN;
+
+ MirKeyboardAction action = MIR_mir_keyboard_event_action(key_event);
+
+ key_state = SDL_PRESSED;
+ key_code = MIR_mir_keyboard_event_key_code(key_event);
+ event_scancode = MIR_mir_keyboard_event_scan_code(key_event);
+
+ if (action == mir_keyboard_action_up)
+ key_state = SDL_RELEASED;
+
+ if (event_scancode < SDL_arraysize(xfree86_scancode_table2))
+ sdl_scancode = xfree86_scancode_table2[event_scancode];
+
+ if (sdl_scancode != SDL_SCANCODE_UNKNOWN)
+ SDL_SendKeyboardKey(key_state, sdl_scancode);
+
+ if (key_state == SDL_PRESSED)
+ HandleKeyText(key_code);
+}
+
+static void
+HandleMouseButton(SDL_Window* sdl_window, Uint8 state, MirPointerEvent const* pointer)
+{
+ uint32_t sdl_button = SDL_BUTTON_LEFT;
+ MirPointerButton button_state = mir_pointer_button_primary;
+
+ static uint32_t old_button_states = 0;
+ uint32_t new_button_states = MIR_mir_pointer_event_buttons(pointer);
+
+ // XOR on our old button states vs our new states to get the newley pressed/released button
+ button_state = new_button_states ^ old_button_states;
+
+ switch (button_state) {
+ case mir_pointer_button_primary:
+ sdl_button = SDL_BUTTON_LEFT;
+ break;
+ case mir_pointer_button_secondary:
+ sdl_button = SDL_BUTTON_RIGHT;
+ break;
+ case mir_pointer_button_tertiary:
+ sdl_button = SDL_BUTTON_MIDDLE;
+ break;
+ case mir_pointer_button_forward:
+ sdl_button = SDL_BUTTON_X1;
+ break;
+ case mir_pointer_button_back:
+ sdl_button = SDL_BUTTON_X2;
+ break;
+ default:
+ break;
+ }
+
+ old_button_states = new_button_states;
+
+ SDL_SendMouseButton(sdl_window, 0, state, sdl_button);
+}
+
+static void
+HandleMouseMotion(SDL_Window* sdl_window, int x, int y)
+{
+ SDL_Mouse* mouse = SDL_GetMouse();
+ SDL_SendMouseMotion(sdl_window, 0, mouse->relative_mode, x, y);
+}
+
+static void
+HandleTouchPress(int device_id, int source_id, SDL_bool down, float x, float y, float pressure)
+{
+ SDL_SendTouch(device_id, source_id, down, x, y, pressure);
+}
+
+static void
+HandleTouchMotion(int device_id, int source_id, float x, float y, float pressure)
+{
+ SDL_SendTouchMotion(device_id, source_id, x, y, pressure);
+}
+
+static void
+HandleMouseScroll(SDL_Window* sdl_window, float hscroll, float vscroll)
+{
+ SDL_SendMouseWheel(sdl_window, 0, hscroll, vscroll, SDL_MOUSEWHEEL_NORMAL);
+}
+
+static void
+AddTouchDevice(int device_id)
+{
+ if (SDL_AddTouch(device_id, "") < 0)
+ SDL_SetError("Error: can't add touch %s, %d", __FILE__, __LINE__);
+}
+
+static void
+HandleTouchEvent(MirTouchEvent const* touch, int device_id, SDL_Window* sdl_window)
+{
+ int i, point_count;
+ point_count = MIR_mir_touch_event_point_count(touch);
+
+ AddTouchDevice(device_id);
+
+ for (i = 0; i < point_count; i++) {
+ int id = MIR_mir_touch_event_id(touch, i);
+
+ int width = sdl_window->w;
+ int height = sdl_window->h;
+
+ float x = MIR_mir_touch_event_axis_value(touch, i, mir_touch_axis_x);
+ float y = MIR_mir_touch_event_axis_value(touch, i, mir_touch_axis_y);
+
+ float n_x = x / width;
+ float n_y = y / height;
+
+ float pressure = MIR_mir_touch_event_axis_value(touch, i, mir_touch_axis_pressure);
+
+ switch (MIR_mir_touch_event_action(touch, i)) {
+ case mir_touch_action_up:
+ HandleTouchPress(device_id, id, SDL_FALSE, n_x, n_y, pressure);
+ break;
+ case mir_touch_action_down:
+ HandleTouchPress(device_id, id, SDL_TRUE, n_x, n_y, pressure);
+ break;
+ case mir_touch_action_change:
+ HandleTouchMotion(device_id, id, n_x, n_y, pressure);
+ break;
+ case mir_touch_actions:
+ break;
+ }
+ }
+}
+
+static void
+HandleMouseEvent(MirPointerEvent const* pointer, SDL_Window* sdl_window)
+{
+ SDL_SetMouseFocus(sdl_window);
+
+ switch (MIR_mir_pointer_event_action(pointer)) {
+ case mir_pointer_action_button_down:
+ HandleMouseButton(sdl_window, SDL_PRESSED, pointer);
+ break;
+ case mir_pointer_action_button_up:
+ HandleMouseButton(sdl_window, SDL_RELEASED, pointer);
+ break;
+ case mir_pointer_action_motion: {
+ int x, y;
+ float hscroll, vscroll;
+ SDL_Mouse* mouse = SDL_GetMouse();
+ x = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_x);
+ y = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_y);
+
+ if (mouse) {
+ if (mouse->relative_mode) {
+ int relative_x = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_relative_x);
+ int relative_y = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_relative_y);
+ HandleMouseMotion(sdl_window, relative_x, relative_y);
+ }
+ else if (mouse->x != x || mouse->y != y) {
+ HandleMouseMotion(sdl_window, x, y);
+ }
+ }
+
+ hscroll = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_hscroll);
+ vscroll = MIR_mir_pointer_event_axis_value(pointer, mir_pointer_axis_vscroll);
+ if (vscroll != 0 || hscroll != 0)
+ HandleMouseScroll(sdl_window, hscroll, vscroll);
+ }
+ break;
+ case mir_pointer_action_leave:
+ SDL_SetMouseFocus(NULL);
+ break;
+ case mir_pointer_action_enter:
+ default:
+ break;
+ }
+}
+
+static void
+HandleInput(MirInputEvent const* input_event, SDL_Window* window)
+{
+ switch (MIR_mir_input_event_get_type(input_event)) {
+ case (mir_input_event_type_key):
+ HandleKeyEvent(MIR_mir_input_event_get_keyboard_event(input_event), window);
+ break;
+ case (mir_input_event_type_pointer):
+ HandleMouseEvent(MIR_mir_input_event_get_pointer_event(input_event), window);
+ break;
+ case (mir_input_event_type_touch):
+ HandleTouchEvent(MIR_mir_input_event_get_touch_event(input_event),
+ MIR_mir_input_event_get_device_id(input_event),
+ window);
+ break;
+ default:
+ break;
+ }
+}
+
+static void
+HandleResize(MirResizeEvent const* resize_event, SDL_Window* window)
+{
+ int new_w = MIR_mir_resize_event_get_width (resize_event);
+ int new_h = MIR_mir_resize_event_get_height(resize_event);
+
+ int old_w = window->w;
+ int old_h = window->h;
+
+ if (new_w != old_w || new_h != old_h)
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, new_w, new_h);
+}
+
+static void
+HandleWindow(MirWindowEvent const* event, SDL_Window* window)
+{
+ MirWindowAttrib attrib = MIR_mir_window_event_get_attribute(event);
+ int value = MIR_mir_window_event_get_attribute_value(event);
+
+ if (attrib == mir_window_attrib_focus) {
+ if (value == mir_window_focus_state_focused) {
+ SDL_SetKeyboardFocus(window);
+ }
+ else if (value == mir_window_focus_state_unfocused) {
+ SDL_SetKeyboardFocus(NULL);
+ }
+ }
+}
+
+static void
+MIR_HandleClose(SDL_Window* window) {
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_CLOSE, 0, 0);
+}
+
+void
+MIR_HandleEvent(MirWindow* mirwindow, MirEvent const* ev, void* context)
+{
+ MirEventType event_type = MIR_mir_event_get_type(ev);
+ SDL_Window* window = (SDL_Window*)context;
+
+ if (window) {
+ switch (event_type) {
+ case (mir_event_type_input):
+ HandleInput(MIR_mir_event_get_input_event(ev), window);
+ break;
+ case (mir_event_type_resize):
+ HandleResize(MIR_mir_event_get_resize_event(ev), window);
+ break;
+ case (mir_event_type_window):
+ HandleWindow(MIR_mir_event_get_window_event(ev), window);
+ break;
+ case (mir_event_type_close_window):
+ MIR_HandleClose(window);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_MIR */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/mir/SDL_mirevents.h b/src/3rdparty/SDL2/src/video/mir/SDL_mirevents.h
new file mode 100644
index 0000000..4b0f209
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/mir/SDL_mirevents.h
@@ -0,0 +1,37 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
+*/
+
+#ifndef SDL_mirevents_h_
+#define SDL_mirevents_h_
+
+#include <mir_toolkit/mir_client_library.h>
+
+extern void
+MIR_HandleEvent(MirWindow*, MirEvent const* ev, void* context);
+
+#endif /* SDL_mirevents_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/video/mir/SDL_mirframebuffer.c b/src/3rdparty/SDL2/src/video/mir/SDL_mirframebuffer.c
new file mode 100644
index 0000000..d678fff
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/mir/SDL_mirframebuffer.c
@@ -0,0 +1,134 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_MIR
+
+#include "SDL_mirevents.h"
+#include "SDL_mirframebuffer.h"
+#include "SDL_mirwindow.h"
+
+#include "SDL_mirdyn.h"
+
+int
+MIR_CreateWindowFramebuffer(_THIS, SDL_Window* window, Uint32* format,
+ void** pixels, int* pitch)
+{
+ MIR_Data* mir_data = _this->driverdata;
+
+ mir_data->software = SDL_TRUE;
+
+ if (MIR_CreateWindow(_this, window) < 0)
+ return SDL_SetError("Failed to create a mir window.");
+
+ *format = MIR_GetSDLPixelFormat(mir_data->pixel_format);
+ if (*format == SDL_PIXELFORMAT_UNKNOWN)
+ return SDL_SetError("Unknown pixel format");
+
+ *pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
+
+ *pixels = SDL_malloc(window->h*(*pitch));
+ if (*pixels == NULL)
+ return SDL_OutOfMemory();
+
+ return 0;
+}
+
+int
+MIR_UpdateWindowFramebuffer(_THIS, SDL_Window* window,
+ const SDL_Rect* rects, int numrects)
+{
+ MIR_Window* mir_window = window->driverdata;
+
+ MirGraphicsRegion region;
+ MirBufferStream* bs;
+ int i, j, x, y, w, h, start;
+ int bytes_per_pixel, bytes_per_row, s_stride, d_stride;
+ char* s_dest;
+ char* pixels;
+
+ bs = MIR_mir_window_get_buffer_stream(mir_window->window);
+ MIR_mir_buffer_stream_get_graphics_region(bs, &region);
+
+ s_dest = region.vaddr;
+ pixels = (char*)window->surface->pixels;
+
+ s_stride = window->surface->pitch;
+ d_stride = region.stride;
+ bytes_per_pixel = window->surface->format->BytesPerPixel;
+
+ for (i = 0; i < numrects; i++) {
+ s_dest = region.vaddr;
+ pixels = (char*)window->surface->pixels;
+
+ x = rects[i].x;
+ y = rects[i].y;
+ w = rects[i].w;
+ h = rects[i].h;
+
+ if (w <= 0 || h <= 0 || (x + w) <= 0 || (y + h) <= 0)
+ continue;
+
+ if (x < 0) {
+ x += w;
+ w += rects[i].x;
+ }
+
+ if (y < 0) {
+ y += h;
+ h += rects[i].y;
+ }
+
+ if (x + w > window->w)
+ w = window->w - x;
+ if (y + h > window->h)
+ h = window->h - y;
+
+ start = y * s_stride + x;
+ pixels += start;
+ s_dest += start;
+
+ bytes_per_row = bytes_per_pixel * w;
+ for (j = 0; j < h; j++) {
+ SDL_memcpy(s_dest, pixels, bytes_per_row);
+ pixels += s_stride;
+ s_dest += d_stride;
+ }
+ }
+
+ MIR_mir_buffer_stream_swap_buffers_sync(bs);
+
+ return 0;
+}
+
+void
+MIR_DestroyWindowFramebuffer(_THIS, SDL_Window* window)
+{
+}
+
+#endif /* SDL_VIDEO_DRIVER_MIR */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/mir/SDL_mirframebuffer.h b/src/3rdparty/SDL2/src/video/mir/SDL_mirframebuffer.h
new file mode 100644
index 0000000..502337c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/mir/SDL_mirframebuffer.h
@@ -0,0 +1,47 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
+*/
+
+#ifndef SDL_mirframebuffer_h_
+#define SDL_mirframebuffer_h_
+
+#include "../SDL_sysvideo.h"
+
+#include "SDL_mirvideo.h"
+
+extern int
+MIR_CreateWindowFramebuffer(_THIS, SDL_Window* sdl_window, Uint32* format,
+ void** pixels, int* pitch);
+
+extern int
+MIR_UpdateWindowFramebuffer(_THIS, SDL_Window* sdl_window,
+ const SDL_Rect* rects, int numrects);
+
+extern void
+MIR_DestroyWindowFramebuffer(_THIS, SDL_Window* sdl_window);
+
+#endif /* SDL_mirframebuffer_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/video/mir/SDL_mirmouse.c b/src/3rdparty/SDL2/src/video/mir/SDL_mirmouse.c
new file mode 100644
index 0000000..5f6e38c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/mir/SDL_mirmouse.c
@@ -0,0 +1,292 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_MIR
+
+#include "../../events/SDL_mouse_c.h"
+#include "../SDL_sysvideo.h"
+#include "SDL_assert.h"
+
+#include "SDL_mirdyn.h"
+
+#include "SDL_mirvideo.h"
+#include "SDL_mirmouse.h"
+#include "SDL_mirwindow.h"
+
+typedef struct
+{
+ MirCursorConfiguration* conf;
+ MirBufferStream* stream;
+ char const* name;
+} MIR_Cursor;
+
+static SDL_Cursor*
+MIR_CreateDefaultCursor()
+{
+ SDL_Cursor* cursor;
+
+ cursor = SDL_calloc(1, sizeof(SDL_Cursor));
+ if (cursor) {
+
+ MIR_Cursor* mir_cursor = SDL_calloc(1, sizeof(MIR_Cursor));
+ if (mir_cursor) {
+ mir_cursor->conf = NULL;
+ mir_cursor->stream = NULL;
+ mir_cursor->name = NULL;
+ cursor->driverdata = mir_cursor;
+ }
+ else {
+ SDL_OutOfMemory();
+ SDL_free(cursor);
+ cursor = NULL;
+ }
+ }
+ else {
+ SDL_OutOfMemory();
+ }
+
+ return cursor;
+}
+
+static void
+CopySurfacePixelsToMirStream(SDL_Surface* surface, MirBufferStream* stream)
+{
+ char* dest, *pixels;
+ int i, s_w, s_h, r_stride, p_stride, bytes_per_pixel, bytes_per_row;
+
+ MirGraphicsRegion region;
+ MIR_mir_buffer_stream_get_graphics_region(stream, &region);
+
+ s_w = surface->w;
+ s_h = surface->h;
+
+ bytes_per_pixel = surface->format->BytesPerPixel;
+ bytes_per_row = bytes_per_pixel * s_w;
+
+ dest = region.vaddr;
+ pixels = (char*)surface->pixels;
+
+ r_stride = region.stride;
+ p_stride = surface->pitch;
+
+ for (i = 0; i < s_h; i++)
+ {
+ SDL_memcpy(dest, pixels, bytes_per_row);
+ dest += r_stride;
+ pixels += p_stride;
+ }
+}
+
+static SDL_Cursor*
+MIR_CreateCursor(SDL_Surface* surface, int hot_x, int hot_y)
+{
+ MirCursorConfiguration* conf;
+ MirBufferStream* stream;
+
+ int s_w = surface->w;
+ int s_h = surface->h;
+
+ MIR_Data* mir_data = (MIR_Data*)SDL_GetVideoDevice()->driverdata;
+ SDL_Cursor* cursor = MIR_CreateDefaultCursor();
+ MIR_Cursor* mir_cursor;
+
+ if (!cursor) {
+ return NULL;
+ }
+
+ mir_cursor = (MIR_Cursor*)cursor->driverdata;
+
+ stream = MIR_mir_connection_create_buffer_stream_sync(mir_data->connection,
+ s_w, s_h, mir_data->pixel_format,
+ mir_buffer_usage_software);
+
+ conf = MIR_mir_cursor_configuration_from_buffer_stream(stream, hot_x, hot_y);
+
+ CopySurfacePixelsToMirStream(surface, stream);
+ MIR_mir_buffer_stream_swap_buffers_sync(stream);
+
+ mir_cursor->conf = conf;
+ mir_cursor->stream = stream;
+
+ return cursor;
+}
+
+static SDL_Cursor*
+MIR_CreateSystemCursor(SDL_SystemCursor id)
+{
+ char const* cursor_name = NULL;
+ SDL_Cursor* cursor;
+ MIR_Cursor* mir_cursor;
+
+ switch(id) {
+ case SDL_SYSTEM_CURSOR_ARROW:
+ cursor_name = MIR_mir_arrow_cursor_name;
+ break;
+ case SDL_SYSTEM_CURSOR_IBEAM:
+ cursor_name = MIR_mir_caret_cursor_name;
+ break;
+ case SDL_SYSTEM_CURSOR_WAIT:
+ cursor_name = MIR_mir_busy_cursor_name;
+ break;
+ case SDL_SYSTEM_CURSOR_CROSSHAIR:
+ /* Unsupported */
+ cursor_name = MIR_mir_arrow_cursor_name;
+ break;
+ case SDL_SYSTEM_CURSOR_WAITARROW:
+ cursor_name = MIR_mir_busy_cursor_name;
+ break;
+ case SDL_SYSTEM_CURSOR_SIZENWSE:
+ cursor_name = MIR_mir_omnidirectional_resize_cursor_name;
+ break;
+ case SDL_SYSTEM_CURSOR_SIZENESW:
+ cursor_name = MIR_mir_omnidirectional_resize_cursor_name;
+ break;
+ case SDL_SYSTEM_CURSOR_SIZEWE:
+ cursor_name = MIR_mir_horizontal_resize_cursor_name;
+ break;
+ case SDL_SYSTEM_CURSOR_SIZENS:
+ cursor_name = MIR_mir_vertical_resize_cursor_name;
+ break;
+ case SDL_SYSTEM_CURSOR_SIZEALL:
+ cursor_name = MIR_mir_omnidirectional_resize_cursor_name;
+ break;
+ case SDL_SYSTEM_CURSOR_NO:
+ /* Unsupported */
+ cursor_name = MIR_mir_closed_hand_cursor_name;
+ break;
+ case SDL_SYSTEM_CURSOR_HAND:
+ cursor_name = MIR_mir_open_hand_cursor_name;
+ break;
+ default:
+ SDL_assert(0);
+ return NULL;
+ }
+
+ cursor = MIR_CreateDefaultCursor();
+ if (!cursor) {
+ return NULL;
+ }
+
+ mir_cursor = (MIR_Cursor*)cursor->driverdata;
+ mir_cursor->name = cursor_name;
+
+ return cursor;
+}
+
+static void
+MIR_FreeCursor(SDL_Cursor* cursor)
+{
+ if (cursor) {
+
+ if (cursor->driverdata) {
+ MIR_Cursor* mir_cursor = (MIR_Cursor*)cursor->driverdata;
+
+ if (mir_cursor->conf)
+ MIR_mir_cursor_configuration_destroy(mir_cursor->conf);
+ if (mir_cursor->stream)
+ MIR_mir_buffer_stream_release_sync(mir_cursor->stream);
+
+ SDL_free(mir_cursor);
+ }
+
+ SDL_free(cursor);
+ }
+}
+
+static int
+MIR_ShowCursor(SDL_Cursor* cursor)
+{
+ MIR_Data* mir_data = (MIR_Data*)SDL_GetVideoDevice()->driverdata;
+ MIR_Window* mir_window = mir_data->current_window;
+
+ if (cursor && cursor->driverdata) {
+ if (mir_window && MIR_mir_window_is_valid(mir_window->window)) {
+ MIR_Cursor* mir_cursor = (MIR_Cursor*)cursor->driverdata;
+
+ if (mir_cursor->name != NULL) {
+ MirWindowSpec* spec = MIR_mir_create_window_spec(mir_data->connection);
+ MIR_mir_window_spec_set_cursor_name(spec, mir_cursor->name);
+ MIR_mir_window_apply_spec(mir_window->window, spec);
+ MIR_mir_window_spec_release(spec);
+ }
+
+ if (mir_cursor->conf) {
+ MIR_mir_window_configure_cursor(mir_window->window, mir_cursor->conf);
+ }
+ }
+ }
+ else if(mir_window && MIR_mir_window_is_valid(mir_window->window)) {
+ MIR_mir_window_configure_cursor(mir_window->window, NULL);
+ }
+
+ return 0;
+}
+
+static void
+MIR_WarpMouse(SDL_Window* window, int x, int y)
+{
+ SDL_Unsupported();
+}
+
+static int
+MIR_WarpMouseGlobal(int x, int y)
+{
+ return SDL_Unsupported();
+}
+
+static int
+MIR_SetRelativeMouseMode(SDL_bool enabled)
+{
+ return 0;
+}
+
+/* TODO Actually implement the cursor, need to wait for mir support */
+void
+MIR_InitMouse()
+{
+ SDL_Mouse* mouse = SDL_GetMouse();
+
+ mouse->CreateCursor = MIR_CreateCursor;
+ mouse->ShowCursor = MIR_ShowCursor;
+ mouse->FreeCursor = MIR_FreeCursor;
+ mouse->WarpMouse = MIR_WarpMouse;
+ mouse->WarpMouseGlobal = MIR_WarpMouseGlobal;
+ mouse->CreateSystemCursor = MIR_CreateSystemCursor;
+ mouse->SetRelativeMouseMode = MIR_SetRelativeMouseMode;
+
+ SDL_SetDefaultCursor(MIR_CreateDefaultCursor());
+}
+
+void
+MIR_FiniMouse()
+{
+}
+
+#endif /* SDL_VIDEO_DRIVER_MIR */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/video/mir/SDL_mirmouse.h b/src/3rdparty/SDL2/src/video/mir/SDL_mirmouse.h
new file mode 100644
index 0000000..de32610
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/mir/SDL_mirmouse.h
@@ -0,0 +1,37 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
+*/
+
+#ifndef SDL_mirmouse_h_
+#define SDL_mirmouse_h_
+
+extern void
+MIR_InitMouse();
+
+extern void
+MIR_FiniMouse();
+
+#endif /* SDL_mirmouse_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/mir/SDL_miropengl.c b/src/3rdparty/SDL2/src/video/mir/SDL_miropengl.c
new file mode 100644
index 0000000..7795f97
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/mir/SDL_miropengl.c
@@ -0,0 +1,78 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_MIR
+
+#include "SDL_miropengl.h"
+
+#include "SDL_mirdyn.h"
+
+int
+MIR_GL_SwapWindow(_THIS, SDL_Window* window)
+{
+ MIR_Window* mir_wind = window->driverdata;
+
+ return SDL_EGL_SwapBuffers(_this, mir_wind->egl_surface);
+}
+
+int
+MIR_GL_MakeCurrent(_THIS, SDL_Window* window, SDL_GLContext context)
+{
+ if (window) {
+ EGLSurface egl_surface = ((MIR_Window*)window->driverdata)->egl_surface;
+ return SDL_EGL_MakeCurrent(_this, egl_surface, context);
+ }
+
+ return SDL_EGL_MakeCurrent(_this, NULL, NULL);
+}
+
+SDL_GLContext
+MIR_GL_CreateContext(_THIS, SDL_Window* window)
+{
+ MIR_Window* mir_window = window->driverdata;
+
+ SDL_GLContext context;
+ context = SDL_EGL_CreateContext(_this, mir_window->egl_surface);
+
+ return context;
+}
+
+int
+MIR_GL_LoadLibrary(_THIS, const char* path)
+{
+ MIR_Data* mir_data = _this->driverdata;
+
+ SDL_EGL_LoadLibrary(_this, path, MIR_mir_connection_get_egl_native_display(mir_data->connection), 0);
+
+ SDL_EGL_ChooseConfig(_this);
+
+ return 0;
+}
+
+#endif /* SDL_VIDEO_DRIVER_MIR */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/mir/SDL_miropengl.h b/src/3rdparty/SDL2/src/video/mir/SDL_miropengl.h
new file mode 100644
index 0000000..2168f96
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/mir/SDL_miropengl.h
@@ -0,0 +1,53 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
+*/
+
+#ifndef SDL_miropengl_h_
+#define SDL_miropengl_h_
+
+#include "SDL_mirwindow.h"
+
+#include "../SDL_egl_c.h"
+
+#define MIR_GL_DeleteContext SDL_EGL_DeleteContext
+#define MIR_GL_GetSwapInterval SDL_EGL_GetSwapInterval
+#define MIR_GL_SetSwapInterval SDL_EGL_SetSwapInterval
+#define MIR_GL_UnloadLibrary SDL_EGL_UnloadLibrary
+#define MIR_GL_GetProcAddress SDL_EGL_GetProcAddress
+
+extern int
+MIR_GL_SwapWindow(_THIS, SDL_Window* window);
+
+extern int
+MIR_GL_MakeCurrent(_THIS, SDL_Window* window, SDL_GLContext context);
+
+extern SDL_GLContext
+MIR_GL_CreateContext(_THIS, SDL_Window* window);
+
+extern int
+MIR_GL_LoadLibrary(_THIS, const char* path);
+
+#endif /* SDL_miropengl_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/mir/SDL_mirsym.h b/src/3rdparty/SDL2/src/video/mir/SDL_mirsym.h
new file mode 100644
index 0000000..6e18b53
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/mir/SDL_mirsym.h
@@ -0,0 +1,143 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/* *INDENT-OFF* */
+
+#ifndef SDL_MIR_MODULE
+#define SDL_MIR_MODULE(modname)
+#endif
+
+#ifndef SDL_MIR_SYM
+#define SDL_MIR_SYM(rc,fn,params)
+#endif
+
+#ifndef SDL_MIR_SYM_CONST
+#define SDL_MIR_SYM_CONST(type, name)
+#endif
+
+SDL_MIR_MODULE(MIR_CLIENT)
+SDL_MIR_SYM(MirWindow *,mir_create_window_sync,(MirWindowSpec* spec))
+SDL_MIR_SYM(MirEGLNativeWindowType,mir_buffer_stream_get_egl_native_window,(MirBufferStream *surface))
+SDL_MIR_SYM(bool,mir_buffer_stream_get_graphics_region,(MirBufferStream *stream, MirGraphicsRegion *graphics_region))
+SDL_MIR_SYM(void,mir_buffer_stream_swap_buffers_sync,(MirBufferStream *stream))
+SDL_MIR_SYM(void,mir_window_set_event_handler,(MirWindow* window, MirWindowEventCallback callback, void* context))
+SDL_MIR_SYM(MirWindowSpec*,mir_create_normal_window_spec,(MirConnection *connection, int width, int height))
+SDL_MIR_SYM(MirWindowSpec*,mir_create_window_spec,(MirConnection *connection))
+SDL_MIR_SYM(void,mir_window_spec_set_buffer_usage,(MirWindowSpec *spec, MirBufferUsage usage))
+SDL_MIR_SYM(void,mir_window_spec_set_name,(MirWindowSpec *spec, char const *name))
+SDL_MIR_SYM(void,mir_window_spec_release,(MirWindowSpec *spec))
+SDL_MIR_SYM(void,mir_window_spec_set_width,(MirWindowSpec *spec, unsigned width))
+SDL_MIR_SYM(void,mir_window_spec_set_height,(MirWindowSpec *spec, unsigned height))
+SDL_MIR_SYM(void,mir_window_spec_set_min_width,(MirWindowSpec *spec, unsigned min_width))
+SDL_MIR_SYM(void,mir_window_spec_set_min_height,(MirWindowSpec *spec, unsigned min_height))
+SDL_MIR_SYM(void,mir_window_spec_set_max_width,(MirWindowSpec *spec, unsigned max_width))
+SDL_MIR_SYM(void,mir_window_spec_set_max_height,(MirWindowSpec *spec, unsigned max_height))
+SDL_MIR_SYM(void,mir_window_spec_set_type,(MirWindowSpec *spec, MirWindowType type))
+SDL_MIR_SYM(void,mir_window_spec_set_state,(MirWindowSpec *spec, MirWindowState state))
+SDL_MIR_SYM(void,mir_window_spec_set_pointer_confinement,(MirWindowSpec *spec, MirPointerConfinementState state))
+SDL_MIR_SYM(void,mir_window_spec_set_pixel_format,(MirWindowSpec *spec, MirPixelFormat pixel_format))
+SDL_MIR_SYM(void,mir_window_spec_set_cursor_name,(MirWindowSpec *spec, char const* cursor_name))
+SDL_MIR_SYM(void,mir_window_apply_spec,(MirWindow* window, MirWindowSpec* spec))
+SDL_MIR_SYM(void,mir_window_get_parameters,(MirWindow *window, MirWindowParameters *params))
+SDL_MIR_SYM(MirBufferStream*,mir_window_get_buffer_stream,(MirWindow* window))
+SDL_MIR_SYM(MirCursorConfiguration*,mir_cursor_configuration_from_buffer_stream,(MirBufferStream const* stream, int hot_x, int hot_y))
+SDL_MIR_SYM(MirBufferStream*,mir_connection_create_buffer_stream_sync,(MirConnection *connection, int w, int h, MirPixelFormat format, MirBufferUsage usage))
+SDL_MIR_SYM(MirKeyboardAction,mir_keyboard_event_action,(MirKeyboardEvent const *event))
+SDL_MIR_SYM(xkb_keysym_t,mir_keyboard_event_key_code,(MirKeyboardEvent const *event))
+SDL_MIR_SYM(int,mir_keyboard_event_scan_code,(MirKeyboardEvent const *event))
+SDL_MIR_SYM(bool,mir_pointer_event_button_state,(MirPointerEvent const *event, MirPointerButton button))
+SDL_MIR_SYM(MirPointerButtons,mir_pointer_event_buttons,(MirPointerEvent const *event))
+SDL_MIR_SYM(MirInputDeviceId,mir_input_event_get_device_id,(MirInputEvent const* ev))
+SDL_MIR_SYM(MirTouchId,mir_touch_event_id,(MirTouchEvent const *event, size_t touch_index))
+SDL_MIR_SYM(float,mir_touch_event_axis_value,(MirTouchEvent const *event, size_t touch_index, MirTouchAxis axis))
+SDL_MIR_SYM(MirTouchAction,mir_touch_event_action,(MirTouchEvent const *event, size_t touch_index))
+SDL_MIR_SYM(MirPointerAction,mir_pointer_event_action,(MirPointerEvent const *event))
+SDL_MIR_SYM(float,mir_pointer_event_axis_value,(MirPointerEvent const *event, MirPointerAxis))
+SDL_MIR_SYM(MirEventType,mir_event_get_type,(MirEvent const *event))
+SDL_MIR_SYM(MirInputEventType,mir_input_event_get_type,(MirInputEvent const *event))
+SDL_MIR_SYM(MirInputEvent const*,mir_event_get_input_event,(MirEvent const *event))
+SDL_MIR_SYM(MirResizeEvent const*,mir_event_get_resize_event,(MirEvent const *event))
+SDL_MIR_SYM(MirKeyboardEvent const*,mir_input_event_get_keyboard_event,(MirInputEvent const *event))
+SDL_MIR_SYM(MirPointerEvent const*,mir_input_event_get_pointer_event,(MirInputEvent const *event))
+SDL_MIR_SYM(MirTouchEvent const*,mir_input_event_get_touch_event,(MirInputEvent const *event))
+SDL_MIR_SYM(MirWindowEvent const*,mir_event_get_window_event,(MirEvent const *event))
+SDL_MIR_SYM(unsigned int,mir_touch_event_point_count,(MirTouchEvent const *event))
+SDL_MIR_SYM(void,mir_connection_get_available_surface_formats,(MirConnection* connection, MirPixelFormat* formats, unsigned const int format_size, unsigned int *num_valid_formats))
+SDL_MIR_SYM(MirEGLNativeDisplayType,mir_connection_get_egl_native_display,(MirConnection *connection))
+SDL_MIR_SYM(bool,mir_connection_is_valid,(MirConnection *connection))
+SDL_MIR_SYM(void,mir_connection_release,(MirConnection *connection))
+SDL_MIR_SYM(MirPixelFormat,mir_connection_get_egl_pixel_format,(MirConnection* connection, void* egldisplay, void* eglconfig))
+SDL_MIR_SYM(MirConnection *,mir_connect_sync,(char const *server, char const *app_name))
+SDL_MIR_SYM(char const *,mir_window_get_error_message,(MirWindow *window))
+SDL_MIR_SYM(bool,mir_window_is_valid,(MirWindow *window))
+SDL_MIR_SYM(void,mir_window_release_sync,(MirWindow* window))
+SDL_MIR_SYM(void,mir_buffer_stream_release_sync,(MirBufferStream *stream))
+SDL_MIR_SYM(void,mir_window_configure_cursor,(MirWindow* window, MirCursorConfiguration const* conf))
+SDL_MIR_SYM(void,mir_cursor_configuration_destroy,(MirCursorConfiguration* conf))
+SDL_MIR_SYM(int,mir_resize_event_get_width,(MirResizeEvent const* resize_event))
+SDL_MIR_SYM(int,mir_resize_event_get_height,(MirResizeEvent const* resize_event))
+SDL_MIR_SYM(char const*,mir_connection_get_error_message,(MirConnection* connection))
+SDL_MIR_SYM(MirWindowAttrib,mir_window_event_get_attribute,(MirWindowEvent const* event))
+SDL_MIR_SYM(int,mir_window_event_get_attribute_value,(MirWindowEvent const* window_event))
+SDL_MIR_SYM(MirDisplayConfig*,mir_connection_create_display_configuration,(MirConnection* connection))
+SDL_MIR_SYM(void,mir_display_config_release,(MirDisplayConfig* config))
+SDL_MIR_SYM(int,mir_display_config_get_num_outputs,(MirDisplayConfig const* config))
+SDL_MIR_SYM(MirOutput*,mir_display_config_get_mutable_output,(MirDisplayConfig* config, size_t index))
+SDL_MIR_SYM(int,mir_output_get_num_modes,(MirOutput const* output))
+SDL_MIR_SYM(MirOutputMode const*,mir_output_get_current_mode,(MirOutput const* output))
+SDL_MIR_SYM(MirPixelFormat,mir_output_get_current_pixel_format,(MirOutput const* output))
+SDL_MIR_SYM(int,mir_output_get_position_x,(MirOutput const* output))
+SDL_MIR_SYM(int,mir_output_get_position_y,(MirOutput const* output))
+SDL_MIR_SYM(bool,mir_output_is_enabled,(MirOutput const* output))
+SDL_MIR_SYM(MirOutputConnectionState,mir_output_get_connection_state,(MirOutput const* output))
+SDL_MIR_SYM(size_t,mir_output_get_preferred_mode_index,(MirOutput const* output))
+SDL_MIR_SYM(MirOutputType,mir_output_get_type,(MirOutput const* output))
+SDL_MIR_SYM(char const*,mir_output_type_name,(MirOutputType type))
+SDL_MIR_SYM(void,mir_output_set_current_mode,(MirOutput* output, MirOutputMode const* mode))
+SDL_MIR_SYM(MirOutputMode const*,mir_output_get_mode,(MirOutput const* output, size_t index))
+SDL_MIR_SYM(int,mir_output_mode_get_width,(MirOutputMode const* mode))
+SDL_MIR_SYM(int,mir_output_mode_get_height,(MirOutputMode const* mode))
+SDL_MIR_SYM(double,mir_output_mode_get_refresh_rate,(MirOutputMode const* mode))
+SDL_MIR_SYM(bool,mir_output_is_gamma_supported,(MirOutput const* output))
+SDL_MIR_SYM(uint32_t,mir_output_get_gamma_size,(MirOutput const* output))
+SDL_MIR_SYM(void,mir_output_get_gamma,(MirOutput const* output, uint16_t* red, uint16_t* green, uint16_t* blue, uint32_t size))
+SDL_MIR_SYM(void,mir_output_set_gamma,(MirOutput* output, uint16_t const* red, uint16_t const* green, uint16_t const* blue, uint32_t size))
+
+SDL_MIR_SYM_CONST(char const*,mir_omnidirectional_resize_cursor_name)
+SDL_MIR_SYM_CONST(char const*,mir_busy_cursor_name)
+SDL_MIR_SYM_CONST(char const*,mir_arrow_cursor_name)
+SDL_MIR_SYM_CONST(char const*,mir_caret_cursor_name)
+SDL_MIR_SYM_CONST(char const*,mir_vertical_resize_cursor_name)
+SDL_MIR_SYM_CONST(char const*,mir_horizontal_resize_cursor_name)
+SDL_MIR_SYM_CONST(char const*,mir_open_hand_cursor_name)
+SDL_MIR_SYM_CONST(char const*,mir_closed_hand_cursor_name)
+SDL_MIR_SYM_CONST(char const*,mir_disabled_cursor_name)
+
+SDL_MIR_MODULE(XKBCOMMON)
+SDL_MIR_SYM(int,xkb_keysym_to_utf8,(xkb_keysym_t keysym, char *buffer, size_t size))
+
+#undef SDL_MIR_MODULE
+#undef SDL_MIR_SYM
+#undef SDL_MIR_SYM_CONST
+
+/* *INDENT-ON* */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/mir/SDL_mirvideo.c b/src/3rdparty/SDL2/src/video/mir/SDL_mirvideo.c
new file mode 100644
index 0000000..8f3a368
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/mir/SDL_mirvideo.c
@@ -0,0 +1,423 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_MIR
+
+#include "SDL_assert.h"
+#include "SDL_log.h"
+
+#include "SDL_mirwindow.h"
+#include "SDL_video.h"
+
+#include "SDL_mirframebuffer.h"
+#include "SDL_mirmouse.h"
+#include "SDL_miropengl.h"
+#include "SDL_mirvideo.h"
+#include "SDL_mirvulkan.h"
+
+#include "SDL_mirdyn.h"
+
+#define MIR_DRIVER_NAME "mir"
+
+static const Uint32 mir_pixel_format_to_sdl_format[] = {
+ SDL_PIXELFORMAT_UNKNOWN, /* mir_pixel_format_invalid */
+ SDL_PIXELFORMAT_ABGR8888, /* mir_pixel_format_abgr_8888 */
+ SDL_PIXELFORMAT_BGR888, /* mir_pixel_format_xbgr_8888 */
+ SDL_PIXELFORMAT_ARGB8888, /* mir_pixel_format_argb_8888 */
+ SDL_PIXELFORMAT_RGB888, /* mir_pixel_format_xrgb_8888 */
+ SDL_PIXELFORMAT_BGR24, /* mir_pixel_format_bgr_888 */
+ SDL_PIXELFORMAT_RGB24, /* mir_pixel_format_rgb_888 */
+ SDL_PIXELFORMAT_RGB565, /* mir_pixel_format_rgb_565 */
+ SDL_PIXELFORMAT_RGBA5551, /* mir_pixel_format_rgba_5551 */
+ SDL_PIXELFORMAT_RGBA4444 /* mir_pixel_format_rgba_4444 */
+};
+
+Uint32
+MIR_GetSDLPixelFormat(MirPixelFormat format)
+{
+ return mir_pixel_format_to_sdl_format[format];
+}
+
+static int
+MIR_VideoInit(_THIS);
+
+static void
+MIR_VideoQuit(_THIS);
+
+static int
+MIR_GetDisplayBounds(_THIS, SDL_VideoDisplay* display, SDL_Rect* rect);
+
+static void
+MIR_GetDisplayModes(_THIS, SDL_VideoDisplay* sdl_display);
+
+static int
+MIR_SetDisplayMode(_THIS, SDL_VideoDisplay* sdl_display, SDL_DisplayMode* mode);
+
+static SDL_WindowShaper*
+MIR_CreateShaper(SDL_Window* window)
+{
+ /* FIXME Im not sure if mir support this atm, will have to come back to this */
+ return NULL;
+}
+
+static int
+MIR_SetWindowShape(SDL_WindowShaper* shaper, SDL_Surface* shape, SDL_WindowShapeMode* shape_mode)
+{
+ return SDL_Unsupported();
+}
+
+static int
+MIR_ResizeWindowShape(SDL_Window* window)
+{
+ return SDL_Unsupported();
+}
+
+static int
+MIR_Available()
+{
+ int available = 0;
+
+ if (SDL_MIR_LoadSymbols()) {
+
+ /* Lets ensure we can connect to the mir server */
+ MirConnection* connection = MIR_mir_connect_sync(NULL, SDL_FUNCTION);
+
+ if (!MIR_mir_connection_is_valid(connection)) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "Unable to connect to the mir server %s",
+ MIR_mir_connection_get_error_message(connection));
+
+ return available;
+ }
+
+ MIR_mir_connection_release(connection);
+
+ available = 1;
+ SDL_MIR_UnloadSymbols();
+ }
+
+ return available;
+}
+
+static void
+MIR_DeleteDevice(SDL_VideoDevice* device)
+{
+ SDL_free(device);
+ SDL_MIR_UnloadSymbols();
+}
+
+static void
+MIR_PumpEvents(_THIS)
+{
+}
+
+static SDL_VideoDevice*
+MIR_CreateDevice(int device_index)
+{
+ MIR_Data* mir_data;
+ SDL_VideoDevice* device = NULL;
+
+ if (!SDL_MIR_LoadSymbols()) {
+ return NULL;
+ }
+
+ device = SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (!device) {
+ SDL_MIR_UnloadSymbols();
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ mir_data = SDL_calloc(1, sizeof(MIR_Data));
+ if (!mir_data) {
+ SDL_free(device);
+ SDL_MIR_UnloadSymbols();
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ device->driverdata = mir_data;
+
+ /* mirvideo */
+ device->VideoInit = MIR_VideoInit;
+ device->VideoQuit = MIR_VideoQuit;
+ device->GetDisplayBounds = MIR_GetDisplayBounds;
+ device->GetDisplayModes = MIR_GetDisplayModes;
+ device->SetDisplayMode = MIR_SetDisplayMode;
+ device->free = MIR_DeleteDevice;
+
+ /* miropengles */
+ device->GL_SwapWindow = MIR_GL_SwapWindow;
+ device->GL_MakeCurrent = MIR_GL_MakeCurrent;
+ device->GL_CreateContext = MIR_GL_CreateContext;
+ device->GL_DeleteContext = MIR_GL_DeleteContext;
+ device->GL_LoadLibrary = MIR_GL_LoadLibrary;
+ device->GL_UnloadLibrary = MIR_GL_UnloadLibrary;
+ device->GL_GetSwapInterval = MIR_GL_GetSwapInterval;
+ device->GL_SetSwapInterval = MIR_GL_SetSwapInterval;
+ device->GL_GetProcAddress = MIR_GL_GetProcAddress;
+
+ /* mirwindow */
+ device->CreateSDLWindow = MIR_CreateWindow;
+ device->DestroyWindow = MIR_DestroyWindow;
+ device->GetWindowWMInfo = MIR_GetWindowWMInfo;
+ device->SetWindowFullscreen = MIR_SetWindowFullscreen;
+ device->MaximizeWindow = MIR_MaximizeWindow;
+ device->MinimizeWindow = MIR_MinimizeWindow;
+ device->RestoreWindow = MIR_RestoreWindow;
+ device->ShowWindow = MIR_RestoreWindow;
+ device->HideWindow = MIR_HideWindow;
+ device->SetWindowSize = MIR_SetWindowSize;
+ device->SetWindowMinimumSize = MIR_SetWindowMinimumSize;
+ device->SetWindowMaximumSize = MIR_SetWindowMaximumSize;
+ device->SetWindowTitle = MIR_SetWindowTitle;
+ device->SetWindowGrab = MIR_SetWindowGrab;
+ device->SetWindowGammaRamp = MIR_SetWindowGammaRamp;
+ device->GetWindowGammaRamp = MIR_GetWindowGammaRamp;
+
+ device->CreateSDLWindowFrom = NULL;
+ device->SetWindowIcon = NULL;
+ device->RaiseWindow = NULL;
+ device->SetWindowBordered = NULL;
+ device->SetWindowResizable = NULL;
+ device->OnWindowEnter = NULL;
+ device->SetWindowPosition = NULL;
+
+ /* mirframebuffer */
+ device->CreateWindowFramebuffer = MIR_CreateWindowFramebuffer;
+ device->UpdateWindowFramebuffer = MIR_UpdateWindowFramebuffer;
+ device->DestroyWindowFramebuffer = MIR_DestroyWindowFramebuffer;
+
+ device->shape_driver.CreateShaper = MIR_CreateShaper;
+ device->shape_driver.SetWindowShape = MIR_SetWindowShape;
+ device->shape_driver.ResizeWindowShape = MIR_ResizeWindowShape;
+
+ device->PumpEvents = MIR_PumpEvents;
+
+ device->SuspendScreenSaver = NULL;
+
+ device->StartTextInput = NULL;
+ device->StopTextInput = NULL;
+ device->SetTextInputRect = NULL;
+
+ device->HasScreenKeyboardSupport = NULL;
+ device->ShowScreenKeyboard = NULL;
+ device->HideScreenKeyboard = NULL;
+ device->IsScreenKeyboardShown = NULL;
+
+ device->SetClipboardText = NULL;
+ device->GetClipboardText = NULL;
+ device->HasClipboardText = NULL;
+
+ device->ShowMessageBox = NULL;
+
+#if SDL_VIDEO_VULKAN
+ device->Vulkan_LoadLibrary = MIR_Vulkan_LoadLibrary;
+ device->Vulkan_UnloadLibrary = MIR_Vulkan_UnloadLibrary;
+ device->Vulkan_GetInstanceExtensions = MIR_Vulkan_GetInstanceExtensions;
+ device->Vulkan_CreateSurface = MIR_Vulkan_CreateSurface;
+#endif
+
+ return device;
+}
+
+VideoBootStrap MIR_bootstrap = {
+ MIR_DRIVER_NAME, "SDL Mir video driver",
+ MIR_Available, MIR_CreateDevice
+};
+
+static SDL_DisplayMode
+MIR_ConvertModeToSDLMode(MirOutputMode const* mode, MirPixelFormat format)
+{
+ SDL_DisplayMode sdl_mode = {
+ .format = MIR_GetSDLPixelFormat(format),
+ .w = MIR_mir_output_mode_get_width(mode),
+ .h = MIR_mir_output_mode_get_height(mode),
+ .refresh_rate = MIR_mir_output_mode_get_refresh_rate(mode),
+ .driverdata = NULL
+ };
+
+ return sdl_mode;
+}
+
+static void
+MIR_AddModeToDisplay(SDL_VideoDisplay* display, MirOutputMode const* mode, MirPixelFormat format)
+{
+ SDL_DisplayMode sdl_mode = MIR_ConvertModeToSDLMode(mode, format);
+ SDL_AddDisplayMode(display, &sdl_mode);
+}
+
+static void
+MIR_InitDisplayFromOutput(_THIS, MirOutput* output)
+{
+ SDL_VideoDisplay display;
+ int m;
+
+ MirPixelFormat format = MIR_mir_output_get_current_pixel_format(output);
+ int num_modes = MIR_mir_output_get_num_modes(output);
+ SDL_DisplayMode current_mode = MIR_ConvertModeToSDLMode(MIR_mir_output_get_current_mode(output), format);
+
+ SDL_zero(display);
+
+ // Unfortunate cast, but SDL_AddVideoDisplay will strdup this pointer so its read-only in this case.
+ display.name = (char*)MIR_mir_output_type_name(MIR_mir_output_get_type(output));
+
+ for (m = 0; m < num_modes; m++) {
+ MirOutputMode const* mode = MIR_mir_output_get_mode(output, m);
+ MIR_AddModeToDisplay(&display, mode, format);
+ }
+
+ display.desktop_mode = current_mode;
+ display.current_mode = current_mode;
+
+ display.driverdata = output;
+ SDL_AddVideoDisplay(&display);
+}
+
+static void
+MIR_InitDisplays(_THIS)
+{
+ MIR_Data* mir_data = _this->driverdata;
+ int num_outputs = MIR_mir_display_config_get_num_outputs(mir_data->display_config);
+ int d;
+
+ for (d = 0; d < num_outputs; d++) {
+ MirOutput* output = MIR_mir_display_config_get_mutable_output(mir_data->display_config, d);
+ SDL_bool enabled = MIR_mir_output_is_enabled(output);
+ MirOutputConnectionState state = MIR_mir_output_get_connection_state(output);
+
+ if (enabled && state == mir_output_connection_state_connected) {
+ MIR_InitDisplayFromOutput(_this, output);
+ }
+ }
+}
+
+static int
+MIR_VideoInit(_THIS)
+{
+ MIR_Data* mir_data = _this->driverdata;
+
+ mir_data->connection = MIR_mir_connect_sync(NULL, SDL_FUNCTION);
+ mir_data->current_window = NULL;
+ mir_data->software = SDL_FALSE;
+ mir_data->pixel_format = mir_pixel_format_invalid;
+
+ if (!MIR_mir_connection_is_valid(mir_data->connection)) {
+ return SDL_SetError("Failed to connect to the mir server: %s",
+ MIR_mir_connection_get_error_message(mir_data->connection));
+ }
+
+ mir_data->display_config = MIR_mir_connection_create_display_configuration(mir_data->connection);
+
+ MIR_InitDisplays(_this);
+ MIR_InitMouse();
+
+ return 0;
+}
+
+static void
+MIR_CleanUpDisplayConfig(_THIS)
+{
+ MIR_Data* mir_data = _this->driverdata;
+ int i;
+
+ // SDL_VideoQuit frees the display driverdata, we own it not them
+ for (i = 0; i < _this->num_displays; ++i) {
+ _this->displays[i].driverdata = NULL;
+ }
+
+ MIR_mir_display_config_release(mir_data->display_config);
+}
+
+static void
+MIR_VideoQuit(_THIS)
+{
+ MIR_Data* mir_data = _this->driverdata;
+
+ MIR_CleanUpDisplayConfig(_this);
+
+ MIR_FiniMouse();
+
+ MIR_GL_DeleteContext(_this, NULL);
+ MIR_GL_UnloadLibrary(_this);
+
+ MIR_mir_connection_release(mir_data->connection);
+
+ SDL_free(mir_data);
+ _this->driverdata = NULL;
+}
+
+static int
+MIR_GetDisplayBounds(_THIS, SDL_VideoDisplay* display, SDL_Rect* rect)
+{
+ MirOutput const* output = display->driverdata;
+
+ rect->x = MIR_mir_output_get_position_x(output);
+ rect->y = MIR_mir_output_get_position_y(output);
+ rect->w = display->current_mode.w;
+ rect->h = display->current_mode.h;
+
+ return 0;
+}
+
+static void
+MIR_GetDisplayModes(_THIS, SDL_VideoDisplay* display)
+{
+}
+
+static int
+MIR_SetDisplayMode(_THIS, SDL_VideoDisplay* display, SDL_DisplayMode* mode)
+{
+ int m;
+ MirOutput* output = display->driverdata;
+ int num_modes = MIR_mir_output_get_num_modes(output);
+ Uint32 sdl_format = MIR_GetSDLPixelFormat(
+ MIR_mir_output_get_current_pixel_format(output));
+
+ for (m = 0; m < num_modes; m++) {
+ MirOutputMode const* mir_mode = MIR_mir_output_get_mode(output, m);
+ int width = MIR_mir_output_mode_get_width(mir_mode);
+ int height = MIR_mir_output_mode_get_height(mir_mode);
+ double refresh_rate = MIR_mir_output_mode_get_refresh_rate(mir_mode);
+
+ if (mode->format == sdl_format &&
+ mode->w == width &&
+ mode->h == height &&
+ mode->refresh_rate == refresh_rate) {
+
+ // FIXME Currently wont actually *set* anything. Need to wait for applying display changes
+ MIR_mir_output_set_current_mode(output, mir_mode);
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+#endif /* SDL_VIDEO_DRIVER_MIR */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/video/mir/SDL_mirvideo.h b/src/3rdparty/SDL2/src/video/mir/SDL_mirvideo.h
new file mode 100644
index 0000000..6850bac
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/mir/SDL_mirvideo.h
@@ -0,0 +1,49 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
+*/
+
+#ifndef SDL_mirvideo_h__
+#define SDL_mirvideo_h__
+
+#include <EGL/egl.h>
+#include <mir_toolkit/mir_client_library.h>
+#include "SDL_stdinc.h"
+
+typedef struct MIR_Window MIR_Window;
+
+typedef struct
+{
+ MirConnection* connection;
+ MirDisplayConfig* display_config;
+ MIR_Window* current_window;
+ SDL_bool software;
+ MirPixelFormat pixel_format;
+} MIR_Data;
+
+extern Uint32
+MIR_GetSDLPixelFormat(MirPixelFormat format);
+
+#endif /* SDL_mirvideo_h__ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/mir/SDL_mirvulkan.c b/src/3rdparty/SDL2/src/video/mir/SDL_mirvulkan.c
new file mode 100644
index 0000000..6ba3fa3
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/mir/SDL_mirvulkan.c
@@ -0,0 +1,176 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ * @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's
+ * SDL_x11vulkan.c.
+ */
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_MIR
+
+#include "SDL_mirvideo.h"
+#include "SDL_mirwindow.h"
+#include "SDL_assert.h"
+
+#include "SDL_loadso.h"
+#include "SDL_mirvulkan.h"
+#include "SDL_syswm.h"
+
+int MIR_Vulkan_LoadLibrary(_THIS, const char *path)
+{
+ VkExtensionProperties *extensions = NULL;
+ Uint32 extensionCount = 0;
+ SDL_bool hasSurfaceExtension = SDL_FALSE;
+ SDL_bool hasMIRSurfaceExtension = SDL_FALSE;
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
+ if(_this->vulkan_config.loader_handle)
+ return SDL_SetError("Vulkan already loaded");
+
+ /* Load the Vulkan loader library */
+ if(!path)
+ path = SDL_getenv("SDL_VULKAN_LIBRARY");
+ if(!path)
+ path = "libvulkan.so.1";
+ _this->vulkan_config.loader_handle = SDL_LoadObject(path);
+ if(!_this->vulkan_config.loader_handle)
+ return -1;
+ SDL_strlcpy(_this->vulkan_config.loader_path, path,
+ SDL_arraysize(_this->vulkan_config.loader_path));
+ vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction(
+ _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr");
+ if(!vkGetInstanceProcAddr)
+ goto fail;
+ _this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr;
+ _this->vulkan_config.vkEnumerateInstanceExtensionProperties =
+ (void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)(
+ VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties");
+ if(!_this->vulkan_config.vkEnumerateInstanceExtensionProperties)
+ goto fail;
+ extensions = SDL_Vulkan_CreateInstanceExtensionsList(
+ (PFN_vkEnumerateInstanceExtensionProperties)
+ _this->vulkan_config.vkEnumerateInstanceExtensionProperties,
+ &extensionCount);
+ if(!extensions)
+ goto fail;
+ for(Uint32 i = 0; i < extensionCount; i++)
+ {
+ if(SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
+ hasSurfaceExtension = SDL_TRUE;
+ else if(SDL_strcmp(VK_KHR_MIR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
+ hasMIRSurfaceExtension = SDL_TRUE;
+ }
+ SDL_free(extensions);
+ if(!hasSurfaceExtension)
+ {
+ SDL_SetError("Installed Vulkan doesn't implement the "
+ VK_KHR_SURFACE_EXTENSION_NAME " extension");
+ goto fail;
+ }
+ else if(!hasMIRSurfaceExtension)
+ {
+ SDL_SetError("Installed Vulkan doesn't implement the "
+ VK_KHR_MIR_SURFACE_EXTENSION_NAME "extension");
+ goto fail;
+ }
+ return 0;
+
+fail:
+ SDL_UnloadObject(_this->vulkan_config.loader_handle);
+ _this->vulkan_config.loader_handle = NULL;
+ return -1;
+}
+
+void MIR_Vulkan_UnloadLibrary(_THIS)
+{
+ if(_this->vulkan_config.loader_handle)
+ {
+ SDL_UnloadObject(_this->vulkan_config.loader_handle);
+ _this->vulkan_config.loader_handle = NULL;
+ }
+}
+
+SDL_bool MIR_Vulkan_GetInstanceExtensions(_THIS,
+ SDL_Window *window,
+ unsigned *count,
+ const char **names)
+{
+ static const char *const extensionsForMir[] = {
+ VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_MIR_SURFACE_EXTENSION_NAME
+ };
+ if(!_this->vulkan_config.loader_handle)
+ {
+ SDL_SetError("Vulkan is not loaded");
+ return SDL_FALSE;
+ }
+ return SDL_Vulkan_GetInstanceExtensions_Helper(
+ count, names, SDL_arraysize(extensionsForMir),
+ extensionsForMir);
+}
+
+SDL_bool MIR_Vulkan_CreateSurface(_THIS,
+ SDL_Window *window,
+ VkInstance instance,
+ VkSurfaceKHR *surface)
+{
+ MIR_Window *windowData = (MIR_Window *)window->driverdata;
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
+ (PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr;
+ PFN_vkCreateMirSurfaceKHR vkCreateMirSurfaceKHR =
+ (PFN_vkCreateMirSurfaceKHR)vkGetInstanceProcAddr(
+ (VkInstance)instance,
+ "vkCreateMirSurfaceKHR");
+ VkMirSurfaceCreateInfoKHR createInfo;
+ VkResult result;
+
+ if(!_this->vulkan_config.loader_handle)
+ {
+ SDL_SetError("Vulkan is not loaded");
+ return SDL_FALSE;
+ }
+
+ if(!vkCreateMirSurfaceKHR)
+ {
+ SDL_SetError(VK_KHR_MIR_SURFACE_EXTENSION_NAME
+ " extension is not enabled in the Vulkan instance.");
+ return SDL_FALSE;
+ }
+ SDL_zero(createInfo);
+ createInfo.sType = VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR;
+ createInfo.pNext = NULL;
+ createInfo.flags = 0;
+ createInfo.connection = windowData->mir_data->connection;
+ createInfo.mirSurface = windowData->window;
+ result = vkCreateMirSurfaceKHR(instance, &createInfo,
+ NULL, surface);
+ if(result != VK_SUCCESS)
+ {
+ SDL_SetError("vkCreateMirSurfaceKHR failed: %s",
+ SDL_Vulkan_GetResultString(result));
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
+}
+
+#endif
+
+/* vim: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/mir/SDL_mirvulkan.h b/src/3rdparty/SDL2/src/video/mir/SDL_mirvulkan.h
new file mode 100644
index 0000000..6f40d5b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/mir/SDL_mirvulkan.h
@@ -0,0 +1,52 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ * @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's
+ * SDL_x11vulkan.h.
+ */
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_mirvulkan_h_
+#define SDL_mirvulkan_h_
+
+#include "../SDL_vulkan_internal.h"
+#include "../SDL_sysvideo.h"
+
+#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_MIR
+
+int MIR_Vulkan_LoadLibrary(_THIS, const char *path);
+void MIR_Vulkan_UnloadLibrary(_THIS);
+SDL_bool MIR_Vulkan_GetInstanceExtensions(_THIS,
+ SDL_Window *window,
+ unsigned *count,
+ const char **names);
+SDL_bool MIR_Vulkan_CreateSurface(_THIS,
+ SDL_Window *window,
+ VkInstance instance,
+ VkSurfaceKHR *surface);
+
+#endif
+
+#endif /* SDL_mirvulkan_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/mir/SDL_mirwindow.c b/src/3rdparty/SDL2/src/video/mir/SDL_mirwindow.c
new file mode 100644
index 0000000..80877ee
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/mir/SDL_mirwindow.c
@@ -0,0 +1,374 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_MIR
+
+#include "../SDL_egl_c.h"
+#include "../SDL_sysvideo.h"
+#include "../../events/SDL_keyboard_c.h"
+
+#include "SDL_mirevents.h"
+#include "SDL_mirwindow.h"
+
+#include "SDL_mirdyn.h"
+
+static int
+IsMirWindowValid(MIR_Window* mir_window)
+{
+ if (!MIR_mir_window_is_valid(mir_window->window)) {
+ const char* error = MIR_mir_window_get_error_message(mir_window->window);
+ return SDL_SetError("Failed to create a mir surface: %s", error);
+ }
+
+ return 1;
+}
+
+static MirPixelFormat
+FindValidPixelFormat(MIR_Data* mir_data)
+{
+ unsigned int pf_size = 32;
+ unsigned int valid_formats;
+ unsigned int f;
+
+ MirPixelFormat formats[pf_size];
+ MIR_mir_connection_get_available_surface_formats(mir_data->connection, formats,
+ pf_size, &valid_formats);
+
+ for (f = 0; f < valid_formats; f++) {
+ MirPixelFormat cur_pf = formats[f];
+
+ if (cur_pf == mir_pixel_format_abgr_8888 ||
+ cur_pf == mir_pixel_format_xbgr_8888 ||
+ cur_pf == mir_pixel_format_argb_8888 ||
+ cur_pf == mir_pixel_format_xrgb_8888) {
+
+ return cur_pf;
+ }
+ }
+
+ return mir_pixel_format_invalid;
+}
+
+int
+MIR_CreateWindow(_THIS, SDL_Window* window)
+{
+ MIR_Window* mir_window;
+ MIR_Data* mir_data;
+ MirPixelFormat pixel_format;
+ MirBufferUsage buffer_usage;
+
+ MirWindowSpec* spec;
+
+ mir_window = SDL_calloc(1, sizeof(MIR_Window));
+ if (!mir_window)
+ return SDL_OutOfMemory();
+
+ mir_data = _this->driverdata;
+ window->driverdata = mir_window;
+
+ if (window->x == SDL_WINDOWPOS_UNDEFINED)
+ window->x = 0;
+
+ if (window->y == SDL_WINDOWPOS_UNDEFINED)
+ window->y = 0;
+
+ mir_window->mir_data = mir_data;
+ mir_window->sdl_window = window;
+
+ if (window->flags & SDL_WINDOW_OPENGL) {
+ pixel_format = MIR_mir_connection_get_egl_pixel_format(mir_data->connection,
+ _this->egl_data->egl_display,
+ _this->egl_data->egl_config);
+ }
+ else {
+ pixel_format = FindValidPixelFormat(mir_data);
+ }
+
+ mir_data->pixel_format = pixel_format;
+ if (pixel_format == mir_pixel_format_invalid) {
+ return SDL_SetError("Failed to find a valid pixel format.");
+ }
+
+ buffer_usage = mir_buffer_usage_hardware;
+ if (mir_data->software)
+ buffer_usage = mir_buffer_usage_software;
+
+ spec = MIR_mir_create_normal_window_spec(mir_data->connection,
+ window->w,
+ window->h);
+
+ MIR_mir_window_spec_set_buffer_usage(spec, buffer_usage);
+ MIR_mir_window_spec_set_name(spec, "Mir surface");
+ MIR_mir_window_spec_set_pixel_format(spec, pixel_format);
+
+ if (window->flags & SDL_WINDOW_INPUT_FOCUS)
+ SDL_SetKeyboardFocus(window);
+
+ mir_window->window = MIR_mir_create_window_sync(spec);
+ MIR_mir_window_set_event_handler(mir_window->window, MIR_HandleEvent, window);
+
+ MIR_mir_window_spec_release(spec);
+
+ if (!MIR_mir_window_is_valid(mir_window->window)) {
+ return SDL_SetError("Failed to create a mir surface: %s",
+ MIR_mir_window_get_error_message(mir_window->window));
+ }
+
+ if (window->flags & SDL_WINDOW_OPENGL) {
+ EGLNativeWindowType egl_native_window =
+ (EGLNativeWindowType)MIR_mir_buffer_stream_get_egl_native_window(
+ MIR_mir_window_get_buffer_stream(mir_window->window));
+
+ mir_window->egl_surface = SDL_EGL_CreateSurface(_this, egl_native_window);
+
+ if (mir_window->egl_surface == EGL_NO_SURFACE) {
+ return SDL_SetError("Failed to create a window surface %p",
+ _this->egl_data->egl_display);
+ }
+ }
+ else {
+ mir_window->egl_surface = EGL_NO_SURFACE;
+ }
+
+ mir_data->current_window = mir_window;
+
+ return 0;
+}
+
+void
+MIR_DestroyWindow(_THIS, SDL_Window* window)
+{
+ MIR_Data* mir_data = _this->driverdata;
+ MIR_Window* mir_window = window->driverdata;
+
+ if (mir_data) {
+ SDL_EGL_DestroySurface(_this, mir_window->egl_surface);
+ MIR_mir_window_release_sync(mir_window->window);
+
+ mir_data->current_window = NULL;
+
+ SDL_free(mir_window);
+ }
+ window->driverdata = NULL;
+}
+
+SDL_bool
+MIR_GetWindowWMInfo(_THIS, SDL_Window* window, SDL_SysWMinfo* info)
+{
+ if (info->version.major == SDL_MAJOR_VERSION &&
+ info->version.minor == SDL_MINOR_VERSION) {
+ MIR_Window* mir_window = window->driverdata;
+
+ info->subsystem = SDL_SYSWM_MIR;
+ info->info.mir.connection = mir_window->mir_data->connection;
+ // Cannot change this to window due to it being in the public API
+ info->info.mir.surface = mir_window->window;
+
+ return SDL_TRUE;
+ }
+
+ return SDL_FALSE;
+}
+
+static void
+UpdateMirWindowState(MIR_Data* mir_data, MIR_Window* mir_window, MirWindowState window_state)
+{
+ if (IsMirWindowValid(mir_window)) {
+ MirWindowSpec* spec = MIR_mir_create_window_spec(mir_data->connection);
+ MIR_mir_window_spec_set_state(spec, window_state);
+
+ MIR_mir_window_apply_spec(mir_window->window, spec);
+ MIR_mir_window_spec_release(spec);
+ }
+}
+
+void
+MIR_SetWindowFullscreen(_THIS, SDL_Window* window,
+ SDL_VideoDisplay* display,
+ SDL_bool fullscreen)
+{
+ if (IsMirWindowValid(window->driverdata)) {
+ MirWindowState state;
+
+ if (fullscreen) {
+ state = mir_window_state_fullscreen;
+ }
+ else {
+ state = mir_window_state_restored;
+ }
+
+ UpdateMirWindowState(_this->driverdata, window->driverdata, state);
+ }
+}
+
+void
+MIR_MaximizeWindow(_THIS, SDL_Window* window)
+{
+ UpdateMirWindowState(_this->driverdata, window->driverdata, mir_window_state_maximized);
+}
+
+void
+MIR_MinimizeWindow(_THIS, SDL_Window* window)
+{
+ UpdateMirWindowState(_this->driverdata, window->driverdata, mir_window_state_minimized);
+}
+
+void
+MIR_RestoreWindow(_THIS, SDL_Window * window)
+{
+ UpdateMirWindowState(_this->driverdata, window->driverdata, mir_window_state_restored);
+}
+
+void
+MIR_HideWindow(_THIS, SDL_Window* window)
+{
+ UpdateMirWindowState(_this->driverdata, window->driverdata, mir_window_state_hidden);
+}
+
+void
+MIR_SetWindowSize(_THIS, SDL_Window* window)
+{
+ MIR_Data* mir_data = _this->driverdata;
+ MIR_Window* mir_window = window->driverdata;
+
+ if (IsMirWindowValid(mir_window)) {
+ MirWindowSpec* spec = MIR_mir_create_window_spec(mir_data->connection);
+ MIR_mir_window_spec_set_width (spec, window->w);
+ MIR_mir_window_spec_set_height(spec, window->h);
+
+ MIR_mir_window_apply_spec(mir_window->window, spec);
+ }
+}
+
+void
+MIR_SetWindowMinimumSize(_THIS, SDL_Window* window)
+{
+ MIR_Data* mir_data = _this->driverdata;
+ MIR_Window* mir_window = window->driverdata;
+
+ if (IsMirWindowValid(mir_window)) {
+ MirWindowSpec* spec = MIR_mir_create_window_spec(mir_data->connection);
+ MIR_mir_window_spec_set_min_width (spec, window->min_w);
+ MIR_mir_window_spec_set_min_height(spec, window->min_h);
+
+ MIR_mir_window_apply_spec(mir_window->window, spec);
+ }
+}
+
+void
+MIR_SetWindowMaximumSize(_THIS, SDL_Window* window)
+{
+ MIR_Data* mir_data = _this->driverdata;
+ MIR_Window* mir_window = window->driverdata;
+
+ if (IsMirWindowValid(mir_window)) {
+ MirWindowSpec* spec = MIR_mir_create_window_spec(mir_data->connection);
+ MIR_mir_window_spec_set_max_width (spec, window->max_w);
+ MIR_mir_window_spec_set_max_height(spec, window->max_h);
+
+ MIR_mir_window_apply_spec(mir_window->window, spec);
+ }
+}
+
+void
+MIR_SetWindowTitle(_THIS, SDL_Window* window)
+{
+ MIR_Data* mir_data = _this->driverdata;
+ MIR_Window* mir_window = window->driverdata;
+ char const* title = window->title ? window->title : "";
+ MirWindowSpec* spec;
+
+ if (IsMirWindowValid(mir_window) < 0)
+ return;
+
+ spec = MIR_mir_create_window_spec(mir_data->connection);
+ MIR_mir_window_spec_set_name(spec, title);
+
+ MIR_mir_window_apply_spec(mir_window->window, spec);
+ MIR_mir_window_spec_release(spec);
+}
+
+void
+MIR_SetWindowGrab(_THIS, SDL_Window* window, SDL_bool grabbed)
+{
+ MIR_Data* mir_data = _this->driverdata;
+ MIR_Window* mir_window = window->driverdata;
+ MirPointerConfinementState confined = mir_pointer_unconfined;
+ MirWindowSpec* spec;
+
+ if (grabbed)
+ confined = mir_pointer_confined_to_window;
+
+ spec = MIR_mir_create_window_spec(mir_data->connection);
+ MIR_mir_window_spec_set_pointer_confinement(spec, confined);
+
+ MIR_mir_window_apply_spec(mir_window->window, spec);
+ MIR_mir_window_spec_release(spec);
+}
+
+int
+MIR_SetWindowGammaRamp(_THIS, SDL_Window* window, Uint16 const* ramp)
+{
+ MirOutput* output = SDL_GetDisplayForWindow(window)->driverdata;
+ Uint32 ramp_size = 256;
+
+ // FIXME Need to apply the changes to the output, once that public API function is around
+ if (MIR_mir_output_is_gamma_supported(output) == mir_output_gamma_supported) {
+ MIR_mir_output_set_gamma(output,
+ ramp + ramp_size * 0,
+ ramp + ramp_size * 1,
+ ramp + ramp_size * 2,
+ ramp_size);
+ return 0;
+ }
+
+ return -1;
+}
+
+int
+MIR_GetWindowGammaRamp(_THIS, SDL_Window* window, Uint16* ramp)
+{
+ MirOutput* output = SDL_GetDisplayForWindow(window)->driverdata;
+ Uint32 ramp_size = 256;
+
+ if (MIR_mir_output_is_gamma_supported(output) == mir_output_gamma_supported) {
+ if (MIR_mir_output_get_gamma_size(output) == ramp_size) {
+ MIR_mir_output_get_gamma(output,
+ ramp + ramp_size * 0,
+ ramp + ramp_size * 1,
+ ramp + ramp_size * 2,
+ ramp_size);
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+#endif /* SDL_VIDEO_DRIVER_MIR */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/mir/SDL_mirwindow.h b/src/3rdparty/SDL2/src/video/mir/SDL_mirwindow.h
new file mode 100644
index 0000000..af618f5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/mir/SDL_mirwindow.h
@@ -0,0 +1,93 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
+*/
+
+#ifndef SDL_mirwindow_h_
+#define SDL_mirwindow_h_
+
+#include "../SDL_sysvideo.h"
+#include "SDL_syswm.h"
+
+#include "SDL_mirvideo.h"
+
+struct MIR_Window {
+ SDL_Window* sdl_window;
+ MIR_Data* mir_data;
+
+ MirWindow* window;
+ EGLSurface egl_surface;
+};
+
+
+extern int
+MIR_CreateWindow(_THIS, SDL_Window* window);
+
+extern void
+MIR_DestroyWindow(_THIS, SDL_Window* window);
+
+extern void
+MIR_SetWindowFullscreen(_THIS, SDL_Window* window,
+ SDL_VideoDisplay* display,
+ SDL_bool fullscreen);
+
+extern void
+MIR_MaximizeWindow(_THIS, SDL_Window* window);
+
+extern void
+MIR_MinimizeWindow(_THIS, SDL_Window* window);
+
+extern void
+MIR_RestoreWindow(_THIS, SDL_Window* window);
+
+extern void
+MIR_HideWindow(_THIS, SDL_Window* window);
+
+extern SDL_bool
+MIR_GetWindowWMInfo(_THIS, SDL_Window* window, SDL_SysWMinfo* info);
+
+extern void
+MIR_SetWindowSize(_THIS, SDL_Window* window);
+
+extern void
+MIR_SetWindowMinimumSize(_THIS, SDL_Window* window);
+
+extern void
+MIR_SetWindowMaximumSize(_THIS, SDL_Window* window);
+
+extern void
+MIR_SetWindowTitle(_THIS, SDL_Window* window);
+
+extern void
+MIR_SetWindowGrab(_THIS, SDL_Window* window, SDL_bool grabbed);
+
+extern int
+MIR_SetWindowGammaRamp(_THIS, SDL_Window* window, Uint16 const* ramp);
+
+extern int
+MIR_GetWindowGammaRamp(_THIS, SDL_Window* window, Uint16* ramp);
+
+#endif /* SDL_mirwindow_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/video/nacl/SDL_naclevents.c b/src/3rdparty/SDL2/src/video/nacl/SDL_naclevents.c
new file mode 100644
index 0000000..812df2b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/nacl/SDL_naclevents.c
@@ -0,0 +1,438 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_NACL
+
+#include "SDL.h"
+#include "../../events/SDL_sysevents.h"
+#include "../../events/SDL_events_c.h"
+#include "SDL_naclevents_c.h"
+#include "SDL_naclvideo.h"
+#include "ppapi_simple/ps_event.h"
+
+/* Ref: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent */
+
+static SDL_Scancode NACL_Keycodes[] = {
+ SDL_SCANCODE_UNKNOWN, /* 0 */
+ SDL_SCANCODE_UNKNOWN, /* 1 */
+ SDL_SCANCODE_UNKNOWN, /* 2 */
+ SDL_SCANCODE_CANCEL, /* DOM_VK_CANCEL 3 */
+ SDL_SCANCODE_UNKNOWN, /* 4 */
+ SDL_SCANCODE_UNKNOWN, /* 5 */
+ SDL_SCANCODE_HELP, /* DOM_VK_HELP 6 */
+ SDL_SCANCODE_UNKNOWN, /* 7 */
+ SDL_SCANCODE_BACKSPACE, /* DOM_VK_BACK_SPACE 8 */
+ SDL_SCANCODE_TAB, /* DOM_VK_TAB 9 */
+ SDL_SCANCODE_UNKNOWN, /* 10 */
+ SDL_SCANCODE_UNKNOWN, /* 11 */
+ SDL_SCANCODE_CLEAR, /* DOM_VK_CLEAR 12 */
+ SDL_SCANCODE_RETURN, /* DOM_VK_RETURN 13 */
+ SDL_SCANCODE_RETURN, /* DOM_VK_ENTER 14 */
+ SDL_SCANCODE_UNKNOWN, /* 15 */
+ SDL_SCANCODE_LSHIFT, /* DOM_VK_SHIFT 16 */
+ SDL_SCANCODE_LCTRL, /* DOM_VK_CONTROL 17 */
+ SDL_SCANCODE_LALT, /* DOM_VK_ALT 18 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_PAUSE 19 */
+ SDL_SCANCODE_CAPSLOCK, /* DOM_VK_CAPS_LOCK 20 */
+ SDL_SCANCODE_LANG1, /* DOM_VK_KANA DOM_VK_HANGUL 21 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_EISU 22 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_JUNJA 23 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_FINAL 24 */
+ SDL_SCANCODE_LANG2, /* DOM_VK_HANJA DOM_VK_KANJI 25 */
+ SDL_SCANCODE_UNKNOWN, /* 26 */
+ SDL_SCANCODE_ESCAPE, /* DOM_VK_ESCAPE 27 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_CONVERT 28 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_NONCONVERT 29 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_ACCEPT 30 */
+ SDL_SCANCODE_MODE, /* DOM_VK_MODECHANGE 31 */
+ SDL_SCANCODE_SPACE, /* DOM_VK_SPACE 32 */
+ SDL_SCANCODE_PAGEUP, /* DOM_VK_PAGE_UP 33 */
+ SDL_SCANCODE_PAGEDOWN, /* DOM_VK_PAGE_DOWN 34 */
+ SDL_SCANCODE_END, /* DOM_VK_END 35 */
+ SDL_SCANCODE_HOME, /* DOM_VK_HOME 36 */
+ SDL_SCANCODE_LEFT, /* DOM_VK_LEFT 37 */
+ SDL_SCANCODE_UP, /* DOM_VK_UP 38 */
+ SDL_SCANCODE_RIGHT, /* DOM_VK_RIGHT 39 */
+ SDL_SCANCODE_DOWN, /* DOM_VK_DOWN 40 */
+ SDL_SCANCODE_SELECT, /* DOM_VK_SELECT 41 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_PRINT 42 */
+ SDL_SCANCODE_EXECUTE, /* DOM_VK_EXECUTE 43 */
+ SDL_SCANCODE_PRINTSCREEN, /* DOM_VK_PRINTSCREEN 44 */
+ SDL_SCANCODE_INSERT, /* DOM_VK_INSERT 45 */
+ SDL_SCANCODE_DELETE, /* DOM_VK_DELETE 46 */
+ SDL_SCANCODE_UNKNOWN, /* 47 */
+ SDL_SCANCODE_0, /* DOM_VK_0 48 */
+ SDL_SCANCODE_1, /* DOM_VK_1 49 */
+ SDL_SCANCODE_2, /* DOM_VK_2 50 */
+ SDL_SCANCODE_3, /* DOM_VK_3 51 */
+ SDL_SCANCODE_4, /* DOM_VK_4 52 */
+ SDL_SCANCODE_5, /* DOM_VK_5 53 */
+ SDL_SCANCODE_6, /* DOM_VK_6 54 */
+ SDL_SCANCODE_7, /* DOM_VK_7 55 */
+ SDL_SCANCODE_8, /* DOM_VK_8 56 */
+ SDL_SCANCODE_9, /* DOM_VK_9 57 */
+ SDL_SCANCODE_KP_COLON, /* DOM_VK_COLON 58 */
+ SDL_SCANCODE_SEMICOLON, /* DOM_VK_SEMICOLON 59 */
+ SDL_SCANCODE_KP_LESS, /* DOM_VK_LESS_THAN 60 */
+ SDL_SCANCODE_EQUALS, /* DOM_VK_EQUALS 61 */
+ SDL_SCANCODE_KP_GREATER, /* DOM_VK_GREATER_THAN 62 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_QUESTION_MARK 63 */
+ SDL_SCANCODE_KP_AT, /* DOM_VK_AT 64 */
+ SDL_SCANCODE_A, /* DOM_VK_A 65 */
+ SDL_SCANCODE_B, /* DOM_VK_B 66 */
+ SDL_SCANCODE_C, /* DOM_VK_C 67 */
+ SDL_SCANCODE_D, /* DOM_VK_D 68 */
+ SDL_SCANCODE_E, /* DOM_VK_E 69 */
+ SDL_SCANCODE_F, /* DOM_VK_F 70 */
+ SDL_SCANCODE_G, /* DOM_VK_G 71 */
+ SDL_SCANCODE_H, /* DOM_VK_H 72 */
+ SDL_SCANCODE_I, /* DOM_VK_I 73 */
+ SDL_SCANCODE_J, /* DOM_VK_J 74 */
+ SDL_SCANCODE_K, /* DOM_VK_K 75 */
+ SDL_SCANCODE_L, /* DOM_VK_L 76 */
+ SDL_SCANCODE_M, /* DOM_VK_M 77 */
+ SDL_SCANCODE_N, /* DOM_VK_N 78 */
+ SDL_SCANCODE_O, /* DOM_VK_O 79 */
+ SDL_SCANCODE_P, /* DOM_VK_P 80 */
+ SDL_SCANCODE_Q, /* DOM_VK_Q 81 */
+ SDL_SCANCODE_R, /* DOM_VK_R 82 */
+ SDL_SCANCODE_S, /* DOM_VK_S 83 */
+ SDL_SCANCODE_T, /* DOM_VK_T 84 */
+ SDL_SCANCODE_U, /* DOM_VK_U 85 */
+ SDL_SCANCODE_V, /* DOM_VK_V 86 */
+ SDL_SCANCODE_W, /* DOM_VK_W 87 */
+ SDL_SCANCODE_X, /* DOM_VK_X 88 */
+ SDL_SCANCODE_Y, /* DOM_VK_Y 89 */
+ SDL_SCANCODE_Z, /* DOM_VK_Z 90 */
+ SDL_SCANCODE_LGUI, /* DOM_VK_WIN 91 */
+ SDL_SCANCODE_UNKNOWN, /* 92 */
+ SDL_SCANCODE_APPLICATION, /* DOM_VK_CONTEXT_MENU 93 */
+ SDL_SCANCODE_UNKNOWN, /* 94 */
+ SDL_SCANCODE_SLEEP, /* DOM_VK_SLEEP 95 */
+ SDL_SCANCODE_KP_0, /* DOM_VK_NUMPAD0 96 */
+ SDL_SCANCODE_KP_1, /* DOM_VK_NUMPAD1 97 */
+ SDL_SCANCODE_KP_2, /* DOM_VK_NUMPAD2 98 */
+ SDL_SCANCODE_KP_3, /* DOM_VK_NUMPAD3 99 */
+ SDL_SCANCODE_KP_4, /* DOM_VK_NUMPAD4 100 */
+ SDL_SCANCODE_KP_5, /* DOM_VK_NUMPAD5 101 */
+ SDL_SCANCODE_KP_6, /* DOM_VK_NUMPAD6 102 */
+ SDL_SCANCODE_KP_7, /* DOM_VK_NUMPAD7 103 */
+ SDL_SCANCODE_KP_8, /* DOM_VK_NUMPAD8 104 */
+ SDL_SCANCODE_KP_9, /* DOM_VK_NUMPAD9 105 */
+ SDL_SCANCODE_KP_MULTIPLY, /* DOM_VK_MULTIPLY 106 */
+ SDL_SCANCODE_KP_PLUS, /* DOM_VK_ADD 107 */
+ SDL_SCANCODE_KP_COMMA, /* DOM_VK_SEPARATOR 108 */
+ SDL_SCANCODE_KP_MINUS, /* DOM_VK_SUBTRACT 109 */
+ SDL_SCANCODE_KP_PERIOD, /* DOM_VK_DECIMAL 110 */
+ SDL_SCANCODE_KP_DIVIDE, /* DOM_VK_DIVIDE 111 */
+ SDL_SCANCODE_F1, /* DOM_VK_F1 112 */
+ SDL_SCANCODE_F2, /* DOM_VK_F2 113 */
+ SDL_SCANCODE_F3, /* DOM_VK_F3 114 */
+ SDL_SCANCODE_F4, /* DOM_VK_F4 115 */
+ SDL_SCANCODE_F5, /* DOM_VK_F5 116 */
+ SDL_SCANCODE_F6, /* DOM_VK_F6 117 */
+ SDL_SCANCODE_F7, /* DOM_VK_F7 118 */
+ SDL_SCANCODE_F8, /* DOM_VK_F8 119 */
+ SDL_SCANCODE_F9, /* DOM_VK_F9 120 */
+ SDL_SCANCODE_F10, /* DOM_VK_F10 121 */
+ SDL_SCANCODE_F11, /* DOM_VK_F11 122 */
+ SDL_SCANCODE_F12, /* DOM_VK_F12 123 */
+ SDL_SCANCODE_F13, /* DOM_VK_F13 124 */
+ SDL_SCANCODE_F14, /* DOM_VK_F14 125 */
+ SDL_SCANCODE_F15, /* DOM_VK_F15 126 */
+ SDL_SCANCODE_F16, /* DOM_VK_F16 127 */
+ SDL_SCANCODE_F17, /* DOM_VK_F17 128 */
+ SDL_SCANCODE_F18, /* DOM_VK_F18 129 */
+ SDL_SCANCODE_F19, /* DOM_VK_F19 130 */
+ SDL_SCANCODE_F20, /* DOM_VK_F20 131 */
+ SDL_SCANCODE_F21, /* DOM_VK_F21 132 */
+ SDL_SCANCODE_F22, /* DOM_VK_F22 133 */
+ SDL_SCANCODE_F23, /* DOM_VK_F23 134 */
+ SDL_SCANCODE_F24, /* DOM_VK_F24 135 */
+ SDL_SCANCODE_UNKNOWN, /* 136 */
+ SDL_SCANCODE_UNKNOWN, /* 137 */
+ SDL_SCANCODE_UNKNOWN, /* 138 */
+ SDL_SCANCODE_UNKNOWN, /* 139 */
+ SDL_SCANCODE_UNKNOWN, /* 140 */
+ SDL_SCANCODE_UNKNOWN, /* 141 */
+ SDL_SCANCODE_UNKNOWN, /* 142 */
+ SDL_SCANCODE_UNKNOWN, /* 143 */
+ SDL_SCANCODE_NUMLOCKCLEAR, /* DOM_VK_NUM_LOCK 144 */
+ SDL_SCANCODE_SCROLLLOCK, /* DOM_VK_SCROLL_LOCK 145 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_FJ_JISHO 146 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_FJ_MASSHOU 147 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_FJ_TOUROKU 148 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_FJ_LOYA 149 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_FJ_ROYA 150 */
+ SDL_SCANCODE_UNKNOWN, /* 151 */
+ SDL_SCANCODE_UNKNOWN, /* 152 */
+ SDL_SCANCODE_UNKNOWN, /* 153 */
+ SDL_SCANCODE_UNKNOWN, /* 154 */
+ SDL_SCANCODE_UNKNOWN, /* 155 */
+ SDL_SCANCODE_UNKNOWN, /* 156 */
+ SDL_SCANCODE_UNKNOWN, /* 157 */
+ SDL_SCANCODE_UNKNOWN, /* 158 */
+ SDL_SCANCODE_UNKNOWN, /* 159 */
+ SDL_SCANCODE_GRAVE, /* DOM_VK_CIRCUMFLEX 160 */
+ SDL_SCANCODE_KP_EXCLAM, /* DOM_VK_EXCLAMATION 161 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_DOUBLE_QUOTE 162 */
+ SDL_SCANCODE_KP_HASH, /* DOM_VK_HASH 163 */
+ SDL_SCANCODE_CURRENCYUNIT, /* DOM_VK_DOLLAR 164 */
+ SDL_SCANCODE_KP_PERCENT, /* DOM_VK_PERCENT 165 */
+ SDL_SCANCODE_KP_AMPERSAND, /* DOM_VK_AMPERSAND 166 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_UNDERSCORE 167 */
+ SDL_SCANCODE_KP_LEFTPAREN, /* DOM_VK_OPEN_PAREN 168 */
+ SDL_SCANCODE_KP_RIGHTPAREN, /* DOM_VK_CLOSE_PAREN 169 */
+ SDL_SCANCODE_KP_MULTIPLY, /* DOM_VK_ASTERISK 170 */
+ SDL_SCANCODE_KP_PLUS, /* DOM_VK_PLUS 171 */
+ SDL_SCANCODE_KP_PLUS, /* DOM_VK_PIPE 172 */
+ SDL_SCANCODE_MINUS, /* DOM_VK_HYPHEN_MINUS 173 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_OPEN_CURLY_BRACKET 174 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_CLOSE_CURLY_BRACKET 175 */
+ SDL_SCANCODE_NONUSBACKSLASH, /* DOM_VK_TILDE 176 */
+ SDL_SCANCODE_UNKNOWN, /* 177 */
+ SDL_SCANCODE_UNKNOWN, /* 178 */
+ SDL_SCANCODE_UNKNOWN, /* 179 */
+ SDL_SCANCODE_UNKNOWN, /* 180 */
+ SDL_SCANCODE_MUTE, /* DOM_VK_VOLUME_MUTE 181 */
+ SDL_SCANCODE_VOLUMEDOWN, /* DOM_VK_VOLUME_DOWN 182 */
+ SDL_SCANCODE_VOLUMEUP, /* DOM_VK_VOLUME_UP 183 */
+ SDL_SCANCODE_UNKNOWN, /* 184 */
+ SDL_SCANCODE_UNKNOWN, /* 185 */
+ SDL_SCANCODE_UNKNOWN, /* 186 */
+ SDL_SCANCODE_UNKNOWN, /* 187 */
+ SDL_SCANCODE_COMMA, /* DOM_VK_COMMA 188 */
+ SDL_SCANCODE_UNKNOWN, /* 189 */
+ SDL_SCANCODE_PERIOD, /* DOM_VK_PERIOD 190 */
+ SDL_SCANCODE_SLASH, /* DOM_VK_SLASH 191 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_BACK_QUOTE 192 */
+ SDL_SCANCODE_UNKNOWN, /* 193 */
+ SDL_SCANCODE_UNKNOWN, /* 194 */
+ SDL_SCANCODE_UNKNOWN, /* 195 */
+ SDL_SCANCODE_UNKNOWN, /* 196 */
+ SDL_SCANCODE_UNKNOWN, /* 197 */
+ SDL_SCANCODE_UNKNOWN, /* 198 */
+ SDL_SCANCODE_UNKNOWN, /* 199 */
+ SDL_SCANCODE_UNKNOWN, /* 200 */
+ SDL_SCANCODE_UNKNOWN, /* 201 */
+ SDL_SCANCODE_UNKNOWN, /* 202 */
+ SDL_SCANCODE_UNKNOWN, /* 203 */
+ SDL_SCANCODE_UNKNOWN, /* 204 */
+ SDL_SCANCODE_UNKNOWN, /* 205 */
+ SDL_SCANCODE_UNKNOWN, /* 206 */
+ SDL_SCANCODE_UNKNOWN, /* 207 */
+ SDL_SCANCODE_UNKNOWN, /* 208 */
+ SDL_SCANCODE_UNKNOWN, /* 209 */
+ SDL_SCANCODE_UNKNOWN, /* 210 */
+ SDL_SCANCODE_UNKNOWN, /* 211 */
+ SDL_SCANCODE_UNKNOWN, /* 212 */
+ SDL_SCANCODE_UNKNOWN, /* 213 */
+ SDL_SCANCODE_UNKNOWN, /* 214 */
+ SDL_SCANCODE_UNKNOWN, /* 215 */
+ SDL_SCANCODE_UNKNOWN, /* 216 */
+ SDL_SCANCODE_UNKNOWN, /* 217 */
+ SDL_SCANCODE_UNKNOWN, /* 218 */
+ SDL_SCANCODE_LEFTBRACKET, /* DOM_VK_OPEN_BRACKET 219 */
+ SDL_SCANCODE_BACKSLASH, /* DOM_VK_BACK_SLASH 220 */
+ SDL_SCANCODE_RIGHTBRACKET, /* DOM_VK_CLOSE_BRACKET 221 */
+ SDL_SCANCODE_APOSTROPHE, /* DOM_VK_QUOTE 222 */
+ SDL_SCANCODE_UNKNOWN, /* 223 */
+ SDL_SCANCODE_RGUI, /* DOM_VK_META 224 */
+ SDL_SCANCODE_RALT, /* DOM_VK_ALTGR 225 */
+ SDL_SCANCODE_UNKNOWN, /* 226 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_ICO_HELP 227 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_ICO_00 228 */
+ SDL_SCANCODE_UNKNOWN, /* 229 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_ICO_CLEAR 230 */
+ SDL_SCANCODE_UNKNOWN, /* 231 */
+ SDL_SCANCODE_UNKNOWN, /* 232 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_RESET 233 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_JUMP 234 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_PA1 235 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_PA2 236 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_PA3 237 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_WSCTRL 238 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_CUSEL 239 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_ATTN 240 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_FINISH 241 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_COPY 242 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_AUTO 243 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_ENLW 244 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_BACKTAB 245 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_ATTN 246 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_CRSEL 247 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_EXSEL 248 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_EREOF 249 */
+ SDL_SCANCODE_AUDIOPLAY, /* DOM_VK_PLAY 250 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_ZOOM 251 */
+ SDL_SCANCODE_UNKNOWN, /* 252 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_PA1 253 */
+ SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_CLEAR 254 */
+ SDL_SCANCODE_UNKNOWN, /* 255 */
+};
+
+static Uint8 SDL_NACL_translate_mouse_button(int32_t button) {
+ switch (button) {
+ case PP_INPUTEVENT_MOUSEBUTTON_LEFT:
+ return SDL_BUTTON_LEFT;
+ case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE:
+ return SDL_BUTTON_MIDDLE;
+ case PP_INPUTEVENT_MOUSEBUTTON_RIGHT:
+ return SDL_BUTTON_RIGHT;
+
+ case PP_INPUTEVENT_MOUSEBUTTON_NONE:
+ default:
+ return 0;
+ }
+}
+
+static SDL_Scancode
+SDL_NACL_translate_keycode(int keycode)
+{
+ SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
+
+ if (keycode < SDL_arraysize(NACL_Keycodes)) {
+ scancode = NACL_Keycodes[keycode];
+ }
+ if (scancode == SDL_SCANCODE_UNKNOWN) {
+ SDL_Log("The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL forums/mailing list <https://discourse.libsdl.org/> NACL KeyCode %d", keycode);
+ }
+ return scancode;
+}
+
+void NACL_PumpEvents(_THIS) {
+ PSEvent* ps_event;
+ PP_Resource event;
+ PP_InputEvent_Type type;
+ PP_InputEvent_Modifier modifiers;
+ struct PP_Rect rect;
+ struct PP_FloatPoint fp;
+ struct PP_Point location;
+ struct PP_Var var;
+ const char *str;
+ char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
+ Uint32 str_len;
+ SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ if (driverdata->window) {
+ while ((ps_event = PSEventTryAcquire()) != NULL) {
+ event = ps_event->as_resource;
+ switch(ps_event->type) {
+ /* From DidChangeView, contains a view resource */
+ case PSE_INSTANCE_DIDCHANGEVIEW:
+ driverdata->ppb_view->GetRect(event, &rect);
+ NACL_SetScreenResolution(rect.size.width, rect.size.height, SDL_PIXELFORMAT_UNKNOWN);
+ // FIXME: Rebuild context? See life.c UpdateContext
+ break;
+
+ /* From HandleInputEvent, contains an input resource. */
+ case PSE_INSTANCE_HANDLEINPUT:
+ type = driverdata->ppb_input_event->GetType(event);
+ modifiers = driverdata->ppb_input_event->GetModifiers(event);
+ switch(type) {
+ case PP_INPUTEVENT_TYPE_MOUSEDOWN:
+ SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_PRESSED, SDL_NACL_translate_mouse_button(driverdata->ppb_mouse_input_event->GetButton(event)));
+ break;
+ case PP_INPUTEVENT_TYPE_MOUSEUP:
+ SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, SDL_NACL_translate_mouse_button(driverdata->ppb_mouse_input_event->GetButton(event)));
+ break;
+ case PP_INPUTEVENT_TYPE_WHEEL:
+ /* FIXME: GetTicks provides high resolution scroll events */
+ fp = driverdata->ppb_wheel_input_event->GetDelta(event);
+ SDL_SendMouseWheel(mouse->focus, mouse->mouseID, fp.x, fp.y, SDL_MOUSEWHEEL_NORMAL);
+ break;
+
+ case PP_INPUTEVENT_TYPE_MOUSEENTER:
+ case PP_INPUTEVENT_TYPE_MOUSELEAVE:
+ /* FIXME: Mouse Focus */
+ break;
+
+
+ case PP_INPUTEVENT_TYPE_MOUSEMOVE:
+ location = driverdata->ppb_mouse_input_event->GetPosition(event);
+ SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_FALSE, location.x, location.y);
+ break;
+
+ case PP_INPUTEVENT_TYPE_TOUCHSTART:
+ case PP_INPUTEVENT_TYPE_TOUCHMOVE:
+ case PP_INPUTEVENT_TYPE_TOUCHEND:
+ case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
+ /* FIXME: Touch events */
+ break;
+
+ case PP_INPUTEVENT_TYPE_KEYDOWN:
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_NACL_translate_keycode(driverdata->ppb_keyboard_input_event->GetKeyCode(event)));
+ break;
+
+ case PP_INPUTEVENT_TYPE_KEYUP:
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_NACL_translate_keycode(driverdata->ppb_keyboard_input_event->GetKeyCode(event)));
+ break;
+
+ case PP_INPUTEVENT_TYPE_CHAR:
+ var = driverdata->ppb_keyboard_input_event->GetCharacterText(event);
+ str = driverdata->ppb_var->VarToUtf8(var, &str_len);
+ /* str is not null terminated! */
+ if ( str_len >= SDL_arraysize(text) ) {
+ str_len = SDL_arraysize(text) - 1;
+ }
+ SDL_strlcpy(text, str, str_len );
+ text[str_len] = '\0';
+
+ SDL_SendKeyboardText(text);
+ /* FIXME: Do we have to handle ref counting? driverdata->ppb_var->Release(var);*/
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+
+ /* From HandleMessage, contains a PP_Var. */
+ case PSE_INSTANCE_HANDLEMESSAGE:
+ break;
+
+ /* From DidChangeFocus, contains a PP_Bool with the current focus state. */
+ case PSE_INSTANCE_DIDCHANGEFOCUS:
+ break;
+
+ /* When the 3D context is lost, no resource. */
+ case PSE_GRAPHICS3D_GRAPHICS3DCONTEXTLOST:
+ break;
+
+ /* When the mouse lock is lost. */
+ case PSE_MOUSELOCK_MOUSELOCKLOST:
+ break;
+
+ default:
+ break;
+ }
+
+ PSEventRelease(ps_event);
+ }
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_NACL */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/nacl/SDL_naclevents_c.h b/src/3rdparty/SDL2/src/video/nacl/SDL_naclevents_c.h
new file mode 100644
index 0000000..8059ea5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/nacl/SDL_naclevents_c.h
@@ -0,0 +1,30 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_naclevents_c_h_
+#define SDL_naclevents_c_h_
+
+#include "SDL_naclvideo.h"
+
+extern void NACL_PumpEvents(_THIS);
+
+#endif /* SDL_naclevents_c_h_ */
diff --git a/src/3rdparty/SDL2/src/video/nacl/SDL_naclglue.c b/src/3rdparty/SDL2/src/video/nacl/SDL_naclglue.c
new file mode 100644
index 0000000..544cc6f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/nacl/SDL_naclglue.c
@@ -0,0 +1,24 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_NACL
+#endif /* SDL_VIDEO_DRIVER_NACL */
diff --git a/src/3rdparty/SDL2/src/video/nacl/SDL_naclopengles.c b/src/3rdparty/SDL2/src/video/nacl/SDL_naclopengles.c
new file mode 100644
index 0000000..98b9ad3
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/nacl/SDL_naclopengles.c
@@ -0,0 +1,174 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_NACL
+
+/* NaCl SDL video GLES 2 driver implementation */
+
+#include "SDL_video.h"
+#include "SDL_naclvideo.h"
+
+#if SDL_LOADSO_DLOPEN
+#include "dlfcn.h"
+#endif
+
+#include "ppapi/gles2/gl2ext_ppapi.h"
+#include "ppapi_simple/ps.h"
+
+/* GL functions */
+int
+NACL_GLES_LoadLibrary(_THIS, const char *path)
+{
+ /* FIXME: Support dynamic linking when PNACL supports it */
+ return glInitializePPAPI(PSGetInterface) == 0;
+}
+
+void *
+NACL_GLES_GetProcAddress(_THIS, const char *proc)
+{
+#if SDL_LOADSO_DLOPEN
+ return dlsym( 0 /* RTLD_DEFAULT */, proc);
+#else
+ return NULL;
+#endif
+}
+
+void
+NACL_GLES_UnloadLibrary(_THIS)
+{
+ /* FIXME: Support dynamic linking when PNACL supports it */
+ glTerminatePPAPI();
+}
+
+int
+NACL_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext sdl_context)
+{
+ SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
+ /* FIXME: Check threading issues...otherwise use a hardcoded _this->context across all threads */
+ driverdata->ppb_instance->BindGraphics(driverdata->instance, (PP_Resource) sdl_context);
+ glSetCurrentContextPPAPI((PP_Resource) sdl_context);
+ return 0;
+}
+
+SDL_GLContext
+NACL_GLES_CreateContext(_THIS, SDL_Window * window)
+{
+ SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
+ PP_Resource context, share_context = 0;
+ /* 64 seems nice. */
+ Sint32 attribs[64];
+ int i = 0;
+
+ if (_this->gl_config.share_with_current_context) {
+ share_context = (PP_Resource) SDL_GL_GetCurrentContext();
+ }
+
+ /* FIXME: Some ATTRIBS from PP_Graphics3DAttrib are not set here */
+
+ attribs[i++] = PP_GRAPHICS3DATTRIB_WIDTH;
+ attribs[i++] = window->w;
+ attribs[i++] = PP_GRAPHICS3DATTRIB_HEIGHT;
+ attribs[i++] = window->h;
+ attribs[i++] = PP_GRAPHICS3DATTRIB_RED_SIZE;
+ attribs[i++] = _this->gl_config.red_size;
+ attribs[i++] = PP_GRAPHICS3DATTRIB_GREEN_SIZE;
+ attribs[i++] = _this->gl_config.green_size;
+ attribs[i++] = PP_GRAPHICS3DATTRIB_BLUE_SIZE;
+ attribs[i++] = _this->gl_config.blue_size;
+
+ if (_this->gl_config.alpha_size) {
+ attribs[i++] = PP_GRAPHICS3DATTRIB_ALPHA_SIZE;
+ attribs[i++] = _this->gl_config.alpha_size;
+ }
+
+ /*if (_this->gl_config.buffer_size) {
+ attribs[i++] = EGL_BUFFER_SIZE;
+ attribs[i++] = _this->gl_config.buffer_size;
+ }*/
+
+ attribs[i++] = PP_GRAPHICS3DATTRIB_DEPTH_SIZE;
+ attribs[i++] = _this->gl_config.depth_size;
+
+ if (_this->gl_config.stencil_size) {
+ attribs[i++] = PP_GRAPHICS3DATTRIB_STENCIL_SIZE;
+ attribs[i++] = _this->gl_config.stencil_size;
+ }
+
+ if (_this->gl_config.multisamplebuffers) {
+ attribs[i++] = PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS;
+ attribs[i++] = _this->gl_config.multisamplebuffers;
+ }
+
+ if (_this->gl_config.multisamplesamples) {
+ attribs[i++] = PP_GRAPHICS3DATTRIB_SAMPLES;
+ attribs[i++] = _this->gl_config.multisamplesamples;
+ }
+
+ attribs[i++] = PP_GRAPHICS3DATTRIB_NONE;
+
+ context = driverdata->ppb_graphics->Create(driverdata->instance, share_context, attribs);
+
+ if (context) {
+ /* We need to make the context current, otherwise nothing works */
+ SDL_GL_MakeCurrent(window, (SDL_GLContext) context);
+ }
+
+ return (SDL_GLContext) context;
+}
+
+
+
+int
+NACL_GLES_SetSwapInterval(_THIS, int interval)
+{
+ /* STUB */
+ return SDL_Unsupported();
+}
+
+int
+NACL_GLES_GetSwapInterval(_THIS)
+{
+ /* STUB */
+ return 0;
+}
+
+int
+NACL_GLES_SwapWindow(_THIS, SDL_Window * window)
+{
+ SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
+ struct PP_CompletionCallback callback = { NULL, 0, PP_COMPLETIONCALLBACK_FLAG_NONE };
+ if (driverdata->ppb_graphics->SwapBuffers((PP_Resource) SDL_GL_GetCurrentContext(), callback ) != 0) {
+ return SDL_SetError("SwapBuffers failed");
+ }
+ return 0;
+}
+
+void
+NACL_GLES_DeleteContext(_THIS, SDL_GLContext context)
+{
+ SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
+ driverdata->ppb_core->ReleaseResource((PP_Resource) context);
+}
+
+#endif /* SDL_VIDEO_DRIVER_NACL */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/nacl/SDL_naclopengles.h b/src/3rdparty/SDL2/src/video/nacl/SDL_naclopengles.h
new file mode 100644
index 0000000..744c0e5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/nacl/SDL_naclopengles.h
@@ -0,0 +1,38 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_naclopengles_h_
+#define SDL_naclopengles_h_
+
+extern int NACL_GLES_LoadLibrary(_THIS, const char *path);
+extern void *NACL_GLES_GetProcAddress(_THIS, const char *proc);
+extern void NACL_GLES_UnloadLibrary(_THIS);
+extern SDL_GLContext NACL_GLES_CreateContext(_THIS, SDL_Window * window);
+extern int NACL_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+extern int NACL_GLES_SetSwapInterval(_THIS, int interval);
+extern int NACL_GLES_GetSwapInterval(_THIS);
+extern int NACL_GLES_SwapWindow(_THIS, SDL_Window * window);
+extern void NACL_GLES_DeleteContext(_THIS, SDL_GLContext context);
+
+#endif /* SDL_naclopengles_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/nacl/SDL_naclvideo.c b/src/3rdparty/SDL2/src/video/nacl/SDL_naclvideo.c
new file mode 100644
index 0000000..24dda2c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/nacl/SDL_naclvideo.c
@@ -0,0 +1,183 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_NACL
+
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/c/pp_instance.h"
+#include "ppapi_simple/ps.h"
+#include "ppapi_simple/ps_interface.h"
+#include "ppapi_simple/ps_event.h"
+#include "nacl_io/nacl_io.h"
+
+#include "SDL_naclvideo.h"
+#include "SDL_naclwindow.h"
+#include "SDL_naclevents_c.h"
+#include "SDL_naclopengles.h"
+#include "SDL_video.h"
+#include "../SDL_sysvideo.h"
+#include "../../events/SDL_events_c.h"
+
+#define NACLVID_DRIVER_NAME "nacl"
+
+/* Static init required because NACL_SetScreenResolution
+ * may appear even before SDL starts and we want to remember
+ * the window width and height
+ */
+static SDL_VideoData nacl = {0};
+
+void
+NACL_SetScreenResolution(int width, int height, Uint32 format)
+{
+ PP_Resource context;
+
+ nacl.w = width;
+ nacl.h = height;
+ nacl.format = format;
+
+ if (nacl.window) {
+ nacl.window->w = width;
+ nacl.window->h = height;
+ SDL_SendWindowEvent(nacl.window, SDL_WINDOWEVENT_RESIZED, width, height);
+ }
+
+ /* FIXME: Check threading issues...otherwise use a hardcoded _this->context across all threads */
+ context = (PP_Resource) SDL_GL_GetCurrentContext();
+ if (context) {
+ PSInterfaceGraphics3D()->ResizeBuffers(context, width, height);
+ }
+
+}
+
+
+
+/* Initialization/Query functions */
+static int NACL_VideoInit(_THIS);
+static void NACL_VideoQuit(_THIS);
+
+static int NACL_Available(void) {
+ return PSGetInstanceId() != 0;
+}
+
+static void NACL_DeleteDevice(SDL_VideoDevice *device) {
+ SDL_VideoData *driverdata = (SDL_VideoData*) device->driverdata;
+ driverdata->ppb_core->ReleaseResource((PP_Resource) driverdata->ppb_message_loop);
+ /* device->driverdata is not freed because it points to static memory */
+ SDL_free(device);
+}
+
+static int
+NACL_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
+{
+ return 0;
+}
+
+static SDL_VideoDevice *NACL_CreateDevice(int devindex) {
+ SDL_VideoDevice *device;
+
+ /* Initialize all variables that we clean on shutdown */
+ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (!device) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ device->driverdata = &nacl;
+
+ /* Set the function pointers */
+ device->VideoInit = NACL_VideoInit;
+ device->VideoQuit = NACL_VideoQuit;
+ device->PumpEvents = NACL_PumpEvents;
+
+ device->CreateSDLWindow = NACL_CreateWindow;
+ device->SetWindowTitle = NACL_SetWindowTitle;
+ device->DestroyWindow = NACL_DestroyWindow;
+
+ device->SetDisplayMode = NACL_SetDisplayMode;
+
+ device->free = NACL_DeleteDevice;
+
+ /* GL pointers */
+ device->GL_LoadLibrary = NACL_GLES_LoadLibrary;
+ device->GL_GetProcAddress = NACL_GLES_GetProcAddress;
+ device->GL_UnloadLibrary = NACL_GLES_UnloadLibrary;
+ device->GL_CreateContext = NACL_GLES_CreateContext;
+ device->GL_MakeCurrent = NACL_GLES_MakeCurrent;
+ device->GL_SetSwapInterval = NACL_GLES_SetSwapInterval;
+ device->GL_GetSwapInterval = NACL_GLES_GetSwapInterval;
+ device->GL_SwapWindow = NACL_GLES_SwapWindow;
+ device->GL_DeleteContext = NACL_GLES_DeleteContext;
+
+
+ return device;
+}
+
+VideoBootStrap NACL_bootstrap = {
+ NACLVID_DRIVER_NAME, "SDL Native Client Video Driver",
+ NACL_Available, NACL_CreateDevice
+};
+
+int NACL_VideoInit(_THIS) {
+ SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
+ SDL_DisplayMode mode;
+
+ SDL_zero(mode);
+ mode.format = driverdata->format;
+ mode.w = driverdata->w;
+ mode.h = driverdata->h;
+ mode.refresh_rate = 0;
+ mode.driverdata = NULL;
+ if (SDL_AddBasicVideoDisplay(&mode) < 0) {
+ return -1;
+ }
+
+ SDL_AddDisplayMode(&_this->displays[0], &mode);
+
+ PSInterfaceInit();
+ driverdata->instance = PSGetInstanceId();
+ driverdata->ppb_graphics = PSInterfaceGraphics3D();
+ driverdata->ppb_message_loop = PSInterfaceMessageLoop();
+ driverdata->ppb_core = PSInterfaceCore();
+ driverdata->ppb_fullscreen = PSInterfaceFullscreen();
+ driverdata->ppb_instance = PSInterfaceInstance();
+ driverdata->ppb_image_data = PSInterfaceImageData();
+ driverdata->ppb_view = PSInterfaceView();
+ driverdata->ppb_var = PSInterfaceVar();
+ driverdata->ppb_input_event = (PPB_InputEvent*) PSGetInterface(PPB_INPUT_EVENT_INTERFACE);
+ driverdata->ppb_keyboard_input_event = (PPB_KeyboardInputEvent*) PSGetInterface(PPB_KEYBOARD_INPUT_EVENT_INTERFACE);
+ driverdata->ppb_mouse_input_event = (PPB_MouseInputEvent*) PSGetInterface(PPB_MOUSE_INPUT_EVENT_INTERFACE);
+ driverdata->ppb_wheel_input_event = (PPB_WheelInputEvent*) PSGetInterface(PPB_WHEEL_INPUT_EVENT_INTERFACE);
+ driverdata->ppb_touch_input_event = (PPB_TouchInputEvent*) PSGetInterface(PPB_TOUCH_INPUT_EVENT_INTERFACE);
+
+
+ driverdata->message_loop = driverdata->ppb_message_loop->Create(driverdata->instance);
+
+ PSEventSetFilter(PSE_ALL);
+
+ /* We're done! */
+ return 0;
+}
+
+void NACL_VideoQuit(_THIS) {
+}
+
+#endif /* SDL_VIDEO_DRIVER_NACL */
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/nacl/SDL_naclvideo.h b/src/3rdparty/SDL2/src/video/nacl/SDL_naclvideo.h
new file mode 100644
index 0000000..6986aa8
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/nacl/SDL_naclvideo.h
@@ -0,0 +1,67 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_naclvideo_h_
+#define SDL_naclvideo_h_
+
+#include "../SDL_sysvideo.h"
+#include "ppapi_simple/ps_interface.h"
+#include "ppapi/c/pp_input_event.h"
+
+
+/* Hidden "this" pointer for the video functions */
+#define _THIS SDL_VideoDevice *_this
+
+
+/* Private display data */
+
+typedef struct SDL_VideoData {
+ Uint32 format;
+ int w, h;
+ SDL_Window *window;
+
+ const PPB_Graphics3D *ppb_graphics;
+ const PPB_MessageLoop *ppb_message_loop;
+ const PPB_Core *ppb_core;
+ const PPB_Fullscreen *ppb_fullscreen;
+ const PPB_Instance *ppb_instance;
+ const PPB_ImageData *ppb_image_data;
+ const PPB_View *ppb_view;
+ const PPB_Var *ppb_var;
+ const PPB_InputEvent *ppb_input_event;
+ const PPB_KeyboardInputEvent *ppb_keyboard_input_event;
+ const PPB_MouseInputEvent *ppb_mouse_input_event;
+ const PPB_WheelInputEvent *ppb_wheel_input_event;
+ const PPB_TouchInputEvent *ppb_touch_input_event;
+
+ PP_Resource message_loop;
+ PP_Instance instance;
+
+ /* FIXME: Check threading issues...otherwise use a hardcoded _this->context across all threads */
+ /* PP_Resource context; */
+
+} SDL_VideoData;
+
+extern void NACL_SetScreenResolution(int width, int height, Uint32 format);
+
+
+#endif /* SDL_naclvideo_h_ */
diff --git a/src/3rdparty/SDL2/src/video/nacl/SDL_naclwindow.c b/src/3rdparty/SDL2/src/video/nacl/SDL_naclwindow.c
new file mode 100644
index 0000000..7193331
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/nacl/SDL_naclwindow.c
@@ -0,0 +1,79 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_NACL
+
+#include "../SDL_sysvideo.h"
+
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_keyboard_c.h"
+#include "SDL_naclvideo.h"
+#include "SDL_naclwindow.h"
+
+int
+NACL_CreateWindow(_THIS, SDL_Window * window)
+{
+ SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
+
+ if (driverdata->window) {
+ SDL_SetError("NaCl only supports one window");
+ return -1;
+ }
+ driverdata->window = window;
+
+ /* Adjust the window data to match the screen */
+ window->x = 0;
+ window->y = 0;
+ window->w = driverdata->w;
+ window->h = driverdata->h;
+
+ window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */
+ window->flags |= SDL_WINDOW_FULLSCREEN; /* window is always fullscreen */
+ window->flags &= ~SDL_WINDOW_HIDDEN;
+ window->flags |= SDL_WINDOW_SHOWN; /* only one window on NaCl */
+ window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
+ window->flags |= SDL_WINDOW_OPENGL;
+
+ SDL_SetMouseFocus(window);
+ SDL_SetKeyboardFocus(window);
+
+ return 0;
+}
+
+void
+NACL_SetWindowTitle(_THIS, SDL_Window * window)
+{
+ /* TODO */
+}
+
+void
+NACL_DestroyWindow(_THIS, SDL_Window * window)
+{
+ SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
+ if (window == driverdata->window) {
+ driverdata->window = NULL;
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_NACL */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/nacl/SDL_naclwindow.h b/src/3rdparty/SDL2/src/video/nacl/SDL_naclwindow.h
new file mode 100644
index 0000000..412b15f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/nacl/SDL_naclwindow.h
@@ -0,0 +1,32 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_naclwindow_h_
+#define SDL_naclwindow_h_
+
+extern int NACL_CreateWindow(_THIS, SDL_Window * window);
+extern void NACL_SetWindowTitle(_THIS, SDL_Window * window);
+extern void NACL_DestroyWindow(_THIS, SDL_Window * window);
+
+#endif /* SDL_naclwindow_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/pandora/SDL_pandora.c b/src/3rdparty/SDL2/src/video/pandora/SDL_pandora.c
new file mode 100644
index 0000000..b319b16
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/pandora/SDL_pandora.c
@@ -0,0 +1,838 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_PANDORA
+
+/* SDL internals */
+#include "../SDL_sysvideo.h"
+#include "SDL_version.h"
+#include "SDL_syswm.h"
+#include "SDL_loadso.h"
+#include "SDL_events.h"
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_keyboard_c.h"
+
+/* PND declarations */
+#include "SDL_pandora.h"
+#include "SDL_pandora_events.h"
+
+/* WIZ declarations */
+#include "GLES/gl.h"
+#ifdef WIZ_GLES_LITE
+static NativeWindowType hNativeWnd = 0; /* A handle to the window we will create. */
+#endif
+
+static int
+PND_available(void)
+{
+ return 1;
+}
+
+static void
+PND_destroy(SDL_VideoDevice * device)
+{
+ if (device->driverdata != NULL) {
+ SDL_free(device->driverdata);
+ device->driverdata = NULL;
+ }
+ SDL_free(device);
+}
+
+static SDL_VideoDevice *
+PND_create()
+{
+ SDL_VideoDevice *device;
+ SDL_VideoData *phdata;
+ int status;
+
+ /* Check if pandora could be initialized */
+ status = PND_available();
+ if (status == 0) {
+ /* PND could not be used */
+ return NULL;
+ }
+
+ /* Initialize SDL_VideoDevice structure */
+ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (device == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ /* Initialize internal Pandora specific data */
+ phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
+ if (phdata == NULL) {
+ SDL_OutOfMemory();
+ SDL_free(device);
+ return NULL;
+ }
+
+ device->driverdata = phdata;
+
+ phdata->egl_initialized = SDL_TRUE;
+
+
+ /* Setup amount of available displays */
+ device->num_displays = 0;
+
+ /* Set device free function */
+ device->free = PND_destroy;
+
+ /* Setup all functions which we can handle */
+ device->VideoInit = PND_videoinit;
+ device->VideoQuit = PND_videoquit;
+ device->GetDisplayModes = PND_getdisplaymodes;
+ device->SetDisplayMode = PND_setdisplaymode;
+ device->CreateSDLWindow = PND_createwindow;
+ device->CreateSDLWindowFrom = PND_createwindowfrom;
+ device->SetWindowTitle = PND_setwindowtitle;
+ device->SetWindowIcon = PND_setwindowicon;
+ device->SetWindowPosition = PND_setwindowposition;
+ device->SetWindowSize = PND_setwindowsize;
+ device->ShowWindow = PND_showwindow;
+ device->HideWindow = PND_hidewindow;
+ device->RaiseWindow = PND_raisewindow;
+ device->MaximizeWindow = PND_maximizewindow;
+ device->MinimizeWindow = PND_minimizewindow;
+ device->RestoreWindow = PND_restorewindow;
+ device->SetWindowGrab = PND_setwindowgrab;
+ device->DestroyWindow = PND_destroywindow;
+#if 0
+ device->GetWindowWMInfo = PND_getwindowwminfo;
+#endif
+ device->GL_LoadLibrary = PND_gl_loadlibrary;
+ device->GL_GetProcAddress = PND_gl_getprocaddres;
+ device->GL_UnloadLibrary = PND_gl_unloadlibrary;
+ device->GL_CreateContext = PND_gl_createcontext;
+ device->GL_MakeCurrent = PND_gl_makecurrent;
+ device->GL_SetSwapInterval = PND_gl_setswapinterval;
+ device->GL_GetSwapInterval = PND_gl_getswapinterval;
+ device->GL_SwapWindow = PND_gl_swapwindow;
+ device->GL_DeleteContext = PND_gl_deletecontext;
+ device->PumpEvents = PND_PumpEvents;
+
+ /* !!! FIXME: implement SetWindowBordered */
+
+ return device;
+}
+
+VideoBootStrap PND_bootstrap = {
+#ifdef WIZ_GLES_LITE
+ "wiz",
+ "SDL Wiz Video Driver",
+#else
+ "pandora",
+ "SDL Pandora Video Driver",
+#endif
+ PND_available,
+ PND_create
+};
+
+/*****************************************************************************/
+/* SDL Video and Display initialization/handling functions */
+/*****************************************************************************/
+int
+PND_videoinit(_THIS)
+{
+ SDL_VideoDisplay display;
+ SDL_DisplayMode current_mode;
+
+ SDL_zero(current_mode);
+#ifdef WIZ_GLES_LITE
+ current_mode.w = 320;
+ current_mode.h = 240;
+#else
+ current_mode.w = 800;
+ current_mode.h = 480;
+#endif
+ current_mode.refresh_rate = 60;
+ current_mode.format = SDL_PIXELFORMAT_RGB565;
+ current_mode.driverdata = NULL;
+
+ SDL_zero(display);
+ display.desktop_mode = current_mode;
+ display.current_mode = current_mode;
+ display.driverdata = NULL;
+
+ SDL_AddVideoDisplay(&display);
+
+ return 1;
+}
+
+void
+PND_videoquit(_THIS)
+{
+
+}
+
+void
+PND_getdisplaymodes(_THIS, SDL_VideoDisplay * display)
+{
+
+}
+
+int
+PND_setdisplaymode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
+{
+ return 0;
+}
+
+int
+PND_createwindow(_THIS, SDL_Window * window)
+{
+ SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+
+ SDL_WindowData *wdata;
+
+ /* Allocate window internal data */
+ wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
+ if (wdata == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ /* Setup driver data for this window */
+ window->driverdata = wdata;
+
+ /* Check if window must support OpenGL ES rendering */
+ if ((window->flags & SDL_WINDOW_OPENGL) == SDL_WINDOW_OPENGL) {
+
+ EGLBoolean initstatus;
+
+ /* Mark this window as OpenGL ES compatible */
+ wdata->uses_gles = SDL_TRUE;
+
+ /* Create connection to OpenGL ES */
+ if (phdata->egl_display == EGL_NO_DISPLAY) {
+ phdata->egl_display = eglGetDisplay((NativeDisplayType) 0);
+ if (phdata->egl_display == EGL_NO_DISPLAY) {
+ return SDL_SetError("PND: Can't get connection to OpenGL ES");
+ }
+
+ initstatus = eglInitialize(phdata->egl_display, NULL, NULL);
+ if (initstatus != EGL_TRUE) {
+ return SDL_SetError("PND: Can't init OpenGL ES library");
+ }
+ }
+
+ phdata->egl_refcount++;
+ }
+
+ /* Window has been successfully created */
+ return 0;
+}
+
+int
+PND_createwindowfrom(_THIS, SDL_Window * window, const void *data)
+{
+ return -1;
+}
+
+void
+PND_setwindowtitle(_THIS, SDL_Window * window)
+{
+}
+void
+PND_setwindowicon(_THIS, SDL_Window * window, SDL_Surface * icon)
+{
+}
+void
+PND_setwindowposition(_THIS, SDL_Window * window)
+{
+}
+void
+PND_setwindowsize(_THIS, SDL_Window * window)
+{
+}
+void
+PND_showwindow(_THIS, SDL_Window * window)
+{
+}
+void
+PND_hidewindow(_THIS, SDL_Window * window)
+{
+}
+void
+PND_raisewindow(_THIS, SDL_Window * window)
+{
+}
+void
+PND_maximizewindow(_THIS, SDL_Window * window)
+{
+}
+void
+PND_minimizewindow(_THIS, SDL_Window * window)
+{
+}
+void
+PND_restorewindow(_THIS, SDL_Window * window)
+{
+}
+void
+PND_setwindowgrab(_THIS, SDL_Window * window, SDL_bool grabbed)
+{
+}
+void
+PND_destroywindow(_THIS, SDL_Window * window)
+{
+ SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+ eglTerminate(phdata->egl_display);
+}
+
+/*****************************************************************************/
+/* SDL Window Manager function */
+/*****************************************************************************/
+#if 0
+SDL_bool
+PND_getwindowwminfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
+{
+ if (info->version.major <= SDL_MAJOR_VERSION) {
+ return SDL_TRUE;
+ } else {
+ SDL_SetError("application not compiled with SDL %d.%d",
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+ return SDL_FALSE;
+ }
+
+ /* Failed to get window manager information */
+ return SDL_FALSE;
+}
+#endif
+
+/*****************************************************************************/
+/* SDL OpenGL/OpenGL ES functions */
+/*****************************************************************************/
+int
+PND_gl_loadlibrary(_THIS, const char *path)
+{
+ /* Check if OpenGL ES library is specified for GF driver */
+ if (path == NULL) {
+ path = SDL_getenv("SDL_OPENGL_LIBRARY");
+ if (path == NULL) {
+ path = SDL_getenv("SDL_OPENGLES_LIBRARY");
+ }
+ }
+
+ /* Check if default library loading requested */
+ if (path == NULL) {
+ /* Already linked with GF library which provides egl* subset of */
+ /* functions, use Common profile of OpenGL ES library by default */
+#ifdef WIZ_GLES_LITE
+ path = "/lib/libopengles_lite.so";
+#else
+ path = "/usr/lib/libGLES_CM.so";
+#endif
+ }
+
+ /* Load dynamic library */
+ _this->gl_config.dll_handle = SDL_LoadObject(path);
+ if (!_this->gl_config.dll_handle) {
+ /* Failed to load new GL ES library */
+ return SDL_SetError("PND: Failed to locate OpenGL ES library");
+ }
+
+ /* Store OpenGL ES library path and name */
+ SDL_strlcpy(_this->gl_config.driver_path, path,
+ SDL_arraysize(_this->gl_config.driver_path));
+
+ /* New OpenGL ES library is loaded */
+ return 0;
+}
+
+void *
+PND_gl_getprocaddres(_THIS, const char *proc)
+{
+ void *function_address;
+
+ /* Try to get function address through the egl interface */
+ function_address = eglGetProcAddress(proc);
+ if (function_address != NULL) {
+ return function_address;
+ }
+
+ /* Then try to get function in the OpenGL ES library */
+ if (_this->gl_config.dll_handle) {
+ function_address =
+ SDL_LoadFunction(_this->gl_config.dll_handle, proc);
+ if (function_address != NULL) {
+ return function_address;
+ }
+ }
+
+ /* Failed to get GL ES function address pointer */
+ SDL_SetError("PND: Cannot locate OpenGL ES function name");
+ return NULL;
+}
+
+void
+PND_gl_unloadlibrary(_THIS)
+{
+ SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+
+ if (phdata->egl_initialized == SDL_TRUE) {
+ /* Unload OpenGL ES library */
+ if (_this->gl_config.dll_handle) {
+ SDL_UnloadObject(_this->gl_config.dll_handle);
+ _this->gl_config.dll_handle = NULL;
+ }
+ } else {
+ SDL_SetError("PND: GF initialization failed, no OpenGL ES support");
+ }
+}
+
+SDL_GLContext
+PND_gl_createcontext(_THIS, SDL_Window * window)
+{
+ SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+ SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+ EGLBoolean status;
+ EGLint configs;
+ uint32_t attr_pos;
+ EGLint attr_value;
+ EGLint cit;
+
+ /* Check if EGL was initialized */
+ if (phdata->egl_initialized != SDL_TRUE) {
+ SDL_SetError("PND: EGL initialization failed, no OpenGL ES support");
+ return NULL;
+ }
+
+ /* Prepare attributes list to pass them to OpenGL ES */
+ attr_pos = 0;
+ wdata->gles_attributes[attr_pos++] = EGL_SURFACE_TYPE;
+ wdata->gles_attributes[attr_pos++] = EGL_WINDOW_BIT;
+ wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE;
+ wdata->gles_attributes[attr_pos++] = _this->gl_config.red_size;
+ wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE;
+ wdata->gles_attributes[attr_pos++] = _this->gl_config.green_size;
+ wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE;
+ wdata->gles_attributes[attr_pos++] = _this->gl_config.blue_size;
+ wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE;
+
+ /* Setup alpha size in bits */
+ if (_this->gl_config.alpha_size) {
+ wdata->gles_attributes[attr_pos++] = _this->gl_config.alpha_size;
+ } else {
+ wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+ }
+
+ /* Setup color buffer size */
+ if (_this->gl_config.buffer_size) {
+ wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
+ wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size;
+ } else {
+ wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
+ wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+ }
+
+ /* Setup depth buffer bits */
+ wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
+ wdata->gles_attributes[attr_pos++] = _this->gl_config.depth_size;
+
+ /* Setup stencil bits */
+ if (_this->gl_config.stencil_size) {
+ wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
+ wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size;
+ } else {
+ wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
+ wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+ }
+
+ /* Set number of samples in multisampling */
+ if (_this->gl_config.multisamplesamples) {
+ wdata->gles_attributes[attr_pos++] = EGL_SAMPLES;
+ wdata->gles_attributes[attr_pos++] =
+ _this->gl_config.multisamplesamples;
+ }
+
+ /* Multisample buffers, OpenGL ES 1.0 spec defines 0 or 1 buffer */
+ if (_this->gl_config.multisamplebuffers) {
+ wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS;
+ wdata->gles_attributes[attr_pos++] =
+ _this->gl_config.multisamplebuffers;
+ }
+
+ /* Finish attributes list */
+ wdata->gles_attributes[attr_pos] = EGL_NONE;
+
+ /* Request first suitable framebuffer configuration */
+ status = eglChooseConfig(phdata->egl_display, wdata->gles_attributes,
+ wdata->gles_configs, 1, &configs);
+ if (status != EGL_TRUE) {
+ SDL_SetError("PND: Can't find closest configuration for OpenGL ES");
+ return NULL;
+ }
+
+ /* Check if nothing has been found, try "don't care" settings */
+ if (configs == 0) {
+ int32_t it;
+ int32_t jt;
+ GLint depthbits[4] = { 32, 24, 16, EGL_DONT_CARE };
+
+ for (it = 0; it < 4; it++) {
+ for (jt = 16; jt >= 0; jt--) {
+ /* Don't care about color buffer bits, use what exist */
+ /* Replace previous set data with EGL_DONT_CARE */
+ attr_pos = 0;
+ wdata->gles_attributes[attr_pos++] = EGL_SURFACE_TYPE;
+ wdata->gles_attributes[attr_pos++] = EGL_WINDOW_BIT;
+ wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE;
+ wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+ wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE;
+ wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+ wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE;
+ wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+ wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE;
+ wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+ wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
+ wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+
+ /* Try to find requested or smallest depth */
+ if (_this->gl_config.depth_size) {
+ wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
+ wdata->gles_attributes[attr_pos++] = depthbits[it];
+ } else {
+ wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
+ wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+ }
+
+ if (_this->gl_config.stencil_size) {
+ wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
+ wdata->gles_attributes[attr_pos++] = jt;
+ } else {
+ wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
+ wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+ }
+
+ wdata->gles_attributes[attr_pos++] = EGL_SAMPLES;
+ wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+ wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS;
+ wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+ wdata->gles_attributes[attr_pos] = EGL_NONE;
+
+ /* Request first suitable framebuffer configuration */
+ status =
+ eglChooseConfig(phdata->egl_display,
+ wdata->gles_attributes,
+ wdata->gles_configs, 1, &configs);
+
+ if (status != EGL_TRUE) {
+ SDL_SetError
+ ("PND: Can't find closest configuration for OpenGL ES");
+ return NULL;
+ }
+ if (configs != 0) {
+ break;
+ }
+ }
+ if (configs != 0) {
+ break;
+ }
+ }
+
+ /* No available configs */
+ if (configs == 0) {
+ SDL_SetError("PND: Can't find any configuration for OpenGL ES");
+ return NULL;
+ }
+ }
+
+ /* Initialize config index */
+ wdata->gles_config = 0;
+
+ /* Now check each configuration to find out the best */
+ for (cit = 0; cit < configs; cit++) {
+ uint32_t stencil_found;
+ uint32_t depth_found;
+
+ stencil_found = 0;
+ depth_found = 0;
+
+ if (_this->gl_config.stencil_size) {
+ status =
+ eglGetConfigAttrib(phdata->egl_display,
+ wdata->gles_configs[cit], EGL_STENCIL_SIZE,
+ &attr_value);
+ if (status == EGL_TRUE) {
+ if (attr_value != 0) {
+ stencil_found = 1;
+ }
+ }
+ } else {
+ stencil_found = 1;
+ }
+
+ if (_this->gl_config.depth_size) {
+ status =
+ eglGetConfigAttrib(phdata->egl_display,
+ wdata->gles_configs[cit], EGL_DEPTH_SIZE,
+ &attr_value);
+ if (status == EGL_TRUE) {
+ if (attr_value != 0) {
+ depth_found = 1;
+ }
+ }
+ } else {
+ depth_found = 1;
+ }
+
+ /* Exit from loop if found appropriate configuration */
+ if ((depth_found != 0) && (stencil_found != 0)) {
+ break;
+ }
+ }
+
+ /* If best could not be found, use first */
+ if (cit == configs) {
+ cit = 0;
+ }
+ wdata->gles_config = cit;
+
+ /* Create OpenGL ES context */
+ wdata->gles_context =
+ eglCreateContext(phdata->egl_display,
+ wdata->gles_configs[wdata->gles_config], NULL, NULL);
+ if (wdata->gles_context == EGL_NO_CONTEXT) {
+ SDL_SetError("PND: OpenGL ES context creation has been failed");
+ return NULL;
+ }
+
+#ifdef WIZ_GLES_LITE
+ if( !hNativeWnd ) {
+ hNativeWnd = (NativeWindowType)malloc(16*1024);
+
+ if(!hNativeWnd)
+ printf( "Error: Wiz framebuffer allocatation failed\n" );
+ else
+ printf( "SDL: Wiz framebuffer allocated: %X\n", hNativeWnd );
+ }
+ else {
+ printf( "SDL: Wiz framebuffer already allocated: %X\n", hNativeWnd );
+ }
+
+ wdata->gles_surface =
+ eglCreateWindowSurface(phdata->egl_display,
+ wdata->gles_configs[wdata->gles_config],
+ hNativeWnd, NULL );
+#else
+ wdata->gles_surface =
+ eglCreateWindowSurface(phdata->egl_display,
+ wdata->gles_configs[wdata->gles_config],
+ (NativeWindowType) 0, NULL);
+#endif
+
+
+ if (wdata->gles_surface == 0) {
+ SDL_SetError("Error : eglCreateWindowSurface failed;");
+ return NULL;
+ }
+
+ /* Make just created context current */
+ status =
+ eglMakeCurrent(phdata->egl_display, wdata->gles_surface,
+ wdata->gles_surface, wdata->gles_context);
+ if (status != EGL_TRUE) {
+ /* Destroy OpenGL ES surface */
+ eglDestroySurface(phdata->egl_display, wdata->gles_surface);
+ eglDestroyContext(phdata->egl_display, wdata->gles_context);
+ wdata->gles_context = EGL_NO_CONTEXT;
+ SDL_SetError("PND: Can't set OpenGL ES context on creation");
+ return NULL;
+ }
+
+ _this->gl_config.accelerated = 1;
+
+ /* Always clear stereo enable, since OpenGL ES do not supports stereo */
+ _this->gl_config.stereo = 0;
+
+ /* Get back samples and samplebuffers configurations. Rest framebuffer */
+ /* parameters could be obtained through the OpenGL ES API */
+ status =
+ eglGetConfigAttrib(phdata->egl_display,
+ wdata->gles_configs[wdata->gles_config],
+ EGL_SAMPLES, &attr_value);
+ if (status == EGL_TRUE) {
+ _this->gl_config.multisamplesamples = attr_value;
+ }
+ status =
+ eglGetConfigAttrib(phdata->egl_display,
+ wdata->gles_configs[wdata->gles_config],
+ EGL_SAMPLE_BUFFERS, &attr_value);
+ if (status == EGL_TRUE) {
+ _this->gl_config.multisamplebuffers = attr_value;
+ }
+
+ /* Get back stencil and depth buffer sizes */
+ status =
+ eglGetConfigAttrib(phdata->egl_display,
+ wdata->gles_configs[wdata->gles_config],
+ EGL_DEPTH_SIZE, &attr_value);
+ if (status == EGL_TRUE) {
+ _this->gl_config.depth_size = attr_value;
+ }
+ status =
+ eglGetConfigAttrib(phdata->egl_display,
+ wdata->gles_configs[wdata->gles_config],
+ EGL_STENCIL_SIZE, &attr_value);
+ if (status == EGL_TRUE) {
+ _this->gl_config.stencil_size = attr_value;
+ }
+
+ /* Under PND OpenGL ES output can't be double buffered */
+ _this->gl_config.double_buffer = 0;
+
+ /* GL ES context was successfully created */
+ return wdata->gles_context;
+}
+
+int
+PND_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context)
+{
+ SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+ SDL_WindowData *wdata;
+ EGLBoolean status;
+
+ if (phdata->egl_initialized != SDL_TRUE) {
+ return SDL_SetError("PND: GF initialization failed, no OpenGL ES support");
+ }
+
+ if ((window == NULL) && (context == NULL)) {
+ status =
+ eglMakeCurrent(phdata->egl_display, EGL_NO_SURFACE,
+ EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ if (status != EGL_TRUE) {
+ /* Failed to set current GL ES context */
+ return SDL_SetError("PND: Can't set OpenGL ES context");
+ }
+ } else {
+ wdata = (SDL_WindowData *) window->driverdata;
+ if (wdata->gles_surface == EGL_NO_SURFACE) {
+ return SDL_SetError
+ ("PND: OpenGL ES surface is not initialized for this window");
+ }
+ if (wdata->gles_context == EGL_NO_CONTEXT) {
+ return SDL_SetError
+ ("PND: OpenGL ES context is not initialized for this window");
+ }
+ if (wdata->gles_context != context) {
+ return SDL_SetError
+ ("PND: OpenGL ES context is not belong to this window");
+ }
+ status =
+ eglMakeCurrent(phdata->egl_display, wdata->gles_surface,
+ wdata->gles_surface, wdata->gles_context);
+ if (status != EGL_TRUE) {
+ /* Failed to set current GL ES context */
+ return SDL_SetError("PND: Can't set OpenGL ES context");
+ }
+ }
+ return 0;
+}
+
+int
+PND_gl_setswapinterval(_THIS, int interval)
+{
+ SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+ EGLBoolean status;
+
+ if (phdata->egl_initialized != SDL_TRUE) {
+ return SDL_SetError("PND: EGL initialization failed, no OpenGL ES support");
+ }
+
+ /* Check if OpenGL ES connection has been initialized */
+ if (phdata->egl_display != EGL_NO_DISPLAY) {
+ /* Set swap OpenGL ES interval */
+ status = eglSwapInterval(phdata->egl_display, interval);
+ if (status == EGL_TRUE) {
+ /* Return success to upper level */
+ phdata->swapinterval = interval;
+ return 0;
+ }
+ }
+
+ /* Failed to set swap interval */
+ return SDL_SetError("PND: Cannot set swap interval");
+}
+
+int
+PND_gl_getswapinterval(_THIS)
+{
+ return ((SDL_VideoData *) _this->driverdata)->swapinterval;
+}
+
+int
+PND_gl_swapwindow(_THIS, SDL_Window * window)
+{
+ SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+ SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+
+ if (phdata->egl_initialized != SDL_TRUE) {
+ return SDL_SetError("PND: GLES initialization failed, no OpenGL ES support");
+ }
+
+ /* Many applications do not uses glFinish(), so we call it for them */
+ glFinish();
+
+ /* Wait until OpenGL ES rendering is completed */
+ eglWaitGL();
+
+ eglSwapBuffers(phdata->egl_display, wdata->gles_surface);
+ return 0;
+}
+
+void
+PND_gl_deletecontext(_THIS, SDL_GLContext context)
+{
+ SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+ EGLBoolean status;
+
+ if (phdata->egl_initialized != SDL_TRUE) {
+ SDL_SetError("PND: GLES initialization failed, no OpenGL ES support");
+ return;
+ }
+
+ /* Check if OpenGL ES connection has been initialized */
+ if (phdata->egl_display != EGL_NO_DISPLAY) {
+ if (context != EGL_NO_CONTEXT) {
+ status = eglDestroyContext(phdata->egl_display, context);
+ if (status != EGL_TRUE) {
+ /* Error during OpenGL ES context destroying */
+ SDL_SetError("PND: OpenGL ES context destroy error");
+ return;
+ }
+ }
+ }
+
+#ifdef WIZ_GLES_LITE
+ if( hNativeWnd != 0 )
+ {
+ free(hNativeWnd);
+ hNativeWnd = 0;
+ printf( "SDL: Wiz framebuffer released\n" );
+ }
+#endif
+
+ return;
+}
+
+#endif /* SDL_VIDEO_DRIVER_PANDORA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/pandora/SDL_pandora.h b/src/3rdparty/SDL2/src/video/pandora/SDL_pandora.h
new file mode 100644
index 0000000..9e460e7
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/pandora/SDL_pandora.h
@@ -0,0 +1,101 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef __SDL_PANDORA_H__
+#define __SDL_PANDORA_H__
+
+#include <GLES/egl.h>
+
+#include "../../SDL_internal.h"
+#include "../SDL_sysvideo.h"
+
+typedef struct SDL_VideoData
+{
+ SDL_bool egl_initialized; /* OpenGL ES device initialization status */
+ EGLDisplay egl_display; /* OpenGL ES display connection */
+ uint32_t egl_refcount; /* OpenGL ES reference count */
+ uint32_t swapinterval; /* OpenGL ES default swap interval */
+
+} SDL_VideoData;
+
+
+typedef struct SDL_DisplayData
+{
+
+} SDL_DisplayData;
+
+
+typedef struct SDL_WindowData
+{
+ SDL_bool uses_gles; /* if true window must support OpenGL ES */
+
+ EGLConfig gles_configs[32];
+ EGLint gles_config; /* OpenGL ES configuration index */
+ EGLContext gles_context; /* OpenGL ES context */
+ EGLint gles_attributes[256]; /* OpenGL ES attributes for context */
+ EGLSurface gles_surface; /* OpenGL ES target rendering surface */
+
+} SDL_WindowData;
+
+
+/****************************************************************************/
+/* SDL_VideoDevice functions declaration */
+/****************************************************************************/
+
+/* Display and window functions */
+int PND_videoinit(_THIS);
+void PND_videoquit(_THIS);
+void PND_getdisplaymodes(_THIS, SDL_VideoDisplay * display);
+int PND_setdisplaymode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
+int PND_createwindow(_THIS, SDL_Window * window);
+int PND_createwindowfrom(_THIS, SDL_Window * window, const void *data);
+void PND_setwindowtitle(_THIS, SDL_Window * window);
+void PND_setwindowicon(_THIS, SDL_Window * window, SDL_Surface * icon);
+void PND_setwindowposition(_THIS, SDL_Window * window);
+void PND_setwindowsize(_THIS, SDL_Window * window);
+void PND_showwindow(_THIS, SDL_Window * window);
+void PND_hidewindow(_THIS, SDL_Window * window);
+void PND_raisewindow(_THIS, SDL_Window * window);
+void PND_maximizewindow(_THIS, SDL_Window * window);
+void PND_minimizewindow(_THIS, SDL_Window * window);
+void PND_restorewindow(_THIS, SDL_Window * window);
+void PND_setwindowgrab(_THIS, SDL_Window * window, SDL_bool grabbed);
+void PND_destroywindow(_THIS, SDL_Window * window);
+
+/* Window manager function */
+SDL_bool PND_getwindowwminfo(_THIS, SDL_Window * window,
+ struct SDL_SysWMinfo *info);
+
+/* OpenGL/OpenGL ES functions */
+int PND_gl_loadlibrary(_THIS, const char *path);
+void *PND_gl_getprocaddres(_THIS, const char *proc);
+void PND_gl_unloadlibrary(_THIS);
+SDL_GLContext PND_gl_createcontext(_THIS, SDL_Window * window);
+int PND_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+int PND_gl_setswapinterval(_THIS, int interval);
+int PND_gl_getswapinterval(_THIS);
+int PND_gl_swapwindow(_THIS, SDL_Window * window);
+void PND_gl_deletecontext(_THIS, SDL_GLContext context);
+
+
+#endif /* __SDL_PANDORA_H__ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/pandora/SDL_pandora_events.c b/src/3rdparty/SDL2/src/video/pandora/SDL_pandora_events.c
new file mode 100644
index 0000000..bff7a36
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/pandora/SDL_pandora_events.c
@@ -0,0 +1,38 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_PANDORA
+
+/* Being a null driver, there's no event stream. We just define stubs for
+ most of the API. */
+
+#include "../../events/SDL_events_c.h"
+
+void
+PND_PumpEvents(_THIS)
+{
+ /* Not implemented. */
+}
+
+#endif /* SDL_VIDEO_DRIVER_PANDORA */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/pandora/SDL_pandora_events.h b/src/3rdparty/SDL2/src/video/pandora/SDL_pandora_events.h
new file mode 100644
index 0000000..f714384
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/pandora/SDL_pandora_events.h
@@ -0,0 +1,25 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+extern void PND_PumpEvents(_THIS);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/psp/SDL_pspevents.c b/src/3rdparty/SDL2/src/video/psp/SDL_pspevents.c
new file mode 100644
index 0000000..14277b3
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/psp/SDL_pspevents.c
@@ -0,0 +1,290 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_PSP
+
+/* Being a null driver, there's no event stream. We just define stubs for
+ most of the API. */
+
+#include "SDL.h"
+#include "../../events/SDL_sysevents.h"
+#include "../../events/SDL_events_c.h"
+#include "../../events/SDL_keyboard_c.h"
+#include "SDL_pspvideo.h"
+#include "SDL_pspevents_c.h"
+#include "SDL_keyboard.h"
+#include "../../thread/SDL_systhread.h"
+#include <psphprm.h>
+
+#ifdef PSPIRKEYB
+#include <pspirkeyb.h>
+#include <pspirkeyb_rawkeys.h>
+
+#define IRKBD_CONFIG_FILE NULL /* this will take ms0:/seplugins/pspirkeyb.ini */
+
+static int irkbd_ready = 0;
+static SDL_Keycode keymap[256];
+#endif
+
+static enum PspHprmKeys hprm = 0;
+static SDL_sem *event_sem = NULL;
+static SDL_Thread *thread = NULL;
+static int running = 0;
+static struct {
+ enum PspHprmKeys id;
+ SDL_Keycode sym;
+} keymap_psp[] = {
+ { PSP_HPRM_PLAYPAUSE, SDLK_F10 },
+ { PSP_HPRM_FORWARD, SDLK_F11 },
+ { PSP_HPRM_BACK, SDLK_F12 },
+ { PSP_HPRM_VOL_UP, SDLK_F13 },
+ { PSP_HPRM_VOL_DOWN, SDLK_F14 },
+ { PSP_HPRM_HOLD, SDLK_F15 }
+};
+
+int EventUpdate(void *data)
+{
+ while (running) {
+ SDL_SemWait(event_sem);
+ sceHprmPeekCurrentKey(&hprm);
+ SDL_SemPost(event_sem);
+ /* Delay 1/60th of a second */
+ sceKernelDelayThread(1000000 / 60);
+ }
+ return 0;
+}
+
+void PSP_PumpEvents(_THIS)
+{
+ int i;
+ enum PspHprmKeys keys;
+ enum PspHprmKeys changed;
+ static enum PspHprmKeys old_keys = 0;
+ SDL_Keysym sym;
+
+ SDL_SemWait(event_sem);
+ keys = hprm;
+ SDL_SemPost(event_sem);
+
+ /* HPRM Keyboard */
+ changed = old_keys ^ keys;
+ old_keys = keys;
+ if(changed) {
+ for(i=0; i<sizeof(keymap_psp)/sizeof(keymap_psp[0]); i++) {
+ if(changed & keymap_psp[i].id) {
+ sym.scancode = keymap_psp[i].id;
+ sym.sym = keymap_psp[i].sym;
+
+ /* out of date
+ SDL_PrivateKeyboard((keys & keymap_psp[i].id) ?
+ SDL_PRESSED : SDL_RELEASED,
+ &sym);
+ */
+ SDL_SendKeyboardKey((keys & keymap_psp[i].id) ?
+ SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap_psp[i].sym));
+ }
+ }
+ }
+
+#ifdef PSPIRKEYB
+ if (irkbd_ready) {
+ unsigned char buffer[255];
+ int i, length, count;
+ SIrKeybScanCodeData *scanData;
+
+ if(pspIrKeybReadinput(buffer, &length) >= 0) {
+ if((length % sizeof(SIrKeybScanCodeData)) == 0){
+ count = length / sizeof(SIrKeybScanCodeData);
+ for( i=0; i < count; i++ ) {
+ unsigned char raw, pressed;
+ scanData=(SIrKeybScanCodeData*) buffer+i;
+ raw = scanData->raw;
+ pressed = scanData->pressed;
+ sym.scancode = raw;
+ sym.sym = keymap[raw];
+ /* not tested */
+ /* SDL_PrivateKeyboard(pressed?SDL_PRESSED:SDL_RELEASED, &sym); */
+ SDL_SendKeyboardKey((keys & keymap_psp[i].id) ?
+ SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap[raw]));
+
+ }
+ }
+ }
+ }
+#endif
+ sceKernelDelayThread(0);
+
+ return;
+}
+
+void PSP_InitOSKeymap(_THIS)
+{
+#ifdef PSPIRKEYB
+ int i;
+ for (i=0; i<SDL_TABLESIZE(keymap); ++i)
+ keymap[i] = SDLK_UNKNOWN;
+
+ keymap[KEY_ESC] = SDLK_ESCAPE;
+
+ keymap[KEY_F1] = SDLK_F1;
+ keymap[KEY_F2] = SDLK_F2;
+ keymap[KEY_F3] = SDLK_F3;
+ keymap[KEY_F4] = SDLK_F4;
+ keymap[KEY_F5] = SDLK_F5;
+ keymap[KEY_F6] = SDLK_F6;
+ keymap[KEY_F7] = SDLK_F7;
+ keymap[KEY_F8] = SDLK_F8;
+ keymap[KEY_F9] = SDLK_F9;
+ keymap[KEY_F10] = SDLK_F10;
+ keymap[KEY_F11] = SDLK_F11;
+ keymap[KEY_F12] = SDLK_F12;
+ keymap[KEY_F13] = SDLK_PRINT;
+ keymap[KEY_F14] = SDLK_PAUSE;
+
+ keymap[KEY_GRAVE] = SDLK_BACKQUOTE;
+ keymap[KEY_1] = SDLK_1;
+ keymap[KEY_2] = SDLK_2;
+ keymap[KEY_3] = SDLK_3;
+ keymap[KEY_4] = SDLK_4;
+ keymap[KEY_5] = SDLK_5;
+ keymap[KEY_6] = SDLK_6;
+ keymap[KEY_7] = SDLK_7;
+ keymap[KEY_8] = SDLK_8;
+ keymap[KEY_9] = SDLK_9;
+ keymap[KEY_0] = SDLK_0;
+ keymap[KEY_MINUS] = SDLK_MINUS;
+ keymap[KEY_EQUAL] = SDLK_EQUALS;
+ keymap[KEY_BACKSPACE] = SDLK_BACKSPACE;
+
+ keymap[KEY_TAB] = SDLK_TAB;
+ keymap[KEY_Q] = SDLK_q;
+ keymap[KEY_W] = SDLK_w;
+ keymap[KEY_E] = SDLK_e;
+ keymap[KEY_R] = SDLK_r;
+ keymap[KEY_T] = SDLK_t;
+ keymap[KEY_Y] = SDLK_y;
+ keymap[KEY_U] = SDLK_u;
+ keymap[KEY_I] = SDLK_i;
+ keymap[KEY_O] = SDLK_o;
+ keymap[KEY_P] = SDLK_p;
+ keymap[KEY_LEFTBRACE] = SDLK_LEFTBRACKET;
+ keymap[KEY_RIGHTBRACE] = SDLK_RIGHTBRACKET;
+ keymap[KEY_ENTER] = SDLK_RETURN;
+
+ keymap[KEY_CAPSLOCK] = SDLK_CAPSLOCK;
+ keymap[KEY_A] = SDLK_a;
+ keymap[KEY_S] = SDLK_s;
+ keymap[KEY_D] = SDLK_d;
+ keymap[KEY_F] = SDLK_f;
+ keymap[KEY_G] = SDLK_g;
+ keymap[KEY_H] = SDLK_h;
+ keymap[KEY_J] = SDLK_j;
+ keymap[KEY_K] = SDLK_k;
+ keymap[KEY_L] = SDLK_l;
+ keymap[KEY_SEMICOLON] = SDLK_SEMICOLON;
+ keymap[KEY_APOSTROPHE] = SDLK_QUOTE;
+ keymap[KEY_BACKSLASH] = SDLK_BACKSLASH;
+
+ keymap[KEY_Z] = SDLK_z;
+ keymap[KEY_X] = SDLK_x;
+ keymap[KEY_C] = SDLK_c;
+ keymap[KEY_V] = SDLK_v;
+ keymap[KEY_B] = SDLK_b;
+ keymap[KEY_N] = SDLK_n;
+ keymap[KEY_M] = SDLK_m;
+ keymap[KEY_COMMA] = SDLK_COMMA;
+ keymap[KEY_DOT] = SDLK_PERIOD;
+ keymap[KEY_SLASH] = SDLK_SLASH;
+
+ keymap[KEY_SPACE] = SDLK_SPACE;
+
+ keymap[KEY_UP] = SDLK_UP;
+ keymap[KEY_DOWN] = SDLK_DOWN;
+ keymap[KEY_LEFT] = SDLK_LEFT;
+ keymap[KEY_RIGHT] = SDLK_RIGHT;
+
+ keymap[KEY_HOME] = SDLK_HOME;
+ keymap[KEY_END] = SDLK_END;
+ keymap[KEY_INSERT] = SDLK_INSERT;
+ keymap[KEY_DELETE] = SDLK_DELETE;
+
+ keymap[KEY_NUMLOCK] = SDLK_NUMLOCK;
+ keymap[KEY_LEFTMETA] = SDLK_LSUPER;
+
+ keymap[KEY_KPSLASH] = SDLK_KP_DIVIDE;
+ keymap[KEY_KPASTERISK] = SDLK_KP_MULTIPLY;
+ keymap[KEY_KPMINUS] = SDLK_KP_MINUS;
+ keymap[KEY_KPPLUS] = SDLK_KP_PLUS;
+ keymap[KEY_KPDOT] = SDLK_KP_PERIOD;
+ keymap[KEY_KPEQUAL] = SDLK_KP_EQUALS;
+
+ keymap[KEY_LEFTCTRL] = SDLK_LCTRL;
+ keymap[KEY_RIGHTCTRL] = SDLK_RCTRL;
+ keymap[KEY_LEFTALT] = SDLK_LALT;
+ keymap[KEY_RIGHTALT] = SDLK_RALT;
+ keymap[KEY_LEFTSHIFT] = SDLK_LSHIFT;
+ keymap[KEY_RIGHTSHIFT] = SDLK_RSHIFT;
+#endif
+}
+
+void PSP_EventInit(_THIS)
+{
+#ifdef PSPIRKEYB
+ int outputmode = PSP_IRKBD_OUTPUT_MODE_SCANCODE;
+ int ret = pspIrKeybInit(IRKBD_CONFIG_FILE, 0);
+ if (ret == PSP_IRKBD_RESULT_OK) {
+ pspIrKeybOutputMode(outputmode);
+ irkbd_ready = 1;
+ } else {
+ irkbd_ready = 0;
+ }
+#endif
+ /* Start thread to read data */
+ if((event_sem = SDL_CreateSemaphore(1)) == NULL) {
+ SDL_SetError("Can't create input semaphore");
+ return;
+ }
+ running = 1;
+ if((thread = SDL_CreateThreadInternal(EventUpdate, "PSPInputThread", 4096, NULL)) == NULL) {
+ SDL_SetError("Can't create input thread");
+ return;
+ }
+}
+
+void PSP_EventQuit(_THIS)
+{
+ running = 0;
+ SDL_WaitThread(thread, NULL);
+ SDL_DestroySemaphore(event_sem);
+#ifdef PSPIRKEYB
+ if (irkbd_ready) {
+ pspIrKeybFinish();
+ irkbd_ready = 0;
+ }
+#endif
+}
+
+/* end of SDL_pspevents.c ... */
+
+#endif /* SDL_VIDEO_DRIVER_PSP */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/psp/SDL_pspevents_c.h b/src/3rdparty/SDL2/src/video/psp/SDL_pspevents_c.h
new file mode 100644
index 0000000..e98beb4
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/psp/SDL_pspevents_c.h
@@ -0,0 +1,31 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "SDL_pspvideo.h"
+
+/* Variables and functions exported by SDL_sysevents.c to other parts
+ of the native video subsystem (SDL_sysvideo.c)
+*/
+extern void PSP_InitOSKeymap(_THIS);
+extern void PSP_PumpEvents(_THIS);
+
+/* end of SDL_pspevents_c.h ... */
+
diff --git a/src/3rdparty/SDL2/src/video/psp/SDL_pspgl.c b/src/3rdparty/SDL2/src/video/psp/SDL_pspgl.c
new file mode 100644
index 0000000..644fb34
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/psp/SDL_pspgl.c
@@ -0,0 +1,210 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_PSP
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "SDL_error.h"
+#include "SDL_pspvideo.h"
+#include "SDL_pspgl_c.h"
+
+/*****************************************************************************/
+/* SDL OpenGL/OpenGL ES functions */
+/*****************************************************************************/
+#define EGLCHK(stmt) \
+ do { \
+ EGLint err; \
+ \
+ stmt; \
+ err = eglGetError(); \
+ if (err != EGL_SUCCESS) { \
+ SDL_SetError("EGL error %d", err); \
+ return 0; \
+ } \
+ } while (0)
+
+int
+PSP_GL_LoadLibrary(_THIS, const char *path)
+{
+ return 0;
+}
+
+/* pspgl doesn't provide this call, so stub it out since SDL requires it.
+#define GLSTUB(func,params) void func params {}
+
+GLSTUB(glOrtho,(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top,
+ GLdouble zNear, GLdouble zFar))
+*/
+void *
+PSP_GL_GetProcAddress(_THIS, const char *proc)
+{
+ return eglGetProcAddress(proc);
+}
+
+void
+PSP_GL_UnloadLibrary(_THIS)
+{
+ eglTerminate(_this->gl_data->display);
+}
+
+static EGLint width = 480;
+static EGLint height = 272;
+
+SDL_GLContext
+PSP_GL_CreateContext(_THIS, SDL_Window * window)
+{
+
+ SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+
+ EGLint attribs[32];
+ EGLDisplay display;
+ EGLContext context;
+ EGLSurface surface;
+ EGLConfig config;
+ EGLint num_configs;
+ int i;
+
+
+ /* EGL init taken from glutCreateWindow() in PSPGL's glut.c. */
+ EGLCHK(display = eglGetDisplay(0));
+ EGLCHK(eglInitialize(display, NULL, NULL));
+ wdata->uses_gles = SDL_TRUE;
+ window->flags |= SDL_WINDOW_FULLSCREEN;
+
+ /* Setup the config based on SDL's current values. */
+ i = 0;
+ attribs[i++] = EGL_RED_SIZE;
+ attribs[i++] = _this->gl_config.red_size;
+ attribs[i++] = EGL_GREEN_SIZE;
+ attribs[i++] = _this->gl_config.green_size;
+ attribs[i++] = EGL_BLUE_SIZE;
+ attribs[i++] = _this->gl_config.blue_size;
+ attribs[i++] = EGL_DEPTH_SIZE;
+ attribs[i++] = _this->gl_config.depth_size;
+
+ if (_this->gl_config.alpha_size)
+ {
+ attribs[i++] = EGL_ALPHA_SIZE;
+ attribs[i++] = _this->gl_config.alpha_size;
+ }
+ if (_this->gl_config.stencil_size)
+ {
+ attribs[i++] = EGL_STENCIL_SIZE;
+ attribs[i++] = _this->gl_config.stencil_size;
+ }
+
+ attribs[i++] = EGL_NONE;
+
+ EGLCHK(eglChooseConfig(display, attribs, &config, 1, &num_configs));
+
+ if (num_configs == 0)
+ {
+ SDL_SetError("No valid EGL configs for requested mode");
+ return 0;
+ }
+
+ EGLCHK(eglGetConfigAttrib(display, config, EGL_WIDTH, &width));
+ EGLCHK(eglGetConfigAttrib(display, config, EGL_HEIGHT, &height));
+
+ EGLCHK(context = eglCreateContext(display, config, NULL, NULL));
+ EGLCHK(surface = eglCreateWindowSurface(display, config, 0, NULL));
+ EGLCHK(eglMakeCurrent(display, surface, surface, context));
+
+ _this->gl_data->display = display;
+ _this->gl_data->context = context;
+ _this->gl_data->surface = surface;
+
+
+ return context;
+}
+
+int
+PSP_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
+{
+ if (!eglMakeCurrent(_this->gl_data->display, _this->gl_data->surface,
+ _this->gl_data->surface, _this->gl_data->context))
+ {
+ return SDL_SetError("Unable to make EGL context current");
+ }
+ return 0;
+}
+
+int
+PSP_GL_SetSwapInterval(_THIS, int interval)
+{
+ EGLBoolean status;
+ status = eglSwapInterval(_this->gl_data->display, interval);
+ if (status == EGL_TRUE) {
+ /* Return success to upper level */
+ _this->gl_data->swapinterval = interval;
+ return 0;
+ }
+ /* Failed to set swap interval */
+ return SDL_SetError("Unable to set the EGL swap interval");
+}
+
+int
+PSP_GL_GetSwapInterval(_THIS)
+{
+ return _this->gl_data->swapinterval;
+}
+
+int
+PSP_GL_SwapWindow(_THIS, SDL_Window * window)
+{
+ if (!eglSwapBuffers(_this->gl_data->display, _this->gl_data->surface)) {
+ return SDL_SetError("eglSwapBuffers() failed");
+ }
+ return 0;
+}
+
+void
+PSP_GL_DeleteContext(_THIS, SDL_GLContext context)
+{
+ SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+ EGLBoolean status;
+
+ if (phdata->egl_initialized != SDL_TRUE) {
+ SDL_SetError("PSP: GLES initialization failed, no OpenGL ES support");
+ return;
+ }
+
+ /* Check if OpenGL ES connection has been initialized */
+ if (_this->gl_data->display != EGL_NO_DISPLAY) {
+ if (context != EGL_NO_CONTEXT) {
+ status = eglDestroyContext(_this->gl_data->display, context);
+ if (status != EGL_TRUE) {
+ /* Error during OpenGL ES context destroying */
+ SDL_SetError("PSP: OpenGL ES context destroy error");
+ return;
+ }
+ }
+ }
+
+ return;
+}
+
+#endif /* SDL_VIDEO_DRIVER_PSP */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/psp/SDL_pspgl_c.h b/src/3rdparty/SDL2/src/video/psp/SDL_pspgl_c.h
new file mode 100644
index 0000000..49300fb
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/psp/SDL_pspgl_c.h
@@ -0,0 +1,54 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_pspgl_c_h_
+#define SDL_pspgl_c_h_
+
+
+#include <GLES/egl.h>
+#include <GLES/gl.h>
+
+#include "SDL_pspvideo.h"
+
+
+typedef struct SDL_GLDriverData {
+ EGLDisplay display;
+ EGLContext context;
+ EGLSurface surface;
+ uint32_t swapinterval;
+}SDL_GLDriverData;
+
+extern void * PSP_GL_GetProcAddress(_THIS, const char *proc);
+extern int PSP_GL_MakeCurrent(_THIS,SDL_Window * window, SDL_GLContext context);
+extern void PSP_GL_SwapBuffers(_THIS);
+
+extern int PSP_GL_SwapWindow(_THIS, SDL_Window * window);
+extern SDL_GLContext PSP_GL_CreateContext(_THIS, SDL_Window * window);
+
+extern int PSP_GL_LoadLibrary(_THIS, const char *path);
+extern void PSP_GL_UnloadLibrary(_THIS);
+extern int PSP_GL_SetSwapInterval(_THIS, int interval);
+extern int PSP_GL_GetSwapInterval(_THIS);
+
+
+#endif /* SDL_pspgl_c_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/psp/SDL_pspmouse.c b/src/3rdparty/SDL2/src/video/psp/SDL_pspmouse.c
new file mode 100644
index 0000000..bd34dfa
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/psp/SDL_pspmouse.c
@@ -0,0 +1,41 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_PSP
+
+#include <stdio.h>
+
+#include "SDL_error.h"
+#include "SDL_mouse.h"
+#include "../../events/SDL_events_c.h"
+
+#include "SDL_pspmouse_c.h"
+
+
+/* The implementation dependent data for the window manager cursor */
+struct WMcursor {
+ int unused;
+};
+
+#endif /* SDL_VIDEO_DRIVER_PSP */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/psp/SDL_pspmouse_c.h b/src/3rdparty/SDL2/src/video/psp/SDL_pspmouse_c.h
new file mode 100644
index 0000000..2d2640e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/psp/SDL_pspmouse_c.h
@@ -0,0 +1,24 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "SDL_pspvideo.h"
+
+/* Functions to be exported */
diff --git a/src/3rdparty/SDL2/src/video/psp/SDL_pspvideo.c b/src/3rdparty/SDL2/src/video/psp/SDL_pspvideo.c
new file mode 100644
index 0000000..8231779
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/psp/SDL_pspvideo.c
@@ -0,0 +1,333 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_PSP
+
+/* SDL internals */
+#include "../SDL_sysvideo.h"
+#include "SDL_version.h"
+#include "SDL_syswm.h"
+#include "SDL_loadso.h"
+#include "SDL_events.h"
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_keyboard_c.h"
+
+
+
+/* PSP declarations */
+#include "SDL_pspvideo.h"
+#include "SDL_pspevents_c.h"
+#include "SDL_pspgl_c.h"
+
+/* unused
+static SDL_bool PSP_initialized = SDL_FALSE;
+*/
+static int
+PSP_Available(void)
+{
+ return 1;
+}
+
+static void
+PSP_Destroy(SDL_VideoDevice * device)
+{
+/* SDL_VideoData *phdata = (SDL_VideoData *) device->driverdata; */
+
+ if (device->driverdata != NULL) {
+ device->driverdata = NULL;
+ }
+}
+
+static SDL_VideoDevice *
+PSP_Create()
+{
+ SDL_VideoDevice *device;
+ SDL_VideoData *phdata;
+ SDL_GLDriverData *gldata;
+ int status;
+
+ /* Check if PSP could be initialized */
+ status = PSP_Available();
+ if (status == 0) {
+ /* PSP could not be used */
+ return NULL;
+ }
+
+ /* Initialize SDL_VideoDevice structure */
+ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (device == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ /* Initialize internal PSP specific data */
+ phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
+ if (phdata == NULL) {
+ SDL_OutOfMemory();
+ SDL_free(device);
+ return NULL;
+ }
+
+ gldata = (SDL_GLDriverData *) SDL_calloc(1, sizeof(SDL_GLDriverData));
+ if (gldata == NULL) {
+ SDL_OutOfMemory();
+ SDL_free(device);
+ SDL_free(phdata);
+ return NULL;
+ }
+ device->gl_data = gldata;
+
+ device->driverdata = phdata;
+
+ phdata->egl_initialized = SDL_TRUE;
+
+
+ /* Setup amount of available displays */
+ device->num_displays = 0;
+
+ /* Set device free function */
+ device->free = PSP_Destroy;
+
+ /* Setup all functions which we can handle */
+ device->VideoInit = PSP_VideoInit;
+ device->VideoQuit = PSP_VideoQuit;
+ device->GetDisplayModes = PSP_GetDisplayModes;
+ device->SetDisplayMode = PSP_SetDisplayMode;
+ device->CreateSDLWindow = PSP_CreateWindow;
+ device->CreateSDLWindowFrom = PSP_CreateWindowFrom;
+ device->SetWindowTitle = PSP_SetWindowTitle;
+ device->SetWindowIcon = PSP_SetWindowIcon;
+ device->SetWindowPosition = PSP_SetWindowPosition;
+ device->SetWindowSize = PSP_SetWindowSize;
+ device->ShowWindow = PSP_ShowWindow;
+ device->HideWindow = PSP_HideWindow;
+ device->RaiseWindow = PSP_RaiseWindow;
+ device->MaximizeWindow = PSP_MaximizeWindow;
+ device->MinimizeWindow = PSP_MinimizeWindow;
+ device->RestoreWindow = PSP_RestoreWindow;
+ device->SetWindowGrab = PSP_SetWindowGrab;
+ device->DestroyWindow = PSP_DestroyWindow;
+#if 0
+ device->GetWindowWMInfo = PSP_GetWindowWMInfo;
+#endif
+ device->GL_LoadLibrary = PSP_GL_LoadLibrary;
+ device->GL_GetProcAddress = PSP_GL_GetProcAddress;
+ device->GL_UnloadLibrary = PSP_GL_UnloadLibrary;
+ device->GL_CreateContext = PSP_GL_CreateContext;
+ device->GL_MakeCurrent = PSP_GL_MakeCurrent;
+ device->GL_SetSwapInterval = PSP_GL_SetSwapInterval;
+ device->GL_GetSwapInterval = PSP_GL_GetSwapInterval;
+ device->GL_SwapWindow = PSP_GL_SwapWindow;
+ device->GL_DeleteContext = PSP_GL_DeleteContext;
+ device->HasScreenKeyboardSupport = PSP_HasScreenKeyboardSupport;
+ device->ShowScreenKeyboard = PSP_ShowScreenKeyboard;
+ device->HideScreenKeyboard = PSP_HideScreenKeyboard;
+ device->IsScreenKeyboardShown = PSP_IsScreenKeyboardShown;
+
+ device->PumpEvents = PSP_PumpEvents;
+
+ return device;
+}
+
+VideoBootStrap PSP_bootstrap = {
+ "PSP",
+ "PSP Video Driver",
+ PSP_Available,
+ PSP_Create
+};
+
+/*****************************************************************************/
+/* SDL Video and Display initialization/handling functions */
+/*****************************************************************************/
+int
+PSP_VideoInit(_THIS)
+{
+ SDL_VideoDisplay display;
+ SDL_DisplayMode current_mode;
+
+ SDL_zero(current_mode);
+
+ current_mode.w = 480;
+ current_mode.h = 272;
+
+ current_mode.refresh_rate = 60;
+ /* 32 bpp for default */
+ current_mode.format = SDL_PIXELFORMAT_ABGR8888;
+
+ current_mode.driverdata = NULL;
+
+ SDL_zero(display);
+ display.desktop_mode = current_mode;
+ display.current_mode = current_mode;
+ display.driverdata = NULL;
+
+ SDL_AddVideoDisplay(&display);
+
+ return 1;
+}
+
+void
+PSP_VideoQuit(_THIS)
+{
+
+}
+
+void
+PSP_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
+{
+
+}
+
+int
+PSP_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
+{
+ return 0;
+}
+#define EGLCHK(stmt) \
+ do { \
+ EGLint err; \
+ \
+ stmt; \
+ err = eglGetError(); \
+ if (err != EGL_SUCCESS) { \
+ SDL_SetError("EGL error %d", err); \
+ return 0; \
+ } \
+ } while (0)
+
+int
+PSP_CreateWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *wdata;
+
+ /* Allocate window internal data */
+ wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
+ if (wdata == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ /* Setup driver data for this window */
+ window->driverdata = wdata;
+
+
+ /* Window has been successfully created */
+ return 0;
+}
+
+int
+PSP_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
+{
+ return SDL_Unsupported();
+}
+
+void
+PSP_SetWindowTitle(_THIS, SDL_Window * window)
+{
+}
+void
+PSP_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
+{
+}
+void
+PSP_SetWindowPosition(_THIS, SDL_Window * window)
+{
+}
+void
+PSP_SetWindowSize(_THIS, SDL_Window * window)
+{
+}
+void
+PSP_ShowWindow(_THIS, SDL_Window * window)
+{
+}
+void
+PSP_HideWindow(_THIS, SDL_Window * window)
+{
+}
+void
+PSP_RaiseWindow(_THIS, SDL_Window * window)
+{
+}
+void
+PSP_MaximizeWindow(_THIS, SDL_Window * window)
+{
+}
+void
+PSP_MinimizeWindow(_THIS, SDL_Window * window)
+{
+}
+void
+PSP_RestoreWindow(_THIS, SDL_Window * window)
+{
+}
+void
+PSP_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
+{
+
+}
+void
+PSP_DestroyWindow(_THIS, SDL_Window * window)
+{
+}
+
+/*****************************************************************************/
+/* SDL Window Manager function */
+/*****************************************************************************/
+#if 0
+SDL_bool
+PSP_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
+{
+ if (info->version.major <= SDL_MAJOR_VERSION) {
+ return SDL_TRUE;
+ } else {
+ SDL_SetError("Application not compiled with SDL %d.%d",
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+ return SDL_FALSE;
+ }
+
+ /* Failed to get window manager information */
+ return SDL_FALSE;
+}
+#endif
+
+
+/* TO Write Me */
+SDL_bool PSP_HasScreenKeyboardSupport(_THIS)
+{
+ return SDL_FALSE;
+}
+void PSP_ShowScreenKeyboard(_THIS, SDL_Window *window)
+{
+}
+void PSP_HideScreenKeyboard(_THIS, SDL_Window *window)
+{
+}
+SDL_bool PSP_IsScreenKeyboardShown(_THIS, SDL_Window *window)
+{
+ return SDL_FALSE;
+}
+
+
+#endif /* SDL_VIDEO_DRIVER_PSP */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/psp/SDL_pspvideo.h b/src/3rdparty/SDL2/src/video/psp/SDL_pspvideo.h
new file mode 100644
index 0000000..741bad1
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/psp/SDL_pspvideo.h
@@ -0,0 +1,102 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_pspvideo_h_
+#define SDL_pspvideo_h_
+
+#include <GLES/egl.h>
+
+#include "../../SDL_internal.h"
+#include "../SDL_sysvideo.h"
+
+typedef struct SDL_VideoData
+{
+ SDL_bool egl_initialized; /* OpenGL ES device initialization status */
+ uint32_t egl_refcount; /* OpenGL ES reference count */
+
+
+
+} SDL_VideoData;
+
+
+typedef struct SDL_DisplayData
+{
+
+} SDL_DisplayData;
+
+
+typedef struct SDL_WindowData
+{
+ SDL_bool uses_gles; /* if true window must support OpenGL ES */
+
+} SDL_WindowData;
+
+
+
+
+/****************************************************************************/
+/* SDL_VideoDevice functions declaration */
+/****************************************************************************/
+
+/* Display and window functions */
+int PSP_VideoInit(_THIS);
+void PSP_VideoQuit(_THIS);
+void PSP_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
+int PSP_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
+int PSP_CreateWindow(_THIS, SDL_Window * window);
+int PSP_CreateWindowFrom(_THIS, SDL_Window * window, const void *data);
+void PSP_SetWindowTitle(_THIS, SDL_Window * window);
+void PSP_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
+void PSP_SetWindowPosition(_THIS, SDL_Window * window);
+void PSP_SetWindowSize(_THIS, SDL_Window * window);
+void PSP_ShowWindow(_THIS, SDL_Window * window);
+void PSP_HideWindow(_THIS, SDL_Window * window);
+void PSP_RaiseWindow(_THIS, SDL_Window * window);
+void PSP_MaximizeWindow(_THIS, SDL_Window * window);
+void PSP_MinimizeWindow(_THIS, SDL_Window * window);
+void PSP_RestoreWindow(_THIS, SDL_Window * window);
+void PSP_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
+void PSP_DestroyWindow(_THIS, SDL_Window * window);
+
+/* Window manager function */
+SDL_bool PSP_GetWindowWMInfo(_THIS, SDL_Window * window,
+ struct SDL_SysWMinfo *info);
+
+/* OpenGL/OpenGL ES functions */
+int PSP_GL_LoadLibrary(_THIS, const char *path);
+void *PSP_GL_GetProcAddress(_THIS, const char *proc);
+void PSP_GL_UnloadLibrary(_THIS);
+SDL_GLContext PSP_GL_CreateContext(_THIS, SDL_Window * window);
+int PSP_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+int PSP_GL_SetSwapInterval(_THIS, int interval);
+int PSP_GL_GetSwapInterval(_THIS);
+int PSP_GL_SwapWindow(_THIS, SDL_Window * window);
+void PSP_GL_DeleteContext(_THIS, SDL_GLContext context);
+
+/* PSP on screen keyboard */
+SDL_bool PSP_HasScreenKeyboardSupport(_THIS);
+void PSP_ShowScreenKeyboard(_THIS, SDL_Window *window);
+void PSP_HideScreenKeyboard(_THIS, SDL_Window *window);
+SDL_bool PSP_IsScreenKeyboardShown(_THIS, SDL_Window *window);
+
+#endif /* SDL_pspvideo_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/qnx/gl.c b/src/3rdparty/SDL2/src/video/qnx/gl.c
new file mode 100644
index 0000000..19e1bd4
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/qnx/gl.c
@@ -0,0 +1,285 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 2017 BlackBerry Limited
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+#include "sdl_qnx.h"
+
+static EGLDisplay egl_disp;
+
+/**
+ * Detertmines the pixel format to use based on the current display and EGL
+ * configuration.
+ * @param egl_conf EGL configuration to use
+ * @return A SCREEN_FORMAT* constant for the pixel format to use
+ */
+static int
+chooseFormat(EGLConfig egl_conf)
+{
+ EGLint buffer_bit_depth;
+ EGLint alpha_bit_depth;
+
+ eglGetConfigAttrib(egl_disp, egl_conf, EGL_BUFFER_SIZE, &buffer_bit_depth);
+ eglGetConfigAttrib(egl_disp, egl_conf, EGL_ALPHA_SIZE, &alpha_bit_depth);
+
+ switch (buffer_bit_depth) {
+ case 32:
+ return SCREEN_FORMAT_RGBX8888;
+ case 24:
+ return SCREEN_FORMAT_RGB888;
+ case 16:
+ switch (alpha_bit_depth) {
+ case 4:
+ return SCREEN_FORMAT_RGBX4444;
+ case 1:
+ return SCREEN_FORMAT_RGBA5551;
+ default:
+ return SCREEN_FORMAT_RGB565;
+ }
+ default:
+ return 0;
+ }
+}
+
+/**
+ * Enumerates the supported EGL configurations and chooses a suitable one.
+ * @param[out] pconf The chosen configuration
+ * @param[out] pformat The chosen pixel format
+ * @return 0 if successful, -1 on error
+ */
+int
+glGetConfig(EGLConfig *pconf, int *pformat)
+{
+ EGLConfig egl_conf = (EGLConfig)0;
+ EGLConfig *egl_configs;
+ EGLint egl_num_configs;
+ EGLint val;
+ EGLBoolean rc;
+ EGLint i;
+
+ // Determine the numbfer of configurations.
+ rc = eglGetConfigs(egl_disp, NULL, 0, &egl_num_configs);
+ if (rc != EGL_TRUE) {
+ return -1;
+ }
+
+ if (egl_num_configs == 0) {
+ return -1;
+ }
+
+ // Allocate enough memory for all configurations.
+ egl_configs = malloc(egl_num_configs * sizeof(*egl_configs));
+ if (egl_configs == NULL) {
+ return -1;
+ }
+
+ // Get the list of configurations.
+ rc = eglGetConfigs(egl_disp, egl_configs, egl_num_configs,
+ &egl_num_configs);
+ if (rc != EGL_TRUE) {
+ free(egl_configs);
+ return -1;
+ }
+
+ // Find a good configuration.
+ for (i = 0; i < egl_num_configs; i++) {
+ eglGetConfigAttrib(egl_disp, egl_configs[i], EGL_SURFACE_TYPE, &val);
+ if (!(val & EGL_WINDOW_BIT)) {
+ continue;
+ }
+
+ eglGetConfigAttrib(egl_disp, egl_configs[i], EGL_RENDERABLE_TYPE, &val);
+ if (!(val & EGL_OPENGL_ES2_BIT)) {
+ continue;
+ }
+
+ eglGetConfigAttrib(egl_disp, egl_configs[i], EGL_DEPTH_SIZE, &val);
+ if (val == 0) {
+ continue;
+ }
+
+ egl_conf = egl_configs[i];
+ break;
+ }
+
+ free(egl_configs);
+ *pconf = egl_conf;
+ *pformat = chooseFormat(egl_conf);
+
+ return 0;
+}
+
+/**
+ * Initializes the EGL library.
+ * @param _THIS
+ * @param name unused
+ * @return 0 if successful, -1 on error
+ */
+int
+glLoadLibrary(_THIS, const char *name)
+{
+ EGLNativeDisplayType disp_id = EGL_DEFAULT_DISPLAY;
+
+ egl_disp = eglGetDisplay(disp_id);
+ if (egl_disp == EGL_NO_DISPLAY) {
+ return -1;
+ }
+
+ if (eglInitialize(egl_disp, NULL, NULL) == EGL_FALSE) {
+ return -1;
+ }
+
+ return 0;
+}
+
+/**
+ * Finds the address of an EGL extension function.
+ * @param proc Function name
+ * @return Function address
+ */
+void *
+glGetProcAddress(_THIS, const char *proc)
+{
+ return eglGetProcAddress(proc);
+}
+
+/**
+ * Associates the given window with the necessary EGL structures for drawing and
+ * displaying content.
+ * @param _THIS
+ * @param window The SDL window to create the context for
+ * @return A pointer to the created context, if successful, NULL on error
+ */
+SDL_GLContext
+glCreateContext(_THIS, SDL_Window *window)
+{
+ window_impl_t *impl = (window_impl_t *)window->driverdata;
+ EGLContext context;
+ EGLSurface surface;
+
+ struct {
+ EGLint client_version[2];
+ EGLint none;
+ } egl_ctx_attr = {
+ .client_version = { EGL_CONTEXT_CLIENT_VERSION, 2 },
+ .none = EGL_NONE
+ };
+
+ struct {
+ EGLint render_buffer[2];
+ EGLint none;
+ } egl_surf_attr = {
+ .render_buffer = { EGL_RENDER_BUFFER, EGL_BACK_BUFFER },
+ .none = EGL_NONE
+ };
+
+ context = eglCreateContext(egl_disp, impl->conf, EGL_NO_CONTEXT,
+ (EGLint *)&egl_ctx_attr);
+ if (context == EGL_NO_CONTEXT) {
+ return NULL;
+ }
+
+ surface = eglCreateWindowSurface(egl_disp, impl->conf, impl->window,
+ (EGLint *)&egl_surf_attr);
+ if (surface == EGL_NO_SURFACE) {
+ return NULL;
+ }
+
+ eglMakeCurrent(egl_disp, surface, surface, context);
+
+ impl->surface = surface;
+ return context;
+}
+
+/**
+ * Sets a new value for the number of frames to display before swapping buffers.
+ * @param _THIS
+ * @param interval New interval value
+ * @return 0 if successful, -1 on error
+ */
+int
+glSetSwapInterval(_THIS, int interval)
+{
+ if (eglSwapInterval(egl_disp, interval) != EGL_TRUE) {
+ return -1;
+ }
+
+ return 0;
+}
+
+/**
+ * Swaps the EGL buffers associated with the given window
+ * @param _THIS
+ * @param window Window to swap buffers for
+ * @return 0 if successful, -1 on error
+ */
+int
+glSwapWindow(_THIS, SDL_Window *window)
+{
+ /* !!! FIXME: should we migrate this all over to use SDL_egl.c? */
+ window_impl_t *impl = (window_impl_t *)window->driverdata;
+ return eglSwapBuffers(egl_disp, impl->surface) == EGL_TRUE ? 0 : -1;
+}
+
+/**
+ * Makes the given context the current one for drawing operations.
+ * @param _THIS
+ * @param window SDL window associated with the context (maybe NULL)
+ * @param context The context to activate
+ * @return 0 if successful, -1 on error
+ */
+int
+glMakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
+{
+ window_impl_t *impl;
+ EGLSurface surface = NULL;
+
+ if (window) {
+ impl = (window_impl_t *)window->driverdata;
+ surface = impl->surface;
+ }
+
+ if (eglMakeCurrent(egl_disp, surface, surface, context) != EGL_TRUE) {
+ return -1;
+ }
+
+ return 0;
+}
+
+/**
+ * Destroys a context.
+ * @param _THIS
+ * @param context The context to destroy
+ */
+void
+glDeleteContext(_THIS, SDL_GLContext context)
+{
+ eglDestroyContext(egl_disp, context);
+}
+
+/**
+ * Terminates access to the EGL library.
+ * @param _THIS
+ */
+void
+glUnloadLibrary(_THIS)
+{
+ eglTerminate(egl_disp);
+}
diff --git a/src/3rdparty/SDL2/src/video/qnx/keyboard.c b/src/3rdparty/SDL2/src/video/qnx/keyboard.c
new file mode 100644
index 0000000..86c6395
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/qnx/keyboard.c
@@ -0,0 +1,133 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 2017 BlackBerry Limited
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+#include "../../events/SDL_keyboard_c.h"
+#include "SDL_scancode.h"
+#include "SDL_events.h"
+#include "sdl_qnx.h"
+#include <sys/keycodes.h>
+
+/**
+ * A map thta translates Screen key names to SDL scan codes.
+ * This map is incomplete, but should include most major keys.
+ */
+static int key_to_sdl[] = {
+ [KEYCODE_SPACE] = SDL_SCANCODE_SPACE,
+ [KEYCODE_APOSTROPHE] = SDL_SCANCODE_APOSTROPHE,
+ [KEYCODE_COMMA] = SDL_SCANCODE_COMMA,
+ [KEYCODE_MINUS] = SDL_SCANCODE_MINUS,
+ [KEYCODE_PERIOD] = SDL_SCANCODE_PERIOD,
+ [KEYCODE_SLASH] = SDL_SCANCODE_SLASH,
+ [KEYCODE_ZERO] = SDL_SCANCODE_0,
+ [KEYCODE_ONE] = SDL_SCANCODE_1,
+ [KEYCODE_TWO] = SDL_SCANCODE_2,
+ [KEYCODE_THREE] = SDL_SCANCODE_3,
+ [KEYCODE_FOUR] = SDL_SCANCODE_4,
+ [KEYCODE_FIVE] = SDL_SCANCODE_5,
+ [KEYCODE_SIX] = SDL_SCANCODE_6,
+ [KEYCODE_SEVEN] = SDL_SCANCODE_7,
+ [KEYCODE_EIGHT] = SDL_SCANCODE_8,
+ [KEYCODE_NINE] = SDL_SCANCODE_9,
+ [KEYCODE_SEMICOLON] = SDL_SCANCODE_SEMICOLON,
+ [KEYCODE_EQUAL] = SDL_SCANCODE_EQUALS,
+ [KEYCODE_LEFT_BRACKET] = SDL_SCANCODE_LEFTBRACKET,
+ [KEYCODE_BACK_SLASH] = SDL_SCANCODE_BACKSLASH,
+ [KEYCODE_RIGHT_BRACKET] = SDL_SCANCODE_RIGHTBRACKET,
+ [KEYCODE_GRAVE] = SDL_SCANCODE_GRAVE,
+ [KEYCODE_A] = SDL_SCANCODE_A,
+ [KEYCODE_B] = SDL_SCANCODE_B,
+ [KEYCODE_C] = SDL_SCANCODE_C,
+ [KEYCODE_D] = SDL_SCANCODE_D,
+ [KEYCODE_E] = SDL_SCANCODE_E,
+ [KEYCODE_F] = SDL_SCANCODE_F,
+ [KEYCODE_G] = SDL_SCANCODE_G,
+ [KEYCODE_H] = SDL_SCANCODE_H,
+ [KEYCODE_I] = SDL_SCANCODE_I,
+ [KEYCODE_J] = SDL_SCANCODE_J,
+ [KEYCODE_K] = SDL_SCANCODE_K,
+ [KEYCODE_L] = SDL_SCANCODE_L,
+ [KEYCODE_M] = SDL_SCANCODE_M,
+ [KEYCODE_N] = SDL_SCANCODE_N,
+ [KEYCODE_O] = SDL_SCANCODE_O,
+ [KEYCODE_P] = SDL_SCANCODE_P,
+ [KEYCODE_Q] = SDL_SCANCODE_Q,
+ [KEYCODE_R] = SDL_SCANCODE_R,
+ [KEYCODE_S] = SDL_SCANCODE_S,
+ [KEYCODE_T] = SDL_SCANCODE_T,
+ [KEYCODE_U] = SDL_SCANCODE_U,
+ [KEYCODE_V] = SDL_SCANCODE_V,
+ [KEYCODE_W] = SDL_SCANCODE_W,
+ [KEYCODE_X] = SDL_SCANCODE_X,
+ [KEYCODE_Y] = SDL_SCANCODE_Y,
+ [KEYCODE_Z] = SDL_SCANCODE_Z,
+ [KEYCODE_UP] = SDL_SCANCODE_UP,
+ [KEYCODE_DOWN] = SDL_SCANCODE_DOWN,
+ [KEYCODE_LEFT] = SDL_SCANCODE_LEFT,
+ [KEYCODE_PG_UP] = SDL_SCANCODE_PAGEUP,
+ [KEYCODE_PG_DOWN] = SDL_SCANCODE_PAGEDOWN,
+ [KEYCODE_RIGHT] = SDL_SCANCODE_RIGHT,
+ [KEYCODE_RETURN] = SDL_SCANCODE_RETURN,
+ [KEYCODE_TAB] = SDL_SCANCODE_TAB,
+ [KEYCODE_ESCAPE] = SDL_SCANCODE_ESCAPE,
+};
+
+/**
+ * Called from the event dispatcher when a keyboard event is encountered.
+ * Translates the event such that it can be handled by SDL.
+ * @param event Screen keyboard event
+ */
+void
+handleKeyboardEvent(screen_event_t event)
+{
+ int val;
+ SDL_Scancode scancode;
+
+ // Get the key value.
+ if (screen_get_event_property_iv(event, SCREEN_PROPERTY_SYM, &val) < 0) {
+ return;
+ }
+
+ // Skip unrecognized keys.
+ if ((val < 0) || (val >= SDL_TABLESIZE(key_to_sdl))) {
+ return;
+ }
+
+ // Translate to an SDL scan code.
+ scancode = key_to_sdl[val];
+ if (scancode == 0) {
+ return;
+ }
+
+ // Get event flags (key state).
+ if (screen_get_event_property_iv(event, SCREEN_PROPERTY_FLAGS, &val) < 0) {
+ return;
+ }
+
+ // Propagate the event to SDL.
+ // FIXME:
+ // Need to handle more key states (such as key combinations).
+ if (val & KEY_DOWN) {
+ SDL_SendKeyboardKey(SDL_PRESSED, scancode);
+ } else {
+ SDL_SendKeyboardKey(SDL_RELEASED, scancode);
+ }
+}
diff --git a/src/3rdparty/SDL2/src/video/qnx/sdl_qnx.h b/src/3rdparty/SDL2/src/video/qnx/sdl_qnx.h
new file mode 100644
index 0000000..65e0798
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/qnx/sdl_qnx.h
@@ -0,0 +1,48 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 2017 BlackBerry Limited
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef __SDL_QNX_H__
+#define __SDL_QNX_H__
+
+#include "../SDL_sysvideo.h"
+#include <screen/screen.h>
+#include <EGL/egl.h>
+
+typedef struct
+{
+ screen_window_t window;
+ EGLSurface surface;
+ EGLConfig conf;
+} window_impl_t;
+
+extern void handleKeyboardEvent(screen_event_t event);
+
+extern int glGetConfig(EGLConfig *pconf, int *pformat);
+extern int glLoadLibrary(_THIS, const char *name);
+void *glGetProcAddress(_THIS, const char *proc);
+extern SDL_GLContext glCreateContext(_THIS, SDL_Window *window);
+extern int glSetSwapInterval(_THIS, int interval);
+extern int glSwapWindow(_THIS, SDL_Window *window);
+extern int glMakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+extern void glDeleteContext(_THIS, SDL_GLContext context);
+extern void glUnloadLibrary(_THIS);
+
+#endif
diff --git a/src/3rdparty/SDL2/src/video/qnx/video.c b/src/3rdparty/SDL2/src/video/qnx/video.c
new file mode 100644
index 0000000..ff8223c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/qnx/video.c
@@ -0,0 +1,364 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 2017 BlackBerry Limited
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+#include "../SDL_sysvideo.h"
+#include "sdl_qnx.h"
+
+static screen_context_t context;
+static screen_event_t event;
+
+/**
+ * Initializes the QNX video plugin.
+ * Creates the Screen context and event handles used for all window operations
+ * by the plugin.
+ * @param _THIS
+ * @return 0 if successful, -1 on error
+ */
+static int
+videoInit(_THIS)
+{
+ SDL_VideoDisplay display;
+
+ if (screen_create_context(&context, 0) < 0) {
+ return -1;
+ }
+
+ if (screen_create_event(&event) < 0) {
+ return -1;
+ }
+
+ SDL_zero(display);
+
+ if (SDL_AddVideoDisplay(&display) < 0) {
+ return -1;
+ }
+
+ _this->num_displays = 1;
+ return 0;
+}
+
+static void
+videoQuit(_THIS)
+{
+}
+
+/**
+ * Creates a new native Screen window and associates it with the given SDL
+ * window.
+ * @param _THIS
+ * @param window SDL window to initialize
+ * @return 0 if successful, -1 on error
+ */
+static int
+createWindow(_THIS, SDL_Window *window)
+{
+ window_impl_t *impl;
+ int size[2];
+ int numbufs;
+ int format;
+ int usage;
+
+ impl = SDL_calloc(1, sizeof(*impl));
+ if (impl == NULL) {
+ return -1;
+ }
+
+ // Create a native window.
+ if (screen_create_window(&impl->window, context) < 0) {
+ goto fail;
+ }
+
+ // Set the native window's size to match the SDL window.
+ size[0] = window->w;
+ size[1] = window->h;
+
+ if (screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_SIZE,
+ size) < 0) {
+ goto fail;
+ }
+
+ if (screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_SOURCE_SIZE,
+ size) < 0) {
+ goto fail;
+ }
+
+ // Create window buffer(s).
+ if (window->flags & SDL_WINDOW_OPENGL) {
+ if (glGetConfig(&impl->conf, &format) < 0) {
+ goto fail;
+ }
+ numbufs = 2;
+
+ usage = SCREEN_USAGE_OPENGL_ES2;
+ if (screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_USAGE,
+ &usage) < 0) {
+ return -1;
+ }
+ } else {
+ format = SCREEN_FORMAT_RGBX8888;
+ numbufs = 1;
+ }
+
+ // Set pixel format.
+ if (screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_FORMAT,
+ &format) < 0) {
+ goto fail;
+ }
+
+ // Create buffer(s).
+ if (screen_create_window_buffers(impl->window, numbufs) < 0) {
+ goto fail;
+ }
+
+ window->driverdata = impl;
+ return 0;
+
+fail:
+ if (impl->window) {
+ screen_destroy_window(impl->window);
+ }
+
+ SDL_free(impl);
+ return -1;
+}
+
+/**
+ * Gets a pointer to the Screen buffer associated with the given window. Note
+ * that the buffer is actually created in createWindow().
+ * @param _THIS
+ * @param window SDL window to get the buffer for
+ * @param[out] pixles Holds a pointer to the window's buffer
+ * @param[out] format Holds the pixel format for the buffer
+ * @param[out] pitch Holds the number of bytes per line
+ * @return 0 if successful, -1 on error
+ */
+static int
+createWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format,
+ void ** pixels, int *pitch)
+{
+ window_impl_t *impl = (window_impl_t *)window->driverdata;
+ screen_buffer_t buffer;
+
+ // Get a pointer to the buffer's memory.
+ if (screen_get_window_property_pv(impl->window, SCREEN_PROPERTY_BUFFERS,
+ (void **)&buffer) < 0) {
+ return -1;
+ }
+
+ if (screen_get_buffer_property_pv(buffer, SCREEN_PROPERTY_POINTER,
+ pixels) < 0) {
+ return -1;
+ }
+
+ // Set format and pitch.
+ if (screen_get_buffer_property_iv(buffer, SCREEN_PROPERTY_STRIDE,
+ pitch) < 0) {
+ return -1;
+ }
+
+ *format = SDL_PIXELFORMAT_RGB888;
+ return 0;
+}
+
+/**
+ * Informs the window manager that the window needs to be updated.
+ * @param _THIS
+ * @param window The window to update
+ * @param rects An array of reectangular areas to update
+ * @param numrects Rect array length
+ * @return 0 if successful, -1 on error
+ */
+static int
+updateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects,
+ int numrects)
+{
+ window_impl_t *impl = (window_impl_t *)window->driverdata;
+ screen_buffer_t buffer;
+
+ if (screen_get_window_property_pv(impl->window, SCREEN_PROPERTY_BUFFERS,
+ (void **)&buffer) < 0) {
+ return -1;
+ }
+
+ screen_post_window(impl->window, buffer, numrects, (int *)rects, 0);
+ screen_flush_context(context, 0);
+ return 0;
+}
+
+/**
+ * Runs the main event loop.
+ * @param _THIS
+ */
+static void
+pumpEvents(_THIS)
+{
+ int type;
+
+ for (;;) {
+ if (screen_get_event(context, event, 0) < 0) {
+ break;
+ }
+
+ if (screen_get_event_property_iv(event, SCREEN_PROPERTY_TYPE, &type)
+ < 0) {
+ break;
+ }
+
+ if (type == SCREEN_EVENT_NONE) {
+ break;
+ }
+
+ switch (type) {
+ case SCREEN_EVENT_KEYBOARD:
+ handleKeyboardEvent(event);
+ break;
+
+ default:
+ break;
+ }
+ }
+}
+
+/**
+ * Updates the size of the native window using the geometry of the SDL window.
+ * @param _THIS
+ * @param window SDL window to update
+ */
+static void
+setWindowSize(_THIS, SDL_Window *window)
+{
+ window_impl_t *impl = (window_impl_t *)window->driverdata;
+ int size[2];
+
+ size[0] = window->w;
+ size[1] = window->h;
+
+ screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_SIZE, size);
+ screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_SOURCE_SIZE,
+ size);
+}
+
+/**
+ * Makes the native window associated with the given SDL window visible.
+ * @param _THIS
+ * @param window SDL window to update
+ */
+static void
+showWindow(_THIS, SDL_Window *window)
+{
+ window_impl_t *impl = (window_impl_t *)window->driverdata;
+ const int visible = 1;
+
+ screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_VISIBLE,
+ &visible);
+}
+
+/**
+ * Makes the native window associated with the given SDL window invisible.
+ * @param _THIS
+ * @param window SDL window to update
+ */
+static void
+hideWindow(_THIS, SDL_Window *window)
+{
+ window_impl_t *impl = (window_impl_t *)window->driverdata;
+ const int visible = 0;
+
+ screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_VISIBLE,
+ &visible);
+}
+
+/**
+ * Destroys the native window associated with the given SDL window.
+ * @param _THIS
+ * @param window SDL window that is being destroyed
+ */
+static void
+destroyWindow(_THIS, SDL_Window *window)
+{
+ window_impl_t *impl = (window_impl_t *)window->driverdata;
+
+ if (impl) {
+ screen_destroy_window(impl->window);
+ window->driverdata = NULL;
+ }
+}
+
+/**
+ * Frees the plugin object created by createDevice().
+ * @param device Plugin object to free
+ */
+static void
+deleteDevice(SDL_VideoDevice *device)
+{
+ SDL_free(device);
+}
+
+/**
+ * Creates the QNX video plugin used by SDL.
+ * @param devindex Unused
+ * @return Initialized device if successful, NULL otherwise
+ */
+static SDL_VideoDevice *
+createDevice(int devindex)
+{
+ SDL_VideoDevice *device;
+
+ device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (device == NULL) {
+ return NULL;
+ }
+
+ device->driverdata = NULL;
+ device->VideoInit = videoInit;
+ device->VideoQuit = videoQuit;
+ device->CreateSDLWindow = createWindow;
+ device->CreateWindowFramebuffer = createWindowFramebuffer;
+ device->UpdateWindowFramebuffer = updateWindowFramebuffer;
+ device->SetWindowSize = setWindowSize;
+ device->ShowWindow = showWindow;
+ device->HideWindow = hideWindow;
+ device->PumpEvents = pumpEvents;
+ device->DestroyWindow = destroyWindow;
+
+ device->GL_LoadLibrary = glLoadLibrary;
+ device->GL_GetProcAddress = glGetProcAddress;
+ device->GL_CreateContext = glCreateContext;
+ device->GL_SetSwapInterval = glSetSwapInterval;
+ device->GL_SwapWindow = glSwapWindow;
+ device->GL_MakeCurrent = glMakeCurrent;
+ device->GL_DeleteContext = glDeleteContext;
+ device->GL_UnloadLibrary = glUnloadLibrary;
+
+ device->free = deleteDevice;
+ return device;
+}
+
+static int
+available()
+{
+ return 1;
+}
+
+VideoBootStrap QNX_bootstrap = {
+ "qnx", "QNX Screen",
+ available, createDevice
+};
diff --git a/src/3rdparty/SDL2/src/video/raspberry/SDL_rpievents.c b/src/3rdparty/SDL2/src/video/raspberry/SDL_rpievents.c
new file mode 100644
index 0000000..4064355
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/raspberry/SDL_rpievents.c
@@ -0,0 +1,45 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_RPI
+
+#include "../../events/SDL_sysevents.h"
+#include "../../events/SDL_events_c.h"
+#include "../../events/SDL_keyboard_c.h"
+#include "SDL_rpivideo.h"
+#include "SDL_rpievents_c.h"
+
+#ifdef SDL_INPUT_LINUXEV
+#include "../../core/linux/SDL_evdev.h"
+#endif
+
+void RPI_PumpEvents(_THIS)
+{
+#ifdef SDL_INPUT_LINUXEV
+ SDL_EVDEV_Poll();
+#endif
+
+}
+
+#endif /* SDL_VIDEO_DRIVER_RPI */
+
diff --git a/src/3rdparty/SDL2/src/video/raspberry/SDL_rpievents_c.h b/src/3rdparty/SDL2/src/video/raspberry/SDL_rpievents_c.h
new file mode 100644
index 0000000..8b1737f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/raspberry/SDL_rpievents_c.h
@@ -0,0 +1,31 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_rpievents_c_h_
+#define SDL_rpievents_c_h_
+
+#include "SDL_rpivideo.h"
+
+void RPI_PumpEvents(_THIS);
+void RPI_EventInit(_THIS);
+void RPI_EventQuit(_THIS);
+
+#endif /* SDL_rpievents_c_h_ */
diff --git a/src/3rdparty/SDL2/src/video/raspberry/SDL_rpimouse.c b/src/3rdparty/SDL2/src/video/raspberry/SDL_rpimouse.c
new file mode 100644
index 0000000..4ea976b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/raspberry/SDL_rpimouse.c
@@ -0,0 +1,386 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_RPI
+
+#include "SDL_assert.h"
+#include "SDL_surface.h"
+#include "SDL_hints.h"
+
+#include "SDL_rpivideo.h"
+#include "SDL_rpimouse.h"
+
+#include "../SDL_sysvideo.h"
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/default_cursor.h"
+
+/* Copied from vc_vchi_dispmanx.h which is bugged and tries to include a non existing file */
+/* Attributes changes flag mask */
+#define ELEMENT_CHANGE_LAYER (1<<0)
+#define ELEMENT_CHANGE_OPACITY (1<<1)
+#define ELEMENT_CHANGE_DEST_RECT (1<<2)
+#define ELEMENT_CHANGE_SRC_RECT (1<<3)
+#define ELEMENT_CHANGE_MASK_RESOURCE (1<<4)
+#define ELEMENT_CHANGE_TRANSFORM (1<<5)
+/* End copied from vc_vchi_dispmanx.h */
+
+static SDL_Cursor *RPI_CreateDefaultCursor(void);
+static SDL_Cursor *RPI_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y);
+static int RPI_ShowCursor(SDL_Cursor * cursor);
+static void RPI_MoveCursor(SDL_Cursor * cursor);
+static void RPI_FreeCursor(SDL_Cursor * cursor);
+static void RPI_WarpMouse(SDL_Window * window, int x, int y);
+static int RPI_WarpMouseGlobal(int x, int y);
+
+static SDL_Cursor *
+RPI_CreateDefaultCursor(void)
+{
+ return SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH, DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY);
+}
+
+/* Create a cursor from a surface */
+static SDL_Cursor *
+RPI_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
+{
+ RPI_CursorData *curdata;
+ SDL_Cursor *cursor;
+ int ret;
+ VC_RECT_T dst_rect;
+ Uint32 dummy;
+
+ SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
+ SDL_assert(surface->pitch == surface->w * 4);
+
+ cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
+ if (cursor == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ curdata = (RPI_CursorData *) SDL_calloc(1, sizeof(*curdata));
+ if (curdata == NULL) {
+ SDL_OutOfMemory();
+ SDL_free(cursor);
+ return NULL;
+ }
+
+ curdata->hot_x = hot_x;
+ curdata->hot_y = hot_y;
+ curdata->w = surface->w;
+ curdata->h = surface->h;
+
+ /* This usage is inspired by Wayland/Weston RPI code, how they figured this out is anyone's guess */
+ curdata->resource = vc_dispmanx_resource_create(VC_IMAGE_ARGB8888, surface->w | (surface->pitch << 16), surface->h | (surface->h << 16), &dummy);
+ SDL_assert(curdata->resource);
+ vc_dispmanx_rect_set(&dst_rect, 0, 0, curdata->w, curdata->h);
+ /* A note from Weston:
+ * vc_dispmanx_resource_write_data() ignores ifmt,
+ * rect.x, rect.width, and uses stride only for computing
+ * the size of the transfer as rect.height * stride.
+ * Therefore we can only write rows starting at x=0.
+ */
+ ret = vc_dispmanx_resource_write_data(curdata->resource, VC_IMAGE_ARGB8888, surface->pitch, surface->pixels, &dst_rect);
+ SDL_assert (ret == DISPMANX_SUCCESS);
+
+ cursor->driverdata = curdata;
+
+ return cursor;
+
+}
+
+/* Show the specified cursor, or hide if cursor is NULL */
+static int
+RPI_ShowCursor(SDL_Cursor * cursor)
+{
+ int ret;
+ DISPMANX_UPDATE_HANDLE_T update;
+ RPI_CursorData *curdata;
+ VC_RECT_T src_rect, dst_rect;
+ SDL_Mouse *mouse;
+ SDL_VideoDisplay *display;
+ SDL_DisplayData *data;
+ VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FROM_SOURCE /* flags */ , 255 /*opacity 0->255*/, 0 /* mask */ };
+ uint32_t layer = SDL_RPI_MOUSELAYER;
+ const char *env;
+
+ mouse = SDL_GetMouse();
+ if (mouse == NULL) {
+ return -1;
+ }
+
+ if (cursor == NULL) {
+ /* FIXME: We hide the current mouse's cursor, what we actually need is *_HideCursor */
+
+ if (mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) {
+ curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata;
+ if (curdata->element > DISPMANX_NO_HANDLE) {
+ update = vc_dispmanx_update_start(10);
+ SDL_assert(update);
+ ret = vc_dispmanx_element_remove(update, curdata->element);
+ SDL_assert(ret == DISPMANX_SUCCESS);
+ ret = vc_dispmanx_update_submit_sync(update);
+ SDL_assert(ret == DISPMANX_SUCCESS);
+ curdata->element = DISPMANX_NO_HANDLE;
+ }
+ }
+ return 0;
+ }
+
+ curdata = (RPI_CursorData *) cursor->driverdata;
+ if (curdata == NULL) {
+ return -1;
+ }
+
+ if (mouse->focus == NULL) {
+ return -1;
+ }
+
+ display = SDL_GetDisplayForWindow(mouse->focus);
+ if (display == NULL) {
+ return -1;
+ }
+
+ data = (SDL_DisplayData*) display->driverdata;
+ if (data == NULL) {
+ return -1;
+ }
+
+ if (curdata->element == DISPMANX_NO_HANDLE) {
+ vc_dispmanx_rect_set(&src_rect, 0, 0, curdata->w << 16, curdata->h << 16);
+ vc_dispmanx_rect_set(&dst_rect, mouse->x, mouse->y, curdata->w, curdata->h);
+
+ update = vc_dispmanx_update_start(10);
+ SDL_assert(update);
+
+ env = SDL_GetHint(SDL_HINT_RPI_VIDEO_LAYER);
+ if (env) {
+ layer = SDL_atoi(env) + 1;
+ }
+
+ curdata->element = vc_dispmanx_element_add(update,
+ data->dispman_display,
+ layer,
+ &dst_rect,
+ curdata->resource,
+ &src_rect,
+ DISPMANX_PROTECTION_NONE,
+ &alpha,
+ DISPMANX_NO_HANDLE, // clamp
+ VC_IMAGE_ROT0);
+ SDL_assert(curdata->element > DISPMANX_NO_HANDLE);
+ ret = vc_dispmanx_update_submit_sync(update);
+ SDL_assert(ret == DISPMANX_SUCCESS);
+ }
+
+ return 0;
+}
+
+/* Free a window manager cursor */
+static void
+RPI_FreeCursor(SDL_Cursor * cursor)
+{
+ int ret;
+ DISPMANX_UPDATE_HANDLE_T update;
+ RPI_CursorData *curdata;
+
+ if (cursor != NULL) {
+ curdata = (RPI_CursorData *) cursor->driverdata;
+
+ if (curdata != NULL) {
+ if (curdata->element != DISPMANX_NO_HANDLE) {
+ update = vc_dispmanx_update_start(10);
+ SDL_assert(update);
+ ret = vc_dispmanx_element_remove(update, curdata->element);
+ SDL_assert(ret == DISPMANX_SUCCESS);
+ ret = vc_dispmanx_update_submit_sync(update);
+ SDL_assert(ret == DISPMANX_SUCCESS);
+ }
+
+ if (curdata->resource != DISPMANX_NO_HANDLE) {
+ ret = vc_dispmanx_resource_delete(curdata->resource);
+ SDL_assert(ret == DISPMANX_SUCCESS);
+ }
+
+ SDL_free(cursor->driverdata);
+ }
+ SDL_free(cursor);
+ }
+}
+
+/* Warp the mouse to (x,y) */
+static void
+RPI_WarpMouse(SDL_Window * window, int x, int y)
+{
+ RPI_WarpMouseGlobal(x, y);
+}
+
+/* Warp the mouse to (x,y) */
+static int
+RPI_WarpMouseGlobal(int x, int y)
+{
+ RPI_CursorData *curdata;
+ DISPMANX_UPDATE_HANDLE_T update;
+ int ret;
+ VC_RECT_T dst_rect;
+ VC_RECT_T src_rect;
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ if (mouse == NULL || mouse->cur_cursor == NULL || mouse->cur_cursor->driverdata == NULL) {
+ return 0;
+ }
+
+ /* Update internal mouse position. */
+ SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 0, x, y);
+
+ curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata;
+ if (curdata->element == DISPMANX_NO_HANDLE) {
+ return 0;
+ }
+
+ update = vc_dispmanx_update_start(10);
+ if (!update) {
+ return 0;
+ }
+
+ src_rect.x = 0;
+ src_rect.y = 0;
+ src_rect.width = curdata->w << 16;
+ src_rect.height = curdata->h << 16;
+ dst_rect.x = x;
+ dst_rect.y = y;
+ dst_rect.width = curdata->w;
+ dst_rect.height = curdata->h;
+
+ ret = vc_dispmanx_element_change_attributes(
+ update,
+ curdata->element,
+ 0,
+ 0,
+ 0,
+ &dst_rect,
+ &src_rect,
+ DISPMANX_NO_HANDLE,
+ DISPMANX_NO_ROTATE);
+ if (ret != DISPMANX_SUCCESS) {
+ return SDL_SetError("vc_dispmanx_element_change_attributes() failed");
+ }
+
+ /* Submit asynchronously, otherwise the peformance suffers a lot */
+ ret = vc_dispmanx_update_submit(update, 0, NULL);
+ if (ret != DISPMANX_SUCCESS) {
+ return SDL_SetError("vc_dispmanx_update_submit() failed");
+ }
+ return 0;
+}
+
+/* Warp the mouse to (x,y) */
+static int
+RPI_WarpMouseGlobalGraphicOnly(int x, int y)
+{
+ RPI_CursorData *curdata;
+ DISPMANX_UPDATE_HANDLE_T update;
+ int ret;
+ VC_RECT_T dst_rect;
+ VC_RECT_T src_rect;
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ if (mouse == NULL || mouse->cur_cursor == NULL || mouse->cur_cursor->driverdata == NULL) {
+ return 0;
+ }
+
+ curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata;
+ if (curdata->element == DISPMANX_NO_HANDLE) {
+ return 0;
+ }
+
+ update = vc_dispmanx_update_start(10);
+ if (!update) {
+ return 0;
+ }
+
+ src_rect.x = 0;
+ src_rect.y = 0;
+ src_rect.width = curdata->w << 16;
+ src_rect.height = curdata->h << 16;
+ dst_rect.x = x;
+ dst_rect.y = y;
+ dst_rect.width = curdata->w;
+ dst_rect.height = curdata->h;
+
+ ret = vc_dispmanx_element_change_attributes(
+ update,
+ curdata->element,
+ 0,
+ 0,
+ 0,
+ &dst_rect,
+ &src_rect,
+ DISPMANX_NO_HANDLE,
+ DISPMANX_NO_ROTATE);
+ if (ret != DISPMANX_SUCCESS) {
+ return SDL_SetError("vc_dispmanx_element_change_attributes() failed");
+ }
+
+ /* Submit asynchronously, otherwise the peformance suffers a lot */
+ ret = vc_dispmanx_update_submit(update, 0, NULL);
+ if (ret != DISPMANX_SUCCESS) {
+ return SDL_SetError("vc_dispmanx_update_submit() failed");
+ }
+ return 0;
+}
+
+void
+RPI_InitMouse(_THIS)
+{
+ /* FIXME: Using UDEV it should be possible to scan all mice
+ * but there's no point in doing so as there's no multimice support...yet!
+ */
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ mouse->CreateCursor = RPI_CreateCursor;
+ mouse->ShowCursor = RPI_ShowCursor;
+ mouse->MoveCursor = RPI_MoveCursor;
+ mouse->FreeCursor = RPI_FreeCursor;
+ mouse->WarpMouse = RPI_WarpMouse;
+ mouse->WarpMouseGlobal = RPI_WarpMouseGlobal;
+
+ SDL_SetDefaultCursor(RPI_CreateDefaultCursor());
+}
+
+void
+RPI_QuitMouse(_THIS)
+{
+
+}
+
+/* This is called when a mouse motion event occurs */
+static void
+RPI_MoveCursor(SDL_Cursor * cursor)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ /* We must NOT call SDL_SendMouseMotion() on the next call or we will enter recursivity,
+ * so we create a version of WarpMouseGlobal without it. */
+ RPI_WarpMouseGlobalGraphicOnly(mouse->x, mouse->y);
+}
+
+#endif /* SDL_VIDEO_DRIVER_RPI */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/raspberry/SDL_rpimouse.h b/src/3rdparty/SDL2/src/video/raspberry/SDL_rpimouse.h
new file mode 100644
index 0000000..919f811
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/raspberry/SDL_rpimouse.h
@@ -0,0 +1,43 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_RPI_mouse_h_
+#define SDL_RPI_mouse_h_
+
+#include "../SDL_sysvideo.h"
+
+typedef struct _RPI_CursorData RPI_CursorData;
+struct _RPI_CursorData
+{
+ DISPMANX_RESOURCE_HANDLE_T resource;
+ DISPMANX_ELEMENT_HANDLE_T element;
+ int hot_x, hot_y;
+ int w, h;
+};
+
+#define SDL_RPI_CURSORDATA(curs) RPI_CursorData *curdata = (RPI_CursorData *) ((curs) ? (curs)->driverdata : NULL)
+
+extern void RPI_InitMouse(_THIS);
+extern void RPI_QuitMouse(_THIS);
+
+#endif /* SDL_RPI_mouse_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/raspberry/SDL_rpiopengles.c b/src/3rdparty/SDL2/src/video/raspberry/SDL_rpiopengles.c
new file mode 100644
index 0000000..b763007
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/raspberry/SDL_rpiopengles.c
@@ -0,0 +1,71 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+#include "SDL_hints.h"
+#include "SDL_log.h"
+
+#if SDL_VIDEO_DRIVER_RPI && SDL_VIDEO_OPENGL_EGL
+
+#include "SDL_rpivideo.h"
+#include "SDL_rpiopengles.h"
+
+/* EGL implementation of SDL OpenGL support */
+
+void
+RPI_GLES_DefaultProfileConfig(_THIS, int *mask, int *major, int *minor)
+{
+ *mask = SDL_GL_CONTEXT_PROFILE_ES;
+ *major = 2;
+ *minor = 0;
+}
+
+int
+RPI_GLES_LoadLibrary(_THIS, const char *path) {
+ return SDL_EGL_LoadLibrary(_this, path, EGL_DEFAULT_DISPLAY, 0);
+}
+
+int
+RPI_GLES_SwapWindow(_THIS, SDL_Window * window) {
+ SDL_WindowData *wdata = ((SDL_WindowData *) window->driverdata);
+
+ if (!(_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, wdata->egl_surface))) {
+ SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "eglSwapBuffers failed.");
+ return 0;
+ }
+
+ /* Wait immediately for vsync (as if we only had two buffers), for low input-lag scenarios.
+ * Run your SDL2 program with "SDL_RPI_DOUBLE_BUFFER=1 <program_name>" to enable this. */
+ if (wdata->double_buffer) {
+ SDL_LockMutex(wdata->vsync_cond_mutex);
+ SDL_CondWait(wdata->vsync_cond, wdata->vsync_cond_mutex);
+ SDL_UnlockMutex(wdata->vsync_cond_mutex);
+ }
+
+ return 0;
+}
+
+SDL_EGL_CreateContext_impl(RPI)
+SDL_EGL_MakeCurrent_impl(RPI)
+
+#endif /* SDL_VIDEO_DRIVER_RPI && SDL_VIDEO_OPENGL_EGL */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/video/raspberry/SDL_rpiopengles.h b/src/3rdparty/SDL2/src/video/raspberry/SDL_rpiopengles.h
new file mode 100644
index 0000000..9724a5f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/raspberry/SDL_rpiopengles.h
@@ -0,0 +1,49 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_rpiopengles_h_
+#define SDL_rpiopengles_h_
+
+#if SDL_VIDEO_DRIVER_RPI && SDL_VIDEO_OPENGL_EGL
+
+#include "../SDL_sysvideo.h"
+#include "../SDL_egl_c.h"
+
+/* OpenGLES functions */
+#define RPI_GLES_GetAttribute SDL_EGL_GetAttribute
+#define RPI_GLES_GetProcAddress SDL_EGL_GetProcAddress
+#define RPI_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
+#define RPI_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
+#define RPI_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
+#define RPI_GLES_DeleteContext SDL_EGL_DeleteContext
+
+extern int RPI_GLES_LoadLibrary(_THIS, const char *path);
+extern SDL_GLContext RPI_GLES_CreateContext(_THIS, SDL_Window * window);
+extern int RPI_GLES_SwapWindow(_THIS, SDL_Window * window);
+extern int RPI_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+extern void RPI_GLES_DefaultProfileConfig(_THIS, int *mask, int *major, int *minor);
+
+#endif /* SDL_VIDEO_DRIVER_RPI && SDL_VIDEO_OPENGL_EGL */
+
+#endif /* SDL_rpiopengles_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/raspberry/SDL_rpivideo.c b/src/3rdparty/SDL2/src/video/raspberry/SDL_rpivideo.c
new file mode 100644
index 0000000..e386380
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/raspberry/SDL_rpivideo.c
@@ -0,0 +1,442 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_RPI
+
+/* References
+ * http://elinux.org/RPi_VideoCore_APIs
+ * https://github.com/raspberrypi/firmware/blob/master/opt/vc/src/hello_pi/hello_triangle/triangle.c
+ * http://cgit.freedesktop.org/wayland/weston/tree/src/rpi-renderer.c
+ * http://cgit.freedesktop.org/wayland/weston/tree/src/compositor-rpi.c
+ */
+
+/* SDL internals */
+#include "../SDL_sysvideo.h"
+#include "SDL_version.h"
+#include "SDL_syswm.h"
+#include "SDL_loadso.h"
+#include "SDL_events.h"
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_keyboard_c.h"
+#include "SDL_hints.h"
+
+#ifdef SDL_INPUT_LINUXEV
+#include "../../core/linux/SDL_evdev.h"
+#endif
+
+/* RPI declarations */
+#include "SDL_rpivideo.h"
+#include "SDL_rpievents_c.h"
+#include "SDL_rpiopengles.h"
+#include "SDL_rpimouse.h"
+
+static int
+RPI_Available(void)
+{
+ return 1;
+}
+
+static void
+RPI_Destroy(SDL_VideoDevice * device)
+{
+ SDL_free(device->driverdata);
+ SDL_free(device);
+}
+
+static int
+RPI_GetRefreshRate()
+{
+ TV_DISPLAY_STATE_T tvstate;
+ if (vc_tv_get_display_state( &tvstate ) == 0) {
+ //The width/height parameters are in the same position in the union
+ //for HDMI and SDTV
+ HDMI_PROPERTY_PARAM_T property;
+ property.property = HDMI_PROPERTY_PIXEL_CLOCK_TYPE;
+ vc_tv_hdmi_get_property(&property);
+ return property.param1 == HDMI_PIXEL_CLOCK_TYPE_NTSC ?
+ tvstate.display.hdmi.frame_rate * (1000.0f/1001.0f) :
+ tvstate.display.hdmi.frame_rate;
+ }
+ return 60; /* Failed to get display state, default to 60 */
+}
+
+static SDL_VideoDevice *
+RPI_Create()
+{
+ SDL_VideoDevice *device;
+ SDL_VideoData *phdata;
+
+ /* Initialize SDL_VideoDevice structure */
+ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (device == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ /* Initialize internal data */
+ phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
+ if (phdata == NULL) {
+ SDL_OutOfMemory();
+ SDL_free(device);
+ return NULL;
+ }
+
+ device->driverdata = phdata;
+
+ /* Setup amount of available displays */
+ device->num_displays = 0;
+
+ /* Set device free function */
+ device->free = RPI_Destroy;
+
+ /* Setup all functions which we can handle */
+ device->VideoInit = RPI_VideoInit;
+ device->VideoQuit = RPI_VideoQuit;
+ device->GetDisplayModes = RPI_GetDisplayModes;
+ device->SetDisplayMode = RPI_SetDisplayMode;
+ device->CreateSDLWindow = RPI_CreateWindow;
+ device->CreateSDLWindowFrom = RPI_CreateWindowFrom;
+ device->SetWindowTitle = RPI_SetWindowTitle;
+ device->SetWindowIcon = RPI_SetWindowIcon;
+ device->SetWindowPosition = RPI_SetWindowPosition;
+ device->SetWindowSize = RPI_SetWindowSize;
+ device->ShowWindow = RPI_ShowWindow;
+ device->HideWindow = RPI_HideWindow;
+ device->RaiseWindow = RPI_RaiseWindow;
+ device->MaximizeWindow = RPI_MaximizeWindow;
+ device->MinimizeWindow = RPI_MinimizeWindow;
+ device->RestoreWindow = RPI_RestoreWindow;
+ device->SetWindowGrab = RPI_SetWindowGrab;
+ device->DestroyWindow = RPI_DestroyWindow;
+#if 0
+ device->GetWindowWMInfo = RPI_GetWindowWMInfo;
+#endif
+ device->GL_LoadLibrary = RPI_GLES_LoadLibrary;
+ device->GL_GetProcAddress = RPI_GLES_GetProcAddress;
+ device->GL_UnloadLibrary = RPI_GLES_UnloadLibrary;
+ device->GL_CreateContext = RPI_GLES_CreateContext;
+ device->GL_MakeCurrent = RPI_GLES_MakeCurrent;
+ device->GL_SetSwapInterval = RPI_GLES_SetSwapInterval;
+ device->GL_GetSwapInterval = RPI_GLES_GetSwapInterval;
+ device->GL_SwapWindow = RPI_GLES_SwapWindow;
+ device->GL_DeleteContext = RPI_GLES_DeleteContext;
+ device->GL_DefaultProfileConfig = RPI_GLES_DefaultProfileConfig;
+
+ device->PumpEvents = RPI_PumpEvents;
+
+ return device;
+}
+
+VideoBootStrap RPI_bootstrap = {
+ "RPI",
+ "RPI Video Driver",
+ RPI_Available,
+ RPI_Create
+};
+
+/*****************************************************************************/
+/* SDL Video and Display initialization/handling functions */
+/*****************************************************************************/
+int
+RPI_VideoInit(_THIS)
+{
+ SDL_VideoDisplay display;
+ SDL_DisplayMode current_mode;
+ SDL_DisplayData *data;
+ uint32_t w,h;
+
+ /* Initialize BCM Host */
+ bcm_host_init();
+
+ SDL_zero(current_mode);
+
+ if (graphics_get_display_size( 0, &w, &h) < 0) {
+ return -1;
+ }
+
+ current_mode.w = w;
+ current_mode.h = h;
+ current_mode.refresh_rate = RPI_GetRefreshRate();
+ /* 32 bpp for default */
+ current_mode.format = SDL_PIXELFORMAT_ABGR8888;
+
+ current_mode.driverdata = NULL;
+
+ SDL_zero(display);
+ display.desktop_mode = current_mode;
+ display.current_mode = current_mode;
+
+ /* Allocate display internal data */
+ data = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
+ if (data == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ data->dispman_display = vc_dispmanx_display_open( 0 /* LCD */);
+
+ display.driverdata = data;
+
+ SDL_AddVideoDisplay(&display);
+
+#ifdef SDL_INPUT_LINUXEV
+ if (SDL_EVDEV_Init() < 0) {
+ return -1;
+ }
+#endif
+
+ RPI_InitMouse(_this);
+
+ return 1;
+}
+
+void
+RPI_VideoQuit(_THIS)
+{
+#ifdef SDL_INPUT_LINUXEV
+ SDL_EVDEV_Quit();
+#endif
+}
+
+void
+RPI_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
+{
+ /* Only one display mode available, the current one */
+ SDL_AddDisplayMode(display, &display->current_mode);
+}
+
+int
+RPI_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
+{
+ return 0;
+}
+
+static void
+RPI_vsync_callback(DISPMANX_UPDATE_HANDLE_T u, void *data)
+{
+ SDL_WindowData *wdata = ((SDL_WindowData *) data);
+
+ SDL_LockMutex(wdata->vsync_cond_mutex);
+ SDL_CondSignal(wdata->vsync_cond);
+ SDL_UnlockMutex(wdata->vsync_cond_mutex);
+}
+
+int
+RPI_CreateWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *wdata;
+ SDL_VideoDisplay *display;
+ SDL_DisplayData *displaydata;
+ VC_RECT_T dst_rect;
+ VC_RECT_T src_rect;
+ VC_DISPMANX_ALPHA_T dispman_alpha;
+ DISPMANX_UPDATE_HANDLE_T dispman_update;
+ uint32_t layer = SDL_RPI_VIDEOLAYER;
+ const char *env;
+
+ /* Disable alpha, otherwise the app looks composed with whatever dispman is showing (X11, console,etc) */
+ dispman_alpha.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS;
+ dispman_alpha.opacity = 0xFF;
+ dispman_alpha.mask = 0;
+
+ /* Allocate window internal data */
+ wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
+ if (wdata == NULL) {
+ return SDL_OutOfMemory();
+ }
+ display = SDL_GetDisplayForWindow(window);
+ displaydata = (SDL_DisplayData *) display->driverdata;
+
+ /* Windows have one size for now */
+ window->w = display->desktop_mode.w;
+ window->h = display->desktop_mode.h;
+
+ /* OpenGL ES is the law here, buddy */
+ window->flags |= SDL_WINDOW_OPENGL;
+
+ /* Create a dispman element and associate a window to it */
+ dst_rect.x = 0;
+ dst_rect.y = 0;
+ dst_rect.width = window->w;
+ dst_rect.height = window->h;
+
+ src_rect.x = 0;
+ src_rect.y = 0;
+ src_rect.width = window->w << 16;
+ src_rect.height = window->h << 16;
+
+ env = SDL_GetHint(SDL_HINT_RPI_VIDEO_LAYER);
+ if (env) {
+ layer = SDL_atoi(env);
+ }
+
+ dispman_update = vc_dispmanx_update_start( 0 );
+ wdata->dispman_window.element = vc_dispmanx_element_add (dispman_update,
+ displaydata->dispman_display,
+ layer /* layer */,
+ &dst_rect,
+ 0 /*src*/,
+ &src_rect,
+ DISPMANX_PROTECTION_NONE,
+ &dispman_alpha /*alpha*/,
+ 0 /*clamp*/,
+ 0 /*transform*/);
+ wdata->dispman_window.width = window->w;
+ wdata->dispman_window.height = window->h;
+ vc_dispmanx_update_submit_sync(dispman_update);
+
+ if (!_this->egl_data) {
+ if (SDL_GL_LoadLibrary(NULL) < 0) {
+ return -1;
+ }
+ }
+ wdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) &wdata->dispman_window);
+
+ if (wdata->egl_surface == EGL_NO_SURFACE) {
+ return SDL_SetError("Could not create GLES window surface");
+ }
+
+ /* Start generating vsync callbacks if necesary */
+ wdata->double_buffer = SDL_FALSE;
+ if (SDL_GetHintBoolean(SDL_HINT_VIDEO_DOUBLE_BUFFER, SDL_FALSE)) {
+ wdata->vsync_cond = SDL_CreateCond();
+ wdata->vsync_cond_mutex = SDL_CreateMutex();
+ wdata->double_buffer = SDL_TRUE;
+ vc_dispmanx_vsync_callback(displaydata->dispman_display, RPI_vsync_callback, (void*)wdata);
+ }
+
+ /* Setup driver data for this window */
+ window->driverdata = wdata;
+
+ /* One window, it always has focus */
+ SDL_SetMouseFocus(window);
+ SDL_SetKeyboardFocus(window);
+
+ /* Window has been successfully created */
+ return 0;
+}
+
+void
+RPI_DestroyWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
+
+ if(data) {
+ if (data->double_buffer) {
+ /* Wait for vsync, and then stop vsync callbacks and destroy related stuff, if needed */
+ SDL_LockMutex(data->vsync_cond_mutex);
+ SDL_CondWait(data->vsync_cond, data->vsync_cond_mutex);
+ SDL_UnlockMutex(data->vsync_cond_mutex);
+
+ vc_dispmanx_vsync_callback(displaydata->dispman_display, NULL, NULL);
+
+ SDL_DestroyCond(data->vsync_cond);
+ SDL_DestroyMutex(data->vsync_cond_mutex);
+ }
+
+#if SDL_VIDEO_OPENGL_EGL
+ if (data->egl_surface != EGL_NO_SURFACE) {
+ SDL_EGL_DestroySurface(_this, data->egl_surface);
+ }
+#endif
+ SDL_free(data);
+ window->driverdata = NULL;
+ }
+}
+
+int
+RPI_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
+{
+ return -1;
+}
+
+void
+RPI_SetWindowTitle(_THIS, SDL_Window * window)
+{
+}
+void
+RPI_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
+{
+}
+void
+RPI_SetWindowPosition(_THIS, SDL_Window * window)
+{
+}
+void
+RPI_SetWindowSize(_THIS, SDL_Window * window)
+{
+}
+void
+RPI_ShowWindow(_THIS, SDL_Window * window)
+{
+}
+void
+RPI_HideWindow(_THIS, SDL_Window * window)
+{
+}
+void
+RPI_RaiseWindow(_THIS, SDL_Window * window)
+{
+}
+void
+RPI_MaximizeWindow(_THIS, SDL_Window * window)
+{
+}
+void
+RPI_MinimizeWindow(_THIS, SDL_Window * window)
+{
+}
+void
+RPI_RestoreWindow(_THIS, SDL_Window * window)
+{
+}
+void
+RPI_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
+{
+
+}
+
+/*****************************************************************************/
+/* SDL Window Manager function */
+/*****************************************************************************/
+#if 0
+SDL_bool
+RPI_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
+{
+ if (info->version.major <= SDL_MAJOR_VERSION) {
+ return SDL_TRUE;
+ } else {
+ SDL_SetError("application not compiled with SDL %d.%d",
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+ return SDL_FALSE;
+ }
+
+ /* Failed to get window manager information */
+ return SDL_FALSE;
+}
+#endif
+
+#endif /* SDL_VIDEO_DRIVER_RPI */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/raspberry/SDL_rpivideo.h b/src/3rdparty/SDL2/src/video/raspberry/SDL_rpivideo.h
new file mode 100644
index 0000000..b2eb670
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/raspberry/SDL_rpivideo.h
@@ -0,0 +1,104 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef __SDL_RPIVIDEO_H__
+#define __SDL_RPIVIDEO_H__
+
+#include "../../SDL_internal.h"
+#include "../SDL_sysvideo.h"
+
+#include <bcm_host.h>
+#include "GLES/gl.h"
+#include "EGL/egl.h"
+#include "EGL/eglext.h"
+
+typedef struct SDL_VideoData
+{
+ uint32_t egl_refcount; /* OpenGL ES reference count */
+} SDL_VideoData;
+
+
+typedef struct SDL_DisplayData
+{
+ DISPMANX_DISPLAY_HANDLE_T dispman_display;
+} SDL_DisplayData;
+
+
+typedef struct SDL_WindowData
+{
+ EGL_DISPMANX_WINDOW_T dispman_window;
+#if SDL_VIDEO_OPENGL_EGL
+ EGLSurface egl_surface;
+#endif
+
+ /* Vsync callback cond and mutex */
+ SDL_cond *vsync_cond;
+ SDL_mutex *vsync_cond_mutex;
+ SDL_bool double_buffer;
+
+} SDL_WindowData;
+
+#define SDL_RPI_VIDEOLAYER 10000 /* High enough so to occlude everything */
+#define SDL_RPI_MOUSELAYER SDL_RPI_VIDEOLAYER + 1
+
+
+/****************************************************************************/
+/* SDL_VideoDevice functions declaration */
+/****************************************************************************/
+
+/* Display and window functions */
+int RPI_VideoInit(_THIS);
+void RPI_VideoQuit(_THIS);
+void RPI_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
+int RPI_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
+int RPI_CreateWindow(_THIS, SDL_Window * window);
+int RPI_CreateWindowFrom(_THIS, SDL_Window * window, const void *data);
+void RPI_SetWindowTitle(_THIS, SDL_Window * window);
+void RPI_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
+void RPI_SetWindowPosition(_THIS, SDL_Window * window);
+void RPI_SetWindowSize(_THIS, SDL_Window * window);
+void RPI_ShowWindow(_THIS, SDL_Window * window);
+void RPI_HideWindow(_THIS, SDL_Window * window);
+void RPI_RaiseWindow(_THIS, SDL_Window * window);
+void RPI_MaximizeWindow(_THIS, SDL_Window * window);
+void RPI_MinimizeWindow(_THIS, SDL_Window * window);
+void RPI_RestoreWindow(_THIS, SDL_Window * window);
+void RPI_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
+void RPI_DestroyWindow(_THIS, SDL_Window * window);
+
+/* Window manager function */
+SDL_bool RPI_GetWindowWMInfo(_THIS, SDL_Window * window,
+ struct SDL_SysWMinfo *info);
+
+/* OpenGL/OpenGL ES functions */
+int RPI_GLES_LoadLibrary(_THIS, const char *path);
+void *RPI_GLES_GetProcAddress(_THIS, const char *proc);
+void RPI_GLES_UnloadLibrary(_THIS);
+SDL_GLContext RPI_GLES_CreateContext(_THIS, SDL_Window * window);
+int RPI_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+int RPI_GLES_SetSwapInterval(_THIS, int interval);
+int RPI_GLES_GetSwapInterval(_THIS);
+int RPI_GLES_SwapWindow(_THIS, SDL_Window * window);
+void RPI_GLES_DeleteContext(_THIS, SDL_GLContext context);
+
+#endif /* __SDL_RPIVIDEO_H__ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/sdlgenblit.pl b/src/3rdparty/SDL2/src/video/sdlgenblit.pl
new file mode 100644
index 0000000..d89ae2a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/sdlgenblit.pl
@@ -0,0 +1,535 @@
+#!/usr/bin/perl -w
+#
+# A script to generate optimized C blitters for Simple DirectMedia Layer
+# http://www.libsdl.org/
+
+use warnings;
+use strict;
+
+my %file;
+
+# The formats potentially supported by this script:
+# SDL_PIXELFORMAT_RGB332
+# SDL_PIXELFORMAT_RGB444
+# SDL_PIXELFORMAT_RGB555
+# SDL_PIXELFORMAT_ARGB4444
+# SDL_PIXELFORMAT_ARGB1555
+# SDL_PIXELFORMAT_RGB565
+# SDL_PIXELFORMAT_RGB24
+# SDL_PIXELFORMAT_BGR24
+# SDL_PIXELFORMAT_RGB888
+# SDL_PIXELFORMAT_BGR888
+# SDL_PIXELFORMAT_ARGB8888
+# SDL_PIXELFORMAT_RGBA8888
+# SDL_PIXELFORMAT_ABGR8888
+# SDL_PIXELFORMAT_BGRA8888
+# SDL_PIXELFORMAT_ARGB2101010
+
+# The formats we're actually creating blitters for:
+my @src_formats = (
+ "RGB888",
+ "BGR888",
+ "ARGB8888",
+ "RGBA8888",
+ "ABGR8888",
+ "BGRA8888",
+);
+my @dst_formats = (
+ "RGB888",
+ "BGR888",
+ "ARGB8888",
+);
+
+my %format_size = (
+ "RGB888" => 4,
+ "BGR888" => 4,
+ "ARGB8888" => 4,
+ "RGBA8888" => 4,
+ "ABGR8888" => 4,
+ "BGRA8888" => 4,
+);
+
+my %format_type = (
+ "RGB888" => "Uint32",
+ "BGR888" => "Uint32",
+ "ARGB8888" => "Uint32",
+ "RGBA8888" => "Uint32",
+ "ABGR8888" => "Uint32",
+ "BGRA8888" => "Uint32",
+);
+
+my %get_rgba_string_ignore_alpha = (
+ "RGB888" => "_R = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _B = (Uint8)_pixel;",
+ "BGR888" => "_B = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _R = (Uint8)_pixel;",
+ "ARGB8888" => "_R = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _B = (Uint8)_pixel;",
+ "RGBA8888" => "_R = (Uint8)(_pixel >> 24); _G = (Uint8)(_pixel >> 16); _B = (Uint8)(_pixel >> 8);",
+ "ABGR8888" => "_B = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _R = (Uint8)_pixel;",
+ "BGRA8888" => "_B = (Uint8)(_pixel >> 24); _G = (Uint8)(_pixel >> 16); _R = (Uint8)(_pixel >> 8);",
+);
+
+my %get_rgba_string = (
+ "RGB888" => $get_rgba_string_ignore_alpha{"RGB888"} . " _A = 0xFF;",
+ "BGR888" => $get_rgba_string_ignore_alpha{"BGR888"} . " _A = 0xFF;",
+ "ARGB8888" => $get_rgba_string_ignore_alpha{"ARGB8888"} . " _A = (Uint8)(_pixel >> 24);",
+ "RGBA8888" => $get_rgba_string_ignore_alpha{"RGBA8888"} . " _A = (Uint8)_pixel;",
+ "ABGR8888" => $get_rgba_string_ignore_alpha{"ABGR8888"} . " _A = (Uint8)(_pixel >> 24);",
+ "BGRA8888" => $get_rgba_string_ignore_alpha{"BGRA8888"} . " _A = (Uint8)_pixel;",
+);
+
+my %set_rgba_string = (
+ "RGB888" => "_pixel = ((Uint32)_R << 16) | ((Uint32)_G << 8) | _B;",
+ "BGR888" => "_pixel = ((Uint32)_B << 16) | ((Uint32)_G << 8) | _R;",
+ "ARGB8888" => "_pixel = ((Uint32)_A << 24) | ((Uint32)_R << 16) | ((Uint32)_G << 8) | _B;",
+ "RGBA8888" => "_pixel = ((Uint32)_R << 24) | ((Uint32)_G << 16) | ((Uint32)_B << 8) | _A;",
+ "ABGR8888" => "_pixel = ((Uint32)_A << 24) | ((Uint32)_B << 16) | ((Uint32)_G << 8) | _R;",
+ "BGRA8888" => "_pixel = ((Uint32)_B << 24) | ((Uint32)_G << 16) | ((Uint32)_R << 8) | _A;",
+);
+
+sub open_file {
+ my $name = shift;
+ open(FILE, ">$name.new") || die "Cant' open $name.new: $!";
+ print FILE <<__EOF__;
+/* DO NOT EDIT! This file is generated by sdlgenblit.pl */
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken\@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../SDL_internal.h"
+
+/* *INDENT-OFF* */
+
+__EOF__
+}
+
+sub close_file {
+ my $name = shift;
+ print FILE <<__EOF__;
+/* *INDENT-ON* */
+
+/* vi: set ts=4 sw=4 expandtab: */
+__EOF__
+ close FILE;
+ if ( ! -f $name || system("cmp -s $name $name.new") != 0 ) {
+ rename("$name.new", "$name");
+ } else {
+ unlink("$name.new");
+ }
+}
+
+sub output_copydefs
+{
+ print FILE <<__EOF__;
+extern SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[];
+__EOF__
+}
+
+sub output_copyfuncname
+{
+ my $prefix = shift;
+ my $src = shift;
+ my $dst = shift;
+ my $modulate = shift;
+ my $blend = shift;
+ my $scale = shift;
+ my $args = shift;
+ my $suffix = shift;
+
+ print FILE "$prefix SDL_Blit_${src}_${dst}";
+ if ( $modulate ) {
+ print FILE "_Modulate";
+ }
+ if ( $blend ) {
+ print FILE "_Blend";
+ }
+ if ( $scale ) {
+ print FILE "_Scale";
+ }
+ if ( $args ) {
+ print FILE "(SDL_BlitInfo *info)";
+ }
+ print FILE "$suffix";
+}
+
+sub get_rgba
+{
+ my $prefix = shift;
+ my $format = shift;
+ my $ignore_alpha = shift;
+
+ my $string;
+ if ($ignore_alpha) {
+ $string = $get_rgba_string_ignore_alpha{$format};
+ } else {
+ $string = $get_rgba_string{$format};
+ }
+
+ $string =~ s/_/$prefix/g;
+ if ( $prefix ne "" ) {
+ print FILE <<__EOF__;
+ ${prefix}pixel = *$prefix;
+__EOF__
+ } else {
+ print FILE <<__EOF__;
+ pixel = *src;
+__EOF__
+ }
+ print FILE <<__EOF__;
+ $string
+__EOF__
+}
+
+sub set_rgba
+{
+ my $prefix = shift;
+ my $format = shift;
+ my $string = $set_rgba_string{$format};
+ $string =~ s/_/$prefix/g;
+ print FILE <<__EOF__;
+ $string
+ *dst = ${prefix}pixel;
+__EOF__
+}
+
+sub output_copycore
+{
+ my $src = shift;
+ my $dst = shift;
+ my $modulate = shift;
+ my $blend = shift;
+ my $s = "";
+ my $d = "";
+
+ # Nice and easy...
+ if ( $src eq $dst && !$modulate && !$blend ) {
+ print FILE <<__EOF__;
+ *dst = *src;
+__EOF__
+ return;
+ }
+
+ my $dst_has_alpha = ($dst =~ /A/) ? 1 : 0;
+ my $ignore_dst_alpha = !$dst_has_alpha && !$blend;
+
+ if ( $blend ) {
+ get_rgba("src", $src, $ignore_dst_alpha);
+ get_rgba("dst", $dst, !$dst_has_alpha);
+ $s = "src";
+ $d = "dst";
+ } else {
+ get_rgba("", $src, $ignore_dst_alpha);
+ }
+
+ if ( $modulate ) {
+ print FILE <<__EOF__;
+ if (flags & SDL_COPY_MODULATE_COLOR) {
+ ${s}R = (${s}R * modulateR) / 255;
+ ${s}G = (${s}G * modulateG) / 255;
+ ${s}B = (${s}B * modulateB) / 255;
+ }
+__EOF__
+ if (not $ignore_dst_alpha) {
+ print FILE <<__EOF__;
+ if (flags & SDL_COPY_MODULATE_ALPHA) {
+ ${s}A = (${s}A * modulateA) / 255;
+ }
+__EOF__
+ }
+ }
+ if ( $blend ) {
+ print FILE <<__EOF__;
+ if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
+ /* This goes away if we ever use premultiplied alpha */
+ if (${s}A < 255) {
+ ${s}R = (${s}R * ${s}A) / 255;
+ ${s}G = (${s}G * ${s}A) / 255;
+ ${s}B = (${s}B * ${s}A) / 255;
+ }
+ }
+ switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
+ case SDL_COPY_BLEND:
+ ${d}R = ${s}R + ((255 - ${s}A) * ${d}R) / 255;
+ ${d}G = ${s}G + ((255 - ${s}A) * ${d}G) / 255;
+ ${d}B = ${s}B + ((255 - ${s}A) * ${d}B) / 255;
+__EOF__
+
+ if ( $dst_has_alpha ) {
+ print FILE <<__EOF__;
+ ${d}A = ${s}A + ((255 - ${s}A) * ${d}A) / 255;
+__EOF__
+ }
+
+ print FILE <<__EOF__;
+ break;
+ case SDL_COPY_ADD:
+ ${d}R = ${s}R + ${d}R; if (${d}R > 255) ${d}R = 255;
+ ${d}G = ${s}G + ${d}G; if (${d}G > 255) ${d}G = 255;
+ ${d}B = ${s}B + ${d}B; if (${d}B > 255) ${d}B = 255;
+ break;
+ case SDL_COPY_MOD:
+ ${d}R = (${s}R * ${d}R) / 255;
+ ${d}G = (${s}G * ${d}G) / 255;
+ ${d}B = (${s}B * ${d}B) / 255;
+ break;
+ }
+__EOF__
+ }
+ if ( $blend ) {
+ set_rgba("dst", $dst);
+ } else {
+ set_rgba("", $dst);
+ }
+}
+
+sub output_copyfunc
+{
+ my $src = shift;
+ my $dst = shift;
+ my $modulate = shift;
+ my $blend = shift;
+ my $scale = shift;
+
+ my $dst_has_alpha = ($dst =~ /A/) ? 1 : 0;
+ my $ignore_dst_alpha = !$dst_has_alpha && !$blend;
+
+ output_copyfuncname("static void", $src, $dst, $modulate, $blend, $scale, 1, "\n");
+ print FILE <<__EOF__;
+{
+__EOF__
+ if ( $modulate || $blend ) {
+ print FILE <<__EOF__;
+ const int flags = info->flags;
+__EOF__
+ }
+ if ( $modulate ) {
+ print FILE <<__EOF__;
+ const Uint32 modulateR = info->r;
+ const Uint32 modulateG = info->g;
+ const Uint32 modulateB = info->b;
+__EOF__
+ if (!$ignore_dst_alpha) {
+ print FILE <<__EOF__;
+ const Uint32 modulateA = info->a;
+__EOF__
+ }
+ }
+ if ( $blend ) {
+ print FILE <<__EOF__;
+ Uint32 srcpixel;
+ Uint32 srcR, srcG, srcB, srcA;
+ Uint32 dstpixel;
+__EOF__
+ if ($dst_has_alpha) {
+ print FILE <<__EOF__;
+ Uint32 dstR, dstG, dstB, dstA;
+__EOF__
+ } else {
+ print FILE <<__EOF__;
+ Uint32 dstR, dstG, dstB;
+__EOF__
+ }
+ } elsif ( $modulate || $src ne $dst ) {
+ print FILE <<__EOF__;
+ Uint32 pixel;
+__EOF__
+ if (!$ignore_dst_alpha) {
+ print FILE <<__EOF__;
+ Uint32 R, G, B, A;
+__EOF__
+ } else {
+ print FILE <<__EOF__;
+ Uint32 R, G, B;
+__EOF__
+ }
+ }
+ if ( $scale ) {
+ print FILE <<__EOF__;
+ int srcy, srcx;
+ int posy, posx;
+ int incy, incx;
+__EOF__
+
+ print FILE <<__EOF__;
+
+ srcy = 0;
+ posy = 0;
+ incy = (info->src_h << 16) / info->dst_h;
+ incx = (info->src_w << 16) / info->dst_w;
+
+ while (info->dst_h--) {
+ $format_type{$src} *src = 0;
+ $format_type{$dst} *dst = ($format_type{$dst} *)info->dst;
+ int n = info->dst_w;
+ srcx = -1;
+ posx = 0x10000L;
+ while (posy >= 0x10000L) {
+ ++srcy;
+ posy -= 0x10000L;
+ }
+ while (n--) {
+ if (posx >= 0x10000L) {
+ while (posx >= 0x10000L) {
+ ++srcx;
+ posx -= 0x10000L;
+ }
+ src = ($format_type{$src} *)(info->src + (srcy * info->src_pitch) + (srcx * $format_size{$src}));
+__EOF__
+ print FILE <<__EOF__;
+ }
+__EOF__
+ output_copycore($src, $dst, $modulate, $blend);
+ print FILE <<__EOF__;
+ posx += incx;
+ ++dst;
+ }
+ posy += incy;
+ info->dst += info->dst_pitch;
+ }
+__EOF__
+ } else {
+ print FILE <<__EOF__;
+
+ while (info->dst_h--) {
+ $format_type{$src} *src = ($format_type{$src} *)info->src;
+ $format_type{$dst} *dst = ($format_type{$dst} *)info->dst;
+ int n = info->dst_w;
+ while (n--) {
+__EOF__
+ output_copycore($src, $dst, $modulate, $blend);
+ print FILE <<__EOF__;
+ ++src;
+ ++dst;
+ }
+ info->src += info->src_pitch;
+ info->dst += info->dst_pitch;
+ }
+__EOF__
+ }
+ print FILE <<__EOF__;
+}
+
+__EOF__
+}
+
+sub output_copyfunc_h
+{
+}
+
+sub output_copyinc
+{
+ print FILE <<__EOF__;
+#include "SDL_video.h"
+#include "SDL_blit.h"
+#include "SDL_blit_auto.h"
+
+__EOF__
+}
+
+sub output_copyfunctable
+{
+ print FILE <<__EOF__;
+SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[] = {
+__EOF__
+ for (my $i = 0; $i <= $#src_formats; ++$i) {
+ my $src = $src_formats[$i];
+ for (my $j = 0; $j <= $#dst_formats; ++$j) {
+ my $dst = $dst_formats[$j];
+ for (my $modulate = 0; $modulate <= 1; ++$modulate) {
+ for (my $blend = 0; $blend <= 1; ++$blend) {
+ for (my $scale = 0; $scale <= 1; ++$scale) {
+ if ( $modulate || $blend || $scale ) {
+ print FILE " { SDL_PIXELFORMAT_$src, SDL_PIXELFORMAT_$dst, ";
+ my $flags = "";
+ my $flag = "";
+ if ( $modulate ) {
+ $flag = "SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA";
+ if ( $flags eq "" ) {
+ $flags = $flag;
+ } else {
+ $flags = "$flags | $flag";
+ }
+ }
+ if ( $blend ) {
+ $flag = "SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD";
+ if ( $flags eq "" ) {
+ $flags = $flag;
+ } else {
+ $flags = "$flags | $flag";
+ }
+ }
+ if ( $scale ) {
+ $flag = "SDL_COPY_NEAREST";
+ if ( $flags eq "" ) {
+ $flags = $flag;
+ } else {
+ $flags = "$flags | $flag";
+ }
+ }
+ if ( $flags eq "" ) {
+ $flags = "0";
+ }
+ print FILE "($flags), SDL_CPU_ANY,";
+ output_copyfuncname("", $src_formats[$i], $dst_formats[$j], $modulate, $blend, $scale, 0, " },\n");
+ }
+ }
+ }
+ }
+ }
+ }
+ print FILE <<__EOF__;
+ { 0, 0, 0, 0, NULL }
+};
+
+__EOF__
+}
+
+sub output_copyfunc_c
+{
+ my $src = shift;
+ my $dst = shift;
+
+ for (my $modulate = 0; $modulate <= 1; ++$modulate) {
+ for (my $blend = 0; $blend <= 1; ++$blend) {
+ for (my $scale = 0; $scale <= 1; ++$scale) {
+ if ( $modulate || $blend || $scale ) {
+ output_copyfunc($src, $dst, $modulate, $blend, $scale);
+ }
+ }
+ }
+ }
+}
+
+open_file("SDL_blit_auto.h");
+output_copydefs();
+for (my $i = 0; $i <= $#src_formats; ++$i) {
+ for (my $j = 0; $j <= $#dst_formats; ++$j) {
+ output_copyfunc_h($src_formats[$i], $dst_formats[$j]);
+ }
+}
+print FILE "\n";
+close_file("SDL_blit_auto.h");
+
+open_file("SDL_blit_auto.c");
+output_copyinc();
+for (my $i = 0; $i <= $#src_formats; ++$i) {
+ for (my $j = 0; $j <= $#dst_formats; ++$j) {
+ output_copyfunc_c($src_formats[$i], $dst_formats[$j]);
+ }
+}
+output_copyfunctable();
+close_file("SDL_blit_auto.c");
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitappdelegate.h b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitappdelegate.h
new file mode 100644
index 0000000..34b0138
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitappdelegate.h
@@ -0,0 +1,47 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#import <UIKit/UIKit.h>
+
+@interface SDLLaunchScreenController : UIViewController
+
+- (instancetype)init;
+- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;
+- (void)loadView;
+
+@end
+
+@interface SDLUIKitDelegate : NSObject<UIApplicationDelegate>
+
++ (id)sharedAppDelegate;
++ (NSString *)getAppDelegateClassName;
+
+- (void)hideLaunchScreen;
+
+/* This property is marked as optional, and is only intended to be used when
+ * the app's UI is storyboard-based. SDL is not storyboard-based, however
+ * several major third-party ad APIs (e.g. Google admob) incorrectly assume this
+ * property always exists, and will crash if it doesn't. */
+@property (nonatomic) UIWindow *window;
+
+@end
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitappdelegate.m b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitappdelegate.m
new file mode 100644
index 0000000..a942dfd
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitappdelegate.m
@@ -0,0 +1,539 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_UIKIT
+
+#include "../SDL_sysvideo.h"
+#include "SDL_assert.h"
+#include "SDL_hints.h"
+#include "SDL_system.h"
+#include "SDL_main.h"
+
+#import "SDL_uikitappdelegate.h"
+#import "SDL_uikitmodes.h"
+#import "SDL_uikitwindow.h"
+
+#include "../../events/SDL_events_c.h"
+
+#ifdef main
+#undef main
+#endif
+
+static int forward_argc;
+static char **forward_argv;
+static int exit_status;
+
+int main(int argc, char **argv)
+{
+ int i;
+
+ /* store arguments */
+ forward_argc = argc;
+ forward_argv = (char **)malloc((argc+1) * sizeof(char *));
+ for (i = 0; i < argc; i++) {
+ forward_argv[i] = malloc( (strlen(argv[i])+1) * sizeof(char));
+ strcpy(forward_argv[i], argv[i]);
+ }
+ forward_argv[i] = NULL;
+
+ /* Give over control to run loop, SDLUIKitDelegate will handle most things from here */
+ @autoreleasepool {
+ UIApplicationMain(argc, argv, nil, [SDLUIKitDelegate getAppDelegateClassName]);
+ }
+
+ /* free the memory we used to hold copies of argc and argv */
+ for (i = 0; i < forward_argc; i++) {
+ free(forward_argv[i]);
+ }
+ free(forward_argv);
+
+ return exit_status;
+}
+
+static void SDLCALL
+SDL_IdleTimerDisabledChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+{
+ BOOL disable = (hint && *hint != '0');
+ [UIApplication sharedApplication].idleTimerDisabled = disable;
+}
+
+#if !TARGET_OS_TV
+/* Load a launch image using the old UILaunchImageFile-era naming rules. */
+static UIImage *
+SDL_LoadLaunchImageNamed(NSString *name, int screenh)
+{
+ UIInterfaceOrientation curorient = [UIApplication sharedApplication].statusBarOrientation;
+ UIUserInterfaceIdiom idiom = [UIDevice currentDevice].userInterfaceIdiom;
+ UIImage *image = nil;
+
+ if (idiom == UIUserInterfaceIdiomPhone && screenh == 568) {
+ /* The image name for the iPhone 5 uses its height as a suffix. */
+ image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-568h", name]];
+ } else if (idiom == UIUserInterfaceIdiomPad) {
+ /* iPad apps can launch in any orientation. */
+ if (UIInterfaceOrientationIsLandscape(curorient)) {
+ if (curorient == UIInterfaceOrientationLandscapeLeft) {
+ image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-LandscapeLeft", name]];
+ } else {
+ image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-LandscapeRight", name]];
+ }
+ if (!image) {
+ image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-Landscape", name]];
+ }
+ } else {
+ if (curorient == UIInterfaceOrientationPortraitUpsideDown) {
+ image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-PortraitUpsideDown", name]];
+ }
+ if (!image) {
+ image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-Portrait", name]];
+ }
+ }
+ }
+
+ if (!image) {
+ image = [UIImage imageNamed:name];
+ }
+
+ return image;
+}
+#endif /* !TARGET_OS_TV */
+
+@interface SDLLaunchScreenController ()
+
+#if !TARGET_OS_TV
+- (NSUInteger)supportedInterfaceOrientations;
+#endif
+
+@end
+
+@implementation SDLLaunchScreenController
+
+- (instancetype)init
+{
+ return [self initWithNibName:nil bundle:[NSBundle mainBundle]];
+}
+
+- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+ if (!(self = [super initWithNibName:nil bundle:nil])) {
+ return nil;
+ }
+
+ NSString *screenname = nibNameOrNil;
+ NSBundle *bundle = nibBundleOrNil;
+ BOOL atleastiOS8 = UIKit_IsSystemVersionAtLeast(8.0);
+
+ /* Launch screens were added in iOS 8. Otherwise we use launch images. */
+ if (screenname && atleastiOS8) {
+ @try {
+ self.view = [bundle loadNibNamed:screenname owner:self options:nil][0];
+ }
+ @catch (NSException *exception) {
+ /* If a launch screen name is specified but it fails to load, iOS
+ * displays a blank screen rather than falling back to an image. */
+ return nil;
+ }
+ }
+
+ if (!self.view) {
+ NSArray *launchimages = [bundle objectForInfoDictionaryKey:@"UILaunchImages"];
+ NSString *imagename = nil;
+ UIImage *image = nil;
+
+ int screenw = (int)([UIScreen mainScreen].bounds.size.width + 0.5);
+ int screenh = (int)([UIScreen mainScreen].bounds.size.height + 0.5);
+
+#if !TARGET_OS_TV
+ UIInterfaceOrientation curorient = [UIApplication sharedApplication].statusBarOrientation;
+
+ /* We always want portrait-oriented size, to match UILaunchImageSize. */
+ if (screenw > screenh) {
+ int width = screenw;
+ screenw = screenh;
+ screenh = width;
+ }
+#endif
+
+ /* Xcode 5 introduced a dictionary of launch images in Info.plist. */
+ if (launchimages) {
+ for (NSDictionary *dict in launchimages) {
+ NSString *minversion = dict[@"UILaunchImageMinimumOSVersion"];
+ NSString *sizestring = dict[@"UILaunchImageSize"];
+
+ /* Ignore this image if the current version is too low. */
+ if (minversion && !UIKit_IsSystemVersionAtLeast(minversion.doubleValue)) {
+ continue;
+ }
+
+ /* Ignore this image if the size doesn't match. */
+ if (sizestring) {
+ CGSize size = CGSizeFromString(sizestring);
+ if ((int)(size.width + 0.5) != screenw || (int)(size.height + 0.5) != screenh) {
+ continue;
+ }
+ }
+
+#if !TARGET_OS_TV
+ UIInterfaceOrientationMask orientmask = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
+ NSString *orientstring = dict[@"UILaunchImageOrientation"];
+
+ if (orientstring) {
+ if ([orientstring isEqualToString:@"PortraitUpsideDown"]) {
+ orientmask = UIInterfaceOrientationMaskPortraitUpsideDown;
+ } else if ([orientstring isEqualToString:@"Landscape"]) {
+ orientmask = UIInterfaceOrientationMaskLandscape;
+ } else if ([orientstring isEqualToString:@"LandscapeLeft"]) {
+ orientmask = UIInterfaceOrientationMaskLandscapeLeft;
+ } else if ([orientstring isEqualToString:@"LandscapeRight"]) {
+ orientmask = UIInterfaceOrientationMaskLandscapeRight;
+ }
+ }
+
+ /* Ignore this image if the orientation doesn't match. */
+ if ((orientmask & (1 << curorient)) == 0) {
+ continue;
+ }
+#endif
+
+ imagename = dict[@"UILaunchImageName"];
+ }
+
+ if (imagename) {
+ image = [UIImage imageNamed:imagename];
+ }
+ }
+#if !TARGET_OS_TV
+ else {
+ imagename = [bundle objectForInfoDictionaryKey:@"UILaunchImageFile"];
+
+ if (imagename) {
+ image = SDL_LoadLaunchImageNamed(imagename, screenh);
+ }
+
+ if (!image) {
+ image = SDL_LoadLaunchImageNamed(@"Default", screenh);
+ }
+ }
+#endif
+
+ if (image) {
+ UIImageView *view = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
+ UIImageOrientation imageorient = UIImageOrientationUp;
+
+#if !TARGET_OS_TV
+ /* Bugs observed / workaround tested in iOS 8.3, 7.1, and 6.1. */
+ if (UIInterfaceOrientationIsLandscape(curorient)) {
+ if (atleastiOS8 && image.size.width < image.size.height) {
+ /* On iOS 8, portrait launch images displayed in forced-
+ * landscape mode (e.g. a standard Default.png on an iPhone
+ * when Info.plist only supports landscape orientations) need
+ * to be rotated to display in the expected orientation. */
+ if (curorient == UIInterfaceOrientationLandscapeLeft) {
+ imageorient = UIImageOrientationRight;
+ } else if (curorient == UIInterfaceOrientationLandscapeRight) {
+ imageorient = UIImageOrientationLeft;
+ }
+ } else if (!atleastiOS8 && image.size.width > image.size.height) {
+ /* On iOS 7 and below, landscape launch images displayed in
+ * landscape mode (e.g. landscape iPad launch images) need
+ * to be rotated to display in the expected orientation. */
+ if (curorient == UIInterfaceOrientationLandscapeLeft) {
+ imageorient = UIImageOrientationLeft;
+ } else if (curorient == UIInterfaceOrientationLandscapeRight) {
+ imageorient = UIImageOrientationRight;
+ }
+ }
+ }
+#endif
+
+ /* Create the properly oriented image. */
+ view.image = [[UIImage alloc] initWithCGImage:image.CGImage scale:image.scale orientation:imageorient];
+
+ self.view = view;
+ }
+ }
+
+ return self;
+}
+
+- (void)loadView
+{
+ /* Do nothing. */
+}
+
+#if !TARGET_OS_TV
+- (BOOL)shouldAutorotate
+{
+ /* If YES, the launch image will be incorrectly rotated in some cases. */
+ return NO;
+}
+
+- (NSUInteger)supportedInterfaceOrientations
+{
+ /* We keep the supported orientations unrestricted to avoid the case where
+ * there are no common orientations between the ones set in Info.plist and
+ * the ones set here (it will cause an exception in that case.) */
+ return UIInterfaceOrientationMaskAll;
+}
+#endif /* !TARGET_OS_TV */
+
+@end
+
+@implementation SDLUIKitDelegate {
+ UIWindow *launchWindow;
+}
+
+/* convenience method */
++ (id)sharedAppDelegate
+{
+ /* the delegate is set in UIApplicationMain(), which is guaranteed to be
+ * called before this method */
+ return [UIApplication sharedApplication].delegate;
+}
+
++ (NSString *)getAppDelegateClassName
+{
+ /* subclassing notice: when you subclass this appdelegate, make sure to add
+ * a category to override this method and return the actual name of the
+ * delegate */
+ return @"SDLUIKitDelegate";
+}
+
+- (void)hideLaunchScreen
+{
+ UIWindow *window = launchWindow;
+
+ if (!window || window.hidden) {
+ return;
+ }
+
+ launchWindow = nil;
+
+ /* Do a nice animated fade-out (roughly matches the real launch behavior.) */
+ [UIView animateWithDuration:0.2 animations:^{
+ window.alpha = 0.0;
+ } completion:^(BOOL finished) {
+ window.hidden = YES;
+ }];
+}
+
+- (void)postFinishLaunch
+{
+ /* Hide the launch screen the next time the run loop is run. SDL apps will
+ * have a chance to load resources while the launch screen is still up. */
+ [self performSelector:@selector(hideLaunchScreen) withObject:nil afterDelay:0.0];
+
+ /* run the user's application, passing argc and argv */
+ SDL_iPhoneSetEventPump(SDL_TRUE);
+ exit_status = SDL_main(forward_argc, forward_argv);
+ SDL_iPhoneSetEventPump(SDL_FALSE);
+
+ if (launchWindow) {
+ launchWindow.hidden = YES;
+ launchWindow = nil;
+ }
+
+ /* exit, passing the return status from the user's application */
+ /* We don't actually exit to support applications that do setup in their
+ * main function and then allow the Cocoa event loop to run. */
+ /* exit(exit_status); */
+}
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+ NSBundle *bundle = [NSBundle mainBundle];
+
+#if SDL_IPHONE_LAUNCHSCREEN
+ /* The normal launch screen is displayed until didFinishLaunching returns,
+ * but SDL_main is called after that happens and there may be a noticeable
+ * delay between the start of SDL_main and when the first real frame is
+ * displayed (e.g. if resources are loaded before SDL_GL_SwapWindow is
+ * called), so we show the launch screen programmatically until the first
+ * time events are pumped. */
+ UIViewController *vc = nil;
+ NSString *screenname = nil;
+
+ /* tvOS only uses a plain launch image. */
+#if !TARGET_OS_TV
+ screenname = [bundle objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
+
+ if (screenname && UIKit_IsSystemVersionAtLeast(8.0)) {
+ @try {
+ /* The launch storyboard is actually a nib in some older versions of
+ * Xcode. We'll try to load it as a storyboard first, as it's more
+ * modern. */
+ UIStoryboard *storyboard = [UIStoryboard storyboardWithName:screenname bundle:bundle];
+ vc = [storyboard instantiateInitialViewController];
+ }
+ @catch (NSException *exception) {
+ /* Do nothing (there's more code to execute below). */
+ }
+ }
+#endif
+
+ if (vc == nil) {
+ vc = [[SDLLaunchScreenController alloc] initWithNibName:screenname bundle:bundle];
+ }
+
+ if (vc.view) {
+ launchWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
+
+ /* We don't want the launch window immediately hidden when a real SDL
+ * window is shown - we fade it out ourselves when we're ready. */
+ launchWindow.windowLevel = UIWindowLevelNormal + 1.0;
+
+ /* Show the window but don't make it key. Events should always go to
+ * other windows when possible. */
+ launchWindow.hidden = NO;
+
+ launchWindow.rootViewController = vc;
+ }
+#endif
+
+ /* Set working directory to resource path */
+ [[NSFileManager defaultManager] changeCurrentDirectoryPath:[bundle resourcePath]];
+
+ /* register a callback for the idletimer hint */
+ SDL_AddHintCallback(SDL_HINT_IDLE_TIMER_DISABLED,
+ SDL_IdleTimerDisabledChanged, NULL);
+
+ SDL_SetMainReady();
+ [self performSelector:@selector(postFinishLaunch) withObject:nil afterDelay:0.0];
+
+ return YES;
+}
+
+- (UIWindow *)window
+{
+ SDL_VideoDevice *_this = SDL_GetVideoDevice();
+ if (_this) {
+ SDL_Window *window = NULL;
+ for (window = _this->windows; window != NULL; window = window->next) {
+ SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
+ if (data != nil) {
+ return data.uiwindow;
+ }
+ }
+ }
+ return nil;
+}
+
+- (void)setWindow:(UIWindow *)window
+{
+ /* Do nothing. */
+}
+
+#if !TARGET_OS_TV
+- (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation
+{
+ BOOL isLandscape = UIInterfaceOrientationIsLandscape(application.statusBarOrientation);
+ SDL_VideoDevice *_this = SDL_GetVideoDevice();
+
+ if (_this && _this->num_displays > 0) {
+ SDL_DisplayMode *desktopmode = &_this->displays[0].desktop_mode;
+ SDL_DisplayMode *currentmode = &_this->displays[0].current_mode;
+
+ /* The desktop display mode should be kept in sync with the screen
+ * orientation so that updating a window's fullscreen state to
+ * SDL_WINDOW_FULLSCREEN_DESKTOP keeps the window dimensions in the
+ * correct orientation. */
+ if (isLandscape != (desktopmode->w > desktopmode->h)) {
+ int height = desktopmode->w;
+ desktopmode->w = desktopmode->h;
+ desktopmode->h = height;
+ }
+
+ /* Same deal with the current mode + SDL_GetCurrentDisplayMode. */
+ if (isLandscape != (currentmode->w > currentmode->h)) {
+ int height = currentmode->w;
+ currentmode->w = currentmode->h;
+ currentmode->h = height;
+ }
+ }
+}
+#endif
+
+- (void)applicationWillTerminate:(UIApplication *)application
+{
+ SDL_OnApplicationWillTerminate();
+}
+
+- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
+{
+ SDL_OnApplicationDidReceiveMemoryWarning();
+}
+
+- (void)applicationWillResignActive:(UIApplication*)application
+{
+ SDL_OnApplicationWillResignActive();
+}
+
+- (void)applicationDidEnterBackground:(UIApplication*)application
+{
+ SDL_OnApplicationDidEnterBackground();
+}
+
+- (void)applicationWillEnterForeground:(UIApplication*)application
+{
+ SDL_OnApplicationWillEnterForeground();
+}
+
+- (void)applicationDidBecomeActive:(UIApplication*)application
+{
+ SDL_OnApplicationDidBecomeActive();
+}
+
+- (void)sendDropFileForURL:(NSURL *)url
+{
+ NSURL *fileURL = url.filePathURL;
+ if (fileURL != nil) {
+ SDL_SendDropFile(NULL, fileURL.path.UTF8String);
+ } else {
+ SDL_SendDropFile(NULL, url.absoluteString.UTF8String);
+ }
+ SDL_SendDropComplete(NULL);
+}
+
+#if TARGET_OS_TV || (defined(__IPHONE_9_0) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0)
+
+- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
+{
+ /* TODO: Handle options */
+ [self sendDropFileForURL:url];
+ return YES;
+}
+
+#else
+
+- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
+{
+ [self sendDropFileForURL:url];
+ return YES;
+}
+
+#endif
+
+@end
+
+#endif /* SDL_VIDEO_DRIVER_UIKIT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitclipboard.h b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitclipboard.h
new file mode 100644
index 0000000..c4b689d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitclipboard.h
@@ -0,0 +1,35 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#ifndef SDL_uikitclipboard_h_
+#define SDL_uikitclipboard_h_
+
+#include "../SDL_sysvideo.h"
+
+extern int UIKit_SetClipboardText(_THIS, const char *text);
+extern char *UIKit_GetClipboardText(_THIS);
+extern SDL_bool UIKit_HasClipboardText(_THIS);
+
+extern void UIKit_InitClipboard(_THIS);
+extern void UIKit_QuitClipboard(_THIS);
+
+#endif /* SDL_uikitclipboard_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitclipboard.m b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitclipboard.m
new file mode 100644
index 0000000..b1d4f6d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitclipboard.m
@@ -0,0 +1,111 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_UIKIT
+
+#include "SDL_uikitvideo.h"
+#include "../../events/SDL_clipboardevents_c.h"
+
+#import <UIKit/UIPasteboard.h>
+
+int
+UIKit_SetClipboardText(_THIS, const char *text)
+{
+#if TARGET_OS_TV
+ return SDL_SetError("The clipboard is not available on tvOS");
+#else
+ @autoreleasepool {
+ [UIPasteboard generalPasteboard].string = @(text);
+ return 0;
+ }
+#endif
+}
+
+char *
+UIKit_GetClipboardText(_THIS)
+{
+#if TARGET_OS_TV
+ return SDL_strdup(""); // Unsupported.
+#else
+ @autoreleasepool {
+ UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
+ NSString *string = pasteboard.string;
+
+ if (string != nil) {
+ return SDL_strdup(string.UTF8String);
+ } else {
+ return SDL_strdup("");
+ }
+ }
+#endif
+}
+
+SDL_bool
+UIKit_HasClipboardText(_THIS)
+{
+ @autoreleasepool {
+#if !TARGET_OS_TV
+ if ([UIPasteboard generalPasteboard].string != nil) {
+ return SDL_TRUE;
+ }
+#endif
+ return SDL_FALSE;
+ }
+}
+
+void
+UIKit_InitClipboard(_THIS)
+{
+#if !TARGET_OS_TV
+ @autoreleasepool {
+ SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+
+ id observer = [center addObserverForName:UIPasteboardChangedNotification
+ object:nil
+ queue:nil
+ usingBlock:^(NSNotification *note) {
+ SDL_SendClipboardUpdate();
+ }];
+
+ data.pasteboardObserver = observer;
+ }
+#endif
+}
+
+void
+UIKit_QuitClipboard(_THIS)
+{
+ @autoreleasepool {
+ SDL_VideoData *data = (__bridge SDL_VideoData *) _this->driverdata;
+
+ if (data.pasteboardObserver != nil) {
+ [[NSNotificationCenter defaultCenter] removeObserver:data.pasteboardObserver];
+ }
+
+ data.pasteboardObserver = nil;
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_UIKIT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitevents.h b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitevents.h
new file mode 100644
index 0000000..0c48829
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitevents.h
@@ -0,0 +1,30 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#ifndef SDL_uikitevents_h_
+#define SDL_uikitevents_h_
+
+#include "../SDL_sysvideo.h"
+
+extern void UIKit_PumpEvents(_THIS);
+
+#endif /* SDL_uikitevents_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitevents.m b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitevents.m
new file mode 100644
index 0000000..d64e330
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitevents.m
@@ -0,0 +1,73 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_UIKIT
+
+#include "../../events/SDL_events_c.h"
+
+#include "SDL_uikitvideo.h"
+#include "SDL_uikitevents.h"
+#include "SDL_uikitopengles.h"
+
+#import <Foundation/Foundation.h>
+
+static BOOL UIKit_EventPumpEnabled = YES;
+
+void
+SDL_iPhoneSetEventPump(SDL_bool enabled)
+{
+ UIKit_EventPumpEnabled = enabled;
+}
+
+void
+UIKit_PumpEvents(_THIS)
+{
+ if (!UIKit_EventPumpEnabled) {
+ return;
+ }
+
+ /* Let the run loop run for a short amount of time: long enough for
+ touch events to get processed (which is important to get certain
+ elements of Game Center's GKLeaderboardViewController to respond
+ to touch input), but not long enough to introduce a significant
+ delay in the rest of the app.
+ */
+ const CFTimeInterval seconds = 0.000002;
+
+ /* Pump most event types. */
+ SInt32 result;
+ do {
+ result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, seconds, TRUE);
+ } while (result == kCFRunLoopRunHandledSource);
+
+ /* Make sure UIScrollView objects scroll properly. */
+ do {
+ result = CFRunLoopRunInMode((CFStringRef)UITrackingRunLoopMode, seconds, TRUE);
+ } while(result == kCFRunLoopRunHandledSource);
+
+ /* See the comment in the function definition. */
+ UIKit_GL_RestoreCurrentContext();
+}
+
+#endif /* SDL_VIDEO_DRIVER_UIKIT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitmessagebox.h b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitmessagebox.h
new file mode 100644
index 0000000..a766b57
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitmessagebox.h
@@ -0,0 +1,31 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_UIKIT
+
+extern SDL_bool UIKit_ShowingMessageBox(void);
+
+extern int UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
+
+#endif /* SDL_VIDEO_DRIVER_UIKIT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitmessagebox.m b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitmessagebox.m
new file mode 100644
index 0000000..7950c8e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitmessagebox.m
@@ -0,0 +1,206 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_UIKIT
+
+#include "SDL.h"
+#include "SDL_uikitvideo.h"
+#include "SDL_uikitwindow.h"
+
+/* Display a UIKit message box */
+
+static SDL_bool s_showingMessageBox = SDL_FALSE;
+
+SDL_bool
+UIKit_ShowingMessageBox(void)
+{
+ return s_showingMessageBox;
+}
+
+static void
+UIKit_WaitUntilMessageBoxClosed(const SDL_MessageBoxData *messageboxdata, int *clickedindex)
+{
+ *clickedindex = messageboxdata->numbuttons;
+
+ @autoreleasepool {
+ /* Run the main event loop until the alert has finished */
+ /* Note that this needs to be done on the main thread */
+ s_showingMessageBox = SDL_TRUE;
+ while ((*clickedindex) == messageboxdata->numbuttons) {
+ [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
+ }
+ s_showingMessageBox = SDL_FALSE;
+ }
+}
+
+static BOOL
+UIKit_ShowMessageBoxAlertController(const SDL_MessageBoxData *messageboxdata, int *buttonid)
+{
+#ifdef __IPHONE_8_0
+ int i;
+ int __block clickedindex = messageboxdata->numbuttons;
+ const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
+ UIWindow *window = nil;
+ UIWindow *alertwindow = nil;
+
+ if (![UIAlertController class]) {
+ return NO;
+ }
+
+ UIAlertController *alert;
+ alert = [UIAlertController alertControllerWithTitle:@(messageboxdata->title)
+ message:@(messageboxdata->message)
+ preferredStyle:UIAlertControllerStyleAlert];
+
+ for (i = 0; i < messageboxdata->numbuttons; i++) {
+ UIAlertAction *action;
+ UIAlertActionStyle style = UIAlertActionStyleDefault;
+
+ if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
+ style = UIAlertActionStyleCancel;
+ }
+
+ action = [UIAlertAction actionWithTitle:@(buttons[i].text)
+ style:style
+ handler:^(UIAlertAction *action) {
+ clickedindex = i;
+ }];
+ [alert addAction:action];
+ }
+
+ if (messageboxdata->window) {
+ SDL_WindowData *data = (__bridge SDL_WindowData *) messageboxdata->window->driverdata;
+ window = data.uiwindow;
+ }
+
+ if (window == nil || window.rootViewController == nil) {
+ alertwindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
+ alertwindow.rootViewController = [UIViewController new];
+ alertwindow.windowLevel = UIWindowLevelAlert;
+
+ window = alertwindow;
+
+ [alertwindow makeKeyAndVisible];
+ }
+
+ [window.rootViewController presentViewController:alert animated:YES completion:nil];
+ UIKit_WaitUntilMessageBoxClosed(messageboxdata, &clickedindex);
+
+ if (alertwindow) {
+ alertwindow.hidden = YES;
+ }
+
+ /* Force the main SDL window to re-evaluate home indicator state */
+ SDL_Window *focus = SDL_GetFocusWindow();
+ if (focus) {
+ SDL_WindowData *data = (__bridge SDL_WindowData *) focus->driverdata;
+ if (data != nil) {
+ if (@available(iOS 11.0, *)) {
+ [data.viewcontroller performSelectorOnMainThread:@selector(setNeedsUpdateOfHomeIndicatorAutoHidden) withObject:nil waitUntilDone:NO];
+ [data.viewcontroller performSelectorOnMainThread:@selector(setNeedsUpdateOfScreenEdgesDeferringSystemGestures) withObject:nil waitUntilDone:NO];
+ }
+ }
+ }
+
+ *buttonid = messageboxdata->buttons[clickedindex].buttonid;
+ return YES;
+#else
+ return NO;
+#endif /* __IPHONE_8_0 */
+}
+
+/* UIAlertView is deprecated in iOS 8+ in favor of UIAlertController. */
+#if __IPHONE_OS_VERSION_MIN_REQUIRED < 80000
+@interface SDLAlertViewDelegate : NSObject <UIAlertViewDelegate>
+
+@property (nonatomic, assign) int *clickedIndex;
+
+@end
+
+@implementation SDLAlertViewDelegate
+
+- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
+{
+ if (_clickedIndex != NULL) {
+ *_clickedIndex = (int) buttonIndex;
+ }
+}
+
+@end
+#endif /* __IPHONE_OS_VERSION_MIN_REQUIRED < 80000 */
+
+static BOOL
+UIKit_ShowMessageBoxAlertView(const SDL_MessageBoxData *messageboxdata, int *buttonid)
+{
+ /* UIAlertView is deprecated in iOS 8+ in favor of UIAlertController. */
+#if __IPHONE_OS_VERSION_MIN_REQUIRED < 80000
+ int i;
+ int clickedindex = messageboxdata->numbuttons;
+ const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
+ UIAlertView *alert = [[UIAlertView alloc] init];
+ SDLAlertViewDelegate *delegate = [[SDLAlertViewDelegate alloc] init];
+
+ alert.delegate = delegate;
+ alert.title = @(messageboxdata->title);
+ alert.message = @(messageboxdata->message);
+
+ for (i = 0; i < messageboxdata->numbuttons; i++) {
+ [alert addButtonWithTitle:@(buttons[i].text)];
+ }
+
+ delegate.clickedIndex = &clickedindex;
+
+ [alert show];
+
+ UIKit_WaitUntilMessageBoxClosed(messageboxdata, &clickedindex);
+
+ alert.delegate = nil;
+
+ *buttonid = messageboxdata->buttons[clickedindex].buttonid;
+ return YES;
+#else
+ return NO;
+#endif /* __IPHONE_OS_VERSION_MIN_REQUIRED < 80000 */
+}
+
+int
+UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
+{
+ BOOL success = NO;
+
+ @autoreleasepool {
+ success = UIKit_ShowMessageBoxAlertController(messageboxdata, buttonid);
+ if (!success) {
+ success = UIKit_ShowMessageBoxAlertView(messageboxdata, buttonid);
+ }
+ }
+
+ if (!success) {
+ return SDL_SetError("Could not show message box.");
+ }
+
+ return 0;
+}
+
+#endif /* SDL_VIDEO_DRIVER_UIKIT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitmetalview.h b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitmetalview.h
new file mode 100644
index 0000000..bc97778
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitmetalview.h
@@ -0,0 +1,58 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+ */
+
+/*
+ * @author Mark Callow, www.edgewise-consulting.com.
+ *
+ * Thanks to Alex Szpakowski, @slime73 on GitHub, for his gist showing
+ * how to add a CAMetalLayer backed view.
+ */
+
+#ifndef SDL_uikitmetalview_h_
+#define SDL_uikitmetalview_h_
+
+#import "../SDL_sysvideo.h"
+#import "SDL_uikitwindow.h"
+
+#if SDL_VIDEO_DRIVER_UIKIT && (SDL_VIDEO_RENDER_METAL || SDL_VIDEO_VULKAN)
+
+#import <UIKit/UIKit.h>
+#import <Metal/Metal.h>
+#import <QuartzCore/CAMetalLayer.h>
+
+#define METALVIEW_TAG 255
+
+@interface SDL_uikitmetalview : SDL_uikitview
+
+- (instancetype)initWithFrame:(CGRect)frame
+ scale:(CGFloat)scale;
+
+@end
+
+SDL_uikitmetalview* UIKit_Mtl_AddMetalView(SDL_Window* window);
+
+void UIKit_Mtl_GetDrawableSize(SDL_Window * window, int * w, int * h);
+
+#endif /* SDL_VIDEO_DRIVER_UIKIT && (SDL_VIDEO_RENDER_METAL || SDL_VIDEO_VULKAN) */
+
+#endif /* SDL_uikitmetalview_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitmetalview.m b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitmetalview.m
new file mode 100644
index 0000000..104189d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitmetalview.m
@@ -0,0 +1,124 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+ */
+
+/*
+ * @author Mark Callow, www.edgewise-consulting.com.
+ *
+ * Thanks to Alex Szpakowski, @slime73 on GitHub, for his gist showing
+ * how to add a CAMetalLayer backed view.
+ */
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_UIKIT && (SDL_VIDEO_RENDER_METAL || SDL_VIDEO_VULKAN)
+
+#import "../SDL_sysvideo.h"
+#import "SDL_uikitwindow.h"
+#import "SDL_uikitmetalview.h"
+
+#include "SDL_assert.h"
+
+@implementation SDL_uikitmetalview
+
+/* Returns a Metal-compatible layer. */
++ (Class)layerClass
+{
+ return [CAMetalLayer class];
+}
+
+- (instancetype)initWithFrame:(CGRect)frame
+ scale:(CGFloat)scale
+{
+ if ((self = [super initWithFrame:frame])) {
+ self.tag = METALVIEW_TAG;
+ /* Set the desired scale. The default drawableSize of a CAMetalLayer
+ * is its bounds x its scale so nothing further needs to be done. */
+ self.layer.contentsScale = scale;
+ }
+
+ return self;
+}
+
+/* Set the size of the metal drawables when the view is resized. */
+- (void)layoutSubviews
+{
+ [super layoutSubviews];
+}
+
+@end
+
+SDL_uikitmetalview*
+UIKit_Mtl_AddMetalView(SDL_Window* window)
+{
+ SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
+ SDL_uikitview *view = (SDL_uikitview*)data.uiwindow.rootViewController.view;
+ CGFloat scale = 1.0;
+
+ if ([view isKindOfClass:[SDL_uikitmetalview class]]) {
+ return (SDL_uikitmetalview *)view;
+ }
+
+ if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
+ /* Set the scale to the natural scale factor of the screen - then
+ * the backing dimensions of the Metal view will match the pixel
+ * dimensions of the screen rather than the dimensions in points
+ * yielding high resolution on retine displays.
+ */
+#ifdef __IPHONE_8_0
+ if ([data.uiwindow.screen respondsToSelector:@selector(nativeScale)]) {
+ scale = data.uiwindow.screen.nativeScale;
+ } else
+#endif
+ {
+ scale = data.uiwindow.screen.scale;
+ }
+ }
+ SDL_uikitmetalview *metalview
+ = [[SDL_uikitmetalview alloc] initWithFrame:view.frame
+ scale:scale];
+ [metalview setSDLWindow:window];
+
+ return metalview;
+}
+
+void
+UIKit_Mtl_GetDrawableSize(SDL_Window * window, int * w, int * h)
+{
+ @autoreleasepool {
+ SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
+ SDL_uikitview *view = (SDL_uikitview*)data.uiwindow.rootViewController.view;
+ SDL_uikitmetalview* metalview = [view viewWithTag:METALVIEW_TAG];
+ if (metalview) {
+ CAMetalLayer *layer = (CAMetalLayer*)metalview.layer;
+ assert(layer != NULL);
+ if (w) {
+ *w = layer.drawableSize.width;
+ }
+ if (h) {
+ *h = layer.drawableSize.height;
+ }
+ } else {
+ SDL_GetWindowSize(window, w, h);
+ }
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_UIKIT && (SDL_VIDEO_RENDER_METAL || SDL_VIDEO_VULKAN) */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitmodes.h b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitmodes.h
new file mode 100644
index 0000000..a1df0d4
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitmodes.h
@@ -0,0 +1,50 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_uikitmodes_h_
+#define SDL_uikitmodes_h_
+
+#include "SDL_uikitvideo.h"
+
+@interface SDL_DisplayData : NSObject
+
+@property (nonatomic, strong) UIScreen *uiscreen;
+
+@end
+
+@interface SDL_DisplayModeData : NSObject
+
+@property (nonatomic, strong) UIScreenMode *uiscreenmode;
+
+@end
+
+extern SDL_bool UIKit_IsDisplayLandscape(UIScreen *uiscreen);
+
+extern int UIKit_InitModes(_THIS);
+extern void UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
+extern int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
+extern void UIKit_QuitModes(_THIS);
+extern int UIKit_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
+
+#endif /* SDL_uikitmodes_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitmodes.m b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitmodes.m
new file mode 100644
index 0000000..75e256b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitmodes.m
@@ -0,0 +1,324 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_UIKIT
+
+#include "SDL_assert.h"
+#include "SDL_uikitmodes.h"
+
+@implementation SDL_DisplayData
+
+@synthesize uiscreen;
+
+@end
+
+@implementation SDL_DisplayModeData
+
+@synthesize uiscreenmode;
+
+@end
+
+
+static int
+UIKit_AllocateDisplayModeData(SDL_DisplayMode * mode,
+ UIScreenMode * uiscreenmode)
+{
+ SDL_DisplayModeData *data = nil;
+
+ if (uiscreenmode != nil) {
+ /* Allocate the display mode data */
+ data = [[SDL_DisplayModeData alloc] init];
+ if (!data) {
+ return SDL_OutOfMemory();
+ }
+
+ data.uiscreenmode = uiscreenmode;
+ }
+
+ mode->driverdata = (void *) CFBridgingRetain(data);
+
+ return 0;
+}
+
+static void
+UIKit_FreeDisplayModeData(SDL_DisplayMode * mode)
+{
+ if (mode->driverdata != NULL) {
+ CFRelease(mode->driverdata);
+ mode->driverdata = NULL;
+ }
+}
+
+static NSUInteger
+UIKit_GetDisplayModeRefreshRate(UIScreen *uiscreen)
+{
+#ifdef __IPHONE_10_3
+ if ([uiscreen respondsToSelector:@selector(maximumFramesPerSecond)]) {
+ return uiscreen.maximumFramesPerSecond;
+ }
+#endif
+ return 0;
+}
+
+static int
+UIKit_AddSingleDisplayMode(SDL_VideoDisplay * display, int w, int h,
+ UIScreen * uiscreen, UIScreenMode * uiscreenmode)
+{
+ SDL_DisplayMode mode;
+ SDL_zero(mode);
+
+ if (UIKit_AllocateDisplayModeData(&mode, uiscreenmode) < 0) {
+ return -1;
+ }
+
+ mode.format = SDL_PIXELFORMAT_ABGR8888;
+ mode.refresh_rate = (int) UIKit_GetDisplayModeRefreshRate(uiscreen);
+ mode.w = w;
+ mode.h = h;
+
+ if (SDL_AddDisplayMode(display, &mode)) {
+ return 0;
+ } else {
+ UIKit_FreeDisplayModeData(&mode);
+ return -1;
+ }
+}
+
+static int
+UIKit_AddDisplayMode(SDL_VideoDisplay * display, int w, int h, UIScreen * uiscreen,
+ UIScreenMode * uiscreenmode, SDL_bool addRotation)
+{
+ if (UIKit_AddSingleDisplayMode(display, w, h, uiscreen, uiscreenmode) < 0) {
+ return -1;
+ }
+
+ if (addRotation) {
+ /* Add the rotated version */
+ if (UIKit_AddSingleDisplayMode(display, h, w, uiscreen, uiscreenmode) < 0) {
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+static int
+UIKit_AddDisplay(UIScreen *uiscreen)
+{
+ UIScreenMode *uiscreenmode = uiscreen.currentMode;
+ CGSize size = uiscreen.bounds.size;
+ SDL_VideoDisplay display;
+ SDL_DisplayMode mode;
+ SDL_zero(mode);
+
+ /* Make sure the width/height are oriented correctly */
+ if (UIKit_IsDisplayLandscape(uiscreen) != (size.width > size.height)) {
+ CGFloat height = size.width;
+ size.width = size.height;
+ size.height = height;
+ }
+
+ mode.format = SDL_PIXELFORMAT_ABGR8888;
+ mode.refresh_rate = (int) UIKit_GetDisplayModeRefreshRate(uiscreen);
+ mode.w = (int) size.width;
+ mode.h = (int) size.height;
+
+ if (UIKit_AllocateDisplayModeData(&mode, uiscreenmode) < 0) {
+ return -1;
+ }
+
+ SDL_zero(display);
+ display.desktop_mode = mode;
+ display.current_mode = mode;
+
+ /* Allocate the display data */
+ SDL_DisplayData *data = [[SDL_DisplayData alloc] init];
+ if (!data) {
+ UIKit_FreeDisplayModeData(&display.desktop_mode);
+ return SDL_OutOfMemory();
+ }
+
+ data.uiscreen = uiscreen;
+
+ display.driverdata = (void *) CFBridgingRetain(data);
+ SDL_AddVideoDisplay(&display);
+
+ return 0;
+}
+
+SDL_bool
+UIKit_IsDisplayLandscape(UIScreen *uiscreen)
+{
+#if !TARGET_OS_TV
+ if (uiscreen == [UIScreen mainScreen]) {
+ return UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
+ } else
+#endif /* !TARGET_OS_TV */
+ {
+ CGSize size = uiscreen.bounds.size;
+ return (size.width > size.height);
+ }
+}
+
+int
+UIKit_InitModes(_THIS)
+{
+ @autoreleasepool {
+ for (UIScreen *uiscreen in [UIScreen screens]) {
+ if (UIKit_AddDisplay(uiscreen) < 0) {
+ return -1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+void
+UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
+{
+ @autoreleasepool {
+ SDL_DisplayData *data = (__bridge SDL_DisplayData *) display->driverdata;
+
+ SDL_bool isLandscape = UIKit_IsDisplayLandscape(data.uiscreen);
+ SDL_bool addRotation = (data.uiscreen == [UIScreen mainScreen]);
+ CGFloat scale = data.uiscreen.scale;
+ NSArray *availableModes = nil;
+
+#if TARGET_OS_TV
+ addRotation = SDL_FALSE;
+ availableModes = @[data.uiscreen.currentMode];
+#else
+ availableModes = data.uiscreen.availableModes;
+#endif
+
+#ifdef __IPHONE_8_0
+ /* The UIScreenMode of an iPhone 6 Plus should be 1080x1920 rather than
+ * 1242x2208 (414x736@3x), so we should use the native scale. */
+ if ([data.uiscreen respondsToSelector:@selector(nativeScale)]) {
+ scale = data.uiscreen.nativeScale;
+ }
+#endif
+
+ for (UIScreenMode *uimode in availableModes) {
+ /* The size of a UIScreenMode is in pixels, but we deal exclusively
+ * in points (except in SDL_GL_GetDrawableSize.) */
+ int w = (int)(uimode.size.width / scale);
+ int h = (int)(uimode.size.height / scale);
+
+ /* Make sure the width/height are oriented correctly */
+ if (isLandscape != (w > h)) {
+ int tmp = w;
+ w = h;
+ h = tmp;
+ }
+
+ UIKit_AddDisplayMode(display, w, h, data.uiscreen, uimode, addRotation);
+ }
+ }
+}
+
+int
+UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
+{
+ @autoreleasepool {
+ SDL_DisplayData *data = (__bridge SDL_DisplayData *) display->driverdata;
+
+#if !TARGET_OS_TV
+ SDL_DisplayModeData *modedata = (__bridge SDL_DisplayModeData *)mode->driverdata;
+ [data.uiscreen setCurrentMode:modedata.uiscreenmode];
+#endif
+
+ if (data.uiscreen == [UIScreen mainScreen]) {
+ /* [UIApplication setStatusBarOrientation:] no longer works reliably
+ * in recent iOS versions, so we can't rotate the screen when setting
+ * the display mode. */
+ if (mode->w > mode->h) {
+ if (!UIKit_IsDisplayLandscape(data.uiscreen)) {
+ return SDL_SetError("Screen orientation does not match display mode size");
+ }
+ } else if (mode->w < mode->h) {
+ if (UIKit_IsDisplayLandscape(data.uiscreen)) {
+ return SDL_SetError("Screen orientation does not match display mode size");
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+int
+UIKit_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
+{
+ @autoreleasepool {
+ int displayIndex = (int) (display - _this->displays);
+ SDL_DisplayData *data = (__bridge SDL_DisplayData *) display->driverdata;
+ CGRect frame = data.uiscreen.bounds;
+
+ /* the default function iterates displays to make a fake offset,
+ as if all the displays were side-by-side, which is fine for iOS. */
+ if (SDL_GetDisplayBounds(displayIndex, rect) < 0) {
+ return -1;
+ }
+
+#if !TARGET_OS_TV && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
+ if (!UIKit_IsSystemVersionAtLeast(7.0)) {
+ frame = [data.uiscreen applicationFrame];
+ }
+#endif
+
+ rect->x += frame.origin.x;
+ rect->y += frame.origin.y;
+ rect->w = frame.size.width;
+ rect->h = frame.size.height;
+ }
+
+ return 0;
+}
+
+void
+UIKit_QuitModes(_THIS)
+{
+ /* Release Objective-C objects, so higher level doesn't free() them. */
+ int i, j;
+ @autoreleasepool {
+ for (i = 0; i < _this->num_displays; i++) {
+ SDL_VideoDisplay *display = &_this->displays[i];
+
+ UIKit_FreeDisplayModeData(&display->desktop_mode);
+ for (j = 0; j < display->num_display_modes; j++) {
+ SDL_DisplayMode *mode = &display->display_modes[j];
+ UIKit_FreeDisplayModeData(mode);
+ }
+
+ if (display->driverdata != NULL) {
+ CFRelease(display->driverdata);
+ display->driverdata = NULL;
+ }
+ }
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_UIKIT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitopengles.h b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitopengles.h
new file mode 100644
index 0000000..6b57289
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitopengles.h
@@ -0,0 +1,40 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#ifndef SDL_uikitopengles_
+#define SDL_uikitopengles_
+
+#include "../SDL_sysvideo.h"
+
+extern int UIKit_GL_MakeCurrent(_THIS, SDL_Window * window,
+ SDL_GLContext context);
+extern void UIKit_GL_GetDrawableSize(_THIS, SDL_Window * window,
+ int * w, int * h);
+extern int UIKit_GL_SwapWindow(_THIS, SDL_Window * window);
+extern SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window);
+extern void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context);
+extern void *UIKit_GL_GetProcAddress(_THIS, const char *proc);
+extern int UIKit_GL_LoadLibrary(_THIS, const char *path);
+
+extern void UIKit_GL_RestoreCurrentContext(void);
+
+#endif /* SDL_uikitopengles_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitopengles.m b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitopengles.m
new file mode 100644
index 0000000..2f6dec4
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitopengles.m
@@ -0,0 +1,250 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_UIKIT
+
+#include "SDL_uikitopengles.h"
+#import "SDL_uikitopenglview.h"
+#include "SDL_uikitmodes.h"
+#include "SDL_uikitwindow.h"
+#include "SDL_uikitevents.h"
+#include "../SDL_sysvideo.h"
+#include "../../events/SDL_keyboard_c.h"
+#include "../../events/SDL_mouse_c.h"
+#include "../../power/uikit/SDL_syspower.h"
+#include "SDL_loadso.h"
+#include <dlfcn.h>
+
+@interface SDLEAGLContext : EAGLContext
+
+/* The OpenGL ES context owns a view / drawable. */
+@property (nonatomic, strong) SDL_uikitopenglview *sdlView;
+
+@end
+
+@implementation SDLEAGLContext
+
+- (void)dealloc
+{
+ /* When the context is deallocated, its view should be removed from any
+ * SDL window that it's attached to. */
+ [self.sdlView setSDLWindow:NULL];
+}
+
+@end
+
+void *
+UIKit_GL_GetProcAddress(_THIS, const char *proc)
+{
+ /* Look through all SO's for the proc symbol. Here's why:
+ * -Looking for the path to the OpenGL Library seems not to work in the iOS Simulator.
+ * -We don't know that the path won't change in the future. */
+ return dlsym(RTLD_DEFAULT, proc);
+}
+
+/*
+ note that SDL_GL_DeleteContext makes it current without passing the window
+*/
+int
+UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
+{
+ @autoreleasepool {
+ SDLEAGLContext *eaglcontext = (__bridge SDLEAGLContext *) context;
+
+ if (![EAGLContext setCurrentContext:eaglcontext]) {
+ return SDL_SetError("Could not make EAGL context current");
+ }
+
+ if (eaglcontext) {
+ [eaglcontext.sdlView setSDLWindow:window];
+ }
+ }
+
+ return 0;
+}
+
+void
+UIKit_GL_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
+{
+ @autoreleasepool {
+ SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
+ UIView *view = data.viewcontroller.view;
+ if ([view isKindOfClass:[SDL_uikitopenglview class]]) {
+ SDL_uikitopenglview *glview = (SDL_uikitopenglview *) view;
+ if (w) {
+ *w = glview.backingWidth;
+ }
+ if (h) {
+ *h = glview.backingHeight;
+ }
+ }
+ }
+}
+
+int
+UIKit_GL_LoadLibrary(_THIS, const char *path)
+{
+ /* We shouldn't pass a path to this function, since we've already loaded the
+ * library. */
+ if (path != NULL) {
+ return SDL_SetError("iOS GL Load Library just here for compatibility");
+ }
+ return 0;
+}
+
+int UIKit_GL_SwapWindow(_THIS, SDL_Window * window)
+{
+ @autoreleasepool {
+ SDLEAGLContext *context = (__bridge SDLEAGLContext *) SDL_GL_GetCurrentContext();
+
+#if SDL_POWER_UIKIT
+ /* Check once a frame to see if we should turn off the battery monitor. */
+ SDL_UIKit_UpdateBatteryMonitoring();
+#endif
+
+ [context.sdlView swapBuffers];
+
+ /* You need to pump events in order for the OS to make changes visible.
+ * We don't pump events here because we don't want iOS application events
+ * (low memory, terminate, etc.) to happen inside low level rendering. */
+ }
+ return 0;
+}
+
+SDL_GLContext
+UIKit_GL_CreateContext(_THIS, SDL_Window * window)
+{
+ @autoreleasepool {
+ SDLEAGLContext *context = nil;
+ SDL_uikitopenglview *view;
+ SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
+ CGRect frame = UIKit_ComputeViewFrame(window, data.uiwindow.screen);
+ EAGLSharegroup *sharegroup = nil;
+ CGFloat scale = 1.0;
+ int samples = 0;
+ int major = _this->gl_config.major_version;
+ int minor = _this->gl_config.minor_version;
+
+ /* The EAGLRenderingAPI enum values currently map 1:1 to major GLES
+ * versions. */
+ EAGLRenderingAPI api = major;
+
+ /* iOS currently doesn't support GLES >3.0. iOS 6 also only supports up
+ * to GLES 2.0. */
+ if (major > 3 || (major == 3 && (minor > 0 || !UIKit_IsSystemVersionAtLeast(7.0)))) {
+ SDL_SetError("OpenGL ES %d.%d context could not be created", major, minor);
+ return NULL;
+ }
+
+ if (_this->gl_config.multisamplebuffers > 0) {
+ samples = _this->gl_config.multisamplesamples;
+ }
+
+ if (_this->gl_config.share_with_current_context) {
+ EAGLContext *context = (__bridge EAGLContext *) SDL_GL_GetCurrentContext();
+ sharegroup = context.sharegroup;
+ }
+
+ if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
+ /* Set the scale to the natural scale factor of the screen - the
+ * backing dimensions of the OpenGL view will match the pixel
+ * dimensions of the screen rather than the dimensions in points. */
+#ifdef __IPHONE_8_0
+ if ([data.uiwindow.screen respondsToSelector:@selector(nativeScale)]) {
+ scale = data.uiwindow.screen.nativeScale;
+ } else
+#endif
+ {
+ scale = data.uiwindow.screen.scale;
+ }
+ }
+
+ context = [[SDLEAGLContext alloc] initWithAPI:api sharegroup:sharegroup];
+ if (!context) {
+ SDL_SetError("OpenGL ES %d context could not be created", _this->gl_config.major_version);
+ return NULL;
+ }
+
+ /* construct our view, passing in SDL's OpenGL configuration data */
+ view = [[SDL_uikitopenglview alloc] initWithFrame:frame
+ scale:scale
+ retainBacking:_this->gl_config.retained_backing
+ rBits:_this->gl_config.red_size
+ gBits:_this->gl_config.green_size
+ bBits:_this->gl_config.blue_size
+ aBits:_this->gl_config.alpha_size
+ depthBits:_this->gl_config.depth_size
+ stencilBits:_this->gl_config.stencil_size
+ sRGB:_this->gl_config.framebuffer_srgb_capable
+ multisamples:samples
+ context:context];
+
+ if (!view) {
+ return NULL;
+ }
+
+ /* The context owns the view / drawable. */
+ context.sdlView = view;
+
+ if (UIKit_GL_MakeCurrent(_this, window, (__bridge SDL_GLContext) context) < 0) {
+ UIKit_GL_DeleteContext(_this, (SDL_GLContext) CFBridgingRetain(context));
+ return NULL;
+ }
+
+ /* We return a +1'd context. The window's driverdata owns the view (via
+ * MakeCurrent.) */
+ return (SDL_GLContext) CFBridgingRetain(context);
+ }
+}
+
+void
+UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
+{
+ @autoreleasepool {
+ /* The context was retained in SDL_GL_CreateContext, so we release it
+ * here. The context's view will be detached from its window when the
+ * context is deallocated. */
+ CFRelease(context);
+ }
+}
+
+void
+UIKit_GL_RestoreCurrentContext(void)
+{
+ @autoreleasepool {
+ /* Some iOS system functionality (such as Dictation on the on-screen
+ keyboard) uses its own OpenGL ES context but doesn't restore the
+ previous one when it's done. This is a workaround to make sure the
+ expected SDL-created OpenGL ES context is active after the OS is
+ finished running its own code for the frame. If this isn't done, the
+ app may crash or have other nasty symptoms when Dictation is used.
+ */
+ EAGLContext *context = (__bridge EAGLContext *) SDL_GL_GetCurrentContext();
+ if (context != NULL && [EAGLContext currentContext] != context) {
+ [EAGLContext setCurrentContext:context];
+ }
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_UIKIT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitopenglview.h b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitopenglview.h
new file mode 100644
index 0000000..8d12c9f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitopenglview.h
@@ -0,0 +1,60 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#import <UIKit/UIKit.h>
+#import <OpenGLES/EAGL.h>
+#import <OpenGLES/ES3/gl.h>
+
+#import "SDL_uikitview.h"
+#include "SDL_uikitvideo.h"
+
+@interface SDL_uikitopenglview : SDL_uikitview
+
+- (instancetype)initWithFrame:(CGRect)frame
+ scale:(CGFloat)scale
+ retainBacking:(BOOL)retained
+ rBits:(int)rBits
+ gBits:(int)gBits
+ bBits:(int)bBits
+ aBits:(int)aBits
+ depthBits:(int)depthBits
+ stencilBits:(int)stencilBits
+ sRGB:(BOOL)sRGB
+ multisamples:(int)multisamples
+ context:(EAGLContext *)glcontext;
+
+@property (nonatomic, readonly, weak) EAGLContext *context;
+
+/* The width and height of the drawable in pixels (as opposed to points.) */
+@property (nonatomic, readonly) int backingWidth;
+@property (nonatomic, readonly) int backingHeight;
+
+@property (nonatomic, readonly) GLuint drawableRenderbuffer;
+@property (nonatomic, readonly) GLuint drawableFramebuffer;
+@property (nonatomic, readonly) GLuint msaaResolveFramebuffer;
+
+- (void)swapBuffers;
+
+- (void)updateFrame;
+
+@end
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitopenglview.m b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitopenglview.m
new file mode 100644
index 0000000..b0628bf
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitopenglview.m
@@ -0,0 +1,384 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_UIKIT
+
+#include <OpenGLES/EAGLDrawable.h>
+#include <OpenGLES/ES2/glext.h>
+#import "SDL_uikitopenglview.h"
+#include "SDL_uikitwindow.h"
+
+@implementation SDL_uikitopenglview {
+ /* The renderbuffer and framebuffer used to render to this layer. */
+ GLuint viewRenderbuffer, viewFramebuffer;
+
+ /* The depth buffer that is attached to viewFramebuffer, if it exists. */
+ GLuint depthRenderbuffer;
+
+ GLenum colorBufferFormat;
+
+ /* format of depthRenderbuffer */
+ GLenum depthBufferFormat;
+
+ /* The framebuffer and renderbuffer used for rendering with MSAA. */
+ GLuint msaaFramebuffer, msaaRenderbuffer;
+
+ /* The number of MSAA samples. */
+ int samples;
+
+ BOOL retainedBacking;
+}
+
+@synthesize context;
+@synthesize backingWidth;
+@synthesize backingHeight;
+
++ (Class)layerClass
+{
+ return [CAEAGLLayer class];
+}
+
+- (instancetype)initWithFrame:(CGRect)frame
+ scale:(CGFloat)scale
+ retainBacking:(BOOL)retained
+ rBits:(int)rBits
+ gBits:(int)gBits
+ bBits:(int)bBits
+ aBits:(int)aBits
+ depthBits:(int)depthBits
+ stencilBits:(int)stencilBits
+ sRGB:(BOOL)sRGB
+ multisamples:(int)multisamples
+ context:(EAGLContext *)glcontext
+{
+ if ((self = [super initWithFrame:frame])) {
+ const BOOL useStencilBuffer = (stencilBits != 0);
+ const BOOL useDepthBuffer = (depthBits != 0);
+ NSString *colorFormat = nil;
+
+ context = glcontext;
+ samples = multisamples;
+ retainedBacking = retained;
+
+ if (!context || ![EAGLContext setCurrentContext:context]) {
+ SDL_SetError("Could not create OpenGL ES drawable (could not make context current)");
+ return nil;
+ }
+
+ if (samples > 0) {
+ GLint maxsamples = 0;
+ glGetIntegerv(GL_MAX_SAMPLES, &maxsamples);
+
+ /* Clamp the samples to the max supported count. */
+ samples = MIN(samples, maxsamples);
+ }
+
+ if (sRGB) {
+ /* sRGB EAGL drawable support was added in iOS 7. */
+ if (UIKit_IsSystemVersionAtLeast(7.0)) {
+ colorFormat = kEAGLColorFormatSRGBA8;
+ colorBufferFormat = GL_SRGB8_ALPHA8;
+ } else {
+ SDL_SetError("sRGB drawables are not supported.");
+ return nil;
+ }
+ } else if (rBits >= 8 || gBits >= 8 || bBits >= 8) {
+ /* if user specifically requests rbg888 or some color format higher than 16bpp */
+ colorFormat = kEAGLColorFormatRGBA8;
+ colorBufferFormat = GL_RGBA8;
+ } else {
+ /* default case (potentially faster) */
+ colorFormat = kEAGLColorFormatRGB565;
+ colorBufferFormat = GL_RGB565;
+ }
+
+ CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
+
+ eaglLayer.opaque = YES;
+ eaglLayer.drawableProperties = @{
+ kEAGLDrawablePropertyRetainedBacking:@(retained),
+ kEAGLDrawablePropertyColorFormat:colorFormat
+ };
+
+ /* Set the appropriate scale (for retina display support) */
+ self.contentScaleFactor = scale;
+
+ /* Create the color Renderbuffer Object */
+ glGenRenderbuffers(1, &viewRenderbuffer);
+ glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
+
+ if (![context renderbufferStorage:GL_RENDERBUFFER fromDrawable:eaglLayer]) {
+ SDL_SetError("Failed to create OpenGL ES drawable");
+ return nil;
+ }
+
+ /* Create the Framebuffer Object */
+ glGenFramebuffers(1, &viewFramebuffer);
+ glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);
+
+ /* attach the color renderbuffer to the FBO */
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, viewRenderbuffer);
+
+ glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
+ glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);
+
+ if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
+ SDL_SetError("Failed creating OpenGL ES framebuffer");
+ return nil;
+ }
+
+ /* When MSAA is used we'll use a separate framebuffer for rendering to,
+ * since we'll need to do an explicit MSAA resolve before presenting. */
+ if (samples > 0) {
+ glGenFramebuffers(1, &msaaFramebuffer);
+ glBindFramebuffer(GL_FRAMEBUFFER, msaaFramebuffer);
+
+ glGenRenderbuffers(1, &msaaRenderbuffer);
+ glBindRenderbuffer(GL_RENDERBUFFER, msaaRenderbuffer);
+
+ glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, colorBufferFormat, backingWidth, backingHeight);
+
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, msaaRenderbuffer);
+ }
+
+ if (useDepthBuffer || useStencilBuffer) {
+ if (useStencilBuffer) {
+ /* Apparently you need to pack stencil and depth into one buffer. */
+ depthBufferFormat = GL_DEPTH24_STENCIL8_OES;
+ } else if (useDepthBuffer) {
+ /* iOS only uses 32-bit float (exposed as fixed point 24-bit)
+ * depth buffers. */
+ depthBufferFormat = GL_DEPTH_COMPONENT24_OES;
+ }
+
+ glGenRenderbuffers(1, &depthRenderbuffer);
+ glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
+
+ if (samples > 0) {
+ glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, depthBufferFormat, backingWidth, backingHeight);
+ } else {
+ glRenderbufferStorage(GL_RENDERBUFFER, depthBufferFormat, backingWidth, backingHeight);
+ }
+
+ if (useDepthBuffer) {
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);
+ }
+ if (useStencilBuffer) {
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);
+ }
+ }
+
+ if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
+ SDL_SetError("Failed creating OpenGL ES framebuffer");
+ return nil;
+ }
+
+ glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
+
+ [self setDebugLabels];
+ }
+
+ return self;
+}
+
+- (GLuint)drawableRenderbuffer
+{
+ return viewRenderbuffer;
+}
+
+- (GLuint)drawableFramebuffer
+{
+ /* When MSAA is used, the MSAA draw framebuffer is used for drawing. */
+ if (msaaFramebuffer) {
+ return msaaFramebuffer;
+ } else {
+ return viewFramebuffer;
+ }
+}
+
+- (GLuint)msaaResolveFramebuffer
+{
+ /* When MSAA is used, the MSAA draw framebuffer is used for drawing and the
+ * view framebuffer is used as a MSAA resolve framebuffer. */
+ if (msaaFramebuffer) {
+ return viewFramebuffer;
+ } else {
+ return 0;
+ }
+}
+
+- (void)updateFrame
+{
+ GLint prevRenderbuffer = 0;
+ glGetIntegerv(GL_RENDERBUFFER_BINDING, &prevRenderbuffer);
+
+ glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
+ [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer *)self.layer];
+
+ glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
+ glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);
+
+ if (msaaRenderbuffer != 0) {
+ glBindRenderbuffer(GL_RENDERBUFFER, msaaRenderbuffer);
+ glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, colorBufferFormat, backingWidth, backingHeight);
+ }
+
+ if (depthRenderbuffer != 0) {
+ glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
+
+ if (samples > 0) {
+ glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, depthBufferFormat, backingWidth, backingHeight);
+ } else {
+ glRenderbufferStorage(GL_RENDERBUFFER, depthBufferFormat, backingWidth, backingHeight);
+ }
+ }
+
+ glBindRenderbuffer(GL_RENDERBUFFER, prevRenderbuffer);
+}
+
+- (void)setDebugLabels
+{
+ if (viewFramebuffer != 0) {
+ glLabelObjectEXT(GL_FRAMEBUFFER, viewFramebuffer, 0, "context FBO");
+ }
+
+ if (viewRenderbuffer != 0) {
+ glLabelObjectEXT(GL_RENDERBUFFER, viewRenderbuffer, 0, "context color buffer");
+ }
+
+ if (depthRenderbuffer != 0) {
+ if (depthBufferFormat == GL_DEPTH24_STENCIL8_OES) {
+ glLabelObjectEXT(GL_RENDERBUFFER, depthRenderbuffer, 0, "context depth-stencil buffer");
+ } else {
+ glLabelObjectEXT(GL_RENDERBUFFER, depthRenderbuffer, 0, "context depth buffer");
+ }
+ }
+
+ if (msaaFramebuffer != 0) {
+ glLabelObjectEXT(GL_FRAMEBUFFER, msaaFramebuffer, 0, "context MSAA FBO");
+ }
+
+ if (msaaRenderbuffer != 0) {
+ glLabelObjectEXT(GL_RENDERBUFFER, msaaRenderbuffer, 0, "context MSAA renderbuffer");
+ }
+}
+
+- (void)swapBuffers
+{
+ if (msaaFramebuffer) {
+ const GLenum attachments[] = {GL_COLOR_ATTACHMENT0};
+
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, viewFramebuffer);
+
+ /* OpenGL ES 3+ provides explicit MSAA resolves via glBlitFramebuffer.
+ * In OpenGL ES 1 and 2, MSAA resolves must be done via an extension. */
+ if (context.API >= kEAGLRenderingAPIOpenGLES3) {
+ int w = backingWidth;
+ int h = backingHeight;
+ glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);
+
+ if (!retainedBacking) {
+ /* Discard the contents of the MSAA drawable color buffer. */
+ glInvalidateFramebuffer(GL_READ_FRAMEBUFFER, 1, attachments);
+ }
+ } else {
+ glResolveMultisampleFramebufferAPPLE();
+
+ if (!retainedBacking) {
+ glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER, 1, attachments);
+ }
+ }
+
+ /* We assume the "drawable framebuffer" (MSAA draw framebuffer) was
+ * previously bound... */
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, msaaFramebuffer);
+ }
+
+ /* viewRenderbuffer should always be bound here. Code that binds something
+ * else is responsible for rebinding viewRenderbuffer, to reduce duplicate
+ * state changes. */
+ [context presentRenderbuffer:GL_RENDERBUFFER];
+}
+
+- (void)layoutSubviews
+{
+ [super layoutSubviews];
+
+ int width = (int) (self.bounds.size.width * self.contentScaleFactor);
+ int height = (int) (self.bounds.size.height * self.contentScaleFactor);
+
+ /* Update the color and depth buffer storage if the layer size has changed. */
+ if (width != backingWidth || height != backingHeight) {
+ EAGLContext *prevContext = [EAGLContext currentContext];
+ if (prevContext != context) {
+ [EAGLContext setCurrentContext:context];
+ }
+
+ [self updateFrame];
+
+ if (prevContext != context) {
+ [EAGLContext setCurrentContext:prevContext];
+ }
+ }
+}
+
+- (void)destroyFramebuffer
+{
+ if (viewFramebuffer != 0) {
+ glDeleteFramebuffers(1, &viewFramebuffer);
+ viewFramebuffer = 0;
+ }
+
+ if (viewRenderbuffer != 0) {
+ glDeleteRenderbuffers(1, &viewRenderbuffer);
+ viewRenderbuffer = 0;
+ }
+
+ if (depthRenderbuffer != 0) {
+ glDeleteRenderbuffers(1, &depthRenderbuffer);
+ depthRenderbuffer = 0;
+ }
+
+ if (msaaFramebuffer != 0) {
+ glDeleteFramebuffers(1, &msaaFramebuffer);
+ msaaFramebuffer = 0;
+ }
+
+ if (msaaRenderbuffer != 0) {
+ glDeleteRenderbuffers(1, &msaaRenderbuffer);
+ msaaRenderbuffer = 0;
+ }
+}
+
+- (void)dealloc
+{
+ if (context && context == [EAGLContext currentContext]) {
+ [self destroyFramebuffer];
+ [EAGLContext setCurrentContext:nil];
+ }
+}
+
+@end
+
+#endif /* SDL_VIDEO_DRIVER_UIKIT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitvideo.h b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitvideo.h
new file mode 100644
index 0000000..e24183a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitvideo.h
@@ -0,0 +1,46 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#ifndef SDL_uikitvideo_h_
+#define SDL_uikitvideo_h_
+
+#include "../SDL_sysvideo.h"
+
+#ifdef __OBJC__
+
+#include <UIKit/UIKit.h>
+
+@interface SDL_VideoData : NSObject
+
+@property (nonatomic, assign) id pasteboardObserver;
+
+@end
+
+CGRect UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen);
+
+#endif /* __OBJC__ */
+
+void UIKit_SuspendScreenSaver(_THIS);
+
+SDL_bool UIKit_IsSystemVersionAtLeast(double version);
+
+#endif /* SDL_uikitvideo_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitvideo.m b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitvideo.m
new file mode 100644
index 0000000..e74339f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitvideo.m
@@ -0,0 +1,238 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_UIKIT
+
+#import <UIKit/UIKit.h>
+
+#include "SDL_video.h"
+#include "SDL_mouse.h"
+#include "SDL_hints.h"
+#include "../SDL_sysvideo.h"
+#include "../SDL_pixels_c.h"
+#include "../../events/SDL_events_c.h"
+
+#include "SDL_uikitvideo.h"
+#include "SDL_uikitevents.h"
+#include "SDL_uikitmodes.h"
+#include "SDL_uikitwindow.h"
+#include "SDL_uikitopengles.h"
+#include "SDL_uikitclipboard.h"
+#include "SDL_uikitvulkan.h"
+
+#define UIKITVID_DRIVER_NAME "uikit"
+
+@implementation SDL_VideoData
+
+@end
+
+/* Initialization/Query functions */
+static int UIKit_VideoInit(_THIS);
+static void UIKit_VideoQuit(_THIS);
+
+/* DUMMY driver bootstrap functions */
+
+static int
+UIKit_Available(void)
+{
+ return 1;
+}
+
+static void UIKit_DeleteDevice(SDL_VideoDevice * device)
+{
+ @autoreleasepool {
+ CFRelease(device->driverdata);
+ SDL_free(device);
+ }
+}
+
+static SDL_VideoDevice *
+UIKit_CreateDevice(int devindex)
+{
+ @autoreleasepool {
+ SDL_VideoDevice *device;
+ SDL_VideoData *data;
+
+ /* Initialize all variables that we clean on shutdown */
+ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (device) {
+ data = [SDL_VideoData new];
+ } else {
+ SDL_free(device);
+ SDL_OutOfMemory();
+ return (0);
+ }
+
+ device->driverdata = (void *) CFBridgingRetain(data);
+
+ /* Set the function pointers */
+ device->VideoInit = UIKit_VideoInit;
+ device->VideoQuit = UIKit_VideoQuit;
+ device->GetDisplayModes = UIKit_GetDisplayModes;
+ device->SetDisplayMode = UIKit_SetDisplayMode;
+ device->PumpEvents = UIKit_PumpEvents;
+ device->SuspendScreenSaver = UIKit_SuspendScreenSaver;
+ device->CreateSDLWindow = UIKit_CreateWindow;
+ device->SetWindowTitle = UIKit_SetWindowTitle;
+ device->ShowWindow = UIKit_ShowWindow;
+ device->HideWindow = UIKit_HideWindow;
+ device->RaiseWindow = UIKit_RaiseWindow;
+ device->SetWindowBordered = UIKit_SetWindowBordered;
+ device->SetWindowFullscreen = UIKit_SetWindowFullscreen;
+ device->DestroyWindow = UIKit_DestroyWindow;
+ device->GetWindowWMInfo = UIKit_GetWindowWMInfo;
+ device->GetDisplayUsableBounds = UIKit_GetDisplayUsableBounds;
+
+#if SDL_IPHONE_KEYBOARD
+ device->HasScreenKeyboardSupport = UIKit_HasScreenKeyboardSupport;
+ device->ShowScreenKeyboard = UIKit_ShowScreenKeyboard;
+ device->HideScreenKeyboard = UIKit_HideScreenKeyboard;
+ device->IsScreenKeyboardShown = UIKit_IsScreenKeyboardShown;
+ device->SetTextInputRect = UIKit_SetTextInputRect;
+#endif
+
+ device->SetClipboardText = UIKit_SetClipboardText;
+ device->GetClipboardText = UIKit_GetClipboardText;
+ device->HasClipboardText = UIKit_HasClipboardText;
+
+ /* OpenGL (ES) functions */
+ device->GL_MakeCurrent = UIKit_GL_MakeCurrent;
+ device->GL_GetDrawableSize = UIKit_GL_GetDrawableSize;
+ device->GL_SwapWindow = UIKit_GL_SwapWindow;
+ device->GL_CreateContext = UIKit_GL_CreateContext;
+ device->GL_DeleteContext = UIKit_GL_DeleteContext;
+ device->GL_GetProcAddress = UIKit_GL_GetProcAddress;
+ device->GL_LoadLibrary = UIKit_GL_LoadLibrary;
+ device->free = UIKit_DeleteDevice;
+
+#if SDL_VIDEO_VULKAN
+ device->Vulkan_LoadLibrary = UIKit_Vulkan_LoadLibrary;
+ device->Vulkan_UnloadLibrary = UIKit_Vulkan_UnloadLibrary;
+ device->Vulkan_GetInstanceExtensions
+ = UIKit_Vulkan_GetInstanceExtensions;
+ device->Vulkan_CreateSurface = UIKit_Vulkan_CreateSurface;
+ device->Vulkan_GetDrawableSize = UIKit_Vulkan_GetDrawableSize;
+#endif
+
+ device->gl_config.accelerated = 1;
+
+ return device;
+ }
+}
+
+VideoBootStrap UIKIT_bootstrap = {
+ UIKITVID_DRIVER_NAME, "SDL UIKit video driver",
+ UIKit_Available, UIKit_CreateDevice
+};
+
+
+int
+UIKit_VideoInit(_THIS)
+{
+ _this->gl_config.driver_loaded = 1;
+
+ if (UIKit_InitModes(_this) < 0) {
+ return -1;
+ }
+ return 0;
+}
+
+void
+UIKit_VideoQuit(_THIS)
+{
+ UIKit_QuitModes(_this);
+}
+
+void
+UIKit_SuspendScreenSaver(_THIS)
+{
+ @autoreleasepool {
+ /* Ignore ScreenSaver API calls if the idle timer hint has been set. */
+ /* FIXME: The idle timer hint should be deprecated for SDL 2.1. */
+ if (!SDL_GetHintBoolean(SDL_HINT_IDLE_TIMER_DISABLED, SDL_FALSE)) {
+ UIApplication *app = [UIApplication sharedApplication];
+
+ /* Prevent the display from dimming and going to sleep. */
+ app.idleTimerDisabled = (_this->suspend_screensaver != SDL_FALSE);
+ }
+ }
+}
+
+SDL_bool
+UIKit_IsSystemVersionAtLeast(double version)
+{
+ return [[UIDevice currentDevice].systemVersion doubleValue] >= version;
+}
+
+CGRect
+UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
+{
+ CGRect frame = screen.bounds;
+
+#if !TARGET_OS_TV && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0)
+ BOOL hasiOS7 = UIKit_IsSystemVersionAtLeast(7.0);
+
+ /* The view should always show behind the status bar in iOS 7+. */
+ if (!hasiOS7 && !(window->flags & (SDL_WINDOW_BORDERLESS|SDL_WINDOW_FULLSCREEN))) {
+ frame = screen.applicationFrame;
+ }
+#endif
+
+#if !TARGET_OS_TV
+ /* iOS 10 seems to have a bug where, in certain conditions, putting the
+ * device to sleep with the a landscape-only app open, re-orienting the
+ * device to portrait, and turning it back on will result in the screen
+ * bounds returning portrait orientation despite the app being in landscape.
+ * This is a workaround until a better solution can be found.
+ * https://bugzilla.libsdl.org/show_bug.cgi?id=3505
+ * https://bugzilla.libsdl.org/show_bug.cgi?id=3465
+ * https://forums.developer.apple.com/thread/65337 */
+ if (UIKit_IsSystemVersionAtLeast(8.0)) {
+ UIInterfaceOrientation orient = [UIApplication sharedApplication].statusBarOrientation;
+ BOOL isLandscape = UIInterfaceOrientationIsLandscape(orient);
+
+ if (isLandscape != (frame.size.width > frame.size.height)) {
+ float height = frame.size.width;
+ frame.size.width = frame.size.height;
+ frame.size.height = height;
+ }
+ }
+#endif
+
+ return frame;
+}
+
+/*
+ * iOS log support.
+ *
+ * This doesn't really have aything to do with the interfaces of the SDL video
+ * subsystem, but we need to stuff this into an Objective-C source code file.
+ */
+
+void SDL_NSLog(const char *text)
+{
+ NSLog(@"%s", text);
+}
+
+#endif /* SDL_VIDEO_DRIVER_UIKIT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitview.h b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitview.h
new file mode 100644
index 0000000..4457f6c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitview.h
@@ -0,0 +1,41 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#import <UIKit/UIKit.h>
+
+#include "../SDL_sysvideo.h"
+
+#include "SDL_touch.h"
+
+@interface SDL_uikitview : UIView
+
+- (instancetype)initWithFrame:(CGRect)frame;
+
+- (void)setSDLWindow:(SDL_Window *)window;
+
+- (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize;
+- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
+- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
+- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
+
+@end
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitview.m b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitview.m
new file mode 100644
index 0000000..bd60c55
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitview.m
@@ -0,0 +1,328 @@
+ /*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_UIKIT
+
+#include "SDL_uikitview.h"
+
+#include "SDL_hints.h"
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_touch_c.h"
+#include "../../events/SDL_events_c.h"
+
+#import "SDL_uikitappdelegate.h"
+#import "SDL_uikitmodes.h"
+#import "SDL_uikitwindow.h"
+
+/* This is defined in SDL_sysjoystick.m */
+extern int SDL_AppleTVRemoteOpenedAsJoystick;
+
+@implementation SDL_uikitview {
+ SDL_Window *sdlwindow;
+
+ SDL_TouchID touchId;
+ UITouch * __weak firstFingerDown;
+}
+
+- (instancetype)initWithFrame:(CGRect)frame
+{
+ if ((self = [super initWithFrame:frame])) {
+#if TARGET_OS_TV
+ /* Apple TV Remote touchpad swipe gestures. */
+ UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
+ swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
+ [self addGestureRecognizer:swipeUp];
+
+ UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
+ swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
+ [self addGestureRecognizer:swipeDown];
+
+ UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
+ swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
+ [self addGestureRecognizer:swipeLeft];
+
+ UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
+ swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
+ [self addGestureRecognizer:swipeRight];
+#endif
+
+ self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ self.autoresizesSubviews = YES;
+
+#if !TARGET_OS_TV
+ self.multipleTouchEnabled = YES;
+#endif
+
+ touchId = 1;
+ SDL_AddTouch(touchId, "");
+ }
+
+ return self;
+}
+
+- (void)setSDLWindow:(SDL_Window *)window
+{
+ SDL_WindowData *data = nil;
+
+ if (window == sdlwindow) {
+ return;
+ }
+
+ /* Remove ourself from the old window. */
+ if (sdlwindow) {
+ SDL_uikitview *view = nil;
+ data = (__bridge SDL_WindowData *) sdlwindow->driverdata;
+
+ [data.views removeObject:self];
+
+ [self removeFromSuperview];
+
+ /* Restore the next-oldest view in the old window. */
+ view = data.views.lastObject;
+
+ data.viewcontroller.view = view;
+
+ data.uiwindow.rootViewController = nil;
+ data.uiwindow.rootViewController = data.viewcontroller;
+
+ [data.uiwindow layoutIfNeeded];
+ }
+
+ /* Add ourself to the new window. */
+ if (window) {
+ data = (__bridge SDL_WindowData *) window->driverdata;
+
+ /* Make sure the SDL window has a strong reference to this view. */
+ [data.views addObject:self];
+
+ /* Replace the view controller's old view with this one. */
+ [data.viewcontroller.view removeFromSuperview];
+ data.viewcontroller.view = self;
+
+ /* The root view controller handles rotation and the status bar.
+ * Assigning it also adds the controller's view to the window. We
+ * explicitly re-set it to make sure the view is properly attached to
+ * the window. Just adding the sub-view if the root view controller is
+ * already correct causes orientation issues on iOS 7 and below. */
+ data.uiwindow.rootViewController = nil;
+ data.uiwindow.rootViewController = data.viewcontroller;
+
+ /* The view's bounds may not be correct until the next event cycle. That
+ * might happen after the current dimensions are queried, so we force a
+ * layout now to immediately update the bounds. */
+ [data.uiwindow layoutIfNeeded];
+ }
+
+ sdlwindow = window;
+}
+
+- (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize
+{
+ CGPoint point = [touch locationInView:self];
+
+ if (normalize) {
+ CGRect bounds = self.bounds;
+ point.x /= bounds.size.width;
+ point.y /= bounds.size.height;
+ }
+
+ return point;
+}
+
+- (float)pressureForTouch:(UITouch *)touch
+{
+#ifdef __IPHONE_9_0
+ if ([touch respondsToSelector:@selector(force)]) {
+ return (float) touch.force;
+ }
+#endif
+
+ return 1.0f;
+}
+
+- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ for (UITouch *touch in touches) {
+ float pressure = [self pressureForTouch:touch];
+
+ if (!firstFingerDown) {
+ CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
+ int clicks = (int) touch.tapCount;
+
+ /* send mouse moved event */
+ SDL_SendMouseMotion(sdlwindow, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
+
+ /* send mouse down event */
+ SDL_SendMouseButtonClicks(sdlwindow, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT, clicks);
+
+ firstFingerDown = touch;
+ }
+
+ CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
+ SDL_SendTouch(touchId, (SDL_FingerID)((size_t)touch),
+ SDL_TRUE, locationInView.x, locationInView.y, pressure);
+ }
+}
+
+- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ for (UITouch *touch in touches) {
+ float pressure = [self pressureForTouch:touch];
+
+ if (touch == firstFingerDown) {
+ /* send mouse up */
+ int clicks = (int) touch.tapCount;
+ SDL_SendMouseButtonClicks(sdlwindow, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT, clicks);
+ firstFingerDown = nil;
+ }
+
+ CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
+ SDL_SendTouch(touchId, (SDL_FingerID)((size_t)touch),
+ SDL_FALSE, locationInView.x, locationInView.y, pressure);
+ }
+}
+
+- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ [self touchesEnded:touches withEvent:event];
+}
+
+- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
+{
+ for (UITouch *touch in touches) {
+ float pressure = [self pressureForTouch:touch];
+
+ if (touch == firstFingerDown) {
+ CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
+
+ /* send moved event */
+ SDL_SendMouseMotion(sdlwindow, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
+ }
+
+ CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
+ SDL_SendTouchMotion(touchId, (SDL_FingerID)((size_t)touch),
+ locationInView.x, locationInView.y, pressure);
+ }
+}
+
+#if TARGET_OS_TV || defined(__IPHONE_9_1)
+- (SDL_Scancode)scancodeFromPressType:(UIPressType)presstype
+{
+ switch (presstype) {
+ case UIPressTypeUpArrow:
+ return SDL_SCANCODE_UP;
+ case UIPressTypeDownArrow:
+ return SDL_SCANCODE_DOWN;
+ case UIPressTypeLeftArrow:
+ return SDL_SCANCODE_LEFT;
+ case UIPressTypeRightArrow:
+ return SDL_SCANCODE_RIGHT;
+ case UIPressTypeSelect:
+ /* HIG says: "primary button behavior" */
+ return SDL_SCANCODE_RETURN;
+ case UIPressTypeMenu:
+ /* HIG says: "returns to previous screen" */
+ return SDL_SCANCODE_ESCAPE;
+ case UIPressTypePlayPause:
+ /* HIG says: "secondary button behavior" */
+ return SDL_SCANCODE_PAUSE;
+ default:
+ return SDL_SCANCODE_UNKNOWN;
+ }
+}
+
+- (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
+{
+ if (!SDL_AppleTVRemoteOpenedAsJoystick) {
+ for (UIPress *press in presses) {
+ SDL_Scancode scancode = [self scancodeFromPressType:press.type];
+ SDL_SendKeyboardKey(SDL_PRESSED, scancode);
+ }
+ }
+ [super pressesBegan:presses withEvent:event];
+}
+
+- (void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
+{
+ if (!SDL_AppleTVRemoteOpenedAsJoystick) {
+ for (UIPress *press in presses) {
+ SDL_Scancode scancode = [self scancodeFromPressType:press.type];
+ SDL_SendKeyboardKey(SDL_RELEASED, scancode);
+ }
+ }
+ [super pressesEnded:presses withEvent:event];
+}
+
+- (void)pressesCancelled:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
+{
+ if (!SDL_AppleTVRemoteOpenedAsJoystick) {
+ for (UIPress *press in presses) {
+ SDL_Scancode scancode = [self scancodeFromPressType:press.type];
+ SDL_SendKeyboardKey(SDL_RELEASED, scancode);
+ }
+ }
+ [super pressesCancelled:presses withEvent:event];
+}
+
+- (void)pressesChanged:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
+{
+ /* This is only called when the force of a press changes. */
+ [super pressesChanged:presses withEvent:event];
+}
+#endif /* TARGET_OS_TV || defined(__IPHONE_9_1) */
+
+#if TARGET_OS_TV
+-(void)swipeGesture:(UISwipeGestureRecognizer *)gesture
+{
+ /* Swipe gestures don't trigger begin states. */
+ if (gesture.state == UIGestureRecognizerStateEnded) {
+ if (!SDL_AppleTVRemoteOpenedAsJoystick) {
+ /* Send arrow key presses for now, as we don't have an external API
+ * which better maps to swipe gestures. */
+ switch (gesture.direction) {
+ case UISwipeGestureRecognizerDirectionUp:
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_UP);
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_UP);
+ break;
+ case UISwipeGestureRecognizerDirectionDown:
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_DOWN);
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_DOWN);
+ break;
+ case UISwipeGestureRecognizerDirectionLeft:
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LEFT);
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LEFT);
+ break;
+ case UISwipeGestureRecognizerDirectionRight:
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RIGHT);
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RIGHT);
+ break;
+ }
+ }
+ }
+}
+#endif /* TARGET_OS_TV */
+
+@end
+
+#endif /* SDL_VIDEO_DRIVER_UIKIT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitviewcontroller.h b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitviewcontroller.h
new file mode 100644
index 0000000..fffb142
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitviewcontroller.h
@@ -0,0 +1,91 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#import <UIKit/UIKit.h>
+
+#include "../SDL_sysvideo.h"
+
+#include "SDL_touch.h"
+
+#if TARGET_OS_TV
+#import <GameController/GameController.h>
+#define SDLRootViewController GCEventViewController
+#else
+#define SDLRootViewController UIViewController
+#endif
+
+#if SDL_IPHONE_KEYBOARD
+@interface SDL_uikitviewcontroller : SDLRootViewController <UITextFieldDelegate>
+#else
+@interface SDL_uikitviewcontroller : SDLRootViewController
+#endif
+
+@property (nonatomic, assign) SDL_Window *window;
+
+- (instancetype)initWithSDLWindow:(SDL_Window *)_window;
+
+- (void)setAnimationCallback:(int)interval
+ callback:(void (*)(void*))callback
+ callbackParam:(void*)callbackParam;
+
+- (void)startAnimation;
+- (void)stopAnimation;
+
+- (void)doLoop:(CADisplayLink*)sender;
+
+- (void)loadView;
+- (void)viewDidLayoutSubviews;
+
+#if !TARGET_OS_TV
+- (NSUInteger)supportedInterfaceOrientations;
+- (BOOL)prefersStatusBarHidden;
+- (BOOL)prefersHomeIndicatorAutoHidden;
+- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures;
+
+@property (nonatomic, assign) int homeIndicatorHidden;
+#endif
+
+#if SDL_IPHONE_KEYBOARD
+- (void)showKeyboard;
+- (void)hideKeyboard;
+- (void)initKeyboard;
+- (void)deinitKeyboard;
+
+- (void)keyboardWillShow:(NSNotification *)notification;
+- (void)keyboardWillHide:(NSNotification *)notification;
+
+- (void)updateKeyboard;
+
+@property (nonatomic, assign, getter=isKeyboardVisible) BOOL keyboardVisible;
+@property (nonatomic, assign) SDL_Rect textInputRect;
+@property (nonatomic, assign) int keyboardHeight;
+#endif
+
+@end
+
+#if SDL_IPHONE_KEYBOARD
+SDL_bool UIKit_HasScreenKeyboardSupport(_THIS);
+void UIKit_ShowScreenKeyboard(_THIS, SDL_Window *window);
+void UIKit_HideScreenKeyboard(_THIS, SDL_Window *window);
+SDL_bool UIKit_IsScreenKeyboardShown(_THIS, SDL_Window *window);
+void UIKit_SetTextInputRect(_THIS, SDL_Rect *rect);
+#endif
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitviewcontroller.m b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitviewcontroller.m
new file mode 100644
index 0000000..2962742
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitviewcontroller.m
@@ -0,0 +1,532 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_UIKIT
+
+#include "SDL_video.h"
+#include "SDL_assert.h"
+#include "SDL_hints.h"
+#include "../SDL_sysvideo.h"
+#include "../../events/SDL_events_c.h"
+
+#import "SDL_uikitviewcontroller.h"
+#import "SDL_uikitmessagebox.h"
+#include "SDL_uikitvideo.h"
+#include "SDL_uikitmodes.h"
+#include "SDL_uikitwindow.h"
+#include "SDL_uikitopengles.h"
+
+#if SDL_IPHONE_KEYBOARD
+#include "keyinfotable.h"
+#endif
+
+#if TARGET_OS_TV
+static void SDLCALL
+SDL_AppleTVControllerUIHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+{
+ @autoreleasepool {
+ SDL_uikitviewcontroller *viewcontroller = (__bridge SDL_uikitviewcontroller *) userdata;
+ viewcontroller.controllerUserInteractionEnabled = hint && (*hint != '0');
+ }
+}
+#endif
+
+#if !TARGET_OS_TV
+static void SDLCALL
+SDL_HideHomeIndicatorHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
+{
+ @autoreleasepool {
+ SDL_uikitviewcontroller *viewcontroller = (__bridge SDL_uikitviewcontroller *) userdata;
+ viewcontroller.homeIndicatorHidden = (hint && *hint) ? SDL_atoi(hint) : -1;
+ if (@available(iOS 11.0, *)) {
+ [viewcontroller setNeedsUpdateOfHomeIndicatorAutoHidden];
+ [viewcontroller setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
+ }
+ }
+}
+#endif
+
+@implementation SDL_uikitviewcontroller {
+ CADisplayLink *displayLink;
+ int animationInterval;
+ void (*animationCallback)(void*);
+ void *animationCallbackParam;
+
+#if SDL_IPHONE_KEYBOARD
+ UITextField *textField;
+ BOOL rotatingOrientation;
+#endif
+}
+
+@synthesize window;
+
+- (instancetype)initWithSDLWindow:(SDL_Window *)_window
+{
+ if (self = [super initWithNibName:nil bundle:nil]) {
+ self.window = _window;
+
+#if SDL_IPHONE_KEYBOARD
+ [self initKeyboard];
+ rotatingOrientation = FALSE;
+#endif
+
+#if TARGET_OS_TV
+ SDL_AddHintCallback(SDL_HINT_APPLE_TV_CONTROLLER_UI_EVENTS,
+ SDL_AppleTVControllerUIHintChanged,
+ (__bridge void *) self);
+#endif
+
+#if !TARGET_OS_TV
+ SDL_AddHintCallback(SDL_HINT_IOS_HIDE_HOME_INDICATOR,
+ SDL_HideHomeIndicatorHintChanged,
+ (__bridge void *) self);
+#endif
+ }
+ return self;
+}
+
+- (void)dealloc
+{
+#if SDL_IPHONE_KEYBOARD
+ [self deinitKeyboard];
+#endif
+
+#if TARGET_OS_TV
+ SDL_DelHintCallback(SDL_HINT_APPLE_TV_CONTROLLER_UI_EVENTS,
+ SDL_AppleTVControllerUIHintChanged,
+ (__bridge void *) self);
+#endif
+
+#if !TARGET_OS_TV
+ SDL_DelHintCallback(SDL_HINT_IOS_HIDE_HOME_INDICATOR,
+ SDL_HideHomeIndicatorHintChanged,
+ (__bridge void *) self);
+#endif
+}
+
+- (void)setAnimationCallback:(int)interval
+ callback:(void (*)(void*))callback
+ callbackParam:(void*)callbackParam
+{
+ [self stopAnimation];
+
+ animationInterval = interval;
+ animationCallback = callback;
+ animationCallbackParam = callbackParam;
+
+ if (animationCallback) {
+ [self startAnimation];
+ }
+}
+
+- (void)startAnimation
+{
+ displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)];
+
+#ifdef __IPHONE_10_3
+ SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
+
+ if ([displayLink respondsToSelector:@selector(preferredFramesPerSecond)]
+ && data != nil && data.uiwindow != nil
+ && [data.uiwindow.screen respondsToSelector:@selector(maximumFramesPerSecond)]) {
+ displayLink.preferredFramesPerSecond = data.uiwindow.screen.maximumFramesPerSecond / animationInterval;
+ } else
+#endif
+ {
+#if __IPHONE_OS_VERSION_MIN_REQUIRED < 100300
+ [displayLink setFrameInterval:animationInterval];
+#endif
+ }
+
+ [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
+}
+
+- (void)stopAnimation
+{
+ [displayLink invalidate];
+ displayLink = nil;
+}
+
+- (void)doLoop:(CADisplayLink*)sender
+{
+ /* Don't run the game loop while a messagebox is up */
+ if (!UIKit_ShowingMessageBox()) {
+ /* See the comment in the function definition. */
+ UIKit_GL_RestoreCurrentContext();
+
+ animationCallback(animationCallbackParam);
+ }
+}
+
+- (void)loadView
+{
+ /* Do nothing. */
+}
+
+- (void)viewDidLayoutSubviews
+{
+ const CGSize size = self.view.bounds.size;
+ int w = (int) size.width;
+ int h = (int) size.height;
+
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
+}
+
+#if !TARGET_OS_TV
+- (NSUInteger)supportedInterfaceOrientations
+{
+ return UIKit_GetSupportedOrientations(window);
+}
+
+#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient
+{
+ return ([self supportedInterfaceOrientations] & (1 << orient)) != 0;
+}
+#endif
+
+- (BOOL)prefersStatusBarHidden
+{
+ BOOL hidden = (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) != 0;
+ return hidden;
+}
+
+- (BOOL)prefersHomeIndicatorAutoHidden
+{
+ BOOL hidden = NO;
+ if (self.homeIndicatorHidden == 1) {
+ hidden = YES;
+ }
+ return hidden;
+}
+
+- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
+{
+ if (self.homeIndicatorHidden >= 0) {
+ if (self.homeIndicatorHidden == 2) {
+ return UIRectEdgeAll;
+ } else {
+ return UIRectEdgeNone;
+ }
+ }
+
+ /* By default, fullscreen and borderless windows get all screen gestures */
+ if ((window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) != 0) {
+ return UIRectEdgeAll;
+ } else {
+ return UIRectEdgeNone;
+ }
+}
+#endif
+
+/*
+ ---- Keyboard related functionality below this line ----
+ */
+#if SDL_IPHONE_KEYBOARD
+
+@synthesize textInputRect;
+@synthesize keyboardHeight;
+@synthesize keyboardVisible;
+
+/* Set ourselves up as a UITextFieldDelegate */
+- (void)initKeyboard
+{
+ textField = [[UITextField alloc] initWithFrame:CGRectZero];
+ textField.delegate = self;
+ /* placeholder so there is something to delete! */
+ textField.text = @" ";
+
+ /* set UITextInputTrait properties, mostly to defaults */
+ textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
+ textField.autocorrectionType = UITextAutocorrectionTypeNo;
+ textField.enablesReturnKeyAutomatically = NO;
+ textField.keyboardAppearance = UIKeyboardAppearanceDefault;
+ textField.keyboardType = UIKeyboardTypeDefault;
+ textField.returnKeyType = UIReturnKeyDefault;
+ textField.secureTextEntry = NO;
+
+ textField.hidden = YES;
+ keyboardVisible = NO;
+
+#if !TARGET_OS_TV
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+ [center addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
+ [center addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
+#endif
+}
+
+- (void)setView:(UIView *)view
+{
+ [super setView:view];
+
+ [view addSubview:textField];
+
+ if (keyboardVisible) {
+ [self showKeyboard];
+ }
+}
+
+/* willRotateToInterfaceOrientation and didRotateFromInterfaceOrientation are deprecated in iOS 8+ in favor of viewWillTransitionToSize */
+#if TARGET_OS_TV || __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000
+- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
+{
+ [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
+ rotatingOrientation = TRUE;
+ [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {}
+ completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
+ rotatingOrientation = FALSE;
+ }];
+}
+#else
+- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
+ [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
+ rotatingOrientation = TRUE;
+}
+
+- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
+ [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
+ rotatingOrientation = FALSE;
+}
+#endif /* TARGET_OS_TV || __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000 */
+
+- (void)deinitKeyboard
+{
+#if !TARGET_OS_TV
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+ [center removeObserver:self name:UIKeyboardWillShowNotification object:nil];
+ [center removeObserver:self name:UIKeyboardWillHideNotification object:nil];
+#endif
+}
+
+/* reveal onscreen virtual keyboard */
+- (void)showKeyboard
+{
+ keyboardVisible = YES;
+ if (textField.window) {
+ [textField becomeFirstResponder];
+ }
+}
+
+/* hide onscreen virtual keyboard */
+- (void)hideKeyboard
+{
+ keyboardVisible = NO;
+ [textField resignFirstResponder];
+}
+
+- (void)keyboardWillShow:(NSNotification *)notification
+{
+#if !TARGET_OS_TV
+ CGRect kbrect = [[notification userInfo][UIKeyboardFrameEndUserInfoKey] CGRectValue];
+
+ /* The keyboard rect is in the coordinate space of the screen/window, but we
+ * want its height in the coordinate space of the view. */
+ kbrect = [self.view convertRect:kbrect fromView:nil];
+
+ [self setKeyboardHeight:(int)kbrect.size.height];
+#endif
+}
+
+- (void)keyboardWillHide:(NSNotification *)notification
+{
+ if (!rotatingOrientation) {
+ SDL_StopTextInput();
+ }
+ [self setKeyboardHeight:0];
+}
+
+- (void)updateKeyboard
+{
+ CGAffineTransform t = self.view.transform;
+ CGPoint offset = CGPointMake(0.0, 0.0);
+ CGRect frame = UIKit_ComputeViewFrame(window, self.view.window.screen);
+
+ if (self.keyboardHeight) {
+ int rectbottom = self.textInputRect.y + self.textInputRect.h;
+ int keybottom = self.view.bounds.size.height - self.keyboardHeight;
+ if (keybottom < rectbottom) {
+ offset.y = keybottom - rectbottom;
+ }
+ }
+
+ /* Apply this view's transform (except any translation) to the offset, in
+ * order to orient it correctly relative to the frame's coordinate space. */
+ t.tx = 0.0;
+ t.ty = 0.0;
+ offset = CGPointApplyAffineTransform(offset, t);
+
+ /* Apply the updated offset to the view's frame. */
+ frame.origin.x += offset.x;
+ frame.origin.y += offset.y;
+
+ self.view.frame = frame;
+}
+
+- (void)setKeyboardHeight:(int)height
+{
+ keyboardVisible = height > 0;
+ keyboardHeight = height;
+ [self updateKeyboard];
+}
+
+/* UITextFieldDelegate method. Invoked when user types something. */
+- (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
+{
+ NSUInteger len = string.length;
+
+ if (len == 0) {
+ /* it wants to replace text with nothing, ie a delete */
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_BACKSPACE);
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_BACKSPACE);
+ } else {
+ /* go through all the characters in the string we've been sent and
+ * convert them to key presses */
+ int i;
+ for (i = 0; i < len; i++) {
+ unichar c = [string characterAtIndex:i];
+ Uint16 mod = 0;
+ SDL_Scancode code;
+
+ if (c < 127) {
+ /* figure out the SDL_Scancode and SDL_keymod for this unichar */
+ code = unicharToUIKeyInfoTable[c].code;
+ mod = unicharToUIKeyInfoTable[c].mod;
+ } else {
+ /* we only deal with ASCII right now */
+ code = SDL_SCANCODE_UNKNOWN;
+ mod = 0;
+ }
+
+ if (mod & KMOD_SHIFT) {
+ /* If character uses shift, press shift down */
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT);
+ }
+
+ /* send a keydown and keyup even for the character */
+ SDL_SendKeyboardKey(SDL_PRESSED, code);
+ SDL_SendKeyboardKey(SDL_RELEASED, code);
+
+ if (mod & KMOD_SHIFT) {
+ /* If character uses shift, press shift back up */
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
+ }
+ }
+
+ SDL_SendKeyboardText([string UTF8String]);
+ }
+
+ return NO; /* don't allow the edit! (keep placeholder text there) */
+}
+
+/* Terminates the editing session */
+- (BOOL)textFieldShouldReturn:(UITextField*)_textField
+{
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RETURN);
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RETURN);
+ if (SDL_GetHintBoolean(SDL_HINT_RETURN_KEY_HIDES_IME, SDL_FALSE)) {
+ SDL_StopTextInput();
+ }
+ return YES;
+}
+
+#endif
+
+@end
+
+/* iPhone keyboard addition functions */
+#if SDL_IPHONE_KEYBOARD
+
+static SDL_uikitviewcontroller *
+GetWindowViewController(SDL_Window * window)
+{
+ if (!window || !window->driverdata) {
+ SDL_SetError("Invalid window");
+ return nil;
+ }
+
+ SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
+
+ return data.viewcontroller;
+}
+
+SDL_bool
+UIKit_HasScreenKeyboardSupport(_THIS)
+{
+ return SDL_TRUE;
+}
+
+void
+UIKit_ShowScreenKeyboard(_THIS, SDL_Window *window)
+{
+ @autoreleasepool {
+ SDL_uikitviewcontroller *vc = GetWindowViewController(window);
+ [vc showKeyboard];
+ }
+}
+
+void
+UIKit_HideScreenKeyboard(_THIS, SDL_Window *window)
+{
+ @autoreleasepool {
+ SDL_uikitviewcontroller *vc = GetWindowViewController(window);
+ [vc hideKeyboard];
+ }
+}
+
+SDL_bool
+UIKit_IsScreenKeyboardShown(_THIS, SDL_Window *window)
+{
+ @autoreleasepool {
+ SDL_uikitviewcontroller *vc = GetWindowViewController(window);
+ if (vc != nil) {
+ return vc.isKeyboardVisible;
+ }
+ return SDL_FALSE;
+ }
+}
+
+void
+UIKit_SetTextInputRect(_THIS, SDL_Rect *rect)
+{
+ if (!rect) {
+ SDL_InvalidParamError("rect");
+ return;
+ }
+
+ @autoreleasepool {
+ SDL_uikitviewcontroller *vc = GetWindowViewController(SDL_GetFocusWindow());
+ if (vc != nil) {
+ vc.textInputRect = *rect;
+
+ if (vc.keyboardVisible) {
+ [vc updateKeyboard];
+ }
+ }
+ }
+}
+
+
+#endif /* SDL_IPHONE_KEYBOARD */
+
+#endif /* SDL_VIDEO_DRIVER_UIKIT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitvulkan.h b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitvulkan.h
new file mode 100644
index 0000000..e3ec350
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitvulkan.h
@@ -0,0 +1,54 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ * @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's
+ * SDL_x11vulkan.h.
+ */
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_uikitvulkan_h_
+#define SDL_uikitvulkan_h_
+
+#include "../SDL_vulkan_internal.h"
+#include "../SDL_sysvideo.h"
+
+#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_UIKIT
+
+int UIKit_Vulkan_LoadLibrary(_THIS, const char *path);
+void UIKit_Vulkan_UnloadLibrary(_THIS);
+SDL_bool UIKit_Vulkan_GetInstanceExtensions(_THIS,
+ SDL_Window *window,
+ unsigned *count,
+ const char **names);
+SDL_bool UIKit_Vulkan_CreateSurface(_THIS,
+ SDL_Window *window,
+ VkInstance instance,
+ VkSurfaceKHR *surface);
+
+void UIKit_Vulkan_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h);
+
+#endif
+
+#endif /* SDL_uikitvulkan_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitvulkan.m b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitvulkan.m
new file mode 100644
index 0000000..771c7a4
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitvulkan.m
@@ -0,0 +1,222 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ * @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's
+ * SDL_x11vulkan.c.
+ */
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_UIKIT
+
+#include "SDL_uikitvideo.h"
+#include "SDL_uikitwindow.h"
+#include "SDL_assert.h"
+
+#include "SDL_loadso.h"
+#include "SDL_uikitvulkan.h"
+#include "SDL_uikitmetalview.h"
+#include "SDL_syswm.h"
+
+#include <dlfcn.h>
+
+#define DEFAULT_MOLTENVK "libMoltenVK.dylib"
+/* Since libSDL is static, could use RTLD_SELF. Using RTLD_DEFAULT is future
+ * proofing. */
+#define DEFAULT_HANDLE RTLD_DEFAULT
+
+int UIKit_Vulkan_LoadLibrary(_THIS, const char *path)
+{
+ VkExtensionProperties *extensions = NULL;
+ Uint32 extensionCount = 0;
+ SDL_bool hasSurfaceExtension = SDL_FALSE;
+ SDL_bool hasIOSSurfaceExtension = SDL_FALSE;
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
+
+ if (_this->vulkan_config.loader_handle) {
+ return SDL_SetError("MoltenVK/Vulkan already loaded");
+ }
+
+ /* Load the Vulkan loader library */
+ if (!path) {
+ path = SDL_getenv("SDL_VULKAN_LIBRARY");
+ }
+
+ if (!path) {
+ /* MoltenVK framework, currently, v0.17.0, has a static library and is
+ * the recommended way to use the package. There is likely no object to
+ * load. */
+ vkGetInstanceProcAddr =
+ (PFN_vkGetInstanceProcAddr)dlsym(DEFAULT_HANDLE,
+ "vkGetInstanceProcAddr");
+ }
+
+ if (vkGetInstanceProcAddr) {
+ _this->vulkan_config.loader_handle = DEFAULT_HANDLE;
+ } else {
+ if (!path) {
+ /* Look for the .dylib packaged with the application instead. */
+ path = DEFAULT_MOLTENVK;
+ }
+
+ _this->vulkan_config.loader_handle = SDL_LoadObject(path);
+ if (!_this->vulkan_config.loader_handle) {
+ return -1;
+ }
+ SDL_strlcpy(_this->vulkan_config.loader_path, path,
+ SDL_arraysize(_this->vulkan_config.loader_path));
+ vkGetInstanceProcAddr =
+ (PFN_vkGetInstanceProcAddr)SDL_LoadFunction(
+ _this->vulkan_config.loader_handle,
+ "vkGetInstanceProcAddr");
+ }
+
+ if (!vkGetInstanceProcAddr) {
+ SDL_SetError("Failed to find %s in either executable or %s: %s",
+ "vkGetInstanceProcAddr",
+ DEFAULT_MOLTENVK,
+ (const char *) dlerror());
+ goto fail;
+ }
+
+ _this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr;
+ _this->vulkan_config.vkEnumerateInstanceExtensionProperties =
+ (void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)(
+ VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties");
+
+ if (!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) {
+ SDL_SetError("No vkEnumerateInstanceExtensionProperties found.");
+ goto fail;
+ }
+
+ extensions = SDL_Vulkan_CreateInstanceExtensionsList(
+ (PFN_vkEnumerateInstanceExtensionProperties)
+ _this->vulkan_config.vkEnumerateInstanceExtensionProperties,
+ &extensionCount);
+
+ if (!extensions) {
+ goto fail;
+ }
+
+ for (Uint32 i = 0; i < extensionCount; i++) {
+ if (SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) {
+ hasSurfaceExtension = SDL_TRUE;
+ } else if (SDL_strcmp(VK_MVK_IOS_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) {
+ hasIOSSurfaceExtension = SDL_TRUE;
+ }
+ }
+
+ SDL_free(extensions);
+
+ if (!hasSurfaceExtension) {
+ SDL_SetError("Installed MoltenVK/Vulkan doesn't implement the "
+ VK_KHR_SURFACE_EXTENSION_NAME " extension");
+ goto fail;
+ } else if (!hasIOSSurfaceExtension) {
+ SDL_SetError("Installed MoltenVK/Vulkan doesn't implement the "
+ VK_MVK_IOS_SURFACE_EXTENSION_NAME "extension");
+ goto fail;
+ }
+
+ return 0;
+
+fail:
+ _this->vulkan_config.loader_handle = NULL;
+ return -1;
+}
+
+void UIKit_Vulkan_UnloadLibrary(_THIS)
+{
+ if (_this->vulkan_config.loader_handle) {
+ if (_this->vulkan_config.loader_handle != DEFAULT_HANDLE) {
+ SDL_UnloadObject(_this->vulkan_config.loader_handle);
+ }
+ _this->vulkan_config.loader_handle = NULL;
+ }
+}
+
+SDL_bool UIKit_Vulkan_GetInstanceExtensions(_THIS,
+ SDL_Window *window,
+ unsigned *count,
+ const char **names)
+{
+ static const char *const extensionsForUIKit[] = {
+ VK_KHR_SURFACE_EXTENSION_NAME, VK_MVK_IOS_SURFACE_EXTENSION_NAME
+ };
+ if (!_this->vulkan_config.loader_handle) {
+ SDL_SetError("Vulkan is not loaded");
+ return SDL_FALSE;
+ }
+
+ return SDL_Vulkan_GetInstanceExtensions_Helper(
+ count, names, SDL_arraysize(extensionsForUIKit),
+ extensionsForUIKit);
+}
+
+SDL_bool UIKit_Vulkan_CreateSurface(_THIS,
+ SDL_Window *window,
+ VkInstance instance,
+ VkSurfaceKHR *surface)
+{
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
+ (PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr;
+ PFN_vkCreateIOSSurfaceMVK vkCreateIOSSurfaceMVK =
+ (PFN_vkCreateIOSSurfaceMVK)vkGetInstanceProcAddr(
+ (VkInstance)instance,
+ "vkCreateIOSSurfaceMVK");
+ VkIOSSurfaceCreateInfoMVK createInfo = {};
+ VkResult result;
+
+ if (!_this->vulkan_config.loader_handle) {
+ SDL_SetError("Vulkan is not loaded");
+ return SDL_FALSE;
+ }
+
+ if (!vkCreateIOSSurfaceMVK) {
+ SDL_SetError(VK_MVK_IOS_SURFACE_EXTENSION_NAME
+ " extension is not enabled in the Vulkan instance.");
+ return SDL_FALSE;
+ }
+
+ createInfo.sType = VK_STRUCTURE_TYPE_IOS_SURFACE_CREATE_INFO_MVK;
+ createInfo.pNext = NULL;
+ createInfo.flags = 0;
+ createInfo.pView = (__bridge void *)UIKit_Mtl_AddMetalView(window);
+ result = vkCreateIOSSurfaceMVK(instance, &createInfo,
+ NULL, surface);
+ if (result != VK_SUCCESS) {
+ SDL_SetError("vkCreateIOSSurfaceMVK failed: %s",
+ SDL_Vulkan_GetResultString(result));
+ return SDL_FALSE;
+ }
+
+ return SDL_TRUE;
+}
+
+void UIKit_Vulkan_GetDrawableSize(_THIS, SDL_Window *window, int *w, int *h)
+{
+ UIKit_Mtl_GetDrawableSize(window, w, h);
+}
+
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitwindow.h b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitwindow.h
new file mode 100644
index 0000000..46073ee
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitwindow.h
@@ -0,0 +1,56 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#ifndef SDL_uikitwindow_h_
+#define SDL_uikitwindow_h_
+
+#include "../SDL_sysvideo.h"
+#import "SDL_uikitvideo.h"
+#import "SDL_uikitview.h"
+#import "SDL_uikitviewcontroller.h"
+
+extern int UIKit_CreateWindow(_THIS, SDL_Window * window);
+extern void UIKit_SetWindowTitle(_THIS, SDL_Window * window);
+extern void UIKit_ShowWindow(_THIS, SDL_Window * window);
+extern void UIKit_HideWindow(_THIS, SDL_Window * window);
+extern void UIKit_RaiseWindow(_THIS, SDL_Window * window);
+extern void UIKit_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
+extern void UIKit_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
+extern void UIKit_DestroyWindow(_THIS, SDL_Window * window);
+extern SDL_bool UIKit_GetWindowWMInfo(_THIS, SDL_Window * window,
+ struct SDL_SysWMinfo * info);
+
+extern NSUInteger UIKit_GetSupportedOrientations(SDL_Window * window);
+
+@class UIWindow;
+
+@interface SDL_WindowData : NSObject
+
+@property (nonatomic, strong) UIWindow *uiwindow;
+@property (nonatomic, strong) SDL_uikitviewcontroller *viewcontroller;
+
+/* Array of SDL_uikitviews owned by this window. */
+@property (nonatomic, copy) NSMutableArray *views;
+
+@end
+
+#endif /* SDL_uikitwindow_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/SDL_uikitwindow.m b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitwindow.m
new file mode 100644
index 0000000..d01cff3
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/SDL_uikitwindow.m
@@ -0,0 +1,465 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_UIKIT
+
+#include "SDL_syswm.h"
+#include "SDL_video.h"
+#include "SDL_mouse.h"
+#include "SDL_assert.h"
+#include "SDL_hints.h"
+#include "../SDL_sysvideo.h"
+#include "../SDL_pixels_c.h"
+#include "../../events/SDL_events_c.h"
+
+#include "SDL_uikitvideo.h"
+#include "SDL_uikitevents.h"
+#include "SDL_uikitmodes.h"
+#include "SDL_uikitwindow.h"
+#import "SDL_uikitappdelegate.h"
+
+#import "SDL_uikitview.h"
+#import "SDL_uikitopenglview.h"
+
+#include <Foundation/Foundation.h>
+
+@implementation SDL_WindowData
+
+@synthesize uiwindow;
+@synthesize viewcontroller;
+@synthesize views;
+
+- (instancetype)init
+{
+ if ((self = [super init])) {
+ views = [NSMutableArray new];
+ }
+
+ return self;
+}
+
+@end
+
+@interface SDL_uikitwindow : UIWindow
+
+- (void)layoutSubviews;
+
+@end
+
+@implementation SDL_uikitwindow
+
+- (void)layoutSubviews
+{
+ /* Workaround to fix window orientation issues in iOS 8+. */
+ self.frame = self.screen.bounds;
+ [super layoutSubviews];
+}
+
+@end
+
+
+static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created)
+{
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ SDL_DisplayData *displaydata = (__bridge SDL_DisplayData *) display->driverdata;
+ SDL_uikitview *view;
+
+ CGRect frame = UIKit_ComputeViewFrame(window, displaydata.uiscreen);
+ int width = (int) frame.size.width;
+ int height = (int) frame.size.height;
+
+ SDL_WindowData *data = [[SDL_WindowData alloc] init];
+ if (!data) {
+ return SDL_OutOfMemory();
+ }
+
+ window->driverdata = (void *) CFBridgingRetain(data);
+
+ data.uiwindow = uiwindow;
+
+ /* only one window on iOS, always shown */
+ window->flags &= ~SDL_WINDOW_HIDDEN;
+
+ if (displaydata.uiscreen != [UIScreen mainScreen]) {
+ window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizable */
+ window->flags &= ~SDL_WINDOW_INPUT_FOCUS; /* never has input focus */
+ window->flags |= SDL_WINDOW_BORDERLESS; /* never has a status bar. */
+ }
+
+#if !TARGET_OS_TV
+ if (displaydata.uiscreen == [UIScreen mainScreen]) {
+ /* SDL_CreateWindow sets the window w&h to the display's bounds if the
+ * fullscreen flag is set. But the display bounds orientation might not
+ * match what we want, and GetSupportedOrientations call below uses the
+ * window w&h. They're overridden below anyway, so we'll just set them
+ * to the requested size for the purposes of determining orientation. */
+ window->w = window->windowed.w;
+ window->h = window->windowed.h;
+
+ NSUInteger orients = UIKit_GetSupportedOrientations(window);
+ BOOL supportsLandscape = (orients & UIInterfaceOrientationMaskLandscape) != 0;
+ BOOL supportsPortrait = (orients & (UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown)) != 0;
+
+ /* Make sure the width/height are oriented correctly */
+ if ((width > height && !supportsLandscape) || (height > width && !supportsPortrait)) {
+ int temp = width;
+ width = height;
+ height = temp;
+ }
+ }
+#endif /* !TARGET_OS_TV */
+
+ window->x = 0;
+ window->y = 0;
+ window->w = width;
+ window->h = height;
+
+ /* The View Controller will handle rotating the view when the device
+ * orientation changes. This will trigger resize events, if appropriate. */
+ data.viewcontroller = [[SDL_uikitviewcontroller alloc] initWithSDLWindow:window];
+
+ /* The window will initially contain a generic view so resizes, touch events,
+ * etc. can be handled without an active OpenGL view/context. */
+ view = [[SDL_uikitview alloc] initWithFrame:frame];
+
+ /* Sets this view as the controller's view, and adds the view to the window
+ * heirarchy. */
+ [view setSDLWindow:window];
+
+ /* Make this window the current mouse focus for touch input */
+ if (displaydata.uiscreen == [UIScreen mainScreen]) {
+ SDL_SetMouseFocus(window);
+ SDL_SetKeyboardFocus(window);
+ }
+
+ return 0;
+}
+
+int
+UIKit_CreateWindow(_THIS, SDL_Window *window)
+{
+ @autoreleasepool {
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ SDL_DisplayData *data = (__bridge SDL_DisplayData *) display->driverdata;
+
+ /* SDL currently puts this window at the start of display's linked list. We rely on this. */
+ SDL_assert(_this->windows == window);
+
+ /* We currently only handle a single window per display on iOS */
+ if (window->next != NULL) {
+ return SDL_SetError("Only one window allowed per display.");
+ }
+
+ /* If monitor has a resolution of 0x0 (hasn't been explicitly set by the
+ * user, so it's in standby), try to force the display to a resolution
+ * that most closely matches the desired window size. */
+#if !TARGET_OS_TV
+ const CGSize origsize = data.uiscreen.currentMode.size;
+ if ((origsize.width == 0.0f) && (origsize.height == 0.0f)) {
+ if (display->num_display_modes == 0) {
+ _this->GetDisplayModes(_this, display);
+ }
+
+ int i;
+ const SDL_DisplayMode *bestmode = NULL;
+ for (i = display->num_display_modes; i >= 0; i--) {
+ const SDL_DisplayMode *mode = &display->display_modes[i];
+ if ((mode->w >= window->w) && (mode->h >= window->h)) {
+ bestmode = mode;
+ }
+ }
+
+ if (bestmode) {
+ SDL_DisplayModeData *modedata = (__bridge SDL_DisplayModeData *)bestmode->driverdata;
+ [data.uiscreen setCurrentMode:modedata.uiscreenmode];
+
+ /* desktop_mode doesn't change here (the higher level will
+ * use it to set all the screens back to their defaults
+ * upon window destruction, SDL_Quit(), etc. */
+ display->current_mode = *bestmode;
+ }
+ }
+
+ if (data.uiscreen == [UIScreen mainScreen]) {
+ if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) {
+ [UIApplication sharedApplication].statusBarHidden = YES;
+ } else {
+ [UIApplication sharedApplication].statusBarHidden = NO;
+ }
+ }
+#endif /* !TARGET_OS_TV */
+
+ /* ignore the size user requested, and make a fullscreen window */
+ /* !!! FIXME: can we have a smaller view? */
+ UIWindow *uiwindow = [[SDL_uikitwindow alloc] initWithFrame:data.uiscreen.bounds];
+
+ /* put the window on an external display if appropriate. */
+ if (data.uiscreen != [UIScreen mainScreen]) {
+ [uiwindow setScreen:data.uiscreen];
+ }
+
+ if (SetupWindowData(_this, window, uiwindow, SDL_TRUE) < 0) {
+ return -1;
+ }
+ }
+
+ return 1;
+}
+
+void
+UIKit_SetWindowTitle(_THIS, SDL_Window * window)
+{
+ @autoreleasepool {
+ SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
+ data.viewcontroller.title = @(window->title);
+ }
+}
+
+void
+UIKit_ShowWindow(_THIS, SDL_Window * window)
+{
+ @autoreleasepool {
+ SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
+ [data.uiwindow makeKeyAndVisible];
+ }
+}
+
+void
+UIKit_HideWindow(_THIS, SDL_Window * window)
+{
+ @autoreleasepool {
+ SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
+ data.uiwindow.hidden = YES;
+ }
+}
+
+void
+UIKit_RaiseWindow(_THIS, SDL_Window * window)
+{
+ /* We don't currently offer a concept of "raising" the SDL window, since
+ * we only allow one per display, in the iOS fashion.
+ * However, we use this entry point to rebind the context to the view
+ * during OnWindowRestored processing. */
+ _this->GL_MakeCurrent(_this, _this->current_glwin, _this->current_glctx);
+}
+
+static void
+UIKit_UpdateWindowBorder(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
+ SDL_uikitviewcontroller *viewcontroller = data.viewcontroller;
+
+#if !TARGET_OS_TV
+ if (data.uiwindow.screen == [UIScreen mainScreen]) {
+ if (window->flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS)) {
+ [UIApplication sharedApplication].statusBarHidden = YES;
+ } else {
+ [UIApplication sharedApplication].statusBarHidden = NO;
+ }
+
+ /* iOS 7+ won't update the status bar until we tell it to. */
+ if ([viewcontroller respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
+ [viewcontroller setNeedsStatusBarAppearanceUpdate];
+ }
+ }
+
+ /* Update the view's frame to account for the status bar change. */
+ viewcontroller.view.frame = UIKit_ComputeViewFrame(window, data.uiwindow.screen);
+#endif /* !TARGET_OS_TV */
+
+#ifdef SDL_IPHONE_KEYBOARD
+ /* Make sure the view is offset correctly when the keyboard is visible. */
+ [viewcontroller updateKeyboard];
+#endif
+
+ [viewcontroller.view setNeedsLayout];
+ [viewcontroller.view layoutIfNeeded];
+}
+
+void
+UIKit_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
+{
+ @autoreleasepool {
+ UIKit_UpdateWindowBorder(_this, window);
+ }
+}
+
+void
+UIKit_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
+{
+ @autoreleasepool {
+ UIKit_UpdateWindowBorder(_this, window);
+ }
+}
+
+void
+UIKit_DestroyWindow(_THIS, SDL_Window * window)
+{
+ @autoreleasepool {
+ if (window->driverdata != NULL) {
+ SDL_WindowData *data = (SDL_WindowData *) CFBridgingRelease(window->driverdata);
+ NSArray *views = nil;
+
+ [data.viewcontroller stopAnimation];
+
+ /* Detach all views from this window. We use a copy of the array
+ * because setSDLWindow will remove the object from the original
+ * array, which would be undesirable if we were iterating over it. */
+ views = [data.views copy];
+ for (SDL_uikitview *view in views) {
+ [view setSDLWindow:NULL];
+ }
+
+ /* iOS may still hold a reference to the window after we release it.
+ * We want to make sure the SDL view controller isn't accessed in
+ * that case, because it would contain an invalid pointer to the old
+ * SDL window. */
+ data.uiwindow.rootViewController = nil;
+ data.uiwindow.hidden = YES;
+ }
+ }
+ window->driverdata = NULL;
+}
+
+SDL_bool
+UIKit_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
+{
+ @autoreleasepool {
+ SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
+
+ if (info->version.major <= SDL_MAJOR_VERSION) {
+ int versionnum = SDL_VERSIONNUM(info->version.major, info->version.minor, info->version.patch);
+
+ info->subsystem = SDL_SYSWM_UIKIT;
+ info->info.uikit.window = data.uiwindow;
+
+ /* These struct members were added in SDL 2.0.4. */
+ if (versionnum >= SDL_VERSIONNUM(2,0,4)) {
+ if ([data.viewcontroller.view isKindOfClass:[SDL_uikitopenglview class]]) {
+ SDL_uikitopenglview *glview = (SDL_uikitopenglview *)data.viewcontroller.view;
+ info->info.uikit.framebuffer = glview.drawableFramebuffer;
+ info->info.uikit.colorbuffer = glview.drawableRenderbuffer;
+ info->info.uikit.resolveFramebuffer = glview.msaaResolveFramebuffer;
+ } else {
+ info->info.uikit.framebuffer = 0;
+ info->info.uikit.colorbuffer = 0;
+ info->info.uikit.resolveFramebuffer = 0;
+ }
+ }
+
+ return SDL_TRUE;
+ } else {
+ SDL_SetError("Application not compiled with SDL %d.%d",
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+ return SDL_FALSE;
+ }
+ }
+}
+
+#if !TARGET_OS_TV
+NSUInteger
+UIKit_GetSupportedOrientations(SDL_Window * window)
+{
+ const char *hint = SDL_GetHint(SDL_HINT_ORIENTATIONS);
+ NSUInteger validOrientations = UIInterfaceOrientationMaskAll;
+ NSUInteger orientationMask = 0;
+
+ @autoreleasepool {
+ SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
+ UIApplication *app = [UIApplication sharedApplication];
+
+ /* Get all possible valid orientations. If the app delegate doesn't tell
+ * us, we get the orientations from Info.plist via UIApplication. */
+ if ([app.delegate respondsToSelector:@selector(application:supportedInterfaceOrientationsForWindow:)]) {
+ validOrientations = [app.delegate application:app supportedInterfaceOrientationsForWindow:data.uiwindow];
+ } else if ([app respondsToSelector:@selector(supportedInterfaceOrientationsForWindow:)]) {
+ validOrientations = [app supportedInterfaceOrientationsForWindow:data.uiwindow];
+ }
+
+ if (hint != NULL) {
+ NSArray *orientations = [@(hint) componentsSeparatedByString:@" "];
+
+ if ([orientations containsObject:@"LandscapeLeft"]) {
+ orientationMask |= UIInterfaceOrientationMaskLandscapeLeft;
+ }
+ if ([orientations containsObject:@"LandscapeRight"]) {
+ orientationMask |= UIInterfaceOrientationMaskLandscapeRight;
+ }
+ if ([orientations containsObject:@"Portrait"]) {
+ orientationMask |= UIInterfaceOrientationMaskPortrait;
+ }
+ if ([orientations containsObject:@"PortraitUpsideDown"]) {
+ orientationMask |= UIInterfaceOrientationMaskPortraitUpsideDown;
+ }
+ }
+
+ if (orientationMask == 0 && (window->flags & SDL_WINDOW_RESIZABLE)) {
+ /* any orientation is okay. */
+ orientationMask = UIInterfaceOrientationMaskAll;
+ }
+
+ if (orientationMask == 0) {
+ if (window->w >= window->h) {
+ orientationMask |= UIInterfaceOrientationMaskLandscape;
+ }
+ if (window->h >= window->w) {
+ orientationMask |= (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
+ }
+ }
+
+ /* Don't allow upside-down orientation on phones, so answering calls is in the natural orientation */
+ if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
+ orientationMask &= ~UIInterfaceOrientationMaskPortraitUpsideDown;
+ }
+
+ /* If none of the specified orientations are actually supported by the
+ * app, we'll revert to what the app supports. An exception would be
+ * thrown by the system otherwise. */
+ if ((validOrientations & orientationMask) == 0) {
+ orientationMask = validOrientations;
+ }
+ }
+
+ return orientationMask;
+}
+#endif /* !TARGET_OS_TV */
+
+int
+SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam)
+{
+ if (!window || !window->driverdata) {
+ return SDL_SetError("Invalid window");
+ }
+
+ @autoreleasepool {
+ SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
+ [data.viewcontroller setAnimationCallback:interval
+ callback:callback
+ callbackParam:callbackParam];
+ }
+
+ return 0;
+}
+
+#endif /* SDL_VIDEO_DRIVER_UIKIT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/uikit/keyinfotable.h b/src/3rdparty/SDL2/src/video/uikit/keyinfotable.h
new file mode 100644
index 0000000..3b23837
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/uikit/keyinfotable.h
@@ -0,0 +1,174 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef _UIKIT_KeyInfo
+#define _UIKIT_KeyInfo
+
+#include "SDL_scancode.h"
+
+/*
+ This file is used by the keyboard code in SDL_uikitview.m to convert between characters
+ passed in from the iPhone's virtual keyboard, and tuples of SDL_Scancode and SDL_keymods.
+ For example unicharToUIKeyInfoTable['a'] would give you the scan code and keymod for lower
+ case a.
+*/
+
+typedef struct
+{
+ SDL_Scancode code;
+ Uint16 mod;
+} UIKitKeyInfo;
+
+/* So far only ASCII characters here */
+static UIKitKeyInfo unicharToUIKeyInfoTable[] = {
+/* 0 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 1 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 2 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 3 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 4 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 5 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 6 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 7 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 8 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 9 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 10 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 11 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 12 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 13 */ { SDL_SCANCODE_RETURN, 0 },
+/* 14 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 15 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 16 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 17 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 18 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 19 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 20 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 21 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 22 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 23 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 24 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 25 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 26 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 27 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 28 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 29 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 30 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 31 */ { SDL_SCANCODE_UNKNOWN, 0 },
+/* 32 */ { SDL_SCANCODE_SPACE, 0 },
+/* 33 */ { SDL_SCANCODE_1, KMOD_SHIFT }, /* plus shift modifier '!' */
+/* 34 */ { SDL_SCANCODE_APOSTROPHE, KMOD_SHIFT }, /* plus shift modifier '"' */
+/* 35 */ { SDL_SCANCODE_3, KMOD_SHIFT }, /* plus shift modifier '#' */
+/* 36 */ { SDL_SCANCODE_4, KMOD_SHIFT }, /* plus shift modifier '$' */
+/* 37 */ { SDL_SCANCODE_5, KMOD_SHIFT }, /* plus shift modifier '%' */
+/* 38 */ { SDL_SCANCODE_7, KMOD_SHIFT }, /* plus shift modifier '&' */
+/* 39 */ { SDL_SCANCODE_APOSTROPHE, 0 }, /* ''' */
+/* 40 */ { SDL_SCANCODE_9, KMOD_SHIFT }, /* plus shift modifier '(' */
+/* 41 */ { SDL_SCANCODE_0, KMOD_SHIFT }, /* plus shift modifier ')' */
+/* 42 */ { SDL_SCANCODE_8, KMOD_SHIFT }, /* '*' */
+/* 43 */ { SDL_SCANCODE_EQUALS, KMOD_SHIFT }, /* plus shift modifier '+' */
+/* 44 */ { SDL_SCANCODE_COMMA, 0 }, /* ',' */
+/* 45 */ { SDL_SCANCODE_MINUS, 0 }, /* '-' */
+/* 46 */ { SDL_SCANCODE_PERIOD, 0 }, /* '.' */
+/* 47 */ { SDL_SCANCODE_SLASH, 0 }, /* '/' */
+/* 48 */ { SDL_SCANCODE_0, 0 },
+/* 49 */ { SDL_SCANCODE_1, 0 },
+/* 50 */ { SDL_SCANCODE_2, 0 },
+/* 51 */ { SDL_SCANCODE_3, 0 },
+/* 52 */ { SDL_SCANCODE_4, 0 },
+/* 53 */ { SDL_SCANCODE_5, 0 },
+/* 54 */ { SDL_SCANCODE_6, 0 },
+/* 55 */ { SDL_SCANCODE_7, 0 },
+/* 56 */ { SDL_SCANCODE_8, 0 },
+/* 57 */ { SDL_SCANCODE_9, 0 },
+/* 58 */ { SDL_SCANCODE_SEMICOLON, KMOD_SHIFT }, /* plus shift modifier ';' */
+/* 59 */ { SDL_SCANCODE_SEMICOLON, 0 },
+/* 60 */ { SDL_SCANCODE_COMMA, KMOD_SHIFT }, /* plus shift modifier '<' */
+/* 61 */ { SDL_SCANCODE_EQUALS, 0 },
+/* 62 */ { SDL_SCANCODE_PERIOD, KMOD_SHIFT }, /* plus shift modifier '>' */
+/* 63 */ { SDL_SCANCODE_SLASH, KMOD_SHIFT }, /* plus shift modifier '?' */
+/* 64 */ { SDL_SCANCODE_2, KMOD_SHIFT }, /* plus shift modifier '@' */
+/* 65 */ { SDL_SCANCODE_A, KMOD_SHIFT }, /* all the following need shift modifiers */
+/* 66 */ { SDL_SCANCODE_B, KMOD_SHIFT },
+/* 67 */ { SDL_SCANCODE_C, KMOD_SHIFT },
+/* 68 */ { SDL_SCANCODE_D, KMOD_SHIFT },
+/* 69 */ { SDL_SCANCODE_E, KMOD_SHIFT },
+/* 70 */ { SDL_SCANCODE_F, KMOD_SHIFT },
+/* 71 */ { SDL_SCANCODE_G, KMOD_SHIFT },
+/* 72 */ { SDL_SCANCODE_H, KMOD_SHIFT },
+/* 73 */ { SDL_SCANCODE_I, KMOD_SHIFT },
+/* 74 */ { SDL_SCANCODE_J, KMOD_SHIFT },
+/* 75 */ { SDL_SCANCODE_K, KMOD_SHIFT },
+/* 76 */ { SDL_SCANCODE_L, KMOD_SHIFT },
+/* 77 */ { SDL_SCANCODE_M, KMOD_SHIFT },
+/* 78 */ { SDL_SCANCODE_N, KMOD_SHIFT },
+/* 79 */ { SDL_SCANCODE_O, KMOD_SHIFT },
+/* 80 */ { SDL_SCANCODE_P, KMOD_SHIFT },
+/* 81 */ { SDL_SCANCODE_Q, KMOD_SHIFT },
+/* 82 */ { SDL_SCANCODE_R, KMOD_SHIFT },
+/* 83 */ { SDL_SCANCODE_S, KMOD_SHIFT },
+/* 84 */ { SDL_SCANCODE_T, KMOD_SHIFT },
+/* 85 */ { SDL_SCANCODE_U, KMOD_SHIFT },
+/* 86 */ { SDL_SCANCODE_V, KMOD_SHIFT },
+/* 87 */ { SDL_SCANCODE_W, KMOD_SHIFT },
+/* 88 */ { SDL_SCANCODE_X, KMOD_SHIFT },
+/* 89 */ { SDL_SCANCODE_Y, KMOD_SHIFT },
+/* 90 */ { SDL_SCANCODE_Z, KMOD_SHIFT },
+/* 91 */ { SDL_SCANCODE_LEFTBRACKET, 0 },
+/* 92 */ { SDL_SCANCODE_BACKSLASH, 0 },
+/* 93 */ { SDL_SCANCODE_RIGHTBRACKET, 0 },
+/* 94 */ { SDL_SCANCODE_6, KMOD_SHIFT }, /* plus shift modifier '^' */
+/* 95 */ { SDL_SCANCODE_MINUS, KMOD_SHIFT }, /* plus shift modifier '_' */
+/* 96 */ { SDL_SCANCODE_GRAVE, KMOD_SHIFT }, /* '`' */
+/* 97 */ { SDL_SCANCODE_A, 0 },
+/* 98 */ { SDL_SCANCODE_B, 0 },
+/* 99 */ { SDL_SCANCODE_C, 0 },
+/* 100 */{ SDL_SCANCODE_D, 0 },
+/* 101 */{ SDL_SCANCODE_E, 0 },
+/* 102 */{ SDL_SCANCODE_F, 0 },
+/* 103 */{ SDL_SCANCODE_G, 0 },
+/* 104 */{ SDL_SCANCODE_H, 0 },
+/* 105 */{ SDL_SCANCODE_I, 0 },
+/* 106 */{ SDL_SCANCODE_J, 0 },
+/* 107 */{ SDL_SCANCODE_K, 0 },
+/* 108 */{ SDL_SCANCODE_L, 0 },
+/* 109 */{ SDL_SCANCODE_M, 0 },
+/* 110 */{ SDL_SCANCODE_N, 0 },
+/* 111 */{ SDL_SCANCODE_O, 0 },
+/* 112 */{ SDL_SCANCODE_P, 0 },
+/* 113 */{ SDL_SCANCODE_Q, 0 },
+/* 114 */{ SDL_SCANCODE_R, 0 },
+/* 115 */{ SDL_SCANCODE_S, 0 },
+/* 116 */{ SDL_SCANCODE_T, 0 },
+/* 117 */{ SDL_SCANCODE_U, 0 },
+/* 118 */{ SDL_SCANCODE_V, 0 },
+/* 119 */{ SDL_SCANCODE_W, 0 },
+/* 120 */{ SDL_SCANCODE_X, 0 },
+/* 121 */{ SDL_SCANCODE_Y, 0 },
+/* 122 */{ SDL_SCANCODE_Z, 0 },
+/* 123 */{ SDL_SCANCODE_LEFTBRACKET, KMOD_SHIFT }, /* plus shift modifier '{' */
+/* 124 */{ SDL_SCANCODE_BACKSLASH, KMOD_SHIFT }, /* plus shift modifier '|' */
+/* 125 */{ SDL_SCANCODE_RIGHTBRACKET, KMOD_SHIFT }, /* plus shift modifier '}' */
+/* 126 */{ SDL_SCANCODE_GRAVE, KMOD_SHIFT }, /* plus shift modifier '~' */
+/* 127 */{ SDL_SCANCODE_BACKSPACE, KMOD_SHIFT }
+};
+
+#endif /* _UIKIT_KeyInfo */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/vivante/SDL_vivanteopengles.c b/src/3rdparty/SDL2/src/video/vivante/SDL_vivanteopengles.c
new file mode 100644
index 0000000..135e838
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/vivante/SDL_vivanteopengles.c
@@ -0,0 +1,47 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_VIVANTE && SDL_VIDEO_OPENGL_EGL
+
+#include "SDL_vivanteopengles.h"
+#include "SDL_vivantevideo.h"
+
+/* EGL implementation of SDL OpenGL support */
+
+int
+VIVANTE_GLES_LoadLibrary(_THIS, const char *path)
+{
+ SDL_DisplayData *displaydata;
+
+ displaydata = SDL_GetDisplayDriverData(0);
+
+ return SDL_EGL_LoadLibrary(_this, path, displaydata->native_display, 0);
+}
+
+SDL_EGL_CreateContext_impl(VIVANTE)
+SDL_EGL_SwapWindow_impl(VIVANTE)
+SDL_EGL_MakeCurrent_impl(VIVANTE)
+
+#endif /* SDL_VIDEO_DRIVER_VIVANTE && SDL_VIDEO_OPENGL_EGL */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/video/vivante/SDL_vivanteopengles.h b/src/3rdparty/SDL2/src/video/vivante/SDL_vivanteopengles.h
new file mode 100644
index 0000000..162d61a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/vivante/SDL_vivanteopengles.h
@@ -0,0 +1,48 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_vivanteopengles_h_
+#define SDL_vivanteopengles_h_
+
+#if SDL_VIDEO_DRIVER_VIVANTE && SDL_VIDEO_OPENGL_EGL
+
+#include "../SDL_sysvideo.h"
+#include "../SDL_egl_c.h"
+
+/* OpenGLES functions */
+#define VIVANTE_GLES_GetAttribute SDL_EGL_GetAttribute
+#define VIVANTE_GLES_GetProcAddress SDL_EGL_GetProcAddress
+#define VIVANTE_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
+#define VIVANTE_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
+#define VIVANTE_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
+#define VIVANTE_GLES_DeleteContext SDL_EGL_DeleteContext
+
+extern int VIVANTE_GLES_LoadLibrary(_THIS, const char *path);
+extern SDL_GLContext VIVANTE_GLES_CreateContext(_THIS, SDL_Window * window);
+extern int VIVANTE_GLES_SwapWindow(_THIS, SDL_Window * window);
+extern int VIVANTE_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+
+#endif /* SDL_VIDEO_DRIVER_VIVANTE && SDL_VIDEO_OPENGL_EGL */
+
+#endif /* SDL_vivanteopengles_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/vivante/SDL_vivanteplatform.c b/src/3rdparty/SDL2/src/video/vivante/SDL_vivanteplatform.c
new file mode 100644
index 0000000..67ea633
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/vivante/SDL_vivanteplatform.c
@@ -0,0 +1,54 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_VIVANTE
+
+#include "SDL_vivanteplatform.h"
+
+#ifdef VIVANTE_PLATFORM_GENERIC
+
+int
+VIVANTE_SetupPlatform(_THIS)
+{
+ return 0;
+}
+
+char *VIVANTE_GetDisplayName(_THIS)
+{
+ return NULL;
+}
+
+void
+VIVANTE_UpdateDisplayScale(_THIS)
+{
+}
+
+void
+VIVANTE_CleanupPlatform(_THIS)
+{
+}
+
+#endif /* VIVANTE_PLATFORM_GENERIC */
+
+#endif /* SDL_VIDEO_DRIVER_VIVANTE */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/vivante/SDL_vivanteplatform.h b/src/3rdparty/SDL2/src/video/vivante/SDL_vivanteplatform.h
new file mode 100644
index 0000000..59fbf60
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/vivante/SDL_vivanteplatform.h
@@ -0,0 +1,47 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_vivanteplatform_h_
+#define SDL_vivanteplatform_h_
+
+#if SDL_VIDEO_DRIVER_VIVANTE
+
+#include "SDL_vivantevideo.h"
+
+#if defined(CAVIUM)
+#define VIVANTE_PLATFORM_CAVIUM
+#elif defined(MARVELL)
+#define VIVANTE_PLATFORM_MARVELL
+#else
+#define VIVANTE_PLATFORM_GENERIC
+#endif
+
+extern int VIVANTE_SetupPlatform(_THIS);
+extern char *VIVANTE_GetDisplayName(_THIS);
+extern void VIVANTE_UpdateDisplayScale(_THIS);
+extern void VIVANTE_CleanupPlatform(_THIS);
+
+#endif /* SDL_VIDEO_DRIVER_VIVANTE */
+
+#endif /* SDL_vivanteplatform_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/vivante/SDL_vivantevideo.c b/src/3rdparty/SDL2/src/video/vivante/SDL_vivantevideo.c
new file mode 100644
index 0000000..656ab55
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/vivante/SDL_vivantevideo.c
@@ -0,0 +1,409 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_VIVANTE
+
+/* SDL internals */
+#include "../SDL_sysvideo.h"
+#include "SDL_version.h"
+#include "SDL_syswm.h"
+#include "SDL_loadso.h"
+#include "SDL_events.h"
+#include "../../events/SDL_events_c.h"
+
+#ifdef SDL_INPUT_LINUXEV
+#include "../../core/linux/SDL_evdev.h"
+#endif
+
+#include "SDL_vivantevideo.h"
+#include "SDL_vivanteplatform.h"
+#include "SDL_vivanteopengles.h"
+
+
+static int
+VIVANTE_Available(void)
+{
+ return 1;
+}
+
+static void
+VIVANTE_Destroy(SDL_VideoDevice * device)
+{
+ if (device->driverdata != NULL) {
+ SDL_free(device->driverdata);
+ device->driverdata = NULL;
+ }
+}
+
+static SDL_VideoDevice *
+VIVANTE_Create()
+{
+ SDL_VideoDevice *device;
+ SDL_VideoData *data;
+
+ /* Initialize SDL_VideoDevice structure */
+ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (device == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ /* Initialize internal data */
+ data = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
+ if (data == NULL) {
+ SDL_OutOfMemory();
+ SDL_free(device);
+ return NULL;
+ }
+
+ device->driverdata = data;
+
+ /* Setup amount of available displays */
+ device->num_displays = 0;
+
+ /* Set device free function */
+ device->free = VIVANTE_Destroy;
+
+ /* Setup all functions which we can handle */
+ device->VideoInit = VIVANTE_VideoInit;
+ device->VideoQuit = VIVANTE_VideoQuit;
+ device->GetDisplayModes = VIVANTE_GetDisplayModes;
+ device->SetDisplayMode = VIVANTE_SetDisplayMode;
+ device->CreateSDLWindow = VIVANTE_CreateWindow;
+ device->SetWindowTitle = VIVANTE_SetWindowTitle;
+ device->SetWindowPosition = VIVANTE_SetWindowPosition;
+ device->SetWindowSize = VIVANTE_SetWindowSize;
+ device->ShowWindow = VIVANTE_ShowWindow;
+ device->HideWindow = VIVANTE_HideWindow;
+ device->DestroyWindow = VIVANTE_DestroyWindow;
+ device->GetWindowWMInfo = VIVANTE_GetWindowWMInfo;
+
+#if SDL_VIDEO_OPENGL_EGL
+ device->GL_LoadLibrary = VIVANTE_GLES_LoadLibrary;
+ device->GL_GetProcAddress = VIVANTE_GLES_GetProcAddress;
+ device->GL_UnloadLibrary = VIVANTE_GLES_UnloadLibrary;
+ device->GL_CreateContext = VIVANTE_GLES_CreateContext;
+ device->GL_MakeCurrent = VIVANTE_GLES_MakeCurrent;
+ device->GL_SetSwapInterval = VIVANTE_GLES_SetSwapInterval;
+ device->GL_GetSwapInterval = VIVANTE_GLES_GetSwapInterval;
+ device->GL_SwapWindow = VIVANTE_GLES_SwapWindow;
+ device->GL_DeleteContext = VIVANTE_GLES_DeleteContext;
+#endif
+
+ device->PumpEvents = VIVANTE_PumpEvents;
+
+ return device;
+}
+
+VideoBootStrap VIVANTE_bootstrap = {
+ "vivante",
+ "Vivante EGL Video Driver",
+ VIVANTE_Available,
+ VIVANTE_Create
+};
+
+/*****************************************************************************/
+/* SDL Video and Display initialization/handling functions */
+/*****************************************************************************/
+
+static int
+VIVANTE_AddVideoDisplays(_THIS)
+{
+ SDL_VideoData *videodata = _this->driverdata;
+ SDL_VideoDisplay display;
+ SDL_DisplayMode current_mode;
+ SDL_DisplayData *data;
+ int pitch = 0, bpp = 0;
+ unsigned long pixels = 0;
+
+ data = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
+ if (data == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ SDL_zero(current_mode);
+#if SDL_VIDEO_DRIVER_VIVANTE_VDK
+ data->native_display = vdkGetDisplay(videodata->vdk_private);
+
+ vdkGetDisplayInfo(data->native_display, &current_mode.w, &current_mode.h, &pixels, &pitch, &bpp);
+#else
+ data->native_display = videodata->fbGetDisplayByIndex(0);
+
+ videodata->fbGetDisplayInfo(data->native_display, &current_mode.w, &current_mode.h, &pixels, &pitch, &bpp);
+#endif /* SDL_VIDEO_DRIVER_VIVANTE_VDK */
+
+ switch (bpp)
+ {
+ default: /* Is another format used? */
+ case 32:
+ current_mode.format = SDL_PIXELFORMAT_ARGB8888;
+ break;
+ case 16:
+ current_mode.format = SDL_PIXELFORMAT_RGB565;
+ break;
+ }
+ /* FIXME: How do we query refresh rate? */
+ current_mode.refresh_rate = 60;
+
+ SDL_zero(display);
+ display.name = VIVANTE_GetDisplayName(_this);
+ display.desktop_mode = current_mode;
+ display.current_mode = current_mode;
+ display.driverdata = data;
+ SDL_AddVideoDisplay(&display);
+ return 0;
+}
+
+int
+VIVANTE_VideoInit(_THIS)
+{
+ SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
+
+#if SDL_VIDEO_DRIVER_VIVANTE_VDK
+ videodata->vdk_private = vdkInitialize();
+ if (!videodata->vdk_private) {
+ return SDL_SetError("vdkInitialize() failed");
+ }
+#else
+ videodata->egl_handle = SDL_LoadObject("libEGL.so.1");
+ if (!videodata->egl_handle) {
+ videodata->egl_handle = SDL_LoadObject("libEGL.so");
+ if (!videodata->egl_handle) {
+ return -1;
+ }
+ }
+#define LOAD_FUNC(NAME) \
+ videodata->NAME = SDL_LoadFunction(videodata->egl_handle, #NAME); \
+ if (!videodata->NAME) return -1;
+
+ LOAD_FUNC(fbGetDisplay);
+ LOAD_FUNC(fbGetDisplayByIndex);
+ LOAD_FUNC(fbGetDisplayGeometry);
+ LOAD_FUNC(fbGetDisplayInfo);
+ LOAD_FUNC(fbDestroyDisplay);
+ LOAD_FUNC(fbCreateWindow);
+ LOAD_FUNC(fbGetWindowGeometry);
+ LOAD_FUNC(fbGetWindowInfo);
+ LOAD_FUNC(fbDestroyWindow);
+#endif
+
+ if (VIVANTE_SetupPlatform(_this) < 0) {
+ return -1;
+ }
+
+ if (VIVANTE_AddVideoDisplays(_this) < 0) {
+ return -1;
+ }
+
+ VIVANTE_UpdateDisplayScale(_this);
+
+#ifdef SDL_INPUT_LINUXEV
+ if (SDL_EVDEV_Init() < 0) {
+ return -1;
+ }
+#endif
+
+ return 0;
+}
+
+void
+VIVANTE_VideoQuit(_THIS)
+{
+ SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
+
+#ifdef SDL_INPUT_LINUXEV
+ SDL_EVDEV_Quit();
+#endif
+
+ VIVANTE_CleanupPlatform(_this);
+
+#if SDL_VIDEO_DRIVER_VIVANTE_VDK
+ if (videodata->vdk_private) {
+ vdkExit(videodata->vdk_private);
+ videodata->vdk_private = NULL;
+ }
+#else
+ if (videodata->egl_handle) {
+ SDL_UnloadObject(videodata->egl_handle);
+ videodata->egl_handle = NULL;
+ }
+#endif
+}
+
+void
+VIVANTE_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
+{
+ /* Only one display mode available, the current one */
+ SDL_AddDisplayMode(display, &display->current_mode);
+}
+
+int
+VIVANTE_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
+{
+ return 0;
+}
+
+int
+VIVANTE_CreateWindow(_THIS, SDL_Window * window)
+{
+ SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
+ SDL_DisplayData *displaydata;
+ SDL_WindowData *data;
+
+ displaydata = SDL_GetDisplayDriverData(0);
+
+ /* Allocate window internal data */
+ data = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
+ if (data == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ /* Setup driver data for this window */
+ window->driverdata = data;
+
+#if SDL_VIDEO_DRIVER_VIVANTE_VDK
+ data->native_window = vdkCreateWindow(displaydata->native_display, window->x, window->y, window->w, window->h);
+#else
+ data->native_window = videodata->fbCreateWindow(displaydata->native_display, window->x, window->y, window->w, window->h);
+#endif
+ if (!data->native_window) {
+ return SDL_SetError("VIVANTE: Can't create native window");
+ }
+
+#if SDL_VIDEO_OPENGL_EGL
+ if (window->flags & SDL_WINDOW_OPENGL) {
+ data->egl_surface = SDL_EGL_CreateSurface(_this, data->native_window);
+ if (data->egl_surface == EGL_NO_SURFACE) {
+ return SDL_SetError("VIVANTE: Can't create EGL surface");
+ }
+ } else {
+ data->egl_surface = EGL_NO_SURFACE;
+ }
+#endif
+
+ /* Window has been successfully created */
+ return 0;
+}
+
+void
+VIVANTE_DestroyWindow(_THIS, SDL_Window * window)
+{
+ SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
+ SDL_WindowData *data;
+
+ data = window->driverdata;
+ if (data) {
+#if SDL_VIDEO_OPENGL_EGL
+ if (data->egl_surface != EGL_NO_SURFACE) {
+ SDL_EGL_DestroySurface(_this, data->egl_surface);
+ }
+#endif
+
+ if (data->native_window) {
+#if SDL_VIDEO_DRIVER_VIVANTE_VDK
+ vdkDestroyWindow(data->native_window);
+#else
+ videodata->fbDestroyWindow(data->native_window);
+#endif
+ }
+
+ SDL_free(data);
+ }
+ window->driverdata = NULL;
+}
+
+void
+VIVANTE_SetWindowTitle(_THIS, SDL_Window * window)
+{
+#if SDL_VIDEO_DRIVER_VIVANTE_VDK
+ SDL_WindowData *data = window->driverdata;
+ vdkSetWindowTitle(data->native_window, window->title);
+#endif
+}
+
+void
+VIVANTE_SetWindowPosition(_THIS, SDL_Window * window)
+{
+ /* FIXME */
+}
+
+void
+VIVANTE_SetWindowSize(_THIS, SDL_Window * window)
+{
+ /* FIXME */
+}
+
+void
+VIVANTE_ShowWindow(_THIS, SDL_Window * window)
+{
+#if SDL_VIDEO_DRIVER_VIVANTE_VDK
+ SDL_WindowData *data = window->driverdata;
+ vdkShowWindow(data->native_window);
+#endif
+ SDL_SetMouseFocus(window);
+ SDL_SetKeyboardFocus(window);
+}
+
+void
+VIVANTE_HideWindow(_THIS, SDL_Window * window)
+{
+#if SDL_VIDEO_DRIVER_VIVANTE_VDK
+ SDL_WindowData *data = window->driverdata;
+ vdkHideWindow(data->native_window);
+#endif
+}
+
+/*****************************************************************************/
+/* SDL Window Manager function */
+/*****************************************************************************/
+SDL_bool
+VIVANTE_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ SDL_DisplayData *displaydata = SDL_GetDisplayDriverData(0);
+
+ if (info->version.major == SDL_MAJOR_VERSION &&
+ info->version.minor == SDL_MINOR_VERSION) {
+ info->subsystem = SDL_SYSWM_VIVANTE;
+ info->info.vivante.display = displaydata->native_display;
+ info->info.vivante.window = data->native_window;
+ return SDL_TRUE;
+ } else {
+ SDL_SetError("Application not compiled with SDL %d.%d",
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+ return SDL_FALSE;
+ }
+}
+
+/*****************************************************************************/
+/* SDL event functions */
+/*****************************************************************************/
+void VIVANTE_PumpEvents(_THIS)
+{
+#ifdef SDL_INPUT_LINUXEV
+ SDL_EVDEV_Poll();
+#endif
+}
+
+#endif /* SDL_VIDEO_DRIVER_VIVANTE */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/vivante/SDL_vivantevideo.h b/src/3rdparty/SDL2/src/video/vivante/SDL_vivantevideo.h
new file mode 100644
index 0000000..d335564
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/vivante/SDL_vivantevideo.h
@@ -0,0 +1,91 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_vivantevideo_h_
+#define SDL_vivantevideo_h_
+
+#include "../../SDL_internal.h"
+#include "../SDL_sysvideo.h"
+
+#include "SDL_egl.h"
+
+#if SDL_VIDEO_DRIVER_VIVANTE_VDK
+#include <gc_vdk.h>
+#else
+#include <EGL/egl.h>
+#endif
+
+typedef struct SDL_VideoData
+{
+#if SDL_VIDEO_DRIVER_VIVANTE_VDK
+ vdkPrivate vdk_private;
+#else
+ void *egl_handle; /* EGL shared library handle */
+ EGLNativeDisplayType (EGLAPIENTRY *fbGetDisplay)(void *context);
+ EGLNativeDisplayType (EGLAPIENTRY *fbGetDisplayByIndex)(int DisplayIndex);
+ void (EGLAPIENTRY *fbGetDisplayGeometry)(EGLNativeDisplayType Display, int *Width, int *Height);
+ void (EGLAPIENTRY *fbGetDisplayInfo)(EGLNativeDisplayType Display, int *Width, int *Height, unsigned long *Physical, int *Stride, int *BitsPerPixel);
+ void (EGLAPIENTRY *fbDestroyDisplay)(EGLNativeDisplayType Display);
+ EGLNativeWindowType (EGLAPIENTRY *fbCreateWindow)(EGLNativeDisplayType Display, int X, int Y, int Width, int Height);
+ void (EGLAPIENTRY *fbGetWindowGeometry)(EGLNativeWindowType Window, int *X, int *Y, int *Width, int *Height);
+ void (EGLAPIENTRY *fbGetWindowInfo)(EGLNativeWindowType Window, int *X, int *Y, int *Width, int *Height, int *BitsPerPixel, unsigned int *Offset);
+ void (EGLAPIENTRY *fbDestroyWindow)(EGLNativeWindowType Window);
+#endif
+} SDL_VideoData;
+
+typedef struct SDL_DisplayData
+{
+ EGLNativeDisplayType native_display;
+} SDL_DisplayData;
+
+typedef struct SDL_WindowData
+{
+ EGLNativeWindowType native_window;
+ EGLSurface egl_surface;
+} SDL_WindowData;
+
+/****************************************************************************/
+/* SDL_VideoDevice functions declaration */
+/****************************************************************************/
+
+/* Display and window functions */
+int VIVANTE_VideoInit(_THIS);
+void VIVANTE_VideoQuit(_THIS);
+void VIVANTE_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
+int VIVANTE_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
+int VIVANTE_CreateWindow(_THIS, SDL_Window * window);
+void VIVANTE_SetWindowTitle(_THIS, SDL_Window * window);
+void VIVANTE_SetWindowPosition(_THIS, SDL_Window * window);
+void VIVANTE_SetWindowSize(_THIS, SDL_Window * window);
+void VIVANTE_ShowWindow(_THIS, SDL_Window * window);
+void VIVANTE_HideWindow(_THIS, SDL_Window * window);
+void VIVANTE_DestroyWindow(_THIS, SDL_Window * window);
+
+/* Window manager function */
+SDL_bool VIVANTE_GetWindowWMInfo(_THIS, SDL_Window * window,
+ struct SDL_SysWMinfo *info);
+
+/* Event functions */
+void VIVANTE_PumpEvents(_THIS);
+
+#endif /* SDL_vivantevideo_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylandclipboard.c b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandclipboard.c
new file mode 100644
index 0000000..5fd826b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandclipboard.c
@@ -0,0 +1,123 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WAYLAND
+
+#include "SDL_waylanddatamanager.h"
+#include "SDL_waylandevents_c.h"
+
+int
+Wayland_SetClipboardText(_THIS, const char *text)
+{
+ SDL_VideoData *video_data = NULL;
+ SDL_WaylandDataDevice *data_device = NULL;
+
+ int status = 0;
+
+ if (_this == NULL || _this->driverdata == NULL) {
+ status = SDL_SetError("Video driver uninitialized");
+ } else {
+ video_data = _this->driverdata;
+ /* TODO: Support more than one seat */
+ data_device = Wayland_get_data_device(video_data->input);
+ if (text[0] != '\0') {
+ SDL_WaylandDataSource* source = Wayland_data_source_create(_this);
+ Wayland_data_source_add_data(source, TEXT_MIME, text,
+ strlen(text) + 1);
+
+ status = Wayland_data_device_set_selection(data_device, source);
+ if (status != 0) {
+ Wayland_data_source_destroy(source);
+ }
+ } else {
+ status = Wayland_data_device_clear_selection(data_device);
+ }
+ }
+
+ return status;
+}
+
+char *
+Wayland_GetClipboardText(_THIS)
+{
+ SDL_VideoData *video_data = NULL;
+ SDL_WaylandDataDevice *data_device = NULL;
+
+ char *text = NULL;
+
+ void *buffer = NULL;
+ size_t length = 0;
+
+ if (_this == NULL || _this->driverdata == NULL) {
+ SDL_SetError("Video driver uninitialized");
+ } else {
+ video_data = _this->driverdata;
+ /* TODO: Support more than one seat */
+ data_device = Wayland_get_data_device(video_data->input);
+ if (data_device->selection_offer != NULL) {
+ buffer = Wayland_data_offer_receive(data_device->selection_offer,
+ &length, TEXT_MIME, SDL_TRUE);
+ if (length > 0) {
+ text = (char*) buffer;
+ }
+ } else if (data_device->selection_source != NULL) {
+ buffer = Wayland_data_source_get_data(data_device->selection_source,
+ &length, TEXT_MIME, SDL_TRUE);
+ if (length > 0) {
+ text = (char*) buffer;
+ }
+ }
+ }
+
+ if (text == NULL) {
+ text = SDL_strdup("");
+ }
+
+ return text;
+}
+
+SDL_bool
+Wayland_HasClipboardText(_THIS)
+{
+ SDL_VideoData *video_data = NULL;
+ SDL_WaylandDataDevice *data_device = NULL;
+
+ SDL_bool result = SDL_FALSE;
+ if (_this == NULL || _this->driverdata == NULL) {
+ SDL_SetError("Video driver uninitialized");
+ } else {
+ video_data = _this->driverdata;
+ data_device = Wayland_get_data_device(video_data->input);
+ if (data_device != NULL && Wayland_data_offer_has_mime(
+ data_device->selection_offer, TEXT_MIME)) {
+ result = SDL_TRUE;
+ } else if(data_device != NULL && Wayland_data_source_has_mime(
+ data_device->selection_source, TEXT_MIME)) {
+ result = SDL_TRUE;
+ }
+ }
+ return result;
+}
+
+#endif /* SDL_VIDEO_DRIVER_WAYLAND */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylandclipboard.h b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandclipboard.h
new file mode 100644
index 0000000..467e1c7
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandclipboard.h
@@ -0,0 +1,32 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_waylandclipboard_h_
+#define SDL_waylandclipboard_h_
+
+extern int Wayland_SetClipboardText(_THIS, const char *text);
+extern char *Wayland_GetClipboardText(_THIS);
+extern SDL_bool Wayland_HasClipboardText(_THIS);
+
+#endif /* SDL_waylandclipboard_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylanddatamanager.c b/src/3rdparty/SDL2/src/video/wayland/SDL_waylanddatamanager.c
new file mode 100644
index 0000000..f1b9742
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylanddatamanager.c
@@ -0,0 +1,468 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WAYLAND
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <limits.h>
+#include <signal.h>
+
+#include "SDL_stdinc.h"
+#include "SDL_assert.h"
+#include "../../core/unix/SDL_poll.h"
+
+#include "SDL_waylandvideo.h"
+#include "SDL_waylanddatamanager.h"
+
+#include "SDL_waylanddyn.h"
+
+static ssize_t
+write_pipe(int fd, const void* buffer, size_t total_length, size_t *pos)
+{
+ int ready = 0;
+ ssize_t bytes_written = 0;
+ ssize_t length = total_length - *pos;
+
+ sigset_t sig_set;
+ sigset_t old_sig_set;
+ struct timespec zerotime = {0};
+
+ ready = SDL_IOReady(fd, SDL_TRUE, 1 * 1000);
+
+ sigemptyset(&sig_set);
+ sigaddset(&sig_set, SIGPIPE);
+
+ pthread_sigmask(SIG_BLOCK, &sig_set, &old_sig_set);
+
+ if (ready == 0) {
+ bytes_written = SDL_SetError("Pipe timeout");
+ } else if (ready < 0) {
+ bytes_written = SDL_SetError("Pipe select error");
+ } else {
+ if (length > 0) {
+ bytes_written = write(fd, (Uint8*)buffer + *pos, SDL_min(length, PIPE_BUF));
+ }
+
+ if (bytes_written > 0) {
+ *pos += bytes_written;
+ }
+ }
+
+ sigtimedwait(&sig_set, 0, &zerotime);
+ pthread_sigmask(SIG_SETMASK, &old_sig_set, NULL);
+
+ return bytes_written;
+}
+
+static ssize_t
+read_pipe(int fd, void** buffer, size_t* total_length, SDL_bool null_terminate)
+{
+ int ready = 0;
+ void* output_buffer = NULL;
+ char temp[PIPE_BUF];
+ size_t new_buffer_length = 0;
+ ssize_t bytes_read = 0;
+ size_t pos = 0;
+
+ ready = SDL_IOReady(fd, SDL_FALSE, 1 * 1000);
+
+ if (ready == 0) {
+ bytes_read = SDL_SetError("Pipe timeout");
+ } else if (ready < 0) {
+ bytes_read = SDL_SetError("Pipe select error");
+ } else {
+ bytes_read = read(fd, temp, sizeof(temp));
+ }
+
+ if (bytes_read > 0) {
+ pos = *total_length;
+ *total_length += bytes_read;
+
+ if (null_terminate == SDL_TRUE) {
+ new_buffer_length = *total_length + 1;
+ } else {
+ new_buffer_length = *total_length;
+ }
+
+ if (*buffer == NULL) {
+ output_buffer = SDL_malloc(new_buffer_length);
+ } else {
+ output_buffer = SDL_realloc(*buffer, new_buffer_length);
+ }
+
+ if (output_buffer == NULL) {
+ bytes_read = SDL_OutOfMemory();
+ } else {
+ SDL_memcpy((Uint8*)output_buffer + pos, temp, bytes_read);
+
+ if (null_terminate == SDL_TRUE) {
+ SDL_memset((Uint8*)output_buffer + (new_buffer_length - 1), 0, 1);
+ }
+
+ *buffer = output_buffer;
+ }
+ }
+
+ return bytes_read;
+}
+
+#define MIME_LIST_SIZE 4
+
+static const char* mime_conversion_list[MIME_LIST_SIZE][2] = {
+ {"text/plain", TEXT_MIME},
+ {"TEXT", TEXT_MIME},
+ {"UTF8_STRING", TEXT_MIME},
+ {"STRING", TEXT_MIME}
+};
+
+const char*
+Wayland_convert_mime_type(const char *mime_type)
+{
+ const char *found = mime_type;
+
+ size_t index = 0;
+
+ for (index = 0; index < MIME_LIST_SIZE; ++index) {
+ if (strcmp(mime_conversion_list[index][0], mime_type) == 0) {
+ found = mime_conversion_list[index][1];
+ break;
+ }
+ }
+
+ return found;
+}
+
+static SDL_MimeDataList*
+mime_data_list_find(struct wl_list* list,
+ const char* mime_type)
+{
+ SDL_MimeDataList *found = NULL;
+
+ SDL_MimeDataList *mime_list = NULL;
+ wl_list_for_each(mime_list, list, link) {
+ if (strcmp(mime_list->mime_type, mime_type) == 0) {
+ found = mime_list;
+ break;
+ }
+ }
+ return found;
+}
+
+static int
+mime_data_list_add(struct wl_list* list,
+ const char* mime_type,
+ void* buffer, size_t length)
+{
+ int status = 0;
+ size_t mime_type_length = 0;
+
+ SDL_MimeDataList *mime_data = NULL;
+
+ mime_data = mime_data_list_find(list, mime_type);
+
+ if (mime_data == NULL) {
+ mime_data = SDL_calloc(1, sizeof(*mime_data));
+ if (mime_data == NULL) {
+ status = SDL_OutOfMemory();
+ } else {
+ WAYLAND_wl_list_insert(list, &(mime_data->link));
+
+ mime_type_length = strlen(mime_type) + 1;
+ mime_data->mime_type = SDL_malloc(mime_type_length);
+ if (mime_data->mime_type == NULL) {
+ status = SDL_OutOfMemory();
+ } else {
+ SDL_memcpy(mime_data->mime_type, mime_type, mime_type_length);
+ }
+ }
+ }
+
+ if (mime_data != NULL && buffer != NULL && length > 0) {
+ if (mime_data->data != NULL) {
+ SDL_free(mime_data->data);
+ }
+ mime_data->data = buffer;
+ mime_data->length = length;
+ }
+
+ return status;
+}
+
+static void
+mime_data_list_free(struct wl_list *list)
+{
+ SDL_MimeDataList *mime_data = NULL;
+ SDL_MimeDataList *next = NULL;
+
+ wl_list_for_each_safe(mime_data, next, list, link) {
+ if (mime_data->data != NULL) {
+ SDL_free(mime_data->data);
+ }
+ if (mime_data->mime_type != NULL) {
+ SDL_free(mime_data->mime_type);
+ }
+ SDL_free(mime_data);
+ }
+}
+
+ssize_t
+Wayland_data_source_send(SDL_WaylandDataSource *source,
+ const char *mime_type, int fd)
+{
+ size_t written_bytes = 0;
+ ssize_t status = 0;
+ SDL_MimeDataList *mime_data = NULL;
+
+ mime_type = Wayland_convert_mime_type(mime_type);
+ mime_data = mime_data_list_find(&source->mimes,
+ mime_type);
+
+ if (mime_data == NULL || mime_data->data == NULL) {
+ status = SDL_SetError("Invalid mime type");
+ close(fd);
+ } else {
+ while (write_pipe(fd, mime_data->data, mime_data->length,
+ &written_bytes) > 0);
+ close(fd);
+ status = written_bytes;
+ }
+ return status;
+}
+
+int Wayland_data_source_add_data(SDL_WaylandDataSource *source,
+ const char *mime_type,
+ const void *buffer,
+ size_t length)
+{
+ int status = 0;
+ if (length > 0) {
+ void *internal_buffer = SDL_malloc(length);
+ if (internal_buffer == NULL) {
+ status = SDL_OutOfMemory();
+ } else {
+ SDL_memcpy(internal_buffer, buffer, length);
+ status = mime_data_list_add(&source->mimes, mime_type,
+ internal_buffer, length);
+ }
+ }
+ return status;
+}
+
+SDL_bool
+Wayland_data_source_has_mime(SDL_WaylandDataSource *source,
+ const char *mime_type)
+{
+ SDL_bool found = SDL_FALSE;
+
+ if (source != NULL) {
+ found = mime_data_list_find(&source->mimes, mime_type) != NULL;
+ }
+ return found;
+}
+
+void*
+Wayland_data_source_get_data(SDL_WaylandDataSource *source,
+ size_t *length, const char* mime_type,
+ SDL_bool null_terminate)
+{
+ SDL_MimeDataList *mime_data = NULL;
+ void *buffer = NULL;
+ *length = 0;
+
+ if (source == NULL) {
+ SDL_SetError("Invalid data source");
+ } else {
+ mime_data = mime_data_list_find(&source->mimes, mime_type);
+ if (mime_data != NULL && mime_data->length > 0) {
+ buffer = SDL_malloc(mime_data->length);
+ if (buffer == NULL) {
+ *length = SDL_OutOfMemory();
+ } else {
+ *length = mime_data->length;
+ SDL_memcpy(buffer, mime_data->data, mime_data->length);
+ }
+ }
+ }
+
+ return buffer;
+}
+
+void
+Wayland_data_source_destroy(SDL_WaylandDataSource *source)
+{
+ if (source != NULL) {
+ wl_data_source_destroy(source->source);
+ mime_data_list_free(&source->mimes);
+ SDL_free(source);
+ }
+}
+
+void*
+Wayland_data_offer_receive(SDL_WaylandDataOffer *offer,
+ size_t *length, const char* mime_type,
+ SDL_bool null_terminate)
+{
+ SDL_WaylandDataDevice *data_device = NULL;
+
+ int pipefd[2];
+ void *buffer = NULL;
+ *length = 0;
+
+ if (offer == NULL) {
+ SDL_SetError("Invalid data offer");
+ } else if ((data_device = offer->data_device) == NULL) {
+ SDL_SetError("Data device not initialized");
+ } else if (pipe2(pipefd, O_CLOEXEC|O_NONBLOCK) == -1) {
+ SDL_SetError("Could not read pipe");
+ } else {
+ wl_data_offer_receive(offer->offer, mime_type, pipefd[1]);
+
+ /* TODO: Needs pump and flush? */
+ WAYLAND_wl_display_flush(data_device->video_data->display);
+
+ close(pipefd[1]);
+
+ while (read_pipe(pipefd[0], &buffer, length, null_terminate) > 0);
+ close(pipefd[0]);
+ }
+ return buffer;
+}
+
+int
+Wayland_data_offer_add_mime(SDL_WaylandDataOffer *offer,
+ const char* mime_type)
+{
+ return mime_data_list_add(&offer->mimes, mime_type, NULL, 0);
+}
+
+
+SDL_bool
+Wayland_data_offer_has_mime(SDL_WaylandDataOffer *offer,
+ const char *mime_type)
+{
+ SDL_bool found = SDL_FALSE;
+
+ if (offer != NULL) {
+ found = mime_data_list_find(&offer->mimes, mime_type) != NULL;
+ }
+ return found;
+}
+
+void
+Wayland_data_offer_destroy(SDL_WaylandDataOffer *offer)
+{
+ if (offer != NULL) {
+ wl_data_offer_destroy(offer->offer);
+ mime_data_list_free(&offer->mimes);
+ SDL_free(offer);
+ }
+}
+
+int
+Wayland_data_device_clear_selection(SDL_WaylandDataDevice *data_device)
+{
+ int status = 0;
+
+ if (data_device == NULL || data_device->data_device == NULL) {
+ status = SDL_SetError("Invalid Data Device");
+ } else if (data_device->selection_source != 0) {
+ wl_data_device_set_selection(data_device->data_device, NULL, 0);
+ data_device->selection_source = NULL;
+ }
+ return status;
+}
+
+int
+Wayland_data_device_set_selection(SDL_WaylandDataDevice *data_device,
+ SDL_WaylandDataSource *source)
+{
+ int status = 0;
+ size_t num_offers = 0;
+ size_t index = 0;
+
+ if (data_device == NULL) {
+ status = SDL_SetError("Invalid Data Device");
+ } else if (source == NULL) {
+ status = SDL_SetError("Invalid source");
+ } else {
+ SDL_MimeDataList *mime_data = NULL;
+
+ wl_list_for_each(mime_data, &(source->mimes), link) {
+ wl_data_source_offer(source->source,
+ mime_data->mime_type);
+
+ /* TODO - Improve system for multiple mime types to same data */
+ for (index = 0; index < MIME_LIST_SIZE; ++index) {
+ if (strcmp(mime_conversion_list[index][1], mime_data->mime_type) == 0) {
+ wl_data_source_offer(source->source,
+ mime_conversion_list[index][0]);
+ }
+ }
+ /* */
+
+ ++num_offers;
+ }
+
+ if (num_offers == 0) {
+ Wayland_data_device_clear_selection(data_device);
+ status = SDL_SetError("No mime data");
+ } else {
+ /* Only set if there is a valid serial if not set it later */
+ if (data_device->selection_serial != 0) {
+ wl_data_device_set_selection(data_device->data_device,
+ source->source,
+ data_device->selection_serial);
+ }
+ data_device->selection_source = source;
+ }
+ }
+
+ return status;
+}
+
+int
+Wayland_data_device_set_serial(SDL_WaylandDataDevice *data_device,
+ uint32_t serial)
+{
+ int status = -1;
+ if (data_device != NULL) {
+ status = 0;
+
+ /* If there was no serial and there is a pending selection set it now. */
+ if (data_device->selection_serial == 0
+ && data_device->selection_source != NULL) {
+ wl_data_device_set_selection(data_device->data_device,
+ data_device->selection_source->source,
+ serial);
+ }
+
+ data_device->selection_serial = serial;
+ }
+
+ return status;
+}
+
+#endif /* SDL_VIDEO_DRIVER_WAYLAND */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylanddatamanager.h b/src/3rdparty/SDL2/src/video/wayland/SDL_waylanddatamanager.h
new file mode 100644
index 0000000..9b13e64
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylanddatamanager.h
@@ -0,0 +1,103 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_waylanddatamanager_h_
+#define SDL_waylanddatamanager_h_
+
+#include "SDL_waylandvideo.h"
+#include "SDL_waylandwindow.h"
+
+#define TEXT_MIME "text/plain;charset=utf-8"
+#define FILE_MIME "text/uri-list"
+
+typedef struct {
+ char *mime_type;
+ void *data;
+ size_t length;
+ struct wl_list link;
+} SDL_MimeDataList;
+
+typedef struct {
+ struct wl_data_source *source;
+ struct wl_list mimes;
+} SDL_WaylandDataSource;
+
+typedef struct {
+ struct wl_data_offer *offer;
+ struct wl_list mimes;
+ void *data_device;
+} SDL_WaylandDataOffer;
+
+typedef struct {
+ struct wl_data_device *data_device;
+ SDL_VideoData *video_data;
+
+ /* Drag and Drop */
+ uint32_t drag_serial;
+ SDL_WaylandDataOffer *drag_offer;
+ SDL_WaylandDataOffer *selection_offer;
+
+ /* Clipboard */
+ uint32_t selection_serial;
+ SDL_WaylandDataSource *selection_source;
+} SDL_WaylandDataDevice;
+
+extern const char* Wayland_convert_mime_type(const char *mime_type);
+
+/* Wayland Data Source - (Sending) */
+extern SDL_WaylandDataSource* Wayland_data_source_create(_THIS);
+extern ssize_t Wayland_data_source_send(SDL_WaylandDataSource *source,
+ const char *mime_type, int fd);
+extern int Wayland_data_source_add_data(SDL_WaylandDataSource *source,
+ const char *mime_type,
+ const void *buffer,
+ size_t length);
+extern SDL_bool Wayland_data_source_has_mime(SDL_WaylandDataSource *source,
+ const char *mime_type);
+extern void* Wayland_data_source_get_data(SDL_WaylandDataSource *source,
+ size_t *length,
+ const char *mime_type,
+ SDL_bool null_terminate);
+extern void Wayland_data_source_destroy(SDL_WaylandDataSource *source);
+
+/* Wayland Data Offer - (Receiving) */
+extern void* Wayland_data_offer_receive(SDL_WaylandDataOffer *offer,
+ size_t *length,
+ const char *mime_type,
+ SDL_bool null_terminate);
+extern SDL_bool Wayland_data_offer_has_mime(SDL_WaylandDataOffer *offer,
+ const char *mime_type);
+extern int Wayland_data_offer_add_mime(SDL_WaylandDataOffer *offer,
+ const char *mime_type);
+extern void Wayland_data_offer_destroy(SDL_WaylandDataOffer *offer);
+
+/* Clipboard */
+extern int Wayland_data_device_clear_selection(SDL_WaylandDataDevice *device);
+extern int Wayland_data_device_set_selection(SDL_WaylandDataDevice *device,
+ SDL_WaylandDataSource *source);
+extern int Wayland_data_device_set_serial(SDL_WaylandDataDevice *device,
+ uint32_t serial);
+#endif /* SDL_waylanddatamanager_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylanddyn.c b/src/3rdparty/SDL2/src/video/wayland/SDL_waylanddyn.c
new file mode 100644
index 0000000..98cc518
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylanddyn.c
@@ -0,0 +1,178 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WAYLAND
+
+#define DEBUG_DYNAMIC_WAYLAND 0
+
+#include "SDL_waylanddyn.h"
+
+#if DEBUG_DYNAMIC_WAYLAND
+#include "SDL_log.h"
+#endif
+
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
+
+#include "SDL_name.h"
+#include "SDL_loadso.h"
+
+typedef struct
+{
+ void *lib;
+ const char *libname;
+} waylanddynlib;
+
+#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
+#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC NULL
+#endif
+#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL
+#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL NULL
+#endif
+#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR
+#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR NULL
+#endif
+#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON
+#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON NULL
+#endif
+
+static waylanddynlib waylandlibs[] = {
+ {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC},
+ {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL},
+ {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR},
+ {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON}
+};
+
+static void *
+WAYLAND_GetSym(const char *fnname, int *pHasModule)
+{
+ int i;
+ void *fn = NULL;
+ for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) {
+ if (waylandlibs[i].lib != NULL) {
+ fn = SDL_LoadFunction(waylandlibs[i].lib, fnname);
+ if (fn != NULL)
+ break;
+ }
+ }
+
+#if DEBUG_DYNAMIC_WAYLAND
+ if (fn != NULL)
+ SDL_Log("WAYLAND: Found '%s' in %s (%p)\n", fnname, waylandlibs[i].libname, fn);
+ else
+ SDL_Log("WAYLAND: Symbol '%s' NOT FOUND!\n", fnname);
+#endif
+
+ if (fn == NULL)
+ *pHasModule = 0; /* kill this module. */
+
+ return fn;
+}
+
+#endif /* SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC */
+
+/* Define all the function pointers and wrappers... */
+#define SDL_WAYLAND_MODULE(modname) int SDL_WAYLAND_HAVE_##modname = 0;
+#define SDL_WAYLAND_SYM(rc,fn,params) SDL_DYNWAYLANDFN_##fn WAYLAND_##fn = NULL;
+#define SDL_WAYLAND_INTERFACE(iface) const struct wl_interface *WAYLAND_##iface = NULL;
+#include "SDL_waylandsym.h"
+
+static int wayland_load_refcount = 0;
+
+void
+SDL_WAYLAND_UnloadSymbols(void)
+{
+ /* Don't actually unload if more than one module is using the libs... */
+ if (wayland_load_refcount > 0) {
+ if (--wayland_load_refcount == 0) {
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
+ int i;
+#endif
+
+ /* set all the function pointers to NULL. */
+#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 0;
+#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = NULL;
+#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = NULL;
+#include "SDL_waylandsym.h"
+
+
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
+ for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) {
+ if (waylandlibs[i].lib != NULL) {
+ SDL_UnloadObject(waylandlibs[i].lib);
+ waylandlibs[i].lib = NULL;
+ }
+ }
+#endif
+ }
+ }
+}
+
+/* returns non-zero if all needed symbols were loaded. */
+int
+SDL_WAYLAND_LoadSymbols(void)
+{
+ int rc = 1; /* always succeed if not using Dynamic WAYLAND stuff. */
+
+ /* deal with multiple modules (dga, wayland, etc) needing these symbols... */
+ if (wayland_load_refcount++ == 0) {
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
+ int i;
+ int *thismod = NULL;
+ for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) {
+ if (waylandlibs[i].libname != NULL) {
+ waylandlibs[i].lib = SDL_LoadObject(waylandlibs[i].libname);
+ }
+ }
+
+#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; /* default yes */
+#include "SDL_waylandsym.h"
+
+#define SDL_WAYLAND_MODULE(modname) thismod = &SDL_WAYLAND_HAVE_##modname;
+#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = (SDL_DYNWAYLANDFN_##fn) WAYLAND_GetSym(#fn,thismod);
+#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = (struct wl_interface *) WAYLAND_GetSym(#iface,thismod);
+#include "SDL_waylandsym.h"
+
+ if (SDL_WAYLAND_HAVE_WAYLAND_CLIENT) {
+ /* all required symbols loaded. */
+ SDL_ClearError();
+ } else {
+ /* in case something got loaded... */
+ SDL_WAYLAND_UnloadSymbols();
+ rc = 0;
+ }
+
+#else /* no dynamic WAYLAND */
+
+#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; /* default yes */
+#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = fn;
+#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = &iface;
+#include "SDL_waylandsym.h"
+
+#endif
+ }
+
+ return rc;
+}
+
+#endif /* SDL_VIDEO_DRIVER_WAYLAND */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylanddyn.h b/src/3rdparty/SDL2/src/video/wayland/SDL_waylanddyn.h
new file mode 100644
index 0000000..720427e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylanddyn.h
@@ -0,0 +1,107 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_waylanddyn_h_
+#define SDL_waylanddyn_h_
+
+#include "../../SDL_internal.h"
+
+/* We can't include wayland-client.h here
+ * but we need some structs from it
+ */
+struct wl_interface;
+struct wl_proxy;
+struct wl_event_queue;
+struct wl_display;
+struct wl_surface;
+struct wl_shm;
+
+#include <stdint.h>
+#include "wayland-cursor.h"
+#include "wayland-util.h"
+#include "xkbcommon/xkbcommon.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+int SDL_WAYLAND_LoadSymbols(void);
+void SDL_WAYLAND_UnloadSymbols(void);
+
+#define SDL_WAYLAND_MODULE(modname) extern int SDL_WAYLAND_HAVE_##modname;
+#define SDL_WAYLAND_SYM(rc,fn,params) \
+ typedef rc (*SDL_DYNWAYLANDFN_##fn) params; \
+ extern SDL_DYNWAYLANDFN_##fn WAYLAND_##fn;
+#define SDL_WAYLAND_INTERFACE(iface) extern const struct wl_interface *WAYLAND_##iface;
+#include "SDL_waylandsym.h"
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
+
+#ifdef _WAYLAND_CLIENT_H
+#error Do not include wayland-client ahead of SDL_waylanddyn.h in dynamic loading mode
+#endif
+
+/* wayland-client-protocol.h included from wayland-client.h
+ * has inline functions that require these to be defined in dynamic loading mode
+ */
+
+#define wl_proxy_create (*WAYLAND_wl_proxy_create)
+#define wl_proxy_destroy (*WAYLAND_wl_proxy_destroy)
+#define wl_proxy_marshal (*WAYLAND_wl_proxy_marshal)
+#define wl_proxy_set_user_data (*WAYLAND_wl_proxy_set_user_data)
+#define wl_proxy_get_user_data (*WAYLAND_wl_proxy_get_user_data)
+#define wl_proxy_add_listener (*WAYLAND_wl_proxy_add_listener)
+#define wl_proxy_marshal_constructor (*WAYLAND_wl_proxy_marshal_constructor)
+#define wl_proxy_marshal_constructor_versioned (*WAYLAND_wl_proxy_marshal_constructor_versioned)
+
+#define wl_seat_interface (*WAYLAND_wl_seat_interface)
+#define wl_surface_interface (*WAYLAND_wl_surface_interface)
+#define wl_shm_pool_interface (*WAYLAND_wl_shm_pool_interface)
+#define wl_buffer_interface (*WAYLAND_wl_buffer_interface)
+#define wl_registry_interface (*WAYLAND_wl_registry_interface)
+#define wl_shell_surface_interface (*WAYLAND_wl_shell_surface_interface)
+#define wl_region_interface (*WAYLAND_wl_region_interface)
+#define wl_pointer_interface (*WAYLAND_wl_pointer_interface)
+#define wl_keyboard_interface (*WAYLAND_wl_keyboard_interface)
+#define wl_compositor_interface (*WAYLAND_wl_compositor_interface)
+#define wl_output_interface (*WAYLAND_wl_output_interface)
+#define wl_shell_interface (*WAYLAND_wl_shell_interface)
+#define wl_shm_interface (*WAYLAND_wl_shm_interface)
+#define wl_data_device_interface (*WAYLAND_wl_data_device_interface)
+#define wl_data_offer_interface (*WAYLAND_wl_data_offer_interface)
+#define wl_data_source_interface (*WAYLAND_wl_data_source_interface)
+#define wl_data_device_manager_interface (*WAYLAND_wl_data_device_manager_interface)
+
+#endif /* SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC */
+
+#include "wayland-client-core.h"
+#include "wayland-client-protocol.h"
+#include "wayland-egl.h"
+
+#endif /* SDL_waylanddyn_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylandevents.c b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandevents.c
new file mode 100644
index 0000000..53453a2
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandevents.c
@@ -0,0 +1,1129 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WAYLAND
+
+#include "SDL_stdinc.h"
+#include "SDL_assert.h"
+#include "SDL_log.h"
+
+#include "../../core/unix/SDL_poll.h"
+#include "../../events/SDL_sysevents.h"
+#include "../../events/SDL_events_c.h"
+#include "../../events/scancodes_xfree86.h"
+
+#include "SDL_waylandvideo.h"
+#include "SDL_waylandevents_c.h"
+#include "SDL_waylandwindow.h"
+
+#include "SDL_waylanddyn.h"
+
+#include "pointer-constraints-unstable-v1-client-protocol.h"
+#include "relative-pointer-unstable-v1-client-protocol.h"
+#include "xdg-shell-unstable-v6-client-protocol.h"
+
+#include <linux/input.h>
+#include <sys/select.h>
+#include <sys/mman.h>
+#include <poll.h>
+#include <unistd.h>
+#include <xkbcommon/xkbcommon.h>
+
+struct SDL_WaylandInput {
+ SDL_VideoData *display;
+ struct wl_seat *seat;
+ struct wl_pointer *pointer;
+ struct wl_touch *touch;
+ struct wl_keyboard *keyboard;
+ SDL_WaylandDataDevice *data_device;
+ struct zwp_relative_pointer_v1 *relative_pointer;
+ SDL_WindowData *pointer_focus;
+ SDL_WindowData *keyboard_focus;
+
+ /* Last motion location */
+ wl_fixed_t sx_w;
+ wl_fixed_t sy_w;
+
+ double dx_frac;
+ double dy_frac;
+
+ struct {
+ struct xkb_keymap *keymap;
+ struct xkb_state *state;
+ } xkb;
+};
+
+struct SDL_WaylandTouchPoint {
+ SDL_TouchID id;
+ float x;
+ float y;
+ struct wl_surface* surface;
+
+ struct SDL_WaylandTouchPoint* prev;
+ struct SDL_WaylandTouchPoint* next;
+};
+
+struct SDL_WaylandTouchPointList {
+ struct SDL_WaylandTouchPoint* head;
+ struct SDL_WaylandTouchPoint* tail;
+};
+
+static struct SDL_WaylandTouchPointList touch_points = {NULL, NULL};
+
+static void
+touch_add(SDL_TouchID id, float x, float y, struct wl_surface *surface)
+{
+ struct SDL_WaylandTouchPoint* tp = SDL_malloc(sizeof(struct SDL_WaylandTouchPoint));
+
+ tp->id = id;
+ tp->x = x;
+ tp->y = y;
+ tp->surface = surface;
+
+ if (touch_points.tail) {
+ touch_points.tail->next = tp;
+ tp->prev = touch_points.tail;
+ } else {
+ touch_points.head = tp;
+ tp->prev = NULL;
+ }
+
+ touch_points.tail = tp;
+ tp->next = NULL;
+}
+
+static void
+touch_update(SDL_TouchID id, float x, float y)
+{
+ struct SDL_WaylandTouchPoint* tp = touch_points.head;
+
+ while (tp) {
+ if (tp->id == id) {
+ tp->x = x;
+ tp->y = y;
+ }
+
+ tp = tp->next;
+ }
+}
+
+static void
+touch_del(SDL_TouchID id, float* x, float* y)
+{
+ struct SDL_WaylandTouchPoint* tp = touch_points.head;
+
+ while (tp) {
+ if (tp->id == id) {
+ *x = tp->x;
+ *y = tp->y;
+
+ if (tp->prev) {
+ tp->prev->next = tp->next;
+ } else {
+ touch_points.head = tp->next;
+ }
+
+ if (tp->next) {
+ tp->next->prev = tp->prev;
+ } else {
+ touch_points.tail = tp->prev;
+ }
+
+ SDL_free(tp);
+ }
+
+ tp = tp->next;
+ }
+}
+
+static struct wl_surface*
+touch_surface(SDL_TouchID id)
+{
+ struct SDL_WaylandTouchPoint* tp = touch_points.head;
+
+ while (tp) {
+ if (tp->id == id) {
+ return tp->surface;
+ }
+
+ tp = tp->next;
+ }
+
+ return NULL;
+}
+
+void
+Wayland_PumpEvents(_THIS)
+{
+ SDL_VideoData *d = _this->driverdata;
+
+ if (SDL_IOReady(WAYLAND_wl_display_get_fd(d->display), SDL_FALSE, 0)) {
+ WAYLAND_wl_display_dispatch(d->display);
+ }
+ else
+ {
+ WAYLAND_wl_display_dispatch_pending(d->display);
+ }
+}
+
+static void
+pointer_handle_enter(void *data, struct wl_pointer *pointer,
+ uint32_t serial, struct wl_surface *surface,
+ wl_fixed_t sx_w, wl_fixed_t sy_w)
+{
+ struct SDL_WaylandInput *input = data;
+ SDL_WindowData *window;
+
+ if (!surface) {
+ /* enter event for a window we've just destroyed */
+ return;
+ }
+
+ /* This handler will be called twice in Wayland 1.4
+ * Once for the window surface which has valid user data
+ * and again for the mouse cursor surface which does not have valid user data
+ * We ignore the later
+ */
+
+ window = (SDL_WindowData *)wl_surface_get_user_data(surface);
+
+ if (window) {
+ input->pointer_focus = window;
+ SDL_SetMouseFocus(window->sdlwindow);
+ }
+}
+
+static void
+pointer_handle_leave(void *data, struct wl_pointer *pointer,
+ uint32_t serial, struct wl_surface *surface)
+{
+ struct SDL_WaylandInput *input = data;
+
+ if (input->pointer_focus) {
+ SDL_SetMouseFocus(NULL);
+ input->pointer_focus = NULL;
+ }
+}
+
+static void
+pointer_handle_motion(void *data, struct wl_pointer *pointer,
+ uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w)
+{
+ struct SDL_WaylandInput *input = data;
+ SDL_WindowData *window = input->pointer_focus;
+ input->sx_w = sx_w;
+ input->sy_w = sy_w;
+ if (input->pointer_focus) {
+ const int sx = wl_fixed_to_int(sx_w);
+ const int sy = wl_fixed_to_int(sy_w);
+ SDL_SendMouseMotion(window->sdlwindow, 0, 0, sx, sy);
+ }
+}
+
+static SDL_bool
+ProcessHitTest(struct SDL_WaylandInput *input, uint32_t serial)
+{
+ SDL_WindowData *window_data = input->pointer_focus;
+ SDL_Window *window = window_data->sdlwindow;
+
+ if (window->hit_test) {
+ const SDL_Point point = { wl_fixed_to_int(input->sx_w), wl_fixed_to_int(input->sy_w) };
+ const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data);
+
+ static const uint32_t directions_wl[] = {
+ WL_SHELL_SURFACE_RESIZE_TOP_LEFT, WL_SHELL_SURFACE_RESIZE_TOP,
+ WL_SHELL_SURFACE_RESIZE_TOP_RIGHT, WL_SHELL_SURFACE_RESIZE_RIGHT,
+ WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT, WL_SHELL_SURFACE_RESIZE_BOTTOM,
+ WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT, WL_SHELL_SURFACE_RESIZE_LEFT
+ };
+
+ /* the names are different (ZXDG_TOPLEVEL_V6_RESIZE_EDGE_* vs
+ WL_SHELL_SURFACE_RESIZE_*), but the values are the same. */
+ const uint32_t *directions_zxdg = directions_wl;
+
+ switch (rc) {
+ case SDL_HITTEST_DRAGGABLE:
+ if (input->display->shell.zxdg) {
+ zxdg_toplevel_v6_move(window_data->shell_surface.zxdg.roleobj.toplevel, input->seat, serial);
+ } else {
+ wl_shell_surface_move(window_data->shell_surface.wl, input->seat, serial);
+ }
+ return SDL_TRUE;
+
+ case SDL_HITTEST_RESIZE_TOPLEFT:
+ case SDL_HITTEST_RESIZE_TOP:
+ case SDL_HITTEST_RESIZE_TOPRIGHT:
+ case SDL_HITTEST_RESIZE_RIGHT:
+ case SDL_HITTEST_RESIZE_BOTTOMRIGHT:
+ case SDL_HITTEST_RESIZE_BOTTOM:
+ case SDL_HITTEST_RESIZE_BOTTOMLEFT:
+ case SDL_HITTEST_RESIZE_LEFT:
+ if (input->display->shell.zxdg) {
+ zxdg_toplevel_v6_resize(window_data->shell_surface.zxdg.roleobj.toplevel, input->seat, serial, directions_zxdg[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
+ } else {
+ wl_shell_surface_resize(window_data->shell_surface.wl, input->seat, serial, directions_wl[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
+ }
+ return SDL_TRUE;
+
+ default: return SDL_FALSE;
+ }
+ }
+
+ return SDL_FALSE;
+}
+
+static void
+pointer_handle_button_common(struct SDL_WaylandInput *input, uint32_t serial,
+ uint32_t time, uint32_t button, uint32_t state_w)
+{
+ SDL_WindowData *window = input->pointer_focus;
+ enum wl_pointer_button_state state = state_w;
+ uint32_t sdl_button;
+
+ if (input->pointer_focus) {
+ switch (button) {
+ case BTN_LEFT:
+ sdl_button = SDL_BUTTON_LEFT;
+ if (ProcessHitTest(input, serial)) {
+ return; /* don't pass this event on to app. */
+ }
+ break;
+ case BTN_MIDDLE:
+ sdl_button = SDL_BUTTON_MIDDLE;
+ break;
+ case BTN_RIGHT:
+ sdl_button = SDL_BUTTON_RIGHT;
+ break;
+ case BTN_SIDE:
+ sdl_button = SDL_BUTTON_X1;
+ break;
+ case BTN_EXTRA:
+ sdl_button = SDL_BUTTON_X2;
+ break;
+ default:
+ return;
+ }
+
+ Wayland_data_device_set_serial(input->data_device, serial);
+
+ SDL_SendMouseButton(window->sdlwindow, 0,
+ state ? SDL_PRESSED : SDL_RELEASED, sdl_button);
+ }
+}
+
+static void
+pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
+ uint32_t time, uint32_t button, uint32_t state_w)
+{
+ struct SDL_WaylandInput *input = data;
+
+ pointer_handle_button_common(input, serial, time, button, state_w);
+}
+
+static void
+pointer_handle_axis_common(struct SDL_WaylandInput *input,
+ uint32_t time, uint32_t axis, wl_fixed_t value)
+{
+ SDL_WindowData *window = input->pointer_focus;
+ enum wl_pointer_axis a = axis;
+ float x, y;
+
+ if (input->pointer_focus) {
+ switch (a) {
+ case WL_POINTER_AXIS_VERTICAL_SCROLL:
+ x = 0;
+ y = 0 - (float)wl_fixed_to_double(value);
+ break;
+ case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
+ x = 0 - (float)wl_fixed_to_double(value);
+ y = 0;
+ break;
+ default:
+ return;
+ }
+
+ SDL_SendMouseWheel(window->sdlwindow, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
+ }
+}
+
+static void
+pointer_handle_axis(void *data, struct wl_pointer *pointer,
+ uint32_t time, uint32_t axis, wl_fixed_t value)
+{
+ struct SDL_WaylandInput *input = data;
+
+ pointer_handle_axis_common(input, time, axis, value);
+}
+
+static const struct wl_pointer_listener pointer_listener = {
+ pointer_handle_enter,
+ pointer_handle_leave,
+ pointer_handle_motion,
+ pointer_handle_button,
+ pointer_handle_axis,
+ NULL, /* frame */
+ NULL, /* axis_source */
+ NULL, /* axis_stop */
+ NULL, /* axis_discrete */
+};
+
+static void
+touch_handler_down(void *data, struct wl_touch *touch, unsigned int serial,
+ unsigned int timestamp, struct wl_surface *surface,
+ int id, wl_fixed_t fx, wl_fixed_t fy)
+{
+ float x, y;
+ SDL_WindowData* window;
+
+ window = (SDL_WindowData *)wl_surface_get_user_data(surface);
+
+ x = wl_fixed_to_double(fx) / window->sdlwindow->w;
+ y = wl_fixed_to_double(fy) / window->sdlwindow->h;
+
+ touch_add(id, x, y, surface);
+ SDL_SendTouch(1, (SDL_FingerID)id, SDL_TRUE, x, y, 1.0f);
+}
+
+static void
+touch_handler_up(void *data, struct wl_touch *touch, unsigned int serial,
+ unsigned int timestamp, int id)
+{
+ float x = 0, y = 0;
+
+ touch_del(id, &x, &y);
+ SDL_SendTouch(1, (SDL_FingerID)id, SDL_FALSE, x, y, 0.0f);
+}
+
+static void
+touch_handler_motion(void *data, struct wl_touch *touch, unsigned int timestamp,
+ int id, wl_fixed_t fx, wl_fixed_t fy)
+{
+ float x, y;
+ SDL_WindowData* window;
+
+ window = (SDL_WindowData *)wl_surface_get_user_data(touch_surface(id));
+
+ x = wl_fixed_to_double(fx) / window->sdlwindow->w;
+ y = wl_fixed_to_double(fy) / window->sdlwindow->h;
+
+ touch_update(id, x, y);
+ SDL_SendTouchMotion(1, (SDL_FingerID)id, x, y, 1.0f);
+}
+
+static void
+touch_handler_frame(void *data, struct wl_touch *touch)
+{
+
+}
+
+static void
+touch_handler_cancel(void *data, struct wl_touch *touch)
+{
+
+}
+
+static const struct wl_touch_listener touch_listener = {
+ touch_handler_down,
+ touch_handler_up,
+ touch_handler_motion,
+ touch_handler_frame,
+ touch_handler_cancel,
+ NULL, /* shape */
+ NULL, /* orientation */
+};
+
+static void
+keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
+ uint32_t format, int fd, uint32_t size)
+{
+ struct SDL_WaylandInput *input = data;
+ char *map_str;
+
+ if (!data) {
+ close(fd);
+ return;
+ }
+
+ if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
+ close(fd);
+ return;
+ }
+
+ map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
+ if (map_str == MAP_FAILED) {
+ close(fd);
+ return;
+ }
+
+ input->xkb.keymap = WAYLAND_xkb_keymap_new_from_string(input->display->xkb_context,
+ map_str,
+ XKB_KEYMAP_FORMAT_TEXT_V1,
+ 0);
+ munmap(map_str, size);
+ close(fd);
+
+ if (!input->xkb.keymap) {
+ fprintf(stderr, "failed to compile keymap\n");
+ return;
+ }
+
+ input->xkb.state = WAYLAND_xkb_state_new(input->xkb.keymap);
+ if (!input->xkb.state) {
+ fprintf(stderr, "failed to create XKB state\n");
+ WAYLAND_xkb_keymap_unref(input->xkb.keymap);
+ input->xkb.keymap = NULL;
+ return;
+ }
+}
+
+static void
+keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
+ uint32_t serial, struct wl_surface *surface,
+ struct wl_array *keys)
+{
+ struct SDL_WaylandInput *input = data;
+ SDL_WindowData *window;
+
+ if (!surface) {
+ /* enter event for a window we've just destroyed */
+ return;
+ }
+
+ window = wl_surface_get_user_data(surface);
+
+ if (window) {
+ input->keyboard_focus = window;
+ window->keyboard_device = input;
+ SDL_SetKeyboardFocus(window->sdlwindow);
+ }
+}
+
+static void
+keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
+ uint32_t serial, struct wl_surface *surface)
+{
+ SDL_SetKeyboardFocus(NULL);
+}
+
+static void
+keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
+ uint32_t serial, uint32_t time, uint32_t key,
+ uint32_t state_w)
+{
+ struct SDL_WaylandInput *input = data;
+ SDL_WindowData *window = input->keyboard_focus;
+ enum wl_keyboard_key_state state = state_w;
+ const xkb_keysym_t *syms;
+ uint32_t scancode;
+ char text[8];
+ int size;
+
+ if (key < SDL_arraysize(xfree86_scancode_table2)) {
+ scancode = xfree86_scancode_table2[key];
+
+ // TODO when do we get WL_KEYBOARD_KEY_STATE_REPEAT?
+ if (scancode != SDL_SCANCODE_UNKNOWN)
+ SDL_SendKeyboardKey(state == WL_KEYBOARD_KEY_STATE_PRESSED ?
+ SDL_PRESSED : SDL_RELEASED, scancode);
+ }
+
+ if (!window || window->keyboard_device != input || !input->xkb.state)
+ return;
+
+ // TODO can this happen?
+ if (WAYLAND_xkb_state_key_get_syms(input->xkb.state, key + 8, &syms) != 1)
+ return;
+
+ if (state) {
+ size = WAYLAND_xkb_keysym_to_utf8(syms[0], text, sizeof text);
+
+ if (size > 0) {
+ text[size] = 0;
+
+ Wayland_data_device_set_serial(input->data_device, serial);
+
+ SDL_SendKeyboardText(text);
+ }
+ }
+}
+
+static void
+keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
+ uint32_t serial, uint32_t mods_depressed,
+ uint32_t mods_latched, uint32_t mods_locked,
+ uint32_t group)
+{
+ struct SDL_WaylandInput *input = data;
+
+ WAYLAND_xkb_state_update_mask(input->xkb.state, mods_depressed, mods_latched,
+ mods_locked, 0, 0, group);
+}
+
+static const struct wl_keyboard_listener keyboard_listener = {
+ keyboard_handle_keymap,
+ keyboard_handle_enter,
+ keyboard_handle_leave,
+ keyboard_handle_key,
+ keyboard_handle_modifiers,
+ NULL, /* repeat_info */
+};
+
+static void
+seat_handle_capabilities(void *data, struct wl_seat *seat,
+ enum wl_seat_capability caps)
+{
+ struct SDL_WaylandInput *input = data;
+
+ if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) {
+ input->pointer = wl_seat_get_pointer(seat);
+ input->display->pointer = input->pointer;
+ wl_pointer_set_user_data(input->pointer, input);
+ wl_pointer_add_listener(input->pointer, &pointer_listener,
+ input);
+ } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
+ wl_pointer_destroy(input->pointer);
+ input->pointer = NULL;
+ input->display->pointer = NULL;
+ }
+
+ if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !input->touch) {
+ SDL_AddTouch(1, "wayland_touch");
+ input->touch = wl_seat_get_touch(seat);
+ wl_touch_set_user_data(input->touch, input);
+ wl_touch_add_listener(input->touch, &touch_listener,
+ input);
+ } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && input->touch) {
+ SDL_DelTouch(1);
+ wl_touch_destroy(input->touch);
+ input->touch = NULL;
+ }
+
+ if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->keyboard) {
+ input->keyboard = wl_seat_get_keyboard(seat);
+ wl_keyboard_set_user_data(input->keyboard, input);
+ wl_keyboard_add_listener(input->keyboard, &keyboard_listener,
+ input);
+ } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard) {
+ wl_keyboard_destroy(input->keyboard);
+ input->keyboard = NULL;
+ }
+}
+
+static const struct wl_seat_listener seat_listener = {
+ seat_handle_capabilities,
+ NULL, /* name */
+};
+
+static void
+data_source_handle_target(void *data, struct wl_data_source *wl_data_source,
+ const char *mime_type)
+{
+}
+
+static void
+data_source_handle_send(void *data, struct wl_data_source *wl_data_source,
+ const char *mime_type, int32_t fd)
+{
+ Wayland_data_source_send((SDL_WaylandDataSource *)data, mime_type, fd);
+}
+
+static void
+data_source_handle_cancelled(void *data, struct wl_data_source *wl_data_source)
+{
+ Wayland_data_source_destroy(data);
+}
+
+static void
+data_source_handle_dnd_drop_performed(void *data, struct wl_data_source *wl_data_source)
+{
+}
+
+static void
+data_source_handle_dnd_finished(void *data, struct wl_data_source *wl_data_source)
+{
+}
+
+static void
+data_source_handle_action(void *data, struct wl_data_source *wl_data_source,
+ uint32_t dnd_action)
+{
+}
+
+static const struct wl_data_source_listener data_source_listener = {
+ data_source_handle_target,
+ data_source_handle_send,
+ data_source_handle_cancelled,
+ data_source_handle_dnd_drop_performed, // Version 3
+ data_source_handle_dnd_finished, // Version 3
+ data_source_handle_action, // Version 3
+};
+
+SDL_WaylandDataSource*
+Wayland_data_source_create(_THIS)
+{
+ SDL_WaylandDataSource *data_source = NULL;
+ SDL_VideoData *driver_data = NULL;
+ struct wl_data_source *id = NULL;
+
+ if (_this == NULL || _this->driverdata == NULL) {
+ SDL_SetError("Video driver uninitialized");
+ } else {
+ driver_data = _this->driverdata;
+
+ if (driver_data->data_device_manager != NULL) {
+ id = wl_data_device_manager_create_data_source(
+ driver_data->data_device_manager);
+ }
+
+ if (id == NULL) {
+ SDL_SetError("Wayland unable to create data source");
+ } else {
+ data_source = SDL_calloc(1, sizeof *data_source);
+ if (data_source == NULL) {
+ SDL_OutOfMemory();
+ wl_data_source_destroy(id);
+ } else {
+ WAYLAND_wl_list_init(&(data_source->mimes));
+ data_source->source = id;
+ wl_data_source_set_user_data(id, data_source);
+ wl_data_source_add_listener(id, &data_source_listener,
+ data_source);
+ }
+ }
+ }
+ return data_source;
+}
+
+static void
+data_offer_handle_offer(void *data, struct wl_data_offer *wl_data_offer,
+ const char *mime_type)
+{
+ SDL_WaylandDataOffer *offer = data;
+ Wayland_data_offer_add_mime(offer, mime_type);
+}
+
+static void
+data_offer_handle_source_actions(void *data, struct wl_data_offer *wl_data_offer,
+ uint32_t source_actions)
+{
+}
+
+static void
+data_offer_handle_actions(void *data, struct wl_data_offer *wl_data_offer,
+ uint32_t dnd_action)
+{
+}
+
+static const struct wl_data_offer_listener data_offer_listener = {
+ data_offer_handle_offer,
+ data_offer_handle_source_actions, // Version 3
+ data_offer_handle_actions, // Version 3
+};
+
+static void
+data_device_handle_data_offer(void *data, struct wl_data_device *wl_data_device,
+ struct wl_data_offer *id)
+{
+ SDL_WaylandDataOffer *data_offer = NULL;
+
+ data_offer = SDL_calloc(1, sizeof *data_offer);
+ if (data_offer == NULL) {
+ SDL_OutOfMemory();
+ } else {
+ data_offer->offer = id;
+ data_offer->data_device = data;
+ WAYLAND_wl_list_init(&(data_offer->mimes));
+ wl_data_offer_set_user_data(id, data_offer);
+ wl_data_offer_add_listener(id, &data_offer_listener, data_offer);
+ }
+}
+
+static void
+data_device_handle_enter(void *data, struct wl_data_device *wl_data_device,
+ uint32_t serial, struct wl_surface *surface,
+ wl_fixed_t x, wl_fixed_t y, struct wl_data_offer *id)
+{
+ SDL_WaylandDataDevice *data_device = data;
+ SDL_bool has_mime = SDL_FALSE;
+ uint32_t dnd_action = WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE;
+
+ data_device->drag_serial = serial;
+
+ if (id != NULL) {
+ data_device->drag_offer = wl_data_offer_get_user_data(id);
+
+ /* TODO: SDL Support more mime types */
+ has_mime = Wayland_data_offer_has_mime(
+ data_device->drag_offer, FILE_MIME);
+
+ /* If drag_mime is NULL this will decline the offer */
+ wl_data_offer_accept(id, serial,
+ (has_mime == SDL_TRUE) ? FILE_MIME : NULL);
+
+ /* SDL only supports "copy" style drag and drop */
+ if (has_mime == SDL_TRUE) {
+ dnd_action = WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY;
+ }
+ wl_data_offer_set_actions(data_device->drag_offer->offer,
+ dnd_action, dnd_action);
+ }
+}
+
+static void
+data_device_handle_leave(void *data, struct wl_data_device *wl_data_device)
+{
+ SDL_WaylandDataDevice *data_device = data;
+ SDL_WaylandDataOffer *offer = NULL;
+
+ if (data_device->selection_offer != NULL) {
+ data_device->selection_offer = NULL;
+ Wayland_data_offer_destroy(offer);
+ }
+}
+
+static void
+data_device_handle_motion(void *data, struct wl_data_device *wl_data_device,
+ uint32_t time, wl_fixed_t x, wl_fixed_t y)
+{
+}
+
+static void
+data_device_handle_drop(void *data, struct wl_data_device *wl_data_device)
+{
+ SDL_WaylandDataDevice *data_device = data;
+ void *buffer = NULL;
+ size_t length = 0;
+
+ const char *current_uri = NULL;
+ const char *last_char = NULL;
+ char *current_char = NULL;
+
+ if (data_device->drag_offer != NULL) {
+ /* TODO: SDL Support more mime types */
+ buffer = Wayland_data_offer_receive(data_device->drag_offer,
+ &length, FILE_MIME, SDL_FALSE);
+
+ /* uri-list */
+ current_uri = (const char *)buffer;
+ last_char = (const char *)buffer + length;
+ for (current_char = buffer; current_char < last_char; ++current_char) {
+ if (*current_char == '\n' || *current_char == 0) {
+ if (*current_uri != 0 && *current_uri != '#') {
+ *current_char = 0;
+ SDL_SendDropFile(NULL, current_uri);
+ }
+ current_uri = (const char *)current_char + 1;
+ }
+ }
+
+ SDL_free(buffer);
+ }
+}
+
+static void
+data_device_handle_selection(void *data, struct wl_data_device *wl_data_device,
+ struct wl_data_offer *id)
+{
+ SDL_WaylandDataDevice *data_device = data;
+ SDL_WaylandDataOffer *offer = NULL;
+
+ if (id != NULL) {
+ offer = wl_data_offer_get_user_data(id);
+ }
+
+ if (data_device->selection_offer != offer) {
+ Wayland_data_offer_destroy(data_device->selection_offer);
+ data_device->selection_offer = offer;
+ }
+
+ SDL_SendClipboardUpdate();
+}
+
+static const struct wl_data_device_listener data_device_listener = {
+ data_device_handle_data_offer,
+ data_device_handle_enter,
+ data_device_handle_leave,
+ data_device_handle_motion,
+ data_device_handle_drop,
+ data_device_handle_selection
+};
+
+void
+Wayland_display_add_input(SDL_VideoData *d, uint32_t id)
+{
+ struct SDL_WaylandInput *input;
+ SDL_WaylandDataDevice *data_device = NULL;
+
+ input = SDL_calloc(1, sizeof *input);
+ if (input == NULL)
+ return;
+
+ input->display = d;
+ input->seat = wl_registry_bind(d->registry, id, &wl_seat_interface, 1);
+ input->sx_w = wl_fixed_from_int(0);
+ input->sy_w = wl_fixed_from_int(0);
+ d->input = input;
+
+ if (d->data_device_manager != NULL) {
+ data_device = SDL_calloc(1, sizeof *data_device);
+ if (data_device == NULL) {
+ return;
+ }
+
+ data_device->data_device = wl_data_device_manager_get_data_device(
+ d->data_device_manager, input->seat
+ );
+ data_device->video_data = d;
+
+ if (data_device->data_device == NULL) {
+ SDL_free(data_device);
+ } else {
+ wl_data_device_set_user_data(data_device->data_device, data_device);
+ wl_data_device_add_listener(data_device->data_device,
+ &data_device_listener, data_device);
+ input->data_device = data_device;
+ }
+ }
+
+ wl_seat_add_listener(input->seat, &seat_listener, input);
+ wl_seat_set_user_data(input->seat, input);
+
+ WAYLAND_wl_display_flush(d->display);
+}
+
+void Wayland_display_destroy_input(SDL_VideoData *d)
+{
+ struct SDL_WaylandInput *input = d->input;
+
+ if (!input)
+ return;
+
+ if (input->data_device != NULL) {
+ Wayland_data_device_clear_selection(input->data_device);
+ if (input->data_device->selection_offer != NULL) {
+ Wayland_data_offer_destroy(input->data_device->selection_offer);
+ }
+ if (input->data_device->drag_offer != NULL) {
+ Wayland_data_offer_destroy(input->data_device->drag_offer);
+ }
+ if (input->data_device->data_device != NULL) {
+ wl_data_device_release(input->data_device->data_device);
+ }
+ SDL_free(input->data_device);
+ }
+
+ if (input->keyboard)
+ wl_keyboard_destroy(input->keyboard);
+
+ if (input->pointer)
+ wl_pointer_destroy(input->pointer);
+
+ if (input->touch) {
+ SDL_DelTouch(1);
+ wl_touch_destroy(input->touch);
+ }
+
+ if (input->seat)
+ wl_seat_destroy(input->seat);
+
+ if (input->xkb.state)
+ WAYLAND_xkb_state_unref(input->xkb.state);
+
+ if (input->xkb.keymap)
+ WAYLAND_xkb_keymap_unref(input->xkb.keymap);
+
+ SDL_free(input);
+ d->input = NULL;
+}
+
+SDL_WaylandDataDevice* Wayland_get_data_device(struct SDL_WaylandInput *input)
+{
+ if (input == NULL) {
+ return NULL;
+ }
+
+ return input->data_device;
+}
+
+/* !!! FIXME: just merge these into display_handle_global(). */
+void Wayland_display_add_relative_pointer_manager(SDL_VideoData *d, uint32_t id)
+{
+ d->relative_pointer_manager =
+ wl_registry_bind(d->registry, id,
+ &zwp_relative_pointer_manager_v1_interface, 1);
+}
+
+void Wayland_display_destroy_relative_pointer_manager(SDL_VideoData *d)
+{
+ if (d->relative_pointer_manager)
+ zwp_relative_pointer_manager_v1_destroy(d->relative_pointer_manager);
+}
+
+void Wayland_display_add_pointer_constraints(SDL_VideoData *d, uint32_t id)
+{
+ d->pointer_constraints =
+ wl_registry_bind(d->registry, id,
+ &zwp_pointer_constraints_v1_interface, 1);
+}
+
+void Wayland_display_destroy_pointer_constraints(SDL_VideoData *d)
+{
+ if (d->pointer_constraints)
+ zwp_pointer_constraints_v1_destroy(d->pointer_constraints);
+}
+
+static void
+relative_pointer_handle_relative_motion(void *data,
+ struct zwp_relative_pointer_v1 *pointer,
+ uint32_t time_hi,
+ uint32_t time_lo,
+ wl_fixed_t dx_w,
+ wl_fixed_t dy_w,
+ wl_fixed_t dx_unaccel_w,
+ wl_fixed_t dy_unaccel_w)
+{
+ struct SDL_WaylandInput *input = data;
+ SDL_VideoData *d = input->display;
+ SDL_WindowData *window = input->pointer_focus;
+ double dx_unaccel;
+ double dy_unaccel;
+ double dx;
+ double dy;
+
+ dx_unaccel = wl_fixed_to_double(dx_unaccel_w);
+ dy_unaccel = wl_fixed_to_double(dy_unaccel_w);
+
+ /* Add left over fraction from last event. */
+ dx_unaccel += input->dx_frac;
+ dy_unaccel += input->dy_frac;
+
+ input->dx_frac = modf(dx_unaccel, &dx);
+ input->dy_frac = modf(dy_unaccel, &dy);
+
+ if (input->pointer_focus && d->relative_mouse_mode) {
+ SDL_SendMouseMotion(window->sdlwindow, 0, 1, (int)dx, (int)dy);
+ }
+}
+
+static const struct zwp_relative_pointer_v1_listener relative_pointer_listener = {
+ relative_pointer_handle_relative_motion,
+};
+
+static void
+locked_pointer_locked(void *data,
+ struct zwp_locked_pointer_v1 *locked_pointer)
+{
+}
+
+static void
+locked_pointer_unlocked(void *data,
+ struct zwp_locked_pointer_v1 *locked_pointer)
+{
+}
+
+static const struct zwp_locked_pointer_v1_listener locked_pointer_listener = {
+ locked_pointer_locked,
+ locked_pointer_unlocked,
+};
+
+static void
+lock_pointer_to_window(SDL_Window *window,
+ struct SDL_WaylandInput *input)
+{
+ SDL_WindowData *w = window->driverdata;
+ SDL_VideoData *d = input->display;
+ struct zwp_locked_pointer_v1 *locked_pointer;
+
+ if (w->locked_pointer)
+ return;
+
+ locked_pointer =
+ zwp_pointer_constraints_v1_lock_pointer(d->pointer_constraints,
+ w->surface,
+ input->pointer,
+ NULL,
+ ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT);
+ zwp_locked_pointer_v1_add_listener(locked_pointer,
+ &locked_pointer_listener,
+ window);
+
+ w->locked_pointer = locked_pointer;
+}
+
+int Wayland_input_lock_pointer(struct SDL_WaylandInput *input)
+{
+ SDL_VideoDevice *vd = SDL_GetVideoDevice();
+ SDL_VideoData *d = input->display;
+ SDL_Window *window;
+ struct zwp_relative_pointer_v1 *relative_pointer;
+
+ if (!d->relative_pointer_manager)
+ return -1;
+
+ if (!d->pointer_constraints)
+ return -1;
+
+ if (!input->relative_pointer) {
+ relative_pointer =
+ zwp_relative_pointer_manager_v1_get_relative_pointer(
+ d->relative_pointer_manager,
+ input->pointer);
+ zwp_relative_pointer_v1_add_listener(relative_pointer,
+ &relative_pointer_listener,
+ input);
+ input->relative_pointer = relative_pointer;
+ }
+
+ for (window = vd->windows; window; window = window->next)
+ lock_pointer_to_window(window, input);
+
+ d->relative_mouse_mode = 1;
+
+ return 0;
+}
+
+int Wayland_input_unlock_pointer(struct SDL_WaylandInput *input)
+{
+ SDL_VideoDevice *vd = SDL_GetVideoDevice();
+ SDL_VideoData *d = input->display;
+ SDL_Window *window;
+ SDL_WindowData *w;
+
+ for (window = vd->windows; window; window = window->next) {
+ w = window->driverdata;
+ if (w->locked_pointer)
+ zwp_locked_pointer_v1_destroy(w->locked_pointer);
+ w->locked_pointer = NULL;
+ }
+
+ zwp_relative_pointer_v1_destroy(input->relative_pointer);
+ input->relative_pointer = NULL;
+
+ d->relative_mouse_mode = 0;
+
+ return 0;
+}
+
+#endif /* SDL_VIDEO_DRIVER_WAYLAND */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylandevents_c.h b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandevents_c.h
new file mode 100644
index 0000000..1c5ffe5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandevents_c.h
@@ -0,0 +1,51 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_waylandevents_h_
+#define SDL_waylandevents_h_
+
+#include "SDL_waylandvideo.h"
+#include "SDL_waylandwindow.h"
+#include "SDL_waylanddatamanager.h"
+
+struct SDL_WaylandInput;
+
+extern void Wayland_PumpEvents(_THIS);
+
+extern void Wayland_display_add_input(SDL_VideoData *d, uint32_t id);
+extern void Wayland_display_destroy_input(SDL_VideoData *d);
+
+extern SDL_WaylandDataDevice* Wayland_get_data_device(struct SDL_WaylandInput *input);
+
+extern void Wayland_display_add_pointer_constraints(SDL_VideoData *d, uint32_t id);
+extern void Wayland_display_destroy_pointer_constraints(SDL_VideoData *d);
+
+extern int Wayland_input_lock_pointer(struct SDL_WaylandInput *input);
+extern int Wayland_input_unlock_pointer(struct SDL_WaylandInput *input);
+
+extern void Wayland_display_add_relative_pointer_manager(SDL_VideoData *d, uint32_t id);
+extern void Wayland_display_destroy_relative_pointer_manager(SDL_VideoData *d);
+
+#endif /* SDL_waylandevents_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylandmouse.c b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandmouse.c
new file mode 100644
index 0000000..c77b53e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandmouse.c
@@ -0,0 +1,396 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WAYLAND
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include "../SDL_sysvideo.h"
+
+#include "SDL_mouse.h"
+#include "../../events/SDL_mouse_c.h"
+#include "SDL_waylandvideo.h"
+#include "SDL_waylandevents_c.h"
+
+#include "SDL_waylanddyn.h"
+#include "wayland-cursor.h"
+
+#include "SDL_assert.h"
+
+
+typedef struct {
+ struct wl_buffer *buffer;
+ struct wl_surface *surface;
+
+ int hot_x, hot_y;
+ int w, h;
+
+ /* Either a preloaded cursor, or one we created ourselves */
+ struct wl_cursor *cursor;
+ void *shm_data;
+} Wayland_CursorData;
+
+static int
+wayland_create_tmp_file(off_t size)
+{
+ static const char template[] = "/sdl-shared-XXXXXX";
+ char *xdg_path;
+ char tmp_path[PATH_MAX];
+ int fd;
+
+ xdg_path = SDL_getenv("XDG_RUNTIME_DIR");
+ if (!xdg_path) {
+ return -1;
+ }
+
+ SDL_strlcpy(tmp_path, xdg_path, PATH_MAX);
+ SDL_strlcat(tmp_path, template, PATH_MAX);
+
+ fd = mkostemp(tmp_path, O_CLOEXEC);
+ if (fd < 0)
+ return -1;
+
+ if (ftruncate(fd, size) < 0) {
+ close(fd);
+ return -1;
+ }
+
+ return fd;
+}
+
+static void
+mouse_buffer_release(void *data, struct wl_buffer *buffer)
+{
+}
+
+static const struct wl_buffer_listener mouse_buffer_listener = {
+ mouse_buffer_release
+};
+
+static int
+create_buffer_from_shm(Wayland_CursorData *d,
+ int width,
+ int height,
+ uint32_t format)
+{
+ SDL_VideoDevice *vd = SDL_GetVideoDevice();
+ SDL_VideoData *data = (SDL_VideoData *) vd->driverdata;
+ struct wl_shm_pool *shm_pool;
+
+ int stride = width * 4;
+ int size = stride * height;
+
+ int shm_fd;
+
+ shm_fd = wayland_create_tmp_file(size);
+ if (shm_fd < 0)
+ {
+ return SDL_SetError("Creating mouse cursor buffer failed.");
+ }
+
+ d->shm_data = mmap(NULL,
+ size,
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED,
+ shm_fd,
+ 0);
+ if (d->shm_data == MAP_FAILED) {
+ d->shm_data = NULL;
+ close (shm_fd);
+ return SDL_SetError("mmap() failed.");
+ }
+
+ shm_pool = wl_shm_create_pool(data->shm, shm_fd, size);
+ d->buffer = wl_shm_pool_create_buffer(shm_pool,
+ 0,
+ width,
+ height,
+ stride,
+ format);
+ wl_buffer_add_listener(d->buffer,
+ &mouse_buffer_listener,
+ d);
+
+ wl_shm_pool_destroy (shm_pool);
+ close (shm_fd);
+
+ return 0;
+}
+
+static SDL_Cursor *
+Wayland_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
+{
+ SDL_Cursor *cursor;
+
+ cursor = calloc(1, sizeof (*cursor));
+ if (cursor) {
+ SDL_VideoDevice *vd = SDL_GetVideoDevice ();
+ SDL_VideoData *wd = (SDL_VideoData *) vd->driverdata;
+ Wayland_CursorData *data = calloc (1, sizeof (Wayland_CursorData));
+ if (!data) {
+ SDL_OutOfMemory();
+ free(cursor);
+ return NULL;
+ }
+ cursor->driverdata = (void *) data;
+
+ /* Assume ARGB8888 */
+ SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
+ SDL_assert(surface->pitch == surface->w * 4);
+
+ /* Allocate shared memory buffer for this cursor */
+ if (create_buffer_from_shm (data,
+ surface->w,
+ surface->h,
+ WL_SHM_FORMAT_ARGB8888) < 0)
+ {
+ free (cursor->driverdata);
+ free (cursor);
+ return NULL;
+ }
+
+ SDL_memcpy(data->shm_data,
+ surface->pixels,
+ surface->h * surface->pitch);
+
+ data->surface = wl_compositor_create_surface(wd->compositor);
+ wl_surface_set_user_data(data->surface, NULL);
+
+ data->hot_x = hot_x;
+ data->hot_y = hot_y;
+ data->w = surface->w;
+ data->h = surface->h;
+ } else {
+ SDL_OutOfMemory();
+ }
+
+ return cursor;
+}
+
+static SDL_Cursor *
+CreateCursorFromWlCursor(SDL_VideoData *d, struct wl_cursor *wlcursor)
+{
+ SDL_Cursor *cursor;
+
+ cursor = calloc(1, sizeof (*cursor));
+ if (cursor) {
+ Wayland_CursorData *data = calloc (1, sizeof (Wayland_CursorData));
+ if (!data) {
+ SDL_OutOfMemory();
+ free(cursor);
+ return NULL;
+ }
+ cursor->driverdata = (void *) data;
+
+ data->buffer = WAYLAND_wl_cursor_image_get_buffer(wlcursor->images[0]);
+ data->surface = wl_compositor_create_surface(d->compositor);
+ wl_surface_set_user_data(data->surface, NULL);
+ data->hot_x = wlcursor->images[0]->hotspot_x;
+ data->hot_y = wlcursor->images[0]->hotspot_y;
+ data->w = wlcursor->images[0]->width;
+ data->h = wlcursor->images[0]->height;
+ data->cursor= wlcursor;
+ } else {
+ SDL_OutOfMemory ();
+ }
+
+ return cursor;
+}
+
+static SDL_Cursor *
+Wayland_CreateDefaultCursor()
+{
+ SDL_VideoDevice *device = SDL_GetVideoDevice();
+ SDL_VideoData *data = device->driverdata;
+
+ return CreateCursorFromWlCursor (data,
+ WAYLAND_wl_cursor_theme_get_cursor(data->cursor_theme,
+ "left_ptr"));
+}
+
+static SDL_Cursor *
+Wayland_CreateSystemCursor(SDL_SystemCursor id)
+{
+ SDL_VideoDevice *vd = SDL_GetVideoDevice();
+ SDL_VideoData *d = vd->driverdata;
+
+ struct wl_cursor *cursor = NULL;
+
+ switch(id)
+ {
+ default:
+ SDL_assert(0);
+ return NULL;
+ case SDL_SYSTEM_CURSOR_ARROW:
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr");
+ break;
+ case SDL_SYSTEM_CURSOR_IBEAM:
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "xterm");
+ break;
+ case SDL_SYSTEM_CURSOR_WAIT:
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "watch");
+ break;
+ case SDL_SYSTEM_CURSOR_CROSSHAIR:
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
+ break;
+ case SDL_SYSTEM_CURSOR_WAITARROW:
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "watch");
+ break;
+ case SDL_SYSTEM_CURSOR_SIZENWSE:
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
+ break;
+ case SDL_SYSTEM_CURSOR_SIZENESW:
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
+ break;
+ case SDL_SYSTEM_CURSOR_SIZEWE:
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
+ break;
+ case SDL_SYSTEM_CURSOR_SIZENS:
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
+ break;
+ case SDL_SYSTEM_CURSOR_SIZEALL:
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
+ break;
+ case SDL_SYSTEM_CURSOR_NO:
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "xterm");
+ break;
+ case SDL_SYSTEM_CURSOR_HAND:
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
+ break;
+ }
+
+ return CreateCursorFromWlCursor(d, cursor);
+}
+
+static void
+Wayland_FreeCursor(SDL_Cursor *cursor)
+{
+ Wayland_CursorData *d;
+
+ if (!cursor)
+ return;
+
+ d = cursor->driverdata;
+
+ /* Probably not a cursor we own */
+ if (!d)
+ return;
+
+ if (d->buffer && !d->cursor)
+ wl_buffer_destroy(d->buffer);
+
+ if (d->surface)
+ wl_surface_destroy(d->surface);
+
+ /* Not sure what's meant to happen to shm_data */
+ free (cursor->driverdata);
+ SDL_free(cursor);
+}
+
+static int
+Wayland_ShowCursor(SDL_Cursor *cursor)
+{
+ SDL_VideoDevice *vd = SDL_GetVideoDevice();
+ SDL_VideoData *d = vd->driverdata;
+
+ struct wl_pointer *pointer = d->pointer;
+
+ if (!pointer)
+ return -1;
+
+ if (cursor)
+ {
+ Wayland_CursorData *data = cursor->driverdata;
+
+ wl_pointer_set_cursor (pointer, 0,
+ data->surface,
+ data->hot_x,
+ data->hot_y);
+ wl_surface_attach(data->surface, data->buffer, 0, 0);
+ wl_surface_damage(data->surface, 0, 0, data->w, data->h);
+ wl_surface_commit(data->surface);
+ }
+ else
+ {
+ wl_pointer_set_cursor (pointer, 0,
+ NULL,
+ 0,
+ 0);
+ }
+
+ return 0;
+}
+
+static void
+Wayland_WarpMouse(SDL_Window *window, int x, int y)
+{
+ SDL_Unsupported();
+}
+
+static int
+Wayland_WarpMouseGlobal(int x, int y)
+{
+ return SDL_Unsupported();
+}
+
+static int
+Wayland_SetRelativeMouseMode(SDL_bool enabled)
+{
+ SDL_VideoDevice *vd = SDL_GetVideoDevice();
+ SDL_VideoData *data = (SDL_VideoData *) vd->driverdata;
+
+ if (enabled)
+ return Wayland_input_lock_pointer(data->input);
+ else
+ return Wayland_input_unlock_pointer(data->input);
+}
+
+void
+Wayland_InitMouse(void)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ mouse->CreateCursor = Wayland_CreateCursor;
+ mouse->CreateSystemCursor = Wayland_CreateSystemCursor;
+ mouse->ShowCursor = Wayland_ShowCursor;
+ mouse->FreeCursor = Wayland_FreeCursor;
+ mouse->WarpMouse = Wayland_WarpMouse;
+ mouse->WarpMouseGlobal = Wayland_WarpMouseGlobal;
+ mouse->SetRelativeMouseMode = Wayland_SetRelativeMouseMode;
+
+ SDL_SetDefaultCursor(Wayland_CreateDefaultCursor());
+}
+
+void
+Wayland_FiniMouse(void)
+{
+ /* This effectively assumes that nobody else
+ * touches SDL_Mouse which is effectively
+ * a singleton */
+}
+#endif /* SDL_VIDEO_DRIVER_WAYLAND */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylandmouse.h b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandmouse.h
new file mode 100644
index 0000000..2c50e5f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandmouse.h
@@ -0,0 +1,31 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+#include "SDL_mouse.h"
+#include "SDL_waylandvideo.h"
+
+#if SDL_VIDEO_DRIVER_WAYLAND
+
+extern void Wayland_InitMouse(void);
+extern void Wayland_FiniMouse(void);
+
+#endif
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylandopengles.c b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandopengles.c
new file mode 100644
index 0000000..9c0b845
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandopengles.c
@@ -0,0 +1,93 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL
+
+#include "SDL_waylandvideo.h"
+#include "SDL_waylandopengles.h"
+#include "SDL_waylandwindow.h"
+#include "SDL_waylandevents_c.h"
+#include "SDL_waylanddyn.h"
+
+/* EGL implementation of SDL OpenGL ES support */
+
+int
+Wayland_GLES_LoadLibrary(_THIS, const char *path) {
+ int ret;
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
+ ret = SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) data->display, 0);
+
+ Wayland_PumpEvents(_this);
+ WAYLAND_wl_display_flush(data->display);
+
+ return ret;
+}
+
+
+SDL_GLContext
+Wayland_GLES_CreateContext(_THIS, SDL_Window * window)
+{
+ SDL_GLContext context;
+ context = SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
+ WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
+
+ return context;
+}
+
+int
+Wayland_GLES_SwapWindow(_THIS, SDL_Window *window)
+{
+ if (SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface) < 0) {
+ return -1;
+ }
+ WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
+ return 0;
+}
+
+int
+Wayland_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
+{
+ int ret;
+
+ if (window && context) {
+ ret = SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context);
+ }
+ else {
+ ret = SDL_EGL_MakeCurrent(_this, NULL, NULL);
+ }
+
+ WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
+
+ return ret;
+}
+
+void
+Wayland_GLES_DeleteContext(_THIS, SDL_GLContext context)
+{
+ SDL_EGL_DeleteContext(_this, context);
+ WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
+}
+
+#endif /* SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylandopengles.h b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandopengles.h
new file mode 100644
index 0000000..58d7f9b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandopengles.h
@@ -0,0 +1,49 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_waylandopengles_h_
+#define SDL_waylandopengles_h_
+
+#include "../SDL_sysvideo.h"
+#include "../SDL_egl_c.h"
+
+typedef struct SDL_PrivateGLESData
+{
+ int dummy;
+} SDL_PrivateGLESData;
+
+/* OpenGLES functions */
+#define Wayland_GLES_GetAttribute SDL_EGL_GetAttribute
+#define Wayland_GLES_GetProcAddress SDL_EGL_GetProcAddress
+#define Wayland_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
+#define Wayland_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
+#define Wayland_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
+
+extern int Wayland_GLES_LoadLibrary(_THIS, const char *path);
+extern SDL_GLContext Wayland_GLES_CreateContext(_THIS, SDL_Window * window);
+extern int Wayland_GLES_SwapWindow(_THIS, SDL_Window * window);
+extern int Wayland_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+extern void Wayland_GLES_DeleteContext(_THIS, SDL_GLContext context);
+
+#endif /* SDL_waylandopengles_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylandsym.h b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandsym.h
new file mode 100644
index 0000000..77783df
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandsym.h
@@ -0,0 +1,127 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/* *INDENT-OFF* */
+
+#ifndef SDL_WAYLAND_MODULE
+#define SDL_WAYLAND_MODULE(modname)
+#endif
+
+#ifndef SDL_WAYLAND_SYM
+#define SDL_WAYLAND_SYM(rc,fn,params)
+#endif
+
+#ifndef SDL_WAYLAND_INTERFACE
+#define SDL_WAYLAND_INTERFACE(iface)
+#endif
+
+SDL_WAYLAND_MODULE(WAYLAND_CLIENT)
+SDL_WAYLAND_SYM(void, wl_proxy_marshal, (struct wl_proxy *, uint32_t, ...))
+SDL_WAYLAND_SYM(struct wl_proxy *, wl_proxy_create, (struct wl_proxy *, const struct wl_interface *))
+SDL_WAYLAND_SYM(void, wl_proxy_destroy, (struct wl_proxy *))
+SDL_WAYLAND_SYM(int, wl_proxy_add_listener, (struct wl_proxy *, void (**)(void), void *))
+SDL_WAYLAND_SYM(void, wl_proxy_set_user_data, (struct wl_proxy *, void *))
+SDL_WAYLAND_SYM(void *, wl_proxy_get_user_data, (struct wl_proxy *))
+SDL_WAYLAND_SYM(uint32_t, wl_proxy_get_id, (struct wl_proxy *))
+SDL_WAYLAND_SYM(const char *, wl_proxy_get_class, (struct wl_proxy *))
+SDL_WAYLAND_SYM(void, wl_proxy_set_queue, (struct wl_proxy *, struct wl_event_queue *))
+SDL_WAYLAND_SYM(struct wl_display *, wl_display_connect, (const char *))
+SDL_WAYLAND_SYM(struct wl_display *, wl_display_connect_to_fd, (int))
+SDL_WAYLAND_SYM(void, wl_display_disconnect, (struct wl_display *))
+SDL_WAYLAND_SYM(int, wl_display_get_fd, (struct wl_display *))
+SDL_WAYLAND_SYM(int, wl_display_dispatch, (struct wl_display *))
+SDL_WAYLAND_SYM(int, wl_display_dispatch_queue, (struct wl_display *, struct wl_event_queue *))
+SDL_WAYLAND_SYM(int, wl_display_dispatch_queue_pending, (struct wl_display *, struct wl_event_queue *))
+SDL_WAYLAND_SYM(int, wl_display_dispatch_pending, (struct wl_display *))
+SDL_WAYLAND_SYM(int, wl_display_get_error, (struct wl_display *))
+SDL_WAYLAND_SYM(int, wl_display_flush, (struct wl_display *))
+SDL_WAYLAND_SYM(int, wl_display_roundtrip, (struct wl_display *))
+SDL_WAYLAND_SYM(struct wl_event_queue *, wl_display_create_queue, (struct wl_display *))
+SDL_WAYLAND_SYM(void, wl_log_set_handler_client, (wl_log_func_t))
+SDL_WAYLAND_SYM(void, wl_list_init, (struct wl_list *))
+SDL_WAYLAND_SYM(void, wl_list_insert, (struct wl_list *, struct wl_list *) )
+SDL_WAYLAND_SYM(void, wl_list_remove, (struct wl_list *))
+SDL_WAYLAND_SYM(int, wl_list_length, (const struct wl_list *))
+SDL_WAYLAND_SYM(int, wl_list_empty, (const struct wl_list *))
+SDL_WAYLAND_SYM(void, wl_list_insert_list, (struct wl_list *, struct wl_list *))
+
+/* These functions are available in Wayland >= 1.4 */
+SDL_WAYLAND_MODULE(WAYLAND_CLIENT_1_4)
+SDL_WAYLAND_SYM(struct wl_proxy *, wl_proxy_marshal_constructor, (struct wl_proxy *, uint32_t opcode, const struct wl_interface *interface, ...))
+
+SDL_WAYLAND_MODULE(WAYLAND_CLIENT_1_10)
+SDL_WAYLAND_SYM(struct wl_proxy *, wl_proxy_marshal_constructor_versioned, (struct wl_proxy *proxy, uint32_t opcode, const struct wl_interface *interface, uint32_t version, ...))
+
+SDL_WAYLAND_INTERFACE(wl_seat_interface)
+SDL_WAYLAND_INTERFACE(wl_surface_interface)
+SDL_WAYLAND_INTERFACE(wl_shm_pool_interface)
+SDL_WAYLAND_INTERFACE(wl_buffer_interface)
+SDL_WAYLAND_INTERFACE(wl_registry_interface)
+SDL_WAYLAND_INTERFACE(wl_shell_surface_interface)
+SDL_WAYLAND_INTERFACE(wl_region_interface)
+SDL_WAYLAND_INTERFACE(wl_pointer_interface)
+SDL_WAYLAND_INTERFACE(wl_keyboard_interface)
+SDL_WAYLAND_INTERFACE(wl_compositor_interface)
+SDL_WAYLAND_INTERFACE(wl_output_interface)
+SDL_WAYLAND_INTERFACE(wl_shell_interface)
+SDL_WAYLAND_INTERFACE(wl_shm_interface)
+SDL_WAYLAND_INTERFACE(wl_data_device_interface)
+SDL_WAYLAND_INTERFACE(wl_data_source_interface)
+SDL_WAYLAND_INTERFACE(wl_data_offer_interface)
+SDL_WAYLAND_INTERFACE(wl_data_device_manager_interface)
+
+SDL_WAYLAND_MODULE(WAYLAND_EGL)
+SDL_WAYLAND_SYM(struct wl_egl_window *, wl_egl_window_create, (struct wl_surface *, int, int))
+SDL_WAYLAND_SYM(void, wl_egl_window_destroy, (struct wl_egl_window *))
+SDL_WAYLAND_SYM(void, wl_egl_window_resize, (struct wl_egl_window *, int, int, int, int))
+SDL_WAYLAND_SYM(void, wl_egl_window_get_attached_size, (struct wl_egl_window *, int *, int *))
+
+SDL_WAYLAND_MODULE(WAYLAND_CURSOR)
+SDL_WAYLAND_SYM(struct wl_cursor_theme *, wl_cursor_theme_load, (const char *, int , struct wl_shm *))
+SDL_WAYLAND_SYM(void, wl_cursor_theme_destroy, (struct wl_cursor_theme *))
+SDL_WAYLAND_SYM(struct wl_cursor *, wl_cursor_theme_get_cursor, (struct wl_cursor_theme *, const char *))
+SDL_WAYLAND_SYM(struct wl_buffer *, wl_cursor_image_get_buffer, (struct wl_cursor_image *))
+SDL_WAYLAND_SYM(int, wl_cursor_frame, (struct wl_cursor *, uint32_t))
+
+SDL_WAYLAND_MODULE(WAYLAND_XKB)
+SDL_WAYLAND_SYM(int, xkb_state_key_get_syms, (struct xkb_state *, xkb_keycode_t, const xkb_keysym_t **))
+SDL_WAYLAND_SYM(int, xkb_keysym_to_utf8, (xkb_keysym_t, char *, size_t) )
+SDL_WAYLAND_SYM(struct xkb_keymap *, xkb_keymap_new_from_string, (struct xkb_context *, const char *, enum xkb_keymap_format, enum xkb_keymap_compile_flags))
+SDL_WAYLAND_SYM(struct xkb_state *, xkb_state_new, (struct xkb_keymap *) )
+SDL_WAYLAND_SYM(void, xkb_keymap_unref, (struct xkb_keymap *) )
+SDL_WAYLAND_SYM(void, xkb_state_unref, (struct xkb_state *) )
+SDL_WAYLAND_SYM(void, xkb_context_unref, (struct xkb_context *) )
+SDL_WAYLAND_SYM(struct xkb_context *, xkb_context_new, (enum xkb_context_flags flags) )
+SDL_WAYLAND_SYM(enum xkb_state_component, xkb_state_update_mask, (struct xkb_state *state,\
+ xkb_mod_mask_t depressed_mods,\
+ xkb_mod_mask_t latched_mods,\
+ xkb_mod_mask_t locked_mods,\
+ xkb_layout_index_t depressed_layout,\
+ xkb_layout_index_t latched_layout,\
+ xkb_layout_index_t locked_layout) )
+
+#undef SDL_WAYLAND_MODULE
+#undef SDL_WAYLAND_SYM
+#undef SDL_WAYLAND_INTERFACE
+
+/* *INDENT-ON* */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylandtouch.c b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandtouch.c
new file mode 100644
index 0000000..005b47f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandtouch.c
@@ -0,0 +1,265 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/* Contributed by Thomas Perl <thomas.perl@jollamobile.com> */
+
+#include "../../SDL_internal.h"
+
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
+
+#include "SDL_log.h"
+#include "SDL_waylandtouch.h"
+#include "../../events/SDL_touch_c.h"
+
+struct SDL_WaylandTouch {
+ struct qt_touch_extension *touch_extension;
+};
+
+
+/**
+ * Qt TouchPointState
+ * adapted from qtbase/src/corelib/global/qnamespace.h
+ **/
+enum QtWaylandTouchPointState {
+ QtWaylandTouchPointPressed = 0x01,
+ QtWaylandTouchPointMoved = 0x02,
+ /*
+ Never sent by the server:
+ QtWaylandTouchPointStationary = 0x04,
+ */
+ QtWaylandTouchPointReleased = 0x08,
+};
+
+static void
+touch_handle_touch(void *data,
+ struct qt_touch_extension *qt_touch_extension,
+ uint32_t time,
+ uint32_t id,
+ uint32_t state,
+ int32_t x,
+ int32_t y,
+ int32_t normalized_x,
+ int32_t normalized_y,
+ int32_t width,
+ int32_t height,
+ uint32_t pressure,
+ int32_t velocity_x,
+ int32_t velocity_y,
+ uint32_t flags,
+ struct wl_array *rawdata)
+{
+ /**
+ * Event is assembled in QtWayland in TouchExtensionGlobal::postTouchEvent
+ * (src/compositor/wayland_wrapper/qwltouch.cpp)
+ **/
+
+ float FIXED_TO_FLOAT = 1. / 10000.;
+ float xf = FIXED_TO_FLOAT * x;
+ float yf = FIXED_TO_FLOAT * y;
+
+ float PRESSURE_TO_FLOAT = 1. / 255.;
+ float pressuref = PRESSURE_TO_FLOAT * pressure;
+
+ uint32_t touchState = state & 0xFFFF;
+ /*
+ Other fields that are sent by the server (qwltouch.cpp),
+ but not used at the moment can be decoded in this way:
+
+ uint32_t sentPointCount = state >> 16;
+ uint32_t touchFlags = flags & 0xFFFF;
+ uint32_t capabilities = flags >> 16;
+ */
+
+ SDL_TouchID deviceId = 1;
+ if (SDL_AddTouch(deviceId, "qt_touch_extension") < 0) {
+ SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__);
+ }
+
+ switch (touchState) {
+ case QtWaylandTouchPointPressed:
+ case QtWaylandTouchPointReleased:
+ SDL_SendTouch(deviceId, (SDL_FingerID)id,
+ (touchState == QtWaylandTouchPointPressed) ? SDL_TRUE : SDL_FALSE,
+ xf, yf, pressuref);
+ break;
+ case QtWaylandTouchPointMoved:
+ SDL_SendTouchMotion(deviceId, (SDL_FingerID)id, xf, yf, pressuref);
+ break;
+ default:
+ /* Should not happen */
+ break;
+ }
+}
+
+static void
+touch_handle_configure(void *data,
+ struct qt_touch_extension *qt_touch_extension,
+ uint32_t flags)
+{
+}
+
+
+/* wayland-qt-touch-extension.c BEGINS */
+
+static const struct qt_touch_extension_listener touch_listener = {
+ touch_handle_touch,
+ touch_handle_configure,
+};
+
+static const struct wl_interface *qt_touch_extension_types[] = {
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+};
+
+static const struct wl_message qt_touch_extension_requests[] = {
+ { "dummy", "", qt_touch_extension_types + 0 },
+};
+
+static const struct wl_message qt_touch_extension_events[] = {
+ { "touch", "uuuiiiiiiuiiua", qt_touch_extension_types + 0 },
+ { "configure", "u", qt_touch_extension_types + 0 },
+};
+
+WL_EXPORT const struct wl_interface qt_touch_extension_interface = {
+ "qt_touch_extension", 1,
+ 1, qt_touch_extension_requests,
+ 2, qt_touch_extension_events,
+};
+
+/* wayland-qt-touch-extension.c ENDS */
+
+/* wayland-qt-windowmanager.c BEGINS */
+static const struct wl_interface *qt_windowmanager_types[] = {
+ NULL,
+ NULL,
+};
+
+static const struct wl_message qt_windowmanager_requests[] = {
+ { "open_url", "us", qt_windowmanager_types + 0 },
+};
+
+static const struct wl_message qt_windowmanager_events[] = {
+ { "hints", "i", qt_windowmanager_types + 0 },
+ { "quit", "", qt_windowmanager_types + 0 },
+};
+
+WL_EXPORT const struct wl_interface qt_windowmanager_interface = {
+ "qt_windowmanager", 1,
+ 1, qt_windowmanager_requests,
+ 2, qt_windowmanager_events,
+};
+/* wayland-qt-windowmanager.c ENDS */
+
+/* wayland-qt-surface-extension.c BEGINS */
+extern const struct wl_interface qt_extended_surface_interface;
+#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
+extern const struct wl_interface wl_surface_interface;
+#endif
+
+static const struct wl_interface *qt_surface_extension_types[] = {
+ NULL,
+ NULL,
+ &qt_extended_surface_interface,
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC
+ /* FIXME: Set this dynamically to (*WAYLAND_wl_surface_interface) ?
+ * The value comes from auto generated code and does
+ * not appear to actually be used anywhere
+ */
+ NULL,
+#else
+ &wl_surface_interface,
+#endif
+};
+
+static const struct wl_message qt_surface_extension_requests[] = {
+ { "get_extended_surface", "no", qt_surface_extension_types + 2 },
+};
+
+WL_EXPORT const struct wl_interface qt_surface_extension_interface = {
+ "qt_surface_extension", 1,
+ 1, qt_surface_extension_requests,
+ 0, NULL,
+};
+
+static const struct wl_message qt_extended_surface_requests[] = {
+ { "update_generic_property", "sa", qt_surface_extension_types + 0 },
+ { "set_content_orientation", "i", qt_surface_extension_types + 0 },
+ { "set_window_flags", "i", qt_surface_extension_types + 0 },
+};
+
+static const struct wl_message qt_extended_surface_events[] = {
+ { "onscreen_visibility", "i", qt_surface_extension_types + 0 },
+ { "set_generic_property", "sa", qt_surface_extension_types + 0 },
+ { "close", "", qt_surface_extension_types + 0 },
+};
+
+WL_EXPORT const struct wl_interface qt_extended_surface_interface = {
+ "qt_extended_surface", 1,
+ 3, qt_extended_surface_requests,
+ 3, qt_extended_surface_events,
+};
+
+/* wayland-qt-surface-extension.c ENDS */
+
+void
+Wayland_touch_create(SDL_VideoData *data, uint32_t id)
+{
+ struct SDL_WaylandTouch *touch;
+
+ if (data->touch) {
+ Wayland_touch_destroy(data);
+ }
+
+ /* !!! FIXME: check for failure, call SDL_OutOfMemory() */
+ data->touch = SDL_malloc(sizeof(struct SDL_WaylandTouch));
+
+ touch = data->touch;
+ touch->touch_extension = wl_registry_bind(data->registry, id, &qt_touch_extension_interface, 1);
+ qt_touch_extension_add_listener(touch->touch_extension, &touch_listener, data);
+}
+
+void
+Wayland_touch_destroy(SDL_VideoData *data)
+{
+ if (data->touch) {
+ struct SDL_WaylandTouch *touch = data->touch;
+ if (touch->touch_extension) {
+ qt_touch_extension_destroy(touch->touch_extension);
+ }
+
+ SDL_free(data->touch);
+ data->touch = NULL;
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylandtouch.h b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandtouch.h
new file mode 100644
index 0000000..9efc5a5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandtouch.h
@@ -0,0 +1,352 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
+
+#ifndef SDL_waylandtouch_h_
+#define SDL_waylandtouch_h_
+
+#include "SDL_waylandvideo.h"
+#include <stdint.h>
+#include <stddef.h>
+#include "wayland-util.h"
+#include "SDL_waylanddyn.h"
+
+
+void Wayland_touch_create(SDL_VideoData *data, uint32_t id);
+void Wayland_touch_destroy(SDL_VideoData *data);
+
+struct qt_touch_extension;
+
+/* Autogenerated QT headers */
+
+/*
+ Support for Wayland with QmlCompositor as Server
+================================================
+
+The Wayland video driver has support for some additional features when
+using QtWayland's "qmlcompositor" as Wayland server. This is needed for touch
+input when running SDL applications under a qmlcompositor Wayland server.
+
+The files following headers have been
+generated from the Wayland XML Protocol Definition in QtWayland as follows:
+
+Clone QtWayland from Git:
+ http://qt.gitorious.org/qt/qtwayland/
+
+Generate headers and glue code:
+ for extension in touch-extension surface-extension windowmanager; do
+ wayland-scanner client-header < src/extensions/$extension.xml > wayland-qt-$extension.h
+ wayland-scanner code < src/extensions/$extension.xml > wayland-qt-$extension.c
+ done
+
+*/
+
+/* wayland-qt-surface-extension.h */
+
+struct wl_client;
+struct wl_resource;
+
+struct qt_surface_extension;
+struct qt_extended_surface;
+
+extern const struct wl_interface qt_surface_extension_interface;
+extern const struct wl_interface qt_extended_surface_interface;
+
+#define QT_SURFACE_EXTENSION_GET_EXTENDED_SURFACE 0
+
+static inline void
+qt_surface_extension_set_user_data(struct qt_surface_extension *qt_surface_extension, void *user_data)
+{
+ wl_proxy_set_user_data((struct wl_proxy *) qt_surface_extension, user_data);
+}
+
+static inline void *
+qt_surface_extension_get_user_data(struct qt_surface_extension *qt_surface_extension)
+{
+ return wl_proxy_get_user_data((struct wl_proxy *) qt_surface_extension);
+}
+
+static inline void
+qt_surface_extension_destroy(struct qt_surface_extension *qt_surface_extension)
+{
+ WAYLAND_wl_proxy_destroy((struct wl_proxy *) qt_surface_extension);
+}
+
+static inline struct qt_extended_surface *
+qt_surface_extension_get_extended_surface(struct qt_surface_extension *qt_surface_extension, struct wl_surface *surface)
+{
+ struct wl_proxy *id;
+
+ id = wl_proxy_create((struct wl_proxy *) qt_surface_extension,
+ &qt_extended_surface_interface);
+ if (!id)
+ return NULL;
+
+ WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_surface_extension,
+ QT_SURFACE_EXTENSION_GET_EXTENDED_SURFACE, id, surface);
+
+ return (struct qt_extended_surface *) id;
+}
+
+#ifndef QT_EXTENDED_SURFACE_ORIENTATION_ENUM
+#define QT_EXTENDED_SURFACE_ORIENTATION_ENUM
+enum qt_extended_surface_orientation {
+ QT_EXTENDED_SURFACE_ORIENTATION_PRIMARYORIENTATION = 0,
+ QT_EXTENDED_SURFACE_ORIENTATION_PORTRAITORIENTATION = 1,
+ QT_EXTENDED_SURFACE_ORIENTATION_LANDSCAPEORIENTATION = 2,
+ QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDPORTRAITORIENTATION = 4,
+ QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDLANDSCAPEORIENTATION = 8,
+};
+#endif /* QT_EXTENDED_SURFACE_ORIENTATION_ENUM */
+
+#ifndef QT_EXTENDED_SURFACE_WINDOWFLAG_ENUM
+#define QT_EXTENDED_SURFACE_WINDOWFLAG_ENUM
+enum qt_extended_surface_windowflag {
+ QT_EXTENDED_SURFACE_WINDOWFLAG_OVERRIDESSYSTEMGESTURES = 1,
+ QT_EXTENDED_SURFACE_WINDOWFLAG_STAYSONTOP = 2,
+};
+#endif /* QT_EXTENDED_SURFACE_WINDOWFLAG_ENUM */
+
+struct qt_extended_surface_listener {
+ /**
+ * onscreen_visibility - (none)
+ * @visible: (none)
+ */
+ void (*onscreen_visibility)(void *data,
+ struct qt_extended_surface *qt_extended_surface,
+ int32_t visible);
+ /**
+ * set_generic_property - (none)
+ * @name: (none)
+ * @value: (none)
+ */
+ void (*set_generic_property)(void *data,
+ struct qt_extended_surface *qt_extended_surface,
+ const char *name,
+ struct wl_array *value);
+ /**
+ * close - (none)
+ */
+ void (*close)(void *data,
+ struct qt_extended_surface *qt_extended_surface);
+};
+
+static inline int
+qt_extended_surface_add_listener(struct qt_extended_surface *qt_extended_surface,
+ const struct qt_extended_surface_listener *listener, void *data)
+{
+ return wl_proxy_add_listener((struct wl_proxy *) qt_extended_surface,
+ (void (**)(void)) listener, data);
+}
+
+#define QT_EXTENDED_SURFACE_UPDATE_GENERIC_PROPERTY 0
+#define QT_EXTENDED_SURFACE_SET_CONTENT_ORIENTATION 1
+#define QT_EXTENDED_SURFACE_SET_WINDOW_FLAGS 2
+
+static inline void
+qt_extended_surface_set_user_data(struct qt_extended_surface *qt_extended_surface, void *user_data)
+{
+ WAYLAND_wl_proxy_set_user_data((struct wl_proxy *) qt_extended_surface, user_data);
+}
+
+static inline void *
+qt_extended_surface_get_user_data(struct qt_extended_surface *qt_extended_surface)
+{
+ return WAYLAND_wl_proxy_get_user_data((struct wl_proxy *) qt_extended_surface);
+}
+
+static inline void
+qt_extended_surface_destroy(struct qt_extended_surface *qt_extended_surface)
+{
+ WAYLAND_wl_proxy_destroy((struct wl_proxy *) qt_extended_surface);
+}
+
+static inline void
+qt_extended_surface_update_generic_property(struct qt_extended_surface *qt_extended_surface, const char *name, struct wl_array *value)
+{
+ WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_extended_surface,
+ QT_EXTENDED_SURFACE_UPDATE_GENERIC_PROPERTY, name, value);
+}
+
+static inline void
+qt_extended_surface_set_content_orientation(struct qt_extended_surface *qt_extended_surface, int32_t orientation)
+{
+ WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_extended_surface,
+ QT_EXTENDED_SURFACE_SET_CONTENT_ORIENTATION, orientation);
+}
+
+static inline void
+qt_extended_surface_set_window_flags(struct qt_extended_surface *qt_extended_surface, int32_t flags)
+{
+ WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_extended_surface,
+ QT_EXTENDED_SURFACE_SET_WINDOW_FLAGS, flags);
+}
+
+/* wayland-qt-touch-extension.h */
+
+extern const struct wl_interface qt_touch_extension_interface;
+
+#ifndef QT_TOUCH_EXTENSION_FLAGS_ENUM
+#define QT_TOUCH_EXTENSION_FLAGS_ENUM
+enum qt_touch_extension_flags {
+ QT_TOUCH_EXTENSION_FLAGS_MOUSE_FROM_TOUCH = 0x1,
+};
+#endif /* QT_TOUCH_EXTENSION_FLAGS_ENUM */
+
+struct qt_touch_extension_listener {
+ /**
+ * touch - (none)
+ * @time: (none)
+ * @id: (none)
+ * @state: (none)
+ * @x: (none)
+ * @y: (none)
+ * @normalized_x: (none)
+ * @normalized_y: (none)
+ * @width: (none)
+ * @height: (none)
+ * @pressure: (none)
+ * @velocity_x: (none)
+ * @velocity_y: (none)
+ * @flags: (none)
+ * @rawdata: (none)
+ */
+ void (*touch)(void *data,
+ struct qt_touch_extension *qt_touch_extension,
+ uint32_t time,
+ uint32_t id,
+ uint32_t state,
+ int32_t x,
+ int32_t y,
+ int32_t normalized_x,
+ int32_t normalized_y,
+ int32_t width,
+ int32_t height,
+ uint32_t pressure,
+ int32_t velocity_x,
+ int32_t velocity_y,
+ uint32_t flags,
+ struct wl_array *rawdata);
+ /**
+ * configure - (none)
+ * @flags: (none)
+ */
+ void (*configure)(void *data,
+ struct qt_touch_extension *qt_touch_extension,
+ uint32_t flags);
+};
+
+static inline int
+qt_touch_extension_add_listener(struct qt_touch_extension *qt_touch_extension,
+ const struct qt_touch_extension_listener *listener, void *data)
+{
+ return wl_proxy_add_listener((struct wl_proxy *) qt_touch_extension,
+ (void (**)(void)) listener, data);
+}
+
+#define QT_TOUCH_EXTENSION_DUMMY 0
+
+static inline void
+qt_touch_extension_set_user_data(struct qt_touch_extension *qt_touch_extension, void *user_data)
+{
+ WAYLAND_wl_proxy_set_user_data((struct wl_proxy *) qt_touch_extension, user_data);
+}
+
+static inline void *
+qt_touch_extension_get_user_data(struct qt_touch_extension *qt_touch_extension)
+{
+ return WAYLAND_wl_proxy_get_user_data((struct wl_proxy *) qt_touch_extension);
+}
+
+static inline void
+qt_touch_extension_destroy(struct qt_touch_extension *qt_touch_extension)
+{
+ WAYLAND_wl_proxy_destroy((struct wl_proxy *) qt_touch_extension);
+}
+
+static inline void
+qt_touch_extension_dummy(struct qt_touch_extension *qt_touch_extension)
+{
+ WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_touch_extension,
+ QT_TOUCH_EXTENSION_DUMMY);
+}
+
+
+/* wayland-qt-windowmanager.h */
+
+extern const struct wl_interface qt_windowmanager_interface;
+
+struct qt_windowmanager_listener {
+ /**
+ * hints - (none)
+ * @show_is_fullscreen: (none)
+ */
+ void (*hints)(void *data,
+ struct qt_windowmanager *qt_windowmanager,
+ int32_t show_is_fullscreen);
+ /**
+ * quit - (none)
+ */
+ void (*quit)(void *data,
+ struct qt_windowmanager *qt_windowmanager);
+};
+
+static inline int
+qt_windowmanager_add_listener(struct qt_windowmanager *qt_windowmanager,
+ const struct qt_windowmanager_listener *listener, void *data)
+{
+ return wl_proxy_add_listener((struct wl_proxy *) qt_windowmanager,
+ (void (**)(void)) listener, data);
+}
+
+#define QT_WINDOWMANAGER_OPEN_URL 0
+
+static inline void
+qt_windowmanager_set_user_data(struct qt_windowmanager *qt_windowmanager, void *user_data)
+{
+ WAYLAND_wl_proxy_set_user_data((struct wl_proxy *) qt_windowmanager, user_data);
+}
+
+static inline void *
+qt_windowmanager_get_user_data(struct qt_windowmanager *qt_windowmanager)
+{
+ return WAYLAND_wl_proxy_get_user_data((struct wl_proxy *) qt_windowmanager);
+}
+
+static inline void
+qt_windowmanager_destroy(struct qt_windowmanager *qt_windowmanager)
+{
+ WAYLAND_wl_proxy_destroy((struct wl_proxy *) qt_windowmanager);
+}
+
+static inline void
+qt_windowmanager_open_url(struct qt_windowmanager *qt_windowmanager, uint32_t remaining, const char *url)
+{
+ WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_windowmanager,
+ QT_WINDOWMANAGER_OPEN_URL, remaining, url);
+}
+
+#endif /* SDL_waylandtouch_h_ */
+
+#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylandvideo.c b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandvideo.c
new file mode 100644
index 0000000..8401a08
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandvideo.c
@@ -0,0 +1,499 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WAYLAND
+
+#include "SDL_video.h"
+#include "SDL_mouse.h"
+#include "SDL_stdinc.h"
+#include "../../events/SDL_events_c.h"
+
+#include "SDL_waylandvideo.h"
+#include "SDL_waylandevents_c.h"
+#include "SDL_waylandwindow.h"
+#include "SDL_waylandopengles.h"
+#include "SDL_waylandmouse.h"
+#include "SDL_waylandtouch.h"
+#include "SDL_waylandclipboard.h"
+#include "SDL_waylandvulkan.h"
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <xkbcommon/xkbcommon.h>
+
+#include "SDL_waylanddyn.h"
+#include <wayland-util.h>
+
+#include "xdg-shell-unstable-v6-client-protocol.h"
+
+#define WAYLANDVID_DRIVER_NAME "wayland"
+
+/* Initialization/Query functions */
+static int
+Wayland_VideoInit(_THIS);
+
+static void
+Wayland_GetDisplayModes(_THIS, SDL_VideoDisplay *sdl_display);
+static int
+Wayland_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
+
+static void
+Wayland_VideoQuit(_THIS);
+
+/* Find out what class name we should use
+ * Based on src/video/x11/SDL_x11video.c */
+static char *
+get_classname()
+{
+/* !!! FIXME: this is probably wrong, albeit harmless in many common cases. From protocol spec:
+ "The surface class identifies the general class of applications
+ to which the surface belongs. A common convention is to use the
+ file name (or the full path if it is a non-standard location) of
+ the application's .desktop file as the class." */
+
+ char *spot;
+#if defined(__LINUX__) || defined(__FREEBSD__)
+ char procfile[1024];
+ char linkfile[1024];
+ int linksize;
+#endif
+
+ /* First allow environment variable override */
+ spot = SDL_getenv("SDL_VIDEO_WAYLAND_WMCLASS");
+ if (spot) {
+ return SDL_strdup(spot);
+ } else {
+ /* Fallback to the "old" envvar */
+ spot = SDL_getenv("SDL_VIDEO_X11_WMCLASS");
+ if (spot) {
+ return SDL_strdup(spot);
+ }
+ }
+
+ /* Next look at the application's executable name */
+#if defined(__LINUX__) || defined(__FREEBSD__)
+#if defined(__LINUX__)
+ SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid());
+#elif defined(__FREEBSD__)
+ SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file",
+ getpid());
+#else
+#error Where can we find the executable name?
+#endif
+ linksize = readlink(procfile, linkfile, sizeof(linkfile) - 1);
+ if (linksize > 0) {
+ linkfile[linksize] = '\0';
+ spot = SDL_strrchr(linkfile, '/');
+ if (spot) {
+ return SDL_strdup(spot + 1);
+ } else {
+ return SDL_strdup(linkfile);
+ }
+ }
+#endif /* __LINUX__ || __FREEBSD__ */
+
+ /* Finally use the default we've used forever */
+ return SDL_strdup("SDL_App");
+}
+
+/* Wayland driver bootstrap functions */
+static int
+Wayland_Available(void)
+{
+ struct wl_display *display = NULL;
+ if (SDL_WAYLAND_LoadSymbols()) {
+ display = WAYLAND_wl_display_connect(NULL);
+ if (display != NULL) {
+ WAYLAND_wl_display_disconnect(display);
+ }
+ SDL_WAYLAND_UnloadSymbols();
+ }
+
+ return (display != NULL);
+}
+
+static void
+Wayland_DeleteDevice(SDL_VideoDevice *device)
+{
+ SDL_free(device);
+ SDL_WAYLAND_UnloadSymbols();
+}
+
+static SDL_VideoDevice *
+Wayland_CreateDevice(int devindex)
+{
+ SDL_VideoDevice *device;
+
+ if (!SDL_WAYLAND_LoadSymbols()) {
+ return NULL;
+ }
+
+ /* Initialize all variables that we clean on shutdown */
+ device = SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (!device) {
+ SDL_WAYLAND_UnloadSymbols();
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ /* Set the function pointers */
+ device->VideoInit = Wayland_VideoInit;
+ device->VideoQuit = Wayland_VideoQuit;
+ device->SetDisplayMode = Wayland_SetDisplayMode;
+ device->GetDisplayModes = Wayland_GetDisplayModes;
+ device->GetWindowWMInfo = Wayland_GetWindowWMInfo;
+
+ device->PumpEvents = Wayland_PumpEvents;
+
+ device->GL_SwapWindow = Wayland_GLES_SwapWindow;
+ device->GL_GetSwapInterval = Wayland_GLES_GetSwapInterval;
+ device->GL_SetSwapInterval = Wayland_GLES_SetSwapInterval;
+ device->GL_MakeCurrent = Wayland_GLES_MakeCurrent;
+ device->GL_CreateContext = Wayland_GLES_CreateContext;
+ device->GL_LoadLibrary = Wayland_GLES_LoadLibrary;
+ device->GL_UnloadLibrary = Wayland_GLES_UnloadLibrary;
+ device->GL_GetProcAddress = Wayland_GLES_GetProcAddress;
+ device->GL_DeleteContext = Wayland_GLES_DeleteContext;
+
+ device->CreateSDLWindow = Wayland_CreateWindow;
+ device->ShowWindow = Wayland_ShowWindow;
+ device->SetWindowFullscreen = Wayland_SetWindowFullscreen;
+ device->MaximizeWindow = Wayland_MaximizeWindow;
+ device->RestoreWindow = Wayland_RestoreWindow;
+ device->SetWindowSize = Wayland_SetWindowSize;
+ device->SetWindowTitle = Wayland_SetWindowTitle;
+ device->DestroyWindow = Wayland_DestroyWindow;
+ device->SetWindowHitTest = Wayland_SetWindowHitTest;
+
+ device->SetClipboardText = Wayland_SetClipboardText;
+ device->GetClipboardText = Wayland_GetClipboardText;
+ device->HasClipboardText = Wayland_HasClipboardText;
+
+#if SDL_VIDEO_VULKAN
+ device->Vulkan_LoadLibrary = Wayland_Vulkan_LoadLibrary;
+ device->Vulkan_UnloadLibrary = Wayland_Vulkan_UnloadLibrary;
+ device->Vulkan_GetInstanceExtensions = Wayland_Vulkan_GetInstanceExtensions;
+ device->Vulkan_CreateSurface = Wayland_Vulkan_CreateSurface;
+#endif
+
+ device->free = Wayland_DeleteDevice;
+
+ return device;
+}
+
+VideoBootStrap Wayland_bootstrap = {
+ WAYLANDVID_DRIVER_NAME, "SDL Wayland video driver",
+ Wayland_Available, Wayland_CreateDevice
+};
+
+static void
+display_handle_geometry(void *data,
+ struct wl_output *output,
+ int x, int y,
+ int physical_width,
+ int physical_height,
+ int subpixel,
+ const char *make,
+ const char *model,
+ int transform)
+
+{
+ SDL_VideoDisplay *display = data;
+
+ display->name = SDL_strdup(model);
+ display->driverdata = output;
+}
+
+static void
+display_handle_mode(void *data,
+ struct wl_output *output,
+ uint32_t flags,
+ int width,
+ int height,
+ int refresh)
+{
+ SDL_VideoDisplay *display = data;
+ SDL_DisplayMode mode;
+
+ SDL_zero(mode);
+ mode.format = SDL_PIXELFORMAT_RGB888;
+ mode.w = width;
+ mode.h = height;
+ mode.refresh_rate = refresh / 1000; // mHz to Hz
+ mode.driverdata = display->driverdata;
+ SDL_AddDisplayMode(display, &mode);
+
+ if (flags & WL_OUTPUT_MODE_CURRENT) {
+ display->current_mode = mode;
+ display->desktop_mode = mode;
+ }
+}
+
+static void
+display_handle_done(void *data,
+ struct wl_output *output)
+{
+ SDL_VideoDisplay *display = data;
+ SDL_AddVideoDisplay(display);
+ SDL_free(display->name);
+ SDL_free(display);
+}
+
+static void
+display_handle_scale(void *data,
+ struct wl_output *output,
+ int32_t factor)
+{
+ // TODO: do HiDPI stuff.
+}
+
+static const struct wl_output_listener output_listener = {
+ display_handle_geometry,
+ display_handle_mode,
+ display_handle_done,
+ display_handle_scale
+};
+
+static void
+Wayland_add_display(SDL_VideoData *d, uint32_t id)
+{
+ struct wl_output *output;
+ SDL_VideoDisplay *display = SDL_malloc(sizeof *display);
+ if (!display) {
+ SDL_OutOfMemory();
+ return;
+ }
+ SDL_zero(*display);
+
+ output = wl_registry_bind(d->registry, id, &wl_output_interface, 2);
+ if (!output) {
+ SDL_SetError("Failed to retrieve output.");
+ SDL_free(display);
+ return;
+ }
+
+ wl_output_add_listener(output, &output_listener, display);
+}
+
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
+static void
+windowmanager_hints(void *data, struct qt_windowmanager *qt_windowmanager,
+ int32_t show_is_fullscreen)
+{
+}
+
+static void
+windowmanager_quit(void *data, struct qt_windowmanager *qt_windowmanager)
+{
+ SDL_SendQuit();
+}
+
+static const struct qt_windowmanager_listener windowmanager_listener = {
+ windowmanager_hints,
+ windowmanager_quit,
+};
+#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
+
+
+static void
+handle_ping_zxdg_shell(void *data, struct zxdg_shell_v6 *zxdg, uint32_t serial)
+{
+ zxdg_shell_v6_pong(zxdg, serial);
+}
+
+static const struct zxdg_shell_v6_listener shell_listener_zxdg = {
+ handle_ping_zxdg_shell
+};
+
+
+static void
+display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
+ const char *interface, uint32_t version)
+{
+ SDL_VideoData *d = data;
+
+ if (strcmp(interface, "wl_compositor") == 0) {
+ d->compositor = wl_registry_bind(d->registry, id, &wl_compositor_interface, 1);
+ } else if (strcmp(interface, "wl_output") == 0) {
+ Wayland_add_display(d, id);
+ } else if (strcmp(interface, "wl_seat") == 0) {
+ Wayland_display_add_input(d, id);
+ } else if (strcmp(interface, "zxdg_shell_v6") == 0) {
+ d->shell.zxdg = wl_registry_bind(d->registry, id, &zxdg_shell_v6_interface, 1);
+ zxdg_shell_v6_add_listener(d->shell.zxdg, &shell_listener_zxdg, NULL);
+ } else if (strcmp(interface, "wl_shell") == 0) {
+ d->shell.wl = wl_registry_bind(d->registry, id, &wl_shell_interface, 1);
+ } else if (strcmp(interface, "wl_shm") == 0) {
+ d->shm = wl_registry_bind(registry, id, &wl_shm_interface, 1);
+ d->cursor_theme = WAYLAND_wl_cursor_theme_load(NULL, 32, d->shm);
+ } else if (strcmp(interface, "zwp_relative_pointer_manager_v1") == 0) {
+ Wayland_display_add_relative_pointer_manager(d, id);
+ } else if (strcmp(interface, "zwp_pointer_constraints_v1") == 0) {
+ Wayland_display_add_pointer_constraints(d, id);
+ } else if (strcmp(interface, "wl_data_device_manager") == 0) {
+ d->data_device_manager = wl_registry_bind(d->registry, id, &wl_data_device_manager_interface, 3);
+
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
+ } else if (strcmp(interface, "qt_touch_extension") == 0) {
+ Wayland_touch_create(d, id);
+ } else if (strcmp(interface, "qt_surface_extension") == 0) {
+ d->surface_extension = wl_registry_bind(registry, id,
+ &qt_surface_extension_interface, 1);
+ } else if (strcmp(interface, "qt_windowmanager") == 0) {
+ d->windowmanager = wl_registry_bind(registry, id,
+ &qt_windowmanager_interface, 1);
+ qt_windowmanager_add_listener(d->windowmanager, &windowmanager_listener, d);
+#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
+ }
+}
+
+static const struct wl_registry_listener registry_listener = {
+ display_handle_global,
+ NULL, /* global_remove */
+};
+
+int
+Wayland_VideoInit(_THIS)
+{
+ SDL_VideoData *data = SDL_malloc(sizeof *data);
+ if (data == NULL)
+ return SDL_OutOfMemory();
+ memset(data, 0, sizeof *data);
+
+ _this->driverdata = data;
+
+ data->xkb_context = WAYLAND_xkb_context_new(0);
+ if (!data->xkb_context) {
+ return SDL_SetError("Failed to create XKB context");
+ }
+
+ data->display = WAYLAND_wl_display_connect(NULL);
+ if (data->display == NULL) {
+ return SDL_SetError("Failed to connect to a Wayland display");
+ }
+
+ data->registry = wl_display_get_registry(data->display);
+ if (data->registry == NULL) {
+ return SDL_SetError("Failed to get the Wayland registry");
+ }
+
+ wl_registry_add_listener(data->registry, &registry_listener, data);
+
+ // First roundtrip to receive all registry objects.
+ WAYLAND_wl_display_roundtrip(data->display);
+
+ // Second roundtrip to receive all output events.
+ WAYLAND_wl_display_roundtrip(data->display);
+
+ Wayland_InitMouse();
+
+ /* Get the surface class name, usually the name of the application */
+ data->classname = get_classname();
+
+ WAYLAND_wl_display_flush(data->display);
+
+ return 0;
+}
+
+static void
+Wayland_GetDisplayModes(_THIS, SDL_VideoDisplay *sdl_display)
+{
+ // Nothing to do here, everything was already done in the wl_output
+ // callbacks.
+}
+
+static int
+Wayland_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
+{
+ return SDL_Unsupported();
+}
+
+void
+Wayland_VideoQuit(_THIS)
+{
+ SDL_VideoData *data = _this->driverdata;
+ int i, j;
+
+ Wayland_FiniMouse ();
+
+ for (i = 0; i < _this->num_displays; ++i) {
+ SDL_VideoDisplay *display = &_this->displays[i];
+ wl_output_destroy(display->driverdata);
+ display->driverdata = NULL;
+
+ for (j = display->num_display_modes; j--;) {
+ display->display_modes[j].driverdata = NULL;
+ }
+ display->desktop_mode.driverdata = NULL;
+ }
+
+ Wayland_display_destroy_input(data);
+ Wayland_display_destroy_pointer_constraints(data);
+ Wayland_display_destroy_relative_pointer_manager(data);
+
+ if (data->xkb_context) {
+ WAYLAND_xkb_context_unref(data->xkb_context);
+ data->xkb_context = NULL;
+ }
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
+ if (data->windowmanager)
+ qt_windowmanager_destroy(data->windowmanager);
+
+ if (data->surface_extension)
+ qt_surface_extension_destroy(data->surface_extension);
+
+ Wayland_touch_destroy(data);
+#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
+
+ if (data->shm)
+ wl_shm_destroy(data->shm);
+
+ if (data->cursor_theme)
+ WAYLAND_wl_cursor_theme_destroy(data->cursor_theme);
+
+ if (data->shell.wl)
+ wl_shell_destroy(data->shell.wl);
+
+ if (data->shell.zxdg)
+ zxdg_shell_v6_destroy(data->shell.zxdg);
+
+ if (data->compositor)
+ wl_compositor_destroy(data->compositor);
+
+ if (data->registry)
+ wl_registry_destroy(data->registry);
+
+ if (data->display) {
+ WAYLAND_wl_display_flush(data->display);
+ WAYLAND_wl_display_disconnect(data->display);
+ }
+
+ SDL_free(data->classname);
+ SDL_free(data);
+ _this->driverdata = NULL;
+}
+
+#endif /* SDL_VIDEO_DRIVER_WAYLAND */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylandvideo.h b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandvideo.h
new file mode 100644
index 0000000..6ad68de
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandvideo.h
@@ -0,0 +1,75 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_waylandvideo_h_
+#define SDL_waylandvideo_h_
+
+#include <EGL/egl.h>
+#include "wayland-util.h"
+
+struct xkb_context;
+struct SDL_WaylandInput;
+
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
+struct SDL_WaylandTouch;
+struct qt_surface_extension;
+struct qt_windowmanager;
+#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
+
+typedef struct {
+ struct wl_display *display;
+ struct wl_registry *registry;
+ struct wl_compositor *compositor;
+ struct wl_shm *shm;
+ struct wl_cursor_theme *cursor_theme;
+ struct wl_pointer *pointer;
+ struct {
+ /* !!! FIXME: add stable xdg_shell from 1.12 */
+ struct zxdg_shell_v6 *zxdg;
+ struct wl_shell *wl;
+ } shell;
+ struct zwp_relative_pointer_manager_v1 *relative_pointer_manager;
+ struct zwp_pointer_constraints_v1 *pointer_constraints;
+ struct wl_data_device_manager *data_device_manager;
+
+ EGLDisplay edpy;
+ EGLContext context;
+ EGLConfig econf;
+
+ struct xkb_context *xkb_context;
+ struct SDL_WaylandInput *input;
+
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
+ struct SDL_WaylandTouch *touch;
+ struct qt_surface_extension *surface_extension;
+ struct qt_windowmanager *windowmanager;
+#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
+
+ char *classname;
+
+ int relative_mouse_mode;
+} SDL_VideoData;
+
+#endif /* SDL_waylandvideo_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylandvulkan.c b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandvulkan.c
new file mode 100644
index 0000000..d67472c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandvulkan.c
@@ -0,0 +1,176 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ * @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's
+ * SDL_x11vulkan.c.
+ */
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_WAYLAND
+
+#include "SDL_waylandvideo.h"
+#include "SDL_waylandwindow.h"
+#include "SDL_assert.h"
+
+#include "SDL_loadso.h"
+#include "SDL_waylandvulkan.h"
+#include "SDL_syswm.h"
+
+int Wayland_Vulkan_LoadLibrary(_THIS, const char *path)
+{
+ VkExtensionProperties *extensions = NULL;
+ Uint32 i, extensionCount = 0;
+ SDL_bool hasSurfaceExtension = SDL_FALSE;
+ SDL_bool hasWaylandSurfaceExtension = SDL_FALSE;
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
+ if(_this->vulkan_config.loader_handle)
+ return SDL_SetError("Vulkan already loaded");
+
+ /* Load the Vulkan loader library */
+ if(!path)
+ path = SDL_getenv("SDL_VULKAN_LIBRARY");
+ if(!path)
+ path = "libvulkan.so.1";
+ _this->vulkan_config.loader_handle = SDL_LoadObject(path);
+ if(!_this->vulkan_config.loader_handle)
+ return -1;
+ SDL_strlcpy(_this->vulkan_config.loader_path, path,
+ SDL_arraysize(_this->vulkan_config.loader_path));
+ vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction(
+ _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr");
+ if(!vkGetInstanceProcAddr)
+ goto fail;
+ _this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr;
+ _this->vulkan_config.vkEnumerateInstanceExtensionProperties =
+ (void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)(
+ VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties");
+ if(!_this->vulkan_config.vkEnumerateInstanceExtensionProperties)
+ goto fail;
+ extensions = SDL_Vulkan_CreateInstanceExtensionsList(
+ (PFN_vkEnumerateInstanceExtensionProperties)
+ _this->vulkan_config.vkEnumerateInstanceExtensionProperties,
+ &extensionCount);
+ if(!extensions)
+ goto fail;
+ for(i = 0; i < extensionCount; i++)
+ {
+ if(SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
+ hasSurfaceExtension = SDL_TRUE;
+ else if(SDL_strcmp(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
+ hasWaylandSurfaceExtension = SDL_TRUE;
+ }
+ SDL_free(extensions);
+ if(!hasSurfaceExtension)
+ {
+ SDL_SetError("Installed Vulkan doesn't implement the "
+ VK_KHR_SURFACE_EXTENSION_NAME " extension");
+ goto fail;
+ }
+ else if(!hasWaylandSurfaceExtension)
+ {
+ SDL_SetError("Installed Vulkan doesn't implement the "
+ VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME "extension");
+ goto fail;
+ }
+ return 0;
+
+fail:
+ SDL_UnloadObject(_this->vulkan_config.loader_handle);
+ _this->vulkan_config.loader_handle = NULL;
+ return -1;
+}
+
+void Wayland_Vulkan_UnloadLibrary(_THIS)
+{
+ if(_this->vulkan_config.loader_handle)
+ {
+ SDL_UnloadObject(_this->vulkan_config.loader_handle);
+ _this->vulkan_config.loader_handle = NULL;
+ }
+}
+
+SDL_bool Wayland_Vulkan_GetInstanceExtensions(_THIS,
+ SDL_Window *window,
+ unsigned *count,
+ const char **names)
+{
+ static const char *const extensionsForWayland[] = {
+ VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
+ };
+ if(!_this->vulkan_config.loader_handle)
+ {
+ SDL_SetError("Vulkan is not loaded");
+ return SDL_FALSE;
+ }
+ return SDL_Vulkan_GetInstanceExtensions_Helper(
+ count, names, SDL_arraysize(extensionsForWayland),
+ extensionsForWayland);
+}
+
+SDL_bool Wayland_Vulkan_CreateSurface(_THIS,
+ SDL_Window *window,
+ VkInstance instance,
+ VkSurfaceKHR *surface)
+{
+ SDL_WindowData *windowData = (SDL_WindowData *)window->driverdata;
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
+ (PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr;
+ PFN_vkCreateWaylandSurfaceKHR vkCreateWaylandSurfaceKHR =
+ (PFN_vkCreateWaylandSurfaceKHR)vkGetInstanceProcAddr(
+ (VkInstance)instance,
+ "vkCreateWaylandSurfaceKHR");
+ VkWaylandSurfaceCreateInfoKHR createInfo;
+ VkResult result;
+
+ if(!_this->vulkan_config.loader_handle)
+ {
+ SDL_SetError("Vulkan is not loaded");
+ return SDL_FALSE;
+ }
+
+ if(!vkCreateWaylandSurfaceKHR)
+ {
+ SDL_SetError(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
+ " extension is not enabled in the Vulkan instance.");
+ return SDL_FALSE;
+ }
+ SDL_zero(createInfo);
+ createInfo.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
+ createInfo.pNext = NULL;
+ createInfo.flags = 0;
+ createInfo.display = windowData->waylandData->display;
+ createInfo.surface = windowData->surface;
+ result = vkCreateWaylandSurfaceKHR(instance, &createInfo,
+ NULL, surface);
+ if(result != VK_SUCCESS)
+ {
+ SDL_SetError("vkCreateWaylandSurfaceKHR failed: %s",
+ SDL_Vulkan_GetResultString(result));
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
+}
+
+#endif
+
+/* vim: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylandvulkan.h b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandvulkan.h
new file mode 100644
index 0000000..5ad3a46
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandvulkan.h
@@ -0,0 +1,52 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ * @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's
+ * SDL_x11vulkan.h.
+ */
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_waylandvulkan_h_
+#define SDL_waylandvulkan_h_
+
+#include "../SDL_vulkan_internal.h"
+#include "../SDL_sysvideo.h"
+
+#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_WAYLAND
+
+int Wayland_Vulkan_LoadLibrary(_THIS, const char *path);
+void Wayland_Vulkan_UnloadLibrary(_THIS);
+SDL_bool Wayland_Vulkan_GetInstanceExtensions(_THIS,
+ SDL_Window *window,
+ unsigned *count,
+ const char **names);
+SDL_bool Wayland_Vulkan_CreateSurface(_THIS,
+ SDL_Window *window,
+ VkInstance instance,
+ VkSurfaceKHR *surface);
+
+#endif
+
+#endif /* SDL_waylandvulkan_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylandwindow.c b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandwindow.c
new file mode 100644
index 0000000..684022a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandwindow.c
@@ -0,0 +1,552 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL
+
+#include "../SDL_sysvideo.h"
+#include "../../events/SDL_windowevents_c.h"
+#include "../SDL_egl_c.h"
+#include "SDL_waylandevents_c.h"
+#include "SDL_waylandwindow.h"
+#include "SDL_waylandvideo.h"
+#include "SDL_waylandtouch.h"
+#include "SDL_waylanddyn.h"
+#include "SDL_hints.h"
+
+#include "xdg-shell-unstable-v6-client-protocol.h"
+
+/* On modern desktops, we probably will use the xdg-shell protocol instead
+ of wl_shell, but wl_shell might be useful on older Wayland installs that
+ don't have the newer protocol, or embedded things that don't have a full
+ window manager. */
+
+static void
+handle_ping_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface,
+ uint32_t serial)
+{
+ wl_shell_surface_pong(shell_surface, serial);
+}
+
+static void
+handle_configure_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface,
+ uint32_t edges, int32_t width, int32_t height)
+{
+ SDL_WindowData *wind = (SDL_WindowData *)data;
+ SDL_Window *window = wind->sdlwindow;
+ struct wl_region *region;
+
+ /* wl_shell_surface spec states that this is a suggestion.
+ Ignore if less than or greater than max/min size. */
+
+ if (width == 0 || height == 0) {
+ return;
+ }
+
+ if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+ if ((window->flags & SDL_WINDOW_RESIZABLE)) {
+ if (window->max_w > 0) {
+ width = SDL_min(width, window->max_w);
+ }
+ width = SDL_max(width, window->min_w);
+
+ if (window->max_h > 0) {
+ height = SDL_min(height, window->max_h);
+ }
+ height = SDL_max(height, window->min_h);
+ } else {
+ return;
+ }
+ }
+
+ if (width == window->w && height == window->h) {
+ return;
+ }
+
+ window->w = width;
+ window->h = height;
+ WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
+
+ region = wl_compositor_create_region(wind->waylandData->compositor);
+ wl_region_add(region, 0, 0, window->w, window->h);
+ wl_surface_set_opaque_region(wind->surface, region);
+ wl_region_destroy(region);
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, window->w, window->h);
+}
+
+static void
+handle_popup_done_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface)
+{
+}
+
+static const struct wl_shell_surface_listener shell_surface_listener_wl = {
+ handle_ping_wl_shell_surface,
+ handle_configure_wl_shell_surface,
+ handle_popup_done_wl_shell_surface
+};
+
+
+
+
+static void
+handle_configure_zxdg_shell_surface(void *data, struct zxdg_surface_v6 *zxdg, uint32_t serial)
+{
+ SDL_WindowData *wind = (SDL_WindowData *)data;
+ SDL_Window *window = wind->sdlwindow;
+ struct wl_region *region;
+ WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
+
+ region = wl_compositor_create_region(wind->waylandData->compositor);
+ wl_region_add(region, 0, 0, window->w, window->h);
+ wl_surface_set_opaque_region(wind->surface, region);
+ wl_region_destroy(region);
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, window->w, window->h);
+ zxdg_surface_v6_ack_configure(zxdg, serial);
+}
+
+static const struct zxdg_surface_v6_listener shell_surface_listener_zxdg = {
+ handle_configure_zxdg_shell_surface
+};
+
+
+static void
+handle_configure_zxdg_toplevel(void *data,
+ struct zxdg_toplevel_v6 *zxdg_toplevel_v6,
+ int32_t width,
+ int32_t height,
+ struct wl_array *states)
+{
+ SDL_WindowData *wind = (SDL_WindowData *)data;
+ SDL_Window *window = wind->sdlwindow;
+
+ /* wl_shell_surface spec states that this is a suggestion.
+ Ignore if less than or greater than max/min size. */
+
+ if (width == 0 || height == 0) {
+ return;
+ }
+
+ if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+ if ((window->flags & SDL_WINDOW_RESIZABLE)) {
+ if (window->max_w > 0) {
+ width = SDL_min(width, window->max_w);
+ }
+ width = SDL_max(width, window->min_w);
+
+ if (window->max_h > 0) {
+ height = SDL_min(height, window->max_h);
+ }
+ height = SDL_max(height, window->min_h);
+ } else {
+ return;
+ }
+ }
+
+ if (width == window->w && height == window->h) {
+ return;
+ }
+
+ window->w = width;
+ window->h = height;
+}
+
+static void
+handle_close_zxdg_toplevel(void *data, struct zxdg_toplevel_v6 *zxdg_toplevel_v6)
+{
+ SDL_WindowData *window = (SDL_WindowData *)data;
+ SDL_SendWindowEvent(window->sdlwindow, SDL_WINDOWEVENT_CLOSE, 0, 0);
+}
+
+static const struct zxdg_toplevel_v6_listener toplevel_listener_zxdg = {
+ handle_configure_zxdg_toplevel,
+ handle_close_zxdg_toplevel
+};
+
+
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
+static void
+handle_onscreen_visibility(void *data,
+ struct qt_extended_surface *qt_extended_surface, int32_t visible)
+{
+}
+
+static void
+handle_set_generic_property(void *data,
+ struct qt_extended_surface *qt_extended_surface, const char *name,
+ struct wl_array *value)
+{
+}
+
+static void
+handle_close(void *data, struct qt_extended_surface *qt_extended_surface)
+{
+ SDL_WindowData *window = (SDL_WindowData *)data;
+ SDL_SendWindowEvent(window->sdlwindow, SDL_WINDOWEVENT_CLOSE, 0, 0);
+}
+
+static const struct qt_extended_surface_listener extended_surface_listener = {
+ handle_onscreen_visibility,
+ handle_set_generic_property,
+ handle_close,
+};
+#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
+
+SDL_bool
+Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ const Uint32 version = ((((Uint32) info->version.major) * 1000000) +
+ (((Uint32) info->version.minor) * 10000) +
+ (((Uint32) info->version.patch)));
+
+ /* Before 2.0.6, it was possible to build an SDL with Wayland support
+ (SDL_SysWMinfo will be large enough to hold Wayland info), but build
+ your app against SDL headers that didn't have Wayland support
+ (SDL_SysWMinfo could be smaller than Wayland needs. This would lead
+ to an app properly using SDL_GetWindowWMInfo() but we'd accidentally
+ overflow memory on the stack or heap. To protect against this, we've
+ padded out the struct unconditionally in the headers and Wayland will
+ just return an error for older apps using this function. Those apps
+ will need to be recompiled against newer headers or not use Wayland,
+ maybe by forcing SDL_VIDEODRIVER=x11. */
+ if (version < 2000006) {
+ info->subsystem = SDL_SYSWM_UNKNOWN;
+ SDL_SetError("Version must be 2.0.6 or newer");
+ return SDL_FALSE;
+ }
+
+ info->info.wl.display = data->waylandData->display;
+ info->info.wl.surface = data->surface;
+ info->info.wl.shell_surface = data->shell_surface.wl;
+ info->subsystem = SDL_SYSWM_WAYLAND;
+
+ return SDL_TRUE;
+}
+
+int
+Wayland_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
+{
+ return 0; /* just succeed, the real work is done elsewhere. */
+}
+
+static void
+SetFullscreen(_THIS, SDL_Window * window, struct wl_output *output)
+{
+ const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
+ SDL_WindowData *wind = window->driverdata;
+
+ if (viddata->shell.zxdg) {
+ if (output) {
+ zxdg_toplevel_v6_set_fullscreen(wind->shell_surface.zxdg.roleobj.toplevel, output);
+ } else {
+ zxdg_toplevel_v6_unset_fullscreen(wind->shell_surface.zxdg.roleobj.toplevel);
+ }
+ } else {
+ if (output) {
+ wl_shell_surface_set_fullscreen(wind->shell_surface.wl,
+ WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
+ 0, output);
+ } else {
+ wl_shell_surface_set_toplevel(wind->shell_surface.wl);
+ }
+ }
+
+ WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
+}
+
+void Wayland_ShowWindow(_THIS, SDL_Window *window)
+{
+ struct wl_output *output = (struct wl_output *) window->fullscreen_mode.driverdata;
+ SetFullscreen(_this, window, (window->flags & SDL_WINDOW_FULLSCREEN) ? output : NULL);
+}
+
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
+static void SDLCALL
+QtExtendedSurface_OnHintChanged(void *userdata, const char *name,
+ const char *oldValue, const char *newValue)
+{
+ struct qt_extended_surface *qt_extended_surface = userdata;
+
+ if (name == NULL) {
+ return;
+ }
+
+ if (strcmp(name, SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION) == 0) {
+ int32_t orientation = QT_EXTENDED_SURFACE_ORIENTATION_PRIMARYORIENTATION;
+
+ if (newValue != NULL) {
+ if (strcmp(newValue, "portrait") == 0) {
+ orientation = QT_EXTENDED_SURFACE_ORIENTATION_PORTRAITORIENTATION;
+ } else if (strcmp(newValue, "landscape") == 0) {
+ orientation = QT_EXTENDED_SURFACE_ORIENTATION_LANDSCAPEORIENTATION;
+ } else if (strcmp(newValue, "inverted-portrait") == 0) {
+ orientation = QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDPORTRAITORIENTATION;
+ } else if (strcmp(newValue, "inverted-landscape") == 0) {
+ orientation = QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDLANDSCAPEORIENTATION;
+ }
+ }
+
+ qt_extended_surface_set_content_orientation(qt_extended_surface, orientation);
+ } else if (strcmp(name, SDL_HINT_QTWAYLAND_WINDOW_FLAGS) == 0) {
+ uint32_t flags = 0;
+
+ if (newValue != NULL) {
+ char *tmp = strdup(newValue);
+ char *saveptr = NULL;
+
+ char *flag = strtok_r(tmp, " ", &saveptr);
+ while (flag) {
+ if (strcmp(flag, "OverridesSystemGestures") == 0) {
+ flags |= QT_EXTENDED_SURFACE_WINDOWFLAG_OVERRIDESSYSTEMGESTURES;
+ } else if (strcmp(flag, "StaysOnTop") == 0) {
+ flags |= QT_EXTENDED_SURFACE_WINDOWFLAG_STAYSONTOP;
+ } else if (strcmp(flag, "BypassWindowManager") == 0) {
+ // See https://github.com/qtproject/qtwayland/commit/fb4267103d
+ flags |= 4 /* QT_EXTENDED_SURFACE_WINDOWFLAG_BYPASSWINDOWMANAGER */;
+ }
+
+ flag = strtok_r(NULL, " ", &saveptr);
+ }
+
+ free(tmp);
+ }
+
+ qt_extended_surface_set_window_flags(qt_extended_surface, flags);
+ }
+}
+
+static void QtExtendedSurface_Subscribe(struct qt_extended_surface *surface, const char *name)
+{
+ SDL_AddHintCallback(name, QtExtendedSurface_OnHintChanged, surface);
+}
+
+static void QtExtendedSurface_Unsubscribe(struct qt_extended_surface *surface, const char *name)
+{
+ SDL_DelHintCallback(name, QtExtendedSurface_OnHintChanged, surface);
+}
+#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
+
+void
+Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
+ SDL_VideoDisplay * _display, SDL_bool fullscreen)
+{
+ struct wl_output *output = (struct wl_output *) _display->driverdata;
+ SetFullscreen(_this, window, fullscreen ? output : NULL);
+}
+
+void
+Wayland_RestoreWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *wind = window->driverdata;
+ const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata;
+
+ if (viddata->shell.zxdg) {
+ } else {
+ wl_shell_surface_set_toplevel(wind->shell_surface.wl);
+ }
+
+ WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
+}
+
+void
+Wayland_MaximizeWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *wind = window->driverdata;
+ SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
+
+ if (viddata->shell.zxdg) {
+ zxdg_toplevel_v6_set_maximized(wind->shell_surface.zxdg.roleobj.toplevel);
+ } else {
+ wl_shell_surface_set_maximized(wind->shell_surface.wl, NULL);
+ }
+
+ WAYLAND_wl_display_flush( viddata->display );
+}
+
+int Wayland_CreateWindow(_THIS, SDL_Window *window)
+{
+ SDL_WindowData *data;
+ SDL_VideoData *c;
+ struct wl_region *region;
+
+ data = calloc(1, sizeof *data);
+ if (data == NULL)
+ return SDL_OutOfMemory();
+
+ c = _this->driverdata;
+ window->driverdata = data;
+
+ if (!(window->flags & SDL_WINDOW_OPENGL)) {
+ SDL_GL_LoadLibrary(NULL);
+ window->flags |= SDL_WINDOW_OPENGL;
+ }
+
+ if (window->x == SDL_WINDOWPOS_UNDEFINED) {
+ window->x = 0;
+ }
+ if (window->y == SDL_WINDOWPOS_UNDEFINED) {
+ window->y = 0;
+ }
+
+ data->waylandData = c;
+ data->sdlwindow = window;
+
+ data->surface =
+ wl_compositor_create_surface(c->compositor);
+ wl_surface_set_user_data(data->surface, data);
+
+ if (c->shell.zxdg) {
+ data->shell_surface.zxdg.surface = zxdg_shell_v6_get_xdg_surface(c->shell.zxdg, data->surface);
+ /* !!! FIXME: add popup role */
+ data->shell_surface.zxdg.roleobj.toplevel = zxdg_surface_v6_get_toplevel(data->shell_surface.zxdg.surface);
+ zxdg_toplevel_v6_add_listener(data->shell_surface.zxdg.roleobj.toplevel, &toplevel_listener_zxdg, data);
+ zxdg_toplevel_v6_set_app_id(data->shell_surface.zxdg.roleobj.toplevel, c->classname);
+ } else {
+ data->shell_surface.wl = wl_shell_get_shell_surface(c->shell.wl, data->surface);
+ wl_shell_surface_set_class(data->shell_surface.wl, c->classname);
+ }
+
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
+ if (c->surface_extension) {
+ data->extended_surface = qt_surface_extension_get_extended_surface(
+ c->surface_extension, data->surface);
+
+ QtExtendedSurface_Subscribe(data->extended_surface, SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION);
+ QtExtendedSurface_Subscribe(data->extended_surface, SDL_HINT_QTWAYLAND_WINDOW_FLAGS);
+ }
+#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
+
+ data->egl_window = WAYLAND_wl_egl_window_create(data->surface,
+ window->w, window->h);
+
+ /* Create the GLES window surface */
+ data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->egl_window);
+
+ if (data->egl_surface == EGL_NO_SURFACE) {
+ return SDL_SetError("failed to create a window surface");
+ }
+
+ if (c->shell.zxdg) {
+ if (data->shell_surface.zxdg.surface) {
+ zxdg_surface_v6_set_user_data(data->shell_surface.zxdg.surface, data);
+ zxdg_surface_v6_add_listener(data->shell_surface.zxdg.surface, &shell_surface_listener_zxdg, data);
+ }
+ } else {
+ if (data->shell_surface.wl) {
+ wl_shell_surface_set_user_data(data->shell_surface.wl, data);
+ wl_shell_surface_add_listener(data->shell_surface.wl, &shell_surface_listener_wl, data);
+ }
+ }
+
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
+ if (data->extended_surface) {
+ qt_extended_surface_set_user_data(data->extended_surface, data);
+ qt_extended_surface_add_listener(data->extended_surface,
+ &extended_surface_listener, data);
+ }
+#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
+
+ region = wl_compositor_create_region(c->compositor);
+ wl_region_add(region, 0, 0, window->w, window->h);
+ wl_surface_set_opaque_region(data->surface, region);
+ wl_region_destroy(region);
+
+ if (c->relative_mouse_mode) {
+ Wayland_input_lock_pointer(c->input);
+ }
+
+ wl_surface_commit(data->surface);
+ WAYLAND_wl_display_flush(c->display);
+
+ return 0;
+}
+
+void Wayland_SetWindowSize(_THIS, SDL_Window * window)
+{
+ SDL_VideoData *data = _this->driverdata;
+ SDL_WindowData *wind = window->driverdata;
+ struct wl_region *region;
+
+ WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
+
+ region =wl_compositor_create_region(data->compositor);
+ wl_region_add(region, 0, 0, window->w, window->h);
+ wl_surface_set_opaque_region(wind->surface, region);
+ wl_region_destroy(region);
+}
+
+void Wayland_SetWindowTitle(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *wind = window->driverdata;
+ SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
+
+ if (window->title != NULL) {
+ if (viddata->shell.zxdg) {
+ zxdg_toplevel_v6_set_title(wind->shell_surface.zxdg.roleobj.toplevel, window->title);
+ } else {
+ wl_shell_surface_set_title(wind->shell_surface.wl, window->title);
+ }
+ }
+
+ WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
+}
+
+void Wayland_DestroyWindow(_THIS, SDL_Window *window)
+{
+ SDL_VideoData *data = _this->driverdata;
+ SDL_WindowData *wind = window->driverdata;
+
+ if (data) {
+ SDL_EGL_DestroySurface(_this, wind->egl_surface);
+ WAYLAND_wl_egl_window_destroy(wind->egl_window);
+
+ if (data->shell.zxdg) {
+ if (wind->shell_surface.zxdg.roleobj.toplevel) {
+ zxdg_toplevel_v6_destroy(wind->shell_surface.zxdg.roleobj.toplevel);
+ }
+ if (wind->shell_surface.zxdg.surface) {
+ zxdg_surface_v6_destroy(wind->shell_surface.zxdg.surface);
+ }
+ } else {
+ if (wind->shell_surface.wl) {
+ wl_shell_surface_destroy(wind->shell_surface.wl);
+ }
+ }
+
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
+ if (wind->extended_surface) {
+ QtExtendedSurface_Unsubscribe(wind->extended_surface, SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION);
+ QtExtendedSurface_Unsubscribe(wind->extended_surface, SDL_HINT_QTWAYLAND_WINDOW_FLAGS);
+ qt_extended_surface_destroy(wind->extended_surface);
+ }
+#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
+ wl_surface_destroy(wind->surface);
+
+ SDL_free(wind);
+ WAYLAND_wl_display_flush(data->display);
+ }
+ window->driverdata = NULL;
+}
+
+#endif /* SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/wayland/SDL_waylandwindow.h b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandwindow.h
new file mode 100644
index 0000000..80d4f31
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/wayland/SDL_waylandwindow.h
@@ -0,0 +1,78 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_waylandwindow_h_
+#define SDL_waylandwindow_h_
+
+#include "../SDL_sysvideo.h"
+#include "SDL_syswm.h"
+
+#include "SDL_waylandvideo.h"
+
+struct SDL_WaylandInput;
+
+typedef struct {
+ struct zxdg_surface_v6 *surface;
+ union {
+ struct zxdg_toplevel_v6 *toplevel;
+ struct zxdg_popup_v6 *popup;
+ } roleobj;
+} SDL_zxdg_shell_surface;
+
+typedef struct {
+ SDL_Window *sdlwindow;
+ SDL_VideoData *waylandData;
+ struct wl_surface *surface;
+ union {
+ /* !!! FIXME: add stable xdg_shell from 1.12 */
+ SDL_zxdg_shell_surface zxdg;
+ struct wl_shell_surface *wl;
+ } shell_surface;
+ struct wl_egl_window *egl_window;
+ struct SDL_WaylandInput *keyboard_device;
+ EGLSurface egl_surface;
+ struct zwp_locked_pointer_v1 *locked_pointer;
+
+#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
+ struct qt_extended_surface *extended_surface;
+#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
+} SDL_WindowData;
+
+extern void Wayland_ShowWindow(_THIS, SDL_Window *window);
+extern void Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
+ SDL_VideoDisplay * _display,
+ SDL_bool fullscreen);
+extern void Wayland_MaximizeWindow(_THIS, SDL_Window * window);
+extern void Wayland_RestoreWindow(_THIS, SDL_Window * window);
+extern int Wayland_CreateWindow(_THIS, SDL_Window *window);
+extern void Wayland_SetWindowSize(_THIS, SDL_Window * window);
+extern void Wayland_SetWindowTitle(_THIS, SDL_Window * window);
+extern void Wayland_DestroyWindow(_THIS, SDL_Window *window);
+
+extern SDL_bool
+Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
+extern int Wayland_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
+
+#endif /* SDL_waylandwindow_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_msctf.h b/src/3rdparty/SDL2/src/video/windows/SDL_msctf.h
new file mode 100644
index 0000000..53cec3d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_msctf.h
@@ -0,0 +1,242 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SDL_msctf_h_
+#define SDL_msctf_h_
+
+#include <unknwn.h>
+
+#define TF_INVALID_COOKIE (0xffffffff)
+#define TF_IPSINK_FLAG_ACTIVE 0x0001
+#define TF_TMAE_UIELEMENTENABLEDONLY 0x00000004
+
+typedef struct ITfThreadMgr ITfThreadMgr;
+typedef struct ITfDocumentMgr ITfDocumentMgr;
+typedef struct ITfClientId ITfClientId;
+
+typedef struct IEnumTfDocumentMgrs IEnumTfDocumentMgrs;
+typedef struct IEnumTfFunctionProviders IEnumTfFunctionProviders;
+typedef struct ITfFunctionProvider ITfFunctionProvider;
+typedef struct ITfCompartmentMgr ITfCompartmentMgr;
+typedef struct ITfContext ITfContext;
+typedef struct IEnumTfContexts IEnumTfContexts;
+typedef struct ITfUIElementSink ITfUIElementSink;
+typedef struct ITfUIElement ITfUIElement;
+typedef struct ITfUIElementMgr ITfUIElementMgr;
+typedef struct IEnumTfUIElements IEnumTfUIElements;
+typedef struct ITfThreadMgrEx ITfThreadMgrEx;
+typedef struct ITfCandidateListUIElement ITfCandidateListUIElement;
+typedef struct ITfReadingInformationUIElement ITfReadingInformationUIElement;
+typedef struct ITfInputProcessorProfileActivationSink ITfInputProcessorProfileActivationSink;
+typedef struct ITfSource ITfSource;
+
+typedef DWORD TfClientId;
+typedef DWORD TfEditCookie;
+
+typedef struct ITfThreadMgrVtbl
+{
+ HRESULT (STDMETHODCALLTYPE *QueryInterface)(ITfThreadMgr *, REFIID, void **);
+ ULONG (STDMETHODCALLTYPE *AddRef)(ITfThreadMgr *);
+ ULONG (STDMETHODCALLTYPE *Release)(ITfThreadMgr *);
+ HRESULT (STDMETHODCALLTYPE *Activate)(ITfThreadMgr *, TfClientId *);
+ HRESULT (STDMETHODCALLTYPE *Deactivate)(ITfThreadMgr *);
+ HRESULT (STDMETHODCALLTYPE *CreateDocumentMgr)(ITfThreadMgr *);
+ HRESULT (STDMETHODCALLTYPE *EnumDocumentMgrs)(ITfThreadMgr *, IEnumTfDocumentMgrs **);
+ HRESULT (STDMETHODCALLTYPE *GetFocus)(ITfThreadMgr *, ITfDocumentMgr **);
+ HRESULT (STDMETHODCALLTYPE *SetFocus)(ITfThreadMgr *, ITfDocumentMgr *);
+ HRESULT (STDMETHODCALLTYPE *AssociateFocus)(ITfThreadMgr *, HWND, ITfDocumentMgr *, ITfDocumentMgr **);
+ HRESULT (STDMETHODCALLTYPE *IsThreadFocus)(ITfThreadMgr *, BOOL *);
+ HRESULT (STDMETHODCALLTYPE *GetFunctionProvider)(ITfThreadMgr *, REFCLSID, ITfFunctionProvider **);
+ HRESULT (STDMETHODCALLTYPE *EnumFunctionProviders)(ITfThreadMgr *, IEnumTfFunctionProviders **);
+ HRESULT (STDMETHODCALLTYPE *GetGlobalCompartment)(ITfThreadMgr *, ITfCompartmentMgr **);
+} ITfThreadMgrVtbl;
+
+struct ITfThreadMgr
+{
+ const struct ITfThreadMgrVtbl *lpVtbl;
+};
+
+typedef struct ITfThreadMgrExVtbl
+{
+ HRESULT (STDMETHODCALLTYPE *QueryInterface)(ITfThreadMgrEx *, REFIID, void **);
+ ULONG (STDMETHODCALLTYPE *AddRef)(ITfThreadMgrEx *);
+ ULONG (STDMETHODCALLTYPE *Release)(ITfThreadMgrEx *);
+ HRESULT (STDMETHODCALLTYPE *Activate)(ITfThreadMgrEx *, TfClientId *);
+ HRESULT (STDMETHODCALLTYPE *Deactivate)(ITfThreadMgrEx *);
+ HRESULT (STDMETHODCALLTYPE *CreateDocumentMgr)(ITfThreadMgrEx *, ITfDocumentMgr **);
+ HRESULT (STDMETHODCALLTYPE *EnumDocumentMgrs)(ITfThreadMgrEx *, IEnumTfDocumentMgrs **);
+ HRESULT (STDMETHODCALLTYPE *GetFocus)(ITfThreadMgrEx *, ITfDocumentMgr **);
+ HRESULT (STDMETHODCALLTYPE *SetFocus)(ITfThreadMgrEx *, ITfDocumentMgr *);
+ HRESULT (STDMETHODCALLTYPE *AssociateFocus)(ITfThreadMgrEx *, ITfDocumentMgr *, ITfDocumentMgr **);
+ HRESULT (STDMETHODCALLTYPE *IsThreadFocus)(ITfThreadMgrEx *, BOOL *);
+ HRESULT (STDMETHODCALLTYPE *GetFunctionProvider)(ITfThreadMgrEx *, REFCLSID, ITfFunctionProvider **);
+ HRESULT (STDMETHODCALLTYPE *EnumFunctionProviders)(ITfThreadMgrEx *, IEnumTfFunctionProviders **);
+ HRESULT (STDMETHODCALLTYPE *GetGlobalCompartment)(ITfThreadMgrEx *, ITfCompartmentMgr **);
+ HRESULT (STDMETHODCALLTYPE *ActivateEx)(ITfThreadMgrEx *, TfClientId *, DWORD);
+ HRESULT (STDMETHODCALLTYPE *GetActiveFlags)(ITfThreadMgrEx *, DWORD *);
+} ITfThreadMgrExVtbl;
+
+struct ITfThreadMgrEx
+{
+ const struct ITfThreadMgrExVtbl *lpVtbl;
+};
+
+typedef struct ITfDocumentMgrVtbl
+{
+ HRESULT (STDMETHODCALLTYPE *QueryInterface)(ITfDocumentMgr *, REFIID, void **);
+ ULONG (STDMETHODCALLTYPE *AddRef)(ITfDocumentMgr *);
+ ULONG (STDMETHODCALLTYPE *Release)(ITfDocumentMgr *);
+ HRESULT (STDMETHODCALLTYPE *CreateContext)(ITfDocumentMgr *, TfClientId, DWORD, IUnknown *, ITfContext **, TfEditCookie *);
+ HRESULT (STDMETHODCALLTYPE *Push)(ITfDocumentMgr *, ITfContext *);
+ HRESULT (STDMETHODCALLTYPE *Pop)(ITfDocumentMgr *);
+ HRESULT (STDMETHODCALLTYPE *GetTop)(ITfDocumentMgr *, ITfContext **);
+ HRESULT (STDMETHODCALLTYPE *GetBase)(ITfDocumentMgr *, ITfContext **);
+ HRESULT (STDMETHODCALLTYPE *EnumContexts)(ITfDocumentMgr *, IEnumTfContexts **);
+} ITfDocumentMgrVtbl;
+
+struct ITfDocumentMgr
+{
+ const struct ITfDocumentMgrVtbl *lpVtbl;
+};
+
+typedef struct ITfUIElementSinkVtbl
+{
+ HRESULT (STDMETHODCALLTYPE *QueryInterface)(ITfUIElementSink *, REFIID, void **);
+ ULONG (STDMETHODCALLTYPE *AddRef)(ITfUIElementSink *);
+ ULONG (STDMETHODCALLTYPE *Release)(ITfUIElementSink *);
+ HRESULT (STDMETHODCALLTYPE *BeginUIElement)(ITfUIElementSink *, DWORD, BOOL *);
+ HRESULT (STDMETHODCALLTYPE *UpdateUIElement)(ITfUIElementSink *, DWORD);
+ HRESULT (STDMETHODCALLTYPE *EndUIElement)(ITfUIElementSink *, DWORD);
+} ITfUIElementSinkVtbl;
+
+struct ITfUIElementSink
+{
+ const struct ITfUIElementSinkVtbl *lpVtbl;
+};
+
+typedef struct ITfUIElementMgrVtbl
+{
+ HRESULT (STDMETHODCALLTYPE *QueryInterface)(ITfUIElementMgr *, REFIID, void **);
+ ULONG (STDMETHODCALLTYPE *AddRef)(ITfUIElementMgr *);
+ ULONG (STDMETHODCALLTYPE *Release)(ITfUIElementMgr *);
+ HRESULT (STDMETHODCALLTYPE *BeginUIElement)(ITfUIElementMgr *, ITfUIElement *, BOOL *, DWORD *);
+ HRESULT (STDMETHODCALLTYPE *UpdateUIElement)(ITfUIElementMgr *, DWORD);
+ HRESULT (STDMETHODCALLTYPE *EndUIElement)(ITfUIElementMgr *, DWORD);
+ HRESULT (STDMETHODCALLTYPE *GetUIElement)(ITfUIElementMgr *, DWORD, ITfUIElement **);
+ HRESULT (STDMETHODCALLTYPE *EnumUIElements)(ITfUIElementMgr *, IEnumTfUIElements **);
+} ITfUIElementMgrVtbl;
+
+struct ITfUIElementMgr
+{
+ const struct ITfUIElementMgrVtbl *lpVtbl;
+};
+
+typedef struct ITfCandidateListUIElementVtbl
+{
+ HRESULT (STDMETHODCALLTYPE *QueryInterface)(ITfCandidateListUIElement *, REFIID, void **);
+ ULONG (STDMETHODCALLTYPE *AddRef)(ITfCandidateListUIElement *);
+ ULONG (STDMETHODCALLTYPE *Release)(ITfCandidateListUIElement *);
+ HRESULT (STDMETHODCALLTYPE *GetDescription)(ITfCandidateListUIElement *, BSTR *);
+ HRESULT (STDMETHODCALLTYPE *GetGUID)(ITfCandidateListUIElement *, GUID *);
+ HRESULT (STDMETHODCALLTYPE *Show)(ITfCandidateListUIElement *, BOOL);
+ HRESULT (STDMETHODCALLTYPE *IsShown)(ITfCandidateListUIElement *, BOOL *);
+ HRESULT (STDMETHODCALLTYPE *GetUpdatedFlags)(ITfCandidateListUIElement *, DWORD *);
+ HRESULT (STDMETHODCALLTYPE *GetDocumentMgr)(ITfCandidateListUIElement *, ITfDocumentMgr **);
+ HRESULT (STDMETHODCALLTYPE *GetCount)(ITfCandidateListUIElement *, UINT *);
+ HRESULT (STDMETHODCALLTYPE *GetSelection)(ITfCandidateListUIElement *, UINT *);
+ HRESULT (STDMETHODCALLTYPE *GetString)(ITfCandidateListUIElement *, UINT, BSTR *);
+ HRESULT (STDMETHODCALLTYPE *GetPageIndex)(ITfCandidateListUIElement *, UINT *, UINT, UINT *);
+ HRESULT (STDMETHODCALLTYPE *SetPageIndex)(ITfCandidateListUIElement *, UINT *, UINT);
+ HRESULT (STDMETHODCALLTYPE *GetCurrentPage)(ITfCandidateListUIElement *, UINT *);
+} ITfCandidateListUIElementVtbl;
+
+struct ITfCandidateListUIElement
+{
+ const struct ITfCandidateListUIElementVtbl *lpVtbl;
+};
+
+typedef struct ITfReadingInformationUIElementVtbl
+{
+ HRESULT (STDMETHODCALLTYPE *QueryInterface)(ITfReadingInformationUIElement *, REFIID, void **);
+ ULONG (STDMETHODCALLTYPE *AddRef)(ITfReadingInformationUIElement *);
+ ULONG (STDMETHODCALLTYPE *Release)(ITfReadingInformationUIElement *);
+ HRESULT (STDMETHODCALLTYPE *GetDescription)(ITfReadingInformationUIElement *, BSTR *);
+ HRESULT (STDMETHODCALLTYPE *GetGUID)(ITfReadingInformationUIElement *, GUID *);
+ HRESULT (STDMETHODCALLTYPE *Show)(ITfReadingInformationUIElement *, BOOL);
+ HRESULT (STDMETHODCALLTYPE *IsShown)(ITfReadingInformationUIElement *, BOOL *);
+ HRESULT (STDMETHODCALLTYPE *GetUpdatedFlags)(ITfReadingInformationUIElement *, DWORD *);
+ HRESULT (STDMETHODCALLTYPE *GetContext)(ITfReadingInformationUIElement *, ITfContext **);
+ HRESULT (STDMETHODCALLTYPE *GetString)(ITfReadingInformationUIElement *, BSTR *);
+ HRESULT (STDMETHODCALLTYPE *GetMaxReadingStringLength)(ITfReadingInformationUIElement *, UINT *);
+ HRESULT (STDMETHODCALLTYPE *GetErrorIndex)(ITfReadingInformationUIElement *, UINT *);
+ HRESULT (STDMETHODCALLTYPE *IsVerticalOrderPreferred)(ITfReadingInformationUIElement *, BOOL *);
+} ITfReadingInformationUIElementVtbl;
+
+struct ITfReadingInformationUIElement
+{
+ const struct ITfReadingInformationUIElementVtbl *lpVtbl;
+};
+
+typedef struct ITfUIElementVtbl
+{
+ HRESULT (STDMETHODCALLTYPE *QueryInterface)(ITfUIElement *, REFIID, void **);
+ ULONG (STDMETHODCALLTYPE *AddRef)(ITfUIElement *);
+ ULONG (STDMETHODCALLTYPE *Release)(ITfUIElement *);
+ HRESULT (STDMETHODCALLTYPE *GetDescription)(ITfUIElement *, BSTR *);
+ HRESULT (STDMETHODCALLTYPE *GetGUID)(ITfUIElement *, GUID *);
+ HRESULT (STDMETHODCALLTYPE *Show)(ITfUIElement *, BOOL);
+ HRESULT (STDMETHODCALLTYPE *IsShown)(ITfUIElement *, BOOL *);
+} ITfUIElementVtbl;
+
+struct ITfUIElement
+{
+ const struct ITfUIElementVtbl *lpVtbl;
+};
+
+typedef struct ITfInputProcessorProfileActivationSinkVtbl
+{
+ HRESULT (STDMETHODCALLTYPE *QueryInterface)(ITfInputProcessorProfileActivationSink *, REFIID, void **);
+ ULONG (STDMETHODCALLTYPE *AddRef)(ITfInputProcessorProfileActivationSink *);
+ ULONG (STDMETHODCALLTYPE *Release)(ITfInputProcessorProfileActivationSink *);
+ HRESULT (STDMETHODCALLTYPE *OnActivated)(ITfInputProcessorProfileActivationSink *, DWORD, LANGID, REFCLSID, REFGUID, REFGUID, HKL, DWORD);
+
+} ITfInputProcessorProfileActivationSinkVtbl;
+
+struct ITfInputProcessorProfileActivationSink
+{
+ const struct ITfInputProcessorProfileActivationSinkVtbl *lpVtbl;
+};
+
+typedef struct ITfSourceVtbl
+{
+ HRESULT (STDMETHODCALLTYPE *QueryInterface)(ITfSource *, REFIID, void **);
+ ULONG (STDMETHODCALLTYPE *AddRef)(ITfSource *);
+ ULONG (STDMETHODCALLTYPE *Release)(ITfSource *);
+ HRESULT (STDMETHODCALLTYPE *AdviseSink)(ITfSource *, REFIID, IUnknown *, DWORD *);
+ HRESULT (STDMETHODCALLTYPE *UnadviseSink)(ITfSource *, DWORD);
+} ITfSourceVtbl;
+
+struct ITfSource
+{
+ const struct ITfSourceVtbl *lpVtbl;
+};
+
+#endif /* SDL_msctf_h_ */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_vkeys.h b/src/3rdparty/SDL2/src/video/windows/SDL_vkeys.h
new file mode 100644
index 0000000..a38e3a2
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_vkeys.h
@@ -0,0 +1,76 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef VK_0
+#define VK_0 '0'
+#define VK_1 '1'
+#define VK_2 '2'
+#define VK_3 '3'
+#define VK_4 '4'
+#define VK_5 '5'
+#define VK_6 '6'
+#define VK_7 '7'
+#define VK_8 '8'
+#define VK_9 '9'
+#define VK_A 'A'
+#define VK_B 'B'
+#define VK_C 'C'
+#define VK_D 'D'
+#define VK_E 'E'
+#define VK_F 'F'
+#define VK_G 'G'
+#define VK_H 'H'
+#define VK_I 'I'
+#define VK_J 'J'
+#define VK_K 'K'
+#define VK_L 'L'
+#define VK_M 'M'
+#define VK_N 'N'
+#define VK_O 'O'
+#define VK_P 'P'
+#define VK_Q 'Q'
+#define VK_R 'R'
+#define VK_S 'S'
+#define VK_T 'T'
+#define VK_U 'U'
+#define VK_V 'V'
+#define VK_W 'W'
+#define VK_X 'X'
+#define VK_Y 'Y'
+#define VK_Z 'Z'
+#endif /* VK_0 */
+
+/* These keys haven't been defined, but were experimentally determined */
+#define VK_SEMICOLON 0xBA
+#define VK_EQUALS 0xBB
+#define VK_COMMA 0xBC
+#define VK_MINUS 0xBD
+#define VK_PERIOD 0xBE
+#define VK_SLASH 0xBF
+#define VK_GRAVE 0xC0
+#define VK_LBRACKET 0xDB
+#define VK_BACKSLASH 0xDC
+#define VK_RBRACKET 0xDD
+#define VK_APOSTROPHE 0xDE
+#define VK_BACKTICK 0xDF
+#define VK_OEM_102 0xE2
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsclipboard.c b/src/3rdparty/SDL2/src/video/windows/SDL_windowsclipboard.c
new file mode 100644
index 0000000..4e61d7a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsclipboard.c
@@ -0,0 +1,160 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINDOWS
+
+#include "SDL_windowsvideo.h"
+#include "SDL_windowswindow.h"
+#include "../../events/SDL_clipboardevents_c.h"
+
+
+#ifdef UNICODE
+#define TEXT_FORMAT CF_UNICODETEXT
+#else
+#define TEXT_FORMAT CF_TEXT
+#endif
+
+
+/* Get any application owned window handle for clipboard association */
+static HWND
+GetWindowHandle(_THIS)
+{
+ SDL_Window *window;
+
+ window = _this->windows;
+ if (window) {
+ return ((SDL_WindowData *) window->driverdata)->hwnd;
+ }
+ return NULL;
+}
+
+int
+WIN_SetClipboardText(_THIS, const char *text)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+ int result = 0;
+
+ if (OpenClipboard(GetWindowHandle(_this))) {
+ HANDLE hMem;
+ LPTSTR tstr;
+ SIZE_T i, size;
+
+ /* Convert the text from UTF-8 to Windows Unicode */
+ tstr = WIN_UTF8ToString(text);
+ if (!tstr) {
+ return -1;
+ }
+
+ /* Find out the size of the data */
+ for (size = 0, i = 0; tstr[i]; ++i, ++size) {
+ if (tstr[i] == '\n' && (i == 0 || tstr[i-1] != '\r')) {
+ /* We're going to insert a carriage return */
+ ++size;
+ }
+ }
+ size = (size+1)*sizeof(*tstr);
+
+ /* Save the data to the clipboard */
+ hMem = GlobalAlloc(GMEM_MOVEABLE, size);
+ if (hMem) {
+ LPTSTR dst = (LPTSTR)GlobalLock(hMem);
+ if (dst) {
+ /* Copy the text over, adding carriage returns as necessary */
+ for (i = 0; tstr[i]; ++i) {
+ if (tstr[i] == '\n' && (i == 0 || tstr[i-1] != '\r')) {
+ *dst++ = '\r';
+ }
+ *dst++ = tstr[i];
+ }
+ *dst = 0;
+ GlobalUnlock(hMem);
+ }
+
+ EmptyClipboard();
+ if (!SetClipboardData(TEXT_FORMAT, hMem)) {
+ result = WIN_SetError("Couldn't set clipboard data");
+ }
+ data->clipboard_count = GetClipboardSequenceNumber();
+ }
+ SDL_free(tstr);
+
+ CloseClipboard();
+ } else {
+ result = WIN_SetError("Couldn't open clipboard");
+ }
+ return result;
+}
+
+char *
+WIN_GetClipboardText(_THIS)
+{
+ char *text;
+
+ text = NULL;
+ if (IsClipboardFormatAvailable(TEXT_FORMAT) &&
+ OpenClipboard(GetWindowHandle(_this))) {
+ HANDLE hMem;
+ LPTSTR tstr;
+
+ hMem = GetClipboardData(TEXT_FORMAT);
+ if (hMem) {
+ tstr = (LPTSTR)GlobalLock(hMem);
+ text = WIN_StringToUTF8(tstr);
+ GlobalUnlock(hMem);
+ } else {
+ WIN_SetError("Couldn't get clipboard data");
+ }
+ CloseClipboard();
+ }
+ if (!text) {
+ text = SDL_strdup("");
+ }
+ return text;
+}
+
+SDL_bool
+WIN_HasClipboardText(_THIS)
+{
+ SDL_bool result = SDL_FALSE;
+ char *text = WIN_GetClipboardText(_this);
+ if (text) {
+ result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
+ SDL_free(text);
+ }
+ return result;
+}
+
+void
+WIN_CheckClipboardUpdate(struct SDL_VideoData * data)
+{
+ const DWORD count = GetClipboardSequenceNumber();
+ if (count != data->clipboard_count) {
+ if (data->clipboard_count) {
+ SDL_SendClipboardUpdate();
+ }
+ data->clipboard_count = count;
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_WINDOWS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsclipboard.h b/src/3rdparty/SDL2/src/video/windows/SDL_windowsclipboard.h
new file mode 100644
index 0000000..937b7d0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsclipboard.h
@@ -0,0 +1,36 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_windowsclipboard_h_
+#define SDL_windowsclipboard_h_
+
+/* Forward declaration */
+struct SDL_VideoData;
+
+extern int WIN_SetClipboardText(_THIS, const char *text);
+extern char *WIN_GetClipboardText(_THIS);
+extern SDL_bool WIN_HasClipboardText(_THIS);
+extern void WIN_CheckClipboardUpdate(struct SDL_VideoData * data);
+
+#endif /* SDL_windowsclipboard_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsevents.c b/src/3rdparty/SDL2/src/video/windows/SDL_windowsevents.c
new file mode 100644
index 0000000..a5fd006
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsevents.c
@@ -0,0 +1,1204 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINDOWS
+
+#include "SDL_windowsvideo.h"
+#include "SDL_windowsshape.h"
+#include "SDL_system.h"
+#include "SDL_syswm.h"
+#include "SDL_timer.h"
+#include "SDL_vkeys.h"
+#include "SDL_hints.h"
+#include "../../events/SDL_events_c.h"
+#include "../../events/SDL_touch_c.h"
+#include "../../events/scancodes_windows.h"
+#include "SDL_assert.h"
+#include "SDL_hints.h"
+
+/* Dropfile support */
+#include <shellapi.h>
+
+/* For GET_X_LPARAM, GET_Y_LPARAM. */
+#include <windowsx.h>
+
+/* #define WMMSG_DEBUG */
+#ifdef WMMSG_DEBUG
+#include <stdio.h>
+#include "wmmsg.h"
+#endif
+
+/* For processing mouse WM_*BUTTON* and WM_MOUSEMOVE message-data from GetMessageExtraInfo() */
+#define MOUSEEVENTF_FROMTOUCH 0xFF515700
+
+/* Masks for processing the windows KEYDOWN and KEYUP messages */
+#define REPEATED_KEYMASK (1<<30)
+#define EXTENDED_KEYMASK (1<<24)
+
+#define VK_ENTER 10 /* Keypad Enter ... no VKEY defined? */
+#ifndef VK_OEM_NEC_EQUAL
+#define VK_OEM_NEC_EQUAL 0x92
+#endif
+
+/* Make sure XBUTTON stuff is defined that isn't in older Platform SDKs... */
+#ifndef WM_XBUTTONDOWN
+#define WM_XBUTTONDOWN 0x020B
+#endif
+#ifndef WM_XBUTTONUP
+#define WM_XBUTTONUP 0x020C
+#endif
+#ifndef GET_XBUTTON_WPARAM
+#define GET_XBUTTON_WPARAM(w) (HIWORD(w))
+#endif
+#ifndef WM_INPUT
+#define WM_INPUT 0x00ff
+#endif
+#ifndef WM_TOUCH
+#define WM_TOUCH 0x0240
+#endif
+#ifndef WM_MOUSEHWHEEL
+#define WM_MOUSEHWHEEL 0x020E
+#endif
+#ifndef WM_UNICHAR
+#define WM_UNICHAR 0x0109
+#endif
+
+static SDL_Scancode
+VKeytoScancode(WPARAM vkey)
+{
+ switch (vkey) {
+ case VK_CLEAR: return SDL_SCANCODE_CLEAR;
+ case VK_MODECHANGE: return SDL_SCANCODE_MODE;
+ case VK_SELECT: return SDL_SCANCODE_SELECT;
+ case VK_EXECUTE: return SDL_SCANCODE_EXECUTE;
+ case VK_HELP: return SDL_SCANCODE_HELP;
+ case VK_PAUSE: return SDL_SCANCODE_PAUSE;
+ case VK_NUMLOCK: return SDL_SCANCODE_NUMLOCKCLEAR;
+
+ case VK_F13: return SDL_SCANCODE_F13;
+ case VK_F14: return SDL_SCANCODE_F14;
+ case VK_F15: return SDL_SCANCODE_F15;
+ case VK_F16: return SDL_SCANCODE_F16;
+ case VK_F17: return SDL_SCANCODE_F17;
+ case VK_F18: return SDL_SCANCODE_F18;
+ case VK_F19: return SDL_SCANCODE_F19;
+ case VK_F20: return SDL_SCANCODE_F20;
+ case VK_F21: return SDL_SCANCODE_F21;
+ case VK_F22: return SDL_SCANCODE_F22;
+ case VK_F23: return SDL_SCANCODE_F23;
+ case VK_F24: return SDL_SCANCODE_F24;
+
+ case VK_OEM_NEC_EQUAL: return SDL_SCANCODE_KP_EQUALS;
+ case VK_BROWSER_BACK: return SDL_SCANCODE_AC_BACK;
+ case VK_BROWSER_FORWARD: return SDL_SCANCODE_AC_FORWARD;
+ case VK_BROWSER_REFRESH: return SDL_SCANCODE_AC_REFRESH;
+ case VK_BROWSER_STOP: return SDL_SCANCODE_AC_STOP;
+ case VK_BROWSER_SEARCH: return SDL_SCANCODE_AC_SEARCH;
+ case VK_BROWSER_FAVORITES: return SDL_SCANCODE_AC_BOOKMARKS;
+ case VK_BROWSER_HOME: return SDL_SCANCODE_AC_HOME;
+ case VK_VOLUME_MUTE: return SDL_SCANCODE_AUDIOMUTE;
+ case VK_VOLUME_DOWN: return SDL_SCANCODE_VOLUMEDOWN;
+ case VK_VOLUME_UP: return SDL_SCANCODE_VOLUMEUP;
+
+ case VK_MEDIA_NEXT_TRACK: return SDL_SCANCODE_AUDIONEXT;
+ case VK_MEDIA_PREV_TRACK: return SDL_SCANCODE_AUDIOPREV;
+ case VK_MEDIA_STOP: return SDL_SCANCODE_AUDIOSTOP;
+ case VK_MEDIA_PLAY_PAUSE: return SDL_SCANCODE_AUDIOPLAY;
+ case VK_LAUNCH_MAIL: return SDL_SCANCODE_MAIL;
+ case VK_LAUNCH_MEDIA_SELECT: return SDL_SCANCODE_MEDIASELECT;
+
+ case VK_OEM_102: return SDL_SCANCODE_NONUSBACKSLASH;
+
+ case VK_ATTN: return SDL_SCANCODE_SYSREQ;
+ case VK_CRSEL: return SDL_SCANCODE_CRSEL;
+ case VK_EXSEL: return SDL_SCANCODE_EXSEL;
+ case VK_OEM_CLEAR: return SDL_SCANCODE_CLEAR;
+
+ case VK_LAUNCH_APP1: return SDL_SCANCODE_APP1;
+ case VK_LAUNCH_APP2: return SDL_SCANCODE_APP2;
+
+ default: return SDL_SCANCODE_UNKNOWN;
+ }
+}
+
+static SDL_Scancode
+WindowsScanCodeToSDLScanCode(LPARAM lParam, WPARAM wParam)
+{
+ SDL_Scancode code;
+ int nScanCode = (lParam >> 16) & 0xFF;
+ SDL_bool bIsExtended = (lParam & (1 << 24)) != 0;
+
+ code = VKeytoScancode(wParam);
+
+ if (code == SDL_SCANCODE_UNKNOWN && nScanCode <= 127) {
+ code = windows_scancode_table[nScanCode];
+
+ if (bIsExtended) {
+ switch (code) {
+ case SDL_SCANCODE_RETURN:
+ code = SDL_SCANCODE_KP_ENTER;
+ break;
+ case SDL_SCANCODE_LALT:
+ code = SDL_SCANCODE_RALT;
+ break;
+ case SDL_SCANCODE_LCTRL:
+ code = SDL_SCANCODE_RCTRL;
+ break;
+ case SDL_SCANCODE_SLASH:
+ code = SDL_SCANCODE_KP_DIVIDE;
+ break;
+ case SDL_SCANCODE_CAPSLOCK:
+ code = SDL_SCANCODE_KP_PLUS;
+ break;
+ default:
+ break;
+ }
+ } else {
+ switch (code) {
+ case SDL_SCANCODE_HOME:
+ code = SDL_SCANCODE_KP_7;
+ break;
+ case SDL_SCANCODE_UP:
+ code = SDL_SCANCODE_KP_8;
+ break;
+ case SDL_SCANCODE_PAGEUP:
+ code = SDL_SCANCODE_KP_9;
+ break;
+ case SDL_SCANCODE_LEFT:
+ code = SDL_SCANCODE_KP_4;
+ break;
+ case SDL_SCANCODE_RIGHT:
+ code = SDL_SCANCODE_KP_6;
+ break;
+ case SDL_SCANCODE_END:
+ code = SDL_SCANCODE_KP_1;
+ break;
+ case SDL_SCANCODE_DOWN:
+ code = SDL_SCANCODE_KP_2;
+ break;
+ case SDL_SCANCODE_PAGEDOWN:
+ code = SDL_SCANCODE_KP_3;
+ break;
+ case SDL_SCANCODE_INSERT:
+ code = SDL_SCANCODE_KP_0;
+ break;
+ case SDL_SCANCODE_DELETE:
+ code = SDL_SCANCODE_KP_PERIOD;
+ break;
+ case SDL_SCANCODE_PRINTSCREEN:
+ code = SDL_SCANCODE_KP_MULTIPLY;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ return code;
+}
+
+static SDL_bool
+WIN_ShouldIgnoreFocusClick()
+{
+ return !SDL_GetHintBoolean(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, SDL_FALSE);
+}
+
+static void
+WIN_CheckWParamMouseButton(SDL_bool bwParamMousePressed, SDL_bool bSDLMousePressed, SDL_WindowData *data, Uint8 button, SDL_MouseID mouseID)
+{
+ if (data->focus_click_pending & SDL_BUTTON(button)) {
+ /* Ignore the button click for activation */
+ if (!bwParamMousePressed) {
+ data->focus_click_pending &= ~SDL_BUTTON(button);
+ if (!data->focus_click_pending) {
+ WIN_UpdateClipCursor(data->window);
+ }
+ }
+ if (WIN_ShouldIgnoreFocusClick()) {
+ return;
+ }
+ }
+
+ if (bwParamMousePressed && !bSDLMousePressed) {
+ SDL_SendMouseButton(data->window, mouseID, SDL_PRESSED, button);
+ } else if (!bwParamMousePressed && bSDLMousePressed) {
+ SDL_SendMouseButton(data->window, mouseID, SDL_RELEASED, button);
+ }
+}
+
+/*
+* Some windows systems fail to send a WM_LBUTTONDOWN sometimes, but each mouse move contains the current button state also
+* so this funciton reconciles our view of the world with the current buttons reported by windows
+*/
+static void
+WIN_CheckWParamMouseButtons(WPARAM wParam, SDL_WindowData *data, SDL_MouseID mouseID)
+{
+ if (wParam != data->mouse_button_flags) {
+ Uint32 mouseFlags = SDL_GetMouseState(NULL, NULL);
+ WIN_CheckWParamMouseButton((wParam & MK_LBUTTON), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT, mouseID);
+ WIN_CheckWParamMouseButton((wParam & MK_MBUTTON), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE, mouseID);
+ WIN_CheckWParamMouseButton((wParam & MK_RBUTTON), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT, mouseID);
+ WIN_CheckWParamMouseButton((wParam & MK_XBUTTON1), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1, mouseID);
+ WIN_CheckWParamMouseButton((wParam & MK_XBUTTON2), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2, mouseID);
+ data->mouse_button_flags = wParam;
+ }
+}
+
+
+static void
+WIN_CheckRawMouseButtons(ULONG rawButtons, SDL_WindowData *data)
+{
+ if (rawButtons != data->mouse_button_flags) {
+ Uint32 mouseFlags = SDL_GetMouseState(NULL, NULL);
+ if ((rawButtons & RI_MOUSE_BUTTON_1_DOWN))
+ WIN_CheckWParamMouseButton((rawButtons & RI_MOUSE_BUTTON_1_DOWN), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT, 0);
+ if ((rawButtons & RI_MOUSE_BUTTON_1_UP))
+ WIN_CheckWParamMouseButton(!(rawButtons & RI_MOUSE_BUTTON_1_UP), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT, 0);
+ if ((rawButtons & RI_MOUSE_BUTTON_2_DOWN))
+ WIN_CheckWParamMouseButton((rawButtons & RI_MOUSE_BUTTON_2_DOWN), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT, 0);
+ if ((rawButtons & RI_MOUSE_BUTTON_2_UP))
+ WIN_CheckWParamMouseButton(!(rawButtons & RI_MOUSE_BUTTON_2_UP), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT, 0);
+ if ((rawButtons & RI_MOUSE_BUTTON_3_DOWN))
+ WIN_CheckWParamMouseButton((rawButtons & RI_MOUSE_BUTTON_3_DOWN), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE, 0);
+ if ((rawButtons & RI_MOUSE_BUTTON_3_UP))
+ WIN_CheckWParamMouseButton(!(rawButtons & RI_MOUSE_BUTTON_3_UP), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE, 0);
+ if ((rawButtons & RI_MOUSE_BUTTON_4_DOWN))
+ WIN_CheckWParamMouseButton((rawButtons & RI_MOUSE_BUTTON_4_DOWN), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1, 0);
+ if ((rawButtons & RI_MOUSE_BUTTON_4_UP))
+ WIN_CheckWParamMouseButton(!(rawButtons & RI_MOUSE_BUTTON_4_UP), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1, 0);
+ if ((rawButtons & RI_MOUSE_BUTTON_5_DOWN))
+ WIN_CheckWParamMouseButton((rawButtons & RI_MOUSE_BUTTON_5_DOWN), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2, 0);
+ if ((rawButtons & RI_MOUSE_BUTTON_5_UP))
+ WIN_CheckWParamMouseButton(!(rawButtons & RI_MOUSE_BUTTON_5_UP), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2, 0);
+ data->mouse_button_flags = rawButtons;
+ }
+}
+
+static void
+WIN_CheckAsyncMouseRelease(SDL_WindowData *data)
+{
+ Uint32 mouseFlags;
+ SHORT keyState;
+
+ /* mouse buttons may have changed state here, we need to resync them,
+ but we will get a WM_MOUSEMOVE right away which will fix things up if in non raw mode also
+ */
+ mouseFlags = SDL_GetMouseState(NULL, NULL);
+
+ keyState = GetAsyncKeyState(VK_LBUTTON);
+ if (!(keyState & 0x8000)) {
+ WIN_CheckWParamMouseButton(SDL_FALSE, (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT, 0);
+ }
+ keyState = GetAsyncKeyState(VK_RBUTTON);
+ if (!(keyState & 0x8000)) {
+ WIN_CheckWParamMouseButton(SDL_FALSE, (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT, 0);
+ }
+ keyState = GetAsyncKeyState(VK_MBUTTON);
+ if (!(keyState & 0x8000)) {
+ WIN_CheckWParamMouseButton(SDL_FALSE, (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE, 0);
+ }
+ keyState = GetAsyncKeyState(VK_XBUTTON1);
+ if (!(keyState & 0x8000)) {
+ WIN_CheckWParamMouseButton(SDL_FALSE, (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1, 0);
+ }
+ keyState = GetAsyncKeyState(VK_XBUTTON2);
+ if (!(keyState & 0x8000)) {
+ WIN_CheckWParamMouseButton(SDL_FALSE, (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2, 0);
+ }
+ data->mouse_button_flags = 0;
+}
+
+static BOOL
+WIN_ConvertUTF32toUTF8(UINT32 codepoint, char * text)
+{
+ if (codepoint <= 0x7F) {
+ text[0] = (char) codepoint;
+ text[1] = '\0';
+ } else if (codepoint <= 0x7FF) {
+ text[0] = 0xC0 | (char) ((codepoint >> 6) & 0x1F);
+ text[1] = 0x80 | (char) (codepoint & 0x3F);
+ text[2] = '\0';
+ } else if (codepoint <= 0xFFFF) {
+ text[0] = 0xE0 | (char) ((codepoint >> 12) & 0x0F);
+ text[1] = 0x80 | (char) ((codepoint >> 6) & 0x3F);
+ text[2] = 0x80 | (char) (codepoint & 0x3F);
+ text[3] = '\0';
+ } else if (codepoint <= 0x10FFFF) {
+ text[0] = 0xF0 | (char) ((codepoint >> 18) & 0x0F);
+ text[1] = 0x80 | (char) ((codepoint >> 12) & 0x3F);
+ text[2] = 0x80 | (char) ((codepoint >> 6) & 0x3F);
+ text[3] = 0x80 | (char) (codepoint & 0x3F);
+ text[4] = '\0';
+ } else {
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
+}
+
+static SDL_bool
+ShouldGenerateWindowCloseOnAltF4(void)
+{
+ return !SDL_GetHintBoolean(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4, SDL_FALSE);
+}
+
+/* Win10 "Fall Creators Update" introduced the bug that SetCursorPos() (as used by SDL_WarpMouseInWindow())
+ doesn't reliably generate WM_MOUSEMOVE events anymore (see #3931) which breaks relative mouse mode via warping.
+ This is used to implement a workaround.. */
+static SDL_bool isWin10FCUorNewer = SDL_FALSE;
+
+LRESULT CALLBACK
+WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ SDL_WindowData *data;
+ LRESULT returnCode = -1;
+
+ /* Send a SDL_SYSWMEVENT if the application wants them */
+ if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
+ SDL_SysWMmsg wmmsg;
+
+ SDL_VERSION(&wmmsg.version);
+ wmmsg.subsystem = SDL_SYSWM_WINDOWS;
+ wmmsg.msg.win.hwnd = hwnd;
+ wmmsg.msg.win.msg = msg;
+ wmmsg.msg.win.wParam = wParam;
+ wmmsg.msg.win.lParam = lParam;
+ SDL_SendSysWMEvent(&wmmsg);
+ }
+
+ /* Get the window data for the window */
+ data = (SDL_WindowData *) GetProp(hwnd, TEXT("SDL_WindowData"));
+ if (!data) {
+ return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
+ }
+
+#ifdef WMMSG_DEBUG
+ {
+ char message[1024];
+ if (msg > MAX_WMMSG) {
+ SDL_snprintf(message, sizeof(message), "Received windows message: %p UNKNOWN (%d) -- 0x%X, 0x%X\n", hwnd, msg, wParam, lParam);
+ } else {
+ SDL_snprintf(message, sizeof(message), "Received windows message: %p %s -- 0x%X, 0x%X\n", hwnd, wmtab[msg], wParam, lParam);
+ }
+ OutputDebugStringA(message);
+ }
+#endif /* WMMSG_DEBUG */
+
+ if (IME_HandleMessage(hwnd, msg, wParam, &lParam, data->videodata))
+ return 0;
+
+ switch (msg) {
+
+ case WM_SHOWWINDOW:
+ {
+ if (wParam) {
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
+ } else {
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
+ }
+ }
+ break;
+
+ case WM_ACTIVATE:
+ {
+ POINT cursorPos;
+ BOOL minimized;
+
+ minimized = HIWORD(wParam);
+ if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
+ if (LOWORD(wParam) == WA_CLICKACTIVE) {
+ if (GetAsyncKeyState(VK_LBUTTON)) {
+ data->focus_click_pending |= SDL_BUTTON_LMASK;
+ }
+ if (GetAsyncKeyState(VK_RBUTTON)) {
+ data->focus_click_pending |= SDL_BUTTON_RMASK;
+ }
+ if (GetAsyncKeyState(VK_MBUTTON)) {
+ data->focus_click_pending |= SDL_BUTTON_MMASK;
+ }
+ if (GetAsyncKeyState(VK_XBUTTON1)) {
+ data->focus_click_pending |= SDL_BUTTON_X1MASK;
+ }
+ if (GetAsyncKeyState(VK_XBUTTON2)) {
+ data->focus_click_pending |= SDL_BUTTON_X2MASK;
+ }
+ }
+
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
+ if (SDL_GetKeyboardFocus() != data->window) {
+ SDL_SetKeyboardFocus(data->window);
+ }
+
+ GetCursorPos(&cursorPos);
+ ScreenToClient(hwnd, &cursorPos);
+ SDL_SendMouseMotion(data->window, 0, 0, cursorPos.x, cursorPos.y);
+
+ WIN_CheckAsyncMouseRelease(data);
+
+ /*
+ * FIXME: Update keyboard state
+ */
+ WIN_CheckClipboardUpdate(data->videodata);
+
+ SDL_ToggleModState(KMOD_CAPS, (GetKeyState(VK_CAPITAL) & 0x0001) != 0);
+ SDL_ToggleModState(KMOD_NUM, (GetKeyState(VK_NUMLOCK) & 0x0001) != 0);
+ } else {
+ data->in_window_deactivation = SDL_TRUE;
+
+ if (SDL_GetKeyboardFocus() == data->window) {
+ SDL_SetKeyboardFocus(NULL);
+ WIN_ResetDeadKeys();
+ }
+
+ ClipCursor(NULL);
+
+ data->in_window_deactivation = SDL_FALSE;
+ }
+ }
+ returnCode = 0;
+ break;
+
+ case WM_MOUSEMOVE:
+ {
+ SDL_Mouse *mouse = SDL_GetMouse();
+ if (!mouse->relative_mode || mouse->relative_mode_warp) {
+ SDL_MouseID mouseID = (((GetMessageExtraInfo() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) ? SDL_TOUCH_MOUSEID : 0);
+ SDL_SendMouseMotion(data->window, mouseID, 0, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
+ if (isWin10FCUorNewer && mouseID != SDL_TOUCH_MOUSEID && mouse->relative_mode_warp) {
+ /* To work around #3931, Win10 bug introduced in Fall Creators Update, where
+ SetCursorPos() (SDL_WarpMouseInWindow()) doesn't reliably generate mouse events anymore,
+ after each windows mouse event generate a fake event for the middle of the window
+ if relative_mode_warp is used */
+ int center_x = 0, center_y = 0;
+ SDL_GetWindowSize(data->window, &center_x, &center_y);
+ center_x /= 2;
+ center_y /= 2;
+ SDL_SendMouseMotion(data->window, mouseID, 0, center_x, center_y);
+ }
+ }
+ }
+ /* don't break here, fall through to check the wParam like the button presses */
+ case WM_LBUTTONUP:
+ case WM_RBUTTONUP:
+ case WM_MBUTTONUP:
+ case WM_XBUTTONUP:
+ case WM_LBUTTONDOWN:
+ case WM_LBUTTONDBLCLK:
+ case WM_RBUTTONDOWN:
+ case WM_RBUTTONDBLCLK:
+ case WM_MBUTTONDOWN:
+ case WM_MBUTTONDBLCLK:
+ case WM_XBUTTONDOWN:
+ case WM_XBUTTONDBLCLK:
+ {
+ SDL_Mouse *mouse = SDL_GetMouse();
+ if (!mouse->relative_mode || mouse->relative_mode_warp) {
+ SDL_MouseID mouseID = (((GetMessageExtraInfo() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) ? SDL_TOUCH_MOUSEID : 0);
+ WIN_CheckWParamMouseButtons(wParam, data, mouseID);
+ }
+ }
+ break;
+
+ case WM_INPUT:
+ {
+ SDL_Mouse *mouse = SDL_GetMouse();
+ HRAWINPUT hRawInput = (HRAWINPUT)lParam;
+ RAWINPUT inp;
+ UINT size = sizeof(inp);
+ const SDL_bool isRelative = mouse->relative_mode || mouse->relative_mode_warp;
+ const SDL_bool isCapture = ((data->window->flags & SDL_WINDOW_MOUSE_CAPTURE) != 0);
+
+ if (!isRelative || mouse->focus != data->window) {
+ if (!isCapture) {
+ break;
+ }
+ }
+
+ GetRawInputData(hRawInput, RID_INPUT, &inp, &size, sizeof(RAWINPUTHEADER));
+
+ /* Mouse data */
+ if (inp.header.dwType == RIM_TYPEMOUSE) {
+ if (isRelative) {
+ RAWMOUSE* rawmouse = &inp.data.mouse;
+
+ if ((rawmouse->usFlags & 0x01) == MOUSE_MOVE_RELATIVE) {
+ SDL_SendMouseMotion(data->window, 0, 1, (int)rawmouse->lLastX, (int)rawmouse->lLastY);
+ } else {
+ /* synthesize relative moves from the abs position */
+ static SDL_Point initialMousePoint;
+ if (initialMousePoint.x == 0 && initialMousePoint.y == 0) {
+ initialMousePoint.x = rawmouse->lLastX;
+ initialMousePoint.y = rawmouse->lLastY;
+ }
+
+ SDL_SendMouseMotion(data->window, 0, 1, (int)(rawmouse->lLastX-initialMousePoint.x), (int)(rawmouse->lLastY-initialMousePoint.y));
+
+ initialMousePoint.x = rawmouse->lLastX;
+ initialMousePoint.y = rawmouse->lLastY;
+ }
+ WIN_CheckRawMouseButtons(rawmouse->usButtonFlags, data);
+ } else if (isCapture) {
+ /* we check for where Windows thinks the system cursor lives in this case, so we don't really lose mouse accel, etc. */
+ POINT pt;
+ RECT hwndRect;
+ HWND currentHnd;
+
+ GetCursorPos(&pt);
+ currentHnd = WindowFromPoint(pt);
+ ScreenToClient(hwnd, &pt);
+ GetClientRect(hwnd, &hwndRect);
+
+ /* if in the window, WM_MOUSEMOVE, etc, will cover it. */
+ if(currentHnd != hwnd || pt.x < 0 || pt.y < 0 || pt.x > hwndRect.right || pt.y > hwndRect.right) {
+ SDL_SendMouseMotion(data->window, 0, 0, (int)pt.x, (int)pt.y);
+ SDL_SendMouseButton(data->window, 0, GetAsyncKeyState(VK_LBUTTON) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_LEFT);
+ SDL_SendMouseButton(data->window, 0, GetAsyncKeyState(VK_RBUTTON) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_RIGHT);
+ SDL_SendMouseButton(data->window, 0, GetAsyncKeyState(VK_MBUTTON) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_MIDDLE);
+ SDL_SendMouseButton(data->window, 0, GetAsyncKeyState(VK_XBUTTON1) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_X1);
+ SDL_SendMouseButton(data->window, 0, GetAsyncKeyState(VK_XBUTTON2) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_X2);
+ }
+ } else {
+ SDL_assert(0 && "Shouldn't happen");
+ }
+ }
+ }
+ break;
+
+ case WM_MOUSEWHEEL:
+ case WM_MOUSEHWHEEL:
+ {
+ short amount = GET_WHEEL_DELTA_WPARAM(wParam);
+ float fAmount = (float) amount / WHEEL_DELTA;
+ if (msg == WM_MOUSEWHEEL)
+ SDL_SendMouseWheel(data->window, 0, 0.0f, fAmount, SDL_MOUSEWHEEL_NORMAL);
+ else
+ SDL_SendMouseWheel(data->window, 0, fAmount, 0.0f, SDL_MOUSEWHEEL_NORMAL);
+ }
+ break;
+
+#ifdef WM_MOUSELEAVE
+ case WM_MOUSELEAVE:
+ if (SDL_GetMouseFocus() == data->window && !SDL_GetMouse()->relative_mode && !(data->window->flags & SDL_WINDOW_MOUSE_CAPTURE)) {
+ if (!IsIconic(hwnd)) {
+ POINT cursorPos;
+ GetCursorPos(&cursorPos);
+ ScreenToClient(hwnd, &cursorPos);
+ SDL_SendMouseMotion(data->window, 0, 0, cursorPos.x, cursorPos.y);
+ }
+ SDL_SetMouseFocus(NULL);
+ }
+ returnCode = 0;
+ break;
+#endif /* WM_MOUSELEAVE */
+
+ case WM_KEYDOWN:
+ case WM_SYSKEYDOWN:
+ {
+ SDL_Scancode code = WindowsScanCodeToSDLScanCode(lParam, wParam);
+ const Uint8 *keyboardState = SDL_GetKeyboardState(NULL);
+
+ /* Detect relevant keyboard shortcuts */
+ if (keyboardState[SDL_SCANCODE_LALT] == SDL_PRESSED || keyboardState[SDL_SCANCODE_RALT] == SDL_PRESSED) {
+ /* ALT+F4: Close window */
+ if (code == SDL_SCANCODE_F4 && ShouldGenerateWindowCloseOnAltF4()) {
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
+ }
+ }
+
+ if (code != SDL_SCANCODE_UNKNOWN) {
+ SDL_SendKeyboardKey(SDL_PRESSED, code);
+ }
+ }
+
+ returnCode = 0;
+ break;
+
+ case WM_SYSKEYUP:
+ case WM_KEYUP:
+ {
+ SDL_Scancode code = WindowsScanCodeToSDLScanCode(lParam, wParam);
+ const Uint8 *keyboardState = SDL_GetKeyboardState(NULL);
+
+ if (code != SDL_SCANCODE_UNKNOWN) {
+ if (code == SDL_SCANCODE_PRINTSCREEN &&
+ keyboardState[code] == SDL_RELEASED) {
+ SDL_SendKeyboardKey(SDL_PRESSED, code);
+ }
+ SDL_SendKeyboardKey(SDL_RELEASED, code);
+ }
+ }
+ returnCode = 0;
+ break;
+
+ case WM_UNICHAR:
+ if ( wParam == UNICODE_NOCHAR ) {
+ returnCode = 1;
+ break;
+ }
+ /* otherwise fall through to below */
+ case WM_CHAR:
+ {
+ char text[5];
+ if ( WIN_ConvertUTF32toUTF8( (UINT32)wParam, text ) ) {
+ SDL_SendKeyboardText( text );
+ }
+ }
+ returnCode = 0;
+ break;
+
+#ifdef WM_INPUTLANGCHANGE
+ case WM_INPUTLANGCHANGE:
+ {
+ WIN_UpdateKeymap();
+ SDL_SendKeymapChangedEvent();
+ }
+ returnCode = 1;
+ break;
+#endif /* WM_INPUTLANGCHANGE */
+
+ case WM_NCLBUTTONDOWN:
+ {
+ data->in_title_click = SDL_TRUE;
+ }
+ break;
+
+ case WM_CAPTURECHANGED:
+ {
+ data->in_title_click = SDL_FALSE;
+
+ /* The mouse may have been released during a modal loop */
+ WIN_CheckAsyncMouseRelease(data);
+ }
+ break;
+
+#ifdef WM_GETMINMAXINFO
+ case WM_GETMINMAXINFO:
+ {
+ MINMAXINFO *info;
+ RECT size;
+ int x, y;
+ int w, h;
+ int min_w, min_h;
+ int max_w, max_h;
+ BOOL constrain_max_size;
+
+ if (SDL_IsShapedWindow(data->window))
+ Win32_ResizeWindowShape(data->window);
+
+ /* If this is an expected size change, allow it */
+ if (data->expected_resize) {
+ break;
+ }
+
+ /* Get the current position of our window */
+ GetWindowRect(hwnd, &size);
+ x = size.left;
+ y = size.top;
+
+ /* Calculate current size of our window */
+ SDL_GetWindowSize(data->window, &w, &h);
+ SDL_GetWindowMinimumSize(data->window, &min_w, &min_h);
+ SDL_GetWindowMaximumSize(data->window, &max_w, &max_h);
+
+ /* Store in min_w and min_h difference between current size and minimal
+ size so we don't need to call AdjustWindowRectEx twice */
+ min_w -= w;
+ min_h -= h;
+ if (max_w && max_h) {
+ max_w -= w;
+ max_h -= h;
+ constrain_max_size = TRUE;
+ } else {
+ constrain_max_size = FALSE;
+ }
+
+ if (!(SDL_GetWindowFlags(data->window) & SDL_WINDOW_BORDERLESS)) {
+ LONG style = GetWindowLong(hwnd, GWL_STYLE);
+ /* DJM - according to the docs for GetMenu(), the
+ return value is undefined if hwnd is a child window.
+ Apparently it's too difficult for MS to check
+ inside their function, so I have to do it here.
+ */
+ BOOL menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
+ size.top = 0;
+ size.left = 0;
+ size.bottom = h;
+ size.right = w;
+
+ AdjustWindowRectEx(&size, style, menu, 0);
+ w = size.right - size.left;
+ h = size.bottom - size.top;
+ }
+
+ /* Fix our size to the current size */
+ info = (MINMAXINFO *) lParam;
+ if (SDL_GetWindowFlags(data->window) & SDL_WINDOW_RESIZABLE) {
+ info->ptMinTrackSize.x = w + min_w;
+ info->ptMinTrackSize.y = h + min_h;
+ if (constrain_max_size) {
+ info->ptMaxTrackSize.x = w + max_w;
+ info->ptMaxTrackSize.y = h + max_h;
+ }
+ } else {
+ info->ptMaxSize.x = w;
+ info->ptMaxSize.y = h;
+ info->ptMaxPosition.x = x;
+ info->ptMaxPosition.y = y;
+ info->ptMinTrackSize.x = w;
+ info->ptMinTrackSize.y = h;
+ info->ptMaxTrackSize.x = w;
+ info->ptMaxTrackSize.y = h;
+ }
+ }
+ returnCode = 0;
+ break;
+#endif /* WM_GETMINMAXINFO */
+
+ case WM_WINDOWPOSCHANGING:
+
+ if (data->expected_resize) {
+ returnCode = 0;
+ }
+ break;
+
+ case WM_WINDOWPOSCHANGED:
+ {
+ RECT rect;
+ int x, y;
+ int w, h;
+
+ if (data->initializing || data->in_border_change) {
+ break;
+ }
+
+ if (!GetClientRect(hwnd, &rect) || IsRectEmpty(&rect)) {
+ break;
+ }
+ ClientToScreen(hwnd, (LPPOINT) & rect);
+ ClientToScreen(hwnd, (LPPOINT) & rect + 1);
+
+ WIN_UpdateClipCursor(data->window);
+
+ x = rect.left;
+ y = rect.top;
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED, x, y);
+
+ w = rect.right - rect.left;
+ h = rect.bottom - rect.top;
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESIZED, w,
+ h);
+
+ /* Forces a WM_PAINT event */
+ InvalidateRect(hwnd, NULL, FALSE);
+ }
+ break;
+
+ case WM_SIZE:
+ {
+ switch (wParam) {
+ case SIZE_MAXIMIZED:
+ SDL_SendWindowEvent(data->window,
+ SDL_WINDOWEVENT_RESTORED, 0, 0);
+ SDL_SendWindowEvent(data->window,
+ SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
+ break;
+ case SIZE_MINIMIZED:
+ SDL_SendWindowEvent(data->window,
+ SDL_WINDOWEVENT_MINIMIZED, 0, 0);
+ break;
+ default:
+ SDL_SendWindowEvent(data->window,
+ SDL_WINDOWEVENT_RESTORED, 0, 0);
+ break;
+ }
+ }
+ break;
+
+ case WM_SETCURSOR:
+ {
+ Uint16 hittest;
+
+ hittest = LOWORD(lParam);
+ if (hittest == HTCLIENT) {
+ SetCursor(SDL_cursor);
+ returnCode = TRUE;
+ } else if (!g_WindowFrameUsableWhileCursorHidden && !SDL_cursor) {
+ SetCursor(NULL);
+ returnCode = TRUE;
+ }
+ }
+ break;
+
+ /* We were occluded, refresh our display */
+ case WM_PAINT:
+ {
+ RECT rect;
+ if (GetUpdateRect(hwnd, &rect, FALSE)) {
+ ValidateRect(hwnd, NULL);
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_EXPOSED,
+ 0, 0);
+ }
+ }
+ returnCode = 0;
+ break;
+
+ /* We'll do our own drawing, prevent flicker */
+ case WM_ERASEBKGND:
+ {
+ }
+ return (1);
+
+ case WM_SYSCOMMAND:
+ {
+ if ((wParam & 0xFFF0) == SC_KEYMENU) {
+ return (0);
+ }
+
+#if defined(SC_SCREENSAVE) || defined(SC_MONITORPOWER)
+ /* Don't start the screensaver or blank the monitor in fullscreen apps */
+ if ((wParam & 0xFFF0) == SC_SCREENSAVE ||
+ (wParam & 0xFFF0) == SC_MONITORPOWER) {
+ if (SDL_GetVideoDevice()->suspend_screensaver) {
+ return (0);
+ }
+ }
+#endif /* System has screensaver support */
+ }
+ break;
+
+ case WM_CLOSE:
+ {
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
+ }
+ returnCode = 0;
+ break;
+
+ case WM_TOUCH:
+ if (data->videodata->GetTouchInputInfo && data->videodata->CloseTouchInputHandle) {
+ UINT i, num_inputs = LOWORD(wParam);
+ PTOUCHINPUT inputs = SDL_stack_alloc(TOUCHINPUT, num_inputs);
+ if (data->videodata->GetTouchInputInfo((HTOUCHINPUT)lParam, num_inputs, inputs, sizeof(TOUCHINPUT))) {
+ RECT rect;
+ float x, y;
+
+ if (!GetClientRect(hwnd, &rect) ||
+ (rect.right == rect.left && rect.bottom == rect.top)) {
+ if (inputs) {
+ SDL_stack_free(inputs);
+ }
+ break;
+ }
+ ClientToScreen(hwnd, (LPPOINT) & rect);
+ ClientToScreen(hwnd, (LPPOINT) & rect + 1);
+ rect.top *= 100;
+ rect.left *= 100;
+ rect.bottom *= 100;
+ rect.right *= 100;
+
+ for (i = 0; i < num_inputs; ++i) {
+ PTOUCHINPUT input = &inputs[i];
+
+ const SDL_TouchID touchId = (SDL_TouchID)((size_t)input->hSource);
+ if (SDL_AddTouch(touchId, "") < 0) {
+ continue;
+ }
+
+ /* Get the normalized coordinates for the window */
+ x = (float)(input->x - rect.left)/(rect.right - rect.left);
+ y = (float)(input->y - rect.top)/(rect.bottom - rect.top);
+
+ if (input->dwFlags & TOUCHEVENTF_DOWN) {
+ SDL_SendTouch(touchId, input->dwID, SDL_TRUE, x, y, 1.0f);
+ }
+ if (input->dwFlags & TOUCHEVENTF_MOVE) {
+ SDL_SendTouchMotion(touchId, input->dwID, x, y, 1.0f);
+ }
+ if (input->dwFlags & TOUCHEVENTF_UP) {
+ SDL_SendTouch(touchId, input->dwID, SDL_FALSE, x, y, 1.0f);
+ }
+ }
+ }
+ SDL_stack_free(inputs);
+
+ data->videodata->CloseTouchInputHandle((HTOUCHINPUT)lParam);
+ return 0;
+ }
+ break;
+
+ case WM_DROPFILES:
+ {
+ UINT i;
+ HDROP drop = (HDROP) wParam;
+ UINT count = DragQueryFile(drop, 0xFFFFFFFF, NULL, 0);
+ for (i = 0; i < count; ++i) {
+ UINT size = DragQueryFile(drop, i, NULL, 0) + 1;
+ LPTSTR buffer = SDL_stack_alloc(TCHAR, size);
+ if (buffer) {
+ if (DragQueryFile(drop, i, buffer, size)) {
+ char *file = WIN_StringToUTF8(buffer);
+ SDL_SendDropFile(data->window, file);
+ SDL_free(file);
+ }
+ SDL_stack_free(buffer);
+ }
+ }
+ SDL_SendDropComplete(data->window);
+ DragFinish(drop);
+ return 0;
+ }
+ break;
+
+ case WM_NCCALCSIZE:
+ {
+ Uint32 window_flags = SDL_GetWindowFlags(data->window);
+ if (wParam == TRUE && (window_flags & SDL_WINDOW_BORDERLESS) && !(window_flags & SDL_WINDOW_FULLSCREEN)) {
+ /* When borderless, need to tell windows that the size of the non-client area is 0 */
+ if (!(window_flags & SDL_WINDOW_RESIZABLE)) {
+ int w, h;
+ NCCALCSIZE_PARAMS *params = (NCCALCSIZE_PARAMS *)lParam;
+ w = data->window->windowed.w;
+ h = data->window->windowed.h;
+ params->rgrc[0].right = params->rgrc[0].left + w;
+ params->rgrc[0].bottom = params->rgrc[0].top + h;
+ }
+ return 0;
+ }
+ }
+ break;
+
+ case WM_NCHITTEST:
+ {
+ SDL_Window *window = data->window;
+ if (window->hit_test) {
+ POINT winpoint = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
+ if (ScreenToClient(hwnd, &winpoint)) {
+ const SDL_Point point = { (int) winpoint.x, (int) winpoint.y };
+ const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data);
+ switch (rc) {
+ #define POST_HIT_TEST(ret) { SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIT_TEST, 0, 0); return ret; }
+ case SDL_HITTEST_DRAGGABLE: POST_HIT_TEST(HTCAPTION);
+ case SDL_HITTEST_RESIZE_TOPLEFT: POST_HIT_TEST(HTTOPLEFT);
+ case SDL_HITTEST_RESIZE_TOP: POST_HIT_TEST(HTTOP);
+ case SDL_HITTEST_RESIZE_TOPRIGHT: POST_HIT_TEST(HTTOPRIGHT);
+ case SDL_HITTEST_RESIZE_RIGHT: POST_HIT_TEST(HTRIGHT);
+ case SDL_HITTEST_RESIZE_BOTTOMRIGHT: POST_HIT_TEST(HTBOTTOMRIGHT);
+ case SDL_HITTEST_RESIZE_BOTTOM: POST_HIT_TEST(HTBOTTOM);
+ case SDL_HITTEST_RESIZE_BOTTOMLEFT: POST_HIT_TEST(HTBOTTOMLEFT);
+ case SDL_HITTEST_RESIZE_LEFT: POST_HIT_TEST(HTLEFT);
+ #undef POST_HIT_TEST
+ case SDL_HITTEST_NORMAL: return HTCLIENT;
+ }
+ }
+ /* If we didn't return, this will call DefWindowProc below. */
+ }
+ }
+ break;
+ }
+
+ /* If there's a window proc, assume it's going to handle messages */
+ if (data->wndproc) {
+ return CallWindowProc(data->wndproc, hwnd, msg, wParam, lParam);
+ } else if (returnCode >= 0) {
+ return returnCode;
+ } else {
+ return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
+ }
+}
+
+/* A message hook called before TranslateMessage() */
+static SDL_WindowsMessageHook g_WindowsMessageHook = NULL;
+static void *g_WindowsMessageHookData = NULL;
+
+void SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback, void *userdata)
+{
+ g_WindowsMessageHook = callback;
+ g_WindowsMessageHookData = userdata;
+}
+
+void
+WIN_PumpEvents(_THIS)
+{
+ const Uint8 *keystate;
+ MSG msg;
+ DWORD start_ticks = GetTickCount();
+
+ if (g_WindowsEnableMessageLoop) {
+ while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+ if (g_WindowsMessageHook) {
+ g_WindowsMessageHook(g_WindowsMessageHookData, msg.hwnd, msg.message, msg.wParam, msg.lParam);
+ }
+
+ /* Always translate the message in case it's a non-SDL window (e.g. with Qt integration) */
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+
+ /* Make sure we don't busy loop here forever if there are lots of events coming in */
+ if (SDL_TICKS_PASSED(msg.time, start_ticks)) {
+ break;
+ }
+ }
+ }
+
+ /* Windows loses a shift KEYUP event when you have both pressed at once and let go of one.
+ You won't get a KEYUP until both are released, and that keyup will only be for the second
+ key you released. Take heroic measures and check the keystate as of the last handled event,
+ and if we think a key is pressed when Windows doesn't, unstick it in SDL's state. */
+ keystate = SDL_GetKeyboardState(NULL);
+ if ((keystate[SDL_SCANCODE_LSHIFT] == SDL_PRESSED) && !(GetKeyState(VK_LSHIFT) & 0x8000)) {
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
+ }
+ if ((keystate[SDL_SCANCODE_RSHIFT] == SDL_PRESSED) && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RSHIFT);
+ }
+}
+
+/* to work around #3931, a bug introduced in Win10 Fall Creators Update (build nr. 16299)
+ we need to detect the windows version. this struct and the function below does that.
+ usually this struct and the corresponding function (RtlGetVersion) are in <Ntddk.h>
+ but here we just load it dynamically */
+struct SDL_WIN_OSVERSIONINFOW {
+ ULONG dwOSVersionInfoSize;
+ ULONG dwMajorVersion;
+ ULONG dwMinorVersion;
+ ULONG dwBuildNumber;
+ ULONG dwPlatformId;
+ WCHAR szCSDVersion[128];
+};
+
+static SDL_bool
+IsWin10FCUorNewer(void)
+{
+ HMODULE handle = GetModuleHandleW(L"ntdll.dll");
+ if (handle) {
+ typedef LONG(WINAPI* RtlGetVersionPtr)(struct SDL_WIN_OSVERSIONINFOW*);
+ RtlGetVersionPtr getVersionPtr = (RtlGetVersionPtr)GetProcAddress(handle, "RtlGetVersion");
+ if (getVersionPtr != NULL) {
+ struct SDL_WIN_OSVERSIONINFOW info;
+ SDL_zero(info);
+ info.dwOSVersionInfoSize = sizeof(info);
+ if (getVersionPtr(&info) == 0) { /* STATUS_SUCCESS == 0 */
+ if ( (info.dwMajorVersion == 10 && info.dwMinorVersion == 0 && info.dwBuildNumber >= 16299)
+ || (info.dwMajorVersion == 10 && info.dwMinorVersion > 0)
+ || (info.dwMajorVersion > 10) )
+ {
+ return SDL_TRUE;
+ }
+ }
+ }
+ }
+ return SDL_FALSE;
+}
+
+static int app_registered = 0;
+LPTSTR SDL_Appname = NULL;
+Uint32 SDL_Appstyle = 0;
+HINSTANCE SDL_Instance = NULL;
+
+/* Register the class for this application */
+int
+SDL_RegisterApp(char *name, Uint32 style, void *hInst)
+{
+ const char *hint;
+ WNDCLASSEX wcex;
+ TCHAR path[MAX_PATH];
+
+ /* Only do this once... */
+ if (app_registered) {
+ ++app_registered;
+ return (0);
+ }
+ if (!name && !SDL_Appname) {
+ name = "SDL_app";
+#if defined(CS_BYTEALIGNCLIENT) || defined(CS_OWNDC)
+ SDL_Appstyle = (CS_BYTEALIGNCLIENT | CS_OWNDC);
+#endif
+ SDL_Instance = hInst ? hInst : GetModuleHandle(NULL);
+ }
+
+ if (name) {
+ SDL_Appname = WIN_UTF8ToString(name);
+ SDL_Appstyle = style;
+ SDL_Instance = hInst ? hInst : GetModuleHandle(NULL);
+ }
+
+ /* Register the application class */
+ wcex.cbSize = sizeof(WNDCLASSEX);
+ wcex.hCursor = NULL;
+ wcex.hIcon = NULL;
+ wcex.hIconSm = NULL;
+ wcex.lpszMenuName = NULL;
+ wcex.lpszClassName = SDL_Appname;
+ wcex.style = SDL_Appstyle;
+ wcex.hbrBackground = NULL;
+ wcex.lpfnWndProc = WIN_WindowProc;
+ wcex.hInstance = SDL_Instance;
+ wcex.cbClsExtra = 0;
+ wcex.cbWndExtra = 0;
+
+ hint = SDL_GetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON);
+ if (hint && *hint) {
+ wcex.hIcon = LoadIcon(SDL_Instance, MAKEINTRESOURCE(SDL_atoi(hint)));
+
+ hint = SDL_GetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL);
+ if (hint && *hint) {
+ wcex.hIconSm = LoadIcon(SDL_Instance, MAKEINTRESOURCE(SDL_atoi(hint)));
+ }
+ } else {
+ /* Use the first icon as a default icon, like in the Explorer */
+ GetModuleFileName(SDL_Instance, path, MAX_PATH);
+ ExtractIconEx(path, 0, &wcex.hIcon, &wcex.hIconSm, 1);
+ }
+
+ if (!RegisterClassEx(&wcex)) {
+ return SDL_SetError("Couldn't register application class");
+ }
+
+ isWin10FCUorNewer = IsWin10FCUorNewer();
+
+ app_registered = 1;
+ return 0;
+}
+
+/* Unregisters the windowclass registered in SDL_RegisterApp above. */
+void
+SDL_UnregisterApp()
+{
+ WNDCLASSEX wcex;
+
+ /* SDL_RegisterApp might not have been called before */
+ if (!app_registered) {
+ return;
+ }
+ --app_registered;
+ if (app_registered == 0) {
+ /* Check for any registered window classes. */
+ if (GetClassInfoEx(SDL_Instance, SDL_Appname, &wcex)) {
+ UnregisterClass(SDL_Appname, SDL_Instance);
+ if (wcex.hIcon) DestroyIcon(wcex.hIcon);
+ if (wcex.hIconSm) DestroyIcon(wcex.hIconSm);
+ }
+ SDL_free(SDL_Appname);
+ SDL_Appname = NULL;
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_WINDOWS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsevents.h b/src/3rdparty/SDL2/src/video/windows/SDL_windowsevents.h
new file mode 100644
index 0000000..1ce2fb4
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsevents.h
@@ -0,0 +1,36 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_windowsevents_h_
+#define SDL_windowsevents_h_
+
+extern LPTSTR SDL_Appname;
+extern Uint32 SDL_Appstyle;
+extern HINSTANCE SDL_Instance;
+
+extern LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam,
+ LPARAM lParam);
+extern void WIN_PumpEvents(_THIS);
+
+#endif /* SDL_windowsevents_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsframebuffer.c b/src/3rdparty/SDL2/src/video/windows/SDL_windowsframebuffer.c
new file mode 100644
index 0000000..e07d9c4
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsframebuffer.c
@@ -0,0 +1,127 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINDOWS
+
+#include "SDL_windowsvideo.h"
+
+int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ size_t size;
+ LPBITMAPINFO info;
+ HBITMAP hbm;
+
+ /* Free the old framebuffer surface */
+ if (data->mdc) {
+ DeleteDC(data->mdc);
+ }
+ if (data->hbm) {
+ DeleteObject(data->hbm);
+ }
+
+ /* Find out the format of the screen */
+ size = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD);
+ info = (LPBITMAPINFO)SDL_stack_alloc(Uint8, size);
+ if (!info) {
+ return SDL_OutOfMemory();
+ }
+
+ SDL_memset(info, 0, size);
+ info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+
+ /* The second call to GetDIBits() fills in the bitfields */
+ hbm = CreateCompatibleBitmap(data->hdc, 1, 1);
+ GetDIBits(data->hdc, hbm, 0, 0, NULL, info, DIB_RGB_COLORS);
+ GetDIBits(data->hdc, hbm, 0, 0, NULL, info, DIB_RGB_COLORS);
+ DeleteObject(hbm);
+
+ *format = SDL_PIXELFORMAT_UNKNOWN;
+ if (info->bmiHeader.biCompression == BI_BITFIELDS) {
+ int bpp;
+ Uint32 *masks;
+
+ bpp = info->bmiHeader.biPlanes * info->bmiHeader.biBitCount;
+ masks = (Uint32*)((Uint8*)info + info->bmiHeader.biSize);
+ *format = SDL_MasksToPixelFormatEnum(bpp, masks[0], masks[1], masks[2], 0);
+ }
+ if (*format == SDL_PIXELFORMAT_UNKNOWN)
+ {
+ /* We'll use RGB format for now */
+ *format = SDL_PIXELFORMAT_RGB888;
+
+ /* Create a new one */
+ SDL_memset(info, 0, size);
+ info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+ info->bmiHeader.biPlanes = 1;
+ info->bmiHeader.biBitCount = 32;
+ info->bmiHeader.biCompression = BI_RGB;
+ }
+
+ /* Fill in the size information */
+ *pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
+ info->bmiHeader.biWidth = window->w;
+ info->bmiHeader.biHeight = -window->h; /* negative for topdown bitmap */
+ info->bmiHeader.biSizeImage = window->h * (*pitch);
+
+ data->mdc = CreateCompatibleDC(data->hdc);
+ data->hbm = CreateDIBSection(data->hdc, info, DIB_RGB_COLORS, pixels, NULL, 0);
+ SDL_stack_free(info);
+
+ if (!data->hbm) {
+ return WIN_SetError("Unable to create DIB");
+ }
+ SelectObject(data->mdc, data->hbm);
+
+ return 0;
+}
+
+int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+
+ BitBlt(data->hdc, 0, 0, window->w, window->h, data->mdc, 0, 0, SRCCOPY);
+ return 0;
+}
+
+void WIN_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+
+ if (!data) {
+ /* The window wasn't fully initialized */
+ return;
+ }
+
+ if (data->mdc) {
+ DeleteDC(data->mdc);
+ data->mdc = NULL;
+ }
+ if (data->hbm) {
+ DeleteObject(data->hbm);
+ data->hbm = NULL;
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_WINDOWS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsframebuffer.h b/src/3rdparty/SDL2/src/video/windows/SDL_windowsframebuffer.h
new file mode 100644
index 0000000..a83cca5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsframebuffer.h
@@ -0,0 +1,27 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+extern int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
+extern int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects);
+extern void WIN_DestroyWindowFramebuffer(_THIS, SDL_Window * window);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowskeyboard.c b/src/3rdparty/SDL2/src/video/windows/SDL_windowskeyboard.c
new file mode 100644
index 0000000..c7f357b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowskeyboard.c
@@ -0,0 +1,1579 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINDOWS
+
+#include "SDL_windowsvideo.h"
+
+#include "../../events/SDL_keyboard_c.h"
+#include "../../events/scancodes_windows.h"
+
+#include <imm.h>
+#include <oleauto.h>
+
+#ifndef SDL_DISABLE_WINDOWS_IME
+static void IME_Init(SDL_VideoData *videodata, HWND hwnd);
+static void IME_Enable(SDL_VideoData *videodata, HWND hwnd);
+static void IME_Disable(SDL_VideoData *videodata, HWND hwnd);
+static void IME_Quit(SDL_VideoData *videodata);
+#endif /* !SDL_DISABLE_WINDOWS_IME */
+
+#ifndef MAPVK_VK_TO_VSC
+#define MAPVK_VK_TO_VSC 0
+#endif
+#ifndef MAPVK_VSC_TO_VK
+#define MAPVK_VSC_TO_VK 1
+#endif
+#ifndef MAPVK_VK_TO_CHAR
+#define MAPVK_VK_TO_CHAR 2
+#endif
+
+/* Alphabetic scancodes for PC keyboards */
+void
+WIN_InitKeyboard(_THIS)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
+ data->ime_com_initialized = SDL_FALSE;
+ data->ime_threadmgr = 0;
+ data->ime_initialized = SDL_FALSE;
+ data->ime_enabled = SDL_FALSE;
+ data->ime_available = SDL_FALSE;
+ data->ime_hwnd_main = 0;
+ data->ime_hwnd_current = 0;
+ data->ime_himc = 0;
+ data->ime_composition[0] = 0;
+ data->ime_readingstring[0] = 0;
+ data->ime_cursor = 0;
+
+ data->ime_candlist = SDL_FALSE;
+ SDL_memset(data->ime_candidates, 0, sizeof(data->ime_candidates));
+ data->ime_candcount = 0;
+ data->ime_candref = 0;
+ data->ime_candsel = 0;
+ data->ime_candpgsize = 0;
+ data->ime_candlistindexbase = 0;
+ data->ime_candvertical = SDL_TRUE;
+
+ data->ime_dirty = SDL_FALSE;
+ SDL_memset(&data->ime_rect, 0, sizeof(data->ime_rect));
+ SDL_memset(&data->ime_candlistrect, 0, sizeof(data->ime_candlistrect));
+ data->ime_winwidth = 0;
+ data->ime_winheight = 0;
+
+ data->ime_hkl = 0;
+ data->ime_himm32 = 0;
+ data->GetReadingString = 0;
+ data->ShowReadingWindow = 0;
+ data->ImmLockIMC = 0;
+ data->ImmUnlockIMC = 0;
+ data->ImmLockIMCC = 0;
+ data->ImmUnlockIMCC = 0;
+ data->ime_uiless = SDL_FALSE;
+ data->ime_threadmgrex = 0;
+ data->ime_uielemsinkcookie = TF_INVALID_COOKIE;
+ data->ime_alpnsinkcookie = TF_INVALID_COOKIE;
+ data->ime_openmodesinkcookie = TF_INVALID_COOKIE;
+ data->ime_convmodesinkcookie = TF_INVALID_COOKIE;
+ data->ime_uielemsink = 0;
+ data->ime_ippasink = 0;
+
+ WIN_UpdateKeymap();
+
+ SDL_SetScancodeName(SDL_SCANCODE_APPLICATION, "Menu");
+ SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Windows");
+ SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Windows");
+
+ /* Are system caps/num/scroll lock active? Set our state to match. */
+ SDL_ToggleModState(KMOD_CAPS, (GetKeyState(VK_CAPITAL) & 0x0001) != 0);
+ SDL_ToggleModState(KMOD_NUM, (GetKeyState(VK_NUMLOCK) & 0x0001) != 0);
+}
+
+void
+WIN_UpdateKeymap()
+{
+ int i;
+ SDL_Scancode scancode;
+ SDL_Keycode keymap[SDL_NUM_SCANCODES];
+
+ SDL_GetDefaultKeymap(keymap);
+
+ for (i = 0; i < SDL_arraysize(windows_scancode_table); i++) {
+ int vk;
+ /* Make sure this scancode is a valid character scancode */
+ scancode = windows_scancode_table[i];
+ if (scancode == SDL_SCANCODE_UNKNOWN ) {
+ continue;
+ }
+
+ /* If this key is one of the non-mappable keys, ignore it */
+ /* Not mapping numbers fixes the French layout, giving numeric keycodes for the number keys, which is the expected behavior */
+ if ((keymap[scancode] & SDLK_SCANCODE_MASK) ||
+ /* scancode == SDL_SCANCODE_GRAVE || */ /* Uncomment this line to re-enable the behavior of not mapping the "`"(grave) key to the users actual keyboard layout */
+ (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0) ) {
+ continue;
+ }
+
+ vk = MapVirtualKey(i, MAPVK_VSC_TO_VK);
+ if ( vk ) {
+ int ch = (MapVirtualKey( vk, MAPVK_VK_TO_CHAR ) & 0x7FFF);
+ if ( ch ) {
+ if ( ch >= 'A' && ch <= 'Z' ) {
+ keymap[scancode] = SDLK_a + ( ch - 'A' );
+ } else {
+ keymap[scancode] = ch;
+ }
+ }
+ }
+ }
+
+ SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
+}
+
+void
+WIN_QuitKeyboard(_THIS)
+{
+#ifndef SDL_DISABLE_WINDOWS_IME
+ IME_Quit((SDL_VideoData *)_this->driverdata);
+#endif
+}
+
+void
+WIN_ResetDeadKeys()
+{
+ /*
+ if a deadkey has been typed, but not the next character (which the deadkey might modify),
+ this tries to undo the effect pressing the deadkey.
+ see: http://archives.miloush.net/michkap/archive/2006/09/10/748775.html
+ */
+ BYTE keyboardState[256];
+ WCHAR buffer[16];
+ int keycode, scancode, result, i;
+
+ GetKeyboardState(keyboardState);
+
+ keycode = VK_SPACE;
+ scancode = MapVirtualKey(keycode, MAPVK_VK_TO_VSC);
+ if (scancode == 0) {
+ /* the keyboard doesn't have this key */
+ return;
+ }
+
+ for (i = 0; i < 5; i++) {
+ result = ToUnicode(keycode, scancode, keyboardState, (LPWSTR)buffer, 16, 0);
+ if (result > 0) {
+ /* success */
+ return;
+ }
+ }
+}
+
+void
+WIN_StartTextInput(_THIS)
+{
+#ifndef SDL_DISABLE_WINDOWS_IME
+ SDL_Window *window;
+#endif
+
+ WIN_ResetDeadKeys();
+
+#ifndef SDL_DISABLE_WINDOWS_IME
+ window = SDL_GetKeyboardFocus();
+ if (window) {
+ HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
+ SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
+ SDL_GetWindowSize(window, &videodata->ime_winwidth, &videodata->ime_winheight);
+ IME_Init(videodata, hwnd);
+ IME_Enable(videodata, hwnd);
+ }
+#endif /* !SDL_DISABLE_WINDOWS_IME */
+}
+
+void
+WIN_StopTextInput(_THIS)
+{
+#ifndef SDL_DISABLE_WINDOWS_IME
+ SDL_Window *window;
+#endif
+
+ WIN_ResetDeadKeys();
+
+#ifndef SDL_DISABLE_WINDOWS_IME
+ window = SDL_GetKeyboardFocus();
+ if (window) {
+ HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
+ SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
+ IME_Init(videodata, hwnd);
+ IME_Disable(videodata, hwnd);
+ }
+#endif /* !SDL_DISABLE_WINDOWS_IME */
+}
+
+void
+WIN_SetTextInputRect(_THIS, SDL_Rect *rect)
+{
+ SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
+ HIMC himc = 0;
+
+ if (!rect) {
+ SDL_InvalidParamError("rect");
+ return;
+ }
+
+ videodata->ime_rect = *rect;
+
+ himc = ImmGetContext(videodata->ime_hwnd_current);
+ if (himc)
+ {
+ COMPOSITIONFORM cf;
+ cf.ptCurrentPos.x = videodata->ime_rect.x;
+ cf.ptCurrentPos.y = videodata->ime_rect.y;
+ cf.dwStyle = CFS_FORCE_POSITION;
+ ImmSetCompositionWindow(himc, &cf);
+ ImmReleaseContext(videodata->ime_hwnd_current, himc);
+ }
+}
+
+#ifdef SDL_DISABLE_WINDOWS_IME
+
+
+SDL_bool
+IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, SDL_VideoData *videodata)
+{
+ return SDL_FALSE;
+}
+
+void IME_Present(SDL_VideoData *videodata)
+{
+}
+
+#else
+
+#ifdef SDL_msctf_h_
+#define USE_INIT_GUID
+#elif defined(__GNUC__)
+#define USE_INIT_GUID
+#endif
+#ifdef USE_INIT_GUID
+#undef DEFINE_GUID
+#define DEFINE_GUID(n,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) static const GUID n = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}
+DEFINE_GUID(IID_ITfInputProcessorProfileActivationSink, 0x71C6E74E,0x0F28,0x11D8,0xA8,0x2A,0x00,0x06,0x5B,0x84,0x43,0x5C);
+DEFINE_GUID(IID_ITfUIElementSink, 0xEA1EA136,0x19DF,0x11D7,0xA6,0xD2,0x00,0x06,0x5B,0x84,0x43,0x5C);
+DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD, 0x34745C63,0xB2F0,0x4784,0x8B,0x67,0x5E,0x12,0xC8,0x70,0x1A,0x31);
+DEFINE_GUID(IID_ITfSource, 0x4EA48A35,0x60AE,0x446F,0x8F,0xD6,0xE6,0xA8,0xD8,0x24,0x59,0xF7);
+DEFINE_GUID(IID_ITfUIElementMgr, 0xEA1EA135,0x19DF,0x11D7,0xA6,0xD2,0x00,0x06,0x5B,0x84,0x43,0x5C);
+DEFINE_GUID(IID_ITfCandidateListUIElement, 0xEA1EA138,0x19DF,0x11D7,0xA6,0xD2,0x00,0x06,0x5B,0x84,0x43,0x5C);
+DEFINE_GUID(IID_ITfReadingInformationUIElement, 0xEA1EA139,0x19DF,0x11D7,0xA6,0xD2,0x00,0x06,0x5B,0x84,0x43,0x5C);
+DEFINE_GUID(IID_ITfThreadMgr, 0xAA80E801,0x2021,0x11D2,0x93,0xE0,0x00,0x60,0xB0,0x67,0xB8,0x6E);
+DEFINE_GUID(CLSID_TF_ThreadMgr, 0x529A9E6B,0x6587,0x4F23,0xAB,0x9E,0x9C,0x7D,0x68,0x3E,0x3C,0x50);
+DEFINE_GUID(IID_ITfThreadMgrEx, 0x3E90ADE3,0x7594,0x4CB0,0xBB,0x58,0x69,0x62,0x8F,0x5F,0x45,0x8C);
+#endif
+
+#define LANG_CHT MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL)
+#define LANG_CHS MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED)
+
+#define MAKEIMEVERSION(major,minor) ((DWORD) (((BYTE)(major) << 24) | ((BYTE)(minor) << 16) ))
+#define IMEID_VER(id) ((id) & 0xffff0000)
+#define IMEID_LANG(id) ((id) & 0x0000ffff)
+
+#define CHT_HKL_DAYI ((HKL)(UINT_PTR)0xE0060404)
+#define CHT_HKL_NEW_PHONETIC ((HKL)(UINT_PTR)0xE0080404)
+#define CHT_HKL_NEW_CHANG_JIE ((HKL)(UINT_PTR)0xE0090404)
+#define CHT_HKL_NEW_QUICK ((HKL)(UINT_PTR)0xE00A0404)
+#define CHT_HKL_HK_CANTONESE ((HKL)(UINT_PTR)0xE00B0404)
+#define CHT_IMEFILENAME1 "TINTLGNT.IME"
+#define CHT_IMEFILENAME2 "CINTLGNT.IME"
+#define CHT_IMEFILENAME3 "MSTCIPHA.IME"
+#define IMEID_CHT_VER42 (LANG_CHT | MAKEIMEVERSION(4, 2))
+#define IMEID_CHT_VER43 (LANG_CHT | MAKEIMEVERSION(4, 3))
+#define IMEID_CHT_VER44 (LANG_CHT | MAKEIMEVERSION(4, 4))
+#define IMEID_CHT_VER50 (LANG_CHT | MAKEIMEVERSION(5, 0))
+#define IMEID_CHT_VER51 (LANG_CHT | MAKEIMEVERSION(5, 1))
+#define IMEID_CHT_VER52 (LANG_CHT | MAKEIMEVERSION(5, 2))
+#define IMEID_CHT_VER60 (LANG_CHT | MAKEIMEVERSION(6, 0))
+#define IMEID_CHT_VER_VISTA (LANG_CHT | MAKEIMEVERSION(7, 0))
+
+#define CHS_HKL ((HKL)(UINT_PTR)0xE00E0804)
+#define CHS_IMEFILENAME1 "PINTLGNT.IME"
+#define CHS_IMEFILENAME2 "MSSCIPYA.IME"
+#define IMEID_CHS_VER41 (LANG_CHS | MAKEIMEVERSION(4, 1))
+#define IMEID_CHS_VER42 (LANG_CHS | MAKEIMEVERSION(4, 2))
+#define IMEID_CHS_VER53 (LANG_CHS | MAKEIMEVERSION(5, 3))
+
+#define LANG() LOWORD((videodata->ime_hkl))
+#define PRIMLANG() ((WORD)PRIMARYLANGID(LANG()))
+#define SUBLANG() SUBLANGID(LANG())
+
+static void IME_UpdateInputLocale(SDL_VideoData *videodata);
+static void IME_ClearComposition(SDL_VideoData *videodata);
+static void IME_SetWindow(SDL_VideoData* videodata, HWND hwnd);
+static void IME_SetupAPI(SDL_VideoData *videodata);
+static DWORD IME_GetId(SDL_VideoData *videodata, UINT uIndex);
+static void IME_SendEditingEvent(SDL_VideoData *videodata);
+static void IME_DestroyTextures(SDL_VideoData *videodata);
+
+static SDL_bool UILess_SetupSinks(SDL_VideoData *videodata);
+static void UILess_ReleaseSinks(SDL_VideoData *videodata);
+static void UILess_EnableUIUpdates(SDL_VideoData *videodata);
+static void UILess_DisableUIUpdates(SDL_VideoData *videodata);
+
+static void
+IME_Init(SDL_VideoData *videodata, HWND hwnd)
+{
+ if (videodata->ime_initialized)
+ return;
+
+ videodata->ime_hwnd_main = hwnd;
+ if (SUCCEEDED(WIN_CoInitialize())) {
+ videodata->ime_com_initialized = SDL_TRUE;
+ CoCreateInstance(&CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (LPVOID *)&videodata->ime_threadmgr);
+ }
+ videodata->ime_initialized = SDL_TRUE;
+ videodata->ime_himm32 = SDL_LoadObject("imm32.dll");
+ if (!videodata->ime_himm32) {
+ videodata->ime_available = SDL_FALSE;
+ SDL_ClearError();
+ return;
+ }
+ videodata->ImmLockIMC = (LPINPUTCONTEXT2 (WINAPI *)(HIMC))SDL_LoadFunction(videodata->ime_himm32, "ImmLockIMC");
+ videodata->ImmUnlockIMC = (BOOL (WINAPI *)(HIMC))SDL_LoadFunction(videodata->ime_himm32, "ImmUnlockIMC");
+ videodata->ImmLockIMCC = (LPVOID (WINAPI *)(HIMCC))SDL_LoadFunction(videodata->ime_himm32, "ImmLockIMCC");
+ videodata->ImmUnlockIMCC = (BOOL (WINAPI *)(HIMCC))SDL_LoadFunction(videodata->ime_himm32, "ImmUnlockIMCC");
+
+ IME_SetWindow(videodata, hwnd);
+ videodata->ime_himc = ImmGetContext(hwnd);
+ ImmReleaseContext(hwnd, videodata->ime_himc);
+ if (!videodata->ime_himc) {
+ videodata->ime_available = SDL_FALSE;
+ IME_Disable(videodata, hwnd);
+ return;
+ }
+ videodata->ime_available = SDL_TRUE;
+ IME_UpdateInputLocale(videodata);
+ IME_SetupAPI(videodata);
+ videodata->ime_uiless = UILess_SetupSinks(videodata);
+ IME_UpdateInputLocale(videodata);
+ IME_Disable(videodata, hwnd);
+}
+
+static void
+IME_Enable(SDL_VideoData *videodata, HWND hwnd)
+{
+ if (!videodata->ime_initialized || !videodata->ime_hwnd_current)
+ return;
+
+ if (!videodata->ime_available) {
+ IME_Disable(videodata, hwnd);
+ return;
+ }
+ if (videodata->ime_hwnd_current == videodata->ime_hwnd_main)
+ ImmAssociateContext(videodata->ime_hwnd_current, videodata->ime_himc);
+
+ videodata->ime_enabled = SDL_TRUE;
+ IME_UpdateInputLocale(videodata);
+ UILess_EnableUIUpdates(videodata);
+}
+
+static void
+IME_Disable(SDL_VideoData *videodata, HWND hwnd)
+{
+ if (!videodata->ime_initialized || !videodata->ime_hwnd_current)
+ return;
+
+ IME_ClearComposition(videodata);
+ if (videodata->ime_hwnd_current == videodata->ime_hwnd_main)
+ ImmAssociateContext(videodata->ime_hwnd_current, (HIMC)0);
+
+ videodata->ime_enabled = SDL_FALSE;
+ UILess_DisableUIUpdates(videodata);
+}
+
+static void
+IME_Quit(SDL_VideoData *videodata)
+{
+ if (!videodata->ime_initialized)
+ return;
+
+ UILess_ReleaseSinks(videodata);
+ if (videodata->ime_hwnd_main)
+ ImmAssociateContext(videodata->ime_hwnd_main, videodata->ime_himc);
+
+ videodata->ime_hwnd_main = 0;
+ videodata->ime_himc = 0;
+ if (videodata->ime_himm32) {
+ SDL_UnloadObject(videodata->ime_himm32);
+ videodata->ime_himm32 = 0;
+ }
+ if (videodata->ime_threadmgr) {
+ videodata->ime_threadmgr->lpVtbl->Release(videodata->ime_threadmgr);
+ videodata->ime_threadmgr = 0;
+ }
+ if (videodata->ime_com_initialized) {
+ WIN_CoUninitialize();
+ videodata->ime_com_initialized = SDL_FALSE;
+ }
+ IME_DestroyTextures(videodata);
+ videodata->ime_initialized = SDL_FALSE;
+}
+
+static void
+IME_GetReadingString(SDL_VideoData *videodata, HWND hwnd)
+{
+ DWORD id = 0;
+ HIMC himc = 0;
+ WCHAR buffer[16];
+ WCHAR *s = buffer;
+ DWORD len = 0;
+ INT err = 0;
+ BOOL vertical = FALSE;
+ UINT maxuilen = 0;
+
+ if (videodata->ime_uiless)
+ return;
+
+ videodata->ime_readingstring[0] = 0;
+
+ id = IME_GetId(videodata, 0);
+ if (!id)
+ return;
+
+ himc = ImmGetContext(hwnd);
+ if (!himc)
+ return;
+
+ if (videodata->GetReadingString) {
+ len = videodata->GetReadingString(himc, 0, 0, &err, &vertical, &maxuilen);
+ if (len) {
+ if (len > SDL_arraysize(buffer))
+ len = SDL_arraysize(buffer);
+
+ len = videodata->GetReadingString(himc, len, s, &err, &vertical, &maxuilen);
+ }
+ SDL_wcslcpy(videodata->ime_readingstring, s, len);
+ }
+ else {
+ LPINPUTCONTEXT2 lpimc = videodata->ImmLockIMC(himc);
+ LPBYTE p = 0;
+ s = 0;
+ switch (id)
+ {
+ case IMEID_CHT_VER42:
+ case IMEID_CHT_VER43:
+ case IMEID_CHT_VER44:
+ p = *(LPBYTE *)((LPBYTE)videodata->ImmLockIMCC(lpimc->hPrivate) + 24);
+ if (!p)
+ break;
+
+ len = *(DWORD *)(p + 7*4 + 32*4);
+ s = (WCHAR *)(p + 56);
+ break;
+ case IMEID_CHT_VER51:
+ case IMEID_CHT_VER52:
+ case IMEID_CHS_VER53:
+ p = *(LPBYTE *)((LPBYTE)videodata->ImmLockIMCC(lpimc->hPrivate) + 4);
+ if (!p)
+ break;
+
+ p = *(LPBYTE *)((LPBYTE)p + 1*4 + 5*4);
+ if (!p)
+ break;
+
+ len = *(DWORD *)(p + 1*4 + (16*2+2*4) + 5*4 + 16*2);
+ s = (WCHAR *)(p + 1*4 + (16*2+2*4) + 5*4);
+ break;
+ case IMEID_CHS_VER41:
+ {
+ int offset = (IME_GetId(videodata, 1) >= 0x00000002) ? 8 : 7;
+ p = *(LPBYTE *)((LPBYTE)videodata->ImmLockIMCC(lpimc->hPrivate) + offset * 4);
+ if (!p)
+ break;
+
+ len = *(DWORD *)(p + 7*4 + 16*2*4);
+ s = (WCHAR *)(p + 6*4 + 16*2*1);
+ }
+ break;
+ case IMEID_CHS_VER42:
+ p = *(LPBYTE *)((LPBYTE)videodata->ImmLockIMCC(lpimc->hPrivate) + 1*4 + 1*4 + 6*4);
+ if (!p)
+ break;
+
+ len = *(DWORD *)(p + 1*4 + (16*2+2*4) + 5*4 + 16*2);
+ s = (WCHAR *)(p + 1*4 + (16*2+2*4) + 5*4);
+ break;
+ }
+ if (s) {
+ size_t size = SDL_min((size_t)(len + 1), SDL_arraysize(videodata->ime_readingstring));
+ SDL_wcslcpy(videodata->ime_readingstring, s, size);
+ }
+
+ videodata->ImmUnlockIMCC(lpimc->hPrivate);
+ videodata->ImmUnlockIMC(himc);
+ }
+ ImmReleaseContext(hwnd, himc);
+ IME_SendEditingEvent(videodata);
+}
+
+static void
+IME_InputLangChanged(SDL_VideoData *videodata)
+{
+ UINT lang = PRIMLANG();
+ IME_UpdateInputLocale(videodata);
+ if (!videodata->ime_uiless)
+ videodata->ime_candlistindexbase = (videodata->ime_hkl == CHT_HKL_DAYI) ? 0 : 1;
+
+ IME_SetupAPI(videodata);
+ if (lang != PRIMLANG()) {
+ IME_ClearComposition(videodata);
+ }
+}
+
+static DWORD
+IME_GetId(SDL_VideoData *videodata, UINT uIndex)
+{
+ static HKL hklprev = 0;
+ static DWORD dwRet[2] = {0};
+ DWORD dwVerSize = 0;
+ DWORD dwVerHandle = 0;
+ LPVOID lpVerBuffer = 0;
+ LPVOID lpVerData = 0;
+ UINT cbVerData = 0;
+ char szTemp[256];
+ HKL hkl = 0;
+ DWORD dwLang = 0;
+ if (uIndex >= sizeof(dwRet) / sizeof(dwRet[0]))
+ return 0;
+
+ hkl = videodata->ime_hkl;
+ if (hklprev == hkl)
+ return dwRet[uIndex];
+
+ hklprev = hkl;
+ dwLang = ((DWORD_PTR)hkl & 0xffff);
+ if (videodata->ime_uiless && LANG() == LANG_CHT) {
+ dwRet[0] = IMEID_CHT_VER_VISTA;
+ dwRet[1] = 0;
+ return dwRet[0];
+ }
+ if (hkl != CHT_HKL_NEW_PHONETIC
+ && hkl != CHT_HKL_NEW_CHANG_JIE
+ && hkl != CHT_HKL_NEW_QUICK
+ && hkl != CHT_HKL_HK_CANTONESE
+ && hkl != CHS_HKL) {
+ dwRet[0] = dwRet[1] = 0;
+ return dwRet[uIndex];
+ }
+ if (ImmGetIMEFileNameA(hkl, szTemp, sizeof(szTemp) - 1) <= 0) {
+ dwRet[0] = dwRet[1] = 0;
+ return dwRet[uIndex];
+ }
+ if (!videodata->GetReadingString) {
+ #define LCID_INVARIANT MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT)
+ if (CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHT_IMEFILENAME1, -1) != 2
+ && CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHT_IMEFILENAME2, -1) != 2
+ && CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHT_IMEFILENAME3, -1) != 2
+ && CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHS_IMEFILENAME1, -1) != 2
+ && CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHS_IMEFILENAME2, -1) != 2) {
+ dwRet[0] = dwRet[1] = 0;
+ return dwRet[uIndex];
+ }
+ #undef LCID_INVARIANT
+ dwVerSize = GetFileVersionInfoSizeA(szTemp, &dwVerHandle);
+ if (dwVerSize) {
+ lpVerBuffer = SDL_malloc(dwVerSize);
+ if (lpVerBuffer) {
+ if (GetFileVersionInfoA(szTemp, dwVerHandle, dwVerSize, lpVerBuffer)) {
+ if (VerQueryValueA(lpVerBuffer, "\\", &lpVerData, &cbVerData)) {
+ #define pVerFixedInfo ((VS_FIXEDFILEINFO FAR*)lpVerData)
+ DWORD dwVer = pVerFixedInfo->dwFileVersionMS;
+ dwVer = (dwVer & 0x00ff0000) << 8 | (dwVer & 0x000000ff) << 16;
+ if ((videodata->GetReadingString) ||
+ ((dwLang == LANG_CHT) && (
+ dwVer == MAKEIMEVERSION(4, 2) ||
+ dwVer == MAKEIMEVERSION(4, 3) ||
+ dwVer == MAKEIMEVERSION(4, 4) ||
+ dwVer == MAKEIMEVERSION(5, 0) ||
+ dwVer == MAKEIMEVERSION(5, 1) ||
+ dwVer == MAKEIMEVERSION(5, 2) ||
+ dwVer == MAKEIMEVERSION(6, 0)))
+ ||
+ ((dwLang == LANG_CHS) && (
+ dwVer == MAKEIMEVERSION(4, 1) ||
+ dwVer == MAKEIMEVERSION(4, 2) ||
+ dwVer == MAKEIMEVERSION(5, 3)))) {
+ dwRet[0] = dwVer | dwLang;
+ dwRet[1] = pVerFixedInfo->dwFileVersionLS;
+ SDL_free(lpVerBuffer);
+ return dwRet[0];
+ }
+ #undef pVerFixedInfo
+ }
+ }
+ }
+ SDL_free(lpVerBuffer);
+ }
+ }
+ dwRet[0] = dwRet[1] = 0;
+ return dwRet[uIndex];
+}
+
+static void
+IME_SetupAPI(SDL_VideoData *videodata)
+{
+ char ime_file[MAX_PATH + 1];
+ void* hime = 0;
+ HKL hkl = 0;
+ videodata->GetReadingString = 0;
+ videodata->ShowReadingWindow = 0;
+ if (videodata->ime_uiless)
+ return;
+
+ hkl = videodata->ime_hkl;
+ if (ImmGetIMEFileNameA(hkl, ime_file, sizeof(ime_file) - 1) <= 0)
+ return;
+
+ hime = SDL_LoadObject(ime_file);
+ if (!hime)
+ return;
+
+ videodata->GetReadingString = (UINT (WINAPI *)(HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT))
+ SDL_LoadFunction(hime, "GetReadingString");
+ videodata->ShowReadingWindow = (BOOL (WINAPI *)(HIMC, BOOL))
+ SDL_LoadFunction(hime, "ShowReadingWindow");
+
+ if (videodata->ShowReadingWindow) {
+ HIMC himc = ImmGetContext(videodata->ime_hwnd_current);
+ if (himc) {
+ videodata->ShowReadingWindow(himc, FALSE);
+ ImmReleaseContext(videodata->ime_hwnd_current, himc);
+ }
+ }
+}
+
+static void
+IME_SetWindow(SDL_VideoData* videodata, HWND hwnd)
+{
+ videodata->ime_hwnd_current = hwnd;
+ if (videodata->ime_threadmgr) {
+ struct ITfDocumentMgr *document_mgr = 0;
+ if (SUCCEEDED(videodata->ime_threadmgr->lpVtbl->AssociateFocus(videodata->ime_threadmgr, hwnd, NULL, &document_mgr))) {
+ if (document_mgr)
+ document_mgr->lpVtbl->Release(document_mgr);
+ }
+ }
+}
+
+static void
+IME_UpdateInputLocale(SDL_VideoData *videodata)
+{
+ static HKL hklprev = 0;
+ videodata->ime_hkl = GetKeyboardLayout(0);
+ if (hklprev == videodata->ime_hkl)
+ return;
+
+ hklprev = videodata->ime_hkl;
+ switch (PRIMLANG()) {
+ case LANG_CHINESE:
+ videodata->ime_candvertical = SDL_TRUE;
+ if (SUBLANG() == SUBLANG_CHINESE_SIMPLIFIED)
+ videodata->ime_candvertical = SDL_FALSE;
+
+ break;
+ case LANG_JAPANESE:
+ videodata->ime_candvertical = SDL_TRUE;
+ break;
+ case LANG_KOREAN:
+ videodata->ime_candvertical = SDL_FALSE;
+ break;
+ }
+}
+
+static void
+IME_ClearComposition(SDL_VideoData *videodata)
+{
+ HIMC himc = 0;
+ if (!videodata->ime_initialized)
+ return;
+
+ himc = ImmGetContext(videodata->ime_hwnd_current);
+ if (!himc)
+ return;
+
+ ImmNotifyIME(himc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
+ if (videodata->ime_uiless)
+ ImmSetCompositionString(himc, SCS_SETSTR, TEXT(""), sizeof(TCHAR), TEXT(""), sizeof(TCHAR));
+
+ ImmNotifyIME(himc, NI_CLOSECANDIDATE, 0, 0);
+ ImmReleaseContext(videodata->ime_hwnd_current, himc);
+ SDL_SendEditingText("", 0, 0);
+}
+
+static void
+IME_GetCompositionString(SDL_VideoData *videodata, HIMC himc, DWORD string)
+{
+ LONG length = ImmGetCompositionStringW(himc, string, videodata->ime_composition, sizeof(videodata->ime_composition) - sizeof(videodata->ime_composition[0]));
+ if (length < 0)
+ length = 0;
+
+ length /= sizeof(videodata->ime_composition[0]);
+ videodata->ime_cursor = LOWORD(ImmGetCompositionStringW(himc, GCS_CURSORPOS, 0, 0));
+ if (videodata->ime_cursor < SDL_arraysize(videodata->ime_composition) && videodata->ime_composition[videodata->ime_cursor] == 0x3000) {
+ int i;
+ for (i = videodata->ime_cursor + 1; i < length; ++i)
+ videodata->ime_composition[i - 1] = videodata->ime_composition[i];
+
+ --length;
+ }
+ videodata->ime_composition[length] = 0;
+}
+
+static void
+IME_SendInputEvent(SDL_VideoData *videodata)
+{
+ char *s = 0;
+ s = WIN_StringToUTF8(videodata->ime_composition);
+ SDL_SendKeyboardText(s);
+ SDL_free(s);
+
+ videodata->ime_composition[0] = 0;
+ videodata->ime_readingstring[0] = 0;
+ videodata->ime_cursor = 0;
+}
+
+static void
+IME_SendEditingEvent(SDL_VideoData *videodata)
+{
+ char *s = 0;
+ WCHAR buffer[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
+ const size_t size = SDL_arraysize(buffer);
+ buffer[0] = 0;
+ if (videodata->ime_readingstring[0]) {
+ size_t len = SDL_min(SDL_wcslen(videodata->ime_composition), (size_t)videodata->ime_cursor);
+ SDL_wcslcpy(buffer, videodata->ime_composition, len + 1);
+ SDL_wcslcat(buffer, videodata->ime_readingstring, size);
+ SDL_wcslcat(buffer, &videodata->ime_composition[len], size);
+ }
+ else {
+ SDL_wcslcpy(buffer, videodata->ime_composition, size);
+ }
+ s = WIN_StringToUTF8(buffer);
+ SDL_SendEditingText(s, videodata->ime_cursor + (int)SDL_wcslen(videodata->ime_readingstring), 0);
+ SDL_free(s);
+}
+
+static void
+IME_AddCandidate(SDL_VideoData *videodata, UINT i, LPCWSTR candidate)
+{
+ LPWSTR dst = videodata->ime_candidates[i];
+ *dst++ = (WCHAR)(TEXT('0') + ((i + videodata->ime_candlistindexbase) % 10));
+ if (videodata->ime_candvertical)
+ *dst++ = TEXT(' ');
+
+ while (*candidate && (SDL_arraysize(videodata->ime_candidates[i]) > (dst - videodata->ime_candidates[i])))
+ *dst++ = *candidate++;
+
+ *dst = (WCHAR)'\0';
+}
+
+static void
+IME_GetCandidateList(HIMC himc, SDL_VideoData *videodata)
+{
+ LPCANDIDATELIST cand_list = 0;
+ DWORD size = ImmGetCandidateListW(himc, 0, 0, 0);
+ if (size) {
+ cand_list = (LPCANDIDATELIST)SDL_malloc(size);
+ if (cand_list) {
+ size = ImmGetCandidateListW(himc, 0, cand_list, size);
+ if (size) {
+ UINT i, j;
+ UINT page_start = 0;
+ videodata->ime_candsel = cand_list->dwSelection;
+ videodata->ime_candcount = cand_list->dwCount;
+
+ if (LANG() == LANG_CHS && IME_GetId(videodata, 0)) {
+ const UINT maxcandchar = 18;
+ size_t cchars = 0;
+
+ for (i = 0; i < videodata->ime_candcount; ++i) {
+ size_t len = SDL_wcslen((LPWSTR)((DWORD_PTR)cand_list + cand_list->dwOffset[i])) + 1;
+ if (len + cchars > maxcandchar) {
+ if (i > cand_list->dwSelection)
+ break;
+
+ page_start = i;
+ cchars = len;
+ }
+ else {
+ cchars += len;
+ }
+ }
+ videodata->ime_candpgsize = i - page_start;
+ } else {
+ videodata->ime_candpgsize = SDL_min(cand_list->dwPageSize, MAX_CANDLIST);
+ if (videodata->ime_candpgsize > 0) {
+ page_start = (cand_list->dwSelection / videodata->ime_candpgsize) * videodata->ime_candpgsize;
+ } else {
+ page_start = 0;
+ }
+ }
+ SDL_memset(&videodata->ime_candidates, 0, sizeof(videodata->ime_candidates));
+ for (i = page_start, j = 0; (DWORD)i < cand_list->dwCount && j < (int)videodata->ime_candpgsize; i++, j++) {
+ LPCWSTR candidate = (LPCWSTR)((DWORD_PTR)cand_list + cand_list->dwOffset[i]);
+ IME_AddCandidate(videodata, j, candidate);
+ }
+ if (PRIMLANG() == LANG_KOREAN || (PRIMLANG() == LANG_CHT && !IME_GetId(videodata, 0)))
+ videodata->ime_candsel = -1;
+
+ }
+ SDL_free(cand_list);
+ }
+ }
+}
+
+static void
+IME_ShowCandidateList(SDL_VideoData *videodata)
+{
+ videodata->ime_dirty = SDL_TRUE;
+ videodata->ime_candlist = SDL_TRUE;
+ IME_DestroyTextures(videodata);
+ IME_SendEditingEvent(videodata);
+}
+
+static void
+IME_HideCandidateList(SDL_VideoData *videodata)
+{
+ videodata->ime_dirty = SDL_FALSE;
+ videodata->ime_candlist = SDL_FALSE;
+ IME_DestroyTextures(videodata);
+ IME_SendEditingEvent(videodata);
+}
+
+SDL_bool
+IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, SDL_VideoData *videodata)
+{
+ SDL_bool trap = SDL_FALSE;
+ HIMC himc = 0;
+ if (!videodata->ime_initialized || !videodata->ime_available || !videodata->ime_enabled)
+ return SDL_FALSE;
+
+ switch (msg) {
+ case WM_INPUTLANGCHANGE:
+ IME_InputLangChanged(videodata);
+ break;
+ case WM_IME_SETCONTEXT:
+ *lParam = 0;
+ break;
+ case WM_IME_STARTCOMPOSITION:
+ trap = SDL_TRUE;
+ break;
+ case WM_IME_COMPOSITION:
+ trap = SDL_TRUE;
+ himc = ImmGetContext(hwnd);
+ if (*lParam & GCS_RESULTSTR) {
+ IME_GetCompositionString(videodata, himc, GCS_RESULTSTR);
+ IME_SendInputEvent(videodata);
+ }
+ if (*lParam & GCS_COMPSTR) {
+ if (!videodata->ime_uiless)
+ videodata->ime_readingstring[0] = 0;
+
+ IME_GetCompositionString(videodata, himc, GCS_COMPSTR);
+ IME_SendEditingEvent(videodata);
+ }
+ ImmReleaseContext(hwnd, himc);
+ break;
+ case WM_IME_ENDCOMPOSITION:
+ videodata->ime_composition[0] = 0;
+ videodata->ime_readingstring[0] = 0;
+ videodata->ime_cursor = 0;
+ SDL_SendEditingText("", 0, 0);
+ break;
+ case WM_IME_NOTIFY:
+ switch (wParam) {
+ case IMN_SETCONVERSIONMODE:
+ case IMN_SETOPENSTATUS:
+ IME_UpdateInputLocale(videodata);
+ break;
+ case IMN_OPENCANDIDATE:
+ case IMN_CHANGECANDIDATE:
+ if (videodata->ime_uiless)
+ break;
+
+ trap = SDL_TRUE;
+ IME_ShowCandidateList(videodata);
+ himc = ImmGetContext(hwnd);
+ if (!himc)
+ break;
+
+ IME_GetCandidateList(himc, videodata);
+ ImmReleaseContext(hwnd, himc);
+ break;
+ case IMN_CLOSECANDIDATE:
+ trap = SDL_TRUE;
+ IME_HideCandidateList(videodata);
+ break;
+ case IMN_PRIVATE:
+ {
+ DWORD dwId = IME_GetId(videodata, 0);
+ IME_GetReadingString(videodata, hwnd);
+ switch (dwId)
+ {
+ case IMEID_CHT_VER42:
+ case IMEID_CHT_VER43:
+ case IMEID_CHT_VER44:
+ case IMEID_CHS_VER41:
+ case IMEID_CHS_VER42:
+ if (*lParam == 1 || *lParam == 2)
+ trap = SDL_TRUE;
+
+ break;
+ case IMEID_CHT_VER50:
+ case IMEID_CHT_VER51:
+ case IMEID_CHT_VER52:
+ case IMEID_CHT_VER60:
+ case IMEID_CHS_VER53:
+ if (*lParam == 16
+ || *lParam == 17
+ || *lParam == 26
+ || *lParam == 27
+ || *lParam == 28)
+ trap = SDL_TRUE;
+ break;
+ }
+ }
+ break;
+ default:
+ trap = SDL_TRUE;
+ break;
+ }
+ break;
+ }
+ return trap;
+}
+
+static void
+IME_CloseCandidateList(SDL_VideoData *videodata)
+{
+ IME_HideCandidateList(videodata);
+ videodata->ime_candcount = 0;
+ SDL_memset(videodata->ime_candidates, 0, sizeof(videodata->ime_candidates));
+}
+
+static void
+UILess_GetCandidateList(SDL_VideoData *videodata, ITfCandidateListUIElement *pcandlist)
+{
+ UINT selection = 0;
+ UINT count = 0;
+ UINT page = 0;
+ UINT pgcount = 0;
+ DWORD pgstart = 0;
+ DWORD pgsize = 0;
+ UINT i, j;
+ pcandlist->lpVtbl->GetSelection(pcandlist, &selection);
+ pcandlist->lpVtbl->GetCount(pcandlist, &count);
+ pcandlist->lpVtbl->GetCurrentPage(pcandlist, &page);
+
+ videodata->ime_candsel = selection;
+ videodata->ime_candcount = count;
+ IME_ShowCandidateList(videodata);
+
+ pcandlist->lpVtbl->GetPageIndex(pcandlist, 0, 0, &pgcount);
+ if (pgcount > 0) {
+ UINT *idxlist = SDL_malloc(sizeof(UINT) * pgcount);
+ if (idxlist) {
+ pcandlist->lpVtbl->GetPageIndex(pcandlist, idxlist, pgcount, &pgcount);
+ pgstart = idxlist[page];
+ if (page < pgcount - 1)
+ pgsize = SDL_min(count, idxlist[page + 1]) - pgstart;
+ else
+ pgsize = count - pgstart;
+
+ SDL_free(idxlist);
+ }
+ }
+ videodata->ime_candpgsize = SDL_min(pgsize, MAX_CANDLIST);
+ videodata->ime_candsel = videodata->ime_candsel - pgstart;
+
+ SDL_memset(videodata->ime_candidates, 0, sizeof(videodata->ime_candidates));
+ for (i = pgstart, j = 0; (DWORD)i < count && j < videodata->ime_candpgsize; i++, j++) {
+ BSTR bstr;
+ if (SUCCEEDED(pcandlist->lpVtbl->GetString(pcandlist, i, &bstr))) {
+ if (bstr) {
+ IME_AddCandidate(videodata, j, bstr);
+ SysFreeString(bstr);
+ }
+ }
+ }
+ if (PRIMLANG() == LANG_KOREAN)
+ videodata->ime_candsel = -1;
+}
+
+STDMETHODIMP_(ULONG) TSFSink_AddRef(TSFSink *sink)
+{
+ return ++sink->refcount;
+}
+
+STDMETHODIMP_(ULONG) TSFSink_Release(TSFSink *sink)
+{
+ --sink->refcount;
+ if (sink->refcount == 0) {
+ SDL_free(sink);
+ return 0;
+ }
+ return sink->refcount;
+}
+
+STDMETHODIMP UIElementSink_QueryInterface(TSFSink *sink, REFIID riid, PVOID *ppv)
+{
+ if (!ppv)
+ return E_INVALIDARG;
+
+ *ppv = 0;
+ if (WIN_IsEqualIID(riid, &IID_IUnknown))
+ *ppv = (IUnknown *)sink;
+ else if (WIN_IsEqualIID(riid, &IID_ITfUIElementSink))
+ *ppv = (ITfUIElementSink *)sink;
+
+ if (*ppv) {
+ TSFSink_AddRef(sink);
+ return S_OK;
+ }
+ return E_NOINTERFACE;
+}
+
+ITfUIElement *UILess_GetUIElement(SDL_VideoData *videodata, DWORD dwUIElementId)
+{
+ ITfUIElementMgr *puiem = 0;
+ ITfUIElement *pelem = 0;
+ ITfThreadMgrEx *threadmgrex = videodata->ime_threadmgrex;
+
+ if (SUCCEEDED(threadmgrex->lpVtbl->QueryInterface(threadmgrex, &IID_ITfUIElementMgr, (LPVOID *)&puiem))) {
+ puiem->lpVtbl->GetUIElement(puiem, dwUIElementId, &pelem);
+ puiem->lpVtbl->Release(puiem);
+ }
+ return pelem;
+}
+
+STDMETHODIMP UIElementSink_BeginUIElement(TSFSink *sink, DWORD dwUIElementId, BOOL *pbShow)
+{
+ ITfUIElement *element = UILess_GetUIElement((SDL_VideoData *)sink->data, dwUIElementId);
+ ITfReadingInformationUIElement *preading = 0;
+ ITfCandidateListUIElement *pcandlist = 0;
+ SDL_VideoData *videodata = (SDL_VideoData *)sink->data;
+ if (!element)
+ return E_INVALIDARG;
+
+ *pbShow = FALSE;
+ if (SUCCEEDED(element->lpVtbl->QueryInterface(element, &IID_ITfReadingInformationUIElement, (LPVOID *)&preading))) {
+ BSTR bstr;
+ if (SUCCEEDED(preading->lpVtbl->GetString(preading, &bstr)) && bstr) {
+ SysFreeString(bstr);
+ }
+ preading->lpVtbl->Release(preading);
+ }
+ else if (SUCCEEDED(element->lpVtbl->QueryInterface(element, &IID_ITfCandidateListUIElement, (LPVOID *)&pcandlist))) {
+ videodata->ime_candref++;
+ UILess_GetCandidateList(videodata, pcandlist);
+ pcandlist->lpVtbl->Release(pcandlist);
+ }
+ return S_OK;
+}
+
+STDMETHODIMP UIElementSink_UpdateUIElement(TSFSink *sink, DWORD dwUIElementId)
+{
+ ITfUIElement *element = UILess_GetUIElement((SDL_VideoData *)sink->data, dwUIElementId);
+ ITfReadingInformationUIElement *preading = 0;
+ ITfCandidateListUIElement *pcandlist = 0;
+ SDL_VideoData *videodata = (SDL_VideoData *)sink->data;
+ if (!element)
+ return E_INVALIDARG;
+
+ if (SUCCEEDED(element->lpVtbl->QueryInterface(element, &IID_ITfReadingInformationUIElement, (LPVOID *)&preading))) {
+ BSTR bstr;
+ if (SUCCEEDED(preading->lpVtbl->GetString(preading, &bstr)) && bstr) {
+ WCHAR *s = (WCHAR *)bstr;
+ SDL_wcslcpy(videodata->ime_readingstring, s, SDL_arraysize(videodata->ime_readingstring));
+ IME_SendEditingEvent(videodata);
+ SysFreeString(bstr);
+ }
+ preading->lpVtbl->Release(preading);
+ }
+ else if (SUCCEEDED(element->lpVtbl->QueryInterface(element, &IID_ITfCandidateListUIElement, (LPVOID *)&pcandlist))) {
+ UILess_GetCandidateList(videodata, pcandlist);
+ pcandlist->lpVtbl->Release(pcandlist);
+ }
+ return S_OK;
+}
+
+STDMETHODIMP UIElementSink_EndUIElement(TSFSink *sink, DWORD dwUIElementId)
+{
+ ITfUIElement *element = UILess_GetUIElement((SDL_VideoData *)sink->data, dwUIElementId);
+ ITfReadingInformationUIElement *preading = 0;
+ ITfCandidateListUIElement *pcandlist = 0;
+ SDL_VideoData *videodata = (SDL_VideoData *)sink->data;
+ if (!element)
+ return E_INVALIDARG;
+
+ if (SUCCEEDED(element->lpVtbl->QueryInterface(element, &IID_ITfReadingInformationUIElement, (LPVOID *)&preading))) {
+ videodata->ime_readingstring[0] = 0;
+ IME_SendEditingEvent(videodata);
+ preading->lpVtbl->Release(preading);
+ }
+ if (SUCCEEDED(element->lpVtbl->QueryInterface(element, &IID_ITfCandidateListUIElement, (LPVOID *)&pcandlist))) {
+ videodata->ime_candref--;
+ if (videodata->ime_candref == 0)
+ IME_CloseCandidateList(videodata);
+
+ pcandlist->lpVtbl->Release(pcandlist);
+ }
+ return S_OK;
+}
+
+STDMETHODIMP IPPASink_QueryInterface(TSFSink *sink, REFIID riid, PVOID *ppv)
+{
+ if (!ppv)
+ return E_INVALIDARG;
+
+ *ppv = 0;
+ if (WIN_IsEqualIID(riid, &IID_IUnknown))
+ *ppv = (IUnknown *)sink;
+ else if (WIN_IsEqualIID(riid, &IID_ITfInputProcessorProfileActivationSink))
+ *ppv = (ITfInputProcessorProfileActivationSink *)sink;
+
+ if (*ppv) {
+ TSFSink_AddRef(sink);
+ return S_OK;
+ }
+ return E_NOINTERFACE;
+}
+
+STDMETHODIMP IPPASink_OnActivated(TSFSink *sink, DWORD dwProfileType, LANGID langid, REFCLSID clsid, REFGUID catid, REFGUID guidProfile, HKL hkl, DWORD dwFlags)
+{
+ static const GUID TF_PROFILE_DAYI = { 0x037B2C25, 0x480C, 0x4D7F, { 0xB0, 0x27, 0xD6, 0xCA, 0x6B, 0x69, 0x78, 0x8A } };
+ SDL_VideoData *videodata = (SDL_VideoData *)sink->data;
+ videodata->ime_candlistindexbase = WIN_IsEqualGUID(&TF_PROFILE_DAYI, guidProfile) ? 0 : 1;
+ if (WIN_IsEqualIID(catid, &GUID_TFCAT_TIP_KEYBOARD) && (dwFlags & TF_IPSINK_FLAG_ACTIVE))
+ IME_InputLangChanged((SDL_VideoData *)sink->data);
+
+ IME_HideCandidateList(videodata);
+ return S_OK;
+}
+
+static void *vtUIElementSink[] = {
+ (void *)(UIElementSink_QueryInterface),
+ (void *)(TSFSink_AddRef),
+ (void *)(TSFSink_Release),
+ (void *)(UIElementSink_BeginUIElement),
+ (void *)(UIElementSink_UpdateUIElement),
+ (void *)(UIElementSink_EndUIElement)
+};
+
+static void *vtIPPASink[] = {
+ (void *)(IPPASink_QueryInterface),
+ (void *)(TSFSink_AddRef),
+ (void *)(TSFSink_Release),
+ (void *)(IPPASink_OnActivated)
+};
+
+static void
+UILess_EnableUIUpdates(SDL_VideoData *videodata)
+{
+ ITfSource *source = 0;
+ if (!videodata->ime_threadmgrex || videodata->ime_uielemsinkcookie != TF_INVALID_COOKIE)
+ return;
+
+ if (SUCCEEDED(videodata->ime_threadmgrex->lpVtbl->QueryInterface(videodata->ime_threadmgrex, &IID_ITfSource, (LPVOID *)&source))) {
+ source->lpVtbl->AdviseSink(source, &IID_ITfUIElementSink, (IUnknown *)videodata->ime_uielemsink, &videodata->ime_uielemsinkcookie);
+ source->lpVtbl->Release(source);
+ }
+}
+
+static void
+UILess_DisableUIUpdates(SDL_VideoData *videodata)
+{
+ ITfSource *source = 0;
+ if (!videodata->ime_threadmgrex || videodata->ime_uielemsinkcookie == TF_INVALID_COOKIE)
+ return;
+
+ if (SUCCEEDED(videodata->ime_threadmgrex->lpVtbl->QueryInterface(videodata->ime_threadmgrex, &IID_ITfSource, (LPVOID *)&source))) {
+ source->lpVtbl->UnadviseSink(source, videodata->ime_uielemsinkcookie);
+ videodata->ime_uielemsinkcookie = TF_INVALID_COOKIE;
+ source->lpVtbl->Release(source);
+ }
+}
+
+static SDL_bool
+UILess_SetupSinks(SDL_VideoData *videodata)
+{
+ TfClientId clientid = 0;
+ SDL_bool result = SDL_FALSE;
+ ITfSource *source = 0;
+ if (FAILED(CoCreateInstance(&CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, &IID_ITfThreadMgrEx, (LPVOID *)&videodata->ime_threadmgrex)))
+ return SDL_FALSE;
+
+ if (FAILED(videodata->ime_threadmgrex->lpVtbl->ActivateEx(videodata->ime_threadmgrex, &clientid, TF_TMAE_UIELEMENTENABLEDONLY)))
+ return SDL_FALSE;
+
+ videodata->ime_uielemsink = SDL_malloc(sizeof(TSFSink));
+ videodata->ime_ippasink = SDL_malloc(sizeof(TSFSink));
+
+ videodata->ime_uielemsink->lpVtbl = vtUIElementSink;
+ videodata->ime_uielemsink->refcount = 1;
+ videodata->ime_uielemsink->data = videodata;
+
+ videodata->ime_ippasink->lpVtbl = vtIPPASink;
+ videodata->ime_ippasink->refcount = 1;
+ videodata->ime_ippasink->data = videodata;
+
+ if (SUCCEEDED(videodata->ime_threadmgrex->lpVtbl->QueryInterface(videodata->ime_threadmgrex, &IID_ITfSource, (LPVOID *)&source))) {
+ if (SUCCEEDED(source->lpVtbl->AdviseSink(source, &IID_ITfUIElementSink, (IUnknown *)videodata->ime_uielemsink, &videodata->ime_uielemsinkcookie))) {
+ if (SUCCEEDED(source->lpVtbl->AdviseSink(source, &IID_ITfInputProcessorProfileActivationSink, (IUnknown *)videodata->ime_ippasink, &videodata->ime_alpnsinkcookie))) {
+ result = SDL_TRUE;
+ }
+ }
+ source->lpVtbl->Release(source);
+ }
+ return result;
+}
+
+#define SAFE_RELEASE(p) \
+{ \
+ if (p) { \
+ (p)->lpVtbl->Release((p)); \
+ (p) = 0; \
+ } \
+}
+
+static void
+UILess_ReleaseSinks(SDL_VideoData *videodata)
+{
+ ITfSource *source = 0;
+ if (videodata->ime_threadmgrex && SUCCEEDED(videodata->ime_threadmgrex->lpVtbl->QueryInterface(videodata->ime_threadmgrex, &IID_ITfSource, (LPVOID *)&source))) {
+ source->lpVtbl->UnadviseSink(source, videodata->ime_uielemsinkcookie);
+ source->lpVtbl->UnadviseSink(source, videodata->ime_alpnsinkcookie);
+ SAFE_RELEASE(source);
+ videodata->ime_threadmgrex->lpVtbl->Deactivate(videodata->ime_threadmgrex);
+ SAFE_RELEASE(videodata->ime_threadmgrex);
+ TSFSink_Release(videodata->ime_uielemsink);
+ videodata->ime_uielemsink = 0;
+ TSFSink_Release(videodata->ime_ippasink);
+ videodata->ime_ippasink = 0;
+ }
+}
+
+static void *
+StartDrawToBitmap(HDC hdc, HBITMAP *hhbm, int width, int height)
+{
+ BITMAPINFO info;
+ BITMAPINFOHEADER *infoHeader = &info.bmiHeader;
+ BYTE *bits = NULL;
+ if (hhbm) {
+ SDL_zero(info);
+ infoHeader->biSize = sizeof(BITMAPINFOHEADER);
+ infoHeader->biWidth = width;
+ infoHeader->biHeight = -1 * SDL_abs(height);
+ infoHeader->biPlanes = 1;
+ infoHeader->biBitCount = 32;
+ infoHeader->biCompression = BI_RGB;
+ *hhbm = CreateDIBSection(hdc, &info, DIB_RGB_COLORS, (void **)&bits, 0, 0);
+ if (*hhbm)
+ SelectObject(hdc, *hhbm);
+ }
+ return bits;
+}
+
+static void
+StopDrawToBitmap(HDC hdc, HBITMAP *hhbm)
+{
+ if (hhbm && *hhbm) {
+ DeleteObject(*hhbm);
+ *hhbm = NULL;
+ }
+}
+
+/* This draws only within the specified area and fills the entire region. */
+static void
+DrawRect(HDC hdc, int left, int top, int right, int bottom, int pensize)
+{
+ /* The case of no pen (PenSize = 0) is automatically taken care of. */
+ const int penadjust = (int)SDL_floor(pensize / 2.0f - 0.5f);
+ left += pensize / 2;
+ top += pensize / 2;
+ right -= penadjust;
+ bottom -= penadjust;
+ Rectangle(hdc, left, top, right, bottom);
+}
+
+static void
+IME_DestroyTextures(SDL_VideoData *videodata)
+{
+}
+
+#define SDL_swap(a,b) { \
+ int c = (a); \
+ (a) = (b); \
+ (b) = c; \
+ }
+
+static void
+IME_PositionCandidateList(SDL_VideoData *videodata, SIZE size)
+{
+ int left, top, right, bottom;
+ SDL_bool ok = SDL_FALSE;
+ int winw = videodata->ime_winwidth;
+ int winh = videodata->ime_winheight;
+
+ /* Bottom */
+ left = videodata->ime_rect.x;
+ top = videodata->ime_rect.y + videodata->ime_rect.h;
+ right = left + size.cx;
+ bottom = top + size.cy;
+ if (right >= winw) {
+ left -= right - winw;
+ right = winw;
+ }
+ if (bottom < winh)
+ ok = SDL_TRUE;
+
+ /* Top */
+ if (!ok) {
+ left = videodata->ime_rect.x;
+ top = videodata->ime_rect.y - size.cy;
+ right = left + size.cx;
+ bottom = videodata->ime_rect.y;
+ if (right >= winw) {
+ left -= right - winw;
+ right = winw;
+ }
+ if (top >= 0)
+ ok = SDL_TRUE;
+ }
+
+ /* Right */
+ if (!ok) {
+ left = videodata->ime_rect.x + size.cx;
+ top = 0;
+ right = left + size.cx;
+ bottom = size.cy;
+ if (right < winw)
+ ok = SDL_TRUE;
+ }
+
+ /* Left */
+ if (!ok) {
+ left = videodata->ime_rect.x - size.cx;
+ top = 0;
+ right = videodata->ime_rect.x;
+ bottom = size.cy;
+ if (right >= 0)
+ ok = SDL_TRUE;
+ }
+
+ /* Window too small, show at (0,0) */
+ if (!ok) {
+ left = 0;
+ top = 0;
+ right = size.cx;
+ bottom = size.cy;
+ }
+
+ videodata->ime_candlistrect.x = left;
+ videodata->ime_candlistrect.y = top;
+ videodata->ime_candlistrect.w = right - left;
+ videodata->ime_candlistrect.h = bottom - top;
+}
+
+static void
+IME_RenderCandidateList(SDL_VideoData *videodata, HDC hdc)
+{
+ int i, j;
+ SIZE size = {0};
+ SIZE candsizes[MAX_CANDLIST];
+ SIZE maxcandsize = {0};
+ HBITMAP hbm = NULL;
+ const int candcount = SDL_min(SDL_min(MAX_CANDLIST, videodata->ime_candcount), videodata->ime_candpgsize);
+ SDL_bool vertical = videodata->ime_candvertical;
+
+ const int listborder = 1;
+ const int listpadding = 0;
+ const int listbordercolor = RGB(0xB4, 0xC7, 0xAA);
+ const int listfillcolor = RGB(255, 255, 255);
+
+ const int candborder = 1;
+ const int candpadding = 0;
+ const int candmargin = 1;
+ const COLORREF candbordercolor = RGB(255, 255, 255);
+ const COLORREF candfillcolor = RGB(255, 255, 255);
+ const COLORREF candtextcolor = RGB(0, 0, 0);
+ const COLORREF selbordercolor = RGB(0x84, 0xAC, 0xDD);
+ const COLORREF selfillcolor = RGB(0xD2, 0xE6, 0xFF);
+ const COLORREF seltextcolor = RGB(0, 0, 0);
+ const int horzcandspacing = 5;
+
+ HPEN listpen = listborder != 0 ? CreatePen(PS_SOLID, listborder, listbordercolor) : (HPEN)GetStockObject(NULL_PEN);
+ HBRUSH listbrush = CreateSolidBrush(listfillcolor);
+ HPEN candpen = candborder != 0 ? CreatePen(PS_SOLID, candborder, candbordercolor) : (HPEN)GetStockObject(NULL_PEN);
+ HBRUSH candbrush = CreateSolidBrush(candfillcolor);
+ HPEN selpen = candborder != 0 ? CreatePen(PS_DOT, candborder, selbordercolor) : (HPEN)GetStockObject(NULL_PEN);
+ HBRUSH selbrush = CreateSolidBrush(selfillcolor);
+ HFONT font = CreateFont((int)(1 + videodata->ime_rect.h * 0.75f), 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH | FF_SWISS, TEXT("Microsoft Sans Serif"));
+
+ SetBkMode(hdc, TRANSPARENT);
+ SelectObject(hdc, font);
+
+ for (i = 0; i < candcount; ++i) {
+ const WCHAR *s = videodata->ime_candidates[i];
+ if (!*s)
+ break;
+
+ GetTextExtentPoint32W(hdc, s, (int)SDL_wcslen(s), &candsizes[i]);
+ maxcandsize.cx = SDL_max(maxcandsize.cx, candsizes[i].cx);
+ maxcandsize.cy = SDL_max(maxcandsize.cy, candsizes[i].cy);
+
+ }
+ if (vertical) {
+ size.cx =
+ (listborder * 2) +
+ (listpadding * 2) +
+ (candmargin * 2) +
+ (candborder * 2) +
+ (candpadding * 2) +
+ (maxcandsize.cx)
+ ;
+ size.cy =
+ (listborder * 2) +
+ (listpadding * 2) +
+ ((candcount + 1) * candmargin) +
+ (candcount * candborder * 2) +
+ (candcount * candpadding * 2) +
+ (candcount * maxcandsize.cy)
+ ;
+ }
+ else {
+ size.cx =
+ (listborder * 2) +
+ (listpadding * 2) +
+ ((candcount + 1) * candmargin) +
+ (candcount * candborder * 2) +
+ (candcount * candpadding * 2) +
+ ((candcount - 1) * horzcandspacing);
+ ;
+
+ for (i = 0; i < candcount; ++i)
+ size.cx += candsizes[i].cx;
+
+ size.cy =
+ (listborder * 2) +
+ (listpadding * 2) +
+ (candmargin * 2) +
+ (candborder * 2) +
+ (candpadding * 2) +
+ (maxcandsize.cy)
+ ;
+ }
+
+ StartDrawToBitmap(hdc, &hbm, size.cx, size.cy);
+
+ SelectObject(hdc, listpen);
+ SelectObject(hdc, listbrush);
+ DrawRect(hdc, 0, 0, size.cx, size.cy, listborder);
+
+ SelectObject(hdc, candpen);
+ SelectObject(hdc, candbrush);
+ SetTextColor(hdc, candtextcolor);
+ SetBkMode(hdc, TRANSPARENT);
+
+ for (i = 0; i < candcount; ++i) {
+ const WCHAR *s = videodata->ime_candidates[i];
+ int left, top, right, bottom;
+ if (!*s)
+ break;
+
+ if (vertical) {
+ left = listborder + listpadding + candmargin;
+ top = listborder + listpadding + (i * candborder * 2) + (i * candpadding * 2) + ((i + 1) * candmargin) + (i * maxcandsize.cy);
+ right = size.cx - listborder - listpadding - candmargin;
+ bottom = top + maxcandsize.cy + (candpadding * 2) + (candborder * 2);
+ }
+ else {
+ left = listborder + listpadding + (i * candborder * 2) + (i * candpadding * 2) + ((i + 1) * candmargin) + (i * horzcandspacing);
+
+ for (j = 0; j < i; ++j)
+ left += candsizes[j].cx;
+
+ top = listborder + listpadding + candmargin;
+ right = left + candsizes[i].cx + (candpadding * 2) + (candborder * 2);
+ bottom = size.cy - listborder - listpadding - candmargin;
+ }
+
+ if (i == videodata->ime_candsel) {
+ SelectObject(hdc, selpen);
+ SelectObject(hdc, selbrush);
+ SetTextColor(hdc, seltextcolor);
+ }
+ else {
+ SelectObject(hdc, candpen);
+ SelectObject(hdc, candbrush);
+ SetTextColor(hdc, candtextcolor);
+ }
+
+ DrawRect(hdc, left, top, right, bottom, candborder);
+ ExtTextOutW(hdc, left + candborder + candpadding, top + candborder + candpadding, 0, NULL, s, (int)SDL_wcslen(s), NULL);
+ }
+ StopDrawToBitmap(hdc, &hbm);
+
+ DeleteObject(listpen);
+ DeleteObject(listbrush);
+ DeleteObject(candpen);
+ DeleteObject(candbrush);
+ DeleteObject(selpen);
+ DeleteObject(selbrush);
+ DeleteObject(font);
+
+ IME_PositionCandidateList(videodata, size);
+}
+
+static void
+IME_Render(SDL_VideoData *videodata)
+{
+ HDC hdc = CreateCompatibleDC(NULL);
+
+ if (videodata->ime_candlist)
+ IME_RenderCandidateList(videodata, hdc);
+
+ DeleteDC(hdc);
+
+ videodata->ime_dirty = SDL_FALSE;
+}
+
+void IME_Present(SDL_VideoData *videodata)
+{
+ if (videodata->ime_dirty)
+ IME_Render(videodata);
+
+ /* FIXME: Need to show the IME bitmap */
+}
+
+#endif /* SDL_DISABLE_WINDOWS_IME */
+
+#endif /* SDL_VIDEO_DRIVER_WINDOWS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowskeyboard.h b/src/3rdparty/SDL2/src/video/windows/SDL_windowskeyboard.h
new file mode 100644
index 0000000..49a1b87
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowskeyboard.h
@@ -0,0 +1,40 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_windowskeyboard_h_
+#define SDL_windowskeyboard_h_
+
+extern void WIN_InitKeyboard(_THIS);
+extern void WIN_UpdateKeymap(void);
+extern void WIN_QuitKeyboard(_THIS);
+
+extern void WIN_ResetDeadKeys(void);
+
+extern void WIN_StartTextInput(_THIS);
+extern void WIN_StopTextInput(_THIS);
+extern void WIN_SetTextInputRect(_THIS, SDL_Rect *rect);
+
+extern SDL_bool IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, struct SDL_VideoData *videodata);
+
+#endif /* SDL_windowskeyboard_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsmessagebox.c b/src/3rdparty/SDL2/src/video/windows/SDL_windowsmessagebox.c
new file mode 100644
index 0000000..924b412
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsmessagebox.c
@@ -0,0 +1,496 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINDOWS
+
+#include "../../core/windows/SDL_windows.h"
+
+#include "SDL_assert.h"
+#include "SDL_windowsvideo.h"
+
+
+#ifndef SS_EDITCONTROL
+#define SS_EDITCONTROL 0x2000
+#endif
+
+/* Display a Windows message box */
+
+#pragma pack(push, 1)
+
+typedef struct
+{
+ WORD dlgVer;
+ WORD signature;
+ DWORD helpID;
+ DWORD exStyle;
+ DWORD style;
+ WORD cDlgItems;
+ short x;
+ short y;
+ short cx;
+ short cy;
+} DLGTEMPLATEEX;
+
+typedef struct
+{
+ DWORD helpID;
+ DWORD exStyle;
+ DWORD style;
+ short x;
+ short y;
+ short cx;
+ short cy;
+ DWORD id;
+} DLGITEMTEMPLATEEX;
+
+#pragma pack(pop)
+
+typedef struct
+{
+ DLGTEMPLATEEX* lpDialog;
+ Uint8 *data;
+ size_t size;
+ size_t used;
+} WIN_DialogData;
+
+
+static INT_PTR MessageBoxDialogProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
+{
+ switch ( iMessage ) {
+ case WM_COMMAND:
+ /* Return the ID of the button that was pushed */
+ EndDialog(hDlg, LOWORD(wParam));
+ return TRUE;
+
+ default:
+ break;
+ }
+ return FALSE;
+}
+
+static SDL_bool ExpandDialogSpace(WIN_DialogData *dialog, size_t space)
+{
+ size_t size = dialog->size;
+
+ if (size == 0) {
+ size = space;
+ } else {
+ while ((dialog->used + space) > size) {
+ size *= 2;
+ }
+ }
+ if (size > dialog->size) {
+ void *data = SDL_realloc(dialog->data, size);
+ if (!data) {
+ SDL_OutOfMemory();
+ return SDL_FALSE;
+ }
+ dialog->data = data;
+ dialog->size = size;
+ dialog->lpDialog = (DLGTEMPLATEEX*)dialog->data;
+ }
+ return SDL_TRUE;
+}
+
+static SDL_bool AlignDialogData(WIN_DialogData *dialog, size_t size)
+{
+ size_t padding = (dialog->used % size);
+
+ if (!ExpandDialogSpace(dialog, padding)) {
+ return SDL_FALSE;
+ }
+
+ dialog->used += padding;
+
+ return SDL_TRUE;
+}
+
+static SDL_bool AddDialogData(WIN_DialogData *dialog, const void *data, size_t size)
+{
+ if (!ExpandDialogSpace(dialog, size)) {
+ return SDL_FALSE;
+ }
+
+ SDL_memcpy(dialog->data+dialog->used, data, size);
+ dialog->used += size;
+
+ return SDL_TRUE;
+}
+
+static SDL_bool AddDialogString(WIN_DialogData *dialog, const char *string)
+{
+ WCHAR *wstring;
+ WCHAR *p;
+ size_t count;
+ SDL_bool status;
+
+ if (!string) {
+ string = "";
+ }
+
+ wstring = WIN_UTF8ToString(string);
+ if (!wstring) {
+ return SDL_FALSE;
+ }
+
+ /* Find out how many characters we have, including null terminator */
+ count = 0;
+ for (p = wstring; *p; ++p) {
+ ++count;
+ }
+ ++count;
+
+ status = AddDialogData(dialog, wstring, count*sizeof(WCHAR));
+ SDL_free(wstring);
+ return status;
+}
+
+static int s_BaseUnitsX;
+static int s_BaseUnitsY;
+static void Vec2ToDLU(short *x, short *y)
+{
+ SDL_assert(s_BaseUnitsX != 0); /* we init in WIN_ShowMessageBox(), which is the only public function... */
+
+ *x = MulDiv(*x, 4, s_BaseUnitsX);
+ *y = MulDiv(*y, 8, s_BaseUnitsY);
+}
+
+
+static SDL_bool AddDialogControl(WIN_DialogData *dialog, WORD type, DWORD style, DWORD exStyle, int x, int y, int w, int h, int id, const char *caption)
+{
+ DLGITEMTEMPLATEEX item;
+ WORD marker = 0xFFFF;
+ WORD extraData = 0;
+
+ SDL_zero(item);
+ item.style = style;
+ item.exStyle = exStyle;
+ item.x = x;
+ item.y = y;
+ item.cx = w;
+ item.cy = h;
+ item.id = id;
+
+ Vec2ToDLU(&item.x, &item.y);
+ Vec2ToDLU(&item.cx, &item.cy);
+
+ if (!AlignDialogData(dialog, sizeof(DWORD))) {
+ return SDL_FALSE;
+ }
+ if (!AddDialogData(dialog, &item, sizeof(item))) {
+ return SDL_FALSE;
+ }
+ if (!AddDialogData(dialog, &marker, sizeof(marker))) {
+ return SDL_FALSE;
+ }
+ if (!AddDialogData(dialog, &type, sizeof(type))) {
+ return SDL_FALSE;
+ }
+ if (!AddDialogString(dialog, caption)) {
+ return SDL_FALSE;
+ }
+ if (!AddDialogData(dialog, &extraData, sizeof(extraData))) {
+ return SDL_FALSE;
+ }
+ ++dialog->lpDialog->cDlgItems;
+
+ return SDL_TRUE;
+}
+
+static SDL_bool AddDialogStatic(WIN_DialogData *dialog, int x, int y, int w, int h, const char *text)
+{
+ DWORD style = WS_VISIBLE | WS_CHILD | SS_LEFT | SS_NOPREFIX | SS_EDITCONTROL;
+ return AddDialogControl(dialog, 0x0082, style, 0, x, y, w, h, -1, text);
+}
+
+static SDL_bool AddDialogButton(WIN_DialogData *dialog, int x, int y, int w, int h, const char *text, int id, SDL_bool isDefault)
+{
+ DWORD style = WS_VISIBLE | WS_CHILD;
+ if (isDefault) {
+ style |= BS_DEFPUSHBUTTON;
+ } else {
+ style |= BS_PUSHBUTTON;
+ }
+ return AddDialogControl(dialog, 0x0080, style, 0, x, y, w, h, id, text);
+}
+
+static void FreeDialogData(WIN_DialogData *dialog)
+{
+ SDL_free(dialog->data);
+ SDL_free(dialog);
+}
+
+static WIN_DialogData *CreateDialogData(int w, int h, const char *caption)
+{
+ WIN_DialogData *dialog;
+ DLGTEMPLATEEX dialogTemplate;
+ WORD WordToPass;
+
+ SDL_zero(dialogTemplate);
+ dialogTemplate.dlgVer = 1;
+ dialogTemplate.signature = 0xffff;
+ dialogTemplate.style = (WS_CAPTION | DS_CENTER | DS_SHELLFONT);
+ dialogTemplate.x = 0;
+ dialogTemplate.y = 0;
+ dialogTemplate.cx = w;
+ dialogTemplate.cy = h;
+ Vec2ToDLU(&dialogTemplate.cx, &dialogTemplate.cy);
+
+ dialog = (WIN_DialogData *)SDL_calloc(1, sizeof(*dialog));
+ if (!dialog) {
+ return NULL;
+ }
+
+ if (!AddDialogData(dialog, &dialogTemplate, sizeof(dialogTemplate))) {
+ FreeDialogData(dialog);
+ return NULL;
+ }
+
+ /* No menu */
+ WordToPass = 0;
+ if (!AddDialogData(dialog, &WordToPass, 2)) {
+ FreeDialogData(dialog);
+ return NULL;
+ }
+
+ /* No custom class */
+ if (!AddDialogData(dialog, &WordToPass, 2)) {
+ FreeDialogData(dialog);
+ return NULL;
+ }
+
+ /* title */
+ if (!AddDialogString(dialog, caption)) {
+ FreeDialogData(dialog);
+ return NULL;
+ }
+
+ /* Font stuff */
+ {
+ /*
+ * We want to use the system messagebox font.
+ */
+ BYTE ToPass;
+
+ NONCLIENTMETRICSA NCM;
+ NCM.cbSize = sizeof(NCM);
+ SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, 0, &NCM, 0);
+
+ /* Font size - convert to logical font size for dialog parameter. */
+ {
+ HDC ScreenDC = GetDC(NULL);
+ int LogicalPixelsY = GetDeviceCaps(ScreenDC, LOGPIXELSY);
+ if (!LogicalPixelsY) /* This can happen if the application runs out of GDI handles */
+ LogicalPixelsY = 72;
+ WordToPass = (WORD)(-72 * NCM.lfMessageFont.lfHeight / LogicalPixelsY);
+ ReleaseDC(NULL, ScreenDC);
+ }
+
+ if (!AddDialogData(dialog, &WordToPass, 2)) {
+ FreeDialogData(dialog);
+ return NULL;
+ }
+
+ /* Font weight */
+ WordToPass = (WORD)NCM.lfMessageFont.lfWeight;
+ if (!AddDialogData(dialog, &WordToPass, 2)) {
+ FreeDialogData(dialog);
+ return NULL;
+ }
+
+ /* italic? */
+ ToPass = NCM.lfMessageFont.lfItalic;
+ if (!AddDialogData(dialog, &ToPass, 1)) {
+ FreeDialogData(dialog);
+ return NULL;
+ }
+
+ /* charset? */
+ ToPass = NCM.lfMessageFont.lfCharSet;
+ if (!AddDialogData(dialog, &ToPass, 1)) {
+ FreeDialogData(dialog);
+ return NULL;
+ }
+
+ /* font typeface. */
+ if (!AddDialogString(dialog, NCM.lfMessageFont.lfFaceName)) {
+ FreeDialogData(dialog);
+ return NULL;
+ }
+ }
+
+ return dialog;
+}
+
+int
+WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
+{
+ WIN_DialogData *dialog;
+ int i, x, y;
+ const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
+ HFONT DialogFont;
+ SIZE Size;
+ RECT TextSize;
+ wchar_t* wmessage;
+ TEXTMETRIC TM;
+
+ HWND ParentWindow = NULL;
+
+ const int ButtonWidth = 88;
+ const int ButtonHeight = 26;
+ const int TextMargin = 16;
+ const int ButtonMargin = 12;
+
+
+ /* Jan 25th, 2013 - dant@fleetsa.com
+ *
+ *
+ * I've tried to make this more reasonable, but I've run in to a lot
+ * of nonsense.
+ *
+ * The original issue is the code was written in pixels and not
+ * dialog units (DLUs). All DialogBox functions use DLUs, which
+ * vary based on the selected font (yay).
+ *
+ * According to MSDN, the most reliable way to convert is via
+ * MapDialogUnits, which requires an HWND, which we don't have
+ * at time of template creation.
+ *
+ * We do however have:
+ * The system font (DLU width 8 for me)
+ * The font we select for the dialog (DLU width 6 for me)
+ *
+ * Based on experimentation, *neither* of these return the value
+ * actually used. Stepping in to MapDialogUnits(), the conversion
+ * is fairly clear, and uses 7 for me.
+ *
+ * As a result, some of this is hacky to ensure the sizing is
+ * somewhat correct.
+ *
+ * Honestly, a long term solution is to use CreateWindow, not CreateDialog.
+ *
+
+ *
+ * In order to get text dimensions we need to have a DC with the desired font.
+ * I'm assuming a dialog box in SDL is rare enough we can to the create.
+ */
+ HDC FontDC = CreateCompatibleDC(0);
+
+ {
+ /* Create a duplicate of the font used in system message boxes. */
+ LOGFONT lf;
+ NONCLIENTMETRICS NCM;
+ NCM.cbSize = sizeof(NCM);
+ SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &NCM, 0);
+ lf = NCM.lfMessageFont;
+ DialogFont = CreateFontIndirect(&lf);
+ }
+
+ /* Select the font in to our DC */
+ SelectObject(FontDC, DialogFont);
+
+ {
+ /* Get the metrics to try and figure our DLU conversion. */
+ GetTextMetrics(FontDC, &TM);
+
+ /* Calculation from the following documentation:
+ * https://support.microsoft.com/en-gb/help/125681/how-to-calculate-dialog-base-units-with-non-system-based-font
+ * This fixes bug 2137, dialog box calculation with a fixed-width system font
+ */
+ {
+ SIZE extent;
+ GetTextExtentPoint32A(FontDC, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 52, &extent);
+ s_BaseUnitsX = (extent.cx / 26 + 1) / 2;
+ }
+ /*s_BaseUnitsX = TM.tmAveCharWidth + 1;*/
+ s_BaseUnitsY = TM.tmHeight;
+ }
+
+ /* Measure the *pixel* size of the string. */
+ wmessage = WIN_UTF8ToString(messageboxdata->message);
+ SDL_zero(TextSize);
+ DrawText(FontDC, wmessage, -1, &TextSize, DT_CALCRECT);
+
+ /* Add some padding for hangs, etc. */
+ TextSize.right += 2;
+ TextSize.bottom += 2;
+
+ /* Done with the DC, and the string */
+ DeleteDC(FontDC);
+ SDL_free(wmessage);
+
+ /* Increase the size of the dialog by some border spacing around the text. */
+ Size.cx = TextSize.right - TextSize.left;
+ Size.cy = TextSize.bottom - TextSize.top;
+ Size.cx += TextMargin * 2;
+ Size.cy += TextMargin * 2;
+
+ /* Ensure the size is wide enough for all of the buttons. */
+ if (Size.cx < messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin)
+ Size.cx = messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin;
+
+ /* Add vertical space for the buttons and border. */
+ Size.cy += ButtonHeight + TextMargin;
+
+ dialog = CreateDialogData(Size.cx, Size.cy, messageboxdata->title);
+ if (!dialog) {
+ return -1;
+ }
+
+ if (!AddDialogStatic(dialog, TextMargin, TextMargin, TextSize.right - TextSize.left, TextSize.bottom - TextSize.top, messageboxdata->message)) {
+ FreeDialogData(dialog);
+ return -1;
+ }
+
+ /* Align the buttons to the right/bottom. */
+ x = Size.cx - (ButtonWidth + ButtonMargin) * messageboxdata->numbuttons;
+ y = Size.cy - ButtonHeight - ButtonMargin;
+ for (i = messageboxdata->numbuttons - 1; i >= 0; --i) {
+ SDL_bool isDefault;
+
+ if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
+ isDefault = SDL_TRUE;
+ } else {
+ isDefault = SDL_FALSE;
+ }
+ if (!AddDialogButton(dialog, x, y, ButtonWidth, ButtonHeight, buttons[i].text, buttons[i].buttonid, isDefault)) {
+ FreeDialogData(dialog);
+ return -1;
+ }
+ x += ButtonWidth + ButtonMargin;
+ }
+
+ /* If we have a parent window, get the Instance and HWND for them
+ * so that our little dialog gets exclusive focus at all times. */
+ if (messageboxdata->window) {
+ ParentWindow = ((SDL_WindowData*)messageboxdata->window->driverdata)->hwnd;
+ }
+
+ *buttonid = (int)DialogBoxIndirect(NULL, (DLGTEMPLATE*)dialog->lpDialog, ParentWindow, (DLGPROC)MessageBoxDialogProc);
+
+ FreeDialogData(dialog);
+ return 0;
+}
+
+#endif /* SDL_VIDEO_DRIVER_WINDOWS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsmessagebox.h b/src/3rdparty/SDL2/src/video/windows/SDL_windowsmessagebox.h
new file mode 100644
index 0000000..2cb29be
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsmessagebox.h
@@ -0,0 +1,29 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINDOWS
+
+extern int WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
+
+#endif /* SDL_VIDEO_DRIVER_WINDOWS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsmodes.c b/src/3rdparty/SDL2/src/video/windows/SDL_windowsmodes.c
new file mode 100644
index 0000000..7425d9a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsmodes.c
@@ -0,0 +1,407 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINDOWS
+
+#include "SDL_windowsvideo.h"
+#include "../../../include/SDL_assert.h"
+#include "../../../include/SDL_log.h"
+
+/* Windows CE compatibility */
+#ifndef CDS_FULLSCREEN
+#define CDS_FULLSCREEN 0
+#endif
+
+/* #define DEBUG_MODES */
+
+static void
+WIN_UpdateDisplayMode(_THIS, LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
+{
+ SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
+ HDC hdc;
+
+ data->DeviceMode.dmFields =
+ (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY |
+ DM_DISPLAYFLAGS);
+
+ if (index == ENUM_CURRENT_SETTINGS
+ && (hdc = CreateDC(deviceName, NULL, NULL, NULL)) != NULL) {
+ char bmi_data[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
+ LPBITMAPINFO bmi;
+ HBITMAP hbm;
+ int logical_width = GetDeviceCaps( hdc, HORZRES );
+ int logical_height = GetDeviceCaps( hdc, VERTRES );
+
+ mode->w = logical_width;
+ mode->h = logical_height;
+
+ SDL_zero(bmi_data);
+ bmi = (LPBITMAPINFO) bmi_data;
+ bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+
+ hbm = CreateCompatibleBitmap(hdc, 1, 1);
+ GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
+ GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
+ DeleteObject(hbm);
+ DeleteDC(hdc);
+ if (bmi->bmiHeader.biCompression == BI_BITFIELDS) {
+ switch (*(Uint32 *) bmi->bmiColors) {
+ case 0x00FF0000:
+ mode->format = SDL_PIXELFORMAT_RGB888;
+ break;
+ case 0x000000FF:
+ mode->format = SDL_PIXELFORMAT_BGR888;
+ break;
+ case 0xF800:
+ mode->format = SDL_PIXELFORMAT_RGB565;
+ break;
+ case 0x7C00:
+ mode->format = SDL_PIXELFORMAT_RGB555;
+ break;
+ }
+ } else if (bmi->bmiHeader.biBitCount == 8) {
+ mode->format = SDL_PIXELFORMAT_INDEX8;
+ } else if (bmi->bmiHeader.biBitCount == 4) {
+ mode->format = SDL_PIXELFORMAT_INDEX4LSB;
+ }
+ } else if (mode->format == SDL_PIXELFORMAT_UNKNOWN) {
+ /* FIXME: Can we tell what this will be? */
+ if ((data->DeviceMode.dmFields & DM_BITSPERPEL) == DM_BITSPERPEL) {
+ switch (data->DeviceMode.dmBitsPerPel) {
+ case 32:
+ mode->format = SDL_PIXELFORMAT_RGB888;
+ break;
+ case 24:
+ mode->format = SDL_PIXELFORMAT_RGB24;
+ break;
+ case 16:
+ mode->format = SDL_PIXELFORMAT_RGB565;
+ break;
+ case 15:
+ mode->format = SDL_PIXELFORMAT_RGB555;
+ break;
+ case 8:
+ mode->format = SDL_PIXELFORMAT_INDEX8;
+ break;
+ case 4:
+ mode->format = SDL_PIXELFORMAT_INDEX4LSB;
+ break;
+ }
+ }
+ }
+}
+
+static SDL_bool
+WIN_GetDisplayMode(_THIS, LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
+{
+ SDL_DisplayModeData *data;
+ DEVMODE devmode;
+
+ devmode.dmSize = sizeof(devmode);
+ devmode.dmDriverExtra = 0;
+ if (!EnumDisplaySettings(deviceName, index, &devmode)) {
+ return SDL_FALSE;
+ }
+
+ data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
+ if (!data) {
+ return SDL_FALSE;
+ }
+
+ mode->driverdata = data;
+ data->DeviceMode = devmode;
+
+ mode->format = SDL_PIXELFORMAT_UNKNOWN;
+ mode->w = data->DeviceMode.dmPelsWidth;
+ mode->h = data->DeviceMode.dmPelsHeight;
+ mode->refresh_rate = data->DeviceMode.dmDisplayFrequency;
+
+ /* Fill in the mode information */
+ WIN_UpdateDisplayMode(_this, deviceName, index, mode);
+ return SDL_TRUE;
+}
+
+static SDL_bool
+WIN_AddDisplay(_THIS, HMONITOR hMonitor, const MONITORINFOEX *info)
+{
+ SDL_VideoDisplay display;
+ SDL_DisplayData *displaydata;
+ SDL_DisplayMode mode;
+ DISPLAY_DEVICE device;
+
+#ifdef DEBUG_MODES
+ SDL_Log("Display: %s\n", WIN_StringToUTF8(info->szDevice));
+#endif
+
+ if (!WIN_GetDisplayMode(_this, info->szDevice, ENUM_CURRENT_SETTINGS, &mode)) {
+ return SDL_FALSE;
+ }
+
+ displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata));
+ if (!displaydata) {
+ return SDL_FALSE;
+ }
+ SDL_memcpy(displaydata->DeviceName, info->szDevice,
+ sizeof(displaydata->DeviceName));
+ displaydata->MonitorHandle = hMonitor;
+
+ SDL_zero(display);
+ device.cb = sizeof(device);
+ if (EnumDisplayDevices(info->szDevice, 0, &device, 0)) {
+ display.name = WIN_StringToUTF8(device.DeviceString);
+ }
+ display.desktop_mode = mode;
+ display.current_mode = mode;
+ display.driverdata = displaydata;
+ SDL_AddVideoDisplay(&display);
+ SDL_free(display.name);
+ return SDL_TRUE;
+}
+
+typedef struct _WIN_AddDisplaysData {
+ SDL_VideoDevice *video_device;
+ SDL_bool want_primary;
+} WIN_AddDisplaysData;
+
+static BOOL CALLBACK
+WIN_AddDisplaysCallback(HMONITOR hMonitor,
+ HDC hdcMonitor,
+ LPRECT lprcMonitor,
+ LPARAM dwData)
+{
+ WIN_AddDisplaysData *data = (WIN_AddDisplaysData*)dwData;
+ MONITORINFOEX info;
+
+ SDL_zero(info);
+ info.cbSize = sizeof(info);
+
+ if (GetMonitorInfo(hMonitor, (LPMONITORINFO)&info) != 0) {
+ const SDL_bool is_primary = ((info.dwFlags & MONITORINFOF_PRIMARY) == MONITORINFOF_PRIMARY);
+
+ if (is_primary == data->want_primary) {
+ WIN_AddDisplay(data->video_device, hMonitor, &info);
+ }
+ }
+
+ // continue enumeration
+ return TRUE;
+}
+
+static void
+WIN_AddDisplays(_THIS)
+{
+ WIN_AddDisplaysData callback_data;
+ callback_data.video_device = _this;
+
+ callback_data.want_primary = SDL_TRUE;
+ EnumDisplayMonitors(NULL, NULL, WIN_AddDisplaysCallback, (LPARAM)&callback_data);
+
+ callback_data.want_primary = SDL_FALSE;
+ EnumDisplayMonitors(NULL, NULL, WIN_AddDisplaysCallback, (LPARAM)&callback_data);
+}
+
+int
+WIN_InitModes(_THIS)
+{
+ WIN_AddDisplays(_this);
+
+ if (_this->num_displays == 0) {
+ return SDL_SetError("No displays available");
+ }
+ return 0;
+}
+
+int
+WIN_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
+{
+ const SDL_DisplayData *data = (const SDL_DisplayData *)display->driverdata;
+ MONITORINFO minfo;
+ BOOL rc;
+
+ SDL_zero(minfo);
+ minfo.cbSize = sizeof(MONITORINFO);
+ rc = GetMonitorInfo(data->MonitorHandle, &minfo);
+
+ if (!rc) {
+ return SDL_SetError("Couldn't find monitor data");
+ }
+
+ rect->x = minfo.rcMonitor.left;
+ rect->y = minfo.rcMonitor.top;
+ rect->w = minfo.rcMonitor.right - minfo.rcMonitor.left;
+ rect->h = minfo.rcMonitor.bottom - minfo.rcMonitor.top;
+
+ return 0;
+}
+
+int
+WIN_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi_out, float * hdpi_out, float * vdpi_out)
+{
+ const SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
+ const SDL_VideoData *videodata = (SDL_VideoData *)display->device->driverdata;
+ float hdpi = 0, vdpi = 0, ddpi = 0;
+
+ if (videodata->GetDpiForMonitor) {
+ UINT hdpi_uint, vdpi_uint;
+ // Windows 8.1+ codepath
+ if (videodata->GetDpiForMonitor(displaydata->MonitorHandle, MDT_EFFECTIVE_DPI, &hdpi_uint, &vdpi_uint) == S_OK) {
+ // GetDpiForMonitor docs promise to return the same hdpi/vdpi
+ hdpi = (float)hdpi_uint;
+ vdpi = (float)hdpi_uint;
+ ddpi = (float)hdpi_uint;
+ } else {
+ return SDL_SetError("GetDpiForMonitor failed");
+ }
+ } else {
+ // Window 8.0 and below: same DPI for all monitors.
+ HDC hdc;
+ int hdpi_int, vdpi_int, hpoints, vpoints, hpix, vpix;
+ float hinches, vinches;
+
+ hdc = GetDC(NULL);
+ if (hdc == NULL) {
+ return SDL_SetError("GetDC failed");
+ }
+ hdpi_int = GetDeviceCaps(hdc, LOGPIXELSX);
+ vdpi_int = GetDeviceCaps(hdc, LOGPIXELSY);
+ ReleaseDC(NULL, hdc);
+
+ hpoints = GetSystemMetrics(SM_CXVIRTUALSCREEN);
+ vpoints = GetSystemMetrics(SM_CYVIRTUALSCREEN);
+
+ hpix = MulDiv(hpoints, hdpi_int, 96);
+ vpix = MulDiv(vpoints, vdpi_int, 96);
+
+ hinches = (float)hpoints / 96.0f;
+ vinches = (float)vpoints / 96.0f;
+
+ hdpi = (float)hdpi_int;
+ vdpi = (float)vdpi_int;
+ ddpi = SDL_ComputeDiagonalDPI(hpix, vpix, hinches, vinches);
+ }
+
+ if (ddpi_out) {
+ *ddpi_out = ddpi;
+ }
+ if (hdpi_out) {
+ *hdpi_out = hdpi;
+ }
+ if (vdpi_out) {
+ *vdpi_out = vdpi;
+ }
+
+ return ddpi != 0.0f ? 0 : SDL_SetError("Couldn't get DPI");
+}
+
+int
+WIN_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
+{
+ const SDL_DisplayData *data = (const SDL_DisplayData *)display->driverdata;
+ MONITORINFO minfo;
+ BOOL rc;
+
+ SDL_zero(minfo);
+ minfo.cbSize = sizeof(MONITORINFO);
+ rc = GetMonitorInfo(data->MonitorHandle, &minfo);
+
+ if (!rc) {
+ return SDL_SetError("Couldn't find monitor data");
+ }
+
+ rect->x = minfo.rcWork.left;
+ rect->y = minfo.rcWork.top;
+ rect->w = minfo.rcWork.right - minfo.rcWork.left;
+ rect->h = minfo.rcWork.bottom - minfo.rcWork.top;
+
+ return 0;
+}
+
+void
+WIN_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
+{
+ SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
+ DWORD i;
+ SDL_DisplayMode mode;
+
+ for (i = 0;; ++i) {
+ if (!WIN_GetDisplayMode(_this, data->DeviceName, i, &mode)) {
+ break;
+ }
+ if (SDL_ISPIXELFORMAT_INDEXED(mode.format)) {
+ /* We don't support palettized modes now */
+ SDL_free(mode.driverdata);
+ continue;
+ }
+ if (mode.format != SDL_PIXELFORMAT_UNKNOWN) {
+ if (!SDL_AddDisplayMode(display, &mode)) {
+ SDL_free(mode.driverdata);
+ }
+ } else {
+ SDL_free(mode.driverdata);
+ }
+ }
+}
+
+int
+WIN_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
+{
+ SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
+ SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
+ LONG status;
+
+ if (mode->driverdata == display->desktop_mode.driverdata) {
+ status = ChangeDisplaySettingsEx(displaydata->DeviceName, NULL, NULL, CDS_FULLSCREEN, NULL);
+ } else {
+ status = ChangeDisplaySettingsEx(displaydata->DeviceName, &data->DeviceMode, NULL, CDS_FULLSCREEN, NULL);
+ }
+ if (status != DISP_CHANGE_SUCCESSFUL) {
+ const char *reason = "Unknown reason";
+ switch (status) {
+ case DISP_CHANGE_BADFLAGS:
+ reason = "DISP_CHANGE_BADFLAGS";
+ break;
+ case DISP_CHANGE_BADMODE:
+ reason = "DISP_CHANGE_BADMODE";
+ break;
+ case DISP_CHANGE_BADPARAM:
+ reason = "DISP_CHANGE_BADPARAM";
+ break;
+ case DISP_CHANGE_FAILED:
+ reason = "DISP_CHANGE_FAILED";
+ break;
+ }
+ return SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason);
+ }
+ EnumDisplaySettings(displaydata->DeviceName, ENUM_CURRENT_SETTINGS, &data->DeviceMode);
+ WIN_UpdateDisplayMode(_this, displaydata->DeviceName, ENUM_CURRENT_SETTINGS, mode);
+ return 0;
+}
+
+void
+WIN_QuitModes(_THIS)
+{
+ /* All fullscreen windows should have restored modes by now */
+}
+
+#endif /* SDL_VIDEO_DRIVER_WINDOWS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsmodes.h b/src/3rdparty/SDL2/src/video/windows/SDL_windowsmodes.h
new file mode 100644
index 0000000..a5c19b7
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsmodes.h
@@ -0,0 +1,47 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_windowsmodes_h_
+#define SDL_windowsmodes_h_
+
+typedef struct
+{
+ TCHAR DeviceName[32];
+ HMONITOR MonitorHandle;
+} SDL_DisplayData;
+
+typedef struct
+{
+ DEVMODE DeviceMode;
+} SDL_DisplayModeData;
+
+extern int WIN_InitModes(_THIS);
+extern int WIN_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
+extern int WIN_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
+extern int WIN_GetDisplayDPI(_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi);
+extern void WIN_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
+extern int WIN_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
+extern void WIN_QuitModes(_THIS);
+
+#endif /* SDL_windowsmodes_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsmouse.c b/src/3rdparty/SDL2/src/video/windows/SDL_windowsmouse.c
new file mode 100644
index 0000000..1ddeae2
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsmouse.c
@@ -0,0 +1,322 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINDOWS
+
+#include "SDL_assert.h"
+#include "SDL_windowsvideo.h"
+
+#include "../../events/SDL_mouse_c.h"
+
+
+HCURSOR SDL_cursor = NULL;
+
+static int rawInputEnableCount = 0;
+
+static int
+ToggleRawInput(SDL_bool enabled)
+{
+ RAWINPUTDEVICE rawMouse = { 0x01, 0x02, 0, NULL }; /* Mouse: UsagePage = 1, Usage = 2 */
+
+ if (enabled) {
+ rawInputEnableCount++;
+ if (rawInputEnableCount > 1) {
+ return 0; /* already done. */
+ }
+ } else {
+ if (rawInputEnableCount == 0) {
+ return 0; /* already done. */
+ }
+ rawInputEnableCount--;
+ if (rawInputEnableCount > 0) {
+ return 0; /* not time to disable yet */
+ }
+ }
+
+ if (!enabled) {
+ rawMouse.dwFlags |= RIDEV_REMOVE;
+ }
+
+ /* (Un)register raw input for mice */
+ if (RegisterRawInputDevices(&rawMouse, 1, sizeof(RAWINPUTDEVICE)) == FALSE) {
+
+ /* Only return an error when registering. If we unregister and fail,
+ then it's probably that we unregistered twice. That's OK. */
+ if (enabled) {
+ return SDL_Unsupported();
+ }
+ }
+ return 0;
+}
+
+
+static SDL_Cursor *
+WIN_CreateDefaultCursor()
+{
+ SDL_Cursor *cursor;
+
+ cursor = SDL_calloc(1, sizeof(*cursor));
+ if (cursor) {
+ cursor->driverdata = LoadCursor(NULL, IDC_ARROW);
+ } else {
+ SDL_OutOfMemory();
+ }
+
+ return cursor;
+}
+
+static SDL_Cursor *
+WIN_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
+{
+ /* msdn says cursor mask has to be padded out to word alignment. Not sure
+ if that means machine word or WORD, but this handles either case. */
+ const size_t pad = (sizeof (size_t) * 8); /* 32 or 64, or whatever. */
+ SDL_Cursor *cursor;
+ HICON hicon;
+ HDC hdc;
+ BITMAPV4HEADER bmh;
+ LPVOID pixels;
+ LPVOID maskbits;
+ size_t maskbitslen;
+ ICONINFO ii;
+
+ SDL_zero(bmh);
+ bmh.bV4Size = sizeof(bmh);
+ bmh.bV4Width = surface->w;
+ bmh.bV4Height = -surface->h; /* Invert the image */
+ bmh.bV4Planes = 1;
+ bmh.bV4BitCount = 32;
+ bmh.bV4V4Compression = BI_BITFIELDS;
+ bmh.bV4AlphaMask = 0xFF000000;
+ bmh.bV4RedMask = 0x00FF0000;
+ bmh.bV4GreenMask = 0x0000FF00;
+ bmh.bV4BlueMask = 0x000000FF;
+
+ maskbitslen = ((surface->w + (pad - (surface->w % pad))) / 8) * surface->h;
+ maskbits = SDL_stack_alloc(Uint8,maskbitslen);
+ if (maskbits == NULL) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ /* AND the cursor against full bits: no change. We already have alpha. */
+ SDL_memset(maskbits, 0xFF, maskbitslen);
+
+ hdc = GetDC(NULL);
+ SDL_zero(ii);
+ ii.fIcon = FALSE;
+ ii.xHotspot = (DWORD)hot_x;
+ ii.yHotspot = (DWORD)hot_y;
+ ii.hbmColor = CreateDIBSection(hdc, (BITMAPINFO*)&bmh, DIB_RGB_COLORS, &pixels, NULL, 0);
+ ii.hbmMask = CreateBitmap(surface->w, surface->h, 1, 1, maskbits);
+ ReleaseDC(NULL, hdc);
+ SDL_stack_free(maskbits);
+
+ SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
+ SDL_assert(surface->pitch == surface->w * 4);
+ SDL_memcpy(pixels, surface->pixels, surface->h * surface->pitch);
+
+ hicon = CreateIconIndirect(&ii);
+
+ DeleteObject(ii.hbmColor);
+ DeleteObject(ii.hbmMask);
+
+ if (!hicon) {
+ WIN_SetError("CreateIconIndirect()");
+ return NULL;
+ }
+
+ cursor = SDL_calloc(1, sizeof(*cursor));
+ if (cursor) {
+ cursor->driverdata = hicon;
+ } else {
+ DestroyIcon(hicon);
+ SDL_OutOfMemory();
+ }
+
+ return cursor;
+}
+
+static SDL_Cursor *
+WIN_CreateSystemCursor(SDL_SystemCursor id)
+{
+ SDL_Cursor *cursor;
+ LPCTSTR name;
+
+ switch(id)
+ {
+ default:
+ SDL_assert(0);
+ return NULL;
+ case SDL_SYSTEM_CURSOR_ARROW: name = IDC_ARROW; break;
+ case SDL_SYSTEM_CURSOR_IBEAM: name = IDC_IBEAM; break;
+ case SDL_SYSTEM_CURSOR_WAIT: name = IDC_WAIT; break;
+ case SDL_SYSTEM_CURSOR_CROSSHAIR: name = IDC_CROSS; break;
+ case SDL_SYSTEM_CURSOR_WAITARROW: name = IDC_WAIT; break;
+ case SDL_SYSTEM_CURSOR_SIZENWSE: name = IDC_SIZENWSE; break;
+ case SDL_SYSTEM_CURSOR_SIZENESW: name = IDC_SIZENESW; break;
+ case SDL_SYSTEM_CURSOR_SIZEWE: name = IDC_SIZEWE; break;
+ case SDL_SYSTEM_CURSOR_SIZENS: name = IDC_SIZENS; break;
+ case SDL_SYSTEM_CURSOR_SIZEALL: name = IDC_SIZEALL; break;
+ case SDL_SYSTEM_CURSOR_NO: name = IDC_NO; break;
+ case SDL_SYSTEM_CURSOR_HAND: name = IDC_HAND; break;
+ }
+
+ cursor = SDL_calloc(1, sizeof(*cursor));
+ if (cursor) {
+ HICON hicon;
+
+ hicon = LoadCursor(NULL, name);
+
+ cursor->driverdata = hicon;
+ } else {
+ SDL_OutOfMemory();
+ }
+
+ return cursor;
+}
+
+static void
+WIN_FreeCursor(SDL_Cursor * cursor)
+{
+ HICON hicon = (HICON)cursor->driverdata;
+
+ DestroyIcon(hicon);
+ SDL_free(cursor);
+}
+
+static int
+WIN_ShowCursor(SDL_Cursor * cursor)
+{
+ if (cursor) {
+ SDL_cursor = (HCURSOR)cursor->driverdata;
+ } else {
+ SDL_cursor = NULL;
+ }
+ if (SDL_GetMouseFocus() != NULL) {
+ SetCursor(SDL_cursor);
+ }
+ return 0;
+}
+
+static void
+WIN_WarpMouse(SDL_Window * window, int x, int y)
+{
+ SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+ HWND hwnd = data->hwnd;
+ POINT pt;
+
+ /* Don't warp the mouse while we're doing a modal interaction */
+ if (data->in_title_click || data->focus_click_pending) {
+ return;
+ }
+
+ pt.x = x;
+ pt.y = y;
+ ClientToScreen(hwnd, &pt);
+ SetCursorPos(pt.x, pt.y);
+}
+
+static int
+WIN_WarpMouseGlobal(int x, int y)
+{
+ POINT pt;
+
+ pt.x = x;
+ pt.y = y;
+ SetCursorPos(pt.x, pt.y);
+ return 0;
+}
+
+static int
+WIN_SetRelativeMouseMode(SDL_bool enabled)
+{
+ return ToggleRawInput(enabled);
+}
+
+static int
+WIN_CaptureMouse(SDL_Window *window)
+{
+ if (!window) {
+ SDL_Window *focusWin = SDL_GetKeyboardFocus();
+ if (focusWin) {
+ WIN_OnWindowEnter(SDL_GetVideoDevice(), focusWin); /* make sure WM_MOUSELEAVE messages are (re)enabled. */
+ }
+ }
+
+ /* While we were thinking of SetCapture() when designing this API in SDL,
+ we didn't count on the fact that SetCapture() only tracks while the
+ left mouse button is held down! Instead, we listen for raw mouse input
+ and manually query the mouse when it leaves the window. :/ */
+ return ToggleRawInput(window != NULL);
+}
+
+static Uint32
+WIN_GetGlobalMouseState(int *x, int *y)
+{
+ Uint32 retval = 0;
+ POINT pt = { 0, 0 };
+ GetCursorPos(&pt);
+ *x = (int) pt.x;
+ *y = (int) pt.y;
+
+ retval |= GetAsyncKeyState(VK_LBUTTON) & 0x8000 ? SDL_BUTTON_LMASK : 0;
+ retval |= GetAsyncKeyState(VK_RBUTTON) & 0x8000 ? SDL_BUTTON_RMASK : 0;
+ retval |= GetAsyncKeyState(VK_MBUTTON) & 0x8000 ? SDL_BUTTON_MMASK : 0;
+ retval |= GetAsyncKeyState(VK_XBUTTON1) & 0x8000 ? SDL_BUTTON_X1MASK : 0;
+ retval |= GetAsyncKeyState(VK_XBUTTON2) & 0x8000 ? SDL_BUTTON_X2MASK : 0;
+
+ return retval;
+}
+
+void
+WIN_InitMouse(_THIS)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ mouse->CreateCursor = WIN_CreateCursor;
+ mouse->CreateSystemCursor = WIN_CreateSystemCursor;
+ mouse->ShowCursor = WIN_ShowCursor;
+ mouse->FreeCursor = WIN_FreeCursor;
+ mouse->WarpMouse = WIN_WarpMouse;
+ mouse->WarpMouseGlobal = WIN_WarpMouseGlobal;
+ mouse->SetRelativeMouseMode = WIN_SetRelativeMouseMode;
+ mouse->CaptureMouse = WIN_CaptureMouse;
+ mouse->GetGlobalMouseState = WIN_GetGlobalMouseState;
+
+ SDL_SetDefaultCursor(WIN_CreateDefaultCursor());
+
+ SDL_SetDoubleClickTime(GetDoubleClickTime());
+}
+
+void
+WIN_QuitMouse(_THIS)
+{
+ if (rawInputEnableCount) { /* force RAWINPUT off here. */
+ rawInputEnableCount = 1;
+ ToggleRawInput(SDL_FALSE);
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_WINDOWS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsmouse.h b/src/3rdparty/SDL2/src/video/windows/SDL_windowsmouse.h
new file mode 100644
index 0000000..775c32c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsmouse.h
@@ -0,0 +1,33 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_windowsmouse_h_
+#define SDL_windowsmouse_h_
+
+extern HCURSOR SDL_cursor;
+
+extern void WIN_InitMouse(_THIS);
+extern void WIN_QuitMouse(_THIS);
+
+#endif /* SDL_windowsmouse_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsopengl.c b/src/3rdparty/SDL2/src/video/windows/SDL_windowsopengl.c
new file mode 100644
index 0000000..c3ba56c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsopengl.c
@@ -0,0 +1,895 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINDOWS
+
+#include "SDL_assert.h"
+#include "SDL_loadso.h"
+#include "SDL_windowsvideo.h"
+#include "SDL_windowsopengles.h"
+#include "SDL_hints.h"
+
+/* WGL implementation of SDL OpenGL support */
+
+#if SDL_VIDEO_OPENGL_WGL
+#include "SDL_opengl.h"
+
+#define DEFAULT_OPENGL "OPENGL32.DLL"
+
+#ifndef WGL_ARB_create_context
+#define WGL_ARB_create_context
+#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
+#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
+#define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
+#define WGL_CONTEXT_FLAGS_ARB 0x2094
+#define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
+#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
+
+#ifndef WGL_ARB_create_context_profile
+#define WGL_ARB_create_context_profile
+#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
+#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
+#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
+#endif
+
+#ifndef WGL_ARB_create_context_robustness
+#define WGL_ARB_create_context_robustness
+#define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004
+#define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
+#define WGL_NO_RESET_NOTIFICATION_ARB 0x8261
+#define WGL_LOSE_CONTEXT_ON_RESET_ARB 0x8252
+#endif
+#endif
+
+#ifndef WGL_EXT_create_context_es2_profile
+#define WGL_EXT_create_context_es2_profile
+#define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004
+#endif
+
+#ifndef WGL_EXT_create_context_es_profile
+#define WGL_EXT_create_context_es_profile
+#define WGL_CONTEXT_ES_PROFILE_BIT_EXT 0x00000004
+#endif
+
+#ifndef WGL_ARB_framebuffer_sRGB
+#define WGL_ARB_framebuffer_sRGB
+#define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20A9
+#endif
+
+#ifndef WGL_ARB_context_flush_control
+#define WGL_ARB_context_flush_control
+#define WGL_CONTEXT_RELEASE_BEHAVIOR_ARB 0x2097
+#define WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB 0x0000
+#define WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098
+#endif
+
+#ifndef WGL_ARB_create_context_no_error
+#define WGL_ARB_create_context_no_error
+#define WGL_CONTEXT_OPENGL_NO_ERROR_ARB 0x31B3
+#endif
+
+typedef HGLRC(APIENTRYP PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC,
+ HGLRC
+ hShareContext,
+ const int
+ *attribList);
+
+int
+WIN_GL_LoadLibrary(_THIS, const char *path)
+{
+ void *handle;
+
+ if (path == NULL) {
+ path = SDL_getenv("SDL_OPENGL_LIBRARY");
+ }
+ if (path == NULL) {
+ path = DEFAULT_OPENGL;
+ }
+ _this->gl_config.dll_handle = SDL_LoadObject(path);
+ if (!_this->gl_config.dll_handle) {
+ return -1;
+ }
+ SDL_strlcpy(_this->gl_config.driver_path, path,
+ SDL_arraysize(_this->gl_config.driver_path));
+
+ /* Allocate OpenGL memory */
+ _this->gl_data = (struct SDL_GLDriverData *) SDL_calloc(1, sizeof(struct SDL_GLDriverData));
+ if (!_this->gl_data) {
+ return SDL_OutOfMemory();
+ }
+
+ /* Load function pointers */
+ handle = _this->gl_config.dll_handle;
+ _this->gl_data->wglGetProcAddress = (void *(WINAPI *) (const char *))
+ SDL_LoadFunction(handle, "wglGetProcAddress");
+ _this->gl_data->wglCreateContext = (HGLRC(WINAPI *) (HDC))
+ SDL_LoadFunction(handle, "wglCreateContext");
+ _this->gl_data->wglDeleteContext = (BOOL(WINAPI *) (HGLRC))
+ SDL_LoadFunction(handle, "wglDeleteContext");
+ _this->gl_data->wglMakeCurrent = (BOOL(WINAPI *) (HDC, HGLRC))
+ SDL_LoadFunction(handle, "wglMakeCurrent");
+ _this->gl_data->wglShareLists = (BOOL(WINAPI *) (HGLRC, HGLRC))
+ SDL_LoadFunction(handle, "wglShareLists");
+
+ if (!_this->gl_data->wglGetProcAddress ||
+ !_this->gl_data->wglCreateContext ||
+ !_this->gl_data->wglDeleteContext ||
+ !_this->gl_data->wglMakeCurrent) {
+ return SDL_SetError("Could not retrieve OpenGL functions");
+ }
+
+ /* XXX Too sleazy? WIN_GL_InitExtensions looks for certain OpenGL
+ extensions via SDL_GL_DeduceMaxSupportedESProfile. This uses
+ SDL_GL_ExtensionSupported which in turn calls SDL_GL_GetProcAddress.
+ However SDL_GL_GetProcAddress will fail if the library is not
+ loaded; it checks for gl_config.driver_loaded > 0. To avoid this
+ test failing, increment driver_loaded around the call to
+ WIN_GLInitExtensions.
+
+ Successful loading of the library is normally indicated by
+ SDL_GL_LoadLibrary incrementing driver_loaded immediately after
+ this function returns 0 to it.
+
+ Alternatives to this are:
+ - moving SDL_GL_DeduceMaxSupportedESProfile to both the WIN and
+ X11 platforms while adding a function equivalent to
+ SDL_GL_ExtensionSupported but which directly calls
+ glGetProcAddress(). Having 3 copies of the
+ SDL_GL_ExtensionSupported makes this alternative unattractive.
+ - moving SDL_GL_DeduceMaxSupportedESProfile to a new file shared
+ by the WIN and X11 platforms while adding a function equivalent
+ to SDL_GL_ExtensionSupported. This is unattractive due to the
+ number of project files that will need updating, plus there
+ will be 2 copies of the SDL_GL_ExtensionSupported code.
+ - Add a private equivalent of SDL_GL_ExtensionSupported to
+ SDL_video.c.
+ - Move the call to WIN_GL_InitExtensions back to WIN_CreateWindow
+ and add a flag to gl_data to avoid multiple calls to this
+ expensive function. This is probably the least objectionable
+ alternative if this increment/decrement trick is unacceptable.
+
+ Note that the driver_loaded > 0 check needs to remain in
+ SDL_GL_ExtensionSupported and SDL_GL_GetProcAddress as they are
+ public API functions.
+ */
+ ++_this->gl_config.driver_loaded;
+ WIN_GL_InitExtensions(_this);
+ --_this->gl_config.driver_loaded;
+
+ return 0;
+}
+
+void *
+WIN_GL_GetProcAddress(_THIS, const char *proc)
+{
+ void *func;
+
+ /* This is to pick up extensions */
+ func = _this->gl_data->wglGetProcAddress(proc);
+ if (!func) {
+ /* This is probably a normal GL function */
+ func = GetProcAddress(_this->gl_config.dll_handle, proc);
+ }
+ return func;
+}
+
+void
+WIN_GL_UnloadLibrary(_THIS)
+{
+ SDL_UnloadObject(_this->gl_config.dll_handle);
+ _this->gl_config.dll_handle = NULL;
+
+ /* Free OpenGL memory */
+ SDL_free(_this->gl_data);
+ _this->gl_data = NULL;
+}
+
+static void
+WIN_GL_SetupPixelFormat(_THIS, PIXELFORMATDESCRIPTOR * pfd)
+{
+ SDL_zerop(pfd);
+ pfd->nSize = sizeof(*pfd);
+ pfd->nVersion = 1;
+ pfd->dwFlags = (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL);
+ if (_this->gl_config.double_buffer) {
+ pfd->dwFlags |= PFD_DOUBLEBUFFER;
+ }
+ if (_this->gl_config.stereo) {
+ pfd->dwFlags |= PFD_STEREO;
+ }
+ pfd->iLayerType = PFD_MAIN_PLANE;
+ pfd->iPixelType = PFD_TYPE_RGBA;
+ pfd->cRedBits = _this->gl_config.red_size;
+ pfd->cGreenBits = _this->gl_config.green_size;
+ pfd->cBlueBits = _this->gl_config.blue_size;
+ pfd->cAlphaBits = _this->gl_config.alpha_size;
+ if (_this->gl_config.buffer_size) {
+ pfd->cColorBits =
+ _this->gl_config.buffer_size - _this->gl_config.alpha_size;
+ } else {
+ pfd->cColorBits = (pfd->cRedBits + pfd->cGreenBits + pfd->cBlueBits);
+ }
+ pfd->cAccumRedBits = _this->gl_config.accum_red_size;
+ pfd->cAccumGreenBits = _this->gl_config.accum_green_size;
+ pfd->cAccumBlueBits = _this->gl_config.accum_blue_size;
+ pfd->cAccumAlphaBits = _this->gl_config.accum_alpha_size;
+ pfd->cAccumBits =
+ (pfd->cAccumRedBits + pfd->cAccumGreenBits + pfd->cAccumBlueBits +
+ pfd->cAccumAlphaBits);
+ pfd->cDepthBits = _this->gl_config.depth_size;
+ pfd->cStencilBits = _this->gl_config.stencil_size;
+}
+
+/* Choose the closest pixel format that meets or exceeds the target.
+ FIXME: Should we weight any particular attribute over any other?
+*/
+static int
+WIN_GL_ChoosePixelFormat(HDC hdc, PIXELFORMATDESCRIPTOR * target)
+{
+ PIXELFORMATDESCRIPTOR pfd;
+ int count, index, best = 0;
+ unsigned int dist, best_dist = ~0U;
+
+ count = DescribePixelFormat(hdc, 1, sizeof(pfd), NULL);
+
+ for (index = 1; index <= count; index++) {
+
+ if (!DescribePixelFormat(hdc, index, sizeof(pfd), &pfd)) {
+ continue;
+ }
+
+ if ((pfd.dwFlags & target->dwFlags) != target->dwFlags) {
+ continue;
+ }
+
+ if (pfd.iLayerType != target->iLayerType) {
+ continue;
+ }
+ if (pfd.iPixelType != target->iPixelType) {
+ continue;
+ }
+
+ dist = 0;
+
+ if (pfd.cColorBits < target->cColorBits) {
+ continue;
+ } else {
+ dist += (pfd.cColorBits - target->cColorBits);
+ }
+ if (pfd.cRedBits < target->cRedBits) {
+ continue;
+ } else {
+ dist += (pfd.cRedBits - target->cRedBits);
+ }
+ if (pfd.cGreenBits < target->cGreenBits) {
+ continue;
+ } else {
+ dist += (pfd.cGreenBits - target->cGreenBits);
+ }
+ if (pfd.cBlueBits < target->cBlueBits) {
+ continue;
+ } else {
+ dist += (pfd.cBlueBits - target->cBlueBits);
+ }
+ if (pfd.cAlphaBits < target->cAlphaBits) {
+ continue;
+ } else {
+ dist += (pfd.cAlphaBits - target->cAlphaBits);
+ }
+ if (pfd.cAccumBits < target->cAccumBits) {
+ continue;
+ } else {
+ dist += (pfd.cAccumBits - target->cAccumBits);
+ }
+ if (pfd.cAccumRedBits < target->cAccumRedBits) {
+ continue;
+ } else {
+ dist += (pfd.cAccumRedBits - target->cAccumRedBits);
+ }
+ if (pfd.cAccumGreenBits < target->cAccumGreenBits) {
+ continue;
+ } else {
+ dist += (pfd.cAccumGreenBits - target->cAccumGreenBits);
+ }
+ if (pfd.cAccumBlueBits < target->cAccumBlueBits) {
+ continue;
+ } else {
+ dist += (pfd.cAccumBlueBits - target->cAccumBlueBits);
+ }
+ if (pfd.cAccumAlphaBits < target->cAccumAlphaBits) {
+ continue;
+ } else {
+ dist += (pfd.cAccumAlphaBits - target->cAccumAlphaBits);
+ }
+ if (pfd.cDepthBits < target->cDepthBits) {
+ continue;
+ } else {
+ dist += (pfd.cDepthBits - target->cDepthBits);
+ }
+ if (pfd.cStencilBits < target->cStencilBits) {
+ continue;
+ } else {
+ dist += (pfd.cStencilBits - target->cStencilBits);
+ }
+
+ if (dist < best_dist) {
+ best = index;
+ best_dist = dist;
+ }
+ }
+
+ return best;
+}
+
+static SDL_bool
+HasExtension(const char *extension, const char *extensions)
+{
+ const char *start;
+ const char *where, *terminator;
+
+ /* Extension names should not have spaces. */
+ where = SDL_strchr(extension, ' ');
+ if (where || *extension == '\0')
+ return SDL_FALSE;
+
+ if (!extensions)
+ return SDL_FALSE;
+
+ /* It takes a bit of care to be fool-proof about parsing the
+ * OpenGL extensions string. Don't be fooled by sub-strings,
+ * etc. */
+
+ start = extensions;
+
+ for (;;) {
+ where = SDL_strstr(start, extension);
+ if (!where)
+ break;
+
+ terminator = where + SDL_strlen(extension);
+ if (where == start || *(where - 1) == ' ')
+ if (*terminator == ' ' || *terminator == '\0')
+ return SDL_TRUE;
+
+ start = terminator;
+ }
+ return SDL_FALSE;
+}
+
+void
+WIN_GL_InitExtensions(_THIS)
+{
+ const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
+ const char *extensions;
+ HWND hwnd;
+ HDC hdc;
+ HGLRC hglrc;
+ PIXELFORMATDESCRIPTOR pfd;
+
+ if (!_this->gl_data) {
+ return;
+ }
+
+ hwnd =
+ CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0,
+ 10, 10, NULL, NULL, SDL_Instance, NULL);
+ if (!hwnd) {
+ return;
+ }
+ WIN_PumpEvents(_this);
+
+ hdc = GetDC(hwnd);
+
+ WIN_GL_SetupPixelFormat(_this, &pfd);
+
+ SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
+
+ hglrc = _this->gl_data->wglCreateContext(hdc);
+ if (!hglrc) {
+ return;
+ }
+ _this->gl_data->wglMakeCurrent(hdc, hglrc);
+
+ wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC))
+ _this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
+ if (wglGetExtensionsStringARB) {
+ extensions = wglGetExtensionsStringARB(hdc);
+ } else {
+ extensions = NULL;
+ }
+
+ /* Check for WGL_ARB_pixel_format */
+ _this->gl_data->HAS_WGL_ARB_pixel_format = SDL_FALSE;
+ if (HasExtension("WGL_ARB_pixel_format", extensions)) {
+ _this->gl_data->wglChoosePixelFormatARB = (BOOL(WINAPI *)
+ (HDC, const int *,
+ const FLOAT *, UINT,
+ int *, UINT *))
+ WIN_GL_GetProcAddress(_this, "wglChoosePixelFormatARB");
+ _this->gl_data->wglGetPixelFormatAttribivARB =
+ (BOOL(WINAPI *) (HDC, int, int, UINT, const int *, int *))
+ WIN_GL_GetProcAddress(_this, "wglGetPixelFormatAttribivARB");
+
+ if ((_this->gl_data->wglChoosePixelFormatARB != NULL) &&
+ (_this->gl_data->wglGetPixelFormatAttribivARB != NULL)) {
+ _this->gl_data->HAS_WGL_ARB_pixel_format = SDL_TRUE;
+ }
+ }
+
+ /* Check for WGL_EXT_swap_control */
+ _this->gl_data->HAS_WGL_EXT_swap_control_tear = SDL_FALSE;
+ if (HasExtension("WGL_EXT_swap_control", extensions)) {
+ _this->gl_data->wglSwapIntervalEXT =
+ WIN_GL_GetProcAddress(_this, "wglSwapIntervalEXT");
+ _this->gl_data->wglGetSwapIntervalEXT =
+ WIN_GL_GetProcAddress(_this, "wglGetSwapIntervalEXT");
+ if (HasExtension("WGL_EXT_swap_control_tear", extensions)) {
+ _this->gl_data->HAS_WGL_EXT_swap_control_tear = SDL_TRUE;
+ }
+ } else {
+ _this->gl_data->wglSwapIntervalEXT = NULL;
+ _this->gl_data->wglGetSwapIntervalEXT = NULL;
+ }
+
+ /* Check for WGL_EXT_create_context_es2_profile */
+ if (HasExtension("WGL_EXT_create_context_es2_profile", extensions)) {
+ SDL_GL_DeduceMaxSupportedESProfile(
+ &_this->gl_data->es_profile_max_supported_version.major,
+ &_this->gl_data->es_profile_max_supported_version.minor
+ );
+ }
+
+ /* Check for WGL_ARB_context_flush_control */
+ if (HasExtension("WGL_ARB_context_flush_control", extensions)) {
+ _this->gl_data->HAS_WGL_ARB_context_flush_control = SDL_TRUE;
+ }
+
+ /* Check for WGL_ARB_create_context_robustness */
+ if (HasExtension("WGL_ARB_create_context_robustness", extensions)) {
+ _this->gl_data->HAS_WGL_ARB_create_context_robustness = SDL_TRUE;
+ }
+
+ /* Check for WGL_ARB_create_context_no_error */
+ if (HasExtension("WGL_ARB_create_context_no_error", extensions)) {
+ _this->gl_data->HAS_WGL_ARB_create_context_no_error = SDL_TRUE;
+ }
+
+ _this->gl_data->wglMakeCurrent(hdc, NULL);
+ _this->gl_data->wglDeleteContext(hglrc);
+ ReleaseDC(hwnd, hdc);
+ DestroyWindow(hwnd);
+ WIN_PumpEvents(_this);
+}
+
+static int
+WIN_GL_ChoosePixelFormatARB(_THIS, int *iAttribs, float *fAttribs)
+{
+ HWND hwnd;
+ HDC hdc;
+ PIXELFORMATDESCRIPTOR pfd;
+ HGLRC hglrc;
+ int pixel_format = 0;
+ unsigned int matching;
+
+ hwnd =
+ CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0,
+ 10, 10, NULL, NULL, SDL_Instance, NULL);
+ WIN_PumpEvents(_this);
+
+ hdc = GetDC(hwnd);
+
+ WIN_GL_SetupPixelFormat(_this, &pfd);
+
+ SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
+
+ hglrc = _this->gl_data->wglCreateContext(hdc);
+ if (hglrc) {
+ _this->gl_data->wglMakeCurrent(hdc, hglrc);
+
+ if (_this->gl_data->HAS_WGL_ARB_pixel_format) {
+ _this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs,
+ 1, &pixel_format,
+ &matching);
+ }
+
+ _this->gl_data->wglMakeCurrent(hdc, NULL);
+ _this->gl_data->wglDeleteContext(hglrc);
+ }
+ ReleaseDC(hwnd, hdc);
+ DestroyWindow(hwnd);
+ WIN_PumpEvents(_this);
+
+ return pixel_format;
+}
+
+/* actual work of WIN_GL_SetupWindow() happens here. */
+static int
+WIN_GL_SetupWindowInternal(_THIS, SDL_Window * window)
+{
+ HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
+ PIXELFORMATDESCRIPTOR pfd;
+ int pixel_format = 0;
+ int iAttribs[64];
+ int *iAttr;
+ int *iAccelAttr;
+ float fAttribs[1] = { 0 };
+
+ WIN_GL_SetupPixelFormat(_this, &pfd);
+
+ /* setup WGL_ARB_pixel_format attribs */
+ iAttr = &iAttribs[0];
+
+ *iAttr++ = WGL_DRAW_TO_WINDOW_ARB;
+ *iAttr++ = GL_TRUE;
+ *iAttr++ = WGL_RED_BITS_ARB;
+ *iAttr++ = _this->gl_config.red_size;
+ *iAttr++ = WGL_GREEN_BITS_ARB;
+ *iAttr++ = _this->gl_config.green_size;
+ *iAttr++ = WGL_BLUE_BITS_ARB;
+ *iAttr++ = _this->gl_config.blue_size;
+
+ if (_this->gl_config.alpha_size) {
+ *iAttr++ = WGL_ALPHA_BITS_ARB;
+ *iAttr++ = _this->gl_config.alpha_size;
+ }
+
+ *iAttr++ = WGL_DOUBLE_BUFFER_ARB;
+ *iAttr++ = _this->gl_config.double_buffer;
+
+ *iAttr++ = WGL_DEPTH_BITS_ARB;
+ *iAttr++ = _this->gl_config.depth_size;
+
+ if (_this->gl_config.stencil_size) {
+ *iAttr++ = WGL_STENCIL_BITS_ARB;
+ *iAttr++ = _this->gl_config.stencil_size;
+ }
+
+ if (_this->gl_config.accum_red_size) {
+ *iAttr++ = WGL_ACCUM_RED_BITS_ARB;
+ *iAttr++ = _this->gl_config.accum_red_size;
+ }
+
+ if (_this->gl_config.accum_green_size) {
+ *iAttr++ = WGL_ACCUM_GREEN_BITS_ARB;
+ *iAttr++ = _this->gl_config.accum_green_size;
+ }
+
+ if (_this->gl_config.accum_blue_size) {
+ *iAttr++ = WGL_ACCUM_BLUE_BITS_ARB;
+ *iAttr++ = _this->gl_config.accum_blue_size;
+ }
+
+ if (_this->gl_config.accum_alpha_size) {
+ *iAttr++ = WGL_ACCUM_ALPHA_BITS_ARB;
+ *iAttr++ = _this->gl_config.accum_alpha_size;
+ }
+
+ if (_this->gl_config.stereo) {
+ *iAttr++ = WGL_STEREO_ARB;
+ *iAttr++ = GL_TRUE;
+ }
+
+ if (_this->gl_config.multisamplebuffers) {
+ *iAttr++ = WGL_SAMPLE_BUFFERS_ARB;
+ *iAttr++ = _this->gl_config.multisamplebuffers;
+ }
+
+ if (_this->gl_config.multisamplesamples) {
+ *iAttr++ = WGL_SAMPLES_ARB;
+ *iAttr++ = _this->gl_config.multisamplesamples;
+ }
+
+ if (_this->gl_config.framebuffer_srgb_capable) {
+ *iAttr++ = WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB;
+ *iAttr++ = _this->gl_config.framebuffer_srgb_capable;
+ }
+
+ /* We always choose either FULL or NO accel on Windows, because of flaky
+ drivers. If the app didn't specify, we use FULL, because that's
+ probably what they wanted (and if you didn't care and got FULL, that's
+ a perfectly valid result in any case). */
+ *iAttr++ = WGL_ACCELERATION_ARB;
+ iAccelAttr = iAttr;
+ if (_this->gl_config.accelerated) {
+ *iAttr++ = WGL_FULL_ACCELERATION_ARB;
+ } else {
+ *iAttr++ = WGL_NO_ACCELERATION_ARB;
+ }
+
+ *iAttr = 0;
+
+ /* Choose and set the closest available pixel format */
+ pixel_format = WIN_GL_ChoosePixelFormatARB(_this, iAttribs, fAttribs);
+
+ /* App said "don't care about accel" and FULL accel failed. Try NO. */
+ if ( ( !pixel_format ) && ( _this->gl_config.accelerated < 0 ) ) {
+ *iAccelAttr = WGL_NO_ACCELERATION_ARB;
+ pixel_format = WIN_GL_ChoosePixelFormatARB(_this, iAttribs, fAttribs);
+ *iAccelAttr = WGL_FULL_ACCELERATION_ARB; /* if we try again. */
+ }
+ if (!pixel_format) {
+ pixel_format = WIN_GL_ChoosePixelFormat(hdc, &pfd);
+ }
+ if (!pixel_format) {
+ return SDL_SetError("No matching GL pixel format available");
+ }
+ if (!SetPixelFormat(hdc, pixel_format, &pfd)) {
+ return WIN_SetError("SetPixelFormat()");
+ }
+ return 0;
+}
+
+int
+WIN_GL_SetupWindow(_THIS, SDL_Window * window)
+{
+ /* The current context is lost in here; save it and reset it. */
+ SDL_Window *current_win = SDL_GL_GetCurrentWindow();
+ SDL_GLContext current_ctx = SDL_GL_GetCurrentContext();
+ const int retval = WIN_GL_SetupWindowInternal(_this, window);
+ WIN_GL_MakeCurrent(_this, current_win, current_ctx);
+ return retval;
+}
+
+SDL_bool
+WIN_GL_UseEGL(_THIS)
+{
+ SDL_assert(_this->gl_data != NULL);
+ SDL_assert(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES);
+
+ return (SDL_GetHintBoolean(SDL_HINT_OPENGL_ES_DRIVER, SDL_FALSE)
+ || _this->gl_config.major_version == 1 /* No WGL extension for OpenGL ES 1.x profiles. */
+ || _this->gl_config.major_version > _this->gl_data->es_profile_max_supported_version.major
+ || (_this->gl_config.major_version == _this->gl_data->es_profile_max_supported_version.major
+ && _this->gl_config.minor_version > _this->gl_data->es_profile_max_supported_version.minor));
+}
+
+SDL_GLContext
+WIN_GL_CreateContext(_THIS, SDL_Window * window)
+{
+ HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
+ HGLRC context, share_context;
+
+ if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES && WIN_GL_UseEGL(_this)) {
+#if SDL_VIDEO_OPENGL_EGL
+ /* Switch to EGL based functions */
+ WIN_GL_UnloadLibrary(_this);
+ _this->GL_LoadLibrary = WIN_GLES_LoadLibrary;
+ _this->GL_GetProcAddress = WIN_GLES_GetProcAddress;
+ _this->GL_UnloadLibrary = WIN_GLES_UnloadLibrary;
+ _this->GL_CreateContext = WIN_GLES_CreateContext;
+ _this->GL_MakeCurrent = WIN_GLES_MakeCurrent;
+ _this->GL_SetSwapInterval = WIN_GLES_SetSwapInterval;
+ _this->GL_GetSwapInterval = WIN_GLES_GetSwapInterval;
+ _this->GL_SwapWindow = WIN_GLES_SwapWindow;
+ _this->GL_DeleteContext = WIN_GLES_DeleteContext;
+
+ if (WIN_GLES_LoadLibrary(_this, NULL) != 0) {
+ return NULL;
+ }
+
+ return WIN_GLES_CreateContext(_this, window);
+#else
+ SDL_SetError("SDL not configured with EGL support");
+ return NULL;
+#endif
+ }
+
+ if (_this->gl_config.share_with_current_context) {
+ share_context = (HGLRC)SDL_GL_GetCurrentContext();
+ } else {
+ share_context = 0;
+ }
+
+ if (_this->gl_config.major_version < 3 &&
+ _this->gl_config.profile_mask == 0 &&
+ _this->gl_config.flags == 0) {
+ /* Create legacy context */
+ context = _this->gl_data->wglCreateContext(hdc);
+ if( share_context != 0 ) {
+ _this->gl_data->wglShareLists(share_context, context);
+ }
+ } else {
+ PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
+ HGLRC temp_context = _this->gl_data->wglCreateContext(hdc);
+ if (!temp_context) {
+ SDL_SetError("Could not create GL context");
+ return NULL;
+ }
+
+ /* Make the context current */
+ if (WIN_GL_MakeCurrent(_this, window, temp_context) < 0) {
+ WIN_GL_DeleteContext(_this, temp_context);
+ return NULL;
+ }
+
+ wglCreateContextAttribsARB =
+ (PFNWGLCREATECONTEXTATTRIBSARBPROC) _this->gl_data->
+ wglGetProcAddress("wglCreateContextAttribsARB");
+ if (!wglCreateContextAttribsARB) {
+ SDL_SetError("GL 3.x is not supported");
+ context = temp_context;
+ } else {
+ int attribs[15]; /* max 14 attributes plus terminator */
+ int iattr = 0;
+
+ attribs[iattr++] = WGL_CONTEXT_MAJOR_VERSION_ARB;
+ attribs[iattr++] = _this->gl_config.major_version;
+ attribs[iattr++] = WGL_CONTEXT_MINOR_VERSION_ARB;
+ attribs[iattr++] = _this->gl_config.minor_version;
+
+ /* SDL profile bits match WGL profile bits */
+ if (_this->gl_config.profile_mask != 0) {
+ attribs[iattr++] = WGL_CONTEXT_PROFILE_MASK_ARB;
+ attribs[iattr++] = _this->gl_config.profile_mask;
+ }
+
+ /* SDL flags match WGL flags */
+ if (_this->gl_config.flags != 0) {
+ attribs[iattr++] = WGL_CONTEXT_FLAGS_ARB;
+ attribs[iattr++] = _this->gl_config.flags;
+ }
+
+ /* only set if wgl extension is available */
+ if (_this->gl_data->HAS_WGL_ARB_context_flush_control) {
+ attribs[iattr++] = WGL_CONTEXT_RELEASE_BEHAVIOR_ARB;
+ attribs[iattr++] = _this->gl_config.release_behavior ?
+ WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB :
+ WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB;
+ }
+
+ /* only set if wgl extension is available */
+ if (_this->gl_data->HAS_WGL_ARB_create_context_robustness) {
+ attribs[iattr++] = WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB;
+ attribs[iattr++] = _this->gl_config.reset_notification ?
+ WGL_LOSE_CONTEXT_ON_RESET_ARB :
+ WGL_NO_RESET_NOTIFICATION_ARB;
+ }
+
+ /* only set if wgl extension is available */
+ if (_this->gl_data->HAS_WGL_ARB_create_context_no_error) {
+ attribs[iattr++] = WGL_CONTEXT_OPENGL_NO_ERROR_ARB;
+ attribs[iattr++] = _this->gl_config.no_error;
+ }
+
+ attribs[iattr++] = 0;
+
+ /* Create the GL 3.x context */
+ context = wglCreateContextAttribsARB(hdc, share_context, attribs);
+ /* Delete the GL 2.x context */
+ _this->gl_data->wglDeleteContext(temp_context);
+ }
+ }
+
+ if (!context) {
+ WIN_SetError("Could not create GL context");
+ return NULL;
+ }
+
+ if (WIN_GL_MakeCurrent(_this, window, context) < 0) {
+ WIN_GL_DeleteContext(_this, context);
+ return NULL;
+ }
+
+ return context;
+}
+
+int
+WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
+{
+ HDC hdc;
+
+ if (!_this->gl_data) {
+ return SDL_SetError("OpenGL not initialized");
+ }
+
+ /* sanity check that higher level handled this. */
+ SDL_assert(window || (!window && !context));
+
+ /* Some Windows drivers freak out if hdc is NULL, even when context is
+ NULL, against spec. Since hdc is _supposed_ to be ignored if context
+ is NULL, we either use the current GL window, or do nothing if we
+ already have no current context. */
+ if (!window) {
+ window = SDL_GL_GetCurrentWindow();
+ if (!window) {
+ SDL_assert(SDL_GL_GetCurrentContext() == NULL);
+ return 0; /* already done. */
+ }
+ }
+
+ hdc = ((SDL_WindowData *) window->driverdata)->hdc;
+ if (!_this->gl_data->wglMakeCurrent(hdc, (HGLRC) context)) {
+ return WIN_SetError("wglMakeCurrent()");
+ }
+ return 0;
+}
+
+int
+WIN_GL_SetSwapInterval(_THIS, int interval)
+{
+ if ((interval < 0) && (!_this->gl_data->HAS_WGL_EXT_swap_control_tear)) {
+ return SDL_SetError("Negative swap interval unsupported in this GL");
+ } else if (_this->gl_data->wglSwapIntervalEXT) {
+ if (_this->gl_data->wglSwapIntervalEXT(interval) != TRUE) {
+ return WIN_SetError("wglSwapIntervalEXT()");
+ }
+ } else {
+ return SDL_Unsupported();
+ }
+ return 0;
+}
+
+int
+WIN_GL_GetSwapInterval(_THIS)
+{
+ int retval = 0;
+ if (_this->gl_data->wglGetSwapIntervalEXT) {
+ retval = _this->gl_data->wglGetSwapIntervalEXT();
+ }
+ return retval;
+}
+
+int
+WIN_GL_SwapWindow(_THIS, SDL_Window * window)
+{
+ HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
+
+ if (!SwapBuffers(hdc)) {
+ return WIN_SetError("SwapBuffers()");
+ }
+ return 0;
+}
+
+void
+WIN_GL_DeleteContext(_THIS, SDL_GLContext context)
+{
+ if (!_this->gl_data) {
+ return;
+ }
+ _this->gl_data->wglDeleteContext((HGLRC) context);
+}
+
+
+SDL_bool
+WIN_GL_SetPixelFormatFrom(_THIS, SDL_Window * fromWindow, SDL_Window * toWindow)
+{
+ HDC hfromdc = ((SDL_WindowData *) fromWindow->driverdata)->hdc;
+ HDC htodc = ((SDL_WindowData *) toWindow->driverdata)->hdc;
+ BOOL result;
+
+ /* get the pixel format of the fromWindow */
+ int pixel_format = GetPixelFormat(hfromdc);
+ PIXELFORMATDESCRIPTOR pfd;
+ SDL_memset(&pfd, 0, sizeof(pfd));
+ DescribePixelFormat(hfromdc, pixel_format, sizeof(pfd), &pfd);
+
+ /* set the pixel format of the toWindow */
+ result = SetPixelFormat(htodc, pixel_format, &pfd);
+
+ return result ? SDL_TRUE : SDL_FALSE;
+}
+
+#endif /* SDL_VIDEO_OPENGL_WGL */
+
+#endif /* SDL_VIDEO_DRIVER_WINDOWS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsopengl.h b/src/3rdparty/SDL2/src/video/windows/SDL_windowsopengl.h
new file mode 100644
index 0000000..75b4898
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsopengl.h
@@ -0,0 +1,142 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_windowsopengl_h_
+#define SDL_windowsopengl_h_
+
+#if SDL_VIDEO_OPENGL_WGL
+
+struct SDL_GLDriverData
+{
+ SDL_bool HAS_WGL_ARB_pixel_format;
+ SDL_bool HAS_WGL_EXT_swap_control_tear;
+ SDL_bool HAS_WGL_ARB_context_flush_control;
+ SDL_bool HAS_WGL_ARB_create_context_robustness;
+ SDL_bool HAS_WGL_ARB_create_context_no_error;
+
+ /* Max version of OpenGL ES context that can be created if the
+ implementation supports WGL_EXT_create_context_es2_profile.
+ major = minor = 0 when unsupported.
+ */
+ struct {
+ int major;
+ int minor;
+ } es_profile_max_supported_version;
+
+ void *(WINAPI * wglGetProcAddress) (const char *proc);
+ HGLRC(WINAPI * wglCreateContext) (HDC hdc);
+ BOOL(WINAPI * wglDeleteContext) (HGLRC hglrc);
+ BOOL(WINAPI * wglMakeCurrent) (HDC hdc, HGLRC hglrc);
+ BOOL(WINAPI * wglShareLists) (HGLRC hglrc1, HGLRC hglrc2);
+ BOOL(WINAPI * wglChoosePixelFormatARB) (HDC hdc,
+ const int *piAttribIList,
+ const FLOAT * pfAttribFList,
+ UINT nMaxFormats,
+ int *piFormats,
+ UINT * nNumFormats);
+ BOOL(WINAPI * wglGetPixelFormatAttribivARB) (HDC hdc, int iPixelFormat,
+ int iLayerPlane,
+ UINT nAttributes,
+ const int *piAttributes,
+ int *piValues);
+ BOOL (WINAPI * wglSwapIntervalEXT) (int interval);
+ int (WINAPI * wglGetSwapIntervalEXT) (void);
+};
+
+/* OpenGL functions */
+extern int WIN_GL_LoadLibrary(_THIS, const char *path);
+extern void *WIN_GL_GetProcAddress(_THIS, const char *proc);
+extern void WIN_GL_UnloadLibrary(_THIS);
+extern SDL_bool WIN_GL_UseEGL(_THIS);
+extern int WIN_GL_SetupWindow(_THIS, SDL_Window * window);
+extern SDL_GLContext WIN_GL_CreateContext(_THIS, SDL_Window * window);
+extern int WIN_GL_MakeCurrent(_THIS, SDL_Window * window,
+ SDL_GLContext context);
+extern int WIN_GL_SetSwapInterval(_THIS, int interval);
+extern int WIN_GL_GetSwapInterval(_THIS);
+extern int WIN_GL_SwapWindow(_THIS, SDL_Window * window);
+extern void WIN_GL_DeleteContext(_THIS, SDL_GLContext context);
+extern void WIN_GL_InitExtensions(_THIS);
+extern SDL_bool WIN_GL_SetPixelFormatFrom(_THIS, SDL_Window * fromWindow, SDL_Window * toWindow);
+
+#ifndef WGL_ARB_pixel_format
+#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
+#define WGL_DRAW_TO_WINDOW_ARB 0x2001
+#define WGL_DRAW_TO_BITMAP_ARB 0x2002
+#define WGL_ACCELERATION_ARB 0x2003
+#define WGL_NEED_PALETTE_ARB 0x2004
+#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005
+#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006
+#define WGL_SWAP_METHOD_ARB 0x2007
+#define WGL_NUMBER_OVERLAYS_ARB 0x2008
+#define WGL_NUMBER_UNDERLAYS_ARB 0x2009
+#define WGL_TRANSPARENT_ARB 0x200A
+#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037
+#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038
+#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039
+#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A
+#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B
+#define WGL_SHARE_DEPTH_ARB 0x200C
+#define WGL_SHARE_STENCIL_ARB 0x200D
+#define WGL_SHARE_ACCUM_ARB 0x200E
+#define WGL_SUPPORT_GDI_ARB 0x200F
+#define WGL_SUPPORT_OPENGL_ARB 0x2010
+#define WGL_DOUBLE_BUFFER_ARB 0x2011
+#define WGL_STEREO_ARB 0x2012
+#define WGL_PIXEL_TYPE_ARB 0x2013
+#define WGL_COLOR_BITS_ARB 0x2014
+#define WGL_RED_BITS_ARB 0x2015
+#define WGL_RED_SHIFT_ARB 0x2016
+#define WGL_GREEN_BITS_ARB 0x2017
+#define WGL_GREEN_SHIFT_ARB 0x2018
+#define WGL_BLUE_BITS_ARB 0x2019
+#define WGL_BLUE_SHIFT_ARB 0x201A
+#define WGL_ALPHA_BITS_ARB 0x201B
+#define WGL_ALPHA_SHIFT_ARB 0x201C
+#define WGL_ACCUM_BITS_ARB 0x201D
+#define WGL_ACCUM_RED_BITS_ARB 0x201E
+#define WGL_ACCUM_GREEN_BITS_ARB 0x201F
+#define WGL_ACCUM_BLUE_BITS_ARB 0x2020
+#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
+#define WGL_DEPTH_BITS_ARB 0x2022
+#define WGL_STENCIL_BITS_ARB 0x2023
+#define WGL_AUX_BUFFERS_ARB 0x2024
+#define WGL_NO_ACCELERATION_ARB 0x2025
+#define WGL_GENERIC_ACCELERATION_ARB 0x2026
+#define WGL_FULL_ACCELERATION_ARB 0x2027
+#define WGL_SWAP_EXCHANGE_ARB 0x2028
+#define WGL_SWAP_COPY_ARB 0x2029
+#define WGL_SWAP_UNDEFINED_ARB 0x202A
+#define WGL_TYPE_RGBA_ARB 0x202B
+#define WGL_TYPE_COLORINDEX_ARB 0x202C
+#endif
+
+#ifndef WGL_ARB_multisample
+#define WGL_SAMPLE_BUFFERS_ARB 0x2041
+#define WGL_SAMPLES_ARB 0x2042
+#endif
+
+#endif /* SDL_VIDEO_OPENGL_WGL */
+
+#endif /* SDL_windowsopengl_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsopengles.c b/src/3rdparty/SDL2/src/video/windows/SDL_windowsopengles.c
new file mode 100644
index 0000000..0ff61c3
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsopengles.c
@@ -0,0 +1,131 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINDOWS && SDL_VIDEO_OPENGL_EGL
+
+#include "SDL_windowsvideo.h"
+#include "SDL_windowsopengles.h"
+#include "SDL_windowsopengl.h"
+#include "SDL_log.h"
+
+/* EGL implementation of SDL OpenGL support */
+
+int
+WIN_GLES_LoadLibrary(_THIS, const char *path) {
+
+ /* If the profile requested is not GL ES, switch over to WIN_GL functions */
+ if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
+#if SDL_VIDEO_OPENGL_WGL
+ WIN_GLES_UnloadLibrary(_this);
+ _this->GL_LoadLibrary = WIN_GL_LoadLibrary;
+ _this->GL_GetProcAddress = WIN_GL_GetProcAddress;
+ _this->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
+ _this->GL_CreateContext = WIN_GL_CreateContext;
+ _this->GL_MakeCurrent = WIN_GL_MakeCurrent;
+ _this->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
+ _this->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
+ _this->GL_SwapWindow = WIN_GL_SwapWindow;
+ _this->GL_DeleteContext = WIN_GL_DeleteContext;
+ return WIN_GL_LoadLibrary(_this, path);
+#else
+ return SDL_SetError("SDL not configured with OpenGL/WGL support");
+#endif
+ }
+
+ if (_this->egl_data == NULL) {
+ return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, 0);
+ }
+
+ return 0;
+}
+
+SDL_GLContext
+WIN_GLES_CreateContext(_THIS, SDL_Window * window)
+{
+ SDL_GLContext context;
+ SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+
+#if SDL_VIDEO_OPENGL_WGL
+ if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
+ /* Switch to WGL based functions */
+ WIN_GLES_UnloadLibrary(_this);
+ _this->GL_LoadLibrary = WIN_GL_LoadLibrary;
+ _this->GL_GetProcAddress = WIN_GL_GetProcAddress;
+ _this->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
+ _this->GL_CreateContext = WIN_GL_CreateContext;
+ _this->GL_MakeCurrent = WIN_GL_MakeCurrent;
+ _this->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
+ _this->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
+ _this->GL_SwapWindow = WIN_GL_SwapWindow;
+ _this->GL_DeleteContext = WIN_GL_DeleteContext;
+
+ if (WIN_GL_LoadLibrary(_this, NULL) != 0) {
+ return NULL;
+ }
+
+ return WIN_GL_CreateContext(_this, window);
+ }
+#endif
+
+ context = SDL_EGL_CreateContext(_this, data->egl_surface);
+ return context;
+}
+
+void
+WIN_GLES_DeleteContext(_THIS, SDL_GLContext context)
+{
+ SDL_EGL_DeleteContext(_this, context);
+ WIN_GLES_UnloadLibrary(_this);
+}
+
+SDL_EGL_SwapWindow_impl(WIN)
+SDL_EGL_MakeCurrent_impl(WIN)
+
+int
+WIN_GLES_SetupWindow(_THIS, SDL_Window * window)
+{
+ /* The current context is lost in here; save it and reset it. */
+ SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
+ SDL_Window *current_win = SDL_GL_GetCurrentWindow();
+ SDL_GLContext current_ctx = SDL_GL_GetCurrentContext();
+
+
+ if (_this->egl_data == NULL) {
+ if (SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, 0) < 0) {
+ SDL_EGL_UnloadLibrary(_this);
+ return -1;
+ }
+ }
+
+ /* Create the GLES window surface */
+ windowdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType)windowdata->hwnd);
+
+ if (windowdata->egl_surface == EGL_NO_SURFACE) {
+ return SDL_SetError("Could not create GLES window surface");
+ }
+
+ return WIN_GLES_MakeCurrent(_this, current_win, current_ctx);
+}
+
+#endif /* SDL_VIDEO_DRIVER_WINDOWS && SDL_VIDEO_OPENGL_EGL */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsopengles.h b/src/3rdparty/SDL2/src/video/windows/SDL_windowsopengles.h
new file mode 100644
index 0000000..8684429
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsopengles.h
@@ -0,0 +1,49 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_winopengles_h_
+#define SDL_winopengles_h_
+
+#if SDL_VIDEO_OPENGL_EGL
+
+#include "../SDL_sysvideo.h"
+#include "../SDL_egl_c.h"
+
+/* OpenGLES functions */
+#define WIN_GLES_GetAttribute SDL_EGL_GetAttribute
+#define WIN_GLES_GetProcAddress SDL_EGL_GetProcAddress
+#define WIN_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
+#define WIN_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
+#define WIN_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
+
+extern int WIN_GLES_LoadLibrary(_THIS, const char *path);
+extern SDL_GLContext WIN_GLES_CreateContext(_THIS, SDL_Window * window);
+extern int WIN_GLES_SwapWindow(_THIS, SDL_Window * window);
+extern int WIN_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+extern void WIN_GLES_DeleteContext(_THIS, SDL_GLContext context);
+extern int WIN_GLES_SetupWindow(_THIS, SDL_Window * window);
+
+#endif /* SDL_VIDEO_OPENGL_EGL */
+
+#endif /* SDL_winopengles_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsshape.c b/src/3rdparty/SDL2/src/video/windows/SDL_windowsshape.c
new file mode 100644
index 0000000..bed4588
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsshape.c
@@ -0,0 +1,110 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINDOWS
+
+#include "SDL_assert.h"
+#include "SDL_windowsshape.h"
+#include "SDL_windowsvideo.h"
+
+SDL_WindowShaper*
+Win32_CreateShaper(SDL_Window * window) {
+ int resized_properly;
+ SDL_WindowShaper* result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper));
+ result->window = window;
+ result->mode.mode = ShapeModeDefault;
+ result->mode.parameters.binarizationCutoff = 1;
+ result->userx = result->usery = 0;
+ result->driverdata = (SDL_ShapeData*)SDL_malloc(sizeof(SDL_ShapeData));
+ ((SDL_ShapeData*)result->driverdata)->mask_tree = NULL;
+ /* Put some driver-data here. */
+ window->shaper = result;
+ resized_properly = Win32_ResizeWindowShape(window);
+ if (resized_properly != 0)
+ return NULL;
+
+ return result;
+}
+
+static void
+CombineRectRegions(SDL_ShapeTree* node,void* closure) {
+ HRGN mask_region = *((HRGN*)closure),temp_region = NULL;
+ if(node->kind == OpaqueShape) {
+ /* Win32 API regions exclude their outline, so we widen the region by one pixel in each direction to include the real outline. */
+ temp_region = CreateRectRgn(node->data.shape.x,node->data.shape.y,node->data.shape.x + node->data.shape.w + 1,node->data.shape.y + node->data.shape.h + 1);
+ if(mask_region != NULL) {
+ CombineRgn(mask_region,mask_region,temp_region,RGN_OR);
+ DeleteObject(temp_region);
+ }
+ else
+ *((HRGN*)closure) = temp_region;
+ }
+}
+
+int
+Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
+ SDL_ShapeData *data;
+ HRGN mask_region = NULL;
+
+ if( (shaper == NULL) ||
+ (shape == NULL) ||
+ ((shape->format->Amask == 0) && (shape_mode->mode != ShapeModeColorKey)) ||
+ (shape->w != shaper->window->w) ||
+ (shape->h != shaper->window->h) ) {
+ return SDL_INVALID_SHAPE_ARGUMENT;
+ }
+
+ data = (SDL_ShapeData*)shaper->driverdata;
+ if(data->mask_tree != NULL)
+ SDL_FreeShapeTree(&data->mask_tree);
+ data->mask_tree = SDL_CalculateShapeTree(*shape_mode,shape);
+
+ SDL_TraverseShapeTree(data->mask_tree,&CombineRectRegions,&mask_region);
+ SDL_assert(mask_region != NULL);
+
+ SetWindowRgn(((SDL_WindowData *)(shaper->window->driverdata))->hwnd, mask_region, TRUE);
+
+ return 0;
+}
+
+int
+Win32_ResizeWindowShape(SDL_Window *window) {
+ SDL_ShapeData* data;
+
+ if (window == NULL)
+ return -1;
+ data = (SDL_ShapeData *)window->shaper->driverdata;
+ if (data == NULL)
+ return -1;
+
+ if(data->mask_tree != NULL)
+ SDL_FreeShapeTree(&data->mask_tree);
+ if(window->shaper->hasshape == SDL_TRUE) {
+ window->shaper->userx = window->x;
+ window->shaper->usery = window->y;
+ SDL_SetWindowPosition(window,-1000,-1000);
+ }
+
+ return 0;
+}
+
+#endif /* SDL_VIDEO_DRIVER_WINDOWS */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsshape.h b/src/3rdparty/SDL2/src/video/windows/SDL_windowsshape.h
new file mode 100644
index 0000000..eb1a887
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsshape.h
@@ -0,0 +1,40 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_windowsshape_h_
+#define SDL_windowsshape_h_
+
+#include "SDL_video.h"
+#include "SDL_shape.h"
+#include "../SDL_sysvideo.h"
+#include "../SDL_shape_internals.h"
+
+typedef struct {
+ SDL_ShapeTree *mask_tree;
+} SDL_ShapeData;
+
+extern SDL_WindowShaper* Win32_CreateShaper(SDL_Window * window);
+extern int Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
+extern int Win32_ResizeWindowShape(SDL_Window *window);
+
+#endif /* SDL_windowsshape_h_ */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsvideo.c b/src/3rdparty/SDL2/src/video/windows/SDL_windowsvideo.c
new file mode 100644
index 0000000..8d45b72
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsvideo.c
@@ -0,0 +1,441 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINDOWS
+
+#include "SDL_main.h"
+#include "SDL_video.h"
+#include "SDL_hints.h"
+#include "SDL_mouse.h"
+#include "SDL_system.h"
+#include "../SDL_sysvideo.h"
+#include "../SDL_pixels_c.h"
+
+#include "SDL_windowsvideo.h"
+#include "SDL_windowsframebuffer.h"
+#include "SDL_windowsshape.h"
+#include "SDL_windowsvulkan.h"
+
+/* Initialization/Query functions */
+static int WIN_VideoInit(_THIS);
+static void WIN_VideoQuit(_THIS);
+
+/* Hints */
+SDL_bool g_WindowsEnableMessageLoop = SDL_TRUE;
+SDL_bool g_WindowFrameUsableWhileCursorHidden = SDL_TRUE;
+
+static void SDLCALL
+UpdateWindowsEnableMessageLoop(void *userdata, const char *name, const char *oldValue, const char *newValue)
+{
+ if (newValue && *newValue == '0') {
+ g_WindowsEnableMessageLoop = SDL_FALSE;
+ } else {
+ g_WindowsEnableMessageLoop = SDL_TRUE;
+ }
+}
+
+static void SDLCALL
+UpdateWindowFrameUsableWhileCursorHidden(void *userdata, const char *name, const char *oldValue, const char *newValue)
+{
+ if (newValue && *newValue == '0') {
+ g_WindowFrameUsableWhileCursorHidden = SDL_FALSE;
+ } else {
+ g_WindowFrameUsableWhileCursorHidden = SDL_TRUE;
+ }
+}
+
+
+/* Windows driver bootstrap functions */
+
+static int
+WIN_Available(void)
+{
+ return (1);
+}
+
+static void
+WIN_DeleteDevice(SDL_VideoDevice * device)
+{
+ SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
+
+ SDL_UnregisterApp();
+ if (data->userDLL) {
+ SDL_UnloadObject(data->userDLL);
+ }
+ if (data->shcoreDLL) {
+ SDL_UnloadObject(data->shcoreDLL);
+ }
+
+ SDL_free(device->driverdata);
+ SDL_free(device);
+}
+
+static SDL_VideoDevice *
+WIN_CreateDevice(int devindex)
+{
+ SDL_VideoDevice *device;
+ SDL_VideoData *data;
+
+ SDL_RegisterApp(NULL, 0, NULL);
+
+ /* Initialize all variables that we clean on shutdown */
+ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (device) {
+ data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
+ } else {
+ data = NULL;
+ }
+ if (!data) {
+ SDL_free(device);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ device->driverdata = data;
+
+ data->userDLL = SDL_LoadObject("USER32.DLL");
+ if (data->userDLL) {
+ data->CloseTouchInputHandle = (BOOL (WINAPI *)(HTOUCHINPUT)) SDL_LoadFunction(data->userDLL, "CloseTouchInputHandle");
+ data->GetTouchInputInfo = (BOOL (WINAPI *)(HTOUCHINPUT, UINT, PTOUCHINPUT, int)) SDL_LoadFunction(data->userDLL, "GetTouchInputInfo");
+ data->RegisterTouchWindow = (BOOL (WINAPI *)(HWND, ULONG)) SDL_LoadFunction(data->userDLL, "RegisterTouchWindow");
+ } else {
+ SDL_ClearError();
+ }
+
+ data->shcoreDLL = SDL_LoadObject("SHCORE.DLL");
+ if (data->shcoreDLL) {
+ data->GetDpiForMonitor = (HRESULT (WINAPI *)(HMONITOR, MONITOR_DPI_TYPE, UINT *, UINT *)) SDL_LoadFunction(data->shcoreDLL, "GetDpiForMonitor");
+ } else {
+ SDL_ClearError();
+ }
+
+ /* Set the function pointers */
+ device->VideoInit = WIN_VideoInit;
+ device->VideoQuit = WIN_VideoQuit;
+ device->GetDisplayBounds = WIN_GetDisplayBounds;
+ device->GetDisplayUsableBounds = WIN_GetDisplayUsableBounds;
+ device->GetDisplayDPI = WIN_GetDisplayDPI;
+ device->GetDisplayModes = WIN_GetDisplayModes;
+ device->SetDisplayMode = WIN_SetDisplayMode;
+ device->PumpEvents = WIN_PumpEvents;
+
+ device->CreateSDLWindow = WIN_CreateWindow;
+ device->CreateSDLWindowFrom = WIN_CreateWindowFrom;
+ device->SetWindowTitle = WIN_SetWindowTitle;
+ device->SetWindowIcon = WIN_SetWindowIcon;
+ device->SetWindowPosition = WIN_SetWindowPosition;
+ device->SetWindowSize = WIN_SetWindowSize;
+ device->GetWindowBordersSize = WIN_GetWindowBordersSize;
+ device->SetWindowOpacity = WIN_SetWindowOpacity;
+ device->ShowWindow = WIN_ShowWindow;
+ device->HideWindow = WIN_HideWindow;
+ device->RaiseWindow = WIN_RaiseWindow;
+ device->MaximizeWindow = WIN_MaximizeWindow;
+ device->MinimizeWindow = WIN_MinimizeWindow;
+ device->RestoreWindow = WIN_RestoreWindow;
+ device->SetWindowBordered = WIN_SetWindowBordered;
+ device->SetWindowResizable = WIN_SetWindowResizable;
+ device->SetWindowFullscreen = WIN_SetWindowFullscreen;
+ device->SetWindowGammaRamp = WIN_SetWindowGammaRamp;
+ device->GetWindowGammaRamp = WIN_GetWindowGammaRamp;
+ device->SetWindowGrab = WIN_SetWindowGrab;
+ device->DestroyWindow = WIN_DestroyWindow;
+ device->GetWindowWMInfo = WIN_GetWindowWMInfo;
+ device->CreateWindowFramebuffer = WIN_CreateWindowFramebuffer;
+ device->UpdateWindowFramebuffer = WIN_UpdateWindowFramebuffer;
+ device->DestroyWindowFramebuffer = WIN_DestroyWindowFramebuffer;
+ device->OnWindowEnter = WIN_OnWindowEnter;
+ device->SetWindowHitTest = WIN_SetWindowHitTest;
+
+ device->shape_driver.CreateShaper = Win32_CreateShaper;
+ device->shape_driver.SetWindowShape = Win32_SetWindowShape;
+ device->shape_driver.ResizeWindowShape = Win32_ResizeWindowShape;
+
+#if SDL_VIDEO_OPENGL_WGL
+ device->GL_LoadLibrary = WIN_GL_LoadLibrary;
+ device->GL_GetProcAddress = WIN_GL_GetProcAddress;
+ device->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
+ device->GL_CreateContext = WIN_GL_CreateContext;
+ device->GL_MakeCurrent = WIN_GL_MakeCurrent;
+ device->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
+ device->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
+ device->GL_SwapWindow = WIN_GL_SwapWindow;
+ device->GL_DeleteContext = WIN_GL_DeleteContext;
+#elif SDL_VIDEO_OPENGL_EGL
+ /* Use EGL based functions */
+ device->GL_LoadLibrary = WIN_GLES_LoadLibrary;
+ device->GL_GetProcAddress = WIN_GLES_GetProcAddress;
+ device->GL_UnloadLibrary = WIN_GLES_UnloadLibrary;
+ device->GL_CreateContext = WIN_GLES_CreateContext;
+ device->GL_MakeCurrent = WIN_GLES_MakeCurrent;
+ device->GL_SetSwapInterval = WIN_GLES_SetSwapInterval;
+ device->GL_GetSwapInterval = WIN_GLES_GetSwapInterval;
+ device->GL_SwapWindow = WIN_GLES_SwapWindow;
+ device->GL_DeleteContext = WIN_GLES_DeleteContext;
+#endif
+#if SDL_VIDEO_VULKAN
+ device->Vulkan_LoadLibrary = WIN_Vulkan_LoadLibrary;
+ device->Vulkan_UnloadLibrary = WIN_Vulkan_UnloadLibrary;
+ device->Vulkan_GetInstanceExtensions = WIN_Vulkan_GetInstanceExtensions;
+ device->Vulkan_CreateSurface = WIN_Vulkan_CreateSurface;
+#endif
+
+ device->StartTextInput = WIN_StartTextInput;
+ device->StopTextInput = WIN_StopTextInput;
+ device->SetTextInputRect = WIN_SetTextInputRect;
+
+ device->SetClipboardText = WIN_SetClipboardText;
+ device->GetClipboardText = WIN_GetClipboardText;
+ device->HasClipboardText = WIN_HasClipboardText;
+
+ device->free = WIN_DeleteDevice;
+
+ return device;
+}
+
+
+VideoBootStrap WINDOWS_bootstrap = {
+ "windows", "SDL Windows video driver", WIN_Available, WIN_CreateDevice
+};
+
+int
+WIN_VideoInit(_THIS)
+{
+ if (WIN_InitModes(_this) < 0) {
+ return -1;
+ }
+
+ WIN_InitKeyboard(_this);
+ WIN_InitMouse(_this);
+
+ SDL_AddHintCallback(SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP, UpdateWindowsEnableMessageLoop, NULL);
+ SDL_AddHintCallback(SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN, UpdateWindowFrameUsableWhileCursorHidden, NULL);
+
+ return 0;
+}
+
+void
+WIN_VideoQuit(_THIS)
+{
+ WIN_QuitModes(_this);
+ WIN_QuitKeyboard(_this);
+ WIN_QuitMouse(_this);
+}
+
+
+#define D3D_DEBUG_INFO
+#include <d3d9.h>
+
+SDL_bool
+D3D_LoadDLL(void **pD3DDLL, IDirect3D9 **pDirect3D9Interface)
+{
+ *pD3DDLL = SDL_LoadObject("D3D9.DLL");
+ if (*pD3DDLL) {
+ typedef IDirect3D9 *(WINAPI *Direct3DCreate9_t) (UINT SDKVersion);
+ Direct3DCreate9_t Direct3DCreate9Func;
+
+#ifdef USE_D3D9EX
+ typedef HRESULT (WINAPI *Direct3DCreate9Ex_t)(UINT SDKVersion, IDirect3D9Ex **ppD3D);
+ Direct3DCreate9Ex_t Direct3DCreate9ExFunc;
+
+ Direct3DCreate9ExFunc = (Direct3DCreate9Ex_t)SDL_LoadFunction(*pD3DDLL, "Direct3DCreate9Ex");
+ if (Direct3DCreate9ExFunc) {
+ IDirect3D9Ex *pDirect3D9ExInterface;
+ HRESULT hr = Direct3DCreate9ExFunc(D3D_SDK_VERSION, &pDirect3D9ExInterface);
+ if (SUCCEEDED(hr)) {
+ const GUID IDirect3D9_GUID = { 0x81bdcbca, 0x64d4, 0x426d, { 0xae, 0x8d, 0xad, 0x1, 0x47, 0xf4, 0x27, 0x5c } };
+ hr = IDirect3D9Ex_QueryInterface(pDirect3D9ExInterface, &IDirect3D9_GUID, (void**)pDirect3D9Interface);
+ IDirect3D9Ex_Release(pDirect3D9ExInterface);
+ if (SUCCEEDED(hr)) {
+ return SDL_TRUE;
+ }
+ }
+ }
+#endif /* USE_D3D9EX */
+
+ Direct3DCreate9Func = (Direct3DCreate9_t)SDL_LoadFunction(*pD3DDLL, "Direct3DCreate9");
+ if (Direct3DCreate9Func) {
+ *pDirect3D9Interface = Direct3DCreate9Func(D3D_SDK_VERSION);
+ if (*pDirect3D9Interface) {
+ return SDL_TRUE;
+ }
+ }
+
+ SDL_UnloadObject(*pD3DDLL);
+ *pD3DDLL = NULL;
+ }
+ *pDirect3D9Interface = NULL;
+ return SDL_FALSE;
+}
+
+
+int
+SDL_Direct3D9GetAdapterIndex(int displayIndex)
+{
+ void *pD3DDLL;
+ IDirect3D9 *pD3D;
+ if (!D3D_LoadDLL(&pD3DDLL, &pD3D)) {
+ SDL_SetError("Unable to create Direct3D interface");
+ return D3DADAPTER_DEFAULT;
+ } else {
+ SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
+ int adapterIndex = D3DADAPTER_DEFAULT;
+
+ if (!pData) {
+ SDL_SetError("Invalid display index");
+ adapterIndex = -1; /* make sure we return something invalid */
+ } else {
+ char *displayName = WIN_StringToUTF8(pData->DeviceName);
+ unsigned int count = IDirect3D9_GetAdapterCount(pD3D);
+ unsigned int i;
+ for (i=0; i<count; i++) {
+ D3DADAPTER_IDENTIFIER9 id;
+ IDirect3D9_GetAdapterIdentifier(pD3D, i, 0, &id);
+
+ if (SDL_strcmp(id.DeviceName, displayName) == 0) {
+ adapterIndex = i;
+ break;
+ }
+ }
+ SDL_free(displayName);
+ }
+
+ /* free up the D3D stuff we inited */
+ IDirect3D9_Release(pD3D);
+ SDL_UnloadObject(pD3DDLL);
+
+ return adapterIndex;
+ }
+}
+
+#if HAVE_DXGI_H
+#define CINTERFACE
+#define COBJMACROS
+#include <dxgi.h>
+
+static SDL_bool
+DXGI_LoadDLL(void **pDXGIDLL, IDXGIFactory **pDXGIFactory)
+{
+ *pDXGIDLL = SDL_LoadObject("DXGI.DLL");
+ if (*pDXGIDLL) {
+ HRESULT (WINAPI *CreateDXGI)(REFIID riid, void **ppFactory);
+
+ CreateDXGI =
+ (HRESULT (WINAPI *) (REFIID, void**)) SDL_LoadFunction(*pDXGIDLL,
+ "CreateDXGIFactory");
+ if (CreateDXGI) {
+ GUID dxgiGUID = {0x7b7166ec,0x21c7,0x44ae,{0xb2,0x1a,0xc9,0xae,0x32,0x1a,0xe3,0x69}};
+ if (!SUCCEEDED(CreateDXGI(&dxgiGUID, (void**)pDXGIFactory))) {
+ *pDXGIFactory = NULL;
+ }
+ }
+ if (!*pDXGIFactory) {
+ SDL_UnloadObject(*pDXGIDLL);
+ *pDXGIDLL = NULL;
+ return SDL_FALSE;
+ }
+
+ return SDL_TRUE;
+ } else {
+ *pDXGIFactory = NULL;
+ return SDL_FALSE;
+ }
+}
+#endif
+
+
+SDL_bool
+SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex)
+{
+#if !HAVE_DXGI_H
+ if (adapterIndex) *adapterIndex = -1;
+ if (outputIndex) *outputIndex = -1;
+ SDL_SetError("SDL was compiled without DXGI support due to missing dxgi.h header");
+ return SDL_FALSE;
+#else
+ SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex);
+ void *pDXGIDLL;
+ char *displayName;
+ int nAdapter, nOutput;
+ IDXGIFactory *pDXGIFactory;
+ IDXGIAdapter *pDXGIAdapter;
+ IDXGIOutput* pDXGIOutput;
+
+ if (!adapterIndex) {
+ SDL_InvalidParamError("adapterIndex");
+ return SDL_FALSE;
+ }
+
+ if (!outputIndex) {
+ SDL_InvalidParamError("outputIndex");
+ return SDL_FALSE;
+ }
+
+ *adapterIndex = -1;
+ *outputIndex = -1;
+
+ if (!pData) {
+ SDL_SetError("Invalid display index");
+ return SDL_FALSE;
+ }
+
+ if (!DXGI_LoadDLL(&pDXGIDLL, &pDXGIFactory)) {
+ SDL_SetError("Unable to create DXGI interface");
+ return SDL_FALSE;
+ }
+
+ displayName = WIN_StringToUTF8(pData->DeviceName);
+ nAdapter = 0;
+ while (*adapterIndex == -1 && SUCCEEDED(IDXGIFactory_EnumAdapters(pDXGIFactory, nAdapter, &pDXGIAdapter))) {
+ nOutput = 0;
+ while (*adapterIndex == -1 && SUCCEEDED(IDXGIAdapter_EnumOutputs(pDXGIAdapter, nOutput, &pDXGIOutput))) {
+ DXGI_OUTPUT_DESC outputDesc;
+ if (SUCCEEDED(IDXGIOutput_GetDesc(pDXGIOutput, &outputDesc))) {
+ char *outputName = WIN_StringToUTF8(outputDesc.DeviceName);
+ if (SDL_strcmp(outputName, displayName) == 0) {
+ *adapterIndex = nAdapter;
+ *outputIndex = nOutput;
+ }
+ SDL_free(outputName);
+ }
+ IDXGIOutput_Release(pDXGIOutput);
+ nOutput++;
+ }
+ IDXGIAdapter_Release(pDXGIAdapter);
+ nAdapter++;
+ }
+ SDL_free(displayName);
+
+ /* free up the DXGI factory */
+ IDXGIFactory_Release(pDXGIFactory);
+ SDL_UnloadObject(pDXGIDLL);
+
+ if (*adapterIndex == -1) {
+ return SDL_FALSE;
+ } else {
+ return SDL_TRUE;
+ }
+#endif
+}
+
+#endif /* SDL_VIDEO_DRIVER_WINDOWS */
+
+/* vim: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsvideo.h b/src/3rdparty/SDL2/src/video/windows/SDL_windowsvideo.h
new file mode 100644
index 0000000..1303754
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsvideo.h
@@ -0,0 +1,199 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_windowsvideo_h_
+#define SDL_windowsvideo_h_
+
+#include "../../core/windows/SDL_windows.h"
+
+#include "../SDL_sysvideo.h"
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1500)
+#include <msctf.h>
+#else
+#include "SDL_msctf.h"
+#endif
+
+#include <imm.h>
+
+#define MAX_CANDLIST 10
+#define MAX_CANDLENGTH 256
+
+#include "SDL_windowsclipboard.h"
+#include "SDL_windowsevents.h"
+#include "SDL_windowskeyboard.h"
+#include "SDL_windowsmodes.h"
+#include "SDL_windowsmouse.h"
+#include "SDL_windowsopengl.h"
+#include "SDL_windowsopengles.h"
+#include "SDL_windowswindow.h"
+#include "SDL_events.h"
+#include "SDL_loadso.h"
+
+
+#if WINVER < 0x0601
+/* Touch input definitions */
+#define TWF_FINETOUCH 1
+#define TWF_WANTPALM 2
+
+#define TOUCHEVENTF_MOVE 0x0001
+#define TOUCHEVENTF_DOWN 0x0002
+#define TOUCHEVENTF_UP 0x0004
+
+DECLARE_HANDLE(HTOUCHINPUT);
+
+typedef struct _TOUCHINPUT {
+ LONG x;
+ LONG y;
+ HANDLE hSource;
+ DWORD dwID;
+ DWORD dwFlags;
+ DWORD dwMask;
+ DWORD dwTime;
+ ULONG_PTR dwExtraInfo;
+ DWORD cxContact;
+ DWORD cyContact;
+} TOUCHINPUT, *PTOUCHINPUT;
+
+#endif /* WINVER < 0x0601 */
+
+#if WINVER < 0x0603
+
+typedef enum MONITOR_DPI_TYPE {
+ MDT_EFFECTIVE_DPI = 0,
+ MDT_ANGULAR_DPI = 1,
+ MDT_RAW_DPI = 2,
+ MDT_DEFAULT = MDT_EFFECTIVE_DPI
+} MONITOR_DPI_TYPE;
+
+#endif /* WINVER < 0x0603 */
+
+typedef BOOL (*PFNSHFullScreen)(HWND, DWORD);
+typedef void (*PFCoordTransform)(SDL_Window*, POINT*);
+
+typedef struct
+{
+ void **lpVtbl;
+ int refcount;
+ void *data;
+} TSFSink;
+
+/* Definition from Win98DDK version of IMM.H */
+typedef struct tagINPUTCONTEXT2 {
+ HWND hWnd;
+ BOOL fOpen;
+ POINT ptStatusWndPos;
+ POINT ptSoftKbdPos;
+ DWORD fdwConversion;
+ DWORD fdwSentence;
+ union {
+ LOGFONTA A;
+ LOGFONTW W;
+ } lfFont;
+ COMPOSITIONFORM cfCompForm;
+ CANDIDATEFORM cfCandForm[4];
+ HIMCC hCompStr;
+ HIMCC hCandInfo;
+ HIMCC hGuideLine;
+ HIMCC hPrivate;
+ DWORD dwNumMsgBuf;
+ HIMCC hMsgBuf;
+ DWORD fdwInit;
+ DWORD dwReserve[3];
+} INPUTCONTEXT2, *PINPUTCONTEXT2, NEAR *NPINPUTCONTEXT2, FAR *LPINPUTCONTEXT2;
+
+/* Private display data */
+
+typedef struct SDL_VideoData
+{
+ int render;
+
+ DWORD clipboard_count;
+
+ /* Touch input functions */
+ void* userDLL;
+ BOOL (WINAPI *CloseTouchInputHandle)( HTOUCHINPUT );
+ BOOL (WINAPI *GetTouchInputInfo)( HTOUCHINPUT, UINT, PTOUCHINPUT, int );
+ BOOL (WINAPI *RegisterTouchWindow)( HWND, ULONG );
+
+ void* shcoreDLL;
+ HRESULT (WINAPI *GetDpiForMonitor)( HMONITOR hmonitor,
+ MONITOR_DPI_TYPE dpiType,
+ UINT *dpiX,
+ UINT *dpiY );
+
+ SDL_bool ime_com_initialized;
+ struct ITfThreadMgr *ime_threadmgr;
+ SDL_bool ime_initialized;
+ SDL_bool ime_enabled;
+ SDL_bool ime_available;
+ HWND ime_hwnd_main;
+ HWND ime_hwnd_current;
+ HIMC ime_himc;
+
+ WCHAR ime_composition[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
+ WCHAR ime_readingstring[16];
+ int ime_cursor;
+
+ SDL_bool ime_candlist;
+ WCHAR ime_candidates[MAX_CANDLIST][MAX_CANDLENGTH];
+ DWORD ime_candcount;
+ DWORD ime_candref;
+ DWORD ime_candsel;
+ UINT ime_candpgsize;
+ int ime_candlistindexbase;
+ SDL_bool ime_candvertical;
+
+ SDL_bool ime_dirty;
+ SDL_Rect ime_rect;
+ SDL_Rect ime_candlistrect;
+ int ime_winwidth;
+ int ime_winheight;
+
+ HKL ime_hkl;
+ void* ime_himm32;
+ UINT (WINAPI *GetReadingString)(HIMC himc, UINT uReadingBufLen, LPWSTR lpwReadingBuf, PINT pnErrorIndex, BOOL *pfIsVertical, PUINT puMaxReadingLen);
+ BOOL (WINAPI *ShowReadingWindow)(HIMC himc, BOOL bShow);
+ LPINPUTCONTEXT2 (WINAPI *ImmLockIMC)(HIMC himc);
+ BOOL (WINAPI *ImmUnlockIMC)(HIMC himc);
+ LPVOID (WINAPI *ImmLockIMCC)(HIMCC himcc);
+ BOOL (WINAPI *ImmUnlockIMCC)(HIMCC himcc);
+
+ SDL_bool ime_uiless;
+ struct ITfThreadMgrEx *ime_threadmgrex;
+ DWORD ime_uielemsinkcookie;
+ DWORD ime_alpnsinkcookie;
+ DWORD ime_openmodesinkcookie;
+ DWORD ime_convmodesinkcookie;
+ TSFSink *ime_uielemsink;
+ TSFSink *ime_ippasink;
+} SDL_VideoData;
+
+extern SDL_bool g_WindowsEnableMessageLoop;
+extern SDL_bool g_WindowFrameUsableWhileCursorHidden;
+
+typedef struct IDirect3D9 IDirect3D9;
+extern SDL_bool D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface );
+
+#endif /* SDL_windowsvideo_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsvulkan.c b/src/3rdparty/SDL2/src/video/windows/SDL_windowsvulkan.c
new file mode 100644
index 0000000..c4b34f0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsvulkan.c
@@ -0,0 +1,176 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ * @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's
+ * SDL_x11vulkan.c.
+ */
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_WINDOWS
+
+#include "SDL_windowsvideo.h"
+#include "SDL_windowswindow.h"
+#include "SDL_assert.h"
+
+#include "SDL_loadso.h"
+#include "SDL_windowsvulkan.h"
+#include "SDL_syswm.h"
+
+int WIN_Vulkan_LoadLibrary(_THIS, const char *path)
+{
+ VkExtensionProperties *extensions = NULL;
+ Uint32 extensionCount = 0;
+ Uint32 i;
+ SDL_bool hasSurfaceExtension = SDL_FALSE;
+ SDL_bool hasWin32SurfaceExtension = SDL_FALSE;
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
+ if(_this->vulkan_config.loader_handle)
+ return SDL_SetError("Vulkan already loaded");
+
+ /* Load the Vulkan loader library */
+ if(!path)
+ path = SDL_getenv("SDL_VULKAN_LIBRARY");
+ if(!path)
+ path = "vulkan-1.dll";
+ _this->vulkan_config.loader_handle = SDL_LoadObject(path);
+ if(!_this->vulkan_config.loader_handle)
+ return -1;
+ SDL_strlcpy(_this->vulkan_config.loader_path, path,
+ SDL_arraysize(_this->vulkan_config.loader_path));
+ vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction(
+ _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr");
+ if(!vkGetInstanceProcAddr)
+ goto fail;
+ _this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr;
+ _this->vulkan_config.vkEnumerateInstanceExtensionProperties =
+ (void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)(
+ VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties");
+ if(!_this->vulkan_config.vkEnumerateInstanceExtensionProperties)
+ goto fail;
+ extensions = SDL_Vulkan_CreateInstanceExtensionsList(
+ (PFN_vkEnumerateInstanceExtensionProperties)
+ _this->vulkan_config.vkEnumerateInstanceExtensionProperties,
+ &extensionCount);
+ if(!extensions)
+ goto fail;
+ for(i = 0; i < extensionCount; i++)
+ {
+ if(SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
+ hasSurfaceExtension = SDL_TRUE;
+ else if(SDL_strcmp(VK_KHR_WIN32_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
+ hasWin32SurfaceExtension = SDL_TRUE;
+ }
+ SDL_free(extensions);
+ if(!hasSurfaceExtension)
+ {
+ SDL_SetError("Installed Vulkan doesn't implement the "
+ VK_KHR_SURFACE_EXTENSION_NAME " extension");
+ goto fail;
+ }
+ else if(!hasWin32SurfaceExtension)
+ {
+ SDL_SetError("Installed Vulkan doesn't implement the "
+ VK_KHR_WIN32_SURFACE_EXTENSION_NAME "extension");
+ goto fail;
+ }
+ return 0;
+
+fail:
+ SDL_UnloadObject(_this->vulkan_config.loader_handle);
+ _this->vulkan_config.loader_handle = NULL;
+ return -1;
+}
+
+void WIN_Vulkan_UnloadLibrary(_THIS)
+{
+ if(_this->vulkan_config.loader_handle)
+ {
+ SDL_UnloadObject(_this->vulkan_config.loader_handle);
+ _this->vulkan_config.loader_handle = NULL;
+ }
+}
+
+SDL_bool WIN_Vulkan_GetInstanceExtensions(_THIS,
+ SDL_Window *window,
+ unsigned *count,
+ const char **names)
+{
+ static const char *const extensionsForWin32[] = {
+ VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME
+ };
+ if(!_this->vulkan_config.loader_handle)
+ {
+ SDL_SetError("Vulkan is not loaded");
+ return SDL_FALSE;
+ }
+ return SDL_Vulkan_GetInstanceExtensions_Helper(
+ count, names, SDL_arraysize(extensionsForWin32),
+ extensionsForWin32);
+}
+
+SDL_bool WIN_Vulkan_CreateSurface(_THIS,
+ SDL_Window *window,
+ VkInstance instance,
+ VkSurfaceKHR *surface)
+{
+ SDL_WindowData *windowData = (SDL_WindowData *)window->driverdata;
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
+ (PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr;
+ PFN_vkCreateWin32SurfaceKHR vkCreateWin32SurfaceKHR =
+ (PFN_vkCreateWin32SurfaceKHR)vkGetInstanceProcAddr(
+ (VkInstance)instance,
+ "vkCreateWin32SurfaceKHR");
+ VkWin32SurfaceCreateInfoKHR createInfo;
+ VkResult result;
+
+ if(!_this->vulkan_config.loader_handle)
+ {
+ SDL_SetError("Vulkan is not loaded");
+ return SDL_FALSE;
+ }
+
+ if(!vkCreateWin32SurfaceKHR)
+ {
+ SDL_SetError(VK_KHR_WIN32_SURFACE_EXTENSION_NAME
+ " extension is not enabled in the Vulkan instance.");
+ return SDL_FALSE;
+ }
+ createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
+ createInfo.pNext = NULL;
+ createInfo.flags = 0;
+ createInfo.hinstance = windowData->hinstance;
+ createInfo.hwnd = windowData->hwnd;
+ result = vkCreateWin32SurfaceKHR(instance, &createInfo,
+ NULL, surface);
+ if(result != VK_SUCCESS)
+ {
+ SDL_SetError("vkCreateWin32SurfaceKHR failed: %s",
+ SDL_Vulkan_GetResultString(result));
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
+}
+
+#endif
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowsvulkan.h b/src/3rdparty/SDL2/src/video/windows/SDL_windowsvulkan.h
new file mode 100644
index 0000000..0acc0a9
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowsvulkan.h
@@ -0,0 +1,52 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/*
+ * @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's
+ * SDL_x11vulkan.h.
+ */
+
+#include "../../SDL_internal.h"
+
+#ifndef SDL_windowsvulkan_h_
+#define SDL_windowsvulkan_h_
+
+#include "../SDL_vulkan_internal.h"
+#include "../SDL_sysvideo.h"
+
+#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_WINDOWS
+
+int WIN_Vulkan_LoadLibrary(_THIS, const char *path);
+void WIN_Vulkan_UnloadLibrary(_THIS);
+SDL_bool WIN_Vulkan_GetInstanceExtensions(_THIS,
+ SDL_Window *window,
+ unsigned *count,
+ const char **names);
+SDL_bool WIN_Vulkan_CreateSurface(_THIS,
+ SDL_Window *window,
+ VkInstance instance,
+ VkSurfaceKHR *surface);
+
+#endif
+
+#endif /* SDL_windowsvulkan_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowswindow.c b/src/3rdparty/SDL2/src/video/windows/SDL_windowswindow.c
new file mode 100644
index 0000000..b082443
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowswindow.c
@@ -0,0 +1,970 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINDOWS
+
+#include "../../core/windows/SDL_windows.h"
+
+#include "SDL_assert.h"
+#include "../SDL_sysvideo.h"
+#include "../SDL_pixels_c.h"
+#include "../../events/SDL_keyboard_c.h"
+#include "../../events/SDL_mouse_c.h"
+
+#include "SDL_windowsvideo.h"
+#include "SDL_windowswindow.h"
+#include "SDL_hints.h"
+
+/* Dropfile support */
+#include <shellapi.h>
+
+/* This is included after SDL_windowsvideo.h, which includes windows.h */
+#include "SDL_syswm.h"
+
+/* Windows CE compatibility */
+#ifndef SWP_NOCOPYBITS
+#define SWP_NOCOPYBITS 0
+#endif
+
+/* Fake window to help with DirectInput events. */
+HWND SDL_HelperWindow = NULL;
+static WCHAR *SDL_HelperWindowClassName = TEXT("SDLHelperWindowInputCatcher");
+static WCHAR *SDL_HelperWindowName = TEXT("SDLHelperWindowInputMsgWindow");
+static ATOM SDL_HelperWindowClass = 0;
+
+/* For borderless Windows, still want the following flags:
+ - WS_CAPTION: this seems to enable the Windows minimize animation
+ - WS_SYSMENU: enables system context menu on task bar
+ - WS_MINIMIZEBOX: window will respond to Windows minimize commands sent to all windows, such as windows key + m, shaking title bar, etc.
+ This will also cause the task bar to overlap the window and other windowed behaviors, so only use this for windows that shouldn't appear to be fullscreen
+ */
+
+#define STYLE_BASIC (WS_CLIPSIBLINGS | WS_CLIPCHILDREN)
+#define STYLE_FULLSCREEN (WS_POPUP)
+#define STYLE_BORDERLESS (WS_POPUP)
+#define STYLE_BORDERLESS_WINDOWED (WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX)
+#define STYLE_NORMAL (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX)
+#define STYLE_RESIZABLE (WS_THICKFRAME | WS_MAXIMIZEBOX)
+#define STYLE_MASK (STYLE_FULLSCREEN | STYLE_BORDERLESS | STYLE_NORMAL | STYLE_RESIZABLE)
+
+static DWORD
+GetWindowStyle(SDL_Window * window)
+{
+ DWORD style = 0;
+
+ if (window->flags & SDL_WINDOW_FULLSCREEN) {
+ style |= STYLE_FULLSCREEN;
+ } else {
+ if (window->flags & SDL_WINDOW_BORDERLESS) {
+ /* SDL 2.1:
+ This behavior more closely matches other platform where the window is borderless
+ but still interacts with the window manager (e.g. task bar shows above it, it can
+ be resized to fit within usable desktop area, etc.) so this should be the behavior
+ for a future SDL release.
+
+ If you want a borderless window the size of the desktop that looks like a fullscreen
+ window, then you should use the SDL_WINDOW_FULLSCREEN_DESKTOP flag.
+ */
+ if (SDL_GetHintBoolean("SDL_BORDERLESS_WINDOWED_STYLE", SDL_FALSE)) {
+ style |= STYLE_BORDERLESS_WINDOWED;
+ } else {
+ style |= STYLE_BORDERLESS;
+ }
+ } else {
+ style |= STYLE_NORMAL;
+ }
+
+ /* You can have a borderless resizable window */
+ if (window->flags & SDL_WINDOW_RESIZABLE) {
+ style |= STYLE_RESIZABLE;
+ }
+ }
+ return style;
+}
+
+static void
+WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL menu, int *x, int *y, int *width, int *height, SDL_bool use_current)
+{
+ RECT rect;
+
+ rect.left = 0;
+ rect.top = 0;
+ rect.right = (use_current ? window->w : window->windowed.w);
+ rect.bottom = (use_current ? window->h : window->windowed.h);
+
+ /* borderless windows will have WM_NCCALCSIZE return 0 for the non-client area. When this happens, it looks like windows will send a resize message
+ expanding the window client area to the previous window + chrome size, so shouldn't need to adjust the window size for the set styles.
+ */
+ if (!(window->flags & SDL_WINDOW_BORDERLESS))
+ AdjustWindowRectEx(&rect, style, menu, 0);
+
+ *x = (use_current ? window->x : window->windowed.x) + rect.left;
+ *y = (use_current ? window->y : window->windowed.y) + rect.top;
+ *width = (rect.right - rect.left);
+ *height = (rect.bottom - rect.top);
+}
+
+static void
+WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width, int *height, SDL_bool use_current)
+{
+ SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+ HWND hwnd = data->hwnd;
+ DWORD style;
+ BOOL menu;
+
+ style = GetWindowLong(hwnd, GWL_STYLE);
+ menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
+ WIN_AdjustWindowRectWithStyle(window, style, menu, x, y, width, height, use_current);
+}
+
+static void
+WIN_SetWindowPositionInternal(_THIS, SDL_Window * window, UINT flags)
+{
+ SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+ HWND hwnd = data->hwnd;
+ HWND top;
+ int x, y;
+ int w, h;
+
+ /* Figure out what the window area will be */
+ if (SDL_ShouldAllowTopmost() && ((window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS) || (window->flags & SDL_WINDOW_ALWAYS_ON_TOP))) {
+ top = HWND_TOPMOST;
+ } else {
+ top = HWND_NOTOPMOST;
+ }
+
+ WIN_AdjustWindowRect(window, &x, &y, &w, &h, SDL_TRUE);
+
+ data->expected_resize = SDL_TRUE;
+ SetWindowPos(hwnd, top, x, y, w, h, flags);
+ data->expected_resize = SDL_FALSE;
+}
+
+static int
+SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, HWND parent, SDL_bool created)
+{
+ SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
+ SDL_WindowData *data;
+
+ /* Allocate the window data */
+ data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
+ if (!data) {
+ return SDL_OutOfMemory();
+ }
+ data->window = window;
+ data->hwnd = hwnd;
+ data->parent = parent;
+ data->hdc = GetDC(hwnd);
+ data->hinstance = (HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
+ data->created = created;
+ data->mouse_button_flags = 0;
+ data->videodata = videodata;
+ data->initializing = SDL_TRUE;
+
+ window->driverdata = data;
+
+ /* Associate the data with the window */
+ if (!SetProp(hwnd, TEXT("SDL_WindowData"), data)) {
+ ReleaseDC(hwnd, data->hdc);
+ SDL_free(data);
+ return WIN_SetError("SetProp() failed");
+ }
+
+ /* Set up the window proc function */
+#ifdef GWLP_WNDPROC
+ data->wndproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC);
+ if (data->wndproc == WIN_WindowProc) {
+ data->wndproc = NULL;
+ } else {
+ SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) WIN_WindowProc);
+ }
+#else
+ data->wndproc = (WNDPROC) GetWindowLong(hwnd, GWL_WNDPROC);
+ if (data->wndproc == WIN_WindowProc) {
+ data->wndproc = NULL;
+ } else {
+ SetWindowLong(hwnd, GWL_WNDPROC, (LONG_PTR) WIN_WindowProc);
+ }
+#endif
+
+ /* Fill in the SDL window with the window data */
+ {
+ RECT rect;
+ if (GetClientRect(hwnd, &rect)) {
+ int w = rect.right;
+ int h = rect.bottom;
+ if ((window->windowed.w && window->windowed.w != w) || (window->windowed.h && window->windowed.h != h)) {
+ /* We tried to create a window larger than the desktop and Windows didn't allow it. Override! */
+ int x, y;
+ int w, h;
+
+ /* Figure out what the window area will be */
+ WIN_AdjustWindowRect(window, &x, &y, &w, &h, SDL_FALSE);
+ SetWindowPos(hwnd, HWND_NOTOPMOST, x, y, w, h, SWP_NOCOPYBITS | SWP_NOZORDER | SWP_NOACTIVATE);
+ } else {
+ window->w = w;
+ window->h = h;
+ }
+ }
+ }
+ {
+ POINT point;
+ point.x = 0;
+ point.y = 0;
+ if (ClientToScreen(hwnd, &point)) {
+ window->x = point.x;
+ window->y = point.y;
+ }
+ }
+ {
+ DWORD style = GetWindowLong(hwnd, GWL_STYLE);
+ if (style & WS_VISIBLE) {
+ window->flags |= SDL_WINDOW_SHOWN;
+ } else {
+ window->flags &= ~SDL_WINDOW_SHOWN;
+ }
+ if (style & WS_POPUP) {
+ window->flags |= SDL_WINDOW_BORDERLESS;
+ } else {
+ window->flags &= ~SDL_WINDOW_BORDERLESS;
+ }
+ if (style & WS_THICKFRAME) {
+ window->flags |= SDL_WINDOW_RESIZABLE;
+ } else {
+ window->flags &= ~SDL_WINDOW_RESIZABLE;
+ }
+#ifdef WS_MAXIMIZE
+ if (style & WS_MAXIMIZE) {
+ window->flags |= SDL_WINDOW_MAXIMIZED;
+ } else
+#endif
+ {
+ window->flags &= ~SDL_WINDOW_MAXIMIZED;
+ }
+#ifdef WS_MINIMIZE
+ if (style & WS_MINIMIZE) {
+ window->flags |= SDL_WINDOW_MINIMIZED;
+ } else
+#endif
+ {
+ window->flags &= ~SDL_WINDOW_MINIMIZED;
+ }
+ }
+ if (GetFocus() == hwnd) {
+ window->flags |= SDL_WINDOW_INPUT_FOCUS;
+ SDL_SetKeyboardFocus(data->window);
+
+ if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
+ RECT rect;
+ GetClientRect(hwnd, &rect);
+ ClientToScreen(hwnd, (LPPOINT) & rect);
+ ClientToScreen(hwnd, (LPPOINT) & rect + 1);
+ ClipCursor(&rect);
+ }
+ }
+
+ /* Enable multi-touch */
+ if (videodata->RegisterTouchWindow) {
+ videodata->RegisterTouchWindow(hwnd, (TWF_FINETOUCH|TWF_WANTPALM));
+ }
+
+ /* Enable dropping files */
+ DragAcceptFiles(hwnd, TRUE);
+
+ data->initializing = SDL_FALSE;
+
+ /* All done! */
+ return 0;
+}
+
+
+
+int
+WIN_CreateWindow(_THIS, SDL_Window * window)
+{
+ HWND hwnd, parent = NULL;
+ DWORD style = STYLE_BASIC;
+ int x, y;
+ int w, h;
+
+ if (window->flags & SDL_WINDOW_SKIP_TASKBAR) {
+ parent = CreateWindow(SDL_Appname, TEXT(""), STYLE_BASIC, 0, 0, 32, 32, NULL, NULL, SDL_Instance, NULL);
+ }
+
+ style |= GetWindowStyle(window);
+
+ /* Figure out what the window area will be */
+ WIN_AdjustWindowRectWithStyle(window, style, FALSE, &x, &y, &w, &h, SDL_FALSE);
+
+ hwnd =
+ CreateWindow(SDL_Appname, TEXT(""), style, x, y, w, h, parent, NULL,
+ SDL_Instance, NULL);
+ if (!hwnd) {
+ return WIN_SetError("Couldn't create window");
+ }
+
+ WIN_PumpEvents(_this);
+
+ if (SetupWindowData(_this, window, hwnd, parent, SDL_TRUE) < 0) {
+ DestroyWindow(hwnd);
+ if (parent) {
+ DestroyWindow(parent);
+ }
+ return -1;
+ }
+
+ /* Inform Windows of the frame change so we can respond to WM_NCCALCSIZE */
+ SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
+
+ if (!(window->flags & SDL_WINDOW_OPENGL)) {
+ return 0;
+ }
+
+ /* The rest of this macro mess is for OpenGL or OpenGL ES windows */
+#if SDL_VIDEO_OPENGL_ES2
+ if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
+#if SDL_VIDEO_OPENGL_WGL
+ && (!_this->gl_data || WIN_GL_UseEGL(_this))
+#endif /* SDL_VIDEO_OPENGL_WGL */
+ ) {
+#if SDL_VIDEO_OPENGL_EGL
+ if (WIN_GLES_SetupWindow(_this, window) < 0) {
+ WIN_DestroyWindow(_this, window);
+ return -1;
+ }
+ return 0;
+#else
+ return SDL_SetError("Could not create GLES window surface (EGL support not configured)");
+#endif /* SDL_VIDEO_OPENGL_EGL */
+ }
+#endif /* SDL_VIDEO_OPENGL_ES2 */
+
+#if SDL_VIDEO_OPENGL_WGL
+ if (WIN_GL_SetupWindow(_this, window) < 0) {
+ WIN_DestroyWindow(_this, window);
+ return -1;
+ }
+#else
+ return SDL_SetError("Could not create GL window (WGL support not configured)");
+#endif
+
+ return 0;
+}
+
+int
+WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
+{
+ HWND hwnd = (HWND) data;
+ LPTSTR title;
+ int titleLen;
+
+ /* Query the title from the existing window */
+ titleLen = GetWindowTextLength(hwnd);
+ title = SDL_stack_alloc(TCHAR, titleLen + 1);
+ if (title) {
+ titleLen = GetWindowText(hwnd, title, titleLen);
+ } else {
+ titleLen = 0;
+ }
+ if (titleLen > 0) {
+ window->title = WIN_StringToUTF8(title);
+ }
+ if (title) {
+ SDL_stack_free(title);
+ }
+
+ if (SetupWindowData(_this, window, hwnd, GetParent(hwnd), SDL_FALSE) < 0) {
+ return -1;
+ }
+
+#if SDL_VIDEO_OPENGL_WGL
+ {
+ const char *hint = SDL_GetHint(SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT);
+ if (hint) {
+ /* This hint is a pointer (in string form) of the address of
+ the window to share a pixel format with
+ */
+ SDL_Window *otherWindow = NULL;
+ SDL_sscanf(hint, "%p", (void**)&otherWindow);
+
+ /* Do some error checking on the pointer */
+ if (otherWindow != NULL && otherWindow->magic == &_this->window_magic)
+ {
+ /* If the otherWindow has SDL_WINDOW_OPENGL set, set it for the new window as well */
+ if (otherWindow->flags & SDL_WINDOW_OPENGL)
+ {
+ window->flags |= SDL_WINDOW_OPENGL;
+ if(!WIN_GL_SetPixelFormatFrom(_this, otherWindow, window)) {
+ return -1;
+ }
+ }
+ }
+ }
+ }
+#endif
+ return 0;
+}
+
+void
+WIN_SetWindowTitle(_THIS, SDL_Window * window)
+{
+ HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
+ LPTSTR title = WIN_UTF8ToString(window->title);
+ SetWindowText(hwnd, title);
+ SDL_free(title);
+}
+
+void
+WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
+{
+ HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
+ HICON hicon = NULL;
+ BYTE *icon_bmp;
+ int icon_len, mask_len, y;
+ SDL_RWops *dst;
+
+ /* Create temporary buffer for ICONIMAGE structure */
+ mask_len = (icon->h * (icon->w + 7)/8);
+ icon_len = 40 + icon->h * icon->w * sizeof(Uint32) + mask_len;
+ icon_bmp = SDL_stack_alloc(BYTE, icon_len);
+ dst = SDL_RWFromMem(icon_bmp, icon_len);
+ if (!dst) {
+ SDL_stack_free(icon_bmp);
+ return;
+ }
+
+ /* Write the BITMAPINFO header */
+ SDL_WriteLE32(dst, 40);
+ SDL_WriteLE32(dst, icon->w);
+ SDL_WriteLE32(dst, icon->h * 2);
+ SDL_WriteLE16(dst, 1);
+ SDL_WriteLE16(dst, 32);
+ SDL_WriteLE32(dst, BI_RGB);
+ SDL_WriteLE32(dst, icon->h * icon->w * sizeof(Uint32));
+ SDL_WriteLE32(dst, 0);
+ SDL_WriteLE32(dst, 0);
+ SDL_WriteLE32(dst, 0);
+ SDL_WriteLE32(dst, 0);
+
+ /* Write the pixels upside down into the bitmap buffer */
+ SDL_assert(icon->format->format == SDL_PIXELFORMAT_ARGB8888);
+ y = icon->h;
+ while (y--) {
+ Uint8 *src = (Uint8 *) icon->pixels + y * icon->pitch;
+ SDL_RWwrite(dst, src, icon->w * sizeof(Uint32), 1);
+ }
+
+ /* Write the mask */
+ SDL_memset(icon_bmp + icon_len - mask_len, 0xFF, mask_len);
+
+ hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
+
+ SDL_RWclose(dst);
+ SDL_stack_free(icon_bmp);
+
+ /* Set the icon for the window */
+ SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
+
+ /* Set the icon in the task manager (should we do this?) */
+ SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
+}
+
+void
+WIN_SetWindowPosition(_THIS, SDL_Window * window)
+{
+ WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
+}
+
+void
+WIN_SetWindowSize(_THIS, SDL_Window * window)
+{
+ WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOACTIVATE);
+}
+
+int
+WIN_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right)
+{
+ HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
+ RECT rcClient, rcWindow;
+ POINT ptDiff;
+
+ /* rcClient stores the size of the inner window, while rcWindow stores the outer size relative to the top-left
+ * screen position; so the top/left values of rcClient are always {0,0} and bottom/right are {height,width} */
+ GetClientRect(hwnd, &rcClient);
+ GetWindowRect(hwnd, &rcWindow);
+
+ /* convert the top/left values to make them relative to
+ * the window; they will end up being slightly negative */
+ ptDiff.y = rcWindow.top;
+ ptDiff.x = rcWindow.left;
+
+ ScreenToClient(hwnd, &ptDiff);
+
+ rcWindow.top = ptDiff.y;
+ rcWindow.left = ptDiff.x;
+
+ /* convert the bottom/right values to make them relative to the window,
+ * these will be slightly bigger than the inner width/height */
+ ptDiff.y = rcWindow.bottom;
+ ptDiff.x = rcWindow.right;
+
+ ScreenToClient(hwnd, &ptDiff);
+
+ rcWindow.bottom = ptDiff.y;
+ rcWindow.right = ptDiff.x;
+
+ /* Now that both the inner and outer rects use the same coordinate system we can substract them to get the border size.
+ * Keep in mind that the top/left coordinates of rcWindow are negative because the border lies slightly before {0,0},
+ * so switch them around because SDL2 wants them in positive. */
+ *top = rcClient.top - rcWindow.top;
+ *left = rcClient.left - rcWindow.left;
+ *bottom = rcWindow.bottom - rcClient.bottom;
+ *right = rcWindow.right - rcClient.right;
+
+ return 0;
+}
+
+void
+WIN_ShowWindow(_THIS, SDL_Window * window)
+{
+ HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
+ ShowWindow(hwnd, SW_SHOW);
+}
+
+void
+WIN_HideWindow(_THIS, SDL_Window * window)
+{
+ HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
+ ShowWindow(hwnd, SW_HIDE);
+}
+
+void
+WIN_RaiseWindow(_THIS, SDL_Window * window)
+{
+ HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
+ SetForegroundWindow(hwnd);
+}
+
+void
+WIN_MaximizeWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+ HWND hwnd = data->hwnd;
+ data->expected_resize = SDL_TRUE;
+ ShowWindow(hwnd, SW_MAXIMIZE);
+ data->expected_resize = SDL_FALSE;
+}
+
+void
+WIN_MinimizeWindow(_THIS, SDL_Window * window)
+{
+ HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
+ ShowWindow(hwnd, SW_MINIMIZE);
+}
+
+void
+WIN_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
+{
+ SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+ HWND hwnd = data->hwnd;
+ DWORD style;
+
+ style = GetWindowLong(hwnd, GWL_STYLE);
+ style &= ~STYLE_MASK;
+ style |= GetWindowStyle(window);
+
+ data->in_border_change = SDL_TRUE;
+ SetWindowLong(hwnd, GWL_STYLE, style);
+ WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOACTIVATE);
+ data->in_border_change = SDL_FALSE;
+}
+
+void
+WIN_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable)
+{
+ SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+ HWND hwnd = data->hwnd;
+ DWORD style;
+
+ style = GetWindowLong(hwnd, GWL_STYLE);
+ style &= ~STYLE_MASK;
+ style |= GetWindowStyle(window);
+
+ SetWindowLong(hwnd, GWL_STYLE, style);
+}
+
+void
+WIN_RestoreWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+ HWND hwnd = data->hwnd;
+ data->expected_resize = SDL_TRUE;
+ ShowWindow(hwnd, SW_RESTORE);
+ data->expected_resize = SDL_FALSE;
+}
+
+void
+WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ HWND hwnd = data->hwnd;
+ SDL_Rect bounds;
+ DWORD style;
+ HWND top;
+ int x, y;
+ int w, h;
+
+ if (SDL_ShouldAllowTopmost() && ((window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS)) == (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_INPUT_FOCUS) || window->flags & SDL_WINDOW_ALWAYS_ON_TOP)) {
+ top = HWND_TOPMOST;
+ } else {
+ top = HWND_NOTOPMOST;
+ }
+
+ style = GetWindowLong(hwnd, GWL_STYLE);
+ style &= ~STYLE_MASK;
+ style |= GetWindowStyle(window);
+
+ WIN_GetDisplayBounds(_this, display, &bounds);
+
+ if (fullscreen) {
+ x = bounds.x;
+ y = bounds.y;
+ w = bounds.w;
+ h = bounds.h;
+
+ /* Unset the maximized flag. This fixes
+ https://bugzilla.libsdl.org/show_bug.cgi?id=3215
+ */
+ if (style & WS_MAXIMIZE) {
+ data->windowed_mode_was_maximized = SDL_TRUE;
+ style &= ~WS_MAXIMIZE;
+ }
+ } else {
+ BOOL menu;
+
+ /* Restore window-maximization state, as applicable.
+ Special care is taken to *not* do this if and when we're
+ alt-tab'ing away (to some other window; as indicated by
+ in_window_deactivation), otherwise
+ https://bugzilla.libsdl.org/show_bug.cgi?id=3215 can reproduce!
+ */
+ if (data->windowed_mode_was_maximized && !data->in_window_deactivation) {
+ style |= WS_MAXIMIZE;
+ data->windowed_mode_was_maximized = SDL_FALSE;
+ }
+
+ menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
+ WIN_AdjustWindowRectWithStyle(window, style, menu, &x, &y, &w, &h, SDL_FALSE);
+ }
+ SetWindowLong(hwnd, GWL_STYLE, style);
+ data->expected_resize = SDL_TRUE;
+ SetWindowPos(hwnd, top, x, y, w, h, SWP_NOCOPYBITS | SWP_NOACTIVATE);
+ data->expected_resize = SDL_FALSE;
+}
+
+int
+WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
+{
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
+ HDC hdc;
+ BOOL succeeded = FALSE;
+
+ hdc = CreateDC(data->DeviceName, NULL, NULL, NULL);
+ if (hdc) {
+ succeeded = SetDeviceGammaRamp(hdc, (LPVOID)ramp);
+ if (!succeeded) {
+ WIN_SetError("SetDeviceGammaRamp()");
+ }
+ DeleteDC(hdc);
+ }
+ return succeeded ? 0 : -1;
+}
+
+int
+WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
+{
+ SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+ SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
+ HDC hdc;
+ BOOL succeeded = FALSE;
+
+ hdc = CreateDC(data->DeviceName, NULL, NULL, NULL);
+ if (hdc) {
+ succeeded = GetDeviceGammaRamp(hdc, (LPVOID)ramp);
+ if (!succeeded) {
+ WIN_SetError("GetDeviceGammaRamp()");
+ }
+ DeleteDC(hdc);
+ }
+ return succeeded ? 0 : -1;
+}
+
+void
+WIN_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
+{
+ WIN_UpdateClipCursor(window);
+
+ if (window->flags & SDL_WINDOW_FULLSCREEN) {
+ UINT flags = SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE;
+
+ if (!(window->flags & SDL_WINDOW_SHOWN)) {
+ flags |= SWP_NOACTIVATE;
+ }
+ WIN_SetWindowPositionInternal(_this, window, flags);
+ }
+}
+
+void
+WIN_DestroyWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+
+ if (data) {
+ ReleaseDC(data->hwnd, data->hdc);
+ RemoveProp(data->hwnd, TEXT("SDL_WindowData"));
+ if (data->created) {
+ DestroyWindow(data->hwnd);
+ if (data->parent) {
+ DestroyWindow(data->parent);
+ }
+ } else {
+ /* Restore any original event handler... */
+ if (data->wndproc != NULL) {
+#ifdef GWLP_WNDPROC
+ SetWindowLongPtr(data->hwnd, GWLP_WNDPROC,
+ (LONG_PTR) data->wndproc);
+#else
+ SetWindowLong(data->hwnd, GWL_WNDPROC,
+ (LONG_PTR) data->wndproc);
+#endif
+ }
+ }
+ SDL_free(data);
+ }
+ window->driverdata = NULL;
+}
+
+SDL_bool
+WIN_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
+{
+ const SDL_WindowData *data = (const SDL_WindowData *) window->driverdata;
+ if (info->version.major <= SDL_MAJOR_VERSION) {
+ int versionnum = SDL_VERSIONNUM(info->version.major, info->version.minor, info->version.patch);
+
+ info->subsystem = SDL_SYSWM_WINDOWS;
+ info->info.win.window = data->hwnd;
+
+ if (versionnum >= SDL_VERSIONNUM(2, 0, 4)) {
+ info->info.win.hdc = data->hdc;
+ }
+
+ if (versionnum >= SDL_VERSIONNUM(2, 0, 5)) {
+ info->info.win.hinstance = data->hinstance;
+ }
+
+ return SDL_TRUE;
+ } else {
+ SDL_SetError("Application not compiled with SDL %d.%d",
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+ return SDL_FALSE;
+ }
+}
+
+
+/*
+ * Creates a HelperWindow used for DirectInput events.
+ */
+int
+SDL_HelperWindowCreate(void)
+{
+ HINSTANCE hInstance = GetModuleHandle(NULL);
+ WNDCLASS wce;
+
+ /* Make sure window isn't created twice. */
+ if (SDL_HelperWindow != NULL) {
+ return 0;
+ }
+
+ /* Create the class. */
+ SDL_zero(wce);
+ wce.lpfnWndProc = DefWindowProc;
+ wce.lpszClassName = (LPCWSTR) SDL_HelperWindowClassName;
+ wce.hInstance = hInstance;
+
+ /* Register the class. */
+ SDL_HelperWindowClass = RegisterClass(&wce);
+ if (SDL_HelperWindowClass == 0 && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) {
+ return WIN_SetError("Unable to create Helper Window Class");
+ }
+
+ /* Create the window. */
+ SDL_HelperWindow = CreateWindowEx(0, SDL_HelperWindowClassName,
+ SDL_HelperWindowName,
+ WS_OVERLAPPED, CW_USEDEFAULT,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ CW_USEDEFAULT, HWND_MESSAGE, NULL,
+ hInstance, NULL);
+ if (SDL_HelperWindow == NULL) {
+ UnregisterClass(SDL_HelperWindowClassName, hInstance);
+ return WIN_SetError("Unable to create Helper Window");
+ }
+
+ return 0;
+}
+
+
+/*
+ * Destroys the HelperWindow previously created with SDL_HelperWindowCreate.
+ */
+void
+SDL_HelperWindowDestroy(void)
+{
+ HINSTANCE hInstance = GetModuleHandle(NULL);
+
+ /* Destroy the window. */
+ if (SDL_HelperWindow != NULL) {
+ if (DestroyWindow(SDL_HelperWindow) == 0) {
+ WIN_SetError("Unable to destroy Helper Window");
+ return;
+ }
+ SDL_HelperWindow = NULL;
+ }
+
+ /* Unregister the class. */
+ if (SDL_HelperWindowClass != 0) {
+ if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) {
+ WIN_SetError("Unable to destroy Helper Window Class");
+ return;
+ }
+ SDL_HelperWindowClass = 0;
+ }
+}
+
+void WIN_OnWindowEnter(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+
+ if (!data || !data->hwnd) {
+ /* The window wasn't fully initialized */
+ return;
+ }
+
+ if (window->flags & SDL_WINDOW_ALWAYS_ON_TOP) {
+ WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOACTIVATE);
+ }
+
+#ifdef WM_MOUSELEAVE
+ {
+ TRACKMOUSEEVENT trackMouseEvent;
+
+ trackMouseEvent.cbSize = sizeof(TRACKMOUSEEVENT);
+ trackMouseEvent.dwFlags = TME_LEAVE;
+ trackMouseEvent.hwndTrack = data->hwnd;
+
+ TrackMouseEvent(&trackMouseEvent);
+ }
+#endif /* WM_MOUSELEAVE */
+}
+
+void
+WIN_UpdateClipCursor(SDL_Window *window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ if (data->focus_click_pending) {
+ return;
+ }
+
+ if ((mouse->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) &&
+ (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
+ if (mouse->relative_mode && !mouse->relative_mode_warp) {
+ LONG cx, cy;
+ RECT rect;
+ GetWindowRect(data->hwnd, &rect);
+
+ cx = (rect.left + rect.right) / 2;
+ cy = (rect.top + rect.bottom) / 2;
+
+ /* Make an absurdly small clip rect */
+ rect.left = cx - 1;
+ rect.right = cx + 1;
+ rect.top = cy - 1;
+ rect.bottom = cy + 1;
+
+ ClipCursor(&rect);
+ } else {
+ RECT rect;
+ if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) {
+ ClientToScreen(data->hwnd, (LPPOINT) & rect);
+ ClientToScreen(data->hwnd, (LPPOINT) & rect + 1);
+ ClipCursor(&rect);
+ }
+ }
+ } else {
+ ClipCursor(NULL);
+ }
+}
+
+int
+WIN_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
+{
+ return 0; /* just succeed, the real work is done elsewhere. */
+}
+
+int
+WIN_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
+{
+ const SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ const HWND hwnd = data->hwnd;
+ const LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
+
+ SDL_assert(style != 0);
+
+ if (opacity == 1.0f) {
+ /* want it fully opaque, just mark it unlayered if necessary. */
+ if (style & WS_EX_LAYERED) {
+ if (SetWindowLong(hwnd, GWL_EXSTYLE, style & ~WS_EX_LAYERED) == 0) {
+ return WIN_SetError("SetWindowLong()");
+ }
+ }
+ } else {
+ const BYTE alpha = (BYTE) ((int) (opacity * 255.0f));
+ /* want it transparent, mark it layered if necessary. */
+ if ((style & WS_EX_LAYERED) == 0) {
+ if (SetWindowLong(hwnd, GWL_EXSTYLE, style | WS_EX_LAYERED) == 0) {
+ return WIN_SetError("SetWindowLong()");
+ }
+ }
+
+ if (SetLayeredWindowAttributes(hwnd, 0, alpha, LWA_ALPHA) == 0) {
+ return WIN_SetError("SetLayeredWindowAttributes()");
+ }
+ }
+
+ return 0;
+}
+
+#endif /* SDL_VIDEO_DRIVER_WINDOWS */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/SDL_windowswindow.h b/src/3rdparty/SDL2/src/video/windows/SDL_windowswindow.h
new file mode 100644
index 0000000..0325abb
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/SDL_windowswindow.h
@@ -0,0 +1,84 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_windowswindow_h_
+#define SDL_windowswindow_h_
+
+#if SDL_VIDEO_OPENGL_EGL
+#include "../SDL_egl_c.h"
+#endif
+
+typedef struct
+{
+ SDL_Window *window;
+ HWND hwnd;
+ HWND parent;
+ HDC hdc;
+ HDC mdc;
+ HINSTANCE hinstance;
+ HBITMAP hbm;
+ WNDPROC wndproc;
+ SDL_bool created;
+ WPARAM mouse_button_flags;
+ SDL_bool initializing;
+ SDL_bool expected_resize;
+ SDL_bool in_border_change;
+ SDL_bool in_title_click;
+ Uint8 focus_click_pending;
+ SDL_bool windowed_mode_was_maximized;
+ SDL_bool in_window_deactivation;
+ struct SDL_VideoData *videodata;
+#if SDL_VIDEO_OPENGL_EGL
+ EGLSurface egl_surface;
+#endif
+} SDL_WindowData;
+
+extern int WIN_CreateWindow(_THIS, SDL_Window * window);
+extern int WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data);
+extern void WIN_SetWindowTitle(_THIS, SDL_Window * window);
+extern void WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
+extern void WIN_SetWindowPosition(_THIS, SDL_Window * window);
+extern void WIN_SetWindowSize(_THIS, SDL_Window * window);
+extern int WIN_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right);
+extern int WIN_SetWindowOpacity(_THIS, SDL_Window * window, float opacity);
+extern void WIN_ShowWindow(_THIS, SDL_Window * window);
+extern void WIN_HideWindow(_THIS, SDL_Window * window);
+extern void WIN_RaiseWindow(_THIS, SDL_Window * window);
+extern void WIN_MaximizeWindow(_THIS, SDL_Window * window);
+extern void WIN_MinimizeWindow(_THIS, SDL_Window * window);
+extern void WIN_RestoreWindow(_THIS, SDL_Window * window);
+extern void WIN_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
+extern void WIN_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
+extern void WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
+extern int WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
+extern int WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
+extern void WIN_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
+extern void WIN_DestroyWindow(_THIS, SDL_Window * window);
+extern SDL_bool WIN_GetWindowWMInfo(_THIS, SDL_Window * window,
+ struct SDL_SysWMinfo *info);
+extern void WIN_OnWindowEnter(_THIS, SDL_Window * window);
+extern void WIN_UpdateClipCursor(SDL_Window *window);
+extern int WIN_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
+
+#endif /* SDL_windowswindow_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/windows/wmmsg.h b/src/3rdparty/SDL2/src/video/windows/wmmsg.h
new file mode 100644
index 0000000..19c1bf4
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/windows/wmmsg.h
@@ -0,0 +1,1052 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#define MAX_WMMSG (sizeof(wmtab)/sizeof(wmtab[0]))
+
+char *wmtab[] = {
+ "WM_NULL",
+ "WM_CREATE",
+ "WM_DESTROY",
+ "WM_MOVE",
+ "UNKNOWN (4)",
+ "WM_SIZE",
+ "WM_ACTIVATE",
+ "WM_SETFOCUS",
+ "WM_KILLFOCUS",
+ "UNKNOWN (9)",
+ "WM_ENABLE",
+ "WM_SETREDRAW",
+ "WM_SETTEXT",
+ "WM_GETTEXT",
+ "WM_GETTEXTLENGTH",
+ "WM_PAINT",
+ "WM_CLOSE",
+ "WM_QUERYENDSESSION",
+ "WM_QUIT",
+ "WM_QUERYOPEN",
+ "WM_ERASEBKGND",
+ "WM_SYSCOLORCHANGE",
+ "WM_ENDSESSION",
+ "UNKNOWN (23)",
+ "WM_SHOWWINDOW",
+ "UNKNOWN (25)",
+ "WM_SETTINGCHANGE",
+ "WM_DEVMODECHANGE",
+ "WM_ACTIVATEAPP",
+ "WM_FONTCHANGE",
+ "WM_TIMECHANGE",
+ "WM_CANCELMODE",
+ "WM_SETCURSOR",
+ "WM_MOUSEACTIVATE",
+ "WM_CHILDACTIVATE",
+ "WM_QUEUESYNC",
+ "WM_GETMINMAXINFO",
+ "UNKNOWN (37)",
+ "WM_PAINTICON",
+ "WM_ICONERASEBKGND",
+ "WM_NEXTDLGCTL",
+ "UNKNOWN (41)",
+ "WM_SPOOLERSTATUS",
+ "WM_DRAWITEM",
+ "WM_MEASUREITEM",
+ "WM_DELETEITEM",
+ "WM_VKEYTOITEM",
+ "WM_CHARTOITEM",
+ "WM_SETFONT",
+ "WM_GETFONT",
+ "WM_SETHOTKEY",
+ "WM_GETHOTKEY",
+ "UNKNOWN (52)",
+ "UNKNOWN (53)",
+ "UNKNOWN (54)",
+ "WM_QUERYDRAGICON",
+ "UNKNOWN (56)",
+ "WM_COMPAREITEM",
+ "UNKNOWN (58)",
+ "UNKNOWN (59)",
+ "UNKNOWN (60)",
+ "WM_GETOBJECT",
+ "UNKNOWN (62)",
+ "UNKNOWN (63)",
+ "UNKNOWN (64)",
+ "WM_COMPACTING",
+ "UNKNOWN (66)",
+ "UNKNOWN (67)",
+ "WM_COMMNOTIFY",
+ "UNKNOWN (69)",
+ "WM_WINDOWPOSCHANGING",
+ "WM_WINDOWPOSCHANGED",
+ "WM_POWER",
+ "UNKNOWN (73)",
+ "WM_COPYDATA",
+ "WM_CANCELJOURNAL",
+ "UNKNOWN (76)",
+ "UNKNOWN (77)",
+ "WM_NOTIFY",
+ "UNKNOWN (79)",
+ "WM_INPUTLANGCHANGEREQUEST",
+ "WM_INPUTLANGCHANGE",
+ "WM_TCARD",
+ "WM_HELP",
+ "WM_USERCHANGED",
+ "WM_NOTIFYFORMAT",
+ "UNKNOWN (86)",
+ "UNKNOWN (87)",
+ "UNKNOWN (88)",
+ "UNKNOWN (89)",
+ "UNKNOWN (90)",
+ "UNKNOWN (91)",
+ "UNKNOWN (92)",
+ "UNKNOWN (93)",
+ "UNKNOWN (94)",
+ "UNKNOWN (95)",
+ "UNKNOWN (96)",
+ "UNKNOWN (97)",
+ "UNKNOWN (98)",
+ "UNKNOWN (99)",
+ "UNKNOWN (100)",
+ "UNKNOWN (101)",
+ "UNKNOWN (102)",
+ "UNKNOWN (103)",
+ "UNKNOWN (104)",
+ "UNKNOWN (105)",
+ "UNKNOWN (106)",
+ "UNKNOWN (107)",
+ "UNKNOWN (108)",
+ "UNKNOWN (109)",
+ "UNKNOWN (110)",
+ "UNKNOWN (111)",
+ "UNKNOWN (112)",
+ "UNKNOWN (113)",
+ "UNKNOWN (114)",
+ "UNKNOWN (115)",
+ "UNKNOWN (116)",
+ "UNKNOWN (117)",
+ "UNKNOWN (118)",
+ "UNKNOWN (119)",
+ "UNKNOWN (120)",
+ "UNKNOWN (121)",
+ "UNKNOWN (122)",
+ "WM_CONTEXTMENU",
+ "WM_STYLECHANGING",
+ "WM_STYLECHANGED",
+ "WM_DISPLAYCHANGE",
+ "WM_GETICON",
+ "WM_SETICON",
+ "WM_NCCREATE",
+ "WM_NCDESTROY",
+ "WM_NCCALCSIZE",
+ "WM_NCHITTEST",
+ "WM_NCPAINT",
+ "WM_NCACTIVATE",
+ "WM_GETDLGCODE",
+ "WM_SYNCPAINT",
+ "UNKNOWN (137)",
+ "UNKNOWN (138)",
+ "UNKNOWN (139)",
+ "UNKNOWN (140)",
+ "UNKNOWN (141)",
+ "UNKNOWN (142)",
+ "UNKNOWN (143)",
+ "UNKNOWN (144)",
+ "UNKNOWN (145)",
+ "UNKNOWN (146)",
+ "UNKNOWN (147)",
+ "UNKNOWN (148)",
+ "UNKNOWN (149)",
+ "UNKNOWN (150)",
+ "UNKNOWN (151)",
+ "UNKNOWN (152)",
+ "UNKNOWN (153)",
+ "UNKNOWN (154)",
+ "UNKNOWN (155)",
+ "UNKNOWN (156)",
+ "UNKNOWN (157)",
+ "UNKNOWN (158)",
+ "UNKNOWN (159)",
+ "WM_NCMOUSEMOVE",
+ "WM_NCLBUTTONDOWN",
+ "WM_NCLBUTTONUP",
+ "WM_NCLBUTTONDBLCLK",
+ "WM_NCRBUTTONDOWN",
+ "WM_NCRBUTTONUP",
+ "WM_NCRBUTTONDBLCLK",
+ "WM_NCMBUTTONDOWN",
+ "WM_NCMBUTTONUP",
+ "WM_NCMBUTTONDBLCLK",
+ "UNKNOWN (170)",
+ "WM_NCXBUTTONDOWN",
+ "WM_NCXBUTTONUP",
+ "WM_NCXBUTTONDBLCLK",
+ "WM_NCUAHDRAWCAPTION",
+ "WM_NCUAHDRAWFRAME",
+ "UNKNOWN (176)",
+ "UNKNOWN (177)",
+ "UNKNOWN (178)",
+ "UNKNOWN (179)",
+ "UNKNOWN (180)",
+ "UNKNOWN (181)",
+ "UNKNOWN (182)",
+ "UNKNOWN (183)",
+ "UNKNOWN (184)",
+ "UNKNOWN (185)",
+ "UNKNOWN (186)",
+ "UNKNOWN (187)",
+ "UNKNOWN (188)",
+ "UNKNOWN (189)",
+ "UNKNOWN (190)",
+ "UNKNOWN (191)",
+ "UNKNOWN (192)",
+ "UNKNOWN (193)",
+ "UNKNOWN (194)",
+ "UNKNOWN (195)",
+ "UNKNOWN (196)",
+ "UNKNOWN (197)",
+ "UNKNOWN (198)",
+ "UNKNOWN (199)",
+ "UNKNOWN (200)",
+ "UNKNOWN (201)",
+ "UNKNOWN (202)",
+ "UNKNOWN (203)",
+ "UNKNOWN (204)",
+ "UNKNOWN (205)",
+ "UNKNOWN (206)",
+ "UNKNOWN (207)",
+ "UNKNOWN (208)",
+ "UNKNOWN (209)",
+ "UNKNOWN (210)",
+ "UNKNOWN (211)",
+ "UNKNOWN (212)",
+ "UNKNOWN (213)",
+ "UNKNOWN (214)",
+ "UNKNOWN (215)",
+ "UNKNOWN (216)",
+ "UNKNOWN (217)",
+ "UNKNOWN (218)",
+ "UNKNOWN (219)",
+ "UNKNOWN (220)",
+ "UNKNOWN (221)",
+ "UNKNOWN (222)",
+ "UNKNOWN (223)",
+ "UNKNOWN (224)",
+ "UNKNOWN (225)",
+ "UNKNOWN (226)",
+ "UNKNOWN (227)",
+ "UNKNOWN (228)",
+ "UNKNOWN (229)",
+ "UNKNOWN (230)",
+ "UNKNOWN (231)",
+ "UNKNOWN (232)",
+ "UNKNOWN (233)",
+ "UNKNOWN (234)",
+ "UNKNOWN (235)",
+ "UNKNOWN (236)",
+ "UNKNOWN (237)",
+ "UNKNOWN (238)",
+ "UNKNOWN (239)",
+ "UNKNOWN (240)",
+ "UNKNOWN (241)",
+ "UNKNOWN (242)",
+ "UNKNOWN (243)",
+ "UNKNOWN (244)",
+ "UNKNOWN (245)",
+ "UNKNOWN (246)",
+ "UNKNOWN (247)",
+ "UNKNOWN (248)",
+ "UNKNOWN (249)",
+ "UNKNOWN (250)",
+ "UNKNOWN (251)",
+ "UNKNOWN (252)",
+ "UNKNOWN (253)",
+ "UNKNOWN (254)",
+ "WM_INPUT",
+ "WM_KEYDOWN",
+ "WM_KEYUP",
+ "WM_CHAR",
+ "WM_DEADCHAR",
+ "WM_SYSKEYDOWN",
+ "WM_SYSKEYUP",
+ "WM_SYSCHAR",
+ "WM_SYSDEADCHAR",
+ "WM_KEYLAST",
+ "UNKNOWN (265)",
+ "UNKNOWN (266)",
+ "UNKNOWN (267)",
+ "UNKNOWN (268)",
+ "UNKNOWN (269)",
+ "UNKNOWN (270)",
+ "UNKNOWN (271)",
+ "WM_INITDIALOG",
+ "WM_COMMAND",
+ "WM_SYSCOMMAND",
+ "WM_TIMER",
+ "WM_HSCROLL",
+ "WM_VSCROLL",
+ "WM_INITMENU",
+ "WM_INITMENUPOPUP",
+ "UNKNOWN (280)",
+ "WM_GESTURE",
+ "UNKNOWN (282)",
+ "UNKNOWN (283)",
+ "UNKNOWN (284)",
+ "UNKNOWN (285)",
+ "UNKNOWN (286)",
+ "WM_MENUSELECT",
+ "WM_MENUCHAR",
+ "WM_ENTERIDLE",
+ "WM_MENURBUTTONUP",
+ "WM_MENUDRAG",
+ "WM_MENUGETOBJECT",
+ "WM_UNINITMENUPOPUP",
+ "WM_MENUCOMMAND",
+ "UNKNOWN (295)",
+ "UNKNOWN (296)",
+ "UNKNOWN (297)",
+ "UNKNOWN (298)",
+ "UNKNOWN (299)",
+ "UNKNOWN (300)",
+ "UNKNOWN (301)",
+ "UNKNOWN (302)",
+ "UNKNOWN (303)",
+ "UNKNOWN (304)",
+ "UNKNOWN (305)",
+ "WM_CTLCOLORMSGBOX",
+ "WM_CTLCOLOREDIT",
+ "WM_CTLCOLORLISTBOX",
+ "WM_CTLCOLORBTN",
+ "WM_CTLCOLORDLG",
+ "WM_CTLCOLORSCROLLBAR",
+ "WM_CTLCOLORSTATIC",
+ "UNKNOWN (313)",
+ "UNKNOWN (314)",
+ "UNKNOWN (315)",
+ "UNKNOWN (316)",
+ "UNKNOWN (317)",
+ "UNKNOWN (318)",
+ "UNKNOWN (319)",
+ "UNKNOWN (320)",
+ "UNKNOWN (321)",
+ "UNKNOWN (322)",
+ "UNKNOWN (323)",
+ "UNKNOWN (324)",
+ "UNKNOWN (325)",
+ "UNKNOWN (326)",
+ "UNKNOWN (327)",
+ "UNKNOWN (328)",
+ "UNKNOWN (329)",
+ "UNKNOWN (330)",
+ "UNKNOWN (331)",
+ "UNKNOWN (332)",
+ "UNKNOWN (333)",
+ "UNKNOWN (334)",
+ "UNKNOWN (335)",
+ "UNKNOWN (336)",
+ "UNKNOWN (337)",
+ "UNKNOWN (338)",
+ "UNKNOWN (339)",
+ "UNKNOWN (340)",
+ "UNKNOWN (341)",
+ "UNKNOWN (342)",
+ "UNKNOWN (343)",
+ "UNKNOWN (344)",
+ "UNKNOWN (345)",
+ "UNKNOWN (346)",
+ "UNKNOWN (347)",
+ "UNKNOWN (348)",
+ "UNKNOWN (349)",
+ "UNKNOWN (350)",
+ "UNKNOWN (351)",
+ "UNKNOWN (352)",
+ "UNKNOWN (353)",
+ "UNKNOWN (354)",
+ "UNKNOWN (355)",
+ "UNKNOWN (356)",
+ "UNKNOWN (357)",
+ "UNKNOWN (358)",
+ "UNKNOWN (359)",
+ "UNKNOWN (360)",
+ "UNKNOWN (361)",
+ "UNKNOWN (362)",
+ "UNKNOWN (363)",
+ "UNKNOWN (364)",
+ "UNKNOWN (365)",
+ "UNKNOWN (366)",
+ "UNKNOWN (367)",
+ "UNKNOWN (368)",
+ "UNKNOWN (369)",
+ "UNKNOWN (370)",
+ "UNKNOWN (371)",
+ "UNKNOWN (372)",
+ "UNKNOWN (373)",
+ "UNKNOWN (374)",
+ "UNKNOWN (375)",
+ "UNKNOWN (376)",
+ "UNKNOWN (377)",
+ "UNKNOWN (378)",
+ "UNKNOWN (379)",
+ "UNKNOWN (380)",
+ "UNKNOWN (381)",
+ "UNKNOWN (382)",
+ "UNKNOWN (383)",
+ "UNKNOWN (384)",
+ "UNKNOWN (385)",
+ "UNKNOWN (386)",
+ "UNKNOWN (387)",
+ "UNKNOWN (388)",
+ "UNKNOWN (389)",
+ "UNKNOWN (390)",
+ "UNKNOWN (391)",
+ "UNKNOWN (392)",
+ "UNKNOWN (393)",
+ "UNKNOWN (394)",
+ "UNKNOWN (395)",
+ "UNKNOWN (396)",
+ "UNKNOWN (397)",
+ "UNKNOWN (398)",
+ "UNKNOWN (399)",
+ "UNKNOWN (400)",
+ "UNKNOWN (401)",
+ "UNKNOWN (402)",
+ "UNKNOWN (403)",
+ "UNKNOWN (404)",
+ "UNKNOWN (405)",
+ "UNKNOWN (406)",
+ "UNKNOWN (407)",
+ "UNKNOWN (408)",
+ "UNKNOWN (409)",
+ "UNKNOWN (410)",
+ "UNKNOWN (411)",
+ "UNKNOWN (412)",
+ "UNKNOWN (413)",
+ "UNKNOWN (414)",
+ "UNKNOWN (415)",
+ "UNKNOWN (416)",
+ "UNKNOWN (417)",
+ "UNKNOWN (418)",
+ "UNKNOWN (419)",
+ "UNKNOWN (420)",
+ "UNKNOWN (421)",
+ "UNKNOWN (422)",
+ "UNKNOWN (423)",
+ "UNKNOWN (424)",
+ "UNKNOWN (425)",
+ "UNKNOWN (426)",
+ "UNKNOWN (427)",
+ "UNKNOWN (428)",
+ "UNKNOWN (429)",
+ "UNKNOWN (430)",
+ "UNKNOWN (431)",
+ "UNKNOWN (432)",
+ "UNKNOWN (433)",
+ "UNKNOWN (434)",
+ "UNKNOWN (435)",
+ "UNKNOWN (436)",
+ "UNKNOWN (437)",
+ "UNKNOWN (438)",
+ "UNKNOWN (439)",
+ "UNKNOWN (440)",
+ "UNKNOWN (441)",
+ "UNKNOWN (442)",
+ "UNKNOWN (443)",
+ "UNKNOWN (444)",
+ "UNKNOWN (445)",
+ "UNKNOWN (446)",
+ "UNKNOWN (447)",
+ "UNKNOWN (448)",
+ "UNKNOWN (449)",
+ "UNKNOWN (450)",
+ "UNKNOWN (451)",
+ "UNKNOWN (452)",
+ "UNKNOWN (453)",
+ "UNKNOWN (454)",
+ "UNKNOWN (455)",
+ "UNKNOWN (456)",
+ "UNKNOWN (457)",
+ "UNKNOWN (458)",
+ "UNKNOWN (459)",
+ "UNKNOWN (460)",
+ "UNKNOWN (461)",
+ "UNKNOWN (462)",
+ "UNKNOWN (463)",
+ "UNKNOWN (464)",
+ "UNKNOWN (465)",
+ "UNKNOWN (466)",
+ "UNKNOWN (467)",
+ "UNKNOWN (468)",
+ "UNKNOWN (469)",
+ "UNKNOWN (470)",
+ "UNKNOWN (471)",
+ "UNKNOWN (472)",
+ "UNKNOWN (473)",
+ "UNKNOWN (474)",
+ "UNKNOWN (475)",
+ "UNKNOWN (476)",
+ "UNKNOWN (477)",
+ "UNKNOWN (478)",
+ "UNKNOWN (479)",
+ "UNKNOWN (480)",
+ "UNKNOWN (481)",
+ "UNKNOWN (482)",
+ "UNKNOWN (483)",
+ "UNKNOWN (484)",
+ "UNKNOWN (485)",
+ "UNKNOWN (486)",
+ "UNKNOWN (487)",
+ "UNKNOWN (488)",
+ "UNKNOWN (489)",
+ "UNKNOWN (490)",
+ "UNKNOWN (491)",
+ "UNKNOWN (492)",
+ "UNKNOWN (493)",
+ "UNKNOWN (494)",
+ "UNKNOWN (495)",
+ "UNKNOWN (496)",
+ "UNKNOWN (497)",
+ "UNKNOWN (498)",
+ "UNKNOWN (499)",
+ "UNKNOWN (500)",
+ "UNKNOWN (501)",
+ "UNKNOWN (502)",
+ "UNKNOWN (503)",
+ "UNKNOWN (504)",
+ "UNKNOWN (505)",
+ "UNKNOWN (506)",
+ "UNKNOWN (507)",
+ "UNKNOWN (508)",
+ "UNKNOWN (509)",
+ "UNKNOWN (510)",
+ "UNKNOWN (511)",
+ "WM_MOUSEMOVE",
+ "WM_LBUTTONDOWN",
+ "WM_LBUTTONUP",
+ "WM_LBUTTONDBLCLK",
+ "WM_RBUTTONDOWN",
+ "WM_RBUTTONUP",
+ "WM_RBUTTONDBLCLK",
+ "WM_MBUTTONDOWN",
+ "WM_MBUTTONUP",
+ "WM_MOUSELAST",
+ "WM_MOUSEWHEEL",
+ "WM_XBUTTONDOWN",
+ "WM_XBUTTONUP",
+ "UNKNOWN (525)",
+ "UNKNOWN (526)",
+ "UNKNOWN (527)",
+ "WM_PARENTNOTIFY",
+ "WM_ENTERMENULOOP",
+ "WM_EXITMENULOOP",
+ "WM_NEXTMENU",
+ "WM_SIZING",
+ "WM_CAPTURECHANGED",
+ "WM_MOVING",
+ "UNKNOWN (535)",
+ "WM_POWERBROADCAST",
+ "WM_DEVICECHANGE",
+ "UNKNOWN (538)",
+ "UNKNOWN (539)",
+ "UNKNOWN (540)",
+ "UNKNOWN (541)",
+ "UNKNOWN (542)",
+ "UNKNOWN (543)",
+ "WM_MDICREATE",
+ "WM_MDIDESTROY",
+ "WM_MDIACTIVATE",
+ "WM_MDIRESTORE",
+ "WM_MDINEXT",
+ "WM_MDIMAXIMIZE",
+ "WM_MDITILE",
+ "WM_MDICASCADE",
+ "WM_MDIICONARRANGE",
+ "WM_MDIGETACTIVE",
+ "UNKNOWN (554)",
+ "UNKNOWN (555)",
+ "UNKNOWN (556)",
+ "UNKNOWN (557)",
+ "UNKNOWN (558)",
+ "UNKNOWN (559)",
+ "WM_MDISETMENU",
+ "WM_ENTERSIZEMOVE",
+ "WM_EXITSIZEMOVE",
+ "WM_DROPFILES",
+ "WM_MDIREFRESHMENU",
+ "UNKNOWN (565)",
+ "UNKNOWN (566)",
+ "UNKNOWN (567)",
+ "WM_POINTERDEVICECHANGE",
+ "WM_POINTERDEVICEINRANGE",
+ "WM_POINTERDEVICEOUTOFRANGE",
+ "UNKNOWN (571)",
+ "UNKNOWN (572)",
+ "UNKNOWN (573)",
+ "UNKNOWN (574)",
+ "UNKNOWN (575)",
+ "WM_TOUCH",
+ "WM_NCPOINTERUPDATE",
+ "WM_NCPOINTERDOWN",
+ "WM_NCPOINTERUP",
+ "UNKNOWN (580)",
+ "WM_POINTERUPDATE",
+ "WM_POINTERDOWN",
+ "WM_POINTERUP",
+ "WM_POINTERENTER",
+ "WM_POINTERLEAVE",
+ "WM_POINTERACTIVATE",
+ "WM_POINTERCAPTURECHANGED",
+ "WM_TOUCHHITTESTING",
+ "WM_POINTERWHEEL",
+ "WM_POINTERHWHEEL",
+ "DM_POINTERHITTEST",
+ "UNKNOWN (592)",
+ "UNKNOWN (593)",
+ "UNKNOWN (594)",
+ "UNKNOWN (595)",
+ "UNKNOWN (596)",
+ "UNKNOWN (597)",
+ "UNKNOWN (598)",
+ "UNKNOWN (599)",
+ "UNKNOWN (600)",
+ "UNKNOWN (601)",
+ "UNKNOWN (602)",
+ "UNKNOWN (603)",
+ "UNKNOWN (604)",
+ "UNKNOWN (605)",
+ "UNKNOWN (606)",
+ "UNKNOWN (607)",
+ "UNKNOWN (608)",
+ "UNKNOWN (609)",
+ "UNKNOWN (610)",
+ "UNKNOWN (611)",
+ "UNKNOWN (612)",
+ "UNKNOWN (613)",
+ "UNKNOWN (614)",
+ "UNKNOWN (615)",
+ "UNKNOWN (616)",
+ "UNKNOWN (617)",
+ "UNKNOWN (618)",
+ "UNKNOWN (619)",
+ "UNKNOWN (620)",
+ "UNKNOWN (621)",
+ "UNKNOWN (622)",
+ "UNKNOWN (623)",
+ "UNKNOWN (624)",
+ "UNKNOWN (625)",
+ "UNKNOWN (626)",
+ "UNKNOWN (627)",
+ "UNKNOWN (628)",
+ "UNKNOWN (629)",
+ "UNKNOWN (630)",
+ "UNKNOWN (631)",
+ "UNKNOWN (632)",
+ "UNKNOWN (633)",
+ "UNKNOWN (634)",
+ "UNKNOWN (635)",
+ "UNKNOWN (636)",
+ "UNKNOWN (637)",
+ "UNKNOWN (638)",
+ "UNKNOWN (639)",
+ "UNKNOWN (640)",
+ "WM_IME_SETCONTEXT",
+ "WM_IME_NOTIFY",
+ "WM_IME_CONTROL",
+ "WM_IME_COMPOSITIONFULL",
+ "WM_IME_SELECT",
+ "WM_IME_CHAR",
+ "UNKNOWN (647)",
+ "WM_IME_REQUEST",
+ "UNKNOWN (649)",
+ "UNKNOWN (650)",
+ "UNKNOWN (651)",
+ "UNKNOWN (652)",
+ "UNKNOWN (653)",
+ "UNKNOWN (654)",
+ "UNKNOWN (655)",
+ "WM_IME_KEYDOWN",
+ "WM_IME_KEYUP",
+ "UNKNOWN (658)",
+ "UNKNOWN (659)",
+ "UNKNOWN (660)",
+ "UNKNOWN (661)",
+ "UNKNOWN (662)",
+ "UNKNOWN (663)",
+ "UNKNOWN (664)",
+ "UNKNOWN (665)",
+ "UNKNOWN (666)",
+ "UNKNOWN (667)",
+ "UNKNOWN (668)",
+ "UNKNOWN (669)",
+ "UNKNOWN (670)",
+ "UNKNOWN (671)",
+ "WM_NCMOUSEHOVER",
+ "WM_MOUSEHOVER",
+ "WM_NCMOUSELEAVE",
+ "WM_MOUSELEAVE",
+ "UNKNOWN (676)",
+ "UNKNOWN (677)",
+ "UNKNOWN (678)",
+ "UNKNOWN (679)",
+ "UNKNOWN (680)",
+ "UNKNOWN (681)",
+ "UNKNOWN (682)",
+ "UNKNOWN (683)",
+ "UNKNOWN (684)",
+ "UNKNOWN (685)",
+ "UNKNOWN (686)",
+ "UNKNOWN (687)",
+ "UNKNOWN (688)",
+ "WM_WTSSESSION_CHANGE",
+ "UNKNOWN (690)",
+ "UNKNOWN (691)",
+ "UNKNOWN (692)",
+ "UNKNOWN (693)",
+ "UNKNOWN (694)",
+ "UNKNOWN (695)",
+ "UNKNOWN (696)",
+ "UNKNOWN (697)",
+ "UNKNOWN (698)",
+ "UNKNOWN (699)",
+ "UNKNOWN (700)",
+ "UNKNOWN (701)",
+ "UNKNOWN (702)",
+ "UNKNOWN (703)",
+ "UNKNOWN (704)",
+ "UNKNOWN (705)",
+ "UNKNOWN (706)",
+ "UNKNOWN (707)",
+ "UNKNOWN (708)",
+ "UNKNOWN (709)",
+ "UNKNOWN (710)",
+ "UNKNOWN (711)",
+ "UNKNOWN (712)",
+ "UNKNOWN (713)",
+ "UNKNOWN (714)",
+ "UNKNOWN (715)",
+ "UNKNOWN (716)",
+ "UNKNOWN (717)",
+ "UNKNOWN (718)",
+ "UNKNOWN (719)",
+ "UNKNOWN (720)",
+ "UNKNOWN (721)",
+ "UNKNOWN (722)",
+ "UNKNOWN (723)",
+ "UNKNOWN (724)",
+ "UNKNOWN (725)",
+ "UNKNOWN (726)",
+ "UNKNOWN (727)",
+ "UNKNOWN (728)",
+ "UNKNOWN (729)",
+ "UNKNOWN (730)",
+ "UNKNOWN (731)",
+ "UNKNOWN (732)",
+ "UNKNOWN (733)",
+ "UNKNOWN (734)",
+ "UNKNOWN (735)",
+ "WM_DPICHANGED",
+ "UNKNOWN (737)",
+ "UNKNOWN (738)",
+ "UNKNOWN (739)",
+ "UNKNOWN (740)",
+ "UNKNOWN (741)",
+ "UNKNOWN (742)",
+ "UNKNOWN (743)",
+ "UNKNOWN (744)",
+ "UNKNOWN (745)",
+ "UNKNOWN (746)",
+ "UNKNOWN (747)",
+ "UNKNOWN (748)",
+ "UNKNOWN (749)",
+ "UNKNOWN (750)",
+ "UNKNOWN (751)",
+ "UNKNOWN (752)",
+ "UNKNOWN (753)",
+ "UNKNOWN (754)",
+ "UNKNOWN (755)",
+ "UNKNOWN (756)",
+ "UNKNOWN (757)",
+ "UNKNOWN (758)",
+ "UNKNOWN (759)",
+ "UNKNOWN (760)",
+ "UNKNOWN (761)",
+ "UNKNOWN (762)",
+ "UNKNOWN (763)",
+ "UNKNOWN (764)",
+ "UNKNOWN (765)",
+ "UNKNOWN (766)",
+ "UNKNOWN (767)",
+ "WM_CUT",
+ "WM_COPY",
+ "WM_PASTE",
+ "WM_CLEAR",
+ "WM_UNDO",
+ "WM_RENDERFORMAT",
+ "WM_RENDERALLFORMATS",
+ "WM_DESTROYCLIPBOARD",
+ "WM_DRAWCLIPBOARD",
+ "WM_PAINTCLIPBOARD",
+ "WM_VSCROLLCLIPBOARD",
+ "WM_SIZECLIPBOARD",
+ "WM_ASKCBFORMATNAME",
+ "WM_CHANGECBCHAIN",
+ "WM_HSCROLLCLIPBOARD",
+ "WM_QUERYNEWPALETTE",
+ "WM_PALETTEISCHANGING",
+ "WM_PALETTECHANGED",
+ "WM_HOTKEY",
+ "UNKNOWN (787)",
+ "UNKNOWN (788)",
+ "UNKNOWN (789)",
+ "UNKNOWN (790)",
+ "WM_PRINT",
+ "WM_PRINTCLIENT",
+ "WM_APPCOMMAND",
+ "WM_THEMECHANGED",
+ "UNKNOWN (795)",
+ "UNKNOWN (796)",
+ "WM_CLIPBOARDUPDATE",
+ "WM_DWMCOMPOSITIONCHANGED",
+ "WM_DWMNCRENDERINGCHANGED",
+ "WM_DWMCOLORIZATIONCOLORCHANGED",
+ "WM_DWMWINDOWMAXIMIZEDCHANGE",
+ "UNKNOWN (802)",
+ "WM_DWMSENDICONICTHUMBNAIL",
+ "UNKNOWN (804)",
+ "UNKNOWN (805)",
+ "WM_DWMSENDICONICLIVEPREVIEWBITMAP",
+ "UNKNOWN (807)",
+ "UNKNOWN (808)",
+ "UNKNOWN (809)",
+ "UNKNOWN (810)",
+ "UNKNOWN (811)",
+ "UNKNOWN (812)",
+ "UNKNOWN (813)",
+ "UNKNOWN (814)",
+ "UNKNOWN (815)",
+ "UNKNOWN (816)",
+ "UNKNOWN (817)",
+ "UNKNOWN (818)",
+ "UNKNOWN (819)",
+ "UNKNOWN (820)",
+ "UNKNOWN (821)",
+ "UNKNOWN (822)",
+ "UNKNOWN (823)",
+ "UNKNOWN (824)",
+ "UNKNOWN (825)",
+ "UNKNOWN (826)",
+ "UNKNOWN (827)",
+ "UNKNOWN (828)",
+ "UNKNOWN (829)",
+ "UNKNOWN (830)",
+ "WM_GETTITLEBARINFOEX",
+ "UNKNOWN (832)",
+ "UNKNOWN (833)",
+ "UNKNOWN (834)",
+ "UNKNOWN (835)",
+ "UNKNOWN (836)",
+ "UNKNOWN (837)",
+ "UNKNOWN (838)",
+ "UNKNOWN (839)",
+ "UNKNOWN (840)",
+ "UNKNOWN (841)",
+ "UNKNOWN (842)",
+ "UNKNOWN (843)",
+ "UNKNOWN (844)",
+ "UNKNOWN (845)",
+ "UNKNOWN (846)",
+ "UNKNOWN (847)",
+ "UNKNOWN (848)",
+ "UNKNOWN (849)",
+ "UNKNOWN (850)",
+ "UNKNOWN (851)",
+ "UNKNOWN (852)",
+ "UNKNOWN (853)",
+ "UNKNOWN (854)",
+ "UNKNOWN (855)",
+ "WM_HANDHELDFIRST",
+ "UNKNOWN (857)",
+ "UNKNOWN (858)",
+ "UNKNOWN (859)",
+ "UNKNOWN (860)",
+ "UNKNOWN (861)",
+ "UNKNOWN (862)",
+ "WM_HANDHELDLAST",
+ "WM_AFXFIRST",
+ "UNKNOWN (865)",
+ "UNKNOWN (866)",
+ "UNKNOWN (867)",
+ "UNKNOWN (868)",
+ "UNKNOWN (869)",
+ "UNKNOWN (870)",
+ "UNKNOWN (871)",
+ "UNKNOWN (872)",
+ "UNKNOWN (873)",
+ "UNKNOWN (874)",
+ "UNKNOWN (875)",
+ "UNKNOWN (876)",
+ "UNKNOWN (877)",
+ "UNKNOWN (878)",
+ "UNKNOWN (879)",
+ "UNKNOWN (880)",
+ "UNKNOWN (881)",
+ "UNKNOWN (882)",
+ "UNKNOWN (883)",
+ "UNKNOWN (884)",
+ "UNKNOWN (885)",
+ "UNKNOWN (886)",
+ "UNKNOWN (887)",
+ "UNKNOWN (888)",
+ "UNKNOWN (889)",
+ "UNKNOWN (890)",
+ "UNKNOWN (891)",
+ "UNKNOWN (892)",
+ "UNKNOWN (893)",
+ "UNKNOWN (894)",
+ "WM_AFXLAST",
+ "WM_PENWINFIRST",
+ "UNKNOWN (897)",
+ "UNKNOWN (898)",
+ "UNKNOWN (899)",
+ "UNKNOWN (900)",
+ "UNKNOWN (901)",
+ "UNKNOWN (902)",
+ "UNKNOWN (903)",
+ "UNKNOWN (904)",
+ "UNKNOWN (905)",
+ "UNKNOWN (906)",
+ "UNKNOWN (907)",
+ "UNKNOWN (908)",
+ "UNKNOWN (909)",
+ "UNKNOWN (910)",
+ "WM_PENWINLAST",
+ "UNKNOWN (912)",
+ "UNKNOWN (913)",
+ "UNKNOWN (914)",
+ "UNKNOWN (915)",
+ "UNKNOWN (916)",
+ "UNKNOWN (917)",
+ "UNKNOWN (918)",
+ "UNKNOWN (919)",
+ "UNKNOWN (920)",
+ "UNKNOWN (921)",
+ "UNKNOWN (922)",
+ "UNKNOWN (923)",
+ "UNKNOWN (924)",
+ "UNKNOWN (925)",
+ "UNKNOWN (926)",
+ "UNKNOWN (927)",
+ "UNKNOWN (928)",
+ "UNKNOWN (929)",
+ "UNKNOWN (930)",
+ "UNKNOWN (931)",
+ "UNKNOWN (932)",
+ "UNKNOWN (933)",
+ "UNKNOWN (934)",
+ "UNKNOWN (935)",
+ "UNKNOWN (936)",
+ "UNKNOWN (937)",
+ "UNKNOWN (938)",
+ "UNKNOWN (939)",
+ "UNKNOWN (940)",
+ "UNKNOWN (941)",
+ "UNKNOWN (942)",
+ "UNKNOWN (943)",
+ "UNKNOWN (944)",
+ "UNKNOWN (945)",
+ "UNKNOWN (946)",
+ "UNKNOWN (947)",
+ "UNKNOWN (948)",
+ "UNKNOWN (949)",
+ "UNKNOWN (950)",
+ "UNKNOWN (951)",
+ "UNKNOWN (952)",
+ "UNKNOWN (953)",
+ "UNKNOWN (954)",
+ "UNKNOWN (955)",
+ "UNKNOWN (956)",
+ "UNKNOWN (957)",
+ "UNKNOWN (958)",
+ "UNKNOWN (959)",
+ "UNKNOWN (960)",
+ "UNKNOWN (961)",
+ "UNKNOWN (962)",
+ "UNKNOWN (963)",
+ "UNKNOWN (964)",
+ "UNKNOWN (965)",
+ "UNKNOWN (966)",
+ "UNKNOWN (967)",
+ "UNKNOWN (968)",
+ "UNKNOWN (969)",
+ "UNKNOWN (970)",
+ "UNKNOWN (971)",
+ "UNKNOWN (972)",
+ "UNKNOWN (973)",
+ "UNKNOWN (974)",
+ "UNKNOWN (975)",
+ "UNKNOWN (976)",
+ "UNKNOWN (977)",
+ "UNKNOWN (978)",
+ "UNKNOWN (979)",
+ "UNKNOWN (980)",
+ "UNKNOWN (981)",
+ "UNKNOWN (982)",
+ "UNKNOWN (983)",
+ "UNKNOWN (984)",
+ "UNKNOWN (985)",
+ "UNKNOWN (986)",
+ "UNKNOWN (987)",
+ "UNKNOWN (988)",
+ "UNKNOWN (989)",
+ "UNKNOWN (990)",
+ "UNKNOWN (991)",
+ "UNKNOWN (992)",
+ "UNKNOWN (993)",
+ "UNKNOWN (994)",
+ "UNKNOWN (995)",
+ "UNKNOWN (996)",
+ "UNKNOWN (997)",
+ "UNKNOWN (998)",
+ "UNKNOWN (999)",
+ "UNKNOWN (1000)",
+ "UNKNOWN (1001)",
+ "UNKNOWN (1002)",
+ "UNKNOWN (1003)",
+ "UNKNOWN (1004)",
+ "UNKNOWN (1005)",
+ "UNKNOWN (1006)",
+ "UNKNOWN (1007)",
+ "UNKNOWN (1008)",
+ "UNKNOWN (1009)",
+ "UNKNOWN (1010)",
+ "UNKNOWN (1011)",
+ "UNKNOWN (1012)",
+ "UNKNOWN (1013)",
+ "UNKNOWN (1014)",
+ "UNKNOWN (1015)",
+ "UNKNOWN (1016)",
+ "UNKNOWN (1017)",
+ "UNKNOWN (1018)",
+ "UNKNOWN (1019)",
+ "UNKNOWN (1020)",
+ "UNKNOWN (1021)",
+ "UNKNOWN (1022)",
+ "UNKNOWN (1023)",
+ "WM_USER"
+};
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/winrt/SDL_winrtevents.cpp b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtevents.cpp
new file mode 100644
index 0000000..370e8c5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtevents.cpp
@@ -0,0 +1,154 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINRT
+
+/*
+ * Windows includes:
+ */
+#include <Windows.h>
+using namespace Windows::UI::Core;
+using Windows::UI::Core::CoreCursor;
+
+/*
+ * SDL includes:
+ */
+#include "SDL_winrtevents_c.h"
+#include "../../core/winrt/SDL_winrtapp_common.h"
+#include "../../core/winrt/SDL_winrtapp_direct3d.h"
+#include "../../core/winrt/SDL_winrtapp_xaml.h"
+#include "SDL_assert.h"
+#include "SDL_system.h"
+
+extern "C" {
+#include "../../thread/SDL_systhread.h"
+#include "../SDL_sysvideo.h"
+#include "../../events/SDL_events_c.h"
+}
+
+
+/* Forward declarations */
+static void WINRT_YieldXAMLThread();
+
+
+/* Global event management */
+
+void
+WINRT_PumpEvents(_THIS)
+{
+ if (SDL_WinRTGlobalApp) {
+ SDL_WinRTGlobalApp->PumpEvents();
+ } else if (WINRT_XAMLWasEnabled) {
+ WINRT_YieldXAMLThread();
+ }
+}
+
+
+/* XAML Thread management */
+
+enum SDL_XAMLAppThreadState
+{
+ ThreadState_NotLaunched = 0,
+ ThreadState_Running,
+ ThreadState_Yielding
+};
+
+static SDL_XAMLAppThreadState _threadState = ThreadState_NotLaunched;
+static SDL_Thread * _XAMLThread = nullptr;
+static SDL_mutex * _mutex = nullptr;
+static SDL_cond * _cond = nullptr;
+
+static void
+WINRT_YieldXAMLThread()
+{
+ SDL_LockMutex(_mutex);
+ SDL_assert(_threadState == ThreadState_Running);
+ _threadState = ThreadState_Yielding;
+ SDL_UnlockMutex(_mutex);
+
+ SDL_CondSignal(_cond);
+
+ SDL_LockMutex(_mutex);
+ while (_threadState != ThreadState_Running) {
+ SDL_CondWait(_cond, _mutex);
+ }
+ SDL_UnlockMutex(_mutex);
+}
+
+static int
+WINRT_XAMLThreadMain(void * userdata)
+{
+ // TODO, WinRT: pass the C-style main() a reasonably realistic
+ // representation of command line arguments.
+ int argc = 0;
+ char **argv = NULL;
+ return WINRT_SDLAppEntryPoint(argc, argv);
+}
+
+void
+WINRT_CycleXAMLThread(void)
+{
+ switch (_threadState) {
+ case ThreadState_NotLaunched:
+ {
+ _cond = SDL_CreateCond();
+
+ _mutex = SDL_CreateMutex();
+ _threadState = ThreadState_Running;
+ _XAMLThread = SDL_CreateThreadInternal(WINRT_XAMLThreadMain, "SDL/XAML App Thread", 0, nullptr);
+
+ SDL_LockMutex(_mutex);
+ while (_threadState != ThreadState_Yielding) {
+ SDL_CondWait(_cond, _mutex);
+ }
+ SDL_UnlockMutex(_mutex);
+
+ break;
+ }
+
+ case ThreadState_Running:
+ {
+ SDL_assert(false);
+ break;
+ }
+
+ case ThreadState_Yielding:
+ {
+ SDL_LockMutex(_mutex);
+ SDL_assert(_threadState == ThreadState_Yielding);
+ _threadState = ThreadState_Running;
+ SDL_UnlockMutex(_mutex);
+
+ SDL_CondSignal(_cond);
+
+ SDL_LockMutex(_mutex);
+ while (_threadState != ThreadState_Yielding) {
+ SDL_CondWait(_cond, _mutex);
+ }
+ SDL_UnlockMutex(_mutex);
+ }
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_WINRT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/winrt/SDL_winrtevents_c.h b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtevents_c.h
new file mode 100644
index 0000000..8b346ec
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtevents_c.h
@@ -0,0 +1,82 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+extern "C" {
+#include "../SDL_sysvideo.h"
+}
+
+/*
+ * Internal-use, C-style functions:
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void WINRT_InitTouch(_THIS);
+extern void WINRT_PumpEvents(_THIS);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+/*
+ * Internal-use, C++/CX functions:
+ */
+#ifdef __cplusplus_winrt
+
+/* Pointers (Mice, Touch, etc.) */
+typedef enum {
+ NormalizeZeroToOne,
+ TransformToSDLWindowSize
+} WINRT_CursorNormalizationType;
+extern Windows::Foundation::Point WINRT_TransformCursorPosition(SDL_Window * window,
+ Windows::Foundation::Point rawPosition,
+ WINRT_CursorNormalizationType normalization);
+extern Uint8 WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt);
+extern void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
+extern void WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
+extern void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
+extern void WINRT_ProcessPointerEnteredEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
+extern void WINRT_ProcessPointerExitedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
+extern void WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint);
+extern void WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices::Input::MouseEventArgs ^args);
+
+/* Keyboard */
+extern void WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args);
+extern void WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args);
+extern void WINRT_ProcessCharacterReceivedEvent(Windows::UI::Core::CharacterReceivedEventArgs ^args);
+
+#if NTDDI_VERSION >= NTDDI_WIN10
+extern SDL_bool WINRT_HasScreenKeyboardSupport(_THIS);
+extern void WINRT_ShowScreenKeyboard(_THIS, SDL_Window *window);
+extern void WINRT_HideScreenKeyboard(_THIS, SDL_Window *window);
+extern SDL_bool WINRT_IsScreenKeyboardShown(_THIS, SDL_Window *window);
+#endif // NTDDI_VERSION >= ...
+
+/* XAML Thread Management */
+extern void WINRT_CycleXAMLThread(void);
+
+#endif // ifdef __cplusplus_winrt
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/winrt/SDL_winrtgamebar.cpp b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtgamebar.cpp
new file mode 100644
index 0000000..9617111
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtgamebar.cpp
@@ -0,0 +1,196 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINRT
+
+/* Windows includes */
+#include <roapi.h>
+#include <windows.foundation.h>
+#include <EventToken.h>
+
+
+/* SDL includes */
+extern "C" {
+#include "SDL_mouse.h"
+#include "../SDL_sysvideo.h"
+}
+#include "SDL_winrtvideo_cpp.h"
+
+
+/* Game Bar events can come in off the main thread. Use the following
+ WinRT CoreDispatcher to deal with them on SDL's thread.
+*/
+static Platform::WeakReference WINRT_MainThreadDispatcher;
+
+
+/* Win10's initial SDK (the 10.0.10240.0 release) does not include references
+ to Game Bar APIs, as the Game Bar was released via Win10 10.0.10586.0.
+
+ Declare its WinRT/COM interface here, to allow compilation with earlier
+ Windows SDKs.
+*/
+MIDL_INTERFACE("1DB9A292-CC78-4173-BE45-B61E67283EA7")
+IGameBarStatics_ : public IInspectable
+{
+public:
+ virtual HRESULT STDMETHODCALLTYPE add_VisibilityChanged(
+ __FIEventHandler_1_IInspectable *handler,
+ Windows::Foundation::EventRegistrationToken *token) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE remove_VisibilityChanged(
+ Windows::Foundation::EventRegistrationToken token) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE add_IsInputRedirectedChanged(
+ __FIEventHandler_1_IInspectable *handler,
+ Windows::Foundation::EventRegistrationToken *token) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE remove_IsInputRedirectedChanged(
+ Windows::Foundation::EventRegistrationToken token) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE get_Visible(
+ boolean *value) = 0;
+
+ virtual HRESULT STDMETHODCALLTYPE get_IsInputRedirected(
+ boolean *value) = 0;
+};
+
+/* Declare the game bar's COM GUID */
+static GUID IID_IGameBarStatics_ = { MAKELONG(0xA292, 0x1DB9), 0xCC78, 0x4173, { 0xBE, 0x45, 0xB6, 0x1E, 0x67, 0x28, 0x3E, 0xA7 } };
+
+/* Retrieves a pointer to the game bar, or NULL if it is not available.
+ If a pointer is returned, it's ->Release() method must be called
+ after the caller has finished using it.
+*/
+static IGameBarStatics_ *
+WINRT_GetGameBar()
+{
+ wchar_t *wClassName = L"Windows.Gaming.UI.GameBar";
+ HSTRING hClassName;
+ IActivationFactory *pActivationFactory = NULL;
+ IGameBarStatics_ *pGameBar = NULL;
+ HRESULT hr;
+
+ hr = ::WindowsCreateString(wClassName, (UINT32)wcslen(wClassName), &hClassName);
+ if (FAILED(hr)) {
+ goto done;
+ }
+
+ hr = Windows::Foundation::GetActivationFactory(hClassName, &pActivationFactory);
+ if (FAILED(hr)) {
+ goto done;
+ }
+
+ pActivationFactory->QueryInterface(IID_IGameBarStatics_, (void **) &pGameBar);
+
+done:
+ if (pActivationFactory) {
+ pActivationFactory->Release();
+ }
+ if (hClassName) {
+ ::WindowsDeleteString(hClassName);
+ }
+ return pGameBar;
+}
+
+static void
+WINRT_HandleGameBarIsInputRedirected_MainThread()
+{
+ IGameBarStatics_ *gameBar;
+ boolean isInputRedirected = 0;
+ if (!WINRT_MainThreadDispatcher) {
+ /* The game bar event handler has been deregistered! */
+ return;
+ }
+ gameBar = WINRT_GetGameBar();
+ if (!gameBar) {
+ /* Shouldn't happen, but just in case... */
+ return;
+ }
+ if (SUCCEEDED(gameBar->get_IsInputRedirected(&isInputRedirected))) {
+ if ( ! isInputRedirected) {
+ /* Input-control is now back to the SDL app. Restore the cursor,
+ in case Windows does not (it does not in either Win10
+ 10.0.10240.0 or 10.0.10586.0, maybe later version(s) too.
+ */
+ SDL_Cursor *cursor = SDL_GetCursor();
+ SDL_SetCursor(cursor);
+ }
+ }
+ gameBar->Release();
+}
+
+static void
+WINRT_HandleGameBarIsInputRedirected_NonMainThread(Platform::Object ^ o1, Platform::Object ^o2)
+{
+ Windows::UI::Core::CoreDispatcher ^dispatcher = WINRT_MainThreadDispatcher.Resolve<Windows::UI::Core::CoreDispatcher>();
+ if (dispatcher) {
+ dispatcher->RunAsync(
+ Windows::UI::Core::CoreDispatcherPriority::Normal,
+ ref new Windows::UI::Core::DispatchedHandler(&WINRT_HandleGameBarIsInputRedirected_MainThread));
+ }
+}
+
+void
+WINRT_InitGameBar(_THIS)
+{
+ SDL_VideoData *driverdata = (SDL_VideoData *)_this->driverdata;
+ IGameBarStatics_ *gameBar = WINRT_GetGameBar();
+ if (gameBar) {
+ /* GameBar.IsInputRedirected events can come in via something other than
+ the main/SDL thread.
+
+ Get a WinRT 'CoreDispatcher' that can be used to call back into the
+ SDL thread.
+ */
+ WINRT_MainThreadDispatcher = Windows::UI::Core::CoreWindow::GetForCurrentThread()->Dispatcher;
+ Windows::Foundation::EventHandler<Platform::Object ^> ^handler = \
+ ref new Windows::Foundation::EventHandler<Platform::Object ^>(&WINRT_HandleGameBarIsInputRedirected_NonMainThread);
+ __FIEventHandler_1_IInspectable * pHandler = reinterpret_cast<__FIEventHandler_1_IInspectable *>(handler);
+ gameBar->add_IsInputRedirectedChanged(pHandler, &driverdata->gameBarIsInputRedirectedToken);
+ gameBar->Release();
+ }
+}
+
+void
+WINRT_QuitGameBar(_THIS)
+{
+ SDL_VideoData *driverdata;
+ IGameBarStatics_ *gameBar;
+ if (!_this || !_this->driverdata) {
+ return;
+ }
+ gameBar = WINRT_GetGameBar();
+ if (!gameBar) {
+ return;
+ }
+ driverdata = (SDL_VideoData *)_this->driverdata;
+ if (driverdata->gameBarIsInputRedirectedToken.Value) {
+ gameBar->remove_IsInputRedirectedChanged(driverdata->gameBarIsInputRedirectedToken);
+ driverdata->gameBarIsInputRedirectedToken.Value = 0;
+ }
+ WINRT_MainThreadDispatcher = nullptr;
+ gameBar->Release();
+}
+
+#endif /* SDL_VIDEO_DRIVER_WINRT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/winrt/SDL_winrtgamebar_cpp.h b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtgamebar_cpp.h
new file mode 100644
index 0000000..a3e4777
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtgamebar_cpp.h
@@ -0,0 +1,35 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#ifndef SDL_winrtgamebar_h_
+#define SDL_winrtgamebar_h_
+
+#ifdef __cplusplus
+/* These are exported as C++ functions, rather than C, to fix a compilation
+ bug with MSVC 2013, for Windows 8.x builds. */
+extern void WINRT_InitGameBar(_THIS);
+extern void WINRT_QuitGameBar(_THIS);
+#endif
+
+#endif /* SDL_winrtgamebar_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/winrt/SDL_winrtkeyboard.cpp b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtkeyboard.cpp
new file mode 100644
index 0000000..34f2421
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtkeyboard.cpp
@@ -0,0 +1,430 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINRT
+
+/* Windows-specific includes */
+#include <Windows.h>
+#include <agile.h>
+
+
+/* SDL-specific includes */
+#include "SDL.h"
+#include "SDL_winrtevents_c.h"
+
+extern "C" {
+#include "../../events/scancodes_windows.h"
+#include "../../events/SDL_keyboard_c.h"
+}
+
+
+static SDL_Scancode WinRT_Official_Keycodes[] = {
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.None -- 0 */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.LeftButton -- 1 */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.RightButton -- 2 */
+ SDL_SCANCODE_CANCEL, /* VirtualKey.Cancel -- 3 */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.MiddleButton -- 4 */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.XButton1 -- 5 */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.XButton2 -- 6 */
+ SDL_SCANCODE_UNKNOWN, /* -- 7 */
+ SDL_SCANCODE_BACKSPACE, /* VirtualKey.Back -- 8 */
+ SDL_SCANCODE_TAB, /* VirtualKey.Tab -- 9 */
+ SDL_SCANCODE_UNKNOWN, /* -- 10 */
+ SDL_SCANCODE_UNKNOWN, /* -- 11 */
+ SDL_SCANCODE_CLEAR, /* VirtualKey.Clear -- 12 */
+ SDL_SCANCODE_RETURN, /* VirtualKey.Enter -- 13 */
+ SDL_SCANCODE_UNKNOWN, /* -- 14 */
+ SDL_SCANCODE_UNKNOWN, /* -- 15 */
+ SDL_SCANCODE_LSHIFT, /* VirtualKey.Shift -- 16 */
+ SDL_SCANCODE_LCTRL, /* VirtualKey.Control -- 17 */
+ SDL_SCANCODE_MENU, /* VirtualKey.Menu -- 18 */
+ SDL_SCANCODE_PAUSE, /* VirtualKey.Pause -- 19 */
+ SDL_SCANCODE_CAPSLOCK, /* VirtualKey.CapitalLock -- 20 */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.Kana or VirtualKey.Hangul -- 21 */
+ SDL_SCANCODE_UNKNOWN, /* -- 22 */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.Junja -- 23 */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.Final -- 24 */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.Hanja or VirtualKey.Kanji -- 25 */
+ SDL_SCANCODE_UNKNOWN, /* -- 26 */
+ SDL_SCANCODE_ESCAPE, /* VirtualKey.Escape -- 27 */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.Convert -- 28 */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.NonConvert -- 29 */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.Accept -- 30 */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.ModeChange -- 31 (maybe SDL_SCANCODE_MODE ?) */
+ SDL_SCANCODE_SPACE, /* VirtualKey.Space -- 32 */
+ SDL_SCANCODE_PAGEUP, /* VirtualKey.PageUp -- 33 */
+ SDL_SCANCODE_PAGEDOWN, /* VirtualKey.PageDown -- 34 */
+ SDL_SCANCODE_END, /* VirtualKey.End -- 35 */
+ SDL_SCANCODE_HOME, /* VirtualKey.Home -- 36 */
+ SDL_SCANCODE_LEFT, /* VirtualKey.Left -- 37 */
+ SDL_SCANCODE_UP, /* VirtualKey.Up -- 38 */
+ SDL_SCANCODE_RIGHT, /* VirtualKey.Right -- 39 */
+ SDL_SCANCODE_DOWN, /* VirtualKey.Down -- 40 */
+ SDL_SCANCODE_SELECT, /* VirtualKey.Select -- 41 */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.Print -- 42 (maybe SDL_SCANCODE_PRINTSCREEN ?) */
+ SDL_SCANCODE_EXECUTE, /* VirtualKey.Execute -- 43 */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.Snapshot -- 44 */
+ SDL_SCANCODE_INSERT, /* VirtualKey.Insert -- 45 */
+ SDL_SCANCODE_DELETE, /* VirtualKey.Delete -- 46 */
+ SDL_SCANCODE_HELP, /* VirtualKey.Help -- 47 */
+ SDL_SCANCODE_0, /* VirtualKey.Number0 -- 48 */
+ SDL_SCANCODE_1, /* VirtualKey.Number1 -- 49 */
+ SDL_SCANCODE_2, /* VirtualKey.Number2 -- 50 */
+ SDL_SCANCODE_3, /* VirtualKey.Number3 -- 51 */
+ SDL_SCANCODE_4, /* VirtualKey.Number4 -- 52 */
+ SDL_SCANCODE_5, /* VirtualKey.Number5 -- 53 */
+ SDL_SCANCODE_6, /* VirtualKey.Number6 -- 54 */
+ SDL_SCANCODE_7, /* VirtualKey.Number7 -- 55 */
+ SDL_SCANCODE_8, /* VirtualKey.Number8 -- 56 */
+ SDL_SCANCODE_9, /* VirtualKey.Number9 -- 57 */
+ SDL_SCANCODE_UNKNOWN, /* -- 58 */
+ SDL_SCANCODE_UNKNOWN, /* -- 59 */
+ SDL_SCANCODE_UNKNOWN, /* -- 60 */
+ SDL_SCANCODE_UNKNOWN, /* -- 61 */
+ SDL_SCANCODE_UNKNOWN, /* -- 62 */
+ SDL_SCANCODE_UNKNOWN, /* -- 63 */
+ SDL_SCANCODE_UNKNOWN, /* -- 64 */
+ SDL_SCANCODE_A, /* VirtualKey.A -- 65 */
+ SDL_SCANCODE_B, /* VirtualKey.B -- 66 */
+ SDL_SCANCODE_C, /* VirtualKey.C -- 67 */
+ SDL_SCANCODE_D, /* VirtualKey.D -- 68 */
+ SDL_SCANCODE_E, /* VirtualKey.E -- 69 */
+ SDL_SCANCODE_F, /* VirtualKey.F -- 70 */
+ SDL_SCANCODE_G, /* VirtualKey.G -- 71 */
+ SDL_SCANCODE_H, /* VirtualKey.H -- 72 */
+ SDL_SCANCODE_I, /* VirtualKey.I -- 73 */
+ SDL_SCANCODE_J, /* VirtualKey.J -- 74 */
+ SDL_SCANCODE_K, /* VirtualKey.K -- 75 */
+ SDL_SCANCODE_L, /* VirtualKey.L -- 76 */
+ SDL_SCANCODE_M, /* VirtualKey.M -- 77 */
+ SDL_SCANCODE_N, /* VirtualKey.N -- 78 */
+ SDL_SCANCODE_O, /* VirtualKey.O -- 79 */
+ SDL_SCANCODE_P, /* VirtualKey.P -- 80 */
+ SDL_SCANCODE_Q, /* VirtualKey.Q -- 81 */
+ SDL_SCANCODE_R, /* VirtualKey.R -- 82 */
+ SDL_SCANCODE_S, /* VirtualKey.S -- 83 */
+ SDL_SCANCODE_T, /* VirtualKey.T -- 84 */
+ SDL_SCANCODE_U, /* VirtualKey.U -- 85 */
+ SDL_SCANCODE_V, /* VirtualKey.V -- 86 */
+ SDL_SCANCODE_W, /* VirtualKey.W -- 87 */
+ SDL_SCANCODE_X, /* VirtualKey.X -- 88 */
+ SDL_SCANCODE_Y, /* VirtualKey.Y -- 89 */
+ SDL_SCANCODE_Z, /* VirtualKey.Z -- 90 */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.LeftWindows -- 91 (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_LGUI ?) */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.RightWindows -- 92 (maybe SDL_SCANCODE_APPLICATION or SDL_SCANCODE_RGUI ?) */
+ SDL_SCANCODE_APPLICATION, /* VirtualKey.Application -- 93 */
+ SDL_SCANCODE_UNKNOWN, /* -- 94 */
+ SDL_SCANCODE_SLEEP, /* VirtualKey.Sleep -- 95 */
+ SDL_SCANCODE_KP_0, /* VirtualKey.NumberPad0 -- 96 */
+ SDL_SCANCODE_KP_1, /* VirtualKey.NumberPad1 -- 97 */
+ SDL_SCANCODE_KP_2, /* VirtualKey.NumberPad2 -- 98 */
+ SDL_SCANCODE_KP_3, /* VirtualKey.NumberPad3 -- 99 */
+ SDL_SCANCODE_KP_4, /* VirtualKey.NumberPad4 -- 100 */
+ SDL_SCANCODE_KP_5, /* VirtualKey.NumberPad5 -- 101 */
+ SDL_SCANCODE_KP_6, /* VirtualKey.NumberPad6 -- 102 */
+ SDL_SCANCODE_KP_7, /* VirtualKey.NumberPad7 -- 103 */
+ SDL_SCANCODE_KP_8, /* VirtualKey.NumberPad8 -- 104 */
+ SDL_SCANCODE_KP_9, /* VirtualKey.NumberPad9 -- 105 */
+ SDL_SCANCODE_KP_MULTIPLY, /* VirtualKey.Multiply -- 106 */
+ SDL_SCANCODE_KP_PLUS, /* VirtualKey.Add -- 107 */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.Separator -- 108 */
+ SDL_SCANCODE_KP_MINUS, /* VirtualKey.Subtract -- 109 */
+ SDL_SCANCODE_UNKNOWN, /* VirtualKey.Decimal -- 110 (maybe SDL_SCANCODE_DECIMALSEPARATOR, SDL_SCANCODE_KP_DECIMAL, or SDL_SCANCODE_KP_PERIOD ?) */
+ SDL_SCANCODE_KP_DIVIDE, /* VirtualKey.Divide -- 111 */
+ SDL_SCANCODE_F1, /* VirtualKey.F1 -- 112 */
+ SDL_SCANCODE_F2, /* VirtualKey.F2 -- 113 */
+ SDL_SCANCODE_F3, /* VirtualKey.F3 -- 114 */
+ SDL_SCANCODE_F4, /* VirtualKey.F4 -- 115 */
+ SDL_SCANCODE_F5, /* VirtualKey.F5 -- 116 */
+ SDL_SCANCODE_F6, /* VirtualKey.F6 -- 117 */
+ SDL_SCANCODE_F7, /* VirtualKey.F7 -- 118 */
+ SDL_SCANCODE_F8, /* VirtualKey.F8 -- 119 */
+ SDL_SCANCODE_F9, /* VirtualKey.F9 -- 120 */
+ SDL_SCANCODE_F10, /* VirtualKey.F10 -- 121 */
+ SDL_SCANCODE_F11, /* VirtualKey.F11 -- 122 */
+ SDL_SCANCODE_F12, /* VirtualKey.F12 -- 123 */
+ SDL_SCANCODE_F13, /* VirtualKey.F13 -- 124 */
+ SDL_SCANCODE_F14, /* VirtualKey.F14 -- 125 */
+ SDL_SCANCODE_F15, /* VirtualKey.F15 -- 126 */
+ SDL_SCANCODE_F16, /* VirtualKey.F16 -- 127 */
+ SDL_SCANCODE_F17, /* VirtualKey.F17 -- 128 */
+ SDL_SCANCODE_F18, /* VirtualKey.F18 -- 129 */
+ SDL_SCANCODE_F19, /* VirtualKey.F19 -- 130 */
+ SDL_SCANCODE_F20, /* VirtualKey.F20 -- 131 */
+ SDL_SCANCODE_F21, /* VirtualKey.F21 -- 132 */
+ SDL_SCANCODE_F22, /* VirtualKey.F22 -- 133 */
+ SDL_SCANCODE_F23, /* VirtualKey.F23 -- 134 */
+ SDL_SCANCODE_F24, /* VirtualKey.F24 -- 135 */
+ SDL_SCANCODE_UNKNOWN, /* -- 136 */
+ SDL_SCANCODE_UNKNOWN, /* -- 137 */
+ SDL_SCANCODE_UNKNOWN, /* -- 138 */
+ SDL_SCANCODE_UNKNOWN, /* -- 139 */
+ SDL_SCANCODE_UNKNOWN, /* -- 140 */
+ SDL_SCANCODE_UNKNOWN, /* -- 141 */
+ SDL_SCANCODE_UNKNOWN, /* -- 142 */
+ SDL_SCANCODE_UNKNOWN, /* -- 143 */
+ SDL_SCANCODE_NUMLOCKCLEAR, /* VirtualKey.NumberKeyLock -- 144 */
+ SDL_SCANCODE_SCROLLLOCK, /* VirtualKey.Scroll -- 145 */
+ SDL_SCANCODE_UNKNOWN, /* -- 146 */
+ SDL_SCANCODE_UNKNOWN, /* -- 147 */
+ SDL_SCANCODE_UNKNOWN, /* -- 148 */
+ SDL_SCANCODE_UNKNOWN, /* -- 149 */
+ SDL_SCANCODE_UNKNOWN, /* -- 150 */
+ SDL_SCANCODE_UNKNOWN, /* -- 151 */
+ SDL_SCANCODE_UNKNOWN, /* -- 152 */
+ SDL_SCANCODE_UNKNOWN, /* -- 153 */
+ SDL_SCANCODE_UNKNOWN, /* -- 154 */
+ SDL_SCANCODE_UNKNOWN, /* -- 155 */
+ SDL_SCANCODE_UNKNOWN, /* -- 156 */
+ SDL_SCANCODE_UNKNOWN, /* -- 157 */
+ SDL_SCANCODE_UNKNOWN, /* -- 158 */
+ SDL_SCANCODE_UNKNOWN, /* -- 159 */
+ SDL_SCANCODE_LSHIFT, /* VirtualKey.LeftShift -- 160 */
+ SDL_SCANCODE_RSHIFT, /* VirtualKey.RightShift -- 161 */
+ SDL_SCANCODE_LCTRL, /* VirtualKey.LeftControl -- 162 */
+ SDL_SCANCODE_RCTRL, /* VirtualKey.RightControl -- 163 */
+ SDL_SCANCODE_MENU, /* VirtualKey.LeftMenu -- 164 */
+ SDL_SCANCODE_MENU, /* VirtualKey.RightMenu -- 165 */
+ SDL_SCANCODE_AC_BACK, /* VirtualKey.GoBack -- 166 : The go back key. */
+ SDL_SCANCODE_AC_FORWARD, /* VirtualKey.GoForward -- 167 : The go forward key. */
+ SDL_SCANCODE_AC_REFRESH, /* VirtualKey.Refresh -- 168 : The refresh key. */
+ SDL_SCANCODE_AC_STOP, /* VirtualKey.Stop -- 169 : The stop key. */
+ SDL_SCANCODE_AC_SEARCH, /* VirtualKey.Search -- 170 : The search key. */
+ SDL_SCANCODE_AC_BOOKMARKS, /* VirtualKey.Favorites -- 171 : The favorites key. */
+ SDL_SCANCODE_AC_HOME /* VirtualKey.GoHome -- 172 : The go home key. */
+};
+
+/* Attempt to translate a keycode that isn't listed in WinRT's VirtualKey enum.
+ */
+static SDL_Scancode
+WINRT_TranslateUnofficialKeycode(int keycode)
+{
+ switch (keycode) {
+ case 173: return SDL_SCANCODE_MUTE; /* VK_VOLUME_MUTE */
+ case 174: return SDL_SCANCODE_VOLUMEDOWN; /* VK_VOLUME_DOWN */
+ case 175: return SDL_SCANCODE_VOLUMEUP; /* VK_VOLUME_UP */
+ case 176: return SDL_SCANCODE_AUDIONEXT; /* VK_MEDIA_NEXT_TRACK */
+ case 177: return SDL_SCANCODE_AUDIOPREV; /* VK_MEDIA_PREV_TRACK */
+ // case 178: return ; /* VK_MEDIA_STOP */
+ case 179: return SDL_SCANCODE_AUDIOPLAY; /* VK_MEDIA_PLAY_PAUSE */
+ case 180: return SDL_SCANCODE_MAIL; /* VK_LAUNCH_MAIL */
+ case 181: return SDL_SCANCODE_MEDIASELECT; /* VK_LAUNCH_MEDIA_SELECT */
+ // case 182: return ; /* VK_LAUNCH_APP1 */
+ case 183: return SDL_SCANCODE_CALCULATOR; /* VK_LAUNCH_APP2 */
+ // case 184: return ; /* ... reserved ... */
+ // case 185: return ; /* ... reserved ... */
+ case 186: return SDL_SCANCODE_SEMICOLON; /* VK_OEM_1, ';:' key on US standard keyboards */
+ case 187: return SDL_SCANCODE_EQUALS; /* VK_OEM_PLUS */
+ case 188: return SDL_SCANCODE_COMMA; /* VK_OEM_COMMA */
+ case 189: return SDL_SCANCODE_MINUS; /* VK_OEM_MINUS */
+ case 190: return SDL_SCANCODE_PERIOD; /* VK_OEM_PERIOD */
+ case 191: return SDL_SCANCODE_SLASH; /* VK_OEM_2, '/?' key on US standard keyboards */
+ case 192: return SDL_SCANCODE_GRAVE; /* VK_OEM_3, '`~' key on US standard keyboards */
+ // ?
+ // ... reserved or unassigned ...
+ // ?
+ case 219: return SDL_SCANCODE_LEFTBRACKET; /* VK_OEM_4, '[{' key on US standard keyboards */
+ case 220: return SDL_SCANCODE_BACKSLASH; /* VK_OEM_5, '\|' key on US standard keyboards */
+ case 221: return SDL_SCANCODE_RIGHTBRACKET; /* VK_OEM_6, ']}' key on US standard keyboards */
+ case 222: return SDL_SCANCODE_APOSTROPHE; /* VK_OEM_7, 'single/double quote' on US standard keyboards */
+ default: break;
+ }
+ return SDL_SCANCODE_UNKNOWN;
+}
+
+static SDL_Scancode
+WINRT_TranslateKeycode(int keycode, unsigned int nativeScancode)
+{
+ // TODO, WinRT: try filling out the WinRT keycode table as much as possible, using the Win32 table for interpretation hints
+
+ SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
+
+ /* HACK ALERT: At least one VirtualKey constant (Shift) with a left/right
+ * designation might not get reported with its correct handedness, however
+ * its hardware scan code can fill in the gaps. If this is detected,
+ * use the hardware scan code to try telling if the left, or the right
+ * side's key was used.
+ *
+ * If Microsoft ever allows MapVirtualKey or MapVirtualKeyEx to be used
+ * in WinRT apps, or something similar to these (it doesn't appear to be,
+ * at least not for Windows [Phone] 8/8.1, as of Oct 24, 2014), then this
+ * hack might become deprecated, or obsolete.
+ */
+ if (nativeScancode < SDL_arraysize(windows_scancode_table)) {
+ switch (keycode) {
+ case 16: // VirtualKey.Shift
+ switch (windows_scancode_table[nativeScancode]) {
+ case SDL_SCANCODE_LSHIFT:
+ case SDL_SCANCODE_RSHIFT:
+ return windows_scancode_table[nativeScancode];
+ }
+ break;
+
+ // Add others, as necessary.
+ //
+ // Unfortunately, this hack doesn't seem to work in determining
+ // handedness with Control keys.
+
+ default:
+ break;
+ }
+ }
+
+ /* Try to get a documented, WinRT, 'VirtualKey' next (as documented at
+ http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.virtualkey.aspx ).
+ If that fails, fall back to a Win32 virtual key.
+ If that fails, attempt to fall back to a scancode-derived key.
+ */
+ if (keycode < SDL_arraysize(WinRT_Official_Keycodes)) {
+ scancode = WinRT_Official_Keycodes[keycode];
+ }
+ if (scancode == SDL_SCANCODE_UNKNOWN) {
+ scancode = WINRT_TranslateUnofficialKeycode(keycode);
+ }
+ if (scancode == SDL_SCANCODE_UNKNOWN) {
+ if (nativeScancode < SDL_arraysize(windows_scancode_table)) {
+ scancode = windows_scancode_table[nativeScancode];
+ }
+ }
+ /*
+ if (scancode == SDL_SCANCODE_UNKNOWN) {
+ SDL_Log("WinRT TranslateKeycode, unknown keycode=%d\n", (int)keycode);
+ }
+ */
+ return scancode;
+}
+
+void
+WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args)
+{
+ SDL_Scancode sdlScancode = WINRT_TranslateKeycode((int)args->VirtualKey, args->KeyStatus.ScanCode);
+#if 0
+ SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
+ SDL_Log("key down, handled=%s, ext?=%s, released?=%s, menu key down?=%s, "
+ "repeat count=%d, native scan code=0x%x, was down?=%s, vkey=%d, "
+ "sdl scan code=%d (%s), sdl key code=%d (%s)\n",
+ (args->Handled ? "1" : "0"),
+ (args->KeyStatus.IsExtendedKey ? "1" : "0"),
+ (args->KeyStatus.IsKeyReleased ? "1" : "0"),
+ (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
+ args->KeyStatus.RepeatCount,
+ args->KeyStatus.ScanCode,
+ (args->KeyStatus.WasKeyDown ? "1" : "0"),
+ args->VirtualKey,
+ sdlScancode,
+ SDL_GetScancodeName(sdlScancode),
+ keycode,
+ SDL_GetKeyName(keycode));
+ //args->Handled = true;
+#endif
+ SDL_SendKeyboardKey(SDL_PRESSED, sdlScancode);
+}
+
+void
+WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args)
+{
+ SDL_Scancode sdlScancode = WINRT_TranslateKeycode((int)args->VirtualKey, args->KeyStatus.ScanCode);
+#if 0
+ SDL_Keycode keycode = SDL_GetKeyFromScancode(sdlScancode);
+ SDL_Log("key up, handled=%s, ext?=%s, released?=%s, menu key down?=%s, "
+ "repeat count=%d, native scan code=0x%x, was down?=%s, vkey=%d, "
+ "sdl scan code=%d (%s), sdl key code=%d (%s)\n",
+ (args->Handled ? "1" : "0"),
+ (args->KeyStatus.IsExtendedKey ? "1" : "0"),
+ (args->KeyStatus.IsKeyReleased ? "1" : "0"),
+ (args->KeyStatus.IsMenuKeyDown ? "1" : "0"),
+ args->KeyStatus.RepeatCount,
+ args->KeyStatus.ScanCode,
+ (args->KeyStatus.WasKeyDown ? "1" : "0"),
+ args->VirtualKey,
+ sdlScancode,
+ SDL_GetScancodeName(sdlScancode),
+ keycode,
+ SDL_GetKeyName(keycode));
+ //args->Handled = true;
+#endif
+ SDL_SendKeyboardKey(SDL_RELEASED, sdlScancode);
+}
+
+void
+WINRT_ProcessCharacterReceivedEvent(Windows::UI::Core::CharacterReceivedEventArgs ^args)
+{
+ wchar_t src_ucs2[2];
+ char dest_utf8[16];
+ int result;
+
+ /* Setup src */
+ src_ucs2[0] = args->KeyCode;
+ src_ucs2[1] = L'\0';
+
+ /* Convert the text, then send an SDL_TEXTINPUT event. */
+ result = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)&src_ucs2, -1, (LPSTR)dest_utf8, sizeof(dest_utf8), NULL, NULL);
+ if (result > 0) {
+ SDL_SendKeyboardText(dest_utf8);
+ }
+}
+
+
+#if NTDDI_VERSION >= NTDDI_WIN10
+
+SDL_bool WINRT_HasScreenKeyboardSupport(_THIS)
+{
+ return SDL_TRUE;
+}
+
+void WINRT_ShowScreenKeyboard(_THIS, SDL_Window *window)
+{
+ using namespace Windows::UI::ViewManagement;
+ InputPane ^ inputPane = InputPane::GetForCurrentView();
+ if (inputPane) {
+ inputPane->TryShow();
+ }
+}
+
+void WINRT_HideScreenKeyboard(_THIS, SDL_Window *window)
+{
+ using namespace Windows::UI::ViewManagement;
+ InputPane ^ inputPane = InputPane::GetForCurrentView();
+ if (inputPane) {
+ inputPane->TryHide();
+ }
+}
+
+SDL_bool WINRT_IsScreenKeyboardShown(_THIS, SDL_Window *window)
+{
+ using namespace Windows::UI::ViewManagement;
+ InputPane ^ inputPane = InputPane::GetForCurrentView();
+ if (inputPane) {
+ // dludwig@pobox.com: checking inputPane->Visible doesn't seem to detect visibility,
+ // at least not on the Windows Phone 10.0.10240.0 emulator. Checking
+ // the size of inputPane->OccludedRect, however, does seem to work.
+ Windows::Foundation::Rect rect = inputPane->OccludedRect;
+ if (rect.Width > 0 && rect.Height > 0) {
+ return SDL_TRUE;
+ }
+ }
+ return SDL_FALSE;
+}
+
+#endif // NTDDI_VERSION >= ...
+
+#endif // SDL_VIDEO_DRIVER_WINRT
diff --git a/src/3rdparty/SDL2/src/video/winrt/SDL_winrtmessagebox.cpp b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtmessagebox.cpp
new file mode 100644
index 0000000..3576a3f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtmessagebox.cpp
@@ -0,0 +1,112 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINRT
+
+extern "C" {
+#include "SDL_messagebox.h"
+#include "../../core/windows/SDL_windows.h"
+}
+
+#include "SDL_winrtevents_c.h"
+
+#include <windows.ui.popups.h>
+using namespace Platform;
+using namespace Windows::Foundation;
+using namespace Windows::UI::Popups;
+
+static String ^
+WINRT_UTF8ToPlatformString(const char * str)
+{
+ wchar_t * wstr = WIN_UTF8ToString(str);
+ String ^ rtstr = ref new String(wstr);
+ SDL_free(wstr);
+ return rtstr;
+}
+
+extern "C" int
+WINRT_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
+{
+#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) && (NTDDI_VERSION == NTDDI_WIN8)
+ /* Sadly, Windows Phone 8 doesn't include the MessageDialog class that
+ * Windows 8.x/RT does, even though MSDN's reference documentation for
+ * Windows Phone 8 mentions it.
+ *
+ * The .NET runtime on Windows Phone 8 does, however, include a
+ * MessageBox class. Perhaps this could be called, somehow?
+ */
+ return SDL_SetError("SDL_messagebox support is not available for Windows Phone 8.0");
+#else
+ SDL_VideoDevice *_this = SDL_GetVideoDevice();
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+ const int maxbuttons = 2;
+ const char * platform = "Windows Phone 8.1+";
+#else
+ const int maxbuttons = 3;
+ const char * platform = "Windows 8.x";
+#endif
+
+ if (messageboxdata->numbuttons > maxbuttons) {
+ return SDL_SetError("WinRT's MessageDialog only supports %d buttons, at most, on %s. %d were requested.",
+ maxbuttons, platform, messageboxdata->numbuttons);
+ }
+
+ /* Build a MessageDialog object and its buttons */
+ MessageDialog ^ dialog = ref new MessageDialog(WINRT_UTF8ToPlatformString(messageboxdata->message));
+ dialog->Title = WINRT_UTF8ToPlatformString(messageboxdata->title);
+ for (int i = 0; i < messageboxdata->numbuttons; ++i) {
+ UICommand ^ button = ref new UICommand(WINRT_UTF8ToPlatformString(messageboxdata->buttons[i].text));
+ button->Id = safe_cast<IntPtr>(i);
+ dialog->Commands->Append(button);
+ if (messageboxdata->buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
+ dialog->CancelCommandIndex = i;
+ }
+ if (messageboxdata->buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
+ dialog->DefaultCommandIndex = i;
+ }
+ }
+
+ /* Display the MessageDialog, then wait for it to be closed */
+ /* TODO, WinRT: Find a way to redraw MessageDialog instances if a GPU device-reset occurs during the following event-loop */
+ auto operation = dialog->ShowAsync();
+ while (operation->Status == Windows::Foundation::AsyncStatus::Started) {
+ WINRT_PumpEvents(_this);
+ }
+
+ /* Retrieve results from the MessageDialog and process them accordingly */
+ if (operation->Status != Windows::Foundation::AsyncStatus::Completed) {
+ return SDL_SetError("An unknown error occurred in displaying the WinRT MessageDialog");
+ }
+ if (buttonid) {
+ IntPtr results = safe_cast<IntPtr>(operation->GetResults()->Id);
+ int clicked_index = results.ToInt32();
+ *buttonid = messageboxdata->buttons[clicked_index].buttonid;
+ }
+ return 0;
+#endif /* if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP / else */
+}
+
+#endif /* SDL_VIDEO_DRIVER_WINRT */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/video/winrt/SDL_winrtmessagebox.h b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtmessagebox.h
new file mode 100644
index 0000000..204cf4a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtmessagebox.h
@@ -0,0 +1,29 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINRT
+
+extern int WINRT_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
+
+#endif /* SDL_VIDEO_DRIVER_WINRT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/winrt/SDL_winrtmouse.cpp b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtmouse.cpp
new file mode 100644
index 0000000..093a1b9
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtmouse.cpp
@@ -0,0 +1,224 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINRT
+
+/*
+ * Windows includes:
+ */
+#include <Windows.h>
+#include <windows.ui.core.h>
+using namespace Windows::UI::Core;
+using Windows::UI::Core::CoreCursor;
+
+/*
+ * SDL includes:
+ */
+extern "C" {
+#include "SDL_assert.h"
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_touch_c.h"
+#include "../SDL_sysvideo.h"
+#include "SDL_events.h"
+#include "SDL_log.h"
+}
+
+#include "../../core/winrt/SDL_winrtapp_direct3d.h"
+#include "SDL_winrtvideo_cpp.h"
+#include "SDL_winrtmouse_c.h"
+
+
+extern "C" SDL_bool WINRT_UsingRelativeMouseMode = SDL_FALSE;
+
+
+static SDL_Cursor *
+WINRT_CreateSystemCursor(SDL_SystemCursor id)
+{
+ SDL_Cursor *cursor;
+ CoreCursorType cursorType = CoreCursorType::Arrow;
+
+ switch(id)
+ {
+ default:
+ SDL_assert(0);
+ return NULL;
+ case SDL_SYSTEM_CURSOR_ARROW: cursorType = CoreCursorType::Arrow; break;
+ case SDL_SYSTEM_CURSOR_IBEAM: cursorType = CoreCursorType::IBeam; break;
+ case SDL_SYSTEM_CURSOR_WAIT: cursorType = CoreCursorType::Wait; break;
+ case SDL_SYSTEM_CURSOR_CROSSHAIR: cursorType = CoreCursorType::Cross; break;
+ case SDL_SYSTEM_CURSOR_WAITARROW: cursorType = CoreCursorType::Wait; break;
+ case SDL_SYSTEM_CURSOR_SIZENWSE: cursorType = CoreCursorType::SizeNorthwestSoutheast; break;
+ case SDL_SYSTEM_CURSOR_SIZENESW: cursorType = CoreCursorType::SizeNortheastSouthwest; break;
+ case SDL_SYSTEM_CURSOR_SIZEWE: cursorType = CoreCursorType::SizeWestEast; break;
+ case SDL_SYSTEM_CURSOR_SIZENS: cursorType = CoreCursorType::SizeNorthSouth; break;
+ case SDL_SYSTEM_CURSOR_SIZEALL: cursorType = CoreCursorType::SizeAll; break;
+ case SDL_SYSTEM_CURSOR_NO: cursorType = CoreCursorType::UniversalNo; break;
+ case SDL_SYSTEM_CURSOR_HAND: cursorType = CoreCursorType::Hand; break;
+ }
+
+ cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
+ if (cursor) {
+ /* Create a pointer to a COM reference to a cursor. The extra
+ pointer is used (on top of the COM reference) to allow the cursor
+ to be referenced by the SDL_cursor's driverdata field, which is
+ a void pointer.
+ */
+ CoreCursor ^* theCursor = new CoreCursor^(nullptr);
+ *theCursor = ref new CoreCursor(cursorType, 0);
+ cursor->driverdata = (void *) theCursor;
+ } else {
+ SDL_OutOfMemory();
+ }
+
+ return cursor;
+}
+
+static SDL_Cursor *
+WINRT_CreateDefaultCursor()
+{
+ return WINRT_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
+}
+
+static void
+WINRT_FreeCursor(SDL_Cursor * cursor)
+{
+ if (cursor->driverdata) {
+ CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
+ *theCursor = nullptr; // Release the COM reference to the CoreCursor
+ delete theCursor; // Delete the pointer to the COM reference
+ }
+ SDL_free(cursor);
+}
+
+static int
+WINRT_ShowCursor(SDL_Cursor * cursor)
+{
+ // TODO, WinRT, XAML: make WINRT_ShowCursor work when XAML support is enabled.
+ if ( ! CoreWindow::GetForCurrentThread()) {
+ return 0;
+ }
+
+ CoreWindow ^ coreWindow = CoreWindow::GetForCurrentThread();
+ if (cursor) {
+ CoreCursor ^* theCursor = (CoreCursor ^*) cursor->driverdata;
+ coreWindow->PointerCursor = *theCursor;
+ } else {
+ // HACK ALERT: TL;DR - Hiding the cursor in WinRT/UWP apps is weird, and
+ // a Win32-style cursor resource file must be directly included in apps,
+ // otherwise hiding the cursor will cause mouse-motion data to never be
+ // received.
+ //
+ // Here's the lengthy explanation:
+ //
+ // There are two ways to hide a cursor in WinRT/UWP apps.
+ // Both involve setting the WinRT CoreWindow's (which is somewhat analogous
+ // to a Win32 HWND) 'PointerCursor' property.
+ //
+ // The first way to hide a cursor sets PointerCursor to nullptr. This
+ // is, arguably, the easiest to implement for an app. It does have an
+ // unfortunate side-effect: it'll prevent mouse-motion events from being
+ // sent to the app (via CoreWindow).
+ //
+ // The second way to hide a cursor sets PointerCursor to a transparent
+ // cursor. This allows mouse-motion events to be sent to the app, but is
+ // more difficult to set up, as:
+ // 1. WinRT/UWP, while providing a few stock cursors, does not provide
+ // a completely transparent cursor.
+ // 2. WinRT/UWP allows apps to provide custom-built cursors, but *ONLY*
+ // if they are linked directly inside the app, via Win32-style
+ // cursor resource files. APIs to create cursors at runtime are
+ // not provided to apps, and attempting to link-to or use Win32
+ // cursor-creation APIs could cause an app to fail Windows Store
+ // certification.
+ //
+ // SDL can use either means of hiding the cursor. It provides a Win32-style
+ // set of cursor resource files in its source distribution, inside
+ // src/main/winrt/. If those files are linked to an SDL-for-WinRT/UWP app
+ // (by including them in a MSVC project, for example), SDL will attempt to
+ // use those, if and when the cursor is hidden via SDL APIs. If those
+ // files are not linked in, SDL will attempt to hide the cursor via the
+ // 'set PointerCursor to nullptr' means (which, if you recall, causes
+ // mouse-motion data to NOT be sent to the app!).
+ //
+ // Tech notes:
+ // - SDL's blank cursor resource uses a resource ID of 5000.
+ // - SDL's cursor resources consist of the following two files:
+ // - src/main/winrt/SDL2-WinRTResource_BlankCursor.cur -- cursor pixel data
+ // - src/main/winrt/SDL2-WinRTResources.rc -- declares the cursor resource, and its ID (of 5000)
+ //
+
+ const unsigned int win32CursorResourceID = 5000;
+ CoreCursor ^ blankCursor = ref new CoreCursor(CoreCursorType::Custom, win32CursorResourceID);
+
+ // Set 'PointerCursor' to 'blankCursor' in a way that shouldn't throw
+ // an exception if the app hasn't loaded that resource.
+ ABI::Windows::UI::Core::ICoreCursor * iblankCursor = reinterpret_cast<ABI::Windows::UI::Core::ICoreCursor *>(blankCursor);
+ ABI::Windows::UI::Core::ICoreWindow * icoreWindow = reinterpret_cast<ABI::Windows::UI::Core::ICoreWindow *>(coreWindow);
+ HRESULT hr = icoreWindow->put_PointerCursor(iblankCursor);
+ if (FAILED(hr)) {
+ // The app doesn't contain the cursor resource, or some other error
+ // occurred. Just use the other, but mouse-motion-preventing, means of
+ // hiding the cursor.
+ coreWindow->PointerCursor = nullptr;
+ }
+ }
+ return 0;
+}
+
+static int
+WINRT_SetRelativeMouseMode(SDL_bool enabled)
+{
+ WINRT_UsingRelativeMouseMode = enabled;
+ return 0;
+}
+
+void
+WINRT_InitMouse(_THIS)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ /* DLudwig, Dec 3, 2012: WinRT does not currently provide APIs for
+ the following features, AFAIK:
+ - custom cursors (multiple system cursors are, however, available)
+ - programmatically moveable cursors
+ */
+
+#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
+ //mouse->CreateCursor = WINRT_CreateCursor;
+ mouse->CreateSystemCursor = WINRT_CreateSystemCursor;
+ mouse->ShowCursor = WINRT_ShowCursor;
+ mouse->FreeCursor = WINRT_FreeCursor;
+ //mouse->WarpMouse = WINRT_WarpMouse;
+ mouse->SetRelativeMouseMode = WINRT_SetRelativeMouseMode;
+
+ SDL_SetDefaultCursor(WINRT_CreateDefaultCursor());
+#endif
+}
+
+void
+WINRT_QuitMouse(_THIS)
+{
+}
+
+#endif /* SDL_VIDEO_DRIVER_WINRT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/winrt/SDL_winrtmouse_c.h b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtmouse_c.h
new file mode 100644
index 0000000..22a80fc
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtmouse_c.h
@@ -0,0 +1,40 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#ifndef SDL_winrtmouse_h_
+#define SDL_winrtmouse_h_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void WINRT_InitMouse(_THIS);
+extern void WINRT_QuitMouse(_THIS);
+extern SDL_bool WINRT_UsingRelativeMouseMode;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SDL_winrtmouse_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/winrt/SDL_winrtopengles.cpp b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtopengles.cpp
new file mode 100644
index 0000000..7874501
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtopengles.cpp
@@ -0,0 +1,203 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL
+
+/* EGL implementation of SDL OpenGL support */
+
+#include "SDL_winrtvideo_cpp.h"
+extern "C" {
+#include "SDL_winrtopengles.h"
+#include "SDL_loadso.h"
+#include "../SDL_egl_c.h"
+}
+
+/* Windows includes */
+#include <wrl/client.h>
+using namespace Windows::UI::Core;
+
+/* ANGLE/WinRT constants */
+static const int ANGLE_D3D_FEATURE_LEVEL_ANY = 0;
+#define EGL_PLATFORM_ANGLE_ANGLE 0x3202
+#define EGL_PLATFORM_ANGLE_TYPE_ANGLE 0x3203
+#define EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE 0x3204
+#define EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE 0x3205
+#define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE 0x3208
+#define EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE 0x3209
+#define EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE 0x320B
+#define EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE 0x320F
+
+#define EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER 0x320B
+
+
+/*
+ * SDL/EGL top-level implementation
+ */
+
+extern "C" int
+WINRT_GLES_LoadLibrary(_THIS, const char *path)
+{
+ SDL_VideoData *video_data = (SDL_VideoData *)_this->driverdata;
+
+ if (SDL_EGL_LoadLibrary(_this, path, EGL_DEFAULT_DISPLAY, 0) != 0) {
+ return -1;
+ }
+
+ /* Load ANGLE/WinRT-specific functions */
+ CreateWinrtEglWindow_Old_Function CreateWinrtEglWindow = (CreateWinrtEglWindow_Old_Function) SDL_LoadFunction(_this->egl_data->egl_dll_handle, "CreateWinrtEglWindow");
+ if (CreateWinrtEglWindow) {
+ /* 'CreateWinrtEglWindow' was found, which means that an an older
+ * version of ANGLE/WinRT is being used. Continue setting up EGL,
+ * as appropriate to this version of ANGLE.
+ */
+
+ /* Create an ANGLE/WinRT EGL-window */
+ /* TODO, WinRT: check for XAML usage before accessing the CoreWindow, as not doing so could lead to a crash */
+ CoreWindow ^ native_win = CoreWindow::GetForCurrentThread();
+ Microsoft::WRL::ComPtr<IUnknown> cpp_win = reinterpret_cast<IUnknown *>(native_win);
+ HRESULT result = CreateWinrtEglWindow(cpp_win, ANGLE_D3D_FEATURE_LEVEL_ANY, &(video_data->winrtEglWindow));
+ if (FAILED(result)) {
+ return -1;
+ }
+
+ /* Call eglGetDisplay and eglInitialize as appropriate. On other
+ * platforms, this would probably get done by SDL_EGL_LoadLibrary,
+ * however ANGLE/WinRT's current implementation (as of Mar 22, 2014) of
+ * eglGetDisplay requires that a C++ object be passed into it, so the
+ * call will be made in this file, a C++ file, instead.
+ */
+ Microsoft::WRL::ComPtr<IUnknown> cpp_display = video_data->winrtEglWindow;
+ _this->egl_data->egl_display = ((eglGetDisplay_Old_Function)_this->egl_data->eglGetDisplay)(cpp_display);
+ if (!_this->egl_data->egl_display) {
+ return SDL_EGL_SetError("Could not get Windows 8.0 EGL display", "eglGetDisplay");
+ }
+
+ if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
+ return SDL_EGL_SetError("Could not initialize Windows 8.0 EGL", "eglInitialize");
+ }
+ } else {
+ /* Declare some ANGLE/EGL initialization property-sets, as suggested by
+ * MSOpenTech's ANGLE-for-WinRT template apps:
+ */
+ const EGLint defaultDisplayAttributes[] =
+ {
+ EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
+ EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE,
+ EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, EGL_TRUE,
+ EGL_NONE,
+ };
+
+ const EGLint fl9_3DisplayAttributes[] =
+ {
+ EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
+ EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, 9,
+ EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, 3,
+ EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE,
+ EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, EGL_TRUE,
+ EGL_NONE,
+ };
+
+ const EGLint warpDisplayAttributes[] =
+ {
+ EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
+ EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE,
+ EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE,
+ EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, EGL_TRUE,
+ EGL_NONE,
+ };
+
+ /* 'CreateWinrtEglWindow' was NOT found, which either means that a
+ * newer version of ANGLE/WinRT is being used, or that we don't have
+ * a valid copy of ANGLE.
+ *
+ * Try loading ANGLE as if it were the newer version.
+ */
+ eglGetPlatformDisplayEXT_Function eglGetPlatformDisplayEXT = (eglGetPlatformDisplayEXT_Function)_this->egl_data->eglGetProcAddress("eglGetPlatformDisplayEXT");
+ if (!eglGetPlatformDisplayEXT) {
+ return SDL_EGL_SetError("Could not retrieve ANGLE/WinRT display function(s)", "eglGetProcAddress");
+ }
+
+#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP)
+ /* Try initializing EGL at D3D11 Feature Level 10_0+ (which is not
+ * supported on WinPhone 8.x.
+ */
+ _this->egl_data->egl_display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, defaultDisplayAttributes);
+ if (!_this->egl_data->egl_display) {
+ return SDL_EGL_SetError("Could not get EGL display for Direct3D 10_0+", "eglGetPlatformDisplayEXT");
+ }
+
+ if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE)
+#endif
+ {
+ /* Try initializing EGL at D3D11 Feature Level 9_3, in case the
+ * 10_0 init fails, or we're on Windows Phone (which only supports
+ * 9_3).
+ */
+ _this->egl_data->egl_display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, fl9_3DisplayAttributes);
+ if (!_this->egl_data->egl_display) {
+ return SDL_EGL_SetError("Could not get EGL display for Direct3D 9_3", "eglGetPlatformDisplayEXT");
+ }
+
+ if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
+ /* Try initializing EGL at D3D11 Feature Level 11_0 on WARP
+ * (a Windows-provided, software rasterizer) if all else fails.
+ */
+ _this->egl_data->egl_display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, warpDisplayAttributes);
+ if (!_this->egl_data->egl_display) {
+ return SDL_EGL_SetError("Could not get EGL display for Direct3D WARP", "eglGetPlatformDisplayEXT");
+ }
+
+ if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
+ return SDL_EGL_SetError("Could not initialize WinRT 8.x+ EGL", "eglInitialize");
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+extern "C" void
+WINRT_GLES_UnloadLibrary(_THIS)
+{
+ SDL_VideoData *video_data = (SDL_VideoData *)_this->driverdata;
+
+ /* Release SDL's own COM reference to the ANGLE/WinRT IWinrtEglWindow */
+ if (video_data->winrtEglWindow) {
+ video_data->winrtEglWindow->Release();
+ video_data->winrtEglWindow = nullptr;
+ }
+
+ /* Perform the bulk of the unloading */
+ SDL_EGL_UnloadLibrary(_this);
+}
+
+extern "C" {
+SDL_EGL_CreateContext_impl(WINRT)
+SDL_EGL_SwapWindow_impl(WINRT)
+SDL_EGL_MakeCurrent_impl(WINRT)
+}
+
+#endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */
+
+/* vi: set ts=4 sw=4 expandtab: */
+
diff --git a/src/3rdparty/SDL2/src/video/winrt/SDL_winrtopengles.h b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtopengles.h
new file mode 100644
index 0000000..a222c2b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtopengles.h
@@ -0,0 +1,70 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#ifndef SDL_winrtopengles_h_
+#define SDL_winrtopengles_h_
+
+#if SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL
+
+#include "../SDL_sysvideo.h"
+#include "../SDL_egl_c.h"
+
+/* OpenGLES functions */
+#define WINRT_GLES_GetAttribute SDL_EGL_GetAttribute
+#define WINRT_GLES_GetProcAddress SDL_EGL_GetProcAddress
+#define WINRT_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
+#define WINRT_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
+#define WINRT_GLES_DeleteContext SDL_EGL_DeleteContext
+
+extern int WINRT_GLES_LoadLibrary(_THIS, const char *path);
+extern void WINRT_GLES_UnloadLibrary(_THIS);
+extern SDL_GLContext WINRT_GLES_CreateContext(_THIS, SDL_Window * window);
+extern int WINRT_GLES_SwapWindow(_THIS, SDL_Window * window);
+extern int WINRT_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+
+
+#ifdef __cplusplus
+
+/* Typedefs for ANGLE/WinRT's C++-based native-display and native-window types,
+ * which are used when calling eglGetDisplay and eglCreateWindowSurface.
+ */
+typedef Microsoft::WRL::ComPtr<IUnknown> WINRT_EGLNativeWindowType_Old;
+
+/* Function pointer typedefs for 'old' ANGLE/WinRT's functions, which may
+ * require that C++ objects be passed in:
+ */
+typedef EGLDisplay (EGLAPIENTRY *eglGetDisplay_Old_Function)(WINRT_EGLNativeWindowType_Old);
+typedef EGLSurface (EGLAPIENTRY *eglCreateWindowSurface_Old_Function)(EGLDisplay, EGLConfig, WINRT_EGLNativeWindowType_Old, const EGLint *);
+typedef HRESULT (EGLAPIENTRY *CreateWinrtEglWindow_Old_Function)(Microsoft::WRL::ComPtr<IUnknown>, int, IUnknown ** result);
+
+#endif /* __cplusplus */
+
+/* Function pointer typedefs for 'new' ANGLE/WinRT functions, which, unlike
+ * the old functions, do not require C++ support and work with plain C.
+ */
+typedef EGLDisplay (EGLAPIENTRY *eglGetPlatformDisplayEXT_Function)(EGLenum, void *, const EGLint *);
+
+#endif /* SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL */
+
+#endif /* SDL_winrtopengles_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/winrt/SDL_winrtpointerinput.cpp b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtpointerinput.cpp
new file mode 100644
index 0000000..bc438f2
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtpointerinput.cpp
@@ -0,0 +1,415 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINRT
+
+/* SDL includes */
+#include "SDL_winrtevents_c.h"
+#include "SDL_winrtmouse_c.h"
+#include "SDL_winrtvideo_cpp.h"
+#include "SDL_assert.h"
+#include "SDL_system.h"
+
+extern "C" {
+#include "../SDL_sysvideo.h"
+#include "../../events/SDL_events_c.h"
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_touch_c.h"
+}
+
+/* File-specific globals: */
+static SDL_TouchID WINRT_TouchID = 1;
+static unsigned int WINRT_LeftFingerDown = 0;
+
+
+void
+WINRT_InitTouch(_THIS)
+{
+ SDL_AddTouch(WINRT_TouchID, "");
+}
+
+
+//
+// Applies necessary geometric transformations to raw cursor positions:
+//
+Windows::Foundation::Point
+WINRT_TransformCursorPosition(SDL_Window * window,
+ Windows::Foundation::Point rawPosition,
+ WINRT_CursorNormalizationType normalization)
+{
+ using namespace Windows::UI::Core;
+ using namespace Windows::Graphics::Display;
+
+ if (!window) {
+ return rawPosition;
+ }
+
+ SDL_WindowData * windowData = (SDL_WindowData *) window->driverdata;
+ if (windowData->coreWindow == nullptr) {
+ // For some reason, the window isn't associated with a CoreWindow.
+ // This might end up being the case as XAML support is extended.
+ // For now, if there's no CoreWindow attached to the SDL_Window,
+ // don't do any transforms.
+
+ // TODO, WinRT: make sure touch input coordinate ranges are correct when using XAML support
+ return rawPosition;
+ }
+
+ // The CoreWindow can only be accessed on certain thread(s).
+ SDL_assert(CoreWindow::GetForCurrentThread() != nullptr);
+
+ CoreWindow ^ nativeWindow = windowData->coreWindow.Get();
+ Windows::Foundation::Point outputPosition;
+
+ // Compute coordinates normalized from 0..1.
+ // If the coordinates need to be sized to the SDL window,
+ // we'll do that after.
+#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) || (NTDDI_VERSION > NTDDI_WIN8)
+ outputPosition.X = rawPosition.X / nativeWindow->Bounds.Width;
+ outputPosition.Y = rawPosition.Y / nativeWindow->Bounds.Height;
+#else
+ switch (WINRT_DISPLAY_PROPERTY(CurrentOrientation))
+ {
+ case DisplayOrientations::Portrait:
+ outputPosition.X = rawPosition.X / nativeWindow->Bounds.Width;
+ outputPosition.Y = rawPosition.Y / nativeWindow->Bounds.Height;
+ break;
+ case DisplayOrientations::PortraitFlipped:
+ outputPosition.X = 1.0f - (rawPosition.X / nativeWindow->Bounds.Width);
+ outputPosition.Y = 1.0f - (rawPosition.Y / nativeWindow->Bounds.Height);
+ break;
+ case DisplayOrientations::Landscape:
+ outputPosition.X = rawPosition.Y / nativeWindow->Bounds.Height;
+ outputPosition.Y = 1.0f - (rawPosition.X / nativeWindow->Bounds.Width);
+ break;
+ case DisplayOrientations::LandscapeFlipped:
+ outputPosition.X = 1.0f - (rawPosition.Y / nativeWindow->Bounds.Height);
+ outputPosition.Y = rawPosition.X / nativeWindow->Bounds.Width;
+ break;
+ default:
+ break;
+ }
+#endif
+
+ if (normalization == TransformToSDLWindowSize) {
+ outputPosition.X *= ((float32) window->w);
+ outputPosition.Y *= ((float32) window->h);
+ }
+
+ return outputPosition;
+}
+
+static inline int
+_lround(float arg)
+{
+ if (arg >= 0.0f) {
+ return (int)floor(arg + 0.5f);
+ } else {
+ return (int)ceil(arg - 0.5f);
+ }
+}
+
+Uint8
+WINRT_GetSDLButtonForPointerPoint(Windows::UI::Input::PointerPoint ^pt)
+{
+ using namespace Windows::UI::Input;
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+ return SDL_BUTTON_LEFT;
+#else
+ switch (pt->Properties->PointerUpdateKind)
+ {
+ case PointerUpdateKind::LeftButtonPressed:
+ case PointerUpdateKind::LeftButtonReleased:
+ return SDL_BUTTON_LEFT;
+
+ case PointerUpdateKind::RightButtonPressed:
+ case PointerUpdateKind::RightButtonReleased:
+ return SDL_BUTTON_RIGHT;
+
+ case PointerUpdateKind::MiddleButtonPressed:
+ case PointerUpdateKind::MiddleButtonReleased:
+ return SDL_BUTTON_MIDDLE;
+
+ case PointerUpdateKind::XButton1Pressed:
+ case PointerUpdateKind::XButton1Released:
+ return SDL_BUTTON_X1;
+
+ case PointerUpdateKind::XButton2Pressed:
+ case PointerUpdateKind::XButton2Released:
+ return SDL_BUTTON_X2;
+
+ default:
+ break;
+ }
+#endif
+
+ return 0;
+}
+
+//const char *
+//WINRT_ConvertPointerUpdateKindToString(Windows::UI::Input::PointerUpdateKind kind)
+//{
+// using namespace Windows::UI::Input;
+//
+// switch (kind)
+// {
+// case PointerUpdateKind::Other:
+// return "Other";
+// case PointerUpdateKind::LeftButtonPressed:
+// return "LeftButtonPressed";
+// case PointerUpdateKind::LeftButtonReleased:
+// return "LeftButtonReleased";
+// case PointerUpdateKind::RightButtonPressed:
+// return "RightButtonPressed";
+// case PointerUpdateKind::RightButtonReleased:
+// return "RightButtonReleased";
+// case PointerUpdateKind::MiddleButtonPressed:
+// return "MiddleButtonPressed";
+// case PointerUpdateKind::MiddleButtonReleased:
+// return "MiddleButtonReleased";
+// case PointerUpdateKind::XButton1Pressed:
+// return "XButton1Pressed";
+// case PointerUpdateKind::XButton1Released:
+// return "XButton1Released";
+// case PointerUpdateKind::XButton2Pressed:
+// return "XButton2Pressed";
+// case PointerUpdateKind::XButton2Released:
+// return "XButton2Released";
+// }
+//
+// return "";
+//}
+
+static bool
+WINRT_IsTouchEvent(Windows::UI::Input::PointerPoint ^pointerPoint)
+{
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+ return true;
+#else
+ using namespace Windows::Devices::Input;
+ switch (pointerPoint->PointerDevice->PointerDeviceType) {
+ case PointerDeviceType::Touch:
+ case PointerDeviceType::Pen:
+ return true;
+ default:
+ return false;
+ }
+#endif
+}
+
+void WINRT_ProcessPointerPressedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
+{
+ if (!window) {
+ return;
+ }
+
+ Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
+
+ if ( ! WINRT_IsTouchEvent(pointerPoint)) {
+ SDL_SendMouseButton(window, 0, SDL_PRESSED, button);
+ } else {
+ Windows::Foundation::Point normalizedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, NormalizeZeroToOne);
+ Windows::Foundation::Point windowPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, TransformToSDLWindowSize);
+
+ if (!WINRT_LeftFingerDown) {
+ if (button) {
+ SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, (int)windowPoint.X, (int)windowPoint.Y);
+ SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, button);
+ }
+
+ WINRT_LeftFingerDown = pointerPoint->PointerId;
+ }
+
+ SDL_SendTouch(
+ WINRT_TouchID,
+ (SDL_FingerID) pointerPoint->PointerId,
+ SDL_TRUE,
+ normalizedPoint.X,
+ normalizedPoint.Y,
+ pointerPoint->Properties->Pressure);
+ }
+}
+
+void
+WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
+{
+ if (!window || WINRT_UsingRelativeMouseMode) {
+ return;
+ }
+
+ Windows::Foundation::Point normalizedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, NormalizeZeroToOne);
+ Windows::Foundation::Point windowPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, TransformToSDLWindowSize);
+
+ if ( ! WINRT_IsTouchEvent(pointerPoint)) {
+ SDL_SendMouseMotion(window, 0, 0, (int)windowPoint.X, (int)windowPoint.Y);
+ } else {
+ if (pointerPoint->PointerId == WINRT_LeftFingerDown) {
+ SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, (int)windowPoint.X, (int)windowPoint.Y);
+ }
+
+ SDL_SendTouchMotion(
+ WINRT_TouchID,
+ (SDL_FingerID) pointerPoint->PointerId,
+ normalizedPoint.X,
+ normalizedPoint.Y,
+ pointerPoint->Properties->Pressure);
+ }
+}
+
+void WINRT_ProcessPointerReleasedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
+{
+ if (!window) {
+ return;
+ }
+
+ Uint8 button = WINRT_GetSDLButtonForPointerPoint(pointerPoint);
+
+ if (!WINRT_IsTouchEvent(pointerPoint)) {
+ SDL_SendMouseButton(window, 0, SDL_RELEASED, button);
+ } else {
+ Windows::Foundation::Point normalizedPoint = WINRT_TransformCursorPosition(window, pointerPoint->Position, NormalizeZeroToOne);
+
+ if (WINRT_LeftFingerDown == pointerPoint->PointerId) {
+ if (button) {
+ SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_RELEASED, button);
+ }
+ WINRT_LeftFingerDown = 0;
+ }
+
+ SDL_SendTouch(
+ WINRT_TouchID,
+ (SDL_FingerID) pointerPoint->PointerId,
+ SDL_FALSE,
+ normalizedPoint.X,
+ normalizedPoint.Y,
+ pointerPoint->Properties->Pressure);
+ }
+}
+
+void WINRT_ProcessPointerEnteredEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
+{
+ if (!window) {
+ return;
+ }
+
+ if (!WINRT_IsTouchEvent(pointerPoint)) {
+ SDL_SetMouseFocus(window);
+ }
+}
+
+void WINRT_ProcessPointerExitedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
+{
+ if (!window) {
+ return;
+ }
+
+ if (!WINRT_IsTouchEvent(pointerPoint)) {
+ SDL_SetMouseFocus(NULL);
+ }
+}
+
+void
+WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::PointerPoint ^pointerPoint)
+{
+ if (!window) {
+ return;
+ }
+
+ float motion = (float) pointerPoint->Properties->MouseWheelDelta / WHEEL_DELTA;
+ SDL_SendMouseWheel(window, 0, 0, (float) motion, SDL_MOUSEWHEEL_NORMAL);
+}
+
+void
+WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices::Input::MouseEventArgs ^args)
+{
+ if (!window || !WINRT_UsingRelativeMouseMode) {
+ return;
+ }
+
+ // DLudwig, 2012-12-28: On some systems, namely Visual Studio's Windows
+ // Simulator, as well as Windows 8 in a Parallels 8 VM, MouseEventArgs'
+ // MouseDelta field often reports very large values. More information
+ // on this can be found at the following pages on MSDN:
+ // - http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/a3c789fa-f1c5-49c4-9c0a-7db88d0f90f8
+ // - https://connect.microsoft.com/VisualStudio/Feedback/details/756515
+ //
+ // The values do not appear to be as large when running on some systems,
+ // most notably a Surface RT. Furthermore, the values returned by
+ // CoreWindow's PointerMoved event, and sent to this class' OnPointerMoved
+ // method, do not ever appear to be large, even when MouseEventArgs'
+ // MouseDelta is reporting to the contrary.
+ //
+ // On systems with the large-values behavior, it appears that the values
+ // get reported as if the screen's size is 65536 units in both the X and Y
+ // dimensions. This can be viewed by using Windows' now-private, "Raw Input"
+ // APIs. (GetRawInputData, RegisterRawInputDevices, WM_INPUT, etc.)
+ //
+ // MSDN's documentation on MouseEventArgs' MouseDelta field (at
+ // http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.input.mouseeventargs.mousedelta ),
+ // does not seem to indicate (to me) that its values should be so large. It
+ // says that its values should be a "change in screen location". I could
+ // be misinterpreting this, however a post on MSDN from a Microsoft engineer (see:
+ // http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/09a9868e-95bb-4858-ba1a-cb4d2c298d62 ),
+ // indicates that these values are in DIPs, which is the same unit used
+ // by CoreWindow's PointerMoved events (via the Position field in its CurrentPoint
+ // property. See http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.input.pointerpoint.position.aspx
+ // for details.)
+ //
+ // To note, PointerMoved events are sent a 'RawPosition' value (via the
+ // CurrentPoint property in MouseEventArgs), however these do not seem
+ // to exhibit the same large-value behavior.
+ //
+ // The values passed via PointerMoved events can't always be used for relative
+ // mouse motion, unfortunately. Its values are bound to the cursor's position,
+ // which stops when it hits one of the screen's edges. This can be a problem in
+ // first person shooters, whereby it is normal for mouse motion to travel far
+ // along any one axis for a period of time. MouseMoved events do not have the
+ // screen-bounding limitation, and can be used regardless of where the system's
+ // cursor is.
+ //
+ // One possible workaround would be to programmatically set the cursor's
+ // position to the screen's center (when SDL's relative mouse mode is enabled),
+ // however WinRT does not yet seem to have the ability to set the cursor's
+ // position via a public API. Win32 did this via an API call, SetCursorPos,
+ // however WinRT makes this function be private. Apps that use it won't get
+ // approved for distribution in the Windows Store. I've yet to be able to find
+ // a suitable, store-friendly counterpart for WinRT.
+ //
+ // There may be some room for a workaround whereby OnPointerMoved's values
+ // are compared to the values from OnMouseMoved in order to detect
+ // when this bug is active. A suitable transformation could then be made to
+ // OnMouseMoved's values. For now, however, the system-reported values are sent
+ // to SDL with minimal transformation: from native screen coordinates (in DIPs)
+ // to SDL window coordinates.
+ //
+ const Windows::Foundation::Point mouseDeltaInDIPs((float)args->MouseDelta.X, (float)args->MouseDelta.Y);
+ const Windows::Foundation::Point mouseDeltaInSDLWindowCoords = WINRT_TransformCursorPosition(window, mouseDeltaInDIPs, TransformToSDLWindowSize);
+ SDL_SendMouseMotion(
+ window,
+ 0,
+ 1,
+ _lround(mouseDeltaInSDLWindowCoords.X),
+ _lround(mouseDeltaInSDLWindowCoords.Y));
+}
+
+#endif // SDL_VIDEO_DRIVER_WINRT
diff --git a/src/3rdparty/SDL2/src/video/winrt/SDL_winrtvideo.cpp b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtvideo.cpp
new file mode 100644
index 0000000..99bfd07
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtvideo.cpp
@@ -0,0 +1,842 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_WINRT
+
+/* WinRT SDL video driver implementation
+
+ Initial work on this was done by David Ludwig (dludwig@pobox.com), and
+ was based off of SDL's "dummy" video driver.
+ */
+
+/* Windows includes */
+#include <agile.h>
+#include <windows.graphics.display.h>
+#include <windows.system.display.h>
+#include <dxgi.h>
+#include <dxgi1_2.h>
+using namespace Windows::ApplicationModel::Core;
+using namespace Windows::Foundation;
+using namespace Windows::Graphics::Display;
+using namespace Windows::UI::Core;
+using namespace Windows::UI::ViewManagement;
+
+
+/* [re]declare Windows GUIDs locally, to limit the amount of external lib(s) SDL has to link to */
+static const GUID IID_IDisplayRequest = { 0xe5732044, 0xf49f, 0x4b60, { 0x8d, 0xd4, 0x5e, 0x7e, 0x3a, 0x63, 0x2a, 0xc0 } };
+static const GUID IID_IDXGIFactory2 = { 0x50c83a1c, 0xe072, 0x4c48, { 0x87, 0xb0, 0x36, 0x30, 0xfa, 0x36, 0xa6, 0xd0 } };
+
+
+/* SDL includes */
+extern "C" {
+#include "SDL_video.h"
+#include "SDL_mouse.h"
+#include "../SDL_sysvideo.h"
+#include "../SDL_pixels_c.h"
+#include "../../events/SDL_events_c.h"
+#include "../../render/SDL_sysrender.h"
+#include "SDL_syswm.h"
+#include "SDL_winrtopengles.h"
+#include "../../core/windows/SDL_windows.h"
+}
+
+#include "../../core/winrt/SDL_winrtapp_direct3d.h"
+#include "../../core/winrt/SDL_winrtapp_xaml.h"
+#include "SDL_winrtvideo_cpp.h"
+#include "SDL_winrtevents_c.h"
+#include "SDL_winrtgamebar_cpp.h"
+#include "SDL_winrtmouse_c.h"
+#include "SDL_main.h"
+#include "SDL_system.h"
+//#include "SDL_log.h"
+
+
+/* Initialization/Query functions */
+static int WINRT_VideoInit(_THIS);
+static int WINRT_InitModes(_THIS);
+static int WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
+static void WINRT_VideoQuit(_THIS);
+
+
+/* Window functions */
+static int WINRT_CreateWindow(_THIS, SDL_Window * window);
+static void WINRT_SetWindowSize(_THIS, SDL_Window * window);
+static void WINRT_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
+static void WINRT_DestroyWindow(_THIS, SDL_Window * window);
+static SDL_bool WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
+
+
+/* Misc functions */
+static ABI::Windows::System::Display::IDisplayRequest * WINRT_CreateDisplayRequest(_THIS);
+extern void WINRT_SuspendScreenSaver(_THIS);
+
+
+/* SDL-internal globals: */
+SDL_Window * WINRT_GlobalSDLWindow = NULL;
+
+
+/* WinRT driver bootstrap functions */
+
+static int
+WINRT_Available(void)
+{
+ return (1);
+}
+
+static void
+WINRT_DeleteDevice(SDL_VideoDevice * device)
+{
+ if (device->driverdata) {
+ SDL_VideoData * video_data = (SDL_VideoData *)device->driverdata;
+ if (video_data->winrtEglWindow) {
+ video_data->winrtEglWindow->Release();
+ }
+ SDL_free(video_data);
+ }
+
+ SDL_free(device);
+}
+
+static SDL_VideoDevice *
+WINRT_CreateDevice(int devindex)
+{
+ SDL_VideoDevice *device;
+ SDL_VideoData *data;
+
+ /* Initialize all variables that we clean on shutdown */
+ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (!device) {
+ SDL_OutOfMemory();
+ return (0);
+ }
+
+ data = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
+ if (!data) {
+ SDL_OutOfMemory();
+ SDL_free(device);
+ return (0);
+ }
+ device->driverdata = data;
+
+ /* Set the function pointers */
+ device->VideoInit = WINRT_VideoInit;
+ device->VideoQuit = WINRT_VideoQuit;
+ device->CreateSDLWindow = WINRT_CreateWindow;
+ device->SetWindowSize = WINRT_SetWindowSize;
+ device->SetWindowFullscreen = WINRT_SetWindowFullscreen;
+ device->DestroyWindow = WINRT_DestroyWindow;
+ device->SetDisplayMode = WINRT_SetDisplayMode;
+ device->PumpEvents = WINRT_PumpEvents;
+ device->GetWindowWMInfo = WINRT_GetWindowWMInfo;
+ device->SuspendScreenSaver = WINRT_SuspendScreenSaver;
+
+#if NTDDI_VERSION >= NTDDI_WIN10
+ device->HasScreenKeyboardSupport = WINRT_HasScreenKeyboardSupport;
+ device->ShowScreenKeyboard = WINRT_ShowScreenKeyboard;
+ device->HideScreenKeyboard = WINRT_HideScreenKeyboard;
+ device->IsScreenKeyboardShown = WINRT_IsScreenKeyboardShown;
+#endif
+
+#ifdef SDL_VIDEO_OPENGL_EGL
+ device->GL_LoadLibrary = WINRT_GLES_LoadLibrary;
+ device->GL_GetProcAddress = WINRT_GLES_GetProcAddress;
+ device->GL_UnloadLibrary = WINRT_GLES_UnloadLibrary;
+ device->GL_CreateContext = WINRT_GLES_CreateContext;
+ device->GL_MakeCurrent = WINRT_GLES_MakeCurrent;
+ device->GL_SetSwapInterval = WINRT_GLES_SetSwapInterval;
+ device->GL_GetSwapInterval = WINRT_GLES_GetSwapInterval;
+ device->GL_SwapWindow = WINRT_GLES_SwapWindow;
+ device->GL_DeleteContext = WINRT_GLES_DeleteContext;
+#endif
+ device->free = WINRT_DeleteDevice;
+
+ return device;
+}
+
+#define WINRTVID_DRIVER_NAME "winrt"
+VideoBootStrap WINRT_bootstrap = {
+ WINRTVID_DRIVER_NAME, "SDL WinRT video driver",
+ WINRT_Available, WINRT_CreateDevice
+};
+
+int
+WINRT_VideoInit(_THIS)
+{
+ SDL_VideoData * driverdata = (SDL_VideoData *) _this->driverdata;
+ if (WINRT_InitModes(_this) < 0) {
+ return -1;
+ }
+ WINRT_InitMouse(_this);
+ WINRT_InitTouch(_this);
+ WINRT_InitGameBar(_this);
+ if (driverdata) {
+ /* Initialize screensaver-disabling support */
+ driverdata->displayRequest = WINRT_CreateDisplayRequest(_this);
+ }
+ return 0;
+}
+
+extern "C"
+Uint32 D3D11_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat);
+
+static void
+WINRT_DXGIModeToSDLDisplayMode(const DXGI_MODE_DESC * dxgiMode, SDL_DisplayMode * sdlMode)
+{
+ SDL_zerop(sdlMode);
+ sdlMode->w = dxgiMode->Width;
+ sdlMode->h = dxgiMode->Height;
+ sdlMode->refresh_rate = dxgiMode->RefreshRate.Numerator / dxgiMode->RefreshRate.Denominator;
+ sdlMode->format = D3D11_DXGIFormatToSDLPixelFormat(dxgiMode->Format);
+}
+
+static int
+WINRT_AddDisplaysForOutput (_THIS, IDXGIAdapter1 * dxgiAdapter1, int outputIndex)
+{
+ HRESULT hr;
+ IDXGIOutput * dxgiOutput = NULL;
+ DXGI_OUTPUT_DESC dxgiOutputDesc;
+ SDL_VideoDisplay display;
+ char * displayName = NULL;
+ UINT numModes;
+ DXGI_MODE_DESC * dxgiModes = NULL;
+ int functionResult = -1; /* -1 for failure, 0 for success */
+ DXGI_MODE_DESC modeToMatch, closestMatch;
+
+ SDL_zero(display);
+
+ hr = dxgiAdapter1->EnumOutputs(outputIndex, &dxgiOutput);
+ if (FAILED(hr)) {
+ if (hr != DXGI_ERROR_NOT_FOUND) {
+ WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIAdapter1::EnumOutputs failed", hr);
+ }
+ goto done;
+ }
+
+ hr = dxgiOutput->GetDesc(&dxgiOutputDesc);
+ if (FAILED(hr)) {
+ WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIOutput::GetDesc failed", hr);
+ goto done;
+ }
+
+ SDL_zero(modeToMatch);
+ modeToMatch.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
+ modeToMatch.Width = (dxgiOutputDesc.DesktopCoordinates.right - dxgiOutputDesc.DesktopCoordinates.left);
+ modeToMatch.Height = (dxgiOutputDesc.DesktopCoordinates.bottom - dxgiOutputDesc.DesktopCoordinates.top);
+ hr = dxgiOutput->FindClosestMatchingMode(&modeToMatch, &closestMatch, NULL);
+ if (hr == DXGI_ERROR_NOT_CURRENTLY_AVAILABLE) {
+ /* DXGI_ERROR_NOT_CURRENTLY_AVAILABLE gets returned by IDXGIOutput::FindClosestMatchingMode
+ when running under the Windows Simulator, which uses Remote Desktop (formerly known as Terminal
+ Services) under the hood. According to the MSDN docs for the similar function,
+ IDXGIOutput::GetDisplayModeList, DXGI_ERROR_NOT_CURRENTLY_AVAILABLE is returned if and
+ when an app is run under a Terminal Services session, hence the assumption.
+
+ In this case, just add an SDL display mode, with approximated values.
+ */
+ SDL_DisplayMode mode;
+ SDL_zero(mode);
+ display.name = "Windows Simulator / Terminal Services Display";
+ mode.w = (dxgiOutputDesc.DesktopCoordinates.right - dxgiOutputDesc.DesktopCoordinates.left);
+ mode.h = (dxgiOutputDesc.DesktopCoordinates.bottom - dxgiOutputDesc.DesktopCoordinates.top);
+ mode.format = DXGI_FORMAT_B8G8R8A8_UNORM;
+ mode.refresh_rate = 0; /* Display mode is unknown, so just fill in zero, as specified by SDL's header files */
+ display.desktop_mode = mode;
+ display.current_mode = mode;
+ if ( ! SDL_AddDisplayMode(&display, &mode)) {
+ goto done;
+ }
+ } else if (FAILED(hr)) {
+ WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIOutput::FindClosestMatchingMode failed", hr);
+ goto done;
+ } else {
+ displayName = WIN_StringToUTF8(dxgiOutputDesc.DeviceName);
+ display.name = displayName;
+ WINRT_DXGIModeToSDLDisplayMode(&closestMatch, &display.desktop_mode);
+ display.current_mode = display.desktop_mode;
+
+ hr = dxgiOutput->GetDisplayModeList(DXGI_FORMAT_B8G8R8A8_UNORM, 0, &numModes, NULL);
+ if (FAILED(hr)) {
+ if (hr == DXGI_ERROR_NOT_CURRENTLY_AVAILABLE) {
+ // TODO, WinRT: make sure display mode(s) are added when using Terminal Services / Windows Simulator
+ }
+ WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIOutput::GetDisplayModeList [get mode list size] failed", hr);
+ goto done;
+ }
+
+ dxgiModes = (DXGI_MODE_DESC *)SDL_calloc(numModes, sizeof(DXGI_MODE_DESC));
+ if ( ! dxgiModes) {
+ SDL_OutOfMemory();
+ goto done;
+ }
+
+ hr = dxgiOutput->GetDisplayModeList(DXGI_FORMAT_B8G8R8A8_UNORM, 0, &numModes, dxgiModes);
+ if (FAILED(hr)) {
+ WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIOutput::GetDisplayModeList [get mode contents] failed", hr);
+ goto done;
+ }
+
+ for (UINT i = 0; i < numModes; ++i) {
+ SDL_DisplayMode sdlMode;
+ WINRT_DXGIModeToSDLDisplayMode(&dxgiModes[i], &sdlMode);
+ SDL_AddDisplayMode(&display, &sdlMode);
+ }
+ }
+
+ if (SDL_AddVideoDisplay(&display) < 0) {
+ goto done;
+ }
+
+ functionResult = 0; /* 0 for Success! */
+done:
+ if (dxgiModes) {
+ SDL_free(dxgiModes);
+ }
+ if (dxgiOutput) {
+ dxgiOutput->Release();
+ }
+ if (displayName) {
+ SDL_free(displayName);
+ }
+ return functionResult;
+}
+
+static int
+WINRT_AddDisplaysForAdapter (_THIS, IDXGIFactory2 * dxgiFactory2, int adapterIndex)
+{
+ HRESULT hr;
+ IDXGIAdapter1 * dxgiAdapter1;
+
+ hr = dxgiFactory2->EnumAdapters1(adapterIndex, &dxgiAdapter1);
+ if (FAILED(hr)) {
+ if (hr != DXGI_ERROR_NOT_FOUND) {
+ WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIFactory1::EnumAdapters1() failed", hr);
+ }
+ return -1;
+ }
+
+ for (int outputIndex = 0; ; ++outputIndex) {
+ if (WINRT_AddDisplaysForOutput(_this, dxgiAdapter1, outputIndex) < 0) {
+ /* HACK: The Windows App Certification Kit 10.0 can fail, when
+ running the Store Apps' test, "Direct3D Feature Test". The
+ certification kit's error is:
+
+ "Application App was not running at the end of the test. It likely crashed or was terminated for having become unresponsive."
+
+ This was caused by SDL/WinRT's DXGI failing to report any
+ outputs. Attempts to get the 1st display-output from the
+ 1st display-adapter can fail, with IDXGIAdapter::EnumOutputs
+ returning DXGI_ERROR_NOT_FOUND. This could be a bug in Windows,
+ the Windows App Certification Kit, or possibly in SDL/WinRT's
+ display detection code. Either way, try to detect when this
+ happens, and use a hackish means to create a reasonable-as-possible
+ 'display mode'. -- DavidL
+ */
+ if (adapterIndex == 0 && outputIndex == 0) {
+ SDL_VideoDisplay display;
+ SDL_DisplayMode mode;
+#if SDL_WINRT_USE_APPLICATIONVIEW
+ ApplicationView ^ appView = ApplicationView::GetForCurrentView();
+#endif
+ CoreWindow ^ coreWin = CoreWindow::GetForCurrentThread();
+ SDL_zero(display);
+ SDL_zero(mode);
+ display.name = "DXGI Display-detection Workaround";
+
+ /* HACK: ApplicationView's VisibleBounds property, appeared, via testing, to
+ give a better approximation of display-size, than did CoreWindow's
+ Bounds property, insofar that ApplicationView::VisibleBounds seems like
+ it will, at least some of the time, give the full display size (during the
+ failing test), whereas CoreWindow might not. -- DavidL
+ */
+
+#if (NTDDI_VERSION >= NTDDI_WIN10) || (SDL_WINRT_USE_APPLICATIONVIEW && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+ mode.w = WINRT_DIPS_TO_PHYSICAL_PIXELS(appView->VisibleBounds.Width);
+ mode.h = WINRT_DIPS_TO_PHYSICAL_PIXELS(appView->VisibleBounds.Height);
+#else
+ /* On platform(s) that do not support VisibleBounds, such as Windows 8.1,
+ fall back to CoreWindow's Bounds property.
+ */
+ mode.w = WINRT_DIPS_TO_PHYSICAL_PIXELS(coreWin->Bounds.Width);
+ mode.h = WINRT_DIPS_TO_PHYSICAL_PIXELS(coreWin->Bounds.Height);
+#endif
+
+ mode.format = DXGI_FORMAT_B8G8R8A8_UNORM;
+ mode.refresh_rate = 0; /* Display mode is unknown, so just fill in zero, as specified by SDL's header files */
+ display.desktop_mode = mode;
+ display.current_mode = mode;
+ if ((SDL_AddDisplayMode(&display, &mode) < 0) ||
+ (SDL_AddVideoDisplay(&display) < 0))
+ {
+ return SDL_SetError("Failed to apply DXGI Display-detection workaround");
+ }
+ }
+
+ break;
+ }
+ }
+
+ dxgiAdapter1->Release();
+ return 0;
+}
+
+int
+WINRT_InitModes(_THIS)
+{
+ /* HACK: Initialize a single display, for whatever screen the app's
+ CoreApplicationView is on.
+ TODO, WinRT: Try initializing multiple displays, one for each monitor.
+ Appropriate WinRT APIs for this seem elusive, though. -- DavidL
+ */
+
+ HRESULT hr;
+ IDXGIFactory2 * dxgiFactory2 = NULL;
+
+ hr = CreateDXGIFactory1(IID_IDXGIFactory2, (void **)&dxgiFactory2);
+ if (FAILED(hr)) {
+ WIN_SetErrorFromHRESULT(__FUNCTION__ ", CreateDXGIFactory1() failed", hr);
+ return -1;
+ }
+
+ for (int adapterIndex = 0; ; ++adapterIndex) {
+ if (WINRT_AddDisplaysForAdapter(_this, dxgiFactory2, adapterIndex) < 0) {
+ break;
+ }
+ }
+
+ return 0;
+}
+
+static int
+WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
+{
+ return 0;
+}
+
+void
+WINRT_VideoQuit(_THIS)
+{
+ SDL_VideoData * driverdata = (SDL_VideoData *) _this->driverdata;
+ if (driverdata && driverdata->displayRequest) {
+ driverdata->displayRequest->Release();
+ driverdata->displayRequest = NULL;
+ }
+ WINRT_QuitGameBar(_this);
+ WINRT_QuitMouse(_this);
+}
+
+static const Uint32 WINRT_DetectableFlags =
+ SDL_WINDOW_MAXIMIZED |
+ SDL_WINDOW_FULLSCREEN_DESKTOP |
+ SDL_WINDOW_SHOWN |
+ SDL_WINDOW_HIDDEN |
+ SDL_WINDOW_MOUSE_FOCUS;
+
+extern "C" Uint32
+WINRT_DetectWindowFlags(SDL_Window * window)
+{
+ Uint32 latestFlags = 0;
+ SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
+ bool is_fullscreen = false;
+
+#if SDL_WINRT_USE_APPLICATIONVIEW
+ if (data->appView) {
+ is_fullscreen = data->appView->IsFullScreen;
+ }
+#elif (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) || (NTDDI_VERSION == NTDDI_WIN8)
+ is_fullscreen = true;
+#endif
+
+ if (data->coreWindow.Get()) {
+ if (is_fullscreen) {
+ SDL_VideoDisplay * display = SDL_GetDisplayForWindow(window);
+ int w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
+ int h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
+
+#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) || (NTDDI_VERSION > NTDDI_WIN8)
+ // On all WinRT platforms, except for WinPhone 8.0, rotate the
+ // window size. This is needed to properly calculate
+ // fullscreen vs. maximized.
+ const DisplayOrientations currentOrientation = WINRT_DISPLAY_PROPERTY(CurrentOrientation);
+ switch (currentOrientation) {
+#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+ case DisplayOrientations::Landscape:
+ case DisplayOrientations::LandscapeFlipped:
+#else
+ case DisplayOrientations::Portrait:
+ case DisplayOrientations::PortraitFlipped:
+#endif
+ {
+ int tmp = w;
+ w = h;
+ h = tmp;
+ } break;
+ }
+#endif
+
+ if (display->desktop_mode.w != w || display->desktop_mode.h != h) {
+ latestFlags |= SDL_WINDOW_MAXIMIZED;
+ } else {
+ latestFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
+ }
+ }
+
+ if (data->coreWindow->Visible) {
+ latestFlags |= SDL_WINDOW_SHOWN;
+ } else {
+ latestFlags |= SDL_WINDOW_HIDDEN;
+ }
+
+#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) && (NTDDI_VERSION < NTDDI_WINBLUE)
+ // data->coreWindow->PointerPosition is not supported on WinPhone 8.0
+ latestFlags |= SDL_WINDOW_MOUSE_FOCUS;
+#else
+ if (data->coreWindow->Visible && data->coreWindow->Bounds.Contains(data->coreWindow->PointerPosition)) {
+ latestFlags |= SDL_WINDOW_MOUSE_FOCUS;
+ }
+#endif
+ }
+
+ return latestFlags;
+}
+
+// TODO, WinRT: consider removing WINRT_UpdateWindowFlags, and just calling WINRT_DetectWindowFlags as-appropriate (with appropriate calls to SDL_SendWindowEvent)
+void
+WINRT_UpdateWindowFlags(SDL_Window * window, Uint32 mask)
+{
+ mask &= WINRT_DetectableFlags;
+ if (window) {
+ Uint32 apply = WINRT_DetectWindowFlags(window);
+ if ((apply & mask) & SDL_WINDOW_FULLSCREEN) {
+ window->last_fullscreen_flags = window->flags; // seems necessary to programmatically un-fullscreen, via SDL APIs
+ }
+ window->flags = (window->flags & ~mask) | (apply & mask);
+ }
+}
+
+static bool
+WINRT_IsCoreWindowActive(CoreWindow ^ coreWindow)
+{
+ /* WinRT does not appear to offer API(s) to determine window-activation state,
+ at least not that I am aware of in Win8 - Win10. As such, SDL tracks this
+ itself, via window-activation events.
+
+ If there *is* an API to track this, it should probably get used instead
+ of the following hack (that uses "SDLHelperWindowActivationState").
+ -- DavidL.
+ */
+ if (coreWindow->CustomProperties->HasKey("SDLHelperWindowActivationState")) {
+ CoreWindowActivationState activationState = \
+ safe_cast<CoreWindowActivationState>(coreWindow->CustomProperties->Lookup("SDLHelperWindowActivationState"));
+ return (activationState != CoreWindowActivationState::Deactivated);
+ }
+
+ /* Assume that non-SDL tracked windows are active, although this should
+ probably be avoided, if possible.
+
+ This might not even be possible, in normal SDL use, at least as of
+ this writing (Dec 22, 2015; via latest hg.libsdl.org/SDL clone) -- DavidL
+ */
+ return true;
+}
+
+int
+WINRT_CreateWindow(_THIS, SDL_Window * window)
+{
+ // Make sure that only one window gets created, at least until multimonitor
+ // support is added.
+ if (WINRT_GlobalSDLWindow != NULL) {
+ SDL_SetError("WinRT only supports one window");
+ return -1;
+ }
+
+ SDL_WindowData *data = new SDL_WindowData; /* use 'new' here as SDL_WindowData may use WinRT/C++ types */
+ if (!data) {
+ SDL_OutOfMemory();
+ return -1;
+ }
+ window->driverdata = data;
+ data->sdlWindow = window;
+
+ /* To note, when XAML support is enabled, access to the CoreWindow will not
+ be possible, at least not via the SDL/XAML thread. Attempts to access it
+ from there will throw exceptions. As such, the SDL_WindowData's
+ 'coreWindow' field will only be set (to a non-null value) if XAML isn't
+ enabled.
+ */
+ if (!WINRT_XAMLWasEnabled) {
+ data->coreWindow = CoreWindow::GetForCurrentThread();
+#if SDL_WINRT_USE_APPLICATIONVIEW
+ data->appView = ApplicationView::GetForCurrentView();
+#endif
+ }
+
+ /* Make note of the requested window flags, before they start getting changed. */
+ const Uint32 requestedFlags = window->flags;
+
+#if SDL_VIDEO_OPENGL_EGL
+ /* Setup the EGL surface, but only if OpenGL ES 2 was requested. */
+ if (!(window->flags & SDL_WINDOW_OPENGL)) {
+ /* OpenGL ES 2 wasn't requested. Don't set up an EGL surface. */
+ data->egl_surface = EGL_NO_SURFACE;
+ } else {
+ /* OpenGL ES 2 was reuqested. Set up an EGL surface. */
+ SDL_VideoData * video_data = (SDL_VideoData *)_this->driverdata;
+
+ /* Call SDL_EGL_ChooseConfig and eglCreateWindowSurface directly,
+ * rather than via SDL_EGL_CreateSurface, as older versions of
+ * ANGLE/WinRT may require that a C++ object, ComPtr<IUnknown>,
+ * be passed into eglCreateWindowSurface.
+ */
+ if (SDL_EGL_ChooseConfig(_this) != 0) {
+ char buf[512];
+ SDL_snprintf(buf, sizeof(buf), "SDL_EGL_ChooseConfig failed: %s", SDL_GetError());
+ return SDL_SetError("%s", buf);
+ }
+
+ if (video_data->winrtEglWindow) { /* ... is the 'old' version of ANGLE/WinRT being used? */
+ /* Attempt to create a window surface using older versions of
+ * ANGLE/WinRT:
+ */
+ Microsoft::WRL::ComPtr<IUnknown> cpp_winrtEglWindow = video_data->winrtEglWindow;
+ data->egl_surface = ((eglCreateWindowSurface_Old_Function)_this->egl_data->eglCreateWindowSurface)(
+ _this->egl_data->egl_display,
+ _this->egl_data->egl_config,
+ cpp_winrtEglWindow, NULL);
+ if (data->egl_surface == NULL) {
+ return SDL_EGL_SetError("unable to create EGL native-window surface", "eglCreateWindowSurface");
+ }
+ } else if (data->coreWindow.Get() != nullptr) {
+ /* Attempt to create a window surface using newer versions of
+ * ANGLE/WinRT:
+ */
+ IInspectable * coreWindowAsIInspectable = reinterpret_cast<IInspectable *>(data->coreWindow.Get());
+ data->egl_surface = _this->egl_data->eglCreateWindowSurface(
+ _this->egl_data->egl_display,
+ _this->egl_data->egl_config,
+ coreWindowAsIInspectable,
+ NULL);
+ if (data->egl_surface == NULL) {
+ return SDL_EGL_SetError("unable to create EGL native-window surface", "eglCreateWindowSurface");
+ }
+ } else {
+ return SDL_SetError("No supported means to create an EGL window surface are available");
+ }
+ }
+#endif
+
+ /* Determine as many flags dynamically, as possible. */
+ window->flags =
+ SDL_WINDOW_BORDERLESS |
+ SDL_WINDOW_RESIZABLE;
+
+#if SDL_VIDEO_OPENGL_EGL
+ if (data->egl_surface) {
+ window->flags |= SDL_WINDOW_OPENGL;
+ }
+#endif
+
+ if (WINRT_XAMLWasEnabled) {
+ /* TODO, WinRT: set SDL_Window size, maybe position too, from XAML control */
+ window->x = 0;
+ window->y = 0;
+ window->flags |= SDL_WINDOW_SHOWN;
+ SDL_SetMouseFocus(NULL); // TODO: detect this
+ SDL_SetKeyboardFocus(NULL); // TODO: detect this
+ } else {
+ /* WinRT 8.x apps seem to live in an environment where the OS controls the
+ app's window size, with some apps being fullscreen, depending on
+ user choice of various things. For now, just adapt the SDL_Window to
+ whatever Windows set-up as the native-window's geometry.
+ */
+ window->x = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Left);
+ window->y = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Top);
+#if NTDDI_VERSION < NTDDI_WIN10
+ /* On WinRT 8.x / pre-Win10, just use the size we were given. */
+ window->w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
+ window->h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
+#else
+ /* On Windows 10, we occasionally get control over window size. For windowed
+ mode apps, try this.
+ */
+ bool didSetSize = false;
+ if (!(requestedFlags & SDL_WINDOW_FULLSCREEN)) {
+ const Windows::Foundation::Size size(WINRT_PHYSICAL_PIXELS_TO_DIPS(window->w),
+ WINRT_PHYSICAL_PIXELS_TO_DIPS(window->h));
+ didSetSize = data->appView->TryResizeView(size);
+ }
+ if (!didSetSize) {
+ /* We either weren't able to set the window size, or a request for
+ fullscreen was made. Get window-size info from the OS.
+ */
+ window->w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width);
+ window->h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height);
+ }
+#endif
+
+ WINRT_UpdateWindowFlags(
+ window,
+ 0xffffffff /* Update any window flag(s) that WINRT_UpdateWindow can handle */
+ );
+
+ /* Try detecting if the window is active */
+ bool isWindowActive = WINRT_IsCoreWindowActive(data->coreWindow.Get());
+ if (isWindowActive) {
+ SDL_SetKeyboardFocus(window);
+ }
+ }
+
+ /* Make sure the WinRT app's IFramworkView can post events on
+ behalf of SDL:
+ */
+ WINRT_GlobalSDLWindow = window;
+
+ /* All done! */
+ return 0;
+}
+
+void
+WINRT_SetWindowSize(_THIS, SDL_Window * window)
+{
+#if NTDDI_VERSION >= NTDDI_WIN10
+ SDL_WindowData * data = (SDL_WindowData *)window->driverdata;
+ const Windows::Foundation::Size size(WINRT_PHYSICAL_PIXELS_TO_DIPS(window->w),
+ WINRT_PHYSICAL_PIXELS_TO_DIPS(window->h));
+ data->appView->TryResizeView(size); // TODO, WinRT: return failure (to caller?) from TryResizeView()
+#endif
+}
+
+void
+WINRT_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
+{
+#if NTDDI_VERSION >= NTDDI_WIN10
+ SDL_WindowData * data = (SDL_WindowData *)window->driverdata;
+ bool isWindowActive = WINRT_IsCoreWindowActive(data->coreWindow.Get());
+ if (isWindowActive) {
+ if (fullscreen) {
+ if (!data->appView->IsFullScreenMode) {
+ data->appView->TryEnterFullScreenMode(); // TODO, WinRT: return failure (to caller?) from TryEnterFullScreenMode()
+ }
+ } else {
+ if (data->appView->IsFullScreenMode) {
+ data->appView->ExitFullScreenMode();
+ }
+ }
+ }
+#endif
+}
+
+
+void
+WINRT_DestroyWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
+
+ if (WINRT_GlobalSDLWindow == window) {
+ WINRT_GlobalSDLWindow = NULL;
+ }
+
+ if (data) {
+ // Delete the internal window data:
+ delete data;
+ data = NULL;
+ window->driverdata = NULL;
+ }
+}
+
+SDL_bool
+WINRT_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
+{
+ SDL_WindowData * data = (SDL_WindowData *) window->driverdata;
+
+ if (info->version.major <= SDL_MAJOR_VERSION) {
+ info->subsystem = SDL_SYSWM_WINRT;
+ info->info.winrt.window = reinterpret_cast<IInspectable *>(data->coreWindow.Get());
+ return SDL_TRUE;
+ } else {
+ SDL_SetError("Application not compiled with SDL %d.%d",
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+ return SDL_FALSE;
+ }
+ return SDL_FALSE;
+}
+
+static ABI::Windows::System::Display::IDisplayRequest *
+WINRT_CreateDisplayRequest(_THIS)
+{
+ /* Setup a WinRT DisplayRequest object, usable for enabling/disabling screensaver requests */
+ wchar_t *wClassName = L"Windows.System.Display.DisplayRequest";
+ HSTRING hClassName;
+ IActivationFactory *pActivationFactory = NULL;
+ IInspectable * pDisplayRequestRaw = nullptr;
+ ABI::Windows::System::Display::IDisplayRequest * pDisplayRequest = nullptr;
+ HRESULT hr;
+
+ hr = ::WindowsCreateString(wClassName, (UINT32)wcslen(wClassName), &hClassName);
+ if (FAILED(hr)) {
+ goto done;
+ }
+
+ hr = Windows::Foundation::GetActivationFactory(hClassName, &pActivationFactory);
+ if (FAILED(hr)) {
+ goto done;
+ }
+
+ hr = pActivationFactory->ActivateInstance(&pDisplayRequestRaw);
+ if (FAILED(hr)) {
+ goto done;
+ }
+
+ hr = pDisplayRequestRaw->QueryInterface(IID_IDisplayRequest, (void **) &pDisplayRequest);
+ if (FAILED(hr)) {
+ goto done;
+ }
+
+done:
+ if (pDisplayRequestRaw) {
+ pDisplayRequestRaw->Release();
+ }
+ if (pActivationFactory) {
+ pActivationFactory->Release();
+ }
+ if (hClassName) {
+ ::WindowsDeleteString(hClassName);
+ }
+
+ return pDisplayRequest;
+}
+
+void
+WINRT_SuspendScreenSaver(_THIS)
+{
+ SDL_VideoData *driverdata = (SDL_VideoData *)_this->driverdata;
+ if (driverdata && driverdata->displayRequest) {
+ ABI::Windows::System::Display::IDisplayRequest * displayRequest = (ABI::Windows::System::Display::IDisplayRequest *) driverdata->displayRequest;
+ if (_this->suspend_screensaver) {
+ displayRequest->RequestActive();
+ } else {
+ displayRequest->RequestRelease();
+ }
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_WINRT */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/winrt/SDL_winrtvideo_cpp.h b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtvideo_cpp.h
new file mode 100644
index 0000000..91e967e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/winrt/SDL_winrtvideo_cpp.h
@@ -0,0 +1,106 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/* Windows includes: */
+#include <windows.h>
+#ifdef __cplusplus_winrt
+#include <agile.h>
+#endif
+
+/* SDL includes: */
+#include "SDL_video.h"
+#include "SDL_events.h"
+
+#if NTDDI_VERSION >= NTDDI_WINBLUE /* ApplicationView's functionality only becomes
+ useful for SDL in Win[Phone] 8.1 and up.
+ Plus, it is not available at all in WinPhone 8.0. */
+#define SDL_WINRT_USE_APPLICATIONVIEW 1
+#endif
+
+extern "C" {
+#include "../SDL_sysvideo.h"
+#include "../SDL_egl_c.h"
+}
+
+/* Private display data */
+typedef struct SDL_VideoData {
+ /* An object created by ANGLE/WinRT (OpenGL ES 2 for WinRT) that gets
+ * passed to eglGetDisplay and eglCreateWindowSurface:
+ */
+ IUnknown *winrtEglWindow;
+
+ /* Event token(s), for unregistering WinRT event handler(s).
+ These are just a struct with a 64-bit integer inside them
+ */
+ Windows::Foundation::EventRegistrationToken gameBarIsInputRedirectedToken;
+
+ /* A WinRT DisplayRequest, used for implementing SDL_*ScreenSaver() functions.
+ * This is really a pointer to a 'ABI::Windows::System::Display::IDisplayRequest *',
+ * It's casted to 'IUnknown *', to help with building SDL.
+ */
+ IUnknown *displayRequest;
+} SDL_VideoData;
+
+/* The global, WinRT, SDL Window.
+ For now, SDL/WinRT only supports one window (due to platform limitations of
+ WinRT.
+*/
+extern SDL_Window * WINRT_GlobalSDLWindow;
+
+/* Updates one or more SDL_Window flags, by querying the OS' native windowing APIs.
+ SDL_Window flags that can be updated should be specified in 'mask'.
+*/
+extern void WINRT_UpdateWindowFlags(SDL_Window * window, Uint32 mask);
+extern "C" Uint32 WINRT_DetectWindowFlags(SDL_Window * window); /* detects flags w/o applying them */
+
+/* Display mode internals */
+//typedef struct
+//{
+// Windows::Graphics::Display::DisplayOrientations currentOrientation;
+//} SDL_DisplayModeData;
+
+#ifdef __cplusplus_winrt
+
+/* A convenience macro to get a WinRT display property */
+#if NTDDI_VERSION > NTDDI_WIN8
+#define WINRT_DISPLAY_PROPERTY(NAME) (Windows::Graphics::Display::DisplayInformation::GetForCurrentView()->NAME)
+#else
+#define WINRT_DISPLAY_PROPERTY(NAME) (Windows::Graphics::Display::DisplayProperties::NAME)
+#endif
+
+/* Converts DIPS to/from physical pixels */
+#define WINRT_DIPS_TO_PHYSICAL_PIXELS(DIPS) ((int)(0.5f + (((float)(DIPS) * (float)WINRT_DISPLAY_PROPERTY(LogicalDpi)) / 96.f)))
+#define WINRT_PHYSICAL_PIXELS_TO_DIPS(PHYSPIX) (((float)(PHYSPIX) * 96.f)/WINRT_DISPLAY_PROPERTY(LogicalDpi))
+
+/* Internal window data */
+struct SDL_WindowData
+{
+ SDL_Window *sdlWindow;
+ Platform::Agile<Windows::UI::Core::CoreWindow> coreWindow;
+#ifdef SDL_VIDEO_OPENGL_EGL
+ EGLSurface egl_surface;
+#endif
+#if SDL_WINRT_USE_APPLICATIONVIEW
+ Windows::UI::ViewManagement::ApplicationView ^ appView;
+#endif
+};
+
+#endif // ifdef __cplusplus_winrt
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11clipboard.c b/src/3rdparty/SDL2/src/video/x11/SDL_x11clipboard.c
new file mode 100644
index 0000000..fad8c9c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11clipboard.c
@@ -0,0 +1,199 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_X11
+
+#include <limits.h> /* For INT_MAX */
+
+#include "SDL_events.h"
+#include "SDL_x11video.h"
+#include "SDL_timer.h"
+
+
+/* If you don't support UTF-8, you might use XA_STRING here */
+#ifdef X_HAVE_UTF8_STRING
+#define TEXT_FORMAT X11_XInternAtom(display, "UTF8_STRING", False)
+#else
+#define TEXT_FORMAT XA_STRING
+#endif
+
+/* Get any application owned window handle for clipboard association */
+static Window
+GetWindow(_THIS)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
+ /* We create an unmapped window that exists just to manage the clipboard,
+ since X11 selection data is tied to a specific window and dies with it.
+ We create the window on demand, so apps that don't use the clipboard
+ don't have to keep an unnecessary resource around. */
+ if (data->clipboard_window == None) {
+ Display *dpy = data->display;
+ Window parent = RootWindow(dpy, DefaultScreen(dpy));
+ XSetWindowAttributes xattr;
+ data->clipboard_window = X11_XCreateWindow(dpy, parent, -10, -10, 1, 1, 0,
+ CopyFromParent, InputOnly,
+ CopyFromParent, 0, &xattr);
+ X11_XFlush(data->display);
+ }
+
+ return data->clipboard_window;
+}
+
+/* We use our own cut-buffer for intermediate storage instead of
+ XA_CUT_BUFFER0 because their use isn't really defined for holding UTF8. */
+Atom
+X11_GetSDLCutBufferClipboardType(Display *display)
+{
+ return X11_XInternAtom(display, "SDL_CUTBUFFER", False);
+}
+
+int
+X11_SetClipboardText(_THIS, const char *text)
+{
+ Display *display = ((SDL_VideoData *) _this->driverdata)->display;
+ Atom format;
+ Window window;
+ Atom XA_CLIPBOARD = X11_XInternAtom(display, "CLIPBOARD", 0);
+
+ /* Get the SDL window that will own the selection */
+ window = GetWindow(_this);
+ if (window == None) {
+ return SDL_SetError("Couldn't find a window to own the selection");
+ }
+
+ /* Save the selection on the root window */
+ format = TEXT_FORMAT;
+ X11_XChangeProperty(display, DefaultRootWindow(display),
+ X11_GetSDLCutBufferClipboardType(display), format, 8, PropModeReplace,
+ (const unsigned char *)text, SDL_strlen(text));
+
+ if (XA_CLIPBOARD != None &&
+ X11_XGetSelectionOwner(display, XA_CLIPBOARD) != window) {
+ X11_XSetSelectionOwner(display, XA_CLIPBOARD, window, CurrentTime);
+ }
+
+ if (X11_XGetSelectionOwner(display, XA_PRIMARY) != window) {
+ X11_XSetSelectionOwner(display, XA_PRIMARY, window, CurrentTime);
+ }
+ return 0;
+}
+
+char *
+X11_GetClipboardText(_THIS)
+{
+ SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
+ Display *display = videodata->display;
+ Atom format;
+ Window window;
+ Window owner;
+ Atom selection;
+ Atom seln_type;
+ int seln_format;
+ unsigned long nbytes;
+ unsigned long overflow;
+ unsigned char *src;
+ char *text;
+ Uint32 waitStart;
+ Uint32 waitElapsed;
+ Atom XA_CLIPBOARD = X11_XInternAtom(display, "CLIPBOARD", 0);
+ if (XA_CLIPBOARD == None) {
+ SDL_SetError("Couldn't access X clipboard");
+ return SDL_strdup("");
+ }
+
+ text = NULL;
+
+ /* Get the window that holds the selection */
+ window = GetWindow(_this);
+ format = TEXT_FORMAT;
+ owner = X11_XGetSelectionOwner(display, XA_CLIPBOARD);
+ if (owner == None) {
+ /* Fall back to ancient X10 cut-buffers which do not support UTF8 strings*/
+ owner = DefaultRootWindow(display);
+ selection = XA_CUT_BUFFER0;
+ format = XA_STRING;
+ } else if (owner == window) {
+ owner = DefaultRootWindow(display);
+ selection = X11_GetSDLCutBufferClipboardType(display);
+ } else {
+ /* Request that the selection owner copy the data to our window */
+ owner = window;
+ selection = X11_XInternAtom(display, "SDL_SELECTION", False);
+ X11_XConvertSelection(display, XA_CLIPBOARD, format, selection, owner,
+ CurrentTime);
+
+ /* When using synergy on Linux and when data has been put in the clipboard
+ on the remote (Windows anyway) machine then selection_waiting may never
+ be set to False. Time out after a while. */
+ waitStart = SDL_GetTicks();
+ videodata->selection_waiting = SDL_TRUE;
+ while (videodata->selection_waiting) {
+ SDL_PumpEvents();
+ waitElapsed = SDL_GetTicks() - waitStart;
+ /* Wait one second for a clipboard response. */
+ if (waitElapsed > 1000) {
+ videodata->selection_waiting = SDL_FALSE;
+ SDL_SetError("Clipboard timeout");
+ /* We need to set the clipboard text so that next time we won't
+ timeout, otherwise we will hang on every call to this function. */
+ X11_SetClipboardText(_this, "");
+ return SDL_strdup("");
+ }
+ }
+ }
+
+ if (X11_XGetWindowProperty(display, owner, selection, 0, INT_MAX/4, False,
+ format, &seln_type, &seln_format, &nbytes, &overflow, &src)
+ == Success) {
+ if (seln_type == format) {
+ text = (char *)SDL_malloc(nbytes+1);
+ if (text) {
+ SDL_memcpy(text, src, nbytes);
+ text[nbytes] = '\0';
+ }
+ }
+ X11_XFree(src);
+ }
+
+ if (!text) {
+ text = SDL_strdup("");
+ }
+
+ return text;
+}
+
+SDL_bool
+X11_HasClipboardText(_THIS)
+{
+ SDL_bool result = SDL_FALSE;
+ char *text = X11_GetClipboardText(_this);
+ if (text) {
+ result = text[0] != '\0' ? SDL_TRUE : SDL_FALSE;
+ SDL_free(text);
+ }
+ return result;
+}
+
+#endif /* SDL_VIDEO_DRIVER_X11 */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11clipboard.h b/src/3rdparty/SDL2/src/video/x11/SDL_x11clipboard.h
new file mode 100644
index 0000000..97aff1b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11clipboard.h
@@ -0,0 +1,33 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_x11clipboard_h_
+#define SDL_x11clipboard_h_
+
+extern int X11_SetClipboardText(_THIS, const char *text);
+extern char *X11_GetClipboardText(_THIS);
+extern SDL_bool X11_HasClipboardText(_THIS);
+extern Atom X11_GetSDLCutBufferClipboardType(Display *display);
+
+#endif /* SDL_x11clipboard_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11dyn.c b/src/3rdparty/SDL2/src/video/x11/SDL_x11dyn.c
new file mode 100644
index 0000000..89f736a
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11dyn.c
@@ -0,0 +1,212 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_X11
+
+#define DEBUG_DYNAMIC_X11 0
+
+#include "SDL_x11dyn.h"
+
+#if DEBUG_DYNAMIC_X11
+#include <stdio.h>
+#endif
+
+#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
+
+#include "SDL_name.h"
+#include "SDL_loadso.h"
+
+typedef struct
+{
+ void *lib;
+ const char *libname;
+} x11dynlib;
+
+#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC NULL
+#endif
+#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT NULL
+#endif
+#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR NULL
+#endif
+#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA NULL
+#endif
+#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 NULL
+#endif
+#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR NULL
+#endif
+#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS NULL
+#endif
+#ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE
+#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE NULL
+#endif
+
+static x11dynlib x11libs[] = {
+ {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC},
+ {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT},
+ {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR},
+ {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA},
+ {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2},
+ {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR},
+ {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS},
+ {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE}
+};
+
+static void *
+X11_GetSym(const char *fnname, int *pHasModule)
+{
+ int i;
+ void *fn = NULL;
+ for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
+ if (x11libs[i].lib != NULL) {
+ fn = SDL_LoadFunction(x11libs[i].lib, fnname);
+ if (fn != NULL)
+ break;
+ }
+ }
+
+#if DEBUG_DYNAMIC_X11
+ if (fn != NULL)
+ printf("X11: Found '%s' in %s (%p)\n", fnname, x11libs[i].libname, fn);
+ else
+ printf("X11: Symbol '%s' NOT FOUND!\n", fnname);
+#endif
+
+ if (fn == NULL)
+ *pHasModule = 0; /* kill this module. */
+
+ return fn;
+}
+
+#endif /* SDL_VIDEO_DRIVER_X11_DYNAMIC */
+
+/* Define all the function pointers and wrappers... */
+#define SDL_X11_SYM(rc,fn,params,args,ret) SDL_DYNX11FN_##fn X11_##fn = NULL;
+#include "SDL_x11sym.h"
+
+/* Annoying varargs entry point... */
+#ifdef X_HAVE_UTF8_STRING
+SDL_DYNX11FN_XCreateIC X11_XCreateIC = NULL;
+SDL_DYNX11FN_XGetICValues X11_XGetICValues = NULL;
+#endif
+
+/* These SDL_X11_HAVE_* flags are here whether you have dynamic X11 or not. */
+#define SDL_X11_MODULE(modname) int SDL_X11_HAVE_##modname = 0;
+#include "SDL_x11sym.h"
+
+static int x11_load_refcount = 0;
+
+void
+SDL_X11_UnloadSymbols(void)
+{
+ /* Don't actually unload if more than one module is using the libs... */
+ if (x11_load_refcount > 0) {
+ if (--x11_load_refcount == 0) {
+ int i;
+
+ /* set all the function pointers to NULL. */
+#define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 0;
+#define SDL_X11_SYM(rc,fn,params,args,ret) X11_##fn = NULL;
+#include "SDL_x11sym.h"
+
+#ifdef X_HAVE_UTF8_STRING
+ X11_XCreateIC = NULL;
+ X11_XGetICValues = NULL;
+#endif
+
+#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
+ for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
+ if (x11libs[i].lib != NULL) {
+ SDL_UnloadObject(x11libs[i].lib);
+ x11libs[i].lib = NULL;
+ }
+ }
+#endif
+ }
+ }
+}
+
+/* returns non-zero if all needed symbols were loaded. */
+int
+SDL_X11_LoadSymbols(void)
+{
+ int rc = 1; /* always succeed if not using Dynamic X11 stuff. */
+
+ /* deal with multiple modules (dga, x11, etc) needing these symbols... */
+ if (x11_load_refcount++ == 0) {
+#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
+ int i;
+ int *thismod = NULL;
+ for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
+ if (x11libs[i].libname != NULL) {
+ x11libs[i].lib = SDL_LoadObject(x11libs[i].libname);
+ }
+ }
+
+#define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1; /* default yes */
+#include "SDL_x11sym.h"
+
+#define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname;
+#define SDL_X11_SYM(a,fn,x,y,z) X11_##fn = (SDL_DYNX11FN_##fn) X11_GetSym(#fn,thismod);
+#include "SDL_x11sym.h"
+
+#ifdef X_HAVE_UTF8_STRING
+ X11_XCreateIC = (SDL_DYNX11FN_XCreateIC)
+ X11_GetSym("XCreateIC", &SDL_X11_HAVE_UTF8);
+ X11_XGetICValues = (SDL_DYNX11FN_XGetICValues)
+ X11_GetSym("XGetICValues", &SDL_X11_HAVE_UTF8);
+#endif
+
+ if (SDL_X11_HAVE_BASEXLIB) {
+ /* all required symbols loaded. */
+ SDL_ClearError();
+ } else {
+ /* in case something got loaded... */
+ SDL_X11_UnloadSymbols();
+ rc = 0;
+ }
+
+#else /* no dynamic X11 */
+
+#define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1; /* default yes */
+#define SDL_X11_SYM(a,fn,x,y,z) X11_##fn = (SDL_DYNX11FN_##fn) fn;
+#include "SDL_x11sym.h"
+
+#ifdef X_HAVE_UTF8_STRING
+ X11_XCreateIC = XCreateIC;
+ X11_XGetICValues = XGetICValues;
+#endif
+#endif
+ }
+
+ return rc;
+}
+
+#endif /* SDL_VIDEO_DRIVER_X11 */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11dyn.h b/src/3rdparty/SDL2/src/video/x11/SDL_x11dyn.h
new file mode 100644
index 0000000..d3866e7
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11dyn.h
@@ -0,0 +1,111 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_x11dyn_h_
+#define SDL_x11dyn_h_
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xatom.h>
+
+#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
+#include <X11/XKBlib.h>
+#endif
+
+/* Apparently some X11 systems can't include this multiple times... */
+#ifndef SDL_INCLUDED_XLIBINT_H
+#define SDL_INCLUDED_XLIBINT_H 1
+#include <X11/Xlibint.h>
+#endif
+
+#include <X11/Xproto.h>
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+
+#ifndef NO_SHARED_MEMORY
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <X11/extensions/XShm.h>
+#endif
+
+#if SDL_VIDEO_DRIVER_X11_XCURSOR
+#include <X11/Xcursor/Xcursor.h>
+#endif
+#if SDL_VIDEO_DRIVER_X11_XDBE
+#include <X11/extensions/Xdbe.h>
+#endif
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+#include <X11/extensions/Xinerama.h>
+#endif
+#if SDL_VIDEO_DRIVER_X11_XINPUT2
+#include <X11/extensions/XInput2.h>
+#endif
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+#include <X11/extensions/Xrandr.h>
+#endif
+#if SDL_VIDEO_DRIVER_X11_XSCRNSAVER
+#include <X11/extensions/scrnsaver.h>
+#endif
+#if SDL_VIDEO_DRIVER_X11_XSHAPE
+#include <X11/extensions/shape.h>
+#endif
+#if SDL_VIDEO_DRIVER_X11_XVIDMODE
+#include <X11/extensions/xf86vmode.h>
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/* evil function signatures... */
+typedef Bool(*SDL_X11_XESetWireToEventRetType) (Display *, XEvent *, xEvent *);
+typedef int (*SDL_X11_XSynchronizeRetType) (Display *);
+typedef Status(*SDL_X11_XESetEventToWireRetType) (Display *, XEvent *, xEvent *);
+
+int SDL_X11_LoadSymbols(void);
+void SDL_X11_UnloadSymbols(void);
+
+/* Declare all the function pointers and wrappers... */
+#define SDL_X11_SYM(rc,fn,params,args,ret) \
+ typedef rc (*SDL_DYNX11FN_##fn) params; \
+ extern SDL_DYNX11FN_##fn X11_##fn;
+#include "SDL_x11sym.h"
+
+/* Annoying varargs entry point... */
+#ifdef X_HAVE_UTF8_STRING
+typedef XIC(*SDL_DYNX11FN_XCreateIC) (XIM,...);
+typedef char *(*SDL_DYNX11FN_XGetICValues) (XIC, ...);
+extern SDL_DYNX11FN_XCreateIC X11_XCreateIC;
+extern SDL_DYNX11FN_XGetICValues X11_XGetICValues;
+#endif
+
+/* These SDL_X11_HAVE_* flags are here whether you have dynamic X11 or not. */
+#define SDL_X11_MODULE(modname) extern int SDL_X11_HAVE_##modname;
+#include "SDL_x11sym.h"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !defined SDL_x11dyn_h_ */
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11events.c b/src/3rdparty/SDL2/src/video/x11/SDL_x11events.c
new file mode 100644
index 0000000..d293a5e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11events.c
@@ -0,0 +1,1500 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_X11
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <signal.h>
+#include <unistd.h>
+#include <limits.h> /* For INT_MAX */
+
+#include "SDL_x11video.h"
+#include "SDL_x11touch.h"
+#include "SDL_x11xinput2.h"
+#include "../../core/unix/SDL_poll.h"
+#include "../../events/SDL_events_c.h"
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_touch_c.h"
+
+#include "SDL_hints.h"
+#include "SDL_timer.h"
+#include "SDL_syswm.h"
+#include "SDL_assert.h"
+
+#include <stdio.h>
+
+/*#define DEBUG_XEVENTS*/
+
+#ifndef _NET_WM_MOVERESIZE_SIZE_TOPLEFT
+#define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
+#endif
+
+#ifndef _NET_WM_MOVERESIZE_SIZE_TOP
+#define _NET_WM_MOVERESIZE_SIZE_TOP 1
+#endif
+
+#ifndef _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
+#define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
+#endif
+
+#ifndef _NET_WM_MOVERESIZE_SIZE_RIGHT
+#define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
+#endif
+
+#ifndef _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
+#define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
+#endif
+
+#ifndef _NET_WM_MOVERESIZE_SIZE_BOTTOM
+#define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
+#endif
+
+#ifndef _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
+#define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
+#endif
+
+#ifndef _NET_WM_MOVERESIZE_SIZE_LEFT
+#define _NET_WM_MOVERESIZE_SIZE_LEFT 7
+#endif
+
+#ifndef _NET_WM_MOVERESIZE_MOVE
+#define _NET_WM_MOVERESIZE_MOVE 8
+#endif
+
+typedef struct {
+ unsigned char *data;
+ int format, count;
+ Atom type;
+} SDL_x11Prop;
+
+/* Reads property
+ Must call X11_XFree on results
+ */
+static void X11_ReadProperty(SDL_x11Prop *p, Display *disp, Window w, Atom prop)
+{
+ unsigned char *ret=NULL;
+ Atom type;
+ int fmt;
+ unsigned long count;
+ unsigned long bytes_left;
+ int bytes_fetch = 0;
+
+ do {
+ if (ret != 0) X11_XFree(ret);
+ X11_XGetWindowProperty(disp, w, prop, 0, bytes_fetch, False, AnyPropertyType, &type, &fmt, &count, &bytes_left, &ret);
+ bytes_fetch += bytes_left;
+ } while (bytes_left != 0);
+
+ p->data=ret;
+ p->format=fmt;
+ p->count=count;
+ p->type=type;
+}
+
+/* Find text-uri-list in a list of targets and return it's atom
+ if available, else return None */
+static Atom X11_PickTarget(Display *disp, Atom list[], int list_count)
+{
+ Atom request = None;
+ char *name;
+ int i;
+ for (i=0; i < list_count && request == None; i++) {
+ name = X11_XGetAtomName(disp, list[i]);
+ if ((SDL_strcmp("text/uri-list", name) == 0) || (SDL_strcmp("text/plain", name) == 0)) {
+ request = list[i];
+ }
+ X11_XFree(name);
+ }
+ return request;
+}
+
+/* Wrapper for X11_PickTarget for a maximum of three targets, a special
+ case in the Xdnd protocol */
+static Atom X11_PickTargetFromAtoms(Display *disp, Atom a0, Atom a1, Atom a2)
+{
+ int count=0;
+ Atom atom[3];
+ if (a0 != None) atom[count++] = a0;
+ if (a1 != None) atom[count++] = a1;
+ if (a2 != None) atom[count++] = a2;
+ return X11_PickTarget(disp, atom, count);
+}
+
+struct KeyRepeatCheckData
+{
+ XEvent *event;
+ SDL_bool found;
+};
+
+static Bool X11_KeyRepeatCheckIfEvent(Display *display, XEvent *chkev,
+ XPointer arg)
+{
+ struct KeyRepeatCheckData *d = (struct KeyRepeatCheckData *) arg;
+ if (chkev->type == KeyPress &&
+ chkev->xkey.keycode == d->event->xkey.keycode &&
+ chkev->xkey.time - d->event->xkey.time < 2)
+ d->found = SDL_TRUE;
+ return False;
+}
+
+/* Check to see if this is a repeated key.
+ (idea shamelessly lifted from GII -- thanks guys! :)
+ */
+static SDL_bool X11_KeyRepeat(Display *display, XEvent *event)
+{
+ XEvent dummyev;
+ struct KeyRepeatCheckData d;
+ d.event = event;
+ d.found = SDL_FALSE;
+ if (X11_XPending(display))
+ X11_XCheckIfEvent(display, &dummyev, X11_KeyRepeatCheckIfEvent,
+ (XPointer) &d);
+ return d.found;
+}
+
+static SDL_bool
+X11_IsWheelEvent(Display * display,XEvent * event,int * xticks,int * yticks)
+{
+ /* according to the xlib docs, no specific mouse wheel events exist.
+ However, the defacto standard is that the vertical wheel is X buttons
+ 4 (up) and 5 (down) and a horizontal wheel is 6 (left) and 7 (right). */
+
+ /* Xlib defines "Button1" through 5, so we just use literals here. */
+ switch (event->xbutton.button) {
+ case 4: *yticks = 1; return SDL_TRUE;
+ case 5: *yticks = -1; return SDL_TRUE;
+ case 6: *xticks = 1; return SDL_TRUE;
+ case 7: *xticks = -1; return SDL_TRUE;
+ default: break;
+ }
+ return SDL_FALSE;
+}
+
+/* Decodes URI escape sequences in string buf of len bytes
+ (excluding the terminating NULL byte) in-place. Since
+ URI-encoded characters take three times the space of
+ normal characters, this should not be an issue.
+
+ Returns the number of decoded bytes that wound up in
+ the buffer, excluding the terminating NULL byte.
+
+ The buffer is guaranteed to be NULL-terminated but
+ may contain embedded NULL bytes.
+
+ On error, -1 is returned.
+ */
+static int X11_URIDecode(char *buf, int len) {
+ int ri, wi, di;
+ char decode = '\0';
+ if (buf == NULL || len < 0) {
+ errno = EINVAL;
+ return -1;
+ }
+ if (len == 0) {
+ len = SDL_strlen(buf);
+ }
+ for (ri = 0, wi = 0, di = 0; ri < len && wi < len; ri += 1) {
+ if (di == 0) {
+ /* start decoding */
+ if (buf[ri] == '%') {
+ decode = '\0';
+ di += 1;
+ continue;
+ }
+ /* normal write */
+ buf[wi] = buf[ri];
+ wi += 1;
+ continue;
+ } else if (di == 1 || di == 2) {
+ char off = '\0';
+ char isa = buf[ri] >= 'a' && buf[ri] <= 'f';
+ char isA = buf[ri] >= 'A' && buf[ri] <= 'F';
+ char isn = buf[ri] >= '0' && buf[ri] <= '9';
+ if (!(isa || isA || isn)) {
+ /* not a hexadecimal */
+ int sri;
+ for (sri = ri - di; sri <= ri; sri += 1) {
+ buf[wi] = buf[sri];
+ wi += 1;
+ }
+ di = 0;
+ continue;
+ }
+ /* itsy bitsy magicsy */
+ if (isn) {
+ off = 0 - '0';
+ } else if (isa) {
+ off = 10 - 'a';
+ } else if (isA) {
+ off = 10 - 'A';
+ }
+ decode |= (buf[ri] + off) << (2 - di) * 4;
+ if (di == 2) {
+ buf[wi] = decode;
+ wi += 1;
+ di = 0;
+ } else {
+ di += 1;
+ }
+ continue;
+ }
+ }
+ buf[wi] = '\0';
+ return wi;
+}
+
+/* Convert URI to local filename
+ return filename if possible, else NULL
+*/
+static char* X11_URIToLocal(char* uri) {
+ char *file = NULL;
+ SDL_bool local;
+
+ if (memcmp(uri,"file:/",6) == 0) uri += 6; /* local file? */
+ else if (strstr(uri,":/") != NULL) return file; /* wrong scheme */
+
+ local = uri[0] != '/' || (uri[0] != '\0' && uri[1] == '/');
+
+ /* got a hostname? */
+ if (!local && uri[0] == '/' && uri[2] != '/') {
+ char* hostname_end = strchr(uri+1, '/');
+ if (hostname_end != NULL) {
+ char hostname[ 257 ];
+ if (gethostname(hostname, 255) == 0) {
+ hostname[ 256 ] = '\0';
+ if (memcmp(uri+1, hostname, hostname_end - (uri+1)) == 0) {
+ uri = hostname_end + 1;
+ local = SDL_TRUE;
+ }
+ }
+ }
+ }
+ if (local) {
+ file = uri;
+ /* Convert URI escape sequences to real characters */
+ X11_URIDecode(file, 0);
+ if (uri[1] == '/') {
+ file++;
+ } else {
+ file--;
+ }
+ }
+ return file;
+}
+
+#if SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
+static void X11_HandleGenericEvent(SDL_VideoData *videodata, XEvent *xev)
+{
+ /* event is a union, so cookie == &event, but this is type safe. */
+ XGenericEventCookie *cookie = &xev->xcookie;
+ if (X11_XGetEventData(videodata->display, cookie)) {
+ X11_HandleXinput2Event(videodata, cookie);
+ X11_XFreeEventData(videodata->display, cookie);
+ }
+}
+#endif /* SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS */
+
+static unsigned
+X11_GetNumLockModifierMask(_THIS)
+{
+ SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
+ Display *display = viddata->display;
+ unsigned num_mask = 0;
+ int i, j;
+ XModifierKeymap *xmods;
+ unsigned n;
+
+ xmods = X11_XGetModifierMapping(display);
+ n = xmods->max_keypermod;
+ for(i = 3; i < 8; i++) {
+ for(j = 0; j < n; j++) {
+ KeyCode kc = xmods->modifiermap[i * n + j];
+ if (viddata->key_layout[kc] == SDL_SCANCODE_NUMLOCKCLEAR) {
+ num_mask = 1 << i;
+ break;
+ }
+ }
+ }
+ X11_XFreeModifiermap(xmods);
+
+ return num_mask;
+}
+
+static void
+X11_ReconcileKeyboardState(_THIS)
+{
+ SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
+ Display *display = viddata->display;
+ char keys[32];
+ int keycode;
+ Window junk_window;
+ int x, y;
+ unsigned int mask;
+ const Uint8 *keyboardState;
+
+ X11_XQueryKeymap(display, keys);
+
+ /* Sync up the keyboard modifier state */
+ if (X11_XQueryPointer(display, DefaultRootWindow(display), &junk_window, &junk_window, &x, &y, &x, &y, &mask)) {
+ SDL_ToggleModState(KMOD_CAPS, (mask & LockMask) != 0);
+ SDL_ToggleModState(KMOD_NUM, (mask & X11_GetNumLockModifierMask(_this)) != 0);
+ }
+
+ keyboardState = SDL_GetKeyboardState(0);
+ for (keycode = 0; keycode < 256; ++keycode) {
+ SDL_Scancode scancode = viddata->key_layout[keycode];
+ SDL_bool x11KeyPressed = (keys[keycode / 8] & (1 << (keycode % 8))) != 0;
+ SDL_bool sdlKeyPressed = keyboardState[scancode] == SDL_PRESSED;
+
+ if (x11KeyPressed && !sdlKeyPressed) {
+ SDL_SendKeyboardKey(SDL_PRESSED, scancode);
+ } else if (!x11KeyPressed && sdlKeyPressed) {
+ SDL_SendKeyboardKey(SDL_RELEASED, scancode);
+ }
+ }
+}
+
+
+static void
+X11_DispatchFocusIn(_THIS, SDL_WindowData *data)
+{
+#ifdef DEBUG_XEVENTS
+ printf("window %p: Dispatching FocusIn\n", data);
+#endif
+ SDL_SetKeyboardFocus(data->window);
+ X11_ReconcileKeyboardState(_this);
+#ifdef X_HAVE_UTF8_STRING
+ if (data->ic) {
+ X11_XSetICFocus(data->ic);
+ }
+#endif
+#ifdef SDL_USE_IME
+ SDL_IME_SetFocus(SDL_TRUE);
+#endif
+}
+
+static void
+X11_DispatchFocusOut(_THIS, SDL_WindowData *data)
+{
+#ifdef DEBUG_XEVENTS
+ printf("window %p: Dispatching FocusOut\n", data);
+#endif
+ /* If another window has already processed a focus in, then don't try to
+ * remove focus here. Doing so will incorrectly remove focus from that
+ * window, and the focus lost event for this window will have already
+ * been dispatched anyway. */
+ if (data->window == SDL_GetKeyboardFocus()) {
+ SDL_SetKeyboardFocus(NULL);
+ }
+#ifdef X_HAVE_UTF8_STRING
+ if (data->ic) {
+ X11_XUnsetICFocus(data->ic);
+ }
+#endif
+#ifdef SDL_USE_IME
+ SDL_IME_SetFocus(SDL_FALSE);
+#endif
+}
+
+static void
+X11_DispatchMapNotify(SDL_WindowData *data)
+{
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
+}
+
+static void
+X11_DispatchUnmapNotify(SDL_WindowData *data)
+{
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
+}
+
+static void
+InitiateWindowMove(_THIS, const SDL_WindowData *data, const SDL_Point *point)
+{
+ SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
+ SDL_Window* window = data->window;
+ Display *display = viddata->display;
+ XEvent evt;
+
+ /* !!! FIXME: we need to regrab this if necessary when the drag is done. */
+ X11_XUngrabPointer(display, 0L);
+ X11_XFlush(display);
+
+ evt.xclient.type = ClientMessage;
+ evt.xclient.window = data->xwindow;
+ evt.xclient.message_type = X11_XInternAtom(display, "_NET_WM_MOVERESIZE", True);
+ evt.xclient.format = 32;
+ evt.xclient.data.l[0] = window->x + point->x;
+ evt.xclient.data.l[1] = window->y + point->y;
+ evt.xclient.data.l[2] = _NET_WM_MOVERESIZE_MOVE;
+ evt.xclient.data.l[3] = Button1;
+ evt.xclient.data.l[4] = 0;
+ X11_XSendEvent(display, DefaultRootWindow(display), False, SubstructureRedirectMask | SubstructureNotifyMask, &evt);
+
+ X11_XSync(display, 0);
+}
+
+static void
+InitiateWindowResize(_THIS, const SDL_WindowData *data, const SDL_Point *point, int direction)
+{
+ SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
+ SDL_Window* window = data->window;
+ Display *display = viddata->display;
+ XEvent evt;
+
+ if (direction < _NET_WM_MOVERESIZE_SIZE_TOPLEFT || direction > _NET_WM_MOVERESIZE_SIZE_LEFT)
+ return;
+
+ /* !!! FIXME: we need to regrab this if necessary when the drag is done. */
+ X11_XUngrabPointer(display, 0L);
+ X11_XFlush(display);
+
+ evt.xclient.type = ClientMessage;
+ evt.xclient.window = data->xwindow;
+ evt.xclient.message_type = X11_XInternAtom(display, "_NET_WM_MOVERESIZE", True);
+ evt.xclient.format = 32;
+ evt.xclient.data.l[0] = window->x + point->x;
+ evt.xclient.data.l[1] = window->y + point->y;
+ evt.xclient.data.l[2] = direction;
+ evt.xclient.data.l[3] = Button1;
+ evt.xclient.data.l[4] = 0;
+ X11_XSendEvent(display, DefaultRootWindow(display), False, SubstructureRedirectMask | SubstructureNotifyMask, &evt);
+
+ X11_XSync(display, 0);
+}
+
+static SDL_bool
+ProcessHitTest(_THIS, const SDL_WindowData *data, const XEvent *xev)
+{
+ SDL_Window *window = data->window;
+
+ if (window->hit_test) {
+ const SDL_Point point = { xev->xbutton.x, xev->xbutton.y };
+ const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data);
+ static const int directions[] = {
+ _NET_WM_MOVERESIZE_SIZE_TOPLEFT, _NET_WM_MOVERESIZE_SIZE_TOP,
+ _NET_WM_MOVERESIZE_SIZE_TOPRIGHT, _NET_WM_MOVERESIZE_SIZE_RIGHT,
+ _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT, _NET_WM_MOVERESIZE_SIZE_BOTTOM,
+ _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT, _NET_WM_MOVERESIZE_SIZE_LEFT
+ };
+
+ switch (rc) {
+ case SDL_HITTEST_DRAGGABLE:
+ InitiateWindowMove(_this, data, &point);
+ return SDL_TRUE;
+
+ case SDL_HITTEST_RESIZE_TOPLEFT:
+ case SDL_HITTEST_RESIZE_TOP:
+ case SDL_HITTEST_RESIZE_TOPRIGHT:
+ case SDL_HITTEST_RESIZE_RIGHT:
+ case SDL_HITTEST_RESIZE_BOTTOMRIGHT:
+ case SDL_HITTEST_RESIZE_BOTTOM:
+ case SDL_HITTEST_RESIZE_BOTTOMLEFT:
+ case SDL_HITTEST_RESIZE_LEFT:
+ InitiateWindowResize(_this, data, &point, directions[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
+ return SDL_TRUE;
+
+ default: return SDL_FALSE;
+ }
+ }
+
+ return SDL_FALSE;
+}
+
+static void
+X11_UpdateUserTime(SDL_WindowData *data, const unsigned long latest)
+{
+ if (latest && (latest != data->user_time)) {
+ SDL_VideoData *videodata = data->videodata;
+ Display *display = videodata->display;
+ X11_XChangeProperty(display, data->xwindow, videodata->_NET_WM_USER_TIME,
+ XA_CARDINAL, 32, PropModeReplace,
+ (const unsigned char *) &latest, 1);
+#ifdef DEBUG_XEVENTS
+ printf("window %p: updating _NET_WM_USER_TIME to %lu\n", data, latest);
+#endif
+ data->user_time = latest;
+ }
+}
+
+static void
+X11_HandleClipboardEvent(_THIS, const XEvent *xevent)
+{
+ SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
+ Display *display = videodata->display;
+
+ SDL_assert(videodata->clipboard_window != None);
+ SDL_assert(xevent->xany.window == videodata->clipboard_window);
+
+ switch (xevent->type) {
+ /* Copy the selection from our own CUTBUFFER to the requested property */
+ case SelectionRequest: {
+ const XSelectionRequestEvent *req = &xevent->xselectionrequest;
+ XEvent sevent;
+ int seln_format;
+ unsigned long nbytes;
+ unsigned long overflow;
+ unsigned char *seln_data;
+
+#ifdef DEBUG_XEVENTS
+ printf("window CLIPBOARD: SelectionRequest (requestor = %ld, target = %ld)\n",
+ req->requestor, req->target);
+#endif
+
+ SDL_zero(sevent);
+ sevent.xany.type = SelectionNotify;
+ sevent.xselection.selection = req->selection;
+ sevent.xselection.target = None;
+ sevent.xselection.property = None; /* tell them no by default */
+ sevent.xselection.requestor = req->requestor;
+ sevent.xselection.time = req->time;
+
+ /* !!! FIXME: We were probably storing this on the root window
+ because an SDL window might go away...? but we don't have to do
+ this now (or ever, really). */
+ if (X11_XGetWindowProperty(display, DefaultRootWindow(display),
+ X11_GetSDLCutBufferClipboardType(display), 0, INT_MAX/4, False, req->target,
+ &sevent.xselection.target, &seln_format, &nbytes,
+ &overflow, &seln_data) == Success) {
+ /* !!! FIXME: cache atoms */
+ Atom XA_TARGETS = X11_XInternAtom(display, "TARGETS", 0);
+ if (sevent.xselection.target == req->target) {
+ X11_XChangeProperty(display, req->requestor, req->property,
+ sevent.xselection.target, seln_format, PropModeReplace,
+ seln_data, nbytes);
+ sevent.xselection.property = req->property;
+ } else if (XA_TARGETS == req->target) {
+ Atom SupportedFormats[] = { XA_TARGETS, sevent.xselection.target };
+ X11_XChangeProperty(display, req->requestor, req->property,
+ XA_ATOM, 32, PropModeReplace,
+ (unsigned char*)SupportedFormats,
+ SDL_arraysize(SupportedFormats));
+ sevent.xselection.property = req->property;
+ sevent.xselection.target = XA_TARGETS;
+ }
+ X11_XFree(seln_data);
+ }
+ X11_XSendEvent(display, req->requestor, False, 0, &sevent);
+ X11_XSync(display, False);
+ }
+ break;
+
+ case SelectionNotify: {
+#ifdef DEBUG_XEVENTS
+ printf("window CLIPBOARD: SelectionNotify (requestor = %ld, target = %ld)\n",
+ xevent->xselection.requestor, xevent->xselection.target);
+#endif
+ videodata->selection_waiting = SDL_FALSE;
+ }
+ break;
+
+ case SelectionClear: {
+ /* !!! FIXME: cache atoms */
+ Atom XA_CLIPBOARD = X11_XInternAtom(display, "CLIPBOARD", 0);
+
+#ifdef DEBUG_XEVENTS
+ printf("window CLIPBOARD: SelectionClear (requestor = %ld, target = %ld)\n",
+ xevent->xselection.requestor, xevent->xselection.target);
+#endif
+
+ if (xevent->xselectionclear.selection == XA_PRIMARY ||
+ (XA_CLIPBOARD != None && xevent->xselectionclear.selection == XA_CLIPBOARD)) {
+ SDL_SendClipboardUpdate();
+ }
+ }
+ break;
+ }
+}
+
+
+static void
+X11_DispatchEvent(_THIS)
+{
+ SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
+ Display *display;
+ SDL_WindowData *data;
+ XEvent xevent;
+ int orig_event_type;
+ KeyCode orig_keycode;
+ XClientMessageEvent m;
+ int i;
+
+ if (!videodata) {
+ return;
+ }
+ display = videodata->display;
+
+ SDL_zero(xevent); /* valgrind fix. --ryan. */
+ X11_XNextEvent(display, &xevent);
+
+ /* Save the original keycode for dead keys, which are filtered out by
+ the XFilterEvent() call below.
+ */
+ orig_event_type = xevent.type;
+ if (orig_event_type == KeyPress || orig_event_type == KeyRelease) {
+ orig_keycode = xevent.xkey.keycode;
+ } else {
+ orig_keycode = 0;
+ }
+
+ /* filter events catchs XIM events and sends them to the correct handler */
+ if (X11_XFilterEvent(&xevent, None) == True) {
+#if 0
+ printf("Filtered event type = %d display = %d window = %d\n",
+ xevent.type, xevent.xany.display, xevent.xany.window);
+#endif
+ /* Make sure dead key press/release events are sent */
+ /* But only if we're using one of the DBus IMEs, otherwise
+ some XIM IMEs will generate duplicate events */
+ if (orig_keycode) {
+#if defined(HAVE_IBUS_IBUS_H) || defined(HAVE_FCITX_FRONTEND_H)
+ SDL_Scancode scancode = videodata->key_layout[orig_keycode];
+ videodata->filter_code = orig_keycode;
+ videodata->filter_time = xevent.xkey.time;
+
+ if (orig_event_type == KeyPress) {
+ SDL_SendKeyboardKey(SDL_PRESSED, scancode);
+ } else {
+ SDL_SendKeyboardKey(SDL_RELEASED, scancode);
+ }
+#endif
+ }
+ return;
+ }
+
+ /* Send a SDL_SYSWMEVENT if the application wants them */
+ if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
+ SDL_SysWMmsg wmmsg;
+
+ SDL_VERSION(&wmmsg.version);
+ wmmsg.subsystem = SDL_SYSWM_X11;
+ wmmsg.msg.x11.event = xevent;
+ SDL_SendSysWMEvent(&wmmsg);
+ }
+
+#if SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
+ if(xevent.type == GenericEvent) {
+ X11_HandleGenericEvent(videodata, &xevent);
+ return;
+ }
+#endif
+
+#if 0
+ printf("type = %d display = %d window = %d\n",
+ xevent.type, xevent.xany.display, xevent.xany.window);
+#endif
+
+ if ((videodata->clipboard_window != None) &&
+ (videodata->clipboard_window == xevent.xany.window)) {
+ X11_HandleClipboardEvent(_this, &xevent);
+ return;
+ }
+
+ data = NULL;
+ if (videodata && videodata->windowlist) {
+ for (i = 0; i < videodata->numwindows; ++i) {
+ if ((videodata->windowlist[i] != NULL) &&
+ (videodata->windowlist[i]->xwindow == xevent.xany.window)) {
+ data = videodata->windowlist[i];
+ break;
+ }
+ }
+ }
+ if (!data) {
+ /* The window for KeymapNotify, etc events is 0 */
+ if (xevent.type == KeymapNotify) {
+ if (SDL_GetKeyboardFocus() != NULL) {
+ X11_ReconcileKeyboardState(_this);
+ }
+ } else if (xevent.type == MappingNotify) {
+ /* Has the keyboard layout changed? */
+ const int request = xevent.xmapping.request;
+
+#ifdef DEBUG_XEVENTS
+ printf("window %p: MappingNotify!\n", data);
+#endif
+ if ((request == MappingKeyboard) || (request == MappingModifier)) {
+ X11_XRefreshKeyboardMapping(&xevent.xmapping);
+ }
+
+ X11_UpdateKeymap(_this);
+ SDL_SendKeymapChangedEvent();
+ }
+ return;
+ }
+
+ switch (xevent.type) {
+
+ /* Gaining mouse coverage? */
+ case EnterNotify:{
+ SDL_Mouse *mouse = SDL_GetMouse();
+#ifdef DEBUG_XEVENTS
+ printf("window %p: EnterNotify! (%d,%d,%d)\n", data,
+ xevent.xcrossing.x,
+ xevent.xcrossing.y,
+ xevent.xcrossing.mode);
+ if (xevent.xcrossing.mode == NotifyGrab)
+ printf("Mode: NotifyGrab\n");
+ if (xevent.xcrossing.mode == NotifyUngrab)
+ printf("Mode: NotifyUngrab\n");
+#endif
+ SDL_SetMouseFocus(data->window);
+
+ mouse->last_x = xevent.xcrossing.x;
+ mouse->last_y = xevent.xcrossing.y;
+
+ if (!mouse->relative_mode) {
+ SDL_SendMouseMotion(data->window, 0, 0, xevent.xcrossing.x, xevent.xcrossing.y);
+ }
+ }
+ break;
+ /* Losing mouse coverage? */
+ case LeaveNotify:{
+#ifdef DEBUG_XEVENTS
+ printf("window %p: LeaveNotify! (%d,%d,%d)\n", data,
+ xevent.xcrossing.x,
+ xevent.xcrossing.y,
+ xevent.xcrossing.mode);
+ if (xevent.xcrossing.mode == NotifyGrab)
+ printf("Mode: NotifyGrab\n");
+ if (xevent.xcrossing.mode == NotifyUngrab)
+ printf("Mode: NotifyUngrab\n");
+#endif
+ if (!SDL_GetMouse()->relative_mode) {
+ SDL_SendMouseMotion(data->window, 0, 0, xevent.xcrossing.x, xevent.xcrossing.y);
+ }
+
+ if (xevent.xcrossing.mode != NotifyGrab &&
+ xevent.xcrossing.mode != NotifyUngrab &&
+ xevent.xcrossing.detail != NotifyInferior) {
+ SDL_SetMouseFocus(NULL);
+ }
+ }
+ break;
+
+ /* Gaining input focus? */
+ case FocusIn:{
+ if (xevent.xfocus.mode == NotifyGrab || xevent.xfocus.mode == NotifyUngrab) {
+ /* Someone is handling a global hotkey, ignore it */
+#ifdef DEBUG_XEVENTS
+ printf("window %p: FocusIn (NotifyGrab/NotifyUngrab, ignoring)\n", data);
+#endif
+ break;
+ }
+
+ if (xevent.xfocus.detail == NotifyInferior) {
+#ifdef DEBUG_XEVENTS
+ printf("window %p: FocusIn (NotifierInferior, ignoring)\n", data);
+#endif
+ break;
+ }
+#ifdef DEBUG_XEVENTS
+ printf("window %p: FocusIn!\n", data);
+#endif
+ if (!videodata->last_mode_change_deadline) /* no recent mode changes */
+ {
+ data->pending_focus = PENDING_FOCUS_NONE;
+ data->pending_focus_time = 0;
+ X11_DispatchFocusIn(_this, data);
+ }
+ else
+ {
+ data->pending_focus = PENDING_FOCUS_IN;
+ data->pending_focus_time = SDL_GetTicks() + PENDING_FOCUS_TIME;
+ }
+ data->last_focus_event_time = SDL_GetTicks();
+ }
+ break;
+
+ /* Losing input focus? */
+ case FocusOut:{
+ if (xevent.xfocus.mode == NotifyGrab || xevent.xfocus.mode == NotifyUngrab) {
+ /* Someone is handling a global hotkey, ignore it */
+#ifdef DEBUG_XEVENTS
+ printf("window %p: FocusOut (NotifyGrab/NotifyUngrab, ignoring)\n", data);
+#endif
+ break;
+ }
+ if (xevent.xfocus.detail == NotifyInferior) {
+ /* We still have focus if a child gets focus */
+#ifdef DEBUG_XEVENTS
+ printf("window %p: FocusOut (NotifierInferior, ignoring)\n", data);
+#endif
+ break;
+ }
+#ifdef DEBUG_XEVENTS
+ printf("window %p: FocusOut!\n", data);
+#endif
+ if (!videodata->last_mode_change_deadline) /* no recent mode changes */
+ {
+ data->pending_focus = PENDING_FOCUS_NONE;
+ data->pending_focus_time = 0;
+ X11_DispatchFocusOut(_this, data);
+ }
+ else
+ {
+ data->pending_focus = PENDING_FOCUS_OUT;
+ data->pending_focus_time = SDL_GetTicks() + PENDING_FOCUS_TIME;
+ }
+ }
+ break;
+
+ /* Key press? */
+ case KeyPress:{
+ KeyCode keycode = xevent.xkey.keycode;
+ KeySym keysym = NoSymbol;
+ char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
+ Status status = 0;
+ SDL_bool handled_by_ime = SDL_FALSE;
+
+#ifdef DEBUG_XEVENTS
+ printf("window %p: KeyPress (X11 keycode = 0x%X)\n", data, xevent.xkey.keycode);
+#endif
+#if 1
+ if (videodata->key_layout[keycode] == SDL_SCANCODE_UNKNOWN && keycode) {
+ int min_keycode, max_keycode;
+ X11_XDisplayKeycodes(display, &min_keycode, &max_keycode);
+ keysym = X11_KeyCodeToSym(_this, keycode, xevent.xkey.state >> 13);
+ fprintf(stderr,
+ "The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL forums/mailing list <https://discourse.libsdl.org/> X11 KeyCode %d (%d), X11 KeySym 0x%lX (%s).\n",
+ keycode, keycode - min_keycode, keysym,
+ X11_XKeysymToString(keysym));
+ }
+#endif
+ /* */
+ SDL_zero(text);
+#ifdef X_HAVE_UTF8_STRING
+ if (data->ic) {
+ X11_Xutf8LookupString(data->ic, &xevent.xkey, text, sizeof(text),
+ &keysym, &status);
+ } else {
+ X11_XLookupString(&xevent.xkey, text, sizeof(text), &keysym, NULL);
+ }
+#else
+ X11_XLookupString(&xevent.xkey, text, sizeof(text), &keysym, NULL);
+#endif
+
+#ifdef SDL_USE_IME
+ if(SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE){
+ handled_by_ime = SDL_IME_ProcessKeyEvent(keysym, keycode);
+ }
+#endif
+ if (!handled_by_ime) {
+ /* Don't send the key if it looks like a duplicate of a filtered key sent by an IME */
+ if (xevent.xkey.keycode != videodata->filter_code || xevent.xkey.time != videodata->filter_time) {
+ SDL_SendKeyboardKey(SDL_PRESSED, videodata->key_layout[keycode]);
+ }
+ if(*text) {
+ SDL_SendKeyboardText(text);
+ }
+ }
+
+ X11_UpdateUserTime(data, xevent.xkey.time);
+ }
+ break;
+
+ /* Key release? */
+ case KeyRelease:{
+ KeyCode keycode = xevent.xkey.keycode;
+
+#ifdef DEBUG_XEVENTS
+ printf("window %p: KeyRelease (X11 keycode = 0x%X)\n", data, xevent.xkey.keycode);
+#endif
+ if (X11_KeyRepeat(display, &xevent)) {
+ /* We're about to get a repeated key down, ignore the key up */
+ break;
+ }
+ SDL_SendKeyboardKey(SDL_RELEASED, videodata->key_layout[keycode]);
+ }
+ break;
+
+ /* Have we been iconified? */
+ case UnmapNotify:{
+#ifdef DEBUG_XEVENTS
+ printf("window %p: UnmapNotify!\n", data);
+#endif
+ X11_DispatchUnmapNotify(data);
+ }
+ break;
+
+ /* Have we been restored? */
+ case MapNotify:{
+#ifdef DEBUG_XEVENTS
+ printf("window %p: MapNotify!\n", data);
+#endif
+ X11_DispatchMapNotify(data);
+ }
+ break;
+
+ /* Have we been resized or moved? */
+ case ConfigureNotify:{
+#ifdef DEBUG_XEVENTS
+ printf("window %p: ConfigureNotify! (position: %d,%d, size: %dx%d)\n", data,
+ xevent.xconfigure.x, xevent.xconfigure.y,
+ xevent.xconfigure.width, xevent.xconfigure.height);
+#endif
+ /* Real configure notify events are relative to the parent, synthetic events are absolute. */
+ if (!xevent.xconfigure.send_event) {
+ unsigned int NumChildren;
+ Window ChildReturn, Root, Parent;
+ Window * Children;
+ /* Translate these coodinates back to relative to root */
+ X11_XQueryTree(data->videodata->display, xevent.xconfigure.window, &Root, &Parent, &Children, &NumChildren);
+ X11_XTranslateCoordinates(xevent.xconfigure.display,
+ Parent, DefaultRootWindow(xevent.xconfigure.display),
+ xevent.xconfigure.x, xevent.xconfigure.y,
+ &xevent.xconfigure.x, &xevent.xconfigure.y,
+ &ChildReturn);
+ }
+
+ if (xevent.xconfigure.x != data->last_xconfigure.x ||
+ xevent.xconfigure.y != data->last_xconfigure.y) {
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED,
+ xevent.xconfigure.x, xevent.xconfigure.y);
+#ifdef SDL_USE_IME
+ if(SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE){
+ /* Update IME candidate list position */
+ SDL_IME_UpdateTextRect(NULL);
+ }
+#endif
+ }
+ if (xevent.xconfigure.width != data->last_xconfigure.width ||
+ xevent.xconfigure.height != data->last_xconfigure.height) {
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESIZED,
+ xevent.xconfigure.width,
+ xevent.xconfigure.height);
+ }
+ data->last_xconfigure = xevent.xconfigure;
+ }
+ break;
+
+ /* Have we been requested to quit (or another client message?) */
+ case ClientMessage:{
+
+ static int xdnd_version=0;
+
+ if (xevent.xclient.message_type == videodata->XdndEnter) {
+
+ SDL_bool use_list = xevent.xclient.data.l[1] & 1;
+ data->xdnd_source = xevent.xclient.data.l[0];
+ xdnd_version = (xevent.xclient.data.l[1] >> 24);
+#ifdef DEBUG_XEVENTS
+ printf("XID of source window : %ld\n", data->xdnd_source);
+ printf("Protocol version to use : %d\n", xdnd_version);
+ printf("More then 3 data types : %d\n", (int) use_list);
+#endif
+
+ if (use_list) {
+ /* fetch conversion targets */
+ SDL_x11Prop p;
+ X11_ReadProperty(&p, display, data->xdnd_source, videodata->XdndTypeList);
+ /* pick one */
+ data->xdnd_req = X11_PickTarget(display, (Atom*)p.data, p.count);
+ X11_XFree(p.data);
+ } else {
+ /* pick from list of three */
+ data->xdnd_req = X11_PickTargetFromAtoms(display, xevent.xclient.data.l[2], xevent.xclient.data.l[3], xevent.xclient.data.l[4]);
+ }
+ }
+ else if (xevent.xclient.message_type == videodata->XdndPosition) {
+
+#ifdef DEBUG_XEVENTS
+ Atom act= videodata->XdndActionCopy;
+ if(xdnd_version >= 2) {
+ act = xevent.xclient.data.l[4];
+ }
+ printf("Action requested by user is : %s\n", X11_XGetAtomName(display , act));
+#endif
+
+
+ /* reply with status */
+ memset(&m, 0, sizeof(XClientMessageEvent));
+ m.type = ClientMessage;
+ m.display = xevent.xclient.display;
+ m.window = xevent.xclient.data.l[0];
+ m.message_type = videodata->XdndStatus;
+ m.format=32;
+ m.data.l[0] = data->xwindow;
+ m.data.l[1] = (data->xdnd_req != None);
+ m.data.l[2] = 0; /* specify an empty rectangle */
+ m.data.l[3] = 0;
+ m.data.l[4] = videodata->XdndActionCopy; /* we only accept copying anyway */
+
+ X11_XSendEvent(display, xevent.xclient.data.l[0], False, NoEventMask, (XEvent*)&m);
+ X11_XFlush(display);
+ }
+ else if(xevent.xclient.message_type == videodata->XdndDrop) {
+ if (data->xdnd_req == None) {
+ /* say again - not interested! */
+ memset(&m, 0, sizeof(XClientMessageEvent));
+ m.type = ClientMessage;
+ m.display = xevent.xclient.display;
+ m.window = xevent.xclient.data.l[0];
+ m.message_type = videodata->XdndFinished;
+ m.format=32;
+ m.data.l[0] = data->xwindow;
+ m.data.l[1] = 0;
+ m.data.l[2] = None; /* fail! */
+ X11_XSendEvent(display, xevent.xclient.data.l[0], False, NoEventMask, (XEvent*)&m);
+ } else {
+ /* convert */
+ if(xdnd_version >= 1) {
+ X11_XConvertSelection(display, videodata->XdndSelection, data->xdnd_req, videodata->PRIMARY, data->xwindow, xevent.xclient.data.l[2]);
+ } else {
+ X11_XConvertSelection(display, videodata->XdndSelection, data->xdnd_req, videodata->PRIMARY, data->xwindow, CurrentTime);
+ }
+ }
+ }
+ else if ((xevent.xclient.message_type == videodata->WM_PROTOCOLS) &&
+ (xevent.xclient.format == 32) &&
+ (xevent.xclient.data.l[0] == videodata->_NET_WM_PING)) {
+ Window root = DefaultRootWindow(display);
+
+#ifdef DEBUG_XEVENTS
+ printf("window %p: _NET_WM_PING\n", data);
+#endif
+ xevent.xclient.window = root;
+ X11_XSendEvent(display, root, False, SubstructureRedirectMask | SubstructureNotifyMask, &xevent);
+ break;
+ }
+
+ else if ((xevent.xclient.message_type == videodata->WM_PROTOCOLS) &&
+ (xevent.xclient.format == 32) &&
+ (xevent.xclient.data.l[0] == videodata->WM_DELETE_WINDOW)) {
+
+#ifdef DEBUG_XEVENTS
+ printf("window %p: WM_DELETE_WINDOW\n", data);
+#endif
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
+ break;
+ }
+ else if ((xevent.xclient.message_type == videodata->WM_PROTOCOLS) &&
+ (xevent.xclient.format == 32) &&
+ (xevent.xclient.data.l[0] == videodata->WM_TAKE_FOCUS)) {
+
+#ifdef DEBUG_XEVENTS
+ printf("window %p: WM_TAKE_FOCUS\n", data);
+#endif
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_TAKE_FOCUS, 0, 0);
+ break;
+ }
+ }
+ break;
+
+ /* Do we need to refresh ourselves? */
+ case Expose:{
+#ifdef DEBUG_XEVENTS
+ printf("window %p: Expose (count = %d)\n", data, xevent.xexpose.count);
+#endif
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
+ }
+ break;
+
+ case MotionNotify:{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ if(!mouse->relative_mode || mouse->relative_mode_warp) {
+#ifdef DEBUG_MOTION
+ printf("window %p: X11 motion: %d,%d\n", data, xevent.xmotion.x, xevent.xmotion.y);
+#endif
+
+ SDL_SendMouseMotion(data->window, 0, 0, xevent.xmotion.x, xevent.xmotion.y);
+ }
+ }
+ break;
+
+ case ButtonPress:{
+ int xticks = 0, yticks = 0;
+#ifdef DEBUG_XEVENTS
+ printf("window %p: ButtonPress (X11 button = %d)\n", data, xevent.xbutton.button);
+#endif
+ if (X11_IsWheelEvent(display,&xevent,&xticks, &yticks)) {
+ SDL_SendMouseWheel(data->window, 0, (float) xticks, (float) yticks, SDL_MOUSEWHEEL_NORMAL);
+ } else {
+ SDL_bool ignore_click = SDL_FALSE;
+ int button = xevent.xbutton.button;
+ if(button == Button1) {
+ if (ProcessHitTest(_this, data, &xevent)) {
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
+ break; /* don't pass this event on to app. */
+ }
+ }
+ else if(button > 7) {
+ /* X button values 4-7 are used for scrolling, so X1 is 8, X2 is 9, ...
+ => subtract (8-SDL_BUTTON_X1) to get value SDL expects */
+ button -= (8-SDL_BUTTON_X1);
+ }
+ if (data->last_focus_event_time) {
+ const int X11_FOCUS_CLICK_TIMEOUT = 10;
+ if (!SDL_TICKS_PASSED(SDL_GetTicks(), data->last_focus_event_time + X11_FOCUS_CLICK_TIMEOUT)) {
+ ignore_click = !SDL_GetHintBoolean(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, SDL_FALSE);
+ }
+ data->last_focus_event_time = 0;
+ }
+ if (!ignore_click) {
+ SDL_SendMouseButton(data->window, 0, SDL_PRESSED, button);
+ }
+ }
+ X11_UpdateUserTime(data, xevent.xbutton.time);
+ }
+ break;
+
+ case ButtonRelease:{
+ int button = xevent.xbutton.button;
+ /* The X server sends a Release event for each Press for wheels. Ignore them. */
+ int xticks = 0, yticks = 0;
+#ifdef DEBUG_XEVENTS
+ printf("window %p: ButtonRelease (X11 button = %d)\n", data, xevent.xbutton.button);
+#endif
+ if (!X11_IsWheelEvent(display, &xevent, &xticks, &yticks)) {
+ if (button > 7) {
+ /* see explanation at case ButtonPress */
+ button -= (8-SDL_BUTTON_X1);
+ }
+ SDL_SendMouseButton(data->window, 0, SDL_RELEASED, button);
+ }
+ }
+ break;
+
+ case PropertyNotify:{
+#ifdef DEBUG_XEVENTS
+ unsigned char *propdata;
+ int status, real_format;
+ Atom real_type;
+ unsigned long items_read, items_left;
+
+ char *name = X11_XGetAtomName(display, xevent.xproperty.atom);
+ if (name) {
+ printf("window %p: PropertyNotify: %s %s time=%lu\n", data, name, (xevent.xproperty.state == PropertyDelete) ? "deleted" : "changed", xevent.xproperty.time);
+ X11_XFree(name);
+ }
+
+ status = X11_XGetWindowProperty(display, data->xwindow, xevent.xproperty.atom, 0L, 8192L, False, AnyPropertyType, &real_type, &real_format, &items_read, &items_left, &propdata);
+ if (status == Success && items_read > 0) {
+ if (real_type == XA_INTEGER) {
+ int *values = (int *)propdata;
+
+ printf("{");
+ for (i = 0; i < items_read; i++) {
+ printf(" %d", values[i]);
+ }
+ printf(" }\n");
+ } else if (real_type == XA_CARDINAL) {
+ if (real_format == 32) {
+ Uint32 *values = (Uint32 *)propdata;
+
+ printf("{");
+ for (i = 0; i < items_read; i++) {
+ printf(" %d", values[i]);
+ }
+ printf(" }\n");
+ } else if (real_format == 16) {
+ Uint16 *values = (Uint16 *)propdata;
+
+ printf("{");
+ for (i = 0; i < items_read; i++) {
+ printf(" %d", values[i]);
+ }
+ printf(" }\n");
+ } else if (real_format == 8) {
+ Uint8 *values = (Uint8 *)propdata;
+
+ printf("{");
+ for (i = 0; i < items_read; i++) {
+ printf(" %d", values[i]);
+ }
+ printf(" }\n");
+ }
+ } else if (real_type == XA_STRING ||
+ real_type == videodata->UTF8_STRING) {
+ printf("{ \"%s\" }\n", propdata);
+ } else if (real_type == XA_ATOM) {
+ Atom *atoms = (Atom *)propdata;
+
+ printf("{");
+ for (i = 0; i < items_read; i++) {
+ char *atomname = X11_XGetAtomName(display, atoms[i]);
+ if (atomname) {
+ printf(" %s", atomname);
+ X11_XFree(atomname);
+ }
+ }
+ printf(" }\n");
+ } else {
+ char *atomname = X11_XGetAtomName(display, real_type);
+ printf("Unknown type: %ld (%s)\n", real_type, atomname ? atomname : "UNKNOWN");
+ if (atomname) {
+ X11_XFree(atomname);
+ }
+ }
+ }
+ if (status == Success) {
+ X11_XFree(propdata);
+ }
+#endif /* DEBUG_XEVENTS */
+
+ /* Take advantage of this moment to make sure user_time has a
+ valid timestamp from the X server, so if we later try to
+ raise/restore this window, _NET_ACTIVE_WINDOW can have a
+ non-zero timestamp, even if there's never been a mouse or
+ key press to this window so far. Note that we don't try to
+ set _NET_WM_USER_TIME here, though. That's only for legit
+ user interaction with the window. */
+ if (!data->user_time) {
+ data->user_time = xevent.xproperty.time;
+ }
+
+ if (xevent.xproperty.atom == data->videodata->_NET_WM_STATE) {
+ /* Get the new state from the window manager.
+ Compositing window managers can alter visibility of windows
+ without ever mapping / unmapping them, so we handle that here,
+ because they use the NETWM protocol to notify us of changes.
+ */
+ const Uint32 flags = X11_GetNetWMState(_this, xevent.xproperty.window);
+ const Uint32 changed = flags ^ data->window->flags;
+
+ if ((changed & SDL_WINDOW_HIDDEN) || (changed & SDL_WINDOW_FULLSCREEN)) {
+ if (flags & SDL_WINDOW_HIDDEN) {
+ X11_DispatchUnmapNotify(data);
+ } else {
+ X11_DispatchMapNotify(data);
+ }
+ }
+
+ if (changed & SDL_WINDOW_MAXIMIZED) {
+ if (flags & SDL_WINDOW_MAXIMIZED) {
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
+ } else {
+ SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
+ }
+ }
+ } else if (xevent.xproperty.atom == videodata->XKLAVIER_STATE) {
+ /* Hack for Ubuntu 12.04 (etc) that doesn't send MappingNotify
+ events when the keyboard layout changes (for example,
+ changing from English to French on the menubar's keyboard
+ icon). Since it changes the XKLAVIER_STATE property, we
+ notice and reinit our keymap here. This might not be the
+ right approach, but it seems to work. */
+ X11_UpdateKeymap(_this);
+ SDL_SendKeymapChangedEvent();
+ } else if (xevent.xproperty.atom == videodata->_NET_FRAME_EXTENTS) {
+ Atom type;
+ int format;
+ unsigned long nitems, bytes_after;
+ unsigned char *property;
+ if (X11_XGetWindowProperty(display, data->xwindow, videodata->_NET_FRAME_EXTENTS, 0, 16, 0, XA_CARDINAL, &type, &format, &nitems, &bytes_after, &property) == Success) {
+ if (type != None && nitems == 4) {
+ data->border_left = (int) ((long*)property)[0];
+ data->border_right = (int) ((long*)property)[1];
+ data->border_top = (int) ((long*)property)[2];
+ data->border_bottom = (int) ((long*)property)[3];
+ }
+ X11_XFree(property);
+
+ #ifdef DEBUG_XEVENTS
+ printf("New _NET_FRAME_EXTENTS: left=%d right=%d, top=%d, bottom=%d\n", data->border_left, data->border_right, data->border_top, data->border_bottom);
+ #endif
+ }
+ }
+ }
+ break;
+
+ case SelectionNotify: {
+ Atom target = xevent.xselection.target;
+#ifdef DEBUG_XEVENTS
+ printf("window %p: SelectionNotify (requestor = %ld, target = %ld)\n", data,
+ xevent.xselection.requestor, xevent.xselection.target);
+#endif
+ if (target == data->xdnd_req) {
+ /* read data */
+ SDL_x11Prop p;
+ X11_ReadProperty(&p, display, data->xwindow, videodata->PRIMARY);
+
+ if (p.format == 8) {
+ /* !!! FIXME: don't use strtok here. It's not reentrant and not in SDL_stdinc. */
+ char* name = X11_XGetAtomName(display, target);
+ char *token = strtok((char *) p.data, "\r\n");
+ while (token != NULL) {
+ if (SDL_strcmp("text/plain", name)==0) {
+ SDL_SendDropText(data->window, token);
+ } else if (SDL_strcmp("text/uri-list", name)==0) {
+ char *fn = X11_URIToLocal(token);
+ if (fn) {
+ SDL_SendDropFile(data->window, fn);
+ }
+ }
+ token = strtok(NULL, "\r\n");
+ }
+ SDL_SendDropComplete(data->window);
+ }
+ X11_XFree(p.data);
+
+ /* send reply */
+ SDL_memset(&m, 0, sizeof(XClientMessageEvent));
+ m.type = ClientMessage;
+ m.display = display;
+ m.window = data->xdnd_source;
+ m.message_type = videodata->XdndFinished;
+ m.format = 32;
+ m.data.l[0] = data->xwindow;
+ m.data.l[1] = 1;
+ m.data.l[2] = videodata->XdndActionCopy;
+ X11_XSendEvent(display, data->xdnd_source, False, NoEventMask, (XEvent*)&m);
+
+ X11_XSync(display, False);
+ }
+ }
+ break;
+
+ default:{
+#ifdef DEBUG_XEVENTS
+ printf("window %p: Unhandled event %d\n", data, xevent.type);
+#endif
+ }
+ break;
+ }
+}
+
+static void
+X11_HandleFocusChanges(_THIS)
+{
+ SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
+ int i;
+
+ if (videodata && videodata->windowlist) {
+ for (i = 0; i < videodata->numwindows; ++i) {
+ SDL_WindowData *data = videodata->windowlist[i];
+ if (data && data->pending_focus != PENDING_FOCUS_NONE) {
+ Uint32 now = SDL_GetTicks();
+ if (SDL_TICKS_PASSED(now, data->pending_focus_time)) {
+ if (data->pending_focus == PENDING_FOCUS_IN) {
+ X11_DispatchFocusIn(_this, data);
+ } else {
+ X11_DispatchFocusOut(_this, data);
+ }
+ data->pending_focus = PENDING_FOCUS_NONE;
+ }
+ }
+ }
+ }
+}
+/* Ack! X11_XPending() actually performs a blocking read if no events available */
+static int
+X11_Pending(Display * display)
+{
+ /* Flush the display connection and look to see if events are queued */
+ X11_XFlush(display);
+ if (X11_XEventsQueued(display, QueuedAlready)) {
+ return (1);
+ }
+
+ /* More drastic measures are required -- see if X is ready to talk */
+ if (SDL_IOReady(ConnectionNumber(display), SDL_FALSE, 0)) {
+ return (X11_XPending(display));
+ }
+
+ /* Oh well, nothing is ready .. */
+ return (0);
+}
+
+void
+X11_PumpEvents(_THIS)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
+ if (data->last_mode_change_deadline) {
+ if (SDL_TICKS_PASSED(SDL_GetTicks(), data->last_mode_change_deadline)) {
+ data->last_mode_change_deadline = 0; /* assume we're done. */
+ }
+ }
+
+ /* Update activity every 30 seconds to prevent screensaver */
+ if (_this->suspend_screensaver) {
+ const Uint32 now = SDL_GetTicks();
+ if (!data->screensaver_activity ||
+ SDL_TICKS_PASSED(now, data->screensaver_activity + 30000)) {
+ X11_XResetScreenSaver(data->display);
+
+#if SDL_USE_LIBDBUS
+ SDL_DBus_ScreensaverTickle();
+#endif
+
+ data->screensaver_activity = now;
+ }
+ }
+
+ /* Keep processing pending events */
+ while (X11_Pending(data->display)) {
+ X11_DispatchEvent(_this);
+ }
+
+#ifdef SDL_USE_IME
+ if(SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE){
+ SDL_IME_PumpEvents();
+ }
+#endif
+
+ /* FIXME: Only need to do this when there are pending focus changes */
+ X11_HandleFocusChanges(_this);
+}
+
+
+void
+X11_SuspendScreenSaver(_THIS)
+{
+#if SDL_VIDEO_DRIVER_X11_XSCRNSAVER
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+ int dummy;
+ int major_version, minor_version;
+#endif /* SDL_VIDEO_DRIVER_X11_XSCRNSAVER */
+
+#if SDL_USE_LIBDBUS
+ if (SDL_DBus_ScreensaverInhibit(_this->suspend_screensaver)) {
+ return;
+ }
+
+ if (_this->suspend_screensaver) {
+ SDL_DBus_ScreensaverTickle();
+ }
+#endif
+
+#if SDL_VIDEO_DRIVER_X11_XSCRNSAVER
+ if (SDL_X11_HAVE_XSS) {
+ /* X11_XScreenSaverSuspend was introduced in MIT-SCREEN-SAVER 1.1 */
+ if (!X11_XScreenSaverQueryExtension(data->display, &dummy, &dummy) ||
+ !X11_XScreenSaverQueryVersion(data->display,
+ &major_version, &minor_version) ||
+ major_version < 1 || (major_version == 1 && minor_version < 1)) {
+ return;
+ }
+
+ X11_XScreenSaverSuspend(data->display, _this->suspend_screensaver);
+ X11_XResetScreenSaver(data->display);
+ }
+#endif
+}
+
+#endif /* SDL_VIDEO_DRIVER_X11 */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11events.h b/src/3rdparty/SDL2/src/video/x11/SDL_x11events.h
new file mode 100644
index 0000000..53c69a5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11events.h
@@ -0,0 +1,31 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_x11events_h_
+#define SDL_x11events_h_
+
+extern void X11_PumpEvents(_THIS);
+extern void X11_SuspendScreenSaver(_THIS);
+
+#endif /* SDL_x11events_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11framebuffer.c b/src/3rdparty/SDL2/src/video/x11/SDL_x11framebuffer.c
new file mode 100644
index 0000000..ad58170
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11framebuffer.c
@@ -0,0 +1,257 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_X11
+
+#include "SDL_x11video.h"
+#include "SDL_x11framebuffer.h"
+
+
+#ifndef NO_SHARED_MEMORY
+
+/* Shared memory error handler routine */
+static int shm_error;
+static int (*X_handler)(Display *, XErrorEvent *) = NULL;
+static int shm_errhandler(Display *d, XErrorEvent *e)
+{
+ if ( e->error_code == BadAccess ) {
+ shm_error = True;
+ return(0);
+ } else
+ return(X_handler(d,e));
+}
+
+static SDL_bool have_mitshm(void)
+{
+ /* Only use shared memory on local X servers */
+ if ( (SDL_strncmp(X11_XDisplayName(NULL), ":", 1) == 0) ||
+ (SDL_strncmp(X11_XDisplayName(NULL), "unix:", 5) == 0) ) {
+ return SDL_X11_HAVE_SHM;
+ }
+ return SDL_FALSE;
+}
+
+#endif /* !NO_SHARED_MEMORY */
+
+int
+X11_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format,
+ void ** pixels, int *pitch)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+ XGCValues gcv;
+ XVisualInfo vinfo;
+
+ /* Free the old framebuffer surface */
+ X11_DestroyWindowFramebuffer(_this, window);
+
+ /* Create the graphics context for drawing */
+ gcv.graphics_exposures = False;
+ data->gc = X11_XCreateGC(display, data->xwindow, GCGraphicsExposures, &gcv);
+ if (!data->gc) {
+ return SDL_SetError("Couldn't create graphics context");
+ }
+
+ /* Find out the pixel format and depth */
+ if (X11_GetVisualInfoFromVisual(display, data->visual, &vinfo) < 0) {
+ return SDL_SetError("Couldn't get window visual information");
+ }
+
+ *format = X11_GetPixelFormatFromVisualInfo(display, &vinfo);
+ if (*format == SDL_PIXELFORMAT_UNKNOWN) {
+ return SDL_SetError("Unknown window pixel format");
+ }
+
+ /* Calculate pitch */
+ *pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
+
+ /* Create the actual image */
+#ifndef NO_SHARED_MEMORY
+ if (have_mitshm()) {
+ XShmSegmentInfo *shminfo = &data->shminfo;
+
+ shminfo->shmid = shmget(IPC_PRIVATE, window->h*(*pitch), IPC_CREAT | 0777);
+ if ( shminfo->shmid >= 0 ) {
+ shminfo->shmaddr = (char *)shmat(shminfo->shmid, 0, 0);
+ shminfo->readOnly = False;
+ if ( shminfo->shmaddr != (char *)-1 ) {
+ shm_error = False;
+ X_handler = X11_XSetErrorHandler(shm_errhandler);
+ X11_XShmAttach(display, shminfo);
+ X11_XSync(display, False);
+ X11_XSetErrorHandler(X_handler);
+ if ( shm_error )
+ shmdt(shminfo->shmaddr);
+ } else {
+ shm_error = True;
+ }
+ shmctl(shminfo->shmid, IPC_RMID, NULL);
+ } else {
+ shm_error = True;
+ }
+ if (!shm_error) {
+ data->ximage = X11_XShmCreateImage(display, data->visual,
+ vinfo.depth, ZPixmap,
+ shminfo->shmaddr, shminfo,
+ window->w, window->h);
+ if (!data->ximage) {
+ X11_XShmDetach(display, shminfo);
+ X11_XSync(display, False);
+ shmdt(shminfo->shmaddr);
+ } else {
+ /* Done! */
+ data->use_mitshm = SDL_TRUE;
+ *pixels = shminfo->shmaddr;
+ return 0;
+ }
+ }
+ }
+#endif /* not NO_SHARED_MEMORY */
+
+ *pixels = SDL_malloc(window->h*(*pitch));
+ if (*pixels == NULL) {
+ return SDL_OutOfMemory();
+ }
+
+ data->ximage = X11_XCreateImage(display, data->visual,
+ vinfo.depth, ZPixmap, 0, (char *)(*pixels),
+ window->w, window->h, 32, 0);
+ if (!data->ximage) {
+ SDL_free(*pixels);
+ return SDL_SetError("Couldn't create XImage");
+ }
+ return 0;
+}
+
+int
+X11_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects,
+ int numrects)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+ int i;
+ int x, y, w ,h;
+#ifndef NO_SHARED_MEMORY
+ if (data->use_mitshm) {
+ for (i = 0; i < numrects; ++i) {
+ x = rects[i].x;
+ y = rects[i].y;
+ w = rects[i].w;
+ h = rects[i].h;
+
+ if (w <= 0 || h <= 0 || (x + w) <= 0 || (y + h) <= 0) {
+ /* Clipped? */
+ continue;
+ }
+ if (x < 0)
+ {
+ x += w;
+ w += rects[i].x;
+ }
+ if (y < 0)
+ {
+ y += h;
+ h += rects[i].y;
+ }
+ if (x + w > window->w)
+ w = window->w - x;
+ if (y + h > window->h)
+ h = window->h - y;
+
+ X11_XShmPutImage(display, data->xwindow, data->gc, data->ximage,
+ x, y, x, y, w, h, False);
+ }
+ }
+ else
+#endif /* !NO_SHARED_MEMORY */
+ {
+ for (i = 0; i < numrects; ++i) {
+ x = rects[i].x;
+ y = rects[i].y;
+ w = rects[i].w;
+ h = rects[i].h;
+
+ if (w <= 0 || h <= 0 || (x + w) <= 0 || (y + h) <= 0) {
+ /* Clipped? */
+ continue;
+ }
+ if (x < 0)
+ {
+ x += w;
+ w += rects[i].x;
+ }
+ if (y < 0)
+ {
+ y += h;
+ h += rects[i].y;
+ }
+ if (x + w > window->w)
+ w = window->w - x;
+ if (y + h > window->h)
+ h = window->h - y;
+
+ X11_XPutImage(display, data->xwindow, data->gc, data->ximage,
+ x, y, x, y, w, h);
+ }
+ }
+
+ X11_XSync(display, False);
+
+ return 0;
+}
+
+void
+X11_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display;
+
+ if (!data) {
+ /* The window wasn't fully initialized */
+ return;
+ }
+
+ display = data->videodata->display;
+
+ if (data->ximage) {
+ XDestroyImage(data->ximage);
+
+#ifndef NO_SHARED_MEMORY
+ if (data->use_mitshm) {
+ X11_XShmDetach(display, &data->shminfo);
+ X11_XSync(display, False);
+ shmdt(data->shminfo.shmaddr);
+ data->use_mitshm = SDL_FALSE;
+ }
+#endif /* !NO_SHARED_MEMORY */
+
+ data->ximage = NULL;
+ }
+ if (data->gc) {
+ X11_XFreeGC(display, data->gc);
+ data->gc = NULL;
+ }
+}
+
+#endif /* SDL_VIDEO_DRIVER_X11 */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11framebuffer.h b/src/3rdparty/SDL2/src/video/x11/SDL_x11framebuffer.h
new file mode 100644
index 0000000..61bb0c5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11framebuffer.h
@@ -0,0 +1,31 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+
+extern int X11_CreateWindowFramebuffer(_THIS, SDL_Window * window,
+ Uint32 * format,
+ void ** pixels, int *pitch);
+extern int X11_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
+ const SDL_Rect * rects, int numrects);
+extern void X11_DestroyWindowFramebuffer(_THIS, SDL_Window * window);
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11keyboard.c b/src/3rdparty/SDL2/src/video/x11/SDL_x11keyboard.c
new file mode 100644
index 0000000..d667c7b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11keyboard.c
@@ -0,0 +1,549 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_X11
+
+#include "SDL_x11video.h"
+
+#include "../../events/SDL_keyboard_c.h"
+#include "../../events/scancodes_darwin.h"
+#include "../../events/scancodes_xfree86.h"
+
+#include <X11/keysym.h>
+#include <X11/XKBlib.h>
+
+#include "imKStoUCS.h"
+
+#ifdef X_HAVE_UTF8_STRING
+#include <locale.h>
+#endif
+
+/* *INDENT-OFF* */
+static const struct {
+ KeySym keysym;
+ SDL_Scancode scancode;
+} KeySymToSDLScancode[] = {
+ { XK_Return, SDL_SCANCODE_RETURN },
+ { XK_Escape, SDL_SCANCODE_ESCAPE },
+ { XK_BackSpace, SDL_SCANCODE_BACKSPACE },
+ { XK_Tab, SDL_SCANCODE_TAB },
+ { XK_Caps_Lock, SDL_SCANCODE_CAPSLOCK },
+ { XK_F1, SDL_SCANCODE_F1 },
+ { XK_F2, SDL_SCANCODE_F2 },
+ { XK_F3, SDL_SCANCODE_F3 },
+ { XK_F4, SDL_SCANCODE_F4 },
+ { XK_F5, SDL_SCANCODE_F5 },
+ { XK_F6, SDL_SCANCODE_F6 },
+ { XK_F7, SDL_SCANCODE_F7 },
+ { XK_F8, SDL_SCANCODE_F8 },
+ { XK_F9, SDL_SCANCODE_F9 },
+ { XK_F10, SDL_SCANCODE_F10 },
+ { XK_F11, SDL_SCANCODE_F11 },
+ { XK_F12, SDL_SCANCODE_F12 },
+ { XK_Print, SDL_SCANCODE_PRINTSCREEN },
+ { XK_Scroll_Lock, SDL_SCANCODE_SCROLLLOCK },
+ { XK_Pause, SDL_SCANCODE_PAUSE },
+ { XK_Insert, SDL_SCANCODE_INSERT },
+ { XK_Home, SDL_SCANCODE_HOME },
+ { XK_Prior, SDL_SCANCODE_PAGEUP },
+ { XK_Delete, SDL_SCANCODE_DELETE },
+ { XK_End, SDL_SCANCODE_END },
+ { XK_Next, SDL_SCANCODE_PAGEDOWN },
+ { XK_Right, SDL_SCANCODE_RIGHT },
+ { XK_Left, SDL_SCANCODE_LEFT },
+ { XK_Down, SDL_SCANCODE_DOWN },
+ { XK_Up, SDL_SCANCODE_UP },
+ { XK_Num_Lock, SDL_SCANCODE_NUMLOCKCLEAR },
+ { XK_KP_Divide, SDL_SCANCODE_KP_DIVIDE },
+ { XK_KP_Multiply, SDL_SCANCODE_KP_MULTIPLY },
+ { XK_KP_Subtract, SDL_SCANCODE_KP_MINUS },
+ { XK_KP_Add, SDL_SCANCODE_KP_PLUS },
+ { XK_KP_Enter, SDL_SCANCODE_KP_ENTER },
+ { XK_KP_Delete, SDL_SCANCODE_KP_PERIOD },
+ { XK_KP_End, SDL_SCANCODE_KP_1 },
+ { XK_KP_Down, SDL_SCANCODE_KP_2 },
+ { XK_KP_Next, SDL_SCANCODE_KP_3 },
+ { XK_KP_Left, SDL_SCANCODE_KP_4 },
+ { XK_KP_Begin, SDL_SCANCODE_KP_5 },
+ { XK_KP_Right, SDL_SCANCODE_KP_6 },
+ { XK_KP_Home, SDL_SCANCODE_KP_7 },
+ { XK_KP_Up, SDL_SCANCODE_KP_8 },
+ { XK_KP_Prior, SDL_SCANCODE_KP_9 },
+ { XK_KP_Insert, SDL_SCANCODE_KP_0 },
+ { XK_KP_Decimal, SDL_SCANCODE_KP_PERIOD },
+ { XK_KP_1, SDL_SCANCODE_KP_1 },
+ { XK_KP_2, SDL_SCANCODE_KP_2 },
+ { XK_KP_3, SDL_SCANCODE_KP_3 },
+ { XK_KP_4, SDL_SCANCODE_KP_4 },
+ { XK_KP_5, SDL_SCANCODE_KP_5 },
+ { XK_KP_6, SDL_SCANCODE_KP_6 },
+ { XK_KP_7, SDL_SCANCODE_KP_7 },
+ { XK_KP_8, SDL_SCANCODE_KP_8 },
+ { XK_KP_9, SDL_SCANCODE_KP_9 },
+ { XK_KP_0, SDL_SCANCODE_KP_0 },
+ { XK_KP_Decimal, SDL_SCANCODE_KP_PERIOD },
+ { XK_Hyper_R, SDL_SCANCODE_APPLICATION },
+ { XK_KP_Equal, SDL_SCANCODE_KP_EQUALS },
+ { XK_F13, SDL_SCANCODE_F13 },
+ { XK_F14, SDL_SCANCODE_F14 },
+ { XK_F15, SDL_SCANCODE_F15 },
+ { XK_F16, SDL_SCANCODE_F16 },
+ { XK_F17, SDL_SCANCODE_F17 },
+ { XK_F18, SDL_SCANCODE_F18 },
+ { XK_F19, SDL_SCANCODE_F19 },
+ { XK_F20, SDL_SCANCODE_F20 },
+ { XK_F21, SDL_SCANCODE_F21 },
+ { XK_F22, SDL_SCANCODE_F22 },
+ { XK_F23, SDL_SCANCODE_F23 },
+ { XK_F24, SDL_SCANCODE_F24 },
+ { XK_Execute, SDL_SCANCODE_EXECUTE },
+ { XK_Help, SDL_SCANCODE_HELP },
+ { XK_Menu, SDL_SCANCODE_MENU },
+ { XK_Select, SDL_SCANCODE_SELECT },
+ { XK_Cancel, SDL_SCANCODE_STOP },
+ { XK_Redo, SDL_SCANCODE_AGAIN },
+ { XK_Undo, SDL_SCANCODE_UNDO },
+ { XK_Find, SDL_SCANCODE_FIND },
+ { XK_KP_Separator, SDL_SCANCODE_KP_COMMA },
+ { XK_Sys_Req, SDL_SCANCODE_SYSREQ },
+ { XK_Control_L, SDL_SCANCODE_LCTRL },
+ { XK_Shift_L, SDL_SCANCODE_LSHIFT },
+ { XK_Alt_L, SDL_SCANCODE_LALT },
+ { XK_Meta_L, SDL_SCANCODE_LGUI },
+ { XK_Super_L, SDL_SCANCODE_LGUI },
+ { XK_Control_R, SDL_SCANCODE_RCTRL },
+ { XK_Shift_R, SDL_SCANCODE_RSHIFT },
+ { XK_Alt_R, SDL_SCANCODE_RALT },
+ { XK_ISO_Level3_Shift, SDL_SCANCODE_RALT },
+ { XK_Meta_R, SDL_SCANCODE_RGUI },
+ { XK_Super_R, SDL_SCANCODE_RGUI },
+ { XK_Mode_switch, SDL_SCANCODE_MODE },
+ { XK_period, SDL_SCANCODE_PERIOD },
+ { XK_comma, SDL_SCANCODE_COMMA },
+ { XK_slash, SDL_SCANCODE_SLASH },
+ { XK_backslash, SDL_SCANCODE_BACKSLASH },
+ { XK_minus, SDL_SCANCODE_MINUS },
+ { XK_equal, SDL_SCANCODE_EQUALS },
+ { XK_space, SDL_SCANCODE_SPACE },
+ { XK_grave, SDL_SCANCODE_GRAVE },
+ { XK_apostrophe, SDL_SCANCODE_APOSTROPHE },
+ { XK_bracketleft, SDL_SCANCODE_LEFTBRACKET },
+ { XK_bracketright, SDL_SCANCODE_RIGHTBRACKET },
+};
+
+static const struct
+{
+ SDL_Scancode const *table;
+ int table_size;
+} scancode_set[] = {
+ { darwin_scancode_table, SDL_arraysize(darwin_scancode_table) },
+ { xfree86_scancode_table, SDL_arraysize(xfree86_scancode_table) },
+ { xfree86_scancode_table2, SDL_arraysize(xfree86_scancode_table2) },
+ { xvnc_scancode_table, SDL_arraysize(xvnc_scancode_table) },
+};
+/* *INDENT-OFF* */
+
+/* This function only works for keyboards in US QWERTY layout */
+static SDL_Scancode
+X11_KeyCodeToSDLScancode(_THIS, KeyCode keycode)
+{
+ KeySym keysym;
+ int i;
+
+ keysym = X11_KeyCodeToSym(_this, keycode, 0);
+ if (keysym == NoSymbol) {
+ return SDL_SCANCODE_UNKNOWN;
+ }
+
+ if (keysym >= XK_a && keysym <= XK_z) {
+ return SDL_SCANCODE_A + (keysym - XK_a);
+ }
+ if (keysym >= XK_A && keysym <= XK_Z) {
+ return SDL_SCANCODE_A + (keysym - XK_A);
+ }
+
+ if (keysym == XK_0) {
+ return SDL_SCANCODE_0;
+ }
+ if (keysym >= XK_1 && keysym <= XK_9) {
+ return SDL_SCANCODE_1 + (keysym - XK_1);
+ }
+
+ for (i = 0; i < SDL_arraysize(KeySymToSDLScancode); ++i) {
+ if (keysym == KeySymToSDLScancode[i].keysym) {
+ return KeySymToSDLScancode[i].scancode;
+ }
+ }
+ return SDL_SCANCODE_UNKNOWN;
+}
+
+static Uint32
+X11_KeyCodeToUcs4(_THIS, KeyCode keycode, unsigned char group)
+{
+ KeySym keysym = X11_KeyCodeToSym(_this, keycode, group);
+
+ if (keysym == NoSymbol) {
+ return 0;
+ }
+
+ return X11_KeySymToUcs4(keysym);
+}
+
+KeySym
+X11_KeyCodeToSym(_THIS, KeyCode keycode, unsigned char group)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+ KeySym keysym;
+
+#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
+ if (data->xkb) {
+ int num_groups = XkbKeyNumGroups(data->xkb, keycode);
+ unsigned char info = XkbKeyGroupInfo(data->xkb, keycode);
+
+ if (num_groups && group >= num_groups) {
+
+ int action = XkbOutOfRangeGroupAction(info);
+
+ if (action == XkbRedirectIntoRange) {
+ if ((group = XkbOutOfRangeGroupNumber(info)) >= num_groups) {
+ group = 0;
+ }
+ } else if (action == XkbClampIntoRange) {
+ group = num_groups - 1;
+ } else {
+ group %= num_groups;
+ }
+ }
+ keysym = X11_XkbKeycodeToKeysym(data->display, keycode, group, 0);
+ } else {
+ keysym = X11_XKeycodeToKeysym(data->display, keycode, 0);
+ }
+#else
+ keysym = X11_XKeycodeToKeysym(data->display, keycode, 0);
+#endif
+
+ return keysym;
+}
+
+int
+X11_InitKeyboard(_THIS)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+ int i = 0;
+ int j = 0;
+ int min_keycode, max_keycode;
+ struct {
+ SDL_Scancode scancode;
+ KeySym keysym;
+ int value;
+ } fingerprint[] = {
+ { SDL_SCANCODE_HOME, XK_Home, 0 },
+ { SDL_SCANCODE_PAGEUP, XK_Prior, 0 },
+ { SDL_SCANCODE_UP, XK_Up, 0 },
+ { SDL_SCANCODE_LEFT, XK_Left, 0 },
+ { SDL_SCANCODE_DELETE, XK_Delete, 0 },
+ { SDL_SCANCODE_KP_ENTER, XK_KP_Enter, 0 },
+ };
+ int best_distance;
+ int best_index;
+ int distance;
+ BOOL xkb_repeat = 0;
+
+ X11_XAutoRepeatOn(data->display);
+
+#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
+ {
+ int xkb_major = XkbMajorVersion;
+ int xkb_minor = XkbMinorVersion;
+
+ if (X11_XkbQueryExtension(data->display, NULL, NULL, NULL, &xkb_major, &xkb_minor)) {
+ data->xkb = X11_XkbGetMap(data->display, XkbAllClientInfoMask, XkbUseCoreKbd);
+ }
+
+ /* This will remove KeyRelease events for held keys */
+ X11_XkbSetDetectableAutoRepeat(data->display, True, &xkb_repeat);
+ }
+#endif
+
+ /* Open a connection to the X input manager */
+#ifdef X_HAVE_UTF8_STRING
+ if (SDL_X11_HAVE_UTF8) {
+ /* Set the locale, and call XSetLocaleModifiers before XOpenIM so that
+ Compose keys will work correctly. */
+ char *prev_locale = setlocale(LC_ALL, NULL);
+ char *prev_xmods = X11_XSetLocaleModifiers(NULL);
+ const char *new_xmods = "";
+#if defined(HAVE_IBUS_IBUS_H) || defined(HAVE_FCITX_FRONTEND_H)
+ const char *env_xmods = SDL_getenv("XMODIFIERS");
+#endif
+ SDL_bool has_dbus_ime_support = SDL_FALSE;
+
+ if (prev_locale) {
+ prev_locale = SDL_strdup(prev_locale);
+ }
+
+ if (prev_xmods) {
+ prev_xmods = SDL_strdup(prev_xmods);
+ }
+
+ /* IBus resends some key events that were filtered by XFilterEvents
+ when it is used via XIM which causes issues. Prevent this by forcing
+ @im=none if XMODIFIERS contains @im=ibus. IBus can still be used via
+ the DBus implementation, which also has support for pre-editing. */
+#ifdef HAVE_IBUS_IBUS_H
+ if (env_xmods && SDL_strstr(env_xmods, "@im=ibus") != NULL) {
+ has_dbus_ime_support = SDL_TRUE;
+ }
+#endif
+#ifdef HAVE_FCITX_FRONTEND_H
+ if (env_xmods && SDL_strstr(env_xmods, "@im=fcitx") != NULL) {
+ has_dbus_ime_support = SDL_TRUE;
+ }
+#endif
+ if (has_dbus_ime_support || !xkb_repeat) {
+ new_xmods = "@im=none";
+ }
+
+ setlocale(LC_ALL, "");
+ X11_XSetLocaleModifiers(new_xmods);
+
+ data->im = X11_XOpenIM(data->display, NULL, data->classname, data->classname);
+
+ /* Reset the locale + X locale modifiers back to how they were,
+ locale first because the X locale modifiers depend on it. */
+ setlocale(LC_ALL, prev_locale);
+ X11_XSetLocaleModifiers(prev_xmods);
+
+ if (prev_locale) {
+ SDL_free(prev_locale);
+ }
+
+ if (prev_xmods) {
+ SDL_free(prev_xmods);
+ }
+ }
+#endif
+ /* Try to determine which scancodes are being used based on fingerprint */
+ best_distance = SDL_arraysize(fingerprint) + 1;
+ best_index = -1;
+ X11_XDisplayKeycodes(data->display, &min_keycode, &max_keycode);
+ for (i = 0; i < SDL_arraysize(fingerprint); ++i) {
+ fingerprint[i].value =
+ X11_XKeysymToKeycode(data->display, fingerprint[i].keysym) -
+ min_keycode;
+ }
+ for (i = 0; i < SDL_arraysize(scancode_set); ++i) {
+ /* Make sure the scancode set isn't too big */
+ if ((max_keycode - min_keycode + 1) <= scancode_set[i].table_size) {
+ continue;
+ }
+ distance = 0;
+ for (j = 0; j < SDL_arraysize(fingerprint); ++j) {
+ if (fingerprint[j].value < 0
+ || fingerprint[j].value >= scancode_set[i].table_size) {
+ distance += 1;
+ } else if (scancode_set[i].table[fingerprint[j].value] != fingerprint[j].scancode) {
+ distance += 1;
+ }
+ }
+ if (distance < best_distance) {
+ best_distance = distance;
+ best_index = i;
+ }
+ }
+ if (best_index >= 0 && best_distance <= 2) {
+#ifdef DEBUG_KEYBOARD
+ printf("Using scancode set %d, min_keycode = %d, max_keycode = %d, table_size = %d\n", best_index, min_keycode, max_keycode, scancode_set[best_index].table_size);
+#endif
+ SDL_memcpy(&data->key_layout[min_keycode], scancode_set[best_index].table,
+ sizeof(SDL_Scancode) * scancode_set[best_index].table_size);
+ } else {
+ SDL_Keycode keymap[SDL_NUM_SCANCODES];
+
+ printf
+ ("Keyboard layout unknown, please report the following to the SDL forums/mailing list (https://discourse.libsdl.org/):\n");
+
+ /* Determine key_layout - only works on US QWERTY layout */
+ SDL_GetDefaultKeymap(keymap);
+ for (i = min_keycode; i <= max_keycode; ++i) {
+ KeySym sym;
+ sym = X11_KeyCodeToSym(_this, (KeyCode) i, 0);
+ if (sym != NoSymbol) {
+ SDL_Scancode scancode;
+ printf("code = %d, sym = 0x%X (%s) ", i - min_keycode,
+ (unsigned int) sym, X11_XKeysymToString(sym));
+ scancode = X11_KeyCodeToSDLScancode(_this, i);
+ data->key_layout[i] = scancode;
+ if (scancode == SDL_SCANCODE_UNKNOWN) {
+ printf("scancode not found\n");
+ } else {
+ printf("scancode = %d (%s)\n", scancode, SDL_GetScancodeName(scancode));
+ }
+ }
+ }
+ }
+
+ X11_UpdateKeymap(_this);
+
+ SDL_SetScancodeName(SDL_SCANCODE_APPLICATION, "Menu");
+
+#ifdef SDL_USE_IME
+ SDL_IME_Init();
+#endif
+
+ return 0;
+}
+
+void
+X11_UpdateKeymap(_THIS)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+ int i;
+ SDL_Scancode scancode;
+ SDL_Keycode keymap[SDL_NUM_SCANCODES];
+ unsigned char group = 0;
+
+ SDL_GetDefaultKeymap(keymap);
+
+#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
+ if (data->xkb) {
+ XkbStateRec state;
+ X11_XkbGetUpdatedMap(data->display, XkbAllClientInfoMask, data->xkb);
+
+ if (X11_XkbGetState(data->display, XkbUseCoreKbd, &state) == Success) {
+ group = state.group;
+ }
+ }
+#endif
+
+
+ for (i = 0; i < SDL_arraysize(data->key_layout); i++) {
+ Uint32 key;
+
+ /* Make sure this is a valid scancode */
+ scancode = data->key_layout[i];
+ if (scancode == SDL_SCANCODE_UNKNOWN) {
+ continue;
+ }
+
+ /* See if there is a UCS keycode for this scancode */
+ key = X11_KeyCodeToUcs4(_this, (KeyCode)i, group);
+ if (key) {
+ keymap[scancode] = key;
+ } else {
+ SDL_Scancode keyScancode = X11_KeyCodeToSDLScancode(_this, (KeyCode)i);
+
+ switch (keyScancode) {
+ case SDL_SCANCODE_RETURN:
+ keymap[scancode] = SDLK_RETURN;
+ break;
+ case SDL_SCANCODE_ESCAPE:
+ keymap[scancode] = SDLK_ESCAPE;
+ break;
+ case SDL_SCANCODE_BACKSPACE:
+ keymap[scancode] = SDLK_BACKSPACE;
+ break;
+ case SDL_SCANCODE_TAB:
+ keymap[scancode] = SDLK_TAB;
+ break;
+ case SDL_SCANCODE_DELETE:
+ keymap[scancode] = SDLK_DELETE;
+ break;
+ default:
+ keymap[scancode] = SDL_SCANCODE_TO_KEYCODE(keyScancode);
+ break;
+ }
+ }
+ }
+ SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
+}
+
+void
+X11_QuitKeyboard(_THIS)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
+#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
+ if (data->xkb) {
+ X11_XkbFreeKeyboard(data->xkb, 0, True);
+ data->xkb = NULL;
+ }
+#endif
+
+#ifdef SDL_USE_IME
+ SDL_IME_Quit();
+#endif
+}
+
+static void
+X11_ResetXIM(_THIS)
+{
+#ifdef X_HAVE_UTF8_STRING
+ SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
+ int i;
+
+ if (videodata && videodata->windowlist) {
+ for (i = 0; i < videodata->numwindows; ++i) {
+ SDL_WindowData *data = videodata->windowlist[i];
+ if (data && data->ic) {
+ /* Clear any partially entered dead keys */
+ char *contents = X11_Xutf8ResetIC(data->ic);
+ if (contents) {
+ X11_XFree(contents);
+ }
+ }
+ }
+ }
+#endif
+}
+
+void
+X11_StartTextInput(_THIS)
+{
+ X11_ResetXIM(_this);
+}
+
+void
+X11_StopTextInput(_THIS)
+{
+ X11_ResetXIM(_this);
+#ifdef SDL_USE_IME
+ SDL_IME_Reset();
+#endif
+}
+
+void
+X11_SetTextInputRect(_THIS, SDL_Rect *rect)
+{
+ if (!rect) {
+ SDL_InvalidParamError("rect");
+ return;
+ }
+
+#ifdef SDL_USE_IME
+ SDL_IME_UpdateTextRect(rect);
+#endif
+}
+
+#endif /* SDL_VIDEO_DRIVER_X11 */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11keyboard.h b/src/3rdparty/SDL2/src/video/x11/SDL_x11keyboard.h
new file mode 100644
index 0000000..c1cc69c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11keyboard.h
@@ -0,0 +1,36 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_x11keyboard_h_
+#define SDL_x11keyboard_h_
+
+extern int X11_InitKeyboard(_THIS);
+extern void X11_UpdateKeymap(_THIS);
+extern void X11_QuitKeyboard(_THIS);
+extern void X11_StartTextInput(_THIS);
+extern void X11_StopTextInput(_THIS);
+extern void X11_SetTextInputRect(_THIS, SDL_Rect *rect);
+extern KeySym X11_KeyCodeToSym(_THIS, KeyCode, unsigned char group);
+
+#endif /* SDL_x11keyboard_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11messagebox.c b/src/3rdparty/SDL2/src/video/x11/SDL_x11messagebox.c
new file mode 100644
index 0000000..fe6ab19
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11messagebox.c
@@ -0,0 +1,853 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_X11
+
+#include "SDL.h"
+#include "SDL_x11video.h"
+#include "SDL_x11dyn.h"
+#include "SDL_assert.h"
+#include "SDL_x11messagebox.h"
+
+#include <X11/keysym.h>
+#include <locale.h>
+
+
+#define SDL_FORK_MESSAGEBOX 1
+#define SDL_SET_LOCALE 1
+
+#if SDL_FORK_MESSAGEBOX
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <errno.h>
+#endif
+
+#define MAX_BUTTONS 8 /* Maximum number of buttons supported */
+#define MAX_TEXT_LINES 32 /* Maximum number of text lines supported */
+#define MIN_BUTTON_WIDTH 64 /* Minimum button width */
+#define MIN_DIALOG_WIDTH 200 /* Minimum dialog width */
+#define MIN_DIALOG_HEIGHT 100 /* Minimum dialog height */
+
+static const char g_MessageBoxFontLatin1[] = "-*-*-medium-r-normal--0-120-*-*-p-0-iso8859-1";
+static const char g_MessageBoxFont[] = "-*-*-medium-r-normal--*-120-*-*-*-*-*-*";
+
+static const SDL_MessageBoxColor g_default_colors[ SDL_MESSAGEBOX_COLOR_MAX ] = {
+ { 56, 54, 53 }, /* SDL_MESSAGEBOX_COLOR_BACKGROUND, */
+ { 209, 207, 205 }, /* SDL_MESSAGEBOX_COLOR_TEXT, */
+ { 140, 135, 129 }, /* SDL_MESSAGEBOX_COLOR_BUTTON_BORDER, */
+ { 105, 102, 99 }, /* SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND, */
+ { 205, 202, 53 }, /* SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED, */
+};
+
+#define SDL_MAKE_RGB( _r, _g, _b ) ( ( ( Uint32 )( _r ) << 16 ) | \
+ ( ( Uint32 )( _g ) << 8 ) | \
+ ( ( Uint32 )( _b ) ) )
+
+typedef struct SDL_MessageBoxButtonDataX11 {
+ int x, y; /* Text position */
+ int length; /* Text length */
+ int text_width; /* Text width */
+
+ SDL_Rect rect; /* Rectangle for entire button */
+
+ const SDL_MessageBoxButtonData *buttondata; /* Button data from caller */
+} SDL_MessageBoxButtonDataX11;
+
+typedef struct TextLineData {
+ int width; /* Width of this text line */
+ int length; /* String length of this text line */
+ const char *text; /* Text for this line */
+} TextLineData;
+
+typedef struct SDL_MessageBoxDataX11
+{
+ Display *display;
+ int screen;
+ Window window;
+#if SDL_VIDEO_DRIVER_X11_XDBE
+ XdbeBackBuffer buf;
+ SDL_bool xdbe; /* Whether Xdbe is present or not */
+#endif
+ long event_mask;
+ Atom wm_protocols;
+ Atom wm_delete_message;
+
+ int dialog_width; /* Dialog box width. */
+ int dialog_height; /* Dialog box height. */
+
+ XFontSet font_set; /* for UTF-8 systems */
+ XFontStruct *font_struct; /* Latin1 (ASCII) fallback. */
+ int xtext, ytext; /* Text position to start drawing at. */
+ int numlines; /* Count of Text lines. */
+ int text_height; /* Height for text lines. */
+ TextLineData linedata[ MAX_TEXT_LINES ];
+
+ int *pbuttonid; /* Pointer to user return buttonid value. */
+
+ int button_press_index; /* Index into buttondata/buttonpos for button which is pressed (or -1). */
+ int mouse_over_index; /* Index into buttondata/buttonpos for button mouse is over (or -1). */
+
+ int numbuttons; /* Count of buttons. */
+ const SDL_MessageBoxButtonData *buttondata;
+ SDL_MessageBoxButtonDataX11 buttonpos[ MAX_BUTTONS ];
+
+ Uint32 color[ SDL_MESSAGEBOX_COLOR_MAX ];
+
+ const SDL_MessageBoxData *messageboxdata;
+} SDL_MessageBoxDataX11;
+
+/* Maximum helper for ints. */
+static SDL_INLINE int
+IntMax( int a, int b )
+{
+ return ( a > b ) ? a : b;
+}
+
+/* Return width and height for a string. */
+static void
+GetTextWidthHeight( SDL_MessageBoxDataX11 *data, const char *str, int nbytes, int *pwidth, int *pheight )
+{
+ if (SDL_X11_HAVE_UTF8) {
+ XRectangle overall_ink, overall_logical;
+ X11_Xutf8TextExtents(data->font_set, str, nbytes, &overall_ink, &overall_logical);
+ *pwidth = overall_logical.width;
+ *pheight = overall_logical.height;
+ } else {
+ XCharStruct text_structure;
+ int font_direction, font_ascent, font_descent;
+ X11_XTextExtents( data->font_struct, str, nbytes,
+ &font_direction, &font_ascent, &font_descent,
+ &text_structure );
+ *pwidth = text_structure.width;
+ *pheight = text_structure.ascent + text_structure.descent;
+ }
+}
+
+/* Return index of button if position x,y is contained therein. */
+static int
+GetHitButtonIndex( SDL_MessageBoxDataX11 *data, int x, int y )
+{
+ int i;
+ int numbuttons = data->numbuttons;
+ SDL_MessageBoxButtonDataX11 *buttonpos = data->buttonpos;
+
+ for ( i = 0; i < numbuttons; i++ ) {
+ SDL_Rect *rect = &buttonpos[ i ].rect;
+
+ if ( ( x >= rect->x ) &&
+ ( x <= ( rect->x + rect->w ) ) &&
+ ( y >= rect->y ) &&
+ ( y <= ( rect->y + rect->h ) ) ) {
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+/* Initialize SDL_MessageBoxData structure and Display, etc. */
+static int
+X11_MessageBoxInit( SDL_MessageBoxDataX11 *data, const SDL_MessageBoxData * messageboxdata, int * pbuttonid )
+{
+ int i;
+ int numbuttons = messageboxdata->numbuttons;
+ const SDL_MessageBoxButtonData *buttondata = messageboxdata->buttons;
+ const SDL_MessageBoxColor *colorhints;
+
+ if ( numbuttons > MAX_BUTTONS ) {
+ return SDL_SetError("Too many buttons (%d max allowed)", MAX_BUTTONS);
+ }
+
+ data->dialog_width = MIN_DIALOG_WIDTH;
+ data->dialog_height = MIN_DIALOG_HEIGHT;
+ data->messageboxdata = messageboxdata;
+ data->buttondata = buttondata;
+ data->numbuttons = numbuttons;
+ data->pbuttonid = pbuttonid;
+
+ data->display = X11_XOpenDisplay( NULL );
+ if ( !data->display ) {
+ return SDL_SetError("Couldn't open X11 display");
+ }
+
+ if (SDL_X11_HAVE_UTF8) {
+ char **missing = NULL;
+ int num_missing = 0;
+ data->font_set = X11_XCreateFontSet(data->display, g_MessageBoxFont,
+ &missing, &num_missing, NULL);
+ if ( missing != NULL ) {
+ X11_XFreeStringList(missing);
+ }
+ if ( data->font_set == NULL ) {
+ return SDL_SetError("Couldn't load font %s", g_MessageBoxFont);
+ }
+ } else {
+ data->font_struct = X11_XLoadQueryFont( data->display, g_MessageBoxFontLatin1 );
+ if ( data->font_struct == NULL ) {
+ return SDL_SetError("Couldn't load font %s", g_MessageBoxFontLatin1);
+ }
+ }
+
+ if ( messageboxdata->colorScheme ) {
+ colorhints = messageboxdata->colorScheme->colors;
+ } else {
+ colorhints = g_default_colors;
+ }
+
+ /* Convert our SDL_MessageBoxColor r,g,b values to packed RGB format. */
+ for ( i = 0; i < SDL_MESSAGEBOX_COLOR_MAX; i++ ) {
+ data->color[ i ] = SDL_MAKE_RGB( colorhints[ i ].r, colorhints[ i ].g, colorhints[ i ].b );
+ }
+
+ return 0;
+}
+
+/* Calculate and initialize text and button locations. */
+static int
+X11_MessageBoxInitPositions( SDL_MessageBoxDataX11 *data )
+{
+ int i;
+ int ybuttons;
+ int text_width_max = 0;
+ int button_text_height = 0;
+ int button_width = MIN_BUTTON_WIDTH;
+ const SDL_MessageBoxData *messageboxdata = data->messageboxdata;
+
+ /* Go over text and break linefeeds into separate lines. */
+ if ( messageboxdata->message && messageboxdata->message[ 0 ] ) {
+ const char *text = messageboxdata->message;
+ TextLineData *plinedata = data->linedata;
+
+ for ( i = 0; i < MAX_TEXT_LINES; i++, plinedata++ ) {
+ int height;
+ char *lf = SDL_strchr( ( char * )text, '\n' );
+
+ data->numlines++;
+
+ /* Only grab length up to lf if it exists and isn't the last line. */
+ plinedata->length = ( lf && ( i < MAX_TEXT_LINES - 1 ) ) ? ( lf - text ) : SDL_strlen( text );
+ plinedata->text = text;
+
+ GetTextWidthHeight( data, text, plinedata->length, &plinedata->width, &height );
+
+ /* Text and widths are the largest we've ever seen. */
+ data->text_height = IntMax( data->text_height, height );
+ text_width_max = IntMax( text_width_max, plinedata->width );
+
+ if (lf && (lf > text) && (lf[-1] == '\r')) {
+ plinedata->length--;
+ }
+
+ text += plinedata->length + 1;
+
+ /* Break if there are no more linefeeds. */
+ if ( !lf )
+ break;
+ }
+
+ /* Bump up the text height slightly. */
+ data->text_height += 2;
+ }
+
+ /* Loop through all buttons and calculate the button widths and height. */
+ for ( i = 0; i < data->numbuttons; i++ ) {
+ int height;
+
+ data->buttonpos[ i ].buttondata = &data->buttondata[ i ];
+ data->buttonpos[ i ].length = SDL_strlen( data->buttondata[ i ].text );
+
+ GetTextWidthHeight( data, data->buttondata[ i ].text, SDL_strlen( data->buttondata[ i ].text ),
+ &data->buttonpos[ i ].text_width, &height );
+
+ button_width = IntMax( button_width, data->buttonpos[ i ].text_width );
+ button_text_height = IntMax( button_text_height, height );
+ }
+
+ if ( data->numlines ) {
+ /* x,y for this line of text. */
+ data->xtext = data->text_height;
+ data->ytext = data->text_height + data->text_height;
+
+ /* Bump button y down to bottom of text. */
+ ybuttons = 3 * data->ytext / 2 + ( data->numlines - 1 ) * data->text_height;
+
+ /* Bump the dialog box width and height up if needed. */
+ data->dialog_width = IntMax( data->dialog_width, 2 * data->xtext + text_width_max );
+ data->dialog_height = IntMax( data->dialog_height, ybuttons );
+ } else {
+ /* Button y starts at height of button text. */
+ ybuttons = button_text_height;
+ }
+
+ if ( data->numbuttons ) {
+ int x, y;
+ int width_of_buttons;
+ int button_spacing = button_text_height;
+ int button_height = 2 * button_text_height;
+
+ /* Bump button width up a bit. */
+ button_width += button_text_height;
+
+ /* Get width of all buttons lined up. */
+ width_of_buttons = data->numbuttons * button_width + ( data->numbuttons - 1 ) * button_spacing;
+
+ /* Bump up dialog width and height if buttons are wider than text. */
+ data->dialog_width = IntMax( data->dialog_width, width_of_buttons + 2 * button_spacing );
+ data->dialog_height = IntMax( data->dialog_height, ybuttons + 2 * button_height );
+
+ /* Location for first button. */
+ x = ( data->dialog_width - width_of_buttons ) / 2;
+ y = ybuttons + ( data->dialog_height - ybuttons - button_height ) / 2;
+
+ for ( i = 0; i < data->numbuttons; i++ ) {
+ /* Button coordinates. */
+ data->buttonpos[ i ].rect.x = x;
+ data->buttonpos[ i ].rect.y = y;
+ data->buttonpos[ i ].rect.w = button_width;
+ data->buttonpos[ i ].rect.h = button_height;
+
+ /* Button text coordinates. */
+ data->buttonpos[ i ].x = x + ( button_width - data->buttonpos[ i ].text_width ) / 2;
+ data->buttonpos[ i ].y = y + ( button_height - button_text_height - 1 ) / 2 + button_text_height;
+
+ /* Scoot over for next button. */
+ x += button_width + button_spacing;
+ }
+ }
+
+ return 0;
+}
+
+/* Free SDL_MessageBoxData data. */
+static void
+X11_MessageBoxShutdown( SDL_MessageBoxDataX11 *data )
+{
+ if ( data->font_set != NULL ) {
+ X11_XFreeFontSet( data->display, data->font_set );
+ data->font_set = NULL;
+ }
+
+ if ( data->font_struct != NULL ) {
+ X11_XFreeFont( data->display, data->font_struct );
+ data->font_struct = NULL;
+ }
+
+#if SDL_VIDEO_DRIVER_X11_XDBE
+ if ( SDL_X11_HAVE_XDBE && data->xdbe ) {
+ X11_XdbeDeallocateBackBufferName(data->display, data->buf);
+ }
+#endif
+
+ if ( data->display ) {
+ if ( data->window != None ) {
+ X11_XWithdrawWindow( data->display, data->window, data->screen );
+ X11_XDestroyWindow( data->display, data->window );
+ data->window = None;
+ }
+
+ X11_XCloseDisplay( data->display );
+ data->display = NULL;
+ }
+}
+
+/* Create and set up our X11 dialog box indow. */
+static int
+X11_MessageBoxCreateWindow( SDL_MessageBoxDataX11 *data )
+{
+ int x, y;
+ XSizeHints *sizehints;
+ XSetWindowAttributes wnd_attr;
+ Atom _NET_WM_WINDOW_TYPE, _NET_WM_WINDOW_TYPE_DIALOG, _NET_WM_NAME;
+ Display *display = data->display;
+ SDL_WindowData *windowdata = NULL;
+ const SDL_MessageBoxData *messageboxdata = data->messageboxdata;
+ char *title_locale = NULL;
+
+ if ( messageboxdata->window ) {
+ SDL_DisplayData *displaydata =
+ (SDL_DisplayData *) SDL_GetDisplayForWindow(messageboxdata->window)->driverdata;
+ windowdata = (SDL_WindowData *)messageboxdata->window->driverdata;
+ data->screen = displaydata->screen;
+ } else {
+ data->screen = DefaultScreen( display );
+ }
+
+ data->event_mask = ExposureMask |
+ ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
+ StructureNotifyMask | FocusChangeMask | PointerMotionMask;
+ wnd_attr.event_mask = data->event_mask;
+
+ data->window = X11_XCreateWindow(
+ display, RootWindow(display, data->screen),
+ 0, 0,
+ data->dialog_width, data->dialog_height,
+ 0, CopyFromParent, InputOutput, CopyFromParent,
+ CWEventMask, &wnd_attr );
+ if ( data->window == None ) {
+ return SDL_SetError("Couldn't create X window");
+ }
+
+ if ( windowdata ) {
+ /* http://tronche.com/gui/x/icccm/sec-4.html#WM_TRANSIENT_FOR */
+ X11_XSetTransientForHint( display, data->window, windowdata->xwindow );
+ }
+
+ X11_XStoreName( display, data->window, messageboxdata->title );
+ _NET_WM_NAME = X11_XInternAtom(display, "_NET_WM_NAME", False);
+
+ title_locale = SDL_iconv_utf8_locale(messageboxdata->title);
+ if (title_locale) {
+ XTextProperty titleprop;
+ Status status = X11_XStringListToTextProperty(&title_locale, 1, &titleprop);
+ SDL_free(title_locale);
+ if (status) {
+ X11_XSetTextProperty(display, data->window, &titleprop, XA_WM_NAME);
+ X11_XFree(titleprop.value);
+ }
+ }
+
+#ifdef X_HAVE_UTF8_STRING
+ if (SDL_X11_HAVE_UTF8) {
+ XTextProperty titleprop;
+ Status status = X11_Xutf8TextListToTextProperty(display, (char **) &messageboxdata->title, 1,
+ XUTF8StringStyle, &titleprop);
+ if (status == Success) {
+ X11_XSetTextProperty(display, data->window, &titleprop,
+ _NET_WM_NAME);
+ X11_XFree(titleprop.value);
+ }
+ }
+#endif
+
+ /* Let the window manager know this is a dialog box */
+ _NET_WM_WINDOW_TYPE = X11_XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
+ _NET_WM_WINDOW_TYPE_DIALOG = X11_XInternAtom(display, "_NET_WM_WINDOW_TYPE_DIALOG", False);
+ X11_XChangeProperty(display, data->window, _NET_WM_WINDOW_TYPE, XA_ATOM, 32,
+ PropModeReplace,
+ (unsigned char *)&_NET_WM_WINDOW_TYPE_DIALOG, 1);
+
+ /* Allow the window to be deleted by the window manager */
+ data->wm_protocols = X11_XInternAtom( display, "WM_PROTOCOLS", False );
+ data->wm_delete_message = X11_XInternAtom( display, "WM_DELETE_WINDOW", False );
+ X11_XSetWMProtocols( display, data->window, &data->wm_delete_message, 1 );
+
+ if ( windowdata ) {
+ XWindowAttributes attrib;
+ Window dummy;
+
+ X11_XGetWindowAttributes(display, windowdata->xwindow, &attrib);
+ x = attrib.x + ( attrib.width - data->dialog_width ) / 2;
+ y = attrib.y + ( attrib.height - data->dialog_height ) / 3 ;
+ X11_XTranslateCoordinates(display, windowdata->xwindow, RootWindow(display, data->screen), x, y, &x, &y, &dummy);
+ } else {
+ const SDL_VideoDevice *dev = SDL_GetVideoDevice();
+ if ((dev) && (dev->displays) && (dev->num_displays > 0)) {
+ const SDL_VideoDisplay *dpy = &dev->displays[0];
+ const SDL_DisplayData *dpydata = (SDL_DisplayData *) dpy->driverdata;
+ x = dpydata->x + (( dpy->current_mode.w - data->dialog_width ) / 2);
+ y = dpydata->y + (( dpy->current_mode.h - data->dialog_height ) / 3);
+ } else { /* oh well. This will misposition on a multi-head setup. Init first next time. */
+ x = ( DisplayWidth( display, data->screen ) - data->dialog_width ) / 2;
+ y = ( DisplayHeight( display, data->screen ) - data->dialog_height ) / 3 ;
+ }
+ }
+ X11_XMoveWindow( display, data->window, x, y );
+
+ sizehints = X11_XAllocSizeHints();
+ if ( sizehints ) {
+ sizehints->flags = USPosition | USSize | PMaxSize | PMinSize;
+ sizehints->x = x;
+ sizehints->y = y;
+ sizehints->width = data->dialog_width;
+ sizehints->height = data->dialog_height;
+
+ sizehints->min_width = sizehints->max_width = data->dialog_width;
+ sizehints->min_height = sizehints->max_height = data->dialog_height;
+
+ X11_XSetWMNormalHints( display, data->window, sizehints );
+
+ X11_XFree( sizehints );
+ }
+
+ X11_XMapRaised( display, data->window );
+
+#if SDL_VIDEO_DRIVER_X11_XDBE
+ /* Initialise a back buffer for double buffering */
+ if (SDL_X11_HAVE_XDBE) {
+ int xdbe_major, xdbe_minor;
+ if (X11_XdbeQueryExtension(display, &xdbe_major, &xdbe_minor) != 0) {
+ data->xdbe = SDL_TRUE;
+ data->buf = X11_XdbeAllocateBackBufferName(display, data->window, XdbeUndefined);
+ } else {
+ data->xdbe = SDL_FALSE;
+ }
+ }
+#endif
+
+ return 0;
+}
+
+/* Draw our message box. */
+static void
+X11_MessageBoxDraw( SDL_MessageBoxDataX11 *data, GC ctx )
+{
+ int i;
+ Drawable window = data->window;
+ Display *display = data->display;
+
+#if SDL_VIDEO_DRIVER_X11_XDBE
+ if (SDL_X11_HAVE_XDBE && data->xdbe) {
+ window = data->buf;
+ X11_XdbeBeginIdiom(data->display);
+ }
+#endif
+
+ X11_XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BACKGROUND ] );
+ X11_XFillRectangle( display, window, ctx, 0, 0, data->dialog_width, data->dialog_height );
+
+ X11_XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_TEXT ] );
+ for ( i = 0; i < data->numlines; i++ ) {
+ TextLineData *plinedata = &data->linedata[ i ];
+
+ if (SDL_X11_HAVE_UTF8) {
+ X11_Xutf8DrawString( display, window, data->font_set, ctx,
+ data->xtext, data->ytext + i * data->text_height,
+ plinedata->text, plinedata->length );
+ } else {
+ X11_XDrawString( display, window, ctx,
+ data->xtext, data->ytext + i * data->text_height,
+ plinedata->text, plinedata->length );
+ }
+ }
+
+ for ( i = 0; i < data->numbuttons; i++ ) {
+ SDL_MessageBoxButtonDataX11 *buttondatax11 = &data->buttonpos[ i ];
+ const SDL_MessageBoxButtonData *buttondata = buttondatax11->buttondata;
+ int border = ( buttondata->flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT ) ? 2 : 0;
+ int offset = ( ( data->mouse_over_index == i ) && ( data->button_press_index == data->mouse_over_index ) ) ? 1 : 0;
+
+ X11_XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND ] );
+ X11_XFillRectangle( display, window, ctx,
+ buttondatax11->rect.x - border, buttondatax11->rect.y - border,
+ buttondatax11->rect.w + 2 * border, buttondatax11->rect.h + 2 * border );
+
+ X11_XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_BORDER ] );
+ X11_XDrawRectangle( display, window, ctx,
+ buttondatax11->rect.x, buttondatax11->rect.y,
+ buttondatax11->rect.w, buttondatax11->rect.h );
+
+ X11_XSetForeground( display, ctx, ( data->mouse_over_index == i ) ?
+ data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED ] :
+ data->color[ SDL_MESSAGEBOX_COLOR_TEXT ] );
+
+ if (SDL_X11_HAVE_UTF8) {
+ X11_Xutf8DrawString( display, window, data->font_set, ctx,
+ buttondatax11->x + offset,
+ buttondatax11->y + offset,
+ buttondata->text, buttondatax11->length );
+ } else {
+ X11_XDrawString( display, window, ctx,
+ buttondatax11->x + offset, buttondatax11->y + offset,
+ buttondata->text, buttondatax11->length );
+ }
+ }
+
+#if SDL_VIDEO_DRIVER_X11_XDBE
+ if (SDL_X11_HAVE_XDBE && data->xdbe) {
+ XdbeSwapInfo swap_info;
+ swap_info.swap_window = data->window;
+ swap_info.swap_action = XdbeUndefined;
+ X11_XdbeSwapBuffers(data->display, &swap_info, 1);
+ X11_XdbeEndIdiom(data->display);
+ }
+#endif
+}
+
+static Bool
+X11_MessageBoxEventTest(Display *display, XEvent *event, XPointer arg)
+{
+ const SDL_MessageBoxDataX11 *data = (const SDL_MessageBoxDataX11 *) arg;
+ return ((event->xany.display == data->display) && (event->xany.window == data->window)) ? True : False;
+}
+
+/* Loop and handle message box event messages until something kills it. */
+static int
+X11_MessageBoxLoop( SDL_MessageBoxDataX11 *data )
+{
+ GC ctx;
+ XGCValues ctx_vals;
+ SDL_bool close_dialog = SDL_FALSE;
+ SDL_bool has_focus = SDL_TRUE;
+ KeySym last_key_pressed = XK_VoidSymbol;
+ unsigned long gcflags = GCForeground | GCBackground;
+
+ SDL_zero(ctx_vals);
+ ctx_vals.foreground = data->color[ SDL_MESSAGEBOX_COLOR_BACKGROUND ];
+ ctx_vals.background = data->color[ SDL_MESSAGEBOX_COLOR_BACKGROUND ];
+
+ if (!SDL_X11_HAVE_UTF8) {
+ gcflags |= GCFont;
+ ctx_vals.font = data->font_struct->fid;
+ }
+
+ ctx = X11_XCreateGC( data->display, data->window, gcflags, &ctx_vals );
+ if ( ctx == None ) {
+ return SDL_SetError("Couldn't create graphics context");
+ }
+
+ data->button_press_index = -1; /* Reset what button is currently depressed. */
+ data->mouse_over_index = -1; /* Reset what button the mouse is over. */
+
+ while( !close_dialog ) {
+ XEvent e;
+ SDL_bool draw = SDL_TRUE;
+
+ /* can't use XWindowEvent() because it can't handle ClientMessage events. */
+ /* can't use XNextEvent() because we only want events for this window. */
+ X11_XIfEvent( data->display, &e, X11_MessageBoxEventTest, (XPointer) data );
+
+ /* If X11_XFilterEvent returns True, then some input method has filtered the
+ event, and the client should discard the event. */
+ if ( ( e.type != Expose ) && X11_XFilterEvent( &e, None ) )
+ continue;
+
+ switch( e.type ) {
+ case Expose:
+ if ( e.xexpose.count > 0 ) {
+ draw = SDL_FALSE;
+ }
+ break;
+
+ case FocusIn:
+ /* Got focus. */
+ has_focus = SDL_TRUE;
+ break;
+
+ case FocusOut:
+ /* lost focus. Reset button and mouse info. */
+ has_focus = SDL_FALSE;
+ data->button_press_index = -1;
+ data->mouse_over_index = -1;
+ break;
+
+ case MotionNotify:
+ if ( has_focus ) {
+ /* Mouse moved... */
+ const int previndex = data->mouse_over_index;
+ data->mouse_over_index = GetHitButtonIndex( data, e.xbutton.x, e.xbutton.y );
+ if (data->mouse_over_index == previndex) {
+ draw = SDL_FALSE;
+ }
+ }
+ break;
+
+ case ClientMessage:
+ if ( e.xclient.message_type == data->wm_protocols &&
+ e.xclient.format == 32 &&
+ e.xclient.data.l[ 0 ] == data->wm_delete_message ) {
+ close_dialog = SDL_TRUE;
+ }
+ break;
+
+ case KeyPress:
+ /* Store key press - we make sure in key release that we got both. */
+ last_key_pressed = X11_XLookupKeysym( &e.xkey, 0 );
+ break;
+
+ case KeyRelease: {
+ Uint32 mask = 0;
+ KeySym key = X11_XLookupKeysym( &e.xkey, 0 );
+
+ /* If this is a key release for something we didn't get the key down for, then bail. */
+ if ( key != last_key_pressed )
+ break;
+
+ if ( key == XK_Escape )
+ mask = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
+ else if ( ( key == XK_Return ) || ( key == XK_KP_Enter ) )
+ mask = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
+
+ if ( mask ) {
+ int i;
+
+ /* Look for first button with this mask set, and return it if found. */
+ for ( i = 0; i < data->numbuttons; i++ ) {
+ SDL_MessageBoxButtonDataX11 *buttondatax11 = &data->buttonpos[ i ];
+
+ if ( buttondatax11->buttondata->flags & mask ) {
+ *data->pbuttonid = buttondatax11->buttondata->buttonid;
+ close_dialog = SDL_TRUE;
+ break;
+ }
+ }
+ }
+ break;
+ }
+
+ case ButtonPress:
+ data->button_press_index = -1;
+ if ( e.xbutton.button == Button1 ) {
+ /* Find index of button they clicked on. */
+ data->button_press_index = GetHitButtonIndex( data, e.xbutton.x, e.xbutton.y );
+ }
+ break;
+
+ case ButtonRelease:
+ /* If button is released over the same button that was clicked down on, then return it. */
+ if ( ( e.xbutton.button == Button1 ) && ( data->button_press_index >= 0 ) ) {
+ int button = GetHitButtonIndex( data, e.xbutton.x, e.xbutton.y );
+
+ if ( data->button_press_index == button ) {
+ SDL_MessageBoxButtonDataX11 *buttondatax11 = &data->buttonpos[ button ];
+
+ *data->pbuttonid = buttondatax11->buttondata->buttonid;
+ close_dialog = SDL_TRUE;
+ }
+ }
+ data->button_press_index = -1;
+ break;
+ }
+
+ if ( draw ) {
+ /* Draw our dialog box. */
+ X11_MessageBoxDraw( data, ctx );
+ }
+ }
+
+ X11_XFreeGC( data->display, ctx );
+ return 0;
+}
+
+static int
+X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid)
+{
+ int ret;
+ SDL_MessageBoxDataX11 data;
+#if SDL_SET_LOCALE
+ char *origlocale;
+#endif
+
+ SDL_zero(data);
+
+ if ( !SDL_X11_LoadSymbols() )
+ return -1;
+
+#if SDL_SET_LOCALE
+ origlocale = setlocale(LC_ALL, NULL);
+ if (origlocale != NULL) {
+ origlocale = SDL_strdup(origlocale);
+ if (origlocale == NULL) {
+ return SDL_OutOfMemory();
+ }
+ setlocale(LC_ALL, "");
+ }
+#endif
+
+ /* This code could get called from multiple threads maybe? */
+ X11_XInitThreads();
+
+ /* Initialize the return buttonid value to -1 (for error or dialogbox closed). */
+ *buttonid = -1;
+
+ /* Init and display the message box. */
+ ret = X11_MessageBoxInit( &data, messageboxdata, buttonid );
+ if ( ret != -1 ) {
+ ret = X11_MessageBoxInitPositions( &data );
+ if ( ret != -1 ) {
+ ret = X11_MessageBoxCreateWindow( &data );
+ if ( ret != -1 ) {
+ ret = X11_MessageBoxLoop( &data );
+ }
+ }
+ }
+
+ X11_MessageBoxShutdown( &data );
+
+#if SDL_SET_LOCALE
+ if (origlocale) {
+ setlocale(LC_ALL, origlocale);
+ SDL_free(origlocale);
+ }
+#endif
+
+ return ret;
+}
+
+/* Display an x11 message box. */
+int
+X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
+{
+#if SDL_FORK_MESSAGEBOX
+ /* Use a child process to protect against setlocale(). Annoying. */
+ pid_t pid;
+ int fds[2];
+ int status = 0;
+
+ if (pipe(fds) == -1) {
+ return X11_ShowMessageBoxImpl(messageboxdata, buttonid); /* oh well. */
+ }
+
+ pid = fork();
+ if (pid == -1) { /* failed */
+ close(fds[0]);
+ close(fds[1]);
+ return X11_ShowMessageBoxImpl(messageboxdata, buttonid); /* oh well. */
+ } else if (pid == 0) { /* we're the child */
+ int exitcode = 0;
+ close(fds[0]);
+ status = X11_ShowMessageBoxImpl(messageboxdata, buttonid);
+ if (write(fds[1], &status, sizeof (int)) != sizeof (int))
+ exitcode = 1;
+ else if (write(fds[1], buttonid, sizeof (int)) != sizeof (int))
+ exitcode = 1;
+ close(fds[1]);
+ _exit(exitcode); /* don't run atexit() stuff, static destructors, etc. */
+ } else { /* we're the parent */
+ pid_t rc;
+ close(fds[1]);
+ do {
+ rc = waitpid(pid, &status, 0);
+ } while ((rc == -1) && (errno == EINTR));
+
+ SDL_assert(rc == pid); /* not sure what to do if this fails. */
+
+ if ((rc == -1) || (!WIFEXITED(status)) || (WEXITSTATUS(status) != 0)) {
+ return SDL_SetError("msgbox child process failed");
+ }
+
+ if (read(fds[0], &status, sizeof (int)) != sizeof (int))
+ status = -1;
+ else if (read(fds[0], buttonid, sizeof (int)) != sizeof (int))
+ status = -1;
+ close(fds[0]);
+
+ return status;
+ }
+#else
+ return X11_ShowMessageBoxImpl(messageboxdata, buttonid);
+#endif
+}
+#endif /* SDL_VIDEO_DRIVER_X11 */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11messagebox.h b/src/3rdparty/SDL2/src/video/x11/SDL_x11messagebox.h
new file mode 100644
index 0000000..cab407b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11messagebox.h
@@ -0,0 +1,28 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#if SDL_VIDEO_DRIVER_X11
+
+extern int X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
+
+#endif /* SDL_VIDEO_DRIVER_X11 */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11modes.c b/src/3rdparty/SDL2/src/video/x11/SDL_x11modes.c
new file mode 100644
index 0000000..5eafe73
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11modes.c
@@ -0,0 +1,1112 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_X11
+
+#include "SDL_hints.h"
+#include "SDL_x11video.h"
+#include "SDL_timer.h"
+#include "edid.h"
+
+/* #define X11MODES_DEBUG */
+
+/* I'm becoming more and more convinced that the application should never
+ * use XRandR, and it's the window manager's responsibility to track and
+ * manage display modes for fullscreen windows. Right now XRandR is completely
+ * broken with respect to window manager behavior on every window manager that
+ * I can find. For example, on Unity 3D if you show a fullscreen window while
+ * the resolution is changing (within ~250 ms) your window will retain the
+ * fullscreen state hint but be decorated and windowed.
+ *
+ * However, many people swear by it, so let them swear at it. :)
+*/
+/* #define XRANDR_DISABLED_BY_DEFAULT */
+
+
+static int
+get_visualinfo(Display * display, int screen, XVisualInfo * vinfo)
+{
+ const char *visual_id = SDL_getenv("SDL_VIDEO_X11_VISUALID");
+ int depth;
+
+ /* Look for an exact visual, if requested */
+ if (visual_id) {
+ XVisualInfo *vi, template;
+ int nvis;
+
+ SDL_zero(template);
+ template.visualid = SDL_strtol(visual_id, NULL, 0);
+ vi = X11_XGetVisualInfo(display, VisualIDMask, &template, &nvis);
+ if (vi) {
+ *vinfo = *vi;
+ X11_XFree(vi);
+ return 0;
+ }
+ }
+
+ depth = DefaultDepth(display, screen);
+ if ((X11_UseDirectColorVisuals() &&
+ X11_XMatchVisualInfo(display, screen, depth, DirectColor, vinfo)) ||
+ X11_XMatchVisualInfo(display, screen, depth, TrueColor, vinfo) ||
+ X11_XMatchVisualInfo(display, screen, depth, PseudoColor, vinfo) ||
+ X11_XMatchVisualInfo(display, screen, depth, StaticColor, vinfo)) {
+ return 0;
+ }
+ return -1;
+}
+
+int
+X11_GetVisualInfoFromVisual(Display * display, Visual * visual, XVisualInfo * vinfo)
+{
+ XVisualInfo *vi;
+ int nvis;
+
+ vinfo->visualid = X11_XVisualIDFromVisual(visual);
+ vi = X11_XGetVisualInfo(display, VisualIDMask, vinfo, &nvis);
+ if (vi) {
+ *vinfo = *vi;
+ X11_XFree(vi);
+ return 0;
+ }
+ return -1;
+}
+
+Uint32
+X11_GetPixelFormatFromVisualInfo(Display * display, XVisualInfo * vinfo)
+{
+ if (vinfo->class == DirectColor || vinfo->class == TrueColor) {
+ int bpp;
+ Uint32 Rmask, Gmask, Bmask, Amask;
+
+ Rmask = vinfo->visual->red_mask;
+ Gmask = vinfo->visual->green_mask;
+ Bmask = vinfo->visual->blue_mask;
+ if (vinfo->depth == 32) {
+ Amask = (0xFFFFFFFF & ~(Rmask | Gmask | Bmask));
+ } else {
+ Amask = 0;
+ }
+
+ bpp = vinfo->depth;
+ if (bpp == 24) {
+ int i, n;
+ XPixmapFormatValues *p = X11_XListPixmapFormats(display, &n);
+ if (p) {
+ for (i = 0; i < n; ++i) {
+ if (p[i].depth == 24) {
+ bpp = p[i].bits_per_pixel;
+ break;
+ }
+ }
+ X11_XFree(p);
+ }
+ }
+
+ return SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
+ }
+
+ if (vinfo->class == PseudoColor || vinfo->class == StaticColor) {
+ switch (vinfo->depth) {
+ case 8:
+ return SDL_PIXELTYPE_INDEX8;
+ case 4:
+ if (BitmapBitOrder(display) == LSBFirst) {
+ return SDL_PIXELFORMAT_INDEX4LSB;
+ } else {
+ return SDL_PIXELFORMAT_INDEX4MSB;
+ }
+ /* break; -Wunreachable-code-break */
+ case 1:
+ if (BitmapBitOrder(display) == LSBFirst) {
+ return SDL_PIXELFORMAT_INDEX1LSB;
+ } else {
+ return SDL_PIXELFORMAT_INDEX1MSB;
+ }
+ /* break; -Wunreachable-code-break */
+ }
+ }
+
+ return SDL_PIXELFORMAT_UNKNOWN;
+}
+
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+static SDL_bool
+CheckXinerama(Display * display, int *major, int *minor)
+{
+ int event_base = 0;
+ int error_base = 0;
+
+ /* Default the extension not available */
+ *major = *minor = 0;
+
+ /* Allow environment override */
+ if (!SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_XINERAMA, SDL_TRUE)) {
+#ifdef X11MODES_DEBUG
+ printf("Xinerama disabled due to hint\n");
+#endif
+ return SDL_FALSE;
+ }
+
+ if (!SDL_X11_HAVE_XINERAMA) {
+#ifdef X11MODES_DEBUG
+ printf("Xinerama support not available\n");
+#endif
+ return SDL_FALSE;
+ }
+
+ /* Query the extension version */
+ if (!X11_XineramaQueryExtension(display, &event_base, &error_base) ||
+ !X11_XineramaQueryVersion(display, major, minor) ||
+ !X11_XineramaIsActive(display)) {
+#ifdef X11MODES_DEBUG
+ printf("Xinerama not active on the display\n");
+#endif
+ return SDL_FALSE;
+ }
+#ifdef X11MODES_DEBUG
+ printf("Xinerama available at version %d.%d!\n", *major, *minor);
+#endif
+ return SDL_TRUE;
+}
+
+/* !!! FIXME: remove this later. */
+/* we have a weird bug where XineramaQueryScreens() throws an X error, so this
+ is here to help track it down (and not crash, too!). */
+static SDL_bool xinerama_triggered_error = SDL_FALSE;
+static int
+X11_XineramaFailed(Display * d, XErrorEvent * e)
+{
+ xinerama_triggered_error = SDL_TRUE;
+ fprintf(stderr, "XINERAMA X ERROR: type=%d serial=%lu err=%u req=%u minor=%u\n",
+ e->type, e->serial, (unsigned int) e->error_code,
+ (unsigned int) e->request_code, (unsigned int) e->minor_code);
+ fflush(stderr);
+ return 0;
+}
+#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
+
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+static SDL_bool
+CheckXRandR(Display * display, int *major, int *minor)
+{
+ /* Default the extension not available */
+ *major = *minor = 0;
+
+ /* Allow environment override */
+#ifdef XRANDR_DISABLED_BY_DEFAULT
+ if (!SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_XRANDR, SDL_FALSE)) {
+#ifdef X11MODES_DEBUG
+ printf("XRandR disabled by default due to window manager issues\n");
+#endif
+ return SDL_FALSE;
+ }
+#else
+ if (!SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_XRANDR, SDL_TRUE)) {
+#ifdef X11MODES_DEBUG
+ printf("XRandR disabled due to hint\n");
+#endif
+ return SDL_FALSE;
+ }
+#endif /* XRANDR_ENABLED_BY_DEFAULT */
+
+ if (!SDL_X11_HAVE_XRANDR) {
+#ifdef X11MODES_DEBUG
+ printf("XRandR support not available\n");
+#endif
+ return SDL_FALSE;
+ }
+
+ /* Query the extension version */
+ *major = 1; *minor = 3; /* we want 1.3 */
+ if (!X11_XRRQueryVersion(display, major, minor)) {
+#ifdef X11MODES_DEBUG
+ printf("XRandR not active on the display\n");
+#endif
+ *major = *minor = 0;
+ return SDL_FALSE;
+ }
+#ifdef X11MODES_DEBUG
+ printf("XRandR available at version %d.%d!\n", *major, *minor);
+#endif
+ return SDL_TRUE;
+}
+
+#define XRANDR_ROTATION_LEFT (1 << 1)
+#define XRANDR_ROTATION_RIGHT (1 << 3)
+
+static int
+CalculateXRandRRefreshRate(const XRRModeInfo *info)
+{
+ return (info->hTotal && info->vTotal) ?
+ round(((double)info->dotClock / (double)(info->hTotal * info->vTotal))) : 0;
+}
+
+static SDL_bool
+SetXRandRModeInfo(Display *display, XRRScreenResources *res, RRCrtc crtc,
+ RRMode modeID, SDL_DisplayMode *mode)
+{
+ int i;
+ for (i = 0; i < res->nmode; ++i) {
+ const XRRModeInfo *info = &res->modes[i];
+ if (info->id == modeID) {
+ XRRCrtcInfo *crtcinfo;
+ Rotation rotation = 0;
+
+ crtcinfo = X11_XRRGetCrtcInfo(display, res, crtc);
+ if (crtcinfo) {
+ rotation = crtcinfo->rotation;
+ X11_XRRFreeCrtcInfo(crtcinfo);
+ }
+
+ if (rotation & (XRANDR_ROTATION_LEFT|XRANDR_ROTATION_RIGHT)) {
+ mode->w = info->height;
+ mode->h = info->width;
+ } else {
+ mode->w = info->width;
+ mode->h = info->height;
+ }
+ mode->refresh_rate = CalculateXRandRRefreshRate(info);
+ ((SDL_DisplayModeData*)mode->driverdata)->xrandr_mode = modeID;
+#ifdef X11MODES_DEBUG
+ printf("XRandR mode %d: %dx%d@%dHz\n", (int) modeID, mode->w, mode->h, mode->refresh_rate);
+#endif
+ return SDL_TRUE;
+ }
+ }
+ return SDL_FALSE;
+}
+
+static void
+SetXRandRDisplayName(Display *dpy, Atom EDID, char *name, const size_t namelen, RROutput output, const unsigned long widthmm, const unsigned long heightmm)
+{
+ /* See if we can get the EDID data for the real monitor name */
+ int inches;
+ int nprop;
+ Atom *props = X11_XRRListOutputProperties(dpy, output, &nprop);
+ int i;
+
+ for (i = 0; i < nprop; ++i) {
+ unsigned char *prop;
+ int actual_format;
+ unsigned long nitems, bytes_after;
+ Atom actual_type;
+
+ if (props[i] == EDID) {
+ if (X11_XRRGetOutputProperty(dpy, output, props[i], 0, 100, False,
+ False, AnyPropertyType, &actual_type,
+ &actual_format, &nitems, &bytes_after,
+ &prop) == Success) {
+ MonitorInfo *info = decode_edid(prop);
+ if (info) {
+#ifdef X11MODES_DEBUG
+ printf("Found EDID data for %s\n", name);
+ dump_monitor_info(info);
+#endif
+ SDL_strlcpy(name, info->dsc_product_name, namelen);
+ free(info);
+ }
+ X11_XFree(prop);
+ }
+ break;
+ }
+ }
+
+ if (props) {
+ X11_XFree(props);
+ }
+
+ inches = (int)((SDL_sqrtf(widthmm * widthmm + heightmm * heightmm) / 25.4f) + 0.5f);
+ if (*name && inches) {
+ const size_t len = SDL_strlen(name);
+ SDL_snprintf(&name[len], namelen-len, " %d\"", inches);
+ }
+
+#ifdef X11MODES_DEBUG
+ printf("Display name: %s\n", name);
+#endif
+}
+
+
+static int
+X11_InitModes_XRandR(_THIS)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+ Display *dpy = data->display;
+ const int screencount = ScreenCount(dpy);
+ const int default_screen = DefaultScreen(dpy);
+ RROutput primary = X11_XRRGetOutputPrimary(dpy, RootWindow(dpy, default_screen));
+ Atom EDID = X11_XInternAtom(dpy, "EDID", False);
+ XRRScreenResources *res = NULL;
+ Uint32 pixelformat;
+ XVisualInfo vinfo;
+ XPixmapFormatValues *pixmapformats;
+ int looking_for_primary;
+ int scanline_pad;
+ int output;
+ int screen, i, n;
+
+ for (looking_for_primary = 1; looking_for_primary >= 0; looking_for_primary--) {
+ for (screen = 0; screen < screencount; screen++) {
+
+ /* we want the primary output first, and then skipped later. */
+ if (looking_for_primary && (screen != default_screen)) {
+ continue;
+ }
+
+ if (get_visualinfo(dpy, screen, &vinfo) < 0) {
+ continue; /* uh, skip this screen? */
+ }
+
+ pixelformat = X11_GetPixelFormatFromVisualInfo(dpy, &vinfo);
+ if (SDL_ISPIXELFORMAT_INDEXED(pixelformat)) {
+ continue; /* Palettized video modes are no longer supported */
+ }
+
+ scanline_pad = SDL_BYTESPERPIXEL(pixelformat) * 8;
+ pixmapformats = X11_XListPixmapFormats(dpy, &n);
+ if (pixmapformats) {
+ for (i = 0; i < n; ++i) {
+ if (pixmapformats[i].depth == vinfo.depth) {
+ scanline_pad = pixmapformats[i].scanline_pad;
+ break;
+ }
+ }
+ X11_XFree(pixmapformats);
+ }
+
+ res = X11_XRRGetScreenResourcesCurrent(dpy, RootWindow(dpy, screen));
+ if (!res || res->noutput == 0) {
+ if (res) {
+ X11_XRRFreeScreenResources(res);
+ }
+
+ res = X11_XRRGetScreenResources(dpy, RootWindow(dpy, screen));
+ if (!res) {
+ continue;
+ }
+ }
+
+ for (output = 0; output < res->noutput; output++) {
+ XRROutputInfo *output_info;
+ int display_x, display_y;
+ unsigned long display_mm_width, display_mm_height;
+ SDL_DisplayData *displaydata;
+ char display_name[128];
+ SDL_DisplayMode mode;
+ SDL_DisplayModeData *modedata;
+ SDL_VideoDisplay display;
+ RRMode modeID;
+ RRCrtc output_crtc;
+ XRRCrtcInfo *crtc;
+
+ /* The primary output _should_ always be sorted first, but just in case... */
+ if ((looking_for_primary && (res->outputs[output] != primary)) ||
+ (!looking_for_primary && (screen == default_screen) && (res->outputs[output] == primary))) {
+ continue;
+ }
+
+ output_info = X11_XRRGetOutputInfo(dpy, res, res->outputs[output]);
+ if (!output_info || !output_info->crtc || output_info->connection == RR_Disconnected) {
+ X11_XRRFreeOutputInfo(output_info);
+ continue;
+ }
+
+ SDL_strlcpy(display_name, output_info->name, sizeof(display_name));
+ display_mm_width = output_info->mm_width;
+ display_mm_height = output_info->mm_height;
+ output_crtc = output_info->crtc;
+ X11_XRRFreeOutputInfo(output_info);
+
+ crtc = X11_XRRGetCrtcInfo(dpy, res, output_crtc);
+ if (!crtc) {
+ continue;
+ }
+
+ SDL_zero(mode);
+ modeID = crtc->mode;
+ mode.w = crtc->width;
+ mode.h = crtc->height;
+ mode.format = pixelformat;
+
+ display_x = crtc->x;
+ display_y = crtc->y;
+
+ X11_XRRFreeCrtcInfo(crtc);
+
+ displaydata = (SDL_DisplayData *) SDL_calloc(1, sizeof(*displaydata));
+ if (!displaydata) {
+ return SDL_OutOfMemory();
+ }
+
+ modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
+ if (!modedata) {
+ SDL_free(displaydata);
+ return SDL_OutOfMemory();
+ }
+ modedata->xrandr_mode = modeID;
+ mode.driverdata = modedata;
+
+ displaydata->screen = screen;
+ displaydata->visual = vinfo.visual;
+ displaydata->depth = vinfo.depth;
+ displaydata->hdpi = display_mm_width ? (((float) mode.w) * 25.4f / display_mm_width) : 0.0f;
+ displaydata->vdpi = display_mm_height ? (((float) mode.h) * 25.4f / display_mm_height) : 0.0f;
+ displaydata->ddpi = SDL_ComputeDiagonalDPI(mode.w, mode.h, ((float) display_mm_width) / 25.4f,((float) display_mm_height) / 25.4f);
+ displaydata->scanline_pad = scanline_pad;
+ displaydata->x = display_x;
+ displaydata->y = display_y;
+ displaydata->use_xrandr = 1;
+ displaydata->xrandr_output = res->outputs[output];
+
+ SetXRandRModeInfo(dpy, res, output_crtc, modeID, &mode);
+ SetXRandRDisplayName(dpy, EDID, display_name, sizeof (display_name), res->outputs[output], display_mm_width, display_mm_height);
+
+ SDL_zero(display);
+ if (*display_name) {
+ display.name = display_name;
+ }
+ display.desktop_mode = mode;
+ display.current_mode = mode;
+ display.driverdata = displaydata;
+ SDL_AddVideoDisplay(&display);
+ }
+
+ X11_XRRFreeScreenResources(res);
+ }
+ }
+
+ if (_this->num_displays == 0) {
+ return SDL_SetError("No available displays");
+ }
+
+ return 0;
+}
+#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
+
+#if SDL_VIDEO_DRIVER_X11_XVIDMODE
+static SDL_bool
+CheckVidMode(Display * display, int *major, int *minor)
+{
+ int vm_event, vm_error = -1;
+ /* Default the extension not available */
+ *major = *minor = 0;
+
+ /* Allow environment override */
+ if (!SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_XVIDMODE, SDL_TRUE)) {
+#ifdef X11MODES_DEBUG
+ printf("XVidMode disabled due to hint\n");
+#endif
+ return SDL_FALSE;
+ }
+
+ if (!SDL_X11_HAVE_XVIDMODE) {
+#ifdef X11MODES_DEBUG
+ printf("XVidMode support not available\n");
+#endif
+ return SDL_FALSE;
+ }
+
+ /* Query the extension version */
+ if (!X11_XF86VidModeQueryExtension(display, &vm_event, &vm_error)
+ || !X11_XF86VidModeQueryVersion(display, major, minor)) {
+#ifdef X11MODES_DEBUG
+ printf("XVidMode not active on the display\n");
+#endif
+ return SDL_FALSE;
+ }
+#ifdef X11MODES_DEBUG
+ printf("XVidMode available at version %d.%d!\n", *major, *minor);
+#endif
+ return SDL_TRUE;
+}
+
+static
+Bool XF86VidModeGetModeInfo(Display * dpy, int scr,
+ XF86VidModeModeInfo* info)
+{
+ Bool retval;
+ int dotclock;
+ XF86VidModeModeLine l;
+ SDL_zerop(info);
+ SDL_zero(l);
+ retval = X11_XF86VidModeGetModeLine(dpy, scr, &dotclock, &l);
+ info->dotclock = dotclock;
+ info->hdisplay = l.hdisplay;
+ info->hsyncstart = l.hsyncstart;
+ info->hsyncend = l.hsyncend;
+ info->htotal = l.htotal;
+ info->hskew = l.hskew;
+ info->vdisplay = l.vdisplay;
+ info->vsyncstart = l.vsyncstart;
+ info->vsyncend = l.vsyncend;
+ info->vtotal = l.vtotal;
+ info->flags = l.flags;
+ info->privsize = l.privsize;
+ info->private = l.private;
+ return retval;
+}
+
+static int
+CalculateXVidModeRefreshRate(const XF86VidModeModeInfo * info)
+{
+ return (info->htotal
+ && info->vtotal) ? (1000 * info->dotclock / (info->htotal *
+ info->vtotal)) : 0;
+}
+
+static SDL_bool
+SetXVidModeModeInfo(const XF86VidModeModeInfo *info, SDL_DisplayMode *mode)
+{
+ mode->w = info->hdisplay;
+ mode->h = info->vdisplay;
+ mode->refresh_rate = CalculateXVidModeRefreshRate(info);
+ ((SDL_DisplayModeData*)mode->driverdata)->vm_mode = *info;
+ return SDL_TRUE;
+}
+#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
+
+int
+X11_InitModes(_THIS)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+ int snum, screen, screencount = 0;
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+ int xinerama_major, xinerama_minor;
+ int use_xinerama = 0;
+ XineramaScreenInfo *xinerama = NULL;
+#endif
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+ int xrandr_major, xrandr_minor;
+#endif
+#if SDL_VIDEO_DRIVER_X11_XVIDMODE
+ int vm_major, vm_minor;
+ int use_vidmode = 0;
+#endif
+
+/* XRandR is the One True Modern Way to do this on X11. If it's enabled and
+ available, don't even look at other ways of doing things. */
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+ /* require at least XRandR v1.3 */
+ if (CheckXRandR(data->display, &xrandr_major, &xrandr_minor) &&
+ (xrandr_major >= 2 || (xrandr_major == 1 && xrandr_minor >= 3))) {
+ if (X11_InitModes_XRandR(_this) == 0)
+ return 0;
+ }
+#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
+
+/* !!! FIXME: eventually remove support for Xinerama and XVidMode (everything below here). */
+
+ /* This is a workaround for some apps (UnrealEngine4, for example) until
+ we sort out the ramifications of removing XVidMode support outright.
+ This block should be removed with the XVidMode support. */
+ {
+ if (SDL_GetHintBoolean("SDL_VIDEO_X11_REQUIRE_XRANDR", SDL_FALSE)) {
+ #if SDL_VIDEO_DRIVER_X11_XRANDR
+ return SDL_SetError("XRandR support is required but not available");
+ #else
+ return SDL_SetError("XRandR support is required but not built into SDL!");
+ #endif
+ }
+ }
+
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+ /* Query Xinerama extention
+ * NOTE: This works with Nvidia Twinview correctly, but you need version 302.17 (released on June 2012)
+ * or newer of the Nvidia binary drivers
+ */
+ if (CheckXinerama(data->display, &xinerama_major, &xinerama_minor)) {
+ int (*handler) (Display *, XErrorEvent *);
+ X11_XSync(data->display, False);
+ handler = X11_XSetErrorHandler(X11_XineramaFailed);
+ xinerama = X11_XineramaQueryScreens(data->display, &screencount);
+ X11_XSync(data->display, False);
+ X11_XSetErrorHandler(handler);
+ if (xinerama_triggered_error) {
+ xinerama = 0;
+ }
+ if (xinerama) {
+ use_xinerama = xinerama_major * 100 + xinerama_minor;
+ }
+ }
+ if (!xinerama) {
+ screencount = ScreenCount(data->display);
+ }
+#else
+ screencount = ScreenCount(data->display);
+#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
+
+#if SDL_VIDEO_DRIVER_X11_XVIDMODE
+ if (CheckVidMode(data->display, &vm_major, &vm_minor)) {
+ use_vidmode = vm_major * 100 + vm_minor;
+ }
+#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
+
+ for (snum = 0; snum < screencount; ++snum) {
+ XVisualInfo vinfo;
+ SDL_VideoDisplay display;
+ SDL_DisplayData *displaydata;
+ SDL_DisplayMode mode;
+ SDL_DisplayModeData *modedata;
+ XPixmapFormatValues *pixmapFormats;
+ char display_name[128];
+ int i, n;
+
+ /* Re-order screens to always put default screen first */
+ if (snum == 0) {
+ screen = DefaultScreen(data->display);
+ } else if (snum == DefaultScreen(data->display)) {
+ screen = 0;
+ } else {
+ screen = snum;
+ }
+
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+ if (xinerama) {
+ if (get_visualinfo(data->display, 0, &vinfo) < 0) {
+ continue;
+ }
+ } else {
+ if (get_visualinfo(data->display, screen, &vinfo) < 0) {
+ continue;
+ }
+ }
+#else
+ if (get_visualinfo(data->display, screen, &vinfo) < 0) {
+ continue;
+ }
+#endif
+
+ displaydata = (SDL_DisplayData *) SDL_calloc(1, sizeof(*displaydata));
+ if (!displaydata) {
+ continue;
+ }
+ display_name[0] = '\0';
+
+ mode.format = X11_GetPixelFormatFromVisualInfo(data->display, &vinfo);
+ if (SDL_ISPIXELFORMAT_INDEXED(mode.format)) {
+ /* We don't support palettized modes now */
+ SDL_free(displaydata);
+ continue;
+ }
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+ if (xinerama) {
+ mode.w = xinerama[screen].width;
+ mode.h = xinerama[screen].height;
+ } else {
+ mode.w = DisplayWidth(data->display, screen);
+ mode.h = DisplayHeight(data->display, screen);
+ }
+#else
+ mode.w = DisplayWidth(data->display, screen);
+ mode.h = DisplayHeight(data->display, screen);
+#endif
+ mode.refresh_rate = 0;
+
+ modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
+ if (!modedata) {
+ SDL_free(displaydata);
+ continue;
+ }
+ mode.driverdata = modedata;
+
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+ /* Most of SDL's calls to X11 are unwaware of Xinerama, and to X11 standard calls, when Xinerama is active,
+ * there's only one screen available. So we force the screen number to zero and
+ * let Xinerama specific code handle specific functionality using displaydata->xinerama_info
+ */
+ if (use_xinerama) {
+ displaydata->screen = 0;
+ displaydata->use_xinerama = use_xinerama;
+ displaydata->xinerama_info = xinerama[screen];
+ displaydata->xinerama_screen = screen;
+ }
+ else displaydata->screen = screen;
+#else
+ displaydata->screen = screen;
+#endif
+ displaydata->visual = vinfo.visual;
+ displaydata->depth = vinfo.depth;
+
+ /* We use the displaydata screen index here so that this works
+ for both the Xinerama case, where we get the overall DPI,
+ and the regular X11 screen info case. */
+ displaydata->hdpi = (float)DisplayWidth(data->display, displaydata->screen) * 25.4f /
+ DisplayWidthMM(data->display, displaydata->screen);
+ displaydata->vdpi = (float)DisplayHeight(data->display, displaydata->screen) * 25.4f /
+ DisplayHeightMM(data->display, displaydata->screen);
+ displaydata->ddpi = SDL_ComputeDiagonalDPI(DisplayWidth(data->display, displaydata->screen),
+ DisplayHeight(data->display, displaydata->screen),
+ (float)DisplayWidthMM(data->display, displaydata->screen) / 25.4f,
+ (float)DisplayHeightMM(data->display, displaydata->screen) / 25.4f);
+
+ displaydata->scanline_pad = SDL_BYTESPERPIXEL(mode.format) * 8;
+ pixmapFormats = X11_XListPixmapFormats(data->display, &n);
+ if (pixmapFormats) {
+ for (i = 0; i < n; ++i) {
+ if (pixmapFormats[i].depth == displaydata->depth) {
+ displaydata->scanline_pad = pixmapFormats[i].scanline_pad;
+ break;
+ }
+ }
+ X11_XFree(pixmapFormats);
+ }
+
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+ if (use_xinerama) {
+ displaydata->x = xinerama[screen].x_org;
+ displaydata->y = xinerama[screen].y_org;
+ }
+ else
+#endif
+ {
+ displaydata->x = 0;
+ displaydata->y = 0;
+ }
+
+#if SDL_VIDEO_DRIVER_X11_XVIDMODE
+ if (!displaydata->use_xrandr &&
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+ /* XVidMode only works on the screen at the origin */
+ (!displaydata->use_xinerama ||
+ (displaydata->x == 0 && displaydata->y == 0)) &&
+#endif
+ use_vidmode) {
+ displaydata->use_vidmode = use_vidmode;
+ if (displaydata->use_xinerama) {
+ displaydata->vidmode_screen = 0;
+ } else {
+ displaydata->vidmode_screen = screen;
+ }
+ XF86VidModeGetModeInfo(data->display, displaydata->vidmode_screen, &modedata->vm_mode);
+ }
+#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
+
+ SDL_zero(display);
+ if (*display_name) {
+ display.name = display_name;
+ }
+ display.desktop_mode = mode;
+ display.current_mode = mode;
+ display.driverdata = displaydata;
+ SDL_AddVideoDisplay(&display);
+ }
+
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+ if (xinerama) X11_XFree(xinerama);
+#endif
+
+ if (_this->num_displays == 0) {
+ return SDL_SetError("No available displays");
+ }
+ return 0;
+}
+
+void
+X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display)
+{
+ Display *display = ((SDL_VideoData *) _this->driverdata)->display;
+ SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
+#if SDL_VIDEO_DRIVER_X11_XVIDMODE
+ int nmodes;
+ XF86VidModeModeInfo ** modes;
+#endif
+ SDL_DisplayMode mode;
+
+ /* Unfortunately X11 requires the window to be created with the correct
+ * visual and depth ahead of time, but the SDL API allows you to create
+ * a window before setting the fullscreen display mode. This means that
+ * we have to use the same format for all windows and all display modes.
+ * (or support recreating the window with a new visual behind the scenes)
+ */
+ mode.format = sdl_display->current_mode.format;
+ mode.driverdata = NULL;
+
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+ if (data->use_xinerama) {
+ int screen_w;
+ int screen_h;
+
+ screen_w = DisplayWidth(display, data->screen);
+ screen_h = DisplayHeight(display, data->screen);
+
+ if (data->use_vidmode && !data->xinerama_info.x_org && !data->xinerama_info.y_org &&
+ (screen_w > data->xinerama_info.width || screen_h > data->xinerama_info.height)) {
+ SDL_DisplayModeData *modedata;
+ /* Add the full (both screens combined) xinerama mode only on the display that starts at 0,0
+ * if we're using vidmode.
+ */
+ mode.w = screen_w;
+ mode.h = screen_h;
+ mode.refresh_rate = 0;
+ modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
+ if (modedata) {
+ *modedata = *(SDL_DisplayModeData *)sdl_display->desktop_mode.driverdata;
+ }
+ mode.driverdata = modedata;
+ if (!SDL_AddDisplayMode(sdl_display, &mode)) {
+ SDL_free(modedata);
+ }
+ }
+ else if (!data->use_xrandr)
+ {
+ SDL_DisplayModeData *modedata;
+ /* Add the current mode of each monitor otherwise if we can't get them from xrandr */
+ mode.w = data->xinerama_info.width;
+ mode.h = data->xinerama_info.height;
+ mode.refresh_rate = 0;
+ modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
+ if (modedata) {
+ *modedata = *(SDL_DisplayModeData *)sdl_display->desktop_mode.driverdata;
+ }
+ mode.driverdata = modedata;
+ if (!SDL_AddDisplayMode(sdl_display, &mode)) {
+ SDL_free(modedata);
+ }
+ }
+
+ }
+#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
+
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+ if (data->use_xrandr) {
+ XRRScreenResources *res;
+
+ res = X11_XRRGetScreenResources (display, RootWindow(display, data->screen));
+ if (res) {
+ SDL_DisplayModeData *modedata;
+ XRROutputInfo *output_info;
+ int i;
+
+ output_info = X11_XRRGetOutputInfo(display, res, data->xrandr_output);
+ if (output_info && output_info->connection != RR_Disconnected) {
+ for (i = 0; i < output_info->nmode; ++i) {
+ modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
+ if (!modedata) {
+ continue;
+ }
+ mode.driverdata = modedata;
+
+ if (!SetXRandRModeInfo(display, res, output_info->crtc, output_info->modes[i], &mode) ||
+ !SDL_AddDisplayMode(sdl_display, &mode)) {
+ SDL_free(modedata);
+ }
+ }
+ }
+ X11_XRRFreeOutputInfo(output_info);
+ X11_XRRFreeScreenResources(res);
+ }
+ return;
+ }
+#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
+
+#if SDL_VIDEO_DRIVER_X11_XVIDMODE
+ if (data->use_vidmode &&
+ X11_XF86VidModeGetAllModeLines(display, data->vidmode_screen, &nmodes, &modes)) {
+ int i;
+ SDL_DisplayModeData *modedata;
+
+#ifdef X11MODES_DEBUG
+ printf("VidMode modes: (unsorted)\n");
+ for (i = 0; i < nmodes; ++i) {
+ printf("Mode %d: %d x %d @ %d, flags: 0x%x\n", i,
+ modes[i]->hdisplay, modes[i]->vdisplay,
+ CalculateXVidModeRefreshRate(modes[i]), modes[i]->flags);
+ }
+#endif
+ for (i = 0; i < nmodes; ++i) {
+ modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
+ if (!modedata) {
+ continue;
+ }
+ mode.driverdata = modedata;
+
+ if (!SetXVidModeModeInfo(modes[i], &mode) || !SDL_AddDisplayMode(sdl_display, &mode)) {
+ SDL_free(modedata);
+ }
+ }
+ X11_XFree(modes);
+ return;
+ }
+#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
+
+ if (!data->use_xrandr && !data->use_vidmode) {
+ SDL_DisplayModeData *modedata;
+ /* Add the desktop mode */
+ mode = sdl_display->desktop_mode;
+ modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
+ if (modedata) {
+ *modedata = *(SDL_DisplayModeData *)sdl_display->desktop_mode.driverdata;
+ }
+ mode.driverdata = modedata;
+ if (!SDL_AddDisplayMode(sdl_display, &mode)) {
+ SDL_free(modedata);
+ }
+ }
+}
+
+int
+X11_SetDisplayMode(_THIS, SDL_VideoDisplay * sdl_display, SDL_DisplayMode * mode)
+{
+ SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
+ Display *display = viddata->display;
+ SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
+ SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)mode->driverdata;
+
+ viddata->last_mode_change_deadline = SDL_GetTicks() + (PENDING_FOCUS_TIME * 2);
+
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+ if (data->use_xrandr) {
+ XRRScreenResources *res;
+ XRROutputInfo *output_info;
+ XRRCrtcInfo *crtc;
+ Status status;
+
+ res = X11_XRRGetScreenResources (display, RootWindow(display, data->screen));
+ if (!res) {
+ return SDL_SetError("Couldn't get XRandR screen resources");
+ }
+
+ output_info = X11_XRRGetOutputInfo(display, res, data->xrandr_output);
+ if (!output_info || output_info->connection == RR_Disconnected) {
+ X11_XRRFreeScreenResources(res);
+ return SDL_SetError("Couldn't get XRandR output info");
+ }
+
+ crtc = X11_XRRGetCrtcInfo(display, res, output_info->crtc);
+ if (!crtc) {
+ X11_XRRFreeOutputInfo(output_info);
+ X11_XRRFreeScreenResources(res);
+ return SDL_SetError("Couldn't get XRandR crtc info");
+ }
+
+ status = X11_XRRSetCrtcConfig (display, res, output_info->crtc, CurrentTime,
+ crtc->x, crtc->y, modedata->xrandr_mode, crtc->rotation,
+ &data->xrandr_output, 1);
+
+ X11_XRRFreeCrtcInfo(crtc);
+ X11_XRRFreeOutputInfo(output_info);
+ X11_XRRFreeScreenResources(res);
+
+ if (status != Success) {
+ return SDL_SetError("X11_XRRSetCrtcConfig failed");
+ }
+ }
+#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
+
+#if SDL_VIDEO_DRIVER_X11_XVIDMODE
+ if (data->use_vidmode) {
+ X11_XF86VidModeSwitchToMode(display, data->vidmode_screen, &modedata->vm_mode);
+ }
+#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
+
+ return 0;
+}
+
+void
+X11_QuitModes(_THIS)
+{
+}
+
+int
+X11_GetDisplayBounds(_THIS, SDL_VideoDisplay * sdl_display, SDL_Rect * rect)
+{
+ SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
+
+ rect->x = data->x;
+ rect->y = data->y;
+ rect->w = sdl_display->current_mode.w;
+ rect->h = sdl_display->current_mode.h;
+
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+ /* Get the real current bounds of the display */
+ if (data->use_xinerama) {
+ Display *display = ((SDL_VideoData *) _this->driverdata)->display;
+ int screencount;
+ XineramaScreenInfo *xinerama = X11_XineramaQueryScreens(display, &screencount);
+ if (xinerama) {
+ rect->x = xinerama[data->xinerama_screen].x_org;
+ rect->y = xinerama[data->xinerama_screen].y_org;
+ X11_XFree(xinerama);
+ }
+ }
+#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
+ return 0;
+}
+
+int
+X11_GetDisplayDPI(_THIS, SDL_VideoDisplay * sdl_display, float * ddpi, float * hdpi, float * vdpi)
+{
+ SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
+
+ if (ddpi) {
+ *ddpi = data->ddpi;
+ }
+ if (hdpi) {
+ *hdpi = data->hdpi;
+ }
+ if (vdpi) {
+ *vdpi = data->vdpi;
+ }
+
+ return data->ddpi != 0.0f ? 0 : SDL_SetError("Couldn't get DPI");
+}
+
+int
+X11_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * sdl_display, SDL_Rect * rect)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+ Display *display = data->display;
+ Atom _NET_WORKAREA;
+ int status, real_format;
+ int retval = -1;
+ Atom real_type;
+ unsigned long items_read = 0, items_left = 0;
+ unsigned char *propdata = NULL;
+
+ if (X11_GetDisplayBounds(_this, sdl_display, rect) < 0) {
+ return -1;
+ }
+
+ _NET_WORKAREA = X11_XInternAtom(display, "_NET_WORKAREA", False);
+ status = X11_XGetWindowProperty(display, DefaultRootWindow(display),
+ _NET_WORKAREA, 0L, 4L, False, XA_CARDINAL,
+ &real_type, &real_format, &items_read,
+ &items_left, &propdata);
+ if ((status == Success) && (items_read >= 4)) {
+ const long *p = (long*) propdata;
+ const SDL_Rect usable = { (int)p[0], (int)p[1], (int)p[2], (int)p[3] };
+ retval = 0;
+ if (!SDL_IntersectRect(rect, &usable, rect)) {
+ SDL_zerop(rect);
+ }
+ }
+
+ if (propdata) {
+ X11_XFree(propdata);
+ }
+
+ return retval;
+}
+
+#endif /* SDL_VIDEO_DRIVER_X11 */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11modes.h b/src/3rdparty/SDL2/src/video/x11/SDL_x11modes.h
new file mode 100644
index 0000000..7d3ff3e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11modes.h
@@ -0,0 +1,85 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_x11modes_h_
+#define SDL_x11modes_h_
+
+typedef struct
+{
+ int screen;
+ Visual *visual;
+ int depth;
+ int scanline_pad;
+ int x;
+ int y;
+ float ddpi;
+ float hdpi;
+ float vdpi;
+
+ int use_xinerama;
+ int use_xrandr;
+ int use_vidmode;
+
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+ XineramaScreenInfo xinerama_info;
+ int xinerama_screen;
+#endif
+
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+ RROutput xrandr_output;
+#endif
+
+#if SDL_VIDEO_DRIVER_X11_XVIDMODE
+ int vidmode_screen;
+#endif
+
+} SDL_DisplayData;
+
+typedef struct
+{
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+ RRMode xrandr_mode;
+#endif
+
+#if SDL_VIDEO_DRIVER_X11_XVIDMODE
+ XF86VidModeModeInfo vm_mode;
+#endif
+
+} SDL_DisplayModeData;
+
+extern int X11_InitModes(_THIS);
+extern void X11_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
+extern int X11_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
+extern void X11_QuitModes(_THIS);
+
+/* Some utility functions for working with visuals */
+extern int X11_GetVisualInfoFromVisual(Display * display, Visual * visual,
+ XVisualInfo * vinfo);
+extern Uint32 X11_GetPixelFormatFromVisualInfo(Display * display,
+ XVisualInfo * vinfo);
+extern int X11_GetDisplayBounds(_THIS, SDL_VideoDisplay * sdl_display, SDL_Rect * rect);
+extern int X11_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * sdl_display, SDL_Rect * rect);
+extern int X11_GetDisplayDPI(_THIS, SDL_VideoDisplay * sdl_display, float * ddpi, float * hdpi, float * vdpi);
+
+#endif /* SDL_x11modes_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11mouse.c b/src/3rdparty/SDL2/src/video/x11/SDL_x11mouse.c
new file mode 100644
index 0000000..3b98726
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11mouse.c
@@ -0,0 +1,448 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_X11
+
+#include <X11/cursorfont.h>
+#include "SDL_assert.h"
+#include "SDL_x11video.h"
+#include "SDL_x11mouse.h"
+#include "SDL_x11xinput2.h"
+#include "../../events/SDL_mouse_c.h"
+
+
+/* FIXME: Find a better place to put this... */
+static Cursor x11_empty_cursor = None;
+
+static Display *
+GetDisplay(void)
+{
+ return ((SDL_VideoData *)SDL_GetVideoDevice()->driverdata)->display;
+}
+
+static Cursor
+X11_CreateEmptyCursor()
+{
+ if (x11_empty_cursor == None) {
+ Display *display = GetDisplay();
+ char data[1];
+ XColor color;
+ Pixmap pixmap;
+
+ SDL_zero(data);
+ color.red = color.green = color.blue = 0;
+ pixmap = X11_XCreateBitmapFromData(display, DefaultRootWindow(display),
+ data, 1, 1);
+ if (pixmap) {
+ x11_empty_cursor = X11_XCreatePixmapCursor(display, pixmap, pixmap,
+ &color, &color, 0, 0);
+ X11_XFreePixmap(display, pixmap);
+ }
+ }
+ return x11_empty_cursor;
+}
+
+static void
+X11_DestroyEmptyCursor(void)
+{
+ if (x11_empty_cursor != None) {
+ X11_XFreeCursor(GetDisplay(), x11_empty_cursor);
+ x11_empty_cursor = None;
+ }
+}
+
+static SDL_Cursor *
+X11_CreateDefaultCursor()
+{
+ SDL_Cursor *cursor;
+
+ cursor = SDL_calloc(1, sizeof(*cursor));
+ if (cursor) {
+ /* None is used to indicate the default cursor */
+ cursor->driverdata = (void*)None;
+ } else {
+ SDL_OutOfMemory();
+ }
+
+ return cursor;
+}
+
+#if SDL_VIDEO_DRIVER_X11_XCURSOR
+static Cursor
+X11_CreateXCursorCursor(SDL_Surface * surface, int hot_x, int hot_y)
+{
+ Display *display = GetDisplay();
+ Cursor cursor = None;
+ XcursorImage *image;
+
+ image = X11_XcursorImageCreate(surface->w, surface->h);
+ if (!image) {
+ SDL_OutOfMemory();
+ return None;
+ }
+ image->xhot = hot_x;
+ image->yhot = hot_y;
+ image->delay = 0;
+
+ SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
+ SDL_assert(surface->pitch == surface->w * 4);
+ SDL_memcpy(image->pixels, surface->pixels, surface->h * surface->pitch);
+
+ cursor = X11_XcursorImageLoadCursor(display, image);
+
+ X11_XcursorImageDestroy(image);
+
+ return cursor;
+}
+#endif /* SDL_VIDEO_DRIVER_X11_XCURSOR */
+
+static Cursor
+X11_CreatePixmapCursor(SDL_Surface * surface, int hot_x, int hot_y)
+{
+ Display *display = GetDisplay();
+ XColor fg, bg;
+ Cursor cursor = None;
+ Uint32 *ptr;
+ Uint8 *data_bits, *mask_bits;
+ Pixmap data_pixmap, mask_pixmap;
+ int x, y;
+ unsigned int rfg, gfg, bfg, rbg, gbg, bbg, fgBits, bgBits;
+ unsigned int width_bytes = ((surface->w + 7) & ~7) / 8;
+
+ data_bits = SDL_calloc(1, surface->h * width_bytes);
+ if (!data_bits) {
+ SDL_OutOfMemory();
+ return None;
+ }
+
+ mask_bits = SDL_calloc(1, surface->h * width_bytes);
+ if (!mask_bits) {
+ SDL_free(data_bits);
+ SDL_OutOfMemory();
+ return None;
+ }
+
+ /* Code below assumes ARGB pixel format */
+ SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
+
+ rfg = gfg = bfg = rbg = gbg = bbg = fgBits = bgBits = 0;
+ for (y = 0; y < surface->h; ++y) {
+ ptr = (Uint32 *)((Uint8 *)surface->pixels + y * surface->pitch);
+ for (x = 0; x < surface->w; ++x) {
+ int alpha = (*ptr >> 24) & 0xff;
+ int red = (*ptr >> 16) & 0xff;
+ int green = (*ptr >> 8) & 0xff;
+ int blue = (*ptr >> 0) & 0xff;
+ if (alpha > 25) {
+ mask_bits[y * width_bytes + x / 8] |= (0x01 << (x % 8));
+
+ if ((red + green + blue) > 0x40) {
+ fgBits++;
+ rfg += red;
+ gfg += green;
+ bfg += blue;
+ data_bits[y * width_bytes + x / 8] |= (0x01 << (x % 8));
+ } else {
+ bgBits++;
+ rbg += red;
+ gbg += green;
+ bbg += blue;
+ }
+ }
+ ++ptr;
+ }
+ }
+
+ if (fgBits) {
+ fg.red = rfg * 257 / fgBits;
+ fg.green = gfg * 257 / fgBits;
+ fg.blue = bfg * 257 / fgBits;
+ }
+ else fg.red = fg.green = fg.blue = 0;
+
+ if (bgBits) {
+ bg.red = rbg * 257 / bgBits;
+ bg.green = gbg * 257 / bgBits;
+ bg.blue = bbg * 257 / bgBits;
+ }
+ else bg.red = bg.green = bg.blue = 0;
+
+ data_pixmap = X11_XCreateBitmapFromData(display, DefaultRootWindow(display),
+ (char*)data_bits,
+ surface->w, surface->h);
+ mask_pixmap = X11_XCreateBitmapFromData(display, DefaultRootWindow(display),
+ (char*)mask_bits,
+ surface->w, surface->h);
+ cursor = X11_XCreatePixmapCursor(display, data_pixmap, mask_pixmap,
+ &fg, &bg, hot_x, hot_y);
+ X11_XFreePixmap(display, data_pixmap);
+ X11_XFreePixmap(display, mask_pixmap);
+
+ return cursor;
+}
+
+static SDL_Cursor *
+X11_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
+{
+ SDL_Cursor *cursor;
+
+ cursor = SDL_calloc(1, sizeof(*cursor));
+ if (cursor) {
+ Cursor x11_cursor = None;
+
+#if SDL_VIDEO_DRIVER_X11_XCURSOR
+ if (SDL_X11_HAVE_XCURSOR) {
+ x11_cursor = X11_CreateXCursorCursor(surface, hot_x, hot_y);
+ }
+#endif
+ if (x11_cursor == None) {
+ x11_cursor = X11_CreatePixmapCursor(surface, hot_x, hot_y);
+ }
+ cursor->driverdata = (void*)x11_cursor;
+ } else {
+ SDL_OutOfMemory();
+ }
+
+ return cursor;
+}
+
+static SDL_Cursor *
+X11_CreateSystemCursor(SDL_SystemCursor id)
+{
+ SDL_Cursor *cursor;
+ unsigned int shape;
+
+ switch(id)
+ {
+ default:
+ SDL_assert(0);
+ return NULL;
+ /* X Font Cursors reference: */
+ /* http://tronche.com/gui/x/xlib/appendix/b/ */
+ case SDL_SYSTEM_CURSOR_ARROW: shape = XC_left_ptr; break;
+ case SDL_SYSTEM_CURSOR_IBEAM: shape = XC_xterm; break;
+ case SDL_SYSTEM_CURSOR_WAIT: shape = XC_watch; break;
+ case SDL_SYSTEM_CURSOR_CROSSHAIR: shape = XC_tcross; break;
+ case SDL_SYSTEM_CURSOR_WAITARROW: shape = XC_watch; break;
+ case SDL_SYSTEM_CURSOR_SIZENWSE: shape = XC_fleur; break;
+ case SDL_SYSTEM_CURSOR_SIZENESW: shape = XC_fleur; break;
+ case SDL_SYSTEM_CURSOR_SIZEWE: shape = XC_sb_h_double_arrow; break;
+ case SDL_SYSTEM_CURSOR_SIZENS: shape = XC_sb_v_double_arrow; break;
+ case SDL_SYSTEM_CURSOR_SIZEALL: shape = XC_fleur; break;
+ case SDL_SYSTEM_CURSOR_NO: shape = XC_pirate; break;
+ case SDL_SYSTEM_CURSOR_HAND: shape = XC_hand2; break;
+ }
+
+ cursor = SDL_calloc(1, sizeof(*cursor));
+ if (cursor) {
+ Cursor x11_cursor;
+
+ x11_cursor = X11_XCreateFontCursor(GetDisplay(), shape);
+
+ cursor->driverdata = (void*)x11_cursor;
+ } else {
+ SDL_OutOfMemory();
+ }
+
+ return cursor;
+}
+
+static void
+X11_FreeCursor(SDL_Cursor * cursor)
+{
+ Cursor x11_cursor = (Cursor)cursor->driverdata;
+
+ if (x11_cursor != None) {
+ X11_XFreeCursor(GetDisplay(), x11_cursor);
+ }
+ SDL_free(cursor);
+}
+
+static int
+X11_ShowCursor(SDL_Cursor * cursor)
+{
+ Cursor x11_cursor = 0;
+
+ if (cursor) {
+ x11_cursor = (Cursor)cursor->driverdata;
+ } else {
+ x11_cursor = X11_CreateEmptyCursor();
+ }
+
+ /* FIXME: Is there a better way than this? */
+ {
+ SDL_VideoDevice *video = SDL_GetVideoDevice();
+ Display *display = GetDisplay();
+ SDL_Window *window;
+ SDL_WindowData *data;
+
+ for (window = video->windows; window; window = window->next) {
+ data = (SDL_WindowData *)window->driverdata;
+ if (x11_cursor != None) {
+ X11_XDefineCursor(display, data->xwindow, x11_cursor);
+ } else {
+ X11_XUndefineCursor(display, data->xwindow);
+ }
+ }
+ X11_XFlush(display);
+ }
+ return 0;
+}
+
+static void
+WarpMouseInternal(Window xwindow, const int x, const int y)
+{
+ SDL_VideoData *videodata = (SDL_VideoData *) SDL_GetVideoDevice()->driverdata;
+ Display *display = videodata->display;
+ X11_XWarpPointer(display, None, xwindow, 0, 0, 0, 0, x, y);
+ X11_XSync(display, False);
+ videodata->global_mouse_changed = SDL_TRUE;
+}
+
+static void
+X11_WarpMouse(SDL_Window * window, int x, int y)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ WarpMouseInternal(data->xwindow, x, y);
+}
+
+static int
+X11_WarpMouseGlobal(int x, int y)
+{
+ WarpMouseInternal(DefaultRootWindow(GetDisplay()), x, y);
+ return 0;
+}
+
+static int
+X11_SetRelativeMouseMode(SDL_bool enabled)
+{
+#if SDL_VIDEO_DRIVER_X11_XINPUT2
+ if(X11_Xinput2IsInitialized())
+ return 0;
+#else
+ SDL_Unsupported();
+#endif
+ return -1;
+}
+
+static int
+X11_CaptureMouse(SDL_Window *window)
+{
+ Display *display = GetDisplay();
+
+ if (window) {
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ const unsigned int mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask;
+ const int rc = X11_XGrabPointer(display, data->xwindow, False,
+ mask, GrabModeAsync, GrabModeAsync,
+ None, None, CurrentTime);
+ if (rc != GrabSuccess) {
+ return SDL_SetError("X server refused mouse capture");
+ }
+ } else {
+ X11_XUngrabPointer(display, CurrentTime);
+ }
+
+ X11_XSync(display, False);
+
+ return 0;
+}
+
+static Uint32
+X11_GetGlobalMouseState(int *x, int *y)
+{
+ SDL_VideoData *videodata = (SDL_VideoData *) SDL_GetVideoDevice()->driverdata;
+ Display *display = GetDisplay();
+ const int num_screens = SDL_GetNumVideoDisplays();
+ int i;
+
+ /* !!! FIXME: should we XSync() here first? */
+
+#if !SDL_VIDEO_DRIVER_X11_XINPUT2
+ videodata->global_mouse_changed = SDL_TRUE;
+#endif
+
+ /* check if we have this cached since XInput last saw the mouse move. */
+ /* !!! FIXME: can we just calculate this from XInput's events? */
+ if (videodata->global_mouse_changed) {
+ for (i = 0; i < num_screens; i++) {
+ SDL_DisplayData *data = (SDL_DisplayData *) SDL_GetDisplayDriverData(i);
+ if (data != NULL) {
+ Window root, child;
+ int rootx, rooty, winx, winy;
+ unsigned int mask;
+ if (X11_XQueryPointer(display, RootWindow(display, data->screen), &root, &child, &rootx, &rooty, &winx, &winy, &mask)) {
+ XWindowAttributes root_attrs;
+ Uint32 buttons = 0;
+ buttons |= (mask & Button1Mask) ? SDL_BUTTON_LMASK : 0;
+ buttons |= (mask & Button2Mask) ? SDL_BUTTON_MMASK : 0;
+ buttons |= (mask & Button3Mask) ? SDL_BUTTON_RMASK : 0;
+ /* SDL_DisplayData->x,y point to screen origin, and adding them to mouse coordinates relative to root window doesn't do the right thing
+ * (observed on dual monitor setup with primary display being the rightmost one - mouse was offset to the right).
+ *
+ * Adding root position to root-relative coordinates seems to be a better way to get absolute position. */
+ X11_XGetWindowAttributes(display, root, &root_attrs);
+ videodata->global_mouse_position.x = root_attrs.x + rootx;
+ videodata->global_mouse_position.y = root_attrs.y + rooty;
+ videodata->global_mouse_buttons = buttons;
+ videodata->global_mouse_changed = SDL_FALSE;
+ break;
+ }
+ }
+ }
+ }
+
+ SDL_assert(!videodata->global_mouse_changed); /* The pointer wasn't on any X11 screen?! */
+
+ *x = videodata->global_mouse_position.x;
+ *y = videodata->global_mouse_position.y;
+ return videodata->global_mouse_buttons;
+}
+
+
+void
+X11_InitMouse(_THIS)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ mouse->CreateCursor = X11_CreateCursor;
+ mouse->CreateSystemCursor = X11_CreateSystemCursor;
+ mouse->ShowCursor = X11_ShowCursor;
+ mouse->FreeCursor = X11_FreeCursor;
+ mouse->WarpMouse = X11_WarpMouse;
+ mouse->WarpMouseGlobal = X11_WarpMouseGlobal;
+ mouse->SetRelativeMouseMode = X11_SetRelativeMouseMode;
+ mouse->CaptureMouse = X11_CaptureMouse;
+ mouse->GetGlobalMouseState = X11_GetGlobalMouseState;
+
+ SDL_SetDefaultCursor(X11_CreateDefaultCursor());
+}
+
+void
+X11_QuitMouse(_THIS)
+{
+ X11_DestroyEmptyCursor();
+}
+
+#endif /* SDL_VIDEO_DRIVER_X11 */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11mouse.h b/src/3rdparty/SDL2/src/video/x11/SDL_x11mouse.h
new file mode 100644
index 0000000..1041858
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11mouse.h
@@ -0,0 +1,31 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_x11mouse_h_
+#define SDL_x11mouse_h_
+
+extern void X11_InitMouse(_THIS);
+extern void X11_QuitMouse(_THIS);
+
+#endif /* SDL_x11mouse_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11opengl.c b/src/3rdparty/SDL2/src/video/x11/SDL_x11opengl.c
new file mode 100644
index 0000000..7c3cb33
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11opengl.c
@@ -0,0 +1,946 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_X11
+
+#include "SDL_x11video.h"
+#include "SDL_assert.h"
+#include "SDL_hints.h"
+
+/* GLX implementation of SDL OpenGL support */
+
+#if SDL_VIDEO_OPENGL_GLX
+#include "SDL_loadso.h"
+#include "SDL_x11opengles.h"
+
+#if defined(__IRIX__)
+/* IRIX doesn't have a GL library versioning system */
+#define DEFAULT_OPENGL "libGL.so"
+#elif defined(__MACOSX__)
+#define DEFAULT_OPENGL "/usr/X11R6/lib/libGL.1.dylib"
+#elif defined(__QNXNTO__)
+#define DEFAULT_OPENGL "libGL.so.3"
+#else
+#define DEFAULT_OPENGL "libGL.so.1"
+#endif
+
+#ifndef GLX_NONE_EXT
+#define GLX_NONE_EXT 0x8000
+#endif
+
+#ifndef GLX_ARB_multisample
+#define GLX_ARB_multisample
+#define GLX_SAMPLE_BUFFERS_ARB 100000
+#define GLX_SAMPLES_ARB 100001
+#endif
+
+#ifndef GLX_EXT_visual_rating
+#define GLX_EXT_visual_rating
+#define GLX_VISUAL_CAVEAT_EXT 0x20
+#define GLX_NONE_EXT 0x8000
+#define GLX_SLOW_VISUAL_EXT 0x8001
+#define GLX_NON_CONFORMANT_VISUAL_EXT 0x800D
+#endif
+
+#ifndef GLX_EXT_visual_info
+#define GLX_EXT_visual_info
+#define GLX_X_VISUAL_TYPE_EXT 0x22
+#define GLX_DIRECT_COLOR_EXT 0x8003
+#endif
+
+#ifndef GLX_ARB_create_context
+#define GLX_ARB_create_context
+#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
+#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
+#define GLX_CONTEXT_FLAGS_ARB 0x2094
+#define GLX_CONTEXT_DEBUG_BIT_ARB 0x0001
+#define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
+
+/* Typedef for the GL 3.0 context creation function */
+typedef GLXContext(*PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display * dpy,
+ GLXFBConfig config,
+ GLXContext
+ share_context,
+ Bool direct,
+ const int
+ *attrib_list);
+#endif
+
+#ifndef GLX_ARB_create_context_profile
+#define GLX_ARB_create_context_profile
+#define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126
+#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
+#define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
+#endif
+
+#ifndef GLX_ARB_create_context_robustness
+#define GLX_ARB_create_context_robustness
+#define GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004
+#define GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
+#define GLX_NO_RESET_NOTIFICATION_ARB 0x8261
+#define GLX_LOSE_CONTEXT_ON_RESET_ARB 0x8252
+#endif
+
+#ifndef GLX_EXT_create_context_es2_profile
+#define GLX_EXT_create_context_es2_profile
+#ifndef GLX_CONTEXT_ES2_PROFILE_BIT_EXT
+#define GLX_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000002
+#endif
+#endif
+
+#ifndef GLX_ARB_framebuffer_sRGB
+#define GLX_ARB_framebuffer_sRGB
+#ifndef GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB
+#define GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20B2
+#endif
+#endif
+
+#ifndef GLX_ARB_create_context_no_error
+#define GLX_ARB_create_context_no_error
+#ifndef GLX_CONTEXT_OPENGL_NO_ERROR_ARB
+#define GLX_CONTEXT_OPENGL_NO_ERROR_ARB 0x31B3
+#endif
+#endif
+
+#ifndef GLX_EXT_swap_control
+#define GLX_SWAP_INTERVAL_EXT 0x20F1
+#define GLX_MAX_SWAP_INTERVAL_EXT 0x20F2
+#endif
+
+#ifndef GLX_EXT_swap_control_tear
+#define GLX_LATE_SWAPS_TEAR_EXT 0x20F3
+#endif
+
+#ifndef GLX_ARB_context_flush_control
+#define GLX_ARB_context_flush_control
+#define GLX_CONTEXT_RELEASE_BEHAVIOR_ARB 0x2097
+#define GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB 0x0000
+#define GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098
+#endif
+
+#define OPENGL_REQUIRES_DLOPEN
+#if defined(OPENGL_REQUIRES_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
+#include <dlfcn.h>
+#define GL_LoadObject(X) dlopen(X, (RTLD_NOW|RTLD_GLOBAL))
+#define GL_LoadFunction dlsym
+#define GL_UnloadObject dlclose
+#else
+#define GL_LoadObject SDL_LoadObject
+#define GL_LoadFunction SDL_LoadFunction
+#define GL_UnloadObject SDL_UnloadObject
+#endif
+
+static void X11_GL_InitExtensions(_THIS);
+
+int
+X11_GL_LoadLibrary(_THIS, const char *path)
+{
+ Display *display;
+ void *handle;
+
+ if (_this->gl_data) {
+ return SDL_SetError("OpenGL context already created");
+ }
+
+ /* Load the OpenGL library */
+ if (path == NULL) {
+ path = SDL_getenv("SDL_OPENGL_LIBRARY");
+ }
+ if (path == NULL) {
+ path = DEFAULT_OPENGL;
+ }
+ _this->gl_config.dll_handle = GL_LoadObject(path);
+ if (!_this->gl_config.dll_handle) {
+#if defined(OPENGL_REQUIRES_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
+ SDL_SetError("Failed loading %s: %s", path, dlerror());
+#endif
+ return -1;
+ }
+ SDL_strlcpy(_this->gl_config.driver_path, path,
+ SDL_arraysize(_this->gl_config.driver_path));
+
+ /* Allocate OpenGL memory */
+ _this->gl_data =
+ (struct SDL_GLDriverData *) SDL_calloc(1,
+ sizeof(struct
+ SDL_GLDriverData));
+ if (!_this->gl_data) {
+ return SDL_OutOfMemory();
+ }
+
+ /* Load function pointers */
+ handle = _this->gl_config.dll_handle;
+ _this->gl_data->glXQueryExtension =
+ (Bool (*)(Display *, int *, int *))
+ GL_LoadFunction(handle, "glXQueryExtension");
+ _this->gl_data->glXGetProcAddress =
+ (void *(*)(const GLubyte *))
+ GL_LoadFunction(handle, "glXGetProcAddressARB");
+ _this->gl_data->glXChooseVisual =
+ (XVisualInfo * (*)(Display *, int, int *))
+ X11_GL_GetProcAddress(_this, "glXChooseVisual");
+ _this->gl_data->glXCreateContext =
+ (GLXContext(*)(Display *, XVisualInfo *, GLXContext, int))
+ X11_GL_GetProcAddress(_this, "glXCreateContext");
+ _this->gl_data->glXDestroyContext =
+ (void (*)(Display *, GLXContext))
+ X11_GL_GetProcAddress(_this, "glXDestroyContext");
+ _this->gl_data->glXMakeCurrent =
+ (int (*)(Display *, GLXDrawable, GLXContext))
+ X11_GL_GetProcAddress(_this, "glXMakeCurrent");
+ _this->gl_data->glXSwapBuffers =
+ (void (*)(Display *, GLXDrawable))
+ X11_GL_GetProcAddress(_this, "glXSwapBuffers");
+ _this->gl_data->glXQueryDrawable =
+ (void (*)(Display*,GLXDrawable,int,unsigned int*))
+ X11_GL_GetProcAddress(_this, "glXQueryDrawable");
+
+ if (!_this->gl_data->glXQueryExtension ||
+ !_this->gl_data->glXChooseVisual ||
+ !_this->gl_data->glXCreateContext ||
+ !_this->gl_data->glXDestroyContext ||
+ !_this->gl_data->glXMakeCurrent ||
+ !_this->gl_data->glXSwapBuffers) {
+ return SDL_SetError("Could not retrieve OpenGL functions");
+ }
+
+ display = ((SDL_VideoData *) _this->driverdata)->display;
+ if (!_this->gl_data->glXQueryExtension(display, &_this->gl_data->errorBase, &_this->gl_data->eventBase)) {
+ return SDL_SetError("GLX is not supported");
+ }
+
+ /* Initialize extensions */
+ /* See lengthy comment about the inc/dec in
+ ../windows/SDL_windowsopengl.c. */
+ ++_this->gl_config.driver_loaded;
+ X11_GL_InitExtensions(_this);
+ --_this->gl_config.driver_loaded;
+
+ /* If we need a GL ES context and there's no
+ * GLX_EXT_create_context_es2_profile extension, switch over to X11_GLES functions
+ */
+ if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES &&
+ X11_GL_UseEGL(_this) ) {
+#if SDL_VIDEO_OPENGL_EGL
+ X11_GL_UnloadLibrary(_this);
+ /* Better avoid conflicts! */
+ if (_this->gl_config.dll_handle != NULL ) {
+ GL_UnloadObject(_this->gl_config.dll_handle);
+ _this->gl_config.dll_handle = NULL;
+ }
+ _this->GL_LoadLibrary = X11_GLES_LoadLibrary;
+ _this->GL_GetProcAddress = X11_GLES_GetProcAddress;
+ _this->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
+ _this->GL_CreateContext = X11_GLES_CreateContext;
+ _this->GL_MakeCurrent = X11_GLES_MakeCurrent;
+ _this->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
+ _this->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
+ _this->GL_SwapWindow = X11_GLES_SwapWindow;
+ _this->GL_DeleteContext = X11_GLES_DeleteContext;
+ return X11_GLES_LoadLibrary(_this, NULL);
+#else
+ return SDL_SetError("SDL not configured with EGL support");
+#endif
+ }
+
+ return 0;
+}
+
+void *
+X11_GL_GetProcAddress(_THIS, const char *proc)
+{
+ if (_this->gl_data->glXGetProcAddress) {
+ return _this->gl_data->glXGetProcAddress((const GLubyte *) proc);
+ }
+ return GL_LoadFunction(_this->gl_config.dll_handle, proc);
+}
+
+void
+X11_GL_UnloadLibrary(_THIS)
+{
+ /* Don't actually unload the library, since it may have registered
+ * X11 shutdown hooks, per the notes at:
+ * http://dri.sourceforge.net/doc/DRIuserguide.html
+ */
+#if 0
+ GL_UnloadObject(_this->gl_config.dll_handle);
+ _this->gl_config.dll_handle = NULL;
+#endif
+
+ /* Free OpenGL memory */
+ SDL_free(_this->gl_data);
+ _this->gl_data = NULL;
+}
+
+static SDL_bool
+HasExtension(const char *extension, const char *extensions)
+{
+ const char *start;
+ const char *where, *terminator;
+
+ if (!extensions)
+ return SDL_FALSE;
+
+ /* Extension names should not have spaces. */
+ where = SDL_strchr(extension, ' ');
+ if (where || *extension == '\0')
+ return SDL_FALSE;
+
+ /* It takes a bit of care to be fool-proof about parsing the
+ * OpenGL extensions string. Don't be fooled by sub-strings,
+ * etc. */
+
+ start = extensions;
+
+ for (;;) {
+ where = SDL_strstr(start, extension);
+ if (!where)
+ break;
+
+ terminator = where + SDL_strlen(extension);
+ if (where == start || *(where - 1) == ' ')
+ if (*terminator == ' ' || *terminator == '\0')
+ return SDL_TRUE;
+
+ start = terminator;
+ }
+ return SDL_FALSE;
+}
+
+static void
+X11_GL_InitExtensions(_THIS)
+{
+ Display *display = ((SDL_VideoData *) _this->driverdata)->display;
+ const int screen = DefaultScreen(display);
+ XVisualInfo *vinfo = NULL;
+ Window w = 0;
+ GLXContext prev_ctx = 0;
+ GLXDrawable prev_drawable = 0;
+ GLXContext context = 0;
+ const char *(*glXQueryExtensionsStringFunc) (Display *, int);
+ const char *extensions;
+
+ vinfo = X11_GL_GetVisual(_this, display, screen);
+ if (vinfo) {
+ GLXContext (*glXGetCurrentContextFunc) (void) =
+ (GLXContext(*)(void))
+ X11_GL_GetProcAddress(_this, "glXGetCurrentContext");
+
+ GLXDrawable (*glXGetCurrentDrawableFunc) (void) =
+ (GLXDrawable(*)(void))
+ X11_GL_GetProcAddress(_this, "glXGetCurrentDrawable");
+
+ if (glXGetCurrentContextFunc && glXGetCurrentDrawableFunc) {
+ XSetWindowAttributes xattr;
+ prev_ctx = glXGetCurrentContextFunc();
+ prev_drawable = glXGetCurrentDrawableFunc();
+
+ xattr.background_pixel = 0;
+ xattr.border_pixel = 0;
+ xattr.colormap =
+ X11_XCreateColormap(display, RootWindow(display, screen),
+ vinfo->visual, AllocNone);
+ w = X11_XCreateWindow(display, RootWindow(display, screen), 0, 0,
+ 32, 32, 0, vinfo->depth, InputOutput, vinfo->visual,
+ (CWBackPixel | CWBorderPixel | CWColormap), &xattr);
+
+ context = _this->gl_data->glXCreateContext(display, vinfo,
+ NULL, True);
+ if (context) {
+ _this->gl_data->glXMakeCurrent(display, w, context);
+ }
+ }
+
+ X11_XFree(vinfo);
+ }
+
+ glXQueryExtensionsStringFunc =
+ (const char *(*)(Display *, int)) X11_GL_GetProcAddress(_this,
+ "glXQueryExtensionsString");
+ if (glXQueryExtensionsStringFunc) {
+ extensions = glXQueryExtensionsStringFunc(display, screen);
+ } else {
+ extensions = NULL;
+ }
+
+ /* Check for GLX_EXT_swap_control(_tear) */
+ _this->gl_data->HAS_GLX_EXT_swap_control_tear = SDL_FALSE;
+ if (HasExtension("GLX_EXT_swap_control", extensions)) {
+ _this->gl_data->glXSwapIntervalEXT =
+ (void (*)(Display*,GLXDrawable,int))
+ X11_GL_GetProcAddress(_this, "glXSwapIntervalEXT");
+ if (HasExtension("GLX_EXT_swap_control_tear", extensions)) {
+ _this->gl_data->HAS_GLX_EXT_swap_control_tear = SDL_TRUE;
+ }
+ }
+
+ /* Check for GLX_MESA_swap_control */
+ if (HasExtension("GLX_MESA_swap_control", extensions)) {
+ _this->gl_data->glXSwapIntervalMESA =
+ (int(*)(int)) X11_GL_GetProcAddress(_this, "glXSwapIntervalMESA");
+ _this->gl_data->glXGetSwapIntervalMESA =
+ (int(*)(void)) X11_GL_GetProcAddress(_this,
+ "glXGetSwapIntervalMESA");
+ }
+
+ /* Check for GLX_SGI_swap_control */
+ if (HasExtension("GLX_SGI_swap_control", extensions)) {
+ _this->gl_data->glXSwapIntervalSGI =
+ (int (*)(int)) X11_GL_GetProcAddress(_this, "glXSwapIntervalSGI");
+ }
+
+ /* Check for GLX_ARB_create_context */
+ if (HasExtension("GLX_ARB_create_context", extensions)) {
+ _this->gl_data->glXCreateContextAttribsARB =
+ (GLXContext (*)(Display*,GLXFBConfig,GLXContext,Bool,const int *))
+ X11_GL_GetProcAddress(_this, "glXCreateContextAttribsARB");
+ _this->gl_data->glXChooseFBConfig =
+ (GLXFBConfig *(*)(Display *, int, const int *, int *))
+ X11_GL_GetProcAddress(_this, "glXChooseFBConfig");
+ }
+
+ /* Check for GLX_EXT_visual_rating */
+ if (HasExtension("GLX_EXT_visual_rating", extensions)) {
+ _this->gl_data->HAS_GLX_EXT_visual_rating = SDL_TRUE;
+ }
+
+ /* Check for GLX_EXT_visual_info */
+ if (HasExtension("GLX_EXT_visual_info", extensions)) {
+ _this->gl_data->HAS_GLX_EXT_visual_info = SDL_TRUE;
+ }
+
+ /* Check for GLX_EXT_create_context_es2_profile */
+ if (HasExtension("GLX_EXT_create_context_es2_profile", extensions)) {
+ /* this wants to call glGetString(), so it needs a context. */
+ /* !!! FIXME: it would be nice not to make a context here though! */
+ if (context) {
+ SDL_GL_DeduceMaxSupportedESProfile(
+ &_this->gl_data->es_profile_max_supported_version.major,
+ &_this->gl_data->es_profile_max_supported_version.minor
+ );
+ }
+ }
+
+ /* Check for GLX_ARB_context_flush_control */
+ if (HasExtension("GLX_ARB_context_flush_control", extensions)) {
+ _this->gl_data->HAS_GLX_ARB_context_flush_control = SDL_TRUE;
+ }
+
+ /* Check for GLX_ARB_create_context_robustness */
+ if (HasExtension("GLX_ARB_create_context_robustness", extensions)) {
+ _this->gl_data->HAS_GLX_ARB_create_context_robustness = SDL_TRUE;
+ }
+
+ /* Check for GLX_ARB_create_context_no_error */
+ if (HasExtension("GLX_ARB_create_context_no_error", extensions)) {
+ _this->gl_data->HAS_GLX_ARB_create_context_no_error = SDL_TRUE;
+ }
+
+ if (context) {
+ _this->gl_data->glXMakeCurrent(display, None, NULL);
+ _this->gl_data->glXDestroyContext(display, context);
+ if (prev_ctx && prev_drawable) {
+ _this->gl_data->glXMakeCurrent(display, prev_drawable, prev_ctx);
+ }
+ }
+
+ if (w) {
+ X11_XDestroyWindow(display, w);
+ }
+ X11_PumpEvents(_this);
+}
+
+/* glXChooseVisual and glXChooseFBConfig have some small differences in
+ * the attribute encoding, it can be chosen with the for_FBConfig parameter.
+ * Some targets fail if you use GLX_X_VISUAL_TYPE_EXT/GLX_DIRECT_COLOR_EXT,
+ * so it gets specified last if used and is pointed to by *_pvistypeattr.
+ * In case of failure, if that pointer is not NULL, set that pointer to None
+ * and try again.
+ */
+static int
+X11_GL_GetAttributes(_THIS, Display * display, int screen, int * attribs, int size, Bool for_FBConfig, int **_pvistypeattr)
+{
+ int i = 0;
+ const int MAX_ATTRIBUTES = 64;
+ int *pvistypeattr = NULL;
+
+ /* assert buffer is large enough to hold all SDL attributes. */
+ SDL_assert(size >= MAX_ATTRIBUTES);
+
+ /* Setup our GLX attributes according to the gl_config. */
+ if( for_FBConfig ) {
+ attribs[i++] = GLX_RENDER_TYPE;
+ attribs[i++] = GLX_RGBA_BIT;
+ } else {
+ attribs[i++] = GLX_RGBA;
+ }
+ attribs[i++] = GLX_RED_SIZE;
+ attribs[i++] = _this->gl_config.red_size;
+ attribs[i++] = GLX_GREEN_SIZE;
+ attribs[i++] = _this->gl_config.green_size;
+ attribs[i++] = GLX_BLUE_SIZE;
+ attribs[i++] = _this->gl_config.blue_size;
+
+ if (_this->gl_config.alpha_size) {
+ attribs[i++] = GLX_ALPHA_SIZE;
+ attribs[i++] = _this->gl_config.alpha_size;
+ }
+
+ if (_this->gl_config.double_buffer) {
+ attribs[i++] = GLX_DOUBLEBUFFER;
+ if( for_FBConfig ) {
+ attribs[i++] = True;
+ }
+ }
+
+ attribs[i++] = GLX_DEPTH_SIZE;
+ attribs[i++] = _this->gl_config.depth_size;
+
+ if (_this->gl_config.stencil_size) {
+ attribs[i++] = GLX_STENCIL_SIZE;
+ attribs[i++] = _this->gl_config.stencil_size;
+ }
+
+ if (_this->gl_config.accum_red_size) {
+ attribs[i++] = GLX_ACCUM_RED_SIZE;
+ attribs[i++] = _this->gl_config.accum_red_size;
+ }
+
+ if (_this->gl_config.accum_green_size) {
+ attribs[i++] = GLX_ACCUM_GREEN_SIZE;
+ attribs[i++] = _this->gl_config.accum_green_size;
+ }
+
+ if (_this->gl_config.accum_blue_size) {
+ attribs[i++] = GLX_ACCUM_BLUE_SIZE;
+ attribs[i++] = _this->gl_config.accum_blue_size;
+ }
+
+ if (_this->gl_config.accum_alpha_size) {
+ attribs[i++] = GLX_ACCUM_ALPHA_SIZE;
+ attribs[i++] = _this->gl_config.accum_alpha_size;
+ }
+
+ if (_this->gl_config.stereo) {
+ attribs[i++] = GLX_STEREO;
+ if( for_FBConfig ) {
+ attribs[i++] = True;
+ }
+ }
+
+ if (_this->gl_config.multisamplebuffers) {
+ attribs[i++] = GLX_SAMPLE_BUFFERS_ARB;
+ attribs[i++] = _this->gl_config.multisamplebuffers;
+ }
+
+ if (_this->gl_config.multisamplesamples) {
+ attribs[i++] = GLX_SAMPLES_ARB;
+ attribs[i++] = _this->gl_config.multisamplesamples;
+ }
+
+ if (_this->gl_config.framebuffer_srgb_capable) {
+ attribs[i++] = GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB;
+ attribs[i++] = True; /* always needed, for_FBConfig or not! */
+ }
+
+ if (_this->gl_config.accelerated >= 0 &&
+ _this->gl_data->HAS_GLX_EXT_visual_rating) {
+ attribs[i++] = GLX_VISUAL_CAVEAT_EXT;
+ attribs[i++] = _this->gl_config.accelerated ? GLX_NONE_EXT :
+ GLX_SLOW_VISUAL_EXT;
+ }
+
+ /* If we're supposed to use DirectColor visuals, and we've got the
+ EXT_visual_info extension, then add GLX_X_VISUAL_TYPE_EXT. */
+ if (X11_UseDirectColorVisuals() &&
+ _this->gl_data->HAS_GLX_EXT_visual_info) {
+ pvistypeattr = &attribs[i];
+ attribs[i++] = GLX_X_VISUAL_TYPE_EXT;
+ attribs[i++] = GLX_DIRECT_COLOR_EXT;
+ }
+
+ attribs[i++] = None;
+
+ SDL_assert(i <= MAX_ATTRIBUTES);
+
+ if (_pvistypeattr) {
+ *_pvistypeattr = pvistypeattr;
+ }
+
+ return i;
+}
+
+XVisualInfo *
+X11_GL_GetVisual(_THIS, Display * display, int screen)
+{
+ /* 64 seems nice. */
+ int attribs[64];
+ XVisualInfo *vinfo;
+ int *pvistypeattr = NULL;
+
+ if (!_this->gl_data) {
+ /* The OpenGL library wasn't loaded, SDL_GetError() should have info */
+ return NULL;
+ }
+
+ X11_GL_GetAttributes(_this, display, screen, attribs, 64, SDL_FALSE, &pvistypeattr);
+ vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs);
+
+ if (!vinfo && (pvistypeattr != NULL)) {
+ *pvistypeattr = None;
+ vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs);
+ }
+
+ if (!vinfo) {
+ SDL_SetError("Couldn't find matching GLX visual");
+ }
+ return vinfo;
+}
+
+static int (*handler) (Display *, XErrorEvent *) = NULL;
+static const char *errorHandlerOperation = NULL;
+static int errorBase = 0;
+static int errorCode = 0;
+static int
+X11_GL_ErrorHandler(Display * d, XErrorEvent * e)
+{
+ char *x11_error = NULL;
+ char x11_error_locale[256];
+
+ errorCode = e->error_code;
+ if (X11_XGetErrorText(d, errorCode, x11_error_locale, sizeof(x11_error_locale)) == Success)
+ {
+ x11_error = SDL_iconv_string("UTF-8", "", x11_error_locale, SDL_strlen(x11_error_locale)+1);
+ }
+
+ if (x11_error)
+ {
+ SDL_SetError("Could not %s: %s", errorHandlerOperation, x11_error);
+ SDL_free(x11_error);
+ }
+ else
+ {
+ SDL_SetError("Could not %s: %i (Base %i)", errorHandlerOperation, errorCode, errorBase);
+ }
+
+ return (0);
+}
+
+SDL_bool
+X11_GL_UseEGL(_THIS)
+{
+ SDL_assert(_this->gl_data != NULL);
+ SDL_assert(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES);
+
+ return (SDL_GetHintBoolean(SDL_HINT_OPENGL_ES_DRIVER, SDL_FALSE)
+ || _this->gl_config.major_version == 1 /* No GLX extension for OpenGL ES 1.x profiles. */
+ || _this->gl_config.major_version > _this->gl_data->es_profile_max_supported_version.major
+ || (_this->gl_config.major_version == _this->gl_data->es_profile_max_supported_version.major
+ && _this->gl_config.minor_version > _this->gl_data->es_profile_max_supported_version.minor));
+}
+
+SDL_GLContext
+X11_GL_CreateContext(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+ int screen =
+ ((SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata)->screen;
+ XWindowAttributes xattr;
+ XVisualInfo v, *vinfo;
+ int n;
+ GLXContext context = NULL, share_context;
+
+ if (_this->gl_config.share_with_current_context) {
+ share_context = (GLXContext)SDL_GL_GetCurrentContext();
+ } else {
+ share_context = NULL;
+ }
+
+ /* We do this to create a clean separation between X and GLX errors. */
+ X11_XSync(display, False);
+ errorHandlerOperation = "create GL context";
+ errorBase = _this->gl_data->errorBase;
+ errorCode = Success;
+ handler = X11_XSetErrorHandler(X11_GL_ErrorHandler);
+ X11_XGetWindowAttributes(display, data->xwindow, &xattr);
+ v.screen = screen;
+ v.visualid = X11_XVisualIDFromVisual(xattr.visual);
+ vinfo = X11_XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n);
+ if (vinfo) {
+ if (_this->gl_config.major_version < 3 &&
+ _this->gl_config.profile_mask == 0 &&
+ _this->gl_config.flags == 0) {
+ /* Create legacy context */
+ context =
+ _this->gl_data->glXCreateContext(display, vinfo, share_context, True);
+ } else {
+ /* max 14 attributes plus terminator */
+ int attribs[15] = {
+ GLX_CONTEXT_MAJOR_VERSION_ARB,
+ _this->gl_config.major_version,
+ GLX_CONTEXT_MINOR_VERSION_ARB,
+ _this->gl_config.minor_version,
+ 0
+ };
+ int iattr = 4;
+
+ /* SDL profile bits match GLX profile bits */
+ if( _this->gl_config.profile_mask != 0 ) {
+ attribs[iattr++] = GLX_CONTEXT_PROFILE_MASK_ARB;
+ attribs[iattr++] = _this->gl_config.profile_mask;
+ }
+
+ /* SDL flags match GLX flags */
+ if( _this->gl_config.flags != 0 ) {
+ attribs[iattr++] = GLX_CONTEXT_FLAGS_ARB;
+ attribs[iattr++] = _this->gl_config.flags;
+ }
+
+ /* only set if glx extension is available */
+ if( _this->gl_data->HAS_GLX_ARB_context_flush_control ) {
+ attribs[iattr++] = GLX_CONTEXT_RELEASE_BEHAVIOR_ARB;
+ attribs[iattr++] =
+ _this->gl_config.release_behavior ?
+ GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB :
+ GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB;
+ }
+
+ /* only set if glx extension is available */
+ if( _this->gl_data->HAS_GLX_ARB_create_context_robustness ) {
+ attribs[iattr++] = GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB;
+ attribs[iattr++] =
+ _this->gl_config.reset_notification ?
+ GLX_LOSE_CONTEXT_ON_RESET_ARB :
+ GLX_NO_RESET_NOTIFICATION_ARB;
+ }
+
+ /* only set if glx extension is available */
+ if( _this->gl_data->HAS_GLX_ARB_create_context_no_error ) {
+ attribs[iattr++] = GLX_CONTEXT_OPENGL_NO_ERROR_ARB;
+ attribs[iattr++] = _this->gl_config.no_error;
+ }
+
+ attribs[iattr++] = 0;
+
+ /* Get a pointer to the context creation function for GL 3.0 */
+ if (!_this->gl_data->glXCreateContextAttribsARB) {
+ SDL_SetError("OpenGL 3.0 and later are not supported by this system");
+ } else {
+ int glxAttribs[64];
+
+ /* Create a GL 3.x context */
+ GLXFBConfig *framebuffer_config = NULL;
+ int fbcount = 0;
+ int *pvistypeattr = NULL;
+
+ X11_GL_GetAttributes(_this,display,screen,glxAttribs,64,SDL_TRUE,&pvistypeattr);
+
+ if (_this->gl_data->glXChooseFBConfig) {
+ framebuffer_config = _this->gl_data->glXChooseFBConfig(display,
+ DefaultScreen(display), glxAttribs,
+ &fbcount);
+
+ if (!framebuffer_config && (pvistypeattr != NULL)) {
+ *pvistypeattr = None;
+ framebuffer_config = _this->gl_data->glXChooseFBConfig(display,
+ DefaultScreen(display), glxAttribs,
+ &fbcount);
+ }
+
+ if (framebuffer_config) {
+ context = _this->gl_data->glXCreateContextAttribsARB(display,
+ framebuffer_config[0],
+ share_context, True, attribs);
+ X11_XFree(framebuffer_config);
+ }
+ }
+ }
+ }
+ X11_XFree(vinfo);
+ }
+ X11_XSync(display, False);
+ X11_XSetErrorHandler(handler);
+
+ if (!context) {
+ if (errorCode == Success) {
+ SDL_SetError("Could not create GL context");
+ }
+ return NULL;
+ }
+
+ if (X11_GL_MakeCurrent(_this, window, context) < 0) {
+ X11_GL_DeleteContext(_this, context);
+ return NULL;
+ }
+
+ return context;
+}
+
+int
+X11_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
+{
+ Display *display = ((SDL_VideoData *) _this->driverdata)->display;
+ Window drawable =
+ (context ? ((SDL_WindowData *) window->driverdata)->xwindow : None);
+ GLXContext glx_context = (GLXContext) context;
+ int rc;
+
+ if (!_this->gl_data) {
+ return SDL_SetError("OpenGL not initialized");
+ }
+
+ /* We do this to create a clean separation between X and GLX errors. */
+ X11_XSync(display, False);
+ errorHandlerOperation = "make GL context current";
+ errorBase = _this->gl_data->errorBase;
+ errorCode = Success;
+ handler = X11_XSetErrorHandler(X11_GL_ErrorHandler);
+ rc = _this->gl_data->glXMakeCurrent(display, drawable, glx_context);
+ X11_XSetErrorHandler(handler);
+
+ if (errorCode != Success) { /* uhoh, an X error was thrown! */
+ return -1; /* the error handler called SDL_SetError() already. */
+ } else if (!rc) { /* glXMakeCurrent() failed without throwing an X error */
+ return SDL_SetError("Unable to make GL context current");
+ }
+
+ return 0;
+}
+
+/*
+ 0 is a valid argument to glXSwapInterval(MESA|EXT) and setting it to 0
+ will undo the effect of a previous call with a value that is greater
+ than zero (or at least that is what the docs say). OTOH, 0 is an invalid
+ argument to glXSwapIntervalSGI and it returns an error if you call it
+ with 0 as an argument.
+*/
+
+static int swapinterval = 0;
+int
+X11_GL_SetSwapInterval(_THIS, int interval)
+{
+ int status = -1;
+
+ if ((interval < 0) && (!_this->gl_data->HAS_GLX_EXT_swap_control_tear)) {
+ SDL_SetError("Negative swap interval unsupported in this GL");
+ } else if (_this->gl_data->glXSwapIntervalEXT) {
+ Display *display = ((SDL_VideoData *) _this->driverdata)->display;
+ const SDL_WindowData *windowdata = (SDL_WindowData *)
+ SDL_GL_GetCurrentWindow()->driverdata;
+
+ Window drawable = windowdata->xwindow;
+
+ /*
+ * This is a workaround for a bug in NVIDIA drivers. Bug has been reported
+ * and will be fixed in a future release (probably 319.xx).
+ *
+ * There's a bug where glXSetSwapIntervalEXT ignores updates because
+ * it has the wrong value cached. To work around it, we just run a no-op
+ * update to the current value.
+ */
+ int currentInterval = X11_GL_GetSwapInterval(_this);
+ _this->gl_data->glXSwapIntervalEXT(display, drawable, currentInterval);
+ _this->gl_data->glXSwapIntervalEXT(display, drawable, interval);
+
+ status = 0;
+ swapinterval = interval;
+ } else if (_this->gl_data->glXSwapIntervalMESA) {
+ status = _this->gl_data->glXSwapIntervalMESA(interval);
+ if (status != 0) {
+ SDL_SetError("glXSwapIntervalMESA failed");
+ } else {
+ swapinterval = interval;
+ }
+ } else if (_this->gl_data->glXSwapIntervalSGI) {
+ status = _this->gl_data->glXSwapIntervalSGI(interval);
+ if (status != 0) {
+ SDL_SetError("glXSwapIntervalSGI failed");
+ } else {
+ swapinterval = interval;
+ }
+ } else {
+ SDL_Unsupported();
+ }
+ return status;
+}
+
+int
+X11_GL_GetSwapInterval(_THIS)
+{
+ if (_this->gl_data->glXSwapIntervalEXT) {
+ Display *display = ((SDL_VideoData *) _this->driverdata)->display;
+ const SDL_WindowData *windowdata = (SDL_WindowData *)
+ SDL_GL_GetCurrentWindow()->driverdata;
+ Window drawable = windowdata->xwindow;
+ unsigned int allow_late_swap_tearing = 0;
+ unsigned int interval = 0;
+
+ if (_this->gl_data->HAS_GLX_EXT_swap_control_tear) {
+ _this->gl_data->glXQueryDrawable(display, drawable,
+ GLX_LATE_SWAPS_TEAR_EXT,
+ &allow_late_swap_tearing);
+ }
+
+ _this->gl_data->glXQueryDrawable(display, drawable,
+ GLX_SWAP_INTERVAL_EXT, &interval);
+
+ if ((allow_late_swap_tearing) && (interval > 0)) {
+ return -((int) interval);
+ }
+
+ return (int) interval;
+ } else if (_this->gl_data->glXGetSwapIntervalMESA) {
+ return _this->gl_data->glXGetSwapIntervalMESA();
+ } else {
+ return swapinterval;
+ }
+}
+
+int
+X11_GL_SwapWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+
+ _this->gl_data->glXSwapBuffers(display, data->xwindow);
+ return 0;
+}
+
+void
+X11_GL_DeleteContext(_THIS, SDL_GLContext context)
+{
+ Display *display = ((SDL_VideoData *) _this->driverdata)->display;
+ GLXContext glx_context = (GLXContext) context;
+
+ if (!_this->gl_data) {
+ return;
+ }
+ _this->gl_data->glXDestroyContext(display, glx_context);
+ X11_XSync(display, False);
+}
+
+#endif /* SDL_VIDEO_OPENGL_GLX */
+
+#endif /* SDL_VIDEO_DRIVER_X11 */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11opengl.h b/src/3rdparty/SDL2/src/video/x11/SDL_x11opengl.h
new file mode 100644
index 0000000..1a26ea0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11opengl.h
@@ -0,0 +1,84 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_x11opengl_h_
+#define SDL_x11opengl_h_
+
+#if SDL_VIDEO_OPENGL_GLX
+#include "SDL_opengl.h"
+#include <GL/glx.h>
+
+struct SDL_GLDriverData
+{
+ int errorBase, eventBase;
+
+ SDL_bool HAS_GLX_EXT_visual_rating;
+ SDL_bool HAS_GLX_EXT_visual_info;
+ SDL_bool HAS_GLX_EXT_swap_control_tear;
+ SDL_bool HAS_GLX_ARB_context_flush_control;
+ SDL_bool HAS_GLX_ARB_create_context_robustness;
+ SDL_bool HAS_GLX_ARB_create_context_no_error;
+
+ /* Max version of OpenGL ES context that can be created if the
+ implementation supports GLX_EXT_create_context_es2_profile.
+ major = minor = 0 when unsupported.
+ */
+ struct {
+ int major;
+ int minor;
+ } es_profile_max_supported_version;
+
+ Bool (*glXQueryExtension) (Display*,int*,int*);
+ void *(*glXGetProcAddress) (const GLubyte*);
+ XVisualInfo *(*glXChooseVisual) (Display*,int,int*);
+ GLXContext (*glXCreateContext) (Display*,XVisualInfo*,GLXContext,Bool);
+ GLXContext (*glXCreateContextAttribsARB) (Display*,GLXFBConfig,GLXContext,Bool,const int *);
+ GLXFBConfig *(*glXChooseFBConfig) (Display*,int,const int *,int *);
+ void (*glXDestroyContext) (Display*, GLXContext);
+ Bool(*glXMakeCurrent) (Display*,GLXDrawable,GLXContext);
+ void (*glXSwapBuffers) (Display*, GLXDrawable);
+ void (*glXQueryDrawable) (Display*,GLXDrawable,int,unsigned int*);
+ void (*glXSwapIntervalEXT) (Display*,GLXDrawable,int);
+ int (*glXSwapIntervalSGI) (int);
+ int (*glXSwapIntervalMESA) (int);
+ int (*glXGetSwapIntervalMESA) (void);
+};
+
+/* OpenGL functions */
+extern int X11_GL_LoadLibrary(_THIS, const char *path);
+extern void *X11_GL_GetProcAddress(_THIS, const char *proc);
+extern void X11_GL_UnloadLibrary(_THIS);
+extern SDL_bool X11_GL_UseEGL(_THIS);
+extern XVisualInfo *X11_GL_GetVisual(_THIS, Display * display, int screen);
+extern SDL_GLContext X11_GL_CreateContext(_THIS, SDL_Window * window);
+extern int X11_GL_MakeCurrent(_THIS, SDL_Window * window,
+ SDL_GLContext context);
+extern int X11_GL_SetSwapInterval(_THIS, int interval);
+extern int X11_GL_GetSwapInterval(_THIS);
+extern int X11_GL_SwapWindow(_THIS, SDL_Window * window);
+extern void X11_GL_DeleteContext(_THIS, SDL_GLContext context);
+
+#endif /* SDL_VIDEO_OPENGL_GLX */
+
+#endif /* SDL_x11opengl_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11opengles.c b/src/3rdparty/SDL2/src/video/x11/SDL_x11opengles.c
new file mode 100644
index 0000000..76b6cd7
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11opengles.c
@@ -0,0 +1,109 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_X11 && SDL_VIDEO_OPENGL_EGL
+
+#include "SDL_x11video.h"
+#include "SDL_x11opengles.h"
+#include "SDL_x11opengl.h"
+
+/* EGL implementation of SDL OpenGL support */
+
+int
+X11_GLES_LoadLibrary(_THIS, const char *path)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
+ /* If the profile requested is not GL ES, switch over to X11_GL functions */
+ if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
+ #if SDL_VIDEO_OPENGL_GLX
+ X11_GLES_UnloadLibrary(_this);
+ _this->GL_LoadLibrary = X11_GL_LoadLibrary;
+ _this->GL_GetProcAddress = X11_GL_GetProcAddress;
+ _this->GL_UnloadLibrary = X11_GL_UnloadLibrary;
+ _this->GL_CreateContext = X11_GL_CreateContext;
+ _this->GL_MakeCurrent = X11_GL_MakeCurrent;
+ _this->GL_SetSwapInterval = X11_GL_SetSwapInterval;
+ _this->GL_GetSwapInterval = X11_GL_GetSwapInterval;
+ _this->GL_SwapWindow = X11_GL_SwapWindow;
+ _this->GL_DeleteContext = X11_GL_DeleteContext;
+ return X11_GL_LoadLibrary(_this, path);
+ #else
+ return SDL_SetError("SDL not configured with OpenGL/GLX support");
+ #endif
+ }
+
+ return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) data->display, 0);
+}
+
+XVisualInfo *
+X11_GLES_GetVisual(_THIS, Display * display, int screen)
+{
+
+ XVisualInfo *egl_visualinfo = NULL;
+ EGLint visual_id;
+ XVisualInfo vi_in;
+ int out_count;
+
+ if (!_this->egl_data) {
+ /* The EGL library wasn't loaded, SDL_GetError() should have info */
+ return NULL;
+ }
+
+ if (_this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display,
+ _this->egl_data->egl_config,
+ EGL_NATIVE_VISUAL_ID,
+ &visual_id) == EGL_FALSE || !visual_id) {
+ /* Use the default visual when all else fails */
+ vi_in.screen = screen;
+ egl_visualinfo = X11_XGetVisualInfo(display,
+ VisualScreenMask,
+ &vi_in, &out_count);
+ } else {
+ vi_in.screen = screen;
+ vi_in.visualid = visual_id;
+ egl_visualinfo = X11_XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &vi_in, &out_count);
+ }
+
+ return egl_visualinfo;
+}
+
+SDL_GLContext
+X11_GLES_CreateContext(_THIS, SDL_Window * window)
+{
+ SDL_GLContext context;
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+
+ X11_XSync(display, False);
+ context = SDL_EGL_CreateContext(_this, data->egl_surface);
+ X11_XSync(display, False);
+
+ return context;
+}
+
+SDL_EGL_SwapWindow_impl(X11)
+SDL_EGL_MakeCurrent_impl(X11)
+
+#endif /* SDL_VIDEO_DRIVER_X11 && SDL_VIDEO_OPENGL_EGL */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11opengles.h b/src/3rdparty/SDL2/src/video/x11/SDL_x11opengles.h
new file mode 100644
index 0000000..b189b76
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11opengles.h
@@ -0,0 +1,56 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_x11opengles_h_
+#define SDL_x11opengles_h_
+
+#if SDL_VIDEO_OPENGL_EGL
+
+#include "../SDL_sysvideo.h"
+#include "../SDL_egl_c.h"
+
+typedef struct SDL_PrivateGLESData
+{
+ /* 1401 If the struct-declaration-list contains no named members, the behavior is undefined. */
+ /* warning: empty struct has size 0 in C, size 1 in C++ [-Wc++-compat] */
+ int dummy;
+} SDL_PrivateGLESData;
+
+/* OpenGLES functions */
+#define X11_GLES_GetAttribute SDL_EGL_GetAttribute
+#define X11_GLES_GetProcAddress SDL_EGL_GetProcAddress
+#define X11_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
+#define X11_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
+#define X11_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
+#define X11_GLES_DeleteContext SDL_EGL_DeleteContext
+
+extern int X11_GLES_LoadLibrary(_THIS, const char *path);
+extern XVisualInfo *X11_GLES_GetVisual(_THIS, Display * display, int screen);
+extern SDL_GLContext X11_GLES_CreateContext(_THIS, SDL_Window * window);
+extern int X11_GLES_SwapWindow(_THIS, SDL_Window * window);
+extern int X11_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+
+#endif /* SDL_VIDEO_OPENGL_EGL */
+
+#endif /* SDL_x11opengles_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11shape.c b/src/3rdparty/SDL2/src/video/x11/SDL_x11shape.c
new file mode 100644
index 0000000..4d68fe0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11shape.c
@@ -0,0 +1,115 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_X11
+
+#include "SDL_assert.h"
+#include "SDL_x11video.h"
+#include "SDL_x11shape.h"
+#include "SDL_x11window.h"
+#include "../SDL_shape_internals.h"
+
+SDL_WindowShaper*
+X11_CreateShaper(SDL_Window* window) {
+ SDL_WindowShaper* result = NULL;
+ SDL_ShapeData* data = NULL;
+ int resized_properly;
+
+#if SDL_VIDEO_DRIVER_X11_XSHAPE
+ if (SDL_X11_HAVE_XSHAPE) { /* Make sure X server supports it. */
+ result = malloc(sizeof(SDL_WindowShaper));
+ result->window = window;
+ result->mode.mode = ShapeModeDefault;
+ result->mode.parameters.binarizationCutoff = 1;
+ result->userx = result->usery = 0;
+ data = SDL_malloc(sizeof(SDL_ShapeData));
+ result->driverdata = data;
+ data->bitmapsize = 0;
+ data->bitmap = NULL;
+ window->shaper = result;
+ resized_properly = X11_ResizeWindowShape(window);
+ SDL_assert(resized_properly == 0);
+ }
+#endif
+
+ return result;
+}
+
+int
+X11_ResizeWindowShape(SDL_Window* window) {
+ SDL_ShapeData* data = window->shaper->driverdata;
+ unsigned int bitmapsize = window->w / 8;
+ SDL_assert(data != NULL);
+
+ if(window->w % 8 > 0)
+ bitmapsize += 1;
+ bitmapsize *= window->h;
+ if(data->bitmapsize != bitmapsize || data->bitmap == NULL) {
+ data->bitmapsize = bitmapsize;
+ if(data->bitmap != NULL)
+ free(data->bitmap);
+ data->bitmap = malloc(data->bitmapsize);
+ if(data->bitmap == NULL) {
+ return SDL_SetError("Could not allocate memory for shaped-window bitmap.");
+ }
+ }
+ memset(data->bitmap,0,data->bitmapsize);
+
+ window->shaper->userx = window->x;
+ window->shaper->usery = window->y;
+ SDL_SetWindowPosition(window,-1000,-1000);
+
+ return 0;
+}
+
+int
+X11_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
+ SDL_ShapeData *data = NULL;
+ SDL_WindowData *windowdata = NULL;
+ Pixmap shapemask;
+
+ if(shaper == NULL || shape == NULL || shaper->driverdata == NULL)
+ return -1;
+
+#if SDL_VIDEO_DRIVER_X11_XSHAPE
+ if(shape->format->Amask == 0 && SDL_SHAPEMODEALPHA(shape_mode->mode))
+ return -2;
+ if(shape->w != shaper->window->w || shape->h != shaper->window->h)
+ return -3;
+ data = shaper->driverdata;
+
+ /* Assume that shaper->alphacutoff already has a value, because SDL_SetWindowShape() should have given it one. */
+ SDL_CalculateShapeBitmap(shaper->mode,shape,data->bitmap,8);
+
+ windowdata = (SDL_WindowData*)(shaper->window->driverdata);
+ shapemask = X11_XCreateBitmapFromData(windowdata->videodata->display,windowdata->xwindow,data->bitmap,shaper->window->w,shaper->window->h);
+
+ X11_XShapeCombineMask(windowdata->videodata->display,windowdata->xwindow, ShapeBounding, 0, 0,shapemask, ShapeSet);
+ X11_XSync(windowdata->videodata->display,False);
+
+ X11_XFreePixmap(windowdata->videodata->display,shapemask);
+#endif
+
+ return 0;
+}
+
+#endif /* SDL_VIDEO_DRIVER_X11 */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11shape.h b/src/3rdparty/SDL2/src/video/x11/SDL_x11shape.h
new file mode 100644
index 0000000..a8c2e2c
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11shape.h
@@ -0,0 +1,39 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_x11shape_h_
+#define SDL_x11shape_h_
+
+#include "SDL_video.h"
+#include "SDL_shape.h"
+#include "../SDL_sysvideo.h"
+
+typedef struct {
+ void* bitmap;
+ Uint32 bitmapsize;
+} SDL_ShapeData;
+
+extern SDL_WindowShaper* X11_CreateShaper(SDL_Window* window);
+extern int X11_ResizeWindowShape(SDL_Window* window);
+extern int X11_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode);
+
+#endif /* SDL_x11shape_h_ */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11sym.h b/src/3rdparty/SDL2/src/video/x11/SDL_x11sym.h
new file mode 100644
index 0000000..a07a030
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11sym.h
@@ -0,0 +1,337 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+/* *INDENT-OFF* */
+
+#ifndef SDL_X11_MODULE
+#define SDL_X11_MODULE(modname)
+#endif
+
+#ifndef SDL_X11_SYM
+#define SDL_X11_SYM(rc,fn,params,args,ret)
+#endif
+
+SDL_X11_MODULE(BASEXLIB)
+SDL_X11_SYM(XSizeHints*,XAllocSizeHints,(void),(),return)
+SDL_X11_SYM(XWMHints*,XAllocWMHints,(void),(),return)
+SDL_X11_SYM(XClassHint*,XAllocClassHint,(void),(),return)
+SDL_X11_SYM(int,XAutoRepeatOn,(Display* a),(a),return)
+SDL_X11_SYM(int,XAutoRepeatOff,(Display* a),(a),return)
+SDL_X11_SYM(int,XChangePointerControl,(Display* a,Bool b,Bool c,int d,int e,int f),(a,b,c,d,e,f),return)
+SDL_X11_SYM(int,XChangeProperty,(Display* a,Window b,Atom c,Atom d,int e,int f,_Xconst unsigned char* g,int h),(a,b,c,d,e,f,g,h),return)
+SDL_X11_SYM(Bool,XCheckIfEvent,(Display* a,XEvent *b,Bool (*c)(Display*,XEvent*,XPointer),XPointer d),(a,b,c,d),return)
+SDL_X11_SYM(int,XClearWindow,(Display* a,Window b),(a,b),return)
+SDL_X11_SYM(int,XCloseDisplay,(Display* a),(a),return)
+SDL_X11_SYM(int,XConvertSelection,(Display* a,Atom b,Atom c,Atom d,Window e,Time f),(a,b,c,d,e,f),return)
+SDL_X11_SYM(Pixmap,XCreateBitmapFromData,(Display *dpy,Drawable d,_Xconst char *data,unsigned int width,unsigned int height),(dpy,d,data,width,height),return)
+SDL_X11_SYM(Colormap,XCreateColormap,(Display* a,Window b,Visual* c,int d),(a,b,c,d),return)
+SDL_X11_SYM(Cursor,XCreatePixmapCursor,(Display* a,Pixmap b,Pixmap c,XColor* d,XColor* e,unsigned int f,unsigned int g),(a,b,c,d,e,f,g),return)
+SDL_X11_SYM(Cursor,XCreateFontCursor,(Display* a,unsigned int b),(a,b),return)
+SDL_X11_SYM(XFontSet,XCreateFontSet,(Display* a, _Xconst char* b, char*** c, int* d, char** e),(a,b,c,d,e),return)
+SDL_X11_SYM(GC,XCreateGC,(Display* a,Drawable b,unsigned long c,XGCValues* d),(a,b,c,d),return)
+SDL_X11_SYM(XImage*,XCreateImage,(Display* a,Visual* b,unsigned int c,int d,int e,char* f,unsigned int g,unsigned int h,int i,int j),(a,b,c,d,e,f,g,h,i,j),return)
+SDL_X11_SYM(Window,XCreateWindow,(Display* a,Window b,int c,int d,unsigned int e,unsigned int f,unsigned int g,int h,unsigned int i,Visual* j,unsigned long k,XSetWindowAttributes* l),(a,b,c,d,e,f,g,h,i,j,k,l),return)
+SDL_X11_SYM(int,XDefineCursor,(Display* a,Window b,Cursor c),(a,b,c),return)
+SDL_X11_SYM(int,XDeleteProperty,(Display* a,Window b,Atom c),(a,b,c),return)
+SDL_X11_SYM(int,XDestroyWindow,(Display* a,Window b),(a,b),return)
+SDL_X11_SYM(int,XDisplayKeycodes,(Display* a,int* b,int* c),(a,b,c),return)
+SDL_X11_SYM(int,XDrawRectangle,(Display* a,Drawable b,GC c,int d,int e,unsigned int f,unsigned int g),(a,b,c,d,e,f,g),return)
+SDL_X11_SYM(char*,XDisplayName,(_Xconst char* a),(a),return)
+SDL_X11_SYM(int,XDrawString,(Display* a,Drawable b,GC c,int d,int e,_Xconst char* f,int g),(a,b,c,d,e,f,g),return)
+SDL_X11_SYM(int,XEventsQueued,(Display* a,int b),(a,b),return)
+SDL_X11_SYM(int,XFillRectangle,(Display* a,Drawable b,GC c,int d,int e,unsigned int f,unsigned int g),(a,b,c,d,e,f,g),return)
+SDL_X11_SYM(Bool,XFilterEvent,(XEvent *event,Window w),(event,w),return)
+SDL_X11_SYM(int,XFlush,(Display* a),(a),return)
+SDL_X11_SYM(int,XFree,(void*a),(a),return)
+SDL_X11_SYM(int,XFreeCursor,(Display* a,Cursor b),(a,b),return)
+SDL_X11_SYM(void,XFreeFontSet,(Display* a, XFontSet b),(a,b),)
+SDL_X11_SYM(int,XFreeGC,(Display* a,GC b),(a,b),return)
+SDL_X11_SYM(int,XFreeFont,(Display* a, XFontStruct* b),(a,b),return)
+SDL_X11_SYM(int,XFreeModifiermap,(XModifierKeymap* a),(a),return)
+SDL_X11_SYM(int,XFreePixmap,(Display* a,Pixmap b),(a,b),return)
+SDL_X11_SYM(void,XFreeStringList,(char** a),(a),)
+SDL_X11_SYM(char*,XGetAtomName,(Display *a,Atom b),(a,b),return)
+SDL_X11_SYM(int,XGetInputFocus,(Display *a,Window *b,int *c),(a,b,c),return)
+SDL_X11_SYM(int,XGetErrorDatabaseText,(Display* a,_Xconst char* b,_Xconst char* c,_Xconst char* d,char* e,int f),(a,b,c,d,e,f),return)
+SDL_X11_SYM(XModifierKeymap*,XGetModifierMapping,(Display* a),(a),return)
+SDL_X11_SYM(int,XGetPointerControl,(Display* a,int* b,int* c,int* d),(a,b,c,d),return)
+SDL_X11_SYM(Window,XGetSelectionOwner,(Display* a,Atom b),(a,b),return)
+SDL_X11_SYM(XVisualInfo*,XGetVisualInfo,(Display* a,long b,XVisualInfo* c,int* d),(a,b,c,d),return)
+SDL_X11_SYM(Status,XGetWindowAttributes,(Display* a,Window b,XWindowAttributes* c),(a,b,c),return)
+SDL_X11_SYM(int,XGetWindowProperty,(Display* a,Window b,Atom c,long d,long e,Bool f,Atom g,Atom* h,int* i,unsigned long* j,unsigned long *k,unsigned char **l),(a,b,c,d,e,f,g,h,i,j,k,l),return)
+SDL_X11_SYM(XWMHints*,XGetWMHints,(Display* a,Window b),(a,b),return)
+SDL_X11_SYM(Status,XGetWMNormalHints,(Display *a,Window b, XSizeHints *c, long *d),(a,b,c,d),return)
+SDL_X11_SYM(int,XIfEvent,(Display* a,XEvent *b,Bool (*c)(Display*,XEvent*,XPointer),XPointer d),(a,b,c,d),return)
+SDL_X11_SYM(int,XGrabKeyboard,(Display* a,Window b,Bool c,int d,int e,Time f),(a,b,c,d,e,f),return)
+SDL_X11_SYM(int,XGrabPointer,(Display* a,Window b,Bool c,unsigned int d,int e,int f,Window g,Cursor h,Time i),(a,b,c,d,e,f,g,h,i),return)
+SDL_X11_SYM(int,XGrabServer,(Display* a),(a),return)
+SDL_X11_SYM(Status,XIconifyWindow,(Display* a,Window b,int c),(a,b,c),return)
+SDL_X11_SYM(KeyCode,XKeysymToKeycode,(Display* a,KeySym b),(a,b),return)
+SDL_X11_SYM(char*,XKeysymToString,(KeySym a),(a),return)
+SDL_X11_SYM(int,XInstallColormap,(Display* a,Colormap b),(a,b),return)
+SDL_X11_SYM(Atom,XInternAtom,(Display* a,_Xconst char* b,Bool c),(a,b,c),return)
+SDL_X11_SYM(XPixmapFormatValues*,XListPixmapFormats,(Display* a,int* b),(a,b),return)
+SDL_X11_SYM(XFontStruct*,XLoadQueryFont,(Display* a,_Xconst char* b),(a,b),return)
+SDL_X11_SYM(KeySym,XLookupKeysym,(XKeyEvent* a,int b),(a,b),return)
+SDL_X11_SYM(int,XLookupString,(XKeyEvent* a,char* b,int c,KeySym* d,XComposeStatus* e),(a,b,c,d,e),return)
+SDL_X11_SYM(int,XMapRaised,(Display* a,Window b),(a,b),return)
+SDL_X11_SYM(Status,XMatchVisualInfo,(Display* a,int b,int c,int d,XVisualInfo* e),(a,b,c,d,e),return)
+SDL_X11_SYM(int,XMissingExtension,(Display* a,_Xconst char* b),(a,b),return)
+SDL_X11_SYM(int,XMoveWindow,(Display* a,Window b,int c,int d),(a,b,c,d),return)
+SDL_X11_SYM(int,XNextEvent,(Display* a,XEvent* b),(a,b),return)
+SDL_X11_SYM(Display*,XOpenDisplay,(_Xconst char* a),(a),return)
+SDL_X11_SYM(Status,XInitThreads,(void),(),return)
+SDL_X11_SYM(int,XPeekEvent,(Display* a,XEvent* b),(a,b),return)
+SDL_X11_SYM(int,XPending,(Display* a),(a),return)
+SDL_X11_SYM(int,XPutImage,(Display* a,Drawable b,GC c,XImage* d,int e,int f,int g,int h,unsigned int i,unsigned int j),(a,b,c,d,e,f,g,h,i,j),return)
+SDL_X11_SYM(int,XQueryKeymap,(Display* a,char *b),(a,b),return)
+SDL_X11_SYM(Bool,XQueryPointer,(Display* a,Window b,Window* c,Window* d,int* e,int* f,int* g,int* h,unsigned int* i),(a,b,c,d,e,f,g,h,i),return)
+SDL_X11_SYM(int,XRaiseWindow,(Display* a,Window b),(a,b),return)
+SDL_X11_SYM(int,XReparentWindow,(Display* a,Window b,Window c,int d,int e),(a,b,c,d,e),return)
+SDL_X11_SYM(int,XResetScreenSaver,(Display* a),(a),return)
+SDL_X11_SYM(int,XResizeWindow,(Display* a,Window b,unsigned int c,unsigned int d),(a,b,c,d),return)
+SDL_X11_SYM(int,XSelectInput,(Display* a,Window b,long c),(a,b,c),return)
+SDL_X11_SYM(Status,XSendEvent,(Display* a,Window b,Bool c,long d,XEvent* e),(a,b,c,d,e),return)
+SDL_X11_SYM(XErrorHandler,XSetErrorHandler,(XErrorHandler a),(a),return)
+SDL_X11_SYM(int,XSetForeground,(Display* a,GC b,unsigned long c),(a,b,c),return)
+SDL_X11_SYM(XIOErrorHandler,XSetIOErrorHandler,(XIOErrorHandler a),(a),return)
+SDL_X11_SYM(int,XSetInputFocus,(Display *a,Window b,int c,Time d),(a,b,c,d),return)
+SDL_X11_SYM(int,XSetSelectionOwner,(Display* a,Atom b,Window c,Time d),(a,b,c,d),return)
+SDL_X11_SYM(int,XSetTransientForHint,(Display* a,Window b,Window c),(a,b,c),return)
+SDL_X11_SYM(void,XSetTextProperty,(Display* a,Window b,XTextProperty* c,Atom d),(a,b,c,d),)
+SDL_X11_SYM(int,XSetWindowBackground,(Display* a,Window b,unsigned long c),(a,b,c),return)
+SDL_X11_SYM(void,XSetWMProperties,(Display* a,Window b,XTextProperty* c,XTextProperty* d,char** e,int f,XSizeHints* g,XWMHints* h,XClassHint* i),(a,b,c,d,e,f,g,h,i),)
+SDL_X11_SYM(void,XSetWMNormalHints,(Display* a,Window b,XSizeHints* c),(a,b,c),)
+SDL_X11_SYM(Status,XSetWMProtocols,(Display* a,Window b,Atom* c,int d),(a,b,c,d),return)
+SDL_X11_SYM(int,XStoreColors,(Display* a,Colormap b,XColor* c,int d),(a,b,c,d),return)
+SDL_X11_SYM(int,XStoreName,(Display* a,Window b,_Xconst char* c),(a,b,c),return)
+SDL_X11_SYM(Status,XStringListToTextProperty,(char** a,int b,XTextProperty* c),(a,b,c),return)
+SDL_X11_SYM(int,XSync,(Display* a,Bool b),(a,b),return)
+SDL_X11_SYM(int,XTextExtents,(XFontStruct* a,_Xconst char* b,int c,int* d,int* e,int* f,XCharStruct* g),(a,b,c,d,e,f,g),return)
+SDL_X11_SYM(Bool,XTranslateCoordinates,(Display *a,Window b,Window c,int d,int e,int* f,int* g,Window* h),(a,b,c,d,e,f,g,h),return)
+SDL_X11_SYM(int,XUndefineCursor,(Display* a,Window b),(a,b),return)
+SDL_X11_SYM(int,XUngrabKeyboard,(Display* a,Time b),(a,b),return)
+SDL_X11_SYM(int,XUngrabPointer,(Display* a,Time b),(a,b),return)
+SDL_X11_SYM(int,XUngrabServer,(Display* a),(a),return)
+SDL_X11_SYM(int,XUninstallColormap,(Display* a,Colormap b),(a,b),return)
+SDL_X11_SYM(int,XUnloadFont,(Display* a,Font b),(a,b),return)
+SDL_X11_SYM(int,XWarpPointer,(Display* a,Window b,Window c,int d,int e,unsigned int f,unsigned int g,int h,int i),(a,b,c,d,e,f,g,h,i),return)
+SDL_X11_SYM(int,XWindowEvent,(Display* a,Window b,long c,XEvent* d),(a,b,c,d),return)
+SDL_X11_SYM(Status,XWithdrawWindow,(Display* a,Window b,int c),(a,b,c),return)
+SDL_X11_SYM(VisualID,XVisualIDFromVisual,(Visual* a),(a),return)
+#if SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY
+SDL_X11_SYM(XExtDisplayInfo*,XextAddDisplay,(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f),(a,b,c,d,e,f),return)
+#else
+SDL_X11_SYM(XExtDisplayInfo*,XextAddDisplay,(XExtensionInfo* a,Display* b,char* c,XExtensionHooks* d,int e,XPointer f),(a,b,c,d,e,f),return)
+#endif
+SDL_X11_SYM(XExtensionInfo*,XextCreateExtension,(void),(),return)
+SDL_X11_SYM(void,XextDestroyExtension,(XExtensionInfo* a),(a),)
+SDL_X11_SYM(XExtDisplayInfo*,XextFindDisplay,(XExtensionInfo* a,Display* b),(a,b),return)
+SDL_X11_SYM(int,XextRemoveDisplay,(XExtensionInfo* a,Display* b),(a,b),return)
+SDL_X11_SYM(Bool,XQueryExtension,(Display* a,_Xconst char* b,int* c,int* d,int* e),(a,b,c,d,e),return)
+SDL_X11_SYM(char *,XDisplayString,(Display* a),(a),return)
+SDL_X11_SYM(int,XGetErrorText,(Display* a,int b,char* c,int d),(a,b,c,d),return)
+SDL_X11_SYM(void,_XEatData,(Display* a,unsigned long b),(a,b),)
+SDL_X11_SYM(void,_XFlush,(Display* a),(a),)
+SDL_X11_SYM(void,_XFlushGCCache,(Display* a,GC b),(a,b),)
+SDL_X11_SYM(int,_XRead,(Display* a,char* b,long c),(a,b,c),return)
+SDL_X11_SYM(void,_XReadPad,(Display* a,char* b,long c),(a,b,c),)
+SDL_X11_SYM(void,_XSend,(Display* a,_Xconst char* b,long c),(a,b,c),)
+SDL_X11_SYM(Status,_XReply,(Display* a,xReply* b,int c,Bool d),(a,b,c,d),return)
+SDL_X11_SYM(unsigned long,_XSetLastRequestRead,(Display* a,xGenericReply* b),(a,b),return)
+SDL_X11_SYM(SDL_X11_XSynchronizeRetType,XSynchronize,(Display* a,Bool b),(a,b),return)
+SDL_X11_SYM(SDL_X11_XESetWireToEventRetType,XESetWireToEvent,(Display* a,int b,SDL_X11_XESetWireToEventRetType c),(a,b,c),return)
+SDL_X11_SYM(SDL_X11_XESetEventToWireRetType,XESetEventToWire,(Display* a,int b,SDL_X11_XESetEventToWireRetType c),(a,b,c),return)
+SDL_X11_SYM(void,XRefreshKeyboardMapping,(XMappingEvent *a),(a),)
+SDL_X11_SYM(int,XQueryTree,(Display* a,Window b,Window* c,Window* d,Window** e,unsigned int* f),(a,b,c,d,e,f),return)
+
+#if SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
+SDL_X11_SYM(Bool,XGetEventData,(Display* a,XGenericEventCookie* b),(a,b),return)
+SDL_X11_SYM(void,XFreeEventData,(Display* a,XGenericEventCookie* b),(a,b),)
+#endif
+
+#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
+SDL_X11_SYM(Bool,XkbQueryExtension,(Display* a,int * b,int * c,int * d,int * e, int *f),(a,b,c,d,e,f),return)
+#if NeedWidePrototypes
+SDL_X11_SYM(KeySym,XkbKeycodeToKeysym,(Display* a,unsigned int b,int c,int d),(a,b,c,d),return)
+#else
+SDL_X11_SYM(KeySym,XkbKeycodeToKeysym,(Display* a,KeyCode b,int c,int d),(a,b,c,d),return)
+#endif
+SDL_X11_SYM(Status,XkbGetState,(Display* a,unsigned int b,XkbStatePtr c),(a,b,c),return)
+SDL_X11_SYM(Status,XkbGetUpdatedMap,(Display* a,unsigned int b,XkbDescPtr c),(a,b,c),return)
+SDL_X11_SYM(XkbDescPtr,XkbGetMap,(Display* a,unsigned int b,unsigned int c),(a,b,c),return)
+SDL_X11_SYM(void,XkbFreeClientMap,(XkbDescPtr a,unsigned int b, Bool c),(a,b,c),)
+SDL_X11_SYM(void,XkbFreeKeyboard,(XkbDescPtr a,unsigned int b, Bool c),(a,b,c),)
+SDL_X11_SYM(BOOL,XkbSetDetectableAutoRepeat,(Display* a, BOOL b, BOOL* c),(a,b,c),return)
+#endif
+
+#if NeedWidePrototypes
+SDL_X11_SYM(KeySym,XKeycodeToKeysym,(Display* a,unsigned int b,int c),(a,b,c),return)
+#else
+SDL_X11_SYM(KeySym,XKeycodeToKeysym,(Display* a,KeyCode b,int c),(a,b,c),return)
+#endif
+
+#ifdef X_HAVE_UTF8_STRING
+SDL_X11_MODULE(UTF8)
+SDL_X11_SYM(int,Xutf8TextListToTextProperty,(Display* a,char** b,int c,XICCEncodingStyle d,XTextProperty* e),(a,b,c,d,e),return)
+SDL_X11_SYM(int,Xutf8LookupString,(XIC a,XKeyPressedEvent* b,char* c,int d,KeySym* e,Status* f),(a,b,c,d,e,f),return)
+/* SDL_X11_SYM(XIC,XCreateIC,(XIM, ...),return) !!! ARGH! */
+SDL_X11_SYM(void,XDestroyIC,(XIC a),(a),)
+/* SDL_X11_SYM(char*,XGetICValues,(XIC, ...),return) !!! ARGH! */
+SDL_X11_SYM(void,XSetICFocus,(XIC a),(a),)
+SDL_X11_SYM(void,XUnsetICFocus,(XIC a),(a),)
+SDL_X11_SYM(XIM,XOpenIM,(Display* a,struct _XrmHashBucketRec* b,char* c,char* d),(a,b,c,d),return)
+SDL_X11_SYM(Status,XCloseIM,(XIM a),(a),return)
+SDL_X11_SYM(void,Xutf8DrawString,(Display *a, Drawable b, XFontSet c, GC d, int e, int f, _Xconst char *g, int h),(a,b,c,d,e,f,g,h),)
+SDL_X11_SYM(int,Xutf8TextExtents,(XFontSet a, _Xconst char* b, int c, XRectangle* d, XRectangle* e),(a,b,c,d,e),return)
+SDL_X11_SYM(char*,XSetLocaleModifiers,(const char *a),(a),return)
+SDL_X11_SYM(char*,Xutf8ResetIC,(XIC a),(a),return)
+#endif
+
+#ifndef NO_SHARED_MEMORY
+SDL_X11_MODULE(SHM)
+SDL_X11_SYM(Status,XShmAttach,(Display* a,XShmSegmentInfo* b),(a,b),return)
+SDL_X11_SYM(Status,XShmDetach,(Display* a,XShmSegmentInfo* b),(a,b),return)
+SDL_X11_SYM(Status,XShmPutImage,(Display* a,Drawable b,GC c,XImage* d,int e,int f,int g,int h,unsigned int i,unsigned int j,Bool k),(a,b,c,d,e,f,g,h,i,j,k),return)
+SDL_X11_SYM(XImage*,XShmCreateImage,(Display* a,Visual* b,unsigned int c,int d,char* e,XShmSegmentInfo* f,unsigned int g,unsigned int h),(a,b,c,d,e,f,g,h),return)
+SDL_X11_SYM(Pixmap,XShmCreatePixmap,(Display *a,Drawable b,char* c,XShmSegmentInfo* d, unsigned int e, unsigned int f, unsigned int g),(a,b,c,d,e,f,g),return)
+SDL_X11_SYM(Bool,XShmQueryExtension,(Display* a),(a),return)
+#endif
+
+/*
+ * Not required...these only exist in code in headers on some 64-bit platforms,
+ * and are removed via macros elsewhere, so it's safe for them to be missing.
+ */
+#ifdef LONG64
+SDL_X11_MODULE(IO_32BIT)
+SDL_X11_SYM(int,_XData32,(Display *dpy,register _Xconst long *data,unsigned len),(dpy,data,len),return)
+SDL_X11_SYM(void,_XRead32,(Display *dpy,register long *data,long len),(dpy,data,len),)
+#endif
+
+/*
+ * These only show up on some variants of Unix.
+ */
+#if defined(__osf__)
+SDL_X11_MODULE(OSF_ENTRY_POINTS)
+SDL_X11_SYM(void,_SmtBufferOverflow,(Display *dpy,register smtDisplayPtr p),(dpy,p),)
+SDL_X11_SYM(void,_SmtIpError,(Display *dpy,register smtDisplayPtr p,int i),(dpy,p,i),)
+SDL_X11_SYM(int,ipAllocateData,(ChannelPtr a,IPCard b,IPDataPtr * c),(a,b,c),return)
+SDL_X11_SYM(int,ipUnallocateAndSendData,(ChannelPtr a,IPCard b),(a,b),return)
+#endif
+
+/* XCursor support */
+#if SDL_VIDEO_DRIVER_X11_XCURSOR
+SDL_X11_MODULE(XCURSOR)
+SDL_X11_SYM(XcursorImage*,XcursorImageCreate,(int a,int b),(a,b),return)
+SDL_X11_SYM(void,XcursorImageDestroy,(XcursorImage *a),(a),)
+SDL_X11_SYM(Cursor,XcursorImageLoadCursor,(Display *a,const XcursorImage *b),(a,b),return)
+#endif
+
+/* Xdbe support */
+#if SDL_VIDEO_DRIVER_X11_XDBE
+SDL_X11_MODULE(XDBE)
+SDL_X11_SYM(Status,XdbeQueryExtension,(Display *dpy,int *major_version_return,int *minor_version_return),(dpy,major_version_return,minor_version_return),return)
+SDL_X11_SYM(XdbeBackBuffer,XdbeAllocateBackBufferName,(Display *dpy,Window window,XdbeSwapAction swap_action),(dpy,window,swap_action),return)
+SDL_X11_SYM(Status,XdbeDeallocateBackBufferName,(Display *dpy,XdbeBackBuffer buffer),(dpy,buffer),return)
+SDL_X11_SYM(Status,XdbeSwapBuffers,(Display *dpy,XdbeSwapInfo *swap_info,int num_windows),(dpy,swap_info,num_windows),return)
+SDL_X11_SYM(Status,XdbeBeginIdiom,(Display *dpy),(dpy),return)
+SDL_X11_SYM(Status,XdbeEndIdiom,(Display *dpy),(dpy),return)
+SDL_X11_SYM(XdbeScreenVisualInfo*,XdbeGetVisualInfo,(Display *dpy,Drawable *screen_specifiers,int *num_screens),(dpy,screen_specifiers,num_screens),return)
+SDL_X11_SYM(void,XdbeFreeVisualInfo,(XdbeScreenVisualInfo *visual_info),(visual_info),)
+SDL_X11_SYM(XdbeBackBufferAttributes*,XdbeGetBackBufferAttributes,(Display *dpy,XdbeBackBuffer buffer),(dpy,buffer),return)
+#endif
+
+/* Xinerama support */
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+SDL_X11_MODULE(XINERAMA)
+SDL_X11_SYM(Bool,XineramaIsActive,(Display *a),(a),return)
+SDL_X11_SYM(Bool,XineramaQueryExtension,(Display *a,int *b,int *c),(a,b,c),return)
+SDL_X11_SYM(Status,XineramaQueryVersion,(Display *a,int *b,int *c),(a,b,c),return)
+SDL_X11_SYM(XineramaScreenInfo*,XineramaQueryScreens,(Display *a, int *b),(a,b),return)
+#endif
+
+/* XInput2 support for multiple mice, tablets, etc. */
+#if SDL_VIDEO_DRIVER_X11_XINPUT2
+SDL_X11_MODULE(XINPUT2)
+SDL_X11_SYM(XIDeviceInfo*,XIQueryDevice,(Display *a,int b,int *c),(a,b,c),return)
+SDL_X11_SYM(void,XIFreeDeviceInfo,(XIDeviceInfo *a),(a),)
+SDL_X11_SYM(int,XISelectEvents,(Display *a,Window b,XIEventMask *c,int d),(a,b,c,d),return)
+SDL_X11_SYM(Status,XIQueryVersion,(Display *a,int *b,int *c),(a,b,c),return)
+SDL_X11_SYM(XIEventMask*,XIGetSelectedEvents,(Display *a,Window b,int *c),(a,b,c),return)
+#endif
+
+/* XRandR support */
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+SDL_X11_MODULE(XRANDR)
+SDL_X11_SYM(Status,XRRQueryVersion,(Display *dpy,int *major_versionp,int *minor_versionp),(dpy,major_versionp,minor_versionp),return)
+SDL_X11_SYM(XRRScreenConfiguration *,XRRGetScreenInfo,(Display *dpy,Drawable draw),(dpy,draw),return)
+SDL_X11_SYM(SizeID,XRRConfigCurrentConfiguration,(XRRScreenConfiguration *config,Rotation *rotation),(config,rotation),return)
+SDL_X11_SYM(short,XRRConfigCurrentRate,(XRRScreenConfiguration *config),(config),return)
+SDL_X11_SYM(short *,XRRConfigRates,(XRRScreenConfiguration *config,int sizeID,int *nrates),(config,sizeID,nrates),return)
+SDL_X11_SYM(XRRScreenSize *,XRRConfigSizes,(XRRScreenConfiguration *config,int *nsizes),(config,nsizes),return)
+SDL_X11_SYM(Status,XRRSetScreenConfigAndRate,(Display *dpy,XRRScreenConfiguration *config,Drawable draw,int size_index,Rotation rotation,short rate,Time timestamp),(dpy,config,draw,size_index,rotation,rate,timestamp),return)
+SDL_X11_SYM(void,XRRFreeScreenConfigInfo,(XRRScreenConfiguration *config),(config),)
+SDL_X11_SYM(void,XRRSetScreenSize,(Display *dpy, Window window,int width, int height,int mmWidth, int mmHeight),(dpy,window,width,height,mmWidth,mmHeight),)
+SDL_X11_SYM(Status,XRRGetScreenSizeRange,(Display *dpy, Window window,int *minWidth, int *minHeight, int *maxWidth, int *maxHeight),(dpy,window,minWidth,minHeight,maxWidth,maxHeight),return)
+SDL_X11_SYM(XRRScreenResources *,XRRGetScreenResources,(Display *dpy, Window window),(dpy, window),return)
+SDL_X11_SYM(XRRScreenResources *,XRRGetScreenResourcesCurrent,(Display *dpy, Window window),(dpy, window),return)
+SDL_X11_SYM(void,XRRFreeScreenResources,(XRRScreenResources *resources),(resources),)
+SDL_X11_SYM(XRROutputInfo *,XRRGetOutputInfo,(Display *dpy, XRRScreenResources *resources, RROutput output),(dpy,resources,output),return)
+SDL_X11_SYM(void,XRRFreeOutputInfo,(XRROutputInfo *outputInfo),(outputInfo),)
+SDL_X11_SYM(XRRCrtcInfo *,XRRGetCrtcInfo,(Display *dpy, XRRScreenResources *resources, RRCrtc crtc),(dpy,resources,crtc),return)
+SDL_X11_SYM(void,XRRFreeCrtcInfo,(XRRCrtcInfo *crtcInfo),(crtcInfo),)
+SDL_X11_SYM(Status,XRRSetCrtcConfig,(Display *dpy, XRRScreenResources *resources, RRCrtc crtc, Time timestamp, int x, int y, RRMode mode, Rotation rotation, RROutput *outputs, int noutputs),(dpy,resources,crtc,timestamp,x,y,mode,rotation,outputs,noutputs),return)
+SDL_X11_SYM(Atom*,XRRListOutputProperties,(Display *dpy, RROutput output, int *nprop),(dpy,output,nprop),return)
+SDL_X11_SYM(XRRPropertyInfo*,XRRQueryOutputProperty,(Display *dpy,RROutput output, Atom property),(dpy,output,property),return)
+SDL_X11_SYM(int,XRRGetOutputProperty,(Display *dpy,RROutput output, Atom property, long offset, long length, Bool _delete, Bool pending, Atom req_type, Atom *actual_type, int *actual_format, unsigned long *nitems, unsigned long *bytes_after, unsigned char **prop),(dpy,output,property,offset,length, _delete, pending, req_type, actual_type, actual_format, nitems, bytes_after, prop),return)
+SDL_X11_SYM(RROutput,XRRGetOutputPrimary,(Display *dpy,Window window),(dpy,window),return)
+#endif
+
+/* MIT-SCREEN-SAVER support */
+#if SDL_VIDEO_DRIVER_X11_XSCRNSAVER
+SDL_X11_MODULE(XSS)
+SDL_X11_SYM(Bool,XScreenSaverQueryExtension,(Display *dpy,int *event_base,int *error_base),(dpy,event_base,error_base),return)
+SDL_X11_SYM(Status,XScreenSaverQueryVersion,(Display *dpy,int *major_versionp,int *minor_versionp),(dpy,major_versionp,minor_versionp),return)
+SDL_X11_SYM(void,XScreenSaverSuspend,(Display *dpy,Bool suspend),(dpy,suspend),return)
+#endif
+
+#if SDL_VIDEO_DRIVER_X11_XSHAPE
+SDL_X11_MODULE(XSHAPE)
+SDL_X11_SYM(void,XShapeCombineMask,(Display *dpy,Window dest,int dest_kind,int x_off,int y_off,Pixmap src,int op),(dpy,dest,dest_kind,x_off,y_off,src,op),)
+#endif
+
+#if SDL_VIDEO_DRIVER_X11_XVIDMODE
+SDL_X11_MODULE(XVIDMODE)
+SDL_X11_SYM(Bool,XF86VidModeGetAllModeLines,(Display *a,int b,int *c,XF86VidModeModeInfo ***d),(a,b,c,d),return)
+SDL_X11_SYM(Bool,XF86VidModeGetModeLine,(Display *a,int b,int *c,XF86VidModeModeLine *d),(a,b,c,d),return)
+SDL_X11_SYM(Bool,XF86VidModeGetViewPort,(Display *a,int b,int *c,int *d),(a,b,c,d),return)
+SDL_X11_SYM(Bool,XF86VidModeQueryExtension,(Display *a,int *b,int *c),(a,b,c),return)
+SDL_X11_SYM(Bool,XF86VidModeQueryVersion,(Display *a,int *b,int *c),(a,b,c),return)
+SDL_X11_SYM(Bool,XF86VidModeSwitchToMode,(Display *a,int b,XF86VidModeModeInfo *c),(a,b,c),return)
+SDL_X11_SYM(Bool,XF86VidModeLockModeSwitch,(Display *a,int b,int c),(a,b,c),return)
+#endif
+
+#undef SDL_X11_MODULE
+#undef SDL_X11_SYM
+
+/* *INDENT-ON* */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11touch.c b/src/3rdparty/SDL2/src/video/x11/SDL_x11touch.c
new file mode 100644
index 0000000..2d0e73b
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11touch.c
@@ -0,0 +1,54 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_X11
+
+#include "SDL_x11video.h"
+#include "SDL_x11touch.h"
+#include "SDL_x11xinput2.h"
+#include "../../events/SDL_touch_c.h"
+
+
+void
+X11_InitTouch(_THIS)
+{
+ if (X11_Xinput2IsMultitouchSupported()) {
+ X11_InitXinput2Multitouch(_this);
+ }
+}
+
+void
+X11_QuitTouch(_THIS)
+{
+ SDL_TouchQuit();
+}
+
+void
+X11_ResetTouch(_THIS)
+{
+ X11_QuitTouch(_this);
+ X11_InitTouch(_this);
+}
+
+#endif /* SDL_VIDEO_DRIVER_X11 */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11touch.h b/src/3rdparty/SDL2/src/video/x11/SDL_x11touch.h
new file mode 100644
index 0000000..5a59af0
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11touch.h
@@ -0,0 +1,32 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_x11touch_h_
+#define SDL_x11touch_h_
+
+extern void X11_InitTouch(_THIS);
+extern void X11_QuitTouch(_THIS);
+extern void X11_ResetTouch(_THIS);
+
+#endif /* SDL_x11touch_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11video.c b/src/3rdparty/SDL2/src/video/x11/SDL_x11video.c
new file mode 100644
index 0000000..b8f8edf
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11video.c
@@ -0,0 +1,496 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_X11
+
+#include <unistd.h> /* For getpid() and readlink() */
+
+#include "SDL_video.h"
+#include "SDL_mouse.h"
+#include "SDL_timer.h"
+#include "../SDL_sysvideo.h"
+#include "../SDL_pixels_c.h"
+
+#include "SDL_x11video.h"
+#include "SDL_x11framebuffer.h"
+#include "SDL_x11shape.h"
+#include "SDL_x11touch.h"
+#include "SDL_x11xinput2.h"
+
+#if SDL_VIDEO_OPENGL_EGL
+#include "SDL_x11opengles.h"
+#endif
+
+#include "SDL_x11vulkan.h"
+
+/* Initialization/Query functions */
+static int X11_VideoInit(_THIS);
+static void X11_VideoQuit(_THIS);
+
+/* Find out what class name we should use */
+static char *
+get_classname()
+{
+ char *spot;
+#if defined(__LINUX__) || defined(__FREEBSD__)
+ char procfile[1024];
+ char linkfile[1024];
+ int linksize;
+#endif
+
+ /* First allow environment variable override */
+ spot = SDL_getenv("SDL_VIDEO_X11_WMCLASS");
+ if (spot) {
+ return SDL_strdup(spot);
+ }
+
+ /* Next look at the application's executable name */
+#if defined(__LINUX__) || defined(__FREEBSD__)
+#if defined(__LINUX__)
+ SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid());
+#elif defined(__FREEBSD__)
+ SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file",
+ getpid());
+#else
+#error Where can we find the executable name?
+#endif
+ linksize = readlink(procfile, linkfile, sizeof(linkfile) - 1);
+ if (linksize > 0) {
+ linkfile[linksize] = '\0';
+ spot = SDL_strrchr(linkfile, '/');
+ if (spot) {
+ return SDL_strdup(spot + 1);
+ } else {
+ return SDL_strdup(linkfile);
+ }
+ }
+#endif /* __LINUX__ || __FREEBSD__ */
+
+ /* Finally use the default we've used forever */
+ return SDL_strdup("SDL_App");
+}
+
+/* X11 driver bootstrap functions */
+
+static int
+X11_Available(void)
+{
+ Display *display = NULL;
+ if (SDL_X11_LoadSymbols()) {
+ display = X11_XOpenDisplay(NULL);
+ if (display != NULL) {
+ X11_XCloseDisplay(display);
+ }
+ SDL_X11_UnloadSymbols();
+ }
+ return (display != NULL);
+}
+
+static void
+X11_DeleteDevice(SDL_VideoDevice * device)
+{
+ SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
+ if (device->vulkan_config.loader_handle) {
+ device->Vulkan_UnloadLibrary(device);
+ }
+ if (data->display) {
+ X11_XCloseDisplay(data->display);
+ }
+ SDL_free(data->windowlist);
+ SDL_free(device->driverdata);
+ SDL_free(device);
+
+ SDL_X11_UnloadSymbols();
+}
+
+/* An error handler to reset the vidmode and then call the default handler. */
+static SDL_bool safety_net_triggered = SDL_FALSE;
+static int (*orig_x11_errhandler) (Display *, XErrorEvent *) = NULL;
+static int
+X11_SafetyNetErrHandler(Display * d, XErrorEvent * e)
+{
+ SDL_VideoDevice *device = NULL;
+ /* if we trigger an error in our error handler, don't try again. */
+ if (!safety_net_triggered) {
+ safety_net_triggered = SDL_TRUE;
+ device = SDL_GetVideoDevice();
+ if (device != NULL) {
+ int i;
+ for (i = 0; i < device->num_displays; i++) {
+ SDL_VideoDisplay *display = &device->displays[i];
+ if (SDL_memcmp(&display->current_mode, &display->desktop_mode,
+ sizeof (SDL_DisplayMode)) != 0) {
+ X11_SetDisplayMode(device, display, &display->desktop_mode);
+ }
+ }
+ }
+ }
+
+ if (orig_x11_errhandler != NULL) {
+ return orig_x11_errhandler(d, e); /* probably terminate. */
+ }
+
+ return 0;
+}
+
+static SDL_VideoDevice *
+X11_CreateDevice(int devindex)
+{
+ SDL_VideoDevice *device;
+ SDL_VideoData *data;
+ const char *display = NULL; /* Use the DISPLAY environment variable */
+
+ if (!SDL_X11_LoadSymbols()) {
+ return NULL;
+ }
+
+ /* Need for threading gl calls. This is also required for the proprietary
+ nVidia driver to be threaded. */
+ X11_XInitThreads();
+
+ /* Initialize all variables that we clean on shutdown */
+ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (!device) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
+ if (!data) {
+ SDL_free(device);
+ SDL_OutOfMemory();
+ return NULL;
+ }
+ device->driverdata = data;
+
+ data->global_mouse_changed = SDL_TRUE;
+
+ /* FIXME: Do we need this?
+ if ( (SDL_strncmp(X11_XDisplayName(display), ":", 1) == 0) ||
+ (SDL_strncmp(X11_XDisplayName(display), "unix:", 5) == 0) ) {
+ local_X11 = 1;
+ } else {
+ local_X11 = 0;
+ }
+ */
+ data->display = X11_XOpenDisplay(display);
+#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
+ /* On some systems if linking without -lX11, it fails and you get following message.
+ * Xlib: connection to ":0.0" refused by server
+ * Xlib: XDM authorization key matches an existing client!
+ *
+ * It succeeds if retrying 1 second later
+ * or if running xhost +localhost on shell.
+ */
+ if (data->display == NULL) {
+ SDL_Delay(1000);
+ data->display = X11_XOpenDisplay(display);
+ }
+#endif
+ if (data->display == NULL) {
+ SDL_free(device->driverdata);
+ SDL_free(device);
+ SDL_SetError("Couldn't open X11 display");
+ return NULL;
+ }
+#ifdef X11_DEBUG
+ X11_XSynchronize(data->display, True);
+#endif
+
+ /* Hook up an X11 error handler to recover the desktop resolution. */
+ safety_net_triggered = SDL_FALSE;
+ orig_x11_errhandler = X11_XSetErrorHandler(X11_SafetyNetErrHandler);
+
+ /* Set the function pointers */
+ device->VideoInit = X11_VideoInit;
+ device->VideoQuit = X11_VideoQuit;
+ device->ResetTouch = X11_ResetTouch;
+ device->GetDisplayModes = X11_GetDisplayModes;
+ device->GetDisplayBounds = X11_GetDisplayBounds;
+ device->GetDisplayUsableBounds = X11_GetDisplayUsableBounds;
+ device->GetDisplayDPI = X11_GetDisplayDPI;
+ device->SetDisplayMode = X11_SetDisplayMode;
+ device->SuspendScreenSaver = X11_SuspendScreenSaver;
+ device->PumpEvents = X11_PumpEvents;
+
+ device->CreateSDLWindow = X11_CreateWindow;
+ device->CreateSDLWindowFrom = X11_CreateWindowFrom;
+ device->SetWindowTitle = X11_SetWindowTitle;
+ device->SetWindowIcon = X11_SetWindowIcon;
+ device->SetWindowPosition = X11_SetWindowPosition;
+ device->SetWindowSize = X11_SetWindowSize;
+ device->SetWindowMinimumSize = X11_SetWindowMinimumSize;
+ device->SetWindowMaximumSize = X11_SetWindowMaximumSize;
+ device->GetWindowBordersSize = X11_GetWindowBordersSize;
+ device->SetWindowOpacity = X11_SetWindowOpacity;
+ device->SetWindowModalFor = X11_SetWindowModalFor;
+ device->SetWindowInputFocus = X11_SetWindowInputFocus;
+ device->ShowWindow = X11_ShowWindow;
+ device->HideWindow = X11_HideWindow;
+ device->RaiseWindow = X11_RaiseWindow;
+ device->MaximizeWindow = X11_MaximizeWindow;
+ device->MinimizeWindow = X11_MinimizeWindow;
+ device->RestoreWindow = X11_RestoreWindow;
+ device->SetWindowBordered = X11_SetWindowBordered;
+ device->SetWindowResizable = X11_SetWindowResizable;
+ device->SetWindowFullscreen = X11_SetWindowFullscreen;
+ device->SetWindowGammaRamp = X11_SetWindowGammaRamp;
+ device->SetWindowGrab = X11_SetWindowGrab;
+ device->DestroyWindow = X11_DestroyWindow;
+ device->CreateWindowFramebuffer = X11_CreateWindowFramebuffer;
+ device->UpdateWindowFramebuffer = X11_UpdateWindowFramebuffer;
+ device->DestroyWindowFramebuffer = X11_DestroyWindowFramebuffer;
+ device->GetWindowWMInfo = X11_GetWindowWMInfo;
+ device->SetWindowHitTest = X11_SetWindowHitTest;
+
+ device->shape_driver.CreateShaper = X11_CreateShaper;
+ device->shape_driver.SetWindowShape = X11_SetWindowShape;
+ device->shape_driver.ResizeWindowShape = X11_ResizeWindowShape;
+
+#if SDL_VIDEO_OPENGL_GLX
+ device->GL_LoadLibrary = X11_GL_LoadLibrary;
+ device->GL_GetProcAddress = X11_GL_GetProcAddress;
+ device->GL_UnloadLibrary = X11_GL_UnloadLibrary;
+ device->GL_CreateContext = X11_GL_CreateContext;
+ device->GL_MakeCurrent = X11_GL_MakeCurrent;
+ device->GL_SetSwapInterval = X11_GL_SetSwapInterval;
+ device->GL_GetSwapInterval = X11_GL_GetSwapInterval;
+ device->GL_SwapWindow = X11_GL_SwapWindow;
+ device->GL_DeleteContext = X11_GL_DeleteContext;
+#elif SDL_VIDEO_OPENGL_EGL
+ device->GL_LoadLibrary = X11_GLES_LoadLibrary;
+ device->GL_GetProcAddress = X11_GLES_GetProcAddress;
+ device->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
+ device->GL_CreateContext = X11_GLES_CreateContext;
+ device->GL_MakeCurrent = X11_GLES_MakeCurrent;
+ device->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
+ device->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
+ device->GL_SwapWindow = X11_GLES_SwapWindow;
+ device->GL_DeleteContext = X11_GLES_DeleteContext;
+#endif
+
+ device->SetClipboardText = X11_SetClipboardText;
+ device->GetClipboardText = X11_GetClipboardText;
+ device->HasClipboardText = X11_HasClipboardText;
+ device->StartTextInput = X11_StartTextInput;
+ device->StopTextInput = X11_StopTextInput;
+ device->SetTextInputRect = X11_SetTextInputRect;
+
+ device->free = X11_DeleteDevice;
+
+#if SDL_VIDEO_VULKAN
+ device->Vulkan_LoadLibrary = X11_Vulkan_LoadLibrary;
+ device->Vulkan_UnloadLibrary = X11_Vulkan_UnloadLibrary;
+ device->Vulkan_GetInstanceExtensions = X11_Vulkan_GetInstanceExtensions;
+ device->Vulkan_CreateSurface = X11_Vulkan_CreateSurface;
+#endif
+
+ return device;
+}
+
+VideoBootStrap X11_bootstrap = {
+ "x11", "SDL X11 video driver",
+ X11_Available, X11_CreateDevice
+};
+
+static int (*handler) (Display *, XErrorEvent *) = NULL;
+static int
+X11_CheckWindowManagerErrorHandler(Display * d, XErrorEvent * e)
+{
+ if (e->error_code == BadWindow) {
+ return (0);
+ } else {
+ return (handler(d, e));
+ }
+}
+
+static void
+X11_CheckWindowManager(_THIS)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+ Display *display = data->display;
+ Atom _NET_SUPPORTING_WM_CHECK;
+ int status, real_format;
+ Atom real_type;
+ unsigned long items_read = 0, items_left = 0;
+ unsigned char *propdata = NULL;
+ Window wm_window = 0;
+#ifdef DEBUG_WINDOW_MANAGER
+ char *wm_name;
+#endif
+
+ /* Set up a handler to gracefully catch errors */
+ X11_XSync(display, False);
+ handler = X11_XSetErrorHandler(X11_CheckWindowManagerErrorHandler);
+
+ _NET_SUPPORTING_WM_CHECK = X11_XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", False);
+ status = X11_XGetWindowProperty(display, DefaultRootWindow(display), _NET_SUPPORTING_WM_CHECK, 0L, 1L, False, XA_WINDOW, &real_type, &real_format, &items_read, &items_left, &propdata);
+ if (status == Success) {
+ if (items_read) {
+ wm_window = ((Window*)propdata)[0];
+ }
+ if (propdata) {
+ X11_XFree(propdata);
+ propdata = NULL;
+ }
+ }
+
+ if (wm_window) {
+ status = X11_XGetWindowProperty(display, wm_window, _NET_SUPPORTING_WM_CHECK, 0L, 1L, False, XA_WINDOW, &real_type, &real_format, &items_read, &items_left, &propdata);
+ if (status != Success || !items_read || wm_window != ((Window*)propdata)[0]) {
+ wm_window = None;
+ }
+ if (status == Success && propdata) {
+ X11_XFree(propdata);
+ propdata = NULL;
+ }
+ }
+
+ /* Reset the error handler, we're done checking */
+ X11_XSync(display, False);
+ X11_XSetErrorHandler(handler);
+
+ if (!wm_window) {
+#ifdef DEBUG_WINDOW_MANAGER
+ printf("Couldn't get _NET_SUPPORTING_WM_CHECK property\n");
+#endif
+ return;
+ }
+ data->net_wm = SDL_TRUE;
+
+#ifdef DEBUG_WINDOW_MANAGER
+ wm_name = X11_GetWindowTitle(_this, wm_window);
+ printf("Window manager: %s\n", wm_name);
+ SDL_free(wm_name);
+#endif
+}
+
+
+int
+X11_VideoInit(_THIS)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
+ /* Get the window class name, usually the name of the application */
+ data->classname = get_classname();
+
+ /* Get the process PID to be associated to the window */
+ data->pid = getpid();
+
+ /* I have no idea how random this actually is, or has to be. */
+ data->window_group = (XID) (((size_t) data->pid) ^ ((size_t) _this));
+
+ /* Look up some useful Atoms */
+#define GET_ATOM(X) data->X = X11_XInternAtom(data->display, #X, False)
+ GET_ATOM(WM_PROTOCOLS);
+ GET_ATOM(WM_DELETE_WINDOW);
+ GET_ATOM(WM_TAKE_FOCUS);
+ GET_ATOM(_NET_WM_STATE);
+ GET_ATOM(_NET_WM_STATE_HIDDEN);
+ GET_ATOM(_NET_WM_STATE_FOCUSED);
+ GET_ATOM(_NET_WM_STATE_MAXIMIZED_VERT);
+ GET_ATOM(_NET_WM_STATE_MAXIMIZED_HORZ);
+ GET_ATOM(_NET_WM_STATE_FULLSCREEN);
+ GET_ATOM(_NET_WM_STATE_ABOVE);
+ GET_ATOM(_NET_WM_STATE_SKIP_TASKBAR);
+ GET_ATOM(_NET_WM_STATE_SKIP_PAGER);
+ GET_ATOM(_NET_WM_ALLOWED_ACTIONS);
+ GET_ATOM(_NET_WM_ACTION_FULLSCREEN);
+ GET_ATOM(_NET_WM_NAME);
+ GET_ATOM(_NET_WM_ICON_NAME);
+ GET_ATOM(_NET_WM_ICON);
+ GET_ATOM(_NET_WM_PING);
+ GET_ATOM(_NET_WM_WINDOW_OPACITY);
+ GET_ATOM(_NET_WM_USER_TIME);
+ GET_ATOM(_NET_ACTIVE_WINDOW);
+ GET_ATOM(_NET_FRAME_EXTENTS);
+ GET_ATOM(UTF8_STRING);
+ GET_ATOM(PRIMARY);
+ GET_ATOM(XdndEnter);
+ GET_ATOM(XdndPosition);
+ GET_ATOM(XdndStatus);
+ GET_ATOM(XdndTypeList);
+ GET_ATOM(XdndActionCopy);
+ GET_ATOM(XdndDrop);
+ GET_ATOM(XdndFinished);
+ GET_ATOM(XdndSelection);
+ GET_ATOM(XKLAVIER_STATE);
+
+ /* Detect the window manager */
+ X11_CheckWindowManager(_this);
+
+ if (X11_InitModes(_this) < 0) {
+ return -1;
+ }
+
+ X11_InitXinput2(_this);
+
+ if (X11_InitKeyboard(_this) != 0) {
+ return -1;
+ }
+ X11_InitMouse(_this);
+
+ X11_InitTouch(_this);
+
+#if SDL_USE_LIBDBUS
+ SDL_DBus_Init();
+#endif
+
+ return 0;
+}
+
+void
+X11_VideoQuit(_THIS)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
+ if (data->clipboard_window) {
+ X11_XDestroyWindow(data->display, data->clipboard_window);
+ }
+
+ SDL_free(data->classname);
+#ifdef X_HAVE_UTF8_STRING
+ if (data->im) {
+ X11_XCloseIM(data->im);
+ }
+#endif
+
+ X11_QuitModes(_this);
+ X11_QuitKeyboard(_this);
+ X11_QuitMouse(_this);
+ X11_QuitTouch(_this);
+
+/* !!! FIXME: other subsystems use D-Bus, so we shouldn't quit it here;
+ have SDL.c do this at a higher level, or add refcounting. */
+#if SDL_USE_LIBDBUS
+ SDL_DBus_Quit();
+#endif
+}
+
+SDL_bool
+X11_UseDirectColorVisuals(void)
+{
+ return SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") ? SDL_FALSE : SDL_TRUE;
+}
+
+#endif /* SDL_VIDEO_DRIVER_X11 */
+
+/* vim: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11video.h b/src/3rdparty/SDL2/src/video/x11/SDL_x11video.h
new file mode 100644
index 0000000..c0dc08e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11video.h
@@ -0,0 +1,156 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_x11video_h_
+#define SDL_x11video_h_
+
+#include "SDL_keycode.h"
+
+#include "../SDL_sysvideo.h"
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xatom.h>
+
+#if SDL_VIDEO_DRIVER_X11_XCURSOR
+#include <X11/Xcursor/Xcursor.h>
+#endif
+#if SDL_VIDEO_DRIVER_X11_XDBE
+#include <X11/extensions/Xdbe.h>
+#endif
+#if SDL_VIDEO_DRIVER_X11_XINERAMA
+#include <X11/extensions/Xinerama.h>
+#endif
+#if SDL_VIDEO_DRIVER_X11_XINPUT2
+#include <X11/extensions/XInput2.h>
+#endif
+#if SDL_VIDEO_DRIVER_X11_XRANDR
+#include <X11/extensions/Xrandr.h>
+#endif
+#if SDL_VIDEO_DRIVER_X11_XSCRNSAVER
+#include <X11/extensions/scrnsaver.h>
+#endif
+#if SDL_VIDEO_DRIVER_X11_XSHAPE
+#include <X11/extensions/shape.h>
+#endif
+#if SDL_VIDEO_DRIVER_X11_XVIDMODE
+#include <X11/extensions/xf86vmode.h>
+#endif
+
+#include "../../core/linux/SDL_dbus.h"
+#include "../../core/linux/SDL_ime.h"
+
+#include "SDL_x11dyn.h"
+
+#include "SDL_x11clipboard.h"
+#include "SDL_x11events.h"
+#include "SDL_x11keyboard.h"
+#include "SDL_x11modes.h"
+#include "SDL_x11mouse.h"
+#include "SDL_x11opengl.h"
+#include "SDL_x11window.h"
+#include "SDL_x11vulkan.h"
+
+/* Private display data */
+
+typedef struct SDL_VideoData
+{
+ Display *display;
+ char *classname;
+ pid_t pid;
+ XIM im;
+ Uint32 screensaver_activity;
+ int numwindows;
+ SDL_WindowData **windowlist;
+ int windowlistlength;
+ XID window_group;
+ Window clipboard_window;
+
+ /* This is true for ICCCM2.0-compliant window managers */
+ SDL_bool net_wm;
+
+ /* Useful atoms */
+ Atom WM_PROTOCOLS;
+ Atom WM_DELETE_WINDOW;
+ Atom WM_TAKE_FOCUS;
+ Atom _NET_WM_STATE;
+ Atom _NET_WM_STATE_HIDDEN;
+ Atom _NET_WM_STATE_FOCUSED;
+ Atom _NET_WM_STATE_MAXIMIZED_VERT;
+ Atom _NET_WM_STATE_MAXIMIZED_HORZ;
+ Atom _NET_WM_STATE_FULLSCREEN;
+ Atom _NET_WM_STATE_ABOVE;
+ Atom _NET_WM_STATE_SKIP_TASKBAR;
+ Atom _NET_WM_STATE_SKIP_PAGER;
+ Atom _NET_WM_ALLOWED_ACTIONS;
+ Atom _NET_WM_ACTION_FULLSCREEN;
+ Atom _NET_WM_NAME;
+ Atom _NET_WM_ICON_NAME;
+ Atom _NET_WM_ICON;
+ Atom _NET_WM_PING;
+ Atom _NET_WM_WINDOW_OPACITY;
+ Atom _NET_WM_USER_TIME;
+ Atom _NET_ACTIVE_WINDOW;
+ Atom _NET_FRAME_EXTENTS;
+ Atom UTF8_STRING;
+ Atom PRIMARY;
+ Atom XdndEnter;
+ Atom XdndPosition;
+ Atom XdndStatus;
+ Atom XdndTypeList;
+ Atom XdndActionCopy;
+ Atom XdndDrop;
+ Atom XdndFinished;
+ Atom XdndSelection;
+ Atom XKLAVIER_STATE;
+
+ SDL_Scancode key_layout[256];
+ SDL_bool selection_waiting;
+
+ SDL_bool broken_pointer_grab; /* true if XGrabPointer seems unreliable. */
+
+ Uint32 last_mode_change_deadline;
+
+ SDL_bool global_mouse_changed;
+ SDL_Point global_mouse_position;
+ Uint32 global_mouse_buttons;
+
+#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
+ XkbDescPtr xkb;
+#endif
+
+ KeyCode filter_code;
+ Time filter_time;
+
+#if SDL_VIDEO_VULKAN
+ /* Vulkan variables only valid if _this->vulkan_config.loader_handle is not NULL */
+ void *vulkan_xlib_xcb_library;
+ PFN_XGetXCBConnection vulkan_XGetXCBConnection;
+#endif
+
+} SDL_VideoData;
+
+extern SDL_bool X11_UseDirectColorVisuals(void);
+
+#endif /* SDL_x11video_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11vulkan.c b/src/3rdparty/SDL2/src/video/x11/SDL_x11vulkan.c
new file mode 100644
index 0000000..ec43aef
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11vulkan.c
@@ -0,0 +1,243 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_X11
+
+#include "SDL_x11video.h"
+#include "SDL_assert.h"
+
+#include "SDL_loadso.h"
+#include "SDL_x11vulkan.h"
+
+#include <X11/Xlib.h>
+/*#include <xcb/xcb.h>*/
+/*
+typedef uint32_t xcb_window_t;
+typedef uint32_t xcb_visualid_t;
+*/
+
+int X11_Vulkan_LoadLibrary(_THIS, const char *path)
+{
+ SDL_VideoData *videoData = (SDL_VideoData *)_this->driverdata;
+ VkExtensionProperties *extensions = NULL;
+ Uint32 extensionCount = 0;
+ SDL_bool hasSurfaceExtension = SDL_FALSE;
+ SDL_bool hasXlibSurfaceExtension = SDL_FALSE;
+ SDL_bool hasXCBSurfaceExtension = SDL_FALSE;
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
+ Uint32 i;
+ if(_this->vulkan_config.loader_handle)
+ return SDL_SetError("Vulkan already loaded");
+
+ /* Load the Vulkan loader library */
+ if(!path)
+ path = SDL_getenv("SDL_VULKAN_LIBRARY");
+ if(!path)
+ path = "libvulkan.so.1";
+ _this->vulkan_config.loader_handle = SDL_LoadObject(path);
+ if(!_this->vulkan_config.loader_handle)
+ return -1;
+ SDL_strlcpy(_this->vulkan_config.loader_path, path, SDL_arraysize(_this->vulkan_config.loader_path));
+ vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction(
+ _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr");
+ if(!vkGetInstanceProcAddr)
+ goto fail;
+ _this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr;
+ _this->vulkan_config.vkEnumerateInstanceExtensionProperties =
+ (void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)(
+ VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties");
+ if(!_this->vulkan_config.vkEnumerateInstanceExtensionProperties)
+ goto fail;
+ extensions = SDL_Vulkan_CreateInstanceExtensionsList(
+ (PFN_vkEnumerateInstanceExtensionProperties)
+ _this->vulkan_config.vkEnumerateInstanceExtensionProperties,
+ &extensionCount);
+ if(!extensions)
+ goto fail;
+ for(i = 0; i < extensionCount; i++)
+ {
+ if(SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
+ hasSurfaceExtension = SDL_TRUE;
+ else if(SDL_strcmp(VK_KHR_XCB_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
+ hasXCBSurfaceExtension = SDL_TRUE;
+ else if(SDL_strcmp(VK_KHR_XLIB_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
+ hasXlibSurfaceExtension = SDL_TRUE;
+ }
+ SDL_free(extensions);
+ if(!hasSurfaceExtension)
+ {
+ SDL_SetError("Installed Vulkan doesn't implement the "
+ VK_KHR_SURFACE_EXTENSION_NAME " extension");
+ goto fail;
+ }
+ if(hasXlibSurfaceExtension)
+ {
+ videoData->vulkan_xlib_xcb_library = NULL;
+ }
+ else if(!hasXCBSurfaceExtension)
+ {
+ SDL_SetError("Installed Vulkan doesn't implement either the "
+ VK_KHR_XCB_SURFACE_EXTENSION_NAME "extension or the "
+ VK_KHR_XLIB_SURFACE_EXTENSION_NAME " extension");
+ goto fail;
+ }
+ else
+ {
+ const char *libX11XCBLibraryName = SDL_getenv("SDL_X11_XCB_LIBRARY");
+ if(!libX11XCBLibraryName)
+ libX11XCBLibraryName = "libX11-xcb.so";
+ videoData->vulkan_xlib_xcb_library = SDL_LoadObject(libX11XCBLibraryName);
+ if(!videoData->vulkan_xlib_xcb_library)
+ goto fail;
+ videoData->vulkan_XGetXCBConnection =
+ SDL_LoadFunction(videoData->vulkan_xlib_xcb_library, "XGetXCBConnection");
+ if(!videoData->vulkan_XGetXCBConnection)
+ {
+ SDL_UnloadObject(videoData->vulkan_xlib_xcb_library);
+ goto fail;
+ }
+ }
+ return 0;
+
+fail:
+ SDL_UnloadObject(_this->vulkan_config.loader_handle);
+ _this->vulkan_config.loader_handle = NULL;
+ return -1;
+}
+
+void X11_Vulkan_UnloadLibrary(_THIS)
+{
+ SDL_VideoData *videoData = (SDL_VideoData *)_this->driverdata;
+ if(_this->vulkan_config.loader_handle)
+ {
+ if(videoData->vulkan_xlib_xcb_library)
+ SDL_UnloadObject(videoData->vulkan_xlib_xcb_library);
+ SDL_UnloadObject(_this->vulkan_config.loader_handle);
+ _this->vulkan_config.loader_handle = NULL;
+ }
+}
+
+SDL_bool X11_Vulkan_GetInstanceExtensions(_THIS,
+ SDL_Window *window,
+ unsigned *count,
+ const char **names)
+{
+ SDL_VideoData *videoData = (SDL_VideoData *)_this->driverdata;
+ if(!_this->vulkan_config.loader_handle)
+ {
+ SDL_SetError("Vulkan is not loaded");
+ return SDL_FALSE;
+ }
+ if(videoData->vulkan_xlib_xcb_library)
+ {
+ static const char *const extensionsForXCB[] = {
+ VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XCB_SURFACE_EXTENSION_NAME,
+ };
+ return SDL_Vulkan_GetInstanceExtensions_Helper(
+ count, names, SDL_arraysize(extensionsForXCB), extensionsForXCB);
+ }
+ else
+ {
+ static const char *const extensionsForXlib[] = {
+ VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_EXTENSION_NAME,
+ };
+ return SDL_Vulkan_GetInstanceExtensions_Helper(
+ count, names, SDL_arraysize(extensionsForXlib), extensionsForXlib);
+ }
+}
+
+SDL_bool X11_Vulkan_CreateSurface(_THIS,
+ SDL_Window *window,
+ VkInstance instance,
+ VkSurfaceKHR *surface)
+{
+ SDL_VideoData *videoData = (SDL_VideoData *)_this->driverdata;
+ SDL_WindowData *windowData = (SDL_WindowData *)window->driverdata;
+ PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
+ if(!_this->vulkan_config.loader_handle)
+ {
+ SDL_SetError("Vulkan is not loaded");
+ return SDL_FALSE;
+ }
+ vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr;
+ if(videoData->vulkan_xlib_xcb_library)
+ {
+ PFN_vkCreateXcbSurfaceKHR vkCreateXcbSurfaceKHR =
+ (PFN_vkCreateXcbSurfaceKHR)vkGetInstanceProcAddr((VkInstance)instance,
+ "vkCreateXcbSurfaceKHR");
+ VkXcbSurfaceCreateInfoKHR createInfo;
+ VkResult result;
+ if(!vkCreateXcbSurfaceKHR)
+ {
+ SDL_SetError(VK_KHR_XCB_SURFACE_EXTENSION_NAME
+ " extension is not enabled in the Vulkan instance.");
+ return SDL_FALSE;
+ }
+ SDL_zero(createInfo);
+ createInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
+ createInfo.connection = videoData->vulkan_XGetXCBConnection(videoData->display);
+ if(!createInfo.connection)
+ {
+ SDL_SetError("XGetXCBConnection failed");
+ return SDL_FALSE;
+ }
+ createInfo.window = (xcb_window_t)windowData->xwindow;
+ result = vkCreateXcbSurfaceKHR(instance, &createInfo,
+ NULL, surface);
+ if(result != VK_SUCCESS)
+ {
+ SDL_SetError("vkCreateXcbSurfaceKHR failed: %s", SDL_Vulkan_GetResultString(result));
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
+ }
+ else
+ {
+ PFN_vkCreateXlibSurfaceKHR vkCreateXlibSurfaceKHR =
+ (PFN_vkCreateXlibSurfaceKHR)vkGetInstanceProcAddr((VkInstance)instance,
+ "vkCreateXlibSurfaceKHR");
+ VkXlibSurfaceCreateInfoKHR createInfo;
+ VkResult result;
+ if(!vkCreateXlibSurfaceKHR)
+ {
+ SDL_SetError(VK_KHR_XLIB_SURFACE_EXTENSION_NAME
+ " extension is not enabled in the Vulkan instance.");
+ return SDL_FALSE;
+ }
+ SDL_zero(createInfo);
+ createInfo.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
+ createInfo.dpy = videoData->display;
+ createInfo.window = (xcb_window_t)windowData->xwindow;
+ result = vkCreateXlibSurfaceKHR(instance, &createInfo,
+ NULL, surface);
+ if(result != VK_SUCCESS)
+ {
+ SDL_SetError("vkCreateXlibSurfaceKHR failed: %s", SDL_Vulkan_GetResultString(result));
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
+ }
+}
+
+#endif
+
+/* vim: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11vulkan.h b/src/3rdparty/SDL2/src/video/x11/SDL_x11vulkan.h
new file mode 100644
index 0000000..152d9d7
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11vulkan.h
@@ -0,0 +1,48 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_x11vulkan_h_
+#define SDL_x11vulkan_h_
+
+#include "../SDL_vulkan_internal.h"
+
+#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_X11
+
+/*typedef struct xcb_connection_t xcb_connection_t;*/
+typedef xcb_connection_t *(*PFN_XGetXCBConnection)(Display *dpy);
+
+int X11_Vulkan_LoadLibrary(_THIS, const char *path);
+void X11_Vulkan_UnloadLibrary(_THIS);
+SDL_bool X11_Vulkan_GetInstanceExtensions(_THIS,
+ SDL_Window *window,
+ unsigned *count,
+ const char **names);
+SDL_bool X11_Vulkan_CreateSurface(_THIS,
+ SDL_Window *window,
+ VkInstance instance,
+ VkSurfaceKHR *surface);
+
+#endif
+
+#endif /* SDL_x11vulkan_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11window.c b/src/3rdparty/SDL2/src/video/x11/SDL_x11window.c
new file mode 100644
index 0000000..be03aa6
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11window.c
@@ -0,0 +1,1609 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_X11
+
+#include "SDL_assert.h"
+#include "SDL_hints.h"
+#include "../SDL_sysvideo.h"
+#include "../SDL_pixels_c.h"
+#include "../../events/SDL_keyboard_c.h"
+#include "../../events/SDL_mouse_c.h"
+
+#include "SDL_x11video.h"
+#include "SDL_x11mouse.h"
+#include "SDL_x11shape.h"
+#include "SDL_x11xinput2.h"
+
+#if SDL_VIDEO_OPENGL_EGL
+#include "SDL_x11opengles.h"
+#endif
+
+#include "SDL_timer.h"
+#include "SDL_syswm.h"
+#include "SDL_log.h"
+
+#define _NET_WM_STATE_REMOVE 0l
+#define _NET_WM_STATE_ADD 1l
+
+static Bool isMapNotify(Display *dpy, XEvent *ev, XPointer win)
+{
+ return ev->type == MapNotify && ev->xmap.window == *((Window*)win);
+}
+static Bool isUnmapNotify(Display *dpy, XEvent *ev, XPointer win)
+{
+ return ev->type == UnmapNotify && ev->xunmap.window == *((Window*)win);
+}
+
+/*
+static Bool isConfigureNotify(Display *dpy, XEvent *ev, XPointer win)
+{
+ return ev->type == ConfigureNotify && ev->xconfigure.window == *((Window*)win);
+}
+static Bool
+X11_XIfEventTimeout(Display *display, XEvent *event_return, Bool (*predicate)(), XPointer arg, int timeoutMS)
+{
+ Uint32 start = SDL_GetTicks();
+
+ while (!X11_XCheckIfEvent(display, event_return, predicate, arg)) {
+ if (SDL_TICKS_PASSED(SDL_GetTicks(), start + timeoutMS)) {
+ return False;
+ }
+ }
+ return True;
+}
+*/
+
+static SDL_bool
+X11_IsWindowLegacyFullscreen(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ return (data->fswindow != 0);
+}
+
+static SDL_bool
+X11_IsWindowMapped(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
+ XWindowAttributes attr;
+
+ X11_XGetWindowAttributes(videodata->display, data->xwindow, &attr);
+ if (attr.map_state != IsUnmapped) {
+ return SDL_TRUE;
+ } else {
+ return SDL_FALSE;
+ }
+}
+
+#if 0
+static SDL_bool
+X11_IsActionAllowed(SDL_Window *window, Atom action)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Atom _NET_WM_ALLOWED_ACTIONS = data->videodata->_NET_WM_ALLOWED_ACTIONS;
+ Atom type;
+ Display *display = data->videodata->display;
+ int form;
+ unsigned long remain;
+ unsigned long len, i;
+ Atom *list;
+ SDL_bool ret = SDL_FALSE;
+
+ if (X11_XGetWindowProperty(display, data->xwindow, _NET_WM_ALLOWED_ACTIONS, 0, 1024, False, XA_ATOM, &type, &form, &len, &remain, (unsigned char **)&list) == Success)
+ {
+ for (i=0; i<len; ++i)
+ {
+ if (list[i] == action) {
+ ret = SDL_TRUE;
+ break;
+ }
+ }
+ X11_XFree(list);
+ }
+ return ret;
+}
+#endif /* 0 */
+
+void
+X11_SetNetWMState(_THIS, Window xwindow, Uint32 flags)
+{
+ SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
+ Display *display = videodata->display;
+ /* !!! FIXME: just dereference videodata below instead of copying to locals. */
+ Atom _NET_WM_STATE = videodata->_NET_WM_STATE;
+ /* Atom _NET_WM_STATE_HIDDEN = videodata->_NET_WM_STATE_HIDDEN; */
+ Atom _NET_WM_STATE_FOCUSED = videodata->_NET_WM_STATE_FOCUSED;
+ Atom _NET_WM_STATE_MAXIMIZED_VERT = videodata->_NET_WM_STATE_MAXIMIZED_VERT;
+ Atom _NET_WM_STATE_MAXIMIZED_HORZ = videodata->_NET_WM_STATE_MAXIMIZED_HORZ;
+ Atom _NET_WM_STATE_FULLSCREEN = videodata->_NET_WM_STATE_FULLSCREEN;
+ Atom _NET_WM_STATE_ABOVE = videodata->_NET_WM_STATE_ABOVE;
+ Atom _NET_WM_STATE_SKIP_TASKBAR = videodata->_NET_WM_STATE_SKIP_TASKBAR;
+ Atom _NET_WM_STATE_SKIP_PAGER = videodata->_NET_WM_STATE_SKIP_PAGER;
+ Atom atoms[16];
+ int count = 0;
+
+ /* The window manager sets this property, we shouldn't set it.
+ If we did, this would indicate to the window manager that we don't
+ actually want to be mapped during X11_XMapRaised(), which would be bad.
+ *
+ if (flags & SDL_WINDOW_HIDDEN) {
+ atoms[count++] = _NET_WM_STATE_HIDDEN;
+ }
+ */
+
+ if (flags & SDL_WINDOW_ALWAYS_ON_TOP) {
+ atoms[count++] = _NET_WM_STATE_ABOVE;
+ }
+ if (flags & SDL_WINDOW_SKIP_TASKBAR) {
+ atoms[count++] = _NET_WM_STATE_SKIP_TASKBAR;
+ atoms[count++] = _NET_WM_STATE_SKIP_PAGER;
+ }
+ if (flags & SDL_WINDOW_INPUT_FOCUS) {
+ atoms[count++] = _NET_WM_STATE_FOCUSED;
+ }
+ if (flags & SDL_WINDOW_MAXIMIZED) {
+ atoms[count++] = _NET_WM_STATE_MAXIMIZED_VERT;
+ atoms[count++] = _NET_WM_STATE_MAXIMIZED_HORZ;
+ }
+ if (flags & SDL_WINDOW_FULLSCREEN) {
+ atoms[count++] = _NET_WM_STATE_FULLSCREEN;
+ }
+
+ SDL_assert(count <= SDL_arraysize(atoms));
+
+ if (count > 0) {
+ X11_XChangeProperty(display, xwindow, _NET_WM_STATE, XA_ATOM, 32,
+ PropModeReplace, (unsigned char *)atoms, count);
+ } else {
+ X11_XDeleteProperty(display, xwindow, _NET_WM_STATE);
+ }
+}
+
+Uint32
+X11_GetNetWMState(_THIS, Window xwindow)
+{
+ SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
+ Display *display = videodata->display;
+ Atom _NET_WM_STATE = videodata->_NET_WM_STATE;
+ Atom _NET_WM_STATE_HIDDEN = videodata->_NET_WM_STATE_HIDDEN;
+ Atom _NET_WM_STATE_FOCUSED = videodata->_NET_WM_STATE_FOCUSED;
+ Atom _NET_WM_STATE_MAXIMIZED_VERT = videodata->_NET_WM_STATE_MAXIMIZED_VERT;
+ Atom _NET_WM_STATE_MAXIMIZED_HORZ = videodata->_NET_WM_STATE_MAXIMIZED_HORZ;
+ Atom _NET_WM_STATE_FULLSCREEN = videodata->_NET_WM_STATE_FULLSCREEN;
+ Atom actualType;
+ int actualFormat;
+ unsigned long i, numItems, bytesAfter;
+ unsigned char *propertyValue = NULL;
+ long maxLength = 1024;
+ Uint32 flags = 0;
+
+ if (X11_XGetWindowProperty(display, xwindow, _NET_WM_STATE,
+ 0l, maxLength, False, XA_ATOM, &actualType,
+ &actualFormat, &numItems, &bytesAfter,
+ &propertyValue) == Success) {
+ Atom *atoms = (Atom *) propertyValue;
+ int maximized = 0;
+ int fullscreen = 0;
+
+ for (i = 0; i < numItems; ++i) {
+ if (atoms[i] == _NET_WM_STATE_HIDDEN) {
+ flags |= SDL_WINDOW_HIDDEN;
+ } else if (atoms[i] == _NET_WM_STATE_FOCUSED) {
+ flags |= SDL_WINDOW_INPUT_FOCUS;
+ } else if (atoms[i] == _NET_WM_STATE_MAXIMIZED_VERT) {
+ maximized |= 1;
+ } else if (atoms[i] == _NET_WM_STATE_MAXIMIZED_HORZ) {
+ maximized |= 2;
+ } else if ( atoms[i] == _NET_WM_STATE_FULLSCREEN) {
+ fullscreen = 1;
+ }
+ }
+ if (maximized == 3) {
+ flags |= SDL_WINDOW_MAXIMIZED;
+ }
+
+ if (fullscreen == 1) {
+ flags |= SDL_WINDOW_FULLSCREEN;
+ }
+
+ /* If the window is unmapped, numItems will be zero and _NET_WM_STATE_HIDDEN
+ * will not be set. Do an additional check to see if the window is unmapped
+ * and mark it as SDL_WINDOW_HIDDEN if it is.
+ */
+ {
+ XWindowAttributes attr;
+ SDL_memset(&attr,0,sizeof(attr));
+ X11_XGetWindowAttributes(videodata->display, xwindow, &attr);
+ if (attr.map_state == IsUnmapped) {
+ flags |= SDL_WINDOW_HIDDEN;
+ }
+ }
+ X11_XFree(propertyValue);
+ }
+
+ /* FIXME, check the size hints for resizable */
+ /* flags |= SDL_WINDOW_RESIZABLE; */
+
+ return flags;
+}
+
+static int
+SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created)
+{
+ SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
+ SDL_WindowData *data;
+ int numwindows = videodata->numwindows;
+ int windowlistlength = videodata->windowlistlength;
+ SDL_WindowData **windowlist = videodata->windowlist;
+
+ /* Allocate the window data */
+ data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
+ if (!data) {
+ return SDL_OutOfMemory();
+ }
+ data->window = window;
+ data->xwindow = w;
+#ifdef X_HAVE_UTF8_STRING
+ if (SDL_X11_HAVE_UTF8 && videodata->im) {
+ data->ic =
+ X11_XCreateIC(videodata->im, XNClientWindow, w, XNFocusWindow, w,
+ XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
+ NULL);
+ }
+#endif
+ data->created = created;
+ data->videodata = videodata;
+
+ /* Associate the data with the window */
+
+ if (numwindows < windowlistlength) {
+ windowlist[numwindows] = data;
+ videodata->numwindows++;
+ } else {
+ windowlist =
+ (SDL_WindowData **) SDL_realloc(windowlist,
+ (numwindows +
+ 1) * sizeof(*windowlist));
+ if (!windowlist) {
+ SDL_free(data);
+ return SDL_OutOfMemory();
+ }
+ windowlist[numwindows] = data;
+ videodata->numwindows++;
+ videodata->windowlistlength++;
+ videodata->windowlist = windowlist;
+ }
+
+ /* Fill in the SDL window with the window data */
+ {
+ XWindowAttributes attrib;
+
+ X11_XGetWindowAttributes(data->videodata->display, w, &attrib);
+ window->x = attrib.x;
+ window->y = attrib.y;
+ window->w = attrib.width;
+ window->h = attrib.height;
+ if (attrib.map_state != IsUnmapped) {
+ window->flags |= SDL_WINDOW_SHOWN;
+ } else {
+ window->flags &= ~SDL_WINDOW_SHOWN;
+ }
+ data->visual = attrib.visual;
+ data->colormap = attrib.colormap;
+ }
+
+ window->flags |= X11_GetNetWMState(_this, w);
+
+ {
+ Window FocalWindow;
+ int RevertTo=0;
+ X11_XGetInputFocus(data->videodata->display, &FocalWindow, &RevertTo);
+ if (FocalWindow==w)
+ {
+ window->flags |= SDL_WINDOW_INPUT_FOCUS;
+ }
+
+ if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
+ SDL_SetKeyboardFocus(data->window);
+ }
+
+ if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
+ /* Tell x11 to clip mouse */
+ }
+ }
+
+ /* All done! */
+ window->driverdata = data;
+ return 0;
+}
+
+static void
+SetWindowBordered(Display *display, int screen, Window window, SDL_bool border)
+{
+ /*
+ * this code used to check for KWM_WIN_DECORATION, but KDE hasn't
+ * supported it for years and years. It now respects _MOTIF_WM_HINTS.
+ * Gnome is similar: just use the Motif atom.
+ */
+
+ Atom WM_HINTS = X11_XInternAtom(display, "_MOTIF_WM_HINTS", True);
+ if (WM_HINTS != None) {
+ /* Hints used by Motif compliant window managers */
+ struct
+ {
+ unsigned long flags;
+ unsigned long functions;
+ unsigned long decorations;
+ long input_mode;
+ unsigned long status;
+ } MWMHints = {
+ (1L << 1), 0, border ? 1 : 0, 0, 0
+ };
+
+ X11_XChangeProperty(display, window, WM_HINTS, WM_HINTS, 32,
+ PropModeReplace, (unsigned char *) &MWMHints,
+ sizeof(MWMHints) / sizeof(long));
+ } else { /* set the transient hints instead, if necessary */
+ X11_XSetTransientForHint(display, window, RootWindow(display, screen));
+ }
+}
+
+int
+X11_CreateWindow(_THIS, SDL_Window * window)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+ SDL_DisplayData *displaydata =
+ (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
+ SDL_WindowData *windowdata;
+ Display *display = data->display;
+ int screen = displaydata->screen;
+ Visual *visual;
+ int depth;
+ XSetWindowAttributes xattr;
+ Window w;
+ XSizeHints *sizehints;
+ XWMHints *wmhints;
+ XClassHint *classhints;
+ Atom _NET_WM_BYPASS_COMPOSITOR;
+ Atom _NET_WM_WINDOW_TYPE;
+ Atom wintype;
+ const char *wintype_name = NULL;
+ long compositor = 1;
+ Atom _NET_WM_PID;
+ Atom XdndAware, xdnd_version = 5;
+ long fevent = 0;
+
+#if SDL_VIDEO_OPENGL_GLX || SDL_VIDEO_OPENGL_EGL
+ if ((window->flags & SDL_WINDOW_OPENGL) &&
+ !SDL_getenv("SDL_VIDEO_X11_VISUALID")) {
+ XVisualInfo *vinfo = NULL;
+
+#if SDL_VIDEO_OPENGL_EGL
+ if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
+#if SDL_VIDEO_OPENGL_GLX
+ && ( !_this->gl_data || X11_GL_UseEGL(_this) )
+#endif
+ ) {
+ vinfo = X11_GLES_GetVisual(_this, display, screen);
+ } else
+#endif
+ {
+#if SDL_VIDEO_OPENGL_GLX
+ vinfo = X11_GL_GetVisual(_this, display, screen);
+#endif
+ }
+
+ if (!vinfo) {
+ return -1;
+ }
+ visual = vinfo->visual;
+ depth = vinfo->depth;
+ X11_XFree(vinfo);
+ } else
+#endif
+ {
+ visual = displaydata->visual;
+ depth = displaydata->depth;
+ }
+
+ xattr.override_redirect = ((window->flags & SDL_WINDOW_TOOLTIP) || (window->flags & SDL_WINDOW_POPUP_MENU)) ? True : False;
+ xattr.background_pixmap = None;
+ xattr.border_pixel = 0;
+
+ if (visual->class == DirectColor) {
+ XColor *colorcells;
+ int i;
+ int ncolors;
+ int rmax, gmax, bmax;
+ int rmask, gmask, bmask;
+ int rshift, gshift, bshift;
+
+ xattr.colormap =
+ X11_XCreateColormap(display, RootWindow(display, screen),
+ visual, AllocAll);
+
+ /* If we can't create a colormap, then we must die */
+ if (!xattr.colormap) {
+ return SDL_SetError("Could not create writable colormap");
+ }
+
+ /* OK, we got a colormap, now fill it in as best as we can */
+ colorcells = SDL_malloc(visual->map_entries * sizeof(XColor));
+ if (!colorcells) {
+ return SDL_OutOfMemory();
+ }
+ ncolors = visual->map_entries;
+ rmax = 0xffff;
+ gmax = 0xffff;
+ bmax = 0xffff;
+
+ rshift = 0;
+ rmask = visual->red_mask;
+ while (0 == (rmask & 1)) {
+ rshift++;
+ rmask >>= 1;
+ }
+
+ gshift = 0;
+ gmask = visual->green_mask;
+ while (0 == (gmask & 1)) {
+ gshift++;
+ gmask >>= 1;
+ }
+
+ bshift = 0;
+ bmask = visual->blue_mask;
+ while (0 == (bmask & 1)) {
+ bshift++;
+ bmask >>= 1;
+ }
+
+ /* build the color table pixel values */
+ for (i = 0; i < ncolors; i++) {
+ Uint32 red = (rmax * i) / (ncolors - 1);
+ Uint32 green = (gmax * i) / (ncolors - 1);
+ Uint32 blue = (bmax * i) / (ncolors - 1);
+
+ Uint32 rbits = (rmask * i) / (ncolors - 1);
+ Uint32 gbits = (gmask * i) / (ncolors - 1);
+ Uint32 bbits = (bmask * i) / (ncolors - 1);
+
+ Uint32 pix =
+ (rbits << rshift) | (gbits << gshift) | (bbits << bshift);
+
+ colorcells[i].pixel = pix;
+
+ colorcells[i].red = red;
+ colorcells[i].green = green;
+ colorcells[i].blue = blue;
+
+ colorcells[i].flags = DoRed | DoGreen | DoBlue;
+ }
+
+ X11_XStoreColors(display, xattr.colormap, colorcells, ncolors);
+
+ SDL_free(colorcells);
+ } else {
+ xattr.colormap =
+ X11_XCreateColormap(display, RootWindow(display, screen),
+ visual, AllocNone);
+ }
+
+ w = X11_XCreateWindow(display, RootWindow(display, screen),
+ window->x, window->y, window->w, window->h,
+ 0, depth, InputOutput, visual,
+ (CWOverrideRedirect | CWBackPixmap | CWBorderPixel |
+ CWColormap), &xattr);
+ if (!w) {
+ return SDL_SetError("Couldn't create window");
+ }
+
+ SetWindowBordered(display, screen, w,
+ (window->flags & SDL_WINDOW_BORDERLESS) == 0);
+
+ sizehints = X11_XAllocSizeHints();
+ /* Setup the normal size hints */
+ sizehints->flags = 0;
+ if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
+ sizehints->min_width = sizehints->max_width = window->w;
+ sizehints->min_height = sizehints->max_height = window->h;
+ sizehints->flags |= (PMaxSize | PMinSize);
+ }
+ sizehints->x = window->x;
+ sizehints->y = window->y;
+ sizehints->flags |= USPosition;
+
+ /* Setup the input hints so we get keyboard input */
+ wmhints = X11_XAllocWMHints();
+ wmhints->input = True;
+ wmhints->window_group = data->window_group;
+ wmhints->flags = InputHint | WindowGroupHint;
+
+ /* Setup the class hints so we can get an icon (AfterStep) */
+ classhints = X11_XAllocClassHint();
+ classhints->res_name = data->classname;
+ classhints->res_class = data->classname;
+
+ /* Set the size, input and class hints, and define WM_CLIENT_MACHINE and WM_LOCALE_NAME */
+ X11_XSetWMProperties(display, w, NULL, NULL, NULL, 0, sizehints, wmhints, classhints);
+
+ X11_XFree(sizehints);
+ X11_XFree(wmhints);
+ X11_XFree(classhints);
+ /* Set the PID related to the window for the given hostname, if possible */
+ if (data->pid > 0) {
+ long pid = (long) data->pid;
+ _NET_WM_PID = X11_XInternAtom(display, "_NET_WM_PID", False);
+ X11_XChangeProperty(display, w, _NET_WM_PID, XA_CARDINAL, 32, PropModeReplace,
+ (unsigned char *) &pid, 1);
+ }
+
+ /* Set the window manager state */
+ X11_SetNetWMState(_this, w, window->flags);
+
+ compositor = 2; /* don't disable compositing except for "normal" windows */
+
+ if (window->flags & SDL_WINDOW_UTILITY) {
+ wintype_name = "_NET_WM_WINDOW_TYPE_UTILITY";
+ } else if (window->flags & SDL_WINDOW_TOOLTIP) {
+ wintype_name = "_NET_WM_WINDOW_TYPE_TOOLTIP";
+ } else if (window->flags & SDL_WINDOW_POPUP_MENU) {
+ wintype_name = "_NET_WM_WINDOW_TYPE_POPUP_MENU";
+ } else {
+ wintype_name = "_NET_WM_WINDOW_TYPE_NORMAL";
+ compositor = 1; /* disable compositing for "normal" windows */
+ }
+
+ /* Let the window manager know what type of window we are. */
+ _NET_WM_WINDOW_TYPE = X11_XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
+ wintype = X11_XInternAtom(display, wintype_name, False);
+ X11_XChangeProperty(display, w, _NET_WM_WINDOW_TYPE, XA_ATOM, 32,
+ PropModeReplace, (unsigned char *)&wintype, 1);
+ if (SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, SDL_TRUE)) {
+ _NET_WM_BYPASS_COMPOSITOR = X11_XInternAtom(display, "_NET_WM_BYPASS_COMPOSITOR", False);
+ X11_XChangeProperty(display, w, _NET_WM_BYPASS_COMPOSITOR, XA_CARDINAL, 32,
+ PropModeReplace,
+ (unsigned char *)&compositor, 1);
+ }
+
+ {
+ Atom protocols[3];
+ int proto_count = 0;
+
+ protocols[proto_count++] = data->WM_DELETE_WINDOW; /* Allow window to be deleted by the WM */
+ protocols[proto_count++] = data->WM_TAKE_FOCUS; /* Since we will want to set input focus explicitly */
+
+ /* Default to using ping if there is no hint */
+ if (SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_NET_WM_PING, SDL_TRUE)) {
+ protocols[proto_count++] = data->_NET_WM_PING; /* Respond so WM knows we're alive */
+ }
+
+ SDL_assert(proto_count <= sizeof(protocols) / sizeof(protocols[0]));
+
+ X11_XSetWMProtocols(display, w, protocols, proto_count);
+ }
+
+ if (SetupWindowData(_this, window, w, SDL_TRUE) < 0) {
+ X11_XDestroyWindow(display, w);
+ return -1;
+ }
+ windowdata = (SDL_WindowData *) window->driverdata;
+
+#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
+ if ((window->flags & SDL_WINDOW_OPENGL) &&
+ _this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
+#if SDL_VIDEO_OPENGL_GLX
+ && ( !_this->gl_data || X11_GL_UseEGL(_this) )
+#endif
+ ) {
+#if SDL_VIDEO_OPENGL_EGL
+ if (!_this->egl_data) {
+ X11_XDestroyWindow(display, w);
+ return -1;
+ }
+
+ /* Create the GLES window surface */
+ windowdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) w);
+
+ if (windowdata->egl_surface == EGL_NO_SURFACE) {
+ X11_XDestroyWindow(display, w);
+ return SDL_SetError("Could not create GLES window surface");
+ }
+#else
+ return SDL_SetError("Could not create GLES window surface (EGL support not configured)");
+#endif /* SDL_VIDEO_OPENGL_EGL */
+ }
+#endif
+
+
+#ifdef X_HAVE_UTF8_STRING
+ if (SDL_X11_HAVE_UTF8 && windowdata->ic) {
+ X11_XGetICValues(windowdata->ic, XNFilterEvents, &fevent, NULL);
+ }
+#endif
+
+ X11_Xinput2SelectTouch(_this, window);
+
+ X11_XSelectInput(display, w,
+ (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
+ ExposureMask | ButtonPressMask | ButtonReleaseMask |
+ PointerMotionMask | KeyPressMask | KeyReleaseMask |
+ PropertyChangeMask | StructureNotifyMask |
+ KeymapStateMask | fevent));
+
+ XdndAware = X11_XInternAtom(display, "XdndAware", False);
+ X11_XChangeProperty(display, w, XdndAware, XA_ATOM, 32,
+ PropModeReplace,
+ (unsigned char*)&xdnd_version, 1);
+
+ X11_XFlush(display);
+
+ return 0;
+}
+
+int
+X11_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
+{
+ Window w = (Window) data;
+
+ window->title = X11_GetWindowTitle(_this, w);
+
+ if (SetupWindowData(_this, window, w, SDL_FALSE) < 0) {
+ return -1;
+ }
+ return 0;
+}
+
+char *
+X11_GetWindowTitle(_THIS, Window xwindow)
+{
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+ Display *display = data->display;
+ int status, real_format;
+ Atom real_type;
+ unsigned long items_read, items_left;
+ unsigned char *propdata;
+ char *title = NULL;
+
+ status = X11_XGetWindowProperty(display, xwindow, data->_NET_WM_NAME,
+ 0L, 8192L, False, data->UTF8_STRING, &real_type, &real_format,
+ &items_read, &items_left, &propdata);
+ if (status == Success && propdata) {
+ title = SDL_strdup(SDL_static_cast(char*, propdata));
+ X11_XFree(propdata);
+ } else {
+ status = X11_XGetWindowProperty(display, xwindow, XA_WM_NAME,
+ 0L, 8192L, False, XA_STRING, &real_type, &real_format,
+ &items_read, &items_left, &propdata);
+ if (status == Success && propdata) {
+ title = SDL_iconv_string("UTF-8", "", SDL_static_cast(char*, propdata), items_read+1);
+ X11_XFree(propdata);
+ } else {
+ title = SDL_strdup("");
+ }
+ }
+ return title;
+}
+
+void
+X11_SetWindowTitle(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+ XTextProperty titleprop;
+ Status status;
+ const char *title = window->title ? window->title : "";
+ char *title_locale = NULL;
+
+#ifdef X_HAVE_UTF8_STRING
+ Atom _NET_WM_NAME = data->videodata->_NET_WM_NAME;
+#endif
+
+ title_locale = SDL_iconv_utf8_locale(title);
+ if (!title_locale) {
+ SDL_OutOfMemory();
+ return;
+ }
+
+ status = X11_XStringListToTextProperty(&title_locale, 1, &titleprop);
+ SDL_free(title_locale);
+ if (status) {
+ X11_XSetTextProperty(display, data->xwindow, &titleprop, XA_WM_NAME);
+ X11_XFree(titleprop.value);
+ }
+#ifdef X_HAVE_UTF8_STRING
+ if (SDL_X11_HAVE_UTF8) {
+ status = X11_Xutf8TextListToTextProperty(display, (char **) &title, 1,
+ XUTF8StringStyle, &titleprop);
+ if (status == Success) {
+ X11_XSetTextProperty(display, data->xwindow, &titleprop,
+ _NET_WM_NAME);
+ X11_XFree(titleprop.value);
+ }
+ }
+#endif
+
+ X11_XFlush(display);
+}
+
+void
+X11_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+ Atom _NET_WM_ICON = data->videodata->_NET_WM_ICON;
+
+ if (icon) {
+ int propsize;
+ long *propdata;
+
+ /* Set the _NET_WM_ICON property */
+ SDL_assert(icon->format->format == SDL_PIXELFORMAT_ARGB8888);
+ propsize = 2 + (icon->w * icon->h);
+ propdata = SDL_malloc(propsize * sizeof(long));
+ if (propdata) {
+ int x, y;
+ Uint32 *src;
+ long *dst;
+
+ propdata[0] = icon->w;
+ propdata[1] = icon->h;
+ dst = &propdata[2];
+ for (y = 0; y < icon->h; ++y) {
+ src = (Uint32*)((Uint8*)icon->pixels + y * icon->pitch);
+ for (x = 0; x < icon->w; ++x) {
+ *dst++ = *src++;
+ }
+ }
+ X11_XChangeProperty(display, data->xwindow, _NET_WM_ICON, XA_CARDINAL,
+ 32, PropModeReplace, (unsigned char *) propdata,
+ propsize);
+ }
+ SDL_free(propdata);
+ } else {
+ X11_XDeleteProperty(display, data->xwindow, _NET_WM_ICON);
+ }
+ X11_XFlush(display);
+}
+
+void
+X11_SetWindowPosition(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+
+ X11_XMoveWindow(display, data->xwindow, window->x - data->border_left, window->y - data->border_top);
+ X11_XFlush(display);
+}
+
+void
+X11_SetWindowMinimumSize(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+
+ if (window->flags & SDL_WINDOW_RESIZABLE) {
+ XSizeHints *sizehints = X11_XAllocSizeHints();
+ long userhints;
+
+ X11_XGetWMNormalHints(display, data->xwindow, sizehints, &userhints);
+
+ sizehints->min_width = window->min_w;
+ sizehints->min_height = window->min_h;
+ sizehints->flags |= PMinSize;
+
+ X11_XSetWMNormalHints(display, data->xwindow, sizehints);
+
+ X11_XFree(sizehints);
+
+ /* See comment in X11_SetWindowSize. */
+ X11_XResizeWindow(display, data->xwindow, window->w, window->h);
+ X11_XMoveWindow(display, data->xwindow, window->x - data->border_left, window->y - data->border_top);
+ X11_XRaiseWindow(display, data->xwindow);
+ }
+
+ X11_XFlush(display);
+}
+
+void
+X11_SetWindowMaximumSize(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+
+ if (window->flags & SDL_WINDOW_RESIZABLE) {
+ XSizeHints *sizehints = X11_XAllocSizeHints();
+ long userhints;
+
+ X11_XGetWMNormalHints(display, data->xwindow, sizehints, &userhints);
+
+ sizehints->max_width = window->max_w;
+ sizehints->max_height = window->max_h;
+ sizehints->flags |= PMaxSize;
+
+ X11_XSetWMNormalHints(display, data->xwindow, sizehints);
+
+ X11_XFree(sizehints);
+
+ /* See comment in X11_SetWindowSize. */
+ X11_XResizeWindow(display, data->xwindow, window->w, window->h);
+ X11_XMoveWindow(display, data->xwindow, window->x - data->border_left, window->y - data->border_top);
+ X11_XRaiseWindow(display, data->xwindow);
+ }
+
+ X11_XFlush(display);
+}
+
+void
+X11_SetWindowSize(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+
+ if (SDL_IsShapedWindow(window)) {
+ X11_ResizeWindowShape(window);
+ }
+ if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
+ /* Apparently, if the X11 Window is set to a 'non-resizable' window, you cannot resize it using the X11_XResizeWindow, thus
+ we must set the size hints to adjust the window size. */
+ XSizeHints *sizehints = X11_XAllocSizeHints();
+ long userhints;
+
+ X11_XGetWMNormalHints(display, data->xwindow, sizehints, &userhints);
+
+ sizehints->min_width = sizehints->max_width = window->w;
+ sizehints->min_height = sizehints->max_height = window->h;
+ sizehints->flags |= PMinSize | PMaxSize;
+
+ X11_XSetWMNormalHints(display, data->xwindow, sizehints);
+
+ X11_XFree(sizehints);
+
+ /* From Pierre-Loup:
+ WMs each have their little quirks with that. When you change the
+ size hints, they get a ConfigureNotify event with the
+ WM_NORMAL_SIZE_HINTS Atom. They all save the hints then, but they
+ don't all resize the window right away to enforce the new hints.
+
+ Some of them resize only after:
+ - A user-initiated move or resize
+ - A code-initiated move or resize
+ - Hiding & showing window (Unmap & map)
+
+ The following move & resize seems to help a lot of WMs that didn't
+ properly update after the hints were changed. We don't do a
+ hide/show, because there are supposedly subtle problems with doing so
+ and transitioning from windowed to fullscreen in Unity.
+ */
+ X11_XResizeWindow(display, data->xwindow, window->w, window->h);
+ X11_XMoveWindow(display, data->xwindow, window->x - data->border_left, window->y - data->border_top);
+ X11_XRaiseWindow(display, data->xwindow);
+ } else {
+ X11_XResizeWindow(display, data->xwindow, window->w, window->h);
+ }
+
+ X11_XFlush(display);
+}
+
+int
+X11_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right)
+{
+ SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+
+ *left = data->border_left;
+ *right = data->border_right;
+ *top = data->border_top;
+ *bottom = data->border_bottom;
+
+ return 0;
+}
+
+int
+X11_SetWindowOpacity(_THIS, SDL_Window * window, float opacity)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+ Atom _NET_WM_WINDOW_OPACITY = data->videodata->_NET_WM_WINDOW_OPACITY;
+
+ if (opacity == 1.0f) {
+ X11_XDeleteProperty(display, data->xwindow, _NET_WM_WINDOW_OPACITY);
+ } else {
+ const Uint32 FullyOpaque = 0xFFFFFFFF;
+ const long alpha = (long) ((double)opacity * (double)FullyOpaque);
+ X11_XChangeProperty(display, data->xwindow, _NET_WM_WINDOW_OPACITY, XA_CARDINAL, 32,
+ PropModeReplace, (unsigned char *)&alpha, 1);
+ }
+
+ return 0;
+}
+
+int
+X11_SetWindowModalFor(_THIS, SDL_Window * modal_window, SDL_Window * parent_window) {
+ SDL_WindowData *data = (SDL_WindowData *) modal_window->driverdata;
+ SDL_WindowData *parent_data = (SDL_WindowData *) parent_window->driverdata;
+ Display *display = data->videodata->display;
+
+ X11_XSetTransientForHint(display, data->xwindow, parent_data->xwindow);
+ return 0;
+}
+
+int
+X11_SetWindowInputFocus(_THIS, SDL_Window * window)
+{
+ if (X11_IsWindowMapped(_this, window)) {
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+ X11_XSetInputFocus(display, data->xwindow, RevertToNone, CurrentTime);
+ X11_XFlush(display);
+ return 0;
+ }
+ return -1;
+}
+
+void
+X11_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
+{
+ const SDL_bool focused = ((window->flags & SDL_WINDOW_INPUT_FOCUS) != 0);
+ const SDL_bool visible = ((window->flags & SDL_WINDOW_HIDDEN) == 0);
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ SDL_DisplayData *displaydata =
+ (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
+ Display *display = data->videodata->display;
+ XEvent event;
+
+ SetWindowBordered(display, displaydata->screen, data->xwindow, bordered);
+ X11_XFlush(display);
+
+ if (visible) {
+ XWindowAttributes attr;
+ do {
+ X11_XSync(display, False);
+ X11_XGetWindowAttributes(display, data->xwindow, &attr);
+ } while (attr.map_state != IsViewable);
+
+ if (focused) {
+ X11_XSetInputFocus(display, data->xwindow, RevertToParent, CurrentTime);
+ }
+ }
+
+ /* make sure these don't make it to the real event queue if they fired here. */
+ X11_XSync(display, False);
+ X11_XCheckIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
+ X11_XCheckIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
+}
+
+void
+X11_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+
+ XSizeHints *sizehints = X11_XAllocSizeHints();
+ long userhints;
+
+ X11_XGetWMNormalHints(display, data->xwindow, sizehints, &userhints);
+
+ if (resizable) {
+ /* FIXME: Is there a better way to get max window size from X? -flibit */
+ const int maxsize = 0x7FFFFFFF;
+ sizehints->min_width = window->min_w;
+ sizehints->min_height = window->min_h;
+ sizehints->max_width = (window->max_w == 0) ? maxsize : window->max_w;
+ sizehints->max_height = (window->max_h == 0) ? maxsize : window->max_h;
+ } else {
+ sizehints->min_width = window->w;
+ sizehints->min_height = window->h;
+ sizehints->max_width = window->w;
+ sizehints->max_height = window->h;
+ }
+ sizehints->flags |= PMinSize | PMaxSize;
+
+ X11_XSetWMNormalHints(display, data->xwindow, sizehints);
+
+ X11_XFree(sizehints);
+
+ /* See comment in X11_SetWindowSize. */
+ X11_XResizeWindow(display, data->xwindow, window->w, window->h);
+ X11_XMoveWindow(display, data->xwindow, window->x - data->border_left, window->y - data->border_top);
+ X11_XRaiseWindow(display, data->xwindow);
+
+ X11_XFlush(display);
+}
+
+void
+X11_ShowWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+ XEvent event;
+
+ if (!X11_IsWindowMapped(_this, window)) {
+ X11_XMapRaised(display, data->xwindow);
+ /* Blocking wait for "MapNotify" event.
+ * We use X11_XIfEvent because pXWindowEvent takes a mask rather than a type,
+ * and XCheckTypedWindowEvent doesn't block */
+ if(!(window->flags & SDL_WINDOW_FOREIGN))
+ X11_XIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
+ X11_XFlush(display);
+ }
+
+ if (!data->videodata->net_wm) {
+ /* no WM means no FocusIn event, which confuses us. Force it. */
+ X11_XSetInputFocus(display, data->xwindow, RevertToNone, CurrentTime);
+ X11_XFlush(display);
+ }
+}
+
+void
+X11_HideWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
+ Display *display = data->videodata->display;
+ XEvent event;
+
+ if (X11_IsWindowMapped(_this, window)) {
+ X11_XWithdrawWindow(display, data->xwindow, displaydata->screen);
+ /* Blocking wait for "UnmapNotify" event */
+ if(!(window->flags & SDL_WINDOW_FOREIGN))
+ X11_XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
+ X11_XFlush(display);
+ }
+}
+
+static void
+SetWindowActive(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ SDL_DisplayData *displaydata =
+ (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
+ Display *display = data->videodata->display;
+ Atom _NET_ACTIVE_WINDOW = data->videodata->_NET_ACTIVE_WINDOW;
+
+ if (X11_IsWindowMapped(_this, window)) {
+ XEvent e;
+
+ /*printf("SDL Window %p: sending _NET_ACTIVE_WINDOW with timestamp %lu\n", window, data->user_time);*/
+
+ SDL_zero(e);
+ e.xany.type = ClientMessage;
+ e.xclient.message_type = _NET_ACTIVE_WINDOW;
+ e.xclient.format = 32;
+ e.xclient.window = data->xwindow;
+ e.xclient.data.l[0] = 1; /* source indication. 1 = application */
+ e.xclient.data.l[1] = data->user_time;
+ e.xclient.data.l[2] = 0;
+
+ X11_XSendEvent(display, RootWindow(display, displaydata->screen), 0,
+ SubstructureNotifyMask | SubstructureRedirectMask, &e);
+
+ X11_XFlush(display);
+ }
+}
+
+void
+X11_RaiseWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+
+ X11_XRaiseWindow(display, data->xwindow);
+ SetWindowActive(_this, window);
+ X11_XFlush(display);
+}
+
+static void
+SetWindowMaximized(_THIS, SDL_Window * window, SDL_bool maximized)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ SDL_DisplayData *displaydata =
+ (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
+ Display *display = data->videodata->display;
+ Atom _NET_WM_STATE = data->videodata->_NET_WM_STATE;
+ Atom _NET_WM_STATE_MAXIMIZED_VERT = data->videodata->_NET_WM_STATE_MAXIMIZED_VERT;
+ Atom _NET_WM_STATE_MAXIMIZED_HORZ = data->videodata->_NET_WM_STATE_MAXIMIZED_HORZ;
+
+ if (maximized) {
+ window->flags |= SDL_WINDOW_MAXIMIZED;
+ } else {
+ window->flags &= ~SDL_WINDOW_MAXIMIZED;
+ }
+
+ if (X11_IsWindowMapped(_this, window)) {
+ XEvent e;
+
+ SDL_zero(e);
+ e.xany.type = ClientMessage;
+ e.xclient.message_type = _NET_WM_STATE;
+ e.xclient.format = 32;
+ e.xclient.window = data->xwindow;
+ e.xclient.data.l[0] =
+ maximized ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
+ e.xclient.data.l[1] = _NET_WM_STATE_MAXIMIZED_VERT;
+ e.xclient.data.l[2] = _NET_WM_STATE_MAXIMIZED_HORZ;
+ e.xclient.data.l[3] = 0l;
+
+ X11_XSendEvent(display, RootWindow(display, displaydata->screen), 0,
+ SubstructureNotifyMask | SubstructureRedirectMask, &e);
+ } else {
+ X11_SetNetWMState(_this, data->xwindow, window->flags);
+ }
+ X11_XFlush(display);
+}
+
+void
+X11_MaximizeWindow(_THIS, SDL_Window * window)
+{
+ SetWindowMaximized(_this, window, SDL_TRUE);
+}
+
+void
+X11_MinimizeWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ SDL_DisplayData *displaydata =
+ (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
+ Display *display = data->videodata->display;
+
+ X11_XIconifyWindow(display, data->xwindow, displaydata->screen);
+ X11_XFlush(display);
+}
+
+void
+X11_RestoreWindow(_THIS, SDL_Window * window)
+{
+ SetWindowMaximized(_this, window, SDL_FALSE);
+ X11_ShowWindow(_this, window);
+ SetWindowActive(_this, window);
+}
+
+/* This asks the Window Manager to handle fullscreen for us. This is the modern way. */
+static void
+X11_SetWindowFullscreenViaWM(_THIS, SDL_Window * window, SDL_VideoDisplay * _display, SDL_bool fullscreen)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ SDL_DisplayData *displaydata = (SDL_DisplayData *) _display->driverdata;
+ Display *display = data->videodata->display;
+ Atom _NET_WM_STATE = data->videodata->_NET_WM_STATE;
+ Atom _NET_WM_STATE_FULLSCREEN = data->videodata->_NET_WM_STATE_FULLSCREEN;
+
+ if (X11_IsWindowMapped(_this, window)) {
+ XEvent e;
+
+ if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
+ /* Compiz refuses fullscreen toggle if we're not resizable, so update the hints so we
+ can be resized to the fullscreen resolution (or reset so we're not resizable again) */
+ XSizeHints *sizehints = X11_XAllocSizeHints();
+ long flags = 0;
+ X11_XGetWMNormalHints(display, data->xwindow, sizehints, &flags);
+ /* set the resize flags on */
+ if (fullscreen) {
+ /* we are going fullscreen so turn the flags off */
+ sizehints->flags &= ~(PMinSize | PMaxSize);
+ } else {
+ /* Reset the min/max width height to make the window non-resizable again */
+ sizehints->flags |= PMinSize | PMaxSize;
+ sizehints->min_width = sizehints->max_width = window->windowed.w;
+ sizehints->min_height = sizehints->max_height = window->windowed.h;
+ }
+ X11_XSetWMNormalHints(display, data->xwindow, sizehints);
+ X11_XFree(sizehints);
+ }
+
+ SDL_zero(e);
+ e.xany.type = ClientMessage;
+ e.xclient.message_type = _NET_WM_STATE;
+ e.xclient.format = 32;
+ e.xclient.window = data->xwindow;
+ e.xclient.data.l[0] =
+ fullscreen ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
+ e.xclient.data.l[1] = _NET_WM_STATE_FULLSCREEN;
+ e.xclient.data.l[3] = 0l;
+
+ X11_XSendEvent(display, RootWindow(display, displaydata->screen), 0,
+ SubstructureNotifyMask | SubstructureRedirectMask, &e);
+
+ /* Fullscreen windows sometimes end up being marked maximized by
+ window managers. Force it back to how we expect it to be. */
+ if (!fullscreen && ((window->flags & SDL_WINDOW_MAXIMIZED) == 0)) {
+ SDL_zero(e);
+ e.xany.type = ClientMessage;
+ e.xclient.message_type = _NET_WM_STATE;
+ e.xclient.format = 32;
+ e.xclient.window = data->xwindow;
+ e.xclient.data.l[0] = _NET_WM_STATE_REMOVE;
+ e.xclient.data.l[1] = data->videodata->_NET_WM_STATE_MAXIMIZED_VERT;
+ e.xclient.data.l[2] = data->videodata->_NET_WM_STATE_MAXIMIZED_HORZ;
+ e.xclient.data.l[3] = 0l;
+ X11_XSendEvent(display, RootWindow(display, displaydata->screen), 0,
+ SubstructureNotifyMask | SubstructureRedirectMask, &e);
+ }
+ } else {
+ Uint32 flags;
+
+ flags = window->flags;
+ if (fullscreen) {
+ flags |= SDL_WINDOW_FULLSCREEN;
+ } else {
+ flags &= ~SDL_WINDOW_FULLSCREEN;
+ }
+ X11_SetNetWMState(_this, data->xwindow, flags);
+ }
+
+ if (data->visual->class == DirectColor) {
+ if ( fullscreen ) {
+ X11_XInstallColormap(display, data->colormap);
+ } else {
+ X11_XUninstallColormap(display, data->colormap);
+ }
+ }
+
+ X11_XFlush(display);
+}
+
+/* This handles fullscreen itself, outside the Window Manager. */
+static void
+X11_BeginWindowFullscreenLegacy(_THIS, SDL_Window * window, SDL_VideoDisplay * _display)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ SDL_DisplayData *displaydata = (SDL_DisplayData *) _display->driverdata;
+ Visual *visual = data->visual;
+ Display *display = data->videodata->display;
+ const int screen = displaydata->screen;
+ Window root = RootWindow(display, screen);
+ const int def_vis = (visual == DefaultVisual(display, screen));
+ unsigned long xattrmask = 0;
+ XSetWindowAttributes xattr;
+ XEvent ev;
+ SDL_Rect rect;
+
+ if ( data->fswindow ) {
+ return; /* already fullscreen, I hope. */
+ }
+
+ X11_GetDisplayBounds(_this, _display, &rect);
+
+ SDL_zero(xattr);
+ xattr.override_redirect = True;
+ xattrmask |= CWOverrideRedirect;
+ xattr.background_pixel = def_vis ? BlackPixel(display, screen) : 0;
+ xattrmask |= CWBackPixel;
+ xattr.border_pixel = 0;
+ xattrmask |= CWBorderPixel;
+ xattr.colormap = data->colormap;
+ xattrmask |= CWColormap;
+
+ data->fswindow = X11_XCreateWindow(display, root,
+ rect.x, rect.y, rect.w, rect.h, 0,
+ displaydata->depth, InputOutput,
+ visual, xattrmask, &xattr);
+
+ X11_XSelectInput(display, data->fswindow, StructureNotifyMask);
+ X11_XSetWindowBackground(display, data->fswindow, 0);
+ X11_XInstallColormap(display, data->colormap);
+ X11_XClearWindow(display, data->fswindow);
+ X11_XMapRaised(display, data->fswindow);
+
+ /* Make sure the fswindow is in view by warping mouse to the corner */
+ X11_XUngrabPointer(display, CurrentTime);
+ X11_XWarpPointer(display, None, root, 0, 0, 0, 0, rect.x, rect.y);
+
+ /* Wait to be mapped, filter Unmap event out if it arrives. */
+ X11_XIfEvent(display, &ev, &isMapNotify, (XPointer)&data->fswindow);
+ X11_XCheckIfEvent(display, &ev, &isUnmapNotify, (XPointer)&data->fswindow);
+
+#if SDL_VIDEO_DRIVER_X11_XVIDMODE
+ if ( displaydata->use_vidmode ) {
+ X11_XF86VidModeLockModeSwitch(display, screen, True);
+ }
+#endif
+
+ SetWindowBordered(display, displaydata->screen, data->xwindow, SDL_FALSE);
+
+ /* Center actual window within our cover-the-screen window. */
+ X11_XReparentWindow(display, data->xwindow, data->fswindow,
+ (rect.w - window->w) / 2, (rect.h - window->h) / 2);
+
+ /* Move the mouse to the upper left to make sure it's on-screen */
+ X11_XWarpPointer(display, None, root, 0, 0, 0, 0, rect.x, rect.y);
+
+ /* Center mouse in the fullscreen window. */
+ rect.x += (rect.w / 2);
+ rect.y += (rect.h / 2);
+ X11_XWarpPointer(display, None, root, 0, 0, 0, 0, rect.x, rect.y);
+
+ /* Wait to be mapped, filter Unmap event out if it arrives. */
+ X11_XIfEvent(display, &ev, &isMapNotify, (XPointer)&data->xwindow);
+ X11_XCheckIfEvent(display, &ev, &isUnmapNotify, (XPointer)&data->xwindow);
+
+ SDL_UpdateWindowGrab(window);
+}
+
+static void
+X11_EndWindowFullscreenLegacy(_THIS, SDL_Window * window, SDL_VideoDisplay * _display)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ SDL_DisplayData *displaydata = (SDL_DisplayData *) _display->driverdata;
+ Display *display = data->videodata->display;
+ const int screen = displaydata->screen;
+ Window root = RootWindow(display, screen);
+ Window fswindow = data->fswindow;
+ XEvent ev;
+
+ if (!data->fswindow) {
+ return; /* already not fullscreen, I hope. */
+ }
+
+ data->fswindow = None;
+
+#if SDL_VIDEO_DRIVER_X11_VIDMODE
+ if ( displaydata->use_vidmode ) {
+ X11_XF86VidModeLockModeSwitch(display, screen, False);
+ }
+#endif
+
+ SDL_UpdateWindowGrab(window);
+
+ X11_XReparentWindow(display, data->xwindow, root, window->x, window->y);
+
+ /* flush these events so they don't confuse normal event handling */
+ X11_XSync(display, False);
+ X11_XCheckIfEvent(display, &ev, &isMapNotify, (XPointer)&data->xwindow);
+ X11_XCheckIfEvent(display, &ev, &isUnmapNotify, (XPointer)&data->xwindow);
+
+ SetWindowBordered(display, screen, data->xwindow,
+ (window->flags & SDL_WINDOW_BORDERLESS) == 0);
+
+ X11_XWithdrawWindow(display, fswindow, screen);
+
+ /* Wait to be unmapped. */
+ X11_XIfEvent(display, &ev, &isUnmapNotify, (XPointer)&fswindow);
+ X11_XDestroyWindow(display, fswindow);
+}
+
+
+void
+X11_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * _display, SDL_bool fullscreen)
+{
+ /* !!! FIXME: SDL_Hint? */
+ SDL_bool legacy = SDL_FALSE;
+ const char *env = SDL_getenv("SDL_VIDEO_X11_LEGACY_FULLSCREEN");
+ if (env) {
+ legacy = SDL_atoi(env);
+ } else {
+ SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
+ SDL_DisplayData *displaydata = (SDL_DisplayData *) _display->driverdata;
+ if ( displaydata->use_vidmode ) {
+ legacy = SDL_TRUE; /* the new stuff only works with XRandR. */
+ } else if ( !videodata->net_wm ) {
+ legacy = SDL_TRUE; /* The window manager doesn't support it */
+ } else {
+ /* !!! FIXME: look at the window manager name, and blacklist certain ones? */
+ /* http://stackoverflow.com/questions/758648/find-the-name-of-the-x-window-manager */
+ legacy = SDL_FALSE; /* try the new way. */
+ }
+ }
+
+ if (legacy) {
+ if (fullscreen) {
+ X11_BeginWindowFullscreenLegacy(_this, window, _display);
+ } else {
+ X11_EndWindowFullscreenLegacy(_this, window, _display);
+ }
+ } else {
+ X11_SetWindowFullscreenViaWM(_this, window, _display, fullscreen);
+ }
+}
+
+
+int
+X11_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+ Visual *visual = data->visual;
+ Colormap colormap = data->colormap;
+ XColor *colorcells;
+ int ncolors;
+ int rmask, gmask, bmask;
+ int rshift, gshift, bshift;
+ int i;
+
+ if (visual->class != DirectColor) {
+ return SDL_SetError("Window doesn't have DirectColor visual");
+ }
+
+ ncolors = visual->map_entries;
+ colorcells = SDL_malloc(ncolors * sizeof(XColor));
+ if (!colorcells) {
+ return SDL_OutOfMemory();
+ }
+
+ rshift = 0;
+ rmask = visual->red_mask;
+ while (0 == (rmask & 1)) {
+ rshift++;
+ rmask >>= 1;
+ }
+
+ gshift = 0;
+ gmask = visual->green_mask;
+ while (0 == (gmask & 1)) {
+ gshift++;
+ gmask >>= 1;
+ }
+
+ bshift = 0;
+ bmask = visual->blue_mask;
+ while (0 == (bmask & 1)) {
+ bshift++;
+ bmask >>= 1;
+ }
+
+ /* build the color table pixel values */
+ for (i = 0; i < ncolors; i++) {
+ Uint32 rbits = (rmask * i) / (ncolors - 1);
+ Uint32 gbits = (gmask * i) / (ncolors - 1);
+ Uint32 bbits = (bmask * i) / (ncolors - 1);
+ Uint32 pix = (rbits << rshift) | (gbits << gshift) | (bbits << bshift);
+
+ colorcells[i].pixel = pix;
+
+ colorcells[i].red = ramp[(0 * 256) + i];
+ colorcells[i].green = ramp[(1 * 256) + i];
+ colorcells[i].blue = ramp[(2 * 256) + i];
+
+ colorcells[i].flags = DoRed | DoGreen | DoBlue;
+ }
+
+ X11_XStoreColors(display, colormap, colorcells, ncolors);
+ X11_XFlush(display);
+ SDL_free(colorcells);
+
+ return 0;
+}
+
+void
+X11_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+ SDL_bool oldstyle_fullscreen;
+ SDL_bool grab_keyboard;
+
+ /* ICCCM2.0-compliant window managers can handle fullscreen windows
+ If we're using XVidMode to change resolution we need to confine
+ the cursor so we don't pan around the virtual desktop.
+ */
+ oldstyle_fullscreen = X11_IsWindowLegacyFullscreen(_this, window);
+
+ if (oldstyle_fullscreen || grabbed) {
+ /* Try to grab the mouse */
+ if (!data->videodata->broken_pointer_grab) {
+ const unsigned int mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask;
+ int attempts;
+ int result;
+
+ /* Try for up to 5000ms (5s) to grab. If it still fails, stop trying. */
+ for (attempts = 0; attempts < 100; attempts++) {
+ result = X11_XGrabPointer(display, data->xwindow, True, mask, GrabModeAsync,
+ GrabModeAsync, data->xwindow, None, CurrentTime);
+ if (result == GrabSuccess) {
+ break;
+ }
+ SDL_Delay(50);
+ }
+
+ if (result != GrabSuccess) {
+ SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "The X server refused to let us grab the mouse. You might experience input bugs.");
+ data->videodata->broken_pointer_grab = SDL_TRUE; /* don't try again. */
+ }
+ }
+
+ /* Raise the window if we grab the mouse */
+ X11_XRaiseWindow(display, data->xwindow);
+
+ /* Now grab the keyboard */
+ if (SDL_GetHintBoolean(SDL_HINT_GRAB_KEYBOARD, SDL_FALSE)) {
+ grab_keyboard = SDL_TRUE;
+ } else {
+ /* We need to do this with the old style override_redirect
+ fullscreen window otherwise we won't get keyboard focus.
+ */
+ grab_keyboard = oldstyle_fullscreen;
+ }
+ if (grab_keyboard) {
+ X11_XGrabKeyboard(display, data->xwindow, True, GrabModeAsync,
+ GrabModeAsync, CurrentTime);
+ }
+ } else {
+ X11_XUngrabPointer(display, CurrentTime);
+ X11_XUngrabKeyboard(display, CurrentTime);
+ }
+ X11_XSync(display, False);
+}
+
+void
+X11_DestroyWindow(_THIS, SDL_Window * window)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+
+ if (data) {
+ SDL_VideoData *videodata = (SDL_VideoData *) data->videodata;
+ Display *display = videodata->display;
+ int numwindows = videodata->numwindows;
+ SDL_WindowData **windowlist = videodata->windowlist;
+ int i;
+
+ if (windowlist) {
+ for (i = 0; i < numwindows; ++i) {
+ if (windowlist[i] && (windowlist[i]->window == window)) {
+ windowlist[i] = windowlist[numwindows - 1];
+ windowlist[numwindows - 1] = NULL;
+ videodata->numwindows--;
+ break;
+ }
+ }
+ }
+#ifdef X_HAVE_UTF8_STRING
+ if (data->ic) {
+ X11_XDestroyIC(data->ic);
+ }
+#endif
+ if (data->created) {
+ X11_XDestroyWindow(display, data->xwindow);
+ X11_XFlush(display);
+ }
+ SDL_free(data);
+ }
+ window->driverdata = NULL;
+}
+
+SDL_bool
+X11_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+ Display *display = data->videodata->display;
+
+ if (info->version.major == SDL_MAJOR_VERSION &&
+ info->version.minor == SDL_MINOR_VERSION) {
+ info->subsystem = SDL_SYSWM_X11;
+ info->info.x11.display = display;
+ info->info.x11.window = data->xwindow;
+ return SDL_TRUE;
+ } else {
+ SDL_SetError("Application not compiled with SDL %d.%d",
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+ return SDL_FALSE;
+ }
+}
+
+int
+X11_SetWindowHitTest(SDL_Window *window, SDL_bool enabled)
+{
+ return 0; /* just succeed, the real work is done elsewhere. */
+}
+
+#endif /* SDL_VIDEO_DRIVER_X11 */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11window.h b/src/3rdparty/SDL2/src/video/x11/SDL_x11window.h
new file mode 100644
index 0000000..7c4c6c5
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11window.h
@@ -0,0 +1,110 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_x11window_h_
+#define SDL_x11window_h_
+
+/* We need to queue the focus in/out changes because they may occur during
+ video mode changes and we can respond to them by triggering more mode
+ changes.
+*/
+#define PENDING_FOCUS_TIME 200
+
+#if SDL_VIDEO_OPENGL_EGL
+#include <EGL/egl.h>
+#endif
+
+typedef enum
+{
+ PENDING_FOCUS_NONE,
+ PENDING_FOCUS_IN,
+ PENDING_FOCUS_OUT
+} PendingFocusEnum;
+
+typedef struct
+{
+ SDL_Window *window;
+ Window xwindow;
+ Window fswindow; /* used if we can't have the WM handle fullscreen. */
+ Visual *visual;
+ Colormap colormap;
+#ifndef NO_SHARED_MEMORY
+ /* MIT shared memory extension information */
+ SDL_bool use_mitshm;
+ XShmSegmentInfo shminfo;
+#endif
+ XImage *ximage;
+ GC gc;
+ XIC ic;
+ SDL_bool created;
+ int border_left;
+ int border_right;
+ int border_top;
+ int border_bottom;
+ Uint32 last_focus_event_time;
+ PendingFocusEnum pending_focus;
+ Uint32 pending_focus_time;
+ XConfigureEvent last_xconfigure;
+ struct SDL_VideoData *videodata;
+ unsigned long user_time;
+ Atom xdnd_req;
+ Window xdnd_source;
+#if SDL_VIDEO_OPENGL_EGL
+ EGLSurface egl_surface;
+#endif
+} SDL_WindowData;
+
+extern void X11_SetNetWMState(_THIS, Window xwindow, Uint32 flags);
+extern Uint32 X11_GetNetWMState(_THIS, Window xwindow);
+
+extern int X11_CreateWindow(_THIS, SDL_Window * window);
+extern int X11_CreateWindowFrom(_THIS, SDL_Window * window, const void *data);
+extern char *X11_GetWindowTitle(_THIS, Window xwindow);
+extern void X11_SetWindowTitle(_THIS, SDL_Window * window);
+extern void X11_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
+extern void X11_SetWindowPosition(_THIS, SDL_Window * window);
+extern void X11_SetWindowMinimumSize(_THIS, SDL_Window * window);
+extern void X11_SetWindowMaximumSize(_THIS, SDL_Window * window);
+extern int X11_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right);
+extern int X11_SetWindowOpacity(_THIS, SDL_Window * window, float opacity);
+extern int X11_SetWindowModalFor(_THIS, SDL_Window * modal_window, SDL_Window * parent_window);
+extern int X11_SetWindowInputFocus(_THIS, SDL_Window * window);
+extern void X11_SetWindowSize(_THIS, SDL_Window * window);
+extern void X11_ShowWindow(_THIS, SDL_Window * window);
+extern void X11_HideWindow(_THIS, SDL_Window * window);
+extern void X11_RaiseWindow(_THIS, SDL_Window * window);
+extern void X11_MaximizeWindow(_THIS, SDL_Window * window);
+extern void X11_MinimizeWindow(_THIS, SDL_Window * window);
+extern void X11_RestoreWindow(_THIS, SDL_Window * window);
+extern void X11_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
+extern void X11_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
+extern void X11_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
+extern int X11_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
+extern void X11_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
+extern void X11_DestroyWindow(_THIS, SDL_Window * window);
+extern SDL_bool X11_GetWindowWMInfo(_THIS, SDL_Window * window,
+ struct SDL_SysWMinfo *info);
+extern int X11_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
+
+#endif /* SDL_x11window_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11xinput2.c b/src/3rdparty/SDL2/src/video/x11/SDL_x11xinput2.c
new file mode 100644
index 0000000..06a8937
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11xinput2.c
@@ -0,0 +1,313 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_X11
+
+#include "SDL_x11video.h"
+#include "SDL_x11xinput2.h"
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_touch_c.h"
+
+#define MAX_AXIS 16
+
+#if SDL_VIDEO_DRIVER_X11_XINPUT2
+static int xinput2_initialized = 0;
+
+#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
+static int xinput2_multitouch_supported = 0;
+#endif
+
+/* Opcode returned X11_XQueryExtension
+ * It will be used in event processing
+ * to know that the event came from
+ * this extension */
+static int xinput2_opcode;
+
+static void parse_valuators(const double *input_values,unsigned char *mask,int mask_len,
+ double *output_values,int output_values_len) {
+ int i = 0,z = 0;
+ int top = mask_len * 8;
+ if (top > MAX_AXIS)
+ top = MAX_AXIS;
+
+ SDL_memset(output_values,0,output_values_len * sizeof(double));
+ for (; i < top && z < output_values_len; i++) {
+ if (XIMaskIsSet(mask, i)) {
+ const int value = (int) *input_values;
+ output_values[z] = value;
+ input_values++;
+ }
+ z++;
+ }
+}
+
+static int
+query_xinput2_version(Display *display, int major, int minor)
+{
+ /* We don't care if this fails, so long as it sets major/minor on it's way out the door. */
+ X11_XIQueryVersion(display, &major, &minor);
+ return ((major * 1000) + minor);
+}
+
+static SDL_bool
+xinput2_version_atleast(const int version, const int wantmajor, const int wantminor)
+{
+ return ( version >= ((wantmajor * 1000) + wantminor) );
+}
+
+#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
+static void
+xinput2_normalize_touch_coordinates(SDL_VideoData *videodata, Window window,
+ double in_x, double in_y, float *out_x, float *out_y)
+{
+ int i;
+ for (i = 0; i < videodata->numwindows; i++) {
+ SDL_WindowData *d = videodata->windowlist[i];
+ if (d->xwindow == window) {
+ if (d->window->w == 1) {
+ *out_x = 0.5f;
+ } else {
+ *out_x = in_x / (d->window->w - 1);
+ }
+ if (d->window->h == 1) {
+ *out_y = 0.5f;
+ } else {
+ *out_y = in_y / (d->window->h - 1);
+ }
+ return;
+ }
+ }
+ // couldn't find the window...
+ *out_x = in_x;
+ *out_y = in_y;
+}
+#endif /* SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH */
+
+#endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */
+
+void
+X11_InitXinput2(_THIS)
+{
+#if SDL_VIDEO_DRIVER_X11_XINPUT2
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
+ int version = 0;
+ XIEventMask eventmask;
+ unsigned char mask[3] = { 0,0,0 };
+ int event, err;
+
+ /*
+ * Initialize XInput 2
+ * According to http://who-t.blogspot.com/2009/05/xi2-recipes-part-1.html its better
+ * to inform Xserver what version of Xinput we support.The server will store the version we support.
+ * "As XI2 progresses it becomes important that you use this call as the server may treat the client
+ * differently depending on the supported version".
+ *
+ * FIXME:event and err are not needed but if not passed X11_XQueryExtension returns SegmentationFault
+ */
+ if (!SDL_X11_HAVE_XINPUT2 ||
+ !X11_XQueryExtension(data->display, "XInputExtension", &xinput2_opcode, &event, &err)) {
+ return; /* X server does not have XInput at all */
+ }
+
+ /* We need at least 2.2 for Multitouch, 2.0 otherwise. */
+ version = query_xinput2_version(data->display, 2, 2);
+ if (!xinput2_version_atleast(version, 2, 0)) {
+ return; /* X server does not support the version we want at all. */
+ }
+
+ xinput2_initialized = 1;
+
+#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH /* Multitouch needs XInput 2.2 */
+ xinput2_multitouch_supported = xinput2_version_atleast(version, 2, 2);
+#endif
+
+ /* Enable Raw motion events for this display */
+ eventmask.deviceid = XIAllMasterDevices;
+ eventmask.mask_len = sizeof(mask);
+ eventmask.mask = mask;
+
+ XISetMask(mask, XI_RawMotion);
+ XISetMask(mask, XI_RawButtonPress);
+ XISetMask(mask, XI_RawButtonRelease);
+
+ if (X11_XISelectEvents(data->display,DefaultRootWindow(data->display),&eventmask,1) != Success) {
+ return;
+ }
+#endif
+}
+
+int
+X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *cookie)
+{
+#if SDL_VIDEO_DRIVER_X11_XINPUT2
+ if(cookie->extension != xinput2_opcode) {
+ return 0;
+ }
+ switch(cookie->evtype) {
+ case XI_RawMotion: {
+ const XIRawEvent *rawev = (const XIRawEvent*)cookie->data;
+ SDL_Mouse *mouse = SDL_GetMouse();
+ double relative_coords[2];
+ static Time prev_time = 0;
+ static double prev_rel_coords[2];
+
+ videodata->global_mouse_changed = SDL_TRUE;
+
+ if (!mouse->relative_mode || mouse->relative_mode_warp) {
+ return 0;
+ }
+
+ parse_valuators(rawev->raw_values,rawev->valuators.mask,
+ rawev->valuators.mask_len,relative_coords,2);
+
+ if ((rawev->time == prev_time) && (relative_coords[0] == prev_rel_coords[0]) && (relative_coords[1] == prev_rel_coords[1])) {
+ return 0; /* duplicate event, drop it. */
+ }
+
+ SDL_SendMouseMotion(mouse->focus,mouse->mouseID,1,(int)relative_coords[0],(int)relative_coords[1]);
+ prev_rel_coords[0] = relative_coords[0];
+ prev_rel_coords[1] = relative_coords[1];
+ prev_time = rawev->time;
+ return 1;
+ }
+ break;
+
+ case XI_RawButtonPress:
+ case XI_RawButtonRelease:
+ videodata->global_mouse_changed = SDL_TRUE;
+ break;
+
+#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
+ case XI_TouchBegin: {
+ const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
+ float x, y;
+ xinput2_normalize_touch_coordinates(videodata, xev->event,
+ xev->event_x, xev->event_y, &x, &y);
+ SDL_SendTouch(xev->sourceid,xev->detail, SDL_TRUE, x, y, 1.0);
+ return 1;
+ }
+ break;
+ case XI_TouchEnd: {
+ const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
+ float x, y;
+ xinput2_normalize_touch_coordinates(videodata, xev->event,
+ xev->event_x, xev->event_y, &x, &y);
+ SDL_SendTouch(xev->sourceid,xev->detail, SDL_FALSE, x, y, 1.0);
+ return 1;
+ }
+ break;
+ case XI_TouchUpdate: {
+ const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
+ float x, y;
+ xinput2_normalize_touch_coordinates(videodata, xev->event,
+ xev->event_x, xev->event_y, &x, &y);
+ SDL_SendTouchMotion(xev->sourceid,xev->detail, x, y, 1.0);
+ return 1;
+ }
+ break;
+#endif
+ }
+#endif
+ return 0;
+}
+
+void
+X11_InitXinput2Multitouch(_THIS)
+{
+#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+ XIDeviceInfo *info;
+ int ndevices,i,j;
+ info = X11_XIQueryDevice(data->display, XIAllDevices, &ndevices);
+
+ for (i = 0; i < ndevices; i++) {
+ XIDeviceInfo *dev = &info[i];
+ for (j = 0; j < dev->num_classes; j++) {
+ SDL_TouchID touchId;
+ XIAnyClassInfo *class = dev->classes[j];
+ XITouchClassInfo *t = (XITouchClassInfo*)class;
+
+ /* Only touch devices */
+ if (class->type != XITouchClass)
+ continue;
+
+ touchId = t->sourceid;
+ SDL_AddTouch(touchId, dev->name);
+ }
+ }
+ X11_XIFreeDeviceInfo(info);
+#endif
+}
+
+void
+X11_Xinput2SelectTouch(_THIS, SDL_Window *window)
+{
+#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
+ SDL_VideoData *data = NULL;
+ XIEventMask eventmask;
+ unsigned char mask[3] = { 0,0,0 };
+ SDL_WindowData *window_data = NULL;
+
+ if (!X11_Xinput2IsMultitouchSupported()) {
+ return;
+ }
+
+ data = (SDL_VideoData *) _this->driverdata;
+ window_data = (SDL_WindowData*)window->driverdata;
+
+ eventmask.deviceid = XIAllMasterDevices;
+ eventmask.mask_len = sizeof(mask);
+ eventmask.mask = mask;
+
+ XISetMask(mask, XI_TouchBegin);
+ XISetMask(mask, XI_TouchUpdate);
+ XISetMask(mask, XI_TouchEnd);
+
+ X11_XISelectEvents(data->display,window_data->xwindow,&eventmask,1);
+#endif
+}
+
+
+int
+X11_Xinput2IsInitialized()
+{
+#if SDL_VIDEO_DRIVER_X11_XINPUT2
+ return xinput2_initialized;
+#else
+ return 0;
+#endif
+}
+
+int
+X11_Xinput2IsMultitouchSupported()
+{
+#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
+ return xinput2_initialized && xinput2_multitouch_supported;
+#else
+ return 0;
+#endif
+}
+
+#endif /* SDL_VIDEO_DRIVER_X11 */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/SDL_x11xinput2.h b/src/3rdparty/SDL2/src/video/x11/SDL_x11xinput2.h
new file mode 100644
index 0000000..4780fbb
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/SDL_x11xinput2.h
@@ -0,0 +1,42 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef SDL_x11xinput2_h_
+#define SDL_x11xinput2_h_
+
+#ifndef SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
+/* Define XGenericEventCookie as forward declaration when
+ *xinput2 is not available in order to compile */
+struct XGenericEventCookie;
+typedef struct XGenericEventCookie XGenericEventCookie;
+#endif
+
+extern void X11_InitXinput2(_THIS);
+extern void X11_InitXinput2Multitouch(_THIS);
+extern int X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *cookie);
+extern int X11_Xinput2IsInitialized(void);
+extern int X11_Xinput2IsMultitouchSupported(void);
+extern void X11_Xinput2SelectTouch(_THIS, SDL_Window *window);
+
+#endif /* SDL_x11xinput2_h_ */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/3rdparty/SDL2/src/video/x11/edid-parse.c b/src/3rdparty/SDL2/src/video/x11/edid-parse.c
new file mode 100644
index 0000000..e22324f
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/edid-parse.c
@@ -0,0 +1,754 @@
+/*
+ * Copyright 2007 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/* Author: Soren Sandmann <sandmann@redhat.com> */
+#include "../../SDL_internal.h"
+#include "SDL_stdinc.h"
+
+#include "edid.h"
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <stdio.h>
+
+#define TRUE 1
+#define FALSE 0
+
+static int
+get_bit (int in, int bit)
+{
+ return (in & (1 << bit)) >> bit;
+}
+
+static int
+get_bits (int in, int begin, int end)
+{
+ int mask = (1 << (end - begin + 1)) - 1;
+
+ return (in >> begin) & mask;
+}
+
+static int
+decode_header (const uchar *edid)
+{
+ if (memcmp (edid, "\x00\xff\xff\xff\xff\xff\xff\x00", 8) == 0)
+ return TRUE;
+ return FALSE;
+}
+
+static int
+decode_vendor_and_product_identification (const uchar *edid, MonitorInfo *info)
+{
+ int is_model_year;
+
+ /* Manufacturer Code */
+ info->manufacturer_code[0] = get_bits (edid[0x08], 2, 6);
+ info->manufacturer_code[1] = get_bits (edid[0x08], 0, 1) << 3;
+ info->manufacturer_code[1] |= get_bits (edid[0x09], 5, 7);
+ info->manufacturer_code[2] = get_bits (edid[0x09], 0, 4);
+ info->manufacturer_code[3] = '\0';
+
+ info->manufacturer_code[0] += 'A' - 1;
+ info->manufacturer_code[1] += 'A' - 1;
+ info->manufacturer_code[2] += 'A' - 1;
+
+ /* Product Code */
+ info->product_code = edid[0x0b] << 8 | edid[0x0a];
+
+ /* Serial Number */
+ info->serial_number =
+ edid[0x0c] | edid[0x0d] << 8 | edid[0x0e] << 16 | edid[0x0f] << 24;
+
+ /* Week and Year */
+ is_model_year = FALSE;
+ switch (edid[0x10])
+ {
+ case 0x00:
+ info->production_week = -1;
+ break;
+
+ case 0xff:
+ info->production_week = -1;
+ is_model_year = TRUE;
+ break;
+
+ default:
+ info->production_week = edid[0x10];
+ break;
+ }
+
+ if (is_model_year)
+ {
+ info->production_year = -1;
+ info->model_year = 1990 + edid[0x11];
+ }
+ else
+ {
+ info->production_year = 1990 + edid[0x11];
+ info->model_year = -1;
+ }
+
+ return TRUE;
+}
+
+static int
+decode_edid_version (const uchar *edid, MonitorInfo *info)
+{
+ info->major_version = edid[0x12];
+ info->minor_version = edid[0x13];
+
+ return TRUE;
+}
+
+static int
+decode_display_parameters (const uchar *edid, MonitorInfo *info)
+{
+ /* Digital vs Analog */
+ info->is_digital = get_bit (edid[0x14], 7);
+
+ if (info->is_digital)
+ {
+ int bits;
+
+ static const int bit_depth[8] =
+ {
+ -1, 6, 8, 10, 12, 14, 16, -1
+ };
+
+ static const Interface interfaces[6] =
+ {
+ UNDEFINED, DVI, HDMI_A, HDMI_B, MDDI, DISPLAY_PORT
+ };
+
+ bits = get_bits (edid[0x14], 4, 6);
+ info->ad.digital.bits_per_primary = bit_depth[bits];
+
+ bits = get_bits (edid[0x14], 0, 3);
+
+ if (bits <= 5)
+ info->ad.digital.interface = interfaces[bits];
+ else
+ info->ad.digital.interface = UNDEFINED;
+ }
+ else
+ {
+ int bits = get_bits (edid[0x14], 5, 6);
+
+ static const double levels[][3] =
+ {
+ { 0.7, 0.3, 1.0 },
+ { 0.714, 0.286, 1.0 },
+ { 1.0, 0.4, 1.4 },
+ { 0.7, 0.0, 0.7 },
+ };
+
+ info->ad.analog.video_signal_level = levels[bits][0];
+ info->ad.analog.sync_signal_level = levels[bits][1];
+ info->ad.analog.total_signal_level = levels[bits][2];
+
+ info->ad.analog.blank_to_black = get_bit (edid[0x14], 4);
+
+ info->ad.analog.separate_hv_sync = get_bit (edid[0x14], 3);
+ info->ad.analog.composite_sync_on_h = get_bit (edid[0x14], 2);
+ info->ad.analog.composite_sync_on_green = get_bit (edid[0x14], 1);
+
+ info->ad.analog.serration_on_vsync = get_bit (edid[0x14], 0);
+ }
+
+ /* Screen Size / Aspect Ratio */
+ if (edid[0x15] == 0 && edid[0x16] == 0)
+ {
+ info->width_mm = -1;
+ info->height_mm = -1;
+ info->aspect_ratio = -1.0;
+ }
+ else if (edid[0x16] == 0)
+ {
+ info->width_mm = -1;
+ info->height_mm = -1;
+ info->aspect_ratio = 100.0 / (edid[0x15] + 99);
+ }
+ else if (edid[0x15] == 0)
+ {
+ info->width_mm = -1;
+ info->height_mm = -1;
+ info->aspect_ratio = 100.0 / (edid[0x16] + 99);
+ info->aspect_ratio = 1/info->aspect_ratio; /* portrait */
+ }
+ else
+ {
+ info->width_mm = 10 * edid[0x15];
+ info->height_mm = 10 * edid[0x16];
+ }
+
+ /* Gamma */
+ if (edid[0x17] == 0xFF)
+ info->gamma = -1.0;
+ else
+ info->gamma = (edid[0x17] + 100.0) / 100.0;
+
+ /* Features */
+ info->standby = get_bit (edid[0x18], 7);
+ info->suspend = get_bit (edid[0x18], 6);
+ info->active_off = get_bit (edid[0x18], 5);
+
+ if (info->is_digital)
+ {
+ info->ad.digital.rgb444 = TRUE;
+ if (get_bit (edid[0x18], 3))
+ info->ad.digital.ycrcb444 = 1;
+ if (get_bit (edid[0x18], 4))
+ info->ad.digital.ycrcb422 = 1;
+ }
+ else
+ {
+ int bits = get_bits (edid[0x18], 3, 4);
+ ColorType color_type[4] =
+ {
+ MONOCHROME, RGB, OTHER_COLOR, UNDEFINED_COLOR
+ };
+
+ info->ad.analog.color_type = color_type[bits];
+ }
+
+ info->srgb_is_standard = get_bit (edid[0x18], 2);
+
+ /* In 1.3 this is called "has preferred timing" */
+ info->preferred_timing_includes_native = get_bit (edid[0x18], 1);
+
+ /* FIXME: In 1.3 this indicates whether the monitor accepts GTF */
+ info->continuous_frequency = get_bit (edid[0x18], 0);
+ return TRUE;
+}
+
+static double
+decode_fraction (int high, int low)
+{
+ double result = 0.0;
+ int i;
+
+ high = (high << 2) | low;
+
+ for (i = 0; i < 10; ++i)
+ result += get_bit (high, i) * SDL_pow (2, i - 10);
+
+ return result;
+}
+
+static int
+decode_color_characteristics (const uchar *edid, MonitorInfo *info)
+{
+ info->red_x = decode_fraction (edid[0x1b], get_bits (edid[0x19], 6, 7));
+ info->red_y = decode_fraction (edid[0x1c], get_bits (edid[0x19], 5, 4));
+ info->green_x = decode_fraction (edid[0x1d], get_bits (edid[0x19], 2, 3));
+ info->green_y = decode_fraction (edid[0x1e], get_bits (edid[0x19], 0, 1));
+ info->blue_x = decode_fraction (edid[0x1f], get_bits (edid[0x1a], 6, 7));
+ info->blue_y = decode_fraction (edid[0x20], get_bits (edid[0x1a], 4, 5));
+ info->white_x = decode_fraction (edid[0x21], get_bits (edid[0x1a], 2, 3));
+ info->white_y = decode_fraction (edid[0x22], get_bits (edid[0x1a], 0, 1));
+
+ return TRUE;
+}
+
+static int
+decode_established_timings (const uchar *edid, MonitorInfo *info)
+{
+ static const Timing established[][8] =
+ {
+ {
+ { 800, 600, 60 },
+ { 800, 600, 56 },
+ { 640, 480, 75 },
+ { 640, 480, 72 },
+ { 640, 480, 67 },
+ { 640, 480, 60 },
+ { 720, 400, 88 },
+ { 720, 400, 70 }
+ },
+ {
+ { 1280, 1024, 75 },
+ { 1024, 768, 75 },
+ { 1024, 768, 70 },
+ { 1024, 768, 60 },
+ { 1024, 768, 87 },
+ { 832, 624, 75 },
+ { 800, 600, 75 },
+ { 800, 600, 72 }
+ },
+ {
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ { 1152, 870, 75 }
+ },
+ };
+
+ int i, j, idx;
+
+ idx = 0;
+ for (i = 0; i < 3; ++i)
+ {
+ for (j = 0; j < 8; ++j)
+ {
+ int byte = edid[0x23 + i];
+
+ if (get_bit (byte, j) && established[i][j].frequency != 0)
+ info->established[idx++] = established[i][j];
+ }
+ }
+ return TRUE;
+}
+
+static int
+decode_standard_timings (const uchar *edid, MonitorInfo *info)
+{
+ int i;
+
+ for (i = 0; i < 8; i++)
+ {
+ int first = edid[0x26 + 2 * i];
+ int second = edid[0x27 + 2 * i];
+
+ if (first != 0x01 && second != 0x01)
+ {
+ int w = 8 * (first + 31);
+ int h = 0;
+
+ switch (get_bits (second, 6, 7))
+ {
+ case 0x00: h = (w / 16) * 10; break;
+ case 0x01: h = (w / 4) * 3; break;
+ case 0x02: h = (w / 5) * 4; break;
+ case 0x03: h = (w / 16) * 9; break;
+ }
+
+ info->standard[i].width = w;
+ info->standard[i].height = h;
+ info->standard[i].frequency = get_bits (second, 0, 5) + 60;
+ }
+ }
+
+ return TRUE;
+}
+
+static void
+decode_lf_string (const uchar *s, int n_chars, char *result)
+{
+ int i;
+ for (i = 0; i < n_chars; ++i)
+ {
+ if (s[i] == 0x0a)
+ {
+ *result++ = '\0';
+ break;
+ }
+ else if (s[i] == 0x00)
+ {
+ /* Convert embedded 0's to spaces */
+ *result++ = ' ';
+ }
+ else
+ {
+ *result++ = s[i];
+ }
+ }
+}
+
+static void
+decode_display_descriptor (const uchar *desc,
+ MonitorInfo *info)
+{
+ switch (desc[0x03])
+ {
+ case 0xFC:
+ decode_lf_string (desc + 5, 13, info->dsc_product_name);
+ break;
+ case 0xFF:
+ decode_lf_string (desc + 5, 13, info->dsc_serial_number);
+ break;
+ case 0xFE:
+ decode_lf_string (desc + 5, 13, info->dsc_string);
+ break;
+ case 0xFD:
+ /* Range Limits */
+ break;
+ case 0xFB:
+ /* Color Point */
+ break;
+ case 0xFA:
+ /* Timing Identifications */
+ break;
+ case 0xF9:
+ /* Color Management */
+ break;
+ case 0xF8:
+ /* Timing Codes */
+ break;
+ case 0xF7:
+ /* Established Timings */
+ break;
+ case 0x10:
+ break;
+ }
+}
+
+static void
+decode_detailed_timing (const uchar *timing,
+ DetailedTiming *detailed)
+{
+ int bits;
+ StereoType stereo[] =
+ {
+ NO_STEREO, NO_STEREO, FIELD_RIGHT, FIELD_LEFT,
+ TWO_WAY_RIGHT_ON_EVEN, TWO_WAY_LEFT_ON_EVEN,
+ FOUR_WAY_INTERLEAVED, SIDE_BY_SIDE
+ };
+
+ detailed->pixel_clock = (timing[0x00] | timing[0x01] << 8) * 10000;
+ detailed->h_addr = timing[0x02] | ((timing[0x04] & 0xf0) << 4);
+ detailed->h_blank = timing[0x03] | ((timing[0x04] & 0x0f) << 8);
+ detailed->v_addr = timing[0x05] | ((timing[0x07] & 0xf0) << 4);
+ detailed->v_blank = timing[0x06] | ((timing[0x07] & 0x0f) << 8);
+ detailed->h_front_porch = timing[0x08] | get_bits (timing[0x0b], 6, 7) << 8;
+ detailed->h_sync = timing[0x09] | get_bits (timing[0x0b], 4, 5) << 8;
+ detailed->v_front_porch =
+ get_bits (timing[0x0a], 4, 7) | get_bits (timing[0x0b], 2, 3) << 4;
+ detailed->v_sync =
+ get_bits (timing[0x0a], 0, 3) | get_bits (timing[0x0b], 0, 1) << 4;
+ detailed->width_mm = timing[0x0c] | get_bits (timing[0x0e], 4, 7) << 8;
+ detailed->height_mm = timing[0x0d] | get_bits (timing[0x0e], 0, 3) << 8;
+ detailed->right_border = timing[0x0f];
+ detailed->top_border = timing[0x10];
+
+ detailed->interlaced = get_bit (timing[0x11], 7);
+
+ /* Stereo */
+ bits = get_bits (timing[0x11], 5, 6) << 1 | get_bit (timing[0x11], 0);
+ detailed->stereo = stereo[bits];
+
+ /* Sync */
+ bits = timing[0x11];
+
+ detailed->digital_sync = get_bit (bits, 4);
+ if (detailed->digital_sync)
+ {
+ detailed->ad.digital.composite = !get_bit (bits, 3);
+
+ if (detailed->ad.digital.composite)
+ {
+ detailed->ad.digital.serrations = get_bit (bits, 2);
+ detailed->ad.digital.negative_vsync = FALSE;
+ }
+ else
+ {
+ detailed->ad.digital.serrations = FALSE;
+ detailed->ad.digital.negative_vsync = !get_bit (bits, 2);
+ }
+
+ detailed->ad.digital.negative_hsync = !get_bit (bits, 0);
+ }
+ else
+ {
+ detailed->ad.analog.bipolar = get_bit (bits, 3);
+ detailed->ad.analog.serrations = get_bit (bits, 2);
+ detailed->ad.analog.sync_on_green = !get_bit (bits, 1);
+ }
+}
+
+static int
+decode_descriptors (const uchar *edid, MonitorInfo *info)
+{
+ int i;
+ int timing_idx;
+
+ timing_idx = 0;
+
+ for (i = 0; i < 4; ++i)
+ {
+ int index = 0x36 + i * 18;
+
+ if (edid[index + 0] == 0x00 && edid[index + 1] == 0x00)
+ {
+ decode_display_descriptor (edid + index, info);
+ }
+ else
+ {
+ decode_detailed_timing (
+ edid + index, &(info->detailed_timings[timing_idx++]));
+ }
+ }
+
+ info->n_detailed_timings = timing_idx;
+
+ return TRUE;
+}
+
+static void
+decode_check_sum (const uchar *edid,
+ MonitorInfo *info)
+{
+ int i;
+ uchar check = 0;
+
+ for (i = 0; i < 128; ++i)
+ check += edid[i];
+
+ info->checksum = check;
+}
+
+MonitorInfo *
+decode_edid (const uchar *edid)
+{
+ MonitorInfo *info = calloc (1, sizeof (MonitorInfo));
+
+ decode_check_sum (edid, info);
+
+ if (!decode_header (edid) ||
+ !decode_vendor_and_product_identification (edid, info) ||
+ !decode_edid_version (edid, info) ||
+ !decode_display_parameters (edid, info) ||
+ !decode_color_characteristics (edid, info) ||
+ !decode_established_timings (edid, info) ||
+ !decode_standard_timings (edid, info) ||
+ !decode_descriptors (edid, info)) {
+ free(info);
+ return NULL;
+ }
+
+ return info;
+}
+
+static const char *
+yesno (int v)
+{
+ return v? "yes" : "no";
+}
+
+void
+dump_monitor_info (MonitorInfo *info)
+{
+ int i;
+
+ printf ("Checksum: %d (%s)\n",
+ info->checksum, info->checksum? "incorrect" : "correct");
+ printf ("Manufacturer Code: %s\n", info->manufacturer_code);
+ printf ("Product Code: 0x%x\n", info->product_code);
+ printf ("Serial Number: %u\n", info->serial_number);
+
+ if (info->production_week != -1)
+ printf ("Production Week: %d\n", info->production_week);
+ else
+ printf ("Production Week: unspecified\n");
+
+ if (info->production_year != -1)
+ printf ("Production Year: %d\n", info->production_year);
+ else
+ printf ("Production Year: unspecified\n");
+
+ if (info->model_year != -1)
+ printf ("Model Year: %d\n", info->model_year);
+ else
+ printf ("Model Year: unspecified\n");
+
+ printf ("EDID revision: %d.%d\n", info->major_version, info->minor_version);
+
+ printf ("Display is %s\n", info->is_digital? "digital" : "analog");
+ if (info->is_digital)
+ {
+ const char *interface;
+ if (info->ad.digital.bits_per_primary != -1)
+ printf ("Bits Per Primary: %d\n", info->ad.digital.bits_per_primary);
+ else
+ printf ("Bits Per Primary: undefined\n");
+
+ switch (info->ad.digital.interface)
+ {
+ case DVI: interface = "DVI"; break;
+ case HDMI_A: interface = "HDMI-a"; break;
+ case HDMI_B: interface = "HDMI-b"; break;
+ case MDDI: interface = "MDDI"; break;
+ case DISPLAY_PORT: interface = "DisplayPort"; break;
+ case UNDEFINED: interface = "undefined"; break;
+ default: interface = "unknown"; break;
+ }
+ printf ("Interface: %s\n", interface);
+
+ printf ("RGB 4:4:4: %s\n", yesno (info->ad.digital.rgb444));
+ printf ("YCrCb 4:4:4: %s\n", yesno (info->ad.digital.ycrcb444));
+ printf ("YCrCb 4:2:2: %s\n", yesno (info->ad.digital.ycrcb422));
+ }
+ else
+ {
+ const char *s;
+ printf ("Video Signal Level: %f\n", info->ad.analog.video_signal_level);
+ printf ("Sync Signal Level: %f\n", info->ad.analog.sync_signal_level);
+ printf ("Total Signal Level: %f\n", info->ad.analog.total_signal_level);
+
+ printf ("Blank to Black: %s\n",
+ yesno (info->ad.analog.blank_to_black));
+ printf ("Separate HV Sync: %s\n",
+ yesno (info->ad.analog.separate_hv_sync));
+ printf ("Composite Sync on H: %s\n",
+ yesno (info->ad.analog.composite_sync_on_h));
+ printf ("Serration on VSync: %s\n",
+ yesno (info->ad.analog.serration_on_vsync));
+
+ switch (info->ad.analog.color_type)
+ {
+ case UNDEFINED_COLOR: s = "undefined"; break;
+ case MONOCHROME: s = "monochrome"; break;
+ case RGB: s = "rgb"; break;
+ case OTHER_COLOR: s = "other color"; break;
+ default: s = "unknown"; break;
+ };
+
+ printf ("Color: %s\n", s);
+ }
+
+ if (info->width_mm == -1)
+ printf ("Width: undefined\n");
+ else
+ printf ("Width: %d mm\n", info->width_mm);
+
+ if (info->height_mm == -1)
+ printf ("Height: undefined\n");
+ else
+ printf ("Height: %d mm\n", info->height_mm);
+
+ if (info->aspect_ratio > 0)
+ printf ("Aspect Ratio: %f\n", info->aspect_ratio);
+ else
+ printf ("Aspect Ratio: undefined\n");
+
+ if (info->gamma >= 0)
+ printf ("Gamma: %f\n", info->gamma);
+ else
+ printf ("Gamma: undefined\n");
+
+ printf ("Standby: %s\n", yesno (info->standby));
+ printf ("Suspend: %s\n", yesno (info->suspend));
+ printf ("Active Off: %s\n", yesno (info->active_off));
+
+ printf ("SRGB is Standard: %s\n", yesno (info->srgb_is_standard));
+ printf ("Preferred Timing Includes Native: %s\n",
+ yesno (info->preferred_timing_includes_native));
+ printf ("Continuous Frequency: %s\n", yesno (info->continuous_frequency));
+
+ printf ("Red X: %f\n", info->red_x);
+ printf ("Red Y: %f\n", info->red_y);
+ printf ("Green X: %f\n", info->green_x);
+ printf ("Green Y: %f\n", info->green_y);
+ printf ("Blue X: %f\n", info->blue_x);
+ printf ("Blue Y: %f\n", info->blue_y);
+ printf ("White X: %f\n", info->white_x);
+ printf ("White Y: %f\n", info->white_y);
+
+ printf ("Established Timings:\n");
+
+ for (i = 0; i < 24; ++i)
+ {
+ Timing *timing = &(info->established[i]);
+
+ if (timing->frequency == 0)
+ break;
+
+ printf (" %d x %d @ %d Hz\n",
+ timing->width, timing->height, timing->frequency);
+
+ }
+
+ printf ("Standard Timings:\n");
+ for (i = 0; i < 8; ++i)
+ {
+ Timing *timing = &(info->standard[i]);
+
+ if (timing->frequency == 0)
+ break;
+
+ printf (" %d x %d @ %d Hz\n",
+ timing->width, timing->height, timing->frequency);
+ }
+
+ for (i = 0; i < info->n_detailed_timings; ++i)
+ {
+ DetailedTiming *timing = &(info->detailed_timings[i]);
+ const char *s;
+
+ printf ("Timing%s: \n",
+ (i == 0 && info->preferred_timing_includes_native)?
+ " (Preferred)" : "");
+ printf (" Pixel Clock: %d\n", timing->pixel_clock);
+ printf (" H Addressable: %d\n", timing->h_addr);
+ printf (" H Blank: %d\n", timing->h_blank);
+ printf (" H Front Porch: %d\n", timing->h_front_porch);
+ printf (" H Sync: %d\n", timing->h_sync);
+ printf (" V Addressable: %d\n", timing->v_addr);
+ printf (" V Blank: %d\n", timing->v_blank);
+ printf (" V Front Porch: %d\n", timing->v_front_porch);
+ printf (" V Sync: %d\n", timing->v_sync);
+ printf (" Width: %d mm\n", timing->width_mm);
+ printf (" Height: %d mm\n", timing->height_mm);
+ printf (" Right Border: %d\n", timing->right_border);
+ printf (" Top Border: %d\n", timing->top_border);
+ switch (timing->stereo)
+ {
+ default:
+ case NO_STEREO: s = "No Stereo"; break;
+ case FIELD_RIGHT: s = "Field Sequential, Right on Sync"; break;
+ case FIELD_LEFT: s = "Field Sequential, Left on Sync"; break;
+ case TWO_WAY_RIGHT_ON_EVEN: s = "Two-way, Right on Even"; break;
+ case TWO_WAY_LEFT_ON_EVEN: s = "Two-way, Left on Even"; break;
+ case FOUR_WAY_INTERLEAVED: s = "Four-way Interleaved"; break;
+ case SIDE_BY_SIDE: s = "Side-by-Side"; break;
+ }
+ printf (" Stereo: %s\n", s);
+
+ if (timing->digital_sync)
+ {
+ printf (" Digital Sync:\n");
+ printf (" composite: %s\n", yesno (timing->ad.digital.composite));
+ printf (" serrations: %s\n", yesno (timing->ad.digital.serrations));
+ printf (" negative vsync: %s\n",
+ yesno (timing->ad.digital.negative_vsync));
+ printf (" negative hsync: %s\n",
+ yesno (timing->ad.digital.negative_hsync));
+ }
+ else
+ {
+ printf (" Analog Sync:\n");
+ printf (" bipolar: %s\n", yesno (timing->ad.analog.bipolar));
+ printf (" serrations: %s\n", yesno (timing->ad.analog.serrations));
+ printf (" sync on green: %s\n", yesno (
+ timing->ad.analog.sync_on_green));
+ }
+ }
+
+ printf ("Detailed Product information:\n");
+ printf (" Product Name: %s\n", info->dsc_product_name);
+ printf (" Serial Number: %s\n", info->dsc_serial_number);
+ printf (" Unspecified String: %s\n", info->dsc_string);
+}
+
diff --git a/src/3rdparty/SDL2/src/video/x11/edid.h b/src/3rdparty/SDL2/src/video/x11/edid.h
new file mode 100644
index 0000000..cb9f0e8
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/edid.h
@@ -0,0 +1,167 @@
+typedef unsigned char uchar;
+typedef struct MonitorInfo MonitorInfo;
+typedef struct Timing Timing;
+typedef struct DetailedTiming DetailedTiming;
+
+typedef enum
+{
+ UNDEFINED,
+ DVI,
+ HDMI_A,
+ HDMI_B,
+ MDDI,
+ DISPLAY_PORT
+} Interface;
+
+typedef enum
+{
+ UNDEFINED_COLOR,
+ MONOCHROME,
+ RGB,
+ OTHER_COLOR
+} ColorType;
+
+typedef enum
+{
+ NO_STEREO,
+ FIELD_RIGHT,
+ FIELD_LEFT,
+ TWO_WAY_RIGHT_ON_EVEN,
+ TWO_WAY_LEFT_ON_EVEN,
+ FOUR_WAY_INTERLEAVED,
+ SIDE_BY_SIDE
+} StereoType;
+
+struct Timing
+{
+ int width;
+ int height;
+ int frequency;
+};
+
+struct DetailedTiming
+{
+ int pixel_clock;
+ int h_addr;
+ int h_blank;
+ int h_sync;
+ int h_front_porch;
+ int v_addr;
+ int v_blank;
+ int v_sync;
+ int v_front_porch;
+ int width_mm;
+ int height_mm;
+ int right_border;
+ int top_border;
+ int interlaced;
+ StereoType stereo;
+
+ int digital_sync;
+ union
+ {
+ struct
+ {
+ int bipolar;
+ int serrations;
+ int sync_on_green;
+ } analog;
+
+ struct
+ {
+ int composite;
+ int serrations;
+ int negative_vsync;
+ int negative_hsync;
+ } digital;
+ } ad;
+};
+
+struct MonitorInfo
+{
+ int checksum;
+ char manufacturer_code[4];
+ int product_code;
+ unsigned int serial_number;
+
+ int production_week; /* -1 if not specified */
+ int production_year; /* -1 if not specified */
+ int model_year; /* -1 if not specified */
+
+ int major_version;
+ int minor_version;
+
+ int is_digital;
+
+ union
+ {
+ struct
+ {
+ int bits_per_primary;
+ Interface interface;
+ int rgb444;
+ int ycrcb444;
+ int ycrcb422;
+ } digital;
+
+ struct
+ {
+ double video_signal_level;
+ double sync_signal_level;
+ double total_signal_level;
+
+ int blank_to_black;
+
+ int separate_hv_sync;
+ int composite_sync_on_h;
+ int composite_sync_on_green;
+ int serration_on_vsync;
+ ColorType color_type;
+ } analog;
+ } ad;
+
+ int width_mm; /* -1 if not specified */
+ int height_mm; /* -1 if not specified */
+ double aspect_ratio; /* -1.0 if not specififed */
+
+ double gamma; /* -1.0 if not specified */
+
+ int standby;
+ int suspend;
+ int active_off;
+
+ int srgb_is_standard;
+ int preferred_timing_includes_native;
+ int continuous_frequency;
+
+ double red_x;
+ double red_y;
+ double green_x;
+ double green_y;
+ double blue_x;
+ double blue_y;
+ double white_x;
+ double white_y;
+
+ Timing established[24]; /* Terminated by 0x0x0 */
+ Timing standard[8];
+
+ int n_detailed_timings;
+ DetailedTiming detailed_timings[4]; /* If monitor has a preferred
+ * mode, it is the first one
+ * (whether it has, is
+ * determined by the
+ * preferred_timing_includes
+ * bit.
+ */
+
+ /* Optional product description */
+ char dsc_serial_number[14];
+ char dsc_product_name[14];
+ char dsc_string[14]; /* Unspecified ASCII data */
+};
+
+MonitorInfo *decode_edid (const uchar *data);
+void dump_monitor_info (MonitorInfo *info);
+char * make_display_name (const char *output_name,
+ const MonitorInfo *info);
diff --git a/src/3rdparty/SDL2/src/video/x11/imKStoUCS.c b/src/3rdparty/SDL2/src/video/x11/imKStoUCS.c
new file mode 100644
index 0000000..40e2242
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/imKStoUCS.c
@@ -0,0 +1,350 @@
+/*
+Copyright (C) 2003-2006,2008 Jamey Sharp, Josh Triplett
+Copyright © 2009 Red Hat, Inc.
+Copyright 1990-1992,1999,2000,2004,2009,2010 Oracle and/or its affiliates.
+All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+*/
+
+#include "../../SDL_internal.h"
+
+#if SDL_VIDEO_DRIVER_X11
+#include <X11/X.h>
+#include "imKStoUCS.h"
+
+static unsigned short const keysym_to_unicode_1a1_1ff[] = {
+ 0x0104, 0x02d8, 0x0141, 0x0000, 0x013d, 0x015a, 0x0000, /* 0x01a0-0x01a7 */
+ 0x0000, 0x0160, 0x015e, 0x0164, 0x0179, 0x0000, 0x017d, 0x017b, /* 0x01a8-0x01af */
+ 0x0000, 0x0105, 0x02db, 0x0142, 0x0000, 0x013e, 0x015b, 0x02c7, /* 0x01b0-0x01b7 */
+ 0x0000, 0x0161, 0x015f, 0x0165, 0x017a, 0x02dd, 0x017e, 0x017c, /* 0x01b8-0x01bf */
+ 0x0154, 0x0000, 0x0000, 0x0102, 0x0000, 0x0139, 0x0106, 0x0000, /* 0x01c0-0x01c7 */
+ 0x010c, 0x0000, 0x0118, 0x0000, 0x011a, 0x0000, 0x0000, 0x010e, /* 0x01c8-0x01cf */
+ 0x0110, 0x0143, 0x0147, 0x0000, 0x0000, 0x0150, 0x0000, 0x0000, /* 0x01d0-0x01d7 */
+ 0x0158, 0x016e, 0x0000, 0x0170, 0x0000, 0x0000, 0x0162, 0x0000, /* 0x01d8-0x01df */
+ 0x0155, 0x0000, 0x0000, 0x0103, 0x0000, 0x013a, 0x0107, 0x0000, /* 0x01e0-0x01e7 */
+ 0x010d, 0x0000, 0x0119, 0x0000, 0x011b, 0x0000, 0x0000, 0x010f, /* 0x01e8-0x01ef */
+ 0x0111, 0x0144, 0x0148, 0x0000, 0x0000, 0x0151, 0x0000, 0x0000, /* 0x01f0-0x01f7 */
+ 0x0159, 0x016f, 0x0000, 0x0171, 0x0000, 0x0000, 0x0163, 0x02d9 /* 0x01f8-0x01ff */
+};
+
+static unsigned short const keysym_to_unicode_2a1_2fe[] = {
+ 0x0126, 0x0000, 0x0000, 0x0000, 0x0000, 0x0124, 0x0000, /* 0x02a0-0x02a7 */
+ 0x0000, 0x0130, 0x0000, 0x011e, 0x0134, 0x0000, 0x0000, 0x0000, /* 0x02a8-0x02af */
+ 0x0000, 0x0127, 0x0000, 0x0000, 0x0000, 0x0000, 0x0125, 0x0000, /* 0x02b0-0x02b7 */
+ 0x0000, 0x0131, 0x0000, 0x011f, 0x0135, 0x0000, 0x0000, 0x0000, /* 0x02b8-0x02bf */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x010a, 0x0108, 0x0000, /* 0x02c0-0x02c7 */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x02c8-0x02cf */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0120, 0x0000, 0x0000, /* 0x02d0-0x02d7 */
+ 0x011c, 0x0000, 0x0000, 0x0000, 0x0000, 0x016c, 0x015c, 0x0000, /* 0x02d8-0x02df */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x010b, 0x0109, 0x0000, /* 0x02e0-0x02e7 */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x02e8-0x02ef */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0121, 0x0000, 0x0000, /* 0x02f0-0x02f7 */
+ 0x011d, 0x0000, 0x0000, 0x0000, 0x0000, 0x016d, 0x015d /* 0x02f8-0x02ff */
+};
+
+static unsigned short const keysym_to_unicode_3a2_3fe[] = {
+ 0x0138, 0x0156, 0x0000, 0x0128, 0x013b, 0x0000, /* 0x03a0-0x03a7 */
+ 0x0000, 0x0000, 0x0112, 0x0122, 0x0166, 0x0000, 0x0000, 0x0000, /* 0x03a8-0x03af */
+ 0x0000, 0x0000, 0x0000, 0x0157, 0x0000, 0x0129, 0x013c, 0x0000, /* 0x03b0-0x03b7 */
+ 0x0000, 0x0000, 0x0113, 0x0123, 0x0167, 0x014a, 0x0000, 0x014b, /* 0x03b8-0x03bf */
+ 0x0100, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x012e, /* 0x03c0-0x03c7 */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0116, 0x0000, 0x0000, 0x012a, /* 0x03c8-0x03cf */
+ 0x0000, 0x0145, 0x014c, 0x0136, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x03d0-0x03d7 */
+ 0x0000, 0x0172, 0x0000, 0x0000, 0x0000, 0x0168, 0x016a, 0x0000, /* 0x03d8-0x03df */
+ 0x0101, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x012f, /* 0x03e0-0x03e7 */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0117, 0x0000, 0x0000, 0x012b, /* 0x03e8-0x03ef */
+ 0x0000, 0x0146, 0x014d, 0x0137, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x03f0-0x03f7 */
+ 0x0000, 0x0173, 0x0000, 0x0000, 0x0000, 0x0169, 0x016b /* 0x03f8-0x03ff */
+};
+
+static unsigned short const keysym_to_unicode_4a1_4df[] = {
+ 0x3002, 0x3008, 0x3009, 0x3001, 0x30fb, 0x30f2, 0x30a1, /* 0x04a0-0x04a7 */
+ 0x30a3, 0x30a5, 0x30a7, 0x30a9, 0x30e3, 0x30e5, 0x30e7, 0x30c3, /* 0x04a8-0x04af */
+ 0x30fc, 0x30a2, 0x30a4, 0x30a6, 0x30a8, 0x30aa, 0x30ab, 0x30ad, /* 0x04b0-0x04b7 */
+ 0x30af, 0x30b1, 0x30b3, 0x30b5, 0x30b7, 0x30b9, 0x30bb, 0x30bd, /* 0x04b8-0x04bf */
+ 0x30bf, 0x30c1, 0x30c4, 0x30c6, 0x30c8, 0x30ca, 0x30cb, 0x30cc, /* 0x04c0-0x04c7 */
+ 0x30cd, 0x30ce, 0x30cf, 0x30d2, 0x30d5, 0x30d8, 0x30db, 0x30de, /* 0x04c8-0x04cf */
+ 0x30df, 0x30e0, 0x30e1, 0x30e2, 0x30e4, 0x30e6, 0x30e8, 0x30e9, /* 0x04d0-0x04d7 */
+ 0x30ea, 0x30eb, 0x30ec, 0x30ed, 0x30ef, 0x30f3, 0x309b, 0x309c /* 0x04d8-0x04df */
+};
+
+static unsigned short const keysym_to_unicode_590_5fe[] = {
+ 0x06f0, 0x06f1, 0x06f2, 0x06f3, 0x06f4, 0x06f5, 0x06f6, 0x06f7, /* 0x0590-0x0597 */
+ 0x06f8, 0x06f9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x0598-0x059f */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x066a, 0x0670, 0x0679, /* 0x05a0-0x05a7 */
+
+ 0x067e, 0x0686, 0x0688, 0x0691, 0x060c, 0x0000, 0x06d4, 0x0000, /* 0x05ac-0x05af */
+ 0x0660, 0x0661, 0x0662, 0x0663, 0x0664, 0x0665, 0x0666, 0x0667, /* 0x05b0-0x05b7 */
+ 0x0668, 0x0669, 0x0000, 0x061b, 0x0000, 0x0000, 0x0000, 0x061f, /* 0x05b8-0x05bf */
+ 0x0000, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627, /* 0x05c0-0x05c7 */
+ 0x0628, 0x0629, 0x062a, 0x062b, 0x062c, 0x062d, 0x062e, 0x062f, /* 0x05c8-0x05cf */
+ 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x0637, /* 0x05d0-0x05d7 */
+ 0x0638, 0x0639, 0x063a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x05d8-0x05df */
+ 0x0640, 0x0641, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647, /* 0x05e0-0x05e7 */
+ 0x0648, 0x0649, 0x064a, 0x064b, 0x064c, 0x064d, 0x064e, 0x064f, /* 0x05e8-0x05ef */
+ 0x0650, 0x0651, 0x0652, 0x0653, 0x0654, 0x0655, 0x0698, 0x06a4, /* 0x05f0-0x05f7 */
+ 0x06a9, 0x06af, 0x06ba, 0x06be, 0x06cc, 0x06d2, 0x06c1 /* 0x05f8-0x05fe */
+};
+
+static unsigned short keysym_to_unicode_680_6ff[] = {
+ 0x0492, 0x0496, 0x049a, 0x049c, 0x04a2, 0x04ae, 0x04b0, 0x04b2, /* 0x0680-0x0687 */
+ 0x04b6, 0x04b8, 0x04ba, 0x0000, 0x04d8, 0x04e2, 0x04e8, 0x04ee, /* 0x0688-0x068f */
+ 0x0493, 0x0497, 0x049b, 0x049d, 0x04a3, 0x04af, 0x04b1, 0x04b3, /* 0x0690-0x0697 */
+ 0x04b7, 0x04b9, 0x04bb, 0x0000, 0x04d9, 0x04e3, 0x04e9, 0x04ef, /* 0x0698-0x069f */
+ 0x0000, 0x0452, 0x0453, 0x0451, 0x0454, 0x0455, 0x0456, 0x0457, /* 0x06a0-0x06a7 */
+ 0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x0491, 0x045e, 0x045f, /* 0x06a8-0x06af */
+ 0x2116, 0x0402, 0x0403, 0x0401, 0x0404, 0x0405, 0x0406, 0x0407, /* 0x06b0-0x06b7 */
+ 0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x0490, 0x040e, 0x040f, /* 0x06b8-0x06bf */
+ 0x044e, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433, /* 0x06c0-0x06c7 */
+ 0x0445, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, /* 0x06c8-0x06cf */
+ 0x043f, 0x044f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432, /* 0x06d0-0x06d7 */
+ 0x044c, 0x044b, 0x0437, 0x0448, 0x044d, 0x0449, 0x0447, 0x044a, /* 0x06d8-0x06df */
+ 0x042e, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413, /* 0x06e0-0x06e7 */
+ 0x0425, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, /* 0x06e8-0x06ef */
+ 0x041f, 0x042f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412, /* 0x06f0-0x06f7 */
+ 0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x042a /* 0x06f8-0x06ff */
+};
+
+static unsigned short const keysym_to_unicode_7a1_7f9[] = {
+ 0x0386, 0x0388, 0x0389, 0x038a, 0x03aa, 0x0000, 0x038c, /* 0x07a0-0x07a7 */
+ 0x038e, 0x03ab, 0x0000, 0x038f, 0x0000, 0x0000, 0x0385, 0x2015, /* 0x07a8-0x07af */
+ 0x0000, 0x03ac, 0x03ad, 0x03ae, 0x03af, 0x03ca, 0x0390, 0x03cc, /* 0x07b0-0x07b7 */
+ 0x03cd, 0x03cb, 0x03b0, 0x03ce, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x07b8-0x07bf */
+ 0x0000, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, /* 0x07c0-0x07c7 */
+ 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f, /* 0x07c8-0x07cf */
+ 0x03a0, 0x03a1, 0x03a3, 0x0000, 0x03a4, 0x03a5, 0x03a6, 0x03a7, /* 0x07d0-0x07d7 */
+ 0x03a8, 0x03a9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x07d8-0x07df */
+ 0x0000, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, /* 0x07e0-0x07e7 */
+ 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, /* 0x07e8-0x07ef */
+ 0x03c0, 0x03c1, 0x03c3, 0x03c2, 0x03c4, 0x03c5, 0x03c6, 0x03c7, /* 0x07f0-0x07f7 */
+ 0x03c8, 0x03c9 /* 0x07f8-0x07ff */
+};
+
+static unsigned short const keysym_to_unicode_8a4_8fe[] = {
+ 0x2320, 0x2321, 0x0000, 0x231c, /* 0x08a0-0x08a7 */
+ 0x231d, 0x231e, 0x231f, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x08a8-0x08af */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x08b0-0x08b7 */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x2264, 0x2260, 0x2265, 0x222b, /* 0x08b8-0x08bf */
+ 0x2234, 0x0000, 0x221e, 0x0000, 0x0000, 0x2207, 0x0000, 0x0000, /* 0x08c0-0x08c7 */
+ 0x2245, 0x2246, 0x0000, 0x0000, 0x0000, 0x0000, 0x21d2, 0x0000, /* 0x08c8-0x08cf */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x221a, 0x0000, /* 0x08d0-0x08d7 */
+ 0x0000, 0x0000, 0x2282, 0x2283, 0x2229, 0x222a, 0x2227, 0x2228, /* 0x08d8-0x08df */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x08e0-0x08e7 */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2202, /* 0x08e8-0x08ef */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0192, 0x0000, /* 0x08f0-0x08f7 */
+ 0x0000, 0x0000, 0x0000, 0x2190, 0x2191, 0x2192, 0x2193 /* 0x08f8-0x08ff */
+};
+
+static unsigned short const keysym_to_unicode_9df_9f8[] = {
+ 0x2422, /* 0x09d8-0x09df */
+ 0x2666, 0x25a6, 0x2409, 0x240c, 0x240d, 0x240a, 0x0000, 0x0000, /* 0x09e0-0x09e7 */
+ 0x240a, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0x2500, /* 0x09e8-0x09ef */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x251c, 0x2524, 0x2534, 0x252c, /* 0x09f0-0x09f7 */
+ 0x2502 /* 0x09f8-0x09ff */
+};
+
+static unsigned short const keysym_to_unicode_aa1_afe[] = {
+ 0x2003, 0x2002, 0x2004, 0x2005, 0x2007, 0x2008, 0x2009, /* 0x0aa0-0x0aa7 */
+ 0x200a, 0x2014, 0x2013, 0x0000, 0x0000, 0x0000, 0x2026, 0x2025, /* 0x0aa8-0x0aaf */
+ 0x2153, 0x2154, 0x2155, 0x2156, 0x2157, 0x2158, 0x2159, 0x215a, /* 0x0ab0-0x0ab7 */
+ 0x2105, 0x0000, 0x0000, 0x2012, 0x2039, 0x2024, 0x203a, 0x0000, /* 0x0ab8-0x0abf */
+ 0x0000, 0x0000, 0x0000, 0x215b, 0x215c, 0x215d, 0x215e, 0x0000, /* 0x0ac0-0x0ac7 */
+ 0x0000, 0x2122, 0x2120, 0x0000, 0x25c1, 0x25b7, 0x25cb, 0x25ad, /* 0x0ac8-0x0acf */
+ 0x2018, 0x2019, 0x201c, 0x201d, 0x211e, 0x2030, 0x2032, 0x2033, /* 0x0ad0-0x0ad7 */
+ 0x0000, 0x271d, 0x0000, 0x220e, 0x25c2, 0x2023, 0x25cf, 0x25ac, /* 0x0ad8-0x0adf */
+ 0x25e6, 0x25ab, 0x25ae, 0x25b5, 0x25bf, 0x2606, 0x2022, 0x25aa, /* 0x0ae0-0x0ae7 */
+ 0x25b4, 0x25be, 0x261a, 0x261b, 0x2663, 0x2666, 0x2665, 0x0000, /* 0x0ae8-0x0aef */
+ 0x2720, 0x2020, 0x2021, 0x2713, 0x2612, 0x266f, 0x266d, 0x2642, /* 0x0af0-0x0af7 */
+ 0x2640, 0x2121, 0x2315, 0x2117, 0x2038, 0x201a, 0x201e /* 0x0af8-0x0aff */
+};
+
+/* none of the APL keysyms match the Unicode characters */
+
+static unsigned short const keysym_to_unicode_cdf_cfa[] = {
+ 0x2017, /* 0x0cd8-0x0cdf */
+ 0x05d0, 0x05d1, 0x05d2, 0x05d3, 0x05d4, 0x05d5, 0x05d6, 0x05d7, /* 0x0ce0-0x0ce7 */
+ 0x05d8, 0x05d9, 0x05da, 0x05db, 0x05dc, 0x05dd, 0x05de, 0x05df, /* 0x0ce8-0x0cef */
+ 0x05e0, 0x05e1, 0x05e2, 0x05e3, 0x05e4, 0x05e5, 0x05e6, 0x05e7, /* 0x0cf0-0x0cf7 */
+ 0x05e8, 0x05e9, 0x05ea /* 0x0cf8-0x0cff */
+};
+
+static unsigned short const keysym_to_unicode_da1_df9[] = {
+ 0x0e01, 0x0e02, 0x0e03, 0x0e04, 0x0e05, 0x0e06, 0x0e07, /* 0x0da0-0x0da7 */
+ 0x0e08, 0x0e09, 0x0e0a, 0x0e0b, 0x0e0c, 0x0e0d, 0x0e0e, 0x0e0f, /* 0x0da8-0x0daf */
+ 0x0e10, 0x0e11, 0x0e12, 0x0e13, 0x0e14, 0x0e15, 0x0e16, 0x0e17, /* 0x0db0-0x0db7 */
+ 0x0e18, 0x0e19, 0x0e1a, 0x0e1b, 0x0e1c, 0x0e1d, 0x0e1e, 0x0e1f, /* 0x0db8-0x0dbf */
+ 0x0e20, 0x0e21, 0x0e22, 0x0e23, 0x0e24, 0x0e25, 0x0e26, 0x0e27, /* 0x0dc0-0x0dc7 */
+ 0x0e28, 0x0e29, 0x0e2a, 0x0e2b, 0x0e2c, 0x0e2d, 0x0e2e, 0x0e2f, /* 0x0dc8-0x0dcf */
+ 0x0e30, 0x0e31, 0x0e32, 0x0e33, 0x0e34, 0x0e35, 0x0e36, 0x0e37, /* 0x0dd0-0x0dd7 */
+ 0x0e38, 0x0e39, 0x0e3a, 0x0000, 0x0000, 0x0000, 0x0e3e, 0x0e3f, /* 0x0dd8-0x0ddf */
+ 0x0e40, 0x0e41, 0x0e42, 0x0e43, 0x0e44, 0x0e45, 0x0e46, 0x0e47, /* 0x0de0-0x0de7 */
+ 0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c, 0x0e4d, 0x0000, 0x0000, /* 0x0de8-0x0def */
+ 0x0e50, 0x0e51, 0x0e52, 0x0e53, 0x0e54, 0x0e55, 0x0e56, 0x0e57, /* 0x0df0-0x0df7 */
+ 0x0e58, 0x0e59 /* 0x0df8-0x0dff */
+};
+
+static unsigned short const keysym_to_unicode_ea0_eff[] = {
+ 0x0000, 0x1101, 0x1101, 0x11aa, 0x1102, 0x11ac, 0x11ad, 0x1103, /* 0x0ea0-0x0ea7 */
+ 0x1104, 0x1105, 0x11b0, 0x11b1, 0x11b2, 0x11b3, 0x11b4, 0x11b5, /* 0x0ea8-0x0eaf */
+ 0x11b6, 0x1106, 0x1107, 0x1108, 0x11b9, 0x1109, 0x110a, 0x110b, /* 0x0eb0-0x0eb7 */
+ 0x110c, 0x110d, 0x110e, 0x110f, 0x1110, 0x1111, 0x1112, 0x1161, /* 0x0eb8-0x0ebf */
+ 0x1162, 0x1163, 0x1164, 0x1165, 0x1166, 0x1167, 0x1168, 0x1169, /* 0x0ec0-0x0ec7 */
+ 0x116a, 0x116b, 0x116c, 0x116d, 0x116e, 0x116f, 0x1170, 0x1171, /* 0x0ec8-0x0ecf */
+ 0x1172, 0x1173, 0x1174, 0x1175, 0x11a8, 0x11a9, 0x11aa, 0x11ab, /* 0x0ed0-0x0ed7 */
+ 0x11ac, 0x11ad, 0x11ae, 0x11af, 0x11b0, 0x11b1, 0x11b2, 0x11b3, /* 0x0ed8-0x0edf */
+ 0x11b4, 0x11b5, 0x11b6, 0x11b7, 0x11b8, 0x11b9, 0x11ba, 0x11bb, /* 0x0ee0-0x0ee7 */
+ 0x11bc, 0x11bd, 0x11be, 0x11bf, 0x11c0, 0x11c1, 0x11c2, 0x0000, /* 0x0ee8-0x0eef */
+ 0x0000, 0x0000, 0x1140, 0x0000, 0x0000, 0x1159, 0x119e, 0x0000, /* 0x0ef0-0x0ef7 */
+ 0x11eb, 0x0000, 0x11f9, 0x0000, 0x0000, 0x0000, 0x0000, 0x20a9, /* 0x0ef8-0x0eff */
+};
+
+static unsigned short keysym_to_unicode_12a1_12fe[] = {
+ 0x1e02, 0x1e03, 0x0000, 0x0000, 0x0000, 0x1e0a, 0x0000, /* 0x12a0-0x12a7 */
+ 0x1e80, 0x0000, 0x1e82, 0x1e0b, 0x1ef2, 0x0000, 0x0000, 0x0000, /* 0x12a8-0x12af */
+ 0x1e1e, 0x1e1f, 0x0000, 0x0000, 0x1e40, 0x1e41, 0x0000, 0x1e56, /* 0x12b0-0x12b7 */
+ 0x1e81, 0x1e57, 0x1e83, 0x1e60, 0x1ef3, 0x1e84, 0x1e85, 0x1e61, /* 0x12b8-0x12bf */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x12c0-0x12c7 */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x12c8-0x12cf */
+ 0x0174, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1e6a, /* 0x12d0-0x12d7 */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0176, 0x0000, /* 0x12d8-0x12df */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x12e0-0x12e7 */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x12e8-0x12ef */
+ 0x0175, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1e6b, /* 0x12f0-0x12f7 */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0177 /* 0x12f0-0x12ff */
+};
+
+static unsigned short const keysym_to_unicode_13bc_13be[] = {
+ 0x0152, 0x0153, 0x0178 /* 0x13b8-0x13bf */
+};
+
+static unsigned short keysym_to_unicode_14a1_14ff[] = {
+ 0x2741, 0x00a7, 0x0589, 0x0029, 0x0028, 0x00bb, 0x00ab, /* 0x14a0-0x14a7 */
+ 0x2014, 0x002e, 0x055d, 0x002c, 0x2013, 0x058a, 0x2026, 0x055c, /* 0x14a8-0x14af */
+ 0x055b, 0x055e, 0x0531, 0x0561, 0x0532, 0x0562, 0x0533, 0x0563, /* 0x14b0-0x14b7 */
+ 0x0534, 0x0564, 0x0535, 0x0565, 0x0536, 0x0566, 0x0537, 0x0567, /* 0x14b8-0x14bf */
+ 0x0538, 0x0568, 0x0539, 0x0569, 0x053a, 0x056a, 0x053b, 0x056b, /* 0x14c0-0x14c7 */
+ 0x053c, 0x056c, 0x053d, 0x056d, 0x053e, 0x056e, 0x053f, 0x056f, /* 0x14c8-0x14cf */
+ 0x0540, 0x0570, 0x0541, 0x0571, 0x0542, 0x0572, 0x0543, 0x0573, /* 0x14d0-0x14d7 */
+ 0x0544, 0x0574, 0x0545, 0x0575, 0x0546, 0x0576, 0x0547, 0x0577, /* 0x14d8-0x14df */
+ 0x0548, 0x0578, 0x0549, 0x0579, 0x054a, 0x057a, 0x054b, 0x057b, /* 0x14e0-0x14e7 */
+ 0x054c, 0x057c, 0x054d, 0x057d, 0x054e, 0x057e, 0x054f, 0x057f, /* 0x14e8-0x14ef */
+ 0x0550, 0x0580, 0x0551, 0x0581, 0x0552, 0x0582, 0x0553, 0x0583, /* 0x14f0-0x14f7 */
+ 0x0554, 0x0584, 0x0555, 0x0585, 0x0556, 0x0586, 0x2019, 0x0027, /* 0x14f8-0x14ff */
+};
+
+static unsigned short keysym_to_unicode_15d0_15f6[] = {
+ 0x10d0, 0x10d1, 0x10d2, 0x10d3, 0x10d4, 0x10d5, 0x10d6, 0x10d7, /* 0x15d0-0x15d7 */
+ 0x10d8, 0x10d9, 0x10da, 0x10db, 0x10dc, 0x10dd, 0x10de, 0x10df, /* 0x15d8-0x15df */
+ 0x10e0, 0x10e1, 0x10e2, 0x10e3, 0x10e4, 0x10e5, 0x10e6, 0x10e7, /* 0x15e0-0x15e7 */
+ 0x10e8, 0x10e9, 0x10ea, 0x10eb, 0x10ec, 0x10ed, 0x10ee, 0x10ef, /* 0x15e8-0x15ef */
+ 0x10f0, 0x10f1, 0x10f2, 0x10f3, 0x10f4, 0x10f5, 0x10f6 /* 0x15f0-0x15f7 */
+};
+
+static unsigned short keysym_to_unicode_16a0_16f6[] = {
+ 0x0000, 0x0000, 0xf0a2, 0x1e8a, 0x0000, 0xf0a5, 0x012c, 0xf0a7, /* 0x16a0-0x16a7 */
+ 0xf0a8, 0x01b5, 0x01e6, 0x0000, 0x0000, 0x0000, 0x0000, 0x019f, /* 0x16a8-0x16af */
+ 0x0000, 0x0000, 0xf0b2, 0x1e8b, 0x01d1, 0xf0b5, 0x012d, 0xf0b7, /* 0x16b0-0x16b7 */
+ 0xf0b8, 0x01b6, 0x01e7, 0x0000, 0x0000, 0x01d2, 0x0000, 0x0275, /* 0x16b8-0x16bf */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x018f, 0x0000, /* 0x16c0-0x16c7 */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x16c8-0x16cf */
+ 0x0000, 0x1e36, 0xf0d2, 0xf0d3, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x16d0-0x16d7 */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x16d8-0x16df */
+ 0x0000, 0x1e37, 0xf0e2, 0xf0e3, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x16e0-0x16e7 */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 0x16e8-0x16ef */
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0259 /* 0x16f0-0x16f6 */
+};
+
+static unsigned short const keysym_to_unicode_1e9f_1eff[] = {
+ 0x0303,
+ 0x1ea0, 0x1ea1, 0x1ea2, 0x1ea3, 0x1ea4, 0x1ea5, 0x1ea6, 0x1ea7, /* 0x1ea0-0x1ea7 */
+ 0x1ea8, 0x1ea9, 0x1eaa, 0x1eab, 0x1eac, 0x1ead, 0x1eae, 0x1eaf, /* 0x1ea8-0x1eaf */
+ 0x1eb0, 0x1eb1, 0x1eb2, 0x1eb3, 0x1eb4, 0x1eb5, 0x1eb6, 0x1eb7, /* 0x1eb0-0x1eb7 */
+ 0x1eb8, 0x1eb9, 0x1eba, 0x1ebb, 0x1ebc, 0x1ebd, 0x1ebe, 0x1ebf, /* 0x1eb8-0x1ebf */
+ 0x1ec0, 0x1ec1, 0x1ec2, 0x1ec3, 0x1ec4, 0x1ec5, 0x1ec6, 0x1ec7, /* 0x1ec0-0x1ec7 */
+ 0x1ec8, 0x1ec9, 0x1eca, 0x1ecb, 0x1ecc, 0x1ecd, 0x1ece, 0x1ecf, /* 0x1ec8-0x1ecf */
+ 0x1ed0, 0x1ed1, 0x1ed2, 0x1ed3, 0x1ed4, 0x1ed5, 0x1ed6, 0x1ed7, /* 0x1ed0-0x1ed7 */
+ 0x1ed8, 0x1ed9, 0x1eda, 0x1edb, 0x1edc, 0x1edd, 0x1ede, 0x1edf, /* 0x1ed8-0x1edf */
+ 0x1ee0, 0x1ee1, 0x1ee2, 0x1ee3, 0x1ee4, 0x1ee5, 0x1ee6, 0x1ee7, /* 0x1ee0-0x1ee7 */
+ 0x1ee8, 0x1ee9, 0x1eea, 0x1eeb, 0x1eec, 0x1eed, 0x1eee, 0x1eef, /* 0x1ee8-0x1eef */
+ 0x1ef0, 0x1ef1, 0x0300, 0x0301, 0x1ef4, 0x1ef5, 0x1ef6, 0x1ef7, /* 0x1ef0-0x1ef7 */
+ 0x1ef8, 0x1ef9, 0x01a0, 0x01a1, 0x01af, 0x01b0, 0x0309, 0x0323 /* 0x1ef8-0x1eff */
+};
+
+static unsigned short const keysym_to_unicode_20a0_20ac[] = {
+ 0x20a0, 0x20a1, 0x20a2, 0x20a3, 0x20a4, 0x20a5, 0x20a6, 0x20a7, /* 0x20a0-0x20a7 */
+ 0x20a8, 0x20a9, 0x20aa, 0x20ab, 0x20ac /* 0x20a8-0x20af */
+};
+
+unsigned int
+X11_KeySymToUcs4(KeySym keysym)
+{
+ /* 'Unicode keysym' */
+ if ((keysym & 0xff000000) == 0x01000000)
+ return (keysym & 0x00ffffff);
+
+ if (keysym > 0 && keysym < 0x100)
+ return keysym;
+ else if (keysym > 0x1a0 && keysym < 0x200)
+ return keysym_to_unicode_1a1_1ff[keysym - 0x1a1];
+ else if (keysym > 0x2a0 && keysym < 0x2ff)
+ return keysym_to_unicode_2a1_2fe[keysym - 0x2a1];
+ else if (keysym > 0x3a1 && keysym < 0x3ff)
+ return keysym_to_unicode_3a2_3fe[keysym - 0x3a2];
+ else if (keysym > 0x4a0 && keysym < 0x4e0)
+ return keysym_to_unicode_4a1_4df[keysym - 0x4a1];
+ else if (keysym > 0x589 && keysym < 0x5ff)
+ return keysym_to_unicode_590_5fe[keysym - 0x590];
+ else if (keysym > 0x67f && keysym < 0x700)
+ return keysym_to_unicode_680_6ff[keysym - 0x680];
+ else if (keysym > 0x7a0 && keysym < 0x7fa)
+ return keysym_to_unicode_7a1_7f9[keysym - 0x7a1];
+ else if (keysym > 0x8a3 && keysym < 0x8ff)
+ return keysym_to_unicode_8a4_8fe[keysym - 0x8a4];
+ else if (keysym > 0x9de && keysym < 0x9f9)
+ return keysym_to_unicode_9df_9f8[keysym - 0x9df];
+ else if (keysym > 0xaa0 && keysym < 0xaff)
+ return keysym_to_unicode_aa1_afe[keysym - 0xaa1];
+ else if (keysym > 0xcde && keysym < 0xcfb)
+ return keysym_to_unicode_cdf_cfa[keysym - 0xcdf];
+ else if (keysym > 0xda0 && keysym < 0xdfa)
+ return keysym_to_unicode_da1_df9[keysym - 0xda1];
+ else if (keysym > 0xe9f && keysym < 0xf00)
+ return keysym_to_unicode_ea0_eff[keysym - 0xea0];
+ else if (keysym > 0x12a0 && keysym < 0x12ff)
+ return keysym_to_unicode_12a1_12fe[keysym - 0x12a1];
+ else if (keysym > 0x13bb && keysym < 0x13bf)
+ return keysym_to_unicode_13bc_13be[keysym - 0x13bc];
+ else if (keysym > 0x14a0 && keysym < 0x1500)
+ return keysym_to_unicode_14a1_14ff[keysym - 0x14a1];
+ else if (keysym > 0x15cf && keysym < 0x15f7)
+ return keysym_to_unicode_15d0_15f6[keysym - 0x15d0];
+ else if (keysym > 0x169f && keysym < 0x16f7)
+ return keysym_to_unicode_16a0_16f6[keysym - 0x16a0];
+ else if (keysym > 0x1e9e && keysym < 0x1f00)
+ return keysym_to_unicode_1e9f_1eff[keysym - 0x1e9f];
+ else if (keysym > 0x209f && keysym < 0x20ad)
+ return keysym_to_unicode_20a0_20ac[keysym - 0x20a0];
+ else
+ return 0;
+}
+
+#endif /* SDL_VIDEO_DRIVER_X11 */
+
diff --git a/src/3rdparty/SDL2/src/video/x11/imKStoUCS.h b/src/3rdparty/SDL2/src/video/x11/imKStoUCS.h
new file mode 100644
index 0000000..fe4381d
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/x11/imKStoUCS.h
@@ -0,0 +1,32 @@
+#ifndef _imKStoUCS_h
+#define _imKStoUCS_h
+
+/*
+Copyright (C) 2003-2006,2008 Jamey Sharp, Josh Triplett
+Copyright © 2009 Red Hat, Inc.
+Copyright 1990-1992,1999,2000,2004,2009,2010 Oracle and/or its affiliates.
+All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+*/
+
+extern unsigned int X11_KeySymToUcs4(KeySym keysym);
+
+#endif /* _imKStoUCS_h */
diff --git a/src/3rdparty/SDL2/src/video/yuv2rgb/LICENSE b/src/3rdparty/SDL2/src/video/yuv2rgb/LICENSE
new file mode 100644
index 0000000..a76efd7
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/yuv2rgb/LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) 2016, Adrien Descamps
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+* Neither the name of yuv2rgb nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/src/3rdparty/SDL2/src/video/yuv2rgb/README.md b/src/3rdparty/SDL2/src/video/yuv2rgb/README.md
new file mode 100644
index 0000000..21191e9
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/yuv2rgb/README.md
@@ -0,0 +1,63 @@
+From: https://github.com/descampsa/yuv2rgb
+# yuv2rgb
+C library for fast image conversion between yuv420p and rgb24.
+
+This is a simple library for optimized image conversion between YUV420p and rgb24.
+It was done mainly as an exercise to learn to use sse intrinsics, so there may still be room for optimization.
+
+For each conversion, a standard c optimized function and two sse function (with aligned and unaligned memory) are implemented.
+The sse version requires only SSE2, which is available on any reasonably recent CPU.
+The library also supports the three different YUV (YCrCb to be correct) color spaces that exist (see comments in code), and others can be added simply.
+
+There is a simple test program, that convert a raw YUV file to rgb ppm format, and measure computation time.
+Optionally, it also compares the result and computation time with the ffmpeg implementation (that uses MMX), and with the IPP functions.
+
+To compile, simply do :
+
+ mkdir build
+ cd build
+ cmake -DCMAKE_BUILD_TYPE=Release ..
+ make
+
+The test program only support raw YUV files for the YUV420 format, and ppm for the RGB24 format.
+To generate a raw yuv file, you can use avconv:
+
+ avconv -i example.jpg -c:v rawvideo -pix_fmt yuv420p example.yuv
+
+To generate the rgb file, you can use the ImageMagick convert program:
+
+ convert example.jpg example.ppm
+
+Then, for YUV420 to RGB24 conversion, use the test program like that:
+
+ ./test_yuv_rgb yuv2rgb image.yuv 4096 2160 image
+
+The second and third parameters are image width and height (that are needed because not available in the raw YUV file), and fourth parameter is the output filename template (several output files will be generated, named for example output_sse.ppm, output_av.ppm, etc.)
+
+Similarly, for RGB24 to YUV420 conversion:
+
+ ./test_yuv_rgb yuv2rgb image.ppm image
+
+On my computer, the test program on a 4K image give the following for yuv2rgb:
+
+ Time will be measured in each configuration for 100 iterations...
+ Processing time (std) : 2.630193 sec
+ Processing time (sse2_unaligned) : 0.704394 sec
+ Processing time (ffmpeg_unaligned) : 1.221432 sec
+ Processing time (ipp_unaligned) : 0.636274 sec
+ Processing time (sse2_aligned) : 0.606648 sec
+ Processing time (ffmpeg_aligned) : 1.227100 sec
+ Processing time (ipp_aligned) : 0.636951 sec
+
+And for rgb2yuv:
+
+ Time will be measured in each configuration for 100 iterations...
+ Processing time (std) : 2.588675 sec
+ Processing time (sse2_unaligned) : 0.676625 sec
+ Processing time (ffmpeg_unaligned) : 3.385816 sec
+ Processing time (ipp_unaligned) : 0.593890 sec
+ Processing time (sse2_aligned) : 0.640630 sec
+ Processing time (ffmpeg_aligned) : 3.397952 sec
+ Processing time (ipp_aligned) : 0.579043 sec
+
+configuration : gcc 4.9.2, swscale 3.0.0, IPP 9.0.1, intel i7-5500U
diff --git a/src/3rdparty/SDL2/src/video/yuv2rgb/yuv_rgb.c b/src/3rdparty/SDL2/src/video/yuv2rgb/yuv_rgb.c
new file mode 100644
index 0000000..891dae2
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/yuv2rgb/yuv_rgb.c
@@ -0,0 +1,687 @@
+// Copyright 2016 Adrien Descamps
+// Distributed under BSD 3-Clause License
+#include "../../SDL_internal.h"
+
+#include "yuv_rgb.h"
+
+#include "SDL_cpuinfo.h"
+/*#include <x86intrin.h>*/
+
+#define PRECISION 6
+#define PRECISION_FACTOR (1<<PRECISION)
+
+typedef struct
+{
+ uint8_t y_shift;
+ int16_t matrix[3][3];
+} RGB2YUVParam;
+// |Y| |y_shift| |matrix[0][0] matrix[0][1] matrix[0][2]| |R|
+// |U| = | 128 | + 1/PRECISION_FACTOR * |matrix[1][0] matrix[1][1] matrix[1][2]| * |G|
+// |V| | 128 | |matrix[2][0] matrix[2][1] matrix[2][2]| |B|
+
+typedef struct
+{
+ uint8_t y_shift;
+ int16_t y_factor;
+ int16_t v_r_factor;
+ int16_t u_g_factor;
+ int16_t v_g_factor;
+ int16_t u_b_factor;
+} YUV2RGBParam;
+// |R| |y_factor 0 v_r_factor| |Y-y_shift|
+// |G| = 1/PRECISION_FACTOR * |y_factor u_g_factor v_g_factor| * | U-128 |
+// |B| |y_factor u_b_factor 0 | | V-128 |
+
+#define V(value) (int16_t)((value*PRECISION_FACTOR)+0.5)
+
+// for ITU-T T.871, values can be found in section 7
+// for ITU-R BT.601-7 values are derived from equations in sections 2.5.1-2.5.3, assuming RGB is encoded using full range ([0-1]<->[0-255])
+// for ITU-R BT.709-6 values are derived from equations in sections 3.2-3.4, assuming RGB is encoded using full range ([0-1]<->[0-255])
+// all values are rounded to the fourth decimal
+
+static const YUV2RGBParam YUV2RGB[3] = {
+ // ITU-T T.871 (JPEG)
+ {/*.y_shift=*/ 0, /*.y_factor=*/ V(1.0), /*.v_r_factor=*/ V(1.402), /*.u_g_factor=*/ -V(0.3441), /*.v_g_factor=*/ -V(0.7141), /*.u_b_factor=*/ V(1.772)},
+ // ITU-R BT.601-7
+ {/*.y_shift=*/ 16, /*.y_factor=*/ V(1.1644), /*.v_r_factor=*/ V(1.596), /*.u_g_factor=*/ -V(0.3918), /*.v_g_factor=*/ -V(0.813), /*.u_b_factor=*/ V(2.0172)},
+ // ITU-R BT.709-6
+ {/*.y_shift=*/ 16, /*.y_factor=*/ V(1.1644), /*.v_r_factor=*/ V(1.7927), /*.u_g_factor=*/ -V(0.2132), /*.v_g_factor=*/ -V(0.5329), /*.u_b_factor=*/ V(2.1124)}
+};
+
+static const RGB2YUVParam RGB2YUV[3] = {
+ // ITU-T T.871 (JPEG)
+ {/*.y_shift=*/ 0, /*.matrix=*/ {{V(0.299), V(0.587), V(0.114)}, {-V(0.1687), -V(0.3313), V(0.5)}, {V(0.5), -V(0.4187), -V(0.0813)}}},
+ // ITU-R BT.601-7
+ {/*.y_shift=*/ 16, /*.matrix=*/ {{V(0.2568), V(0.5041), V(0.0979)}, {-V(0.1482), -V(0.291), V(0.4392)}, {V(0.4392), -V(0.3678), -V(0.0714)}}},
+ // ITU-R BT.709-6
+ {/*.y_shift=*/ 16, /*.matrix=*/ {{V(0.1826), V(0.6142), V(0.062)}, {-V(0.1006), -V(0.3386), V(0.4392)}, {V(0.4392), -V(0.3989), -V(0.0403)}}}
+};
+
+/* The various layouts of YUV data we support */
+#define YUV_FORMAT_420 1
+#define YUV_FORMAT_422 2
+#define YUV_FORMAT_NV12 3
+
+/* The various formats of RGB pixel that we support */
+#define RGB_FORMAT_RGB565 1
+#define RGB_FORMAT_RGB24 2
+#define RGB_FORMAT_RGBA 3
+#define RGB_FORMAT_BGRA 4
+#define RGB_FORMAT_ARGB 5
+#define RGB_FORMAT_ABGR 6
+
+// divide by PRECISION_FACTOR and clamp to [0:255] interval
+// input must be in the [-128*PRECISION_FACTOR:384*PRECISION_FACTOR] range
+static uint8_t clampU8(int32_t v)
+{
+ static const uint8_t lut[512] =
+ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,
+ 47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,
+ 91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,
+ 126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,
+ 159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
+ 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,
+ 225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
+ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
+ };
+ return lut[(v+128*PRECISION_FACTOR)>>PRECISION];
+}
+
+
+#define STD_FUNCTION_NAME yuv420_rgb565_std
+#define YUV_FORMAT YUV_FORMAT_420
+#define RGB_FORMAT RGB_FORMAT_RGB565
+#include "yuv_rgb_std_func.h"
+
+#define STD_FUNCTION_NAME yuv420_rgb24_std
+#define YUV_FORMAT YUV_FORMAT_420
+#define RGB_FORMAT RGB_FORMAT_RGB24
+#include "yuv_rgb_std_func.h"
+
+#define STD_FUNCTION_NAME yuv420_rgba_std
+#define YUV_FORMAT YUV_FORMAT_420
+#define RGB_FORMAT RGB_FORMAT_RGBA
+#include "yuv_rgb_std_func.h"
+
+#define STD_FUNCTION_NAME yuv420_bgra_std
+#define YUV_FORMAT YUV_FORMAT_420
+#define RGB_FORMAT RGB_FORMAT_BGRA
+#include "yuv_rgb_std_func.h"
+
+#define STD_FUNCTION_NAME yuv420_argb_std
+#define YUV_FORMAT YUV_FORMAT_420
+#define RGB_FORMAT RGB_FORMAT_ARGB
+#include "yuv_rgb_std_func.h"
+
+#define STD_FUNCTION_NAME yuv420_abgr_std
+#define YUV_FORMAT YUV_FORMAT_420
+#define RGB_FORMAT RGB_FORMAT_ABGR
+#include "yuv_rgb_std_func.h"
+
+#define STD_FUNCTION_NAME yuv422_rgb565_std
+#define YUV_FORMAT YUV_FORMAT_422
+#define RGB_FORMAT RGB_FORMAT_RGB565
+#include "yuv_rgb_std_func.h"
+
+#define STD_FUNCTION_NAME yuv422_rgb24_std
+#define YUV_FORMAT YUV_FORMAT_422
+#define RGB_FORMAT RGB_FORMAT_RGB24
+#include "yuv_rgb_std_func.h"
+
+#define STD_FUNCTION_NAME yuv422_rgba_std
+#define YUV_FORMAT YUV_FORMAT_422
+#define RGB_FORMAT RGB_FORMAT_RGBA
+#include "yuv_rgb_std_func.h"
+
+#define STD_FUNCTION_NAME yuv422_bgra_std
+#define YUV_FORMAT YUV_FORMAT_422
+#define RGB_FORMAT RGB_FORMAT_BGRA
+#include "yuv_rgb_std_func.h"
+
+#define STD_FUNCTION_NAME yuv422_argb_std
+#define YUV_FORMAT YUV_FORMAT_422
+#define RGB_FORMAT RGB_FORMAT_ARGB
+#include "yuv_rgb_std_func.h"
+
+#define STD_FUNCTION_NAME yuv422_abgr_std
+#define YUV_FORMAT YUV_FORMAT_422
+#define RGB_FORMAT RGB_FORMAT_ABGR
+#include "yuv_rgb_std_func.h"
+
+#define STD_FUNCTION_NAME yuvnv12_rgb565_std
+#define YUV_FORMAT YUV_FORMAT_NV12
+#define RGB_FORMAT RGB_FORMAT_RGB565
+#include "yuv_rgb_std_func.h"
+
+#define STD_FUNCTION_NAME yuvnv12_rgb24_std
+#define YUV_FORMAT YUV_FORMAT_NV12
+#define RGB_FORMAT RGB_FORMAT_RGB24
+#include "yuv_rgb_std_func.h"
+
+#define STD_FUNCTION_NAME yuvnv12_rgba_std
+#define YUV_FORMAT YUV_FORMAT_NV12
+#define RGB_FORMAT RGB_FORMAT_RGBA
+#include "yuv_rgb_std_func.h"
+
+#define STD_FUNCTION_NAME yuvnv12_bgra_std
+#define YUV_FORMAT YUV_FORMAT_NV12
+#define RGB_FORMAT RGB_FORMAT_BGRA
+#include "yuv_rgb_std_func.h"
+
+#define STD_FUNCTION_NAME yuvnv12_argb_std
+#define YUV_FORMAT YUV_FORMAT_NV12
+#define RGB_FORMAT RGB_FORMAT_ARGB
+#include "yuv_rgb_std_func.h"
+
+#define STD_FUNCTION_NAME yuvnv12_abgr_std
+#define YUV_FORMAT YUV_FORMAT_NV12
+#define RGB_FORMAT RGB_FORMAT_ABGR
+#include "yuv_rgb_std_func.h"
+
+void rgb24_yuv420_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *RGB, uint32_t RGB_stride,
+ uint8_t *Y, uint8_t *U, uint8_t *V, uint32_t Y_stride, uint32_t UV_stride,
+ YCbCrType yuv_type)
+{
+ const RGB2YUVParam *const param = &(RGB2YUV[yuv_type]);
+
+ uint32_t x, y;
+ for(y=0; y<(height-1); y+=2)
+ {
+ const uint8_t *rgb_ptr1=RGB+y*RGB_stride,
+ *rgb_ptr2=RGB+(y+1)*RGB_stride;
+
+ uint8_t *y_ptr1=Y+y*Y_stride,
+ *y_ptr2=Y+(y+1)*Y_stride,
+ *u_ptr=U+(y/2)*UV_stride,
+ *v_ptr=V+(y/2)*UV_stride;
+
+ for(x=0; x<(width-1); x+=2)
+ {
+ // compute yuv for the four pixels, u and v values are summed
+ int32_t y_tmp, u_tmp, v_tmp;
+
+ y_tmp = param->matrix[0][0]*rgb_ptr1[0] + param->matrix[0][1]*rgb_ptr1[1] + param->matrix[0][2]*rgb_ptr1[2];
+ u_tmp = param->matrix[1][0]*rgb_ptr1[0] + param->matrix[1][1]*rgb_ptr1[1] + param->matrix[1][2]*rgb_ptr1[2];
+ v_tmp = param->matrix[2][0]*rgb_ptr1[0] + param->matrix[2][1]*rgb_ptr1[1] + param->matrix[2][2]*rgb_ptr1[2];
+ y_ptr1[0]=clampU8(y_tmp+((param->y_shift)<<PRECISION));
+
+ y_tmp = param->matrix[0][0]*rgb_ptr1[3] + param->matrix[0][1]*rgb_ptr1[4] + param->matrix[0][2]*rgb_ptr1[5];
+ u_tmp += param->matrix[1][0]*rgb_ptr1[3] + param->matrix[1][1]*rgb_ptr1[4] + param->matrix[1][2]*rgb_ptr1[5];
+ v_tmp += param->matrix[2][0]*rgb_ptr1[3] + param->matrix[2][1]*rgb_ptr1[4] + param->matrix[2][2]*rgb_ptr1[5];
+ y_ptr1[1]=clampU8(y_tmp+((param->y_shift)<<PRECISION));
+
+ y_tmp = param->matrix[0][0]*rgb_ptr2[0] + param->matrix[0][1]*rgb_ptr2[1] + param->matrix[0][2]*rgb_ptr2[2];
+ u_tmp += param->matrix[1][0]*rgb_ptr2[0] + param->matrix[1][1]*rgb_ptr2[1] + param->matrix[1][2]*rgb_ptr2[2];
+ v_tmp += param->matrix[2][0]*rgb_ptr2[0] + param->matrix[2][1]*rgb_ptr2[1] + param->matrix[2][2]*rgb_ptr2[2];
+ y_ptr2[0]=clampU8(y_tmp+((param->y_shift)<<PRECISION));
+
+ y_tmp = param->matrix[0][0]*rgb_ptr2[3] + param->matrix[0][1]*rgb_ptr2[4] + param->matrix[0][2]*rgb_ptr2[5];
+ u_tmp += param->matrix[1][0]*rgb_ptr2[3] + param->matrix[1][1]*rgb_ptr2[4] + param->matrix[1][2]*rgb_ptr2[5];
+ v_tmp += param->matrix[2][0]*rgb_ptr2[3] + param->matrix[2][1]*rgb_ptr2[4] + param->matrix[2][2]*rgb_ptr2[5];
+ y_ptr2[1]=clampU8(y_tmp+((param->y_shift)<<PRECISION));
+
+ u_ptr[0] = clampU8(u_tmp/4+(128<<PRECISION));
+ v_ptr[0] = clampU8(v_tmp/4+(128<<PRECISION));
+
+ rgb_ptr1 += 6;
+ rgb_ptr2 += 6;
+ y_ptr1 += 2;
+ y_ptr2 += 2;
+ u_ptr += 1;
+ v_ptr += 1;
+ }
+ }
+}
+
+#ifdef __SSE2__
+
+#define SSE_FUNCTION_NAME yuv420_rgb565_sse
+#define STD_FUNCTION_NAME yuv420_rgb565_std
+#define YUV_FORMAT YUV_FORMAT_420
+#define RGB_FORMAT RGB_FORMAT_RGB565
+#define SSE_ALIGNED
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv420_rgb565_sseu
+#define STD_FUNCTION_NAME yuv420_rgb565_std
+#define YUV_FORMAT YUV_FORMAT_420
+#define RGB_FORMAT RGB_FORMAT_RGB565
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv420_rgb24_sse
+#define STD_FUNCTION_NAME yuv420_rgb24_std
+#define YUV_FORMAT YUV_FORMAT_420
+#define RGB_FORMAT RGB_FORMAT_RGB24
+#define SSE_ALIGNED
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv420_rgb24_sseu
+#define STD_FUNCTION_NAME yuv420_rgb24_std
+#define YUV_FORMAT YUV_FORMAT_420
+#define RGB_FORMAT RGB_FORMAT_RGB24
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv420_rgba_sse
+#define STD_FUNCTION_NAME yuv420_rgba_std
+#define YUV_FORMAT YUV_FORMAT_420
+#define RGB_FORMAT RGB_FORMAT_RGBA
+#define SSE_ALIGNED
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv420_rgba_sseu
+#define STD_FUNCTION_NAME yuv420_rgba_std
+#define YUV_FORMAT YUV_FORMAT_420
+#define RGB_FORMAT RGB_FORMAT_RGBA
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv420_bgra_sse
+#define STD_FUNCTION_NAME yuv420_bgra_std
+#define YUV_FORMAT YUV_FORMAT_420
+#define RGB_FORMAT RGB_FORMAT_BGRA
+#define SSE_ALIGNED
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv420_bgra_sseu
+#define STD_FUNCTION_NAME yuv420_bgra_std
+#define YUV_FORMAT YUV_FORMAT_420
+#define RGB_FORMAT RGB_FORMAT_BGRA
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv420_argb_sse
+#define STD_FUNCTION_NAME yuv420_argb_std
+#define YUV_FORMAT YUV_FORMAT_420
+#define RGB_FORMAT RGB_FORMAT_ARGB
+#define SSE_ALIGNED
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv420_argb_sseu
+#define STD_FUNCTION_NAME yuv420_argb_std
+#define YUV_FORMAT YUV_FORMAT_420
+#define RGB_FORMAT RGB_FORMAT_ARGB
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv420_abgr_sse
+#define STD_FUNCTION_NAME yuv420_abgr_std
+#define YUV_FORMAT YUV_FORMAT_420
+#define RGB_FORMAT RGB_FORMAT_ABGR
+#define SSE_ALIGNED
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv420_abgr_sseu
+#define STD_FUNCTION_NAME yuv420_abgr_std
+#define YUV_FORMAT YUV_FORMAT_420
+#define RGB_FORMAT RGB_FORMAT_ABGR
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv422_rgb565_sse
+#define STD_FUNCTION_NAME yuv422_rgb565_std
+#define YUV_FORMAT YUV_FORMAT_422
+#define RGB_FORMAT RGB_FORMAT_RGB565
+#define SSE_ALIGNED
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv422_rgb565_sseu
+#define STD_FUNCTION_NAME yuv422_rgb565_std
+#define YUV_FORMAT YUV_FORMAT_422
+#define RGB_FORMAT RGB_FORMAT_RGB565
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv422_rgb24_sse
+#define STD_FUNCTION_NAME yuv422_rgb24_std
+#define YUV_FORMAT YUV_FORMAT_422
+#define RGB_FORMAT RGB_FORMAT_RGB24
+#define SSE_ALIGNED
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv422_rgb24_sseu
+#define STD_FUNCTION_NAME yuv422_rgb24_std
+#define YUV_FORMAT YUV_FORMAT_422
+#define RGB_FORMAT RGB_FORMAT_RGB24
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv422_rgba_sse
+#define STD_FUNCTION_NAME yuv422_rgba_std
+#define YUV_FORMAT YUV_FORMAT_422
+#define RGB_FORMAT RGB_FORMAT_RGBA
+#define SSE_ALIGNED
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv422_rgba_sseu
+#define STD_FUNCTION_NAME yuv422_rgba_std
+#define YUV_FORMAT YUV_FORMAT_422
+#define RGB_FORMAT RGB_FORMAT_RGBA
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv422_bgra_sse
+#define STD_FUNCTION_NAME yuv422_bgra_std
+#define YUV_FORMAT YUV_FORMAT_422
+#define RGB_FORMAT RGB_FORMAT_BGRA
+#define SSE_ALIGNED
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv422_bgra_sseu
+#define STD_FUNCTION_NAME yuv422_bgra_std
+#define YUV_FORMAT YUV_FORMAT_422
+#define RGB_FORMAT RGB_FORMAT_BGRA
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv422_argb_sse
+#define STD_FUNCTION_NAME yuv422_argb_std
+#define YUV_FORMAT YUV_FORMAT_422
+#define RGB_FORMAT RGB_FORMAT_ARGB
+#define SSE_ALIGNED
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv422_argb_sseu
+#define STD_FUNCTION_NAME yuv422_argb_std
+#define YUV_FORMAT YUV_FORMAT_422
+#define RGB_FORMAT RGB_FORMAT_ARGB
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv422_abgr_sse
+#define STD_FUNCTION_NAME yuv422_abgr_std
+#define YUV_FORMAT YUV_FORMAT_422
+#define RGB_FORMAT RGB_FORMAT_ABGR
+#define SSE_ALIGNED
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuv422_abgr_sseu
+#define STD_FUNCTION_NAME yuv422_abgr_std
+#define YUV_FORMAT YUV_FORMAT_422
+#define RGB_FORMAT RGB_FORMAT_ABGR
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuvnv12_rgb565_sse
+#define STD_FUNCTION_NAME yuvnv12_rgb565_std
+#define YUV_FORMAT YUV_FORMAT_NV12
+#define RGB_FORMAT RGB_FORMAT_RGB565
+#define SSE_ALIGNED
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuvnv12_rgb565_sseu
+#define STD_FUNCTION_NAME yuvnv12_rgb565_std
+#define YUV_FORMAT YUV_FORMAT_NV12
+#define RGB_FORMAT RGB_FORMAT_RGB565
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuvnv12_rgb24_sse
+#define STD_FUNCTION_NAME yuvnv12_rgb24_std
+#define YUV_FORMAT YUV_FORMAT_NV12
+#define RGB_FORMAT RGB_FORMAT_RGB24
+#define SSE_ALIGNED
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuvnv12_rgb24_sseu
+#define STD_FUNCTION_NAME yuvnv12_rgb24_std
+#define YUV_FORMAT YUV_FORMAT_NV12
+#define RGB_FORMAT RGB_FORMAT_RGB24
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuvnv12_rgba_sse
+#define STD_FUNCTION_NAME yuvnv12_rgba_std
+#define YUV_FORMAT YUV_FORMAT_NV12
+#define RGB_FORMAT RGB_FORMAT_RGBA
+#define SSE_ALIGNED
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuvnv12_rgba_sseu
+#define STD_FUNCTION_NAME yuvnv12_rgba_std
+#define YUV_FORMAT YUV_FORMAT_NV12
+#define RGB_FORMAT RGB_FORMAT_RGBA
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuvnv12_bgra_sse
+#define STD_FUNCTION_NAME yuvnv12_bgra_std
+#define YUV_FORMAT YUV_FORMAT_NV12
+#define RGB_FORMAT RGB_FORMAT_BGRA
+#define SSE_ALIGNED
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuvnv12_bgra_sseu
+#define STD_FUNCTION_NAME yuvnv12_bgra_std
+#define YUV_FORMAT YUV_FORMAT_NV12
+#define RGB_FORMAT RGB_FORMAT_BGRA
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuvnv12_argb_sse
+#define STD_FUNCTION_NAME yuvnv12_argb_std
+#define YUV_FORMAT YUV_FORMAT_NV12
+#define RGB_FORMAT RGB_FORMAT_ARGB
+#define SSE_ALIGNED
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuvnv12_argb_sseu
+#define STD_FUNCTION_NAME yuvnv12_argb_std
+#define YUV_FORMAT YUV_FORMAT_NV12
+#define RGB_FORMAT RGB_FORMAT_ARGB
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuvnv12_abgr_sse
+#define STD_FUNCTION_NAME yuvnv12_abgr_std
+#define YUV_FORMAT YUV_FORMAT_NV12
+#define RGB_FORMAT RGB_FORMAT_ABGR
+#define SSE_ALIGNED
+#include "yuv_rgb_sse_func.h"
+
+#define SSE_FUNCTION_NAME yuvnv12_abgr_sseu
+#define STD_FUNCTION_NAME yuvnv12_abgr_std
+#define YUV_FORMAT YUV_FORMAT_NV12
+#define RGB_FORMAT RGB_FORMAT_ABGR
+#include "yuv_rgb_sse_func.h"
+
+
+#define UNPACK_RGB24_32_STEP1(RGB1, RGB2, RGB3, RGB4, RGB5, RGB6, R1, R2, G1, G2, B1, B2) \
+R1 = _mm_unpacklo_epi8(RGB1, RGB4); \
+R2 = _mm_unpackhi_epi8(RGB1, RGB4); \
+G1 = _mm_unpacklo_epi8(RGB2, RGB5); \
+G2 = _mm_unpackhi_epi8(RGB2, RGB5); \
+B1 = _mm_unpacklo_epi8(RGB3, RGB6); \
+B2 = _mm_unpackhi_epi8(RGB3, RGB6);
+
+#define UNPACK_RGB24_32_STEP2(RGB1, RGB2, RGB3, RGB4, RGB5, RGB6, R1, R2, G1, G2, B1, B2) \
+RGB1 = _mm_unpacklo_epi8(R1, G2); \
+RGB2 = _mm_unpackhi_epi8(R1, G2); \
+RGB3 = _mm_unpacklo_epi8(R2, B1); \
+RGB4 = _mm_unpackhi_epi8(R2, B1); \
+RGB5 = _mm_unpacklo_epi8(G1, B2); \
+RGB6 = _mm_unpackhi_epi8(G1, B2); \
+
+#define UNPACK_RGB24_32(RGB1, RGB2, RGB3, RGB4, RGB5, RGB6, R1, R2, G1, G2, B1, B2) \
+UNPACK_RGB24_32_STEP1(RGB1, RGB2, RGB3, RGB4, RGB5, RGB6, R1, R2, G1, G2, B1, B2) \
+UNPACK_RGB24_32_STEP2(RGB1, RGB2, RGB3, RGB4, RGB5, RGB6, R1, R2, G1, G2, B1, B2) \
+UNPACK_RGB24_32_STEP1(RGB1, RGB2, RGB3, RGB4, RGB5, RGB6, R1, R2, G1, G2, B1, B2) \
+UNPACK_RGB24_32_STEP2(RGB1, RGB2, RGB3, RGB4, RGB5, RGB6, R1, R2, G1, G2, B1, B2) \
+UNPACK_RGB24_32_STEP1(RGB1, RGB2, RGB3, RGB4, RGB5, RGB6, R1, R2, G1, G2, B1, B2) \
+
+#define RGB2YUV_16(R, G, B, Y, U, V) \
+Y = _mm_add_epi16(_mm_mullo_epi16(R, _mm_set1_epi16(param->matrix[0][0])), \
+ _mm_mullo_epi16(G, _mm_set1_epi16(param->matrix[0][1]))); \
+Y = _mm_add_epi16(Y, _mm_mullo_epi16(B, _mm_set1_epi16(param->matrix[0][2]))); \
+Y = _mm_add_epi16(Y, _mm_set1_epi16((param->y_shift)<<PRECISION)); \
+Y = _mm_srai_epi16(Y, PRECISION); \
+U = _mm_add_epi16(_mm_mullo_epi16(R, _mm_set1_epi16(param->matrix[1][0])), \
+ _mm_mullo_epi16(G, _mm_set1_epi16(param->matrix[1][1]))); \
+U = _mm_add_epi16(U, _mm_mullo_epi16(B, _mm_set1_epi16(param->matrix[1][2]))); \
+U = _mm_add_epi16(U, _mm_set1_epi16(128<<PRECISION)); \
+U = _mm_srai_epi16(U, PRECISION); \
+V = _mm_add_epi16(_mm_mullo_epi16(R, _mm_set1_epi16(param->matrix[2][0])), \
+ _mm_mullo_epi16(G, _mm_set1_epi16(param->matrix[2][1]))); \
+V = _mm_add_epi16(V, _mm_mullo_epi16(B, _mm_set1_epi16(param->matrix[2][2]))); \
+V = _mm_add_epi16(V, _mm_set1_epi16(128<<PRECISION)); \
+V = _mm_srai_epi16(V, PRECISION);
+
+#define RGB2YUV_32 \
+ __m128i r1, r2, b1, b2, g1, g2; \
+ __m128i r_16, g_16, b_16; \
+ __m128i y1_16, y2_16, u1_16, u2_16, v1_16, v2_16, y, u1, u2, v1, v2, u1_tmp, u2_tmp, v1_tmp, v2_tmp; \
+ __m128i rgb1 = LOAD_SI128((const __m128i*)(rgb_ptr1)), \
+ rgb2 = LOAD_SI128((const __m128i*)(rgb_ptr1+16)), \
+ rgb3 = LOAD_SI128((const __m128i*)(rgb_ptr1+32)), \
+ rgb4 = LOAD_SI128((const __m128i*)(rgb_ptr2)), \
+ rgb5 = LOAD_SI128((const __m128i*)(rgb_ptr2+16)), \
+ rgb6 = LOAD_SI128((const __m128i*)(rgb_ptr2+32)); \
+ /* unpack rgb24 data to r, g and b data in separate channels*/ \
+ UNPACK_RGB24_32(rgb1, rgb2, rgb3, rgb4, rgb5, rgb6, r1, r2, g1, g2, b1, b2) \
+ /* process pixels of first line */ \
+ r_16 = _mm_unpacklo_epi8(r1, _mm_setzero_si128()); \
+ g_16 = _mm_unpacklo_epi8(g1, _mm_setzero_si128()); \
+ b_16 = _mm_unpacklo_epi8(b1, _mm_setzero_si128()); \
+ RGB2YUV_16(r_16, g_16, b_16, y1_16, u1_16, v1_16) \
+ r_16 = _mm_unpackhi_epi8(r1, _mm_setzero_si128()); \
+ g_16 = _mm_unpackhi_epi8(g1, _mm_setzero_si128()); \
+ b_16 = _mm_unpackhi_epi8(b1, _mm_setzero_si128()); \
+ RGB2YUV_16(r_16, g_16, b_16, y2_16, u2_16, v2_16) \
+ y = _mm_packus_epi16(y1_16, y2_16); \
+ u1 = _mm_packus_epi16(u1_16, u2_16); \
+ v1 = _mm_packus_epi16(v1_16, v2_16); \
+ /* save Y values */ \
+ SAVE_SI128((__m128i*)(y_ptr1), y); \
+ /* process pixels of second line */ \
+ r_16 = _mm_unpacklo_epi8(r2, _mm_setzero_si128()); \
+ g_16 = _mm_unpacklo_epi8(g2, _mm_setzero_si128()); \
+ b_16 = _mm_unpacklo_epi8(b2, _mm_setzero_si128()); \
+ RGB2YUV_16(r_16, g_16, b_16, y1_16, u1_16, v1_16) \
+ r_16 = _mm_unpackhi_epi8(r2, _mm_setzero_si128()); \
+ g_16 = _mm_unpackhi_epi8(g2, _mm_setzero_si128()); \
+ b_16 = _mm_unpackhi_epi8(b2, _mm_setzero_si128()); \
+ RGB2YUV_16(r_16, g_16, b_16, y2_16, u2_16, v2_16) \
+ y = _mm_packus_epi16(y1_16, y2_16); \
+ u2 = _mm_packus_epi16(u1_16, u2_16); \
+ v2 = _mm_packus_epi16(v1_16, v2_16); \
+ /* save Y values */ \
+ SAVE_SI128((__m128i*)(y_ptr2), y); \
+ /* vertical subsampling of u/v values */ \
+ u1_tmp = _mm_avg_epu8(u1, u2); \
+ v1_tmp = _mm_avg_epu8(v1, v2); \
+ /* do the same again with next data */ \
+ rgb1 = LOAD_SI128((const __m128i*)(rgb_ptr1+48)); \
+ rgb2 = LOAD_SI128((const __m128i*)(rgb_ptr1+64)); \
+ rgb3 = LOAD_SI128((const __m128i*)(rgb_ptr1+80)); \
+ rgb4 = LOAD_SI128((const __m128i*)(rgb_ptr2+48)); \
+ rgb5 = LOAD_SI128((const __m128i*)(rgb_ptr2+64)); \
+ rgb6 = LOAD_SI128((const __m128i*)(rgb_ptr2+80)); \
+ /* unpack rgb24 data to r, g and b data in separate channels*/ \
+ UNPACK_RGB24_32(rgb1, rgb2, rgb3, rgb4, rgb5, rgb6, r1, r2, g1, g2, b1, b2) \
+ /* process pixels of first line */ \
+ r_16 = _mm_unpacklo_epi8(r1, _mm_setzero_si128()); \
+ g_16 = _mm_unpacklo_epi8(g1, _mm_setzero_si128()); \
+ b_16 = _mm_unpacklo_epi8(b1, _mm_setzero_si128()); \
+ RGB2YUV_16(r_16, g_16, b_16, y1_16, u1_16, v1_16) \
+ r_16 = _mm_unpackhi_epi8(r1, _mm_setzero_si128()); \
+ g_16 = _mm_unpackhi_epi8(g1, _mm_setzero_si128()); \
+ b_16 = _mm_unpackhi_epi8(b1, _mm_setzero_si128()); \
+ RGB2YUV_16(r_16, g_16, b_16, y2_16, u2_16, v2_16) \
+ y = _mm_packus_epi16(y1_16, y2_16); \
+ u1 = _mm_packus_epi16(u1_16, u2_16); \
+ v1 = _mm_packus_epi16(v1_16, v2_16); \
+ /* save Y values */ \
+ SAVE_SI128((__m128i*)(y_ptr1+16), y); \
+ /* process pixels of second line */ \
+ r_16 = _mm_unpacklo_epi8(r2, _mm_setzero_si128()); \
+ g_16 = _mm_unpacklo_epi8(g2, _mm_setzero_si128()); \
+ b_16 = _mm_unpacklo_epi8(b2, _mm_setzero_si128()); \
+ RGB2YUV_16(r_16, g_16, b_16, y1_16, u1_16, v1_16) \
+ r_16 = _mm_unpackhi_epi8(r2, _mm_setzero_si128()); \
+ g_16 = _mm_unpackhi_epi8(g2, _mm_setzero_si128()); \
+ b_16 = _mm_unpackhi_epi8(b2, _mm_setzero_si128()); \
+ RGB2YUV_16(r_16, g_16, b_16, y2_16, u2_16, v2_16) \
+ y = _mm_packus_epi16(y1_16, y2_16); \
+ u2 = _mm_packus_epi16(u1_16, u2_16); \
+ v2 = _mm_packus_epi16(v1_16, v2_16); \
+ /* save Y values */ \
+ SAVE_SI128((__m128i*)(y_ptr2+16), y); \
+ /* vertical subsampling of u/v values */ \
+ u2_tmp = _mm_avg_epu8(u1, u2); \
+ v2_tmp = _mm_avg_epu8(v1, v2); \
+ /* horizontal subsampling of u/v values */ \
+ u1 = _mm_packus_epi16(_mm_srl_epi16(u1_tmp, _mm_cvtsi32_si128(8)), _mm_srl_epi16(u2_tmp, _mm_cvtsi32_si128(8))); \
+ v1 = _mm_packus_epi16(_mm_srl_epi16(v1_tmp, _mm_cvtsi32_si128(8)), _mm_srl_epi16(v2_tmp, _mm_cvtsi32_si128(8))); \
+ u2 = _mm_packus_epi16(_mm_and_si128(u1_tmp, _mm_set1_epi16(0xFF)), _mm_and_si128(u2_tmp, _mm_set1_epi16(0xFF))); \
+ v2 = _mm_packus_epi16(_mm_and_si128(v1_tmp, _mm_set1_epi16(0xFF)), _mm_and_si128(v2_tmp, _mm_set1_epi16(0xFF))); \
+ u1 = _mm_avg_epu8(u1, u2); \
+ v1 = _mm_avg_epu8(v1, v2); \
+ SAVE_SI128((__m128i*)(u_ptr), u1); \
+ SAVE_SI128((__m128i*)(v_ptr), v1);
+
+void rgb24_yuv420_sse(uint32_t width, uint32_t height,
+ const uint8_t *RGB, uint32_t RGB_stride,
+ uint8_t *Y, uint8_t *U, uint8_t *V, uint32_t Y_stride, uint32_t UV_stride,
+ YCbCrType yuv_type)
+{
+ #define LOAD_SI128 _mm_load_si128
+ #define SAVE_SI128 _mm_stream_si128
+ const RGB2YUVParam *const param = &(RGB2YUV[yuv_type]);
+
+ uint32_t xpos, ypos;
+ for(ypos=0; ypos<(height-1); ypos+=2)
+ {
+ const uint8_t *rgb_ptr1=RGB+ypos*RGB_stride,
+ *rgb_ptr2=RGB+(ypos+1)*RGB_stride;
+
+ uint8_t *y_ptr1=Y+ypos*Y_stride,
+ *y_ptr2=Y+(ypos+1)*Y_stride,
+ *u_ptr=U+(ypos/2)*UV_stride,
+ *v_ptr=V+(ypos/2)*UV_stride;
+
+ for(xpos=0; xpos<(width-31); xpos+=32)
+ {
+ RGB2YUV_32
+
+ rgb_ptr1+=96;
+ rgb_ptr2+=96;
+ y_ptr1+=32;
+ y_ptr2+=32;
+ u_ptr+=16;
+ v_ptr+=16;
+ }
+ }
+ #undef LOAD_SI128
+ #undef SAVE_SI128
+}
+
+void rgb24_yuv420_sseu(uint32_t width, uint32_t height,
+ const uint8_t *RGB, uint32_t RGB_stride,
+ uint8_t *Y, uint8_t *U, uint8_t *V, uint32_t Y_stride, uint32_t UV_stride,
+ YCbCrType yuv_type)
+{
+ #define LOAD_SI128 _mm_loadu_si128
+ #define SAVE_SI128 _mm_storeu_si128
+ const RGB2YUVParam *const param = &(RGB2YUV[yuv_type]);
+
+ uint32_t xpos, ypos;
+ for(ypos=0; ypos<(height-1); ypos+=2)
+ {
+ const uint8_t *rgb_ptr1=RGB+ypos*RGB_stride,
+ *rgb_ptr2=RGB+(ypos+1)*RGB_stride;
+
+ uint8_t *y_ptr1=Y+ypos*Y_stride,
+ *y_ptr2=Y+(ypos+1)*Y_stride,
+ *u_ptr=U+(ypos/2)*UV_stride,
+ *v_ptr=V+(ypos/2)*UV_stride;
+
+ for(xpos=0; xpos<(width-31); xpos+=32)
+ {
+ RGB2YUV_32
+
+ rgb_ptr1+=96;
+ rgb_ptr2+=96;
+ y_ptr1+=32;
+ y_ptr2+=32;
+ u_ptr+=16;
+ v_ptr+=16;
+ }
+ }
+ #undef LOAD_SI128
+ #undef SAVE_SI128
+}
+
+
+#endif //__SSE2__
+
diff --git a/src/3rdparty/SDL2/src/video/yuv2rgb/yuv_rgb.h b/src/3rdparty/SDL2/src/video/yuv2rgb/yuv_rgb.h
new file mode 100644
index 0000000..81d97eb
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/yuv2rgb/yuv_rgb.h
@@ -0,0 +1,381 @@
+// Copyright 2016 Adrien Descamps
+// Distributed under BSD 3-Clause License
+
+// Provide optimized functions to convert images from 8bits yuv420 to rgb24 format
+
+// There are a few slightly different variations of the YCbCr color space with different parameters that
+// change the conversion matrix.
+// The three most common YCbCr color space, defined by BT.601, BT.709 and JPEG standard are implemented here.
+// See the respective standards for details
+// The matrix values used are derived from http://www.equasys.de/colorconversion.html
+
+// YUV420 is stored as three separate channels, with U and V (Cb and Cr) subsampled by a 2 factor
+// For conversion from yuv to rgb, no interpolation is done, and the same UV value are used for 4 rgb pixels. This
+// is suboptimal for image quality, but by far the fastest method.
+
+// For all methods, width and height should be even, if not, the last row/column of the result image won't be affected.
+// For sse methods, if the width if not divisable by 32, the last (width%32) pixels of each line won't be affected.
+
+#include "SDL_stdinc.h"
+/*#include <stdint.h>*/
+
+typedef enum
+{
+ YCBCR_JPEG,
+ YCBCR_601,
+ YCBCR_709
+} YCbCrType;
+
+// yuv to rgb, standard c implementation
+void yuv420_rgb565_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv420_rgb24_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv420_rgba_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv420_bgra_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv420_argb_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv420_abgr_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv422_rgb565_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv422_rgb24_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv422_rgba_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv422_bgra_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv422_argb_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv422_abgr_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuvnv12_rgb565_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuvnv12_rgb24_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuvnv12_rgba_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuvnv12_bgra_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuvnv12_argb_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuvnv12_abgr_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+// yuv to rgb, sse implementation
+// pointers must be 16 byte aligned, and strides must be divisable by 16
+void yuv420_rgb565_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv420_rgb24_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv420_rgba_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv420_bgra_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv420_argb_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv420_abgr_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv422_rgb565_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv422_rgb24_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv422_rgba_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv422_bgra_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv422_argb_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv422_abgr_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuvnv12_rgb565_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuvnv12_rgb24_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuvnv12_rgba_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuvnv12_bgra_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuvnv12_argb_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuvnv12_abgr_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+// yuv to rgb, sse implementation
+// pointers do not need to be 16 byte aligned
+void yuv420_rgb565_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv420_rgb24_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv420_rgba_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv420_bgra_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv420_argb_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv420_abgr_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv422_rgb565_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv422_rgb24_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv422_rgba_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv422_bgra_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv422_argb_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuv422_abgr_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuvnv12_rgb565_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuvnv12_rgb24_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuvnv12_rgba_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuvnv12_bgra_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuvnv12_argb_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+void yuvnv12_abgr_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *y, const uint8_t *u, const uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ uint8_t *rgb, uint32_t rgb_stride,
+ YCbCrType yuv_type);
+
+
+// rgb to yuv, standard c implementation
+void rgb24_yuv420_std(
+ uint32_t width, uint32_t height,
+ const uint8_t *rgb, uint32_t rgb_stride,
+ uint8_t *y, uint8_t *u, uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ YCbCrType yuv_type);
+
+// rgb to yuv, sse implementation
+// pointers must be 16 byte aligned, and strides must be divisible by 16
+void rgb24_yuv420_sse(
+ uint32_t width, uint32_t height,
+ const uint8_t *rgb, uint32_t rgb_stride,
+ uint8_t *y, uint8_t *u, uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ YCbCrType yuv_type);
+
+// rgb to yuv, sse implementation
+// pointers do not need to be 16 byte aligned
+void rgb24_yuv420_sseu(
+ uint32_t width, uint32_t height,
+ const uint8_t *rgb, uint32_t rgb_stride,
+ uint8_t *y, uint8_t *u, uint8_t *v, uint32_t y_stride, uint32_t uv_stride,
+ YCbCrType yuv_type);
+
diff --git a/src/3rdparty/SDL2/src/video/yuv2rgb/yuv_rgb_sse_func.h b/src/3rdparty/SDL2/src/video/yuv2rgb/yuv_rgb_sse_func.h
new file mode 100644
index 0000000..f81140e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/yuv2rgb/yuv_rgb_sse_func.h
@@ -0,0 +1,498 @@
+// Copyright 2016 Adrien Descamps
+// Distributed under BSD 3-Clause License
+
+/* You need to define the following macros before including this file:
+ SSE_FUNCTION_NAME
+ STD_FUNCTION_NAME
+ YUV_FORMAT
+ RGB_FORMAT
+*/
+/* You may define the following macro, which affects generated code:
+ SSE_ALIGNED
+*/
+
+#ifdef SSE_ALIGNED
+/* Unaligned instructions seem faster, even on aligned data? */
+/*
+#define LOAD_SI128 _mm_load_si128
+#define SAVE_SI128 _mm_stream_si128
+*/
+#define LOAD_SI128 _mm_loadu_si128
+#define SAVE_SI128 _mm_storeu_si128
+#else
+#define LOAD_SI128 _mm_loadu_si128
+#define SAVE_SI128 _mm_storeu_si128
+#endif
+
+#define UV2RGB_16(U,V,R1,G1,B1,R2,G2,B2) \
+ r_tmp = _mm_mullo_epi16(V, _mm_set1_epi16(param->v_r_factor)); \
+ g_tmp = _mm_add_epi16( \
+ _mm_mullo_epi16(U, _mm_set1_epi16(param->u_g_factor)), \
+ _mm_mullo_epi16(V, _mm_set1_epi16(param->v_g_factor))); \
+ b_tmp = _mm_mullo_epi16(U, _mm_set1_epi16(param->u_b_factor)); \
+ R1 = _mm_unpacklo_epi16(r_tmp, r_tmp); \
+ G1 = _mm_unpacklo_epi16(g_tmp, g_tmp); \
+ B1 = _mm_unpacklo_epi16(b_tmp, b_tmp); \
+ R2 = _mm_unpackhi_epi16(r_tmp, r_tmp); \
+ G2 = _mm_unpackhi_epi16(g_tmp, g_tmp); \
+ B2 = _mm_unpackhi_epi16(b_tmp, b_tmp); \
+
+#define ADD_Y2RGB_16(Y1,Y2,R1,G1,B1,R2,G2,B2) \
+ Y1 = _mm_mullo_epi16(_mm_sub_epi16(Y1, _mm_set1_epi16(param->y_shift)), _mm_set1_epi16(param->y_factor)); \
+ Y2 = _mm_mullo_epi16(_mm_sub_epi16(Y2, _mm_set1_epi16(param->y_shift)), _mm_set1_epi16(param->y_factor)); \
+ \
+ R1 = _mm_srai_epi16(_mm_add_epi16(R1, Y1), PRECISION); \
+ G1 = _mm_srai_epi16(_mm_add_epi16(G1, Y1), PRECISION); \
+ B1 = _mm_srai_epi16(_mm_add_epi16(B1, Y1), PRECISION); \
+ R2 = _mm_srai_epi16(_mm_add_epi16(R2, Y2), PRECISION); \
+ G2 = _mm_srai_epi16(_mm_add_epi16(G2, Y2), PRECISION); \
+ B2 = _mm_srai_epi16(_mm_add_epi16(B2, Y2), PRECISION); \
+
+#define PACK_RGB565_32(R1, R2, G1, G2, B1, B2, RGB1, RGB2, RGB3, RGB4) \
+{ \
+ __m128i red_mask, tmp1, tmp2, tmp3, tmp4; \
+\
+ red_mask = _mm_set1_epi16((short)0xF800); \
+ RGB1 = _mm_and_si128(_mm_unpacklo_epi8(_mm_setzero_si128(), R1), red_mask); \
+ RGB2 = _mm_and_si128(_mm_unpackhi_epi8(_mm_setzero_si128(), R1), red_mask); \
+ RGB3 = _mm_and_si128(_mm_unpacklo_epi8(_mm_setzero_si128(), R2), red_mask); \
+ RGB4 = _mm_and_si128(_mm_unpackhi_epi8(_mm_setzero_si128(), R2), red_mask); \
+ tmp1 = _mm_slli_epi16(_mm_srli_epi16(_mm_unpacklo_epi8(G1, _mm_setzero_si128()), 2), 5); \
+ tmp2 = _mm_slli_epi16(_mm_srli_epi16(_mm_unpackhi_epi8(G1, _mm_setzero_si128()), 2), 5); \
+ tmp3 = _mm_slli_epi16(_mm_srli_epi16(_mm_unpacklo_epi8(G2, _mm_setzero_si128()), 2), 5); \
+ tmp4 = _mm_slli_epi16(_mm_srli_epi16(_mm_unpackhi_epi8(G2, _mm_setzero_si128()), 2), 5); \
+ RGB1 = _mm_or_si128(RGB1, tmp1); \
+ RGB2 = _mm_or_si128(RGB2, tmp2); \
+ RGB3 = _mm_or_si128(RGB3, tmp3); \
+ RGB4 = _mm_or_si128(RGB4, tmp4); \
+ tmp1 = _mm_srli_epi16(_mm_unpacklo_epi8(B1, _mm_setzero_si128()), 3); \
+ tmp2 = _mm_srli_epi16(_mm_unpackhi_epi8(B1, _mm_setzero_si128()), 3); \
+ tmp3 = _mm_srli_epi16(_mm_unpacklo_epi8(B2, _mm_setzero_si128()), 3); \
+ tmp4 = _mm_srli_epi16(_mm_unpackhi_epi8(B2, _mm_setzero_si128()), 3); \
+ RGB1 = _mm_or_si128(RGB1, tmp1); \
+ RGB2 = _mm_or_si128(RGB2, tmp2); \
+ RGB3 = _mm_or_si128(RGB3, tmp3); \
+ RGB4 = _mm_or_si128(RGB4, tmp4); \
+}
+
+#define PACK_RGB24_32_STEP1(R1, R2, G1, G2, B1, B2, RGB1, RGB2, RGB3, RGB4, RGB5, RGB6) \
+RGB1 = _mm_packus_epi16(_mm_and_si128(R1,_mm_set1_epi16(0xFF)), _mm_and_si128(R2,_mm_set1_epi16(0xFF))); \
+RGB2 = _mm_packus_epi16(_mm_and_si128(G1,_mm_set1_epi16(0xFF)), _mm_and_si128(G2,_mm_set1_epi16(0xFF))); \
+RGB3 = _mm_packus_epi16(_mm_and_si128(B1,_mm_set1_epi16(0xFF)), _mm_and_si128(B2,_mm_set1_epi16(0xFF))); \
+RGB4 = _mm_packus_epi16(_mm_srli_epi16(R1,8), _mm_srli_epi16(R2,8)); \
+RGB5 = _mm_packus_epi16(_mm_srli_epi16(G1,8), _mm_srli_epi16(G2,8)); \
+RGB6 = _mm_packus_epi16(_mm_srli_epi16(B1,8), _mm_srli_epi16(B2,8)); \
+
+#define PACK_RGB24_32_STEP2(R1, R2, G1, G2, B1, B2, RGB1, RGB2, RGB3, RGB4, RGB5, RGB6) \
+R1 = _mm_packus_epi16(_mm_and_si128(RGB1,_mm_set1_epi16(0xFF)), _mm_and_si128(RGB2,_mm_set1_epi16(0xFF))); \
+R2 = _mm_packus_epi16(_mm_and_si128(RGB3,_mm_set1_epi16(0xFF)), _mm_and_si128(RGB4,_mm_set1_epi16(0xFF))); \
+G1 = _mm_packus_epi16(_mm_and_si128(RGB5,_mm_set1_epi16(0xFF)), _mm_and_si128(RGB6,_mm_set1_epi16(0xFF))); \
+G2 = _mm_packus_epi16(_mm_srli_epi16(RGB1,8), _mm_srli_epi16(RGB2,8)); \
+B1 = _mm_packus_epi16(_mm_srli_epi16(RGB3,8), _mm_srli_epi16(RGB4,8)); \
+B2 = _mm_packus_epi16(_mm_srli_epi16(RGB5,8), _mm_srli_epi16(RGB6,8)); \
+
+#define PACK_RGB24_32(R1, R2, G1, G2, B1, B2, RGB1, RGB2, RGB3, RGB4, RGB5, RGB6) \
+PACK_RGB24_32_STEP1(R1, R2, G1, G2, B1, B2, RGB1, RGB2, RGB3, RGB4, RGB5, RGB6) \
+PACK_RGB24_32_STEP2(R1, R2, G1, G2, B1, B2, RGB1, RGB2, RGB3, RGB4, RGB5, RGB6) \
+PACK_RGB24_32_STEP1(R1, R2, G1, G2, B1, B2, RGB1, RGB2, RGB3, RGB4, RGB5, RGB6) \
+PACK_RGB24_32_STEP2(R1, R2, G1, G2, B1, B2, RGB1, RGB2, RGB3, RGB4, RGB5, RGB6) \
+PACK_RGB24_32_STEP1(R1, R2, G1, G2, B1, B2, RGB1, RGB2, RGB3, RGB4, RGB5, RGB6) \
+
+#define PACK_RGBA_32(R1, R2, G1, G2, B1, B2, A1, A2, RGB1, RGB2, RGB3, RGB4, RGB5, RGB6, RGB7, RGB8) \
+{ \
+ __m128i lo_ab, hi_ab, lo_gr, hi_gr; \
+\
+ lo_ab = _mm_unpacklo_epi8( A1, B1 ); \
+ hi_ab = _mm_unpackhi_epi8( A1, B1 ); \
+ lo_gr = _mm_unpacklo_epi8( G1, R1 ); \
+ hi_gr = _mm_unpackhi_epi8( G1, R1 ); \
+ RGB1 = _mm_unpacklo_epi16( lo_ab, lo_gr ); \
+ RGB2 = _mm_unpackhi_epi16( lo_ab, lo_gr ); \
+ RGB3 = _mm_unpacklo_epi16( hi_ab, hi_gr ); \
+ RGB4 = _mm_unpackhi_epi16( hi_ab, hi_gr ); \
+\
+ lo_ab = _mm_unpacklo_epi8( A2, B2 ); \
+ hi_ab = _mm_unpackhi_epi8( A2, B2 ); \
+ lo_gr = _mm_unpacklo_epi8( G2, R2 ); \
+ hi_gr = _mm_unpackhi_epi8( G2, R2 ); \
+ RGB5 = _mm_unpacklo_epi16( lo_ab, lo_gr ); \
+ RGB6 = _mm_unpackhi_epi16( lo_ab, lo_gr ); \
+ RGB7 = _mm_unpacklo_epi16( hi_ab, hi_gr ); \
+ RGB8 = _mm_unpackhi_epi16( hi_ab, hi_gr ); \
+}
+
+#if RGB_FORMAT == RGB_FORMAT_RGB565
+
+#define PACK_PIXEL \
+ __m128i rgb_1, rgb_2, rgb_3, rgb_4, rgb_5, rgb_6, rgb_7, rgb_8; \
+ \
+ PACK_RGB565_32(r_8_11, r_8_12, g_8_11, g_8_12, b_8_11, b_8_12, rgb_1, rgb_2, rgb_3, rgb_4) \
+ \
+ PACK_RGB565_32(r_8_21, r_8_22, g_8_21, g_8_22, b_8_21, b_8_22, rgb_5, rgb_6, rgb_7, rgb_8) \
+
+#elif RGB_FORMAT == RGB_FORMAT_RGB24
+
+#define PACK_PIXEL \
+ __m128i rgb_1, rgb_2, rgb_3, rgb_4, rgb_5, rgb_6; \
+ __m128i rgb_7, rgb_8, rgb_9, rgb_10, rgb_11, rgb_12; \
+ \
+ PACK_RGB24_32(r_8_11, r_8_12, g_8_11, g_8_12, b_8_11, b_8_12, rgb_1, rgb_2, rgb_3, rgb_4, rgb_5, rgb_6) \
+ \
+ PACK_RGB24_32(r_8_21, r_8_22, g_8_21, g_8_22, b_8_21, b_8_22, rgb_7, rgb_8, rgb_9, rgb_10, rgb_11, rgb_12) \
+
+#elif RGB_FORMAT == RGB_FORMAT_RGBA
+
+#define PACK_PIXEL \
+ __m128i rgb_1, rgb_2, rgb_3, rgb_4, rgb_5, rgb_6, rgb_7, rgb_8; \
+ __m128i rgb_9, rgb_10, rgb_11, rgb_12, rgb_13, rgb_14, rgb_15, rgb_16; \
+ __m128i a = _mm_set1_epi8((char)0xFF); \
+ \
+ PACK_RGBA_32(r_8_11, r_8_12, g_8_11, g_8_12, b_8_11, b_8_12, a, a, rgb_1, rgb_2, rgb_3, rgb_4, rgb_5, rgb_6, rgb_7, rgb_8) \
+ \
+ PACK_RGBA_32(r_8_21, r_8_22, g_8_21, g_8_22, b_8_21, b_8_22, a, a, rgb_9, rgb_10, rgb_11, rgb_12, rgb_13, rgb_14, rgb_15, rgb_16) \
+
+#elif RGB_FORMAT == RGB_FORMAT_BGRA
+
+#define PACK_PIXEL \
+ __m128i rgb_1, rgb_2, rgb_3, rgb_4, rgb_5, rgb_6, rgb_7, rgb_8; \
+ __m128i rgb_9, rgb_10, rgb_11, rgb_12, rgb_13, rgb_14, rgb_15, rgb_16; \
+ __m128i a = _mm_set1_epi8((char)0xFF); \
+ \
+ PACK_RGBA_32(b_8_11, b_8_12, g_8_11, g_8_12, r_8_11, r_8_12, a, a, rgb_1, rgb_2, rgb_3, rgb_4, rgb_5, rgb_6, rgb_7, rgb_8) \
+ \
+ PACK_RGBA_32(b_8_21, b_8_22, g_8_21, g_8_22, r_8_21, r_8_22, a, a, rgb_9, rgb_10, rgb_11, rgb_12, rgb_13, rgb_14, rgb_15, rgb_16) \
+
+#elif RGB_FORMAT == RGB_FORMAT_ARGB
+
+#define PACK_PIXEL \
+ __m128i rgb_1, rgb_2, rgb_3, rgb_4, rgb_5, rgb_6, rgb_7, rgb_8; \
+ __m128i rgb_9, rgb_10, rgb_11, rgb_12, rgb_13, rgb_14, rgb_15, rgb_16; \
+ __m128i a = _mm_set1_epi8((char)0xFF); \
+ \
+ PACK_RGBA_32(a, a, r_8_11, r_8_12, g_8_11, g_8_12, b_8_11, b_8_12, rgb_1, rgb_2, rgb_3, rgb_4, rgb_5, rgb_6, rgb_7, rgb_8) \
+ \
+ PACK_RGBA_32(a, a, r_8_21, r_8_22, g_8_21, g_8_22, b_8_21, b_8_22, rgb_9, rgb_10, rgb_11, rgb_12, rgb_13, rgb_14, rgb_15, rgb_16) \
+
+#elif RGB_FORMAT == RGB_FORMAT_ABGR
+
+#define PACK_PIXEL \
+ __m128i rgb_1, rgb_2, rgb_3, rgb_4, rgb_5, rgb_6, rgb_7, rgb_8; \
+ __m128i rgb_9, rgb_10, rgb_11, rgb_12, rgb_13, rgb_14, rgb_15, rgb_16; \
+ __m128i a = _mm_set1_epi8((char)0xFF); \
+ \
+ PACK_RGBA_32(a, a, b_8_11, b_8_12, g_8_11, g_8_12, r_8_11, r_8_12, rgb_1, rgb_2, rgb_3, rgb_4, rgb_5, rgb_6, rgb_7, rgb_8) \
+ \
+ PACK_RGBA_32(a, a, b_8_21, b_8_22, g_8_21, g_8_22, r_8_21, r_8_22, rgb_9, rgb_10, rgb_11, rgb_12, rgb_13, rgb_14, rgb_15, rgb_16) \
+
+#else
+#error PACK_PIXEL unimplemented
+#endif
+
+#if RGB_FORMAT == RGB_FORMAT_RGB565
+
+#define SAVE_LINE1 \
+ SAVE_SI128((__m128i*)(rgb_ptr1), rgb_1); \
+ SAVE_SI128((__m128i*)(rgb_ptr1+16), rgb_2); \
+ SAVE_SI128((__m128i*)(rgb_ptr1+32), rgb_3); \
+ SAVE_SI128((__m128i*)(rgb_ptr1+48), rgb_4); \
+
+#define SAVE_LINE2 \
+ SAVE_SI128((__m128i*)(rgb_ptr2), rgb_5); \
+ SAVE_SI128((__m128i*)(rgb_ptr2+16), rgb_6); \
+ SAVE_SI128((__m128i*)(rgb_ptr2+32), rgb_7); \
+ SAVE_SI128((__m128i*)(rgb_ptr2+48), rgb_8); \
+
+#elif RGB_FORMAT == RGB_FORMAT_RGB24
+
+#define SAVE_LINE1 \
+ SAVE_SI128((__m128i*)(rgb_ptr1), rgb_1); \
+ SAVE_SI128((__m128i*)(rgb_ptr1+16), rgb_2); \
+ SAVE_SI128((__m128i*)(rgb_ptr1+32), rgb_3); \
+ SAVE_SI128((__m128i*)(rgb_ptr1+48), rgb_4); \
+ SAVE_SI128((__m128i*)(rgb_ptr1+64), rgb_5); \
+ SAVE_SI128((__m128i*)(rgb_ptr1+80), rgb_6); \
+
+#define SAVE_LINE2 \
+ SAVE_SI128((__m128i*)(rgb_ptr2), rgb_7); \
+ SAVE_SI128((__m128i*)(rgb_ptr2+16), rgb_8); \
+ SAVE_SI128((__m128i*)(rgb_ptr2+32), rgb_9); \
+ SAVE_SI128((__m128i*)(rgb_ptr2+48), rgb_10); \
+ SAVE_SI128((__m128i*)(rgb_ptr2+64), rgb_11); \
+ SAVE_SI128((__m128i*)(rgb_ptr2+80), rgb_12); \
+
+#elif RGB_FORMAT == RGB_FORMAT_RGBA || RGB_FORMAT == RGB_FORMAT_BGRA || \
+ RGB_FORMAT == RGB_FORMAT_ARGB || RGB_FORMAT == RGB_FORMAT_ABGR
+
+#define SAVE_LINE1 \
+ SAVE_SI128((__m128i*)(rgb_ptr1), rgb_1); \
+ SAVE_SI128((__m128i*)(rgb_ptr1+16), rgb_2); \
+ SAVE_SI128((__m128i*)(rgb_ptr1+32), rgb_3); \
+ SAVE_SI128((__m128i*)(rgb_ptr1+48), rgb_4); \
+ SAVE_SI128((__m128i*)(rgb_ptr1+64), rgb_5); \
+ SAVE_SI128((__m128i*)(rgb_ptr1+80), rgb_6); \
+ SAVE_SI128((__m128i*)(rgb_ptr1+96), rgb_7); \
+ SAVE_SI128((__m128i*)(rgb_ptr1+112), rgb_8); \
+
+#define SAVE_LINE2 \
+ SAVE_SI128((__m128i*)(rgb_ptr2), rgb_9); \
+ SAVE_SI128((__m128i*)(rgb_ptr2+16), rgb_10); \
+ SAVE_SI128((__m128i*)(rgb_ptr2+32), rgb_11); \
+ SAVE_SI128((__m128i*)(rgb_ptr2+48), rgb_12); \
+ SAVE_SI128((__m128i*)(rgb_ptr2+64), rgb_13); \
+ SAVE_SI128((__m128i*)(rgb_ptr2+80), rgb_14); \
+ SAVE_SI128((__m128i*)(rgb_ptr2+96), rgb_15); \
+ SAVE_SI128((__m128i*)(rgb_ptr2+112), rgb_16); \
+
+#else
+#error SAVE_LINE unimplemented
+#endif
+
+#if YUV_FORMAT == YUV_FORMAT_420
+
+#define READ_Y(y_ptr) \
+ y = LOAD_SI128((const __m128i*)(y_ptr)); \
+
+#define READ_UV \
+ u = LOAD_SI128((const __m128i*)(u_ptr)); \
+ v = LOAD_SI128((const __m128i*)(v_ptr)); \
+
+#elif YUV_FORMAT == YUV_FORMAT_422
+
+#define READ_Y(y_ptr) \
+{ \
+ __m128i y1, y2; \
+ y1 = _mm_srli_epi16(_mm_slli_epi16(LOAD_SI128((const __m128i*)(y_ptr)), 8), 8); \
+ y2 = _mm_srli_epi16(_mm_slli_epi16(LOAD_SI128((const __m128i*)(y_ptr+16)), 8), 8); \
+ y = _mm_packus_epi16(y1, y2); \
+}
+
+#define READ_UV \
+{ \
+ __m128i u1, u2, u3, u4, v1, v2, v3, v4; \
+ u1 = _mm_srli_epi32(_mm_slli_epi32(LOAD_SI128((const __m128i*)(u_ptr)), 24), 24); \
+ u2 = _mm_srli_epi32(_mm_slli_epi32(LOAD_SI128((const __m128i*)(u_ptr+16)), 24), 24); \
+ u3 = _mm_srli_epi32(_mm_slli_epi32(LOAD_SI128((const __m128i*)(u_ptr+32)), 24), 24); \
+ u4 = _mm_srli_epi32(_mm_slli_epi32(LOAD_SI128((const __m128i*)(u_ptr+48)), 24), 24); \
+ u = _mm_packus_epi16(_mm_packs_epi32(u1, u2), _mm_packs_epi32(u3, u4)); \
+ v1 = _mm_srli_epi32(_mm_slli_epi32(LOAD_SI128((const __m128i*)(v_ptr)), 24), 24); \
+ v2 = _mm_srli_epi32(_mm_slli_epi32(LOAD_SI128((const __m128i*)(v_ptr+16)), 24), 24); \
+ v3 = _mm_srli_epi32(_mm_slli_epi32(LOAD_SI128((const __m128i*)(v_ptr+32)), 24), 24); \
+ v4 = _mm_srli_epi32(_mm_slli_epi32(LOAD_SI128((const __m128i*)(v_ptr+48)), 24), 24); \
+ v = _mm_packus_epi16(_mm_packs_epi32(v1, v2), _mm_packs_epi32(v3, v4)); \
+}
+
+#elif YUV_FORMAT == YUV_FORMAT_NV12
+
+#define READ_Y(y_ptr) \
+ y = LOAD_SI128((const __m128i*)(y_ptr)); \
+
+#define READ_UV \
+{ \
+ __m128i u1, u2, v1, v2; \
+ u1 = _mm_srli_epi16(_mm_slli_epi16(LOAD_SI128((const __m128i*)(u_ptr)), 8), 8); \
+ u2 = _mm_srli_epi16(_mm_slli_epi16(LOAD_SI128((const __m128i*)(u_ptr+16)), 8), 8); \
+ u = _mm_packus_epi16(u1, u2); \
+ v1 = _mm_srli_epi16(_mm_slli_epi16(LOAD_SI128((const __m128i*)(v_ptr)), 8), 8); \
+ v2 = _mm_srli_epi16(_mm_slli_epi16(LOAD_SI128((const __m128i*)(v_ptr+16)), 8), 8); \
+ v = _mm_packus_epi16(v1, v2); \
+}
+
+#else
+#error READ_UV unimplemented
+#endif
+
+#define YUV2RGB_32 \
+ __m128i r_tmp, g_tmp, b_tmp; \
+ __m128i r_16_1, g_16_1, b_16_1, r_16_2, g_16_2, b_16_2; \
+ __m128i r_uv_16_1, g_uv_16_1, b_uv_16_1, r_uv_16_2, g_uv_16_2, b_uv_16_2; \
+ __m128i y_16_1, y_16_2; \
+ __m128i y, u, v, u_16, v_16; \
+ __m128i r_8_11, g_8_11, b_8_11, r_8_21, g_8_21, b_8_21; \
+ __m128i r_8_12, g_8_12, b_8_12, r_8_22, g_8_22, b_8_22; \
+ \
+ READ_UV \
+ \
+ /* process first 16 pixels of first line */\
+ u_16 = _mm_unpacklo_epi8(u, _mm_setzero_si128()); \
+ v_16 = _mm_unpacklo_epi8(v, _mm_setzero_si128()); \
+ u_16 = _mm_add_epi16(u_16, _mm_set1_epi16(-128)); \
+ v_16 = _mm_add_epi16(v_16, _mm_set1_epi16(-128)); \
+ \
+ UV2RGB_16(u_16, v_16, r_16_1, g_16_1, b_16_1, r_16_2, g_16_2, b_16_2) \
+ r_uv_16_1=r_16_1; g_uv_16_1=g_16_1; b_uv_16_1=b_16_1; \
+ r_uv_16_2=r_16_2; g_uv_16_2=g_16_2; b_uv_16_2=b_16_2; \
+ \
+ READ_Y(y_ptr1) \
+ y_16_1 = _mm_unpacklo_epi8(y, _mm_setzero_si128()); \
+ y_16_2 = _mm_unpackhi_epi8(y, _mm_setzero_si128()); \
+ \
+ ADD_Y2RGB_16(y_16_1, y_16_2, r_16_1, g_16_1, b_16_1, r_16_2, g_16_2, b_16_2) \
+ \
+ r_8_11 = _mm_packus_epi16(r_16_1, r_16_2); \
+ g_8_11 = _mm_packus_epi16(g_16_1, g_16_2); \
+ b_8_11 = _mm_packus_epi16(b_16_1, b_16_2); \
+ \
+ /* process first 16 pixels of second line */\
+ r_16_1=r_uv_16_1; g_16_1=g_uv_16_1; b_16_1=b_uv_16_1; \
+ r_16_2=r_uv_16_2; g_16_2=g_uv_16_2; b_16_2=b_uv_16_2; \
+ \
+ READ_Y(y_ptr2) \
+ y_16_1 = _mm_unpacklo_epi8(y, _mm_setzero_si128()); \
+ y_16_2 = _mm_unpackhi_epi8(y, _mm_setzero_si128()); \
+ \
+ ADD_Y2RGB_16(y_16_1, y_16_2, r_16_1, g_16_1, b_16_1, r_16_2, g_16_2, b_16_2) \
+ \
+ r_8_21 = _mm_packus_epi16(r_16_1, r_16_2); \
+ g_8_21 = _mm_packus_epi16(g_16_1, g_16_2); \
+ b_8_21 = _mm_packus_epi16(b_16_1, b_16_2); \
+ \
+ /* process last 16 pixels of first line */\
+ u_16 = _mm_unpackhi_epi8(u, _mm_setzero_si128()); \
+ v_16 = _mm_unpackhi_epi8(v, _mm_setzero_si128()); \
+ u_16 = _mm_add_epi16(u_16, _mm_set1_epi16(-128)); \
+ v_16 = _mm_add_epi16(v_16, _mm_set1_epi16(-128)); \
+ \
+ UV2RGB_16(u_16, v_16, r_16_1, g_16_1, b_16_1, r_16_2, g_16_2, b_16_2) \
+ r_uv_16_1=r_16_1; g_uv_16_1=g_16_1; b_uv_16_1=b_16_1; \
+ r_uv_16_2=r_16_2; g_uv_16_2=g_16_2; b_uv_16_2=b_16_2; \
+ \
+ READ_Y(y_ptr1+16*y_pixel_stride) \
+ y_16_1 = _mm_unpacklo_epi8(y, _mm_setzero_si128()); \
+ y_16_2 = _mm_unpackhi_epi8(y, _mm_setzero_si128()); \
+ \
+ ADD_Y2RGB_16(y_16_1, y_16_2, r_16_1, g_16_1, b_16_1, r_16_2, g_16_2, b_16_2) \
+ \
+ r_8_12 = _mm_packus_epi16(r_16_1, r_16_2); \
+ g_8_12 = _mm_packus_epi16(g_16_1, g_16_2); \
+ b_8_12 = _mm_packus_epi16(b_16_1, b_16_2); \
+ \
+ /* process last 16 pixels of second line */\
+ r_16_1=r_uv_16_1; g_16_1=g_uv_16_1; b_16_1=b_uv_16_1; \
+ r_16_2=r_uv_16_2; g_16_2=g_uv_16_2; b_16_2=b_uv_16_2; \
+ \
+ READ_Y(y_ptr2+16*y_pixel_stride) \
+ y_16_1 = _mm_unpacklo_epi8(y, _mm_setzero_si128()); \
+ y_16_2 = _mm_unpackhi_epi8(y, _mm_setzero_si128()); \
+ \
+ ADD_Y2RGB_16(y_16_1, y_16_2, r_16_1, g_16_1, b_16_1, r_16_2, g_16_2, b_16_2) \
+ \
+ r_8_22 = _mm_packus_epi16(r_16_1, r_16_2); \
+ g_8_22 = _mm_packus_epi16(g_16_1, g_16_2); \
+ b_8_22 = _mm_packus_epi16(b_16_1, b_16_2); \
+ \
+
+
+void SSE_FUNCTION_NAME(uint32_t width, uint32_t height,
+ const uint8_t *Y, const uint8_t *U, const uint8_t *V, uint32_t Y_stride, uint32_t UV_stride,
+ uint8_t *RGB, uint32_t RGB_stride,
+ YCbCrType yuv_type)
+{
+ const YUV2RGBParam *const param = &(YUV2RGB[yuv_type]);
+#if YUV_FORMAT == YUV_FORMAT_420
+ const int y_pixel_stride = 1;
+ const int uv_pixel_stride = 1;
+ const int uv_x_sample_interval = 2;
+ const int uv_y_sample_interval = 2;
+#elif YUV_FORMAT == YUV_FORMAT_422
+ const int y_pixel_stride = 2;
+ const int uv_pixel_stride = 4;
+ const int uv_x_sample_interval = 2;
+ const int uv_y_sample_interval = 1;
+#elif YUV_FORMAT == YUV_FORMAT_NV12
+ const int y_pixel_stride = 1;
+ const int uv_pixel_stride = 2;
+ const int uv_x_sample_interval = 2;
+ const int uv_y_sample_interval = 2;
+#endif
+#if RGB_FORMAT == RGB_FORMAT_RGB565
+ const int rgb_pixel_stride = 2;
+#elif RGB_FORMAT == RGB_FORMAT_RGB24
+ const int rgb_pixel_stride = 3;
+#elif RGB_FORMAT == RGB_FORMAT_RGBA || RGB_FORMAT == RGB_FORMAT_BGRA || \
+ RGB_FORMAT == RGB_FORMAT_ARGB || RGB_FORMAT == RGB_FORMAT_ABGR
+ const int rgb_pixel_stride = 4;
+#else
+#error Unknown RGB pixel size
+#endif
+
+ if (width >= 32) {
+ uint32_t xpos, ypos;
+ for(ypos=0; ypos<(height-(uv_y_sample_interval-1)); ypos+=uv_y_sample_interval)
+ {
+ const uint8_t *y_ptr1=Y+ypos*Y_stride,
+ *y_ptr2=Y+(ypos+1)*Y_stride,
+ *u_ptr=U+(ypos/uv_y_sample_interval)*UV_stride,
+ *v_ptr=V+(ypos/uv_y_sample_interval)*UV_stride;
+
+ uint8_t *rgb_ptr1=RGB+ypos*RGB_stride,
+ *rgb_ptr2=RGB+(ypos+1)*RGB_stride;
+
+ for(xpos=0; xpos<(width-31); xpos+=32)
+ {
+ YUV2RGB_32
+ {
+ PACK_PIXEL
+ SAVE_LINE1
+ if (uv_y_sample_interval > 1)
+ {
+ SAVE_LINE2
+ }
+ }
+
+ y_ptr1+=32*y_pixel_stride;
+ y_ptr2+=32*y_pixel_stride;
+ u_ptr+=32*uv_pixel_stride/uv_x_sample_interval;
+ v_ptr+=32*uv_pixel_stride/uv_x_sample_interval;
+ rgb_ptr1+=32*rgb_pixel_stride;
+ rgb_ptr2+=32*rgb_pixel_stride;
+ }
+ }
+
+ /* Catch the last line, if needed */
+ if (uv_y_sample_interval == 2 && ypos == (height-1))
+ {
+ const uint8_t *y_ptr=Y+ypos*Y_stride,
+ *u_ptr=U+(ypos/uv_y_sample_interval)*UV_stride,
+ *v_ptr=V+(ypos/uv_y_sample_interval)*UV_stride;
+
+ uint8_t *rgb_ptr=RGB+ypos*RGB_stride;
+
+ STD_FUNCTION_NAME(width, 1, y_ptr, u_ptr, v_ptr, Y_stride, UV_stride, rgb_ptr, RGB_stride, yuv_type);
+ }
+ }
+
+ /* Catch the right column, if needed */
+ {
+ int converted = (width & ~31);
+ if (converted != width)
+ {
+ const uint8_t *y_ptr=Y+converted*y_pixel_stride,
+ *u_ptr=U+converted*uv_pixel_stride/uv_x_sample_interval,
+ *v_ptr=V+converted*uv_pixel_stride/uv_x_sample_interval;
+
+ uint8_t *rgb_ptr=RGB+converted*rgb_pixel_stride;
+
+ STD_FUNCTION_NAME(width-converted, height, y_ptr, u_ptr, v_ptr, Y_stride, UV_stride, rgb_ptr, RGB_stride, yuv_type);
+ }
+ }
+}
+
+#undef SSE_FUNCTION_NAME
+#undef STD_FUNCTION_NAME
+#undef YUV_FORMAT
+#undef RGB_FORMAT
+#undef SSE_ALIGNED
+#undef LOAD_SI128
+#undef SAVE_SI128
+#undef UV2RGB_16
+#undef ADD_Y2RGB_16
+#undef PACK_RGB24_32_STEP1
+#undef PACK_RGB24_32_STEP2
+#undef PACK_RGB24_32
+#undef PACK_RGBA_32
+#undef PACK_PIXEL
+#undef SAVE_LINE1
+#undef SAVE_LINE2
+#undef READ_Y
+#undef READ_UV
+#undef YUV2RGB_32
diff --git a/src/3rdparty/SDL2/src/video/yuv2rgb/yuv_rgb_std_func.h b/src/3rdparty/SDL2/src/video/yuv2rgb/yuv_rgb_std_func.h
new file mode 100644
index 0000000..bf4f48e
--- /dev/null
+++ b/src/3rdparty/SDL2/src/video/yuv2rgb/yuv_rgb_std_func.h
@@ -0,0 +1,220 @@
+// Copyright 2016 Adrien Descamps
+// Distributed under BSD 3-Clause License
+
+/* You need to define the following macros before including this file:
+ STD_FUNCTION_NAME
+ YUV_FORMAT
+ RGB_FORMAT
+*/
+
+#if RGB_FORMAT == RGB_FORMAT_RGB565
+
+#define PACK_PIXEL(rgb_ptr) \
+ *(Uint16 *)rgb_ptr = \
+ ((((Uint16)clampU8(y_tmp+r_tmp)) << 8 ) & 0xF800) | \
+ ((((Uint16)clampU8(y_tmp+g_tmp)) << 3) & 0x07E0) | \
+ (((Uint16)clampU8(y_tmp+b_tmp)) >> 3); \
+ rgb_ptr += 2; \
+
+#elif RGB_FORMAT == RGB_FORMAT_RGB24
+
+#define PACK_PIXEL(rgb_ptr) \
+ rgb_ptr[0] = clampU8(y_tmp+r_tmp); \
+ rgb_ptr[1] = clampU8(y_tmp+g_tmp); \
+ rgb_ptr[2] = clampU8(y_tmp+b_tmp); \
+ rgb_ptr += 3; \
+
+#elif RGB_FORMAT == RGB_FORMAT_RGBA
+
+#define PACK_PIXEL(rgb_ptr) \
+ *(Uint32 *)rgb_ptr = \
+ (((Uint32)clampU8(y_tmp+r_tmp)) << 24) | \
+ (((Uint32)clampU8(y_tmp+g_tmp)) << 16) | \
+ (((Uint32)clampU8(y_tmp+b_tmp)) << 8) | \
+ 0x000000FF; \
+ rgb_ptr += 4; \
+
+#elif RGB_FORMAT == RGB_FORMAT_BGRA
+
+#define PACK_PIXEL(rgb_ptr) \
+ *(Uint32 *)rgb_ptr = \
+ (((Uint32)clampU8(y_tmp+b_tmp)) << 24) | \
+ (((Uint32)clampU8(y_tmp+g_tmp)) << 16) | \
+ (((Uint32)clampU8(y_tmp+r_tmp)) << 8) | \
+ 0x000000FF; \
+ rgb_ptr += 4; \
+
+#elif RGB_FORMAT == RGB_FORMAT_ARGB
+
+#define PACK_PIXEL(rgb_ptr) \
+ *(Uint32 *)rgb_ptr = \
+ 0xFF000000 | \
+ (((Uint32)clampU8(y_tmp+r_tmp)) << 16) | \
+ (((Uint32)clampU8(y_tmp+g_tmp)) << 8) | \
+ (((Uint32)clampU8(y_tmp+b_tmp)) << 0); \
+ rgb_ptr += 4; \
+
+#elif RGB_FORMAT == RGB_FORMAT_ABGR
+
+#define PACK_PIXEL(rgb_ptr) \
+ *(Uint32 *)rgb_ptr = \
+ 0xFF000000 | \
+ (((Uint32)clampU8(y_tmp+b_tmp)) << 16) | \
+ (((Uint32)clampU8(y_tmp+g_tmp)) << 8) | \
+ (((Uint32)clampU8(y_tmp+r_tmp)) << 0); \
+ rgb_ptr += 4; \
+
+#else
+#error PACK_PIXEL unimplemented
+#endif
+
+
+void STD_FUNCTION_NAME(
+ uint32_t width, uint32_t height,
+ const uint8_t *Y, const uint8_t *U, const uint8_t *V, uint32_t Y_stride, uint32_t UV_stride,
+ uint8_t *RGB, uint32_t RGB_stride,
+ YCbCrType yuv_type)
+{
+ const YUV2RGBParam *const param = &(YUV2RGB[yuv_type]);
+#if YUV_FORMAT == YUV_FORMAT_420
+ const int y_pixel_stride = 1;
+ const int uv_pixel_stride = 1;
+ const int uv_x_sample_interval = 2;
+ const int uv_y_sample_interval = 2;
+#elif YUV_FORMAT == YUV_FORMAT_422
+ const int y_pixel_stride = 2;
+ const int uv_pixel_stride = 4;
+ const int uv_x_sample_interval = 2;
+ const int uv_y_sample_interval = 1;
+#elif YUV_FORMAT == YUV_FORMAT_NV12
+ const int y_pixel_stride = 1;
+ const int uv_pixel_stride = 2;
+ const int uv_x_sample_interval = 2;
+ const int uv_y_sample_interval = 2;
+#endif
+
+ uint32_t x, y;
+ for(y=0; y<(height-(uv_y_sample_interval-1)); y+=uv_y_sample_interval)
+ {
+ const uint8_t *y_ptr1=Y+y*Y_stride,
+ *y_ptr2=Y+(y+1)*Y_stride,
+ *u_ptr=U+(y/uv_y_sample_interval)*UV_stride,
+ *v_ptr=V+(y/uv_y_sample_interval)*UV_stride;
+
+ uint8_t *rgb_ptr1=RGB+y*RGB_stride,
+ *rgb_ptr2=RGB+(y+1)*RGB_stride;
+
+ for(x=0; x<(width-(uv_x_sample_interval-1)); x+=uv_x_sample_interval)
+ {
+ // Compute U and V contributions, common to the four pixels
+
+ int32_t u_tmp = ((*u_ptr)-128);
+ int32_t v_tmp = ((*v_ptr)-128);
+
+ int32_t r_tmp = (v_tmp*param->v_r_factor);
+ int32_t g_tmp = (u_tmp*param->u_g_factor + v_tmp*param->v_g_factor);
+ int32_t b_tmp = (u_tmp*param->u_b_factor);
+
+ // Compute the Y contribution for each pixel
+
+ int32_t y_tmp = ((y_ptr1[0]-param->y_shift)*param->y_factor);
+ PACK_PIXEL(rgb_ptr1);
+
+ y_tmp = ((y_ptr1[y_pixel_stride]-param->y_shift)*param->y_factor);
+ PACK_PIXEL(rgb_ptr1);
+
+ if (uv_y_sample_interval > 1) {
+ y_tmp = ((y_ptr2[0]-param->y_shift)*param->y_factor);
+ PACK_PIXEL(rgb_ptr2);
+
+ y_tmp = ((y_ptr2[y_pixel_stride]-param->y_shift)*param->y_factor);
+ PACK_PIXEL(rgb_ptr2);
+ }
+
+ y_ptr1+=2*y_pixel_stride;
+ y_ptr2+=2*y_pixel_stride;
+ u_ptr+=2*uv_pixel_stride/uv_x_sample_interval;
+ v_ptr+=2*uv_pixel_stride/uv_x_sample_interval;
+ }
+
+ /* Catch the last pixel, if needed */
+ if (uv_x_sample_interval == 2 && x == (width-1))
+ {
+ // Compute U and V contributions, common to the four pixels
+
+ int32_t u_tmp = ((*u_ptr)-128);
+ int32_t v_tmp = ((*v_ptr)-128);
+
+ int32_t r_tmp = (v_tmp*param->v_r_factor);
+ int32_t g_tmp = (u_tmp*param->u_g_factor + v_tmp*param->v_g_factor);
+ int32_t b_tmp = (u_tmp*param->u_b_factor);
+
+ // Compute the Y contribution for each pixel
+
+ int32_t y_tmp = ((y_ptr1[0]-param->y_shift)*param->y_factor);
+ PACK_PIXEL(rgb_ptr1);
+
+ if (uv_y_sample_interval > 1) {
+ y_tmp = ((y_ptr2[0]-param->y_shift)*param->y_factor);
+ PACK_PIXEL(rgb_ptr2);
+ }
+ }
+ }
+
+ /* Catch the last line, if needed */
+ if (uv_y_sample_interval == 2 && y == (height-1))
+ {
+ const uint8_t *y_ptr1=Y+y*Y_stride,
+ *u_ptr=U+(y/uv_y_sample_interval)*UV_stride,
+ *v_ptr=V+(y/uv_y_sample_interval)*UV_stride;
+
+ uint8_t *rgb_ptr1=RGB+y*RGB_stride;
+
+ for(x=0; x<(width-(uv_x_sample_interval-1)); x+=uv_x_sample_interval)
+ {
+ // Compute U and V contributions, common to the four pixels
+
+ int32_t u_tmp = ((*u_ptr)-128);
+ int32_t v_tmp = ((*v_ptr)-128);
+
+ int32_t r_tmp = (v_tmp*param->v_r_factor);
+ int32_t g_tmp = (u_tmp*param->u_g_factor + v_tmp*param->v_g_factor);
+ int32_t b_tmp = (u_tmp*param->u_b_factor);
+
+ // Compute the Y contribution for each pixel
+
+ int32_t y_tmp = ((y_ptr1[0]-param->y_shift)*param->y_factor);
+ PACK_PIXEL(rgb_ptr1);
+
+ y_tmp = ((y_ptr1[y_pixel_stride]-param->y_shift)*param->y_factor);
+ PACK_PIXEL(rgb_ptr1);
+
+ y_ptr1+=2*y_pixel_stride;
+ u_ptr+=2*uv_pixel_stride/uv_x_sample_interval;
+ v_ptr+=2*uv_pixel_stride/uv_x_sample_interval;
+ }
+
+ /* Catch the last pixel, if needed */
+ if (uv_x_sample_interval == 2 && x == (width-1))
+ {
+ // Compute U and V contributions, common to the four pixels
+
+ int32_t u_tmp = ((*u_ptr)-128);
+ int32_t v_tmp = ((*v_ptr)-128);
+
+ int32_t r_tmp = (v_tmp*param->v_r_factor);
+ int32_t g_tmp = (u_tmp*param->u_g_factor + v_tmp*param->v_g_factor);
+ int32_t b_tmp = (u_tmp*param->u_b_factor);
+
+ // Compute the Y contribution for each pixel
+
+ int32_t y_tmp = ((y_ptr1[0]-param->y_shift)*param->y_factor);
+ PACK_PIXEL(rgb_ptr1);
+ }
+ }
+}
+
+#undef STD_FUNCTION_NAME
+#undef YUV_FORMAT
+#undef RGB_FORMAT
+#undef PACK_PIXEL
diff --git a/src/3rdparty/buildvm/buildvm-post.bat b/src/3rdparty/buildvm/buildvm-post.bat
new file mode 100644
index 0000000..f9127f2
--- /dev/null
+++ b/src/3rdparty/buildvm/buildvm-post.bat
@@ -0,0 +1,17 @@
+set buildvm=%1
+set outdir=%2
+
+if not exist %outdir% mkdir -p %outdir%
+
+set src=..\LuaJIT-2.0.5\src
+
+set sources=%src%\lib_base.c %src%\lib_math.c %src%\lib_bit.c %src%\lib_string.c %src%\lib_table.c %src%\lib_io.c %src%\lib_os.c %src%\lib_package.c %src%\lib_debug.c %src%\lib_jit.c %src%\lib_ffi.c
+
+%buildvm% -m peobj -o %outdir%\lj_vm.obj %sources%
+%buildvm% -m bcdef -o %outdir%\lj_bcdef.h %sources%
+%buildvm% -m ffdef -o %outdir%\lj_ffdef.h %sources%
+%buildvm% -m libdef -o %outdir%\lj_libdef.h %sources%
+%buildvm% -m recdef -o %outdir%\lj_recdef.h %sources%
+%buildvm% -m vmdef -o %outdir%\vmdef.lua %sources%
+%buildvm% -m folddef -o %outdir%\lj_folddef.h %src%\lj_opt_fold.c
+
diff --git a/src/3rdparty/buildvm/buildvm.exe b/src/3rdparty/buildvm/buildvm.exe
new file mode 100644
index 0000000..a41ba10
--- /dev/null
+++ b/src/3rdparty/buildvm/buildvm.exe
Binary files differ
diff --git a/src/3rdparty/minilua/minilua-post.bat b/src/3rdparty/minilua/minilua-post.bat
new file mode 100644
index 0000000..0e0406f
--- /dev/null
+++ b/src/3rdparty/minilua/minilua-post.bat
@@ -0,0 +1,6 @@
+set minilua=%1
+set outdir=%2
+set luajit=..\LuaJIT-2.0.5
+
+if not exist %outdir% mkdir -p %outdir%
+%minilua% %luajit%\dynasm\dynasm.lua -LN -D WIN -D JIT -D FFI -o %outdir%\buildvm_arch.h %luajit%\src\vm_x86.dasc
diff --git a/src/3rdparty/minilua/minilua.exe b/src/3rdparty/minilua/minilua.exe
new file mode 100644
index 0000000..5369029
--- /dev/null
+++ b/src/3rdparty/minilua/minilua.exe
Binary files differ
diff --git a/src/3rdparty/ogl/OpenGL.h b/src/3rdparty/ogl/OpenGL.h
new file mode 100644
index 0000000..3e416c7
--- /dev/null
+++ b/src/3rdparty/ogl/OpenGL.h
@@ -0,0 +1,184 @@
+#ifndef __OGL2D_H
+#define __OGL2D_H
+#include <vector>
+
+/* include gl.h before this file */
+namespace ogl2d
+{
+ /* 2d wrap of opengl 3.0 */
+ class OpenGL
+ {
+ public:
+ OpenGL();
+ ~OpenGL();
+
+ inline void enable(GLenum cap)
+ {
+ glEnable(cap);
+ }
+
+ inline void disable(GLenum cap)
+ {
+ glDisable(cap);
+ }
+
+ inline void setBlendFunc(GLenum sfactor, GLenum dfactor)
+ {
+ glBlendFunc(sfactor, dfactor);
+ }
+
+ inline void setClearColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a)
+ {
+ glClearColor(r / 255.f, g / 255.f, b / 255.f, a / 255.f);
+ }
+
+ void pushColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a = 255);
+ void popColor();
+ void flushError();
+ GLuint genTexture();
+ void deleteTexture(GLuint texture);
+ void bindTexture(GLuint texture = 0);
+ inline GLuint curTexture()
+ {
+ return _texture;
+ }
+ void setTexParameter(GLenum pname, GLint param);
+ void texImage(GLint internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels = NULL);
+ void texSubImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
+ void activeTexUnit(unsigned int unit = 0);
+
+ inline void drawArrays(GLenum mode, GLint first, GLsizei count)
+ {
+ glDrawArrays(mode, first, count);
+ }
+
+ inline void drawBuffer(GLenum mode)
+ {
+
+ }
+
+ inline void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
+ {
+
+ }
+
+ inline void enableClientState(GLenum arr)
+ {
+ glEnableClientState(arr);
+ }
+
+ inline void disableClientState(GLenum arr)
+ {
+ glDisableClientState(arr);
+ }
+
+ inline GLuint genFrameBuffer()
+ {
+ GLuint fbo;
+ glGenFramebuffers(1, &fbo);
+ return fbo;
+ }
+
+ inline void bindFrameBuffer(GLuint fbo)
+ {
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+ }
+
+ // Ļһ
+ inline void ortho(int w, float radio)
+ {
+ glOrtho(0, w, w*radio, 0, -1, 1);
+ }
+
+ inline void orthox(int w, int h)
+ {
+ glOrtho(0, w, h, 0, -1, 1);
+ }
+
+ protected:
+ struct { GLubyte r, g, b, a; } _color; // current draw color
+ struct { GLubyte r, g, b, a; } _precolor; // previous draw color
+ GLuint _texture; // current binded texture
+
+ };
+
+ ///* OpenGL instance singleton */
+ extern OpenGL gl;
+
+#if defined(OGL2D_IMPLEMENT)
+
+ OpenGL gl;
+
+ OpenGL::OpenGL()
+ {
+ memset(&_color, 0xff, sizeof(_color));
+ memset(&_precolor, 0xff, sizeof(_precolor));
+ }
+
+ OpenGL::~OpenGL()
+ {
+ }
+
+ void OpenGL::pushColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a)
+ {
+ memcpy(&_precolor, &_color, sizeof(_precolor));
+ _color.r = r;
+ _color.g = g;
+ _color.b = b;
+ _color.a = a;
+ glColor4ub(r, g, b, a);
+ }
+
+ void OpenGL::popColor()
+ {
+ memcpy(&_color, &_precolor, sizeof(_precolor));
+ glColor4ub(_color.r, _color.g, _color.b, _color.a);
+ }
+
+ void OpenGL::flushError()
+ {
+ while (glGetError() != GL_NO_ERROR);
+ }
+
+ GLuint OpenGL::genTexture()
+ {
+ GLuint t;
+ glGenTextures(1, &t);
+ return t;
+ }
+
+ void OpenGL::bindTexture(GLuint texture)
+ {
+ glBindTexture(GL_TEXTURE_2D, texture);
+ }
+
+ void OpenGL::deleteTexture(GLuint texture)
+ {
+ glDeleteTextures(1, &texture);
+ }
+
+ void OpenGL::setTexParameter(GLenum pname, GLint param)
+ {
+ glTexParameteri(GL_TEXTURE_2D, pname, param);
+ }
+
+ void OpenGL::texImage(GLint internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)
+ {
+ glTexImage2D(GL_TEXTURE_2D, 0, internalformat, width, height, 0, format, type, pixels);
+ }
+
+ void OpenGL::texSubImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)
+ {
+ glTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, width, height, format, type, pixels);
+ }
+
+ void OpenGL::activeTexUnit(unsigned int unit)
+ {
+ // glActiveTexture selects which texture unit subsequent texture state calls will affect.
+ glActiveTexture(GL_TEXTURE0 + unit);
+ }
+
+#endif // OGL2D_IMPLEMENT
+}
+
+#endif \ No newline at end of file
diff --git a/src/libjin/3rdparty/smount/dirent.h b/src/3rdparty/smount/dirent.h
index 832b164..832b164 100644
--- a/src/libjin/3rdparty/smount/dirent.h
+++ b/src/3rdparty/smount/dirent.h
diff --git a/src/libjin/3rdparty/smount/smount.c b/src/3rdparty/smount/smount.c
index 6214800..6214800 100644
--- a/src/libjin/3rdparty/smount/smount.c
+++ b/src/3rdparty/smount/smount.c
diff --git a/src/libjin/3rdparty/smount/smount.h b/src/3rdparty/smount/smount.h
index 0f8f774..0f8f774 100644
--- a/src/libjin/3rdparty/smount/smount.h
+++ b/src/3rdparty/smount/smount.h
diff --git a/src/libjin/3rdparty/stb/stb_image.h b/src/3rdparty/stb/stb_image.h
index 4df317a..4df317a 100644
--- a/src/libjin/3rdparty/stb/stb_image.h
+++ b/src/3rdparty/stb/stb_image.h
diff --git a/src/libjin/3rdparty/stb/stb_truetype.h b/src/3rdparty/stb/stb_truetype.h
index 927ee21..927ee21 100644
--- a/src/libjin/3rdparty/stb/stb_truetype.h
+++ b/src/3rdparty/stb/stb_truetype.h
diff --git a/src/libjin/3rdparty/stb/stb_vorbis.c b/src/3rdparty/stb/stb_vorbis.c
index a863042..a863042 100644
--- a/src/libjin/3rdparty/stb/stb_vorbis.c
+++ b/src/3rdparty/stb/stb_vorbis.c
diff --git a/src/libjin/3rdparty/tekcos/README b/src/3rdparty/tekcos/README
index fe5ede1..fe5ede1 100644
--- a/src/libjin/3rdparty/tekcos/README
+++ b/src/3rdparty/tekcos/README
diff --git a/src/libjin/3rdparty/tekcos/tekcos.c b/src/3rdparty/tekcos/tekcos.c
index e2b7e5c..e2b7e5c 100644
--- a/src/libjin/3rdparty/tekcos/tekcos.c
+++ b/src/3rdparty/tekcos/tekcos.c
diff --git a/src/libjin/3rdparty/tekcos/tekcos.h b/src/3rdparty/tekcos/tekcos.h
index cddc8f3..cddc8f3 100644
--- a/src/libjin/3rdparty/tekcos/tekcos.h
+++ b/src/3rdparty/tekcos/tekcos.h
diff --git a/src/libjin/3rdparty/wav/wav.c b/src/3rdparty/wav/wav.c
index 6f9b2ab..6f9b2ab 100644
--- a/src/libjin/3rdparty/wav/wav.c
+++ b/src/3rdparty/wav/wav.c
diff --git a/src/libjin/3rdparty/wav/wav.h b/src/3rdparty/wav/wav.h
index c12cd5d..c12cd5d 100644
--- a/src/libjin/3rdparty/wav/wav.h
+++ b/src/3rdparty/wav/wav.h
diff --git a/src/jin/main.cpp b/src/jin/main.cpp
new file mode 100644
index 0000000..8b91cf3
--- /dev/null
+++ b/src/jin/main.cpp
@@ -0,0 +1,107 @@
+#include "lua/luax.h"
+#include "lua/jin.h"
+#include "libjin/jin.h"
+
+#ifdef _WIN32
+ #include <Windows.h>
+ #include <direct.h>
+ #include <shlobj.h>
+ #include <wchar.h>
+#endif
+
+#define EXECUTABLE_DIR "./"
+#define DIALOG_TITLE L"Open existing game"
+
+using namespace std;
+using namespace JinEngine::Filesystem;
+using namespace JinEngine::Lua;
+
+// Load game under cwd.
+static void load(const char* cwd)
+{
+
+ // Global lua runtime.
+ lua_State* L = luax_newstate();
+
+ // Open lua standard module.
+ luax_openlibs(L);
+ // Open jin module.
+ luaopen_jin(L);
+ // Set current working directory.
+ luax_newtable(L);
+ luax_setfieldstring(L, "cwd", cwd);
+ luax_setfield(L, -2, "args");
+ // Clear lua stack.
+ luax_clearstack(L);
+
+ // Boot jin and run it.
+ boot(L);
+
+ // Close lua lib.
+ luax_close(L);
+
+}
+
+#ifdef _WIN32
+// WChar to string.
+std::string wstrtostr(const std::wstring &wstr)
+{
+ std::string strTo;
+ char *szTo = new char[wstr.length() + 1];
+ szTo[wstr.size()] = '\0';
+ WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, szTo, (int)wstr.length(), NULL, NULL);
+ strTo = szTo;
+ delete[] szTo;
+ return strTo;
+}
+#endif
+
+std::string BrowseFolder()
+{
+#ifdef _WIN32
+ string path = EXECUTABLE_DIR;
+ IFileDialog* pfd = NULL;
+ DWORD dwFlags;
+ IShellItem* pItem = NULL;
+ HRESULT hr = CoInitialize(NULL);
+ if (FAILED(hr)) goto End;
+ hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
+ IID_IFileOpenDialog, reinterpret_cast<void**>(&pfd));
+ if (FAILED(hr)) goto End;
+ pfd->SetTitle(DIALOG_TITLE);
+ hr = pfd->GetOptions(&dwFlags);
+ if (FAILED(hr)) goto End;
+ hr = pfd->SetOptions(dwFlags | FOS_PICKFOLDERS);
+ if (FAILED(hr)) goto End;
+ hr = pfd->Show(NULL);
+ if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED))
+ goto End;
+ hr = pfd->GetResult(&pItem);
+ if (FAILED(hr)) goto End;
+ LPWSTR filePath;
+ hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &filePath);
+ if (FAILED(hr)) goto End;
+ path = wstrtostr(filePath);
+ CoTaskMemFree(filePath);
+ pItem->Release();
+ pfd->Release();
+ CoUninitialize();
+End:
+ return path;
+#endif
+}
+
+int main(int argc, char* args[])
+{
+ string cwd = EXECUTABLE_DIR;
+#ifdef _WIN32
+ if (argc > 1)
+ cwd = args[1];
+#endif
+ else
+ cwd = BrowseFolder();
+ if (!cwd.empty())
+ load(cwd.c_str());
+
+ return 0;
+}// todo:main.luaĶȡ \ No newline at end of file
diff --git a/src/libjin/3rdparty/base64/base64.h b/src/libjin/3rdparty/base64/base64.h
deleted file mode 100644
index 2519797..0000000
--- a/src/libjin/3rdparty/base64/base64.h
+++ /dev/null
@@ -1,186 +0,0 @@
-#ifndef BASE64_H
-#define BASE64_H
-
-#define BASE64_ENCODE_OUT_SIZE(s) ((unsigned int)((((s) + 2) / 3) * 4 + 1))
-#define BASE64_DECODE_OUT_SIZE(s) ((unsigned int)(((s) / 4) * 3))
-
-/*
-* out is null-terminated encode string.
-* return values is out length, exclusive terminating `\0'
-*/
-unsigned int
-base64_encode(const unsigned char *in, unsigned int inlen, char *out);
-
-/*
-* return values is out length
-*/
-unsigned int
-base64_decode(const char *in, unsigned int inlen, unsigned char *out);
-
-#endif /* BASE64_H */
-
-#ifdef BASE64_IMPLEMENT
-
-/* This is a public domain base64 implementation written by WEI Zhicheng. */
-
-#define BASE64_PAD '='
-
-/* BASE 64 encode table */
-static const char base64en[] = {
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
- 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
- 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
- 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
- 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
- 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
- 'w', 'x', 'y', 'z', '0', '1', '2', '3',
- '4', '5', '6', '7', '8', '9', '+', '/',
-};
-
-/* ASCII order for BASE 64 decode, 255 in unused character */
-static const unsigned char base64de[] = {
- /* nul, soh, stx, etx, eot, enq, ack, bel, */
- 255, 255, 255, 255, 255, 255, 255, 255,
-
- /* bs, ht, nl, vt, np, cr, so, si, */
- 255, 255, 255, 255, 255, 255, 255, 255,
-
- /* dle, dc1, dc2, dc3, dc4, nak, syn, etb, */
- 255, 255, 255, 255, 255, 255, 255, 255,
-
- /* can, em, sub, esc, fs, gs, rs, us, */
- 255, 255, 255, 255, 255, 255, 255, 255,
-
- /* sp, '!', '"', '#', '$', '%', '&', ''', */
- 255, 255, 255, 255, 255, 255, 255, 255,
-
- /* '(', ')', '*', '+', ',', '-', '.', '/', */
- 255, 255, 255, 62, 255, 255, 255, 63,
-
- /* '0', '1', '2', '3', '4', '5', '6', '7', */
- 52, 53, 54, 55, 56, 57, 58, 59,
-
- /* '8', '9', ':', ';', '<', '=', '>', '?', */
- 60, 61, 255, 255, 255, 255, 255, 255,
-
- /* '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', */
- 255, 0, 1, 2, 3, 4, 5, 6,
-
- /* 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', */
- 7, 8, 9, 10, 11, 12, 13, 14,
-
- /* 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', */
- 15, 16, 17, 18, 19, 20, 21, 22,
-
- /* 'X', 'Y', 'Z', '[', '\', ']', '^', '_', */
- 23, 24, 25, 255, 255, 255, 255, 255,
-
- /* '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', */
- 255, 26, 27, 28, 29, 30, 31, 32,
-
- /* 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', */
- 33, 34, 35, 36, 37, 38, 39, 40,
-
- /* 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', */
- 41, 42, 43, 44, 45, 46, 47, 48,
-
- /* 'x', 'y', 'z', '{', '|', '}', '~', del, */
- 49, 50, 51, 255, 255, 255, 255, 255
-};
-
-unsigned int
-base64_encode(const unsigned char *in, unsigned int inlen, char *out)
-{
- int s;
- unsigned int i;
- unsigned int j;
- unsigned char c;
- unsigned char l;
-
- s = 0;
- l = 0;
- for (i = j = 0; i < inlen; i++) {
- c = in[i];
-
- switch (s) {
- case 0:
- s = 1;
- out[j++] = base64en[(c >> 2) & 0x3F];
- break;
- case 1:
- s = 2;
- out[j++] = base64en[((l & 0x3) << 4) | ((c >> 4) & 0xF)];
- break;
- case 2:
- s = 0;
- out[j++] = base64en[((l & 0xF) << 2) | ((c >> 6) & 0x3)];
- out[j++] = base64en[c & 0x3F];
- break;
- }
- l = c;
- }
-
- switch (s) {
- case 1:
- out[j++] = base64en[(l & 0x3) << 4];
- out[j++] = BASE64_PAD;
- out[j++] = BASE64_PAD;
- break;
- case 2:
- out[j++] = base64en[(l & 0xF) << 2];
- out[j++] = BASE64_PAD;
- break;
- }
-
- out[j] = 0;
-
- return j;
-}
-
-unsigned int
-base64_decode(const char *in, unsigned int inlen, unsigned char *out)
-{
- unsigned int i;
- unsigned int j;
- unsigned char c;
-
- if (inlen & 0x3) {
- return 0;
- }
-
- for (i = j = 0; i < inlen; i++) {
- if (in[i] == BASE64_PAD) {
- break;
- }
- if (in[i] < 0) {
- return 0;
- }
-
- c = base64de[in[i]];
- if (c == 255) {
- return 0;
- }
-
- switch (i & 0x3) {
- case 0:
- out[j] = (c << 2) & 0xFF;
- break;
- case 1:
- out[j++] |= (c >> 4) & 0x3;
- out[j] = (c & 0xF) << 4;
- break;
- case 2:
- out[j++] |= (c >> 2) & 0xF;
- out[j] = (c & 0x3) << 6;
- break;
- case 3:
- out[j++] |= c;
- break;
- }
- }
- out[j] = '\0';
-
- return j;
-}
-
-#endif
diff --git a/src/libjin/3rdparty/ogl/OpenGL.h b/src/libjin/3rdparty/ogl/OpenGL.h
deleted file mode 100644
index 3984b49..0000000
--- a/src/libjin/3rdparty/ogl/OpenGL.h
+++ /dev/null
@@ -1,520 +0,0 @@
-#ifndef __OGL2D_H
-#define __OGL2D_H
-#include <vector>
-
-/* include gl.h before this file */
-namespace ogl2d
-{
- /* 2d wrap of opengl 3.0 */
- class OpenGL
- {
- public:
- OpenGL();
- ~OpenGL();
-
- inline void enable(GLenum cap)
- {
- glEnable(cap);
- }
-
- inline void disable(GLenum cap)
- {
- glDisable(cap);
- }
-
- inline void setBlendFunc(GLenum sfactor, GLenum dfactor)
- {
- glBlendFunc(sfactor, dfactor);
- }
-
- inline void setClearColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a)
- {
- glClearColor(r / 255.f, g / 255.f, b / 255.f, a / 255.f);
- }
-
- void pushColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a = 255);
- void popColor();
- void flushError();
- GLuint genTexture();
- void bindTexture(GLuint texture = 0);
- inline GLuint curTexture()
- {
- return _texture;
- }
- void setTexParameter(GLenum pname, GLint param);
- void texImage(GLint internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels = NULL);
- void texSubImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
- void activeTexUnit(unsigned int unit = 0);
-
- inline void drawArrays(GLenum mode, GLint first, GLsizei count)
- {
- glDrawArrays(mode, first, count);
- }
-
- inline void drawBuffer(GLenum mode)
- {
-
- }
-
- inline void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
- {
-
- }
-
- inline void enableClientState(GLenum arr)
- {
- glEnableClientState(arr);
- }
-
- inline void disableClientState(GLenum arr)
- {
- glDisableClientState(arr);
- }
-
- inline GLuint genFrameBuffer()
- {
- GLuint fbo;
- glGenFramebuffers(1, &fbo);
- return fbo;
- }
-
- inline void bindFrameBuffer(GLuint fbo)
- {
- glBindFramebuffer(GL_FRAMEBUFFER, fbo);
- }
-
- // Ļһ
- inline void ortho(int w, float radio)
- {
- glOrtho(0, w, w*radio, 0, -1, 1);
- }
-
- inline void orthox(int w, int h)
- {
- glOrtho(0, w, h, 0, -1, 1);
- }
-
- protected:
- struct { GLubyte r, g, b, a; } _color; // current draw color
- struct { GLubyte r, g, b, a; } _precolor; // previous draw color
- GLuint _texture; // current binded texture
-
- };
-
- ///* OpenGL instance singleton */
- extern OpenGL gl;
-
-#if defined(OGL2D_IMPLEMENT)
-
- OpenGL gl;
-
- OpenGL::OpenGL()
- {
- memset(&_color, 0xff, sizeof(_color));
- memset(&_precolor, 0xff, sizeof(_precolor));
- }
-
- OpenGL::~OpenGL()
- {
- }
-
- void OpenGL::pushColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a)
- {
- memcpy(&_precolor, &_color, sizeof(_precolor));
- _color.r = r;
- _color.g = g;
- _color.b = b;
- _color.a = a;
- glColor4ub(r, g, b, a);
- }
-
- void OpenGL::popColor()
- {
- memcpy(&_color, &_precolor, sizeof(_precolor));
- glColor4ub(_color.r, _color.g, _color.b, _color.a);
- }
-
- void OpenGL::flushError()
- {
- while (glGetError() != GL_NO_ERROR);
- }
-
- GLuint OpenGL::genTexture()
- {
- GLuint t;
- glGenTextures(1, &t);
- return t;
- }
-
- void OpenGL::bindTexture(GLuint texture)
- {
- glBindTexture(GL_TEXTURE_2D, texture);
- }
-
- void OpenGL::setTexParameter(GLenum pname, GLint param)
- {
- glTexParameteri(GL_TEXTURE_2D, pname, param);
- }
-
- void OpenGL::texImage(GLint internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)
- {
- glTexImage2D(GL_TEXTURE_2D, 0, internalformat, width, height, 0, format, type, pixels);
- }
-
- void OpenGL::texSubImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels)
- {
- glTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, width, height, format, type, pixels);
- }
-
- void OpenGL::activeTexUnit(unsigned int unit)
- {
- // glActiveTexture selects which texture unit subsequent texture state calls will affect.
- glActiveTexture(GL_TEXTURE0 + unit);
- }
-
-#endif // OGL2D_IMPLEMENT
-}
-
-#endif
-
-
-/* GL.h
-
-WINGDIAPI void APIENTRY glAccum(GLenum op, GLfloat value);
-WINGDIAPI void APIENTRY glAlphaFunc(GLenum func, GLclampf ref);
-WINGDIAPI GLboolean APIENTRY glAreTexturesResident(GLsizei n, const GLuint *textures, GLboolean *residences);
-WINGDIAPI void APIENTRY glArrayElement(GLint i);
-WINGDIAPI void APIENTRY glBegin(GLenum mode);
-WINGDIAPI void APIENTRY glBindTexture(GLenum target, GLuint texture);
-WINGDIAPI void APIENTRY glBitmap(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap);
-WINGDIAPI void APIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor);
-WINGDIAPI void APIENTRY glCallList(GLuint list);
-WINGDIAPI void APIENTRY glCallLists(GLsizei n, GLenum type, const GLvoid *lists);
-WINGDIAPI void APIENTRY glClear(GLbitfield mask);
-WINGDIAPI void APIENTRY glClearAccum(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
-WINGDIAPI void APIENTRY glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
-WINGDIAPI void APIENTRY glClearDepth(GLclampd depth);
-WINGDIAPI void APIENTRY glClearIndex(GLfloat c);
-WINGDIAPI void APIENTRY glClearStencil(GLint s);
-WINGDIAPI void APIENTRY glClipPlane(GLenum plane, const GLdouble *equation);
-WINGDIAPI void APIENTRY glColor3b(GLbyte red, GLbyte green, GLbyte blue);
-WINGDIAPI void APIENTRY glColor3bv(const GLbyte *v);
-WINGDIAPI void APIENTRY glColor3d(GLdouble red, GLdouble green, GLdouble blue);
-WINGDIAPI void APIENTRY glColor3dv(const GLdouble *v);
-WINGDIAPI void APIENTRY glColor3f(GLfloat red, GLfloat green, GLfloat blue);
-WINGDIAPI void APIENTRY glColor3fv(const GLfloat *v);
-WINGDIAPI void APIENTRY glColor3i(GLint red, GLint green, GLint blue);
-WINGDIAPI void APIENTRY glColor3iv(const GLint *v);
-WINGDIAPI void APIENTRY glColor3s(GLshort red, GLshort green, GLshort blue);
-WINGDIAPI void APIENTRY glColor3sv(const GLshort *v);
-WINGDIAPI void APIENTRY glColor3ub(GLubyte red, GLubyte green, GLubyte blue);
-WINGDIAPI void APIENTRY glColor3ubv(const GLubyte *v);
-WINGDIAPI void APIENTRY glColor3ui(GLuint red, GLuint green, GLuint blue);
-WINGDIAPI void APIENTRY glColor3uiv(const GLuint *v);
-WINGDIAPI void APIENTRY glColor3us(GLushort red, GLushort green, GLushort blue);
-WINGDIAPI void APIENTRY glColor3usv(const GLushort *v);
-WINGDIAPI void APIENTRY glColor4b(GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha);
-WINGDIAPI void APIENTRY glColor4bv(const GLbyte *v);
-WINGDIAPI void APIENTRY glColor4d(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha);
-WINGDIAPI void APIENTRY glColor4dv(const GLdouble *v);
-WINGDIAPI void APIENTRY glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
-WINGDIAPI void APIENTRY glColor4fv(const GLfloat *v);
-WINGDIAPI void APIENTRY glColor4i(GLint red, GLint green, GLint blue, GLint alpha);
-WINGDIAPI void APIENTRY glColor4iv(const GLint *v);
-WINGDIAPI void APIENTRY glColor4s(GLshort red, GLshort green, GLshort blue, GLshort alpha);
-WINGDIAPI void APIENTRY glColor4sv(const GLshort *v);
-WINGDIAPI void APIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
-WINGDIAPI void APIENTRY glColor4ubv(const GLubyte *v);
-WINGDIAPI void APIENTRY glColor4ui(GLuint red, GLuint green, GLuint blue, GLuint alpha);
-WINGDIAPI void APIENTRY glColor4uiv(const GLuint *v);
-WINGDIAPI void APIENTRY glColor4us(GLushort red, GLushort green, GLushort blue, GLushort alpha);
-WINGDIAPI void APIENTRY glColor4usv(const GLushort *v);
-WINGDIAPI void APIENTRY glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
-WINGDIAPI void APIENTRY glColorMaterial(GLenum face, GLenum mode);
-WINGDIAPI void APIENTRY glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
-WINGDIAPI void APIENTRY glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type);
-WINGDIAPI void APIENTRY glCopyTexImage1D(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLint border);
-WINGDIAPI void APIENTRY glCopyTexImage2D(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
-WINGDIAPI void APIENTRY glCopyTexSubImage1D(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
-WINGDIAPI void APIENTRY glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
-WINGDIAPI void APIENTRY glCullFace(GLenum mode);
-WINGDIAPI void APIENTRY glDeleteLists(GLuint list, GLsizei range);
-WINGDIAPI void APIENTRY glDeleteTextures(GLsizei n, const GLuint *textures);
-WINGDIAPI void APIENTRY glDepthFunc(GLenum func);
-WINGDIAPI void APIENTRY glDepthMask(GLboolean flag);
-WINGDIAPI void APIENTRY glDepthRange(GLclampd zNear, GLclampd zFar);
-WINGDIAPI void APIENTRY glDisable(GLenum cap);
-WINGDIAPI void APIENTRY glDisableClientState(GLenum array);
-WINGDIAPI void APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count);
-WINGDIAPI void APIENTRY glDrawBuffer(GLenum mode);
-WINGDIAPI void APIENTRY glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
-WINGDIAPI void APIENTRY glDrawPixels(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
-WINGDIAPI void APIENTRY glEdgeFlag(GLboolean flag);
-WINGDIAPI void APIENTRY glEdgeFlagPointer(GLsizei stride, const GLvoid *pointer);
-WINGDIAPI void APIENTRY glEdgeFlagv(const GLboolean *flag);
-WINGDIAPI void APIENTRY glEnable(GLenum cap);
-WINGDIAPI void APIENTRY glEnableClientState(GLenum array);
-WINGDIAPI void APIENTRY glEnd(void);
-WINGDIAPI void APIENTRY glEndList(void);
-WINGDIAPI void APIENTRY glEvalCoord1d(GLdouble u);
-WINGDIAPI void APIENTRY glEvalCoord1dv(const GLdouble *u);
-WINGDIAPI void APIENTRY glEvalCoord1f(GLfloat u);
-WINGDIAPI void APIENTRY glEvalCoord1fv(const GLfloat *u);
-WINGDIAPI void APIENTRY glEvalCoord2d(GLdouble u, GLdouble v);
-WINGDIAPI void APIENTRY glEvalCoord2dv(const GLdouble *u);
-WINGDIAPI void APIENTRY glEvalCoord2f(GLfloat u, GLfloat v);
-WINGDIAPI void APIENTRY glEvalCoord2fv(const GLfloat *u);
-WINGDIAPI void APIENTRY glEvalMesh1(GLenum mode, GLint i1, GLint i2);
-WINGDIAPI void APIENTRY glEvalMesh2(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2);
-WINGDIAPI void APIENTRY glEvalPoint1(GLint i);
-WINGDIAPI void APIENTRY glEvalPoint2(GLint i, GLint j);
-WINGDIAPI void APIENTRY glFeedbackBuffer(GLsizei size, GLenum type, GLfloat *buffer);
-WINGDIAPI void APIENTRY glFinish(void);
-WINGDIAPI void APIENTRY glFlush(void);
-WINGDIAPI void APIENTRY glFogf(GLenum pname, GLfloat param);
-WINGDIAPI void APIENTRY glFogfv(GLenum pname, const GLfloat *params);
-WINGDIAPI void APIENTRY glFogi(GLenum pname, GLint param);
-WINGDIAPI void APIENTRY glFogiv(GLenum pname, const GLint *params);
-WINGDIAPI void APIENTRY glFrontFace(GLenum mode);
-WINGDIAPI void APIENTRY glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
-WINGDIAPI GLuint APIENTRY glGenLists(GLsizei range);
-WINGDIAPI void APIENTRY glGenTextures(GLsizei n, GLuint *textures);
-WINGDIAPI void APIENTRY glGetBooleanv(GLenum pname, GLboolean *params);
-WINGDIAPI void APIENTRY glGetClipPlane(GLenum plane, GLdouble *equation);
-WINGDIAPI void APIENTRY glGetDoublev(GLenum pname, GLdouble *params);
-WINGDIAPI GLenum APIENTRY glGetError(void);
-WINGDIAPI void APIENTRY glGetFloatv(GLenum pname, GLfloat *params);
-WINGDIAPI void APIENTRY glGetIntegerv(GLenum pname, GLint *params);
-WINGDIAPI void APIENTRY glGetLightfv(GLenum light, GLenum pname, GLfloat *params);
-WINGDIAPI void APIENTRY glGetLightiv(GLenum light, GLenum pname, GLint *params);
-WINGDIAPI void APIENTRY glGetMapdv(GLenum target, GLenum query, GLdouble *v);
-WINGDIAPI void APIENTRY glGetMapfv(GLenum target, GLenum query, GLfloat *v);
-WINGDIAPI void APIENTRY glGetMapiv(GLenum target, GLenum query, GLint *v);
-WINGDIAPI void APIENTRY glGetMaterialfv(GLenum face, GLenum pname, GLfloat *params);
-WINGDIAPI void APIENTRY glGetMaterialiv(GLenum face, GLenum pname, GLint *params);
-WINGDIAPI void APIENTRY glGetPixelMapfv(GLenum map, GLfloat *values);
-WINGDIAPI void APIENTRY glGetPixelMapuiv(GLenum map, GLuint *values);
-WINGDIAPI void APIENTRY glGetPixelMapusv(GLenum map, GLushort *values);
-WINGDIAPI void APIENTRY glGetPointerv(GLenum pname, GLvoid* *params);
-WINGDIAPI void APIENTRY glGetPolygonStipple(GLubyte *mask);
-WINGDIAPI const GLubyte * APIENTRY glGetString(GLenum name);
-WINGDIAPI void APIENTRY glGetTexEnvfv(GLenum target, GLenum pname, GLfloat *params);
-WINGDIAPI void APIENTRY glGetTexEnviv(GLenum target, GLenum pname, GLint *params);
-WINGDIAPI void APIENTRY glGetTexGendv(GLenum coord, GLenum pname, GLdouble *params);
-WINGDIAPI void APIENTRY glGetTexGenfv(GLenum coord, GLenum pname, GLfloat *params);
-WINGDIAPI void APIENTRY glGetTexGeniv(GLenum coord, GLenum pname, GLint *params);
-WINGDIAPI void APIENTRY glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels);
-WINGDIAPI void APIENTRY glGetTexLevelParameterfv(GLenum target, GLint level, GLenum pname, GLfloat *params);
-WINGDIAPI void APIENTRY glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params);
-WINGDIAPI void APIENTRY glGetTexParameterfv(GLenum target, GLenum pname, GLfloat *params);
-WINGDIAPI void APIENTRY glGetTexParameteriv(GLenum target, GLenum pname, GLint *params);
-WINGDIAPI void APIENTRY glHint(GLenum target, GLenum mode);
-WINGDIAPI void APIENTRY glIndexMask(GLuint mask);
-WINGDIAPI void APIENTRY glIndexPointer(GLenum type, GLsizei stride, const GLvoid *pointer);
-WINGDIAPI void APIENTRY glIndexd(GLdouble c);
-WINGDIAPI void APIENTRY glIndexdv(const GLdouble *c);
-WINGDIAPI void APIENTRY glIndexf(GLfloat c);
-WINGDIAPI void APIENTRY glIndexfv(const GLfloat *c);
-WINGDIAPI void APIENTRY glIndexi(GLint c);
-WINGDIAPI void APIENTRY glIndexiv(const GLint *c);
-WINGDIAPI void APIENTRY glIndexs(GLshort c);
-WINGDIAPI void APIENTRY glIndexsv(const GLshort *c);
-WINGDIAPI void APIENTRY glIndexub(GLubyte c);
-WINGDIAPI void APIENTRY glIndexubv(const GLubyte *c);
-WINGDIAPI void APIENTRY glInitNames(void);
-WINGDIAPI void APIENTRY glInterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer);
-WINGDIAPI GLboolean APIENTRY glIsEnabled(GLenum cap);
-WINGDIAPI GLboolean APIENTRY glIsList(GLuint list);
-WINGDIAPI GLboolean APIENTRY glIsTexture(GLuint texture);
-WINGDIAPI void APIENTRY glLightModelf(GLenum pname, GLfloat param);
-WINGDIAPI void APIENTRY glLightModelfv(GLenum pname, const GLfloat *params);
-WINGDIAPI void APIENTRY glLightModeli(GLenum pname, GLint param);
-WINGDIAPI void APIENTRY glLightModeliv(GLenum pname, const GLint *params);
-WINGDIAPI void APIENTRY glLightf(GLenum light, GLenum pname, GLfloat param);
-WINGDIAPI void APIENTRY glLightfv(GLenum light, GLenum pname, const GLfloat *params);
-WINGDIAPI void APIENTRY glLighti(GLenum light, GLenum pname, GLint param);
-WINGDIAPI void APIENTRY glLightiv(GLenum light, GLenum pname, const GLint *params);
-WINGDIAPI void APIENTRY glLineStipple(GLint factor, GLushort pattern);
-WINGDIAPI void APIENTRY glLineWidth(GLfloat width);
-WINGDIAPI void APIENTRY glListBase(GLuint base);
-WINGDIAPI void APIENTRY glLoadIdentity(void);
-WINGDIAPI void APIENTRY glLoadMatrixd(const GLdouble *m);
-WINGDIAPI void APIENTRY glLoadMatrixf(const GLfloat *m);
-WINGDIAPI void APIENTRY glLoadName(GLuint name);
-WINGDIAPI void APIENTRY glLogicOp(GLenum opcode);
-WINGDIAPI void APIENTRY glMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points);
-WINGDIAPI void APIENTRY glMap1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points);
-WINGDIAPI void APIENTRY glMap2d(GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points);
-WINGDIAPI void APIENTRY glMap2f(GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points);
-WINGDIAPI void APIENTRY glMapGrid1d(GLint un, GLdouble u1, GLdouble u2);
-WINGDIAPI void APIENTRY glMapGrid1f(GLint un, GLfloat u1, GLfloat u2);
-WINGDIAPI void APIENTRY glMapGrid2d(GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2);
-WINGDIAPI void APIENTRY glMapGrid2f(GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2);
-WINGDIAPI void APIENTRY glMaterialf(GLenum face, GLenum pname, GLfloat param);
-WINGDIAPI void APIENTRY glMaterialfv(GLenum face, GLenum pname, const GLfloat *params);
-WINGDIAPI void APIENTRY glMateriali(GLenum face, GLenum pname, GLint param);
-WINGDIAPI void APIENTRY glMaterialiv(GLenum face, GLenum pname, const GLint *params);
-WINGDIAPI void APIENTRY glMatrixMode(GLenum mode);
-WINGDIAPI void APIENTRY glMultMatrixd(const GLdouble *m);
-WINGDIAPI void APIENTRY glMultMatrixf(const GLfloat *m);
-WINGDIAPI void APIENTRY glNewList(GLuint list, GLenum mode);
-WINGDIAPI void APIENTRY glNormal3b(GLbyte nx, GLbyte ny, GLbyte nz);
-WINGDIAPI void APIENTRY glNormal3bv(const GLbyte *v);
-WINGDIAPI void APIENTRY glNormal3d(GLdouble nx, GLdouble ny, GLdouble nz);
-WINGDIAPI void APIENTRY glNormal3dv(const GLdouble *v);
-WINGDIAPI void APIENTRY glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz);
-WINGDIAPI void APIENTRY glNormal3fv(const GLfloat *v);
-WINGDIAPI void APIENTRY glNormal3i(GLint nx, GLint ny, GLint nz);
-WINGDIAPI void APIENTRY glNormal3iv(const GLint *v);
-WINGDIAPI void APIENTRY glNormal3s(GLshort nx, GLshort ny, GLshort nz);
-WINGDIAPI void APIENTRY glNormal3sv(const GLshort *v);
-WINGDIAPI void APIENTRY glNormalPointer(GLenum type, GLsizei stride, const GLvoid *pointer);
-WINGDIAPI void APIENTRY glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
-WINGDIAPI void APIENTRY glPassThrough(GLfloat token);
-WINGDIAPI void APIENTRY glPixelMapfv(GLenum map, GLsizei mapsize, const GLfloat *values);
-WINGDIAPI void APIENTRY glPixelMapuiv(GLenum map, GLsizei mapsize, const GLuint *values);
-WINGDIAPI void APIENTRY glPixelMapusv(GLenum map, GLsizei mapsize, const GLushort *values);
-WINGDIAPI void APIENTRY glPixelStoref(GLenum pname, GLfloat param);
-WINGDIAPI void APIENTRY glPixelStorei(GLenum pname, GLint param);
-WINGDIAPI void APIENTRY glPixelTransferf(GLenum pname, GLfloat param);
-WINGDIAPI void APIENTRY glPixelTransferi(GLenum pname, GLint param);
-WINGDIAPI void APIENTRY glPixelZoom(GLfloat xfactor, GLfloat yfactor);
-WINGDIAPI void APIENTRY glPointSize(GLfloat size);
-WINGDIAPI void APIENTRY glPolygonMode(GLenum face, GLenum mode);
-WINGDIAPI void APIENTRY glPolygonOffset(GLfloat factor, GLfloat units);
-WINGDIAPI void APIENTRY glPolygonStipple(const GLubyte *mask);
-WINGDIAPI void APIENTRY glPopAttrib(void);
-WINGDIAPI void APIENTRY glPopClientAttrib(void);
-WINGDIAPI void APIENTRY glPopMatrix(void);
-WINGDIAPI void APIENTRY glPopName(void);
-WINGDIAPI void APIENTRY glPrioritizeTextures(GLsizei n, const GLuint *textures, const GLclampf *priorities);
-WINGDIAPI void APIENTRY glPushAttrib(GLbitfield mask);
-WINGDIAPI void APIENTRY glPushClientAttrib(GLbitfield mask);
-WINGDIAPI void APIENTRY glPushMatrix(void);
-WINGDIAPI void APIENTRY glPushName(GLuint name);
-WINGDIAPI void APIENTRY glRasterPos2d(GLdouble x, GLdouble y);
-WINGDIAPI void APIENTRY glRasterPos2dv(const GLdouble *v);
-WINGDIAPI void APIENTRY glRasterPos2f(GLfloat x, GLfloat y);
-WINGDIAPI void APIENTRY glRasterPos2fv(const GLfloat *v);
-WINGDIAPI void APIENTRY glRasterPos2i(GLint x, GLint y);
-WINGDIAPI void APIENTRY glRasterPos2iv(const GLint *v);
-WINGDIAPI void APIENTRY glRasterPos2s(GLshort x, GLshort y);
-WINGDIAPI void APIENTRY glRasterPos2sv(const GLshort *v);
-WINGDIAPI void APIENTRY glRasterPos3d(GLdouble x, GLdouble y, GLdouble z);
-WINGDIAPI void APIENTRY glRasterPos3dv(const GLdouble *v);
-WINGDIAPI void APIENTRY glRasterPos3f(GLfloat x, GLfloat y, GLfloat z);
-WINGDIAPI void APIENTRY glRasterPos3fv(const GLfloat *v);
-WINGDIAPI void APIENTRY glRasterPos3i(GLint x, GLint y, GLint z);
-WINGDIAPI void APIENTRY glRasterPos3iv(const GLint *v);
-WINGDIAPI void APIENTRY glRasterPos3s(GLshort x, GLshort y, GLshort z);
-WINGDIAPI void APIENTRY glRasterPos3sv(const GLshort *v);
-WINGDIAPI void APIENTRY glRasterPos4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w);
-WINGDIAPI void APIENTRY glRasterPos4dv(const GLdouble *v);
-WINGDIAPI void APIENTRY glRasterPos4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w);
-WINGDIAPI void APIENTRY glRasterPos4fv(const GLfloat *v);
-WINGDIAPI void APIENTRY glRasterPos4i(GLint x, GLint y, GLint z, GLint w);
-WINGDIAPI void APIENTRY glRasterPos4iv(const GLint *v);
-WINGDIAPI void APIENTRY glRasterPos4s(GLshort x, GLshort y, GLshort z, GLshort w);
-WINGDIAPI void APIENTRY glRasterPos4sv(const GLshort *v);
-WINGDIAPI void APIENTRY glReadBuffer(GLenum mode);
-WINGDIAPI void APIENTRY glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
-WINGDIAPI void APIENTRY glRectd(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2);
-WINGDIAPI void APIENTRY glRectdv(const GLdouble *v1, const GLdouble *v2);
-WINGDIAPI void APIENTRY glRectf(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2);
-WINGDIAPI void APIENTRY glRectfv(const GLfloat *v1, const GLfloat *v2);
-WINGDIAPI void APIENTRY glRecti(GLint x1, GLint y1, GLint x2, GLint y2);
-WINGDIAPI void APIENTRY glRectiv(const GLint *v1, const GLint *v2);
-WINGDIAPI void APIENTRY glRects(GLshort x1, GLshort y1, GLshort x2, GLshort y2);
-WINGDIAPI void APIENTRY glRectsv(const GLshort *v1, const GLshort *v2);
-WINGDIAPI GLint APIENTRY glRenderMode(GLenum mode);
-WINGDIAPI void APIENTRY glRotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
-WINGDIAPI void APIENTRY glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
-WINGDIAPI void APIENTRY glScaled(GLdouble x, GLdouble y, GLdouble z);
-WINGDIAPI void APIENTRY glScalef(GLfloat x, GLfloat y, GLfloat z);
-WINGDIAPI void APIENTRY glScissor(GLint x, GLint y, GLsizei width, GLsizei height);
-WINGDIAPI void APIENTRY glSelectBuffer(GLsizei size, GLuint *buffer);
-WINGDIAPI void APIENTRY glShadeModel(GLenum mode);
-WINGDIAPI void APIENTRY glStencilFunc(GLenum func, GLint ref, GLuint mask);
-WINGDIAPI void APIENTRY glStencilMask(GLuint mask);
-WINGDIAPI void APIENTRY glStencilOp(GLenum fail, GLenum zfail, GLenum zpass);
-WINGDIAPI void APIENTRY glTexCoord1d(GLdouble s);
-WINGDIAPI void APIENTRY glTexCoord1dv(const GLdouble *v);
-WINGDIAPI void APIENTRY glTexCoord1f(GLfloat s);
-WINGDIAPI void APIENTRY glTexCoord1fv(const GLfloat *v);
-WINGDIAPI void APIENTRY glTexCoord1i(GLint s);
-WINGDIAPI void APIENTRY glTexCoord1iv(const GLint *v);
-WINGDIAPI void APIENTRY glTexCoord1s(GLshort s);
-WINGDIAPI void APIENTRY glTexCoord1sv(const GLshort *v);
-WINGDIAPI void APIENTRY glTexCoord2d(GLdouble s, GLdouble t);
-WINGDIAPI void APIENTRY glTexCoord2dv(const GLdouble *v);
-WINGDIAPI void APIENTRY glTexCoord2f(GLfloat s, GLfloat t);
-WINGDIAPI void APIENTRY glTexCoord2fv(const GLfloat *v);
-WINGDIAPI void APIENTRY glTexCoord2i(GLint s, GLint t);
-WINGDIAPI void APIENTRY glTexCoord2iv(const GLint *v);
-WINGDIAPI void APIENTRY glTexCoord2s(GLshort s, GLshort t);
-WINGDIAPI void APIENTRY glTexCoord2sv(const GLshort *v);
-WINGDIAPI void APIENTRY glTexCoord3d(GLdouble s, GLdouble t, GLdouble r);
-WINGDIAPI void APIENTRY glTexCoord3dv(const GLdouble *v);
-WINGDIAPI void APIENTRY glTexCoord3f(GLfloat s, GLfloat t, GLfloat r);
-WINGDIAPI void APIENTRY glTexCoord3fv(const GLfloat *v);
-WINGDIAPI void APIENTRY glTexCoord3i(GLint s, GLint t, GLint r);
-WINGDIAPI void APIENTRY glTexCoord3iv(const GLint *v);
-WINGDIAPI void APIENTRY glTexCoord3s(GLshort s, GLshort t, GLshort r);
-WINGDIAPI void APIENTRY glTexCoord3sv(const GLshort *v);
-WINGDIAPI void APIENTRY glTexCoord4d(GLdouble s, GLdouble t, GLdouble r, GLdouble q);
-WINGDIAPI void APIENTRY glTexCoord4dv(const GLdouble *v);
-WINGDIAPI void APIENTRY glTexCoord4f(GLfloat s, GLfloat t, GLfloat r, GLfloat q);
-WINGDIAPI void APIENTRY glTexCoord4fv(const GLfloat *v);
-WINGDIAPI void APIENTRY glTexCoord4i(GLint s, GLint t, GLint r, GLint q);
-WINGDIAPI void APIENTRY glTexCoord4iv(const GLint *v);
-WINGDIAPI void APIENTRY glTexCoord4s(GLshort s, GLshort t, GLshort r, GLshort q);
-WINGDIAPI void APIENTRY glTexCoord4sv(const GLshort *v);
-WINGDIAPI void APIENTRY glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
-WINGDIAPI void APIENTRY glTexEnvf(GLenum target, GLenum pname, GLfloat param);
-WINGDIAPI void APIENTRY glTexEnvfv(GLenum target, GLenum pname, const GLfloat *params);
-WINGDIAPI void APIENTRY glTexEnvi(GLenum target, GLenum pname, GLint param);
-WINGDIAPI void APIENTRY glTexEnviv(GLenum target, GLenum pname, const GLint *params);
-WINGDIAPI void APIENTRY glTexGend(GLenum coord, GLenum pname, GLdouble param);
-WINGDIAPI void APIENTRY glTexGendv(GLenum coord, GLenum pname, const GLdouble *params);
-WINGDIAPI void APIENTRY glTexGenf(GLenum coord, GLenum pname, GLfloat param);
-WINGDIAPI void APIENTRY glTexGenfv(GLenum coord, GLenum pname, const GLfloat *params);
-WINGDIAPI void APIENTRY glTexGeni(GLenum coord, GLenum pname, GLint param);
-WINGDIAPI void APIENTRY glTexGeniv(GLenum coord, GLenum pname, const GLint *params);
-WINGDIAPI void APIENTRY glTexImage1D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
-WINGDIAPI void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
-WINGDIAPI void APIENTRY glTexParameterf(GLenum target, GLenum pname, GLfloat param);
-WINGDIAPI void APIENTRY glTexParameterfv(GLenum target, GLenum pname, const GLfloat *params);
-WINGDIAPI void APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param);
-WINGDIAPI void APIENTRY glTexParameteriv(GLenum target, GLenum pname, const GLint *params);
-WINGDIAPI void APIENTRY glTexSubImage1D(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels);
-WINGDIAPI void APIENTRY glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
-WINGDIAPI void APIENTRY glTranslated(GLdouble x, GLdouble y, GLdouble z);
-WINGDIAPI void APIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z);
-WINGDIAPI void APIENTRY glVertex2d(GLdouble x, GLdouble y);
-WINGDIAPI void APIENTRY glVertex2dv(const GLdouble *v);
-WINGDIAPI void APIENTRY glVertex2f(GLfloat x, GLfloat y);
-WINGDIAPI void APIENTRY glVertex2fv(const GLfloat *v);
-WINGDIAPI void APIENTRY glVertex2i(GLint x, GLint y);
-WINGDIAPI void APIENTRY glVertex2iv(const GLint *v);
-WINGDIAPI void APIENTRY glVertex2s(GLshort x, GLshort y);
-WINGDIAPI void APIENTRY glVertex2sv(const GLshort *v);
-WINGDIAPI void APIENTRY glVertex3d(GLdouble x, GLdouble y, GLdouble z);
-WINGDIAPI void APIENTRY glVertex3dv(const GLdouble *v);
-WINGDIAPI void APIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z);
-WINGDIAPI void APIENTRY glVertex3fv(const GLfloat *v);
-WINGDIAPI void APIENTRY glVertex3i(GLint x, GLint y, GLint z);
-WINGDIAPI void APIENTRY glVertex3iv(const GLint *v);
-WINGDIAPI void APIENTRY glVertex3s(GLshort x, GLshort y, GLshort z);
-WINGDIAPI void APIENTRY glVertex3sv(const GLshort *v);
-WINGDIAPI void APIENTRY glVertex4d(GLdouble x, GLdouble y, GLdouble z, GLdouble w);
-WINGDIAPI void APIENTRY glVertex4dv(const GLdouble *v);
-WINGDIAPI void APIENTRY glVertex4f(GLfloat x, GLfloat y, GLfloat z, GLfloat w);
-WINGDIAPI void APIENTRY glVertex4fv(const GLfloat *v);
-WINGDIAPI void APIENTRY glVertex4i(GLint x, GLint y, GLint z, GLint w);
-WINGDIAPI void APIENTRY glVertex4iv(const GLint *v);
-WINGDIAPI void APIENTRY glVertex4s(GLshort x, GLshort y, GLshort z, GLshort w);
-WINGDIAPI void APIENTRY glVertex4sv(const GLshort *v);
-WINGDIAPI void APIENTRY glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
-WINGDIAPI void APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height);
-
-*/
diff --git a/src/libjin/Audio/SDL/je_sdl_audio.cpp b/src/libjin/Audio/SDL/je_sdl_audio.cpp
index 96df17f..c21d077 100644
--- a/src/libjin/Audio/SDL/je_sdl_audio.cpp
+++ b/src/libjin/Audio/SDL/je_sdl_audio.cpp
@@ -9,134 +9,137 @@
#include "je_sdl_audio.h"
#include "je_sdl_source.h"
+using namespace JinEngine::Math;
+
namespace JinEngine
{
namespace Audio
{
-
- using namespace JinEngine::Math;
-
- /* עcallbackƵ̵߳ */
- static void defaultCallback(void *userdata, Uint8 *stream, int size)
- {
- static SDLAudio* audio = static_cast<SDLAudio*>(userdata);
- if (!audio->goOnProcess())
- return;
- audio->lock();
- audio->processCommands();
- audio->processSources(stream, size);
- audio->processBuffer(stream, size);
- audio->unlock();
- }
-
- /*call only once*/ bool SDLAudio::initSystem(const SettingBase* s)
- {
- #if defined(jin_debug)
- Loghelper::log(Loglevel::LV_INFO, "Init AudioManager System");
- #endif
-
- if (SDL_Init(SDL_INIT_AUDIO) < 0)
- return false;
- SDL_AudioSpec spec;
- Setting* setting = (Setting*)s;
- if (setting == nullptr)
- return false;
-
- unsigned int samplerate = setting->samplerate;
- unsigned int samples = clamp<int>(setting->samples, 1, setting->samplerate);
-
- spec.freq = samplerate; // ÿsample,õ 11025, 22050, 44100 and 48000 Hz.
- spec.format = AUDIO_S16SYS; // signed 16-bit samples in native byte order
- spec.channels = SDLAUDIO_CHANNELS; //
- spec.samples = samples; // ÿβʱһã=setting->samplerateÿֻ1
- spec.userdata = this;
- spec.callback = defaultCallback;
-
- audioDevice = SDL_OpenAudioDevice(NULL, 0, &spec, NULL, 0);
- if (audioDevice == 0)
- return false;
- /* start audio */
- SDL_PauseAudioDevice(audioDevice, 0);
- return true;
- }
-
- /*call only once*/ void SDLAudio::quitSystem()
- {
- SDL_CloseAudio();
- }
-
- void SDLAudio::lock()
- {
- SDL_LockAudioDevice(audioDevice);
- }
-
- void SDLAudio::unlock()
- {
- SDL_UnlockAudioDevice(audioDevice);
- }
-
- bool SDLAudio::goOnProcess()
- {
- if (state == SDLAudio::State::STOP)
- {
- SDLSourceManager::get()->removeAllSource();
- pause();
- return false;
- }
- else if (state == SDLAudio::State::PAUSE)
- return false;
- else
- return true;
- }
-
- void SDLAudio::processCommands()
- {
- SDLSourceManager::get()->processCommands();
- }
-
- void SDLAudio::processSources(void* buffer, size_t len)
- {
- SDLSourceManager::get()->processSources(buffer, len);
- }
-
- void SDLAudio::processBuffer(void* buff, size_t len)
- {
- short* buffer = (short*)buff;
- int samples = (len / SDLAUDIO_BYTEDEPTH) >> 1; // ˫
- const char L = 0, R = 1;
- for (int i = 0; i < samples; ++i)
- {
- short* clip = buffer + (i << 1);
- clip[L] *= volume;
- clip[R] *= volume;
- }
- }
-
- void SDLAudio::play()
- {
- state = State::PLAY;
- }
-
- void SDLAudio::stop()
- {
- state = State::STOP;
- }
-
- void SDLAudio::pause()
- {
- state = State::PAUSE;
- }
-
- void SDLAudio::resume()
- {
- state = State::PLAY;
- }
-
- void SDLAudio::setVolume(float volume)
- {
- this->volume = clamp(volume, 0.0f, 1.0f);
- }
-
+ namespace SDL
+ {
+
+ /* עcallbackƵ̵߳ */
+ static void defaultCallback(void *userdata, Uint8 *stream, int size)
+ {
+ static SDLAudio* audio = static_cast<SDLAudio*>(userdata);
+ if (!audio->goOnProcess())
+ return;
+ audio->lock();
+ audio->processCommands();
+ audio->processSources(stream, size);
+ audio->processBuffer(stream, size);
+ audio->unlock();
+ }
+
+ /*call only once*/ bool SDLAudio::initSystem(const SettingBase* s)
+ {
+ jin_log_info("Initialize audio system.");
+
+ if (SDL_Init(SDL_INIT_AUDIO) < 0)
+ return false;
+
+ SDL_AudioSpec spec;
+ Setting* setting = (Setting*)s;
+ if (setting == nullptr)
+ return false;
+
+ unsigned int samplerate = setting->samplerate;
+ unsigned int samples = clamp<int>(setting->samples, 1, setting->samplerate);
+
+ spec.freq = samplerate; // ÿsample,õ 11025, 22050, 44100 and 48000 Hz.
+ spec.format = AUDIO_S16SYS; // signed 16-bit samples in native byte order
+ spec.channels = SDLAUDIO_CHANNELS; //
+ spec.samples = samples; // ÿβʱһã=setting->samplerateÿֻ1
+ spec.userdata = this;
+ spec.callback = defaultCallback;
+
+ audioDevice = SDL_OpenAudioDevice(NULL, 0, &spec, NULL, 0);
+ if (audioDevice == 0)
+ return false;
+ /* start audio */
+ SDL_PauseAudioDevice(audioDevice, 0);
+ return true;
+ }
+
+ /*call only once*/ void SDLAudio::quitSystem()
+ {
+ jin_log_info("Quit audio system.");
+ SDL_CloseAudio();
+ }
+
+ void SDLAudio::lock()
+ {
+ SDL_LockAudioDevice(audioDevice);
+ }
+
+ void SDLAudio::unlock()
+ {
+ SDL_UnlockAudioDevice(audioDevice);
+ }
+
+ bool SDLAudio::goOnProcess()
+ {
+ if (state == SDLAudio::State::STOP)
+ {
+ SDLSourceManager::get()->removeAllSource();
+ pause();
+ return false;
+ }
+ else if (state == SDLAudio::State::PAUSE)
+ return false;
+ else
+ return true;
+ }
+
+ void SDLAudio::processCommands()
+ {
+ SDLSourceManager::get()->processCommands();
+ }
+
+ void SDLAudio::processSources(void* buffer, size_t len)
+ {
+ SDLSourceManager::get()->processSources(buffer, len);
+ }
+
+ void SDLAudio::processBuffer(void* buff, size_t len)
+ {
+ short* buffer = (short*)buff;
+ int samples = (len / SDLAUDIO_BYTEDEPTH) >> 1; // ˫
+ const char L = 0, R = 1;
+ for (int i = 0; i < samples; ++i)
+ {
+ short* clip = buffer + (i << 1);
+ clip[L] *= volume;
+ clip[R] *= volume;
+ }
+ }
+
+ void SDLAudio::play()
+ {
+ state = State::PLAY;
+ }
+
+ void SDLAudio::stop()
+ {
+ state = State::STOP;
+ }
+
+ void SDLAudio::pause()
+ {
+ state = State::PAUSE;
+ }
+
+ void SDLAudio::resume()
+ {
+ state = State::PLAY;
+ }
+
+ void SDLAudio::setVolume(float volume)
+ {
+ this->volume = clamp(volume, 0.0f, 1.0f);
+ }
+
+ } // namespace SDL
} // namespace Audio
} // namespace JinEngine
diff --git a/src/libjin/Audio/SDL/je_sdl_audio.h b/src/libjin/Audio/SDL/je_sdl_audio.h
index 57fee5b..77162d4 100644
--- a/src/libjin/Audio/SDL/je_sdl_audio.h
+++ b/src/libjin/Audio/SDL/je_sdl_audio.h
@@ -1,5 +1,5 @@
-#ifndef __JE_AUDIO_SDL_H
-#define __JE_AUDIO_SDL_H
+#ifndef __JE_AUDIO_SDL_H__
+#define __JE_AUDIO_SDL_H__
#include "../../core/je_configuration.h"
#if defined(jin_audio) && (jin_audio == jin_audio_sdl)
@@ -13,123 +13,126 @@ namespace JinEngine
{
namespace Audio
{
-
- #define SDLAUDIO_BITDEPTH 16
- #define SDLAUDIO_BYTEDEPTH (SDLAUDIO_BITDEPTH >> 3)
- #define SDLAUDIO_CHANNELS 2
-
- ///
- /// Audio system SDL implementation.
- ///
- class SDLAudio : public AudioManager<SDLAudio>
- {
- public:
- ///
- /// SDL audio setting.
- ///
- struct Setting : SettingBase
- {
- public:
- int samplerate; // Ƶ
- int samples; // sample<=samplerate
- };
-
- ///
- /// Play all sources whose state is playing.
- ///
- void play() override;
-
- ///
- /// Stop and remove all sources from the queue.
- ///
- void stop() override;
-
- ///
- /// Pause audio.
- ///
- void pause() override;
-
- ///
- /// Resume audio.
- ///
- void resume() override;
-
- ///
- /// Set global audio volume.
- ///
- void setVolume(float volume) override;
-
- ///
- /// Process all commands in the queue.
- ///
- void processCommands();
-
- ///
- /// Process all sources.
- ///
- /// @param buffer Source buffer.
- /// @param len Source length.
- ///
- void processSources(void* buffer, size_t len);
-
- ///
- /// Process audio buffer.
- ///
- /// @param buffer Audio stream buffer.
- /// @param len Length of stream buffer.
- ///
- void processBuffer(void* buffer, size_t len);
-
- ///
- /// Goon process.
- ///
- /// @return True if sucessful, otherwise return false.
- ///
- bool goOnProcess();
-
- ///
- /// Lock audio device.
- ///
- void lock();
-
- ///
- /// Unlock audio device.
- ///
- void unlock();
-
- private:
- singleton(SDLAudio);
-
- ///
- /// SDL audio constructor.
- ///
- SDLAudio() {};
-
- ///
- /// SDL audio destructor.
- ///
- ~SDLAudio() {};
-
- ///
- /// Initialize audio system.
- ///
- /// @param setting Audio setting.
- ///
- bool initSystem(const SettingBase* setting) override;
-
- ///
- /// Quit audio system.
- ///
- void quitSystem() override;
-
- // Audio device id.
- unsigned int audioDevice;
-
- };
-
+ namespace SDL
+ {
+
+#define SDLAUDIO_BITDEPTH 16
+#define SDLAUDIO_BYTEDEPTH (SDLAUDIO_BITDEPTH >> 3)
+#define SDLAUDIO_CHANNELS 2
+
+ ///
+ /// Audio system SDL implementation.
+ ///
+ class SDLAudio : public AudioManager<SDLAudio>
+ {
+ public:
+ ///
+ /// SDL audio setting.
+ ///
+ struct Setting : SettingBase
+ {
+ public:
+ int samplerate; // Ƶ
+ int samples; // sample<=samplerate
+ };
+
+ ///
+ /// Play all sources whose state is playing.
+ ///
+ void play() override;
+
+ ///
+ /// Stop and remove all sources from the queue.
+ ///
+ void stop() override;
+
+ ///
+ /// Pause audio.
+ ///
+ void pause() override;
+
+ ///
+ /// Resume audio.
+ ///
+ void resume() override;
+
+ ///
+ /// Set global audio volume.
+ ///
+ void setVolume(float volume) override;
+
+ ///
+ /// Process all commands in the queue.
+ ///
+ void processCommands();
+
+ ///
+ /// Process all sources.
+ ///
+ /// @param buffer Source buffer.
+ /// @param len Source length.
+ ///
+ void processSources(void* buffer, size_t len);
+
+ ///
+ /// Process audio buffer.
+ ///
+ /// @param buffer Audio stream buffer.
+ /// @param len Length of stream buffer.
+ ///
+ void processBuffer(void* buffer, size_t len);
+
+ ///
+ /// Goon process.
+ ///
+ /// @return True if sucessful, otherwise return false.
+ ///
+ bool goOnProcess();
+
+ ///
+ /// Lock audio device.
+ ///
+ void lock();
+
+ ///
+ /// Unlock audio device.
+ ///
+ void unlock();
+
+ private:
+ singleton(SDLAudio);
+
+ ///
+ /// SDL audio constructor.
+ ///
+ SDLAudio() {};
+
+ ///
+ /// SDL audio destructor.
+ ///
+ ~SDLAudio() {};
+
+ ///
+ /// Initialize audio system.
+ ///
+ /// @param setting Audio setting.
+ ///
+ bool initSystem(const SettingBase* setting) override;
+
+ ///
+ /// Quit audio system.
+ ///
+ void quitSystem() override;
+
+ // Audio device id.
+ unsigned int audioDevice;
+
+ };
+
+ } // namespace SDL
} // namespace Audio
} // namespace JinEngine
#endif // (jin_audio) && (jin_audio == jin_audio_sdl)
-#endif // __JE_AUDIO_SDL_H \ No newline at end of file
+#endif // __JE_AUDIO_SDL_H__ \ No newline at end of file
diff --git a/src/libjin/Audio/SDL/je_sdl_source.cpp b/src/libjin/Audio/SDL/je_sdl_source.cpp
index 72607dd..207aa86 100644
--- a/src/libjin/Audio/SDL/je_sdl_source.cpp
+++ b/src/libjin/Audio/SDL/je_sdl_source.cpp
@@ -6,168 +6,172 @@
#include <climits>
#define STB_VORBIS_HEADER_ONLY
-#include "../../3rdparty/stb/stb_vorbis.c"
+#include "stb/stb_vorbis.c"
+#include "wav/wav.h"
+
#include "../../math/je_math.h"
#include "../../utils/je_macros.h"
-#include "../../3rdparty/wav/wav.h"
#include "je_sdl_audio.h"
#include "je_sdl_source.h"
+using namespace JinEngine::Math;
+
namespace JinEngine
{
namespace Audio
{
-
- using namespace JinEngine::Math;
-
- #define BITS 8
-
- typedef struct SDLSourceCommand
- {
- typedef enum Action
- {
- Nothing = 0,
- Play,
- Stop,
- Pause,
- Resume,
- Rewind,
- SetVolume,
- SetLoop,
- SetRate,
- };
- Action action;
- union {
- int _integer;
- float _float;
- bool _boolean;
- const char* _string;
- } parameter;
-
- SDLSource* source;
- };
-
- typedef enum CHANNEL
- {
- MONO = 1, //
- STEREO = 2, //
- };
-
- typedef /*mask*/ enum STATUS
- {
- PLAYING = 1,
- PAUSED = 2,
- STOPPED = 4
- };
-
- #define Command SDLSourceCommand
- #define Action Command::Action
- #define Manager SDLSourceManager
-
- ///*class member*/ std::queue<Command*> Manager::commands;
- ///*class member*/ std::stack<Command*> Manager::commandsPool;
- ///*class member*/ std::vector<SDLSource*> Manager::sources;
- /*class member*/ Manager* Manager::manager = nullptr;
-
- SDLSource* SDLSource::createSource(const char* file)
- {
- std::ifstream fs;
- fs.open(file, std::ios::binary);
- if (!fs.is_open())
- {
- fs.close();
- return nullptr;
- }
- fs.seekg(0,std::ios::end);
- int size = fs.tellg();
- fs.seekg(0, std::ios::beg);
- char* buffer = (char*)malloc(size);
- memset(buffer, 0, size);
- fs.read(buffer, size);
- fs.close();
- SDLSource* source = createSource(buffer, size);
- free(buffer);
- return source;
- }
-
- SDLSource* SDLSource::createSource(void* mem, size_t size)
- {
- if (mem == nullptr)
- return nullptr;
- SDLSource* source = new SDLSource();
- try
- {
- SourceType format = getType(mem, size);
- switch (format)
- {
- case OGG: source->decode_ogg(mem, size); break;
- case WAV: source->decode_wav(mem, size); break;
- }
- }
- catch (SourceException& exp)
- {
- delete source;
- return nullptr;
- };
- return source;
- }
-
- SDLSource::SDLSource()
- {
- memset(&status, 0, sizeof(status));
- memset(&raw, 0, sizeof(raw));
- status.volume = 1;
- }
-
- SDLSource::~SDLSource()
- {
- delete raw.data;
- raw.end = 0;
- raw.data = 0;
- }
-
- void SDLSource::decode_wav(void* mem, int size)
- {
- wav_t wav;
- if (wav_read(&wav, mem, size) == 0)
- {
- raw.data = wav.data;
- raw.length = wav.length * wav.channels * wav.bitdepth / 8;
- raw.channels = clamp<int>(wav.channels, CHANNEL::MONO, CHANNEL::STEREO);
- raw.end = (char*)raw.data + raw.length;
- raw.samplerate = wav.samplerate;
- raw.bitdepth = wav.bitdepth;
- raw.samples = wav.length;
- }
- else
- throw SourceException();
- }
-
- void SDLSource::decode_ogg(void* _mem, int size)
- {
- unsigned char* mem = (unsigned char*)_mem;
- int channels;
- int samplerate;
- short* data = (short*)raw.data;
- int samples = stb_vorbis_decode_memory(
- mem,
- size,
- &channels,
- &samplerate,
- &data
- );
- const int bitdepth = sizeof(short) * BITS;
- raw.channels = channels;
- raw.samplerate = samplerate;
- raw.data = data;
- raw.samples = samples; // һsample
- raw.length = samples * channels * sizeof(short); // һsample
- raw.bitdepth = bitdepth;
- raw.end = (char*)data + raw.length;
- }
-
- #define ActionNone(T)\
+ namespace SDL
+ {
+
+
+#define BITS 8
+
+ typedef struct SDLSourceCommand
+ {
+ typedef enum Action
+ {
+ Nothing = 0,
+ Play,
+ Stop,
+ Pause,
+ Resume,
+ Rewind,
+ SetVolume,
+ SetLoop,
+ SetRate,
+ };
+ Action action;
+ union {
+ int _integer;
+ float _float;
+ bool _boolean;
+ const char* _string;
+ } parameter;
+
+ SDLSource* source;
+ };
+
+ typedef enum CHANNEL
+ {
+ MONO = 1, //
+ STEREO = 2, //
+ };
+
+ typedef /*mask*/ enum STATUS
+ {
+ PLAYING = 1,
+ PAUSED = 2,
+ STOPPED = 4
+ };
+
+#define Command SDLSourceCommand
+#define Action Command::Action
+#define Manager SDLSourceManager
+
+ ///*class member*/ std::queue<Command*> Manager::commands;
+ ///*class member*/ std::stack<Command*> Manager::commandsPool;
+ ///*class member*/ std::vector<SDLSource*> Manager::sources;
+ /*class member*/ Manager* Manager::manager = nullptr;
+
+ SDLSource* SDLSource::createSource(const char* file)
+ {
+ std::ifstream fs;
+ fs.open(file, std::ios::binary);
+ if (!fs.is_open())
+ {
+ fs.close();
+ return nullptr;
+ }
+ fs.seekg(0, std::ios::end);
+ int size = fs.tellg();
+ fs.seekg(0, std::ios::beg);
+ char* buffer = (char*)malloc(size);
+ memset(buffer, 0, size);
+ fs.read(buffer, size);
+ fs.close();
+ SDLSource* source = createSource(buffer, size);
+ free(buffer);
+ return source;
+ }
+
+ SDLSource* SDLSource::createSource(void* mem, size_t size)
+ {
+ if (mem == nullptr)
+ return nullptr;
+ SDLSource* source = new SDLSource();
+ try
+ {
+ SourceType format = getType(mem, size);
+ switch (format)
+ {
+ case OGG: source->decode_ogg(mem, size); break;
+ case WAV: source->decode_wav(mem, size); break;
+ }
+ }
+ catch (SourceException& exp)
+ {
+ delete source;
+ return nullptr;
+ };
+ return source;
+ }
+
+ SDLSource::SDLSource()
+ {
+ memset(&status, 0, sizeof(status));
+ memset(&raw, 0, sizeof(raw));
+ status.volume = 1;
+ }
+
+ SDLSource::~SDLSource()
+ {
+ delete raw.data;
+ raw.end = 0;
+ raw.data = 0;
+ }
+
+ void SDLSource::decode_wav(void* mem, int size)
+ {
+ wav_t wav;
+ if (wav_read(&wav, mem, size) == 0)
+ {
+ raw.data = wav.data;
+ raw.length = wav.length * wav.channels * wav.bitdepth / 8;
+ raw.channels = clamp<int>(wav.channels, CHANNEL::MONO, CHANNEL::STEREO);
+ raw.end = (char*)raw.data + raw.length;
+ raw.samplerate = wav.samplerate;
+ raw.bitdepth = wav.bitdepth;
+ raw.samples = wav.length;
+ }
+ else
+ throw SourceException();
+ }
+
+ void SDLSource::decode_ogg(void* _mem, int size)
+ {
+ unsigned char* mem = (unsigned char*)_mem;
+ int channels;
+ int samplerate;
+ short* data = (short*)raw.data;
+ int samples = stb_vorbis_decode_memory(
+ mem,
+ size,
+ &channels,
+ &samplerate,
+ &data
+ );
+ const int bitdepth = sizeof(short) * BITS;
+ raw.channels = channels;
+ raw.samplerate = samplerate;
+ raw.data = data;
+ raw.samples = samples; // һsample
+ raw.length = samples * channels * sizeof(short); // һsample
+ raw.bitdepth = bitdepth;
+ raw.end = (char*)data + raw.length;
+ }
+
+#define ActionNone(T)\
do{\
Command* cmd = Manager::get()->getCommand();\
cmd->action = Action::T; \
@@ -175,7 +179,7 @@ namespace JinEngine
Manager::get()->pushCommand(cmd); \
} while (0)
- #define ActionArg(T, ARGT, ARG)\
+#define ActionArg(T, ARGT, ARG)\
do{\
Command* cmd = Manager::get()->getCommand();\
cmd->action = Action::T; \
@@ -184,217 +188,217 @@ namespace JinEngine
Manager::get()->pushCommand(cmd); \
}while(0)
- #define ActionInt(T, INT) ActionArg(T, _integer, INT)
- #define ActionFloat(T, FLT) ActionArg(T, _float, FLT)
- #define ActionString(T, STR) ActionArg(T, _string, STR)
- #define ActionBool(T, BOL) ActionArg(T, _boolean, BOL)
-
- void SDLSource::play()
- {
- ActionNone(Play);
- }
-
- void SDLSource::stop()
- {
- ActionNone(Stop);
- }
-
- void SDLSource::pause()
- {
- ActionNone(Pause);
- }
-
- void SDLSource::resume()
- {
- ActionNone(Resume);
- }
-
- void SDLSource::rewind()
- {
- ActionNone(Rewind);
- }
-
- inline bool SDLSource::isStopped() const
- {
- return is(STOPPED);
- }
-
- bool SDLSource::isPaused() const
- {
- return is(PAUSED);
- }
-
- void SDLSource::setPitch(float pitch)
- {
- }
-
- void SDLSource::setVolume(float volume)
- {
- ActionFloat(SetVolume, clamp(volume, 0.0f, 1.0f));
- }
-
- void SDLSource::setLoop(bool loop)
- {
- ActionBool(SetLoop, loop);
- }
-
- void SDLSource::setRate(float rate)
- {
- ActionFloat(SetRate, rate);
- }
-
- inline void SDLSource::handle(
- SDLSourceManager* manager,
- SDLSourceCommand* cmd
- )
- {
- switch (cmd->action)
- {
- case Command::Action::Play:
- manager->removeSource(this);
- manager->pushSource(this);
- status.state = PLAYING;
- status.pos = 0; // rewind
- break;
- case Command::Action::Stop:
- manager->removeSource(this);
- status.state = STOPPED;
- status.pos = 0; // rewind
- break;
- case Command::Action::Pause:
- manager->removeSource(this);
- status.state = PAUSED;
- break;
- case Command::Action::Resume:
- manager->removeSource(this);
- manager->pushSource(this);
- status.state = PLAYING;
- break;
- case Command::Action::Rewind:
- status.state = PLAYING;
- status.pos = 0;
- break;
- case Command::Action::SetVolume:
- status.volume = cmd->parameter._float;
- break;
- case Command::Action::SetLoop:
- status.loop = cmd->parameter._boolean;
- break;
- }
- }
-
- inline void SDLSource::process(void* buf, size_t size)
- {
- short* buffer = (short*)buf; // AUDIO_S16SYS
- int samples = (size / SDLAUDIO_BYTEDEPTH) >> 1; // ˫
- const char L = 0, R = 1;
- for (int i = 0; i < samples; ++i)
- {
- char* source = (char*)raw.data + status.pos * (raw.bitdepth / 8) * raw.channels;
- short l = 0;
- short r = 0;
- if (raw.bitdepth == 16)
- {
- l = ((short*)source)[L] * status.volume;
- r = ((short*)source)[L + raw.channels - 1] * status.volume;
- }
- else if (raw.bitdepth == 8)
- {
- l = source[L] << 8; // << 8 Ŵ16bits
- r = source[L + raw.channels - 1] << 8;
- }
- short* sample = buffer + (i << 1);
- sample[L] = clamp(sample[L] + l, SHRT_MIN, SHRT_MAX); //
- sample[R] = clamp(sample[R] + r, SHRT_MIN, SHRT_MAX); //
- ++status.pos;
- if (status.pos > raw.samples && status.loop)
- status.pos = 0; // rewind
- else if (status.pos > raw.samples && !status.loop)
- break;
- }
- }
-
- Manager* Manager::get()
- {
- return (manager == nullptr ? manager = new Manager() : manager);
- }
-
- void Manager::processCommands()
- {
- Command* cmd = nullptr;
- SDLSource* source = nullptr;
- while (!commands.empty())
- {
- cmd = commands.front();
- if (cmd != nullptr)
- {
- source = cmd->source;
- if (source != nullptr)
- source->handle(manager, cmd);
- }
- commands.pop();
- }
- }
-
- /* AUDIO_S16SYS[size>>1] buffer */
- void Manager::processSources(void* buf, size_t size)
- {
- /* clear render buffer */
- memset(buf, 0, size);
- SDLSource* src = nullptr;
- std::vector<SDLSource*>::iterator it = sources.begin();
- for (; it != sources.end();)
- {
- src = *it;
- if (src != nullptr)
- src->process(buf, size);
- ++it;
- }
- }
-
- void Manager::removeSource(SDLSource* source)
- {
- std::vector<SDLSource*>::iterator it = sources.begin();
- for (it = sources.begin(); it != sources.end(); )
- {
- if (*it == source)
- {
- it = sources.erase(it);
- return;
- }
- ++it;
- }
- }
-
- void Manager::removeAllSource()
- {
- sources.clear();
- }
-
- void Manager::pushSource(SDLSource* source)
- {
- if(source != nullptr)
- sources.push_back(source);
- }
-
- void Manager::pushCommand(SDLSourceCommand* cmd)
- {
- commands.push(cmd);
- }
-
- Command* Manager::getCommand()
- {
- if (!commandsPool.empty())
- {
- Command* cmd = commandsPool.top();
- commandsPool.pop();
- return cmd;
- }
- return new Command();
- }
-
-
+#define ActionInt(T, INT) ActionArg(T, _integer, INT)
+#define ActionFloat(T, FLT) ActionArg(T, _float, FLT)
+#define ActionString(T, STR) ActionArg(T, _string, STR)
+#define ActionBool(T, BOL) ActionArg(T, _boolean, BOL)
+
+ void SDLSource::play()
+ {
+ ActionNone(Play);
+ }
+
+ void SDLSource::stop()
+ {
+ ActionNone(Stop);
+ }
+
+ void SDLSource::pause()
+ {
+ ActionNone(Pause);
+ }
+
+ void SDLSource::resume()
+ {
+ ActionNone(Resume);
+ }
+
+ void SDLSource::rewind()
+ {
+ ActionNone(Rewind);
+ }
+
+ inline bool SDLSource::isStopped() const
+ {
+ return is(STOPPED);
+ }
+
+ bool SDLSource::isPaused() const
+ {
+ return is(PAUSED);
+ }
+
+ void SDLSource::setPitch(float pitch)
+ {
+ }
+
+ void SDLSource::setVolume(float volume)
+ {
+ ActionFloat(SetVolume, clamp(volume, 0.0f, 1.0f));
+ }
+
+ void SDLSource::setLoop(bool loop)
+ {
+ ActionBool(SetLoop, loop);
+ }
+
+ void SDLSource::setRate(float rate)
+ {
+ ActionFloat(SetRate, rate);
+ }
+
+ inline void SDLSource::handle(
+ SDLSourceManager* manager,
+ SDLSourceCommand* cmd
+ )
+ {
+ switch (cmd->action)
+ {
+ case Command::Action::Play:
+ manager->removeSource(this);
+ manager->pushSource(this);
+ status.state = PLAYING;
+ status.pos = 0; // rewind
+ break;
+ case Command::Action::Stop:
+ manager->removeSource(this);
+ status.state = STOPPED;
+ status.pos = 0; // rewind
+ break;
+ case Command::Action::Pause:
+ manager->removeSource(this);
+ status.state = PAUSED;
+ break;
+ case Command::Action::Resume:
+ manager->removeSource(this);
+ manager->pushSource(this);
+ status.state = PLAYING;
+ break;
+ case Command::Action::Rewind:
+ status.state = PLAYING;
+ status.pos = 0;
+ break;
+ case Command::Action::SetVolume:
+ status.volume = cmd->parameter._float;
+ break;
+ case Command::Action::SetLoop:
+ status.loop = cmd->parameter._boolean;
+ break;
+ }
+ }
+
+ inline void SDLSource::process(void* buf, size_t size)
+ {
+ short* buffer = (short*)buf; // AUDIO_S16SYS
+ int samples = (size / SDLAUDIO_BYTEDEPTH) >> 1; // ˫
+ const char L = 0, R = 1;
+ for (int i = 0; i < samples; ++i)
+ {
+ char* source = (char*)raw.data + status.pos * (raw.bitdepth / 8) * raw.channels;
+ short l = 0;
+ short r = 0;
+ if (raw.bitdepth == 16)
+ {
+ l = ((short*)source)[L] * status.volume;
+ r = ((short*)source)[L + raw.channels - 1] * status.volume;
+ }
+ else if (raw.bitdepth == 8)
+ {
+ l = source[L] << 8; // << 8 Ŵ16bits
+ r = source[L + raw.channels - 1] << 8;
+ }
+ short* sample = buffer + (i << 1);
+ sample[L] = clamp(sample[L] + l, SHRT_MIN, SHRT_MAX); //
+ sample[R] = clamp(sample[R] + r, SHRT_MIN, SHRT_MAX); //
+ ++status.pos;
+ if (status.pos > raw.samples && status.loop)
+ status.pos = 0; // rewind
+ else if (status.pos > raw.samples && !status.loop)
+ break;
+ }
+ }
+
+ Manager* Manager::get()
+ {
+ return (manager == nullptr ? manager = new Manager() : manager);
+ }
+
+ void Manager::processCommands()
+ {
+ Command* cmd = nullptr;
+ SDLSource* source = nullptr;
+ while (!commands.empty())
+ {
+ cmd = commands.front();
+ if (cmd != nullptr)
+ {
+ source = cmd->source;
+ if (source != nullptr)
+ source->handle(manager, cmd);
+ }
+ commands.pop();
+ }
+ }
+
+ /* AUDIO_S16SYS[size>>1] buffer */
+ void Manager::processSources(void* buf, size_t size)
+ {
+ /* clear render buffer */
+ memset(buf, 0, size);
+ SDLSource* src = nullptr;
+ std::vector<SDLSource*>::iterator it = sources.begin();
+ for (; it != sources.end();)
+ {
+ src = *it;
+ if (src != nullptr)
+ src->process(buf, size);
+ ++it;
+ }
+ }
+
+ void Manager::removeSource(SDLSource* source)
+ {
+ std::vector<SDLSource*>::iterator it = sources.begin();
+ for (it = sources.begin(); it != sources.end(); )
+ {
+ if (*it == source)
+ {
+ it = sources.erase(it);
+ return;
+ }
+ ++it;
+ }
+ }
+
+ void Manager::removeAllSource()
+ {
+ sources.clear();
+ }
+
+ void Manager::pushSource(SDLSource* source)
+ {
+ if (source != nullptr)
+ sources.push_back(source);
+ }
+
+ void Manager::pushCommand(SDLSourceCommand* cmd)
+ {
+ commands.push(cmd);
+ }
+
+ Command* Manager::getCommand()
+ {
+ if (!commandsPool.empty())
+ {
+ Command* cmd = commandsPool.top();
+ commandsPool.pop();
+ return cmd;
+ }
+ return new Command();
+ }
+
+ } // namespace SDL
} // namespace Audio
} // namespace JinEngine
-#endif // (jin_audio) && (jin_audio == jin_audio_sdl)
+#endif // (jin_audio) && (jin_audio == jin_audio_sdl) \ No newline at end of file
diff --git a/src/libjin/Audio/SDL/je_sdl_source.h b/src/libjin/Audio/SDL/je_sdl_source.h
index 78cae80..bbc8c7a 100644
--- a/src/libjin/Audio/SDL/je_sdl_source.h
+++ b/src/libjin/Audio/SDL/je_sdl_source.h
@@ -1,5 +1,5 @@
-#ifndef __JE_SOURCE_SDL_H
-#define __JE_SOURCE_SDL_H
+#ifndef __JE_SOURCE_SDL_H__
+#define __JE_SOURCE_SDL_H__
#include "../../core/je_configuration.h"
#if defined(jin_audio) && (jin_audio == jin_audio_sdl)
@@ -14,256 +14,259 @@ namespace JinEngine
{
namespace Audio
{
+ namespace SDL
+ {
- typedef struct SDLSourceCommand;
+ typedef struct SDLSourceCommand;
- class SDLSourceManager;
+ class SDLSourceManager;
- ///
- /// Audio source SDL implementation.
- ///
- class SDLSource : public Source
- {
- public:
///
- /// Create source from raw source data file.
+ /// Audio source SDL implementation.
///
- /// @param file Audio source file.
- /// @return Return source if create successful, otherwise return null.
- ///
- static SDLSource* createSource(const char* file);
-
- ///
- /// Create source from raw source data.
- ///
- /// @param mem Source data.
- /// @param size Source data size.
- /// @return Return source if create successful, otherwise return null.
- ///
- static SDLSource* createSource(void* mem, size_t size);
-
- ///
- /// Source destructor.
- ///
- ~SDLSource();
-
- ///
- /// Play source.
- ///
- void play() override;
-
- ///
- /// Stop source.
- ///
- void stop() override;
-
- ///
- /// Pause source.
- ///
- void pause() override;
-
- ///
- /// Resume source.
- ///
- void resume() override;
-
- ///
- /// Rewind source.
- ///
- void rewind() override;
-
- ///
- /// Return if the source is stopped.
- ///
- /// @return True if the source is stopped, otherwise return false.
- ///
- bool isStopped() const override;
-
- ///
- /// Return if the source is paused.
- ///
- /// @return True if the source is paused(, otherwise return false.
- ///
- bool isPaused() const override;
-
- ///
- /// Set pitch.
- ///
- /// @param pitch Pitch of source.
- ///
- void setPitch(float pitch) override;
-
- ///
- /// Set volume.
- ///
- /// @param volume Volume of source.
- ///
- void setVolume(float volume) override;
-
- ///
- /// Set source loop.
- ///
- /// @param loop Looping or not.
- ///
- void setLoop(bool loop) override;
-
- ///
- /// Set source rate.
- ///
- /// @param rate Rate of source.
- ///
- void setRate(float rate) override;
-
- ///
- /// Handle a specific command.
- ///
- /// @param manager Audio manager.
- /// @param cmd Source commad.
- ///
- inline void handle(SDLSourceManager* manager, SDLSourceCommand* cmd);
-
- ///
- /// Process decoded source data.
- ///
- /// @param buffer Source data.
- /// @param size Data size.
- ///
- inline void process(void* buffer, size_t size);
-
- protected:
- ///
- /// Source constructor.
- ///
- SDLSource();
-
- ///
- /// Decode wav file.
- ///
- /// @param mem Wav file data.
- /// @param size Wav data size.
- ///
- void decode_wav(void* mem, int size);
+ class SDLSource : public Source
+ {
+ public:
+ ///
+ /// Create source from raw source data file.
+ ///
+ /// @param file Audio source file.
+ /// @return Return source if create successful, otherwise return null.
+ ///
+ static SDLSource* createSource(const char* file);
+
+ ///
+ /// Create source from raw source data.
+ ///
+ /// @param mem Source data.
+ /// @param size Source data size.
+ /// @return Return source if create successful, otherwise return null.
+ ///
+ static SDLSource* createSource(void* mem, size_t size);
+
+ ///
+ /// Source destructor.
+ ///
+ ~SDLSource();
+
+ ///
+ /// Play source.
+ ///
+ void play() override;
+
+ ///
+ /// Stop source.
+ ///
+ void stop() override;
+
+ ///
+ /// Pause source.
+ ///
+ void pause() override;
+
+ ///
+ /// Resume source.
+ ///
+ void resume() override;
+
+ ///
+ /// Rewind source.
+ ///
+ void rewind() override;
+
+ ///
+ /// Return if the source is stopped.
+ ///
+ /// @return True if the source is stopped, otherwise return false.
+ ///
+ bool isStopped() const override;
+
+ ///
+ /// Return if the source is paused.
+ ///
+ /// @return True if the source is paused(, otherwise return false.
+ ///
+ bool isPaused() const override;
+
+ ///
+ /// Set pitch.
+ ///
+ /// @param pitch Pitch of source.
+ ///
+ void setPitch(float pitch) override;
+
+ ///
+ /// Set volume.
+ ///
+ /// @param volume Volume of source.
+ ///
+ void setVolume(float volume) override;
+
+ ///
+ /// Set source loop.
+ ///
+ /// @param loop Looping or not.
+ ///
+ void setLoop(bool loop) override;
+
+ ///
+ /// Set source rate.
+ ///
+ /// @param rate Rate of source.
+ ///
+ void setRate(float rate) override;
+
+ ///
+ /// Handle a specific command.
+ ///
+ /// @param manager Audio manager.
+ /// @param cmd Source commad.
+ ///
+ inline void handle(SDLSourceManager* manager, SDLSourceCommand* cmd);
+
+ ///
+ /// Process decoded source data.
+ ///
+ /// @param buffer Source data.
+ /// @param size Data size.
+ ///
+ inline void process(void* buffer, size_t size);
+
+ protected:
+ ///
+ /// Source constructor.
+ ///
+ SDLSource();
+
+ ///
+ /// Decode wav file.
+ ///
+ /// @param mem Wav file data.
+ /// @param size Wav data size.
+ ///
+ void decode_wav(void* mem, int size);
+
+ ///
+ /// Decode ogg file.
+ ///
+ /// @param mem ogg file data.
+ /// @param size ogg data size.
+ ///
+ void decode_ogg(void* mem, int size);
+
+ ///
+ /// Check source state.
+ ///
+ /// @param state State to be checked.
+ /// @return True if state is given state, otherwise return false.
+ ///
+ inline bool is(int state) const
+ {
+ return (status.state & state) == state;
+ }
+
+ // Source data.
+ struct {
+ const void* data; // Ƶ
+ int length; // dataֽڳ
+ const void* end; // dataβ = (unsigned char*)data + size
+ int samplerate; // Ƶ
+ unsigned char bitdepth; // ÿsampleıس
+ int samples; // sample = size / (bitdepth / 8)
+ unsigned char channels; // channel1(mono)2(stereo)
+ } raw;
+ // Procedure controller variable.
+ struct {
+ int pos; // ǰŵsample
+ int pitch; // pitch
+ int state; // ǰ״̬
+ bool loop; // loop or not
+ float volume; //
+ } status;
+
+ };
///
- /// Decode ogg file.
- ///
- /// @param mem ogg file data.
- /// @param size ogg data size.
+ /// Source manager.
///
- void decode_ogg(void* mem, int size);
-
- ///
- /// Check source state.
- ///
- /// @param state State to be checked.
- /// @return True if state is given state, otherwise return false.
- ///
- inline bool is(int state) const
- {
- return (status.state & state) == state;
- }
-
- // Source data.
- struct{
- const void* data; // Ƶ
- int length; // dataֽڳ
- const void* end; // dataβ = (unsigned char*)data + size
- int samplerate; // Ƶ
- unsigned char bitdepth; // ÿsampleıس
- int samples; // sample = size / (bitdepth / 8)
- unsigned char channels; // channel1(mono)2(stereo)
- } raw;
- // Procedure controller variable.
- struct{
- int pos; // ǰŵsample
- int pitch; // pitch
- int state; // ǰ״̬
- bool loop; // loop or not
- float volume; //
- } status;
-
- };
-
- ///
- /// Source manager.
- ///
- class SDLSourceManager
- {
- public:
- ///
- /// Get manager singleton.
- ///
- /// @return Singleton of SDL source manager.
- ///
- static SDLSourceManager* get();
-
- ///
- /// Process commands.
- ///
- void processCommands();
-
- ///
- /// Process sources.
- ///
- /// @param buffer Source data.
- /// @param size Size of source data.
- ///
- void processSources(void* buffer, size_t size);
-
- ///
- /// Clear source queue.
- ///
- /// This function will stop all sources.
- ///
- void removeAllSource();
-
- ///
- /// Remove specific source.
- ///
- /// @param source SDL audio source.
- ///
- void removeSource(SDLSource* source);
-
- ///
- /// Push specific source into queue.
- ///
- /// @param source SDL audio source.
- ///
- void pushSource(SDLSource* source);
-
- ///
- /// Get command from queue.
- ///
- /// @return Command at first place.
- ///
- SDLSourceCommand* getCommand();
-
- ///
- /// Push command.
- ///
- /// @param cmd Spcific command.
- ///
- void pushCommand(SDLSourceCommand* cmd);
-
- private:
- std::queue<SDLSourceCommand*> commands;
- std::stack<SDLSourceCommand*> commandsPool;
- std::vector<SDLSource*> sources; // processing sources
- static SDLSourceManager* manager;
-
- };
-
- class SourceException : public std::exception
- {
- const char* what() const throw ()
- {
- return "Load Source Exception";
- }
- };
-
+ class SDLSourceManager
+ {
+ public:
+ ///
+ /// Get manager singleton.
+ ///
+ /// @return Singleton of SDL source manager.
+ ///
+ static SDLSourceManager* get();
+
+ ///
+ /// Process commands.
+ ///
+ void processCommands();
+
+ ///
+ /// Process sources.
+ ///
+ /// @param buffer Source data.
+ /// @param size Size of source data.
+ ///
+ void processSources(void* buffer, size_t size);
+
+ ///
+ /// Clear source queue.
+ ///
+ /// This function will stop all sources.
+ ///
+ void removeAllSource();
+
+ ///
+ /// Remove specific source.
+ ///
+ /// @param source SDL audio source.
+ ///
+ void removeSource(SDLSource* source);
+
+ ///
+ /// Push specific source into queue.
+ ///
+ /// @param source SDL audio source.
+ ///
+ void pushSource(SDLSource* source);
+
+ ///
+ /// Get command from queue.
+ ///
+ /// @return Command at first place.
+ ///
+ SDLSourceCommand* getCommand();
+
+ ///
+ /// Push command.
+ ///
+ /// @param cmd Spcific command.
+ ///
+ void pushCommand(SDLSourceCommand* cmd);
+
+ private:
+ std::queue<SDLSourceCommand*> commands;
+ std::stack<SDLSourceCommand*> commandsPool;
+ std::vector<SDLSource*> sources; // processing sources
+ static SDLSourceManager* manager;
+
+ };
+
+ class SourceException : public std::exception
+ {
+ const char* what() const throw ()
+ {
+ return "Load Source Exception";
+ }
+ };
+
+ } // namespace SDL
} // namespace Audio
} // namespace JinEngine
#endif // (jin_audio) && (jin_audio == jin_audio_sdl)
-#endif // __JE_SOURCE_SDL_H \ No newline at end of file
+#endif // __JE_SOURCE_SDL_H__ \ No newline at end of file
diff --git a/src/libjin/Audio/je_audio_manager.h b/src/libjin/Audio/je_audio_manager.h
index 00b531a..120d38e 100644
--- a/src/libjin/Audio/je_audio_manager.h
+++ b/src/libjin/Audio/je_audio_manager.h
@@ -1,5 +1,5 @@
-#ifndef __JE_AUDIO_H
-#define __JE_AUDIO_H
+#ifndef __JE_AUDIO_H__
+#define __JE_AUDIO_H__
#include "../core/je_configuration.h"
#if defined(jin_audio)
@@ -84,4 +84,4 @@ namespace JinEngine
#endif // jin_audio
-#endif // __JE_AUDIO_H \ No newline at end of file
+#endif // __JE_AUDIO_H__ \ No newline at end of file
diff --git a/src/libjin/Audio/je_source.h b/src/libjin/Audio/je_source.h
index 519d39f..f60daf9 100644
--- a/src/libjin/Audio/je_source.h
+++ b/src/libjin/Audio/je_source.h
@@ -1,5 +1,5 @@
-#ifndef __JE_AUDIO_SOURCE_H
-#define __JE_AUDIO_SOURCE_H
+#ifndef __JE_AUDIO_SOURCE_H__
+#define __JE_AUDIO_SOURCE_H__
#include "../core/je_configuration.h"
#if defined(jin_audio)
@@ -113,4 +113,4 @@ namespace JinEngine
#endif // jin_audio
-#endif // __JE_AUDIO_SOURCE_H \ No newline at end of file
+#endif // __JE_AUDIO_SOURCE_H__ \ No newline at end of file
diff --git a/src/libjin/Common/je_array.hpp b/src/libjin/Common/je_array.hpp
index 361f1f0..8a5cbf1 100644
--- a/src/libjin/Common/je_array.hpp
+++ b/src/libjin/Common/je_array.hpp
@@ -1,5 +1,5 @@
-#ifndef __JE_COMMON_ARRAY_H
-#define __JE_COMMON_ARRAY_H
+#ifndef __JE_COMMON_ARRAY_H__
+#define __JE_COMMON_ARRAY_H__
namespace JinEngine
{
diff --git a/src/libjin/Common/je_common.h b/src/libjin/Common/je_common.h
index 0dfa79a..31b67c6 100644
--- a/src/libjin/Common/je_common.h
+++ b/src/libjin/Common/je_common.h
@@ -1,6 +1,7 @@
-#ifndef __JE_COMMON_H
-#define __JE_COMMON_H
+#ifndef __JE_COMMON_H__
+#define __JE_COMMON_H__
+#include "je_exception.h"
#include "je_array.hpp"
#endif \ No newline at end of file
diff --git a/src/libjin/Common/je_exception.cpp b/src/libjin/Common/je_exception.cpp
index e69de29..5489a42 100644
--- a/src/libjin/Common/je_exception.cpp
+++ b/src/libjin/Common/je_exception.cpp
@@ -0,0 +1,46 @@
+#include <stdarg.h>
+
+#include "je_exception.h"
+
+namespace JinEngine
+{
+
+ Exception::Exception(const char *fmt, ...)
+ {
+ va_list args;
+ int size_buffer = 256, size_out;
+ char *buffer;
+ while (true)
+ {
+ buffer = new char[size_buffer];
+ memset(buffer, 0, size_buffer);
+
+ va_start(args, fmt);
+ size_out = vsnprintf(buffer, size_buffer, fmt, args);
+ va_end(args);
+
+ // see http://perfec.to/vsnprintf/pasprintf.c
+ // if size_out ...
+ // == -1 --> output was truncated
+ // == size_buffer --> output was truncated
+ // == size_buffer-1 --> ambiguous, /may/ have been truncated
+ // > size_buffer --> output was truncated, and size_out
+ // bytes would have been written
+ if (size_out == size_buffer || size_out == -1 || size_out == size_buffer - 1)
+ size_buffer *= 2;
+ else if (size_out > size_buffer)
+ size_buffer = size_out + 2; // to avoid the ambiguous case
+ else
+ break;
+
+ delete[] buffer;
+ }
+ mMessage = std::string(buffer);
+ delete[] buffer;
+ }
+
+ Exception::~Exception() throw()
+ {
+ }
+
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/Common/je_exception.h b/src/libjin/Common/je_exception.h
index 7c66af8..c319ebd 100644
--- a/src/libjin/Common/je_exception.h
+++ b/src/libjin/Common/je_exception.h
@@ -1,19 +1,42 @@
-#ifndef __JE_EXCEPTION_H
-#define __JE_EXCEPTION_H
+#ifndef __JE_EXCEPTION_H__
+#define __JE_EXCEPTION_H__
#include <exception>
+#include <string>
namespace JinEngine
{
///
- /// Built-in exception class.
+ /// Jin Exception.
///
- class JinException : public std::exception
+ class Exception : public std::exception
{
public:
- JinException();
- const char* what() const throw();
+
+ ///
+ /// Creates a new Exception according to printf-rules.
+ ///
+ /// @param fmt The format string (see printf).
+ ///
+ Exception(const char *fmt, ...);
+ virtual ~Exception() throw();
+
+ ///
+ /// Returns a string containing reason for the exception.
+ ///
+ /// @return A description of the exception.
+ ///
+ inline virtual const char *what() const throw()
+ {
+ return mMessage.c_str();
+ }
+
+ private:
+ ///
+ /// Exception message.
+ ///
+ std::string mMessage;
};
diff --git a/src/libjin/Common/je_noncopyable.h b/src/libjin/Common/je_noncopyable.h
index 89a3e68..eff7121 100644
--- a/src/libjin/Common/je_noncopyable.h
+++ b/src/libjin/Common/je_noncopyable.h
@@ -1,5 +1,5 @@
-#ifndef __JE_NONCOPYABLE_H
-#define __JE_NONCOPYABLE_H
+#ifndef __JE_NONCOPYABLE_H__
+#define __JE_NONCOPYABLE_H__
namespace JinEngine
{
diff --git a/src/libjin/Common/je_object.h b/src/libjin/Common/je_object.h
index c256879..1afbf67 100644
--- a/src/libjin/Common/je_object.h
+++ b/src/libjin/Common/je_object.h
@@ -1,5 +1,5 @@
-#ifndef __JE_OBJECT_H
-#define __JE_OBJECT_H
+#ifndef __JE_OBJECT_H__
+#define __JE_OBJECT_H__
namespace JinEngine
{
@@ -9,6 +9,8 @@ namespace JinEngine
///
class Object
{
+ public:
+
};
} // namespace JinEngine
diff --git a/src/libjin/Common/je_pool.hpp b/src/libjin/Common/je_pool.hpp
index 1107fd5..cb96c5b 100644
--- a/src/libjin/Common/je_pool.hpp
+++ b/src/libjin/Common/je_pool.hpp
@@ -1,11 +1,177 @@
-#ifndef __JE_POOL_H
-#define __JE_POOL_H
+///
+/// An O(1) Object Pool. Original from https://www.codeproject.com/Articles/746630/O-Object-Pool-in-Cplusplus
+///
+#ifndef __JE_POOL_H__
+#define __JE_POOL_H__
+
+#include <stdlib.h>
+#include <iostream>
+
+#include "je_types.h"
namespace JinEngine
{
+ class DefaultMemoryAllocator
+ {
+ public:
+ static inline void *Allocate(size_t size)
+ {
+ return ::operator new(size, ::std::nothrow);
+ }
+ static inline void Deallocate(void *pointer, size_t size)
+ {
+ ::operator delete(pointer);
+ }
+ };
+
+ template<typename T, class TMemoryAllocator = DefaultMemoryAllocator>
+ class Pool
+ {
+ private:
+ struct _Node
+ {
+ void *_memory;
+ size_t _capacity;
+ _Node *_nextNode;
+
+ _Node(size_t capacity)
+ {
+ if (capacity < 1)
+ throw std::invalid_argument("capacity must be at least 1.");
+
+ _memory = TMemoryAllocator::Allocate(_itemSize * capacity);
+ if (_memory == NULL)
+ throw std::bad_alloc();
+
+ _capacity = capacity;
+ _nextNode = NULL;
+ }
+ ~_Node()
+ {
+ TMemoryAllocator::Deallocate(_memory, _itemSize * _capacity);
+ }
+ };
+
+ void *_nodeMemory;
+ T *_firstDeleted;
+ size_t _countInNode;
+ size_t _nodeCapacity;
+ _Node _firstNode;
+ _Node *_lastNode;
+ size_t _maxBlockLength;
+
+ static const size_t _itemSize;
+
+ Pool(const Pool<T, TMemoryAllocator> &source);
+ void operator = (const Pool<T, TMemoryAllocator> &source);
+
+ void _AllocateNewNode()
+ {
+ size_t size = _countInNode;
+ if (size >= _maxBlockLength)
+ size = _maxBlockLength;
+ else
+ {
+ size *= 2;
+
+ if (size < _countInNode)
+ throw std::overflow_error("size became too big.");
+
+ if (size >= _maxBlockLength)
+ size = _maxBlockLength;
+ }
+
+ _Node *newNode = new _Node(size);
+ _lastNode->_nextNode = newNode;
+ _lastNode = newNode;
+ _nodeMemory = newNode->_memory;
+ _countInNode = 0;
+ _nodeCapacity = size;
+ }
+
+ public:
+ explicit Pool(size_t initialCapacity = 32, size_t maxBlockLength = 1000000)
+ : _firstDeleted(NULL)
+ , _countInNode(0)
+ , _nodeCapacity(initialCapacity)
+ , _firstNode(initialCapacity)
+ , _maxBlockLength(maxBlockLength)
+ {
+ if (maxBlockLength < 1)
+ throw std::invalid_argument("maxBlockLength must be at least 1.");
+
+ _nodeMemory = _firstNode._memory;
+ _lastNode = &_firstNode;
+ }
+ ~Pool()
+ {
+ _Node *node = _firstNode._nextNode;
+ while (node)
+ {
+ _Node *nextNode = node->_nextNode;
+ delete node;
+ node = nextNode;
+ }
+ }
+
+ T *New()
+ {
+ if (_firstDeleted)
+ {
+ T *result = _firstDeleted;
+ _firstDeleted = *((T **)_firstDeleted);
+ new(result) T();
+ return result;
+ }
+
+ if (_countInNode >= _nodeCapacity)
+ _AllocateNewNode();
+
+ char *address = (char *)_nodeMemory;
+ address += _countInNode * _itemSize;
+ T *result = new(address) T();
+ _countInNode++;
+ return result;
+ }
+
+ // This method is useful if you want to call a non-default constructor.
+ // It should be used like this:
+ // new (pool.GetNextWithoutInitializing()) ObjectType(... parameters ...);
+ T *GetNextWithoutInitializing()
+ {
+ if (_firstDeleted)
+ {
+ T *result = (T *)_firstDeleted;
+ _firstDeleted = *((T **)_firstDeleted);
+ return result;
+ }
+
+ if (_countInNode >= _nodeCapacity)
+ _AllocateNewNode();
+
+ char *address = (char *)_nodeMemory;
+ address += _countInNode * _itemSize;
+ _countInNode++;
+ return (T *)address;
+ }
+ void Delete(T *content)
+ {
+ content->~T();
+
+ *((T **)content) = _firstDeleted;
+ _firstDeleted = content;
+ }
+ void DeleteWithoutDestroying(T *content)
+ {
+ *((T **)content) = _firstDeleted;
+ _firstDeleted = content;
+ }
+ };
+ template<typename T, class TMemoryAllocator>
+ const size_t Pool<T, TMemoryAllocator>::_itemSize = ((sizeof(T) + sizeof(void *) - 1) / sizeof(void *)) * sizeof(void *);
-}
+} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/Common/je_singleton.hpp b/src/libjin/Common/je_singleton.hpp
index e981e7a..d7f52c9 100644
--- a/src/libjin/Common/je_singleton.hpp
+++ b/src/libjin/Common/je_singleton.hpp
@@ -1,5 +1,5 @@
-#ifndef __JE_SINGLETON_H
-#define __JE_SINGLETON_H
+#ifndef __JE_SINGLETON_H__
+#define __JE_SINGLETON_H__
namespace JinEngine
{
@@ -77,4 +77,4 @@ namespace JinEngine
} // namespace JinEngine
-#endif // __JE_SINGLETON_H \ No newline at end of file
+#endif // __JE_SINGLETON_H__
diff --git a/src/libjin/Common/je_stringmap.hpp b/src/libjin/Common/je_stringmap.hpp
index 43e3e9b..7a3bd80 100644
--- a/src/libjin/Common/je_stringmap.hpp
+++ b/src/libjin/Common/je_stringmap.hpp
@@ -1,5 +1,5 @@
-#ifndef __JE_COMMON_SREINGMAP_H
-#define __JE_COMMON_SREINGMAP_H
+#ifndef __JE_COMMON_SREINGMAP_H__
+#define __JE_COMMON_SREINGMAP_H__
namespace JinEngine
{
diff --git a/src/libjin/Common/je_subsystem.hpp b/src/libjin/Common/je_subsystem.hpp
index d8e106d..c015bef 100644
--- a/src/libjin/Common/je_subsystem.hpp
+++ b/src/libjin/Common/je_subsystem.hpp
@@ -1,5 +1,5 @@
-#ifndef __JE_COMMON_SUBSYSTEM_H
-#define __JE_COMMON_SUBSYSTEM_H
+#ifndef __JE_COMMON_SUBSYSTEM_H__
+#define __JE_COMMON_SUBSYSTEM_H__
#include "../utils/je_macros.h"
diff --git a/src/libjin/Common/je_temporary.h b/src/libjin/Common/je_temporary.h
index 5af8704..647bfba 100644
--- a/src/libjin/Common/je_temporary.h
+++ b/src/libjin/Common/je_temporary.h
@@ -1,5 +1,5 @@
-#ifndef __JE_ON_STACK_H
-#define __JE_ON_STACK_H
+#ifndef __JE_TEMPORARY_H__
+#define __JE_TEMPORARY_H__
namespace JinEngine
{
diff --git a/src/libjin/Common/je_types.h b/src/libjin/Common/je_types.h
index 446c413..448d7ac 100644
--- a/src/libjin/Common/je_types.h
+++ b/src/libjin/Common/je_types.h
@@ -1,5 +1,5 @@
-#ifndef __JE_TYPES_H
-#define __JE_TYPES_H
+#ifndef __JE_TYPES_H__
+#define __JE_TYPES_H__
#include <stdint.h>
namespace JinEngine
diff --git a/src/libjin/Common/je_utf8.h b/src/libjin/Common/je_utf8.h
index a11850c..d840b75 100644
--- a/src/libjin/Common/je_utf8.h
+++ b/src/libjin/Common/je_utf8.h
@@ -1,5 +1,5 @@
-#ifndef __JE_COMMON_UTF8_H
-#define __JE_COMMON_UTF8_H
+#ifndef __JE_COMMON_UTF8_H__
+#define __JE_COMMON_UTF8_H__
#include "../core/je_configuration.h"
#if jin_os == jin_os_windows
@@ -31,4 +31,4 @@ namespace JinEngine
#endif // jin_os == jin_os_windows
-#endif // __JE_COMMON_UTF8_H \ No newline at end of file
+#endif // __JE_COMMON_UTF8_H__
diff --git a/src/libjin/Filesystem/je_asset_database.cpp b/src/libjin/Filesystem/je_asset_database.cpp
index ac547f0..a8524c5 100644
--- a/src/libjin/Filesystem/je_asset_database.cpp
+++ b/src/libjin/Filesystem/je_asset_database.cpp
@@ -5,6 +5,8 @@
#include <stdlib.h>
#include <stdio.h> /* defines FILENAME_MAX */
+#include "../common/je_exception.h"
+
#include "je_asset_database.h"
namespace JinEngine
@@ -34,14 +36,13 @@ namespace JinEngine
}
}
- bool AssetDatabase::read(const char* path, Buffer& buffer)
+ void AssetDatabase::read(const char* path, Buffer& buffer)
{
size_t size;
byte* data = (byte*)smtread(mSmt, path, &size);
- if (data == nullptr)
- return false;
+ if (data == nullptr)
+ throw Exception("Could not read file %s.", path);
buffer.bind(data, size);
- return true;
}
Buffer* read(const char* path)
@@ -73,12 +74,11 @@ namespace JinEngine
{
return smtexists(mSmt, path) == 0;
}
-
+/*
std::vector<std::string> AssetDatabase::getFiles(const char* path, bool recursive)
{
-
}
-
+*/
} // namespace Filesystem
} // namespace JinEngine
diff --git a/src/libjin/Filesystem/je_asset_database.h b/src/libjin/Filesystem/je_asset_database.h
index 8c30fc1..e8b1bd1 100644
--- a/src/libjin/Filesystem/je_asset_database.h
+++ b/src/libjin/Filesystem/je_asset_database.h
@@ -1,12 +1,12 @@
-#ifndef __JE_ASSET_DATABASE_H
-#define __JE_ASSET_DATABASE_H
+#ifndef __JE_ASSET_DATABASE_H__
+#define __JE_ASSET_DATABASE_H__
#include "../core/je_configuration.h"
#if defined(jin_filesystem)
#include <vector>
-#include "../3rdparty/smount/smount.h"
+#include "smount/smount.h"
#include "je_buffer.h"
@@ -70,7 +70,7 @@ namespace JinEngine
/// @param buffer Buffer to fill.
/// @return True if read sucessful, otherwise return false.
///
- bool read(const char* path, Buffer& buffer);
+ void read(const char* path, Buffer& buffer);
///
/// Read file and return data content.
@@ -88,7 +88,7 @@ namespace JinEngine
/// @param recursive Recursivily search folder.
/// @return File list under given directory.
///
- std::vector<std::string> getFiles(const char* path, bool recursive);
+ std::vector<std::string> getFiles(const char* directory, bool recursive = false);
///
/// Get full path of asset.
diff --git a/src/libjin/Filesystem/je_buffer.h b/src/libjin/Filesystem/je_buffer.h
index 0726e1d..1111e49 100644
--- a/src/libjin/Filesystem/je_buffer.h
+++ b/src/libjin/Filesystem/je_buffer.h
@@ -1,5 +1,5 @@
-#ifndef __JE_BUFFER_H
-#define __JE_BUFFER_H
+#ifndef __JE_BUFFER_H__
+#define __JE_BUFFER_H__
#include "../core/je_configuration.h"
#if defined(jin_filesystem)
diff --git a/src/libjin/Game/je_game.cpp b/src/libjin/Game/je_application.cpp
index 6eb1d3f..a5a8812 100644
--- a/src/libjin/Game/je_game.cpp
+++ b/src/libjin/Game/je_application.cpp
@@ -8,11 +8,11 @@
#include "../graphics/je_window.h"
#include "../math/je_math.h"
-#include "je_game.h"
+#include "je_application.h"
namespace JinEngine
{
- namespace Core
+ namespace Game
{
using namespace JinEngine::Graphics;
@@ -20,10 +20,10 @@ namespace JinEngine
using namespace JinEngine::Time;
using namespace JinEngine::Math;
- Game::Game() :_running(true) {};
+ Application::Application() :_running(true) {};
/* default game loop */
- void Game::run()
+ void Application::run()
{
if (_onLoad != nullptr)
_onLoad();
@@ -57,11 +57,11 @@ namespace JinEngine
quitloop:;
}
- bool Game::initSystem(const SettingBase* setting)
+ bool Application::initSystem(const SettingBase* setting)
{
if (setting == nullptr)
return false;
- Game::Setting* s = (Game::Setting*) setting;
+ Application::Setting* s = (Application::Setting*) setting;
_onEvent = s->eventHandler;
_onUpdate = s->updater;
_onDraw = s->drawer;
@@ -69,7 +69,7 @@ namespace JinEngine
return true;
}
- void Game::quitSystem()
+ void Application::quitSystem()
{
}
diff --git a/src/libjin/Game/je_game.h b/src/libjin/Game/je_application.h
index 78c3385..094de6a 100644
--- a/src/libjin/Game/je_game.h
+++ b/src/libjin/Game/je_application.h
@@ -1,5 +1,5 @@
-#ifndef __JE_CORE_GAME_H
-#define __JE_CORE_GAME_H
+#ifndef __JE_CORE_GAME_H__
+#define __JE_CORE_GAME_H__
#include "../core/je_configuration.h"
#if defined(jin_game)
@@ -12,13 +12,13 @@
namespace JinEngine
{
- namespace Core
+ namespace Game
{
///
/// Game class.
///
- class Game : public Subsystem<Game>
+ class Application : public Subsystem<Application>
{
public:
@@ -63,10 +63,10 @@ namespace JinEngine
private:
- Game();
- ~Game() {};
+ Application();
+ ~Application() {};
- singleton(Game);
+ singleton(Application);
onEvent _onEvent;
onUpdate _onUpdate;
@@ -85,4 +85,4 @@ namespace JinEngine
#endif // jin_game
-#endif // __JE_CORE_GAME_H \ No newline at end of file
+#endif // __JE_CORE_GAME_H__ \ No newline at end of file
diff --git a/src/libjin/Game/je_entity.cpp b/src/libjin/Game/je_entity.cpp
index 1396518..e69de29 100644
--- a/src/libjin/Game/je_entity.cpp
+++ b/src/libjin/Game/je_entity.cpp
@@ -1,11 +0,0 @@
-#include "je_entity.h"
-
-namespace JinEngine
-{
- namespace Game
- {
-
-
-
- } // namespace Game
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/Game/je_entity.h b/src/libjin/Game/je_entity.h
index 4a252da..39822b6 100644
--- a/src/libjin/Game/je_entity.h
+++ b/src/libjin/Game/je_entity.h
@@ -1,15 +1,7 @@
-#ifndef __JE_GAME_OBJECT_H
-#define __JE_GAME_OBJECT_H
+#ifndef __JE_ENTITY_H__
+#define __JE_ENTITY_H__
-#include "../core/je_configuration.h"
-#if defined(jin_game)
-
-#include <list>
-#include <map>
-#include <set>
-
-#include "../common/je_object.h"
-#include "../common/je_types.h"
+#include "je_gameobject.h"
namespace JinEngine
{
@@ -17,59 +9,19 @@ namespace JinEngine
{
///
- /// Game object base class.
+ ///
///
- class Entity : public Object
+ class Entity : public GameObject
{
public:
+ Entity();
- ///
- ///
- ///
- virtual ~Entity();
-
- ///
- ///
- ///
- void lifecycle();
-
- ///
- ///
- ///
- void setVisible(bool isVisible);
+ private:
- ///
- ///
- ///
- void setActive(bool isActive);
-
- protected:
- virtual void onAlive();
- virtual void onUpdate(float dt);
- virtual void onDraw();
- virtual void onDie();
-
- uint32 layer; // layer where entity belongs
- uint32 index; // render index in layer
- uint64 tag; // tag of entity, 64 now
- bool mIsVisible; // if the entity is visible or not
- bool mIsActive; // if the entity is joined into the logic
};
- ///
- /// Entity list. For quickly adding and removing entities.
- ///
- typedef std::list<Entity*> EntityList;
-
- ///
- /// Entity set. For searching and keeps entities unique and sorted.
- ///
- typedef std::set<Entity*> EntitySet;
-
} // namespace Game
-} // namespace JinEngine
-
-#endif // jin_game
+} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/Game/je_gameobject.cpp b/src/libjin/Game/je_gameobject.cpp
new file mode 100644
index 0000000..1396518
--- /dev/null
+++ b/src/libjin/Game/je_gameobject.cpp
@@ -0,0 +1,11 @@
+#include "je_entity.h"
+
+namespace JinEngine
+{
+ namespace Game
+ {
+
+
+
+ } // namespace Game
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/Game/je_gameobject.h b/src/libjin/Game/je_gameobject.h
new file mode 100644
index 0000000..fefc6df
--- /dev/null
+++ b/src/libjin/Game/je_gameobject.h
@@ -0,0 +1,86 @@
+#ifndef __JE_GAME_OBJECT_H__
+#define __JE_GAME_OBJECT_H__
+
+#include "../core/je_configuration.h"
+#if defined(jin_game)
+
+#include <list>
+#include <map>
+#include <set>
+
+#include "../common/je_object.h"
+#include "../common/je_types.h"
+#include "../graphics/je_sprite.h"
+
+namespace JinEngine
+{
+ namespace Game
+ {
+
+ ///
+ /// Game object base class.
+ ///
+ class GameObject : public Object
+ {
+ public:
+
+ ///
+ ///
+ ///
+ virtual ~GameObject();
+
+ ///
+ ///
+ ///
+ void lifecycle();
+
+ ///
+ ///
+ ///
+ void setVisible(bool isVisible);
+
+ ///
+ ///
+ ///
+ void setActive(bool isActive);
+
+ ///
+ ///
+ ///
+ void setOrder(uint32 order);
+
+ protected:
+ virtual void onAlive();
+ virtual void onUpdate(float dt);
+ virtual void onDraw();
+ virtual void onDestroy();
+
+ uint32 mLayer; // layer where entity belongs
+ uint32 mOrder; // render index in layer
+ uint32 mTag; // tag of entity, support 32 tags now
+ bool mIsVisible; // if the entity is visible or not
+ bool mIsActive; // if the entity is joined into the logic
+
+ ///
+ /// Position of entity.
+ ///
+ Math::Vector2<float> mPosition;
+
+ };
+
+ ///
+ /// Entity list. For quickly adding and removing entities.
+ ///
+ typedef std::list<GameObject*> EntityList;
+
+ ///
+ /// Entity set. For searching and keeps entities unique and sorted.
+ ///
+ typedef std::set<GameObject*> EntitySet;
+
+ } // namespace Game
+} // namespace JinEngine
+
+#endif // jin_game
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Game/je_scene.h b/src/libjin/Game/je_scene.h
index f510a1f..811d1a8 100644
--- a/src/libjin/Game/je_scene.h
+++ b/src/libjin/Game/je_scene.h
@@ -1,5 +1,5 @@
-#ifndef __JE_GAME_SCENE_H
-#define __JE_GAME_SCENE_H
+#ifndef __JE_GAME_SCENE_H__
+#define __JE_GAME_SCENE_H__
#include "../core/je_configuration.h"
#if defined(jin_game)
@@ -28,7 +28,7 @@ namespace JinEngine
///
///
///
- EntityList& getEntitiesByTag(uint64 tag);
+ EntityList& getEntitiesByTag(uint32 tag);
///
///
@@ -38,7 +38,7 @@ namespace JinEngine
///
///
///
- void setEntitiesActiveByTag(uint64 tag);
+ void setEntitiesActiveByTag(uint32 tag);
///
///
@@ -53,7 +53,7 @@ namespace JinEngine
///
///
///
- void removeEntitiesByTag(uint64 tag);
+ void removeEntitiesByTag(uint32 tag);
protected:
// all entities
@@ -61,7 +61,7 @@ namespace JinEngine
// all entities grouped by layer, render order
std::map<uint32, EntityList> layers;
// all entities grouped by tag
- std::map<uint64, EntityList> tags;
+ std::map<uint32, EntityList> tags;
};
diff --git a/src/libjin/Graphics/Font/je_decoder.cpp b/src/libjin/Graphics/Font/je_decoder.cpp
deleted file mode 100644
index 01e1990..0000000
--- a/src/libjin/Graphics/Font/je_decoder.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include "je_decoder.h"
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- /* utf8 byte string to unicode codepoint */
- static const char *utf8toCodepoint(const char *p, unsigned *res) {
- return nullptr;
-
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // decoders
- /////////////////////////////////////////////////////////////////////////////
-
- const void* Utf8::decode(const void* data, Codepoint* res) const
- {
- const char* p = (char*)data;
- unsigned x, mask, shift;
- switch (*p & 0xf0) {
- case 0xf0: mask = 0x07; shift = 18; break;
- case 0xe0: mask = 0x0f; shift = 12; break;
- case 0xc0:
- case 0xd0: mask = 0x1f; shift = 6; break;
- default:
- *res = *p;
- return p + 1;
- }
- x = (*p & mask) << shift;
- do {
- if (*(++p) == '\0') {
- *res = x;
- return p;
- }
- shift -= 6;
- x |= (*p & 0x3f) << shift;
- } while (shift);
- *res = x;
- return p + 1;
- }
-
- const void* Utf8::next(const void* data) const
- {
- const char* p = (char*)data;
- unsigned x, mask, shift;
- switch (*p & 0xf0) {
- case 0xf0: mask = 0x07; shift = 18; break;
- case 0xe0: mask = 0x0f; shift = 12; break;
- case 0xc0:
- case 0xd0: mask = 0x1f; shift = 6; break;
- default:
- return p + 1;
- }
- x = (*p & mask) << shift;
- do {
- if (*(++p) == '\0') {
- return p;
- }
- shift -= 6;
- x |= (*p & 0x3f) << shift;
- } while (shift);
- return p + 1;
- }
- /*
- const void* Utf16::decode(const void* data, Codepoint* res) const
- {
- return nullptr;
- }
-
- const void* Utf16::next(const void* data) const
- {
- return nullptr;
- }
- */
- const void* Ascii::decode(const void* data, Codepoint* res) const
- {
- const char* p = (char*)data;
- *res = *p;
- return p + 1;
- }
-
- const void* Ascii::next(const void* data) const
- {
- const char* p = (char*)data;
- return p + 1;
- }
-
- } // namespace Graphics
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/Graphics/Font/je_decoder.h b/src/libjin/Graphics/Font/je_decoder.h
deleted file mode 100644
index 36cbda7..0000000
--- a/src/libjin/Graphics/Font/je_decoder.h
+++ /dev/null
@@ -1,94 +0,0 @@
-#ifndef __JE_UTF8_H
-#define __JE_UTF8_H
-
-#include <vector>
-
-#include "je_text.h"
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- ///
- /// Text decoder.
- ///
- class Decoder
- {
- public:
-
- ///
- /// Decode a code unit.
- ///
- /// @param data Code units.
- /// @param codepoint Value of code point.
- /// @return Next code unit location.
- ///
- virtual const void* decode(const void* data, Codepoint* codepoint) const = 0 ;
-
- ///
- /// Get next code unit location.
- ///
- /// @param data Code units.
- /// @return Next code unit location.
- ///
- virtual const void* next(const void* data) const = 0;
-
- };
-
- ///
- /// Utf-8 decoder.
- ///
- class Utf8 : public Decoder
- {
- public:
-
- ///
- /// Decode a code unit.
- ///
- /// @param data Code units.
- /// @param codepoint Value of code point.
- /// @return Next code unit location.
- ///
- const void* decode(const void* data, Codepoint* codepoint) const override;
-
- ///
- /// Get next code unit location.
- ///
- /// @param data Code units.
- /// @return Next code unit location.
- ///
- const void* next(const void* data) const override;
-
- };
-
- ///
- /// Ascii decoder.
- ///
- class Ascii : public Decoder
- {
- public:
-
- ///
- /// Decode a code unit.
- ///
- /// @param data Code units.
- /// @param codepoint Value of code point.
- /// @return Next code unit location.
- ///
- const void* decode(const void* data, Codepoint* codepoint) const override;
-
- ///
- /// Get next code unit location.
- ///
- /// @param data Code units.
- /// @return Next code unit location.
- ///
- const void* next(const void* data) const override;
-
- };
-
- } // namespace Graphics
-} // namespace JinEngine
-
-#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/Font/je_font.h b/src/libjin/Graphics/Font/je_font.h
deleted file mode 100644
index 4529902..0000000
--- a/src/libjin/Graphics/Font/je_font.h
+++ /dev/null
@@ -1,100 +0,0 @@
-#ifndef __JE_FONT_H
-#define __JE_FONT_H
-
-#include <vector>
-#include "je_text.h"
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- struct Page;
-
- ///
- /// Base Font class.
- ///
- class Font
- {
- public:
- ///
- /// Font constructor.
- ///
- Font(unsigned fontsize)
- : mFontSize(fontsize)
- {
- }
-
- ///
- /// Font destructor.
- ///
- virtual ~Font() {};
-
- ///
- /// Create page with given text.
- ///
- /// @param text Text to be typesetted.
- /// @param lineheight Line height of text.
- /// @param spacing Spacing between characters. 0 by default.
- /// @return Page if created successfully, otherwise return null.
- ///
- virtual Page* typeset(const Text& text, int lineheight, int spacing = 0) = 0;
-
- ///
- /// Create page with given unicode codepoints.
- ///
- /// @param content Unicode codepoints to be typesetted.
- /// @param lineheight Line height of text.
- /// @param spacing Spacing between characters. 0 by default.
- /// @return Page if created successfully, otherwise return null.
- ///
- virtual Page* typeset(const Content& content, int lineheight, int spacing = 0) = 0;
-
- ///
- /// Render page to given position.
- ///
- /// @param page Page to be rendered.
- /// @param x X value of the position.
- /// @param y Y value of the position.
- ///
- virtual void print(const Page* page, int x, int y) = 0;
-
- ///
- /// Render unicode codepoints to given position.
- ///
- /// @param content Unicode codepoints to be typesetted.
- /// @param x X value of the position.
- /// @param y Y value of the position.
- /// @param lineheight Line height of the content.
- /// @param spacing Spacing between characters.
- ///
- virtual void print(const Content& content, int x, int y, int lineheight, int spacing = 0) = 0;
-
- ///
- /// Render text to given position.
- ///
- /// @param text Text to be rendered.
- /// @param x X value of the position.
- /// @param y Y value of the position.
- /// @param lineheight Line height of the text.
- /// @param spacing Spacing between characters.
- ///
- virtual void print(const Text& text, int x, int y, int lineheight, int spacing = 0) = 0;
-
- ///
- /// Get font size.
- ///
- /// @return Font size.
- ///
- inline unsigned getFontSize() { return mFontSize; };
-
- protected:
-
- unsigned mFontSize;
-
- };
-
- } // namespace Graphics
-} // namespace JinEngine
-
-#endif // __JE_FONT_H \ No newline at end of file
diff --git a/src/libjin/Graphics/Font/je_page.h b/src/libjin/Graphics/Font/je_page.h
deleted file mode 100644
index fbc297e..0000000
--- a/src/libjin/Graphics/Font/je_page.h
+++ /dev/null
@@ -1,51 +0,0 @@
-#ifndef __JE_PAGE_H
-#define __JE_PAGE_H
-
-#include "../../math/je_vector2.hpp"
-
-#include "je_font.h"
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- class Font;
-
- ///
- /// Glyphs data to be rendered.
- ///
- struct GlyphVertex
- {
- int x, y; ///< screen coordinates
- float u, v; ///< normalized texture uv
- };
-
- ///
- /// Glyphs info for reducing draw call.
- ///
- struct GlyphArrayDrawInfo
- {
- GLuint texture; ///< atlas
- unsigned int start; ///< glyph vertex indecies
- unsigned int count; ///< glyph vertex count
- };
-
- ///
- /// Page to be rendered.
- ///
- /// A page is a pre-rendered text struct for reducing draw call. Each page
- /// keeps a font pointer which should not be changed.
- ///
- struct Page
- {
- Font* font;
- std::vector<GlyphArrayDrawInfo> glyphinfolist;
- std::vector<GlyphVertex> glyphvertices;
- Math::Vector2<int> size;
- };
-
- } // namespace Graphics
-} // namespace JinEngine
-
-#endif // __JE_PAGE_H \ No newline at end of file
diff --git a/src/libjin/Graphics/Font/je_text.cpp b/src/libjin/Graphics/Font/je_text.cpp
deleted file mode 100644
index 75dfc7b..0000000
--- a/src/libjin/Graphics/Font/je_text.cpp
+++ /dev/null
@@ -1,154 +0,0 @@
-#include <cstring>
-
-#include "je_text.h"
-#include "je_decoder.h"
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- /////////////////////////////////////////////////////////////////////////////
- // iterator
- /////////////////////////////////////////////////////////////////////////////
-
- Text::Iterator::Iterator(const Iterator& itor)
- : data(itor.data)
- , p(itor.p)
- , encode(itor.encode)
- , length(itor.length)
- {
- switch (encode)
- {
- case Encode::UTF8: decoder = new Utf8(); break;
- case Encode::ASCII: decoder = new Ascii(); break;
- }
- }
-
- Text::Iterator::Iterator(const Encode& _encode, const void* _data, unsigned int _length)
- : data(_data)
- , p(_data)
- , encode(_encode)
- , length(_length)
- {
- switch (encode)
- {
- case Encode::UTF8: decoder = new Utf8(); break;
- case Encode::ASCII: decoder = new Ascii(); break;
- }
- }
-
- Text::Iterator::~Iterator()
- {
- delete decoder;
- }
-
- Codepoint Text::Iterator::get()
- {
- Codepoint codepoint;
- decoder->decode(p, &codepoint);
- return codepoint;
- }
-
- Codepoint Text::Iterator::operator*()
- {
- return get();
- }
- /*
- Text::Iterator Text::Iterator::begin()
- {
- Iterator itor(encode, data, length);
- itor.toBegin();
- return itor;
- }
-
- Text::Iterator Text::Iterator::end()
- {
- Iterator itor(encode, data, length);
- itor.toEnd();
- return itor;
- }
- */
- void Text::Iterator::toBegin()
- {
- p = (const unsigned char*)data;
- }
-
- void Text::Iterator::toEnd()
- {
- p = (const unsigned char*)data + length;
- }
-
- Text::Iterator& Text::Iterator::operator ++()
- {
- p = decoder->next(p);
- return *this;
- }
-
- Text::Iterator Text::Iterator::operator ++(int)
- {
- p = decoder->next(p);
- Iterator itor(encode, data, length);
- itor.p = p;
- return itor;
- }
-
- bool Text::Iterator::operator !=(const Iterator& itor)
- {
- return !(data == itor.data
- && p == itor.p
- && length == itor.length
- && encode == itor.encode);
- }
-
- bool Text::Iterator::operator ==(const Iterator& itor)
- {
- return data == itor.data
- && p == itor.p
- && length == itor.length
- && encode == itor.encode;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // text
- /////////////////////////////////////////////////////////////////////////////
-
- Text::Text(Encode encode, const void* data)
- {
- unsigned length = strlen((const char*)data);
- Iterator end = Iterator(encode, data, length);
- end.toEnd();
- Iterator it = Iterator(encode, data, length);
- for (; it != end; ++it)
- {
- content.push_back(*it);
- }
- }
-
- Text::Text(Encode encode, const void* data, unsigned length)
- {
- Iterator end = Iterator(encode, data, length);
- end.toEnd();
- Iterator it = Iterator(encode, data, length);
- for (; it != end; ++it)
- {
- content.push_back(*it);
- }
- }
-
- Text::~Text()
- {
- }
-
- const Content& Text::getContent() const
- {
- return content;
- }
-
- const Content& Text::operator*() const
- {
- return content;
- }
-
- } // namespace Graphics
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/Graphics/Font/je_text.h b/src/libjin/Graphics/Font/je_text.h
deleted file mode 100644
index 7436875..0000000
--- a/src/libjin/Graphics/Font/je_text.h
+++ /dev/null
@@ -1,169 +0,0 @@
-#ifndef __JE_TEXT_H
-#define __JE_TEXT_H
-
-#include <vector>
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- typedef unsigned int Codepoint;
-
- typedef std::vector<Codepoint> Content;
-
- class Text;
-
- class Decoder;
-
- ///
- /// Supported text encoding.
- ///
- enum Encode
- {
- UTF8, ///< utf-8
- ASCII, ///< ASCII
- };
-
- ///
- /// Decoded text. Saved as unicode codepoints.
- ///
- class Text
- {
- public:
- ///
- ///
- ///
- Text(Encode encode, const void* data);
-
- ///
- ///
- ///
- Text(Encode encode, const void* data, unsigned int length);
-
- ///
- ///
- ///
- ~Text();
-
- ///
- ///
- ///
- const Content& getContent() const;
-
- ///
- ///
- ///
- const Content& operator*() const;
-
- private:
- ///
- ///
- ///
- class Iterator
- {
- public:
-
- ///
- ///
- ///
- Iterator(const Iterator& itor);
-
- ///
- ///
- ///
- Iterator(const Encode& encode, const void* data, unsigned int length);
-
- ///
- ///
- ///
- ~Iterator();
-
- ///
- ///
- ///
- Codepoint get();
-
- //Iterator begin();
- //Iterator end();
-
- ///
- ///
- ///
- void toBegin();
-
- ///
- ///
- ///
- void toEnd();
-
- ///
- ///
- ///
- Codepoint operator *();
-
- ///
- ///
- ///
- Iterator& operator ++();
-
- ///
- ///
- ///
- Iterator operator ++(int);
-
- ///
- ///
- ///
- bool operator !=(const Iterator& itor);
-
- ///
- ///
- ///
- bool operator ==(const Iterator& itor);
-
- private:
-
- ///
- ///
- ///
- void operator = (const Iterator&);
-
- ///
- ///
- ///
- const Encode encode;
-
- ///
- ///
- ///
- const Decoder* decoder;
-
- ///
- ///
- ///
- const void* p;
-
- ///
- ///
- ///
- const void* const data;
-
- ///
- ///
- ///
- unsigned int length;
-
- };
-
- ///
- ///
- ///
- Content content;
-
- };
-
- } // namespace Graphics
-} // namespace JinEngine
-
-#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/Font/je_texture_font.cpp b/src/libjin/Graphics/Font/je_texture_font.cpp
deleted file mode 100644
index 9651c1a..0000000
--- a/src/libjin/Graphics/Font/je_texture_font.cpp
+++ /dev/null
@@ -1,318 +0,0 @@
-#include <vector>
-
-#include "../../math/je_vector2.hpp"
-
-#include "../shader/je_shader.h"
-
-#include "je_texture_font.h"
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- using namespace std;
- using namespace Math;
-
- TextureFont * TextureFont::createTextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh)
- {
- TextureFont* tf = new TextureFont(bitmap, codepoints, cellw, cellh);
- return tf;
- }
-
- TextureFont * TextureFont::createTextureFont(const Bitmap* bitmap, const Text& codepoints, int cellw, int cellh)
- {
- TextureFont* tf = new TextureFont(bitmap, *codepoints, cellw, cellh);
- return tf;
- }
-
- TextureFont* TextureFont::createTextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh)
- {
- TextureFont* tf = new TextureFont(bitmap, codepoints, mask, cellh);
- return tf;
- }
-
- TextureFont* TextureFont::createTextureFont(const Bitmap* bitmap, const Text& codepoints, Color mask, int cellh)
- {
- TextureFont* tf = new TextureFont(bitmap, *codepoints, mask, cellh);
- return tf;
- }
-
- TextureFont::~TextureFont()
- {
- }
-
- const TextureFont::TextureGlyph* TextureFont::findGlyph(Codepoint codepoint) const
- {
- auto it = glyphs.find(codepoint);
- if (it != glyphs.end())
- {
- return &it->second;
- }
- else
- return nullptr;
- }
-
- Page* TextureFont::typeset(const Content& text, int lineheight, int spacing)
- {
- Page* page = new Page();
- page->font = this;
- vector<GlyphArrayDrawInfo>& glyphinfolist = page->glyphinfolist;
- vector<GlyphVertex>& glyphvertices = page->glyphvertices;
- int texture = -1;
- const TextureGlyph* glyph = nullptr;
- GlyphVertex vertex;
- Vector2<int> p(0, 0);
- int i = 0;
-
- #define glyphvertices_push(_x, _y, _u, _v) \
- vertex.x = _x; vertex.y = _y;\
- vertex.u = _u; vertex.v = _v;\
- glyphvertices.push_back(vertex);\
-
- for (Codepoint c : text)
- {
- // return
- if (c == 0x0D) continue;
- // newline
- if (c == 0x0A)
- {
- p.y += lineheight;
- p.x = 0;
- continue;
- }
- if (c == 0x09)
- {
- // tab = 4*space
- unsigned cw = getCharWidth(0x20);
- p.x += cw * 4;
- continue;
- }
- glyph = findGlyph(c);
- if (glyph == nullptr) continue;
- if (texture != mTexture)
- {
- texture = mTexture;
- GlyphArrayDrawInfo info;
- info.start = i;
- info.count = 0;
- info.texture = texture;
- glyphinfolist.push_back(info);
- }
- glyphinfolist[glyphinfolist.size() - 1].count += 4;
- // normalized
- float w = getWidth(), h = getHeight();
- float nx = glyph->x / w, ny = glyph->y / h;
- float nw = glyph->w / w, nh = glyph->h / h;
- glyphvertices_push(p.x, p.y, nx, ny);
- glyphvertices_push(p.x, p.y + glyph->h, nx, ny + nh);
- glyphvertices_push(p.x + glyph->w, p.y + glyph->h, nx + nw, ny + nh);
- glyphvertices_push(p.x + glyph->w, p.y, nx + nw, ny);
- p.x += glyph->w + spacing;
- i += 4;
- }
- getTextBox(text, &page->size.w, &page->size.h, lineheight, spacing);
- return page;
- }
-
- int TextureFont::getCharWidth(int c)
- {
- auto it = glyphs.find(c);
- if (it != glyphs.end())
- {
- return it->second.w;
- }
- return 0;
- }
-
- int TextureFont::getCharHeight(int c)
- {
- auto it = glyphs.find(c);
- if (it != glyphs.end())
- {
- return it->second.h;
- }
- return 0;
- }
-
- int TextureFont::getTextWidth(const Content& t, int spacing)
- {
- int res = 0;
- int tmp = 0;
- for (Codepoint c : t)
- {
- if (c == 0x0D)
- continue;
- if (c == 0x0A)
- {
- tmp = 0;
- continue;
- }
- if (c == 0x09)
- {
- // tab = 4*space
- unsigned cw = getCharWidth(0x20);
- tmp += cw * 4;
- if (tmp > res) res = tmp;
- continue;
- }
- tmp += getCharWidth(c) + spacing;
- if (tmp > res) res = tmp;
- }
- return res;
- }
-
- int TextureFont::getTextHeight(const Content& t, int lineheight)
- {
- int res = 0;
- bool newline = true;
- for (Codepoint c : t)
- {
- if (c == 0x0A)
- newline = true;
- else if (c == 0x0D);
- else if (newline)
- {
- newline = false;
- res += lineheight;
- }
- }
- return res;
- }
-
- void TextureFont::getTextBox(const Content& text, int* w, int* h, int lineheight, int spacing)
- {
- *w = 0;
- *h = 0;
- int tmp = 0;
- bool newline = true;
- for (Codepoint c : text)
- {
- if (c == 0x0D)
- continue;
- if (c == 0x0A)
- {
- tmp = 0;
- newline = true;
- continue;
- }
- else if (newline)
- {
- newline = false;
- *h += lineheight;
- }
- tmp += getCharWidth(c) + spacing;
- if (tmp > *w)
- *w = tmp;
- }
- }
-
- Page* TextureFont::typeset(const Text& text, int lineheight, int spacing)
- {
- return typeset(*text, lineheight, spacing);
- }
-
- void TextureFont::print(const Page* page, int x, int y)
- {
- Shader* shader = Shader::getCurrentShader();
- const vector<GlyphArrayDrawInfo>& glyphinfolist = page->glyphinfolist;
- const vector<GlyphVertex>& glyphvertices = page->glyphvertices;
- gl.ModelMatrix.setTransformation(x, y, 0, 1, 1, 0, 0);
- shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
- shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
- for (int i = 0; i < glyphinfolist.size(); ++i)
- {
- const GlyphArrayDrawInfo& info = glyphinfolist[i];
- shader->bindVertexPointer(2, GL_INT, sizeof(GlyphVertex), &glyphvertices[info.start].x);
- shader->bindUVPointer(2, GL_FLOAT, sizeof(GlyphVertex), &glyphvertices[info.start].u);
- gl.bindTexture(info.texture);
- gl.drawArrays(GL_QUADS, 0, info.count);
- gl.bindTexture(0);
- }
- }
-
- void TextureFont::print(const Content& text, int x, int y, int lineheight, int spacing)
- {
- Page* page = typeset(text, lineheight, spacing);
- print(page, x, y);
- delete page;
- }
-
- void TextureFont::print(const Text& text, int x, int y, int lineheight, int spacing)
- {
- Page* page = typeset(text, lineheight, spacing);
- print(page, x, y);
- delete page;
- }
-
- TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh)
- : Graphic(bitmap)
- , Font(cellh)
- {
- TextureGlyph glyph;
- Vector2<int> count(bitmap->getWidth() / cellw, bitmap->getHeight() / cellh);
- glyph.w = cellw;
- glyph.h = cellh;
- for (int y = 0; y < count.row; ++y)
- {
- glyph.y = y * cellh;
- for (int x = 0; x < count.colum; ++x)
- {
- glyph.x = x * cellw;
- if (x + y * count.colum >= codepoints.size())
- return;
- glyphs.insert(std::pair<Codepoint, TextureGlyph>(codepoints[x + y * count.colum], glyph));
- }
- }
- }
-
- TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh)
- : Graphic(bitmap)
- , Font(cellh)
- {
- TextureGlyph glyph;
- glyph.h = cellh;
- int w = bitmap->getWidth();
- int h = bitmap->getHeight();
- int i = 0;
- for (int y = 0; y < h; y += cellh)
- {
- glyph.y = y;
- bool newc = false;
- for (int x = 0; x <= w; ++x)
- {
- if (x == w && newc)
- {
- glyph.w = x - glyph.x;
- if (i >= codepoints.size())
- return;
- glyphs.insert(std::pair<Codepoint, TextureGlyph>(codepoints[i], glyph));
- ++i;
- newc = false;
- break;
- }
- Color c = bitmap->getPixels()[x + y * w];
- if (!newc && c != mask)
- {
- glyph.x = x;
- newc = true;
- }
- else if (newc && c == mask)
- {
- glyph.w = x - glyph.x;
- if (i >= codepoints.size())
- return;
- glyphs.insert(std::pair<Codepoint, TextureGlyph>(codepoints[i], glyph));
- if (codepoints[i] == 't')
- {
- int a = 10;
- }
- ++i;
- newc = false;
- }
- }
- }
- }
-
- }
-} \ No newline at end of file
diff --git a/src/libjin/Graphics/Font/je_texture_font.h b/src/libjin/Graphics/Font/je_texture_font.h
deleted file mode 100644
index 6276350..0000000
--- a/src/libjin/Graphics/Font/je_texture_font.h
+++ /dev/null
@@ -1,140 +0,0 @@
-#ifndef __JE_TEXTURE_FONT_H
-#define __JE_TEXTURE_FONT_H
-
-#include <map>
-#include <vector>
-
-#include "../../math/je_vector4.hpp"
-
-#include "../je_graphic.h"
-#include "../je_bitmap.h"
-
-#include "je_page.h"
-#include "je_font.h"
-#include "je_text.h"
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- ///
- ///
- ///
- class TextureFont : public Font
- , public Graphic
- {
- public:
-
- ///
- ///
- ///
- static TextureFont* createTextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh);
-
- ///
- ///
- ///
- static TextureFont* createTextureFont(const Bitmap* bitmap, const Text& text, int cellw, int cellh);
-
- ///
- ///
- ///
- static TextureFont* createTextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh);
-
- ///
- ///
- ///
- static TextureFont* createTextureFont(const Bitmap* bitmap, const Text& text, Color mask, int cellh);
-
- ///
- ///
- ///
- ~TextureFont();
-
- ///
- ///
- ///
- Page* typeset(const Text& text, int lineheight, int spacing = 0) override;
-
- ///
- ///
- ///
- Page* typeset(const Content& text, int lineheight, int spacing = 0) override ;
-
- ///
- ///
- ///
- void print(const Page* page, int x, int y) override;
-
- ///
- ///
- ///
- void print(const Content& text, int x, int y, int linehgiht, int spacing = 0) override;
-
- ///
- ///
- ///
- void print(const Text& text, int x, int y, int lineheight, int spacing = 0)override;
-
- private:
-
- ///
- ///
- ///
- struct TextureGlyph
- {
- float x, y, w, h;
- };
-
- ///
- ///
- ///
- TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh);
-
- ///
- ///
- ///
- TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh);
-
- ///
- ///
- ///
- int getCharWidth(int c);
-
- ///
- ///
- ///
- int getCharHeight(int c);
-
- ///
- ///
- ///
- int getTextWidth(const Content& text, int spacing = 0);
-
- ///
- ///
- ///
- int getTextHeight(const Content& text, int lineheight);
-
- ///
- ///
- ///
- void getTextBox(const Content& text, int* w, int* h, int lineheight, int spacing = 0);
-
- ///
- ///
- ///
- const TextureGlyph* findGlyph(Codepoint codepoint) const;
-
-
- ///
- ///
- ///
- std::map<Codepoint, TextureGlyph> glyphs;
-
- };
-
- } // namespace Graphics
-} // namespace JinEngine
-
-#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/Font/je_ttf.cpp b/src/libjin/Graphics/Font/je_ttf.cpp
deleted file mode 100644
index a11efb0..0000000
--- a/src/libjin/Graphics/Font/je_ttf.cpp
+++ /dev/null
@@ -1,463 +0,0 @@
-#include "../../core/je_configuration.h"
-#if defined(jin_graphics)
-
-#include <stdio.h>
-
-#include "../../common/je_array.hpp"
-
-#include "../je_gl.h"
-#include "../je_color.h"
-#include "../shader/je_shader.h"
-
-#include "je_ttf.h"
-#include "je_page.h"
-
-#define STB_TRUETYPE_IMPLEMENTATION
-#include "../../3rdparty/stb/stb_truetype.h"
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- /////////////////////////////////////////////////////////////////////////////
- // TTFData
- /////////////////////////////////////////////////////////////////////////////
-
- TTFData* TTFData::createTTFData(const unsigned char* data, unsigned int size)
- {
- TTFData* ttf = nullptr;
- try
- {
- ttf = new TTFData(data, size);
- return ttf;
- }
- catch (...)
- {
- return nullptr;
- }
- }
-
- TTFData::TTFData(const unsigned char* d, unsigned int s)
- {
- raw.size = s;
- raw.data = (unsigned char*)malloc(s);
- memcpy(raw.data, d, s);
- if (!stbtt_InitFont(&info, (const unsigned char*)raw.data, 0))
- {
- delete raw.data;
- throw 0;
- }
- /* push default fontsize */
- pushTTFsize(FONT_SIZE);
- }
-
- TTFData::~TTFData()
- {
- free(raw.data);
- }
-
- TTF* TTFData::createTTF(unsigned fontSize)
- {
- TTF* ttf;
- try
- {
- ttf = new TTF(this, fontSize);
- }
- catch (...)
- {
- return nullptr;
- }
- return ttf;
- }
-
- /*
- * (0, 0)
- * +--------------+ ascent
- * | +--------+ |
- * | | | |
- * | | bitmap | |
- * +--|--------|--+ baseline
- * | +--------+ |
- * +--|-----------+ decent
- * | |
- * leftSideBearing |
- * advanceWidth
- */
- void TTFData::getVMetrics(int* baseline, int* descent)
- {
- float scale = scales.back();
- int ascent;
- stbtt_GetFontVMetrics(&info, &ascent, descent, 0);
- *baseline = (int)(ascent*scale) + 1; // slight adjustment
- *descent = *baseline - (int)(*descent*scale) + 1;
- }
-
- void TTFData::getHMetrics(unsigned int codepoint, int* advanceWidth, int* leftSideBearing)
- {
- float scale = scales.back();
- int adw, lsb;
- stbtt_GetCodepointHMetrics(&info, codepoint, &adw, &lsb);
- *advanceWidth = (int)(adw*scale);
- *leftSideBearing = (int)(lsb*scale);
- }
-
- void TTFData::pushTTFsize(unsigned int fs)
- {
- float sc = stbtt_ScaleForPixelHeight(&info, fs);
- scales.push_back(sc);
- }
-
- void TTFData::popTTFsize()
- {
- /* always keep default ttf size on the bottom of stack */
- if (scales.size() > 1)
- scales.pop_back();
- }
-
- Channel* TTFData::getCodepointBitmapAlpha(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const
- {
- float scale = scales.back();
- Channel* bitmap = stbtt_GetCodepointBitmap(&info, scale, scale, codepoint, width, height, xoff, yoff);
- return bitmap;
- }
-
- Color* TTFData::getCodepointBitmap(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const
- {
- float scale = scales.back();
- Channel* bitmap = stbtt_GetCodepointBitmap(&info, scale, scale, codepoint, width, height, xoff, yoff);
- int w = *width, h = *height;
- //int xo = *xoff, yo = *yoff;
- Color* bitmap32 = new Color[w*h];
- for (int y = 0; y < h; ++y)
- {
- for (int x = 0; x < w; ++x)
- {
- bitmap32[x + y * w].set(0xff, 0xff, 0xff, bitmap[x + y * w]);
- }
- }
- free(bitmap);
- return bitmap32;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // TTF
- /////////////////////////////////////////////////////////////////////////////
-
- #include "../shader/je_font.shader.h"
-
- using namespace std;
- using namespace JinEngine::Math;
-
- const int TTF::TEXTURE_WIDTHS[] = { 128, 256, 256, 512, 512, 1024, 1024 };
- const int TTF::TEXTURE_HEIGHTS[] = { 128, 128, 256, 256, 512, 512, 1024 };
-
- /* little endian unicode */
- static const char* unicodeLittleEndian(const char* p, unsigned* res)
- {
- }
-
- ///*static*/ TTF* TTF::createTTF(TTFData* fontData, unsigned int fontSzie)
- //{
- // TTF* ttf;
- // try
- // {
- // ttf = new TTF(fontData, fontSzie);
- // }
- // catch (...)
- // {
- // return nullptr;
- // }
- // return ttf;
- //}
-
- TTF::TTF(TTFData* f, unsigned int fontSize)
- : Font(fontSize)
- , cursor(0, 0)
- , ttf(f)
- {
- ttf->pushTTFsize(fontSize);
- ttf->getVMetrics(&baseline, &descent);
- estimateSize();
- ttf->popTTFsize();
- /* create a default texture */
- createAtlas();
- }
-
- /* estimate the size of atlas texture */
- void TTF::estimateSize()
- {
- for (int level = 0; level <= TEXTURE_SIZE_LEVEL_MAX; ++level)
- {
- if (descent * (descent*0.8) * 96 <= TEXTURE_WIDTHS[level] * TEXTURE_HEIGHTS[level])
- {
- textureWidth = TEXTURE_WIDTHS[level];
- textureHeight = TEXTURE_HEIGHTS[level];
- break;
- }
- }
- }
-
- TTF::~TTF()
- {
- }
-
- GLuint TTF::createAtlas()
- {
- GLuint t;
- gl.flushError();
- t = gl.genTexture();
- gl.bindTexture(t);
- gl.setTexParameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- gl.setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- gl.setTexParameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- gl.setTexParameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- gl.texImage(GL_RGBA8, textureWidth, textureHeight, GL_RGBA, GL_UNSIGNED_BYTE);
- if (glGetError() != GL_NO_ERROR)
- {
- glDeleteTextures(1, &t);
- gl.bindTexture(0);
- return 0;
- }
- atlases.push_back(t);
- gl.bindTexture(0);
- return t;
- }
-
- void TTF::print(const Content& t, int x, int y, int lineheight, int spacing)
- {
- Page* page = typeset(t, lineheight, spacing);
- print(page, x, y);
- delete page;
- }
-
- Page* TTF::typeset(const Content& text, int lineheight, int spacing)
- {
- Page* page = new Page();
- page->font = this;
- vector<GlyphArrayDrawInfo>& glyphinfolist = page->glyphinfolist;
- vector<GlyphVertex>& glyphvertices = page->glyphvertices;
- int texture = -1;
- TTFGlyph* glyph = nullptr;
- GlyphVertex vertex;
- Vector2<int> p(0, 0);
- int i = 0;
-
- #define glyphvertices_push(_x, _y, _u, _v) \
- vertex.x = _x; vertex.y = _y;\
- vertex.u = _u; vertex.v = _v;\
- glyphvertices.push_back(vertex);
-
- #define glyphlize(c)\
- do{\
- glyph = &findGlyph(c); \
- if (texture != glyph->atlas) \
- { \
- GlyphArrayDrawInfo info; \
- info.start = i; \
- info.count = 0; \
- info.texture = glyph->atlas; \
- texture = glyph->atlas; \
- glyphinfolist.push_back(info); \
- } \
- glyphinfolist[glyphinfolist.size() - 1].count += 4; \
- TTFGlyph::Bbox& bbox = glyph->bbox; \
- glyphvertices_push(p.x, p.y, bbox.x, bbox.y); \
- glyphvertices_push(p.x, p.y + glyph->height, bbox.x, bbox.y + bbox.h); \
- glyphvertices_push(p.x + glyph->width, p.y + glyph->height, bbox.x + bbox.w, bbox.y + bbox.h); \
- glyphvertices_push(p.x + glyph->width, p.y, bbox.x + bbox.w, bbox.y); \
- }while(0)
-
- for (Codepoint c : text)
- {
- if (c == 0x0D)
- continue;
- if (c == 0x0A)
- {
- /* new line */
- p.y += lineheight;
- p.x = 0;
- continue;
- }
- if (c == 0x09)
- {
- // tab = 4*space
- unsigned cw = getCharWidth(0x20);
- p.x += cw * 4;
- continue;
- }
- glyphlize(c);
- p.x += glyph->width + spacing;
- i += 4;
- }
- getTextBox(text, &page->size.w, &page->size.h, lineheight, spacing);
- return page;
- }
-
- Page* TTF::typeset(const Text& text, int lineheight, int spacing)
- {
- return typeset(*text, lineheight, spacing);
- }
-
- void TTF::print(const Page* page, int x, int y)
- {
- Shader* shader = Shader::getCurrentShader();
- const vector<GlyphArrayDrawInfo>& glyphinfolist = page->glyphinfolist;
- const vector<GlyphVertex>& glyphvertices = page->glyphvertices;
- gl.ModelMatrix.setTransformation(x, y, 0, 1, 1, 0, 0);
- shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
- shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
- for (int i = 0; i < glyphinfolist.size(); ++i)
- {
- const GlyphArrayDrawInfo& info = glyphinfolist[i];
- shader->bindVertexPointer(2, GL_INT, sizeof(GlyphVertex), &glyphvertices[info.start].x);
- shader->bindUVPointer(2, GL_FLOAT, sizeof(GlyphVertex), &glyphvertices[info.start].u);
- gl.bindTexture(info.texture);
- gl.drawArrays(GL_QUADS, 0, info.count);
- gl.bindTexture(0);
- }
- }
-
- void TTF::print(const Text& text, int x, int y, int lineheight, int spacing /* = 0 */)
- {
- print(*text, x, y, lineheight, spacing);
- }
-
- int TTF::getCharWidth(int c)
- {
- int adw, lsb;
- ttf->pushTTFsize(mFontSize);
- ttf->getHMetrics(c, &adw, &lsb);
- ttf->popTTFsize();
- return adw;
- }
-
- int TTF::getCharHeight(int c)
- {
- return descent;
- }
-
- int TTF::getTextWidth(const Content& t, int spacing)
- {
- ttf->pushTTFsize(mFontSize);
- int res = 0;
- int tmp = 0;
- for (Codepoint c : t)
- {
- if (c == 0x0D)
- continue;
- if (c == 0x0A)
- {
- tmp = 0;
- continue;
- }
- tmp += getCharWidth(c) + spacing;
- if (tmp > res)
- res = tmp;
- }
- ttf->popTTFsize();
- return res;
- }
-
- int TTF::getTextHeight(const Content& t, int lineheight)
- {
- ttf->pushTTFsize(mFontSize);
- int res = 0;
- bool newline = true;
- for (Codepoint c : t)
- {
- if (c == 0x0A)
- newline = true;
- else if (c == 0x0D);
- else if (newline)
- {
- newline = false;
- res += lineheight;
- }
- }
- ttf->popTTFsize();
- return res;
- }
-
- void TTF::getTextBox(const Content& text, int* w, int* h, int lineheight, int spacing)
- {
- ttf->pushTTFsize(mFontSize);
- *w = 0;
- *h = 0;
- int tmp = 0;
- bool newline = true;
- for (Codepoint c : text)
- {
- if (c == 0x0D)
- continue;
- if (c == 0x0A)
- {
- tmp = 0;
- newline = true;
- continue;
- }
- else if (newline)
- {
- newline = false;
- *h += lineheight;
- }
- tmp += getCharWidth(c) + spacing;
- if (tmp > *w)
- *w = tmp;
- }
- ttf->popTTFsize();
- }
-
- TTF::TTFGlyph& TTF::bakeGlyph(unsigned int character)
- {
- int w, h, xoff, yoff;
- ttf->pushTTFsize(mFontSize);
- GLuint atlas = atlases.back();
- const Color* bitmap = ttf->getCodepointBitmap(character, &w, &h, &xoff, &yoff);
- int adw, lsb;
- {
- /* bake glyph */
- ttf->getHMetrics(character, &adw, &lsb);
- ttf->popTTFsize();
- if (cursor.x + adw > textureWidth )
- {
- cursor.x = 0;
- cursor.y += descent;
- if (cursor.y + descent * 2 > textureHeight)
- {
- /* create new atlas */
- atlas = createAtlas();
- cursor.y = 0;
- }
- }
- gl.bindTexture(atlas);
- gl.texSubImage(cursor.x + xoff, cursor.y + yoff + baseline, w, h, GL_RGBA, GL_UNSIGNED_BYTE, bitmap);
- gl.bindTexture();
- delete[] bitmap;
- }
- TTFGlyph glyph;
- glyph.atlas = atlas;
- glyph.bbox.x = cursor.x / (float)textureWidth;
- glyph.bbox.y = cursor.y / (float)textureHeight;
- glyph.bbox.w = adw / (float)textureWidth;
- glyph.bbox.h = descent / (float)textureHeight;
- glyph.width = adw;
- glyph.height = descent;
- glyphs.insert(std::pair<unsigned int, TTFGlyph>(character, glyph));
- cursor.x += adw;
- return glyphs[character];
- }
-
- TTF::TTFGlyph& TTF::findGlyph(unsigned int character)
- {
- map<unsigned int, TTFGlyph>::iterator it = glyphs.find(character);
- if (it != glyphs.end())
- return it->second;
- else
- return bakeGlyph(character);
- }
-
- } // namespace Graphics
-} // namespace JinEngine
-
-#endif // defined(jin_graphics) \ No newline at end of file
diff --git a/src/libjin/Graphics/Font/je_ttf.h b/src/libjin/Graphics/Font/je_ttf.h
deleted file mode 100644
index e3d63b2..0000000
--- a/src/libjin/Graphics/Font/je_ttf.h
+++ /dev/null
@@ -1,288 +0,0 @@
-#ifndef __JETTF_H
-#define __JE_TTF_H
-#include "../../core/je_configuration.h"
-#if defined(jin_graphics)
-
-#include <vector>
-#include <map>
-
-#include "../../3rdparty/stb/stb_truetype.h"
-#include "../../math/je_quad.h"
-
-#include "../je_color.h"
-#include "../je_graphic.h"
-
-#include "je_page.h"
-#include "je_font.h"
-#include "je_text.h"
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- class TTF;
-
- //
- // TTFData
- // |- TTF(14px)
- // |- TTF(15px)
- // .
- // .
- // .
- //
- class TTFData
- {
- public:
-
- ///
- ///
- ///
- static TTFData* createTTFData(const unsigned char* data, unsigned int size);
-
- ///
- ///
- ///
- ~TTFData();
-
- ///
- ///
- ///
- TTF* createTTF(unsigned ttfsize);
-
- ///
- ///
- ///
- void pushTTFsize(unsigned ttfsize);
-
- ///
- ///
- ///
- void popTTFsize();
-
- ///
- ///
- ///
- Channel* getCodepointBitmapAlpha(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const;
-
- ///
- ///
- ///
- Color* getCodepointBitmap(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const;
-
- ///
- ///
- ///
- void getVMetrics(int* baseline, int* descent);
-
- ///
- ///
- ///
- void getHMetrics(unsigned int codepoint, int* advanceWidth, int* leftSideBearing);
-
- private:
-
- ///
- ///
- ///
- static const unsigned int FONT_SIZE = 12;
-
- ///
- ///
- ///
- TTFData(const unsigned char* data, unsigned int size);
-
- ///
- ///
- ///
- stbtt_fontinfo info;
-
- ///
- ///
- ///
- struct
- {
- unsigned char* data;
- unsigned int size;
- } raw;
-
- ///
- ///
- ///
- std::vector<float> scales;
-
- };
-
- class TTF : public Font
- {
- public:
- //static TTF* createTTF(TTFData* ttfData, unsigned ttfSzie);
-
- ///
- ///
- ///
- Page* typeset(const Text& text, int lineheight, int spacing = 0) override;
-
- ///
- ///
- ///
- Page* typeset(const Content& text, int lineheight, int spacing = 0) override;
-
- ///
- ///
- ///
- void print(const Text& text, int x, int y, int lineheight, int spacing = 0) override;
-
- ///
- ///
- ///
- void print(const Content& text, int x, int y, int lineheight, int spacing = 0) override;
-
- ///
- ///
- ///
- void print(const Page* page, int x, int y) override;
-
- ///
- ///
- ///
- ~TTF();
-
- private:
-
- friend class TTFData;
-
- ///
- ///
- ///
- struct TTFGlyph
- {
- GLuint atlas;
- // normalized coordinates
- struct Bbox
- {
- float x, y;
- float w, h;
- } bbox;
- // glyph size in pixel
- unsigned int width, height;
- };
-
- ///
- ///
- ///
- static const int TEXTURE_SIZE_LEVELS_COUNT = 7;
-
- ///
- ///
- ///
- static const int TEXTURE_SIZE_LEVEL_MAX = TEXTURE_SIZE_LEVELS_COUNT - 1;
-
- ///
- ///
- ///
- static const int TEXTURE_WIDTHS[TEXTURE_SIZE_LEVELS_COUNT];
-
- ///
- ///
- ///
- static const int TEXTURE_HEIGHTS[TEXTURE_SIZE_LEVELS_COUNT];
-
- ///
- ///
- ///
- TTF(TTFData* ttf, Codepoint ttfSize);
-
- ///
- ///
- ///
- void estimateSize();
-
- ///
- ///
- ///
- GLuint createAtlas();
-
- ///
- ///
- ///
- TTFGlyph& bakeGlyph(Codepoint character);
-
- ///
- ///
- ///
- TTFGlyph& findGlyph(Codepoint character);
-
- ///
- ///
- ///
- int getCharWidth(int c);
-
- ///
- ///
- ///
- int getCharHeight(int c);
-
- ///
- ///
- ///
- int getTextWidth(const Content& text, int spacing = 0);
-
- ///
- ///
- ///
- int getTextHeight(const Content& text, int lineheight);
-
- ///
- ///
- ///
- void getTextBox(const Content& text, int* w, int* h, int lineheight, int spacing = 0);
-
- ///
- ///
- ///
- int textureWidth;
-
- ///
- ///
- ///
- int textureHeight;
-
- ///
- ///
- ///
- std::vector<GLuint> atlases;
-
- ///
- ///
- ///
- std::map<Codepoint, TTFGlyph> glyphs;
-
- ///
- ///
- ///
- TTFData* ttf;
-
- ///
- ///
- ///
- int baseline;
-
- ///
- ///
- ///
- int descent;
-
- ///
- ///
- ///
- Math::Vector2<float> cursor;
-
- };
-
- } // namespace Graphics
-} // namespace JinEngine
-
-#endif // defined(jin_graphics)
-
-#endif // __JE_FONT_H \ No newline at end of file
diff --git a/src/libjin/Graphics/Shader/je_jsl_compiler.cpp b/src/libjin/Graphics/Shader/je_jsl_compiler.cpp
deleted file mode 100644
index 81b14e8..0000000
--- a/src/libjin/Graphics/Shader/je_jsl_compiler.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-#include "../../core/je_configuration.h"
-#if defined(jin_graphics) && (jin_graphics & jin_graphics_shader)
-
-#include "../../Filesystem/je_buffer.h"
-
-#include "je_jsl_compiler.h"
-
-using namespace std;
-using namespace JinEngine::Filesystem;
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
-#include "je_base.shader.h"
-
- bool JSLCompiler::compile(const string& jsl, string* vertex_shader, string* fragment_shader)
- {
- // parse shader source, need some optimizations
- int loc_VERTEX_SHADER = jsl.find("#VERTEX_SHADER");
- int loc_END_VERTEX_SHADER = jsl.find("#END_VERTEX_SHADER");
- int loc_FRAGMENT_SHADER = jsl.find("#FRAGMENT_SHADER");
- int loc_END_FRAGMENT_SHADER = jsl.find("#END_FRAGMENT_SHADER");
- if (loc_VERTEX_SHADER == string::npos
- || loc_END_VERTEX_SHADER == string::npos
- || loc_FRAGMENT_SHADER == string::npos
- || loc_END_FRAGMENT_SHADER == string::npos
- )
- return false;
- // Load vertex and fragment shader source into buffers.
- {
- // Compile JSL vertex program.
- int start = loc_VERTEX_SHADER + strlen("#VERTEX_SHADER");
- *vertex_shader = jsl.substr(start, loc_END_VERTEX_SHADER - start);
- Buffer vbuffer = Buffer(vertex_shader->length() + BASE_VERTEX_SHADER_SIZE);
- formatVertexShader((char*)&vbuffer, vertex_shader->c_str());
- vertex_shader->assign((char*)&vbuffer);
- }
- {
- // Compile JSL fragment program.
- int start = loc_FRAGMENT_SHADER + strlen("#FRAGMENT_SHADER");
- *fragment_shader = jsl.substr(start, loc_END_FRAGMENT_SHADER - start);
- Buffer fbuffer = Buffer(fragment_shader->length() + BASE_FRAGMENT_SHADER_SIZE);
- formatFragmentShader((char*)&fbuffer, fragment_shader->c_str());
- fragment_shader->assign((char*)&fbuffer);
- }
- return true;
- }
-
- } // namespace Graphics
-} // namespace JinEngine
-
-#endif // (jin_graphics) && (jin_graphics & jin_graphics_shader) \ No newline at end of file
diff --git a/src/libjin/Graphics/Shader/je_jsl_compiler.h b/src/libjin/Graphics/Shader/je_jsl_compiler.h
deleted file mode 100644
index 29129e1..0000000
--- a/src/libjin/Graphics/Shader/je_jsl_compiler.h
+++ /dev/null
@@ -1,42 +0,0 @@
-#ifndef __JE_JSL_COMPILER_H
-#define __JE_JSL_COMPILER_H
-
-#include "../../core/je_configuration.h"
-#if defined(jin_graphics) && (jin_graphics & jin_graphics_shader)
-
-#include <string>
-
-#include "../../common/je_singleton.hpp"
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- ///
- /// Compile JSL into GLSL.
- ///
- class JSLCompiler : public Singleton<JSLCompiler>
- {
- public:
- ///
- /// Compile JSL shader source into GLSL.
- ///
- /// @param jsl JSL shader source.
- /// @param glsl_vertex Output of vertex glsl shader source.
- /// @param glsl_fragment Output of fragment glsl shader source.
- /// @return True if compile successful, otherwise return false.
- ///
- bool compile(const std::string& jsl, std::string* glsl_vertex, std::string* glsl_fragment);
-
- private:
- singleton(JSLCompiler);
-
- };
-
- } // namespace Graphics
-} // namespace JinEngine
-
-#endif // (jin_graphics) && (jin_graphics & jin_graphics_shader)
-
-#endif // __JE_JSL_COMPILER_H \ No newline at end of file
diff --git a/src/libjin/Graphics/Shader/je_shader.cpp b/src/libjin/Graphics/Shader/je_shader.cpp
deleted file mode 100644
index b0e7506..0000000
--- a/src/libjin/Graphics/Shader/je_shader.cpp
+++ /dev/null
@@ -1,278 +0,0 @@
-#include "../../core/je_configuration.h"
-#if defined(jin_graphics) && (jin_graphics & jin_graphics_shader)
-
-#include <iostream>
-
-#include "../../filesystem/je_buffer.h"
-#include "../../utils/je_macros.h"
-
-#include "je_jsl_compiler.h"
-#include "je_shader.h"
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- using namespace std;
- using namespace JinEngine::Filesystem;
-
- //
- // default_texture
- // base_shader
- // SHADER_FORMAT_SIZE
- // formatShader
- //
- #include "je_default.shader.h"
-
- //
- // https://stackoverflow.com/questions/27941496/use-sampler-without-passing-through-value
- // The default value of a sampler variable is 0. From the GLSL 3.30 spec,
- // section "4.3.5 Uniforms":
- //
- // The link time initial value is either the value of the variable's
- // initializer, if present, or 0 if no initializer is present.Sampler
- // types cannot have initializers.
- //
- // Since a value of 0 means that it's sampling from texture unit 0, it will
- // work without ever setting the value as long as you bind your textures to
- // unit 0. This is well defined behavior.
- //
- // Since texture unit 0 is also the default until you call glActiveTexture()
- // with a value other than GL_TEXTURE0, it's very common to always use unit
- // 0 as long as shaders do not need more than one texture.Which means that
- // often times, setting the sampler uniforms is redundant for simple
- // applications.
- //
- // I would still prefer to always set the values.If nothing else, it makes
- // it clear to anybody reading your code that you really mean to sample from
- // texture unit 0, and did not just forget to set the value.
- //
- const int DEFAULT_TEXTURE_UNIT = 0;
-
- /*static*/ Shader* Shader::CurrentShader = nullptr;
-
- Shader* Shader::createShader(const string& program)
- {
- Shader* shader = nullptr;
- try
- {
- shader = new Shader(program);
- }
- catch(...)
- {
- return nullptr;
- }
- return shader;
- }
-
- Shader::Shader(const string& program)
- : mCurrentTextureUnit(DEFAULT_TEXTURE_UNIT)
- {
- if (!compile(program))
- throw 0;
- }
-
- Shader::~Shader()
- {
- if (CurrentShader == this)
- unuse();
- // delete shader program
- glDeleteShader(mPID);
- }
-
- bool Shader::compile(const string& program)
- {
- string vertex_shader, fragment_shader;
- // Compile JSL shader source into GLSL shader source.
- JSLCompiler* compiler = JSLCompiler::get();
- if (!compiler->compile(program, &vertex_shader, &fragment_shader))
- {
- return false;
- }
-#define glsl(SHADER_MODE, SHADER, SRC) \
-do{ \
-const GLchar* src = SRC.c_str(); \
-glShaderSource(SHADER, 1, &src, NULL); \
-glCompileShader(SHADER); \
-GLint success; \
-glGetShaderiv(SHADER, GL_COMPILE_STATUS, &success); \
-if (success == GL_FALSE) \
- return false; \
-}while(0)
- // Compile vertex shader.
- GLuint vid = glCreateShader(GL_VERTEX_SHADER);
- glsl(GL_VERTEX_SHADER, vid, vertex_shader);
- // Compile fragment shader.
- GLuint fid = glCreateShader(GL_FRAGMENT_SHADER);
- glsl(GL_FRAGMENT_SHADER, fid, fragment_shader);
-#undef glsl
- // Create OpenGL shader program.
- mPID = glCreateProgram();
- glAttachShader(mPID, vid);
- glAttachShader(mPID, fid);
- glLinkProgram(mPID);
- GLint success;
- glGetProgramiv(mPID, GL_LINK_STATUS, &success);
- if (success == GL_FALSE)
- return false;
- }
-
- static inline GLint getMaxTextureUnits()
- {
- GLint maxTextureUnits = 0;
- glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
- return maxTextureUnits;
- }
-
- void Shader::use()
- {
- glUseProgram(mPID);
- CurrentShader = this;
- sendInt(SHADER_MAIN_TEXTURE, DEFAULT_TEXTURE_UNIT);
- }
-
- /*static*/ void Shader::unuse()
- {
- glUseProgram(0);
- CurrentShader = nullptr;
- }
-
- GLint Shader::claimTextureUnit(const std::string& name)
- {
- std::map<std::string, GLint>::iterator unit = mTextureUnits.find(name);
- if (unit != mTextureUnits.end())
- return unit->second;
- static GLint MAX_TEXTURE_UNITS = getMaxTextureUnits();
- if (++mCurrentTextureUnit >= MAX_TEXTURE_UNITS)
- return 0;
- mTextureUnits[name] = mCurrentTextureUnit;
- return mCurrentTextureUnit;
- }
-
- #define checkJSL() \
- if (CurrentShader != this) \
- return
-
- void Shader::sendInt(const char* name, int value)
- {
- checkJSL();
- int loc = glGetUniformLocation(mPID, name);
- glUniform1i(loc, value);
- }
-
- void Shader::sendFloat(const char* variable, float number)
- {
- checkJSL();
- int loc = glGetUniformLocation(mPID, variable);
- glUniform1f(loc, number);
- }
-
- //
- // https://www.douban.com/note/627332677/
- // struct TextureUnit
- // {
- // GLuint targetTexture1D;
- // GLuint targetTexture2D;
- // GLuint targetTexture3D;
- // GLuint targetTextureCube;
- // ...
- // };
- //
- // TextureUnit mTextureUnits[GL_MAX_TEXTURE_IMAGE_UNITS]
- // GLuint mCurrentTextureUnit = 0;
- //
- void Shader::sendTexture(const char* variable, const Texture* tex)
- {
- checkJSL();
- GLint location = glGetUniformLocation(mPID, variable);
- if (location == -1)
- return;
- GLint unit = claimTextureUnit(variable);
- if (unit == 0)
- {
- // TODO: 쳣󶨵
- return;
- }
- gl.activeTexUnit(unit);
- glUniform1i(location, unit);
- gl.bindTexture(tex->getTexture());
- gl.activeTexUnit(0);
- }
-
- void Shader::sendCanvas(const char* variable, const Canvas* canvas)
- {
- checkJSL();
- GLint location = glGetUniformLocation(mPID, variable);
- if (location == -1)
- return;
- GLint unit = claimTextureUnit(variable);
- if (unit == 0)
- {
- // TODO: 쳣󶨵
- return;
- }
- glUniform1i(location, unit);
- glActiveTexture(GL_TEXTURE0 + unit);
- gl.bindTexture(canvas->getTexture());
-
- glActiveTexture(GL_TEXTURE0);
- }
-
- void Shader::sendVec2(const char* name, float x, float y)
- {
- checkJSL();
- int loc = glGetUniformLocation(mPID, name);
- glUniform2f(loc, x, y);
- }
-
- void Shader::sendVec3(const char* name, float x, float y, float z)
- {
- checkJSL();
- int loc = glGetUniformLocation(mPID, name);
- glUniform3f(loc, x, y, z);
- }
-
- void Shader::sendVec4(const char* name, float x, float y, float z, float w)
- {
- checkJSL();
- int loc = glGetUniformLocation(mPID, name);
- glUniform4f(loc, x, y, z, w);
- }
-
- void Shader::sendColor(const char* name, const Color* col)
- {
- checkJSL();
- int loc = glGetUniformLocation(mPID, name);
- glUniform4f(loc,
- col->r / 255.f,
- col->g / 255.f,
- col->b / 255.f,
- col->a / 255.f
- );
- }
-
- void Shader::sendMatrix4(const char* name, const Math::Matrix* mat4)
- {
- int loc = glGetUniformLocation(mPID, name);
- glUniformMatrix4fv(loc, 1, GL_FALSE, mat4->getElements());
- }
-
- void Shader::bindVertexPointer(int n, GLenum type, GLsizei stride, const GLvoid * pointers)
- {
- GLint loc = glGetAttribLocation(mPID, SHADER_VERTEX_COORDS);
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(loc, n, type, GL_FALSE, stride, pointers);
- }
-
- void Shader::bindUVPointer(int n, GLenum type, GLsizei stride, const GLvoid * pointers)
- {
- GLint loc = glGetAttribLocation(mPID, SHADER_TEXTURE_COORDS);
- glEnableVertexAttribArray(1);
- glVertexAttribPointer(loc, n, type, GL_FALSE, stride, pointers);
- }
-
- } // namespace Graphics
-} // namespace JinEngine
-
-#endif // (jin_graphics) && (jin_graphics & jin_graphics_shader) \ No newline at end of file
diff --git a/src/libjin/Graphics/Shader/je_shader.h b/src/libjin/Graphics/Shader/je_shader.h
deleted file mode 100644
index 928fb0a..0000000
--- a/src/libjin/Graphics/Shader/je_shader.h
+++ /dev/null
@@ -1,200 +0,0 @@
-#ifndef __JE_SHADER_H
-#define __JE_SHADER_H
-
-#include "../../core/je_configuration.h"
-#if defined(jin_graphics) && (jin_graphics & jin_graphics_shader)
-
-#include <string>
-#include <map>
-
-#include "../../3rdparty/GLee/GLee.h"
-
-#include "../je_color.h"
-#include "../je_texture.h"
-#include "../je_canvas.h"
-
-#include "je_base.shader.h"
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- ///
- /// Built in shader program.
- ///
- /// Built in shader program written with custom shading language called JSL (jin
- /// shading language). A JSL program is compiled into glsl, so most glsl built in
- /// functions and structs are available in JSL.
- ///
- class Shader
- {
- public:
- ///
- /// Create shader program from source code.
- ///
- /// @param source The shader source code.
- ///
- static Shader* createShader(const std::string& source);
-
- ///
- /// Get current shader.
- ///
- /// @return Current used shader program.
- ///
- static inline Shader* getCurrentShader() { return CurrentShader; }
-
- ///
- /// Unuse current shader.
- ///
- static void unuse();
-
- ///
- /// Destructor of shader.
- ///
- virtual ~Shader();
-
- ///
- /// Use specific shader.
- ///
- void use();
-
- ///
- /// Send float value to shader.
- ///
- /// @param name Name of the uniform variable to be assigned.
- /// @param number Value of uniform variable to be sent.
- ///
- void sendFloat(const char* name, float number);
-
- ///
- /// Send texture to shader.
- ///
- /// @param name Name of the uniform variable to be assigned.
- /// @param texture Texture to be sent.
- ///
- void sendTexture(const char* name, const Texture* texture);
-
- ///
- /// Send integer value to shader
- ///
- /// @param name Name of the uniform variable to be assigned.
- /// @param value Value to be sent.
- ///
- void sendInt(const char* name, int value);
-
- ///
- /// Send 2D vector to shader.
- ///
- /// @param name Name of the uniform variable to be assigned.
- /// @param x X value of the vector to be sent.
- /// @param y Y value of the vector to be sent.
- ///
- void sendVec2(const char* name, float x, float y);
-
- ///
- /// Send 3D vector to shader.
- ///
- /// @param name Name of the uniform variable to be assigned.
- /// @param x X value of the vector to be sent.
- /// @param y Y value of the vector to be sent.
- /// @param z Z value of the vector to be sent.
- ///
- void sendVec3(const char* name, float x, float y, float z);
-
- ///
- /// Send 4D vector to shader.
- ///
- /// @param name Name of the uniform variable to be assigned.
- /// @param x X value of the vector to be sent.
- /// @param y Y value of the vector to be sent.
- /// @param z Z value of the vector to be sent.
- /// @param w W value of the vector to be sent.
- ///
- void sendVec4(const char* name, float x, float y, float z, float w);
-
- ///
- /// Send canvas to shader.
- ///
- /// @param name Name of the uniform variable to be assigned.
- /// @param canvas Canvas to be sent.
- ///
- void sendCanvas(const char* name, const Canvas* canvas);
-
- ///
- /// Send color to shader.
- ///
- /// @param name Name of the uniform variable to be assigned.
- /// @param color Color to be sent.
- ///
- void sendColor(const char* name, const Color* color);
-
- ///
- /// Send 4 by 4 matrix to shader.
- ///
- /// @param name Name of the uniform variable to be assigned.
- /// @param mat4 Matrix to be sent.
- ///
- void sendMatrix4(const char* name, const Math::Matrix* mat4);
-
- ///
- /// Set vertices value.
- ///
- /// @param n Number of vertices.
- /// @param type Data type of each component in the array.
- /// @param stride Byte offset between consecutive generic vertex attributes.
- /// @param pointers Pointer to the first component of the first generic vertex
- /// attribute in the array.
- ///
- void bindVertexPointer(int n, GLenum type, GLsizei stride, const GLvoid * pointers);
-
- ///
- /// Set texture UV coordinates.
- ///
- /// @param n Number of vertices.
- /// @param type Data type of each component in the array.
- /// @param stride Byte offset between consecutive generic vertex attributes.
- /// @param pointers Pointer to the first component of the first generic vertex
- /// attribute in the array.
- ///
- void bindUVPointer(int n, GLenum type, GLsizei stride, const GLvoid * pointers);
-
- protected:
- ///
- /// Reference of current used shader.
- ///
- static Shader* CurrentShader;
-
- ///
- /// Get texture unit of the uniform texture. If not, assign one.
- ///
- /// @param name Name of the texture uniform variable.
- /// @return Texture unit which texture variable be assigned.
- ///
- GLint claimTextureUnit(const std::string& name);
-
- ///
- /// Shader constructor.
- ///
- Shader(const std::string& program);
-
- ///
- /// Compile JSL program into GLSL source.
- ///
- /// @param program JSL source code.
- /// @return Return true if compile successed, otherwise return false.
- ///
- bool compile(const std::string& program);
-
- GLuint mPID;
- GLint mCurrentTextureUnit;
- std::map<std::string, GLint> mTextureUnits;
-
- };
-
- } // namespace Graphics
-} // namespace JinEngine
-
-#endif // (jin_graphics) && (jin_graphics & jin_graphics_shader)
-
-#endif // __JE_SHADER_H \ No newline at end of file
diff --git a/src/libjin/Graphics/animation/je_animation.h b/src/libjin/Graphics/animation/je_animation.h
deleted file mode 100644
index f330a0c..0000000
--- a/src/libjin/Graphics/animation/je_animation.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef __JE_ANIMATION_H
-#define __JE_ANIMATION_H
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- ///
- ///
- ///
- class Animation
- {
-
- };
-
- } // namespace Graphics
-} // namespace JinEngine
-
-#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/animation/je_clip.h b/src/libjin/Graphics/animation/je_clip.h
deleted file mode 100644
index d6709dc..0000000
--- a/src/libjin/Graphics/animation/je_clip.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef __JE_CLIP_H
-#define __JE_CLIP_H
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- ///
- /// Animation clip with key.
- ///
- class Clip
- {
-
- };
-
- } // namespace Graphics
-} // namespace JinEngine
-
-#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/animations/je_animation.cpp b/src/libjin/Graphics/animations/je_animation.cpp
new file mode 100644
index 0000000..4fe673a
--- /dev/null
+++ b/src/libjin/Graphics/animations/je_animation.cpp
@@ -0,0 +1,14 @@
+#include "je_animation.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Animations
+ {
+
+
+
+ }
+ }
+} \ No newline at end of file
diff --git a/src/libjin/Graphics/animations/je_animation.h b/src/libjin/Graphics/animations/je_animation.h
new file mode 100644
index 0000000..9926cf9
--- /dev/null
+++ b/src/libjin/Graphics/animations/je_animation.h
@@ -0,0 +1,64 @@
+#ifndef __JE_ANIMATION_H__
+#define __JE_ANIMATION_H__
+
+#include <vector>
+#include <string>
+
+#include "../je_sprite.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Animations
+ {
+
+ ///
+ /// Animation clip with key.
+ ///
+ class Animation
+ {
+ public:
+ void update(float dt);
+
+ void start();
+ void pause();
+ void stop();
+ void rewind();
+ void setSpeed(float speed);
+
+ ///
+ /// Get current frame index.
+ ///
+ uint getCurrentFrameIndex();
+
+ ///
+ ///
+ ///
+ Sprite* getCurrentFrame();
+
+ ///
+ /// Set current frame index.
+ ///
+ /// @param frame Current frame to play.
+ ///
+ void setCurrentFrame(uint frame);
+
+ private:
+ ///
+ /// Key frames.
+ ///
+ std::vector<Sprite*> mFrames;
+
+ ///
+ /// Animation playing speed.
+ ///
+ float mSpeed;
+
+ };
+
+ } // namespace Animations
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/animations/je_animator.cpp b/src/libjin/Graphics/animations/je_animator.cpp
new file mode 100644
index 0000000..360bd5d
--- /dev/null
+++ b/src/libjin/Graphics/animations/je_animator.cpp
@@ -0,0 +1,14 @@
+#include "je_animator.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Animations
+ {
+
+
+
+ }
+ }
+} \ No newline at end of file
diff --git a/src/libjin/Graphics/animations/je_animator.h b/src/libjin/Graphics/animations/je_animator.h
new file mode 100644
index 0000000..6510a7d
--- /dev/null
+++ b/src/libjin/Graphics/animations/je_animator.h
@@ -0,0 +1,50 @@
+#ifndef __JE_ANIMATOR_H__
+#define __JE_ANIMATOR_H__
+
+#include <map>
+#include <vector>
+#include <string>
+
+#include "je_animation.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Animations
+ {
+
+ ///
+ ///
+ ///
+ class Animator
+ {
+ public:
+ void addAnimation(const std::string& key, Animation* clip);
+ bool hasKey(const std::string& key);
+
+ void play();
+ void switchAnimation(const std::string& key);
+
+ ///
+ /// Control clips.
+ ///
+ void stopAnimation();
+ void pauseAnimation();
+ void rewindAnimation();
+ void startAnimation();
+
+ private:
+ ///
+ /// Map a key to clips.
+ ///
+ std::map<std::string, Animation*> mAnimations;
+ Animation* mCurrentAnimation;
+
+ };
+
+ } // namespace Animations
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/fonts/je_decoder.cpp b/src/libjin/Graphics/fonts/je_decoder.cpp
new file mode 100644
index 0000000..02112a0
--- /dev/null
+++ b/src/libjin/Graphics/fonts/je_decoder.cpp
@@ -0,0 +1,96 @@
+#include <stdlib.h>
+#include <string.h>
+#include "je_decoder.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Fonts
+ {
+
+ /* utf8 byte string to unicode codepoint */
+ static const char *utf8toCodepoint(const char *p, unsigned *res) {
+ return nullptr;
+
+ }
+
+ /////////////////////////////////////////////////////////////////////////////
+ // decoders
+ /////////////////////////////////////////////////////////////////////////////
+
+ const void* Utf8::decode(const void* data, Codepoint* res) const
+ {
+ const char* p = (char*)data;
+ unsigned x, mask, shift;
+ switch (*p & 0xf0) {
+ case 0xf0: mask = 0x07; shift = 18; break;
+ case 0xe0: mask = 0x0f; shift = 12; break;
+ case 0xc0:
+ case 0xd0: mask = 0x1f; shift = 6; break;
+ default:
+ *res = *p;
+ return p + 1;
+ }
+ x = (*p & mask) << shift;
+ do {
+ if (*(++p) == '\0') {
+ *res = x;
+ return p;
+ }
+ shift -= 6;
+ x |= (*p & 0x3f) << shift;
+ } while (shift);
+ *res = x;
+ return p + 1;
+ }
+
+ const void* Utf8::next(const void* data) const
+ {
+ const char* p = (char*)data;
+ unsigned x, mask, shift;
+ switch (*p & 0xf0) {
+ case 0xf0: mask = 0x07; shift = 18; break;
+ case 0xe0: mask = 0x0f; shift = 12; break;
+ case 0xc0:
+ case 0xd0: mask = 0x1f; shift = 6; break;
+ default:
+ return p + 1;
+ }
+ x = (*p & mask) << shift;
+ do {
+ if (*(++p) == '\0') {
+ return p;
+ }
+ shift -= 6;
+ x |= (*p & 0x3f) << shift;
+ } while (shift);
+ return p + 1;
+ }
+ /*
+ const void* Utf16::decode(const void* data, Codepoint* res) const
+ {
+ return nullptr;
+ }
+
+ const void* Utf16::next(const void* data) const
+ {
+ return nullptr;
+ }
+ */
+ const void* Ascii::decode(const void* data, Codepoint* res) const
+ {
+ const char* p = (char*)data;
+ *res = *p;
+ return p + 1;
+ }
+
+ const void* Ascii::next(const void* data) const
+ {
+ const char* p = (char*)data;
+ return p + 1;
+ }
+
+ } // namespace Fonts
+ } // namespace Graphics
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/Graphics/fonts/je_decoder.h b/src/libjin/Graphics/fonts/je_decoder.h
new file mode 100644
index 0000000..840cada
--- /dev/null
+++ b/src/libjin/Graphics/fonts/je_decoder.h
@@ -0,0 +1,97 @@
+#ifndef __JE_UTF8_H__
+#define __JE_UTF8_H__
+
+#include <vector>
+
+#include "je_text.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Fonts
+ {
+
+ ///
+ /// Text decoder.
+ ///
+ class Decoder
+ {
+ public:
+
+ ///
+ /// Decode a code unit.
+ ///
+ /// @param data Code units.
+ /// @param codepoint Value of code point.
+ /// @return Next code unit location.
+ ///
+ virtual const void* decode(const void* data, Codepoint* codepoint) const = 0;
+
+ ///
+ /// Get next code unit location.
+ ///
+ /// @param data Code units.
+ /// @return Next code unit location.
+ ///
+ virtual const void* next(const void* data) const = 0;
+
+ };
+
+ ///
+ /// Utf-8 decoder.
+ ///
+ class Utf8 : public Decoder
+ {
+ public:
+
+ ///
+ /// Decode a code unit.
+ ///
+ /// @param data Code units.
+ /// @param codepoint Value of code point.
+ /// @return Next code unit location.
+ ///
+ const void* decode(const void* data, Codepoint* codepoint) const override;
+
+ ///
+ /// Get next code unit location.
+ ///
+ /// @param data Code units.
+ /// @return Next code unit location.
+ ///
+ const void* next(const void* data) const override;
+
+ };
+
+ ///
+ /// Ascii decoder.
+ ///
+ class Ascii : public Decoder
+ {
+ public:
+
+ ///
+ /// Decode a code unit.
+ ///
+ /// @param data Code units.
+ /// @param codepoint Value of code point.
+ /// @return Next code unit location.
+ ///
+ const void* decode(const void* data, Codepoint* codepoint) const override;
+
+ ///
+ /// Get next code unit location.
+ ///
+ /// @param data Code units.
+ /// @return Next code unit location.
+ ///
+ const void* next(const void* data) const override;
+
+ };
+
+ } // namespace Fonts
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/fonts/je_font.h b/src/libjin/Graphics/fonts/je_font.h
new file mode 100644
index 0000000..9581b9f
--- /dev/null
+++ b/src/libjin/Graphics/fonts/je_font.h
@@ -0,0 +1,109 @@
+#ifndef __JE_FONT_H__
+#define __JE_FONT_H__
+
+#include <vector>
+#include "je_text.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Fonts
+ {
+
+ struct Page;
+
+ //
+ // Font
+ // |- TTF
+ // |- TextureFont
+ //
+
+ ///
+ /// Base Font class.
+ ///
+ class Font
+ {
+ public:
+ ///
+ /// Font constructor.
+ ///
+ Font(unsigned fontsize)
+ : mFontSize(fontsize)
+ {
+ }
+
+ ///
+ /// Font destructor.
+ ///
+ virtual ~Font() {};
+
+ ///
+ /// Create page with given text.
+ ///
+ /// @param text Text to be typesetted.
+ /// @param lineheight Line height of text.
+ /// @param spacing Spacing between characters. 0 by default.
+ /// @return Page if created successfully, otherwise return null.
+ ///
+ virtual Page* typeset(const Text& text, int lineheight, int spacing = 0) = 0;
+
+ ///
+ /// Create page with given unicode codepoints.
+ ///
+ /// @param content Unicode codepoints to be typesetted.
+ /// @param lineheight Line height of text.
+ /// @param spacing Spacing between characters. 0 by default.
+ /// @return Page if created successfully, otherwise return null.
+ ///
+ virtual Page* typeset(const Content& content, int lineheight, int spacing = 0) = 0;
+
+ ///
+ /// Render page to given position.
+ ///
+ /// @param page Page to be rendered.
+ /// @param x X value of the position.
+ /// @param y Y value of the position.
+ ///
+ virtual void render(const Page* page, int x, int y) = 0;
+
+ ///
+ /// Render unicode codepoints to given position.
+ ///
+ /// @param content Unicode codepoints to be typesetted.
+ /// @param x X value of the position.
+ /// @param y Y value of the position.
+ /// @param lineheight Line height of the content.
+ /// @param spacing Spacing between characters.
+ ///
+ virtual void render(const Content& content, int x, int y, int lineheight, int spacing = 0) = 0;
+
+ ///
+ /// Render text to given position.
+ ///
+ /// @param text Text to be rendered.
+ /// @param x X value of the position.
+ /// @param y Y value of the position.
+ /// @param lineheight Line height of the text.
+ /// @param spacing Spacing between characters.
+ ///
+ virtual void render(const Text& text, int x, int y, int lineheight, int spacing = 0) = 0;
+
+ ///
+ /// Get font size.
+ ///
+ /// @return Font size.
+ ///
+ inline unsigned getFontSize() { return mFontSize; };
+
+ protected:
+
+ unsigned mFontSize;
+
+ };
+
+ } // namespace Fonts
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif // __JE_FONT_H__
diff --git a/src/libjin/Graphics/fonts/je_page.h b/src/libjin/Graphics/fonts/je_page.h
new file mode 100644
index 0000000..707f53a
--- /dev/null
+++ b/src/libjin/Graphics/fonts/je_page.h
@@ -0,0 +1,54 @@
+#ifndef __JE_PAGE_H__
+#define __JE_PAGE_H__
+
+#include "../../math/je_vector2.hpp"
+
+#include "je_font.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Fonts
+ {
+
+ class Font;
+
+ ///
+ /// Glyphs data to be rendered.
+ ///
+ struct GlyphVertex
+ {
+ int x, y; ///< screen coordinates
+ float u, v; ///< normalized texture uv
+ };
+
+ ///
+ /// Glyphs info for reducing draw call.
+ ///
+ struct GlyphArrayDrawInfo
+ {
+ GLuint texture; ///< atlas
+ unsigned int start; ///< glyph vertex indecies
+ unsigned int count; ///< glyph vertex count
+ };
+
+ ///
+ /// Page to be rendered.
+ ///
+ /// A page is a pre-rendered text struct for reducing draw call. Each page
+ /// keeps a font pointer which should not be changed.
+ ///
+ struct Page
+ {
+ Font* font;
+ std::vector<GlyphArrayDrawInfo> glyphinfolist;
+ std::vector<GlyphVertex> glyphvertices;
+ Math::Vector2<int> size;
+ };
+
+ } // namespace Fonts
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif // __JE_PAGE_H__
diff --git a/src/libjin/Graphics/fonts/je_text.cpp b/src/libjin/Graphics/fonts/je_text.cpp
new file mode 100644
index 0000000..80aaa6a
--- /dev/null
+++ b/src/libjin/Graphics/fonts/je_text.cpp
@@ -0,0 +1,157 @@
+#include <cstring>
+
+#include "je_text.h"
+#include "je_decoder.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Fonts
+ {
+
+ /////////////////////////////////////////////////////////////////////////////
+ // iterator
+ /////////////////////////////////////////////////////////////////////////////
+
+ Text::Iterator::Iterator(const Iterator& itor)
+ : data(itor.data)
+ , p(itor.p)
+ , encode(itor.encode)
+ , length(itor.length)
+ {
+ switch (encode)
+ {
+ case Encode::UTF8: decoder = new Utf8(); break;
+ case Encode::ASCII: decoder = new Ascii(); break;
+ }
+ }
+
+ Text::Iterator::Iterator(const Encode& _encode, const void* _data, unsigned int _length)
+ : data(_data)
+ , p(_data)
+ , encode(_encode)
+ , length(_length)
+ {
+ switch (encode)
+ {
+ case Encode::UTF8: decoder = new Utf8(); break;
+ case Encode::ASCII: decoder = new Ascii(); break;
+ }
+ }
+
+ Text::Iterator::~Iterator()
+ {
+ delete decoder;
+ }
+
+ Codepoint Text::Iterator::get()
+ {
+ Codepoint codepoint;
+ decoder->decode(p, &codepoint);
+ return codepoint;
+ }
+
+ Codepoint Text::Iterator::operator*()
+ {
+ return get();
+ }
+ /*
+ Text::Iterator Text::Iterator::begin()
+ {
+ Iterator itor(encode, data, length);
+ itor.toBegin();
+ return itor;
+ }
+
+ Text::Iterator Text::Iterator::end()
+ {
+ Iterator itor(encode, data, length);
+ itor.toEnd();
+ return itor;
+ }
+ */
+ void Text::Iterator::toBegin()
+ {
+ p = (const unsigned char*)data;
+ }
+
+ void Text::Iterator::toEnd()
+ {
+ p = (const unsigned char*)data + length;
+ }
+
+ Text::Iterator& Text::Iterator::operator ++()
+ {
+ p = decoder->next(p);
+ return *this;
+ }
+
+ Text::Iterator Text::Iterator::operator ++(int)
+ {
+ p = decoder->next(p);
+ Iterator itor(encode, data, length);
+ itor.p = p;
+ return itor;
+ }
+
+ bool Text::Iterator::operator !=(const Iterator& itor)
+ {
+ return !(data == itor.data
+ && p == itor.p
+ && length == itor.length
+ && encode == itor.encode);
+ }
+
+ bool Text::Iterator::operator ==(const Iterator& itor)
+ {
+ return data == itor.data
+ && p == itor.p
+ && length == itor.length
+ && encode == itor.encode;
+ }
+
+ /////////////////////////////////////////////////////////////////////////////
+ // text
+ /////////////////////////////////////////////////////////////////////////////
+
+ Text::Text(Encode encode, const void* data)
+ {
+ unsigned length = strlen((const char*)data);
+ Iterator end = Iterator(encode, data, length);
+ end.toEnd();
+ Iterator it = Iterator(encode, data, length);
+ for (; it != end; ++it)
+ {
+ content.push_back(*it);
+ }
+ }
+
+ Text::Text(Encode encode, const void* data, unsigned length)
+ {
+ Iterator end = Iterator(encode, data, length);
+ end.toEnd();
+ Iterator it = Iterator(encode, data, length);
+ for (; it != end; ++it)
+ {
+ content.push_back(*it);
+ }
+ }
+
+ Text::~Text()
+ {
+ }
+
+ const Content& Text::getContent() const
+ {
+ return content;
+ }
+
+ const Content& Text::operator*() const
+ {
+ return content;
+ }
+
+ } // namespace Fonts
+ } // namespace Graphics
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/Graphics/fonts/je_text.h b/src/libjin/Graphics/fonts/je_text.h
new file mode 100644
index 0000000..6e6f8b0
--- /dev/null
+++ b/src/libjin/Graphics/fonts/je_text.h
@@ -0,0 +1,172 @@
+#ifndef __JE_TEXT_H__
+#define __JE_TEXT_H__
+
+#include <vector>
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Fonts
+ {
+
+ typedef unsigned int Codepoint;
+
+ typedef std::vector<Codepoint> Content;
+
+ class Text;
+
+ class Decoder;
+
+ ///
+ /// Supported text encoding.
+ ///
+ enum Encode
+ {
+ UTF8, ///< utf-8
+ ASCII, ///< ASCII
+ };
+
+ ///
+ /// Decoded text. Saved as unicode codepoints.
+ ///
+ class Text
+ {
+ public:
+ ///
+ ///
+ ///
+ Text(Encode encode, const void* data);
+
+ ///
+ ///
+ ///
+ Text(Encode encode, const void* data, unsigned int length);
+
+ ///
+ ///
+ ///
+ ~Text();
+
+ ///
+ ///
+ ///
+ const Content& getContent() const;
+
+ ///
+ ///
+ ///
+ const Content& operator*() const;
+
+ private:
+ ///
+ ///
+ ///
+ class Iterator
+ {
+ public:
+
+ ///
+ ///
+ ///
+ Iterator(const Iterator& itor);
+
+ ///
+ ///
+ ///
+ Iterator(const Encode& encode, const void* data, unsigned int length);
+
+ ///
+ ///
+ ///
+ ~Iterator();
+
+ ///
+ ///
+ ///
+ Codepoint get();
+
+ //Iterator begin();
+ //Iterator end();
+
+ ///
+ ///
+ ///
+ void toBegin();
+
+ ///
+ ///
+ ///
+ void toEnd();
+
+ ///
+ ///
+ ///
+ Codepoint operator *();
+
+ ///
+ ///
+ ///
+ Iterator& operator ++();
+
+ ///
+ ///
+ ///
+ Iterator operator ++(int);
+
+ ///
+ ///
+ ///
+ bool operator !=(const Iterator& itor);
+
+ ///
+ ///
+ ///
+ bool operator ==(const Iterator& itor);
+
+ private:
+
+ ///
+ ///
+ ///
+ void operator = (const Iterator&);
+
+ ///
+ ///
+ ///
+ const Encode encode;
+
+ ///
+ ///
+ ///
+ const Decoder* decoder;
+
+ ///
+ ///
+ ///
+ const void* p;
+
+ ///
+ ///
+ ///
+ const void* const data;
+
+ ///
+ ///
+ ///
+ unsigned int length;
+
+ };
+
+ ///
+ ///
+ ///
+ Content content;
+
+ };
+
+ }
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/fonts/je_texture_font.cpp b/src/libjin/Graphics/fonts/je_texture_font.cpp
new file mode 100644
index 0000000..0d9b882
--- /dev/null
+++ b/src/libjin/Graphics/fonts/je_texture_font.cpp
@@ -0,0 +1,322 @@
+#include <vector>
+
+#include "../../math/je_vector2.hpp"
+
+#include "../shaders/je_shader.h"
+
+#include "je_texture_font.h"
+
+using namespace std;
+using namespace JinEngine::Math;
+using namespace JinEngine::Graphics::Shaders;
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Fonts
+ {
+
+ TextureFont * TextureFont::createTextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh)
+ {
+ TextureFont* tf = new TextureFont(bitmap, codepoints, cellw, cellh);
+ return tf;
+ }
+
+ TextureFont * TextureFont::createTextureFont(const Bitmap* bitmap, const Text& codepoints, int cellw, int cellh)
+ {
+ TextureFont* tf = new TextureFont(bitmap, *codepoints, cellw, cellh);
+ return tf;
+ }
+
+ TextureFont* TextureFont::createTextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh)
+ {
+ TextureFont* tf = new TextureFont(bitmap, codepoints, mask, cellh);
+ return tf;
+ }
+
+ TextureFont* TextureFont::createTextureFont(const Bitmap* bitmap, const Text& codepoints, Color mask, int cellh)
+ {
+ TextureFont* tf = new TextureFont(bitmap, *codepoints, mask, cellh);
+ return tf;
+ }
+
+ TextureFont::~TextureFont()
+ {
+ }
+
+ const TextureFont::TextureGlyph* TextureFont::findGlyph(Codepoint codepoint) const
+ {
+ auto it = glyphs.find(codepoint);
+ if (it != glyphs.end())
+ {
+ return &it->second;
+ }
+ else
+ return nullptr;
+ }
+
+ Page* TextureFont::typeset(const Content& text, int lineheight, int spacing)
+ {
+ Page* page = new Page();
+ page->font = this;
+ vector<GlyphArrayDrawInfo>& glyphinfolist = page->glyphinfolist;
+ vector<GlyphVertex>& glyphvertices = page->glyphvertices;
+ int texture = -1;
+ const TextureGlyph* glyph = nullptr;
+ GlyphVertex vertex;
+ Vector2<int> p(0, 0);
+ int i = 0;
+
+#define glyphvertices_push(_x, _y, _u, _v) \
+ vertex.x = _x; vertex.y = _y;\
+ vertex.u = _u; vertex.v = _v;\
+ glyphvertices.push_back(vertex);\
+
+ for (Codepoint c : text)
+ {
+ // return
+ if (c == 0x0D) continue;
+ // newline
+ if (c == 0x0A)
+ {
+ p.y += lineheight;
+ p.x = 0;
+ continue;
+ }
+ if (c == 0x09)
+ {
+ // tab = 4*space
+ unsigned cw = getCharWidth(0x20);
+ p.x += cw * 4;
+ continue;
+ }
+ glyph = findGlyph(c);
+ if (glyph == nullptr) continue;
+ if (texture != getGLTexture())
+ {
+ texture = getGLTexture();
+ GlyphArrayDrawInfo info;
+ info.start = i;
+ info.count = 0;
+ info.texture = texture;
+ glyphinfolist.push_back(info);
+ }
+ glyphinfolist[glyphinfolist.size() - 1].count += 4;
+ // normalized
+ float w = getWidth(), h = getHeight();
+ float nx = glyph->x / w, ny = glyph->y / h;
+ float nw = glyph->w / w, nh = glyph->h / h;
+ glyphvertices_push(p.x, p.y, nx, ny);
+ glyphvertices_push(p.x, p.y + glyph->h, nx, ny + nh);
+ glyphvertices_push(p.x + glyph->w, p.y + glyph->h, nx + nw, ny + nh);
+ glyphvertices_push(p.x + glyph->w, p.y, nx + nw, ny);
+ p.x += glyph->w + spacing;
+ i += 4;
+ }
+ getTextBox(text, &page->size.w, &page->size.h, lineheight, spacing);
+ return page;
+ }
+
+ int TextureFont::getCharWidth(int c)
+ {
+ auto it = glyphs.find(c);
+ if (it != glyphs.end())
+ {
+ return it->second.w;
+ }
+ return 0;
+ }
+
+ int TextureFont::getCharHeight(int c)
+ {
+ auto it = glyphs.find(c);
+ if (it != glyphs.end())
+ {
+ return it->second.h;
+ }
+ return 0;
+ }
+
+ int TextureFont::getTextWidth(const Content& t, int spacing)
+ {
+ int res = 0;
+ int tmp = 0;
+ for (Codepoint c : t)
+ {
+ if (c == 0x0D)
+ continue;
+ if (c == 0x0A)
+ {
+ tmp = 0;
+ continue;
+ }
+ if (c == 0x09)
+ {
+ // tab = 4*space
+ unsigned cw = getCharWidth(0x20);
+ tmp += cw * 4;
+ if (tmp > res) res = tmp;
+ continue;
+ }
+ tmp += getCharWidth(c) + spacing;
+ if (tmp > res) res = tmp;
+ }
+ return res;
+ }
+
+ int TextureFont::getTextHeight(const Content& t, int lineheight)
+ {
+ int res = 0;
+ bool newline = true;
+ for (Codepoint c : t)
+ {
+ if (c == 0x0A)
+ newline = true;
+ else if (c == 0x0D);
+ else if (newline)
+ {
+ newline = false;
+ res += lineheight;
+ }
+ }
+ return res;
+ }
+
+ void TextureFont::getTextBox(const Content& text, int* w, int* h, int lineheight, int spacing)
+ {
+ *w = 0;
+ *h = 0;
+ int tmp = 0;
+ bool newline = true;
+ for (Codepoint c : text)
+ {
+ if (c == 0x0D)
+ continue;
+ if (c == 0x0A)
+ {
+ tmp = 0;
+ newline = true;
+ continue;
+ }
+ else if (newline)
+ {
+ newline = false;
+ *h += lineheight;
+ }
+ tmp += getCharWidth(c) + spacing;
+ if (tmp > *w)
+ *w = tmp;
+ }
+ }
+
+ Page* TextureFont::typeset(const Text& text, int lineheight, int spacing)
+ {
+ return typeset(*text, lineheight, spacing);
+ }
+
+ void TextureFont::render(const Page* page, int x, int y)
+ {
+ Shader* shader = Shader::getCurrentShader();
+ const vector<GlyphArrayDrawInfo>& glyphinfolist = page->glyphinfolist;
+ const vector<GlyphVertex>& glyphvertices = page->glyphvertices;
+ gl.ModelMatrix.setTransformation(x, y, 0, 1, 1, 0, 0);
+ shader->sendMatrix4(SHADER_MODEL_MATRIX, &(gl.getMatrix() * gl.ModelMatrix));
+ shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
+ for (int i = 0; i < glyphinfolist.size(); ++i)
+ {
+ const GlyphArrayDrawInfo& info = glyphinfolist[i];
+ shader->setVertexPointer(2, GL_INT, sizeof(GlyphVertex), &glyphvertices[info.start].x);
+ shader->setUVPointer(2, GL_FLOAT, sizeof(GlyphVertex), &glyphvertices[info.start].u);
+ gl.bindTexture(info.texture);
+ gl.drawArrays(GL_QUADS, 0, info.count);
+ gl.bindTexture(0);
+ }
+ }
+
+ void TextureFont::render(const Content& text, int x, int y, int lineheight, int spacing)
+ {
+ Page* page = typeset(text, lineheight, spacing);
+ render(page, x, y);
+ delete page;
+ }
+
+ void TextureFont::render(const Text& text, int x, int y, int lineheight, int spacing)
+ {
+ Page* page = typeset(text, lineheight, spacing);
+ render(page, x, y);
+ delete page;
+ }
+
+ TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh)
+ : Graphic(bitmap)
+ , Font(cellh)
+ {
+ TextureGlyph glyph;
+ Vector2<int> count(bitmap->getWidth() / cellw, bitmap->getHeight() / cellh);
+ glyph.w = cellw;
+ glyph.h = cellh;
+ for (int y = 0; y < count.row; ++y)
+ {
+ glyph.y = y * cellh;
+ for (int x = 0; x < count.colum; ++x)
+ {
+ glyph.x = x * cellw;
+ if (x + y * count.colum >= codepoints.size())
+ return;
+ glyphs.insert(std::pair<Codepoint, TextureGlyph>(codepoints[x + y * count.colum], glyph));
+ }
+ }
+ }
+
+ TextureFont::TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh)
+ : Graphic(bitmap)
+ , Font(cellh)
+ {
+ TextureGlyph glyph;
+ glyph.h = cellh;
+ int w = bitmap->getWidth();
+ int h = bitmap->getHeight();
+ int i = 0;
+ for (int y = 0; y < h; y += cellh)
+ {
+ glyph.y = y;
+ bool newc = false;
+ for (int x = 0; x <= w; ++x)
+ {
+ if (x == w && newc)
+ {
+ glyph.w = x - glyph.x;
+ if (i >= codepoints.size())
+ return;
+ glyphs.insert(std::pair<Codepoint, TextureGlyph>(codepoints[i], glyph));
+ ++i;
+ newc = false;
+ break;
+ }
+ Color c = bitmap->getPixels()[x + y * w];
+ if (!newc && c != mask)
+ {
+ glyph.x = x;
+ newc = true;
+ }
+ else if (newc && c == mask)
+ {
+ glyph.w = x - glyph.x;
+ if (i >= codepoints.size())
+ return;
+ glyphs.insert(std::pair<Codepoint, TextureGlyph>(codepoints[i], glyph));
+ if (codepoints[i] == 't')
+ {
+ int a = 10;
+ }
+ ++i;
+ newc = false;
+ }
+ }
+ }
+ }
+
+ }
+ }
+} \ No newline at end of file
diff --git a/src/libjin/Graphics/fonts/je_texture_font.h b/src/libjin/Graphics/fonts/je_texture_font.h
new file mode 100644
index 0000000..8a50699
--- /dev/null
+++ b/src/libjin/Graphics/fonts/je_texture_font.h
@@ -0,0 +1,144 @@
+#ifndef __JE_TEXTURE_FONT_H__
+#define __JE_TEXTURE_FONT_H__
+
+#include <map>
+#include <vector>
+
+#include "../../math/je_vector4.hpp"
+
+#include "../je_graphic.h"
+#include "../je_bitmap.h"
+
+#include "je_page.h"
+#include "je_font.h"
+#include "je_text.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Fonts
+ {
+
+ ///
+ ///
+ ///
+ class TextureFont
+ : public Font
+ , public Graphic
+ {
+ public:
+
+ ///
+ ///
+ ///
+ static TextureFont* createTextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh);
+
+ ///
+ ///
+ ///
+ static TextureFont* createTextureFont(const Bitmap* bitmap, const Text& text, int cellw, int cellh);
+
+ ///
+ ///
+ ///
+ static TextureFont* createTextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh);
+
+ ///
+ ///
+ ///
+ static TextureFont* createTextureFont(const Bitmap* bitmap, const Text& text, Color mask, int cellh);
+
+ ///
+ ///
+ ///
+ ~TextureFont();
+
+ ///
+ ///
+ ///
+ Page* typeset(const Text& text, int lineheight, int spacing = 0) override;
+
+ ///
+ ///
+ ///
+ Page* typeset(const Content& text, int lineheight, int spacing = 0) override;
+
+ ///
+ ///
+ ///
+ void render(const Page* page, int x, int y) override;
+
+ ///
+ ///
+ ///
+ void render(const Content& text, int x, int y, int linehgiht, int spacing = 0) override;
+
+ ///
+ ///
+ ///
+ void render(const Text& text, int x, int y, int lineheight, int spacing = 0)override;
+
+ private:
+
+ ///
+ ///
+ ///
+ struct TextureGlyph
+ {
+ float x, y, w, h;
+ };
+
+ ///
+ ///
+ ///
+ TextureFont(const Bitmap* bitmap, const Content& codepoints, int cellw, int cellh);
+
+ ///
+ ///
+ ///
+ TextureFont(const Bitmap* bitmap, const Content& codepoints, Color mask, int cellh);
+
+ ///
+ ///
+ ///
+ int getCharWidth(int c);
+
+ ///
+ ///
+ ///
+ int getCharHeight(int c);
+
+ ///
+ ///
+ ///
+ int getTextWidth(const Content& text, int spacing = 0);
+
+ ///
+ ///
+ ///
+ int getTextHeight(const Content& text, int lineheight);
+
+ ///
+ ///
+ ///
+ void getTextBox(const Content& text, int* w, int* h, int lineheight, int spacing = 0);
+
+ ///
+ ///
+ ///
+ const TextureGlyph* findGlyph(Codepoint codepoint) const;
+
+
+ ///
+ ///
+ ///
+ std::map<Codepoint, TextureGlyph> glyphs;
+
+ };
+
+ } // namespace Fonts
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/fonts/je_ttf.cpp b/src/libjin/Graphics/fonts/je_ttf.cpp
new file mode 100644
index 0000000..9994666
--- /dev/null
+++ b/src/libjin/Graphics/fonts/je_ttf.cpp
@@ -0,0 +1,468 @@
+#include "../../core/je_configuration.h"
+#if defined(jin_graphics)
+
+#include <stdio.h>
+
+#include "../../common/je_array.hpp"
+
+#include "../je_gl.h"
+#include "../je_color.h"
+#include "../shaders/je_shader.h"
+
+#include "je_ttf.h"
+#include "je_page.h"
+
+#define STB_TRUETYPE_IMPLEMENTATION
+#include "stb/stb_truetype.h"
+
+using namespace JinEngine::Graphics::Shaders;
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Fonts
+ {
+
+ //////////////////////////////////////////////////////////////////////////////////////////////////////
+ // TTFData
+ //////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ TTFData* TTFData::createTTFData(const unsigned char* data, unsigned int size)
+ {
+ TTFData* ttf = nullptr;
+ try
+ {
+ ttf = new TTFData(data, size);
+ return ttf;
+ }
+ catch (...)
+ {
+ return nullptr;
+ }
+ }
+
+ TTFData::TTFData(const unsigned char* d, unsigned int s)
+ {
+ raw.size = s;
+ raw.data = (unsigned char*)malloc(s);
+ memcpy(raw.data, d, s);
+ if (!stbtt_InitFont(&info, (const unsigned char*)raw.data, 0))
+ {
+ delete raw.data;
+ throw 0;
+ }
+ /* push default fontsize */
+ pushTTFsize(FONT_SIZE);
+ }
+
+ TTFData::~TTFData()
+ {
+ free(raw.data);
+ }
+
+ TTF* TTFData::createTTF(unsigned fontSize)
+ {
+ TTF* ttf;
+ try
+ {
+ ttf = new TTF(this, fontSize);
+ }
+ catch (...)
+ {
+ return nullptr;
+ }
+ return ttf;
+ }
+
+ /*
+ * (0, 0)
+ * +--------------+ ascent
+ * | +--------+ |
+ * | | | |
+ * | | bitmap | |
+ * +--|--------|--+ baseline
+ * | +--------+ |
+ * +--|-----------+ decent
+ * | |
+ * leftSideBearing |
+ * advanceWidth
+ */
+ void TTFData::getVMetrics(int* baseline, int* descent)
+ {
+ float scale = scales.back();
+ int ascent;
+ stbtt_GetFontVMetrics(&info, &ascent, descent, 0);
+ *baseline = (int)(ascent*scale) + 1; // slight adjustment
+ *descent = *baseline - (int)(*descent*scale) + 1;
+ }
+
+ void TTFData::getHMetrics(unsigned int codepoint, int* advanceWidth, int* leftSideBearing)
+ {
+ float scale = scales.back();
+ int adw, lsb;
+ stbtt_GetCodepointHMetrics(&info, codepoint, &adw, &lsb);
+ *advanceWidth = (int)(adw*scale);
+ *leftSideBearing = (int)(lsb*scale);
+ }
+
+ void TTFData::pushTTFsize(unsigned int fs)
+ {
+ float sc = stbtt_ScaleForPixelHeight(&info, fs);
+ scales.push_back(sc);
+ }
+
+ void TTFData::popTTFsize()
+ {
+ /* always keep default ttf size on the bottom of stack */
+ if (scales.size() > 1)
+ scales.pop_back();
+ }
+
+ Channel* TTFData::getCodepointBitmapAlpha(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const
+ {
+ float scale = scales.back();
+ Channel* bitmap = stbtt_GetCodepointBitmap(&info, scale, scale, codepoint, width, height, xoff, yoff);
+ return bitmap;
+ }
+
+ Color* TTFData::getCodepointBitmap(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const
+ {
+ float scale = scales.back();
+ Channel* bitmap = stbtt_GetCodepointBitmap(&info, scale, scale, codepoint, width, height, xoff, yoff);
+ int w = *width, h = *height;
+ //int xo = *xoff, yo = *yoff;
+ Color* bitmap32 = new Color[w*h];
+ for (int y = 0; y < h; ++y)
+ {
+ for (int x = 0; x < w; ++x)
+ {
+ bitmap32[x + y * w].set(0xff, 0xff, 0xff, bitmap[x + y * w]);
+ }
+ }
+ free(bitmap);
+ return bitmap32;
+ }
+
+ //////////////////////////////////////////////////////////////////////////////////////////////////////
+ // TTF
+ //////////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include "../shaders/built-in/je_font.shader.h"
+
+ using namespace std;
+ using namespace JinEngine::Math;
+
+ const int TTF::TEXTURE_WIDTHS[] = { 128, 256, 256, 512, 512, 1024, 1024 };
+ const int TTF::TEXTURE_HEIGHTS[] = { 128, 128, 256, 256, 512, 512, 1024 };
+
+ /* little endian unicode */
+ static const char* unicodeLittleEndian(const char* p, unsigned* res)
+ {
+ }
+
+ ///*static*/ TTF* TTF::createTTF(TTFData* fontData, unsigned int fontSzie)
+ //{
+ // TTF* ttf;
+ // try
+ // {
+ // ttf = new TTF(fontData, fontSzie);
+ // }
+ // catch (...)
+ // {
+ // return nullptr;
+ // }
+ // return ttf;
+ //}
+
+ TTF::TTF(TTFData* f, unsigned int fontSize)
+ : Font(fontSize)
+ , cursor(0, 0)
+ , ttf(f)
+ {
+ ttf->pushTTFsize(fontSize);
+ ttf->getVMetrics(&baseline, &descent);
+ estimateSize();
+ ttf->popTTFsize();
+ /* create a default texture */
+ createAtlas();
+ }
+
+ /* estimate the size of atlas texture */
+ void TTF::estimateSize()
+ {
+ for (int level = 0; level <= TEXTURE_SIZE_LEVEL_MAX; ++level)
+ {
+ if (descent * (descent*0.8) * 96 <= TEXTURE_WIDTHS[level] * TEXTURE_HEIGHTS[level])
+ {
+ textureWidth = TEXTURE_WIDTHS[level];
+ textureHeight = TEXTURE_HEIGHTS[level];
+ break;
+ }
+ }
+ }
+
+ TTF::~TTF()
+ {
+ }
+
+ GLuint TTF::createAtlas()
+ {
+ GLuint t;
+ gl.flushError();
+ t = gl.genTexture();
+ gl.bindTexture(t);
+ gl.setTexParameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ gl.setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ gl.setTexParameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ gl.setTexParameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ gl.texImage(GL_RGBA8, textureWidth, textureHeight, GL_RGBA, GL_UNSIGNED_BYTE);
+ if (glGetError() != GL_NO_ERROR)
+ {
+ glDeleteTextures(1, &t);
+ gl.bindTexture(0);
+ return 0;
+ }
+ atlases.push_back(t);
+ gl.bindTexture(0);
+ return t;
+ }
+
+ void TTF::render(const Content& t, int x, int y, int lineheight, int spacing)
+ {
+ Page* page = typeset(t, lineheight, spacing);
+ render(page, x, y);
+ delete page;
+ }
+
+ Page* TTF::typeset(const Content& text, int lineheight, int spacing)
+ {
+ Page* page = new Page();
+ page->font = this;
+ vector<GlyphArrayDrawInfo>& glyphinfolist = page->glyphinfolist;
+ vector<GlyphVertex>& glyphvertices = page->glyphvertices;
+ int texture = -1;
+ TTFGlyph* glyph = nullptr;
+ GlyphVertex vertex;
+ Vector2<int> p(0, 0);
+ int i = 0;
+
+#define glyphvertices_push(_x, _y, _u, _v) \
+ vertex.x = _x; vertex.y = _y;\
+ vertex.u = _u; vertex.v = _v;\
+ glyphvertices.push_back(vertex);
+
+#define glyphlize(c)\
+ do{\
+ glyph = &findGlyph(c); \
+ if (texture != glyph->atlas) \
+ { \
+ GlyphArrayDrawInfo info; \
+ info.start = i; \
+ info.count = 0; \
+ info.texture = glyph->atlas; \
+ texture = glyph->atlas; \
+ glyphinfolist.push_back(info); \
+ } \
+ glyphinfolist[glyphinfolist.size() - 1].count += 4; \
+ TTFGlyph::Bbox& bbox = glyph->bbox; \
+ glyphvertices_push(p.x, p.y, bbox.x, bbox.y); \
+ glyphvertices_push(p.x, p.y + glyph->height, bbox.x, bbox.y + bbox.h); \
+ glyphvertices_push(p.x + glyph->width, p.y + glyph->height, bbox.x + bbox.w, bbox.y + bbox.h); \
+ glyphvertices_push(p.x + glyph->width, p.y, bbox.x + bbox.w, bbox.y); \
+ }while(0)
+
+ for (Codepoint c : text)
+ {
+ if (c == 0x0D)
+ continue;
+ if (c == 0x0A)
+ {
+ /* new line */
+ p.y += lineheight;
+ p.x = 0;
+ continue;
+ }
+ if (c == 0x09)
+ {
+ // tab = 4*space
+ unsigned cw = getCharWidth(0x20);
+ p.x += cw * 4;
+ continue;
+ }
+ glyphlize(c);
+ p.x += glyph->width + spacing;
+ i += 4;
+ }
+ getTextBox(text, &page->size.w, &page->size.h, lineheight, spacing);
+ return page;
+ }
+
+ Page* TTF::typeset(const Text& text, int lineheight, int spacing)
+ {
+ return typeset(*text, lineheight, spacing);
+ }
+
+ void TTF::render(const Page* page, int x, int y)
+ {
+ Shader* shader = Shader::getCurrentShader();
+ const vector<GlyphArrayDrawInfo>& glyphinfolist = page->glyphinfolist;
+ const vector<GlyphVertex>& glyphvertices = page->glyphvertices;
+ gl.ModelMatrix.setTransformation(x, y, 0, 1, 1, 0, 0);
+ shader->sendMatrix4(SHADER_MODEL_MATRIX, &(gl.getMatrix() * gl.ModelMatrix));
+ shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
+ for (int i = 0; i < glyphinfolist.size(); ++i)
+ {
+ const GlyphArrayDrawInfo& info = glyphinfolist[i];
+ shader->setVertexPointer(2, GL_INT, sizeof(GlyphVertex), &glyphvertices[info.start].x);
+ shader->setUVPointer(2, GL_FLOAT, sizeof(GlyphVertex), &glyphvertices[info.start].u);
+ gl.bindTexture(info.texture);
+ gl.drawArrays(GL_QUADS, 0, info.count);
+ gl.bindTexture(0);
+ }
+ }
+
+ void TTF::render(const Text& text, int x, int y, int lineheight, int spacing /* = 0 */)
+ {
+ render(*text, x, y, lineheight, spacing);
+ }
+
+ int TTF::getCharWidth(int c)
+ {
+ int adw, lsb;
+ ttf->pushTTFsize(mFontSize);
+ ttf->getHMetrics(c, &adw, &lsb);
+ ttf->popTTFsize();
+ return adw;
+ }
+
+ int TTF::getCharHeight(int c)
+ {
+ return descent;
+ }
+
+ int TTF::getTextWidth(const Content& t, int spacing)
+ {
+ ttf->pushTTFsize(mFontSize);
+ int res = 0;
+ int tmp = 0;
+ for (Codepoint c : t)
+ {
+ if (c == 0x0D)
+ continue;
+ if (c == 0x0A)
+ {
+ tmp = 0;
+ continue;
+ }
+ tmp += getCharWidth(c) + spacing;
+ if (tmp > res)
+ res = tmp;
+ }
+ ttf->popTTFsize();
+ return res;
+ }
+
+ int TTF::getTextHeight(const Content& t, int lineheight)
+ {
+ ttf->pushTTFsize(mFontSize);
+ int res = 0;
+ bool newline = true;
+ for (Codepoint c : t)
+ {
+ if (c == 0x0A)
+ newline = true;
+ else if (c == 0x0D);
+ else if (newline)
+ {
+ newline = false;
+ res += lineheight;
+ }
+ }
+ ttf->popTTFsize();
+ return res;
+ }
+
+ void TTF::getTextBox(const Content& text, int* w, int* h, int lineheight, int spacing)
+ {
+ ttf->pushTTFsize(mFontSize);
+ *w = 0;
+ *h = 0;
+ int tmp = 0;
+ bool newline = true;
+ for (Codepoint c : text)
+ {
+ if (c == 0x0D)
+ continue;
+ if (c == 0x0A)
+ {
+ tmp = 0;
+ newline = true;
+ continue;
+ }
+ else if (newline)
+ {
+ newline = false;
+ *h += lineheight;
+ }
+ tmp += getCharWidth(c) + spacing;
+ if (tmp > *w)
+ *w = tmp;
+ }
+ ttf->popTTFsize();
+ }
+
+ TTF::TTFGlyph& TTF::bakeGlyph(unsigned int character)
+ {
+ int w, h, xoff, yoff;
+ ttf->pushTTFsize(mFontSize);
+ GLuint atlas = atlases.back();
+ const Color* bitmap = ttf->getCodepointBitmap(character, &w, &h, &xoff, &yoff);
+ int adw, lsb;
+ {
+ /* bake glyph */
+ ttf->getHMetrics(character, &adw, &lsb);
+ ttf->popTTFsize();
+ if (cursor.x + adw > textureWidth)
+ {
+ cursor.x = 0;
+ cursor.y += descent;
+ if (cursor.y + descent * 2 > textureHeight)
+ {
+ /* create new atlas */
+ atlas = createAtlas();
+ cursor.y = 0;
+ }
+ }
+ gl.bindTexture(atlas);
+ gl.texSubImage(cursor.x + xoff, cursor.y + yoff + baseline, w, h, GL_RGBA, GL_UNSIGNED_BYTE, bitmap);
+ gl.bindTexture();
+ delete[] bitmap;
+ }
+ TTFGlyph glyph;
+ glyph.atlas = atlas;
+ glyph.bbox.x = cursor.x / (float)textureWidth;
+ glyph.bbox.y = cursor.y / (float)textureHeight;
+ glyph.bbox.w = adw / (float)textureWidth;
+ glyph.bbox.h = descent / (float)textureHeight;
+ glyph.width = adw;
+ glyph.height = descent;
+ glyphs.insert(std::pair<unsigned int, TTFGlyph>(character, glyph));
+ cursor.x += adw;
+ return glyphs[character];
+ }
+
+ TTF::TTFGlyph& TTF::findGlyph(unsigned int character)
+ {
+ map<unsigned int, TTFGlyph>::iterator it = glyphs.find(character);
+ if (it != glyphs.end())
+ return it->second;
+ else
+ return bakeGlyph(character);
+ }
+
+ } // namespace Fonts
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif // defined(jin_graphics) \ No newline at end of file
diff --git a/src/libjin/Graphics/fonts/je_ttf.h b/src/libjin/Graphics/fonts/je_ttf.h
new file mode 100644
index 0000000..28260f6
--- /dev/null
+++ b/src/libjin/Graphics/fonts/je_ttf.h
@@ -0,0 +1,292 @@
+#ifndef __JE_TTF_H__
+#define __JE_TTF_H__
+#include "../../core/je_configuration.h"
+#if defined(jin_graphics)
+
+#include <vector>
+#include <map>
+
+#include "stb/stb_truetype.h"
+
+#include "../../math/je_quad.h"
+
+#include "../je_color.h"
+#include "../je_graphic.h"
+
+#include "je_page.h"
+#include "je_font.h"
+#include "je_text.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Fonts
+ {
+
+ class TTF;
+
+ //
+ // TTFData
+ // |- TTF(14px)
+ // |- TTF(15px)
+ // .
+ // .
+ // .
+ //
+ class TTFData
+ {
+ public:
+
+ ///
+ ///
+ ///
+ static TTFData* createTTFData(const unsigned char* data, unsigned int size);
+
+ ///
+ ///
+ ///
+ ~TTFData();
+
+ ///
+ ///
+ ///
+ TTF* createTTF(unsigned ttfsize);
+
+ ///
+ ///
+ ///
+ void pushTTFsize(unsigned ttfsize);
+
+ ///
+ ///
+ ///
+ void popTTFsize();
+
+ ///
+ ///
+ ///
+ Channel* getCodepointBitmapAlpha(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const;
+
+ ///
+ ///
+ ///
+ Color* getCodepointBitmap(unsigned int codepoint, int* width, int* height, int* xoff, int* yoff) const;
+
+ ///
+ ///
+ ///
+ void getVMetrics(int* baseline, int* descent);
+
+ ///
+ ///
+ ///
+ void getHMetrics(unsigned int codepoint, int* advanceWidth, int* leftSideBearing);
+
+ private:
+
+ ///
+ ///
+ ///
+ static const unsigned int FONT_SIZE = 12;
+
+ ///
+ ///
+ ///
+ TTFData(const unsigned char* data, unsigned int size);
+
+ ///
+ ///
+ ///
+ stbtt_fontinfo info;
+
+ ///
+ ///
+ ///
+ struct
+ {
+ unsigned char* data;
+ unsigned int size;
+ } raw;
+
+ ///
+ ///
+ ///
+ std::vector<float> scales;
+
+ };
+
+ class TTF : public Font
+ {
+ public:
+ //static TTF* createTTF(TTFData* ttfData, unsigned ttfSzie);
+
+ ///
+ ///
+ ///
+ Page* typeset(const Text& text, int lineheight, int spacing = 0) override;
+
+ ///
+ ///
+ ///
+ Page* typeset(const Content& text, int lineheight, int spacing = 0) override;
+
+ ///
+ ///
+ ///
+ void render(const Text& text, int x, int y, int lineheight, int spacing = 0) override;
+
+ ///
+ ///
+ ///
+ void render(const Content& text, int x, int y, int lineheight, int spacing = 0) override;
+
+ ///
+ ///
+ ///
+ void render(const Page* page, int x, int y) override;
+
+ ///
+ ///
+ ///
+ ~TTF();
+
+ private:
+
+ friend class TTFData;
+
+ ///
+ ///
+ ///
+ struct TTFGlyph
+ {
+ GLuint atlas;
+ // normalized coordinates
+ struct Bbox
+ {
+ float x, y;
+ float w, h;
+ } bbox;
+ // glyph size in pixel
+ unsigned int width, height;
+ };
+
+ ///
+ ///
+ ///
+ static const int TEXTURE_SIZE_LEVELS_COUNT = 7;
+
+ ///
+ ///
+ ///
+ static const int TEXTURE_SIZE_LEVEL_MAX = TEXTURE_SIZE_LEVELS_COUNT - 1;
+
+ ///
+ ///
+ ///
+ static const int TEXTURE_WIDTHS[TEXTURE_SIZE_LEVELS_COUNT];
+
+ ///
+ ///
+ ///
+ static const int TEXTURE_HEIGHTS[TEXTURE_SIZE_LEVELS_COUNT];
+
+ ///
+ ///
+ ///
+ TTF(TTFData* ttf, Codepoint ttfSize);
+
+ ///
+ ///
+ ///
+ void estimateSize();
+
+ ///
+ ///
+ ///
+ GLuint createAtlas();
+
+ ///
+ ///
+ ///
+ TTFGlyph& bakeGlyph(Codepoint character);
+
+ ///
+ ///
+ ///
+ TTFGlyph& findGlyph(Codepoint character);
+
+ ///
+ ///
+ ///
+ int getCharWidth(int c);
+
+ ///
+ ///
+ ///
+ int getCharHeight(int c);
+
+ ///
+ ///
+ ///
+ int getTextWidth(const Content& text, int spacing = 0);
+
+ ///
+ ///
+ ///
+ int getTextHeight(const Content& text, int lineheight);
+
+ ///
+ ///
+ ///
+ void getTextBox(const Content& text, int* w, int* h, int lineheight, int spacing = 0);
+
+ ///
+ ///
+ ///
+ int textureWidth;
+
+ ///
+ ///
+ ///
+ int textureHeight;
+
+ ///
+ ///
+ ///
+ std::vector<GLuint> atlases;
+
+ ///
+ ///
+ ///
+ std::map<Codepoint, TTFGlyph> glyphs;
+
+ ///
+ ///
+ ///
+ TTFData* ttf;
+
+ ///
+ ///
+ ///
+ int baseline;
+
+ ///
+ ///
+ ///
+ int descent;
+
+ ///
+ ///
+ ///
+ Math::Vector2<float> cursor;
+
+ };
+
+ } // namespace Fonts
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif // defined(jin_graphics)
+
+#endif // __JE_FONT_H__
diff --git a/src/libjin/Graphics/je_bitmap.cpp b/src/libjin/Graphics/je_bitmap.cpp
index 0747f0b..cdab46d 100644
--- a/src/libjin/Graphics/je_bitmap.cpp
+++ b/src/libjin/Graphics/je_bitmap.cpp
@@ -1,6 +1,7 @@
#define STB_IMAGE_IMPLEMENTATION
-#include "../3rdparty/stb/stb_image.h"
+#include "stb/stb_image.h"
+#include "../common/je_exception.h"
#include "../filesystem/je_asset_database.h"
#include "../math/je_math.h"
@@ -22,7 +23,6 @@ namespace JinEngine
return createBitmap(&buffer, buffer.size());
}
- /* pixelbitmap */
Bitmap* Bitmap::createBitmap(const void* pixel, unsigned width, unsigned height)
{
Bitmap* bitmap = new Bitmap(width, height);
@@ -36,8 +36,11 @@ namespace JinEngine
return nullptr;
int w, h;
void* data = stbi_load_from_memory((unsigned char *)imgData, size, &w, &h, NULL, STBI_rgb_alpha);
- if (data == nullptr)
- return nullptr;
+ if (data == nullptr)
+ {
+ throw Exception("Could not create bitmap from image data.");
+ return nullptr;
+ }
Bitmap* bitmap = new Bitmap();
bitmap->pixels = (Color*)data;
bitmap->width = w;
@@ -53,6 +56,20 @@ namespace JinEngine
return bitmap;
}
+ /*static*/ Bitmap* Bitmap::createBitmap(int width, int height, std::function<Color(int, int, int, int)> drawer)
+ {
+ Bitmap* bitmap = new Bitmap(width, height);
+ for (int y = 0; y < height; ++y)
+ {
+ for (int x = 0; x < width; ++x)
+ {
+ Color c = drawer(width, height, x, y);
+ bitmap->setPixel(c, x, y);
+ }
+ }
+ return bitmap;
+ }
+
/*static */ Bitmap* Bitmap::clone(const Bitmap* bitmap)
{
Bitmap* b = new Bitmap();
@@ -74,6 +91,8 @@ namespace JinEngine
width = w;
height = h;
pixels = new Color[w*h];
+ if (pixels == nullptr)
+ throw Exception("No enough memory.");
}
Bitmap::~Bitmap()
@@ -95,6 +114,8 @@ namespace JinEngine
if (pixels != nullptr)
delete[] pixels;
pixels = new Color[w*h];
+ if (pixels == nullptr)
+ throw Exception("Not enough memory.");
size_t s = w * h * sizeof(Color);
memcpy(pixels, p, s);
width = w;
@@ -103,10 +124,12 @@ namespace JinEngine
void Bitmap::setPixel(const Color& c, int x, int y)
{
- if (pixels == nullptr)
- return;
+ if (pixels == nullptr)
+ throw Exception("Bitmap don't have pixel space.");
if (without<int>(x, 0, width - 1) || without<int>(y, 0, height - 1))
return;
+ if (x + y * width >= width * height)
+ throw Exception("Pixel <%d, %d> of bitmap is out of range.", x, y);
pixels[x + y * width] = c;
}
@@ -115,7 +138,8 @@ namespace JinEngine
if (pixels != nullptr)
delete[] pixels;
pixels = new Color[w*h];
- size_t s = w * h * sizeof(Color);
+ if (pixels == nullptr)
+ throw Exception("Not enough memory.");
width = w;
height = h;
for (int x = 0; x < w; ++x)
@@ -127,8 +151,10 @@ namespace JinEngine
}
}
- void Bitmap::setPixels(Color* p)
+ void Bitmap::setPixels(Color* p, int count)
{
+ if (count > width * height)
+ throw Exception("Pixels are out of range.");
size_t s = width * height * sizeof(Color);
memcpy(pixels, p, s);
}
diff --git a/src/libjin/Graphics/je_bitmap.h b/src/libjin/Graphics/je_bitmap.h
index ae97d0d..5ab11ca 100644
--- a/src/libjin/Graphics/je_bitmap.h
+++ b/src/libjin/Graphics/je_bitmap.h
@@ -1,9 +1,12 @@
-#ifndef __JE_BITMAP_H
-#define __JE_BITMAP_H
+#ifndef __JE_BITMAP_H__
+#define __JE_BITMAP_H__
#include "../core/je_configuration.h"
#if defined(jin_graphics)
-#include "../3rdparty/GLee/GLee.h"
+#include <functional>
+
+#include "GLee/GLee.h"
+
#include "../common/je_types.h"
#include "../math/je_vector2.hpp"
@@ -17,7 +20,9 @@ namespace JinEngine
///
/// A RGBA32 bitmap.
///
- /// A bitmap keeps pixels and can't draw directly onto screen. To render bitmap, a texture is required.
+ /// A bitmap keeps pixels and can't draw directly onto screen. To render bitmap, a texture is required. A
+ /// texture is a renderable hard ware side structure which could be handled with GPU. For instance, opengl
+ /// create texture and store it in GPU memory for rendering them onto hdc.
///
class Bitmap
{
@@ -59,6 +64,11 @@ namespace JinEngine
///
static Bitmap* createBitmap(int width, int height, Color color = Color::BLACK);
+ ///
+ /// Create bitmap and set bitmap pixels with given drawer.
+ ///
+ static Bitmap* createBitmap(int width, int height, std::function<Color(int, int, int, int)> drawer);
+
///
/// Create bitmap with another one.
///
@@ -119,8 +129,9 @@ namespace JinEngine
/// Set pixels with given color data.
///
/// @param colors New pixels' colors.
+ /// @param count Number of pixels.
///
- void setPixels(Color* colors);
+ void setPixels(Color* colors, int count);
///
/// Get pixel in given position.
diff --git a/src/libjin/Graphics/je_canvas.cpp b/src/libjin/Graphics/je_canvas.cpp
index 7e0858b..7c8e849 100644
--- a/src/libjin/Graphics/je_canvas.cpp
+++ b/src/libjin/Graphics/je_canvas.cpp
@@ -18,10 +18,10 @@ namespace JinEngine
return new Canvas(w, h);
}
- Canvas::Canvas(GLuint n)
- : fbo(n)
- {
- }
+ Canvas::Canvas(GLuint n)
+ : fbo(n)
+ {
+ }
Canvas::Canvas(int w, int h)
: Graphic(w, h)
@@ -33,14 +33,13 @@ namespace JinEngine
fbo = gl.genFrameBuffer();
gl.bindFrameBuffer(fbo);
- // Generate texture save target
- mTexture = gl.genTexture();
- gl.bindTexture(mTexture);
+ GLuint texture = getGLTexture();
+ gl.bindTexture(texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
gl.texImage(GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
gl.bindTexture(0);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture, 0);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
diff --git a/src/libjin/Graphics/je_canvas.h b/src/libjin/Graphics/je_canvas.h
index f39b0de..3964517 100644
--- a/src/libjin/Graphics/je_canvas.h
+++ b/src/libjin/Graphics/je_canvas.h
@@ -1,5 +1,5 @@
-#ifndef __JE_CANVAS_H
-#define __JE_CANVAS_H
+#ifndef __JE_CANVAS_H__
+#define __JE_CANVAS_H__
#include "../core/je_configuration.h"
#if defined(jin_graphics)
@@ -14,7 +14,8 @@ namespace JinEngine
///
/// A canvas is a rendering target.
///
- class Canvas: public Graphic
+ class Canvas
+ : public Graphic
{
public:
///
@@ -65,4 +66,4 @@ namespace JinEngine
#endif // defined(jin_graphics)
-#endif // __JE_CANVAS_H \ No newline at end of file
+#endif // __JE_CANVAS_H__ \ No newline at end of file
diff --git a/src/libjin/Graphics/je_color.cpp b/src/libjin/Graphics/je_color.cpp
index da48162..c939a1d 100644
--- a/src/libjin/Graphics/je_color.cpp
+++ b/src/libjin/Graphics/je_color.cpp
@@ -13,5 +13,10 @@ namespace JinEngine
const Color Color::MAGENTA = Color(255, 0, 255);
const Color Color::YELLOW = Color(255, 255, 0);
+ const uint32 Color::RMASK = 0x000000ff;
+ const uint32 Color::GMASK = 0x0000ff00;
+ const uint32 Color::BMASK = 0x00ff0000;
+ const uint32 Color::AMASK = 0xff000000;
+
}
} \ No newline at end of file
diff --git a/src/libjin/Graphics/je_color.h b/src/libjin/Graphics/je_color.h
index 8fe7691..06b8f61 100644
--- a/src/libjin/Graphics/je_color.h
+++ b/src/libjin/Graphics/je_color.h
@@ -1,11 +1,13 @@
/**
* Some color operating here.
*/
-#ifndef __JE_COLOR_H
-#define __JE_COLOR_H
+#ifndef __JE_COLOR_H__
+#define __JE_COLOR_H__
#include "../core/je_configuration.h"
#if defined(jin_graphics)
+#include "../math/je_math.h"
+
#include "../common/je_types.h"
#include "../utils/je_endian.h"
@@ -28,6 +30,30 @@ namespace JinEngine
static const Color MAGENTA;
static const Color YELLOW;
+ static const uint32 RMASK;
+ static const uint32 GMASK;
+ static const uint32 BMASK;
+ static const uint32 AMASK;
+
+ ///
+ /// Get lerp color with given factor.
+ ///
+ /// @param start Start color.
+ /// @param end End color.
+ /// @param t Factor of interplation.
+ /// @return Color after interplation.
+ ///
+ static Color lerp(Color start, Color end, float t)
+ {
+ t = Math::clamp<float>(t, 0, 1);
+ Color c;
+ c.r = Math::lerp(start.r, end.r, t);
+ c.g = Math::lerp(start.g, end.g, t);
+ c.b = Math::lerp(start.b, end.b, t);
+ c.a = Math::lerp(start.a, end.a, t);
+ return c;
+ }
+
///
///
///
@@ -90,4 +116,4 @@ namespace JinEngine
#endif // jin_graphics
-#endif // __JE_COLOR_H \ No newline at end of file
+#endif // __JE_COLOR_H__ \ No newline at end of file
diff --git a/src/libjin/Graphics/je_gl.cpp b/src/libjin/Graphics/je_gl.cpp
index 9ef1460..3f19d36 100644
--- a/src/libjin/Graphics/je_gl.cpp
+++ b/src/libjin/Graphics/je_gl.cpp
@@ -1,5 +1,8 @@
#define OGL2D_IMPLEMENT
#include "je_gl.h"
+#include "je_color.h"
+
+using namespace JinEngine::Math;
namespace JinEngine
{
@@ -8,5 +11,82 @@ namespace JinEngine
OpenGL gl;
+ OpenGL::OpenGL()
+ : ogl2d::OpenGL()
+ {
+ mMatrices.push_back(Matrix());
+ calcMatrix();
+ }
+
+ void OpenGL::setColor(Channel r, Channel g, Channel b, Channel a)
+ {
+ setColor(Color(r, g, b, a));
+ }
+
+ void OpenGL::setColor(Color c)
+ {
+ mCurrentColor = c;
+ glColor4f(c.r / 255.f, c.g / 255.f, c.b / 255.f, c.a / 255.f);
+ }
+
+ Color OpenGL::getColor()
+ {
+ return mCurrentColor;
+ }
+
+ void OpenGL::clearMatrix()
+ {
+ mMatrices.clear();
+ mMatrices.push_back(Matrix());
+ mMatrix.setIdentity();
+ }
+
+ void OpenGL::push()
+ {
+ mMatrices.push_back(Matrix());
+ }
+
+ void OpenGL::pop()
+ {
+ if (mMatrices.size() == 1)
+ return;
+ mMatrices.pop_back();
+ calcMatrix();
+ }
+
+ void OpenGL::calcMatrix()
+ {
+ mMatrix.setIdentity();
+ for (Matrix& m : mMatrices)
+ mMatrix *= m;
+ }
+
+ void OpenGL::translate(float x, float y)
+ {
+ if (mMatrices.size() == 1)
+ return;
+ Matrix& m = mMatrices.back();
+ m.translate(x, y);
+ mMatrix.translate(x, y);
+ }
+
+ void OpenGL::scale(float sx, float sy)
+ {
+ if (mMatrices.size() == 1)
+ return;
+ Matrix& m = mMatrices.back();
+ m.scale(sx, sy);
+ mMatrix.scale(sx, sy);
+ }
+
+ void OpenGL::rotate(float r)
+ {
+ if (mMatrices.size() == 1)
+ return;
+ Matrix& m = mMatrices.back();
+ m.rotate(r);
+ mMatrix.rotate(r);
+ }
+
} // namespace Graphics
} // namespace JinEngine
diff --git a/src/libjin/Graphics/je_gl.h b/src/libjin/Graphics/je_gl.h
index cda8bf9..1dddab3 100644
--- a/src/libjin/Graphics/je_gl.h
+++ b/src/libjin/Graphics/je_gl.h
@@ -1,10 +1,14 @@
-#ifndef __JE_OPENGL_H
-#define __JE_OPENGL_H
+#ifndef __JE_OPENGL_H__
+#define __JE_OPENGL_H__
+
+#include <vector>
-#include "../3rdparty/GLee/GLee.h"
-#include "../3rdparty/ogl/OpenGL.h"
#include "../math/je_matrix.h"
+#include "je_color.h"
+#include "GLee/GLee.h"
+#include "ogl/OpenGL.h"
+
namespace JinEngine
{
namespace Graphics
@@ -26,9 +30,35 @@ namespace JinEngine
///
///
///
- OpenGL() : ogl2d::OpenGL()
- {
- }
+ OpenGL();
+
+ void setColor(Channel r, Channel g, Channel b, Channel a);
+
+ void setColor(Color c);
+
+ Color getColor();
+
+ void clearMatrix();
+
+ void push();
+
+ void pop();
+
+ void translate(float x, float y);
+
+ void scale(float sx, float sy);
+
+ void rotate(float r);
+
+ const Math::Matrix& getMatrix() { return mMatrix; };
+
+ private:
+
+ void calcMatrix();
+
+ Color mCurrentColor;
+ std::vector<Math::Matrix> mMatrices;
+ Math::Matrix mMatrix;
};
@@ -37,4 +67,4 @@ namespace JinEngine
} // namespace Graphics
} // namespace JinEngine
-#endif // __JE_OPENGL_H \ No newline at end of file
+#endif // __JE_OPENGL_H__ \ No newline at end of file
diff --git a/src/libjin/Graphics/je_graphic.cpp b/src/libjin/Graphics/je_graphic.cpp
index 831e409..6f3ff58 100644
--- a/src/libjin/Graphics/je_graphic.cpp
+++ b/src/libjin/Graphics/je_graphic.cpp
@@ -5,9 +5,11 @@
#include "../math/je_matrix.h"
-#include "shader/je_shader.h"
+#include "shaders/je_shader.h"
#include "je_graphic.h"
+using namespace JinEngine::Graphics::Shaders;
+
namespace JinEngine
{
namespace Graphics
@@ -17,32 +19,14 @@ namespace JinEngine
: mTexture(0)
, mSize(w, h)
{
- mVertexCoords[0] = 0; mVertexCoords[1] = 0;
- mVertexCoords[2] = 0; mVertexCoords[3] = h;
- mVertexCoords[4] = w; mVertexCoords[5] = h;
- mVertexCoords[6] = w; mVertexCoords[7] = 0;
-
- mTextureCoords[0] = 0; mTextureCoords[1] = 0;
- mTextureCoords[2] = 0; mTextureCoords[3] = 1;
- mTextureCoords[4] = 1; mTextureCoords[5] = 1;
- mTextureCoords[6] = 1; mTextureCoords[7] = 0;
+ mTexture = gl.genTexture();
}
Graphic::Graphic(const Bitmap* bitmap)
: mTexture(0)
{
- uint32 w = mSize.w = bitmap->getWidth();
- uint32 h = mSize.h = bitmap->getHeight();
-
- mVertexCoords[0] = 0; mVertexCoords[1] = 0;
- mVertexCoords[2] = 0; mVertexCoords[3] = h;
- mVertexCoords[4] = w; mVertexCoords[5] = h;
- mVertexCoords[6] = w; mVertexCoords[7] = 0;
-
- mTextureCoords[0] = 0; mTextureCoords[1] = 0;
- mTextureCoords[2] = 0; mTextureCoords[3] = 1;
- mTextureCoords[4] = 1; mTextureCoords[5] = 1;
- mTextureCoords[6] = 1; mTextureCoords[7] = 0;
+ mSize.w = bitmap->getWidth();
+ mSize.h = bitmap->getHeight();
const Color* pixels = bitmap->getPixels();
@@ -50,7 +34,7 @@ namespace JinEngine
gl.bindTexture(mTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- gl.texImage(GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
+ gl.texImage(GL_RGBA8, mSize.w, mSize.h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
gl.bindTexture(0);
}
@@ -59,49 +43,63 @@ namespace JinEngine
glDeleteTextures(1, &mTexture);
}
- void Graphic::draw(int x, int y, float sx, float sy, float r, float ox, float oy)
+ void Graphic::render(int x, int y, float sx, float sy, float r, float ox, float oy) const
{
gl.ModelMatrix.setTransformation(x, y, r, sx, sy, ox, oy);
+ int w = getWidth(), h = getHeight();
+ static float vertexCoords[8];
+ static float textureCoords[8];
+ // Set vertex coordinates.
+ vertexCoords[0] = 0; vertexCoords[1] = 0;
+ vertexCoords[2] = 0; vertexCoords[3] = h;
+ vertexCoords[4] = w; vertexCoords[5] = h;
+ vertexCoords[6] = w; vertexCoords[7] = 0;
+ // Set texture coordinates.
+ textureCoords[0] = 0; textureCoords[1] = 0;
+ textureCoords[2] = 0; textureCoords[3] = 1;
+ textureCoords[4] = 1; textureCoords[5] = 1;
+ textureCoords[6] = 1; textureCoords[7] = 0;
+ // Set shader.
+ Shader* shader = Shader::getCurrentShader();
+ shader->sendMatrix4(SHADER_MODEL_MATRIX, &(gl.getMatrix() * gl.ModelMatrix));
+ shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
+ shader->setVertexPointer(2, GL_FLOAT, 0, vertexCoords);
+ shader->setUVPointer(2, GL_FLOAT, 0, textureCoords);
- Shader* shader = Shader::getCurrentShader();
- shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
- shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
- shader->bindVertexPointer(2, GL_FLOAT, 0, mVertexCoords);
- shader->bindUVPointer(2, GL_FLOAT, 0, mTextureCoords);
-
- gl.bindTexture(mTexture);
+ gl.bindTexture(getGLTexture());
gl.drawArrays(GL_QUADS, 0, 4);
gl.bindTexture(0);
}
-
- void Graphic::draw(const Math::Quad& slice, int x, int y, float sx, float sy, float r, float ax, float ay)
+
+ void Graphic::render(const Math::Quad& slice, int x, int y, float sx, float sy, float r, float ax, float ay) const
{
- float vertCoords[8] = {
- 0, 0,
- 0, slice.h,
- slice.w, slice.h,
- slice.w, 0
- };
+ static float vertexCoords[8];
+ static float textureCoords[8];
+
+ // Set vertex coordinates.
+ vertexCoords[0] = 0; vertexCoords[1] = 0;
+ vertexCoords[2] = 0; vertexCoords[3] = slice.h;
+ vertexCoords[4] = slice.w; vertexCoords[5] = slice.h;
+ vertexCoords[6] = slice.w; vertexCoords[7] = 0;
+ // Set texture coordinates.
float slx = slice.x / mSize.w;
float sly = slice.y / mSize.h;
float slw = slice.w / mSize.w;
float slh = slice.h / mSize.h;
- float texCoords[8] = {
- slx, sly,
- slx, sly + slh,
- slx + slw, sly + slh,
- slx + slw, sly
- };
+ textureCoords[0] = slx; textureCoords[1] = sly;
+ textureCoords[2] = slx; textureCoords[3] = sly + slh;
+ textureCoords[4] = slx + slw; textureCoords[5] = sly + slh;
+ textureCoords[6] = slx + slw; textureCoords[7] = sly;
gl.ModelMatrix.setTransformation(x, y, r, sx, sy, ax, ay);
Shader* shader = Shader::getCurrentShader();
- shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
+ shader->sendMatrix4(SHADER_MODEL_MATRIX, &(gl.getMatrix() * gl.ModelMatrix));
shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
- shader->bindVertexPointer(2, GL_FLOAT, 0, vertCoords);
- shader->bindUVPointer(2, GL_FLOAT, 0, texCoords);
+ shader->setVertexPointer(2, GL_FLOAT, 0, vertexCoords);
+ shader->setUVPointer(2, GL_FLOAT, 0, textureCoords);
- gl.bindTexture(mTexture);
+ gl.bindTexture(getGLTexture());
gl.drawArrays(GL_QUADS, 0, 4);
gl.bindTexture(0);
}
diff --git a/src/libjin/Graphics/je_graphic.h b/src/libjin/Graphics/je_graphic.h
index fb6b19e..91c8b44 100644
--- a/src/libjin/Graphics/je_graphic.h
+++ b/src/libjin/Graphics/je_graphic.h
@@ -1,5 +1,5 @@
-#ifndef __JE_GRAPHIC_H
-#define __JE_GRAPHIC_H
+#ifndef __JE_GRAPHIC_H__
+#define __JE_GRAPHIC_H__
#include "../core/je_configuration.h"
#if defined(jin_graphics)
@@ -14,21 +14,14 @@ namespace JinEngine
namespace Graphics
{
- //
- // Graphic
- // |-Texture
- // |-Canvas
- //
-
///
- /// Class inherites Graphic doesn't keep any state such as origin, scale and other
- /// properties.
+ /// Class inherites Graphic doesn't keep any state such as origin, scale and other properties.
///
class Graphic
{
public:
///
- ///
+ ///
///
Graphic(int w = 0, int h = 0);
@@ -45,16 +38,6 @@ namespace JinEngine
///
///
///
- void draw(int x, int y, float sx = 1, float sy = 1, float r = 0, float ox = 0, float oy = 0);
-
- ///
- ///
- ///
- void draw(const Math::Quad& slice, int x, int y, float sx = 1, float sy = 1, float r = 0, float ax = 0, float ay = 0);
-
- ///
- ///
- ///
inline int getWidth() const { return mSize.w; }
///
@@ -63,24 +46,33 @@ namespace JinEngine
inline int getHeight() const { return mSize.h; }
///
- ///
+ /// Get opengl texture token.
+ ///
+ /// @return OpenGL texture token.
///
- inline GLuint getTexture() const { return mTexture; }
+ inline GLuint getGLTexture() const { return mTexture; }
///
///
///
void setFilter(GLint min, GLint max);
+ ///
+ /// Render graphic single with given coordinates.
+ ///
+ void render(int x, int y, float sx = 1, float sy = 1, float r = 0, float ox = 0, float oy = 0) const;
+
+ ///
+ /// Render part of graphic single with given coordinates.
+ ///
+ void render(const Math::Quad& slice, int x, int y, float sx = 1, float sy = 1, float r = 0, float ox = 0, float oy = 0) const;
+
protected:
- GLuint mTexture;
+ Math::Vector2<uint> mSize;
private:
- JinEngine::Math::Vector2<uint> mSize;
- // Screen coordinates and uv coordinates.
- float mVertexCoords[8];
- float mTextureCoords[8];
-
+ GLuint mTexture;
+
};
} // namespace Graphics
@@ -88,4 +80,4 @@ namespace JinEngine
#endif // defined(jin_graphics)
-#endif // __JE_GRAPHIC_H \ No newline at end of file
+#endif // __JE_GRAPHIC_H__ \ No newline at end of file
diff --git a/src/libjin/Graphics/je_graphics.h b/src/libjin/Graphics/je_graphics.h
index 2ba003d..979d8f4 100644
--- a/src/libjin/Graphics/je_graphics.h
+++ b/src/libjin/Graphics/je_graphics.h
@@ -1,5 +1,5 @@
-#ifndef __JE_GRAPHICS_H
-#define __JE_GRAPHICS_H
+#ifndef __JE_GRAPHICS_H__
+#define __JE_GRAPHICS_H__
#include "../core/je_configuration.h"
#if defined(jin_graphics)
@@ -10,12 +10,28 @@
#include "je_window.h"
#include "je_bitmap.h"
#include "je_image.h"
+#include "je_sprite.h"
+#include "je_sprite_sheet.h"
-#include "shader/je_shader.h"
+#include "shaders/je_shader.h"
-#include "font/je_ttf.h"
-#include "font/je_text.h"
-#include "font/je_texture_font.h"
+#include "fonts/je_ttf.h"
+#include "fonts/je_text.h"
+#include "fonts/je_texture_font.h"
+
+#include "particles/je_particle_system.h"
+
+//struct Stats
+//{
+// int drawCalls;
+// int drawCallsBatched;
+// int canvasSwitches;
+// int shaderSwitches;
+// int canvases;
+// int images;
+// int fonts;
+// int64 textureMemory;
+//};
#endif // defined(jin_graphics)
-#endif // __JE_GRAPHICS_H \ No newline at end of file
+#endif // __JE_GRAPHICS_H__ \ No newline at end of file
diff --git a/src/libjin/Graphics/je_image.cpp b/src/libjin/Graphics/je_image.cpp
index f800423..6baf16d 100644
--- a/src/libjin/Graphics/je_image.cpp
+++ b/src/libjin/Graphics/je_image.cpp
@@ -1,6 +1,7 @@
-#include "../3rdparty/stb/stb_image.h"
#include "../filesystem/je_asset_database.h"
+#include "stb/stb_image.h"
+
#include "je_image.h"
namespace JinEngine
diff --git a/src/libjin/Graphics/je_image.h b/src/libjin/Graphics/je_image.h
index 04ee4d2..971ac18 100644
--- a/src/libjin/Graphics/je_image.h
+++ b/src/libjin/Graphics/je_image.h
@@ -1,5 +1,5 @@
-#ifndef __JE_IMAGE_H
-#define __JE_IMAGE_H
+#ifndef __JE_IMAGE_H__
+#define __JE_IMAGE_H__
#include "je_bitmap.h"
@@ -13,7 +13,8 @@ namespace JinEngine
///
/// Just like bitmap but only from image file. The pixels data is readonly.
///
- class Image : public Bitmap
+ class Image
+ : public Bitmap
{
public:
///
diff --git a/src/libjin/Graphics/je_mesh.h b/src/libjin/Graphics/je_mesh.h
index ed22d91..e0a38f8 100644
--- a/src/libjin/Graphics/je_mesh.h
+++ b/src/libjin/Graphics/je_mesh.h
@@ -1,5 +1,7 @@
-#ifndef __JE_MESH_H
-#define __JE_MESH_H
+#ifndef __JE_MESH_H__
+#define __JE_MESH_H__
+
+#include "je_graphic.h"
namespace JinEngine
{
@@ -7,14 +9,16 @@ namespace JinEngine
{
///
- ///
+ /// A 2D mesh.
///
class Mesh
{
public:
+ void setGraphic();
+
private:
-
+ const Graphic* mGraphic;
};
diff --git a/src/libjin/Graphics/je_shapes.cpp b/src/libjin/Graphics/je_shapes.cpp
index 3146f31..486c506 100644
--- a/src/libjin/Graphics/je_shapes.cpp
+++ b/src/libjin/Graphics/je_shapes.cpp
@@ -6,9 +6,11 @@
#include "../math/je_matrix.h"
#include "../math/je_constant.h"
-#include "shader/je_shader.h"
+#include "shaders/je_shader.h"
#include "je_shapes.h"
+using namespace JinEngine::Graphics::Shaders;
+
namespace JinEngine
{
namespace Graphics
@@ -21,9 +23,9 @@ namespace JinEngine
float verts[] = { x + 0.5f , y + 0.5f };
Shader* shader = Shader::getCurrentShader();
- shader->bindVertexPointer(2, GL_FLOAT, 0, verts);
+ shader->setVertexPointer(2, GL_FLOAT, 0, verts);
gl.ModelMatrix.setIdentity();
- shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
+ shader->sendMatrix4(SHADER_MODEL_MATRIX, &(gl.getMatrix() * gl.ModelMatrix));
shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
glDrawArrays(GL_POINTS, 0, 1);
@@ -32,9 +34,9 @@ namespace JinEngine
void points(int n, GLshort* p)
{
Shader* shader = Shader::getCurrentShader();
- shader->bindVertexPointer(2, GL_SHORT, 0, p);
+ shader->setVertexPointer(2, GL_SHORT, 0, p);
gl.ModelMatrix.setIdentity();
- shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
+ shader->sendMatrix4(SHADER_MODEL_MATRIX, &(gl.getMatrix() * gl.ModelMatrix));
shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
glDrawArrays(GL_POINTS, 0, n);
@@ -43,14 +45,14 @@ namespace JinEngine
void line(int x1, int y1, int x2, int y2)
{
float verts[] = {
- x1, y1,
- x2, y2
+ x1 + 0.5f, y1 + 0.5f,
+ x2 + 0.5f, y2 + 0.5f
};
Shader* shader = Shader::getCurrentShader();
- shader->bindVertexPointer(2, GL_FLOAT, 0, verts);
+ shader->setVertexPointer(2, GL_FLOAT, 0, verts);
gl.ModelMatrix.setIdentity();
- shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
+ shader->sendMatrix4(SHADER_MODEL_MATRIX, &(gl.getMatrix() * gl.ModelMatrix));
shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
glDrawArrays(GL_LINES, 0, 2);
@@ -83,13 +85,13 @@ namespace JinEngine
void rect(RenderMode mode, int x, int y, int w, int h)
{
- float coords[] = { x, y, x + w, y, x + w, y + h, x, y + h };
+ float coords[] = { x + 0.5f, y + 0.5f, x + w + 0.5f, y + 0.5f, x + w + 0.5f, y + h + 0.5f, x + 0.5f, y + h + 0.5f };
polygon(mode, coords, 4);
}
void triangle(RenderMode mode, int x1, int y1, int x2, int y2, int x3, int y3)
{
- float coords[] = { x1, y1, x2, y2, x3, y3 };
+ float coords[] = { x1 + 0.5f, y1 + 0.5f, x2 + 0.5f, y2 + 0.5f, x3 + 0.5f, y3 + 0.5f };
polygon(mode, coords, 3);
}
@@ -97,9 +99,9 @@ namespace JinEngine
{
Shader* shader = Shader::getCurrentShader();
gl.ModelMatrix.setIdentity();
- shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
+ shader->sendMatrix4(SHADER_MODEL_MATRIX, &(gl.getMatrix() * gl.ModelMatrix));
shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
- shader->bindVertexPointer(2, GL_FLOAT, 0, p);
+ shader->setVertexPointer(2, GL_FLOAT, 0, p);
glDrawArrays(GL_LINE_LOOP, 0, count);
}
@@ -114,9 +116,9 @@ namespace JinEngine
{
Shader* shader = Shader::getCurrentShader();
gl.ModelMatrix.setIdentity();
- shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
+ shader->sendMatrix4(SHADER_MODEL_MATRIX, &(gl.getMatrix() * gl.ModelMatrix));
shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
- shader->bindVertexPointer(2, GL_FLOAT, 0, p);
+ shader->setVertexPointer(2, GL_FLOAT, 0, p);
glDrawArrays(GL_POLYGON, 0, count);
}
diff --git a/src/libjin/Graphics/je_shapes.h b/src/libjin/Graphics/je_shapes.h
index 2221526..d62592b 100644
--- a/src/libjin/Graphics/je_shapes.h
+++ b/src/libjin/Graphics/je_shapes.h
@@ -1,5 +1,5 @@
-#ifndef __JE_GEOMETRY_H
-#define __JE_GEOMETRY_H
+#ifndef __JE_GEOMETRY_H__
+#define __JE_GEOMETRY_H__
#include "../core/je_configuration.h"
#if defined(jin_graphics)
@@ -12,11 +12,11 @@ namespace JinEngine
namespace Graphics
{
- typedef enum {
+ enum RenderMode {
NONE = 0,
FILL ,
LINE
- }RenderMode;
+ };
extern void line(int x1, int y1, int x2, int y2);
extern void rect(RenderMode mode, int x, int y, int w, int h);
@@ -31,4 +31,4 @@ namespace JinEngine
#endif // jin_graphics
-#endif // __JE_GEOMETRY_H \ No newline at end of file
+#endif // __JE_GEOMETRY_H__ \ No newline at end of file
diff --git a/src/libjin/Graphics/je_sprite.cpp b/src/libjin/Graphics/je_sprite.cpp
index 3ac976a..810cb0e 100644
--- a/src/libjin/Graphics/je_sprite.cpp
+++ b/src/libjin/Graphics/je_sprite.cpp
@@ -1,11 +1,156 @@
+#include "shaders/je_shader.h"
+
#include "je_sprite.h"
+using namespace JinEngine::Math;
+using namespace JinEngine::Graphics::Shaders;
+
namespace JinEngine
{
namespace Graphics
{
+ Sprite::Sprite()
+ : mShader(nullptr)
+ , mGraphic(nullptr)
+ , mScale(1, 1)
+ , mColor(255, 255, 255, 255)
+ , mIsOriginEnum(false)
+ {
+ }
+
+ Sprite::~Sprite()
+ {
+ }
+
+ void Sprite::setQuad(int x, int y, int w, int h)
+ {
+ mQuad.x = x;
+ mQuad.y = y;
+ mQuad.w = w;
+ mQuad.h = h;
+ if (mIsOriginEnum)
+ setOrigin(mOriginEnum);
+ }
+
+ void Sprite::setRotation(float r)
+ {
+ mRotation = r;
+ }
+
+ void Sprite::setOrigin(Origin origin)
+ {
+ mIsOriginEnum = true;
+ mOriginEnum = origin;
+ int l = 0, r = 0, t = 0, b = 0;
+ Vector2<int> size = getSize();
+ r = size.w;
+ b = size.h;
+ switch (origin)
+ {
+ case TopLeft:
+ mOrigin.x = l;
+ mOrigin.y = t;
+ break;
+ case TopCenter:
+ mOrigin.x = r/2.f;
+ mOrigin.y = t;
+ break;
+ case TopRight:
+ mOrigin.x = r;
+ mOrigin.y = t;
+ break;
+ case MiddleLeft:
+ mOrigin.x = l;
+ mOrigin.y = b/2.f;
+ break;
+ case MiddleCenter:
+ mOrigin.x = r/2.f;
+ mOrigin.y = b/2.f;
+ break;
+ case MiddleRight:
+ mOrigin.x = r;
+ mOrigin.y = b/2.f;
+ break;
+ case BottomLeft:
+ mOrigin.x = l;
+ mOrigin.y = b;
+ break;
+ case BottomCenter:
+ mOrigin.x = r/2.f;
+ mOrigin.y = b;
+ break;
+ case BottomRight:
+ mOrigin.x = r;
+ mOrigin.y = b;
+ break;
+ }
+ }
+
+ void Sprite::setOrigin(int x, int y)
+ {
+ mOrigin.set(x, y);
+ mIsOriginEnum = false;
+ }
+
+ void Sprite::setPosition(float x, float y)
+ {
+ mPosition.set(x, y);
+ }
+
+ void Sprite::setScale(float x, float y)
+ {
+ mScale.set(x, y);
+ }
+
+ void Sprite::setColor(Color color)
+ {
+ mColor = color;
+ }
+
+ void Sprite::setShader(Shader* shader)
+ {
+ mShader = shader;
+ }
+
+ void Sprite::setGraphic(const Graphic* graphic)
+ {
+ mGraphic = graphic;
+ int w = mGraphic->getWidth();
+ int h = mGraphic->getHeight();
+ setQuad(0, 0, w, h);
+ }
+
+
+ void Sprite::move(float x, float y)
+ {
+ mPosition.x += x;
+ mPosition.y += y;
+ }
+
+ void Sprite::rotate(float r)
+ {
+ mRotation += r;
+ }
+
+ void Sprite::scale(float sx, float sy)
+ {
+ mScale.x += sx;
+ mScale.y += sy;
+ }
+ void Sprite::render()
+ {
+ Shader* shader = Shader::getCurrentShader();
+ Color c = gl.getColor();
+ gl.setColor(mColor);
+ if(mShader != nullptr)
+ mShader->use();
+ if(mGraphic != nullptr)
+ mGraphic->render(mQuad, mPosition.x, mPosition.y, mScale.x, mScale.y, mRotation, mOrigin.x, mOrigin.y);
+ shader->use();
+ gl.setColor(c);
+ }
} // namespace Graphics
} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/Graphics/je_sprite.h b/src/libjin/Graphics/je_sprite.h
index 3b96162..65e00eb 100644
--- a/src/libjin/Graphics/je_sprite.h
+++ b/src/libjin/Graphics/je_sprite.h
@@ -1,34 +1,85 @@
-#ifndef __JE_SPRITE_H
-#define __JE_SPRITE_H
+#ifndef __JE_SPRITE_H__
+#define __JE_SPRITE_H__
#include "../common/je_types.h"
#include "../math/je_vector2.hpp"
-#include "shader/je_shader.h"
+#include "shaders/je_shader.h"
#include "je_color.h"
namespace JinEngine
{
namespace Graphics
{
+
///
- /// A sprite is unit of rendering, logic and events.
+ /// A sprite is unit of rendering. Animation is based on sprite, but not texture or other graphic stuff.
///
class Sprite
{
public:
- void setOrigin(float x, float y);
- void setPosition(int x, int y);
- void setScale(float x, float y);
+ Sprite();
+ virtual ~Sprite();
+
+ enum Origin
+ {
+ TopLeft,
+ TopCenter,
+ TopRight,
+ MiddleLeft,
+ MiddleCenter,
+ MiddleRight,
+ BottomLeft,
+ BottomCenter,
+ BottomRight
+ };
+
+ void setQuad(int x, int y, int w, int h);
+ void setRotation(float r);
+ void setOrigin(Origin origin);
+ void setOrigin(int x, int y);
+ void setPosition(float x, float y);
+ void setScale(float sx, float sy);
void setColor(Color color);
- void setShader(const Shader* shader);
+ void setShader(Shaders::Shader* shader);
+ void setGraphic(const Graphic* graphic);
+
+ void move(float x, float y);
+ void rotate(float r);
+ void scale(float sx, float sy);
+
+ float getRotation() { return mRotation; }
+ Math::Vector2<int> getSize() { return Math::Vector2<int>(mQuad.w, mQuad.h); }
+ const Math::Quad& getQuad() { return mQuad; }
+ const Math::Vector2<float>& getPosition() { return mPosition; }
+ const Math::Vector2<int>& getOrigin() { return mOrigin; }
+ const Math::Vector2<float>& getScale() { return mScale; }
+ const Color& getColor() { return mColor; }
+ const Graphic* getGraphic() { return mGraphic; }
+ const Shaders::Shader* getShader() { return mShader; }
+
+ ///
+ /// Render callback.
+ ///
+ virtual void render();
private:
- Math::Vector2<int> mPosition;
- Math::Vector2<float> mOrigin;
+ ///
+ /// Origin must be 0~1 float value.
+ ///
+ Math::Vector2<float> mPosition;
+ Math::Vector2<int> mOrigin;
Math::Vector2<float> mScale;
+ float mRotation;
Color mColor;
- const Shader* mShader;
+
+ Math::Quad mQuad;
+
+ bool mIsOriginEnum;
+ Origin mOriginEnum;
+
+ Shaders::Shader* mShader;
+ const Graphic* mGraphic;
};
diff --git a/src/libjin/Graphics/je_sprite_batch.cpp b/src/libjin/Graphics/je_sprite_batch.cpp
index e69de29..f339715 100644
--- a/src/libjin/Graphics/je_sprite_batch.cpp
+++ b/src/libjin/Graphics/je_sprite_batch.cpp
@@ -0,0 +1,11 @@
+#include "je_sprite_batch.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+
+
+
+ }
+} \ No newline at end of file
diff --git a/src/libjin/Graphics/je_sprite_batch.h b/src/libjin/Graphics/je_sprite_batch.h
index 85a7951..64f9805 100644
--- a/src/libjin/Graphics/je_sprite_batch.h
+++ b/src/libjin/Graphics/je_sprite_batch.h
@@ -1,5 +1,5 @@
-#ifndef __JE_SPRITE_BATCH_H
-#define __JE_SPRITE_BATCH_H
+#ifndef __JE_GRAPHICS_SPRITE_BATCH_H__
+#define __JE_GRAPHICS_SPRITE_BATCH_H__
namespace JinEngine
{
@@ -8,10 +8,13 @@ namespace JinEngine
class SpriteBatch
{
+ public:
+
+ private:
};
} // namespace Graphics
-} // namespace JinEngine
+} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/je_sprite_sheet.cpp b/src/libjin/Graphics/je_sprite_sheet.cpp
new file mode 100644
index 0000000..3a08751
--- /dev/null
+++ b/src/libjin/Graphics/je_sprite_sheet.cpp
@@ -0,0 +1,22 @@
+#include "je_sprite_sheet.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+
+ SpriteSheet::SpriteSheet(const Graphic* graphic)
+ : mGraphic(graphic)
+ {
+ }
+
+ Sprite* SpriteSheet::createSprite(const Math::Quad& quad)
+ {
+ Sprite* spr = new Sprite();
+ spr->setGraphic(mGraphic);
+ spr->setQuad(quad.x, quad.y, quad.w, quad.h);
+ return spr;
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/libjin/Graphics/je_sprite_sheet.h b/src/libjin/Graphics/je_sprite_sheet.h
new file mode 100644
index 0000000..8c56c51
--- /dev/null
+++ b/src/libjin/Graphics/je_sprite_sheet.h
@@ -0,0 +1,33 @@
+#ifndef __JE_SPRITE_SHEET_H__
+#define __JE_SPRITE_SHEET_H__
+
+#include <vector>
+
+#include "../math/je_quad.h"
+
+#include "je_sprite.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+
+ class SpriteSheet
+ {
+ public:
+ ///
+ /// Create a new sprite in sheet.
+ ///
+ Sprite* createSprite(const Math::Quad& quad);
+
+ SpriteSheet(const Graphic* graphic);
+
+ private:
+ const Graphic* const mGraphic;
+
+ };
+
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/je_texture.h b/src/libjin/Graphics/je_texture.h
index ddc8cfc..566ba84 100644
--- a/src/libjin/Graphics/je_texture.h
+++ b/src/libjin/Graphics/je_texture.h
@@ -1,9 +1,9 @@
-#ifndef __JE_TEXTURE_H
-#define __JE_TEXTURE_H
+#ifndef __JE_TEXTURE_H__
+#define __JE_TEXTURE_H__
#include "../core/je_configuration.h"
#if defined(jin_graphics)
-#include "../3rdparty/GLee/GLee.h"
+#include "GLee/GLee.h"
#include "je_color.h"
#include "je_graphic.h"
@@ -17,7 +17,8 @@ namespace JinEngine
///
///
///
- class Texture: public Graphic
+ class Texture
+ : public Graphic
{
public:
///
@@ -53,4 +54,4 @@ namespace JinEngine
#endif // jin_graphics
-#endif // __JE_TEXTURE_H \ No newline at end of file
+#endif // __JE_TEXTURE_H__ \ No newline at end of file
diff --git a/src/libjin/Graphics/je_window.cpp b/src/libjin/Graphics/je_window.cpp
index f0b789e..c14d290 100644
--- a/src/libjin/Graphics/je_window.cpp
+++ b/src/libjin/Graphics/je_window.cpp
@@ -3,15 +3,18 @@
#include <iostream>
+#include "../common/je_exception.h"
#include "../utils/je_utils.h"
#include "../audio/sdl/je_sdl_audio.h"
#include "../utils/je_log.h"
-#include "shader/je_shader.h"
+#include "shaders/je_shader.h"
#include "je_window.h"
#include "je_gl.h"
#include "je_canvas.h"
+using namespace JinEngine::Graphics::Shaders;
+
namespace JinEngine
{
namespace Graphics
@@ -19,9 +22,7 @@ namespace JinEngine
bool Window::initSystem(const SettingBase* s)
{
- #if defined(jin_debug)
- Loghelper::log(Loglevel::LV_INFO, "Init window system");
- #endif
+ jin_log_info("Initialize window system.");
if (SDL_Init(SDL_INIT_VIDEO) < 0)
return false;
@@ -30,8 +31,9 @@ namespace JinEngine
mSize.w = setting->width;
mSize.h = setting->height;
mFps = setting->fps;
- bool vsync = setting->vsync;
- const char* title = setting->title;
+ bool vsync = setting->vsync;
+ const char* title = setting->title;
+ const char* icon = setting->icon;
if (mWnd)
{
@@ -58,34 +60,51 @@ namespace JinEngine
int wx = SDL_WINDOWPOS_UNDEFINED,
wy = SDL_WINDOWPOS_UNDEFINED;
- int flag = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL;
+ int flag = SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL;
if (setting->fullscreen) flag |= SDL_WINDOW_FULLSCREEN;
if (setting->resizable) flag |= SDL_WINDOW_RESIZABLE;
mWnd = SDL_CreateWindow(title, wx, wy, mSize.w, mSize.h, flag);
if (mWnd == NULL)
return false;
+
+ // Set window icon
+ try
+ {
+ Bitmap* bitmap = Bitmap::createBitmap(icon);
+ SDL_Surface *surface;
+ Color* pixels = const_cast<Color*>(bitmap->getPixels());
+ uint w = bitmap->getWidth(), h = bitmap->getHeight();
+ surface = SDL_CreateRGBSurfaceFrom(
+ pixels, w, h, 32, w * 4, Color::RMASK, Color::GMASK, Color::BMASK, Color::AMASK);
+ SDL_SetWindowIcon(mWnd, surface);
+ SDL_FreeSurface(surface);
+ } catch (...) {}
+
ctx = SDL_GL_CreateContext(mWnd);
if (ctx == NULL)
return false;
SDL_GL_SetSwapInterval(vsync ? 1 : 0);
SDL_GL_MakeCurrent(mWnd, ctx);
- // default configuration
+ // Default configuration
gl.setClearColor(0, 0, 0, 0xff);
- gl.pushColor(0xff, 0xff, 0xff, 0xff);
+ glClear(GL_COLOR_BUFFER_BIT);
+ gl.pushColor(0xff, 0xff, 0xff, 0xff);
gl.enable(GL_BLEND);
gl.enable(GL_TEXTURE_2D);
gl.setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- // avoid white screen blink on windows
- swapBuffers();
- // bind to default canvas
+ // Bind to default canvas
Canvas::unbind();
Shader::unuse();
+ // Avoid white blinnk.
+ swapBuffers();
+
return true;
}
void Window::quitSystem()
{
+ jin_log_info("Quit window system.");
// disable opengl
gl.disable(GL_BLEND);
gl.disable(GL_TEXTURE_2D);
diff --git a/src/libjin/Graphics/je_window.h b/src/libjin/Graphics/je_window.h
index 7ca1e5e..831f3e6 100644
--- a/src/libjin/Graphics/je_window.h
+++ b/src/libjin/Graphics/je_window.h
@@ -16,7 +16,8 @@ namespace JinEngine
///
///
///
- class Window : public Subsystem<Window>
+ class Window
+ : public Subsystem<Window>
{
public:
///
@@ -26,6 +27,7 @@ namespace JinEngine
{
public:
const char* title; ///< window title
+ const char* icon; ///< window icon
bool fullscreen; ///< full screen
int width, height; ///< window size
bool vsync; ///< vsync
@@ -58,6 +60,16 @@ namespace JinEngine
///
void swapBuffers();
+ ///
+ ///
+ ///
+ inline void hide() { SDL_HideWindow(mWnd); };
+
+ ///
+ ///
+ ///
+ void show() { SDL_ShowWindow(mWnd); };
+
private:
// declare a singleton
diff --git a/src/libjin/Graphics/particle/je_particle.h b/src/libjin/Graphics/particle/je_particle.h
deleted file mode 100644
index 2a5c54f..0000000
--- a/src/libjin/Graphics/particle/je_particle.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef __JE_PARTICLE_H
-#define __JE_PARTICLE_H
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- ///
- /// Single particle.
- ///
- class Particle
- {
-
-
- };
-
- } // namespace Graphics
-} // namespace JinEngine
-
-#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/particle/je_particle_batch.h b/src/libjin/Graphics/particle/je_particle_batch.h
deleted file mode 100644
index 19f4ded..0000000
--- a/src/libjin/Graphics/particle/je_particle_batch.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef __JE_PARTICLE_BATCH_H
-#define __JE_PARTICLE_BATCH_H
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- ///
- ///
- ///
- class ParticleBatch
- {
-
- };
-
- } // namespace Graphics
-} // namespace JinEngine
-
-#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/particle/je_particle_emitter.h b/src/libjin/Graphics/particle/je_particle_emitter.h
deleted file mode 100644
index e191e36..0000000
--- a/src/libjin/Graphics/particle/je_particle_emitter.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef __JE_PARTICLE_EMMITTER_H
-#define __JE_PARTICLE_EMMITTER_H
-
-namespace JinEngine
-{
- namespace Graphics
- {
-
- ///
- /// Particle emitter
- ///
- class ParticleEmitter
- {
- public:
-
- private:
-
- };
-
- }
-}
-
-#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/particles/je_particle.cpp b/src/libjin/Graphics/particles/je_particle.cpp
new file mode 100644
index 0000000..20bbd03
--- /dev/null
+++ b/src/libjin/Graphics/particles/je_particle.cpp
@@ -0,0 +1,26 @@
+#include "je_particle.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Particles
+ {
+
+ void Particle::reset()
+ {
+ lifeTime = 0.0f;
+ life = 0.0f;
+ position.set(0, 0);
+ direction = 0.0f;
+ speed.set(0, 0);
+ linearAcceleration.set(0, 0);
+ radialAcceleration = 0.0f;
+ size = 1;
+ sizeBegin = 1;
+ alive = true;
+ }
+
+ }
+ }
+} \ No newline at end of file
diff --git a/src/libjin/Graphics/particles/je_particle.h b/src/libjin/Graphics/particles/je_particle.h
new file mode 100644
index 0000000..2d112d1
--- /dev/null
+++ b/src/libjin/Graphics/particles/je_particle.h
@@ -0,0 +1,178 @@
+#ifndef __JE_PARTICLE_H__
+#define __JE_PARTICLE_H__
+
+#include "../../math/je_vector2.hpp"
+#include "../je_color.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Particles
+ {
+
+ class ParticleEmitter;
+
+ ///
+ ///
+ ///
+ struct LifeTimeDef
+ {
+ bool enableRandom = false;
+ union
+ {
+ struct
+ {
+ float min, max;
+ } random;
+ float life;
+ } life;
+ };
+
+ ///
+ ///
+ ///
+ struct SpeedOverTimeDef
+ {
+ bool enable = false;
+ bool enableRandom = false;
+ union
+ {
+ struct
+ {
+ Math::Vector2<float> startFloor;
+ Math::Vector2<float> startCeil;
+ Math::Vector2<float> endFloor;
+ Math::Vector2<float> endCeil;
+ } random;
+ struct
+ {
+ Math::Vector2<float> start;
+ Math::Vector2<float> end;
+ } speed;
+ } speed;
+ };
+
+ struct SizeOverTimeDef
+ {
+ bool enable = false;
+ bool enableRandom = false;
+ union {
+ struct {
+ float startFloor = 1;
+ float startCeil = 1;
+ float endFloor = 1;
+ float endCeil = 1;
+ } random;
+ struct {
+ float start = 1;
+ float end = 1;
+ } size;
+ } size;
+ };
+
+ struct ColorOverTimeDef
+ {
+ bool enable = false;
+ Color colorStart = Color::WHITE;
+ Color colorEnd = Color::WHITE;
+ };
+
+ struct linearAccelarationDef
+ {
+ Math::Vector2<float> linearAccelaration;
+ };
+
+ struct RadialAccelarationDef
+ {
+ float radialAccelaration;
+ };
+
+ ///
+ ///
+ ///
+ struct ParticleDef
+ {
+ private:
+ friend class ParticleEmitter;
+
+ public:
+ // Basic definitions.
+ LifeTimeDef lifeTimeDef; ///<
+ linearAccelarationDef linearAccelarationDef; ///<
+ RadialAccelarationDef radialAccelarationDef; ///<
+ // Optional definitions.
+ SpeedOverTimeDef speedOverTimeDef; ///<
+ SizeOverTimeDef sizeOverTimeDef; ///<
+ ColorOverTimeDef colorOverTimeDef; ///<
+ };
+
+ ///
+ /// A single particle contains various properties of particle, such as position, accelaration, color and
+ /// other attributes changed over time.
+ ///
+ struct Particle
+ {
+ ///
+ /// Default constructor.
+ ///
+ Particle() {};
+
+ ///
+ /// Reset to default.
+ ///
+ void reset();
+
+ ///
+ /// Whole life time.
+ ///
+ float lifeTime = 0.0f;
+
+ ///
+ /// Current life time.
+ ///
+ float life = 0.0f;
+
+ ///
+ /// Current position.
+ ///
+ Math::Vector2<float> position;
+
+ ///
+ /// Emitte direction.
+ ///
+ float direction = 0;
+
+ Math::Vector2<float> speed;
+ Math::Vector2<float> linearAcceleration;
+ float radialAcceleration = 0;
+
+ ///
+ /// Size over lifetime.
+ ///
+ float size = 1;
+ float sizeBegin = 1;
+ float sizeEnd = 1;
+
+ float rotation = 0;
+ float angle = 0;
+
+ ///
+ /// Color over lifetime.
+ ///
+ Color color = Color::WHITE;
+ Color colorStart = Color::WHITE;
+ Color colorEnd = Color::WHITE;
+
+ ///
+ /// Is particle still alive? Alive is equivalent to NOT available in particle pool.
+ ///
+ bool alive = true;
+
+ };
+
+ } // namespace Particles
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/particles/je_particle_emitter.cpp b/src/libjin/Graphics/particles/je_particle_emitter.cpp
new file mode 100644
index 0000000..edc4bee
--- /dev/null
+++ b/src/libjin/Graphics/particles/je_particle_emitter.cpp
@@ -0,0 +1,42 @@
+#include <time.h>
+
+#include "../../math/je_random.h"
+
+#include "je_particle_emitter.h"
+
+using namespace JinEngine::Math;
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Particles
+ {
+
+ // Particle emitter
+ static RandomGenerator rnd(time(NULL));
+
+ ParticleEmitter::ParticleEmitter(ParticleSystem& ps)
+ : mParticleSystem(ps)
+ {
+ }
+
+ void ParticleEmitter::update(float dt)
+ {
+ mTime += dt;
+ if (mTime < 1)
+ return;
+
+
+ mTime -= 1;
+ }
+
+ void ParticleEmitter::emit()
+ {
+
+
+ }
+
+ }
+ }
+} \ No newline at end of file
diff --git a/src/libjin/Graphics/particles/je_particle_emitter.h b/src/libjin/Graphics/particles/je_particle_emitter.h
new file mode 100644
index 0000000..9200532
--- /dev/null
+++ b/src/libjin/Graphics/particles/je_particle_emitter.h
@@ -0,0 +1,112 @@
+#ifndef __JE_PARTICLE_EMITTER_H__
+#define __JE_PARTICLE_EMITTER_H__
+
+#include "../../common/je_temporary.h"
+#include "../../math/je_vector2.hpp"
+
+#include "je_particle.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Particles
+ {
+
+ struct PositionDef
+ {
+ bool enableRandom = false;
+ union
+ {
+ struct
+ {
+ Math::Vector2<float> min;
+ Math::Vector2<float> max;
+ } random;
+ Math::Vector2<float> position;
+ } position;
+ };
+
+ struct DirectionDef
+ {
+ bool enableRandom = false;
+ union
+ {
+ struct
+ {
+ float min = 0;
+ float max = 0;
+ } random;
+ float direction = 0;
+ } direction;
+ };
+
+ ///
+ /// How many particles emitted per second.
+ ///
+ struct EmitRateDef
+ {
+ bool enableRandom = false;
+ union
+ {
+ struct
+ {
+ float min = 1;
+ float max = 1;
+ } random;
+ float rate = 1;
+ } rate;
+ };
+
+ ///
+ /// Definition of particle emitter.
+ ///
+ struct ParticleEmitterDef : public Temporary
+ {
+ PositionDef positionDef; ///< Emit position(relativily to the particle system center).
+ DirectionDef directionDef; ///< Emit direction.
+ EmitRateDef emitRateDef; ///< Emit rate.
+ };
+
+ class ParticleSystem;
+
+ ///
+ /// Emit a single particle.
+ ///
+ class ParticleEmitter
+ {
+ public:
+ ///
+ ///
+ ///
+ ParticleEmitter(ParticleSystem& ps);
+
+ ///
+ ///
+ ///
+ void update(float dt);
+
+ private:
+ ///
+ ///
+ ///
+ ParticleSystem& mParticleSystem;
+
+ ///
+ /// Emit a particle according to emitter definition and particle definition, particle system should
+ /// assign particle value to the particle in particle pool, but not use this return particle.
+ ///
+ void emit();
+
+ ///
+ ///
+ ///
+ float mTime;
+
+ };
+
+ } // namespace Particles
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/particles/je_particle_pool.h b/src/libjin/Graphics/particles/je_particle_pool.h
new file mode 100644
index 0000000..46cd73a
--- /dev/null
+++ b/src/libjin/Graphics/particles/je_particle_pool.h
@@ -0,0 +1,24 @@
+#ifndef __JE_PARTICLE_BATCH_H__
+#define __JE_PARTICLE_BATCH_H__
+
+#include "../../common/je_pool.hpp"
+
+#include "je_particle.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Particles
+ {
+
+ ///
+ /// Particle pool for reducing memory fragmentation.
+ ///
+ typedef Pool<Particle> ParticlePool;
+
+ } // namespace Particles
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/particle/je_particle_emitter.cpp b/src/libjin/Graphics/particles/je_particle_system.cpp
index d57d5ed..68f8f21 100644
--- a/src/libjin/Graphics/particle/je_particle_emitter.cpp
+++ b/src/libjin/Graphics/particles/je_particle_system.cpp
@@ -1,4 +1,4 @@
-#include "je_particle_emitter.h"
+#include "je_particle_system.h"
namespace JinEngine
{
diff --git a/src/libjin/Graphics/particles/je_particle_system.h b/src/libjin/Graphics/particles/je_particle_system.h
new file mode 100644
index 0000000..afa96b2
--- /dev/null
+++ b/src/libjin/Graphics/particles/je_particle_system.h
@@ -0,0 +1,103 @@
+#ifndef __JE_PARTICLE_EMMITTER_H__
+#define __JE_PARTICLE_EMMITTER_H__
+
+#include <vector>
+
+#include "../../common/je_temporary.h"
+#include "../../game/je_gameobject.h"
+
+#include "../je_sprite.h"
+
+#include "je_particle_emitter.h"
+#include "je_particle_pool.h"
+#include "je_particle.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Particles
+ {
+
+ ///
+ /// Definition of particle system.
+ ///
+ struct ParticleSystemDef : public Temporary
+ {
+ uint maxParticleCount = 1; ///< Max count of particles in pool. 1 by default.
+
+ ParticleEmitterDef emitterDef; ///< Particle emitter definition.
+ ParticleDef particleDef; ///< Particle definition.
+ };
+
+ ///
+ /// Particle emitter, handle all particles it emitts.
+ ///
+ class ParticleSystem : public Game::GameObject
+ {
+ public:
+ ///
+ /// Particle system constructor
+ ///
+ /// @param def Definition of particle system.
+ ///
+ ParticleSystem(const ParticleSystemDef& def);
+
+ ///
+ /// Particle system destructor.
+ ///
+ ~ParticleSystem();
+
+ ///
+ /// Update particle system and all alive particles.
+ ///
+ void update(float sec);
+
+ ///
+ /// Render particle system.
+ ///
+ void render(int x, int y, float sx = 1, float sy = 1, float r = 0, float ax = 0, float ay = 0);
+
+ ///
+ /// Set sprite to render.
+ ///
+ /// @param sprite Sprite to render.
+ ///
+ void setSprite(Sprite* sprite);
+
+ private:
+ // Disable default constructor.
+ ParticleSystem();
+
+ ///
+ /// Particle system definition.
+ ///
+ ParticleSystemDef mDef;
+
+ ///
+ /// Sprite to be drawn.
+ ///
+ Sprite* mSprite;
+
+ ///
+ /// Particle emitter.
+ ///
+ ParticleEmitter mEmitter;
+
+ ///
+ /// Particle pool.
+ ///
+ ParticlePool mParticlePool;
+
+ ///
+ /// Alive particles, that means these particles could join to the life cycle loop.
+ ///
+ std::vector<Particle*> mAliveParticles;
+
+ };
+
+ } // namespace Particles
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/Shader/je_default.shader.h b/src/libjin/Graphics/shaders/built-in/je_default.shader.h
index 3f57c44..3f57c44 100644
--- a/src/libjin/Graphics/Shader/je_default.shader.h
+++ b/src/libjin/Graphics/shaders/built-in/je_default.shader.h
diff --git a/src/libjin/Graphics/Shader/je_font.shader.h b/src/libjin/Graphics/shaders/built-in/je_font.shader.h
index e04c225..e04c225 100644
--- a/src/libjin/Graphics/Shader/je_font.shader.h
+++ b/src/libjin/Graphics/shaders/built-in/je_font.shader.h
diff --git a/src/libjin/Graphics/Shader/je_texture.shader.h b/src/libjin/Graphics/shaders/built-in/je_texture.shader.h
index d1fc86f..d1fc86f 100644
--- a/src/libjin/Graphics/Shader/je_texture.shader.h
+++ b/src/libjin/Graphics/shaders/built-in/je_texture.shader.h
diff --git a/src/libjin/Graphics/Shader/je_base.shader.h b/src/libjin/Graphics/shaders/je_base.shader.h
index d6f9d7b..88fa872 100644
--- a/src/libjin/Graphics/Shader/je_base.shader.h
+++ b/src/libjin/Graphics/shaders/je_base.shader.h
@@ -1,5 +1,5 @@
-#ifndef __JE_BASE_SHADER_H
-#define __JE_BASE_SHADER_H
+#ifndef __JE_BASE_SHADER_H__
+#define __JE_BASE_SHADER_H__
static const char* base_shared = R"(
#define Number float
@@ -26,8 +26,9 @@ static const char* base_vertex = R"(
#version 130 core
%s
-
+// Projection matrix
uniform mat4 jin_ProjectionMatrix;
+// Model view matrix
uniform mat4 jin_ModelMatrix;
in vec2 jin_VertexCoords;
@@ -85,4 +86,4 @@ static const char* SHADER_MAIN_TEXTURE = "jin_MainTexture";
static const char* SHADER_VERTEX_COORDS = "jin_VertexCoords";
static const char* SHADER_TEXTURE_COORDS = "jin_TextureCoords";
-#endif // __JE_BASE_SHADER_H \ No newline at end of file
+#endif // __JE_BASE_SHADER_H__
diff --git a/src/libjin/Graphics/shaders/je_jsl_compiler.cpp b/src/libjin/Graphics/shaders/je_jsl_compiler.cpp
new file mode 100644
index 0000000..feb88d4
--- /dev/null
+++ b/src/libjin/Graphics/shaders/je_jsl_compiler.cpp
@@ -0,0 +1,57 @@
+#include "../../core/je_configuration.h"
+#if defined(jin_graphics) && (jin_graphics & jin_graphics_shader)
+
+#include "../../Filesystem/je_buffer.h"
+
+#include "je_jsl_compiler.h"
+
+using namespace std;
+using namespace JinEngine::Filesystem;
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Shaders
+ {
+
+ #include "je_base.shader.h"
+
+ bool JSLCompiler::compile(const string& jsl, string* vertex_shader, string* fragment_shader)
+ {
+ // parse shader source, need some optimizations
+ int loc_VERTEX_SHADER = jsl.find("#VERTEX_SHADER");
+ int loc_END_VERTEX_SHADER = jsl.find("#END_VERTEX_SHADER");
+ int loc_FRAGMENT_SHADER = jsl.find("#FRAGMENT_SHADER");
+ int loc_END_FRAGMENT_SHADER = jsl.find("#END_FRAGMENT_SHADER");
+ if (loc_VERTEX_SHADER == string::npos
+ || loc_END_VERTEX_SHADER == string::npos
+ || loc_FRAGMENT_SHADER == string::npos
+ || loc_END_FRAGMENT_SHADER == string::npos
+ )
+ return false;
+ // Load vertex and fragment shader source into buffers.
+ {
+ // Compile JSL vertex program.
+ int start = loc_VERTEX_SHADER + strlen("#VERTEX_SHADER");
+ *vertex_shader = jsl.substr(start, loc_END_VERTEX_SHADER - start);
+ Buffer vbuffer = Buffer(vertex_shader->length() + BASE_VERTEX_SHADER_SIZE);
+ formatVertexShader((char*)&vbuffer, vertex_shader->c_str());
+ vertex_shader->assign((char*)&vbuffer);
+ }
+ {
+ // Compile JSL fragment program.
+ int start = loc_FRAGMENT_SHADER + strlen("#FRAGMENT_SHADER");
+ *fragment_shader = jsl.substr(start, loc_END_FRAGMENT_SHADER - start);
+ Buffer fbuffer = Buffer(fragment_shader->length() + BASE_FRAGMENT_SHADER_SIZE);
+ formatFragmentShader((char*)&fbuffer, fragment_shader->c_str());
+ fragment_shader->assign((char*)&fbuffer);
+ }
+ return true;
+ }
+
+ } // namespace Shaders
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif // (jin_graphics) && (jin_graphics & jin_graphics_shader) \ No newline at end of file
diff --git a/src/libjin/Graphics/shaders/je_jsl_compiler.h b/src/libjin/Graphics/shaders/je_jsl_compiler.h
new file mode 100644
index 0000000..df1e827
--- /dev/null
+++ b/src/libjin/Graphics/shaders/je_jsl_compiler.h
@@ -0,0 +1,45 @@
+#ifndef __JE_JSL_COMPILER_H__
+#define __JE_JSL_COMPILER_H__
+
+#include "../../core/je_configuration.h"
+#if defined(jin_graphics) && (jin_graphics & jin_graphics_shader)
+
+#include <string>
+
+#include "../../common/je_singleton.hpp"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Shaders
+ {
+
+ ///
+ /// Compile JSL into GLSL.
+ ///
+ class JSLCompiler : public Singleton<JSLCompiler>
+ {
+ public:
+ ///
+ /// Compile JSL shader source into GLSL.
+ ///
+ /// @param jsl JSL shader source.
+ /// @param glsl_vertex Output of vertex glsl shader source.
+ /// @param glsl_fragment Output of fragment glsl shader source.
+ /// @return True if compile successful, otherwise return false.
+ ///
+ bool compile(const std::string& jsl, std::string* glsl_vertex, std::string* glsl_fragment);
+
+ private:
+ singleton(JSLCompiler);
+
+ };
+
+ } // namespace Shaders
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif // (jin_graphics) && (jin_graphics & jin_graphics_shader)
+
+#endif // __JE_JSL_COMPILER_H__
diff --git a/src/libjin/Graphics/shaders/je_shader.cpp b/src/libjin/Graphics/shaders/je_shader.cpp
new file mode 100644
index 0000000..c1abbf0
--- /dev/null
+++ b/src/libjin/Graphics/shaders/je_shader.cpp
@@ -0,0 +1,281 @@
+#include "../../core/je_configuration.h"
+#if defined(jin_graphics) && (jin_graphics & jin_graphics_shader)
+
+#include <iostream>
+
+#include "../../filesystem/je_buffer.h"
+#include "../../utils/je_macros.h"
+
+#include "je_jsl_compiler.h"
+#include "je_shader.h"
+
+using namespace std;
+using namespace JinEngine::Filesystem;
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Shaders
+ {
+
+ //
+ // default_texture
+ // base_shader
+ // SHADER_FORMAT_SIZE
+ // formatShader
+ //
+#include "built-in/je_default.shader.h"
+
+//
+// https://stackoverflow.com/questions/27941496/use-sampler-without-passing-through-value
+// The default value of a sampler variable is 0. From the GLSL 3.30 spec,
+// section "4.3.5 Uniforms":
+//
+// The link time initial value is either the value of the variable's
+// initializer, if present, or 0 if no initializer is present.Sampler
+// types cannot have initializers.
+//
+// Since a value of 0 means that it's sampling from texture unit 0, it will
+// work without ever setting the value as long as you bind your textures to
+// unit 0. This is well defined behavior.
+//
+// Since texture unit 0 is also the default until you call glActiveTexture()
+// with a value other than GL_TEXTURE0, it's very common to always use unit
+// 0 as long as shaders do not need more than one texture.Which means that
+// often times, setting the sampler uniforms is redundant for simple
+// applications.
+//
+// I would still prefer to always set the values.If nothing else, it makes
+// it clear to anybody reading your code that you really mean to sample from
+// texture unit 0, and did not just forget to set the value.
+//
+ const int DEFAULT_TEXTURE_UNIT = 0;
+
+ /*static*/ Shader* Shader::CurrentShader = nullptr;
+
+ Shader* Shader::createShader(const string& program)
+ {
+ Shader* shader = nullptr;
+ try
+ {
+ shader = new Shader(program);
+ }
+ catch (...)
+ {
+ return nullptr;
+ }
+ return shader;
+ }
+
+ Shader::Shader(const string& program)
+ : mCurrentTextureUnit(DEFAULT_TEXTURE_UNIT)
+ {
+ if (!compile(program))
+ throw 0;
+ }
+
+ Shader::~Shader()
+ {
+ if (CurrentShader == this)
+ unuse();
+ // delete shader program
+ glDeleteShader(mPID);
+ }
+
+ bool Shader::compile(const string& program)
+ {
+ string vertex_shader, fragment_shader;
+ // Compile JSL shader source into GLSL shader source.
+ JSLCompiler* compiler = JSLCompiler::get();
+ if (!compiler->compile(program, &vertex_shader, &fragment_shader))
+ {
+ return false;
+ }
+#define glsl(SHADER_MODE, SHADER, SRC) \
+do{ \
+const GLchar* src = SRC.c_str(); \
+glShaderSource(SHADER, 1, &src, NULL); \
+glCompileShader(SHADER); \
+GLint success; \
+glGetShaderiv(SHADER, GL_COMPILE_STATUS, &success); \
+if (success == GL_FALSE) \
+ return false; \
+}while(0)
+ // Compile vertex shader.
+ GLuint vid = glCreateShader(GL_VERTEX_SHADER);
+ glsl(GL_VERTEX_SHADER, vid, vertex_shader);
+ // Compile fragment shader.
+ GLuint fid = glCreateShader(GL_FRAGMENT_SHADER);
+ glsl(GL_FRAGMENT_SHADER, fid, fragment_shader);
+#undef glsl
+ // Create OpenGL shader program.
+ mPID = glCreateProgram();
+ glAttachShader(mPID, vid);
+ glAttachShader(mPID, fid);
+ glLinkProgram(mPID);
+ GLint success;
+ glGetProgramiv(mPID, GL_LINK_STATUS, &success);
+ if (success == GL_FALSE)
+ return false;
+ }
+
+ static inline GLint getMaxTextureUnits()
+ {
+ GLint maxTextureUnits = 0;
+ glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
+ return maxTextureUnits;
+ }
+
+ void Shader::use()
+ {
+ glUseProgram(mPID);
+ CurrentShader = this;
+ sendInt(SHADER_MAIN_TEXTURE, DEFAULT_TEXTURE_UNIT);
+ }
+
+ /*static*/ void Shader::unuse()
+ {
+ glUseProgram(0);
+ CurrentShader = nullptr;
+ }
+
+ GLint Shader::claimTextureUnit(const std::string& name)
+ {
+ std::map<std::string, GLint>::iterator unit = mTextureUnits.find(name);
+ if (unit != mTextureUnits.end())
+ return unit->second;
+ static GLint MAX_TEXTURE_UNITS = getMaxTextureUnits();
+ if (++mCurrentTextureUnit >= MAX_TEXTURE_UNITS)
+ return 0;
+ mTextureUnits[name] = mCurrentTextureUnit;
+ return mCurrentTextureUnit;
+ }
+
+#define checkJSL() \
+ if (CurrentShader != this) \
+ return
+
+ void Shader::sendInt(const char* name, int value)
+ {
+ checkJSL();
+ int loc = glGetUniformLocation(mPID, name);
+ glUniform1i(loc, value);
+ }
+
+ void Shader::sendFloat(const char* variable, float number)
+ {
+ checkJSL();
+ int loc = glGetUniformLocation(mPID, variable);
+ glUniform1f(loc, number);
+ }
+
+ //
+ // https://www.douban.com/note/627332677/
+ // struct TextureUnit
+ // {
+ // GLuint targetTexture1D;
+ // GLuint targetTexture2D;
+ // GLuint targetTexture3D;
+ // GLuint targetTextureCube;
+ // ...
+ // };
+ //
+ // TextureUnit mTextureUnits[GL_MAX_TEXTURE_IMAGE_UNITS]
+ // GLuint mCurrentTextureUnit = 0;
+ //
+ void Shader::sendTexture(const char* variable, const Texture* tex)
+ {
+ checkJSL();
+ GLint location = glGetUniformLocation(mPID, variable);
+ if (location == -1)
+ return;
+ GLint unit = claimTextureUnit(variable);
+ if (unit == 0)
+ {
+ // TODO: 쳣󶨵
+ return;
+ }
+ gl.activeTexUnit(unit);
+ glUniform1i(location, unit);
+ gl.bindTexture(tex->getGLTexture());
+ gl.activeTexUnit(0);
+ }
+
+ void Shader::sendCanvas(const char* variable, const Canvas* canvas)
+ {
+ checkJSL();
+ GLint location = glGetUniformLocation(mPID, variable);
+ if (location == -1)
+ return;
+ GLint unit = claimTextureUnit(variable);
+ if (unit == 0)
+ {
+ // TODO: 쳣󶨵
+ return;
+ }
+ glUniform1i(location, unit);
+ glActiveTexture(GL_TEXTURE0 + unit);
+ gl.bindTexture(canvas->getGLTexture());
+
+ glActiveTexture(GL_TEXTURE0);
+ }
+
+ void Shader::sendVec2(const char* name, float x, float y)
+ {
+ checkJSL();
+ int loc = glGetUniformLocation(mPID, name);
+ glUniform2f(loc, x, y);
+ }
+
+ void Shader::sendVec3(const char* name, float x, float y, float z)
+ {
+ checkJSL();
+ int loc = glGetUniformLocation(mPID, name);
+ glUniform3f(loc, x, y, z);
+ }
+
+ void Shader::sendVec4(const char* name, float x, float y, float z, float w)
+ {
+ checkJSL();
+ int loc = glGetUniformLocation(mPID, name);
+ glUniform4f(loc, x, y, z, w);
+ }
+
+ void Shader::sendColor(const char* name, const Color* col)
+ {
+ checkJSL();
+ int loc = glGetUniformLocation(mPID, name);
+ glUniform4f(loc,
+ col->r / 255.f,
+ col->g / 255.f,
+ col->b / 255.f,
+ col->a / 255.f
+ );
+ }
+
+ void Shader::sendMatrix4(const char* name, const Math::Matrix* mat4)
+ {
+ int loc = glGetUniformLocation(mPID, name);
+ glUniformMatrix4fv(loc, 1, GL_FALSE, mat4->getElements());
+ }
+
+ void Shader::setVertexPointer(int n, GLenum type, GLsizei stride, const GLvoid * pointers)
+ {
+ GLint loc = glGetAttribLocation(mPID, SHADER_VERTEX_COORDS);
+ glEnableVertexAttribArray(0);
+ glVertexAttribPointer(loc, n, type, GL_FALSE, stride, pointers);
+ }
+
+ void Shader::setUVPointer(int n, GLenum type, GLsizei stride, const GLvoid * pointers)
+ {
+ GLint loc = glGetAttribLocation(mPID, SHADER_TEXTURE_COORDS);
+ glEnableVertexAttribArray(1);
+ glVertexAttribPointer(loc, n, type, GL_FALSE, stride, pointers);
+ }
+
+ } // namespace Shaders
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif // (jin_graphics) && (jin_graphics & jin_graphics_shader) \ No newline at end of file
diff --git a/src/libjin/Graphics/shaders/je_shader.h b/src/libjin/Graphics/shaders/je_shader.h
new file mode 100644
index 0000000..2009e79
--- /dev/null
+++ b/src/libjin/Graphics/shaders/je_shader.h
@@ -0,0 +1,201 @@
+#ifndef __JE_SHADER_H__
+#define __JE_SHADER_H__
+
+#include "../../core/je_configuration.h"
+#if defined(jin_graphics) && (jin_graphics & jin_graphics_shader)
+
+#include <string>
+#include <map>
+
+#include "GLee/GLee.h"
+
+#include "../je_color.h"
+#include "../je_texture.h"
+#include "../je_canvas.h"
+
+#include "je_base.shader.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Shaders
+ {
+
+ ///
+ /// Built in shader program.
+ ///
+ /// Built in shader program written with custom shading language called JSL (jin shading language). A
+ /// JSL program is compiled into glsl, so most glsl built in functions and structs are available in
+ /// JSL.
+ ///
+ class Shader
+ {
+ public:
+ ///
+ /// Create shader program from source code.
+ ///
+ /// @param source The shader source code.
+ ///
+ static Shader* createShader(const std::string& source);
+
+ ///
+ /// Get current shader.
+ ///
+ /// @return Current used shader program.
+ ///
+ static inline Shader* getCurrentShader() { return CurrentShader; }
+
+ ///
+ /// Unuse current shader.
+ ///
+ static void unuse();
+
+ ///
+ /// Destructor of shader.
+ ///
+ virtual ~Shader();
+
+ ///
+ /// Use specific shader.
+ ///
+ void use();
+
+ ///
+ /// Send float value to shader.
+ ///
+ /// @param name Name of the uniform variable to be assigned.
+ /// @param number Value of uniform variable to be sent.
+ ///
+ void sendFloat(const char* name, float number);
+
+ ///
+ /// Send texture to shader.
+ ///
+ /// @param name Name of the uniform variable to be assigned.
+ /// @param texture Texture to be sent.
+ ///
+ void sendTexture(const char* name, const Texture* texture);
+
+ ///
+ /// Send integer value to shader
+ ///
+ /// @param name Name of the uniform variable to be assigned.
+ /// @param value Value to be sent.
+ ///
+ void sendInt(const char* name, int value);
+
+ ///
+ /// Send 2D vector to shader.
+ ///
+ /// @param name Name of the uniform variable to be assigned.
+ /// @param x X value of the vector to be sent.
+ /// @param y Y value of the vector to be sent.
+ ///
+ void sendVec2(const char* name, float x, float y);
+
+ ///
+ /// Send 3D vector to shader.
+ ///
+ /// @param name Name of the uniform variable to be assigned.
+ /// @param x X value of the vector to be sent.
+ /// @param y Y value of the vector to be sent.
+ /// @param z Z value of the vector to be sent.
+ ///
+ void sendVec3(const char* name, float x, float y, float z);
+
+ ///
+ /// Send 4D vector to shader.
+ ///
+ /// @param name Name of the uniform variable to be assigned.
+ /// @param x X value of the vector to be sent.
+ /// @param y Y value of the vector to be sent.
+ /// @param z Z value of the vector to be sent.
+ /// @param w W value of the vector to be sent.
+ ///
+ void sendVec4(const char* name, float x, float y, float z, float w);
+
+ ///
+ /// Send canvas to shader.
+ ///
+ /// @param name Name of the uniform variable to be assigned.
+ /// @param canvas Canvas to be sent.
+ ///
+ void sendCanvas(const char* name, const Canvas* canvas);
+
+ ///
+ /// Send color to shader.
+ ///
+ /// @param name Name of the uniform variable to be assigned.
+ /// @param color Color to be sent.
+ ///
+ void sendColor(const char* name, const Color* color);
+
+ ///
+ /// Send 4 by 4 matrix to shader.
+ ///
+ /// @param name Name of the uniform variable to be assigned.
+ /// @param mat4 Matrix to be sent.
+ ///
+ void sendMatrix4(const char* name, const Math::Matrix* mat4);
+
+ ///
+ /// Set vertices value.
+ ///
+ /// @param n Number of vertices.
+ /// @param type Data type of each component in the array.
+ /// @param stride Byte offset between consecutive generic vertex attributes.
+ /// @param pointers Pointer to the first component of the first generic vertex attribute in the array.
+ ///
+ void setVertexPointer(int n, GLenum type, GLsizei stride, const GLvoid * pointers);
+
+ ///
+ /// Set texture UV coordinates.
+ ///
+ /// @param n Number of vertices.
+ /// @param type Data type of each component in the array.
+ /// @param stride Byte offset between consecutive generic vertex attributes.
+ /// @param pointers Pointer to the first component of the first generic vertex attribute in the array.
+ ///
+ void setUVPointer(int n, GLenum type, GLsizei stride, const GLvoid * pointers);
+
+ protected:
+ ///
+ /// Reference of current used shader.
+ ///
+ static Shader* CurrentShader;
+
+ ///
+ /// Get texture unit of the uniform texture. If not, assign one.
+ ///
+ /// @param name Name of the texture uniform variable.
+ /// @return Texture unit which texture variable be assigned.
+ ///
+ GLint claimTextureUnit(const std::string& name);
+
+ ///
+ /// Shader constructor.
+ ///
+ Shader(const std::string& program);
+
+ ///
+ /// Compile JSL program into GLSL source.
+ ///
+ /// @param program JSL source code.
+ /// @return Return true if compile successed, otherwise return false.
+ ///
+ bool compile(const std::string& program);
+
+ GLuint mPID;
+ GLint mCurrentTextureUnit;
+ std::map<std::string, GLint> mTextureUnits;
+
+ };
+
+ } // namespace Shaders
+ } // namespace Graphics
+} // namespace JinEngine
+
+#endif // (jin_graphics) && (jin_graphics & jin_graphics_shader)
+
+#endif // __JE_SHADER_H__ \ No newline at end of file
diff --git a/src/libjin/Input/je_event.h b/src/libjin/Input/je_event.h
index 126d0f6..9fe34ff 100644
--- a/src/libjin/Input/je_event.h
+++ b/src/libjin/Input/je_event.h
@@ -1,5 +1,5 @@
-#ifndef __JE_EVENT_H
-#define __JE_EVENT_H
+#ifndef __JE_EVENT_H__
+#define __JE_EVENT_H__
#include "../core/je_configuration.h"
#if defined(jin_input)
@@ -118,4 +118,4 @@ namespace JinEngine
#endif // defined(jin_input)
-#endif // __JE_EVENT_H \ No newline at end of file
+#endif // __JE_EVENT_H__
diff --git a/src/libjin/Input/je_input.h b/src/libjin/Input/je_input.h
index 8c7faf7..2abee0a 100644
--- a/src/libjin/Input/je_input.h
+++ b/src/libjin/Input/je_input.h
@@ -1,5 +1,5 @@
-#ifndef __JE_INPUT_H
-#define __JE_INPUT_H
+#ifndef __JE_INPUT_H__
+#define __JE_INPUT_H__
#include "je_event.h"
#include "je_keyboard.h"
diff --git a/src/libjin/Input/je_joypad.h b/src/libjin/Input/je_joypad.h
index 74173af..fb5dc38 100644
--- a/src/libjin/Input/je_joypad.h
+++ b/src/libjin/Input/je_joypad.h
@@ -1,5 +1,5 @@
-#ifndef __JE_JOYPAD_H
-#define __JE_JOYPAD_H
+#ifndef __JE_JOYPAD_H__
+#define __JE_JOYPAD_H__
#include <SDL2/SDL.h>
@@ -53,4 +53,4 @@ namespace JinEngine
} // namespace Input
} // namespace JinEngine
-#endif // __JE_JOYPAD_H \ No newline at end of file
+#endif // __JE_JOYPAD_H__
diff --git a/src/libjin/Input/je_keyboard.h b/src/libjin/Input/je_keyboard.h
index 61da361..25cfd5d 100644
--- a/src/libjin/Input/je_keyboard.h
+++ b/src/libjin/Input/je_keyboard.h
@@ -1,5 +1,5 @@
-#ifndef __JE_KEYBOARD_H
-#define __JE_KEYBOARD_H
+#ifndef __JE_KEYBOARD_H__
+#define __JE_KEYBOARD_H__
namespace JinEngine
{
@@ -17,4 +17,4 @@ namespace JinEngine
} // namespace Input
} // namespace JinEngine
-#endif // __JE_KEYBOARD_H \ No newline at end of file
+#endif // __JE_KEYBOARD_H__
diff --git a/src/libjin/Input/je_mouse.h b/src/libjin/Input/je_mouse.h
index 29038ec..3c4ad9b 100644
--- a/src/libjin/Input/je_mouse.h
+++ b/src/libjin/Input/je_mouse.h
@@ -1,5 +1,5 @@
-#ifndef __JE_MOUSE_H
-#define __JE_MOUSE_H
+#ifndef __JE_MOUSE_H__
+#define __JE_MOUSE_H__
#include "../core/je_configuration.h"
#if defined(jin_input)
@@ -46,4 +46,4 @@ namespace JinEngine
#endif // defined(jin_input)
-#endif // __JE_MOUSE_H \ No newline at end of file
+#endif // __JE_MOUSE_H__
diff --git a/src/libjin/Graphics/animation/je_animation.cpp b/src/libjin/Math/je_bezier_curve.cpp
index e69de29..e69de29 100644
--- a/src/libjin/Graphics/animation/je_animation.cpp
+++ b/src/libjin/Math/je_bezier_curve.cpp
diff --git a/src/libjin/Math/je_bezier_curve.h b/src/libjin/Math/je_bezier_curve.h
new file mode 100644
index 0000000..6925baf
--- /dev/null
+++ b/src/libjin/Math/je_bezier_curve.h
@@ -0,0 +1,17 @@
+#ifndef __JIN_BEZIER_CURVE_H__
+#define __JIN_BEZIER_CURVE_H__
+
+namespace JinEngine
+{
+ namespace Math
+ {
+
+ class BezierCurve
+ {
+
+ };
+
+ } // namespace Math
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Math/je_constant.h b/src/libjin/Math/je_constant.h
index 5ab126c..45577e7 100644
--- a/src/libjin/Math/je_constant.h
+++ b/src/libjin/Math/je_constant.h
@@ -1,5 +1,5 @@
-#ifndef __JE_MATH_CONSTANT_H
-#define __JE_MATH_CONSTANT_H
+#ifndef __JE_MATH_CONSTANT_H__
+#define __JE_MATH_CONSTANT_H__
#define PI 3.1415926f
diff --git a/src/libjin/Graphics/animation/je_clip.cpp b/src/libjin/Math/je_ellipse.cpp
index e69de29..e69de29 100644
--- a/src/libjin/Graphics/animation/je_clip.cpp
+++ b/src/libjin/Math/je_ellipse.cpp
diff --git a/src/libjin/Graphics/particle/je_particle.cpp b/src/libjin/Math/je_ellipse.h
index e69de29..e69de29 100644
--- a/src/libjin/Graphics/particle/je_particle.cpp
+++ b/src/libjin/Math/je_ellipse.h
diff --git a/src/libjin/Math/je_math.h b/src/libjin/Math/je_math.h
index 1f8e0b3..de57e36 100644
--- a/src/libjin/Math/je_math.h
+++ b/src/libjin/Math/je_math.h
@@ -1,5 +1,5 @@
-#ifndef __JE_UTILS_MATH_H
-#define __JE_UTILS_MATH_H
+#ifndef __JE_UTILS_MATH_H__
+#define __JE_UTILS_MATH_H__
#include "je_constant.h"
#include "je_matrix.h"
@@ -71,7 +71,13 @@ namespace JinEngine
return a + t * (b - a);
}
+ inline float lerp(float a, float b, float f)
+ {
+ f = clamp<float>(f, 0, 1);
+ return a + f * (b - a);
+ }
+
} // namespace Math
} // namespace JinEngine
-#endif // __JE_UTILS_MATH_H \ No newline at end of file
+#endif // __JE_UTILS_MATH_H__
diff --git a/src/libjin/Math/je_matrix.h b/src/libjin/Math/je_matrix.h
index 3592d18..bbc831d 100644
--- a/src/libjin/Math/je_matrix.h
+++ b/src/libjin/Math/je_matrix.h
@@ -1,5 +1,5 @@
-#ifndef __JE_MATRIX_H
-#define __JE_MATRIX_H
+#ifndef __JE_MATRIX_H__
+#define __JE_MATRIX_H__
namespace JinEngine
{
@@ -156,4 +156,4 @@ namespace JinEngine
} // namespace Math
} // namespace JinEngine
-#endif // __JE_MATRIX_H \ No newline at end of file
+#endif // __JE_MATRIX_H__
diff --git a/src/libjin/Math/je_quad.h b/src/libjin/Math/je_quad.h
index 2a66fa1..8a7bd64 100644
--- a/src/libjin/Math/je_quad.h
+++ b/src/libjin/Math/je_quad.h
@@ -1,5 +1,5 @@
-#ifndef __JE_QUAD_H
-#define __JE_QUAD_H
+#ifndef __JE_QUAD_H__
+#define __JE_QUAD_H__
namespace JinEngine
{
@@ -20,4 +20,4 @@ namespace JinEngine
} // namespace Math
} // namespace JinEngine
-#endif // __JE_QUAD_H \ No newline at end of file
+#endif // __JE_QUAD_H__
diff --git a/src/libjin/Math/je_random.cpp b/src/libjin/Math/je_random.cpp
new file mode 100644
index 0000000..983fa36
--- /dev/null
+++ b/src/libjin/Math/je_random.cpp
@@ -0,0 +1,13 @@
+#include "je_random.h"
+
+namespace JinEngine
+{
+ namespace Math
+ {
+
+ RandomGenerator::RandomGenerator()
+ {
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/libjin/Math/je_random.h b/src/libjin/Math/je_random.h
index eb59341..0bcdec7 100644
--- a/src/libjin/Math/je_random.h
+++ b/src/libjin/Math/je_random.h
@@ -1,14 +1,28 @@
-#ifndef __JE_RANDOM_H
-#define __JE_RANDOM_H
+#ifndef __JE_RANDOM_H__
+#define __JE_RANDOM_H__
+
+#include "../common/je_types.h"
namespace JinEngine
{
namespace Math
{
+ ///
+ /// A random number generator.
+ ///
+ class RandomGenerator
+ {
+ public:
+ RandomGenerator();
+ explicit RandomGenerator(uint32 seed);
+
+ uint32 rand(uint32 min, uint32 max);
+ float rand(float min, float max);
+ };
- }
-}
+ } // namespace Math
+} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/Math/je_vector2.hpp b/src/libjin/Math/je_vector2.hpp
index a2b3371..e9599e1 100644
--- a/src/libjin/Math/je_vector2.hpp
+++ b/src/libjin/Math/je_vector2.hpp
@@ -1,5 +1,5 @@
-#ifndef __JE_VECTOR_H
-#define __JE_VECTOR_H
+#ifndef __JE_VECTOR_H__
+#define __JE_VECTOR_H__
namespace JinEngine
{
@@ -25,6 +25,18 @@ namespace JinEngine
data[1] = v.data[1];
}
+ void operator = (const Vector2<T>& v)
+ {
+ data[0] = v.data[0];
+ data[1] = v.data[1];
+ }
+
+ void set(T _x, T _y)
+ {
+ data[0] = _x;
+ data[1] = _y;
+ }
+
T &x = data[0], &y = data[1]; // xy
T &w = data[0], &h = data[1]; // wh
T &colum = data[0], &row = data[1]; // colum row
diff --git a/src/libjin/Math/je_vector3.hpp b/src/libjin/Math/je_vector3.hpp
index 0f9448d..fdab2d0 100644
--- a/src/libjin/Math/je_vector3.hpp
+++ b/src/libjin/Math/je_vector3.hpp
@@ -1,5 +1,5 @@
-#ifndef __JE_VECTOR3_H
-#define __JE_VECTOR3_H
+#ifndef __JE_VECTOR3_H__
+#define __JE_VECTOR3_H__
namespace JinEngine
{
diff --git a/src/libjin/Math/je_vector4.hpp b/src/libjin/Math/je_vector4.hpp
index 20353eb..5cd5b35 100644
--- a/src/libjin/Math/je_vector4.hpp
+++ b/src/libjin/Math/je_vector4.hpp
@@ -1,5 +1,5 @@
-#ifndef __JE_VECTOR4_H
-#define __JE_VECTOR4_H
+#ifndef __JE_VECTOR4_H__
+#define __JE_VECTOR4_H__
namespace JinEngine
{
diff --git a/src/libjin/Net/je_net_manager.h b/src/libjin/Net/je_net_manager.h
index 8f72b73..62aa947 100644
--- a/src/libjin/Net/je_net_manager.h
+++ b/src/libjin/Net/je_net_manager.h
@@ -1,5 +1,5 @@
-#ifndef __JE_NET_H
-#define __JE_NET_H
+#ifndef __JE_NET_H__
+#define __JE_NET_H__
#include "../core/je_configuration.h"
#if defined(jin_net)
@@ -47,4 +47,4 @@ namespace JinEngine
#endif // defined(jin_net)
-#endif // __JE_NET_H \ No newline at end of file
+#endif // __JE_NET_H__
diff --git a/src/libjin/Net/je_socket.h b/src/libjin/Net/je_socket.h
index d496fcb..eb01719 100644
--- a/src/libjin/Net/je_socket.h
+++ b/src/libjin/Net/je_socket.h
@@ -1,9 +1,9 @@
-#ifndef __JE_NET_SOCKET_H
-#define __JE_NET_SOCKET_H
+#ifndef __JE_NET_SOCKET_H__
+#define __JE_NET_SOCKET_H__
#include "../core/je_configuration.h"
#if defined(jin_net)
-#include "../3rdparty/tekcos/tekcos.h"
+#include "tekcos/tekcos.h"
namespace JinEngine
{
@@ -141,4 +141,4 @@ namespace JinEngine
#endif // defined(jin_net)
-#endif // __JE_NET_SOCKET_H \ No newline at end of file
+#endif // __JE_NET_SOCKET_H__ \ No newline at end of file
diff --git a/src/libjin/README.md b/src/libjin/README.md
index e69de29..57d6fe2 100644
--- a/src/libjin/README.md
+++ b/src/libjin/README.md
@@ -0,0 +1,4 @@
+
+
+GUIDE LINE 114
+------------------------------------------------------------------------------------------------------------------ \ No newline at end of file
diff --git a/src/libjin/Time/je_timer.cpp b/src/libjin/Time/je_timer.cpp
index a2f2486..8dc5e86 100644
--- a/src/libjin/Time/je_timer.cpp
+++ b/src/libjin/Time/je_timer.cpp
@@ -9,52 +9,71 @@ namespace JinEngine
{
- Timers::Timers()
- : timers()
+ Timer::Timer()
+ : mHandlers()
{
}
- Timers::~Timers()
+ Timer::~Timer()
{
- for (int i = 0; i < timers.size(); ++i)
- delete timers[i];
+ for (int i = 0; i < mHandlers.size(); ++i)
+ delete mHandlers[i];
}
- void Timers::update(int ms)
+ void Timer::update(float dt)
{
- std::vector<Timer*>::iterator it = timers.begin();
- for (; it != timers.end(); )
- {
- if (!(*it)->process(ms))
- {
- Timer* t = *it;
- timers.erase(it);
- delete t;
- return;
- }
- ++it;
- }
+ // Process handler.
+ std::vector<Handler*>::iterator it = mHandlers.begin();
+ for (; it != mHandlers.end(); ++it)
+ (*it)->process(dt);
+ // Erase canceled handler.
+ for (it = mHandlers.begin(); it != mHandlers.end();)
+ {
+ if ((*it)->canceled)
+ {
+ Handler* h = *it;
+ it = mHandlers.erase(it);
+ delete h;
+ }
+ else
+ ++it;
+ }
}
- void Timers::every(int ms, timer_callback callback, void* p)
+ void Timer::cancel(Handler* handler)
+ {
+ if(handler != nullptr)
+ handler->canceled = true;
+ }
+
+ void Timer::cancelAll()
+ {
+ for (auto h : mHandlers)
+ cancel(h);
+ }
+
+ Timer::Handler* Timer::every(float dt, TimerCallback callback, void* p, FinishCallback finish)
{
- Timer* t = new Timer(Timer::EVERY, ms, 0, callback, p);
- timers.push_back(t);
+ Handler* t = new Handler(Handler::EVERY, dt, 0, callback, p, finish);
+ mHandlers.push_back(t);
+ return t;
}
- void Timers::after(int ms, timer_callback callback, void* p)
+ Timer::Handler* Timer::after(float dt, TimerCallback callback, void* p, FinishCallback finish)
{
- Timer* t = new Timer(Timer::AFTER, ms, 0, callback, p);
- timers.push_back(t);
+ Handler* t = new Handler(Handler::AFTER, dt, 0, callback, p, finish);
+ mHandlers.push_back(t);
+ return t;
}
- void Timers::repeat(int ms, int count, timer_callback callback, void* p)
+ Timer::Handler* Timer::repeat(float dt, int count, TimerCallback callback, void* p, FinishCallback finish)
{
- Timer* t = new Timer(Timer::REPEAT, ms, count, callback, p);
- timers.push_back(t);
+ Handler* t = new Handler(Handler::REPEAT, dt, count, callback, p, finish);
+ mHandlers.push_back(t);
+ return t;
}
- Timers::Timer::Timer(Type t, int d, int c, timer_callback f, void* p)
+ Timer::Handler::Handler(Type t, float d, int c, TimerCallback f, void* p, FinishCallback finishcallback)
: type(t)
, duration(d)
, count(c)
@@ -62,39 +81,42 @@ namespace JinEngine
, countdown(c)
, callback(f)
, paramters(p)
+ , canceled(false)
+ , finishCallback(finishcallback)
{
}
- Timers::Timer::~Timer()
+ Timer::Handler::~Handler()
{
+ if (finishCallback != nullptr)
+ finishCallback(paramters);
}
- bool Timers::Timer::process(int ms)
+ void Timer::Handler::process(float dt)
{
- tickdown -= ms;
+ tickdown -= dt;
if (tickdown <= 0)
{
- tickdown = duration;
- if (callback != nullptr)
+ tickdown += duration;
+ if (!canceled && callback != nullptr)
callback(paramters);
if (type == EVERY)
{
}
else if (type == AFTER)
{
- return false;
+ canceled = true;
}
else if (type == REPEAT)
{
--countdown;
- if (countdown <= 0)
- return false;
+ if (countdown <= 0)
+ canceled = true;
}
}
- return true;
}
} // namespace Time
} // namespace JinEngine
-#endif // defined(jin_time)
+#endif // defined(jin_time) \ No newline at end of file
diff --git a/src/libjin/Time/je_timer.h b/src/libjin/Time/je_timer.h
index b6b4b9e..31cd322 100644
--- a/src/libjin/Time/je_timer.h
+++ b/src/libjin/Time/je_timer.h
@@ -1,9 +1,11 @@
-#ifndef __JE_TIMER_H
-#define __JE_TIMER_H
+#ifndef __JE_TIMER_H__
+#define __JE_TIMER_H__
#include "../core/je_configuration.h"
#if defined(jin_time)
#include <vector>
+#include <functional>
+
#include "SDL2/SDL.h"
namespace JinEngine
@@ -14,68 +16,86 @@ namespace JinEngine
///
///
///
- class Timers
+ class Timer
{
public:
- typedef void(*timer_callback)(void* prameters);
+
+ typedef std::function<void(void*)> TimerCallback;
+
+ typedef std::function<void(void*)> FinishCallback;
///
///
///
- Timers();
+ class Handler
+ {
+ public:
+ friend class Timer;
+ enum Type
+ {
+ EVERY,
+ AFTER,
+ REPEAT,
+ };
+ Handler(Type type, float duration, int count = 0, TimerCallback callback = nullptr, void* paramters = nullptr, FinishCallback finishcallback = nullptr);
+ virtual ~Handler();
+ void process(float dt);
+
+ protected:
+ int count;
+ int countdown;
+ float duration;
+ float tickdown;
+ Type type;
+ TimerCallback callback;
+ FinishCallback finishCallback;
+ void* paramters;
+ bool canceled;
+ };
///
///
///
- ~Timers();
+ Timer();
///
///
///
- void update(int ms);
+ ~Timer();
///
///
///
- void every(int ms, timer_callback callback, void* paramters);
+ void update(float dt);
///
///
///
- void after(int ms, timer_callback callback, void* paramters);
+ Handler* every(float dt, TimerCallback callback, void* paramters, FinishCallback finish);
///
///
///
- void repeat(int ms, int count, timer_callback callback, void* paramters);
+ Handler* after(float dt, TimerCallback callback, void* paramters, FinishCallback finish);
- private:
+ ///
+ ///
+ ///
+ Handler* repeat(float dt, int count, TimerCallback callback, void* paramters, FinishCallback finish);
///
///
///
- class Timer
- {
- public:
- enum Type
- {
- EVERY,
- AFTER,
- REPEAT,
- };
- Timer(Type type, int duration, int count = 0, timer_callback callback = nullptr, void* paramters = nullptr);
- virtual ~Timer();
- bool process(int ms);
- private:
- int duration;
- int count;
- int tickdown;
- int countdown;
- Type type;
- timer_callback callback;
- void* paramters;
- };
- std::vector<Timer*> timers;
+ void cancel(Handler* handler);
+
+ ///
+ ///
+ ///
+ void cancelAll();
+
+ private:
+
+ std::vector<Handler*> mHandlers;
};
@@ -114,4 +134,4 @@ namespace JinEngine
#endif // defined(jin_time)
-#endif // __JE_TIMER_H \ No newline at end of file
+#endif // __JE_TIMER_H__ \ No newline at end of file
diff --git a/src/libjin/Utils/je_log.cpp b/src/libjin/Utils/je_log.cpp
index 2bcb25a..e369e14 100644
--- a/src/libjin/Utils/je_log.cpp
+++ b/src/libjin/Utils/je_log.cpp
@@ -1,2 +1,81 @@
#define LOGHELPER_IMPLEMENT
-#include "je_log.h" \ No newline at end of file
+#include "je_log.h"
+
+#define hasbit(flag, bit) ((flag & bit) == bit)
+
+unsigned int Loghelper::dir = Loghelper::Direction::DIR_CERR;
+unsigned int Loghelper::levels = Loghelper::Level::LV_ALL;
+std::ofstream Loghelper::fs;
+
+void Loghelper::log(Level _level, const char* _fmt, ...)
+{
+ if (!hasbit(levels, _level))
+ return;
+#define FORMAT_MSG_BUFFER_SIZE (204800)
+ const char* levelStr = nullptr;
+ switch (_level)
+ {
+ case LV_ERROR:
+ levelStr = "[Jin Error]: ";
+ break;
+ case LV_WARNING:
+ levelStr = "[Jin Warning]: ";
+ break;
+ case LV_INFO:
+ levelStr = "[Jin Info]: ";
+ break;
+ case LV_DEBUG:
+ levelStr = "[Jin Debug]: ";
+ break;
+ default:
+ levelStr = "[Jin Unknow]: ";
+ break;
+ }
+ char buffer[FORMAT_MSG_BUFFER_SIZE + 1] = { 0 };
+ strcpy(buffer, levelStr);
+ va_list args;
+ va_start(args, _fmt);
+ vsnprintf(buffer + strlen(buffer), FORMAT_MSG_BUFFER_SIZE, _fmt, args);
+ va_end(args);
+ if (hasbit(dir, DIR_CERR))
+ {
+ std::cerr << buffer << std::endl;
+ }
+ if (hasbit(dir, DIR_FILE))
+ {
+ fs << buffer << std::endl;
+ }
+#undef FORMAT_MSG_BUFFER_SIZE
+}
+
+// ض
+void Loghelper::redirect(unsigned int _dir, char* _path)
+{
+ dir = _dir;
+ if (hasbit(dir, DIR_FILE))
+ {
+ try
+ {
+ fs.open(_path, std::ios_base::app);
+ }
+ catch (std::ios_base::failure& e) {
+ dir = DIR_CERR;
+ log(Level::LV_WARNING, "ضlog· %s ʧ", _path);
+ }
+ }
+}
+
+// ɸѡȼ
+void Loghelper::restrict(unsigned int _levels)
+{
+ levels = _levels;
+}
+
+void Loghelper::close()
+{
+ if (!fs.fail())
+ fs.close();
+ fs.clear();
+}
+
+#undef hasbit
diff --git a/src/libjin/Utils/je_log.h b/src/libjin/Utils/je_log.h
index 928a009..f81bbae 100644
--- a/src/libjin/Utils/je_log.h
+++ b/src/libjin/Utils/je_log.h
@@ -1,11 +1,13 @@
-#ifndef __LOG_HELPER_H
-#define __LOG_HELPER_H
+#ifndef __LOG_H__ELPER_H__
+#define __LOG_H__ELPER_H__
#include <string>
#include <iostream>
#include <fstream>
#include <stdarg.h>
+#include "../core/je_configuration.h"
+
class Loghelper
{
public:
@@ -21,7 +23,7 @@ public:
{
LV_NONE = 0, // none
LV_ERROR = 1 << 1, // error
- LV_WARN = 1 << 2, // warn
+ LV_WARNING = 1 << 2, // warn
LV_INFO = 1 << 3, // info
LV_DEBUG = 1 << 4, // debug
LV_ALL = 0xffffffff
@@ -43,89 +45,19 @@ private:
static std::ofstream fs; // ļ
};
-typedef Loghelper::Level Loglevel;
-
-#ifdef LOGHELPER_IMPLEMENT
-
-#define hasbit(flag, bit) ((flag & bit) == bit)
-
-unsigned int Loghelper::dir = Loghelper::Direction::DIR_CERR;
-unsigned int Loghelper::levels = Loghelper::Level::LV_ALL;
-std::ofstream Loghelper::fs;
-
-void Loghelper::log(Level _level, const char* _fmt, ...)
-{
- if (!hasbit(levels, _level))
- return;
-#define FORMAT_MSG_BUFFER_SIZE (204800)
- const char* levelStr = nullptr;
- switch (_level)
- {
- case LV_ERROR:
- levelStr = "[Jin Error]:";
- break;
- case LV_WARN:
- levelStr = "[Jin Warn]:";
- break;
- case LV_INFO:
- levelStr = "[Jin Info]:";
- break;
- case LV_DEBUG:
- levelStr = "[Jin Debug]:";
- break;
- default:
- levelStr = "[Jin Unknown]:";
- break;
- }
- char buffer[FORMAT_MSG_BUFFER_SIZE + 1] = { 0 };
- strcpy(buffer, levelStr);
- va_list args;
- va_start(args, _fmt);
- vsnprintf(buffer + strlen(buffer), FORMAT_MSG_BUFFER_SIZE, _fmt, args);
- va_end(args);
- if (hasbit(dir, DIR_CERR))
- {
- std::cerr << buffer << std::endl;
- }
- if (hasbit(dir, DIR_FILE))
- {
- fs << buffer << std::endl;
- }
-#undef FORMAT_MSG_BUFFER_SIZE
-}
-// ض
-void Loghelper::redirect(unsigned int _dir, char* _path)
-{
- dir = _dir;
- if (hasbit(dir, DIR_FILE))
- {
- try
- {
- fs.open(_path, std::ios_base::app);
- }
- catch (std::ios_base::failure& e) {
- dir = DIR_CERR;
- log(Level::LV_WARN, "ضlog· %s ʧ", _path);
- }
- }
-}
-
-// ɸѡȼ
-void Loghelper::restrict(unsigned int _levels)
-{
- levels = _levels;
-}
-
-void Loghelper::close()
-{
- if (!fs.fail())
- fs.close();
- fs.clear();
-}
-
-#undef hasbit
-
-#endif
+typedef Loghelper::Level Loglevel;
-#endif \ No newline at end of file
+#if defined(jin_debug)
+ #define jin_log_error(f, ...) Loghelper::log(Loghelper::LV_ERROR, f, __VA_ARGS__)
+ #define jin_log_info(f, ...) Loghelper::log(Loghelper::LV_INFO, f, __VA_ARGS__)
+ #define jin_log_warning(f, ...) Loghelper::log(Loghelper::LV_WARNING, f, __VA_ARGS__)
+ #define jin_log_debug(f, ...) Loghelper::log(Loghelper::LV_DEBUG, f, __VA_ARGS__)
+#else
+ #define jin_log_error(f, ...)
+ #define jin_log_info(f, ...)
+ #define jin_log_warning(f, ...)
+ #define jin_log_debug(f, ...)
+#endif
+
+#endif // __LOG_H__ELPER_H__ \ No newline at end of file
diff --git a/src/libjin/Utils/je_macros.h b/src/libjin/Utils/je_macros.h
index 475a482..6e4e7a9 100644
--- a/src/libjin/Utils/je_macros.h
+++ b/src/libjin/Utils/je_macros.h
@@ -1,5 +1,5 @@
-#ifndef __JE_MACROS_H
-#define __JE_MACROS_H
+#ifndef __JE_MACROS_H__
+#define __JE_MACROS_H__
#include <cstring>
//#define implement // ʵֽӿ
diff --git a/src/libjin/Utils/je_utils.h b/src/libjin/Utils/je_utils.h
index 21c507d..a77c126 100644
--- a/src/libjin/Utils/je_utils.h
+++ b/src/libjin/Utils/je_utils.h
@@ -1,5 +1,5 @@
-#ifndef __JE_UTILS_H
-#define __JE_UTILS_H
+#ifndef __JE_UTILS_H__
+#define __JE_UTILS_H__
#include "je_macros.h"
#include "je_endian.h"
diff --git a/src/libjin/ai/je_ai.h b/src/libjin/ai/je_ai.h
new file mode 100644
index 0000000..57debce
--- /dev/null
+++ b/src/libjin/ai/je_ai.h
@@ -0,0 +1,10 @@
+#ifndef __JE_AI_H__
+#define __JE_AI_H__
+
+// Decision Making
+#include "je_state_machine.h"
+#include "je_behavior_tree.h"
+
+//
+
+#endif \ No newline at end of file
diff --git a/src/libjin/ai/je_behavior_tree.h b/src/libjin/ai/je_behavior_tree.h
index 6e276b6..173df80 100644
--- a/src/libjin/ai/je_behavior_tree.h
+++ b/src/libjin/ai/je_behavior_tree.h
@@ -1,24 +1,59 @@
-#ifndef __JE_BEHAVIOR_TREE_H
-#define __JE_BEHAVIOR_TREE_H
+#ifndef __JE_BEHAVIOR_TREE_H__
+#define __JE_BEHAVIOR_TREE_H__
#include "../core/je_configuration.h"
#if defined(jin_ai)
+#include <functional>
+
namespace JinEngine
{
namespace AI
{
-
+
///
///
///
class BehaviorTree
{
+ public:
+ BehaviorTree(void* userData) : mUserData(userData){}
+
+ class Node
+ {
+ public:
+ enum Type
+ {
+
+ };
+
+ enum Status
+ {
+ Running,
+ Success,
+ Failure
+ };
+
+ Status status;
+ };
+
+ typedef std::function<Node::Status(void*)> UpdateCallback;
+
+ Node makeNode(Node::Type type, UpdateCallback callback);
+
+ private:
+
+ ///
+ ///
+ ///
+ void* const mUserData;
};
- }
-}
+ typedef BehaviorTree::Node::Status BahaviorNodeStatus;
+
+ } // namespace AI
+} // namespace JinEngine
#endif // jin_ai
diff --git a/src/libjin/ai/je_state_machine.cpp b/src/libjin/ai/je_state_machine.cpp
index e69de29..6208265 100644
--- a/src/libjin/ai/je_state_machine.cpp
+++ b/src/libjin/ai/je_state_machine.cpp
@@ -0,0 +1,445 @@
+#include "je_state_machine.h"
+
+#include "../utils/je_log.h"
+
+using namespace std;
+
+namespace JinEngine
+{
+ namespace AI
+ {
+
+ StateMachine::StateMachine(Mode mode, void* userdata)
+ : mCurrentState(0)
+ , mUserData(userdata)
+ , mMode(mode)
+ {
+ addState(0);
+ }
+
+ StateMachine::~StateMachine()
+ {
+ }
+
+ void StateMachine::invokeCallback(int from, int to)
+ {
+ if (mExitCallback != nullptr)
+ mExitCallback(from, mUserData);
+ if (mTraslateCallback != nullptr)
+ mTraslateCallback(from, to, mUserData);
+ if (mEnterCallback != nullptr)
+ mEnterCallback(to, mUserData);
+ map<int, StateChangeCallback>::iterator it = mOnExitState.find(from);
+ if (it != mOnExitState.end())
+ it->second(mUserData);
+ map<pair<int, int>, StateTranslateCallback>::iterator transItr
+ = mOnStateTranslate.find(pair<int, int>(from, to));
+ if (transItr != mOnStateTranslate.end())
+ transItr->second(mUserData);
+ it = mOnEnterState.find(to);
+ if (it != mOnEnterState.end())
+ it->second(mUserData);
+ }
+
+ void StateMachine::stepwiseProcess()
+ {
+ map<int, State>::iterator it = mStates.find(mCurrentState);
+ if (it == mStates.end())
+ {
+ jin_log_error("The state [%d] is not exist.", mCurrentState);
+ return;
+ }
+ State& state = it->second;
+ for (int i = 0; i < state.transitions.size(); ++i)
+ {
+ Conditions conditions = state.transitions[i].conditions;
+ bool isActive = true;
+ for (int j = 0; j < conditions.conditions.size(); ++j)
+ {
+ isActive &= processCondition(conditions.conditions[j]);
+ if (!isActive)
+ break;
+ }
+ if (isActive)
+ {
+ // Traslate
+ mCurrentState = state.transitions[i].state;
+ invokeCallback(state.name, mCurrentState);
+ break;
+ }
+ }
+ // Call update
+ if (mUpdateCallback != nullptr)
+ mUpdateCallback(mCurrentState, mUserData);
+ map<int, StateUpdateCallback>::iterator uit = mOnUpdateState.find(mCurrentState);
+ if (uit != mOnUpdateState.end())
+ uit->second(mUserData);
+ }
+
+ void StateMachine::iterativeProcess()
+ {
+ map<int, State>::iterator it = mStates.find(mCurrentState);
+ if (it == mStates.end())
+ {
+ jin_log_error("The state [%d] is not exist.", mCurrentState);
+ return;
+ }
+ State& state = it->second;
+ bool isActive = true;
+ for (int i = 0; i < state.transitions.size(); ++i)
+ {
+ Conditions conditions = state.transitions[i].conditions;
+ isActive = true;
+ for (int j = 0; j < conditions.conditions.size(); ++j)
+ {
+ isActive &= processCondition(conditions.conditions[j]);
+ if (!isActive)
+ break;
+ }
+ if (isActive)
+ {
+ // Traslate
+ mCurrentState = state.transitions[i].state;
+ invokeCallback(state.name, mCurrentState);
+ break;
+ }
+ }
+ // Call update
+ if (mUpdateCallback != nullptr)
+ mUpdateCallback(mCurrentState, mUserData);
+ map<int, StateUpdateCallback>::iterator uit = mOnUpdateState.find(mCurrentState);
+ if (uit != mOnUpdateState.end())
+ uit->second(mUserData);
+ // Recursive.
+ if(isActive)
+ return iterativeProcess();
+ }
+
+ void StateMachine::setMode(Mode mode)
+ {
+ mMode = mode;
+ }
+
+ void StateMachine::update()
+ {
+ switch (mMode)
+ {
+ case Mode::Iterative: iterativeProcess(); break;
+ case Mode::Stepwise: stepwiseProcess(); break;
+ }
+ }
+
+ bool StateMachine::processCondition(const Condition& condition)
+ {
+ map<int, Parameter>::iterator it = mParameters.find(condition.parameter);
+ if (it == mParameters.end())
+ {
+ jin_log_error("The parameter <%d> is not exist", condition.parameter);
+ return false;
+ }
+ Parameter& p = it->second;
+ switch (p.type)
+ {
+ case ParameterType::Int:
+ {
+ int value = p.value._int;
+ int cvalue = condition.value._int;
+ bool is = false;
+ is |= ((condition.expression & ParameterExpression::INT_GREATER) ? value > cvalue : false);
+ is |= ((condition.expression & ParameterExpression::INT_EQUAL) ? value == cvalue : false);
+ is |= ((condition.expression & ParameterExpression::INT_LESS) ? value < cvalue : false);
+ return is;
+ }
+ case ParameterType::Float:
+ {
+ float value = p.value._float;
+ float cvalue = condition.value._float;
+ bool is = false;
+ is |= ((condition.expression & ParameterExpression::FLOAT_GREATER) ? value > cvalue : false);
+ is |= ((condition.expression & ParameterExpression::FLOAT_EQUAL) ? value == cvalue : false);
+ is |= ((condition.expression & ParameterExpression::FLOAT_LESS) ? value < cvalue : false);
+ return is;
+ }
+ case ParameterType::Bool:
+ {
+ bool value = p.value._bool;
+ bool cvalue = condition.value._bool;
+ bool is = false;
+ is |= ((condition.expression & ParameterExpression::BOOL_IS) ? value == cvalue : false);
+ is |= ((condition.expression & ParameterExpression::BOOL_NOT) ? value != cvalue : false);
+ return is;
+ }
+ case ParameterType::Trigger:
+ {
+ bool is = p.value._trigger;
+ // Close trigger.
+ p.value._trigger = false;
+ return is;
+ }
+ }
+ return false;
+ }
+
+ int StateMachine::getCurrentState()
+ {
+ return mCurrentState;
+ }
+
+ void StateMachine::addParameteri(int name)
+ {
+ if (mParameters.find(name) != mParameters.end())
+ {
+ jin_log_error("The parameter <%d> is already exist.", name);
+ return;
+ }
+ Parameter p;
+ p.type = ParameterType::Int;
+ p.value._int = 0;
+ mParameters.insert(pair<int, Parameter>(name, p));
+ }
+
+ void StateMachine::addParameterf(int name)
+ {
+ if (mParameters.find(name) != mParameters.end())
+ {
+ jin_log_error("The parameter <%d> is already exist.", name);
+ return;
+ }
+ Parameter p;
+ p.type = ParameterType::Float;
+ p.value._float = 0.0f;
+ mParameters.insert(pair<int, Parameter>(name, p));
+ }
+
+ void StateMachine::addParameterb(int name)
+ {
+ if (mParameters.find(name) != mParameters.end())
+ {
+ jin_log_error("The parameter <%d> is already exist.", name);
+ return;
+ }
+ Parameter p;
+ p.type = ParameterType::Bool;
+ p.value._bool = false;
+ mParameters.insert(pair<int, Parameter>(name, p));
+ }
+
+ void StateMachine::addParametert(int name)
+ {
+ if (mParameters.find(name) != mParameters.end())
+ {
+ jin_log_error("The parameter <%d> is already exist.", name);
+ return;
+ }
+ Parameter p;
+ p.type = ParameterType::Trigger;
+ p.value._trigger = false;
+ mParameters.insert(pair<int, Parameter>(name, p));
+ }
+
+ void StateMachine::addState(int name)
+ {
+ if (mStates.find(name) != mStates.end())
+ {
+ jin_log_error("The state [%d] is already exist.", name);
+ return;
+ }
+ State state;
+ state.name = name;
+ mStates.insert(pair<int, State>(name, state));
+ }
+
+ const char* StateMachine::parameterTypeString(ParameterType type)
+ {
+ switch (type)
+ {
+ case ParameterType::Int: return "int";
+ case ParameterType::Float: return "float";
+ case ParameterType::Bool: return "bool";
+ case ParameterType::Trigger: return "trigger";
+ }
+ }
+
+ void StateMachine::addTransition(int from, int to, const Conditions& conditions)
+ {
+ map<int, State>::iterator it;
+ it = mStates.find(from);
+ if (it == mStates.end())
+ {
+ jin_log_error("The state [%d] is not exist.", from);
+ return;
+ }
+ State& fromState = it->second;
+ it = mStates.find(to);
+ if (it == mStates.end())
+ {
+ jin_log_error("The state [%d] is not exist.", to);
+ return;
+ }
+ // Check condtion correctness.
+ for (int i = 0; i < conditions.conditions.size(); ++i)
+ {
+ const Condition& condition = conditions.conditions[i];
+ map<int, Parameter>::iterator itp;
+ itp = mParameters.find(condition.parameter);
+ if (itp == mParameters.end())
+ {
+ jin_log_error("The parameter <%d> is not exist.", condition.parameter);
+ return;
+ }
+ Parameter& p = itp->second;
+ if (p.type != condition.type)
+ {
+ jin_log_error("The type of parameter <%d> is a %s, but the transition gives a %s value."
+ , condition.parameter, parameterTypeString(p.type), parameterTypeString(condition.type));
+ return;
+ }
+ }
+ // Add transition.
+ Transition transition;
+ transition.conditions = conditions;
+ transition.state = to;
+ fromState.transitions.push_back(transition);
+ }
+
+ void StateMachine::setParameteri(int name, int value)
+ {
+ map<int, Parameter>::iterator it = mParameters.find(name);
+ if (it == mParameters.end())
+ {
+ jin_log_error("The state [%d] is not exist.", name);
+ return;
+ }
+ Parameter& p = it->second;
+ if (p.type != ParameterType::Int)
+ {
+ jin_log_error("The type of parameter <%d> is %s, but try to assign a int value to it", name, parameterTypeString(p.type));
+ return;
+ }
+ p.value._int = value;
+ }
+
+ void StateMachine::setParameterf(int name, float value)
+ {
+ map<int, Parameter>::iterator it = mParameters.find(name);
+ if (it == mParameters.end())
+ {
+ jin_log_error("The state [%d] is not exist.", name);
+ return;
+ }
+ Parameter& p = it->second;
+ if (p.type != ParameterType::Float)
+ {
+ jin_log_error("The type of parameter <%d> is %s, but try to assign a float value to it", name, parameterTypeString(p.type));
+ return;
+ }
+ p.value._float = value;
+ }
+
+ void StateMachine::setParameterb(int name, bool value)
+ {
+ map<int, Parameter>::iterator it = mParameters.find(name);
+ if (it == mParameters.end())
+ {
+ jin_log_error("The state %s is not exist.", name);
+ return;
+ }
+ Parameter& p = it->second;
+ if (p.type != ParameterType::Bool)
+ {
+ jin_log_error("The type of parameter <%d> is %s, but try to assign a bool value to it", name, parameterTypeString(p.type));
+ return;
+ }
+ p.value._bool = value;
+ }
+
+ void StateMachine::setParametert(int name)
+ {
+ map<int, Parameter>::iterator it = mParameters.find(name);
+ if (it == mParameters.end())
+ {
+ jin_log_error("The state %s is not exist.", name);
+ return;
+ }
+ Parameter& p = it->second;
+ if (p.type != ParameterType::Trigger)
+ {
+ jin_log_error("The type of parameter <%d> is %s, but try to assign a trigger value to it", name, parameterTypeString(p.type));
+ return;
+ }
+ p.value._trigger = true;
+ }
+
+ void StateMachine::forceToState(int name)
+ {
+ if (mStates.find(name) == mStates.end())
+ {
+ jin_log_error("The state [%d] is not exist.", name);
+ return;
+ }
+ mCurrentState = name;
+ }
+
+ void StateMachine::addEnterListener(int state, const StateChangeCallback& callback)
+ {
+ if (mOnEnterState.find(state) != mOnEnterState.end())
+ {
+ jin_log_error("The enter listener of [%d] is already exist.", state);
+ return;
+ }
+ mOnEnterState.insert(pair<int, StateChangeCallback>(state, callback));
+ }
+
+ void StateMachine::addUpdateListener(int state, const StateUpdateCallback& callback)
+ {
+ if (mOnUpdateState.find(state) != mOnUpdateState.end())
+ {
+ jin_log_error("The update listener of [%d] is already exist.", state);
+ return;
+ }
+ mOnUpdateState.insert(pair<int, StateUpdateCallback>(state, callback));
+ }
+
+ void StateMachine::addExitListener(int state, const StateChangeCallback& callback)
+ {
+ if (mOnExitState.find(state) != mOnExitState.end())
+ {
+ jin_log_error("The exit listener of [%d] is already exist.", state);
+ return;
+ }
+ mOnExitState.insert(pair<int, StateChangeCallback>(state, callback));
+ }
+
+ void StateMachine::addTranslateListener(int from, int to, const StateChangeCallback& callback)
+ {
+ if (mOnStateTranslate.find(pair<int, int>(from, to)) != mOnStateTranslate.end())
+ {
+ jin_log_error("The traslate listener of [%d] to [%d] is already exist.", from, to);
+ return;
+ }
+ pair<int, int> key(from, to);
+ mOnStateTranslate.insert(pair<pair<int, int>, StateTranslateCallback>(key, callback));
+ }
+
+ void StateMachine::setUpdateListener(const SingleStateCallback& callback)
+ {
+ mUpdateCallback = callback;
+ }
+
+ void StateMachine::setEnterListener(const SingleStateCallback& callback)
+ {
+ mEnterCallback = callback;
+ }
+
+ void StateMachine::setExitListener(const SingleStateCallback& callback)
+ {
+ mExitCallback = callback;
+ }
+
+ void StateMachine::setTranslateListener(const DoubleStateCallback& callback)
+ {
+ mTraslateCallback = callback;
+ }
+
+ } // namespace AI
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/libjin/ai/je_state_machine.h b/src/libjin/ai/je_state_machine.h
index 7869925..c928989 100644
--- a/src/libjin/ai/je_state_machine.h
+++ b/src/libjin/ai/je_state_machine.h
@@ -1,24 +1,413 @@
-#ifndef __JE_STATEMACHINE_TREE_H
-#define __JE_STATEMACHINE_TREE_H
+#ifndef __JE_STATE_MACHINE_H__
+#define __JE_STATE_MACHINE_H__
#include "../core/je_configuration.h"
#if defined(jin_ai)
+#include <map>
+#include <vector>
+#include <functional>
+
+#include "../common/je_temporary.h"
+#include "../common/je_types.h"
+#include "../common/je_object.h"
+
namespace JinEngine
{
namespace AI
{
///
+ /// A single layer statemachine.
///
- ///
- class StateMachine
+ class StateMachine : public Object
{
+ public:
+ ///
+ ///
+ ///
+ enum ParameterExpression
+ {
+ INT_GREATER = 0x02,
+ INT_LESS = 0x04,
+ INT_EQUAL = 0x08,
+
+ FLOAT_GREATER = 0x10,
+ FLOAT_LESS = 0x20,
+ FLOAT_EQUAL = 0x40,
+
+ BOOL_IS = 0x80,
+ BOOL_NOT = 0x100,
+ };
+
+ private:
+ ///
+ ///
+ ///
+ enum ParameterType
+ {
+ Int, ///< A integer value.
+ Float, ///< A float value.
+ Bool, ///< A bool value.
+ Trigger ///< A trigger will be reset to false after activated.
+ };
+
+ ///
+ ///
+ ///
+ union ParameterValue
+ {
+ int _int; ///< 0 by default.
+ float _float; ///< 0 by default.
+ bool _bool; ///< false by default.
+ bool _trigger; ///< false by default.
+ };
+
+ ///
+ /// Traslation's condition.
+ ///
+ struct Condition
+ {
+ int parameter;
+ ParameterExpression expression;
+ ParameterType type;
+ ParameterValue value;
+ };
+
+ public:
+ ///
+ ///
+ ///
+ enum Mode
+ {
+ Iterative, ///< Process until reach condition failed.(May cause endless loop)
+ Stepwise ///< Process one state each update.
+ };
+
+ struct Conditions : Temporary
+ {
+ Conditions()
+ {
+ }
+
+ Conditions(const Conditions& condition)
+ {
+ conditions = condition.conditions;
+ }
+
+ void operator = (const Conditions& condition)
+ {
+ conditions = condition.conditions;
+ }
+
+ inline Conditions& andi(int parameter, ParameterExpression expression, int value)
+ {
+ Condition condition;
+ condition.expression = expression;
+ condition.parameter = parameter;
+ condition.value._int = value;
+ condition.type = ParameterType::Int;
+ conditions.push_back(condition);
+ return *this;
+ }
+
+ inline Conditions& andf(int parameter, ParameterExpression expression , float value)
+ {
+ Condition condition;
+ condition.expression = expression;
+ condition.parameter = parameter;
+ condition.value._int = value;
+ condition.type = ParameterType::Float;
+ conditions.push_back(condition);
+ return *this;
+ }
+
+ inline Conditions& andb(int parameter, ParameterExpression expression, bool value)
+ {
+ Condition condition;
+ condition.expression = expression;
+ condition.parameter = parameter;
+ condition.value._int = value;
+ condition.type = ParameterType::Bool;
+ conditions.push_back(condition);
+ return *this;
+ }
+
+ inline Conditions& andt(int parameter)
+ {
+ Condition condition;
+ condition.parameter = parameter;
+ condition.type = ParameterType::Trigger;
+ conditions.push_back(condition);
+ return *this;
+ }
+
+ private:
+ friend class StateMachine;
+ std::vector<Condition> conditions;
+ };
+
+ ///
+ ///
+ ///
+ typedef std::function<void(void*)> StateChangeCallback;
+
+ ///
+ ///
+ ///
+ typedef std::function<void(void*)> StateUpdateCallback;
+
+ ///
+ ///
+ ///
+ typedef std::function<void(void*)> StateTranslateCallback;
+
+ ///
+ ///
+ ///
+ typedef std::function<void(int, void*)> SingleStateCallback;
+
+ ///
+ ///
+ ///
+ typedef std::function<void(int, const int, void*)> DoubleStateCallback;
+
+ ///
+ /// State machine constructor.
+ ///
+ StateMachine(Mode mode = Mode::Stepwise, void* userdata = nullptr);
+
+ ///
+ /// State machine destructor.
+ ///
+ ~StateMachine();
+
+ ///
+ ///
+ ///
+ void setMode(Mode mode);
+
+ ///
+ /// Process current state..
+ ///
+ void update();
+
+ ///
+ /// Get current state name.
+ ///
+ int getCurrentState();
+
+ ///
+ /// Add a integer parameter.
+ ///
+ void addParameteri(int name);
+
+ ///
+ ///
+ ///
+ void addParameterf(int name);
+
+ ///
+ ///
+ ///
+ void addParameterb(int name);
+
+ ///
+ ///
+ ///
+ void addParametert(int name);
+
+ ///
+ /// Add a state.
+ ///
+ void addState(int name);
+
+ ///
+ ///
+ ///
+ void addTransition(int from, int to, const Conditions& conditions);
+
+ ///
+ /// Set parameter value.
+ ///
+ void setParameteri(int name, int value);
+
+ ///
+ /// Set parameter value.
+ ///
+ void setParameterf(int name, float value);
+
+ ///
+ /// Set parameter value.
+ ///
+ void setParameterb(int name, bool value);
+
+ ///
+ /// Set parameter value.
+ ///
+ void setParametert(int name);
+
+ ///
+ /// Force change to state.
+ ///
+ void forceToState(int name);
+
+ ///
+ ///
+ ///
+ void addEnterListener(int state, const StateChangeCallback& callback);
+
+ ///
+ /// Call state update function.
+ ///
+ void addUpdateListener(int state, const StateUpdateCallback& callback);
+
+ ///
+ ///
+ ///
+ void addExitListener(int state, const StateChangeCallback& callback);
+
+ ///
+ ///
+ ///
+ void addTranslateListener(int from, int to, const StateChangeCallback& callback);
+
+ ///
+ ///
+ ///
+ void setEnterListener(const SingleStateCallback& callback);
+
+ ///
+ ///
+ ///
+ void setUpdateListener(const SingleStateCallback& callback);
+
+ ///
+ ///
+ ///
+ void setExitListener(const SingleStateCallback& callback);
+
+ ///
+ ///
+ ///
+ void setTranslateListener(const DoubleStateCallback& callback);
+
+ private:
+
+ ///
+ ///
+ ///
+ struct Parameter
+ {
+ ParameterType type;
+ ParameterValue value;
+ };
+
+ ///
+ /// Translate to another state.
+ ///
+ struct Transition
+ {
+ Conditions conditions; ///< Condition to active transition.
+ int state; ///< State to translate to.
+ };
+
+ ///
+ /// A single state.
+ ///
+ struct State
+ {
+ int name; ///< Name of state.
+ std::vector<Transition> transitions; ///< All transitions this state have.
+ };
+
+ const char* parameterTypeString(ParameterType type);
+
+ ///
+ /// Check if condition is full filled.
+ ///
+ /// @param condition Condition to check.
+ ///
+ bool processCondition(const Condition& condition);
+
+ ///
+ ///
+ ///
+ void stepwiseProcess();
+
+ ///
+ ///
+ ///
+ void iterativeProcess();
+
+ ///
+ ///
+ ///
+ void invokeCallback(int from, int to);
+
+ ///
+ /// All state this state machine keeps.
+ ///
+ std::map<int, State> mStates;
+
+ ///
+ ///
+ ///
+ std::map<int, StateChangeCallback> mOnEnterState;
+
+ ///
+ ///
+ ///
+ std::map<int, StateUpdateCallback> mOnUpdateState;
+
+ ///
+ ///
+ ///
+ std::map<int, StateChangeCallback> mOnExitState;
+
+ ///
+ /// From first to second.
+ ///
+ std::map<std::pair<int, int>, StateTranslateCallback> mOnStateTranslate;
+
+ ///
+ ///
+ ///
+ SingleStateCallback mEnterCallback;
+
+ ///
+ ///
+ ///
+ SingleStateCallback mUpdateCallback;
+
+ ///
+ ///
+ ///
+ SingleStateCallback mExitCallback;
+
+ ///
+ ///
+ ///
+ DoubleStateCallback mTraslateCallback;
+
+ ///
+ /// Current state.
+ ///
+ int mCurrentState;
+
+ ///
+ /// All parameters.
+ ///
+ std::map<int, Parameter> mParameters;
+
+ Mode mMode;
+
+ void* const mUserData;
};
- }
-}
+ } // namespace Graphics
+} // namespace JinEngine
#endif // jin_ai
diff --git a/src/libjin/core/je_configuration.h b/src/libjin/core/je_configuration.h
index 34c3a74..80e2748 100644
--- a/src/libjin/core/je_configuration.h
+++ b/src/libjin/core/je_configuration.h
@@ -1,8 +1,11 @@
-#ifndef __JE_COMMON_MODULES_H
-#define __JE_COMMON_MODULES_H
+#ifndef __JE_COMMON_MODULES_H__
+#define __JE_COMMON_MODULES_H__
#define jin_undefined 0x00
+///
+/// Debug output
+///
#define jin_debug
#define jin_os_windows 0x01
@@ -50,4 +53,6 @@
#define jin_ai
-#endif // __JE_COMMON_MODULES_H \ No newline at end of file
+#define JIN_EXPORT __declspec(dllexport)
+
+#endif // __JE_COMMON_MODULES_H__ \ No newline at end of file
diff --git a/src/libjin/core/je_version.h b/src/libjin/core/je_version.h
index 77302c6..b5fe379 100644
--- a/src/libjin/core/je_version.h
+++ b/src/libjin/core/je_version.h
@@ -1,5 +1,5 @@
-#ifndef __JE_CORE_VERSION_H
-#define __JE_CORE_VERSION_H
+#ifndef __JE_CORE_VERSION_H__
+#define __JE_CORE_VERSION_H__
namespace JinEngine
{
@@ -49,4 +49,4 @@ namespace JinEngine
} // namespace Core
} // namespace JinEngine
-#endif // __JE_CORE_VERSION_H \ No newline at end of file
+#endif // __JE_CORE_VERSION_H__
diff --git a/src/libjin/jin.h b/src/libjin/jin.h
index b47a56d..8164511 100644
--- a/src/libjin/jin.h
+++ b/src/libjin/jin.h
@@ -1,5 +1,5 @@
-#ifndef __JE_H
-#define __JE_H
+#ifndef __JE_H__
+#define __JE_H__
#include "core/je_configuration.h"
@@ -7,14 +7,15 @@
#if jin_audio == jin_audio_sdl
#include "audio/sdl/je_sdl_audio.h"
#endif
-#include "game/je_game.h"
+#include "game/je_application.h"
#include "filesystem/je_asset_database.h"
#include "filesystem/je_buffer.h"
#include "input/je_input.h"
#include "net/je_net_manager.h"
#include "graphics/je_graphics.h"
#include "time/je_timer.h"
-#include "multithread/je_thread.h"
+#include "threads/je_thread.h"
#include "common/je_common.h"
+#include "ai/je_ai.h"
-#endif // __JE_H \ No newline at end of file
+#endif // __JE_H__ \ No newline at end of file
diff --git a/src/libjin/multithread/je_thread.cpp b/src/libjin/threads/je_thread.cpp
index 0c528bf..0c34508 100644
--- a/src/libjin/multithread/je_thread.cpp
+++ b/src/libjin/threads/je_thread.cpp
@@ -5,7 +5,7 @@
namespace JinEngine
{
- namespace MultiThread
+ namespace Threads
{
class Mutex
@@ -295,7 +295,7 @@ namespace JinEngine
unlock();
}
- } // namespace MultiThread
+ } // namespace Threads
} // namespace JinEngine
#endif // defined(jin_thread) \ No newline at end of file
diff --git a/src/libjin/multithread/je_thread.h b/src/libjin/threads/je_thread.h
index 353690c..77f147d 100644
--- a/src/libjin/multithread/je_thread.h
+++ b/src/libjin/threads/je_thread.h
@@ -1,5 +1,5 @@
-#ifndef __JE_THREAD_H
-#define __JE_THREAD_H
+#ifndef __JE_THREAD_H__
+#define __JE_THREAD_H__
#include "../core/je_configuration.h"
#if defined(jin_thread)
@@ -15,7 +15,7 @@
namespace JinEngine
{
- namespace MultiThread
+ namespace Threads
{
/**
* ӢӢMutual exclusionд Mutexһڶ̱߳Уֹ߳ͬʱͬһԴ
@@ -159,9 +159,9 @@ namespace JinEngine
};
- } // namespace MultiThread
+ } // namespace Threads
} // namespace JinEngine
#endif // defined(jin_thread)
-#endif // __JE_THREAD_H \ No newline at end of file
+#endif // __JE_THREAD_H__ \ No newline at end of file
diff --git a/src/lua/common/Proxy.h b/src/lua/common/Proxy.h
deleted file mode 100644
index 5ebb5b2..0000000
--- a/src/lua/common/Proxy.h
+++ /dev/null
@@ -1,67 +0,0 @@
-#ifndef __JIN_COMMON_PROXY_H
-#define __JIN_COMMON_PROXY_H
-
-#include "Reference.hpp"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- class Proxy
- {
- public:
- void bind(RefBase* ref)
- {
- if (ref == nullptr)
- return;
- reference = ref;
- }
-
- void release()
- {
- if (reference != nullptr)
- {
- reference->release();
- reference = nullptr;
- }
- }
-
- void retain()
- {
- if (reference != nullptr)
- reference->retain();
- }
-
- void setUserdata(void* data)
- {
- if (reference != nullptr)
- reference->setUserdata(data);
- }
-
- template<class T>
- Ref<T>& getRef()
- {
- return *(Ref<T>*) reference;
- }
-
- template<class T>
- T* getObject()
- {
- Ref<T>& ref = getRef<T>();
- return ref.getObject();
- }
-
- const char* getObjectType()
- {
- return reference->type;
- }
-
- RefBase* reference;
-
- };
-
- } // namespace Lua
-} // namespace JinEngine
-
-#endif // __JIN_COMMON_PROXY_H \ No newline at end of file
diff --git a/src/lua/common/Reference.hpp b/src/lua/common/Reference.hpp
deleted file mode 100644
index ba918bb..0000000
--- a/src/lua/common/Reference.hpp
+++ /dev/null
@@ -1,88 +0,0 @@
-#ifndef __JIN_COMMON_REFERENCE_H
-#define __JIN_COMMON_REFERENCE_H
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- /*abstract*/class RefBase
- {
- public:
- void retain()
- {
- ++count;
- }
-
- void release()
- {
- if (--count <= 0)
- delete this;
- }
-
- // object type string
- const char* const type;
-
- void setUserdata(void* data)
- {
- userdata = data;
- }
-
- void* getUserdata()
- {
- return userdata;
- }
-
- protected:
- RefBase(void* obj, const char* t)
- : count(1)
- , object(obj)
- , type(t)
- {
- }
-
- RefBase(const RefBase&);
-
- virtual ~RefBase()
- {
- }
-
- void* object;
- int count;
- void* userdata;
- };
-
- template<class T>
- class Ref : public RefBase
- {
- public:
- Ref(T* obj, const char* type)
- : RefBase(obj, type)
- {
- }
-
- ~Ref()
- {
- T* obj = static_cast<T*>(object);
- delete obj;
- }
-
- T* operator->()
- {
- return (T*)object;
- }
-
- T* getObject()
- {
- return (T*)object;
- }
-
- private:
- Ref(const Ref<T>& ref);
-
- };
-
- }
-}
-
-#endif \ No newline at end of file
diff --git a/src/lua/common/common.h b/src/lua/common/common.h
deleted file mode 100644
index 0ee72cc..0000000
--- a/src/lua/common/common.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef __JIN_M_TYPES_H
-#define __JIN_M_TYPES_H
-
-#include "Proxy.h"
-#include "Reference.hpp"
-#include "error.h"
-
-#endif \ No newline at end of file
diff --git a/src/lua/common/constant.h b/src/lua/common/constant.h
deleted file mode 100644
index 6f70f09..0000000
--- a/src/lua/common/constant.h
+++ /dev/null
@@ -1 +0,0 @@
-#pragma once
diff --git a/src/lua/common/error.h b/src/lua/common/error.h
deleted file mode 100644
index c254486..0000000
--- a/src/lua/common/error.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef __JIN_ERROR_H
-#define __JIN_ERROR_H
-#include "../../luax.h"
-#include "../jin.h"
-#include <string.h>
-
-namespace JinEngine
-{
-namespace Lua
-{
-
- static const int FORMAT_MSG_BUFFER_SIZE = 2048;
-
- inline void error(lua_State* L, const char* fmt, ...)
- {
- char err[FORMAT_MSG_BUFFER_SIZE + 1] = { 0 };
- va_list args;
- va_start(args, fmt);
- vsnprintf(err + strlen(err), FORMAT_MSG_BUFFER_SIZE, fmt, args);
- va_end(args);
- luax_getglobal(L, MODULE_NAME);
- luax_setfieldstring(L, "error", err);
- }
-
-}
-}
-
-#endif \ No newline at end of file
diff --git a/src/lua/common/je_lua_callback.cpp b/src/lua/common/je_lua_callback.cpp
new file mode 100644
index 0000000..392f919
--- /dev/null
+++ b/src/lua/common/je_lua_callback.cpp
@@ -0,0 +1,43 @@
+#include "je_lua_callback.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ LuaCallback::LuaCallback(lua_State* L)
+ : mLuaFunc(nullptr)
+ , mParams(0)
+ , mL(L)
+ {
+ }
+
+ LuaCallback::~LuaCallback()
+ {
+ delete mLuaFunc;
+ for (auto p : mParams)
+ delete p;
+ }
+
+ void LuaCallback::setFunc(int i)
+ {
+ if (mLuaFunc != nullptr)
+ delete mLuaFunc;
+ mLuaFunc = new LuaRef(mL, i);
+ }
+
+ void LuaCallback::pushParam(int i)
+ {
+ mParams.push_back(new LuaRef(mL, i));
+ }
+
+ void LuaCallback::call()
+ {
+ mLuaFunc->push();
+ for (auto p : mParams)
+ p->push();
+ luax_call(mL, mParams.size(), 0);
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/common/je_lua_callback.h b/src/lua/common/je_lua_callback.h
new file mode 100644
index 0000000..f3301fc
--- /dev/null
+++ b/src/lua/common/je_lua_callback.h
@@ -0,0 +1,67 @@
+#ifndef __JIN_COMMON_FUNCTION_H
+#define __JIN_COMMON_FUNCTION_H
+
+#include <vector>
+
+#include "libjin/jin.h"
+#include "../luax.h"
+#include "je_lua_reference.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ ///
+ ///
+ ///
+ class LuaCallback
+ {
+ public:
+ ///
+ ///
+ ///
+ LuaCallback(lua_State* L);
+
+ ///
+ ///
+ ///
+ ~LuaCallback();
+
+ ///
+ ///
+ ///
+ void setFunc(int i);
+
+ ///
+ ///
+ ///
+ void pushParam(int i);
+
+ ///
+ ///
+ ///
+ void call();
+
+ private:
+ ///
+ ///
+ ///
+ LuaRef* mLuaFunc;
+
+ ///
+ ///
+ ///
+ std::vector<LuaRef*> mParams;
+
+ ///
+ ///
+ ///
+ lua_State* const mL;
+
+ };
+
+ } // namespace Lua
+} // namespace JinEngine
+
+#endif // __JIN_COMMON_REFERENCE_H \ No newline at end of file
diff --git a/src/lua/common/je_lua_common.h b/src/lua/common/je_lua_common.h
new file mode 100644
index 0000000..5b217a2
--- /dev/null
+++ b/src/lua/common/je_lua_common.h
@@ -0,0 +1,10 @@
+#ifndef __JIN_M_TYPES_H
+#define __JIN_M_TYPES_H
+
+#include "je_lua_port.h"
+#include "je_lua_proxy.h"
+#include "je_lua_shared.hpp"
+#include "je_lua_error.h"
+#include "je_lua_reference.h"
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/particle/je_particle_system.cpp b/src/lua/common/je_lua_constant.h
index 6f70f09..6f70f09 100644
--- a/src/libjin/Graphics/particle/je_particle_system.cpp
+++ b/src/lua/common/je_lua_constant.h
diff --git a/src/lua/common/je_lua_error.h b/src/lua/common/je_lua_error.h
new file mode 100644
index 0000000..3f7e76f
--- /dev/null
+++ b/src/lua/common/je_lua_error.h
@@ -0,0 +1,28 @@
+#ifndef __JIN_ERROR_H
+#define __JIN_ERROR_H
+#include "../luax.h"
+#include <string.h>
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ static const int FORMAT_MSG_BUFFER_SIZE = 2048;
+
+ inline void error(lua_State* L, const char* fmt, ...)
+ {
+ char err[FORMAT_MSG_BUFFER_SIZE + 1] = { 0 };
+ va_list args;
+ va_start(args, fmt);
+ vsnprintf(err + strlen(err), FORMAT_MSG_BUFFER_SIZE, fmt, args);
+ va_end(args);
+ //luax_getglobal(L, "jin");
+ //luax_setfieldstring(L, "error", err);
+ luax_error(L, err);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/particle/je_particle_batch.cpp b/src/lua/common/je_lua_function.cpp
index e69de29..e69de29 100644
--- a/src/libjin/Graphics/particle/je_particle_batch.cpp
+++ b/src/lua/common/je_lua_function.cpp
diff --git a/src/lua/common/je_lua_function.h b/src/lua/common/je_lua_function.h
new file mode 100644
index 0000000..49c1b31
--- /dev/null
+++ b/src/lua/common/je_lua_function.h
@@ -0,0 +1,6 @@
+#ifndef __JE_LUA_FUNCTION_H__
+#define __JE_LUA_FUNCTION_H__
+
+
+
+#endif \ No newline at end of file
diff --git a/src/lua/common/je_lua_port.h b/src/lua/common/je_lua_port.h
new file mode 100644
index 0000000..8e99ca4
--- /dev/null
+++ b/src/lua/common/je_lua_port.h
@@ -0,0 +1,8 @@
+#ifndef __JE_LUA_PORT_H
+#define __JE_LUA_PORT_H
+
+#define LUA_PORT extern
+#define LUA_IMPLEMENT static
+#define LUA_EXPORT
+
+#endif \ No newline at end of file
diff --git a/src/lua/common/je_lua_proxy.h b/src/lua/common/je_lua_proxy.h
new file mode 100644
index 0000000..ca4a56a
--- /dev/null
+++ b/src/lua/common/je_lua_proxy.h
@@ -0,0 +1,72 @@
+#ifndef __JIN_COMMON_PROXY_H
+#define __JIN_COMMON_PROXY_H
+
+#include "../luax.h"
+
+#include "je_lua_shared.hpp"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ class Proxy
+ {
+ public:
+ void bind(SharedBase* s)
+ {
+ if (s == nullptr)
+ return;
+ shared = s;
+ shared->retain();
+ }
+
+ void release()
+ {
+ if (shared != nullptr)
+ {
+ shared->release();
+ shared = nullptr;
+ }
+ }
+/*
+ void retain()
+ {
+ if (shared != nullptr)
+ shared->retain();
+ }
+*/
+ template<class T>
+ Shared<T>& getShared()
+ {
+ return *(Shared<T>*)shared;
+ }
+
+ ///
+ /// For convenience.
+ ///
+ template<class T>
+ T* getObject()
+ {
+ Shared<T>& shared = getShared<T>();
+ return shared.getObject();
+ }
+
+ const char* getObjectType()
+ {
+ return shared->type;
+ }
+
+ SharedBase* shared;
+
+ };
+
+ inline Proxy* luax_newinstance(lua_State* L, const char* type)
+ {
+ return static_cast<Proxy*>(luax_newinstance(L, type, sizeof(Proxy)));
+ }
+
+ } // namespace Lua
+} // namespace JinEngine
+
+#endif // __JIN_COMMON_PROXY_H \ No newline at end of file
diff --git a/src/lua/common/je_lua_reference.cpp b/src/lua/common/je_lua_reference.cpp
new file mode 100644
index 0000000..90223de
--- /dev/null
+++ b/src/lua/common/je_lua_reference.cpp
@@ -0,0 +1,31 @@
+#include "je_lua_reference.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ LuaRef::LuaRef(lua_State* L, int i)
+ : mL(L)
+ {
+ luax_pushvalue(mL, i);
+ mIndex = luax_ref(mL, LUA_REGISTRYINDEX);
+ }
+
+ LuaRef::~LuaRef()
+ {
+ unref();
+ }
+
+ void LuaRef::unref()
+ {
+ luax_unref(mL, LUA_REGISTRYINDEX, mIndex);
+ }
+
+ void LuaRef::push()
+ {
+ luax_rawgeti(mL, LUA_REGISTRYINDEX, mIndex);
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/common/je_lua_reference.h b/src/lua/common/je_lua_reference.h
new file mode 100644
index 0000000..f338762
--- /dev/null
+++ b/src/lua/common/je_lua_reference.h
@@ -0,0 +1,54 @@
+#ifndef __JIN_COMMON_REFERENCE_H
+#define __JIN_COMMON_REFERENCE_H
+
+#include "../luax.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ ///
+ /// This class wraps the reference functionality built into Lua, which allows C++ code to refer to Lua
+ /// variables.
+ ///
+ class LuaRef
+ {
+ public:
+ ///
+ ///
+ ///
+ LuaRef(lua_State* L, int i);
+
+ ///
+ ///
+ ///
+ ~LuaRef();
+
+ ///
+ ///
+ ///
+ void unref();
+
+ ///
+ /// Push value onto the stack.
+ ///
+ void push();
+
+ private:
+ ///
+ ///
+ ///
+ lua_State* const mL;
+
+ ///
+ ///
+ ///
+ int mIndex;
+
+ };
+
+ } // namespace Lua
+} // namespace JinEngine
+
+#endif // __JIN_COMMON_REFERENCE_H \ No newline at end of file
diff --git a/src/lua/common/je_lua_shared.hpp b/src/lua/common/je_lua_shared.hpp
new file mode 100644
index 0000000..91705d1
--- /dev/null
+++ b/src/lua/common/je_lua_shared.hpp
@@ -0,0 +1,151 @@
+#ifndef __JIN_COMMON_SHARED_H__
+#define __JIN_COMMON_SHARED_H__
+
+#include <map>
+#include <vector>
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ class SharedBase
+ {
+ public:
+ void retain()
+ {
+ ++mCount;
+ }
+
+ void release()
+ {
+ if (--mCount <= 0)
+ delete this;
+ }
+
+ // Object type.
+ const char* const type;
+
+ void setDependency(int key, SharedBase* shared)
+ {
+ removeDependency(key);
+ shared->retain();
+ mDependencies.insert(std::pair<int, SharedBase*>(key, shared));
+ }
+
+ void removeDependency(int key)
+ {
+ if (!isDependOn(key))
+ return;
+ DepMap::iterator it = mDependencies.find(key);
+ it->second->release();
+ mDependencies.erase(it);
+ }
+
+ void removeDependency(SharedBase* dep)
+ {
+ for (DepMap::iterator it = mDependencies.begin(); it != mDependencies.end();)
+ {
+ if (it->second == dep)
+ {
+ it->second->release();
+ mDependencies.erase(it);
+ }
+ else
+ ++it;
+ }
+ }
+
+ bool isDependOn(int key)
+ {
+ return mDependencies.find(key) != mDependencies.end();
+ }
+
+ bool isDependOn(SharedBase* shared)
+ {
+ for (std::pair<int, SharedBase*> dep : mDependencies)
+ {
+ if (dep.second == shared)
+ return true;
+ }
+ return false;
+ }
+
+ void clearDependencies()
+ {
+ for (std::pair<int, SharedBase*> dep : mDependencies)
+ dep.second->release();
+ mDependencies.clear();
+ }
+
+ SharedBase* getDependency(int key)
+ {
+ if (!isDependOn(key))
+ return nullptr;
+ return mDependencies.find(key)->second;
+ }
+
+ bool isType(const char* t)
+ {
+ return strcmp(type, t) == 0;
+ }
+
+ protected:
+
+ using DepMap = std::map<int, SharedBase*>;
+
+ SharedBase(void* obj, const char* t)
+ : mCount(0)
+ , mObject(obj)
+ , type(t)
+ {
+ }
+
+ SharedBase(const SharedBase&);
+
+ virtual ~SharedBase()
+ {
+ clearDependencies();
+ }
+
+ void* mObject;
+ int mCount;
+ DepMap mDependencies;
+ };
+
+ template<class T>
+ class Shared : public SharedBase
+ {
+ public:
+ Shared(T* obj, const char* type)
+ : SharedBase(obj, type)
+ {
+ }
+
+ T* operator->()
+ {
+ return static_cast<T*>(mObject);
+ }
+
+ T* getObject()
+ {
+ return static_cast<T*>(mObject);
+ }
+
+ private:
+ // Disable copy constructor.
+ Shared(const Shared<T>& shared);
+
+ // Make shared only be able created with new.
+ ~Shared()
+ {
+ T* obj = static_cast<T*>(mObject);
+ delete obj;
+ }
+
+ };
+
+ } // namespace Lua
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/lua/embed/boot.lua.h b/src/lua/embed/boot.lua.h
deleted file mode 100644
index 99e657b..0000000
--- a/src/lua/embed/boot.lua.h
+++ /dev/null
@@ -1,175 +0,0 @@
-/* boot.lua */
-static const char* boot_lua = R"(
-jin.args[2] = jin.args[2] or '.'
-jin.filesystem.init()
-jin.filesystem.mount(jin.args[2])
-
--------------------------------------------------------------------------
--- Config game
--------------------------------------------------------------------------
-
-jin.config = {}
-if jin.filesystem.exist("config.lua") then
- jin.config = require "config"
-end
-jin.config.width = jin.config.width or 576
-jin.config.height = jin.config.height or 448
-jin.config.vsync = jin.config.vsync or true
-jin.config.title = jin.config.title or ("jin v" .. jin.version)
-jin.config.resizable = jin.config.resizable or false
-jin.config.fullscreen = jin.config.fullscreen or false
-jin.config.fps = jin.config.fps or 60
-
--------------------------------------------------------------------------
--- Initialize sub systems
--------------------------------------------------------------------------
-
-jin.graphics.init(jin.config)
-jin.audio.init()
--- TODO: ϵͳģ
-
--------------------------------------------------------------------------
--- Default game loop
--------------------------------------------------------------------------
-
-local function call(func, ...)
- if func then
- return func(...)
- end
-end
-
-function jin.core.run()
- call(jin.core.onLoad)
- jin.graphics.reset()
- local dt = 0
- local previous = jin.time.second()
- local current = previous
- while jin.core.running() do
- for _, e in pairs(jin.event.poll()) do
- if e.type == "KeyDown" then
- jin.keyboard.set(e.key, true)
- elseif e.type == "KeyUp" then
- jin.keyboard.set(e.key, false)
- end
- call(jin.core.onEvent, e)
- end
- previous = current
- current = jin.time.second()
- dt = current - previous
- call(jin.core.onUpdate, dt)
- jin.graphics.clear()
- call(jin.core.onDraw)
- jin.graphics.present()
- -- Sleep 1 ms
- jin.time.sleep(0.001)
- end
-end
-
--------------------------------------------------------------------------
--- No game handler
--------------------------------------------------------------------------
-
-jin.core.setHandler = function(handler)
- if handler == nil then
- return
- end
- jin.core.onLoad = handler.onLoad
- jin.core.onEvent = handler.onEvent
- jin.core.onUpdate = handler.onUpdate
- jin.core.onDraw = handler.onDraw
-end
-
--- TODO: Ĭͼbase64
-jin.nogame = {
- cs = 64,
- sw = jin.graphics.getWidth(),
- sh = jin.graphics.getHeight(),
- cw = 0,
- ch = 0,
- ww = 6,
- ww2 = 6*2,
- speed = 4,
- t = 0,
- onLoad = function()
- local nogame = jin.nogame
- nogame.cw = nogame.sw / nogame.cs
- nogame.ch = nogame.sh / nogame.cs
- nogame.t = nogame.ww - 1
- end,
- onEvent = function(e)
- if e.type == 'Quit' then
- jin.core.stop()
- end
- end,
- onUpdate = function(dt)
- print(dt)
- local nogame = jin.nogame
- nogame.t = nogame.t + dt * nogame.speed
- if nogame.t > nogame.ww2 then
- nogame.t = nogame.t - nogame.ww2
- end
- end,
- circle = function(x, y, r)
- local nogame = jin.nogame
- if r % nogame.ww2 > nogame.ww then
- return
- end
- r = math.sin((r/nogame.ww)*math.pi)*nogame.cs/2
- local fact = (x + y) / nogame.ch * nogame.cw
- jin.graphics.setColor(
- 155 + 100 * math.sin(fact),
- 155 + 100 * math.cos(fact),
- 155 + 100 * math.sin(fact * fact),
- 255
- )
- jin.graphics.circle("fill", x*nogame.cs + nogame.cs/2, y*nogame.cs + nogame.cs/2, r)
- end,
- onDraw = function()
- local nogame = jin.nogame
- for y = 0, nogame.ch - 1 do
- for x = 0, nogame.cw - 1 do
- nogame.circle(x, y, nogame.t+x+y)
- end
- end
- end
-}
-
--------------------------------------------------------------------------
--- Boot jin
--------------------------------------------------------------------------
-
-local function onError(msg)
- jin.graphics.reset()
- jin.graphics.setClearColor(100, 100, 100, 255)
- jin.graphics.clear()
- jin.graphics.print("Error:\n" .. msg .. "\n" .. debug.traceback(), 5, 5)
- jin.graphics.present()
- while jin.core.running() do
- for _, e in pairs(jin.event.poll()) do
- if e.type == "Quit" then
- jin.core.stop()
- end
- end
- jin.time.sleep(0.001)
- end
- jin.core.quit()
-end
-
-local function boot()
- if jin.filesystem.exist("main.lua") then
- -- Require main game script
- xpcall(function() require"main" end, onError)
- xpcall(function() jin.core.run() end, onError)
- else
- -- No game
- jin.core.setHandler(jin.nogame)
- jin.core.run()
- end
- jin.graphics.destroy()
- jin.audio.destroy()
- jin.core.quit()
-end
-
-xpcall(boot, onError)
-
-)"; \ No newline at end of file
diff --git a/src/lua/embed/embed.h b/src/lua/embed/embed.h
index 18373c8..054672c 100644
--- a/src/lua/embed/embed.h
+++ b/src/lua/embed/embed.h
@@ -4,30 +4,26 @@
namespace JinEngine
{
-namespace embed
-{
+ namespace Embed
+ {
-#define embed(L, script, name)\
- if(luax_loadbuffer(L, script, strlen(script), name) == 0)\
- lua_call(L, 0, 0);
+ #define embed(L, script, name)\
+ if(luax_loadbuffer(L, script, strlen(script), name) == 0)\
+ lua_call(L, 0, 0);
- /**
- * embed structure.
- */
- struct jin_Embed
- {
- const char* file, *source;
- };
+ // Embed structure.
+ struct jin_Embed
+ {
+ const char* file, *source;
+ };
- static void boot(lua_State* L)
- {
- // embed scripts
- #include "graphics.lua.h"
- #include "keyboard.lua.h"
- #include "mouse.lua.h"
- #include "boot.lua.h"
+ // Embed scripts.
+ #include "scripts/graphics.lua.h"
+ #include "scripts/keyboard.lua.h"
+ #include "scripts/mouse.lua.h"
+ #include "scripts/boot.lua.h"
- // in order
+ // In order.
const jin_Embed scripts[] = {
{ "graphics.lua", graphics_lua },
{ "keyboard.lua", keyboard_lua },
@@ -36,11 +32,13 @@ namespace embed
{ 0, 0 }
};
- for (int i = 0; scripts[i].file; ++i)
- embed(L, scripts[i].source, scripts[i].file);
- }
+ static void boot(lua_State* L)
+ {
+ for (int i = 0; scripts[i].file; ++i)
+ embed(L, scripts[i].source, scripts[i].file);
+ }
-} // embed
+ } // namespace Embed
} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/lua/embed/graphics.lua.h b/src/lua/embed/graphics.lua.h
deleted file mode 100644
index 5fa5dad..0000000
--- a/src/lua/embed/graphics.lua.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/* graphics.lua */
-static const char* graphics_lua = R"(
-jin.graphics = jin.graphics or {}
-
-local default_shader = nil
-local default_shader_source = [[
-#VERTEX_SHADER
-
-Vertex vert(Vertex v)
-{
- return v;
-}
-
-#END_VERTEX_SHADER
-
-#FRAGMENT_SHADER
-
-Color frag(Color col, Texture tex, Vertex v)
-{
- return col * texel(tex, v.uv);
-}
-
-#END_FRAGMENT_SHADER
-]]
-
-local _init = jin.graphics.init
-
-jin.graphics.init = function(setting)
- _init(setting);
- default_shader = jin.graphics.newShader(default_shader_source)
- jin.graphics.useShader(default_shader)
-end
-
-jin.graphics.unuseShader = function()
- jin.graphics.useShader(default_shader)
-end
-
--- Reset all attributes to default value.
-jin.graphics.reset = function()
- jin.graphics.setColor(255, 255, 255, 255)
- jin.graphics.setClearColor(0, 0, 0, 255)
- jin.graphics.clear()
- jin.graphics.unsetFont()
-end
-
-)";
diff --git a/src/lua/embed/scripts/ai.lua.h b/src/lua/embed/scripts/ai.lua.h
new file mode 100644
index 0000000..a69da84
--- /dev/null
+++ b/src/lua/embed/scripts/ai.lua.h
@@ -0,0 +1,26 @@
+/* graphics.lua */
+static const char* ai_lua = R"(
+jin.ai = jin.ai or {}
+
+local ja = jin.ai
+
+ja.StateMachineType = {
+ STEPWISE = 1,
+ ITERATIVE = 2,
+}
+
+
+
+)";
+
+
+//local sp = jin.graphics.newSprite()
+//local sm = jin.ai.newStateMachine(jin.StateMachineMode.STEPWISE, sp)
+//sm:addState("run")
+//sm:addEnterCallback("run", function(spr)
+// spr:setRun()
+//end)
+//
+//function jin.core.onUpdate(dt)
+// sm:update()
+//end
diff --git a/src/lua/embed/scripts/boot.lua.h b/src/lua/embed/scripts/boot.lua.h
new file mode 100644
index 0000000..af81c16
--- /dev/null
+++ b/src/lua/embed/scripts/boot.lua.h
@@ -0,0 +1,139 @@
+/* boot.lua */
+static const char* boot_lua = R"(
+local cwd = jin.args['cwd'] or '.'
+jin.filesystem.init()
+jin.filesystem.mount(cwd)
+
+-------------------------------------------------------------------------
+-- Config game
+-------------------------------------------------------------------------
+
+jin.config = {}
+if jin.filesystem.exist("config.lua") then
+ xpcall(function()jin.config = require "config" end, function()end)
+end
+jin.config.width = jin.config.width or 580
+jin.config.height = jin.config.height or 450
+jin.config.vsync = jin.config.vsync or true
+jin.config.title = jin.config.title or ("jin v" .. jin.version)
+jin.config.resizable = jin.config.resizable or false
+jin.config.fullscreen = jin.config.fullscreen or false
+jin.config.fps = jin.config.fps or 60
+jin.config.icon = jin.config.icon or ""
+
+-------------------------------------------------------------------------
+-- Default game loop
+-------------------------------------------------------------------------
+
+local function call(func, ...)
+ if func then
+ return func(...)
+ end
+end
+
+local step = jin.time.step
+jin.time.step = nil
+
+function jin.core.run()
+ jin.graphics.reset()
+ call(jin.core.onLoad)
+ local dt = 0
+ while jin.core.running() do
+ for _, e in pairs(jin.event.poll()) do
+ if e.type == "KeyDown" then
+ jin.keyboard.set(e.key, true)
+ elseif e.type == "KeyUp" then
+ jin.keyboard.set(e.key, false)
+ end
+ call(jin.core.onEvent, e)
+ end
+ step()
+ dt = jin.time.getDelta()
+ call(jin.core.onUpdate)
+ jin.graphics.clear()
+ call(jin.core.onDraw)
+ jin.graphics.present()
+ jin.time.sleep(0.001)
+ end
+end
+
+-------------------------------------------------------------------------
+-- Boot game
+-------------------------------------------------------------------------
+
+-- Display error message.
+local function onError(msg)
+ jin.audio.destroy()
+ jin.graphics.showWindow()
+ local err = "Error:\n" .. msg .. "\n" .. debug.traceback()
+ jin.graphics.reset()
+ jin.graphics.setClearColor(100, 100, 100, 255)
+ jin.graphics.clear()
+ jin.graphics.print(err, 5, 5)
+ jin.graphics.present()
+ while jin.core.running() do
+ for _, e in pairs(jin.event.poll()) do
+ if e.type == "Quit" then
+ jin.core.stop()
+ end
+ end
+ jin.time.sleep(0.001)
+ end
+end
+
+-- No game screen.
+local function noGame()
+ jin.graphics.showWindow()
+ jin.graphics.reset()
+ jin.graphics.setClearColor(100, 100, 100, 255)
+ jin.graphics.clear()
+ jin.graphics.print("No Game", 5, 5)
+ jin.graphics.present()
+ while jin.core.running() do
+ for _, e in pairs(jin.event.poll()) do
+ if e.type == "Quit" then
+ jin.core.stop()
+ end
+ end
+ jin.time.sleep(0.001)
+ end
+end
+
+local function boot()
+ if jin.filesystem.exist("main.lua") then
+ call(function()
+ require"main"
+ jin.core.run()
+ end)
+ else
+ noGame()
+ end
+end
+
+-------------------------------------------------------------------------
+-- Initialize sub systems
+-------------------------------------------------------------------------
+
+jin.audio.init()
+jin.graphics.init(jin.config)
+
+-------------------------------------------------------------------------
+-- Boot game
+-------------------------------------------------------------------------
+
+xpcall(boot, onError)
+
+-------------------------------------------------------------------------
+-- Destroy sub-systems
+-------------------------------------------------------------------------
+
+jin.graphics.destroy()
+jin.audio.destroy()
+
+-------------------------------------------------------------------------
+-- Quit game
+-------------------------------------------------------------------------
+
+jin.core.quit()
+
+)"; \ No newline at end of file
diff --git a/src/lua/embed/scripts/graphics.lua.h b/src/lua/embed/scripts/graphics.lua.h
new file mode 100644
index 0000000..e1079b9
--- /dev/null
+++ b/src/lua/embed/scripts/graphics.lua.h
@@ -0,0 +1,73 @@
+/* graphics.lua */
+static const char* graphics_lua = R"(
+jin.graphics = jin.graphics or {}
+
+local jg = jin.graphics
+
+jg.RenderMode = {
+ FILL = 1,
+ LINE = 2,
+}
+
+jg.SpriteOrigin = {
+ TOPLEFT = 0,
+ TOPCENTER = 1,
+ TOPRIGHT = 2,
+ MIDDLELEFT = 3,
+ MIDDLECENTER = 4,
+ MIDDLERIGHT = 5,
+ BOTTOMLEFT = 6,
+ BOTTOMCENTER = 7,
+ BOTTOMRIGHT = 8
+}
+
+local default_shader = nil
+local default_shader_source = [[
+#VERTEX_SHADER
+
+Vertex vert(Vertex v)
+{
+ return v;
+}
+
+#END_VERTEX_SHADER
+
+#FRAGMENT_SHADER
+
+Color frag(Color col, Texture tex, Vertex v)
+{
+ return col * texel(tex, v.uv);
+}
+
+#END_FRAGMENT_SHADER
+]]
+
+local _init = jg.init
+local initialized = false
+
+jg.init = function(setting)
+ if initialized then
+ return initialized
+ end
+ initialized = _init(setting)
+ if initialized then
+ default_shader = jg.newShader(default_shader_source)
+ jg.useShader(default_shader)
+ end
+ return initialized
+end
+
+jg.unuseShader = function()
+ jg.useShader(default_shader)
+end
+
+-- Reset all attributes to default value.
+jg.reset = function()
+ jg.setColor(255, 255, 255, 255)
+ jg.setClearColor(0, 0, 0, 255)
+ jg.clear()
+ jg.unsetFont()
+ jg.unuseShader()
+end
+
+)"; \ No newline at end of file
diff --git a/src/lua/embed/keyboard.lua.h b/src/lua/embed/scripts/keyboard.lua.h
index ee8428f..e989928 100644
--- a/src/lua/embed/keyboard.lua.h
+++ b/src/lua/embed/scripts/keyboard.lua.h
@@ -2,6 +2,8 @@
static const char* keyboard_lua = R"(
jin.keyboard = jin.keyboard or {}
+local jk = jin.keyboard
+
local keys = {}
function jin.keyboard.isPressed(k)
diff --git a/src/lua/embed/mouse.lua.h b/src/lua/embed/scripts/mouse.lua.h
index 3c222f3..ca070a3 100644
--- a/src/lua/embed/mouse.lua.h
+++ b/src/lua/embed/scripts/mouse.lua.h
@@ -1,6 +1,8 @@
static const char* mouse_lua = R"(
jin.mouse = jin.mouse or {}
+local jm = jin.mouse
+
local button = {}
function jin.mouse.isDown(btn)
diff --git a/src/lua/embed/net.lua.h b/src/lua/embed/scripts/net.lua.h
index 4d89dc7..a986ce6 100644
--- a/src/lua/embed/net.lua.h
+++ b/src/lua/embed/scripts/net.lua.h
@@ -1,4 +1,7 @@
/* net.lua */
static const char* net_lua = R"(
jin.net = jin.net or {}
+
+local jn = jin.net
+
)"; \ No newline at end of file
diff --git a/src/lua/embed/path.lua.h b/src/lua/embed/scripts/path.lua.h
index 648adf8..f7e1ec3 100644
--- a/src/lua/embed/path.lua.h
+++ b/src/lua/embed/scripts/path.lua.h
@@ -2,6 +2,8 @@
static const char* path_lua = R"(
jin.path = jin.path or {}
+local jp = jin.path
+
-- game root directory
jin._root = nil
diff --git a/src/lua/jin.cpp b/src/lua/jin.cpp
index faae9b2..d9f685b 100644
--- a/src/lua/jin.cpp
+++ b/src/lua/jin.cpp
@@ -1,39 +1,40 @@
-#include "jin.h"
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
#include "embed/embed.h"
+#include "jin.h"
namespace JinEngine
{
namespace Lua
{
- extern int luaopen_core(lua_State* L);
- extern int luaopen_graphics(lua_State* L);
- extern int luaopen_audio(lua_State* L);
- extern int luaopen_net(lua_State* L);
- extern int luaopen_event(lua_State* L);
- extern int luaopen_time(lua_State* L);
- extern int luaopen_mouse(lua_State* L);
- extern int luaopen_keyboard(lua_State* L);
- extern int luaopen_filesystem(lua_State* L);
- extern int luaopen_joypad(lua_State* L);
- extern int luaopen_math(lua_State* L);
- extern int luaopen_thread(lua_State* L);
- extern int luaopen_bit(lua_State* L);
+ LUA_PORT int luaopen_core(lua_State* L);
+ LUA_PORT int luaopen_graphics(lua_State* L);
+ LUA_PORT int luaopen_audio(lua_State* L);
+ LUA_PORT int luaopen_net(lua_State* L);
+ LUA_PORT int luaopen_event(lua_State* L);
+ LUA_PORT int luaopen_time(lua_State* L);
+ LUA_PORT int luaopen_mouse(lua_State* L);
+ LUA_PORT int luaopen_keyboard(lua_State* L);
+ LUA_PORT int luaopen_filesystem(lua_State* L);
+ LUA_PORT int luaopen_joypad(lua_State* L);
+ LUA_PORT int luaopen_math(lua_State* L);
+ LUA_PORT int luaopen_thread(lua_State* L);
+ LUA_PORT int luaopen_bit(lua_State* L);
- static int l_getversion(lua_State* L)
+ LUA_IMPLEMENT int l_getversion(lua_State* L)
{
luax_pushstring(L, VERSION);
return 1;
}
- static int l_getAuthor(lua_State* L)
+ LUA_IMPLEMENT int l_getAuthor(lua_State* L)
{
luax_pushstring(L, AUTHOR);
return 1;
}
- static int l_getOS(lua_State* L)
+ LUA_IMPLEMENT int l_getOS(lua_State* L)
{
#ifdef _WIN32
luax_pushstring(L, "windows");
@@ -45,65 +46,64 @@ namespace JinEngine
return 1;
}
- static int l_revision(lua_State* L)
+ LUA_IMPLEMENT int l_revision(lua_State* L)
{
luax_pushnumber(L, REVISION);
return 1;
}
- static const luax_Str s[] = {
+ LUA_IMPLEMENT const luax_Str s[] = {
{ "version", VERSION },
{ "author", AUTHOR },
{ "codename", CODE_NAME },
{ 0, 0 }
};
- static const luax_Num n[] = {
+ LUA_IMPLEMENT const luax_Num n[] = {
{ "revision", REVISION },
{ 0, 0 }
};
- /* sub modules */
- static const luax_Ref mods[] = {
- { "core", luaopen_core },
- { "event", luaopen_event },
- { "graphics", luaopen_graphics },
- { "time", luaopen_time },
- { "mouse", luaopen_mouse },
- { "keyboard", luaopen_keyboard },
- { "filesystem", luaopen_filesystem },
- { "net", luaopen_net },
- { "audio", luaopen_audio },
- { "joypad", luaopen_joypad },
- { "math", luaopen_math },
- { "thread", luaopen_thread },
- { "bit", luaopen_bit },
- //{"ai", luaopen_ai },
- { 0, 0 }
- };
-
/* register jin module, keep it on the top of stack */
- int luaopen_jin(lua_State* L)
+ LUA_EXPORT int luaopen_jin(lua_State* L)
{
luax_globaltable(L, MODULE_NAME);
- /* register values */
+ // Register values.
luax_setfieldstrings(L, s);
luax_setfieldnumbers(L, n);
- /* register submodules */
- for (int i = 0; mods[i].name; ++i)
+ luax_Reg modules[] = {
+ { "core", luaopen_core },
+ { "event", luaopen_event },
+ { "graphics", luaopen_graphics },
+ { "time", luaopen_time },
+ { "mouse", luaopen_mouse },
+ { "keyboard", luaopen_keyboard },
+ { "filesystem", luaopen_filesystem },
+ { "net", luaopen_net },
+ { "audio", luaopen_audio },
+ { "joypad", luaopen_joypad },
+ { "math", luaopen_math },
+ { "thread", luaopen_thread },
+ { "bit", luaopen_bit },
+ //{"ai", luaopen_ai },
+ { 0, 0 }
+ };
+
+ // Register sub modules.
+ for (int i = 0; modules[i].name; ++i)
{
- mods[i].func(L);
- luax_setfield(L, -2, mods[i].name);
+ modules[i].func(L);
+ luax_setfield(L, -2, modules[i].name);
}
return 1;
}
- void boot(lua_State* L)
+ LUA_EXPORT void boot(lua_State* L)
{
- JinEngine::embed::boot(L);
+ JinEngine::Embed::boot(L);
}
} // namespace Lua
diff --git a/src/lua/jin.h b/src/lua/jin.h
index 71ad51b..a4dcd3e 100644
--- a/src/lua/jin.h
+++ b/src/lua/jin.h
@@ -4,6 +4,7 @@
#ifndef __JIN_M_JIN_H
#define __JIN_M_JIN_H
+#include "lua/common/je_lua_common.h"
#include "luax.h"
#define MODULE_NAME "jin"
@@ -21,12 +22,12 @@ namespace JinEngine
///
/// open jin module.
///
- int luaopen_jin(lua_State* L);
+ LUA_EXPORT int luaopen_jin(lua_State* L);
///
/// Boot jin.
///
- void boot(lua_State* L);
+ LUA_EXPORT void boot(lua_State* L);
} // namespace JinEngine
} // namespace Lua
diff --git a/src/lua/libraries/luax/luax.h b/src/lua/libraries/luax/luax.h
index fd10737..311bc95 100644
--- a/src/lua/libraries/luax/luax.h
+++ b/src/lua/libraries/luax/luax.h
@@ -40,13 +40,13 @@
#define luax_pcall lua_pcall
#define luax_setglobal lua_setglobal
#define luax_setglobali(L, i, name)\
-lua_pushvalue(L, i);\
-lua_setglobal(L, name);
+ lua_pushvalue(L, i);\
+ lua_setglobal(L, name);
#define luax_pop lua_pop
#define luax_newtable lua_newtable
#define luax_getglobal lua_getglobal
-#define luax_clear(L) lua_settop(L, 0)
+#define luax_clearstack(L) lua_settop(L, 0)
/**
*
*/
@@ -89,6 +89,14 @@ inline bool luax_checkbool(lua_State *L, int numArg)
*/
/* get value and leaves it on top of stack */
#define luax_rawgetnumber(L, i, k) (lua_rawgeti(L,i, k), lua_tonumber(L, -1))
+inline float luax_rawgetnumberthenpop(lua_State* L, int i, int k)
+{
+ float n = luax_rawgetnumber(L, i, k);
+ luax_pop(L, 1);
+ return n;
+}
+
+#define luax_rawgeti lua_rawgeti
/**
*
@@ -111,6 +119,7 @@ inline bool luax_checkbool(lua_State *L, int numArg)
#define luax_pushboolean lua_pushboolean
#define luax_pushlightuserdata lua_pushlightuserdata
#define luax_pushnil lua_pushnil
+#define luax_pushvalue lua_pushvalue
//inline void luax_pushuserdata(lua_State* L, void* p)
//{
@@ -168,6 +177,10 @@ inline char luax_getfieldbool(lua_State* L, int I, const char* N)
char bin = lua_toboolean(L, -1);
return bin;
}
+/**
+*
+*/
+#define luax_call lua_call
/**
* Set raw
@@ -270,6 +283,7 @@ inline int luax_istype(lua_State* L, int idx, const char* tname)
#define luax_istable(L, i) luax_is(table, L, i)
#define luax_isnil(L, i) luax_is(nil, L, i)
#define luax_isboolean(L, i) luax_is(boolean, L, i)
+#define luax_isfunction(L, i) luax_is(function, L, i)
#define luax_isuserdata lua_isuserdata
#define luax_islightuserdata lua_islightuserdata
inline int luax_isinteger(lua_State* L, int i)
@@ -417,7 +431,11 @@ inline void luax_setfieldnumbers(lua_State* L, const luax_Num* strs)
}
}
-typedef luaL_Reg luax_Ref;
+typedef luaL_Reg luax_Reg;
+
+#define luax_ref luaL_ref
+
+#define luax_unref luaL_unref
#endif // #if LUA_VERSION_NUM == 501
diff --git a/src/lua/main.cpp b/src/lua/main.cpp
deleted file mode 100644
index 95862ec..0000000
--- a/src/lua/main.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-#ifdef _WIN32
- #include <SDL2/SDL_Main.h>
- #include <direct.h>
-#endif
-
-#include "luax.h"
-#include "jin.h"
-#include "libjin/jin.h"
-#include <Windows.h>
-
-using namespace JinEngine::Lua;
-using namespace JinEngine::Filesystem;
-
-int main(int argc, char* argv[])
-{
- lua_State* L = luax_newstate();
-
- /* open lua standard module */
- luax_openlibs(L);
- /* open jin module */
- luaopen_jin(L);
- /* add args to field */
- luax_newtable(L);
- for (int i = 0; i < argc; ++i)
- luax_setrawstring(L, -2, i + 1, argv[i]);
- luax_setfield(L, -2, "args");
- /* push current working directory */
- /* absolute directory */
- Buffer cwd = Buffer(1024);
-#ifdef _WIN32
- _getcwd((char*)&cwd, cwd.size());
-#elif defined __unix__
-#elif defined __APPLE__
-#endif
- luax_setfieldstring(L, "cwd", (char*)&cwd);
- luax_clear(L);
-
- /* boot jin and run it */
- boot(L);
-
- luax_close(L);
-
- return 0;
-} \ No newline at end of file
diff --git a/src/lua/modules/ai/je_lua_ai.cpp b/src/lua/modules/ai/je_lua_ai.cpp
new file mode 100644
index 0000000..4afd625
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_ai.cpp
@@ -0,0 +1,13 @@
+#include "libjin/jin.h"
+
+using namespace JinEngine::AI;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/modules/ai/je_lua_ai.h b/src/lua/modules/ai/je_lua_ai.h
new file mode 100644
index 0000000..036bc3f
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_ai.h
@@ -0,0 +1,7 @@
+#ifndef __JE_LUA_AI_H__
+#define __JE_LUA_AI_H__
+
+#include "je_lua_behavior_tree.h"
+#include "je_lua_state_machine.h"
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/ai/je_lua_behavior_tree.cpp b/src/lua/modules/ai/je_lua_behavior_tree.cpp
new file mode 100644
index 0000000..20e8e55
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_behavior_tree.cpp
@@ -0,0 +1,11 @@
+#include "libjin/jin.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_BehaviorTree = "Texture";
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/modules/ai/je_lua_behavior_tree.h b/src/lua/modules/ai/je_lua_behavior_tree.h
new file mode 100644
index 0000000..083d12b
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_behavior_tree.h
@@ -0,0 +1,14 @@
+#ifndef __JE_LUA_BEHAVIOR_TREE_H__
+#define __JE_LUA_BEHAVIOR_TREE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_BehaviorTree;
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/ai/je_lua_state_machine.cpp b/src/lua/modules/ai/je_lua_state_machine.cpp
new file mode 100644
index 0000000..86ce7a5
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_state_machine.cpp
@@ -0,0 +1,25 @@
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+using namespace JinEngine::AI;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_StateMachine = "StateMachine";
+
+ LUA_IMPLEMENT int l_addEnterCallback(lua_State* L)
+ {
+ //StateMachine* sm;
+ //sm->addEnterListener("", [](void* p) -> void{
+
+ //
+ //});
+
+ return 0;
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/modules/ai/je_lua_state_machine.h b/src/lua/modules/ai/je_lua_state_machine.h
new file mode 100644
index 0000000..3c78f75
--- /dev/null
+++ b/src/lua/modules/ai/je_lua_state_machine.h
@@ -0,0 +1,14 @@
+#ifndef __JE_LUA_STATE_MACHINE_H__
+#define __JE_LUA_STATE_MACHINE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_StateMachine;
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/audio/audio.cpp b/src/lua/modules/audio/audio.cpp
deleted file mode 100644
index 198323d..0000000
--- a/src/lua/modules/audio/audio.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Audio;
- using namespace JinEngine::Filesystem;
-
- typedef SDLAudio Audio;
- typedef SDLSource Source;
-
- static int l_init(lua_State* L)
- {
- Audio::Setting setting;
- setting.samplerate = 44100;
- setting.samples = 44100;
- if (!Audio::get()->init(&setting))
- {
- luax_error(L, "could not init audio");
- luax_pushboolean(L, false);
- return 1;
- }
- luax_pushboolean(L, true);
- return 1;
- }
-
- static int l_play(lua_State* L)
- {
- Audio::get()->play();
- return 0;
- }
-
- static int l_stop(lua_State* L)
- {
- Audio::get()->stop();
- return 0;
- }
-
- static int l_pause(lua_State* L)
- {
- Audio::get()->pause();
- return 0;
- }
-
- static int l_resume(lua_State* L)
- {
- Audio::get()->resume();
- return 0;
- }
-
- static int l_setVolume(lua_State* L)
- {
- float volume = luax_checknumber(L, 1);
- Audio::get()->setVolume(volume);
- return 0;
- }
-
- static int l_newSource(lua_State* L)
- {
- AssetDatabase* fs = AssetDatabase::get();
- const char* f = luax_checkstring(L, 1);
- Buffer b;
- if (!fs->exists(f))
- {
- error(L, "No such image %s", f);
- goto fail;
- }
- if (!fs->read(f, b))
- {
- error(L, "Failed to read source file %s", f);
- goto fail;
- }
- Source* src = Source::createSource((void*)&b, b.size());
- if (src == nullptr)
- {
- error(L, "Failed to decode source file %s", f);
- goto fail;
- }
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_AUDIO_SOURCE, sizeof(Proxy));
- proxy->bind(new Ref<Source>(src, JIN_AUDIO_SOURCE));
- return 1;
- fail:
- luax_pushnil(L);
- return 1;
- }
-
- static int l_destroy(lua_State* L)
- {
- Audio* audio = Audio::get();
- audio->quit();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "init", l_init },
- { "play", l_play },
- { "stop", l_stop },
- { "pause", l_pause },
- { "resume", l_resume },
- { "setVolume", l_setVolume },
- { "newSource", l_newSource },
- { "destroy", l_destroy },
- { 0, 0 }
- };
-
- extern int luaopen_Source(lua_State* L);
-
- int luaopen_audio(lua_State* L)
- {
- luaopen_Source(L);
-
- luax_newlib(L, f);
-
- return 1;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/audio/je_lua_audio.cpp b/src/lua/modules/audio/je_lua_audio.cpp
new file mode 100644
index 0000000..50c5268
--- /dev/null
+++ b/src/lua/modules/audio/je_lua_audio.cpp
@@ -0,0 +1,135 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_source.h"
+
+using namespace JinEngine::Audio;
+using namespace JinEngine::Audio::SDL;
+using namespace JinEngine::Filesystem;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ typedef SDLAudio Audio;
+ typedef SDLSource Source;
+
+ struct
+ {
+ bool initialized = false;
+ } context;
+
+ LUA_IMPLEMENT int l_init(lua_State* L)
+ {
+ if (context.initialized)
+ {
+ // Already initialized.
+ luax_pushboolean(L, true);
+ return 1;
+ }
+ Audio::Setting setting;
+ setting.samplerate = 44100;
+ setting.samples = 44100;
+ context.initialized = Audio::get()->init(&setting);
+ if (!context.initialized)
+ {
+ luax_error(L, "could not init audio");
+ luax_pushboolean(L, false);
+ return 1;
+ }
+ luax_pushboolean(L, true);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_play(lua_State* L)
+ {
+ Audio::get()->play();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_stop(lua_State* L)
+ {
+ Audio::get()->stop();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_pause(lua_State* L)
+ {
+ Audio::get()->pause();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_resume(lua_State* L)
+ {
+ Audio::get()->resume();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setVolume(lua_State* L)
+ {
+ float volume = luax_checknumber(L, 1);
+ Audio::get()->setVolume(volume);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_newSource(lua_State* L)
+ {
+ AssetDatabase* fs = AssetDatabase::get();
+ const char* f = luax_checkstring(L, 1);
+ Buffer b;
+ try
+ {
+ if (!fs->exists(f))
+ throw Exception("No such source file %s.", f);
+ fs->read(f, b);
+ }
+ catch (Exception& e)
+ {
+ error(L, "Failed to read source file %s", f);
+ luax_pushnil(L);
+ return 1;
+ }
+ Source* src = Source::createSource((void*)&b, b.size());
+ if (src == nullptr)
+ {
+ error(L, "Failed to decode source file %s", f);
+ luax_pushnil(L);
+ return 1;
+ }
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Source);
+ proxy->bind(new Shared<Source>(src, Jin_Lua_Source));
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_destroy(lua_State* L)
+ {
+ Audio* audio = Audio::get();
+ audio->quit();
+ return 0;
+ }
+
+ LUA_EXPORT int luaopen_audio(lua_State* L)
+ {
+ luaopen_Source(L);
+
+ luaL_Reg f[] = {
+ { "init", l_init },
+ { "play", l_play },
+ { "stop", l_stop },
+ { "pause", l_pause },
+ { "resume", l_resume },
+ { "setVolume", l_setVolume },
+ { "newSource", l_newSource },
+ { "destroy", l_destroy },
+ { 0, 0 }
+ };
+
+ luax_newlib(L, f);
+
+ return 1;
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/audio/je_lua_audio.h b/src/lua/modules/audio/je_lua_audio.h
new file mode 100644
index 0000000..fa66392
--- /dev/null
+++ b/src/lua/modules/audio/je_lua_audio.h
@@ -0,0 +1,6 @@
+#ifndef __JE_LUA_AUDIO_H__
+#define __JE_LUA_AUDIO_H__
+
+#include "je_lua_audio.h"
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/audio/je_lua_source.cpp b/src/lua/modules/audio/je_lua_source.cpp
new file mode 100644
index 0000000..e152847
--- /dev/null
+++ b/src/lua/modules/audio/je_lua_source.cpp
@@ -0,0 +1,117 @@
+#include "libjin/jin.h"
+#include "lua/modules/luax.h"
+#include "lua/common/je_lua_common.h"
+
+
+using namespace JinEngine::Audio;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Source = "Source";
+
+ typedef Shared<Source>& SharedSource;
+
+ LUA_IMPLEMENT inline SharedSource checkSource(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Source);
+ return proxy->getShared<Source>();
+ }
+
+ LUA_IMPLEMENT int l_play(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ shared->play();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_stop(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ shared->stop();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_pause(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ shared->pause();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_rewind(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ shared->rewind();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_resume(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ shared->resume();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_isStop(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ bool isStop = shared->isStopped();
+ luax_pushboolean(L, isStop);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_isPaused(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ bool isPaused = shared->isPaused();
+ luax_pushboolean(L, isPaused);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_setVolume(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ float volume = luax_checknumber(L, 2);
+ shared->setVolume(volume);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setLoop(lua_State* L)
+ {
+ SharedSource shared = checkSource(L);
+ bool loop = luax_checkbool(L, 2);
+ shared->setLoop(loop);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Source);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Source(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "play", l_play },
+ { "stop", l_stop },
+ { "pause", l_pause },
+ { "resume", l_resume },
+ { "rewind", l_rewind },
+ { "isStop", l_isStop },
+ { "isPaused", l_isPaused },
+ { "setVolume", l_setVolume },
+ { "setLoop", l_setLoop },
+ { 0, 0 }
+ };
+
+ luax_newtype(L, Jin_Lua_Source, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/audio/je_lua_source.h b/src/lua/modules/audio/je_lua_source.h
new file mode 100644
index 0000000..f7e6b48
--- /dev/null
+++ b/src/lua/modules/audio/je_lua_source.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_SOURCE_H__
+#define __JE_LUA_SOURCE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Source;
+
+ void luaopen_Source(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/audio/source.cpp b/src/lua/modules/audio/source.cpp
deleted file mode 100644
index bf43ceb..0000000
--- a/src/lua/modules/audio/source.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-#include "libjin/jin.h"
-#include "lua/modules/luax.h"
-#include "lua/common/common.h"
-#include "lua/modules/types.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Audio;
-
- typedef Ref<Source>& SourceRef;
-
- static inline SourceRef checkSource(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_AUDIO_SOURCE);
- return proxy->getRef<Source>();
- }
-
- static int l_play(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->play();
- return 0;
- }
-
- static int l_stop(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->stop();
- return 0;
- }
-
- static int l_pause(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->pause();
- return 0;
- }
-
- static int l_rewind(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->rewind();
- return 0;
- }
-
- static int l_resume(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- ref->resume();
- return 0;
- }
-
- static int l_isStop(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- bool isStop = ref->isStopped();
- luax_pushboolean(L, isStop);
- return 1;
- }
-
- static int l_isPaused(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- bool isPaused = ref->isPaused();
- luax_pushboolean(L, isPaused);
- return 1;
- }
-
- static int l_setVolume(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- float volume = luax_checknumber(L, 2);
- ref->setVolume(volume);
- return 0;
- }
-
- static int l_setLoop(lua_State* L)
- {
- SourceRef ref = checkSource(L);
- bool loop = luax_checkbool(L, 2);
- ref->setLoop(loop);
- return 0;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_AUDIO_SOURCE);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "play", l_play },
- { "stop", l_stop },
- { "pause", l_pause },
- { "resume", l_resume },
- { "rewind", l_rewind },
- { "isStop", l_isStop },
- { "isPaused", l_isPaused },
- { "setVolume", l_setVolume },
- { "setLoop", l_setLoop },
- { 0, 0 }
- };
-
- int luaopen_Source(lua_State* L)
- {
- luax_newtype(L, JIN_AUDIO_SOURCE, f);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/bit/bit.cpp b/src/lua/modules/bit/je_lua_bit.cpp
index cedd60a..fdd0ae0 100644
--- a/src/lua/modules/bit/bit.cpp
+++ b/src/lua/modules/bit/je_lua_bit.cpp
@@ -1,5 +1,7 @@
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
#include "libjin/jin.h"
+
#include <cstdlib>
namespace JinEngine
@@ -7,7 +9,7 @@ namespace JinEngine
namespace Lua
{
- static int l_and(lua_State* L)
+ LUA_IMPLEMENT int l_and(lua_State* L)
{
int a = luax_checkinteger(L, 1);
int b = luax_checkinteger(L, 2);
@@ -15,7 +17,7 @@ namespace JinEngine
return 1;
}
- static int l_or(lua_State* L)
+ LUA_IMPLEMENT int l_or(lua_State* L)
{
int a = luax_checkinteger(L, 1);
int b = luax_checkinteger(L, 2);
@@ -23,7 +25,7 @@ namespace JinEngine
return 1;
}
- static int l_xor(lua_State* L)
+ LUA_IMPLEMENT int l_xor(lua_State* L)
{
int a = luax_checkinteger(L, 1);
int b = luax_checkinteger(L, 2);
@@ -31,14 +33,14 @@ namespace JinEngine
return 1;
}
- static int l_not(lua_State* L)
+ LUA_IMPLEMENT int l_not(lua_State* L)
{
int n = luax_checkinteger(L, 1);
luax_pushinteger(L, ~n);
return 1;
}
- static int l_lshift(lua_State* L)
+ LUA_IMPLEMENT int l_lshift(lua_State* L)
{
int a = luax_checkinteger(L, 1);
int b = luax_checkinteger(L, 2);
@@ -46,7 +48,7 @@ namespace JinEngine
return 1;
}
- static int l_rshift(lua_State* L)
+ LUA_IMPLEMENT int l_rshift(lua_State* L)
{
int a = luax_checkinteger(L, 1);
int b = luax_checkinteger(L, 2);
@@ -54,7 +56,7 @@ namespace JinEngine
return 1;
}
- static int l_include(lua_State* L)
+ LUA_IMPLEMENT int l_include(lua_State* L)
{
int a = luax_checkinteger(L, 1);
int b = luax_checkinteger(L, 2);
@@ -62,19 +64,20 @@ namespace JinEngine
return 1;
}
- static const luaL_Reg f[] = {
- { "bAnd", l_and },
- { "bOr" , l_or },
- { "bXor", l_xor },
- { "bNot", l_not },
- { "bLs", l_lshift },
- { "bRs", l_rshift },
- { "bInc", l_include },
- { 0, 0 }
- };
-
- int luaopen_bit(lua_State* L)
+
+ LUA_EXPORT int luaopen_bit(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "bAnd", l_and },
+ { "bOr" , l_or },
+ { "bXor", l_xor },
+ { "bNot", l_not },
+ { "bLs", l_lshift },
+ { "bRs", l_rshift },
+ { "bInc", l_include },
+ { 0, 0 }
+ };
+
luax_newlib(L, f);
return 1;
diff --git a/src/libjin/Graphics/particle/je_particle_system.h b/src/lua/modules/bit/je_lua_bit.h
index e69de29..e69de29 100644
--- a/src/libjin/Graphics/particle/je_particle_system.h
+++ b/src/lua/modules/bit/je_lua_bit.h
diff --git a/src/lua/modules/core/core.cpp b/src/lua/modules/core/core.cpp
deleted file mode 100644
index a576bec..0000000
--- a/src/lua/modules/core/core.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-#include "lua/modules/luax.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Core;
-
- static int l_running(lua_State* L)
- {
- static Game* game = Game::get();
- bool running = game->running();
- luax_pushboolean(L, running);
- return 1;
- }
-
- static int l_stop(lua_State* L)
- {
- Game::get()->stop();
- return 0;
- }
-
- static int l_quit(lua_State* L)
- {
- Game::get()->quit();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "running", l_running },
- { "stop", l_stop },
- { "quit", l_quit },
- { 0, 0 }
- };
-
- int luaopen_core(lua_State* L)
- {
- luax_newlib(L, f);
-
- return 1;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/core/je_lua_core.cpp b/src/lua/modules/core/je_lua_core.cpp
new file mode 100644
index 0000000..f5b06c3
--- /dev/null
+++ b/src/lua/modules/core/je_lua_core.cpp
@@ -0,0 +1,46 @@
+#include "lua/common/je_lua_common.h"
+#include "lua/modules/luax.h"
+#include "libjin/jin.h"
+
+using namespace JinEngine::Game;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ LUA_IMPLEMENT int l_running(lua_State* L)
+ {
+ static Application* app = Application::get();
+ bool running = app->running();
+ luax_pushboolean(L, running);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_stop(lua_State* L)
+ {
+ Application::get()->stop();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_quit(lua_State* L)
+ {
+ Application::get()->quit();
+ return 0;
+ }
+
+ LUA_EXPORT int luaopen_core(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "running", l_running },
+ { "stop", l_stop },
+ { "quit", l_quit },
+ { 0, 0 }
+ };
+ luax_newlib(L, f);
+
+ return 1;
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/core/je_lua_core.h b/src/lua/modules/core/je_lua_core.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/core/je_lua_core.h
diff --git a/src/lua/modules/event/event.cpp b/src/lua/modules/event/je_lua_event.cpp
index 9f565d0..82ba385 100644
--- a/src/lua/modules/event/event.cpp
+++ b/src/lua/modules/event/je_lua_event.cpp
@@ -1,21 +1,22 @@
/**
* Event module
*/
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
#include "libjin/jin.h"
+using namespace JinEngine;
+using namespace JinEngine::Input;
+
namespace JinEngine
{
namespace Lua
{
- using namespace JinEngine;
- using namespace JinEngine::Input;
-
/**
* Load event poll, return a iterator(a table).
*/
- static int l_event_poll(lua_State *L)
+ LUA_IMPLEMENT int l_event_poll(lua_State *L)
{
/* table to store events */
luax_newtable(L);
@@ -100,10 +101,9 @@ namespace JinEngine
case EventType::CONTROLLERAXISMOTION:
-
default:
- /* ignore other events */
- luax_pop(L, 1); // pop table out
+ // Ignore oter events and pop up the event table.
+ luax_pop(L, 1);
goto poll;
break;
}
@@ -111,18 +111,18 @@ namespace JinEngine
}
return 1;
}
-
- static const luaL_Reg f[] = {
- { "poll", l_event_poll },
- { 0, 0 }
- };
/**
* load event module
*/
- int luaopen_event(lua_State* L)
+ LUA_EXPORT int luaopen_event(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "poll", l_event_poll },
+ { 0, 0 }
+ };
luax_newlib(L, f);
+
return 1;
}
diff --git a/src/lua/modules/event/je_lua_event.h b/src/lua/modules/event/je_lua_event.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/event/je_lua_event.h
diff --git a/src/lua/modules/filesystem/filesystem.cpp b/src/lua/modules/filesystem/je_lua_filesystem.cpp
index 7466ce8..6245ba8 100644
--- a/src/lua/modules/filesystem/filesystem.cpp
+++ b/src/lua/modules/filesystem/je_lua_filesystem.cpp
@@ -1,3 +1,4 @@
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
#include "libjin/jin.h"
#include <string>
@@ -9,25 +10,25 @@ namespace JinEngine
namespace Lua
{
- static struct
+ LUA_IMPLEMENT struct
{
AssetDatabase* fs;
} context;
- static int l_init(lua_State* L)
+ LUA_IMPLEMENT int l_init(lua_State* L)
{
context.fs = AssetDatabase::get();
return 0;
}
- static int l_mount(lua_State* L)
+ LUA_IMPLEMENT int l_mount(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
context.fs->mount(path);
return 0;
}
- static int l_exist(lua_State * L)
+ LUA_IMPLEMENT int l_exist(lua_State * L)
{
const char* path = luax_checkstring(L, 1);
int r = context.fs->exists(path);
@@ -35,7 +36,7 @@ namespace JinEngine
return 1;
}
- static int l_isDir(lua_State* L)
+ LUA_IMPLEMENT int l_isDir(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
int r = context.fs->isDir(path);
@@ -43,7 +44,7 @@ namespace JinEngine
return 1;
}
- static int l_isFile(lua_State* L)
+ LUA_IMPLEMENT int l_isFile(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
int r = context.fs->isFile(path);
@@ -51,7 +52,7 @@ namespace JinEngine
return 1;
}
- static int loadbuffer(lua_State* L)
+ LUA_IMPLEMENT int loadbuffer(lua_State* L)
{
const char* filename = lua_tostring(L, -1);
Buffer bf;
@@ -60,7 +61,7 @@ namespace JinEngine
return 1;
}
- static int loader(lua_State* L)
+ LUA_IMPLEMENT int loader(lua_State* L)
{
const char * filename = lua_tostring(L, -1);
@@ -107,7 +108,7 @@ namespace JinEngine
return 1;
}
- static int l_read(lua_State* L)
+ LUA_IMPLEMENT int l_read(lua_State* L)
{
AssetDatabase* fs = context.fs;
const char* file = luax_checkstring(L, 1);
@@ -119,20 +120,20 @@ namespace JinEngine
return 2;
}
- static const luaL_Reg f[] = {
- { "init", l_init },
- { "mount", l_mount },
- { "isDirectory", l_isDir },
- { "isFile", l_isFile },
- { "exist", l_exist },
- { "read", l_read },
- { 0, 0 }
- };
-
- int luaopen_filesystem(lua_State* L)
+ LUA_EXPORT int luaopen_filesystem(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "init", l_init },
+ { "mount", l_mount },
+ { "isDirectory", l_isDir },
+ { "isFile", l_isFile },
+ { "exist", l_exist },
+ { "read", l_read },
+ { 0, 0 }
+ };
luax_newlib(L, f);
luax_registersearcher(L, loader, 1);
+
return 0;
}
diff --git a/src/lua/modules/filesystem/je_lua_filesystem.h b/src/lua/modules/filesystem/je_lua_filesystem.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/filesystem/je_lua_filesystem.h
diff --git a/src/lua/modules/graphics/bitmap.cpp b/src/lua/modules/graphics/bitmap.cpp
deleted file mode 100644
index 13517f9..0000000
--- a/src/lua/modules/graphics/bitmap.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- typedef Ref<Bitmap>& BitmapRef;
-
- static inline BitmapRef checkBitmap(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_BITMAP);
- return proxy->getRef<Bitmap>();
- }
-
- static int l_gc(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- ref.release();
- return 0;
- }
-
- static int l_getWidth(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- int w = ref->getWidth();
- luax_pushinteger(L, w);
- return 1;
- }
-
- static int l_getHeight(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- int h = ref->getHeight();
- luax_pushinteger(L, h);
- return 1;
- }
-
- static int l_getSize(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- int w = ref->getWidth();
- int h = ref->getHeight();
- luax_pushinteger(L, w);
- luax_pushinteger(L, h);
- return 2;
- }
-
- static int l_getPixel(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- int x = luax_checkinteger(L, 2);
- int y = luax_checkinteger(L, 3);
- Color col = ref->getPixel(x, y);
- luax_pushinteger(L, col.r);
- luax_pushinteger(L, col.g);
- luax_pushinteger(L, col.b);
- luax_pushinteger(L, col.a);
- return 4;
- }
-
- static int l_setPixel(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- int x = luax_checkinteger(L, 2);
- int y = luax_checkinteger(L, 3);
- if (!luax_istable(L, 4))
- {
- luax_typerror(L, 4, "table");
- return 1;
- }
- unsigned int r = luax_rawgetnumber(L, 4, 1);
- unsigned int g = luax_rawgetnumber(L, 4, 2);
- unsigned int b = luax_rawgetnumber(L, 4, 3);
- unsigned int a = luax_rawgetnumber(L, 4, 4);
- ref->setPixel(Color(r, g, b, a), x, y);
- return 0;
- }
-
- static int l_clone(lua_State* L)
- {
- BitmapRef ref = checkBitmap(L);
- Bitmap* bitmap = ref.getObject();
- Bitmap* b = Bitmap::clone(bitmap);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_BITMAP, sizeof(Proxy));
- proxy->bind(new Ref<Bitmap>(b, JIN_GRAPHICS_BITMAP));
- return 1;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "getSize", l_getSize },
- { "getPixel", l_getPixel },
- { "setPixel", l_setPixel },
- { "clone", l_clone },
- { 0, 0 }
- };
-
- int luaopen_Bitmap(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_BITMAP, f);
- return 0;
- }
-
- } // graphics
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/canvas.cpp b/src/lua/modules/graphics/canvas.cpp
deleted file mode 100644
index e49e209..0000000
--- a/src/lua/modules/graphics/canvas.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- typedef Ref<Canvas>& CanvasRef;
-
- static inline CanvasRef checkCanvas(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_CANVAS);
- return proxy->getRef<Canvas>();
- }
-
- static int l_getWidth(lua_State* L)
- {
- CanvasRef ref = checkCanvas(L);
- luax_pushnumber(L, ref->getWidth());
- return 1;
- }
-
- static int l_getHeight(lua_State* L)
- {
- CanvasRef ref = checkCanvas(L);
- luax_pushnumber(L, ref->getHeight());
- return 1;
- }
-
- static int l_getSize(lua_State* L)
- {
- CanvasRef ref = checkCanvas(L);
- luax_pushnumber(L, ref->getWidth());
- luax_pushnumber(L, ref->getHeight());
- return 2;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_CANVAS);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "getSize", l_getSize },
- { 0, 0 }
- };
-
- int luaopen_Canvas(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_CANVAS, f);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_bitmap.cpp b/src/lua/modules/graphics/je_lua_bitmap.cpp
new file mode 100644
index 0000000..6b7655f
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_bitmap.cpp
@@ -0,0 +1,114 @@
+#include "lua/common/je_lua_common.h"
+#include "lua/modules/luax.h"
+
+#include "libjin/jin.h"
+#include "je_lua_bitmap.h"
+
+using namespace JinEngine::Graphics;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Bitmap = "Bitmap";
+
+ typedef Shared<Bitmap>& SharedBitmap;
+
+ LUA_IMPLEMENT inline SharedBitmap checkBitmap(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Bitmap);
+ return proxy->getShared<Bitmap>();
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ shared.release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ int w = shared->getWidth();
+ luax_pushinteger(L, w);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getHeight(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ int h = shared->getHeight();
+ luax_pushinteger(L, h);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ int w = shared->getWidth();
+ int h = shared->getHeight();
+ luax_pushinteger(L, w);
+ luax_pushinteger(L, h);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_getPixel(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ int x = luax_checkinteger(L, 2);
+ int y = luax_checkinteger(L, 3);
+ Color col = shared->getPixel(x, y);
+ luax_pushinteger(L, col.r);
+ luax_pushinteger(L, col.g);
+ luax_pushinteger(L, col.b);
+ luax_pushinteger(L, col.a);
+ return 4;
+ }
+
+ LUA_IMPLEMENT int l_setPixel(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ int x = luax_checkinteger(L, 2);
+ int y = luax_checkinteger(L, 3);
+ if (!luax_istable(L, 4))
+ {
+ luax_typerror(L, 4, "table");
+ return 1;
+ }
+ unsigned int r = luax_rawgetnumber(L, 4, 1);
+ unsigned int g = luax_rawgetnumber(L, 4, 2);
+ unsigned int b = luax_rawgetnumber(L, 4, 3);
+ unsigned int a = luax_rawgetnumber(L, 4, 4);
+ shared->setPixel(Color(r, g, b, a), x, y);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_clone(lua_State* L)
+ {
+ SharedBitmap shared = checkBitmap(L);
+ Bitmap* bitmap = shared.getObject();
+ Bitmap* b = Bitmap::clone(bitmap);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Bitmap);
+ proxy->bind(new Shared<Bitmap>(b, Jin_Lua_Bitmap));
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_Bitmap(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "getSize", l_getSize },
+ { "getPixel", l_getPixel },
+ { "setPixel", l_setPixel },
+ { "clone", l_clone },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Bitmap, f);
+ }
+
+ } // namespace Graphics
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_bitmap.h b/src/lua/modules/graphics/je_lua_bitmap.h
new file mode 100644
index 0000000..b463d83
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_bitmap.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_BITMAP_H__
+#define __JE_LUA_BITMAP_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Bitmap;
+
+ void luaopen_Bitmap(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_canvas.cpp b/src/lua/modules/graphics/je_lua_canvas.cpp
new file mode 100644
index 0000000..f7bd650
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_canvas.cpp
@@ -0,0 +1,66 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_canvas.h"
+
+using namespace JinEngine::Graphics;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Canvas = "Canvas";
+
+ typedef Shared<Canvas>& SharedCanvas;
+
+ LUA_IMPLEMENT inline SharedCanvas checkCanvas(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Canvas);
+ return proxy->getShared<Canvas>();
+ }
+
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
+ {
+ SharedCanvas shared = checkCanvas(L);
+ luax_pushnumber(L, shared->getWidth());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getHeight(lua_State* L)
+ {
+ SharedCanvas shared = checkCanvas(L);
+ luax_pushnumber(L, shared->getHeight());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
+ {
+ SharedCanvas shared = checkCanvas(L);
+ luax_pushnumber(L, shared->getWidth());
+ luax_pushnumber(L, shared->getHeight());
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Canvas);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Canvas(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "getSize", l_getSize },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Canvas, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_canvas.h b/src/lua/modules/graphics/je_lua_canvas.h
new file mode 100644
index 0000000..d1fa885
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_canvas.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_CANVAS_H__
+#define __JE_LUA_CANVAS_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Canvas;
+
+ void luaopen_Canvas(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp
index 8b2d7cd..ce569d0 100644
--- a/src/lua/modules/graphics/graphics.cpp
+++ b/src/lua/modules/graphics/je_lua_graphics.cpp
@@ -3,14 +3,27 @@
#include "libjin/jin.h"
#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
+
+#include "lua/common/je_lua_common.h"
+
+#include "je_lua_canvas.h"
+#include "je_lua_sprite.h"
+#include "je_lua_spritesheet.h"
+#include "je_lua_bitmap.h"
+#include "je_lua_ttf.h"
+#include "je_lua_ttf_data.h"
+#include "je_lua_texture.h"
+#include "je_lua_shader.h"
+#include "je_lua_text.h"
+#include "je_lua_texture_font.h"
+#include "je_lua_page.h"
using namespace std;
using namespace JinEngine;
using namespace JinEngine::Graphics;
-using JinEngine::Filesystem::AssetDatabase;
-using JinEngine::Filesystem::Buffer;
+using namespace JinEngine::Graphics::Fonts;
+using namespace JinEngine::Graphics::Shaders;
+using namespace JinEngine::Filesystem;
namespace JinEngine
{
@@ -18,59 +31,52 @@ namespace JinEngine
{
#include "../../resources/font.ttf.h"
-
+
static struct
{
Color curRenderColor;
Color curClearColor;
Font* curFont = nullptr;
Font* defaultFont = nullptr;
+ bool initialized = false;
} context;
- static int l_init(lua_State* L)
+ LUA_IMPLEMENT int l_init(lua_State* L)
{
+ if (context.initialized)
+ {
+ luax_pushboolean(L, true);
+ return 1;
+ }
+
Window* wnd = Window::get();
Window::Setting setting;
setting.width = luax_getfieldinteger(L, 1, "width");
setting.height = luax_getfieldinteger(L, 1, "height");
setting.title = luax_getfieldstring(L, 1, "title");
+ setting.icon = luax_getfieldstring(L, 1, "icon");
setting.vsync = luax_getfieldbool(L, 1, "vsync");
setting.fullscreen = luax_getfieldbool(L, 1, "fullscreen");
setting.resizable = luax_getfieldbool(L, 1, "resizable");
- if (!wnd->init(&setting))
+ context.initialized = wnd->init(&setting);
+ if (!context.initialized)
{
- luax_pushboolean(L, false);
+ luax_pushboolean(L, context.initialized);
return 1;
}
- {
- /* load default font */
- Bitmap* bitmap = Bitmap::createBitmap(default_font_bitmap, sizeof(default_font_bitmap));
- const Color* pixels = bitmap->getPixels();
- ofstream f = ofstream();
- f.open("font.pixels", ios_base::app);
- for (int y = 0; y < bitmap->getHeight(); ++y)
- {
- for (int x = 0; x < bitmap->getWidth(); ++x)
- {
- Color c = pixels[x + y * bitmap->getWidth()];
- f << (int)c.r << ",";
- f << (int)c.g << ",";
- f << (int)c.b << ",";
- f << (int)c.a << ",";
- }
- }
-
- TextureFont* tf = TextureFont::createTextureFont(bitmap, Text(Encode::UTF8, default_charset), default_font_split, bitmap->getHeight());
- context.defaultFont = tf;
- delete bitmap;
- }
- context.curFont = context.defaultFont;
-
- luax_pushboolean(L, true);
+
+ /* load default font */
+ Bitmap* bitmap = Bitmap::createBitmap(default_font_bitmap, sizeof(default_font_bitmap));
+ TextureFont* tf = TextureFont::createTextureFont(bitmap, Text(Encode::UTF8, default_charset), default_font_split, bitmap->getHeight());
+ delete bitmap;
+ context.defaultFont = tf;
+ context.curFont = tf;
+
+ luax_pushboolean(L, context.initialized);
return 1;
}
- static int l_setTitle(lua_State* L)
+ LUA_IMPLEMENT int l_setTitle(lua_State* L)
{
Window* wnd = Window::get();
const char* title = luax_checkstring(L, 1);
@@ -78,14 +84,28 @@ namespace JinEngine
return 0;
}
- static int l_destroy(lua_State* L)
+ LUA_IMPLEMENT int l_destroy(lua_State* L)
{
Window* wnd = Window::get();
wnd->quit();
return 0;
}
-
- static int l_getSize(lua_State* L)
+
+ LUA_IMPLEMENT int l_showWindow(lua_State* L)
+ {
+ Window* wnd = Window::get();
+ wnd->show();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_hideWindow(lua_State* L)
+ {
+ Window* wnd = Window::get();
+ wnd->hide();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
{
Window* wnd = Window::get();
luax_pushnumber(L, wnd->getW());
@@ -93,21 +113,21 @@ namespace JinEngine
return 2;
}
- static int l_getWidth(lua_State* L)
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
{
Window* wnd = Window::get();
luax_pushnumber(L, wnd->getW());
return 1;
}
- static int l_getHeight(lua_State* L)
+ LUA_IMPLEMENT int l_getHeight(lua_State* L)
{
Window* wnd = Window::get();
luax_pushnumber(L, wnd->getH());
return 1;
}
- static int l_newBitmap(lua_State* L)
+ LUA_IMPLEMENT int l_newBitmap(lua_State* L)
{
Bitmap* bitmap = nullptr;
if (luax_gettop(L) == 2)
@@ -120,55 +140,82 @@ namespace JinEngine
{
int w = luax_checkinteger(L, 1);
int h = luax_checkinteger(L, 2);
- if (!luax_istable(L, 3))
+ if (luax_istable(L, 3))
{
- luax_typerror(L, 3, "table");
+ unsigned int r = luax_rawgetnumber(L, 3, 1);
+ unsigned int g = luax_rawgetnumber(L, 3, 2);
+ unsigned int b = luax_rawgetnumber(L, 3, 3);
+ unsigned int a = luax_rawgetnumber(L, 3, 4);
+ bitmap = Bitmap::createBitmap(w, h, Color(r, g, b, a));
+ }
+ else if (luax_isfunction(L, 3))
+ {
+ std::function<Color(int, int, int, int)> drawer = [=](int w, int h, int x, int y)->Color{
+ luax_pushvalue(L, 3);
+ luax_pushnumber(L, w);
+ luax_pushnumber(L, h);
+ luax_pushnumber(L, x);
+ luax_pushnumber(L, y);
+ // Call drawer function.
+ luax_call(L, 4, 1);
+ // Get result color.
+ if (!luax_istable(L, -1))
+ luax_error(L, "Return value of bitmap drawer is wrong, should be a color table.");
+ Color c;
+ c.r = luax_rawgetnumberthenpop(L, -1, 1);
+ c.g = luax_rawgetnumberthenpop(L, -1, 2);
+ c.b = luax_rawgetnumberthenpop(L, -1, 3);
+ c.a = luax_rawgetnumberthenpop(L, -1, 4);
+ // Pop return value.
+ luax_pop(L, 1);
+ return c;
+ };
+ bitmap = Bitmap::createBitmap(w, h, drawer);
+ }
+ else
+ {
+ luax_typerror(L, 3, "color table or color setter");
return 1;
}
- unsigned int r = luax_rawgetnumber(L, 3, 1);
- unsigned int g = luax_rawgetnumber(L, 3, 2);
- unsigned int b = luax_rawgetnumber(L, 3, 3);
- unsigned int a = luax_rawgetnumber(L, 3, 4);
- bitmap = Bitmap::createBitmap(w, h, Color(r, g, b, a));
}
else
{
const char* f = luax_checkstring(L, 1);
AssetDatabase* fs = AssetDatabase::get();
- if (!fs->exists(f))
+ Buffer b;
+ try
{
- error(L, "No such image file %s", f);
- goto fail;
+ if (!fs->exists(f))
+ throw Exception("No such image file %s.", f);
+ fs->read(f, b);
}
- Buffer b;
- if (!fs->read(f, b))
+ catch (Exception& e)
{
error(L, "Failed to read image %s", f);
- goto fail;
+ luax_pushnil(L);
+ return 1;
}
bitmap = Bitmap::createBitmap(&b, b.size());
if (bitmap == nullptr)
{
error(L, "Failed to decode image file %s", f);
- goto fail;
+ luax_pushnil(L);
+ return 1;
}
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_BITMAP, sizeof(Proxy));
- proxy->bind(new Ref<Bitmap>(bitmap, JIN_GRAPHICS_BITMAP));
- return 1;
- fail:
- luax_pushnil(L);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Bitmap);
+ proxy->bind(new Shared<Bitmap>(bitmap, Jin_Lua_Bitmap));
return 1;
}
/* jin.graphics.newTexture(bitmap) */
- static int l_newTexture(lua_State* L)
+ LUA_IMPLEMENT int l_newTexture(lua_State* L)
{
Texture* texture = nullptr;
- if (luax_istype(L, 1, JIN_GRAPHICS_BITMAP))
+ if (luax_istype(L, 1, Jin_Lua_Bitmap))
{
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_BITMAP);
- Ref<Bitmap>& refBitmap = p->getRef<Bitmap>();
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Bitmap);
+ Shared<Bitmap>& refBitmap = p->getShared<Bitmap>();
Bitmap* bitmap = refBitmap.getObject();
texture = Texture::createTexture(bitmap);
}
@@ -177,12 +224,12 @@ namespace JinEngine
const char* path = luax_checkstring(L, 1);
texture = Texture::createTexture(path);
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXTURE, sizeof(Proxy));
- proxy->bind(new Ref<Texture>(texture, JIN_GRAPHICS_TEXTURE));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Texture);
+ proxy->bind(new Shared<Texture>(texture, Jin_Lua_Texture));
return 1;
}
- static int l_newShader(lua_State* L)
+ LUA_IMPLEMENT int l_newShader(lua_State* L)
{
const char* program = luax_checkstring(L, 1);
Shader* jsl = Shader::createShader(program);
@@ -192,18 +239,18 @@ namespace JinEngine
luax_pushnil(L);
return 1;
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_SHADER, sizeof(Proxy));
- proxy->bind(new Ref<Shader>(jsl, JIN_GRAPHICS_SHADER));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Shader);
+ proxy->bind(new Shared<Shader>(jsl, Jin_Lua_Shader));
return 1;
}
- static int l_newShaderf(lua_State* L)
+ LUA_IMPLEMENT int l_newShaderf(lua_State* L)
{
const char* path = luax_checkstring(L, 1);
AssetDatabase* fs = AssetDatabase::get();
if (!fs->exists(path))
{
- error(L, "No such shader file %s\n", path);
+ error(L, "No such shader file \"%s\"", path);
luax_pushnil(L);
return 1;
}
@@ -216,28 +263,28 @@ namespace JinEngine
luax_pushnil(L);
return 1;
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_SHADER, sizeof(Proxy));
- proxy->bind(new Ref<Shader>(jsl, JIN_GRAPHICS_SHADER));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Shader);
+ proxy->bind(new Shared<Shader>(jsl, Jin_Lua_Shader));
return 1;
}
- static int l_newCanvas(lua_State* L)
+ LUA_IMPLEMENT int l_newCanvas(lua_State* L)
{
int w = luax_checknumber(L, 1);
int h = luax_checknumber(L, 2);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_CANVAS, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Canvas);
Canvas* cvs = Canvas::createCanvas(w, h);
- proxy->bind(new Ref<Canvas>(cvs, JIN_GRAPHICS_CANVAS));
+ proxy->bind(new Shared<Canvas>(cvs, Jin_Lua_Canvas));
return 1;
}
- static int l_clear(lua_State* L)
+ LUA_IMPLEMENT int l_clear(lua_State* L)
{
glClear(GL_COLOR_BUFFER_BIT);
return 0;
}
- static int l_setClearColor(lua_State* L)
+ LUA_IMPLEMENT int l_setClearColor(lua_State* L)
{
if (luax_gettop(L) == 0)
{
@@ -257,15 +304,15 @@ namespace JinEngine
return 0;
}
- static int l_present(lua_State* L)
+ LUA_IMPLEMENT int l_present(lua_State* L)
{
Window::get()->swapBuffers();
return 0;
}
- static void l_draw_texture(lua_State* L)
+ LUA_IMPLEMENT void l_draw_texture(lua_State* L)
{
- if (!luax_istype(L, 1, JIN_GRAPHICS_TEXTURE))
+ if (!luax_istype(L, 1, Jin_Lua_Texture))
return;
int x = luax_optnumber(L, 2, 0);
int y = luax_optnumber(L, 3, 0);
@@ -275,13 +322,13 @@ namespace JinEngine
float ox = luax_optnumber(L, 7, 0);
float oy = luax_optnumber(L, 8, 0);
Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Texture>& tex = proxy->getRef<Texture>();
- tex->draw(x, y, sx, sy, r, ox, oy);
+ Shared<Texture>& tex = proxy->getShared<Texture>();
+ tex->render(x, y, sx, sy, r, ox, oy);
}
- static void l_draw_canvas(lua_State* L)
+ LUA_IMPLEMENT void l_draw_canvas(lua_State* L)
{
- if (!luax_istype(L, 1, JIN_GRAPHICS_CANVAS))
+ if (!luax_istype(L, 1, Jin_Lua_Canvas))
return;
int x = luax_optnumber(L, 2, 0);
int y = luax_optnumber(L, 3, 0);
@@ -291,14 +338,14 @@ namespace JinEngine
float ox = luax_optnumber(L, 7, 0);
float oy = luax_optnumber(L, 8, 0);
Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Canvas>& p = proxy->getRef<Canvas>();
- p->draw(x, y, sx, sy, r, ox, oy);
+ Shared<Canvas>& p = proxy->getShared<Canvas>();
+ p->render(x, y, sx, sy, r, ox, oy);
}
/* jin.graphics.draw(text, font, x, y) */
- static void l_draw_text(lua_State* L)
+ LUA_IMPLEMENT void l_draw_text(lua_State* L)
{
- if (!luax_istype(L, 1, JIN_GRAPHICS_TEXT))
+ if (!luax_istype(L, 1, Jin_Lua_Text))
return;
Proxy* p = (Proxy*)luax_toudata(L, 1);
Text* text = p->getObject<Text>();
@@ -307,12 +354,12 @@ namespace JinEngine
int spacing = luax_optnumber(L, 6, 0);
Font* font = nullptr;
Proxy* p2 = (Proxy*)luax_toudata(L, 2);
- if (luax_istype(L, 2, JIN_GRAPHICS_TEXTUREFONT))
+ if (luax_istype(L, 2, Jin_Lua_TextureFont))
{
TextureFont* tf = p2->getObject<TextureFont>();
font = tf;
}
- else if (luax_istype(L, 2, JIN_GRAPHICS_TTF))
+ else if (luax_istype(L, 2, Jin_Lua_TTF))
{
TTF* ttf = p2->getObject<TTF>();
font = ttf;
@@ -322,31 +369,31 @@ namespace JinEngine
font = context.defaultFont;
}
int lineheight = luax_optnumber(L, 5, font->getFontSize());
- font->print(*text, x, y, lineheight, spacing);
+ font->render(*text, x, y, lineheight, spacing);
}
/* jin.graphics.draw(page, x, y) */
- static void l_draw_page(lua_State* L)
+ LUA_IMPLEMENT void l_draw_page(lua_State* L)
{
- if (!luax_istype(L, 1, JIN_GRAPHICS_PAGE))
+ if (!luax_istype(L, 1, Jin_Lua_Page))
return;
int x = luax_optnumber(L, 2, 0);
int y = luax_optnumber(L, 3, 0);
Proxy* p = (Proxy*)luax_toudata(L, 1);
Page* page = p->getObject<Page>();
Font* font = page->font;
- font->print(page, x, y);
+ font->render(page, x, y);
}
- static int l_draw(lua_State* L)
+ LUA_IMPLEMENT int l_draw(lua_State* L)
{
- if (luax_istype(L, 1, JIN_GRAPHICS_TEXTURE))
+ if (luax_istype(L, 1, Jin_Lua_Texture))
l_draw_texture(L);
- else if (luax_istype(L, 1, JIN_GRAPHICS_CANVAS))
+ else if (luax_istype(L, 1, Jin_Lua_Canvas))
l_draw_canvas(L);
- else if (luax_istype(L, 1, JIN_GRAPHICS_TEXT))
+ else if (luax_istype(L, 1, Jin_Lua_Text))
l_draw_text(L);
- else if (luax_istype(L, 1, JIN_GRAPHICS_PAGE))
+ else if (luax_istype(L, 1, Jin_Lua_Page))
l_draw_page(L);
else
{
@@ -357,7 +404,7 @@ namespace JinEngine
}
// draw(tex, quad, x, y, sx, sy, r, ax, ay)
- static int l_drawq(lua_State* L)
+ LUA_IMPLEMENT int l_drawq(lua_State* L)
{
if (!luax_istable(L, 2))
{
@@ -378,17 +425,17 @@ namespace JinEngine
float ox = luax_optnumber(L, 8, 0);
float oy = luax_optnumber(L, 9, 0);
- if (luax_istype(L, 1, JIN_GRAPHICS_TEXTURE))
+ if (luax_istype(L, 1, Jin_Lua_Texture))
{
Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Texture>& tex = proxy->getRef<Texture>();
- tex->draw(q, x, y, sx, sy, r, ox, oy);
+ Shared<Texture>& tex = proxy->getShared<Texture>();
+ tex->render(q, x, y, sx, sy, r, ox, oy);
}
- else if (luax_istype(L, 1, JIN_GRAPHICS_CANVAS))
+ else if (luax_istype(L, 1, Jin_Lua_Canvas))
{
Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Canvas>& p = proxy->getRef<Canvas>();
- p->draw(q, x, y, sx, sy, r, ox, oy);
+ Shared<Canvas>& p = proxy->getShared<Canvas>();
+ p->render(q, x, y, sx, sy, r, ox, oy);
}
else
{
@@ -398,7 +445,7 @@ namespace JinEngine
/* print(string, x, y, lineheight, spacing) */
/* need set font */
- static int l_print(lua_State* L)
+ LUA_IMPLEMENT int l_print(lua_State* L)
{
Font* font = context.curFont;
if (font == nullptr)
@@ -410,15 +457,15 @@ namespace JinEngine
int y = luax_optnumber(L, 3, 0);
int lineheight = luax_optnumber(L, 4, font->getFontSize());
int spacing = luax_optnumber(L, 5, 0);
- font->print(text, x, y, lineheight, spacing);
+ font->render(text, x, y, lineheight, spacing);
return 0;
}
- static int l_setColor(lua_State* L)
+ LUA_IMPLEMENT int l_setColor(lua_State* L)
{
if (luax_gettop(L) == 0)
{
- glColor4f(1, 1, 1, 1);
+ gl.setColor(Color(255, 255, 255, 255));
return 0;
}
@@ -429,14 +476,11 @@ namespace JinEngine
context.curRenderColor.a = luax_checknumber(L, 4);
else
context.curRenderColor.a = 255;
- glColor4f(context.curRenderColor.r / 255.f,
- context.curRenderColor.g / 255.f,
- context.curRenderColor.b / 255.f,
- context.curRenderColor.a / 255.f);
+ gl.setColor(context.curRenderColor);
return 0;
}
- static int l_getColor(lua_State * L)
+ LUA_IMPLEMENT int l_getColor(lua_State * L)
{
luax_pushnumber(L, context.curRenderColor.r);
luax_pushnumber(L, context.curRenderColor.g);
@@ -445,7 +489,7 @@ namespace JinEngine
return 4;
}
- static int l_bindCanvas(lua_State* L)
+ LUA_IMPLEMENT int l_bindCanvas(lua_State* L)
{
if (luax_gettop(L) == 0)
{
@@ -453,29 +497,29 @@ namespace JinEngine
Canvas::unbind();
return 0;
}
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_CANVAS);
- Ref<Canvas>& ref = proxy->getRef<Canvas>();
- Canvas::bind(ref.getObject());
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Canvas);
+ Shared<Canvas>& shared = proxy->getShared<Canvas>();
+ Canvas::bind(shared.getObject());
return 0;
}
- static int l_unbindCanvas(lua_State* L)
+ LUA_IMPLEMENT int l_unbindCanvas(lua_State* L)
{
Canvas::unbind();
return 0;
}
- static int l_useShader(lua_State* L)
+ LUA_IMPLEMENT int l_useShader(lua_State* L)
{
if (luax_gettop(L) == 0)
{
Shader::unuse();
return 0;
}
- if (luax_istype(L, 1, JIN_GRAPHICS_SHADER))
+ if (luax_istype(L, 1, Jin_Lua_Shader))
{
- Proxy* proxy = (Proxy*)luax_toudata(L, 1);
- Ref<Shader>& jsl = proxy->getRef<Shader>();
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Shader);
+ Shared<Shader>& jsl = proxy->getShared<Shader>();
jsl->use();
}
else
@@ -485,21 +529,13 @@ namespace JinEngine
return 0;
}
- static int l_setBlend(lua_State* L)
+ LUA_IMPLEMENT int l_setBlend(lua_State* L)
{
return 0;
}
- static RenderMode strtomode(const char* str)
- {
- std::string s = std::string(str);
- if (s == "fill") return RenderMode::FILL;
- else if (s == "line") return RenderMode::LINE;
- else return RenderMode::NONE;
- }
-
- static int l_point(lua_State* L)
+ LUA_IMPLEMENT int l_point(lua_State* L)
{
int x = luax_checknumber(L, 1);
int y = luax_checknumber(L, 2);
@@ -508,7 +544,7 @@ namespace JinEngine
return 0;
}
- static int l_line(lua_State* L)
+ LUA_IMPLEMENT int l_line(lua_State* L)
{
int x1 = luax_checknumber(L, 1);
int y1 = luax_checknumber(L, 2);
@@ -519,10 +555,9 @@ namespace JinEngine
return 0;
}
- static int l_rect(lua_State* L)
+ LUA_IMPLEMENT int l_rect(lua_State* L)
{
- const char* modestr = luax_checkstring(L, 1);
- RenderMode mode = strtomode(modestr);
+ RenderMode mode = static_cast<RenderMode>(luax_checkinteger(L, 1));
if (mode != RenderMode::NONE)
{
int x = luax_checknumber(L, 2);
@@ -540,10 +575,9 @@ namespace JinEngine
return 0;
}
- static int l_circle(lua_State* L)
+ LUA_IMPLEMENT int l_circle(lua_State* L)
{
- const char* modestr = luax_checkstring(L, 1);
- RenderMode mode = strtomode(modestr);
+ RenderMode mode = static_cast<RenderMode>(luax_checkinteger(L, 1));
if (mode != RenderMode::NONE)
{
int x = luax_checknumber(L, 2);
@@ -560,10 +594,9 @@ namespace JinEngine
return 0;
}
- static int l_triangle(lua_State* L)
+ LUA_IMPLEMENT int l_triangle(lua_State* L)
{
- const char* modestr = luax_checkstring(L, 1);
- RenderMode mode = strtomode(modestr);
+ RenderMode mode = static_cast<RenderMode>(luax_checkinteger(L, 1));
if (mode != RenderMode::NONE)
{
int x = luax_checknumber(L, 2);
@@ -586,11 +619,10 @@ namespace JinEngine
return 0;
}
- static int l_polygon(lua_State* L)
+ LUA_IMPLEMENT int l_polygon(lua_State* L)
{
- const char* modestr = luax_checkstring(L, 1);
+ RenderMode mode = static_cast<RenderMode>(luax_checkinteger(L, 1));
int n = luax_checknumber(L, 2);
- RenderMode mode = strtomode(modestr);
if (mode != RenderMode::NONE)
{
if (!luax_istable(L, 3))
@@ -601,7 +633,7 @@ namespace JinEngine
int tn = luax_tableidxlen(L, 3);
if (tn != n * 2)
{
- static char* emsg = \
+ LUA_IMPLEMENT char* emsg = \
"number of polygon vertices doesn't match " \
"provided n, expect %d numbers but get %d";
luax_error(L, emsg, n * 2, tn);
@@ -621,16 +653,16 @@ namespace JinEngine
return 0;
}
- static int l_newTTFData(lua_State* L)
+ LUA_IMPLEMENT int l_newTTFData(lua_State* L)
{
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TTFDATA, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_TTFData);
TTFData* fd = nullptr;
{
const char* path = luax_checkstring(L, 1);
AssetDatabase* fs = AssetDatabase::get();
if (!fs->exists(path))
{
- error(L, "No such font %s\n", path);
+ error(L, "No such font \"%s\"", path);
luax_pushnil(L);
return 1;
}
@@ -638,12 +670,12 @@ namespace JinEngine
fs->read(path, b);
fd = TTFData::createTTFData(&b, b.size());
}
- proxy->bind(new Ref<TTFData>(fd, JIN_GRAPHICS_TTFDATA));
+ proxy->bind(new Shared<TTFData>(fd, Jin_Lua_TTFData));
return 1;
}
-
+
/* newText(str[, encode]) */
- static int l_newText(lua_State* L)
+ LUA_IMPLEMENT int l_newText(lua_State* L)
{
Encode encode = Encode::UTF8;
if (luax_gettop(L) == 2)
@@ -661,20 +693,48 @@ namespace JinEngine
unsigned length;
const char* data = luax_checklstring(L, 1, &length);
Text* text = new Text(encode, data, length);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXT, sizeof(Proxy));
- proxy->bind(new Ref<Text>(text, JIN_GRAPHICS_TEXT));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Text);
+ proxy->bind(new Shared<Text>(text, Jin_Lua_Text));
return 1;
}
+ LUA_IMPLEMENT int l_newSprite(lua_State* L)
+ {
+ Proxy* p = luax_newinstance(L, Jin_Lua_Sprite);
+ p->bind(new Shared<Sprite>(new Sprite(), Jin_Lua_Sprite));
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_newSpriteSheet(lua_State* L)
+ {
+ Proxy* pxyGraphic = nullptr;
+ if (luax_istype(L, 1, Jin_Lua_Texture))
+ pxyGraphic = (Proxy*)luax_checktype(L, 1, Jin_Lua_Texture);
+ else if(luax_istype(L, 1, Jin_Lua_Canvas))
+ pxyGraphic = (Proxy*)luax_checktype(L, 1, Jin_Lua_Canvas);
+ if (pxyGraphic != nullptr)
+ {
+ Proxy* pxySSheet = luax_newinstance(L, Jin_Lua_SpriteSheet);
+ Graphic* graphic = pxyGraphic->getObject<Graphic>();
+ Shared<SpriteSheet>* shrSSheet = new Shared<SpriteSheet>(new SpriteSheet(graphic), Jin_Lua_SpriteSheet);
+ Shared<Graphic>& shrGraphic = pxyGraphic->getShared<Graphic>();
+ shrSSheet->setDependency((int)SpriteSheetDependency::DEP_GRAPHIC, &shrGraphic);
+ pxySSheet->bind(shrSSheet);
+ return 1;
+ }
+ else
+ return 0;
+ }
+
/* newTextureFont(bitmap, text, color | cellw, cellh) */
- static int l_newTextureFont(lua_State* L)
+ LUA_IMPLEMENT int l_newTextureFont(lua_State* L)
{
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_BITMAP);
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Bitmap);
Bitmap* bitmap = p->getObject<Bitmap>();
Text* text;
- if (luax_istype(L, 2, JIN_GRAPHICS_TEXT))
+ if (luax_istype(L, 2, Jin_Lua_Text))
{
- Proxy* pt = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_TEXT);
+ Proxy* pt = (Proxy*)luax_checktype(L, 2, Jin_Lua_Text);
text = pt->getObject<Text>();
}
else if (luax_isstring(L, 2))
@@ -713,92 +773,78 @@ namespace JinEngine
// Delete temporary text.
delete text;
}
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TEXTUREFONT, sizeof(Proxy));
- proxy->bind(new Ref<TextureFont>(textureFont, JIN_GRAPHICS_TEXTUREFONT));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_TextureFont);
+ proxy->bind(new Shared<TextureFont>(textureFont, Jin_Lua_TextureFont));
return 1;
}
/* setFont(font) */
- static int l_setFont(lua_State* L)
+ LUA_IMPLEMENT int l_setFont(lua_State* L)
{
- if (luax_istype(L, 1, JIN_GRAPHICS_TTF))
+ if (luax_istype(L, 1, Jin_Lua_TTF))
{
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTF);
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_TTF);
TTF* ttf = p->getObject<TTF>();
context.curFont = ttf;
}
- else if (luax_istype(L, 1, JIN_GRAPHICS_TEXTUREFONT))
+ else if (luax_istype(L, 1, Jin_Lua_TextureFont))
{
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTUREFONT);
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_TextureFont);
TextureFont* tf = p->getObject<TextureFont>();
context.curFont = tf;
}
return 0;
}
- static int l_unsetFont(lua_State* L)
+ LUA_IMPLEMENT int l_unsetFont(lua_State* L)
{
context.curFont = context.defaultFont;
return 0;
}
- static const luaL_Reg f[] = {
- /* window */
- { "init", l_init },
- { "setTitle", l_setTitle },
- { "getSize", l_getSize },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "destroy", l_destroy },
- /* creators */
- { "newBitmap", l_newBitmap },
- { "newTexture", l_newTexture },
- { "newShader", l_newShader },
- { "newShaderf", l_newShaderf },
- { "newCanvas", l_newCanvas },
- { "newTTFData", l_newTTFData },
- { "newText", l_newText },
- { "newTextureFont", l_newTextureFont },
- /* render */
- { "setClearColor", l_setClearColor },
- { "clear", l_clear },
- { "draw", l_draw },
- { "print", l_print },
- { "drawq", l_drawq },
- { "setColor", l_setColor },
- { "getColor", l_getColor },
- { "present", l_present },
- /* canvas */
- { "bindCanvas", l_bindCanvas },
- { "unbindCanvas", l_unbindCanvas },
- /* shader */
- { "useShader", l_useShader },
- /* shapes */
- { "point", l_point },
- { "line", l_line },
- { "rect", l_rect },
- { "circle", l_circle },
- { "triangle", l_triangle },
- { "polygon", l_polygon },
- /* font */
- { "setFont", l_setFont },
- { "unsetFont", l_unsetFont },
- { 0, 0 }
- };
-
- extern int luaopen_Texture(lua_State* L);
- extern int luaopen_Text(lua_State* L);
- extern int luaopen_TTF(lua_State* L);
- extern int luaopen_TextureFont(lua_State* L);
- extern int luaopen_TTFData(lua_State* L);
- extern int luaopen_Page(lua_State* L);
- extern int luaopen_Canvas(lua_State* L);
- extern int luaopen_JSL(lua_State* L);
- extern int luaopen_Bitmap(lua_State* L);
-
- int luaopen_graphics(lua_State* L)
+ LUA_IMPLEMENT int l_clearMatrix(lua_State* L)
+ {
+ gl.clearMatrix();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_pushMatrix(lua_State* L)
+ {
+ gl.push();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_popMatrix(lua_State* L)
+ {
+ gl.pop();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_scale(lua_State* L)
+ {
+ float sx = luax_checknumber(L, 1);
+ float sy = luax_checknumber(L, 2);
+ gl.scale(sx, sy);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_translate(lua_State* L)
+ {
+ float x = luax_checknumber(L, 1);
+ float y = luax_checknumber(L, 2);
+ gl.translate(x, y);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_rotate(lua_State* L)
+ {
+ float r = luax_checknumber(L, 1);
+ gl.rotate(r);
+ return 0;
+ }
+
+ LUA_EXPORT int luaopen_graphics(lua_State* L)
{
- // register types
luaopen_Bitmap(L);
luaopen_Texture(L);
luaopen_Canvas(L);
@@ -807,13 +853,70 @@ namespace JinEngine
luaopen_Text(L);
luaopen_TextureFont(L);
luaopen_Page(L);
- luaopen_JSL(L);
-
- // load whole lib
+ luaopen_Shader(L);
+ luaopen_Sprite(L);
+ luaopen_SpriteSheet(L);
+
+ luaL_Reg f[] = {
+ /* window */
+ { "init", l_init },
+ { "setTitle", l_setTitle },
+ { "getSize", l_getSize },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "destroy", l_destroy },
+ { "hideWindow", l_hideWindow },
+ { "showWindow", l_showWindow },
+ /* creators */
+ { "newBitmap", l_newBitmap },
+ { "newTexture", l_newTexture },
+ { "newShader", l_newShader },
+ { "newShaderf", l_newShaderf },
+ { "newCanvas", l_newCanvas },
+ { "newTTFData", l_newTTFData },
+ { "newText", l_newText },
+ { "newTextureFont", l_newTextureFont },
+ { "newSprite", l_newSprite },
+ { "newSpriteSheet", l_newSpriteSheet },
+ /* render */
+ { "setClearColor", l_setClearColor },
+ { "clear", l_clear },
+ { "draw", l_draw },
+ { "print", l_print },
+ { "drawq", l_drawq },
+ { "setColor", l_setColor },
+ { "getColor", l_getColor },
+ { "present", l_present },
+ /* canvas */
+ { "bindCanvas", l_bindCanvas },
+ { "unbindCanvas", l_unbindCanvas },
+ /* shader */
+ { "useShader", l_useShader },
+ /* shapes */
+ { "point", l_point },
+ { "line", l_line },
+ { "rect", l_rect },
+ { "circle", l_circle },
+ { "triangle", l_triangle },
+ { "polygon", l_polygon },
+ /* font */
+ { "setFont", l_setFont },
+ { "unsetFont", l_unsetFont },
+ /* transform */
+ { "pushMatrix", l_pushMatrix },
+ { "clearMatrix", l_clearMatrix },
+ { "popMatrix", l_popMatrix },
+ { "translate", l_translate },
+ { "rotate", l_rotate },
+ { "scale", l_scale },
+ { 0, 0 }
+ };
+
+ // Load whole lib.
luax_newlib(L, f);
return 1;
}
- }// lua
-}// jin \ No newline at end of file
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_graphics.h b/src/lua/modules/graphics/je_lua_graphics.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_graphics.h
diff --git a/src/lua/modules/graphics/je_lua_page.cpp b/src/lua/modules/graphics/je_lua_page.cpp
new file mode 100644
index 0000000..20ec398
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_page.cpp
@@ -0,0 +1,69 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include <iostream>
+
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Fonts;
+using namespace JinEngine::Graphics::Shaders;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Page = "Page";
+
+ typedef Shared<Font>& SharedFont;
+
+ Page* getPage(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Page);
+ return proxy->getObject<Page>();
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Page);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
+ {
+ Page* page = getPage(L);
+ luax_pushinteger(L, page->size.w);
+ luax_pushinteger(L, page->size.h);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
+ {
+ Page* page = getPage(L);
+ luax_pushinteger(L, page->size.w);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getHeight(lua_State* L)
+ {
+ Page* page = getPage(L);
+ luax_pushinteger(L, page->size.h);
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_Page(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "getSize", l_getSize },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Page, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_page.h b/src/lua/modules/graphics/je_lua_page.h
new file mode 100644
index 0000000..e4a21a3
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_page.h
@@ -0,0 +1,22 @@
+#ifndef __JE_LUA_PAGE_H__
+#define __JE_LUA_PAGE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ enum class PageDependency
+ {
+ DEP_TTF = 1,
+ DEP_TEXTURE_FONT = 2,
+ };
+
+ extern const char* Jin_Lua_Page;
+
+ void luaopen_Page(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_particle_system.cpp b/src/lua/modules/graphics/je_lua_particle_system.cpp
new file mode 100644
index 0000000..7099a5c
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_particle_system.cpp
@@ -0,0 +1,11 @@
+#include "libjin/jin.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+
+
+ } // Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_particle_system.h b/src/lua/modules/graphics/je_lua_particle_system.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_particle_system.h
diff --git a/src/lua/modules/graphics/je_lua_shader.cpp b/src/lua/modules/graphics/je_lua_shader.cpp
new file mode 100644
index 0000000..1612a69
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_shader.cpp
@@ -0,0 +1,137 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include "je_lua_shader.h"
+#include "je_lua_canvas.h"
+#include "je_lua_texture.h"
+
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Shaders;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Shader = "Shader";
+
+ typedef Shared<Shader>& ShaderRef;
+
+ static inline ShaderRef checkShader(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Shader);
+ return proxy->getShared<Shader>();
+ }
+
+ /**
+ * jsl:sendNumber("variable", 0.1)
+ */
+ LUA_IMPLEMENT int l_sendNumber(lua_State* L)
+ {
+ ShaderRef shared = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ float number = luax_checknumber(L, 3);
+ shared->sendFloat(variable, number);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_sendTexture(lua_State* L)
+ {
+ ShaderRef shared = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 3, Jin_Lua_Texture);
+ Shared<Texture>& tex = proxy->getShared<Texture>();
+ shared->sendTexture(variable, tex.getObject());
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_sendCanvas(lua_State* L)
+ {
+ ShaderRef shared = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 3, Jin_Lua_Canvas);
+ Shared<Canvas>& canvas = proxy->getShared<Canvas>();
+ shared->sendCanvas(variable, canvas.getObject());
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_sendVec2(lua_State* L)
+ {
+ ShaderRef shared = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ if (!luax_istable(L, 3))
+ {
+ luax_typerror(L, 3, "table");
+ return 1;
+ }
+ float x = luax_rawgetnumber(L, 3, 1);
+ float y = luax_rawgetnumber(L, 3, 2);
+ shared->sendVec2(variable, x, y);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_sendVec3(lua_State* L)
+ {
+ ShaderRef shared = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ if (!luax_istable(L, 3))
+ {
+ luax_typerror(L, 3, "table");
+ return 1;
+ }
+ float x = luax_rawgetnumber(L, 3, 1);
+ float y = luax_rawgetnumber(L, 3, 2);
+ float z = luax_rawgetnumber(L, 3, 3);
+ shared->sendVec3(variable, x, y, z);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_sendVec4(lua_State* L)
+ {
+ ShaderRef shared = checkShader(L);
+ const char* variable = luax_checkstring(L, 2);
+ if (!luax_istable(L, 3))
+ {
+ luax_typerror(L, 3, "table");
+ return 1;
+ }
+ float x = luax_rawgetnumber(L, 3, 1);
+ float y = luax_rawgetnumber(L, 3, 2);
+ float z = luax_rawgetnumber(L, 3, 3);
+ float w = luax_rawgetnumber(L, 3, 4);
+ shared->sendVec4(variable, x, y, z, w);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_sendColor(lua_State* L)
+ {
+ return l_sendVec4(L);
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Shader);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Shader(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "sendNumber", l_sendNumber },
+ { "sendTexture", l_sendTexture },
+ { "sendCanvas", l_sendCanvas },
+ { "sendVec2", l_sendVec2 },
+ { "sendVec3", l_sendVec3 },
+ { "sendVec4", l_sendVec4 },
+ { "sendColor", l_sendColor },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Shader, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_shader.h b/src/lua/modules/graphics/je_lua_shader.h
new file mode 100644
index 0000000..5a84372
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_shader.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_SHDER_H__
+#define __JE_LUA_SHDER_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Shader;
+
+ void luaopen_Shader(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_sprite.cpp b/src/lua/modules/graphics/je_lua_sprite.cpp
new file mode 100644
index 0000000..97128a9
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_sprite.cpp
@@ -0,0 +1,262 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include "je_lua_sprite.h"
+#include "je_lua_canvas.h"
+#include "je_lua_texture.h"
+#include "je_lua_shader.h"
+
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Shaders;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+ const char* Jin_Lua_Sprite = "Sprite";
+
+ typedef Shared<Sprite>& SharedSprite;
+
+ LUA_IMPLEMENT inline SharedSprite checkSprite(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Sprite);
+ return proxy->getShared<Sprite>();
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Sprite);
+ p->release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setRotation(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float r = luax_checknumber(L, 2);
+ sprite->setRotation(r);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setOrigin(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ switch (luax_gettop(L))
+ {
+ case 2:
+ {
+ int origin = luax_checkinteger(L, 2);
+ sprite->setOrigin(static_cast<Sprite::Origin>(origin));
+ }
+ break;
+ case 3:
+ {
+ int x = luax_checkinteger(L, 2);
+ int y = luax_checkinteger(L, 3);
+ sprite->setOrigin(x, y);
+ }
+ break;
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setPosition(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float x = luax_checknumber(L, 2);
+ float y = luax_checknumber(L, 3);
+ sprite->setPosition(x, y);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setScale(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float sx = luax_checknumber(L, 2);
+ float sy = luax_checknumber(L, 3);
+ sprite->setScale(sx, sy);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setColor(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ Channel r = luax_checkinteger(L, 2);
+ Channel g = luax_checkinteger(L, 3);
+ Channel b = luax_checkinteger(L, 4);
+ Channel a = luax_checkinteger(L, 5);
+ sprite->setColor(Color(r, g, b, a));
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setShader(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 2, Jin_Lua_Shader);
+ Shader* shader = proxy->getObject<Shader>();
+ sprite->setShader(shader);
+ sprite.setDependency((int)SpriteDependency::DEP_SHADER, &proxy->getShared<Shader>());
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_setGraphic(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ Graphic* graphic = nullptr;
+ Proxy* p = nullptr;
+ if (luax_istype(L, 2, Jin_Lua_Texture))
+ p = (Proxy*)luax_checktype(L, 2, Jin_Lua_Texture);
+ else if (luax_istype(L, 2, Jin_Lua_Canvas))
+ p = (Proxy*)luax_checktype(L, 2, Jin_Lua_Canvas);
+ if (p != nullptr)
+ {
+ sprite->setGraphic(p->getObject<Graphic>());
+ sprite.setDependency((int)SpriteDependency::DEP_GRAPHIC, &p->getShared<Graphic>());
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_move(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float x = luax_checknumber(L, 2);
+ float y = luax_checknumber(L, 3);
+ sprite->move(x, y);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_scale(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float sx = luax_checknumber(L, 2);
+ float sy = luax_checknumber(L, 3);
+ sprite->scale(sx, sy);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_rotate(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float r = luax_checknumber(L, 2);
+ sprite->rotate(r);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getRotation(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ float r = sprite->getRotation();
+ luax_pushnumber(L, r);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getPosition(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ const Math::Vector2<float>& pos = sprite->getPosition();
+ luax_pushnumber(L, pos.x);
+ luax_pushnumber(L, pos.y);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_getOrigin(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ const Math::Vector2<int>& origin = sprite->getOrigin();
+ luax_pushinteger(L, origin.x);
+ luax_pushinteger(L, origin.y);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_getScale(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ const Math::Vector2<float> scale = sprite->getScale();
+ luax_pushnumber(L, scale.x);
+ luax_pushnumber(L, scale.y);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_getColor(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ const Color& c = sprite->getColor();
+ luax_pushinteger(L, c.r);
+ luax_pushinteger(L, c.g);
+ luax_pushinteger(L, c.b);
+ luax_pushinteger(L, c.a);
+ return 4;
+ }
+
+ LUA_IMPLEMENT int l_render(lua_State* L)
+ {
+ SharedSprite sprite = checkSprite(L);
+ sprite->render();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getGraphic(lua_State* L)
+ {
+ Proxy* pxySprite = (Proxy*)luax_checktype(L, 1, Jin_Lua_Sprite);
+ Shared<Sprite>& shrSprite = pxySprite->getShared<Sprite>();
+ SharedBase* shrGraphic = shrSprite.getDependency((int)SpriteDependency::DEP_GRAPHIC);
+ if (shrGraphic->isType(Jin_Lua_Canvas))
+ {
+ Proxy* pxyCanvas = luax_newinstance(L, Jin_Lua_Canvas);
+ pxyCanvas->bind(shrGraphic);
+ return 1;
+ }
+ else if (shrGraphic->isType(Jin_Lua_Texture))
+ {
+ Proxy* pxyTexture = luax_newinstance(L, Jin_Lua_Texture);
+ pxyTexture->bind(shrGraphic);
+ return 1;
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getShader(lua_State* L)
+ {
+ Proxy* pxySprite = (Proxy*)luax_checktype(L, 1, Jin_Lua_Sprite);
+ Shared<Sprite>& shrSprite = pxySprite->getShared<Sprite>();
+ SharedBase* shrShader = shrSprite.getDependency((int)SpriteDependency::DEP_SHADER);
+ if (shrShader != nullptr && shrShader->isType(Jin_Lua_Shader))
+ {
+ Proxy* pxyShader = luax_newinstance(L, Jin_Lua_Shader);
+ pxyShader->bind(shrShader);
+ return 1;
+ }
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Sprite(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "render", l_render },
+ { "setRotation", l_setRotation },
+ { "setOrigin", l_setOrigin },
+ { "setPosition", l_setPosition },
+ { "setScale", l_setScale },
+ { "setColor", l_setColor },
+ { "setShader", l_setShader },
+ { "setGraphic", l_setGraphic },
+ { "move", l_move },
+ { "scale", l_scale },
+ { "rotate", l_rotate },
+ { "getRotation", l_getRotation },
+ { "getPosition", l_getPosition },
+ { "getOrigin", l_getOrigin },
+ { "getScale", l_getScale },
+ { "getColor", l_getColor },
+ { "getShader", l_getShader },
+ { "getGraphic", l_getGraphic },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Sprite, methods);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_sprite.h b/src/lua/modules/graphics/je_lua_sprite.h
new file mode 100644
index 0000000..02c44bf
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_sprite.h
@@ -0,0 +1,24 @@
+#ifndef __JE_LUA_SPRITE_H__
+#define __JE_LUA_SPRITE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ // Sprite dependency slots.
+ enum class SpriteDependency
+ {
+ DEP_GRAPHIC = 1,
+ DEP_SHADER = 2,
+ DEP_SPRITESHEET = 3
+ };
+
+ extern const char* Jin_Lua_Sprite;
+
+ void luaopen_Sprite(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_spritesheet.cpp b/src/lua/modules/graphics/je_lua_spritesheet.cpp
new file mode 100644
index 0000000..15469e9
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_spritesheet.cpp
@@ -0,0 +1,54 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_sprite.h"
+#include "je_lua_spritesheet.h"
+
+using namespace JinEngine::Math;
+using namespace JinEngine::Graphics;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_SpriteSheet = "SpriteSheet";
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* pxySSheet = (Proxy*)luax_checktype(L, 1, Jin_Lua_SpriteSheet);
+ pxySSheet->release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_newSprite(lua_State* L)
+ {
+ Proxy* pxySSheet = (Proxy*)luax_checktype(L, 1, Jin_Lua_SpriteSheet);
+ Shared<SpriteSheet>& shrSSheet = pxySSheet->getShared<SpriteSheet>();
+ SpriteSheet* sheet = pxySSheet->getObject<SpriteSheet>();
+ Quad quad;
+ quad.x = luax_checkinteger(L, 2);
+ quad.y = luax_checkinteger(L, 3);
+ quad.w = luax_checkinteger(L, 4);
+ quad.h = luax_checkinteger(L, 5);
+ Sprite* spr = sheet->createSprite(quad);
+ Proxy* pxySprite = luax_newinstance(L, Jin_Lua_Sprite);
+ Shared<Sprite>* shrSprite = new Shared<Sprite>(spr, Jin_Lua_Sprite);
+ shrSprite->setDependency((int)SpriteDependency::DEP_SPRITESHEET, &shrSSheet);
+ pxySprite->bind(shrSprite);
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_SpriteSheet(lua_State* L)
+ {
+ luaL_Reg methods[] = {
+ { "__gc", l_gc },
+ { "newSprite", l_newSprite },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_SpriteSheet, methods);
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_spritesheet.h b/src/lua/modules/graphics/je_lua_spritesheet.h
new file mode 100644
index 0000000..bcae60b
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_spritesheet.h
@@ -0,0 +1,21 @@
+#ifndef __JE_LUA_SPRITE_SHEET_H__
+#define __JE_LUA_SPRITE_SHEET_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ enum class SpriteSheetDependency
+ {
+ DEP_GRAPHIC = 1
+ };
+
+ extern const char* Jin_Lua_SpriteSheet;
+
+ void luaopen_SpriteSheet(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_text.cpp b/src/lua/modules/graphics/je_lua_text.cpp
new file mode 100644
index 0000000..9377a0a
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_text.cpp
@@ -0,0 +1,32 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+using namespace JinEngine::Graphics;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Text = "Text";
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Text);
+ p->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Text(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Text, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_text.h b/src/lua/modules/graphics/je_lua_text.h
new file mode 100644
index 0000000..dfcc9cc
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_text.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_TEXT_H__
+#define __JE_LUA_TEXT_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Text;
+
+ void luaopen_Text(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_texture.cpp b/src/lua/modules/graphics/je_lua_texture.cpp
new file mode 100644
index 0000000..79ddc63
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_texture.cpp
@@ -0,0 +1,66 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_texture.h"
+
+using namespace JinEngine::Graphics;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Texture = "Texture";
+
+ typedef Shared<Texture>& SharedTexture;
+
+ LUA_IMPLEMENT inline SharedTexture checkTexture(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Texture);
+ return proxy->getShared<Texture>();
+ }
+
+ LUA_IMPLEMENT int l_getWidth(lua_State* L)
+ {
+ SharedTexture shared = checkTexture(L);
+ luax_pushnumber(L, shared->getWidth());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getHeight(lua_State *L)
+ {
+ SharedTexture shared = checkTexture(L);
+ luax_pushnumber(L, shared->getHeight());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getSize(lua_State* L)
+ {
+ SharedTexture shared = checkTexture(L);
+ luax_pushnumber(L, shared->getWidth());
+ luax_pushnumber(L, shared->getHeight());
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Texture);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Texture(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "getWidth", l_getWidth },
+ { "getHeight", l_getHeight },
+ { "getSize", l_getSize },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Texture, f);
+ }
+
+ }// namespace Lua
+}// namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_texture.h b/src/lua/modules/graphics/je_lua_texture.h
new file mode 100644
index 0000000..c8bb71c
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_texture.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_TEXTURE_H__
+#define __JE_LUA_TEXTURE_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Texture;
+
+ void luaopen_Texture(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_texture_font.cpp b/src/lua/modules/graphics/je_lua_texture_font.cpp
new file mode 100644
index 0000000..8ca3ce5
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_texture_font.cpp
@@ -0,0 +1,66 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include "je_lua_page.h"
+#include "je_lua_text.h"
+
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Fonts;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_TextureFont = "TextureFont";
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_TextureFont);
+ proxy->release();
+ return 0;
+ }
+
+ /* typeset(Text | string, lineheight, spacing) */
+ LUA_IMPLEMENT int l_typeset(lua_State* L)
+ {
+ Proxy* pxyTexFont = (Proxy*)luax_checktype(L, 1, Jin_Lua_TextureFont);
+ Shared<TextureFont>& shrTexFont = pxyTexFont->getShared<TextureFont>();
+ TextureFont* tf = pxyTexFont->getObject<TextureFont>();
+ int lineheight = luax_checkinteger(L, 3);
+ int spacing = luax_optnumber(L, 4, 0);
+ Page* page = nullptr;
+ if (luax_isstring(L, 2))
+ {
+ unsigned length;
+ const char* str = luax_checklstring(L, 2, &length);
+ Text text(Encode::UTF8, str, length);
+ page = tf->typeset(text, lineheight, spacing);
+ }
+ else if (luax_istype(L, 2, Jin_Lua_Text))
+ {
+ Proxy* p2 = (Proxy*)luax_checktype(L, 2, Jin_Lua_Text);
+ Text* text = p2->getObject<Text>();
+ page = tf->typeset(*text, lineheight, spacing);
+ }
+ Proxy* pxyPage = luax_newinstance(L, Jin_Lua_Page);
+ Shared<Page>* shrPage = new Shared<Page>(page, Jin_Lua_Page);
+ shrPage->setDependency((int)PageDependency::DEP_TEXTURE_FONT, &shrTexFont);
+ pxyPage->bind(shrPage);
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_TextureFont(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "typeset", l_typeset },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_TextureFont, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_texture_font.h b/src/lua/modules/graphics/je_lua_texture_font.h
new file mode 100644
index 0000000..d1fffe5
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_texture_font.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_TEXTURE_FONT_H__
+#define __JE_LUA_TEXTURE_FONT_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_TextureFont;
+
+ void luaopen_TextureFont(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_ttf.cpp b/src/lua/modules/graphics/je_lua_ttf.cpp
new file mode 100644
index 0000000..c5d922b
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_ttf.cpp
@@ -0,0 +1,66 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include "je_lua_page.h"
+#include "je_lua_text.h"
+
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Fonts;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_TTF = "TTF";
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_TTF);
+ proxy->release();
+ return 0;
+ }
+
+ /* typeset(Text | string, lineheight, spacing) */
+ LUA_IMPLEMENT int l_typeset(lua_State* L)
+ {
+ Proxy* pxyTTF = (Proxy*)luax_checktype(L, 1, Jin_Lua_TTF);
+ Shared<TTF>& shrTTF = pxyTTF->getShared<TTF>();
+ TTF* ttf = pxyTTF->getObject<TTF>();
+ int lineheight = luax_optnumber(L, 3, ttf->getFontSize());
+ int spacing = luax_optnumber(L, 4, 0);
+ Page* page = nullptr;
+ if (luax_isstring(L, 2))
+ {
+ unsigned length;
+ const char* str = luax_checklstring(L, 2, &length);
+ Text text(Encode::UTF8, str, length);
+ page = ttf->typeset(text, lineheight, spacing);
+ }
+ else if (luax_istype(L, 2, Jin_Lua_Text))
+ {
+ Proxy* pxyText = (Proxy*)luax_checktype(L, 2, Jin_Lua_Text);
+ Text* text = pxyText->getObject<Text>();
+ page = ttf->typeset(*text, lineheight, spacing);
+ }
+ Proxy* pxyPage = luax_newinstance(L, Jin_Lua_Page);
+ Shared<Page>* refPage = new Shared<Page>(page, Jin_Lua_Page);
+ refPage->setDependency((int)PageDependency::DEP_TTF, &shrTTF);
+ pxyPage->bind(refPage);
+ return 1;
+ }
+
+ LUA_EXPORT void luaopen_TTF(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "typeset", l_typeset },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_TTF, f);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_ttf.h b/src/lua/modules/graphics/je_lua_ttf.h
new file mode 100644
index 0000000..bfe503d
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_ttf.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_TTF_H__
+#define __JE_LUA_TTF_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_TTF;
+
+ void luaopen_TTF(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_ttf_data.cpp b/src/lua/modules/graphics/je_lua_ttf_data.cpp
new file mode 100644
index 0000000..1277318
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_ttf_data.cpp
@@ -0,0 +1,52 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+
+#include "je_lua_ttf.h"
+#include "je_lua_ttf_data.h"
+
+using namespace JinEngine::Graphics;
+using namespace JinEngine::Graphics::Fonts;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_TTFData = "TTFData";
+
+ LUA_IMPLEMENT int l_newTTF(lua_State* L)
+ {
+ Proxy* pxyTTFData = (Proxy*)luax_checktype(L, 1, Jin_Lua_TTFData);
+ int fontsize = luax_checkinteger(L, 2);
+ Shared<TTFData>& shrFontData = pxyTTFData->getShared<TTFData>();
+ TTFData* fontData = shrFontData.getObject();
+ Proxy* pxyTTF = luax_newinstance(L, Jin_Lua_TTF);
+ TTF* font = fontData->createTTF(fontsize);
+ Shared<TTF>* shrTTF = new Shared<TTF>(font, Jin_Lua_TTF);
+ shrTTF->setDependency((int)TTFDependency::DEP_TTFDATA, &shrFontData);
+ pxyTTF->bind(shrTTF);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_TTFData);
+ p->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_TTFData(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "newTTF", l_newTTF },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_TTFData, f);
+
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_ttf_data.h b/src/lua/modules/graphics/je_lua_ttf_data.h
new file mode 100644
index 0000000..1fd832d
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_ttf_data.h
@@ -0,0 +1,21 @@
+#ifndef __JE_LUA_TTFDATA_H__
+#define __JE_LUA_TTFDATA_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ enum class TTFDependency
+ {
+ DEP_TTFDATA = 1,
+ };
+
+ extern const char* Jin_Lua_TTFData;
+
+ void luaopen_TTFData(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/page.cpp b/src/lua/modules/graphics/page.cpp
deleted file mode 100644
index 8c9e918..0000000
--- a/src/lua/modules/graphics/page.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-#include <iostream>
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- typedef Ref<Font>& FontRef;
-
- Page* getPage(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_PAGE);
- return proxy->getObject<Page>();
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_PAGE);
- {
- /* release font */
- Ref<Page>* page = &proxy->getRef<Page>();
- RefBase* font = (RefBase*)page->getUserdata();
- font->release();
- }
- proxy->release();
- return 0;
- }
-
- static int l_getSize(lua_State* L)
- {
- Page* page = getPage(L);
- luax_pushinteger(L, page->size.w);
- luax_pushinteger(L, page->size.h);
- return 2;
- }
-
- static int l_getWidth(lua_State* L)
- {
- Page* page = getPage(L);
- luax_pushinteger(L, page->size.w);
- return 1;
- }
-
- static int l_getHeight(lua_State* L)
- {
- Page* page = getPage(L);
- luax_pushinteger(L, page->size.h);
- return 1;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "getSize", l_getSize },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { 0, 0 }
- };
-
- int luaopen_Page(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_PAGE, f);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/shader.cpp b/src/lua/modules/graphics/shader.cpp
deleted file mode 100644
index d7733d4..0000000
--- a/src/lua/modules/graphics/shader.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- typedef Ref<Shader>& ShaderRef;
-
- static inline ShaderRef checkShader(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_SHADER);
- return proxy->getRef<Shader>();
- }
-
- /**
- * jsl:sendNumber("variable", 0.1)
- */
- static int l_sendNumber (lua_State* L)
- {
- ShaderRef ref = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- float number = luax_checknumber(L, 3);
- ref->sendFloat(variable, number);
- return 0;
- }
-
- static int l_sendTexture (lua_State* L)
- {
- ShaderRef ref = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- Proxy* proxy = (Proxy*)luax_checktype(L, 3, JIN_GRAPHICS_TEXTURE);
- Ref<Texture>& tex = proxy->getRef<Texture>();
- ref->sendTexture(variable, tex.getObject());
- return 0;
- }
-
- static int l_sendCanvas (lua_State* L)
- {
- ShaderRef ref = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- Proxy* proxy = (Proxy*)luax_checktype(L, 3, JIN_GRAPHICS_CANVAS);
- Ref<Canvas>& canvas = proxy->getRef<Canvas>();
- ref->sendCanvas(variable, canvas.getObject());
- return 0;
- }
-
- static int l_sendVec2 (lua_State* L)
- {
- ShaderRef ref = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- if (!luax_istable(L, 3))
- {
- luax_typerror(L, 3, "table");
- return 1;
- }
- float x = luax_rawgetnumber(L, 3, 1);
- float y = luax_rawgetnumber(L, 3, 2);
- ref->sendVec2(variable, x, y);
- return 0;
- }
-
- static int l_sendVec3 (lua_State* L)
- {
- ShaderRef ref = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- if (!luax_istable(L, 3))
- {
- luax_typerror(L, 3, "table");
- return 1;
- }
- float x = luax_rawgetnumber(L, 3, 1);
- float y = luax_rawgetnumber(L, 3, 2);
- float z = luax_rawgetnumber(L, 3, 3);
- ref->sendVec3(variable, x, y, z);
- return 0;
- }
-
- static int l_sendVec4 (lua_State* L)
- {
- ShaderRef ref = checkShader(L);
- const char* variable = luax_checkstring(L, 2);
- if (!luax_istable(L, 3))
- {
- luax_typerror(L, 3, "table");
- return 1;
- }
- float x = luax_rawgetnumber(L, 3, 1);
- float y = luax_rawgetnumber(L, 3, 2);
- float z = luax_rawgetnumber(L, 3, 3);
- float w = luax_rawgetnumber(L, 3, 4);
- ref->sendVec4(variable, x, y, z, w);
- return 0;
- }
-
- static int l_sendColor (lua_State* L)
- {
- return l_sendVec4(L);
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_SHADER);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "sendNumber", l_sendNumber },
- { "sendTexture", l_sendTexture },
- { "sendCanvas", l_sendCanvas },
- { "sendVec2", l_sendVec2 },
- { "sendVec3", l_sendVec3 },
- { "sendVec4", l_sendVec4 },
- { "sendColor", l_sendColor },
- { 0, 0 }
- };
-
- /**
- * JSL program
- */
- int luaopen_JSL(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_SHADER, f);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/text.cpp b/src/lua/modules/graphics/text.cpp
deleted file mode 100644
index cbc82f1..0000000
--- a/src/lua/modules/graphics/text.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- static int l_gc(lua_State* L)
- {
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXT);
- p->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { 0, 0 }
- };
-
- int luaopen_Text(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_TEXT, f);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/texture.cpp b/src/lua/modules/graphics/texture.cpp
deleted file mode 100644
index 61bfaee..0000000
--- a/src/lua/modules/graphics/texture.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- typedef Ref<Texture>& TextureRef;
-
- static inline TextureRef checkTexture(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTURE);
- return proxy->getRef<Texture>();
- }
-
- static int l_getWidth(lua_State* L)
- {
- TextureRef ref = checkTexture(L);
- luax_pushnumber(L, ref->getWidth());
- return 1;
- }
-
- static int l_getHeight(lua_State *L)
- {
- TextureRef ref = checkTexture(L);
- luax_pushnumber(L, ref->getHeight());
- return 1;
- }
-
- static int l_getSize(lua_State* L)
- {
- TextureRef ref = checkTexture(L);
- luax_pushnumber(L, ref->getWidth());
- luax_pushnumber(L, ref->getHeight());
- return 2;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTURE);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "getWidth", l_getWidth },
- { "getHeight", l_getHeight },
- { "getSize", l_getSize },
- { 0, 0 }
- };
-
- int luaopen_Texture(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_TEXTURE, f);
- return 0;
- }
-
- }// lua
-}// jin \ No newline at end of file
diff --git a/src/lua/modules/graphics/texture_font.cpp b/src/lua/modules/graphics/texture_font.cpp
deleted file mode 100644
index a2e88ba..0000000
--- a/src/lua/modules/graphics/texture_font.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTUREFONT);
- proxy->release();
- return 0;
- }
-
- /* typeset(Text | string, lineheight, spacing) */
- static int l_typeset(lua_State* L)
- {
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTUREFONT);
- TextureFont* tf = p->getObject<TextureFont>();
- int lineheight = luax_checkinteger(L, 3);
- int spacing = luax_optnumber(L, 4, 0);
- Page* page = nullptr;
- if (luax_isstring(L, 2))
- {
- unsigned length;
- const char* str = luax_checklstring(L, 2, &length);
- Text text(Encode::UTF8, str, length);
- page = tf->typeset(text, lineheight, spacing);
- }
- else if (luax_istype(L, 2, JIN_GRAPHICS_TEXT))
- {
- Proxy* p2 = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_TEXT);
- Text* text = p2->getObject<Text>();
- page = tf->typeset(*text, lineheight, spacing);
- }
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_PAGE, sizeof(Proxy));
- Ref<Page>* refPage = new Ref<Page>(page, JIN_GRAPHICS_PAGE);
- {
- /* retain related ttf */
- Ref<TextureFont>& refTF = p->getRef<TextureFont>();
- refTF.retain();
- refPage->setUserdata(&refTF);
- }
- proxy->bind(refPage);
- return 1;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "typeset", l_typeset },
- { 0, 0 }
- };
-
- int luaopen_TextureFont(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_TEXTUREFONT, f);
-
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/ttf.cpp b/src/lua/modules/graphics/ttf.cpp
deleted file mode 100644
index 414c7eb..0000000
--- a/src/lua/modules/graphics/ttf.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTF);
- {
- /* release ttf data */
- Ref<TTF>* ttf = &proxy->getRef<TTF>();
- RefBase* data = (RefBase*)ttf->getUserdata();
- data->release();
- }
- proxy->release();
- return 0;
- }
-
- /* typeset(Text | string, lineheight, spacing) */
- static int l_typeset(lua_State* L)
- {
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTF);
- TTF* ttf = p->getObject<TTF>();
- int lineheight = luax_optnumber(L, 3, ttf->getFontSize());
- int spacing = luax_optnumber(L, 4, 0);
- Page* page = nullptr;
- if (luax_isstring(L, 2))
- {
- unsigned length;
- const char* str = luax_checklstring(L, 2, &length);
- Text text(Encode::UTF8, str, length);
- page = ttf->typeset(text, lineheight, spacing);
- }
- else if (luax_istype(L, 2, JIN_GRAPHICS_TEXT))
- {
- Proxy* p2 = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_TEXT);
- Text* text = p2->getObject<Text>();
- page = ttf->typeset(*text, lineheight, spacing);
- }
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_PAGE, sizeof(Proxy));
- Ref<Page>* refPage = new Ref<Page>(page, JIN_GRAPHICS_PAGE);
- {
- /* retain related ttf */
- Ref<TTF>& refTTF = p->getRef<TTF>();
- refTTF.retain();
- refPage->setUserdata(&refTTF);
- }
- proxy->bind(refPage);
- return 1;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "typeset", l_typeset },
- { 0, 0 }
- };
-
- int luaopen_TTF(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_TTF, f);
-
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/graphics/ttfData.cpp b/src/lua/modules/graphics/ttfData.cpp
deleted file mode 100644
index 43c3613..0000000
--- a/src/lua/modules/graphics/ttfData.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Graphics;
-
- static int l_newTTF(lua_State* L)
- {
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTFDATA);
- int fontsize = luax_checkinteger(L, 2);
- Ref<TTFData>& refFontData = p->getRef<TTFData>();
- TTFData* fontData = refFontData.getObject();
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_GRAPHICS_TTF, sizeof(Proxy));
- TTF* font = fontData->createTTF(fontsize);
- Ref<TTF>* refTTF = new Ref<TTF>(font, JIN_GRAPHICS_TTF);
- {
- Ref<TTFData>& refTTFData = p->getRef<TTFData>();
- refTTFData.retain();
- refTTF->setUserdata(&refTTFData);
- }
- proxy->bind(refTTF);
- return 1;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* p = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TTFDATA);
- p->release();
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "__gc", l_gc },
- { "newTTF", l_newTTF },
- { 0, 0 }
- };
-
- int luaopen_TTFData(lua_State* L)
- {
- luax_newtype(L, JIN_GRAPHICS_TTFDATA, f);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/joypad/joypad.cpp b/src/lua/modules/joypad/je_lua_joypad.cpp
index d67a624..a57fc99 100644
--- a/src/lua/modules/joypad/joypad.cpp
+++ b/src/lua/modules/joypad/je_lua_joypad.cpp
@@ -1,17 +1,17 @@
-#include "libjin/jin.h"
#include "lua/modules/luax.h"
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
namespace JinEngine
{
namespace Lua
{
- static const luaL_Reg f[] = {
- { 0, 0 }
- };
-
- int luaopen_joypad(lua_State* L)
+ LUA_EXPORT int luaopen_joypad(lua_State* L)
{
+ luaL_Reg f[] = {
+ { 0, 0 }
+ };
luax_newlib(L, f);
return 1;
diff --git a/src/lua/modules/joypad/je_lua_joypad.h b/src/lua/modules/joypad/je_lua_joypad.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/joypad/je_lua_joypad.h
diff --git a/src/lua/modules/keyboard/keyboard.cpp b/src/lua/modules/keyboard/je_lua_keyboard.cpp
index 727a51e..6b7f3cd 100644
--- a/src/lua/modules/keyboard/keyboard.cpp
+++ b/src/lua/modules/keyboard/je_lua_keyboard.cpp
@@ -1,3 +1,4 @@
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
namespace JinEngine
@@ -6,7 +7,7 @@ namespace JinEngine
{
//https://wiki.libsdl.org/SDL_Keycode
- int luaopen_keyboard(lua_State* L)
+ LUA_EXPORT int luaopen_keyboard(lua_State* L)
{
luax_newlib(L, 0);
return 1;
diff --git a/src/lua/modules/keyboard/je_lua_keyboard.h b/src/lua/modules/keyboard/je_lua_keyboard.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/keyboard/je_lua_keyboard.h
diff --git a/src/lua/modules/math/math.cpp b/src/lua/modules/math/je_lua_math.cpp
index 4891762..2afeaf9 100644
--- a/src/lua/modules/math/math.cpp
+++ b/src/lua/modules/math/je_lua_math.cpp
@@ -1,3 +1,4 @@
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
#include "libjin/jin.h"
@@ -6,7 +7,7 @@ namespace JinEngine
namespace Lua
{
- static int l_mod(lua_State* L)
+ LUA_IMPLEMENT int l_mod(lua_State* L)
{
int n = luax_checkinteger(L, 1);
int m = luax_checkinteger(L, 2);
@@ -15,13 +16,12 @@ namespace JinEngine
return 1;
}
- static const luaL_Reg f[] = {
- { "mod", l_mod },
- { 0, 0 }
- };
-
- int luaopen_math(lua_State* L)
+ LUA_EXPORT int luaopen_math(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "mod", l_mod },
+ { 0, 0 }
+ };
luax_newlib(L, f);
return 1;
}
diff --git a/src/lua/modules/math/je_lua_math.h b/src/lua/modules/math/je_lua_math.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/math/je_lua_math.h
diff --git a/src/lua/modules/mouse/mouse.cpp b/src/lua/modules/mouse/je_lua_mouse.cpp
index 9d45178..9e6824a 100644
--- a/src/lua/modules/mouse/mouse.cpp
+++ b/src/lua/modules/mouse/je_lua_mouse.cpp
@@ -1,14 +1,15 @@
+#include "lua/common/je_lua_common.h"
#include "lua/modules/luax.h"
#include "libjin/jin.h"
+using namespace JinEngine::Input;
+
namespace JinEngine
{
namespace Lua
{
- using namespace JinEngine::Input;
-
- static int l_pos(lua_State* L)
+ LUA_IMPLEMENT int l_pos(lua_State* L)
{
static Mouse* mouse = Mouse::get();
int x, y;
@@ -18,22 +19,21 @@ namespace JinEngine
return 2;
}
- static int l_setVisible(lua_State* L)
+ LUA_IMPLEMENT int l_setVisible(lua_State* L)
{
bool visible = luax_checkbool(L, 1);
Mouse* mouse = Mouse::get();
mouse->setVisible(visible);
return 0;
}
-
- static const luaL_Reg f[] = {
- { "position", l_pos },
- { "setVisible", l_setVisible },
- { 0, 0 }
- };
- int luaopen_mouse(lua_State* L)
+ LUA_EXPORT int luaopen_mouse(lua_State* L)
{
+ luaL_Reg f[] = {
+ { "getPosition", l_pos },
+ { "setVisible", l_setVisible },
+ { 0, 0 }
+ };
luax_newlib(L, f);
return 1;
}
diff --git a/src/lua/modules/mouse/je_lua_mouse.h b/src/lua/modules/mouse/je_lua_mouse.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/mouse/je_lua_mouse.h
diff --git a/src/lua/modules/net/Buffer.cpp b/src/lua/modules/net/Buffer.cpp
deleted file mode 100644
index ddfbd6b..0000000
--- a/src/lua/modules/net/Buffer.cpp
+++ /dev/null
@@ -1,142 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-#include "Buffer.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
- namespace Net
- {
-
- using namespace JinEngine;
-
- typedef Ref<Buffer>& BufferRef;
-
- static inline BufferRef checkNetBuffer(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_NETWORK_BUFFER);
- return proxy->getRef<Buffer>();
- }
-
- // net.Buffer:append(value) -> value_length
- static int l_append(lua_State* L)
- {
- BufferRef ref = checkNetBuffer(L);
- const int vp = 2;
- if (luax_isintegerstrict(L, vp))
- {
- int n = luax_checkinteger(L, vp);
- int size = sizeof(n);
- ref->append(&n, size);
- luax_pushinteger(L, size);
- return 1;
- }
- else if (luax_isfloatstrict(L, vp))
- {
- float n = luax_checknumber(L, vp);
- int size = sizeof(n);
- ref->append(&n, size);
- luax_pushinteger(L, size);
- return 1;
- }
- else if (luax_isbooleanstrict(L, vp))
- {
- bool n = luax_checkbool(L, vp);
- int size = sizeof(n);
- ref->append(&n, size);
- luax_pushinteger(L, size);
- return 1;
- }
- else if (luax_isstringstrict(L, vp))
- {
- const char* str = luax_checkstring(L, vp);
- int size = strlen(str) + 1;
- ref->append(str, size);
- luax_pushinteger(L, size);
- return 1;
- }
- else
- {
- luax_typerror(L, vp, "number, bool or string");
- return 0;
- }
- }
-
- // net.Buffer:grabString(offset) -> string, length
- static int l_grabString(lua_State* L)
- {
- BufferRef ref = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- unsigned int len;
- char* data = ref->grabString(&len, offset);
- Array<char> str;
- str.bind(data, len);
- luax_pushstring(L, &str);
- luax_pushinteger(L, str.count());
- return 2;
- }
-
- // net.Buffer:grabInteger(offset) -> integer, length
- static int l_grabInteger(lua_State* L)
- {
- BufferRef ref = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- int len;
- int integer = ref->grabInteger(&len, offset);
- luax_pushinteger(L, integer);
- luax_pushinteger(L, len);
- return 2;
- }
-
- static int l_grabFloat(lua_State* L)
- {
- BufferRef ref = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- int len;
- float floatv = ref->grabFloat(&len, offset);
- luax_pushnumber(L, floatv);
- luax_pushinteger(L, len);
- return 2;
- }
-
- static int l_grabBoolean(lua_State* L)
- {
- BufferRef ref = checkNetBuffer(L);
- int offset = luax_checkinteger(L, 2);
- int len;
- bool boolean = ref->grabBoolean(&len, offset);
- luax_pushboolean(L, boolean);
- luax_pushinteger(L, len);
- return 2;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_NETWORK_BUFFER);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg netbuffer_function[] = {
- { "__gc", l_gc },
- { "append", l_append },
- { "grabString", l_grabString },
- { "grabInteger", l_grabInteger },
- { "grabBoolean", l_grabBoolean },
- { "grabFloat", l_grabFloat },
- { 0, 0 }
- };
-
- } // namespace Net
-
- int luaopen_Buffer(lua_State* L)
- {
- luax_newtype(L, JIN_NETWORK_BUFFER, Net::netbuffer_function);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/net/je_lua_buffer.cpp b/src/lua/modules/net/je_lua_buffer.cpp
new file mode 100644
index 0000000..0198095
--- /dev/null
+++ b/src/lua/modules/net/je_lua_buffer.cpp
@@ -0,0 +1,137 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_buffer.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Buffer = "Buffer";
+
+ typedef Shared<Net::Buffer>& SharedBuffer;
+
+ static inline SharedBuffer checkNetBuffer(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Buffer);
+ return proxy->getShared<Net::Buffer>();
+ }
+
+ // net.Buffer:append(value) -> value_length
+ LUA_IMPLEMENT int l_append(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ const int vp = 2;
+ if (luax_isintegerstrict(L, vp))
+ {
+ int n = luax_checkinteger(L, vp);
+ int size = sizeof(n);
+ shared->append(&n, size);
+ luax_pushinteger(L, size);
+ return 1;
+ }
+ else if (luax_isfloatstrict(L, vp))
+ {
+ float n = luax_checknumber(L, vp);
+ int size = sizeof(n);
+ shared->append(&n, size);
+ luax_pushinteger(L, size);
+ return 1;
+ }
+ else if (luax_isbooleanstrict(L, vp))
+ {
+ bool n = luax_checkbool(L, vp);
+ int size = sizeof(n);
+ shared->append(&n, size);
+ luax_pushinteger(L, size);
+ return 1;
+ }
+ else if (luax_isstringstrict(L, vp))
+ {
+ const char* str = luax_checkstring(L, vp);
+ int size = strlen(str) + 1;
+ shared->append(str, size);
+ luax_pushinteger(L, size);
+ return 1;
+ }
+ else
+ {
+ luax_typerror(L, vp, "number, bool or string");
+ return 0;
+ }
+ }
+
+ // net.Buffer:grabString(offset) -> string, length
+ LUA_IMPLEMENT int l_grabString(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ unsigned int len;
+ char* data = shared->grabString(&len, offset);
+ Array<char> str;
+ str.bind(data, len);
+ luax_pushstring(L, &str);
+ luax_pushinteger(L, str.count());
+ return 2;
+ }
+
+ // net.Buffer:grabInteger(offset) -> integer, length
+ LUA_IMPLEMENT int l_grabInteger(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ int len;
+ int integer = shared->grabInteger(&len, offset);
+ luax_pushinteger(L, integer);
+ luax_pushinteger(L, len);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_grabFloat(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ int len;
+ float floatv = shared->grabFloat(&len, offset);
+ luax_pushnumber(L, floatv);
+ luax_pushinteger(L, len);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_grabBoolean(lua_State* L)
+ {
+ SharedBuffer shared = checkNetBuffer(L);
+ int offset = luax_checkinteger(L, 2);
+ int len;
+ bool boolean = shared->grabBoolean(&len, offset);
+ luax_pushboolean(L, boolean);
+ luax_pushinteger(L, len);
+ return 2;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Buffer);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Buffer(lua_State* L)
+ {
+ luaL_Reg netbuffer_function[] = {
+ { "__gc", l_gc },
+ { "append", l_append },
+ { "grabString", l_grabString },
+ { "grabInteger", l_grabInteger },
+ { "grabBoolean", l_grabBoolean },
+ { "grabFloat", l_grabFloat },
+ { 0, 0 }
+ };
+
+ luax_newtype(L, Jin_Lua_Buffer, netbuffer_function);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/net/Buffer.h b/src/lua/modules/net/je_lua_buffer.h
index 8733778..d226640 100644
--- a/src/lua/modules/net/Buffer.h
+++ b/src/lua/modules/net/je_lua_buffer.h
@@ -3,12 +3,17 @@
#include <cstring>
#include <cstdlib>
-#include "lua/common/common.h"
+#include "lua/common/je_lua_common.h"
namespace JinEngine
{
namespace Lua
{
+
+ extern const char* Jin_Lua_Buffer;
+
+ void luaopen_Buffer(lua_State* L);
+
namespace Net
{
diff --git a/src/lua/modules/net/net.cpp b/src/lua/modules/net/je_lua_net.cpp
index 4ef9ece..b081733 100644
--- a/src/lua/modules/net/net.cpp
+++ b/src/lua/modules/net/je_lua_net.cpp
@@ -1,8 +1,10 @@
#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
+
#include "libjin/jin.h"
-#include "lua/common/common.h"
-#include "Buffer.h"
+#include "lua/common/je_lua_common.h"
+
+#include "je_lua_buffer.h"
+#include "je_lua_socket.h"
namespace JinEngine
{
@@ -12,13 +14,13 @@ namespace Lua
using namespace JinEngine::Lua::Net;
using namespace JinEngine::Net;
- static int l_initNetwork(lua_State* L)
+ LUA_IMPLEMENT int l_initNetwork(lua_State* L)
{
JinEngine::Net::NetManager::get()->init();
return 1;
}
- static int l_Socket(lua_State* L)
+ LUA_IMPLEMENT int l_Socket(lua_State* L)
{
SocketInformation info = { 0 };
{
@@ -48,35 +50,31 @@ namespace Lua
}
}
Socket* socket = new Socket(info);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_SOCKET, sizeof(Proxy));
- proxy->bind(new Ref<Socket>(socket, JIN_NETWORK_SOCKET));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Socket);
+ proxy->bind(new Shared<Socket>(socket, Jin_Lua_Socket));
return 1;
}
- static int l_Buffer(lua_State* L)
+ LUA_IMPLEMENT int l_Buffer(lua_State* L)
{
int size = luax_checkinteger(L, 1);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer);
Net::Buffer* buffer = new Net::Buffer(size);
- proxy->bind(new Ref<Buffer>(buffer, JIN_NETWORK_BUFFER));
+ proxy->bind(new Shared<Buffer>(buffer, Jin_Lua_Buffer));
return 1;
}
- static const luaL_Reg f[] = {
- { "init", l_initNetwork },
- { "newSocket", l_Socket },
- { "newBuffer", l_Buffer },
- { 0, 0 }
- };
-
- extern int luaopen_Socket(lua_State* L);
- extern int luaopen_Buffer(lua_State* L);
-
- int luaopen_net(lua_State* L)
+ LUA_EXPORT int luaopen_net(lua_State* L)
{
luaopen_Socket(L);
luaopen_Buffer(L);
-
+
+ luaL_Reg f[] = {
+ { "init", l_initNetwork },
+ { "newSocket", l_Socket },
+ { "newBuffer", l_Buffer },
+ { 0, 0 }
+ };
luax_newlib(L, f);
return 1;
diff --git a/src/lua/modules/net/je_lua_net.h b/src/lua/modules/net/je_lua_net.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/net/je_lua_net.h
diff --git a/src/lua/modules/net/je_lua_socket.cpp b/src/lua/modules/net/je_lua_socket.cpp
new file mode 100644
index 0000000..db170e4
--- /dev/null
+++ b/src/lua/modules/net/je_lua_socket.cpp
@@ -0,0 +1,129 @@
+#include "lua/modules/luax.h"
+
+#include "lua/common/je_lua_common.h"
+#include "libjin/jin.h"
+#include "je_lua_buffer.h"
+
+using namespace JinEngine::Net;
+using namespace JinEngine::Lua::Net;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Socket = "Socket";
+
+ typedef Shared<Socket>& SharedSocket;
+
+ const int BUFFER_SIZE = 1024;
+
+ LUA_IMPLEMENT inline SharedSocket checkSocket(lua_State* L, int pos = 1)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, pos, Jin_Lua_Socket);
+ return proxy->getShared<Socket>();
+ }
+
+ LUA_IMPLEMENT inline Shared<Buffer>& checkNetBuffer(lua_State* L, int pos = 1)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, pos, Jin_Lua_Buffer);
+ return proxy->getShared<Buffer>();
+ }
+
+ // return net.Socket
+ LUA_IMPLEMENT int l_accept(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ Socket* client = socket->accept();
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Socket);
+ proxy->bind(new Shared<Socket>(client, Jin_Lua_Socket));
+ return 1;
+ }
+
+ // return net.Buffer
+ LUA_IMPLEMENT int l_receive(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ char buffer[BUFFER_SIZE] = {0};
+ int size = socket->receive(buffer, BUFFER_SIZE);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer);
+ Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
+ proxy->bind(new Shared<Buffer>(netBuffer, Jin_Lua_Buffer));
+ return 1;
+ }
+
+ // Socket:receiveFrom(address, port)
+ LUA_IMPLEMENT int l_receiveFrom(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ int address = luax_checkinteger(L, 2);
+ int port = luax_checkinteger(L, 3);
+ char buffer[BUFFER_SIZE];
+ int size = socket->receiveFrom(buffer, BUFFER_SIZE, address, port);
+ Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer);
+ proxy->bind(new Shared<Buffer>(netBuffer, Jin_Lua_Buffer));
+ return 1;
+ }
+
+ // Socket:send(net.Buffer) -> data_length
+ LUA_IMPLEMENT int l_send(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ Shared<Buffer>& shared = checkNetBuffer(L, 2);
+ int len = socket->send(shared->buffer, shared->size);
+ luax_pushinteger(L, len);
+ return 1;
+ }
+
+ // Socket:sendTo(address, port, net.Buffer)
+ LUA_IMPLEMENT int l_sendTo(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ int address = luax_checkinteger(L, 2);
+ int port = luax_checkinteger(L, 3);
+ Shared<Buffer>& buffer = checkNetBuffer(L, 4);
+ socket->sendTo(buffer->buffer, buffer->size, address, port);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_close(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ socket->close();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_configBlocking(lua_State* L)
+ {
+ SharedSocket socket = checkSocket(L);
+ bool blocking = luax_checkbool(L, 2);
+ socket->configureBlocking(blocking);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Socket);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Socket(lua_State* L)
+ {
+ luaL_Reg socket_function[] = {
+ { "__gc", l_gc },
+ { "accept", l_accept },
+ { "receive", l_receive },
+ { "receiveFrom", l_receiveFrom },
+ { "send", l_send },
+ { "sendTo", l_sendTo },
+ { "close", l_close },
+ { "configBlocking", l_configBlocking },
+ { 0, 0 }
+ };
+ luax_newtype(L, Jin_Lua_Socket, socket_function);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/net/je_lua_socket.h b/src/lua/modules/net/je_lua_socket.h
new file mode 100644
index 0000000..b33fac6
--- /dev/null
+++ b/src/lua/modules/net/je_lua_socket.h
@@ -0,0 +1,16 @@
+#ifndef __JE_LUA_SOCKET_H__
+#define __JE_LUA_SOCKET_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Socket;
+
+ void luaopen_Socket(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/net/socket.cpp b/src/lua/modules/net/socket.cpp
deleted file mode 100644
index d6de730..0000000
--- a/src/lua/modules/net/socket.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "lua/common/common.h"
-#include "libjin/jin.h"
-#include "Buffer.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Net;
- using namespace Lua::Net;
-
- typedef Ref<Socket>& SocketRef;
-
- const int BUFFER_SIZE = 1024;
-
- static inline SocketRef checkSocket(lua_State* L, int pos = 1)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, pos, JIN_NETWORK_SOCKET);
- return proxy->getRef<Socket>();
- }
-
- static inline Ref<Buffer>& checkNetBuffer(lua_State* L, int pos = 1)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, pos, JIN_NETWORK_BUFFER);
- return proxy->getRef<Buffer>();
- }
-
- // return net.Socket
- static int l_accept(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- Socket* client = socket->accept();
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_SOCKET, sizeof(Proxy));
- proxy->bind(new Ref<Socket>(client, JIN_NETWORK_SOCKET));
- return 1;
- }
-
- // return net.Buffer
- static int l_receive(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- char buffer[BUFFER_SIZE] = {0};
- int size = socket->receive(buffer, BUFFER_SIZE);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy));
- Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
- proxy->bind(new Ref<Buffer>(netBuffer, JIN_NETWORK_BUFFER));
- return 1;
- }
-
- // Socket:receiveFrom(address, port)
- static int l_receiveFrom(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- int address = luax_checkinteger(L, 2);
- int port = luax_checkinteger(L, 3);
- char buffer[BUFFER_SIZE];
- int size = socket->receiveFrom(buffer, BUFFER_SIZE, address, port);
- Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy));
- proxy->bind(new Ref<Buffer>(netBuffer, JIN_NETWORK_BUFFER));
- return 1;
- }
-
- // Socket:send(net.Buffer) -> data_length
- static int l_send(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- Ref<Buffer>& ref = checkNetBuffer(L, 2);
- int len = socket->send(ref->buffer, ref->size);
- luax_pushinteger(L, len);
- return 1;
- }
-
- // Socket:sendTo(address, port, net.Buffer)
- static int l_sendTo(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- int address = luax_checkinteger(L, 2);
- int port = luax_checkinteger(L, 3);
- Ref<Buffer>& buffer = checkNetBuffer(L, 4);
- socket->sendTo(buffer->buffer, buffer->size, address, port);
- return 0;
- }
-
- static int l_close(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- socket->close();
- return 0;
- }
-
- static int l_configBlocking(lua_State* L)
- {
- SocketRef socket = checkSocket(L);
- bool blocking = luax_checkbool(L, 2);
- socket->configureBlocking(blocking);
- return 0;
- }
-
- static int l_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_NETWORK_SOCKET);
- proxy->release();
- return 0;
- }
-
- static const luaL_Reg socket_function[] = {
- { "__gc", l_gc },
- { "accept", l_accept },
- { "receive", l_receive },
- { "receiveFrom", l_receiveFrom },
- { "send", l_send },
- { "sendTo", l_sendTo },
- { "close", l_close },
- { "configBlocking", l_configBlocking },
- { 0, 0 }
- };
-
- int luaopen_Socket(lua_State* L)
- {
- luax_newtype(L, JIN_NETWORK_SOCKET, socket_function);
- return 0;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/thread/Thread.cpp b/src/lua/modules/thread/Thread.cpp
deleted file mode 100644
index e1c5a92..0000000
--- a/src/lua/modules/thread/Thread.cpp
+++ /dev/null
@@ -1,252 +0,0 @@
-#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
-#include "libjin/jin.h"
-#include "lua/jin.h"
-#include "lua/common/common.h"
-#include "thread.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using thread::Thread;
-
- typedef Ref<Thread>& ThreadRef;
-
- int luaopen_thread(lua_State* L);
-
- static inline ThreadRef checkThread(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_THREAD_THREAD);
- return proxy->getRef<Thread>();
- }
-
- static int threadRunner(void* t)
- {
- ThreadRef ref = *(Ref<Thread>*)t;
- lua_State* L = lua_open();
- luax_openlibs(L);
- luaopen_jin(L);
- luax_getglobal(L, MODULE_NAME);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_THREAD_THREAD, sizeof(Proxy));
- ref.retain();
- proxy->bind(&ref);
- luax_setfield(L, -2, "_curThread");
- luax_dostring(L, ref->code.c_str());
- luax_close(L);
- return 0;
- }
-
- static int l_thread_gc(lua_State* L)
- {
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_THREAD_THREAD);
- proxy->release();
- return 0;
- }
-
- static int l_start(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- bool result = ref->start(&ref);
- luax_pushboolean(L, result);
- return 1;
- }
-
- static int l_wait(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- ref->wait();
- return 0;
- }
-
- static int l_send(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- int slot = luax_checkinteger(L, 2);
- const int vp = 3;
- if (luax_isnumberstrict(L, vp))
- {
- float real = luax_checknumber(L, vp);
- ref->send(slot, real);
- }
- else if (luax_isbooleanstrict(L, vp))
- {
- bool bol = luax_checkbool(L, vp);
- ref->send(slot, bol);
- }
- else if (luax_isstringstrict(L, vp))
- {
- const char* str = luax_checkstring(L, vp);
- ref->send(slot, str);
- }
- else if (luax_isuserdata(L, vp))
- {
- void* p = luax_touserdata(L, vp);
- ref->send(slot, p);
- }
- else if (luax_islightuserdata(L, vp))
- {
- void* p = luax_tolightuserdata(L, vp);
- ref->send(slot, p);
- }
- return 0;
- }
-
- static int l_receive(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- int slot = luax_checkinteger(L, 2);
- bool result = ref->receive(slot);
- luax_pushboolean(L, result);
- return 1;
- }
-
- static int l_fetch(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- int slot = luax_checkinteger(L, 2);
- Thread::Variant v = ref->fetch(slot);
- switch (v.type)
- {
- case thread::Thread::Variant::INTERGER:
- luax_pushinteger(L, v.integer);
- break;
-
- case thread::Thread::Variant::BOOLEAN:
- luax_pushboolean(L, v.boolean);
- break;
-
- case thread::Thread::Variant::CSTRING:
- luax_pushstring(L, v.cstring);
- break;
-
- case thread::Thread::Variant::REAL:
- luax_pushnumber(L, v.real);
- break;
-
- case thread::Thread::Variant::POINTER:
- Proxy* p = (Proxy*)v.pointer;
- Proxy* proxy = (Proxy*)luax_newinstance(L, p->getObjectType(), sizeof(Proxy));
- p->reference->retain();
- proxy->bind(p->reference);
- break;
-
- }
- return 1;
- }
-
- static int l_demand(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- int slot = luax_checkinteger(L, 2);
- Thread::Variant v = ref->demand(slot);
- switch (v.type)
- {
- case thread::Thread::Variant::INTERGER:
- luax_pushinteger(L, v.integer);
- break;
-
- case thread::Thread::Variant::BOOLEAN:
- luax_pushboolean(L, v.boolean);
- break;
-
- case thread::Thread::Variant::CSTRING:
- luax_pushstring(L, v.cstring);
- break;
-
- case thread::Thread::Variant::REAL:
- luax_pushnumber(L, v.real);
- break;
-
- case thread::Thread::Variant::POINTER:
- Proxy* p = (Proxy*)v.pointer;
- const char* objType = p->getObjectType();
- Proxy* proxy = (Proxy*)luax_newinstance(L, objType, sizeof(Proxy));
- p->reference->retain();
- proxy->bind(p->reference);
- break;
-
- }
- return 1;
- }
-
- static int l_remove(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- int slot = luax_checkinteger(L, 2);
- ref->remove(slot);
- return 0;
- }
-
- static int l_getName(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- const char* name = ref->getName();
- luax_pushstring(L, name);
- return 1;
- }
-
- static int l_isRunning(lua_State* L)
- {
- ThreadRef ref = checkThread(L);
- bool running = ref->isRunning();
- luax_pushboolean(L, running);
- return 1;
- }
-
- static const luaL_Reg thread_function[] = {
- { "__gc", l_thread_gc },
- { "start", l_start },
- { "wait", l_wait },
- { "send", l_send },
- { "receive", l_receive },
- { "fetch", l_fetch },
- { "demand", l_demand },
- { "remove", l_remove },
- { "getName", l_getName },
- { "isRunning", l_isRunning },
- { 0, 0 }
- };
-
- static int luaopen_Thread(lua_State* L)
- {
- luax_newtype(L, JIN_THREAD_THREAD, thread_function);
-
- return 0;
- }
-
- static int l_newThread(lua_State* L)
- {
- const char* name = luax_checkstring(L, 1);
- const char* code = luax_checkstring(L, 2);
- Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_THREAD_THREAD, sizeof(Proxy));
- Thread* thread = new Thread(name, code, threadRunner);
- proxy->bind(new Ref<Thread>(thread, JIN_THREAD_THREAD));
- return 1;
- }
-
- static int l_getThread(lua_State* L)
- {
- luax_getglobal(L, MODULE_NAME);
- luax_getfield(L, -1, "_curThread");
- return 1;
- }
-
- static const luaL_Reg f[] = {
- { "newThread", l_newThread },
- { "getThread", l_getThread },
- { 0, 0 }
- };
-
- int luaopen_thread(lua_State* L)
- {
- luaopen_Thread(L);
-
- luax_newlib(L, f);
-
- return 1;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/thread/Thread.h b/src/lua/modules/thread/Thread.h
deleted file mode 100644
index 60d588a..0000000
--- a/src/lua/modules/thread/Thread.h
+++ /dev/null
@@ -1,94 +0,0 @@
-#include "libjin/jin.h"
-#include "lua/common/common.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
- namespace thread
- {
-
- class Thread
- {
- public:
- typedef JinEngine::MultiThread::Thread::Variant Variant;
- typedef JinEngine::MultiThread::Thread::ThreadRunner ThreadRunner;
-
- Thread(std::string _name, std::string _code, ThreadRunner runner)
- : name(_name)
- , code(_code)
- {
- thread = new JinEngine::MultiThread::Thread(_name, runner);
- }
-
- ~Thread()
- {
- delete thread;
- }
-
- bool start(void* p)
- {
- return thread->start(p);
- }
-
- void wait()
- {
- thread->wait();
- }
-
- void send(int slot, const Variant& value)
- {
- thread->send(slot, value);
- }
-
- bool receive(int slot)
- {
- return thread->receive(slot);
- }
-
- Variant fetch(int slot)
- {
- return thread->fetch(slot);
- }
-
- Variant demand(int slot)
- {
- return thread->demand(slot);
- }
-
- void remove(int slot)
- {
- thread->remove(slot);
- }
-
- const char* getName()
- {
- return name.c_str();
- }
-
- bool isRunning()
- {
- return thread->isRunning();
- }
-
- void lock()
- {
- thread->lock();
- }
-
- void unlock()
- {
- thread->unlock();
- }
-
- const std::string name;
- const std::string code;
-
- private:
- JinEngine::MultiThread::Thread* thread;
-
- };
-
- } // thread
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/thread/je_lua_thread.cpp b/src/lua/modules/thread/je_lua_thread.cpp
new file mode 100644
index 0000000..d7b50ab
--- /dev/null
+++ b/src/lua/modules/thread/je_lua_thread.cpp
@@ -0,0 +1,248 @@
+#include "lua/modules/luax.h"
+
+#include "libjin/jin.h"
+#include "lua/jin.h"
+#include "lua/common/je_lua_common.h"
+#include "je_lua_thread.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Thread = "Thread";
+
+ typedef Shared<Thread>& SharedThread;
+
+ int luaopen_thread(lua_State* L);
+
+ static inline SharedThread checkThread(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Thread);
+ return proxy->getShared<Thread>();
+ }
+
+ LUA_IMPLEMENT int threadRunner(void* t)
+ {
+ SharedThread shared = *(Shared<Thread>*)t;
+ lua_State* L = lua_open();
+ luax_openlibs(L);
+ luaopen_jin(L);
+ luax_getglobal(L, MODULE_NAME);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Thread);
+ proxy->bind(&shared);
+ luax_setfield(L, -2, "_curThread");
+ luax_dostring(L, shared->code.c_str());
+ luax_close(L);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_thread_gc(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Thread);
+ proxy->release();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_start(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ bool result = shared->start(&shared);
+ luax_pushboolean(L, result);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_wait(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ shared->wait();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_send(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ int slot = luax_checkinteger(L, 2);
+ const int vp = 3;
+ if (luax_isnumberstrict(L, vp))
+ {
+ float real = luax_checknumber(L, vp);
+ shared->send(slot, real);
+ }
+ else if (luax_isbooleanstrict(L, vp))
+ {
+ bool bol = luax_checkbool(L, vp);
+ shared->send(slot, bol);
+ }
+ else if (luax_isstringstrict(L, vp))
+ {
+ const char* str = luax_checkstring(L, vp);
+ shared->send(slot, str);
+ }
+ else if (luax_isuserdata(L, vp))
+ {
+ void* p = luax_touserdata(L, vp);
+ shared->send(slot, p);
+ }
+ else if (luax_islightuserdata(L, vp))
+ {
+ void* p = luax_tolightuserdata(L, vp);
+ shared->send(slot, p);
+ }
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_receive(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ int slot = luax_checkinteger(L, 2);
+ bool result = shared->receive(slot);
+ luax_pushboolean(L, result);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_fetch(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ int slot = luax_checkinteger(L, 2);
+ Thread::Variant v = shared->fetch(slot);
+ switch (v.type)
+ {
+ case Thread::Variant::INTERGER:
+ luax_pushinteger(L, v.integer);
+ break;
+
+ case Thread::Variant::BOOLEAN:
+ luax_pushboolean(L, v.boolean);
+ break;
+
+ case Thread::Variant::CSTRING:
+ luax_pushstring(L, v.cstring);
+ break;
+
+ case Thread::Variant::REAL:
+ luax_pushnumber(L, v.real);
+ break;
+
+ case Thread::Variant::POINTER:
+ Proxy* p = (Proxy*)v.pointer;
+ Proxy* proxy = luax_newinstance(L, p->getObjectType());
+ proxy->bind(p->shared);
+ break;
+
+ }
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_demand(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ int slot = luax_checkinteger(L, 2);
+ Thread::Variant v = shared->demand(slot);
+ switch (v.type)
+ {
+ case Thread::Variant::INTERGER:
+ luax_pushinteger(L, v.integer);
+ break;
+
+ case Thread::Variant::BOOLEAN:
+ luax_pushboolean(L, v.boolean);
+ break;
+
+ case Thread::Variant::CSTRING:
+ luax_pushstring(L, v.cstring);
+ break;
+
+ case Thread::Variant::REAL:
+ luax_pushnumber(L, v.real);
+ break;
+
+ case Thread::Variant::POINTER:
+ Proxy* p = (Proxy*)v.pointer;
+ const char* objType = p->getObjectType();
+ Proxy* proxy = luax_newinstance(L, objType);
+ proxy->bind(p->shared);
+ break;
+
+ }
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_remove(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ int slot = luax_checkinteger(L, 2);
+ shared->remove(slot);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_getName(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ const char* name = shared->getName();
+ luax_pushstring(L, name);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_isRunning(lua_State* L)
+ {
+ SharedThread shared = checkThread(L);
+ bool running = shared->isRunning();
+ luax_pushboolean(L, running);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int luaopen_Thread(lua_State* L)
+ {
+ luaL_Reg thread_function[] = {
+ { "__gc", l_thread_gc },
+ { "start", l_start },
+ { "wait", l_wait },
+ { "send", l_send },
+ { "receive", l_receive },
+ { "fetch", l_fetch },
+ { "demand", l_demand },
+ { "remove", l_remove },
+ { "getName", l_getName },
+ { "isRunning", l_isRunning },
+ { 0, 0 }
+ };
+
+ luax_newtype(L, Jin_Lua_Thread, thread_function);
+
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_newThread(lua_State* L)
+ {
+ const char* name = luax_checkstring(L, 1);
+ const char* code = luax_checkstring(L, 2);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Thread);
+ Thread* thread = new Thread(name, code, threadRunner);
+ proxy->bind(new Shared<Thread>(thread, Jin_Lua_Thread));
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getThread(lua_State* L)
+ {
+ luax_getglobal(L, MODULE_NAME);
+ luax_getfield(L, -1, "_curThread");
+ return 1;
+ }
+
+ LUA_EXPORT int luaopen_thread(lua_State* L)
+ {
+ luaopen_Thread(L);
+
+ luaL_Reg f[] = {
+ { "newThread", l_newThread },
+ { "getThread", l_getThread },
+ { 0, 0 }
+ };
+ luax_newlib(L, f);
+
+ return 1;
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/thread/je_lua_thread.h b/src/lua/modules/thread/je_lua_thread.h
new file mode 100644
index 0000000..a3e4e76
--- /dev/null
+++ b/src/lua/modules/thread/je_lua_thread.h
@@ -0,0 +1,93 @@
+#include "libjin/jin.h"
+#include "lua/common/je_lua_common.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Thread;
+
+ class Thread
+ {
+ public:
+ typedef JinEngine::Threads::Thread::Variant Variant;
+ typedef JinEngine::Threads::Thread::ThreadRunner ThreadRunner;
+
+ Thread(std::string _name, std::string _code, ThreadRunner runner)
+ : name(_name)
+ , code(_code)
+ {
+ thread = new JinEngine::Threads::Thread(_name, runner);
+ }
+
+ ~Thread()
+ {
+ delete thread;
+ }
+
+ bool start(void* p)
+ {
+ return thread->start(p);
+ }
+
+ void wait()
+ {
+ thread->wait();
+ }
+
+ void send(int slot, const Variant& value)
+ {
+ thread->send(slot, value);
+ }
+
+ bool receive(int slot)
+ {
+ return thread->receive(slot);
+ }
+
+ Variant fetch(int slot)
+ {
+ return thread->fetch(slot);
+ }
+
+ Variant demand(int slot)
+ {
+ return thread->demand(slot);
+ }
+
+ void remove(int slot)
+ {
+ thread->remove(slot);
+ }
+
+ const char* getName()
+ {
+ return name.c_str();
+ }
+
+ bool isRunning()
+ {
+ return thread->isRunning();
+ }
+
+ void lock()
+ {
+ thread->lock();
+ }
+
+ void unlock()
+ {
+ thread->unlock();
+ }
+
+ const std::string name;
+ const std::string code;
+
+ private:
+ JinEngine::Threads::Thread* thread;
+
+ };
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/time/je_lua_time.cpp b/src/lua/modules/time/je_lua_time.cpp
new file mode 100644
index 0000000..39ec899
--- /dev/null
+++ b/src/lua/modules/time/je_lua_time.cpp
@@ -0,0 +1,71 @@
+#include "SDL2/SDL.h"
+#include "lua/common/je_lua_common.h"
+#include "lua/modules/luax.h"
+#include "libjin/jin.h"
+
+
+#include "je_lua_timer.h"
+
+using namespace JinEngine::Time;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ static struct
+ {
+ float previous;
+ float current;
+ } context;
+
+ LUA_IMPLEMENT int l_sec(lua_State* L)
+ {
+ luax_pushnumber(L, getSecond());
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_sleep(lua_State* L)
+ {
+ double sec = luax_checknumber(L, 1);
+ sleep(sec * 1000.0f);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_newTimer(lua_State* L)
+ {
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Timer);
+ proxy->bind(new Shared<Timer>(new Timer(), Jin_Lua_Timer));
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_getDelta(lua_State* L)
+ {
+ luax_pushnumber(L, context.current - context.previous);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_step(lua_State* L)
+ {
+ context.previous = context.current;
+ context.current = getSecond();
+ return 0;
+ }
+
+ LUA_EXPORT int luaopen_time(lua_State* L)
+ {
+ luaopen_Timer(L);
+ luaL_Reg f[] = {
+ { "second", l_sec },
+ { "sleep", l_sleep },
+ { "newTimer", l_newTimer },
+ { "step", l_step },
+ { "getDelta", l_getDelta },
+ { 0, 0 },
+ };
+ luax_newlib(L, f);
+ return 1;
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/time/je_lua_time.h b/src/lua/modules/time/je_lua_time.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lua/modules/time/je_lua_time.h
diff --git a/src/lua/modules/time/je_lua_timer.cpp b/src/lua/modules/time/je_lua_timer.cpp
new file mode 100644
index 0000000..540f205
--- /dev/null
+++ b/src/lua/modules/time/je_lua_timer.cpp
@@ -0,0 +1,146 @@
+
+#include "lua/common/je_lua_callback.h"
+#include "lua/common/je_lua_common.h"
+#include "je_lua_timer.h"
+
+using namespace JinEngine::Time;
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ const char* Jin_Lua_Timer = "Timer";
+
+ const char* Jin_Lua_Handler = "Handler";
+
+ typedef Shared<Timer>& SharedTimer;
+
+ static Timer::TimerCallback timerCallback = [](void* data)->void
+ {
+ LuaCallback* func = static_cast<LuaCallback*>(data);
+ func->call();
+ };
+
+ static Timer::FinishCallback finishCallback = [](void* data)->void
+ {
+ LuaCallback* func = static_cast<LuaCallback*>(data);
+ delete func;
+ };
+
+ LUA_IMPLEMENT inline SharedTimer checkTimer(lua_State* L)
+ {
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Timer);
+ return proxy->getShared<Timer>();
+ }
+
+ // timer:every(time, callback, parameter)
+ LUA_IMPLEMENT int l_every(lua_State* L)
+ {
+ int n = luax_gettop(L);
+ SharedTimer shared = checkTimer(L);
+ Timer* timer = shared.getObject();
+ float s = luax_checknumber(L, 2);
+ LuaCallback* func = new LuaCallback(L);
+ func->setFunc(3);
+ for(int i = 4; i <= n; ++i)
+ func->pushParam(i);
+ Timer::Handler* handler = timer->every(s, timerCallback, func, finishCallback);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Handler);
+ Shared<Timer::Handler>* shrHandler = new Shared<Timer::Handler>(handler, Jin_Lua_Handler);
+ shrHandler->retain();
+ proxy->bind(shrHandler);
+ return 1;
+ }
+
+ // timer:after(time, callback, parameter)
+ LUA_IMPLEMENT int l_after(lua_State* L)
+ {
+ int n = luax_gettop(L);
+ SharedTimer shared = checkTimer(L);
+ Timer* timer = shared.getObject();
+ float s = luax_checknumber(L, 2);
+ LuaCallback* func = new LuaCallback(L);
+ func->setFunc(3);
+ for (int i = 4; i <= n; ++i)
+ func->pushParam(i);
+ Timer::Handler* handler = timer->after(s, timerCallback, func, finishCallback);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Handler);
+ Shared<Timer::Handler>* shrHandler = new Shared<Timer::Handler>(handler, Jin_Lua_Handler);
+ shrHandler->retain();
+ proxy->bind(shrHandler);
+ return 1;
+ }
+
+ // timer:repeat(time, callback, parameter)
+ LUA_IMPLEMENT int l_repeat(lua_State* L)
+ {
+ int n = luax_gettop(L);
+ SharedTimer shared = checkTimer(L);
+ Timer* timer = shared.getObject();
+ float s = luax_checknumber(L, 2);
+ int count = luax_checkinteger(L, 3);
+ LuaCallback* func = new LuaCallback(L);
+ func->setFunc(4);
+ for (int i = 5; i <= n; ++i)
+ func->pushParam(i);
+ Timer::Handler* handler = timer->repeat(s, count, timerCallback, func, finishCallback);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Handler);
+ Shared<Timer::Handler>* shrHandler = new Shared<Timer::Handler>(handler, Jin_Lua_Handler);
+ shrHandler->retain();
+ proxy->bind(shrHandler);
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_update(lua_State* L)
+ {
+ SharedTimer shared = checkTimer(L);
+ Timer* timer = shared.getObject();
+ float s = luax_checknumber(L, 2);
+ timer->update(s);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_cancel(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Timer);
+ Timer* timer = p->getObject<Timer>();
+ Proxy* ph = (Proxy*)luax_checktype(L, 2, Jin_Lua_Handler);
+ Timer::Handler* handler = ph->getObject<Timer::Handler>();
+ timer->cancel(handler);
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_cancelAll(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Timer);
+ Timer* timer = p->getObject<Timer>();
+ timer->cancelAll();
+ return 0;
+ }
+
+ LUA_IMPLEMENT int l_gc(lua_State* L)
+ {
+ Proxy* p = (Proxy*)luax_checktype(L, 1, Jin_Lua_Timer);
+ p->release();
+ return 0;
+ }
+
+ LUA_EXPORT void luaopen_Timer(lua_State* L)
+ {
+ luaL_Reg f[] = {
+ { "__gc", l_gc },
+ { "every", l_every },
+ { "after", l_after },
+ { "duplicate", l_repeat },
+ { "update", l_update },
+ { "cancel", l_cancel },
+ { "cancelAll", l_cancelAll },
+ { 0, 0 }
+ };
+
+ luax_newtype(L, Jin_Lua_Timer, f);
+ }
+
+ }
+} \ No newline at end of file
diff --git a/src/lua/modules/time/je_lua_timer.h b/src/lua/modules/time/je_lua_timer.h
new file mode 100644
index 0000000..35ec15d
--- /dev/null
+++ b/src/lua/modules/time/je_lua_timer.h
@@ -0,0 +1,20 @@
+#ifndef __JE_LUA_TIMER_H__
+#define __JE_LUA_TIMER_H__
+
+#include "libjin/jin.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern const char* Jin_Lua_Timer;
+
+ extern const char* Jin_Lua_Handler;
+
+ void luaopen_Timer(lua_State* L);
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/time/time.cpp b/src/lua/modules/time/time.cpp
deleted file mode 100644
index f6e6f26..0000000
--- a/src/lua/modules/time/time.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-#include "lua/modules/luax.h"
-#include <SDL2/SDL.h>
-#include "libjin/jin.h"
-
-namespace JinEngine
-{
- namespace Lua
- {
-
- using namespace JinEngine::Time;
-
- static int l_sec(lua_State* L)
- {
- luax_pushnumber(L, getSecond());
- return 1;
- }
-
- static int l_sleep(lua_State* L)
- {
- double sec = luax_checknumber(L, 1);
- sleep(sec * 1000.0f);
- return 0;
- }
-
- static const luaL_Reg f[] = {
- { "second", l_sec },
- { "sleep", l_sleep },
- { 0, 0 },
- };
-
- int luaopen_time(lua_State* L)
- {
- luax_newlib(L, f);
- return 1;
- }
-
- } // namespace Lua
-} // namespace JinEngine \ No newline at end of file
diff --git a/src/lua/modules/types.h b/src/lua/modules/types.h
deleted file mode 100644
index 123604e..0000000
--- a/src/lua/modules/types.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#ifndef __JIN_MODULES_TYPES_H
-#define __JIN_MODULES_TYPES_H
-
-// graphics module
-#define JIN_GRAPHICS_TEXTURE "Texture"
-#define JIN_GRAPHICS_SHADER "Shader"
-#define JIN_GRAPHICS_CANVAS "Canvas"
-#define JIN_GRAPHICS_TEXT "Text"
-#define JIN_GRAPHICS_TTFDATA "TTFData"
-#define JIN_GRAPHICS_TTF "TTF"
-#define JIN_GRAPHICS_TEXTUREFONT "TextureFont"
-#define JIN_GRAPHICS_PAGE "Page"
-#define JIN_GRAPHICS_BITMAP "Bitmap"
-
-// audio module
-#define JIN_AUDIO_SOURCE "Source"
-
-// thread module
-#define JIN_THREAD_THREAD "Thread"
-
-// network module
-#define JIN_NETWORK_SOCKET "Socket"
-#define JIN_NETWORK_BUFFER "Buffer"
-
-#endif \ No newline at end of file
diff --git a/src/lua/resources/font.ttf b/src/lua/resources/font.ttf
deleted file mode 100644
index 153c608..0000000
--- a/src/lua/resources/font.ttf
+++ /dev/null
Binary files differ
diff --git a/src/lua/resources/font.ttf.h b/src/lua/resources/font.ttf.h
index bb0734f..b220738 100644
--- a/src/lua/resources/font.ttf.h
+++ b/src/lua/resources/font.ttf.h
@@ -2,361 +2,365 @@ static const char
default_font_bitmap[] =
{ 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,3,154,0,0,0,14,8,6,0,0,0,78,
234,99,67,0,0,0,4,103,65,77,65,0,0,177,143,11,252,97,5,0,0,0,9,112,72,89,115,
-0,0,14,194,0,0,14,194,1,21,40,74,128,0,0,0,25,116,69,88,116,83,111,102,116,
-119,97,114,101,0,112,97,105,110,116,46,110,101,116,32,52,46,48,46,50,49,241,
-32,105,149,0,0,29,22,73,68,65,84,120,94,237,92,61,168,109,75,82,126,8,134,166,
-26,138,32,152,152,60,16,68,12,6,28,159,130,136,129,58,193,168,136,99,96,224,4,
-38,47,83,208,64,197,224,129,168,32,19,61,13,12,100,20,20,196,72,196,216,159,
-200,68,19,49,209,72,65,20,19,17,217,246,87,95,215,174,175,126,122,239,117,206,
-61,87,158,48,181,169,123,86,87,125,93,93,127,221,107,173,125,238,189,31,220,
-62,184,221,192,31,20,114,249,164,115,82,204,35,28,232,10,238,10,6,116,21,7,
-122,132,123,169,141,43,248,9,247,104,222,132,159,104,194,169,76,229,87,232,
-234,188,171,56,208,251,192,42,238,132,125,164,3,93,153,251,104,62,232,165,184,
-61,124,74,111,105,247,173,48,78,142,189,106,243,25,206,233,125,224,21,115,5,
-183,135,15,73,237,93,153,243,8,127,146,59,61,211,43,93,193,94,193,76,164,243,
-174,206,125,41,30,116,117,206,85,92,165,151,204,187,130,123,169,173,183,198,
-130,94,138,175,116,117,238,75,214,120,107,155,142,59,97,85,127,194,40,93,197,
-190,47,123,255,223,112,239,34,175,58,167,147,254,165,114,167,103,122,208,85,
-125,197,60,155,7,58,97,92,94,117,39,185,147,234,79,24,167,215,98,183,40,209,
-85,253,30,38,250,44,233,78,228,115,222,199,188,43,24,165,151,226,157,238,243,
-238,179,11,87,73,30,5,87,73,30,5,87,201,73,174,60,75,201,251,74,13,236,208,44,
-56,149,143,137,169,24,227,219,237,211,197,159,96,164,100,200,140,221,154,32,
-67,60,192,108,41,237,63,192,41,65,119,199,125,225,126,5,255,64,159,222,37,87,
-109,56,95,141,243,118,251,207,197,95,18,153,95,125,105,241,191,44,254,72,116,
-160,143,22,67,14,253,182,58,218,197,218,234,191,243,158,241,152,128,147,57,
-199,121,134,186,128,3,25,242,141,177,134,202,184,132,13,73,215,57,153,246,160,
-47,186,113,62,200,80,47,199,109,233,153,10,254,157,236,190,22,115,31,9,155,60,
-99,111,183,95,76,163,96,236,171,44,225,124,149,40,87,252,201,238,98,179,195,
-79,72,39,60,100,85,250,28,71,251,170,87,238,113,53,155,105,254,35,31,186,46,
-143,170,190,172,147,248,9,214,124,226,231,136,1,59,37,121,181,13,158,236,203,
-120,152,147,71,19,243,19,146,193,63,227,151,246,214,98,211,95,181,15,86,108,
-220,35,50,171,31,143,108,213,92,20,172,249,230,227,11,88,208,93,246,0,159,112,
-39,214,249,101,173,196,15,112,109,157,215,216,204,81,100,230,39,75,116,148,
-237,144,79,53,3,87,123,87,234,187,174,156,18,6,156,113,87,237,129,243,200,185,
-198,115,202,97,197,93,93,247,5,254,89,188,252,60,151,187,159,83,61,106,12,29,
-51,219,124,34,119,50,237,3,61,200,16,131,254,46,169,62,241,185,235,171,246,
-211,101,37,14,167,53,138,185,154,223,154,83,159,95,215,42,118,155,158,188,87,
-203,4,185,96,140,183,106,164,132,173,189,48,244,64,26,169,95,213,103,126,56,
-170,118,31,205,203,107,102,221,213,245,234,188,194,78,107,148,145,213,230,137,
-235,188,136,239,227,197,246,204,63,229,206,214,84,137,114,181,249,12,239,172,
-243,170,206,185,74,242,40,184,74,242,40,184,74,110,183,111,177,171,42,87,158,
-165,228,125,165,6,44,120,144,73,67,62,54,115,197,24,127,150,95,52,127,198,254,
-140,23,185,223,16,221,85,27,206,95,123,209,108,100,200,55,198,26,42,227,18,54,
-36,93,231,100,90,215,127,238,126,69,198,56,75,246,172,76,134,122,57,110,75,
-207,84,240,239,100,247,181,152,61,66,191,253,215,98,28,166,91,107,31,31,129,
-208,155,255,97,87,65,31,167,27,4,56,231,24,125,170,212,241,92,179,18,15,116,
-112,173,209,140,255,56,97,136,171,107,35,190,105,47,130,43,246,147,230,39,152,
-107,227,129,228,195,197,154,191,121,63,234,126,206,58,191,58,157,3,176,143,
-117,162,30,92,163,198,0,106,103,198,146,103,223,163,118,147,239,96,207,233,
-148,71,215,225,204,83,13,108,230,135,51,112,212,223,99,80,98,60,189,166,19,
-246,211,39,189,5,127,148,162,103,122,252,115,47,64,171,190,240,97,164,246,121,
-238,217,217,87,167,220,3,90,223,37,145,156,247,126,9,187,17,71,240,132,71,252,
-181,38,192,193,119,91,111,115,239,49,214,33,114,16,56,158,1,129,59,249,132,49,
-228,31,10,214,251,164,18,253,113,92,212,16,54,156,24,71,237,11,222,179,29,155,
-237,56,19,83,107,50,219,99,125,61,78,16,99,128,141,192,89,157,64,91,18,121,
-201,56,183,87,251,240,211,182,238,28,115,206,31,184,219,114,202,251,146,235,
-106,190,89,75,237,211,25,199,28,214,56,118,204,38,189,34,143,124,79,231,133,
-238,159,169,102,179,205,39,114,39,211,62,208,131,12,81,244,50,3,53,168,123,
-169,159,101,148,165,115,21,180,116,97,155,189,135,154,125,210,114,202,121,167,
-179,253,247,22,255,214,226,222,3,228,189,90,38,200,5,99,188,85,35,37,44,123,1,
-107,195,223,143,90,175,68,143,118,191,217,67,244,21,18,245,131,57,240,30,203,
-245,14,57,251,83,115,20,235,193,159,156,7,250,192,61,7,137,174,151,253,244,
-125,76,251,148,123,236,49,7,76,223,177,14,40,98,9,121,95,11,204,188,229,179,
-170,230,46,143,126,121,49,124,1,127,197,100,213,102,196,0,174,123,62,98,1,206,
-81,129,207,92,37,121,20,92,37,252,243,27,23,255,210,226,239,218,227,9,247,23,
-139,191,167,201,149,103,41,121,95,169,97,43,16,200,164,33,31,155,185,98,140,
-125,211,149,41,134,204,216,173,9,50,196,3,204,150,210,254,3,156,18,116,119,28,
-27,6,5,196,38,255,176,52,203,158,209,201,80,129,35,95,141,19,27,43,31,64,170,
-173,58,208,243,195,141,184,126,88,146,247,140,199,4,156,204,57,206,51,212,5,
-28,200,144,111,140,53,84,198,37,108,72,186,206,201,180,174,231,161,136,220,
-242,32,173,249,31,230,131,12,245,114,220,150,158,169,224,223,201,238,107,48,
-247,43,246,211,191,46,158,111,38,224,210,155,251,39,110,44,249,197,135,57,246,
-195,187,30,232,216,55,245,198,155,111,98,100,224,40,235,123,164,227,123,29,65,
-220,35,42,85,220,116,163,11,44,230,158,94,186,238,88,203,105,224,251,126,212,
-156,101,157,95,69,47,170,158,246,177,14,111,126,252,201,155,120,189,201,149,
-186,152,79,252,76,24,216,112,155,206,88,11,103,34,117,170,1,199,218,113,227,
-39,195,38,124,204,190,179,254,240,5,120,228,197,53,192,195,78,127,137,239,241,
-250,56,159,245,180,237,118,180,182,142,167,76,111,208,96,175,79,72,48,6,62,
-247,87,216,86,63,240,64,24,15,65,244,193,57,234,135,177,218,2,23,189,213,134,
-154,222,47,248,226,83,253,10,77,228,198,37,96,250,88,177,136,17,164,117,226,
-90,250,197,42,215,2,86,115,130,235,79,6,28,108,33,39,140,81,253,81,108,206,11,
-56,112,90,111,226,212,166,227,166,190,0,14,132,254,236,251,4,76,123,136,209,
-99,14,123,189,30,88,15,113,2,115,90,87,235,4,142,156,62,239,91,114,237,63,204,
-163,143,154,239,222,47,61,135,176,11,251,245,133,20,125,133,252,217,158,95,28,
-125,243,28,151,123,129,204,152,249,121,46,215,184,85,78,221,111,46,246,94,65,
-188,245,92,156,109,62,145,59,153,246,129,30,100,136,162,223,35,248,197,179,50,
-244,32,200,17,79,244,23,123,31,249,2,155,212,236,168,109,214,149,251,166,247,
-6,114,206,103,205,44,71,238,32,199,11,73,215,147,187,132,210,166,49,167,14,
-148,176,209,35,248,137,117,115,93,216,123,238,91,254,210,162,230,66,251,155,
-57,64,159,178,183,181,167,57,47,114,174,54,185,94,228,93,123,146,243,194,166,
-174,23,126,178,255,40,245,216,32,39,114,190,7,208,255,243,53,230,212,121,190,
-7,127,97,49,112,95,94,156,251,7,107,241,10,235,195,103,196,133,121,244,79,115,
-2,102,206,208,31,245,30,9,198,92,236,217,220,83,25,19,92,37,121,20,92,37,252,
-243,231,23,255,227,98,212,156,26,197,128,111,183,111,93,252,223,77,174,204,63,
-127,120,241,15,236,107,240,183,217,207,61,82,195,187,61,135,205,28,87,193,181,
-144,96,223,116,89,218,177,81,152,224,90,140,9,227,246,179,52,143,148,117,93,
-54,111,108,126,109,236,71,54,170,95,224,171,113,98,110,158,175,218,110,91,55,
-229,99,28,214,238,15,182,192,101,201,204,147,159,170,119,174,235,214,145,242,
-85,155,224,138,197,88,245,206,125,253,110,87,49,147,29,93,43,122,128,15,45,
-185,7,174,231,225,10,238,132,81,126,75,187,47,197,196,149,223,92,112,40,70,
-239,241,227,88,80,237,205,24,43,142,57,70,127,230,131,223,57,251,0,242,131,
-188,98,185,199,106,141,10,126,60,175,136,227,30,217,24,144,161,92,207,195,254,
-186,159,224,105,109,106,230,253,120,202,81,88,142,94,84,61,237,99,29,172,7,76,
-60,44,214,189,83,234,98,62,241,51,97,226,91,244,208,98,30,234,207,30,208,121,
-224,136,25,55,90,127,57,128,6,63,33,207,190,179,254,243,249,168,177,168,52,
-199,235,82,92,159,94,198,172,174,133,225,15,108,247,223,60,245,57,240,131,121,
-87,108,228,34,247,67,217,55,150,99,142,194,142,105,236,227,56,80,210,203,188,
-222,47,241,240,17,181,38,135,13,151,128,59,214,235,1,214,220,179,22,243,67,30,
-243,69,198,117,206,7,113,181,54,248,137,241,248,155,192,251,72,115,222,207,
-224,218,31,97,211,37,96,174,15,158,115,0,158,239,29,92,91,99,6,135,61,231,9,
-167,122,248,133,126,96,252,213,30,115,3,189,214,235,180,71,97,131,125,114,194,
-173,145,228,48,108,247,117,177,158,246,233,156,31,173,1,57,252,80,156,175,203,
-207,115,185,250,166,114,112,206,49,215,87,137,235,115,239,156,229,107,164,100,
-218,7,122,144,33,138,126,143,230,62,155,242,130,156,151,60,155,29,181,77,12,
-242,59,245,6,108,66,247,232,69,243,43,109,30,217,175,114,223,240,163,184,30,
-188,80,194,254,142,253,137,120,248,133,33,198,170,103,44,200,79,223,179,212,
-133,47,90,163,58,143,159,58,15,189,153,251,152,186,200,239,35,157,174,199,62,
-65,14,225,11,214,197,56,214,247,158,171,125,196,223,46,194,166,227,129,123,92,
-95,206,243,61,228,115,122,143,242,12,2,102,162,83,191,249,217,235,177,128,32,
-131,63,158,235,184,31,199,108,231,239,94,252,199,77,122,187,253,219,226,31,
-219,163,224,60,2,225,207,127,88,252,125,54,186,221,190,121,241,9,215,229,202,
-183,219,175,217,159,164,95,89,12,233,191,47,254,38,199,168,1,75,52,200,164,33,
-7,225,79,77,228,244,235,99,16,48,254,48,227,212,55,97,52,18,154,222,41,63,228,
-16,131,66,84,202,47,154,113,163,81,255,88,92,109,136,110,43,214,155,109,160,
-49,185,65,92,235,220,227,68,28,249,175,6,16,247,78,127,117,118,49,214,161,237,
-140,235,7,56,229,110,23,135,152,147,111,16,167,233,219,55,95,23,243,188,38,
-204,161,226,230,60,209,191,107,54,249,48,51,247,195,243,90,131,185,54,106,3,
-91,240,49,242,64,59,234,91,254,107,76,125,141,156,67,173,11,37,113,160,101,28,
-242,201,252,100,92,248,219,109,97,109,198,31,227,186,62,236,42,6,177,228,58,
-244,181,29,167,107,99,62,236,40,209,174,99,34,43,240,195,237,193,14,248,233,
-11,205,226,152,151,113,145,179,45,85,90,146,106,87,215,39,134,154,147,253,132,
-55,174,251,142,56,238,17,149,230,243,160,249,153,120,182,217,215,38,115,45,
-149,128,53,103,89,231,87,209,35,170,15,223,176,119,80,183,240,145,31,197,166,
-186,88,254,206,24,216,209,26,130,145,35,200,249,83,231,129,115,204,209,31,180,
-9,249,195,51,204,9,215,139,35,231,121,206,84,139,158,211,130,115,194,245,102,
-248,54,157,111,181,23,34,142,124,62,192,247,156,111,112,206,167,174,25,245,
-235,56,80,210,203,188,30,27,250,45,226,131,222,53,196,246,47,92,106,206,176,
-22,30,82,240,133,0,228,208,71,45,52,39,113,142,99,46,244,96,218,209,124,100,
-28,108,194,94,172,153,207,136,184,162,62,206,49,126,168,161,95,240,83,123,48,
-242,228,18,242,51,189,97,156,182,36,114,88,251,32,226,1,71,254,116,175,7,198,
-115,135,223,96,16,215,251,10,24,61,103,129,59,253,45,12,196,12,189,83,183,151,
-71,152,211,123,20,28,47,235,172,3,123,100,250,82,174,246,125,244,131,226,214,
-44,203,31,63,207,229,90,67,149,131,35,127,145,95,213,107,125,178,28,53,70,46,
-71,223,156,48,22,93,211,131,12,33,122,65,51,103,61,79,222,215,209,95,121,63,
-90,158,155,109,212,207,109,214,90,114,126,191,143,184,220,185,214,150,236,87,
-225,23,165,29,203,26,79,52,229,151,123,200,125,86,61,99,97,31,65,162,107,69,
-46,88,115,141,149,243,162,87,117,30,117,209,115,125,30,124,130,205,199,47,154,
-170,139,252,97,77,167,56,107,232,127,127,63,209,216,226,154,121,8,84,175,7,
-253,192,243,43,176,156,95,49,209,243,192,226,217,20,185,2,158,62,213,30,208,
-124,169,221,240,9,215,196,196,28,191,250,206,197,127,184,248,239,23,255,248,
-93,234,124,187,125,126,241,31,217,149,190,112,118,220,143,44,254,171,61,250,
-179,197,191,106,215,29,199,171,42,87,190,221,254,103,241,183,239,209,31,64,
-176,232,119,23,223,231,169,1,219,72,32,147,134,28,132,160,189,32,209,56,138,
-33,14,73,226,139,7,37,248,217,15,15,202,129,139,34,247,98,196,92,74,176,46,
-198,121,3,177,41,189,113,92,202,130,233,129,194,195,25,182,216,188,170,11,27,
-216,212,104,18,31,51,22,199,57,247,56,49,158,30,6,222,229,69,51,252,153,55,
-205,244,96,139,121,190,41,32,65,126,65,192,99,12,253,84,15,207,173,199,239,
-227,233,48,98,172,33,197,26,192,78,177,168,77,72,35,166,140,13,191,40,241,56,
-114,173,137,197,218,92,207,165,161,131,47,186,94,62,20,162,7,152,251,94,175,
-208,81,2,59,176,87,111,150,208,123,157,32,137,121,129,193,92,30,204,148,248,
-203,177,247,60,226,200,118,233,31,228,200,19,230,245,131,246,202,218,249,102,
-22,120,181,19,135,163,175,135,235,168,101,223,143,176,3,157,82,255,102,84,115,
-182,36,149,12,157,241,169,102,134,161,166,199,21,120,165,211,30,69,76,74,140,
-43,244,201,207,205,200,133,211,212,123,117,109,165,105,63,70,238,179,206,175,
-78,49,186,111,32,248,100,26,203,77,207,95,234,135,11,24,228,197,109,198,250,
-148,229,126,228,92,173,15,240,200,55,100,152,3,121,245,189,249,3,194,245,102,
-246,155,74,122,45,96,131,123,229,1,78,9,227,197,140,109,62,47,149,124,157,156,
-43,158,111,208,129,216,47,208,228,7,11,93,79,243,151,109,129,139,94,230,209,
-79,197,198,126,196,250,158,111,48,207,144,26,19,207,10,173,37,174,193,88,139,
-117,225,250,60,67,242,126,246,43,207,231,189,199,246,167,226,96,11,113,224,
-139,15,218,123,140,101,237,66,19,218,176,101,253,177,57,242,228,18,242,51,189,
-98,156,17,11,243,87,207,48,230,216,235,11,162,143,138,227,217,169,125,22,215,
-181,6,196,42,99,237,233,57,0,117,209,231,5,216,205,231,17,217,175,162,238,148,
-102,123,113,159,80,154,94,160,176,78,93,119,58,47,217,155,117,157,147,92,253,
-83,57,56,231,111,250,210,39,116,89,14,31,145,147,108,179,230,88,107,69,54,31,
-149,12,33,250,125,21,61,84,109,176,39,225,83,212,35,239,199,121,127,240,188,
-128,110,252,210,96,240,229,46,119,50,109,214,107,204,225,23,198,61,246,30,188,
-80,194,62,203,99,244,20,226,165,87,174,203,207,10,57,86,230,32,114,164,243,
-168,139,253,174,243,184,30,230,33,190,233,183,150,81,47,237,107,234,188,135,
-160,7,107,143,195,143,211,47,83,208,95,32,204,197,23,114,196,6,245,58,50,6,
-216,198,26,92,167,98,34,183,136,7,140,181,96,27,126,78,47,175,88,211,113,81,
-95,202,152,71,174,249,21,153,243,19,139,127,127,49,98,248,185,197,212,184,62,
-112,126,245,29,139,255,124,241,223,44,254,98,194,128,111,183,63,93,252,179,
-123,244,189,139,241,79,167,190,110,192,241,170,202,149,187,228,235,239,215,91,
-162,6,118,123,142,7,11,254,244,100,59,77,15,37,94,56,149,66,86,31,24,128,241,
-132,158,214,76,152,205,180,175,146,104,186,74,108,96,199,69,195,240,70,169,
-205,18,54,80,104,151,198,6,113,137,115,143,19,243,242,122,196,189,246,69,19,
-62,210,30,52,115,163,158,94,52,105,151,146,136,161,142,243,188,138,3,79,185,
-158,112,145,187,231,88,200,128,173,113,95,171,53,184,231,94,235,8,251,216,136,
-188,137,67,170,7,88,244,0,252,154,254,189,91,232,40,153,99,139,67,217,125,166,
-79,122,32,18,3,63,193,176,7,140,31,110,115,30,232,159,199,16,135,167,214,63,
-236,250,218,188,214,181,227,42,247,181,218,225,225,232,107,121,223,199,56,219,
-3,65,167,245,116,219,15,95,26,42,45,76,181,27,123,103,227,241,51,201,31,224,
-141,181,198,129,211,28,145,21,87,252,44,204,122,86,233,180,54,153,107,169,4,
-172,57,203,58,191,138,126,83,125,248,230,191,157,138,56,248,81,108,170,139,
-229,239,49,6,140,26,227,39,227,36,10,215,211,153,94,99,6,30,243,127,106,49,
-228,167,51,236,238,15,8,215,139,35,231,121,142,203,149,250,77,95,231,47,137,
-19,174,55,51,158,62,79,123,193,253,135,159,57,87,241,64,229,56,80,251,171,149,
-178,38,98,100,253,76,99,31,199,129,146,94,230,209,31,197,198,76,205,95,228,
-190,246,56,207,10,96,112,175,192,156,120,49,241,90,146,25,183,238,253,136,19,
-126,248,189,198,114,154,112,121,69,207,7,113,212,78,54,177,158,231,154,49,43,
-142,53,84,95,193,145,39,151,144,159,233,117,93,228,0,117,189,175,93,98,169,
-245,5,211,87,173,111,63,95,163,231,234,153,184,70,78,91,50,251,153,237,129,
-231,125,16,254,69,221,49,230,39,112,212,71,15,115,93,238,105,197,177,71,188,
-110,32,228,157,185,87,220,142,3,63,69,118,150,107,13,85,14,142,53,25,111,173,
-1,239,59,253,204,62,201,163,174,78,245,140,50,31,149,32,187,235,35,167,103,
-159,184,6,242,173,117,243,171,208,81,26,26,198,10,155,111,251,162,153,107,166,
-212,238,73,219,204,72,5,187,165,36,140,69,7,202,251,50,235,253,10,126,229,243,
-149,57,136,115,70,231,81,135,188,241,60,211,121,92,135,123,5,18,173,187,247,
-130,238,3,151,112,127,98,45,248,226,82,239,127,124,17,70,155,167,254,34,123,
-77,113,15,131,45,196,14,27,136,63,63,111,228,61,9,61,158,203,234,253,11,115,
-245,221,72,233,227,161,223,216,51,186,38,53,204,47,175,153,211,152,243,235,
-246,39,34,9,75,217,46,56,143,190,127,241,63,45,254,235,36,5,223,110,63,36,35,
-240,15,46,254,134,36,1,251,85,149,43,207,82,242,190,82,3,187,5,199,38,68,81,
-88,112,50,174,167,135,146,218,0,51,150,24,54,166,115,63,96,58,198,237,171,68,
-215,200,216,233,191,76,142,194,230,166,159,108,196,6,113,137,115,143,19,243,
-152,159,140,123,205,139,38,54,12,190,93,136,27,73,111,84,230,70,101,148,135,
-93,74,34,134,58,206,243,42,14,60,229,122,194,157,106,60,97,195,191,140,189,86,
-107,112,207,125,228,134,135,16,24,235,96,227,231,154,68,15,208,7,237,1,176,
-234,40,153,99,203,118,226,129,91,123,56,247,27,94,24,224,51,236,210,30,190,
-173,170,15,46,156,3,12,106,63,191,104,242,192,244,181,127,116,49,236,95,249,
-109,37,244,129,137,7,170,137,114,222,192,244,11,107,210,39,50,235,166,184,176,
-91,235,73,238,251,60,246,142,226,220,247,154,163,130,31,207,43,226,238,62,56,
-25,202,245,131,159,134,225,53,215,246,145,243,180,54,53,61,15,96,205,89,214,
-249,149,247,71,205,117,244,93,244,3,214,56,61,36,221,235,98,62,105,156,3,102,
-49,226,139,127,26,16,178,233,76,175,245,113,223,156,243,94,102,94,153,191,144,
-58,99,45,196,82,207,31,141,55,52,53,214,199,189,229,121,122,246,111,52,125,
-173,158,79,238,45,229,169,126,204,49,71,136,7,122,224,96,167,174,91,243,238,
-76,127,84,146,103,122,254,34,143,53,23,244,213,237,35,111,192,122,141,48,199,
-231,51,167,234,91,156,77,172,5,49,184,174,15,104,199,88,77,222,109,134,157,
-141,1,37,220,92,107,92,67,150,247,65,204,138,181,179,94,207,67,143,197,52,109,
-221,192,42,119,187,244,29,182,38,202,53,187,98,15,204,248,188,255,192,145,3,
-197,209,94,207,79,141,67,251,130,60,219,139,251,128,51,252,235,231,205,178,
-254,48,95,248,169,114,174,199,251,142,202,193,156,227,189,215,109,174,209,139,
-214,114,185,115,213,175,81,37,67,184,158,243,243,62,84,61,152,122,228,79,235,
-166,136,200,119,63,47,184,199,14,126,153,116,144,59,153,54,235,53,230,240,11,
-227,190,6,8,126,77,84,239,95,123,69,18,198,162,211,115,155,125,167,250,232,35,
-234,245,89,35,246,125,175,55,117,145,123,157,199,245,98,223,107,108,140,63,
-246,18,176,174,211,222,163,196,25,182,64,189,78,100,29,121,156,176,129,251,32,
-100,176,11,121,222,187,81,11,224,97,155,177,42,134,177,196,252,192,18,81,125,
-161,14,28,185,225,53,206,29,216,232,251,153,127,242,223,101,222,110,255,188,
-248,139,38,115,125,198,225,37,242,47,23,255,237,226,159,52,217,140,235,92,37,
-39,185,242,44,37,239,43,53,176,91,112,104,66,38,0,201,195,8,63,65,211,67,9,
-146,116,191,209,44,6,150,227,140,67,98,33,247,102,193,207,47,23,12,230,198,
-195,54,127,98,156,55,16,155,25,69,99,195,82,138,185,249,155,4,226,96,131,7,
-109,111,122,248,174,54,96,147,235,59,206,153,216,104,36,174,199,185,25,247,46,
-127,117,54,114,167,190,18,135,181,167,7,219,176,75,137,218,203,227,60,175,226,
-192,140,81,113,145,39,176,75,79,53,134,77,200,21,203,185,122,112,16,123,173,
-214,196,210,47,149,134,142,255,35,24,71,248,201,92,184,62,122,128,242,238,135,
-251,12,127,32,193,79,208,163,7,2,124,41,192,24,251,77,200,243,10,140,251,5,44,
-198,253,55,47,145,95,196,135,181,217,83,122,8,231,67,31,220,49,140,19,54,180,
-159,243,141,42,252,167,239,193,240,147,123,83,165,17,139,199,225,243,115,141,
-34,238,90,123,224,49,174,125,18,113,134,116,142,235,132,175,24,226,184,71,214,
-200,201,80,174,63,251,9,198,120,234,189,180,182,217,164,230,180,31,35,103,42,
-231,218,96,206,235,125,232,185,197,122,144,32,231,216,15,211,111,249,106,93,
-122,62,58,198,237,105,220,184,158,206,244,169,62,62,31,185,203,245,100,108,
-174,71,124,174,241,92,63,250,235,116,22,175,147,161,20,119,174,153,207,167,
-108,190,177,43,30,254,193,70,253,150,29,235,43,110,170,31,125,227,8,118,160,7,
-142,222,6,238,116,95,137,181,21,155,237,194,15,96,136,51,173,125,2,223,207,
-129,26,31,214,196,189,174,251,22,249,242,250,68,254,114,47,170,79,41,86,147,
-103,155,94,23,239,217,96,237,71,158,77,218,83,190,246,248,91,161,125,21,107,
-103,125,61,51,179,182,239,3,172,171,56,230,77,99,102,143,41,135,127,125,159,
-34,102,232,21,55,253,213,237,154,27,175,111,142,135,185,1,22,118,230,60,131,
-117,62,37,115,79,229,88,206,121,118,220,156,175,238,39,115,254,65,203,7,184,
-230,175,238,197,243,90,115,12,11,165,132,177,232,154,30,100,8,215,247,126,203,
-122,176,230,60,228,180,197,17,124,227,115,163,250,77,219,228,26,143,207,231,
-167,201,157,76,155,245,134,217,87,169,23,246,71,113,61,120,161,130,221,82,18,
-198,162,243,88,98,31,169,158,53,155,251,39,242,203,243,71,231,81,7,223,121,
-134,246,121,145,215,171,186,216,239,92,143,236,190,129,40,175,245,136,243,50,
-124,213,53,244,218,145,96,230,3,115,192,184,230,218,138,97,126,16,39,116,176,
-133,151,87,216,155,115,173,57,161,93,16,122,31,191,180,192,79,80,190,79,198,
-108,240,231,22,255,201,226,233,55,149,248,13,230,223,45,254,233,197,161,81,12,
-56,143,130,171,228,36,87,158,165,228,125,165,6,44,41,32,147,134,28,132,4,59,
-161,24,108,56,197,16,135,68,251,191,69,3,225,97,35,55,24,152,141,228,9,6,193,
-94,46,48,49,186,46,48,88,59,63,0,230,27,174,19,27,73,15,57,54,67,52,147,54,98,
-222,72,78,241,141,191,227,156,105,159,27,146,140,88,122,12,239,254,159,1,121,
-252,57,102,202,255,239,95,52,231,60,241,70,84,107,28,54,241,159,38,57,49,71,
-154,123,240,213,90,131,123,238,195,86,247,45,31,138,221,255,156,195,238,199,
-220,235,249,208,98,143,99,204,79,197,192,95,198,93,231,212,60,100,172,251,89,
-255,7,53,191,242,253,131,159,185,215,233,15,214,80,226,154,25,195,27,251,146,
-216,190,167,6,12,63,114,110,88,79,223,215,78,253,165,33,226,174,181,152,207,
-130,136,67,41,234,171,113,61,194,43,134,56,238,145,53,114,90,242,176,21,126,
-130,129,83,98,79,43,2,204,181,239,181,52,155,212,112,45,197,130,117,95,101,
-185,247,24,215,233,125,224,185,99,109,201,30,119,61,11,166,186,124,117,192,
-232,254,158,236,35,7,87,95,52,193,192,247,60,69,94,39,191,184,94,175,105,242,
-199,201,80,138,59,247,22,40,246,97,207,231,189,23,132,49,102,92,46,233,251,31,
-84,31,204,233,27,71,88,15,121,69,172,244,54,112,167,243,18,52,190,84,137,93,
-159,67,255,76,107,159,132,223,87,222,23,90,203,199,243,181,118,49,7,177,32,
-135,218,3,234,83,138,213,228,221,230,68,185,71,162,134,138,71,206,123,95,196,
-40,214,206,122,208,148,95,16,99,87,44,235,171,235,18,83,206,87,167,45,113,251,
-211,111,202,107,143,195,118,143,131,235,122,126,65,243,89,200,126,73,251,205,
-252,224,167,218,211,62,61,157,173,213,191,211,254,131,111,124,46,202,114,224,
-115,253,40,119,187,253,188,96,125,225,27,99,232,107,33,46,172,85,207,68,248,0,
-155,89,190,102,43,97,44,186,166,7,25,194,245,241,98,194,30,179,25,246,241,17,
-8,241,192,95,141,147,182,56,10,159,53,199,148,99,222,39,83,239,218,124,126,
-154,220,201,180,89,111,152,125,21,126,81,218,176,219,204,72,5,187,165,36,140,
-69,231,61,133,122,247,30,166,46,124,209,125,80,231,169,221,152,199,123,143,
-230,142,186,232,187,71,58,93,143,123,196,243,174,4,31,84,158,239,147,236,75,
-216,140,243,154,236,251,104,222,67,244,69,207,140,254,69,18,109,143,252,36,
-215,32,252,84,109,176,214,160,234,200,159,111,146,219,237,183,101,20,92,37,
-121,20,92,37,39,185,242,44,37,239,43,53,96,73,1,153,52,228,32,29,145,235,161,
-11,102,19,116,174,155,112,42,76,181,119,42,94,95,55,143,148,249,225,168,218,
-83,159,102,191,163,41,171,230,20,103,245,13,227,44,243,171,217,246,235,237,
-134,60,75,102,158,236,169,222,185,226,78,53,1,107,62,193,122,192,40,14,92,177,
-179,93,222,28,170,116,242,213,175,38,157,174,85,215,185,26,95,197,213,81,72,
-85,147,117,19,215,60,76,254,131,231,24,112,64,225,80,197,225,202,149,93,115,
-178,163,113,20,140,211,93,86,99,190,226,27,57,143,42,95,141,121,177,249,195,
-79,72,39,124,245,21,44,56,167,53,82,28,101,62,170,252,196,38,56,205,127,132,
-175,186,98,231,37,57,121,106,11,124,5,51,113,157,7,46,115,83,204,224,62,39,
-143,38,230,39,36,195,26,160,53,202,184,58,202,140,115,6,15,11,124,96,80,141,
-216,55,187,161,201,254,199,222,202,156,235,211,109,220,53,246,9,201,201,30,
-184,214,252,145,93,112,181,93,71,207,88,231,151,124,39,206,245,60,250,100,242,
-87,218,76,58,101,181,231,18,29,101,59,228,235,235,190,168,190,160,132,1,215,
-154,157,214,230,39,36,215,214,29,113,230,199,107,237,93,245,143,247,146,254,
-207,20,124,126,205,227,73,14,174,190,85,159,248,92,128,123,123,126,169,61,219,
-180,28,56,153,246,129,30,100,8,215,235,179,214,146,52,61,49,208,241,37,42,228,
-196,6,10,47,36,231,223,126,215,56,125,62,63,77,238,100,218,172,55,76,147,80,
-218,52,219,204,72,5,187,165,36,140,69,231,177,204,47,212,124,89,71,252,124,89,
-215,88,227,165,137,47,154,90,63,206,139,231,64,181,201,245,34,239,154,87,206,
-11,155,186,94,237,175,19,215,62,186,58,175,214,49,230,113,143,76,152,53,122,
-68,134,86,124,216,68,252,250,69,144,19,214,202,243,98,118,230,42,201,163,224,
-42,201,163,224,42,57,201,149,103,41,121,95,169,129,157,150,158,152,45,78,84,
-49,155,183,54,19,228,130,25,113,134,120,130,1,25,234,2,14,100,200,3,46,233,88,
-120,20,151,5,38,163,201,251,95,107,35,111,43,153,32,23,140,225,246,135,227,56,
-152,250,161,69,222,150,50,25,170,224,246,71,101,38,191,66,192,201,156,227,60,
-67,93,192,129,12,169,88,61,96,150,68,169,97,215,72,105,75,231,23,77,193,134,
-164,235,156,76,123,208,23,221,56,31,100,168,151,227,182,244,76,5,127,205,46,
-15,246,248,38,245,62,211,62,215,237,28,48,78,5,123,213,230,17,231,100,232,55,
-198,27,34,99,174,224,182,116,166,130,125,58,7,58,193,37,60,126,138,236,46,119,
-50,237,3,189,146,33,159,96,13,241,4,51,145,205,202,243,158,206,133,94,176,79,
-241,32,155,113,97,142,161,174,224,20,1,174,15,25,135,121,32,67,62,193,93,193,
-128,10,238,205,176,32,67,191,0,95,201,102,95,152,123,21,7,186,138,125,37,174,
-97,77,155,245,13,163,4,157,224,142,88,67,189,63,123,159,125,156,255,85,191,
-195,190,49,233,53,249,93,231,132,177,232,64,124,96,215,151,14,242,140,223,114,
-39,211,170,62,158,169,130,53,14,127,214,218,186,209,134,190,240,132,220,176,
-160,45,113,76,188,38,40,166,218,220,58,147,14,114,39,211,102,125,195,56,65,46,
-24,227,173,26,169,96,183,148,132,177,232,52,170,254,75,16,214,12,177,159,190,
-212,134,30,148,127,251,29,114,126,249,167,117,137,245,80,27,218,118,9,125,192,
-28,62,143,235,122,235,234,10,149,57,239,52,47,141,40,105,152,71,100,232,130,
-79,163,19,235,188,170,115,174,146,60,10,174,146,60,10,174,146,147,92,121,150,
-146,247,149,26,216,105,233,137,217,226,68,21,179,121,107,51,65,46,152,17,103,
-136,39,24,144,161,46,224,64,134,60,224,146,238,11,247,43,52,189,19,155,191,31,
-136,224,109,37,19,228,130,49,220,254,112,204,67,15,196,13,121,56,108,43,25,
-170,224,246,71,101,38,191,66,192,201,156,227,60,67,93,192,129,12,169,88,30,
-204,95,123,209,124,64,5,127,205,110,28,222,143,110,158,38,171,116,5,227,84,
-176,87,109,30,113,78,134,126,99,188,33,50,230,10,110,75,103,42,216,167,115,
-160,19,92,194,227,167,200,238,114,39,211,62,208,43,25,242,9,214,16,79,48,19,
-217,172,60,239,233,92,232,5,251,20,15,178,25,23,230,24,234,2,174,146,205,186,
-56,207,144,79,112,87,48,160,130,123,51,44,200,208,47,192,87,178,217,23,230,94,
-197,129,174,98,95,137,107,88,211,102,125,195,40,65,39,184,35,214,80,239,207,
-222,103,31,199,47,47,63,176,231,32,149,239,249,38,189,38,191,235,156,48,22,
-221,171,215,114,50,173,234,243,51,155,83,252,51,6,95,111,177,211,26,85,27,87,
-94,52,201,249,153,109,35,206,126,155,116,144,59,153,54,235,27,198,9,114,193,
-24,111,213,72,5,187,165,36,140,69,103,250,52,210,56,37,135,198,58,55,158,157,
-201,143,230,229,154,103,221,213,245,214,213,21,42,115,222,116,158,33,158,96,
-148,12,253,2,188,147,205,242,57,58,91,185,74,242,40,184,74,242,40,184,74,78,
-114,229,89,74,182,63,111,183,255,5,75,238,218,119,32,100,170,216,0,0,0,0,73,
-69,78,68,174,66,96,130 };
+0,0,14,189,0,0,14,189,1,71,251,144,173,0,0,0,24,116,69,88,116,83,111,102,116,
+119,97,114,101,0,112,97,105,110,116,46,110,101,116,32,52,46,49,46,49,99,42,
+156,75,0,0,29,72,73,68,65,84,120,94,237,93,61,200,181,73,82,29,4,67,83,13,69,
+16,76,76,6,4,17,131,5,215,81,16,49,80,55,88,21,113,13,12,92,208,100,50,5,13,
+84,12,6,68,5,153,104,52,48,144,85,80,16,35,17,99,127,34,19,77,196,68,35,5,81,
+76,68,228,218,167,78,215,173,83,63,125,239,115,191,239,27,118,132,173,203,121,
+223,167,171,78,87,87,87,87,247,243,60,247,157,111,247,189,219,123,183,27,240,
+94,17,215,79,54,23,229,60,226,65,174,240,174,112,32,202,123,196,125,198,121,
+102,119,81,222,43,220,173,186,235,118,51,201,196,159,100,226,89,107,208,95,
+145,171,253,148,247,105,113,183,106,20,229,157,184,143,108,144,43,125,31,245,
+135,188,202,219,205,167,242,46,253,190,43,142,139,115,175,250,188,194,133,188,
+194,133,92,225,43,231,42,111,171,142,162,220,183,229,159,244,46,207,236,42,87,
+184,87,56,147,104,191,171,125,63,205,62,87,121,85,94,233,115,133,119,213,223,
+85,30,68,185,175,242,183,234,37,249,52,198,121,215,62,159,241,212,254,136,231,
+242,105,242,30,113,175,112,32,159,53,222,219,232,171,205,229,100,127,85,239,
+242,204,14,185,106,175,156,103,253,32,39,142,235,171,237,164,119,81,251,137,
+227,242,166,220,173,74,114,213,190,155,73,62,75,182,147,120,159,79,163,223,21,
+142,202,171,124,151,123,191,123,239,130,170,201,173,64,213,228,86,160,106,78,
+122,197,172,37,246,149,58,216,83,179,201,169,126,76,76,229,24,110,183,79,22,
+62,66,75,197,152,153,187,45,33,198,120,192,217,90,250,207,188,49,62,72,226,
+125,225,126,133,248,32,159,168,125,119,105,178,108,53,46,200,181,121,222,110,
+255,181,240,37,209,249,213,151,22,254,117,225,3,177,65,62,88,128,30,246,237,
+117,244,251,115,11,136,33,235,87,235,138,88,175,11,253,140,149,121,47,229,105,
+155,154,24,51,115,183,37,139,177,50,47,113,67,211,109,46,102,61,216,139,109,
+236,15,49,214,235,188,173,61,75,225,191,149,223,55,229,220,91,2,211,103,238,
+237,246,75,169,21,192,190,42,218,147,95,67,229,159,252,46,92,142,3,186,170,
+189,192,123,41,78,160,248,76,253,31,197,208,109,185,85,237,101,156,132,39,92,
+139,137,159,35,7,112,73,250,234,27,152,252,75,123,236,147,91,29,53,62,32,183,
+136,87,107,107,193,236,213,255,48,255,59,148,27,247,136,140,26,135,218,20,53,
+23,143,114,247,36,111,46,119,221,3,223,137,119,130,246,47,113,37,212,113,196,
+214,198,121,7,62,19,248,201,26,109,85,63,142,174,33,170,191,139,235,107,19,93,
+146,56,192,80,143,165,69,116,94,110,57,234,124,78,57,172,188,139,243,184,204,
+91,45,155,47,63,207,245,30,231,180,30,117,14,157,51,251,124,162,119,49,235,3,
+59,196,24,131,253,174,169,49,241,185,235,43,246,219,117,101,30,46,171,21,125,
+53,191,53,167,222,191,142,85,252,54,59,177,71,203,2,189,112,12,219,52,74,226,
+214,90,24,106,32,181,52,174,26,51,63,108,85,191,143,250,229,49,179,237,234,
+120,181,95,129,203,106,101,102,245,121,66,237,23,243,251,112,193,158,249,167,
+220,217,152,170,81,84,159,207,248,14,237,87,109,142,170,201,173,64,213,228,86,
+160,106,110,183,111,177,171,170,87,204,90,98,95,169,3,155,60,196,180,161,31,
+139,185,114,12,159,229,23,205,159,177,159,241,34,247,155,171,45,246,221,165,
+137,177,132,103,248,218,139,102,19,99,190,57,119,91,178,24,43,243,18,55,52,
+221,230,98,86,183,127,238,126,69,160,157,53,187,87,22,99,189,206,219,218,179,
+20,254,91,249,125,83,206,110,161,222,254,123,1,135,233,182,218,199,91,16,212,
+230,127,218,85,200,135,233,6,17,92,191,242,47,117,92,58,159,99,86,225,129,14,
+212,53,154,249,31,38,14,121,117,108,204,79,247,34,196,175,42,247,163,195,188,
+48,54,30,72,222,95,208,252,161,127,250,226,106,243,99,63,103,155,95,157,206,1,
+248,199,56,177,30,28,99,154,67,59,51,150,190,230,204,215,110,138,29,240,156,
+78,121,116,27,207,155,0,124,230,135,51,7,127,250,28,84,56,159,190,239,32,149,
+251,201,147,218,66,60,42,81,51,125,254,115,45,192,170,177,240,97,164,214,249,
+84,179,53,86,151,92,3,186,190,75,35,57,63,213,11,252,198,60,2,157,207,249,215,
+53,1,15,177,219,120,27,189,198,184,14,145,131,224,241,12,112,13,185,83,76,104,
+67,255,190,240,188,78,170,48,30,237,29,62,92,56,143,90,23,188,103,59,183,251,
+113,244,90,155,253,113,125,125,158,16,206,1,227,8,207,22,106,201,214,68,94,10,
+207,192,177,84,62,105,227,162,205,43,157,115,206,31,208,125,185,228,53,225,60,
+52,223,92,203,90,167,157,199,28,246,121,112,190,252,60,215,71,190,167,243,66,
+247,207,180,102,179,207,39,122,23,179,62,176,67,140,81,236,210,3,107,80,247,
+82,63,203,168,75,231,42,100,217,194,55,235,19,107,246,81,203,41,251,157,206,
+246,223,95,248,237,133,94,3,196,30,45,11,244,194,49,108,211,40,137,203,90,192,
+216,136,247,131,86,43,81,163,61,110,214,16,99,133,70,227,96,14,188,198,242,
+122,135,158,245,169,57,138,241,16,79,206,3,99,224,158,131,70,199,203,113,250,
+62,166,127,234,125,238,209,7,96,236,24,7,18,115,9,125,31,11,96,222,242,89,85,
+115,151,91,191,178,128,88,128,143,77,87,125,198,28,128,186,231,99,46,224,57,
+43,248,25,85,147,91,129,170,225,207,111,92,248,229,133,239,218,237,137,247,
+151,11,223,211,244,138,89,75,236,43,117,108,11,4,49,109,232,199,98,174,28,131,
+111,186,210,197,152,153,187,45,33,198,120,192,217,90,250,207,188,49,62,72,226,
+177,96,176,128,216,228,239,215,98,217,93,154,24,75,120,134,171,243,196,198,
+202,7,144,90,171,13,242,252,112,35,239,107,47,154,75,66,211,109,46,102,117,59,
+15,69,228,150,7,105,205,255,208,31,98,172,215,121,91,123,150,194,127,43,191,
+111,194,185,95,177,150,255,109,97,190,153,0,165,54,247,111,220,88,234,75,20,
+196,15,239,122,160,163,102,235,141,55,223,196,8,240,168,235,123,164,243,251,
+58,66,248,64,161,218,238,11,63,99,172,176,160,239,233,165,235,206,181,156,6,
+255,211,124,209,196,111,222,196,235,77,174,172,139,197,196,207,196,129,15,247,
+233,192,88,56,19,105,83,11,16,99,199,141,159,128,79,196,152,99,7,24,11,248,
+118,70,110,128,15,63,167,151,120,157,175,207,191,157,245,75,220,143,174,173,
+243,169,211,27,52,251,212,90,64,27,252,92,95,225,91,227,192,3,97,125,33,240,
+171,88,63,180,123,125,37,187,173,13,45,167,122,137,184,66,235,115,171,47,128,
+136,177,114,49,71,136,174,19,199,210,47,86,113,77,174,230,4,215,31,213,47,96,
+151,192,23,114,194,57,106,60,202,197,220,163,23,16,188,94,179,234,211,121,189,
+46,200,131,160,62,251,62,9,30,230,232,115,14,127,125,61,48,30,230,9,206,113,
+92,89,39,32,114,250,188,110,137,90,127,232,199,24,53,223,189,94,122,14,225,23,
+254,107,253,161,174,144,63,219,243,11,81,55,207,121,185,22,8,214,38,63,207,
+245,145,187,233,188,248,173,5,175,21,204,183,214,249,236,243,137,222,197,172,
+15,236,16,99,20,251,110,33,46,158,149,97,135,64,143,249,68,125,113,143,32,95,
+128,105,205,143,250,230,186,114,223,244,218,69,206,249,172,153,245,200,29,244,
+120,33,233,118,162,107,168,109,22,11,234,32,137,27,53,130,223,24,55,175,11,
+107,207,99,203,95,90,212,92,104,125,51,7,168,83,214,182,214,52,251,69,206,213,
+39,199,139,188,107,77,178,95,248,212,241,34,78,214,31,181,62,55,232,201,156,
+239,1,140,255,124,141,62,181,159,239,193,95,92,0,239,203,11,185,126,48,22,175,
+48,62,98,198,188,208,143,241,105,78,0,230,12,245,81,239,145,0,250,98,207,230,
+154,202,156,64,213,228,86,160,106,248,243,23,22,254,105,1,107,78,139,114,128,
+219,237,91,23,254,167,233,21,252,249,195,11,63,176,175,129,111,179,223,187,
+165,142,119,121,14,155,57,174,2,117,33,1,223,116,89,219,185,177,48,129,186,24,
+19,199,253,87,109,110,5,180,197,226,141,205,175,133,13,196,85,70,141,11,184,
+58,79,244,205,253,213,218,125,235,166,124,204,155,95,52,193,139,214,25,83,156,
+106,119,212,113,129,220,10,84,159,64,110,5,42,119,94,235,121,252,26,171,114,
+38,63,58,86,212,0,31,90,106,13,92,205,195,21,222,137,163,120,151,126,95,229,
+196,149,223,92,112,40,70,237,241,227,92,72,173,205,104,43,143,92,236,141,124,
+240,59,114,12,16,63,200,43,151,123,172,239,211,196,31,207,43,242,16,131,237,
+17,23,99,117,206,181,56,129,105,108,90,56,150,114,129,115,142,252,42,106,81,
+237,244,143,113,48,30,56,241,176,88,247,78,89,23,139,137,159,137,19,223,162,
+135,21,253,176,254,172,1,237,7,196,156,113,163,245,151,3,88,240,27,250,233,69,
+115,62,31,117,46,213,18,243,117,13,174,79,47,99,60,251,50,16,15,124,247,191,
+60,245,62,136,131,121,87,110,228,34,215,67,241,39,235,30,126,208,230,231,206,
+91,146,236,210,239,84,47,145,159,208,134,143,199,92,95,15,64,115,207,181,152,
+31,242,152,47,2,215,253,203,183,92,139,208,224,55,218,245,75,32,157,31,16,57,
+239,53,91,235,35,124,42,143,113,2,115,14,28,93,195,177,117,206,64,248,115,204,
+188,184,66,92,168,7,206,191,242,0,218,117,189,78,123,20,62,88,39,39,222,106,
+73,14,145,119,250,238,241,97,60,173,211,57,63,186,6,68,196,161,60,31,151,159,
+231,122,141,77,245,64,206,49,199,87,141,219,115,237,156,245,171,165,98,214,7,
+118,136,49,138,125,183,230,58,155,242,130,156,151,60,155,31,245,77,14,242,59,
+125,153,2,159,176,61,122,209,252,120,172,169,208,228,186,225,71,121,125,242,
+34,137,251,187,246,19,243,225,23,134,104,171,157,115,65,126,250,158,165,45,98,
+209,53,170,253,248,169,253,80,155,185,142,105,139,252,62,178,233,120,172,19,
+228,16,177,96,92,180,99,124,175,185,90,71,252,235,34,124,58,31,188,199,235,
+203,126,190,135,188,79,175,81,228,138,156,73,78,245,230,103,175,207,5,2,29,
+226,241,92,199,253,56,122,59,190,123,225,79,154,246,118,251,247,133,31,219,
+173,64,110,65,240,243,31,23,190,207,90,183,219,55,47,156,120,93,175,184,221,
+126,221,126,82,126,117,1,218,255,88,248,38,231,168,3,75,52,196,180,161,135,
+224,167,38,242,244,159,53,129,227,15,51,46,125,19,70,33,161,232,93,242,67,14,
+57,88,136,42,167,23,77,141,111,90,220,234,171,126,67,140,159,234,3,133,201,13,
+162,60,114,235,60,49,143,252,159,6,144,247,86,255,233,236,2,198,161,239,204,
+155,95,52,195,47,14,49,23,223,32,46,211,183,111,62,46,250,249,154,244,28,146,
+139,159,154,39,198,55,215,67,245,201,135,153,185,30,174,174,53,198,198,218,
+192,23,98,140,27,25,253,104,108,249,63,99,234,99,228,155,160,174,11,53,113,
+160,101,30,242,201,252,100,94,196,219,125,97,108,206,63,218,117,124,248,85,14,
+230,146,215,161,143,237,60,29,27,253,225,71,133,126,157,19,89,65,28,238,15,
+126,128,167,47,52,11,209,79,121,228,66,15,187,105,84,150,166,250,213,241,201,
+161,101,246,95,248,134,186,239,200,67,158,56,23,71,223,159,41,206,132,217,103,
+31,155,224,88,170,1,52,103,217,230,87,81,35,106,167,127,140,131,189,131,117,
+139,24,249,81,110,90,23,203,223,153,3,63,186,134,0,114,4,61,127,107,63,32,207,
+57,234,131,62,161,175,15,173,144,20,15,4,215,11,62,175,105,28,234,67,115,202,
+233,157,231,130,235,13,196,54,157,111,181,22,98,30,249,124,192,156,114,190,
+129,146,79,25,51,214,111,224,45,73,118,233,119,154,155,231,7,118,215,146,219,
+191,112,137,92,82,131,177,240,144,130,47,4,160,135,221,215,61,159,207,124,48,
+2,208,23,118,128,126,250,190,119,30,124,250,154,79,220,184,162,61,206,49,126,
+194,202,56,181,6,35,79,202,139,94,39,187,193,18,187,100,107,34,135,181,14,98,
+222,64,228,175,159,11,248,233,185,195,95,48,200,171,254,200,213,115,22,188,
+211,127,133,129,57,195,238,50,249,211,22,250,244,26,5,248,133,41,108,92,7,214,
+200,244,165,92,173,251,168,7,229,173,94,150,63,126,158,235,153,59,174,161,234,
+129,200,113,228,87,237,186,62,89,143,53,70,46,199,216,92,208,22,91,179,67,140,
+33,118,97,51,103,61,79,94,215,81,95,88,67,157,195,210,54,223,88,63,247,89,215,
+146,253,251,125,196,245,142,186,182,132,95,69,92,212,118,46,215,120,146,41,
+191,220,67,30,179,218,57,23,214,17,52,58,86,228,130,107,174,115,101,191,168,
+85,237,71,91,212,92,239,135,152,224,243,241,139,166,218,34,127,24,211,37,206,
+26,198,63,125,121,20,115,139,107,230,33,88,211,249,135,56,240,252,10,46,251,
+87,78,212,60,184,120,54,69,174,192,103,76,181,6,52,95,234,55,98,194,53,57,209,
+199,175,190,115,225,143,22,254,97,225,199,239,90,199,237,246,249,133,63,182,
+43,125,225,236,188,31,89,248,235,221,250,243,133,95,179,235,206,227,85,213,43,
+110,183,255,93,248,246,221,250,67,40,150,252,222,194,189,159,58,176,141,4,49,
+109,232,33,152,180,47,72,20,142,114,200,67,146,248,226,65,13,126,247,195,131,
+122,240,98,145,251,98,68,95,106,48,46,218,211,203,135,23,142,107,184,96,202,
+225,225,12,95,44,222,249,80,198,166,70,145,64,131,54,231,162,60,114,235,60,
+209,158,30,6,222,230,69,51,226,233,155,230,209,139,166,111,10,104,144,95,136,
+231,6,246,105,61,60,183,62,127,111,79,15,132,156,107,104,48,6,184,211,3,167,
+250,132,38,230,148,121,17,23,53,62,143,105,173,49,54,199,115,109,216,16,139,
+142,151,15,133,168,1,230,190,175,87,216,168,129,31,248,171,55,75,93,39,104,
+162,95,112,208,151,7,51,53,254,114,236,53,143,121,100,191,140,15,122,228,9,
+253,250,65,123,101,236,124,51,11,190,250,137,195,209,199,195,117,172,101,223,
+143,240,3,155,74,255,102,148,92,230,108,181,170,24,59,115,211,154,25,135,150,
+62,175,224,171,156,246,40,230,164,194,121,101,206,61,206,13,228,194,101,170,
+189,58,182,202,244,226,16,185,207,54,191,58,205,209,235,14,130,152,204,98,185,
+233,249,75,245,112,129,131,188,184,207,24,159,186,105,191,235,250,128,143,124,
+67,135,62,208,231,216,217,39,197,3,193,245,6,235,77,53,64,94,11,248,230,94,
+121,192,83,65,123,129,115,155,31,50,84,124,156,156,43,244,163,13,194,122,129,
+165,60,88,200,120,154,191,236,11,40,246,22,167,114,1,254,196,248,158,239,56,
+67,234,156,120,86,232,90,226,26,136,117,225,248,60,67,242,126,246,43,175,179,
+123,141,237,143,183,32,248,9,95,152,7,190,248,160,191,206,245,43,112,185,118,
+97,81,30,228,94,31,27,145,39,229,69,175,147,157,200,45,204,133,249,171,103,24,
+207,60,95,95,8,99,236,103,157,231,5,246,184,174,107,64,174,182,48,246,244,28,
+128,117,209,231,5,248,237,231,81,244,138,117,167,54,251,139,251,132,202,244,2,
+133,113,234,184,211,121,201,218,172,227,156,244,26,159,234,1,222,123,60,103,
+211,151,62,97,203,122,196,136,156,100,159,244,23,168,107,181,90,85,140,33,246,
+125,21,53,212,215,59,246,140,235,226,254,136,156,205,251,131,231,5,108,227,
+151,6,67,44,119,189,139,89,179,93,231,172,123,121,154,123,159,188,72,226,62,
+203,99,212,20,230,203,168,220,150,159,21,242,92,153,131,200,145,246,163,205,
+207,142,124,134,113,60,244,195,252,166,191,90,198,122,105,93,211,230,53,4,59,
+160,53,142,56,78,127,76,65,125,65,208,23,95,200,145,27,210,215,145,115,128,
+111,140,193,113,42,39,114,139,249,0,24,11,190,17,231,244,242,138,49,157,23,
+235,75,29,243,200,49,63,150,62,63,177,240,7,11,152,195,207,47,208,226,246,224,
+249,213,119,44,252,197,194,223,46,124,49,113,128,219,237,207,22,126,118,183,
+190,119,1,255,116,234,235,6,30,175,170,94,209,53,95,127,191,222,26,117,176,
+203,115,60,88,240,211,147,237,114,122,9,65,18,85,11,93,125,80,7,199,19,122,26,
+51,113,54,232,95,53,0,23,171,202,87,18,39,10,134,55,202,94,136,240,129,133,
+118,77,108,16,229,1,125,158,232,135,254,245,5,234,77,95,52,17,35,253,193,210,
+11,245,217,95,52,189,112,99,14,181,157,251,85,30,112,202,117,229,249,166,159,
+234,161,114,49,14,184,117,222,175,172,117,205,125,228,128,254,177,17,121,19,
+135,86,15,176,168,1,196,53,253,123,183,176,81,51,207,45,14,101,143,153,49,233,
+129,72,14,226,4,224,15,28,63,220,230,60,48,62,159,67,28,158,186,254,225,215,
+199,230,181,142,29,87,17,63,218,234,135,135,163,143,229,117,31,237,236,15,2,
+155,174,167,251,126,248,210,80,101,217,171,223,216,59,155,143,223,73,255,128,
+111,208,53,14,158,230,136,168,60,137,179,128,235,89,181,211,216,4,199,82,13,
+160,57,203,54,191,138,122,83,123,228,214,255,58,21,243,224,71,185,105,93,44,
+127,143,57,0,214,24,191,57,79,178,112,61,237,225,58,103,240,209,255,167,22,
+160,207,177,179,79,138,7,130,235,5,159,215,52,14,244,42,167,7,123,246,95,45,
+23,92,111,112,62,125,95,107,45,120,252,200,73,206,85,60,80,57,15,210,94,92,
+101,76,204,145,235,135,182,250,2,138,93,250,49,30,229,2,252,169,107,21,185,
+175,181,203,179,2,28,220,43,208,39,94,76,124,45,9,206,91,247,126,204,19,113,
+248,189,198,114,154,120,64,92,121,62,200,3,248,97,43,124,98,60,207,53,231,172,
+60,32,199,10,68,158,148,23,189,78,118,130,63,145,3,172,235,125,236,54,151,136,
+209,193,88,31,215,75,212,108,61,19,23,108,130,75,182,102,142,51,251,3,230,125,
+16,241,197,186,163,205,79,240,104,143,26,230,184,220,211,202,99,141,248,186,
+65,144,119,230,94,121,203,187,205,161,142,115,210,51,174,201,143,142,201,249,
+214,53,224,125,167,159,197,39,125,172,171,75,61,59,44,70,21,232,238,246,200,
+233,57,38,142,129,124,235,186,249,85,216,168,13,11,231,10,159,239,246,69,51,
+175,153,74,187,39,109,55,163,20,238,214,82,208,22,27,36,214,212,216,246,185,
+247,221,87,136,43,159,175,204,65,156,51,218,143,54,228,141,231,153,246,227,56,
+220,43,208,232,186,123,45,232,62,112,13,159,127,48,22,98,113,173,215,63,190,8,
+163,207,83,125,17,190,166,184,135,193,23,230,14,31,152,127,126,222,200,123,18,
+118,60,151,229,26,100,95,125,55,82,249,112,168,55,214,140,142,73,11,243,203,
+107,230,52,250,252,134,253,196,76,194,83,246,11,228,214,247,47,252,243,194,
+223,36,45,112,187,253,144,180,128,31,92,248,134,164,1,252,170,234,21,179,150,
+216,87,234,96,151,224,88,132,88,20,46,56,129,235,233,97,161,22,192,204,37,135,
+133,233,232,7,76,231,184,127,213,0,62,70,214,102,127,44,250,88,88,45,122,160,
+251,136,13,162,60,160,207,19,253,152,159,204,123,147,23,77,108,24,124,187,16,
+55,146,94,168,255,95,95,52,35,190,204,123,101,173,107,238,35,7,60,132,0,140,
+131,141,159,215,36,106,128,49,244,26,8,27,53,243,220,178,159,120,224,214,26,
+206,245,134,23,6,196,12,191,244,135,111,171,234,131,11,251,128,131,181,159,95,
+52,121,96,250,216,63,186,0,255,87,254,90,9,123,112,152,43,216,38,201,121,3,24,
+23,198,100,76,4,215,77,121,128,235,179,150,232,251,60,246,142,242,60,246,154,
+163,194,31,207,43,242,238,49,184,24,235,192,1,140,195,107,142,237,45,199,52,
+54,45,167,60,68,206,178,205,175,188,62,106,174,163,238,162,30,48,198,233,33,
+233,190,46,22,83,159,103,93,59,204,47,254,105,64,232,166,61,92,215,199,99,115,
+244,135,127,207,95,214,2,24,11,115,153,206,84,159,111,104,235,92,129,178,102,
+2,207,211,179,127,163,233,241,247,124,114,111,41,198,245,147,117,199,124,96,7,
+143,89,23,222,146,154,119,7,227,81,13,16,87,158,191,200,99,205,5,99,117,255,
+200,27,184,190,70,232,227,253,153,83,141,45,206,38,174,5,57,184,110,15,104,
+167,185,154,190,251,12,63,155,3,73,60,160,175,53,174,161,203,251,32,122,197,
+216,217,78,228,185,152,118,28,183,175,239,236,151,190,38,121,180,102,192,201,
+31,230,231,245,7,196,254,86,30,227,11,155,91,234,60,180,46,136,217,95,220,7,
+28,136,175,159,55,203,251,195,124,149,154,88,130,241,120,223,81,61,192,62,94,
+123,221,231,106,189,52,150,235,29,213,190,90,85,140,225,118,246,207,251,80,
+237,0,237,200,159,174,155,50,34,223,253,188,224,30,59,196,101,218,65,239,98,
+214,108,215,57,71,92,104,247,49,32,136,107,146,122,255,218,35,82,208,22,155,
+190,192,177,238,212,30,117,68,187,62,107,196,190,239,235,77,91,228,94,251,113,
+188,216,247,58,55,206,63,246,146,62,3,104,237,81,227,128,47,72,95,39,66,91,62,
+79,248,192,125,16,58,248,133,62,239,221,88,11,240,225,155,115,85,14,231,18,
+253,131,75,70,141,133,54,32,114,195,107,156,59,240,209,247,51,127,242,223,101,
+222,110,255,178,240,69,211,185,61,243,240,18,249,87,11,127,183,240,147,166,
+155,121,29,85,115,210,43,102,45,177,175,212,193,46,193,161,8,153,0,36,15,45,
+252,134,76,15,37,72,210,253,70,179,0,46,219,153,135,196,66,239,197,130,223,95,
+46,28,244,141,135,109,254,70,123,122,0,196,162,177,96,169,65,223,28,31,139,30,
+62,120,208,106,209,3,140,93,125,192,39,199,87,94,112,163,144,56,30,251,102,
+222,219,252,167,179,145,187,30,235,87,243,69,19,122,142,77,204,107,12,80,175,
+92,246,157,95,30,174,174,53,227,82,109,216,248,191,8,198,22,126,51,23,110,143,
+26,160,190,199,129,60,32,102,196,3,13,126,67,30,61,16,224,75,1,206,177,223,
+132,60,175,224,120,92,224,162,221,255,242,194,3,203,231,135,177,89,83,122,8,
+231,67,31,232,28,206,179,238,137,124,163,138,248,25,123,0,113,114,111,170,54,
+230,226,243,240,254,211,26,121,30,213,55,248,104,215,154,143,121,134,118,158,
+215,137,95,57,228,97,254,54,190,139,177,50,103,138,19,64,123,154,87,26,219,
+124,210,194,177,148,11,104,206,84,143,120,121,197,126,189,14,61,183,24,15,26,
+228,28,251,161,127,115,222,215,165,231,163,115,220,159,206,27,215,211,153,62,
+173,143,247,71,238,166,125,239,118,204,207,181,158,235,94,247,128,204,215,197,
+88,157,55,173,153,231,139,186,249,198,174,124,196,7,31,245,91,118,140,175,188,
+113,253,44,54,182,224,7,118,240,122,188,177,159,53,127,49,182,114,23,196,47,
+226,0,135,60,232,170,239,126,14,212,249,97,76,220,235,122,108,145,47,95,159,
+200,95,169,197,211,92,77,159,125,250,186,120,205,6,30,239,97,31,123,252,171,
+208,190,138,177,179,157,224,220,181,214,136,121,92,229,49,111,125,255,105,43,
+226,171,60,128,118,229,77,127,33,173,185,241,245,205,243,65,63,114,225,103,
+206,51,160,253,169,153,107,42,206,25,224,156,103,231,205,249,234,113,178,174,
+223,27,243,145,199,236,123,241,60,214,60,135,197,82,65,91,108,205,14,49,134,
+219,153,83,204,3,115,231,90,169,29,208,156,135,158,190,216,66,108,124,110,212,
+184,233,155,168,243,241,254,252,52,189,139,89,179,221,56,251,42,213,194,254,
+40,175,79,94,164,112,183,150,130,182,216,124,46,177,143,212,206,53,155,235,39,
+242,203,243,71,251,209,134,216,121,134,246,126,145,215,171,54,214,30,247,45,
+53,128,199,6,161,190,174,71,156,151,17,171,142,161,215,206,4,152,15,244,1,112,
+205,177,149,195,252,96,158,176,193,23,94,94,225,111,206,181,230,132,126,33,
+168,125,252,209,2,191,33,249,62,25,189,129,207,45,252,233,194,244,151,74,252,
+5,243,239,23,126,122,33,44,202,1,114,43,80,53,39,189,98,214,18,251,74,29,88,
+82,32,166,13,61,4,9,118,193,98,176,224,148,67,30,18,237,255,22,13,130,135,141,
+92,96,0,11,201,19,12,129,191,188,192,228,232,184,224,96,236,233,1,16,63,49,
+182,11,11,73,57,44,134,40,166,90,136,44,16,47,86,72,124,227,175,60,114,225,
+159,27,146,192,92,250,28,222,254,127,12,200,231,159,231,252,213,125,209,172,
+121,226,141,168,174,49,185,240,137,255,209,36,23,230,168,230,254,181,181,174,
+185,15,95,61,182,124,40,178,6,148,147,15,140,30,199,92,235,249,208,98,141,163,
+205,79,229,32,94,206,187,246,233,53,168,92,143,179,254,47,168,249,149,239,31,
+252,206,55,116,198,131,49,84,56,102,230,240,198,190,52,182,239,105,1,16,71,
+206,13,107,196,247,181,203,233,165,1,63,235,90,204,103,65,204,67,37,214,183,
+62,168,156,248,202,33,15,62,48,15,155,27,100,233,171,47,191,2,79,133,53,173,
+92,128,99,223,215,210,124,210,194,177,148,11,156,247,155,215,24,199,57,159,69,
+92,91,194,231,93,207,130,105,93,242,63,27,208,56,168,153,252,35,7,87,95,52,1,
+240,79,121,194,207,41,46,142,87,215,148,125,238,241,184,24,171,243,240,179,
+214,22,36,246,97,207,231,189,22,4,104,115,94,174,233,251,31,210,30,204,45,54,
+182,48,30,242,138,185,246,120,251,121,227,50,189,84,169,95,239,195,248,160,
+171,190,163,229,117,161,107,249,184,191,174,93,244,193,92,144,195,84,3,167,
+185,154,190,251,156,164,215,8,127,42,31,57,159,234,194,175,98,236,108,39,122,
+126,33,156,187,242,184,190,58,46,57,165,94,108,114,75,182,198,115,121,250,255,
+209,212,26,135,239,62,15,142,235,249,133,204,103,33,235,37,237,55,139,131,159,
+234,79,235,244,116,182,214,61,56,239,63,198,198,231,162,172,7,127,90,63,247,
+219,207,11,248,102,108,156,67,31,11,243,194,88,245,76,68,12,240,153,245,171,
+183,10,218,98,107,118,136,49,220,30,47,38,172,49,235,97,31,111,65,48,31,196,
+171,243,164,47,182,34,102,205,49,245,232,247,209,84,187,214,159,159,166,119,
+49,107,182,27,103,95,69,92,212,54,238,118,51,74,225,110,45,5,109,177,121,77,
+97,189,123,13,211,22,177,232,62,168,253,212,111,244,227,189,71,115,71,91,212,
+221,35,155,142,199,61,226,121,87,65,12,170,207,247,73,214,37,124,198,121,77,
+248,62,154,247,16,99,209,51,163,127,145,68,223,35,158,228,26,130,223,106,13,
+232,26,84,27,241,249,166,185,221,126,71,90,129,170,201,173,64,213,156,244,138,
+89,75,236,43,117,96,73,129,152,54,244,16,109,17,211,161,203,34,232,168,155,
+112,90,152,234,239,180,120,211,184,185,21,208,86,245,87,99,82,27,17,69,89,45,
+167,121,214,216,208,206,58,191,154,125,191,234,23,173,170,143,214,25,147,63,
+181,59,42,15,200,173,64,205,39,224,7,76,214,94,171,7,191,57,84,237,20,171,95,
+77,54,29,171,142,83,231,55,199,49,229,33,183,66,171,150,108,155,80,243,48,197,
+15,204,115,192,1,133,67,21,135,43,71,118,203,201,143,206,163,112,92,238,186,
+58,231,43,177,57,114,43,227,234,156,23,44,30,126,66,59,241,107,172,128,240,92,
+86,43,241,76,119,111,21,60,241,9,164,254,143,248,213,86,252,188,146,147,167,
+190,128,43,156,9,181,31,80,250,166,57,3,83,159,220,234,224,39,107,165,229,178,
+90,15,121,5,56,103,240,176,192,7,6,181,200,28,204,111,88,114,252,177,183,50,
+202,250,52,31,142,26,239,201,31,80,215,124,225,232,23,168,190,91,239,39,208,
+254,101,77,19,202,122,158,98,50,253,27,250,148,171,12,245,231,26,109,85,63,
+142,174,33,42,255,133,245,133,36,14,48,172,89,105,17,252,132,230,226,184,19,
+207,226,120,83,127,167,53,169,254,120,47,233,255,76,193,251,215,60,158,244,64,
+141,173,198,196,135,124,220,219,243,75,237,217,167,229,192,197,172,15,236,16,
+99,184,93,159,181,150,166,217,201,137,151,168,208,147,27,44,188,144,228,191,
+126,123,204,64,157,167,247,231,167,233,93,204,154,237,198,105,26,106,155,101,
+187,25,165,112,183,150,130,182,216,124,46,243,11,53,95,214,49,127,190,172,235,
+92,227,165,137,47,154,186,126,236,55,191,104,114,188,200,187,230,149,253,194,
+167,142,87,235,235,132,90,71,87,251,213,117,140,126,220,35,19,103,181,30,137,
+177,149,31,62,49,127,253,34,200,5,99,229,126,209,59,163,106,114,43,80,53,185,
+21,168,154,147,94,49,107,137,125,165,14,118,90,122,98,182,58,73,229,108,108,
+107,22,232,133,51,242,140,241,132,3,49,86,230,205,196,37,133,183,181,20,180,
+197,6,193,226,114,129,9,20,121,255,207,106,136,237,37,11,244,194,49,222,254,
+176,29,7,83,63,180,136,237,41,139,177,10,207,62,188,74,250,43,98,189,46,244,
+51,86,230,29,7,48,102,225,46,185,191,104,170,24,51,115,183,133,178,181,243,
+139,166,112,67,211,109,46,102,61,216,139,109,236,15,49,214,235,188,173,61,75,
+225,95,243,203,131,61,190,73,189,247,180,207,117,63,7,142,75,225,94,245,105,
+216,166,81,140,157,249,219,50,139,177,159,240,141,145,57,151,120,91,61,74,229,
+110,108,107,23,216,132,151,248,248,45,186,187,222,197,172,15,236,42,198,124,
+194,53,198,19,206,36,214,43,247,123,218,23,118,225,26,182,233,40,214,227,66,
+31,99,93,225,37,198,66,125,200,88,173,147,24,243,9,175,112,142,206,42,15,173,
+147,24,51,115,207,228,37,198,206,252,109,185,38,214,251,66,223,194,123,37,166,
+173,237,82,120,71,98,229,161,165,98,214,108,55,108,115,147,101,171,252,109,
+201,98,44,225,109,117,147,202,3,182,41,137,177,50,111,91,178,24,235,179,192,
+243,255,212,239,176,111,76,123,77,127,183,185,160,45,54,8,31,216,245,165,131,
+152,249,91,239,98,86,181,199,51,85,64,231,225,207,90,219,54,250,208,23,158,
+208,27,23,178,53,206,209,87,150,205,56,199,109,218,65,239,98,214,108,111,28,
+23,232,133,99,216,166,81,10,119,107,41,104,139,77,103,213,255,8,194,53,195,
+220,79,95,106,195,14,201,127,253,14,61,191,252,211,117,137,241,176,54,244,237,
+26,198,128,62,124,30,215,241,214,213,21,41,125,222,170,95,106,81,211,56,143,
+196,216,133,159,90,39,104,191,106,115,84,77,110,5,170,38,183,2,85,115,210,43,
+102,45,177,175,212,193,78,75,79,204,86,39,169,156,141,109,205,2,189,112,70,
+158,49,158,112,32,198,202,188,153,184,164,240,182,150,130,182,216,32,248,137,
+162,119,97,241,247,3,17,216,94,178,64,47,28,227,237,15,219,60,244,32,220,144,
+135,195,182,138,177,10,207,62,188,74,250,43,98,189,46,244,51,86,230,29,7,48,
+102,225,46,249,218,139,230,3,41,252,107,126,227,240,126,116,243,52,93,149,43,
+28,151,194,189,234,211,176,77,163,24,59,243,183,101,22,99,63,225,27,35,115,46,
+241,182,122,148,202,221,216,214,46,176,9,47,241,241,91,116,119,189,139,89,31,
+216,85,140,249,132,107,140,39,156,73,172,87,238,247,180,47,236,194,53,108,211,
+81,172,199,133,62,198,186,192,171,98,189,114,191,109,233,98,204,39,188,194,57,
+58,171,60,180,78,98,204,204,125,56,55,99,103,254,182,92,19,235,125,161,111,
+225,189,18,211,214,118,41,188,35,177,242,208,82,49,107,182,27,182,185,201,178,
+85,254,182,100,49,150,240,182,186,73,229,1,219,148,196,88,153,183,45,89,140,
+245,89,224,241,203,203,247,110,95,88,80,253,238,111,218,107,250,187,205,5,109,
+177,189,241,88,46,102,85,123,126,102,115,137,127,198,224,227,45,184,172,86,
+245,113,229,69,147,200,207,108,155,113,142,219,180,131,222,197,172,217,222,56,
+46,208,11,199,176,77,163,20,238,214,82,208,22,155,217,83,75,231,41,57,52,104,
+95,172,163,218,30,245,203,107,158,109,87,199,91,87,87,164,244,121,167,253,140,
+241,132,163,98,236,23,248,46,214,203,251,104,111,69,213,228,86,160,106,114,43,
+80,53,39,189,98,214,18,246,243,118,251,63,227,27,138,9,123,111,123,255,0,0,0,
+0,73,69,78,68,174,66,96,130 };
+
static const char*
default_charset = R"( abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.!?;:-_/|\!'"+=*()[]{}&%$#@<>^`~)";